@yiin/reactive-proxy-state 1.0.44 → 2.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/README.md +41 -0
- package/dist/index.cjs +3344 -1131
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3474 -1254
- package/dist/location.d.ts +288 -0
- package/dist/reactive.d.ts +5 -1
- package/dist/utils.d.ts +150 -9
- package/dist/wrap-array.d.ts +2 -2
- package/dist/wrap-map.d.ts +2 -2
- package/dist/wrap-set.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,67 +4,44 @@ var __defProp = Object.defineProperty;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
function __accessProp(key) {
|
|
8
|
-
return this[key];
|
|
9
|
-
}
|
|
10
|
-
var __toESMCache_node;
|
|
11
|
-
var __toESMCache_esm;
|
|
12
7
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
-
var canCache = mod != null && typeof mod === "object";
|
|
14
|
-
if (canCache) {
|
|
15
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
-
var cached = cache.get(mod);
|
|
17
|
-
if (cached)
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
8
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
9
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (canCache)
|
|
31
|
-
cache.set(mod, to);
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
32
16
|
return to;
|
|
33
17
|
};
|
|
18
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
34
19
|
var __toCommonJS = (from) => {
|
|
35
|
-
var entry =
|
|
20
|
+
var entry = __moduleCache.get(from), desc;
|
|
36
21
|
if (entry)
|
|
37
22
|
return entry;
|
|
38
23
|
entry = __defProp({}, "__esModule", { value: true });
|
|
39
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
45
|
-
});
|
|
46
|
-
}
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
25
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
26
|
+
get: () => from[key],
|
|
27
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
28
|
+
}));
|
|
47
29
|
__moduleCache.set(from, entry);
|
|
48
30
|
return entry;
|
|
49
31
|
};
|
|
50
|
-
var __moduleCache;
|
|
51
32
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
52
|
-
var __returnValue = (v) => v;
|
|
53
|
-
function __exportSetter(name, newValue) {
|
|
54
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
55
|
-
}
|
|
56
33
|
var __export = (target, all) => {
|
|
57
34
|
for (var name in all)
|
|
58
35
|
__defProp(target, name, {
|
|
59
36
|
get: all[name],
|
|
60
37
|
enumerable: true,
|
|
61
38
|
configurable: true,
|
|
62
|
-
set:
|
|
39
|
+
set: (newValue) => all[name] = () => newValue
|
|
63
40
|
});
|
|
64
41
|
};
|
|
65
42
|
|
|
66
43
|
// node_modules/@vue/shared/dist/shared.cjs.js
|
|
67
|
-
var require_shared_cjs = __commonJS(
|
|
44
|
+
var require_shared_cjs = __commonJS((exports2) => {
|
|
68
45
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
69
46
|
/*! #__NO_SIDE_EFFECTS__ */
|
|
70
47
|
function makeMap(str) {
|
|
@@ -87,7 +64,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
87
64
|
}
|
|
88
65
|
};
|
|
89
66
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
90
|
-
var
|
|
67
|
+
var hasOwn2 = (val, key) => hasOwnProperty.call(val, key);
|
|
91
68
|
var isArray = Array.isArray;
|
|
92
69
|
var isMap = (val) => toTypeString(val) === "[object Map]";
|
|
93
70
|
var isSet = (val) => toTypeString(val) === "[object Set]";
|
|
@@ -96,9 +73,9 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
96
73
|
var isFunction = (val) => typeof val === "function";
|
|
97
74
|
var isString = (val) => typeof val === "string";
|
|
98
75
|
var isSymbol = (val) => typeof val === "symbol";
|
|
99
|
-
var
|
|
76
|
+
var isObject7 = (val) => val !== null && typeof val === "object";
|
|
100
77
|
var isPromise = (val) => {
|
|
101
|
-
return (
|
|
78
|
+
return (isObject7(val) || isFunction(val)) && isFunction(val.then) && isFunction(val.catch);
|
|
102
79
|
};
|
|
103
80
|
var objectToString = Object.prototype.toString;
|
|
104
81
|
var toTypeString = (value) => objectToString.call(value);
|
|
@@ -300,7 +277,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
300
277
|
}
|
|
301
278
|
}
|
|
302
279
|
return res;
|
|
303
|
-
} else if (isString(value) ||
|
|
280
|
+
} else if (isString(value) || isObject7(value)) {
|
|
304
281
|
return value;
|
|
305
282
|
}
|
|
306
283
|
}
|
|
@@ -343,7 +320,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
343
320
|
res += normalized + " ";
|
|
344
321
|
}
|
|
345
322
|
}
|
|
346
|
-
} else if (
|
|
323
|
+
} else if (isObject7(value)) {
|
|
347
324
|
for (const name in value) {
|
|
348
325
|
if (value[name]) {
|
|
349
326
|
res += name + " ";
|
|
@@ -480,8 +457,8 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
480
457
|
if (aValidType || bValidType) {
|
|
481
458
|
return aValidType && bValidType ? looseCompareArrays(a, b) : false;
|
|
482
459
|
}
|
|
483
|
-
aValidType =
|
|
484
|
-
bValidType =
|
|
460
|
+
aValidType = isObject7(a);
|
|
461
|
+
bValidType = isObject7(b);
|
|
485
462
|
if (aValidType || bValidType) {
|
|
486
463
|
if (!aValidType || !bValidType) {
|
|
487
464
|
return false;
|
|
@@ -508,7 +485,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
508
485
|
return !!(val && val["__v_isRef"] === true);
|
|
509
486
|
};
|
|
510
487
|
var toDisplayString = (val) => {
|
|
511
|
-
return isString(val) ? val : val == null ? "" : isArray(val) ||
|
|
488
|
+
return isString(val) ? val : val == null ? "" : isArray(val) || isObject7(val) && (val.toString === objectToString || !isFunction(val.toString)) ? isRef3(val) ? toDisplayString(val.value) : JSON.stringify(val, replacer, 2) : String(val);
|
|
512
489
|
};
|
|
513
490
|
var replacer = (_key, val) => {
|
|
514
491
|
if (isRef3(val)) {
|
|
@@ -526,7 +503,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
526
503
|
};
|
|
527
504
|
} else if (isSymbol(val)) {
|
|
528
505
|
return stringifySymbol(val);
|
|
529
|
-
} else if (
|
|
506
|
+
} else if (isObject7(val) && !isArray(val) && !isPlainObject(val)) {
|
|
530
507
|
return String(val);
|
|
531
508
|
}
|
|
532
509
|
return val;
|
|
@@ -556,7 +533,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
556
533
|
exports2.getEscapedCssVarName = getEscapedCssVarName;
|
|
557
534
|
exports2.getGlobalThis = getGlobalThis;
|
|
558
535
|
exports2.hasChanged = hasChanged;
|
|
559
|
-
exports2.hasOwn =
|
|
536
|
+
exports2.hasOwn = hasOwn2;
|
|
560
537
|
exports2.hyphenate = hyphenate;
|
|
561
538
|
exports2.includeBooleanAttr = includeBooleanAttr;
|
|
562
539
|
exports2.invokeArrayFns = invokeArrayFns;
|
|
@@ -575,7 +552,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
575
552
|
exports2.isMap = isMap;
|
|
576
553
|
exports2.isMathMLTag = isMathMLTag;
|
|
577
554
|
exports2.isModelListener = isModelListener;
|
|
578
|
-
exports2.isObject =
|
|
555
|
+
exports2.isObject = isObject7;
|
|
579
556
|
exports2.isOn = isOn;
|
|
580
557
|
exports2.isPlainObject = isPlainObject;
|
|
581
558
|
exports2.isPromise = isPromise;
|
|
@@ -610,7 +587,7 @@ var require_shared_cjs = __commonJS(function(exports2) {
|
|
|
610
587
|
});
|
|
611
588
|
|
|
612
589
|
// node_modules/@vue/reactivity/dist/reactivity.cjs.js
|
|
613
|
-
var require_reactivity_cjs = __commonJS(
|
|
590
|
+
var require_reactivity_cjs = __commonJS((exports2) => {
|
|
614
591
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
615
592
|
var shared = require_shared_cjs();
|
|
616
593
|
function warn(msg, ...args) {
|
|
@@ -2350,37 +2327,40 @@ var require_reactivity_cjs = __commonJS(function(exports2) {
|
|
|
2350
2327
|
// src/index.ts
|
|
2351
2328
|
var exports_src = {};
|
|
2352
2329
|
__export(exports_src, {
|
|
2353
|
-
|
|
2354
|
-
cleanupEffect: () => cleanupEffect,
|
|
2355
|
-
computed: () => computed,
|
|
2356
|
-
createBridgeEmitter: () => createBridgeEmitter,
|
|
2357
|
-
createMainBridgeEmitter: () => createMainBridgeEmitter,
|
|
2358
|
-
createRendererBridgeEmitter: () => createRendererBridgeEmitter,
|
|
2359
|
-
deepClone: () => deepClone,
|
|
2360
|
-
deepEqual: () => deepEqual,
|
|
2361
|
-
deepToRaw: () => deepToRaw,
|
|
2362
|
-
getProxyStats: () => getProxyStats,
|
|
2363
|
-
isComputed: () => isComputed,
|
|
2364
|
-
isReactive: () => isReactive,
|
|
2365
|
-
isRef: () => isRef,
|
|
2366
|
-
isRefSymbol: () => isRefSymbol,
|
|
2367
|
-
markRaw: () => markRaw,
|
|
2368
|
-
reactive: () => reactive,
|
|
2369
|
-
ref: () => ref,
|
|
2370
|
-
resetProxyStats: () => resetProxyStats,
|
|
2371
|
-
runCleanupFunctions: () => runCleanupFunctions,
|
|
2372
|
-
setActiveEffect: () => setActiveEffect,
|
|
2373
|
-
toRaw: () => toRaw,
|
|
2374
|
-
toRef: () => toRef,
|
|
2375
|
-
toRefs: () => toRefs,
|
|
2376
|
-
track: () => track,
|
|
2377
|
-
trackVueReactiveEvents: () => trackVueReactiveEvents,
|
|
2378
|
-
trigger: () => trigger,
|
|
2379
|
-
triggerRef: () => triggerRef,
|
|
2380
|
-
unref: () => unref,
|
|
2381
|
-
updateState: () => updateState,
|
|
2330
|
+
watchEffect: () => watchEffect,
|
|
2382
2331
|
watch: () => watch,
|
|
2383
|
-
|
|
2332
|
+
updateState: () => updateState,
|
|
2333
|
+
unref: () => unref,
|
|
2334
|
+
triggerRef: () => triggerRef,
|
|
2335
|
+
trigger: () => trigger,
|
|
2336
|
+
trackVueReactiveEvents: () => trackVueReactiveEvents,
|
|
2337
|
+
track: () => track,
|
|
2338
|
+
toRefs: () => toRefs,
|
|
2339
|
+
toRef: () => toRef,
|
|
2340
|
+
toRaw: () => toRaw,
|
|
2341
|
+
setActiveEffect: () => setActiveEffect,
|
|
2342
|
+
runCleanupFunctions: () => runCleanupFunctions,
|
|
2343
|
+
resetProxyStats: () => resetProxyStats,
|
|
2344
|
+
ref: () => ref,
|
|
2345
|
+
reactive: () => reactive,
|
|
2346
|
+
markRaw: () => markRaw,
|
|
2347
|
+
isRefSymbol: () => isRefSymbol,
|
|
2348
|
+
isRef: () => isRef,
|
|
2349
|
+
isReactive: () => isReactive,
|
|
2350
|
+
isComputed: () => isComputed,
|
|
2351
|
+
getProxyStats: () => getProxyStats,
|
|
2352
|
+
deepToRaw: () => deepToRaw,
|
|
2353
|
+
deepEqual: () => deepEqual,
|
|
2354
|
+
deepClone: () => deepClone,
|
|
2355
|
+
createRendererBridgeEmitter: () => createRendererBridgeEmitter,
|
|
2356
|
+
createMainBridgeEmitter: () => createMainBridgeEmitter,
|
|
2357
|
+
createBridgeEmitter: () => createBridgeEmitter,
|
|
2358
|
+
computed: () => computed,
|
|
2359
|
+
cleanupEffect: () => cleanupEffect,
|
|
2360
|
+
activeEffect: () => activeEffect,
|
|
2361
|
+
UnsupportedStateError: () => UnsupportedStateError,
|
|
2362
|
+
SnapshotLimitError: () => SnapshotLimitError,
|
|
2363
|
+
SNAPSHOT_SHARED_COPY_LIMIT: () => SNAPSHOT_SHARED_COPY_LIMIT
|
|
2384
2364
|
});
|
|
2385
2365
|
module.exports = __toCommonJS(exports_src);
|
|
2386
2366
|
|
|
@@ -2398,40 +2378,50 @@ function unwrapForStore(value) {
|
|
|
2398
2378
|
if (Array.isArray(value)) {
|
|
2399
2379
|
for (let i = 0;i < value.length; i++) {
|
|
2400
2380
|
const child = value[i];
|
|
2401
|
-
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2402
|
-
value
|
|
2403
|
-
}
|
|
2381
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2382
|
+
storeRawChild(value, i, child);
|
|
2404
2383
|
}
|
|
2405
2384
|
} else if (!(value instanceof Map) && !(value instanceof Set) && !(value instanceof Date)) {
|
|
2406
2385
|
for (const key in value) {
|
|
2407
2386
|
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
2408
2387
|
continue;
|
|
2409
2388
|
const child = value[key];
|
|
2410
|
-
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2411
|
-
value
|
|
2412
|
-
}
|
|
2389
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2390
|
+
storeRawChild(value, key, child);
|
|
2413
2391
|
}
|
|
2414
2392
|
}
|
|
2415
2393
|
return value;
|
|
2416
2394
|
}
|
|
2417
|
-
var
|
|
2395
|
+
var lookupSetter = Object.prototype.__lookupSetter__;
|
|
2396
|
+
function storeRawChild(value, key, child) {
|
|
2397
|
+
if (lookupSetter === undefined) {
|
|
2398
|
+
if (Reflect.getOwnPropertyDescriptor(value, key)?.value === child)
|
|
2399
|
+
Reflect.set(value, key, toRaw(child));
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
if (lookupSetter.call(value, key) !== undefined)
|
|
2403
|
+
return;
|
|
2404
|
+
try {
|
|
2405
|
+
value[key] = toRaw(child);
|
|
2406
|
+
} catch {}
|
|
2407
|
+
}
|
|
2418
2408
|
var MAX_CACHE_SIZE = 1000;
|
|
2419
2409
|
var pathCache = new WeakMap;
|
|
2420
2410
|
var pathCacheSize = new WeakMap;
|
|
2421
|
-
var pathConcatCache = new Map;
|
|
2422
|
-
var MAX_PATH_CACHE_SIZE = 1000;
|
|
2423
2411
|
var globalSeen = new WeakMap;
|
|
2424
2412
|
var wrapperCache = new WeakMap;
|
|
2413
|
+
var locationNodes = new WeakMap;
|
|
2425
2414
|
var proxyStats = {
|
|
2426
2415
|
created: 0,
|
|
2427
2416
|
arrays: 0,
|
|
2428
2417
|
maps: 0,
|
|
2429
2418
|
sets: 0,
|
|
2430
2419
|
objects: 0,
|
|
2431
|
-
staleEvicted: 0
|
|
2420
|
+
staleEvicted: 0,
|
|
2421
|
+
detachedWrites: 0
|
|
2432
2422
|
};
|
|
2433
2423
|
function getProxyStats() {
|
|
2434
|
-
return { ...proxyStats, pathConcatCacheSize:
|
|
2424
|
+
return { ...proxyStats, pathConcatCacheSize: 0 };
|
|
2435
2425
|
}
|
|
2436
2426
|
function resetProxyStats() {
|
|
2437
2427
|
proxyStats.created = 0;
|
|
@@ -2440,41 +2430,7 @@ function resetProxyStats() {
|
|
|
2440
2430
|
proxyStats.sets = 0;
|
|
2441
2431
|
proxyStats.objects = 0;
|
|
2442
2432
|
proxyStats.staleEvicted = 0;
|
|
2443
|
-
|
|
2444
|
-
function evictDeep(value) {
|
|
2445
|
-
if (value == null || typeof value !== "object")
|
|
2446
|
-
return;
|
|
2447
|
-
value = toRaw(value);
|
|
2448
|
-
if (!globalSeen.has(value))
|
|
2449
|
-
return;
|
|
2450
|
-
globalSeen.delete(value);
|
|
2451
|
-
wrapperCache.delete(value);
|
|
2452
|
-
proxyStats.staleEvicted++;
|
|
2453
|
-
if (Array.isArray(value)) {
|
|
2454
|
-
for (let i = 0;i < value.length; i++) {
|
|
2455
|
-
if (value[i] != null && typeof value[i] === "object") {
|
|
2456
|
-
evictDeep(value[i]);
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
} else if (value instanceof Map) {
|
|
2460
|
-
for (const v of value.values()) {
|
|
2461
|
-
if (v != null && typeof v === "object")
|
|
2462
|
-
evictDeep(v);
|
|
2463
|
-
}
|
|
2464
|
-
} else if (value instanceof Set) {
|
|
2465
|
-
for (const v of value) {
|
|
2466
|
-
if (v != null && typeof v === "object")
|
|
2467
|
-
evictDeep(v);
|
|
2468
|
-
}
|
|
2469
|
-
} else {
|
|
2470
|
-
const keys = Object.keys(value);
|
|
2471
|
-
for (let i = 0;i < keys.length; i++) {
|
|
2472
|
-
const child = value[keys[i]];
|
|
2473
|
-
if (child != null && typeof child === "object") {
|
|
2474
|
-
evictDeep(child);
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2433
|
+
proxyStats.detachedWrites = 0;
|
|
2478
2434
|
}
|
|
2479
2435
|
function cleanupPathCache(root) {
|
|
2480
2436
|
const cache = pathCache.get(root);
|
|
@@ -2490,23 +2446,11 @@ function cleanupPathCache(root) {
|
|
|
2490
2446
|
pathCacheSize.set(root, MAX_CACHE_SIZE - entriesToRemove);
|
|
2491
2447
|
}
|
|
2492
2448
|
}
|
|
2493
|
-
function
|
|
2494
|
-
if (pathConcatCache.size > MAX_PATH_CACHE_SIZE) {
|
|
2495
|
-
const entriesToRemove = Math.floor(MAX_PATH_CACHE_SIZE * 0.2);
|
|
2496
|
-
let count = 0;
|
|
2497
|
-
for (const key of pathConcatCache.keys()) {
|
|
2498
|
-
if (count >= entriesToRemove)
|
|
2499
|
-
break;
|
|
2500
|
-
pathConcatCache.delete(key);
|
|
2501
|
-
count++;
|
|
2502
|
-
}
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
function deepEqual(a, b, seen = new WeakMap) {
|
|
2449
|
+
function deepEqual(a, b, seen) {
|
|
2506
2450
|
if (a === b)
|
|
2507
2451
|
return true;
|
|
2508
2452
|
if (a == null || b == null)
|
|
2509
|
-
return
|
|
2453
|
+
return false;
|
|
2510
2454
|
if (typeof a !== typeof b)
|
|
2511
2455
|
return false;
|
|
2512
2456
|
if (a instanceof Date && b instanceof Date)
|
|
@@ -2515,45 +2459,75 @@ function deepEqual(a, b, seen = new WeakMap) {
|
|
|
2515
2459
|
return false;
|
|
2516
2460
|
if (Array.isArray(a) !== Array.isArray(b))
|
|
2517
2461
|
return false;
|
|
2518
|
-
if (seen
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
return deepEqualCache.get(a).get(b);
|
|
2462
|
+
if (seen !== undefined) {
|
|
2463
|
+
if (seen.has(a))
|
|
2464
|
+
return seen.get(a) === b;
|
|
2465
|
+
seen.set(a, b);
|
|
2523
2466
|
}
|
|
2524
|
-
if (!deepEqualCache.has(a)) {
|
|
2525
|
-
deepEqualCache.set(a, new WeakMap);
|
|
2526
|
-
}
|
|
2527
|
-
let result;
|
|
2528
2467
|
if (Array.isArray(a)) {
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2468
|
+
if (a.length !== b.length)
|
|
2469
|
+
return false;
|
|
2470
|
+
for (let i = 0;i < a.length; i++) {
|
|
2471
|
+
const left = a[i];
|
|
2472
|
+
if (left === undefined && !(i in a))
|
|
2473
|
+
continue;
|
|
2474
|
+
const right = b[i];
|
|
2475
|
+
if (left === right)
|
|
2476
|
+
continue;
|
|
2477
|
+
if (isObject(left) && isObject(right))
|
|
2478
|
+
seen ??= startSeen(a, b);
|
|
2479
|
+
if (!deepEqual(left, right, seen))
|
|
2480
|
+
return false;
|
|
2539
2481
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2482
|
+
return true;
|
|
2483
|
+
}
|
|
2484
|
+
if (a instanceof Map && b instanceof Map) {
|
|
2485
|
+
if (a.size !== b.size)
|
|
2486
|
+
return false;
|
|
2487
|
+
for (const [key, left] of a) {
|
|
2488
|
+
if (!b.has(key))
|
|
2489
|
+
return false;
|
|
2490
|
+
const right = b.get(key);
|
|
2491
|
+
if (left === right)
|
|
2492
|
+
continue;
|
|
2493
|
+
if (isObject(left) && isObject(right))
|
|
2494
|
+
seen ??= startSeen(a, b);
|
|
2495
|
+
if (!deepEqual(left, right, seen))
|
|
2496
|
+
return false;
|
|
2549
2497
|
}
|
|
2550
|
-
|
|
2551
|
-
const keysA = Object.keys(a);
|
|
2552
|
-
const keysB = Object.keys(b);
|
|
2553
|
-
result = keysA.length === keysB.length && keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(a[key], b[key], seen));
|
|
2498
|
+
return true;
|
|
2554
2499
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2500
|
+
if (a instanceof Set && b instanceof Set) {
|
|
2501
|
+
if (a.size !== b.size)
|
|
2502
|
+
return false;
|
|
2503
|
+
for (const value of a) {
|
|
2504
|
+
if (!b.has(value))
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
return true;
|
|
2508
|
+
}
|
|
2509
|
+
const keysA = Object.keys(a);
|
|
2510
|
+
if (keysA.length !== Object.keys(b).length)
|
|
2511
|
+
return false;
|
|
2512
|
+
for (let i = 0;i < keysA.length; i++) {
|
|
2513
|
+
const key = keysA[i];
|
|
2514
|
+
if (!hasOwn.call(b, key))
|
|
2515
|
+
return false;
|
|
2516
|
+
const left = a[key];
|
|
2517
|
+
const right = b[key];
|
|
2518
|
+
if (left === right)
|
|
2519
|
+
continue;
|
|
2520
|
+
if (isObject(left) && isObject(right))
|
|
2521
|
+
seen ??= startSeen(a, b);
|
|
2522
|
+
if (!deepEqual(left, right, seen))
|
|
2523
|
+
return false;
|
|
2524
|
+
}
|
|
2525
|
+
return true;
|
|
2526
|
+
}
|
|
2527
|
+
function startSeen(a, b) {
|
|
2528
|
+
const seen = new WeakMap;
|
|
2529
|
+
seen.set(a, b);
|
|
2530
|
+
return seen;
|
|
2557
2531
|
}
|
|
2558
2532
|
function setInPathCache(root, pathKey, value) {
|
|
2559
2533
|
if (!pathCache.has(root)) {
|
|
@@ -2589,21 +2563,6 @@ function evictDescendantsFromPathCache(root, pathKey) {
|
|
|
2589
2563
|
pathCacheSize.set(root, (pathCacheSize.get(root) ?? cache.size) - evicted);
|
|
2590
2564
|
}
|
|
2591
2565
|
}
|
|
2592
|
-
function getPathConcat(path) {
|
|
2593
|
-
const result = pathConcatCache.get(path);
|
|
2594
|
-
if (result !== undefined) {
|
|
2595
|
-
pathConcatCache.delete(path);
|
|
2596
|
-
pathConcatCache.set(path, result);
|
|
2597
|
-
}
|
|
2598
|
-
return result;
|
|
2599
|
-
}
|
|
2600
|
-
function setPathConcat(path, value) {
|
|
2601
|
-
if (pathConcatCache.has(path)) {
|
|
2602
|
-
pathConcatCache.delete(path);
|
|
2603
|
-
}
|
|
2604
|
-
pathConcatCache.set(path, value);
|
|
2605
|
-
cleanupPathConcatCache();
|
|
2606
|
-
}
|
|
2607
2566
|
function isObject(val) {
|
|
2608
2567
|
return val !== null && typeof val === "object";
|
|
2609
2568
|
}
|
|
@@ -2637,298 +2596,2095 @@ function traverse(value, seen = new Set) {
|
|
|
2637
2596
|
}
|
|
2638
2597
|
return value;
|
|
2639
2598
|
}
|
|
2640
|
-
|
|
2599
|
+
var SNAPSHOT_SHARED_COPY_LIMIT = 1e5;
|
|
2600
|
+
|
|
2601
|
+
class SnapshotLimitError extends RangeError {
|
|
2602
|
+
constructor(extraCopies) {
|
|
2603
|
+
super(`reactive-proxy-state: a snapshot would copy shared objects more than ` + `${SNAPSHOT_SHARED_COPY_LIMIT} extra times (counted ${extraCopies} before stopping; ` + `an object is copied once per place it holds). Nothing was changed. To remove such a ` + `graph, see "Shared graphs have a copy limit" under "Synchronization Limits" in the README`);
|
|
2604
|
+
this.name = "SnapshotLimitError";
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
class UnsupportedStateError extends TypeError {
|
|
2609
|
+
constructor(problem) {
|
|
2610
|
+
super(`reactive-proxy-state: ${problem}. Nothing was changed. See "Supported inputs" under ` + `"Synchronization Limits" in the README`);
|
|
2611
|
+
this.name = "UnsupportedStateError";
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
var SNAPSHOT_CHECK_AFTER = SNAPSHOT_SHARED_COPY_LIMIT + 1;
|
|
2615
|
+
function cloneTree(value, named) {
|
|
2616
|
+
return copyTree(value, undefined, undefined, false, named);
|
|
2617
|
+
}
|
|
2618
|
+
var REACHES = Symbol("reaches");
|
|
2619
|
+
function cloneTreeUnless(value, container, named) {
|
|
2620
|
+
return copyUnless(value, container, false, named);
|
|
2621
|
+
}
|
|
2622
|
+
function cloneStored(value, container, named) {
|
|
2623
|
+
return copyUnless(value, container, true, named);
|
|
2624
|
+
}
|
|
2625
|
+
var copiedFresh = false;
|
|
2626
|
+
function copyUnless(value, container, checkFresh, named) {
|
|
2627
|
+
try {
|
|
2628
|
+
return copyTree(value, container, undefined, checkFresh, named);
|
|
2629
|
+
} catch (error) {
|
|
2630
|
+
if (error === reachedContainer) {
|
|
2631
|
+
copiedFresh = false;
|
|
2632
|
+
return REACHES;
|
|
2633
|
+
}
|
|
2634
|
+
throw error;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function cloneTreeAfter(value, container, contents, named) {
|
|
2638
|
+
return copyTree(value, container, contents, false, named);
|
|
2639
|
+
}
|
|
2640
|
+
var reachedContainer = new Error("reactive-proxy-state: internal, a copy reached its container");
|
|
2641
|
+
function copyTree(value, container, contents, checkFresh, named) {
|
|
2641
2642
|
if (value === null || typeof value !== "object") {
|
|
2643
|
+
if (checkFresh)
|
|
2644
|
+
copiedFresh = true;
|
|
2642
2645
|
return value;
|
|
2643
2646
|
}
|
|
2644
|
-
|
|
2645
|
-
|
|
2647
|
+
const top = toRaw(value);
|
|
2648
|
+
if (top === value && top !== container) {
|
|
2649
|
+
const small = copySmall(value, container, checkFresh, named);
|
|
2650
|
+
if (small !== undefined)
|
|
2651
|
+
return small;
|
|
2652
|
+
}
|
|
2653
|
+
const base = cloneAncestors.length;
|
|
2654
|
+
const workBase = cloneWork.length;
|
|
2655
|
+
const outerTop = cloneTop;
|
|
2656
|
+
const outerCountdown = cloneCountdown;
|
|
2657
|
+
const outerContainer = cloneContainer;
|
|
2658
|
+
const outerContents = cloneContents;
|
|
2659
|
+
const outerFresh = cloneFresh;
|
|
2660
|
+
const outerFirst = cloneFirst;
|
|
2661
|
+
const outerSeen = cloneSeen;
|
|
2662
|
+
const outerBase = cloneBase;
|
|
2663
|
+
const outerIndex = cloneIndex;
|
|
2664
|
+
const outerNamed = cloneNamed;
|
|
2665
|
+
cloneTop = top;
|
|
2666
|
+
cloneCountdown = SNAPSHOT_CHECK_AFTER;
|
|
2667
|
+
cloneContainer = container;
|
|
2668
|
+
cloneContents = contents;
|
|
2669
|
+
cloneFresh = checkFresh && locationNodes.get(top) === undefined;
|
|
2670
|
+
cloneFirst = undefined;
|
|
2671
|
+
cloneSeen = undefined;
|
|
2672
|
+
cloneBase = base;
|
|
2673
|
+
cloneIndex = undefined;
|
|
2674
|
+
cloneNamed = named;
|
|
2675
|
+
try {
|
|
2676
|
+
const copy = cloneEntry(value, 0, named);
|
|
2677
|
+
if (checkFresh)
|
|
2678
|
+
copiedFresh = cloneFresh;
|
|
2679
|
+
return copy;
|
|
2680
|
+
} finally {
|
|
2681
|
+
cloneAncestors.length = base;
|
|
2682
|
+
cloneCopies.length = base;
|
|
2683
|
+
cloneWork.length = workBase;
|
|
2684
|
+
cloneTop = outerTop;
|
|
2685
|
+
cloneCountdown = outerCountdown;
|
|
2686
|
+
cloneContainer = outerContainer;
|
|
2687
|
+
cloneContents = outerContents;
|
|
2688
|
+
cloneFresh = outerFresh;
|
|
2689
|
+
cloneFirst = outerFirst;
|
|
2690
|
+
cloneSeen = outerSeen;
|
|
2691
|
+
cloneBase = outerBase;
|
|
2692
|
+
cloneIndex = outerIndex;
|
|
2693
|
+
cloneNamed = outerNamed;
|
|
2646
2694
|
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2695
|
+
}
|
|
2696
|
+
var cloneTop;
|
|
2697
|
+
var cloneCountdown = 0;
|
|
2698
|
+
var cloneContainer;
|
|
2699
|
+
var cloneContents;
|
|
2700
|
+
var cloneFresh = false;
|
|
2701
|
+
var cloneFirst;
|
|
2702
|
+
var cloneSeen;
|
|
2703
|
+
var cloneNamed = 0 /* None */;
|
|
2704
|
+
function copySmall(value, container, checkFresh, named) {
|
|
2705
|
+
if (!Array.isArray(value)) {
|
|
2706
|
+
const copy2 = copyLeaf(value);
|
|
2707
|
+
if (copy2 !== undefined && checkFresh)
|
|
2708
|
+
copiedFresh = locationNodes.get(value) === undefined;
|
|
2709
|
+
return copy2;
|
|
2710
|
+
}
|
|
2711
|
+
const length = value.length;
|
|
2712
|
+
if (length > 8)
|
|
2713
|
+
return;
|
|
2714
|
+
if (named === 2 /* All */ && namedKeys(value) !== undefined)
|
|
2715
|
+
return;
|
|
2716
|
+
const copy = new Array(length);
|
|
2717
|
+
let fresh = checkFresh && locationNodes.get(value) === undefined;
|
|
2718
|
+
for (let i = 0;i < length; i++) {
|
|
2719
|
+
const item = value[i];
|
|
2720
|
+
if (item === null || typeof item !== "object") {
|
|
2721
|
+
if (item !== undefined || i in value)
|
|
2722
|
+
copy[i] = item;
|
|
2723
|
+
continue;
|
|
2724
|
+
}
|
|
2725
|
+
if (item === container || toRaw(item) !== item)
|
|
2726
|
+
return;
|
|
2727
|
+
const leaf = copyLeaf(item);
|
|
2728
|
+
if (leaf === undefined)
|
|
2729
|
+
return;
|
|
2730
|
+
copy[i] = leaf;
|
|
2731
|
+
if (fresh)
|
|
2732
|
+
fresh = locationNodes.get(item) === undefined && value.indexOf(item) === i;
|
|
2650
2733
|
}
|
|
2651
|
-
if (
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
return
|
|
2734
|
+
if (checkFresh)
|
|
2735
|
+
copiedFresh = fresh;
|
|
2736
|
+
return copy;
|
|
2737
|
+
}
|
|
2738
|
+
function copyLeaf(value) {
|
|
2739
|
+
if (Object.getPrototypeOf(value) !== Object.prototype)
|
|
2740
|
+
return;
|
|
2741
|
+
const copy = {};
|
|
2742
|
+
for (const key in value) {
|
|
2743
|
+
if (!hasOwn.call(value, key))
|
|
2744
|
+
continue;
|
|
2745
|
+
const entry = value[key];
|
|
2746
|
+
if (entry !== null && typeof entry === "object")
|
|
2747
|
+
return;
|
|
2748
|
+
if (key === "__proto__")
|
|
2749
|
+
setData(copy, key, entry);
|
|
2750
|
+
else
|
|
2751
|
+
copy[key] = entry;
|
|
2658
2752
|
}
|
|
2659
|
-
if (value
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
return
|
|
2753
|
+
if (Object.getOwnPropertySymbols(value).length !== 0)
|
|
2754
|
+
return;
|
|
2755
|
+
return copy;
|
|
2756
|
+
}
|
|
2757
|
+
function readsOf(identity) {
|
|
2758
|
+
if (identity !== cloneContainer)
|
|
2759
|
+
return identity;
|
|
2760
|
+
if (cloneContents === undefined)
|
|
2761
|
+
throw reachedContainer;
|
|
2762
|
+
return cloneContents;
|
|
2763
|
+
}
|
|
2764
|
+
function countCopy() {
|
|
2765
|
+
if (--cloneCountdown === 0) {
|
|
2766
|
+
if (cloneFresh)
|
|
2767
|
+
cloneCountdown = SNAPSHOT_CHECK_AFTER;
|
|
2768
|
+
else
|
|
2769
|
+
checkSharedCopies(cloneTop);
|
|
2666
2770
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
return newSet;
|
|
2771
|
+
}
|
|
2772
|
+
function noteFresh(value) {
|
|
2773
|
+
const identity = toRaw(value);
|
|
2774
|
+
if (identity !== value || identity === cloneTop || locationNodes.get(identity) !== undefined) {
|
|
2775
|
+
cloneFresh = false;
|
|
2776
|
+
return;
|
|
2674
2777
|
}
|
|
2675
|
-
const
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
newObject[key] = deepClone(value[key], seen);
|
|
2680
|
-
}
|
|
2778
|
+
const first = cloneFirst;
|
|
2779
|
+
if (first === undefined) {
|
|
2780
|
+
cloneFirst = identity;
|
|
2781
|
+
return;
|
|
2681
2782
|
}
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
if (descriptor && Object.prototype.propertyIsEnumerable.call(value, symbolKey)) {
|
|
2686
|
-
newObject[symbolKey] = deepClone(value[symbolKey], seen);
|
|
2687
|
-
}
|
|
2783
|
+
if (identity === first) {
|
|
2784
|
+
cloneFresh = false;
|
|
2785
|
+
return;
|
|
2688
2786
|
}
|
|
2689
|
-
|
|
2787
|
+
let seen = cloneSeen;
|
|
2788
|
+
if (seen === undefined) {
|
|
2789
|
+
seen = cloneSeen = new Set;
|
|
2790
|
+
seen.add(first);
|
|
2791
|
+
}
|
|
2792
|
+
const size = seen.size;
|
|
2793
|
+
seen.add(identity);
|
|
2794
|
+
if (seen.size === size)
|
|
2795
|
+
cloneFresh = false;
|
|
2690
2796
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2797
|
+
function namedKeys(array) {
|
|
2798
|
+
const keys = Object.keys(array);
|
|
2799
|
+
let start = keys.length;
|
|
2800
|
+
while (start > 0 && !isIndexKey(keys[start - 1]))
|
|
2801
|
+
start--;
|
|
2802
|
+
const symbols = Object.getOwnPropertySymbols(array);
|
|
2803
|
+
let names = start === keys.length ? undefined : keys.slice(start);
|
|
2804
|
+
for (let i = 0;i < symbols.length; i++) {
|
|
2805
|
+
if (isEnumerable.call(array, symbols[i]))
|
|
2806
|
+
(names ??= []).push(symbols[i]);
|
|
2807
|
+
}
|
|
2808
|
+
return names;
|
|
2696
2809
|
}
|
|
2697
|
-
function
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2810
|
+
function isIndexKey(key) {
|
|
2811
|
+
const length = key.length;
|
|
2812
|
+
if (length === 0 || length > 10)
|
|
2813
|
+
return false;
|
|
2814
|
+
const first = key.charCodeAt(0);
|
|
2815
|
+
if (first < 48 || first > 57 || first === 48 && length > 1)
|
|
2816
|
+
return false;
|
|
2817
|
+
for (let i = 1;i < length; i++) {
|
|
2818
|
+
const code = key.charCodeAt(i);
|
|
2819
|
+
if (code < 48 || code > 57)
|
|
2820
|
+
return false;
|
|
2821
|
+
}
|
|
2822
|
+
return length < 10 || Number(key) < 4294967295;
|
|
2702
2823
|
}
|
|
2703
|
-
function
|
|
2704
|
-
|
|
2705
|
-
obj.delete(key);
|
|
2706
|
-
else
|
|
2707
|
-
delete obj[key];
|
|
2824
|
+
function setData(object, key, value) {
|
|
2825
|
+
Object.defineProperty(object, key, { value, writable: true, enumerable: true, configurable: true });
|
|
2708
2826
|
}
|
|
2709
|
-
function
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2827
|
+
function checkSharedCopies(value) {
|
|
2828
|
+
const walk = { extra: 0, low: Infinity, marks: new Map };
|
|
2829
|
+
walkCopies(value, walk);
|
|
2830
|
+
if (walk.extra > SNAPSHOT_SHARED_COPY_LIMIT)
|
|
2831
|
+
throw new SnapshotLimitError(walk.extra);
|
|
2832
|
+
}
|
|
2833
|
+
function walkCopies(top, walk) {
|
|
2834
|
+
const frames = [];
|
|
2835
|
+
enterCopies(top, 0, walk, frames);
|
|
2836
|
+
while (frames.length > 0) {
|
|
2837
|
+
const frame = frames[frames.length - 1];
|
|
2838
|
+
if (frame.next < frame.entries.length && walk.extra <= SNAPSHOT_SHARED_COPY_LIMIT) {
|
|
2839
|
+
const entry = frame.entries[frame.next++];
|
|
2840
|
+
if (entry === null || typeof entry !== "object") {
|
|
2841
|
+
walk.low = Infinity;
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
const size = enterCopies(entry, frame.depth + 1, walk, frames);
|
|
2845
|
+
if (frames[frames.length - 1] !== frame)
|
|
2846
|
+
continue;
|
|
2847
|
+
frame.size += size;
|
|
2848
|
+
if (walk.low < frame.low)
|
|
2849
|
+
frame.low = walk.low;
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
frames.pop();
|
|
2853
|
+
walk.marks.set(frame.identity, frame.low > frame.depth ? frame.size : -1);
|
|
2854
|
+
walk.low = frame.low;
|
|
2855
|
+
const below = frames[frames.length - 1];
|
|
2856
|
+
if (below !== undefined) {
|
|
2857
|
+
below.size += frame.size;
|
|
2858
|
+
if (frame.low < below.low)
|
|
2859
|
+
below.low = frame.low;
|
|
2860
|
+
}
|
|
2718
2861
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2862
|
+
}
|
|
2863
|
+
function enterCopies(value, depth, walk, frames) {
|
|
2864
|
+
const identity = toRaw(value);
|
|
2865
|
+
const source = identity === cloneContainer ? readsOf(identity) : identity;
|
|
2866
|
+
const marks = walk.marks;
|
|
2867
|
+
const mark = marks.get(identity);
|
|
2868
|
+
if (mark !== undefined) {
|
|
2869
|
+
if (mark <= -2) {
|
|
2870
|
+
walk.low = -mark - 2;
|
|
2871
|
+
return 0;
|
|
2872
|
+
}
|
|
2873
|
+
walk.low = Infinity;
|
|
2874
|
+
if (mark > 0) {
|
|
2875
|
+
walk.extra += mark;
|
|
2876
|
+
return mark;
|
|
2877
|
+
}
|
|
2878
|
+
walk.extra++;
|
|
2879
|
+
}
|
|
2880
|
+
if (walk.extra > SNAPSHOT_SHARED_COPY_LIMIT) {
|
|
2881
|
+
if (mark === undefined)
|
|
2882
|
+
marks.set(identity, 1);
|
|
2883
|
+
walk.low = Infinity;
|
|
2884
|
+
return 1;
|
|
2885
|
+
}
|
|
2886
|
+
marks.set(identity, -(depth + 2));
|
|
2887
|
+
frames.push({ identity, depth, entries: entriesOf(source, identity), next: 0, size: 1, low: Infinity });
|
|
2888
|
+
return 0;
|
|
2889
|
+
}
|
|
2890
|
+
function entriesOf(source, identity) {
|
|
2891
|
+
if (Array.isArray(source)) {
|
|
2892
|
+
const names = keepsNamed(cloneNamed, identity === cloneTop ? 0 : 1) ? namedKeys(source) : undefined;
|
|
2893
|
+
if (names === undefined)
|
|
2894
|
+
return source;
|
|
2895
|
+
const entries2 = source.slice();
|
|
2896
|
+
for (let i = 0;i < names.length; i++)
|
|
2897
|
+
entries2.push(source[names[i]]);
|
|
2898
|
+
return entries2;
|
|
2899
|
+
}
|
|
2900
|
+
const entries = [];
|
|
2901
|
+
if (source instanceof Map) {
|
|
2902
|
+
for (const [key, entry] of Map.prototype.entries.call(source))
|
|
2903
|
+
entries.push(key, entry);
|
|
2904
|
+
} else if (source instanceof Set) {
|
|
2905
|
+
for (const entry of Set.prototype.values.call(source))
|
|
2906
|
+
entries.push(entry);
|
|
2907
|
+
}
|
|
2908
|
+
for (const key in source)
|
|
2909
|
+
if (hasOwn.call(source, key))
|
|
2910
|
+
entries.push(source[key]);
|
|
2911
|
+
const symbolKeys = Object.getOwnPropertySymbols(source);
|
|
2912
|
+
for (let i = 0;i < symbolKeys.length; i++) {
|
|
2913
|
+
if (isEnumerable.call(source, symbolKeys[i]))
|
|
2914
|
+
entries.push(source[symbolKeys[i]]);
|
|
2915
|
+
}
|
|
2916
|
+
return entries;
|
|
2917
|
+
}
|
|
2918
|
+
var cloneAncestors = [];
|
|
2919
|
+
var cloneCopies = [];
|
|
2920
|
+
var cloneBase = 0;
|
|
2921
|
+
var cloneIndex;
|
|
2922
|
+
var DEEP_PATH = 64;
|
|
2923
|
+
var cloneWork = [];
|
|
2924
|
+
var FILL_DEPTH = 256;
|
|
2925
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
2926
|
+
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
|
2927
|
+
function enterPath(identity, copy, depth) {
|
|
2928
|
+
cloneAncestors.push(identity);
|
|
2929
|
+
cloneCopies.push(copy);
|
|
2930
|
+
if (depth < DEEP_PATH)
|
|
2931
|
+
return;
|
|
2932
|
+
if (cloneIndex !== undefined) {
|
|
2933
|
+
cloneIndex.set(identity, copy);
|
|
2721
2934
|
return;
|
|
2722
2935
|
}
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
evictDescendantsFromPathCache(root, pathKey);
|
|
2727
|
-
return;
|
|
2936
|
+
cloneIndex = new Map;
|
|
2937
|
+
for (let i = cloneBase;i < cloneAncestors.length; i++)
|
|
2938
|
+
cloneIndex.set(cloneAncestors[i], cloneCopies[i]);
|
|
2728
2939
|
}
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2940
|
+
function leavePath(length) {
|
|
2941
|
+
const ancestors = cloneAncestors;
|
|
2942
|
+
const index = cloneIndex;
|
|
2943
|
+
while (ancestors.length > length) {
|
|
2944
|
+
const identity = ancestors.pop();
|
|
2945
|
+
cloneCopies.pop();
|
|
2946
|
+
if (index !== undefined)
|
|
2947
|
+
index.delete(identity);
|
|
2948
|
+
}
|
|
2949
|
+
if (index !== undefined && length - cloneBase <= DEEP_PATH)
|
|
2950
|
+
cloneIndex = undefined;
|
|
2951
|
+
}
|
|
2952
|
+
function cloneValue(value, depth, named) {
|
|
2953
|
+
if (value === null || typeof value !== "object")
|
|
2954
|
+
return value;
|
|
2955
|
+
if (cloneFresh)
|
|
2956
|
+
noteFresh(value);
|
|
2957
|
+
return cloneEntry(value, depth, named);
|
|
2958
|
+
}
|
|
2959
|
+
function keepsNamed(named, depth) {
|
|
2960
|
+
return named === 2 /* All */ || named === 1 /* Below */ && depth > 0;
|
|
2961
|
+
}
|
|
2962
|
+
function cloneEntry(value, depth, named) {
|
|
2963
|
+
const identity = toRaw(value);
|
|
2964
|
+
if (identity === cloneContainer)
|
|
2965
|
+
value = readsOf(identity);
|
|
2966
|
+
if (depth > DEEP_PATH) {
|
|
2967
|
+
const ancestor = cloneIndex.get(identity);
|
|
2968
|
+
if (ancestor !== undefined)
|
|
2969
|
+
return ancestor;
|
|
2970
|
+
} else {
|
|
2971
|
+
const ancestors = cloneAncestors;
|
|
2972
|
+
for (let i = ancestors.length - 1, stop = ancestors.length - depth;i >= stop; i--) {
|
|
2973
|
+
if (ancestors[i] === identity)
|
|
2974
|
+
return cloneCopies[i];
|
|
2734
2975
|
}
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2976
|
+
}
|
|
2977
|
+
countCopy();
|
|
2978
|
+
let copy;
|
|
2979
|
+
let kind;
|
|
2980
|
+
if (Array.isArray(value)) {
|
|
2981
|
+
copy = new Array(value.length);
|
|
2982
|
+
kind = 1 /* Array */;
|
|
2983
|
+
} else {
|
|
2984
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2985
|
+
if (prototype === Object.prototype) {
|
|
2986
|
+
copy = {};
|
|
2987
|
+
kind = 0 /* Object */;
|
|
2988
|
+
} else if (value instanceof Date) {
|
|
2989
|
+
copy = new Date(value.getTime());
|
|
2990
|
+
kind = 0 /* Object */;
|
|
2991
|
+
} else if (value instanceof Map) {
|
|
2992
|
+
copy = new Map;
|
|
2993
|
+
kind = 2 /* Map */;
|
|
2994
|
+
} else if (value instanceof Set) {
|
|
2995
|
+
copy = new Set;
|
|
2996
|
+
kind = 3 /* Set */;
|
|
2997
|
+
} else {
|
|
2998
|
+
copy = Object.create(prototype);
|
|
2999
|
+
kind = 0 /* Object */;
|
|
2744
3000
|
}
|
|
2745
|
-
|
|
2746
|
-
|
|
3001
|
+
}
|
|
3002
|
+
if (depth >= FILL_DEPTH - 1) {
|
|
3003
|
+
cloneDeep(kind, value, identity, copy, depth, named);
|
|
3004
|
+
return copy;
|
|
3005
|
+
}
|
|
3006
|
+
const below = depth + 1;
|
|
3007
|
+
let pushed = false;
|
|
3008
|
+
if (kind === 0 /* Object */) {
|
|
3009
|
+
for (const key in value) {
|
|
3010
|
+
if (!hasOwn.call(value, key))
|
|
3011
|
+
continue;
|
|
3012
|
+
let child = value[key];
|
|
3013
|
+
if (child !== null && typeof child === "object") {
|
|
3014
|
+
if (!pushed) {
|
|
3015
|
+
pushed = true;
|
|
3016
|
+
enterPath(identity, copy, depth);
|
|
3017
|
+
}
|
|
3018
|
+
if (cloneFresh)
|
|
3019
|
+
noteFresh(child);
|
|
3020
|
+
child = cloneEntry(child, below, named);
|
|
3021
|
+
}
|
|
3022
|
+
if (key === "__proto__")
|
|
3023
|
+
setData(copy, key, child);
|
|
3024
|
+
else
|
|
3025
|
+
copy[key] = child;
|
|
3026
|
+
}
|
|
3027
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
3028
|
+
if (symbolKeys.length !== 0)
|
|
3029
|
+
pushed = fillSymbols(value, identity, copy, depth, named, symbolKeys, pushed);
|
|
3030
|
+
} else if (kind === 1 /* Array */) {
|
|
3031
|
+
const length = copy.length;
|
|
3032
|
+
for (let i = 0;i < length; i++) {
|
|
3033
|
+
const child = value[i];
|
|
3034
|
+
if (child === null || typeof child !== "object") {
|
|
3035
|
+
if (child !== undefined || i in value)
|
|
3036
|
+
copy[i] = child;
|
|
3037
|
+
continue;
|
|
3038
|
+
}
|
|
3039
|
+
if (!pushed) {
|
|
3040
|
+
pushed = true;
|
|
3041
|
+
enterPath(identity, copy, depth);
|
|
3042
|
+
}
|
|
3043
|
+
if (cloneFresh)
|
|
3044
|
+
noteFresh(child);
|
|
3045
|
+
copy[i] = cloneEntry(child, below, named);
|
|
3046
|
+
}
|
|
3047
|
+
if (keepsNamed(named, depth))
|
|
3048
|
+
pushed = fillNamed(value, identity, copy, depth, named, pushed);
|
|
3049
|
+
} else {
|
|
3050
|
+
pushed = kind === 2 /* Map */ ? fillMap(value, identity, copy, depth, named) : fillSet(value, identity, copy, depth, named);
|
|
3051
|
+
}
|
|
3052
|
+
if (pushed) {
|
|
3053
|
+
if (depth < DEEP_PATH) {
|
|
3054
|
+
cloneAncestors.pop();
|
|
3055
|
+
cloneCopies.pop();
|
|
3056
|
+
} else {
|
|
3057
|
+
leavePath(cloneAncestors.length - 1);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
return copy;
|
|
3061
|
+
}
|
|
3062
|
+
function cloneDeep(kind, value, identity, copy, depth, named) {
|
|
3063
|
+
const pathLength = cloneAncestors.length;
|
|
3064
|
+
if (depth >= FILL_DEPTH) {
|
|
3065
|
+
cloneWork.push(kind, value, identity, copy, pathLength);
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3068
|
+
const workBase = cloneWork.length;
|
|
3069
|
+
fill(kind, value, identity, copy, depth, named);
|
|
3070
|
+
fillWaiting(workBase);
|
|
3071
|
+
leavePath(pathLength);
|
|
3072
|
+
}
|
|
3073
|
+
function fill(kind, value, identity, copy, depth, named) {
|
|
3074
|
+
if (kind === 0 /* Object */)
|
|
3075
|
+
fillObject(value, identity, copy, depth, named);
|
|
3076
|
+
else if (kind === 1 /* Array */)
|
|
3077
|
+
fillArray(value, identity, copy, depth, named);
|
|
3078
|
+
else if (kind === 2 /* Map */)
|
|
3079
|
+
fillMap(value, identity, copy, depth, named);
|
|
3080
|
+
else
|
|
3081
|
+
fillSet(value, identity, copy, depth, named);
|
|
3082
|
+
}
|
|
3083
|
+
function fillWaiting(workBase) {
|
|
3084
|
+
const work = cloneWork;
|
|
3085
|
+
while (work.length > workBase) {
|
|
3086
|
+
const at = work.length - 5;
|
|
3087
|
+
const kind = work[at];
|
|
3088
|
+
const value = work[at + 1];
|
|
3089
|
+
const identity = work[at + 2];
|
|
3090
|
+
const copy = work[at + 3];
|
|
3091
|
+
const pathLength = work[at + 4];
|
|
3092
|
+
work.length = at;
|
|
3093
|
+
if (cloneAncestors.length !== pathLength)
|
|
3094
|
+
leavePath(pathLength);
|
|
3095
|
+
fill(kind, value, identity, copy, FILL_DEPTH, cloneNamed);
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
function fillObject(value, identity, copy, depth, named) {
|
|
3099
|
+
const below = depth + 1;
|
|
3100
|
+
let pushed = false;
|
|
3101
|
+
for (const key in value) {
|
|
3102
|
+
if (!hasOwn.call(value, key))
|
|
3103
|
+
continue;
|
|
3104
|
+
let child = value[key];
|
|
3105
|
+
if (child !== null && typeof child === "object") {
|
|
3106
|
+
if (!pushed) {
|
|
3107
|
+
pushed = true;
|
|
3108
|
+
enterPath(identity, copy, depth);
|
|
3109
|
+
}
|
|
3110
|
+
if (cloneFresh)
|
|
3111
|
+
noteFresh(child);
|
|
3112
|
+
child = cloneEntry(child, below, named);
|
|
3113
|
+
}
|
|
3114
|
+
if (key === "__proto__")
|
|
3115
|
+
setData(copy, key, child);
|
|
3116
|
+
else
|
|
3117
|
+
copy[key] = child;
|
|
3118
|
+
}
|
|
3119
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
3120
|
+
return symbolKeys.length === 0 ? pushed : fillSymbols(value, identity, copy, depth, named, symbolKeys, pushed);
|
|
3121
|
+
}
|
|
3122
|
+
function fillSymbols(value, identity, copy, depth, named, symbolKeys, pushed) {
|
|
3123
|
+
const below = depth + 1;
|
|
3124
|
+
for (let i = 0;i < symbolKeys.length; i++) {
|
|
3125
|
+
const symbolKey = symbolKeys[i];
|
|
3126
|
+
if (!isEnumerable.call(value, symbolKey))
|
|
3127
|
+
continue;
|
|
3128
|
+
const child = value[symbolKey];
|
|
3129
|
+
if (child !== null && typeof child === "object" && !pushed) {
|
|
3130
|
+
pushed = true;
|
|
3131
|
+
enterPath(identity, copy, depth);
|
|
3132
|
+
}
|
|
3133
|
+
copy[symbolKey] = cloneValue(child, below, named);
|
|
3134
|
+
}
|
|
3135
|
+
return pushed;
|
|
3136
|
+
}
|
|
3137
|
+
function fillArray(value, identity, copy, depth, named) {
|
|
3138
|
+
const below = depth + 1;
|
|
3139
|
+
let pushed = false;
|
|
3140
|
+
const length = copy.length;
|
|
3141
|
+
for (let i = 0;i < length; i++) {
|
|
3142
|
+
const child = value[i];
|
|
3143
|
+
if (child === null || typeof child !== "object") {
|
|
3144
|
+
if (child !== undefined || i in value)
|
|
3145
|
+
copy[i] = child;
|
|
3146
|
+
continue;
|
|
3147
|
+
}
|
|
3148
|
+
if (!pushed) {
|
|
3149
|
+
pushed = true;
|
|
3150
|
+
enterPath(identity, copy, depth);
|
|
3151
|
+
}
|
|
3152
|
+
if (cloneFresh)
|
|
3153
|
+
noteFresh(child);
|
|
3154
|
+
copy[i] = cloneEntry(child, below, named);
|
|
3155
|
+
}
|
|
3156
|
+
return keepsNamed(named, depth) ? fillNamed(value, identity, copy, depth, named, pushed) : pushed;
|
|
3157
|
+
}
|
|
3158
|
+
function fillNamed(value, identity, copy, depth, named, pushed) {
|
|
3159
|
+
const names = namedKeys(value);
|
|
3160
|
+
if (names === undefined)
|
|
3161
|
+
return pushed;
|
|
3162
|
+
const below = depth + 1;
|
|
3163
|
+
for (let i = 0;i < names.length; i++) {
|
|
3164
|
+
const child = value[names[i]];
|
|
3165
|
+
if (child !== null && typeof child === "object" && !pushed) {
|
|
3166
|
+
pushed = true;
|
|
3167
|
+
enterPath(identity, copy, depth);
|
|
3168
|
+
}
|
|
3169
|
+
setData(copy, names[i], cloneValue(child, below, named));
|
|
3170
|
+
}
|
|
3171
|
+
return pushed;
|
|
3172
|
+
}
|
|
3173
|
+
function fillMap(value, identity, copy, depth, named) {
|
|
3174
|
+
const below = depth + 1;
|
|
3175
|
+
enterPath(identity, copy, depth);
|
|
3176
|
+
const entries = toRaw(value);
|
|
3177
|
+
Map.prototype.forEach.call(entries, (entry, key) => {
|
|
3178
|
+
const keyCopy = cloneValue(key, below, named);
|
|
3179
|
+
copy.set(nameMember(key, keyCopy, entries, false), cloneValue(entry, below, named));
|
|
3180
|
+
});
|
|
3181
|
+
fillCollectionProperties(entries, copy, below, named);
|
|
3182
|
+
return true;
|
|
3183
|
+
}
|
|
3184
|
+
function fillSet(value, identity, copy, depth, named) {
|
|
3185
|
+
const below = depth + 1;
|
|
3186
|
+
enterPath(identity, copy, depth);
|
|
3187
|
+
const members = toRaw(value);
|
|
3188
|
+
let later;
|
|
3189
|
+
Set.prototype.forEach.call(members, (entry) => {
|
|
3190
|
+
if (entry === null || typeof entry !== "object") {
|
|
3191
|
+
copy.add(entry);
|
|
2747
3192
|
return;
|
|
2748
3193
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
if (
|
|
2753
|
-
|
|
3194
|
+
const raw = toRaw(entry);
|
|
3195
|
+
if (raw !== entry && later === undefined && Set.prototype.has.call(members, raw))
|
|
3196
|
+
later = laterTwins(members);
|
|
3197
|
+
if (later !== undefined && later.has(entry))
|
|
3198
|
+
return;
|
|
3199
|
+
const entryCopy = cloneValue(entry, below, named);
|
|
3200
|
+
if (copyingPayload)
|
|
3201
|
+
nameCopyOfCopy(entry, entryCopy);
|
|
3202
|
+
else
|
|
3203
|
+
nameRaw(raw, collectionIdentities.members.get(raw), entry, entryCopy, members, false);
|
|
3204
|
+
copy.add(entryCopy);
|
|
3205
|
+
});
|
|
3206
|
+
fillCollectionProperties(members, copy, below, named);
|
|
3207
|
+
return true;
|
|
3208
|
+
}
|
|
3209
|
+
function laterTwins(set) {
|
|
3210
|
+
const seen = new Set;
|
|
3211
|
+
const later = new Set;
|
|
3212
|
+
Set.prototype.forEach.call(set, (member) => {
|
|
3213
|
+
if (member === null || typeof member !== "object")
|
|
2754
3214
|
return;
|
|
3215
|
+
const raw = toRaw(member);
|
|
3216
|
+
if (seen.has(raw))
|
|
3217
|
+
later.add(member);
|
|
3218
|
+
else
|
|
3219
|
+
seen.add(raw);
|
|
3220
|
+
});
|
|
3221
|
+
return later;
|
|
3222
|
+
}
|
|
3223
|
+
function fillCollectionProperties(value, copy, depth, named) {
|
|
3224
|
+
for (const key in value) {
|
|
3225
|
+
if (hasOwn.call(value, key))
|
|
3226
|
+
setData(copy, key, cloneValue(value[key], depth, named));
|
|
3227
|
+
}
|
|
3228
|
+
const symbols = Object.getOwnPropertySymbols(value);
|
|
3229
|
+
for (let i = 0;i < symbols.length; i++) {
|
|
3230
|
+
if (isEnumerable.call(value, symbols[i]))
|
|
3231
|
+
setData(copy, symbols[i], cloneValue(value[symbols[i]], depth, named));
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
var collectionIdentityKey = Symbol.for("@yiin/reactive-proxy-state.collection-identities.v4");
|
|
3235
|
+
var collectionIdentities = Reflect.get(globalThis, collectionIdentityKey) ?? { members: new WeakMap, copies: new WeakMap, indexes: new WeakMap, overrides: new WeakMap, watches: new WeakMap };
|
|
3236
|
+
if (!Reflect.has(globalThis, collectionIdentityKey)) {
|
|
3237
|
+
Object.defineProperty(globalThis, collectionIdentityKey, { value: collectionIdentities });
|
|
3238
|
+
}
|
|
3239
|
+
function ownToken(member) {
|
|
3240
|
+
const token = { shared: false };
|
|
3241
|
+
collectionIdentities.members.set(member, token);
|
|
3242
|
+
return token;
|
|
3243
|
+
}
|
|
3244
|
+
function nameMember(member, copy, collection, entering) {
|
|
3245
|
+
if (member === null || typeof member !== "object" || copy === null || typeof copy !== "object")
|
|
3246
|
+
return copy;
|
|
3247
|
+
if (copyingPayload) {
|
|
3248
|
+
nameCopyOfCopy(member, copy);
|
|
3249
|
+
return copy;
|
|
3250
|
+
}
|
|
3251
|
+
const raw = toRaw(member);
|
|
3252
|
+
const own = collectionIdentities.members.get(raw);
|
|
3253
|
+
if (own === undefined || own.shared)
|
|
3254
|
+
return nameRaw(raw, own, member, copy, collection, entering);
|
|
3255
|
+
if (copy !== member)
|
|
3256
|
+
collectionIdentities.copies.set(copy, own);
|
|
3257
|
+
return copy;
|
|
3258
|
+
}
|
|
3259
|
+
function nameKey(event, key, collection, entering) {
|
|
3260
|
+
const raw = toRaw(key);
|
|
3261
|
+
const own = collectionIdentities.members.get(raw);
|
|
3262
|
+
if (own === undefined) {
|
|
3263
|
+
if (entering)
|
|
3264
|
+
ownToken(raw);
|
|
3265
|
+
else
|
|
3266
|
+
namedInPlace(raw, collection);
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
if (!own.shared)
|
|
3270
|
+
return;
|
|
3271
|
+
event.key = nameRaw(raw, own, key, key, collection, entering);
|
|
3272
|
+
}
|
|
3273
|
+
function nameRaw(raw, own, member, copy, collection, entering) {
|
|
3274
|
+
let token;
|
|
3275
|
+
if (own === undefined)
|
|
3276
|
+
token = entering ? ownToken(raw) : namedInPlace(raw, collection);
|
|
3277
|
+
else if (!own.shared)
|
|
3278
|
+
token = own;
|
|
3279
|
+
else
|
|
3280
|
+
token = sharedTokenIn(raw, own, collection, entering);
|
|
3281
|
+
if (copy !== member) {
|
|
3282
|
+
collectionIdentities.copies.set(copy, token);
|
|
3283
|
+
return copy;
|
|
3284
|
+
}
|
|
3285
|
+
return own === undefined || token === own ? copy : carrier(raw, token);
|
|
3286
|
+
}
|
|
3287
|
+
function namedInPlace(member, collection) {
|
|
3288
|
+
const origin = collectionIdentities.copies.get(member);
|
|
3289
|
+
if (origin === undefined)
|
|
3290
|
+
return ownToken(member);
|
|
3291
|
+
const index = replicaIndex(collection, true);
|
|
3292
|
+
const held = heldMember(collection, index, origin);
|
|
3293
|
+
if (held !== undefined && held !== member) {
|
|
3294
|
+
const token = ownToken(member);
|
|
3295
|
+
index.byToken.set(token, member);
|
|
3296
|
+
return token;
|
|
3297
|
+
}
|
|
3298
|
+
origin.shared = true;
|
|
3299
|
+
collectionIdentities.members.set(member, origin);
|
|
3300
|
+
index.byToken.set(origin, member);
|
|
3301
|
+
return origin;
|
|
3302
|
+
}
|
|
3303
|
+
function sharedTokenIn(member, token, collection, entering) {
|
|
3304
|
+
let inCollection = collectionIdentities.overrides.get(collection);
|
|
3305
|
+
const current = inCollection?.get(member) ?? token;
|
|
3306
|
+
if (!entering)
|
|
3307
|
+
return current;
|
|
3308
|
+
const index = replicaIndex(collection, true);
|
|
3309
|
+
const held = heldMember(collection, index, current);
|
|
3310
|
+
if (held === undefined || held === member)
|
|
3311
|
+
return current;
|
|
3312
|
+
const other = { shared: false };
|
|
3313
|
+
if (inCollection === undefined)
|
|
3314
|
+
collectionIdentities.overrides.set(collection, inCollection = new WeakMap);
|
|
3315
|
+
inCollection.set(member, other);
|
|
3316
|
+
index.byToken.set(other, member);
|
|
3317
|
+
return other;
|
|
3318
|
+
}
|
|
3319
|
+
function carrier(member, token) {
|
|
3320
|
+
const copy = cloneTree(member, 2 /* All */);
|
|
3321
|
+
collectionIdentities.copies.set(copy, token);
|
|
3322
|
+
return copy;
|
|
3323
|
+
}
|
|
3324
|
+
function nameCopyOfCopy(source, copy) {
|
|
3325
|
+
if (source === null || typeof source !== "object" || copy === null || typeof copy !== "object")
|
|
3326
|
+
return;
|
|
3327
|
+
const token = collectionIdentities.copies.get(source) ?? collectionIdentities.members.get(source);
|
|
3328
|
+
if (token !== undefined)
|
|
3329
|
+
collectionIdentities.copies.set(copy, token);
|
|
3330
|
+
}
|
|
3331
|
+
var copyingPayload = false;
|
|
3332
|
+
function copyingPayloads(run) {
|
|
3333
|
+
const outer = copyingPayload;
|
|
3334
|
+
copyingPayload = true;
|
|
3335
|
+
try {
|
|
3336
|
+
return run();
|
|
3337
|
+
} finally {
|
|
3338
|
+
copyingPayload = outer;
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
function eventToken(member) {
|
|
3342
|
+
const raw = toRaw(member);
|
|
3343
|
+
return collectionIdentities.members.get(raw) ?? collectionIdentities.copies.get(raw);
|
|
3344
|
+
}
|
|
3345
|
+
function replicaIndex(collection, member) {
|
|
3346
|
+
let index = collectionIdentities.indexes.get(collection);
|
|
3347
|
+
const size = collection.size;
|
|
3348
|
+
if (index === undefined || index.size !== size || index.member !== member) {
|
|
3349
|
+
const byToken = new Map;
|
|
3350
|
+
const overrides = member ? collectionIdentities.overrides.get(collection) : undefined;
|
|
3351
|
+
const members = collection instanceof Map ? Map.prototype.keys.call(collection) : Set.prototype.values.call(collection);
|
|
3352
|
+
for (const held of members) {
|
|
3353
|
+
if (held === null || typeof held !== "object")
|
|
3354
|
+
continue;
|
|
3355
|
+
const raw = toRaw(held);
|
|
3356
|
+
if (member) {
|
|
3357
|
+
const own = overrides?.get(raw) ?? collectionIdentities.members.get(raw);
|
|
3358
|
+
if (own !== undefined) {
|
|
3359
|
+
byToken.set(own, held);
|
|
3360
|
+
continue;
|
|
3361
|
+
}
|
|
3362
|
+
const origin = collectionIdentities.copies.get(raw);
|
|
3363
|
+
if (origin !== undefined && !byToken.has(origin))
|
|
3364
|
+
byToken.set(origin, held);
|
|
3365
|
+
} else {
|
|
3366
|
+
const token = collectionIdentities.copies.get(raw) ?? collectionIdentities.members.get(raw);
|
|
3367
|
+
if (token !== undefined && !byToken.has(token))
|
|
3368
|
+
byToken.set(token, held);
|
|
3369
|
+
}
|
|
2755
3370
|
}
|
|
2756
|
-
|
|
2757
|
-
|
|
3371
|
+
index = { byToken, size, member };
|
|
3372
|
+
collectionIdentities.indexes.set(collection, index);
|
|
3373
|
+
const watch = indexWatches.get(collection);
|
|
3374
|
+
if (watch !== undefined)
|
|
3375
|
+
watch.indexed = true;
|
|
3376
|
+
}
|
|
3377
|
+
return index;
|
|
3378
|
+
}
|
|
3379
|
+
var indexWatches = collectionIdentities.watches;
|
|
3380
|
+
function watchIndex(collection) {
|
|
3381
|
+
const watch = { indexed: collectionIdentities.indexes.has(collection) };
|
|
3382
|
+
indexWatches.set(collection, watch);
|
|
3383
|
+
return watch;
|
|
3384
|
+
}
|
|
3385
|
+
function heldToken(collection, member) {
|
|
3386
|
+
return collectionIdentities.overrides.get(collection)?.get(member) ?? collectionIdentities.members.get(member);
|
|
3387
|
+
}
|
|
3388
|
+
function indexAdded(collection, member) {
|
|
3389
|
+
const index = collectionIdentities.indexes.get(collection);
|
|
3390
|
+
if (index === undefined)
|
|
3391
|
+
return;
|
|
3392
|
+
if (!index.member || index.size !== collection.size - 1) {
|
|
3393
|
+
collectionIdentities.indexes.delete(collection);
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
index.size = collection.size;
|
|
3397
|
+
if (member === null || typeof member !== "object")
|
|
3398
|
+
return;
|
|
3399
|
+
const raw = toRaw(member);
|
|
3400
|
+
const own = heldToken(collection, raw);
|
|
3401
|
+
if (own !== undefined) {
|
|
3402
|
+
index.byToken.set(own, member);
|
|
3403
|
+
return;
|
|
3404
|
+
}
|
|
3405
|
+
const origin = collectionIdentities.copies.get(raw);
|
|
3406
|
+
if (origin !== undefined && !index.byToken.has(origin))
|
|
3407
|
+
index.byToken.set(origin, member);
|
|
3408
|
+
}
|
|
3409
|
+
function indexRemoved(collection, member) {
|
|
3410
|
+
const index = collectionIdentities.indexes.get(collection);
|
|
3411
|
+
if (index === undefined)
|
|
3412
|
+
return;
|
|
3413
|
+
if (!index.member || index.size !== collection.size + 1) {
|
|
3414
|
+
collectionIdentities.indexes.delete(collection);
|
|
3415
|
+
return;
|
|
3416
|
+
}
|
|
3417
|
+
index.size = collection.size;
|
|
3418
|
+
if (member === null || typeof member !== "object")
|
|
3419
|
+
return;
|
|
3420
|
+
const raw = toRaw(member);
|
|
3421
|
+
const token = heldToken(collection, raw) ?? collectionIdentities.copies.get(raw);
|
|
3422
|
+
if (token !== undefined && index.byToken.get(token) === member)
|
|
3423
|
+
index.byToken.delete(token);
|
|
3424
|
+
}
|
|
3425
|
+
function keepIndexSize(collection) {
|
|
3426
|
+
const index = collectionIdentities.indexes.get(collection);
|
|
3427
|
+
if (index !== undefined)
|
|
3428
|
+
index.size = collection.size;
|
|
3429
|
+
}
|
|
3430
|
+
function heldMember(raw, index, token) {
|
|
3431
|
+
const held = index.byToken.get(token);
|
|
3432
|
+
return held !== undefined && raw.has(held) ? held : undefined;
|
|
3433
|
+
}
|
|
3434
|
+
function newMember(raw, member, token, reactive) {
|
|
3435
|
+
let added = member;
|
|
3436
|
+
if (raw.has(member)) {
|
|
3437
|
+
added = cloneTree(member, 2 /* All */);
|
|
3438
|
+
collectionIdentities.copies.set(added, token);
|
|
3439
|
+
}
|
|
3440
|
+
if (reactive && !collectionIdentities.members.has(added)) {
|
|
3441
|
+
token.shared = true;
|
|
3442
|
+
collectionIdentities.members.set(added, token);
|
|
3443
|
+
}
|
|
3444
|
+
return added;
|
|
3445
|
+
}
|
|
3446
|
+
function objectToken(value) {
|
|
3447
|
+
return value !== null && typeof value === "object" ? eventToken(value) : undefined;
|
|
3448
|
+
}
|
|
3449
|
+
function replicaAdd(set, value) {
|
|
3450
|
+
const raw = toRaw(set);
|
|
3451
|
+
const token = objectToken(value);
|
|
3452
|
+
if (token === undefined) {
|
|
3453
|
+
set.add(value);
|
|
3454
|
+
keepIndexSize(raw);
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
const index = replicaIndex(raw, raw !== set);
|
|
3458
|
+
if (heldMember(raw, index, token) !== undefined)
|
|
3459
|
+
return;
|
|
3460
|
+
const member = newMember(raw, toRaw(value), token, set !== raw);
|
|
3461
|
+
set.add(member);
|
|
3462
|
+
index.byToken.set(token, member);
|
|
3463
|
+
index.size = raw.size;
|
|
3464
|
+
}
|
|
3465
|
+
function replicaDelete(set, value) {
|
|
3466
|
+
const raw = toRaw(set);
|
|
3467
|
+
const token = objectToken(value);
|
|
3468
|
+
if (token === undefined) {
|
|
3469
|
+
set.delete(value);
|
|
3470
|
+
keepIndexSize(raw);
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
const index = replicaIndex(raw, raw !== set);
|
|
3474
|
+
const held = heldMember(raw, index, token);
|
|
3475
|
+
set.delete(held === undefined ? value : held);
|
|
3476
|
+
index.byToken.delete(token);
|
|
3477
|
+
index.size = raw.size;
|
|
3478
|
+
}
|
|
3479
|
+
function replicaMapSet(map, key, value) {
|
|
3480
|
+
const raw = toRaw(map);
|
|
3481
|
+
const token = objectToken(key);
|
|
3482
|
+
if (token === undefined) {
|
|
3483
|
+
map.set(key, value);
|
|
3484
|
+
keepIndexSize(raw);
|
|
3485
|
+
return;
|
|
3486
|
+
}
|
|
3487
|
+
const index = replicaIndex(raw, raw !== map);
|
|
3488
|
+
const held = heldMember(raw, index, token);
|
|
3489
|
+
if (held !== undefined) {
|
|
3490
|
+
map.set(held, value);
|
|
3491
|
+
return;
|
|
3492
|
+
}
|
|
3493
|
+
const member = newMember(raw, toRaw(key), token, map !== raw);
|
|
3494
|
+
map.set(member, value);
|
|
3495
|
+
index.byToken.set(token, member);
|
|
3496
|
+
index.size = raw.size;
|
|
3497
|
+
}
|
|
3498
|
+
function replicaMapDelete(map, key) {
|
|
3499
|
+
const raw = toRaw(map);
|
|
3500
|
+
const token = objectToken(key);
|
|
3501
|
+
if (token === undefined) {
|
|
3502
|
+
map.delete(key);
|
|
3503
|
+
keepIndexSize(raw);
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
const index = replicaIndex(raw, raw !== map);
|
|
3507
|
+
const held = heldMember(raw, index, token);
|
|
3508
|
+
map.delete(held === undefined ? key : held);
|
|
3509
|
+
index.byToken.delete(token);
|
|
3510
|
+
index.size = raw.size;
|
|
3511
|
+
}
|
|
3512
|
+
function forgetReplicaIndex(collection) {
|
|
3513
|
+
collectionIdentities.indexes.delete(toRaw(collection));
|
|
3514
|
+
}
|
|
3515
|
+
function deepClone(value, seen = new WeakMap) {
|
|
3516
|
+
if (value === null || typeof value !== "object") {
|
|
3517
|
+
return value;
|
|
3518
|
+
}
|
|
3519
|
+
if (value instanceof Date) {
|
|
3520
|
+
return new Date(value.getTime());
|
|
3521
|
+
}
|
|
3522
|
+
const identity = toRaw(value);
|
|
3523
|
+
if (seen.has(identity)) {
|
|
3524
|
+
return seen.get(identity);
|
|
3525
|
+
}
|
|
3526
|
+
if (Array.isArray(value)) {
|
|
3527
|
+
const newArray = [];
|
|
3528
|
+
seen.set(identity, newArray);
|
|
3529
|
+
for (let i = 0;i < value.length; i++) {
|
|
3530
|
+
newArray[i] = deepClone(value[i], seen);
|
|
2758
3531
|
}
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
3532
|
+
return newArray;
|
|
3533
|
+
}
|
|
3534
|
+
if (value instanceof Map) {
|
|
3535
|
+
const newMap = new Map;
|
|
3536
|
+
seen.set(identity, newMap);
|
|
3537
|
+
value.forEach((val, key) => {
|
|
3538
|
+
newMap.set(deepClone(key, seen), deepClone(val, seen));
|
|
3539
|
+
});
|
|
3540
|
+
return newMap;
|
|
3541
|
+
}
|
|
3542
|
+
if (value instanceof Set) {
|
|
3543
|
+
const newSet = new Set;
|
|
3544
|
+
seen.set(identity, newSet);
|
|
3545
|
+
value.forEach((val) => {
|
|
3546
|
+
newSet.add(deepClone(val, seen));
|
|
3547
|
+
});
|
|
3548
|
+
return newSet;
|
|
3549
|
+
}
|
|
3550
|
+
const newObject = Object.create(Object.getPrototypeOf(value));
|
|
3551
|
+
seen.set(identity, newObject);
|
|
3552
|
+
for (const key in value) {
|
|
3553
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
3554
|
+
newObject[key] = deepClone(value[key], seen);
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
3558
|
+
for (const symbolKey of symbolKeys) {
|
|
3559
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, symbolKey);
|
|
3560
|
+
if (descriptor && Object.prototype.propertyIsEnumerable.call(value, symbolKey)) {
|
|
3561
|
+
newObject[symbolKey] = deepClone(value[symbolKey], seen);
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
return newObject;
|
|
3565
|
+
}
|
|
3566
|
+
// src/location.ts
|
|
3567
|
+
class Place {
|
|
3568
|
+
parentRef;
|
|
3569
|
+
parentId;
|
|
3570
|
+
key;
|
|
3571
|
+
constructor(parent, key) {
|
|
3572
|
+
this.parentRef = new WeakRef(parent);
|
|
3573
|
+
this.parentId = parent.id;
|
|
3574
|
+
this.key = key;
|
|
3575
|
+
parent.childPlaces++;
|
|
3576
|
+
}
|
|
3577
|
+
get parent() {
|
|
3578
|
+
return this.parentRef.deref();
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
function dropped(place) {
|
|
3582
|
+
const parent = place.parent;
|
|
3583
|
+
if (parent !== undefined)
|
|
3584
|
+
parent.childPlaces--;
|
|
3585
|
+
}
|
|
3586
|
+
var WIDE = 8;
|
|
3587
|
+
var nodes = locationNodes;
|
|
3588
|
+
var nodeCount = 0;
|
|
3589
|
+
var FAST_CHAIN_LIMIT = 256;
|
|
3590
|
+
function isObject2(value) {
|
|
3591
|
+
return value !== null && typeof value === "object";
|
|
3592
|
+
}
|
|
3593
|
+
function getLocationNode(raw) {
|
|
3594
|
+
return nodes.get(raw);
|
|
3595
|
+
}
|
|
3596
|
+
function ensureLocationNode(raw) {
|
|
3597
|
+
let node = nodes.get(raw);
|
|
3598
|
+
if (node === undefined) {
|
|
3599
|
+
node = {
|
|
3600
|
+
id: ++nodeCount,
|
|
3601
|
+
raw,
|
|
3602
|
+
kind: raw instanceof Map ? 1 /* Map */ : raw instanceof Set ? 2 /* Set */ : 0 /* Plain */,
|
|
3603
|
+
places: [],
|
|
3604
|
+
root: undefined,
|
|
3605
|
+
scope: undefined,
|
|
3606
|
+
proxy: undefined,
|
|
3607
|
+
evicted: undefined,
|
|
3608
|
+
relinked: 0,
|
|
3609
|
+
relinkedPlaces: 0,
|
|
3610
|
+
lostLink: false,
|
|
3611
|
+
dataOnly: undefined,
|
|
3612
|
+
childPlaces: 0,
|
|
3613
|
+
walk: 0,
|
|
3614
|
+
touched: 0,
|
|
3615
|
+
pruned: 0,
|
|
3616
|
+
index: undefined
|
|
3617
|
+
};
|
|
3618
|
+
nodes.set(raw, node);
|
|
3619
|
+
}
|
|
3620
|
+
return node;
|
|
3621
|
+
}
|
|
3622
|
+
function writesThroughSetter(target, prop, node) {
|
|
3623
|
+
let dataOnly = node.dataOnly;
|
|
3624
|
+
if (dataOnly === undefined)
|
|
3625
|
+
dataOnly = node.dataOnly = hasNoOwnAccessor(target);
|
|
3626
|
+
if (dataOnly)
|
|
3627
|
+
return false;
|
|
3628
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
3629
|
+
return descriptor !== undefined && descriptor.set !== undefined;
|
|
3630
|
+
}
|
|
3631
|
+
function hasNoOwnAccessor(target) {
|
|
3632
|
+
const keys = Reflect.ownKeys(target);
|
|
3633
|
+
if (keys.length > 64)
|
|
3634
|
+
return false;
|
|
3635
|
+
for (let i = 0;i < keys.length; i++) {
|
|
3636
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, keys[i]);
|
|
3637
|
+
if (descriptor.get !== undefined || descriptor.set !== undefined)
|
|
3638
|
+
return false;
|
|
3639
|
+
}
|
|
3640
|
+
return true;
|
|
3641
|
+
}
|
|
3642
|
+
function holdsIn(parent, key, raw) {
|
|
3643
|
+
if (parent === undefined)
|
|
3644
|
+
return false;
|
|
3645
|
+
const container = parent.raw;
|
|
3646
|
+
switch (parent.kind) {
|
|
3647
|
+
case 1 /* Map */: {
|
|
3648
|
+
const held = container.get(key);
|
|
3649
|
+
return held === raw || proxyOf(held, raw);
|
|
3650
|
+
}
|
|
3651
|
+
case 2 /* Set */:
|
|
3652
|
+
return container.has(raw);
|
|
3653
|
+
default: {
|
|
3654
|
+
const held = container[key];
|
|
3655
|
+
return held === raw || proxyOf(held, raw);
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
function proxyOf(held, raw) {
|
|
3660
|
+
return isObject2(held) && held["__v_raw" /* RAW */] !== undefined && toRaw(held) === raw;
|
|
3661
|
+
}
|
|
3662
|
+
function holds(place, raw) {
|
|
3663
|
+
return holdsIn(place.parent, place.key, raw);
|
|
3664
|
+
}
|
|
3665
|
+
function segment(parent, key, raw) {
|
|
3666
|
+
if (parent.kind === 2 /* Set */) {
|
|
3667
|
+
let index = 0;
|
|
3668
|
+
for (const member of parent.raw) {
|
|
3669
|
+
if (member === raw)
|
|
3670
|
+
break;
|
|
3671
|
+
index++;
|
|
3672
|
+
}
|
|
3673
|
+
return String(index);
|
|
3674
|
+
}
|
|
3675
|
+
return String(key);
|
|
3676
|
+
}
|
|
3677
|
+
function samePlace(place, parent, key) {
|
|
3678
|
+
return place.parentId === parent.id && (parent.kind === 2 /* Set */ || place.key === key);
|
|
3679
|
+
}
|
|
3680
|
+
function chain(node, tail) {
|
|
3681
|
+
let reversed;
|
|
3682
|
+
let current = node;
|
|
3683
|
+
for (let steps = 0;steps < FAST_CHAIN_LIMIT; steps++) {
|
|
3684
|
+
const places = current.places;
|
|
3685
|
+
const root = current.root;
|
|
3686
|
+
if (root !== undefined) {
|
|
3687
|
+
if (places.length !== 0)
|
|
3688
|
+
return;
|
|
3689
|
+
return { root, paths: [buildPath(root.path, reversed, tail)] };
|
|
3690
|
+
}
|
|
3691
|
+
if (places.length !== 1)
|
|
3692
|
+
return places.length === 0 ? null : undefined;
|
|
3693
|
+
const place = places[0];
|
|
3694
|
+
const parent = place.parent;
|
|
3695
|
+
if (!holdsIn(parent, place.key, current.raw)) {
|
|
3696
|
+
dropped(place);
|
|
3697
|
+
current.places = [];
|
|
3698
|
+
return null;
|
|
3699
|
+
}
|
|
3700
|
+
(reversed ??= []).push(segment(parent, place.key, current.raw));
|
|
3701
|
+
current = parent;
|
|
3702
|
+
}
|
|
3703
|
+
return;
|
|
3704
|
+
}
|
|
3705
|
+
function findAll(node, tail, firstOnly) {
|
|
3706
|
+
const out = [];
|
|
3707
|
+
const segments = [];
|
|
3708
|
+
const visiting = new Set;
|
|
3709
|
+
const frames = [];
|
|
3710
|
+
const enter = (entered) => {
|
|
3711
|
+
visiting.add(entered);
|
|
3712
|
+
const root = entered.root;
|
|
3713
|
+
if (root !== undefined)
|
|
3714
|
+
out.push({ root, path: buildPath(root.path, segments, tail) });
|
|
3715
|
+
frames.push({ node: entered, places: entered.places, next: 0, stale: false });
|
|
3716
|
+
};
|
|
3717
|
+
enter(node);
|
|
3718
|
+
while (frames.length > 0) {
|
|
3719
|
+
const frame = frames[frames.length - 1];
|
|
3720
|
+
const current = frame.node;
|
|
3721
|
+
if (frame.next < frame.places.length && !(firstOnly && out.length > 0)) {
|
|
3722
|
+
const place = frame.places[frame.next++];
|
|
3723
|
+
const parent = place.parent;
|
|
3724
|
+
if (!holdsIn(parent, place.key, current.raw)) {
|
|
3725
|
+
frame.stale = true;
|
|
3726
|
+
continue;
|
|
3727
|
+
}
|
|
3728
|
+
if (visiting.has(parent))
|
|
3729
|
+
continue;
|
|
3730
|
+
segments.push(segment(parent, place.key, current.raw));
|
|
3731
|
+
enter(parent);
|
|
3732
|
+
continue;
|
|
3733
|
+
}
|
|
3734
|
+
frames.pop();
|
|
3735
|
+
if (frame.stale)
|
|
3736
|
+
current.places = keepPlaces(frame.places, (place) => holds(place, current.raw));
|
|
3737
|
+
visiting.delete(current);
|
|
3738
|
+
if (frames.length > 0)
|
|
3739
|
+
segments.pop();
|
|
3740
|
+
}
|
|
3741
|
+
return out;
|
|
3742
|
+
}
|
|
3743
|
+
function buildPath(base, reversed, tail) {
|
|
3744
|
+
const middle = reversed === undefined ? 0 : reversed.length;
|
|
3745
|
+
const path = new Array(base.length + middle + (tail === undefined ? 0 : 1));
|
|
3746
|
+
let index = 0;
|
|
3747
|
+
for (let i = 0;i < base.length; i++)
|
|
3748
|
+
path[index++] = base[i];
|
|
3749
|
+
for (let i = middle - 1;i >= 0; i--)
|
|
3750
|
+
path[index++] = reversed[i];
|
|
3751
|
+
if (tail !== undefined)
|
|
3752
|
+
path[index] = String(tail);
|
|
3753
|
+
return path;
|
|
3754
|
+
}
|
|
3755
|
+
function locate(node, tail) {
|
|
3756
|
+
const single = chain(node, tail);
|
|
3757
|
+
if (single !== undefined) {
|
|
3758
|
+
if (single === null) {
|
|
3759
|
+
proxyStats.detachedWrites++;
|
|
2763
3760
|
return;
|
|
2764
3761
|
}
|
|
2765
|
-
|
|
2766
|
-
|
|
3762
|
+
return single.root.emit === undefined ? undefined : single;
|
|
3763
|
+
}
|
|
3764
|
+
const found = findAll(node, tail, false);
|
|
3765
|
+
if (found.length === 0) {
|
|
3766
|
+
proxyStats.detachedWrites++;
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
let root = found[0].root;
|
|
3770
|
+
for (let i = 1;i < found.length; i++) {
|
|
3771
|
+
if (found[i].root !== root) {
|
|
3772
|
+
if (node.scope !== undefined && found.some((entry) => entry.root === node.scope)) {
|
|
3773
|
+
root = node.scope;
|
|
3774
|
+
}
|
|
3775
|
+
break;
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
if (root.emit === undefined)
|
|
3779
|
+
return;
|
|
3780
|
+
const paths = [];
|
|
3781
|
+
for (let i = 0;i < found.length; i++) {
|
|
3782
|
+
if (found[i].root === root)
|
|
3783
|
+
paths.push(found[i].path);
|
|
3784
|
+
}
|
|
3785
|
+
return { root, paths };
|
|
3786
|
+
}
|
|
3787
|
+
function isAttached(node) {
|
|
3788
|
+
const single = chain(node, undefined);
|
|
3789
|
+
if (single !== undefined)
|
|
3790
|
+
return single !== null;
|
|
3791
|
+
return findAll(node, undefined, true).length > 0;
|
|
3792
|
+
}
|
|
3793
|
+
function attachedBefore(node, former) {
|
|
3794
|
+
let current = node;
|
|
3795
|
+
for (let steps = 0;steps < FAST_CHAIN_LIMIT; steps++) {
|
|
3796
|
+
if (current.root !== undefined || current === former)
|
|
3797
|
+
return true;
|
|
3798
|
+
const places = current.places;
|
|
3799
|
+
if (places.length !== 1)
|
|
3800
|
+
break;
|
|
3801
|
+
const place = places[0];
|
|
3802
|
+
const parent = place.parent;
|
|
3803
|
+
if (!holdsIn(parent, place.key, current.raw))
|
|
3804
|
+
return false;
|
|
3805
|
+
current = parent;
|
|
3806
|
+
}
|
|
3807
|
+
if (current.root !== undefined || current === former)
|
|
3808
|
+
return true;
|
|
3809
|
+
const visited = new Set;
|
|
3810
|
+
visited.add(current);
|
|
3811
|
+
const stack = [current];
|
|
3812
|
+
const next = [0];
|
|
3813
|
+
while (stack.length > 0) {
|
|
3814
|
+
const top = stack.length - 1;
|
|
3815
|
+
const at = stack[top];
|
|
3816
|
+
const places = at.places;
|
|
3817
|
+
if (next[top] >= places.length) {
|
|
3818
|
+
stack.pop();
|
|
3819
|
+
next.pop();
|
|
3820
|
+
continue;
|
|
3821
|
+
}
|
|
3822
|
+
const place = places[next[top]++];
|
|
3823
|
+
const parent = place.parent;
|
|
3824
|
+
if (!holdsIn(parent, place.key, at.raw))
|
|
3825
|
+
continue;
|
|
3826
|
+
if (parent.root !== undefined || parent === former)
|
|
3827
|
+
return true;
|
|
3828
|
+
if (visited.has(parent))
|
|
3829
|
+
continue;
|
|
3830
|
+
visited.add(parent);
|
|
3831
|
+
stack.push(parent);
|
|
3832
|
+
next.push(0);
|
|
3833
|
+
}
|
|
3834
|
+
return false;
|
|
3835
|
+
}
|
|
3836
|
+
function dispatch(target, event) {
|
|
3837
|
+
const { root, paths } = target;
|
|
3838
|
+
if (paths.length === 1) {
|
|
3839
|
+
if (root.undelivered === undefined)
|
|
3840
|
+
root.emit(event);
|
|
3841
|
+
else
|
|
3842
|
+
deliver(root, [event]);
|
|
3843
|
+
return;
|
|
3844
|
+
}
|
|
3845
|
+
deliver(root, copyingPayloads(() => copiesPerPath(event, paths, root.async)));
|
|
3846
|
+
}
|
|
3847
|
+
function copiesPerPath(event, paths, async) {
|
|
3848
|
+
const removesValue = event.action === "set-delete";
|
|
3849
|
+
const events = [event];
|
|
3850
|
+
for (let i = 1;i < paths.length; i++) {
|
|
3851
|
+
const copy = { ...event, path: paths[i] };
|
|
3852
|
+
if (isObject2(event.newValue))
|
|
3853
|
+
copy.newValue = cloneTree(event.newValue, event.action === "replace" ? 1 /* Below */ : 0 /* None */);
|
|
3854
|
+
if (isObject2(event.value) && !removesValue) {
|
|
3855
|
+
copy.value = cloneTree(event.value, 2 /* All */);
|
|
3856
|
+
nameCopyOfCopy(event.value, copy.value);
|
|
3857
|
+
}
|
|
3858
|
+
if (event.items !== undefined)
|
|
3859
|
+
copy.items = cloneTree(event.items, 1 /* Below */);
|
|
3860
|
+
if (async) {
|
|
3861
|
+
if (isObject2(event.oldValue))
|
|
3862
|
+
copy.oldValue = cloneTree(event.oldValue, 2 /* All */);
|
|
3863
|
+
if (event.oldValues !== undefined)
|
|
3864
|
+
copy.oldValues = cloneTree(event.oldValues, 1 /* Below */);
|
|
3865
|
+
if (removesValue) {
|
|
3866
|
+
copy.value = copy.oldValue;
|
|
3867
|
+
nameCopyOfCopy(event.value, copy.value);
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
events.push(copy);
|
|
3871
|
+
}
|
|
3872
|
+
return events;
|
|
3873
|
+
}
|
|
3874
|
+
function deliver(root, events) {
|
|
3875
|
+
const emit = root.emit;
|
|
3876
|
+
let queue = root.undelivered;
|
|
3877
|
+
if (queue === undefined) {
|
|
3878
|
+
if (events.length === 1) {
|
|
3879
|
+
emit(events[0]);
|
|
2767
3880
|
return;
|
|
2768
3881
|
}
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
3882
|
+
queue = root.undelivered = { events, next: 0 };
|
|
3883
|
+
} else {
|
|
3884
|
+
for (let i = 0;i < events.length; i++)
|
|
3885
|
+
queue.events.push(events[i]);
|
|
3886
|
+
}
|
|
3887
|
+
let failed = false;
|
|
3888
|
+
let failure;
|
|
3889
|
+
while (queue.next < queue.events.length) {
|
|
3890
|
+
try {
|
|
3891
|
+
emit(queue.events[queue.next++]);
|
|
3892
|
+
} catch (error) {
|
|
3893
|
+
if (!failed) {
|
|
3894
|
+
failed = true;
|
|
3895
|
+
failure = error;
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
if (root.undelivered === queue)
|
|
3900
|
+
root.undelivered = undefined;
|
|
3901
|
+
if (failed)
|
|
3902
|
+
throw failure;
|
|
3903
|
+
}
|
|
3904
|
+
function copyPayload(event, target, container, held) {
|
|
3905
|
+
if (event === undefined)
|
|
3906
|
+
return 1 /* Done */;
|
|
3907
|
+
const removed = target.root.async;
|
|
3908
|
+
const { newValue, oldValue, value, items, oldValues } = event;
|
|
3909
|
+
const stored = event.action !== "set-delete";
|
|
3910
|
+
let fresh = true;
|
|
3911
|
+
let newCopy = newValue;
|
|
3912
|
+
if (isObject2(newValue)) {
|
|
3913
|
+
newCopy = held === undefined ? cloneStored(newValue, container, event.action === "replace" ? 1 /* Below */ : 0 /* None */) : cloneTreeUnless(newValue, container, event.action === "replace" ? 1 /* Below */ : 0 /* None */);
|
|
3914
|
+
if (newCopy === REACHES)
|
|
3915
|
+
return 0 /* Reaches */;
|
|
3916
|
+
fresh = held === undefined && copiedFresh;
|
|
3917
|
+
}
|
|
3918
|
+
let valueCopy = value;
|
|
3919
|
+
if (isObject2(value) && stored) {
|
|
3920
|
+
valueCopy = cloneStored(value, container, 2 /* All */);
|
|
3921
|
+
if (valueCopy === REACHES)
|
|
3922
|
+
return 0 /* Reaches */;
|
|
3923
|
+
fresh &&= copiedFresh;
|
|
3924
|
+
}
|
|
3925
|
+
let itemsCopy = items;
|
|
3926
|
+
if (items !== undefined && holdsObject(items)) {
|
|
3927
|
+
itemsCopy = cloneStored(items, container, 1 /* Below */);
|
|
3928
|
+
if (itemsCopy === REACHES)
|
|
3929
|
+
return 0 /* Reaches */;
|
|
3930
|
+
fresh &&= copiedFresh;
|
|
3931
|
+
}
|
|
3932
|
+
if (removed) {
|
|
3933
|
+
const oldCopy = isObject2(oldValue) ? cloneTreeUnless(oldValue, container, 2 /* All */) : oldValue;
|
|
3934
|
+
if (oldCopy === REACHES)
|
|
3935
|
+
return 0 /* Reaches */;
|
|
3936
|
+
const oldValuesCopy = oldValues !== undefined && holdsObject(oldValues) ? cloneTreeUnless(oldValues, container, 1 /* Below */) : oldValues;
|
|
3937
|
+
if (oldValuesCopy === REACHES)
|
|
3938
|
+
return 0 /* Reaches */;
|
|
3939
|
+
if (isObject2(oldValue))
|
|
3940
|
+
event.oldValue = oldCopy;
|
|
3941
|
+
if (oldValues !== undefined)
|
|
3942
|
+
event.oldValues = oldValuesCopy;
|
|
3943
|
+
if (!stored)
|
|
3944
|
+
valueCopy = event.oldValue;
|
|
3945
|
+
}
|
|
3946
|
+
if (isObject2(newValue))
|
|
3947
|
+
event.newValue = newCopy;
|
|
3948
|
+
if (isObject2(value))
|
|
3949
|
+
event.value = nameMember(value, valueCopy, container, stored);
|
|
3950
|
+
if (items !== undefined)
|
|
3951
|
+
event.items = itemsCopy;
|
|
3952
|
+
return fresh ? 2 /* Fresh */ : 1 /* Done */;
|
|
3953
|
+
}
|
|
3954
|
+
function copyPayloadReaching(event, target, container, after) {
|
|
3955
|
+
refuseAccessors(event, target.root.async, container, after);
|
|
3956
|
+
copyPayloadAfter(event, target, container, after);
|
|
3957
|
+
}
|
|
3958
|
+
function copyPayloadAfter(event, target, container, after) {
|
|
3959
|
+
const { newValue, oldValue, value, items, oldValues } = event;
|
|
3960
|
+
const removed = target.root.async;
|
|
3961
|
+
const stored = event.action !== "set-delete";
|
|
3962
|
+
const newCopy = isObject2(newValue) ? cloneTreeAfter(newValue, container, after, event.action === "replace" ? 1 /* Below */ : 0 /* None */) : newValue;
|
|
3963
|
+
const oldCopy = removed && isObject2(oldValue) ? cloneTreeAfter(oldValue, container, after, 2 /* All */) : oldValue;
|
|
3964
|
+
const valueCopy = !isObject2(value) ? value : stored ? cloneTreeAfter(value, container, after, 2 /* All */) : oldCopy;
|
|
3965
|
+
const itemsCopy = items !== undefined && holdsObject(items) ? cloneTreeAfter(items, container, after, 1 /* Below */) : items;
|
|
3966
|
+
const oldValuesCopy = removed && oldValues !== undefined && holdsObject(oldValues) ? cloneTreeAfter(oldValues, container, after, 1 /* Below */) : oldValues;
|
|
3967
|
+
if (isObject2(newValue))
|
|
3968
|
+
event.newValue = newCopy;
|
|
3969
|
+
if (isObject2(oldValue))
|
|
3970
|
+
event.oldValue = oldCopy;
|
|
3971
|
+
if (isObject2(value))
|
|
3972
|
+
event.value = nameMember(value, valueCopy, container, stored);
|
|
3973
|
+
if (items !== undefined)
|
|
3974
|
+
event.items = itemsCopy;
|
|
3975
|
+
if (oldValues !== undefined)
|
|
3976
|
+
event.oldValues = oldValuesCopy;
|
|
3977
|
+
}
|
|
3978
|
+
function holdsObject(values) {
|
|
3979
|
+
for (let i = 0;i < values.length; i++)
|
|
3980
|
+
if (isObject2(values[i]))
|
|
3981
|
+
return true;
|
|
3982
|
+
return false;
|
|
3983
|
+
}
|
|
3984
|
+
function shallowCopy(container) {
|
|
3985
|
+
const copy = Array.isArray(container) ? container.slice() : container instanceof Map ? new Map(Map.prototype.entries.call(container)) : container instanceof Set ? new Set(Set.prototype.values.call(container)) : Object.create(Object.getPrototypeOf(container));
|
|
3986
|
+
const keys = Reflect.ownKeys(container);
|
|
3987
|
+
for (let i = 0;i < keys.length; i++) {
|
|
3988
|
+
const value = enumerableData(container, keys[i]);
|
|
3989
|
+
if (value !== NOT_ENUMERABLE)
|
|
3990
|
+
setData(copy, keys[i], value);
|
|
3991
|
+
}
|
|
3992
|
+
return copy;
|
|
3993
|
+
}
|
|
3994
|
+
var NOT_ENUMERABLE = Symbol("not enumerable");
|
|
3995
|
+
function enumerableData(object, key) {
|
|
3996
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
3997
|
+
if (!descriptor.enumerable)
|
|
3998
|
+
return NOT_ENUMERABLE;
|
|
3999
|
+
if (descriptor.get !== undefined || descriptor.set !== undefined) {
|
|
4000
|
+
throw new UnsupportedStateError(`the accessor property '${String(key)}' sits in a payload that reaches back into the ` + `object it is written to, and a getter cannot be read as it will be after the write`);
|
|
4001
|
+
}
|
|
4002
|
+
return descriptor.value;
|
|
4003
|
+
}
|
|
4004
|
+
function refuseAccessors(event, removed, container, after) {
|
|
4005
|
+
const pending = [event.newValue];
|
|
4006
|
+
if (event.action !== "set-delete")
|
|
4007
|
+
pending.push(event.value);
|
|
4008
|
+
if (event.items !== undefined)
|
|
4009
|
+
pending.push(event.items);
|
|
4010
|
+
if (removed) {
|
|
4011
|
+
pending.push(event.oldValue);
|
|
4012
|
+
if (event.oldValues !== undefined)
|
|
4013
|
+
pending.push(event.oldValues);
|
|
4014
|
+
}
|
|
4015
|
+
const seen = new Set;
|
|
4016
|
+
while (pending.length > 0) {
|
|
4017
|
+
const entry = pending.pop();
|
|
4018
|
+
if (!isObject2(entry))
|
|
4019
|
+
continue;
|
|
4020
|
+
let value = toRaw(entry);
|
|
4021
|
+
if (value === container)
|
|
4022
|
+
value = after;
|
|
4023
|
+
if (seen.has(value))
|
|
4024
|
+
continue;
|
|
4025
|
+
seen.add(value);
|
|
4026
|
+
if (Array.isArray(value)) {
|
|
4027
|
+
for (let i = 0;i < value.length; i++)
|
|
4028
|
+
pending.push(value[i]);
|
|
4029
|
+
} else if (value instanceof Map) {
|
|
4030
|
+
for (const [key, item] of Map.prototype.entries.call(value))
|
|
4031
|
+
pending.push(key, item);
|
|
4032
|
+
} else if (value instanceof Set) {
|
|
4033
|
+
for (const item of Set.prototype.values.call(value))
|
|
4034
|
+
pending.push(item);
|
|
4035
|
+
}
|
|
4036
|
+
const keys = Reflect.ownKeys(value);
|
|
4037
|
+
for (let i = 0;i < keys.length; i++) {
|
|
4038
|
+
const item = enumerableData(value, keys[i]);
|
|
4039
|
+
if (item !== NOT_ENUMERABLE)
|
|
4040
|
+
pending.push(item);
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
function addPlace(node, parent, key) {
|
|
4045
|
+
if (findPlace(node, parent, key) !== undefined)
|
|
4046
|
+
return false;
|
|
4047
|
+
pushPlace(node, new Place(parent, key));
|
|
4048
|
+
return true;
|
|
4049
|
+
}
|
|
4050
|
+
function findPlace(node, parent, key) {
|
|
4051
|
+
const places = node.places;
|
|
4052
|
+
if (places.length <= WIDE) {
|
|
4053
|
+
for (let i = 0;i < places.length; i++) {
|
|
4054
|
+
if (samePlace(places[i], parent, key))
|
|
4055
|
+
return places[i];
|
|
2773
4056
|
}
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
4057
|
+
return;
|
|
4058
|
+
}
|
|
4059
|
+
let index = node.index;
|
|
4060
|
+
if (index === undefined || index.places !== places || index.length !== places.length) {
|
|
4061
|
+
index = node.index = { places, length: places.length, byParent: new Map };
|
|
4062
|
+
for (let i = 0;i < places.length; i++)
|
|
4063
|
+
indexPlace(index.byParent, places[i]);
|
|
4064
|
+
}
|
|
4065
|
+
const entry = index.byParent.get(parent.id);
|
|
4066
|
+
if (entry === undefined)
|
|
4067
|
+
return;
|
|
4068
|
+
if (entry instanceof Place)
|
|
4069
|
+
return parent.kind === 2 /* Set */ || entry.key === key ? entry : undefined;
|
|
4070
|
+
return entry.get(key);
|
|
4071
|
+
}
|
|
4072
|
+
function indexPlace(byParent, place) {
|
|
4073
|
+
const entry = byParent.get(place.parentId);
|
|
4074
|
+
if (entry === undefined)
|
|
4075
|
+
byParent.set(place.parentId, place);
|
|
4076
|
+
else if (entry instanceof Place) {
|
|
4077
|
+
if (entry.key !== place.key)
|
|
4078
|
+
byParent.set(place.parentId, new Map([[entry.key, entry], [place.key, place]]));
|
|
4079
|
+
} else if (!entry.has(place.key))
|
|
4080
|
+
entry.set(place.key, place);
|
|
4081
|
+
}
|
|
4082
|
+
function pushPlace(node, place) {
|
|
4083
|
+
const places = node.places;
|
|
4084
|
+
places.push(place);
|
|
4085
|
+
const index = node.index;
|
|
4086
|
+
if (index !== undefined && index.places === places && index.length === places.length - 1) {
|
|
4087
|
+
index.length++;
|
|
4088
|
+
indexPlace(index.byParent, place);
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
function prunePlaces(node) {
|
|
4092
|
+
const count = node.places.length;
|
|
4093
|
+
if (count > WIDE && count < 2 * node.pruned)
|
|
4094
|
+
return;
|
|
4095
|
+
let places = keepPlaces(node.places, (place) => holds(place, node.raw));
|
|
4096
|
+
if (places.length > 1) {
|
|
4097
|
+
const live = pruneScratch;
|
|
4098
|
+
live.length = places.length;
|
|
4099
|
+
let attached = 0;
|
|
4100
|
+
let parent;
|
|
4101
|
+
let parentAttached = false;
|
|
4102
|
+
for (let i = 0;i < places.length; i++) {
|
|
4103
|
+
const next = places[i].parent;
|
|
4104
|
+
if (next !== parent) {
|
|
4105
|
+
parent = next;
|
|
4106
|
+
parentAttached = isAttached(next);
|
|
4107
|
+
}
|
|
4108
|
+
live[i] = parentAttached;
|
|
4109
|
+
if (parentAttached)
|
|
4110
|
+
attached++;
|
|
4111
|
+
}
|
|
4112
|
+
if (attached > 0 && attached < places.length) {
|
|
4113
|
+
const kept = [];
|
|
4114
|
+
for (let i = 0;i < places.length; i++) {
|
|
4115
|
+
if (live[i])
|
|
4116
|
+
kept.push(places[i]);
|
|
4117
|
+
else {
|
|
4118
|
+
markLostLink(places[i].parent);
|
|
4119
|
+
dropped(places[i]);
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
places = kept;
|
|
2779
4123
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
4124
|
+
}
|
|
4125
|
+
pruneScratch.length = 0;
|
|
4126
|
+
node.places = places;
|
|
4127
|
+
node.pruned = places.length;
|
|
4128
|
+
}
|
|
4129
|
+
var pruneScratch = [];
|
|
4130
|
+
function keepPlaces(places, keep) {
|
|
4131
|
+
const kept = [];
|
|
4132
|
+
for (let i = 0;i < places.length; i++) {
|
|
4133
|
+
if (keep(places[i]))
|
|
4134
|
+
kept.push(places[i]);
|
|
4135
|
+
else
|
|
4136
|
+
dropped(places[i]);
|
|
4137
|
+
}
|
|
4138
|
+
return kept;
|
|
4139
|
+
}
|
|
4140
|
+
function markLostLink(node) {
|
|
4141
|
+
if (node.lostLink)
|
|
4142
|
+
return;
|
|
4143
|
+
node.lostLink = true;
|
|
4144
|
+
const pending = [node];
|
|
4145
|
+
while (pending.length > 0) {
|
|
4146
|
+
const places = pending.pop().places;
|
|
4147
|
+
for (let i = 0;i < places.length; i++) {
|
|
4148
|
+
const parent = places[i].parent;
|
|
4149
|
+
if (parent !== undefined && !parent.lostLink) {
|
|
4150
|
+
parent.lostLink = true;
|
|
4151
|
+
pending.push(parent);
|
|
4152
|
+
}
|
|
2782
4153
|
}
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
function notePlace(node, parent, key) {
|
|
4157
|
+
const places = node.places;
|
|
4158
|
+
if (places.length === 1 && samePlace(places[0], parent, key))
|
|
4159
|
+
return;
|
|
4160
|
+
if (addPlace(node, parent, key) && node.places.length > 1)
|
|
4161
|
+
prunePlaces(node);
|
|
4162
|
+
}
|
|
4163
|
+
function detachPlace(value, parent, key) {
|
|
4164
|
+
const node = nodes.get(value);
|
|
4165
|
+
if (node !== undefined)
|
|
4166
|
+
removePlace(node, parent, key);
|
|
4167
|
+
}
|
|
4168
|
+
function removePlace(node, parent, key) {
|
|
4169
|
+
const places = node.places;
|
|
4170
|
+
if (places.length <= WIDE) {
|
|
4171
|
+
for (let i = 0;i < places.length; i++) {
|
|
4172
|
+
if (samePlace(places[i], parent, key)) {
|
|
4173
|
+
dropped(places[i]);
|
|
4174
|
+
places.splice(i, 1);
|
|
4175
|
+
node.index = undefined;
|
|
4176
|
+
return true;
|
|
4177
|
+
}
|
|
2788
4178
|
}
|
|
2789
|
-
|
|
2790
|
-
|
|
4179
|
+
return false;
|
|
4180
|
+
}
|
|
4181
|
+
const place = findPlace(node, parent, key);
|
|
4182
|
+
if (place === undefined)
|
|
4183
|
+
return false;
|
|
4184
|
+
const at = places.indexOf(place);
|
|
4185
|
+
if (at < 0) {
|
|
4186
|
+
node.index = undefined;
|
|
4187
|
+
return false;
|
|
4188
|
+
}
|
|
4189
|
+
dropped(place);
|
|
4190
|
+
places.splice(at, 1);
|
|
4191
|
+
const index = node.index;
|
|
4192
|
+
index.length--;
|
|
4193
|
+
const entry = index.byParent.get(place.parentId);
|
|
4194
|
+
if (entry === place)
|
|
4195
|
+
index.byParent.delete(place.parentId);
|
|
4196
|
+
else if (entry instanceof Map && entry.get(place.key) === place)
|
|
4197
|
+
entry.delete(place.key);
|
|
4198
|
+
return true;
|
|
4199
|
+
}
|
|
4200
|
+
function newWalk(touched, store, former, held, first) {
|
|
4201
|
+
return {
|
|
4202
|
+
id: ++stamps,
|
|
4203
|
+
store,
|
|
4204
|
+
firstId: nodeCount + 1,
|
|
4205
|
+
touched,
|
|
4206
|
+
seen: new Set,
|
|
4207
|
+
repeated: undefined,
|
|
4208
|
+
aliases: first?.repeated,
|
|
4209
|
+
created: undefined,
|
|
4210
|
+
revisit: first?.created,
|
|
4211
|
+
relinked: [],
|
|
4212
|
+
former,
|
|
4213
|
+
held
|
|
4214
|
+
};
|
|
4215
|
+
}
|
|
4216
|
+
function adoptFrame(raw, node, unknown, key) {
|
|
4217
|
+
let kind = 3 /* Object */;
|
|
4218
|
+
let keys;
|
|
4219
|
+
let entries;
|
|
4220
|
+
if (Array.isArray(raw))
|
|
4221
|
+
kind = 0 /* Array */;
|
|
4222
|
+
else if (raw instanceof Map) {
|
|
4223
|
+
kind = 1 /* Map */;
|
|
4224
|
+
entries = Map.prototype.entries.call(raw);
|
|
4225
|
+
} else if (raw instanceof Set) {
|
|
4226
|
+
kind = 2 /* Set */;
|
|
4227
|
+
entries = Set.prototype.values.call(raw);
|
|
4228
|
+
} else if (raw instanceof Date || ArrayBuffer.isView(raw))
|
|
4229
|
+
kind = 4 /* None */;
|
|
4230
|
+
else
|
|
4231
|
+
keys = Object.keys(raw);
|
|
4232
|
+
return { raw, node, unknown, key, kind, next: 0, keys, entries, childKey: undefined, swaps: undefined };
|
|
4233
|
+
}
|
|
4234
|
+
function nextChild(frame) {
|
|
4235
|
+
const raw = frame.raw;
|
|
4236
|
+
switch (frame.kind) {
|
|
4237
|
+
case 0 /* Array */:
|
|
4238
|
+
while (frame.next < raw.length) {
|
|
4239
|
+
const index = frame.next++;
|
|
4240
|
+
const child = raw[index];
|
|
4241
|
+
if (isObject2(child)) {
|
|
4242
|
+
frame.childKey = index;
|
|
4243
|
+
return child;
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
2791
4246
|
return;
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
4247
|
+
case 1 /* Map */:
|
|
4248
|
+
for (;; ) {
|
|
4249
|
+
const step = frame.entries.next();
|
|
4250
|
+
if (step.done)
|
|
4251
|
+
return;
|
|
4252
|
+
const child = step.value[1];
|
|
4253
|
+
if (isObject2(child)) {
|
|
4254
|
+
frame.childKey = step.value[0];
|
|
4255
|
+
return child;
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
case 2 /* Set */:
|
|
4259
|
+
for (;; ) {
|
|
4260
|
+
const step = frame.entries.next();
|
|
4261
|
+
if (step.done)
|
|
4262
|
+
return;
|
|
4263
|
+
if (isObject2(step.value)) {
|
|
4264
|
+
frame.childKey = undefined;
|
|
4265
|
+
return step.value;
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
case 3 /* Object */: {
|
|
4269
|
+
const keys = frame.keys;
|
|
4270
|
+
while (frame.next < keys.length) {
|
|
4271
|
+
const key = keys[frame.next++];
|
|
4272
|
+
const child = raw[key];
|
|
4273
|
+
if (isObject2(child)) {
|
|
4274
|
+
frame.childKey = key;
|
|
4275
|
+
return child;
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
2798
4278
|
return;
|
|
2799
4279
|
}
|
|
2800
|
-
|
|
2801
|
-
},
|
|
2802
|
-
"map-delete": function(targetMap, _parentKeyIgnored, event) {
|
|
2803
|
-
if (!(targetMap instanceof Map)) {
|
|
2804
|
-
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
4280
|
+
default:
|
|
2805
4281
|
return;
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
function enterAdopt(raw, key, walk, frames) {
|
|
4285
|
+
let node = nodes.get(raw);
|
|
4286
|
+
if (node !== undefined) {
|
|
4287
|
+
if (node.walk === walk.id)
|
|
4288
|
+
return node;
|
|
4289
|
+
node.walk = walk.id;
|
|
4290
|
+
if (!node.lostLink && walk.revisit?.has(raw) !== true) {
|
|
4291
|
+
if (attachedBefore(node, walk.former))
|
|
4292
|
+
return node;
|
|
4293
|
+
if (walk.aliases === undefined)
|
|
4294
|
+
(walk.created ??= new Set).add(raw);
|
|
4295
|
+
}
|
|
4296
|
+
if (node.lostLink)
|
|
4297
|
+
walk.relinked.push(node);
|
|
4298
|
+
frames.push(adoptFrame(raw, node, false, key));
|
|
4299
|
+
return node;
|
|
4300
|
+
}
|
|
4301
|
+
if (raw["__v_skip" /* SKIP */])
|
|
4302
|
+
return;
|
|
4303
|
+
if (raw["__v_isReactive" /* IS_REACTIVE */]) {
|
|
4304
|
+
const target = toRaw(raw);
|
|
4305
|
+
if (frames.length > 0)
|
|
4306
|
+
storeRaw(frames[frames.length - 1], key, raw, target);
|
|
4307
|
+
return enterAdopt(target, key, walk, frames);
|
|
4308
|
+
}
|
|
4309
|
+
const seen = walk.seen;
|
|
4310
|
+
const size = seen.size;
|
|
4311
|
+
seen.add(raw);
|
|
4312
|
+
if (seen.size === size) {
|
|
4313
|
+
(walk.repeated ??= new Set).add(raw);
|
|
4314
|
+
return;
|
|
4315
|
+
}
|
|
4316
|
+
if (walk.aliases?.has(raw))
|
|
4317
|
+
node = walkNode(raw, walk);
|
|
4318
|
+
if (walk.held?.has(raw))
|
|
4319
|
+
return node;
|
|
4320
|
+
frames.push(adoptFrame(raw, node, true, key));
|
|
4321
|
+
return node;
|
|
4322
|
+
}
|
|
4323
|
+
function walkNode(raw, walk) {
|
|
4324
|
+
const node = ensureLocationNode(raw);
|
|
4325
|
+
node.walk = walk.id;
|
|
4326
|
+
return node;
|
|
4327
|
+
}
|
|
4328
|
+
function storeRaw(frame, key, proxy, target) {
|
|
4329
|
+
const container = frame.raw;
|
|
4330
|
+
switch (frame.kind) {
|
|
4331
|
+
case 1 /* Map */:
|
|
4332
|
+
Map.prototype.set.call(container, key, target);
|
|
2812
4333
|
return;
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
},
|
|
2816
|
-
"set-add": function(targetSet, _keyIgnored, event) {
|
|
2817
|
-
if (!(targetSet instanceof Set)) {
|
|
2818
|
-
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
4334
|
+
case 2 /* Set */:
|
|
4335
|
+
(frame.swaps ??= new Map).set(proxy, target);
|
|
2819
4336
|
return;
|
|
4337
|
+
default: {
|
|
4338
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(container, key);
|
|
4339
|
+
if (descriptor !== undefined && descriptor.value === proxy)
|
|
4340
|
+
Reflect.set(container, key, target);
|
|
2820
4341
|
}
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
function swapMembers(set, swaps) {
|
|
4345
|
+
const members = Array.from(Set.prototype.values.call(set));
|
|
4346
|
+
Set.prototype.clear.call(set);
|
|
4347
|
+
for (let i = 0;i < members.length; i++) {
|
|
4348
|
+
const member = members[i];
|
|
4349
|
+
Set.prototype.add.call(set, isObject2(member) && swaps.get(member) || member);
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
function placeChild(frame, key, childNode, walk) {
|
|
4353
|
+
if (childNode === undefined)
|
|
4354
|
+
return;
|
|
4355
|
+
const parent = frame.node ??= walkNode(frame.raw, walk);
|
|
4356
|
+
if (parent.id < walk.firstId && childNode.id < walk.firstId) {
|
|
4357
|
+
if (walk.aliases !== undefined && !walk.aliases.has(childNode.raw))
|
|
2826
4358
|
return;
|
|
2827
|
-
|
|
2828
|
-
targetSet.delete(event.value);
|
|
2829
|
-
},
|
|
2830
|
-
"set-clear": function(targetSet, _keyIgnored, event) {
|
|
2831
|
-
if (!(targetSet instanceof Set)) {
|
|
2832
|
-
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
4359
|
+
if (!addPlace(childNode, parent, key))
|
|
2833
4360
|
return;
|
|
4361
|
+
} else {
|
|
4362
|
+
pushPlace(childNode, new Place(parent, key));
|
|
4363
|
+
}
|
|
4364
|
+
touch(childNode, walk.store, walk.touched);
|
|
4365
|
+
}
|
|
4366
|
+
function touch(node, store, touched) {
|
|
4367
|
+
if (node.touched === store)
|
|
4368
|
+
return;
|
|
4369
|
+
node.touched = store;
|
|
4370
|
+
touched.push(node);
|
|
4371
|
+
}
|
|
4372
|
+
var stamps = 0;
|
|
4373
|
+
function walkFrames(frames, walk) {
|
|
4374
|
+
for (;; ) {
|
|
4375
|
+
const frame = frames[frames.length - 1];
|
|
4376
|
+
const child = nextChild(frame);
|
|
4377
|
+
if (child !== undefined) {
|
|
4378
|
+
const depth = frames.length;
|
|
4379
|
+
const childNode = enterAdopt(child, frame.childKey, walk, frames);
|
|
4380
|
+
if (frames.length === depth)
|
|
4381
|
+
placeChild(frame, frame.childKey, childNode, walk);
|
|
4382
|
+
continue;
|
|
4383
|
+
}
|
|
4384
|
+
frames.pop();
|
|
4385
|
+
if (frame.swaps !== undefined)
|
|
4386
|
+
swapMembers(frame.raw, frame.swaps);
|
|
4387
|
+
const node = frame.node;
|
|
4388
|
+
if (frame.unknown && node !== undefined && walk.aliases === undefined)
|
|
4389
|
+
(walk.created ??= new Set).add(frame.raw);
|
|
4390
|
+
if (frames.length === 0)
|
|
4391
|
+
return node;
|
|
4392
|
+
placeChild(frames[frames.length - 1], frame.key, node, walk);
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
function adopt(raw, walk) {
|
|
4396
|
+
const frames = [];
|
|
4397
|
+
const node = enterAdopt(raw, undefined, walk, frames);
|
|
4398
|
+
return frames.length === 0 ? node : walkFrames(frames, walk);
|
|
4399
|
+
}
|
|
4400
|
+
function adoptAll(touched, store, former, held, visit) {
|
|
4401
|
+
let walk = newWalk(touched, store, former, held);
|
|
4402
|
+
visit(walk);
|
|
4403
|
+
if (walk.repeated !== undefined) {
|
|
4404
|
+
const first = walk;
|
|
4405
|
+
walk = newWalk(touched, store, former, held, first);
|
|
4406
|
+
visit(walk);
|
|
4407
|
+
for (let i = 0;i < first.relinked.length; i++)
|
|
4408
|
+
first.relinked[i].lostLink = false;
|
|
4409
|
+
}
|
|
4410
|
+
for (let i = 0;i < walk.relinked.length; i++)
|
|
4411
|
+
walk.relinked[i].lostLink = false;
|
|
4412
|
+
}
|
|
4413
|
+
function pruneTouched(touched) {
|
|
4414
|
+
for (let i = 0;i < touched.length; i++) {
|
|
4415
|
+
if (touched[i].places.length > 1)
|
|
4416
|
+
prunePlaces(touched[i]);
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
function hasObjectChild(raw) {
|
|
4420
|
+
if (Array.isArray(raw)) {
|
|
4421
|
+
for (let i = 0;i < raw.length; i++)
|
|
4422
|
+
if (isObject2(raw[i]))
|
|
4423
|
+
return true;
|
|
4424
|
+
return false;
|
|
4425
|
+
}
|
|
4426
|
+
if (Object.getPrototypeOf(raw) !== Object.prototype) {
|
|
4427
|
+
if (raw instanceof Map || raw instanceof Set) {
|
|
4428
|
+
const entries = raw instanceof Map ? Map.prototype.values.call(raw) : Set.prototype.values.call(raw);
|
|
4429
|
+
for (const child of entries)
|
|
4430
|
+
if (isObject2(child))
|
|
4431
|
+
return true;
|
|
4432
|
+
return false;
|
|
2834
4433
|
}
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
if (
|
|
2840
|
-
|
|
2841
|
-
|
|
4434
|
+
if (raw instanceof Date || ArrayBuffer.isView(raw))
|
|
4435
|
+
return false;
|
|
4436
|
+
}
|
|
4437
|
+
for (const key in raw) {
|
|
4438
|
+
if (Object.prototype.hasOwnProperty.call(raw, key) && isObject2(raw[key]))
|
|
4439
|
+
return true;
|
|
4440
|
+
}
|
|
4441
|
+
return false;
|
|
4442
|
+
}
|
|
4443
|
+
function insertedNeedWalk(inserted) {
|
|
4444
|
+
let fresh;
|
|
4445
|
+
for (let i = 0;i < inserted.length; i++) {
|
|
4446
|
+
const value = inserted[i];
|
|
4447
|
+
if (!isObject2(value))
|
|
4448
|
+
continue;
|
|
4449
|
+
const node = nodes.get(value);
|
|
4450
|
+
if (node !== undefined) {
|
|
4451
|
+
if (node.lostLink || !attachedBefore(node, undefined))
|
|
4452
|
+
return true;
|
|
4453
|
+
continue;
|
|
2842
4454
|
}
|
|
2843
|
-
if (
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
} else if (target instanceof Set && newValue instanceof Set) {
|
|
2852
|
-
const newValueEntries = [...newValue.values()];
|
|
2853
|
-
target.clear();
|
|
2854
|
-
for (const value of newValueEntries) {
|
|
2855
|
-
target.add(value);
|
|
2856
|
-
}
|
|
2857
|
-
} else if (typeof target === "object" && target !== null && typeof newValue === "object" && newValue !== null) {
|
|
2858
|
-
Object.keys(target).forEach((key) => delete target[key]);
|
|
2859
|
-
Object.assign(target, newValue);
|
|
2860
|
-
} else {
|
|
2861
|
-
console.warn(`Type mismatch or unsupported type for 'replace' action at path ${event.path.join(".")}. Target type: ${typeof target} ${target.constructor.name}, New value type: ${typeof newValue} ${newValue.constructor.name}`);
|
|
4455
|
+
if (hasObjectChild(value))
|
|
4456
|
+
return true;
|
|
4457
|
+
if (inserted.length > 1) {
|
|
4458
|
+
if (fresh === undefined)
|
|
4459
|
+
fresh = new Set;
|
|
4460
|
+
else if (fresh.has(value))
|
|
4461
|
+
return true;
|
|
4462
|
+
fresh.add(value);
|
|
2862
4463
|
}
|
|
2863
4464
|
}
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
if (!
|
|
2868
|
-
console.warn("event path is invalid for action", event);
|
|
4465
|
+
return false;
|
|
4466
|
+
}
|
|
4467
|
+
function heldBefore(value, replaced) {
|
|
4468
|
+
if (!Array.isArray(value) || !Array.isArray(replaced))
|
|
2869
4469
|
return;
|
|
4470
|
+
let before;
|
|
4471
|
+
for (let i = 0;i < value.length; i++) {
|
|
4472
|
+
const item = value[i];
|
|
4473
|
+
if (!isObject2(item) || nodes.get(item) !== undefined)
|
|
4474
|
+
continue;
|
|
4475
|
+
if (before === undefined) {
|
|
4476
|
+
if (replaced.indexOf(item) === -1)
|
|
4477
|
+
return;
|
|
4478
|
+
before = new Set;
|
|
4479
|
+
for (let j = 0;j < replaced.length; j++)
|
|
4480
|
+
if (isObject2(replaced[j]))
|
|
4481
|
+
before.add(replaced[j]);
|
|
4482
|
+
}
|
|
4483
|
+
if (!before.has(item))
|
|
4484
|
+
return;
|
|
2870
4485
|
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
4486
|
+
return before;
|
|
4487
|
+
}
|
|
4488
|
+
function heldItems(value, replaced) {
|
|
4489
|
+
if (!isObject2(value) || !isObject2(replaced) || nodes.get(replaced) === undefined)
|
|
4490
|
+
return;
|
|
4491
|
+
return heldBefore(value, replaced);
|
|
4492
|
+
}
|
|
4493
|
+
function attachValue(value, parent, key, fresh, replaced, held) {
|
|
4494
|
+
if (fresh)
|
|
4495
|
+
return;
|
|
4496
|
+
const former = isObject2(replaced) ? nodes.get(replaced) : undefined;
|
|
4497
|
+
const existing = nodes.get(value);
|
|
4498
|
+
if (existing !== undefined && !existing.lostLink && attachedBefore(existing, former)) {
|
|
4499
|
+
if (addPlace(existing, parent, key) && existing.places.length > 1)
|
|
4500
|
+
prunePlaces(existing);
|
|
2874
4501
|
return;
|
|
2875
4502
|
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
4503
|
+
if (existing === undefined && !hasObjectChild(value))
|
|
4504
|
+
return;
|
|
4505
|
+
const touched = [];
|
|
4506
|
+
const store = ++stamps;
|
|
4507
|
+
adoptAll(touched, store, former, held, (walk) => {
|
|
4508
|
+
const node = adopt(value, walk);
|
|
4509
|
+
if (node !== undefined && addPlace(node, parent, key))
|
|
4510
|
+
touch(node, store, touched);
|
|
4511
|
+
});
|
|
4512
|
+
pruneTouched(touched);
|
|
4513
|
+
}
|
|
4514
|
+
function adoptRoot(node) {
|
|
4515
|
+
const touched = [];
|
|
4516
|
+
adoptAll(touched, ++stamps, undefined, undefined, (walk) => {
|
|
4517
|
+
node.walk = walk.id;
|
|
4518
|
+
walkFrames([adoptFrame(node.raw, node, false, undefined)], walk);
|
|
4519
|
+
});
|
|
4520
|
+
pruneTouched(touched);
|
|
4521
|
+
}
|
|
4522
|
+
function relinkArray(arrayNode, array, from, removed, inserted, insertedFresh = false) {
|
|
4523
|
+
if (insertedFresh)
|
|
4524
|
+
inserted = undefined;
|
|
4525
|
+
relink(arrayNode, array, from, removed, inserted, false);
|
|
4526
|
+
}
|
|
4527
|
+
function relinkReorder(arrayNode, array, removed, inserted) {
|
|
4528
|
+
relink(arrayNode, array, 0, removed, inserted, true);
|
|
4529
|
+
}
|
|
4530
|
+
function relink(arrayNode, array, from, removed, inserted, findAliases) {
|
|
4531
|
+
const touched = [];
|
|
4532
|
+
const store = ++stamps;
|
|
4533
|
+
if (inserted !== undefined && insertedNeedWalk(inserted)) {
|
|
4534
|
+
adoptAll(touched, store, undefined, undefined, (walk) => {
|
|
4535
|
+
for (let i = 0;i < inserted.length; i++) {
|
|
4536
|
+
const value = inserted[i];
|
|
4537
|
+
if (isObject2(value))
|
|
4538
|
+
adopt(value, walk);
|
|
2893
4539
|
}
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
4540
|
+
});
|
|
4541
|
+
}
|
|
4542
|
+
let removedNode = false;
|
|
4543
|
+
if (removed !== undefined) {
|
|
4544
|
+
for (let i = 0;i < removed.length; i++) {
|
|
4545
|
+
const value = removed[i];
|
|
4546
|
+
if (isObject2(value)) {
|
|
4547
|
+
const node = nodes.get(value);
|
|
4548
|
+
if (node !== undefined) {
|
|
4549
|
+
stripIndexes(node, arrayNode, from);
|
|
4550
|
+
removedNode = true;
|
|
4551
|
+
}
|
|
2897
4552
|
}
|
|
2898
|
-
targetForHandler = parent;
|
|
2899
|
-
keyForHandler = path[path.length - 1];
|
|
2900
4553
|
}
|
|
2901
|
-
}
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
if (
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
4554
|
+
}
|
|
4555
|
+
const call = ++relinkCalls;
|
|
4556
|
+
let firstIndex;
|
|
4557
|
+
let left = findAliases || removedNode || holdsNode(inserted) ? Infinity : arrayNode.childPlaces;
|
|
4558
|
+
for (let i = from;i < array.length && left > 0; i++) {
|
|
4559
|
+
const value = array[i];
|
|
4560
|
+
if (!isObject2(value))
|
|
4561
|
+
continue;
|
|
4562
|
+
let node = nodes.get(value);
|
|
4563
|
+
if (node === undefined) {
|
|
4564
|
+
if (!findAliases)
|
|
4565
|
+
continue;
|
|
4566
|
+
const first = (firstIndex ??= new Map).get(value);
|
|
4567
|
+
if (first === undefined) {
|
|
4568
|
+
firstIndex.set(value, i);
|
|
4569
|
+
continue;
|
|
2915
4570
|
}
|
|
2916
|
-
if (
|
|
2917
|
-
|
|
2918
|
-
|
|
4571
|
+
if (value["__v_skip" /* SKIP */])
|
|
4572
|
+
continue;
|
|
4573
|
+
node = ensureLocationNode(value);
|
|
4574
|
+
node.relinked = call;
|
|
4575
|
+
node.relinkedPlaces = 0;
|
|
4576
|
+
node.places.push(new Place(arrayNode, first));
|
|
4577
|
+
} else if (node.relinked !== call) {
|
|
4578
|
+
node.relinked = call;
|
|
4579
|
+
const places = node.places;
|
|
4580
|
+
if (places.length === 1 && places[0].parentId === arrayNode.id && typeof places[0].key === "number" && places[0].key >= from) {
|
|
4581
|
+
places[0].key = i;
|
|
4582
|
+
node.relinkedPlaces = 0;
|
|
4583
|
+
left--;
|
|
4584
|
+
continue;
|
|
2919
4585
|
}
|
|
2920
|
-
|
|
4586
|
+
node.relinkedPlaces = stripIndexes(node, arrayNode, from);
|
|
2921
4587
|
}
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
4588
|
+
if (node.relinkedPlaces > 0) {
|
|
4589
|
+
node.relinkedPlaces--;
|
|
4590
|
+
left--;
|
|
4591
|
+
}
|
|
4592
|
+
node.places.push(new Place(arrayNode, i));
|
|
4593
|
+
if (node.places.length > 1)
|
|
4594
|
+
touch(node, store, touched);
|
|
2925
4595
|
}
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
4596
|
+
pruneTouched(touched);
|
|
4597
|
+
}
|
|
4598
|
+
var relinkCalls = 0;
|
|
4599
|
+
function holdsNode(values) {
|
|
4600
|
+
if (values === undefined)
|
|
4601
|
+
return false;
|
|
4602
|
+
for (let i = 0;i < values.length; i++) {
|
|
4603
|
+
const value = values[i];
|
|
4604
|
+
if (isObject2(value) && nodes.get(value) !== undefined)
|
|
4605
|
+
return true;
|
|
4606
|
+
}
|
|
4607
|
+
return false;
|
|
4608
|
+
}
|
|
4609
|
+
function stripIndexes(node, arrayNode, from) {
|
|
4610
|
+
const places = node.places;
|
|
4611
|
+
let count = 0;
|
|
4612
|
+
for (let i = places.length - 1;i >= 0; i--) {
|
|
4613
|
+
const place = places[i];
|
|
4614
|
+
if (place.parentId === arrayNode.id && typeof place.key === "number" && place.key >= from) {
|
|
4615
|
+
arrayNode.childPlaces--;
|
|
4616
|
+
places.splice(i, 1);
|
|
4617
|
+
count++;
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
if (count > 0)
|
|
4621
|
+
node.index = undefined;
|
|
4622
|
+
return count;
|
|
4623
|
+
}
|
|
4624
|
+
function evictDeep(value, parent) {
|
|
4625
|
+
if (value == null || typeof value !== "object")
|
|
4626
|
+
return;
|
|
4627
|
+
const top = toRaw(value);
|
|
4628
|
+
if (globalSeen.get(top) === undefined)
|
|
4629
|
+
return;
|
|
4630
|
+
const pending = [parent, undefined, top];
|
|
4631
|
+
while (pending.length > 0) {
|
|
4632
|
+
const raw = pending.pop();
|
|
4633
|
+
const key = pending.pop();
|
|
4634
|
+
const container = pending.pop();
|
|
4635
|
+
const proxy = globalSeen.get(raw);
|
|
4636
|
+
if (proxy === undefined)
|
|
4637
|
+
continue;
|
|
4638
|
+
const node = nodes.get(raw);
|
|
4639
|
+
if (node !== undefined) {
|
|
4640
|
+
const places = node.places;
|
|
4641
|
+
const onlyUnderParent = container !== undefined && node.root === undefined && places.length === 1 && places[0].parentId === container.id;
|
|
4642
|
+
if (!onlyUnderParent) {
|
|
4643
|
+
if (container !== undefined && places.length > 1 && removePlace(node, container, key))
|
|
4644
|
+
markLostLink(container);
|
|
4645
|
+
if (isAttached(node))
|
|
4646
|
+
continue;
|
|
4647
|
+
}
|
|
4648
|
+
node.proxy = undefined;
|
|
4649
|
+
node.evicted = new WeakRef(proxy);
|
|
4650
|
+
}
|
|
4651
|
+
globalSeen.delete(raw);
|
|
4652
|
+
wrapperCache.delete(raw);
|
|
4653
|
+
proxyStats.staleEvicted++;
|
|
4654
|
+
if (Array.isArray(raw)) {
|
|
4655
|
+
for (let i = 0;i < raw.length; i++)
|
|
4656
|
+
pushProxied(raw[i], node, i, pending);
|
|
4657
|
+
} else if (raw instanceof Map) {
|
|
4658
|
+
Map.prototype.forEach.call(raw, (child, key2) => pushProxied(child, node, key2, pending));
|
|
4659
|
+
} else if (raw instanceof Set) {
|
|
4660
|
+
for (const child of Set.prototype.values.call(raw))
|
|
4661
|
+
pushProxied(child, node, undefined, pending);
|
|
4662
|
+
} else {
|
|
4663
|
+
const keys = Object.keys(raw);
|
|
4664
|
+
for (let i = 0;i < keys.length; i++)
|
|
4665
|
+
pushProxied(raw[keys[i]], node, keys[i], pending);
|
|
4666
|
+
}
|
|
2930
4667
|
}
|
|
2931
4668
|
}
|
|
4669
|
+
function pushProxied(value, container, key, pending) {
|
|
4670
|
+
if (value === null || typeof value !== "object")
|
|
4671
|
+
return;
|
|
4672
|
+
const raw = toRaw(value);
|
|
4673
|
+
if (globalSeen.get(raw) !== undefined)
|
|
4674
|
+
pending.push(container, key, raw);
|
|
4675
|
+
}
|
|
4676
|
+
function restoreEvicted(node) {
|
|
4677
|
+
const proxy = node.evicted?.deref();
|
|
4678
|
+
node.evicted = undefined;
|
|
4679
|
+
if (proxy === undefined)
|
|
4680
|
+
return;
|
|
4681
|
+
node.proxy = proxy;
|
|
4682
|
+
globalSeen.set(node.raw, proxy);
|
|
4683
|
+
wrapperCache.set(node.raw, proxy);
|
|
4684
|
+
proxyStats.staleEvicted--;
|
|
4685
|
+
return proxy;
|
|
4686
|
+
}
|
|
4687
|
+
|
|
2932
4688
|
// src/watch-effect.ts
|
|
2933
4689
|
var activeEffect = null;
|
|
2934
4690
|
var queuedEffects = new Map;
|
|
@@ -3040,70 +4796,583 @@ function trigger(target, key) {
|
|
|
3040
4796
|
queuedEffects.set(effect, triggerLevel);
|
|
3041
4797
|
}
|
|
3042
4798
|
}
|
|
3043
|
-
});
|
|
3044
|
-
}
|
|
3045
|
-
};
|
|
3046
|
-
addEffects(key);
|
|
3047
|
-
if (queuedEffects.size > 0) {
|
|
3048
|
-
flushEffects();
|
|
3049
|
-
}
|
|
3050
|
-
} finally {
|
|
3051
|
-
currentTriggerDepth--;
|
|
3052
|
-
}
|
|
3053
|
-
}
|
|
3054
|
-
function watchEffect(effectCallback, options = {}) {
|
|
3055
|
-
const run = () => {
|
|
3056
|
-
if (!effectFn.active) {
|
|
3057
|
-
throw new Error("Trying to run a stopped effect");
|
|
3058
|
-
}
|
|
3059
|
-
const previousEffect = activeEffect;
|
|
3060
|
-
try {
|
|
3061
|
-
runCleanupFunctions(effectFn);
|
|
3062
|
-
cleanupEffect(effectFn);
|
|
3063
|
-
setActiveEffect(effectFn);
|
|
3064
|
-
const onCleanup = (cleanupFn) => {
|
|
3065
|
-
if (!effectFn.cleanupFns) {
|
|
3066
|
-
effectFn.cleanupFns = [];
|
|
4799
|
+
});
|
|
4800
|
+
}
|
|
4801
|
+
};
|
|
4802
|
+
addEffects(key);
|
|
4803
|
+
if (queuedEffects.size > 0) {
|
|
4804
|
+
flushEffects();
|
|
4805
|
+
}
|
|
4806
|
+
} finally {
|
|
4807
|
+
currentTriggerDepth--;
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4810
|
+
function watchEffect(effectCallback, options = {}) {
|
|
4811
|
+
const run = () => {
|
|
4812
|
+
if (!effectFn.active) {
|
|
4813
|
+
throw new Error("Trying to run a stopped effect");
|
|
4814
|
+
}
|
|
4815
|
+
const previousEffect = activeEffect;
|
|
4816
|
+
try {
|
|
4817
|
+
runCleanupFunctions(effectFn);
|
|
4818
|
+
cleanupEffect(effectFn);
|
|
4819
|
+
setActiveEffect(effectFn);
|
|
4820
|
+
const onCleanup = (cleanupFn) => {
|
|
4821
|
+
if (!effectFn.cleanupFns) {
|
|
4822
|
+
effectFn.cleanupFns = [];
|
|
4823
|
+
}
|
|
4824
|
+
effectFn.cleanupFns.push(cleanupFn);
|
|
4825
|
+
};
|
|
4826
|
+
return effectCallback(onCleanup);
|
|
4827
|
+
} finally {
|
|
4828
|
+
setActiveEffect(previousEffect);
|
|
4829
|
+
}
|
|
4830
|
+
};
|
|
4831
|
+
const effectFn = {
|
|
4832
|
+
run,
|
|
4833
|
+
dependencies: new Set,
|
|
4834
|
+
options,
|
|
4835
|
+
active: true,
|
|
4836
|
+
_rawCallback: effectCallback,
|
|
4837
|
+
cleanupFns: []
|
|
4838
|
+
};
|
|
4839
|
+
if (!options.lazy) {
|
|
4840
|
+
effectFn.run();
|
|
4841
|
+
}
|
|
4842
|
+
const stopHandle = () => {
|
|
4843
|
+
if (effectFn.active) {
|
|
4844
|
+
runCleanupFunctions(effectFn);
|
|
4845
|
+
cleanupEffect(effectFn);
|
|
4846
|
+
effectFn.active = false;
|
|
4847
|
+
queuedEffects.delete(effectFn);
|
|
4848
|
+
}
|
|
4849
|
+
};
|
|
4850
|
+
stopHandle.effect = effectFn;
|
|
4851
|
+
return stopHandle;
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4854
|
+
// src/wrap-array.ts
|
|
4855
|
+
function isObject3(v) {
|
|
4856
|
+
return v && typeof v === "object";
|
|
4857
|
+
}
|
|
4858
|
+
function arrayIndex(prop) {
|
|
4859
|
+
if (typeof prop !== "string" || prop.length === 0 || prop.length > 10)
|
|
4860
|
+
return -1;
|
|
4861
|
+
const first = prop.charCodeAt(0);
|
|
4862
|
+
if (first < 48 || first > 57 || first === 48 && prop.length > 1)
|
|
4863
|
+
return -1;
|
|
4864
|
+
for (let i = 1;i < prop.length; i++) {
|
|
4865
|
+
const code = prop.charCodeAt(i);
|
|
4866
|
+
if (code < 48 || code > 57)
|
|
4867
|
+
return -1;
|
|
4868
|
+
}
|
|
4869
|
+
const index = Number(prop);
|
|
4870
|
+
return index < 4294967295 ? index : -1;
|
|
4871
|
+
}
|
|
4872
|
+
function placeKey(prop) {
|
|
4873
|
+
const index = arrayIndex(prop);
|
|
4874
|
+
return index >= 0 ? index : prop;
|
|
4875
|
+
}
|
|
4876
|
+
function toIntegerOrInfinity(value) {
|
|
4877
|
+
const number = +value;
|
|
4878
|
+
if (number !== number || number === 0)
|
|
4879
|
+
return 0;
|
|
4880
|
+
return Math.trunc(number);
|
|
4881
|
+
}
|
|
4882
|
+
function clampIndex(relative, length) {
|
|
4883
|
+
return relative < 0 ? Math.max(length + relative, 0) : Math.min(relative, length);
|
|
4884
|
+
}
|
|
4885
|
+
function unwrapItems(items) {
|
|
4886
|
+
for (let i = 0;i < items.length; i++) {
|
|
4887
|
+
if (isObject3(items[i]))
|
|
4888
|
+
items[i] = unwrapForStore(items[i]);
|
|
4889
|
+
}
|
|
4890
|
+
}
|
|
4891
|
+
function planReorder(target, prop, method, args) {
|
|
4892
|
+
const length = target.length;
|
|
4893
|
+
if (prop === "fill" || prop === "copyWithin") {
|
|
4894
|
+
const fill2 = prop === "fill";
|
|
4895
|
+
const to = fill2 ? 0 : clampIndex(toIntegerOrInfinity(args[0]), length);
|
|
4896
|
+
const start = clampIndex(toIntegerOrInfinity(args[1]), length);
|
|
4897
|
+
const end = args[2] === undefined ? length : clampIndex(toIntegerOrInfinity(args[2]), length);
|
|
4898
|
+
const after2 = target.slice();
|
|
4899
|
+
method.call(after2, fill2 ? args[0] : to, start, end);
|
|
4900
|
+
const size = after2.length;
|
|
4901
|
+
if (fill2)
|
|
4902
|
+
return { after: after2, first: Math.min(start, size), last: Math.min(end, size), skip: -1 };
|
|
4903
|
+
const from = Math.min(to, size);
|
|
4904
|
+
const count = Math.min(Math.min(end, size) - Math.min(start, size), size - from);
|
|
4905
|
+
return { after: after2, first: from, last: from + Math.max(count, 0), skip: -1 };
|
|
4906
|
+
}
|
|
4907
|
+
const after = target.slice();
|
|
4908
|
+
method.apply(after, args);
|
|
4909
|
+
if (prop === "reverse") {
|
|
4910
|
+
return { after, first: 0, last: length, skip: length % 2 === 1 ? (length - 1) / 2 : -1 };
|
|
4911
|
+
}
|
|
4912
|
+
const sorted = length < 2 ? 0 : length;
|
|
4913
|
+
for (let i = length;i < target.length; i++) {
|
|
4914
|
+
if (i in target)
|
|
4915
|
+
after[i] = target[i];
|
|
4916
|
+
else
|
|
4917
|
+
after.length = i + 1;
|
|
4918
|
+
}
|
|
4919
|
+
return { after, first: 0, last: sorted, skip: -1 };
|
|
4920
|
+
}
|
|
4921
|
+
var strictWrites = function() {
|
|
4922
|
+
return this === undefined;
|
|
4923
|
+
}();
|
|
4924
|
+
function checkReorder(target, reorder) {
|
|
4925
|
+
const { after, first, last, skip } = reorder;
|
|
4926
|
+
let extensible;
|
|
4927
|
+
for (let i = first;i < last; i++) {
|
|
4928
|
+
if (i === skip)
|
|
4929
|
+
continue;
|
|
4930
|
+
if (i in after) {
|
|
4931
|
+
if (i in target) {
|
|
4932
|
+
if (strictWrites)
|
|
4933
|
+
target[i] = target[i];
|
|
4934
|
+
else if (!Reflect.set(target, i, target[i]))
|
|
4935
|
+
throw new TypeError(`Cannot assign to read only property '${i}' of array`);
|
|
4936
|
+
} else if (!(extensible ??= Object.isExtensible(target))) {
|
|
4937
|
+
throw new TypeError(`Cannot add property ${i}, array is not extensible`);
|
|
4938
|
+
}
|
|
4939
|
+
} else if (i in target && !Reflect.getOwnPropertyDescriptor(target, i).configurable) {
|
|
4940
|
+
throw new TypeError(`Cannot delete property '${i}' of array`);
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4944
|
+
function reorderChanges(target, after) {
|
|
4945
|
+
if (after.length !== target.length)
|
|
4946
|
+
return true;
|
|
4947
|
+
for (let i = 0;i < after.length; i++) {
|
|
4948
|
+
const value = after[i];
|
|
4949
|
+
const current = target[i];
|
|
4950
|
+
if (value !== current) {
|
|
4951
|
+
if (value === value || current === current)
|
|
4952
|
+
return true;
|
|
4953
|
+
} else if (value === 0) {
|
|
4954
|
+
if (1 / value !== 1 / current)
|
|
4955
|
+
return true;
|
|
4956
|
+
} else if (value === undefined && i in after !== i in target) {
|
|
4957
|
+
return true;
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
return false;
|
|
4961
|
+
}
|
|
4962
|
+
function writeReorder(target, reorder) {
|
|
4963
|
+
const { after, first, last, skip } = reorder;
|
|
4964
|
+
for (let i = first;i < last; i++) {
|
|
4965
|
+
if (i === skip)
|
|
4966
|
+
continue;
|
|
4967
|
+
if (i in after)
|
|
4968
|
+
target[i] = after[i];
|
|
4969
|
+
else
|
|
4970
|
+
delete target[i];
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4973
|
+
function evictRemoved(removed) {
|
|
4974
|
+
for (let i = 0;i < removed.length; i++) {
|
|
4975
|
+
if (isObject3(removed[i]))
|
|
4976
|
+
evictDeep(removed[i]);
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
function wrapArray(arr, node) {
|
|
4980
|
+
const cachedProxy = wrapperCache.get(arr);
|
|
4981
|
+
if (cachedProxy)
|
|
4982
|
+
return cachedProxy;
|
|
4983
|
+
if (globalSeen.has(arr))
|
|
4984
|
+
return globalSeen.get(arr);
|
|
4985
|
+
const methodCache = {};
|
|
4986
|
+
const proxy = new Proxy(arr, {
|
|
4987
|
+
get(target, prop, receiver) {
|
|
4988
|
+
if (prop === "__v_raw" /* RAW */)
|
|
4989
|
+
return target;
|
|
4990
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
4991
|
+
return true;
|
|
4992
|
+
track(target, prop);
|
|
4993
|
+
if (methodCache[prop]) {
|
|
4994
|
+
return methodCache[prop];
|
|
4995
|
+
}
|
|
4996
|
+
switch (prop) {
|
|
4997
|
+
case "sort":
|
|
4998
|
+
case "reverse":
|
|
4999
|
+
case "fill":
|
|
5000
|
+
case "copyWithin": {
|
|
5001
|
+
track(target, "length");
|
|
5002
|
+
const method = Array.prototype[prop];
|
|
5003
|
+
methodCache[prop] = function(...args) {
|
|
5004
|
+
if (prop === "fill" && isObject3(args[0]))
|
|
5005
|
+
args[0] = unwrapForStore(args[0]);
|
|
5006
|
+
const reorder = planReorder(target, prop, method, args);
|
|
5007
|
+
const before = target.slice();
|
|
5008
|
+
checkReorder(target, reorder);
|
|
5009
|
+
const after = reorder.after;
|
|
5010
|
+
if (!reorderChanges(target, after))
|
|
5011
|
+
return proxy;
|
|
5012
|
+
const located = locate(node);
|
|
5013
|
+
const event = located && {
|
|
5014
|
+
action: "replace",
|
|
5015
|
+
path: located.paths[0],
|
|
5016
|
+
oldValue: before,
|
|
5017
|
+
newValue: target
|
|
5018
|
+
};
|
|
5019
|
+
if (event !== undefined)
|
|
5020
|
+
copyPayloadAfter(event, located, target, after);
|
|
5021
|
+
writeReorder(target, reorder);
|
|
5022
|
+
relinkReorder(node, target, before, prop === "fill" ? [args[0]] : undefined);
|
|
5023
|
+
if (event !== undefined)
|
|
5024
|
+
dispatch(located, event);
|
|
5025
|
+
trigger(target, Symbol.iterator);
|
|
5026
|
+
evictRemoved(before);
|
|
5027
|
+
return proxy;
|
|
5028
|
+
};
|
|
5029
|
+
return methodCache[prop];
|
|
5030
|
+
}
|
|
5031
|
+
case "push":
|
|
5032
|
+
track(target, "length");
|
|
5033
|
+
methodCache[prop] = function(...items) {
|
|
5034
|
+
unwrapItems(items);
|
|
5035
|
+
const oldLength = target.length;
|
|
5036
|
+
const located = items.length > 0 ? locate(node) : undefined;
|
|
5037
|
+
const event = located && {
|
|
5038
|
+
action: "array-push",
|
|
5039
|
+
path: located.paths[0],
|
|
5040
|
+
key: oldLength,
|
|
5041
|
+
items
|
|
5042
|
+
};
|
|
5043
|
+
const copied = copyPayload(event, located, target);
|
|
5044
|
+
if (copied === 0 /* Reaches */) {
|
|
5045
|
+
const after = target.slice();
|
|
5046
|
+
after.push(...items);
|
|
5047
|
+
copyPayloadReaching(event, located, target, after);
|
|
5048
|
+
}
|
|
5049
|
+
const result = target.push(...items);
|
|
5050
|
+
const newLength = target.length;
|
|
5051
|
+
if (items.length > 0) {
|
|
5052
|
+
relinkArray(node, target, oldLength, undefined, items, copied === 2 /* Fresh */);
|
|
5053
|
+
if (event !== undefined)
|
|
5054
|
+
dispatch(located, event);
|
|
5055
|
+
trigger(target, Symbol.iterator);
|
|
5056
|
+
if (oldLength !== newLength) {
|
|
5057
|
+
trigger(target, "length");
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
return result;
|
|
5061
|
+
};
|
|
5062
|
+
return methodCache[prop];
|
|
5063
|
+
case "pop":
|
|
5064
|
+
track(target, "length");
|
|
5065
|
+
methodCache[prop] = function() {
|
|
5066
|
+
if (target.length === 0)
|
|
5067
|
+
return;
|
|
5068
|
+
const oldLength = target.length;
|
|
5069
|
+
const poppedIndex = oldLength - 1;
|
|
5070
|
+
const oldValue = target[poppedIndex];
|
|
5071
|
+
const located = locate(node);
|
|
5072
|
+
const event = located && {
|
|
5073
|
+
action: "array-pop",
|
|
5074
|
+
path: located.paths[0],
|
|
5075
|
+
key: poppedIndex,
|
|
5076
|
+
oldValue
|
|
5077
|
+
};
|
|
5078
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5079
|
+
const after = target.slice();
|
|
5080
|
+
after.pop();
|
|
5081
|
+
copyPayloadReaching(event, located, target, after);
|
|
5082
|
+
}
|
|
5083
|
+
const result = target.pop();
|
|
5084
|
+
const newLength = target.length;
|
|
5085
|
+
if (isObject3(oldValue))
|
|
5086
|
+
detachPlace(oldValue, node, poppedIndex);
|
|
5087
|
+
if (event !== undefined)
|
|
5088
|
+
dispatch(located, event);
|
|
5089
|
+
if (isObject3(oldValue))
|
|
5090
|
+
evictDeep(oldValue);
|
|
5091
|
+
trigger(target, Symbol.iterator);
|
|
5092
|
+
if (oldLength !== newLength) {
|
|
5093
|
+
trigger(target, "length");
|
|
5094
|
+
}
|
|
5095
|
+
return result;
|
|
5096
|
+
};
|
|
5097
|
+
return methodCache[prop];
|
|
5098
|
+
case "shift":
|
|
5099
|
+
track(target, "length");
|
|
5100
|
+
methodCache[prop] = function() {
|
|
5101
|
+
if (target.length === 0)
|
|
5102
|
+
return;
|
|
5103
|
+
const oldLength = target.length;
|
|
5104
|
+
const oldValue = target[0];
|
|
5105
|
+
const located = locate(node);
|
|
5106
|
+
const event = located && {
|
|
5107
|
+
action: "array-shift",
|
|
5108
|
+
path: located.paths[0],
|
|
5109
|
+
key: 0,
|
|
5110
|
+
oldValue
|
|
5111
|
+
};
|
|
5112
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5113
|
+
const after = target.slice();
|
|
5114
|
+
after.shift();
|
|
5115
|
+
copyPayloadReaching(event, located, target, after);
|
|
5116
|
+
}
|
|
5117
|
+
const result = target.shift();
|
|
5118
|
+
const newLength = target.length;
|
|
5119
|
+
relinkArray(node, target, 0, [oldValue]);
|
|
5120
|
+
if (event !== undefined)
|
|
5121
|
+
dispatch(located, event);
|
|
5122
|
+
if (isObject3(oldValue))
|
|
5123
|
+
evictDeep(oldValue);
|
|
5124
|
+
trigger(target, Symbol.iterator);
|
|
5125
|
+
if (oldLength !== newLength) {
|
|
5126
|
+
trigger(target, "length");
|
|
5127
|
+
}
|
|
5128
|
+
return result;
|
|
5129
|
+
};
|
|
5130
|
+
return methodCache[prop];
|
|
5131
|
+
case "unshift":
|
|
5132
|
+
track(target, "length");
|
|
5133
|
+
methodCache[prop] = function(...items) {
|
|
5134
|
+
unwrapItems(items);
|
|
5135
|
+
const oldLength = target.length;
|
|
5136
|
+
const located = items.length > 0 ? locate(node) : undefined;
|
|
5137
|
+
const event = located && {
|
|
5138
|
+
action: "array-unshift",
|
|
5139
|
+
path: located.paths[0],
|
|
5140
|
+
key: 0,
|
|
5141
|
+
items
|
|
5142
|
+
};
|
|
5143
|
+
const copied = copyPayload(event, located, target);
|
|
5144
|
+
if (copied === 0 /* Reaches */) {
|
|
5145
|
+
const after = target.slice();
|
|
5146
|
+
after.unshift(...items);
|
|
5147
|
+
copyPayloadReaching(event, located, target, after);
|
|
5148
|
+
}
|
|
5149
|
+
const result = target.unshift(...items);
|
|
5150
|
+
const newLength = target.length;
|
|
5151
|
+
if (items.length > 0) {
|
|
5152
|
+
relinkArray(node, target, 0, undefined, items, copied === 2 /* Fresh */);
|
|
5153
|
+
if (event !== undefined)
|
|
5154
|
+
dispatch(located, event);
|
|
5155
|
+
trigger(target, Symbol.iterator);
|
|
5156
|
+
if (oldLength !== newLength) {
|
|
5157
|
+
trigger(target, "length");
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
return result;
|
|
5161
|
+
};
|
|
5162
|
+
return methodCache[prop];
|
|
5163
|
+
case "splice":
|
|
5164
|
+
track(target, "length");
|
|
5165
|
+
methodCache[prop] = function(...args) {
|
|
5166
|
+
const oldLength = target.length;
|
|
5167
|
+
const actualStart = args.length === 0 ? 0 : clampIndex(toIntegerOrInfinity(args[0]), oldLength);
|
|
5168
|
+
const actualDeleteCount = args.length === 0 ? 0 : args.length === 1 ? oldLength - actualStart : Math.min(Math.max(toIntegerOrInfinity(args[1]), 0), oldLength - actualStart);
|
|
5169
|
+
const items = args.length > 2 ? args.slice(2) : [];
|
|
5170
|
+
unwrapItems(items);
|
|
5171
|
+
const changes = actualDeleteCount > 0 || items.length > 0;
|
|
5172
|
+
const located = changes ? locate(node) : undefined;
|
|
5173
|
+
const event = located && {
|
|
5174
|
+
action: "array-splice",
|
|
5175
|
+
path: located.paths[0],
|
|
5176
|
+
key: actualStart,
|
|
5177
|
+
deleteCount: actualDeleteCount,
|
|
5178
|
+
items: items.length > 0 ? items : undefined,
|
|
5179
|
+
oldValues: actualDeleteCount > 0 ? target.slice(actualStart, actualStart + actualDeleteCount) : undefined
|
|
5180
|
+
};
|
|
5181
|
+
const copied = copyPayload(event, located, target);
|
|
5182
|
+
if (copied === 0 /* Reaches */) {
|
|
5183
|
+
const after = target.slice();
|
|
5184
|
+
after.splice(actualStart, actualDeleteCount, ...items);
|
|
5185
|
+
copyPayloadReaching(event, located, target, after);
|
|
5186
|
+
}
|
|
5187
|
+
const deletedItems = target.splice(actualStart, actualDeleteCount, ...items);
|
|
5188
|
+
const newLength = target.length;
|
|
5189
|
+
if (changes) {
|
|
5190
|
+
relinkArray(node, target, actualStart, deletedItems, items, copied === 2 /* Fresh */);
|
|
5191
|
+
if (event !== undefined)
|
|
5192
|
+
dispatch(located, event);
|
|
5193
|
+
evictRemoved(deletedItems);
|
|
5194
|
+
trigger(target, Symbol.iterator);
|
|
5195
|
+
if (oldLength !== newLength) {
|
|
5196
|
+
trigger(target, "length");
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
return deletedItems;
|
|
5200
|
+
};
|
|
5201
|
+
return methodCache[prop];
|
|
5202
|
+
case "find": {
|
|
5203
|
+
track(target, Symbol.iterator);
|
|
5204
|
+
if (!methodCache[prop]) {
|
|
5205
|
+
methodCache[prop] = function(predicate, thisArg) {
|
|
5206
|
+
const idx = Array.prototype.findIndex.call(target, predicate, thisArg);
|
|
5207
|
+
if (idx === -1)
|
|
5208
|
+
return;
|
|
5209
|
+
const value2 = target[idx];
|
|
5210
|
+
if (!isObject3(value2))
|
|
5211
|
+
return value2;
|
|
5212
|
+
return wrapChild(value2, node, idx);
|
|
5213
|
+
};
|
|
5214
|
+
}
|
|
5215
|
+
return methodCache[prop];
|
|
5216
|
+
}
|
|
5217
|
+
case "at": {
|
|
5218
|
+
track(target, Symbol.iterator);
|
|
5219
|
+
if (!methodCache[prop]) {
|
|
5220
|
+
methodCache[prop] = function(index2) {
|
|
5221
|
+
let idx = Number(index2);
|
|
5222
|
+
if (!Number.isInteger(idx))
|
|
5223
|
+
idx = Math.trunc(idx);
|
|
5224
|
+
if (idx < 0)
|
|
5225
|
+
idx = target.length + idx;
|
|
5226
|
+
if (idx < 0 || idx >= target.length)
|
|
5227
|
+
return;
|
|
5228
|
+
const value2 = target[idx];
|
|
5229
|
+
if (!isObject3(value2))
|
|
5230
|
+
return value2;
|
|
5231
|
+
return wrapChild(value2, node, idx);
|
|
5232
|
+
};
|
|
5233
|
+
}
|
|
5234
|
+
return methodCache[prop];
|
|
5235
|
+
}
|
|
5236
|
+
case Symbol.iterator:
|
|
5237
|
+
case "values":
|
|
5238
|
+
case "keys":
|
|
5239
|
+
case "entries":
|
|
5240
|
+
case "forEach":
|
|
5241
|
+
case "map":
|
|
5242
|
+
case "filter":
|
|
5243
|
+
case "reduce":
|
|
5244
|
+
case "reduceRight":
|
|
5245
|
+
case "findIndex":
|
|
5246
|
+
case "every":
|
|
5247
|
+
case "some":
|
|
5248
|
+
case "join":
|
|
5249
|
+
track(target, Symbol.iterator);
|
|
5250
|
+
break;
|
|
5251
|
+
case "length":
|
|
5252
|
+
track(target, "length");
|
|
5253
|
+
return Reflect.get(target, prop, receiver);
|
|
5254
|
+
}
|
|
5255
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5256
|
+
const index = arrayIndex(prop);
|
|
5257
|
+
if (index >= 0) {
|
|
5258
|
+
track(target, prop);
|
|
5259
|
+
if (!isObject3(value))
|
|
5260
|
+
return value;
|
|
5261
|
+
return wrapChild(value, node, index);
|
|
5262
|
+
}
|
|
5263
|
+
const isNumericIndex = typeof prop === "string" && !isNaN(parseInt(prop, 10));
|
|
5264
|
+
if (isNumericIndex) {
|
|
5265
|
+
track(target, prop);
|
|
5266
|
+
if (!isObject3(value))
|
|
5267
|
+
return value;
|
|
5268
|
+
return wrapChild(value, node, placeKey(prop));
|
|
5269
|
+
}
|
|
5270
|
+
if (typeof value === "function") {
|
|
5271
|
+
return value.bind(target);
|
|
5272
|
+
}
|
|
5273
|
+
return value;
|
|
5274
|
+
},
|
|
5275
|
+
set(target, prop, value, receiver) {
|
|
5276
|
+
if (isObject3(value))
|
|
5277
|
+
value = unwrapForStore(value);
|
|
5278
|
+
const oldValue = target[prop];
|
|
5279
|
+
if (oldValue === value && Reflect.has(target, prop))
|
|
5280
|
+
return true;
|
|
5281
|
+
if (isObject3(oldValue) && isObject3(value) && deepEqual(oldValue, value))
|
|
5282
|
+
return true;
|
|
5283
|
+
const truncated = prop === "length" && Number(value) < target.length ? target.slice(Number(value)) : undefined;
|
|
5284
|
+
const isNumericIndex = typeof prop === "number" || arrayIndex(prop) >= 0 || typeof prop === "string" && !isNaN(parseInt(prop));
|
|
5285
|
+
const emits = isNumericIndex || prop === "length" || !writesThroughSetter(target, prop, node);
|
|
5286
|
+
const grows = prop === "length" && Number(value) > Number(oldValue);
|
|
5287
|
+
const located = emits ? grows ? locate(node) : locate(node, prop) : undefined;
|
|
5288
|
+
const event = located === undefined || grows ? undefined : { action: "set", path: located.paths[0], oldValue, newValue: value };
|
|
5289
|
+
const held = event !== undefined ? heldItems(value, oldValue) : undefined;
|
|
5290
|
+
const copied = copyPayload(event, located, target, held);
|
|
5291
|
+
if (copied === 0 /* Reaches */) {
|
|
5292
|
+
const after = target.slice();
|
|
5293
|
+
Reflect.set(after, prop, value);
|
|
5294
|
+
copyPayloadReaching(event, located, target, after);
|
|
5295
|
+
}
|
|
5296
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
5297
|
+
if (result && emits) {
|
|
5298
|
+
if (truncated !== undefined) {
|
|
5299
|
+
relinkArray(node, target, target.length, truncated);
|
|
5300
|
+
} else if (prop !== "length") {
|
|
5301
|
+
const key = placeKey(prop);
|
|
5302
|
+
if (isObject3(oldValue))
|
|
5303
|
+
detachPlace(oldValue, node, key);
|
|
5304
|
+
if (isObject3(value))
|
|
5305
|
+
attachValue(value, node, key, copied === 2 /* Fresh */, located && oldValue, held);
|
|
5306
|
+
}
|
|
5307
|
+
if (grows) {
|
|
5308
|
+
if (located !== undefined) {
|
|
5309
|
+
const oldLength = Number(oldValue);
|
|
5310
|
+
const newLength = Number(value);
|
|
5311
|
+
const events = [];
|
|
5312
|
+
for (let i = oldLength;i < newLength; i++) {
|
|
5313
|
+
const index = String(i);
|
|
5314
|
+
for (let j = 0;j < located.paths.length; j++) {
|
|
5315
|
+
events.push({ action: "set", path: [...located.paths[j], index], newValue: undefined });
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
if (events.length > 0)
|
|
5319
|
+
deliver(located.root, events);
|
|
5320
|
+
}
|
|
5321
|
+
} else if (event !== undefined) {
|
|
5322
|
+
dispatch(located, event);
|
|
3067
5323
|
}
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
5324
|
+
if (isObject3(oldValue) && oldValue !== value) {
|
|
5325
|
+
evictDeep(oldValue);
|
|
5326
|
+
}
|
|
5327
|
+
if (truncated !== undefined)
|
|
5328
|
+
evictRemoved(truncated);
|
|
5329
|
+
trigger(target, prop);
|
|
5330
|
+
}
|
|
5331
|
+
return result;
|
|
5332
|
+
},
|
|
5333
|
+
deleteProperty(target, prop) {
|
|
5334
|
+
const oldValue = target[prop];
|
|
5335
|
+
const hadProperty = Object.prototype.hasOwnProperty.call(target, prop);
|
|
5336
|
+
const located = hadProperty ? locate(node, prop) : undefined;
|
|
5337
|
+
const event = located && { action: "delete", path: located.paths[0], oldValue };
|
|
5338
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5339
|
+
const after = target.slice();
|
|
5340
|
+
Reflect.deleteProperty(after, prop);
|
|
5341
|
+
copyPayloadReaching(event, located, target, after);
|
|
5342
|
+
}
|
|
5343
|
+
const result = Reflect.deleteProperty(target, prop);
|
|
5344
|
+
if (hadProperty && result) {
|
|
5345
|
+
if (isObject3(oldValue))
|
|
5346
|
+
detachPlace(oldValue, node, placeKey(prop));
|
|
5347
|
+
if (event !== undefined)
|
|
5348
|
+
dispatch(located, event);
|
|
5349
|
+
trigger(target, prop);
|
|
5350
|
+
if (isObject3(oldValue))
|
|
5351
|
+
evictDeep(oldValue);
|
|
5352
|
+
}
|
|
5353
|
+
return result;
|
|
3092
5354
|
}
|
|
3093
|
-
};
|
|
3094
|
-
|
|
3095
|
-
|
|
5355
|
+
});
|
|
5356
|
+
globalSeen.set(arr, proxy);
|
|
5357
|
+
wrapperCache.set(arr, proxy);
|
|
5358
|
+
proxyStats.created++;
|
|
5359
|
+
proxyStats.arrays++;
|
|
5360
|
+
return proxy;
|
|
3096
5361
|
}
|
|
3097
5362
|
|
|
3098
|
-
// src/wrap-
|
|
3099
|
-
function
|
|
3100
|
-
|
|
5363
|
+
// src/wrap-map.ts
|
|
5364
|
+
function isObject4(value) {
|
|
5365
|
+
return value !== null && typeof value === "object";
|
|
5366
|
+
}
|
|
5367
|
+
function wrapMap(map, node) {
|
|
5368
|
+
const cachedProxy = wrapperCache.get(map);
|
|
3101
5369
|
if (cachedProxy)
|
|
3102
5370
|
return cachedProxy;
|
|
3103
|
-
if (globalSeen.has(
|
|
3104
|
-
return globalSeen.get(
|
|
5371
|
+
if (globalSeen.has(map))
|
|
5372
|
+
return globalSeen.get(map);
|
|
3105
5373
|
const methodCache = {};
|
|
3106
|
-
const
|
|
5374
|
+
const watch = watchIndex(map);
|
|
5375
|
+
const proxy = new Proxy(map, {
|
|
3107
5376
|
get(target, prop, receiver) {
|
|
3108
5377
|
if (prop === "__v_raw" /* RAW */)
|
|
3109
5378
|
return target;
|
|
@@ -3116,54 +5385,95 @@ function wrapSet(set, emit, path = []) {
|
|
|
3116
5385
|
if (methodCache[prop]) {
|
|
3117
5386
|
return methodCache[prop];
|
|
3118
5387
|
}
|
|
3119
|
-
if (prop === "
|
|
3120
|
-
methodCache[prop] = function(value2) {
|
|
5388
|
+
if (prop === "set") {
|
|
5389
|
+
methodCache[prop] = function(key, value2) {
|
|
3121
5390
|
if (value2 != null && typeof value2 === "object")
|
|
3122
5391
|
value2 = unwrapForStore(value2);
|
|
3123
|
-
const existed = target.has(
|
|
5392
|
+
const existed = target.has(key);
|
|
5393
|
+
const oldValue = target.get(key);
|
|
3124
5394
|
const oldSize = target.size;
|
|
5395
|
+
if (oldValue === value2)
|
|
5396
|
+
return receiver;
|
|
5397
|
+
if (oldValue && typeof oldValue === "object" && value2 && typeof value2 === "object" && deepEqual(oldValue, value2))
|
|
5398
|
+
return receiver;
|
|
5399
|
+
const located = locate(node);
|
|
5400
|
+
const event = located && {
|
|
5401
|
+
action: "map-set",
|
|
5402
|
+
path: located.paths[0],
|
|
5403
|
+
key,
|
|
5404
|
+
oldValue,
|
|
5405
|
+
newValue: value2
|
|
5406
|
+
};
|
|
5407
|
+
const held = located && heldItems(value2, oldValue);
|
|
5408
|
+
if (event !== undefined && isObject4(key))
|
|
5409
|
+
nameKey(event, key, target, !existed);
|
|
5410
|
+
const copied = copyPayload(event, located, target, held);
|
|
5411
|
+
if (copied === 0 /* Reaches */) {
|
|
5412
|
+
copyPayloadReaching(event, located, target, shallowCopy(target).set(key, value2));
|
|
5413
|
+
}
|
|
5414
|
+
target.set(key, value2);
|
|
5415
|
+
const newSize = target.size;
|
|
5416
|
+
if (!existed && watch.indexed)
|
|
5417
|
+
indexAdded(target, key);
|
|
5418
|
+
if (isObject4(oldValue))
|
|
5419
|
+
detachPlace(oldValue, node, key);
|
|
5420
|
+
if (isObject4(value2))
|
|
5421
|
+
attachValue(value2, node, key, copied === 2 /* Fresh */, located && oldValue, held);
|
|
5422
|
+
if (event !== undefined)
|
|
5423
|
+
dispatch(located, event);
|
|
3125
5424
|
if (!existed) {
|
|
3126
|
-
target.add(value2);
|
|
3127
|
-
const newSize = target.size;
|
|
3128
|
-
const event = {
|
|
3129
|
-
action: "set-add",
|
|
3130
|
-
path,
|
|
3131
|
-
value: value2
|
|
3132
|
-
};
|
|
3133
|
-
emit?.(event);
|
|
3134
5425
|
trigger(target, Symbol.iterator);
|
|
3135
5426
|
if (oldSize !== newSize) {
|
|
3136
5427
|
trigger(target, "size");
|
|
3137
5428
|
}
|
|
5429
|
+
} else {
|
|
5430
|
+
trigger(target, String(key));
|
|
3138
5431
|
}
|
|
5432
|
+
if (isObject4(oldValue))
|
|
5433
|
+
evictDeep(oldValue);
|
|
3139
5434
|
return receiver;
|
|
3140
5435
|
};
|
|
3141
5436
|
return methodCache[prop];
|
|
3142
5437
|
}
|
|
3143
5438
|
if (prop === "delete") {
|
|
3144
|
-
methodCache[prop] = function(
|
|
3145
|
-
const existed = target.has(
|
|
5439
|
+
methodCache[prop] = function(key) {
|
|
5440
|
+
const existed = target.has(key);
|
|
5441
|
+
if (!existed)
|
|
5442
|
+
return false;
|
|
5443
|
+
const oldValue = target.get(key);
|
|
3146
5444
|
const oldSize = target.size;
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
5445
|
+
const located = locate(node);
|
|
5446
|
+
const event = located && {
|
|
5447
|
+
action: "map-delete",
|
|
5448
|
+
path: located.paths[0],
|
|
5449
|
+
key,
|
|
5450
|
+
oldValue
|
|
5451
|
+
};
|
|
5452
|
+
if (event !== undefined && isObject4(key))
|
|
5453
|
+
nameKey(event, key, target, false);
|
|
5454
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5455
|
+
const after = shallowCopy(target);
|
|
5456
|
+
after.delete(key);
|
|
5457
|
+
copyPayloadReaching(event, located, target, after);
|
|
5458
|
+
}
|
|
5459
|
+
const result = target.delete(key);
|
|
5460
|
+
const newSize = target.size;
|
|
5461
|
+
if (result) {
|
|
5462
|
+
if (watch.indexed)
|
|
5463
|
+
indexRemoved(target, key);
|
|
5464
|
+
if (isObject4(oldValue))
|
|
5465
|
+
detachPlace(oldValue, node, key);
|
|
5466
|
+
if (event !== undefined)
|
|
5467
|
+
dispatch(located, event);
|
|
5468
|
+
trigger(target, Symbol.iterator);
|
|
5469
|
+
if (oldSize !== newSize) {
|
|
5470
|
+
trigger(target, "size");
|
|
3163
5471
|
}
|
|
3164
|
-
|
|
5472
|
+
trigger(target, String(key));
|
|
5473
|
+
if (isObject4(oldValue))
|
|
5474
|
+
evictDeep(oldValue);
|
|
3165
5475
|
}
|
|
3166
|
-
return
|
|
5476
|
+
return result;
|
|
3167
5477
|
};
|
|
3168
5478
|
return methodCache[prop];
|
|
3169
5479
|
}
|
|
@@ -3172,87 +5482,75 @@ function wrapSet(set, emit, path = []) {
|
|
|
3172
5482
|
const oldSize = target.size;
|
|
3173
5483
|
if (oldSize === 0)
|
|
3174
5484
|
return;
|
|
5485
|
+
const removed = [...target];
|
|
3175
5486
|
target.clear();
|
|
3176
5487
|
const newSize = target.size;
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
5488
|
+
if (watch.indexed)
|
|
5489
|
+
forgetReplicaIndex(target);
|
|
5490
|
+
for (const [key, value2] of removed) {
|
|
5491
|
+
if (isObject4(value2))
|
|
5492
|
+
detachPlace(value2, node, key);
|
|
5493
|
+
}
|
|
5494
|
+
const located = locate(node);
|
|
5495
|
+
if (located !== undefined) {
|
|
5496
|
+
dispatch(located, {
|
|
5497
|
+
action: "map-clear",
|
|
5498
|
+
path: located.paths[0],
|
|
5499
|
+
key: null
|
|
5500
|
+
});
|
|
5501
|
+
}
|
|
3183
5502
|
trigger(target, Symbol.iterator);
|
|
3184
5503
|
if (oldSize !== newSize) {
|
|
3185
5504
|
trigger(target, "size");
|
|
3186
5505
|
}
|
|
5506
|
+
for (const [, value2] of removed) {
|
|
5507
|
+
if (isObject4(value2))
|
|
5508
|
+
evictDeep(value2);
|
|
5509
|
+
}
|
|
5510
|
+
};
|
|
5511
|
+
return methodCache[prop];
|
|
5512
|
+
}
|
|
5513
|
+
if (prop === "get") {
|
|
5514
|
+
methodCache[prop] = function(key) {
|
|
5515
|
+
track(target, String(key));
|
|
5516
|
+
const value2 = target.get(key);
|
|
5517
|
+
if (!value2 || typeof value2 !== "object")
|
|
5518
|
+
return value2;
|
|
5519
|
+
return wrapChild(value2, node, key);
|
|
3187
5520
|
};
|
|
3188
5521
|
return methodCache[prop];
|
|
3189
5522
|
}
|
|
3190
5523
|
if (prop === "has") {
|
|
3191
5524
|
track(target, Symbol.iterator);
|
|
3192
|
-
methodCache[prop] = function(
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
}
|
|
3196
|
-
return target.has(value2);
|
|
5525
|
+
methodCache[prop] = function(key) {
|
|
5526
|
+
track(target, String(key));
|
|
5527
|
+
return target.has(key);
|
|
3197
5528
|
}.bind(target);
|
|
3198
5529
|
return methodCache[prop];
|
|
3199
5530
|
}
|
|
3200
|
-
if (prop ===
|
|
5531
|
+
if (prop === Symbol.iterator || prop === "entries" || prop === "values" || prop === "keys" || prop === "forEach") {
|
|
3201
5532
|
track(target, Symbol.iterator);
|
|
3202
|
-
const originalMethod = Reflect.get(target, prop, receiver);
|
|
3203
5533
|
if (prop === "forEach") {
|
|
3204
5534
|
methodCache[prop] = (callbackfn, thisArg) => {
|
|
3205
|
-
const
|
|
3206
|
-
for (const value2 of
|
|
3207
|
-
callbackfn.call(thisArg, value2,
|
|
5535
|
+
const entriesIterator = proxy.entries();
|
|
5536
|
+
for (const [key, value2] of entriesIterator) {
|
|
5537
|
+
callbackfn.call(thisArg, value2, key, proxy);
|
|
3208
5538
|
}
|
|
3209
5539
|
};
|
|
3210
5540
|
return methodCache[prop];
|
|
3211
5541
|
}
|
|
3212
|
-
methodCache[prop] = function* (
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
if (prop === "entries") {
|
|
3218
|
-
valueToWrap = entry[1];
|
|
3219
|
-
}
|
|
3220
|
-
track(target, String(index));
|
|
3221
|
-
let wrappedValue = valueToWrap;
|
|
3222
|
-
if (valueToWrap && typeof valueToWrap === "object") {
|
|
3223
|
-
if (globalSeen.has(valueToWrap)) {
|
|
3224
|
-
wrappedValue = globalSeen.get(valueToWrap);
|
|
3225
|
-
} else {
|
|
3226
|
-
const cachedValueProxy = wrapperCache.get(valueToWrap);
|
|
3227
|
-
if (cachedValueProxy) {
|
|
3228
|
-
wrappedValue = cachedValueProxy;
|
|
3229
|
-
} else {
|
|
3230
|
-
const keyForPath = String(index);
|
|
3231
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${keyForPath}` : keyForPath;
|
|
3232
|
-
let newPath = getPathConcat(pathKey);
|
|
3233
|
-
if (newPath === undefined) {
|
|
3234
|
-
newPath = path.concat(keyForPath);
|
|
3235
|
-
setPathConcat(pathKey, newPath);
|
|
3236
|
-
}
|
|
3237
|
-
if (valueToWrap instanceof Map)
|
|
3238
|
-
wrappedValue = wrapMap(valueToWrap, emit, newPath);
|
|
3239
|
-
else if (valueToWrap instanceof Set)
|
|
3240
|
-
wrappedValue = wrapSet(valueToWrap, emit, newPath);
|
|
3241
|
-
else if (Array.isArray(valueToWrap))
|
|
3242
|
-
wrappedValue = wrapArray(valueToWrap, emit, newPath);
|
|
3243
|
-
else if (valueToWrap instanceof Date)
|
|
3244
|
-
wrappedValue = new Date(valueToWrap.getTime());
|
|
3245
|
-
else
|
|
3246
|
-
wrappedValue = reactive(valueToWrap, emit, newPath);
|
|
3247
|
-
}
|
|
3248
|
-
}
|
|
5542
|
+
methodCache[prop] = function* () {
|
|
5543
|
+
for (const [key, value2] of target.entries()) {
|
|
5544
|
+
if (prop === "keys") {
|
|
5545
|
+
yield key;
|
|
5546
|
+
continue;
|
|
3249
5547
|
}
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
} else {
|
|
5548
|
+
const wrappedValue = isObject4(value2) ? wrapChild(value2, node, key) : value2;
|
|
5549
|
+
if (prop === "values") {
|
|
3253
5550
|
yield wrappedValue;
|
|
5551
|
+
continue;
|
|
3254
5552
|
}
|
|
3255
|
-
|
|
5553
|
+
yield [isObject4(key) ? wrapUnplaced(key) : key, wrappedValue];
|
|
3256
5554
|
}
|
|
3257
5555
|
};
|
|
3258
5556
|
return methodCache[prop];
|
|
@@ -3262,7 +5560,7 @@ function wrapSet(set, emit, path = []) {
|
|
|
3262
5560
|
return target.size;
|
|
3263
5561
|
}
|
|
3264
5562
|
if (prop === "constructor") {
|
|
3265
|
-
return
|
|
5563
|
+
return Map;
|
|
3266
5564
|
}
|
|
3267
5565
|
const value = Reflect.get(target, prop, receiver);
|
|
3268
5566
|
if (typeof value === "function") {
|
|
@@ -3271,22 +5569,26 @@ function wrapSet(set, emit, path = []) {
|
|
|
3271
5569
|
return value;
|
|
3272
5570
|
}
|
|
3273
5571
|
});
|
|
3274
|
-
globalSeen.set(
|
|
3275
|
-
wrapperCache.set(
|
|
5572
|
+
globalSeen.set(map, proxy);
|
|
5573
|
+
wrapperCache.set(map, proxy);
|
|
3276
5574
|
proxyStats.created++;
|
|
3277
|
-
proxyStats.
|
|
5575
|
+
proxyStats.maps++;
|
|
3278
5576
|
return proxy;
|
|
3279
5577
|
}
|
|
3280
5578
|
|
|
3281
|
-
// src/wrap-
|
|
3282
|
-
function
|
|
3283
|
-
|
|
5579
|
+
// src/wrap-set.ts
|
|
5580
|
+
function isObject5(value) {
|
|
5581
|
+
return value !== null && typeof value === "object";
|
|
5582
|
+
}
|
|
5583
|
+
function wrapSet(set, node) {
|
|
5584
|
+
const cachedProxy = wrapperCache.get(set);
|
|
3284
5585
|
if (cachedProxy)
|
|
3285
5586
|
return cachedProxy;
|
|
3286
|
-
if (globalSeen.has(
|
|
3287
|
-
return globalSeen.get(
|
|
5587
|
+
if (globalSeen.has(set))
|
|
5588
|
+
return globalSeen.get(set);
|
|
3288
5589
|
const methodCache = {};
|
|
3289
|
-
const
|
|
5590
|
+
const watch = watchIndex(set);
|
|
5591
|
+
const proxy = new Proxy(set, {
|
|
3290
5592
|
get(target, prop, receiver) {
|
|
3291
5593
|
if (prop === "__v_raw" /* RAW */)
|
|
3292
5594
|
return target;
|
|
@@ -3299,75 +5601,77 @@ function wrapMap(map, emit, path = []) {
|
|
|
3299
5601
|
if (methodCache[prop]) {
|
|
3300
5602
|
return methodCache[prop];
|
|
3301
5603
|
}
|
|
3302
|
-
if (prop === "
|
|
3303
|
-
methodCache[prop] = function(
|
|
5604
|
+
if (prop === "add") {
|
|
5605
|
+
methodCache[prop] = function(value2) {
|
|
3304
5606
|
if (value2 != null && typeof value2 === "object")
|
|
3305
5607
|
value2 = unwrapForStore(value2);
|
|
3306
|
-
const existed = target.has(
|
|
3307
|
-
const oldValue = target.get(key);
|
|
5608
|
+
const existed = target.has(value2);
|
|
3308
5609
|
const oldSize = target.size;
|
|
3309
|
-
if (oldValue === value2)
|
|
3310
|
-
return receiver;
|
|
3311
|
-
if (oldValue && typeof oldValue === "object" && value2 && typeof value2 === "object" && deepEqual(oldValue, value2, new WeakMap))
|
|
3312
|
-
return receiver;
|
|
3313
|
-
target.set(key, value2);
|
|
3314
|
-
const newSize = target.size;
|
|
3315
|
-
const pathKey = path.join(".");
|
|
3316
|
-
let cachedPath = getPathConcat(pathKey);
|
|
3317
|
-
if (cachedPath === undefined) {
|
|
3318
|
-
cachedPath = path;
|
|
3319
|
-
setPathConcat(pathKey, cachedPath);
|
|
3320
|
-
}
|
|
3321
|
-
const event = {
|
|
3322
|
-
action: "map-set",
|
|
3323
|
-
path: cachedPath,
|
|
3324
|
-
key,
|
|
3325
|
-
oldValue,
|
|
3326
|
-
newValue: value2 !== null && typeof value2 === "object" ? deepClone(value2) : value2
|
|
3327
|
-
};
|
|
3328
|
-
emit?.(event);
|
|
3329
5610
|
if (!existed) {
|
|
5611
|
+
const located = locate(node);
|
|
5612
|
+
const event = located && {
|
|
5613
|
+
action: "set-add",
|
|
5614
|
+
path: located.paths[0],
|
|
5615
|
+
value: value2
|
|
5616
|
+
};
|
|
5617
|
+
const copied = copyPayload(event, located, target);
|
|
5618
|
+
if (copied === 0 /* Reaches */) {
|
|
5619
|
+
copyPayloadReaching(event, located, target, shallowCopy(target).add(value2));
|
|
5620
|
+
}
|
|
5621
|
+
target.add(value2);
|
|
5622
|
+
const newSize = target.size;
|
|
5623
|
+
if (watch.indexed)
|
|
5624
|
+
indexAdded(target, value2);
|
|
5625
|
+
if (isObject5(value2))
|
|
5626
|
+
attachValue(value2, node, undefined, copied === 2 /* Fresh */);
|
|
5627
|
+
if (event !== undefined)
|
|
5628
|
+
dispatch(located, event);
|
|
3330
5629
|
trigger(target, Symbol.iterator);
|
|
3331
5630
|
if (oldSize !== newSize) {
|
|
3332
5631
|
trigger(target, "size");
|
|
3333
5632
|
}
|
|
3334
|
-
} else {
|
|
3335
|
-
trigger(target, String(key));
|
|
3336
5633
|
}
|
|
3337
5634
|
return receiver;
|
|
3338
5635
|
};
|
|
3339
5636
|
return methodCache[prop];
|
|
3340
5637
|
}
|
|
3341
5638
|
if (prop === "delete") {
|
|
3342
|
-
methodCache[prop] = function(
|
|
3343
|
-
const existed = target.has(
|
|
3344
|
-
if (!existed)
|
|
3345
|
-
return false;
|
|
3346
|
-
const oldValue = target.get(key);
|
|
5639
|
+
methodCache[prop] = function(value2) {
|
|
5640
|
+
const existed = target.has(value2);
|
|
3347
5641
|
const oldSize = target.size;
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
const
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
setPathConcat(pathKey, cachedPath);
|
|
3356
|
-
}
|
|
3357
|
-
const event = {
|
|
3358
|
-
action: "map-delete",
|
|
3359
|
-
path: cachedPath,
|
|
3360
|
-
key,
|
|
5642
|
+
if (existed) {
|
|
5643
|
+
const oldValue = value2;
|
|
5644
|
+
const located = locate(node);
|
|
5645
|
+
const event = located && {
|
|
5646
|
+
action: "set-delete",
|
|
5647
|
+
path: located.paths[0],
|
|
5648
|
+
value: value2,
|
|
3361
5649
|
oldValue
|
|
3362
5650
|
};
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
5651
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5652
|
+
const after = shallowCopy(target);
|
|
5653
|
+
after.delete(value2);
|
|
5654
|
+
copyPayloadReaching(event, located, target, after);
|
|
3367
5655
|
}
|
|
3368
|
-
|
|
5656
|
+
const result = target.delete(value2);
|
|
5657
|
+
const newSize = target.size;
|
|
5658
|
+
if (result) {
|
|
5659
|
+
if (watch.indexed)
|
|
5660
|
+
indexRemoved(target, value2);
|
|
5661
|
+
if (isObject5(value2))
|
|
5662
|
+
detachPlace(value2, node, undefined);
|
|
5663
|
+
if (event !== undefined)
|
|
5664
|
+
dispatch(located, event);
|
|
5665
|
+
trigger(target, Symbol.iterator);
|
|
5666
|
+
if (oldSize !== newSize) {
|
|
5667
|
+
trigger(target, "size");
|
|
5668
|
+
}
|
|
5669
|
+
if (isObject5(value2))
|
|
5670
|
+
evictDeep(value2);
|
|
5671
|
+
}
|
|
5672
|
+
return result;
|
|
3369
5673
|
}
|
|
3370
|
-
return
|
|
5674
|
+
return false;
|
|
3371
5675
|
};
|
|
3372
5676
|
return methodCache[prop];
|
|
3373
5677
|
}
|
|
@@ -3376,132 +5680,72 @@ function wrapMap(map, emit, path = []) {
|
|
|
3376
5680
|
const oldSize = target.size;
|
|
3377
5681
|
if (oldSize === 0)
|
|
3378
5682
|
return;
|
|
5683
|
+
const removed = [...target];
|
|
3379
5684
|
target.clear();
|
|
3380
5685
|
const newSize = target.size;
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
5686
|
+
if (watch.indexed)
|
|
5687
|
+
forgetReplicaIndex(target);
|
|
5688
|
+
for (const member of removed) {
|
|
5689
|
+
if (isObject5(member))
|
|
5690
|
+
detachPlace(member, node, undefined);
|
|
5691
|
+
}
|
|
5692
|
+
const located = locate(node);
|
|
5693
|
+
if (located !== undefined) {
|
|
5694
|
+
dispatch(located, {
|
|
5695
|
+
action: "set-clear",
|
|
5696
|
+
path: located.paths[0],
|
|
5697
|
+
value: null
|
|
5698
|
+
});
|
|
5699
|
+
}
|
|
3387
5700
|
trigger(target, Symbol.iterator);
|
|
3388
5701
|
if (oldSize !== newSize) {
|
|
3389
5702
|
trigger(target, "size");
|
|
3390
5703
|
}
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
if (prop === "get") {
|
|
3395
|
-
methodCache[prop] = function(key) {
|
|
3396
|
-
track(target, String(key));
|
|
3397
|
-
const value2 = target.get(key);
|
|
3398
|
-
if (!value2 || typeof value2 !== "object")
|
|
3399
|
-
return value2;
|
|
3400
|
-
if (globalSeen.has(value2))
|
|
3401
|
-
return globalSeen.get(value2);
|
|
3402
|
-
const cachedValueProxy = wrapperCache.get(value2);
|
|
3403
|
-
if (cachedValueProxy)
|
|
3404
|
-
return cachedValueProxy;
|
|
3405
|
-
const keyString = String(key);
|
|
3406
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${keyString}` : keyString;
|
|
3407
|
-
let newPath = getPathConcat(pathKey);
|
|
3408
|
-
if (newPath === undefined) {
|
|
3409
|
-
newPath = path.concat(keyString);
|
|
3410
|
-
setPathConcat(pathKey, newPath);
|
|
5704
|
+
for (const member of removed) {
|
|
5705
|
+
if (isObject5(member))
|
|
5706
|
+
evictDeep(member);
|
|
3411
5707
|
}
|
|
3412
|
-
if (value2 instanceof Map)
|
|
3413
|
-
return wrapMap(value2, emit, newPath);
|
|
3414
|
-
if (value2 instanceof Set)
|
|
3415
|
-
return wrapSet(value2, emit, newPath);
|
|
3416
|
-
if (Array.isArray(value2))
|
|
3417
|
-
return wrapArray(value2, emit, newPath);
|
|
3418
|
-
if (value2 instanceof Date)
|
|
3419
|
-
return new Date(value2.getTime());
|
|
3420
|
-
return reactive(value2, emit, newPath);
|
|
3421
5708
|
};
|
|
3422
5709
|
return methodCache[prop];
|
|
3423
5710
|
}
|
|
3424
5711
|
if (prop === "has") {
|
|
3425
5712
|
track(target, Symbol.iterator);
|
|
3426
|
-
methodCache[prop] = function(
|
|
3427
|
-
|
|
3428
|
-
|
|
5713
|
+
methodCache[prop] = function(value2) {
|
|
5714
|
+
if (typeof value2 === "string" || typeof value2 === "number" || typeof value2 === "symbol") {
|
|
5715
|
+
track(target, String(value2));
|
|
5716
|
+
}
|
|
5717
|
+
return target.has(value2);
|
|
3429
5718
|
}.bind(target);
|
|
3430
5719
|
return methodCache[prop];
|
|
3431
5720
|
}
|
|
3432
|
-
if (prop ===
|
|
5721
|
+
if (prop === "values" || prop === Symbol.iterator || prop === "entries" || prop === "keys" || prop === "forEach") {
|
|
3433
5722
|
track(target, Symbol.iterator);
|
|
3434
5723
|
const originalMethod = Reflect.get(target, prop, receiver);
|
|
3435
5724
|
if (prop === "forEach") {
|
|
3436
5725
|
methodCache[prop] = (callbackfn, thisArg) => {
|
|
3437
|
-
const
|
|
3438
|
-
for (const
|
|
3439
|
-
callbackfn.call(thisArg, value2,
|
|
5726
|
+
const valuesIterator = proxy.values();
|
|
5727
|
+
for (const value2 of valuesIterator) {
|
|
5728
|
+
callbackfn.call(thisArg, value2, value2, proxy);
|
|
3440
5729
|
}
|
|
3441
5730
|
};
|
|
3442
5731
|
return methodCache[prop];
|
|
3443
5732
|
}
|
|
3444
5733
|
methodCache[prop] = function* (...args) {
|
|
5734
|
+
let index = 0;
|
|
3445
5735
|
const iterator = originalMethod.apply(target, args);
|
|
3446
5736
|
for (const entry of iterator) {
|
|
3447
|
-
let keyToWrap = entry;
|
|
3448
5737
|
let valueToWrap = entry;
|
|
3449
|
-
|
|
3450
|
-
if (prop === "entries" || prop === Symbol.iterator) {
|
|
3451
|
-
keyToWrap = entry[0];
|
|
5738
|
+
if (prop === "entries") {
|
|
3452
5739
|
valueToWrap = entry[1];
|
|
3453
|
-
isEntry = true;
|
|
3454
|
-
}
|
|
3455
|
-
let wrappedKey = keyToWrap;
|
|
3456
|
-
if (isEntry && keyToWrap && typeof keyToWrap === "object") {
|
|
3457
|
-
if (globalSeen.has(keyToWrap)) {
|
|
3458
|
-
wrappedKey = globalSeen.get(keyToWrap);
|
|
3459
|
-
} else {
|
|
3460
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${String(keyToWrap)}` : String(keyToWrap);
|
|
3461
|
-
let keyPath = getPathConcat(pathKey);
|
|
3462
|
-
if (keyPath === undefined) {
|
|
3463
|
-
keyPath = path.concat(String(keyToWrap));
|
|
3464
|
-
setPathConcat(pathKey, keyPath);
|
|
3465
|
-
}
|
|
3466
|
-
wrappedKey = reactive(keyToWrap, emit, keyPath);
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
let wrappedValue = valueToWrap;
|
|
3470
|
-
if (valueToWrap && typeof valueToWrap === "object") {
|
|
3471
|
-
if (globalSeen.has(valueToWrap)) {
|
|
3472
|
-
wrappedValue = globalSeen.get(valueToWrap);
|
|
3473
|
-
} else {
|
|
3474
|
-
const cachedValueProxy = wrapperCache.get(valueToWrap);
|
|
3475
|
-
if (cachedValueProxy) {
|
|
3476
|
-
wrappedValue = cachedValueProxy;
|
|
3477
|
-
} else {
|
|
3478
|
-
const keyString = String(keyToWrap);
|
|
3479
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${keyString}` : keyString;
|
|
3480
|
-
let newPath = getPathConcat(pathKey);
|
|
3481
|
-
if (newPath === undefined) {
|
|
3482
|
-
newPath = path.concat(keyString);
|
|
3483
|
-
setPathConcat(pathKey, newPath);
|
|
3484
|
-
}
|
|
3485
|
-
if (valueToWrap instanceof Map)
|
|
3486
|
-
wrappedValue = wrapMap(valueToWrap, emit, newPath);
|
|
3487
|
-
else if (valueToWrap instanceof Set)
|
|
3488
|
-
wrappedValue = wrapSet(valueToWrap, emit, newPath);
|
|
3489
|
-
else if (Array.isArray(valueToWrap))
|
|
3490
|
-
wrappedValue = wrapArray(valueToWrap, emit, newPath);
|
|
3491
|
-
else if (valueToWrap instanceof Date)
|
|
3492
|
-
wrappedValue = new Date(valueToWrap.getTime());
|
|
3493
|
-
else
|
|
3494
|
-
wrappedValue = reactive(valueToWrap, emit, newPath);
|
|
3495
|
-
}
|
|
3496
|
-
}
|
|
3497
5740
|
}
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
yield wrappedValue;
|
|
5741
|
+
track(target, String(index));
|
|
5742
|
+
const wrappedValue = isObject5(valueToWrap) ? wrapChild(valueToWrap, node, undefined) : valueToWrap;
|
|
5743
|
+
if (prop === "entries") {
|
|
5744
|
+
yield [wrappedValue, wrappedValue];
|
|
3502
5745
|
} else {
|
|
3503
|
-
yield
|
|
5746
|
+
yield wrappedValue;
|
|
3504
5747
|
}
|
|
5748
|
+
index++;
|
|
3505
5749
|
}
|
|
3506
5750
|
};
|
|
3507
5751
|
return methodCache[prop];
|
|
@@ -3511,350 +5755,24 @@ function wrapMap(map, emit, path = []) {
|
|
|
3511
5755
|
return target.size;
|
|
3512
5756
|
}
|
|
3513
5757
|
if (prop === "constructor") {
|
|
3514
|
-
return
|
|
3515
|
-
}
|
|
3516
|
-
const value = Reflect.get(target, prop, receiver);
|
|
3517
|
-
if (typeof value === "function") {
|
|
3518
|
-
return value.bind(target);
|
|
3519
|
-
}
|
|
3520
|
-
return value;
|
|
3521
|
-
}
|
|
3522
|
-
});
|
|
3523
|
-
globalSeen.set(map, proxy);
|
|
3524
|
-
wrapperCache.set(map, proxy);
|
|
3525
|
-
proxyStats.created++;
|
|
3526
|
-
proxyStats.maps++;
|
|
3527
|
-
return proxy;
|
|
3528
|
-
}
|
|
3529
|
-
|
|
3530
|
-
// src/wrap-array.ts
|
|
3531
|
-
function isObject2(v) {
|
|
3532
|
-
return v && typeof v === "object";
|
|
3533
|
-
}
|
|
3534
|
-
function wrapArray(arr, emit, path = []) {
|
|
3535
|
-
const cachedProxy = wrapperCache.get(arr);
|
|
3536
|
-
if (cachedProxy)
|
|
3537
|
-
return cachedProxy;
|
|
3538
|
-
if (globalSeen.has(arr))
|
|
3539
|
-
return globalSeen.get(arr);
|
|
3540
|
-
const methodCache = {};
|
|
3541
|
-
const proxy = new Proxy(arr, {
|
|
3542
|
-
get(target, prop, receiver) {
|
|
3543
|
-
if (prop === "__v_raw" /* RAW */)
|
|
3544
|
-
return target;
|
|
3545
|
-
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3546
|
-
return true;
|
|
3547
|
-
track(target, prop);
|
|
3548
|
-
if (methodCache[prop]) {
|
|
3549
|
-
return methodCache[prop];
|
|
3550
|
-
}
|
|
3551
|
-
switch (prop) {
|
|
3552
|
-
case "push":
|
|
3553
|
-
track(target, "length");
|
|
3554
|
-
methodCache[prop] = function(...items) {
|
|
3555
|
-
const oldLength = target.length;
|
|
3556
|
-
const result = target.push(...items);
|
|
3557
|
-
const newLength = target.length;
|
|
3558
|
-
if (items.length > 0) {
|
|
3559
|
-
const event = {
|
|
3560
|
-
action: "array-push",
|
|
3561
|
-
path,
|
|
3562
|
-
key: oldLength,
|
|
3563
|
-
items
|
|
3564
|
-
};
|
|
3565
|
-
emit?.(event);
|
|
3566
|
-
trigger(target, Symbol.iterator);
|
|
3567
|
-
if (oldLength !== newLength) {
|
|
3568
|
-
trigger(target, "length");
|
|
3569
|
-
}
|
|
3570
|
-
}
|
|
3571
|
-
return result;
|
|
3572
|
-
};
|
|
3573
|
-
return methodCache[prop];
|
|
3574
|
-
case "pop":
|
|
3575
|
-
track(target, "length");
|
|
3576
|
-
methodCache[prop] = function() {
|
|
3577
|
-
if (target.length === 0)
|
|
3578
|
-
return;
|
|
3579
|
-
const oldLength = target.length;
|
|
3580
|
-
const poppedIndex = oldLength - 1;
|
|
3581
|
-
const oldValue = target[poppedIndex];
|
|
3582
|
-
const result = target.pop();
|
|
3583
|
-
const newLength = target.length;
|
|
3584
|
-
const event = {
|
|
3585
|
-
action: "array-pop",
|
|
3586
|
-
path,
|
|
3587
|
-
key: poppedIndex,
|
|
3588
|
-
oldValue
|
|
3589
|
-
};
|
|
3590
|
-
emit?.(event);
|
|
3591
|
-
if (isObject2(oldValue))
|
|
3592
|
-
evictDeep(oldValue);
|
|
3593
|
-
trigger(target, Symbol.iterator);
|
|
3594
|
-
if (oldLength !== newLength) {
|
|
3595
|
-
trigger(target, "length");
|
|
3596
|
-
}
|
|
3597
|
-
return result;
|
|
3598
|
-
};
|
|
3599
|
-
return methodCache[prop];
|
|
3600
|
-
case "shift":
|
|
3601
|
-
track(target, "length");
|
|
3602
|
-
methodCache[prop] = function() {
|
|
3603
|
-
if (target.length === 0)
|
|
3604
|
-
return;
|
|
3605
|
-
const oldLength = target.length;
|
|
3606
|
-
const oldValue = target[0];
|
|
3607
|
-
const result = target.shift();
|
|
3608
|
-
const newLength = target.length;
|
|
3609
|
-
const event = {
|
|
3610
|
-
action: "array-shift",
|
|
3611
|
-
path,
|
|
3612
|
-
key: 0,
|
|
3613
|
-
oldValue
|
|
3614
|
-
};
|
|
3615
|
-
emit?.(event);
|
|
3616
|
-
if (isObject2(oldValue))
|
|
3617
|
-
evictDeep(oldValue);
|
|
3618
|
-
trigger(target, Symbol.iterator);
|
|
3619
|
-
if (oldLength !== newLength) {
|
|
3620
|
-
trigger(target, "length");
|
|
3621
|
-
}
|
|
3622
|
-
return result;
|
|
3623
|
-
};
|
|
3624
|
-
return methodCache[prop];
|
|
3625
|
-
case "unshift":
|
|
3626
|
-
track(target, "length");
|
|
3627
|
-
methodCache[prop] = function(...items) {
|
|
3628
|
-
const oldLength = target.length;
|
|
3629
|
-
const result = target.unshift(...items);
|
|
3630
|
-
const newLength = target.length;
|
|
3631
|
-
if (items.length > 0) {
|
|
3632
|
-
const event = {
|
|
3633
|
-
action: "array-unshift",
|
|
3634
|
-
path,
|
|
3635
|
-
key: 0,
|
|
3636
|
-
items
|
|
3637
|
-
};
|
|
3638
|
-
emit?.(event);
|
|
3639
|
-
trigger(target, Symbol.iterator);
|
|
3640
|
-
if (oldLength !== newLength) {
|
|
3641
|
-
trigger(target, "length");
|
|
3642
|
-
}
|
|
3643
|
-
}
|
|
3644
|
-
return result;
|
|
3645
|
-
};
|
|
3646
|
-
return methodCache[prop];
|
|
3647
|
-
case "splice":
|
|
3648
|
-
track(target, "length");
|
|
3649
|
-
methodCache[prop] = function(start, deleteCount, ...items) {
|
|
3650
|
-
const oldLength = target.length;
|
|
3651
|
-
const actualStart = start < 0 ? Math.max(target.length + start, 0) : Math.min(start, target.length);
|
|
3652
|
-
const deleteCountNum = deleteCount === undefined ? target.length - actualStart : Number(deleteCount);
|
|
3653
|
-
const actualDeleteCount = Math.min(deleteCountNum, target.length - actualStart);
|
|
3654
|
-
const deletedItems = target.slice(actualStart, actualStart + actualDeleteCount);
|
|
3655
|
-
const result = target.splice(start, deleteCountNum, ...items);
|
|
3656
|
-
const newLength = target.length;
|
|
3657
|
-
if (actualDeleteCount > 0 || items.length > 0) {
|
|
3658
|
-
const event = {
|
|
3659
|
-
action: "array-splice",
|
|
3660
|
-
path,
|
|
3661
|
-
key: actualStart,
|
|
3662
|
-
deleteCount: actualDeleteCount,
|
|
3663
|
-
items: items.length > 0 ? items : undefined,
|
|
3664
|
-
oldValues: deletedItems.length > 0 ? deletedItems : undefined
|
|
3665
|
-
};
|
|
3666
|
-
emit?.(event);
|
|
3667
|
-
for (let i = 0;i < deletedItems.length; i++) {
|
|
3668
|
-
if (isObject2(deletedItems[i]))
|
|
3669
|
-
evictDeep(deletedItems[i]);
|
|
3670
|
-
}
|
|
3671
|
-
trigger(target, Symbol.iterator);
|
|
3672
|
-
if (oldLength !== newLength) {
|
|
3673
|
-
trigger(target, "length");
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
return result;
|
|
3677
|
-
};
|
|
3678
|
-
return methodCache[prop];
|
|
3679
|
-
case "find": {
|
|
3680
|
-
track(target, Symbol.iterator);
|
|
3681
|
-
if (!methodCache[prop]) {
|
|
3682
|
-
methodCache[prop] = function(predicate, thisArg) {
|
|
3683
|
-
const idx = Array.prototype.findIndex.call(target, predicate, thisArg);
|
|
3684
|
-
if (idx === -1)
|
|
3685
|
-
return;
|
|
3686
|
-
const value2 = target[idx];
|
|
3687
|
-
if (!isObject2(value2))
|
|
3688
|
-
return value2;
|
|
3689
|
-
const propKey = String(idx);
|
|
3690
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3691
|
-
let newPath = getPathConcat(pathKey);
|
|
3692
|
-
if (newPath === undefined) {
|
|
3693
|
-
newPath = path.concat(propKey);
|
|
3694
|
-
setPathConcat(pathKey, newPath);
|
|
3695
|
-
}
|
|
3696
|
-
if (globalSeen.has(value2))
|
|
3697
|
-
return globalSeen.get(value2);
|
|
3698
|
-
const cachedValueProxy = wrapperCache.get(value2);
|
|
3699
|
-
if (cachedValueProxy)
|
|
3700
|
-
return cachedValueProxy;
|
|
3701
|
-
if (Array.isArray(value2))
|
|
3702
|
-
return wrapArray(value2, emit, newPath);
|
|
3703
|
-
if (value2 instanceof Map)
|
|
3704
|
-
return wrapMap(value2, emit, newPath);
|
|
3705
|
-
if (value2 instanceof Set)
|
|
3706
|
-
return wrapSet(value2, emit, newPath);
|
|
3707
|
-
if (value2 instanceof Date)
|
|
3708
|
-
return new Date(value2.getTime());
|
|
3709
|
-
return reactive(value2, emit, newPath);
|
|
3710
|
-
};
|
|
3711
|
-
}
|
|
3712
|
-
return methodCache[prop];
|
|
3713
|
-
}
|
|
3714
|
-
case "at": {
|
|
3715
|
-
track(target, Symbol.iterator);
|
|
3716
|
-
if (!methodCache[prop]) {
|
|
3717
|
-
methodCache[prop] = function(index) {
|
|
3718
|
-
let idx = Number(index);
|
|
3719
|
-
if (!Number.isInteger(idx))
|
|
3720
|
-
idx = Math.trunc(idx);
|
|
3721
|
-
if (idx < 0)
|
|
3722
|
-
idx = target.length + idx;
|
|
3723
|
-
if (idx < 0 || idx >= target.length)
|
|
3724
|
-
return;
|
|
3725
|
-
const value2 = target[idx];
|
|
3726
|
-
if (!isObject2(value2))
|
|
3727
|
-
return value2;
|
|
3728
|
-
const propKey = String(idx);
|
|
3729
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3730
|
-
let newPath = getPathConcat(pathKey);
|
|
3731
|
-
if (newPath === undefined) {
|
|
3732
|
-
newPath = path.concat(propKey);
|
|
3733
|
-
setPathConcat(pathKey, newPath);
|
|
3734
|
-
}
|
|
3735
|
-
if (globalSeen.has(value2))
|
|
3736
|
-
return globalSeen.get(value2);
|
|
3737
|
-
const cachedValueProxy = wrapperCache.get(value2);
|
|
3738
|
-
if (cachedValueProxy)
|
|
3739
|
-
return cachedValueProxy;
|
|
3740
|
-
if (Array.isArray(value2))
|
|
3741
|
-
return wrapArray(value2, emit, newPath);
|
|
3742
|
-
if (value2 instanceof Map)
|
|
3743
|
-
return wrapMap(value2, emit, newPath);
|
|
3744
|
-
if (value2 instanceof Set)
|
|
3745
|
-
return wrapSet(value2, emit, newPath);
|
|
3746
|
-
if (value2 instanceof Date)
|
|
3747
|
-
return new Date(value2.getTime());
|
|
3748
|
-
return reactive(value2, emit, newPath);
|
|
3749
|
-
};
|
|
3750
|
-
}
|
|
3751
|
-
return methodCache[prop];
|
|
3752
|
-
}
|
|
3753
|
-
case Symbol.iterator:
|
|
3754
|
-
case "values":
|
|
3755
|
-
case "keys":
|
|
3756
|
-
case "entries":
|
|
3757
|
-
case "forEach":
|
|
3758
|
-
case "map":
|
|
3759
|
-
case "filter":
|
|
3760
|
-
case "reduce":
|
|
3761
|
-
case "reduceRight":
|
|
3762
|
-
case "findIndex":
|
|
3763
|
-
case "every":
|
|
3764
|
-
case "some":
|
|
3765
|
-
case "join":
|
|
3766
|
-
track(target, Symbol.iterator);
|
|
3767
|
-
break;
|
|
3768
|
-
case "length":
|
|
3769
|
-
track(target, "length");
|
|
3770
|
-
return Reflect.get(target, prop, receiver);
|
|
5758
|
+
return Set;
|
|
3771
5759
|
}
|
|
3772
5760
|
const value = Reflect.get(target, prop, receiver);
|
|
3773
|
-
const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(prop, 10));
|
|
3774
|
-
if (isNumericIndex) {
|
|
3775
|
-
track(target, String(prop));
|
|
3776
|
-
if (!isObject2(value))
|
|
3777
|
-
return value;
|
|
3778
|
-
if (globalSeen.has(value))
|
|
3779
|
-
return globalSeen.get(value);
|
|
3780
|
-
const cachedValueProxy = wrapperCache.get(value);
|
|
3781
|
-
if (cachedValueProxy)
|
|
3782
|
-
return cachedValueProxy;
|
|
3783
|
-
const propKey = String(prop);
|
|
3784
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3785
|
-
let newPath = getPathConcat(pathKey);
|
|
3786
|
-
if (newPath === undefined) {
|
|
3787
|
-
newPath = path.concat(propKey);
|
|
3788
|
-
setPathConcat(pathKey, newPath);
|
|
3789
|
-
}
|
|
3790
|
-
if (Array.isArray(value))
|
|
3791
|
-
return wrapArray(value, emit, newPath);
|
|
3792
|
-
if (value instanceof Map)
|
|
3793
|
-
return wrapMap(value, emit, newPath);
|
|
3794
|
-
if (value instanceof Set)
|
|
3795
|
-
return wrapSet(value, emit, newPath);
|
|
3796
|
-
if (value instanceof Date)
|
|
3797
|
-
return new Date(value.getTime());
|
|
3798
|
-
return reactive(value, emit, newPath);
|
|
3799
|
-
}
|
|
3800
5761
|
if (typeof value === "function") {
|
|
3801
5762
|
return value.bind(target);
|
|
3802
5763
|
}
|
|
3803
5764
|
return value;
|
|
3804
|
-
},
|
|
3805
|
-
set(target, prop, value, receiver) {
|
|
3806
|
-
if (isObject2(value))
|
|
3807
|
-
value = unwrapForStore(value);
|
|
3808
|
-
const oldValue = target[prop];
|
|
3809
|
-
if (oldValue === value && Reflect.has(target, prop))
|
|
3810
|
-
return true;
|
|
3811
|
-
if (isObject2(oldValue) && isObject2(value) && deepEqual(oldValue, value, new WeakMap))
|
|
3812
|
-
return true;
|
|
3813
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
3814
|
-
const result = Reflect.set(target, prop, value, receiver);
|
|
3815
|
-
const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(String(prop)));
|
|
3816
|
-
if (result && (!descriptor || !descriptor.set || isNumericIndex)) {
|
|
3817
|
-
const resolvePath = (key) => {
|
|
3818
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${key}` : key;
|
|
3819
|
-
let newPath = getPathConcat(pathKey);
|
|
3820
|
-
if (newPath === undefined) {
|
|
3821
|
-
newPath = path.concat(key);
|
|
3822
|
-
setPathConcat(pathKey, newPath);
|
|
3823
|
-
}
|
|
3824
|
-
return newPath;
|
|
3825
|
-
};
|
|
3826
|
-
if (Array.isArray(target) && prop === "length" && Number(value) > Number(oldValue)) {
|
|
3827
|
-
const oldLength = Number(oldValue);
|
|
3828
|
-
const newLength = Number(value);
|
|
3829
|
-
for (let i = oldLength;i < newLength; i++) {
|
|
3830
|
-
emit?.({ action: "set", path: resolvePath(String(i)), newValue: undefined });
|
|
3831
|
-
}
|
|
3832
|
-
} else {
|
|
3833
|
-
const event = {
|
|
3834
|
-
action: "set",
|
|
3835
|
-
path: resolvePath(String(prop)),
|
|
3836
|
-
oldValue,
|
|
3837
|
-
newValue: isObject2(value) ? deepClone(value) : value
|
|
3838
|
-
};
|
|
3839
|
-
emit?.(event);
|
|
3840
|
-
}
|
|
3841
|
-
if (isObject2(oldValue) && oldValue !== value) {
|
|
3842
|
-
evictDeep(oldValue);
|
|
3843
|
-
}
|
|
3844
|
-
trigger(target, prop);
|
|
3845
|
-
}
|
|
3846
|
-
return result;
|
|
3847
5765
|
}
|
|
3848
5766
|
});
|
|
3849
|
-
globalSeen.set(
|
|
3850
|
-
wrapperCache.set(
|
|
5767
|
+
globalSeen.set(set, proxy);
|
|
5768
|
+
wrapperCache.set(set, proxy);
|
|
3851
5769
|
proxyStats.created++;
|
|
3852
|
-
proxyStats.
|
|
5770
|
+
proxyStats.sets++;
|
|
3853
5771
|
return proxy;
|
|
3854
5772
|
}
|
|
3855
5773
|
|
|
3856
5774
|
// src/reactive.ts
|
|
3857
|
-
function
|
|
5775
|
+
function isObject6(v) {
|
|
3858
5776
|
return v && typeof v === "object";
|
|
3859
5777
|
}
|
|
3860
5778
|
function isReactive(value) {
|
|
@@ -3868,60 +5786,98 @@ function createAsyncEmit(emit) {
|
|
|
3868
5786
|
if (!flushScheduled) {
|
|
3869
5787
|
flushScheduled = true;
|
|
3870
5788
|
queueMicrotask(() => {
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
5789
|
+
let failed = false;
|
|
5790
|
+
let failure;
|
|
5791
|
+
let next = 0;
|
|
5792
|
+
while (next < queue.length) {
|
|
5793
|
+
try {
|
|
5794
|
+
emit(queue[next++]);
|
|
5795
|
+
} catch (error) {
|
|
5796
|
+
if (!failed) {
|
|
5797
|
+
failed = true;
|
|
5798
|
+
failure = error;
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
if (next === FLUSH_CHUNK) {
|
|
5802
|
+
queue.splice(0, next);
|
|
5803
|
+
next = 0;
|
|
5804
|
+
}
|
|
3875
5805
|
}
|
|
5806
|
+
queue.length = 0;
|
|
5807
|
+
flushScheduled = false;
|
|
5808
|
+
if (failed)
|
|
5809
|
+
throw failure;
|
|
3876
5810
|
});
|
|
3877
5811
|
}
|
|
3878
5812
|
};
|
|
3879
5813
|
}
|
|
5814
|
+
var FLUSH_CHUNK = 1024;
|
|
3880
5815
|
function reactive(obj, emit, path = [], options) {
|
|
3881
5816
|
if (obj["__v_skip" /* SKIP */]) {
|
|
3882
5817
|
return obj;
|
|
3883
5818
|
}
|
|
3884
|
-
|
|
3885
|
-
|
|
5819
|
+
const existing = globalSeen.get(obj);
|
|
5820
|
+
if (existing !== undefined)
|
|
5821
|
+
return existing;
|
|
5822
|
+
if (obj["__v_isReactive" /* IS_REACTIVE */])
|
|
5823
|
+
return obj;
|
|
3886
5824
|
if (emit && path.length === 0 && options?.async) {
|
|
3887
5825
|
emit = createAsyncEmit(emit);
|
|
3888
5826
|
}
|
|
5827
|
+
let fresh = false;
|
|
3889
5828
|
if (emit && path.length === 0) {
|
|
3890
5829
|
try {
|
|
3891
|
-
const
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
newValue: obj
|
|
3895
|
-
};
|
|
3896
|
-
emit(initialEvent);
|
|
5830
|
+
const newValue = cloneStored(obj, undefined, 2 /* All */);
|
|
5831
|
+
fresh = copiedFresh;
|
|
5832
|
+
emit({ action: "replace", path: [], newValue });
|
|
3897
5833
|
} catch (error) {
|
|
5834
|
+
if (error instanceof SnapshotLimitError)
|
|
5835
|
+
throw error;
|
|
3898
5836
|
console.error("Failed to emit initial reactive state:", error);
|
|
3899
5837
|
}
|
|
3900
5838
|
}
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
if (
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
5839
|
+
const node = ensureLocationNode(obj);
|
|
5840
|
+
node.root = { emit, path, async: emit !== undefined && options?.async === true, undelivered: undefined };
|
|
5841
|
+
node.scope = node.root;
|
|
5842
|
+
if (emit && !fresh)
|
|
5843
|
+
adoptRoot(node);
|
|
5844
|
+
return createProxy(obj, node, options);
|
|
5845
|
+
}
|
|
5846
|
+
function wrapChild(raw, parent, key, options) {
|
|
5847
|
+
let node = getLocationNode(raw);
|
|
5848
|
+
if (node !== undefined && node.proxy !== undefined) {
|
|
5849
|
+
notePlace(node, parent, key);
|
|
5850
|
+
node.scope ??= parent.scope;
|
|
5851
|
+
return node.proxy;
|
|
5852
|
+
}
|
|
5853
|
+
if (raw["__v_skip" /* SKIP */])
|
|
5854
|
+
return raw;
|
|
5855
|
+
if (raw["__v_isReactive" /* IS_REACTIVE */])
|
|
5856
|
+
return wrapChild(toRaw(raw), parent, key, options);
|
|
5857
|
+
if (raw instanceof Date)
|
|
5858
|
+
return new Date(raw.getTime());
|
|
5859
|
+
node ??= ensureLocationNode(raw);
|
|
5860
|
+
notePlace(node, parent, key);
|
|
5861
|
+
node.scope ??= parent.scope;
|
|
5862
|
+
return restoreEvicted(node) ?? createProxy(raw, node, options);
|
|
5863
|
+
}
|
|
5864
|
+
function wrapUnplaced(raw) {
|
|
5865
|
+
if (raw["__v_skip" /* SKIP */])
|
|
5866
|
+
return raw;
|
|
5867
|
+
const existing = globalSeen.get(raw);
|
|
5868
|
+
if (existing !== undefined)
|
|
5869
|
+
return existing;
|
|
5870
|
+
if (raw["__v_isReactive" /* IS_REACTIVE */])
|
|
5871
|
+
return wrapUnplaced(toRaw(raw));
|
|
5872
|
+
const node = ensureLocationNode(raw);
|
|
5873
|
+
return restoreEvicted(node) ?? createProxy(raw, node);
|
|
5874
|
+
}
|
|
5875
|
+
function createProxy(raw, node, options) {
|
|
5876
|
+
const proxy = Array.isArray(raw) ? wrapArray(raw, node) : raw instanceof Map ? wrapMap(raw, node) : raw instanceof Set ? wrapSet(raw, node) : wrapObject(raw, node, options);
|
|
5877
|
+
node.proxy = proxy;
|
|
5878
|
+
return proxy;
|
|
5879
|
+
}
|
|
5880
|
+
function wrapObject(obj, node, options) {
|
|
3925
5881
|
const proxy = new Proxy(obj, {
|
|
3926
5882
|
get(target, prop, receiver) {
|
|
3927
5883
|
if (prop === "__v_raw" /* RAW */) {
|
|
@@ -3932,44 +5888,45 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3932
5888
|
}
|
|
3933
5889
|
const value = Reflect.get(target, prop, receiver);
|
|
3934
5890
|
track(target, prop);
|
|
3935
|
-
if (!
|
|
5891
|
+
if (!isObject6(value))
|
|
3936
5892
|
return value;
|
|
3937
|
-
|
|
3938
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3939
|
-
let newPath = getPathConcat(pathKey);
|
|
3940
|
-
if (newPath === undefined) {
|
|
3941
|
-
newPath = path.concat(propKey);
|
|
3942
|
-
setPathConcat(pathKey, newPath);
|
|
3943
|
-
}
|
|
3944
|
-
return wrapValue(value, newPath);
|
|
5893
|
+
return wrapChild(value, node, prop, options);
|
|
3945
5894
|
},
|
|
3946
5895
|
set(target, prop, value, receiver) {
|
|
3947
|
-
if (
|
|
5896
|
+
if (isObject6(value))
|
|
3948
5897
|
value = unwrapForStore(value);
|
|
3949
5898
|
const oldValue = target[prop];
|
|
3950
5899
|
if (oldValue === value)
|
|
3951
5900
|
return true;
|
|
3952
|
-
if (!options?.async &&
|
|
5901
|
+
if (!options?.async && isObject6(oldValue) && isObject6(value) && deepEqual(oldValue, value))
|
|
3953
5902
|
return true;
|
|
3954
|
-
const
|
|
5903
|
+
const emits = !writesThroughSetter(target, prop, node);
|
|
5904
|
+
const located = emits ? locate(node, prop) : undefined;
|
|
5905
|
+
const event = located && {
|
|
5906
|
+
action: "set",
|
|
5907
|
+
path: located.paths[0],
|
|
5908
|
+
oldValue,
|
|
5909
|
+
newValue: value
|
|
5910
|
+
};
|
|
5911
|
+
const held = located && heldItems(value, oldValue);
|
|
5912
|
+
const copied = copyPayload(event, located, target, held);
|
|
5913
|
+
if (copied === 0 /* Reaches */) {
|
|
5914
|
+
const after = shallowCopy(target);
|
|
5915
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
5916
|
+
if (descriptor === undefined || descriptor.enumerable)
|
|
5917
|
+
setData(after, prop, value);
|
|
5918
|
+
copyPayloadReaching(event, located, target, after);
|
|
5919
|
+
}
|
|
3955
5920
|
const result = Reflect.set(target, prop, value, receiver);
|
|
3956
|
-
if (result &&
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
}
|
|
3964
|
-
const event = {
|
|
3965
|
-
action: "set",
|
|
3966
|
-
path: newPath,
|
|
3967
|
-
oldValue,
|
|
3968
|
-
newValue: isObject3(value) ? deepClone(value) : value
|
|
3969
|
-
};
|
|
3970
|
-
emit?.(event);
|
|
5921
|
+
if (result && emits) {
|
|
5922
|
+
if (isObject6(oldValue))
|
|
5923
|
+
detachPlace(oldValue, node, prop);
|
|
5924
|
+
if (isObject6(value))
|
|
5925
|
+
attachValue(value, node, prop, copied === 2 /* Fresh */, located && oldValue, held);
|
|
5926
|
+
if (event !== undefined)
|
|
5927
|
+
dispatch(located, event);
|
|
3971
5928
|
trigger(target, prop);
|
|
3972
|
-
if (
|
|
5929
|
+
if (isObject6(oldValue)) {
|
|
3973
5930
|
evictDeep(oldValue);
|
|
3974
5931
|
}
|
|
3975
5932
|
}
|
|
@@ -3978,23 +5935,25 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3978
5935
|
deleteProperty(target, prop) {
|
|
3979
5936
|
const oldValue = target[prop];
|
|
3980
5937
|
const hadProperty = Object.prototype.hasOwnProperty.call(target, prop);
|
|
5938
|
+
const located = hadProperty ? locate(node, prop) : undefined;
|
|
5939
|
+
const event = located && {
|
|
5940
|
+
action: "delete",
|
|
5941
|
+
path: located.paths[0],
|
|
5942
|
+
oldValue
|
|
5943
|
+
};
|
|
5944
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5945
|
+
const after = shallowCopy(target);
|
|
5946
|
+
delete after[prop];
|
|
5947
|
+
copyPayloadReaching(event, located, target, after);
|
|
5948
|
+
}
|
|
3981
5949
|
const result = Reflect.deleteProperty(target, prop);
|
|
3982
5950
|
if (hadProperty && result) {
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
newPath = path.concat(propKey);
|
|
3988
|
-
setPathConcat(pathKey, newPath);
|
|
3989
|
-
}
|
|
3990
|
-
const event = {
|
|
3991
|
-
action: "delete",
|
|
3992
|
-
path: newPath,
|
|
3993
|
-
oldValue
|
|
3994
|
-
};
|
|
3995
|
-
emit?.(event);
|
|
5951
|
+
if (isObject6(oldValue))
|
|
5952
|
+
detachPlace(oldValue, node, prop);
|
|
5953
|
+
if (event !== undefined)
|
|
5954
|
+
dispatch(located, event);
|
|
3996
5955
|
trigger(target, prop);
|
|
3997
|
-
if (
|
|
5956
|
+
if (isObject6(oldValue)) {
|
|
3998
5957
|
evictDeep(oldValue);
|
|
3999
5958
|
}
|
|
4000
5959
|
}
|
|
@@ -4006,6 +5965,260 @@ function reactive(obj, emit, path = [], options) {
|
|
|
4006
5965
|
proxyStats.objects++;
|
|
4007
5966
|
return proxy;
|
|
4008
5967
|
}
|
|
5968
|
+
|
|
5969
|
+
// src/state.ts
|
|
5970
|
+
function getValue(obj, key) {
|
|
5971
|
+
if (obj instanceof Map)
|
|
5972
|
+
return obj.get(key);
|
|
5973
|
+
return obj[key];
|
|
5974
|
+
}
|
|
5975
|
+
function setValue(obj, key, value) {
|
|
5976
|
+
if (obj instanceof Map)
|
|
5977
|
+
obj.set(key, value);
|
|
5978
|
+
else
|
|
5979
|
+
obj[key] = value;
|
|
5980
|
+
}
|
|
5981
|
+
function deleteValue(obj, key) {
|
|
5982
|
+
if (obj instanceof Map)
|
|
5983
|
+
obj.delete(key);
|
|
5984
|
+
else
|
|
5985
|
+
delete obj[key];
|
|
5986
|
+
}
|
|
5987
|
+
function validateCachedPath(root, fullPath, pathKey, cached) {
|
|
5988
|
+
if (fullPath.length === 0)
|
|
5989
|
+
return cached;
|
|
5990
|
+
const lastKey = fullPath[fullPath.length - 1];
|
|
5991
|
+
let grandparent = root;
|
|
5992
|
+
for (let i = 0;i < fullPath.length - 1; i++) {
|
|
5993
|
+
grandparent = grandparent ? getValue(grandparent, fullPath[i]) : undefined;
|
|
5994
|
+
if (grandparent === undefined)
|
|
5995
|
+
break;
|
|
5996
|
+
}
|
|
5997
|
+
if (grandparent === undefined) {
|
|
5998
|
+
evictDescendantsFromPathCache(root, pathKey);
|
|
5999
|
+
return;
|
|
6000
|
+
}
|
|
6001
|
+
const actual = getValue(grandparent, lastKey);
|
|
6002
|
+
if (actual === cached)
|
|
6003
|
+
return cached;
|
|
6004
|
+
evictDescendantsFromPathCache(root, pathKey);
|
|
6005
|
+
return;
|
|
6006
|
+
}
|
|
6007
|
+
var actionHandlers = {
|
|
6008
|
+
set: function(parent, key, event) {
|
|
6009
|
+
if (Array.isArray(parent) && key === "length" && Number(event.newValue) > parent.length) {
|
|
6010
|
+
console.warn(`refusing to grow array length via bare set at path ${event.path.join(".")}`);
|
|
6011
|
+
return;
|
|
6012
|
+
}
|
|
6013
|
+
setValue(parent, key, event.newValue);
|
|
6014
|
+
},
|
|
6015
|
+
delete: function(parent, key) {
|
|
6016
|
+
deleteValue(parent, key);
|
|
6017
|
+
},
|
|
6018
|
+
"array-push": function(targetArray, _keyIgnored, event) {
|
|
6019
|
+
if (!Array.isArray(targetArray)) {
|
|
6020
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6021
|
+
return;
|
|
6022
|
+
}
|
|
6023
|
+
if (!event.items) {
|
|
6024
|
+
console.warn("array-push event missing items");
|
|
6025
|
+
return;
|
|
6026
|
+
}
|
|
6027
|
+
targetArray.push(...event.items);
|
|
6028
|
+
},
|
|
6029
|
+
"array-pop": function(targetArray, _keyIgnored, event) {
|
|
6030
|
+
if (!Array.isArray(targetArray)) {
|
|
6031
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6032
|
+
return;
|
|
6033
|
+
}
|
|
6034
|
+
if (targetArray.length > 0) {
|
|
6035
|
+
targetArray.pop();
|
|
6036
|
+
}
|
|
6037
|
+
},
|
|
6038
|
+
"array-splice": function(targetArray, _keyIgnored, event) {
|
|
6039
|
+
if (!Array.isArray(targetArray)) {
|
|
6040
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6041
|
+
return;
|
|
6042
|
+
}
|
|
6043
|
+
if (event.key === undefined || event.deleteCount === undefined) {
|
|
6044
|
+
console.warn("array-splice event missing key or deletecount");
|
|
6045
|
+
return;
|
|
6046
|
+
}
|
|
6047
|
+
if (event.items && event.items.length > 0) {
|
|
6048
|
+
targetArray.splice(event.key, event.deleteCount, ...event.items);
|
|
6049
|
+
} else {
|
|
6050
|
+
targetArray.splice(event.key, event.deleteCount);
|
|
6051
|
+
}
|
|
6052
|
+
},
|
|
6053
|
+
"array-shift": function(targetArray, _keyIgnored, event) {
|
|
6054
|
+
if (!Array.isArray(targetArray)) {
|
|
6055
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6056
|
+
return;
|
|
6057
|
+
}
|
|
6058
|
+
if (targetArray.length > 0) {
|
|
6059
|
+
targetArray.shift();
|
|
6060
|
+
}
|
|
6061
|
+
},
|
|
6062
|
+
"array-unshift": function(targetArray, _keyIgnored, event) {
|
|
6063
|
+
if (!Array.isArray(targetArray)) {
|
|
6064
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6065
|
+
return;
|
|
6066
|
+
}
|
|
6067
|
+
if (!event.items) {
|
|
6068
|
+
console.warn("array-unshift event missing items");
|
|
6069
|
+
return;
|
|
6070
|
+
}
|
|
6071
|
+
targetArray.unshift(...event.items);
|
|
6072
|
+
},
|
|
6073
|
+
"map-set": function(targetMap2, _parentKeyIgnored, event) {
|
|
6074
|
+
if (!(targetMap2 instanceof Map)) {
|
|
6075
|
+
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
6076
|
+
return;
|
|
6077
|
+
}
|
|
6078
|
+
replicaMapSet(targetMap2, event.key, event.newValue);
|
|
6079
|
+
},
|
|
6080
|
+
"map-delete": function(targetMap2, _parentKeyIgnored, event) {
|
|
6081
|
+
if (!(targetMap2 instanceof Map)) {
|
|
6082
|
+
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
6083
|
+
return;
|
|
6084
|
+
}
|
|
6085
|
+
replicaMapDelete(targetMap2, event.key);
|
|
6086
|
+
},
|
|
6087
|
+
"map-clear": function(targetMap2, _parentKeyIgnored, event) {
|
|
6088
|
+
if (!(targetMap2 instanceof Map)) {
|
|
6089
|
+
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
6090
|
+
return;
|
|
6091
|
+
}
|
|
6092
|
+
targetMap2.clear();
|
|
6093
|
+
forgetReplicaIndex(targetMap2);
|
|
6094
|
+
},
|
|
6095
|
+
"set-add": function(targetSet, _keyIgnored, event) {
|
|
6096
|
+
if (!(targetSet instanceof Set)) {
|
|
6097
|
+
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
6098
|
+
return;
|
|
6099
|
+
}
|
|
6100
|
+
replicaAdd(targetSet, event.value);
|
|
6101
|
+
},
|
|
6102
|
+
"set-delete": function(targetSet, _keyIgnored, event) {
|
|
6103
|
+
if (!(targetSet instanceof Set)) {
|
|
6104
|
+
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
6105
|
+
return;
|
|
6106
|
+
}
|
|
6107
|
+
replicaDelete(targetSet, event.value);
|
|
6108
|
+
},
|
|
6109
|
+
"set-clear": function(targetSet, _keyIgnored, event) {
|
|
6110
|
+
if (!(targetSet instanceof Set)) {
|
|
6111
|
+
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
6112
|
+
return;
|
|
6113
|
+
}
|
|
6114
|
+
targetSet.clear();
|
|
6115
|
+
forgetReplicaIndex(targetSet);
|
|
6116
|
+
},
|
|
6117
|
+
replace: function(target, _keyIgnored, event) {
|
|
6118
|
+
const newValue = event.newValue;
|
|
6119
|
+
if (newValue === undefined || newValue === null) {
|
|
6120
|
+
console.warn("replace action requires newValue");
|
|
6121
|
+
return;
|
|
6122
|
+
}
|
|
6123
|
+
if (Array.isArray(target) && Array.isArray(newValue)) {
|
|
6124
|
+
target.splice(0, target.length, ...newValue);
|
|
6125
|
+
} else if (target instanceof Map && newValue instanceof Map) {
|
|
6126
|
+
const newValueEntries = [...newValue.entries()];
|
|
6127
|
+
target.clear();
|
|
6128
|
+
forgetReplicaIndex(target);
|
|
6129
|
+
const reactiveTarget = isReactive(target);
|
|
6130
|
+
for (const [key, value] of newValueEntries) {
|
|
6131
|
+
if (reactiveTarget)
|
|
6132
|
+
replicaMapSet(target, key, value);
|
|
6133
|
+
else
|
|
6134
|
+
target.set(key, value);
|
|
6135
|
+
}
|
|
6136
|
+
} else if (target instanceof Set && newValue instanceof Set) {
|
|
6137
|
+
const newValueEntries = [...newValue.values()];
|
|
6138
|
+
target.clear();
|
|
6139
|
+
forgetReplicaIndex(target);
|
|
6140
|
+
const reactiveTarget = isReactive(target);
|
|
6141
|
+
for (const value of newValueEntries) {
|
|
6142
|
+
if (reactiveTarget)
|
|
6143
|
+
replicaAdd(target, value);
|
|
6144
|
+
else
|
|
6145
|
+
target.add(value);
|
|
6146
|
+
}
|
|
6147
|
+
} else if (typeof target === "object" && target !== null && typeof newValue === "object" && newValue !== null) {
|
|
6148
|
+
Object.keys(target).forEach((key) => delete target[key]);
|
|
6149
|
+
Object.assign(target, newValue);
|
|
6150
|
+
} else {
|
|
6151
|
+
console.warn(`Type mismatch or unsupported type for 'replace' action at path ${event.path.join(".")}. Target type: ${typeof target} ${target.constructor.name}, New value type: ${typeof newValue} ${newValue.constructor.name}`);
|
|
6152
|
+
}
|
|
6153
|
+
}
|
|
6154
|
+
};
|
|
6155
|
+
function updateState(root, event) {
|
|
6156
|
+
const { action, path } = event;
|
|
6157
|
+
if (!path || path.length === 0 && action !== "replace") {
|
|
6158
|
+
console.warn("event path is invalid for action", event);
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
const handler = actionHandlers[action];
|
|
6162
|
+
if (!handler) {
|
|
6163
|
+
console.error(`unhandled action type: ${action}`, event);
|
|
6164
|
+
return;
|
|
6165
|
+
}
|
|
6166
|
+
let targetForHandler;
|
|
6167
|
+
let keyForHandler = null;
|
|
6168
|
+
if (action === "set" || action === "delete") {
|
|
6169
|
+
if (path.length === 1) {
|
|
6170
|
+
targetForHandler = root;
|
|
6171
|
+
keyForHandler = path[0];
|
|
6172
|
+
} else {
|
|
6173
|
+
const parentPath = path.slice(0, -1);
|
|
6174
|
+
const parentPathKey = parentPath.join(".");
|
|
6175
|
+
let parent = pathCache.get(root)?.get(parentPathKey);
|
|
6176
|
+
if (parent !== undefined) {
|
|
6177
|
+
parent = validateCachedPath(root, parentPath, parentPathKey, parent);
|
|
6178
|
+
}
|
|
6179
|
+
if (parent === undefined) {
|
|
6180
|
+
parent = parentPath.reduce((acc, key) => acc ? getValue(acc, key) : undefined, root);
|
|
6181
|
+
if (parent !== undefined)
|
|
6182
|
+
setInPathCache(root, parentPathKey, parent);
|
|
6183
|
+
}
|
|
6184
|
+
if (parent === undefined) {
|
|
6185
|
+
console.warn(`parent path ${parentPathKey} not found for action ${action}`);
|
|
6186
|
+
return;
|
|
6187
|
+
}
|
|
6188
|
+
targetForHandler = parent;
|
|
6189
|
+
keyForHandler = path[path.length - 1];
|
|
6190
|
+
}
|
|
6191
|
+
} else if (action.startsWith("array-") || action.startsWith("map-") || action.startsWith("set-") || action === "replace") {
|
|
6192
|
+
if (path.length === 0 && action === "replace") {
|
|
6193
|
+
targetForHandler = root;
|
|
6194
|
+
} else {
|
|
6195
|
+
const targetPath = path;
|
|
6196
|
+
const targetPathKey = targetPath.join(".");
|
|
6197
|
+
let targetCollection = pathCache.get(root)?.get(targetPathKey);
|
|
6198
|
+
if (targetCollection !== undefined) {
|
|
6199
|
+
targetCollection = validateCachedPath(root, targetPath, targetPathKey, targetCollection);
|
|
6200
|
+
}
|
|
6201
|
+
if (targetCollection === undefined) {
|
|
6202
|
+
targetCollection = targetPath.reduce((acc, key) => acc ? getValue(acc, key) : undefined, root);
|
|
6203
|
+
if (targetCollection !== undefined)
|
|
6204
|
+
setInPathCache(root, targetPathKey, targetCollection);
|
|
6205
|
+
}
|
|
6206
|
+
if (targetCollection === undefined) {
|
|
6207
|
+
console.warn(`target at path ${targetPathKey} not found for action ${action}`);
|
|
6208
|
+
return;
|
|
6209
|
+
}
|
|
6210
|
+
targetForHandler = targetCollection;
|
|
6211
|
+
}
|
|
6212
|
+
} else {
|
|
6213
|
+
console.error(`unexpected action type passed checks: ${action}`);
|
|
6214
|
+
return;
|
|
6215
|
+
}
|
|
6216
|
+
handler(targetForHandler, keyForHandler, event);
|
|
6217
|
+
if (action === "set" && event.newValue != null && typeof event.newValue === "object") {
|
|
6218
|
+
const fullPathKey = path.join(".");
|
|
6219
|
+
evictDescendantsFromPathCache(root, fullPathKey);
|
|
6220
|
+
}
|
|
6221
|
+
}
|
|
4009
6222
|
// src/ref.ts
|
|
4010
6223
|
var isRefSymbol = Symbol("isRef");
|
|
4011
6224
|
function ref(value) {
|