@tko/bind 4.0.0-alpha8.4 → 4.0.0-beta1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ // @tko/bind 🥊 4.0.0-beta1.3 ESM
2
+ import { options } from "@tko/utils";
3
+ import { isWriteableObservable } from "@tko/observable";
4
+ import { LifeCycle } from "@tko/lifecycle";
5
+ export class BindingHandler extends LifeCycle {
6
+ constructor(params) {
7
+ super();
8
+ const { $element, valueAccessor, allBindings, $context } = params;
9
+ Object.assign(this, {
10
+ valueAccessor,
11
+ allBindings,
12
+ $element,
13
+ $context,
14
+ $data: $context.$data
15
+ });
16
+ this.anchorTo($element);
17
+ }
18
+ get value() {
19
+ return this.valueAccessor();
20
+ }
21
+ set value(v) {
22
+ const va = this.valueAccessor();
23
+ if (isWriteableObservable(va)) {
24
+ va(v);
25
+ } else {
26
+ this.valueAccessor(v);
27
+ }
28
+ }
29
+ get controlsDescendants() {
30
+ return false;
31
+ }
32
+ static get allowVirtualElements() {
33
+ return false;
34
+ }
35
+ static get isBindingHandlerClass() {
36
+ return true;
37
+ }
38
+ get bindingCompleted() {
39
+ return true;
40
+ }
41
+ static registerAs(name, provider = options.bindingProviderInstance) {
42
+ provider.bindingHandlers.set(name, this);
43
+ }
44
+ }
45
+ const ResolveSymbol = Symbol("Async Binding Resolved");
46
+ export class AsyncBindingHandler extends BindingHandler {
47
+ constructor(params) {
48
+ super(params);
49
+ this.bindingCompletion = new Promise((resolve) => {
50
+ this[ResolveSymbol] = resolve;
51
+ });
52
+ this.completeBinding = (bindingResult) => this[ResolveSymbol](bindingResult);
53
+ }
54
+ get bindingCompleted() {
55
+ return this.bindingCompletion;
56
+ }
57
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/BindingHandler.ts"],
4
+ "sourcesContent": ["\nimport { options } from '@tko/utils'\nimport { isWriteableObservable } from '@tko/observable'\nimport { LifeCycle } from '@tko/lifecycle'\n\nexport class BindingHandler extends LifeCycle {\n constructor (params) {\n super()\n const {$element, valueAccessor, allBindings, $context} = params\n Object.assign(this, {\n valueAccessor,\n allBindings,\n $element,\n $context,\n $data: $context.$data\n })\n\n this.anchorTo($element)\n }\n\n get value () { return this.valueAccessor() }\n set value (v) {\n const va = this.valueAccessor()\n if (isWriteableObservable(va)) {\n va(v)\n } else {\n this.valueAccessor(v)\n }\n }\n\n get controlsDescendants () { return false }\n\n static get allowVirtualElements () { return false }\n static get isBindingHandlerClass () { return true }\n\n /* Overload this for asynchronous bindings or bindings that recursively\n apply bindings (e.g. components, foreach, template).\n\n A binding should be complete when it has run through once, notably\n in server-side bindings for pre-rendering.\n */\n get bindingCompleted () { return true }\n\n static registerAs (name, provider = options.bindingProviderInstance) {\n provider.bindingHandlers.set(name, this)\n }\n}\n\n/**\n * An AsyncBindingHandler shall call `completeBinding` when the binding\n * is to be considered complete.\n */\nconst ResolveSymbol = Symbol('Async Binding Resolved')\n\nexport class AsyncBindingHandler extends BindingHandler {\n constructor (params) {\n super(params)\n this.bindingCompletion = new Promise((resolve) => {\n this[ResolveSymbol] = resolve\n })\n this.completeBinding = bindingResult => this[ResolveSymbol](bindingResult)\n }\n\n get bindingCompleted () { return this.bindingCompletion }\n}\n"],
5
+ "mappings": ";AACA;AACA;AACA;AAEO,aAAM,uBAAuB,UAAU;AAAA,EAC5C,YAAa,QAAQ;AACnB,UAAM;AACN,UAAM,EAAC,UAAU,eAAe,aAAa,aAAY;AACzD,WAAO,OAAO,MAAM;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,SAAS;AAAA,IAClB,CAAC;AAED,SAAK,SAAS,QAAQ;AAAA,EACxB;AAAA,MAEI,QAAS;AAAE,WAAO,KAAK,cAAc;AAAA,EAAE;AAAA,MACvC,MAAO,GAAG;AACZ,UAAM,KAAK,KAAK,cAAc;AAC9B,QAAI,sBAAsB,EAAE,GAAG;AAC7B,SAAG,CAAC;AAAA,IACN,OAAO;AACL,WAAK,cAAc,CAAC;AAAA,IACtB;AAAA,EACF;AAAA,MAEI,sBAAuB;AAAE,WAAO;AAAA,EAAM;AAAA,aAE/B,uBAAwB;AAAE,WAAO;AAAA,EAAM;AAAA,aACvC,wBAAyB;AAAE,WAAO;AAAA,EAAK;AAAA,MAQ9C,mBAAoB;AAAE,WAAO;AAAA,EAAK;AAAA,SAE/B,WAAY,MAAM,WAAW,QAAQ,yBAAyB;AACnE,aAAS,gBAAgB,IAAI,MAAM,IAAI;AAAA,EACzC;AACF;AAMA,MAAM,gBAAgB,OAAO,wBAAwB;AAE9C,aAAM,4BAA4B,eAAe;AAAA,EACtD,YAAa,QAAQ;AACnB,UAAM,MAAM;AACZ,SAAK,oBAAoB,IAAI,QAAQ,CAAC,YAAY;AAChD,WAAK,iBAAiB;AAAA,IACxB,CAAC;AACD,SAAK,kBAAkB,mBAAiB,KAAK,eAAe,aAAa;AAAA,EAC3E;AAAA,MAEI,mBAAoB;AAAE,WAAO,KAAK;AAAA,EAAkB;AAC1D;",
6
+ "names": []
7
+ }
@@ -0,0 +1,41 @@
1
+ // @tko/bind 🥊 4.0.0-beta1.3 ESM
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+ export class BindingResult {
23
+ constructor({ asyncBindingsApplied, rootNode, bindingContext }) {
24
+ Object.assign(this, {
25
+ rootNode,
26
+ bindingContext,
27
+ isSync: asyncBindingsApplied.size === 0,
28
+ isComplete: this.isSync
29
+ });
30
+ if (!this.isSync) {
31
+ this.completionPromise = this.completeWhenBindingsFinish(asyncBindingsApplied);
32
+ }
33
+ }
34
+ completeWhenBindingsFinish(asyncBindingsApplied) {
35
+ return __async(this, null, function* () {
36
+ yield Promise.all(asyncBindingsApplied);
37
+ this.isComplete = true;
38
+ return this;
39
+ });
40
+ }
41
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/BindingResult.ts"],
4
+ "sourcesContent": ["\n\nexport class BindingResult {\n constructor ({asyncBindingsApplied, rootNode, bindingContext}) {\n Object.assign(this, {\n rootNode,\n bindingContext,\n isSync: asyncBindingsApplied.size === 0,\n isComplete: this.isSync\n })\n\n if (!this.isSync) {\n this.completionPromise = this.completeWhenBindingsFinish(asyncBindingsApplied)\n }\n }\n\n async completeWhenBindingsFinish (asyncBindingsApplied) {\n await Promise.all(asyncBindingsApplied)\n this.isComplete = true\n return this\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAEO,aAAM,cAAc;AAAA,EACzB,YAAa,EAAC,sBAAsB,UAAU,kBAAiB;AAC7D,WAAO,OAAO,MAAM;AAAA,MAClB;AAAA,MACA;AAAA,MACA,QAAQ,qBAAqB,SAAS;AAAA,MACtC,YAAY,KAAK;AAAA,IACnB,CAAC;AAED,QAAI,CAAC,KAAK,QAAQ;AAChB,WAAK,oBAAoB,KAAK,2BAA2B,oBAAoB;AAAA,IAC/E;AAAA,EACF;AAAA,EAEM,2BAA4B,sBAAsB;AAAA;AACtD,YAAM,QAAQ,IAAI,oBAAoB;AACtC,WAAK,aAAa;AAClB,aAAO;AAAA,IACT;AAAA;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,42 @@
1
+ // @tko/bind 🥊 4.0.0-beta1.3 ESM
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+ import { applyBindingsToDescendants } from "./applyBindings";
23
+ import { AsyncBindingHandler } from "./BindingHandler";
24
+ export class DescendantBindingHandler extends AsyncBindingHandler {
25
+ get controlsDescendants() {
26
+ return true;
27
+ }
28
+ applyBindingsToDescendants(childContext, callback) {
29
+ return __async(this, null, function* () {
30
+ const bindingResult = applyBindingsToDescendants(childContext, this.$element);
31
+ if (bindingResult.isSync) {
32
+ this.bindingCompletion = bindingResult;
33
+ } else {
34
+ yield bindingResult.completionPromise;
35
+ }
36
+ if (callback) {
37
+ callback(bindingResult);
38
+ }
39
+ this.completeBinding(bindingResult);
40
+ });
41
+ }
42
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/DescendantBindingHandler.ts"],
4
+ "sourcesContent": ["\n\nimport { applyBindingsToDescendants } from './applyBindings'\nimport { AsyncBindingHandler } from './BindingHandler'\n\n/**\n * This DescendantBindingHandler is a base class for bindings that control\n * descendants, such as the `if`, `with`, `component`, `foreach` and `template`\n * bindings.\n */\nexport class DescendantBindingHandler extends AsyncBindingHandler {\n get controlsDescendants () { return true }\n\n async applyBindingsToDescendants (childContext, callback) {\n const bindingResult = applyBindingsToDescendants(childContext, this.$element)\n if (bindingResult.isSync) {\n this.bindingCompletion = bindingResult\n } else {\n await bindingResult.completionPromise\n }\n if (callback) { callback(bindingResult) }\n this.completeBinding(bindingResult)\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AAOO,aAAM,iCAAiC,oBAAoB;AAAA,MAC5D,sBAAuB;AAAE,WAAO;AAAA,EAAK;AAAA,EAEnC,2BAA4B,cAAc,UAAU;AAAA;AACxD,YAAM,gBAAgB,2BAA2B,cAAc,KAAK,QAAQ;AAC5E,UAAI,cAAc,QAAQ;AACxB,aAAK,oBAAoB;AAAA,MAC3B,OAAO;AACL,cAAM,cAAc;AAAA,MACtB;AACA,UAAI,UAAU;AAAE,iBAAS,aAAa;AAAA,MAAE;AACxC,WAAK,gBAAgB,aAAa;AAAA,IACpC;AAAA;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,84 @@
1
+ // @tko/bind 🥊 4.0.0-beta1.3 ESM
2
+ import { virtualElements, options } from "@tko/utils";
3
+ import { BindingHandler } from "./BindingHandler";
4
+ const PossibleWeakMap = options.global.WeakMap || Map;
5
+ const legacyBindingMap = new PossibleWeakMap();
6
+ export class LegacyBindingHandler extends BindingHandler {
7
+ constructor(params) {
8
+ super(params);
9
+ const handler = this.handler;
10
+ this.onError = params.onError;
11
+ if (typeof handler.dispose === "function") {
12
+ this.addDisposable(handler);
13
+ }
14
+ try {
15
+ this.initReturn = handler.init && handler.init(...this.legacyArgs);
16
+ } catch (e) {
17
+ params.onError("init", e);
18
+ }
19
+ }
20
+ onValueChange() {
21
+ const handler = this.handler;
22
+ if (typeof handler.update !== "function") {
23
+ return;
24
+ }
25
+ try {
26
+ handler.update(...this.legacyArgs);
27
+ } catch (e) {
28
+ this.onError("update", e);
29
+ }
30
+ }
31
+ get legacyArgs() {
32
+ return [
33
+ this.$element,
34
+ this.valueAccessor,
35
+ this.allBindings,
36
+ this.$data,
37
+ this.$context
38
+ ];
39
+ }
40
+ get controlsDescendants() {
41
+ const objectToTest = this.initReturn || this.handler || {};
42
+ return objectToTest.controlsDescendantBindings;
43
+ }
44
+ static getOrCreateFor(key, handler) {
45
+ if (legacyBindingMap.has(handler)) {
46
+ return legacyBindingMap.get(handler);
47
+ }
48
+ const newLegacyHandler = this.createFor(key, handler);
49
+ legacyBindingMap.set(handler, newLegacyHandler);
50
+ return newLegacyHandler;
51
+ }
52
+ static createFor(key, handler) {
53
+ if (typeof handler === "function") {
54
+ const [initFn, disposeFn] = [handler, handler.dispose];
55
+ return class extends LegacyBindingHandler {
56
+ get handler() {
57
+ const init = initFn.bind(this);
58
+ const dispose = disposeFn ? disposeFn.bind(this) : null;
59
+ return { init, dispose };
60
+ }
61
+ static get after() {
62
+ return handler.after;
63
+ }
64
+ static get allowVirtualElements() {
65
+ return handler.allowVirtualElements || virtualElements.allowedBindings[key];
66
+ }
67
+ };
68
+ }
69
+ if (typeof handler === "object") {
70
+ return class extends LegacyBindingHandler {
71
+ get handler() {
72
+ return handler;
73
+ }
74
+ static get after() {
75
+ return handler.after;
76
+ }
77
+ static get allowVirtualElements() {
78
+ return handler.allowVirtualElements || virtualElements.allowedBindings[key];
79
+ }
80
+ };
81
+ }
82
+ throw new Error("The given handler is not an appropriate type.");
83
+ }
84
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/LegacyBindingHandler.ts"],
4
+ "sourcesContent": ["\nimport { virtualElements, options } from '@tko/utils'\nimport { BindingHandler } from './BindingHandler'\n\n/**\n * We have no guarantees, for users employing legacy bindings,\n * that it has not been changed with a modification like\n *\n * ko.bindingHandlers[name] = { init: ...}\n *\n * ... so we have to keep track by way of a map.\n */\nconst PossibleWeakMap = options.global.WeakMap || Map\nconst legacyBindingMap = new PossibleWeakMap()\n\nexport class LegacyBindingHandler extends BindingHandler {\n constructor (params) {\n super(params)\n const handler = this.handler\n this.onError = params.onError\n\n if (typeof handler.dispose === 'function') {\n this.addDisposable(handler)\n }\n\n try {\n this.initReturn = handler.init && handler.init(...this.legacyArgs)\n } catch (e) {\n params.onError('init', e)\n }\n }\n\n onValueChange () {\n const handler = this.handler\n if (typeof handler.update !== 'function') { return }\n try {\n handler.update(...this.legacyArgs)\n } catch (e) {\n this.onError('update', e)\n }\n }\n\n get legacyArgs () {\n return [\n this.$element, this.valueAccessor, this.allBindings,\n this.$data, this.$context\n ]\n }\n\n get controlsDescendants () {\n const objectToTest = this.initReturn || this.handler || {}\n return objectToTest.controlsDescendantBindings\n }\n\n /**\n * Create a handler instance from the `origin`, which may be:\n *\n * 1. an object (becomes LegacyBindingHandler)\n * 2. a function (becomes LegacyBindingHandler with `init: function`)\n *\n * If given an object (the only kind supported in knockout 3.x and before), it\n * shall draw the `init`, `update`, and `allowVirtualElements` properties\n */\n static getOrCreateFor (key, handler) {\n if (legacyBindingMap.has(handler)) {\n return legacyBindingMap.get(handler)\n }\n const newLegacyHandler = this.createFor(key, handler)\n legacyBindingMap.set(handler, newLegacyHandler)\n return newLegacyHandler\n }\n\n static createFor (key, handler) {\n if (typeof handler === 'function') {\n const [initFn, disposeFn] = [handler, handler.dispose]\n return class extends LegacyBindingHandler {\n get handler () {\n const init = initFn.bind(this)\n const dispose = disposeFn ? disposeFn.bind(this) : null\n return { init, dispose }\n }\n static get after () { return handler.after }\n static get allowVirtualElements () {\n return handler.allowVirtualElements || virtualElements.allowedBindings[key]\n }\n }\n }\n\n if (typeof handler === 'object') {\n return class extends LegacyBindingHandler {\n get handler () { return handler }\n static get after () { return handler.after }\n static get allowVirtualElements () {\n return handler.allowVirtualElements || virtualElements.allowedBindings[key]\n }\n }\n }\n\n throw new Error('The given handler is not an appropriate type.')\n }\n}\n"],
5
+ "mappings": ";AACA;AACA;AAUA,MAAM,kBAAkB,QAAQ,OAAO,WAAW;AAClD,MAAM,mBAAmB,IAAI,gBAAgB;AAEtC,aAAM,6BAA6B,eAAe;AAAA,EACvD,YAAa,QAAQ;AACnB,UAAM,MAAM;AACZ,UAAM,UAAU,KAAK;AACrB,SAAK,UAAU,OAAO;AAEtB,QAAI,OAAO,QAAQ,YAAY,YAAY;AACzC,WAAK,cAAc,OAAO;AAAA,IAC5B;AAEA,QAAI;AACF,WAAK,aAAa,QAAQ,QAAQ,QAAQ,KAAK,GAAG,KAAK,UAAU;AAAA,IACnE,SAAS,GAAP;AACA,aAAO,QAAQ,QAAQ,CAAC;AAAA,IAC1B;AAAA,EACF;AAAA,EAEA,gBAAiB;A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,iBAAO,QAAQ;AAAA,QAAM;AAAA,mBAChC,uBAAwB;AACjC,iBAAO,QAAQ,wBAAwB,gBAAgB,gBAAgB;AAAA,QACzE;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,331 @@
1
+ // @tko/bind 🥊 4.0.0-beta1.3 ESM
2
+ import {
3
+ extend,
4
+ objectMap,
5
+ virtualElements,
6
+ tagNameLower,
7
+ domData,
8
+ objectForEach,
9
+ arrayIndexOf,
10
+ arrayForEach,
11
+ options
12
+ } from "@tko/utils";
13
+ import {
14
+ dependencyDetection
15
+ } from "@tko/observable";
16
+ import {
17
+ computed
18
+ } from "@tko/computed";
19
+ import {
20
+ dataFor,
21
+ bindingContext,
22
+ boundElementDomDataKey,
23
+ contextSubscribeSymbol
24
+ } from "./bindingContext";
25
+ import {
26
+ bindingEvent
27
+ } from "./bindingEvent";
28
+ import {
29
+ BindingResult
30
+ } from "./BindingResult";
31
+ import {
32
+ LegacyBindingHandler
33
+ } from "./LegacyBindingHandler";
34
+ const bindingDoesNotRecurseIntoElementTypes = {
35
+ "script": true,
36
+ "textarea": true,
37
+ "template": true
38
+ };
39
+ function getBindingProvider() {
40
+ return options.bindingProviderInstance.instance || options.bindingProviderInstance;
41
+ }
42
+ function isProviderForNode(provider, node) {
43
+ const nodeTypes = provider.FOR_NODE_TYPES || [1, 3, 8];
44
+ return nodeTypes.includes(node.nodeType);
45
+ }
46
+ function asProperHandlerClass(handler, bindingKey) {
47
+ if (!handler) {
48
+ return;
49
+ }
50
+ return handler.isBindingHandlerClass ? handler : LegacyBindingHandler.getOrCreateFor(bindingKey, handler);
51
+ }
52
+ function getBindingHandlerFromComponent(bindingKey, $component) {
53
+ if (!$component || typeof $component.getBindingHandler !== "function") {
54
+ return;
55
+ }
56
+ return asProperHandlerClass($component.getBindingHandler(bindingKey));
57
+ }
58
+ export function getBindingHandler(bindingKey) {
59
+ const bindingDefinition = options.getBindingHandler(bindingKey) || getBindingProvider().bindingHandlers.get(bindingKey);
60
+ return asProperHandlerClass(bindingDefinition, bindingKey);
61
+ }
62
+ function evaluateValueAccessor(valueAccessor) {
63
+ return valueAccessor();
64
+ }
65
+ function applyBindingsToDescendantsInternal(bindingContext2, elementOrVirtualElement, asyncBindingsApplied) {
66
+ let nextInQueue = virtualElements.firstChild(elementOrVirtualElement);
67
+ if (!nextInQueue) {
68
+ return;
69
+ }
70
+ let currentChild;
71
+ const provider = getBindingProvider();
72
+ const preprocessNode = provider.preprocessNode;
73
+ if (preprocessNode) {
74
+ while (currentChild = nextInQueue) {
75
+ nextInQueue = virtualElements.nextSibling(currentChild);
76
+ preprocessNode.call(provider, currentChild);
77
+ }
78
+ nextInQueue = virtualElements.firstChild(elementOrVirtualElement);
79
+ }
80
+ while (currentChild = nextInQueue) {
81
+ nextInQueue = virtualElements.nextSibling(currentChild);
82
+ applyBindingsToNodeAndDescendantsInternal(bindingContext2, currentChild, asyncBindingsApplied);
83
+ }
84
+ bindingEvent.notify(elementOrVirtualElement, bindingEvent.childrenComplete);
85
+ }
86
+ function hasBindings(node) {
87
+ const provider = getBindingProvider();
88
+ return isProviderForNode(provider, node) && provider.nodeHasBindings(node);
89
+ }
90
+ function nodeOrChildHasBindings(node) {
91
+ return hasBindings(node) || [...node.childNodes].some((c) => nodeOrChildHasBindings(c));
92
+ }
93
+ function applyBindingsToNodeAndDescendantsInternal(bindingContext2, nodeVerified, asyncBindingsApplied) {
94
+ var isElement = nodeVerified.nodeType === 1;
95
+ if (isElement) {
96
+ virtualElements.normaliseVirtualElementDomStructure(nodeVerified);
97
+ }
98
+ let shouldApplyBindings = isElement || hasBindings(nodeVerified);
99
+ const { shouldBindDescendants } = shouldApplyBindings ? applyBindingsToNodeInternal(nodeVerified, null, bindingContext2, asyncBindingsApplied) : { shouldBindDescendants: true };
100
+ if (shouldBindDescendants && !bindingDoesNotRecurseIntoElementTypes[tagNameLower(nodeVerified)]) {
101
+ applyBindingsToDescendantsInternal(bindingContext2, nodeVerified, asyncBindingsApplied);
102
+ }
103
+ }
104
+ function* topologicalSortBindings(bindings, $component) {
105
+ const results = [];
106
+ const bindingsConsidered = {};
107
+ const cyclicDependencyStack = [];
108
+ objectForEach(bindings, function pushBinding(bindingKey) {
109
+ if (!bindingsConsidered[bindingKey]) {
110
+ const binding = getBindingHandlerFromComponent(bindingKey, $component) || getBindingHandler(bindingKey);
111
+ if (!binding) {
112
+ return;
113
+ }
114
+ if (binding.after) {
115
+ cyclicDependencyStack.push(bindingKey);
116
+ arrayForEach(binding.after, function(bindingDependencyKey) {
117
+ if (!bindings[bindingDependencyKey]) {
118
+ return;
119
+ }
120
+ if (arrayIndexOf(cyclicDependencyStack, bindingDependencyKey) !== -1) {
121
+ throw Error("Cannot combine the following bindings, because they have a cyclic dependency: " + cyclicDependencyStack.join(", "));
122
+ } else {
123
+ pushBinding(bindingDependencyKey);
124
+ }
125
+ });
126
+ cyclicDependencyStack.length--;
127
+ }
128
+ results.push([bindingKey, binding]);
129
+ }
130
+ bindingsConsidered[bindingKey] = true;
131
+ });
132
+ for (const result of results) {
133
+ yield result;
134
+ }
135
+ }
136
+ function applyBindingsToNodeInternal(node, sourceBindings, bindingContext2, asyncBindingsApplied) {
137
+ const bindingInfo = domData.getOrSet(node, boundElementDomDataKey, {});
138
+ const alreadyBound = bindingInfo.alreadyBound;
139
+ if (!sourceBindings) {
140
+ if (alreadyBound) {
141
+ if (!nodeOrChildHasBindings(node)) {
142
+ return false;
143
+ }
144
+ onBindingError({
145
+ during: "apply",
146
+ errorCaptured: new Error("You cannot apply bindings multiple times to the same element."),
147
+ element: node,
148
+ bindingContext: bindingContext2
149
+ });
150
+ return false;
151
+ }
152
+ bindingInfo.alreadyBound = true;
153
+ }
154
+ if (!alreadyBound) {
155
+ bindingInfo.context = bindingContext2;
156
+ }
157
+ var bindings;
158
+ if (sourceBindings && typeof sourceBindings !== "function") {
159
+ bindings = sourceBindings;
160
+ } else {
161
+ const provider = getBindingProvider();
162
+ const getBindings = provider.getBindingAccessors;
163
+ if (isProviderForNode(provider, node)) {
164
+ var bindingsUpdater = computed(function() {
165
+ bindings = sourceBindings ? sourceBindings(bindingContext2, node) : getBindings.call(provider, node, bindingContext2);
166
+ if (bindings && bindingContext2[contextSubscribeSymbol]) {
167
+ bindingContext2[contextSubscribeSymbol]();
168
+ }
169
+ return bindings;
170
+ }, null, { disposeWhenNodeIsRemoved: node });
171
+ if (!bindings || !bindingsUpdater.isActive()) {
172
+ bindingsUpdater = null;
173
+ }
174
+ }
175
+ }
176
+ var bindingHandlerThatControlsDescendantBindings;
177
+ if (bindings) {
178
+ let allBindings = function() {
179
+ return objectMap(bindingsUpdater ? bindingsUpdater() : bindings, evaluateValueAccessor);
180
+ };
181
+ const $component = bindingContext2.$component || {};
182
+ const allBindingHandlers = {};
183
+ domData.set(node, "bindingHandlers", allBindingHandlers);
184
+ const getValueAccessor = bindingsUpdater ? (bindingKey) => function(optionalValue) {
185
+ const valueAccessor = bindingsUpdater()[bindingKey];
186
+ if (arguments.length === 0) {
187
+ return evaluateValueAccessor(valueAccessor);
188
+ } else {
189
+ return valueAccessor(optionalValue);
190
+ }
191
+ } : (bindingKey) => bindings[bindingKey];
192
+ allBindings.has = (key) => key in bindings;
193
+ allBindings.get = (key) => bindings[key] && evaluateValueAccessor(getValueAccessor(key));
194
+ if (bindingEvent.childrenComplete in bindings) {
195
+ bindingEvent.subscribe(node, bindingEvent.childrenComplete, () => {
196
+ const callback = evaluateValueAccessor(bindings[bindingEvent.childrenComplete]);
197
+ if (!callback) {
198
+ return;
199
+ }
200
+ const nodes = virtualElements.childNodes(node);
201
+ if (nodes.length) {
202
+ callback(nodes, dataFor(nodes[0]));
203
+ }
204
+ });
205
+ }
206
+ const bindingsGenerated = topologicalSortBindings(bindings, $component);
207
+ const nodeAsyncBindingPromises = /* @__PURE__ */ new Set();
208
+ for (const [key, BindingHandlerClass] of bindingsGenerated) {
209
+ let reportBindingError = function(during, errorCaptured) {
210
+ onBindingError({
211
+ during,
212
+ errorCaptured,
213
+ bindings,
214
+ allBindings,
215
+ bindingKey: key,
216
+ bindingContext: bindingContext2,
217
+ element: node,
218
+ valueAccessor: getValueAccessor(key)
219
+ });
220
+ };
221
+ if (node.nodeType === 8 && !BindingHandlerClass.allowVirtualElements) {
222
+ throw new Error(`The binding '${key}' cannot be used with virtual elements`);
223
+ }
224
+ try {
225
+ const bindingHandler = dependencyDetection.ignore(() => new BindingHandlerClass({
226
+ allBindings,
227
+ $element: node,
228
+ $context: bindingContext2,
229
+ onError: reportBindingError,
230
+ valueAccessor(...v) {
231
+ return getValueAccessor(key)(...v);
232
+ }
233
+ }));
234
+ if (bindingHandler.onValueChange) {
235
+ dependencyDetection.ignore(() => bindingHandler.computed("onValueChange"));
236
+ }
237
+ allBindingHandlers[key] = bindingHandler;
238
+ if (bindingHandler.controlsDescendants) {
239
+ if (bindingHandlerThatControlsDescendantBindings !== void 0) {
240
+ throw new Error("Multiple bindings (" + bindingHandlerThatControlsDescendantBindings + " and " + key + ") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");
241
+ }
242
+ bindingHandlerThatControlsDescendantBindings = key;
243
+ }
244
+ if (bindingHandler.bindingCompleted instanceof Promise) {
245
+ asyncBindingsApplied.add(bindingHandler.bindingCompleted);
246
+ nodeAsyncBindingPromises.add(bindingHandler.bindingCompleted);
247
+ }
248
+ } catch (err) {
249
+ reportBindingError("creation", err);
250
+ }
251
+ }
252
+ triggerDescendantsComplete(node, bindings, nodeAsyncBindingPromises);
253
+ }
254
+ const shouldBindDescendants = bindingHandlerThatControlsDescendantBindings === void 0;
255
+ return { shouldBindDescendants };
256
+ }
257
+ function triggerDescendantsComplete(node, bindings, nodeAsyncBindingPromises) {
258
+ const hasBindingHandler = bindingEvent.descendantsComplete in bindings;
259
+ const hasFirstChild = virtualElements.firstChild(node);
260
+ const accessor = hasBindingHandler && evaluateValueAccessor(bindings[bindingEvent.descendantsComplete]);
261
+ const callback = () => {
262
+ bindingEvent.notify(node, bindingEvent.descendantsComplete);
263
+ if (accessor && hasFirstChild) {
264
+ accessor(node);
265
+ }
266
+ };
267
+ if (nodeAsyncBindingPromises.size) {
268
+ Promise.all(nodeAsyncBindingPromises).then(callback);
269
+ } else {
270
+ callback();
271
+ }
272
+ }
273
+ function getBindingContext(viewModelOrBindingContext, extendContextCallback) {
274
+ return viewModelOrBindingContext && viewModelOrBindingContext instanceof bindingContext ? viewModelOrBindingContext : new bindingContext(viewModelOrBindingContext, void 0, void 0, extendContextCallback);
275
+ }
276
+ export function applyBindingAccessorsToNode(node, bindings, viewModelOrBindingContext, asyncBindingsApplied) {
277
+ if (node.nodeType === 1) {
278
+ virtualElements.normaliseVirtualElementDomStructure(node);
279
+ }
280
+ return applyBindingsToNodeInternal(node, bindings, getBindingContext(viewModelOrBindingContext), asyncBindingsApplied);
281
+ }
282
+ export function applyBindingsToNode(node, bindings, viewModelOrBindingContext) {
283
+ const asyncBindingsApplied = /* @__PURE__ */ new Set();
284
+ const bindingContext2 = getBindingContext(viewModelOrBindingContext);
285
+ const bindingAccessors = getBindingProvider().makeBindingAccessors(bindings, bindingContext2, node);
286
+ applyBindingAccessorsToNode(node, bindingAccessors, bindingContext2, asyncBindingsApplied);
287
+ return new BindingResult({ asyncBindingsApplied, rootNode: node, bindingContext: bindingContext2 });
288
+ }
289
+ export function applyBindingsToDescendants(viewModelOrBindingContext, rootNode) {
290
+ const asyncBindingsApplied = /* @__PURE__ */ new Set();
291
+ if (rootNode.nodeType === 1 || rootNode.nodeType === 8) {
292
+ const bindingContext2 = getBindingContext(viewModelOrBindingContext);
293
+ applyBindingsToDescendantsInternal(bindingContext2, rootNode, asyncBindingsApplied);
294
+ return new BindingResult({ asyncBindingsApplied, rootNode, bindingContext: bindingContext2 });
295
+ }
296
+ return new BindingResult({ asyncBindingsApplied, rootNode });
297
+ }
298
+ export function applyBindings(viewModelOrBindingContext, rootNode, extendContextCallback) {
299
+ const asyncBindingsApplied = /* @__PURE__ */ new Set();
300
+ if (!options.jQuery === void 0 && options.jQuery) {
301
+ options.jQuery = options.jQuery;
302
+ }
303
+ if (!rootNode) {
304
+ rootNode = window.document.body;
305
+ if (!rootNode) {
306
+ throw Error("ko.applyBindings: could not find window.document.body; has the document been loaded?");
307
+ }
308
+ } else if (rootNode.nodeType !== 1 && rootNode.nodeType !== 8) {
309
+ throw Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node");
310
+ }
311
+ const rootContext = getBindingContext(viewModelOrBindingContext, extendContextCallback);
312
+ applyBindingsToNodeAndDescendantsInternal(rootContext, rootNode, asyncBindingsApplied);
313
+ return Promise.all(asyncBindingsApplied);
314
+ }
315
+ function onBindingError(spec) {
316
+ var error, bindingText;
317
+ if (spec.bindingKey) {
318
+ error = spec.errorCaptured;
319
+ spec.message = 'Unable to process binding "' + spec.bindingKey + '" in binding "' + spec.bindingKey + '"\nMessage: ' + (error.message ? error.message : error);
320
+ } else {
321
+ error = spec.errorCaptured;
322
+ }
323
+ try {
324
+ extend(error, spec);
325
+ } catch (e) {
326
+ spec.stack = error.stack;
327
+ error = new Error(error.message ? error.message : error);
328
+ extend(error, spec);
329
+ }
330
+ options.onError(error);
331
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/applyBindings.ts"],
4
+ "sourcesContent": ["\n/* eslint no-cond-assign: 0 */\n\nimport {\n extend, objectMap, virtualElements, tagNameLower, domData, objectForEach,\n arrayIndexOf, arrayForEach, options\n} from '@tko/utils'\n\nimport {\n dependencyDetection\n} from '@tko/observable'\n\nimport {\n computed\n} from '@tko/computed'\n\nimport {\n dataFor, bindingContext, boundElementDomDataKey, contextSubscribeSymbol\n} from './bindingContext'\n\nimport {\n bindingEvent\n} from './bindingEvent'\n\nimport {\n BindingResult\n} from './BindingResult'\n\nimport {\n LegacyBindingHandler\n} from './LegacyBindingHandler'\n\n// The following element types will not be recursed into during binding.\nconst bindingDoesNotRecurseIntoElementTypes = {\n // Don't want bindings that operate on text nodes to mutate <script> and <textarea> contents,\n // because it's unexpected and a potential XSS issue.\n // Also bindings should not operate on <template> elements since this breaks in Internet Explorer\n // and because such elements' contents are always intended to be bound in a different context\n // from where they appear in the document.\n 'script': true,\n 'textarea': true,\n 'template': true\n}\n\nfunction getBindingProvider () {\n return options.bindingProviderInstance.instance || options.bindingProviderInstance\n}\n\nfunction isProviderForNode (provider, node) {\n const nodeTypes = provider.FOR_NODE_TYPES || [1, 3, 8]\n return nodeTypes.includes(node.nodeType)\n}\n\nfunction asProperHandlerClass (handler, bindingKey) {\n if (!handler) { return }\n return handler.isBindingHandlerClass ? handler\n : LegacyBindingHandler.getOrCreateFor(bindingKey, handler)\n}\n\nfunction getBindingHandlerFromComponent (bindingKey, $component) {\n if (!$component || typeof $component.getBindingHandler !== 'function') { return }\n return asProperHandlerClass($component.getBindingHandler(bindingKey))\n}\n\nexport function getBindingHandler (bindingKey) {\n const bindingDefinition = options.getBindingHandler(bindingKey) || getBindingProvider().bindingHandlers.get(bindingKey)\n return asProperHandlerClass(bindingDefinition, bindingKey)\n}\n\n// Returns the value of a valueAccessor function\nfunction evaluateValueAccessor (valueAccessor) {\n return valueAccessor()\n}\n\nfunction applyBindingsToDescendantsInternal (bindingContext, elementOrVirtualElement, asyncBindingsApplied) {\n let nextInQueue = virtualElements.firstChild(elementOrVirtualElement)\n\n if (!nextInQueue) { return }\n\n let currentChild\n const provider = getBindingProvider()\n const preprocessNode = provider.preprocessNode\n\n // Preprocessing allows a binding provider to mutate a node before bindings are applied to it. For example it's\n // possible to insert new siblings after it, and/or replace the node with a different one. This can be used to\n // implement custom binding syntaxes, such as {{ value }} for string interpolation, or custom element types that\n // trigger insertion of <template> contents at that point in the document.\n if (preprocessNode) {\n while (currentChild = nextInQueue) {\n nextInQueue = virtualElements.nextSibling(currentChild)\n preprocessNode.call(provider, currentChild)\n }\n\n // Reset nextInQueue for the next loop\n nextInQueue = virtualElements.firstChild(elementOrVirtualElement)\n }\n\n while (currentChild = nextInQueue) {\n // Keep a record of the next child *before* applying bindings, in case the binding removes the current child from its position\n nextInQueue = virtualElements.nextSibling(currentChild)\n applyBindingsToNodeAndDescendantsInternal(bindingContext, currentChild, asyncBindingsApplied)\n }\n\n bindingEvent.notify(elementOrVirtualElement, bindingEvent.childrenComplete)\n}\n\nfunction hasBindings (node) {\n const provider = getBindingProvider()\n return isProviderForNode(provider, node) && provider.nodeHasBindings(node)\n}\n\nfunction nodeOrChildHasBindings (node) {\n return hasBindings(node) || [...node.childNodes].some(c => nodeOrChildHasBindings(c))\n}\n\nfunction applyBindingsToNodeAndDescendantsInternal (bindingContext, nodeVerified, asyncBindingsApplied) {\n var isElement = nodeVerified.nodeType === 1\n if (isElement) { // Workaround IE <= 8 HTML parsing weirdness\n virtualElements.normaliseVirtualElementDomStructure(nodeVerified)\n }\n\n // Perf optimisation: Apply bindings only if...\n // (1) We need to store the binding info for the node (all element nodes)\n // (2) It might have bindings (e.g., it has a data-bind attribute, or it's a marker for a containerless template)\n\n let shouldApplyBindings = isElement || // Case (1)\n hasBindings(nodeVerified) // Case (2)\n\n const { shouldBindDescendants } = shouldApplyBindings\n ? applyBindingsToNodeInternal(nodeVerified, null, bindingContext, asyncBindingsApplied)\n : { shouldBindDescendants: true }\n\n if (shouldBindDescendants && !bindingDoesNotRecurseIntoElementTypes[tagNameLower(nodeVerified)]) {\n // We're recursing automatically into (real or virtual) child nodes without changing binding contexts. So,\n // * For children of a *real* element, the binding context is certainly the same as on their DOM .parentNode,\n // hence bindingContextsMayDifferFromDomParentElement is false\n // * For children of a *virtual* element, we can't be sure. Evaluating .parentNode on those children may\n // skip over any number of intermediate virtual elements, any of which might define a custom binding context,\n // hence bindingContextsMayDifferFromDomParentElement is true\n applyBindingsToDescendantsInternal(bindingContext, nodeVerified, asyncBindingsApplied)\n }\n}\n\n\nfunction * topologicalSortBindings (bindings, $component) {\n const results = []\n // Depth-first sort\n const bindingsConsidered = {} // A temporary record of which bindings are already in 'result'\n const cyclicDependencyStack = [] // Keeps track of a depth-search so that, if there's a cycle, we know which bindings caused it\n\n objectForEach(bindings, function pushBinding (bindingKey) {\n if (!bindingsConsidered[bindingKey]) {\n const binding = getBindingHandlerFromComponent(bindingKey, $component) || getBindingHandler(bindingKey)\n if (!binding) { return }\n // First add dependencies (if any) of the current binding\n if (binding.after) {\n cyclicDependencyStack.push(bindingKey)\n arrayForEach(binding.after, function (bindingDependencyKey) {\n if (!bindings[bindingDependencyKey]) { return }\n if (arrayIndexOf(cyclicDependencyStack, bindingDependencyKey) !== -1) {\n throw Error('Cannot combine the following bindings, because they have a cyclic dependency: ' + cyclicDependencyStack.join(', '))\n } else {\n pushBinding(bindingDependencyKey)\n }\n })\n cyclicDependencyStack.length--\n }\n // Next add the current binding\n results.push([ bindingKey, binding ])\n }\n bindingsConsidered[bindingKey] = true\n })\n\n for (const result of results) { yield result }\n}\n\nfunction applyBindingsToNodeInternal (node, sourceBindings, bindingContext, asyncBindingsApplied) {\n const bindingInfo = domData.getOrSet(node, boundElementDomDataKey, {})\n // Prevent multiple applyBindings calls for the same node, except when a binding value is specified\n const alreadyBound = bindingInfo.alreadyBound\n if (!sourceBindings) {\n if (alreadyBound) {\n if (!nodeOrChildHasBindings(node)) { return false }\n onBindingError({\n during: 'apply',\n errorCaptured: new Error('You cannot apply bindings multiple times to the same element.'),\n element: node,\n bindingContext\n })\n return false\n }\n bindingInfo.alreadyBound = true\n }\n\n if (!alreadyBound) {\n bindingInfo.context = bindingContext\n }\n\n // Use bindings if given, otherwise fall back on asking the bindings provider to give us some bindings\n var bindings\n if (sourceBindings && typeof sourceBindings !== 'function') {\n bindings = sourceBindings\n } else {\n const provider = getBindingProvider()\n const getBindings = provider.getBindingAccessors\n\n if (isProviderForNode(provider, node)) {\n // Get the binding from the provider within a computed observable so that we can update the bindings whenever\n // the binding context is updated or if the binding provider accesses observables.\n var bindingsUpdater = computed(\n function () {\n bindings = sourceBindings ? sourceBindings(bindingContext, node) : getBindings.call(provider, node, bindingContext)\n // Register a dependency on the binding context to support observable view models.\n if (bindings && bindingContext[contextSubscribeSymbol]) { bindingContext[contextSubscribeSymbol]() }\n return bindings\n },\n null, { disposeWhenNodeIsRemoved: node }\n )\n\n if (!bindings || !bindingsUpdater.isActive()) { bindingsUpdater = null }\n }\n }\n\n var bindingHandlerThatControlsDescendantBindings\n if (bindings) {\n const $component = bindingContext.$component || {}\n\n const allBindingHandlers = {}\n domData.set(node, 'bindingHandlers', allBindingHandlers)\n\n // Return the value accessor for a given binding. When bindings are static (won't be updated because of a binding\n // context update), just return the value accessor from the binding. Otherwise, return a function that always gets\n // the latest binding value and registers a dependency on the binding updater.\n const getValueAccessor = bindingsUpdater\n ? (bindingKey) => function (optionalValue) {\n const valueAccessor = bindingsUpdater()[bindingKey]\n if (arguments.length === 0) {\n return evaluateValueAccessor(valueAccessor)\n } else {\n return valueAccessor(optionalValue)\n }\n } : (bindingKey) => bindings[bindingKey]\n\n // Use of allBindings as a function is maintained for backwards compatibility, but its use is deprecated\n function allBindings () {\n return objectMap(bindingsUpdater ? bindingsUpdater() : bindings, evaluateValueAccessor)\n }\n\n // The following is the 3.x allBindings API\n allBindings.has = (key) => key in bindings\n allBindings.get = (key) => bindings[key] && evaluateValueAccessor(getValueAccessor(key))\n\n if (bindingEvent.childrenComplete in bindings) {\n bindingEvent.subscribe(node, bindingEvent.childrenComplete, () => {\n const callback = evaluateValueAccessor(bindings[bindingEvent.childrenComplete])\n if (!callback) { return }\n const nodes = virtualElements.childNodes(node)\n if (nodes.length) { callback(nodes, dataFor(nodes[0])) }\n })\n }\n\n const bindingsGenerated = topologicalSortBindings(bindings, $component)\n const nodeAsyncBindingPromises = new Set()\n for (const [key, BindingHandlerClass] of bindingsGenerated) {\n // Go through the sorted bindings, calling init and update for each\n function reportBindingError (during, errorCaptured) {\n onBindingError({\n during,\n errorCaptured,\n bindings,\n allBindings,\n bindingKey: key,\n bindingContext,\n element: node,\n valueAccessor: getValueAccessor(key)\n })\n }\n\n if (node.nodeType === 8 && !BindingHandlerClass.allowVirtualElements) {\n throw new Error(`The binding '${key}' cannot be used with virtual elements`)\n }\n\n try {\n const bindingHandler = dependencyDetection.ignore(() =>\n new BindingHandlerClass({\n allBindings,\n $element: node,\n $context: bindingContext,\n onError: reportBindingError,\n valueAccessor (...v) { return getValueAccessor(key)(...v) }\n })\n )\n\n if (bindingHandler.onValueChange) {\n dependencyDetection.ignore(() =>\n bindingHandler.computed('onValueChange')\n )\n }\n\n // Expose the bindings via domData.\n allBindingHandlers[key] = bindingHandler\n\n if (bindingHandler.controlsDescendants) {\n if (bindingHandlerThatControlsDescendantBindings !== undefined) { throw new Error('Multiple bindings (' + bindingHandlerThatControlsDescendantBindings + ' and ' + key + ') are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.') }\n bindingHandlerThatControlsDescendantBindings = key\n }\n\n if (bindingHandler.bindingCompleted instanceof Promise) {\n asyncBindingsApplied.add(bindingHandler.bindingCompleted)\n nodeAsyncBindingPromises.add(bindingHandler.bindingCompleted)\n }\n } catch (err) {\n reportBindingError('creation', err)\n }\n }\n\n triggerDescendantsComplete(node, bindings, nodeAsyncBindingPromises)\n }\n\n const shouldBindDescendants = bindingHandlerThatControlsDescendantBindings === undefined\n return { shouldBindDescendants }\n}\n\n/**\n *\n * @param {HTMLElement} node\n * @param {Object} bindings\n * @param {[Promise]} nodeAsyncBindingPromises\n */\nfunction triggerDescendantsComplete (node, bindings, nodeAsyncBindingPromises) {\n /** descendantsComplete ought to be an instance of the descendantsComplete\n * binding handler. */\n const hasBindingHandler = bindingEvent.descendantsComplete in bindings\n const hasFirstChild = virtualElements.firstChild(node)\n const accessor = hasBindingHandler && evaluateValueAccessor(bindings[bindingEvent.descendantsComplete])\n const callback = () => {\n bindingEvent.notify(node, bindingEvent.descendantsComplete)\n if (accessor && hasFirstChild) { accessor(node) }\n }\n if (nodeAsyncBindingPromises.size) {\n Promise.all(nodeAsyncBindingPromises).then(callback)\n } else {\n callback()\n }\n}\n\n\nfunction getBindingContext (viewModelOrBindingContext, extendContextCallback) {\n return viewModelOrBindingContext && (viewModelOrBindingContext instanceof bindingContext)\n ? viewModelOrBindingContext\n : new bindingContext(viewModelOrBindingContext, undefined, undefined, extendContextCallback)\n}\n\nexport function applyBindingAccessorsToNode (node, bindings, viewModelOrBindingContext, asyncBindingsApplied) {\n if (node.nodeType === 1) { // If it's an element, workaround IE <= 8 HTML parsing weirdness\n virtualElements.normaliseVirtualElementDomStructure(node)\n }\n return applyBindingsToNodeInternal(node, bindings, getBindingContext(viewModelOrBindingContext), asyncBindingsApplied)\n}\n\nexport function applyBindingsToNode (node, bindings, viewModelOrBindingContext) {\n const asyncBindingsApplied = new Set()\n const bindingContext = getBindingContext(viewModelOrBindingContext)\n const bindingAccessors = getBindingProvider().makeBindingAccessors(bindings, bindingContext, node)\n applyBindingAccessorsToNode(node, bindingAccessors, bindingContext, asyncBindingsApplied)\n return new BindingResult({asyncBindingsApplied, rootNode: node, bindingContext})\n}\n\nexport function applyBindingsToDescendants (viewModelOrBindingContext, rootNode) {\n const asyncBindingsApplied = new Set()\n if (rootNode.nodeType === 1 || rootNode.nodeType === 8) {\n const bindingContext = getBindingContext(viewModelOrBindingContext)\n applyBindingsToDescendantsInternal(bindingContext, rootNode, asyncBindingsApplied)\n return new BindingResult({asyncBindingsApplied, rootNode, bindingContext})\n }\n return new BindingResult({asyncBindingsApplied, rootNode})\n}\n\nexport function applyBindings (viewModelOrBindingContext, rootNode, extendContextCallback) {\n const asyncBindingsApplied = new Set()\n // If jQuery is loaded after Knockout, we won't initially have access to it. So save it here.\n if (!options.jQuery === undefined && options.jQuery) {\n options.jQuery = options.jQuery\n }\n\n // rootNode is optional\n if (!rootNode) {\n rootNode = window.document.body\n if (!rootNode) {\n throw Error('ko.applyBindings: could not find window.document.body; has the document been loaded?')\n }\n } else if (rootNode.nodeType !== 1 && rootNode.nodeType !== 8) {\n throw Error('ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node')\n }\n const rootContext = getBindingContext(viewModelOrBindingContext, extendContextCallback)\n applyBindingsToNodeAndDescendantsInternal(rootContext, rootNode, asyncBindingsApplied)\n return Promise.all(asyncBindingsApplied)\n}\n\nfunction onBindingError (spec) {\n var error, bindingText\n if (spec.bindingKey) {\n // During: 'init' or initial 'update'\n error = spec.errorCaptured\n spec.message = 'Unable to process binding \"' + spec.bindingKey +\n '\" in binding \"' + spec.bindingKey +\n '\"\\nMessage: ' + (error.message ? error.message : error)\n } else {\n // During: 'apply'\n error = spec.errorCaptured\n }\n try {\n extend(error, spec)\n } catch (e) {\n // Read-only error e.g. a DOMEXception.\n spec.stack = error.stack\n error = new Error(error.message ? error.message : error)\n extend(error, spec)\n }\n options.onError(error)\n}\n"],
5
+ "mappings": ";AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA;AAAA;AAAA;AAIA;AAAA;AAAA;AAKA,MAAM,wCAAwC;AAAA,EAM5C,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,YAAY;AACd;AAEA,8BAA+B;AAC7B,SAAO,QAAQ,wBAAwB,YAAY,QAAQ;AAC7D;AAEA,2BAA4B,UAAU,MAAM;AAC1C,QAAM,YAAY,SAAS,kBAAkB,CAAC,GAAG,GAAG,CAAC;AACrD,SAAO,UAAU,SAAS,KAAK,QAAQ;AACzC;AAEA,8BAA+B,SAAS,YAAY;AAClD,MAAI,CAAC,SAAS;AAAE;AAAA,EAAO;AACvB,SAAO,QAAQ,wBAAwB,UACnC,qBAAqB,eAAe,YAAY,OAAO;AAC7D;AAEA,wCAAyC,YAAY,YAAY;AAC/D,MAAI,CAAC,cAAc,OAAO,WAAW,sBAAsB,YAAY;AAAE;AAAA,EAAO;AAChF,SAAO,qBAAqB,WAAW,kBAAkB,UAAU,CAAC;AACtE;AAE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