@solid-primitives/utils 7.0.0-next.3 → 7.0.0-next.7
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.
- package/README.md +13 -0
- package/dist/colors/helpers.d.ts +41 -43
- package/dist/colors/helpers.js +6 -8
- package/dist/colors/intl.d.ts +16 -17
- package/dist/colors/manipulation.d.ts +131 -133
- package/dist/colors/types.d.ts +24 -26
- package/dist/immutable/array.d.ts +105 -106
- package/dist/immutable/copy.d.ts +22 -23
- package/dist/immutable/number.d.ts +8 -9
- package/dist/immutable/object.d.ts +52 -52
- package/dist/immutable/types.d.ts +6 -6
- package/dist/immutable/update.d.ts +23 -25
- package/dist/index.d.ts +248 -229
- package/dist/index.js +28 -3
- package/dist/types.d.ts +53 -55
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,289 +1,308 @@
|
|
|
1
1
|
/* @ts-self-types="./index.d.ts" */
|
|
2
2
|
import { AccessReturnTypes, AccessorArray, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Narrow, NoInfer, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterParam, Simplify, Size, Tail, Truthy, UnboxLazy, UnionToIntersection, Values } from "./types.js";
|
|
3
3
|
import { Accessor, ComputeFunction, NoInfer as NoInfer$1, Setter, Signal, SignalOptions, Store, StoreSetter, createSignal, onCleanup } from "solid-js";
|
|
4
|
-
|
|
5
4
|
//#region src/index.d.ts
|
|
6
5
|
declare const isServer: boolean;
|
|
7
6
|
/** `true` in the browser, `false` on the server. */
|
|
8
|
-
declare const isClient: boolean;
|
|
7
|
+
export declare const isClient: boolean;
|
|
9
8
|
/** `true` in the browser with Solid's DEV mode active. */
|
|
10
|
-
declare const isDev: boolean;
|
|
9
|
+
export declare const isDev: boolean;
|
|
11
10
|
/** `true` when DEV mode is off (i.e. production browser builds and all SSR). */
|
|
12
|
-
declare const isProd: boolean;
|
|
11
|
+
export declare const isProd: boolean;
|
|
13
12
|
/** No-operation function — accepts any arguments and returns `undefined`. */
|
|
14
|
-
declare const noop: Noop;
|
|
13
|
+
export declare const noop: Noop;
|
|
15
14
|
/** A function that always returns `true`. Useful as a default predicate prop. */
|
|
16
|
-
declare const trueFn: () => boolean;
|
|
15
|
+
export declare const trueFn: () => boolean;
|
|
17
16
|
/** A function that always returns `false`. Useful as a default predicate prop. */
|
|
18
|
-
declare const falseFn: () => boolean;
|
|
17
|
+
export declare const falseFn: () => boolean;
|
|
19
18
|
/** @deprecated use {@link equalFn} from "solid-js" */
|
|
20
|
-
declare const defaultEquals: typeof Object.is;
|
|
19
|
+
export declare const defaultEquals: typeof Object.is;
|
|
21
20
|
/**
|
|
22
|
-
* Signal options that disable equality checking, causing the signal to always
|
|
23
|
-
* notify subscribers even when the value hasn't changed. Useful for signals
|
|
24
|
-
* holding mutable objects where structural equality cannot be assumed.
|
|
25
|
-
*/
|
|
26
|
-
declare const EQUALS_FALSE_OPTIONS: {
|
|
21
|
+
* Signal options that disable equality checking, causing the signal to always
|
|
22
|
+
* notify subscribers even when the value hasn't changed. Useful for signals
|
|
23
|
+
* holding mutable objects where structural equality cannot be assumed.
|
|
24
|
+
*/
|
|
25
|
+
export declare const EQUALS_FALSE_OPTIONS: {
|
|
27
26
|
readonly equals: false;
|
|
28
27
|
};
|
|
29
28
|
/**
|
|
30
|
-
* Signal options that allow writes from inside an owned reactive scope
|
|
31
|
-
* (component body, memo, or effect) without throwing `SIGNAL_WRITE_IN_OWNED_SCOPE`
|
|
32
|
-
* in Solid 2.0 dev mode.
|
|
33
|
-
*
|
|
34
|
-
* Use only for implementation-detail signals that genuinely need to be written
|
|
35
|
-
* from within a scope — not as a general escape hatch.
|
|
36
|
-
*/
|
|
37
|
-
declare const INTERNAL_OPTIONS: {
|
|
29
|
+
* Signal options that allow writes from inside an owned reactive scope
|
|
30
|
+
* (component body, memo, or effect) without throwing `SIGNAL_WRITE_IN_OWNED_SCOPE`
|
|
31
|
+
* in Solid 2.0 dev mode.
|
|
32
|
+
*
|
|
33
|
+
* Use only for implementation-detail signals that genuinely need to be written
|
|
34
|
+
* from within a scope — not as a general escape hatch.
|
|
35
|
+
*/
|
|
36
|
+
export declare const INTERNAL_OPTIONS: {
|
|
38
37
|
readonly ownedWrite: true;
|
|
39
38
|
};
|
|
40
39
|
/**
|
|
41
|
-
* Returns `true` if `v` is an instance of `c`. Checks both `instanceof` and
|
|
42
|
-
* `constructor` so that values created across different realms (e.g. iframes) match.
|
|
43
|
-
*/
|
|
44
|
-
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
40
|
+
* Returns `true` if `v` is an instance of `c`. Checks both `instanceof` and
|
|
41
|
+
* `constructor` so that values created across different realms (e.g. iframes) match.
|
|
42
|
+
*/
|
|
43
|
+
export declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
45
44
|
/** Check if value is typeof "object" or "function" */
|
|
46
|
-
declare function isObject(value: any): value is AnyObject;
|
|
45
|
+
export declare function isObject(value: any): value is AnyObject;
|
|
47
46
|
/** Type guard: returns `true` when `i` is neither `null` nor `undefined`. */
|
|
48
|
-
declare const isNonNullable: <T>(i: T) => i is NonNullable<T>;
|
|
47
|
+
export declare const isNonNullable: <T>(i: T) => i is NonNullable<T>;
|
|
49
48
|
/** Returns a new array with all `null` and `undefined` items removed. */
|
|
50
|
-
declare const filterNonNullable: <T extends readonly unknown[]>(arr: T) => NonNullable<T[number]>[];
|
|
49
|
+
export declare const filterNonNullable: <T extends readonly unknown[]>(arr: T) => NonNullable<T[number]>[];
|
|
51
50
|
/** Three-way comparison: returns `-1` if `a < b`, `1` if `a > b`, `0` if equal. */
|
|
52
|
-
declare const compare: (a: any, b: any) => number;
|
|
51
|
+
export declare const compare: (a: any, b: any) => number;
|
|
53
52
|
/**
|
|
54
|
-
* Check shallow array equality
|
|
55
|
-
*/
|
|
56
|
-
declare const arrayEquals: (a: readonly unknown[], b: readonly unknown[]) => boolean;
|
|
53
|
+
* Check shallow array equality
|
|
54
|
+
*/
|
|
55
|
+
export declare const arrayEquals: (a: readonly unknown[], b: readonly unknown[]) => boolean;
|
|
57
56
|
/**
|
|
58
|
-
* Returns a function that will call all functions in the order they were chained with the same arguments.
|
|
59
|
-
*/
|
|
60
|
-
declare function chain<Args extends [] | any[]>(callbacks: {
|
|
57
|
+
* Returns a function that will call all functions in the order they were chained with the same arguments.
|
|
58
|
+
*/
|
|
59
|
+
export declare function chain<Args extends [] | any[]>(callbacks: {
|
|
61
60
|
[Symbol.iterator](): IterableIterator<((...args: Args) => any) | undefined>;
|
|
62
61
|
}): (...args: Args) => void;
|
|
63
62
|
/**
|
|
64
|
-
* Returns a function that will call all functions in the reversed order with the same arguments.
|
|
65
|
-
*/
|
|
66
|
-
declare function reverseChain<Args extends [] | any[]>(callbacks: (((...args: Args) => any) | undefined)[]): (...args: Args) => void;
|
|
63
|
+
* Returns a function that will call all functions in the reversed order with the same arguments.
|
|
64
|
+
*/
|
|
65
|
+
export declare function reverseChain<Args extends [] | any[]>(callbacks: (((...args: Args) => any) | undefined)[]): (...args: Args) => void;
|
|
67
66
|
/** Clamps `n` to the inclusive range `[min, max]`. */
|
|
68
|
-
declare const clamp: (n: number, min: number, max: number) => number;
|
|
67
|
+
export declare const clamp: (n: number, min: number, max: number) => number;
|
|
69
68
|
/** Creates an ID generator with its own isolated counter and per-generator random segment. Each call to the returned function produces a `timestamp-sequence-random` string that is unique within the generator and with high probability unique across independent generators (e.g. separate processes or SSR requests). */
|
|
70
|
-
declare const createIdGenerator: () => (() => string);
|
|
69
|
+
export declare const createIdGenerator: () => (() => string);
|
|
71
70
|
/**
|
|
72
|
-
* Accesses the value of a MaybeAccessor
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* access("foo") // => "foo"
|
|
76
|
-
* access(() => "foo") // => "foo"
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
declare const access: <T extends MaybeAccessor<any>>(v: T) => MaybeAccessorValue<T>;
|
|
71
|
+
* Accesses the value of a MaybeAccessor
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* access("foo") // => "foo"
|
|
75
|
+
* access(() => "foo") // => "foo"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const access: <T extends MaybeAccessor<any>>(v: T) => MaybeAccessorValue<T>;
|
|
80
79
|
/**
|
|
81
|
-
* Wraps `value` in a single-element array. If `value` is already an array it is
|
|
82
|
-
* returned as-is. Falsy values (except `0` and `false`) produce an empty array.
|
|
83
|
-
*/
|
|
84
|
-
declare const asArray: <T>(value: T) => (T extends any[] ? T[number] : NonNullable<T>)[];
|
|
80
|
+
* Wraps `value` in a single-element array. If `value` is already an array it is
|
|
81
|
+
* returned as-is. Falsy values (except `0` and `false`) produce an empty array.
|
|
82
|
+
*/
|
|
83
|
+
export declare const asArray: <T>(value: T) => (T extends any[] ? T[number] : NonNullable<T>)[];
|
|
85
84
|
/**
|
|
86
|
-
* Access an array of MaybeAccessors
|
|
87
|
-
* @example
|
|
88
|
-
* const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
|
|
89
|
-
* const newList = accessArray(list) // T: number[]
|
|
90
|
-
*/
|
|
91
|
-
declare const accessArray: <A extends MaybeAccessor<any>>(list: readonly A[]) => MaybeAccessorValue<A>[];
|
|
85
|
+
* Access an array of MaybeAccessors
|
|
86
|
+
* @example
|
|
87
|
+
* const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
|
|
88
|
+
* const newList = accessArray(list) // T: number[]
|
|
89
|
+
*/
|
|
90
|
+
export declare const accessArray: <A extends MaybeAccessor<any>>(list: readonly A[]) => MaybeAccessorValue<A>[];
|
|
92
91
|
/**
|
|
93
|
-
* Run the function if the accessed value is not `undefined` nor `null`
|
|
94
|
-
* @param value
|
|
95
|
-
* @param fn
|
|
96
|
-
*/
|
|
97
|
-
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
92
|
+
* Run the function if the accessed value is not `undefined` nor `null`
|
|
93
|
+
* @param value
|
|
94
|
+
* @param fn
|
|
95
|
+
*/
|
|
96
|
+
export declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
98
97
|
/**
|
|
99
|
-
* Wraps a plain value in a zero-argument accessor `() => value`.
|
|
100
|
-
* If `v` is already a function it is returned unchanged.
|
|
101
|
-
*/
|
|
102
|
-
declare const asAccessor: <A extends MaybeAccessor<unknown>>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
98
|
+
* Wraps a plain value in a zero-argument accessor `() => value`.
|
|
99
|
+
* If `v` is already a function it is returned unchanged.
|
|
100
|
+
*/
|
|
101
|
+
export declare const asAccessor: <A extends MaybeAccessor<unknown>>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
103
102
|
/** If value is a function – call it with a given arguments – otherwise get the value as is */
|
|
104
|
-
declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFunction ? Parameters<T> : never): T extends AnyFunction ? ReturnType<T> : T;
|
|
103
|
+
export declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFunction ? Parameters<T> : never): T extends AnyFunction ? ReturnType<T> : T;
|
|
105
104
|
/**
|
|
106
|
-
* A deferred effect compute function. Skips the first reactive run and returns
|
|
107
|
-
* `initialValue` instead, then calls `fn` on subsequent dependency changes.
|
|
108
|
-
* Useful as the compute phase of `createEffect(defer(...), apply)` when the
|
|
109
|
-
* initial run should be suppressed.
|
|
110
|
-
*
|
|
111
|
-
* @param deps - a single accessor or an array of accessors to track
|
|
112
|
-
* @param fn - called with the current input, previous input, and previous return value
|
|
113
|
-
* @param initialValue - returned on the skipped first run (defaults to `undefined`)
|
|
114
|
-
*/
|
|
115
|
-
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer$1<Prev>) => Next, initialValue: Next): ComputeFunction<undefined | NoInfer$1<Next>, NoInfer$1<Next>>;
|
|
116
|
-
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer$1<Prev>) => Next, initialValue?: undefined): ComputeFunction<undefined | NoInfer$1<Next>>;
|
|
105
|
+
* A deferred effect compute function. Skips the first reactive run and returns
|
|
106
|
+
* `initialValue` instead, then calls `fn` on subsequent dependency changes.
|
|
107
|
+
* Useful as the compute phase of `createEffect(defer(...), apply)` when the
|
|
108
|
+
* initial run should be suppressed.
|
|
109
|
+
*
|
|
110
|
+
* @param deps - a single accessor or an array of accessors to track
|
|
111
|
+
* @param fn - called with the current input, previous input, and previous return value
|
|
112
|
+
* @param initialValue - returned on the skipped first run (defaults to `undefined`)
|
|
113
|
+
*/
|
|
114
|
+
export declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer$1<Prev>) => Next, initialValue: Next): ComputeFunction<undefined | NoInfer$1<Next>, NoInfer$1<Next>>;
|
|
115
|
+
export declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer$1<Prev>) => Next, initialValue?: undefined): ComputeFunction<undefined | NoInfer$1<Next>>;
|
|
117
116
|
/**
|
|
118
|
-
* Get entries of an object
|
|
119
|
-
*/
|
|
120
|
-
declare const entries: <T extends object>(obj: T) => [keyof T, T[keyof T]][];
|
|
117
|
+
* Get entries of an object
|
|
118
|
+
*/
|
|
119
|
+
export declare const entries: <T extends object>(obj: T) => [keyof T, T[keyof T]][];
|
|
121
120
|
/**
|
|
122
|
-
* Get keys of an object
|
|
123
|
-
*/
|
|
124
|
-
declare const keys: <T extends object>(object: T) => (keyof T)[];
|
|
121
|
+
* Get keys of an object
|
|
122
|
+
*/
|
|
123
|
+
export declare const keys: <T extends object>(object: T) => (keyof T)[];
|
|
125
124
|
/**
|
|
126
|
-
* Solid's `onCleanup` that doesn't warn in development if used outside of a component.
|
|
127
|
-
*/
|
|
128
|
-
declare const tryOnCleanup: typeof onCleanup;
|
|
125
|
+
* Solid's `onCleanup` that doesn't warn in development if used outside of a component.
|
|
126
|
+
*/
|
|
127
|
+
export declare const tryOnCleanup: typeof onCleanup;
|
|
129
128
|
/**
|
|
130
|
-
* Creates a stack of callbacks that can be pushed to, executed all at once, or cleared.
|
|
131
|
-
* All callbacks receive the same arguments when `execute` is called; the stack is
|
|
132
|
-
* automatically cleared after execution.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```ts
|
|
136
|
-
* const stack = createCallbackStack<string>();
|
|
137
|
-
* stack.push(s => console.log("a:", s));
|
|
138
|
-
* stack.push(s => console.log("b:", s));
|
|
139
|
-
* stack.execute("hello"); // logs "a: hello", "b: hello" — stack is now empty
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
129
|
+
* Creates a stack of callbacks that can be pushed to, executed all at once, or cleared.
|
|
130
|
+
* All callbacks receive the same arguments when `execute` is called; the stack is
|
|
131
|
+
* automatically cleared after execution.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const stack = createCallbackStack<string>();
|
|
136
|
+
* stack.push(s => console.log("a:", s));
|
|
137
|
+
* stack.push(s => console.log("b:", s));
|
|
138
|
+
* stack.execute("hello"); // logs "a: hello", "b: hello" — stack is now empty
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
143
142
|
push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
|
|
144
143
|
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
|
|
145
144
|
clear: VoidFunction;
|
|
146
145
|
};
|
|
147
146
|
/**
|
|
148
|
-
* Returns a debounced wrapper around `fn` that batches rapid synchronous calls
|
|
149
|
-
* into a single invocation. Only the most-recently-passed arguments are forwarded.
|
|
150
|
-
* The counter resets on cleanup so stale microtasks are silently discarded.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* const flush = createMicrotask((value: string) => console.log(value));
|
|
155
|
-
* flush("a");
|
|
156
|
-
* flush("b");
|
|
157
|
-
* flush("c"); // only "c" is logged (in the next microtask)
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
declare function createMicrotask<A extends any[] | []>(fn: (...a: A) => void): (...a: A) => void;
|
|
147
|
+
* Returns a debounced wrapper around `fn` that batches rapid synchronous calls
|
|
148
|
+
* into a single invocation. Only the most-recently-passed arguments are forwarded.
|
|
149
|
+
* The counter resets on cleanup so stale microtasks are silently discarded.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const flush = createMicrotask((value: string) => console.log(value));
|
|
154
|
+
* flush("a");
|
|
155
|
+
* flush("b");
|
|
156
|
+
* flush("c"); // only "c" is logged (in the next microtask)
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export declare function createMicrotask<A extends any[] | []>(fn: (...a: A) => void): (...a: A) => void;
|
|
161
160
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
|
|
173
|
-
|
|
161
|
+
* `createSignal` on the client; a plain mutable box on the server.
|
|
162
|
+
*
|
|
163
|
+
* Solid 2 treats a setter that runs during a server render as an error in waiting
|
|
164
|
+
* (`SERVER_WRITE`: the write lands as inert data today and throws in a later release) — server
|
|
165
|
+
* render is pure, state enters through async sources. Primitives that hold *interactive*
|
|
166
|
+
* state (a cursor, a toggle, a controlled value) have no async source, so on the server they
|
|
167
|
+
* keep a plain value instead: reads and updater-form writes behave the same within a request,
|
|
168
|
+
* and nothing touches the reactive graph.
|
|
169
|
+
*
|
|
170
|
+
* The signal is still *created* on the server — hydration ids are handed out per created
|
|
171
|
+
* primitive, so a server branch that skipped it would misalign keys with the client
|
|
172
|
+
* ("Hydration key miss"). It is simply never read or written there.
|
|
173
|
+
*
|
|
174
|
+
* @param value initial value
|
|
175
|
+
* @param options signal options (the signal only matters on the client)
|
|
176
|
+
* @returns a `[get, set]` tuple with `createSignal`'s shape
|
|
177
|
+
* @see {@link createSignal}
|
|
178
|
+
*/
|
|
179
|
+
export declare function createServerSafeSignal<T>(value: T, options?: SignalOptions<T>): ReturnType<typeof createSignal<T>>;
|
|
180
|
+
/**
|
|
181
|
+
* A hydratable version of the {@link createSignal}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete.
|
|
182
|
+
*
|
|
183
|
+
* @param serverValue initial value of the state on the server
|
|
184
|
+
* @param update called once on the client or on hydration to initialize the value
|
|
185
|
+
* @param options {@link SignalOptions}
|
|
186
|
+
* @returns
|
|
187
|
+
* ```ts
|
|
188
|
+
* [state: Accessor<T>, setState: Setter<T>]
|
|
189
|
+
* ```
|
|
190
|
+
* @see {@link createSignal}
|
|
191
|
+
*/
|
|
192
|
+
export declare function createHydratableSignal<T>(serverValue: T, update: () => T, options?: SignalOptions<T>): ReturnType<typeof createSignal<T>>;
|
|
174
193
|
/** @deprecated use {@link createHydratableSignal} instead */
|
|
175
|
-
declare const createHydrateSignal: typeof createHydratableSignal;
|
|
194
|
+
export declare const createHydrateSignal: typeof createHydratableSignal;
|
|
176
195
|
/**
|
|
177
|
-
* Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
|
|
178
|
-
* each item that appeared or disappeared. Items are compared with `===`.
|
|
179
|
-
*
|
|
180
|
-
* @param current - the new array
|
|
181
|
-
* @param prev - the previous array snapshot
|
|
182
|
-
* @param handleAdded - called once for each item present in `current` but not `prev`
|
|
183
|
-
* @param handleRemoved - called once for each item present in `prev` but not `current`
|
|
184
|
-
*/
|
|
185
|
-
declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
|
|
196
|
+
* Diffs two arrays by reference and calls `handleAdded` / `handleRemoved` for
|
|
197
|
+
* each item that appeared or disappeared. Items are compared with `===`.
|
|
198
|
+
*
|
|
199
|
+
* @param current - the new array
|
|
200
|
+
* @param prev - the previous array snapshot
|
|
201
|
+
* @param handleAdded - called once for each item present in `current` but not `prev`
|
|
202
|
+
* @param handleRemoved - called once for each item present in `prev` but not `current`
|
|
203
|
+
*/
|
|
204
|
+
export declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
|
|
186
205
|
/**
|
|
187
|
-
* Schedules `fn` to run after the browser has painted by nesting two
|
|
188
|
-
* requestAnimationFrame calls. No-op in non-browser environments.
|
|
189
|
-
*/
|
|
190
|
-
declare const afterPaint: (fn: () => void) => void;
|
|
206
|
+
* Schedules `fn` to run after the browser has painted by nesting two
|
|
207
|
+
* requestAnimationFrame calls. No-op in non-browser environments.
|
|
208
|
+
*/
|
|
209
|
+
export declare const afterPaint: (fn: () => void) => void;
|
|
191
210
|
/**
|
|
192
|
-
* Parse a string as a single JSON value.
|
|
193
|
-
*
|
|
194
|
-
* ```ts
|
|
195
|
-
* const { data } = createSSE<{ status: string }>(url, { transform: json });
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
declare const json: <T>(raw: string) => T;
|
|
211
|
+
* Parse a string as a single JSON value.
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* const { data } = createSSE<{ status: string }>(url, { transform: json });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare const json: <T>(raw: string) => T;
|
|
199
218
|
/**
|
|
200
|
-
* Parse a string as newline-delimited JSON (NDJSON / JSON Lines).
|
|
201
|
-
*
|
|
202
|
-
* Each non-empty line is parsed as a separate JSON value and returned as an array.
|
|
203
|
-
*
|
|
204
|
-
* ```ts
|
|
205
|
-
* const { data } = createSSE<TickEvent[]>(url, { transform: ndjson });
|
|
206
|
-
* // data() === [{ id: 1, type: "tick" }, { id: 2, type: "tick" }]
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
declare const ndjson: <T>(raw: string) => T[];
|
|
219
|
+
* Parse a string as newline-delimited JSON (NDJSON / JSON Lines).
|
|
220
|
+
*
|
|
221
|
+
* Each non-empty line is parsed as a separate JSON value and returned as an array.
|
|
222
|
+
*
|
|
223
|
+
* ```ts
|
|
224
|
+
* const { data } = createSSE<TickEvent[]>(url, { transform: ndjson });
|
|
225
|
+
* // data() === [{ id: 1, type: "tick" }, { id: 2, type: "tick" }]
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export declare const ndjson: <T>(raw: string) => T[];
|
|
210
229
|
/**
|
|
211
|
-
* Split a string into individual lines, returning a `string[]`. Empty lines are filtered out.
|
|
212
|
-
*
|
|
213
|
-
* ```ts
|
|
214
|
-
* const { data } = createSSE<string[]>(url, { transform: lines });
|
|
215
|
-
* // data() === ["line one", "line two"]
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
declare const lines: (raw: string) => string[];
|
|
230
|
+
* Split a string into individual lines, returning a `string[]`. Empty lines are filtered out.
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* const { data } = createSSE<string[]>(url, { transform: lines });
|
|
234
|
+
* // data() === ["line one", "line two"]
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export declare const lines: (raw: string) => string[];
|
|
219
238
|
/**
|
|
220
|
-
* Parse a string as a number using `Number()` semantics.
|
|
221
|
-
*
|
|
222
|
-
* Note: `""` → `0`, non-numeric strings → `NaN`.
|
|
223
|
-
*
|
|
224
|
-
* ```ts
|
|
225
|
-
* const { data } = createSSE<number>(url, { transform: number });
|
|
226
|
-
* // data() === 42
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
declare const number: (raw: string) => number;
|
|
239
|
+
* Parse a string as a number using `Number()` semantics.
|
|
240
|
+
*
|
|
241
|
+
* Note: `""` → `0`, non-numeric strings → `NaN`.
|
|
242
|
+
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* const { data } = createSSE<number>(url, { transform: number });
|
|
245
|
+
* // data() === 42
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export declare const number: (raw: string) => number;
|
|
230
249
|
/**
|
|
231
|
-
* Wrap any `(string) => T` transform in a `try/catch`. Returns `fallback`
|
|
232
|
-
* (default `undefined`) instead of throwing on malformed input.
|
|
233
|
-
*
|
|
234
|
-
* ```ts
|
|
235
|
-
* const { data } = createSSE<MyEvent>(url, { transform: safe(json) });
|
|
236
|
-
* const { data } = createSSE<number>(url, { transform: safe(number, 0) });
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
declare function safe<T>(transform: (raw: string) => T): (raw: string) => T | undefined;
|
|
240
|
-
declare function safe<T>(transform: (raw: string) => T, fallback: T): (raw: string) => T;
|
|
250
|
+
* Wrap any `(string) => T` transform in a `try/catch`. Returns `fallback`
|
|
251
|
+
* (default `undefined`) instead of throwing on malformed input.
|
|
252
|
+
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* const { data } = createSSE<MyEvent>(url, { transform: safe(json) });
|
|
255
|
+
* const { data } = createSSE<number>(url, { transform: safe(number, 0) });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
export declare function safe<T>(transform: (raw: string) => T): (raw: string) => T | undefined;
|
|
259
|
+
export declare function safe<T>(transform: (raw: string) => T, fallback: T): (raw: string) => T;
|
|
241
260
|
/**
|
|
242
|
-
* Compose two transforms into one: the output of `a` is passed as the input of `b`.
|
|
243
|
-
*
|
|
244
|
-
* ```ts
|
|
245
|
-
* const { data } = createSSE<RawEvent[]>(url, {
|
|
246
|
-
* transform: pipe(ndjson<RawEvent>, rows => rows.filter(r => r.type === "tick")),
|
|
247
|
-
* });
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
declare function pipe<A, B>(a: (raw: string) => A, b: (a: A) => B): (raw: string) => B;
|
|
261
|
+
* Compose two transforms into one: the output of `a` is passed as the input of `b`.
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* const { data } = createSSE<RawEvent[]>(url, {
|
|
265
|
+
* transform: pipe(ndjson<RawEvent>, rows => rows.filter(r => r.type === "tick")),
|
|
266
|
+
* });
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
export declare function pipe<A, B>(a: (raw: string) => A, b: (a: A) => B): (raw: string) => B;
|
|
251
270
|
/**
|
|
252
|
-
* Check if a wrapper element contains a target element.
|
|
253
|
-
* Portal-aware: follows SolidJS `_$host` links so elements rendered inside
|
|
254
|
-
* a `<Portal>` are correctly treated as children of the portal's anchor.
|
|
255
|
-
*/
|
|
256
|
-
declare const contains: (wrapper: HTMLElement, target: HTMLElement) => boolean;
|
|
271
|
+
* Check if a wrapper element contains a target element.
|
|
272
|
+
* Portal-aware: follows SolidJS `_$host` links so elements rendered inside
|
|
273
|
+
* a `<Portal>` are correctly treated as children of the portal's anchor.
|
|
274
|
+
*/
|
|
275
|
+
export declare const contains: (wrapper: HTMLElement, target: HTMLElement) => boolean;
|
|
257
276
|
/**
|
|
258
|
-
* Returns a singleton value keyed by `key`, shared across every copy of the calling module that
|
|
259
|
-
* ends up loaded in the same JS realm (a `Symbol.for(key)` slot on `globalThis`, not a module-scope
|
|
260
|
-
* binding). Use this instead of a plain module-scope `let`/`const` for state that must stay
|
|
261
|
-
* consistent (ref-counts, active-instance stacks) even if the app's dependency graph ends up with
|
|
262
|
-
* more than one installed copy of the package — module-scope state would otherwise be split across
|
|
263
|
-
* copies and go out of sync (e.g. a "topmost instance" check disagreeing between copies).
|
|
264
|
-
*
|
|
265
|
-
* ```ts
|
|
266
|
-
* const registry = globalRegistry("@solid-primitives/my-package:my-state", () => ({
|
|
267
|
-
* stack: createSignal<string[]>([], { ownedWrite: true }),
|
|
268
|
-
* nextId: 0,
|
|
269
|
-
* }));
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
declare function globalRegistry<T>(key: string, init: () => T): T;
|
|
277
|
+
* Returns a singleton value keyed by `key`, shared across every copy of the calling module that
|
|
278
|
+
* ends up loaded in the same JS realm (a `Symbol.for(key)` slot on `globalThis`, not a module-scope
|
|
279
|
+
* binding). Use this instead of a plain module-scope `let`/`const` for state that must stay
|
|
280
|
+
* consistent (ref-counts, active-instance stacks) even if the app's dependency graph ends up with
|
|
281
|
+
* more than one installed copy of the package — module-scope state would otherwise be split across
|
|
282
|
+
* copies and go out of sync (e.g. a "topmost instance" check disagreeing between copies).
|
|
283
|
+
*
|
|
284
|
+
* ```ts
|
|
285
|
+
* const registry = globalRegistry("@solid-primitives/my-package:my-state", () => ({
|
|
286
|
+
* stack: createSignal<string[]>([], { ownedWrite: true }),
|
|
287
|
+
* nextId: 0,
|
|
288
|
+
* }));
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
export declare function globalRegistry<T>(key: string, init: () => T): T;
|
|
273
292
|
/**
|
|
274
|
-
* Wraps a setter function of any signal or store
|
|
275
|
-
*
|
|
276
|
-
* ```ts
|
|
277
|
-
* const [data, setData] = wrapSetter(
|
|
278
|
-
* createSignal(initialData),
|
|
279
|
-
* (setter) => (next) => { console.log(next); return setter(next); },
|
|
280
|
-
* );
|
|
281
|
-
* ```
|
|
282
|
-
* If you destructure signal or store in a longer tuple, you need to use a const assertion for the types to work.
|
|
283
|
-
*/
|
|
284
|
-
declare function wrapSetter<T>(signal: Signal<T>, wrapper: (setter: Setter<T>) => Setter<T>): Signal<T>;
|
|
285
|
-
declare function wrapSetter<T>(store: [Store<T>, StoreSetter<T>], wrapper: (setter: StoreSetter<T>) => StoreSetter<T>): [Store<T>, StoreSetter<T>];
|
|
286
|
-
declare function wrapSetter<T, S extends Signal<T> | [Store<T>, StoreSetter<T>] | [...Signal<T>, ...any[]] | [Store<T>, StoreSetter<T>, ...any[]]>(signalOrStore: S, wrapper: (setter: S[1]) => S[1]): S;
|
|
287
|
-
declare function wrapSetter<T, S extends Signal<T> | [Store<T>, StoreSetter<T>] | readonly [...Signal<T>, ...any[]] | readonly [Store<T>, StoreSetter<T>, ...any[]]>(signalOrStore: S, wrapper: (setter: S[1]) => S[1]): S;
|
|
293
|
+
* Wraps a setter function of any signal or store
|
|
294
|
+
*
|
|
295
|
+
* ```ts
|
|
296
|
+
* const [data, setData] = wrapSetter(
|
|
297
|
+
* createSignal(initialData),
|
|
298
|
+
* (setter) => (next) => { console.log(next); return setter(next); },
|
|
299
|
+
* );
|
|
300
|
+
* ```
|
|
301
|
+
* If you destructure signal or store in a longer tuple, you need to use a const assertion for the types to work.
|
|
302
|
+
*/
|
|
303
|
+
export declare function wrapSetter<T>(signal: Signal<T>, wrapper: (setter: Setter<T>) => Setter<T>): Signal<T>;
|
|
304
|
+
export declare function wrapSetter<T>(store: [Store<T>, StoreSetter<T>], wrapper: (setter: StoreSetter<T>) => StoreSetter<T>): [Store<T>, StoreSetter<T>];
|
|
305
|
+
export declare function wrapSetter<T, S extends Signal<T> | [Store<T>, StoreSetter<T>] | [...Signal<T>, ...any[]] | [Store<T>, StoreSetter<T>, ...any[]]>(signalOrStore: S, wrapper: (setter: S[1]) => S[1]): S;
|
|
306
|
+
export declare function wrapSetter<T, S extends Signal<T> | [Store<T>, StoreSetter<T>] | readonly [...Signal<T>, ...any[]] | readonly [Store<T>, StoreSetter<T>, ...any[]]>(signalOrStore: S, wrapper: (setter: S[1]) => S[1]): S;
|
|
288
307
|
//#endregion
|
|
289
|
-
export { AccessReturnTypes, AccessorArray, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive,
|
|
308
|
+
export { AccessReturnTypes, AccessorArray, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Narrow, NoInfer, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterParam, Simplify, Size, Tail, Truthy, UnboxLazy, UnionToIntersection, Values, isServer };
|
package/dist/index.js
CHANGED
|
@@ -195,6 +195,32 @@ function createMicrotask(fn) {
|
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
|
+
* `createSignal` on the client; a plain mutable box on the server.
|
|
199
|
+
*
|
|
200
|
+
* Solid 2 treats a setter that runs during a server render as an error in waiting
|
|
201
|
+
* (`SERVER_WRITE`: the write lands as inert data today and throws in a later release) — server
|
|
202
|
+
* render is pure, state enters through async sources. Primitives that hold *interactive*
|
|
203
|
+
* state (a cursor, a toggle, a controlled value) have no async source, so on the server they
|
|
204
|
+
* keep a plain value instead: reads and updater-form writes behave the same within a request,
|
|
205
|
+
* and nothing touches the reactive graph.
|
|
206
|
+
*
|
|
207
|
+
* The signal is still *created* on the server — hydration ids are handed out per created
|
|
208
|
+
* primitive, so a server branch that skipped it would misalign keys with the client
|
|
209
|
+
* ("Hydration key miss"). It is simply never read or written there.
|
|
210
|
+
*
|
|
211
|
+
* @param value initial value
|
|
212
|
+
* @param options signal options (the signal only matters on the client)
|
|
213
|
+
* @returns a `[get, set]` tuple with `createSignal`'s shape
|
|
214
|
+
* @see {@link createSignal}
|
|
215
|
+
*/
|
|
216
|
+
function createServerSafeSignal(value, options) {
|
|
217
|
+
const signal = createSignal(value, options);
|
|
218
|
+
if (!isServer) return signal;
|
|
219
|
+
const get = () => value;
|
|
220
|
+
const set = (next) => value = typeof next === "function" ? next(value) : next;
|
|
221
|
+
return [get, set];
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
198
224
|
* A hydratable version of the {@link createSignal}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete.
|
|
199
225
|
*
|
|
200
226
|
* @param serverValue initial value of the state on the server
|
|
@@ -207,8 +233,7 @@ function createMicrotask(fn) {
|
|
|
207
233
|
* @see {@link createSignal}
|
|
208
234
|
*/
|
|
209
235
|
function createHydratableSignal(serverValue, update, options) {
|
|
210
|
-
if (isServer
|
|
211
|
-
if (sharedConfig.hydrating) {
|
|
236
|
+
if (isServer || sharedConfig.hydrating) {
|
|
212
237
|
const [state, setState] = createSignal(serverValue, options);
|
|
213
238
|
onSettled(() => {
|
|
214
239
|
setState(() => update());
|
|
@@ -356,4 +381,4 @@ function wrapSetter(signalOrStore, wrapper) {
|
|
|
356
381
|
];
|
|
357
382
|
}
|
|
358
383
|
//#endregion
|
|
359
|
-
export { EQUALS_FALSE_OPTIONS, INTERNAL_OPTIONS, access, accessArray, accessWith, afterPaint, arrayEquals, asAccessor, asArray, chain, clamp, compare, contains, createCallbackStack, createHydratableSignal, createHydrateSignal, createIdGenerator, createMicrotask, defaultEquals, defer, entries, falseFn, filterNonNullable, globalRegistry, handleDiffArray, isClient, isDev, isNonNullable, isObject, isProd, isServer, json, keys, lines, ndjson, noop, number, ofClass, pipe, reverseChain, safe, trueFn, tryOnCleanup, withAccess, wrapSetter };
|
|
384
|
+
export { EQUALS_FALSE_OPTIONS, INTERNAL_OPTIONS, access, accessArray, accessWith, afterPaint, arrayEquals, asAccessor, asArray, chain, clamp, compare, contains, createCallbackStack, createHydratableSignal, createHydrateSignal, createIdGenerator, createMicrotask, createServerSafeSignal, defaultEquals, defer, entries, falseFn, filterNonNullable, globalRegistry, handleDiffArray, isClient, isDev, isNonNullable, isObject, isProd, isServer, json, keys, lines, ndjson, noop, number, ofClass, pipe, reverseChain, safe, trueFn, tryOnCleanup, withAccess, wrapSetter };
|