@tko/utils.component
Advanced tools
+30
-1
@@ -1,8 +0,22 @@ | ||
| // @tko/utils.component 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils.component 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { LifeCycle } from "@tko/lifecycle"; | ||
| import { register, VIEW_MODEL_FACTORY } from "./loaders"; | ||
| export class ComponentABC extends LifeCycle { | ||
| /** | ||
| * The tag name of the custom element. For example 'my-component'. | ||
| * By default converts the class name from camel case to kebab case. | ||
| * @return {string} The custom node name of this component. | ||
| */ | ||
| static get customElementName() { | ||
| return this.name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(); | ||
| } | ||
| /** | ||
| * Overload this to return: | ||
| * 1. A string of markup | ||
| * 2. An array of DOM nodes | ||
| * 3. A document fragment | ||
| * 4. An AMD module (with `{require: 'some/template'}`) | ||
| * @return {mixed} One of the accepted template types for the ComponentBinding. | ||
| */ | ||
| static get template() { | ||
@@ -14,8 +28,23 @@ if ("template" in this.prototype) { | ||
| } | ||
| /** | ||
| * This is called by the default `template`. Overload this to return: | ||
| * 1. The element ID | ||
| * 2. A DOM node itself | ||
| * @return {string|HTMLElement} either the element ID or actual element. | ||
| */ | ||
| static get element() { | ||
| throw new Error("[ComponentABC] `element` must be overloaded."); | ||
| } | ||
| /** | ||
| * @return {bool} True if the component shall load synchronously | ||
| */ | ||
| static get sync() { | ||
| return true; | ||
| } | ||
| /** | ||
| * Construct a new instance of the model. When using ComponentABC as a | ||
| * base class, we do pass in the $element and $componentTemplateNodes. | ||
| * @param {Object} params | ||
| * @param {{element: HTMLElement, templateNodes: [HTMLElement]}} componentInfo | ||
| */ | ||
| static [VIEW_MODEL_FACTORY](params, componentInfo) { | ||
@@ -22,0 +51,0 @@ return new this(params, componentInfo); |
| { | ||
| "version": 3, | ||
| "sources": ["../src/ComponentABC.ts"], | ||
| "sourcesContent": ["/**\n * Component --- Abstract Base Class\n *\n * This simplifies and compartmentalizes Components. Use this:\n *\n * class CompX extends ComponentABC {\n * \tstatic get element () { return 'comp-x-id' }\n * \tstatic get sync () { return false }\n * \tstatic get elementName () { return 'comp-x' }\n * }\n * CompX.register()\n *\n * instead of:\n *\n * class CompX {}\n *\n * ko.components.register('comp-x', {\n * viewModel: CompX,\n * synchronous: false,\n * template: { element: 'comp-x' }\n * })\n *\n * As well, gain all the benefits of a LifeCycle, namely automated\n * event and subscription addition/removal.\n *\n * NOTE: A Component created this way can add events to the component node\n * with `this.addEventListener(type, action)`.\n */\nimport {LifeCycle} from '@tko/lifecycle'\nimport {register, VIEW_MODEL_FACTORY} from './loaders'\n\nexport class ComponentABC extends LifeCycle {\n\t/**\n * The tag name of the custom element. For example 'my-component'.\n * By default converts the class name from camel case to kebab case.\n\t * @return {string} The custom node name of this component.\n\t */\n static get customElementName () {\n return this.name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()\n }\n\n\t/**\n\t * Overload this to return:\n\t * 1. A string of markup\n\t * 2. An array of DOM nodes\n\t * 3. A document fragment\n\t * 4. An AMD module (with `{require: 'some/template'}`)\n\t * @return {mixed} One of the accepted template types for the ComponentBinding.\n\t */\n static get template () {\n if ('template' in this.prototype) { return }\n return { element: this.element }\n }\n\n\t/**\n\t * This is called by the default `template`. Overload this to return:\n\t * 1. The element ID\n\t * 2. A DOM node itself\n\t * @return {string|HTMLElement} either the element ID or actual element.\n\t */\n static get element () {\n throw new Error('[ComponentABC] `element` must be overloaded.')\n }\n\n\t/**\n\t * @return {bool} True if the component shall load synchronously\n\t */\n static get sync () { return true }\n\n /**\n * Construct a new instance of the model. When using ComponentABC as a\n * base class, we do pass in the $element and $componentTemplateNodes.\n * @param {Object} params\n * @param {{element: HTMLElement, templateNodes: [HTMLElement]}} componentInfo\n */\n static [VIEW_MODEL_FACTORY] (params, componentInfo) {\n return new this(params, componentInfo)\n }\n\n static register (name = this.customElementName) {\n const viewModel = this\n const {template} = this\n const synchronous = this.sync\n register(name, { viewModel, template, synchronous })\n }\n}\n"], | ||
| "mappings": ";AA4BA;AACA;AAEO,aAAM,qBAAqB,UAAU;AAAA,aAM/B,oBAAqB;AAC9B,WAAO,KAAK,KAAK,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AAAA,EACtE;AAAA,aAUW,WAAY;AACrB,QAAI,cAAc,KAAK,WAAW;AAAE;AAAA,IAAO;AAC3C,WAAO,EAAE,SAAS,KAAK,QAAQ;AAAA,EACjC;AAAA,aAQW,UAAW;AACpB,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAAA,aAKW,OAAQ;AAAE,WAAO;AAAA,EAAK;AAAA,UAQzB,oBAAqB,QAAQ,eAAe;AAClD,WAAO,IAAI,KAAK,QAAQ,aAAa;AAAA,EACvC;AAAA,SAEO,SAAU,OAAO,KAAK,mBAAmB;AAC9C,UAAM,YAAY;AAClB,UAAM,EAAC,aAAY;AACnB,UAAM,cAAc,KAAK;AACzB,aAAS,MAAM,EAAE,WAAW,UAAU,YAAY,CAAC;AAAA,EACrD;AACF;", | ||
| "sourcesContent": ["/**\n * Component --- Abstract Base Class\n *\n * This simplifies and compartmentalizes Components. Use this:\n *\n * class CompX extends ComponentABC {\n * \tstatic get element () { return 'comp-x-id' }\n * \tstatic get sync () { return false }\n * \tstatic get elementName () { return 'comp-x' }\n * }\n * CompX.register()\n *\n * instead of:\n *\n * class CompX {}\n *\n * ko.components.register('comp-x', {\n * viewModel: CompX,\n * synchronous: false,\n * template: { element: 'comp-x' }\n * })\n *\n * As well, gain all the benefits of a LifeCycle, namely automated\n * event and subscription addition/removal.\n *\n * NOTE: A Component created this way can add events to the component node\n * with `this.addEventListener(type, action)`.\n */\nimport { LifeCycle } from '@tko/lifecycle'\nimport { register, VIEW_MODEL_FACTORY } from './loaders'\n\nexport class ComponentABC extends LifeCycle {\n /**\n * The tag name of the custom element. For example 'my-component'.\n * By default converts the class name from camel case to kebab case.\n * @return {string} The custom node name of this component.\n */\n static get customElementName() {\n return this.name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()\n }\n\n /**\n * Overload this to return:\n * 1. A string of markup\n * 2. An array of DOM nodes\n * 3. A document fragment\n * 4. An AMD module (with `{require: 'some/template'}`)\n * @return {mixed} One of the accepted template types for the ComponentBinding.\n */\n static get template(): any {\n if ('template' in this.prototype) {\n return\n }\n return { element: this.element }\n }\n\n /**\n * This is called by the default `template`. Overload this to return:\n * 1. The element ID\n * 2. A DOM node itself\n * @return {string|HTMLElement} either the element ID or actual element.\n */\n static get element() {\n throw new Error('[ComponentABC] `element` must be overloaded.')\n }\n\n /**\n * @return {bool} True if the component shall load synchronously\n */\n static get sync() {\n return true\n }\n\n /**\n * Construct a new instance of the model. When using ComponentABC as a\n * base class, we do pass in the $element and $componentTemplateNodes.\n * @param {Object} params\n * @param {{element: HTMLElement, templateNodes: [HTMLElement]}} componentInfo\n */\n static [VIEW_MODEL_FACTORY](params: object, componentInfo: ComponentInfo): ComponentABC {\n return new (this as any)(params, componentInfo)\n }\n\n static register(name = this.customElementName) {\n const viewModel = this\n const { template } = this\n const synchronous = this.sync\n register(name, { viewModel, template, synchronous })\n }\n}\ninterface ComponentInfo {\n element: HTMLElement\n templateNodes: HTMLElement[]\n}\n"], | ||
| "mappings": ";;AA4BA,SAAS,iBAAiB;AAC1B,SAAS,UAAU,0BAA0B;AAEtC,aAAM,qBAAqB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1C,WAAW,oBAAoB;AAC7B,WAAO,KAAK,KAAK,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,WAAW,WAAgB;AACzB,QAAI,cAAc,KAAK,WAAW;AAChC;AAAA,IACF;AACA,WAAO,EAAE,SAAS,KAAK,QAAQ;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,UAAU;AACnB,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,OAAO;AAChB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAQ,kBAAkB,EAAE,QAAgB,eAA4C;AACtF,WAAO,IAAK,KAAa,QAAQ,aAAa;AAAA,EAChD;AAAA,EAEA,OAAO,SAAS,OAAO,KAAK,mBAAmB;AAC7C,UAAM,YAAY;AAClB,UAAM,EAAE,SAAS,IAAI;AACrB,UAAM,cAAc,KAAK;AACzB,aAAS,MAAM,EAAE,WAAW,UAAU,YAAY,CAAC;AAAA,EACrD;AACF;", | ||
| "names": [] | ||
| } |
+6
-8
@@ -1,16 +0,13 @@ | ||
| // @tko/utils.component 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils.component 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { registry } from "./registry"; | ||
| import { ComponentABC } from "./ComponentABC"; | ||
| import { | ||
| register, | ||
| isRegistered, | ||
| unregister, | ||
| defaultLoader, | ||
| defaultConfigRegistry | ||
| } from "./loaders"; | ||
| import { register, isRegistered, unregister, defaultLoader, defaultConfigRegistry } from "./loaders"; | ||
| export { ComponentABC }; | ||
| export default { | ||
| ComponentABC, | ||
| // -- Registry -- | ||
| get: registry.get, | ||
| clearCachedDefinition: registry.clearCachedDefinition, | ||
| // -- Loader -- | ||
| register, | ||
@@ -20,2 +17,3 @@ isRegistered, | ||
| defaultLoader, | ||
| // "Privately" expose the underlying config registry for use in old-IE shim | ||
| _allRegisteredComponents: defaultConfigRegistry, | ||
@@ -22,0 +20,0 @@ get loaders() { |
| { | ||
| "version": 3, | ||
| "sources": ["../src/index.ts"], | ||
| "sourcesContent": ["\nimport {registry} from './registry'\n\nimport { ComponentABC } from './ComponentABC'\n\nimport {\n register,\n isRegistered,\n unregister,\n defaultLoader,\n defaultConfigRegistry\n} from './loaders'\n\nexport { ComponentABC }\n\nexport default {\n ComponentABC,\n // -- Registry --\n get: registry.get,\n clearCachedDefinition: registry.clearCachedDefinition,\n\n // -- Loader --\n register,\n isRegistered,\n unregister,\n defaultLoader,\n // \"Privately\" expose the underlying config registry for use in old-IE shim\n _allRegisteredComponents: defaultConfigRegistry,\n\n get loaders () { return registry.loaders },\n set loaders (loaders) { registry.loaders = loaders }\n}\n"], | ||
| "mappings": ";AACA;AAEA;AAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AAEA,eAAe;AAAA,EACb;AAAA,EAEA,KAAK,SAAS;AAAA,EACd,uBAAuB,SAAS;AAAA,EAGhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,0BAA0B;AAAA,MAEtB,UAAW;AAAE,WAAO,SAAS;AAAA,EAAQ;AAAA,MACrC,QAAS,SAAS;AAAE,aAAS,UAAU;AAAA,EAAQ;AACrD;", | ||
| "sourcesContent": ["import { registry } from './registry'\n\nimport { ComponentABC } from './ComponentABC'\n\nimport { register, isRegistered, unregister, defaultLoader, defaultConfigRegistry } from './loaders'\n\nexport { ComponentABC }\n\nexport default {\n ComponentABC,\n // -- Registry --\n get: registry.get,\n clearCachedDefinition: registry.clearCachedDefinition,\n\n // -- Loader --\n register,\n isRegistered,\n unregister,\n defaultLoader,\n // \"Privately\" expose the underlying config registry for use in old-IE shim\n _allRegisteredComponents: defaultConfigRegistry,\n\n get loaders() {\n return registry.loaders\n },\n set loaders(loaders) {\n registry.loaders = loaders\n }\n}\n"], | ||
| "mappings": ";;AAAA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;AAE7B,SAAS,UAAU,cAAc,YAAY,eAAe,6BAA6B;AAEzF,SAAS;AAET,eAAe;AAAA,EACb;AAAA;AAAA,EAEA,KAAK,SAAS;AAAA,EACd,uBAAuB,SAAS;AAAA;AAAA,EAGhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA,0BAA0B;AAAA,EAE1B,IAAI,UAAU;AACZ,WAAO,SAAS;AAAA,EAClB;AAAA,EACA,IAAI,QAAQ,SAAS;AACnB,aAAS,UAAU;AAAA,EACrB;AACF;", | ||
| "names": [] | ||
| } |
+6
-8
@@ -1,16 +0,13 @@ | ||
| // @tko/utils.component 🥊 4.0.0-beta1.3 MJS | ||
| // @tko/utils.component 🥊 4.0.0 MJS | ||
| "use strict"; | ||
| import { registry } from "./registry"; | ||
| import { ComponentABC } from "./ComponentABC"; | ||
| import { | ||
| register, | ||
| isRegistered, | ||
| unregister, | ||
| defaultLoader, | ||
| defaultConfigRegistry | ||
| } from "./loaders"; | ||
| import { register, isRegistered, unregister, defaultLoader, defaultConfigRegistry } from "./loaders"; | ||
| export { ComponentABC }; | ||
| export default { | ||
| ComponentABC, | ||
| // -- Registry -- | ||
| get: registry.get, | ||
| clearCachedDefinition: registry.clearCachedDefinition, | ||
| // -- Loader -- | ||
| register, | ||
@@ -20,2 +17,3 @@ isRegistered, | ||
| defaultLoader, | ||
| // "Privately" expose the underlying config registry for use in old-IE shim | ||
| _allRegisteredComponents: defaultConfigRegistry, | ||
@@ -22,0 +20,0 @@ get loaders() { |
| { | ||
| "version": 3, | ||
| "sources": ["../src/index.ts"], | ||
| "sourcesContent": ["\nimport {registry} from './registry'\n\nimport { ComponentABC } from './ComponentABC'\n\nimport {\n register,\n isRegistered,\n unregister,\n defaultLoader,\n defaultConfigRegistry\n} from './loaders'\n\nexport { ComponentABC }\n\nexport default {\n ComponentABC,\n // -- Registry --\n get: registry.get,\n clearCachedDefinition: registry.clearCachedDefinition,\n\n // -- Loader --\n register,\n isRegistered,\n unregister,\n defaultLoader,\n // \"Privately\" expose the underlying config registry for use in old-IE shim\n _allRegisteredComponents: defaultConfigRegistry,\n\n get loaders () { return registry.loaders },\n set loaders (loaders) { registry.loaders = loaders }\n}\n"], | ||
| "mappings": ";AACA;AAEA;AAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AAEA,eAAe;AAAA,EACb;AAAA,EAEA,KAAK,SAAS;AAAA,EACd,uBAAuB,SAAS;AAAA,EAGhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,0BAA0B;AAAA,MAEtB,UAAW;AAAE,WAAO,SAAS;AAAA,EAAQ;AAAA,MACrC,QAAS,SAAS;AAAE,aAAS,UAAU;AAAA,EAAQ;AACrD;", | ||
| "sourcesContent": ["import { registry } from './registry'\n\nimport { ComponentABC } from './ComponentABC'\n\nimport { register, isRegistered, unregister, defaultLoader, defaultConfigRegistry } from './loaders'\n\nexport { ComponentABC }\n\nexport default {\n ComponentABC,\n // -- Registry --\n get: registry.get,\n clearCachedDefinition: registry.clearCachedDefinition,\n\n // -- Loader --\n register,\n isRegistered,\n unregister,\n defaultLoader,\n // \"Privately\" expose the underlying config registry for use in old-IE shim\n _allRegisteredComponents: defaultConfigRegistry,\n\n get loaders() {\n return registry.loaders\n },\n set loaders(loaders) {\n registry.loaders = loaders\n }\n}\n"], | ||
| "mappings": ";;AAAA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;AAE7B,SAAS,UAAU,cAAc,YAAY,eAAe,6BAA6B;AAEzF,SAAS;AAET,eAAe;AAAA,EACb;AAAA;AAAA,EAEA,KAAK,SAAS;AAAA,EACd,uBAAuB,SAAS;AAAA;AAAA,EAGhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA,0BAA0B;AAAA,EAE1B,IAAI,UAAU;AACZ,WAAO,SAAS;AAAA,EAClB;AAAA,EACA,IAAI,QAAQ,SAAS;AACnB,aAAS,UAAU;AAAA,EACrB;AACF;", | ||
| "names": [] | ||
| } |
+18
-15
@@ -1,2 +0,3 @@ | ||
| // @tko/utils.component 🥊 4.0.0-beta1.3 ESM | ||
| // @tko/utils.component 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { | ||
@@ -12,4 +13,4 @@ isDomElement, | ||
| import { registry } from "./registry"; | ||
| export var defaultConfigRegistry = {}; | ||
| export const VIEW_MODEL_FACTORY = Symbol("Knockout View Model ViewModel factory"); | ||
| export const defaultConfigRegistry = {}; | ||
| export const VIEW_MODEL_FACTORY = /* @__PURE__ */ Symbol("Knockout View Model ViewModel factory"); | ||
| export function register(componentName, config) { | ||
@@ -39,9 +40,9 @@ if (!config) { | ||
| } | ||
| export var defaultLoader = { | ||
| getConfig: function(componentName, callback) { | ||
| var result = hasOwnProperty(defaultConfigRegistry, componentName) ? defaultConfigRegistry[componentName] : null; | ||
| export const defaultLoader = { | ||
| getConfig(componentName, callback) { | ||
| const result = hasOwnProperty(defaultConfigRegistry, componentName) ? defaultConfigRegistry[componentName] : null; | ||
| callback(result); | ||
| }, | ||
| loadComponent: function(componentName, config, callback) { | ||
| var errorCallback = makeErrorCallback(componentName); | ||
| loadComponent(componentName, config, callback) { | ||
| const errorCallback = makeErrorCallback(componentName); | ||
| possiblyGetConfigFromAmd(errorCallback, config, function(loadedConfig) { | ||
@@ -51,12 +52,12 @@ resolveConfig(componentName, errorCallback, loadedConfig, callback); | ||
| }, | ||
| loadTemplate: function(componentName, templateConfig, callback) { | ||
| loadTemplate(componentName, templateConfig, callback) { | ||
| resolveTemplate(makeErrorCallback(componentName), templateConfig, callback); | ||
| }, | ||
| loadViewModel: function(componentName, viewModelConfig, callback) { | ||
| loadViewModel(componentName, viewModelConfig, callback) { | ||
| resolveViewModel(makeErrorCallback(componentName), viewModelConfig, callback); | ||
| } | ||
| }; | ||
| var createViewModelKey = "createViewModel"; | ||
| const createViewModelKey = "createViewModel"; | ||
| function resolveConfig(componentName, errorCallback, config, callback) { | ||
| var result = {}, makeCallBackWhenZero = 2, tryIssueCallback = function() { | ||
| const result = {}, tryIssueCallback = function() { | ||
| if (--makeCallBackWhenZero === 0) { | ||
@@ -66,2 +67,3 @@ callback(result); | ||
| }, templateConfig = config["template"], viewModelConfig = config["viewModel"]; | ||
| let makeCallBackWhenZero = 2; | ||
| if (templateConfig) { | ||
@@ -96,7 +98,7 @@ possiblyGetConfigFromAmd(errorCallback, templateConfig, function(loadedConfig) { | ||
| } else if (templateConfig.element) { | ||
| var element = templateConfig.element; | ||
| const element = templateConfig.element; | ||
| if (isDomElement(element)) { | ||
| callback(cloneNodesFromTemplateSourceElement(element)); | ||
| } else if (typeof element === "string") { | ||
| var elemInstance = document.getElementById(element); | ||
| const elemInstance = document.getElementById(element); | ||
| if (elemInstance) { | ||
@@ -126,3 +128,3 @@ callback(cloneNodesFromTemplateSourceElement(elemInstance)); | ||
| } else if ("instance" in viewModelConfig) { | ||
| var fixedInstance = viewModelConfig["instance"]; | ||
| const fixedInstance = viewModelConfig["instance"]; | ||
| callback(function() { | ||
@@ -153,2 +155,3 @@ return fixedInstance; | ||
| if (window.amdRequire || window.require) { | ||
| ; | ||
| (window.amdRequire || window.require)([config.require], callback); | ||
@@ -155,0 +158,0 @@ } else { |
| { | ||
| "version": 3, | ||
| "sources": ["../src/loaders.ts"], | ||
| "sourcesContent": ["\nimport {\n isDomElement, isDocumentFragment, tagNameLower, parseHtmlFragment,\n makeArray, cloneNodes, hasOwnProperty\n} from '@tko/utils'\n\nimport {registry} from './registry'\n\n// The default loader is responsible for two things:\n// 1. Maintaining the default in-memory registry of component configuration objects\n// (i.e., the thing you're writing to when you call ko.components.register(someName, ...))\n// 2. Answering requests for components by fetching configuration objects\n// from that default in-memory registry and resolving them into standard\n// component definition objects (of the form { createViewModel: ..., template: ... })\n// Custom loaders may override either of these facilities, i.e.,\n// 1. To supply configuration objects from some other source (e.g., conventions)\n// 2. Or, to resolve configuration objects by loading viewmodels/templates via arbitrary logic.\n\nexport var defaultConfigRegistry = {}\nexport const VIEW_MODEL_FACTORY = Symbol('Knockout View Model ViewModel factory')\n\nexport function register (componentName, config) {\n if (!config) {\n throw new Error('Invalid configuration for ' + componentName)\n }\n\n if (isRegistered(componentName)) {\n throw new Error('Component ' + componentName + ' is already registered')\n }\n\n const ceok = componentName.includes('-') && componentName.toLowerCase() === componentName\n\n if (!config.ignoreCustomElementWarning && !ceok) {\n console.log(`\n\uD83E\uDD4A Knockout warning: components for custom elements must be lowercase and contain a dash. To ignore this warning, add to the 'config' of .register(componentName, config):\n\n ignoreCustomElementWarning: true\n `)\n }\n\n defaultConfigRegistry[componentName] = config\n}\n\nexport function isRegistered (componentName) {\n return hasOwnProperty(defaultConfigRegistry, componentName)\n}\n\nexport function unregister (componentName) {\n delete defaultConfigRegistry[componentName]\n registry.clearCachedDefinition(componentName)\n}\n\nexport var defaultLoader = {\n getConfig: function (componentName, callback) {\n var result = hasOwnProperty(defaultConfigRegistry, componentName)\n ? defaultConfigRegistry[componentName]\n : null\n callback(result)\n },\n\n loadComponent: function (componentName, config, callback) {\n var errorCallback = makeErrorCallback(componentName)\n possiblyGetConfigFromAmd(errorCallback, config, function (loadedConfig) {\n resolveConfig(componentName, errorCallback, loadedConfig, callback)\n })\n },\n\n loadTemplate: function (componentName, templateConfig, callback) {\n resolveTemplate(makeErrorCallback(componentName), templateConfig, callback)\n },\n\n loadViewModel: function (componentName, viewModelConfig, callback) {\n resolveViewModel(makeErrorCallback(componentName), viewModelConfig, callback)\n }\n}\n\nvar createViewModelKey = 'createViewModel'\n\n// Takes a config object of the form { template: ..., viewModel: ... }, and asynchronously convert it\n// into the standard component definition format:\n// { template: <ArrayOfDomNodes>, createViewModel: function(params, componentInfo) { ... } }.\n// Since both template and viewModel may need to be resolved asynchronously, both tasks are performed\n// in parallel, and the results joined when both are ready. We don't depend on any promises infrastructure,\n// so this is implemented manually below.\nfunction resolveConfig (componentName, errorCallback, config, callback) {\n var result = {},\n makeCallBackWhenZero = 2,\n tryIssueCallback = function () {\n if (--makeCallBackWhenZero === 0) {\n callback(result)\n }\n },\n templateConfig = config['template'],\n viewModelConfig = config['viewModel']\n\n if (templateConfig) {\n possiblyGetConfigFromAmd(errorCallback, templateConfig, function (loadedConfig) {\n registry._getFirstResultFromLoaders('loadTemplate', [componentName, loadedConfig], function (resolvedTemplate) {\n result['template'] = resolvedTemplate\n tryIssueCallback()\n })\n })\n } else {\n tryIssueCallback()\n }\n\n if (viewModelConfig) {\n possiblyGetConfigFromAmd(errorCallback, viewModelConfig, function (loadedConfig) {\n registry._getFirstResultFromLoaders('loadViewModel', [componentName, loadedConfig], function (resolvedViewModel) {\n result[createViewModelKey] = resolvedViewModel\n tryIssueCallback()\n })\n })\n } else {\n tryIssueCallback()\n }\n}\n\nfunction resolveTemplate (errorCallback, templateConfig, callback) {\n if (typeof templateConfig === 'string') {\n // Markup - parse it\n callback(parseHtmlFragment(templateConfig))\n } else if (templateConfig instanceof Array) {\n // Assume already an array of DOM nodes - pass through unchanged\n callback(templateConfig)\n } else if (isDocumentFragment(templateConfig)) {\n // Document fragment - use its child nodes\n callback(makeArray(templateConfig.childNodes))\n } else if (templateConfig.element) {\n var element = templateConfig.element\n if (isDomElement(element)) {\n // Element instance - copy its child nodes\n callback(cloneNodesFromTemplateSourceElement(element))\n } else if (typeof element === 'string') {\n // Element ID - find it, then copy its child nodes\n var elemInstance = document.getElementById(element)\n if (elemInstance) {\n callback(cloneNodesFromTemplateSourceElement(elemInstance))\n } else {\n errorCallback('Cannot find element with ID ' + element)\n }\n } else {\n errorCallback('Unknown element type: ' + element)\n }\n } else if (templateConfig.elementName) {\n // JSX in the style of babel-plugin-transform-jsx\n callback(templateConfig)\n } else {\n errorCallback('Unknown template value: ' + templateConfig)\n }\n}\n\nfunction resolveViewModel (errorCallback, viewModelConfig, callback) {\n if (viewModelConfig[VIEW_MODEL_FACTORY]) {\n callback((...args) => viewModelConfig[VIEW_MODEL_FACTORY](...args))\n } else if (typeof viewModelConfig === 'function') {\n // Constructor - convert to standard factory function format\n // By design, this does *not* supply componentInfo to the constructor, as the intent is that\n // componentInfo contains non-viewmodel data (e.g., the component's element) that should only\n // be used in factory functions, not viewmodel constructors.\n callback(function (params /*, componentInfo */) {\n return new viewModelConfig(params)\n })\n } else if (typeof viewModelConfig[createViewModelKey] === 'function') {\n // Already a factory function - use it as-is\n callback(viewModelConfig[createViewModelKey])\n } else if ('instance' in viewModelConfig) {\n // Fixed object instance - promote to createViewModel format for API consistency\n var fixedInstance = viewModelConfig['instance']\n callback(function (/* params, componentInfo */) {\n return fixedInstance\n })\n } else if ('viewModel' in viewModelConfig) {\n // Resolved AMD module whose value is of the form { viewModel: ... }\n resolveViewModel(errorCallback, viewModelConfig['viewModel'], callback)\n } else {\n errorCallback('Unknown viewModel value: ' + viewModelConfig)\n }\n}\n\nfunction cloneNodesFromTemplateSourceElement (elemInstance) {\n switch (tagNameLower(elemInstance)) {\n case 'script':\n return parseHtmlFragment(elemInstance.text)\n case 'textarea':\n return parseHtmlFragment(elemInstance.value)\n case 'template':\n // For browsers with proper <template> element support (i.e., where the .content property\n // gives a document fragment), use that document fragment.\n if (isDocumentFragment(elemInstance.content)) {\n return cloneNodes(elemInstance.content.childNodes)\n }\n }\n\n // Regular elements such as <div>, and <template> elements on old browsers that don't really\n // understand <template> and just treat it as a regular container\n return cloneNodes(elemInstance.childNodes)\n}\n\nfunction possiblyGetConfigFromAmd (errorCallback, config, callback) {\n if (typeof config.require === 'string') {\n // The config is the value of an AMD module\n if (window.amdRequire || window.require) {\n (window.amdRequire || window.require)([config.require], callback)\n } else {\n errorCallback('Uses require, but no AMD loader is present')\n }\n } else {\n callback(config)\n }\n}\n\nfunction makeErrorCallback (componentName) {\n return function (message) {\n throw new Error('Component \\'' + componentName + '\\': ' + message)\n }\n}\n\n// By default, the default loader is the only registered component loader\nregistry.loaders.push(defaultLoader)\n"], | ||
| "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA;AAYO,WAAI,wBAAwB,CAAC;AAC7B,aAAM,qBAAqB,OAAO,uCAAuC;AAEzE,yBAAmB,eAAe,QAAQ;AAC/C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,+BAA+B,aAAa;AAAA,EAC9D;AAEA,MAAI,aAAa,aAAa,GAAG;AAC/B,UAAM,IAAI,MAAM,eAAe,gBAAgB,wBAAwB;AAAA,EACzE;AAEA,QAAM,OAAO,cAAc,SAAS,GAAG,KAAK,cAAc,YAAY,MAAM;AAE5E,MAA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AA,IACnC,CAAC;AAAA,EACH,WAAW,OAAO,gBAAgB,wBAAwB,YAAY;AAEpE,aAAS,gBAAgB,mBAAmB;AAAA,EAC9C,WAAW,cAAc,iBAAiB;AAExC,QAAI,gBAAgB,gBAAgB;AACpC,aAAS,WAAuC;AAC9C,aAAO;AAAA,IACT,CAAC;AAAA,EACH,WAAW,eAAe,iBAAiB;AAEzC,qBAAiB,eAAe,gBAAgB,cAAc,QAAQ;AAAA,EACxE,OAAO;AACL,kBAAc,8BAA8B,eAAe;AAAA,EAC7D;AACF;AAEA,6CAA8C,cAAc;AAC1D,UAAQ,aAAa,YAAY;AAAA,SAC1B;AACH,aAAO,kBAAkB,aAAa,IAAI;AAAA,SACvC;AACH,aAAO,kBAAkB,aAAa,KAAK;AAAA,SACxC;AAGH,UAAI,mBAAmB,aAAa,OAAO,GAAG;AAC5C,eAAO,WAAW,aAAa,QAAQ,UAAU;AAAA,MACnD;AAAA;AAKJ,SAAO,WAAW,aAAa,UAAU;AAC3C;AAEA,kCAAmC,eAAe,QAAQ,UAAU;AAClE,MAAI,OAAO,OAAO,YAAY,UAAU;AAEtC,QAAI,OAAO,cAAc,OAAO,SAAS;AACvC,MAAC,QAAO,cAAc,OAAO,SAAS,CAAC,OAAO,OAAO,GAAG,QAAQ;AAAA,IAClE,OAAO;AACL,oBAAc,4CAA4C;AAAA,IAC5D;AAAA,EACF,OAAO;AACL,aAAS,MAAM;AAAA,EACjB;AACF;AAEA,2BAA4B,eAAe;AACzC,SAAO,SAAU,SAAS;AACxB,UAAM,IAAI,MAAM,gBAAiB,gBAAgB,QAAS,OAAO;AAAA,EACnE;AACF;AAGA,SAAS,QAAQ,KAAK,aAAa;", | ||
| "sourcesContent": ["import {\n isDomElement,\n isDocumentFragment,\n tagNameLower,\n parseHtmlFragment,\n makeArray,\n cloneNodes,\n hasOwnProperty\n} from '@tko/utils'\n\nimport { registry } from './registry'\n\n// The default loader is responsible for two things:\n// 1. Maintaining the default in-memory registry of component configuration objects\n// (i.e., the thing you're writing to when you call ko.components.register(someName, ...))\n// 2. Answering requests for components by fetching configuration objects\n// from that default in-memory registry and resolving them into standard\n// component definition objects (of the form { createViewModel: ..., template: ... })\n// Custom loaders may override either of these facilities, i.e.,\n// 1. To supply configuration objects from some other source (e.g., conventions)\n// 2. Or, to resolve configuration objects by loading viewmodels/templates via arbitrary logic.\n\nexport const defaultConfigRegistry: Record<string, Config> = {}\nexport const VIEW_MODEL_FACTORY = Symbol('Knockout View Model ViewModel factory')\n\nexport interface Component {\n template: Node[]\n createViewModel?: CreateViewModel\n}\nexport type CreateViewModel = (params: ViewModelParams, componentInfo: ComponentInfo) => ViewModel\n\nexport interface ViewModelParams {\n [name: string]: any\n}\n\nexport interface ComponentInfo {\n element: Node\n templateNodes: Node[]\n}\n\nexport interface ViewModel {\n dispose?: () => void\n koDescendantsComplete?: (node: Node) => void\n}\n\nexport interface Config {\n require?: string\n viewModel?: RequireConfig | ViewModelConfig | any\n template?: RequireConfig | TemplateConfig | any\n synchronous?: boolean\n ignoreCustomElementWarning?: boolean\n}\n\nexport interface ViewModelConstructor {\n new (params?: ViewModelParams): ViewModel\n}\n\nexport interface ViewModelStatic {\n instance: any\n}\nexport interface ViewModelFactory {\n createViewModel: CreateViewModel\n}\nexport interface TemplateElement {\n element: string | Node\n}\n\nexport type ViewModelConfig = ViewModelConstructor | ViewModelStatic | ViewModelFactory\nexport type TemplateConfig = string | Node[] | DocumentFragment | TemplateElement\n\nexport interface RequireConfig {\n require: string\n}\n\nexport function register(componentName: string, config: Config) {\n if (!config) {\n throw new Error('Invalid configuration for ' + componentName)\n }\n\n if (isRegistered(componentName)) {\n throw new Error('Component ' + componentName + ' is already registered')\n }\n\n const ceok = componentName.includes('-') && componentName.toLowerCase() === componentName\n\n if (!config.ignoreCustomElementWarning && !ceok) {\n console.log(`\n\uD83E\uDD4A Knockout warning: components for custom elements must be lowercase and contain a dash. To ignore this warning, add to the 'config' of .register(componentName, config):\n\n ignoreCustomElementWarning: true\n `)\n }\n\n defaultConfigRegistry[componentName] = config\n}\n\nexport function isRegistered(componentName: string): boolean {\n return hasOwnProperty(defaultConfigRegistry, componentName)\n}\n\nexport function unregister(componentName: string): void {\n delete defaultConfigRegistry[componentName]\n registry.clearCachedDefinition(componentName)\n}\n\nexport interface Loader {\n getConfig?(componentName: string, callback: (config: Config | null) => void): void\n loadComponent?(componentName: string, config: Config | object, callback: (component: Component | null) => void): void\n loadTemplate?(\n componentName: string,\n config: TemplateConfig | any,\n callback: (resolvedTemplate: Node[] | null) => void\n ): void\n loadViewModel?(\n componentName: string,\n config: ViewModelConfig | any,\n callback: (resolvedViewModel: CreateViewModel | null) => void\n ): void\n}\n\nexport const defaultLoader: Loader = {\n getConfig(componentName: string, callback: (config: Config | null) => void): void {\n const result = hasOwnProperty(defaultConfigRegistry, componentName) ? defaultConfigRegistry[componentName] : null\n callback(result)\n },\n\n loadComponent(componentName: string, config: Config, callback: (component: Component) => void): void {\n const errorCallback = makeErrorCallback(componentName)\n possiblyGetConfigFromAmd(errorCallback, config, function (loadedConfig) {\n resolveConfig(componentName, errorCallback, loadedConfig, callback)\n })\n },\n\n loadTemplate(\n componentName: string,\n templateConfig: TemplateConfig,\n callback: (resolvedTemplate: Node[]) => void\n ): void {\n resolveTemplate(makeErrorCallback(componentName), templateConfig, callback)\n },\n\n loadViewModel(\n componentName: string,\n viewModelConfig: ViewModelConfig,\n callback: (resolvedViewModel: CreateViewModel) => void\n ): void {\n resolveViewModel(makeErrorCallback(componentName), viewModelConfig, callback)\n }\n}\n\nconst createViewModelKey = 'createViewModel'\n\n// Takes a config object of the form { template: ..., viewModel: ... }, and asynchronously convert it\n// into the standard component definition format:\n// { template: <ArrayOfDomNodes>, createViewModel: function(params, componentInfo) { ... } }.\n// Since both template and viewModel may need to be resolved asynchronously, both tasks are performed\n// in parallel, and the results joined when both are ready. We don't depend on any promises infrastructure,\n// so this is implemented manually below.\nfunction resolveConfig(componentName, errorCallback, config, callback) {\n const result = {},\n tryIssueCallback = function () {\n if (--makeCallBackWhenZero === 0) {\n callback(result)\n }\n },\n templateConfig = config['template'],\n viewModelConfig = config['viewModel']\n\n let makeCallBackWhenZero = 2\n if (templateConfig) {\n possiblyGetConfigFromAmd(errorCallback, templateConfig, function (loadedConfig) {\n registry._getFirstResultFromLoaders('loadTemplate', [componentName, loadedConfig], function (resolvedTemplate) {\n result['template'] = resolvedTemplate\n tryIssueCallback()\n })\n })\n } else {\n tryIssueCallback()\n }\n\n if (viewModelConfig) {\n possiblyGetConfigFromAmd(errorCallback, viewModelConfig, function (loadedConfig) {\n registry._getFirstResultFromLoaders('loadViewModel', [componentName, loadedConfig], function (resolvedViewModel) {\n result[createViewModelKey] = resolvedViewModel\n tryIssueCallback()\n })\n })\n } else {\n tryIssueCallback()\n }\n}\n\nfunction resolveTemplate(errorCallback, templateConfig, callback) {\n if (typeof templateConfig === 'string') {\n // Markup - parse it\n callback(parseHtmlFragment(templateConfig))\n } else if (templateConfig instanceof Array) {\n // Assume already an array of DOM nodes - pass through unchanged\n callback(templateConfig)\n } else if (isDocumentFragment(templateConfig)) {\n // Document fragment - use its child nodes\n callback(makeArray(templateConfig.childNodes))\n } else if (templateConfig.element) {\n const element = templateConfig.element\n if (isDomElement(element)) {\n // Element instance - copy its child nodes\n callback(cloneNodesFromTemplateSourceElement(element))\n } else if (typeof element === 'string') {\n // Element ID - find it, then copy its child nodes\n const elemInstance = document.getElementById(element)\n if (elemInstance) {\n callback(cloneNodesFromTemplateSourceElement(elemInstance))\n } else {\n errorCallback('Cannot find element with ID ' + element)\n }\n } else {\n errorCallback('Unknown element type: ' + element)\n }\n } else if (templateConfig.elementName) {\n // JSX in the style of babel-plugin-transform-jsx\n callback(templateConfig)\n } else {\n errorCallback('Unknown template value: ' + templateConfig)\n }\n}\n\nfunction resolveViewModel(errorCallback, viewModelConfig, callback) {\n if (viewModelConfig[VIEW_MODEL_FACTORY]) {\n callback((...args) => viewModelConfig[VIEW_MODEL_FACTORY](...args))\n } else if (typeof viewModelConfig === 'function') {\n // Constructor - convert to standard factory function format\n // By design, this does *not* supply componentInfo to the constructor, as the intent is that\n // componentInfo contains non-viewmodel data (e.g., the component's element) that should only\n // be used in factory functions, not viewmodel constructors.\n callback(function (params /*, componentInfo */) {\n return new viewModelConfig(params)\n })\n } else if (typeof viewModelConfig[createViewModelKey] === 'function') {\n // Already a factory function - use it as-is\n callback(viewModelConfig[createViewModelKey])\n } else if ('instance' in viewModelConfig) {\n // Fixed object instance - promote to createViewModel format for API consistency\n const fixedInstance = viewModelConfig['instance']\n callback(function (/* params, componentInfo */) {\n return fixedInstance\n })\n } else if ('viewModel' in viewModelConfig) {\n // Resolved AMD module whose value is of the form { viewModel: ... }\n resolveViewModel(errorCallback, viewModelConfig['viewModel'], callback)\n } else {\n errorCallback('Unknown viewModel value: ' + viewModelConfig)\n }\n}\n\nfunction cloneNodesFromTemplateSourceElement(elemInstance) {\n switch (tagNameLower(elemInstance)) {\n case 'script':\n return parseHtmlFragment(elemInstance.text)\n case 'textarea':\n return parseHtmlFragment(elemInstance.value)\n case 'template':\n // For browsers with proper <template> element support (i.e., where the .content property\n // gives a document fragment), use that document fragment.\n if (isDocumentFragment(elemInstance.content)) {\n return cloneNodes(elemInstance.content.childNodes)\n }\n }\n\n // Regular elements such as <div>, and <template> elements on old browsers that don't really\n // understand <template> and just treat it as a regular container\n return cloneNodes(elemInstance.childNodes)\n}\n\nfunction possiblyGetConfigFromAmd(errorCallback, config, callback) {\n if (typeof config.require === 'string') {\n // The config is the value of an AMD module\n if (window.amdRequire || window.require) {\n ;(window.amdRequire || window.require)([config.require], callback)\n } else {\n errorCallback('Uses require, but no AMD loader is present')\n }\n } else {\n callback(config)\n }\n}\n\nfunction makeErrorCallback(componentName) {\n return function (message) {\n throw new Error(\"Component '\" + componentName + \"': \" + message)\n }\n}\n\n// By default, the default loader is the only registered component loader\nregistry.loaders.push(defaultLoader)\n"], | ||
| "mappings": ";;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EAC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AAI,OAAO,cAAc,OAAO,SAAS;AACvC;AAAC,OAAC,OAAO,cAAc,OAAO,SAAS,CAAC,OAAO,OAAO,GAAG,QAAQ;AAAA,IACnE,OAAO;AACL,oBAAc,4CAA4C;AAAA,IAC5D;AAAA,EACF,OAAO;AACL,aAAS,MAAM;AAAA,EACjB;AACF;AAEA,SAAS,kBAAkB,eAAe;AACxC,SAAO,SAAU,SAAS;AACxB,UAAM,IAAI,MAAM,gBAAgB,gBAAgB,QAAQ,OAAO;AAAA,EACjE;AACF;AAGA,SAAS,QAAQ,KAAK,aAAa;", | ||
| "names": [] | ||
| } |
+27
-27
@@ -1,13 +0,8 @@ | ||
| // @tko/utils.component 🥊 4.0.0-beta1.3 ESM | ||
| import { | ||
| subscribable, | ||
| dependencyDetection | ||
| } from "@tko/observable"; | ||
| import { | ||
| getObjectOwnProperty, | ||
| tasks | ||
| } from "@tko/utils"; | ||
| var loadingSubscribablesCache = {}, loadedDefinitionsCache = {}; | ||
| // @tko/utils.component 🥊 4.0.0 ESM | ||
| "use strict"; | ||
| import { subscribable, dependencyDetection } from "@tko/observable"; | ||
| import { getObjectOwnProperty, tasks } from "@tko/utils"; | ||
| const loadingSubscribablesCache = {}, loadedDefinitionsCache = {}; | ||
| function loadComponentAndNotify(componentName, callback) { | ||
| var _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName), completedAsync; | ||
| let _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName), completedAsync; | ||
| if (!_subscribable) { | ||
@@ -17,3 +12,3 @@ _subscribable = loadingSubscribablesCache[componentName] = new subscribable(); | ||
| beginLoadingComponent(componentName, function(definition, config) { | ||
| var isSynchronousComponent = !!(config && config.synchronous); | ||
| const isSynchronousComponent = !!(config && config.synchronous); | ||
| loadedDefinitionsCache[componentName] = { definition, isSynchronousComponent }; | ||
@@ -49,19 +44,24 @@ delete loadingSubscribablesCache[componentName]; | ||
| } | ||
| var currentCandidateLoader = candidateLoaders.shift(); | ||
| const currentCandidateLoader = candidateLoaders.shift(); | ||
| if (currentCandidateLoader) { | ||
| var methodInstance = currentCandidateLoader[methodName]; | ||
| const methodInstance = currentCandidateLoader[methodName]; | ||
| if (methodInstance) { | ||
| var wasAborted = false, synchronousReturnValue = methodInstance.apply(currentCandidateLoader, argsExceptCallback.concat(function(result) { | ||
| if (wasAborted) { | ||
| callback(null); | ||
| } else if (result !== null) { | ||
| callback(result); | ||
| } else { | ||
| getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders); | ||
| } | ||
| })); | ||
| let wasAborted = false, synchronousReturnValue = methodInstance.apply( | ||
| currentCandidateLoader, | ||
| argsExceptCallback.concat(function(result) { | ||
| if (wasAborted) { | ||
| callback(null); | ||
| } else if (result !== null) { | ||
| callback(result); | ||
| } else { | ||
| getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders); | ||
| } | ||
| }) | ||
| ); | ||
| if (synchronousReturnValue !== void 0) { | ||
| wasAborted = true; | ||
| if (!currentCandidateLoader.suppressLoaderExceptions) { | ||
| throw new Error("Component loaders must supply values by invoking the callback, not by returning values synchronously."); | ||
| throw new Error( | ||
| "Component loaders must supply values by invoking the callback, not by returning values synchronously." | ||
| ); | ||
| } | ||
@@ -76,5 +76,5 @@ } | ||
| } | ||
| export var registry = { | ||
| export const registry = { | ||
| get(componentName, callback) { | ||
| var cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName); | ||
| const cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName); | ||
| if (cachedDefinition) { | ||
@@ -98,3 +98,3 @@ if (cachedDefinition.isSynchronousComponent) { | ||
| _getFirstResultFromLoaders: getFirstResultFromLoaders, | ||
| loaders: [] | ||
| loaders: new Array() | ||
| }; |
| { | ||
| "version": 3, | ||
| "sources": ["../src/registry.ts"], | ||
| "sourcesContent": ["\nimport {\n subscribable, dependencyDetection\n} from '@tko/observable'\n\nimport {\n getObjectOwnProperty, tasks\n} from '@tko/utils'\n\nvar loadingSubscribablesCache = {}, // Tracks component loads that are currently in flight\n loadedDefinitionsCache = {} // Tracks component loads that have already completed\n\nfunction loadComponentAndNotify (componentName, callback) {\n var _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName),\n completedAsync\n if (!_subscribable) {\n // It's not started loading yet. Start loading, and when it's done, move it to loadedDefinitionsCache.\n _subscribable = loadingSubscribablesCache[componentName] = new subscribable()\n _subscribable.subscribe(callback)\n\n beginLoadingComponent(componentName, function (definition, config) {\n var isSynchronousComponent = !!(config && config.synchronous)\n loadedDefinitionsCache[componentName] = { definition: definition, isSynchronousComponent: isSynchronousComponent }\n delete loadingSubscribablesCache[componentName]\n\n // For API consistency, all loads complete asynchronously. However we want to avoid\n // adding an extra task schedule if it's unnecessary (i.e., the completion is already\n // async).\n //\n // You can bypass the 'always asynchronous' feature by putting the synchronous:true\n // flag on your component configuration when you register it.\n if (completedAsync || isSynchronousComponent) {\n // Note that notifySubscribers ignores any dependencies read within the callback.\n // See comment in loaderRegistryBehaviors.js for reasoning\n _subscribable.notifySubscribers(definition)\n } else {\n tasks.schedule(function () {\n _subscribable.notifySubscribers(definition)\n })\n }\n })\n completedAsync = true\n } else {\n _subscribable.subscribe(callback)\n }\n}\n\nfunction beginLoadingComponent (componentName, callback) {\n getFirstResultFromLoaders('getConfig', [componentName], function (config) {\n if (config) {\n // We have a config, so now load its definition\n getFirstResultFromLoaders('loadComponent', [componentName, config], function (definition) {\n callback(definition, config)\n })\n } else {\n // The component has no config - it's unknown to all the loaders.\n // Note that this is not an error (e.g., a module loading error) - that would abort the\n // process and this callback would not run. For this callback to run, all loaders must\n // have confirmed they don't know about this component.\n callback(null, null)\n }\n })\n}\n\nfunction getFirstResultFromLoaders (methodName, argsExceptCallback, callback, candidateLoaders) {\n // On the first call in the stack, start with the full set of loaders\n if (!candidateLoaders) {\n candidateLoaders = registry.loaders.slice(0) // Use a copy, because we'll be mutating this array\n }\n\n // Try the next candidate\n var currentCandidateLoader = candidateLoaders.shift()\n if (currentCandidateLoader) {\n var methodInstance = currentCandidateLoader[methodName]\n if (methodInstance) {\n var wasAborted = false,\n synchronousReturnValue = methodInstance.apply(currentCandidateLoader, argsExceptCallback.concat(function (result) {\n if (wasAborted) {\n callback(null)\n } else if (result !== null) {\n // This candidate returned a value. Use it.\n callback(result)\n } else {\n // Try the next candidate\n getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders)\n }\n }))\n\n // Currently, loaders may not return anything synchronously. This leaves open the possibility\n // that we'll extend the API to support synchronous return values in the future. It won't be\n // a breaking change, because currently no loader is allowed to return anything except undefined.\n if (synchronousReturnValue !== undefined) {\n wasAborted = true\n\n // Method to suppress exceptions will remain undocumented. This is only to keep\n // KO's specs running tidily, since we can observe the loading got aborted without\n // having exceptions cluttering up the console too.\n if (!currentCandidateLoader.suppressLoaderExceptions) {\n throw new Error('Component loaders must supply values by invoking the callback, not by returning values synchronously.')\n }\n }\n } else {\n // This candidate doesn't have the relevant handler. Synchronously move on to the next one.\n getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders)\n }\n } else {\n // No candidates returned a value\n callback(null)\n }\n}\n\nexport var registry = {\n get (componentName, callback) {\n var cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName)\n if (cachedDefinition) {\n // It's already loaded and cached. Reuse the same definition object.\n // Note that for API consistency, even cache hits complete asynchronously by default.\n // You can bypass this by putting synchronous:true on your component config.\n if (cachedDefinition.isSynchronousComponent) {\n dependencyDetection.ignore(function () { // See comment in loaderRegistryBehaviors.js for reasoning\n callback(cachedDefinition.definition)\n })\n } else {\n tasks.schedule(function () { callback(cachedDefinition.definition) })\n }\n } else {\n // Join the loading process that is already underway, or start a new one.\n loadComponentAndNotify(componentName, callback)\n }\n },\n\n clearCachedDefinition (componentName) {\n delete loadedDefinitionsCache[componentName]\n },\n\n _getFirstResultFromLoaders: getFirstResultFromLoaders,\n\n loaders: []\n}\n"], | ||
| "mappings": ";AACA;AAAA;AAAA;AAAA;AAIA;AAAA;AA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;AACd,mBAAS,IAAI;AAAA,QACf,WAAW,WAAW,MAAM;AAE1B,mBAAS,MAAM;AAAA,QACjB,OAAO;AAEL,oCAA0B,YAAY,oBAAoB,UAAU,gBAAgB;AAAA,QACtF;AAAA,MACF,CAAC,CAAC;AAKJ,UAAI,2BAA2B,QAAW;AACxC,qBAAa;AAKb,YAAI,CAAC,uBAAuB,0BAA0B;AACpD,gBAAM,IAAI,MAAM,uGAAuG;AAAA,QACzH;AAAA,MACF;AAAA,IACF,OAAO;AAEL,gCAA0B,YAAY,oBAAoB,UAAU,gBAAgB;AAAA,IACtF;AAAA,EACF,OAAO;AAEL,aAAS,IAAI;AAAA,EACf;AACF;AAEO,WAAI,WAAW;AAAA,EACpB,IAAK,eAAe,UAAU;AAC5B,QAAI,mBAAmB,qBAAqB,wBAAwB,aAAa;AACjF,QAAI,kBAAkB;AAIpB,UAAI,iBAAiB,wBAAwB;AAC3C,4BAAoB,OAAO,WAAY;AACrC,mBAAS,iBAAiB,UAAU;AAAA,QACtC,CAAC;AAAA,MACH,OAAO;AACL,cAAM,SAAS,WAAY;AAAE,mBAAS,iBAAiB,UAAU;AAAA,QAAE,CAAC;AAAA,MACtE;AAAA,IACF,OAAO;AAEL,6BAAuB,eAAe,QAAQ;AAAA,IAChD;AAAA,EACF;AAAA,EAEA,sBAAuB,eAAe;AACpC,WAAO,uBAAuB;AAAA,EAChC;AAAA,EAEA,4BAA4B;AAAA,EAE5B,SAAS,CAAC;AACZ;", | ||
| "sourcesContent": ["import { subscribable, dependencyDetection } from '@tko/observable'\nimport { getObjectOwnProperty, tasks } from '@tko/utils'\nimport type { Loader } from './loaders'\n\nconst loadingSubscribablesCache = {}, // Tracks component loads that are currently in flight\n loadedDefinitionsCache = {} // Tracks component loads that have already completed\n\nfunction loadComponentAndNotify(componentName: string, callback: any): void {\n let _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName),\n completedAsync\n if (!_subscribable) {\n // It's not started loading yet. Start loading, and when it's done, move it to loadedDefinitionsCache.\n _subscribable = loadingSubscribablesCache[componentName] = new subscribable()\n _subscribable.subscribe(callback)\n\n beginLoadingComponent(componentName, function (definition, config) {\n const isSynchronousComponent = !!(config && config.synchronous)\n loadedDefinitionsCache[componentName] = { definition: definition, isSynchronousComponent: isSynchronousComponent }\n delete loadingSubscribablesCache[componentName]\n\n // For API consistency, all loads complete asynchronously. However we want to avoid\n // adding an extra task schedule if it's unnecessary (i.e., the completion is already\n // async).\n //\n // You can bypass the 'always asynchronous' feature by putting the synchronous:true\n // flag on your component configuration when you register it.\n if (completedAsync || isSynchronousComponent) {\n // Note that notifySubscribers ignores any dependencies read within the callback.\n // See comment in loaderRegistryBehaviors.js for reasoning\n _subscribable.notifySubscribers(definition)\n } else {\n tasks.schedule(function () {\n _subscribable.notifySubscribers(definition)\n })\n }\n })\n completedAsync = true\n } else {\n _subscribable.subscribe(callback)\n }\n}\n\nfunction beginLoadingComponent(componentName, callback) {\n getFirstResultFromLoaders('getConfig', [componentName], function (config) {\n if (config) {\n // We have a config, so now load its definition\n getFirstResultFromLoaders('loadComponent', [componentName, config], function (definition) {\n callback(definition, config)\n })\n } else {\n // The component has no config - it's unknown to all the loaders.\n // Note that this is not an error (e.g., a module loading error) - that would abort the\n // process and this callback would not run. For this callback to run, all loaders must\n // have confirmed they don't know about this component.\n callback(null, null)\n }\n })\n}\n\nfunction getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders?) {\n // On the first call in the stack, start with the full set of loaders\n if (!candidateLoaders) {\n candidateLoaders = registry.loaders.slice(0) // Use a copy, because we'll be mutating this array\n }\n\n // Try the next candidate\n const currentCandidateLoader = candidateLoaders.shift()\n if (currentCandidateLoader) {\n const methodInstance = currentCandidateLoader[methodName]\n if (methodInstance) {\n let wasAborted = false,\n synchronousReturnValue = methodInstance.apply(\n currentCandidateLoader,\n argsExceptCallback.concat(function (result) {\n if (wasAborted) {\n callback(null)\n } else if (result !== null) {\n // This candidate returned a value. Use it.\n callback(result)\n } else {\n // Try the next candidate\n getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders)\n }\n })\n )\n\n // Currently, loaders may not return anything synchronously. This leaves open the possibility\n // that we'll extend the API to support synchronous return values in the future. It won't be\n // a breaking change, because currently no loader is allowed to return anything except undefined.\n if (synchronousReturnValue !== undefined) {\n wasAborted = true\n\n // Method to suppress exceptions will remain undocumented. This is only to keep\n // KO's specs running tidily, since we can observe the loading got aborted without\n // having exceptions cluttering up the console too.\n if (!currentCandidateLoader.suppressLoaderExceptions) {\n throw new Error(\n 'Component loaders must supply values by invoking the callback, not by returning values synchronously.'\n )\n }\n }\n } else {\n // This candidate doesn't have the relevant handler. Synchronously move on to the next one.\n getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders)\n }\n } else {\n // No candidates returned a value\n callback(null)\n }\n}\n\nexport const registry = {\n get(componentName: string, callback: any) {\n const cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName)\n if (cachedDefinition) {\n // It's already loaded and cached. Reuse the same definition object.\n // Note that for API consistency, even cache hits complete asynchronously by default.\n // You can bypass this by putting synchronous:true on your component config.\n if (cachedDefinition.isSynchronousComponent) {\n dependencyDetection.ignore(function () {\n // See comment in loaderRegistryBehaviors.js for reasoning\n callback(cachedDefinition.definition)\n })\n } else {\n tasks.schedule(function () {\n callback(cachedDefinition.definition)\n })\n }\n } else {\n // Join the loading process that is already underway, or start a new one.\n loadComponentAndNotify(componentName, callback)\n }\n },\n\n clearCachedDefinition(componentName: string) {\n delete loadedDefinitionsCache[componentName]\n },\n\n _getFirstResultFromLoaders: getFirstResultFromLoaders,\n\n loaders: new Array<Loader>()\n}\n"], | ||
| "mappings": ";;AAAA,SAAS,cAAc,2BAA2B;AAClD,SAAS,sBAAsB,aAAa;AAG5C,MAAM,4BAA4B,CAAC,GACjC,yBAAyB,CAAC;AAE5B,SAAS,uBAAuB,eAAuB,UAAqB;AAC1E,MAAI,gBAAgB,qBAAqB,2BAA2B,aAAa,GAC/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sCAA0B,YAAY,oBAAoB,UAAU,gBAAgB;AAAA,UACtF;AAAA,QACF,CAAC;AAAA,MACH;AAKF,UAAI,2BAA2B,QAAW;AACxC,qBAAa;AAKb,YAAI,CAAC,uBAAuB,0BAA0B;AACpD,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,OAAO;AAEL,gCAA0B,YAAY,oBAAoB,UAAU,gBAAgB;AAAA,IACtF;AAAA,EACF,OAAO;AAEL,aAAS,IAAI;AAAA,EACf;AACF;AAEO,aAAM,WAAW;AAAA,EACtB,IAAI,eAAuB,UAAe;AACxC,UAAM,mBAAmB,qBAAqB,wBAAwB,aAAa;AACnF,QAAI,kBAAkB;AAIpB,UAAI,iBAAiB,wBAAwB;AAC3C,4BAAoB,OAAO,WAAY;AAErC,mBAAS,iBAAiB,UAAU;AAAA,QACtC,CAAC;AAAA,MACH,OAAO;AACL,cAAM,SAAS,WAAY;AACzB,mBAAS,iBAAiB,UAAU;AAAA,QACtC,CAAC;AAAA,MACH;AAAA,IACF,OAAO;AAEL,6BAAuB,eAAe,QAAQ;AAAA,IAChD;AAAA,EACF;AAAA,EAEA,sBAAsB,eAAuB;AAC3C,WAAO,uBAAuB,aAAa;AAAA,EAC7C;AAAA,EAEA,4BAA4B;AAAA,EAE5B,SAAS,IAAI,MAAc;AAC7B;", | ||
| "names": [] | ||
| } |
+10
-11
| { | ||
| "version": "4.0.0-beta1.3", | ||
| "version": "4.0.0", | ||
| "name": "@tko/utils.component", | ||
@@ -12,13 +12,13 @@ "description": "Registry and loading utilities for web components", | ||
| "dependencies": { | ||
| "@tko/lifecycle": "^4.0.0-beta1.3", | ||
| "@tko/observable": "^4.0.0-beta1.3", | ||
| "@tko/utils": "^4.0.0-beta1.3", | ||
| "@tko/lifecycle": "^4.0.0", | ||
| "@tko/observable": "^4.0.0", | ||
| "@tko/utils": "^4.0.0", | ||
| "tslib": "^2.2.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "@tko/bind": "^4.0.0-alpha9.0", | ||
| "@tko/binding.core": "^4.0.0-alpha9.0", | ||
| "@tko/computed": "^4.0.0-alpha8.0", | ||
| "@tko/provider.multi": "^4.0.0-alpha8.4", | ||
| "@tko/provider.virtual": "^4.0.0-alpha9.0" | ||
| "@tko/bind": "^4.0.0", | ||
| "@tko/binding.core": "^4.0.0", | ||
| "@tko/computed": "^4.0.0", | ||
| "@tko/provider.multi": "^4.0.0", | ||
| "@tko/provider.virtual": "^4.0.0" | ||
| }, | ||
@@ -51,4 +51,3 @@ "karma": { | ||
| "url": "git+https://github.com/knockout/tko.git" | ||
| }, | ||
| "gitHead": "a8843acb8ae085915115e53a4e057b30731c635e" | ||
| } | ||
| } |
-22
| The MIT License (MIT) - http://www.opensource.org/licenses/mit-license.php | ||
| Copyright (c) Steven Sanderson, the Knockout.js team, and other contributors | ||
| http://knockoutjs.com/ | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
267775
1.5%2680
6.22%0
-100%13
-7.14%Updated
Updated
Updated