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

@tko/binding.template

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tko/binding.template - npm Package Compare versions

Comparing version
4.0.0-beta1.3
to
4.0.0
+5
-11
dist/foreach.js

@@ -1,12 +0,6 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 ESM
import {
unwrap,
peek
} from "@tko/observable";
import {
nativeTemplateEngine
} from "./nativeTemplateEngine";
import {
TemplateBindingHandler
} from "./templating";
// @tko/binding.template 🥊 4.0.0 ESM
"use strict";
import { unwrap, peek } from "@tko/observable";
import { nativeTemplateEngine } from "./nativeTemplateEngine";
import { TemplateBindingHandler } from "./templating";
export class TemplateForEachBindingHandler extends TemplateBindingHandler {

@@ -13,0 +7,0 @@ get value() {

{
"version": 3,
"sources": ["../src/foreach.ts"],
"sourcesContent": ["\nimport {\n unwrap, peek\n} from '@tko/observable'\n\nimport {\n nativeTemplateEngine\n} from './nativeTemplateEngine'\n\nimport {\n TemplateBindingHandler\n} from './templating'\n\n// \"foreach: someExpression\" is equivalent to \"template: { foreach: someExpression }\"\n// \"foreach: { data: someExpression, afterAdd: myfn }\" is equivalent to \"template: { foreach: someExpression, afterAdd: myfn }\"\nexport class TemplateForEachBindingHandler extends TemplateBindingHandler {\n get value () {\n const modelValue = this.valueAccessor()\n const unwrappedValue = peek(modelValue) // Unwrap without setting a dependency here\n\n // If unwrappedValue is the array, pass in the wrapped value on its own\n // The value will be unwrapped and tracked within the template binding\n // (See https://github.com/SteveSanderson/knockout/issues/523)\n if (!unwrappedValue || typeof unwrappedValue.length === 'number') {\n return { foreach: modelValue, templateEngine: nativeTemplateEngine.instance }\n }\n\n // If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates\n unwrap(modelValue)\n return {\n foreach: unwrappedValue.data,\n as: unwrappedValue.as,\n includeDestroyed: unwrappedValue.includeDestroyed,\n afterAdd: unwrappedValue.afterAdd,\n beforeRemove: unwrappedValue.beforeRemove,\n afterRender: unwrappedValue.afterRender,\n beforeMove: unwrappedValue.beforeMove,\n afterMove: unwrappedValue.afterMove,\n templateEngine: nativeTemplateEngine.instance\n }\n }\n}\n"],
"mappings": ";AACA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA;AAAA;AAAA;AAMO,aAAM,sCAAsC,uBAAuB;AAAA,MACpE,QAAS;AACX,UAAM,aAAa,KAAK,cAAc;AACtC,UAAM,iBAAiB,KAAK,UAAU;AAKtC,QAAI,CAAC,kBAAkB,OAAO,eAAe,WAAW,UAAU;AAChE,aAAO,EAAE,SAAS,YAAY,gBAAgB,qBAAqB,SAAS;AAAA,IAC9E;AAGA,WAAO,UAAU;AACjB,WAAO;AAAA,MACL,SAAS,eAAe;AAAA,MACxB,IAAI,eAAe;AAAA,MACnB,kBAAkB,eAAe;AAAA,MACjC,UAAU,eAAe;AAAA,MACzB,cAAc,eAAe;AAAA,MAC7B,aAAa,eAAe;AAAA,MAC5B,YAAY,eAAe;AAAA,MAC3B,WAAW,eAAe;AAAA,MAC1B,gBAAgB,qBAAqB;AAAA,IACvC;AAAA,EACF;AACF;",
"sourcesContent": ["import { unwrap, peek } from '@tko/observable'\n\nimport { nativeTemplateEngine } from './nativeTemplateEngine'\n\nimport { TemplateBindingHandler } from './templating'\n\n// \"foreach: someExpression\" is equivalent to \"template: { foreach: someExpression }\"\n// \"foreach: { data: someExpression, afterAdd: myfn }\" is equivalent to \"template: { foreach: someExpression, afterAdd: myfn }\"\nexport class TemplateForEachBindingHandler extends TemplateBindingHandler {\n override get value() {\n const modelValue = this.valueAccessor()\n const unwrappedValue = peek(modelValue) // Unwrap without setting a dependency here\n\n // If unwrappedValue is the array, pass in the wrapped value on its own\n // The value will be unwrapped and tracked within the template binding\n // (See https://github.com/SteveSanderson/knockout/issues/523)\n if (!unwrappedValue || typeof unwrappedValue.length === 'number') {\n return { foreach: modelValue, templateEngine: nativeTemplateEngine.instance }\n }\n\n // If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates\n unwrap(modelValue)\n return {\n foreach: unwrappedValue.data,\n as: unwrappedValue.as,\n includeDestroyed: unwrappedValue.includeDestroyed,\n afterAdd: unwrappedValue.afterAdd,\n beforeRemove: unwrappedValue.beforeRemove,\n afterRender: unwrappedValue.afterRender,\n beforeMove: unwrappedValue.beforeMove,\n afterMove: unwrappedValue.afterMove,\n templateEngine: nativeTemplateEngine.instance\n }\n }\n}\n"],
"mappings": ";;AAAA,SAAS,QAAQ,YAAY;AAE7B,SAAS,4BAA4B;AAErC,SAAS,8BAA8B;AAIhC,aAAM,sCAAsC,uBAAuB;AAAA,EACxE,IAAa,QAAQ;AACnB,UAAM,aAAa,KAAK,cAAc;AACtC,UAAM,iBAAiB,KAAK,UAAU;AAKtC,QAAI,CAAC,kBAAkB,OAAO,eAAe,WAAW,UAAU;AAChE,aAAO,EAAE,SAAS,YAAY,gBAAgB,qBAAqB,SAAS;AAAA,IAC9E;AAGA,WAAO,UAAU;AACjB,WAAO;AAAA,MACL,SAAS,eAAe;AAAA,MACxB,IAAI,eAAe;AAAA,MACnB,kBAAkB,eAAe;AAAA,MACjC,UAAU,eAAe;AAAA,MACzB,cAAc,eAAe;AAAA,MAC7B,aAAa,eAAe;AAAA,MAC5B,YAAY,eAAe;AAAA,MAC3B,WAAW,eAAe;AAAA,MAC1B,gBAAgB,qBAAqB;AAAA,IACvC;AAAA,EACF;AACF;",
"names": []
}

@@ -1,12 +0,6 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 ESM
import {
TemplateForEachBindingHandler
} from "./foreach";
import {
TemplateBindingHandler
} from "./templating";
export const bindings = {
foreach: TemplateForEachBindingHandler,
template: TemplateBindingHandler
};
// @tko/binding.template 🥊 4.0.0 ESM
"use strict";
import { TemplateForEachBindingHandler } from "./foreach";
import { TemplateBindingHandler } from "./templating";
export const bindings = { foreach: TemplateForEachBindingHandler, template: TemplateBindingHandler };
export * from "./nativeTemplateEngine";

@@ -13,0 +7,0 @@ export * from "./templateEngine";

{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["\nimport {\n TemplateForEachBindingHandler\n} from './foreach'\n\nimport {\n TemplateBindingHandler\n} from './templating'\n// 'let': letBinding,\n// template: template,\n\nexport const bindings = {\n foreach: TemplateForEachBindingHandler,\n template: TemplateBindingHandler\n}\n\nexport * from './nativeTemplateEngine'\nexport * from './templateEngine'\nexport * from './templating'\nexport * from './templateSources'\n"],
"mappings": ";AACA;AAAA;AAAA;AAIA;AAAA;AAAA;AAMO,aAAM,WAAW;AAAA,EACtB,SAAS;AAAA,EACT,UAAU;AACZ;AAEA;AACA;AACA;AACA;",
"sourcesContent": ["import { TemplateForEachBindingHandler } from './foreach'\n\nimport { TemplateBindingHandler } from './templating'\n// 'let': letBinding,\n// template: template,\n\nexport const bindings = { foreach: TemplateForEachBindingHandler, template: TemplateBindingHandler }\n\nexport * from './nativeTemplateEngine'\nexport * from './templateEngine'\nexport * from './templating'\nexport * from './templateSources'\n"],
"mappings": ";;AAAA,SAAS,qCAAqC;AAE9C,SAAS,8BAA8B;AAIhC,aAAM,WAAW,EAAE,SAAS,+BAA+B,UAAU,uBAAuB;AAEnG,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
"names": []
}

@@ -1,12 +0,6 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 MJS
import {
TemplateForEachBindingHandler
} from "./foreach";
import {
TemplateBindingHandler
} from "./templating";
export const bindings = {
foreach: TemplateForEachBindingHandler,
template: TemplateBindingHandler
};
// @tko/binding.template 🥊 4.0.0 MJS
"use strict";
import { TemplateForEachBindingHandler } from "./foreach";
import { TemplateBindingHandler } from "./templating";
export const bindings = { foreach: TemplateForEachBindingHandler, template: TemplateBindingHandler };
export * from "./nativeTemplateEngine";

@@ -13,0 +7,0 @@ export * from "./templateEngine";

{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["\nimport {\n TemplateForEachBindingHandler\n} from './foreach'\n\nimport {\n TemplateBindingHandler\n} from './templating'\n// 'let': letBinding,\n// template: template,\n\nexport const bindings = {\n foreach: TemplateForEachBindingHandler,\n template: TemplateBindingHandler\n}\n\nexport * from './nativeTemplateEngine'\nexport * from './templateEngine'\nexport * from './templating'\nexport * from './templateSources'\n"],
"mappings": ";AACA;AAAA;AAAA;AAIA;AAAA;AAAA;AAMO,aAAM,WAAW;AAAA,EACtB,SAAS;AAAA,EACT,UAAU;AACZ;AAEA;AACA;AACA;AACA;",
"sourcesContent": ["import { TemplateForEachBindingHandler } from './foreach'\n\nimport { TemplateBindingHandler } from './templating'\n// 'let': letBinding,\n// template: template,\n\nexport const bindings = { foreach: TemplateForEachBindingHandler, template: TemplateBindingHandler }\n\nexport * from './nativeTemplateEngine'\nexport * from './templateEngine'\nexport * from './templating'\nexport * from './templateSources'\n"],
"mappings": ";;AAAA,SAAS,qCAAqC;AAE9C,SAAS,8BAA8B;AAIhC,aAAM,WAAW,EAAE,SAAS,+BAA+B,UAAU,uBAAuB;AAEnG,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
"names": []
}

@@ -1,13 +0,6 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 ESM
import {
ieVersion,
makeArray,
parseHtmlFragment
} from "@tko/utils";
import {
templateEngine
} from "./templateEngine";
import {
setTemplateEngine
} from "./templating";
// @tko/binding.template 🥊 4.0.0 ESM
"use strict";
import { makeArray, parseHtmlFragment } from "@tko/utils";
import { templateEngine } from "./templateEngine";
import { setTemplateEngine } from "./templating";
export function nativeTemplateEngine() {

@@ -17,8 +10,8 @@ }

nativeTemplateEngine.prototype.constructor = nativeTemplateEngine;
nativeTemplateEngine.prototype.renderTemplateSource = function(templateSource, bindingContext, options2, templateDocument) {
var useNodesIfAvailable = !(ieVersion < 9), templateNodesFunc = useNodesIfAvailable ? templateSource.nodes : null, templateNodes = templateNodesFunc ? templateSource.nodes() : null;
nativeTemplateEngine.prototype.renderTemplateSource = function(templateSource, bindingContext, options, templateDocument) {
const templateNodes = templateSource.nodes ? templateSource.nodes() : null;
if (templateNodes) {
return makeArray(templateNodes.cloneNode(true).childNodes);
} else {
var templateText = templateSource.text();
const templateText = templateSource.text();
return parseHtmlFragment(templateText, templateDocument);

@@ -25,0 +18,0 @@ }

{
"version": 3,
"sources": ["../src/nativeTemplateEngine.ts"],
"sourcesContent": ["\nimport {\n extend, options, ieVersion, makeArray, parseHtmlFragment\n} from '@tko/utils'\n\nimport {\n templateEngine\n} from './templateEngine'\n\nimport {\n setTemplateEngine\n} from './templating'\n\nexport function nativeTemplateEngine () {\n}\n\nnativeTemplateEngine.prototype = new templateEngine()\nnativeTemplateEngine.prototype.constructor = nativeTemplateEngine\nnativeTemplateEngine.prototype.renderTemplateSource = function (templateSource, bindingContext, options, templateDocument) {\n var useNodesIfAvailable = !(ieVersion < 9), // IE<9 cloneNode doesn't work properly\n templateNodesFunc = useNodesIfAvailable ? templateSource.nodes : null,\n templateNodes = templateNodesFunc ? templateSource.nodes() : null\n\n if (templateNodes) {\n return makeArray(templateNodes.cloneNode(true).childNodes)\n } else {\n var templateText = templateSource.text()\n return parseHtmlFragment(templateText, templateDocument)\n }\n}\n\nnativeTemplateEngine.instance = new nativeTemplateEngine()\nsetTemplateEngine(nativeTemplateEngine.instance)\n"],
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIO,uCAAiC;AACxC;AAEA,qBAAqB,YAAY,IAAI,eAAe;AACpD,qBAAqB,UAAU,cAAc;AAC7C,qBAAqB,UAAU,uBAAuB,SAAU,gBAAgB,gBAAgB,UAAS,kBAAkB;AACzH,MAAI,sBAAsB,CAAE,aAAY,IACtC,oBAAoB,sBAAsB,eAAe,QAAQ,MACjE,gBAAgB,oBAAoB,eAAe,MAAM,IAAI;AAE/D,MAAI,eAAe;AACjB,WAAO,UAAU,cAAc,UAAU,IAAI,EAAE,UAAU;AAAA,EAC3D,OAAO;AACL,QAAI,eAAe,eAAe,KAAK;AACvC,WAAO,kBAAkB,cAAc,gBAAgB;AAAA,EACzD;AACF;AAEA,qBAAqB,WAAW,IAAI,qBAAqB;AACzD,kBAAkB,qBAAqB,QAAQ;",
"sourcesContent": ["import { makeArray, parseHtmlFragment } from '@tko/utils'\nimport { templateEngine, TemplateOptions } from './templateEngine'\nimport { setTemplateEngine } from './templating'\nimport type { TemplateSource } from './templateSources'\nimport type { BindingContext } from '@tko/bind'\n\nexport function nativeTemplateEngine() {}\n\nnativeTemplateEngine.prototype = new templateEngine()\nnativeTemplateEngine.prototype.constructor = nativeTemplateEngine\nnativeTemplateEngine.prototype.renderTemplateSource = function (\n templateSource: TemplateSource,\n bindingContext: BindingContext<any>,\n options: TemplateOptions<any>,\n templateDocument?: Document\n): Node[] {\n const templateNodes = templateSource.nodes ? templateSource.nodes() : null\n\n if (templateNodes) {\n return makeArray(templateNodes.cloneNode(true).childNodes)\n } else {\n const templateText = templateSource.text()\n return parseHtmlFragment(templateText, templateDocument)\n }\n}\n\nnativeTemplateEngine.instance = new nativeTemplateEngine()\nsetTemplateEngine(nativeTemplateEngine.instance)\n"],
"mappings": ";;AAAA,SAAS,WAAW,yBAAyB;AAC7C,SAAS,sBAAuC;AAChD,SAAS,yBAAyB;AAI3B,gBAAS,uBAAuB;AAAC;AAExC,qBAAqB,YAAY,IAAI,eAAe;AACpD,qBAAqB,UAAU,cAAc;AAC7C,qBAAqB,UAAU,uBAAuB,SACpD,gBACA,gBACA,SACA,kBACQ;AACR,QAAM,gBAAgB,eAAe,QAAQ,eAAe,MAAM,IAAI;AAEtE,MAAI,eAAe;AACjB,WAAO,UAAU,cAAc,UAAU,IAAI,EAAE,UAAU;AAAA,EAC3D,OAAO;AACL,UAAM,eAAe,eAAe,KAAK;AACzC,WAAO,kBAAkB,cAAc,gBAAgB;AAAA,EACzD;AACF;AAEA,qBAAqB,WAAW,IAAI,qBAAqB;AACzD,kBAAkB,qBAAqB,QAAQ;",
"names": []
}

@@ -1,38 +0,34 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 ESM
import {
extend,
options
} from "@tko/utils";
import {
domElement,
anonymousTemplate
} from "./templateSources";
// @tko/binding.template 🥊 4.0.0 ESM
"use strict";
import { extend, options } from "@tko/utils";
import { domElement, anonymousTemplate } from "./templateSources";
export function templateEngine() {
}
;
extend(templateEngine.prototype, {
renderTemplateSource: function(templateSource, bindingContext, options2, templateDocument) {
renderTemplateSource(templateSource, bindingContext, options2, templateDocument) {
options2.onError("Override renderTemplateSource");
},
createJavaScriptEvaluatorBlock: function(script) {
options.onError("Override createJavaScriptEvaluatorBlock");
createJavaScriptEvaluatorBlock(script) {
options.onError(new Error("Override createJavaScriptEvaluatorBlock"));
},
makeTemplateSource: function(template, templateDocument) {
makeTemplateSource(template, templateDocument) {
if (typeof template === "string") {
templateDocument = templateDocument || document;
var elem = templateDocument.getElementById(template);
const elem = templateDocument.getElementById(template);
if (!elem) {
options.onError("Cannot find template with ID " + template);
throw options.onError(new Error("Cannot find template with ID " + template), false);
}
return new domElement(elem);
} else if (template.nodeType == 1 || template.nodeType == 8) {
} else if (template.nodeType === Node.ELEMENT_NODE) {
return new anonymousTemplate(template);
} else if (template.nodeType === Node.COMMENT_NODE) {
return new anonymousTemplate(template);
} else {
options.onError("Unknown template type: " + template);
throw options.onError(new Error("Unknown template type: " + template), false);
}
},
renderTemplate: function(template, bindingContext, options2, templateDocument) {
var templateSource = this["makeTemplateSource"](template, templateDocument);
renderTemplate(template, bindingContext, options2, templateDocument) {
const templateSource = this.makeTemplateSource(template, templateDocument);
return this.renderTemplateSource(templateSource, bindingContext, options2, templateDocument);
}
});
{
"version": 3,
"sources": ["../src/templateEngine.ts"],
"sourcesContent": ["// If you want to make a custom template engine,\n//\n// [1] Inherit from this class (like ko.nativeTemplateEngine does)\n// [2] Override 'renderTemplateSource', supplying a function with this signature:\n//\n// function (templateSource, bindingContext, options) {\n// // - templateSource.text() is the text of the template you should render\n// // - bindingContext.$data is the data you should pass into the template\n// // - you might also want to make bindingContext.$parent, bindingContext.$parents,\n// // and bindingContext.$root available in the template too\n// // - options gives you access to any other properties set on \"data-bind: { template: options }\"\n// // - templateDocument is the document object of the template\n// //\n// // Return value: an array of DOM nodes\n// }\n//\n// [3] Override 'createJavaScriptEvaluatorBlock', supplying a function with this signature:\n//\n// function (script) {\n// // Return value: Whatever syntax means \"Evaluate the JavaScript statement 'script' and output the result\"\n// // For example, the jquery.tmpl template engine converts 'someScript' to '${ someScript }'\n// }\n//\n// This is only necessary if you want to allow data-bind attributes to reference arbitrary template variables.\n// If you don't want to allow that, you can set the property 'allowTemplateRewriting' to false (like ko.nativeTemplateEngine does)\n// and then you don't need to override 'createJavaScriptEvaluatorBlock'.\n\nimport {\n extend, options\n} from '@tko/utils'\n\nimport {\n domElement, anonymousTemplate\n} from './templateSources'\n\nexport function templateEngine () { };\n\nextend(templateEngine.prototype, {\n renderTemplateSource: function (templateSource, bindingContext, options, templateDocument) {\n options.onError('Override renderTemplateSource')\n },\n\n createJavaScriptEvaluatorBlock: function (script) {\n options.onError('Override createJavaScriptEvaluatorBlock')\n },\n\n makeTemplateSource: function (template, templateDocument) {\n // Named template\n if (typeof template === 'string') {\n templateDocument = templateDocument || document\n var elem = templateDocument.getElementById(template)\n if (!elem) { options.onError('Cannot find template with ID ' + template) }\n return new domElement(elem)\n } else if ((template.nodeType == 1) || (template.nodeType == 8)) {\n // Anonymous template\n return new anonymousTemplate(template)\n } else { options.onError('Unknown template type: ' + template) }\n },\n\n renderTemplate: function (template, bindingContext, options, templateDocument) {\n var templateSource = this['makeTemplateSource'](template, templateDocument)\n return this.renderTemplateSource(templateSource, bindingContext, options, templateDocument)\n }\n})\n"],
"mappings": ";AA2BA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAAA;AAIO,iCAA2B;AAAE;AAAC;AAErC,OAAO,eAAe,WAAW;AAAA,EAC/B,sBAAsB,SAAU,gBAAgB,gBAAgB,UAAS,kBAAkB;AACzF,aAAQ,QAAQ,+BAA+B;AAAA,EACjD;AAAA,EAEA,gCAAgC,SAAU,QAAQ;AAChD,YAAQ,QAAQ,yCAAyC;AAAA,EAC3D;AAAA,EAEA,oBAAoB,SAAU,UAAU,kBAAkB;AAExD,QAAI,OAAO,aAAa,UAAU;AAChC,yBAAmB,oBAAoB;AACvC,UAAI,OAAO,iBAAiB,eAAe,QAAQ;AACnD,UAAI,CAAC,MAAM;AAAE,gBAAQ,QAAQ,kCAAkC,QAAQ;AAAA,MAAE;AACzE,aAAO,IAAI,WAAW,IAAI;AAAA,IAC5B,WAAY,SAAS,YAAY,KAAO,SAAS,YAAY,GAAI;AAE/D,aAAO,IAAI,kBAAkB,QAAQ;AAAA,IACvC,OAAO;AAAE,cAAQ,QAAQ,4BAA4B,QAAQ;AAAA,IAAE;AAAA,EACjE;AAAA,EAEA,gBAAgB,SAAU,UAAU,gBAAgB,UAAS,kBAAkB;AAC7E,QAAI,iBAAiB,KAAK,sBAAsB,UAAU,gBAAgB;AAC1E,WAAO,KAAK,qBAAqB,gBAAgB,gBAAgB,UAAS,gBAAgB;AAAA,EAC5F;AACF,CAAC;",
"names": []
"sourcesContent": ["// If you want to make a custom template engine,\n//\n// [1] Inherit from this class (like ko.nativeTemplateEngine does)\n// [2] Override 'renderTemplateSource', supplying a function with this signature:\n//\n// function (templateSource, bindingContext, options) {\n// // - templateSource.text() is the text of the template you should render\n// // - bindingContext.$data is the data you should pass into the template\n// // - you might also want to make bindingContext.$parent, bindingContext.$parents,\n// // and bindingContext.$root available in the template too\n// // - options gives you access to any other properties set on \"data-bind: { template: options }\"\n// // - templateDocument is the document object of the template\n// //\n// // Return value: an array of DOM nodes\n// }\n//\n// [3] Override 'createJavaScriptEvaluatorBlock', supplying a function with this signature:\n//\n// function (script) {\n// // Return value: Whatever syntax means \"Evaluate the JavaScript statement 'script' and output the result\"\n// // For example, the jquery.tmpl template engine converts 'someScript' to '${ someScript }'\n// }\n//\n// This is only necessary if you want to allow data-bind attributes to reference arbitrary template variables.\n// If you don't want to allow that, you can set the property 'allowTemplateRewriting' to false (like ko.nativeTemplateEngine does)\n// and then you don't need to override 'createJavaScriptEvaluatorBlock'.\n\nimport { extend, options } from '@tko/utils'\nimport { domElement, anonymousTemplate } from './templateSources'\nimport type { TemplateSource } from './templateSources'\nimport type { BindingContext } from '@tko/bind'\n\nexport interface TemplateOptions<T = any> {\n afterRender?: (elements: Node[], dataItem: T) => void\n templateEngine?: TemplateEngine\n}\n\nexport interface TemplateEngine {\n allowTemplateRewriting: boolean\n\n renderTemplateSource(\n templateSource: TemplateSource,\n bindingContext: BindingContext<any>,\n options: TemplateOptions<any>,\n templateDocument?: Document\n ): Node[]\n createJavaScriptEvaluatorBlock(script: string): string\n\n makeTemplateSource(template: string | Node, templateDocument?: Document): TemplateSource\n\n renderTemplate(\n template: string | Node,\n bindingContext: BindingContext<any>,\n options: TemplateOptions<any>,\n templateDocument?: Document\n ): Node[]\n\n isTemplateRewritten(template: string | Node, templateDocument?: Document): boolean\n\n rewriteTemplate(template: string | Node, rewriterCallback: (val: string) => string, templateDocument?: Document): void\n}\n\n//TODO Class-Migration implements TemplateEngine\nexport function templateEngine() {}\n\nextend(templateEngine.prototype, {\n renderTemplateSource(\n templateSource: TemplateSource,\n bindingContext: BindingContext<any>,\n options,\n templateDocument?: Document\n ) {\n // templateSource, bindingContext, templateDocument not in use\n options.onError('Override renderTemplateSource')\n },\n\n createJavaScriptEvaluatorBlock(script: string) {\n options.onError(new Error('Override createJavaScriptEvaluatorBlock'))\n },\n\n makeTemplateSource(template: string | Node, templateDocument?: Document): TemplateSource {\n // Named template\n if (typeof template === 'string') {\n templateDocument = templateDocument || document\n const elem = templateDocument.getElementById(template)\n if (!elem) {\n throw options.onError(new Error('Cannot find template with ID ' + template), false)\n }\n return new domElement(elem)\n } else if (template.nodeType === Node.ELEMENT_NODE) {\n // Anonymous template\n return new anonymousTemplate(template as Element)\n } else if (template.nodeType === Node.COMMENT_NODE) {\n // Anonymous template stored in a comment node\n return new anonymousTemplate(template as Comment)\n } else {\n throw options.onError(new Error('Unknown template type: ' + template), false)\n }\n },\n\n renderTemplate(\n template: string | Node,\n bindingContext: BindingContext<any>,\n options: TemplateOptions<any>,\n templateDocument?: Document\n ): Node[] {\n const templateSource = this.makeTemplateSource(template, templateDocument)\n return this.renderTemplateSource(templateSource, bindingContext, options, templateDocument)\n }\n})\n"],
"mappings": ";;AA2BA,SAAS,QAAQ,eAAe;AAChC,SAAS,YAAY,yBAAyB;AAmCvC,gBAAS,iBAAiB;AAAC;AAElC,OAAO,eAAe,WAAW;AAAA,EAC/B,qBACE,gBACA,gBACAA,UACA,kBACA;AAEA,IAAAA,SAAQ,QAAQ,+BAA+B;AAAA,EACjD;AAAA,EAEA,+BAA+B,QAAgB;AAC7C,YAAQ,QAAQ,IAAI,MAAM,yCAAyC,CAAC;AAAA,EACtE;AAAA,EAEA,mBAAmB,UAAyB,kBAA6C;AAEvF,QAAI,OAAO,aAAa,UAAU;AAChC,yBAAmB,oBAAoB;AACvC,YAAM,OAAO,iBAAiB,eAAe,QAAQ;AACrD,UAAI,CAAC,MAAM;AACT,cAAM,QAAQ,QAAQ,IAAI,MAAM,kCAAkC,QAAQ,GAAG,KAAK;AAAA,MACpF;AACA,aAAO,IAAI,WAAW,IAAI;AAAA,IAC5B,WAAW,SAAS,aAAa,KAAK,cAAc;AAElD,aAAO,IAAI,kBAAkB,QAAmB;AAAA,IAClD,WAAW,SAAS,aAAa,KAAK,cAAc;AAElD,aAAO,IAAI,kBAAkB,QAAmB;AAAA,IAClD,OAAO;AACL,YAAM,QAAQ,QAAQ,IAAI,MAAM,4BAA4B,QAAQ,GAAG,KAAK;AAAA,IAC9E;AAAA,EACF;AAAA,EAEA,eACE,UACA,gBACAA,UACA,kBACQ;AACR,UAAM,iBAAiB,KAAK,mBAAmB,UAAU,gBAAgB;AACzE,WAAO,KAAK,qBAAqB,gBAAgB,gBAAgBA,UAAS,gBAAgB;AAAA,EAC5F;AACF,CAAC;",
"names": ["options"]
}

@@ -1,39 +0,7 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 ESM
import {
tagNameLower as tagNameLowerFn,
setHtml,
domData,
parseHtmlForTemplateNodes
} from "@tko/utils";
var templateScript = 1, templateTextArea = 2, templateTemplate = 3, templateElement = 4;
export function domElement(element) {
this.domElement = element;
if (!element) {
return;
}
var tagNameLower = tagNameLowerFn(element);
this.templateType = tagNameLower === "script" ? templateScript : tagNameLower === "textarea" ? templateTextArea : tagNameLower == "template" && element.content && element.content.nodeType === 11 ? templateTemplate : templateElement;
}
domElement.prototype.text = function() {
var elemContentsProperty = this.templateType === templateScript ? "text" : this.templateType === templateTextArea ? "value" : "innerHTML";
if (arguments.length == 0) {
return this.domElement[elemContentsProperty];
} else {
var valueToWrite = arguments[0];
if (elemContentsProperty === "innerHTML") {
setHtml(this.domElement, valueToWrite);
} else {
this.domElement[elemContentsProperty] = valueToWrite;
}
}
};
var dataDomDataPrefix = domData.nextKey() + "_";
domElement.prototype.data = function(key) {
if (arguments.length === 1) {
return domData.get(this.domElement, dataDomDataPrefix + key);
} else {
domData.set(this.domElement, dataDomDataPrefix + key, arguments[1]);
}
};
var templatesDomDataKey = domData.nextKey();
// @tko/binding.template 🥊 4.0.0 ESM
"use strict";
import { tagNameLower as tagNameLowerFn, setHtml, domData, parseHtmlForTemplateNodes } from "@tko/utils";
const templateScript = 1, templateTextArea = 2, templateTemplate = 3, templateElement = 4, templateAnonymous = 5;
const dataDomDataPrefix = domData.nextKey() + "_";
const templatesDomDataKey = domData.nextKey();
function getTemplateDomData(element) {

@@ -45,37 +13,70 @@ return domData.get(element, templatesDomDataKey) || {};

}
domElement.prototype.nodes = function() {
var element = this.domElement;
if (arguments.length == 0) {
const templateData = getTemplateDomData(element);
let nodes = templateData.containerData || (this.templateType === templateTemplate ? element.content : this.templateType === templateElement ? element : void 0);
if (!nodes || templateData.alwaysCheckText) {
const text = this["text"]();
if (text) {
nodes = parseHtmlForTemplateNodes(text, element.ownerDocument);
this["text"]("");
setTemplateDomData(element, { containerData: nodes, alwaysCheckText: true });
export class domElement {
constructor(element) {
this.domElement = element;
if (element.nodeType === Node.COMMENT_NODE) {
this.templateType = templateElement;
} else {
const tagNameLower = tagNameLowerFn(this.domElement);
this.templateType = tagNameLower === "script" ? templateScript : tagNameLower === "textarea" ? templateTextArea : (
// For browsers with proper <template> element support, where the .content property gives a document fragment
tagNameLower == "template" && element.content && element.content.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? templateTemplate : templateElement
);
}
}
text(valueToWrite) {
const elemContentsProperty = this.templateType === templateScript ? "text" : this.templateType === templateTextArea ? "value" : "innerHTML";
if (arguments.length == 0) {
return this.domElement[elemContentsProperty];
} else {
if (elemContentsProperty === "innerHTML") {
setHtml(this.domElement, valueToWrite);
} else {
this.domElement[elemContentsProperty] = valueToWrite;
}
}
return nodes;
} else {
var valueToWrite = arguments[0];
setTemplateDomData(element, { containerData: valueToWrite });
}
};
export function anonymousTemplate(element) {
this.domElement = element;
data(key, valueToWrite) {
if (arguments.length === 1) {
return domData.get(this.domElement, dataDomDataPrefix + key);
} else {
domData.set(this.domElement, dataDomDataPrefix + key, valueToWrite);
}
}
nodes(valueToWrite) {
const element = this.domElement;
if (arguments.length == 0) {
const templateData = getTemplateDomData(element);
let nodes = templateData.containerData || (this.templateType === templateTemplate ? element.content : this.templateType === templateElement ? element : void 0);
if (!nodes || templateData.alwaysCheckText) {
const text = this.text();
if (text) {
nodes = parseHtmlForTemplateNodes(text, element.ownerDocument);
this.text("");
setTemplateDomData(element, { containerData: nodes, alwaysCheckText: true });
}
}
return nodes;
} else {
setTemplateDomData(element, { containerData: valueToWrite });
}
return void 0;
}
}
anonymousTemplate.prototype = new domElement();
anonymousTemplate.prototype.constructor = anonymousTemplate;
anonymousTemplate.prototype.text = function() {
if (arguments.length == 0) {
var templateData = getTemplateDomData(this.domElement);
if (templateData.textData === void 0 && templateData.containerData) {
templateData.textData = templateData.containerData.innerHTML;
export class anonymousTemplate extends domElement {
constructor(element) {
super(element);
this.templateType = templateAnonymous;
}
text(valueToWrite) {
if (arguments.length == 0) {
const templateData = getTemplateDomData(this.domElement);
if (templateData.textData === void 0 && templateData.containerData) {
templateData.textData = templateData.containerData.innerHTML;
}
return templateData.textData;
} else {
setTemplateDomData(this.domElement, { textData: valueToWrite });
}
return templateData.textData;
} else {
var valueToWrite = arguments[0];
setTemplateDomData(this.domElement, { textData: valueToWrite });
}
};
}
{
"version": 3,
"sources": ["../src/templateSources.ts"],
"sourcesContent": ["// A template source represents a read/write way of accessing a template. This is to eliminate the need for template loading/saving\n// logic to be duplicated in every template engine (and means they can all work with anonymous templates, etc.)\n//\n// Two are provided by default:\n// 1. ko.templateSources.domElement - reads/writes the text content of an arbitrary DOM element\n// 2. ko.templateSources.anonymousElement - uses ko.utils.domData to read/write text *associated* with the DOM element, but\n// without reading/writing the actual element text content, since it will be overwritten\n// with the rendered template output.\n// You can implement your own template source if you want to fetch/store templates somewhere other than in DOM elements.\n// Template sources need to have the following functions:\n// text() \t\t\t- returns the template text from your storage location\n// text(value)\t\t- writes the supplied template text to your storage location\n// data(key)\t\t\t- reads values stored using data(key, value) - see below\n// data(key, value)\t- associates \"value\" with this template and the key \"key\". Is used to store information like \"isRewritten\".\n//\n// Optionally, template sources can also have the following functions:\n// nodes() - returns a DOM element containing the nodes of this template, where available\n// nodes(value) - writes the given DOM element to your storage location\n// If a DOM element is available for a given template source, template engines are encouraged to use it in preference over text()\n// for improved speed. However, all templateSources must supply text() even if they don't supply nodes().\n//\n// Once you've implemented a templateSource, make your template engine use it by subclassing whatever template engine you were\n// using and overriding \"makeTemplateSource\" to return an instance of your custom template source.\n\nimport {\n tagNameLower as tagNameLowerFn, setHtml, domData, parseHtmlForTemplateNodes\n} from '@tko/utils'\n\n// ---- ko.templateSources.domElement -----\n\n// template types\nvar templateScript = 1,\n templateTextArea = 2,\n templateTemplate = 3,\n templateElement = 4\n\nexport function domElement (element) {\n this.domElement = element\n\n if (!element) { return }\n var tagNameLower = tagNameLowerFn(element)\n this.templateType =\n tagNameLower === 'script' ? templateScript\n : tagNameLower === 'textarea' ? templateTextArea\n // For browsers with proper <template> element support, where the .content property gives a document fragment\n : tagNameLower == 'template' && element.content && element.content.nodeType === 11 ? templateTemplate\n : templateElement\n}\n\ndomElement.prototype.text = function (/* valueToWrite */) {\n var elemContentsProperty = this.templateType === templateScript ? 'text'\n : this.templateType === templateTextArea ? 'value'\n : 'innerHTML'\n\n if (arguments.length == 0) {\n return this.domElement[elemContentsProperty]\n } else {\n var valueToWrite = arguments[0]\n if (elemContentsProperty === 'innerHTML') { setHtml(this.domElement, valueToWrite) } else { this.domElement[elemContentsProperty] = valueToWrite }\n }\n}\n\nvar dataDomDataPrefix = domData.nextKey() + '_'\ndomElement.prototype.data = function (key /*, valueToWrite */) {\n if (arguments.length === 1) {\n return domData.get(this.domElement, dataDomDataPrefix + key)\n } else {\n domData.set(this.domElement, dataDomDataPrefix + key, arguments[1])\n }\n}\n\nvar templatesDomDataKey = domData.nextKey()\nfunction getTemplateDomData (element) {\n return domData.get(element, templatesDomDataKey) || {}\n}\nfunction setTemplateDomData (element, data) {\n domData.set(element, templatesDomDataKey, data)\n}\n\ndomElement.prototype.nodes = function (/* valueToWrite */) {\n var element = this.domElement\n if (arguments.length == 0) {\n const templateData = getTemplateDomData(element)\n let nodes = templateData.containerData || (\n this.templateType === templateTemplate ? element.content :\n this.templateType === templateElement ? element :\n undefined\n )\n if (!nodes || templateData.alwaysCheckText) {\n // If the template is associated with an element that stores the template as text,\n // parse and cache the nodes whenever there's new text content available. This allows\n // the user to update the template content by updating the text of template node.\n const text = this['text']()\n if (text) {\n nodes = parseHtmlForTemplateNodes(text, element.ownerDocument)\n this['text']('') // clear the text from the node\n setTemplateDomData(element, {containerData: nodes, alwaysCheckText: true})\n }\n }\n\n return nodes\n } else {\n var valueToWrite = arguments[0]\n setTemplateDomData(element, {containerData: valueToWrite})\n }\n}\n\n// ---- ko.templateSources.anonymousTemplate -----\n// Anonymous templates are normally saved/retrieved as DOM nodes through \"nodes\".\n// For compatibility, you can also read \"text\"; it will be serialized from the nodes on demand.\n// Writing to \"text\" is still supported, but then the template data will not be available as DOM nodes.\n\nexport function anonymousTemplate (element) {\n this.domElement = element\n}\n\nanonymousTemplate.prototype = new domElement()\nanonymousTemplate.prototype.constructor = anonymousTemplate\nanonymousTemplate.prototype.text = function (/* valueToWrite */) {\n if (arguments.length == 0) {\n var templateData = getTemplateDomData(this.domElement)\n if (templateData.textData === undefined && templateData.containerData) { templateData.textData = templateData.containerData.innerHTML }\n return templateData.textData\n } else {\n var valueToWrite = arguments[0]\n setTemplateDomData(this.domElement, {textData: valueToWrite})\n }\n}\n"],
"mappings": ";AAwBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,IAAI,iBAAiB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,kBAAkB;AAEb,2BAAqB,SAAS;AACnC,OAAK,aAAa;AAElB,MAAI,CAAC,SAAS;AAAE;AAAA,EAAO;AACvB,MAAI,eAAe,eAAe,OAAO;AACzC,OAAK,eACC,iBAAiB,WAAW,iBAC1B,iBAAiB,aAAa,mBAE9B,gBAAgB,cAAc,QAAQ,WAAW,QAAQ,QAAQ,aAAa,KAAK,mBACnF;AACV;AAEA,WAAW,UAAU,OAAO,WAA8B;AACxD,MAAI,uBAAuB,KAAK,iBAAiB,iBAAiB,SACrC,KAAK,iBAAiB,mBAAmB,UACzC;AAE7B,MAAI,UAAU,UAAU,GAAG;AACzB,WAAO,KAAK,WAAW;AAAA,EACzB,OAAO;AACL,QAAI,eAAe,UAAU;AAC7B,QAAI,yBAAyB,aAAa;AAAE,cAAQ,KAAK,YAAY,YAAY;AAAA,IAAE,OAAO;AAAE,WAAK,WAAW,wBAAwB;AAAA,IAAa;AAAA,EACnJ;AACF;AAEA,IAAI,oBAAoB,QAAQ,QAAQ,IAAI;AAC5C,WAAW,UAAU,OAAO,SAAU,KAAyB;AAC7D,MAAI,UAA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;AAAA,EACtB,OAAO;AACL,QAAI,eAAe,UAAU;AAC7B,uBAAmB,KAAK,YAAY,EAAC,UAAU,aAAY,CAAC;AAAA,EAC9D;AACF;",
"sourcesContent": ["// A template source represents a read/write way of accessing a template. This is to eliminate the need for template loading/saving\n// logic to be duplicated in every template engine (and means they can all work with anonymous templates, etc.)\n//\n// Two are provided by default:\n// 1. ko.templateSources.domElement - reads/writes the text content of an arbitrary DOM element\n// 2. ko.templateSources.anonymousElement - uses ko.utils.domData to read/write text *associated* with the DOM element, but\n// without reading/writing the actual element text content, since it will be overwritten\n// with the rendered template output.\n// You can implement your own template source if you want to fetch/store templates somewhere other than in DOM elements.\n// Template sources need to have the following functions:\n// text() \t\t\t- returns the template text from your storage location\n// text(value)\t\t- writes the supplied template text to your storage location\n// data(key)\t\t\t- reads values stored using data(key, value) - see below\n// data(key, value)\t- associates \"value\" with this template and the key \"key\". Is used to store information like \"isRewritten\".\n//\n// Optionally, template sources can also have the following functions:\n// nodes() - returns a DOM element containing the nodes of this template, where available\n// nodes(value) - writes the given DOM element to your storage location\n// If a DOM element is available for a given template source, template engines are encouraged to use it in preference over text()\n// for improved speed. However, all templateSources must supply text() even if they don't supply nodes().\n//\n// Once you've implemented a templateSource, make your template engine use it by subclassing whatever template engine you were\n// using and overriding \"makeTemplateSource\" to return an instance of your custom template source.\n\nimport { tagNameLower as tagNameLowerFn, setHtml, domData, parseHtmlForTemplateNodes } from '@tko/utils'\n\n// ---- ko.templateSources.domElement -----\n\n// template types\nconst templateScript = 1,\n templateTextArea = 2,\n templateTemplate = 3,\n templateElement = 4,\n templateAnonymous = 5\n\nexport interface TemplateSource {\n text(): string\n text(valueToWrite: string): void\n text(valueToWrite?: string): string | void\n\n data(key: string): any\n data<T>(key: string): T\n data<T>(key: string, valueToWrite: T): void\n\n nodes(): Node\n nodes(valueToWrite: Node): undefined\n nodes(valueToWrite?: any): Node | undefined\n}\n\nconst dataDomDataPrefix = domData.nextKey() + '_'\nconst templatesDomDataKey = domData.nextKey()\nfunction getTemplateDomData(element) {\n return domData.get(element, templatesDomDataKey) || {}\n}\nfunction setTemplateDomData(element, data) {\n domData.set(element, templatesDomDataKey, data)\n}\n\nexport class domElement implements TemplateSource {\n protected domElement: Element | Comment\n protected templateType: number\n\n constructor(element: Element | Comment) {\n this.domElement = element\n\n if (element.nodeType === Node.COMMENT_NODE) {\n this.templateType = templateElement\n } else {\n const tagNameLower = tagNameLowerFn(this.domElement as Element)\n this.templateType =\n tagNameLower === 'script'\n ? templateScript\n : tagNameLower === 'textarea'\n ? templateTextArea\n : // For browsers with proper <template> element support, where the .content property gives a document fragment\n tagNameLower == 'template'\n && (element as HTMLTemplateElement).content\n && (element as HTMLTemplateElement).content.nodeType === Node.DOCUMENT_FRAGMENT_NODE\n ? templateTemplate\n : templateElement\n }\n }\n\n text(): string\n text(valueToWrite: string): void\n text(valueToWrite?: string): string | void {\n const elemContentsProperty =\n this.templateType === templateScript ? 'text' : this.templateType === templateTextArea ? 'value' : 'innerHTML'\n\n if (arguments.length == 0) {\n return this.domElement[elemContentsProperty]\n } else {\n if (elemContentsProperty === 'innerHTML') {\n setHtml(this.domElement, valueToWrite!)\n } else {\n this.domElement[elemContentsProperty] = valueToWrite\n }\n }\n }\n\n data<T = any>(key: string, valueToWrite?: T): T | void {\n if (arguments.length === 1) {\n return domData.get(this.domElement, dataDomDataPrefix + key)\n } else {\n domData.set(this.domElement, dataDomDataPrefix + key, valueToWrite)\n }\n }\n\n nodes(): Node\n nodes(valueToWrite: Node): undefined\n nodes(valueToWrite?: any): Node | undefined {\n const element = this.domElement\n if (arguments.length == 0) {\n const templateData = getTemplateDomData(element)\n let nodes =\n templateData.containerData\n || (this.templateType === templateTemplate\n ? (element as HTMLTemplateElement).content\n : this.templateType === templateElement\n ? element\n : undefined)\n if (!nodes || templateData.alwaysCheckText) {\n // If the template is associated with an element that stores the template as text,\n // parse and cache the nodes whenever there's new text content available. This allows\n // the user to update the template content by updating the text of template node.\n const text = this.text()\n if (text) {\n nodes = parseHtmlForTemplateNodes(text, element.ownerDocument)\n this.text('') // clear the text from the node\n setTemplateDomData(element, { containerData: nodes, alwaysCheckText: true })\n }\n }\n return nodes\n } else {\n setTemplateDomData(element, { containerData: valueToWrite })\n }\n return undefined\n }\n}\n\n// ---- ko.templateSources.anonymousTemplate -----\n// Anonymous templates are normally saved/retrieved as DOM nodes through \"nodes\".\n// For compatibility, you can also read \"text\"; it will be serialized from the nodes on demand.\n// Writing to \"text\" is still supported, but then the template data will not be available as DOM nodes.\nexport class anonymousTemplate extends domElement {\n constructor(element: Element | Comment) {\n super(element)\n //The old prototype construct uses an empty-constructor from domElement, so templateType and element was 'undefined'.\n //With the new templateType = templateAnonymous (5) we achieve the same behavior in the \"nodes\" Method\n this.templateType = templateAnonymous\n }\n\n override text(): string\n override text(valueToWrite: string): void\n override text(valueToWrite?: string): string | void {\n if (arguments.length == 0) {\n const templateData = getTemplateDomData(this.domElement)\n if (templateData.textData === undefined && templateData.containerData) {\n templateData.textData = templateData.containerData.innerHTML\n }\n return templateData.textData\n } else {\n setTemplateDomData(this.domElement, { textData: valueToWrite })\n }\n }\n}\n"],
"mappings": ";;AAwBA,SAAS,gBAAgB,gBAAgB,SAAS,SAAS,iCAAiC;AAK5F,MAAM,iBAAiB,GACrB,mBAAmB,GACnB,mBAAmB,GACnB,kBAAkB,GAClB,oBAAoB;AAgBtB,MAAM,oBAAoB,QAAQ,QAAQ,IAAI;AAC9C,MAAM,sBAAsB,QAAQ,QAAQ;AAC5C,SAAS,mBAAmB,SAAS;AACnC,SAAO,QAAQ,IAAI,SAAS,mBAAmB,KAAK,CAAC;AACvD;AACA,SAAS,mBAAmB,SAAS,MAAM;AACzC,UAAQ,IAAI,SAAS,qBAAqB,IAAI;AAChD;AAEO,aAAM,WAAqC;AAAA,EAIhD,YAAY,SAA4B;AACtC,SAAK,aAAa;AAElB,QAAI,QAAQ,aAAa,KAAK,cAAc;AAC1C,WAAK,eAAe;AAAA,IACtB,OAAO;AAC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AAa,CAAC;AAAA,IAC7D;AACA,WAAO;AAAA,EACT;AACF;AAMO,aAAM,0BAA0B,WAAW;AAAA,EAChD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAGb,SAAK,eAAe;AAAA,EACtB;AAAA,EAIS,KAAK,cAAsC;AAClD,QAAI,UAAU,UAAU,GAAG;AACzB,YAAM,eAAe,mBAAmB,KAAK,UAAU;AACvD,UAAI,aAAa,aAAa,UAAa,aAAa,eAAe;AACrE,qBAAa,WAAW,aAAa,cAAc;AAAA,MACrD;AACA,aAAO,aAAa;AAAA,IACtB,OAAO;AACL,yBAAmB,KAAK,YAAY,EAAE,UAAU,aAAa,CAAC;AAAA,IAChE;AAAA,EACF;AACF;",
"names": []
}

@@ -1,2 +0,3 @@

// @tko/binding.template 🥊 4.0.0-beta1.3 ESM
// @tko/binding.template 🥊 4.0.0 ESM
"use strict";
import {

@@ -20,19 +21,7 @@ virtualElements,

} from "@tko/bind";
import {
computed
} from "@tko/computed";
import {
isObservable,
dependencyDetection,
unwrap,
observable,
isObservableArray
} from "@tko/observable";
import {
templateEngine
} from "./templateEngine";
import {
anonymousTemplate as AnonymousTemplate
} from "./templateSources";
var _templateEngine;
import { computed } from "@tko/computed";
import { isObservable, dependencyDetection, unwrap, observable, isObservableArray } from "@tko/observable";
import { templateEngine } from "./templateEngine";
import { anonymousTemplate as AnonymousTemplate } from "./templateSources";
let _templateEngine;
const cleanContainerDomDataKey = domData.nextKey();

@@ -48,3 +37,3 @@ export function setTemplateEngine(tEngine) {

let nextInQueue = firstNode;
let firstOutOfRangeNode = virtualElements.nextSibling(lastNode);
const firstOutOfRangeNode = virtualElements.nextSibling(lastNode);
while (nextInQueue && (node = nextInQueue) !== firstOutOfRangeNode) {

@@ -57,11 +46,11 @@ nextInQueue = virtualElements.nextSibling(node);

if (continuousNodeArray.length) {
var firstNode = continuousNodeArray[0];
var lastNode = continuousNodeArray[continuousNodeArray.length - 1];
var parentNode = firstNode.parentNode;
var provider = koOptions.bindingProviderInstance;
var preprocessNode = provider.preprocessNode;
let firstNode = continuousNodeArray[0];
let lastNode = continuousNodeArray[continuousNodeArray.length - 1];
const parentNode = firstNode.parentNode;
const provider = koOptions.bindingProviderInstance;
const preprocessNode = provider.preprocessNode;
if (preprocessNode) {
invokeForEachNodeInContinuousRange(firstNode, lastNode, function(node, nextNodeInRange) {
var nodePreviousSibling = node.previousSibling;
var newNodes = preprocessNode.call(provider, node);
const nodePreviousSibling = node.previousSibling;
const newNodes = preprocessNode.call(provider, node);
if (newNodes) {

@@ -88,3 +77,3 @@ if (node === firstNode) {

invokeForEachNodeInContinuousRange(firstNode, lastNode, function(node) {
if (node.nodeType === 1 || node.nodeType === 8) {
if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.COMMENT_NODE) {
applyBindings(bindingContext, node).then(afterBindingCallback);

@@ -94,3 +83,3 @@ }

invokeForEachNodeInContinuousRange(firstNode, lastNode, function(node) {
if (node.nodeType === 1 || node.nodeType === 8) {
if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.COMMENT_NODE) {
memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext]);

@@ -107,10 +96,10 @@ }

options = options || {};
var firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
var templateDocument = (firstTargetNode || template || {}).ownerDocument;
var templateEngineToUse = options.templateEngine || _templateEngine;
var renderedNodesArray = templateEngineToUse.renderTemplate(template, bindingContext, options, templateDocument);
const firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
const templateDocument = (firstTargetNode || template || {}).ownerDocument;
const templateEngineToUse = options.templateEngine || _templateEngine;
const renderedNodesArray = templateEngineToUse.renderTemplate(template, bindingContext, options, templateDocument);
if (typeof renderedNodesArray.length !== "number" || renderedNodesArray.length > 0 && typeof renderedNodesArray[0].nodeType !== "number") {
throw new Error("Template engine must return an array of DOM nodes");
}
var haveAddedNodesToParent = false;
let haveAddedNodesToParent = false;
switch (renderMode) {

@@ -157,16 +146,30 @@ case "replaceChildren":

if (targetNodeOrNodeArray) {
var firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
var whenToDispose = function() {
let firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
const whenToDispose = function() {
return !firstTargetNode || !domNodeIsAttachedToDocument(firstTargetNode);
};
var activelyDisposeWhenNodeIsRemoved = firstTargetNode && renderMode === "replaceNode" ? firstTargetNode.parentNode : firstTargetNode;
return computed(function() {
var bindingContext = dataOrBindingContext && dataOrBindingContext instanceof BindingContextConstructor ? dataOrBindingContext : new BindingContextConstructor(dataOrBindingContext, null, null, null, { "exportDependencies": true });
var templateName = resolveTemplateName(template, bindingContext.$data, bindingContext);
const renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options, afterBindingCallback);
if (renderMode === "replaceNode") {
targetNodeOrNodeArray = renderedNodesArray;
firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
}
}, null, { disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved });
const activelyDisposeWhenNodeIsRemoved = firstTargetNode && renderMode === "replaceNode" ? firstTargetNode.parentNode : firstTargetNode;
return computed(
// So the DOM is automatically updated when any dependency changes
function() {
const bindingContext = dataOrBindingContext && dataOrBindingContext instanceof BindingContextConstructor ? dataOrBindingContext : new BindingContextConstructor(dataOrBindingContext, void 0, void 0, void 0, {
exportDependencies: true
});
const templateName = resolveTemplateName(template, bindingContext.$data, bindingContext);
const renderedNodesArray = executeTemplate(
targetNodeOrNodeArray,
renderMode,
templateName,
bindingContext,
options,
afterBindingCallback
);
if (renderMode === "replaceNode") {
targetNodeOrNodeArray = renderedNodesArray;
firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray);
}
},
null,
{ disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved }
);
} else {

@@ -179,3 +182,3 @@ return memoization.memoize(function(domNode) {

export default function renderTemplateForEach(template, arrayOrObservableArray, options, targetNode, parentBindingContext, afterBindingCallback) {
var arrayItemContext;
let arrayItemContext;
function executeTemplateForArrayItem(arrayValue, index) {

@@ -188,6 +191,3 @@ if (options.as) {

} else {
arrayItemContext = parentBindingContext.extend({
[options.as]: arrayValue,
$index: index
});
arrayItemContext = parentBindingContext.extend({ [options.as]: arrayValue, $index: index });
}

@@ -199,6 +199,13 @@ } else {

}
var templateName = resolveTemplateName(template, arrayValue, arrayItemContext);
return executeTemplate(targetNode, "ignoreTargetNode", templateName, arrayItemContext, options, afterBindingCallback);
const templateName = resolveTemplateName(template, arrayValue, arrayItemContext);
return executeTemplate(
targetNode,
"ignoreTargetNode",
templateName,
arrayItemContext,
options,
afterBindingCallback
);
}
var activateBindingsCallback = function(arrayValue, addedNodesArray) {
const activateBindingsCallback = function(arrayValue, addedNodesArray) {
activateBindingsOnContinuousNodeArray(addedNodesArray, arrayItemContext, afterBindingCallback);

@@ -211,3 +218,10 @@ if (options.afterRender) {

function localSetDomNodeChildrenFromArrayMapping(newArray, changeList) {
dependencyDetection.ignore(setDomNodeChildrenFromArrayMapping, null, [targetNode, newArray, executeTemplateForArrayItem, options, activateBindingsCallback, changeList]);
dependencyDetection.ignore(setDomNodeChildrenFromArrayMapping, null, [
targetNode,
newArray,
executeTemplateForArrayItem,
options,
activateBindingsCallback,
changeList
]);
bindingEvent.notify(targetNode, bindingEvent.childrenComplete);

@@ -218,24 +232,32 @@ }

localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray.peek());
var subscription = arrayOrObservableArray.subscribe(function(changeList) {
localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray(), changeList);
}, null, "arrayChange");
const subscription = arrayOrObservableArray.subscribe(
function(changeList) {
localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray(), changeList);
},
null,
"arrayChange"
);
subscription.disposeWhenNodeIsRemoved(targetNode);
return subscription;
} else {
return computed(function() {
var unwrappedArray = unwrap(arrayOrObservableArray) || [];
const unwrappedIsIterable = Symbol.iterator in unwrappedArray;
if (!unwrappedIsIterable) {
unwrappedArray = [unwrappedArray];
}
if (shouldHideDestroyed) {
unwrappedArray = arrayFilter(unwrappedArray, function(item) {
return item === void 0 || item === null || !unwrap(item._destroy);
});
}
localSetDomNodeChildrenFromArrayMapping(unwrappedArray);
}, null, { disposeWhenNodeIsRemoved: targetNode });
return computed(
function() {
let unwrappedArray = unwrap(arrayOrObservableArray) || [];
const unwrappedIsIterable = Symbol.iterator in unwrappedArray;
if (!unwrappedIsIterable) {
unwrappedArray = [unwrappedArray];
}
if (shouldHideDestroyed) {
unwrappedArray = arrayFilter(unwrappedArray, function(item) {
return item === void 0 || item === null || !unwrap(item._destroy);
});
}
localSetDomNodeChildrenFromArrayMapping(unwrappedArray);
},
null,
{ disposeWhenNodeIsRemoved: targetNode }
);
}
}
let templateComputedDomDataKey = domData.nextKey();
const templateComputedDomDataKey = domData.nextKey();
export class TemplateBindingHandler extends AsyncBindingHandler {

@@ -246,5 +268,3 @@ constructor(params) {

const bindingValue = unwrap(this.value);
domData.set(element, "conditional", {
elseChainSatisfied: observable(true)
});
domData.set(element, "conditional", { elseChainSatisfied: observable(true) });
if (typeof bindingValue === "string" || bindingValue.name) {

@@ -261,2 +281,6 @@ this.bindNamedTemplate();

}
// We've been given an array of DOM nodes. Save them as the template source.
// There is no known use case for the node array being an observable array (if the output
// varies, put that behavior *into* your template - that's what templates are for), and
// the implementation would be a mess, so assert that it's not observable.
bindNodeTemplate(nodes) {

@@ -284,8 +308,8 @@ if (isObservable(nodes)) {

const bindingContext = this.$context;
var value = this.value;
var options = unwrap(value);
var shouldDisplay = true;
var templateComputed = null;
var elseChainSatisfied = domData.get(element, "conditional").elseChainSatisfied;
var templateName;
const value = this.value;
let options = unwrap(value);
let shouldDisplay = true;
let templateComputed = null;
const elseChainSatisfied = domData.get(element, "conditional").elseChainSatisfied;
let templateName;
if (typeof options === "string") {

@@ -304,8 +328,22 @@ templateName = value;

if ("foreach" in options) {
var dataArray = shouldDisplay && options.foreach || [];
templateComputed = renderTemplateForEach(templateName || element, dataArray, options, element, bindingContext, this.completeBinding);
const dataArray = shouldDisplay && options.foreach || [];
templateComputed = renderTemplateForEach(
templateName || element,
dataArray,
options,
element,
bindingContext,
this.completeBinding
);
elseChainSatisfied((unwrap(dataArray) || []).length !== 0);
} else if (shouldDisplay) {
var innerBindingContext = "data" in options ? bindingContext.createStaticChildContext(options.data, options.as) : bindingContext;
templateComputed = renderTemplate(templateName || element, innerBindingContext, options, element, void 0, this.completeBinding);
const innerBindingContext = "data" in options ? bindingContext.createStaticChildContext(options.data, options.as) : bindingContext;
templateComputed = renderTemplate(
templateName || element,
innerBindingContext,
options,
element,
void 0,
this.completeBinding
);
elseChainSatisfied(true);

@@ -319,7 +357,11 @@ } else {

disposeOldComputedAndStoreNewOne(element, newComputed) {
let oldComputed = domData.get(element, templateComputedDomDataKey);
const oldComputed = domData.get(element, templateComputedDomDataKey);
if (oldComputed && typeof oldComputed.dispose === "function") {
oldComputed.dispose();
}
domData.set(element, templateComputedDomDataKey, newComputed && (!newComputed.isActive || newComputed.isActive()) ? newComputed : void 0);
domData.set(
element,
templateComputedDomDataKey,
newComputed && (!newComputed.isActive || newComputed.isActive()) ? newComputed : void 0
);
}

@@ -326,0 +368,0 @@ get controlsDescendants() {

{
"version": 3,
"sources": ["../src/templating.ts"],
"sourcesContent": ["import {\n virtualElements, fixUpContinuousNodeArray, replaceDomNodes, memoization,\n domNodeIsAttachedToDocument, moveCleanedNodesToContainerElement,\n arrayFilter, domData, options as koOptions\n} from '@tko/utils'\n\nimport {\n applyBindings, setDomNodeChildrenFromArrayMapping, AsyncBindingHandler,\n bindingEvent, bindingContext as BindingContextConstructor\n} from '@tko/bind'\n\nimport {\n computed\n} from '@tko/computed'\n\nimport {\n isObservable, dependencyDetection, unwrap, observable, isObservableArray\n} from '@tko/observable'\n\nimport {\n templateEngine\n} from './templateEngine'\n\nimport {\n anonymousTemplate as AnonymousTemplate\n} from './templateSources'\n\nvar _templateEngine\nconst cleanContainerDomDataKey = domData.nextKey()\n\nexport function setTemplateEngine (tEngine) {\n if ((tEngine !== undefined) && !(tEngine instanceof templateEngine)) {\n // TODO: ko.templateEngine to appropriate name\n throw new Error('templateEngine must inherit from ko.templateEngine')\n }\n _templateEngine = tEngine\n}\n\nfunction invokeForEachNodeInContinuousRange (firstNode, lastNode, action) {\n let node\n let nextInQueue = firstNode\n let firstOutOfRangeNode = virtualElements.nextSibling(lastNode)\n while (nextInQueue && ((node = nextInQueue) !== firstOutOfRangeNode)) {\n nextInQueue = virtualElements.nextSibling(node)\n action(node, nextInQueue)\n }\n}\n\nfunction activateBindingsOnContinuousNodeArray (continuousNodeArray, bindingContext, afterBindingCallback) {\n // To be used on any nodes that have been rendered by a template and have been inserted into some parent element\n // Walks through continuousNodeArray (which *must* be continuous, i.e., an uninterrupted sequence of sibling nodes, because\n // the algorithm for walking them relies on this), and for each top-level item in the virtual-element sense,\n // (1) Does a regular \"applyBindings\" to associate bindingContext with this node and to activate any non-memoized bindings\n // (2) Unmemoizes any memos in the DOM subtree (e.g., to activate bindings that had been memoized during template rewriting)\n\n if (continuousNodeArray.length) {\n var firstNode = continuousNodeArray[0]\n var lastNode = continuousNodeArray[continuousNodeArray.length - 1]\n var parentNode = firstNode.parentNode\n var provider = koOptions.bindingProviderInstance\n var preprocessNode = provider.preprocessNode\n\n if (preprocessNode) {\n invokeForEachNodeInContinuousRange(firstNode, lastNode, function (node, nextNodeInRange) {\n var nodePreviousSibling = node.previousSibling\n var newNodes = preprocessNode.call(provider, node)\n if (newNodes) {\n if (node === firstNode) { firstNode = newNodes[0] || nextNodeInRange }\n if (node === lastNode) { lastNode = newNodes[newNodes.length - 1] || nodePreviousSibling }\n }\n })\n\n // Because preprocessNode can change the nodes, including the first and last nodes, update continuousNodeArray to match.\n // We need the full set, including inner nodes, because the unmemoize step might remove the first node (and so the real\n // first node needs to be in the array).\n continuousNodeArray.length = 0\n if (!firstNode) { // preprocessNode might have removed all the nodes, in which case there's nothing left to do\n return\n }\n if (firstNode === lastNode) {\n continuousNodeArray.push(firstNode)\n } else {\n continuousNodeArray.push(firstNode, lastNode)\n fixUpContinuousNodeArray(continuousNodeArray, parentNode)\n }\n }\n\n // Need to applyBindings *before* unmemoziation, because unmemoization might introduce extra nodes (that we don't want to re-bind)\n // whereas a regular applyBindings won't introduce new memoized nodes\n invokeForEachNodeInContinuousRange(firstNode, lastNode, function (node) {\n if (node.nodeType === 1 || node.nodeType === 8) { applyBindings(bindingContext, node).then(afterBindingCallback) }\n })\n invokeForEachNodeInContinuousRange(firstNode, lastNode, function (node) {\n if (node.nodeType === 1 || node.nodeType === 8) { memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext]) }\n })\n\n // Make sure any changes done by applyBindings or unmemoize are reflected in the array\n fixUpContinuousNodeArray(continuousNodeArray, parentNode)\n }\n}\n\nfunction getFirstNodeFromPossibleArray (nodeOrNodeArray) {\n return nodeOrNodeArray.nodeType ? nodeOrNodeArray\n : nodeOrNodeArray.length > 0 ? nodeOrNodeArray[0]\n : null\n}\n\nfunction executeTemplate (targetNodeOrNodeArray, renderMode, template, bindingContext, options, afterBindingCallback) {\n options = options || {}\n var firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray)\n var templateDocument = (firstTargetNode || template || {}).ownerDocument\n var templateEngineToUse = (options.templateEngine || _templateEngine)\n var renderedNodesArray = templateEngineToUse.renderTemplate(template, bindingContext, options, templateDocument)\n\n // Loosely check result is an array of DOM nodes\n if ((typeof renderedNodesArray.length !== 'number') || (renderedNodesArray.length > 0 && typeof renderedNodesArray[0].nodeType !== 'number')) { throw new Error('Template engine must return an array of DOM nodes') }\n\n var haveAddedNodesToParent = false\n switch (renderMode) {\n case 'replaceChildren':\n virtualElements.setDomNodeChildren(targetNodeOrNodeArray, renderedNodesArray)\n haveAddedNodesToParent = true\n break\n case 'replaceNode':\n replaceDomNodes(targetNodeOrNodeArray, renderedNodesArray)\n haveAddedNodesToParent = true\n break\n case 'ignoreTargetNode': break\n default:\n throw new Error('Unknown renderMode: ' + renderMode)\n }\n\n if (haveAddedNodesToParent) {\n activateBindingsOnContinuousNodeArray(renderedNodesArray, bindingContext, afterBindingCallback)\n if (options.afterRender) { dependencyDetection.ignore(options.afterRender, null, [renderedNodesArray, bindingContext['$data']]) }\n if (renderMode === 'replaceChildren') {\n bindingEvent.notify(targetNodeOrNodeArray, bindingEvent.childrenComplete)\n }\n }\n\n return renderedNodesArray\n}\n\nfunction resolveTemplateName (template, data, context) {\n // The template can be specified as:\n if (isObservable(template)) {\n // 1. An observable, with string value\n return template()\n } else if (typeof template === 'function') {\n // 2. A function of (data, context) returning a string\n return template(data, context)\n } else {\n // 3. A string\n return template\n }\n}\n\nexport function renderTemplate (template, dataOrBindingContext, options, targetNodeOrNodeArray, renderMode, afterBindingCallback) {\n options = options || {}\n if ((options.templateEngine || _templateEngine) === undefined) { throw new Error('Set a template engine before calling renderTemplate') }\n renderMode = renderMode || 'replaceChildren'\n\n if (targetNodeOrNodeArray) {\n var firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray)\n\n var whenToDispose = function () { return (!firstTargetNode) || !domNodeIsAttachedToDocument(firstTargetNode) } // Passive disposal (on next evaluation)\n var activelyDisposeWhenNodeIsRemoved = (firstTargetNode && renderMode === 'replaceNode') ? firstTargetNode.parentNode : firstTargetNode\n\n return computed( // So the DOM is automatically updated when any dependency changes\n function () {\n // Ensure we've got a proper binding context to work with\n var bindingContext = (dataOrBindingContext && (dataOrBindingContext instanceof BindingContextConstructor))\n ? dataOrBindingContext\n : new BindingContextConstructor(dataOrBindingContext, null, null, null, { 'exportDependencies': true })\n\n var templateName = resolveTemplateName(template, bindingContext.$data, bindingContext)\n const renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options, afterBindingCallback)\n\n if (renderMode === 'replaceNode') {\n targetNodeOrNodeArray = renderedNodesArray\n firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray)\n }\n },\n null,\n { disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved }\n )\n } else {\n // We don't yet have a DOM node to evaluate, so use a memo and render the template later when there is a DOM node\n return memoization.memoize(function (domNode) {\n renderTemplate(template, dataOrBindingContext, options, domNode, 'replaceNode')\n })\n }\n}\n\nexport default function renderTemplateForEach (template, arrayOrObservableArray, options, targetNode, parentBindingContext, afterBindingCallback) {\n // Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then\n // activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.\n var arrayItemContext\n\n // This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode\n function executeTemplateForArrayItem (arrayValue, index) {\n // Support selecting template as a function of the data being rendered\n if (options.as) {\n if (koOptions.createChildContextWithAs) {\n arrayItemContext = parentBindingContext.createChildContext(\n arrayValue, options.as, context => { context.$index = index }\n )\n } else {\n arrayItemContext = parentBindingContext.extend({\n [options.as]: arrayValue,\n $index: index\n })\n }\n } else {\n arrayItemContext = parentBindingContext.createChildContext(arrayValue, options.as, context => { context.$index = index })\n }\n\n var templateName = resolveTemplateName(template, arrayValue, arrayItemContext)\n return executeTemplate(targetNode, 'ignoreTargetNode', templateName, arrayItemContext, options, afterBindingCallback)\n }\n\n // This will be called whenever setDomNodeChildrenFromArrayMapping has added nodes to targetNode\n var activateBindingsCallback = function (arrayValue, addedNodesArray /*, index */) {\n activateBindingsOnContinuousNodeArray(addedNodesArray, arrayItemContext, afterBindingCallback)\n if (options.afterRender) { options.afterRender(addedNodesArray, arrayValue) }\n\n // release the \"cache\" variable, so that it can be collected by\n // the GC when its value isn't used from within the bindings anymore.\n arrayItemContext = null\n }\n\n // Call setDomNodeChildrenFromArrayMapping, ignoring any observables unwrapped within (most likely from a callback function).\n // If the array items are observables, though, they will be unwrapped in executeTemplateForArrayItem and managed within setDomNodeChildrenFromArrayMapping.\n function localSetDomNodeChildrenFromArrayMapping (newArray, changeList) {\n dependencyDetection.ignore(setDomNodeChildrenFromArrayMapping, null, [targetNode, newArray, executeTemplateForArrayItem, options, activateBindingsCallback, changeList])\n bindingEvent.notify(targetNode, bindingEvent.childrenComplete)\n }\n\n const shouldHideDestroyed = (options.includeDestroyed === false) || (koOptions.foreachHidesDestroyed && !options.includeDestroyed);\n if (!shouldHideDestroyed && !options.beforeRemove && isObservableArray(arrayOrObservableArray)) {\n localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray.peek())\n var subscription = arrayOrObservableArray.subscribe(function (changeList) {\n localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray(), changeList)\n }, null, 'arrayChange')\n subscription.disposeWhenNodeIsRemoved(targetNode)\n return subscription\n } else {\n return computed(function () {\n var unwrappedArray = unwrap(arrayOrObservableArray) || []\n const unwrappedIsIterable = Symbol.iterator in unwrappedArray\n if (!unwrappedIsIterable) { unwrappedArray = [unwrappedArray] }\n if (shouldHideDestroyed) {\n // Filter out any entries marked as destroyed\n unwrappedArray = arrayFilter(unwrappedArray, function (item) {\n return item === undefined || item === null || !unwrap(item._destroy);\n })\n }\n localSetDomNodeChildrenFromArrayMapping(unwrappedArray)\n }, null, { disposeWhenNodeIsRemoved: targetNode })\n }\n}\n\nlet templateComputedDomDataKey = domData.nextKey()\n\nexport class TemplateBindingHandler extends AsyncBindingHandler {\n constructor (params) {\n super(params)\n const element = this.$element\n const bindingValue = unwrap(this.value)\n\n // Expose 'conditional' for `else` chaining.\n domData.set(element, 'conditional', {\n elseChainSatisfied: observable(true)\n })\n\n // Support anonymous templates\n if (typeof bindingValue === 'string' || bindingValue.name) {\n this.bindNamedTemplate()\n } else if ('nodes' in bindingValue) {\n this.bindNodeTemplate(bindingValue.nodes || [])\n } else {\n this.bindAnonymousTemplate()\n }\n }\n\n bindNamedTemplate () {\n // It's a named template - clear the element\n virtualElements.emptyNode(this.$element)\n }\n\n // We've been given an array of DOM nodes. Save them as the template source.\n // There is no known use case for the node array being an observable array (if the output\n // varies, put that behavior *into* your template - that's what templates are for), and\n // the implementation would be a mess, so assert that it's not observable.\n bindNodeTemplate (nodes) {\n if (isObservable(nodes)) {\n throw new Error('The \"nodes\" option must be a plain, non-observable array.')\n }\n\n // If the nodes are already attached to a KO-generated container, we reuse that container without moving the\n // elements to a new one (we check only the first node, as the nodes are always moved together)\n let container = nodes[0] && nodes[0].parentNode\n if (!container || !domData.get(container, cleanContainerDomDataKey)) {\n container = moveCleanedNodesToContainerElement(nodes)\n domData.set(container, cleanContainerDomDataKey, true)\n }\n\n new AnonymousTemplate(this.$element).nodes(container)\n }\n\n bindAnonymousTemplate () {\n // It's an anonymous template - store the element contents, then clear the element\n const templateNodes = virtualElements.childNodes(this.$element)\n if (templateNodes.length === 0) {\n throw new Error('Anonymous template defined, but no template content was provided.')\n }\n const container = moveCleanedNodesToContainerElement(templateNodes) // This also removes the nodes from their current parent\n new AnonymousTemplate(this.$element).nodes(container)\n }\n\n onValueChange () {\n const element = this.$element\n const bindingContext = this.$context\n var value = this.value\n var options = unwrap(value)\n var shouldDisplay = true\n var templateComputed = null\n var elseChainSatisfied = domData.get(element, 'conditional').elseChainSatisfied\n var templateName\n\n if (typeof options === 'string') {\n templateName = value\n options = {}\n } else {\n templateName = options.name\n\n // Support \"if\"/\"ifnot\" conditions\n if ('if' in options) {\n shouldDisplay = unwrap(options.if)\n }\n\n if (shouldDisplay && 'ifnot' in options) {\n shouldDisplay = !unwrap(options.ifnot)\n }\n }\n\n if ('foreach' in options) {\n // Render once for each data point (treating data set as empty if shouldDisplay==false)\n var dataArray = (shouldDisplay && options.foreach) || []\n templateComputed = renderTemplateForEach(templateName || element, dataArray, options, element, bindingContext, this.completeBinding)\n\n elseChainSatisfied((unwrap(dataArray) || []).length !== 0)\n } else if (shouldDisplay) {\n // Render once for this single data point (or use the viewModel if no data was provided)\n var innerBindingContext = ('data' in options)\n ? bindingContext.createStaticChildContext(options.data, options.as) // Given an explicit 'data' value, we create a child binding context for it\n : bindingContext // Given no explicit 'data' value, we retain the same binding context\n templateComputed = renderTemplate(templateName || element, innerBindingContext, options, element, undefined, this.completeBinding)\n elseChainSatisfied(true)\n } else {\n virtualElements.emptyNode(element)\n elseChainSatisfied(false)\n }\n\n // It only makes sense to have a single template computed per element (otherwise which one should have its output displayed?)\n this.disposeOldComputedAndStoreNewOne(element, templateComputed)\n }\n\n disposeOldComputedAndStoreNewOne (element, newComputed) {\n let oldComputed = domData.get(element, templateComputedDomDataKey)\n if (oldComputed && (typeof oldComputed.dispose === 'function')) { oldComputed.dispose() }\n domData.set(element, templateComputedDomDataKey, (newComputed && (!newComputed.isActive || newComputed.isActive())) ? newComputed : undefined)\n }\n\n get controlsDescendants () { return true }\n static get allowVirtualElements () { return true }\n}\n"],
"mappings": ";AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA,IAAI;AACJ,MAAM,2BAA2B,QAAQ,QAAQ;AAE1C,kCAA4B,SAAS;AAC1C,MAAK,YAAY,UAAc,CAAE,oBAAmB,iBAAiB;AAEnE,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,oBAAkB;AACpB;AAEA,4CAA6C,WAAW,UAAU,QAAQ;AACxE,MAAI;AACJ,MAAI,cAAc;AAClB,MAAI,sBAAsB,gBAAgB,YAAY,QAAQ;AAC9D,SAAO,eAAiB,QAAO,iBAAiB,qBAAsB;AACpE,kBAAc,gBAAgB,YAAY,IAAI;AAC9C,WAAO,MAAM,WAAW;AAAA,EAC1B;AACF;AAEA,+CAAgD,qBAAqB,gBAAgB,sBAAsB;AAOzG,MAAI,oBAAoB,QAAQ;AAC9B,QAAI,YAAY,oBAAoB;AACp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AK;AACnD;",
"sourcesContent": ["import {\n virtualElements,\n fixUpContinuousNodeArray,\n replaceDomNodes,\n memoization,\n domNodeIsAttachedToDocument,\n moveCleanedNodesToContainerElement,\n arrayFilter,\n domData,\n options as koOptions\n} from '@tko/utils'\n\nimport {\n applyBindings,\n setDomNodeChildrenFromArrayMapping,\n AsyncBindingHandler,\n bindingEvent,\n bindingContext as BindingContextConstructor\n} from '@tko/bind'\n\nimport { computed } from '@tko/computed'\n\nimport type { Computed } from '@tko/computed'\n\nimport type { BindingContext } from '@tko/bind'\n\nimport { isObservable, dependencyDetection, unwrap, observable, isObservableArray } from '@tko/observable'\n\nimport { templateEngine } from './templateEngine'\n\nimport type { TemplateEngine, TemplateOptions } from './templateEngine'\n\nimport { anonymousTemplate as AnonymousTemplate } from './templateSources'\n\nlet _templateEngine: TemplateEngine\nconst cleanContainerDomDataKey = domData.nextKey()\n\nexport function setTemplateEngine(tEngine: TemplateEngine | undefined): void {\n if (tEngine !== undefined && !(tEngine instanceof templateEngine)) {\n // TODO: ko.templateEngine to appropriate name\n throw new Error('templateEngine must inherit from ko.templateEngine')\n }\n _templateEngine = tEngine!\n}\n\nfunction invokeForEachNodeInContinuousRange(firstNode, lastNode, action) {\n let node\n let nextInQueue = firstNode\n const firstOutOfRangeNode = virtualElements.nextSibling(lastNode)\n while (nextInQueue && (node = nextInQueue) !== firstOutOfRangeNode) {\n nextInQueue = virtualElements.nextSibling(node)\n action(node, nextInQueue)\n }\n}\n\nfunction activateBindingsOnContinuousNodeArray(\n continuousNodeArray,\n bindingContext: BindingContext,\n afterBindingCallback\n) {\n // To be used on any nodes that have been rendered by a template and have been inserted into some parent element\n // Walks through continuousNodeArray (which *must* be continuous, i.e., an uninterrupted sequence of sibling nodes, because\n // the algorithm for walking them relies on this), and for each top-level item in the virtual-element sense,\n // (1) Does a regular \"applyBindings\" to associate bindingContext with this node and to activate any non-memoized bindings\n // (2) Unmemoizes any memos in the DOM subtree (e.g., to activate bindings that had been memoized during template rewriting)\n\n if (continuousNodeArray.length) {\n let firstNode = continuousNodeArray[0]\n let lastNode = continuousNodeArray[continuousNodeArray.length - 1]\n const parentNode = firstNode.parentNode\n const provider = koOptions.bindingProviderInstance\n const preprocessNode = provider.preprocessNode\n\n if (preprocessNode) {\n invokeForEachNodeInContinuousRange(firstNode, lastNode, function (node, nextNodeInRange) {\n const nodePreviousSibling = node.previousSibling\n const newNodes = preprocessNode.call(provider, node)\n if (newNodes) {\n if (node === firstNode) {\n firstNode = newNodes[0] || nextNodeInRange\n }\n if (node === lastNode) {\n lastNode = newNodes[newNodes.length - 1] || nodePreviousSibling\n }\n }\n })\n\n // Because preprocessNode can change the nodes, including the first and last nodes, update continuousNodeArray to match.\n // We need the full set, including inner nodes, because the unmemoize step might remove the first node (and so the real\n // first node needs to be in the array).\n continuousNodeArray.length = 0\n if (!firstNode) {\n // preprocessNode might have removed all the nodes, in which case there's nothing left to do\n return\n }\n if (firstNode === lastNode) {\n continuousNodeArray.push(firstNode)\n } else {\n continuousNodeArray.push(firstNode, lastNode)\n fixUpContinuousNodeArray(continuousNodeArray, parentNode)\n }\n }\n\n // Need to applyBindings *before* unmemoziation, because unmemoization might introduce extra nodes (that we don't want to re-bind)\n // whereas a regular applyBindings won't introduce new memoized nodes\n invokeForEachNodeInContinuousRange(firstNode, lastNode, function (node) {\n if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.COMMENT_NODE) {\n applyBindings(bindingContext, node).then(afterBindingCallback)\n }\n })\n invokeForEachNodeInContinuousRange(firstNode, lastNode, function (node) {\n if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.COMMENT_NODE) {\n memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext])\n }\n })\n\n // Make sure any changes done by applyBindings or unmemoize are reflected in the array\n fixUpContinuousNodeArray(continuousNodeArray, parentNode)\n }\n}\n\nfunction getFirstNodeFromPossibleArray(nodeOrNodeArray) {\n return nodeOrNodeArray.nodeType ? nodeOrNodeArray : nodeOrNodeArray.length > 0 ? nodeOrNodeArray[0] : null\n}\n\nfunction executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options, afterBindingCallback) {\n options = options || {}\n const firstTargetNode = targetNodeOrNodeArray && getFirstNodeFromPossibleArray(targetNodeOrNodeArray)\n const templateDocument = (firstTargetNode || template || {}).ownerDocument\n const templateEngineToUse = options.templateEngine || _templateEngine\n const renderedNodesArray = templateEngineToUse.renderTemplate(template, bindingContext, options, templateDocument)\n\n // Loosely check result is an array of DOM nodes\n if (\n typeof renderedNodesArray.length !== 'number'\n || (renderedNodesArray.length > 0 && typeof renderedNodesArray[0].nodeType !== 'number')\n ) {\n throw new Error('Template engine must return an array of DOM nodes')\n }\n\n let haveAddedNodesToParent = false\n switch (renderMode) {\n case 'replaceChildren':\n virtualElements.setDomNodeChildren(targetNodeOrNodeArray, renderedNodesArray)\n haveAddedNodesToParent = true\n break\n case 'replaceNode':\n replaceDomNodes(targetNodeOrNodeArray, renderedNodesArray)\n haveAddedNodesToParent = true\n break\n case 'ignoreTargetNode':\n break\n default:\n throw new Error('Unknown renderMode: ' + renderMode)\n }\n\n if (haveAddedNodesToParent) {\n activateBindingsOnContinuousNodeArray(renderedNodesArray, bindingContext, afterBindingCallback)\n if (options.afterRender) {\n dependencyDetection.ignore(options.afterRender, null, [renderedNodesArray, bindingContext['$data']])\n }\n if (renderMode === 'replaceChildren') {\n bindingEvent.notify(targetNodeOrNodeArray, bindingEvent.childrenComplete)\n }\n }\n\n return renderedNodesArray\n}\n\nfunction resolveTemplateName(template, data, context) {\n // The template can be specified as:\n if (isObservable(template)) {\n // 1. An observable, with string value\n return template()\n } else if (typeof template === 'function') {\n // 2. A function of (data, context) returning a string\n return template(data, context)\n } else {\n // 3. A string\n return template\n }\n}\n\nexport type RenderModeEnum = 'replaceChildren' | 'replaceNode' | 'ignoreTargetNode'\n\nexport function renderTemplate<T = any>(\n template: string | Node | (() => string | Node),\n dataOrBindingContext: T | BindingContext<T> | null | undefined,\n options: TemplateOptions<T> | null | undefined,\n targetNodeOrNodeArray: Node | Node[],\n renderMode?: RenderModeEnum,\n afterBindingCallback?\n): Computed<void> | string {\n options = options || {}\n if ((options.templateEngine || _templateEngine) === undefined) {\n throw new Error('Set a template engine before calling renderTemplate')\n }\n renderMode = renderMode || 'replaceChildren'\n\n if (targetNodeOrNodeArray) {\n let firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray)\n\n const whenToDispose = function () {\n return !firstTargetNode || !domNodeIsAttachedToDocument(firstTargetNode)\n } // Passive disposal (on next evaluation)\n const activelyDisposeWhenNodeIsRemoved =\n firstTargetNode && renderMode === 'replaceNode' ? firstTargetNode.parentNode : firstTargetNode\n\n return computed(\n // So the DOM is automatically updated when any dependency changes\n function () {\n // Ensure we've got a proper binding context to work with\n const bindingContext =\n dataOrBindingContext && dataOrBindingContext instanceof BindingContextConstructor\n ? dataOrBindingContext\n : new BindingContextConstructor(dataOrBindingContext, undefined, undefined, undefined, {\n exportDependencies: true\n })\n\n const templateName = resolveTemplateName(template, bindingContext.$data, bindingContext)\n const renderedNodesArray = executeTemplate(\n targetNodeOrNodeArray,\n renderMode,\n templateName,\n bindingContext,\n options,\n afterBindingCallback\n )\n\n if (renderMode === 'replaceNode') {\n targetNodeOrNodeArray = renderedNodesArray\n firstTargetNode = getFirstNodeFromPossibleArray(targetNodeOrNodeArray)\n }\n },\n null,\n { disposeWhen: whenToDispose, disposeWhenNodeIsRemoved: activelyDisposeWhenNodeIsRemoved }\n )\n } else {\n // We don't yet have a DOM node to evaluate, so use a memo and render the template later when there is a DOM node\n return memoization.memoize(function (domNode) {\n renderTemplate(template, dataOrBindingContext, options, domNode, 'replaceNode')\n })\n }\n}\n\nexport default function renderTemplateForEach(\n template,\n arrayOrObservableArray,\n options,\n targetNode,\n parentBindingContext,\n afterBindingCallback\n) {\n // Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then\n // activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.\n let arrayItemContext\n\n // This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode\n function executeTemplateForArrayItem(arrayValue, index) {\n // Support selecting template as a function of the data being rendered\n if (options.as) {\n if (koOptions.createChildContextWithAs) {\n arrayItemContext = parentBindingContext.createChildContext(arrayValue, options.as, context => {\n context.$index = index\n })\n } else {\n arrayItemContext = parentBindingContext.extend({ [options.as]: arrayValue, $index: index })\n }\n } else {\n arrayItemContext = parentBindingContext.createChildContext(arrayValue, options.as, context => {\n context.$index = index\n })\n }\n\n const templateName = resolveTemplateName(template, arrayValue, arrayItemContext)\n return executeTemplate(\n targetNode,\n 'ignoreTargetNode',\n templateName,\n arrayItemContext,\n options,\n afterBindingCallback\n )\n }\n\n // This will be called whenever setDomNodeChildrenFromArrayMapping has added nodes to targetNode\n const activateBindingsCallback = function (arrayValue, addedNodesArray /*, index */) {\n activateBindingsOnContinuousNodeArray(addedNodesArray, arrayItemContext, afterBindingCallback)\n if (options.afterRender) {\n options.afterRender(addedNodesArray, arrayValue)\n }\n\n // release the \"cache\" variable, so that it can be collected by\n // the GC when its value isn't used from within the bindings anymore.\n arrayItemContext = null\n }\n\n // Call setDomNodeChildrenFromArrayMapping, ignoring any observables unwrapped within (most likely from a callback function).\n // If the array items are observables, though, they will be unwrapped in executeTemplateForArrayItem and managed within setDomNodeChildrenFromArrayMapping.\n function localSetDomNodeChildrenFromArrayMapping(newArray, changeList?) {\n dependencyDetection.ignore(setDomNodeChildrenFromArrayMapping, null, [\n targetNode,\n newArray,\n executeTemplateForArrayItem,\n options,\n activateBindingsCallback,\n changeList\n ])\n bindingEvent.notify(targetNode, bindingEvent.childrenComplete)\n }\n\n const shouldHideDestroyed =\n options.includeDestroyed === false || (koOptions.foreachHidesDestroyed && !options.includeDestroyed)\n if (!shouldHideDestroyed && !options.beforeRemove && isObservableArray(arrayOrObservableArray)) {\n localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray.peek())\n const subscription = arrayOrObservableArray.subscribe(\n function (changeList) {\n localSetDomNodeChildrenFromArrayMapping(arrayOrObservableArray(), changeList)\n },\n null,\n 'arrayChange'\n )\n subscription.disposeWhenNodeIsRemoved(targetNode)\n return subscription\n } else {\n return computed(\n function () {\n let unwrappedArray = unwrap(arrayOrObservableArray) || []\n const unwrappedIsIterable = Symbol.iterator in unwrappedArray\n if (!unwrappedIsIterable) {\n unwrappedArray = [unwrappedArray]\n }\n if (shouldHideDestroyed) {\n // Filter out any entries marked as destroyed\n unwrappedArray = arrayFilter(unwrappedArray, function (item) {\n return item === undefined || item === null || !unwrap(item._destroy)\n })\n }\n localSetDomNodeChildrenFromArrayMapping(unwrappedArray)\n },\n null,\n { disposeWhenNodeIsRemoved: targetNode }\n )\n }\n}\n\nconst templateComputedDomDataKey = domData.nextKey()\n\nexport class TemplateBindingHandler extends AsyncBindingHandler {\n constructor(params) {\n super(params)\n const element = this.$element\n const bindingValue = unwrap(this.value)\n\n // Expose 'conditional' for `else` chaining.\n domData.set(element, 'conditional', { elseChainSatisfied: observable(true) })\n\n // Support anonymous templates\n if (typeof bindingValue === 'string' || bindingValue.name) {\n this.bindNamedTemplate()\n } else if ('nodes' in bindingValue) {\n this.bindNodeTemplate(bindingValue.nodes || [])\n } else {\n this.bindAnonymousTemplate()\n }\n }\n\n bindNamedTemplate() {\n // It's a named template - clear the element\n virtualElements.emptyNode(this.$element)\n }\n\n // We've been given an array of DOM nodes. Save them as the template source.\n // There is no known use case for the node array being an observable array (if the output\n // varies, put that behavior *into* your template - that's what templates are for), and\n // the implementation would be a mess, so assert that it's not observable.\n bindNodeTemplate(nodes) {\n if (isObservable(nodes)) {\n throw new Error('The \"nodes\" option must be a plain, non-observable array.')\n }\n\n // If the nodes are already attached to a KO-generated container, we reuse that container without moving the\n // elements to a new one (we check only the first node, as the nodes are always moved together)\n let container = nodes[0] && nodes[0].parentNode\n if (!container || !domData.get(container, cleanContainerDomDataKey)) {\n container = moveCleanedNodesToContainerElement(nodes)\n domData.set(container, cleanContainerDomDataKey, true)\n }\n\n new AnonymousTemplate(this.$element).nodes(container)\n }\n\n bindAnonymousTemplate() {\n // It's an anonymous template - store the element contents, then clear the element\n const templateNodes = virtualElements.childNodes(this.$element)\n if (templateNodes.length === 0) {\n throw new Error('Anonymous template defined, but no template content was provided.')\n }\n const container = moveCleanedNodesToContainerElement(templateNodes) // This also removes the nodes from their current parent\n new AnonymousTemplate(this.$element).nodes(container)\n }\n\n onValueChange() {\n const element = this.$element\n const bindingContext = this.$context\n const value = this.value\n let options = unwrap(value)\n let shouldDisplay = true\n let templateComputed: string | Computed<any> | null = null\n const elseChainSatisfied = domData.get(element, 'conditional').elseChainSatisfied\n let templateName\n\n if (typeof options === 'string') {\n templateName = value\n options = {}\n } else {\n templateName = options.name\n\n // Support \"if\"/\"ifnot\" conditions\n if ('if' in options) {\n shouldDisplay = unwrap(options.if)\n }\n\n if (shouldDisplay && 'ifnot' in options) {\n shouldDisplay = !unwrap(options.ifnot)\n }\n }\n\n if ('foreach' in options) {\n // Render once for each data point (treating data set as empty if shouldDisplay==false)\n const dataArray = (shouldDisplay && options.foreach) || []\n templateComputed = renderTemplateForEach(\n templateName || element,\n dataArray,\n options,\n element,\n bindingContext,\n this.completeBinding\n )\n\n elseChainSatisfied((unwrap(dataArray) || []).length !== 0)\n } else if (shouldDisplay) {\n // Render once for this single data point (or use the viewModel if no data was provided)\n const innerBindingContext =\n 'data' in options\n ? bindingContext.createStaticChildContext(options.data, options.as) // Given an explicit 'data' value, we create a child binding context for it\n : bindingContext // Given no explicit 'data' value, we retain the same binding context\n templateComputed = renderTemplate(\n templateName || element,\n innerBindingContext,\n options,\n element,\n undefined,\n this.completeBinding\n )\n elseChainSatisfied(true)\n } else {\n virtualElements.emptyNode(element)\n elseChainSatisfied(false)\n }\n\n // It only makes sense to have a single template computed per element (otherwise which one should have its output displayed?)\n this.disposeOldComputedAndStoreNewOne(element, templateComputed)\n }\n\n disposeOldComputedAndStoreNewOne(element, newComputed) {\n const oldComputed = domData.get(element, templateComputedDomDataKey)\n if (oldComputed && typeof oldComputed.dispose === 'function') {\n oldComputed.dispose()\n }\n domData.set(\n element,\n templateComputedDomDataKey,\n newComputed && (!newComputed.isActive || newComputed.isActive()) ? newComputed : undefined\n )\n }\n\n override get controlsDescendants() {\n return true\n }\n static override get allowVirtualElements() {\n return true\n }\n}\n"],
"mappings": ";;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,OACN;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AAAA,OACb;AAEP,SAAS,gBAAgB;AAMzB,SAAS,cAAc,qBAAqB,QAAQ,YAAY,yBAAyB;AAEzF,SAAS,sBAAsB;AAI/B,SAAS,qBAAqB,yBAAyB;AAEvD,IAAI;AACJ,MAAM,2BAA2B,QAAQ,QAAQ;AAE1C,gBAAS,kBAAkB,SAA2C;AAC3E,MAAI,YAAY,UAAa,EAAE,mBAAmB,iBAAiB;AAEjE,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,oBAAkB;AACpB;AAEA,SAAS,mCAAmC,WAAW,UAAU,QAAQ;AACvE,MAAI;AACJ,MAAI,cAAc;AAClB,QAAM,sBAAsB,gBAAgB,YAAY,QAAQ;AAChE,SAAO,gBAAgB,OAAO,iBAAiB,qBAAqB;AAClE,kBAAc,gBAAgB,YAAY,IAAI;AAC9C,WAAO,MAAM,WAAW;AAAA,EAC1B;AACF;AAEA,SAAS,sCACP,qBACA,gBACA,sBACA;AAOA,MAAI,oBAAoB,QAAQ;AAC9B,QAAI,YAAY,oBAAoB,CAAC;AACrC,QAAI,WAAW,oBAAoB,oBAAoB,SAAS,CAAC;AACjE,UAAM,aAAa,UAAU;AAC7B,UAAM,WAAW,UAAU;AAC3B,UAAM,iBAAiB,SAAS;AAEhC,QAAI,gBAAgB;AAClB,yCAAmC,WAAW,UAAU,SAAU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AA,MACA;AAAA,MACA,gBAAgB,CAAC,YAAY,YAAY,YAAY,SAAS,KAAK,cAAc;AAAA,IACnF;AAAA,EACF;AAAA,EAEA,IAAa,sBAAsB;AACjC,WAAO;AAAA,EACT;AAAA,EACA,WAAoB,uBAAuB;AACzC,WAAO;AAAA,EACT;AACF;",
"names": []
}

@@ -0,90 +1,83 @@

import { extend, arrayPushAll, parseHtmlFragment } from '@tko/utils'
import {
extend, arrayPushAll, parseHtmlFragment
} from '@tko/utils';
import { renderTemplate, anonymousTemplate, templateEngine } from '../dist'
import {
renderTemplate, anonymousTemplate, templateEngine
} from '../dist';
import type { BindingContext } from '@tko/bind'
export function dummyTemplateEngine(templates?) {
const inMemoryTemplates = templates || {}
const inMemoryTemplateData = {}
export function dummyTemplateEngine(templates) {
var inMemoryTemplates = templates || {};
var inMemoryTemplateData = {};
function dummyTemplateSource(id) {
this.id = id;
function dummyTemplateSource(id) {
this.id = id
}
dummyTemplateSource.prototype = {
text: function (val) {
if (arguments.length >= 1) inMemoryTemplates[this.id] = val
return inMemoryTemplates[this.id]
},
data: function (key, val) {
if (arguments.length >= 2) {
inMemoryTemplateData[this.id] = inMemoryTemplateData[this.id] || {}
inMemoryTemplateData[this.id][key] = val
}
return (inMemoryTemplateData[this.id] || {})[key]
}
dummyTemplateSource.prototype = {
text: function(val) {
if (arguments.length >= 1)
inMemoryTemplates[this.id] = val;
return inMemoryTemplates[this.id];
},
data: function(key, val) {
if (arguments.length >= 2) {
inMemoryTemplateData[this.id] = inMemoryTemplateData[this.id] || {};
inMemoryTemplateData[this.id][key] = val;
}
return (inMemoryTemplateData[this.id] || {})[key];
}
};
}
this.makeTemplateSource = function(template) {
if (typeof template == "string")
return new dummyTemplateSource(template); // Named template comes from the in-memory collection
else if ((template.nodeType == 1) || (template.nodeType == 8))
return new anonymousTemplate(template); // Anonymous template
};
this.makeTemplateSource = function (template) {
if (typeof template == 'string')
return new dummyTemplateSource(template) // Named template comes from the in-memory collection
else if (template.nodeType === Node.ELEMENT_NODE || template.nodeType === Node.COMMENT_NODE)
return new anonymousTemplate(template) // Anonymous template
}
this.renderTemplateSource = function (templateSource, bindingContext, rt_options, templateDocument) {
var data = bindingContext['$data'];
if (data && typeof data.get_value === 'function') {
// For cases when data is an Identifier/Expression.
data = data.get_value(data, bindingContext);
}
templateDocument = templateDocument || document;
rt_options = rt_options || {};
var templateText = templateSource.text();
if (typeof templateText == "function")
templateText = templateText(data, rt_options);
this.renderTemplateSource = function (templateSource, bindingContext: BindingContext, rt_options, templateDocument) {
let data = bindingContext['$data']
if (data && typeof data.get_value === 'function') {
// For cases when data is an Identifier/Expression.
data = data.get_value(data, bindingContext)
}
templateDocument = templateDocument || document
rt_options = rt_options || {}
let templateText = templateSource.text()
if (typeof templateText == 'function') templateText = templateText(data, rt_options)
templateText = rt_options.showParams ? templateText + ", data=" + data + ", options=" + rt_options : templateText;
// var templateOptions = options.templateOptions; // Have templateOptions in scope to support [js:templateOptions.foo] syntax
templateText = rt_options.showParams ? templateText + ', data=' + data + ', options=' + rt_options : templateText
// var templateOptions = options.templateOptions; // Have templateOptions in scope to support [js:templateOptions.foo] syntax
var result;
let result
data = data || {};
// Builders (e.g. rollup) mangle `data` to e.g. `data$$1`.
// This workaround works as long as nomangle$data doesn't
// appear anywhere not in tests.
const nomangle$data = data
window.__prevent_tree_shaking__ = nomangle$data
delete window.__prevent_tree_shaking__
data = data || {}
// Builders (e.g. rollup) mangle `data` to e.g. `data$$1`.
// This workaround works as long as nomangle$data doesn't
// appear anywhere not in tests.
const nomangle$data: any = data
;(window as any).__prevent_tree_shaking__ = nomangle$data
delete (window as any).__prevent_tree_shaking__
rt_options.templateRenderingVariablesInScope = rt_options.templateRenderingVariablesInScope || {};
rt_options.templateRenderingVariablesInScope = rt_options.templateRenderingVariablesInScope || {}
extend(data, rt_options.templateRenderingVariablesInScope);
extend(data, rt_options.templateRenderingVariablesInScope)
// Dummy [renderTemplate:...] syntax
result = templateText.replace(/\[renderTemplate\:(.*?)\]/g, function (match, templateName) {
return renderTemplate(templateName, data, rt_options);
});
// Dummy [renderTemplate:...] syntax
result = templateText.replace(/\[renderTemplate\:(.*?)\]/g, function (match, templateName) {
return renderTemplate(templateName, data, rt_options)
})
const evalHandler = function (match, script) {
try {
const evalResult = eval(script)
return evalResult === null || evalResult === undefined ? '' : evalResult.toString()
} catch (ex: any) {
throw new Error('Error evaluating script: [js: ' + script + ']\n\nException: ' + ex.toString())
}
}
var evalHandler = function (match, script) {
try {
var evalResult = eval(script);
return (evalResult === null) || (evalResult === undefined) ? "" : evalResult.toString();
} catch (ex) {
throw new Error("Error evaluating script: [js: " + script + "]\n\nException: " + ex.toString());
}
};
// Dummy [[js:...]] syntax (in case you need to use square brackets inside the expression)
result = result.replace(/\[\[js\:([\s\S]*?)\]\]/g, evalHandler)
// Dummy [[js:...]] syntax (in case you need to use square brackets inside the expression)
result = result.replace(/\[\[js\:([\s\S]*?)\]\]/g, evalHandler);
// Dummy [js:...] syntax
result = result.replace(/\[js\:([\s\S]*?)\]/g, evalHandler);
/*with (bindingContext) {
// Dummy [js:...] syntax
result = result.replace(/\[js\:([\s\S]*?)\]/g, evalHandler)
/*with (bindingContext) {
with (data || {}) {

@@ -97,17 +90,18 @@ with (options.templateRenderingVariablesInScope || {}) {

// Use same HTML parsing code as real template engine so as to trigger same combination of IE weirdnesses
// Also ensure resulting nodelist is an array to mimic what the default templating engine does, so we see the effects of not being able to remove dead memo comment nodes.
return arrayPushAll([], parseHtmlFragment(result, templateDocument));
};
// Use same HTML parsing code as real template engine so as to trigger same combination of IE weirdnesses
// Also ensure resulting nodelist is an array to mimic what the default templating engine does, so we see the effects of not being able to remove dead memo comment nodes.
return arrayPushAll([], parseHtmlFragment(result, templateDocument))
}
this.rewriteTemplate = function (template, rewriterCallback, templateDocument) {
// Only rewrite if the template isn't a function (can't rewrite those)
var templateSource = this.makeTemplateSource(template, templateDocument);
if (typeof templateSource.text() != "function")
return templateEngine.prototype.rewriteTemplate.call(this, template, rewriterCallback, templateDocument);
};
this.createJavaScriptEvaluatorBlock = function (script) { return "[js:" + script + "]"; };
this.rewriteTemplate = function (template, rewriterCallback, templateDocument) {
// Only rewrite if the template isn't a function (can't rewrite those)
const templateSource = this.makeTemplateSource(template, templateDocument)
if (typeof templateSource.text() != 'function')
return templateEngine.prototype.rewriteTemplate.call(this, template, rewriterCallback, templateDocument)
}
this.createJavaScriptEvaluatorBlock = function (script) {
return '[js:' + script + ']'
}
}
dummyTemplateEngine.prototype = new templateEngine();
dummyTemplateEngine.prototype = new templateEngine()
{
"version": "4.0.0-beta1.3",
"version": "4.0.0",
"name": "@tko/binding.template",

@@ -26,6 +26,6 @@ "description": "TKO Template bindings",

"dependencies": {
"@tko/bind": "^4.0.0-beta1.3",
"@tko/computed": "^4.0.0-beta1.3",
"@tko/observable": "^4.0.0-beta1.3",
"@tko/utils": "^4.0.0-beta1.3",
"@tko/bind": "^4.0.0",
"@tko/computed": "^4.0.0",
"@tko/observable": "^4.0.0",
"@tko/utils": "^4.0.0",
"tslib": "^2.2.0"

@@ -39,3 +39,3 @@ },

"peerDependencies": {
"@tko/binding.if": "^4.0.0-alpha9.0"
"@tko/binding.if": "^4.0.0"
},

@@ -54,4 +54,3 @@ "licenses": [

"./helpers/*": "./helpers/*"
},
"gitHead": "a8843acb8ae085915115e53a4e057b30731c635e"
}
}
The MIT License (MIT) - http://www.opensource.org/licenses/mit-license.php
Copyright (c) Steven Sanderson, the Knockout.js team, and other contributors
http://knockoutjs.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

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

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