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