@shadow-js/web 1.0.3 → 1.0.5
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/CHANGELOG.md +15 -0
- package/README.md +2 -3
- package/dist/dev/attributes.js +1 -5
- package/dist/dev/attributes.js.map +1 -1
- package/dist/dev/class-style.js +15 -13
- package/dist/dev/class-style.js.map +1 -1
- package/dist/dev/control-flow/dynamic.js +4 -4
- package/dist/dev/control-flow/no-hydration.js +1 -1
- package/dist/dev/control-flow/portal.js +1 -1
- package/dist/dev/element.js +10 -27
- package/dist/dev/element.js.map +1 -1
- package/dist/dev/events.js +64 -80
- package/dist/dev/events.js.map +1 -1
- package/dist/dev/extend.js +6 -6
- package/dist/dev/head/use-head.js +1 -1
- package/dist/dev/head/validate.js +1 -1
- package/dist/dev/hydration.js +21 -13
- package/dist/dev/hydration.js.map +1 -1
- package/dist/dev/index.d.ts +5 -5
- package/dist/dev/index.js +6 -6
- package/dist/dev/insert.js +50 -68
- package/dist/dev/insert.js.map +1 -1
- package/dist/dev/internal/reconcile.d.ts +2 -1
- package/dist/dev/internal/reconcile.js +19 -2
- package/dist/dev/internal/reconcile.js.map +1 -1
- package/dist/dev/jsx/global.d.ts +2 -2
- package/dist/dev/jsx/html.d.ts +1 -1
- package/dist/dev/jsx/intrinsic.d.ts +1 -1
- package/dist/dev/jsx/mathml.d.ts +1 -1
- package/dist/dev/jsx/svg.d.ts +1 -1
- package/dist/dev/jsx-runtime.d.ts +3 -3
- package/dist/dev/render.js +22 -11
- package/dist/dev/render.js.map +1 -1
- package/dist/dev/server/class-style.js +1 -1
- package/dist/dev/server/element.js +3 -3
- package/dist/dev/server/form-controls.js +1 -1
- package/dist/dev/server/hydration-script.js +1 -1
- package/dist/dev/server/portals.js +1 -1
- package/dist/dev/server/raw-text.js +1 -1
- package/dist/dev/server/render.js +2 -2
- package/dist/dev/server/stream.js +3 -3
- package/dist/dev/spread.js +59 -84
- package/dist/dev/spread.js.map +1 -1
- package/dist/dev/template.js +3 -3
- package/dist/prod/attributes.js +1 -1
- package/dist/prod/attributes.js.map +1 -1
- package/dist/prod/class-style.js +1 -1
- package/dist/prod/class-style.js.map +1 -1
- package/dist/prod/control-flow/dynamic.js +1 -1
- package/dist/prod/control-flow/no-hydration.js +1 -1
- package/dist/prod/control-flow/portal.js +1 -1
- package/dist/prod/element.js +1 -1
- package/dist/prod/element.js.map +1 -1
- package/dist/prod/events.js +1 -1
- package/dist/prod/events.js.map +1 -1
- package/dist/prod/extend.js +1 -1
- package/dist/prod/head/use-head.js +1 -1
- package/dist/prod/head/validate.js +1 -1
- package/dist/prod/hydration.js +1 -1
- package/dist/prod/hydration.js.map +1 -1
- package/dist/prod/index.js +1 -1
- package/dist/prod/insert.js +1 -1
- package/dist/prod/insert.js.map +1 -1
- package/dist/prod/internal/reconcile.js +1 -1
- package/dist/prod/internal/reconcile.js.map +1 -1
- package/dist/prod/render.js +1 -1
- package/dist/prod/render.js.map +1 -1
- package/dist/prod/server/class-style.js +1 -1
- package/dist/prod/server/element.js +1 -1
- package/dist/prod/server/form-controls.js +2 -2
- package/dist/prod/server/hydration-script.js +1 -1
- package/dist/prod/server/portals.js +1 -1
- package/dist/prod/server/raw-text.js +1 -1
- package/dist/prod/server/render.js +1 -1
- package/dist/prod/server/stream.js +1 -1
- package/dist/prod/spread.js +1 -1
- package/dist/prod/spread.js.map +1 -1
- package/dist/prod/template.js +1 -1
- package/dist/server/attributes.js +1 -1
- package/dist/server/attributes.js.map +1 -1
- package/dist/server/class-style.js +1 -1
- package/dist/server/class-style.js.map +1 -1
- package/dist/server/control-flow/dynamic.js +1 -1
- package/dist/server/control-flow/portal.js +1 -1
- package/dist/server/control-flow/suspense.js +1 -1
- package/dist/server/element.js +1 -1
- package/dist/server/element.js.map +1 -1
- package/dist/server/events.js +1 -1
- package/dist/server/events.js.map +1 -1
- package/dist/server/extend.js +1 -1
- package/dist/server/head/use-head.js +1 -1
- package/dist/server/head/validate.js +1 -1
- package/dist/server/hydration.js +1 -1
- package/dist/server/hydration.js.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/insert.js +1 -1
- package/dist/server/insert.js.map +1 -1
- package/dist/server/internal/reconcile.js +1 -1
- package/dist/server/internal/reconcile.js.map +1 -1
- package/dist/server/render.js +1 -1
- package/dist/server/render.js.map +1 -1
- package/dist/server/server/class-style.js +1 -1
- package/dist/server/server/element.js +1 -1
- package/dist/server/server/form-controls.js +2 -2
- package/dist/server/server/hydration-script.js +1 -1
- package/dist/server/server/portals.js +1 -1
- package/dist/server/server/raw-text.js +1 -1
- package/dist/server/server/render.js +1 -1
- package/dist/server/server/stream.js +1 -1
- package/dist/server/spread.js +1 -1
- package/dist/server/spread.js.map +1 -1
- package/dist/server/template.js +1 -1
- package/dist/server-dev/attributes.js +1 -5
- package/dist/server-dev/attributes.js.map +1 -1
- package/dist/server-dev/class-style.js +15 -13
- package/dist/server-dev/class-style.js.map +1 -1
- package/dist/server-dev/control-flow/dynamic.js +1 -1
- package/dist/server-dev/control-flow/portal.js +1 -1
- package/dist/server-dev/control-flow/suspense.js +2 -2
- package/dist/server-dev/element.js +1 -1
- package/dist/server-dev/element.js.map +1 -1
- package/dist/server-dev/events.js +64 -80
- package/dist/server-dev/events.js.map +1 -1
- package/dist/server-dev/extend.js +6 -6
- package/dist/server-dev/head/use-head.js +1 -1
- package/dist/server-dev/head/validate.js +1 -1
- package/dist/server-dev/hydration.js +21 -13
- package/dist/server-dev/hydration.js.map +1 -1
- package/dist/server-dev/index.js +6 -6
- package/dist/server-dev/insert.js +50 -68
- package/dist/server-dev/insert.js.map +1 -1
- package/dist/server-dev/internal/reconcile.js +19 -2
- package/dist/server-dev/internal/reconcile.js.map +1 -1
- package/dist/server-dev/render.js +22 -11
- package/dist/server-dev/render.js.map +1 -1
- package/dist/server-dev/server/class-style.js +1 -1
- package/dist/server-dev/server/element.js +3 -3
- package/dist/server-dev/server/form-controls.js +1 -1
- package/dist/server-dev/server/hydration-script.js +1 -1
- package/dist/server-dev/server/portals.js +1 -1
- package/dist/server-dev/server/raw-text.js +1 -1
- package/dist/server-dev/server/render.js +2 -2
- package/dist/server-dev/server/stream.js +3 -3
- package/dist/server-dev/spread.js +59 -84
- package/dist/server-dev/spread.js.map +1 -1
- package/dist/server-dev/template.js +3 -3
- package/package.json +3 -3
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
// src/internal/reconcile.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runs `run`, which moves nodes in the tree of `at` without `moveBefore`: a browser blurs a focused
|
|
4
|
+
* element that `insertBefore` moves, so a focused element of that tree that lost the focus gets it
|
|
5
|
+
* back, without scrolling. A text control keeps its selection across the move, and `focus()` keeps
|
|
6
|
+
* it. The focused element is read once, before `run`.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function keepFocus(at, run) {
|
|
10
|
+
const root = at.getRootNode();
|
|
11
|
+
const active = root.activeElement;
|
|
12
|
+
run();
|
|
13
|
+
if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });
|
|
14
|
+
}
|
|
2
15
|
/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */
|
|
3
16
|
function removeNode(parent, node) {
|
|
4
17
|
if (node !== void 0 && node.parentNode === parent) parent.removeChild(node);
|
|
@@ -44,7 +57,8 @@ function markLongestIncreasing(values, offset, marks) {
|
|
|
44
57
|
* 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of
|
|
45
58
|
* surviving positions stay where they are; every other node is moved (or inserted) directly
|
|
46
59
|
* before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,
|
|
47
|
-
* which keeps focus and iframe state, and `insertBefore` otherwise
|
|
60
|
+
* which keeps focus and iframe state, and `insertBefore` otherwise (a focused element that the move
|
|
61
|
+
* blurred gets the focus back). Each node moves at most once,
|
|
48
62
|
* and the number of moves is minimal for the surviving order.
|
|
49
63
|
*
|
|
50
64
|
* @param parent The parent of the region.
|
|
@@ -101,6 +115,8 @@ function reconcileNodes(parent, prev, next, end) {
|
|
|
101
115
|
const stable = new Uint8Array(nextTail - head);
|
|
102
116
|
markLongestIncreasing(survivors, head, stable);
|
|
103
117
|
const movable = typeof parent.moveBefore === "function";
|
|
118
|
+
const root = parent.getRootNode();
|
|
119
|
+
const active = movable ? null : root.activeElement;
|
|
104
120
|
let anchorNode = before;
|
|
105
121
|
for (let index = nextTail - 1; index >= head; index -= 1) {
|
|
106
122
|
const node = next[index];
|
|
@@ -110,7 +126,8 @@ function reconcileNodes(parent, prev, next, end) {
|
|
|
110
126
|
}
|
|
111
127
|
anchorNode = node;
|
|
112
128
|
}
|
|
129
|
+
if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });
|
|
113
130
|
}
|
|
114
|
-
export { reconcileNodes };
|
|
131
|
+
export { keepFocus, reconcileNodes };
|
|
115
132
|
|
|
116
133
|
//# sourceMappingURL=reconcile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile.js","names":[],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] as number;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] as number] as number;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n // `tails[-1]` is undefined, which reads as no predecessor.\n previous[index] = tails[low - 1] ?? -1;\n tails[low] = index;\n }\n let cursor = tails.at(-1) ?? -1;\n while (cursor !== -1) {\n marks[(values[cursor] as number) - offset] = 1;\n cursor = previous[cursor] as number;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index] as Node;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n // Nothing survived: the new nodes go in document order. Inserting them back to front (the move loop below)\n // ends with the same tree but not the same steps, and a `<select>` picks its shown option while its options\n // arrive, so a replaced option list would show the wrong value.\n if (survivors.length === 0) {\n for (const node of next.slice(head, nextTail)) parent.insertBefore(node, before);\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index] as Node;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reconcile.js","names":[],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/**\n * Runs `run`, which moves nodes in the tree of `at` without `moveBefore`: a browser blurs a focused\n * element that `insertBefore` moves, so a focused element of that tree that lost the focus gets it\n * back, without scrolling. A text control keeps its selection across the move, and `focus()` keeps\n * it. The focused element is read once, before `run`.\n * @internal\n */\nexport function keepFocus(at: Node, run: () => void): void {\n const root = at.getRootNode() as Partial<DocumentOrShadowRoot>;\n const active = root.activeElement as HTMLElement | null | undefined;\n run();\n if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] as number;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] as number] as number;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n // `tails[-1]` is undefined, which reads as no predecessor.\n previous[index] = tails[low - 1] ?? -1;\n tails[low] = index;\n }\n let cursor = tails.at(-1) ?? -1;\n while (cursor !== -1) {\n marks[(values[cursor] as number) - offset] = 1;\n cursor = previous[cursor] as number;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise (a focused element that the move\n * blurred gets the focus back). Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index] as Node;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n // Nothing survived: the new nodes go in document order. Inserting them back to front (the move loop below)\n // ends with the same tree but not the same steps, and a `<select>` picks its shown option while its options\n // arrive, so a replaced option list would show the wrong value.\n if (survivors.length === 0) {\n for (const node of next.slice(head, nextTail)) parent.insertBefore(node, before);\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n // Without moveBefore, insertBefore blurs a focused element it moves: the focused element is read once\n // for the pass and gets the focus back (without scrolling) when the moves took it.\n const root = parent.getRootNode() as Partial<DocumentOrShadowRoot>;\n const active = movable ? null : (root.activeElement as HTMLElement | null | undefined);\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index] as Node;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n if (active != null && root.activeElement !== active) active.focus({ preventScroll: true });\n}\n"],"mappings":";;;;;;;;AAYA,SAAgB,UAAU,IAAU,KAAuB;CACzD,MAAM,OAAO,GAAG,YAAY;CAC5B,MAAM,SAAS,KAAK;CACpB,IAAI;CACJ,IAAI,UAAU,QAAQ,KAAK,kBAAkB,QAAQ,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;AAC3F;;AAGA,SAAS,WAAW,QAAc,MAA8B;CAC9D,IAAI,SAAS,KAAA,KAAa,KAAK,eAAe,QAAQ,OAAO,YAAY,IAAI;AAC/E;;;;;;AAOA,SAAS,sBAAsB,QAA2B,QAAgB,OAAyB;CAEjG,MAAM,QAAkB,CAAC;CACzB,MAAM,WAAqB,OAAO,UAAU,EAAE;CAC9C,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAAG;EACrD,MAAM,QAAQ,OAAO;EACrB,IAAI,MAAM;EACV,IAAI,OAAO,MAAM;EACjB,OAAO,MAAM,MAAM;GACjB,MAAM,SAAU,MAAM,QAAS;GAE/B,IADc,OAAO,MAAM,WACf,OAAO,MAAM,SAAS;QAC7B,OAAO;EACd;EAEA,SAAS,SAAS,MAAM,MAAM,MAAM;EACpC,MAAM,OAAO;CACf;CACA,IAAI,SAAS,MAAM,GAAG,EAAE,KAAK;CAC7B,OAAO,WAAW,IAAI;EACpB,MAAO,OAAO,UAAqB,UAAU;EAC7C,SAAS,SAAS;CACpB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,eACd,QACA,MACA,MACA,KACM;CACN,MAAM,aAAa,KAAK;CACxB,MAAM,aAAa,KAAK;CAExB,IAAI,OAAO;CACX,OAAO,OAAO,cAAc,OAAO,cAAc,KAAK,UAAU,KAAK,OAAO,QAAQ;CACpF,IAAI,WAAW;CACf,IAAI,WAAW;CACf,OAAO,WAAW,QAAQ,WAAW,QAAQ,KAAK,WAAW,OAAO,KAAK,WAAW,IAAI;EACtF,YAAY;EACZ,YAAY;CACd;CACA,IAAI,aAAa,QAAQ,aAAa,MAAM;CAG5C,MAAM,SAAS,WAAW,aAAc,KAAK,aAAa,OAAQ;CAElE,IAAI,aAAa,MAAM;EACrB,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG,WAAW,QAAQ,KAAK,MAAM;EACnF;CACF;CAEA,MAAM,yBAAS,IAAI,IAAkB;CACrC,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG;EACnD,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,KAAA,GAAW,OAAO,IAAI,MAAM,KAAK;CAChD;CAEA,MAAM,YAAsB,CAAC;CAC7B,KAAK,IAAI,QAAQ,MAAM,QAAQ,UAAU,SAAS,GAAG;EACnD,MAAM,OAAO,KAAK;EAClB,MAAM,WAAW,OAAO,IAAI,IAAI;EAChC,IAAI,aAAa,KAAA,GAAW,WAAW,QAAQ,IAAI;OAC9C,UAAU,KAAK,QAAQ;CAC9B;CAKA,IAAI,UAAU,WAAW,GAAG;EAC1B,KAAK,MAAM,QAAQ,KAAK,MAAM,MAAM,QAAQ,GAAG,OAAO,aAAa,MAAM,MAAM;EAC/E;CACF;CAEA,MAAM,SAAS,IAAI,WAAW,WAAW,IAAI;CAC7C,sBAAsB,WAAW,MAAM,MAAM;CAC7C,MAAM,UAAU,OAAQ,OAAkC,eAAe;CAIzE,MAAM,OAAO,OAAO,YAAY;CAChC,MAAM,SAAS,UAAU,OAAQ,KAAK;CACtC,IAAI,aAAa;CACjB,KAAK,IAAI,QAAQ,WAAW,GAAG,SAAS,MAAM,SAAS,GAAG;EACxD,MAAM,OAAO,KAAK;EAClB,IAAI,OAAO,QAAQ,UAAU,GAAG;GAC9B,IAAI,WAAW,KAAK,eAAe,QACjC,OAA0B,WAAW,MAAM,UAAU;QAClD,OAAO,aAAa,MAAM,UAAU;EAC3C;EACA,aAAa;CACf;CACA,IAAI,UAAU,QAAQ,KAAK,kBAAkB,QAAQ,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;AAC3F"}
|
package/dist/dev/jsx/global.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Booleanish, CSSProperties, CSSPropertyValue, ClassValue, JsxChild, Maybe, Ref, TextChild } from "./types.js";
|
|
2
|
-
import { EventAttributes, MediaEventAttributes, VideoEventAttributes, WindowEventAttributes } from "./events.js";
|
|
3
1
|
import { AriaAttributes } from "./aria.js";
|
|
2
|
+
import { EventAttributes, MediaEventAttributes, VideoEventAttributes, WindowEventAttributes } from "./events.js";
|
|
3
|
+
import { Booleanish, CSSProperties, CSSPropertyValue, ClassValue, JsxChild, Maybe, Ref, TextChild } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Values accepted by `data-*` attributes. `true` and `false` are written as the strings "true" and
|
|
6
6
|
* "false", so they are not presence flags.
|
package/dist/dev/jsx/html.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LooseString, Maybe } from "./types.js";
|
|
2
1
|
import { Aliases, ElementProps, MediaElementProps, TextElementProps, VideoElementProps, VoidElementProps, WindowElementProps } from "./global.js";
|
|
2
|
+
import { LooseString, Maybe } from "./types.js";
|
|
3
3
|
/** Targets of links and forms. Any other browsing-context name is also accepted. @since 1.0.0 */
|
|
4
4
|
export type LinkTarget = LooseString<"_self" | "_blank" | "_parent" | "_top">;
|
|
5
5
|
/** Referrer policies, as in the HTML standard. @since 1.0.0 */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { JsxChild, MathMLTagElement, Maybe } from "./types.js";
|
|
2
1
|
import { Aliases, ElementProps, GlobalAttributes, TextElementProps } from "./global.js";
|
|
3
2
|
import { AnchorAttributes, HTMLIntrinsicElements, ScriptAttributes, StyleElementAttributes } from "./html.js";
|
|
4
3
|
import { MathMLGlobalAttributes, MathMLIntrinsicElements } from "./mathml.js";
|
|
5
4
|
import { SVGAnchorAttributes, SVGCoreAttributes, SVGHrefAttributes, SVGIntrinsicElements, SVGPresentationAttributes, SVGReactPresentationAttributes } from "./svg.js";
|
|
5
|
+
import { JsxChild, MathMLTagElement, Maybe } from "./types.js";
|
|
6
6
|
/** The DOM element a shared `a` may be. @internal */
|
|
7
7
|
type AnchorElement = HTMLElementTagNameMap["a"] | SVGElementTagNameMap["a"] | MathMLTagElement<"a">;
|
|
8
8
|
/** The DOM element a shared `script` may be. @internal */
|
package/dist/dev/jsx/mathml.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Booleanish, MathMLTagElement, Maybe } from "./types.js";
|
|
2
1
|
import { ElementProps, VoidElementProps } from "./global.js";
|
|
2
|
+
import { Booleanish, MathMLTagElement, Maybe } from "./types.js";
|
|
3
3
|
/** A MathML length or unitless number, e.g. `"2em"`, `"thin"`, `3`. @since 1.0.0 */
|
|
4
4
|
export type MathValue = Maybe<number | string>;
|
|
5
5
|
/** The `mathvariant` presentation values. @since 1.0.0 */
|
package/dist/dev/jsx/svg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LooseString, Maybe } from "./types.js";
|
|
2
1
|
import { ElementProps, TextElementProps, VoidElementProps, WindowElementProps } from "./global.js";
|
|
2
|
+
import { LooseString, Maybe } from "./types.js";
|
|
3
3
|
/** A length, coordinate, or other SVG number. Plain numbers are user units. @since 1.0.0 */
|
|
4
4
|
export type SvgValue = Maybe<number | string>;
|
|
5
5
|
/** Coordinate-system units of gradients, patterns, clip paths and masks. @since 1.0.0 */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Booleanish, CSSProperties, ClassValue, JsxChild, Maybe, MaybeAccessor, Ref, RefOf, TextChild } from "./jsx/types.js";
|
|
2
1
|
import { Component, FlowComponent, ParentComponent, ParentProps, VoidComponent, VoidProps } from "./jsx/component.js";
|
|
3
2
|
import { BoundEventHandler, CustomEventProps, EventHandler, EventHandlerProp, ListenerObject } from "./jsx/events.js";
|
|
4
|
-
import { AriaAttributes, AriaRole } from "./jsx/aria.js";
|
|
5
3
|
import { DirectiveProps } from "./jsx/global.js";
|
|
4
|
+
import { AriaAttributes, AriaRole } from "./jsx/aria.js";
|
|
5
|
+
import { CustomElementProps, IntrinsicElementMap } from "./jsx/intrinsic.js";
|
|
6
6
|
import { HTMLIntrinsicElements } from "./jsx/html.js";
|
|
7
7
|
import { MathMLIntrinsicElements } from "./jsx/mathml.js";
|
|
8
8
|
import { SVGIntrinsicElements } from "./jsx/svg.js";
|
|
9
|
-
import {
|
|
9
|
+
import { Booleanish, CSSProperties, ClassValue, JsxChild, Maybe, MaybeAccessor, Ref, RefOf, TextChild } from "./jsx/types.js";
|
|
10
10
|
/**
|
|
11
11
|
* The app's custom events, by name, for the `on:` and `oncapture:` prefixes: declaration-merge it so
|
|
12
12
|
* `on:toast={...}` receives a typed event. Empty by default; a name without an entry is not accepted
|
package/dist/dev/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { withScope } from "./internal/hydration-scope.js";
|
|
2
|
-
import { claims } from "./internal/hydration-hooks.js";
|
|
3
|
-
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
4
1
|
import { attachRootErrors } from "./control-flow/root-errors.js";
|
|
2
|
+
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
3
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
4
|
+
import { withScope } from "./internal/hydration-scope.js";
|
|
5
5
|
import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
|
|
6
6
|
// src/render.ts
|
|
7
7
|
/**
|
|
@@ -32,19 +32,30 @@ import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
|
|
|
32
32
|
*/
|
|
33
33
|
function render(code, container, options) {
|
|
34
34
|
const region = createRegion(container, null, void 0);
|
|
35
|
-
|
|
36
|
-
if (options !== void 0) attachRootErrors(options);
|
|
37
|
-
bindRegion(region, untrack(code));
|
|
38
|
-
return dispose;
|
|
39
|
-
}))));
|
|
40
|
-
flushSync();
|
|
35
|
+
let stop;
|
|
41
36
|
let disposed = false;
|
|
42
|
-
|
|
37
|
+
const teardown = () => {
|
|
43
38
|
if (disposed) return;
|
|
44
39
|
disposed = true;
|
|
45
|
-
stop();
|
|
40
|
+
stop?.();
|
|
46
41
|
removeRegion(region);
|
|
47
42
|
};
|
|
43
|
+
try {
|
|
44
|
+
claims.current.withoutClaiming(() => withScope(null, () => batch(() => createRoot((dispose) => {
|
|
45
|
+
stop = dispose;
|
|
46
|
+
if (options !== void 0) attachRootErrors(options);
|
|
47
|
+
bindRegion(region, untrack(code));
|
|
48
|
+
}))));
|
|
49
|
+
flushSync();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
try {
|
|
52
|
+
teardown();
|
|
53
|
+
} catch (cleanupError) {
|
|
54
|
+
throw new AggregateError([error, cleanupError], "render() failed and so did its teardown.");
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
return teardown;
|
|
48
59
|
}
|
|
49
60
|
export { render };
|
|
50
61
|
|
package/dist/dev/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":[],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n try {\n claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n stop = dispose;\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n }),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a render that throws (an effect of the first flush failed),\n // so the root must not stay alive with its DOM and effects.\n try {\n teardown();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"render() failed and so did its teardown.\" : \"SHADOW_RENDER_ERRORS\",\n );\n }\n throw error;\n }\n return teardown;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,OACd,MACA,WACA,SACY;CACZ,MAAM,SAAS,aAAa,WAAW,MAAM,KAAA,CAAS;CACtD,IAAI;CACJ,IAAI,WAAW;CACf,MAAM,iBAAuB;EAC3B,IAAI,UAAU;EACd,WAAW;EACX,OAAO;EACP,aAAa,MAAM;CACrB;CAKA,IAAI;EACF,OAAO,QAAQ,sBACb,UAAU,YACR,YACE,YAAY,YAAY;GACtB,OAAO;GAEP,IAAI,YAAY,KAAA,GAAW,iBAAiB,OAAO;GAEnD,WAAW,QAAQ,QAAQ,IAAI,CAAC;EAClC,CAAC,CACH,CACF,CACF;EACA,UAAU;CACZ,SAAS,OAAO;EAGd,IAAI;GACF,SAAS;EACX,SAAS,cAAc;GACrB,MAAM,IAAI,eACR,CAAC,OAAO,YAAY,GACV,0CACZ;EACF;EACA,MAAM;CACR;CACA,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cssValueText } from "../internal/css-units.js";
|
|
2
2
|
import { invalid } from "./errors.js";
|
|
3
|
-
import { isSsrNode } from "./node.js";
|
|
4
3
|
import { escapeHtml, resolveValue } from "./escape.js";
|
|
4
|
+
import { isSsrNode } from "./node.js";
|
|
5
5
|
// src/server/class-style.ts
|
|
6
6
|
/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */
|
|
7
7
|
const CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { nextKey } from "../internal/hydration-scope.js";
|
|
2
2
|
import { IGNORED_KEYS, attributeName, isFlagAttribute } from "../internal/react-names.js";
|
|
3
|
-
import { invalid } from "./errors.js";
|
|
4
|
-
import { SsrNode, isSsrNode } from "./node.js";
|
|
5
|
-
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
6
3
|
import { isEventName, ssrAttribute } from "./attributes.js";
|
|
7
4
|
import { classText, ssrStyle, styleText } from "./class-style.js";
|
|
5
|
+
import { invalid } from "./errors.js";
|
|
6
|
+
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
8
7
|
import { keepLeadingNewline, markSelectedOptions, textareaContent } from "./form-controls.js";
|
|
8
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
9
9
|
import { rawElementContent } from "./raw-text.js";
|
|
10
10
|
// src/server/element.ts
|
|
11
11
|
/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invalid } from "./errors.js";
|
|
2
|
-
import { SsrNode } from "./node.js";
|
|
3
2
|
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
3
|
+
import { SsrNode } from "./node.js";
|
|
4
4
|
// src/server/form-controls.ts
|
|
5
5
|
/**
|
|
6
6
|
* Server markup for the controls whose state is not an attribute. A browser ignores `value` on a
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { childScope, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { PortalContext } from "../internal/portal-context.js";
|
|
2
3
|
import { SsrError } from "./errors.js";
|
|
3
4
|
import { escape } from "./escape.js";
|
|
4
|
-
import { PortalContext } from "../internal/portal-context.js";
|
|
5
5
|
/** The collector behind a {@link ServerPortals}: what a renderer writes into while it renders. @internal */
|
|
6
6
|
var PortalCollector = class {
|
|
7
7
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invalid } from "./errors.js";
|
|
2
|
-
import { SsrNode, isSsrNode } from "./node.js";
|
|
3
2
|
import { render, resolveValue } from "./escape.js";
|
|
3
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
4
4
|
// src/server/raw-text.ts
|
|
5
5
|
/** The elements whose text the parser reads raw. */
|
|
6
6
|
const RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style"]);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
2
|
+
import { runWithServerHead } from "../head/server-head.js";
|
|
1
3
|
import { createRootScope, resourceKey, withScope } from "../internal/hydration-scope.js";
|
|
2
4
|
import { MAX_TIMER_MS, SsrError } from "./errors.js";
|
|
3
5
|
import { escape } from "./escape.js";
|
|
4
|
-
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
5
|
-
import { runWithServerHead } from "../head/server-head.js";
|
|
6
6
|
import { portalCollectorFor, withPortalSink } from "./portals.js";
|
|
7
7
|
import { ResourceCacheContext, createRoot } from "@shadow-js/core";
|
|
8
8
|
// src/server/render.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
2
|
+
import { runWithServerHead } from "../head/server-head.js";
|
|
1
3
|
import { createRootScope, resourceKey, withScope } from "../internal/hydration-scope.js";
|
|
4
|
+
import { StreamContext } from "../internal/stream-context.js";
|
|
2
5
|
import { MAX_TIMER_MS, SsrError } from "./errors.js";
|
|
3
6
|
import { escape } from "./escape.js";
|
|
4
|
-
import { StreamContext } from "../internal/stream-context.js";
|
|
5
|
-
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
6
|
-
import { runWithServerHead } from "../head/server-head.js";
|
|
7
7
|
import { portalCollectorFor, withPortalSink } from "./portals.js";
|
|
8
8
|
import { serialize } from "./serialize.js";
|
|
9
9
|
import { ResourceCacheContext, createRoot, untrack } from "@shadow-js/core";
|
package/dist/dev/spread.js
CHANGED
|
@@ -1,56 +1,22 @@
|
|
|
1
1
|
import { setAttribute, setAttributeNS, setBoolAttribute } from "./attributes.js";
|
|
2
2
|
import { autoFocus } from "./autofocus.js";
|
|
3
3
|
import { applyClass, asRecord, classList, style } from "./class-style.js";
|
|
4
|
-
import {
|
|
4
|
+
import { bindEvent } from "./events.js";
|
|
5
5
|
import { bindRegion, createRegion, watchCommits } from "./insert.js";
|
|
6
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
6
7
|
import { IGNORED_KEYS, attributeName, eventPlan, isFlagAttribute } from "./internal/react-names.js";
|
|
7
|
-
import { bindEvent } from "./events.js";
|
|
8
8
|
import { plainText, setSelectValue } from "./select-value.js";
|
|
9
9
|
import { onCleanup, untrack, useRenderEffect } from "@shadow-js/core";
|
|
10
10
|
// src/spread.ts
|
|
11
11
|
/** The namespace of `xlink:` attributes (SVG's legacy links). */
|
|
12
12
|
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
13
|
-
/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`); null and undefined mean empty. */
|
|
14
|
-
function innerHtmlValue(value) {
|
|
15
|
-
if (value === null || typeof value !== "object") return "";
|
|
16
|
-
return plainText(Reflect.get(value, "__html"));
|
|
17
|
-
}
|
|
18
13
|
/** Keys that would reach a prototype if written as properties. Ignored everywhere. */
|
|
19
14
|
const FORBIDDEN_NAMES = /^(?:__proto__|constructor|prototype)$/;
|
|
20
|
-
/** True for `on*` keys, which bind event handlers. */
|
|
21
|
-
function isEventKey(key) {
|
|
22
|
-
return key.length > 2 && key.startsWith("on");
|
|
23
|
-
}
|
|
24
|
-
/** The name after a `prop:`, `attr:` or `bool:` namespace, or the whole key. */
|
|
25
|
-
function nameOf(key) {
|
|
26
|
-
const colon = key.indexOf(":");
|
|
27
|
-
return colon === -1 ? key : key.slice(colon + 1);
|
|
28
|
-
}
|
|
29
|
-
/** Reads every prop except children, inside the render effect so each read is tracked. */
|
|
30
|
-
function readEntries(props, textarea) {
|
|
31
|
-
const entries = [];
|
|
32
|
-
if (props === null || typeof props !== "object") return entries;
|
|
33
|
-
let value;
|
|
34
|
-
let hasValue = false;
|
|
35
|
-
for (const key of Object.keys(props)) {
|
|
36
|
-
if (FORBIDDEN_NAMES.test(nameOf(key)) || IGNORED_KEYS.test(key)) continue;
|
|
37
|
-
if (key === "children") {
|
|
38
|
-
if (textarea) {
|
|
39
|
-
value = Reflect.get(props, key);
|
|
40
|
-
hasValue = true;
|
|
41
|
-
}
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
entries.push([key, Reflect.get(props, key)]);
|
|
45
|
-
}
|
|
46
|
-
if (hasValue && !entries.some(([key]) => key === "value")) entries.push(["value", value]);
|
|
47
|
-
return entries;
|
|
48
|
-
}
|
|
49
15
|
/** Runs and forgets the cleanup the last ref callback returned, if any. */
|
|
50
16
|
function runRefCleanup(state) {
|
|
51
|
-
const cleanup = state.
|
|
17
|
+
const cleanup = state.unref;
|
|
52
18
|
if (cleanup === void 0) return;
|
|
53
|
-
state.
|
|
19
|
+
state.unref = void 0;
|
|
54
20
|
untrack(cleanup);
|
|
55
21
|
}
|
|
56
22
|
/** Applies one prop that is new or changed. */
|
|
@@ -60,13 +26,13 @@ function applyKey(el, key, value, state, svg) {
|
|
|
60
26
|
if (typeof value === "function") {
|
|
61
27
|
const callRef = value;
|
|
62
28
|
const cleanup = untrack(() => callRef(el));
|
|
63
|
-
if (typeof cleanup === "function") state.
|
|
29
|
+
if (typeof cleanup === "function") state.unref = cleanup;
|
|
64
30
|
}
|
|
65
31
|
return;
|
|
66
32
|
}
|
|
67
33
|
if (key === "autoFocus") {
|
|
68
|
-
if (!state.
|
|
69
|
-
state.
|
|
34
|
+
if (!state.focused) {
|
|
35
|
+
state.focused = true;
|
|
70
36
|
autoFocus(el, value);
|
|
71
37
|
}
|
|
72
38
|
return;
|
|
@@ -76,27 +42,27 @@ function applyKey(el, key, value, state, svg) {
|
|
|
76
42
|
return;
|
|
77
43
|
}
|
|
78
44
|
if (key === "style") {
|
|
79
|
-
state.
|
|
45
|
+
state.styled = style(el, value, state.styled);
|
|
80
46
|
return;
|
|
81
47
|
}
|
|
82
48
|
if (key === "classList") {
|
|
83
|
-
state.
|
|
49
|
+
state.listed = classList(el, asRecord(value), state.listed);
|
|
84
50
|
return;
|
|
85
51
|
}
|
|
86
|
-
if (
|
|
87
|
-
state.
|
|
88
|
-
state.
|
|
52
|
+
if (key.length > 2 && key.startsWith("on")) {
|
|
53
|
+
state.unbind.get(key)?.();
|
|
54
|
+
state.unbind.delete(key);
|
|
89
55
|
const plan = eventPlan(key, el.localName, el.getAttribute("type")?.toLowerCase() ?? null);
|
|
90
56
|
const handler = plan.passive && typeof value === "function" ? {
|
|
91
57
|
handleEvent: value,
|
|
92
58
|
passive: true
|
|
93
59
|
} : value;
|
|
94
60
|
const unbind = bindEvent(el, plan.type, handler, true, plan.capture);
|
|
95
|
-
if (unbind !== void 0) state.
|
|
61
|
+
if (unbind !== void 0) state.unbind.set(key, unbind);
|
|
96
62
|
return;
|
|
97
63
|
}
|
|
98
64
|
if (key === "innerHTML" || key === "dangerouslySetInnerHTML") {
|
|
99
|
-
el.innerHTML = key === "innerHTML" ?
|
|
65
|
+
el.innerHTML = plainText(key === "innerHTML" ? value : value !== null && typeof value === "object" ? Reflect.get(value, "__html") : void 0);
|
|
100
66
|
return;
|
|
101
67
|
}
|
|
102
68
|
if (key === "textContent") {
|
|
@@ -107,19 +73,11 @@ function applyKey(el, key, value, state, svg) {
|
|
|
107
73
|
setSelectValue(el, value);
|
|
108
74
|
return;
|
|
109
75
|
}
|
|
110
|
-
if (!svg && LIVE_PROPERTIES.test(key) && key in el) {
|
|
76
|
+
if (!svg && LIVE_PROPERTIES.test(key) && key in el && !isMeasure(el, key)) {
|
|
111
77
|
liveDiffers(el, key, value, svg) && Reflect.set(el, key, STRING_PROPERTIES.test(key) ? value ?? "" : Boolean(value));
|
|
112
78
|
if (key === "value" && el instanceof HTMLInputElement) el.defaultValue = plainText(value);
|
|
113
79
|
return;
|
|
114
80
|
}
|
|
115
|
-
writeKey(el, key, value, svg);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Writes one prop by its key: a `prop:` property, an `attr:` or `bool:` attribute, or an attribute
|
|
119
|
-
* under its React name. An `undefined` value removes the attribute or resets the property, which is how
|
|
120
|
-
* a prop that disappeared is undone.
|
|
121
|
-
*/
|
|
122
|
-
function writeKey(el, key, value, svg) {
|
|
123
81
|
if (key.startsWith("prop:")) Reflect.set(el, key.slice(5), value);
|
|
124
82
|
else if (key.startsWith("attr:")) setAttribute(el, key.slice(5), value);
|
|
125
83
|
else if (key.startsWith("bool:")) setBoolAttribute(el, key.slice(5), value);
|
|
@@ -135,34 +93,24 @@ const LIVE_PROPERTIES = /^(?:value|checked|selected|muted|indeterminate|defaultV
|
|
|
135
93
|
/** The properties of {@link LIVE_PROPERTIES} that hold text; the others are booleans. */
|
|
136
94
|
const STRING_PROPERTIES = /^(?:value|defaultValue)$/;
|
|
137
95
|
/**
|
|
96
|
+
* True for the `value` of a `progress`, `meter` or `li`: a number property that turns `undefined` into `0` and
|
|
97
|
+
* writes `value="0"`, where the server leaves the attribute out (an indeterminate bar, an unnumbered item). It is written as
|
|
98
|
+
* an attribute, which `setAttribute` removes for `null` and `undefined`, like the compiler does.
|
|
99
|
+
*/
|
|
100
|
+
function isMeasure(el, key) {
|
|
101
|
+
return key === "value" && (el.localName === "progress" || el.localName === "meter" || el.localName === "li");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
138
104
|
* True when a live property (typed value, toggled box) no longer matches the value last applied, so
|
|
139
105
|
* an unchanged prop is written again and the element follows the data.
|
|
140
106
|
*/
|
|
141
107
|
function liveDiffers(el, key, value, svg) {
|
|
142
|
-
if (svg || !LIVE_PROPERTIES.test(key) || !(key in el)) return false;
|
|
108
|
+
if (svg || !LIVE_PROPERTIES.test(key) || !(key in el) || isMeasure(el, key)) return false;
|
|
143
109
|
if (key === "value" && el instanceof HTMLSelectElement) return true;
|
|
144
110
|
const live = Reflect.get(el, key);
|
|
145
111
|
return STRING_PROPERTIES.test(key) ? live !== plainText(value) : live !== Boolean(value);
|
|
146
112
|
}
|
|
147
113
|
/**
|
|
148
|
-
* Applies the entries that changed since the last run and undoes the ones that disappeared.
|
|
149
|
-
* Unchanged values are skipped by identity, so only changed keys touch the DOM.
|
|
150
|
-
*/
|
|
151
|
-
function applyEntries(el, entries, state, svg) {
|
|
152
|
-
const current = /* @__PURE__ */ new Set();
|
|
153
|
-
for (const [key, value] of entries) {
|
|
154
|
-
current.add(key);
|
|
155
|
-
if (state.values.has(key) && Object.is(state.values.get(key), value) && !liveDiffers(el, key, value, svg)) continue;
|
|
156
|
-
state.values.set(key, value);
|
|
157
|
-
applyKey(el, key, value, state, svg);
|
|
158
|
-
}
|
|
159
|
-
for (const key of [...state.values.keys()]) {
|
|
160
|
-
if (current.has(key)) continue;
|
|
161
|
-
state.values.delete(key);
|
|
162
|
-
applyKey(el, key, void 0, state, svg);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
114
|
* Applies a whole props object to an element and keeps it in sync: the helper compiled JSX calls for
|
|
167
115
|
* `{...props}` on an element. The props are read inside a render effect, so a getter (or the props
|
|
168
116
|
* accessor) that changes rewrites only the keys whose values changed, and a key that disappears is
|
|
@@ -235,10 +183,7 @@ function followOptions(el, isSVG, state) {
|
|
|
235
183
|
function newState() {
|
|
236
184
|
return {
|
|
237
185
|
values: /* @__PURE__ */ new Map(),
|
|
238
|
-
|
|
239
|
-
styleValue: void 0,
|
|
240
|
-
classListValue: void 0,
|
|
241
|
-
refCleanup: void 0
|
|
186
|
+
unbind: /* @__PURE__ */ new Map()
|
|
242
187
|
};
|
|
243
188
|
}
|
|
244
189
|
/**
|
|
@@ -257,12 +202,42 @@ function spreadProps(el, props, isSVG) {
|
|
|
257
202
|
function applyProps(el, read, isSVG, state) {
|
|
258
203
|
const textarea = el.localName === "textarea";
|
|
259
204
|
onCleanup(() => {
|
|
260
|
-
for (const unbind of state.
|
|
261
|
-
state.
|
|
205
|
+
for (const unbind of state.unbind.values()) unbind();
|
|
206
|
+
state.unbind.clear();
|
|
262
207
|
runRefCleanup(state);
|
|
263
208
|
});
|
|
264
|
-
useRenderEffect(() =>
|
|
265
|
-
|
|
209
|
+
useRenderEffect(() => {
|
|
210
|
+
const props = read();
|
|
211
|
+
const entries = [];
|
|
212
|
+
if (props === null || typeof props !== "object") return entries;
|
|
213
|
+
let value;
|
|
214
|
+
let hasValue = false;
|
|
215
|
+
for (const key of Object.keys(props)) {
|
|
216
|
+
if (FORBIDDEN_NAMES.test(key.slice(key.indexOf(":") + 1)) || IGNORED_KEYS.test(key)) continue;
|
|
217
|
+
if (key === "children") {
|
|
218
|
+
if (textarea) {
|
|
219
|
+
value = Reflect.get(props, key);
|
|
220
|
+
hasValue = true;
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
entries.push([key, Reflect.get(props, key)]);
|
|
225
|
+
}
|
|
226
|
+
if (hasValue && !entries.some(([key]) => key === "value")) entries.push(["value", value]);
|
|
227
|
+
return entries;
|
|
228
|
+
}, (entries) => {
|
|
229
|
+
const current = /* @__PURE__ */ new Set();
|
|
230
|
+
for (const [key, value] of entries) {
|
|
231
|
+
current.add(key);
|
|
232
|
+
if (state.values.has(key) && Object.is(state.values.get(key), value) && !liveDiffers(el, key, value, isSVG)) continue;
|
|
233
|
+
state.values.set(key, value);
|
|
234
|
+
applyKey(el, key, value, state, isSVG);
|
|
235
|
+
}
|
|
236
|
+
for (const key of [...state.values.keys()]) {
|
|
237
|
+
if (current.has(key)) continue;
|
|
238
|
+
state.values.delete(key);
|
|
239
|
+
applyKey(el, key, void 0, state, isSVG);
|
|
240
|
+
}
|
|
266
241
|
});
|
|
267
242
|
}
|
|
268
243
|
export { spread, spreadProps };
|