Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tko/utils.component

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tko/utils.component - npm Package Compare versions

Comparing version
4.0.0-alpha9.0
to
4.0.0-beta1.0
+29
dist/ComponentABC.js
// @tko/utils.component 🥊 4.0.0-beta1.0 ESM
import { LifeCycle } from "@tko/lifecycle";
import { register, VIEW_MODEL_FACTORY } from "./loaders";
export class ComponentABC extends LifeCycle {
static get customElementName() {
return this.name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
}
static get template() {
if ("template" in this.prototype) {
return;
}
return { element: this.element };
}
static get element() {
throw new Error("[ComponentABC] `element` must be overloaded.");
}
static get sync() {
return true;
}
static [VIEW_MODEL_FACTORY](params, componentInfo) {
return new this(params, componentInfo);
}
static register(name = this.customElementName) {
const viewModel = this;
const { template } = this;
const synchronous = this.sync;
register(name, { viewModel, template, synchronous });
}
}
{
"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;",
"names": []
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

// @tko/utils.component 🥊 4.0.0-beta1.0 ESM
import { registry } from "./registry";
import { ComponentABC } from "./ComponentABC";
import {
register,
isRegistered,
unregister,
defaultLoader,
defaultConfigRegistry
} from "./loaders";
export { ComponentABC };
export default {
ComponentABC,
get: registry.get,
clearCachedDefinition: registry.clearCachedDefinition,
register,
isRegistered,
unregister,
defaultLoader,
_allRegisteredComponents: defaultConfigRegistry,
get loaders() {
return registry.loaders;
},
set loaders(loaders) {
registry.loaders = 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;",
"names": []
}
// @tko/utils.component 🥊 4.0.0-beta1.0 MJS
import { registry } from "./registry";
import { ComponentABC } from "./ComponentABC";
import {
register,
isRegistered,
unregister,
defaultLoader,
defaultConfigRegistry
} from "./loaders";
export { ComponentABC };
export default {
ComponentABC,
get: registry.get,
clearCachedDefinition: registry.clearCachedDefinition,
register,
isRegistered,
unregister,
defaultLoader,
_allRegisteredComponents: defaultConfigRegistry,
get loaders() {
return registry.loaders;
},
set loaders(loaders) {
registry.loaders = 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;",
"names": []
}
// @tko/utils.component 🥊 4.0.0-beta1.0 ESM
import {
isDomElement,
isDocumentFragment,
tagNameLower,
parseHtmlFragment,
makeArray,
cloneNodes,
hasOwnProperty
} from "@tko/utils";
import { registry } from "./registry";
export var defaultConfigRegistry = {};
export const VIEW_MODEL_FACTORY = Symbol("Knockout View Model ViewModel factory");
export function register(componentName, config) {
if (!config) {
throw new Error("Invalid configuration for " + componentName);
}
if (isRegistered(componentName)) {
throw new Error("Component " + componentName + " is already registered");
}
const ceok = componentName.includes("-") && componentName.toLowerCase() === componentName;
if (!config.ignoreCustomElementWarning && !ceok) {
console.log(`
\u{1F94A} 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):
ignoreCustomElementWarning: true
`);
}
defaultConfigRegistry[componentName] = config;
}
export function isRegistered(componentName) {
return hasOwnProperty(defaultConfigRegistry, componentName);
}
export function unregister(componentName) {
delete defaultConfigRegistry[componentName];
registry.clearCachedDefinition(componentName);
}
export var defaultLoader = {
getConfig: function(componentName, callback) {
var result = hasOwnProperty(defaultConfigRegistry, componentName) ? defaultConfigRegistry[componentName] : null;
callback(result);
},
loadComponent: function(componentName, config, callback) {
var errorCallback = makeErrorCallback(componentName);
possiblyGetConfigFromAmd(errorCallback, config, function(loadedConfig) {
resolveConfig(componentName, errorCallback, loadedConfig, callback);
});
},
loadTemplate: function(componentName, templateConfig, callback) {
resolveTemplate(makeErrorCallback(componentName), templateConfig, callback);
},
loadViewModel: function(componentName, viewModelConfig, callback) {
resolveViewModel(makeErrorCallback(componentName), viewModelConfig, callback);
}
};
var createViewModelKey = "createViewModel";
function resolveConfig(componentName, errorCallback, config, callback) {
var result = {}, makeCallBackWhenZero = 2, tryIssueCallback = function() {
if (--makeCallBackWhenZero === 0) {
callback(result);
}
}, templateConfig = config["template"], viewModelConfig = config["viewModel"];
if (templateConfig) {
possiblyGetConfigFromAmd(errorCallback, templateConfig, function(loadedConfig) {
registry._getFirstResultFromLoaders("loadTemplate", [componentName, loadedConfig], function(resolvedTemplate) {
result["template"] = resolvedTemplate;
tryIssueCallback();
});
});
} else {
tryIssueCallback();
}
if (viewModelConfig) {
possiblyGetConfigFromAmd(errorCallback, viewModelConfig, function(loadedConfig) {
registry._getFirstResultFromLoaders("loadViewModel", [componentName, loadedConfig], function(resolvedViewModel) {
result[createViewModelKey] = resolvedViewModel;
tryIssueCallback();
});
});
} else {
tryIssueCallback();
}
}
function resolveTemplate(errorCallback, templateConfig, callback) {
if (typeof templateConfig === "string") {
callback(parseHtmlFragment(templateConfig));
} else if (templateConfig instanceof Array) {
callback(templateConfig);
} else if (isDocumentFragment(templateConfig)) {
callback(makeArray(templateConfig.childNodes));
} else if (templateConfig.element) {
var element = templateConfig.element;
if (isDomElement(element)) {
callback(cloneNodesFromTemplateSourceElement(element));
} else if (typeof element === "string") {
var elemInstance = document.getElementById(element);
if (elemInstance) {
callback(cloneNodesFromTemplateSourceElement(elemInstance));
} else {
errorCallback("Cannot find element with ID " + element);
}
} else {
errorCallback("Unknown element type: " + element);
}
} else if (templateConfig.elementName) {
callback(templateConfig);
} else {
errorCallback("Unknown template value: " + templateConfig);
}
}
function resolveViewModel(errorCallback, viewModelConfig, callback) {
if (viewModelConfig[VIEW_MODEL_FACTORY]) {
callback((...args) => viewModelConfig[VIEW_MODEL_FACTORY](...args));
} else if (typeof viewModelConfig === "function") {
callback(function(params) {
return new viewModelConfig(params);
});
} else if (typeof viewModelConfig[createViewModelKey] === "function") {
callback(viewModelConfig[createViewModelKey]);
} else if ("instance" in viewModelConfig) {
var fixedInstance = viewModelConfig["instance"];
callback(function() {
return fixedInstance;
});
} else if ("viewModel" in viewModelConfig) {
resolveViewModel(errorCallback, viewModelConfig["viewModel"], callback);
} else {
errorCallback("Unknown viewModel value: " + viewModelConfig);
}
}
function cloneNodesFromTemplateSourceElement(elemInstance) {
switch (tagNameLower(elemInstance)) {
case "script":
return parseHtmlFragment(elemInstance.text);
case "textarea":
return parseHtmlFragment(elemInstance.value);
case "template":
if (isDocumentFragment(elemInstance.content)) {
return cloneNodes(elemInstance.content.childNodes);
}
}
return cloneNodes(elemInstance.childNodes);
}
function possiblyGetConfigFromAmd(errorCallback, config, callback) {
if (typeof config.require === "string") {
if (window.amdRequire || window.require) {
(window.amdRequire || window.require)([config.require], callback);
} else {
errorCallback("Uses require, but no AMD loader is present");
}
} else {
callback(config);
}
}
function makeErrorCallback(componentName) {
return function(message) {
throw new Error("Component '" + componentName + "': " + message);
};
}
registry.loaders.push(defaultLoader);
{
"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,MAAI,CAAC,OAAO,8BAA8B,CAAC,MAAM;AAC/C,YAAQ,IAAI;AAAA;AAAA;AAAA;AAAA,KAIX;AAAA,EACH;AAEA,wBAAsB,iBAAiB;AACzC;AAEO,6BAAuB,eAAe;AAC3C,SAAO,eAAe,uBAAuB,aAAa;AAC5D;AAEO,2BAAqB,eAAe;AACzC,SAAO,sBAAsB;AAC7B,WAAS,sBAAsB,aAAa;AAC9C;AAEO,WAAI,gBAAgB;AAAA,EACzB,WAAW,SAAU,eAAe,UAAU;AAC5C,QAAI,SAAS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ACF;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;",
"names": []
}
// @tko/utils.component 🥊 4.0.0-beta1.0 ESM
import {
subscribable,
dependencyDetection
} from "@tko/observable";
import {
getObjectOwnProperty,
tasks
} from "@tko/utils";
var loadingSubscribablesCache = {}, loadedDefinitionsCache = {};
function loadComponentAndNotify(componentName, callback) {
var _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName), completedAsync;
if (!_subscribable) {
_subscribable = loadingSubscribablesCache[componentName] = new subscribable();
_subscribable.subscribe(callback);
beginLoadingComponent(componentName, function(definition, config) {
var isSynchronousComponent = !!(config && config.synchronous);
loadedDefinitionsCache[componentName] = { definition, isSynchronousComponent };
delete loadingSubscribablesCache[componentName];
if (completedAsync || isSynchronousComponent) {
_subscribable.notifySubscribers(definition);
} else {
tasks.schedule(function() {
_subscribable.notifySubscribers(definition);
});
}
});
completedAsync = true;
} else {
_subscribable.subscribe(callback);
}
}
function beginLoadingComponent(componentName, callback) {
getFirstResultFromLoaders("getConfig", [componentName], function(config) {
if (config) {
getFirstResultFromLoaders("loadComponent", [componentName, config], function(definition) {
callback(definition, config);
});
} else {
callback(null, null);
}
});
}
function getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders) {
if (!candidateLoaders) {
candidateLoaders = registry.loaders.slice(0);
}
var currentCandidateLoader = candidateLoaders.shift();
if (currentCandidateLoader) {
var 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);
}
}));
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.");
}
}
} else {
getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders);
}
} else {
callback(null);
}
}
export var registry = {
get(componentName, callback) {
var cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName);
if (cachedDefinition) {
if (cachedDefinition.isSynchronousComponent) {
dependencyDetection.ignore(function() {
callback(cachedDefinition.definition);
});
} else {
tasks.schedule(function() {
callback(cachedDefinition.definition);
});
}
} else {
loadComponentAndNotify(componentName, callback);
}
},
clearCachedDefinition(componentName) {
delete loadedDefinitionsCache[componentName];
},
_getFirstResultFromLoaders: getFirstResultFromLoaders,
loaders: []
};
{
"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;AAAA;AAAA;AAIA,IAAI,4BAA4B,CAAC,GAC/B,yBAAyB,CAAC;AAE5B,gCAAiC,eAAe,UAAU;AACxD,MAAI,gBAA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AAY,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;",
"names": []
}
+23
-27
{
"version": "4.0.0-beta1.0",
"name": "@tko/utils.component",
"version": "4.0.0-alpha9.0",
"description": "Registry and loading utilities for web components",

@@ -12,10 +12,8 @@ "module": "dist/utils.component.js",

"dependencies": {
"@tko/lifecycle": "^4.0.0-alpha9.0",
"@tko/observable": "^4.0.0-alpha8.0",
"@tko/utils": "^4.0.0-alpha8.0",
"jss": "^9.8.3",
"jss-preset-default": "^4.5.0",
"tslib": "^1.8.0"
"@tko/lifecycle": "^4.0.0-beta1.0",
"@tko/observable": "^4.0.0-beta1.0",
"@tko/utils": "^4.0.0-beta1.0",
"tslib": "^2.2.0"
},
"devDependencies": {
"peerDependencies": {
"@tko/bind": "^4.0.0-alpha9.0",

@@ -32,19 +30,2 @@ "@tko/binding.core": "^4.0.0-alpha9.0",

},
"__about__shared.package.json": "These properties are copied into all packages/*/package.json. Run `yarn repackage`",
"standard": {
"env": [
"browser",
"jasmine",
"mocha"
]
},
"scripts": {
"test": "npx karma start ../../karma.conf.js --once",
"build": "npx rollup -c ../../rollup.config.js",
"watch": "npx karma start ../../karma.conf.js",
"prepare": "npx rollup -c ../../rollup.config.js"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://tko.io",

@@ -54,6 +35,21 @@ "licenses": [

"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
"url": "https://opensource.org/licenses/MIT"
}
],
"gitHead": "90cdb597db01d50725c567810af092e70a5b32d9"
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"./helpers/*": "./helpers/*"
},
"bugs": {
"url": "https://github.com/knockout/tko/issues"
},
"author": "The Knockout Team",
"repository": {
"type": "git",
"url": "git+https://github.com/knockout/tko.git"
},
"gitHead": "99114c4deded3fc5dbddd5c7c9c63c845a18263b"
}
/*!
* Registry and loading utilities for web components 🥊 @tko/utils.component@4.0.0-alpha9.0
* (c) The Knockout.js Team - https://tko.io
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
import { subscribable, dependencyDetection } from '@tko/observable';
import { getObjectOwnProperty, tasks, isDomElement, isDocumentFragment, tagNameLower, parseHtmlFragment, makeArray, cloneNodes, hasOwnProperty } from '@tko/utils';
import { LifeCycle } from '@tko/lifecycle';
var loadingSubscribablesCache = {}, // Tracks component loads that are currently in flight
loadedDefinitionsCache = {}; // Tracks component loads that have already completed
function loadComponentAndNotify (componentName, callback) {
var _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName),
completedAsync;
if (!_subscribable) {
// It's not started loading yet. Start loading, and when it's done, move it to loadedDefinitionsCache.
_subscribable = loadingSubscribablesCache[componentName] = new subscribable();
_subscribable.subscribe(callback);
beginLoadingComponent(componentName, function (definition, config) {
var isSynchronousComponent = !!(config && config.synchronous);
loadedDefinitionsCache[componentName] = { definition: definition, isSynchronousComponent: isSynchronousComponent };
delete loadingSubscribablesCache[componentName];
// For API consistency, all loads complete asynchronously. However we want to avoid
// adding an extra task schedule if it's unnecessary (i.e., the completion is already
// async).
//
// You can bypass the 'always asynchronous' feature by putting the synchronous:true
// flag on your component configuration when you register it.
if (completedAsync || isSynchronousComponent) {
// Note that notifySubscribers ignores any dependencies read within the callback.
// See comment in loaderRegistryBehaviors.js for reasoning
_subscribable.notifySubscribers(definition);
} else {
tasks.schedule(function () {
_subscribable.notifySubscribers(definition);
});
}
});
completedAsync = true;
} else {
_subscribable.subscribe(callback);
}
}
function beginLoadingComponent (componentName, callback) {
getFirstResultFromLoaders('getConfig', [componentName], function (config) {
if (config) {
// We have a config, so now load its definition
getFirstResultFromLoaders('loadComponent', [componentName, config], function (definition) {
callback(definition, config);
});
} else {
// The component has no config - it's unknown to all the loaders.
// Note that this is not an error (e.g., a module loading error) - that would abort the
// process and this callback would not run. For this callback to run, all loaders must
// have confirmed they don't know about this component.
callback(null, null);
}
});
}
function getFirstResultFromLoaders (methodName, argsExceptCallback, callback, candidateLoaders) {
// On the first call in the stack, start with the full set of loaders
if (!candidateLoaders) {
candidateLoaders = registry.loaders.slice(0); // Use a copy, because we'll be mutating this array
}
// Try the next candidate
var currentCandidateLoader = candidateLoaders.shift();
if (currentCandidateLoader) {
var methodInstance = currentCandidateLoader[methodName];
if (methodInstance) {
var wasAborted = false,
synchronousReturnValue = methodInstance.apply(currentCandidateLoader, argsExceptCallback.concat(function (result) {
if (wasAborted) {
callback(null);
} else if (result !== null) {
// This candidate returned a value. Use it.
callback(result);
} else {
// Try the next candidate
getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders);
}
}));
// Currently, loaders may not return anything synchronously. This leaves open the possibility
// that we'll extend the API to support synchronous return values in the future. It won't be
// a breaking change, because currently no loader is allowed to return anything except undefined.
if (synchronousReturnValue !== undefined) {
wasAborted = true;
// Method to suppress exceptions will remain undocumented. This is only to keep
// KO's specs running tidily, since we can observe the loading got aborted without
// having exceptions cluttering up the console too.
if (!currentCandidateLoader.suppressLoaderExceptions) {
throw new Error('Component loaders must supply values by invoking the callback, not by returning values synchronously.')
}
}
} else {
// This candidate doesn't have the relevant handler. Synchronously move on to the next one.
getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders);
}
} else {
// No candidates returned a value
callback(null);
}
}
var registry = {
get (componentName, callback) {
var cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName);
if (cachedDefinition) {
// It's already loaded and cached. Reuse the same definition object.
// Note that for API consistency, even cache hits complete asynchronously by default.
// You can bypass this by putting synchronous:true on your component config.
if (cachedDefinition.isSynchronousComponent) {
dependencyDetection.ignore(function () { // See comment in loaderRegistryBehaviors.js for reasoning
callback(cachedDefinition.definition);
});
} else {
tasks.schedule(function () { callback(cachedDefinition.definition); });
}
} else {
// Join the loading process that is already underway, or start a new one.
loadComponentAndNotify(componentName, callback);
}
},
clearCachedDefinition (componentName) {
delete loadedDefinitionsCache[componentName];
},
_getFirstResultFromLoaders: getFirstResultFromLoaders,
loaders: []
};
// The default loader is responsible for two things:
// 1. Maintaining the default in-memory registry of component configuration objects
// (i.e., the thing you're writing to when you call ko.components.register(someName, ...))
// 2. Answering requests for components by fetching configuration objects
// from that default in-memory registry and resolving them into standard
// component definition objects (of the form { createViewModel: ..., template: ... })
// Custom loaders may override either of these facilities, i.e.,
// 1. To supply configuration objects from some other source (e.g., conventions)
// 2. Or, to resolve configuration objects by loading viewmodels/templates via arbitrary logic.
var defaultConfigRegistry = {};
const VIEW_MODEL_FACTORY = Symbol('Knockout View Model ViewModel factory');
function register (componentName, config) {
if (!config) {
throw new Error('Invalid configuration for ' + componentName)
}
if (isRegistered(componentName)) {
throw new Error('Component ' + componentName + ' is already registered')
}
const ceok = componentName.includes('-') && componentName.toLowerCase() === componentName;
if (!config.ignoreCustomElementWarning && !ceok) {
console.log(`
🥊 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):
ignoreCustomElementWarning: true
`);
}
defaultConfigRegistry[componentName] = config;
}
function isRegistered (componentName) {
return hasOwnProperty(defaultConfigRegistry, componentName)
}
function unregister (componentName) {
delete defaultConfigRegistry[componentName];
registry.clearCachedDefinition(componentName);
}
var defaultLoader = {
getConfig: function (componentName, callback) {
var result = hasOwnProperty(defaultConfigRegistry, componentName)
? defaultConfigRegistry[componentName]
: null;
callback(result);
},
loadComponent: function (componentName, config, callback) {
var errorCallback = makeErrorCallback(componentName);
possiblyGetConfigFromAmd(errorCallback, config, function (loadedConfig) {
resolveConfig(componentName, errorCallback, loadedConfig, callback);
});
},
loadTemplate: function (componentName, templateConfig, callback) {
resolveTemplate(makeErrorCallback(componentName), templateConfig, callback);
},
loadViewModel: function (componentName, viewModelConfig, callback) {
resolveViewModel(makeErrorCallback(componentName), viewModelConfig, callback);
}
};
var createViewModelKey = 'createViewModel';
// Takes a config object of the form { template: ..., viewModel: ... }, and asynchronously convert it
// into the standard component definition format:
// { template: <ArrayOfDomNodes>, createViewModel: function(params, componentInfo) { ... } }.
// Since both template and viewModel may need to be resolved asynchronously, both tasks are performed
// in parallel, and the results joined when both are ready. We don't depend on any promises infrastructure,
// so this is implemented manually below.
function resolveConfig (componentName, errorCallback, config, callback) {
var result = {},
makeCallBackWhenZero = 2,
tryIssueCallback = function () {
if (--makeCallBackWhenZero === 0) {
callback(result);
}
},
templateConfig = config['template'],
viewModelConfig = config['viewModel'];
if (templateConfig) {
possiblyGetConfigFromAmd(errorCallback, templateConfig, function (loadedConfig) {
registry._getFirstResultFromLoaders('loadTemplate', [componentName, loadedConfig], function (resolvedTemplate) {
result['template'] = resolvedTemplate;
tryIssueCallback();
});
});
} else {
tryIssueCallback();
}
if (viewModelConfig) {
possiblyGetConfigFromAmd(errorCallback, viewModelConfig, function (loadedConfig) {
registry._getFirstResultFromLoaders('loadViewModel', [componentName, loadedConfig], function (resolvedViewModel) {
result[createViewModelKey] = resolvedViewModel;
tryIssueCallback();
});
});
} else {
tryIssueCallback();
}
}
function resolveTemplate (errorCallback, templateConfig, callback) {
if (typeof templateConfig === 'string') {
// Markup - parse it
callback(parseHtmlFragment(templateConfig));
} else if (templateConfig instanceof Array) {
// Assume already an array of DOM nodes - pass through unchanged
callback(templateConfig);
} else if (isDocumentFragment(templateConfig)) {
// Document fragment - use its child nodes
callback(makeArray(templateConfig.childNodes));
} else if (templateConfig.element) {
var element = templateConfig.element;
if (isDomElement(element)) {
// Element instance - copy its child nodes
callback(cloneNodesFromTemplateSourceElement(element));
} else if (typeof element === 'string') {
// Element ID - find it, then copy its child nodes
var elemInstance = document.getElementById(element);
if (elemInstance) {
callback(cloneNodesFromTemplateSourceElement(elemInstance));
} else {
errorCallback('Cannot find element with ID ' + element);
}
} else {
errorCallback('Unknown element type: ' + element);
}
} else if (templateConfig.elementName) {
// JSX in the style of babel-plugin-transform-jsx
callback(templateConfig);
} else {
errorCallback('Unknown template value: ' + templateConfig);
}
}
function resolveViewModel (errorCallback, viewModelConfig, callback) {
if (viewModelConfig[VIEW_MODEL_FACTORY]) {
callback((...args) => viewModelConfig[VIEW_MODEL_FACTORY](...args));
} else if (typeof viewModelConfig === 'function') {
// Constructor - convert to standard factory function format
// By design, this does *not* supply componentInfo to the constructor, as the intent is that
// componentInfo contains non-viewmodel data (e.g., the component's element) that should only
// be used in factory functions, not viewmodel constructors.
callback(function (params /*, componentInfo */) {
return new viewModelConfig(params)
});
} else if (typeof viewModelConfig[createViewModelKey] === 'function') {
// Already a factory function - use it as-is
callback(viewModelConfig[createViewModelKey]);
} else if ('instance' in viewModelConfig) {
// Fixed object instance - promote to createViewModel format for API consistency
var fixedInstance = viewModelConfig['instance'];
callback(function (/* params, componentInfo */) {
return fixedInstance
});
} else if ('viewModel' in viewModelConfig) {
// Resolved AMD module whose value is of the form { viewModel: ... }
resolveViewModel(errorCallback, viewModelConfig['viewModel'], callback);
} else {
errorCallback('Unknown viewModel value: ' + viewModelConfig);
}
}
function cloneNodesFromTemplateSourceElement (elemInstance) {
switch (tagNameLower(elemInstance)) {
case 'script':
return parseHtmlFragment(elemInstance.text)
case 'textarea':
return parseHtmlFragment(elemInstance.value)
case 'template':
// For browsers with proper <template> element support (i.e., where the .content property
// gives a document fragment), use that document fragment.
if (isDocumentFragment(elemInstance.content)) {
return cloneNodes(elemInstance.content.childNodes)
}
}
// Regular elements such as <div>, and <template> elements on old browsers that don't really
// understand <template> and just treat it as a regular container
return cloneNodes(elemInstance.childNodes)
}
function possiblyGetConfigFromAmd (errorCallback, config, callback) {
if (typeof config.require === 'string') {
// The config is the value of an AMD module
if (window.amdRequire || window.require) {
(window.amdRequire || window.require)([config.require], callback);
} else {
errorCallback('Uses require, but no AMD loader is present');
}
} else {
callback(config);
}
}
function makeErrorCallback (componentName) {
return function (message) {
throw new Error('Component \'' + componentName + '\': ' + message)
}
}
// By default, the default loader is the only registered component loader
registry.loaders.push(defaultLoader);
/**
* Component --- Abstract Base Class
*
* This simplifies and compartmentalizes Components. Use this:
*
* class CompX extends ComponentABC {
* static get element () { return 'comp-x-id' }
* static get sync () { return false }
* static get elementName () { return 'comp-x' }
* }
* CompX.register()
*
* instead of:
*
* class CompX {}
*
* ko.components.register('comp-x', {
* viewModel: CompX,
* synchronous: false,
* template: { element: 'comp-x' }
* })
*
* As well, gain all the benefits of a LifeCycle, namely automated
* event and subscription addition/removal.
*
* NOTE: A Component created this way can add events to the component node
* with `this.addEventListener(type, action)`.
*/
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 () {
if ('template' in this.prototype) { return }
return { element: this.element }
}
/**
* 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) {
return new this(params, componentInfo)
}
static register (name = this.customElementName) {
const viewModel = this;
const {template} = this;
const synchronous = this.sync;
register(name, { viewModel, template, synchronous });
}
}
var index = {
ComponentABC,
// -- Registry --
get: registry.get,
clearCachedDefinition: registry.clearCachedDefinition,
// -- Loader --
register,
isRegistered,
unregister,
defaultLoader,
// "Privately" expose the underlying config registry for use in old-IE shim
_allRegisteredComponents: defaultConfigRegistry,
get loaders () { return registry.loaders },
set loaders (loaders) { registry.loaders = loaders; }
}
export default index;
export { ComponentABC };
//# sourceMappingURL=utils.component.es6.js.map
{"version":3,"file":"utils.component.es6.js","sources":["../src/registry.js","../src/loaders.js","../src/ComponentABC.js","../src/index.js"],"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","\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🥊 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","/**\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","\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"],"names":[],"mappings":";;;;;;;;;;AASA,IAAI,yBAAyB,GAAG,EAAE;EAChC,sBAAsB,GAAG,GAAE;;AAE7B,SAAS,sBAAsB,EAAE,aAAa,EAAE,QAAQ,EAAE;EACxD,IAAI,aAAa,GAAG,oBAAoB,CAAC,yBAAyB,EAAE,aAAa,CAAC;IAChF,eAAc;EAChB,IAAI,CAAC,aAAa,EAAE;;IAElB,aAAa,GAAG,yBAAyB,CAAC,aAAa,CAAC,GAAG,IAAI,YAAY,GAAE;IAC7E,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAC;;IAEjC,qBAAqB,CAAC,aAAa,EAAE,UAAU,UAAU,EAAE,MAAM,EAAE;MACjE,IAAI,sBAAsB,GAAG,CAAC,EAAE,MAAM,IAAI,MAAM,CAAC,WAAW,EAAC;MAC7D,sBAAsB,CAAC,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,sBAAsB,EAAE,sBAAsB,GAAE;MAClH,OAAO,yBAAyB,CAAC,aAAa,EAAC;;;;;;;;MAQ/C,IAAI,cAAc,IAAI,sBAAsB,EAAE;;;QAG5C,aAAa,CAAC,iBAAiB,CAAC,UAAU,EAAC;OAC5C,MAAM;QACL,KAAK,CAAC,QAAQ,CAAC,YAAY;UACzB,aAAa,CAAC,iBAAiB,CAAC,UAAU,EAAC;SAC5C,EAAC;OACH;KACF,EAAC;IACF,cAAc,GAAG,KAAI;GACtB,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G;EACjB,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB;;;EAGrD,QAAQ;EACR,YAAY;EACZ,UAAU;EACV,aAAa;;EAEb,wBAAwB,EAAE,qBAAqB;;EAE/C,IAAI,OAAO,CAAC,GAAG,EAAE,OAAO,QAAQ,CAAC,OAAO,EAAE;EAC1C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAO,EAAE;CACrD;;;"}
/*!
* Registry and loading utilities for web components 🥊 @tko/utils.component@4.0.0-alpha9.0
* (c) The Knockout.js Team - https://tko.io
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
import { subscribable, dependencyDetection } from '@tko/observable';
import { getObjectOwnProperty, tasks, isDomElement, isDocumentFragment, tagNameLower, parseHtmlFragment, makeArray, cloneNodes, hasOwnProperty } from '@tko/utils';
import { LifeCycle } from '@tko/lifecycle';
var loadingSubscribablesCache = {}, // Tracks component loads that are currently in flight
loadedDefinitionsCache = {}; // Tracks component loads that have already completed
function loadComponentAndNotify(componentName, callback) {
var _subscribable = getObjectOwnProperty(loadingSubscribablesCache, componentName), completedAsync;
if (!_subscribable) {
// It's not started loading yet. Start loading, and when it's done, move it to loadedDefinitionsCache.
_subscribable = loadingSubscribablesCache[componentName] = new subscribable();
_subscribable.subscribe(callback);
beginLoadingComponent(componentName, function (definition, config) {
var isSynchronousComponent = !!(config && config.synchronous);
loadedDefinitionsCache[componentName] = { definition: definition, isSynchronousComponent: isSynchronousComponent };
delete loadingSubscribablesCache[componentName];
// For API consistency, all loads complete asynchronously. However we want to avoid
// adding an extra task schedule if it's unnecessary (i.e., the completion is already
// async).
//
// You can bypass the 'always asynchronous' feature by putting the synchronous:true
// flag on your component configuration when you register it.
if (completedAsync || isSynchronousComponent) {
// Note that notifySubscribers ignores any dependencies read within the callback.
// See comment in loaderRegistryBehaviors.js for reasoning
_subscribable.notifySubscribers(definition);
}
else {
tasks.schedule(function () {
_subscribable.notifySubscribers(definition);
});
}
});
completedAsync = true;
}
else {
_subscribable.subscribe(callback);
}
}
function beginLoadingComponent(componentName, callback) {
getFirstResultFromLoaders('getConfig', [componentName], function (config) {
if (config) {
// We have a config, so now load its definition
getFirstResultFromLoaders('loadComponent', [componentName, config], function (definition) {
callback(definition, config);
});
}
else {
// The component has no config - it's unknown to all the loaders.
// Note that this is not an error (e.g., a module loading error) - that would abort the
// process and this callback would not run. For this callback to run, all loaders must
// have confirmed they don't know about this component.
callback(null, null);
}
});
}
function getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders) {
// On the first call in the stack, start with the full set of loaders
if (!candidateLoaders) {
candidateLoaders = registry.loaders.slice(0); // Use a copy, because we'll be mutating this array
}
// Try the next candidate
var currentCandidateLoader = candidateLoaders.shift();
if (currentCandidateLoader) {
var methodInstance = currentCandidateLoader[methodName];
if (methodInstance) {
var wasAborted = false, synchronousReturnValue = methodInstance.apply(currentCandidateLoader, argsExceptCallback.concat(function (result) {
if (wasAborted) {
callback(null);
}
else if (result !== null) {
// This candidate returned a value. Use it.
callback(result);
}
else {
// Try the next candidate
getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders);
}
}));
// Currently, loaders may not return anything synchronously. This leaves open the possibility
// that we'll extend the API to support synchronous return values in the future. It won't be
// a breaking change, because currently no loader is allowed to return anything except undefined.
if (synchronousReturnValue !== undefined) {
wasAborted = true;
// Method to suppress exceptions will remain undocumented. This is only to keep
// KO's specs running tidily, since we can observe the loading got aborted without
// having exceptions cluttering up the console too.
if (!currentCandidateLoader.suppressLoaderExceptions) {
throw new Error('Component loaders must supply values by invoking the callback, not by returning values synchronously.');
}
}
}
else {
// This candidate doesn't have the relevant handler. Synchronously move on to the next one.
getFirstResultFromLoaders(methodName, argsExceptCallback, callback, candidateLoaders);
}
}
else {
// No candidates returned a value
callback(null);
}
}
var registry = {
get: function (componentName, callback) {
var cachedDefinition = getObjectOwnProperty(loadedDefinitionsCache, componentName);
if (cachedDefinition) {
// It's already loaded and cached. Reuse the same definition object.
// Note that for API consistency, even cache hits complete asynchronously by default.
// You can bypass this by putting synchronous:true on your component config.
if (cachedDefinition.isSynchronousComponent) {
dependencyDetection.ignore(function () {
callback(cachedDefinition.definition);
});
}
else {
tasks.schedule(function () { callback(cachedDefinition.definition); });
}
}
else {
// Join the loading process that is already underway, or start a new one.
loadComponentAndNotify(componentName, callback);
}
},
clearCachedDefinition: function (componentName) {
delete loadedDefinitionsCache[componentName];
},
_getFirstResultFromLoaders: getFirstResultFromLoaders,
loaders: []
};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
// The default loader is responsible for two things:
// 1. Maintaining the default in-memory registry of component configuration objects
// (i.e., the thing you're writing to when you call ko.components.register(someName, ...))
// 2. Answering requests for components by fetching configuration objects
// from that default in-memory registry and resolving them into standard
// component definition objects (of the form { createViewModel: ..., template: ... })
// Custom loaders may override either of these facilities, i.e.,
// 1. To supply configuration objects from some other source (e.g., conventions)
// 2. Or, to resolve configuration objects by loading viewmodels/templates via arbitrary logic.
var defaultConfigRegistry = {};
var VIEW_MODEL_FACTORY = Symbol('Knockout View Model ViewModel factory');
function register(componentName, config) {
if (!config) {
throw new Error('Invalid configuration for ' + componentName);
}
if (isRegistered(componentName)) {
throw new Error('Component ' + componentName + ' is already registered');
}
var ceok = componentName.includes('-') && componentName.toLowerCase() === componentName;
if (!config.ignoreCustomElementWarning && !ceok) {
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 ");
}
defaultConfigRegistry[componentName] = config;
}
function isRegistered(componentName) {
return hasOwnProperty(defaultConfigRegistry, componentName);
}
function unregister(componentName) {
delete defaultConfigRegistry[componentName];
registry.clearCachedDefinition(componentName);
}
var defaultLoader = {
getConfig: function (componentName, callback) {
var result = hasOwnProperty(defaultConfigRegistry, componentName)
? defaultConfigRegistry[componentName]
: null;
callback(result);
},
loadComponent: function (componentName, config, callback) {
var errorCallback = makeErrorCallback(componentName);
possiblyGetConfigFromAmd(errorCallback, config, function (loadedConfig) {
resolveConfig(componentName, errorCallback, loadedConfig, callback);
});
},
loadTemplate: function (componentName, templateConfig, callback) {
resolveTemplate(makeErrorCallback(componentName), templateConfig, callback);
},
loadViewModel: function (componentName, viewModelConfig, callback) {
resolveViewModel(makeErrorCallback(componentName), viewModelConfig, callback);
}
};
var createViewModelKey = 'createViewModel';
// Takes a config object of the form { template: ..., viewModel: ... }, and asynchronously convert it
// into the standard component definition format:
// { template: <ArrayOfDomNodes>, createViewModel: function(params, componentInfo) { ... } }.
// Since both template and viewModel may need to be resolved asynchronously, both tasks are performed
// in parallel, and the results joined when both are ready. We don't depend on any promises infrastructure,
// so this is implemented manually below.
function resolveConfig(componentName, errorCallback, config, callback) {
var result = {}, makeCallBackWhenZero = 2, tryIssueCallback = function () {
if (--makeCallBackWhenZero === 0) {
callback(result);
}
}, templateConfig = config['template'], viewModelConfig = config['viewModel'];
if (templateConfig) {
possiblyGetConfigFromAmd(errorCallback, templateConfig, function (loadedConfig) {
registry._getFirstResultFromLoaders('loadTemplate', [componentName, loadedConfig], function (resolvedTemplate) {
result['template'] = resolvedTemplate;
tryIssueCallback();
});
});
}
else {
tryIssueCallback();
}
if (viewModelConfig) {
possiblyGetConfigFromAmd(errorCallback, viewModelConfig, function (loadedConfig) {
registry._getFirstResultFromLoaders('loadViewModel', [componentName, loadedConfig], function (resolvedViewModel) {
result[createViewModelKey] = resolvedViewModel;
tryIssueCallback();
});
});
}
else {
tryIssueCallback();
}
}
function resolveTemplate(errorCallback, templateConfig, callback) {
if (typeof templateConfig === 'string') {
// Markup - parse it
callback(parseHtmlFragment(templateConfig));
}
else if (templateConfig instanceof Array) {
// Assume already an array of DOM nodes - pass through unchanged
callback(templateConfig);
}
else if (isDocumentFragment(templateConfig)) {
// Document fragment - use its child nodes
callback(makeArray(templateConfig.childNodes));
}
else if (templateConfig.element) {
var element = templateConfig.element;
if (isDomElement(element)) {
// Element instance - copy its child nodes
callback(cloneNodesFromTemplateSourceElement(element));
}
else if (typeof element === 'string') {
// Element ID - find it, then copy its child nodes
var elemInstance = document.getElementById(element);
if (elemInstance) {
callback(cloneNodesFromTemplateSourceElement(elemInstance));
}
else {
errorCallback('Cannot find element with ID ' + element);
}
}
else {
errorCallback('Unknown element type: ' + element);
}
}
else if (templateConfig.elementName) {
// JSX in the style of babel-plugin-transform-jsx
callback(templateConfig);
}
else {
errorCallback('Unknown template value: ' + templateConfig);
}
}
function resolveViewModel(errorCallback, viewModelConfig, callback) {
if (viewModelConfig[VIEW_MODEL_FACTORY]) {
callback(function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return viewModelConfig[VIEW_MODEL_FACTORY].apply(viewModelConfig, __spread(args));
});
}
else if (typeof viewModelConfig === 'function') {
// Constructor - convert to standard factory function format
// By design, this does *not* supply componentInfo to the constructor, as the intent is that
// componentInfo contains non-viewmodel data (e.g., the component's element) that should only
// be used in factory functions, not viewmodel constructors.
callback(function (params /*, componentInfo */) {
return new viewModelConfig(params);
});
}
else if (typeof viewModelConfig[createViewModelKey] === 'function') {
// Already a factory function - use it as-is
callback(viewModelConfig[createViewModelKey]);
}
else if ('instance' in viewModelConfig) {
// Fixed object instance - promote to createViewModel format for API consistency
var fixedInstance = viewModelConfig['instance'];
callback(function ( /* params, componentInfo */) {
return fixedInstance;
});
}
else if ('viewModel' in viewModelConfig) {
// Resolved AMD module whose value is of the form { viewModel: ... }
resolveViewModel(errorCallback, viewModelConfig['viewModel'], callback);
}
else {
errorCallback('Unknown viewModel value: ' + viewModelConfig);
}
}
function cloneNodesFromTemplateSourceElement(elemInstance) {
switch (tagNameLower(elemInstance)) {
case 'script':
return parseHtmlFragment(elemInstance.text);
case 'textarea':
return parseHtmlFragment(elemInstance.value);
case 'template':
// For browsers with proper <template> element support (i.e., where the .content property
// gives a document fragment), use that document fragment.
if (isDocumentFragment(elemInstance.content)) {
return cloneNodes(elemInstance.content.childNodes);
}
}
// Regular elements such as <div>, and <template> elements on old browsers that don't really
// understand <template> and just treat it as a regular container
return cloneNodes(elemInstance.childNodes);
}
function possiblyGetConfigFromAmd(errorCallback, config, callback) {
if (typeof config.require === 'string') {
// The config is the value of an AMD module
if (window.amdRequire || window.require) {
(window.amdRequire || window.require)([config.require], callback);
}
else {
errorCallback('Uses require, but no AMD loader is present');
}
}
else {
callback(config);
}
}
function makeErrorCallback(componentName) {
return function (message) {
throw new Error('Component \'' + componentName + '\': ' + message);
};
}
// By default, the default loader is the only registered component loader
registry.loaders.push(defaultLoader);
var ComponentABC = /** @class */ (function (_super) {
__extends(ComponentABC, _super);
function ComponentABC() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(ComponentABC, "customElementName", {
/**
* 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.
*/
get: function () {
return this.name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ComponentABC, "template", {
/**
* 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.
*/
get: function () {
if ('template' in this.prototype) {
return;
}
return { element: this.element };
},
enumerable: true,
configurable: true
});
Object.defineProperty(ComponentABC, "element", {
/**
* 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.
*/
get: function () {
throw new Error('[ComponentABC] `element` must be overloaded.');
},
enumerable: true,
configurable: true
});
Object.defineProperty(ComponentABC, "sync", {
/**
* @return {bool} True if the component shall load synchronously
*/
get: function () { return true; },
enumerable: true,
configurable: 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
*/
ComponentABC[VIEW_MODEL_FACTORY] = function (params, componentInfo) {
return new this(params, componentInfo);
};
ComponentABC.register = function (name) {
if (name === void 0) { name = this.customElementName; }
var viewModel = this;
var template = this.template;
var synchronous = this.sync;
register(name, { viewModel: viewModel, template: template, synchronous: synchronous });
};
return ComponentABC;
}(LifeCycle));
var index = {
ComponentABC: ComponentABC,
// -- Registry --
get: registry.get,
clearCachedDefinition: registry.clearCachedDefinition,
// -- Loader --
register: register,
isRegistered: isRegistered,
unregister: unregister,
defaultLoader: defaultLoader,
// "Privately" expose the underlying config registry for use in old-IE shim
_allRegisteredComponents: defaultConfigRegistry,
get loaders() { return registry.loaders; },
set loaders(loaders) { registry.loaders = loaders; }
};
export default index;
export { ComponentABC };
//# sourceMappingURL=utils.component.js.map
{"version":3,"file":"utils.component.js","sources":["../../../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;AAgBA,IAAI,aAAa,GAAG,SAAS,CAAC,EAAE,CAAC,EAAE;IAC/B,aAAa,GAAG,MAAM,CAAC,cAAc;SAChC,EAAE,SAAS,EAAE,EAAE,EAAE,YAAY,KAAK,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;QAC5E,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,KA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