@tempots/dom 25.1.3 → 26.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": "25.1.3",
3
+ "version": "26.1.0",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -121,6 +121,13 @@ export declare const emitValueAsNumber: (fn: (num: number) => void) => (event: E
121
121
  * @public
122
122
  */
123
123
  export declare const emitValueAsDate: (fn: (date: Date) => void) => (event: Event) => void;
124
+ /**
125
+ * Converts the value of an HTML input element to a Date object or null and emits it using the provided callback function.
126
+ * @param fn - The callback function to be called with the converted Date object or null.
127
+ * @returns A function that can be used as an event handler for input events.
128
+ * @public
129
+ */
130
+ export declare const emitValueAsNullableDate: (fn: (date: Date | null) => void) => (event: Event) => void;
124
131
  /**
125
132
  * Emits the value of an HTMLInputElement as a Date object.
126
133
  * @param fn - The callback function to be called with the emitted Date object.
@@ -128,6 +135,13 @@ export declare const emitValueAsDate: (fn: (date: Date) => void) => (event: Even
128
135
  * @public
129
136
  */
130
137
  export declare const emitValueAsDateTime: (fn: (date: Date) => void) => (event: Event) => void;
138
+ /**
139
+ * Emits the value of an HTMLInputElement as a Date object or null.
140
+ * @param fn - The callback function to be called with the emitted Date object or null.
141
+ * @returns The event handler function.
142
+ * @public
143
+ */
144
+ export declare const emitValueAsNullableDateTime: (fn: (date: Date | null) => void) => (event: Event) => void;
131
145
  /**
132
146
  * Calls the provided function with the checked value of the event target.
133
147
  * @param fn - The function to be called with the checked value.
@@ -11,4 +11,4 @@ import { Renderable, TNode } from '../types/domain';
11
11
  * @returns A Clear function that can be used to clean up any resources associated with the execution.
12
12
  * @public
13
13
  */
14
- export declare const OnBrowserCtx: (fn: (ctx: BrowserContext) => TNode | void) => Renderable;
14
+ export declare const WithBrowserCtx: (fn: (ctx: BrowserContext) => TNode | void) => Renderable;
@@ -11,4 +11,4 @@ import { Renderable, TNode } from '../types/domain';
11
11
  * @returns A Clear function that can be used to clean up any resources associated with the execution.
12
12
  * @public
13
13
  */
14
- export declare const OnCtx: (fn: (ctx: DOMContext) => TNode | void) => Renderable;
14
+ export declare const WithCtx: (fn: (ctx: DOMContext) => TNode | void) => Renderable;
@@ -11,4 +11,4 @@ import { Renderable, TNode } from '../types/domain';
11
11
  * @returns - The renderable function.
12
12
  * @public
13
13
  */
14
- export declare const OnElement: <T extends HTMLElement>(fn: (element: T) => TNode | void) => Renderable;
14
+ export declare const WithElement: <T extends HTMLElement>(fn: (element: T) => TNode | void) => Renderable;
@@ -7,4 +7,4 @@ import { Renderable, TNode } from '../types/domain';
7
7
  * @returns A Clear function that can be used to clean up any resources associated with the execution.
8
8
  * @public
9
9
  */
10
- export declare const OnHeadlessCtx: (fn: (ctx: HeadlessContext) => TNode | void) => Renderable;
10
+ export declare const WithHeadlessCtx: (fn: (ctx: HeadlessContext) => TNode | void) => Renderable;
@@ -0,0 +1,54 @@
1
+ import { ProviderMark, Renderable, TNode } from '../types/domain';
2
+ /**
3
+ * Converts a tuple type `T` into an array of `ProviderMark` types.
4
+ * If `T` is an empty tuple, returns an empty array.
5
+ * If `T` has only one element, returns an array with a single `ProviderMark`.
6
+ * If `T` has more than one element, recursively converts each element into a `ProviderMark` and returns an array.
7
+ * @public
8
+ */
9
+ export type ToArrayOfMarks<T extends unknown[]> = T extends [] ? [] : T extends [infer K] ? [ProviderMark<K>] : T extends [infer K, ...infer R] ? [ProviderMark<K>, ...ToArrayOfMarks<R>] : never;
10
+ /**
11
+ * Represents a type that transforms a tuple of values into an object where each value is associated with a provider mark.
12
+ * @typeParam T - The tuple of values.
13
+ * @returns An object where each value is associated with a provider mark.
14
+ * @public
15
+ */
16
+ export type ToProviders<T extends unknown[]> = T extends [] ? [] : T extends [ProviderMark<infer K>] ? [K] : T extends [ProviderMark<infer K>, ...infer R] ? [K, ...ToProviders<R>] : never;
17
+ export type ProviderOptions = {
18
+ use: <T>(mark: ProviderMark<T>) => T;
19
+ set: <T>(mark: ProviderMark<T>, value: T) => void;
20
+ };
21
+ /**
22
+ * Returns a renderable function that executes the given function with the
23
+ * current DOMContext as argument.
24
+ * The given function can return a TNode or void. If you need to perform some
25
+ * actions when the Renderable is disposed, you can use `OnDispose` as the
26
+ * return value.
27
+ *
28
+ * @param fn - The function to be executed with the DOMContext argument.
29
+ * @returns A Clear function that can be used to clean up any resources associated with the execution.
30
+ * @public
31
+ */
32
+ export declare const WithProvider: (fn: (ctx: ProviderOptions) => TNode | void) => Renderable;
33
+ /**
34
+ * Returns a renderable function that sets a provider for the given provider mark and returns a child renderable.
35
+ *
36
+ * @param mark - The provider mark to set the provider for.
37
+ * @param value - The provider to set for the given mark.
38
+ * @param child - The child renderable to return.
39
+ */
40
+ export declare const SetProvider: <T>(mark: ProviderMark<T>, value: T, child: (provider: T) => TNode) => Renderable;
41
+ /**
42
+ * Returns a renderable function that uses a provider for the given provider mark and returns a child renderable.
43
+ *
44
+ * @param mark - The provider mark to use the provider for.
45
+ * @param child - The child renderable to return.
46
+ */
47
+ export declare const UseProvider: <T>(mark: ProviderMark<T>, child: (provider: T) => TNode) => Renderable;
48
+ /**
49
+ * Returns a renderable function that uses a provider for the given provider marks and returns a child renderable.
50
+ *
51
+ * @param marks - The provider marks to use the providers for.
52
+ * @param child - The child renderable to return.
53
+ */
54
+ export declare const UseProviders: <T extends unknown[]>(...marks: ToArrayOfMarks<T>) => (child: (...providers: ToProviders<T>) => TNode) => Renderable;
@@ -223,4 +223,4 @@ export declare const animateSignal: <T>(signal: Signal<T>, options?: AnimateSign
223
223
  * @returns - The computed value as a signal.
224
224
  * @public
225
225
  */
226
- export declare const makeComputedRecord: <T extends Record<string, Value<unknown>>, O>(record: T, fn: (value: RemoveSignals<T>) => O) => Computed<O>;
226
+ export declare const computedRecord: <T extends Record<string, Value<unknown>>, O>(record: T, fn: (value: RemoveSignals<T>) => O) => Computed<O>;
package/std/signal.d.ts CHANGED
@@ -397,7 +397,7 @@ export declare class Prop<T> extends Signal<T> {
397
397
  * @returns - The computed signal.
398
398
  * @public
399
399
  */
400
- export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySignal>, equals?: (a: T, b: T) => boolean) => Computed<T>;
400
+ export declare const computed: <T>(fn: () => T, dependencies: Array<AnySignal>, equals?: (a: T, b: T) => boolean) => Computed<T>;
401
401
  /**
402
402
  * Executes the provided function `fn` whenever any of the signals in the `signals` array change.
403
403
  * Returns a disposable object that can be used to stop the effect.
@@ -407,7 +407,7 @@ export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySigna
407
407
  * @returns A disposable object that can be used to stop the effect.
408
408
  * @public
409
409
  */
410
- export declare const makeEffect: (fn: () => void, signals: Array<AnySignal>, options?: ListenerOptions) => () => void;
410
+ export declare const effect: (fn: () => void, signals: Array<AnySignal>, options?: ListenerOptions) => () => void;
411
411
  /**
412
412
  * Creates a new Prop object with the specified value and equality function.
413
413
  *
@@ -417,7 +417,7 @@ export declare const makeEffect: (fn: () => void, signals: Array<AnySignal>, opt
417
417
  * @returns A new Prop object.
418
418
  * @public
419
419
  */
420
- export declare const makeProp: <T>(value: T, equals?: (a: T, b: T) => boolean) => Prop<T>;
420
+ export declare const prop: <T>(value: T, equals?: (a: T, b: T) => boolean) => Prop<T>;
421
421
  /**
422
422
  * Creates a signal with the specified initial value and equality function.
423
423
  *
@@ -427,4 +427,4 @@ export declare const makeProp: <T>(value: T, equals?: (a: T, b: T) => boolean) =
427
427
  * @returns A new Signal instance.
428
428
  * @public
429
429
  */
430
- export declare const makeSignal: <T>(value: T, equals?: (a: T, b: T) => boolean) => Signal<T>;
430
+ export declare const signal: <T>(value: T, equals?: (a: T, b: T) => boolean) => Signal<T>;
package/std/value.d.ts CHANGED
@@ -81,7 +81,14 @@ export declare const Value: {
81
81
  * @returns - The computed signal.
82
82
  * @public
83
83
  */
84
- 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>;
84
+ export declare const computedOf: <T extends Value<unknown>[]>(...args: T) => <O>(fn: (...args: GetValueTypes<T>) => O, equals?: (a: O, b: O) => boolean) => import('./signal').Computed<O>;
85
+ /**
86
+ * Joins a set of signals into a single signal that emits a record of the values.
87
+ * @param values - The set of signals to join as a record of `Value`s.
88
+ * @returns A signal that emits a record of the values.
89
+ * @public
90
+ */
91
+ export declare const joinSignals: <T extends Record<string, Value<unknown>>>(values: T) => Signal<{ [K in keyof T]: T[K]; }>;
85
92
  /**
86
93
  * Creates an effect that depends on other signals or literal values and updates when any of the dependencies change.
87
94
  *
@@ -89,4 +96,4 @@ export declare const makeComputedOf: <T extends Value<unknown>[]>(...args: T) =>
89
96
  * @returns A disposable object that can be used to stop the effect.
90
97
  * @public
91
98
  */
92
- export declare const makeEffectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void, options?: ListenerOptions) => () => void;
99
+ export declare const effectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void, options?: ListenerOptions) => () => void;
@@ -1,64 +0,0 @@
1
- import { TNode, Renderable, ProviderMark } from '../types/domain';
2
- /**
3
- * Converts a tuple type `T` into an array of `ProviderMark` types.
4
- * If `T` is an empty tuple, returns an empty array.
5
- * If `T` has only one element, returns an array with a single `ProviderMark`.
6
- * If `T` has more than one element, recursively converts each element into a `ProviderMark` and returns an array.
7
- * @public
8
- */
9
- export type ToArrayOfMarks<T extends unknown[]> = T extends [] ? [] : T extends [infer K] ? [ProviderMark<K>] : T extends [infer K, ...infer R] ? [ProviderMark<K>, ...ToArrayOfMarks<R>] : never;
10
- /**
11
- * Represents a type that transforms a tuple of values into an object where each value is associated with a provider mark.
12
- * @typeParam T - The tuple of values.
13
- * @returns An object where each value is associated with a provider mark.
14
- * @public
15
- */
16
- export type ToProviders<T extends unknown[]> = T extends [] ? object : T extends [infer K] ? {
17
- [_ in ProviderMark<K>]: K;
18
- } : T extends [infer K, ...infer R] ? {
19
- [_ in ProviderMark<K>]: K;
20
- } & ToProviders<R> : never;
21
- /**
22
- * Represents a consumer function that takes a callback function and returns a renderable object.
23
- * The callback function takes a value of type T and returns a TNode.
24
- *
25
- * @typeParam T - The type of the value passed to the callback function.
26
- * @public
27
- */
28
- export type Consumer<T> = (fn: (value: T) => TNode) => Renderable;
29
- /**
30
- * Represents a type that extracts the value types from a record of `Consumer` types.
31
- * @typeParam C - The record of `Consumer` types.
32
- * @public
33
- */
34
- export type UseMany<C extends Record<string, Consumer<unknown>>> = {
35
- [K in keyof C]: C[K] extends Consumer<infer V> ? V : never;
36
- };
37
- /**
38
- * Creates a renderable function that consumes data from multiple consumers and renders the result.
39
- *
40
- * @param providers - An object containing consumer functions.
41
- * @param fn - A function that receives the data from the consumers and returns a renderable function.
42
- * @returns A renderable function that can be called with a DOMContext and returns a cleanup function.
43
- * @public
44
- */
45
- export declare const Use: <C extends Record<string, Consumer<unknown>>>(providers: C, fn: (data: UseMany<C>) => TNode) => Renderable;
46
- /**
47
- * Creates a renderable function that consumes a provider value and renders a `TNode`.
48
- *
49
- * @typeParam T - The type of the provider value.
50
- * @param mark - The provider mark.
51
- * @param fn - The function that takes the provider value and returns a `TNode`.
52
- * @returns A renderable function that consumes the provider value and renders a `TNode`.
53
- * @public
54
- */
55
- export declare const UseProvider: <T>(mark: ProviderMark<T>, fn: (value: T) => TNode) => Renderable;
56
- /**
57
- * Creates a renderable function that consumes providers and renders a TNode.
58
- *
59
- * @param marks - The marks to be converted to an array of marks.
60
- * @param fn - The function that takes providers and returns a TNode.
61
- * @returns A renderable function that consumes providers and renders a TNode.
62
- * @public
63
- */
64
- export declare const UseProviders: <T extends unknown[]>(marks: ToArrayOfMarks<T>, fn: (providers: ToProviders<T>) => TNode) => Renderable;
@@ -1,48 +0,0 @@
1
- import { TNode, Renderable, ProviderMark } from '../types/domain';
2
- /**
3
- * Represents a provider function that takes a `TNode` and returns a `Renderable`.
4
- * @param node - The node to be rendered.
5
- * @returns The rendered output.
6
- * @public
7
- */
8
- export type Provider = (node: TNode) => Renderable;
9
- /**
10
- * Creates a unique symbol that can be used as a provider mark for a specific type `T`.
11
- * The provider mark is used to identify the provider of a value of type `T` in a dependency injection system.
12
- *
13
- * @param identifier - A string that uniquely identifies the provider.
14
- * @returns A unique symbol that can be used as a provider mark.
15
- * @public
16
- */
17
- export declare const makeProviderMark: <T>(identifier: string) => ProviderMark<T>;
18
- /**
19
- * Higher-order function that composes multiple provider functions into a single provider function.
20
- *
21
- * @param providerFns - The provider functions to be composed.
22
- * @returns A new provider function that applies the composed providers in reverse order.
23
- * @public
24
- */
25
- export declare const Provide: <T extends Provider[]>(...providerFns: T) => Provider;
26
- /**
27
- * Creates a renderable with a provider mark and value.
28
- *
29
- * The value will be available to any consumers that request the provider mark.
30
- *
31
- * @typeParam T - The type of the provider value.
32
- * @param mark - The provider mark.
33
- * @param value - The provider value.
34
- * @param child - The child TNode.
35
- * @returns - The renderable with the provider.
36
- * @public
37
- */
38
- export declare const WithProvider: <T>(mark: ProviderMark<T>, value: T, child: TNode) => Renderable;
39
- /**
40
- * Renders the given child with the specified providers.
41
- *
42
- * @typeParam T - The types of the provider values.
43
- * @param providers - An object containing the providers.
44
- * @param child - The child to render.
45
- * @returns The rendered result.
46
- * @public
47
- */
48
- export declare const WithProviders: <T extends unknown[]>(providers: { [K in ProviderMark<T[number]>]: T[number]; }, child: TNode) => Renderable;