@tempots/dom 26.0.0 → 26.2.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": "26.0.0",
3
+ "version": "26.2.0",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,55 +1,7 @@
1
- import { Renderable, TNode } from '../types/domain';
2
- /**
3
- * A provider mark for a signal representing the current appearance type.
4
- * @public
5
- */
6
- export declare const probeMarker: import('..').ProviderMark<(identifier: symbol) => void>;
1
+ import { Provider } from './provider';
7
2
  export type ProbeResolution = 'resolved' | 'timeout';
8
- /**
9
- * Provides a child component with a probe, which can be used to trigger a callback when all probes with the same identifier are resolved.
10
- * To resolve a probe, call the `done` function passed using the `UseProbe` renderable.
11
- *
12
- * @param identifier - The identifier for the probe.
13
- * @param callback - The callback to be triggered when the probe is no longer needed.
14
- * @param child - The child component to be provided with the probe.
15
- * @returns The child component with the probe.
16
- * @public
17
- */
18
- export declare const ProvideProbe: ({ identifier, callback, child, timeout, }: {
19
- identifier: symbol;
3
+ export type ProbeOptions = {
20
4
  callback?: (resolution: ProbeResolution) => void;
21
- child: TNode;
22
5
  timeout?: number;
23
- }) => Renderable;
24
- /**
25
- * Uses a probe, which can be used to trigger a callback when all probes with the same identifier are resolved.
26
- * To resolve a probe, call the `done` function.
27
- *
28
- * @param identifier - The identifier for the probe.
29
- * @param fn - The callback to be triggered when the probe is no longer needed.
30
- * @returns The child component with the probe.
31
- * @public
32
- */
33
- export declare const UseProbe: (identifier: symbol, fn: (done: () => void) => TNode) => Renderable;
34
- /**
35
- * Provides a global probe, which can be used to trigger a callback when all probes with the same identifier are resolved.
36
- * To resolve a probe, call the `done` function passed using the `UseProbe` renderable.
37
- *
38
- * @param callback - The callback to be triggered when the probe is no longer needed.
39
- * @param child - The child component to be provided with the probe.
40
- * @returns The child component with the probe.
41
- * @public
42
- */
43
- export declare const ProvideGlobalProbe: ({ callback, timeout, }: {
44
- callback?: (resolution: ProbeResolution) => void;
45
- timeout?: number;
46
- }, child: TNode) => Renderable;
47
- /**
48
- * Uses a global probe, which can be used to trigger a callback when all probes with the same identifier are resolved.
49
- * To resolve a probe, call the `done` function.
50
- *
51
- * @param fn - The callback to be triggered when the probe is no longer needed.
52
- * @returns The child component with the probe.
53
- * @public
54
- */
55
- export declare const UseGlobalProbe: (fn: (done: () => void) => TNode) => Renderable;
6
+ };
7
+ export declare const makeProbe: (identifier: symbol) => Provider<() => void, ProbeOptions>;
@@ -0,0 +1,73 @@
1
+ import { DOMContext } from '../dom/dom-context';
2
+ import { ProviderMark, Renderable, TNode } from '../types/domain';
3
+ /**
4
+ * Converts a tuple type `T` into an array of `Provider` types.
5
+ * If `T` is an empty tuple, returns an empty array.
6
+ * If `T` has only one element, returns an array with a single `Provider`.
7
+ * If `T` has more than one element, recursively converts each element into a `Provider` and returns an array.
8
+ * @public
9
+ */
10
+ export type ToArrayOfProviders<T extends unknown[]> = T extends [] ? [] : T extends [infer K] ? [Provider<K>] : T extends [infer K, ...infer R] ? [Provider<K>, ...ToArrayOfProviders<R>] : never;
11
+ /**
12
+ * Converts an array of `Provider` types `T` into an array of their corresponding types.
13
+ * @public
14
+ */
15
+ export type ToProviderTypes<T extends unknown[]> = T extends [] ? [] : T extends [Provider<infer K>] ? [K] : T extends [Provider<infer K>, ...infer R] ? [K, ...ToProviderTypes<R>] : never;
16
+ /**
17
+ * Represents a provider for a specific type `T`.
18
+ * @public
19
+ */
20
+ export type Provider<T, O extends object = object> = {
21
+ /** The provider mark. */
22
+ mark: ProviderMark<T>;
23
+ /** The function to create the provider. */
24
+ create: (options: O | undefined, ctx: DOMContext) => {
25
+ value: T;
26
+ dispose: () => void;
27
+ onUse?: () => void;
28
+ };
29
+ };
30
+ /**
31
+ * Represents an object with provider options.
32
+ * @public
33
+ */
34
+ export type ProviderOptions = {
35
+ /** The function to use a provider. */
36
+ use: <T, O extends object = object>(provider: Provider<T, O>) => T;
37
+ /** The function to set a provider. */
38
+ set: <T, O extends object = object>(provider: Provider<T, O>, options?: O) => void;
39
+ };
40
+ /**
41
+ * Returns a renderable function that executes the given function with the
42
+ * current DOMContext as argument.
43
+ * The given function can return a TNode or void. If you need to perform some
44
+ * actions when the Renderable is disposed, you can use `OnDispose` as the
45
+ * return value.
46
+ *
47
+ * @param fn - The function to be executed with the DOMContext argument.
48
+ * @returns A Clear function that can be used to clean up any resources associated with the execution.
49
+ * @public
50
+ */
51
+ export declare const WithProvider: (fn: (ctx: ProviderOptions) => TNode | void) => Renderable;
52
+ /**
53
+ * Returns a renderable function that sets a provider for the given provider mark and returns a child renderable.
54
+ *
55
+ * @param provider - The provider to set.
56
+ * @param options - The options to pass to the provider.
57
+ * @param child - The child renderable to return.
58
+ */
59
+ export declare const Provide: <T, O extends object>(provider: Provider<T, O>, options: O, child: (value: T) => TNode) => Renderable;
60
+ /**
61
+ * Returns a renderable function that uses a provider for the given provider mark and returns a child renderable.
62
+ *
63
+ * @param provider - The provider mark to use the provider for.
64
+ * @param child - The child renderable to return.
65
+ */
66
+ export declare const Use: <T>(provider: Provider<T>, child: (provider: T) => TNode) => Renderable;
67
+ /**
68
+ * Returns a renderable function that uses a provider for the given provider marks and returns a child renderable.
69
+ *
70
+ * @param providers - The provider marks to use the providers for.
71
+ * @param child - The child renderable to return.
72
+ */
73
+ export declare const UseMany: <T extends unknown[]>(...providers: ToArrayOfProviders<T>) => (child: (...values: ToProviderTypes<T>) => TNode) => Renderable;
package/types/domain.d.ts CHANGED
@@ -32,7 +32,10 @@ export type ProviderMark<T> = symbol & {
32
32
  * The keys of the record are ProviderMark types, and the values are of unknown type.
33
33
  * @public
34
34
  */
35
- export type Providers = Record<ProviderMark<unknown>, unknown>;
35
+ export type Providers = Record<ProviderMark<unknown>, [
36
+ unknown,
37
+ undefined | (() => void)
38
+ ]>;
36
39
  /**
37
40
  * Represents the size of an object with width and height.
38
41
  * @public
@@ -1,54 +0,0 @@
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;