@tempots/dom 17.0.0 → 19.0.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.
- package/dom/animatable.d.ts +12 -12
- package/dom/attr.d.ts +14 -7
- package/dom/dom-context.d.ts +47 -2
- package/dom/dom-utils.d.ts +6 -3
- package/dom/handle-anchor-click.d.ts +13 -2
- package/dom/ssr.d.ts +48 -16
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1050 -931
- package/package.json +1 -1
- package/renderable/async.d.ts +33 -3
- package/renderable/attribute.d.ts +28 -9
- package/renderable/bind.d.ts +43 -13
- package/renderable/conjunction.d.ts +23 -4
- package/renderable/consumers.d.ts +54 -1
- package/renderable/domnode.d.ts +10 -2
- package/renderable/element.d.ts +50 -3
- package/renderable/empty.d.ts +5 -0
- package/renderable/ensure.d.ts +10 -0
- package/renderable/foreach.d.ts +12 -2
- package/renderable/fragment.d.ts +11 -0
- package/renderable/handler.d.ts +67 -10
- package/renderable/map-signal.d.ts +15 -0
- package/renderable/not-empty.d.ts +13 -1
- package/renderable/onctx.d.ts +9 -2
- package/renderable/oneof.d.ts +138 -16
- package/renderable/onmount.d.ts +8 -0
- package/renderable/onunmount.d.ts +6 -0
- package/renderable/portal.d.ts +12 -3
- package/renderable/providers.d.ts +39 -6
- package/renderable/render.d.ts +39 -3
- package/renderable/repeat.d.ts +11 -2
- package/renderable/style.d.ts +5 -2
- package/renderable/task.d.ts +18 -2
- package/renderable/text.d.ts +18 -5
- package/renderable/when.d.ts +21 -3
- package/std/interpolate.d.ts +56 -5
- package/std/position.d.ts +42 -2
- package/std/signal-utils.d.ts +226 -0
- package/std/signal.d.ts +397 -85
- package/types/aria-attributes.d.ts +5 -0
- package/types/css-styles.d.ts +11 -0
- package/types/domain.d.ts +69 -3
- package/types/html-attributes.d.ts +10 -0
- package/types/html-events.d.ts +5 -0
- package/types/html-tags.d.ts +5 -0
- package/types/mathml-attributes.d.ts +5 -0
- package/types/mathml-tags.d.ts +4 -0
- package/types/svg-attributes.d.ts +5 -0
- package/types/svg-tags.d.ts +5 -0
package/std/signal.d.ts
CHANGED
|
@@ -1,137 +1,449 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Value } from '../types/domain';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents any type of signal.
|
|
5
|
+
* It can be a Signal, Prop, or Computed.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam T - The type of value the signal holds.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
4
10
|
export type AnySignal<T = any> = Signal<T> | Prop<T> | Computed<T>;
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
12
|
+
* Represents a type that maps each property of `T` to a `Signal` of its corresponding type.
|
|
13
|
+
* @typeParam T - The type of the object.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type AtGetter<T> = {
|
|
17
|
+
[K in keyof T]-?: Signal<T[K]>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Represents a signal that holds a value and notifies its listeners when the value changes.
|
|
21
|
+
* @typeParam T - The type of the value held by the signal.
|
|
22
|
+
* @public
|
|
7
23
|
*/
|
|
8
24
|
export declare class Signal<T> {
|
|
9
25
|
readonly equals: (a: T, b: T) => boolean;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Creates a Signal that holds the result of a Promise.
|
|
28
|
+
*
|
|
29
|
+
* @typeParam O - The type of the value returned by the Promise.
|
|
30
|
+
* @param promise - The Promise to use to feed the Signal.
|
|
31
|
+
* @param init - The initial value of the Signal before the Promise resolves.
|
|
32
|
+
* @param recover - A function to recover from Promise rejection and provide an alternative value for the Signal.
|
|
33
|
+
* @param equals - A function to compare two values of type O for equality. Defaults to strict equality (===).
|
|
34
|
+
* @returns - A Signal that represents the result of the Promise.
|
|
35
|
+
*/
|
|
36
|
+
static readonly ofPromise: <O>(promise: Promise<O>, init: O, recover?: (error: unknown) => O, equals?: (a: O, b: O) => boolean) => Signal<O>;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a value is a Signal.
|
|
39
|
+
*
|
|
40
|
+
* @param value - The value to check.
|
|
41
|
+
* @returns `true` if the value is a Signal, `false` otherwise.
|
|
42
|
+
*/
|
|
43
|
+
static readonly is: <O = unknown>(value: unknown) => value is Signal<O>;
|
|
44
|
+
/**
|
|
45
|
+
* Wraps a value or a Signal instance into a Signal.
|
|
46
|
+
* If the value is already a Signal, it returns the value itself.
|
|
47
|
+
* If the value is not a Signal, it creates a new Signal instance with the given value.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam O - The type of the value.
|
|
50
|
+
* @param value - The value or Signal instance to wrap.
|
|
51
|
+
* @param equals - A function that determines if two values are equal. Defaults to strict equality (===).
|
|
52
|
+
* @returns A Signal instance.
|
|
53
|
+
*/
|
|
54
|
+
static readonly wrap: <O>(value: O | Signal<O>, equals?: (a: O, b: O) => boolean) => Signal<O>;
|
|
55
|
+
/**
|
|
56
|
+
* Wraps a value in a `Signal` if it is not already a `Signal`.
|
|
57
|
+
* If the value is `null` or `undefined`, it returns `null` or `undefined` respectively.
|
|
58
|
+
* @param value - The value to wrap or check.
|
|
59
|
+
* @returns The wrapped value if it is not `null` or `undefined`, otherwise `null` or `undefined`.
|
|
60
|
+
*/
|
|
61
|
+
static readonly maybeWrap: <O>(value: O | Signal<O> | null | undefined) => Signal<O> | undefined | null;
|
|
62
|
+
/**
|
|
63
|
+
* Unwraps a value from a `Signal` if it is a `Signal`, otherwise returns the value as is.
|
|
64
|
+
*
|
|
65
|
+
* @param value - The value to unwrap.
|
|
66
|
+
* @returns The unwrapped value.
|
|
67
|
+
*/
|
|
68
|
+
static readonly unwrap: <O>(value: Signal<O> | O) => O;
|
|
69
|
+
/**
|
|
70
|
+
* Maps the value of a `Signal` or a regular value using the provided mapping function.
|
|
71
|
+
* If the input value is a `Signal`, the mapping function is applied to its value.
|
|
72
|
+
* If the input value is not a `Signal`, the mapping function is directly applied to the value.
|
|
73
|
+
*
|
|
74
|
+
* @param value - The input value to be mapped.
|
|
75
|
+
* @param fn - The mapping function to be applied to the value.
|
|
76
|
+
* @returns A new `Signal` with the mapped value if the input value is a `Signal`,
|
|
77
|
+
* otherwise, the result of applying the mapping function to the value.
|
|
78
|
+
*
|
|
79
|
+
* @typeParam N - The type of the input value.
|
|
80
|
+
* @typeParam O - The type of the mapped value.
|
|
81
|
+
*/
|
|
82
|
+
static readonly map: <N, O>(value: Value<N>, fn: (value: N) => O) => Value<O>;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
protected readonly $__signal__ = true;
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
17
90
|
protected _value: T;
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
18
94
|
protected readonly _derivatives: Array<Computed<unknown>>;
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
19
98
|
protected readonly _onValueListeners: Array<(value: T) => void>;
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
20
102
|
protected readonly _onDisposeListeners: Array<() => void>;
|
|
103
|
+
/**
|
|
104
|
+
* Represents a signal with a value of type T.
|
|
105
|
+
*
|
|
106
|
+
* @param value - The initial value of the signal.
|
|
107
|
+
* @param equals - A function that determines whether two values of type T are equal.
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
21
110
|
constructor(value: T, equals: (a: T, b: T) => boolean);
|
|
111
|
+
/**
|
|
112
|
+
* Gets the current value of the signal.
|
|
113
|
+
* @returns The current value of the signal.
|
|
114
|
+
*/
|
|
22
115
|
readonly get: () => T;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the value of the signal.
|
|
118
|
+
* @returns The current value of the signal.
|
|
119
|
+
*/
|
|
23
120
|
get value(): T;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if the signal has any registered listeners.
|
|
123
|
+
* @returns `true` if the signal has listeners, `false` otherwise.
|
|
124
|
+
*/
|
|
24
125
|
readonly hasListeners: () => boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Registers a listener function to be called whenever the value of the signal changes.
|
|
128
|
+
* The listener function will be immediately called with the current value of the signal.
|
|
129
|
+
* Returns a function that can be called to unregister the listener.
|
|
130
|
+
*
|
|
131
|
+
* @param listener - The listener function to be called when the value of the signal changes.
|
|
132
|
+
*/
|
|
25
133
|
readonly on: (listener: (value: T) => void) => () => void;
|
|
134
|
+
/**
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
26
137
|
protected readonly _setAndNotify: (newV: T, forceNotifications: boolean) => void;
|
|
138
|
+
/**
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
27
141
|
protected _disposed: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Checks whether the signal is disposed.
|
|
144
|
+
* @returns True if the signal is disposed, false otherwise.
|
|
145
|
+
*/
|
|
28
146
|
readonly isDisposed: () => boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Adds a listener function to be called when the object is disposed.
|
|
149
|
+
* @param listener - The listener function to be called when the object is disposed.
|
|
150
|
+
* @returns A function that can be called to remove the listener.
|
|
151
|
+
*/
|
|
29
152
|
readonly onDispose: (listener: () => void) => void;
|
|
153
|
+
/**
|
|
154
|
+
* Disposes the signal, releasing any resources associated with it.
|
|
155
|
+
*/
|
|
30
156
|
readonly dispose: () => void;
|
|
31
|
-
|
|
32
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Returns a new Computed instance that applies the given mapping function to the value of this Signal.
|
|
159
|
+
* The mapping function is called whenever the value of this Signal changes.
|
|
160
|
+
*
|
|
161
|
+
* @typeParam O - The type of the mapped value.
|
|
162
|
+
* @param fn - The mapping function to apply to the value of this Signal.
|
|
163
|
+
* @param equals - Optional equality function to determine if two mapped values are equal.
|
|
164
|
+
* @returns - A new Computed instance with the mapped value.
|
|
165
|
+
*/
|
|
166
|
+
readonly map: <O>(fn: (value: T) => O, equals?: (a: O, b: O) => boolean) => Computed<O>;
|
|
167
|
+
/**
|
|
168
|
+
* Returns a new Signal that applies the given function to the value of the current Signal,
|
|
169
|
+
* and then flattens the resulting Signal.
|
|
170
|
+
*
|
|
171
|
+
* @typeParam O - The type of the value emitted by the resulting Signal.
|
|
172
|
+
* @param fn - The function to apply to the value of the current Signal.
|
|
173
|
+
* @param equals - A function that determines whether two values of type O are equal.
|
|
174
|
+
* Defaults to a strict equality check (===).
|
|
175
|
+
* @returns A new Signal that emits the values of the resulting Signal.
|
|
176
|
+
*/
|
|
177
|
+
readonly flatMap: <O>(fn: (value: T) => Signal<O>, equals?: (a: O, b: O) => boolean) => Computed<O>;
|
|
178
|
+
/**
|
|
179
|
+
* Invokes a callback function with the current value of the signal, without modifying the signal.
|
|
180
|
+
*
|
|
181
|
+
* @param fn - The callback function to be invoked with the current value of the signal.
|
|
182
|
+
* @returns A new signal that emits the same value as the original signal and invokes the callback function.
|
|
183
|
+
*/
|
|
33
184
|
readonly tap: (fn: (value: T) => void) => Computed<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Returns a new Signal that emits the value at the specified key of the current value.
|
|
187
|
+
*
|
|
188
|
+
* @param key - The key of the value to retrieve.
|
|
189
|
+
* @returns A new Signal that emits the value at the specified key.
|
|
190
|
+
*/
|
|
34
191
|
readonly at: <K extends keyof T>(key: K) => Signal<T[K]>;
|
|
35
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Represents a collection of signals for each key in the value of the signal.
|
|
194
|
+
* @typeParam T - The type of the signals.
|
|
195
|
+
*/
|
|
196
|
+
readonly $: AtGetter<T>;
|
|
36
197
|
readonly filter: (fn: (value: T) => boolean, startValue?: T) => Computed<T>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Returns a new Computed object that applies the provided mapping function to the value of this Signal,
|
|
200
|
+
* and filters out values that are `undefined` or `null`.
|
|
201
|
+
*
|
|
202
|
+
* @typeParam O - The type of the mapped value.
|
|
203
|
+
* @param fn - The mapping function to apply to the value of this Signal.
|
|
204
|
+
* @param startValue - The initial value for the Computed object.
|
|
205
|
+
* @param equals - Optional equality function to determine if two values are equal.
|
|
206
|
+
* @returns - A new Computed object with the mapped and filtered values.
|
|
207
|
+
*/
|
|
208
|
+
readonly filterMap: <O>(fn: (value: T) => O | undefined | null, startValue: O, equals?: (a: O, b: O) => boolean) => Computed<O>;
|
|
209
|
+
/**
|
|
210
|
+
* Maps the values emitted by the signal to a new value asynchronously using the provided function.
|
|
211
|
+
* If the function throws an error, it will be caught and logged.
|
|
212
|
+
* If a recovery function is provided, it will be called with the error and its return value will be used as the mapped value.
|
|
213
|
+
* If no recovery function is provided, the error will be logged as an unhandled promise rejection.
|
|
214
|
+
*
|
|
215
|
+
* @typeParam O - The type of the mapped value.
|
|
216
|
+
* @param fn - The function to map the values emitted by the signal.
|
|
217
|
+
* @param alt - The alternate value to use if the signal is disposed or the mapping function throws an error.
|
|
218
|
+
* @param recover - The recovery function to handle errors thrown by the mapping function.
|
|
219
|
+
* @param equals - The equality function to compare the mapped values for equality.
|
|
220
|
+
* @returns A property that holds the mapped value and can be observed for changes.
|
|
221
|
+
*/
|
|
222
|
+
readonly mapAsync: <O>(fn: (value: T) => Promise<O>, alt: O, recover?: (error: unknown) => O, equals?: (a: O, b: O) => boolean) => Prop<O>;
|
|
223
|
+
/**
|
|
224
|
+
* Maps the values of the signal using the provided function `fn`, and returns a new signal
|
|
225
|
+
* containing the mapped values. If the mapped value is `undefined` or `null`, it is replaced
|
|
226
|
+
* with the provided `alt` value.
|
|
227
|
+
*
|
|
228
|
+
* @typeParam O - The type of the mapped value.
|
|
229
|
+
* @param fn - The function used to map the values of the signal.
|
|
230
|
+
* @param alt - The alternative value to use when the mapped value is `undefined` or `null`.
|
|
231
|
+
* @returns A new signal containing the mapped values.
|
|
232
|
+
*/
|
|
233
|
+
readonly mapMaybe: <O>(fn: (value: T) => O | undefined | null, alt: O) => Computed<O>;
|
|
234
|
+
/**
|
|
235
|
+
* Feeds a property into the signal and sets up disposal behavior.
|
|
236
|
+
* @param prop - The property to feed into the signal.
|
|
237
|
+
* @param autoDisposeProp - Determines whether the property should be automatically disposed when the signal is disposed.
|
|
238
|
+
* @returns The input property.
|
|
239
|
+
*/
|
|
40
240
|
readonly feedProp: (prop: Prop<T>, autoDisposeProp?: boolean) => Prop<T>;
|
|
241
|
+
/**
|
|
242
|
+
* Derives a new property from the current signal.
|
|
243
|
+
* @param autoDisposeProp - Determines whether the derived property should be automatically disposed.
|
|
244
|
+
* @returns The derived property.
|
|
245
|
+
*/
|
|
41
246
|
readonly deriveProp: (autoDisposeProp?: boolean) => Prop<T>;
|
|
247
|
+
/**
|
|
248
|
+
* Returns a signal that emits the count of values received so far.
|
|
249
|
+
* @returns A signal that emits the count of values received so far.
|
|
250
|
+
*/
|
|
42
251
|
readonly count: () => Computed<number>;
|
|
43
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Adds a computed value as a derivative of the signal.
|
|
254
|
+
* When the computed value is disposed, it is automatically removed from the derivatives list.
|
|
255
|
+
* Additionally, when the computed value is disposed, it sets the signal as dirty.
|
|
256
|
+
* @param computed - The computed value to add as a derivative.
|
|
257
|
+
*/
|
|
258
|
+
readonly setDerivative: <O>(computed: Computed<O>) => void;
|
|
44
259
|
}
|
|
45
260
|
/**
|
|
46
|
-
*
|
|
261
|
+
* Represents a computed signal that derives its value from a function.
|
|
262
|
+
* It extends the `Signal` class.
|
|
263
|
+
*
|
|
264
|
+
* @typeParam T - The type of the computed value.
|
|
265
|
+
* @public
|
|
47
266
|
*/
|
|
48
267
|
export declare class Computed<T> extends Signal<T> {
|
|
49
268
|
private readonly _fn;
|
|
269
|
+
/**
|
|
270
|
+
* Checks if a value is an instance of `Computed`.
|
|
271
|
+
*
|
|
272
|
+
* @param value - The value to check.
|
|
273
|
+
* @returns `true` if the value is an instance of `Computed`, `false` otherwise.
|
|
274
|
+
*/
|
|
50
275
|
static is<T = unknown>(value: unknown): value is Computed<T>;
|
|
51
|
-
|
|
276
|
+
/**
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
protected readonly $__computed__ = true;
|
|
280
|
+
/**
|
|
281
|
+
* @internal
|
|
282
|
+
*/
|
|
52
283
|
protected _isDirty: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Represents a Signal object.
|
|
286
|
+
* @param _fn - The function that returns the value of the signal.
|
|
287
|
+
* @param equals - The function used to compare two values of type T for equality.
|
|
288
|
+
*/
|
|
53
289
|
constructor(_fn: () => T, equals: (a: T, b: T) => boolean);
|
|
290
|
+
/**
|
|
291
|
+
* Marks the signal as dirty, indicating that its value has changed and needs to be recalculated.
|
|
292
|
+
* If the signal is already dirty or disposed, this method does nothing.
|
|
293
|
+
* It also marks all dependent signals as dirty and schedules a notification to update their values.
|
|
294
|
+
*/
|
|
54
295
|
readonly setDirty: () => void;
|
|
296
|
+
/**
|
|
297
|
+
* @internal
|
|
298
|
+
*/
|
|
55
299
|
protected _scheduleCount: number;
|
|
56
|
-
|
|
300
|
+
/**
|
|
301
|
+
* Schedules a notification to be executed asynchronously.
|
|
302
|
+
* If the signal is dirty, it will be updated and notified.
|
|
303
|
+
* @internal
|
|
304
|
+
*/
|
|
305
|
+
protected readonly _scheduleNotify: () => void;
|
|
306
|
+
/** {@inheritDoc Signal.get} */
|
|
57
307
|
readonly get: () => T;
|
|
308
|
+
/** {@inheritDoc Signal.value} */
|
|
58
309
|
get value(): T;
|
|
59
310
|
}
|
|
60
|
-
|
|
311
|
+
/**
|
|
312
|
+
* Represents the data passed to a reducer effect.
|
|
313
|
+
*
|
|
314
|
+
* @typeParam S - The type of the state.
|
|
315
|
+
* @typeParam A - The type of the action.
|
|
316
|
+
* @public
|
|
317
|
+
*/
|
|
318
|
+
export type ReducerEffectData<S, A> = {
|
|
319
|
+
/**
|
|
320
|
+
* The previous state before the action was dispatched.
|
|
321
|
+
*/
|
|
61
322
|
previousState: S;
|
|
323
|
+
/**
|
|
324
|
+
* The current state after the action was dispatched.
|
|
325
|
+
*/
|
|
62
326
|
state: S;
|
|
327
|
+
/**
|
|
328
|
+
* The action that was dispatched.
|
|
329
|
+
*/
|
|
63
330
|
action: A;
|
|
331
|
+
/**
|
|
332
|
+
* A function to dispatch a new action.
|
|
333
|
+
*/
|
|
64
334
|
dispatch: (action: A) => void;
|
|
65
|
-
}
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Represents a function that defines a reducer effect.
|
|
338
|
+
* A reducer effect is a function that takes in the previous state, current state, action, and a dispatch function,
|
|
339
|
+
* and performs some side effects based on the state and action.
|
|
340
|
+
*
|
|
341
|
+
* @typeParam S - The type of the state.
|
|
342
|
+
* @typeParam A - The type of the action.
|
|
343
|
+
*
|
|
344
|
+
* @param data - An object containing the previous state, current state, action, and dispatch function.
|
|
345
|
+
* @public
|
|
346
|
+
*/
|
|
347
|
+
export type ReducerEffect<S, A> = (data: ReducerEffectData<S, A>) => void;
|
|
66
348
|
/**
|
|
67
|
-
*
|
|
349
|
+
* Represents a property signal that holds a value of type T.
|
|
350
|
+
* It extends the `Signal` class.
|
|
351
|
+
*
|
|
352
|
+
* @typeParam T - The type of the property value.
|
|
353
|
+
* @public
|
|
68
354
|
*/
|
|
69
355
|
export declare class Prop<T> extends Signal<T> {
|
|
70
|
-
|
|
71
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Checks if a value is a Prop.
|
|
358
|
+
* @param value - The value to check.
|
|
359
|
+
* @returns `true` if the value is a Prop, `false` otherwise.
|
|
360
|
+
*/
|
|
361
|
+
static is: <T_1 = unknown>(value: unknown) => value is Prop<T_1>;
|
|
362
|
+
/**
|
|
363
|
+
* @internal
|
|
364
|
+
*/
|
|
365
|
+
protected readonly $__prop__ = true;
|
|
366
|
+
/**
|
|
367
|
+
* Changes the value of the property and notifies its listeners.
|
|
368
|
+
*
|
|
369
|
+
* @param value - The new value of the property.
|
|
370
|
+
*/
|
|
72
371
|
readonly set: (value: T) => void;
|
|
372
|
+
/**
|
|
373
|
+
* Updates the value of the signal by applying the provided function to the current value.
|
|
374
|
+
* @param fn - The function to apply to the current value.
|
|
375
|
+
*/
|
|
73
376
|
readonly update: (fn: (value: T) => T) => void;
|
|
377
|
+
/**
|
|
378
|
+
* Creates a reducer function that combines the provided reducer function and effects.
|
|
379
|
+
* @param fn - The reducer function that takes the current state and an action, and returns the new state.
|
|
380
|
+
* @param effects - An array of effects to be executed after the state is updated.
|
|
381
|
+
* @returns A dispatch function that can be used to update the state and trigger the effects.
|
|
382
|
+
*/
|
|
74
383
|
readonly reducer: <A>(fn: (acc: T, value: A) => T, ...effects: ReducerEffect<T, A>[]) => (action: A) => void;
|
|
75
|
-
|
|
384
|
+
/**
|
|
385
|
+
* Creates an isomorphism for the Signal.
|
|
386
|
+
* An isomorphism is a pair of functions that convert values between two types,
|
|
387
|
+
* along with an equality function to compare values of the second type.
|
|
388
|
+
*
|
|
389
|
+
* @param to - A function that converts values from type T to type O.
|
|
390
|
+
* @param from - A function that converts values from type O to type T.
|
|
391
|
+
* @param equals - An optional function that compares values of type O for equality.
|
|
392
|
+
* Defaults to a strict equality check (===).
|
|
393
|
+
* @returns A Prop object representing the isomorphism.
|
|
394
|
+
*/
|
|
395
|
+
readonly iso: <O>(to: (value: T) => O, from: (value: O) => T, equals?: (a: O, b: O) => boolean) => Prop<O>;
|
|
396
|
+
/**
|
|
397
|
+
* Returns a `Prop` that represents the value at the specified key of the current value.
|
|
398
|
+
*
|
|
399
|
+
* @param key - The key of the value to access.
|
|
400
|
+
* @returns A `Prop` that represents the value at the specified key.
|
|
401
|
+
*/
|
|
76
402
|
readonly atProp: <K extends keyof T>(key: K) => Prop<T[K]>;
|
|
403
|
+
/**
|
|
404
|
+
* Access for the current value of the property.
|
|
405
|
+
*/
|
|
77
406
|
get value(): T;
|
|
78
407
|
set value(value: T);
|
|
79
408
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
equals?: (a: T, b: T) => boolean;
|
|
122
|
-
}): Prop<T>;
|
|
123
|
-
export declare function animateOne<T>(signal: Signal<T>, options?: {
|
|
124
|
-
initialValue?: T;
|
|
125
|
-
interpolate?: (start: T, end: T, delta: number) => T;
|
|
126
|
-
duration?: number;
|
|
127
|
-
easing?: (t: number) => number;
|
|
128
|
-
equals?: (a: T, b: T) => boolean;
|
|
129
|
-
}): Prop<T>;
|
|
130
|
-
export type Value<T> = Signal<T> | T;
|
|
131
|
-
export type NValue<T> = Value<T> | Value<T | null> | Value<T | undefined> | Value<T | null | undefined> | null | undefined;
|
|
132
|
-
export type GetValueType<T> = T extends Signal<infer V> ? V : T;
|
|
133
|
-
export type RemoveSignals<T extends Record<string | number | symbol, Value<unknown>>, K extends (string | number | symbol) & keyof T = keyof T> = {
|
|
134
|
-
[k in K]: GetValueType<T[k]>;
|
|
135
|
-
};
|
|
136
|
-
export declare function computedRecord<T extends Record<string, Value<unknown>>, U>(record: T, fn: (value: RemoveSignals<T>) => U): Computed<U>;
|
|
137
|
-
export {};
|
|
409
|
+
/**
|
|
410
|
+
* Creates a computed signal that depends on other signals and updates when any of the dependencies change.
|
|
411
|
+
*
|
|
412
|
+
* @typeParam T - The type of the computed value.
|
|
413
|
+
* @param fn - The function that computes the value.
|
|
414
|
+
* @param dependencies - The array of signals that the computed value depends on.
|
|
415
|
+
* @param equals - The equality function used to compare the previous and current computed values.
|
|
416
|
+
* @returns - The computed signal.
|
|
417
|
+
* @public
|
|
418
|
+
*/
|
|
419
|
+
export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySignal>, equals?: (a: T, b: T) => boolean) => Computed<T>;
|
|
420
|
+
/**
|
|
421
|
+
* Executes the provided function `fn` whenever any of the signals in the `signals` array change.
|
|
422
|
+
* Returns a disposable object that can be used to stop the effect.
|
|
423
|
+
*
|
|
424
|
+
* @param fn - The function to execute when the signals change.
|
|
425
|
+
* @param signals - An array of signals to watch for changes.
|
|
426
|
+
* @returns A disposable object that can be used to stop the effect.
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
export declare const makeEffect: (fn: () => void, signals: Array<AnySignal>) => () => void;
|
|
430
|
+
/**
|
|
431
|
+
* Creates a new Prop object with the specified value and equality function.
|
|
432
|
+
*
|
|
433
|
+
* @typeParam T - The type of the value.
|
|
434
|
+
* @param value - The initial value of the Prop.
|
|
435
|
+
* @param equals - The equality function used to compare values. Defaults to strict equality (===).
|
|
436
|
+
* @returns A new Prop object.
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
export declare const makeProp: <T>(value: T, equals?: (a: T, b: T) => boolean) => Prop<T>;
|
|
440
|
+
/**
|
|
441
|
+
* Creates a signal with the specified initial value and equality function.
|
|
442
|
+
*
|
|
443
|
+
* @typeParam T - The type of the signal value.
|
|
444
|
+
* @param value - The initial value of the signal.
|
|
445
|
+
* @param equals - The equality function used to compare signal values. Defaults to a strict equality check (`===`).
|
|
446
|
+
* @returns A new Signal instance.
|
|
447
|
+
* @public
|
|
448
|
+
*/
|
|
449
|
+
export declare const makeSignal: <T>(value: T, equals?: (a: T, b: T) => boolean) => Signal<T>;
|
package/types/css-styles.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a set of properties or values that are excluded from the CSSStyleDeclaration interface.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
1
6
|
export type ExcludeFromStyle = 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty' | 'parentRule' | 'length' | 'name' | number;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a subset of CSS styles.
|
|
9
|
+
* It is a type that excludes certain properties from the `CSSStyleDeclaration` type.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
2
13
|
export type CSSStyles = Omit<CSSStyleDeclaration, ExcludeFromStyle>;
|
package/types/domain.d.ts
CHANGED
|
@@ -1,14 +1,80 @@
|
|
|
1
1
|
import { DOMContext } from '../dom/dom-context';
|
|
2
|
-
import {
|
|
2
|
+
import { Signal } from '../std/signal';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Represents a function that can be rendered in the DOM.
|
|
6
|
+
* @param ctx - The DOM context for rendering.
|
|
7
|
+
* @returns A function that clears the rendered content.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
4
10
|
export type Renderable = (ctx: DOMContext) => Clear;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a node in the rendering tree.
|
|
13
|
+
* It can be a renderable element, a string value, undefined, null, or an array of renderable elements.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
5
16
|
export type TNode = Renderable | Value<string> | undefined | null | Renderable[];
|
|
17
|
+
/**
|
|
18
|
+
* Represents a function that clears a resource.
|
|
19
|
+
* @param removeTree - A boolean value indicating whether to remove the tree associated with the resource.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
6
22
|
export type Clear = (removeTree: boolean) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Represents a provider mark.
|
|
25
|
+
* @typeParam T - The type of the mark.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
7
28
|
export type ProviderMark<T> = symbol & {
|
|
8
29
|
readonly __type: T;
|
|
9
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Represents a collection of providers.
|
|
33
|
+
* The keys of the record are ProviderMark types, and the values are of unknown type.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
10
36
|
export type Providers = Record<ProviderMark<unknown>, unknown>;
|
|
11
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Represents the size of an object with width and height.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export type Size = {
|
|
42
|
+
/**
|
|
43
|
+
* The width of the object.
|
|
44
|
+
*/
|
|
12
45
|
readonly width: number;
|
|
46
|
+
/**
|
|
47
|
+
* The height of the object.
|
|
48
|
+
*/
|
|
13
49
|
readonly height: number;
|
|
14
|
-
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Represents a value that can either be a `Signal<T>` or a generic type `T`.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export type Value<T> = Signal<T> | T;
|
|
57
|
+
/**
|
|
58
|
+
* Represents a nullable value or a signal of a nullable value.
|
|
59
|
+
* @typeParam T - The type of the value.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export type NValue<T> = Value<T> | Value<T | null> | Value<T | undefined> | Value<T | null | undefined> | null | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the value type of a given Value type.
|
|
65
|
+
* If the type is a `Signal`, it returns the inferred value type.
|
|
66
|
+
* Otherwise, it returns the type itself.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export type GetValueType<T> = T extends Signal<infer V> ? V : T;
|
|
70
|
+
/**
|
|
71
|
+
* Removes signals from a given object type and returns a new object type
|
|
72
|
+
* with only the non-signal properties.
|
|
73
|
+
*
|
|
74
|
+
* @typeParam T - The input object type.
|
|
75
|
+
* @typeParam K - The keys of the input object type to keep (optional).
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export type RemoveSignals<T extends Record<string | number | symbol, Value<unknown>>, K extends (string | number | symbol) & keyof T = keyof T> = {
|
|
79
|
+
[k in K]: GetValueType<T[k]>;
|
|
80
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the HTML attributes that can be used in an HTML element.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
1
6
|
export type HTMLAttributes = {
|
|
2
7
|
accept: string;
|
|
3
8
|
'accept-charset': string;
|
|
@@ -113,4 +118,9 @@ export type HTMLAttributes = {
|
|
|
113
118
|
innerHTML: string;
|
|
114
119
|
outerHTML: string;
|
|
115
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* Represents the possible input types for HTML input elements.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
116
126
|
export type InputTypes = 'text' | 'number' | 'checkbox' | 'radio' | 'file' | 'password' | 'button' | 'submit' | 'reset' | 'date' | 'range' | 'color' | 'hidden' | 'image' | 'month' | 'time' | 'week' | 'email' | 'tel' | 'url' | 'search' | 'datetime-local';
|