@vmz/core 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client-nav.d.ts +5 -55
- package/dist/browser/client-nav.js +5 -769
- package/dist/browser/diagnostics/precision-trace.d.ts +47 -0
- package/dist/browser/diagnostics/precision-trace.js +86 -0
- package/dist/browser/dom/attributes.d.ts +5 -0
- package/dist/browser/dom/attributes.js +102 -0
- package/dist/browser/dom/component.d.ts +11 -0
- package/dist/browser/dom/component.js +255 -0
- package/dist/browser/dom/direct-api.d.ts +66 -0
- package/dist/browser/dom/direct-api.js +446 -0
- package/dist/browser/dom/lifecycle.d.ts +9 -0
- package/dist/browser/dom/lifecycle.js +161 -0
- package/dist/browser/dom/registry.d.ts +5 -0
- package/dist/browser/dom/registry.js +16 -0
- package/dist/browser/dom-core.d.ts +51 -249
- package/dist/browser/dom-core.js +51 -2521
- package/dist/browser/navigation/client-navigation.d.ts +44 -0
- package/dist/browser/navigation/client-navigation.js +277 -0
- package/dist/browser/navigation/extract-html.d.ts +1 -0
- package/dist/browser/navigation/extract-html.js +5 -0
- package/dist/browser/navigation/layout-retain.d.ts +3 -0
- package/dist/browser/navigation/layout-retain.js +34 -0
- package/dist/browser/navigation/locale-transition.d.ts +24 -0
- package/dist/browser/navigation/locale-transition.js +323 -0
- package/dist/browser/navigation/scroll-focus.d.ts +14 -0
- package/dist/browser/navigation/scroll-focus.js +87 -0
- package/dist/browser/reactivity/patch-scheduler.d.ts +12 -0
- package/dist/browser/reactivity/patch-scheduler.js +720 -0
- package/dist/browser/reactivity/write-barrier.d.ts +16 -0
- package/dist/browser/reactivity/write-barrier.js +546 -0
- package/dist/browser/resume/adopt.d.ts +1 -0
- package/dist/browser/resume/adopt.js +168 -0
- package/dist/browser/resume/hydrate.d.ts +4 -0
- package/dist/browser/resume/hydrate.js +107 -0
- package/dist/browser/resume/resume.d.ts +3 -0
- package/dist/browser/resume/resume.js +102 -0
- package/dist/faces/dom.browser.d.ts +2 -1
- package/dist/faces/dom.browser.js +2 -1
- package/dist/host/{deployment-registry.d.ts → deployment/deployment-registry.d.ts} +1 -1
- package/dist/host/{deployment-registry.js → deployment/deployment-registry.js} +1 -1
- package/dist/host/list-client-components.d.ts +2 -2
- package/dist/host/list-client-components.js +4 -4
- package/dist/host/{render-host.d.ts → render/render-host.d.ts} +2 -2
- package/dist/host/{render-host.js → render/render-host.js} +1 -1
- package/dist/host/{route-layout-chain.js → render/route-layout-chain.js} +1 -1
- package/dist/host/serve/bootstrap.d.ts +1 -0
- package/dist/host/serve/bootstrap.js +25 -0
- package/dist/host/serve/constants.d.ts +6 -0
- package/dist/host/serve/constants.js +6 -0
- package/dist/host/serve/hmr-dev.d.ts +34 -0
- package/dist/host/serve/hmr-dev.js +294 -0
- package/dist/host/serve/http.d.ts +1 -0
- package/dist/host/serve/http.js +124 -0
- package/dist/host/serve/locale-theme.d.ts +19 -0
- package/dist/host/serve/locale-theme.js +169 -0
- package/dist/host/serve/page-catalog.d.ts +14 -0
- package/dist/host/serve/page-catalog.js +105 -0
- package/dist/host/serve/page-render.d.ts +17 -0
- package/dist/host/serve/page-render.js +419 -0
- package/dist/host/serve/paths.d.ts +3 -0
- package/dist/host/serve/paths.js +74 -0
- package/dist/host/serve/route-catalog.d.ts +6 -0
- package/dist/host/serve/route-catalog.js +108 -0
- package/dist/host/serve/state.d.ts +30 -0
- package/dist/host/serve/state.js +36 -0
- package/dist/host/serve-host.d.ts +0 -17
- package/dist/host/serve-host.mjs +4 -1420
- package/dist/ssr/document.d.ts +2 -0
- package/dist/ssr/document.js +71 -0
- package/dist/ssr/dom-ssr.d.ts +10 -47
- package/dist/ssr/dom-ssr.js +10 -1284
- package/dist/ssr/render.d.ts +2 -0
- package/dist/ssr/render.js +78 -0
- package/dist/ssr/serialize.d.ts +3 -0
- package/dist/ssr/serialize.js +678 -0
- package/package.json +11 -11
- /package/dist/host/{route-layout-chain.d.ts → render/route-layout-chain.d.ts} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function __vmzAllowShared(value: any): any;
|
|
2
|
+
export declare function __vmzTakeShared(value: any): any;
|
|
3
|
+
export declare function __vmzSharedCrossComponentDiagnostics(): any[];
|
|
4
|
+
export declare function __vmzSharedCrossComponentDiagnosticsReset(): void;
|
|
5
|
+
export declare function __vmzReadPath(inst: any, root: any, segs: any): any;
|
|
6
|
+
export declare function __vmzWritePathLogical(inst: any, root: any, segs: any, kind: any, rhs: any): any;
|
|
7
|
+
export declare function __vmzWritePath(inst: any, root: any, segs: any, value: any): any;
|
|
8
|
+
export declare function __vmzWritePathItem(inst: any, root: any, idx: any, leaf: any, value: any): any;
|
|
9
|
+
export declare function __vmzListTranspose(inst: any, root: any, ia: any, ib: any): void;
|
|
10
|
+
export declare function __vmzWritePathCompound(inst: any, root: any, segs: any, op: any, rhs: any): any;
|
|
11
|
+
export declare function __vmzWritePathCompoundItem(inst: any, root: any, idx: any, leaf: any, op: any, rhs: any): any;
|
|
12
|
+
export declare function __vmzArrayItemCompoundStride(inst: any, root: any, leaf: any, op: any, rhs: any, start: any, step: any): void;
|
|
13
|
+
export declare function __vmzArrayMutate(inst: any, root: any, baseSegs: any, method: any, args: any): any;
|
|
14
|
+
export declare function makeReactive(inst: any, stateKeys: any): void;
|
|
15
|
+
export declare function __vmzIsWriteBarrierOwned(value: any): boolean;
|
|
16
|
+
export declare function __vmzIsReactiveProxy(value: any): boolean;
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import { promoteLeafDirtyToTrie, scheduleRefresh } from './patch-scheduler.js';
|
|
2
|
+
const wbSharedOwners = new WeakMap();
|
|
3
|
+
const wbAllowShared = new WeakSet();
|
|
4
|
+
const wbCrossComponentDiags = [];
|
|
5
|
+
export function __vmzAllowShared(value) {
|
|
6
|
+
if (value != null && typeof value === 'object')
|
|
7
|
+
wbAllowShared.add(value);
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function __vmzTakeShared(value) {
|
|
11
|
+
if (value != null && typeof value === 'object') {
|
|
12
|
+
wbSharedOwners.delete(value);
|
|
13
|
+
wbAllowShared.delete(value);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function __vmzSharedCrossComponentDiagnostics() {
|
|
18
|
+
return wbCrossComponentDiags.slice();
|
|
19
|
+
}
|
|
20
|
+
export function __vmzSharedCrossComponentDiagnosticsReset() {
|
|
21
|
+
wbCrossComponentDiags.length = 0;
|
|
22
|
+
}
|
|
23
|
+
function registerWbOwner(value, report, baseSegs = [], inst = null) {
|
|
24
|
+
if (value == null || typeof value !== 'object')
|
|
25
|
+
return;
|
|
26
|
+
let entry = wbSharedOwners.get(value);
|
|
27
|
+
if (!entry) {
|
|
28
|
+
entry = { owners: [] };
|
|
29
|
+
wbSharedOwners.set(value, entry);
|
|
30
|
+
}
|
|
31
|
+
if (entry.owners.some((o) => o.report === report && sameSegs(o.baseSegs, baseSegs))) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
entry.owners.push({ report, baseSegs: baseSegs.slice(), inst });
|
|
35
|
+
// Cross-component share without explicit allow ??diagnose (13 ).
|
|
36
|
+
if (!wbAllowShared.has(value) && inst) {
|
|
37
|
+
const other = entry.owners.find((o) => o.inst && o.inst !== inst);
|
|
38
|
+
if (other) {
|
|
39
|
+
const msg = 'vmz: shared plain object written from multiple components without allowShared';
|
|
40
|
+
if (!wbCrossComponentDiags.some((d) => d.message === msg)) {
|
|
41
|
+
wbCrossComponentDiags.push({ kind: 'shared_cross_component', message: msg });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function notifyWbShared(rootObj, localSegs) {
|
|
47
|
+
const entry = rootObj && typeof rootObj === 'object' ? wbSharedOwners.get(rootObj) : null;
|
|
48
|
+
if (!entry || !entry.owners.length)
|
|
49
|
+
return false;
|
|
50
|
+
for (const o of entry.owners) {
|
|
51
|
+
if (localSegs == null) {
|
|
52
|
+
o.report(o.baseSegs.length ? o.baseSegs.slice() : null);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
o.report([...o.baseSegs, ...localSegs]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
export function __vmzReadPath(inst, root, segs) {
|
|
61
|
+
if (!inst || !root)
|
|
62
|
+
return undefined;
|
|
63
|
+
let obj = inst[root];
|
|
64
|
+
if (!Array.isArray(segs) || segs.length === 0)
|
|
65
|
+
return obj;
|
|
66
|
+
for (let i = 0; i < segs.length; i++) {
|
|
67
|
+
if (obj == null || typeof obj !== 'object')
|
|
68
|
+
return undefined;
|
|
69
|
+
obj = obj[segs[i]];
|
|
70
|
+
}
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
export function __vmzWritePathLogical(inst, root, segs, kind, rhs) {
|
|
74
|
+
const cur = __vmzReadPath(inst, root, segs);
|
|
75
|
+
if (kind === '||') {
|
|
76
|
+
if (cur)
|
|
77
|
+
return cur;
|
|
78
|
+
}
|
|
79
|
+
else if (kind === '&&') {
|
|
80
|
+
if (!cur)
|
|
81
|
+
return cur;
|
|
82
|
+
}
|
|
83
|
+
else if (kind === '??') {
|
|
84
|
+
if (cur != null)
|
|
85
|
+
return cur;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return cur;
|
|
89
|
+
}
|
|
90
|
+
return __vmzWritePath(inst, root, segs, rhs);
|
|
91
|
+
}
|
|
92
|
+
function applyCompoundOp(op, cur, rhs) {
|
|
93
|
+
switch (op) {
|
|
94
|
+
case '+':
|
|
95
|
+
return cur + rhs;
|
|
96
|
+
case '-':
|
|
97
|
+
return cur - rhs;
|
|
98
|
+
case '*':
|
|
99
|
+
return cur * rhs;
|
|
100
|
+
case '/':
|
|
101
|
+
return cur / rhs;
|
|
102
|
+
case '%':
|
|
103
|
+
return cur % rhs;
|
|
104
|
+
case '**':
|
|
105
|
+
return cur ** rhs;
|
|
106
|
+
case '<<':
|
|
107
|
+
return cur << rhs;
|
|
108
|
+
case '>>':
|
|
109
|
+
return cur >> rhs;
|
|
110
|
+
case '>>>':
|
|
111
|
+
return cur >>> rhs;
|
|
112
|
+
case '|':
|
|
113
|
+
return cur | rhs;
|
|
114
|
+
case '^':
|
|
115
|
+
return cur ^ rhs;
|
|
116
|
+
case '&':
|
|
117
|
+
return cur & rhs;
|
|
118
|
+
default:
|
|
119
|
+
return cur;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function notifyArrayItemLeaf(inst, root, idx, leaf) {
|
|
123
|
+
if (typeof inst.__vmzDrainLeafDirty === 'function' && ((inst.__vmzEventDepth || 0) > 0 || inst.__vmzFlushSync)) {
|
|
124
|
+
const i = +idx;
|
|
125
|
+
const ld = inst.__vmzLeafDirty;
|
|
126
|
+
if (!ld) {
|
|
127
|
+
inst.__vmzLeafDirty = { root, field: leaf, idxs: [i] };
|
|
128
|
+
}
|
|
129
|
+
else if (ld.root === root && ld.field === leaf) {
|
|
130
|
+
ld.idxs.push(i);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
promoteLeafDirtyToTrie(inst);
|
|
134
|
+
scheduleRefresh(inst, { type: 'path', root, segs: [String(idx), leaf] });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
inst.__vmzFlushScheduled = true;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
scheduleRefresh(inst, { type: 'path', root, segs: [String(idx), leaf] });
|
|
141
|
+
}
|
|
142
|
+
export function __vmzWritePath(inst, root, segs, value) {
|
|
143
|
+
if (!inst || inst.__vmzDestroyed)
|
|
144
|
+
return value;
|
|
145
|
+
if (!root || !Array.isArray(segs) || segs.length === 0)
|
|
146
|
+
return value;
|
|
147
|
+
// Hot path: array item field write (`rows[i].label`) ??no map/slice, no shared-owner walk.
|
|
148
|
+
if (segs.length === 2) {
|
|
149
|
+
return __vmzWritePathItem(inst, root, segs[0], segs[1], value);
|
|
150
|
+
}
|
|
151
|
+
const normSegs = segs.map((s) => String(s));
|
|
152
|
+
let obj = inst[root];
|
|
153
|
+
if (obj == null || typeof obj !== 'object')
|
|
154
|
+
return value;
|
|
155
|
+
for (let i = 0; i < normSegs.length - 1; i++) {
|
|
156
|
+
obj = obj[normSegs[i]];
|
|
157
|
+
if (obj == null || typeof obj !== 'object')
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
const leaf = normSegs[normSegs.length - 1];
|
|
161
|
+
if (Object.is(obj[leaf], value))
|
|
162
|
+
return value;
|
|
163
|
+
obj[leaf] = value;
|
|
164
|
+
// Register newly assigned nested objects under this field for future shared writes.
|
|
165
|
+
if (value != null && typeof value === 'object') {
|
|
166
|
+
const report = (local) => {
|
|
167
|
+
if (!local || local.length === 0) {
|
|
168
|
+
scheduleRefresh(inst, { type: 'replace', root });
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
scheduleRefresh(inst, { type: 'path', root, segs: local });
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
registerWbOwner(value, report, normSegs.slice(), inst);
|
|
175
|
+
}
|
|
176
|
+
const rootObj = inst[root];
|
|
177
|
+
const rootArr = rootObj;
|
|
178
|
+
const isRootIndex = normSegs.length === 1 && Array.isArray(rootArr) && leaf !== 'length' && String(Number(leaf)) === leaf;
|
|
179
|
+
if (isRootIndex) {
|
|
180
|
+
if (!notifyWbShared(rootObj, null)) {
|
|
181
|
+
scheduleRefresh(inst, { type: 'replace', root });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (!notifyWbShared(rootObj, normSegs)) {
|
|
185
|
+
scheduleRefresh(inst, { type: 'path', root, segs: normSegs });
|
|
186
|
+
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
export function __vmzWritePathItem(inst, root, idx, leaf, value) {
|
|
190
|
+
if (!inst || inst.__vmzDestroyed)
|
|
191
|
+
return value;
|
|
192
|
+
if (!root || leaf == null)
|
|
193
|
+
return value;
|
|
194
|
+
const arr = inst[root];
|
|
195
|
+
if (!Array.isArray(arr))
|
|
196
|
+
return value;
|
|
197
|
+
const item = arr[idx];
|
|
198
|
+
if (item == null || typeof item !== 'object')
|
|
199
|
+
return value;
|
|
200
|
+
if (Object.is(item[leaf], value))
|
|
201
|
+
return value;
|
|
202
|
+
item[leaf] = value;
|
|
203
|
+
if (tryInlineLeafApply(inst, root, idx, leaf, item))
|
|
204
|
+
return value;
|
|
205
|
+
notifyArrayItemLeaf(inst, root, idx, leaf);
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
export function __vmzListTranspose(inst, root, ia, ib) {
|
|
209
|
+
if (!inst || inst.__vmzDestroyed || !root)
|
|
210
|
+
return;
|
|
211
|
+
const arr = inst[root];
|
|
212
|
+
if (!Array.isArray(arr))
|
|
213
|
+
return;
|
|
214
|
+
const a = +ia;
|
|
215
|
+
const b = +ib;
|
|
216
|
+
if (a === b || a < 0 || b < 0 || a >= arr.length || b >= arr.length)
|
|
217
|
+
return;
|
|
218
|
+
const tmp = arr[a];
|
|
219
|
+
arr[a] = arr[b];
|
|
220
|
+
arr[b] = tmp;
|
|
221
|
+
const hook = inst.__vmzEachTranspose && inst.__vmzEachTranspose[root];
|
|
222
|
+
if (typeof hook === 'function' && hook(a, b) === true)
|
|
223
|
+
return;
|
|
224
|
+
scheduleRefresh(inst, { type: 'replace', root });
|
|
225
|
+
}
|
|
226
|
+
export function __vmzWritePathCompound(inst, root, segs, op, rhs) {
|
|
227
|
+
if (!inst || inst.__vmzDestroyed)
|
|
228
|
+
return undefined;
|
|
229
|
+
if (!root || !Array.isArray(segs) || segs.length === 0)
|
|
230
|
+
return undefined;
|
|
231
|
+
if (segs.length === 2) {
|
|
232
|
+
return __vmzWritePathCompoundItem(inst, root, segs[0], segs[1], op, rhs);
|
|
233
|
+
}
|
|
234
|
+
const cur = __vmzReadPath(inst, root, segs);
|
|
235
|
+
const value = applyCompoundOp(op, cur, rhs);
|
|
236
|
+
return __vmzWritePath(inst, root, segs, value);
|
|
237
|
+
}
|
|
238
|
+
export function __vmzWritePathCompoundItem(inst, root, idx, leaf, op, rhs) {
|
|
239
|
+
if (!inst || inst.__vmzDestroyed)
|
|
240
|
+
return undefined;
|
|
241
|
+
if (!root || leaf == null)
|
|
242
|
+
return undefined;
|
|
243
|
+
const arr = inst[root];
|
|
244
|
+
if (!Array.isArray(arr))
|
|
245
|
+
return undefined;
|
|
246
|
+
const item = arr[idx];
|
|
247
|
+
if (item == null || typeof item !== 'object')
|
|
248
|
+
return undefined;
|
|
249
|
+
const cur = item[leaf];
|
|
250
|
+
const value = applyCompoundOp(op, cur, rhs);
|
|
251
|
+
if (Object.is(cur, value))
|
|
252
|
+
return value;
|
|
253
|
+
item[leaf] = value;
|
|
254
|
+
if (tryInlineLeafApply(inst, root, idx, leaf, item))
|
|
255
|
+
return value;
|
|
256
|
+
notifyArrayItemLeaf(inst, root, idx, leaf);
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
export function __vmzArrayItemCompoundStride(inst, root, leaf, op, rhs, start, step) {
|
|
260
|
+
if (!inst || inst.__vmzDestroyed || !root || leaf == null)
|
|
261
|
+
return;
|
|
262
|
+
// Prefer eachBlock-owned loop (hoisted applyByField, no per-index hook lookup).
|
|
263
|
+
const owned = inst.__vmzEachCompoundStride && inst.__vmzEachCompoundStride[root];
|
|
264
|
+
if (typeof owned === 'function' && owned(leaf, op, rhs, start, step) === true)
|
|
265
|
+
return;
|
|
266
|
+
const arr = inst[root];
|
|
267
|
+
if (!Array.isArray(arr))
|
|
268
|
+
return;
|
|
269
|
+
const s = +start || 0;
|
|
270
|
+
const st = +step || 0;
|
|
271
|
+
if (st <= 0)
|
|
272
|
+
return;
|
|
273
|
+
const n = arr.length;
|
|
274
|
+
const canInline = typeof inst.__vmzEachApplyLeaf === 'object' &&
|
|
275
|
+
typeof inst.__vmzEachApplyLeaf[root] === 'function' &&
|
|
276
|
+
((inst.__vmzEventDepth || 0) > 0 || inst.__vmzFlushSync);
|
|
277
|
+
const applyLeaf = canInline ? inst.__vmzEachApplyLeaf[root] : null;
|
|
278
|
+
// Hot path: string `+=` with inline DOM ??no switch / Object.is / idxs.
|
|
279
|
+
if (op === '+' && applyLeaf) {
|
|
280
|
+
for (let i = s; i < n; i += st) {
|
|
281
|
+
const item = arr[i];
|
|
282
|
+
if (item == null || typeof item !== 'object')
|
|
283
|
+
continue;
|
|
284
|
+
item[leaf] = item[leaf] + rhs;
|
|
285
|
+
applyLeaf(i, leaf, item);
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const idxs = [];
|
|
290
|
+
for (let i = s; i < n; i += st) {
|
|
291
|
+
const item = arr[i];
|
|
292
|
+
if (item == null || typeof item !== 'object')
|
|
293
|
+
continue;
|
|
294
|
+
const cur = item[leaf];
|
|
295
|
+
const value = applyCompoundOp(op, cur, rhs);
|
|
296
|
+
if (Object.is(cur, value))
|
|
297
|
+
continue;
|
|
298
|
+
item[leaf] = value;
|
|
299
|
+
if (applyLeaf && applyLeaf(i, leaf, item) === true)
|
|
300
|
+
continue;
|
|
301
|
+
idxs.push(i);
|
|
302
|
+
}
|
|
303
|
+
if (!idxs.length)
|
|
304
|
+
return;
|
|
305
|
+
if (typeof inst.__vmzDrainLeafDirty === 'function' && ((inst.__vmzEventDepth || 0) > 0 || inst.__vmzFlushSync)) {
|
|
306
|
+
inst.__vmzLeafDirty = { root, field: leaf, idxs };
|
|
307
|
+
inst.__vmzFlushScheduled = true;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
for (let k = 0; k < idxs.length; k++) {
|
|
311
|
+
notifyArrayItemLeaf(inst, root, idxs[k], leaf);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function tryInlineLeafApply(inst, root, idx, leaf, item) {
|
|
315
|
+
const hook = inst.__vmzEachApplyLeaf && inst.__vmzEachApplyLeaf[root];
|
|
316
|
+
if (typeof hook !== 'function')
|
|
317
|
+
return false;
|
|
318
|
+
return hook(+idx, leaf, item) === true;
|
|
319
|
+
}
|
|
320
|
+
export function __vmzArrayMutate(inst, root, baseSegs, method, args) {
|
|
321
|
+
if (!inst || inst.__vmzDestroyed)
|
|
322
|
+
return undefined;
|
|
323
|
+
if (!root || typeof method !== 'string')
|
|
324
|
+
return undefined;
|
|
325
|
+
const segs = Array.isArray(baseSegs) ? baseSegs.map((s) => String(s)) : [];
|
|
326
|
+
let arr = inst[root];
|
|
327
|
+
if (arr == null || typeof arr !== 'object')
|
|
328
|
+
return undefined;
|
|
329
|
+
for (let i = 0; i < segs.length; i++) {
|
|
330
|
+
arr = arr[segs[i]];
|
|
331
|
+
if (arr == null || typeof arr !== 'object')
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
if (!Array.isArray(arr) || typeof arr[method] !== 'function')
|
|
335
|
+
return undefined;
|
|
336
|
+
const list = Array.isArray(args) ? args : [];
|
|
337
|
+
const ret = arr[method](...list);
|
|
338
|
+
const rootObj = inst[root];
|
|
339
|
+
if (segs.length === 0) {
|
|
340
|
+
if (!notifyWbShared(rootObj, null)) {
|
|
341
|
+
scheduleRefresh(inst, { type: 'replace', root });
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else if (!notifyWbShared(rootObj, segs)) {
|
|
345
|
+
scheduleRefresh(inst, { type: 'path', root, segs: segs.slice() });
|
|
346
|
+
}
|
|
347
|
+
return ret;
|
|
348
|
+
}
|
|
349
|
+
export function makeReactive(inst, stateKeys) {
|
|
350
|
+
const barrier = !!inst.constructor.__vmzWriteBarrier;
|
|
351
|
+
for (const key of stateKeys) {
|
|
352
|
+
if (!key || key.startsWith('#'))
|
|
353
|
+
continue;
|
|
354
|
+
const desc = Object.getOwnPropertyDescriptor(inst, key);
|
|
355
|
+
if (desc && desc.set && desc.get && !desc.writable)
|
|
356
|
+
continue;
|
|
357
|
+
const report = (segs) => {
|
|
358
|
+
if (!segs || segs.length === 0) {
|
|
359
|
+
scheduleRefresh(inst, { type: 'replace', root: key });
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
scheduleRefresh(inst, { type: 'path', root: key, segs });
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
// WriteBarrier components keep plain objects ??nested writes go through __vmzWritePath.
|
|
366
|
+
let value = barrier ? inst[key] : wrapReactive(inst[key], report, []);
|
|
367
|
+
if (barrier)
|
|
368
|
+
registerWbOwner(value, report, [], inst);
|
|
369
|
+
Object.defineProperty(inst, key, {
|
|
370
|
+
configurable: true,
|
|
371
|
+
enumerable: true,
|
|
372
|
+
get() {
|
|
373
|
+
return value;
|
|
374
|
+
},
|
|
375
|
+
set(next) {
|
|
376
|
+
const wrapped = barrier ? next : wrapReactive(next, report, []);
|
|
377
|
+
if (Object.is(value, wrapped))
|
|
378
|
+
return;
|
|
379
|
+
value = wrapped;
|
|
380
|
+
if (barrier)
|
|
381
|
+
registerWbOwner(value, report, [], inst);
|
|
382
|
+
report(null);
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const reactiveProxies = new WeakMap();
|
|
388
|
+
const writeBarrierOwned = new WeakSet();
|
|
389
|
+
export function __vmzIsWriteBarrierOwned(value) {
|
|
390
|
+
return writeBarrierOwned.has(value);
|
|
391
|
+
}
|
|
392
|
+
export function __vmzIsReactiveProxy(value) {
|
|
393
|
+
const e = reactiveProxies.get(value);
|
|
394
|
+
return !!(e && e.kind === 'proxy' && e.proxy === value);
|
|
395
|
+
}
|
|
396
|
+
const ARRAY_MUTATORS = new Set(['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse', 'fill', 'copyWithin']);
|
|
397
|
+
function sameSegs(a, b) {
|
|
398
|
+
if (a.length !== b.length)
|
|
399
|
+
return false;
|
|
400
|
+
for (let i = 0; i < a.length; i++) {
|
|
401
|
+
if (a[i] !== b[i])
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
function addOwner(entry, report, baseSegs) {
|
|
407
|
+
if (entry.owners.some((o) => o.report === report && sameSegs(o.baseSegs, baseSegs))) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
entry.owners.push({
|
|
411
|
+
report,
|
|
412
|
+
baseSegs: baseSegs.slice(),
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function notifyOwners(owners, localSegs) {
|
|
416
|
+
for (const o of owners) {
|
|
417
|
+
if (localSegs == null) {
|
|
418
|
+
o.report(o.baseSegs.length ? o.baseSegs.slice() : null);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
o.report([...o.baseSegs, ...localSegs]);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function wrapReactive(value, report, pathSegs = []) {
|
|
426
|
+
if (value == null || typeof value !== 'object')
|
|
427
|
+
return value;
|
|
428
|
+
const existing = reactiveProxies.get(value);
|
|
429
|
+
if (existing) {
|
|
430
|
+
addOwner(existing, report, pathSegs);
|
|
431
|
+
return existing.proxy;
|
|
432
|
+
}
|
|
433
|
+
if (Array.isArray(value))
|
|
434
|
+
return wrapArray(value, report, pathSegs);
|
|
435
|
+
if (isPlainObject(value))
|
|
436
|
+
return wrapOwnedObject(value, report, pathSegs);
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
function isPlainObject(value) {
|
|
440
|
+
const proto = Object.getPrototypeOf(value);
|
|
441
|
+
return proto === Object.prototype || proto === null;
|
|
442
|
+
}
|
|
443
|
+
function wrapOwnedObject(obj, report, pathSegs) {
|
|
444
|
+
const existing = reactiveProxies.get(obj);
|
|
445
|
+
if (existing) {
|
|
446
|
+
addOwner(existing, report, pathSegs);
|
|
447
|
+
return existing.proxy;
|
|
448
|
+
}
|
|
449
|
+
const entry = {
|
|
450
|
+
proxy: obj,
|
|
451
|
+
owners: [],
|
|
452
|
+
kind: 'barrier',
|
|
453
|
+
};
|
|
454
|
+
addOwner(entry, report, pathSegs);
|
|
455
|
+
writeBarrierOwned.add(obj);
|
|
456
|
+
reactiveProxies.set(obj, entry);
|
|
457
|
+
for (const prop of Object.keys(obj)) {
|
|
458
|
+
installOwnedProp(obj, prop, entry);
|
|
459
|
+
}
|
|
460
|
+
return obj;
|
|
461
|
+
}
|
|
462
|
+
function installOwnedProp(obj, prop, entry) {
|
|
463
|
+
const desc = Object.getOwnPropertyDescriptor(obj, prop);
|
|
464
|
+
if (!desc || !desc.configurable)
|
|
465
|
+
return;
|
|
466
|
+
if (desc.get || desc.set)
|
|
467
|
+
return;
|
|
468
|
+
let current = obj[prop];
|
|
469
|
+
for (const o of entry.owners) {
|
|
470
|
+
current = wrapReactive(current, o.report, [...o.baseSegs, prop]);
|
|
471
|
+
}
|
|
472
|
+
Object.defineProperty(obj, prop, {
|
|
473
|
+
configurable: true,
|
|
474
|
+
enumerable: desc.enumerable !== false,
|
|
475
|
+
get() {
|
|
476
|
+
return current;
|
|
477
|
+
},
|
|
478
|
+
set(next) {
|
|
479
|
+
const local = [prop];
|
|
480
|
+
let wrapped = next;
|
|
481
|
+
for (const o of entry.owners) {
|
|
482
|
+
wrapped = wrapReactive(next, o.report, [...o.baseSegs, ...local]);
|
|
483
|
+
}
|
|
484
|
+
if (Object.is(current, wrapped))
|
|
485
|
+
return;
|
|
486
|
+
current = wrapped;
|
|
487
|
+
notifyOwners(entry.owners, local);
|
|
488
|
+
},
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
function wrapArray(arr, report, pathSegs) {
|
|
492
|
+
const existing = reactiveProxies.get(arr);
|
|
493
|
+
if (existing) {
|
|
494
|
+
addOwner(existing, report, pathSegs);
|
|
495
|
+
return existing.proxy;
|
|
496
|
+
}
|
|
497
|
+
const entry = {
|
|
498
|
+
proxy: null,
|
|
499
|
+
owners: [],
|
|
500
|
+
kind: 'proxy',
|
|
501
|
+
};
|
|
502
|
+
addOwner(entry, report, pathSegs);
|
|
503
|
+
const isArrayIndex = (prop) => typeof prop === 'string' && prop !== 'length' && String(Number(prop)) === prop;
|
|
504
|
+
const proxy = new Proxy(arr, {
|
|
505
|
+
get(target, prop, receiver) {
|
|
506
|
+
if (typeof prop === 'string' && ARRAY_MUTATORS.has(prop)) {
|
|
507
|
+
const fn = target[prop];
|
|
508
|
+
return (...args) => {
|
|
509
|
+
const ret = fn.apply(target, args);
|
|
510
|
+
notifyOwners(entry.owners, null);
|
|
511
|
+
return ret;
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
// Indices / length / methods: return as-is (plain elements).
|
|
515
|
+
return Reflect.get(target, prop, receiver);
|
|
516
|
+
},
|
|
517
|
+
set(target, prop, next, receiver) {
|
|
518
|
+
const prev = target[prop];
|
|
519
|
+
if (Object.is(prev, next))
|
|
520
|
+
return true;
|
|
521
|
+
const ok = Reflect.set(target, prop, next, receiver);
|
|
522
|
+
if (ok) {
|
|
523
|
+
if (prop === 'length' || isArrayIndex(prop))
|
|
524
|
+
notifyOwners(entry.owners, null);
|
|
525
|
+
else if (typeof prop === 'string')
|
|
526
|
+
notifyOwners(entry.owners, [prop]);
|
|
527
|
+
else
|
|
528
|
+
notifyOwners(entry.owners, null);
|
|
529
|
+
}
|
|
530
|
+
return ok;
|
|
531
|
+
},
|
|
532
|
+
deleteProperty(target, prop) {
|
|
533
|
+
if (!(prop in target))
|
|
534
|
+
return true;
|
|
535
|
+
const ok = Reflect.deleteProperty(target, prop);
|
|
536
|
+
if (ok) {
|
|
537
|
+
notifyOwners(entry.owners, typeof prop === 'string' ? [prop] : null);
|
|
538
|
+
}
|
|
539
|
+
return ok;
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
entry.proxy = proxy;
|
|
543
|
+
reactiveProxies.set(arr, entry);
|
|
544
|
+
reactiveProxies.set(proxy, entry);
|
|
545
|
+
return proxy;
|
|
546
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runDirectResume(Component: any, inst: any, container: any): any;
|