solid-js 1.1.2 → 1.1.6-beta.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.
@@ -15,7 +15,6 @@ interface Signal<T> {
15
15
  observers: Computation<any>[] | null;
16
16
  observerSlots: number[] | null;
17
17
  pending: T | {};
18
- tValue?: T;
19
18
  comparator?: (prev: T, next: T) => boolean;
20
19
  name?: string;
21
20
  }
@@ -33,47 +32,140 @@ interface Owner {
33
32
  interface Computation<T> extends Owner {
34
33
  fn: (v?: T) => T;
35
34
  state: number;
36
- tState?: number;
37
35
  sources: Signal<T>[] | null;
38
36
  sourceSlots: number[] | null;
39
37
  value?: T;
40
- updatedAt: number | null;
38
+ updatedAt: number;
41
39
  pure: boolean;
42
40
  user?: boolean;
43
41
  suspense?: SuspenseContextType;
44
42
  }
45
- interface Memo<T> extends Signal<T>, Computation<T> {
46
- tOwned?: Computation<any>[];
47
- }
48
43
  interface Transition {
49
- sources: Set<Signal<any>>;
44
+ sources: Set<Signal<any> | Computation<any>>;
45
+ lookup: Map<Signal<any> | Computation<any>, Signal<any> | Computation<any>>;
46
+ updated: Set<Computation<any>>;
50
47
  effects: Computation<any>[];
51
48
  promises: Set<Promise<any>>;
52
- disposed: Set<Computation<any>>;
53
49
  queue: Set<Computation<any>>;
54
50
  scheduler?: (fn: () => void) => unknown;
55
51
  running: boolean;
56
52
  cb: (() => void)[];
57
53
  }
54
+ /**
55
+ * Creates a new non-tracked reactive context that doesn't auto-dispose
56
+ *
57
+ * @param fn a function in which the reactive state is scoped
58
+ * @param detachedOwner optional reactive context to bind the root to
59
+ * @returns the output of `fn`.
60
+ *
61
+ * @description https://www.solidjs.com/docs/latest/api#createroot
62
+ */
58
63
  export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: Owner): T;
64
+ export declare type SignalOptions<T> = {
65
+ name?: string;
66
+ equals?: false | ((prev: T, next: T) => boolean);
67
+ };
68
+ /**
69
+ * Creates a simple reactive state with a getter and setter
70
+ * ```typescript
71
+ * const [state: Accessor<T>, setState: Setter<T>] = createSignal<T>(
72
+ * value: T,
73
+ * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
74
+ * )
75
+ * ```
76
+ * @param value initial value of the state; if empty, the state's type will automatically extended with undefined; otherwise you need to extend the type manually if you want setting to undefined not be an error
77
+ * @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
78
+ *
79
+ * @returns ```typescript
80
+ * [state: Accessor<T>, setState: Setter<T>]
81
+ * ```
82
+ * * the Accessor is merely a function that returns the current value and registers each call to the reactive root
83
+ * * the Setter is a function that allows directly setting or mutating the value:
84
+ * ```typescript
85
+ * const [count, setCount] = createSignal(0);
86
+ * setCount(count => count + 1);
87
+ * ```
88
+ *
89
+ * @description https://www.solidjs.com/docs/latest/api#createsignal
90
+ */
59
91
  export declare function createSignal<T>(): [get: Accessor<T | undefined>, set: Setter<T | undefined>];
60
92
  export declare function createSignal<T>(value: T, options?: {
61
93
  equals?: false | ((prev: T, next: T) => boolean);
62
94
  name?: string;
63
95
  internal?: boolean;
64
96
  }): [get: Accessor<T>, set: Setter<T>];
97
+ /**
98
+ * Creates a reactive computation that runs immediately before render, mainly used to write to other reactive primitives
99
+ * ```typescript
100
+ * export function createComputed<T>(
101
+ * fn: (v: T) => T,
102
+ * value?: T,
103
+ * options?: { name?: string }
104
+ * ): void;
105
+ * ```
106
+ * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
107
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
108
+ * @param options allows to set a name in dev mode for debugging purposes
109
+ *
110
+ * @description https://www.solidjs.com/docs/latest/api#createcomputed
111
+ */
65
112
  export declare function createComputed<T>(fn: (v?: T) => T | undefined): void;
66
113
  export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
67
114
  name?: string;
68
115
  }): void;
116
+ /**
117
+ * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
118
+ * ```typescript
119
+ * export function createRenderEffect<T>(
120
+ * fn: (v: T) => T,
121
+ * value?: T,
122
+ * options?: { name?: string }
123
+ * ): void;
124
+ * ```
125
+ * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
126
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
127
+ * @param options allows to set a name in dev mode for debugging purposes
128
+ *
129
+ * @description https://www.solidjs.com/docs/latest/api#createrendereffect
130
+ */
69
131
  export declare function createRenderEffect<T>(fn: (v?: T) => T | undefined): void;
70
132
  export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options?: {
71
133
  name?: string;
72
134
  }): void;
135
+ /**
136
+ * Creates a reactive computation that runs after the render phase
137
+ * ```typescript
138
+ * export function createEffect<T>(
139
+ * fn: (v: T) => T,
140
+ * value?: T,
141
+ * options?: { name?: string }
142
+ * ): void;
143
+ * ```
144
+ * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
145
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
146
+ * @param options allows to set a name in dev mode for debugging purposes
147
+ *
148
+ * @description https://www.solidjs.com/docs/latest/api#createeffect
149
+ */
73
150
  export declare function createEffect<T>(fn: (v?: T) => T | undefined): void;
74
151
  export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
75
152
  name?: string;
76
153
  }): void;
154
+ /**
155
+ * Creates a readonly derived reactive memoized signal
156
+ * ```typescript
157
+ * export function createMemo<T>(
158
+ * fn: (v: T) => T,
159
+ * value?: T,
160
+ * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
161
+ * ): T;
162
+ * ```
163
+ * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
164
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
165
+ * @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
166
+ *
167
+ * @description https://www.solidjs.com/docs/latest/api#creatememo
168
+ */
77
169
  export declare function createMemo<T>(fn: (v?: T) => T, value?: undefined, options?: {
78
170
  equals?: false | ((prev: T, next: T) => boolean);
79
171
  name?: string;
@@ -86,56 +178,183 @@ export interface Resource<T> extends Accessor<T> {
86
178
  loading: boolean;
87
179
  error: any;
88
180
  }
89
- export declare type ResourceReturn<T> = [
90
- Resource<T>,
91
- {
92
- mutate: Setter<T>;
93
- refetch: () => void;
94
- }
95
- ];
96
- export declare function createResource<T, U = true>(fetcher: (k: U, getPrev: Accessor<T | undefined>) => T | Promise<T>, options?: {
97
- initialValue?: undefined;
98
- name?: string;
99
- }): ResourceReturn<T | undefined>;
100
- export declare function createResource<T, U = true>(fetcher: (k: U, getPrev: Accessor<T>) => T | Promise<T>, options: {
101
- initialValue: T;
102
- name?: string;
103
- }): ResourceReturn<T>;
104
- export declare function createResource<T, U>(source: U | false | null | (() => U | false | null), fetcher: (k: U, getPrev: Accessor<T | undefined>) => T | Promise<T>, options?: {
105
- initialValue?: undefined;
181
+ export declare type ResourceActions<T> = {
182
+ mutate: Setter<T>;
183
+ refetch: () => void;
184
+ };
185
+ export declare type ResourceReturn<T> = [Resource<T>, ResourceActions<T>];
186
+ export declare type ResourceSource<S> = S | false | null | (() => S | false | null);
187
+ export declare type ResourceFetcher<S, T> = (k: S, getPrev: Accessor<T>) => T | Promise<T>;
188
+ export declare type ResourceOptions<T> = T extends undefined ? {
189
+ initialValue?: T;
106
190
  name?: string;
107
- }): ResourceReturn<T | undefined>;
108
- export declare function createResource<T, U>(source: U | false | null | (() => U | false | null), fetcher: (k: U, getPrev: Accessor<T>) => T | Promise<T>, options: {
191
+ } : {
109
192
  initialValue: T;
110
193
  name?: string;
111
- }): ResourceReturn<T>;
194
+ };
195
+ /**
196
+ * Creates a resource that wraps a repeated promise in a reactive pattern:
197
+ * ```typescript
198
+ * const [resource, { mutate, refetch }] = crateResource(source, fetcher, options);
199
+ * ```
200
+ * @param source - reactive data function to toggle the request, optional
201
+ * @param fetcher - function that receives the source (or true) and an accessor for the last or initial value and returns a value or a Promise with the value:
202
+ * ```typescript
203
+ * const fetcher: ResourceFetcher<S, T, > = (
204
+ * sourceOutput: ReturnValue<typeof source>,
205
+ * getPrev: Accessor<T>
206
+ * ) => T | Promise<T>;
207
+ * ```
208
+ * @param options - an optional object with the initialValue and the name (for debugging purposes)
209
+ *
210
+ * @returns ```typescript
211
+ * [Resource<T>, { mutate: Setter<T>, refetch: () => void }]
212
+ * ```
213
+ *
214
+ * * Setting an `initialValue` in the options will mean that both the prev() accessor and the resource should never return undefined (if that is wanted, you need to extend the type with undefined)
215
+ * * `mutate` allows to manually overwrite the resource without calling the fetcher
216
+ * * `refetch` will re-run the fetcher without changing the source
217
+ *
218
+ * @description https://www.solidjs.com/docs/latest/api#createresource
219
+ */
220
+ export declare function createResource<T extends any, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
221
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
222
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
223
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
224
+ /**
225
+ * Creates a reactive computation that only runs and notifies the reactive context when the browser is idle
226
+ * ```typescript
227
+ * export function createDeferred<T>(
228
+ * fn: (v: T) => T,
229
+ * value?: T,
230
+ * options?: { timeoutMs?: number, name?: string, equals?: false | ((prev: T, next: T) => boolean) }
231
+ * ): () => T);
232
+ * ```
233
+ * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
234
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
235
+ * @param options allows to set the timeout in milliseconds, use a custom comparison function and set a name in dev mode for debugging purposes
236
+ *
237
+ * @description https://www.solidjs.com/docs/latest/api#createdeferred
238
+ */
112
239
  export declare function createDeferred<T>(source: Accessor<T>, options?: {
113
240
  equals?: false | ((prev: T, next: T) => boolean);
114
241
  name?: string;
115
242
  timeoutMs?: number;
116
243
  }): Accessor<T>;
244
+ /**
245
+ * Creates a conditional signal that only notifies subscribers when entering or exiting their key matching the value
246
+ * ```typescript
247
+ * export function createRenderEffect<T, U>(
248
+ * source: () => T
249
+ * fn: (a: U, b: T) => boolean,
250
+ * options?: { name?: string }
251
+ * ): (k: U) => boolean;
252
+ * ```
253
+ * @param source
254
+ * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
255
+ * @param options allows to set a name in dev mode for debugging purposes, optional
256
+ *
257
+ * ```typescript
258
+ * const isSelected = createSelector(selectedId);
259
+ * <For each={list()}>
260
+ * {(item) => <li classList={{ active: isSelected(item.id) }}>{item.name}</li>}
261
+ * </For>
262
+ * ```
263
+ *
264
+ * This makes the operation O(2) instead of O(n).
265
+ *
266
+ * @description https://www.solidjs.com/docs/latest/api#createrendereffect
267
+ */
117
268
  export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b: T) => boolean, options?: {
118
269
  name?: string;
119
270
  }): (key: U) => boolean;
271
+ /**
272
+ * Holds changes inside the block before the reactive context is updated
273
+ * @param fn wraps the reactive updates that should be batched
274
+ * @returns the return value from `fn`
275
+ *
276
+ * @description https://www.solidjs.com/docs/latest/api#batch
277
+ */
120
278
  export declare function batch<T>(fn: () => T): T;
279
+ /**
280
+ * Ignores tracking context inside its scope
281
+ * @param fn the scope that is out of the tracking context
282
+ * @returns the return value of `fn`
283
+ *
284
+ * @description https://www.solidjs.com/docs/latest/api#untrack
285
+ */
121
286
  export declare function untrack<T>(fn: Accessor<T>): T;
122
287
  export declare type ReturnTypes<T> = T extends (() => any)[] ? {
123
288
  [I in keyof T]: ReturnTypes<T[I]>;
124
289
  } : T extends () => any ? ReturnType<T> : never;
290
+ /**
291
+ * on - make dependencies of a computation explicit
292
+ * ```typescript
293
+ * export function on<T extends Array<() => any> | (() => any), U>(
294
+ * deps: T | T[],
295
+ * fn: (input: T, prevInput: T, prevValue?: U) => U,
296
+ * options?: { defer?: boolean } = {}
297
+ * ): (prevValue?: U) => U | undefined;
298
+ * ```
299
+ * @param deps list of reactive dependencies or a single reactive dependency
300
+ * @param fn computation on input; the current previous content(s) of input and the previous value are given as arguments and it returns a new value
301
+ * @param options optional, allows deferred computation until at the end of the next change
302
+ * ```typescript
303
+ * createEffect(on(a, (v) => console.log(v, b())));
304
+ *
305
+ * // is equivalent to:
306
+ * createEffect(() => {
307
+ * const v = a();
308
+ * untrack(() => console.log(v, b()));
309
+ * });
310
+ * ```
311
+ *
312
+ * @description https://www.solidjs.com/docs/latest/api#on
313
+ */
125
314
  export declare function on<T extends (() => any)[], U>(deps: [...T], fn: (input: ReturnTypes<T>, prevInput: ReturnTypes<T>, prevValue?: U) => U, options?: {
126
315
  defer?: boolean;
127
316
  }): (prevValue?: U) => U;
128
317
  export declare function on<T extends () => any, U>(deps: T, fn: (input: ReturnType<T>, prevInput: ReturnType<T>, prevValue?: U) => U, options?: {
129
318
  defer?: boolean;
130
319
  }): (prevValue?: U) => U;
320
+ /**
321
+ * onMount - run an effect only after initial render on mount
322
+ * @param fn an effect that should run only once on mount
323
+ *
324
+ * @description https://www.solidjs.com/docs/latest/api#onmount
325
+ */
131
326
  export declare function onMount(fn: () => void): void;
327
+ /**
328
+ * onCleanup - run an effect once before the reactive scope is disposed
329
+ * @param fn an effect that should run only once on cleanup
330
+ *
331
+ * @description https://www.solidjs.com/docs/latest/api#oncleanup
332
+ */
132
333
  export declare function onCleanup(fn: () => void): () => void;
334
+ /**
335
+ * onError - run an effect whenever an error is thrown within the context of the child scopes
336
+ * @param fn an error handler that receives the error
337
+ *
338
+ * * If the error is thrown again inside the error handler, it will trigger the next available parent handler
339
+ *
340
+ * @description https://www.solidjs.com/docs/latest/api#onerror
341
+ */
133
342
  export declare function onError(fn: (err: any) => void): void;
134
343
  export declare function getListener(): Computation<any> | null;
135
344
  export declare function getOwner(): Owner | null;
136
345
  export declare function runWithOwner(o: Owner, fn: () => any): any;
137
346
  export declare function enableScheduling(scheduler?: typeof requestCallback): void;
138
347
  export declare function startTransition(fn: () => void, cb?: () => void): void;
348
+ /**
349
+ * ```typescript
350
+ * export function useTransition(): [
351
+ * () => boolean,
352
+ * (fn: () => void, cb?: () => void) => void
353
+ * ];
354
+ * @returns a tuple; first value is an accessor if the transition is pending and a callback to start the transition
355
+ *
356
+ * @description https://www.solidjs.com/docs/latest/api#usetransition
357
+ */
139
358
  export declare function useTransition(): [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
140
359
  export declare function resumeEffects(e: Computation<any>[]): void;
141
360
  export declare function devComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
@@ -155,9 +374,40 @@ export interface Context<T> {
155
374
  }) => any;
156
375
  defaultValue: T;
157
376
  }
377
+ /**
378
+ * Creates a Context to handle a state scoped for the children of a component
379
+ * ```typescript
380
+ * interface Context<T> {
381
+ * id: symbol;
382
+ * Provider: (props: { value: T; children: any }) => any;
383
+ * defaultValue: T;
384
+ * }
385
+ * export function createContext<T>(defaultValue?: T): Context<T | undefined>;
386
+ * ```
387
+ * @param defaultValue optional default to inject into context
388
+ * @returns The context that contains the Provider Component and that can be used with `useContext`
389
+ *
390
+ * @description https://www.solidjs.com/docs/latest/api#createcontext
391
+ */
158
392
  export declare function createContext<T>(): Context<T | undefined>;
159
393
  export declare function createContext<T>(defaultValue: T): Context<T>;
394
+ /**
395
+ * use a context to receive a scoped state from a parent's Context.Provider
396
+ *
397
+ * @param context Context object made by `createContext`
398
+ * @returns the current or `defaultValue`, if present
399
+ *
400
+ * @description https://www.solidjs.com/docs/latest/api#usecontext
401
+ */
160
402
  export declare function useContext<T>(context: Context<T>): T;
403
+ /**
404
+ * Resolves child elements to help interact with children
405
+ *
406
+ * @param fn an accessor for the children
407
+ * @returns a accessor of the same children, but resolved
408
+ *
409
+ * @description https://www.solidjs.com/docs/latest/api#children
410
+ */
161
411
  export declare function children(fn: Accessor<JSX.Element>): Accessor<JSX.Element>;
162
412
  declare type SuspenseContextType = {
163
413
  increment?: () => void;
@@ -171,6 +421,5 @@ export declare function getSuspenseContext(): Context<SuspenseContextType> & {
171
421
  increment?(): void;
172
422
  decrement?(): void;
173
423
  };
174
- export declare function readSignal(this: Signal<any> | Memo<any>): any;
175
- export declare function writeSignal(node: Signal<any> | Memo<any>, value: any, isComp?: boolean): any;
424
+ export declare function writeSignal(node: Signal<any>, value: any): any;
176
425
  export {};
@@ -1,9 +1,25 @@
1
1
  import type { JSX } from "../jsx";
2
+ /**
3
+ * **[experimental]** controls the order in which suspended content is rendered
4
+ *
5
+ * @description https://www.solidjs.com/docs/latest/api#%3Csuspenselist%3E-(experimental)
6
+ */
2
7
  export declare function SuspenseList(props: {
3
8
  children: JSX.Element;
4
9
  revealOrder: "forwards" | "backwards" | "together";
5
10
  tail?: "collapsed" | "hidden";
6
11
  }): JSX.Element;
12
+ /**
13
+ * tracks all resources inside a component and renders a fallback until they are all resolved
14
+ * ```typescript
15
+ * const AsyncComponent = lazy(() => import('./component'));
16
+ *
17
+ * <Suspense fallback={<LoadingIndicator />}>
18
+ * <AsyncComponent />
19
+ * </Suspense>
20
+ * ```
21
+ * @description https://www.solidjs.com/docs/latest/api#%3Csuspense%3E
22
+ */
7
23
  export declare function Suspense(props: {
8
24
  fallback?: JSX.Element;
9
25
  children: JSX.Element;
@@ -12,10 +12,15 @@ export declare type Component<P = {}> = (props: PropsWithChildren<P>) => JSX.Ele
12
12
  */
13
13
  export declare type ComponentProps<T extends keyof JSX.IntrinsicElements | Component<any>> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : {};
14
14
  export declare function createComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
15
- export declare function mergeProps<T>(source: T): T;
16
- export declare function mergeProps<T, U>(source: T, source1: U): T & U;
17
- export declare function mergeProps<T, U, V>(source: T, source1: U, source2: V): T & U & V;
18
- export declare function mergeProps<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
15
+ declare type BoxedTupleTypes<T extends any[]> = {
16
+ [P in keyof T]: [T[P]];
17
+ }[Exclude<keyof T, keyof any[]>];
18
+ declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
19
+ declare type UnboxIntersection<T> = T extends {
20
+ 0: infer U;
21
+ } ? U : never;
22
+ declare type MergeProps<T extends any[]> = UnboxIntersection<UnionToIntersection<BoxedTupleTypes<T>>>;
23
+ export declare function mergeProps<T extends any[]>(...sources: T): MergeProps<T>;
19
24
  export declare function splitProps<T extends object, K1 extends keyof T>(props: T, ...keys: [K1[]]): [Pick<T, K1>, Omit<T, K1>];
20
25
  export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T>(props: T, ...keys: [K1[], K2[]]): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>];
21
26
  export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>];
@@ -34,3 +39,4 @@ export declare function lazy<T extends Component<any>>(fn: () => Promise<{
34
39
  preload: () => void;
35
40
  };
36
41
  export declare function createUniqueId(): string;
42
+ export {};
@@ -1,29 +1,97 @@
1
1
  import { Accessor } from "../reactive/signal";
2
2
  import type { JSX } from "../jsx";
3
+ /**
4
+ * creates a list elements from a list
5
+ *
6
+ * it receives a map function as its child that receives a list element and an accessor with the index and returns a JSX-Element; if the list is empty, an optional fallback is returned:
7
+ * ```typescript
8
+ * <For each={items} fallback={<div>No items</div>}>
9
+ * {(item, index) => <div data-index={index()}>{item}</div>}
10
+ * </For>
11
+ * ```
12
+ * If you have a list with fixed indices and changing values, consider using `<Index>` instead.
13
+ *
14
+ * @description https://www.solidjs.com/docs/latest/api#%3Cfor%3E
15
+ */
3
16
  export declare function For<T, U extends JSX.Element>(props: {
4
17
  each: readonly T[] | undefined | null | false;
5
18
  fallback?: JSX.Element;
6
19
  children: (item: T, index: Accessor<number>) => U;
7
20
  }): Accessor<U[]>;
21
+ /**
22
+ * Non-keyed iteration over a list creating elements from its items
23
+ *
24
+ * To be used if you have a list with fixed indices, but changing values.
25
+ * ```typescript
26
+ * <Index each={items} fallback={<div>No items</div>}>
27
+ * {(item, index) => <div data-index={index}>{item()}</div>}
28
+ * </Index>
29
+ * ```
30
+ * If you have a list with changing indices, better use `<For>`.
31
+ *
32
+ * @description https://www.solidjs.com/docs/latest/api#%3Cindex%3E
33
+ */
8
34
  export declare function Index<T, U extends JSX.Element>(props: {
9
35
  each: readonly T[] | undefined | null | false;
10
36
  fallback?: JSX.Element;
11
37
  children: (item: Accessor<T>, index: number) => U;
12
38
  }): Accessor<U[]>;
39
+ /**
40
+ * Conditionally render its children or an optional fallback component
41
+ * @description https://www.solidjs.com/docs/latest/api#%3Cshow%3E
42
+ */
13
43
  export declare function Show<T>(props: {
14
44
  when: T | undefined | null | false;
15
45
  fallback?: JSX.Element;
16
- children: JSX.Element | ((item: T) => JSX.Element);
46
+ children: JSX.Element | ((item: NonNullable<T>) => JSX.Element);
17
47
  }): () => JSX.Element;
48
+ /**
49
+ * switches between content based on mutually exclusive conditions
50
+ * ```typescript
51
+ * <Switch fallback={<FourOhFour />}>
52
+ * <Match when={state.route === 'home'}>
53
+ * <Home />
54
+ * </Match>
55
+ * <Match when={state.route === 'settings'}>
56
+ * <Settings />
57
+ * </Match>
58
+ * </Switch>
59
+ * ```
60
+ * @description https://www.solidjs.com/docs/latest/api#%3Cswitch%3E%2F%3Cmatch%3E
61
+ */
18
62
  export declare function Switch(props: {
19
63
  fallback?: JSX.Element;
20
64
  children: JSX.Element;
21
65
  }): Accessor<JSX.Element>;
22
66
  export declare type MatchProps<T> = {
23
67
  when: T | undefined | null | false;
24
- children: JSX.Element | ((item: T) => JSX.Element);
68
+ children: JSX.Element | ((item: NonNullable<T>) => JSX.Element);
25
69
  };
70
+ /**
71
+ * selects a content based on condition when inside a `<Switch>` control flow
72
+ * ```typescript
73
+ * <Match when={condition()}>
74
+ * <Content/>
75
+ * </Match>
76
+ * ```
77
+ * @description https://www.solidjs.com/docs/latest/api#%3Cswitch%3E%2F%3Cmatch%3E
78
+ */
26
79
  export declare function Match<T>(props: MatchProps<T>): JSX.Element;
80
+ /**
81
+ * catches uncaught errors inside components and renders a fallback content
82
+ *
83
+ * Also supports a callback form that passes the error and a reset function:
84
+ * ```typescript
85
+ * <ErrorBoundary fallback={
86
+ * (err, reset) => <div onClick={reset}>Error: {err.toString()}</div>
87
+ * }>
88
+ * <MyComp />
89
+ * </ErrorBoundary>
90
+ * ```
91
+ * Errors thrown from the fallback can be caught by a parent ErrorBoundary
92
+ *
93
+ * @description https://www.solidjs.com/docs/latest/api#%3Cerrorboundary%3E
94
+ */
27
95
  export declare function ErrorBoundary(props: {
28
96
  fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
29
97
  children: JSX.Element;
package/web/dist/dev.cjs CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var solidJs = require('solid-js');
6
6
 
7
- const booleans = ["allowfullscreen", "allowpaymentrequest", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "ismap", "itemscope", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected", "truespeed"];
8
- const Properties = new Set(["className", "indeterminate", "value", "readOnly", ...booleans]);
7
+ const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"];
8
+ const Properties = new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]);
9
9
  const ChildProperties = new Set(["innerHTML", "textContent", "innerText", "children"]);
10
10
  const Aliases = {
11
11
  className: "class",
@@ -13,6 +13,10 @@ const Aliases = {
13
13
  };
14
14
  const PropAliases = {
15
15
  class: "className",
16
+ formnovalidate: "formNoValidate",
17
+ ismap: "isMap",
18
+ nomodule: "noModule",
19
+ playsinline: "playsInline",
16
20
  readonly: "readOnly"
17
21
  };
18
22
  const DelegatedEvents = new Set(["beforeinput", "click", "dblclick", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]);
@@ -142,27 +146,27 @@ function addEventListener(node, name, handler, delegate) {
142
146
  } else node.addEventListener(name, handler);
143
147
  }
144
148
  function classList(node, value, prev = {}) {
145
- const classKeys = Object.keys(value),
149
+ const classKeys = Object.keys(value || {}),
146
150
  prevKeys = Object.keys(prev);
147
151
  let i, len;
148
152
  for (i = 0, len = prevKeys.length; i < len; i++) {
149
153
  const key = prevKeys[i];
150
- if (!key || key === "undefined" || key in value) continue;
154
+ if (!key || key === "undefined" || value[key]) continue;
151
155
  toggleClassKey(node, key, false);
152
156
  delete prev[key];
153
157
  }
154
158
  for (i = 0, len = classKeys.length; i < len; i++) {
155
159
  const key = classKeys[i],
156
160
  classValue = !!value[key];
157
- if (!key || key === "undefined" || prev[key] === classValue) continue;
158
- toggleClassKey(node, key, classValue);
161
+ if (!key || key === "undefined" || prev[key] === classValue || !classValue) continue;
162
+ toggleClassKey(node, key, true);
159
163
  prev[key] = classValue;
160
164
  }
161
165
  return prev;
162
166
  }
163
167
  function style(node, value, prev = {}) {
164
168
  const nodeStyle = node.style;
165
- if (typeof value === "string") return nodeStyle.cssText = value;
169
+ if (value == null || typeof value === "string") return nodeStyle.cssText = value;
166
170
  typeof prev === "string" && (prev = {});
167
171
  let v, s;
168
172
  for (s in prev) {