{"version":3,"sources":["webpack:///../WCC.UI/App/decorators/componentModel.ts","webpack:///../WCC.UI/App/extensions/knockout/factories/vm.ts","webpack:///../WCC.UI/App/extensions/knockout/lazyComponent.ts","webpack:///../WCC.UI/App/viewmodels/base_es5.js","webpack:///../WCC.UI/App/viewmodels/disposable_es5.js"],"names":["componentModelMetadataKey","Symbol","componentModel","model","ctor","Reflect","defineMetadata","BaseViewModel","require","ViewModelFactory","constructor","ViewModel","createViewModel","params","componentInfo","_this$ViewModel$Model","effects","withEffects","element","undefined","data","ref","idx","ko","unwrap","viewmodel","Model","this","getMetadata","prototype","templateNodes","createViewModelv2","isInjectable","container","disposeContainer","createExtendedContainer","module","bind","wccModules","componentConfig","toConstantValue","componentData","toSelf","get","utils","domNodeDisposal","addDisposeCallback","createViewModelv3","ctx","ServicesContext","dispose","beforeInit","isObservableArray","register","remove","indexOf","splice","includes","push","isWritableObservable","exposeViewModel","initViewModel","attempt","Promise","resolve","reject","document","body","contains","isInitializable","init","isLazyComponent","applyBindingsToNode","isComponentReady","$","attr","requestAnimationFrame","isDisposable","item","_","isObject","isSubscribable","define","Base","_ref","_ref2","ManagersContext","config","call","_register","components","storage","managers","Object","create","Disposables","__initialized","__initTasks","disposables","each","func","field","_registerObservable","registerObservable"],"mappings":"qIAAA,oEAAO,MAAMA,EAA4BC,OAAO,sBAElC,SAAUC,EAAeC,GACnC,OAAQC,IACJC,QAAQC,eAAeN,EAA2BG,EAAOC,GAClDA,K,qpBCMf,MAAMG,EAAgBC,EAAQ,wCAwFxB,MAAOC,EACTC,YAAoBC,GAAA,KAAAA,YAEpBC,gBAAgBC,EAAuCC,GAA0C,IAAAC,EAC7F,MAAMC,EAAUC,wBACVC,EAAUJ,EAAcI,aAETC,IAAjBN,EAAOV,QACPU,EAAS,CAAEV,MAAOU,IAEtB,IAAI,MAAEV,EAAK,KAAEiB,EAAO,GAAE,IAAEC,EAAG,IAAEC,GAAQT,EAErCV,EAAQoB,EAAGC,OAAOrB,GAClBA,E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DvB,KAAKsE,YAAYvC,KAAK,WAClB/B,KAAKuE,YAAYK,mBAAmBF,EAAO/B,EAAMpB,IACnDb,KAAKV,OAGJ0E,GAGJ1F,GACV,6B","file":"340.73f7d2238efdcf49e920.js","sourcesContent":["export const componentModelMetadataKey = Symbol('component:template');\r\n\r\nexport default function componentModel(model: any) {\r\n return (ctor: any) => {\r\n Reflect.defineMetadata(componentModelMetadataKey, model, ctor);\r\n return ctor;\r\n }\r\n}","import { componentModelMetadataKey } from 'decorators/componentModel';\r\nimport { wccModules } from 'enums/wccModules';\r\nimport { isDisposable } from 'interfaces/disposable';\r\nimport { isInitializable } from 'interfaces/initializable';\r\nimport { isInjectable } from 'interfaces/injectable';\r\nimport { Subscribable, SubscribableOrNullableValue } from 'knockout';\r\nimport { ServicesContext } from 'services/context';\r\nimport { createExtendedContainer } from '../../../configuration/inversify/container/extended';\r\nimport { EffectsContainer, withEffects } from '../../../mixins/withEffects';\r\nimport { isLazyComponent } from '../lazyComponent';\r\n\r\nconst BaseViewModel = require('viewmodels/base_es5');\r\n\r\nconst maxLoadAttempts = 1000;\r\n\r\nfunction createViewModel(ViewModel: any, model: any, data: any, componentInfo: ko.components.ComponentInfo) {\r\n const ctx = new ServicesContext();\r\n const viewmodel = new ViewModel(model, componentInfo, ctx, data, {});\r\n\r\n ko.utils.domNodeDisposal.addDisposeCallback(componentInfo.element, () => ctx.dispose());\r\n\r\n return viewmodel;\r\n}\r\n\r\nfunction createViewModelv2(ViewModel: any, model: any, data: any, componentInfo: ko.components.ComponentInfo) {\r\n return new ViewModel({\r\n model: model,\r\n data: data,\r\n element: componentInfo.element,\r\n templateNodes: componentInfo.templateNodes\r\n });\r\n}\r\n\r\nfunction createViewModelv3(ViewModel: any, model: any, data: any, componentInfo: ko.components.ComponentInfo) {\r\n type Model = typeof model;\r\n type Data = typeof data;\r\n\r\n const [container, disposeContainer] = createExtendedContainer(module => module instanceof ViewModel);\r\n\r\n container.bind(wccModules.componentConfig).toConstantValue(model);\r\n container.bind(wccModules.componentData).toConstantValue(data);\r\n container.bind(wccModules.componentInfo).toConstantValue(componentInfo);\r\n container.bind(ViewModel).toSelf();\r\n\r\n const viewmodel = container.get(ViewModel);\r\n\r\n ko.utils.domNodeDisposal.addDisposeCallback(componentInfo.element, () => disposeContainer());\r\n\r\n return viewmodel;\r\n}\r\n\r\nfunction initViewModel(viewmodel: unknown, element: Node, attempt = 1) {\r\n return new Promise((resolve, reject) => {\r\n if (document.body.contains(element)) {\r\n if (isInitializable(viewmodel))\r\n viewmodel.init();\r\n\r\n if (isLazyComponent(viewmodel)) {\r\n ko.applyBindingsToNode(element, {\r\n 'attr': {\r\n 'component-ready': viewmodel.isComponentReady\r\n }\r\n }, {});\r\n } else {\r\n $(element).attr('component-ready', 'true');\r\n }\r\n\r\n resolve(true);\r\n } else if (attempt <= maxLoadAttempts) {\r\n requestAnimationFrame(() => resolve(initViewModel(viewmodel, element, attempt + 1)));\r\n } else {\r\n if (isDisposable(viewmodel))\r\n viewmodel.dispose();\r\n\r\n resolve(false);\r\n }\r\n });\r\n}\r\n\r\nfunction exposeViewModel(ref: Subscribable, viewmodel: any, effects: EffectsContainer, idx: SubscribableOrNullableValue) {\r\n if (ko.isObservableArray(ref)) {\r\n effects.register({ dispose: () => ref.remove(viewmodel) });\r\n\r\n effects.register(idx => {\r\n if (idx != undefined) {\r\n if (ref().indexOf(viewmodel) != idx)\r\n ref.remove(viewmodel);\r\n\r\n ref.splice(idx, 0, viewmodel);\r\n } else if (!ref().includes(viewmodel)) {\r\n ref.push(viewmodel);\r\n }\r\n }, [idx], false);\r\n } else if (ko.isWritableObservable(ref)) {\r\n ref(viewmodel);\r\n effects.register({ dispose: () => ref(undefined) });\r\n }\r\n}\r\n\r\nexport class ViewModelFactory {\r\n constructor(private ViewModel: any) { }\r\n\r\n createViewModel(params: ko.components.ViewModelParams, componentInfo: ko.components.ComponentInfo) {\r\n const effects = withEffects();\r\n const element = componentInfo.element;\r\n\r\n if (params.model === undefined)\r\n params = { model: params };\r\n\r\n let { model, data = {}, ref, idx } = params;\r\n\r\n model = ko.unwrap(model);\r\n model = model != null ? model : {};\r\n\r\n data = ko.unwrap(data);\r\n data = data != null ? data : {};\r\n\r\n let Model = this.ViewModel.Model ?? Reflect.getMetadata(componentModelMetadataKey, this.ViewModel);\r\n\r\n if (Model != undefined)\r\n model = model instanceof Model ? model : new Model(model, data);\r\n\r\n let viewmodel: any;\r\n\r\n if (this.ViewModel.prototype instanceof BaseViewModel) {\r\n viewmodel = createViewModelv2(this.ViewModel, model, data, componentInfo);\r\n } else if (isInjectable(this.ViewModel)) {\r\n viewmodel = createViewModelv3(this.ViewModel, model, data, componentInfo);\r\n } else {\r\n viewmodel = createViewModel(this.ViewModel, model, data, componentInfo)\r\n } \r\n\r\n if (viewmodel.beforeInit)\r\n viewmodel.beforeInit();\r\n\r\n if (ref != undefined)\r\n exposeViewModel(ref, viewmodel, effects, idx);\r\n\r\n initViewModel(viewmodel, element);\r\n\r\n ko.utils.domNodeDisposal.addDisposeCallback(element, () => {\r\n effects.dispose();\r\n \r\n if (viewmodel.dispose) {\r\n viewmodel.dispose();\r\n }\r\n });\r\n\r\n return viewmodel;\r\n }\r\n}","import { Subscribable } from 'knockout';\r\n\r\nexport interface LazyComponent {\r\n isComponentReady: Subscribable\r\n}\r\n\r\nexport function isLazyComponent(item: any): item is LazyComponent {\r\n return _.isObject(item) && ko.isSubscribable(item.isComponentReady);\r\n}","define('viewmodels/base_es5', [\r\n 'viewmodels/disposable_es5',\r\n 'services/context',\r\n 'managers/context'\r\n], function (Base, { ServicesContext }, { ManagersContext }) {\r\n function ViewModel(config) {\r\n Base.call(this);\r\n\r\n this.model = config.model;\r\n this.data = config.data;\r\n this.element = config.element;\r\n this.templateNodes = config.templateNodes;\r\n this.ctx = this._register(new ServicesContext());\r\n this.components = this.ctx.components;\r\n this.storage = this.ctx.storage;\r\n this.managers = this._register(new ManagersContext()); \r\n }\r\n\r\n ViewModel.prototype = Object.create(Base.prototype);\r\n ViewModel.prototype.constructor = ViewModel;\r\n\r\n return ViewModel;\r\n})","define('viewmodels/disposable_es5', [\r\n 'managers/disposables'\r\n], function (Disposables) {\r\n function ViewModel() {\r\n this.__initialized = false;\r\n this.__initTasks = [];\r\n\r\n this.disposables = new Disposables();\r\n }\r\n\r\n ViewModel.prototype.beforeInit = function () {\r\n _(this.__initTasks).each(function (func) { func() });\r\n this.__initialized = true;\r\n };\r\n\r\n ViewModel.prototype.init = function () {};\r\n\r\n ViewModel.prototype.dispose = function () {\r\n this.disposables.dispose();\r\n };\r\n\r\n ViewModel.prototype._register = function (field) {\r\n if (this.__initialized) {\r\n this.disposables.register(field);\r\n } else {\r\n this.__initTasks.push(function () {\r\n this.disposables.register(field);\r\n }.bind(this));\r\n }\r\n\r\n return field;\r\n };\r\n\r\n ViewModel.prototype._registerObservable = function (field, init, dispose) {\r\n if (this.__initialized) {\r\n this.disposables.registerObservable(field, init, dispose);\r\n } else {\r\n this.__initTasks.push(function () {\r\n this.disposables.registerObservable(field, init, dispose);\r\n }.bind(this));\r\n }\r\n\r\n return field;\r\n };\r\n\r\n return ViewModel;\r\n});"],"sourceRoot":""}