wevu 6.7.2 → 6.7.4
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/api.d.mts +1 -0
- package/dist/api.mjs +2 -0
- package/dist/compiler.mjs +2 -3
- package/dist/defineProperty-JH0tR899.mjs +39 -0
- package/dist/fetch.d.mts +26 -0
- package/dist/fetch.mjs +345 -0
- package/dist/index-Ciz2Ye1L.d.mts +246 -0
- package/dist/index.d.mts +238 -410
- package/dist/index.mjs +1609 -2560
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/ref-BeA_Is-2.mjs +804 -0
- package/dist/router-5qgy8oOS.mjs +329 -0
- package/dist/router-BxV0btOX.d.mts +46 -0
- package/dist/router.d.mts +192 -0
- package/dist/router.mjs +1412 -0
- package/dist/store-DFP_p2kt.mjs +504 -0
- package/dist/store.d.mts +2 -0
- package/dist/store.mjs +2 -0
- package/package.json +31 -2
- /package/dist/{weappIntrinsicElements-CihhL3Md.d.mts → weappIntrinsicElements-BKiRK0cC.d.mts} +0 -0
|
@@ -0,0 +1,804 @@
|
|
|
1
|
+
import { t as _defineProperty } from "./defineProperty-JH0tR899.mjs";
|
|
2
|
+
//#region src/scheduler.ts
|
|
3
|
+
const resolvedPromise = Promise.resolve();
|
|
4
|
+
const jobQueue = /* @__PURE__ */ new Set();
|
|
5
|
+
let isFlushing = false;
|
|
6
|
+
let isFlushPending = false;
|
|
7
|
+
function flushJobs() {
|
|
8
|
+
isFlushPending = false;
|
|
9
|
+
isFlushing = true;
|
|
10
|
+
try {
|
|
11
|
+
jobQueue.forEach((job) => job());
|
|
12
|
+
} finally {
|
|
13
|
+
jobQueue.clear();
|
|
14
|
+
isFlushing = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function queueJob(job) {
|
|
18
|
+
jobQueue.add(job);
|
|
19
|
+
if (!isFlushing && !isFlushPending) {
|
|
20
|
+
isFlushPending = true;
|
|
21
|
+
resolvedPromise.then(flushJobs);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function nextTick(fn) {
|
|
25
|
+
return fn ? resolvedPromise.then(fn) : resolvedPromise;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/reactivity/core.ts
|
|
29
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
let activeEffect = null;
|
|
31
|
+
const effectStack = [];
|
|
32
|
+
let batchDepth = 0;
|
|
33
|
+
const batchedEffects = /* @__PURE__ */ new Set();
|
|
34
|
+
function startBatch() {
|
|
35
|
+
batchDepth++;
|
|
36
|
+
}
|
|
37
|
+
function flushBatchedEffects() {
|
|
38
|
+
while (batchedEffects.size) {
|
|
39
|
+
const effects = Array.from(batchedEffects);
|
|
40
|
+
batchedEffects.clear();
|
|
41
|
+
for (const ef of effects) ef();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function endBatch() {
|
|
45
|
+
if (batchDepth === 0) return;
|
|
46
|
+
batchDepth--;
|
|
47
|
+
if (batchDepth === 0) flushBatchedEffects();
|
|
48
|
+
}
|
|
49
|
+
function batch(fn) {
|
|
50
|
+
startBatch();
|
|
51
|
+
try {
|
|
52
|
+
return fn();
|
|
53
|
+
} finally {
|
|
54
|
+
endBatch();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function cleanupEffect(effect) {
|
|
58
|
+
const { deps } = effect;
|
|
59
|
+
for (let i = 0; i < deps.length; i++) deps[i].delete(effect);
|
|
60
|
+
deps.length = 0;
|
|
61
|
+
}
|
|
62
|
+
function stop(runner) {
|
|
63
|
+
var _runner$onStop;
|
|
64
|
+
if (!runner.active) return;
|
|
65
|
+
runner.active = false;
|
|
66
|
+
cleanupEffect(runner);
|
|
67
|
+
(_runner$onStop = runner.onStop) === null || _runner$onStop === void 0 || _runner$onStop.call(runner);
|
|
68
|
+
}
|
|
69
|
+
let activeEffectScope;
|
|
70
|
+
var EffectScopeImpl = class {
|
|
71
|
+
constructor(detached = false) {
|
|
72
|
+
this.detached = detached;
|
|
73
|
+
_defineProperty(this, "active", true);
|
|
74
|
+
_defineProperty(this, "effects", []);
|
|
75
|
+
_defineProperty(this, "cleanups", []);
|
|
76
|
+
_defineProperty(this, "parent", void 0);
|
|
77
|
+
_defineProperty(this, "scopes", void 0);
|
|
78
|
+
if (!detached && activeEffectScope) {
|
|
79
|
+
var _activeEffectScope;
|
|
80
|
+
this.parent = activeEffectScope;
|
|
81
|
+
((_activeEffectScope = activeEffectScope).scopes || (_activeEffectScope.scopes = [])).push(this);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
run(fn) {
|
|
85
|
+
if (!this.active) return;
|
|
86
|
+
const prev = activeEffectScope;
|
|
87
|
+
activeEffectScope = this;
|
|
88
|
+
try {
|
|
89
|
+
return fn();
|
|
90
|
+
} finally {
|
|
91
|
+
activeEffectScope = prev;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
stop() {
|
|
95
|
+
var _this$parent;
|
|
96
|
+
if (!this.active) return;
|
|
97
|
+
this.active = false;
|
|
98
|
+
for (const effect of this.effects) stop(effect);
|
|
99
|
+
this.effects.length = 0;
|
|
100
|
+
for (const cleanup of this.cleanups) cleanup();
|
|
101
|
+
this.cleanups.length = 0;
|
|
102
|
+
if (this.scopes) {
|
|
103
|
+
for (const scope of this.scopes) scope.stop();
|
|
104
|
+
this.scopes.length = 0;
|
|
105
|
+
}
|
|
106
|
+
if ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.scopes) {
|
|
107
|
+
const index = this.parent.scopes.indexOf(this);
|
|
108
|
+
if (index >= 0) this.parent.scopes.splice(index, 1);
|
|
109
|
+
}
|
|
110
|
+
this.parent = void 0;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function effectScope(detached = false) {
|
|
114
|
+
return new EffectScopeImpl(detached);
|
|
115
|
+
}
|
|
116
|
+
function getCurrentScope() {
|
|
117
|
+
return activeEffectScope;
|
|
118
|
+
}
|
|
119
|
+
function onScopeDispose(fn) {
|
|
120
|
+
if (activeEffectScope === null || activeEffectScope === void 0 ? void 0 : activeEffectScope.active) activeEffectScope.cleanups.push(fn);
|
|
121
|
+
}
|
|
122
|
+
function recordEffectScope(effect) {
|
|
123
|
+
if (activeEffectScope === null || activeEffectScope === void 0 ? void 0 : activeEffectScope.active) activeEffectScope.effects.push(effect);
|
|
124
|
+
}
|
|
125
|
+
function createReactiveEffect(fn, options = {}) {
|
|
126
|
+
const effect = function reactiveEffect() {
|
|
127
|
+
if (!effect.active) return fn();
|
|
128
|
+
if (effect._running) return fn();
|
|
129
|
+
cleanupEffect(effect);
|
|
130
|
+
try {
|
|
131
|
+
effect._running = true;
|
|
132
|
+
effectStack.push(effect);
|
|
133
|
+
activeEffect = effect;
|
|
134
|
+
return fn();
|
|
135
|
+
} finally {
|
|
136
|
+
var _effectStack;
|
|
137
|
+
effectStack.pop();
|
|
138
|
+
activeEffect = (_effectStack = effectStack[effectStack.length - 1]) !== null && _effectStack !== void 0 ? _effectStack : null;
|
|
139
|
+
effect._running = false;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
effect.deps = [];
|
|
143
|
+
effect.scheduler = options.scheduler;
|
|
144
|
+
effect.onStop = options.onStop;
|
|
145
|
+
effect.active = true;
|
|
146
|
+
effect._running = false;
|
|
147
|
+
effect._fn = fn;
|
|
148
|
+
return effect;
|
|
149
|
+
}
|
|
150
|
+
function effect(fn, options = {}) {
|
|
151
|
+
const _effect = createReactiveEffect(fn, options);
|
|
152
|
+
recordEffectScope(_effect);
|
|
153
|
+
if (!options.lazy) _effect();
|
|
154
|
+
return _effect;
|
|
155
|
+
}
|
|
156
|
+
function track(target, key) {
|
|
157
|
+
if (!activeEffect) return;
|
|
158
|
+
let depsMap = targetMap.get(target);
|
|
159
|
+
if (!depsMap) {
|
|
160
|
+
depsMap = /* @__PURE__ */ new Map();
|
|
161
|
+
targetMap.set(target, depsMap);
|
|
162
|
+
}
|
|
163
|
+
let dep = depsMap.get(key);
|
|
164
|
+
if (!dep) {
|
|
165
|
+
dep = /* @__PURE__ */ new Set();
|
|
166
|
+
depsMap.set(key, dep);
|
|
167
|
+
}
|
|
168
|
+
if (!dep.has(activeEffect)) {
|
|
169
|
+
dep.add(activeEffect);
|
|
170
|
+
activeEffect.deps.push(dep);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function scheduleEffect(ef) {
|
|
174
|
+
if (ef.scheduler) {
|
|
175
|
+
ef.scheduler();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (batchDepth > 0) {
|
|
179
|
+
batchedEffects.add(ef);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
ef();
|
|
183
|
+
}
|
|
184
|
+
function trigger(target, key) {
|
|
185
|
+
const depsMap = targetMap.get(target);
|
|
186
|
+
if (!depsMap) return;
|
|
187
|
+
const effects = depsMap.get(key);
|
|
188
|
+
if (!effects) return;
|
|
189
|
+
const effectsToRun = /* @__PURE__ */ new Set();
|
|
190
|
+
effects.forEach((ef) => {
|
|
191
|
+
if (ef !== activeEffect) effectsToRun.add(ef);
|
|
192
|
+
});
|
|
193
|
+
effectsToRun.forEach(scheduleEffect);
|
|
194
|
+
}
|
|
195
|
+
function trackEffects(dep) {
|
|
196
|
+
if (!activeEffect) return;
|
|
197
|
+
if (!dep.has(activeEffect)) {
|
|
198
|
+
dep.add(activeEffect);
|
|
199
|
+
activeEffect.deps.push(dep);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function triggerEffects(dep) {
|
|
203
|
+
new Set(dep).forEach(scheduleEffect);
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/reactivity/reactive/mutation.ts
|
|
207
|
+
const mutationRecorders = /* @__PURE__ */ new Set();
|
|
208
|
+
function addMutationRecorder(recorder) {
|
|
209
|
+
mutationRecorders.add(recorder);
|
|
210
|
+
}
|
|
211
|
+
function removeMutationRecorder(recorder) {
|
|
212
|
+
mutationRecorders.delete(recorder);
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/reactivity/reactive/patchState.ts
|
|
216
|
+
const rawRootMap = /* @__PURE__ */ new WeakMap();
|
|
217
|
+
const rawVersionMap = /* @__PURE__ */ new WeakMap();
|
|
218
|
+
const rawParentMap = /* @__PURE__ */ new WeakMap();
|
|
219
|
+
const rawParentsMap = /* @__PURE__ */ new WeakMap();
|
|
220
|
+
const rawMultiParentSet = /* @__PURE__ */ new WeakSet();
|
|
221
|
+
const rawPathMap = /* @__PURE__ */ new WeakMap();
|
|
222
|
+
const rootPatchNodesMap = /* @__PURE__ */ new WeakMap();
|
|
223
|
+
function getRootPatchNodes(root) {
|
|
224
|
+
let nodes = rootPatchNodesMap.get(root);
|
|
225
|
+
if (!nodes) {
|
|
226
|
+
nodes = /* @__PURE__ */ new Set();
|
|
227
|
+
rootPatchNodesMap.set(root, nodes);
|
|
228
|
+
}
|
|
229
|
+
return nodes;
|
|
230
|
+
}
|
|
231
|
+
function indexPatchNode(root, node) {
|
|
232
|
+
getRootPatchNodes(root).add(node);
|
|
233
|
+
}
|
|
234
|
+
function bumpRawVersion(target) {
|
|
235
|
+
var _rawVersionMap$get;
|
|
236
|
+
rawVersionMap.set(target, ((_rawVersionMap$get = rawVersionMap.get(target)) !== null && _rawVersionMap$get !== void 0 ? _rawVersionMap$get : 0) + 1);
|
|
237
|
+
}
|
|
238
|
+
function getRawVersion(target) {
|
|
239
|
+
var _rawVersionMap$get2;
|
|
240
|
+
return (_rawVersionMap$get2 = rawVersionMap.get(target)) !== null && _rawVersionMap$get2 !== void 0 ? _rawVersionMap$get2 : 0;
|
|
241
|
+
}
|
|
242
|
+
function bumpAncestorVersions(target) {
|
|
243
|
+
const visited = /* @__PURE__ */ new Set();
|
|
244
|
+
const stack = [target];
|
|
245
|
+
for (let i = 0; i < 2e3 && stack.length; i++) {
|
|
246
|
+
const current = stack.pop();
|
|
247
|
+
const parents = rawParentsMap.get(current);
|
|
248
|
+
if (!parents) continue;
|
|
249
|
+
for (const parent of parents.keys()) {
|
|
250
|
+
if (visited.has(parent)) continue;
|
|
251
|
+
visited.add(parent);
|
|
252
|
+
bumpRawVersion(parent);
|
|
253
|
+
stack.push(parent);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function refreshPathUniqueness(child) {
|
|
258
|
+
const parents = rawParentsMap.get(child);
|
|
259
|
+
if (!parents) {
|
|
260
|
+
rawMultiParentSet.delete(child);
|
|
261
|
+
rawParentMap.delete(child);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
let uniqueParent;
|
|
265
|
+
let uniqueKey;
|
|
266
|
+
let total = 0;
|
|
267
|
+
for (const [parent, keys] of parents) {
|
|
268
|
+
for (const k of keys) {
|
|
269
|
+
total += 1;
|
|
270
|
+
if (total > 1) break;
|
|
271
|
+
uniqueParent = parent;
|
|
272
|
+
uniqueKey = k;
|
|
273
|
+
}
|
|
274
|
+
if (total > 1) break;
|
|
275
|
+
}
|
|
276
|
+
if (total === 1 && uniqueParent && uniqueKey) {
|
|
277
|
+
rawMultiParentSet.delete(child);
|
|
278
|
+
rawParentMap.set(child, {
|
|
279
|
+
parent: uniqueParent,
|
|
280
|
+
key: uniqueKey
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
rawMultiParentSet.add(child);
|
|
285
|
+
rawParentMap.delete(child);
|
|
286
|
+
}
|
|
287
|
+
function recordParentLink(child, parent, key) {
|
|
288
|
+
if (typeof key !== "string") {
|
|
289
|
+
rawMultiParentSet.add(child);
|
|
290
|
+
rawParentMap.delete(child);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (mutationRecorders.size) {
|
|
294
|
+
var _rawRootMap$get;
|
|
295
|
+
const root = (_rawRootMap$get = rawRootMap.get(parent)) !== null && _rawRootMap$get !== void 0 ? _rawRootMap$get : parent;
|
|
296
|
+
indexPatchNode(root, parent);
|
|
297
|
+
indexPatchNode(root, child);
|
|
298
|
+
}
|
|
299
|
+
let parents = rawParentsMap.get(child);
|
|
300
|
+
if (!parents) {
|
|
301
|
+
parents = /* @__PURE__ */ new Map();
|
|
302
|
+
rawParentsMap.set(child, parents);
|
|
303
|
+
}
|
|
304
|
+
let keys = parents.get(parent);
|
|
305
|
+
if (!keys) {
|
|
306
|
+
keys = /* @__PURE__ */ new Set();
|
|
307
|
+
parents.set(parent, keys);
|
|
308
|
+
}
|
|
309
|
+
keys.add(key);
|
|
310
|
+
refreshPathUniqueness(child);
|
|
311
|
+
}
|
|
312
|
+
function removeParentLink(child, parent, key) {
|
|
313
|
+
const parents = rawParentsMap.get(child);
|
|
314
|
+
if (!parents) return;
|
|
315
|
+
const keys = parents.get(parent);
|
|
316
|
+
if (!keys) return;
|
|
317
|
+
keys.delete(key);
|
|
318
|
+
if (!keys.size) parents.delete(parent);
|
|
319
|
+
if (!parents.size) rawParentsMap.delete(child);
|
|
320
|
+
refreshPathUniqueness(child);
|
|
321
|
+
}
|
|
322
|
+
function resolvePathToTarget(root, target) {
|
|
323
|
+
if (target === root) return [];
|
|
324
|
+
if (rawMultiParentSet.has(target)) return;
|
|
325
|
+
const segments = [];
|
|
326
|
+
let current = target;
|
|
327
|
+
for (let i = 0; i < 2e3; i++) {
|
|
328
|
+
if (current === root) return segments.reverse();
|
|
329
|
+
if (rawMultiParentSet.has(current)) return;
|
|
330
|
+
const info = rawParentMap.get(current);
|
|
331
|
+
if (!info) return;
|
|
332
|
+
if (typeof info.key !== "string") return;
|
|
333
|
+
segments.push(info.key);
|
|
334
|
+
current = info.parent;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/reactivity/reactive/shared.ts
|
|
339
|
+
let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags) {
|
|
340
|
+
ReactiveFlags["IS_REACTIVE"] = "__r_isReactive";
|
|
341
|
+
ReactiveFlags["RAW"] = "__r_raw";
|
|
342
|
+
ReactiveFlags["SKIP"] = "__r_skip";
|
|
343
|
+
return ReactiveFlags;
|
|
344
|
+
}({});
|
|
345
|
+
function isObject(value) {
|
|
346
|
+
return typeof value === "object" && value !== null;
|
|
347
|
+
}
|
|
348
|
+
const VERSION_KEY = Symbol("wevu.version");
|
|
349
|
+
function isArrayIndexKey(key) {
|
|
350
|
+
if (!key) return false;
|
|
351
|
+
const code0 = key.charCodeAt(0);
|
|
352
|
+
if (code0 < 48 || code0 > 57) return false;
|
|
353
|
+
const n = Number(key);
|
|
354
|
+
return Number.isInteger(n) && n >= 0 && String(n) === key;
|
|
355
|
+
}
|
|
356
|
+
function toRaw(observed) {
|
|
357
|
+
var _ReactiveFlags$RAW;
|
|
358
|
+
return (_ReactiveFlags$RAW = observed === null || observed === void 0 ? void 0 : observed[ReactiveFlags.RAW]) !== null && _ReactiveFlags$RAW !== void 0 ? _ReactiveFlags$RAW : observed;
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/reactivity/reactive/state.ts
|
|
362
|
+
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
363
|
+
const rawMap = /* @__PURE__ */ new WeakMap();
|
|
364
|
+
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/reactivity/reactive/patch.ts
|
|
367
|
+
/**
|
|
368
|
+
* 预链接响应式树结构,供运行时差量路径追踪使用。
|
|
369
|
+
* @internal
|
|
370
|
+
*/
|
|
371
|
+
function prelinkReactiveTree(root, options) {
|
|
372
|
+
const rootRaw = toRaw(root);
|
|
373
|
+
rawPathMap.set(rootRaw, "");
|
|
374
|
+
indexPatchNode(rootRaw, rootRaw);
|
|
375
|
+
const shouldIncludeTopKey = options === null || options === void 0 ? void 0 : options.shouldIncludeTopKey;
|
|
376
|
+
const maxDepth = typeof (options === null || options === void 0 ? void 0 : options.maxDepth) === "number" ? Math.max(0, Math.floor(options.maxDepth)) : Number.POSITIVE_INFINITY;
|
|
377
|
+
const maxKeys = typeof (options === null || options === void 0 ? void 0 : options.maxKeys) === "number" ? Math.max(0, Math.floor(options.maxKeys)) : Number.POSITIVE_INFINITY;
|
|
378
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
379
|
+
const stack = [{
|
|
380
|
+
current: rootRaw,
|
|
381
|
+
path: "",
|
|
382
|
+
depth: 0
|
|
383
|
+
}];
|
|
384
|
+
let indexed = 0;
|
|
385
|
+
while (stack.length) {
|
|
386
|
+
const node = stack.pop();
|
|
387
|
+
if (visited.has(node.current)) continue;
|
|
388
|
+
visited.add(node.current);
|
|
389
|
+
rawPathMap.set(node.current, node.path);
|
|
390
|
+
indexPatchNode(rootRaw, node.current);
|
|
391
|
+
indexed += 1;
|
|
392
|
+
if (indexed >= maxKeys) continue;
|
|
393
|
+
if (node.depth >= maxDepth) continue;
|
|
394
|
+
if (Array.isArray(node.current)) continue;
|
|
395
|
+
const entries = Object.entries(node.current);
|
|
396
|
+
for (const [key, value] of entries) {
|
|
397
|
+
if (node.path === "" && shouldIncludeTopKey && !shouldIncludeTopKey(key)) continue;
|
|
398
|
+
if (!isObject(value)) continue;
|
|
399
|
+
if (value[ReactiveFlags.SKIP]) continue;
|
|
400
|
+
const childRaw = toRaw(value);
|
|
401
|
+
if (!rawRootMap.has(childRaw)) rawRootMap.set(childRaw, rootRaw);
|
|
402
|
+
recordParentLink(childRaw, node.current, key);
|
|
403
|
+
if (!rawMultiParentSet.has(childRaw)) {
|
|
404
|
+
const childPath = node.path ? `${node.path}.${key}` : key;
|
|
405
|
+
rawPathMap.set(childRaw, childPath);
|
|
406
|
+
}
|
|
407
|
+
indexPatchNode(rootRaw, childRaw);
|
|
408
|
+
stack.push({
|
|
409
|
+
current: childRaw,
|
|
410
|
+
path: node.path ? `${node.path}.${key}` : key,
|
|
411
|
+
depth: node.depth + 1
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* 清理预链接阶段建立的路径与父子索引。
|
|
418
|
+
* @internal
|
|
419
|
+
*/
|
|
420
|
+
function clearPatchIndices(root) {
|
|
421
|
+
const rootRaw = toRaw(root);
|
|
422
|
+
const nodes = rootPatchNodesMap.get(rootRaw);
|
|
423
|
+
if (!nodes) {
|
|
424
|
+
rawPathMap.delete(rootRaw);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
for (const node of nodes) {
|
|
428
|
+
rawParentMap.delete(node);
|
|
429
|
+
rawParentsMap.delete(node);
|
|
430
|
+
rawPathMap.delete(node);
|
|
431
|
+
rawMultiParentSet.delete(node);
|
|
432
|
+
rawRootMap.delete(node);
|
|
433
|
+
rawVersionMap.delete(node);
|
|
434
|
+
}
|
|
435
|
+
rootPatchNodesMap.delete(rootRaw);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
|
|
439
|
+
* @internal
|
|
440
|
+
*/
|
|
441
|
+
function touchReactive(target) {
|
|
442
|
+
track(toRaw(target), VERSION_KEY);
|
|
443
|
+
}
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/reactivity/reactive/shallow.ts
|
|
446
|
+
const shallowHandlers = {
|
|
447
|
+
get(target, key, receiver) {
|
|
448
|
+
if (key === ReactiveFlags.IS_REACTIVE) return true;
|
|
449
|
+
if (key === ReactiveFlags.RAW) return target;
|
|
450
|
+
const res = Reflect.get(target, key, receiver);
|
|
451
|
+
track(target, key);
|
|
452
|
+
return res;
|
|
453
|
+
},
|
|
454
|
+
set(target, key, value, receiver) {
|
|
455
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
456
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
457
|
+
if (!Object.is(oldValue, value)) {
|
|
458
|
+
trigger(target, key);
|
|
459
|
+
trigger(target, VERSION_KEY);
|
|
460
|
+
bumpRawVersion(target);
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
},
|
|
464
|
+
deleteProperty(target, key) {
|
|
465
|
+
const hadKey = Object.prototype.hasOwnProperty.call(target, key);
|
|
466
|
+
const result = Reflect.deleteProperty(target, key);
|
|
467
|
+
if (hadKey && result) {
|
|
468
|
+
trigger(target, key);
|
|
469
|
+
trigger(target, VERSION_KEY);
|
|
470
|
+
bumpRawVersion(target);
|
|
471
|
+
}
|
|
472
|
+
return result;
|
|
473
|
+
},
|
|
474
|
+
ownKeys(target) {
|
|
475
|
+
track(target, Symbol.iterator);
|
|
476
|
+
track(target, VERSION_KEY);
|
|
477
|
+
return Reflect.ownKeys(target);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
|
|
482
|
+
*
|
|
483
|
+
* @param target 待转换的对象
|
|
484
|
+
* @returns 浅层响应式代理
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* const state = shallowReactive({ nested: { count: 0 } })
|
|
489
|
+
*
|
|
490
|
+
* state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
|
|
491
|
+
* state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
function shallowReactive(target) {
|
|
495
|
+
if (!isObject(target)) return target;
|
|
496
|
+
const existingProxy = shallowReactiveMap.get(target);
|
|
497
|
+
if (existingProxy) return existingProxy;
|
|
498
|
+
if (target[ReactiveFlags.IS_REACTIVE]) return target;
|
|
499
|
+
const proxy = new Proxy(target, shallowHandlers);
|
|
500
|
+
shallowReactiveMap.set(target, proxy);
|
|
501
|
+
rawMap.set(proxy, target);
|
|
502
|
+
if (!rawVersionMap.has(target)) rawVersionMap.set(target, 0);
|
|
503
|
+
return proxy;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* 判断一个值是否为 shallowReactive 创建的浅层响应式对象
|
|
507
|
+
*/
|
|
508
|
+
function isShallowReactive(value) {
|
|
509
|
+
const raw = toRaw(value);
|
|
510
|
+
return shallowReactiveMap.has(raw);
|
|
511
|
+
}
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/reactivity/reactive.ts
|
|
514
|
+
/**
|
|
515
|
+
* 读取响应式版本号(框架内部调试能力)。
|
|
516
|
+
* @internal
|
|
517
|
+
*/
|
|
518
|
+
function getReactiveVersion(target) {
|
|
519
|
+
return getRawVersion(toRaw(target));
|
|
520
|
+
}
|
|
521
|
+
function emitMutation(target, key, op) {
|
|
522
|
+
var _rawRootMap$get;
|
|
523
|
+
if (!mutationRecorders.size) return;
|
|
524
|
+
if (typeof key !== "string") return;
|
|
525
|
+
if (key.startsWith("__r_")) return;
|
|
526
|
+
const root = (_rawRootMap$get = rawRootMap.get(target)) !== null && _rawRootMap$get !== void 0 ? _rawRootMap$get : target;
|
|
527
|
+
const kind = Array.isArray(target) && (key === "length" || isArrayIndexKey(key)) ? "array" : "property";
|
|
528
|
+
const baseSegments = resolvePathToTarget(root, target);
|
|
529
|
+
if (!baseSegments) {
|
|
530
|
+
const fallback = /* @__PURE__ */ new Set();
|
|
531
|
+
const parents = rawParentsMap.get(target);
|
|
532
|
+
if (parents) for (const [parent, keys] of parents) {
|
|
533
|
+
var _resolvePathToTarget;
|
|
534
|
+
const parentPath = rawPathMap.get(parent);
|
|
535
|
+
const topFromParentPath = parentPath ? parentPath.split(".", 1)[0] : void 0;
|
|
536
|
+
const topFromResolve = !topFromParentPath ? (_resolvePathToTarget = resolvePathToTarget(root, parent)) === null || _resolvePathToTarget === void 0 ? void 0 : _resolvePathToTarget[0] : void 0;
|
|
537
|
+
for (const k of keys) {
|
|
538
|
+
var _ref;
|
|
539
|
+
if (typeof k !== "string") continue;
|
|
540
|
+
fallback.add((_ref = topFromParentPath !== null && topFromParentPath !== void 0 ? topFromParentPath : topFromResolve) !== null && _ref !== void 0 ? _ref : k);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
else fallback.add(key);
|
|
544
|
+
for (const recorder of mutationRecorders) recorder({
|
|
545
|
+
root,
|
|
546
|
+
kind,
|
|
547
|
+
op,
|
|
548
|
+
path: void 0,
|
|
549
|
+
fallbackTopKeys: fallback.size ? Array.from(fallback) : void 0
|
|
550
|
+
});
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const arrayIndexPos = baseSegments.findIndex((seg) => isArrayIndexKey(seg));
|
|
554
|
+
if (arrayIndexPos !== -1) {
|
|
555
|
+
const path = baseSegments.slice(0, arrayIndexPos).join(".") || void 0;
|
|
556
|
+
for (const recorder of mutationRecorders) recorder({
|
|
557
|
+
root,
|
|
558
|
+
kind: "array",
|
|
559
|
+
op,
|
|
560
|
+
path
|
|
561
|
+
});
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const basePath = baseSegments.length ? baseSegments.join(".") : "";
|
|
565
|
+
const path = kind === "array" ? basePath || void 0 : basePath ? `${basePath}.${key}` : key;
|
|
566
|
+
for (const recorder of mutationRecorders) recorder({
|
|
567
|
+
root,
|
|
568
|
+
kind,
|
|
569
|
+
op,
|
|
570
|
+
path
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
const mutableHandlers = {
|
|
574
|
+
get(target, key, receiver) {
|
|
575
|
+
if (key === ReactiveFlags.IS_REACTIVE) return true;
|
|
576
|
+
if (key === ReactiveFlags.RAW) return target;
|
|
577
|
+
const res = Reflect.get(target, key, receiver);
|
|
578
|
+
track(target, key);
|
|
579
|
+
if (isObject(res)) {
|
|
580
|
+
var _rawRootMap$get2, _ReactiveFlags$RAW;
|
|
581
|
+
if (res[ReactiveFlags.SKIP]) return res;
|
|
582
|
+
const parentRoot = (_rawRootMap$get2 = rawRootMap.get(target)) !== null && _rawRootMap$get2 !== void 0 ? _rawRootMap$get2 : target;
|
|
583
|
+
const childRaw = (_ReactiveFlags$RAW = res === null || res === void 0 ? void 0 : res[ReactiveFlags.RAW]) !== null && _ReactiveFlags$RAW !== void 0 ? _ReactiveFlags$RAW : res;
|
|
584
|
+
if (!rawRootMap.has(childRaw)) rawRootMap.set(childRaw, parentRoot);
|
|
585
|
+
recordParentLink(childRaw, target, key);
|
|
586
|
+
const parentPath = rawPathMap.get(target);
|
|
587
|
+
if (mutationRecorders.size && typeof key === "string" && parentPath != null && !rawMultiParentSet.has(childRaw)) {
|
|
588
|
+
const nextPath = parentPath ? `${parentPath}.${key}` : key;
|
|
589
|
+
rawPathMap.set(childRaw, nextPath);
|
|
590
|
+
}
|
|
591
|
+
return reactive(res);
|
|
592
|
+
}
|
|
593
|
+
return res;
|
|
594
|
+
},
|
|
595
|
+
set(target, key, value, receiver) {
|
|
596
|
+
const isArr = Array.isArray(target);
|
|
597
|
+
const oldLength = isArr ? target.length : 0;
|
|
598
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
599
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
600
|
+
if (!Object.is(oldValue, value)) {
|
|
601
|
+
var _ReactiveFlags$RAW2;
|
|
602
|
+
const oldRaw = isObject(oldValue) ? (_ReactiveFlags$RAW2 = oldValue === null || oldValue === void 0 ? void 0 : oldValue[ReactiveFlags.RAW]) !== null && _ReactiveFlags$RAW2 !== void 0 ? _ReactiveFlags$RAW2 : oldValue : void 0;
|
|
603
|
+
if (oldRaw) removeParentLink(oldRaw, target, key);
|
|
604
|
+
if (isObject(value) && !value[ReactiveFlags.SKIP]) {
|
|
605
|
+
var _rawRootMap$get3, _ReactiveFlags$RAW3;
|
|
606
|
+
const root = (_rawRootMap$get3 = rawRootMap.get(target)) !== null && _rawRootMap$get3 !== void 0 ? _rawRootMap$get3 : target;
|
|
607
|
+
const childRaw = (_ReactiveFlags$RAW3 = value === null || value === void 0 ? void 0 : value[ReactiveFlags.RAW]) !== null && _ReactiveFlags$RAW3 !== void 0 ? _ReactiveFlags$RAW3 : value;
|
|
608
|
+
if (!rawRootMap.has(childRaw)) rawRootMap.set(childRaw, root);
|
|
609
|
+
recordParentLink(childRaw, target, key);
|
|
610
|
+
const parentPath = rawPathMap.get(target);
|
|
611
|
+
if (mutationRecorders.size && typeof key === "string" && parentPath != null && !rawMultiParentSet.has(childRaw)) {
|
|
612
|
+
const nextPath = parentPath ? `${parentPath}.${key}` : key;
|
|
613
|
+
rawPathMap.set(childRaw, nextPath);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
trigger(target, key);
|
|
617
|
+
if (isArr && typeof key === "string" && isArrayIndexKey(key) && Number(key) >= oldLength) trigger(target, "length");
|
|
618
|
+
trigger(target, VERSION_KEY);
|
|
619
|
+
bumpRawVersion(target);
|
|
620
|
+
bumpAncestorVersions(target);
|
|
621
|
+
const root = rawRootMap.get(target);
|
|
622
|
+
if (root && root !== target) {
|
|
623
|
+
trigger(root, VERSION_KEY);
|
|
624
|
+
bumpRawVersion(root);
|
|
625
|
+
}
|
|
626
|
+
emitMutation(target, key, "set");
|
|
627
|
+
}
|
|
628
|
+
return result;
|
|
629
|
+
},
|
|
630
|
+
deleteProperty(target, key) {
|
|
631
|
+
const hadKey = Object.prototype.hasOwnProperty.call(target, key);
|
|
632
|
+
const oldValue = hadKey ? target[key] : void 0;
|
|
633
|
+
const result = Reflect.deleteProperty(target, key);
|
|
634
|
+
if (hadKey && result) {
|
|
635
|
+
var _ReactiveFlags$RAW4;
|
|
636
|
+
const oldRaw = isObject(oldValue) ? (_ReactiveFlags$RAW4 = oldValue === null || oldValue === void 0 ? void 0 : oldValue[ReactiveFlags.RAW]) !== null && _ReactiveFlags$RAW4 !== void 0 ? _ReactiveFlags$RAW4 : oldValue : void 0;
|
|
637
|
+
if (oldRaw) removeParentLink(oldRaw, target, key);
|
|
638
|
+
trigger(target, key);
|
|
639
|
+
trigger(target, VERSION_KEY);
|
|
640
|
+
bumpRawVersion(target);
|
|
641
|
+
bumpAncestorVersions(target);
|
|
642
|
+
const root = rawRootMap.get(target);
|
|
643
|
+
if (root && root !== target) {
|
|
644
|
+
trigger(root, VERSION_KEY);
|
|
645
|
+
bumpRawVersion(root);
|
|
646
|
+
}
|
|
647
|
+
emitMutation(target, key, "delete");
|
|
648
|
+
}
|
|
649
|
+
return result;
|
|
650
|
+
},
|
|
651
|
+
ownKeys(target) {
|
|
652
|
+
track(target, Symbol.iterator);
|
|
653
|
+
track(target, VERSION_KEY);
|
|
654
|
+
return Reflect.ownKeys(target);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
function reactive(target) {
|
|
658
|
+
if (!isObject(target)) return target;
|
|
659
|
+
const existingProxy = reactiveMap.get(target);
|
|
660
|
+
if (existingProxy) return existingProxy;
|
|
661
|
+
if (target[ReactiveFlags.IS_REACTIVE]) return target;
|
|
662
|
+
const proxy = new Proxy(target, mutableHandlers);
|
|
663
|
+
reactiveMap.set(target, proxy);
|
|
664
|
+
rawMap.set(proxy, target);
|
|
665
|
+
if (!rawVersionMap.has(target)) rawVersionMap.set(target, 0);
|
|
666
|
+
if (!rawRootMap.has(target)) rawRootMap.set(target, target);
|
|
667
|
+
return proxy;
|
|
668
|
+
}
|
|
669
|
+
function isReactive(value) {
|
|
670
|
+
return Boolean(value && value[ReactiveFlags.IS_REACTIVE]);
|
|
671
|
+
}
|
|
672
|
+
function convertToReactive(value) {
|
|
673
|
+
return isObject(value) ? reactive(value) : value;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
|
|
677
|
+
*
|
|
678
|
+
* @param value 需要标记的对象
|
|
679
|
+
* @returns 带有跳过标记的原对象
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* ```ts
|
|
683
|
+
* const foo = markRaw({
|
|
684
|
+
* nested: {}
|
|
685
|
+
* })
|
|
686
|
+
*
|
|
687
|
+
* const state = reactive({
|
|
688
|
+
* foo
|
|
689
|
+
* })
|
|
690
|
+
*
|
|
691
|
+
* state.foo // 不是响应式对象
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
function markRaw(value) {
|
|
695
|
+
if (!isObject(value)) return value;
|
|
696
|
+
Object.defineProperty(value, ReactiveFlags.SKIP, {
|
|
697
|
+
value: true,
|
|
698
|
+
configurable: true,
|
|
699
|
+
enumerable: false,
|
|
700
|
+
writable: true
|
|
701
|
+
});
|
|
702
|
+
return value;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* 判断某个值是否被标记为原始(即不应转换为响应式)。
|
|
706
|
+
*
|
|
707
|
+
* @param value 待检测的值
|
|
708
|
+
* @returns 若含有跳过标记则返回 true
|
|
709
|
+
*/
|
|
710
|
+
function isRaw(value) {
|
|
711
|
+
return isObject(value) && ReactiveFlags.SKIP in value;
|
|
712
|
+
}
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/reactivity/ref.ts
|
|
715
|
+
const RefFlag = "__v_isRef";
|
|
716
|
+
function markAsRef(target) {
|
|
717
|
+
try {
|
|
718
|
+
Object.defineProperty(target, RefFlag, {
|
|
719
|
+
value: true,
|
|
720
|
+
configurable: true
|
|
721
|
+
});
|
|
722
|
+
} catch (_unused) {
|
|
723
|
+
target[RefFlag] = true;
|
|
724
|
+
}
|
|
725
|
+
return target;
|
|
726
|
+
}
|
|
727
|
+
function isRef(value) {
|
|
728
|
+
return Boolean(value && typeof value === "object" && value["__v_isRef"] === true);
|
|
729
|
+
}
|
|
730
|
+
var RefImpl = class {
|
|
731
|
+
constructor(value) {
|
|
732
|
+
_defineProperty(this, "_value", void 0);
|
|
733
|
+
_defineProperty(this, "_rawValue", void 0);
|
|
734
|
+
_defineProperty(this, "dep", void 0);
|
|
735
|
+
markAsRef(this);
|
|
736
|
+
this._rawValue = value;
|
|
737
|
+
this._value = convertToReactive(value);
|
|
738
|
+
}
|
|
739
|
+
get value() {
|
|
740
|
+
if (!this.dep) this.dep = /* @__PURE__ */ new Set();
|
|
741
|
+
trackEffects(this.dep);
|
|
742
|
+
return this._value;
|
|
743
|
+
}
|
|
744
|
+
set value(newValue) {
|
|
745
|
+
if (!Object.is(newValue, this._rawValue)) {
|
|
746
|
+
this._rawValue = newValue;
|
|
747
|
+
this._value = convertToReactive(newValue);
|
|
748
|
+
if (this.dep) triggerEffects(this.dep);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
function ref(value) {
|
|
753
|
+
if (isRef(value)) return value;
|
|
754
|
+
return markRaw(new RefImpl(value));
|
|
755
|
+
}
|
|
756
|
+
function unref(value) {
|
|
757
|
+
return isRef(value) ? value.value : value;
|
|
758
|
+
}
|
|
759
|
+
function toValue(source) {
|
|
760
|
+
return typeof source === "function" ? source() : unref(source);
|
|
761
|
+
}
|
|
762
|
+
var CustomRefImpl = class {
|
|
763
|
+
constructor(factory, defaultValue) {
|
|
764
|
+
_defineProperty(this, "_getValue", void 0);
|
|
765
|
+
_defineProperty(this, "_setValue", void 0);
|
|
766
|
+
_defineProperty(this, "dep", void 0);
|
|
767
|
+
markAsRef(this);
|
|
768
|
+
const fallbackValue = defaultValue;
|
|
769
|
+
const track = () => {
|
|
770
|
+
if (!this.dep) this.dep = /* @__PURE__ */ new Set();
|
|
771
|
+
trackEffects(this.dep);
|
|
772
|
+
};
|
|
773
|
+
const trigger = () => {
|
|
774
|
+
if (this.dep) triggerEffects(this.dep);
|
|
775
|
+
};
|
|
776
|
+
const withFallback = (value) => value === void 0 && fallbackValue !== void 0 ? fallbackValue : value;
|
|
777
|
+
if (typeof factory === "function") {
|
|
778
|
+
const handlers = factory(track, trigger);
|
|
779
|
+
this._getValue = () => withFallback(handlers.get());
|
|
780
|
+
this._setValue = (value) => handlers.set(value);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const handlers = factory;
|
|
784
|
+
this._getValue = () => {
|
|
785
|
+
track();
|
|
786
|
+
return withFallback(handlers.get());
|
|
787
|
+
};
|
|
788
|
+
this._setValue = (value) => {
|
|
789
|
+
handlers.set(value);
|
|
790
|
+
trigger();
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
get value() {
|
|
794
|
+
return this._getValue();
|
|
795
|
+
}
|
|
796
|
+
set value(newValue) {
|
|
797
|
+
this._setValue(newValue);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
function customRef(factory, defaultValue) {
|
|
801
|
+
return markRaw(new CustomRefImpl(factory, defaultValue));
|
|
802
|
+
}
|
|
803
|
+
//#endregion
|
|
804
|
+
export { track as A, effect as C, onScopeDispose as D, getCurrentScope as E, triggerEffects as M, nextTick as N, startBatch as O, queueJob as P, batch as S, endBatch as T, ReactiveFlags as _, toValue as a, addMutationRecorder as b, isRaw as c, reactive as d, isShallowReactive as f, touchReactive as g, prelinkReactiveTree as h, ref as i, trigger as j, stop as k, isReactive as l, clearPatchIndices as m, isRef as n, unref as o, shallowReactive as p, markAsRef as r, getReactiveVersion as s, customRef as t, markRaw as u, isObject as v, effectScope as w, removeMutationRecorder as x, toRaw as y };
|