@tempots/dom 20.1.0 → 21.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/index.cjs +1 -1
- package/index.d.ts +1 -0
- package/index.js +376 -365
- package/package.json +1 -1
- package/renderable/attribute.d.ts +2 -1
- package/renderable/ensure.d.ts +2 -1
- package/renderable/foreach.d.ts +2 -1
- package/renderable/map-signal.d.ts +2 -1
- package/renderable/not-empty.d.ts +2 -1
- package/renderable/oneof.d.ts +2 -1
- package/renderable/repeat.d.ts +2 -1
- package/renderable/text.d.ts +2 -1
- package/renderable/when.d.ts +2 -1
- package/std/signal-utils.d.ts +2 -1
- package/std/signal.d.ts +0 -58
- package/std/value.d.ts +71 -0
- package/types/domain.d.ts +1 -6
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { NValue, Renderable
|
|
1
|
+
import { NValue, Renderable } from '../types/domain';
|
|
2
|
+
import { Value } from '../std/value';
|
|
2
3
|
/**
|
|
3
4
|
* The `attr` object allows to create any HTML attribute. Either a literal value
|
|
4
5
|
* or `Signal<?>` can be passed as a value. The type of the value is inferred
|
package/renderable/ensure.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TNode, Renderable
|
|
1
|
+
import { TNode, Renderable } from '../types/domain';
|
|
2
2
|
import { Signal } from '../std/signal';
|
|
3
|
+
import { Value } from '../std/value';
|
|
3
4
|
/**
|
|
4
5
|
* Represents a function that ensures a signal has a value before rendering a TNode.
|
|
5
6
|
*
|
package/renderable/foreach.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { TNode, Renderable
|
|
1
|
+
import { TNode, Renderable } from '../types/domain';
|
|
2
2
|
import { Signal } from '../std/signal';
|
|
3
3
|
import { ElementPosition } from '../std/position';
|
|
4
|
+
import { Value } from '../std/value';
|
|
4
5
|
/**
|
|
5
6
|
* Renders a list of items based on a signal of arrays.
|
|
6
7
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Value } from '../std/value';
|
|
2
|
+
import { Renderable } from '../types/domain';
|
|
2
3
|
/**
|
|
3
4
|
* Returns a renderable component that displays the given `display` component
|
|
4
5
|
* when the `signal` contains a non-empty array, and the `whenEmpty` component
|
package/renderable/oneof.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Signal } from '../std/signal';
|
|
2
|
-
import {
|
|
2
|
+
import { Value } from '../std/value';
|
|
3
|
+
import { Renderable, TNode } from '../types/domain';
|
|
3
4
|
/**
|
|
4
5
|
* Represents a set of options for a one-of type.
|
|
5
6
|
* @typeParam T - The type of the options.
|
package/renderable/repeat.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ElementPosition } from '../std/position';
|
|
2
2
|
import { Signal } from '../std/signal';
|
|
3
|
-
import {
|
|
3
|
+
import { Value } from '../std/value';
|
|
4
|
+
import { TNode, Renderable } from '../types/domain';
|
|
4
5
|
/**
|
|
5
6
|
* Creates a renderable function that repeats a given element a specified number of times.
|
|
6
7
|
*
|
package/renderable/text.d.ts
CHANGED
package/renderable/when.d.ts
CHANGED
package/std/signal-utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { RemoveSignals
|
|
1
|
+
import { RemoveSignals } from '../types/domain';
|
|
2
2
|
import { AnySignal, Computed, Prop, Signal } from './signal';
|
|
3
|
+
import { Value } from './value';
|
|
3
4
|
/**
|
|
4
5
|
* Represents a memory store that stores key-value pairs.
|
|
5
6
|
*
|
package/std/signal.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { GetValueTypes, Value } from '../types/domain';
|
|
2
1
|
/**
|
|
3
2
|
* Represents any type of signal.
|
|
4
3
|
* It can be a Signal, Prop, or Computed.
|
|
@@ -40,45 +39,6 @@ export declare class Signal<T> {
|
|
|
40
39
|
* @returns `true` if the value is a Signal, `false` otherwise.
|
|
41
40
|
*/
|
|
42
41
|
static readonly is: <O>(value: O | Signal<O>) => value is Signal<O>;
|
|
43
|
-
/**
|
|
44
|
-
* Wraps a value or a Signal instance into a Signal.
|
|
45
|
-
* If the value is already a Signal, it returns the value itself.
|
|
46
|
-
* If the value is not a Signal, it creates a new Signal instance with the given value.
|
|
47
|
-
*
|
|
48
|
-
* @typeParam O - The type of the value.
|
|
49
|
-
* @param value - The value or Signal instance to wrap.
|
|
50
|
-
* @param equals - A function that determines if two values are equal. Defaults to strict equality (===).
|
|
51
|
-
* @returns A Signal instance.
|
|
52
|
-
*/
|
|
53
|
-
static readonly wrap: <O>(value: O | Signal<O>, equals?: (a: O, b: O) => boolean) => Signal<O>;
|
|
54
|
-
/**
|
|
55
|
-
* Wraps a value in a `Signal` if it is not already a `Signal`.
|
|
56
|
-
* If the value is `null` or `undefined`, it returns `null` or `undefined` respectively.
|
|
57
|
-
* @param value - The value to wrap or check.
|
|
58
|
-
* @returns The wrapped value if it is not `null` or `undefined`, otherwise `null` or `undefined`.
|
|
59
|
-
*/
|
|
60
|
-
static readonly maybeWrap: <O>(value: O | Signal<O> | null | undefined) => Signal<O> | undefined | null;
|
|
61
|
-
/**
|
|
62
|
-
* Unwraps a value from a `Signal` if it is a `Signal`, otherwise returns the value as is.
|
|
63
|
-
*
|
|
64
|
-
* @param value - The value to unwrap.
|
|
65
|
-
* @returns The unwrapped value.
|
|
66
|
-
*/
|
|
67
|
-
static readonly unwrap: <O>(value: Signal<O> | O) => O;
|
|
68
|
-
/**
|
|
69
|
-
* Maps the value of a `Signal` or a regular value using the provided mapping function.
|
|
70
|
-
* If the input value is a `Signal`, the mapping function is applied to its value.
|
|
71
|
-
* If the input value is not a `Signal`, the mapping function is directly applied to the value.
|
|
72
|
-
*
|
|
73
|
-
* @param value - The input value to be mapped.
|
|
74
|
-
* @param fn - The mapping function to be applied to the value.
|
|
75
|
-
* @returns A new `Signal` with the mapped value if the input value is a `Signal`,
|
|
76
|
-
* otherwise, the result of applying the mapping function to the value.
|
|
77
|
-
*
|
|
78
|
-
* @typeParam N - The type of the input value.
|
|
79
|
-
* @typeParam O - The type of the mapped value.
|
|
80
|
-
*/
|
|
81
|
-
static readonly map: <N, O>(value: Value<N>, fn: (value: N) => O) => Value<O>;
|
|
82
42
|
/**
|
|
83
43
|
* @internal
|
|
84
44
|
*/
|
|
@@ -422,16 +382,6 @@ export declare class Prop<T> extends Signal<T> {
|
|
|
422
382
|
* @public
|
|
423
383
|
*/
|
|
424
384
|
export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySignal>, equals?: (a: T, b: T) => boolean) => Computed<T>;
|
|
425
|
-
/**
|
|
426
|
-
* Creates a computed signal that depends on other signals or literal values and updates when any of the dependencies change.
|
|
427
|
-
*
|
|
428
|
-
* @typeParam T - The type of the argument values.
|
|
429
|
-
* @param fn - The function that computes the value.
|
|
430
|
-
* @param equals - The equality function used to compare the previous and current computed values.
|
|
431
|
-
* @returns - The computed signal.
|
|
432
|
-
* @public
|
|
433
|
-
*/
|
|
434
|
-
export declare const makeComputedOf: <T extends Value<unknown>[]>(...args: T) => <O>(fn: (...args: GetValueTypes<T>) => O, equals?: (a: O, b: O) => boolean) => Computed<O>;
|
|
435
385
|
/**
|
|
436
386
|
* Executes the provided function `fn` whenever any of the signals in the `signals` array change.
|
|
437
387
|
* Returns a disposable object that can be used to stop the effect.
|
|
@@ -442,14 +392,6 @@ export declare const makeComputedOf: <T extends Value<unknown>[]>(...args: T) =>
|
|
|
442
392
|
* @public
|
|
443
393
|
*/
|
|
444
394
|
export declare const makeEffect: (fn: () => void, signals: Array<AnySignal>) => () => void;
|
|
445
|
-
/**
|
|
446
|
-
* Creates an effect that depends on other signals or literal values and updates when any of the dependencies change.
|
|
447
|
-
*
|
|
448
|
-
* @param args - The array of signals or literal values that the effect depends on.
|
|
449
|
-
* @returns A disposable object that can be used to stop the effect.
|
|
450
|
-
* @public
|
|
451
|
-
*/
|
|
452
|
-
export declare const makeEffectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void) => void;
|
|
453
395
|
/**
|
|
454
396
|
* Creates a new Prop object with the specified value and equality function.
|
|
455
397
|
*
|
package/std/value.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { GetValueTypes } from '../types/domain';
|
|
2
|
+
import { Signal } from './signal';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a value that can either be a `Signal<T>` or a generic type `T`.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type Value<T> = Signal<T> | T;
|
|
9
|
+
export declare const Value: {
|
|
10
|
+
/**
|
|
11
|
+
* Maps a value or a Signal to a new value.
|
|
12
|
+
* If the value is a Signal, it returns a new Signal with the mapped value.
|
|
13
|
+
* If the value is not a Signal, it returns the mapped value.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - The type of the value.
|
|
16
|
+
* @typeParam U - The type of the new value.
|
|
17
|
+
* @param value - The value or Signal to map.
|
|
18
|
+
* @param fn - The function to map the value.
|
|
19
|
+
* @returns The mapped value.
|
|
20
|
+
*/
|
|
21
|
+
map: <T, U>(value: Value<T>, fn: (value: T) => U) => Value<U>;
|
|
22
|
+
/**
|
|
23
|
+
* Wraps a value or a Signal instance into a Signal.
|
|
24
|
+
* If the value is already a Signal, it returns the value itself.
|
|
25
|
+
* If the value is not a Signal, it creates a new Signal instance with the given value.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam O - The type of the value.
|
|
28
|
+
* @param value - The value or Signal instance to wrap.
|
|
29
|
+
* @param equals - A function that determines if two values are equal. Defaults to strict equality (===).
|
|
30
|
+
* @returns A Signal instance.
|
|
31
|
+
*/
|
|
32
|
+
toSignal: <T>(value: Value<T>, equals?: (a: T, b: T) => boolean) => Signal<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Wraps a value in a `Signal` if it is not already a `Signal`.
|
|
35
|
+
* If the value is `null` or `undefined`, it returns `null` or `undefined` respectively.
|
|
36
|
+
* @param value - The value to wrap or check.
|
|
37
|
+
* @returns The wrapped value if it is not `null` or `undefined`, otherwise `null` or `undefined`.
|
|
38
|
+
*/
|
|
39
|
+
maybeToSignal: <T>(value: Value<T> | undefined | null, equals?: (a: T, b: T) => boolean) => Signal<T> | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the value from a `Signal` or the value itself if it is not a `Signal`.
|
|
42
|
+
* @param value - The value or Signal instance to get the value from.
|
|
43
|
+
* @returns The value.
|
|
44
|
+
*/
|
|
45
|
+
get: <T>(value: Value<T>) => T;
|
|
46
|
+
/**
|
|
47
|
+
* Adds a listener to a `Signal` or calls the listener immediately if it is not a `Signal`.
|
|
48
|
+
* @param value - The value or Signal instance to add the listener to.
|
|
49
|
+
* @param listener - The listener to call when the value changes.
|
|
50
|
+
* @returns A function to remove the listener.
|
|
51
|
+
*/
|
|
52
|
+
on: <T>(value: Value<T>, listener: (value: T) => void) => (() => void);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Creates a computed signal that depends on other signals or literal values and updates when any of the dependencies change.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam T - The type of the argument values.
|
|
58
|
+
* @param fn - The function that computes the value.
|
|
59
|
+
* @param equals - The equality function used to compare the previous and current computed values.
|
|
60
|
+
* @returns - The computed signal.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare const makeComputedOf: <T extends Value<unknown>[]>(...args: T) => <O>(fn: (...args: GetValueTypes<T>) => O, equals?: (a: O, b: O) => boolean) => import('./signal').Computed<O>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates an effect that depends on other signals or literal values and updates when any of the dependencies change.
|
|
66
|
+
*
|
|
67
|
+
* @param args - The array of signals or literal values that the effect depends on.
|
|
68
|
+
* @returns A disposable object that can be used to stop the effect.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export declare const makeEffectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void) => void;
|
package/types/domain.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DOMContext } from '../dom/dom-context';
|
|
2
2
|
import { Signal } from '../std/signal';
|
|
3
|
+
import { Value } from '../std/value';
|
|
3
4
|
/**
|
|
4
5
|
* Represents a function that can be rendered in the DOM.
|
|
5
6
|
* @param ctx - The DOM context for rendering.
|
|
@@ -47,12 +48,6 @@ export type Size = {
|
|
|
47
48
|
*/
|
|
48
49
|
readonly height: number;
|
|
49
50
|
};
|
|
50
|
-
/**
|
|
51
|
-
* Represents a value that can either be a `Signal<T>` or a generic type `T`.
|
|
52
|
-
*
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
export type Value<T> = Signal<T> | T;
|
|
56
51
|
/**
|
|
57
52
|
* Represents a nullable value or a signal of a nullable value.
|
|
58
53
|
* @typeParam T - The type of the value.
|