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