solid-js 1.2.5 → 1.3.0-beta.10

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.
@@ -1,16 +1,15 @@
1
1
  import { requestCallback } from "./scheduler";
2
2
  import type { JSX } from "../jsx";
3
- export declare type Accessor<T> = () => T;
4
- export declare type Setter<T> = undefined extends T ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(v: (U extends Function ? never : U) | ((prev: T) => U)) => U;
5
3
  export declare const equalFn: <T>(a: T, b: T) => boolean;
6
4
  export declare const $PROXY: unique symbol;
7
5
  export declare const NOTPENDING: {};
8
6
  export declare var Owner: Owner | null;
9
- export declare let Transition: Transition | null;
7
+ export declare let Transition: TransitionState | null;
8
+ declare let ExternalSourceFactory: ExternalSourceFactory | null;
10
9
  declare global {
11
10
  var _$afterUpdate: () => void;
12
11
  }
13
- interface Signal<T> {
12
+ export interface SignalState<T> {
14
13
  value?: T;
15
14
  observers: Computation<any>[] | null;
16
15
  observerSlots: number[] | null;
@@ -19,7 +18,7 @@ interface Signal<T> {
19
18
  comparator?: (prev: T, next: T) => boolean;
20
19
  name?: string;
21
20
  }
22
- interface Owner {
21
+ export interface Owner {
23
22
  owned: Computation<any>[] | null;
24
23
  cleanups: (() => void)[] | null;
25
24
  owner: Owner | null;
@@ -30,23 +29,20 @@ interface Owner {
30
29
  name?: string;
31
30
  componentName?: string;
32
31
  }
33
- interface Computation<T> extends Owner {
34
- fn: (v?: T) => T;
32
+ export interface Computation<Init, Next extends Init = Init> extends Owner {
33
+ fn: EffectFunction<Init, Next>;
35
34
  state: number;
36
35
  tState?: number;
37
- sources: Signal<T>[] | null;
36
+ sources: SignalState<Next>[] | null;
38
37
  sourceSlots: number[] | null;
39
- value?: T;
38
+ value?: Init;
40
39
  updatedAt: number | null;
41
40
  pure: boolean;
42
41
  user?: boolean;
43
42
  suspense?: SuspenseContextType;
44
43
  }
45
- interface Memo<T> extends Signal<T>, Computation<T> {
46
- tOwned?: Computation<any>[];
47
- }
48
- interface Transition {
49
- sources: Set<Signal<any>>;
44
+ export interface TransitionState {
45
+ sources: Set<SignalState<any>>;
50
46
  effects: Computation<any>[];
51
47
  promises: Set<Promise<any>>;
52
48
  disposed: Set<Computation<any>>;
@@ -55,6 +51,12 @@ interface Transition {
55
51
  running: boolean;
56
52
  cb: (() => void)[];
57
53
  }
54
+ declare type ExternalSourceFactory = <Prev, Next extends Prev = Prev>(fn: EffectFunction<Prev, Next>, trigger: () => void) => ExternalSource;
55
+ export interface ExternalSource {
56
+ track: EffectFunction<any, any>;
57
+ dispose: () => void;
58
+ }
59
+ export declare type RootFunction<T> = (dispose: () => void) => T;
58
60
  /**
59
61
  * Creates a new non-tracked reactive context that doesn't auto-dispose
60
62
  *
@@ -64,11 +66,13 @@ interface Transition {
64
66
  *
65
67
  * @description https://www.solidjs.com/docs/latest/api#createroot
66
68
  */
67
- export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: Owner): T;
68
- export declare type SignalOptions<T> = {
69
- name?: string;
70
- equals?: false | ((prev: T, next: T) => boolean);
71
- };
69
+ export declare function createRoot<T>(fn: RootFunction<T>, detachedOwner?: Owner): T;
70
+ export declare type Accessor<T> = () => T;
71
+ export declare type Setter<T> = undefined extends T ? <U extends T>(value?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(value: (U extends Function ? never : U) | ((prev: T) => U)) => U;
72
+ export declare type Signal<T> = [get: Accessor<T>, set: Setter<T>];
73
+ export interface SignalOptions<T> extends MemoOptions<T> {
74
+ internal?: boolean;
75
+ }
72
76
  /**
73
77
  * Creates a simple reactive state with a getter and setter
74
78
  * ```typescript
@@ -92,18 +96,21 @@ export declare type SignalOptions<T> = {
92
96
  *
93
97
  * @description https://www.solidjs.com/docs/latest/api#createsignal
94
98
  */
95
- export declare function createSignal<T>(): [get: Accessor<T | undefined>, set: Setter<T | undefined>];
96
- export declare function createSignal<T>(value: T, options?: {
97
- equals?: false | ((prev: T, next: T) => boolean);
99
+ export declare function createSignal<T>(): Signal<T | undefined>;
100
+ export declare function createSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
101
+ export interface BaseOptions {
98
102
  name?: string;
99
- internal?: boolean;
100
- }): [get: Accessor<T>, set: Setter<T>];
103
+ }
104
+ export declare type NoInfer<T extends any> = [T][T extends any ? 0 : never];
105
+ export interface EffectOptions extends BaseOptions {
106
+ }
107
+ export declare type EffectFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
101
108
  /**
102
109
  * Creates a reactive computation that runs immediately before render, mainly used to write to other reactive primitives
103
110
  * ```typescript
104
- * export function createComputed<T>(
105
- * fn: (v: T) => T,
106
- * value?: T,
111
+ * export function createComputed<Next, Init = Next>(
112
+ * fn: (v: Init | Next) => Next,
113
+ * value?: Init,
107
114
  * options?: { name?: string }
108
115
  * ): void;
109
116
  * ```
@@ -113,10 +120,8 @@ export declare function createSignal<T>(value: T, options?: {
113
120
  *
114
121
  * @description https://www.solidjs.com/docs/latest/api#createcomputed
115
122
  */
116
- export declare function createComputed<T>(fn: (v?: T) => T | undefined): void;
117
- export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
118
- name?: string;
119
- }): void;
123
+ export declare function createComputed<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
124
+ export declare function createComputed<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
120
125
  /**
121
126
  * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
122
127
  * ```typescript
@@ -132,10 +137,8 @@ export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
132
137
  *
133
138
  * @description https://www.solidjs.com/docs/latest/api#createrendereffect
134
139
  */
135
- export declare function createRenderEffect<T>(fn: (v?: T) => T | undefined): void;
136
- export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options?: {
137
- name?: string;
138
- }): void;
140
+ export declare function createRenderEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
141
+ export declare function createRenderEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
139
142
  /**
140
143
  * Creates a reactive computation that runs after the render phase
141
144
  * ```typescript
@@ -151,10 +154,14 @@ export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options
151
154
  *
152
155
  * @description https://www.solidjs.com/docs/latest/api#createeffect
153
156
  */
154
- export declare function createEffect<T>(fn: (v?: T) => T | undefined): void;
155
- export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
156
- name?: string;
157
- }): void;
157
+ export declare function createEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
158
+ export declare function createEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
159
+ interface Memo<Prev, Next = Prev> extends SignalState<Next>, Computation<Next> {
160
+ tOwned?: Computation<Prev | Next, Next>[];
161
+ }
162
+ export interface MemoOptions<T> extends EffectOptions {
163
+ equals?: false | ((prev: T, next: T) => boolean);
164
+ }
158
165
  /**
159
166
  * Creates a readonly derived reactive memoized signal
160
167
  * ```typescript
@@ -170,25 +177,23 @@ export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
170
177
  *
171
178
  * @description https://www.solidjs.com/docs/latest/api#creatememo
172
179
  */
173
- export declare function createMemo<T>(fn: (v?: T) => T, value?: undefined, options?: {
174
- equals?: false | ((prev: T, next: T) => boolean);
175
- name?: string;
176
- }): Accessor<T>;
177
- export declare function createMemo<T>(fn: (v: T) => T, value: T, options?: {
178
- equals?: false | ((prev: T, next: T) => boolean);
179
- name?: string;
180
- }): Accessor<T>;
180
+ export declare function createMemo<Next extends _Next, Init = Next, _Next = Next>(fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
181
+ export declare function createMemo<Next extends _Next, Init = undefined, _Next = Next>(..._: undefined extends Init ? [fn: EffectFunction<Init | _Next, Next>, value?: Init, options?: MemoOptions<Next>] : [fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>]): Accessor<Next>;
181
182
  export interface Resource<T> extends Accessor<T> {
182
183
  loading: boolean;
183
184
  error: any;
184
185
  }
185
186
  export declare type ResourceActions<T> = {
186
187
  mutate: Setter<T>;
187
- refetch: () => void;
188
+ refetch: (info?: unknown) => void;
188
189
  };
189
190
  export declare type ResourceReturn<T> = [Resource<T>, ResourceActions<T>];
190
191
  export declare type ResourceSource<S> = S | false | null | (() => S | false | null);
191
- export declare type ResourceFetcher<S, T> = (k: S, getPrev: Accessor<T>) => T | Promise<T>;
192
+ export declare type ResourceFetcher<S, T> = (k: S, info: ResourceFetcherInfo<T>) => T | Promise<T>;
193
+ export declare type ResourceFetcherInfo<T> = {
194
+ value: T | undefined;
195
+ refetching?: unknown;
196
+ };
192
197
  export declare type ResourceOptions<T> = T extends undefined ? {
193
198
  initialValue?: T;
194
199
  name?: string;
@@ -199,14 +204,14 @@ export declare type ResourceOptions<T> = T extends undefined ? {
199
204
  /**
200
205
  * Creates a resource that wraps a repeated promise in a reactive pattern:
201
206
  * ```typescript
202
- * const [resource, { mutate, refetch }] = crateResource(source, fetcher, options);
207
+ * const [resource, { mutate, refetch }] = createResource(source, fetcher, options);
203
208
  * ```
204
209
  * @param source - reactive data function to toggle the request, optional
205
210
  * @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:
206
211
  * ```typescript
207
212
  * const fetcher: ResourceFetcher<S, T, > = (
208
213
  * sourceOutput: ReturnValue<typeof source>,
209
- * getPrev: Accessor<T>
214
+ * info: ResourceFetcherInfo<T>
210
215
  * ) => T | Promise<T>;
211
216
  * ```
212
217
  * @param options - an optional object with the initialValue and the name (for debugging purposes)
@@ -221,30 +226,31 @@ export declare type ResourceOptions<T> = T extends undefined ? {
221
226
  *
222
227
  * @description https://www.solidjs.com/docs/latest/api#createresource
223
228
  */
224
- export declare function createResource<T extends any, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
225
- export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
226
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
227
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
229
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
230
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
231
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
232
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
233
+ export declare function refetchResources(info?: unknown): void;
234
+ export interface DeferredOptions<T> {
235
+ equals?: false | ((prev: T, next: T) => boolean);
236
+ name?: string;
237
+ timeoutMs?: number;
238
+ }
228
239
  /**
229
240
  * Creates a reactive computation that only runs and notifies the reactive context when the browser is idle
230
241
  * ```typescript
231
242
  * export function createDeferred<T>(
232
243
  * fn: (v: T) => T,
233
- * value?: T,
234
244
  * options?: { timeoutMs?: number, name?: string, equals?: false | ((prev: T, next: T) => boolean) }
235
245
  * ): () => T);
236
246
  * ```
237
247
  * @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
238
- * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
239
248
  * @param options allows to set the timeout in milliseconds, use a custom comparison function and set a name in dev mode for debugging purposes
240
249
  *
241
250
  * @description https://www.solidjs.com/docs/latest/api#createdeferred
242
251
  */
243
- export declare function createDeferred<T>(source: Accessor<T>, options?: {
244
- equals?: false | ((prev: T, next: T) => boolean);
245
- name?: string;
246
- timeoutMs?: number;
247
- }): Accessor<T>;
252
+ export declare function createDeferred<T>(source: Accessor<T>, options?: DeferredOptions<T>): Accessor<T>;
253
+ export declare type EqualityCheckerFunction<T, U> = (a: U, b: T) => boolean;
248
254
  /**
249
255
  * Creates a conditional signal that only notifies subscribers when entering or exiting their key matching the value
250
256
  * ```typescript
@@ -269,9 +275,7 @@ export declare function createDeferred<T>(source: Accessor<T>, options?: {
269
275
  *
270
276
  * @description https://www.solidjs.com/docs/latest/api#createselector
271
277
  */
272
- export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b: T) => boolean, options?: {
273
- name?: string;
274
- }): (key: U) => boolean;
278
+ export declare function createSelector<T, U>(source: Accessor<T>, fn?: EqualityCheckerFunction<T, U>, options?: BaseOptions): (key: U) => boolean;
275
279
  /**
276
280
  * Holds changes inside the block before the reactive context is updated
277
281
  * @param fn wraps the reactive updates that should be batched
@@ -279,7 +283,7 @@ export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b:
279
283
  *
280
284
  * @description https://www.solidjs.com/docs/latest/api#batch
281
285
  */
282
- export declare function batch<T>(fn: () => T): T;
286
+ export declare function batch<T>(fn: Accessor<T>): T;
283
287
  /**
284
288
  * Ignores tracking context inside its scope
285
289
  * @param fn the scope that is out of the tracking context
@@ -291,6 +295,10 @@ export declare function untrack<T>(fn: Accessor<T>): T;
291
295
  export declare type ReturnTypes<T> = T extends (() => any)[] ? {
292
296
  [I in keyof T]: ReturnTypes<T[I]>;
293
297
  } : T extends () => any ? ReturnType<T> : never;
298
+ export declare type OnEffectFunction<S, Prev, Next extends Prev = Prev> = (input: ReturnTypes<S>, prevInput: ReturnTypes<S>, v: Prev) => Next;
299
+ export interface OnOptions {
300
+ defer?: boolean;
301
+ }
294
302
  /**
295
303
  * on - make dependencies of a computation explicit
296
304
  * ```typescript
@@ -303,6 +311,8 @@ export declare type ReturnTypes<T> = T extends (() => any)[] ? {
303
311
  * @param deps list of reactive dependencies or a single reactive dependency
304
312
  * @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
305
313
  * @param options optional, allows deferred computation until at the end of the next change
314
+ * @returns an effect function that is passed into createEffect. For example:
315
+ *
306
316
  * ```typescript
307
317
  * createEffect(on(a, (v) => console.log(v, b())));
308
318
  *
@@ -315,12 +325,7 @@ export declare type ReturnTypes<T> = T extends (() => any)[] ? {
315
325
  *
316
326
  * @description https://www.solidjs.com/docs/latest/api#on
317
327
  */
318
- export declare function on<T extends (() => any)[], U>(deps: [...T], fn: (input: ReturnTypes<T>, prevInput: ReturnTypes<T>, prevValue?: U) => U, options?: {
319
- defer?: boolean;
320
- }): (prevValue?: U) => U;
321
- export declare function on<T extends () => any, U>(deps: T, fn: (input: ReturnType<T>, prevInput: ReturnType<T>, prevValue?: U) => U, options?: {
322
- defer?: boolean;
323
- }): (prevValue?: U) => U;
328
+ export declare function on<S extends Accessor<unknown> | Accessor<unknown>[] | [], Next, Init = unknown>(deps: S, fn: OnEffectFunction<S, Init | Next, Next>, options?: OnOptions): EffectFunction<NoInfer<Init> | NoInfer<Next>, NoInfer<Next>>;
324
329
  /**
325
330
  * onMount - run an effect only after initial render on mount
326
331
  * @param fn an effect that should run only once on mount
@@ -344,11 +349,18 @@ export declare function onCleanup(fn: () => void): () => void;
344
349
  * @description https://www.solidjs.com/docs/latest/api#onerror
345
350
  */
346
351
  export declare function onError(fn: (err: any) => void): void;
347
- export declare function getListener(): Computation<any> | null;
352
+ export declare function getListener(): Computation<any, any> | null;
348
353
  export declare function getOwner(): Owner | null;
349
354
  export declare function runWithOwner(o: Owner, fn: () => any): any;
350
355
  export declare function enableScheduling(scheduler?: typeof requestCallback): void;
356
+ /**
357
+ * ```typescript
358
+ * export function startTransition(fn: () => void, cb?: () => void) => void
359
+ *
360
+ * @description https://www.solidjs.com/docs/latest/api#usetransition
361
+ */
351
362
  export declare function startTransition(fn: () => void, cb?: () => void): void;
363
+ export declare type Transition = [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
352
364
  /**
353
365
  * ```typescript
354
366
  * export function useTransition(): [
@@ -359,7 +371,7 @@ export declare function startTransition(fn: () => void, cb?: () => void): void;
359
371
  *
360
372
  * @description https://www.solidjs.com/docs/latest/api#usetransition
361
373
  */
362
- export declare function useTransition(): [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
374
+ export declare function useTransition(): Transition;
363
375
  export declare function resumeEffects(e: Computation<any>[]): void;
364
376
  export declare function devComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
365
377
  export declare function hashValue(v: any): string;
@@ -370,12 +382,13 @@ interface GraphRecord {
370
382
  [k: string]: GraphRecord | unknown;
371
383
  }
372
384
  export declare function serializeGraph(owner?: Owner | null): GraphRecord;
385
+ export declare type ContextProviderComponent<T> = (props: {
386
+ value: T;
387
+ children: any;
388
+ }) => any;
373
389
  export interface Context<T> {
374
390
  id: symbol;
375
- Provider: (props: {
376
- value: T;
377
- children: any;
378
- }) => any;
391
+ Provider: ContextProviderComponent<T>;
379
392
  defaultValue: T;
380
393
  }
381
394
  /**
@@ -413,18 +426,21 @@ export declare function useContext<T>(context: Context<T>): T;
413
426
  * @description https://www.solidjs.com/docs/latest/api#children
414
427
  */
415
428
  export declare function children(fn: Accessor<JSX.Element>): Accessor<JSX.Element>;
416
- declare type SuspenseContextType = {
429
+ export declare type SuspenseContextType = {
417
430
  increment?: () => void;
418
431
  decrement?: () => void;
419
432
  inFallback?: () => boolean;
420
433
  effects?: Computation<any>[];
421
434
  resolved?: boolean;
422
435
  };
423
- export declare function getSuspenseContext(): Context<SuspenseContextType> & {
436
+ declare type SuspenseContext = Context<SuspenseContextType> & {
424
437
  active?(): boolean;
425
438
  increment?(): void;
426
439
  decrement?(): void;
427
440
  };
428
- export declare function readSignal(this: Signal<any> | Memo<any>): any;
429
- export declare function writeSignal(node: Signal<any> | Memo<any>, value: any, isComp?: boolean): any;
441
+ declare let SuspenseContext: SuspenseContext;
442
+ export declare function getSuspenseContext(): SuspenseContext;
443
+ export declare function enableExternalSource(factory: ExternalSourceFactory): void;
444
+ export declare function readSignal(this: SignalState<any> | Memo<any>): any;
445
+ export declare function writeSignal(node: SignalState<any> | Memo<any>, value: any, isComp?: boolean): any;
430
446
  export {};
@@ -1,4 +1,5 @@
1
1
  import type { JSX } from "../jsx";
2
+ export declare function enableHydration(): void;
2
3
  export declare type PropsWithChildren<P = {}> = P & {
3
4
  children?: JSX.Element;
4
5
  };
@@ -36,7 +37,9 @@ export declare function splitProps<T extends object, K1 extends keyof T, K2 exte
36
37
  export declare function lazy<T extends Component<any>>(fn: () => Promise<{
37
38
  default: T;
38
39
  }>): T & {
39
- preload: () => void;
40
+ preload: () => Promise<{
41
+ default: T;
42
+ }>;
40
43
  };
41
44
  export declare function createUniqueId(): string;
42
45
  export {};
@@ -1,13 +1,14 @@
1
- declare type HydrationContext = {
1
+ export declare type HydrationContext = {
2
2
  id: string;
3
3
  count: number;
4
- loadResource?: (id: string) => Promise<any>;
5
4
  };
6
5
  declare type SharedConfig = {
7
6
  context?: HydrationContext;
8
7
  resources?: {
9
8
  [key: string]: any;
10
9
  };
10
+ load?: (id: string) => Promise<any> | undefined;
11
+ gather?: (key: string) => void;
11
12
  registry?: Map<string, Element>;
12
13
  };
13
14
  export declare const sharedConfig: SharedConfig;
@@ -1,3 +1,3 @@
1
- export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, DEV } from "./reactive";
2
- export { awaitSuspense, mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
1
+ export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, DEV, enableExternalSource } from "./reactive";
2
+ export { mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
3
3
  export type { Component, Resource } from "./rendering";
@@ -1,9 +1,8 @@
1
+ import type { Accessor, Setter } from "../reactive/signal";
1
2
  export declare const equalFn: <T>(a: T, b: T) => boolean;
2
3
  export declare const $PROXY: unique symbol;
3
4
  export declare const DEV: {};
4
5
  export declare let Owner: Owner | null;
5
- export declare type Accessor<T> = () => T;
6
- export declare type Setter<T> = undefined extends T ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: U) => U)) => U : <U extends T>(v: (U extends Function ? never : U) | ((prev: U) => U)) => U;
7
6
  interface Owner {
8
7
  owner: Owner | null;
9
8
  context: any | null;
@@ -71,4 +70,5 @@ export declare function from<T>(producer: ((setter: Setter<T>) => () => void) |
71
70
  unsubscribe: () => void;
72
71
  };
73
72
  }): Accessor<T>;
73
+ export declare function enableExternalSource(factory: any): void;
74
74
  export {};
@@ -56,9 +56,9 @@ declare type MatchProps<T> = {
56
56
  };
57
57
  export declare function Match<T>(props: MatchProps<T>): MatchProps<T>;
58
58
  export declare function ErrorBoundary(props: {
59
- fallback: string | ((err: any) => string);
59
+ fallback: string | ((err: any, reset: () => void) => string);
60
60
  children: string;
61
- }): string;
61
+ }): any;
62
62
  export interface Resource<T> {
63
63
  (): T | undefined;
64
64
  loading: boolean;
@@ -82,6 +82,7 @@ export declare function createResource<T, U = true>(fetcher: (k: U, getPrev: ()
82
82
  export declare function createResource<T, U>(fn: U | false | (() => U | false), fetcher: (k: U, getPrev: () => T | undefined) => T | Promise<T>, options?: {
83
83
  initialValue?: T;
84
84
  }): ResourceReturn<T>;
85
+ export declare function refetchResources(info?: unknown): void;
85
86
  export declare function lazy(fn: () => Promise<{
86
87
  default: any;
87
88
  }>): (props: any) => string;
@@ -91,11 +92,13 @@ export declare function useTransition(): [() => boolean, (fn: () => any) => void
91
92
  declare type HydrationContext = {
92
93
  id: string;
93
94
  count: number;
94
- writeResource?: (id: string, v: Promise<any>) => void;
95
+ writeResource?: (id: string, v: Promise<any> | any, error?: boolean) => void;
95
96
  resources: Record<string, any>;
96
97
  suspense: Record<string, SuspenseContextType>;
98
+ registerFragment: (v: string) => (v?: string, err?: any) => boolean;
97
99
  async?: boolean;
98
100
  streaming?: boolean;
101
+ noHydrate: boolean;
99
102
  };
100
103
  export declare function SuspenseList(props: {
101
104
  children: string;
@@ -103,8 +106,7 @@ export declare function SuspenseList(props: {
103
106
  tail?: "collapsed" | "hidden";
104
107
  }): string;
105
108
  export declare function Suspense(props: {
106
- fallback: string;
109
+ fallback?: string;
107
110
  children: string;
108
111
  }): any;
109
- export declare function awaitSuspense(fn: () => any): Promise<unknown>;
110
112
  export {};
package/web/dist/dev.cjs CHANGED
@@ -98,7 +98,7 @@ function render(code, element, init) {
98
98
  let disposer;
99
99
  solidJs.createRoot(dispose => {
100
100
  disposer = dispose;
101
- insert(element, code(), element.firstChild ? null : undefined, init);
101
+ element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init);
102
102
  });
103
103
  return () => {
104
104
  disposer();
@@ -218,28 +218,21 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
218
218
  prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
219
219
  }
220
220
  }
221
- function hydrate(code, element) {
222
- solidJs.sharedConfig.resources = globalThis._$HYDRATION.resources;
223
- solidJs.sharedConfig.completed = globalThis._$HYDRATION.completed;
224
- solidJs.sharedConfig.events = globalThis._$HYDRATION.events;
221
+ function hydrate$1(code, element, options = {}) {
222
+ solidJs.sharedConfig.completed = globalThis._$HY.completed;
223
+ solidJs.sharedConfig.events = globalThis._$HY.events;
224
+ solidJs.sharedConfig.load = globalThis._$HY.load;
225
+ solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
226
+ solidJs.sharedConfig.registry = new Map();
225
227
  solidJs.sharedConfig.context = {
226
- id: "",
227
- count: 0,
228
- loadResource: globalThis._$HYDRATION.loadResource
228
+ id: options.renderId || "",
229
+ count: 0
229
230
  };
230
- solidJs.sharedConfig.registry = new Map();
231
- gatherHydratable(element);
231
+ gatherHydratable(element, options.renderId);
232
232
  const dispose = render(code, element, [...element.childNodes]);
233
233
  solidJs.sharedConfig.context = null;
234
234
  return dispose;
235
235
  }
236
- function gatherHydratable(element) {
237
- const templates = element.querySelectorAll(`*[data-hk]`);
238
- for (let i = 0; i < templates.length; i++) {
239
- const node = templates[i];
240
- solidJs.sharedConfig.registry.set(node.getAttribute("data-hk"), node);
241
- }
242
- }
243
236
  function getNextElement(template) {
244
237
  let node, key;
245
238
  if (!solidJs.sharedConfig.context || !(node = solidJs.sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -333,7 +326,7 @@ function eventHandler(e) {
333
326
  Object.defineProperty(e, "currentTarget", {
334
327
  configurable: true,
335
328
  get() {
336
- return node;
329
+ return node || document;
337
330
  }
338
331
  });
339
332
  while (node !== null) {
@@ -388,7 +381,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
388
381
  solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
389
382
  return () => current;
390
383
  }
391
- if (solidJs.sharedConfig.context && current && current.length) return current;
384
+ if (solidJs.sharedConfig.context && current && current.length) {
385
+ for (let i = 0; i < array.length; i++) {
386
+ if (array[i].parentNode) return current = array;
387
+ }
388
+ return current;
389
+ }
392
390
  if (array.length === 0) {
393
391
  current = cleanChildren(parent, current, marker);
394
392
  if (multi) return current;
@@ -405,6 +403,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
405
403
  }
406
404
  current = array;
407
405
  } else if (value instanceof Node) {
406
+ if (solidJs.sharedConfig.context) return current = value.parentNode ? value : current;
408
407
  if (Array.isArray(current)) {
409
408
  if (multi) return current = cleanChildren(parent, current, marker, value);
410
409
  cleanChildren(parent, current, null, value);
@@ -456,6 +455,14 @@ function cleanChildren(parent, current, marker, replacement) {
456
455
  } else parent.insertBefore(node, marker);
457
456
  return [node];
458
457
  }
458
+ function gatherHydratable(element, root) {
459
+ const templates = element.querySelectorAll(`*[data-hk]`);
460
+ for (let i = 0; i < templates.length; i++) {
461
+ const node = templates[i];
462
+ const key = node.getAttribute("data-hk");
463
+ if (!root || key.startsWith(root)) solidJs.sharedConfig.registry.set(key, node);
464
+ }
465
+ }
459
466
  function getHydrationKey() {
460
467
  const hydrate = solidJs.sharedConfig.context;
461
468
  return `${hydrate.id}${hydrate.count++}`;
@@ -469,8 +476,7 @@ function NoHydration(props) {
469
476
 
470
477
  function renderToString(fn, options) {}
471
478
  function renderToStringAsync(fn, options) {}
472
- function pipeToNodeWritable(fn, writable, options) {}
473
- function pipeToWritable(fn, writable, options) {}
479
+ function renderToStream(fn, options) {}
474
480
  function ssr(template, ...nodes) {}
475
481
  function resolveSSRNode(node) {}
476
482
  function ssrClassList(value) {}
@@ -486,6 +492,10 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
486
492
  function createElement(tagName, isSVG = false) {
487
493
  return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName);
488
494
  }
495
+ const hydrate = (...args) => {
496
+ solidJs.enableHydration();
497
+ return hydrate$1(...args);
498
+ };
489
499
  function Portal(props) {
490
500
  const {
491
501
  useShadow
@@ -630,7 +640,6 @@ exports.clearDelegatedEvents = clearDelegatedEvents;
630
640
  exports.delegateEvents = delegateEvents;
631
641
  exports.dynamicProperty = dynamicProperty;
632
642
  exports.escape = escape;
633
- exports.gatherHydratable = gatherHydratable;
634
643
  exports.generateHydrationScript = generateHydrationScript;
635
644
  exports.getHydrationKey = getHydrationKey;
636
645
  exports.getNextElement = getNextElement;
@@ -640,9 +649,8 @@ exports.hydrate = hydrate;
640
649
  exports.insert = insert;
641
650
  exports.isServer = isServer;
642
651
  exports.memo = memo;
643
- exports.pipeToNodeWritable = pipeToNodeWritable;
644
- exports.pipeToWritable = pipeToWritable;
645
652
  exports.render = render;
653
+ exports.renderToStream = renderToStream;
646
654
  exports.renderToString = renderToString;
647
655
  exports.renderToStringAsync = renderToStringAsync;
648
656
  exports.resolveSSRNode = resolveSSRNode;