@solidjs/web 2.0.0-rc.15 → 2.0.0-rc.17

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.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +361 -483
  3. package/dist/server.js +346 -391
  4. package/dist/server.observe.js +346 -391
  5. package/dist/web.dev.js +110 -55
  6. package/dist/web.js +51 -50
  7. package/dist/web.observe.js +61 -55
  8. package/frames/dist/client.dev.js +610 -621
  9. package/frames/dist/client.js +540 -566
  10. package/frames/dist/client.observe.js +571 -573
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +793 -424
  13. package/frames/dist/server.js +792 -371
  14. package/frames/dist/server.observe.js +792 -371
  15. package/frames/dist/wire.js +371 -6
  16. package/package.json +11 -11
  17. package/serialization/dist/decode.js +9 -7
  18. package/serialization/dist/serialization.js +9 -7
  19. package/serialization/types/serializer-decode.d.ts +2 -2
  20. package/server-functions/dist/client.dev.js +13 -22
  21. package/server-functions/dist/client.js +11 -22
  22. package/server-functions/dist/client.observe.js +13 -22
  23. package/server-functions/dist/rich-args.js +84 -1
  24. package/server-functions/dist/server.dev.js +194 -20
  25. package/server-functions/dist/server.js +194 -20
  26. package/server-functions/dist/server.observe.js +194 -20
  27. package/skills/server-components/SKILL.md +74 -185
  28. package/types/client.d.ts +27 -5
  29. package/types/diagnostics.d.ts +16 -0
  30. package/types/frames/assets-tier.d.ts +2 -2
  31. package/types/frames/client.d.ts +8 -3
  32. package/types/frames/frame-client.d.ts +121 -157
  33. package/types/frames/frame-morph.d.ts +28 -0
  34. package/types/frames/frame-sink.d.ts +13 -9
  35. package/types/frames/frame-transport.d.ts +30 -1
  36. package/types/frames/regions-tier.d.ts +15 -0
  37. package/types/frames/serializer-decode.d.ts +2 -2
  38. package/types/frames/server.d.ts +0 -52
  39. package/types/frames/wire-tier.d.ts +54 -1
  40. package/types/index.d.ts +2 -2
  41. package/types/jsx.d.ts +11 -5
  42. package/types/observe.d.ts +14 -7
  43. package/types/render.d.ts +3 -1
  44. package/types/response.d.ts +5 -4
  45. package/types/serializer-decode.d.ts +2 -2
  46. package/types/server-functions/argument-codec.d.ts +30 -0
  47. package/types/server-functions/client.d.ts +27 -9
  48. package/types/server-functions/server.d.ts +23 -2
  49. package/types/server-functions/shared.d.ts +19 -0
  50. package/types/server-functions/uploads.d.ts +50 -0
  51. package/types/server-observe.d.ts +3 -2
  52. package/types/server.d.ts +58 -77
  53. package/frames/dist/bind.dev.js +0 -326
  54. package/frames/dist/bind.js +0 -295
  55. package/types/frames/bind-tier.d.ts +0 -60
@@ -1,295 +0,0 @@
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 };
@@ -1,60 +0,0 @@
1
- /**
2
- * Register a text start marker's position on its parent element's consumer
3
- * entry for the occurrence — the one its attribute markers opened, if any,
4
- * so an element is one consumer however its positions are spelled. The slot
5
- * sync's walk dispatches here (frame-client.ts `collectSlots`).
6
- */
7
- export declare function text(start: Comment, elements: Map<string, any>): void;
8
- /**
9
- * An element's positions join each occurrence's consumer list, in document
10
- * order. The slot sync's walk dispatches here for every server element with
11
- * attributes (frame-client.ts `collectSlots`).
12
- */
13
- export declare function positions(el: Element, elements: Map<string, any>): void;
14
- /**
15
- * The consumer set the slot sync found for a MOUNTED data occurrence — at
16
- * the mount (the set the fill was handed) and on every re-sync. A changed
17
- * set (a morph replaced one of its elements, a response added or dropped a
18
- * bound position) rebinds in place through the mount's rebinder: the fill's
19
- * computation stays, the binding gets the new set.
20
- */
21
- export declare function sync(frame: object, occurrence: string, consumers: any[]): void;
22
- /** The mount's rebind callback (`ctx.onRebind`), registered during the
23
- * invocation — before `sync` records the mount's set. */
24
- export declare function rebinder(frame: object, occurrence: string, fn: (consumers: any[]) => void): void;
25
- /** The occurrence is gone (unmounted, or re-invoked: the new invocation
26
- * registers its own rebinder). */
27
- export declare function unmount(frame: object, occurrence: string): void;
28
- /** The positions of an incoming element a client fill writes (see
29
- * `owned`). */
30
- interface Owned {
31
- attrs: Set<string>;
32
- class: string[] | null;
33
- style: string[] | null;
34
- }
35
- export declare function owned(el: Element): Owned | null;
36
- /**
37
- * Apply the server's value for `name` (null: absent) to an element with
38
- * binding-slot positions: a client-owned attribute is left alone; owned
39
- * `class`/`style` NAMES are re-imposed over the server's string. Returns
40
- * whether the attribute changed, or undefined when the position is not
41
- * owned and the caller writes it. (The eager wrapper answers `undefined`
42
- * itself for a null `owned`; the arms call here with one.)
43
- */
44
- export declare function apply(oldEl: Element, name: string, value: string, owned: Owned): boolean | undefined;
45
- /**
46
- * Bind a binding-slot occurrence (principles §9.2.3). The fill runs ONCE,
47
- * untracked, under the occurrence's owner — a component body: a top-level
48
- * read is a one-time read (dev names it through `untrack`'s label), and state
49
- * created in the body lives as long as the occurrence. Its object's value
50
- * positions are written by one render effect over every consuming element,
51
- * diffed per position by `assign`, so a getter's change re-reads the
52
- * occurrence and touches only what moved. Handlers and refs are read once
53
- * when an element binds and handed to `assign`, which binds them as client
54
- * JSX does (delegation, tuples). A consumer change (`ctx.onRebind`: the morph
55
- * replaced an element, a response bound a new position) rebinds without
56
- * re-running the fill. The client entry's `slotsFor` dispatches here under
57
- * the occurrence's owner (client.ts).
58
- */
59
- export declare function bind(fill: (args: any) => any, args: any, ctx: any, label: string | undefined): void;
60
- export {};