1 | /**
|
---|
2 | * @vue/reactivity v3.5.13
|
---|
3 | * (c) 2018-present Yuxi (Evan) You and Vue contributors
|
---|
4 | * @license MIT
|
---|
5 | **/
|
---|
6 | 'use strict';
|
---|
7 |
|
---|
8 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
9 |
|
---|
10 | var shared = require('@vue/shared');
|
---|
11 |
|
---|
12 | function warn(msg, ...args) {
|
---|
13 | console.warn(`[Vue warn] ${msg}`, ...args);
|
---|
14 | }
|
---|
15 |
|
---|
16 | let activeEffectScope;
|
---|
17 | class EffectScope {
|
---|
18 | constructor(detached = false) {
|
---|
19 | this.detached = detached;
|
---|
20 | /**
|
---|
21 | * @internal
|
---|
22 | */
|
---|
23 | this._active = true;
|
---|
24 | /**
|
---|
25 | * @internal
|
---|
26 | */
|
---|
27 | this.effects = [];
|
---|
28 | /**
|
---|
29 | * @internal
|
---|
30 | */
|
---|
31 | this.cleanups = [];
|
---|
32 | this._isPaused = false;
|
---|
33 | this.parent = activeEffectScope;
|
---|
34 | if (!detached && activeEffectScope) {
|
---|
35 | this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
---|
36 | this
|
---|
37 | ) - 1;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | get active() {
|
---|
41 | return this._active;
|
---|
42 | }
|
---|
43 | pause() {
|
---|
44 | if (this._active) {
|
---|
45 | this._isPaused = true;
|
---|
46 | let i, l;
|
---|
47 | if (this.scopes) {
|
---|
48 | for (i = 0, l = this.scopes.length; i < l; i++) {
|
---|
49 | this.scopes[i].pause();
|
---|
50 | }
|
---|
51 | }
|
---|
52 | for (i = 0, l = this.effects.length; i < l; i++) {
|
---|
53 | this.effects[i].pause();
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 | /**
|
---|
58 | * Resumes the effect scope, including all child scopes and effects.
|
---|
59 | */
|
---|
60 | resume() {
|
---|
61 | if (this._active) {
|
---|
62 | if (this._isPaused) {
|
---|
63 | this._isPaused = false;
|
---|
64 | let i, l;
|
---|
65 | if (this.scopes) {
|
---|
66 | for (i = 0, l = this.scopes.length; i < l; i++) {
|
---|
67 | this.scopes[i].resume();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | for (i = 0, l = this.effects.length; i < l; i++) {
|
---|
71 | this.effects[i].resume();
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | run(fn) {
|
---|
77 | if (this._active) {
|
---|
78 | const currentEffectScope = activeEffectScope;
|
---|
79 | try {
|
---|
80 | activeEffectScope = this;
|
---|
81 | return fn();
|
---|
82 | } finally {
|
---|
83 | activeEffectScope = currentEffectScope;
|
---|
84 | }
|
---|
85 | } else {
|
---|
86 | warn(`cannot run an inactive effect scope.`);
|
---|
87 | }
|
---|
88 | }
|
---|
89 | /**
|
---|
90 | * This should only be called on non-detached scopes
|
---|
91 | * @internal
|
---|
92 | */
|
---|
93 | on() {
|
---|
94 | activeEffectScope = this;
|
---|
95 | }
|
---|
96 | /**
|
---|
97 | * This should only be called on non-detached scopes
|
---|
98 | * @internal
|
---|
99 | */
|
---|
100 | off() {
|
---|
101 | activeEffectScope = this.parent;
|
---|
102 | }
|
---|
103 | stop(fromParent) {
|
---|
104 | if (this._active) {
|
---|
105 | this._active = false;
|
---|
106 | let i, l;
|
---|
107 | for (i = 0, l = this.effects.length; i < l; i++) {
|
---|
108 | this.effects[i].stop();
|
---|
109 | }
|
---|
110 | this.effects.length = 0;
|
---|
111 | for (i = 0, l = this.cleanups.length; i < l; i++) {
|
---|
112 | this.cleanups[i]();
|
---|
113 | }
|
---|
114 | this.cleanups.length = 0;
|
---|
115 | if (this.scopes) {
|
---|
116 | for (i = 0, l = this.scopes.length; i < l; i++) {
|
---|
117 | this.scopes[i].stop(true);
|
---|
118 | }
|
---|
119 | this.scopes.length = 0;
|
---|
120 | }
|
---|
121 | if (!this.detached && this.parent && !fromParent) {
|
---|
122 | const last = this.parent.scopes.pop();
|
---|
123 | if (last && last !== this) {
|
---|
124 | this.parent.scopes[this.index] = last;
|
---|
125 | last.index = this.index;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | this.parent = void 0;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 | function effectScope(detached) {
|
---|
133 | return new EffectScope(detached);
|
---|
134 | }
|
---|
135 | function getCurrentScope() {
|
---|
136 | return activeEffectScope;
|
---|
137 | }
|
---|
138 | function onScopeDispose(fn, failSilently = false) {
|
---|
139 | if (activeEffectScope) {
|
---|
140 | activeEffectScope.cleanups.push(fn);
|
---|
141 | } else if (!failSilently) {
|
---|
142 | warn(
|
---|
143 | `onScopeDispose() is called when there is no active effect scope to be associated with.`
|
---|
144 | );
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | let activeSub;
|
---|
149 | const EffectFlags = {
|
---|
150 | "ACTIVE": 1,
|
---|
151 | "1": "ACTIVE",
|
---|
152 | "RUNNING": 2,
|
---|
153 | "2": "RUNNING",
|
---|
154 | "TRACKING": 4,
|
---|
155 | "4": "TRACKING",
|
---|
156 | "NOTIFIED": 8,
|
---|
157 | "8": "NOTIFIED",
|
---|
158 | "DIRTY": 16,
|
---|
159 | "16": "DIRTY",
|
---|
160 | "ALLOW_RECURSE": 32,
|
---|
161 | "32": "ALLOW_RECURSE",
|
---|
162 | "PAUSED": 64,
|
---|
163 | "64": "PAUSED"
|
---|
164 | };
|
---|
165 | const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
|
---|
166 | class ReactiveEffect {
|
---|
167 | constructor(fn) {
|
---|
168 | this.fn = fn;
|
---|
169 | /**
|
---|
170 | * @internal
|
---|
171 | */
|
---|
172 | this.deps = void 0;
|
---|
173 | /**
|
---|
174 | * @internal
|
---|
175 | */
|
---|
176 | this.depsTail = void 0;
|
---|
177 | /**
|
---|
178 | * @internal
|
---|
179 | */
|
---|
180 | this.flags = 1 | 4;
|
---|
181 | /**
|
---|
182 | * @internal
|
---|
183 | */
|
---|
184 | this.next = void 0;
|
---|
185 | /**
|
---|
186 | * @internal
|
---|
187 | */
|
---|
188 | this.cleanup = void 0;
|
---|
189 | this.scheduler = void 0;
|
---|
190 | if (activeEffectScope && activeEffectScope.active) {
|
---|
191 | activeEffectScope.effects.push(this);
|
---|
192 | }
|
---|
193 | }
|
---|
194 | pause() {
|
---|
195 | this.flags |= 64;
|
---|
196 | }
|
---|
197 | resume() {
|
---|
198 | if (this.flags & 64) {
|
---|
199 | this.flags &= ~64;
|
---|
200 | if (pausedQueueEffects.has(this)) {
|
---|
201 | pausedQueueEffects.delete(this);
|
---|
202 | this.trigger();
|
---|
203 | }
|
---|
204 | }
|
---|
205 | }
|
---|
206 | /**
|
---|
207 | * @internal
|
---|
208 | */
|
---|
209 | notify() {
|
---|
210 | if (this.flags & 2 && !(this.flags & 32)) {
|
---|
211 | return;
|
---|
212 | }
|
---|
213 | if (!(this.flags & 8)) {
|
---|
214 | batch(this);
|
---|
215 | }
|
---|
216 | }
|
---|
217 | run() {
|
---|
218 | if (!(this.flags & 1)) {
|
---|
219 | return this.fn();
|
---|
220 | }
|
---|
221 | this.flags |= 2;
|
---|
222 | cleanupEffect(this);
|
---|
223 | prepareDeps(this);
|
---|
224 | const prevEffect = activeSub;
|
---|
225 | const prevShouldTrack = shouldTrack;
|
---|
226 | activeSub = this;
|
---|
227 | shouldTrack = true;
|
---|
228 | try {
|
---|
229 | return this.fn();
|
---|
230 | } finally {
|
---|
231 | if (activeSub !== this) {
|
---|
232 | warn(
|
---|
233 | "Active effect was not restored correctly - this is likely a Vue internal bug."
|
---|
234 | );
|
---|
235 | }
|
---|
236 | cleanupDeps(this);
|
---|
237 | activeSub = prevEffect;
|
---|
238 | shouldTrack = prevShouldTrack;
|
---|
239 | this.flags &= ~2;
|
---|
240 | }
|
---|
241 | }
|
---|
242 | stop() {
|
---|
243 | if (this.flags & 1) {
|
---|
244 | for (let link = this.deps; link; link = link.nextDep) {
|
---|
245 | removeSub(link);
|
---|
246 | }
|
---|
247 | this.deps = this.depsTail = void 0;
|
---|
248 | cleanupEffect(this);
|
---|
249 | this.onStop && this.onStop();
|
---|
250 | this.flags &= ~1;
|
---|
251 | }
|
---|
252 | }
|
---|
253 | trigger() {
|
---|
254 | if (this.flags & 64) {
|
---|
255 | pausedQueueEffects.add(this);
|
---|
256 | } else if (this.scheduler) {
|
---|
257 | this.scheduler();
|
---|
258 | } else {
|
---|
259 | this.runIfDirty();
|
---|
260 | }
|
---|
261 | }
|
---|
262 | /**
|
---|
263 | * @internal
|
---|
264 | */
|
---|
265 | runIfDirty() {
|
---|
266 | if (isDirty(this)) {
|
---|
267 | this.run();
|
---|
268 | }
|
---|
269 | }
|
---|
270 | get dirty() {
|
---|
271 | return isDirty(this);
|
---|
272 | }
|
---|
273 | }
|
---|
274 | let batchDepth = 0;
|
---|
275 | let batchedSub;
|
---|
276 | let batchedComputed;
|
---|
277 | function batch(sub, isComputed = false) {
|
---|
278 | sub.flags |= 8;
|
---|
279 | if (isComputed) {
|
---|
280 | sub.next = batchedComputed;
|
---|
281 | batchedComputed = sub;
|
---|
282 | return;
|
---|
283 | }
|
---|
284 | sub.next = batchedSub;
|
---|
285 | batchedSub = sub;
|
---|
286 | }
|
---|
287 | function startBatch() {
|
---|
288 | batchDepth++;
|
---|
289 | }
|
---|
290 | function endBatch() {
|
---|
291 | if (--batchDepth > 0) {
|
---|
292 | return;
|
---|
293 | }
|
---|
294 | if (batchedComputed) {
|
---|
295 | let e = batchedComputed;
|
---|
296 | batchedComputed = void 0;
|
---|
297 | while (e) {
|
---|
298 | const next = e.next;
|
---|
299 | e.next = void 0;
|
---|
300 | e.flags &= ~8;
|
---|
301 | e = next;
|
---|
302 | }
|
---|
303 | }
|
---|
304 | let error;
|
---|
305 | while (batchedSub) {
|
---|
306 | let e = batchedSub;
|
---|
307 | batchedSub = void 0;
|
---|
308 | while (e) {
|
---|
309 | const next = e.next;
|
---|
310 | e.next = void 0;
|
---|
311 | e.flags &= ~8;
|
---|
312 | if (e.flags & 1) {
|
---|
313 | try {
|
---|
314 | ;
|
---|
315 | e.trigger();
|
---|
316 | } catch (err) {
|
---|
317 | if (!error) error = err;
|
---|
318 | }
|
---|
319 | }
|
---|
320 | e = next;
|
---|
321 | }
|
---|
322 | }
|
---|
323 | if (error) throw error;
|
---|
324 | }
|
---|
325 | function prepareDeps(sub) {
|
---|
326 | for (let link = sub.deps; link; link = link.nextDep) {
|
---|
327 | link.version = -1;
|
---|
328 | link.prevActiveLink = link.dep.activeLink;
|
---|
329 | link.dep.activeLink = link;
|
---|
330 | }
|
---|
331 | }
|
---|
332 | function cleanupDeps(sub) {
|
---|
333 | let head;
|
---|
334 | let tail = sub.depsTail;
|
---|
335 | let link = tail;
|
---|
336 | while (link) {
|
---|
337 | const prev = link.prevDep;
|
---|
338 | if (link.version === -1) {
|
---|
339 | if (link === tail) tail = prev;
|
---|
340 | removeSub(link);
|
---|
341 | removeDep(link);
|
---|
342 | } else {
|
---|
343 | head = link;
|
---|
344 | }
|
---|
345 | link.dep.activeLink = link.prevActiveLink;
|
---|
346 | link.prevActiveLink = void 0;
|
---|
347 | link = prev;
|
---|
348 | }
|
---|
349 | sub.deps = head;
|
---|
350 | sub.depsTail = tail;
|
---|
351 | }
|
---|
352 | function isDirty(sub) {
|
---|
353 | for (let link = sub.deps; link; link = link.nextDep) {
|
---|
354 | if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
|
---|
355 | return true;
|
---|
356 | }
|
---|
357 | }
|
---|
358 | if (sub._dirty) {
|
---|
359 | return true;
|
---|
360 | }
|
---|
361 | return false;
|
---|
362 | }
|
---|
363 | function refreshComputed(computed) {
|
---|
364 | if (computed.flags & 4 && !(computed.flags & 16)) {
|
---|
365 | return;
|
---|
366 | }
|
---|
367 | computed.flags &= ~16;
|
---|
368 | if (computed.globalVersion === globalVersion) {
|
---|
369 | return;
|
---|
370 | }
|
---|
371 | computed.globalVersion = globalVersion;
|
---|
372 | const dep = computed.dep;
|
---|
373 | computed.flags |= 2;
|
---|
374 | if (dep.version > 0 && !computed.isSSR && computed.deps && !isDirty(computed)) {
|
---|
375 | computed.flags &= ~2;
|
---|
376 | return;
|
---|
377 | }
|
---|
378 | const prevSub = activeSub;
|
---|
379 | const prevShouldTrack = shouldTrack;
|
---|
380 | activeSub = computed;
|
---|
381 | shouldTrack = true;
|
---|
382 | try {
|
---|
383 | prepareDeps(computed);
|
---|
384 | const value = computed.fn(computed._value);
|
---|
385 | if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
|
---|
386 | computed._value = value;
|
---|
387 | dep.version++;
|
---|
388 | }
|
---|
389 | } catch (err) {
|
---|
390 | dep.version++;
|
---|
391 | throw err;
|
---|
392 | } finally {
|
---|
393 | activeSub = prevSub;
|
---|
394 | shouldTrack = prevShouldTrack;
|
---|
395 | cleanupDeps(computed);
|
---|
396 | computed.flags &= ~2;
|
---|
397 | }
|
---|
398 | }
|
---|
399 | function removeSub(link, soft = false) {
|
---|
400 | const { dep, prevSub, nextSub } = link;
|
---|
401 | if (prevSub) {
|
---|
402 | prevSub.nextSub = nextSub;
|
---|
403 | link.prevSub = void 0;
|
---|
404 | }
|
---|
405 | if (nextSub) {
|
---|
406 | nextSub.prevSub = prevSub;
|
---|
407 | link.nextSub = void 0;
|
---|
408 | }
|
---|
409 | if (dep.subsHead === link) {
|
---|
410 | dep.subsHead = nextSub;
|
---|
411 | }
|
---|
412 | if (dep.subs === link) {
|
---|
413 | dep.subs = prevSub;
|
---|
414 | if (!prevSub && dep.computed) {
|
---|
415 | dep.computed.flags &= ~4;
|
---|
416 | for (let l = dep.computed.deps; l; l = l.nextDep) {
|
---|
417 | removeSub(l, true);
|
---|
418 | }
|
---|
419 | }
|
---|
420 | }
|
---|
421 | if (!soft && !--dep.sc && dep.map) {
|
---|
422 | dep.map.delete(dep.key);
|
---|
423 | }
|
---|
424 | }
|
---|
425 | function removeDep(link) {
|
---|
426 | const { prevDep, nextDep } = link;
|
---|
427 | if (prevDep) {
|
---|
428 | prevDep.nextDep = nextDep;
|
---|
429 | link.prevDep = void 0;
|
---|
430 | }
|
---|
431 | if (nextDep) {
|
---|
432 | nextDep.prevDep = prevDep;
|
---|
433 | link.nextDep = void 0;
|
---|
434 | }
|
---|
435 | }
|
---|
436 | function effect(fn, options) {
|
---|
437 | if (fn.effect instanceof ReactiveEffect) {
|
---|
438 | fn = fn.effect.fn;
|
---|
439 | }
|
---|
440 | const e = new ReactiveEffect(fn);
|
---|
441 | if (options) {
|
---|
442 | shared.extend(e, options);
|
---|
443 | }
|
---|
444 | try {
|
---|
445 | e.run();
|
---|
446 | } catch (err) {
|
---|
447 | e.stop();
|
---|
448 | throw err;
|
---|
449 | }
|
---|
450 | const runner = e.run.bind(e);
|
---|
451 | runner.effect = e;
|
---|
452 | return runner;
|
---|
453 | }
|
---|
454 | function stop(runner) {
|
---|
455 | runner.effect.stop();
|
---|
456 | }
|
---|
457 | let shouldTrack = true;
|
---|
458 | const trackStack = [];
|
---|
459 | function pauseTracking() {
|
---|
460 | trackStack.push(shouldTrack);
|
---|
461 | shouldTrack = false;
|
---|
462 | }
|
---|
463 | function enableTracking() {
|
---|
464 | trackStack.push(shouldTrack);
|
---|
465 | shouldTrack = true;
|
---|
466 | }
|
---|
467 | function resetTracking() {
|
---|
468 | const last = trackStack.pop();
|
---|
469 | shouldTrack = last === void 0 ? true : last;
|
---|
470 | }
|
---|
471 | function onEffectCleanup(fn, failSilently = false) {
|
---|
472 | if (activeSub instanceof ReactiveEffect) {
|
---|
473 | activeSub.cleanup = fn;
|
---|
474 | } else if (!failSilently) {
|
---|
475 | warn(
|
---|
476 | `onEffectCleanup() was called when there was no active effect to associate with.`
|
---|
477 | );
|
---|
478 | }
|
---|
479 | }
|
---|
480 | function cleanupEffect(e) {
|
---|
481 | const { cleanup } = e;
|
---|
482 | e.cleanup = void 0;
|
---|
483 | if (cleanup) {
|
---|
484 | const prevSub = activeSub;
|
---|
485 | activeSub = void 0;
|
---|
486 | try {
|
---|
487 | cleanup();
|
---|
488 | } finally {
|
---|
489 | activeSub = prevSub;
|
---|
490 | }
|
---|
491 | }
|
---|
492 | }
|
---|
493 |
|
---|
494 | let globalVersion = 0;
|
---|
495 | class Link {
|
---|
496 | constructor(sub, dep) {
|
---|
497 | this.sub = sub;
|
---|
498 | this.dep = dep;
|
---|
499 | this.version = dep.version;
|
---|
500 | this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
---|
501 | }
|
---|
502 | }
|
---|
503 | class Dep {
|
---|
504 | constructor(computed) {
|
---|
505 | this.computed = computed;
|
---|
506 | this.version = 0;
|
---|
507 | /**
|
---|
508 | * Link between this dep and the current active effect
|
---|
509 | */
|
---|
510 | this.activeLink = void 0;
|
---|
511 | /**
|
---|
512 | * Doubly linked list representing the subscribing effects (tail)
|
---|
513 | */
|
---|
514 | this.subs = void 0;
|
---|
515 | /**
|
---|
516 | * For object property deps cleanup
|
---|
517 | */
|
---|
518 | this.map = void 0;
|
---|
519 | this.key = void 0;
|
---|
520 | /**
|
---|
521 | * Subscriber counter
|
---|
522 | */
|
---|
523 | this.sc = 0;
|
---|
524 | {
|
---|
525 | this.subsHead = void 0;
|
---|
526 | }
|
---|
527 | }
|
---|
528 | track(debugInfo) {
|
---|
529 | if (!activeSub || !shouldTrack || activeSub === this.computed) {
|
---|
530 | return;
|
---|
531 | }
|
---|
532 | let link = this.activeLink;
|
---|
533 | if (link === void 0 || link.sub !== activeSub) {
|
---|
534 | link = this.activeLink = new Link(activeSub, this);
|
---|
535 | if (!activeSub.deps) {
|
---|
536 | activeSub.deps = activeSub.depsTail = link;
|
---|
537 | } else {
|
---|
538 | link.prevDep = activeSub.depsTail;
|
---|
539 | activeSub.depsTail.nextDep = link;
|
---|
540 | activeSub.depsTail = link;
|
---|
541 | }
|
---|
542 | addSub(link);
|
---|
543 | } else if (link.version === -1) {
|
---|
544 | link.version = this.version;
|
---|
545 | if (link.nextDep) {
|
---|
546 | const next = link.nextDep;
|
---|
547 | next.prevDep = link.prevDep;
|
---|
548 | if (link.prevDep) {
|
---|
549 | link.prevDep.nextDep = next;
|
---|
550 | }
|
---|
551 | link.prevDep = activeSub.depsTail;
|
---|
552 | link.nextDep = void 0;
|
---|
553 | activeSub.depsTail.nextDep = link;
|
---|
554 | activeSub.depsTail = link;
|
---|
555 | if (activeSub.deps === link) {
|
---|
556 | activeSub.deps = next;
|
---|
557 | }
|
---|
558 | }
|
---|
559 | }
|
---|
560 | if (activeSub.onTrack) {
|
---|
561 | activeSub.onTrack(
|
---|
562 | shared.extend(
|
---|
563 | {
|
---|
564 | effect: activeSub
|
---|
565 | },
|
---|
566 | debugInfo
|
---|
567 | )
|
---|
568 | );
|
---|
569 | }
|
---|
570 | return link;
|
---|
571 | }
|
---|
572 | trigger(debugInfo) {
|
---|
573 | this.version++;
|
---|
574 | globalVersion++;
|
---|
575 | this.notify(debugInfo);
|
---|
576 | }
|
---|
577 | notify(debugInfo) {
|
---|
578 | startBatch();
|
---|
579 | try {
|
---|
580 | if (true) {
|
---|
581 | for (let head = this.subsHead; head; head = head.nextSub) {
|
---|
582 | if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
---|
583 | head.sub.onTrigger(
|
---|
584 | shared.extend(
|
---|
585 | {
|
---|
586 | effect: head.sub
|
---|
587 | },
|
---|
588 | debugInfo
|
---|
589 | )
|
---|
590 | );
|
---|
591 | }
|
---|
592 | }
|
---|
593 | }
|
---|
594 | for (let link = this.subs; link; link = link.prevSub) {
|
---|
595 | if (link.sub.notify()) {
|
---|
596 | ;
|
---|
597 | link.sub.dep.notify();
|
---|
598 | }
|
---|
599 | }
|
---|
600 | } finally {
|
---|
601 | endBatch();
|
---|
602 | }
|
---|
603 | }
|
---|
604 | }
|
---|
605 | function addSub(link) {
|
---|
606 | link.dep.sc++;
|
---|
607 | if (link.sub.flags & 4) {
|
---|
608 | const computed = link.dep.computed;
|
---|
609 | if (computed && !link.dep.subs) {
|
---|
610 | computed.flags |= 4 | 16;
|
---|
611 | for (let l = computed.deps; l; l = l.nextDep) {
|
---|
612 | addSub(l);
|
---|
613 | }
|
---|
614 | }
|
---|
615 | const currentTail = link.dep.subs;
|
---|
616 | if (currentTail !== link) {
|
---|
617 | link.prevSub = currentTail;
|
---|
618 | if (currentTail) currentTail.nextSub = link;
|
---|
619 | }
|
---|
620 | if (link.dep.subsHead === void 0) {
|
---|
621 | link.dep.subsHead = link;
|
---|
622 | }
|
---|
623 | link.dep.subs = link;
|
---|
624 | }
|
---|
625 | }
|
---|
626 | const targetMap = /* @__PURE__ */ new WeakMap();
|
---|
627 | const ITERATE_KEY = Symbol(
|
---|
628 | "Object iterate"
|
---|
629 | );
|
---|
630 | const MAP_KEY_ITERATE_KEY = Symbol(
|
---|
631 | "Map keys iterate"
|
---|
632 | );
|
---|
633 | const ARRAY_ITERATE_KEY = Symbol(
|
---|
634 | "Array iterate"
|
---|
635 | );
|
---|
636 | function track(target, type, key) {
|
---|
637 | if (shouldTrack && activeSub) {
|
---|
638 | let depsMap = targetMap.get(target);
|
---|
639 | if (!depsMap) {
|
---|
640 | targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
---|
641 | }
|
---|
642 | let dep = depsMap.get(key);
|
---|
643 | if (!dep) {
|
---|
644 | depsMap.set(key, dep = new Dep());
|
---|
645 | dep.map = depsMap;
|
---|
646 | dep.key = key;
|
---|
647 | }
|
---|
648 | {
|
---|
649 | dep.track({
|
---|
650 | target,
|
---|
651 | type,
|
---|
652 | key
|
---|
653 | });
|
---|
654 | }
|
---|
655 | }
|
---|
656 | }
|
---|
657 | function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
---|
658 | const depsMap = targetMap.get(target);
|
---|
659 | if (!depsMap) {
|
---|
660 | globalVersion++;
|
---|
661 | return;
|
---|
662 | }
|
---|
663 | const run = (dep) => {
|
---|
664 | if (dep) {
|
---|
665 | {
|
---|
666 | dep.trigger({
|
---|
667 | target,
|
---|
668 | type,
|
---|
669 | key,
|
---|
670 | newValue,
|
---|
671 | oldValue,
|
---|
672 | oldTarget
|
---|
673 | });
|
---|
674 | }
|
---|
675 | }
|
---|
676 | };
|
---|
677 | startBatch();
|
---|
678 | if (type === "clear") {
|
---|
679 | depsMap.forEach(run);
|
---|
680 | } else {
|
---|
681 | const targetIsArray = shared.isArray(target);
|
---|
682 | const isArrayIndex = targetIsArray && shared.isIntegerKey(key);
|
---|
683 | if (targetIsArray && key === "length") {
|
---|
684 | const newLength = Number(newValue);
|
---|
685 | depsMap.forEach((dep, key2) => {
|
---|
686 | if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !shared.isSymbol(key2) && key2 >= newLength) {
|
---|
687 | run(dep);
|
---|
688 | }
|
---|
689 | });
|
---|
690 | } else {
|
---|
691 | if (key !== void 0 || depsMap.has(void 0)) {
|
---|
692 | run(depsMap.get(key));
|
---|
693 | }
|
---|
694 | if (isArrayIndex) {
|
---|
695 | run(depsMap.get(ARRAY_ITERATE_KEY));
|
---|
696 | }
|
---|
697 | switch (type) {
|
---|
698 | case "add":
|
---|
699 | if (!targetIsArray) {
|
---|
700 | run(depsMap.get(ITERATE_KEY));
|
---|
701 | if (shared.isMap(target)) {
|
---|
702 | run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
---|
703 | }
|
---|
704 | } else if (isArrayIndex) {
|
---|
705 | run(depsMap.get("length"));
|
---|
706 | }
|
---|
707 | break;
|
---|
708 | case "delete":
|
---|
709 | if (!targetIsArray) {
|
---|
710 | run(depsMap.get(ITERATE_KEY));
|
---|
711 | if (shared.isMap(target)) {
|
---|
712 | run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
---|
713 | }
|
---|
714 | }
|
---|
715 | break;
|
---|
716 | case "set":
|
---|
717 | if (shared.isMap(target)) {
|
---|
718 | run(depsMap.get(ITERATE_KEY));
|
---|
719 | }
|
---|
720 | break;
|
---|
721 | }
|
---|
722 | }
|
---|
723 | }
|
---|
724 | endBatch();
|
---|
725 | }
|
---|
726 | function getDepFromReactive(object, key) {
|
---|
727 | const depMap = targetMap.get(object);
|
---|
728 | return depMap && depMap.get(key);
|
---|
729 | }
|
---|
730 |
|
---|
731 | function reactiveReadArray(array) {
|
---|
732 | const raw = toRaw(array);
|
---|
733 | if (raw === array) return raw;
|
---|
734 | track(raw, "iterate", ARRAY_ITERATE_KEY);
|
---|
735 | return isShallow(array) ? raw : raw.map(toReactive);
|
---|
736 | }
|
---|
737 | function shallowReadArray(arr) {
|
---|
738 | track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
---|
739 | return arr;
|
---|
740 | }
|
---|
741 | const arrayInstrumentations = {
|
---|
742 | __proto__: null,
|
---|
743 | [Symbol.iterator]() {
|
---|
744 | return iterator(this, Symbol.iterator, toReactive);
|
---|
745 | },
|
---|
746 | concat(...args) {
|
---|
747 | return reactiveReadArray(this).concat(
|
---|
748 | ...args.map((x) => shared.isArray(x) ? reactiveReadArray(x) : x)
|
---|
749 | );
|
---|
750 | },
|
---|
751 | entries() {
|
---|
752 | return iterator(this, "entries", (value) => {
|
---|
753 | value[1] = toReactive(value[1]);
|
---|
754 | return value;
|
---|
755 | });
|
---|
756 | },
|
---|
757 | every(fn, thisArg) {
|
---|
758 | return apply(this, "every", fn, thisArg, void 0, arguments);
|
---|
759 | },
|
---|
760 | filter(fn, thisArg) {
|
---|
761 | return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
|
---|
762 | },
|
---|
763 | find(fn, thisArg) {
|
---|
764 | return apply(this, "find", fn, thisArg, toReactive, arguments);
|
---|
765 | },
|
---|
766 | findIndex(fn, thisArg) {
|
---|
767 | return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
---|
768 | },
|
---|
769 | findLast(fn, thisArg) {
|
---|
770 | return apply(this, "findLast", fn, thisArg, toReactive, arguments);
|
---|
771 | },
|
---|
772 | findLastIndex(fn, thisArg) {
|
---|
773 | return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
---|
774 | },
|
---|
775 | // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
|
---|
776 | forEach(fn, thisArg) {
|
---|
777 | return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
---|
778 | },
|
---|
779 | includes(...args) {
|
---|
780 | return searchProxy(this, "includes", args);
|
---|
781 | },
|
---|
782 | indexOf(...args) {
|
---|
783 | return searchProxy(this, "indexOf", args);
|
---|
784 | },
|
---|
785 | join(separator) {
|
---|
786 | return reactiveReadArray(this).join(separator);
|
---|
787 | },
|
---|
788 | // keys() iterator only reads `length`, no optimisation required
|
---|
789 | lastIndexOf(...args) {
|
---|
790 | return searchProxy(this, "lastIndexOf", args);
|
---|
791 | },
|
---|
792 | map(fn, thisArg) {
|
---|
793 | return apply(this, "map", fn, thisArg, void 0, arguments);
|
---|
794 | },
|
---|
795 | pop() {
|
---|
796 | return noTracking(this, "pop");
|
---|
797 | },
|
---|
798 | push(...args) {
|
---|
799 | return noTracking(this, "push", args);
|
---|
800 | },
|
---|
801 | reduce(fn, ...args) {
|
---|
802 | return reduce(this, "reduce", fn, args);
|
---|
803 | },
|
---|
804 | reduceRight(fn, ...args) {
|
---|
805 | return reduce(this, "reduceRight", fn, args);
|
---|
806 | },
|
---|
807 | shift() {
|
---|
808 | return noTracking(this, "shift");
|
---|
809 | },
|
---|
810 | // slice could use ARRAY_ITERATE but also seems to beg for range tracking
|
---|
811 | some(fn, thisArg) {
|
---|
812 | return apply(this, "some", fn, thisArg, void 0, arguments);
|
---|
813 | },
|
---|
814 | splice(...args) {
|
---|
815 | return noTracking(this, "splice", args);
|
---|
816 | },
|
---|
817 | toReversed() {
|
---|
818 | return reactiveReadArray(this).toReversed();
|
---|
819 | },
|
---|
820 | toSorted(comparer) {
|
---|
821 | return reactiveReadArray(this).toSorted(comparer);
|
---|
822 | },
|
---|
823 | toSpliced(...args) {
|
---|
824 | return reactiveReadArray(this).toSpliced(...args);
|
---|
825 | },
|
---|
826 | unshift(...args) {
|
---|
827 | return noTracking(this, "unshift", args);
|
---|
828 | },
|
---|
829 | values() {
|
---|
830 | return iterator(this, "values", toReactive);
|
---|
831 | }
|
---|
832 | };
|
---|
833 | function iterator(self, method, wrapValue) {
|
---|
834 | const arr = shallowReadArray(self);
|
---|
835 | const iter = arr[method]();
|
---|
836 | if (arr !== self && !isShallow(self)) {
|
---|
837 | iter._next = iter.next;
|
---|
838 | iter.next = () => {
|
---|
839 | const result = iter._next();
|
---|
840 | if (result.value) {
|
---|
841 | result.value = wrapValue(result.value);
|
---|
842 | }
|
---|
843 | return result;
|
---|
844 | };
|
---|
845 | }
|
---|
846 | return iter;
|
---|
847 | }
|
---|
848 | const arrayProto = Array.prototype;
|
---|
849 | function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
---|
850 | const arr = shallowReadArray(self);
|
---|
851 | const needsWrap = arr !== self && !isShallow(self);
|
---|
852 | const methodFn = arr[method];
|
---|
853 | if (methodFn !== arrayProto[method]) {
|
---|
854 | const result2 = methodFn.apply(self, args);
|
---|
855 | return needsWrap ? toReactive(result2) : result2;
|
---|
856 | }
|
---|
857 | let wrappedFn = fn;
|
---|
858 | if (arr !== self) {
|
---|
859 | if (needsWrap) {
|
---|
860 | wrappedFn = function(item, index) {
|
---|
861 | return fn.call(this, toReactive(item), index, self);
|
---|
862 | };
|
---|
863 | } else if (fn.length > 2) {
|
---|
864 | wrappedFn = function(item, index) {
|
---|
865 | return fn.call(this, item, index, self);
|
---|
866 | };
|
---|
867 | }
|
---|
868 | }
|
---|
869 | const result = methodFn.call(arr, wrappedFn, thisArg);
|
---|
870 | return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
---|
871 | }
|
---|
872 | function reduce(self, method, fn, args) {
|
---|
873 | const arr = shallowReadArray(self);
|
---|
874 | let wrappedFn = fn;
|
---|
875 | if (arr !== self) {
|
---|
876 | if (!isShallow(self)) {
|
---|
877 | wrappedFn = function(acc, item, index) {
|
---|
878 | return fn.call(this, acc, toReactive(item), index, self);
|
---|
879 | };
|
---|
880 | } else if (fn.length > 3) {
|
---|
881 | wrappedFn = function(acc, item, index) {
|
---|
882 | return fn.call(this, acc, item, index, self);
|
---|
883 | };
|
---|
884 | }
|
---|
885 | }
|
---|
886 | return arr[method](wrappedFn, ...args);
|
---|
887 | }
|
---|
888 | function searchProxy(self, method, args) {
|
---|
889 | const arr = toRaw(self);
|
---|
890 | track(arr, "iterate", ARRAY_ITERATE_KEY);
|
---|
891 | const res = arr[method](...args);
|
---|
892 | if ((res === -1 || res === false) && isProxy(args[0])) {
|
---|
893 | args[0] = toRaw(args[0]);
|
---|
894 | return arr[method](...args);
|
---|
895 | }
|
---|
896 | return res;
|
---|
897 | }
|
---|
898 | function noTracking(self, method, args = []) {
|
---|
899 | pauseTracking();
|
---|
900 | startBatch();
|
---|
901 | const res = toRaw(self)[method].apply(self, args);
|
---|
902 | endBatch();
|
---|
903 | resetTracking();
|
---|
904 | return res;
|
---|
905 | }
|
---|
906 |
|
---|
907 | const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,__isVue`);
|
---|
908 | const builtInSymbols = new Set(
|
---|
909 | /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
|
---|
910 | );
|
---|
911 | function hasOwnProperty(key) {
|
---|
912 | if (!shared.isSymbol(key)) key = String(key);
|
---|
913 | const obj = toRaw(this);
|
---|
914 | track(obj, "has", key);
|
---|
915 | return obj.hasOwnProperty(key);
|
---|
916 | }
|
---|
917 | class BaseReactiveHandler {
|
---|
918 | constructor(_isReadonly = false, _isShallow = false) {
|
---|
919 | this._isReadonly = _isReadonly;
|
---|
920 | this._isShallow = _isShallow;
|
---|
921 | }
|
---|
922 | get(target, key, receiver) {
|
---|
923 | if (key === "__v_skip") return target["__v_skip"];
|
---|
924 | const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
---|
925 | if (key === "__v_isReactive") {
|
---|
926 | return !isReadonly2;
|
---|
927 | } else if (key === "__v_isReadonly") {
|
---|
928 | return isReadonly2;
|
---|
929 | } else if (key === "__v_isShallow") {
|
---|
930 | return isShallow2;
|
---|
931 | } else if (key === "__v_raw") {
|
---|
932 | if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
|
---|
933 | // this means the receiver is a user proxy of the reactive proxy
|
---|
934 | Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
---|
935 | return target;
|
---|
936 | }
|
---|
937 | return;
|
---|
938 | }
|
---|
939 | const targetIsArray = shared.isArray(target);
|
---|
940 | if (!isReadonly2) {
|
---|
941 | let fn;
|
---|
942 | if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
---|
943 | return fn;
|
---|
944 | }
|
---|
945 | if (key === "hasOwnProperty") {
|
---|
946 | return hasOwnProperty;
|
---|
947 | }
|
---|
948 | }
|
---|
949 | const res = Reflect.get(
|
---|
950 | target,
|
---|
951 | key,
|
---|
952 | // if this is a proxy wrapping a ref, return methods using the raw ref
|
---|
953 | // as receiver so that we don't have to call `toRaw` on the ref in all
|
---|
954 | // its class methods
|
---|
955 | isRef(target) ? target : receiver
|
---|
956 | );
|
---|
957 | if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
---|
958 | return res;
|
---|
959 | }
|
---|
960 | if (!isReadonly2) {
|
---|
961 | track(target, "get", key);
|
---|
962 | }
|
---|
963 | if (isShallow2) {
|
---|
964 | return res;
|
---|
965 | }
|
---|
966 | if (isRef(res)) {
|
---|
967 | return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
|
---|
968 | }
|
---|
969 | if (shared.isObject(res)) {
|
---|
970 | return isReadonly2 ? readonly(res) : reactive(res);
|
---|
971 | }
|
---|
972 | return res;
|
---|
973 | }
|
---|
974 | }
|
---|
975 | class MutableReactiveHandler extends BaseReactiveHandler {
|
---|
976 | constructor(isShallow2 = false) {
|
---|
977 | super(false, isShallow2);
|
---|
978 | }
|
---|
979 | set(target, key, value, receiver) {
|
---|
980 | let oldValue = target[key];
|
---|
981 | if (!this._isShallow) {
|
---|
982 | const isOldValueReadonly = isReadonly(oldValue);
|
---|
983 | if (!isShallow(value) && !isReadonly(value)) {
|
---|
984 | oldValue = toRaw(oldValue);
|
---|
985 | value = toRaw(value);
|
---|
986 | }
|
---|
987 | if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
|
---|
988 | if (isOldValueReadonly) {
|
---|
989 | return false;
|
---|
990 | } else {
|
---|
991 | oldValue.value = value;
|
---|
992 | return true;
|
---|
993 | }
|
---|
994 | }
|
---|
995 | }
|
---|
996 | const hadKey = shared.isArray(target) && shared.isIntegerKey(key) ? Number(key) < target.length : shared.hasOwn(target, key);
|
---|
997 | const result = Reflect.set(
|
---|
998 | target,
|
---|
999 | key,
|
---|
1000 | value,
|
---|
1001 | isRef(target) ? target : receiver
|
---|
1002 | );
|
---|
1003 | if (target === toRaw(receiver)) {
|
---|
1004 | if (!hadKey) {
|
---|
1005 | trigger(target, "add", key, value);
|
---|
1006 | } else if (shared.hasChanged(value, oldValue)) {
|
---|
1007 | trigger(target, "set", key, value, oldValue);
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 | return result;
|
---|
1011 | }
|
---|
1012 | deleteProperty(target, key) {
|
---|
1013 | const hadKey = shared.hasOwn(target, key);
|
---|
1014 | const oldValue = target[key];
|
---|
1015 | const result = Reflect.deleteProperty(target, key);
|
---|
1016 | if (result && hadKey) {
|
---|
1017 | trigger(target, "delete", key, void 0, oldValue);
|
---|
1018 | }
|
---|
1019 | return result;
|
---|
1020 | }
|
---|
1021 | has(target, key) {
|
---|
1022 | const result = Reflect.has(target, key);
|
---|
1023 | if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
|
---|
1024 | track(target, "has", key);
|
---|
1025 | }
|
---|
1026 | return result;
|
---|
1027 | }
|
---|
1028 | ownKeys(target) {
|
---|
1029 | track(
|
---|
1030 | target,
|
---|
1031 | "iterate",
|
---|
1032 | shared.isArray(target) ? "length" : ITERATE_KEY
|
---|
1033 | );
|
---|
1034 | return Reflect.ownKeys(target);
|
---|
1035 | }
|
---|
1036 | }
|
---|
1037 | class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
---|
1038 | constructor(isShallow2 = false) {
|
---|
1039 | super(true, isShallow2);
|
---|
1040 | }
|
---|
1041 | set(target, key) {
|
---|
1042 | {
|
---|
1043 | warn(
|
---|
1044 | `Set operation on key "${String(key)}" failed: target is readonly.`,
|
---|
1045 | target
|
---|
1046 | );
|
---|
1047 | }
|
---|
1048 | return true;
|
---|
1049 | }
|
---|
1050 | deleteProperty(target, key) {
|
---|
1051 | {
|
---|
1052 | warn(
|
---|
1053 | `Delete operation on key "${String(key)}" failed: target is readonly.`,
|
---|
1054 | target
|
---|
1055 | );
|
---|
1056 | }
|
---|
1057 | return true;
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 | const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
---|
1061 | const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
---|
1062 | const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
|
---|
1063 | const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
---|
1064 |
|
---|
1065 | const toShallow = (value) => value;
|
---|
1066 | const getProto = (v) => Reflect.getPrototypeOf(v);
|
---|
1067 | function createIterableMethod(method, isReadonly2, isShallow2) {
|
---|
1068 | return function(...args) {
|
---|
1069 | const target = this["__v_raw"];
|
---|
1070 | const rawTarget = toRaw(target);
|
---|
1071 | const targetIsMap = shared.isMap(rawTarget);
|
---|
1072 | const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
---|
1073 | const isKeyOnly = method === "keys" && targetIsMap;
|
---|
1074 | const innerIterator = target[method](...args);
|
---|
1075 | const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
---|
1076 | !isReadonly2 && track(
|
---|
1077 | rawTarget,
|
---|
1078 | "iterate",
|
---|
1079 | isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
|
---|
1080 | );
|
---|
1081 | return {
|
---|
1082 | // iterator protocol
|
---|
1083 | next() {
|
---|
1084 | const { value, done } = innerIterator.next();
|
---|
1085 | return done ? { value, done } : {
|
---|
1086 | value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
---|
1087 | done
|
---|
1088 | };
|
---|
1089 | },
|
---|
1090 | // iterable protocol
|
---|
1091 | [Symbol.iterator]() {
|
---|
1092 | return this;
|
---|
1093 | }
|
---|
1094 | };
|
---|
1095 | };
|
---|
1096 | }
|
---|
1097 | function createReadonlyMethod(type) {
|
---|
1098 | return function(...args) {
|
---|
1099 | {
|
---|
1100 | const key = args[0] ? `on key "${args[0]}" ` : ``;
|
---|
1101 | warn(
|
---|
1102 | `${shared.capitalize(type)} operation ${key}failed: target is readonly.`,
|
---|
1103 | toRaw(this)
|
---|
1104 | );
|
---|
1105 | }
|
---|
1106 | return type === "delete" ? false : type === "clear" ? void 0 : this;
|
---|
1107 | };
|
---|
1108 | }
|
---|
1109 | function createInstrumentations(readonly, shallow) {
|
---|
1110 | const instrumentations = {
|
---|
1111 | get(key) {
|
---|
1112 | const target = this["__v_raw"];
|
---|
1113 | const rawTarget = toRaw(target);
|
---|
1114 | const rawKey = toRaw(key);
|
---|
1115 | if (!readonly) {
|
---|
1116 | if (shared.hasChanged(key, rawKey)) {
|
---|
1117 | track(rawTarget, "get", key);
|
---|
1118 | }
|
---|
1119 | track(rawTarget, "get", rawKey);
|
---|
1120 | }
|
---|
1121 | const { has } = getProto(rawTarget);
|
---|
1122 | const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
---|
1123 | if (has.call(rawTarget, key)) {
|
---|
1124 | return wrap(target.get(key));
|
---|
1125 | } else if (has.call(rawTarget, rawKey)) {
|
---|
1126 | return wrap(target.get(rawKey));
|
---|
1127 | } else if (target !== rawTarget) {
|
---|
1128 | target.get(key);
|
---|
1129 | }
|
---|
1130 | },
|
---|
1131 | get size() {
|
---|
1132 | const target = this["__v_raw"];
|
---|
1133 | !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
|
---|
1134 | return Reflect.get(target, "size", target);
|
---|
1135 | },
|
---|
1136 | has(key) {
|
---|
1137 | const target = this["__v_raw"];
|
---|
1138 | const rawTarget = toRaw(target);
|
---|
1139 | const rawKey = toRaw(key);
|
---|
1140 | if (!readonly) {
|
---|
1141 | if (shared.hasChanged(key, rawKey)) {
|
---|
1142 | track(rawTarget, "has", key);
|
---|
1143 | }
|
---|
1144 | track(rawTarget, "has", rawKey);
|
---|
1145 | }
|
---|
1146 | return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
---|
1147 | },
|
---|
1148 | forEach(callback, thisArg) {
|
---|
1149 | const observed = this;
|
---|
1150 | const target = observed["__v_raw"];
|
---|
1151 | const rawTarget = toRaw(target);
|
---|
1152 | const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
---|
1153 | !readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
---|
1154 | return target.forEach((value, key) => {
|
---|
1155 | return callback.call(thisArg, wrap(value), wrap(key), observed);
|
---|
1156 | });
|
---|
1157 | }
|
---|
1158 | };
|
---|
1159 | shared.extend(
|
---|
1160 | instrumentations,
|
---|
1161 | readonly ? {
|
---|
1162 | add: createReadonlyMethod("add"),
|
---|
1163 | set: createReadonlyMethod("set"),
|
---|
1164 | delete: createReadonlyMethod("delete"),
|
---|
1165 | clear: createReadonlyMethod("clear")
|
---|
1166 | } : {
|
---|
1167 | add(value) {
|
---|
1168 | if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
---|
1169 | value = toRaw(value);
|
---|
1170 | }
|
---|
1171 | const target = toRaw(this);
|
---|
1172 | const proto = getProto(target);
|
---|
1173 | const hadKey = proto.has.call(target, value);
|
---|
1174 | if (!hadKey) {
|
---|
1175 | target.add(value);
|
---|
1176 | trigger(target, "add", value, value);
|
---|
1177 | }
|
---|
1178 | return this;
|
---|
1179 | },
|
---|
1180 | set(key, value) {
|
---|
1181 | if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
---|
1182 | value = toRaw(value);
|
---|
1183 | }
|
---|
1184 | const target = toRaw(this);
|
---|
1185 | const { has, get } = getProto(target);
|
---|
1186 | let hadKey = has.call(target, key);
|
---|
1187 | if (!hadKey) {
|
---|
1188 | key = toRaw(key);
|
---|
1189 | hadKey = has.call(target, key);
|
---|
1190 | } else {
|
---|
1191 | checkIdentityKeys(target, has, key);
|
---|
1192 | }
|
---|
1193 | const oldValue = get.call(target, key);
|
---|
1194 | target.set(key, value);
|
---|
1195 | if (!hadKey) {
|
---|
1196 | trigger(target, "add", key, value);
|
---|
1197 | } else if (shared.hasChanged(value, oldValue)) {
|
---|
1198 | trigger(target, "set", key, value, oldValue);
|
---|
1199 | }
|
---|
1200 | return this;
|
---|
1201 | },
|
---|
1202 | delete(key) {
|
---|
1203 | const target = toRaw(this);
|
---|
1204 | const { has, get } = getProto(target);
|
---|
1205 | let hadKey = has.call(target, key);
|
---|
1206 | if (!hadKey) {
|
---|
1207 | key = toRaw(key);
|
---|
1208 | hadKey = has.call(target, key);
|
---|
1209 | } else {
|
---|
1210 | checkIdentityKeys(target, has, key);
|
---|
1211 | }
|
---|
1212 | const oldValue = get ? get.call(target, key) : void 0;
|
---|
1213 | const result = target.delete(key);
|
---|
1214 | if (hadKey) {
|
---|
1215 | trigger(target, "delete", key, void 0, oldValue);
|
---|
1216 | }
|
---|
1217 | return result;
|
---|
1218 | },
|
---|
1219 | clear() {
|
---|
1220 | const target = toRaw(this);
|
---|
1221 | const hadItems = target.size !== 0;
|
---|
1222 | const oldTarget = shared.isMap(target) ? new Map(target) : new Set(target) ;
|
---|
1223 | const result = target.clear();
|
---|
1224 | if (hadItems) {
|
---|
1225 | trigger(
|
---|
1226 | target,
|
---|
1227 | "clear",
|
---|
1228 | void 0,
|
---|
1229 | void 0,
|
---|
1230 | oldTarget
|
---|
1231 | );
|
---|
1232 | }
|
---|
1233 | return result;
|
---|
1234 | }
|
---|
1235 | }
|
---|
1236 | );
|
---|
1237 | const iteratorMethods = [
|
---|
1238 | "keys",
|
---|
1239 | "values",
|
---|
1240 | "entries",
|
---|
1241 | Symbol.iterator
|
---|
1242 | ];
|
---|
1243 | iteratorMethods.forEach((method) => {
|
---|
1244 | instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
---|
1245 | });
|
---|
1246 | return instrumentations;
|
---|
1247 | }
|
---|
1248 | function createInstrumentationGetter(isReadonly2, shallow) {
|
---|
1249 | const instrumentations = createInstrumentations(isReadonly2, shallow);
|
---|
1250 | return (target, key, receiver) => {
|
---|
1251 | if (key === "__v_isReactive") {
|
---|
1252 | return !isReadonly2;
|
---|
1253 | } else if (key === "__v_isReadonly") {
|
---|
1254 | return isReadonly2;
|
---|
1255 | } else if (key === "__v_raw") {
|
---|
1256 | return target;
|
---|
1257 | }
|
---|
1258 | return Reflect.get(
|
---|
1259 | shared.hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
---|
1260 | key,
|
---|
1261 | receiver
|
---|
1262 | );
|
---|
1263 | };
|
---|
1264 | }
|
---|
1265 | const mutableCollectionHandlers = {
|
---|
1266 | get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
---|
1267 | };
|
---|
1268 | const shallowCollectionHandlers = {
|
---|
1269 | get: /* @__PURE__ */ createInstrumentationGetter(false, true)
|
---|
1270 | };
|
---|
1271 | const readonlyCollectionHandlers = {
|
---|
1272 | get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
---|
1273 | };
|
---|
1274 | const shallowReadonlyCollectionHandlers = {
|
---|
1275 | get: /* @__PURE__ */ createInstrumentationGetter(true, true)
|
---|
1276 | };
|
---|
1277 | function checkIdentityKeys(target, has, key) {
|
---|
1278 | const rawKey = toRaw(key);
|
---|
1279 | if (rawKey !== key && has.call(target, rawKey)) {
|
---|
1280 | const type = shared.toRawType(target);
|
---|
1281 | warn(
|
---|
1282 | `Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
|
---|
1283 | );
|
---|
1284 | }
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | const reactiveMap = /* @__PURE__ */ new WeakMap();
|
---|
1288 | const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
---|
1289 | const readonlyMap = /* @__PURE__ */ new WeakMap();
|
---|
1290 | const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
---|
1291 | function targetTypeMap(rawType) {
|
---|
1292 | switch (rawType) {
|
---|
1293 | case "Object":
|
---|
1294 | case "Array":
|
---|
1295 | return 1 /* COMMON */;
|
---|
1296 | case "Map":
|
---|
1297 | case "Set":
|
---|
1298 | case "WeakMap":
|
---|
1299 | case "WeakSet":
|
---|
1300 | return 2 /* COLLECTION */;
|
---|
1301 | default:
|
---|
1302 | return 0 /* INVALID */;
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 | function getTargetType(value) {
|
---|
1306 | return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(shared.toRawType(value));
|
---|
1307 | }
|
---|
1308 | function reactive(target) {
|
---|
1309 | if (isReadonly(target)) {
|
---|
1310 | return target;
|
---|
1311 | }
|
---|
1312 | return createReactiveObject(
|
---|
1313 | target,
|
---|
1314 | false,
|
---|
1315 | mutableHandlers,
|
---|
1316 | mutableCollectionHandlers,
|
---|
1317 | reactiveMap
|
---|
1318 | );
|
---|
1319 | }
|
---|
1320 | function shallowReactive(target) {
|
---|
1321 | return createReactiveObject(
|
---|
1322 | target,
|
---|
1323 | false,
|
---|
1324 | shallowReactiveHandlers,
|
---|
1325 | shallowCollectionHandlers,
|
---|
1326 | shallowReactiveMap
|
---|
1327 | );
|
---|
1328 | }
|
---|
1329 | function readonly(target) {
|
---|
1330 | return createReactiveObject(
|
---|
1331 | target,
|
---|
1332 | true,
|
---|
1333 | readonlyHandlers,
|
---|
1334 | readonlyCollectionHandlers,
|
---|
1335 | readonlyMap
|
---|
1336 | );
|
---|
1337 | }
|
---|
1338 | function shallowReadonly(target) {
|
---|
1339 | return createReactiveObject(
|
---|
1340 | target,
|
---|
1341 | true,
|
---|
1342 | shallowReadonlyHandlers,
|
---|
1343 | shallowReadonlyCollectionHandlers,
|
---|
1344 | shallowReadonlyMap
|
---|
1345 | );
|
---|
1346 | }
|
---|
1347 | function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
---|
1348 | if (!shared.isObject(target)) {
|
---|
1349 | {
|
---|
1350 | warn(
|
---|
1351 | `value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(
|
---|
1352 | target
|
---|
1353 | )}`
|
---|
1354 | );
|
---|
1355 | }
|
---|
1356 | return target;
|
---|
1357 | }
|
---|
1358 | if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
---|
1359 | return target;
|
---|
1360 | }
|
---|
1361 | const existingProxy = proxyMap.get(target);
|
---|
1362 | if (existingProxy) {
|
---|
1363 | return existingProxy;
|
---|
1364 | }
|
---|
1365 | const targetType = getTargetType(target);
|
---|
1366 | if (targetType === 0 /* INVALID */) {
|
---|
1367 | return target;
|
---|
1368 | }
|
---|
1369 | const proxy = new Proxy(
|
---|
1370 | target,
|
---|
1371 | targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
|
---|
1372 | );
|
---|
1373 | proxyMap.set(target, proxy);
|
---|
1374 | return proxy;
|
---|
1375 | }
|
---|
1376 | function isReactive(value) {
|
---|
1377 | if (isReadonly(value)) {
|
---|
1378 | return isReactive(value["__v_raw"]);
|
---|
1379 | }
|
---|
1380 | return !!(value && value["__v_isReactive"]);
|
---|
1381 | }
|
---|
1382 | function isReadonly(value) {
|
---|
1383 | return !!(value && value["__v_isReadonly"]);
|
---|
1384 | }
|
---|
1385 | function isShallow(value) {
|
---|
1386 | return !!(value && value["__v_isShallow"]);
|
---|
1387 | }
|
---|
1388 | function isProxy(value) {
|
---|
1389 | return value ? !!value["__v_raw"] : false;
|
---|
1390 | }
|
---|
1391 | function toRaw(observed) {
|
---|
1392 | const raw = observed && observed["__v_raw"];
|
---|
1393 | return raw ? toRaw(raw) : observed;
|
---|
1394 | }
|
---|
1395 | function markRaw(value) {
|
---|
1396 | if (!shared.hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
|
---|
1397 | shared.def(value, "__v_skip", true);
|
---|
1398 | }
|
---|
1399 | return value;
|
---|
1400 | }
|
---|
1401 | const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
|
---|
1402 | const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
|
---|
1403 |
|
---|
1404 | function isRef(r) {
|
---|
1405 | return r ? r["__v_isRef"] === true : false;
|
---|
1406 | }
|
---|
1407 | function ref(value) {
|
---|
1408 | return createRef(value, false);
|
---|
1409 | }
|
---|
1410 | function shallowRef(value) {
|
---|
1411 | return createRef(value, true);
|
---|
1412 | }
|
---|
1413 | function createRef(rawValue, shallow) {
|
---|
1414 | if (isRef(rawValue)) {
|
---|
1415 | return rawValue;
|
---|
1416 | }
|
---|
1417 | return new RefImpl(rawValue, shallow);
|
---|
1418 | }
|
---|
1419 | class RefImpl {
|
---|
1420 | constructor(value, isShallow2) {
|
---|
1421 | this.dep = new Dep();
|
---|
1422 | this["__v_isRef"] = true;
|
---|
1423 | this["__v_isShallow"] = false;
|
---|
1424 | this._rawValue = isShallow2 ? value : toRaw(value);
|
---|
1425 | this._value = isShallow2 ? value : toReactive(value);
|
---|
1426 | this["__v_isShallow"] = isShallow2;
|
---|
1427 | }
|
---|
1428 | get value() {
|
---|
1429 | {
|
---|
1430 | this.dep.track({
|
---|
1431 | target: this,
|
---|
1432 | type: "get",
|
---|
1433 | key: "value"
|
---|
1434 | });
|
---|
1435 | }
|
---|
1436 | return this._value;
|
---|
1437 | }
|
---|
1438 | set value(newValue) {
|
---|
1439 | const oldValue = this._rawValue;
|
---|
1440 | const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
---|
1441 | newValue = useDirectValue ? newValue : toRaw(newValue);
|
---|
1442 | if (shared.hasChanged(newValue, oldValue)) {
|
---|
1443 | this._rawValue = newValue;
|
---|
1444 | this._value = useDirectValue ? newValue : toReactive(newValue);
|
---|
1445 | {
|
---|
1446 | this.dep.trigger({
|
---|
1447 | target: this,
|
---|
1448 | type: "set",
|
---|
1449 | key: "value",
|
---|
1450 | newValue,
|
---|
1451 | oldValue
|
---|
1452 | });
|
---|
1453 | }
|
---|
1454 | }
|
---|
1455 | }
|
---|
1456 | }
|
---|
1457 | function triggerRef(ref2) {
|
---|
1458 | if (ref2.dep) {
|
---|
1459 | {
|
---|
1460 | ref2.dep.trigger({
|
---|
1461 | target: ref2,
|
---|
1462 | type: "set",
|
---|
1463 | key: "value",
|
---|
1464 | newValue: ref2._value
|
---|
1465 | });
|
---|
1466 | }
|
---|
1467 | }
|
---|
1468 | }
|
---|
1469 | function unref(ref2) {
|
---|
1470 | return isRef(ref2) ? ref2.value : ref2;
|
---|
1471 | }
|
---|
1472 | function toValue(source) {
|
---|
1473 | return shared.isFunction(source) ? source() : unref(source);
|
---|
1474 | }
|
---|
1475 | const shallowUnwrapHandlers = {
|
---|
1476 | get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
|
---|
1477 | set: (target, key, value, receiver) => {
|
---|
1478 | const oldValue = target[key];
|
---|
1479 | if (isRef(oldValue) && !isRef(value)) {
|
---|
1480 | oldValue.value = value;
|
---|
1481 | return true;
|
---|
1482 | } else {
|
---|
1483 | return Reflect.set(target, key, value, receiver);
|
---|
1484 | }
|
---|
1485 | }
|
---|
1486 | };
|
---|
1487 | function proxyRefs(objectWithRefs) {
|
---|
1488 | return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
---|
1489 | }
|
---|
1490 | class CustomRefImpl {
|
---|
1491 | constructor(factory) {
|
---|
1492 | this["__v_isRef"] = true;
|
---|
1493 | this._value = void 0;
|
---|
1494 | const dep = this.dep = new Dep();
|
---|
1495 | const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
|
---|
1496 | this._get = get;
|
---|
1497 | this._set = set;
|
---|
1498 | }
|
---|
1499 | get value() {
|
---|
1500 | return this._value = this._get();
|
---|
1501 | }
|
---|
1502 | set value(newVal) {
|
---|
1503 | this._set(newVal);
|
---|
1504 | }
|
---|
1505 | }
|
---|
1506 | function customRef(factory) {
|
---|
1507 | return new CustomRefImpl(factory);
|
---|
1508 | }
|
---|
1509 | function toRefs(object) {
|
---|
1510 | if (!isProxy(object)) {
|
---|
1511 | warn(`toRefs() expects a reactive object but received a plain one.`);
|
---|
1512 | }
|
---|
1513 | const ret = shared.isArray(object) ? new Array(object.length) : {};
|
---|
1514 | for (const key in object) {
|
---|
1515 | ret[key] = propertyToRef(object, key);
|
---|
1516 | }
|
---|
1517 | return ret;
|
---|
1518 | }
|
---|
1519 | class ObjectRefImpl {
|
---|
1520 | constructor(_object, _key, _defaultValue) {
|
---|
1521 | this._object = _object;
|
---|
1522 | this._key = _key;
|
---|
1523 | this._defaultValue = _defaultValue;
|
---|
1524 | this["__v_isRef"] = true;
|
---|
1525 | this._value = void 0;
|
---|
1526 | }
|
---|
1527 | get value() {
|
---|
1528 | const val = this._object[this._key];
|
---|
1529 | return this._value = val === void 0 ? this._defaultValue : val;
|
---|
1530 | }
|
---|
1531 | set value(newVal) {
|
---|
1532 | this._object[this._key] = newVal;
|
---|
1533 | }
|
---|
1534 | get dep() {
|
---|
1535 | return getDepFromReactive(toRaw(this._object), this._key);
|
---|
1536 | }
|
---|
1537 | }
|
---|
1538 | class GetterRefImpl {
|
---|
1539 | constructor(_getter) {
|
---|
1540 | this._getter = _getter;
|
---|
1541 | this["__v_isRef"] = true;
|
---|
1542 | this["__v_isReadonly"] = true;
|
---|
1543 | this._value = void 0;
|
---|
1544 | }
|
---|
1545 | get value() {
|
---|
1546 | return this._value = this._getter();
|
---|
1547 | }
|
---|
1548 | }
|
---|
1549 | function toRef(source, key, defaultValue) {
|
---|
1550 | if (isRef(source)) {
|
---|
1551 | return source;
|
---|
1552 | } else if (shared.isFunction(source)) {
|
---|
1553 | return new GetterRefImpl(source);
|
---|
1554 | } else if (shared.isObject(source) && arguments.length > 1) {
|
---|
1555 | return propertyToRef(source, key, defaultValue);
|
---|
1556 | } else {
|
---|
1557 | return ref(source);
|
---|
1558 | }
|
---|
1559 | }
|
---|
1560 | function propertyToRef(source, key, defaultValue) {
|
---|
1561 | const val = source[key];
|
---|
1562 | return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
---|
1563 | }
|
---|
1564 |
|
---|
1565 | class ComputedRefImpl {
|
---|
1566 | constructor(fn, setter, isSSR) {
|
---|
1567 | this.fn = fn;
|
---|
1568 | this.setter = setter;
|
---|
1569 | /**
|
---|
1570 | * @internal
|
---|
1571 | */
|
---|
1572 | this._value = void 0;
|
---|
1573 | /**
|
---|
1574 | * @internal
|
---|
1575 | */
|
---|
1576 | this.dep = new Dep(this);
|
---|
1577 | /**
|
---|
1578 | * @internal
|
---|
1579 | */
|
---|
1580 | this.__v_isRef = true;
|
---|
1581 | // TODO isolatedDeclarations "__v_isReadonly"
|
---|
1582 | // A computed is also a subscriber that tracks other deps
|
---|
1583 | /**
|
---|
1584 | * @internal
|
---|
1585 | */
|
---|
1586 | this.deps = void 0;
|
---|
1587 | /**
|
---|
1588 | * @internal
|
---|
1589 | */
|
---|
1590 | this.depsTail = void 0;
|
---|
1591 | /**
|
---|
1592 | * @internal
|
---|
1593 | */
|
---|
1594 | this.flags = 16;
|
---|
1595 | /**
|
---|
1596 | * @internal
|
---|
1597 | */
|
---|
1598 | this.globalVersion = globalVersion - 1;
|
---|
1599 | /**
|
---|
1600 | * @internal
|
---|
1601 | */
|
---|
1602 | this.next = void 0;
|
---|
1603 | // for backwards compat
|
---|
1604 | this.effect = this;
|
---|
1605 | this["__v_isReadonly"] = !setter;
|
---|
1606 | this.isSSR = isSSR;
|
---|
1607 | }
|
---|
1608 | /**
|
---|
1609 | * @internal
|
---|
1610 | */
|
---|
1611 | notify() {
|
---|
1612 | this.flags |= 16;
|
---|
1613 | if (!(this.flags & 8) && // avoid infinite self recursion
|
---|
1614 | activeSub !== this) {
|
---|
1615 | batch(this, true);
|
---|
1616 | return true;
|
---|
1617 | }
|
---|
1618 | }
|
---|
1619 | get value() {
|
---|
1620 | const link = this.dep.track({
|
---|
1621 | target: this,
|
---|
1622 | type: "get",
|
---|
1623 | key: "value"
|
---|
1624 | }) ;
|
---|
1625 | refreshComputed(this);
|
---|
1626 | if (link) {
|
---|
1627 | link.version = this.dep.version;
|
---|
1628 | }
|
---|
1629 | return this._value;
|
---|
1630 | }
|
---|
1631 | set value(newValue) {
|
---|
1632 | if (this.setter) {
|
---|
1633 | this.setter(newValue);
|
---|
1634 | } else {
|
---|
1635 | warn("Write operation failed: computed value is readonly");
|
---|
1636 | }
|
---|
1637 | }
|
---|
1638 | }
|
---|
1639 | function computed(getterOrOptions, debugOptions, isSSR = false) {
|
---|
1640 | let getter;
|
---|
1641 | let setter;
|
---|
1642 | if (shared.isFunction(getterOrOptions)) {
|
---|
1643 | getter = getterOrOptions;
|
---|
1644 | } else {
|
---|
1645 | getter = getterOrOptions.get;
|
---|
1646 | setter = getterOrOptions.set;
|
---|
1647 | }
|
---|
1648 | const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
---|
1649 | if (debugOptions && !isSSR) {
|
---|
1650 | cRef.onTrack = debugOptions.onTrack;
|
---|
1651 | cRef.onTrigger = debugOptions.onTrigger;
|
---|
1652 | }
|
---|
1653 | return cRef;
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | const TrackOpTypes = {
|
---|
1657 | "GET": "get",
|
---|
1658 | "HAS": "has",
|
---|
1659 | "ITERATE": "iterate"
|
---|
1660 | };
|
---|
1661 | const TriggerOpTypes = {
|
---|
1662 | "SET": "set",
|
---|
1663 | "ADD": "add",
|
---|
1664 | "DELETE": "delete",
|
---|
1665 | "CLEAR": "clear"
|
---|
1666 | };
|
---|
1667 | const ReactiveFlags = {
|
---|
1668 | "SKIP": "__v_skip",
|
---|
1669 | "IS_REACTIVE": "__v_isReactive",
|
---|
1670 | "IS_READONLY": "__v_isReadonly",
|
---|
1671 | "IS_SHALLOW": "__v_isShallow",
|
---|
1672 | "RAW": "__v_raw",
|
---|
1673 | "IS_REF": "__v_isRef"
|
---|
1674 | };
|
---|
1675 |
|
---|
1676 | const WatchErrorCodes = {
|
---|
1677 | "WATCH_GETTER": 2,
|
---|
1678 | "2": "WATCH_GETTER",
|
---|
1679 | "WATCH_CALLBACK": 3,
|
---|
1680 | "3": "WATCH_CALLBACK",
|
---|
1681 | "WATCH_CLEANUP": 4,
|
---|
1682 | "4": "WATCH_CLEANUP"
|
---|
1683 | };
|
---|
1684 | const INITIAL_WATCHER_VALUE = {};
|
---|
1685 | const cleanupMap = /* @__PURE__ */ new WeakMap();
|
---|
1686 | let activeWatcher = void 0;
|
---|
1687 | function getCurrentWatcher() {
|
---|
1688 | return activeWatcher;
|
---|
1689 | }
|
---|
1690 | function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
|
---|
1691 | if (owner) {
|
---|
1692 | let cleanups = cleanupMap.get(owner);
|
---|
1693 | if (!cleanups) cleanupMap.set(owner, cleanups = []);
|
---|
1694 | cleanups.push(cleanupFn);
|
---|
1695 | } else if (!failSilently) {
|
---|
1696 | warn(
|
---|
1697 | `onWatcherCleanup() was called when there was no active watcher to associate with.`
|
---|
1698 | );
|
---|
1699 | }
|
---|
1700 | }
|
---|
1701 | function watch(source, cb, options = shared.EMPTY_OBJ) {
|
---|
1702 | const { immediate, deep, once, scheduler, augmentJob, call } = options;
|
---|
1703 | const warnInvalidSource = (s) => {
|
---|
1704 | (options.onWarn || warn)(
|
---|
1705 | `Invalid watch source: `,
|
---|
1706 | s,
|
---|
1707 | `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
|
---|
1708 | );
|
---|
1709 | };
|
---|
1710 | const reactiveGetter = (source2) => {
|
---|
1711 | if (deep) return source2;
|
---|
1712 | if (isShallow(source2) || deep === false || deep === 0)
|
---|
1713 | return traverse(source2, 1);
|
---|
1714 | return traverse(source2);
|
---|
1715 | };
|
---|
1716 | let effect;
|
---|
1717 | let getter;
|
---|
1718 | let cleanup;
|
---|
1719 | let boundCleanup;
|
---|
1720 | let forceTrigger = false;
|
---|
1721 | let isMultiSource = false;
|
---|
1722 | if (isRef(source)) {
|
---|
1723 | getter = () => source.value;
|
---|
1724 | forceTrigger = isShallow(source);
|
---|
1725 | } else if (isReactive(source)) {
|
---|
1726 | getter = () => reactiveGetter(source);
|
---|
1727 | forceTrigger = true;
|
---|
1728 | } else if (shared.isArray(source)) {
|
---|
1729 | isMultiSource = true;
|
---|
1730 | forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
---|
1731 | getter = () => source.map((s) => {
|
---|
1732 | if (isRef(s)) {
|
---|
1733 | return s.value;
|
---|
1734 | } else if (isReactive(s)) {
|
---|
1735 | return reactiveGetter(s);
|
---|
1736 | } else if (shared.isFunction(s)) {
|
---|
1737 | return call ? call(s, 2) : s();
|
---|
1738 | } else {
|
---|
1739 | warnInvalidSource(s);
|
---|
1740 | }
|
---|
1741 | });
|
---|
1742 | } else if (shared.isFunction(source)) {
|
---|
1743 | if (cb) {
|
---|
1744 | getter = call ? () => call(source, 2) : source;
|
---|
1745 | } else {
|
---|
1746 | getter = () => {
|
---|
1747 | if (cleanup) {
|
---|
1748 | pauseTracking();
|
---|
1749 | try {
|
---|
1750 | cleanup();
|
---|
1751 | } finally {
|
---|
1752 | resetTracking();
|
---|
1753 | }
|
---|
1754 | }
|
---|
1755 | const currentEffect = activeWatcher;
|
---|
1756 | activeWatcher = effect;
|
---|
1757 | try {
|
---|
1758 | return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
|
---|
1759 | } finally {
|
---|
1760 | activeWatcher = currentEffect;
|
---|
1761 | }
|
---|
1762 | };
|
---|
1763 | }
|
---|
1764 | } else {
|
---|
1765 | getter = shared.NOOP;
|
---|
1766 | warnInvalidSource(source);
|
---|
1767 | }
|
---|
1768 | if (cb && deep) {
|
---|
1769 | const baseGetter = getter;
|
---|
1770 | const depth = deep === true ? Infinity : deep;
|
---|
1771 | getter = () => traverse(baseGetter(), depth);
|
---|
1772 | }
|
---|
1773 | const scope = getCurrentScope();
|
---|
1774 | const watchHandle = () => {
|
---|
1775 | effect.stop();
|
---|
1776 | if (scope && scope.active) {
|
---|
1777 | shared.remove(scope.effects, effect);
|
---|
1778 | }
|
---|
1779 | };
|
---|
1780 | if (once && cb) {
|
---|
1781 | const _cb = cb;
|
---|
1782 | cb = (...args) => {
|
---|
1783 | _cb(...args);
|
---|
1784 | watchHandle();
|
---|
1785 | };
|
---|
1786 | }
|
---|
1787 | let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
---|
1788 | const job = (immediateFirstRun) => {
|
---|
1789 | if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
|
---|
1790 | return;
|
---|
1791 | }
|
---|
1792 | if (cb) {
|
---|
1793 | const newValue = effect.run();
|
---|
1794 | if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue))) {
|
---|
1795 | if (cleanup) {
|
---|
1796 | cleanup();
|
---|
1797 | }
|
---|
1798 | const currentWatcher = activeWatcher;
|
---|
1799 | activeWatcher = effect;
|
---|
1800 | try {
|
---|
1801 | const args = [
|
---|
1802 | newValue,
|
---|
1803 | // pass undefined as the old value when it's changed for the first time
|
---|
1804 | oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
---|
1805 | boundCleanup
|
---|
1806 | ];
|
---|
1807 | call ? call(cb, 3, args) : (
|
---|
1808 | // @ts-expect-error
|
---|
1809 | cb(...args)
|
---|
1810 | );
|
---|
1811 | oldValue = newValue;
|
---|
1812 | } finally {
|
---|
1813 | activeWatcher = currentWatcher;
|
---|
1814 | }
|
---|
1815 | }
|
---|
1816 | } else {
|
---|
1817 | effect.run();
|
---|
1818 | }
|
---|
1819 | };
|
---|
1820 | if (augmentJob) {
|
---|
1821 | augmentJob(job);
|
---|
1822 | }
|
---|
1823 | effect = new ReactiveEffect(getter);
|
---|
1824 | effect.scheduler = scheduler ? () => scheduler(job, false) : job;
|
---|
1825 | boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
|
---|
1826 | cleanup = effect.onStop = () => {
|
---|
1827 | const cleanups = cleanupMap.get(effect);
|
---|
1828 | if (cleanups) {
|
---|
1829 | if (call) {
|
---|
1830 | call(cleanups, 4);
|
---|
1831 | } else {
|
---|
1832 | for (const cleanup2 of cleanups) cleanup2();
|
---|
1833 | }
|
---|
1834 | cleanupMap.delete(effect);
|
---|
1835 | }
|
---|
1836 | };
|
---|
1837 | {
|
---|
1838 | effect.onTrack = options.onTrack;
|
---|
1839 | effect.onTrigger = options.onTrigger;
|
---|
1840 | }
|
---|
1841 | if (cb) {
|
---|
1842 | if (immediate) {
|
---|
1843 | job(true);
|
---|
1844 | } else {
|
---|
1845 | oldValue = effect.run();
|
---|
1846 | }
|
---|
1847 | } else if (scheduler) {
|
---|
1848 | scheduler(job.bind(null, true), true);
|
---|
1849 | } else {
|
---|
1850 | effect.run();
|
---|
1851 | }
|
---|
1852 | watchHandle.pause = effect.pause.bind(effect);
|
---|
1853 | watchHandle.resume = effect.resume.bind(effect);
|
---|
1854 | watchHandle.stop = watchHandle;
|
---|
1855 | return watchHandle;
|
---|
1856 | }
|
---|
1857 | function traverse(value, depth = Infinity, seen) {
|
---|
1858 | if (depth <= 0 || !shared.isObject(value) || value["__v_skip"]) {
|
---|
1859 | return value;
|
---|
1860 | }
|
---|
1861 | seen = seen || /* @__PURE__ */ new Set();
|
---|
1862 | if (seen.has(value)) {
|
---|
1863 | return value;
|
---|
1864 | }
|
---|
1865 | seen.add(value);
|
---|
1866 | depth--;
|
---|
1867 | if (isRef(value)) {
|
---|
1868 | traverse(value.value, depth, seen);
|
---|
1869 | } else if (shared.isArray(value)) {
|
---|
1870 | for (let i = 0; i < value.length; i++) {
|
---|
1871 | traverse(value[i], depth, seen);
|
---|
1872 | }
|
---|
1873 | } else if (shared.isSet(value) || shared.isMap(value)) {
|
---|
1874 | value.forEach((v) => {
|
---|
1875 | traverse(v, depth, seen);
|
---|
1876 | });
|
---|
1877 | } else if (shared.isPlainObject(value)) {
|
---|
1878 | for (const key in value) {
|
---|
1879 | traverse(value[key], depth, seen);
|
---|
1880 | }
|
---|
1881 | for (const key of Object.getOwnPropertySymbols(value)) {
|
---|
1882 | if (Object.prototype.propertyIsEnumerable.call(value, key)) {
|
---|
1883 | traverse(value[key], depth, seen);
|
---|
1884 | }
|
---|
1885 | }
|
---|
1886 | }
|
---|
1887 | return value;
|
---|
1888 | }
|
---|
1889 |
|
---|
1890 | exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
|
---|
1891 | exports.EffectFlags = EffectFlags;
|
---|
1892 | exports.EffectScope = EffectScope;
|
---|
1893 | exports.ITERATE_KEY = ITERATE_KEY;
|
---|
1894 | exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
|
---|
1895 | exports.ReactiveEffect = ReactiveEffect;
|
---|
1896 | exports.ReactiveFlags = ReactiveFlags;
|
---|
1897 | exports.TrackOpTypes = TrackOpTypes;
|
---|
1898 | exports.TriggerOpTypes = TriggerOpTypes;
|
---|
1899 | exports.WatchErrorCodes = WatchErrorCodes;
|
---|
1900 | exports.computed = computed;
|
---|
1901 | exports.customRef = customRef;
|
---|
1902 | exports.effect = effect;
|
---|
1903 | exports.effectScope = effectScope;
|
---|
1904 | exports.enableTracking = enableTracking;
|
---|
1905 | exports.getCurrentScope = getCurrentScope;
|
---|
1906 | exports.getCurrentWatcher = getCurrentWatcher;
|
---|
1907 | exports.isProxy = isProxy;
|
---|
1908 | exports.isReactive = isReactive;
|
---|
1909 | exports.isReadonly = isReadonly;
|
---|
1910 | exports.isRef = isRef;
|
---|
1911 | exports.isShallow = isShallow;
|
---|
1912 | exports.markRaw = markRaw;
|
---|
1913 | exports.onEffectCleanup = onEffectCleanup;
|
---|
1914 | exports.onScopeDispose = onScopeDispose;
|
---|
1915 | exports.onWatcherCleanup = onWatcherCleanup;
|
---|
1916 | exports.pauseTracking = pauseTracking;
|
---|
1917 | exports.proxyRefs = proxyRefs;
|
---|
1918 | exports.reactive = reactive;
|
---|
1919 | exports.reactiveReadArray = reactiveReadArray;
|
---|
1920 | exports.readonly = readonly;
|
---|
1921 | exports.ref = ref;
|
---|
1922 | exports.resetTracking = resetTracking;
|
---|
1923 | exports.shallowReactive = shallowReactive;
|
---|
1924 | exports.shallowReadArray = shallowReadArray;
|
---|
1925 | exports.shallowReadonly = shallowReadonly;
|
---|
1926 | exports.shallowRef = shallowRef;
|
---|
1927 | exports.stop = stop;
|
---|
1928 | exports.toRaw = toRaw;
|
---|
1929 | exports.toReactive = toReactive;
|
---|
1930 | exports.toReadonly = toReadonly;
|
---|
1931 | exports.toRef = toRef;
|
---|
1932 | exports.toRefs = toRefs;
|
---|
1933 | exports.toValue = toValue;
|
---|
1934 | exports.track = track;
|
---|
1935 | exports.traverse = traverse;
|
---|
1936 | exports.trigger = trigger;
|
---|
1937 | exports.triggerRef = triggerRef;
|
---|
1938 | exports.unref = unref;
|
---|
1939 | exports.watch = watch;
|
---|