solid-js 2.0.0-beta.1 → 2.0.0-beta.11

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 (38) hide show
  1. package/CHEATSHEET.md +640 -0
  2. package/README.md +42 -188
  3. package/dist/dev.cjs +446 -291
  4. package/dist/dev.js +426 -293
  5. package/dist/server.cjs +941 -345
  6. package/dist/server.js +897 -299
  7. package/dist/solid.cjs +438 -261
  8. package/dist/solid.js +418 -263
  9. package/package.json +67 -39
  10. package/types/client/component.d.ts +64 -19
  11. package/types/client/core.d.ts +110 -34
  12. package/types/client/flow.d.ts +176 -42
  13. package/types/client/hydration.d.ts +513 -37
  14. package/types/index.d.ts +8 -13
  15. package/types/server/component.d.ts +11 -11
  16. package/types/server/core.d.ts +19 -21
  17. package/types/server/flow.d.ts +76 -21
  18. package/types/server/hydration.d.ts +34 -9
  19. package/types/server/index.d.ts +6 -8
  20. package/types/server/shared.d.ts +10 -2
  21. package/types/server/signals.d.ts +80 -19
  22. package/types/types.d.ts +15 -0
  23. package/types-cjs/client/component.d.cts +120 -0
  24. package/types-cjs/client/core.d.cts +141 -0
  25. package/types-cjs/client/flow.d.cts +234 -0
  26. package/types-cjs/client/hydration.d.cts +568 -0
  27. package/types-cjs/index.d.cts +15 -0
  28. package/types-cjs/package.json +3 -0
  29. package/types-cjs/server/component.d.cts +67 -0
  30. package/types-cjs/server/core.d.cts +42 -0
  31. package/types-cjs/server/flow.d.cts +115 -0
  32. package/types-cjs/server/hydration.d.cts +63 -0
  33. package/types-cjs/server/index.d.cts +10 -0
  34. package/types-cjs/server/shared.d.cts +54 -0
  35. package/types-cjs/server/signals.d.cts +123 -0
  36. package/types-cjs/types.d.cts +15 -0
  37. package/jsx-runtime.d.ts +0 -1
  38. package/types/jsx.d.ts +0 -4129
@@ -1,10 +1,18 @@
1
- import type { Accessor } from "@solidjs/signals";
2
- import type { JSX } from "../jsx.js";
1
+ import type { Accessor, RevealOrder } from "@solidjs/signals";
2
+ export type { RevealOrder };
3
+ import type { Element as SolidElement } from "../types.js";
4
+ type NonZeroParams<T extends (...args: any[]) => any> = Parameters<T>["length"] extends 0 ? never : T;
5
+ type ConditionalRenderCallback<T> = (item: Accessor<NonNullable<T>>) => SolidElement;
6
+ type ConditionalRenderChildren<T, F extends ConditionalRenderCallback<T> = ConditionalRenderCallback<T>> = SolidElement | NonZeroParams<F>;
3
7
  /**
4
- * Creates a list of elements from a list
8
+ * Creates a list of elements from a list.
5
9
  *
6
- * it receives a map function as its child that receives list element and index accessors and returns a JSX-Element; if the list is empty, an optional fallback is returned:
7
- * ```typescript
10
+ * Receives a map function as its child that takes list element and index
11
+ * accessors and returns a JSX element; if the list is empty, an optional
12
+ * `fallback` is rendered instead.
13
+ *
14
+ * @example
15
+ * ```tsx
8
16
  * <For each={items} fallback={<div>No items</div>}>
9
17
  * {(item, index) => <div data-index={index()}>{item()}</div>}
10
18
  * </For>
@@ -12,17 +20,20 @@ import type { JSX } from "../jsx.js";
12
20
  *
13
21
  * @description https://docs.solidjs.com/reference/components/for
14
22
  */
15
- export declare function For<T extends readonly any[], U extends JSX.Element>(props: {
23
+ export declare function For<T extends readonly any[], U extends SolidElement>(props: {
16
24
  each: T | undefined | null | false;
17
- fallback?: JSX.Element;
25
+ fallback?: SolidElement;
18
26
  keyed?: boolean | ((item: T[number]) => any);
19
27
  children: (item: Accessor<T[number]>, index: Accessor<number>) => U;
20
- }): JSX.Element;
28
+ }): SolidElement;
21
29
  /**
22
- * Creates a list elements from a count
30
+ * Creates a list of elements from a count.
31
+ *
32
+ * Receives a map function as its child that takes the index and returns a JSX
33
+ * element; if the count is zero, an optional `fallback` is rendered instead.
23
34
  *
24
- * it receives a map function as its child that receives the index and returns a JSX-Element; if the list is empty, an optional fallback is returned:
25
- * ```typescript
35
+ * @example
36
+ * ```tsx
26
37
  * <Repeat count={items.length} fallback={<div>No items</div>}>
27
38
  * {(index) => <div data-index={index}>{items[index]}</div>}
28
39
  * </Repeat>
@@ -30,25 +41,43 @@ export declare function For<T extends readonly any[], U extends JSX.Element>(pro
30
41
  *
31
42
  * @description https://docs.solidjs.com/reference/components/repeat
32
43
  */
33
- export declare function Repeat<T extends JSX.Element>(props: {
44
+ export declare function Repeat<T extends SolidElement>(props: {
34
45
  count: number;
35
46
  from?: number | undefined;
36
- fallback?: JSX.Element;
47
+ fallback?: SolidElement;
37
48
  children: ((index: number) => T) | T;
38
- }): JSX.Element;
49
+ }): SolidElement;
39
50
  /**
40
- * Conditionally render its children or an optional fallback component
51
+ * Conditionally renders its children when `when` is truthy, otherwise renders
52
+ * the optional `fallback`.
53
+ *
54
+ * The function-child form receives an accessor for the narrowed value — call
55
+ * it to read. Without `keyed` (default), the child is preserved across
56
+ * truthy values; with `keyed`, the child remounts whenever the value's
57
+ * identity changes.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * <Show when={user()} fallback={<SignIn />}>
62
+ * {u => <Greeting name={u().name} />}
63
+ * </Show>
64
+ * ```
65
+ *
41
66
  * @description https://docs.solidjs.com/reference/components/show
42
67
  */
43
- export declare function Show<T>(props: {
68
+ export declare function Show<T, F extends ConditionalRenderCallback<T>>(props: {
44
69
  when: T | undefined | null | false;
45
70
  keyed?: boolean;
46
- fallback?: JSX.Element;
47
- children: JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element);
48
- }): JSX.Element;
71
+ fallback?: SolidElement;
72
+ children: ConditionalRenderChildren<T, F>;
73
+ }): SolidElement;
49
74
  /**
50
- * Switches between content based on mutually exclusive conditions
51
- * ```typescript
75
+ * Switches between content based on mutually exclusive conditions. Renders
76
+ * the first `<Match>` whose `when` is truthy; falls back to `fallback` when
77
+ * none match.
78
+ *
79
+ * @example
80
+ * ```tsx
52
81
  * <Switch fallback={<FourOhFour />}>
53
82
  * <Match when={state.route === 'home'}>
54
83
  * <Home />
@@ -58,43 +87,148 @@ export declare function Show<T>(props: {
58
87
  * </Match>
59
88
  * </Switch>
60
89
  * ```
90
+ *
61
91
  * @description https://docs.solidjs.com/reference/components/switch-and-match
62
92
  */
63
93
  export declare function Switch(props: {
64
- fallback?: JSX.Element;
65
- children: JSX.Element;
66
- }): JSX.Element;
67
- export type MatchProps<T> = {
94
+ fallback?: SolidElement;
95
+ children: SolidElement;
96
+ }): SolidElement;
97
+ export type MatchProps<T, F extends ConditionalRenderCallback<T> = ConditionalRenderCallback<T>> = {
68
98
  when: T | undefined | null | false;
69
99
  keyed?: boolean;
70
- children: JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element);
100
+ children: ConditionalRenderChildren<T, F>;
71
101
  };
72
102
  /**
73
- * Selects a content based on condition when inside a `<Switch>` control flow
74
- * ```typescript
75
- * <Match when={condition()}>
76
- * <Content/>
77
- * </Match>
103
+ * A branch inside a `<Switch>`. The first `<Match>` whose `when` is truthy
104
+ * wins; remaining matches are skipped.
105
+ *
106
+ * Like `<Show>`, `<Match>` supports a function child that receives an
107
+ * accessor for the narrowed value.
108
+ *
109
+ * @example
110
+ * ```tsx
111
+ * <Switch fallback={<NotFound />}>
112
+ * <Match when={user()}>
113
+ * {u => <Profile name={u().name} />}
114
+ * </Match>
115
+ * <Match when={loading()}>
116
+ * <Spinner />
117
+ * </Match>
118
+ * </Switch>
78
119
  * ```
120
+ *
79
121
  * @description https://docs.solidjs.com/reference/components/switch-and-match
80
122
  */
81
- export declare function Match<T>(props: MatchProps<T>): JSX.Element;
123
+ export declare function Match<T, F extends ConditionalRenderCallback<T>>(props: MatchProps<T, F>): SolidElement;
82
124
  /**
83
- * Catches uncaught errors inside components and renders a fallback content
125
+ * Catches uncaught errors inside its subtree and renders fallback content
126
+ * instead. The `fallback` prop can be a JSX element, or a callback that
127
+ * receives the error and a `reset()` function for retry affordances.
84
128
  *
85
- * Also supports a callback form that passes the error and a reset function:
86
- * ```typescript
87
- * <Errored fallback={
88
- * (err, reset) => <div onClick={reset}>Error: {err.toString()}</div>
89
- * }>
129
+ * Errors thrown from the fallback itself can be caught by a parent
130
+ * `<Errored>`.
131
+ *
132
+ * @example
133
+ * ```tsx
134
+ * <Errored fallback={(err, reset) => (
135
+ * <div onClick={reset}>Error: {err.toString()}</div>
136
+ * )}>
90
137
  * <MyComp />
91
138
  * </Errored>
92
139
  * ```
93
- * Errors thrown from the fallback can be caught by a parent Errored
94
140
  *
95
141
  * @description https://docs.solidjs.com/reference/components/error-boundary
96
142
  */
97
143
  export declare function Errored(props: {
98
- fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
99
- children: JSX.Element;
100
- }): JSX.Element;
144
+ fallback: SolidElement | ((err: any, reset: () => void) => SolidElement);
145
+ children: SolidElement;
146
+ }): SolidElement;
147
+ /**
148
+ * Renders a `fallback` while pending async reads inside the subtree settle.
149
+ *
150
+ * Any computation (`createMemo`, `createSignal(fn)`, `createStore(fn)`,
151
+ * `lazy(...)`, etc.) that throws because data isn't ready is caught by the
152
+ * nearest enclosing `<Loading>`. The boundary swaps to its `fallback` until
153
+ * every pending read has resolved, then renders the children.
154
+ *
155
+ * The optional `on` prop scopes the boundary so it ignores transitions
156
+ * caused by writes to other reactive sources — those transitions stay on the
157
+ * previous content (with `isPending()` flipping during the transition).
158
+ *
159
+ * Scope `<Loading>` around the data-dependent slot, not the surrounding
160
+ * shell. Wrapping layout chrome (header, nav, footer) in the same boundary
161
+ * as the data means revalidation replaces the entire screen with the
162
+ * fallback; rendering chrome outside the boundary keeps it stable while
163
+ * only the affordance flips.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * const Profile = lazy(() => import("./Profile"));
168
+ *
169
+ * <Loading fallback={<Spinner />}>
170
+ * <Profile />
171
+ * </Loading>
172
+ * ```
173
+ *
174
+ * @example
175
+ * ```tsx
176
+ * // Only show the fallback for transitions caused by writes to `route`.
177
+ * <Loading fallback={<Skeleton />} on={route}>
178
+ * <Page />
179
+ * </Loading>
180
+ * ```
181
+ *
182
+ * @description https://docs.solidjs.com/reference/components/suspense
183
+ */
184
+ export declare function Loading(props: {
185
+ fallback?: SolidElement;
186
+ on?: any;
187
+ children: SolidElement;
188
+ }): SolidElement;
189
+ export type RevealProps = {
190
+ order?: RevealOrder;
191
+ collapsed?: boolean;
192
+ children: SolidElement;
193
+ };
194
+ /**
195
+ * Coordinates the reveal timing of sibling `<Loading>` boundaries.
196
+ *
197
+ * The `order` prop picks the reveal policy:
198
+ * - `"sequential"` (default) — boundaries reveal in registration order; later boundaries
199
+ * stay on their fallback until earlier ones resolve.
200
+ * - `"together"` — every direct slot stays on its fallback until the whole group is
201
+ * "minimally ready" (every direct slot has its own first visible content available),
202
+ * then the group releases in one cohesive reveal.
203
+ * - `"natural"` — each boundary reveals as its own data resolves. At the top level
204
+ * this is equivalent to omitting `<Reveal>`; the mode exists for nesting, where
205
+ * the group registers as a single composite slot in an enclosing `<Reveal>`.
206
+ *
207
+ * The `collapsed` prop is only consulted when `order="sequential"` (the default);
208
+ * it is ignored under `"together"` and `"natural"`. When set, tail boundaries past
209
+ * the frontier suppress their own fallback output.
210
+ *
211
+ * Nested `<Reveal>` groups compose: the inner group is one slot in the outer order
212
+ * and is held on its fallbacks until the outer releases the slot. Once released, the
213
+ * inner group runs its own `order` locally over whatever is still pending. There is
214
+ * no escape hatch — nesting under an outer group means participating in its ordering.
215
+ * See `documentation/solid-2.0/03-control-flow.md` for the full nesting matrix and the
216
+ * "minimally ready" definition per order.
217
+ *
218
+ * @example
219
+ * ```tsx
220
+ * // Default order is "sequential"; the inner group composes as one slot
221
+ * // and runs its own "natural" order locally once the outer releases it.
222
+ * <Reveal>
223
+ * <Loading fallback={<Skeleton />}><ProfileHeader /></Loading>
224
+ * <Reveal order="natural">
225
+ * <Loading fallback={<Skeleton />}><PostA /></Loading>
226
+ * <Loading fallback={<Skeleton />}><PostB /></Loading>
227
+ * </Reveal>
228
+ * <Loading fallback={<Skeleton />}><Comments /></Loading>
229
+ * </Reveal>
230
+ * ```
231
+ *
232
+ * @description https://docs.solidjs.com/reference/components/reveal
233
+ */
234
+ export declare function Reveal(props: RevealProps): SolidElement;