UNPKG

iportal

Version:

web-portal

87 lines (77 loc) 2.34 kB
import { EventProvider } from '../Event' import { Sandbox } from '../Sandbox' import { ModuleEvents, ModuleConfig, ModuleResources, ModuleElements, ModuleManifest, Application } from '../types' class ModuleProptey extends EventProvider { public id: string public param: object = {} public application: Application public sandbox: Sandbox | undefined public view: HTMLElement | HTMLPortalElement | HTMLIFrameElement | null = null public model: ModuleManifest public events: ModuleEvents = { transformStart: () => undefined, transformEnd: () => undefined, start: () => undefined, load: () => undefined, loadError: () => undefined, preload: () => undefined, destroy: () => undefined } public darkTask: Array<() => void> = [] public createTime = Date.now() public transient = false public config: ModuleConfig = { title: '', rel: 'module', level: 0, source: {}, prerender: [], apply: ['smart-setTimeout', 'link-in-new-window', ['tap-highlight', 'tap-highlight data-appeared']], free: true, background: 'auto' } public components: ((w: Window) => CustomElementConstructor)[] = [] public resources: ModuleResources = { script: [], image: [], worker: [], video: [], audio: [], font: [], style: [] } public elements: ModuleElements = { container: document.body } constructor (id: string, model: ModuleManifest, application: Application) { super() this.id = id this.param = {} this.model = model this.application = application const { config, resources, events, components } = this.setDefaultConfig(model) Object.assign(this.config, config) Object.assign(this.resources, resources) Object.assign(this.events, events) if (components) { this.components = components } } public setDefaultConfig (manifest: ModuleManifest) { if (manifest.config?.rel === 'frameworks') { // } if (manifest.config?.portal) { if (!manifest.config.free) { console.error('[Module.config[free & portal]] conflit! [free] must be true when [portal] sets true') } } if ((manifest.config?.level ?? 0) > 10000) { console.error('[Module.config.level] needs to be less than 9999!') } return manifest } } export { ModuleProptey }