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,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;oBACxE,KAAK,CAAC;gBACP,KAAK,UAAU,CAAC,KAAK;oBACpB,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;oBACvE,KAAK,CAAC;YACR,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;QAC3B,CAAC;KACD;IAjDA;QADC,WAAW,EAAE;;;;gDAQb;IA4CF,MAAM,CAAC,SAAS,CAAC;AAClB,CAAC;AAED,eAAe,cAAc,CAAC","sourcesContent":["import { assign } from '@dojo/core/lang';\nimport { Handle } from '@dojo/core/interfaces';\nimport cssTransitions from '../animations/cssTransitions';\nimport { Constructor, DNode, Projection, ProjectionOptions } from './../interfaces';\nimport { WidgetBase } from './../WidgetBase';\nimport { afterRender } from './../decorators/afterRender';\nimport { v } from './../d';\nimport { Registry } from './../Registry';\nimport { dom } from './../vdom';\n\n/**\n * Represents the attach state of the projector\n */\nexport enum ProjectorAttachState {\n\tAttached = 1,\n\tDetached\n}\n\n/**\n * Attach type for the projector\n */\nexport enum AttachType {\n\tAppend = 1,\n\tMerge = 2\n}\n\nexport interface AttachOptions {\n\t/**\n\t * If `'append'` it will appended to the root. If `'merge'` it will merged with the root. If `'replace'` it will\n\t * replace the root.\n\t */\n\ttype: AttachType;\n\n\t/**\n\t * Element to attach the projector.\n\t */\n\troot?: Element;\n}\n\nexport interface ProjectorProperties {\n\tregistry?: Registry;\n}\n\nexport interface ProjectorMixin<P> {\n\treadonly properties: Readonly<P> & Readonly<ProjectorProperties>;\n\n\t/**\n\t * Append the projector to the root.\n\t */\n\tappend(root?: Element): Handle;\n\n\t/**\n\t * Merge the projector onto the root.\n\t *\n\t * The `root` and any of its `children` will be re-used.  Any excess DOM nodes will be ignored and any missing DOM nodes\n\t * will be created.\n\t * @param root The root element that the root virtual DOM node will be merged with.  Defaults to `document.body`.\n\t */\n\tmerge(root?: Element): Handle;\n\n\t/**\n\t * Attach the project to a _sandboxed_ document fragment that is not part of the DOM.\n\t *\n\t * When sandboxed, the `Projector` will run in a sync manner, where renders are completed within the same turn.\n\t * The `Projector` creates a `DocumentFragment` which replaces any other `root` that has been set.\n\t * @param doc The `Document` to use, which defaults to the global `document`.\n\t */\n\tsandbox(doc?: Document): void;\n\n\t/**\n\t * Sets the properties for the widget. Responsible for calling the diffing functions for the properties against the\n\t * previous properties. Runs though any registered specific property diff functions collecting the results and then\n\t * runs the remainder through the catch all diff function. The aggregate of the two sets of the results is then\n\t * set as the widget's properties\n\t *\n\t * @param properties The new widget properties\n\t */\n\tsetProperties(properties: this['properties']): void;\n\n\t/**\n\t * Sets the widget's children\n\t */\n\tsetChildren(children: DNode[]): void;\n\n\t/**\n\t * Return a `string` that represents the HTML of the current projection.  The projector needs to be attached.\n\t */\n\ttoHtml(): string;\n\n\t/**\n\t * Indicates if the projectors is in async mode, configured to `true` by defaults.\n\t */\n\tasync: boolean;\n\n\t/**\n\t * Root element to attach the projector\n\t */\n\troot: Element;\n\n\t/**\n\t * The status of the projector\n\t */\n\treadonly projectorState: ProjectorAttachState;\n\n\t/**\n\t * Runs registered destroy handles\n\t */\n\tdestroy(): void;\n}\n\nexport function ProjectorMixin<P, T extends Constructor<WidgetBase<P>>>(Base: T): T & Constructor<ProjectorMixin<P>> {\n\tabstract class Projector extends Base {\n\t\tpublic projectorState: ProjectorAttachState;\n\n\t\tprivate _root: Element = document.body;\n\t\tprivate _async = true;\n\t\tprivate _attachHandle: Handle | undefined;\n\t\tprivate _projectionOptions: Partial<ProjectionOptions>;\n\t\tprivate _projection: Projection | undefined;\n\t\tprivate _projectorProperties: this['properties'] = {} as this['properties'];\n\t\tpublic abstract properties: Readonly<P> & Readonly<ProjectorProperties>;\n\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args);\n\n\t\t\tthis._projectionOptions = {\n\t\t\t\ttransitions: cssTransitions\n\t\t\t};\n\n\t\t\tthis.root = document.body;\n\t\t\tthis.projectorState = ProjectorAttachState.Detached;\n\t\t}\n\n\t\tpublic append(root?: Element): Handle {\n\t\t\tconst options = {\n\t\t\t\ttype: AttachType.Append,\n\t\t\t\troot\n\t\t\t};\n\n\t\t\treturn this._attach(options);\n\t\t}\n\n\t\tpublic merge(root?: Element): Handle {\n\t\t\tconst options = {\n\t\t\t\ttype: AttachType.Merge,\n\t\t\t\troot\n\t\t\t};\n\n\t\t\treturn this._attach(options);\n\t\t}\n\n\t\tpublic set root(root: Element) {\n\t\t\tif (this.projectorState === ProjectorAttachState.Attached) {\n\t\t\t\tthrow new Error('Projector already attached, cannot change root element');\n\t\t\t}\n\t\t\tthis._root = root;\n\t\t}\n\n\t\tpublic get root(): Element {\n\t\t\treturn this._root;\n\t\t}\n\n\t\tpublic get async(): boolean {\n\t\t\treturn this._async;\n\t\t}\n\n\t\tpublic set async(async: boolean) {\n\t\t\tif (this.projectorState === ProjectorAttachState.Attached) {\n\t\t\t\tthrow new Error('Projector already attached, cannot change async mode');\n\t\t\t}\n\t\t\tthis._async = async;\n\t\t}\n\n\t\tpublic sandbox(doc: Document = document): void {\n\t\t\tif (this.projectorState === ProjectorAttachState.Attached) {\n\t\t\t\tthrow new Error('Projector already attached, cannot create sandbox');\n\t\t\t}\n\t\t\tthis._async = false;\n\t\t\tconst previousRoot = this.root;\n\n\t\t\t/* free up the document fragment for GC */\n\t\t\tthis.own({\n\t\t\t\tdestroy: () => {\n\t\t\t\t\tthis._root = previousRoot;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis._attach({\n\t\t\t\t/* DocumentFragment is not assignable to Element, but provides everything needed to work */\n\t\t\t\troot: doc.createDocumentFragment() as any,\n\t\t\t\ttype: AttachType.Append\n\t\t\t});\n\t\t}\n\n\t\tpublic setChildren(children: DNode[]): void {\n\t\t\tthis.__setChildren__(children);\n\t\t}\n\n\t\tpublic setProperties(properties: this['properties']): void {\n\t\t\tthis.__setProperties__(properties);\n\t\t}\n\n\t\tpublic __setProperties__(properties: this['properties']): void {\n\t\t\tif (this._projectorProperties && this._projectorProperties.registry !== properties.registry) {\n\t\t\t\tif (this._projectorProperties.registry) {\n\t\t\t\t\tthis._projectorProperties.registry.destroy();\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._projectorProperties = assign({}, properties);\n\t\t\tsuper.__setCoreProperties__({ bind: this, baseRegistry: properties.registry });\n\t\t\tsuper.__setProperties__(properties);\n\t\t}\n\n\t\tpublic toHtml(): string {\n\t\t\tif (this.projectorState !== ProjectorAttachState.Attached || !this._projection) {\n\t\t\t\tthrow new Error('Projector is not attached, cannot return an HTML string of projection.');\n\t\t\t}\n\t\t\treturn (this._projection.domNode.childNodes[0] as Element).outerHTML;\n\t\t}\n\n\t\t@afterRender()\n\t\tpublic afterRender(result: DNode) {\n\t\t\tlet node = result;\n\t\t\tif (typeof result === 'string' || result === null || result === undefined) {\n\t\t\t\tnode = v('span', {}, [result]);\n\t\t\t}\n\n\t\t\treturn node;\n\t\t}\n\n\t\tpublic destroy() {\n\t\t\tsuper.destroy();\n\t\t}\n\n\t\tprivate _attach({ type, root }: AttachOptions): Handle {\n\t\t\tif (root) {\n\t\t\t\tthis.root = root;\n\t\t\t}\n\n\t\t\tif (this._attachHandle) {\n\t\t\t\treturn this._attachHandle;\n\t\t\t}\n\n\t\t\tthis.projectorState = ProjectorAttachState.Attached;\n\n\t\t\tconst handle = {\n\t\t\t\tdestroy: () => {\n\t\t\t\t\tif (this.projectorState === ProjectorAttachState.Attached) {\n\t\t\t\t\t\tthis._projection = undefined;\n\t\t\t\t\t\tthis.projectorState = ProjectorAttachState.Detached;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tthis.own(handle);\n\t\t\tthis._attachHandle = handle;\n\n\t\t\tthis._projectionOptions = { ...this._projectionOptions, ...{ sync: !this._async } };\n\n\t\t\tswitch (type) {\n\t\t\t\tcase AttachType.Append:\n\t\t\t\t\tthis._projection = dom.append(this.root, this, this._projectionOptions);\n\t\t\t\t\tbreak;\n\t\t\t\tcase AttachType.Merge:\n\t\t\t\t\tthis._projection = dom.merge(this.root, this, this._projectionOptions);\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\treturn this._attachHandle;\n\t\t}\n\t}\n\n\treturn Projector;\n}\n\nexport default ProjectorMixin;\n"]}