@estjs/template 0.0.15-beta.13 → 0.0.15-beta.17
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/dist/chunk-3E4EK64L.dev.esm.js +152 -0
- package/dist/chunk-3E4EK64L.dev.esm.js.map +1 -0
- package/dist/chunk-IRDMO5MX.esm.js +2 -0
- package/dist/chunk-IRDMO5MX.esm.js.map +1 -0
- package/dist/internal-Bz6h0aPa.d.cts +84 -0
- package/dist/internal-Bz6h0aPa.d.ts +84 -0
- package/dist/internal.cjs.js +2 -0
- package/dist/internal.cjs.js.map +1 -0
- package/dist/internal.d.cts +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.dev.cjs.js +110 -0
- package/dist/internal.dev.cjs.js.map +1 -0
- package/dist/internal.dev.esm.js +3 -0
- package/dist/internal.dev.esm.js.map +1 -0
- package/dist/internal.esm.js +2 -0
- package/dist/internal.esm.js.map +1 -0
- package/dist/template.cjs.js +2 -2
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +423 -341
- package/dist/template.d.ts +423 -341
- package/dist/template.dev.cjs.js +1464 -1311
- package/dist/template.dev.cjs.js.map +1 -1
- package/dist/template.dev.esm.js +1393 -1381
- package/dist/template.dev.esm.js.map +1 -1
- package/dist/template.esm.js +2 -2
- package/dist/template.esm.js.map +1 -1
- package/package.json +13 -3
package/dist/template.d.cts
CHANGED
|
@@ -1,224 +1,235 @@
|
|
|
1
1
|
import { Signal, Computed } from '@estjs/signals';
|
|
2
|
+
import { S as Scope } from './internal-Bz6h0aPa.cjs';
|
|
3
|
+
export { I as InjectionKey, i as inject, p as provide } from './internal-Bz6h0aPa.cjs';
|
|
4
|
+
import { normalizeClassName } from '@estjs/shared';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
|
|
6
|
+
declare enum COMPONENT_STATE {
|
|
7
|
+
/** Initial state */
|
|
8
|
+
INITIAL = 0,
|
|
9
|
+
/** Mounting */
|
|
10
|
+
MOUNTING = 1,
|
|
11
|
+
/** MOUNTED */
|
|
12
|
+
MOUNTED = 2,
|
|
13
|
+
/** Updating */
|
|
14
|
+
UPDATING = 3,
|
|
15
|
+
/** Destroying */
|
|
16
|
+
DESTROYING = 4,
|
|
17
|
+
/** destroy */
|
|
18
|
+
DESTROYED = 5
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
declare function provide<T>(key: InjectionKey<T> | string | number, value: T): void;
|
|
17
|
-
/**
|
|
18
|
-
* Inject a value from the scope hierarchy.
|
|
19
|
-
* Traverses up the parent chain until finding a matching key.
|
|
20
|
-
*
|
|
21
|
-
* @param key - The injection key
|
|
22
|
-
* @param defaultValue - Default value if key is not found
|
|
23
|
-
* @returns The injected value or default value
|
|
24
|
-
*/
|
|
25
|
-
declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Scope represents an execution context in the component tree.
|
|
29
|
-
* It manages provides, cleanup functions, and lifecycle hooks.
|
|
30
|
-
*/
|
|
31
|
-
interface Scope {
|
|
32
|
-
/** Unique identifier for debugging */
|
|
33
|
-
readonly id: number;
|
|
34
|
-
/** Parent scope in the hierarchy */
|
|
35
|
-
parent: Scope | null;
|
|
36
|
-
/** Child scopes (lazy initialized) */
|
|
37
|
-
children: Set<Scope> | null;
|
|
38
|
-
/** Provided values (lazy initialized) */
|
|
39
|
-
provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
|
|
40
|
-
/** Cleanup functions (lazy initialized) */
|
|
41
|
-
cleanup: Set<() => void> | null;
|
|
42
|
-
/** Mount lifecycle hooks (lazy initialized) */
|
|
43
|
-
onMount: Set<() => void | Promise<void>> | null;
|
|
44
|
-
/** Update lifecycle hooks (lazy initialized) */
|
|
45
|
-
onUpdate: Set<() => void | Promise<void>> | null;
|
|
46
|
-
/** Destroy lifecycle hooks (lazy initialized) */
|
|
47
|
-
onDestroy: Set<() => void | Promise<void>> | null;
|
|
48
|
-
/** Whether the scope has been mounted */
|
|
49
|
-
isMounted: boolean;
|
|
50
|
-
/** Whether the scope has been destroyed */
|
|
51
|
-
isDestroyed: boolean;
|
|
20
|
+
declare enum COMPONENT_TYPE {
|
|
21
|
+
NORMAL = "normal",
|
|
22
|
+
FRAGMENT = "fragment",
|
|
23
|
+
PORTAL = "portal",
|
|
24
|
+
SUSPENSE = "suspense",
|
|
25
|
+
FOR = "for"
|
|
52
26
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Get the currently active scope.
|
|
55
|
-
* @returns The active scope or null if none is active
|
|
56
|
-
*/
|
|
57
|
-
declare function getActiveScope(): Scope | null;
|
|
58
|
-
/**
|
|
59
|
-
* Set the active scope (internal use).
|
|
60
|
-
* @param scope - The scope to set as active
|
|
61
|
-
*/
|
|
62
|
-
declare function setActiveScope(scope: Scope | null): void;
|
|
63
|
-
/**
|
|
64
|
-
* Create a new scope with optional parent.
|
|
65
|
-
* If no parent is provided, uses the current active scope as parent.
|
|
66
|
-
*
|
|
67
|
-
* @param parent - Optional parent scope (defaults to active scope)
|
|
68
|
-
* @returns A new scope instance
|
|
69
|
-
*/
|
|
70
|
-
declare function createScope(parent?: Scope | null): Scope;
|
|
71
|
-
/**
|
|
72
|
-
* Run a function within a scope, ensuring proper cleanup.
|
|
73
|
-
* The previous active scope is restored even if the function throws.
|
|
74
|
-
*
|
|
75
|
-
* @param scope - The scope to run within
|
|
76
|
-
* @param fn - The function to execute
|
|
77
|
-
* @returns The return value of the function
|
|
78
|
-
*/
|
|
79
|
-
declare function runWithScope<T>(scope: Scope, fn: () => T): T;
|
|
80
|
-
/**
|
|
81
|
-
* Dispose a scope and all its children.
|
|
82
|
-
* Children are disposed first (depth-first), then the scope itself.
|
|
83
|
-
*
|
|
84
|
-
* @param scope - The scope to dispose
|
|
85
|
-
*/
|
|
86
|
-
declare function disposeScope(scope: Scope): void;
|
|
87
|
-
/**
|
|
88
|
-
* Register a cleanup function in the current scope.
|
|
89
|
-
* The function will be called when the scope is disposed.
|
|
90
|
-
*
|
|
91
|
-
* @param fn - The cleanup function
|
|
92
|
-
*/
|
|
93
|
-
declare function onCleanup(fn: () => void): void;
|
|
94
|
-
|
|
95
|
-
declare const NORMAL_COMPONENT: unique symbol;
|
|
96
27
|
|
|
97
28
|
type AnyNode = Node | Component<any> | Element | string | number | boolean | null | undefined | AnyNode[] | (() => AnyNode) | Signal<AnyNode> | Computed<AnyNode>;
|
|
98
29
|
type ComponentProps = Record<string, unknown>;
|
|
99
30
|
type ComponentFn<P = ComponentProps> = (props: P) => AnyNode;
|
|
100
31
|
|
|
101
|
-
declare class Component<P extends ComponentProps =
|
|
102
|
-
component: ComponentFn<P>;
|
|
32
|
+
declare class Component<P extends ComponentProps = {}> {
|
|
33
|
+
readonly component: ComponentFn<P>;
|
|
103
34
|
props: P;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
35
|
+
readonly [COMPONENT_TYPE.NORMAL] = true;
|
|
36
|
+
scope: Scope | null;
|
|
37
|
+
state: COMPONENT_STATE;
|
|
107
38
|
beforeNode: Node | undefined;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
get firstChild(): Node | undefined;
|
|
39
|
+
renderedNodes: Node[];
|
|
40
|
+
firstChild: Node | undefined;
|
|
41
|
+
protected parentNode: Node | undefined;
|
|
42
|
+
private readonly parentScope;
|
|
43
|
+
private readonly reactiveProps;
|
|
44
|
+
private rootEventCleanups;
|
|
45
|
+
private rootRefCleanup?;
|
|
116
46
|
constructor(component: ComponentFn<P>, props?: P);
|
|
47
|
+
/**
|
|
48
|
+
* Mount the component into `parentNode` (optionally before `beforeNode`).
|
|
49
|
+
* If already rendered, the existing DOM is re-inserted without re-running
|
|
50
|
+
* the component function.
|
|
51
|
+
*/
|
|
117
52
|
mount(parentNode: Node, beforeNode?: Node): AnyNode[];
|
|
118
|
-
update<T extends ComponentProps>(prevNode: Component<T>): Component<T>;
|
|
119
53
|
/**
|
|
120
|
-
*
|
|
54
|
+
* Re-install props into the same `reactiveProps` container (preserving
|
|
55
|
+
* any closures already holding a reference to it) and re-apply
|
|
56
|
+
* refs/events against the current root element.
|
|
121
57
|
*/
|
|
122
|
-
|
|
123
|
-
private unwrapRenderResult;
|
|
124
|
-
forceUpdate(): void;
|
|
58
|
+
update(props: P): void;
|
|
125
59
|
/**
|
|
126
|
-
*
|
|
60
|
+
* Tear down and re-mount the component at its current insertion point.
|
|
61
|
+
* No-op if the component has never been mounted.
|
|
127
62
|
*/
|
|
128
|
-
|
|
63
|
+
forceUpdate(): void;
|
|
129
64
|
/**
|
|
130
|
-
*
|
|
65
|
+
* Dispose the scope, remove all rendered nodes, and clear bookkeeping.
|
|
66
|
+
* Idempotent: subsequent calls are no-ops.
|
|
131
67
|
*/
|
|
132
68
|
destroy(): void;
|
|
133
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Apply props that bind to the root DOM element rather than flowing into
|
|
71
|
+
* the component body: `ref` (signal/function) and `onXxx` event handlers.
|
|
72
|
+
* The render-facing `reactiveProps` already has those keys; here we just
|
|
73
|
+
* wire them to the actual DOM node.
|
|
74
|
+
*/
|
|
75
|
+
private syncSpecialProps;
|
|
76
|
+
/**
|
|
77
|
+
* Remove all listeners/ref bindings currently attached to the root element.
|
|
78
|
+
*/
|
|
79
|
+
private releaseSpecialProps;
|
|
80
|
+
/**
|
|
81
|
+
* Bind the root ref prop and return a cleanup that restores the previous ref state.
|
|
82
|
+
*/
|
|
83
|
+
private bindRootRef;
|
|
134
84
|
}
|
|
135
85
|
/**
|
|
136
|
-
*
|
|
137
|
-
* @param {unknown} node - the node to check
|
|
138
|
-
* @returns {boolean} true if the node is a component, false otherwise
|
|
86
|
+
* Check if a value is a Component instance.
|
|
139
87
|
*/
|
|
140
88
|
declare function isComponent(node: unknown): node is Component;
|
|
141
89
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* @param {ComponentProps} props - the component props
|
|
145
|
-
* @returns {Component} the component
|
|
90
|
+
* Wrap a component function in a Component instance, or pass an existing
|
|
91
|
+
* Component instance through unchanged.
|
|
146
92
|
*/
|
|
147
93
|
declare function createComponent<P extends ComponentProps>(componentFn: ComponentFn<P>, props?: P): Component<P>;
|
|
148
94
|
|
|
149
95
|
/**
|
|
150
|
-
* Create a template factory function from HTML string
|
|
96
|
+
* Create a template factory function from HTML string.
|
|
151
97
|
*
|
|
152
98
|
* This function creates a reusable template factory that efficiently clones
|
|
153
|
-
* DOM nodes from the provided HTML string. The template is parsed once
|
|
99
|
+
* DOM nodes from the provided HTML string. The template is parsed once.
|
|
154
100
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
|
|
101
|
+
* Security note: `template(html)` is a raw HTML entrypoint. The caller is
|
|
102
|
+
* responsible for ensuring `html` is trusted and not derived from unsanitized
|
|
103
|
+
* user input.
|
|
104
|
+
*
|
|
105
|
+
* @param html - The HTML string to create template from.
|
|
106
|
+
* @returns Factory function that returns a cloned node of the template.
|
|
107
|
+
* @throws {Error} When template content is empty or invalid.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const buttonTemplate = template('<button>Click me</button>');
|
|
112
|
+
* const button1 = buttonTemplate(); // Creates first button instance
|
|
113
|
+
* const button2 = buttonTemplate(); // Creates second button instance
|
|
114
|
+
* ```
|
|
159
115
|
*/
|
|
160
116
|
declare function template(html: string): () => Node;
|
|
161
117
|
/**
|
|
162
|
-
* Create and mount an application with the specified component
|
|
118
|
+
* Create and mount an application with the specified component.
|
|
163
119
|
*
|
|
164
120
|
* This function initializes an application by mounting a root component
|
|
165
121
|
* to a target DOM element. It handles target validation and cleanup.
|
|
166
122
|
*
|
|
167
|
-
* @param component - The root component function to mount
|
|
168
|
-
* @param target - CSS selector string or DOM element to mount to
|
|
169
|
-
* @returns
|
|
123
|
+
* @param component - The root component function to mount.
|
|
124
|
+
* @param target - CSS selector string or DOM element to mount to.
|
|
125
|
+
* @returns Object with root component and unmount function.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const App = () => template('<div>Hello World</div>')
|
|
130
|
+
* const app = createApp(App, '#root');
|
|
131
|
+
*
|
|
132
|
+
* // Or with DOM element
|
|
133
|
+
* const container = document.getElementById('app');
|
|
134
|
+
* const app = createApp(App, container);
|
|
135
|
+
* ```
|
|
170
136
|
*/
|
|
171
|
-
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P
|
|
137
|
+
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P>, target: string | Element): {
|
|
138
|
+
root: Component<{}> | undefined;
|
|
139
|
+
unmount: () => void;
|
|
140
|
+
} | undefined;
|
|
141
|
+
declare function hydrate<P extends ComponentProps = {}>(component: ComponentFn<P>, target: string | Element): {
|
|
142
|
+
root: Component<{}> | undefined;
|
|
143
|
+
unmount: () => void;
|
|
144
|
+
} | undefined;
|
|
172
145
|
|
|
173
146
|
type LifecycleHook = () => void | Promise<void>;
|
|
174
147
|
/**
|
|
175
148
|
* Register a mount lifecycle hook.
|
|
176
|
-
*
|
|
149
|
+
* If the scope is already mounted, the hook is executed immediately.
|
|
177
150
|
*
|
|
178
|
-
* @param hook - The hook function to
|
|
151
|
+
* @param hook - The hook function to register.
|
|
152
|
+
* @returns {void}
|
|
179
153
|
*/
|
|
180
154
|
declare function onMount(hook: LifecycleHook): void;
|
|
155
|
+
/**
|
|
156
|
+
* Register an update lifecycle hook.
|
|
157
|
+
*
|
|
158
|
+
* @param hook - The hook function to register.
|
|
159
|
+
* @returns {void}
|
|
160
|
+
*/
|
|
161
|
+
declare function onUpdate(hook: LifecycleHook): void;
|
|
181
162
|
/**
|
|
182
163
|
* Register a destroy lifecycle hook.
|
|
183
|
-
* Called before the component is removed from the DOM.
|
|
184
164
|
*
|
|
185
|
-
* @param hook - The hook function to
|
|
165
|
+
* @param hook - The hook function to register.
|
|
166
|
+
* @returns {void}
|
|
186
167
|
*/
|
|
187
168
|
declare function onDestroy(hook: LifecycleHook): void;
|
|
169
|
+
|
|
188
170
|
/**
|
|
189
|
-
*
|
|
190
|
-
* Called after the component updates.
|
|
171
|
+
* Modifiers supported by `bind:*` two-way bindings.
|
|
191
172
|
*
|
|
192
|
-
*
|
|
173
|
+
* - `trim` strip surrounding whitespace from string values
|
|
174
|
+
* - `number` coerce numeric strings to numbers (no-op on `NaN`)
|
|
175
|
+
* - `lazy` commit on `change` instead of `input`
|
|
193
176
|
*/
|
|
194
|
-
|
|
177
|
+
interface BindModifiers {
|
|
178
|
+
trim?: boolean;
|
|
179
|
+
number?: boolean;
|
|
180
|
+
lazy?: boolean;
|
|
181
|
+
[key: string]: boolean | undefined;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Synchronizes a DOM element property with a model getter and setter.
|
|
185
|
+
*
|
|
186
|
+
* @param node The element to bind. `null` is tolerated (no-op).
|
|
187
|
+
* @param prop Bound property: `value` / `checked` / `files` / arbitrary.
|
|
188
|
+
* @param getter Reactive getter or static initial value.
|
|
189
|
+
* @param setter Receives the new value when the user edits the DOM.
|
|
190
|
+
* @param modifiers Optional `BindModifiers`.
|
|
191
|
+
*/
|
|
192
|
+
declare function bindElement(node: Element | null, prop: 'value' | 'checked' | 'files' | string, getter: (() => unknown) | unknown, setter: (value: unknown) => void, modifiers?: BindModifiers): void;
|
|
195
193
|
|
|
196
194
|
/**
|
|
197
|
-
*
|
|
195
|
+
* Set up event delegation for specified event types.
|
|
196
|
+
*
|
|
197
|
+
* @param eventNames - Array of event names to delegate.
|
|
198
|
+
* @param document - Document to attach events to (defaults to window.document).
|
|
199
|
+
*/
|
|
200
|
+
declare function delegateEvents(eventNames: string[], document?: Document): void;
|
|
201
|
+
/**
|
|
202
|
+
* Clear all delegated events from document.
|
|
198
203
|
*
|
|
199
|
-
* @param
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
* @param document - Document to clear events from (defaults to window.document).
|
|
205
|
+
*/
|
|
206
|
+
declare function clearDelegatedEvents(document?: Document): void;
|
|
207
|
+
/**
|
|
208
|
+
* Registers an event listener and scopes its cleanup when needed.
|
|
209
|
+
*
|
|
210
|
+
* @param element - The element to add the listener to.
|
|
211
|
+
* @param event - The event name.
|
|
212
|
+
* @param handler - The event handler.
|
|
213
|
+
* @param options - Optional event listener options.
|
|
214
|
+
* @returns {void}
|
|
203
215
|
*/
|
|
204
216
|
declare function addEventListener(element: Element, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
|
|
217
|
+
|
|
205
218
|
/**
|
|
206
|
-
*
|
|
219
|
+
* Omits props from a target object using a proxy.
|
|
207
220
|
*
|
|
208
|
-
* @param
|
|
209
|
-
* @param
|
|
210
|
-
* @
|
|
211
|
-
* @param setter - The setter function to call when the element's value changes
|
|
221
|
+
* @param target - The target object.
|
|
222
|
+
* @param keys - The keys to omit.
|
|
223
|
+
* @returns A proxy that omits specified keys.
|
|
212
224
|
*/
|
|
213
|
-
declare function
|
|
225
|
+
declare function omitProps<T extends object, K extends keyof T>(target: T, keys: K[]): Omit<T, K>;
|
|
226
|
+
|
|
214
227
|
/**
|
|
215
228
|
* Reactive node insertion with binding support
|
|
216
229
|
*
|
|
217
230
|
* @param parent Parent node
|
|
218
231
|
* @param nodeFactory Node factory function or static node
|
|
219
232
|
* @param before Reference node for insertion position
|
|
220
|
-
* @param options Insertion options
|
|
221
|
-
*
|
|
222
233
|
* @example
|
|
223
234
|
* ```typescript
|
|
224
235
|
* insert(container, () => message.value, null);
|
|
@@ -226,212 +237,203 @@ declare function bindElement(node: Element, key: string, defaultValue: unknown,
|
|
|
226
237
|
* insert(container, "Hello World", null); // Direct string support
|
|
227
238
|
* ```
|
|
228
239
|
*/
|
|
229
|
-
declare function insert(parent: Node, nodeFactory: AnyNode, before?: Node):
|
|
240
|
+
declare function insert(parent: Node, nodeFactory: AnyNode, before?: Node): Node[] | undefined;
|
|
230
241
|
/**
|
|
231
|
-
*
|
|
242
|
+
* Returns the first child of a node.
|
|
232
243
|
*
|
|
233
|
-
* @param
|
|
234
|
-
* @
|
|
235
|
-
* @returns Array of mapped nodes
|
|
244
|
+
* @param node - The node to get the child from.
|
|
245
|
+
* @returns The first child node or null.
|
|
236
246
|
*/
|
|
237
|
-
declare function
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Set up event delegation for specified event types
|
|
241
|
-
* @param {string[]} eventNames - Array of event names to delegate
|
|
242
|
-
* @param {Document} document - Document to attach events to (defaults to window.document)
|
|
243
|
-
*/
|
|
244
|
-
declare function delegateEvents(eventNames: string[], document?: Document): void;
|
|
245
|
-
|
|
247
|
+
declare function child(node: Node | null): Node | null;
|
|
246
248
|
/**
|
|
247
|
-
*
|
|
249
|
+
* Returns the next sibling after advancing by `step`.
|
|
248
250
|
*
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* @returns
|
|
251
|
+
* @param node - The starting node.
|
|
252
|
+
* @param step - Number of steps to advance.
|
|
253
|
+
* @returns The resulting sibling node or null.
|
|
252
254
|
*/
|
|
253
|
-
declare function
|
|
254
|
-
|
|
255
|
+
declare function next(node: Node | null, step?: number): Node | null;
|
|
255
256
|
/**
|
|
256
|
-
*
|
|
257
|
+
* Returns the child node at the requested index.
|
|
258
|
+
*
|
|
259
|
+
* @param node - The parent node.
|
|
260
|
+
* @param index - The child index.
|
|
261
|
+
* @returns The child node at index or null.
|
|
257
262
|
*/
|
|
263
|
+
declare function nthChild(node: Node | null, index: number): Node | null;
|
|
258
264
|
|
|
259
265
|
/**
|
|
260
|
-
*
|
|
266
|
+
* Returns a new hydration key.
|
|
261
267
|
*
|
|
262
|
-
* @
|
|
268
|
+
* @returns The new hydration key as a string.
|
|
263
269
|
*/
|
|
264
|
-
declare function
|
|
270
|
+
declare function getHydrationKey(): string;
|
|
265
271
|
/**
|
|
266
|
-
*
|
|
267
|
-
* Handles both component nodes and DOM nodes
|
|
272
|
+
* Resets the client-side hydration key counter.
|
|
268
273
|
*
|
|
269
|
-
* @
|
|
270
|
-
* @param child - Child node to insert
|
|
271
|
-
* @param before - Reference node for insertion position
|
|
274
|
+
* @returns {void}
|
|
272
275
|
*/
|
|
273
|
-
declare function
|
|
276
|
+
declare function resetHydrationKey(): void;
|
|
274
277
|
/**
|
|
275
|
-
*
|
|
276
|
-
* Handles both component nodes and DOM nodes
|
|
278
|
+
* Returns whether the runtime is currently in the hydration first-pass.
|
|
277
279
|
*
|
|
278
|
-
* @
|
|
279
|
-
* @param newNode - New node to insert
|
|
280
|
-
* @param oldNode - Old node to be replaced
|
|
280
|
+
* @returns True while hydrating, false otherwise.
|
|
281
281
|
*/
|
|
282
|
-
declare function
|
|
282
|
+
declare function isHydrating(): boolean;
|
|
283
|
+
/** Pop the next call-site anchor comment, or `null` if exhausted. */
|
|
284
|
+
declare function consumeTeleportAnchor(): Comment | null;
|
|
285
|
+
/** Pop the next teleport block from `target`, returning start/end markers and inner nodes. */
|
|
286
|
+
declare function consumeTeleportBlock(target: Element): {
|
|
287
|
+
start: Comment;
|
|
288
|
+
end: Comment;
|
|
289
|
+
nodes: Node[];
|
|
290
|
+
} | null;
|
|
283
291
|
/**
|
|
284
|
-
*
|
|
292
|
+
* Begins hydration.
|
|
285
293
|
*
|
|
286
|
-
* @param
|
|
287
|
-
* @returns The first DOM node or undefined
|
|
288
|
-
*/
|
|
289
|
-
declare function getFirstDOMNode(node: AnyNode): Node | undefined;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Node normalization and comparison utilities
|
|
294
|
+
* @param root - The root element to hydrate.
|
|
293
295
|
*/
|
|
294
|
-
|
|
296
|
+
declare function beginHydration(root: Element): void;
|
|
295
297
|
/**
|
|
296
|
-
*
|
|
297
|
-
* Converts primitives to text nodes
|
|
298
|
+
* Ends hydration.
|
|
298
299
|
*
|
|
299
|
-
* @
|
|
300
|
-
* @returns Normalized DOM node
|
|
300
|
+
* @returns {void}
|
|
301
301
|
*/
|
|
302
|
-
declare function
|
|
302
|
+
declare function endHydration(): void;
|
|
303
303
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
304
|
+
* Returns a factory function that, when called at component render time:
|
|
305
|
+
* - During hydration: increments the key, looks up the pre-built registry,
|
|
306
|
+
* and returns the ACTUAL SSR DOM node (no cloneNode).
|
|
307
|
+
* - During CSR: clones the parsed template as usual.
|
|
306
308
|
*
|
|
307
|
-
* @param
|
|
308
|
-
* @
|
|
309
|
-
* @returns true if nodes are considered the same
|
|
309
|
+
* @param html - The HTML template string.
|
|
310
|
+
* @returns A factory function that returns a DOM element.
|
|
310
311
|
*/
|
|
311
|
-
declare function
|
|
312
|
+
declare function getRenderedElement(html: string): () => Element;
|
|
312
313
|
/**
|
|
313
|
-
*
|
|
314
|
-
* Performs strict equality check on top-level properties
|
|
314
|
+
* Patches class while considering hydration state.
|
|
315
315
|
*
|
|
316
|
-
* @param
|
|
317
|
-
* @param
|
|
318
|
-
* @
|
|
319
|
-
|
|
320
|
-
declare function shallowCompare(a: unknown, b: unknown): boolean;
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Get rendered element by hydration key or create from template
|
|
324
|
-
* @param {string} temp - the template string
|
|
325
|
-
* @returns {Function} a function that returns the element
|
|
316
|
+
* @param el - The element to patch.
|
|
317
|
+
* @param prev - Previous class value.
|
|
318
|
+
* @param next - Next class value.
|
|
319
|
+
* @param isSVG - Whether the element is an SVG element.
|
|
326
320
|
*/
|
|
327
|
-
declare function
|
|
321
|
+
declare function patchClassHydrate(el: Element, prev: unknown, next: unknown, isSVG?: boolean): void;
|
|
328
322
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
* @param
|
|
332
|
-
* @
|
|
323
|
+
* Patches attribute while considering hydration state.
|
|
324
|
+
*
|
|
325
|
+
* @param el - The element to patch.
|
|
326
|
+
* @param key - The attribute key.
|
|
327
|
+
* @param prev - Previous attribute value.
|
|
328
|
+
* @param next - Next attribute value.
|
|
333
329
|
*/
|
|
334
|
-
declare function
|
|
330
|
+
declare function patchAttrHydrate(el: Element, key: string, prev: unknown, next: unknown): void;
|
|
335
331
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @param
|
|
339
|
-
* @
|
|
332
|
+
* Patches style while considering hydration state.
|
|
333
|
+
*
|
|
334
|
+
* @param el - The element to patch.
|
|
335
|
+
* @param prev - Previous style value.
|
|
336
|
+
* @param next - Next style value.
|
|
340
337
|
*/
|
|
341
|
-
declare function
|
|
338
|
+
declare function patchStyleHydrate(el: HTMLElement, prev: unknown, next?: unknown): void;
|
|
342
339
|
|
|
343
340
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
*
|
|
355
|
-
* @returns true if hydration is in progress
|
|
356
|
-
*/
|
|
357
|
-
declare function isHydrating(): boolean;
|
|
358
|
-
/**
|
|
359
|
-
* Get the hydration key
|
|
360
|
-
* @returns the hydration key string
|
|
341
|
+
* Applies a minimal class update to an element.
|
|
342
|
+
*
|
|
343
|
+
* Class values are normalized into a string first, then written through
|
|
344
|
+
* `className` or `setAttribute('class')` depending on the element type.
|
|
345
|
+
* Hydration stays silent and reuses the server-rendered result by default.
|
|
346
|
+
*
|
|
347
|
+
* @param el - The element to patch.
|
|
348
|
+
* @param prev - Previous class value.
|
|
349
|
+
* @param next - Next class value.
|
|
350
|
+
* @param isSVG - Whether the element is an SVG element.
|
|
351
|
+
* @returns {void}
|
|
361
352
|
*/
|
|
362
|
-
declare function
|
|
353
|
+
declare function patchClass(el: Element, prev: unknown, next: unknown, isSVG?: boolean): void;
|
|
363
354
|
/**
|
|
364
|
-
*
|
|
355
|
+
* Normalizes supported class inputs into a single string.
|
|
365
356
|
*/
|
|
366
|
-
declare
|
|
357
|
+
declare const normalizeClass: typeof normalizeClassName;
|
|
367
358
|
|
|
368
359
|
/**
|
|
369
|
-
*
|
|
370
|
-
* Supports silent hydration (skips DOM updates during hydration phase)
|
|
360
|
+
* Applies a minimal style update to an element.
|
|
371
361
|
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* @param
|
|
376
|
-
* @
|
|
362
|
+
* Supports both string-based and object-based styles, while staying silent
|
|
363
|
+
* during hydration so the server-rendered DOM can be reused.
|
|
364
|
+
*
|
|
365
|
+
* @param el - The element to patch.
|
|
366
|
+
* @param prev - Previous style value.
|
|
367
|
+
* @param next - Next style value.
|
|
368
|
+
* @returns {void}
|
|
377
369
|
*/
|
|
378
|
-
declare function
|
|
370
|
+
declare function patchStyle(el: HTMLElement, prev: unknown, next?: unknown): void;
|
|
379
371
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
372
|
+
* Sets a single style property.
|
|
373
|
+
*
|
|
374
|
+
* Centralizes array-value expansion, CSS variable writes, vendor-prefix
|
|
375
|
+
* resolution, and `!important` handling in one place.
|
|
382
376
|
*
|
|
383
|
-
* @param
|
|
384
|
-
* @
|
|
385
|
-
* @
|
|
377
|
+
* @param style - Target style object.
|
|
378
|
+
* @param name - Style property name.
|
|
379
|
+
* @param val - Style value.
|
|
380
|
+
* @private
|
|
386
381
|
*/
|
|
387
|
-
declare function
|
|
382
|
+
declare function setStyle(style: CSSStyleDeclaration, name: string, val: string | string[]): void;
|
|
388
383
|
|
|
389
384
|
/**
|
|
390
|
-
*
|
|
391
|
-
* Supports silent hydration (skips DOM updates during hydration phase)
|
|
385
|
+
* Supported value types for the attribute patch layer.
|
|
392
386
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
387
|
+
* In addition to primitive values, spread objects are also accepted, so the
|
|
388
|
+
* type keeps `Record<string, unknown>`.
|
|
395
389
|
*/
|
|
396
|
-
|
|
390
|
+
type AttrValue = string | boolean | number | null | undefined | Record<string, unknown>;
|
|
397
391
|
/**
|
|
398
|
-
*
|
|
392
|
+
* Applies a minimal attribute update to an element.
|
|
399
393
|
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
394
|
+
* This is the most general-purpose attribute updater in the template runtime.
|
|
395
|
+
* It is responsible for:
|
|
396
|
+
* - skipping internal reserved fields;
|
|
397
|
+
* - expanding spread attribute objects;
|
|
398
|
+
* - handling boolean attributes and SVG / xlink / xmlns namespaces;
|
|
399
|
+
* - applying basic dangerous-URL protection;
|
|
400
|
+
* - refusing raw HTML sinks such as `innerHTML` / `srcdoc`;
|
|
401
|
+
* - staying silent during hydration to avoid overwriting SSR DOM.
|
|
402
|
+
*
|
|
403
|
+
* @param el - The element to patch.
|
|
404
|
+
* @param key - The attribute key.
|
|
405
|
+
* @param prev - Previous attribute value.
|
|
406
|
+
* @param next - Next attribute value.
|
|
404
407
|
*/
|
|
405
|
-
declare function setStyle(style: CSSStyleDeclaration, name: string, val: string | string[]): void;
|
|
406
|
-
|
|
407
|
-
type AttrValue = string | boolean | number | null | undefined | Record<string, unknown>;
|
|
408
408
|
declare function patchAttr(el: Element, key: string, prev: AttrValue, next: AttrValue): void;
|
|
409
409
|
|
|
410
410
|
/**
|
|
411
|
-
* Extended
|
|
412
|
-
* @public
|
|
411
|
+
* Extended listener options with optional event delegation support.
|
|
413
412
|
*/
|
|
414
413
|
interface EventOptions extends AddEventListenerOptions {
|
|
415
414
|
/**
|
|
416
|
-
*
|
|
417
|
-
*
|
|
415
|
+
* Selector used for event delegation.
|
|
416
|
+
*
|
|
417
|
+
* When provided, the handler only runs if the event target matches the selector.
|
|
418
418
|
*/
|
|
419
419
|
delegate?: string;
|
|
420
420
|
}
|
|
421
421
|
/**
|
|
422
|
-
*
|
|
423
|
-
* @public
|
|
422
|
+
* Cleanup function signature for event listeners.
|
|
424
423
|
*/
|
|
425
424
|
type EventCleanup = () => void;
|
|
426
425
|
/**
|
|
427
|
-
* Adds an event listener to an element with optional delegation
|
|
426
|
+
* Adds an event listener to an element with optional simple delegation.
|
|
427
|
+
*
|
|
428
|
+
* Without `delegate`, this is a thin wrapper around native `addEventListener()`.
|
|
429
|
+
* When `delegate` is provided, the runtime first checks the selector match before
|
|
430
|
+
* dispatching the real handler to the caller.
|
|
428
431
|
*
|
|
429
|
-
* @param el - The element to
|
|
430
|
-
* @param event - The event
|
|
431
|
-
* @param handler - The event handler function
|
|
432
|
-
* @param options -
|
|
433
|
-
* @returns A cleanup function
|
|
434
|
-
* @public
|
|
432
|
+
* @param el - The element to add the listener to.
|
|
433
|
+
* @param event - The name of the event to listen for.
|
|
434
|
+
* @param handler - The event handler function.
|
|
435
|
+
* @param options - Optional event listener options.
|
|
436
|
+
* @returns A cleanup function that removes the listener.
|
|
435
437
|
*/
|
|
436
438
|
declare function addEvent(el: Element, event: string, handler: EventListener, options?: EventOptions): EventCleanup;
|
|
437
439
|
|
|
@@ -439,15 +441,15 @@ interface FragmentProps extends ComponentProps {
|
|
|
439
441
|
children?: AnyNode | AnyNode[];
|
|
440
442
|
}
|
|
441
443
|
/**
|
|
442
|
-
* Fragment component - renders multiple children without wrapper elements (Client-side only)
|
|
444
|
+
* Fragment component - renders multiple children without wrapper elements (Client-side only).
|
|
443
445
|
*
|
|
444
446
|
* **Client-side behavior:**
|
|
445
|
-
* - Returns children directly for rendering
|
|
446
|
-
* - Hydration system matches children using hydration keys
|
|
447
|
-
* - The template system handles array children automatically
|
|
447
|
+
* - Returns children directly for rendering.
|
|
448
|
+
* - Hydration system matches children using hydration keys.
|
|
449
|
+
* - The template system handles array children automatically.
|
|
448
450
|
*
|
|
449
|
-
* @param props - Component props with children
|
|
450
|
-
* @returns Children directly without wrapper
|
|
451
|
+
* @param props - Component props with children.
|
|
452
|
+
* @returns {AnyNode} Children directly without wrapper.
|
|
451
453
|
*
|
|
452
454
|
* @example
|
|
453
455
|
* ```tsx
|
|
@@ -473,51 +475,66 @@ interface FragmentProps extends ComponentProps {
|
|
|
473
475
|
declare function Fragment(props?: FragmentProps): AnyNode;
|
|
474
476
|
declare namespace Fragment { }
|
|
475
477
|
/**
|
|
476
|
-
* Check if a node is a Fragment component
|
|
477
|
-
*
|
|
478
|
-
* @
|
|
478
|
+
* Check if a node is a Fragment component.
|
|
479
|
+
*
|
|
480
|
+
* @param node - Node to check.
|
|
481
|
+
* @returns {boolean} True if node is a Fragment.
|
|
479
482
|
*/
|
|
480
483
|
declare function isFragment(node: unknown): boolean;
|
|
481
484
|
|
|
482
485
|
interface PortalProps {
|
|
486
|
+
/** Children to render at the target location. */
|
|
483
487
|
children?: AnyNode | AnyNode[];
|
|
484
|
-
|
|
485
|
-
|
|
488
|
+
/**
|
|
489
|
+
* Mount target — CSS selector string, `Element`, or reactive getter.
|
|
490
|
+
* When the getter result changes, the Portal re-mounts at the new target.
|
|
491
|
+
*/
|
|
492
|
+
target?: string | Element | (() => string | Element | null | undefined);
|
|
493
|
+
/**
|
|
494
|
+
* When truthy, children render inline at the call site instead of being teleported.
|
|
495
|
+
* May be a static value or a reactive getter.
|
|
496
|
+
*/
|
|
497
|
+
disabled?: boolean | (() => boolean);
|
|
486
498
|
}
|
|
487
499
|
/**
|
|
488
|
-
* Portal
|
|
500
|
+
* Portal — teleports children into a different DOM node.
|
|
501
|
+
*
|
|
502
|
+
* - `disabled=true` renders children inline at the call site.
|
|
503
|
+
* - Otherwise children are teleported into `target`.
|
|
504
|
+
* - Both `target` and `disabled` may be reactive; changes trigger re-mount.
|
|
489
505
|
*
|
|
490
|
-
* @
|
|
491
|
-
* @returns Comment node as placeholder in parent tree
|
|
506
|
+
* @returns A placeholder comment node that marks the call site.
|
|
492
507
|
*
|
|
493
508
|
* @example
|
|
494
509
|
* ```tsx
|
|
495
|
-
* <Portal target="#modal-root">
|
|
510
|
+
* <Portal target="#modal-root" disabled={isMobile}>
|
|
496
511
|
* <div>Modal content</div>
|
|
497
512
|
* </Portal>
|
|
513
|
+
* ```
|
|
498
514
|
*/
|
|
499
|
-
declare function Portal(props: PortalProps): Comment
|
|
515
|
+
declare function Portal(props: PortalProps): Comment;
|
|
500
516
|
declare namespace Portal { }
|
|
501
517
|
/**
|
|
502
|
-
* Check if a node is a Portal component
|
|
503
|
-
*
|
|
504
|
-
* @
|
|
518
|
+
* Check if a node is a Portal component.
|
|
519
|
+
*
|
|
520
|
+
* @param node - Node to check.
|
|
521
|
+
* @returns True if node is a Portal.
|
|
505
522
|
*/
|
|
506
523
|
declare function isPortal(node: unknown): boolean;
|
|
507
524
|
|
|
508
525
|
interface SuspenseProps {
|
|
509
526
|
/** The content to render. Can be a Promise for async loading. */
|
|
510
|
-
children?:
|
|
527
|
+
children?: Node | Node[] | Promise<Node | Node[]>;
|
|
511
528
|
/** Fallback content to display while children is loading (Promise pending). */
|
|
512
|
-
fallback?:
|
|
529
|
+
fallback?: Node;
|
|
513
530
|
/** Optional key for reconciliation. */
|
|
514
531
|
key?: string;
|
|
515
532
|
}
|
|
516
533
|
/**
|
|
517
|
-
* Suspense component - handles async content with a fallback UI
|
|
534
|
+
* Suspense component - handles async content with a fallback UI.
|
|
518
535
|
*
|
|
519
|
-
* @param props - Component props with children, fallback, and optional key
|
|
520
|
-
* @returns Placeholder node or fallback content
|
|
536
|
+
* @param props - Component props with children, fallback, and optional key.
|
|
537
|
+
* @returns {AnyNode} Placeholder node or fallback content.
|
|
521
538
|
*
|
|
522
539
|
* @example
|
|
523
540
|
* ```tsx
|
|
@@ -526,12 +543,13 @@ interface SuspenseProps {
|
|
|
526
543
|
* </Suspense>
|
|
527
544
|
* ```
|
|
528
545
|
*/
|
|
529
|
-
declare function Suspense(props: SuspenseProps):
|
|
546
|
+
declare function Suspense(props: SuspenseProps): Node;
|
|
530
547
|
declare namespace Suspense { }
|
|
531
548
|
/**
|
|
532
|
-
* Check if a node is a Suspense component
|
|
533
|
-
*
|
|
534
|
-
* @
|
|
549
|
+
* Check if a node is a Suspense component.
|
|
550
|
+
*
|
|
551
|
+
* @param node - Node to check.
|
|
552
|
+
* @returns {boolean} True if node is a Suspense.
|
|
535
553
|
*/
|
|
536
554
|
declare function isSuspense(node: unknown): boolean;
|
|
537
555
|
|
|
@@ -550,38 +568,102 @@ interface ResourceOptions<T> {
|
|
|
550
568
|
initialValue?: T;
|
|
551
569
|
}
|
|
552
570
|
/**
|
|
553
|
-
* Create a resource for async data fetching
|
|
554
|
-
* Inspired by SolidJS createResource
|
|
571
|
+
* Create a resource for async data fetching.
|
|
572
|
+
* Inspired by SolidJS createResource.
|
|
573
|
+
*
|
|
574
|
+
* @param fetcher - Function that returns a Promise with the data.
|
|
575
|
+
* @param options - Optional configuration.
|
|
576
|
+
* @returns {[Resource<T>, ResourceActions<T>]} Tuple of [resource, actions].
|
|
577
|
+
*/
|
|
578
|
+
declare function createResource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
|
|
579
|
+
|
|
580
|
+
interface AsyncComponentOptions {
|
|
581
|
+
/**
|
|
582
|
+
* Component to render while the async component is loading.
|
|
583
|
+
* Only shown after `delay` ms has elapsed (prevents flash of loading state).
|
|
584
|
+
*/
|
|
585
|
+
loading?: ComponentFn;
|
|
586
|
+
/**
|
|
587
|
+
* Component to render when the async component fails to load.
|
|
588
|
+
* Receives `{ error, retry }` as props.
|
|
589
|
+
*/
|
|
590
|
+
error?: ComponentFn<{
|
|
591
|
+
error: Error;
|
|
592
|
+
retry: () => void;
|
|
593
|
+
}>;
|
|
594
|
+
/**
|
|
595
|
+
* Delay in ms before showing the `loading` component (default: 200).
|
|
596
|
+
*/
|
|
597
|
+
delay?: number;
|
|
598
|
+
/**
|
|
599
|
+
* Timeout in ms. If loading exceeds this, the error component is shown.
|
|
600
|
+
*/
|
|
601
|
+
timeout?: number;
|
|
602
|
+
/**
|
|
603
|
+
* SSR rendering strategy (default: `'blocking'`).
|
|
604
|
+
*
|
|
605
|
+
* - `'blocking'` — Pre-calls the loader at definition time. If the module
|
|
606
|
+
* resolves before the component body runs (e.g. pre-loaded via
|
|
607
|
+
* `renderToStringAsync`), the real component is inlined in the HTML.
|
|
608
|
+
* - `'client-only'` — Renders `null` on the server; loads only in browser.
|
|
609
|
+
*/
|
|
610
|
+
ssr?: 'blocking' | 'client-only';
|
|
611
|
+
/**
|
|
612
|
+
* Called when loading fails. Useful for logging or error tracking.
|
|
613
|
+
*/
|
|
614
|
+
onError?: (error: Error, retry: () => void) => void;
|
|
615
|
+
}
|
|
616
|
+
type LoaderResult<P> = {
|
|
617
|
+
default: ComponentFn<P>;
|
|
618
|
+
} | ComponentFn<P>;
|
|
619
|
+
/**
|
|
620
|
+
* Define an async (lazy-loaded) component.
|
|
555
621
|
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
* @returns Tuple of [resource, actions]
|
|
622
|
+
* Compatible with client, SSR, and SSG. Integrates with `<Suspense>` via
|
|
623
|
+
* `SuspenseContext` when rendered inside a Suspense boundary.
|
|
559
624
|
*
|
|
560
|
-
* @example
|
|
561
|
-
* ```typescript
|
|
562
|
-
* const [data, { refetch, mutate }] = createResource(
|
|
563
|
-
* () => fetch('/api/user').then(r => r.json()),
|
|
564
|
-
* { initialValue: null }
|
|
565
|
-
* );
|
|
566
625
|
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* console.log(data.state.value);
|
|
626
|
+
* @param loader - The async loader function.
|
|
627
|
+
* @param options - Configuration options.
|
|
628
|
+
* @returns {ComponentFn<P>} The async component wrapper function.
|
|
571
629
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```tsx
|
|
632
|
+
* // Simple
|
|
633
|
+
* const Chart = defineAsyncComponent(() => import('./Chart'));
|
|
634
|
+
*
|
|
635
|
+
* // With options
|
|
636
|
+
* const Chart = defineAsyncComponent(
|
|
637
|
+
* () => import('./Chart'),
|
|
638
|
+
* {
|
|
639
|
+
* loading: () => <Spinner />,
|
|
640
|
+
* error: ({ error, retry }) => (
|
|
641
|
+
* <div>
|
|
642
|
+
* <p>{error.message}</p>
|
|
643
|
+
* <button onClick={retry}>Retry</button>
|
|
644
|
+
* </div>
|
|
645
|
+
* ),
|
|
646
|
+
* delay: 200,
|
|
647
|
+
* timeout: 10_000,
|
|
648
|
+
* }
|
|
649
|
+
* );
|
|
574
650
|
*
|
|
575
|
-
* //
|
|
576
|
-
*
|
|
651
|
+
* // Works standalone or inside Suspense
|
|
652
|
+
* function App() {
|
|
653
|
+
* return (
|
|
654
|
+
* <Suspense fallback={<div>Loading…</div>}>
|
|
655
|
+
* <Chart data={data} />
|
|
656
|
+
* </Suspense>
|
|
657
|
+
* );
|
|
658
|
+
* }
|
|
577
659
|
* ```
|
|
578
660
|
*/
|
|
579
|
-
declare function
|
|
661
|
+
declare function defineAsyncComponent<P extends ComponentProps = ComponentProps>(loader: () => Promise<LoaderResult<P>>, options?: AsyncComponentOptions): ComponentFn<P>;
|
|
580
662
|
|
|
581
663
|
interface ForProps<T> {
|
|
582
664
|
each: T[] | Signal<T[]> | (() => T[]);
|
|
583
665
|
children: (item: T, index: number) => AnyNode;
|
|
584
|
-
|
|
666
|
+
key?: (item: T) => unknown;
|
|
585
667
|
fallback?: () => AnyNode;
|
|
586
668
|
}
|
|
587
669
|
/**
|
|
@@ -593,4 +675,4 @@ interface ForProps<T> {
|
|
|
593
675
|
declare function For<T>(props: ForProps<T>): Node;
|
|
594
676
|
declare namespace For { }
|
|
595
677
|
|
|
596
|
-
export { Component, type ComponentFn, type ComponentProps, For,
|
|
678
|
+
export { type AsyncComponentOptions, Component, type ComponentFn, type ComponentProps, For, Fragment, Portal, Suspense, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, resetHydrationKey, setStyle, template };
|