@tempots/dom 20.0.0 → 20.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/dom",
3
- "version": "20.0.0",
3
+ "version": "20.1.0",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,13 +1,13 @@
1
- import { TNode, Renderable } from '../types/domain';
1
+ import { TNode, Renderable, Value } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
3
  /**
4
4
  * Represents a function that ensures a signal has a value before rendering a TNode.
5
5
  *
6
6
  * @typeParam T - The type of the signal value.
7
- * @param signal - The signal to ensure has a value.
7
+ * @param value - The signal or literal that may hold a value of type T or null or undefined.
8
8
  * @param then - The function that returns a TNode when the signal has a value. It takes a signal of the non-nullable type of T.
9
9
  * @param otherwise - The function that returns a TNode when the signal does not have a value.
10
10
  * @returns A renderable function that ensures the signal has a value before rendering a TNode.
11
11
  * @public
12
12
  */
13
- export declare const Ensure: <T>(signal: Signal<T | null> | Signal<T | undefined> | Signal<T | null | undefined>, then: (value: Signal<NonNullable<T>>) => TNode, otherwise?: () => TNode) => Renderable;
13
+ export declare const Ensure: <T>(value: Value<T | null> | Value<T | undefined> | Value<T | null | undefined>, then: (value: Signal<NonNullable<T>>) => TNode, otherwise?: () => TNode) => Renderable;
@@ -1,14 +1,14 @@
1
- import { TNode, Renderable } from '../types/domain';
1
+ import { TNode, Renderable, Value } from '../types/domain';
2
2
  import { Signal } from '../std/signal';
3
3
  import { ElementPosition } from '../std/position';
4
4
  /**
5
5
  * Renders a list of items based on a signal of arrays.
6
6
  *
7
7
  * @typeParam T - The type of items in the array.
8
- * @param signal - The signal of arrays to iterate over.
8
+ * @param value - The signal of arrays to iterate over.
9
9
  * @param item - The function that renders each item in the array.
10
10
  * @param separator - The function that renders the separator between items.
11
11
  * @returns - The renderable function that renders the list of items.
12
12
  * @public
13
13
  */
14
- export declare const ForEach: <T>(signal: Signal<T[]>, item: (value: Signal<T>, position: Signal<ElementPosition>) => TNode, separator?: (pos: Signal<ElementPosition>) => TNode) => Renderable;
14
+ export declare const ForEach: <T>(value: Value<T[]>, item: (value: Signal<T>, position: Signal<ElementPosition>) => TNode, separator?: (pos: Signal<ElementPosition>) => TNode) => Renderable;
@@ -1,5 +1,4 @@
1
- import { Renderable } from '../types/domain';
2
- import { Signal } from '../std/signal';
1
+ import { Renderable, Value } from '../types/domain';
3
2
  /**
4
3
  * Maps the values emitted by a signal to a renderable function and returns a new renderable function.
5
4
  *
@@ -10,9 +9,9 @@ import { Signal } from '../std/signal';
10
9
  * changes to a state that requires a different renderable function.
11
10
  *
12
11
  * @typeParam T - The type of values emitted by the signal.
13
- * @param signal - The signal to map.
12
+ * @param vlaue - The signal or value to map.
14
13
  * @param fn - The function to map the signal values to renderable functions.
15
14
  * @returns - A new renderable function that represents the mapped signal.
16
15
  * @public
17
16
  */
18
- export declare const MapSignal: <T>(signal: Signal<T>, fn: (value: T) => Renderable) => Renderable;
17
+ export declare const MapSignal: <T>(value: Value<T>, fn: (value: T) => Renderable) => Renderable;
@@ -1,15 +1,14 @@
1
- import { Signal } from '../std/signal';
2
- import { Renderable } from '../types/domain';
1
+ import { Renderable, Value } from '../types/domain';
3
2
  /**
4
3
  * Returns a renderable component that displays the given `display` component
5
4
  * when the `signal` contains a non-empty array, and the `whenEmpty` component
6
5
  * otherwise.
7
6
  *
8
7
  * @typeParam T - The type of elements in the array.
9
- * @param signal - The signal containing the array.
8
+ * @param value - The signal or literal containing the array.
10
9
  * @param display - The component to display when the array is non-empty.
11
10
  * @param whenEmpty- The component to display when the array is empty.
12
11
  * @returns - The renderable component.
13
12
  * @public
14
13
  */
15
- export declare const NotEmpty: <T>(signal: Signal<T[]>, display: Renderable, whenEmpty?: Renderable) => Renderable;
14
+ export declare const NotEmpty: <T>(value: Value<T[]>, display: Renderable, whenEmpty?: Renderable) => Renderable;
@@ -1,5 +1,5 @@
1
1
  import { Signal } from '../std/signal';
2
- import { Renderable, TNode } from '../types/domain';
2
+ import { Renderable, TNode, Value } from '../types/domain';
3
3
  /**
4
4
  * Represents a set of options for a one-of type.
5
5
  * @typeParam T - The type of the options.
@@ -14,12 +14,12 @@ export type OneOfOptions<T extends Record<string, unknown>> = {
14
14
  * The signal value should be an object with a single key that matches one of the keys in the `cases` object.
15
15
  *
16
16
  * @typeParam T - The type of the signal value.
17
- * @param match - The signal to match against.
17
+ * @param match - The signal or value to match against.
18
18
  * @param cases - An object containing the different cases to render based on the signal value.
19
19
  * @returns A renderable function that renders the appropriate component based on the signal value.
20
20
  * @public
21
21
  */
22
- export declare const OneOf: <T extends Record<string, unknown>>(match: Signal<T>, cases: OneOfOptions<T>) => Renderable;
22
+ export declare const OneOf: <T extends Record<string, unknown>>(match: Value<T>, cases: OneOfOptions<T>) => Renderable;
23
23
  /**
24
24
  * Represents the options for a one-of field.
25
25
  *
@@ -39,13 +39,13 @@ export type OneOfFieldOptions<T extends {
39
39
  *
40
40
  * @typeParam T - The type containing the one-of field.
41
41
  * @typeParam K - The type of the one-of field key.
42
- * @param match - The signal that emits the object containing the one-of field.
42
+ * @param match - The signal or value that emits the object containing the one-of field.
43
43
  * @param field - The key of the one-of field.
44
44
  * @param cases - The options for the different cases of rendering based on the one-of field value.
45
45
  * @returns - The renderable field representing the one-of field.
46
46
  * @public
47
47
  */
48
- export declare const OneOfField: <T extends { [_ in K]: string; }, K extends string>(match: Signal<T>, field: K, cases: OneOfFieldOptions<T, K>) => Renderable;
48
+ export declare const OneOfField: <T extends { [_ in K]: string; }, K extends string>(match: Value<T>, field: K, cases: OneOfFieldOptions<T, K>) => Renderable;
49
49
  /**
50
50
  * The options for a one-of kind field.
51
51
  *
@@ -72,7 +72,7 @@ export type OneOfKindOptions<T extends {
72
72
  */
73
73
  export declare const OneOfKind: <T extends {
74
74
  kind: string;
75
- }>(match: Signal<T>, cases: OneOfKindOptions<T>) => Renderable;
75
+ }>(match: Value<T>, cases: OneOfKindOptions<T>) => Renderable;
76
76
  /**
77
77
  * Represents a mapping of keys to functions that accept a value of type `Signal<V>`
78
78
  * and return a `TNode`.
@@ -94,7 +94,7 @@ export type OneOfTupleOptions<T extends string, V> = {
94
94
  * @returns The result of matching the signal value with the cases.
95
95
  * @public
96
96
  */
97
- export declare const OneOfTuple: <T extends string, V>(match: Signal<[T, V]>, cases: OneOfTupleOptions<T, V>) => Renderable;
97
+ export declare const OneOfTuple: <T extends string, V>(match: Value<[T, V]>, cases: OneOfTupleOptions<T, V>) => Renderable;
98
98
  /**
99
99
  * Represents a mapping of types to rendering functions.
100
100
  * @typeParam T - The type that contains a `type` property.
@@ -120,7 +120,7 @@ export type OneOfTypeOptions<T extends {
120
120
  */
121
121
  export declare const OneOfType: <T extends {
122
122
  type: string;
123
- }>(match: Signal<T>, cases: OneOfTypeOptions<T>) => Renderable;
123
+ }>(match: Value<T>, cases: OneOfTypeOptions<T>) => Renderable;
124
124
  /**
125
125
  * Represents a set of options for a one-of value.
126
126
  * @typeParam T - The type of the one-of value.
@@ -140,4 +140,4 @@ export type OneOfValueOptions<T extends symbol | number | string> = {
140
140
  * @returns - The renderable value representing one of the cases.
141
141
  * @public
142
142
  */
143
- export declare const OneOfValue: <T extends symbol | number | string>(match: Signal<T>, cases: OneOfValueOptions<T>) => Renderable;
143
+ export declare const OneOfValue: <T extends symbol | number | string>(match: Value<T>, cases: OneOfValueOptions<T>) => Renderable;
@@ -1,6 +1,6 @@
1
1
  import { ElementPosition } from '../std/position';
2
2
  import { Signal } from '../std/signal';
3
- import { TNode, Renderable } from '../types/domain';
3
+ import { TNode, Renderable, Value } 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 } 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: Signal<number>, element: (index: Signal<ElementPosition>) => TNode, separator?: (pos: Signal<ElementPosition>) => TNode) => Renderable;
13
+ export declare const Repeat: (times: Value<number>, element: (index: Signal<ElementPosition>) => TNode, separator?: (pos: Signal<ElementPosition>) => TNode) => Renderable;
@@ -1,5 +1,4 @@
1
- import { Renderable, TNode } from '../types/domain';
2
- import { Signal } from '../std/signal';
1
+ import { Renderable, TNode, Value } from '../types/domain';
3
2
  /**
4
3
  * Renders the `then` node if the `condition` is true, otherwise renders the `otherwise` node.
5
4
  *
@@ -9,7 +8,7 @@ import { Signal } from '../std/signal';
9
8
  * @returns The rendered node.
10
9
  * @public
11
10
  */
12
- export declare const When: (condition: Signal<boolean>, then: TNode, otherwise?: TNode) => Renderable;
11
+ export declare const When: (condition: Value<boolean>, then: TNode, otherwise?: TNode) => Renderable;
13
12
  /**
14
13
  * Executes the `then` TNode if the `condition` Signal evaluates to `false`, otherwise executes the `otherwise` TNode.
15
14
  *
@@ -19,4 +18,4 @@ export declare const When: (condition: Signal<boolean>, then: TNode, otherwise?:
19
18
  * @returns The result of executing the `then` or `otherwise` TNode based on the condition.
20
19
  * @public
21
20
  */
22
- export declare const Unless: (condition: Signal<boolean>, then: TNode, otherwise?: TNode) => Renderable;
21
+ export declare const Unless: (condition: Value<boolean>, then: TNode, otherwise?: TNode) => Renderable;
package/std/position.d.ts CHANGED
@@ -41,13 +41,13 @@ export declare class ElementPosition {
41
41
  */
42
42
  get isLast(): boolean;
43
43
  /**
44
- * Checks if the index of the element is even.
45
- * @returns `true` if the index is even, `false` otherwise.
44
+ * Checks if the counter of the element is even.
45
+ * @returns `true` if the counter is even, `false` otherwise.
46
46
  */
47
47
  get isEven(): boolean;
48
48
  /**
49
- * Checks if the index of the element is odd.
50
- * @returns `true` if the index is odd, `false` otherwise.
49
+ * Checks if the counter of the element is odd.
50
+ * @returns `true` if the counter is odd, `false` otherwise.
51
51
  */
52
52
  get isOdd(): boolean;
53
53
  }
package/std/signal.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Value } from '../types/domain';
1
+ import { GetValueTypes, Value } from '../types/domain';
2
2
  /**
3
3
  * Represents any type of signal.
4
4
  * It can be a Signal, Prop, or Computed.
@@ -39,7 +39,7 @@ export declare class Signal<T> {
39
39
  * @param value - The value to check.
40
40
  * @returns `true` if the value is a Signal, `false` otherwise.
41
41
  */
42
- static readonly is: <O = unknown>(value: unknown) => value is Signal<O>;
42
+ static readonly is: <O>(value: O | Signal<O>) => value is Signal<O>;
43
43
  /**
44
44
  * Wraps a value or a Signal instance into a Signal.
45
45
  * If the value is already a Signal, it returns the value itself.
@@ -363,7 +363,7 @@ export declare class Prop<T> extends Signal<T> {
363
363
  * @param value - The value to check.
364
364
  * @returns `true` if the value is a Prop, `false` otherwise.
365
365
  */
366
- static is: <T_1 = unknown>(value: unknown) => value is Prop<T_1>;
366
+ static is: <T_1>(value: T_1 | Prop<T_1> | Signal<T_1> | Computed<T_1>) => value is Prop<T_1>;
367
367
  /**
368
368
  * @internal
369
369
  */
@@ -422,6 +422,16 @@ export declare class Prop<T> extends Signal<T> {
422
422
  * @public
423
423
  */
424
424
  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>;
425
435
  /**
426
436
  * Executes the provided function `fn` whenever any of the signals in the `signals` array change.
427
437
  * Returns a disposable object that can be used to stop the effect.
@@ -432,6 +442,14 @@ export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySigna
432
442
  * @public
433
443
  */
434
444
  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;
435
453
  /**
436
454
  * Creates a new Prop object with the specified value and equality function.
437
455
  *
package/types/domain.d.ts CHANGED
@@ -66,6 +66,13 @@ export type NValue<T> = Value<T> | Value<T | null> | Value<T | undefined> | Valu
66
66
  * @public
67
67
  */
68
68
  export type GetValueType<T> = T extends Signal<infer V> ? V : T;
69
+ /**
70
+ * Gets the value types of a given array of Value types.
71
+ * @public
72
+ */
73
+ export type GetValueTypes<T extends Value<unknown>[]> = {
74
+ [K in keyof T]: GetValueType<T[K]>;
75
+ };
69
76
  /**
70
77
  * Removes signals from a given object type and returns a new object type
71
78
  * with only the non-signal properties.