Skip to content

Commit

Permalink
convert theme system to real plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Jan 28, 2019
1 parent b4fcb96 commit 602c160
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 38 deletions.
13 changes: 6 additions & 7 deletions src/bootstrap4/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Theme, defineThemeSystem } from '@fullcalendar/core'
import { Theme, createPlugin } from '@fullcalendar/core'

export class Bootstrap4Theme extends Theme {
}
Expand Down Expand Up @@ -44,9 +44,8 @@ Bootstrap4Theme.prototype.iconOverrideOption = 'bootstrapFontAwesome'
Bootstrap4Theme.prototype.iconOverrideCustomButtonOption = 'bootstrapFontAwesome'
Bootstrap4Theme.prototype.iconOverridePrefix = 'fa-'


defineThemeSystem('bootstrap4', Bootstrap4Theme)

export default {
warning: 'TODO: convert bootstrap4 to real plugin. will still work though.'
}
export default createPlugin({
themeClasses: {
bootstrap4: Bootstrap4Theme
}
})
6 changes: 3 additions & 3 deletions src/core/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { default as EmitterMixin, EmitterInterface } from './common/EmitterMixin
import OptionsManager from './OptionsManager'
import View from './View'
import Theme from './theme/Theme'
import { getThemeSystemClass } from './theme/ThemeRegistry'
import { OptionsInput } from './types/input-types'
import { getLocale } from './datelib/locale'
import { DateEnv, DateInput } from './datelib/env'
Expand Down Expand Up @@ -34,6 +33,7 @@ import { PointerDragEvent } from './interactions/pointer'
import { InteractionSettingsInput, parseInteractionSettings, Interaction, interactionSettingsStore, InteractionClass } from './interactions/interaction'
import EventClicking from './interactions/EventClicking'
import EventHovering from './interactions/EventHovering'
import StandardTheme from './theme/StandardTheme'

export interface DateClickApi extends DatePointApi {
dayEl: HTMLElement
Expand Down Expand Up @@ -1223,8 +1223,8 @@ function buildDateEnv(locale, timeZone, timeZoneImpl, firstDay, weekNumberCalcul
}


function buildTheme(calendarOptions) {
let themeClass = getThemeSystemClass(calendarOptions.themeSystem || calendarOptions.theme)
function buildTheme(this: Calendar, calendarOptions) {
let themeClass = this.pluginSystem.hooks.themeClasses[calendarOptions.themeSystem || calendarOptions.theme] || StandardTheme
return new themeClass(calendarOptions)
}

Expand Down
1 change: 0 additions & 1 deletion src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export { unpromisify } from './util/promise'

export { default as EmitterMixin, EmitterInterface } from './common/EmitterMixin'
export { DateRange, rangeContainsMarker, intersectRanges, rangesEqual, rangesIntersect, rangeContainsRange } from './datelib/date-range'
export { defineThemeSystem } from './theme/ThemeRegistry'
export { default as Mixin } from './common/Mixin'
export { default as PositionCache } from './common/PositionCache'
export { default as ScrollComponent, ScrollbarWidths } from './common/ScrollComponent'
Expand Down
13 changes: 10 additions & 3 deletions src/core/plugin-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { dateSelectionJoinTransformer } from './interactions/date-selecting'
import { EventResizeJoinTransforms } from './interactions/event-resizing'
import { ExternalDefTransform } from './interactions/external-element-dragging'
import { InteractionClass } from './interactions/interaction'
import { ThemeClass } from './theme/Theme'
import { __assign } from 'tslib'

// TODO: easier way to add new hooks? need to update a million things

Expand All @@ -34,6 +36,7 @@ export interface PluginDefInput {
eventDropTransformers?: EventDropTransformers[]
componentInteractions?: InteractionClass[]
calendarInteractions?: CalendarInteractionClass[]
themeClasses?: { [themeSystemName: string]: ThemeClass }
}

export interface PluginHooks {
Expand All @@ -54,6 +57,7 @@ export interface PluginHooks {
eventDropTransformers: EventDropTransformers[]
componentInteractions: InteractionClass[]
calendarInteractions: CalendarInteractionClass[]
themeClasses: { [themeSystemName: string]: ThemeClass }
}

export interface PluginDef extends PluginHooks {
Expand Down Expand Up @@ -92,7 +96,8 @@ export function createPlugin(input: PluginDefInput): PluginDef {
viewContainerModifiers: input.viewContainerModifiers || [],
eventDropTransformers: input.eventDropTransformers || [],
componentInteractions: input.componentInteractions || [],
calendarInteractions: input.calendarInteractions || []
calendarInteractions: input.calendarInteractions || [],
themeClasses: input.themeClasses || {}
}
}

Expand All @@ -119,7 +124,8 @@ export class PluginSystem {
viewContainerModifiers: [],
eventDropTransformers: [],
componentInteractions: [],
calendarInteractions: []
calendarInteractions: [],
themeClasses: {}
}
this.addedHash = {}
}
Expand Down Expand Up @@ -166,6 +172,7 @@ function combineHooks(hooks0: PluginHooks, hooks1: PluginHooks): PluginHooks {
viewContainerModifiers: hooks0.viewContainerModifiers.concat(hooks1.viewContainerModifiers),
eventDropTransformers: hooks0.eventDropTransformers.concat(hooks1.eventDropTransformers),
calendarInteractions: hooks0.calendarInteractions.concat(hooks1.calendarInteractions),
componentInteractions: hooks0.componentInteractions.concat(hooks1.componentInteractions)
componentInteractions: hooks0.componentInteractions.concat(hooks1.componentInteractions),
themeClasses: __assign({}, hooks0.themeClasses, hooks1.themeClasses)
}
}
2 changes: 2 additions & 0 deletions src/core/theme/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ Theme.prototype.classes = {}
Theme.prototype.iconClasses = {}
Theme.prototype.baseIconClass = ''
Theme.prototype.iconOverridePrefix = ''

export type ThemeClass = { new(calendarOptions: any): Theme }
18 changes: 0 additions & 18 deletions src/core/theme/ThemeRegistry.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/core/theme/config.ts

This file was deleted.

0 comments on commit 602c160

Please sign in to comment.