@estjs/template 0.0.15-beta.8 → 0.0.15
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/template.cjs.js +2 -7
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +281 -176
- package/dist/template.d.ts +281 -176
- package/dist/template.dev.cjs.js +785 -742
- package/dist/template.dev.cjs.js.map +1 -0
- package/dist/template.dev.esm.js +767 -734
- package/dist/template.dev.esm.js.map +1 -0
- package/dist/template.esm.js +2 -7
- package/dist/template.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/template.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Signal, Computed } from '@estjs/signals';
|
|
2
|
-
export { escapeHTML } from '@estjs/shared';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* InjectionKey is a unique identifier for provided values.
|
|
@@ -25,40 +24,79 @@ declare function provide<T>(key: InjectionKey<T> | string | number, value: T): v
|
|
|
25
24
|
*/
|
|
26
25
|
declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
27
26
|
|
|
28
|
-
/**
|
|
29
|
-
* Scope represents an execution context in the component tree.
|
|
30
|
-
* It manages provides, cleanup functions, and lifecycle hooks.
|
|
31
|
-
*/
|
|
32
27
|
interface Scope {
|
|
33
|
-
/** Unique identifier for debugging */
|
|
34
28
|
readonly id: number;
|
|
35
|
-
/** Parent scope in the hierarchy */
|
|
36
29
|
parent: Scope | null;
|
|
37
|
-
|
|
38
|
-
children: Set<Scope> | null;
|
|
39
|
-
/** Provided values (lazy initialized) */
|
|
30
|
+
children: Scope[] | null;
|
|
40
31
|
provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/** Update lifecycle hooks (lazy initialized) */
|
|
46
|
-
onUpdate: Set<() => void | Promise<void>> | null;
|
|
47
|
-
/** Destroy lifecycle hooks (lazy initialized) */
|
|
48
|
-
onDestroy: Set<() => void | Promise<void>> | null;
|
|
49
|
-
/** Whether the scope has been mounted */
|
|
32
|
+
cleanup: (() => void)[] | null;
|
|
33
|
+
onMount: (() => void | Promise<void>)[] | null;
|
|
34
|
+
onUpdate: (() => void | Promise<void>)[] | null;
|
|
35
|
+
onDestroy: (() => void | Promise<void>)[] | null;
|
|
50
36
|
isMounted: boolean;
|
|
51
|
-
/** Whether the scope has been destroyed */
|
|
52
37
|
isDestroyed: boolean;
|
|
53
38
|
}
|
|
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;
|
|
54
98
|
|
|
55
|
-
declare
|
|
56
|
-
NORMAL = "normal",
|
|
57
|
-
FRAGMENT = "fragment",
|
|
58
|
-
PORTAL = "portal",
|
|
59
|
-
SUSPENSE = "suspense",
|
|
60
|
-
FOR = "for"
|
|
61
|
-
}
|
|
99
|
+
declare const NORMAL_COMPONENT: unique symbol;
|
|
62
100
|
|
|
63
101
|
type AnyNode = Node | Component<any> | Element | string | number | boolean | null | undefined | AnyNode[] | (() => AnyNode) | Signal<AnyNode> | Computed<AnyNode>;
|
|
64
102
|
type ComponentProps = Record<string, unknown>;
|
|
@@ -72,16 +110,26 @@ declare class Component<P extends ComponentProps = ComponentProps> {
|
|
|
72
110
|
protected parentNode: Node | undefined;
|
|
73
111
|
beforeNode: Node | undefined;
|
|
74
112
|
private reactiveProps;
|
|
113
|
+
private _propSnapshots;
|
|
75
114
|
readonly key: string | undefined;
|
|
76
115
|
protected state: number;
|
|
77
116
|
protected parentScope: Scope | null;
|
|
78
|
-
|
|
117
|
+
readonly [NORMAL_COMPONENT] = true;
|
|
79
118
|
get isConnected(): boolean;
|
|
80
119
|
get firstChild(): Node | undefined;
|
|
81
120
|
constructor(component: ComponentFn<P>, props?: P);
|
|
82
121
|
mount(parentNode: Node, beforeNode?: Node): AnyNode[];
|
|
83
|
-
update(prevNode: Component<
|
|
84
|
-
|
|
122
|
+
update<T extends ComponentProps>(prevNode: Component<T>): Component<T>;
|
|
123
|
+
/**
|
|
124
|
+
* Update reactive props by comparing with current values
|
|
125
|
+
*/
|
|
126
|
+
private _updateReactiveProps;
|
|
127
|
+
private unwrapRenderResult;
|
|
128
|
+
forceUpdate(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get anchor node for insertion
|
|
131
|
+
*/
|
|
132
|
+
private _getAnchorNode;
|
|
85
133
|
/**
|
|
86
134
|
* Destroy component
|
|
87
135
|
*/
|
|
@@ -111,13 +159,7 @@ declare function createComponent<P extends ComponentProps>(componentFn: Componen
|
|
|
111
159
|
* @param html - The HTML string to create template from
|
|
112
160
|
* @returns Factory function that returns a cloned node of the template
|
|
113
161
|
* @throws {Error} When template content is empty or invalid
|
|
114
|
-
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const buttonTemplate = template('<button>Click me</button>');
|
|
118
|
-
* const button1 = buttonTemplate(); // Creates first button instance
|
|
119
|
-
* const button2 = buttonTemplate(); // Creates second button instance
|
|
120
|
-
* ```
|
|
162
|
+
|
|
121
163
|
*/
|
|
122
164
|
declare function template(html: string): () => Node;
|
|
123
165
|
/**
|
|
@@ -129,60 +171,82 @@ declare function template(html: string): () => Node;
|
|
|
129
171
|
* @param component - The root component function to mount
|
|
130
172
|
* @param target - CSS selector string or DOM element to mount to
|
|
131
173
|
* @returns The mount root component instance, or undefined if target not found
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* const App = () => template('<div>Hello World</div>')
|
|
136
|
-
* const app = createApp(App, '#root');
|
|
137
|
-
*
|
|
138
|
-
* // Or with DOM element
|
|
139
|
-
* const container = document.getElementById('app');
|
|
140
|
-
* const app = createApp(App, container);
|
|
141
|
-
* ```
|
|
142
174
|
*/
|
|
143
|
-
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P>, target: string | Element): Component<P> | undefined;
|
|
175
|
+
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P> | Component<P>, target: string | Element): Component<P> | undefined;
|
|
144
176
|
|
|
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
|
+
*/
|
|
145
181
|
type LifecycleHook = () => void | Promise<void>;
|
|
146
182
|
/**
|
|
147
183
|
* Register a mount lifecycle hook.
|
|
148
|
-
*
|
|
184
|
+
* Runs after component is mounted and virtual tree is committed.
|
|
185
|
+
* If the scope is already mounted, the hook executes immediately.
|
|
149
186
|
*
|
|
150
|
-
* @
|
|
187
|
+
* @throws Error in dev mode if called outside a scope
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* onMount(() => {
|
|
191
|
+
* console.log('Component mounted');
|
|
192
|
+
* return () => console.log('Cleanup');
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
151
195
|
*/
|
|
152
196
|
declare function onMount(hook: LifecycleHook): void;
|
|
153
197
|
/**
|
|
154
|
-
* Register
|
|
155
|
-
*
|
|
198
|
+
* Register an update lifecycle hook.
|
|
199
|
+
* Runs whenever the component re-renders due to prop or state changes.
|
|
156
200
|
*
|
|
157
|
-
* @
|
|
201
|
+
* @throws Error in dev mode if called outside a scope
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* onUpdate(() => {
|
|
205
|
+
* console.log('Component updated');
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
158
208
|
*/
|
|
159
|
-
declare function
|
|
209
|
+
declare function onUpdate(hook: LifecycleHook): void;
|
|
160
210
|
/**
|
|
161
|
-
* Register
|
|
162
|
-
*
|
|
211
|
+
* 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.
|
|
163
214
|
*
|
|
164
|
-
* @
|
|
215
|
+
* @throws Error in dev mode if called outside a scope
|
|
216
|
+
* @example
|
|
217
|
+
* ```tsx
|
|
218
|
+
* onDestroy(() => {
|
|
219
|
+
* unsubscribe();
|
|
220
|
+
* clearTimeout(timerId);
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
165
223
|
*/
|
|
166
|
-
declare function
|
|
224
|
+
declare function onDestroy(hook: LifecycleHook): void;
|
|
167
225
|
|
|
168
226
|
/**
|
|
169
227
|
* Add event listener with automatic cleanup on scope destruction
|
|
228
|
+
*
|
|
229
|
+
* @param element - Element to attach listener to
|
|
230
|
+
* @param event - Event name
|
|
231
|
+
* @param handler - Event handler function
|
|
232
|
+
* @param options - Event listener options
|
|
170
233
|
*/
|
|
171
234
|
declare function addEventListener(element: Element, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
|
|
172
235
|
/**
|
|
173
|
-
* Bind an element to a setter function
|
|
236
|
+
* Bind an element to a setter function for two-way data binding
|
|
174
237
|
*
|
|
175
|
-
* @param node The element to bind
|
|
176
|
-
* @param
|
|
238
|
+
* @param node - The element to bind
|
|
239
|
+
* @param key - The property key (unused, kept for API compatibility)
|
|
240
|
+
* @param defaultValue - Default value (unused, kept for API compatibility)
|
|
241
|
+
* @param setter - The setter function to call when the element's value changes
|
|
177
242
|
*/
|
|
178
|
-
declare function bindElement(node: Element, key:
|
|
243
|
+
declare function bindElement(node: Element, key: string, defaultValue: unknown, setter: (value: unknown) => void): void;
|
|
179
244
|
/**
|
|
180
245
|
* Reactive node insertion with binding support
|
|
181
246
|
*
|
|
182
247
|
* @param parent Parent node
|
|
183
248
|
* @param nodeFactory Node factory function or static node
|
|
184
249
|
* @param before Reference node for insertion position
|
|
185
|
-
* @param options Insertion options
|
|
186
250
|
*
|
|
187
251
|
* @example
|
|
188
252
|
* ```typescript
|
|
@@ -194,6 +258,10 @@ declare function bindElement(node: Element, key: any, defaultValue: any, setter:
|
|
|
194
258
|
declare function insert(parent: Node, nodeFactory: AnyNode, before?: Node): AnyNode[] | undefined;
|
|
195
259
|
/**
|
|
196
260
|
* Map nodes from template by indexes
|
|
261
|
+
*
|
|
262
|
+
* @param template - Template node to traverse
|
|
263
|
+
* @param indexes - Array of indexes to map
|
|
264
|
+
* @returns Array of mapped nodes
|
|
197
265
|
*/
|
|
198
266
|
declare function mapNodes(template: Node, indexes: number[]): Node[];
|
|
199
267
|
|
|
@@ -213,6 +281,119 @@ declare function delegateEvents(eventNames: string[], document?: Document): void
|
|
|
213
281
|
*/
|
|
214
282
|
declare function omitProps<T extends object, K extends keyof T>(target: T, keys: K[]): Omit<T, K>;
|
|
215
283
|
|
|
284
|
+
/**
|
|
285
|
+
* DOM manipulation utilities
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Remove node from its parent
|
|
290
|
+
*
|
|
291
|
+
* @param node - Node to remove
|
|
292
|
+
*/
|
|
293
|
+
declare function removeNode(node: AnyNode): void;
|
|
294
|
+
/**
|
|
295
|
+
* Insert child node into parent
|
|
296
|
+
* Handles both component nodes and DOM nodes
|
|
297
|
+
*
|
|
298
|
+
* @param parent - Parent node
|
|
299
|
+
* @param child - Child node to insert
|
|
300
|
+
* @param before - Reference node for insertion position
|
|
301
|
+
*/
|
|
302
|
+
declare function insertNode(parent: Node, child: AnyNode, before?: AnyNode): void;
|
|
303
|
+
/**
|
|
304
|
+
* Replace child node with a new node
|
|
305
|
+
* Handles both component nodes and DOM nodes
|
|
306
|
+
*
|
|
307
|
+
* @param parent - Parent node
|
|
308
|
+
* @param newNode - New node to insert
|
|
309
|
+
* @param oldNode - Old node to be replaced
|
|
310
|
+
*/
|
|
311
|
+
declare function replaceNode(parent: Node, newNode: AnyNode, oldNode: AnyNode): void;
|
|
312
|
+
/**
|
|
313
|
+
* Get the first DOM node from a node or component
|
|
314
|
+
*
|
|
315
|
+
* @param node - Node or component
|
|
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
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Normalize node for reconciliation
|
|
326
|
+
* Converts primitives to text nodes
|
|
327
|
+
*
|
|
328
|
+
* @param node - Node to normalize
|
|
329
|
+
* @returns Normalized DOM node
|
|
330
|
+
*/
|
|
331
|
+
declare function normalizeNode(node: unknown): Node;
|
|
332
|
+
/**
|
|
333
|
+
* Check if two nodes are the same (for reconciliation)
|
|
334
|
+
* Combines key check and type check
|
|
335
|
+
*
|
|
336
|
+
* @param a - First node
|
|
337
|
+
* @param b - Second node
|
|
338
|
+
* @returns true if nodes are considered the same
|
|
339
|
+
*/
|
|
340
|
+
declare function isSameNode(a: AnyNode, b: AnyNode): boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Shallow compare two objects or arrays
|
|
343
|
+
* Performs strict equality check on top-level properties
|
|
344
|
+
*
|
|
345
|
+
* @param a - First value to compare
|
|
346
|
+
* @param b - Second value to compare
|
|
347
|
+
* @returns true if values are shallowly equal
|
|
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
|
|
355
|
+
*/
|
|
356
|
+
declare function getRenderedElement(temp: string): () => Node | null;
|
|
357
|
+
/**
|
|
358
|
+
* Maps server-side rendered nodes during hydration
|
|
359
|
+
* @param {HTMLElement} templateEl - The root template element
|
|
360
|
+
* @param {number[]} idx - Array of indices to map
|
|
361
|
+
* @returns {Node[]} Array of mapped nodes
|
|
362
|
+
*/
|
|
363
|
+
declare function mapSSRNodes(templateEl: HTMLElement, idx: number[]): Node[];
|
|
364
|
+
/**
|
|
365
|
+
* Hydrate a server-rendered component
|
|
366
|
+
* @param {ComponentFn} component - Component function to hydrate
|
|
367
|
+
* @param {HTMLElement | string} container - Container element or selector
|
|
368
|
+
* @returns {any} Component instance or undefined if hydration fails
|
|
369
|
+
*/
|
|
370
|
+
declare function hydrate(component: ComponentFn, container: HTMLElement | string): any;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Start hydration mode
|
|
374
|
+
* Called when beginning client-side hydration of server-rendered content
|
|
375
|
+
*/
|
|
376
|
+
declare function startHydration(): void;
|
|
377
|
+
/**
|
|
378
|
+
* End hydration mode
|
|
379
|
+
* Called when hydration is complete
|
|
380
|
+
*/
|
|
381
|
+
declare function endHydration(): void;
|
|
382
|
+
/**
|
|
383
|
+
* Check if hydration is currently active
|
|
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
|
|
390
|
+
*/
|
|
391
|
+
declare function getHydrationKey(): string;
|
|
392
|
+
/**
|
|
393
|
+
* Reset the hydration key counter
|
|
394
|
+
*/
|
|
395
|
+
declare function resetHydrationKey(): void;
|
|
396
|
+
|
|
216
397
|
/**
|
|
217
398
|
* Patches the class attribute of an element
|
|
218
399
|
* Supports silent hydration (skips DOM updates during hydration phase)
|
|
@@ -226,6 +407,7 @@ declare function omitProps<T extends object, K extends keyof T>(target: T, keys:
|
|
|
226
407
|
declare function patchClass(el: Element, prev: unknown, next: unknown, isSVG?: boolean): void;
|
|
227
408
|
/**
|
|
228
409
|
* Normalizes different class value formats into a single string
|
|
410
|
+
* Re-exports normalizeClassName from shared as normalizeClass for backward compatibility
|
|
229
411
|
*
|
|
230
412
|
* @param value - The class value to normalize
|
|
231
413
|
* @returns A normalized class string
|
|
@@ -286,23 +468,39 @@ interface FragmentProps extends ComponentProps {
|
|
|
286
468
|
children?: AnyNode | AnyNode[];
|
|
287
469
|
}
|
|
288
470
|
/**
|
|
289
|
-
* Fragment component - renders multiple children without wrapper elements
|
|
471
|
+
* Fragment component - renders multiple children without wrapper elements (Client-side only)
|
|
472
|
+
*
|
|
473
|
+
* **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
|
|
290
477
|
*
|
|
291
478
|
* @param props - Component props with children
|
|
292
|
-
* @returns
|
|
479
|
+
* @returns Children directly without wrapper
|
|
293
480
|
*
|
|
294
481
|
* @example
|
|
295
482
|
* ```tsx
|
|
483
|
+
* // Basic usage
|
|
296
484
|
* <Fragment>
|
|
297
485
|
* <div>First</div>
|
|
298
486
|
* <span>Second</span>
|
|
299
487
|
* </Fragment>
|
|
488
|
+
*
|
|
489
|
+
* // Nested fragments
|
|
490
|
+
* <Fragment>
|
|
491
|
+
* <Fragment>
|
|
492
|
+
* <div>Nested 1</div>
|
|
493
|
+
* <div>Nested 2</div>
|
|
494
|
+
* </Fragment>
|
|
495
|
+
* <div>Third</div>
|
|
496
|
+
* </Fragment>
|
|
497
|
+
*
|
|
498
|
+
* // Empty fragment (renders nothing)
|
|
499
|
+
* <Fragment />
|
|
300
500
|
* ```
|
|
301
501
|
*/
|
|
302
502
|
declare function Fragment(props?: FragmentProps): AnyNode;
|
|
303
|
-
declare namespace Fragment {
|
|
304
|
-
var fragment: boolean;
|
|
305
|
-
}
|
|
503
|
+
declare namespace Fragment { }
|
|
306
504
|
/**
|
|
307
505
|
* Check if a node is a Fragment component
|
|
308
506
|
* @param node - Node to check
|
|
@@ -326,12 +524,9 @@ interface PortalProps {
|
|
|
326
524
|
* <Portal target="#modal-root">
|
|
327
525
|
* <div>Modal content</div>
|
|
328
526
|
* </Portal>
|
|
329
|
-
* ```
|
|
330
527
|
*/
|
|
331
528
|
declare function Portal(props: PortalProps): Comment | string;
|
|
332
|
-
declare namespace Portal {
|
|
333
|
-
var portal: boolean;
|
|
334
|
-
}
|
|
529
|
+
declare namespace Portal { }
|
|
335
530
|
/**
|
|
336
531
|
* Check if a node is a Portal component
|
|
337
532
|
* @param node - Node to check
|
|
@@ -347,25 +542,6 @@ interface SuspenseProps {
|
|
|
347
542
|
/** Optional key for reconciliation. */
|
|
348
543
|
key?: string;
|
|
349
544
|
}
|
|
350
|
-
/**
|
|
351
|
-
* Suspense component - handles async content with a fallback UI
|
|
352
|
-
*
|
|
353
|
-
* @param props - Component props with children, fallback, and optional key
|
|
354
|
-
* @returns Placeholder node or fallback content
|
|
355
|
-
*
|
|
356
|
-
* @example
|
|
357
|
-
* ```tsx
|
|
358
|
-
* <Suspense fallback={<div>Loading...</div>}>
|
|
359
|
-
* {asyncContent}
|
|
360
|
-
* </Suspense>
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
declare const SuspenseContext: unique symbol;
|
|
364
|
-
interface SuspenseContextType {
|
|
365
|
-
register: (promise: Promise<any>) => void;
|
|
366
|
-
increment: () => void;
|
|
367
|
-
decrement: () => void;
|
|
368
|
-
}
|
|
369
545
|
/**
|
|
370
546
|
* Suspense component - handles async content with a fallback UI
|
|
371
547
|
*
|
|
@@ -380,9 +556,7 @@ interface SuspenseContextType {
|
|
|
380
556
|
* ```
|
|
381
557
|
*/
|
|
382
558
|
declare function Suspense(props: SuspenseProps): AnyNode;
|
|
383
|
-
declare namespace Suspense {
|
|
384
|
-
var suspense: boolean;
|
|
385
|
-
}
|
|
559
|
+
declare namespace Suspense { }
|
|
386
560
|
/**
|
|
387
561
|
* Check if a node is a Suspense component
|
|
388
562
|
* @param node - Node to check
|
|
@@ -433,88 +607,19 @@ interface ResourceOptions<T> {
|
|
|
433
607
|
*/
|
|
434
608
|
declare function createResource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
|
|
435
609
|
|
|
610
|
+
interface ForProps<T> {
|
|
611
|
+
each: T[] | Signal<T[]> | (() => T[]);
|
|
612
|
+
children: (item: T, index: number) => AnyNode;
|
|
613
|
+
keyFn?: (item: T) => unknown;
|
|
614
|
+
fallback?: () => AnyNode;
|
|
615
|
+
}
|
|
436
616
|
/**
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* function component(props) {
|
|
443
|
-
* // render function props: template, hydrationKey, ...components
|
|
444
|
-
* return render(_tmpl, getHydrationKey(), createSSGComponent(xx, {}));
|
|
445
|
-
* }
|
|
446
|
-
*
|
|
447
|
-
* renderToString(component, props)
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*/
|
|
451
|
-
/**
|
|
452
|
-
* render the component to string
|
|
453
|
-
* @param {ComponentFn} component - the component to render
|
|
454
|
-
* @param {ComponentProps} props - the props to pass to the component
|
|
455
|
-
* @returns {string} the rendered string
|
|
456
|
-
*/
|
|
457
|
-
declare function renderToString(component: ComponentFn, props?: ComponentProps): string;
|
|
458
|
-
/**
|
|
459
|
-
* render the component to string
|
|
460
|
-
* @param {string[]} templates - the template to render
|
|
461
|
-
* @param {string} hydrationKey - the hydration key
|
|
462
|
-
* @param {...string[]} components - the components to render
|
|
463
|
-
* @returns {string} the rendered string
|
|
464
|
-
*/
|
|
465
|
-
declare function render(templates: string[], hydrationKey: string, ...components: string[]): string;
|
|
466
|
-
/**
|
|
467
|
-
* create a ssg component
|
|
468
|
-
* @param {ComponentFn} component - the component to create
|
|
469
|
-
* @param {ComponentProps} props - the props to pass to the component
|
|
470
|
-
* @returns {string} the created component as a string
|
|
471
|
-
*/
|
|
472
|
-
declare function createSSGComponent(component: ComponentFn, props?: ComponentProps): string;
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* get the hydration key
|
|
476
|
-
* @returns {string} the hydration key
|
|
477
|
-
*/
|
|
478
|
-
declare function getHydrationKey(): string;
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Generate server-side rendering attribute string
|
|
482
|
-
*
|
|
483
|
-
* Generate HTML-compatible attribute string based on attribute type, handling special cases:
|
|
484
|
-
* - Automatic unwrapping of reactive values
|
|
485
|
-
* - Normalization of special attributes (style/class)
|
|
486
|
-
* - Ignoring event attributes
|
|
487
|
-
* - Special handling for boolean attributes
|
|
488
|
-
*
|
|
489
|
-
* @param attrName Attribute name
|
|
490
|
-
* @param attrValue Attribute value
|
|
491
|
-
* @param hydrationId Hydration ID (for client-side reuse)
|
|
492
|
-
* @returns Formatted HTML attribute string
|
|
493
|
-
*/
|
|
494
|
-
declare function setSSGAttr(attrName: string, attrValue: any, hydrationId: string): string;
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Server-side node mapping utilities
|
|
498
|
-
*/
|
|
499
|
-
/**
|
|
500
|
-
* getRenderedElement function - gets an element based on string template
|
|
501
|
-
*/
|
|
502
|
-
declare function getRenderedElement(temp: string): () => Node;
|
|
503
|
-
/**
|
|
504
|
-
* Maps server-side rendered nodes during hydration
|
|
505
|
-
* @param {HTMLElement} template - The root template element
|
|
506
|
-
* @param {number[]} idx - Array of indices to map
|
|
507
|
-
* @returns {Node[]} Array of mapped nodes
|
|
508
|
-
*/
|
|
509
|
-
declare function mapSSRNodes(template: HTMLElement, idx: number[]): Node[];
|
|
510
|
-
/**
|
|
511
|
-
* Hydrates a server-rendered component
|
|
512
|
-
*
|
|
513
|
-
* @param {Function} component - Component function to hydrate
|
|
514
|
-
* @param {HTMLElement | string} container - Container element or selector
|
|
515
|
-
* @param {Record<string, unknown>} props - Component properties
|
|
516
|
-
* @returns {any} Component instance or undefined if hydration fails
|
|
617
|
+
* Optimized For Component
|
|
618
|
+
* - Uses createDetachedScope to avoid parent.children Set overhead (SolidJS style)
|
|
619
|
+
* - Uses DocumentFragment batching for mass creation
|
|
620
|
+
* - Inlines scope switching for performance
|
|
517
621
|
*/
|
|
518
|
-
declare function
|
|
622
|
+
declare function For<T>(props: ForProps<T>): Node;
|
|
623
|
+
declare namespace For { }
|
|
519
624
|
|
|
520
|
-
export {
|
|
625
|
+
export { Component, type ComponentFn, type ComponentProps, For, type ForProps, Fragment, type FragmentProps, type InjectionKey, Portal, type PortalProps, type Scope, Suspense, type SuspenseProps, addEvent, addEventListener, bindElement, createApp, createComponent, createResource, createScope, delegateEvents, disposeScope, endHydration, getActiveScope, getFirstDOMNode, getHydrationKey, getRenderedElement, hydrate, inject, insert, insertNode, isComponent, isFragment, isHydrating, isPortal, isSameNode, isSuspense, mapNodes, mapSSRNodes, normalizeClass, normalizeNode, omitProps, onCleanup, onDestroy, onMount, onUpdate, patchAttr, patchClass, patchStyle, provide, removeNode, replaceNode, resetHydrationKey, runWithScope, setActiveScope, setStyle, shallowCompare, startHydration, template };
|