import { PluginDef } from './plugin-system-struct' ; import { createPlugin } from './plugin-system' ; import { arrayEventSourcePlugin } from './event-sources/array-event-source' ; import { funcEventSourcePlugin } from './event-sources/func-event-source' ; import { jsonFeedEventSourcePlugin } from './event-sources/json-feed-event-source' ; import { simpleRecurringEventsPlugin } from './structs/recurring-event-simple' ; import { changeHandlerPlugin } from './option-change-handlers' ; import { handleDateProfile } from './dates-set' ; import { handleEventStore } from './event-crud' ; import { isArraysEqual } from './util/array' ; import { removeElement } from './util/dom-manip' ; import { computeEventSourcesLoading } from './reducers/eventSources' ; import { CalendarDataManagerState } from './reducers/data-types' ; export const globalPlugins = [ arrayEventSourcePlugin , funcEventSourcePlugin , jsonFeedEventSourcePlugin , simpleRecurringEventsPlugin , changeHandlerPlugin , createPlugin ( { isLoadingFuncs : [ ( state ) => computeEventSourcesLoading ( state . eventSources ) , ] , contentTypeHandlers : { html : buildHtmlRenderer , domNodes : buildDomNodeRenderer , } , propSetHandlers : { dateProfile : handleDateProfile , eventStore : handleEventStore , } , } ) , ] ; function buildHtmlRenderer ( ) { let currentEl = null ; let currentHtml = '' ; function render ( el , html ) { if ( el !== currentEl || html !== currentHtml ) { el . innerHTML = html ; } currentEl = el ; currentHtml = html ; } function destroy ( ) { currentEl . innerHTML = '' ; currentEl = null ; currentHtml = '' ; } return { render , destroy } ; } function buildDomNodeRenderer ( ) { let currentEl = null ; let currentDomNodes = [ ] ; function render ( el , domNodes ) { let newDomNodes = Array . prototype . slice . call ( domNodes ) ; if ( el !== currentEl || ! isArraysEqual ( currentDomNodes , newDomNodes ) ) { for ( let newNode of newDomNodes ) { el . appendChild ( newNode ) ; } destroy ( ) ; } currentEl = el ; currentDomNodes = newDomNodes ; } function destroy ( ) { currentDomNodes . forEach ( removeElement ) ; currentDomNodes = [ ] ; currentEl = null ; } return { render , destroy } ; }