solid-js 1.9.11 → 2.0.0-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.
Files changed (82) hide show
  1. package/dist/dev.cjs +733 -1678
  2. package/dist/dev.js +598 -1643
  3. package/dist/server.cjs +769 -703
  4. package/dist/server.js +682 -670
  5. package/dist/solid.cjs +699 -1618
  6. package/dist/solid.js +563 -1582
  7. package/package.json +7 -151
  8. package/types/{render → client}/component.d.ts +1 -38
  9. package/types/client/core.d.ts +65 -0
  10. package/types/client/flow.d.ts +100 -0
  11. package/types/client/hydration.d.ts +76 -0
  12. package/types/index.d.ts +11 -14
  13. package/types/jsx.d.ts +1508 -1633
  14. package/types/server/component.d.ts +66 -0
  15. package/types/server/core.d.ts +44 -0
  16. package/types/server/flow.d.ts +60 -0
  17. package/types/server/hydration.d.ts +21 -0
  18. package/types/server/index.d.ts +12 -3
  19. package/types/server/shared.d.ts +45 -0
  20. package/types/server/signals.d.ts +60 -0
  21. package/h/dist/h.cjs +0 -115
  22. package/h/dist/h.js +0 -113
  23. package/h/jsx-dev-runtime/package.json +0 -8
  24. package/h/jsx-runtime/dist/jsx.cjs +0 -15
  25. package/h/jsx-runtime/dist/jsx.js +0 -10
  26. package/h/jsx-runtime/package.json +0 -8
  27. package/h/jsx-runtime/types/index.d.ts +0 -11
  28. package/h/jsx-runtime/types/jsx.d.ts +0 -4242
  29. package/h/package.json +0 -8
  30. package/h/types/hyperscript.d.ts +0 -20
  31. package/h/types/index.d.ts +0 -3
  32. package/html/dist/html.cjs +0 -583
  33. package/html/dist/html.js +0 -581
  34. package/html/package.json +0 -8
  35. package/html/types/index.d.ts +0 -3
  36. package/html/types/lit.d.ts +0 -41
  37. package/store/dist/dev.cjs +0 -458
  38. package/store/dist/dev.js +0 -449
  39. package/store/dist/server.cjs +0 -126
  40. package/store/dist/server.js +0 -114
  41. package/store/dist/store.cjs +0 -438
  42. package/store/dist/store.js +0 -429
  43. package/store/package.json +0 -46
  44. package/store/types/index.d.ts +0 -12
  45. package/store/types/modifiers.d.ts +0 -6
  46. package/store/types/mutable.d.ts +0 -5
  47. package/store/types/server.d.ts +0 -17
  48. package/store/types/store.d.ts +0 -107
  49. package/types/reactive/array.d.ts +0 -44
  50. package/types/reactive/observable.d.ts +0 -36
  51. package/types/reactive/scheduler.d.ts +0 -10
  52. package/types/reactive/signal.d.ts +0 -577
  53. package/types/render/Suspense.d.ts +0 -26
  54. package/types/render/flow.d.ts +0 -118
  55. package/types/render/hydration.d.ts +0 -24
  56. package/types/render/index.d.ts +0 -4
  57. package/types/server/reactive.d.ts +0 -98
  58. package/types/server/rendering.d.ts +0 -159
  59. package/universal/dist/dev.cjs +0 -245
  60. package/universal/dist/dev.js +0 -243
  61. package/universal/dist/universal.cjs +0 -245
  62. package/universal/dist/universal.js +0 -243
  63. package/universal/package.json +0 -20
  64. package/universal/types/index.d.ts +0 -3
  65. package/universal/types/universal.d.ts +0 -30
  66. package/web/dist/dev.cjs +0 -894
  67. package/web/dist/dev.js +0 -782
  68. package/web/dist/server.cjs +0 -892
  69. package/web/dist/server.js +0 -782
  70. package/web/dist/web.cjs +0 -883
  71. package/web/dist/web.js +0 -771
  72. package/web/package.json +0 -46
  73. package/web/storage/dist/storage.cjs +0 -12
  74. package/web/storage/dist/storage.js +0 -10
  75. package/web/storage/package.json +0 -15
  76. package/web/storage/types/index.d.ts +0 -2
  77. package/web/types/client.d.ts +0 -79
  78. package/web/types/core.d.ts +0 -2
  79. package/web/types/index.d.ts +0 -50
  80. package/web/types/jsx.d.ts +0 -1
  81. package/web/types/server-mock.d.ts +0 -65
  82. package/web/types/server.d.ts +0 -177
@@ -1,118 +0,0 @@
1
- import { Accessor } from "../reactive/signal.js";
2
- import type { JSX } from "../jsx.js";
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://docs.solidjs.com/reference/components/for
15
- */
16
- export declare function For<T extends readonly any[], U extends JSX.Element>(props: {
17
- each: T | undefined | null | false;
18
- fallback?: JSX.Element;
19
- children: (item: T[number], index: Accessor<number>) => U;
20
- }): JSX.Element;
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://docs.solidjs.com/reference/components/index-component
33
- */
34
- export declare function Index<T extends readonly any[], U extends JSX.Element>(props: {
35
- each: T | undefined | null | false;
36
- fallback?: JSX.Element;
37
- children: (item: Accessor<T[number]>, index: number) => U;
38
- }): JSX.Element;
39
- type RequiredParameter<T> = T extends () => unknown ? never : T;
40
- /**
41
- * Conditionally render its children or an optional fallback component
42
- * @description https://docs.solidjs.com/reference/components/show
43
- */
44
- export declare function Show<T, TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element>(props: {
45
- when: T | undefined | null | false;
46
- keyed?: false;
47
- fallback?: JSX.Element;
48
- children: JSX.Element | RequiredParameter<TRenderFunction>;
49
- }): JSX.Element;
50
- export declare function Show<T, TRenderFunction extends (item: NonNullable<T>) => JSX.Element>(props: {
51
- when: T | undefined | null | false;
52
- keyed: true;
53
- fallback?: JSX.Element;
54
- children: JSX.Element | RequiredParameter<TRenderFunction>;
55
- }): JSX.Element;
56
- /**
57
- * Switches between content based on mutually exclusive conditions
58
- * ```typescript
59
- * <Switch fallback={<FourOhFour />}>
60
- * <Match when={state.route === 'home'}>
61
- * <Home />
62
- * </Match>
63
- * <Match when={state.route === 'settings'}>
64
- * <Settings />
65
- * </Match>
66
- * </Switch>
67
- * ```
68
- * @description https://docs.solidjs.com/reference/components/switch-and-match
69
- */
70
- export declare function Switch(props: {
71
- fallback?: JSX.Element;
72
- children: JSX.Element;
73
- }): JSX.Element;
74
- export type MatchProps<T> = {
75
- when: T | undefined | null | false;
76
- keyed?: boolean;
77
- children: JSX.Element | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => JSX.Element);
78
- };
79
- /**
80
- * Selects a content based on condition when inside a `<Switch>` control flow
81
- * ```typescript
82
- * <Match when={condition()}>
83
- * <Content/>
84
- * </Match>
85
- * ```
86
- * @description https://docs.solidjs.com/reference/components/switch-and-match
87
- */
88
- export declare function Match<T, TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element>(props: {
89
- when: T | undefined | null | false;
90
- keyed?: false;
91
- children: JSX.Element | RequiredParameter<TRenderFunction>;
92
- }): JSX.Element;
93
- export declare function Match<T, TRenderFunction extends (item: NonNullable<T>) => JSX.Element>(props: {
94
- when: T | undefined | null | false;
95
- keyed: true;
96
- children: JSX.Element | RequiredParameter<TRenderFunction>;
97
- }): JSX.Element;
98
- export declare function resetErrorBoundaries(): void;
99
- /**
100
- * Catches uncaught errors inside components and renders a fallback content
101
- *
102
- * Also supports a callback form that passes the error and a reset function:
103
- * ```typescript
104
- * <ErrorBoundary fallback={
105
- * (err, reset) => <div onClick={reset}>Error: {err.toString()}</div>
106
- * }>
107
- * <MyComp />
108
- * </ErrorBoundary>
109
- * ```
110
- * Errors thrown from the fallback can be caught by a parent ErrorBoundary
111
- *
112
- * @description https://docs.solidjs.com/reference/components/error-boundary
113
- */
114
- export declare function ErrorBoundary(props: {
115
- fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
116
- children: JSX.Element;
117
- }): JSX.Element;
118
- export {};
@@ -1,24 +0,0 @@
1
- import { Computation } from "../reactive/signal.js";
2
- export type HydrationContext = {
3
- id: string;
4
- count: number;
5
- };
6
- type SharedConfig = {
7
- context?: HydrationContext;
8
- resources?: {
9
- [key: string]: any;
10
- };
11
- load?: (id: string) => Promise<any> | any;
12
- has?: (id: string) => boolean;
13
- gather?: (key: string) => void;
14
- registry?: Map<string, Element>;
15
- done?: boolean;
16
- count?: number;
17
- effects?: Computation<any, any>[];
18
- getContextId(): string;
19
- getNextContextId(): string;
20
- };
21
- export declare const sharedConfig: SharedConfig;
22
- export declare function setHydrateContext(context?: HydrationContext): void;
23
- export declare function nextHydrateContext(): HydrationContext | undefined;
24
- export {};
@@ -1,4 +0,0 @@
1
- export * from "./component.js";
2
- export * from "./flow.js";
3
- export * from "./Suspense.js";
4
- export { sharedConfig } from "./hydration.js";
@@ -1,98 +0,0 @@
1
- export declare const equalFn: <T>(a: T, b: T) => boolean;
2
- export declare const $PROXY: unique symbol;
3
- export declare const $TRACK: unique symbol;
4
- export declare const $DEVCOMP: unique symbol;
5
- export declare const DEV: undefined;
6
- export type Accessor<T> = () => T;
7
- export 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;
8
- export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
9
- export declare function castError(err: unknown): Error;
10
- export declare let Owner: Owner | null;
11
- interface Owner {
12
- owner: Owner | null;
13
- context: any | null;
14
- owned: Owner[] | null;
15
- cleanups: (() => void)[] | null;
16
- }
17
- export declare function createOwner(): Owner;
18
- export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: typeof Owner): T;
19
- export declare function createSignal<T>(value: T, options?: {
20
- equals?: false | ((prev: T, next: T) => boolean);
21
- name?: string;
22
- }): [get: () => T, set: (v: (T extends Function ? never : T) | ((prev: T) => T)) => T];
23
- export declare function createComputed<T>(fn: (v?: T) => T, value?: T): void;
24
- export declare const createRenderEffect: typeof createComputed;
25
- export declare function createEffect<T>(fn: (v?: T) => T, value?: T): void;
26
- export declare function createReaction(fn: () => void): (fn: () => void) => void;
27
- export declare function createMemo<T>(fn: (v?: T) => T, value?: T): () => T;
28
- export declare function createDeferred<T>(source: () => T): () => T;
29
- export declare function createSelector<T>(source: () => T, fn?: (k: T, value: T) => boolean): (k: T) => boolean;
30
- export declare function batch<T>(fn: () => T): T;
31
- export declare const untrack: typeof batch;
32
- export declare function on<T, U>(deps: Array<() => T> | (() => T), fn: (value: Array<T> | T, prev?: Array<T> | T, prevResults?: U) => U, options?: {
33
- defer?: boolean;
34
- }): (prev?: U) => U | undefined;
35
- export declare function onMount(fn: () => void): void;
36
- export declare function onCleanup(fn: () => void): () => void;
37
- export declare function cleanNode(node: Owner): void;
38
- export declare function catchError<T>(fn: () => T, handler: (err: Error) => void): T | undefined;
39
- export declare function getListener(): null;
40
- export interface Context<T> {
41
- id: symbol;
42
- Provider: (props: {
43
- value: T;
44
- children: any;
45
- }) => any;
46
- defaultValue?: T;
47
- }
48
- export declare function createContext<T>(defaultValue?: T): Context<T>;
49
- export declare function useContext<T>(context: Context<T>): T;
50
- export declare function getOwner(): Owner | null;
51
- type ChildrenReturn = Accessor<any> & {
52
- toArray: () => any[];
53
- };
54
- export declare function children(fn: () => any): ChildrenReturn;
55
- export declare function runWithOwner<T>(o: typeof Owner, fn: () => T): T | undefined;
56
- export interface Task {
57
- id: number;
58
- fn: ((didTimeout: boolean) => void) | null;
59
- startTime: number;
60
- expirationTime: number;
61
- }
62
- export declare function requestCallback(fn: () => void, options?: {
63
- timeout: number;
64
- }): Task;
65
- export declare function cancelCallback(task: Task): void;
66
- export declare function mapArray<T, U>(list: Accessor<readonly T[] | undefined | null | false>, mapFn: (v: T, i: Accessor<number>) => U, options?: {
67
- fallback?: Accessor<any>;
68
- }): () => U[];
69
- export declare function indexArray<T, U>(list: Accessor<readonly T[] | undefined | null | false>, mapFn: (v: Accessor<T>, i: number) => U, options?: {
70
- fallback?: Accessor<any>;
71
- }): () => U[];
72
- export type ObservableObserver<T> = ((v: T) => void) | {
73
- next: (v: T) => void;
74
- error?: (v: any) => void;
75
- complete?: (v: boolean) => void;
76
- };
77
- export declare function observable<T>(input: Accessor<T>): {
78
- subscribe(observer: ObservableObserver<T>): {
79
- unsubscribe(): void;
80
- };
81
- [Symbol.observable](): {
82
- subscribe(observer: ObservableObserver<T>): {
83
- unsubscribe(): void;
84
- };
85
- [Symbol.observable](): /*elided*/ any;
86
- };
87
- };
88
- export declare function from<T>(producer: ((setter: Setter<T>) => () => void) | {
89
- subscribe: (fn: (v: T) => void) => (() => void) | {
90
- unsubscribe: () => void;
91
- };
92
- }): Accessor<T>;
93
- export declare function enableExternalSource(factory: any): void;
94
- /**
95
- * @deprecated since version 1.7.0 and will be removed in next major - use catchError instead
96
- */
97
- export declare function onError(fn: (err: Error) => void): void;
98
- export {};
@@ -1,159 +0,0 @@
1
- import { Accessor, Setter, Signal } from "./reactive.js";
2
- import type { JSX } from "../jsx.js";
3
- export type Component<P = {}> = (props: P) => JSX.Element;
4
- export type VoidProps<P = {}> = P & {
5
- children?: never;
6
- };
7
- export type VoidComponent<P = {}> = Component<VoidProps<P>>;
8
- export type ParentProps<P = {}> = P & {
9
- children?: JSX.Element;
10
- };
11
- export type ParentComponent<P = {}> = Component<ParentProps<P>>;
12
- export type FlowProps<P = {}, C = JSX.Element> = P & {
13
- children: C;
14
- };
15
- export type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>;
16
- export type Ref<T> = T | ((val: T) => void);
17
- export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {});
18
- export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>;
19
- type SharedConfig = {
20
- context?: HydrationContext;
21
- getContextId(): string;
22
- getNextContextId(): string;
23
- };
24
- export declare const sharedConfig: SharedConfig;
25
- export declare function createUniqueId(): string;
26
- export declare function createComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
27
- export declare function mergeProps<T, U>(source: T, source1: U): T & U;
28
- export declare function mergeProps<T, U, V>(source: T, source1: U, source2: V): T & U & V;
29
- export declare function mergeProps<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
30
- export declare function splitProps<T extends object, K1 extends keyof T>(props: T, ...keys: [K1[]]): [Pick<T, K1>, Omit<T, K1>];
31
- 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>];
32
- 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>];
33
- export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>];
34
- export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T, K5 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[], K5[]]): [
35
- Pick<T, K1>,
36
- Pick<T, K2>,
37
- Pick<T, K3>,
38
- Pick<T, K4>,
39
- Pick<T, K5>,
40
- Omit<T, K1 | K2 | K3 | K4 | K5>
41
- ];
42
- export declare function For<T>(props: {
43
- each: T[];
44
- fallback?: string;
45
- children: (item: T, index: () => number) => string;
46
- }): string | any[] | undefined;
47
- export declare function Index<T>(props: {
48
- each: T[];
49
- fallback?: string;
50
- children: (item: () => T, index: number) => string;
51
- }): string | any[] | undefined;
52
- /**
53
- * Conditionally render its children or an optional fallback component
54
- * @description https://docs.solidjs.com/reference/components/show
55
- */
56
- export declare function Show<T>(props: {
57
- when: T | undefined | null | false;
58
- keyed?: boolean;
59
- fallback?: string;
60
- children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string);
61
- }): string;
62
- export declare function Switch(props: {
63
- fallback?: string;
64
- children: MatchProps<unknown> | MatchProps<unknown>[];
65
- }): string;
66
- type MatchProps<T> = {
67
- when: T | false;
68
- keyed?: boolean;
69
- children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string);
70
- };
71
- export declare function Match<T>(props: MatchProps<T>): MatchProps<T>;
72
- export declare function resetErrorBoundaries(): void;
73
- export declare function ErrorBoundary(props: {
74
- fallback: string | ((err: any, reset: () => void) => string);
75
- children: string;
76
- }): string | ((err: any, reset: () => void) => string) | {
77
- t: string;
78
- };
79
- export interface Resource<T> {
80
- (): T | undefined;
81
- state: "unresolved" | "pending" | "ready" | "refreshing" | "errored";
82
- loading: boolean;
83
- error: any;
84
- latest: T | undefined;
85
- }
86
- type SuspenseContextType = {
87
- resources: Map<string, {
88
- _loading: boolean;
89
- error: any;
90
- }>;
91
- completed: () => void;
92
- };
93
- export type ResourceActions<T> = {
94
- mutate: Setter<T>;
95
- refetch: (info?: unknown) => void;
96
- };
97
- export type ResourceReturn<T> = [Resource<T>, ResourceActions<T>];
98
- export type ResourceSource<S> = S | false | null | undefined | (() => S | false | null | undefined);
99
- export type ResourceFetcher<S, T> = (k: S, info: ResourceFetcherInfo<T>) => T | Promise<T>;
100
- export type ResourceFetcherInfo<T> = {
101
- value: T | undefined;
102
- refetching?: unknown;
103
- };
104
- export type ResourceOptions<T> = undefined extends T ? {
105
- initialValue?: T;
106
- name?: string;
107
- deferStream?: boolean;
108
- ssrLoadFrom?: "initial" | "server";
109
- storage?: () => Signal<T | undefined>;
110
- onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
111
- } : {
112
- initialValue: T;
113
- name?: string;
114
- deferStream?: boolean;
115
- ssrLoadFrom?: "initial" | "server";
116
- storage?: (v?: T) => Signal<T | undefined>;
117
- onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
118
- };
119
- export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
120
- export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
121
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
122
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
123
- export declare function lazy<T extends Component<any>>(fn: () => Promise<{
124
- default: T;
125
- }>): T & {
126
- preload: () => Promise<{
127
- default: T;
128
- }>;
129
- };
130
- export declare function enableScheduling(): void;
131
- export declare function enableHydration(): void;
132
- export declare function startTransition(fn: () => any): void;
133
- export declare function useTransition(): [() => boolean, (fn: () => any) => void];
134
- type HydrationContext = {
135
- id: string;
136
- count: number;
137
- serialize: (id: string, v: Promise<any> | any, deferStream?: boolean) => void;
138
- nextRoot: (v: any) => string;
139
- replace: (id: string, replacement: () => any) => void;
140
- block: (p: Promise<any>) => void;
141
- resources: Record<string, any>;
142
- suspense: Record<string, SuspenseContextType>;
143
- registerFragment: (v: string) => (v?: string, err?: any) => boolean;
144
- lazy: Record<string, Promise<any>>;
145
- async?: boolean;
146
- noHydrate: boolean;
147
- };
148
- export declare function SuspenseList(props: {
149
- children: string;
150
- revealOrder: "forwards" | "backwards" | "together";
151
- tail?: "collapsed" | "hidden";
152
- }): string;
153
- export declare function Suspense(props: {
154
- fallback?: string;
155
- children: string;
156
- }): string | number | boolean | Node | JSX.ArrayElement | {
157
- t: string;
158
- } | null | undefined;
159
- export {};
@@ -1,245 +0,0 @@
1
- 'use strict';
2
-
3
- var solidJs = require('solid-js');
4
-
5
- const memo = fn => solidJs.createMemo(() => fn());
6
-
7
- function createRenderer$1({
8
- createElement,
9
- createTextNode,
10
- isTextNode,
11
- replaceText,
12
- insertNode,
13
- removeNode,
14
- setProperty,
15
- getParentNode,
16
- getFirstChild,
17
- getNextSibling
18
- }) {
19
- function insert(parent, accessor, marker, initial) {
20
- if (marker !== undefined && !initial) initial = [];
21
- if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
22
- solidJs.createRenderEffect(current => insertExpression(parent, accessor(), current, marker), initial);
23
- }
24
- function insertExpression(parent, value, current, marker, unwrapArray) {
25
- while (typeof current === "function") current = current();
26
- if (value === current) return current;
27
- const t = typeof value,
28
- multi = marker !== undefined;
29
- if (t === "string" || t === "number") {
30
- if (t === "number") value = value.toString();
31
- if (multi) {
32
- let node = current[0];
33
- if (node && isTextNode(node)) {
34
- replaceText(node, value);
35
- } else node = createTextNode(value);
36
- current = cleanChildren(parent, current, marker, node);
37
- } else {
38
- if (current !== "" && typeof current === "string") {
39
- replaceText(getFirstChild(parent), current = value);
40
- } else {
41
- cleanChildren(parent, current, marker, createTextNode(value));
42
- current = value;
43
- }
44
- }
45
- } else if (value == null || t === "boolean") {
46
- current = cleanChildren(parent, current, marker);
47
- } else if (t === "function") {
48
- solidJs.createRenderEffect(() => {
49
- let v = value();
50
- while (typeof v === "function") v = v();
51
- current = insertExpression(parent, v, current, marker);
52
- });
53
- return () => current;
54
- } else if (Array.isArray(value)) {
55
- const array = [];
56
- if (normalizeIncomingArray(array, value, unwrapArray)) {
57
- solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
58
- return () => current;
59
- }
60
- if (array.length === 0) {
61
- const replacement = cleanChildren(parent, current, marker);
62
- if (multi) return current = replacement;
63
- } else {
64
- if (Array.isArray(current)) {
65
- if (current.length === 0) {
66
- appendNodes(parent, array, marker);
67
- } else reconcileArrays(parent, current, array);
68
- } else if (current == null || current === "") {
69
- appendNodes(parent, array);
70
- } else {
71
- reconcileArrays(parent, multi && current || [getFirstChild(parent)], array);
72
- }
73
- }
74
- current = array;
75
- } else {
76
- if (Array.isArray(current)) {
77
- if (multi) return current = cleanChildren(parent, current, marker, value);
78
- cleanChildren(parent, current, null, value);
79
- } else if (current == null || current === "" || !getFirstChild(parent)) {
80
- insertNode(parent, value);
81
- } else replaceNode(parent, value, getFirstChild(parent));
82
- current = value;
83
- }
84
- return current;
85
- }
86
- function normalizeIncomingArray(normalized, array, unwrap) {
87
- let dynamic = false;
88
- for (let i = 0, len = array.length; i < len; i++) {
89
- let item = array[i],
90
- t;
91
- if (item == null || item === true || item === false) ; else if (Array.isArray(item)) {
92
- dynamic = normalizeIncomingArray(normalized, item) || dynamic;
93
- } else if ((t = typeof item) === "string" || t === "number") {
94
- normalized.push(createTextNode(item));
95
- } else if (t === "function") {
96
- if (unwrap) {
97
- while (typeof item === "function") item = item();
98
- dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic;
99
- } else {
100
- normalized.push(item);
101
- dynamic = true;
102
- }
103
- } else normalized.push(item);
104
- }
105
- return dynamic;
106
- }
107
- function reconcileArrays(parentNode, a, b) {
108
- let bLength = b.length,
109
- aEnd = a.length,
110
- bEnd = bLength,
111
- aStart = 0,
112
- bStart = 0,
113
- after = getNextSibling(a[aEnd - 1]),
114
- map = null;
115
- while (aStart < aEnd || bStart < bEnd) {
116
- if (a[aStart] === b[bStart]) {
117
- aStart++;
118
- bStart++;
119
- continue;
120
- }
121
- while (a[aEnd - 1] === b[bEnd - 1]) {
122
- aEnd--;
123
- bEnd--;
124
- }
125
- if (aEnd === aStart) {
126
- const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after;
127
- while (bStart < bEnd) insertNode(parentNode, b[bStart++], node);
128
- } else if (bEnd === bStart) {
129
- while (aStart < aEnd) {
130
- if (!map || !map.has(a[aStart])) removeNode(parentNode, a[aStart]);
131
- aStart++;
132
- }
133
- } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
134
- const node = getNextSibling(a[--aEnd]);
135
- insertNode(parentNode, b[bStart++], getNextSibling(a[aStart++]));
136
- insertNode(parentNode, b[--bEnd], node);
137
- a[aEnd] = b[bEnd];
138
- } else {
139
- if (!map) {
140
- map = new Map();
141
- let i = bStart;
142
- while (i < bEnd) map.set(b[i], i++);
143
- }
144
- const index = map.get(a[aStart]);
145
- if (index != null) {
146
- if (bStart < index && index < bEnd) {
147
- let i = aStart,
148
- sequence = 1,
149
- t;
150
- while (++i < aEnd && i < bEnd) {
151
- if ((t = map.get(a[i])) == null || t !== index + sequence) break;
152
- sequence++;
153
- }
154
- if (sequence > index - bStart) {
155
- const node = a[aStart];
156
- while (bStart < index) insertNode(parentNode, b[bStart++], node);
157
- } else replaceNode(parentNode, b[bStart++], a[aStart++]);
158
- } else aStart++;
159
- } else removeNode(parentNode, a[aStart++]);
160
- }
161
- }
162
- }
163
- function cleanChildren(parent, current, marker, replacement) {
164
- if (marker === undefined) {
165
- let removed;
166
- while (removed = getFirstChild(parent)) removeNode(parent, removed);
167
- replacement && insertNode(parent, replacement);
168
- return "";
169
- }
170
- const node = replacement || createTextNode("");
171
- if (current.length) {
172
- let inserted = false;
173
- for (let i = current.length - 1; i >= 0; i--) {
174
- const el = current[i];
175
- if (node !== el) {
176
- const isParent = getParentNode(el) === parent;
177
- if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el);
178
- } else inserted = true;
179
- }
180
- } else insertNode(parent, node, marker);
181
- return [node];
182
- }
183
- function appendNodes(parent, array, marker) {
184
- for (let i = 0, len = array.length; i < len; i++) insertNode(parent, array[i], marker);
185
- }
186
- function replaceNode(parent, newNode, oldNode) {
187
- insertNode(parent, newNode, oldNode);
188
- removeNode(parent, oldNode);
189
- }
190
- function spreadExpression(node, props, prevProps = {}, skipChildren) {
191
- props || (props = {});
192
- if (!skipChildren) {
193
- solidJs.createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children));
194
- }
195
- solidJs.createRenderEffect(() => props.ref && props.ref(node));
196
- solidJs.createRenderEffect(() => {
197
- for (const prop in props) {
198
- if (prop === "children" || prop === "ref") continue;
199
- const value = props[prop];
200
- if (value === prevProps[prop]) continue;
201
- setProperty(node, prop, value, prevProps[prop]);
202
- prevProps[prop] = value;
203
- }
204
- });
205
- return prevProps;
206
- }
207
- return {
208
- render(code, element) {
209
- let disposer;
210
- solidJs.createRoot(dispose => {
211
- disposer = dispose;
212
- insert(element, code());
213
- });
214
- return disposer;
215
- },
216
- insert,
217
- spread(node, accessor, skipChildren) {
218
- if (typeof accessor === "function") {
219
- solidJs.createRenderEffect(current => spreadExpression(node, accessor(), current, skipChildren));
220
- } else spreadExpression(node, accessor, undefined, skipChildren);
221
- },
222
- createElement,
223
- createTextNode,
224
- insertNode,
225
- setProp(node, name, value, prev) {
226
- setProperty(node, name, value, prev);
227
- return value;
228
- },
229
- mergeProps: solidJs.mergeProps,
230
- effect: solidJs.createRenderEffect,
231
- memo,
232
- createComponent: solidJs.createComponent,
233
- use(fn, element, arg) {
234
- return solidJs.untrack(() => fn(element, arg));
235
- }
236
- };
237
- }
238
-
239
- function createRenderer(options) {
240
- const renderer = createRenderer$1(options);
241
- renderer.mergeProps = solidJs.mergeProps;
242
- return renderer;
243
- }
244
-
245
- exports.createRenderer = createRenderer;