@torpor/view 1.3.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Effect-Bp-BIDDm.d.cts → Effect-Bi_nt6cx.d.cts} +16 -3
- package/dist/Effect-Bi_nt6cx.d.cts.map +1 -0
- package/dist/{Effect-VsIY2vPx.d.mts → Effect-Bi_nt6cx.d.mts} +16 -3
- package/dist/Effect-Bi_nt6cx.d.mts.map +1 -0
- package/dist/ListItemSpec-DFkYr2TE.d.cts +28 -0
- package/dist/ListItemSpec-DFkYr2TE.d.cts.map +1 -0
- package/dist/ListItemSpec-DFkYr2TE.d.mts +28 -0
- package/dist/ListItemSpec-DFkYr2TE.d.mts.map +1 -0
- package/dist/{AsyncOptions-BDtArmeL.d.mts → WatchOptions--xq-Gn4e.d.cts} +77 -4
- package/dist/WatchOptions--xq-Gn4e.d.cts.map +1 -0
- package/dist/{AsyncOptions-C_7mWR6F.d.cts → WatchOptions-DWF4EqB6.d.mts} +77 -4
- package/dist/WatchOptions-DWF4EqB6.d.mts.map +1 -0
- package/dist/compile.cjs +1399 -406
- package/dist/compile.d.cts +26 -12
- package/dist/compile.d.cts.map +1 -1
- package/dist/compile.d.mts +26 -12
- package/dist/compile.d.mts.map +1 -1
- package/dist/compile.mjs +1399 -406
- package/dist/compile.mjs.map +1 -1
- package/dist/dev.cjs +101 -51
- package/dist/dev.d.cts +33 -2
- package/dist/dev.d.cts.map +1 -1
- package/dist/dev.d.mts +33 -2
- package/dist/dev.d.mts.map +1 -1
- package/dist/dev.mjs +51 -2
- package/dist/dev.mjs.map +1 -1
- package/dist/{fromWebSocket-ERhd9KZR.mjs → fromWebSocket-B22DIys7.mjs} +11 -2
- package/dist/fromWebSocket-B22DIys7.mjs.map +1 -0
- package/dist/{fromWebSocket-Cdoghvmh.cjs → fromWebSocket-C56rkQpZ.cjs} +15 -0
- package/dist/index.cjs +605 -266
- package/dist/index.d.cts +36 -129
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +36 -129
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +593 -255
- package/dist/index.mjs.map +1 -1
- package/dist/runtime.iife.js +1 -1
- package/dist/ssr.cjs +122 -22
- package/dist/ssr.d.cts +46 -12
- package/dist/ssr.d.cts.map +1 -1
- package/dist/ssr.d.mts +46 -12
- package/dist/ssr.d.mts.map +1 -1
- package/dist/ssr.mjs +121 -23
- package/dist/ssr.mjs.map +1 -1
- package/dist/titleWarning-BMjLAXpn.mjs +72 -0
- package/dist/titleWarning-BMjLAXpn.mjs.map +1 -0
- package/dist/titleWarning-DXp4fK7q.cjs +87 -0
- package/package.json +2 -1
- package/dist/AsyncOptions-BDtArmeL.d.mts.map +0 -1
- package/dist/AsyncOptions-C_7mWR6F.d.cts.map +0 -1
- package/dist/Cleanup-D0wvGW5d.d.cts +0 -9
- package/dist/Cleanup-D0wvGW5d.d.cts.map +0 -1
- package/dist/Cleanup-D0wvGW5d.d.mts +0 -9
- package/dist/Cleanup-D0wvGW5d.d.mts.map +0 -1
- package/dist/Effect-Bp-BIDDm.d.cts.map +0 -1
- package/dist/Effect-VsIY2vPx.d.mts.map +0 -1
- package/dist/devContext-BulTn3U5.cjs +0 -27
- package/dist/devContext-ZNsPyOgB.mjs +0 -24
- package/dist/devContext-ZNsPyOgB.mjs.map +0 -1
- package/dist/fromWebSocket-ERhd9KZR.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as buildStyles, c as
|
|
1
|
+
import { n as setDevSlotDepth, r as devContext } from "./titleWarning-BMjLAXpn.mjs";
|
|
2
|
+
import { a as buildStyles, c as proxyArrayContentSymbol, i as formatText, l as proxyDataSymbol, n as fromServer, o as buildClasses, r as fromElement, s as $unwrap, t as fromWebSocket, u as proxyKeysSymbol } from "./fromWebSocket-B22DIys7.mjs";
|
|
3
3
|
//#region src/render/context.ts
|
|
4
4
|
const CONTEXT_SYMBOL = Symbol.for("torp.Context");
|
|
5
5
|
const context = globalThis[CONTEXT_SYMBOL] ??= {
|
|
@@ -7,7 +7,6 @@ const context = globalThis[CONTEXT_SYMBOL] ??= {
|
|
|
7
7
|
previousEffect: null,
|
|
8
8
|
extent: 0,
|
|
9
9
|
batch: 0,
|
|
10
|
-
batchOperation: 0,
|
|
11
10
|
registerComputed: null,
|
|
12
11
|
effectsToRun: [],
|
|
13
12
|
firstSignalToUpdate: null,
|
|
@@ -23,98 +22,11 @@ const context = globalThis[CONTEXT_SYMBOL] ??= {
|
|
|
23
22
|
mountEffects: [],
|
|
24
23
|
stashedEvents: [],
|
|
25
24
|
stashedAnimations: [],
|
|
25
|
+
runAnimations: null,
|
|
26
26
|
hydrationNode: null,
|
|
27
27
|
serverValues: null
|
|
28
28
|
};
|
|
29
29
|
//#endregion
|
|
30
|
-
//#region src/render/addAnimation.ts
|
|
31
|
-
function addAnimation(el, entry, exit) {
|
|
32
|
-
context.stashedAnimations.push({
|
|
33
|
-
region: context.activeRegion,
|
|
34
|
-
el,
|
|
35
|
-
in: entry,
|
|
36
|
-
out: exit
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/render/addEvent.ts
|
|
41
|
-
function addEvent(el, type, listener) {
|
|
42
|
-
if (listener !== void 0 && listener !== null) context.stashedEvents.push({
|
|
43
|
-
el,
|
|
44
|
-
type,
|
|
45
|
-
listener
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/render/isTextNode.ts
|
|
50
|
-
function isTextNode(node) {
|
|
51
|
-
return node.nodeType === 3;
|
|
52
|
-
}
|
|
53
|
-
const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
|
|
54
|
-
/**
|
|
55
|
-
* Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
|
|
56
|
-
* when the server recorded the branch it rendered).
|
|
57
|
-
*/
|
|
58
|
-
function isHydrationBreak(data) {
|
|
59
|
-
return HYDRATION_BREAK_REGEX.test(data);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The branch index encoded in a `^<index>` branch-break marker, or `undefined`
|
|
63
|
-
* for a plain `^` marker (e.g. from `@for`, which has no branch index).
|
|
64
|
-
*/
|
|
65
|
-
function hydrationBreakIndex(data) {
|
|
66
|
-
if (!data.startsWith("^") || data.length === 1) return;
|
|
67
|
-
const index = Number(data.slice(1));
|
|
68
|
-
return Number.isNaN(index) ? void 0 : index;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/render/isCommentNode.ts
|
|
72
|
-
function isCommentNode(node) {
|
|
73
|
-
return node.nodeType === 8;
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/render/nodeCheckHydrationBreak.ts
|
|
77
|
-
/**
|
|
78
|
-
* When hydrating, removes and skips hydration comments that are inserted at the
|
|
79
|
-
* start of branches and used to split up text nodes that would otherwise be
|
|
80
|
-
* joined in HTML.
|
|
81
|
-
*
|
|
82
|
-
* @param node The node to check and maybe skip.
|
|
83
|
-
* @returns The next node.
|
|
84
|
-
*/
|
|
85
|
-
function nodeCheckHydrationBreak(node) {
|
|
86
|
-
if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
|
|
87
|
-
let comment = node;
|
|
88
|
-
node = node.nextSibling;
|
|
89
|
-
comment.remove();
|
|
90
|
-
}
|
|
91
|
-
context.hydrationNode = node;
|
|
92
|
-
return node;
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/render/nodeNext.ts
|
|
96
|
-
/**
|
|
97
|
-
* Gets the next sibling of a node.
|
|
98
|
-
*
|
|
99
|
-
* When hydrating, sets the hydration node.
|
|
100
|
-
*
|
|
101
|
-
* @param node The node.
|
|
102
|
-
* @param text Whether we require a text node.
|
|
103
|
-
*/
|
|
104
|
-
function nodeNext(node, text = false) {
|
|
105
|
-
if (context.hydrationNode !== null) {
|
|
106
|
-
if (text && isTextNode(node)) return node;
|
|
107
|
-
let next = nodeCheckHydrationBreak(node.nextSibling);
|
|
108
|
-
while (!text && next !== null && isTextNode(next) && next.textContent?.trim() === "") next = nodeCheckHydrationBreak(next.nextSibling);
|
|
109
|
-
if (!text && next !== null && next.nodeName === "TBODY" && next.firstChild && isTextNode(node)) {
|
|
110
|
-
next = next.firstChild;
|
|
111
|
-
context.hydrationNode = next;
|
|
112
|
-
}
|
|
113
|
-
return next;
|
|
114
|
-
}
|
|
115
|
-
return node.nextSibling;
|
|
116
|
-
}
|
|
117
|
-
//#endregion
|
|
118
30
|
//#region src/dev/devAssert.ts
|
|
119
31
|
/**
|
|
120
32
|
* Throws when `condition` is false — but only when dev mode is enabled (the
|
|
@@ -362,17 +274,30 @@ function resubscribeSuspendSources(effect) {
|
|
|
362
274
|
context.activeTarget = oldActive;
|
|
363
275
|
}
|
|
364
276
|
/**
|
|
277
|
+
* How many times a single effect may run in one flush before it's treated as
|
|
278
|
+
* a cycle. Deliberately generous: the limit is per effect, so a large flush
|
|
279
|
+
* (hundreds of effects reacting to one change) is fine — only an effect that
|
|
280
|
+
* keeps re-queuing itself hits it.
|
|
281
|
+
*/
|
|
282
|
+
const MAX_EFFECT_RUNS_PER_FLUSH = 100;
|
|
283
|
+
/**
|
|
365
284
|
* Runs the effects that have been collected during the batch.
|
|
366
285
|
*/
|
|
367
286
|
function triggerEffects() {
|
|
368
287
|
let unhandledError = null;
|
|
288
|
+
let cycle = false;
|
|
369
289
|
const queue = context.effectsToRun;
|
|
370
290
|
queue.sort((a, b) => a.seq - b.seq);
|
|
371
291
|
for (let i = 0; i < queue.length; i++) {
|
|
372
292
|
const effect = queue[i];
|
|
373
|
-
context.batchOperation++;
|
|
374
293
|
effect.queued = false;
|
|
375
294
|
if (effect.destroyed) continue;
|
|
295
|
+
const runs = (effect.flushRuns ?? 0) + 1;
|
|
296
|
+
effect.flushRuns = runs;
|
|
297
|
+
if (runs > MAX_EFFECT_RUNS_PER_FLUSH) {
|
|
298
|
+
cycle = true;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
376
301
|
try {
|
|
377
302
|
checkEffect(effect);
|
|
378
303
|
} catch (err) {
|
|
@@ -388,7 +313,10 @@ function triggerEffects() {
|
|
|
388
313
|
}
|
|
389
314
|
}
|
|
390
315
|
}
|
|
391
|
-
for (let effect of queue)
|
|
316
|
+
for (let effect of queue) {
|
|
317
|
+
effect.queued = false;
|
|
318
|
+
effect.flushRuns = 0;
|
|
319
|
+
}
|
|
392
320
|
context.effectsToRun = [];
|
|
393
321
|
let signal = context.firstSignalToUpdate;
|
|
394
322
|
context.firstSignalToUpdate = null;
|
|
@@ -398,6 +326,7 @@ function triggerEffects() {
|
|
|
398
326
|
signal.nextSignalToUpdate = null;
|
|
399
327
|
signal = nextSignal;
|
|
400
328
|
}
|
|
329
|
+
if (cycle) throw new Error("Cycle detected");
|
|
401
330
|
if (unhandledError !== null) throw unhandledError.error;
|
|
402
331
|
}
|
|
403
332
|
//#endregion
|
|
@@ -412,7 +341,6 @@ function batchEnd() {
|
|
|
412
341
|
triggerEffects();
|
|
413
342
|
} finally {
|
|
414
343
|
context.batch = 0;
|
|
415
|
-
context.batchOperation = 0;
|
|
416
344
|
context.previousEffect = null;
|
|
417
345
|
}
|
|
418
346
|
}
|
|
@@ -490,59 +418,6 @@ function $run(fn, name, options) {
|
|
|
490
418
|
return effect;
|
|
491
419
|
}
|
|
492
420
|
//#endregion
|
|
493
|
-
//#region src/watch/$peek.ts
|
|
494
|
-
/**
|
|
495
|
-
* Runs a function without tracking the reactive values it reads: `$watch`'d
|
|
496
|
-
* state accessed inside `fn` does not become a dependency of the currently
|
|
497
|
-
* running effect or computed. Useful for reading state inside an effect
|
|
498
|
-
* without re-running it when that state changes.
|
|
499
|
-
*
|
|
500
|
-
* @param fn The function to run untracked.
|
|
501
|
-
*/
|
|
502
|
-
function $peek(fn) {
|
|
503
|
-
const oldActiveTarget = context.activeTarget;
|
|
504
|
-
context.activeTarget = null;
|
|
505
|
-
const result = fn();
|
|
506
|
-
context.activeTarget = oldActiveTarget;
|
|
507
|
-
return result;
|
|
508
|
-
}
|
|
509
|
-
//#endregion
|
|
510
|
-
//#region src/watch/flushMountEffects.ts
|
|
511
|
-
/**
|
|
512
|
-
* Runs the collected `$onmount`/`onmount` callbacks — once, after the
|
|
513
|
-
* component's markup has been added to the DOM (or, when hydrating, after
|
|
514
|
-
* hydration is complete). Multiple callbacks run in the order they were
|
|
515
|
-
* added.
|
|
516
|
-
*
|
|
517
|
-
* Each callback becomes an effect with `isMountEffect` set, so the keyed-list
|
|
518
|
-
* reconciler's force-rerun path (`rerunRegionEffects`) skips it. Its body
|
|
519
|
-
* also runs untracked: mount callbacks are once-only, so reactive reads
|
|
520
|
-
* inside them do not subscribe. In dev builds a tracked pass warns when a
|
|
521
|
-
* callback reads reactive state, since that is almost always a mistake — the
|
|
522
|
-
* reactive part should be wrapped in `$run`.
|
|
523
|
-
*/
|
|
524
|
-
function flushMountEffects() {
|
|
525
|
-
if (context.mountEffects.length === 0) return;
|
|
526
|
-
const activeRegion = context.activeRegion;
|
|
527
|
-
for (let effect of context.mountEffects) {
|
|
528
|
-
context.activeRegion = effect.region;
|
|
529
|
-
$run(() => runMountCallback(effect.fn), void 0, { isMountEffect: true });
|
|
530
|
-
}
|
|
531
|
-
context.activeRegion = activeRegion;
|
|
532
|
-
context.mountEffects.length = 0;
|
|
533
|
-
}
|
|
534
|
-
function runMountCallback(fn) {
|
|
535
|
-
if (!devContext.enabled) return $peek(fn);
|
|
536
|
-
const result = fn();
|
|
537
|
-
const effect = context.activeTarget;
|
|
538
|
-
if (effect !== null && effect.type === 2 && effect.firstSource !== null) {
|
|
539
|
-
console.warn("[torpor] A $onmount/onmount callback read reactive state, but mount callbacks run only once and will not re-run. Wrap the reactive part in $run(), e.g. $onmount(() => { $run(() => ...); });");
|
|
540
|
-
deactivateSources(effect);
|
|
541
|
-
clearSources(effect);
|
|
542
|
-
}
|
|
543
|
-
return result;
|
|
544
|
-
}
|
|
545
|
-
//#endregion
|
|
546
421
|
//#region src/render/animate.ts
|
|
547
422
|
/**
|
|
548
423
|
* Parses a transform function argument as a number, returning null for
|
|
@@ -697,13 +572,183 @@ async function animate(el, enter, keyframes, options) {
|
|
|
697
572
|
await animation.finished;
|
|
698
573
|
}
|
|
699
574
|
//#endregion
|
|
575
|
+
//#region src/render/runAnimations.ts
|
|
576
|
+
/**
|
|
577
|
+
* Runs the animations stashed by `addAnimation` (`context.stashedAnimations`)
|
|
578
|
+
* when their element has been added to the DOM.
|
|
579
|
+
*
|
|
580
|
+
* Kept in its own module (imported only by `addAnimation`) rather than in
|
|
581
|
+
* `runMountSideEffects`: this way a component that never uses a
|
|
582
|
+
* `transition`/`transition-in`/`transition-out` attribute never imports
|
|
583
|
+
* `t_animate`, so this module — and `animate.ts` with it — is tree-shaken
|
|
584
|
+
* out of the bundle. `runMountSideEffects` reaches the runner through
|
|
585
|
+
* `context.runAnimations`, which stays null until `addAnimation` installs it.
|
|
586
|
+
*/
|
|
587
|
+
function runAnimations() {
|
|
588
|
+
for (let animation of context.stashedAnimations) {
|
|
589
|
+
context.activeRegion = animation.region;
|
|
590
|
+
$run(function runMountSideEffectsAnimation() {
|
|
591
|
+
if (animation.in !== void 0) animate(animation.el, true, animation.in.keyframes, animation.in.options);
|
|
592
|
+
if (animation.out !== void 0) return () => {
|
|
593
|
+
animate(animation.el, false, animation.out.keyframes, animation.out.options);
|
|
594
|
+
};
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
context.stashedAnimations.length = 0;
|
|
598
|
+
}
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region src/render/addAnimation.ts
|
|
601
|
+
function addAnimation(el, entry, exit) {
|
|
602
|
+
context.runAnimations ??= runAnimations;
|
|
603
|
+
context.stashedAnimations.push({
|
|
604
|
+
region: context.activeRegion,
|
|
605
|
+
el,
|
|
606
|
+
in: entry,
|
|
607
|
+
out: exit
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region src/render/addEvent.ts
|
|
612
|
+
function addEvent(el, type, listener) {
|
|
613
|
+
if (listener !== void 0 && listener !== null) context.stashedEvents.push({
|
|
614
|
+
el,
|
|
615
|
+
type,
|
|
616
|
+
listener
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/render/isTextNode.ts
|
|
621
|
+
function isTextNode(node) {
|
|
622
|
+
return node.nodeType === 3;
|
|
623
|
+
}
|
|
624
|
+
const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
|
|
625
|
+
/**
|
|
626
|
+
* Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
|
|
627
|
+
* when the server recorded the branch it rendered).
|
|
628
|
+
*/
|
|
629
|
+
function isHydrationBreak(data) {
|
|
630
|
+
return HYDRATION_BREAK_REGEX.test(data);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* The branch index encoded in a `^<index>` branch-break marker, or `undefined`
|
|
634
|
+
* for a plain `^` marker (e.g. from `@for`, which has no branch index).
|
|
635
|
+
*/
|
|
636
|
+
function hydrationBreakIndex(data) {
|
|
637
|
+
if (!data.startsWith("^") || data.length === 1) return;
|
|
638
|
+
const index = Number(data.slice(1));
|
|
639
|
+
return Number.isNaN(index) ? void 0 : index;
|
|
640
|
+
}
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region src/render/isCommentNode.ts
|
|
643
|
+
function isCommentNode(node) {
|
|
644
|
+
return node.nodeType === 8;
|
|
645
|
+
}
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region src/render/nodeCheckHydrationBreak.ts
|
|
648
|
+
/**
|
|
649
|
+
* When hydrating, removes and skips hydration comments that are inserted at the
|
|
650
|
+
* start of branches and used to split up text nodes that would otherwise be
|
|
651
|
+
* joined in HTML.
|
|
652
|
+
*
|
|
653
|
+
* @param node The node to check and maybe skip.
|
|
654
|
+
* @returns The next node.
|
|
655
|
+
*/
|
|
656
|
+
function nodeCheckHydrationBreak(node) {
|
|
657
|
+
if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
|
|
658
|
+
let comment = node;
|
|
659
|
+
node = node.nextSibling;
|
|
660
|
+
comment.remove();
|
|
661
|
+
}
|
|
662
|
+
context.hydrationNode = node;
|
|
663
|
+
return node;
|
|
664
|
+
}
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region src/render/nodeNext.ts
|
|
667
|
+
/**
|
|
668
|
+
* Gets the next sibling of a node.
|
|
669
|
+
*
|
|
670
|
+
* When hydrating, sets the hydration node.
|
|
671
|
+
*
|
|
672
|
+
* @param node The node.
|
|
673
|
+
* @param text Whether we require a text node.
|
|
674
|
+
*/
|
|
675
|
+
function nodeNext(node, text = false) {
|
|
676
|
+
if (context.hydrationNode !== null) {
|
|
677
|
+
if (text && isTextNode(node)) return node;
|
|
678
|
+
let next = nodeCheckHydrationBreak(node.nextSibling);
|
|
679
|
+
while (!text && next !== null && isTextNode(next) && next.textContent?.trim() === "") next = nodeCheckHydrationBreak(next.nextSibling);
|
|
680
|
+
if (!text && next !== null && next.nodeName === "TBODY" && next.firstChild && isTextNode(node)) {
|
|
681
|
+
next = next.firstChild;
|
|
682
|
+
context.hydrationNode = next;
|
|
683
|
+
}
|
|
684
|
+
return next;
|
|
685
|
+
}
|
|
686
|
+
return node.nextSibling;
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/watch/$peek.ts
|
|
690
|
+
/**
|
|
691
|
+
* Runs a function without tracking the reactive values it reads: `$watch`'d
|
|
692
|
+
* state accessed inside `fn` does not become a dependency of the currently
|
|
693
|
+
* running effect or computed. Useful for reading state inside an effect
|
|
694
|
+
* without re-running it when that state changes.
|
|
695
|
+
*
|
|
696
|
+
* @param fn The function to run untracked.
|
|
697
|
+
*/
|
|
698
|
+
function $peek(fn) {
|
|
699
|
+
const oldActiveTarget = context.activeTarget;
|
|
700
|
+
context.activeTarget = null;
|
|
701
|
+
try {
|
|
702
|
+
return fn();
|
|
703
|
+
} finally {
|
|
704
|
+
context.activeTarget = oldActiveTarget;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/watch/flushMountEffects.ts
|
|
709
|
+
/**
|
|
710
|
+
* Runs the collected `$onmount`/`onmount` callbacks — once, after the
|
|
711
|
+
* component's markup has been added to the DOM (or, when hydrating, after
|
|
712
|
+
* hydration is complete). Multiple callbacks run in the order they were
|
|
713
|
+
* added.
|
|
714
|
+
*
|
|
715
|
+
* Each callback becomes an effect with `isMountEffect` set, so the keyed-list
|
|
716
|
+
* reconciler's force-rerun path (`rerunRegionEffects`) skips it. Its body
|
|
717
|
+
* also runs untracked: mount callbacks are once-only, so reactive reads
|
|
718
|
+
* inside them do not subscribe. In dev builds a tracked pass warns when a
|
|
719
|
+
* callback reads reactive state, since that is almost always a mistake — the
|
|
720
|
+
* reactive part should be wrapped in `$run`.
|
|
721
|
+
*/
|
|
722
|
+
function flushMountEffects() {
|
|
723
|
+
if (context.mountEffects.length === 0) return;
|
|
724
|
+
const activeRegion = context.activeRegion;
|
|
725
|
+
for (let effect of context.mountEffects) {
|
|
726
|
+
context.activeRegion = effect.region;
|
|
727
|
+
$run(() => runMountCallback(effect.fn), void 0, { isMountEffect: true });
|
|
728
|
+
}
|
|
729
|
+
context.activeRegion = activeRegion;
|
|
730
|
+
context.mountEffects.length = 0;
|
|
731
|
+
}
|
|
732
|
+
function runMountCallback(fn) {
|
|
733
|
+
if (!devContext.enabled) return $peek(fn);
|
|
734
|
+
const result = fn();
|
|
735
|
+
const effect = context.activeTarget;
|
|
736
|
+
if (effect !== null && effect.type === 2 && effect.firstSource !== null) {
|
|
737
|
+
console.warn("[torpor] A $onmount/onmount callback read reactive state, but mount callbacks run only once and will not re-run. Wrap the reactive part in $run(), e.g. $onmount(() => { $run(() => ...); });");
|
|
738
|
+
deactivateSources(effect);
|
|
739
|
+
clearSources(effect);
|
|
740
|
+
}
|
|
741
|
+
return result;
|
|
742
|
+
}
|
|
743
|
+
//#endregion
|
|
700
744
|
//#region src/render/delegatedEvents.ts
|
|
701
745
|
/**
|
|
702
746
|
* Event delegation.
|
|
703
747
|
*
|
|
704
748
|
* For event types in `DELEGATED_EVENT_TYPES` (all natively bubbling), we
|
|
705
|
-
* register a single listener on `
|
|
706
|
-
*
|
|
749
|
+
* register a single listener on each element's `ownerDocument` per type and
|
|
750
|
+
* dispatch by walking up from the event target, running each ancestor's
|
|
751
|
+
* stashed handler in turn until one calls `stopPropagation()`.
|
|
707
752
|
* This replaces per-element `addEventListener` for delegated types.
|
|
708
753
|
*
|
|
709
754
|
* Why: in the js-framework-bench row template, every `<tr>` clones two `<a>`
|
|
@@ -723,6 +768,22 @@ async function animate(el, enter, keyframes, options) {
|
|
|
723
768
|
* Non-bubbling events (`focus`, `blur`, `scroll`, `load`, `error`, `abort`,
|
|
724
769
|
* `unload`, `resize`, etc.) bypass delegation and use direct
|
|
725
770
|
* `addEventListener` on the element, preserving native semantics.
|
|
771
|
+
*
|
|
772
|
+
* Limitations (inherent to delegating to the document, same trade-off as
|
|
773
|
+
* React and Solid):
|
|
774
|
+
*
|
|
775
|
+
* - A native `stopPropagation()` — third-party code, or a listener added in
|
|
776
|
+
* `$onmount` — stops the event before it reaches the document, so the
|
|
777
|
+
* delegated handlers won't run. Torpor handlers can still call
|
|
778
|
+
* `stopPropagation()` among themselves (that's what ends the walk below).
|
|
779
|
+
* - `stopPropagation()` in a delegated handler runs after the native event
|
|
780
|
+
* has finished bubbling, so it only affects other delegated handlers, not
|
|
781
|
+
* native listeners.
|
|
782
|
+
*
|
|
783
|
+
* Shadow DOM and multiple documents are supported: the listener lives on the
|
|
784
|
+
* element's `ownerDocument` (so components mounted into an iframe or popup
|
|
785
|
+
* document work), and the path comes from `composedPath()` (so the listener
|
|
786
|
+
* sees the real target inside a shadow root, not the retargeted host).
|
|
726
787
|
*/
|
|
727
788
|
const DELEGATED_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
728
789
|
"auxclick",
|
|
@@ -770,10 +831,12 @@ function isDelegatedEventType(type) {
|
|
|
770
831
|
const DELEGATE_PREFIX = "torp.$$";
|
|
771
832
|
const DELEGATE_REGISTERED = Symbol.for("torp.delegated.registered");
|
|
772
833
|
function delegatedHandler(event) {
|
|
773
|
-
let node = event.target;
|
|
774
834
|
const stopAt = event.currentTarget;
|
|
775
835
|
const key = DELEGATE_PREFIX + event.type;
|
|
776
|
-
|
|
836
|
+
const path = event.composedPath();
|
|
837
|
+
for (let i = 0; i < path.length; i++) {
|
|
838
|
+
const node = path[i];
|
|
839
|
+
if (node === stopAt) break;
|
|
777
840
|
const handler = node[key];
|
|
778
841
|
if (handler !== void 0) {
|
|
779
842
|
Object.defineProperty(event, "currentTarget", {
|
|
@@ -786,29 +849,28 @@ function delegatedHandler(event) {
|
|
|
786
849
|
} finally {
|
|
787
850
|
delete event.currentTarget;
|
|
788
851
|
}
|
|
789
|
-
return;
|
|
852
|
+
if (event.cancelBubble) return;
|
|
790
853
|
}
|
|
791
|
-
node = node.parentNode;
|
|
792
854
|
}
|
|
793
855
|
}
|
|
794
|
-
function ensureDelegatedListener(type) {
|
|
795
|
-
|
|
796
|
-
let registered = document[DELEGATE_REGISTERED];
|
|
856
|
+
function ensureDelegatedListener(doc, type) {
|
|
857
|
+
let registered = doc[DELEGATE_REGISTERED];
|
|
797
858
|
if (!registered) {
|
|
798
859
|
registered = /* @__PURE__ */ new Set();
|
|
799
|
-
|
|
860
|
+
doc[DELEGATE_REGISTERED] = registered;
|
|
800
861
|
}
|
|
801
862
|
if (registered.has(type)) return;
|
|
802
863
|
registered.add(type);
|
|
803
|
-
|
|
864
|
+
doc.addEventListener(type, delegatedHandler);
|
|
804
865
|
}
|
|
805
866
|
/**
|
|
806
867
|
* Attach a delegated event handler to an element.
|
|
807
868
|
*
|
|
808
869
|
* Stores the handler as a property on the element and ensures a single
|
|
809
|
-
*
|
|
810
|
-
* document
|
|
811
|
-
*
|
|
870
|
+
* listener exists for the type on the element's own document (so components
|
|
871
|
+
* mounted into another document — an iframe or popup — get delegated events
|
|
872
|
+
* too). Idempotent for the document-level listener: the first call for a
|
|
873
|
+
* given type registers it, subsequent calls are a Set-has check.
|
|
812
874
|
*
|
|
813
875
|
* Passing `null` or `undefined` as the listener clears any previously-set
|
|
814
876
|
* handler for that type on the element (mirroring `addEvent`'s existing
|
|
@@ -820,7 +882,9 @@ function attachDelegatedEvent(el, type, listener) {
|
|
|
820
882
|
el[key] = void 0;
|
|
821
883
|
return;
|
|
822
884
|
}
|
|
823
|
-
|
|
885
|
+
const doc = el.ownerDocument;
|
|
886
|
+
if (doc === null || typeof doc.addEventListener !== "function") return;
|
|
887
|
+
ensureDelegatedListener(doc, type);
|
|
824
888
|
el[key] = listener;
|
|
825
889
|
}
|
|
826
890
|
const DIRECT_LISTENERS = "torp.$directListeners";
|
|
@@ -862,8 +926,19 @@ function copyEventListeners(from, to) {
|
|
|
862
926
|
}
|
|
863
927
|
//#endregion
|
|
864
928
|
//#region src/render/isFragmentNode.ts
|
|
929
|
+
/**
|
|
930
|
+
* Whether the node is a detached template/document fragment — i.e. a tree
|
|
931
|
+
* we're still building, where mount-time side effects (`$onmount`, event
|
|
932
|
+
* hookup, animations) must wait until the outer tree is inserted.
|
|
933
|
+
*
|
|
934
|
+
* A `ShadowRoot` is also `nodeType 11`, but it's a live tree root (its host
|
|
935
|
+
* may already be connected), so side effects must run when content is added
|
|
936
|
+
* to it. `host` distinguishes a shadow root without relying on
|
|
937
|
+
* `instanceof ShadowRoot`, which fails across realms (e.g. an iframe's
|
|
938
|
+
* shadow root).
|
|
939
|
+
*/
|
|
865
940
|
function isFragmentNode(node) {
|
|
866
|
-
return node.nodeType === 11;
|
|
941
|
+
return node.nodeType === 11 && node.host === void 0;
|
|
867
942
|
}
|
|
868
943
|
//#endregion
|
|
869
944
|
//#region src/render/runMountSideEffects.ts
|
|
@@ -889,16 +964,7 @@ function runMountSideEffects(parent, activeRegion, hydrationNode) {
|
|
|
889
964
|
}
|
|
890
965
|
context.stashedEvents.length = 0;
|
|
891
966
|
}
|
|
892
|
-
|
|
893
|
-
context.activeRegion = animation.region;
|
|
894
|
-
$run(function runMountSideEffectsAnimation() {
|
|
895
|
-
if (animation.in !== void 0) animate(animation.el, true, animation.in.keyframes, animation.in.options);
|
|
896
|
-
if (animation.out !== void 0) return () => {
|
|
897
|
-
animate(animation.el, false, animation.out.keyframes, animation.out.options);
|
|
898
|
-
};
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
context.stashedAnimations.length = 0;
|
|
967
|
+
if (context.stashedAnimations.length > 0) context.runAnimations?.();
|
|
902
968
|
context.activeRegion = activeRegion;
|
|
903
969
|
}
|
|
904
970
|
//#endregion
|
|
@@ -950,6 +1016,47 @@ function addFragment(fragment, parent, before, endNode, startNode) {
|
|
|
950
1016
|
if (hydrationNode !== null && endNode !== void 0) nodeNext(endNode);
|
|
951
1017
|
}
|
|
952
1018
|
//#endregion
|
|
1019
|
+
//#region src/render/urlAttributes.ts
|
|
1020
|
+
/**
|
|
1021
|
+
* A function that rewrites the URLs in `href`, `src` and `action` attributes
|
|
1022
|
+
* as the client sets them, registered by a host framework with
|
|
1023
|
+
* `setUrlRewriter` (e.g. `@torpor/build` adds a site's base path, so markup
|
|
1024
|
+
* can be written base-free). Undefined when no rewriting is needed.
|
|
1025
|
+
*/
|
|
1026
|
+
let rewriteUrl;
|
|
1027
|
+
/**
|
|
1028
|
+
* Registers a function that rewrites the URLs in `href`, `src` and `action`
|
|
1029
|
+
* attributes the client sets -- from dynamic attributes, spread props and
|
|
1030
|
+
* client-rendered markup -- or clears it with `undefined`. Fragments already
|
|
1031
|
+
* cached are not rewritten again, so register it before the first render.
|
|
1032
|
+
*/
|
|
1033
|
+
function setUrlRewriter(rewriter) {
|
|
1034
|
+
rewriteUrl = rewriter;
|
|
1035
|
+
}
|
|
1036
|
+
const URL_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
1037
|
+
"href",
|
|
1038
|
+
"src",
|
|
1039
|
+
"action"
|
|
1040
|
+
]);
|
|
1041
|
+
/** An attribute value, with its URL rewritten if it's a URL attribute. */
|
|
1042
|
+
function urlAttributeValue(name, value) {
|
|
1043
|
+
if (rewriteUrl === void 0 || typeof value !== "string") return value;
|
|
1044
|
+
return URL_ATTRIBUTES.has(name.toLowerCase()) ? rewriteUrl(value) : value;
|
|
1045
|
+
}
|
|
1046
|
+
/** Rewrites the URL attributes of the elements in a freshly parsed template. */
|
|
1047
|
+
function rewriteUrlsIn(root) {
|
|
1048
|
+
if (rewriteUrl === void 0) return;
|
|
1049
|
+
const elements = [...root.querySelectorAll("[href], [src], [action]")];
|
|
1050
|
+
if (root instanceof Element && root.matches("[href], [src], [action]")) elements.push(root);
|
|
1051
|
+
for (const el of elements) for (const name of URL_ATTRIBUTES) {
|
|
1052
|
+
const value = el.getAttribute(name);
|
|
1053
|
+
if (value !== null) {
|
|
1054
|
+
const rewritten = rewriteUrl(value);
|
|
1055
|
+
if (rewritten !== value) el.setAttribute(name, rewritten);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
//#endregion
|
|
953
1060
|
//#region src/render/applyProps.ts
|
|
954
1061
|
function applyProps(el, props, propNamesUsed) {
|
|
955
1062
|
if (props !== void 0) {
|
|
@@ -959,7 +1066,7 @@ function applyProps(el, props, propNamesUsed) {
|
|
|
959
1066
|
if (isDelegatedEventType(eventName)) attachDelegatedEvent(el, eventName, value);
|
|
960
1067
|
else el.addEventListener(eventName, value);
|
|
961
1068
|
} else $run(function setAttribute() {
|
|
962
|
-
el.setAttribute(name, value);
|
|
1069
|
+
el.setAttribute(name, urlAttributeValue(name, value));
|
|
963
1070
|
});
|
|
964
1071
|
}
|
|
965
1072
|
}
|
|
@@ -1132,7 +1239,9 @@ function fillLayoutSlot(component, slot, parent, anchor, $props, $context) {
|
|
|
1132
1239
|
region.depth = refillDepth;
|
|
1133
1240
|
refillDepths.delete(parent);
|
|
1134
1241
|
}
|
|
1242
|
+
const previousSlotDepth = devContext.enabled ? setDevSlotDepth(region.depth) : -1;
|
|
1135
1243
|
component(parent, anchor, $props, $context, { _: slot });
|
|
1244
|
+
if (devContext.enabled) setDevSlotDepth(previousSlotDepth);
|
|
1136
1245
|
popRegion(oldRegion);
|
|
1137
1246
|
return region;
|
|
1138
1247
|
}
|
|
@@ -1188,8 +1297,9 @@ function getFragment(document, array, index, html, ns) {
|
|
|
1188
1297
|
template.innerHTML = html;
|
|
1189
1298
|
array[index] = template.content;
|
|
1190
1299
|
}
|
|
1300
|
+
rewriteUrlsIn(array[index]);
|
|
1191
1301
|
}
|
|
1192
|
-
return array[index]
|
|
1302
|
+
return document.importNode(array[index], true);
|
|
1193
1303
|
}
|
|
1194
1304
|
//#endregion
|
|
1195
1305
|
//#region src/render/getElementFragment.ts
|
|
@@ -1228,8 +1338,9 @@ function getElementFragment(document, array, index, html, ns) {
|
|
|
1228
1338
|
template.innerHTML = html;
|
|
1229
1339
|
array[index] = template.content.firstElementChild;
|
|
1230
1340
|
}
|
|
1341
|
+
rewriteUrlsIn(array[index]);
|
|
1231
1342
|
}
|
|
1232
|
-
return array[index]
|
|
1343
|
+
return document.importNode(array[index], true);
|
|
1233
1344
|
}
|
|
1234
1345
|
//#endregion
|
|
1235
1346
|
//#region src/render/isServerComponent.ts
|
|
@@ -1292,8 +1403,12 @@ function containedTrees(parent) {
|
|
|
1292
1403
|
* @param parent The parent node
|
|
1293
1404
|
* @param component The component to mount
|
|
1294
1405
|
* @param props An object containing component props
|
|
1406
|
+
* @param slots Slot render functions for the component
|
|
1407
|
+
* @param rootContext The root `$context`, which the component and all of its
|
|
1408
|
+
* descendants inherit (e.g. app-wide state that a framework provides to
|
|
1409
|
+
* every page)
|
|
1295
1410
|
*/
|
|
1296
|
-
function hydrate(parent, component, props, slots) {
|
|
1411
|
+
function hydrate(parent, component, props, slots, rootContext) {
|
|
1297
1412
|
if (isServerComponent(component)) throw new Error("The component was compiled for SSR (it renders to an HTML string) and cannot be hydrated in the browser. Import the client build instead, e.g. with the '?client' import query");
|
|
1298
1413
|
const saved = context.rootRegion !== null ? {
|
|
1299
1414
|
activeRegion: context.activeRegion,
|
|
@@ -1306,7 +1421,7 @@ function hydrate(parent, component, props, slots) {
|
|
|
1306
1421
|
context.rootRegion = root;
|
|
1307
1422
|
context.previousRegion = root;
|
|
1308
1423
|
pushRegion(root);
|
|
1309
|
-
component(parent, null, props,
|
|
1424
|
+
component(parent, null, props, rootContext, slots);
|
|
1310
1425
|
context.hydrationNode = null;
|
|
1311
1426
|
flushMountEffects();
|
|
1312
1427
|
if (saved === null) {
|
|
@@ -1339,8 +1454,12 @@ function hydrate(parent, component, props, slots) {
|
|
|
1339
1454
|
* child elements
|
|
1340
1455
|
* @param component The component to mount
|
|
1341
1456
|
* @param props An object containing component props
|
|
1457
|
+
* @param slots Slot render functions for the component
|
|
1458
|
+
* @param rootContext The root `$context`, which the component and all of its
|
|
1459
|
+
* descendants inherit (e.g. app-wide state that a framework provides to
|
|
1460
|
+
* every page)
|
|
1342
1461
|
*/
|
|
1343
|
-
function mount(parent, component, props, slots) {
|
|
1462
|
+
function mount(parent, component, props, slots, rootContext) {
|
|
1344
1463
|
if (isServerComponent(component)) throw new Error("The component was compiled for SSR (it renders to an HTML string) and cannot be mounted in the browser. Import the client build instead, e.g. with the '?client' import query");
|
|
1345
1464
|
if (parent.childElementCount > 0) throw new Error("The parent node must have no child elements");
|
|
1346
1465
|
while (parent.firstChild !== null) parent.firstChild.remove();
|
|
@@ -1353,13 +1472,28 @@ function mount(parent, component, props, slots) {
|
|
|
1353
1472
|
context.rootRegion = root;
|
|
1354
1473
|
context.previousRegion = root;
|
|
1355
1474
|
pushRegion(root);
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1475
|
+
let mounted = false;
|
|
1476
|
+
try {
|
|
1477
|
+
component(parent, null, props, rootContext, slots);
|
|
1478
|
+
mounted = true;
|
|
1479
|
+
} finally {
|
|
1480
|
+
if (mounted) {
|
|
1481
|
+
if (saved !== null) {
|
|
1482
|
+
context.rootRegion = saved.rootRegion;
|
|
1483
|
+
context.previousRegion = saved.previousRegion;
|
|
1484
|
+
context.activeRegion = saved.activeRegion;
|
|
1485
|
+
}
|
|
1486
|
+
} else {
|
|
1487
|
+
unregisterRegionTree(parent);
|
|
1488
|
+
try {
|
|
1489
|
+
clearRegion(root);
|
|
1490
|
+
} catch {}
|
|
1491
|
+
context.rootRegion = saved !== null ? saved.rootRegion : null;
|
|
1492
|
+
context.previousRegion = saved !== null ? saved.previousRegion : null;
|
|
1493
|
+
context.activeRegion = saved !== null ? saved.activeRegion : null;
|
|
1494
|
+
}
|
|
1361
1495
|
}
|
|
1362
|
-
registerRegionTree(parent, root);
|
|
1496
|
+
if (mounted) registerRegionTree(parent, root);
|
|
1363
1497
|
}
|
|
1364
1498
|
//#endregion
|
|
1365
1499
|
//#region src/render/unmount.ts
|
|
@@ -1373,6 +1507,10 @@ function mount(parent, component, props, slots) {
|
|
|
1373
1507
|
* embed is disposed and the host's render context is left untouched. Any
|
|
1374
1508
|
* embeds living inside a root container are disposed along with it.
|
|
1375
1509
|
*
|
|
1510
|
+
* When no tree was mounted into `parent`, this is a no-op apart from
|
|
1511
|
+
* disposing any embeds living inside it and removing `parent`'s own child
|
|
1512
|
+
* nodes — it never touches the running app's root context.
|
|
1513
|
+
*
|
|
1376
1514
|
* Call this before `mount`ing a fresh component tree into the same container
|
|
1377
1515
|
* (e.g. when client-side navigating to a route whose layout chain differs
|
|
1378
1516
|
* from the previous one). `mount` refuses to mount into a non-empty parent
|
|
@@ -1386,17 +1524,17 @@ function unmount(parent) {
|
|
|
1386
1524
|
clearRegion(nestedTree);
|
|
1387
1525
|
unregisterRegionTree(nestedParent);
|
|
1388
1526
|
}
|
|
1389
|
-
if (owned !== void 0
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
clearRegion(
|
|
1527
|
+
if (owned !== void 0) {
|
|
1528
|
+
if (owned !== context.rootRegion) {
|
|
1529
|
+
clearRegion(owned);
|
|
1530
|
+
unregisterRegionTree(parent);
|
|
1531
|
+
} else {
|
|
1532
|
+
clearRegion(owned);
|
|
1395
1533
|
context.rootRegion = null;
|
|
1396
1534
|
context.previousRegion = null;
|
|
1397
1535
|
context.activeRegion = null;
|
|
1536
|
+
unregisterRegionTree(parent);
|
|
1398
1537
|
}
|
|
1399
|
-
if (owned !== void 0) unregisterRegionTree(parent);
|
|
1400
1538
|
}
|
|
1401
1539
|
while (parent.firstChild !== null) parent.firstChild.remove();
|
|
1402
1540
|
}
|
|
@@ -1860,50 +1998,23 @@ function clearServerBranch(region, removedFirst, anchor) {
|
|
|
1860
1998
|
}
|
|
1861
1999
|
}
|
|
1862
2000
|
//#endregion
|
|
1863
|
-
//#region src/
|
|
1864
|
-
const warnedByRegion = /* @__PURE__ */ new WeakMap();
|
|
2001
|
+
//#region src/watch/isWrappable.ts
|
|
1865
2002
|
/**
|
|
1866
|
-
*
|
|
2003
|
+
* Whether `$watch`/`deepWrap` can proxy this value.
|
|
1867
2004
|
*
|
|
1868
|
-
*
|
|
1869
|
-
*
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
1872
|
-
*
|
|
1873
|
-
*
|
|
1874
|
-
* positionally) and are ignored.
|
|
1875
|
-
*
|
|
1876
|
-
* @param region The `@for` list's region, used to dedupe warnings per list.
|
|
1877
|
-
* @param specs The new row specs, in order.
|
|
2005
|
+
* Only plain objects, plain arrays, and exact Date/Map/Set/URL/
|
|
2006
|
+
* URLSearchParams instances are deep-watched. Everything else -- class
|
|
2007
|
+
* instances, array/collection subclasses, RegExp, typed arrays, promises, DOM
|
|
2008
|
+
* nodes, weak collections, and any frozen/non-extensible object -- is treated
|
|
2009
|
+
* as an opaque value: it is returned unchanged, and only replacing the
|
|
2010
|
+
* property that holds it is reactive.
|
|
1878
2011
|
*/
|
|
1879
|
-
function
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
if (!seen.has(key)) {
|
|
1886
|
-
seen.add(key);
|
|
1887
|
-
continue;
|
|
1888
|
-
}
|
|
1889
|
-
let warned = warnedByRegion.get(region);
|
|
1890
|
-
if (warned === void 0) {
|
|
1891
|
-
warned = /* @__PURE__ */ new Set();
|
|
1892
|
-
warnedByRegion.set(region, warned);
|
|
1893
|
-
}
|
|
1894
|
-
if (!warned.has(key)) {
|
|
1895
|
-
warned.add(key);
|
|
1896
|
-
console.warn(`[torpor] Duplicate @key value ${formatKey(key)} in a keyed @for list. Keys must be unique, or updates and removals will affect the wrong rows.`);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
function formatKey(key) {
|
|
1901
|
-
try {
|
|
1902
|
-
const json = JSON.stringify(key);
|
|
1903
|
-
return json === void 0 ? String(key) : json;
|
|
1904
|
-
} catch {
|
|
1905
|
-
return String(key);
|
|
1906
|
-
}
|
|
2012
|
+
function isWrappable(value) {
|
|
2013
|
+
if (value === null || typeof value !== "object") return false;
|
|
2014
|
+
if (!Object.isExtensible(value)) return false;
|
|
2015
|
+
const proto = Object.getPrototypeOf(value);
|
|
2016
|
+
if (proto === Date.prototype || proto === Map.prototype || proto === Set.prototype || typeof URL !== "undefined" && proto === URL.prototype || typeof URLSearchParams !== "undefined" && proto === URLSearchParams.prototype) return true;
|
|
2017
|
+
return proto === Object.prototype || proto === null || proto === Array.prototype;
|
|
1907
2018
|
}
|
|
1908
2019
|
//#endregion
|
|
1909
2020
|
//#region src/watch/propagateSignal.ts
|
|
@@ -1999,24 +2110,35 @@ var AwaitSuspend = class extends Error {
|
|
|
1999
2110
|
//#endregion
|
|
2000
2111
|
//#region src/watch/deepWrap.ts
|
|
2001
2112
|
/**
|
|
2002
|
-
* Wraps a value with `$watch` if it is a plain object
|
|
2003
|
-
*
|
|
2004
|
-
* otherwise
|
|
2113
|
+
* Wraps a value with `$watch` if it is a plain object, plain array, or exact
|
|
2114
|
+
* Date/Map/Set instance that is not already watched. Returns the value
|
|
2115
|
+
* unchanged otherwise (class instances, subclasses, RegExp, typed arrays,
|
|
2116
|
+
* frozen objects, promises, DOM nodes, ... stay opaque).
|
|
2005
2117
|
*
|
|
2006
2118
|
* Used by the `get` trap (wrap values on read) and the `set` trap (wrap
|
|
2007
2119
|
* values on write), so a value stored in watched state is reactive whether
|
|
2008
2120
|
* it's been read yet or not.
|
|
2009
2121
|
*/
|
|
2010
2122
|
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
2123
|
+
const wrappedProxies = /* @__PURE__ */ new WeakSet();
|
|
2124
|
+
/**
|
|
2125
|
+
* Whether `value` is a proxy created by `deepWrap` — checked without going
|
|
2126
|
+
* through the proxy's `get` trap.
|
|
2127
|
+
*/
|
|
2128
|
+
function isWrappedProxy(value) {
|
|
2129
|
+
return value !== null && typeof value === "object" && wrappedProxies.has(value);
|
|
2130
|
+
}
|
|
2011
2131
|
function deepWrap(value) {
|
|
2012
2132
|
if (value === void 0 || value === null || typeof value !== "object") return value;
|
|
2133
|
+
if (wrappedProxies.has(value)) return value;
|
|
2013
2134
|
if (value[proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
|
|
2135
|
+
if (!isWrappable(value)) return value;
|
|
2014
2136
|
if (value.then !== void 0) return value;
|
|
2015
|
-
if (value.nodeType !== void 0) return value;
|
|
2016
2137
|
const cached = proxyCache.get(value);
|
|
2017
2138
|
if (cached !== void 0) return cached;
|
|
2018
2139
|
const proxy = $watch(value);
|
|
2019
2140
|
proxyCache.set(value, proxy);
|
|
2141
|
+
wrappedProxies.add(proxy);
|
|
2020
2142
|
return proxy;
|
|
2021
2143
|
}
|
|
2022
2144
|
//#endregion
|
|
@@ -2043,6 +2165,114 @@ function ensureProxySignal(data, key) {
|
|
|
2043
2165
|
return signal;
|
|
2044
2166
|
}
|
|
2045
2167
|
//#endregion
|
|
2168
|
+
//#region src/watch/urlHandlers.ts
|
|
2169
|
+
const URL_KEY = Symbol("torp.url");
|
|
2170
|
+
const URL_PARAMS_KEY = Symbol("torp.urlParams");
|
|
2171
|
+
const URL_PROPERTIES = /* @__PURE__ */ new Set([
|
|
2172
|
+
"href",
|
|
2173
|
+
"origin",
|
|
2174
|
+
"protocol",
|
|
2175
|
+
"username",
|
|
2176
|
+
"password",
|
|
2177
|
+
"host",
|
|
2178
|
+
"hostname",
|
|
2179
|
+
"port",
|
|
2180
|
+
"pathname",
|
|
2181
|
+
"search",
|
|
2182
|
+
"searchParams",
|
|
2183
|
+
"hash"
|
|
2184
|
+
]);
|
|
2185
|
+
const URL_METHODS = /* @__PURE__ */ new Set(["toString", "toJSON"]);
|
|
2186
|
+
const URL_MEMBERS = /* @__PURE__ */ new Set([...URL_PROPERTIES, ...URL_METHODS]);
|
|
2187
|
+
const URL_PARAMS_METHODS = /* @__PURE__ */ new Set([
|
|
2188
|
+
"append",
|
|
2189
|
+
"delete",
|
|
2190
|
+
"get",
|
|
2191
|
+
"getAll",
|
|
2192
|
+
"has",
|
|
2193
|
+
"set",
|
|
2194
|
+
"sort",
|
|
2195
|
+
"entries",
|
|
2196
|
+
"forEach",
|
|
2197
|
+
"keys",
|
|
2198
|
+
"values",
|
|
2199
|
+
"toString"
|
|
2200
|
+
]);
|
|
2201
|
+
const URL_PARAMS_MUTATORS = /* @__PURE__ */ new Set([
|
|
2202
|
+
"append",
|
|
2203
|
+
"delete",
|
|
2204
|
+
"set",
|
|
2205
|
+
"sort"
|
|
2206
|
+
]);
|
|
2207
|
+
function urlGet(data, target, key, wrap) {
|
|
2208
|
+
trackProxySignal(data, URL_KEY);
|
|
2209
|
+
if (key === "searchParams") {
|
|
2210
|
+
const params = target.searchParams;
|
|
2211
|
+
if (data.shallow === true) return params;
|
|
2212
|
+
const proxy = wrap(params);
|
|
2213
|
+
const paramsData = params[proxyDataSymbol];
|
|
2214
|
+
if (paramsData !== void 0) {
|
|
2215
|
+
paramsData.linkedUrlData = data;
|
|
2216
|
+
data.urlParamsData = paramsData;
|
|
2217
|
+
}
|
|
2218
|
+
return proxy;
|
|
2219
|
+
}
|
|
2220
|
+
if (URL_METHODS.has(key)) return function(...args) {
|
|
2221
|
+
return target[key](...args);
|
|
2222
|
+
};
|
|
2223
|
+
return target[key];
|
|
2224
|
+
}
|
|
2225
|
+
function urlSet(data, target, key, value) {
|
|
2226
|
+
const before = target.href;
|
|
2227
|
+
const descriptor = typeof key === "string" ? Object.getOwnPropertyDescriptor(URL.prototype, key) : void 0;
|
|
2228
|
+
if (descriptor?.set !== void 0) descriptor.set.call(target, value);
|
|
2229
|
+
else if (!Reflect.set(target, key, value, target)) return false;
|
|
2230
|
+
if (target.href !== before) {
|
|
2231
|
+
batchStart();
|
|
2232
|
+
try {
|
|
2233
|
+
propagateSignal(data, URL_KEY);
|
|
2234
|
+
if (data.urlParamsData !== void 0) propagateSignal(data.urlParamsData, URL_PARAMS_KEY);
|
|
2235
|
+
} finally {
|
|
2236
|
+
batchEnd();
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
return true;
|
|
2240
|
+
}
|
|
2241
|
+
function trackUrlParams(data) {
|
|
2242
|
+
trackProxySignal(data, URL_PARAMS_KEY);
|
|
2243
|
+
if (data.linkedUrlData !== void 0) trackProxySignal(data.linkedUrlData, URL_KEY);
|
|
2244
|
+
}
|
|
2245
|
+
function propagateUrlParams(data) {
|
|
2246
|
+
batchStart();
|
|
2247
|
+
try {
|
|
2248
|
+
propagateSignal(data, URL_PARAMS_KEY);
|
|
2249
|
+
if (data.linkedUrlData !== void 0) propagateSignal(data.linkedUrlData, URL_KEY);
|
|
2250
|
+
} finally {
|
|
2251
|
+
batchEnd();
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
function urlParamsGet(data, target, key) {
|
|
2255
|
+
if (key === "size") {
|
|
2256
|
+
trackUrlParams(data);
|
|
2257
|
+
return target.size;
|
|
2258
|
+
}
|
|
2259
|
+
if (key === Symbol.iterator) {
|
|
2260
|
+
trackUrlParams(data);
|
|
2261
|
+
return target[Symbol.iterator].bind(target);
|
|
2262
|
+
}
|
|
2263
|
+
return function(...args) {
|
|
2264
|
+
const method = key;
|
|
2265
|
+
if (URL_PARAMS_MUTATORS.has(method)) {
|
|
2266
|
+
const before = target.toString();
|
|
2267
|
+
const result = target[method](...args);
|
|
2268
|
+
if (target.toString() !== before) propagateUrlParams(data);
|
|
2269
|
+
return result;
|
|
2270
|
+
}
|
|
2271
|
+
trackUrlParams(data);
|
|
2272
|
+
return target[method](...args);
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2275
|
+
//#endregion
|
|
2046
2276
|
//#region src/watch/proxyGet.ts
|
|
2047
2277
|
/**
|
|
2048
2278
|
* Called when a read hits a `didSuspend` computed. Subscribes the reader (so
|
|
@@ -2093,6 +2323,8 @@ function proxyGet(target, key, receiver) {
|
|
|
2093
2323
|
let data = target[proxyDataSymbol];
|
|
2094
2324
|
if (key === proxyDataSymbol) return data;
|
|
2095
2325
|
if ((data.isDate || data.isMap || data.isSet) && !Object.prototype.hasOwnProperty.call(target, key)) return collectionGet(data, target, key, receiver);
|
|
2326
|
+
if (data.isUrl && typeof key === "string" && URL_MEMBERS.has(key) && !Object.prototype.hasOwnProperty.call(target, key)) return urlGet(data, target, key, deepWrap);
|
|
2327
|
+
if (data.isUrlParams && (key === "size" || key === Symbol.iterator || typeof key === "string" && URL_PARAMS_METHODS.has(key)) && !Object.prototype.hasOwnProperty.call(target, key)) return urlParamsGet(data, target, key);
|
|
2096
2328
|
let signal = data.signals.get(key);
|
|
2097
2329
|
if (signal === void 0) {
|
|
2098
2330
|
const propDescriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
@@ -2156,7 +2388,7 @@ function proxyGet(target, key, receiver) {
|
|
|
2156
2388
|
}
|
|
2157
2389
|
const arrayWrapper = {
|
|
2158
2390
|
[Symbol.iterator]: function(data, target, _key) {
|
|
2159
|
-
|
|
2391
|
+
trackArrayReads(data);
|
|
2160
2392
|
return function arrayIterator() {
|
|
2161
2393
|
let index = 0;
|
|
2162
2394
|
return {
|
|
@@ -2200,29 +2432,112 @@ const arrayWrapper = {
|
|
|
2200
2432
|
toReversed: readHandle,
|
|
2201
2433
|
toSorted: readHandle,
|
|
2202
2434
|
toSpliced: readHandle,
|
|
2203
|
-
indexOf:
|
|
2204
|
-
lastIndexOf:
|
|
2205
|
-
includes:
|
|
2435
|
+
indexOf: searchHandle,
|
|
2436
|
+
lastIndexOf: searchHandle,
|
|
2437
|
+
includes: searchHandle,
|
|
2206
2438
|
find: readHandle,
|
|
2207
2439
|
findIndex: readHandle,
|
|
2208
2440
|
some: readHandle,
|
|
2209
2441
|
every: readHandle,
|
|
2210
|
-
join:
|
|
2442
|
+
join: joinHandle,
|
|
2211
2443
|
forEach: readHandle,
|
|
2212
2444
|
reduce: readHandle,
|
|
2213
2445
|
reduceRight: readHandle,
|
|
2214
2446
|
flat: readHandle,
|
|
2215
2447
|
flatMap: readHandle,
|
|
2216
|
-
at:
|
|
2448
|
+
at: atHandle
|
|
2217
2449
|
};
|
|
2450
|
+
/**
|
|
2451
|
+
* Wraps (and writes back) every object element of a raw array, so callback
|
|
2452
|
+
* parameters and returned values are reactive proxies — the same lazy wrapping
|
|
2453
|
+
* the iterator does. Skipped entirely once every element is wrapped (the
|
|
2454
|
+
* `elementsWrapped` flag, reset by mutations that can insert raw elements);
|
|
2455
|
+
* `isWrappedProxy` skips elements that are already proxies without reading
|
|
2456
|
+
* through their `get` trap. Shallow arrays are left unwrapped to match the
|
|
2457
|
+
* `get` trap's deep-only behaviour.
|
|
2458
|
+
*/
|
|
2459
|
+
function wrapArrayElements(data, target) {
|
|
2460
|
+
if (data.shallow === true || data.elementsWrapped === true) return;
|
|
2461
|
+
const length = target.length;
|
|
2462
|
+
for (let i = 0; i < length; i++) {
|
|
2463
|
+
const value = target[i];
|
|
2464
|
+
if (value !== null && typeof value === "object" && !isWrappedProxy(value)) {
|
|
2465
|
+
const wrapped = deepWrap(value);
|
|
2466
|
+
if (wrapped !== value) target[i] = wrapped;
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
data.elementsWrapped = true;
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Subscribes the active effect to everything a read of the array's contents
|
|
2473
|
+
* depends on: `length` (rows added/removed) and the content signal (an
|
|
2474
|
+
* element replaced at an existing index, which keeps the length). When no
|
|
2475
|
+
* effect is active both are cheap no-ops.
|
|
2476
|
+
*/
|
|
2477
|
+
function trackArrayReads(data) {
|
|
2478
|
+
trackProxySignal(data, "length");
|
|
2479
|
+
trackProxySignal(data, proxyArrayContentSymbol);
|
|
2480
|
+
}
|
|
2218
2481
|
function readHandle(data, target, key) {
|
|
2219
2482
|
return function(...args) {
|
|
2220
|
-
|
|
2483
|
+
trackArrayReads(data);
|
|
2484
|
+
wrapArrayElements(data, target);
|
|
2485
|
+
return target[key].apply(target, args);
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
function joinHandle(data, target, key) {
|
|
2489
|
+
return function(...args) {
|
|
2490
|
+
trackArrayReads(data);
|
|
2221
2491
|
return target[key].apply(target, args);
|
|
2222
2492
|
};
|
|
2223
2493
|
}
|
|
2494
|
+
/**
|
|
2495
|
+
* `indexOf` / `lastIndexOf` / `includes`.
|
|
2496
|
+
*
|
|
2497
|
+
* Elements are wrapped lazily, so the array can hold raw objects or their
|
|
2498
|
+
* proxies — and a raw search value can miss the proxy that replaced it (or a
|
|
2499
|
+
* proxy can miss the raw object it wraps). On a miss with an object argument,
|
|
2500
|
+
* retry with the unwrapped and wrapped forms.
|
|
2501
|
+
*/
|
|
2502
|
+
function searchHandle(data, target, key) {
|
|
2503
|
+
return function(...args) {
|
|
2504
|
+
trackArrayReads(data);
|
|
2505
|
+
const search = args[0];
|
|
2506
|
+
const func = target[key];
|
|
2507
|
+
const found = func.apply(target, args);
|
|
2508
|
+
if ((found === -1 || found === false) && search !== null && typeof search === "object") for (const candidate of [$unwrap(search), deepWrap(search)]) {
|
|
2509
|
+
if (candidate === search) continue;
|
|
2510
|
+
const result = func.apply(target, [candidate, ...args.slice(1)]);
|
|
2511
|
+
if (result !== -1 && result !== false) return result;
|
|
2512
|
+
}
|
|
2513
|
+
return found;
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* `at`: like a direct `arr[i]` read, but it wraps just the element it returns
|
|
2518
|
+
* (a whole-array wrap would turn the O(1) lookup into O(n)).
|
|
2519
|
+
*/
|
|
2520
|
+
function atHandle(data, target, _key) {
|
|
2521
|
+
return function(index) {
|
|
2522
|
+
trackArrayReads(data);
|
|
2523
|
+
const length = target.length;
|
|
2524
|
+
let i = Math.trunc(Number(index ?? 0)) || 0;
|
|
2525
|
+
if (i < 0) i += length;
|
|
2526
|
+
if (i < 0 || i >= length) return void 0;
|
|
2527
|
+
let value = target[i];
|
|
2528
|
+
if (data.shallow !== true) {
|
|
2529
|
+
const wrapped = deepWrap(value);
|
|
2530
|
+
if (wrapped !== value) {
|
|
2531
|
+
value = wrapped;
|
|
2532
|
+
target[i] = value;
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
return value;
|
|
2536
|
+
};
|
|
2537
|
+
}
|
|
2224
2538
|
function arrayHandle(data, target, key) {
|
|
2225
2539
|
return function(...args) {
|
|
2540
|
+
if (key === "push" || key === "unshift" || key === "splice") data.elementsWrapped = false;
|
|
2226
2541
|
const result = target[key].apply(target, args);
|
|
2227
2542
|
propagateSignal(data, "length");
|
|
2228
2543
|
if (key !== "sort" && key !== "reverse") propagateSignal(data, proxyKeysSymbol);
|
|
@@ -2327,7 +2642,7 @@ const mapWrapper = {
|
|
|
2327
2642
|
return function(key) {
|
|
2328
2643
|
key = $unwrap(key);
|
|
2329
2644
|
const result = target.delete(key);
|
|
2330
|
-
propagateCollection(data, collectionKey(key));
|
|
2645
|
+
if (result) propagateCollection(data, collectionKey(key));
|
|
2331
2646
|
return result;
|
|
2332
2647
|
};
|
|
2333
2648
|
},
|
|
@@ -2401,7 +2716,7 @@ const setWrapper = {
|
|
|
2401
2716
|
return function(value) {
|
|
2402
2717
|
value = $unwrap(value);
|
|
2403
2718
|
const result = target.delete(value);
|
|
2404
|
-
propagateCollection(data, collectionKey(value));
|
|
2719
|
+
if (result) propagateCollection(data, collectionKey(value));
|
|
2405
2720
|
return result;
|
|
2406
2721
|
};
|
|
2407
2722
|
},
|
|
@@ -2454,16 +2769,21 @@ function setEntries(data, target) {
|
|
|
2454
2769
|
//#region src/watch/proxySet.ts
|
|
2455
2770
|
function proxySet(target, key, value, receiver) {
|
|
2456
2771
|
const oldValue = target[key];
|
|
2457
|
-
if (value
|
|
2458
|
-
if (context.batchOperation > 100) throw new Error("Cycle detected");
|
|
2772
|
+
if (!Object.is(value, oldValue)) {
|
|
2459
2773
|
let data = target[proxyDataSymbol];
|
|
2460
2774
|
devContext.signalSet(data, key);
|
|
2775
|
+
if (data.isUrl && !Object.prototype.hasOwnProperty.call(target, key)) return urlSet(data, target, key, value);
|
|
2461
2776
|
if (data.shallow !== true) value = deepWrap(value);
|
|
2462
2777
|
const isNewKey = !Object.prototype.hasOwnProperty.call(target, key);
|
|
2778
|
+
const isArrayIndex = data.isArray && typeof key !== "symbol" && !isNaN(+key);
|
|
2779
|
+
const oldLength = isArrayIndex ? target.length : 0;
|
|
2463
2780
|
Reflect.set(target, key, value, receiver);
|
|
2464
2781
|
propagateSignal(data, key);
|
|
2465
2782
|
if (isNewKey) propagateSignal(data, proxyKeysSymbol);
|
|
2466
|
-
if (
|
|
2783
|
+
if (isArrayIndex) {
|
|
2784
|
+
propagateSignal(data, proxyArrayContentSymbol);
|
|
2785
|
+
if (target.length !== oldLength) propagateSignal(data, "length");
|
|
2786
|
+
}
|
|
2467
2787
|
}
|
|
2468
2788
|
return true;
|
|
2469
2789
|
}
|
|
@@ -2477,6 +2797,11 @@ const sharedHandler = {
|
|
|
2477
2797
|
if (data !== void 0) trackProxySignal(data, proxyKeysSymbol);
|
|
2478
2798
|
return Reflect.ownKeys(target);
|
|
2479
2799
|
},
|
|
2800
|
+
has: (target, key) => {
|
|
2801
|
+
const data = target[proxyDataSymbol];
|
|
2802
|
+
if (data !== void 0) trackProxySignal(data, proxyKeysSymbol);
|
|
2803
|
+
return Reflect.has(target, key);
|
|
2804
|
+
},
|
|
2480
2805
|
deleteProperty: (target, key) => {
|
|
2481
2806
|
const deleted = Reflect.deleteProperty(target, key);
|
|
2482
2807
|
const data = target[proxyDataSymbol];
|
|
@@ -2490,20 +2815,33 @@ const sharedHandler = {
|
|
|
2490
2815
|
/**
|
|
2491
2816
|
* Watches an object and runs effects when its properties are changed.
|
|
2492
2817
|
*
|
|
2493
|
-
*
|
|
2494
|
-
*
|
|
2495
|
-
*
|
|
2818
|
+
* Only plain objects, plain arrays, and exact Date/Map/Set/URL/
|
|
2819
|
+
* URLSearchParams instances are deep-watched. Other values -- class instances,
|
|
2820
|
+
* subclasses, RegExp, typed arrays, frozen/non-extensible objects, promises,
|
|
2821
|
+
* DOM nodes, ... -- are returned unchanged. Effects still track the property
|
|
2822
|
+
* that holds them, so replacing the value is reactive even though mutating it
|
|
2823
|
+
* in place isn't.
|
|
2824
|
+
*
|
|
2825
|
+
* Dates, Maps, Sets, URLs and URLSearchParams are supported: their methods are
|
|
2826
|
+
* reactive (reads track, writes notify), so they can be used in watched state
|
|
2827
|
+
* directly.
|
|
2496
2828
|
*
|
|
2497
2829
|
* @param object The object to watch
|
|
2498
2830
|
*/
|
|
2499
2831
|
function $watch(object, options) {
|
|
2500
2832
|
if (object === void 0 || object === null || object[proxyDataSymbol] !== void 0) return object;
|
|
2833
|
+
if (!isWrappable(object)) {
|
|
2834
|
+
if (devContext.enabled) console.warn("$watch() only deep-watches plain objects, arrays and exact Date/Map/Set/URL/URLSearchParams instances; returning this value unchanged.");
|
|
2835
|
+
return object;
|
|
2836
|
+
}
|
|
2501
2837
|
const data = {
|
|
2502
2838
|
target: object,
|
|
2503
2839
|
isArray: Array.isArray(object),
|
|
2504
2840
|
isDate: object instanceof Date,
|
|
2505
2841
|
isMap: object instanceof Map,
|
|
2506
2842
|
isSet: object instanceof Set,
|
|
2843
|
+
isUrl: typeof URL !== "undefined" && object instanceof URL,
|
|
2844
|
+
isUrlParams: typeof URLSearchParams !== "undefined" && object instanceof URLSearchParams,
|
|
2507
2845
|
shallow: options?.shallow === true,
|
|
2508
2846
|
signals: /* @__PURE__ */ new Map()
|
|
2509
2847
|
};
|
|
@@ -2776,7 +3114,7 @@ function runList(region, parent, anchor, buildItems, create, update, noWatch) {
|
|
|
2776
3114
|
const oldRegion = pushRegion(region, first);
|
|
2777
3115
|
first = false;
|
|
2778
3116
|
const newSpecs = buildItems();
|
|
2779
|
-
if (devContext.enabled) checkListKeys(region, newSpecs);
|
|
3117
|
+
if (devContext.enabled) devContext.checkListKeys(region, newSpecs);
|
|
2780
3118
|
context.activeTarget = null;
|
|
2781
3119
|
listItems = runListItems(region, parent, anchor, listItems, newSpecs, create, update, noWatch);
|
|
2782
3120
|
popRegion(oldRegion);
|
|
@@ -3060,7 +3398,7 @@ function setAttribute(el, name, value) {
|
|
|
3060
3398
|
if (name === "value") {
|
|
3061
3399
|
if (setValueProperty(el, String(value))) return;
|
|
3062
3400
|
}
|
|
3063
|
-
el.setAttribute(name, value);
|
|
3401
|
+
el.setAttribute(name, urlAttributeValue(name, value));
|
|
3064
3402
|
}
|
|
3065
3403
|
/** Sets the `value` property on a form control; returns false for other elements. */
|
|
3066
3404
|
function setValueProperty(el, value) {
|
|
@@ -3493,6 +3831,6 @@ function $stream(source, handler, options) {
|
|
|
3493
3831
|
});
|
|
3494
3832
|
}
|
|
3495
3833
|
//#endregion
|
|
3496
|
-
export { $async, $batch, $bind, $cache, $onmount, $peek, $pending, $refresh, $run, $stream, $unwrap, $watch, clearLayoutSlot, fillLayoutSlot, fromElement, fromServer, fromWebSocket, hydrate, mount, addElement as t_add_element, addFragment as t_add_fragment, nodeAnchor as t_anchor, addAnimation as t_animate, applyProps as t_apply_props, setAttribute as t_attribute, nodeChild as t_child, buildClasses as t_class, setDynamicElement as t_dynamic, addEvent as t_event, firstInsideNode as t_first_inside, formatText as t_fmt, getFragment as t_fragment, getElementFragment as t_fragment_el, headElement as t_head_element, newListItem as t_list_item, nodeNext as t_next, popRegion as t_pop_region, pushRegion as t_push_region, newRegion as t_region, rerunRegionEffects as t_rerun_region_effects, restoreHydration as t_restore_hydration, nodeRoot as t_root, nodeRootElement as t_root_el, runAwait as t_run_await, runControlBranch as t_run_branch, runControl as t_run_control, runList as t_run_list, runTry as t_run_try, saveHydration as t_save_hydration, nodeSkip as t_skip, buildStyles as t_style, unmount };
|
|
3834
|
+
export { $async, $batch, $bind, $cache, $onmount, $peek, $pending, $refresh, $run, $stream, $unwrap, $watch, clearLayoutSlot, fillLayoutSlot, fromElement, fromServer, fromWebSocket, hydrate, mount, setUrlRewriter, addElement as t_add_element, addFragment as t_add_fragment, nodeAnchor as t_anchor, addAnimation as t_animate, applyProps as t_apply_props, setAttribute as t_attribute, nodeChild as t_child, buildClasses as t_class, setDynamicElement as t_dynamic, addEvent as t_event, firstInsideNode as t_first_inside, formatText as t_fmt, getFragment as t_fragment, getElementFragment as t_fragment_el, headElement as t_head_element, newListItem as t_list_item, nodeNext as t_next, popRegion as t_pop_region, pushRegion as t_push_region, newRegion as t_region, rerunRegionEffects as t_rerun_region_effects, restoreHydration as t_restore_hydration, nodeRoot as t_root, nodeRootElement as t_root_el, runAwait as t_run_await, runControlBranch as t_run_branch, runControl as t_run_control, runList as t_run_list, runTry as t_run_try, saveHydration as t_save_hydration, nodeSkip as t_skip, buildStyles as t_style, unmount };
|
|
3497
3835
|
|
|
3498
3836
|
//# sourceMappingURL=index.mjs.map
|