@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/dom/errors.d.ts +1 -9
- package/dom/headless-context.d.ts +58 -0
- package/index.cjs +1 -1
- package/index.d.ts +4 -1
- package/index.js +1426 -1200
- package/package.json +3 -2
- package/renderable/async.d.ts +2 -36
- package/renderable/conjunction.d.ts +2 -25
- package/renderable/element.d.ts +2 -8
- package/renderable/empty.d.ts +1 -7
- package/renderable/ensure.d.ts +2 -90
- package/renderable/foreach.d.ts +1 -63
- package/renderable/fragment.d.ts +1 -14
- package/renderable/map-signal.d.ts +1 -18
- package/renderable/not-empty.d.ts +1 -15
- package/renderable/on-dispose.d.ts +9 -9
- package/renderable/oneof.d.ts +2 -153
- package/renderable/provider.d.ts +7 -228
- package/renderable/repeat.d.ts +1 -70
- package/renderable/shared.d.ts +8 -0
- package/renderable/task.d.ts +2 -22
- package/renderable/utils.d.ts +1 -30
- package/renderable/when.d.ts +1 -20
- package/renderable/with-scope.d.ts +1 -39
- package/types/domain.d.ts +3 -12
package/renderable/provider.d.ts
CHANGED
|
@@ -1,235 +1,14 @@
|
|
|
1
1
|
import { DOMContext } from '../dom/dom-context';
|
|
2
|
-
import {
|
|
2
|
+
import { Provider as BaseProvider, ProviderOptions as BaseProviderOptions } from '@tempots/render';
|
|
3
|
+
export { WithProvider, Provide, Use, UseMany } from './shared';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Represents a provider for a specific type `T`, specialized for DOMContext.
|
|
5
6
|
* @public
|
|
6
7
|
*/
|
|
7
|
-
export type
|
|
8
|
+
export type Provider<T, O = any> = BaseProvider<T, O, DOMContext>;
|
|
8
9
|
/**
|
|
9
|
-
* Represents
|
|
10
|
+
* Represents an object with provider options, specialized for DOMContext.
|
|
10
11
|
* @public
|
|
11
12
|
*/
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
mark: ProviderMark<T>;
|
|
15
|
-
/** The function to create the provider. */
|
|
16
|
-
create: (options: O | undefined, ctx: DOMContext) => {
|
|
17
|
-
value: T;
|
|
18
|
-
dispose: () => void;
|
|
19
|
-
onUse?: () => void;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Represents an object with provider options.
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export type ProviderOptions = {
|
|
27
|
-
/** The function to use a provider. */
|
|
28
|
-
use: <T, O = any>(provider: Provider<T, O>) => T;
|
|
29
|
-
/** The function to set a provider. */
|
|
30
|
-
set: <T, O = any>(provider: Provider<T, O>, options?: O) => void;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Returns a renderable object that executes the given function with the
|
|
34
|
-
* current DOMContext as argument.
|
|
35
|
-
* The given function can return a TNode or void. If you need to perform some
|
|
36
|
-
* actions when the Renderable is disposed, you can use `OnDispose` as the
|
|
37
|
-
* return value.
|
|
38
|
-
*
|
|
39
|
-
* @param fn - The function to be executed with the DOMContext argument.
|
|
40
|
-
* @returns A Clear function that can be used to clean up any resources associated with the execution.
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
export declare const WithProvider: (fn: (opts: ProviderOptions) => TNode | void) => Renderable;
|
|
44
|
-
/**
|
|
45
|
-
* Makes a provider available to all child components in the component tree.
|
|
46
|
-
*
|
|
47
|
-
* This function creates a provider context that child components can access using `Use`.
|
|
48
|
-
* The provider is automatically disposed when the component is unmounted.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* // Create a theme provider
|
|
53
|
-
* const ThemeProvider: Provider<Signal<string>> = {
|
|
54
|
-
* mark: makeProviderMark<Signal<string>>('Theme'),
|
|
55
|
-
* create: () => {
|
|
56
|
-
* const theme = prop('light')
|
|
57
|
-
* return {
|
|
58
|
-
* value: theme,
|
|
59
|
-
* dispose: () => theme.dispose()
|
|
60
|
-
* }
|
|
61
|
-
* }
|
|
62
|
-
* }
|
|
63
|
-
*
|
|
64
|
-
* // Provide the theme to child components
|
|
65
|
-
* const App = () =>
|
|
66
|
-
* Provide(
|
|
67
|
-
* ThemeProvider,
|
|
68
|
-
* {}, // options
|
|
69
|
-
* () => html.div(
|
|
70
|
-
* html.h1('My App'),
|
|
71
|
-
* ThemeToggle(), // Can access the theme
|
|
72
|
-
* MainContent() // Can also access the theme
|
|
73
|
-
* )
|
|
74
|
-
* )
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* // Provider with options
|
|
80
|
-
* const ConfigProvider: Provider<Config, { apiUrl: string }> = {
|
|
81
|
-
* mark: makeProviderMark<Config>('Config'),
|
|
82
|
-
* create: (options) => {
|
|
83
|
-
* const config = new Config(options.apiUrl)
|
|
84
|
-
* return {
|
|
85
|
-
* value: config,
|
|
86
|
-
* dispose: () => config.cleanup()
|
|
87
|
-
* }
|
|
88
|
-
* }
|
|
89
|
-
* }
|
|
90
|
-
*
|
|
91
|
-
* // Provide with specific options
|
|
92
|
-
* Provide(
|
|
93
|
-
* ConfigProvider,
|
|
94
|
-
* { apiUrl: 'https://api.example.com' },
|
|
95
|
-
* () => AppContent()
|
|
96
|
-
* )
|
|
97
|
-
* ```
|
|
98
|
-
*
|
|
99
|
-
* @typeParam T - The type of value provided by the provider
|
|
100
|
-
* @typeParam O - The type of options passed to the provider
|
|
101
|
-
* @param provider - The provider definition containing mark and create function
|
|
102
|
-
* @param options - Options to pass to the provider's create function
|
|
103
|
-
* @param child - Function that returns the child components that can access the provider
|
|
104
|
-
* @returns A renderable that provides the value to its children
|
|
105
|
-
* @public
|
|
106
|
-
*/
|
|
107
|
-
export declare const Provide: <T, O>(provider: Provider<T, O>, options: O, child: () => TNode) => Renderable;
|
|
108
|
-
/**
|
|
109
|
-
* Consumes a provider value and makes it available to a child component.
|
|
110
|
-
*
|
|
111
|
-
* This function looks up a provider in the component tree and passes its value
|
|
112
|
-
* to the child function. The provider must have been made available by a parent
|
|
113
|
-
* component using `Provide`.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* // Use a theme provider
|
|
118
|
-
* const ThemeToggle = () =>
|
|
119
|
-
* Use(
|
|
120
|
-
* ThemeProvider,
|
|
121
|
-
* (theme) => html.button(
|
|
122
|
-
* on.click(() => {
|
|
123
|
-
* theme.value = theme.value === 'light' ? 'dark' : 'light'
|
|
124
|
-
* }),
|
|
125
|
-
* 'Current theme: ', theme
|
|
126
|
-
* )
|
|
127
|
-
* )
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* // Use multiple properties from a provider
|
|
133
|
-
* const UserProfile = () =>
|
|
134
|
-
* Use(
|
|
135
|
-
* UserProvider,
|
|
136
|
-
* (user) => html.div(
|
|
137
|
-
* html.h2('Welcome, ', user.map(u => u.name)),
|
|
138
|
-
* html.p('Email: ', user.map(u => u.email)),
|
|
139
|
-
* html.p('Role: ', user.map(u => u.role))
|
|
140
|
-
* )
|
|
141
|
-
* )
|
|
142
|
-
* ```
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* // Use provider in conditional rendering
|
|
147
|
-
* const ConditionalContent = () =>
|
|
148
|
-
* Use(
|
|
149
|
-
* AuthProvider,
|
|
150
|
-
* (auth) => auth.map(a => a.isLoggedIn)
|
|
151
|
-
* ? html.div('Welcome back!')
|
|
152
|
-
* : html.div('Please log in')
|
|
153
|
-
* )
|
|
154
|
-
* ```
|
|
155
|
-
*
|
|
156
|
-
* @typeParam T - The type of value provided by the provider
|
|
157
|
-
* @param provider - The provider to consume (must be available in parent components)
|
|
158
|
-
* @param child - Function that receives the provider value and returns content to render
|
|
159
|
-
* @returns A renderable that consumes the provider and renders the child content
|
|
160
|
-
* @throws {ProviderNotFoundError} When the provider is not found in the component tree
|
|
161
|
-
* @public
|
|
162
|
-
*/
|
|
163
|
-
export declare const Use: <T>(provider: Provider<T>, child: (provider: T) => TNode) => Renderable;
|
|
164
|
-
/**
|
|
165
|
-
* Consumes multiple providers and makes their values available to a child component.
|
|
166
|
-
*
|
|
167
|
-
* This function is a convenience wrapper for consuming multiple providers at once.
|
|
168
|
-
* It's equivalent to nesting multiple `Use` calls but provides a cleaner API when
|
|
169
|
-
* you need access to several providers simultaneously.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
* // Use multiple providers together
|
|
174
|
-
* const Dashboard = () =>
|
|
175
|
-
* UseMany(
|
|
176
|
-
* UserProvider,
|
|
177
|
-
* ThemeProvider,
|
|
178
|
-
* ConfigProvider
|
|
179
|
-
* )(
|
|
180
|
-
* (user, theme, config) => html.div(
|
|
181
|
-
* attr.class(theme.map(t => `theme-${t}`)),
|
|
182
|
-
* html.h1('Dashboard for ', user.map(u => u.name)),
|
|
183
|
-
* html.p('API URL: ', config.map(c => c.apiUrl)),
|
|
184
|
-
* html.p('Current theme: ', theme)
|
|
185
|
-
* )
|
|
186
|
-
* )
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* // Equivalent to nested Use calls
|
|
192
|
-
* const Dashboard = () =>
|
|
193
|
-
* Use(UserProvider, user =>
|
|
194
|
-
* Use(ThemeProvider, theme =>
|
|
195
|
-
* Use(ConfigProvider, config =>
|
|
196
|
-
* html.div(
|
|
197
|
-
* // Same content as above
|
|
198
|
-
* )
|
|
199
|
-
* )
|
|
200
|
-
* )
|
|
201
|
-
* )
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* // Type-safe access to multiple providers
|
|
207
|
-
* const SettingsPanel = () =>
|
|
208
|
-
* UseMany(
|
|
209
|
-
* PreferencesProvider,
|
|
210
|
-
* UserProvider
|
|
211
|
-
* )(
|
|
212
|
-
* (preferences, user) => html.div(
|
|
213
|
-
* html.h2('Settings for ', user.map(u => u.name)),
|
|
214
|
-
* html.label(
|
|
215
|
-
* 'Theme: ',
|
|
216
|
-
* html.select(
|
|
217
|
-
* attr.value(preferences.map(p => p.theme)),
|
|
218
|
-
* on.change(emitValue(value => {
|
|
219
|
-
* preferences.update(p => ({ ...p, theme: value }))
|
|
220
|
-
* })),
|
|
221
|
-
* html.option(attr.value('light'), 'Light'),
|
|
222
|
-
* html.option(attr.value('dark'), 'Dark')
|
|
223
|
-
* )
|
|
224
|
-
* )
|
|
225
|
-
* )
|
|
226
|
-
* )
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* @typeParam T - Tuple type representing the types of all providers
|
|
230
|
-
* @param providers - Variable number of providers to consume
|
|
231
|
-
* @returns Function that takes a child function and returns a renderable
|
|
232
|
-
* @throws {ProviderNotFoundError} When any of the providers is not found in the component tree
|
|
233
|
-
* @public
|
|
234
|
-
*/
|
|
235
|
-
export declare const UseMany: <T extends Provider<unknown>[]>(...providers: T) => (child: (...values: ToProviderTypes<T>) => TNode) => Renderable;
|
|
13
|
+
export type ProviderOptions = BaseProviderOptions<DOMContext>;
|
|
14
|
+
export type { ToProviderTypes } from '@tempots/render';
|
package/renderable/repeat.d.ts
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { TNode, Renderable } from '../types/domain';
|
|
3
|
-
/**
|
|
4
|
-
* Renders content a specified number of times, with each iteration receiving position information.
|
|
5
|
-
*
|
|
6
|
-
* This function is useful for generating repeated UI elements based on a count rather than an array.
|
|
7
|
-
* Each iteration receives an `ElementPosition` object that provides the current index and position
|
|
8
|
-
* information relative to the total count.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // Create a simple numbered list
|
|
13
|
-
* const count = prop(5)
|
|
14
|
-
*
|
|
15
|
-
* Repeat(count,
|
|
16
|
-
* (position) => html.div(
|
|
17
|
-
* `Item ${position.index + 1} of ${position.total.value}`,
|
|
18
|
-
* position.isFirst ? ' (first)' : '',
|
|
19
|
-
* position.isLast ? ' (last)' : ''
|
|
20
|
-
* )
|
|
21
|
-
* )
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* // Create a star rating component
|
|
27
|
-
* const rating = prop(3)
|
|
28
|
-
* const maxStars = 5
|
|
29
|
-
*
|
|
30
|
-
* Repeat(maxStars,
|
|
31
|
-
* (position) => html.span(
|
|
32
|
-
* attr.class(position.index < rating.value ? 'star-filled' : 'star-empty'),
|
|
33
|
-
* '★'
|
|
34
|
-
* )
|
|
35
|
-
* )
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* // With separators between items
|
|
41
|
-
* Repeat(3,
|
|
42
|
-
* (position) => html.span(`Item ${position.index}`),
|
|
43
|
-
* () => html.span(' | ') // Separator
|
|
44
|
-
* )
|
|
45
|
-
* // Renders: Item 0 | Item 1 | Item 2
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* // Dynamic count that updates the UI
|
|
51
|
-
* const itemCount = prop(2)
|
|
52
|
-
*
|
|
53
|
-
* html.div(
|
|
54
|
-
* html.button(
|
|
55
|
-
* on.click(() => itemCount.value++),
|
|
56
|
-
* 'Add Item'
|
|
57
|
-
* ),
|
|
58
|
-
* Repeat(itemCount,
|
|
59
|
-
* (position) => html.div(`Dynamic item ${position.index + 1}`)
|
|
60
|
-
* )
|
|
61
|
-
* )
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @param times - A signal or number representing how many times to repeat the content
|
|
65
|
-
* @param element - Function that returns content for each iteration, receives position information
|
|
66
|
-
* @param separator - Optional function that returns content to place between iterations
|
|
67
|
-
* @returns A renderable that displays the repeated content
|
|
68
|
-
* @public
|
|
69
|
-
*/
|
|
70
|
-
export declare const Repeat: (times: Value<number>, element: (index: ElementPosition) => TNode, separator?: (pos: ElementPosition) => TNode) => Renderable;
|
|
1
|
+
export { Repeat } from './shared';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DOMContext } from '../dom/dom-context';
|
|
2
|
+
import { DOM_RENDERABLE_TYPE } from '../types/domain';
|
|
3
|
+
export declare const domKit: import('@tempots/render').RenderKit<DOMContext, typeof DOM_RENDERABLE_TYPE>;
|
|
4
|
+
export declare const Empty: import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Fragment: (...children: import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>[]) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, When: (condition: import('@tempots/core').Value<boolean>, then: () => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, otherwise?: (() => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Unless: (condition: import('@tempots/core').Value<boolean>, then: () => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, otherwise?: (() => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, ForEach: <T>(value: import('@tempots/core').Value<T[]>, item: (value: import('@tempots/core').Signal<T>, position: import('@tempots/core').ElementPosition) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, separator?: ((pos: import('@tempots/core').ElementPosition) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Repeat: (times: import('@tempots/core').Value<number>, element: (index: import('@tempots/core').ElementPosition) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, separator?: ((pos: import('@tempots/core').ElementPosition) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OneOf: <T extends Record<string, unknown>>(match: import('@tempots/core').Value<T>, cases: import('@tempots/render').OneOfOptions<T, DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OneOfField: <T extends { [_ in K]: string; }, K extends string>(match: import('@tempots/core').Value<T>, field: K, cases: import('@tempots/render').OneOfFieldOptions<T, K, DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OneOfKind: <T extends {
|
|
5
|
+
kind: string;
|
|
6
|
+
}>(match: import('@tempots/core').Value<T>, cases: import('@tempots/render').OneOfKindOptions<T, DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OneOfType: <T extends {
|
|
7
|
+
type: string;
|
|
8
|
+
}>(match: import('@tempots/core').Value<T>, cases: import('@tempots/render').OneOfTypeOptions<T, DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OneOfValue: <T extends symbol | number | string>(match: import('@tempots/core').Value<T>, cases: import('@tempots/render').OneOfValueOptions<T, DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OneOfTuple: <T extends string, V>(match: import('@tempots/core').Value<[T, V]>, cases: import('@tempots/render').OneOfTupleOptions<T, V, DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, MapSignal: <T>(value: import('@tempots/core').Value<T>, fn: (value: T) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Ensure: <T>(value: import('@tempots/render').NillifyValue<T>, then: (value: import('@tempots/core').Signal<T & {} extends infer T_1 ? { [P in keyof T_1]: T_1[P]; } : never>) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, otherwise?: (() => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, EnsureAll: <T extends readonly import('@tempots/core').Value<unknown>[]>(...signals: { [K in keyof T]: import('@tempots/render').NillifyValue<T[K]>; }) => (callback: (...values: { [K_1 in keyof T]: import('@tempots/core').Signal<(T[K_1] extends import('@tempots/core').Value<infer U> ? U : never) & {} extends infer T_1 ? { [P in keyof T_1]: T_1[P]; } : never>; }) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, otherwise?: (() => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, NotEmpty: <T>(value: import('@tempots/core').Value<T[]>, display: (value: import('@tempots/core').Signal<T[]>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, whenEmpty?: (() => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>) | undefined) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Task: <T>(task: () => Promise<T>, options: import('@tempots/render').TaskOptions<T, DOMContext, typeof DOM_RENDERABLE_TYPE> | ((value: T) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>)) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Async: <T>(promise: Promise<T>, options: import('@tempots/render').AsyncOptions<T, DOMContext, typeof DOM_RENDERABLE_TYPE> | ((value: T) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>)) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, OnDispose: (...fns: (import('@tempots/render').DisposeCallback<DOMContext> | import('@tempots/render').WithDispose<DOMContext>)[]) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Conjunction: (separator: () => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>, options?: import('@tempots/render').ConjunctionOptions<DOMContext, typeof DOM_RENDERABLE_TYPE> | undefined) => (pos: import('@tempots/core').Signal<import('@tempots/core').ElementPosition>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, WithScope: (fn: (scope: import('@tempots/core').DisposalScope) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, WithProvider: (fn: (opts: import('@tempots/render').ProviderOptions<DOMContext>) => void | import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Provide: <T, O>(provider: import('@tempots/render').Provider<T, O, DOMContext>, options: O, child: () => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, Use: <T>(provider: import('@tempots/render').Provider<T, unknown, DOMContext>, child: (provider: T) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, UseMany: <P extends import('@tempots/render').Provider<unknown, unknown, DOMContext>[]>(...providers: P) => (child: (...values: import('@tempots/render').ToProviderTypes<P>) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>, handleValueOrSignal: <T, R>(value: import('@tempots/core').Value<T>, onSignal: (signal: import('@tempots/core').Signal<T>) => R, onStatic: (literal: T) => R) => R, createReactiveRenderable: <T>(ctx: DOMContext, signal: import('@tempots/core').Signal<T>, render: (value: T) => import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Clear, renderableOfTNode: (child: import('@tempots/core').TNode<DOMContext, typeof DOM_RENDERABLE_TYPE>) => import('@tempots/core').Renderable<DOMContext, typeof DOM_RENDERABLE_TYPE>;
|
package/renderable/task.d.ts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Represents the options for a task.
|
|
4
|
-
*
|
|
5
|
-
* @typeParam T - The type of the task value.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export type TaskOptions<T> = {
|
|
9
|
-
pending?: () => TNode;
|
|
10
|
-
then: (value: T) => TNode;
|
|
11
|
-
error?: (error: unknown) => TNode;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Represents a renderable task that can be executed asynchronously.
|
|
15
|
-
*
|
|
16
|
-
* @typeParam T - The type of the value returned by the task.
|
|
17
|
-
* @param task - The asynchronous task to be executed.
|
|
18
|
-
* @param options - The options for the task or a function that transforms the task result into a renderable node.
|
|
19
|
-
* @returns - A renderable object that renders the task and returns a cleanup function.
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
export declare const Task: <T>(task: () => Promise<T>, options: TaskOptions<T> | ((value: T) => TNode)) => Renderable;
|
|
1
|
+
export { Task } from './shared';
|
|
2
|
+
export type { TaskOptions } from '@tempots/render';
|
package/renderable/utils.d.ts
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { DOMContext } from '../dom/dom-context';
|
|
3
|
-
import { Signal, Value } from '@tempots/core';
|
|
4
|
-
/**
|
|
5
|
-
* Helper function to handle a value that could be either a Signal or a static value.
|
|
6
|
-
* Delegates to the appropriate handler based on whether the value is a Signal.
|
|
7
|
-
*
|
|
8
|
-
* @param value - The value to check (could be Signal<T> or T)
|
|
9
|
-
* @param onSignal - Handler function to call if value is a Signal
|
|
10
|
-
* @param onStatic - Handler function to call if value is static
|
|
11
|
-
* @returns The result from the appropriate handler
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare const handleValueOrSignal: <T, R>(value: Value<T>, onSignal: (signal: Signal<T>) => R, onStatic: (literal: T) => R) => R;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a reactive renderable that updates when a signal changes.
|
|
17
|
-
* This helper consolidates the common pattern of:
|
|
18
|
-
* - Creating a new context reference
|
|
19
|
-
* - Setting up a signal listener that re-renders on changes
|
|
20
|
-
* - Properly cleaning up the old render before creating a new one
|
|
21
|
-
* - Disposing the signal listener and context on cleanup
|
|
22
|
-
* - Creating a disposal scope for each branch to track signals
|
|
23
|
-
*
|
|
24
|
-
* @param ctx - The parent DOM context
|
|
25
|
-
* @param signal - The signal to watch for changes
|
|
26
|
-
* @param render - Function that takes the signal value and returns content to render
|
|
27
|
-
* @returns A Clear function that cleans up the reactive renderable
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export declare const createReactiveRenderable: <T>(ctx: DOMContext, signal: Signal<T>, render: (value: T) => TNode) => Clear;
|
|
1
|
+
export { handleValueOrSignal, createReactiveRenderable } from './shared';
|
package/renderable/when.d.ts
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Value } from '@tempots/core';
|
|
3
|
-
/**
|
|
4
|
-
* Lazily renders content based on a boolean condition.
|
|
5
|
-
* @param condition - The condition to evaluate
|
|
6
|
-
* @param then - Function returning content to render if condition is true
|
|
7
|
-
* @param otherwise - Optional function returning content to render if condition is false
|
|
8
|
-
* @returns Renderable content
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export declare const When: (condition: Value<boolean>, then: () => TNode, otherwise?: () => TNode) => Renderable;
|
|
12
|
-
/**
|
|
13
|
-
* Lazily renders content when a condition is false.
|
|
14
|
-
* @param condition - The condition to evaluate
|
|
15
|
-
* @param then - Function returning content to render if condition is false
|
|
16
|
-
* @param otherwise - Optional function returning content to render if condition is true
|
|
17
|
-
* @returns Renderable content
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export declare const Unless: (condition: Value<boolean>, then: () => TNode, otherwise?: () => TNode) => Renderable;
|
|
1
|
+
export { When, Unless } from './shared';
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Renderable, TNode } from '../types/domain';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a renderable that provides explicit access to a DisposalScope.
|
|
5
|
-
*
|
|
6
|
-
* This is useful when you need to create signals in async contexts (like setTimeout,
|
|
7
|
-
* fetch callbacks, event handlers) where automatic scope tracking doesn't work.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // Using scope in async context
|
|
12
|
-
* WithScope(scope => {
|
|
13
|
-
* setTimeout(() => {
|
|
14
|
-
* const signal = scope.prop(42)
|
|
15
|
-
* // signal will be disposed when component unmounts
|
|
16
|
-
* }, 1000)
|
|
17
|
-
*
|
|
18
|
-
* return html.div('Loading...')
|
|
19
|
-
* })
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* // Using scope with fetch
|
|
25
|
-
* WithScope(scope => {
|
|
26
|
-
* fetch('/api/data').then(response => {
|
|
27
|
-
* const data = scope.prop(response.data)
|
|
28
|
-
* // data will be disposed when component unmounts
|
|
29
|
-
* })
|
|
30
|
-
*
|
|
31
|
-
* return html.div('Fetching...')
|
|
32
|
-
* })
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @param fn - Function that receives the scope and returns content to render
|
|
36
|
-
* @returns A renderable that manages the scope lifecycle
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export declare const WithScope: (fn: (scope: DisposalScope) => TNode) => Renderable;
|
|
1
|
+
export { WithScope } from './shared';
|
package/types/domain.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ReadSignal } from '../../../tempots-core/dist/signal';
|
|
2
1
|
import { DOMContext } from '../dom/dom-context';
|
|
3
2
|
import { AnySignal, Computed, Prop, Signal, Value, ValueType, BaseValueType, ValueTypes, Values, RemoveSignals, Nil, Clear, ProviderMark, makeProviderMark, Renderable as CoreRenderable } from '@tempots/core';
|
|
4
3
|
export type { Clear, ProviderMark, ValueType, BaseValueType, ValueTypes, Values, RemoveSignals, Nil, AnySignal, };
|
|
@@ -128,16 +127,8 @@ export declare const domRenderable: <CTX extends DOMContext = DOMContext>(render
|
|
|
128
127
|
* @typeParam CTX - The type of DOMContext (defaults to DOMContext)
|
|
129
128
|
* @public
|
|
130
129
|
*/
|
|
131
|
-
export type TNode<CTX extends DOMContext = DOMContext> = Renderable<CTX> | string |
|
|
132
|
-
|
|
133
|
-
* Represents a collection of providers.
|
|
134
|
-
* The keys of the record are ProviderMark types, and the values are of unknown type.
|
|
135
|
-
* @public
|
|
136
|
-
*/
|
|
137
|
-
export type Providers = Record<ProviderMark<unknown>, [
|
|
138
|
-
unknown,
|
|
139
|
-
undefined | (() => void)
|
|
140
|
-
]>;
|
|
130
|
+
export type TNode<CTX extends DOMContext = DOMContext> = Renderable<CTX> | string | Signal<string> | undefined | null | Renderable<CTX>[];
|
|
131
|
+
export type { Providers } from '@tempots/render';
|
|
141
132
|
/**
|
|
142
133
|
* Represents the size of an object with width and height.
|
|
143
134
|
* @public
|
|
@@ -157,7 +148,7 @@ export type Size = {
|
|
|
157
148
|
* @typeParam T - The type of the value.
|
|
158
149
|
* @public
|
|
159
150
|
*/
|
|
160
|
-
export type NValue<T> = Value<NonNullable<T>> |
|
|
151
|
+
export type NValue<T> = Value<NonNullable<T>> | Signal<T> | Signal<T | null> | Signal<T | undefined> | Signal<T | null | undefined> | null | undefined;
|
|
161
152
|
type TupleToUnion<T extends unknown[]> = T[number];
|
|
162
153
|
export type SplitNValue<T> = (T extends unknown ? TupleToUnion<NValue<T>[]> : never) | NValue<T>;
|
|
163
154
|
export type SplitValue<T> = (T extends unknown ? TupleToUnion<Value<T>[]> : never) | Value<T>;
|