@tempots/dom 35.0.4 → 36.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/dom",
3
- "version": "35.0.4",
3
+ "version": "36.0.0",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "license": "Apache-2.0",
16
16
  "dependencies": {
17
- "@tempots/core": "^2.0.4"
17
+ "@tempots/core": "^2.1.0",
18
+ "@tempots/render": "^0.0.1"
18
19
  },
19
20
  "description": "Fully-typed frontend framework alternative to React and Angular",
20
21
  "keywords": [
@@ -1,36 +1,2 @@
1
- import { Renderable, TNode } from '../types/domain';
2
- /**
3
- * Options for the `Async` component.
4
- * @typeParam T - The type of the value.
5
- * @public
6
- */
7
- export type AsyncOptions<T> = {
8
- /**
9
- * The node to render while the promise is pending.
10
- */
11
- pending?: () => TNode;
12
- /**
13
- * The node to render when the promise is resolved.
14
- *
15
- * @param value - The value returned by the promise.
16
- * @returns The node to render.
17
- */
18
- then: (value: T) => TNode;
19
- /**
20
- * The node to render when the promise is rejected.
21
- *
22
- * @param error - The error returned by the promise.
23
- * @returns The node to render.
24
- */
25
- error?: (error: unknown) => TNode;
26
- };
27
- /**
28
- * Creates a renderable asynchronous task that wraps a promise.
29
- *
30
- * @typeParam T - The type of the value returned by the promise.
31
- * @param promise - The promise to wrap.
32
- * @param options - The options for the asynchronous task.
33
- * @returns The renderable asynchronous task.
34
- * @public
35
- */
36
- export declare const Async: <T>(promise: Promise<T>, options: AsyncOptions<T> | ((value: T) => TNode)) => Renderable;
1
+ export { Async } from './shared';
2
+ export type { AsyncOptions } from '@tempots/render';
@@ -1,25 +1,2 @@
1
- import { Signal, ElementPosition } from '@tempots/core';
2
- import { Renderable, TNode } from '../types/domain';
3
- /**
4
- * Options for configuring a conjunction.
5
- * @public
6
- */
7
- export type ConjunctionOptions = {
8
- /**
9
- * The separator to use for the last element.
10
- */
11
- lastSeparator?: () => TNode;
12
- /**
13
- * The separator to use for the first element.
14
- */
15
- firstSeparator?: () => TNode;
16
- };
17
- /**
18
- * Creates a Renderable that returns the appropriate separator based on the element position.
19
- *
20
- * @param separator - The default separator to use.
21
- * @param options - The options for configuring the conjunction.
22
- * @returns A function that returns the appropriate separator based on the element position.
23
- * @public
24
- */
25
- export declare const Conjunction: (separator: () => TNode, options?: ConjunctionOptions) => (pos: Signal<ElementPosition>) => Renderable;
1
+ export { Conjunction } from './shared';
2
+ export type { ConjunctionOptions } from '@tempots/render';
@@ -1,12 +1,6 @@
1
1
  import { TNode, Renderable } from '../types/domain';
2
- import { DOMContext } from '../dom/dom-context';
3
- /**
4
- * Converts a TNode into a Renderable.
5
- * @param child - The TNode to convert.
6
- * @returns The corresponding Renderable.
7
- * @public
8
- */
9
- export declare const renderableOfTNode: <T extends DOMContext>(child: TNode<T>) => Renderable<T>;
2
+ import { renderableOfTNode } from './shared';
3
+ export { renderableOfTNode };
10
4
  /**
11
5
  * Creates a Renderable that represents an HTML element.
12
6
  *
@@ -1,7 +1 @@
1
- import { Renderable } from '../types/domain';
2
- /**
3
- * Represents an empty renderable object.
4
- * @returns A renderable object that does nothing.
5
- * @public
6
- */
7
- export declare const Empty: Renderable;
1
+ export { Empty } from './shared';
@@ -1,90 +1,2 @@
1
- import { TNode, Renderable } from '../types/domain';
2
- import { Signal, Value } from '@tempots/core';
3
- export type NillifyValue<T> = Value<T | null | undefined> | Value<T | undefined> | Value<T | null>;
4
- export type Id<T> = {} & {
5
- [P in keyof T]: T[P];
6
- };
7
- export type Merge<A, B> = Id<A & B>;
8
- export type NonNillable<T> = Merge<T, {}>;
9
- /**
10
- * Conditionally renders content based on whether a value is non-null/non-undefined.
11
- *
12
- * This function provides a type-safe way to handle nullable values in your UI. It only
13
- * renders the `then` content when the value is not null or undefined, and optionally
14
- * renders alternative content when the value is null/undefined.
15
- *
16
- * @example
17
- * ```typescript
18
- * // With a signal that might be null
19
- * const user = prop<User | null>(null)
20
- *
21
- * Ensure(user,
22
- * (userSignal) => html.div('Welcome, ', userSignal.map(u => u.name)),
23
- * () => html.div('Please log in')
24
- * )
25
- * ```
26
- *
27
- * @example
28
- * ```typescript
29
- * // With a literal value
30
- * const maybeData = getData() // returns string | null
31
- *
32
- * Ensure(maybeData,
33
- * (dataSignal) => html.div('Data: ', dataSignal),
34
- * () => html.div('No data available')
35
- * )
36
- * ```
37
- *
38
- * @typeParam T - The type of the value when it's not null/undefined
39
- * @param value - A signal or literal value that may be null or undefined
40
- * @param then - Function that receives a signal of the non-nullable value and returns content to render
41
- * @param otherwise - Optional function that returns content to render when value is null/undefined
42
- * @returns A renderable that conditionally displays content based on the value's nullability
43
- * @public
44
- */
45
- export declare const Ensure: <T>(value: NillifyValue<T>, then: (value: Signal<NonNillable<T>>) => TNode, otherwise?: () => TNode) => Renderable;
46
- /**
47
- * Conditionally renders content only when ALL provided values are non-null/non-undefined.
48
- *
49
- * This function is useful when you need multiple values to be present before rendering content.
50
- * It waits for all values to be non-null/non-undefined before calling the callback function.
51
- * If any value becomes null/undefined, it will render the `otherwise` content instead.
52
- *
53
- * @example
54
- * ```typescript
55
- * const user = prop<User | null>(null)
56
- * const profile = prop<Profile | null>(null)
57
- * const settings = prop<Settings | null>(null)
58
- *
59
- * EnsureAll(user, profile, settings)(
60
- * (userSignal, profileSignal, settingsSignal) => html.div(
61
- * html.h1('Dashboard'),
62
- * html.div('User: ', userSignal.map(u => u.name)),
63
- * html.div('Profile: ', profileSignal.map(p => p.bio)),
64
- * html.div('Theme: ', settingsSignal.map(s => s.theme))
65
- * ),
66
- * () => html.div('Loading user data...')
67
- * )
68
- * ```
69
- *
70
- * @example
71
- * ```typescript
72
- * // Mix of signals and literal values
73
- * const apiData = prop<Data | null>(null)
74
- * const staticConfig = { theme: 'dark' }
75
- *
76
- * EnsureAll(apiData, staticConfig)(
77
- * (dataSignal, configSignal) => html.div(
78
- * 'Data loaded with theme: ',
79
- * configSignal.map(c => c.theme)
80
- * ),
81
- * () => html.div('Waiting for data...')
82
- * )
83
- * ```
84
- *
85
- * @typeParam T - Tuple type representing the types of all input values
86
- * @param signals - Variable number of values (signals or literals) that may be null/undefined
87
- * @returns A function that takes a callback and optional otherwise function, returning a renderable
88
- * @public
89
- */
90
- export declare const EnsureAll: <T extends readonly Value<any>[]>(...signals: { [K in keyof T]: NillifyValue<T[K]>; }) => (callback: (...values: { [K in keyof T]: Signal<NonNillable<T[K] extends Value<infer U> ? U : never>>; }) => TNode, otherwise?: () => TNode) => Renderable;
1
+ export { Ensure, EnsureAll } from './shared';
2
+ export type { NillifyValue, NonNillable, Id, Merge } from '@tempots/render';
@@ -1,63 +1 @@
1
- import { TNode, Renderable } from '../types/domain';
2
- import { Signal, Value, ElementPosition } from '@tempots/core';
3
- /**
4
- * Efficiently renders a dynamic list of items from an array signal.
5
- *
6
- * This function creates a reactive list that automatically updates when the source array changes.
7
- * Each item in the array gets its own signal that tracks changes to that specific item.
8
- * The list efficiently handles additions, removals, and modifications to the array.
9
- *
10
- * @example
11
- * ```typescript
12
- * const todos = prop([
13
- * { id: 1, text: 'Learn Tempo', done: false },
14
- * { id: 2, text: 'Build an app', done: false }
15
- * ])
16
- *
17
- * ForEach(todos,
18
- * (todoSignal, position) => html.div(
19
- * html.input(
20
- * attr.type('checkbox'),
21
- * attr.checked(todoSignal.map(t => t.done))
22
- * ),
23
- * html.span(todoSignal.map(t => t.text)),
24
- * html.small(`Item ${position.index + 1}`)
25
- * )
26
- * )
27
- * ```
28
- *
29
- * @example
30
- * ```typescript
31
- * // With separators between items
32
- * const items = prop(['apple', 'banana', 'cherry'])
33
- *
34
- * ForEach(items,
35
- * (itemSignal) => html.span(itemSignal),
36
- * () => html.span(', ') // Separator between items
37
- * )
38
- * // Renders: apple, banana, cherry
39
- * ```
40
- *
41
- * @example
42
- * ```typescript
43
- * // Using position information
44
- * const numbers = prop([10, 20, 30])
45
- *
46
- * ForEach(numbers,
47
- * (numberSignal, position) => html.div(
48
- * `Position ${position.index}: `,
49
- * numberSignal,
50
- * position.isFirst ? ' (first)' : '',
51
- * position.isLast ? ' (last)' : ''
52
- * )
53
- * )
54
- * ```
55
- *
56
- * @typeParam T - The type of items in the array
57
- * @param value - A signal or literal array to iterate over
58
- * @param item - Function that renders each item, receives the item signal and position info
59
- * @param separator - Optional function that renders content between items
60
- * @returns A renderable that displays the dynamic list
61
- * @public
62
- */
63
- export declare const ForEach: <T>(value: Value<T[]>, item: (value: Signal<T>, position: ElementPosition) => TNode, separator?: (pos: ElementPosition) => TNode) => Renderable;
1
+ export { ForEach } from './shared';
@@ -1,14 +1 @@
1
- import { TNode, Renderable } from '../types/domain';
2
- import { DOMContext } from '../dom/dom-context';
3
- /**
4
- * Creates a fragment renderable that represents a collection of child renderables.
5
- *
6
- * The Fragment itself does not render any DOM elements. Instead, it renders the child renderables in the given DOM context.
7
- *
8
- * It can be used any time a single Renderable/TNode is expected, but multiple renderables are needed.
9
- *
10
- * @param children - The child renderables to include in the fragment.
11
- * @returns A renderable object that renders the child renderables in the given DOM context.
12
- * @public
13
- */
14
- export declare const Fragment: <T extends DOMContext>(...children: TNode<T>[]) => Renderable<T>;
1
+ export { Fragment } from './shared';
@@ -1,18 +1 @@
1
- import { Renderable, TNode } from '../types/domain';
2
- import { Value } from '@tempots/core';
3
- /**
4
- * Maps the values emitted by a signal to a renderable function and returns a new renderable function.
5
- *
6
- * While it is tempting to use MapSignal for its simplicity, it is important to remember that the
7
- * renderable function returned by MapSignal will be re-rendered every time the signal emits a new value.
8
- *
9
- * In other contexts link `Ensure` or `OneOf`, the renderable function is only re-rendered when the signal
10
- * changes to a state that requires a different renderable function.
11
- *
12
- * @typeParam T - The type of values emitted by the signal.
13
- * @param vlaue - The signal or value to map.
14
- * @param fn - The function to map the signal values to a renderable/TNode.
15
- * @returns - A new renderable function that represents the mapped signal.
16
- * @public
17
- */
18
- export declare const MapSignal: <T>(value: Value<T>, fn: (value: T) => TNode) => Renderable;
1
+ export { MapSignal } from './shared';
@@ -1,15 +1 @@
1
- import { Signal, Value } from '@tempots/core';
2
- import { Renderable } from '../types/domain';
3
- /**
4
- * Returns a renderable component that displays the given `display` component
5
- * when the `signal` contains a non-empty array, and the `whenEmpty` component
6
- * otherwise.
7
- *
8
- * @typeParam T - The type of elements in the array.
9
- * @param value - The signal or literal containing the array.
10
- * @param display - The component to display when the array is non-empty.
11
- * @param whenEmpty - The component to display when the array is empty.
12
- * @returns - The renderable component.
13
- * @public
14
- */
15
- export declare const NotEmpty: <T>(value: Value<T[]>, display: (value: Signal<T[]>) => Renderable, whenEmpty?: () => Renderable) => Renderable;
1
+ export { NotEmpty } from './shared';
@@ -1,13 +1,13 @@
1
- import { Renderable } from '../types/domain';
2
1
  import { DOMContext } from '../dom/dom-context';
3
- export type DisposeCallback = (removeTree: boolean, ctx: DOMContext) => void;
4
- export type WithDispose = {
5
- dispose: DisposeCallback;
6
- };
2
+ import { DisposeCallback as BaseDisposeCallback, WithDispose as BaseWithDispose } from '@tempots/render';
3
+ export { OnDispose } from './shared';
7
4
  /**
8
- * Creates a renderable object that will be called when the component is unmounted.
9
- * @param fns - The function(s) to be called when the component is unmounted.
10
- * @returns A renderable object that takes a DOMContext and returns a function that takes a boolean indicating whether to remove the tree.
5
+ * Callback invoked on dispose, specialized for DOMContext.
11
6
  * @public
12
7
  */
13
- export declare const OnDispose: (...fns: (DisposeCallback | WithDispose)[]) => Renderable;
8
+ export type DisposeCallback = BaseDisposeCallback<DOMContext>;
9
+ /**
10
+ * Object with a dispose method, specialized for DOMContext.
11
+ * @public
12
+ */
13
+ export type WithDispose = BaseWithDispose<DOMContext>;
@@ -1,153 +1,2 @@
1
- import { Signal, Value } from '@tempots/core';
2
- import { Renderable, TNode } from '../types/domain';
3
- /**
4
- * Represents a set of options for a one-of type.
5
- * @typeParam T - The type of the options.
6
- * @public
7
- */
8
- export type OneOfOptions<T extends Record<string, unknown>> = {
9
- [KK in keyof T]: (value: Signal<T[KK]>) => TNode;
10
- };
11
- /**
12
- * Converts an object to a union of its keys.
13
- * @typeParam T - The type of the object.
14
- * @public
15
- */
16
- export type ObjectToUnion<T> = {
17
- [K in keyof T]: {
18
- [P in K]: T[K];
19
- };
20
- }[keyof T];
21
- /**
22
- * Creates a renderable function that renders different components based on the value of a signal.
23
- *
24
- * The signal value should be an object with a single key that matches one of the keys in the `cases` object.
25
- *
26
- * @typeParam T - The type of the signal value.
27
- * @param match - The signal or value to match against.
28
- * @param cases - An object containing the different cases to render based on the signal value.
29
- * @returns A renderable function that renders the appropriate component based on the signal value.
30
- * @public
31
- */
32
- export declare const OneOf: <T extends Record<string, unknown>>(match: Value<T>, cases: OneOfOptions<T>) => Renderable;
33
- /**
34
- * Represents the options for a one-of field.
35
- *
36
- * @typeParam T - The type containing the one-of field.
37
- * @typeParam K - The key of the one-of field in the type.
38
- * @public
39
- */
40
- export type OneOfFieldOptions<T extends {
41
- [_ in K]: string;
42
- }, K extends string> = {
43
- [KK in T[K]]: (value: Signal<T extends {
44
- [_ in K]: KK;
45
- } ? T : never>) => TNode;
46
- };
47
- /**
48
- * Creates a renderable that renders different components based on the value of the specified field.
49
- *
50
- * @typeParam T - The type containing the one-of field.
51
- * @typeParam K - The type of the one-of field key.
52
- * @param match - The signal or value that emits the object containing the one-of field.
53
- * @param field - The key of the one-of field.
54
- * @param cases - The options for the different cases of rendering based on the one-of field value.
55
- * @returns - The renderable field representing the one-of field.
56
- * @public
57
- */
58
- export declare const OneOfField: <T extends { [_ in K]: string; }, K extends string>(match: Value<T>, field: K, cases: OneOfFieldOptions<T, K>) => Renderable;
59
- /**
60
- * The options for a one-of kind field.
61
- *
62
- * @typeParam T - The type that contains the `kind` property.
63
- * @public
64
- */
65
- export type OneOfKindOptions<T extends {
66
- kind: string;
67
- }> = {
68
- [KK in T['kind']]: (value: Signal<T extends {
69
- kind: KK;
70
- } ? T : never>) => TNode;
71
- };
72
- /**
73
- * Creates a renderable field that matches the value of the `kind` property in the provided `match` signal.
74
- *
75
- * It uses the `cases` object to determine the appropriate field to render based on the value of `kind`.
76
- *
77
- * @typeParam T - The type of the object with a `kind` property.
78
- * @param match - The signal containing the object to match against.
79
- * @param cases - The object containing the cases to match against.
80
- * @returns - The renderable field that matches the value of `kind`.
81
- * @public
82
- */
83
- export declare const OneOfKind: <T extends {
84
- kind: string;
85
- }>(match: Value<T>, cases: OneOfKindOptions<T>) => Renderable;
86
- /**
87
- * Represents a mapping of keys to functions that accept a value of type `Signal<V>`
88
- * and return a `TNode`.
89
- *
90
- * @typeParam T - The union type of keys.
91
- * @typeParam V - The type of the value accepted by the functions.
92
- * @public
93
- */
94
- export type OneOfTupleOptions<T extends string, V> = {
95
- [KK in T]: (value: Signal<V>) => TNode;
96
- };
97
- /**
98
- * Creates a tuple-based one-of component that matches a signal value with a set of cases.
99
- *
100
- * The signal value should be a tuple with the first element being the key to match against.
101
- *
102
- * @param match - The signal containing the value to match.
103
- * @param cases - The options for the one-of component.
104
- * @returns The result of matching the signal value with the cases.
105
- * @public
106
- */
107
- export declare const OneOfTuple: <T extends string, V>(match: Value<[T, V]>, cases: OneOfTupleOptions<T, V>) => Renderable;
108
- /**
109
- * Represents a mapping of types to rendering functions.
110
- * @typeParam T - The type that contains a `type` property.
111
- * @public
112
- */
113
- export type OneOfTypeOptions<T extends {
114
- type: string;
115
- }> = {
116
- [KK in T['type']]: (value: Signal<T extends {
117
- type: KK;
118
- } ? T : never>) => TNode;
119
- };
120
- /**
121
- * Creates a field that renders one of the provided cases based on the value of the `type` property.
122
- *
123
- * It uses the `cases` object to determine the appropriate field to render based on the value of `type`.
124
- *
125
- * @typeParam T - The type of the object with a `type` property.
126
- * @param match - The signal that contains the object with the `type` property.
127
- * @param cases - The options for rendering each case based on the `type` property.
128
- * @returns - The rendered field.
129
- * @public
130
- */
131
- export declare const OneOfType: <T extends {
132
- type: string;
133
- }>(match: Value<T>, cases: OneOfTypeOptions<T>) => Renderable;
134
- /**
135
- * Represents a set of options for a one-of value.
136
- * @typeParam T - The type of the one-of value.
137
- * @public
138
- */
139
- export type OneOfValueOptions<T extends symbol | number | string> = {
140
- [KK in T]: () => TNode;
141
- };
142
- /**
143
- * Creates a renderable value that represents one of the provided cases based on the given match signal.
144
- *
145
- * The match signal should emit a value that matches one of the keys in the `cases` object.
146
- *
147
- * @typeParam T - The type of the match signal value.
148
- * @param match - The match signal.
149
- * @param cases - The options for the one-of value.
150
- * @returns - The renderable value representing one of the cases.
151
- * @public
152
- */
153
- export declare const OneOfValue: <T extends symbol | number | string>(match: Value<T>, cases: OneOfValueOptions<T>) => Renderable;
1
+ export { OneOf, OneOfField, OneOfKind, OneOfType, OneOfValue, OneOfTuple, } from './shared';
2
+ export type { OneOfOptions, ObjectToUnion, OneOfFieldOptions, OneOfKindOptions, OneOfTupleOptions, OneOfTypeOptions, OneOfValueOptions, } from '@tempots/render';