@tempots/dom 24.0.0-next.1 → 24.0.0-next.10
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/browser-context.d.ts +3 -2
- package/dom/dom-context.d.ts +13 -1
- package/dom/headless-context.d.ts +4 -4
- package/index.cjs +1 -1
- package/index.d.ts +1 -0
- package/index.js +852 -574
- package/package.json +1 -1
- package/renderable/probe.d.ts +12 -3
- package/renderable/render.d.ts +180 -0
- package/renderable/style.d.ts +1 -0
- package/std/signal.d.ts +8 -2
- package/std/value.d.ts +2 -2
package/package.json
CHANGED
package/renderable/probe.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Renderable, TNode } from '../types/domain';
|
|
|
3
3
|
* A provider mark for a signal representing the current appearance type.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export declare const probeMarker: import('
|
|
6
|
+
export declare const probeMarker: import('..').ProviderMark<(identifier: symbol) => void>;
|
|
7
|
+
export type ProbeResolution = 'resolved' | 'timeout';
|
|
7
8
|
/**
|
|
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.
|
|
9
10
|
* To resolve a probe, call the `done` function passed using the `UseProbe` renderable.
|
|
@@ -14,7 +15,12 @@ export declare const probeMarker: import('../types/domain').ProviderMark<(identi
|
|
|
14
15
|
* @returns The child component with the probe.
|
|
15
16
|
* @public
|
|
16
17
|
*/
|
|
17
|
-
export declare const ProvideProbe: (identifier
|
|
18
|
+
export declare const ProvideProbe: ({ identifier, callback, child, timeout, }: {
|
|
19
|
+
identifier: symbol;
|
|
20
|
+
callback?: (resolution: ProbeResolution) => void;
|
|
21
|
+
child: TNode;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
}) => Renderable;
|
|
18
24
|
/**
|
|
19
25
|
* Uses a probe, which can be used to trigger a callback when all probes with the same identifier are resolved.
|
|
20
26
|
* To resolve a probe, call the `done` function.
|
|
@@ -34,7 +40,10 @@ export declare const UseProbe: (identifier: symbol, fn: (done: () => void) => TN
|
|
|
34
40
|
* @returns The child component with the probe.
|
|
35
41
|
* @public
|
|
36
42
|
*/
|
|
37
|
-
export declare const ProvideGlobalProbe: (callback
|
|
43
|
+
export declare const ProvideGlobalProbe: ({ callback, timeout, }: {
|
|
44
|
+
callback?: (resolution: ProbeResolution) => void;
|
|
45
|
+
timeout?: number;
|
|
46
|
+
}, child: TNode) => Renderable;
|
|
38
47
|
/**
|
|
39
48
|
* Uses a global probe, which can be used to trigger a callback when all probes with the same identifier are resolved.
|
|
40
49
|
* To resolve a probe, call the `done` function.
|
package/renderable/render.d.ts
CHANGED
|
@@ -36,6 +36,16 @@ export type RenderOptions = {
|
|
|
36
36
|
* @public
|
|
37
37
|
*/
|
|
38
38
|
export declare const render: (node: Renderable, parent: Node | string, { doc, clear }?: RenderOptions) => () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Runs a renderable function in a headless environment.
|
|
41
|
+
*
|
|
42
|
+
* @param makeRenderable - A function that returns a Renderable to be rendered in the headless environment.
|
|
43
|
+
* @param options - Optional configuration for the headless environment.
|
|
44
|
+
* @param options.startUrl - The initial URL for the headless environment. Defaults to 'https://example.com'.
|
|
45
|
+
* @param options.selector - The selector used to find the root element in the headless environment. Defaults to ':root'.
|
|
46
|
+
* @returns An object containing the clear function, root element, and current URL Signal of the headless environment.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
39
49
|
export declare const runHeadless: (makeRenderable: () => Renderable, { startUrl, selector, }?: {
|
|
40
50
|
startUrl?: Value<string>;
|
|
41
51
|
selector?: string;
|
|
@@ -51,3 +61,173 @@ export declare const runHeadless: (makeRenderable: () => Renderable, { startUrl,
|
|
|
51
61
|
export declare class RenderingError extends Error {
|
|
52
62
|
constructor(message: string);
|
|
53
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export declare const _NODE_PLACEHOLDER_ATTR = "data-tts-node";
|
|
68
|
+
export declare const CLASS_PLACEHOLDER_ATTR = "data-tts-class";
|
|
69
|
+
/**
|
|
70
|
+
* Represents an adapter for headless rendering environments.
|
|
71
|
+
* This class provides methods to interact with elements in a headless context.
|
|
72
|
+
*
|
|
73
|
+
* This class is used to adapt the HeadlesContext to whatever you want to use to render your final HTML.
|
|
74
|
+
* You can use libraries like cheerio to render your HTML.
|
|
75
|
+
*
|
|
76
|
+
* For cheerio an adapter could look like this:
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* const renderWithCheerio = (html: string, root: HeadlessPortal) => {
|
|
80
|
+
* const $ = cheerio.load(html)
|
|
81
|
+
*
|
|
82
|
+
* // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
* const adapter = new HeadlessAdapter<cheerio.Cheerio<any>>({
|
|
84
|
+
* // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
* select: (selector: string): cheerio.Cheerio<any>[] => [$(selector)],
|
|
86
|
+
* getAttribute: (el, name: string) => el.attr(name) ?? null,
|
|
87
|
+
* setAttribute: (el, name: string, value: string | null) => {
|
|
88
|
+
* if (value === null) {
|
|
89
|
+
* el.removeAttr(name)
|
|
90
|
+
* } else {
|
|
91
|
+
* el.attr(name, value)
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* getClass: el => el.attr('class') ?? '',
|
|
95
|
+
* setClass: (el, value: string | null) => {
|
|
96
|
+
* if (value === null) {
|
|
97
|
+
* el.removeAttr('class')
|
|
98
|
+
* } else {
|
|
99
|
+
* el.attr('class', value)
|
|
100
|
+
* }
|
|
101
|
+
* },
|
|
102
|
+
* getStyles: el => el.attr('style') ?? {},
|
|
103
|
+
* setStyles: (el, value: Record<string, string>) => {
|
|
104
|
+
* if (Object.keys(value).length === 0) {
|
|
105
|
+
* el.removeAttr('style')
|
|
106
|
+
* } else {
|
|
107
|
+
* el.css(value)
|
|
108
|
+
* }
|
|
109
|
+
* },
|
|
110
|
+
* appendHTML: (el, html) => el.append(html),
|
|
111
|
+
* getInnerHTML: el => el.html() ?? '',
|
|
112
|
+
* setInnerHTML: (el, html) => el.html(html),
|
|
113
|
+
* getInnerText: el => el.text() ?? '',
|
|
114
|
+
* setInnerText: (el, text) => el.text(text),
|
|
115
|
+
* })
|
|
116
|
+
*
|
|
117
|
+
* adapter.setFromRoot(root, true)
|
|
118
|
+
*
|
|
119
|
+
* return $.html()
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* This function will return the rendered HTML as a string.
|
|
124
|
+
*
|
|
125
|
+
* @typeParam EL - The type of elements in the headless environment.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export declare class HeadlessAdapter<EL> {
|
|
129
|
+
/**
|
|
130
|
+
* Selects elements from the headless environment.
|
|
131
|
+
* @param selector - The selector to select elements from. The supported selectors are CSS selectors whose complexity depends on the adapter implementation.
|
|
132
|
+
* @returns An array of elements.
|
|
133
|
+
*/
|
|
134
|
+
readonly select: (selector: string) => EL[];
|
|
135
|
+
/**
|
|
136
|
+
* Gets the value of an attribute from an element.
|
|
137
|
+
* @param el - The element to get the attribute from.
|
|
138
|
+
* @param attr - The attribute to get the value from.
|
|
139
|
+
* @returns The value of the attribute or null if the attribute is not set.
|
|
140
|
+
*/
|
|
141
|
+
readonly getAttribute: (el: EL, attr: string) => string | null;
|
|
142
|
+
/**
|
|
143
|
+
* Sets the value of an attribute on an element.
|
|
144
|
+
* @param el - The element to set the attribute on.
|
|
145
|
+
* @param attr - The attribute to set the value of.
|
|
146
|
+
* @param value - The value to set the attribute to.
|
|
147
|
+
*/
|
|
148
|
+
readonly setAttribute: (el: EL, attr: string, value: string | null) => void;
|
|
149
|
+
/**
|
|
150
|
+
* Gets the class of an element.
|
|
151
|
+
* @param el - The element to get the class from.
|
|
152
|
+
* @returns The class of the element or an empty string if the class is not set.
|
|
153
|
+
*/
|
|
154
|
+
readonly getClass: (el: EL) => string | null;
|
|
155
|
+
/**
|
|
156
|
+
* Sets the class of an element.
|
|
157
|
+
* @param el - The element to set the class on.
|
|
158
|
+
* @param cls - The class to set.
|
|
159
|
+
*/
|
|
160
|
+
readonly setClass: (el: EL, cls: string | null) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Gets the styles of an element.
|
|
163
|
+
* @param el - The element to get the styles from.
|
|
164
|
+
* @returns The styles of the element.
|
|
165
|
+
*/
|
|
166
|
+
readonly getStyles: (el: EL) => Record<string, string>;
|
|
167
|
+
/**
|
|
168
|
+
* Sets the styles of an element.
|
|
169
|
+
* @param el - The element to set the styles on.
|
|
170
|
+
*/
|
|
171
|
+
readonly setStyles: (el: EL, styles: Record<string, string>) => void;
|
|
172
|
+
/**
|
|
173
|
+
* Appends HTML to an element.
|
|
174
|
+
* @param el - The element to append the HTML to.
|
|
175
|
+
* @param html - The HTML to append.
|
|
176
|
+
*/
|
|
177
|
+
readonly appendHTML: (el: EL, html: string) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Gets the inner HTML of an element.
|
|
180
|
+
* @param el - The element to get the inner HTML from.
|
|
181
|
+
* @returns The inner HTML of the element or an empty string if the inner HTML is not set.
|
|
182
|
+
*/
|
|
183
|
+
readonly getInnerHTML: (el: EL) => string | null;
|
|
184
|
+
/**
|
|
185
|
+
* Sets the inner HTML of an element.
|
|
186
|
+
* @param el - The element to set the inner HTML on.
|
|
187
|
+
* @param html - The inner HTML to set.
|
|
188
|
+
*/
|
|
189
|
+
readonly setInnerHTML: (el: EL, html: string) => void;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the inner text of an element.
|
|
192
|
+
* @param el - The element to get the inner text from.
|
|
193
|
+
* @returns The inner text of the element or an empty string if the inner text is not set.
|
|
194
|
+
*/
|
|
195
|
+
readonly getInnerText: (el: EL) => string | null;
|
|
196
|
+
/**
|
|
197
|
+
* Sets the inner text of an element.
|
|
198
|
+
* @param el - The element to set the inner text on.
|
|
199
|
+
* @param text - The inner text to set.
|
|
200
|
+
*/
|
|
201
|
+
readonly setInnerText: (el: EL, text: string) => void;
|
|
202
|
+
constructor({ select, getAttribute, setAttribute, getClass, setClass, getStyles, setStyles, appendHTML, getInnerHTML, setInnerHTML, getInnerText, setInnerText, }: {
|
|
203
|
+
select: (selector: string) => EL[];
|
|
204
|
+
getAttribute: (el: EL, attr: string) => string | null;
|
|
205
|
+
setAttribute: (el: EL, attr: string, value: string | null) => void;
|
|
206
|
+
getClass: (el: EL) => string | null;
|
|
207
|
+
setClass: (el: EL, cls: string | null) => void;
|
|
208
|
+
getStyles: (el: EL) => Record<string, string>;
|
|
209
|
+
setStyles: (el: EL, styles: Record<string, string>) => void;
|
|
210
|
+
appendHTML: (el: EL, html: string) => void;
|
|
211
|
+
getInnerHTML: (el: EL) => string | null;
|
|
212
|
+
setInnerHTML: (el: EL, html: string) => void;
|
|
213
|
+
getInnerText: (el: EL) => string | null;
|
|
214
|
+
setInnerText: (el: EL, text: string) => void;
|
|
215
|
+
});
|
|
216
|
+
/**
|
|
217
|
+
* Sets the content of the root element from a HeadlessPortal. Generally this will be the same instance that is
|
|
218
|
+
* returned by `runHeadless`.
|
|
219
|
+
*
|
|
220
|
+
* @param root - The HeadlessPortal containing the content to set.
|
|
221
|
+
* @param setPlaceholders - Whether to set placeholders for the content. This allows you to restore the original content
|
|
222
|
+
* when you render on the server and then hydrate on the client.
|
|
223
|
+
*/
|
|
224
|
+
readonly setFromRoot: (root: HeadlessPortal, setPlaceholders: boolean) => void;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Restores all placeholders in the DOM. This function is useful when the HTML is rendered on the server and then
|
|
228
|
+
* hydrated on the client. It restores the original content that was replaced with placeholders during the initial
|
|
229
|
+
* render. When you render on the server side, make sure to call `HeadlessAdapter.setFromRoot` with the result of
|
|
230
|
+
* `runHeadless` and the second parameter `setPlaceholders` to `true`.
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
export declare const restoreTempoPlaceholders: () => void;
|
package/renderable/style.d.ts
CHANGED
|
@@ -418,6 +418,7 @@ export declare const style: {
|
|
|
418
418
|
userSelect: (value: NValue<string>) => Renderable;
|
|
419
419
|
vectorEffect: (value: NValue<string>) => Renderable;
|
|
420
420
|
verticalAlign: (value: NValue<string>) => Renderable;
|
|
421
|
+
viewTransitionName: (value: NValue<string>) => Renderable;
|
|
421
422
|
visibility: (value: NValue<string>) => Renderable;
|
|
422
423
|
webkitAlignContent: (value: NValue<string>) => Renderable;
|
|
423
424
|
webkitAlignItems: (value: NValue<string>) => Renderable;
|
package/std/signal.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ export type AnySignal<T = any> = Signal<T> | Prop<T> | Computed<T>;
|
|
|
14
14
|
export type AtGetter<T> = {
|
|
15
15
|
[K in keyof T]-?: Signal<T[K]>;
|
|
16
16
|
};
|
|
17
|
+
export type ListenerOptions = {
|
|
18
|
+
skipInitial?: boolean;
|
|
19
|
+
once?: boolean;
|
|
20
|
+
abortSignal?: AbortSignal;
|
|
21
|
+
};
|
|
17
22
|
/**
|
|
18
23
|
* Represents a signal that holds a value and notifies its listeners when the value changes.
|
|
19
24
|
* @typeParam T - The type of the value held by the signal.
|
|
@@ -88,8 +93,9 @@ export declare class Signal<T> {
|
|
|
88
93
|
* Returns a function that can be called to unregister the listener.
|
|
89
94
|
*
|
|
90
95
|
* @param listener - The listener function to be called when the value of the signal changes.
|
|
96
|
+
* @param options - Options for the listener.
|
|
91
97
|
*/
|
|
92
|
-
readonly on: (listener: (value: T) => void) => () => void;
|
|
98
|
+
readonly on: (listener: (value: T) => void, options?: ListenerOptions) => () => void;
|
|
93
99
|
/**
|
|
94
100
|
* @internal
|
|
95
101
|
*/
|
|
@@ -391,7 +397,7 @@ export declare const makeComputed: <T>(fn: () => T, dependencies: Array<AnySigna
|
|
|
391
397
|
* @returns A disposable object that can be used to stop the effect.
|
|
392
398
|
* @public
|
|
393
399
|
*/
|
|
394
|
-
export declare const makeEffect: (fn: () => void, signals: Array<AnySignal
|
|
400
|
+
export declare const makeEffect: (fn: () => void, signals: Array<AnySignal>, options?: ListenerOptions) => () => void;
|
|
395
401
|
/**
|
|
396
402
|
* Creates a new Prop object with the specified value and equality function.
|
|
397
403
|
*
|
package/std/value.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GetValueTypes } from '../types/domain';
|
|
2
|
-
import { Signal } from './signal';
|
|
2
|
+
import { ListenerOptions, Signal } from './signal';
|
|
3
3
|
/**
|
|
4
4
|
* Represents a value that can either be a `Signal<T>` or a generic type `T`.
|
|
5
5
|
*
|
|
@@ -75,4 +75,4 @@ export declare const makeComputedOf: <T extends Value<unknown>[]>(...args: T) =>
|
|
|
75
75
|
* @returns A disposable object that can be used to stop the effect.
|
|
76
76
|
* @public
|
|
77
77
|
*/
|
|
78
|
-
export declare const makeEffectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void) => void;
|
|
78
|
+
export declare const makeEffectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: GetValueTypes<T>) => void, options?: ListenerOptions) => () => void;
|