@tempots/dom 20.1.0 → 22.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 +2 -1
- package/index.js +490 -477
- package/package.json +1 -1
- package/renderable/attribute.d.ts +2 -1
- package/renderable/conjunction.d.ts +1 -1
- package/renderable/ensure.d.ts +2 -1
- package/renderable/foreach.d.ts +4 -3
- 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 +4 -4
- package/renderable/text.d.ts +2 -1
- package/renderable/when.d.ts +2 -1
- package/std/{position.d.ts → element-position.d.ts} +25 -22
- package/std/signal-utils.d.ts +2 -1
- package/std/signal.d.ts +0 -58
- package/std/value.d.ts +78 -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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Signal } from '../std/signal';
|
|
2
2
|
import { Renderable, TNode } from '../types/domain';
|
|
3
|
-
import { ElementPosition } from '../std/position';
|
|
3
|
+
import { ElementPosition } from '../std/element-position';
|
|
4
4
|
/**
|
|
5
5
|
* Options for configuring a conjunction.
|
|
6
6
|
* @public
|
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
|
-
import { ElementPosition } from '../std/position';
|
|
3
|
+
import { ElementPosition } from '../std/element-position';
|
|
4
|
+
import { Value } from '../std/value';
|
|
4
5
|
/**
|
|
5
6
|
* Renders a list of items based on a signal of arrays.
|
|
6
7
|
*
|
|
@@ -11,4 +12,4 @@ import { ElementPosition } from '../std/position';
|
|
|
11
12
|
* @returns - The renderable function that renders the list of items.
|
|
12
13
|
* @public
|
|
13
14
|
*/
|
|
14
|
-
export declare const ForEach: <T>(value: Value<T[]>, item: (value: Signal<T>, position:
|
|
15
|
+
export declare const ForEach: <T>(value: Value<T[]>, item: (value: Signal<T>, position: ElementPosition) => TNode, separator?: (pos: ElementPosition) => TNode) => Renderable;
|
|
@@ -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,6 @@
|
|
|
1
|
-
import { ElementPosition } from '../std/position';
|
|
2
|
-
import {
|
|
3
|
-
import { TNode, Renderable
|
|
1
|
+
import { ElementPosition } from '../std/element-position';
|
|
2
|
+
import { Value } from '../std/value';
|
|
3
|
+
import { TNode, Renderable } from '../types/domain';
|
|
4
4
|
/**
|
|
5
5
|
* Creates a renderable function that repeats a given element a specified number of times.
|
|
6
6
|
*
|
|
@@ -10,4 +10,4 @@ import { TNode, Renderable, Value } from '../types/domain';
|
|
|
10
10
|
* @returns A renderable function that renders the repeated elements.
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export declare const Repeat: (times: Value<number>, element: (index:
|
|
13
|
+
export declare const Repeat: (times: Value<number>, element: (index: ElementPosition) => TNode, separator?: (pos: ElementPosition) => TNode) => Renderable;
|
package/renderable/text.d.ts
CHANGED
package/renderable/when.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Signal } from './signal';
|
|
1
2
|
/**
|
|
2
3
|
* Represents the position of an element in a collection.
|
|
3
4
|
*
|
|
4
5
|
* @public
|
|
5
6
|
*/
|
|
6
7
|
export declare class ElementPosition {
|
|
8
|
+
#private;
|
|
7
9
|
/**
|
|
8
10
|
* The index of the element.
|
|
9
11
|
*/
|
|
@@ -11,7 +13,26 @@ export declare class ElementPosition {
|
|
|
11
13
|
/**
|
|
12
14
|
* The total number of elements in the collection.
|
|
13
15
|
*/
|
|
14
|
-
readonly total: number
|
|
16
|
+
readonly total: Signal<number>;
|
|
17
|
+
/**
|
|
18
|
+
* The counter of the element starting from 1.
|
|
19
|
+
*/
|
|
20
|
+
readonly counter: number;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if the element is the first element in the collection.
|
|
23
|
+
* @returns `true` if the element is the first element, `false` otherwise.
|
|
24
|
+
*/
|
|
25
|
+
readonly isFirst: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the counter of the element is even.
|
|
28
|
+
* @returns `true` if the counter is even, `false` otherwise.
|
|
29
|
+
*/
|
|
30
|
+
readonly isEven: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the counter of the element is odd.
|
|
33
|
+
* @returns `true` if the counter is odd, `false` otherwise.
|
|
34
|
+
*/
|
|
35
|
+
readonly isOdd: boolean;
|
|
15
36
|
/**
|
|
16
37
|
* Creates a new instance of `ElementPosition`.
|
|
17
38
|
* @param index - The index of the element.
|
|
@@ -25,29 +46,11 @@ export declare class ElementPosition {
|
|
|
25
46
|
/**
|
|
26
47
|
* The total number of elements in the collection.
|
|
27
48
|
*/
|
|
28
|
-
total: number);
|
|
29
|
-
/**
|
|
30
|
-
* Gets the counter of the element.
|
|
31
|
-
*/
|
|
32
|
-
get counter(): number;
|
|
33
|
-
/**
|
|
34
|
-
* Checks if the element is the first element in the collection.
|
|
35
|
-
* @returns `true` if the element is the first element, `false` otherwise.
|
|
36
|
-
*/
|
|
37
|
-
get isFirst(): boolean;
|
|
49
|
+
total: Signal<number>);
|
|
38
50
|
/**
|
|
39
51
|
* Checks if the element is the last element in the collection.
|
|
40
52
|
* @returns `true` if the element is the last element, `false` otherwise.
|
|
41
53
|
*/
|
|
42
|
-
get isLast(): boolean
|
|
43
|
-
|
|
44
|
-
* Checks if the counter of the element is even.
|
|
45
|
-
* @returns `true` if the counter is even, `false` otherwise.
|
|
46
|
-
*/
|
|
47
|
-
get isEven(): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Checks if the counter of the element is odd.
|
|
50
|
-
* @returns `true` if the counter is odd, `false` otherwise.
|
|
51
|
-
*/
|
|
52
|
-
get isOdd(): boolean;
|
|
54
|
+
get isLast(): Signal<boolean>;
|
|
55
|
+
readonly dispose: () => void;
|
|
53
56
|
}
|
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,78 @@
|
|
|
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
|
+
* Disposes of a value or a Signal.
|
|
55
|
+
* If the value is a Signal, it disposes of the Signal.
|
|
56
|
+
* If the value is not a Signal, it does nothing.
|
|
57
|
+
* @param value - The value or Signal instance to dispose of.
|
|
58
|
+
*/
|
|
59
|
+
dispose: <T>(value: Value<T>) => void;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Creates a computed signal that depends on other signals or literal values and updates when any of the dependencies change.
|
|
63
|
+
*
|
|
64
|
+
* @typeParam T - The type of the argument values.
|
|
65
|
+
* @param fn - The function that computes the value.
|
|
66
|
+
* @param equals - The equality function used to compare the previous and current computed values.
|
|
67
|
+
* @returns - The computed signal.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
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>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates an effect that depends on other signals or literal values and updates when any of the dependencies change.
|
|
73
|
+
*
|
|
74
|
+
* @param args - The array of signals or literal values that the effect depends on.
|
|
75
|
+
* @returns A disposable object that can be used to stop the effect.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
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.
|