@tko/observable 4.0.0-beta1.0 → 4.0.0
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.
- package/dist/Subscription.js +4 -5
- package/dist/Subscription.js.map +2 -2
- package/dist/defer.js +2 -1
- package/dist/defer.js.map +2 -2
- package/dist/dependencyDetection.js +11 -3
- package/dist/dependencyDetection.js.map +2 -2
- package/dist/extenders.js +12 -23
- package/dist/extenders.js.map +3 -3
- package/dist/index.cjs +346 -276
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +3 -9
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +3 -9
- package/dist/index.mjs.map +2 -2
- package/dist/mappingHelpers.js +14 -11
- package/dist/mappingHelpers.js.map +2 -2
- package/dist/observable.js +39 -13
- package/dist/observable.js.map +3 -3
- package/dist/observableArray.changeTracking.js +20 -21
- package/dist/observableArray.changeTracking.js.map +2 -2
- package/dist/observableArray.js +25 -27
- package/dist/observableArray.js.map +2 -2
- package/dist/subscribable.js +12 -17
- package/dist/subscribable.js.map +2 -2
- package/dist/subscribableSymbol.js +3 -2
- package/dist/subscribableSymbol.js.map +2 -2
- package/package.json +3 -4
- package/LICENSE +0 -22
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
// @tko/observable 🥊 4.0.0
|
|
1
|
+
// @tko/observable 🥊 4.0.0 CommonJS
|
|
2
|
+
"use strict";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,10 +21,42 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
18
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __await = function(promise, isYieldStar) {
|
|
25
|
+
this[0] = promise;
|
|
26
|
+
this[1] = isYieldStar;
|
|
27
|
+
};
|
|
28
|
+
var __yieldStar = (value) => {
|
|
29
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
30
|
+
if (obj == null) {
|
|
31
|
+
obj = value[__knownSymbol("iterator")]();
|
|
32
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
33
|
+
} else {
|
|
34
|
+
obj = obj.call(value);
|
|
35
|
+
method = (k) => it[k] = (v) => {
|
|
36
|
+
if (isAwait) {
|
|
37
|
+
isAwait = false;
|
|
38
|
+
if (k === "throw") throw v;
|
|
39
|
+
return v;
|
|
40
|
+
}
|
|
41
|
+
isAwait = true;
|
|
42
|
+
return {
|
|
43
|
+
done: false,
|
|
44
|
+
value: new __await(new Promise((resolve) => {
|
|
45
|
+
var x = obj[k](v);
|
|
46
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
47
|
+
resolve(x);
|
|
48
|
+
}), 1)
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
53
|
+
throw x;
|
|
54
|
+
}, "return" in obj && method("return"), it;
|
|
55
|
+
};
|
|
19
56
|
|
|
20
57
|
// index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
58
|
+
var index_exports = {};
|
|
59
|
+
__export(index_exports, {
|
|
23
60
|
LATEST_VALUE: () => LATEST_VALUE,
|
|
24
61
|
applyExtenders: () => applyExtenders,
|
|
25
62
|
arrayChangeEventName: () => arrayChangeEventName,
|
|
@@ -41,13 +78,13 @@ __export(observable_exports, {
|
|
|
41
78
|
unwrap: () => unwrap,
|
|
42
79
|
valuesArePrimitiveAndEqual: () => valuesArePrimitiveAndEqual
|
|
43
80
|
});
|
|
44
|
-
module.exports = __toCommonJS(
|
|
81
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
82
|
|
|
46
83
|
// ../utils/dist/array.js
|
|
47
84
|
var { isArray } = Array;
|
|
48
|
-
function arrayForEach(array, action,
|
|
85
|
+
function arrayForEach(array, action, actionOwner) {
|
|
49
86
|
if (arguments.length > 2) {
|
|
50
|
-
action = action.bind(
|
|
87
|
+
action = action.bind(actionOwner);
|
|
51
88
|
}
|
|
52
89
|
for (let i = 0, j = array.length; i < j; ++i) {
|
|
53
90
|
action(array[i], i, array);
|
|
@@ -57,7 +94,7 @@ function arrayIndexOf(array, item) {
|
|
|
57
94
|
return (isArray(array) ? array : [...array]).indexOf(item);
|
|
58
95
|
}
|
|
59
96
|
function arrayRemoveItem(array, itemToRemove) {
|
|
60
|
-
|
|
97
|
+
const index = arrayIndexOf(array, itemToRemove);
|
|
61
98
|
if (index > 0) {
|
|
62
99
|
array.splice(index, 1);
|
|
63
100
|
} else if (index === 0) {
|
|
@@ -66,7 +103,7 @@ function arrayRemoveItem(array, itemToRemove) {
|
|
|
66
103
|
}
|
|
67
104
|
function findMovesInArrayComparison(left, right, limitFailedCompares) {
|
|
68
105
|
if (left.length && right.length) {
|
|
69
|
-
|
|
106
|
+
let failedCompares, l, r, leftItem, rightItem;
|
|
70
107
|
for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {
|
|
71
108
|
for (r = 0; rightItem = right[r]; ++r) {
|
|
72
109
|
if (leftItem.value === rightItem.value) {
|
|
@@ -94,10 +131,10 @@ function compareArrays(oldArray, newArray, options2) {
|
|
|
94
131
|
}
|
|
95
132
|
}
|
|
96
133
|
function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusNotInBig, options2) {
|
|
97
|
-
|
|
134
|
+
let myMin = Math.min, myMax = Math.max, editDistanceMatrix = new Array(), smlIndex, smlIndexMax = smlArray.length, bigIndex, bigIndexMax = bigArray.length, compareRange = bigIndexMax - smlIndexMax || 1, maxDistance = smlIndexMax + bigIndexMax + 1, thisRow, lastRow, bigIndexMaxForRow, bigIndexMinForRow;
|
|
98
135
|
for (smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
|
|
99
136
|
lastRow = thisRow;
|
|
100
|
-
editDistanceMatrix.push(thisRow =
|
|
137
|
+
editDistanceMatrix.push(thisRow = new Array());
|
|
101
138
|
bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
|
|
102
139
|
bigIndexMinForRow = myMax(0, smlIndex - 1);
|
|
103
140
|
for (bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
|
|
@@ -108,35 +145,38 @@ function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusN
|
|
|
108
145
|
} else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1]) {
|
|
109
146
|
thisRow[bigIndex] = lastRow[bigIndex - 1];
|
|
110
147
|
} else {
|
|
111
|
-
|
|
112
|
-
|
|
148
|
+
const northDistance = lastRow[bigIndex] || maxDistance;
|
|
149
|
+
const westDistance = thisRow[bigIndex - 1] || maxDistance;
|
|
113
150
|
thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
|
|
114
151
|
}
|
|
115
152
|
}
|
|
116
153
|
}
|
|
117
|
-
|
|
154
|
+
let editScript = new Array(), meMinusOne, notInSml = new Array(), notInBig = new Array();
|
|
118
155
|
for (smlIndex = smlIndexMax, bigIndex = bigIndexMax; smlIndex || bigIndex; ) {
|
|
119
156
|
meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
|
|
120
157
|
if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {
|
|
121
|
-
notInSml.push(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
158
|
+
notInSml.push(
|
|
159
|
+
editScript[editScript.length] = {
|
|
160
|
+
// added
|
|
161
|
+
status: statusNotInSml,
|
|
162
|
+
value: bigArray[--bigIndex],
|
|
163
|
+
index: bigIndex
|
|
164
|
+
}
|
|
165
|
+
);
|
|
126
166
|
} else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
|
|
127
|
-
notInBig.push(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
167
|
+
notInBig.push(
|
|
168
|
+
editScript[editScript.length] = {
|
|
169
|
+
// deleted
|
|
170
|
+
status: statusNotInBig,
|
|
171
|
+
value: smlArray[--smlIndex],
|
|
172
|
+
index: smlIndex
|
|
173
|
+
}
|
|
174
|
+
);
|
|
132
175
|
} else {
|
|
133
176
|
--bigIndex;
|
|
134
177
|
--smlIndex;
|
|
135
|
-
if (!options2.sparse) {
|
|
136
|
-
editScript.push({
|
|
137
|
-
"status": "retained",
|
|
138
|
-
"value": bigArray[bigIndex]
|
|
139
|
-
});
|
|
178
|
+
if (!(options2 == null ? void 0 : options2.sparse)) {
|
|
179
|
+
editScript.push({ status: "retained", value: bigArray[bigIndex] });
|
|
140
180
|
}
|
|
141
181
|
}
|
|
142
182
|
}
|
|
@@ -145,40 +185,79 @@ function compareSmallArrayToBigArray(smlArray, bigArray, statusNotInSml, statusN
|
|
|
145
185
|
}
|
|
146
186
|
|
|
147
187
|
// ../utils/dist/options.js
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
getBindingHandler() {
|
|
173
|
-
},
|
|
174
|
-
cleanExternalData() {
|
|
188
|
+
var Options = class {
|
|
189
|
+
constructor() {
|
|
190
|
+
this.bindingStringPreparsers = [];
|
|
191
|
+
this.knockoutInstance = null;
|
|
192
|
+
this.deferUpdates = false;
|
|
193
|
+
this.useOnlyNativeEvents = true;
|
|
194
|
+
this.useTemplateTag = true;
|
|
195
|
+
this.protoProperty = "__ko_proto__";
|
|
196
|
+
this.defaultBindingAttribute = "data-bind";
|
|
197
|
+
this.allowVirtualElements = true;
|
|
198
|
+
this.bindingGlobals = /* @__PURE__ */ Object.create(null);
|
|
199
|
+
this.createChildContextWithAs = false;
|
|
200
|
+
this.disableJQueryUsage = false;
|
|
201
|
+
this.Promise = globalThis.Promise;
|
|
202
|
+
this.taskScheduler = null;
|
|
203
|
+
this.debug = false;
|
|
204
|
+
this.templateSizeLimit = 4096;
|
|
205
|
+
this.allowScriptTagsInTemplates = false;
|
|
206
|
+
this._sanitizeWarningLogged = false;
|
|
207
|
+
this.global = globalThis;
|
|
208
|
+
this.document = globalThis.document;
|
|
209
|
+
this.filters = {};
|
|
210
|
+
this.includeDestroyed = false;
|
|
211
|
+
this.foreachHidesDestroyed = false;
|
|
175
212
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return
|
|
213
|
+
get jQuery() {
|
|
214
|
+
var _a;
|
|
215
|
+
if (this.disableJQueryUsage) return;
|
|
216
|
+
return (_a = this._jQuery) != null ? _a : globalThis.jQuery;
|
|
180
217
|
}
|
|
181
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Set jQuery manuall to be used by TKO.
|
|
220
|
+
* @param jQuery If jQuery set to undefined, TKO will not use jQuery and this.disableJQueryUsage to true.
|
|
221
|
+
*/
|
|
222
|
+
set jQuery(jQuery) {
|
|
223
|
+
if (!jQuery) {
|
|
224
|
+
this.disableJQueryUsage = true;
|
|
225
|
+
this._jQuery = void 0;
|
|
226
|
+
} else {
|
|
227
|
+
this._jQuery = jQuery;
|
|
228
|
+
this.disableJQueryUsage = false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Sanitize HTML templates before parsing them. Default is a no-op.
|
|
233
|
+
* Please configure something like DOMPurify or validator.js for your environment.
|
|
234
|
+
* @param html HTML string to be sanitized
|
|
235
|
+
* @returns Sanitized HTML string
|
|
236
|
+
*/
|
|
237
|
+
sanitizeHtmlTemplate(html) {
|
|
238
|
+
if (!this._sanitizeWarningLogged) {
|
|
239
|
+
console.warn(
|
|
240
|
+
"WARNING -- You don't have a HTML sanitizer configured. Please configure options.sanitizeHtmlTemplate to avoid XSS vulnerabilities."
|
|
241
|
+
);
|
|
242
|
+
this._sanitizeWarningLogged = true;
|
|
243
|
+
}
|
|
244
|
+
return html;
|
|
245
|
+
}
|
|
246
|
+
onError(e, throws = true) {
|
|
247
|
+
if (throws) throw e;
|
|
248
|
+
return e;
|
|
249
|
+
}
|
|
250
|
+
set(name, value) {
|
|
251
|
+
this[name] = value;
|
|
252
|
+
}
|
|
253
|
+
// Overload getBindingHandler to have a custom lookup function.
|
|
254
|
+
getBindingHandler(key) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
cleanExternalData(node, callback) {
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
var options = new Options();
|
|
182
261
|
var options_default = options;
|
|
183
262
|
|
|
184
263
|
// ../utils/dist/error.js
|
|
@@ -205,7 +284,7 @@ function safeSetTimeout(handler, timeout) {
|
|
|
205
284
|
|
|
206
285
|
// ../utils/dist/async.js
|
|
207
286
|
function throttle(callback, timeout) {
|
|
208
|
-
|
|
287
|
+
let timeoutInstance;
|
|
209
288
|
return function(...args) {
|
|
210
289
|
if (!timeoutInstance) {
|
|
211
290
|
timeoutInstance = safeSetTimeout(function() {
|
|
@@ -216,33 +295,22 @@ function throttle(callback, timeout) {
|
|
|
216
295
|
};
|
|
217
296
|
}
|
|
218
297
|
function debounce(callback, timeout) {
|
|
219
|
-
|
|
298
|
+
let timeoutInstance;
|
|
220
299
|
return function(...args) {
|
|
221
300
|
clearTimeout(timeoutInstance);
|
|
222
301
|
timeoutInstance = safeSetTimeout(() => callback(...args), timeout);
|
|
223
302
|
};
|
|
224
303
|
}
|
|
225
304
|
|
|
226
|
-
// ../utils/dist/ie.js
|
|
227
|
-
var ieVersion = options_default.document && function() {
|
|
228
|
-
var version = 3, div = options_default.document.createElement("div"), iElems = div.getElementsByTagName("i");
|
|
229
|
-
while (div.innerHTML = "<!--[if gt IE " + ++version + "]><i></i><![endif]-->", iElems[0]) {
|
|
230
|
-
}
|
|
231
|
-
if (!version) {
|
|
232
|
-
const userAgent = window.navigator.userAgent;
|
|
233
|
-
return ua.match(/MSIE ([^ ]+)/) || ua.match(/rv:([^ )]+)/);
|
|
234
|
-
}
|
|
235
|
-
return version > 4 ? version : void 0;
|
|
236
|
-
}();
|
|
237
|
-
|
|
238
305
|
// ../utils/dist/object.js
|
|
239
306
|
function hasOwnProperty(obj, propName) {
|
|
240
307
|
return Object.prototype.hasOwnProperty.call(obj, propName);
|
|
241
308
|
}
|
|
242
309
|
function extend(target, source) {
|
|
243
310
|
if (source) {
|
|
244
|
-
for (
|
|
311
|
+
for (const prop of Object.keys(source)) {
|
|
245
312
|
if (hasOwnProperty(source, prop)) {
|
|
313
|
+
;
|
|
246
314
|
target[prop] = source[prop];
|
|
247
315
|
}
|
|
248
316
|
}
|
|
@@ -250,7 +318,7 @@ function extend(target, source) {
|
|
|
250
318
|
return target;
|
|
251
319
|
}
|
|
252
320
|
function objectForEach(obj, action) {
|
|
253
|
-
for (
|
|
321
|
+
for (const prop in obj) {
|
|
254
322
|
if (hasOwnProperty(obj, prop)) {
|
|
255
323
|
action(prop, obj[prop]);
|
|
256
324
|
}
|
|
@@ -274,78 +342,75 @@ function overwriteLengthPropertyIfSupported(fn, descriptor) {
|
|
|
274
342
|
}
|
|
275
343
|
}
|
|
276
344
|
|
|
277
|
-
// ../utils/dist/jquery.js
|
|
278
|
-
var jQueryInstance = options_default.global && options_default.global.jQuery;
|
|
279
|
-
|
|
280
345
|
// ../utils/dist/dom/info.js
|
|
281
346
|
function tagNameLower(element) {
|
|
282
347
|
return element && element.tagName && element.tagName.toLowerCase();
|
|
283
348
|
}
|
|
284
349
|
|
|
350
|
+
// ../utils/dist/dom/event.js
|
|
351
|
+
var knownEvents = {};
|
|
352
|
+
var knownEventTypesByEventName = {};
|
|
353
|
+
knownEvents["UIEvents"] = ["keyup", "keydown", "keypress"];
|
|
354
|
+
knownEvents["MouseEvents"] = [
|
|
355
|
+
"click",
|
|
356
|
+
"dblclick",
|
|
357
|
+
"mousedown",
|
|
358
|
+
"mouseup",
|
|
359
|
+
"mousemove",
|
|
360
|
+
"mouseover",
|
|
361
|
+
"mouseout",
|
|
362
|
+
"mouseenter",
|
|
363
|
+
"mouseleave"
|
|
364
|
+
];
|
|
365
|
+
objectForEach(knownEvents, function(eventType, knownEventsForType) {
|
|
366
|
+
if (knownEventsForType.length) {
|
|
367
|
+
for (let i = 0, j = knownEventsForType.length; i < j; i++) {
|
|
368
|
+
knownEventTypesByEventName[knownEventsForType[i]] = eventType;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
285
373
|
// ../utils/dist/dom/data.js
|
|
286
|
-
var datastoreTime = new Date().getTime();
|
|
374
|
+
var datastoreTime = (/* @__PURE__ */ new Date()).getTime();
|
|
287
375
|
var dataStoreKeyExpandoPropertyName = `__ko__${datastoreTime}`;
|
|
288
|
-
var dataStoreSymbol = Symbol("Knockout data");
|
|
289
|
-
var dataStore;
|
|
376
|
+
var dataStoreSymbol = /* @__PURE__ */ Symbol("Knockout data");
|
|
290
377
|
var uniqueId = 0;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
},
|
|
299
|
-
clear(node) {
|
|
300
|
-
if (node[dataStoreSymbol]) {
|
|
301
|
-
delete node[dataStoreSymbol];
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
var IE = {
|
|
308
|
-
getDataforNode(node, createIfNotFound) {
|
|
309
|
-
let dataStoreKey = node[dataStoreKeyExpandoPropertyName];
|
|
310
|
-
const hasExistingDataStore = dataStoreKey && dataStoreKey !== "null" && dataStore[dataStoreKey];
|
|
311
|
-
if (!hasExistingDataStore) {
|
|
312
|
-
if (!createIfNotFound) {
|
|
313
|
-
return void 0;
|
|
314
|
-
}
|
|
315
|
-
dataStoreKey = node[dataStoreKeyExpandoPropertyName] = "ko" + uniqueId++;
|
|
316
|
-
dataStore[dataStoreKey] = {};
|
|
317
|
-
}
|
|
318
|
-
return dataStore[dataStoreKey];
|
|
319
|
-
},
|
|
320
|
-
clear(node) {
|
|
321
|
-
const dataStoreKey = node[dataStoreKeyExpandoPropertyName];
|
|
322
|
-
if (dataStoreKey) {
|
|
323
|
-
delete dataStore[dataStoreKey];
|
|
324
|
-
node[dataStoreKeyExpandoPropertyName] = null;
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
return false;
|
|
378
|
+
function isSafeKey(key) {
|
|
379
|
+
return key !== "__proto__" && key !== "constructor" && key !== "prototype";
|
|
380
|
+
}
|
|
381
|
+
function getDataForNode(node, createIfNotFound) {
|
|
382
|
+
let dataForNode = node[dataStoreSymbol];
|
|
383
|
+
if (!dataForNode && createIfNotFound) {
|
|
384
|
+
dataForNode = node[dataStoreSymbol] = {};
|
|
328
385
|
}
|
|
329
|
-
|
|
330
|
-
|
|
386
|
+
return dataForNode;
|
|
387
|
+
}
|
|
331
388
|
function nextKey() {
|
|
332
389
|
return uniqueId++ + dataStoreKeyExpandoPropertyName;
|
|
333
390
|
}
|
|
334
391
|
function get(node, key) {
|
|
392
|
+
if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key);
|
|
335
393
|
const dataForNode = getDataForNode(node, false);
|
|
336
394
|
return dataForNode && dataForNode[key];
|
|
337
395
|
}
|
|
338
396
|
function set(node, key, value) {
|
|
339
|
-
|
|
340
|
-
|
|
397
|
+
if (!isSafeKey(key)) throw new Error("Unsafe key for DOM data: " + key);
|
|
398
|
+
const dataForNode = getDataForNode(
|
|
399
|
+
node,
|
|
400
|
+
value !== void 0
|
|
401
|
+
/* createIfNotFound */
|
|
402
|
+
);
|
|
403
|
+
if (dataForNode) {
|
|
404
|
+
dataForNode[key] = value;
|
|
405
|
+
}
|
|
341
406
|
}
|
|
342
407
|
|
|
343
408
|
// ../utils/dist/dom/disposal.js
|
|
344
409
|
var domDataKey = nextKey();
|
|
345
410
|
function getDisposeCallbacksCollection(node, createIfNotFound) {
|
|
346
|
-
|
|
411
|
+
let allDisposeCallbacks = get(node, domDataKey);
|
|
347
412
|
if (allDisposeCallbacks === void 0 && createIfNotFound) {
|
|
348
|
-
allDisposeCallbacks =
|
|
413
|
+
allDisposeCallbacks = new Array();
|
|
349
414
|
set(node, domDataKey, allDisposeCallbacks);
|
|
350
415
|
}
|
|
351
416
|
return allDisposeCallbacks;
|
|
@@ -360,7 +425,7 @@ function addDisposeCallback(node, callback) {
|
|
|
360
425
|
getDisposeCallbacksCollection(node, true).push(callback);
|
|
361
426
|
}
|
|
362
427
|
function removeDisposeCallback(node, callback) {
|
|
363
|
-
|
|
428
|
+
const callbacksCollection = getDisposeCallbacksCollection(node, false);
|
|
364
429
|
if (callbacksCollection) {
|
|
365
430
|
arrayRemoveItem(callbacksCollection, callback);
|
|
366
431
|
if (callbacksCollection.length === 0) {
|
|
@@ -368,58 +433,34 @@ function removeDisposeCallback(node, callback) {
|
|
|
368
433
|
}
|
|
369
434
|
}
|
|
370
435
|
}
|
|
371
|
-
var otherNodeCleanerFunctions =
|
|
436
|
+
var otherNodeCleanerFunctions = new Array();
|
|
372
437
|
function cleanjQueryData(node) {
|
|
373
|
-
|
|
438
|
+
const jQueryCleanNodeFn = options_default.jQuery ? options_default.jQuery.cleanData : null;
|
|
374
439
|
if (jQueryCleanNodeFn) {
|
|
375
440
|
jQueryCleanNodeFn([node]);
|
|
376
441
|
}
|
|
377
442
|
}
|
|
378
443
|
otherNodeCleanerFunctions.push(cleanjQueryData);
|
|
379
444
|
|
|
380
|
-
// ../utils/dist/dom/event.js
|
|
381
|
-
var knownEvents = {};
|
|
382
|
-
var knownEventTypesByEventName = {};
|
|
383
|
-
var keyEventTypeName = options_default.global.navigator && /Firefox\/2/i.test(options_default.global.navigator.userAgent) ? "KeyboardEvent" : "UIEvents";
|
|
384
|
-
knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"];
|
|
385
|
-
knownEvents["MouseEvents"] = [
|
|
386
|
-
"click",
|
|
387
|
-
"dblclick",
|
|
388
|
-
"mousedown",
|
|
389
|
-
"mouseup",
|
|
390
|
-
"mousemove",
|
|
391
|
-
"mouseover",
|
|
392
|
-
"mouseout",
|
|
393
|
-
"mouseenter",
|
|
394
|
-
"mouseleave"
|
|
395
|
-
];
|
|
396
|
-
objectForEach(knownEvents, function(eventType, knownEventsForType) {
|
|
397
|
-
if (knownEventsForType.length) {
|
|
398
|
-
for (var i = 0, j = knownEventsForType.length; i < j; i++) {
|
|
399
|
-
knownEventTypesByEventName[knownEventsForType[i]] = eventType;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// ../utils/dist/dom/virtualElements.js
|
|
405
|
-
var commentNodesHaveTextProperty = options_default.document && options_default.document.createComment("test").text === "<!--test-->";
|
|
406
|
-
|
|
407
445
|
// ../utils/dist/dom/html.js
|
|
408
|
-
var supportsTemplateTag = options_default.document && "content" in options_default.document.createElement("template");
|
|
446
|
+
var supportsTemplateTag = options_default.useTemplateTag && options_default.document && "content" in options_default.document.createElement("template");
|
|
409
447
|
|
|
410
448
|
// ../utils/dist/dom/selectExtensions.js
|
|
411
|
-
var hasDomDataExpandoProperty = Symbol("Knockout selectExtensions hasDomDataProperty");
|
|
449
|
+
var hasDomDataExpandoProperty = /* @__PURE__ */ Symbol("Knockout selectExtensions hasDomDataProperty");
|
|
412
450
|
var selectExtensions = {
|
|
413
451
|
optionValueDomDataKey: nextKey(),
|
|
414
452
|
readValue: function(element) {
|
|
415
453
|
switch (tagNameLower(element)) {
|
|
416
|
-
case "option":
|
|
454
|
+
case "option": {
|
|
417
455
|
if (element[hasDomDataExpandoProperty] === true) {
|
|
418
456
|
return get(element, selectExtensions.optionValueDomDataKey);
|
|
419
457
|
}
|
|
420
458
|
return element.value;
|
|
421
|
-
|
|
422
|
-
|
|
459
|
+
}
|
|
460
|
+
case "select": {
|
|
461
|
+
const selectElement = element;
|
|
462
|
+
return selectElement.selectedIndex >= 0 ? selectExtensions.readValue(selectElement.options[selectElement.selectedIndex]) : void 0;
|
|
463
|
+
}
|
|
423
464
|
default:
|
|
424
465
|
return element.value;
|
|
425
466
|
}
|
|
@@ -432,36 +473,42 @@ var selectExtensions = {
|
|
|
432
473
|
if (hasDomDataExpandoProperty in element) {
|
|
433
474
|
delete element[hasDomDataExpandoProperty];
|
|
434
475
|
}
|
|
476
|
+
;
|
|
435
477
|
element.value = value;
|
|
436
478
|
} else {
|
|
479
|
+
const el = element;
|
|
437
480
|
set(element, selectExtensions.optionValueDomDataKey, value);
|
|
438
|
-
|
|
439
|
-
|
|
481
|
+
el[hasDomDataExpandoProperty] = true;
|
|
482
|
+
el.value = typeof value === "number" ? value : "";
|
|
440
483
|
}
|
|
441
484
|
break;
|
|
442
485
|
case "select":
|
|
443
|
-
|
|
444
|
-
value
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
486
|
+
{
|
|
487
|
+
if (value === "" || value === null) {
|
|
488
|
+
value = void 0;
|
|
489
|
+
}
|
|
490
|
+
let selection = -1;
|
|
491
|
+
const selectElement = element;
|
|
492
|
+
for (let i = 0, n = selectElement.options.length, optionValue; i < n; ++i) {
|
|
493
|
+
optionValue = selectExtensions.readValue(selectElement.options[i]);
|
|
494
|
+
const strictEqual = optionValue === value;
|
|
495
|
+
const blankEqual = optionValue === "" && value === void 0;
|
|
496
|
+
const numericEqual = typeof value === "number" && Number(optionValue) === value;
|
|
497
|
+
if (strictEqual || blankEqual || numericEqual) {
|
|
498
|
+
selection = i;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (allowUnset || selection >= 0 || value === void 0 && selectElement.size > 1) {
|
|
503
|
+
selectElement.selectedIndex = selection;
|
|
455
504
|
}
|
|
456
|
-
}
|
|
457
|
-
if (allowUnset || selection >= 0 || value === void 0 && element.size > 1) {
|
|
458
|
-
element.selectedIndex = selection;
|
|
459
505
|
}
|
|
460
506
|
break;
|
|
461
507
|
default:
|
|
462
508
|
if (value === null || value === void 0) {
|
|
463
509
|
value = "";
|
|
464
510
|
}
|
|
511
|
+
;
|
|
465
512
|
element.value = value;
|
|
466
513
|
break;
|
|
467
514
|
}
|
|
@@ -476,30 +523,19 @@ __export(tasks_exports, {
|
|
|
476
523
|
runEarly: () => processTasks,
|
|
477
524
|
schedule: () => schedule
|
|
478
525
|
});
|
|
479
|
-
var taskQueue =
|
|
526
|
+
var taskQueue = new Array();
|
|
480
527
|
var taskQueueLength = 0;
|
|
481
528
|
var nextHandle = 1;
|
|
482
529
|
var nextIndexToProcess = 0;
|
|
483
530
|
var w = options_default.global;
|
|
484
531
|
if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {
|
|
485
|
-
options_default.taskScheduler = function(callback) {
|
|
486
|
-
|
|
532
|
+
options_default.taskScheduler = (function(callback) {
|
|
533
|
+
const div = w.document.createElement("div");
|
|
487
534
|
new w.MutationObserver(callback).observe(div, { attributes: true });
|
|
488
535
|
return function() {
|
|
489
536
|
div.classList.toggle("foo");
|
|
490
537
|
};
|
|
491
|
-
}(scheduledProcess);
|
|
492
|
-
} else if (w && w.document && "onreadystatechange" in w.document.createElement("script")) {
|
|
493
|
-
options_default.taskScheduler = function(callback) {
|
|
494
|
-
var script = document.createElement("script");
|
|
495
|
-
script.onreadystatechange = function() {
|
|
496
|
-
script.onreadystatechange = null;
|
|
497
|
-
document.documentElement.removeChild(script);
|
|
498
|
-
script = null;
|
|
499
|
-
callback();
|
|
500
|
-
};
|
|
501
|
-
document.documentElement.appendChild(script);
|
|
502
|
-
};
|
|
538
|
+
})(scheduledProcess);
|
|
503
539
|
} else {
|
|
504
540
|
options_default.taskScheduler = function(callback) {
|
|
505
541
|
setTimeout(callback, 0);
|
|
@@ -507,8 +543,8 @@ if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {
|
|
|
507
543
|
}
|
|
508
544
|
function processTasks() {
|
|
509
545
|
if (taskQueueLength) {
|
|
510
|
-
|
|
511
|
-
for (
|
|
546
|
+
let mark = taskQueueLength, countMarks = 0;
|
|
547
|
+
for (let task; nextIndexToProcess < taskQueueLength; ) {
|
|
512
548
|
if (task = taskQueue[nextIndexToProcess++]) {
|
|
513
549
|
if (nextIndexToProcess > mark) {
|
|
514
550
|
if (++countMarks >= 5e3) {
|
|
@@ -542,13 +578,13 @@ function schedule(func) {
|
|
|
542
578
|
return nextHandle++;
|
|
543
579
|
}
|
|
544
580
|
function cancel(handle) {
|
|
545
|
-
|
|
581
|
+
const index = handle - (nextHandle - taskQueueLength);
|
|
546
582
|
if (index >= nextIndexToProcess && index < taskQueueLength) {
|
|
547
583
|
taskQueue[index] = null;
|
|
548
584
|
}
|
|
549
585
|
}
|
|
550
586
|
function resetForTesting() {
|
|
551
|
-
|
|
587
|
+
const length = taskQueueLength - nextIndexToProcess;
|
|
552
588
|
nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
|
|
553
589
|
return length;
|
|
554
590
|
}
|
|
@@ -567,13 +603,13 @@ __export(dependencyDetection_exports, {
|
|
|
567
603
|
});
|
|
568
604
|
|
|
569
605
|
// src/subscribableSymbol.ts
|
|
570
|
-
var SUBSCRIBABLE_SYM = Symbol("Knockout Subscribable");
|
|
606
|
+
var SUBSCRIBABLE_SYM = /* @__PURE__ */ Symbol("Knockout Subscribable");
|
|
571
607
|
function isSubscribable(instance) {
|
|
572
608
|
return instance && instance[SUBSCRIBABLE_SYM] || false;
|
|
573
609
|
}
|
|
574
610
|
|
|
575
611
|
// src/dependencyDetection.ts
|
|
576
|
-
var outerFrames =
|
|
612
|
+
var outerFrames = new Array();
|
|
577
613
|
var currentFrame;
|
|
578
614
|
var lastId = 0;
|
|
579
615
|
function getId() {
|
|
@@ -591,7 +627,11 @@ function registerDependency(subscribable2) {
|
|
|
591
627
|
if (!isSubscribable(subscribable2)) {
|
|
592
628
|
throw new Error("Only subscribable things can act as dependencies");
|
|
593
629
|
}
|
|
594
|
-
currentFrame.callback.call(
|
|
630
|
+
currentFrame.callback.call(
|
|
631
|
+
currentFrame.callbackTarget,
|
|
632
|
+
subscribable2,
|
|
633
|
+
subscribable2._id || (subscribable2._id = getId())
|
|
634
|
+
);
|
|
595
635
|
}
|
|
596
636
|
}
|
|
597
637
|
function ignore(callback, callbackTarget, callbackArgs) {
|
|
@@ -606,16 +646,19 @@ function getDependenciesCount() {
|
|
|
606
646
|
if (currentFrame) {
|
|
607
647
|
return currentFrame.computed.getDependenciesCount();
|
|
608
648
|
}
|
|
649
|
+
return void 0;
|
|
609
650
|
}
|
|
610
651
|
function getDependencies() {
|
|
611
652
|
if (currentFrame) {
|
|
612
653
|
return currentFrame.computed.getDependencies();
|
|
613
654
|
}
|
|
655
|
+
return void 0;
|
|
614
656
|
}
|
|
615
657
|
function isInitial() {
|
|
616
658
|
if (currentFrame) {
|
|
617
659
|
return currentFrame.isInitial;
|
|
618
660
|
}
|
|
661
|
+
return void 0;
|
|
619
662
|
}
|
|
620
663
|
|
|
621
664
|
// src/defer.ts
|
|
@@ -662,6 +705,7 @@ var Subscription = class {
|
|
|
662
705
|
this._node = node;
|
|
663
706
|
addDisposeCallback(node, this._domNodeDisposalCallback = this.dispose.bind(this));
|
|
664
707
|
}
|
|
708
|
+
// TC39 Observable API
|
|
665
709
|
unsubscribe() {
|
|
666
710
|
this.dispose();
|
|
667
711
|
}
|
|
@@ -671,21 +715,16 @@ var Subscription = class {
|
|
|
671
715
|
};
|
|
672
716
|
|
|
673
717
|
// src/extenders.ts
|
|
674
|
-
var primitiveTypes = {
|
|
675
|
-
"undefined": 1,
|
|
676
|
-
"boolean": 1,
|
|
677
|
-
"number": 1,
|
|
678
|
-
"string": 1
|
|
679
|
-
};
|
|
718
|
+
var primitiveTypes = { undefined: 1, boolean: 1, number: 1, string: 1 };
|
|
680
719
|
function valuesArePrimitiveAndEqual(a, b) {
|
|
681
|
-
|
|
720
|
+
const oldValueIsPrimitive = a === null || typeof a in primitiveTypes;
|
|
682
721
|
return oldValueIsPrimitive ? a === b : false;
|
|
683
722
|
}
|
|
684
723
|
function applyExtenders(requestedExtenders) {
|
|
685
|
-
|
|
724
|
+
let target = this;
|
|
686
725
|
if (requestedExtenders) {
|
|
687
726
|
objectForEach(requestedExtenders, function(key, value) {
|
|
688
|
-
|
|
727
|
+
const extenderHandler = extenders[key];
|
|
689
728
|
if (typeof extenderHandler === "function") {
|
|
690
729
|
target = extenderHandler(target, value) || target;
|
|
691
730
|
} else {
|
|
@@ -700,12 +739,14 @@ function notify(target, notifyWhen) {
|
|
|
700
739
|
}
|
|
701
740
|
function deferred(target, option) {
|
|
702
741
|
if (option !== true) {
|
|
703
|
-
throw new Error(
|
|
742
|
+
throw new Error(
|
|
743
|
+
"The 'deferred' extender only accepts the value 'true', because it is not supported to turn deferral off once enabled."
|
|
744
|
+
);
|
|
704
745
|
}
|
|
705
746
|
deferUpdates(target);
|
|
706
747
|
}
|
|
707
748
|
function rateLimit(target, options2) {
|
|
708
|
-
|
|
749
|
+
let timeout, method, limitFunction;
|
|
709
750
|
if (typeof options2 === "number") {
|
|
710
751
|
timeout = options2;
|
|
711
752
|
} else {
|
|
@@ -718,21 +759,17 @@ function rateLimit(target, options2) {
|
|
|
718
759
|
return limitFunction(callback, timeout);
|
|
719
760
|
});
|
|
720
761
|
}
|
|
721
|
-
var extenders = {
|
|
722
|
-
notify,
|
|
723
|
-
deferred,
|
|
724
|
-
rateLimit
|
|
725
|
-
};
|
|
762
|
+
var extenders = { notify, deferred, rateLimit };
|
|
726
763
|
|
|
727
764
|
// src/subscribable.ts
|
|
728
|
-
var LATEST_VALUE = Symbol("Knockout latest value");
|
|
765
|
+
var LATEST_VALUE = /* @__PURE__ */ Symbol("Knockout latest value");
|
|
729
766
|
if (!Symbol.observable) {
|
|
730
|
-
Symbol.observable = Symbol.for("@tko/Symbol.observable");
|
|
767
|
+
Symbol.observable = /* @__PURE__ */ Symbol.for("@tko/Symbol.observable");
|
|
731
768
|
}
|
|
732
|
-
function
|
|
769
|
+
var subscribable = function subscribableFactory() {
|
|
733
770
|
Object.setPrototypeOf(this, ko_subscribable_fn);
|
|
734
771
|
ko_subscribable_fn.init(this);
|
|
735
|
-
}
|
|
772
|
+
};
|
|
736
773
|
var defaultEvent = "change";
|
|
737
774
|
var ko_subscribable_fn = {
|
|
738
775
|
[SUBSCRIBABLE_SYM]: true,
|
|
@@ -746,9 +783,7 @@ var ko_subscribable_fn = {
|
|
|
746
783
|
subscribe(callback, callbackTarget, event) {
|
|
747
784
|
const isTC39Callback = typeof callback === "object" && callback.next;
|
|
748
785
|
event = event || defaultEvent;
|
|
749
|
-
const observer = isTC39Callback ? callback : {
|
|
750
|
-
next: callbackTarget ? callback.bind(callbackTarget) : callback
|
|
751
|
-
};
|
|
786
|
+
const observer = isTC39Callback ? callback : { next: callbackTarget ? callback.bind(callbackTarget) : callback };
|
|
752
787
|
const subscriptionInstance = new Subscription(this, observer, () => {
|
|
753
788
|
arrayRemoveItem(this._subscriptions[event], subscriptionInstance);
|
|
754
789
|
if (this.afterSubscriptionRemove) {
|
|
@@ -759,7 +794,7 @@ var ko_subscribable_fn = {
|
|
|
759
794
|
this.beforeSubscriptionAdd(event);
|
|
760
795
|
}
|
|
761
796
|
if (!this._subscriptions[event]) {
|
|
762
|
-
this._subscriptions[event] =
|
|
797
|
+
this._subscriptions[event] = new Array();
|
|
763
798
|
}
|
|
764
799
|
this._subscriptions[event].push(subscriptionInstance);
|
|
765
800
|
if (isTC39Callback && LATEST_VALUE in this) {
|
|
@@ -802,7 +837,7 @@ var ko_subscribable_fn = {
|
|
|
802
837
|
if (event) {
|
|
803
838
|
return this._subscriptions[event] && this._subscriptions[event].length || 0;
|
|
804
839
|
} else {
|
|
805
|
-
|
|
840
|
+
let total = 0;
|
|
806
841
|
objectForEach(this._subscriptions, function(eventName, subscriptions) {
|
|
807
842
|
if (eventName !== "dirty") {
|
|
808
843
|
total += subscriptions.length;
|
|
@@ -857,6 +892,7 @@ function observable(initialValue) {
|
|
|
857
892
|
function Observable() {
|
|
858
893
|
if (arguments.length > 0) {
|
|
859
894
|
if (Observable.isDifferent(Observable[LATEST_VALUE], arguments[0])) {
|
|
895
|
+
;
|
|
860
896
|
Observable.valueWillMutate();
|
|
861
897
|
Observable[LATEST_VALUE] = arguments[0];
|
|
862
898
|
Observable.valueHasMutated();
|
|
@@ -877,20 +913,43 @@ function observable(initialValue) {
|
|
|
877
913
|
return Observable;
|
|
878
914
|
}
|
|
879
915
|
observable.fn = {
|
|
916
|
+
/**
|
|
917
|
+
* Compares two values for equality.
|
|
918
|
+
* @param a The first value.
|
|
919
|
+
* @param b The second value.
|
|
920
|
+
* @returns True if the values are equal, otherwise false.
|
|
921
|
+
*/
|
|
880
922
|
equalityComparer: valuesArePrimitiveAndEqual,
|
|
923
|
+
/**
|
|
924
|
+
* Returns the current value of the observable without creating a dependency.
|
|
925
|
+
* @returns The current value.
|
|
926
|
+
*/
|
|
881
927
|
peek() {
|
|
882
928
|
return this[LATEST_VALUE];
|
|
883
929
|
},
|
|
930
|
+
/**
|
|
931
|
+
* Notifies subscribers that the value has changed.
|
|
932
|
+
*/
|
|
884
933
|
valueHasMutated() {
|
|
885
934
|
this.notifySubscribers(this[LATEST_VALUE], "spectate");
|
|
886
935
|
this.notifySubscribers(this[LATEST_VALUE]);
|
|
887
936
|
},
|
|
937
|
+
/**
|
|
938
|
+
* Notifies subscribers that the value is about to change.
|
|
939
|
+
*/
|
|
888
940
|
valueWillMutate() {
|
|
889
941
|
this.notifySubscribers(this[LATEST_VALUE], "beforeChange");
|
|
890
942
|
},
|
|
943
|
+
/**
|
|
944
|
+
* Modifies the value of the observable using a function.
|
|
945
|
+
* @param fn The function to modify the value.
|
|
946
|
+
* @param peek Whether to use the current value without creating a dependency.
|
|
947
|
+
* @returns The modified observable.
|
|
948
|
+
*/
|
|
891
949
|
modify(fn, peek2 = true) {
|
|
892
|
-
|
|
950
|
+
this(fn(peek2 ? this.peek() : this()));
|
|
893
951
|
},
|
|
952
|
+
// Some observables may not always be writeable, notably computeds.
|
|
894
953
|
isWriteable: true
|
|
895
954
|
};
|
|
896
955
|
function limitNotifySubscribers(value, event) {
|
|
@@ -903,15 +962,15 @@ function limitNotifySubscribers(value, event) {
|
|
|
903
962
|
}
|
|
904
963
|
}
|
|
905
964
|
subscribable.fn.limit = function limit(limitFunction) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
965
|
+
const self = this;
|
|
966
|
+
const selfIsObservable = isObservable(self);
|
|
967
|
+
const beforeChange = "beforeChange";
|
|
968
|
+
let ignoreBeforeChange, notifyNextChange, previousValue, pendingValue, didUpdate;
|
|
910
969
|
if (!self._origNotifySubscribers) {
|
|
911
970
|
self._origNotifySubscribers = self.notifySubscribers;
|
|
912
971
|
self.notifySubscribers = limitNotifySubscribers;
|
|
913
972
|
}
|
|
914
|
-
|
|
973
|
+
const finish = limitFunction(function() {
|
|
915
974
|
self._notificationIsPending = false;
|
|
916
975
|
if (selfIsObservable && pendingValue === self) {
|
|
917
976
|
pendingValue = self._evalIfChanged ? self._evalIfChanged() : self();
|
|
@@ -939,7 +998,10 @@ subscribable.fn.limit = function limit(limitFunction) {
|
|
|
939
998
|
}
|
|
940
999
|
},
|
|
941
1000
|
_notifyNextChangeIfValueIsDifferent() {
|
|
942
|
-
if (self.isDifferent(previousValue, self.peek(
|
|
1001
|
+
if (self.isDifferent(previousValue, self.peek(
|
|
1002
|
+
true
|
|
1003
|
+
/* evaluate */
|
|
1004
|
+
))) {
|
|
943
1005
|
notifyNextChange = true;
|
|
944
1006
|
}
|
|
945
1007
|
},
|
|
@@ -985,8 +1047,8 @@ function trackArrayChanges(target, options2) {
|
|
|
985
1047
|
let arrayChangeSubscription;
|
|
986
1048
|
let pendingNotifications = 0;
|
|
987
1049
|
let underlyingNotifySubscribersFunction;
|
|
988
|
-
|
|
989
|
-
|
|
1050
|
+
const underlyingBeforeSubscriptionAddFunction = target.beforeSubscriptionAdd;
|
|
1051
|
+
const underlyingAfterSubscriptionRemoveFunction = target.afterSubscriptionRemove;
|
|
990
1052
|
target.beforeSubscriptionAdd = function(event) {
|
|
991
1053
|
if (underlyingBeforeSubscriptionAddFunction) {
|
|
992
1054
|
underlyingBeforeSubscriptionAddFunction.call(target, event);
|
|
@@ -1023,11 +1085,11 @@ function trackArrayChanges(target, options2) {
|
|
|
1023
1085
|
}
|
|
1024
1086
|
return underlyingNotifySubscribersFunction.apply(this, arguments);
|
|
1025
1087
|
};
|
|
1026
|
-
|
|
1088
|
+
let previousContents = new Array().concat(target.peek() === void 0 ? [] : target.peek());
|
|
1027
1089
|
cachedDiff = null;
|
|
1028
1090
|
arrayChangeSubscription = target.subscribe(function(currentContents) {
|
|
1029
1091
|
let changes;
|
|
1030
|
-
currentContents =
|
|
1092
|
+
currentContents = new Array().concat(currentContents || []);
|
|
1031
1093
|
if (target.hasSubscriptionsForEvent(arrayChangeEventName)) {
|
|
1032
1094
|
changes = getChanges(previousContents, currentContents);
|
|
1033
1095
|
}
|
|
@@ -1049,9 +1111,9 @@ function trackArrayChanges(target, options2) {
|
|
|
1049
1111
|
if (!trackingChanges || pendingNotifications) {
|
|
1050
1112
|
return;
|
|
1051
1113
|
}
|
|
1052
|
-
|
|
1114
|
+
let diff = new Array(), arrayLength = rawArray.length, argsLength = args.length, offset = 0;
|
|
1053
1115
|
function pushDiff(status, value, index) {
|
|
1054
|
-
return diff[diff.length] = {
|
|
1116
|
+
return diff[diff.length] = { status, value, index };
|
|
1055
1117
|
}
|
|
1056
1118
|
switch (operationName) {
|
|
1057
1119
|
case "push":
|
|
@@ -1069,16 +1131,18 @@ function trackArrayChanges(target, options2) {
|
|
|
1069
1131
|
}
|
|
1070
1132
|
break;
|
|
1071
1133
|
case "splice":
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1134
|
+
{
|
|
1135
|
+
const startIndex = Math.min(Math.max(0, args[0] < 0 ? arrayLength + args[0] : args[0]), arrayLength), endDeleteIndex = argsLength === 1 ? arrayLength : Math.min(startIndex + (args[1] || 0), arrayLength), endAddIndex = startIndex + argsLength - 2, endIndex = Math.max(endDeleteIndex, endAddIndex), additions = new Array(), deletions = new Array();
|
|
1136
|
+
for (let index = startIndex, argsIndex = 2; index < endIndex; ++index, ++argsIndex) {
|
|
1137
|
+
if (index < endDeleteIndex) {
|
|
1138
|
+
deletions.push(pushDiff("deleted", rawArray[index], index));
|
|
1139
|
+
}
|
|
1140
|
+
if (index < endAddIndex) {
|
|
1141
|
+
additions.push(pushDiff("added", args[argsIndex], index));
|
|
1142
|
+
}
|
|
1079
1143
|
}
|
|
1144
|
+
findMovesInArrayComparison(deletions, additions);
|
|
1080
1145
|
}
|
|
1081
|
-
findMovesInArrayComparison(deletions, additions);
|
|
1082
1146
|
break;
|
|
1083
1147
|
default:
|
|
1084
1148
|
return;
|
|
@@ -1093,12 +1157,16 @@ extenders.trackArrayChanges = trackArrayChanges;
|
|
|
1093
1157
|
function observableArray(initialValues) {
|
|
1094
1158
|
initialValues = initialValues || [];
|
|
1095
1159
|
if (typeof initialValues !== "object" || !("length" in initialValues)) {
|
|
1096
|
-
throw new Error(
|
|
1160
|
+
throw new Error(
|
|
1161
|
+
"The argument passed when initializing an observable array must be an array, or null, or undefined."
|
|
1162
|
+
);
|
|
1097
1163
|
}
|
|
1098
|
-
|
|
1099
|
-
Object.setPrototypeOf(result, observableArray.fn);
|
|
1164
|
+
const result = Object.setPrototypeOf(observable(initialValues), observableArray.fn);
|
|
1100
1165
|
trackArrayChanges(result);
|
|
1101
|
-
overwriteLengthPropertyIfSupported(result, { get: () =>
|
|
1166
|
+
overwriteLengthPropertyIfSupported(result, { get: () => {
|
|
1167
|
+
var _a;
|
|
1168
|
+
return (_a = result()) == null ? void 0 : _a.length;
|
|
1169
|
+
} });
|
|
1102
1170
|
return result;
|
|
1103
1171
|
}
|
|
1104
1172
|
function isObservableArray(instance) {
|
|
@@ -1106,13 +1174,13 @@ function isObservableArray(instance) {
|
|
|
1106
1174
|
}
|
|
1107
1175
|
observableArray.fn = {
|
|
1108
1176
|
remove(valueOrPredicate) {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
return
|
|
1177
|
+
const underlyingArray = this.peek();
|
|
1178
|
+
const removedValues = new Array();
|
|
1179
|
+
const predicate = typeof valueOrPredicate === "function" && !isObservable(valueOrPredicate) ? valueOrPredicate : function(value) {
|
|
1180
|
+
return value === valueOrPredicate;
|
|
1113
1181
|
};
|
|
1114
|
-
for (
|
|
1115
|
-
|
|
1182
|
+
for (let i = 0; i < underlyingArray.length; i++) {
|
|
1183
|
+
const value = underlyingArray[i];
|
|
1116
1184
|
if (predicate(value)) {
|
|
1117
1185
|
if (removedValues.length === 0) {
|
|
1118
1186
|
this.valueWillMutate();
|
|
@@ -1132,8 +1200,8 @@ observableArray.fn = {
|
|
|
1132
1200
|
},
|
|
1133
1201
|
removeAll(arrayOfValues) {
|
|
1134
1202
|
if (arrayOfValues === void 0) {
|
|
1135
|
-
|
|
1136
|
-
|
|
1203
|
+
const underlyingArray = this.peek();
|
|
1204
|
+
const allValues = underlyingArray.slice(0);
|
|
1137
1205
|
this.valueWillMutate();
|
|
1138
1206
|
underlyingArray.splice(0, underlyingArray.length);
|
|
1139
1207
|
this.valueHasMutated();
|
|
@@ -1147,13 +1215,13 @@ observableArray.fn = {
|
|
|
1147
1215
|
});
|
|
1148
1216
|
},
|
|
1149
1217
|
destroy(valueOrPredicate) {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
return
|
|
1218
|
+
const underlyingArray = this.peek();
|
|
1219
|
+
const predicate = typeof valueOrPredicate === "function" && !isObservable(valueOrPredicate) ? valueOrPredicate : function(value) {
|
|
1220
|
+
return value === valueOrPredicate;
|
|
1153
1221
|
};
|
|
1154
1222
|
this.valueWillMutate();
|
|
1155
|
-
for (
|
|
1156
|
-
|
|
1223
|
+
for (let i = underlyingArray.length - 1; i >= 0; i--) {
|
|
1224
|
+
const value = underlyingArray[i];
|
|
1157
1225
|
if (predicate(value)) {
|
|
1158
1226
|
value["_destroy"] = true;
|
|
1159
1227
|
}
|
|
@@ -1177,7 +1245,7 @@ observableArray.fn = {
|
|
|
1177
1245
|
return arrayIndexOf(this(), item);
|
|
1178
1246
|
},
|
|
1179
1247
|
replace(oldItem, newItem) {
|
|
1180
|
-
|
|
1248
|
+
const index = this.indexOf(oldItem);
|
|
1181
1249
|
if (index >= 0) {
|
|
1182
1250
|
this.valueWillMutate();
|
|
1183
1251
|
this.peek()[index] = newItem;
|
|
@@ -1191,23 +1259,23 @@ observableArray.fn = {
|
|
|
1191
1259
|
return [...this()].reverse();
|
|
1192
1260
|
},
|
|
1193
1261
|
[Symbol.iterator]: function* () {
|
|
1194
|
-
yield* this();
|
|
1262
|
+
yield* __yieldStar(this());
|
|
1195
1263
|
}
|
|
1196
1264
|
};
|
|
1197
1265
|
Object.setPrototypeOf(observableArray.fn, observable.fn);
|
|
1198
1266
|
arrayForEach(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function(methodName) {
|
|
1199
1267
|
observableArray.fn[methodName] = function() {
|
|
1200
|
-
|
|
1268
|
+
const underlyingArray = this.peek();
|
|
1201
1269
|
this.valueWillMutate();
|
|
1202
1270
|
this.cacheDiffForKnownOperation(underlyingArray, methodName, arguments);
|
|
1203
|
-
|
|
1271
|
+
const methodCallResult = underlyingArray[methodName].apply(underlyingArray, arguments);
|
|
1204
1272
|
this.valueHasMutated();
|
|
1205
1273
|
return methodCallResult === underlyingArray ? this : methodCallResult;
|
|
1206
1274
|
};
|
|
1207
1275
|
});
|
|
1208
1276
|
arrayForEach(["slice"], function(methodName) {
|
|
1209
1277
|
observableArray.fn[methodName] = function() {
|
|
1210
|
-
|
|
1278
|
+
const underlyingArray = this();
|
|
1211
1279
|
return underlyingArray[methodName].apply(underlyingArray, arguments);
|
|
1212
1280
|
};
|
|
1213
1281
|
});
|
|
@@ -1220,26 +1288,26 @@ function toJS(rootObject) {
|
|
|
1220
1288
|
throw new Error("When calling ko.toJS, pass the object you want to convert.");
|
|
1221
1289
|
}
|
|
1222
1290
|
return mapJsObjectGraph(rootObject, function(valueToMap) {
|
|
1223
|
-
for (
|
|
1291
|
+
for (let i = 0; isObservable(valueToMap) && i < maxNestedObservableDepth; i++) {
|
|
1224
1292
|
valueToMap = valueToMap();
|
|
1225
1293
|
}
|
|
1226
1294
|
return valueToMap;
|
|
1227
1295
|
});
|
|
1228
1296
|
}
|
|
1229
1297
|
function toJSON(rootObject, replacer, space) {
|
|
1230
|
-
|
|
1298
|
+
const plainJavaScriptObject = toJS(rootObject);
|
|
1231
1299
|
return JSON.stringify(plainJavaScriptObject, replacer, space);
|
|
1232
1300
|
}
|
|
1233
1301
|
function mapJsObjectGraph(rootObject, mapInputCallback, visitedObjects = /* @__PURE__ */ new Map()) {
|
|
1234
1302
|
rootObject = mapInputCallback(rootObject);
|
|
1235
|
-
|
|
1303
|
+
const canHaveProperties = typeof rootObject === "object" && rootObject !== null && rootObject !== void 0 && !(rootObject instanceof RegExp) && !(rootObject instanceof Date) && !(rootObject instanceof String) && !(rootObject instanceof Number) && !(rootObject instanceof Boolean);
|
|
1236
1304
|
if (!canHaveProperties) {
|
|
1237
1305
|
return rootObject;
|
|
1238
1306
|
}
|
|
1239
|
-
|
|
1307
|
+
const outputProperties = rootObject instanceof Array ? [] : {};
|
|
1240
1308
|
visitedObjects.set(rootObject, outputProperties);
|
|
1241
1309
|
visitPropertiesOrArrayEntries(rootObject, function(indexer) {
|
|
1242
|
-
|
|
1310
|
+
const propertyValue = mapInputCallback(rootObject[indexer]);
|
|
1243
1311
|
switch (typeof propertyValue) {
|
|
1244
1312
|
case "boolean":
|
|
1245
1313
|
case "number":
|
|
@@ -1249,8 +1317,10 @@ function mapJsObjectGraph(rootObject, mapInputCallback, visitedObjects = /* @__P
|
|
|
1249
1317
|
break;
|
|
1250
1318
|
case "object":
|
|
1251
1319
|
case "undefined":
|
|
1252
|
-
|
|
1253
|
-
|
|
1320
|
+
{
|
|
1321
|
+
const previouslyMappedValue = visitedObjects.get(propertyValue);
|
|
1322
|
+
outputProperties[indexer] = previouslyMappedValue !== void 0 ? previouslyMappedValue : mapJsObjectGraph(propertyValue, mapInputCallback, visitedObjects);
|
|
1323
|
+
}
|
|
1254
1324
|
break;
|
|
1255
1325
|
}
|
|
1256
1326
|
});
|
|
@@ -1258,14 +1328,14 @@ function mapJsObjectGraph(rootObject, mapInputCallback, visitedObjects = /* @__P
|
|
|
1258
1328
|
}
|
|
1259
1329
|
function visitPropertiesOrArrayEntries(rootObject, visitorCallback) {
|
|
1260
1330
|
if (rootObject instanceof Array) {
|
|
1261
|
-
for (
|
|
1331
|
+
for (let i = 0; i < rootObject.length; i++) {
|
|
1262
1332
|
visitorCallback(i);
|
|
1263
1333
|
}
|
|
1264
1334
|
if (typeof rootObject["toJSON"] === "function") {
|
|
1265
1335
|
visitorCallback("toJSON");
|
|
1266
1336
|
}
|
|
1267
1337
|
} else {
|
|
1268
|
-
for (
|
|
1338
|
+
for (const propertyName in rootObject) {
|
|
1269
1339
|
visitorCallback(propertyName);
|
|
1270
1340
|
}
|
|
1271
1341
|
}
|