@firsthandjs/dom 0.9.0 → 0.10.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/dist/chunk-467WEPXM.js +1 -0
- package/dist/chunk-J5525WK6.js +1 -0
- package/dist/{chunk-26MSEGYG.js → chunk-YX6HJXS6.js} +1 -1
- package/dist/claim.d.ts +10 -0
- package/dist/claim.d.ts.map +1 -1
- package/dist/{dev-chunk-5QV3XALZ.js → dev-chunk-KJHYMOKB.js} +1 -1
- package/dist/{dev-chunk-HCAUM4JK.js → dev-chunk-O5KFGWVZ.js} +160 -63
- package/dist/{dev-chunk-HTXIHAW7.js → dev-chunk-U46CIJCO.js} +242 -308
- package/dist/hydrate.d.ts +11 -0
- package/dist/hydrate.d.ts.map +1 -1
- package/dist/hydrate.dev.js +36 -25
- package/dist/hydrate.js +1 -1
- package/dist/index.dev.js +3 -3
- package/dist/index.js +1 -1
- package/dist/insert.d.ts +58 -108
- package/dist/insert.d.ts.map +1 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.dev.js +121 -11
- package/dist/internal.js +1 -1
- package/dist/list.d.ts.map +1 -1
- package/dist/nodes.d.ts +36 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/props.d.ts.map +1 -1
- package/dist/reconcile.d.ts +30 -0
- package/dist/reconcile.d.ts.map +1 -0
- package/dist/store.d.ts +105 -0
- package/dist/store.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-NNHZJMZS.js +0 -1
- package/dist/chunk-TZRPGQ3R.js +0 -1
|
@@ -33,30 +33,30 @@ function label(value, kind, name) {
|
|
|
33
33
|
return value;
|
|
34
34
|
}
|
|
35
35
|
var QUIET = 20;
|
|
36
|
-
function devRan(
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
function devRan(store) {
|
|
37
|
+
if (store.busy === true) {
|
|
38
|
+
store.busy = false;
|
|
39
|
+
store.quiet = 0;
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const quiet = (
|
|
43
|
-
|
|
42
|
+
const quiet = (store.quiet ?? 0) + 1;
|
|
43
|
+
store.quiet = quiet;
|
|
44
44
|
if (quiet !== QUIET) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
devWarnOnce(
|
|
48
|
-
`quiet-run:${
|
|
49
|
-
`<${
|
|
48
|
+
`quiet-run:${store.name}`,
|
|
49
|
+
`<${store.name}> ran ${String(QUIET)} times and wrote nothing.
|
|
50
50
|
Something it reads in a statement changes more often than what it shows. Move that read into the markup, where it is a part of its own, or move the derivation into a computed in the setup.`
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
|
-
function devHandedNewFunction(
|
|
53
|
+
function devHandedNewFunction(store, value) {
|
|
54
54
|
if (typeof value !== "function") {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
devWarnOnce(
|
|
58
|
-
`new-function:${
|
|
59
|
-
`<${
|
|
58
|
+
`new-function:${store.name}`,
|
|
59
|
+
`<${store.name}> hands a child a new function on every run, so that child runs again whenever this one does.
|
|
60
60
|
If the handler does not depend on the run, define it in the setup.`
|
|
61
61
|
);
|
|
62
62
|
}
|
|
@@ -91,17 +91,152 @@ function next(node) {
|
|
|
91
91
|
return claimer === null ? sibling : claimer.step(sibling);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
// packages/dom/src/reconcile.ts
|
|
95
|
+
function reconcile(parent, marker, a, b) {
|
|
96
|
+
let aStart = 0;
|
|
97
|
+
let bStart = 0;
|
|
98
|
+
let aEnd = a.length - 1;
|
|
99
|
+
let bEnd = b.length - 1;
|
|
100
|
+
while (aStart <= aEnd && bStart <= bEnd && a[aStart] === b[bStart]) {
|
|
101
|
+
aStart++;
|
|
102
|
+
bStart++;
|
|
103
|
+
}
|
|
104
|
+
while (aStart <= aEnd && bStart <= bEnd && a[aEnd] === b[bEnd]) {
|
|
105
|
+
aEnd--;
|
|
106
|
+
bEnd--;
|
|
107
|
+
}
|
|
108
|
+
const after = bEnd + 1 < b.length ? b[bEnd + 1] : marker;
|
|
109
|
+
if (aStart > aEnd) {
|
|
110
|
+
for (let i = bStart; i <= bEnd; i++) {
|
|
111
|
+
parent.insertBefore(b[i], after);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (bStart > bEnd) {
|
|
116
|
+
for (let i = aStart; i <= aEnd; i++) {
|
|
117
|
+
parent.removeChild(a[i]);
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
reorder(parent, b, after, { a, aStart, aEnd, bStart, bEnd });
|
|
122
|
+
}
|
|
123
|
+
function reorder(parent, b, after, middle) {
|
|
124
|
+
const count = middle.bEnd - middle.bStart + 1;
|
|
125
|
+
const sources = sourcesOf(parent, b, middle);
|
|
126
|
+
const keep = longestIncreasing(sources);
|
|
127
|
+
let k = keep.length - 1;
|
|
128
|
+
let anchor = after;
|
|
129
|
+
for (let j = count - 1; j >= 0; j--) {
|
|
130
|
+
const node = b[middle.bStart + j];
|
|
131
|
+
if (k >= 0 && keep[k] === j) {
|
|
132
|
+
k--;
|
|
133
|
+
} else {
|
|
134
|
+
parent.insertBefore(node, anchor);
|
|
135
|
+
}
|
|
136
|
+
anchor = node;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function sourcesOf(parent, b, middle) {
|
|
140
|
+
const { a, aStart, aEnd, bStart, bEnd } = middle;
|
|
141
|
+
const oldIndex = /* @__PURE__ */ new Map();
|
|
142
|
+
for (let i = aStart; i <= aEnd; i++) {
|
|
143
|
+
oldIndex.set(a[i], i);
|
|
144
|
+
}
|
|
145
|
+
const count = bEnd - bStart + 1;
|
|
146
|
+
const sources = new Int32Array(count).fill(-1);
|
|
147
|
+
for (let j = 0; j < count; j++) {
|
|
148
|
+
const node = b[bStart + j];
|
|
149
|
+
const found = oldIndex.get(node);
|
|
150
|
+
if (found !== void 0) {
|
|
151
|
+
sources[j] = found;
|
|
152
|
+
oldIndex.delete(node);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const node of oldIndex.keys()) {
|
|
156
|
+
parent.removeChild(node);
|
|
157
|
+
}
|
|
158
|
+
return sources;
|
|
159
|
+
}
|
|
160
|
+
function longestIncreasing(sources) {
|
|
161
|
+
const length = sources.length;
|
|
162
|
+
const predecessor = new Int32Array(length).fill(-1);
|
|
163
|
+
const tails = [];
|
|
164
|
+
for (let i = 0; i < length; i++) {
|
|
165
|
+
const value = sources[i];
|
|
166
|
+
if (value === -1) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
let low = 0;
|
|
170
|
+
let high = tails.length;
|
|
171
|
+
while (low < high) {
|
|
172
|
+
const mid = low + high >> 1;
|
|
173
|
+
if (sources[tails[mid]] < value) {
|
|
174
|
+
low = mid + 1;
|
|
175
|
+
} else {
|
|
176
|
+
high = mid;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (low > 0) {
|
|
180
|
+
predecessor[i] = tails[low - 1];
|
|
181
|
+
}
|
|
182
|
+
tails[low] = i;
|
|
183
|
+
}
|
|
184
|
+
const result = [];
|
|
185
|
+
let cursor = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
186
|
+
while (cursor !== -1) {
|
|
187
|
+
result.push(cursor);
|
|
188
|
+
cursor = predecessor[cursor];
|
|
189
|
+
}
|
|
190
|
+
return result.reverse();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// packages/dom/src/insert.ts
|
|
194
|
+
import { bind, getOwner, onCleanup, runWithOwner } from "@firsthandjs/core";
|
|
195
|
+
|
|
196
|
+
// packages/dom/src/nodes.ts
|
|
197
|
+
var TEXT_NODE = 3;
|
|
198
|
+
function isNode(value) {
|
|
199
|
+
return typeof value.nodeType === "number";
|
|
200
|
+
}
|
|
201
|
+
function detach(node) {
|
|
202
|
+
const owner = node.parentNode;
|
|
203
|
+
if (owner !== null) {
|
|
204
|
+
owner.removeChild(node);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function clearIn(parent, marker, current) {
|
|
208
|
+
if (marker === null && Array.isArray(current) && current.length > 1 && parent.childNodes.length === current.length) {
|
|
209
|
+
parent.textContent = "";
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return clear(current);
|
|
213
|
+
}
|
|
214
|
+
function clear(current) {
|
|
215
|
+
if (current !== null) {
|
|
216
|
+
if (Array.isArray(current)) {
|
|
217
|
+
for (let i = 0; i < current.length; i++) {
|
|
218
|
+
detach(current[i]);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
detach(current);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
function single(parent, marker, current, node) {
|
|
227
|
+
if (current === node) {
|
|
228
|
+
return node;
|
|
229
|
+
}
|
|
230
|
+
if (current !== null && !Array.isArray(current)) {
|
|
231
|
+
parent.replaceChild(node, current);
|
|
232
|
+
return node;
|
|
233
|
+
}
|
|
234
|
+
clear(current);
|
|
235
|
+
parent.insertBefore(node, marker);
|
|
236
|
+
return node;
|
|
237
|
+
}
|
|
238
|
+
|
|
94
239
|
// packages/dom/src/insert.ts
|
|
95
|
-
import {
|
|
96
|
-
bind,
|
|
97
|
-
createOwner,
|
|
98
|
-
signal,
|
|
99
|
-
disposeOwner,
|
|
100
|
-
getOwner,
|
|
101
|
-
onCleanup,
|
|
102
|
-
runWithOwner,
|
|
103
|
-
setOwner
|
|
104
|
-
} from "@firsthandjs/core";
|
|
105
240
|
var discarding = 0;
|
|
106
241
|
function discard(body) {
|
|
107
242
|
discarding++;
|
|
@@ -111,124 +246,26 @@ function discard(body) {
|
|
|
111
246
|
discarding--;
|
|
112
247
|
}
|
|
113
248
|
}
|
|
114
|
-
var TEXT_NODE = 3;
|
|
115
|
-
function isNode(value) {
|
|
116
|
-
return typeof value.nodeType === "number";
|
|
117
|
-
}
|
|
118
249
|
var PART = /* @__PURE__ */ Symbol("firsthand.part");
|
|
119
250
|
var FLAT = /* @__PURE__ */ Symbol("firsthand.flat");
|
|
251
|
+
var PENDING = /* @__PURE__ */ Symbol("firsthand.pending");
|
|
252
|
+
var mounted = /* @__PURE__ */ new WeakSet();
|
|
120
253
|
function part(thunk) {
|
|
121
254
|
return { [PART]: true, anchor: document.createTextNode(""), thunk, owner: getOwner() };
|
|
122
255
|
}
|
|
123
256
|
function isDynamicChild(value) {
|
|
124
257
|
return PART in value;
|
|
125
258
|
}
|
|
126
|
-
function
|
|
127
|
-
return { slots: [], owner: getOwner(), generation: 0, name };
|
|
128
|
-
}
|
|
129
|
-
function wrote(store2) {
|
|
130
|
-
store2.busy = true;
|
|
131
|
-
}
|
|
132
|
-
function site(store2, index) {
|
|
133
|
-
const existing = store2.slots[index];
|
|
134
|
-
if (existing !== void 0) {
|
|
135
|
-
existing.seen = store2.generation;
|
|
136
|
-
return existing;
|
|
137
|
-
}
|
|
138
|
-
const slot = { seen: store2.generation };
|
|
139
|
-
store2.slots[index] = slot;
|
|
140
|
-
return slot;
|
|
141
|
-
}
|
|
142
|
-
function open(store2, slot) {
|
|
143
|
-
const owner = createOwner(store2.owner);
|
|
144
|
-
slot.owner = owner;
|
|
145
|
-
return setOwner(owner);
|
|
146
|
-
}
|
|
147
|
-
function close(previous) {
|
|
148
|
-
setOwner(previous);
|
|
149
|
-
}
|
|
150
|
-
function ran(store2, value) {
|
|
151
|
-
devRan(store2);
|
|
152
|
-
const generation = store2.generation;
|
|
153
|
-
const slots = store2.slots;
|
|
154
|
-
for (let i = 0; i < slots.length; i++) {
|
|
155
|
-
const slot = slots[i];
|
|
156
|
-
if (slot === void 0 || slot.seen === generation) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (slot.owner !== void 0) {
|
|
160
|
-
disposeOwner(slot.owner);
|
|
161
|
-
}
|
|
162
|
-
slots[i] = void 0;
|
|
163
|
-
}
|
|
164
|
-
store2.generation = generation + 1;
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
function cell(store2, index, value) {
|
|
168
|
-
const slot = site(store2, index);
|
|
169
|
-
const existing = slot.cell;
|
|
170
|
-
if (existing === void 0) {
|
|
171
|
-
const made = signal(value);
|
|
172
|
-
slot.cell = made;
|
|
173
|
-
return made;
|
|
174
|
-
}
|
|
175
|
-
if (existing.peek() !== value) {
|
|
176
|
-
devHandedNewFunction(store2, value);
|
|
177
|
-
wrote(store2);
|
|
178
|
-
existing.value = value;
|
|
179
|
-
}
|
|
180
|
-
return existing;
|
|
181
|
-
}
|
|
182
|
-
function writeChild(store2, index, parent, marker, value) {
|
|
183
|
-
const slot = site(store2, index);
|
|
184
|
-
if (slot.node === void 0 && hydration.current !== null) {
|
|
185
|
-
const claimed = hydration.current.claim(parent, marker);
|
|
186
|
-
if (claimed !== null) {
|
|
187
|
-
if (typeof value === "object" && value !== null && isDynamicChild(value)) {
|
|
188
|
-
slot.last = value;
|
|
189
|
-
hydration.current.keep(slot, parent, value.anchor, claimed);
|
|
190
|
-
runWithOwner(value.owner, () => {
|
|
191
|
-
insert(parent, value.thunk, value.anchor);
|
|
192
|
-
});
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
slot.node = claimed.nodes;
|
|
196
|
-
slot.text = claimed.text;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const type = typeof value;
|
|
200
|
-
if (type === "string" || type === "number") {
|
|
201
|
-
const text = String(value);
|
|
202
|
-
if (text === slot.text) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
wrote(store2);
|
|
206
|
-
slot.text = text;
|
|
207
|
-
slot.node = applyChild(parent, marker, slot.node ?? null, text);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
slot.text = void 0;
|
|
211
|
-
if (value === slot.last) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
wrote(store2);
|
|
215
|
-
slot.last = value;
|
|
216
|
-
slot.node = applyChild(parent, marker, slot.node ?? null, value);
|
|
217
|
-
}
|
|
218
|
-
function insert(parent, value, marker = null, seed) {
|
|
259
|
+
function insert(parent, value, marker = null, options) {
|
|
219
260
|
if (typeof value !== "function") {
|
|
220
261
|
applyChild(parent, marker, null, value);
|
|
221
262
|
return;
|
|
222
263
|
}
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
|
|
264
|
+
const claimed = claimFor(parent, marker, options?.seed);
|
|
265
|
+
let current = claimed === null ? null : claimed.nodes;
|
|
266
|
+
let written = claimed?.text;
|
|
226
267
|
let adopting = claimed !== null;
|
|
227
|
-
|
|
228
|
-
current = claimed.nodes;
|
|
229
|
-
written = claimed.text;
|
|
230
|
-
}
|
|
231
|
-
const body = () => {
|
|
268
|
+
const run = () => {
|
|
232
269
|
const next2 = value();
|
|
233
270
|
const type = typeof next2;
|
|
234
271
|
if (type === "string" || type === "number") {
|
|
@@ -241,29 +278,45 @@ function insert(parent, value, marker = null, seed) {
|
|
|
241
278
|
}
|
|
242
279
|
written = void 0;
|
|
243
280
|
if (type === "function") {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
insert(parent, next2, marker, claimed);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
current = clear(current);
|
|
250
|
-
insert(parent, next2, marker, null);
|
|
281
|
+
current = adopting ? null : clear(current);
|
|
282
|
+
insert(parent, next2, marker, { seed: adopting ? claimed : null });
|
|
251
283
|
return;
|
|
252
284
|
}
|
|
253
285
|
current = applyChild(parent, marker, current, next2);
|
|
254
286
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
287
|
+
const report = options?.report;
|
|
288
|
+
bindIn(
|
|
289
|
+
claimed,
|
|
290
|
+
report === void 0 ? run : () => {
|
|
291
|
+
run();
|
|
292
|
+
report(nodesOf(current, marker));
|
|
293
|
+
}
|
|
294
|
+
);
|
|
262
295
|
adopting = false;
|
|
263
296
|
onCleanup(() => {
|
|
264
297
|
current = discarding > 0 ? null : clear(current);
|
|
265
298
|
});
|
|
266
299
|
}
|
|
300
|
+
function nodesOf(current, anchor) {
|
|
301
|
+
const nodes = current === null ? [] : Array.isArray(current) ? [...current] : [current];
|
|
302
|
+
nodes.push(anchor);
|
|
303
|
+
return nodes;
|
|
304
|
+
}
|
|
305
|
+
function claimFor(parent, marker, seed) {
|
|
306
|
+
if (seed !== void 0) {
|
|
307
|
+
return seed;
|
|
308
|
+
}
|
|
309
|
+
return hydration.current === null ? null : hydration.current.claim(parent, marker);
|
|
310
|
+
}
|
|
311
|
+
function bindIn(claimed, body) {
|
|
312
|
+
if (claimed === null) {
|
|
313
|
+
bind(body);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
hydration.current.within(claimed.region, () => {
|
|
317
|
+
bind(body);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
267
320
|
function applyChild(parent, marker, current, value) {
|
|
268
321
|
const type = typeof value;
|
|
269
322
|
if (value == null || type === "boolean") {
|
|
@@ -279,45 +332,17 @@ function applyChild(parent, marker, current, value) {
|
|
|
279
332
|
}
|
|
280
333
|
return single(parent, marker, current, document.createTextNode(text));
|
|
281
334
|
}
|
|
282
|
-
|
|
335
|
+
return applyOther(parent, marker, current, value);
|
|
336
|
+
}
|
|
337
|
+
function applyOther(parent, marker, current, value) {
|
|
338
|
+
if (typeof value === "function") {
|
|
283
339
|
return applyChild(parent, marker, current, value());
|
|
284
340
|
}
|
|
285
341
|
if (Array.isArray(value)) {
|
|
286
|
-
|
|
287
|
-
const rows = value;
|
|
288
|
-
if (rows.length === 0) {
|
|
289
|
-
return clearIn(parent, marker, current);
|
|
290
|
-
}
|
|
291
|
-
reconcile(
|
|
292
|
-
parent,
|
|
293
|
-
marker,
|
|
294
|
-
current === null ? [] : Array.isArray(current) ? current : [current],
|
|
295
|
-
rows
|
|
296
|
-
);
|
|
297
|
-
return rows;
|
|
298
|
-
}
|
|
299
|
-
const next2 = [];
|
|
300
|
-
const dynamic = [];
|
|
301
|
-
flatten(value, next2, dynamic);
|
|
302
|
-
if (next2.length === 0) {
|
|
303
|
-
return clearIn(parent, marker, current);
|
|
304
|
-
}
|
|
305
|
-
reconcile(
|
|
306
|
-
parent,
|
|
307
|
-
marker,
|
|
308
|
-
current === null ? [] : Array.isArray(current) ? current : [current],
|
|
309
|
-
next2
|
|
310
|
-
);
|
|
311
|
-
for (let i = 0; i < dynamic.length; i++) {
|
|
312
|
-
const child = dynamic[i];
|
|
313
|
-
runWithOwner(child.owner ?? getOwner(), () => {
|
|
314
|
-
insert(parent, child.thunk, child.anchor);
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
return next2;
|
|
342
|
+
return applyArray(parent, marker, current, value);
|
|
318
343
|
}
|
|
319
344
|
if (isDynamicChild(value)) {
|
|
320
|
-
return
|
|
345
|
+
return applyArray(parent, marker, current, [value]);
|
|
321
346
|
}
|
|
322
347
|
if (isNode(value)) {
|
|
323
348
|
return single(parent, marker, current, value);
|
|
@@ -325,6 +350,43 @@ function applyChild(parent, marker, current, value) {
|
|
|
325
350
|
devWarnRenderedObject(value);
|
|
326
351
|
return applyChild(parent, marker, current, String(value));
|
|
327
352
|
}
|
|
353
|
+
function asList(current) {
|
|
354
|
+
return current === null ? [] : Array.isArray(current) ? current : [current];
|
|
355
|
+
}
|
|
356
|
+
function applyArray(parent, marker, current, value) {
|
|
357
|
+
if (FLAT in value) {
|
|
358
|
+
const rows = value;
|
|
359
|
+
if (rows.length === 0) {
|
|
360
|
+
return clearIn(parent, marker, current);
|
|
361
|
+
}
|
|
362
|
+
reconcile(parent, marker, asList(current), rows);
|
|
363
|
+
value[PENDING]?.(parent);
|
|
364
|
+
return rows;
|
|
365
|
+
}
|
|
366
|
+
const next2 = [];
|
|
367
|
+
const dynamic = [];
|
|
368
|
+
flatten(value, next2, dynamic);
|
|
369
|
+
if (next2.length === 0) {
|
|
370
|
+
return clearIn(parent, marker, current);
|
|
371
|
+
}
|
|
372
|
+
reconcile(parent, marker, asList(current), next2);
|
|
373
|
+
for (let i = 0; i < dynamic.length; i++) {
|
|
374
|
+
bindPart(dynamic[i], parent);
|
|
375
|
+
}
|
|
376
|
+
return next2;
|
|
377
|
+
}
|
|
378
|
+
function bindPart(child, parent, report) {
|
|
379
|
+
if (mounted.has(child)) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
mounted.add(child);
|
|
383
|
+
runWithOwner(child.owner ?? getOwner(), () => {
|
|
384
|
+
insert(parent, child.thunk, child.anchor, report === void 0 ? void 0 : { report });
|
|
385
|
+
onCleanup(() => {
|
|
386
|
+
mounted.delete(child);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
328
390
|
function flatten(value, out, dynamic) {
|
|
329
391
|
for (let i = 0; i < value.length; i++) {
|
|
330
392
|
let item = value[i];
|
|
@@ -348,131 +410,6 @@ function flatten(value, out, dynamic) {
|
|
|
348
410
|
}
|
|
349
411
|
}
|
|
350
412
|
}
|
|
351
|
-
function detach(node) {
|
|
352
|
-
const owner = node.parentNode;
|
|
353
|
-
if (owner !== null) {
|
|
354
|
-
owner.removeChild(node);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
function clearIn(parent, marker, current) {
|
|
358
|
-
if (marker === null && Array.isArray(current) && current.length > 1 && parent.childNodes.length === current.length) {
|
|
359
|
-
parent.textContent = "";
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
return clear(current);
|
|
363
|
-
}
|
|
364
|
-
function clear(current) {
|
|
365
|
-
if (current !== null) {
|
|
366
|
-
if (Array.isArray(current)) {
|
|
367
|
-
for (let i = 0; i < current.length; i++) {
|
|
368
|
-
detach(current[i]);
|
|
369
|
-
}
|
|
370
|
-
} else {
|
|
371
|
-
detach(current);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
function single(parent, marker, current, node) {
|
|
377
|
-
if (current === node) {
|
|
378
|
-
return node;
|
|
379
|
-
}
|
|
380
|
-
if (current !== null && !Array.isArray(current)) {
|
|
381
|
-
parent.replaceChild(node, current);
|
|
382
|
-
return node;
|
|
383
|
-
}
|
|
384
|
-
clear(current);
|
|
385
|
-
parent.insertBefore(node, marker);
|
|
386
|
-
return node;
|
|
387
|
-
}
|
|
388
|
-
function reconcile(parent, marker, a, b) {
|
|
389
|
-
let aStart = 0;
|
|
390
|
-
let bStart = 0;
|
|
391
|
-
let aEnd = a.length - 1;
|
|
392
|
-
let bEnd = b.length - 1;
|
|
393
|
-
while (aStart <= aEnd && bStart <= bEnd && a[aStart] === b[bStart]) {
|
|
394
|
-
aStart++;
|
|
395
|
-
bStart++;
|
|
396
|
-
}
|
|
397
|
-
while (aStart <= aEnd && bStart <= bEnd && a[aEnd] === b[bEnd]) {
|
|
398
|
-
aEnd--;
|
|
399
|
-
bEnd--;
|
|
400
|
-
}
|
|
401
|
-
const after = bEnd + 1 < b.length ? b[bEnd + 1] : marker;
|
|
402
|
-
if (aStart > aEnd) {
|
|
403
|
-
for (let i = bStart; i <= bEnd; i++) {
|
|
404
|
-
parent.insertBefore(b[i], after);
|
|
405
|
-
}
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
if (bStart > bEnd) {
|
|
409
|
-
for (let i = aStart; i <= aEnd; i++) {
|
|
410
|
-
parent.removeChild(a[i]);
|
|
411
|
-
}
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
const oldIndex = /* @__PURE__ */ new Map();
|
|
415
|
-
for (let i = aStart; i <= aEnd; i++) {
|
|
416
|
-
oldIndex.set(a[i], i);
|
|
417
|
-
}
|
|
418
|
-
const middle = bEnd - bStart + 1;
|
|
419
|
-
const sources = new Int32Array(middle).fill(-1);
|
|
420
|
-
for (let j = 0; j < middle; j++) {
|
|
421
|
-
const node = b[bStart + j];
|
|
422
|
-
const found = oldIndex.get(node);
|
|
423
|
-
if (found !== void 0) {
|
|
424
|
-
sources[j] = found;
|
|
425
|
-
oldIndex.delete(node);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
for (const node of oldIndex.keys()) {
|
|
429
|
-
parent.removeChild(node);
|
|
430
|
-
}
|
|
431
|
-
const keep = longestIncreasing(sources);
|
|
432
|
-
let k = keep.length - 1;
|
|
433
|
-
let anchor = after;
|
|
434
|
-
for (let j = middle - 1; j >= 0; j--) {
|
|
435
|
-
const node = b[bStart + j];
|
|
436
|
-
if (k >= 0 && keep[k] === j) {
|
|
437
|
-
k--;
|
|
438
|
-
} else {
|
|
439
|
-
parent.insertBefore(node, anchor);
|
|
440
|
-
}
|
|
441
|
-
anchor = node;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
function longestIncreasing(sources) {
|
|
445
|
-
const length = sources.length;
|
|
446
|
-
const predecessor = new Int32Array(length).fill(-1);
|
|
447
|
-
const tails = [];
|
|
448
|
-
for (let i = 0; i < length; i++) {
|
|
449
|
-
const value = sources[i];
|
|
450
|
-
if (value === -1) {
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
let low = 0;
|
|
454
|
-
let high = tails.length;
|
|
455
|
-
while (low < high) {
|
|
456
|
-
const mid = low + high >> 1;
|
|
457
|
-
if (sources[tails[mid]] < value) {
|
|
458
|
-
low = mid + 1;
|
|
459
|
-
} else {
|
|
460
|
-
high = mid;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (low > 0) {
|
|
464
|
-
predecessor[i] = tails[low - 1];
|
|
465
|
-
}
|
|
466
|
-
tails[low] = i;
|
|
467
|
-
}
|
|
468
|
-
const result = [];
|
|
469
|
-
let cursor = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
470
|
-
while (cursor !== -1) {
|
|
471
|
-
result.push(cursor);
|
|
472
|
-
cursor = predecessor[cursor];
|
|
473
|
-
}
|
|
474
|
-
return result.reverse();
|
|
475
|
-
}
|
|
476
413
|
|
|
477
414
|
export {
|
|
478
415
|
devWarn,
|
|
@@ -480,22 +417,19 @@ export {
|
|
|
480
417
|
devPart,
|
|
481
418
|
devComponent,
|
|
482
419
|
label,
|
|
420
|
+
devRan,
|
|
421
|
+
devHandedNewFunction,
|
|
483
422
|
devHydrationMismatch,
|
|
484
423
|
hydration,
|
|
485
424
|
first,
|
|
486
425
|
next,
|
|
426
|
+
reconcile,
|
|
487
427
|
discard,
|
|
488
428
|
FLAT,
|
|
429
|
+
PENDING,
|
|
489
430
|
part,
|
|
490
|
-
|
|
491
|
-
wrote,
|
|
492
|
-
site,
|
|
493
|
-
open,
|
|
494
|
-
close,
|
|
495
|
-
ran,
|
|
496
|
-
cell,
|
|
497
|
-
writeChild,
|
|
431
|
+
isDynamicChild,
|
|
498
432
|
insert,
|
|
499
433
|
applyChild,
|
|
500
|
-
|
|
434
|
+
bindPart
|
|
501
435
|
};
|
package/dist/hydrate.d.ts
CHANGED
|
@@ -86,6 +86,17 @@ export declare function adopt(tag: string): Node | null;
|
|
|
86
86
|
* and the caller renders it from nothing instead.
|
|
87
87
|
*/
|
|
88
88
|
export declare function claimRegion(parent: Node, marker: Node | null): Claimed | null;
|
|
89
|
+
/**
|
|
90
|
+
* Puts an anchor where hydration has got to, and hands back its parent.
|
|
91
|
+
*
|
|
92
|
+
* A keyed list's row that is a view is bound here rather than with the rest,
|
|
93
|
+
* because by then the reconciler would have put the list's anchors where the
|
|
94
|
+
* server's rows are and taken the rows out. The anchor goes in at the point
|
|
95
|
+
* the region has reached, and the row runs there — which adopts the nodes the
|
|
96
|
+
* server sent for it, in row order, because that is the order the markup is
|
|
97
|
+
* in.
|
|
98
|
+
*/
|
|
99
|
+
export declare function place(anchor: Node): Node | null;
|
|
89
100
|
/** Makes `region` the one nodes are adopted from while `body` runs. */
|
|
90
101
|
export declare function within<T>(region: Region, body: () => T): T;
|
|
91
102
|
//# sourceMappingURL=hydrate.d.ts.map
|
package/dist/hydrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../src/hydrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAa,KAAK,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA0B3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,SAAS,GAAE,UAA0B,GAAG,OAAO,CAIxF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAgBhE;AAaD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAW9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../src/hydrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAa,KAAK,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA0B3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,SAAS,GAAE,UAA0B,GAAG,OAAO,CAIxF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAgBhE;AAaD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAW9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,CAe7E;AA+DD;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAK/C;AAED,uEAAuE;AACvE,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAQ1D"}
|