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