@solidjs/web 2.0.0-rc.13 → 2.0.0-rc.14
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/server.dev.js +200 -73
- package/dist/server.js +182 -59
- package/dist/server.observe.js +183 -60
- package/dist/web.dev.js +70 -35
- package/dist/web.js +43 -31
- package/dist/web.observe.js +43 -33
- package/frames/dist/assets.js +92 -0
- package/frames/dist/bind.dev.js +326 -0
- package/frames/dist/bind.js +295 -0
- package/frames/dist/client.dev.js +605 -1086
- package/frames/dist/client.js +572 -1066
- package/frames/dist/client.observe.js +571 -1066
- package/frames/dist/regions.js +130 -0
- package/frames/dist/server.dev.js +339 -177
- package/frames/dist/server.js +335 -173
- package/frames/dist/server.observe.js +335 -173
- package/frames/dist/trace.js +42 -0
- package/frames/dist/wire.js +133 -0
- package/package.json +28 -2
- package/performance-tracks/dist/performance-tracks.dev.js +2 -1
- package/performance-tracks/dist/performance-tracks.observe.js +2 -1
- package/performance-tracks/types/index.d.ts +8 -6
- package/serialization/dist/decode.js +37 -8
- package/serialization/dist/serialization.js +39 -10
- package/serialization/types/serializer-decode.d.ts +24 -2
- package/server-functions/dist/client.dev.js +99 -61
- package/server-functions/dist/client.js +99 -61
- package/server-functions/dist/client.observe.js +99 -61
- package/server-functions/dist/server.dev.js +87 -50
- package/server-functions/dist/server.js +87 -50
- package/server-functions/dist/server.observe.js +87 -50
- package/skills/server-components/SKILL.md +65 -43
- package/types/client.d.ts +20 -0
- package/types/constants.d.ts +2 -1
- package/types/diagnostics.d.ts +8 -0
- package/types/frames/assets-tier.d.ts +78 -0
- package/types/frames/bind-tier.d.ts +60 -0
- package/types/frames/client.d.ts +37 -3
- package/types/frames/frame-client.d.ts +249 -78
- package/types/frames/frame-container-plugin.d.ts +2 -2
- package/types/frames/frame-sink.d.ts +33 -0
- package/types/frames/frame-transport.d.ts +66 -18
- package/types/frames/regions-tier.d.ts +45 -0
- package/types/frames/serializer-decode.d.ts +24 -2
- package/types/frames/server.d.ts +32 -8
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/wire-tier.d.ts +116 -0
- package/types/index.d.ts +38 -0
- package/types/index.server.d.ts +9 -0
- package/types/jsx.d.ts +1 -1
- package/types/observe.d.ts +4 -2
- package/types/serializer-decode.d.ts +24 -2
- package/types/server-functions/client.d.ts +26 -0
- package/types/server-functions/registry.d.ts +4 -1
- package/types/server-functions/shared.d.ts +12 -8
- package/types/server-mock.d.ts +13 -1
- package/types/server.d.ts +34 -8
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { createSignal, untrack, createRenderEffect, onCleanup } from 'solid-js';
|
|
2
|
+
import { assign, runHydrationEvents } from '@solidjs/web';
|
|
3
|
+
import { sharedConfig } from 'solid-js/internal';
|
|
4
|
+
import { isAsyncValue } from '@solidjs/web/frames';
|
|
5
|
+
|
|
6
|
+
const SLOT_MARKER = "_s:";
|
|
7
|
+
const SLOT_TEXT = SLOT_MARKER + "t=";
|
|
8
|
+
|
|
9
|
+
function slotEntry(entry, pos) {
|
|
10
|
+
const colon = entry.indexOf(":");
|
|
11
|
+
if (colon < 1) return null;
|
|
12
|
+
const eq = entry.indexOf("=", colon);
|
|
13
|
+
return [entry.slice(0, colon), {
|
|
14
|
+
pos,
|
|
15
|
+
key: decodeURIComponent(eq === -1 ? entry.slice(colon + 1) : entry.slice(colon + 1, eq)),
|
|
16
|
+
name: eq === -1 ? undefined : decodeURIComponent(entry.slice(eq + 1))
|
|
17
|
+
}];
|
|
18
|
+
}
|
|
19
|
+
function consumersOf(elements, occurrence) {
|
|
20
|
+
let consumers = elements.get(occurrence);
|
|
21
|
+
if (consumers === undefined) elements.set(occurrence, consumers = []);
|
|
22
|
+
return Array.isArray(consumers) ? consumers : null;
|
|
23
|
+
}
|
|
24
|
+
function text(start, elements) {
|
|
25
|
+
const parsed = slotEntry(start.data.slice(SLOT_TEXT.length), "text");
|
|
26
|
+
const consumers = parsed && consumersOf(elements, parsed[0]);
|
|
27
|
+
if (!consumers) return;
|
|
28
|
+
const element = start.parentNode;
|
|
29
|
+
let consumer;
|
|
30
|
+
for (let i = consumers.length; i-- && !consumer;) if (consumers[i].element === element) consumer = consumers[i];
|
|
31
|
+
consumer || consumers.push(consumer = {
|
|
32
|
+
element,
|
|
33
|
+
positions: []
|
|
34
|
+
});
|
|
35
|
+
parsed[1].start = start;
|
|
36
|
+
consumer.positions.push(parsed[1]);
|
|
37
|
+
}
|
|
38
|
+
function slotPositions(el) {
|
|
39
|
+
const attrs = el.attributes;
|
|
40
|
+
let out = null;
|
|
41
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
42
|
+
const attr = attrs[i];
|
|
43
|
+
if (!attr.name.startsWith(SLOT_MARKER)) continue;
|
|
44
|
+
const pos = attr.name.slice(SLOT_MARKER.length);
|
|
45
|
+
for (const entry of attr.value.split(",")) {
|
|
46
|
+
const parsed = slotEntry(entry, pos);
|
|
47
|
+
if (!parsed) continue;
|
|
48
|
+
out || (out = Object.create(null));
|
|
49
|
+
(out[parsed[0]] || (out[parsed[0]] = [])).push(parsed[1]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function positions(el, elements) {
|
|
55
|
+
const byOccurrence = slotPositions(el);
|
|
56
|
+
if (byOccurrence !== null) {
|
|
57
|
+
for (const occurrence in byOccurrence) {
|
|
58
|
+
const consumers = consumersOf(elements, occurrence);
|
|
59
|
+
if (consumers) consumers.push({
|
|
60
|
+
element: el,
|
|
61
|
+
positions: byOccurrence[occurrence]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function consumersEqual(a, b) {
|
|
67
|
+
if (a.length !== b.length) return false;
|
|
68
|
+
for (let i = 0; i < a.length; i++) {
|
|
69
|
+
const x = a[i];
|
|
70
|
+
const y = b[i];
|
|
71
|
+
if (x.element !== y.element || x.positions.length !== y.positions.length) return false;
|
|
72
|
+
for (let j = 0; j < x.positions.length; j++) {
|
|
73
|
+
const p = x.positions[j];
|
|
74
|
+
const q = y.positions[j];
|
|
75
|
+
if (p.pos !== q.pos || p.key !== q.key || p.name !== q.name || p.start !== q.start) return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const byFrame = new WeakMap();
|
|
81
|
+
function occurrencesOf(frame) {
|
|
82
|
+
let slots = byFrame.get(frame);
|
|
83
|
+
if (!slots) byFrame.set(frame, slots = new Map());
|
|
84
|
+
return slots;
|
|
85
|
+
}
|
|
86
|
+
function sync(frame, occurrence, consumers) {
|
|
87
|
+
const slots = occurrencesOf(frame);
|
|
88
|
+
const entry = slots.get(occurrence);
|
|
89
|
+
if (!entry) slots.set(occurrence, {
|
|
90
|
+
consumers,
|
|
91
|
+
rebind: undefined
|
|
92
|
+
});else if (!entry.consumers) entry.consumers = consumers;else if (!consumersEqual(entry.consumers, consumers)) {
|
|
93
|
+
entry.consumers = consumers;
|
|
94
|
+
entry.rebind && entry.rebind(consumers);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function rebinder(frame, occurrence, fn) {
|
|
98
|
+
const slots = occurrencesOf(frame);
|
|
99
|
+
const entry = slots.get(occurrence);
|
|
100
|
+
if (entry) entry.rebind = fn;else slots.set(occurrence, {
|
|
101
|
+
consumers: undefined,
|
|
102
|
+
rebind: fn
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function unmount(frame, occurrence) {
|
|
106
|
+
byFrame.get(frame)?.delete(occurrence);
|
|
107
|
+
}
|
|
108
|
+
function owned(el) {
|
|
109
|
+
const attrs = el.attributes;
|
|
110
|
+
let out = null;
|
|
111
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
112
|
+
const name = attrs[i].name;
|
|
113
|
+
if (!name.startsWith(SLOT_MARKER)) continue;
|
|
114
|
+
const pos = name.slice(SLOT_MARKER.length);
|
|
115
|
+
if (pos === "ref" || pos.startsWith("on:")) continue;
|
|
116
|
+
out || (out = {
|
|
117
|
+
attrs: new Set(),
|
|
118
|
+
class: null,
|
|
119
|
+
style: null
|
|
120
|
+
});
|
|
121
|
+
if (pos !== "class" && pos !== "style") {
|
|
122
|
+
out.attrs.add(pos);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
for (const entry of attrs[i].value.split(",")) {
|
|
126
|
+
const eq = entry.indexOf("=");
|
|
127
|
+
if (eq === -1) {
|
|
128
|
+
out.attrs.add(pos);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
(out[pos] || (out[pos] = [])).push(decodeURIComponent(entry.slice(eq + 1)));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
function morphOwnedClass(oldEl, value, names) {
|
|
137
|
+
const list = oldEl.classList;
|
|
138
|
+
const set = new Set(value ? value.split(/\s+/) : []);
|
|
139
|
+
set.delete("");
|
|
140
|
+
for (const name of names) list.contains(name) ? set.add(name) : set.delete(name);
|
|
141
|
+
const next = [...set].join(" ");
|
|
142
|
+
if (next === (oldEl.getAttribute("class") || "")) return false;
|
|
143
|
+
next ? oldEl.setAttribute("class", next) : oldEl.removeAttribute("class");
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
function morphOwnedStyle(oldEl, value, names) {
|
|
147
|
+
const style = oldEl.style;
|
|
148
|
+
const saved = names.map(name => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
|
|
149
|
+
const before = oldEl.getAttribute("style");
|
|
150
|
+
value ? oldEl.setAttribute("style", value) : oldEl.removeAttribute("style");
|
|
151
|
+
for (const [name, v, priority] of saved) {
|
|
152
|
+
v ? style.setProperty(name, v, priority) : style.removeProperty(name);
|
|
153
|
+
}
|
|
154
|
+
return oldEl.getAttribute("style") !== before;
|
|
155
|
+
}
|
|
156
|
+
function apply(oldEl, name, value, owned) {
|
|
157
|
+
if (owned.attrs.has(name)) return false;
|
|
158
|
+
if ((name === "class" || name === "style") && owned[name] !== null) {
|
|
159
|
+
return name === "class" ? morphOwnedClass(oldEl, value, owned.class) : morphOwnedStyle(oldEl, value, owned.style);
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
const handlerOwners = new WeakMap();
|
|
164
|
+
function bind(fill, args, ctx, label) {
|
|
165
|
+
const [consumers, setConsumers] = createSignal(ctx.positions);
|
|
166
|
+
ctx.onRebind(setConsumers);
|
|
167
|
+
const raw = untrack(() => fill(args), label);
|
|
168
|
+
const node = typeof Node === "function" && raw instanceof Node;
|
|
169
|
+
const pending = isAsyncValue(raw);
|
|
170
|
+
const out = raw == null || typeof raw !== "object" || node || pending ? {} : raw;
|
|
171
|
+
const token = {};
|
|
172
|
+
const state = new WeakMap();
|
|
173
|
+
let bound = new Set();
|
|
174
|
+
createRenderEffect(() => consumers().map(valuesFor), writes => {
|
|
175
|
+
const next = new Set();
|
|
176
|
+
for (const {
|
|
177
|
+
element,
|
|
178
|
+
positions,
|
|
179
|
+
values,
|
|
180
|
+
texts
|
|
181
|
+
} of writes) {
|
|
182
|
+
next.add(element);
|
|
183
|
+
write(element, positions, values);
|
|
184
|
+
for (const [start, v, key] of texts) writeText(start, v);
|
|
185
|
+
}
|
|
186
|
+
for (const element of bound) if (!next.has(element)) release(element);
|
|
187
|
+
bound = next;
|
|
188
|
+
});
|
|
189
|
+
onCleanup(() => {
|
|
190
|
+
for (const element of bound) release(element);
|
|
191
|
+
});
|
|
192
|
+
function valuesFor({
|
|
193
|
+
element,
|
|
194
|
+
positions
|
|
195
|
+
}) {
|
|
196
|
+
const props = {};
|
|
197
|
+
const texts = [];
|
|
198
|
+
let classNames = null;
|
|
199
|
+
let styleProps = null;
|
|
200
|
+
for (const {
|
|
201
|
+
pos,
|
|
202
|
+
key,
|
|
203
|
+
name,
|
|
204
|
+
start
|
|
205
|
+
} of positions) {
|
|
206
|
+
if (pos === "ref" || pos.startsWith("on:")) continue;
|
|
207
|
+
if (pos === "text") texts.push([start, out[key], key]);else if (pos === "class" || pos === "style") {
|
|
208
|
+
if (name === undefined) props[pos] = out[key];else if (pos === "class") (classNames || (classNames = {}))[name] = !!out[key];else (styleProps || (styleProps = {}))[name] = out[key];
|
|
209
|
+
} else props[pos] = out[key];
|
|
210
|
+
}
|
|
211
|
+
if (classNames !== null && !("class" in props)) props.class = classNames;
|
|
212
|
+
if (styleProps !== null && !("style" in props)) props.style = styleProps;
|
|
213
|
+
return {
|
|
214
|
+
element,
|
|
215
|
+
positions,
|
|
216
|
+
values: props,
|
|
217
|
+
texts
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function write(element, positions, props) {
|
|
221
|
+
let st = state.get(element);
|
|
222
|
+
if (!st) state.set(element, st = {
|
|
223
|
+
prev: {},
|
|
224
|
+
handlers: {},
|
|
225
|
+
ref: undefined,
|
|
226
|
+
refId: ""
|
|
227
|
+
});
|
|
228
|
+
const handlers = {};
|
|
229
|
+
const refKeys = [];
|
|
230
|
+
for (const {
|
|
231
|
+
pos,
|
|
232
|
+
key
|
|
233
|
+
} of positions) {
|
|
234
|
+
if (pos === "ref") refKeys.push(key);else if (pos.startsWith("on:")) handlers["on" + pos[3].toUpperCase() + pos.slice(4)] = key;
|
|
235
|
+
}
|
|
236
|
+
let owners = handlerOwners.get(element);
|
|
237
|
+
if (!owners) handlerOwners.set(element, owners = {});
|
|
238
|
+
let events = false;
|
|
239
|
+
for (const prop in handlers) {
|
|
240
|
+
events = true;
|
|
241
|
+
const key = handlers[prop];
|
|
242
|
+
let h = st.handlers[prop];
|
|
243
|
+
if (h === undefined || h.key !== key) st.handlers[prop] = h = {
|
|
244
|
+
key,
|
|
245
|
+
value: untrack(() => out[key])
|
|
246
|
+
};
|
|
247
|
+
props[prop] = h.value;
|
|
248
|
+
owners[prop] = token;
|
|
249
|
+
}
|
|
250
|
+
const clearing = {};
|
|
251
|
+
for (const prop in st.handlers) {
|
|
252
|
+
if (prop in handlers) continue;
|
|
253
|
+
delete st.handlers[prop];
|
|
254
|
+
if (owners[prop] === token) {
|
|
255
|
+
delete owners[prop];
|
|
256
|
+
clearing[prop] = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (refKeys.length) {
|
|
260
|
+
const id = refKeys.join(",");
|
|
261
|
+
if (st.refId !== id) {
|
|
262
|
+
const refs = refKeys.map(k => untrack(() => out[k]));
|
|
263
|
+
st.refId = id;
|
|
264
|
+
st.ref = el => {
|
|
265
|
+
for (const r of refs) typeof r === "function" && r(el);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
props.ref = st.ref;
|
|
269
|
+
}
|
|
270
|
+
for (const k in st.prev) {
|
|
271
|
+
if (k in props || k === "ref" || k in clearing) continue;
|
|
272
|
+
delete st.prev[k];
|
|
273
|
+
}
|
|
274
|
+
assign(element, props, true, st.prev);
|
|
275
|
+
if (events && sharedConfig.completed && !sharedConfig.completed.has(element)) {
|
|
276
|
+
sharedConfig.completed.add(element);
|
|
277
|
+
runHydrationEvents();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function release(element) {
|
|
281
|
+
if (!state.has(element)) return;
|
|
282
|
+
write(element, [], {});
|
|
283
|
+
state.delete(element);
|
|
284
|
+
}
|
|
285
|
+
function writeText(start, v, key) {
|
|
286
|
+
let s = "";
|
|
287
|
+
if (typeof v === "string" || typeof v === "number") s = "" + v;
|
|
288
|
+
const n = start.nextSibling;
|
|
289
|
+
if (n && n.nodeType === 3) {
|
|
290
|
+
if (n.data !== s) n.data = s;
|
|
291
|
+
} else if (s) start.after(s);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export { apply, bind, owned, positions, rebinder, sync, text, unmount };
|