ripple 0.3.127 → 0.4.0
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 +293 -0
- package/package.json +10 -4
- package/src/runtime/element.js +23 -6
- package/src/runtime/index-client.js +81 -41
- package/src/runtime/index-server.js +1 -0
- package/src/runtime/internal/client/blocks.js +192 -114
- package/src/runtime/internal/client/component.js +4 -30
- package/src/runtime/internal/client/composite.js +12 -13
- package/src/runtime/internal/client/constants.js +14 -5
- package/src/runtime/internal/client/context.js +12 -19
- package/src/runtime/internal/client/css.js +7 -9
- package/src/runtime/internal/client/events.js +178 -90
- package/src/runtime/internal/client/expression.js +185 -124
- package/src/runtime/internal/client/for.js +616 -264
- package/src/runtime/internal/client/head.js +10 -5
- package/src/runtime/internal/client/html.js +1 -0
- package/src/runtime/internal/client/hydration.js +152 -10
- package/src/runtime/internal/client/if.js +239 -50
- package/src/runtime/internal/client/index.js +9 -13
- package/src/runtime/internal/client/operations.js +44 -51
- package/src/runtime/internal/client/portal.js +163 -85
- package/src/runtime/internal/client/render.js +44 -25
- package/src/runtime/internal/client/rpc.js +3 -3
- package/src/runtime/internal/client/runtime.js +799 -576
- package/src/runtime/internal/client/selector.js +77 -0
- package/src/runtime/internal/client/template.js +133 -158
- package/src/runtime/internal/client/transport.js +38 -0
- package/src/runtime/internal/client/try.js +465 -426
- package/src/runtime/internal/client/types.d.ts +65 -21
- package/src/runtime/internal/client/utils.js +1 -3
- package/src/runtime/internal/server/dynamic.js +20 -21
- package/src/runtime/internal/server/index.js +327 -275
- package/src/runtime/internal/server/rpc.js +3 -2
- package/src/runtime/internal/server/transport.js +16 -0
- package/src/runtime/transport.js +21 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +0 -5
- package/tests/client/array/array.copy-within.test.tsrx +12 -12
- package/tests/client/array/array.derived.test.tsrx +46 -46
- package/tests/client/array/array.iteration.test.tsrx +10 -10
- package/tests/client/array/array.mutations.test.tsrx +20 -20
- package/tests/client/array/array.static.test.tsrx +11 -11
- package/tests/client/array/array.to-methods.test.tsrx +6 -6
- package/tests/client/async-suspend.test.tsrx +74 -75
- package/tests/client/basic/basic.attributes.test.tsrx +86 -83
- package/tests/client/basic/basic.collections.test.tsrx +12 -12
- package/tests/client/basic/basic.components.test.tsrx +99 -25
- package/tests/client/basic/basic.errors.test.tsrx +18 -18
- package/tests/client/basic/basic.events.test.tsrx +42 -42
- package/tests/client/basic/basic.get-set.test.tsrx +8 -8
- package/tests/client/basic/basic.reactivity.test.tsrx +97 -29
- package/tests/client/basic/basic.rendering.test.tsrx +25 -25
- package/tests/client/basic/basic.utilities.test.tsrx +3 -3
- package/tests/client/boundaries.test.tsrx +8 -8
- package/tests/client/boxed-locals.test.tsrx +452 -0
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +6 -6
- package/tests/client/compiler/compiler.assignments.test.tsrx +9 -73
- package/tests/client/compiler/compiler.attributes.test.tsrx +23 -23
- package/tests/client/compiler/compiler.basic.test.tsrx +15 -60
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +18 -43
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +2 -2
- package/tests/client/composite/__snapshots__/composite.render.test.tsrx.snap +0 -1
- package/tests/client/composite/composite.dynamic-components.test.tsrx +77 -6
- package/tests/client/composite/composite.props.test.tsrx +149 -12
- package/tests/client/composite/composite.reactivity.test.tsrx +51 -52
- package/tests/client/composite/composite.render.test.tsrx +26 -9
- package/tests/client/css/scoped-styles.test.tsrx +8 -8
- package/tests/client/date.test.tsrx +42 -42
- package/tests/client/derived-release.test.tsrx +370 -0
- package/tests/client/dynamic-elements.test.tsrx +45 -45
- package/tests/client/events.test.tsrx +97 -71
- package/tests/client/for-selector.test.tsrx +221 -0
- package/tests/client/for-single-root-items.test.tsrx +118 -3
- package/tests/client/for.test.tsrx +332 -31
- package/tests/client/head.test.tsrx +19 -19
- package/tests/client/html.test.tsrx +11 -9
- package/tests/client/if-block.test.tsrx +80 -0
- package/tests/client/map.test.tsrx +16 -16
- package/tests/client/media-query.test.tsrx +7 -7
- package/tests/client/portal.test.tsrx +224 -26
- package/tests/client/primitive-text.test.tsrx +50 -0
- package/tests/client/prop-kind-switch.test.tsrx +141 -0
- package/tests/client/ref.test.tsrx +17 -17
- package/tests/client/return.test.tsrx +26 -3
- package/tests/client/root-boundary.test.tsrx +42 -0
- package/tests/client/scoped-flush.test.tsrx +8 -8
- package/tests/client/set.test.tsrx +6 -6
- package/tests/client/svg.test.tsrx +11 -11
- package/tests/client/switch.test.tsrx +44 -44
- package/tests/client/track-async-hydration.test.tsrx +4 -4
- package/tests/client/try.test.tsrx +151 -83
- package/tests/client/tsx.test.tsrx +43 -40
- package/tests/client/url/url.derived.test.tsrx +6 -6
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +10 -10
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +10 -10
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +18 -18
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +2 -2
- package/tests/hydration/basic.test.js +74 -1
- package/tests/hydration/build-components.js +22 -1
- package/tests/hydration/compiled/client/basic.js +1142 -713
- package/tests/hydration/compiled/client/composite.js +151 -100
- package/tests/hydration/compiled/client/events.js +190 -150
- package/tests/hydration/compiled/client/for.js +1472 -1126
- package/tests/hydration/compiled/client/fragment-cursor.js +2341 -0
- package/tests/hydration/compiled/client/head.js +255 -199
- package/tests/hydration/compiled/client/hmr.js +54 -41
- package/tests/hydration/compiled/client/html-in-template.js +54 -39
- package/tests/hydration/compiled/client/html.js +1633 -1263
- package/tests/hydration/compiled/client/if-children.js +420 -270
- package/tests/hydration/compiled/client/if-fragment-controlflow.js +363 -317
- package/tests/hydration/compiled/client/if.js +229 -219
- package/tests/hydration/compiled/client/mixed-control-flow.js +420 -400
- package/tests/hydration/compiled/client/nested-control-flow.js +1326 -1255
- package/tests/hydration/compiled/client/portal.js +87 -95
- package/tests/hydration/compiled/client/reactivity.js +140 -83
- package/tests/hydration/compiled/client/return.js +28 -19
- package/tests/hydration/compiled/client/streaming.js +390 -306
- package/tests/hydration/compiled/client/switch.js +258 -266
- package/tests/hydration/compiled/client/track-async-serialization.js +448 -280
- package/tests/hydration/compiled/client/try.js +173 -129
- package/tests/hydration/compiled/client/typed-text.js +71 -0
- package/tests/hydration/compiled/fixtures/money.js +10 -0
- package/tests/hydration/compiled/server/basic.js +123 -6
- package/tests/hydration/compiled/server/composite.js +16 -30
- package/tests/hydration/compiled/server/events.js +19 -19
- package/tests/hydration/compiled/server/for.js +109 -49
- package/tests/hydration/compiled/server/fragment-cursor.js +1687 -0
- package/tests/hydration/compiled/server/head.js +20 -28
- package/tests/hydration/compiled/server/hmr.js +2 -2
- package/tests/hydration/compiled/server/html.js +71 -247
- package/tests/hydration/compiled/server/if-children.js +107 -15
- package/tests/hydration/compiled/server/if.js +11 -15
- package/tests/hydration/compiled/server/mixed-control-flow.js +8 -8
- package/tests/hydration/compiled/server/portal.js +14 -22
- package/tests/hydration/compiled/server/reactivity.js +14 -46
- package/tests/hydration/compiled/server/streaming.js +19 -19
- package/tests/hydration/compiled/server/switch.js +8 -8
- package/tests/hydration/compiled/server/track-async-serialization.js +150 -23
- package/tests/hydration/compiled/server/try.js +8 -8
- package/tests/hydration/compiled/server/typed-text.js +17 -0
- package/tests/hydration/components/basic.tsrx +44 -8
- package/tests/hydration/components/composite.tsrx +2 -2
- package/tests/hydration/components/events.tsrx +25 -25
- package/tests/hydration/components/for.tsrx +115 -67
- package/tests/hydration/components/fragment-cursor.tsrx +650 -0
- package/tests/hydration/components/head.tsrx +16 -16
- package/tests/hydration/components/hmr.tsrx +2 -2
- package/tests/hydration/components/html.tsrx +7 -7
- package/tests/hydration/components/if-children.tsrx +72 -25
- package/tests/hydration/components/if.tsrx +18 -18
- package/tests/hydration/components/mixed-control-flow.tsrx +11 -11
- package/tests/hydration/components/portal.tsrx +3 -3
- package/tests/hydration/components/reactivity.tsrx +16 -16
- package/tests/hydration/components/streaming.tsrx +20 -20
- package/tests/hydration/components/switch.tsrx +20 -20
- package/tests/hydration/components/text-types.ts +4 -0
- package/tests/hydration/components/track-async-serialization.tsrx +80 -26
- package/tests/hydration/components/try.tsrx +8 -8
- package/tests/hydration/components/typed-text.tsrx +22 -0
- package/tests/hydration/fixtures/money.js +10 -0
- package/tests/hydration/for.test.js +36 -0
- package/tests/hydration/fragment-cursor.test.js +111 -0
- package/tests/hydration/if-children.test.js +24 -0
- package/tests/hydration/streaming.test.js +19 -0
- package/tests/hydration/track-async-serialization.test.js +87 -2
- package/tests/hydration/tsconfig.text-types.json +10 -0
- package/tests/hydration/typed-text.test.js +34 -0
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +42 -42
- package/tests/server/basic.components.test.tsrx +64 -8
- package/tests/server/basic.test.tsrx +34 -32
- package/tests/server/compiler.test.tsrx +1 -70
- package/tests/server/composite.props.test.tsrx +6 -6
- package/tests/server/dynamic-elements.test.tsrx +31 -8
- package/tests/server/for.test.tsrx +94 -0
- package/tests/server/head.test.tsrx +11 -11
- package/tests/server/scoped-styles.test.tsrx +2 -2
- package/tests/server/streaming-ssr.test.tsrx +48 -43
- package/tests/server/track-async-serialization.test.tsrx +204 -21
- package/tests/server/try.test.tsrx +48 -48
- package/tests/types/transport.ts +40 -0
- package/tests/utils/vite-plugin-config.test.js +23 -0
- package/types/index.d.ts +48 -7
- package/types/server.d.ts +3 -0
- package/types/transport.d.ts +15 -0
- package/src/runtime/internal/client/switch.js +0 -113
- package/src/utils/errors.js +0 -13
- package/tests/client/lazy-array.test.tsrx +0 -31
- package/tests/client/lazy-destructuring.test.tsrx +0 -438
- package/tests/client/tracked-index-access.test.tsrx +0 -113
- package/tests/server/lazy-destructuring.test.tsrx +0 -595
- package/tests/server/tracked-index-access.test.tsrx +0 -76
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
/** @import { Block } from '#client' */
|
|
1
|
+
/** @import { AppendIntoAnchor, Block } from '#client' */
|
|
2
2
|
|
|
3
3
|
import { is_array } from '@tsrx/core/runtime/language-helpers';
|
|
4
4
|
import { branch, destroy_block, render } from './blocks.js';
|
|
5
|
-
import { BRANCH_BLOCK, UNINITIALIZED } from './constants.js';
|
|
5
|
+
import { BRANCH_BLOCK, IF_BLOCK, UNINITIALIZED } from './constants.js';
|
|
6
6
|
import { create_text, get_next_sibling } from './operations.js';
|
|
7
7
|
import { assign_nodes } from './template.js';
|
|
8
8
|
import { active_block } from './runtime.js';
|
|
9
9
|
import { hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
|
|
10
10
|
import { COMMENT_NODE, HYDRATION_END, HYDRATION_START, TEXT_NODE } from '../../../constants.js';
|
|
11
|
-
import { is_tsrx_element } from '../../element.js';
|
|
11
|
+
import { is_tsrx_element, TSRX_ELEMENT } from '../../element.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Finds the nearest enclosing
|
|
14
|
+
* Finds the nearest enclosing block that owns a DOM range (a branch or an if
|
|
15
|
+
* block) in the block hierarchy.
|
|
15
16
|
* @param {Block | null} block
|
|
16
17
|
* @returns {Block | null}
|
|
17
18
|
*/
|
|
18
19
|
function find_enclosing_branch(block) {
|
|
19
20
|
while (block !== null) {
|
|
20
|
-
if ((block.f & BRANCH_BLOCK) !== 0) {
|
|
21
|
+
if ((block.f & (BRANCH_BLOCK | IF_BLOCK)) !== 0) {
|
|
21
22
|
return block;
|
|
22
23
|
}
|
|
23
24
|
block = block.p;
|
|
@@ -32,13 +33,19 @@ function find_enclosing_branch(block) {
|
|
|
32
33
|
* @returns {void}
|
|
33
34
|
*/
|
|
34
35
|
export function render_value(value, anchor, block) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// render_tsrx_element, inline: an element's render may return another
|
|
37
|
+
// element (a wrapper), an array, or text.
|
|
38
|
+
var rendered = false;
|
|
39
|
+
// is_tsrx_element, inline: every component render passes through here.
|
|
40
|
+
while (value != null && value[TSRX_ELEMENT] === true) {
|
|
41
|
+
value = value.render(anchor, block, value.p);
|
|
42
|
+
rendered = true;
|
|
43
|
+
}
|
|
44
|
+
if (is_array(value)) {
|
|
38
45
|
render_tsrx_collection(value, anchor, block);
|
|
39
46
|
} else if (value != null) {
|
|
40
47
|
var text = value + '';
|
|
41
|
-
if (text !== '') {
|
|
48
|
+
if (rendered || text !== '') {
|
|
42
49
|
render_tsrx_collection_text(text, anchor, true);
|
|
43
50
|
}
|
|
44
51
|
}
|
|
@@ -60,11 +67,27 @@ function render_tsrx_collection(value, anchor, block) {
|
|
|
60
67
|
var start = document.createComment('');
|
|
61
68
|
var end = document.createComment('');
|
|
62
69
|
|
|
63
|
-
anchor
|
|
70
|
+
insert_before(anchor, start);
|
|
71
|
+
insert_before(anchor, end);
|
|
64
72
|
assign_nodes(start, end);
|
|
65
73
|
render_tsrx_collection_items(value, end, block);
|
|
66
74
|
}
|
|
67
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Inserts `node` before `anchor`, or appends it into the parent when `anchor`
|
|
78
|
+
* is an append-into sentinel (see `append_into`).
|
|
79
|
+
* @param {ChildNode | AppendIntoAnchor} anchor
|
|
80
|
+
* @param {Node} node
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
function insert_before(anchor, node) {
|
|
84
|
+
if (/** @type {AppendIntoAnchor} */ (anchor).into === true) {
|
|
85
|
+
/** @type {AppendIntoAnchor} */ (anchor).parent.appendChild(node);
|
|
86
|
+
} else {
|
|
87
|
+
/** @type {ChildNode} */ (anchor).before(node);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
68
91
|
/**
|
|
69
92
|
* @param {any[]} value
|
|
70
93
|
* @param {ChildNode} anchor
|
|
@@ -92,7 +115,7 @@ function render_tsrx_collection_items(value, anchor, block) {
|
|
|
92
115
|
* @returns {void}
|
|
93
116
|
*/
|
|
94
117
|
function render_tsrx_element(value, anchor, block) {
|
|
95
|
-
var result = value.render(anchor, block);
|
|
118
|
+
var result = value.render(anchor, block, value.p);
|
|
96
119
|
|
|
97
120
|
if (is_tsrx_element(result)) {
|
|
98
121
|
render_tsrx_element(result, anchor, block);
|
|
@@ -112,7 +135,7 @@ function render_tsrx_element(value, anchor, block) {
|
|
|
112
135
|
function render_tsrx_collection_text(value, anchor, assign = false) {
|
|
113
136
|
if (!hydrating) {
|
|
114
137
|
var text = create_text(value);
|
|
115
|
-
anchor
|
|
138
|
+
insert_before(anchor, text);
|
|
116
139
|
if (assign) {
|
|
117
140
|
assign_nodes(text, text);
|
|
118
141
|
}
|
|
@@ -167,68 +190,99 @@ function render_tsrx_collection_text(value, anchor, assign = false) {
|
|
|
167
190
|
set_hydrate_node(node ?? anchor);
|
|
168
191
|
}
|
|
169
192
|
|
|
193
|
+
/**
|
|
194
|
+
* @typedef {{
|
|
195
|
+
* start: Node | null;
|
|
196
|
+
* end: Node | null;
|
|
197
|
+
* a: ChildNode;
|
|
198
|
+
* n: number;
|
|
199
|
+
* g: () => any;
|
|
200
|
+
* b: Block | null;
|
|
201
|
+
* m: Comment | null;
|
|
202
|
+
* t: Text | null;
|
|
203
|
+
* v: string | import('../../element.js').TSRXElement | typeof UNINITIALIZED;
|
|
204
|
+
* e: boolean;
|
|
205
|
+
* i: boolean;
|
|
206
|
+
* p: Block | null;
|
|
207
|
+
* o: Node | null;
|
|
208
|
+
* }} ExpressionState
|
|
209
|
+
*/
|
|
210
|
+
|
|
170
211
|
/**
|
|
171
212
|
* @param {Node} node
|
|
172
213
|
* @param {() => any} get_value
|
|
173
214
|
* @returns {void}
|
|
174
215
|
*/
|
|
175
216
|
export function expression(node, get_value) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
217
|
+
// State lives on the render block instead of a per-expression closure, and
|
|
218
|
+
// the anchor's node type is read once since the anchor never changes.
|
|
219
|
+
render(run_expression, {
|
|
220
|
+
start: null,
|
|
221
|
+
end: null,
|
|
222
|
+
a: /** @type {ChildNode} */ (node),
|
|
223
|
+
n: node.nodeType,
|
|
224
|
+
g: get_value,
|
|
225
|
+
// child block rendering a TSRX element / collection
|
|
226
|
+
b: null,
|
|
227
|
+
// hydration end marker
|
|
228
|
+
m: null,
|
|
229
|
+
// text node inserted before a comment anchor
|
|
230
|
+
t: null,
|
|
231
|
+
// last rendered value
|
|
232
|
+
v: UNINITIALIZED,
|
|
233
|
+
// whether the last value was an element / collection
|
|
234
|
+
e: false,
|
|
235
|
+
// whether the block has rendered once
|
|
236
|
+
i: false,
|
|
237
|
+
// enclosing branch whose start was moved to include element content
|
|
238
|
+
p: null,
|
|
239
|
+
// that branch's original start node
|
|
240
|
+
o: null,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @param {ExpressionState} s
|
|
246
|
+
* @returns {void}
|
|
247
|
+
*/
|
|
248
|
+
function run_expression(s) {
|
|
249
|
+
var next_value = s.g();
|
|
250
|
+
var anchor = s.a;
|
|
251
|
+
var type = typeof next_value;
|
|
252
|
+
var is_hydration_marker =
|
|
253
|
+
hydrating && s.n === COMMENT_NODE && /** @type {Comment} */ (anchor).data === HYDRATION_START;
|
|
254
|
+
|
|
255
|
+
if (is_hydration_marker) {
|
|
256
|
+
s.m ??= ensure_expression_end(anchor);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
var end = s.m;
|
|
260
|
+
|
|
261
|
+
if (next_value !== null && (type === 'object' || type === 'function')) {
|
|
194
262
|
var next_is_collection = is_array(next_value);
|
|
195
|
-
var next_is_element = next_is_collection || is_tsrx_element(next_value);
|
|
196
|
-
var is_hydration_marker =
|
|
197
|
-
hydrating &&
|
|
198
|
-
anchor.nodeType === COMMENT_NODE &&
|
|
199
|
-
/** @type {Comment} */ (anchor).data === HYDRATION_START;
|
|
200
|
-
|
|
201
|
-
if (is_hydration_marker) {
|
|
202
|
-
end ??= ensure_expression_end(anchor);
|
|
203
|
-
}
|
|
204
263
|
|
|
205
|
-
if (
|
|
206
|
-
if (
|
|
264
|
+
if (next_is_collection || is_tsrx_element(next_value)) {
|
|
265
|
+
if (s.i && s.e && s.v === next_value) {
|
|
207
266
|
if (end !== null) {
|
|
208
|
-
|
|
267
|
+
settle_hydration(end);
|
|
209
268
|
}
|
|
210
269
|
return;
|
|
211
270
|
}
|
|
212
271
|
|
|
213
|
-
if (
|
|
272
|
+
if (s.n === TEXT_NODE) {
|
|
214
273
|
/** @type {Text} */ (anchor).nodeValue = '';
|
|
215
|
-
} else if (
|
|
216
|
-
|
|
217
|
-
|
|
274
|
+
} else if (s.t !== null) {
|
|
275
|
+
s.t.remove();
|
|
276
|
+
s.t = null;
|
|
218
277
|
}
|
|
219
278
|
|
|
220
|
-
if (
|
|
221
|
-
destroy_block(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (modified_parent_branch !== null && modified_parent_branch.s !== null) {
|
|
225
|
-
modified_parent_branch.s.start = original_parent_start;
|
|
226
|
-
modified_parent_branch = null;
|
|
227
|
-
original_parent_start = null;
|
|
228
|
-
}
|
|
279
|
+
if (s.b !== null) {
|
|
280
|
+
destroy_block(s.b);
|
|
281
|
+
s.b = null;
|
|
282
|
+
restore_parent_start(s);
|
|
229
283
|
}
|
|
230
284
|
|
|
231
|
-
if (end !== null && (
|
|
285
|
+
if (end !== null && (s.i || !hydrating)) {
|
|
232
286
|
clear_expression_range(anchor, end);
|
|
233
287
|
}
|
|
234
288
|
|
|
@@ -236,18 +290,18 @@ export function expression(node, get_value) {
|
|
|
236
290
|
set_hydrate_node(get_next_sibling(anchor) ?? end);
|
|
237
291
|
}
|
|
238
292
|
|
|
239
|
-
// Find the enclosing branch block BEFORE creating
|
|
293
|
+
// Find the enclosing branch block BEFORE creating the child block
|
|
240
294
|
// so we can update its s.start to include content inserted before anchor
|
|
241
295
|
var parent_branch = find_enclosing_branch(active_block);
|
|
242
296
|
|
|
243
|
-
child_block = branch(() => {
|
|
297
|
+
var child_block = (s.b = branch(() => {
|
|
244
298
|
var block = /** @type {Block} */ (active_block);
|
|
245
299
|
if (next_is_collection) {
|
|
246
300
|
render_tsrx_collection(next_value, end ?? anchor, block);
|
|
247
301
|
} else {
|
|
248
302
|
render_tsrx_element(next_value, end ?? anchor, block);
|
|
249
303
|
}
|
|
250
|
-
});
|
|
304
|
+
}));
|
|
251
305
|
|
|
252
306
|
// Update parent branch's s.start to include content inserted before anchor.
|
|
253
307
|
// This ensures that when the parent branch is destroyed, the full DOM range
|
|
@@ -267,81 +321,91 @@ export function expression(node, get_value) {
|
|
|
267
321
|
// update it to include the child's content
|
|
268
322
|
if (parent_start === anchor || parent_start === end) {
|
|
269
323
|
// Save original so we can restore it when switching to non-TSRXElement
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
|
|
324
|
+
if (s.p === null) {
|
|
325
|
+
s.p = parent_branch;
|
|
326
|
+
s.o = parent_start;
|
|
273
327
|
}
|
|
274
328
|
parent_branch.s.start = child_start;
|
|
275
329
|
}
|
|
276
330
|
}
|
|
277
331
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
332
|
+
s.v = next_value;
|
|
333
|
+
s.e = true;
|
|
334
|
+
s.i = true;
|
|
281
335
|
if (end !== null) {
|
|
282
|
-
|
|
336
|
+
settle_hydration(end);
|
|
283
337
|
}
|
|
284
338
|
return;
|
|
285
339
|
}
|
|
340
|
+
}
|
|
286
341
|
|
|
287
|
-
|
|
342
|
+
var next_text = next_value == null ? '' : next_value + '';
|
|
288
343
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
return;
|
|
344
|
+
if (s.i && !s.e && s.v === next_text) {
|
|
345
|
+
if (end !== null) {
|
|
346
|
+
settle_hydration(end);
|
|
294
347
|
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
295
350
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
modified_parent_branch = null;
|
|
304
|
-
original_parent_start = null;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
351
|
+
if (s.b !== null) {
|
|
352
|
+
destroy_block(s.b);
|
|
353
|
+
s.b = null;
|
|
354
|
+
// Restore parent branch's start to original value since the child's DOM nodes
|
|
355
|
+
// have been removed and the old start reference would be stale
|
|
356
|
+
restore_parent_start(s);
|
|
357
|
+
}
|
|
307
358
|
|
|
308
|
-
|
|
309
|
-
|
|
359
|
+
if (is_hydration_marker) {
|
|
360
|
+
var text = (s.t = get_hydrated_text(anchor, /** @type {Comment} */ (end)));
|
|
310
361
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
} else if (text === null) {
|
|
317
|
-
text = create_text(next_text);
|
|
318
|
-
/** @type {Comment} */ (end).before(text);
|
|
319
|
-
} else if (text.nodeValue !== next_text) {
|
|
320
|
-
text.nodeValue = next_text;
|
|
362
|
+
if (next_text === '') {
|
|
363
|
+
if (text !== null) {
|
|
364
|
+
text.remove();
|
|
365
|
+
s.t = null;
|
|
321
366
|
}
|
|
322
|
-
} else if (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
text.
|
|
367
|
+
} else if (text === null) {
|
|
368
|
+
text = s.t = create_text(next_text);
|
|
369
|
+
/** @type {Comment} */ (end).before(text);
|
|
370
|
+
} else if (text.nodeValue !== next_text) {
|
|
371
|
+
text.nodeValue = next_text;
|
|
372
|
+
}
|
|
373
|
+
} else if (s.n === COMMENT_NODE) {
|
|
374
|
+
var text = s.t;
|
|
375
|
+
if (next_text === '') {
|
|
376
|
+
if (text !== null) {
|
|
377
|
+
text.remove();
|
|
378
|
+
s.t = null;
|
|
333
379
|
}
|
|
334
|
-
} else if (
|
|
335
|
-
|
|
380
|
+
} else if (text === null) {
|
|
381
|
+
text = s.t = create_text(next_text);
|
|
382
|
+
(end ?? anchor).before(text);
|
|
383
|
+
} else if (text.nodeValue !== next_text) {
|
|
384
|
+
text.nodeValue = next_text;
|
|
336
385
|
}
|
|
386
|
+
} else if (s.n === TEXT_NODE) {
|
|
387
|
+
/** @type {Text} */ (anchor).nodeValue = next_text;
|
|
388
|
+
}
|
|
337
389
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
390
|
+
s.v = next_text;
|
|
391
|
+
s.e = false;
|
|
392
|
+
s.i = true;
|
|
393
|
+
if (end !== null) {
|
|
394
|
+
settle_hydration(end);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @param {ExpressionState} s
|
|
400
|
+
* @returns {void}
|
|
401
|
+
*/
|
|
402
|
+
function restore_parent_start(s) {
|
|
403
|
+
var parent = s.p;
|
|
404
|
+
if (parent !== null && parent.s !== null) {
|
|
405
|
+
parent.s.start = s.o;
|
|
406
|
+
s.p = null;
|
|
407
|
+
s.o = null;
|
|
408
|
+
}
|
|
345
409
|
}
|
|
346
410
|
|
|
347
411
|
/**
|
|
@@ -416,17 +480,14 @@ function clear_expression_range(anchor, end) {
|
|
|
416
480
|
}
|
|
417
481
|
|
|
418
482
|
/**
|
|
483
|
+
* Leaves the hydration cursor on the expression's end marker, the last node
|
|
484
|
+
* the expression owns: the parent steps past it with its own sibling
|
|
485
|
+
* navigation, exactly as it does after an element or a control-flow block.
|
|
419
486
|
* @param {Comment} end
|
|
420
487
|
* @returns {void}
|
|
421
488
|
*/
|
|
422
|
-
function
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
var next = get_next_sibling(end);
|
|
428
|
-
|
|
429
|
-
if (next !== null) {
|
|
430
|
-
set_hydrate_node(next);
|
|
489
|
+
function settle_hydration(end) {
|
|
490
|
+
if (hydrating) {
|
|
491
|
+
set_hydrate_node(end);
|
|
431
492
|
}
|
|
432
493
|
}
|