@estjs/template 0.0.15-beta.12 → 0.0.15-beta.14
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 -2
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +87 -43
- package/dist/template.d.ts +87 -43
- package/dist/template.dev.cjs.js +361 -208
- package/dist/template.dev.cjs.js.map +1 -1
- package/dist/template.dev.esm.js +363 -211
- 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 +3 -3
package/dist/template.d.cts
CHANGED
|
@@ -24,30 +24,16 @@ declare function provide<T>(key: InjectionKey<T> | string | number, value: T): v
|
|
|
24
24
|
*/
|
|
25
25
|
declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Scope represents an execution context in the component tree.
|
|
29
|
-
* It manages provides, cleanup functions, and lifecycle hooks.
|
|
30
|
-
*/
|
|
31
27
|
interface Scope {
|
|
32
|
-
/** Unique identifier for debugging */
|
|
33
28
|
readonly id: number;
|
|
34
|
-
/** Parent scope in the hierarchy */
|
|
35
29
|
parent: Scope | null;
|
|
36
|
-
|
|
37
|
-
children: Set<Scope> | null;
|
|
38
|
-
/** Provided values (lazy initialized) */
|
|
30
|
+
children: Scope[] | null;
|
|
39
31
|
provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 */
|
|
32
|
+
cleanup: (() => void)[] | null;
|
|
33
|
+
onMount: (() => void | Promise<void>)[] | null;
|
|
34
|
+
onUpdate: (() => void | Promise<void>)[] | null;
|
|
35
|
+
onDestroy: (() => void | Promise<void>)[] | null;
|
|
49
36
|
isMounted: boolean;
|
|
50
|
-
/** Whether the scope has been destroyed */
|
|
51
37
|
isDestroyed: boolean;
|
|
52
38
|
}
|
|
53
39
|
/**
|
|
@@ -60,13 +46,6 @@ declare function getActiveScope(): Scope | null;
|
|
|
60
46
|
* @param scope - The scope to set as active
|
|
61
47
|
*/
|
|
62
48
|
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
49
|
declare function createScope(parent?: Scope | null): Scope;
|
|
71
50
|
/**
|
|
72
51
|
* Run a function within a scope, ensuring proper cleanup.
|
|
@@ -78,17 +57,42 @@ declare function createScope(parent?: Scope | null): Scope;
|
|
|
78
57
|
*/
|
|
79
58
|
declare function runWithScope<T>(scope: Scope, fn: () => T): T;
|
|
80
59
|
/**
|
|
81
|
-
* Dispose a scope and all
|
|
82
|
-
*
|
|
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).
|
|
83
69
|
*
|
|
84
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
|
+
* ```
|
|
85
78
|
*/
|
|
86
79
|
declare function disposeScope(scope: Scope): void;
|
|
87
80
|
/**
|
|
88
|
-
* Register a cleanup function
|
|
89
|
-
*
|
|
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.
|
|
90
86
|
*
|
|
91
|
-
* @param fn - The cleanup function
|
|
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
|
+
* ```
|
|
92
96
|
*/
|
|
93
97
|
declare function onCleanup(fn: () => void): void;
|
|
94
98
|
|
|
@@ -170,28 +174,54 @@ declare function template(html: string): () => Node;
|
|
|
170
174
|
*/
|
|
171
175
|
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P> | Component<P>, target: string | Element): Component<P> | undefined;
|
|
172
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
|
+
*/
|
|
173
181
|
type LifecycleHook = () => void | Promise<void>;
|
|
174
182
|
/**
|
|
175
183
|
* Register a mount lifecycle hook.
|
|
176
|
-
*
|
|
184
|
+
* Runs after component is mounted and virtual tree is committed.
|
|
185
|
+
* If the scope is already mounted, the hook executes immediately.
|
|
177
186
|
*
|
|
178
|
-
* @
|
|
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
|
+
* ```
|
|
179
195
|
*/
|
|
180
196
|
declare function onMount(hook: LifecycleHook): void;
|
|
181
197
|
/**
|
|
182
|
-
* Register
|
|
183
|
-
*
|
|
198
|
+
* Register an update lifecycle hook.
|
|
199
|
+
* Runs whenever the component re-renders due to prop or state changes.
|
|
184
200
|
*
|
|
185
|
-
* @
|
|
201
|
+
* @throws Error in dev mode if called outside a scope
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* onUpdate(() => {
|
|
205
|
+
* console.log('Component updated');
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
186
208
|
*/
|
|
187
|
-
declare function
|
|
209
|
+
declare function onUpdate(hook: LifecycleHook): void;
|
|
188
210
|
/**
|
|
189
|
-
* Register
|
|
190
|
-
*
|
|
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.
|
|
191
214
|
*
|
|
192
|
-
* @
|
|
215
|
+
* @throws Error in dev mode if called outside a scope
|
|
216
|
+
* @example
|
|
217
|
+
* ```tsx
|
|
218
|
+
* onDestroy(() => {
|
|
219
|
+
* unsubscribe();
|
|
220
|
+
* clearTimeout(timerId);
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
193
223
|
*/
|
|
194
|
-
declare function
|
|
224
|
+
declare function onDestroy(hook: LifecycleHook): void;
|
|
195
225
|
|
|
196
226
|
/**
|
|
197
227
|
* Add event listener with automatic cleanup on scope destruction
|
|
@@ -217,7 +247,6 @@ declare function bindElement(node: Element, key: string, defaultValue: unknown,
|
|
|
217
247
|
* @param parent Parent node
|
|
218
248
|
* @param nodeFactory Node factory function or static node
|
|
219
249
|
* @param before Reference node for insertion position
|
|
220
|
-
* @param options Insertion options
|
|
221
250
|
*
|
|
222
251
|
* @example
|
|
223
252
|
* ```typescript
|
|
@@ -578,4 +607,19 @@ interface ResourceOptions<T> {
|
|
|
578
607
|
*/
|
|
579
608
|
declare function createResource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
|
|
580
609
|
|
|
581
|
-
|
|
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
|
+
}
|
|
616
|
+
/**
|
|
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
|
|
621
|
+
*/
|
|
622
|
+
declare function For<T>(props: ForProps<T>): Node;
|
|
623
|
+
declare namespace For { }
|
|
624
|
+
|
|
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 };
|
package/dist/template.d.ts
CHANGED
|
@@ -24,30 +24,16 @@ declare function provide<T>(key: InjectionKey<T> | string | number, value: T): v
|
|
|
24
24
|
*/
|
|
25
25
|
declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Scope represents an execution context in the component tree.
|
|
29
|
-
* It manages provides, cleanup functions, and lifecycle hooks.
|
|
30
|
-
*/
|
|
31
27
|
interface Scope {
|
|
32
|
-
/** Unique identifier for debugging */
|
|
33
28
|
readonly id: number;
|
|
34
|
-
/** Parent scope in the hierarchy */
|
|
35
29
|
parent: Scope | null;
|
|
36
|
-
|
|
37
|
-
children: Set<Scope> | null;
|
|
38
|
-
/** Provided values (lazy initialized) */
|
|
30
|
+
children: Scope[] | null;
|
|
39
31
|
provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 */
|
|
32
|
+
cleanup: (() => void)[] | null;
|
|
33
|
+
onMount: (() => void | Promise<void>)[] | null;
|
|
34
|
+
onUpdate: (() => void | Promise<void>)[] | null;
|
|
35
|
+
onDestroy: (() => void | Promise<void>)[] | null;
|
|
49
36
|
isMounted: boolean;
|
|
50
|
-
/** Whether the scope has been destroyed */
|
|
51
37
|
isDestroyed: boolean;
|
|
52
38
|
}
|
|
53
39
|
/**
|
|
@@ -60,13 +46,6 @@ declare function getActiveScope(): Scope | null;
|
|
|
60
46
|
* @param scope - The scope to set as active
|
|
61
47
|
*/
|
|
62
48
|
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
49
|
declare function createScope(parent?: Scope | null): Scope;
|
|
71
50
|
/**
|
|
72
51
|
* Run a function within a scope, ensuring proper cleanup.
|
|
@@ -78,17 +57,42 @@ declare function createScope(parent?: Scope | null): Scope;
|
|
|
78
57
|
*/
|
|
79
58
|
declare function runWithScope<T>(scope: Scope, fn: () => T): T;
|
|
80
59
|
/**
|
|
81
|
-
* Dispose a scope and all
|
|
82
|
-
*
|
|
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).
|
|
83
69
|
*
|
|
84
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
|
+
* ```
|
|
85
78
|
*/
|
|
86
79
|
declare function disposeScope(scope: Scope): void;
|
|
87
80
|
/**
|
|
88
|
-
* Register a cleanup function
|
|
89
|
-
*
|
|
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.
|
|
90
86
|
*
|
|
91
|
-
* @param fn - The cleanup function
|
|
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
|
+
* ```
|
|
92
96
|
*/
|
|
93
97
|
declare function onCleanup(fn: () => void): void;
|
|
94
98
|
|
|
@@ -170,28 +174,54 @@ declare function template(html: string): () => Node;
|
|
|
170
174
|
*/
|
|
171
175
|
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P> | Component<P>, target: string | Element): Component<P> | undefined;
|
|
172
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
|
+
*/
|
|
173
181
|
type LifecycleHook = () => void | Promise<void>;
|
|
174
182
|
/**
|
|
175
183
|
* Register a mount lifecycle hook.
|
|
176
|
-
*
|
|
184
|
+
* Runs after component is mounted and virtual tree is committed.
|
|
185
|
+
* If the scope is already mounted, the hook executes immediately.
|
|
177
186
|
*
|
|
178
|
-
* @
|
|
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
|
+
* ```
|
|
179
195
|
*/
|
|
180
196
|
declare function onMount(hook: LifecycleHook): void;
|
|
181
197
|
/**
|
|
182
|
-
* Register
|
|
183
|
-
*
|
|
198
|
+
* Register an update lifecycle hook.
|
|
199
|
+
* Runs whenever the component re-renders due to prop or state changes.
|
|
184
200
|
*
|
|
185
|
-
* @
|
|
201
|
+
* @throws Error in dev mode if called outside a scope
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* onUpdate(() => {
|
|
205
|
+
* console.log('Component updated');
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
186
208
|
*/
|
|
187
|
-
declare function
|
|
209
|
+
declare function onUpdate(hook: LifecycleHook): void;
|
|
188
210
|
/**
|
|
189
|
-
* Register
|
|
190
|
-
*
|
|
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.
|
|
191
214
|
*
|
|
192
|
-
* @
|
|
215
|
+
* @throws Error in dev mode if called outside a scope
|
|
216
|
+
* @example
|
|
217
|
+
* ```tsx
|
|
218
|
+
* onDestroy(() => {
|
|
219
|
+
* unsubscribe();
|
|
220
|
+
* clearTimeout(timerId);
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
193
223
|
*/
|
|
194
|
-
declare function
|
|
224
|
+
declare function onDestroy(hook: LifecycleHook): void;
|
|
195
225
|
|
|
196
226
|
/**
|
|
197
227
|
* Add event listener with automatic cleanup on scope destruction
|
|
@@ -217,7 +247,6 @@ declare function bindElement(node: Element, key: string, defaultValue: unknown,
|
|
|
217
247
|
* @param parent Parent node
|
|
218
248
|
* @param nodeFactory Node factory function or static node
|
|
219
249
|
* @param before Reference node for insertion position
|
|
220
|
-
* @param options Insertion options
|
|
221
250
|
*
|
|
222
251
|
* @example
|
|
223
252
|
* ```typescript
|
|
@@ -578,4 +607,19 @@ interface ResourceOptions<T> {
|
|
|
578
607
|
*/
|
|
579
608
|
declare function createResource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
|
|
580
609
|
|
|
581
|
-
|
|
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
|
+
}
|
|
616
|
+
/**
|
|
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
|
|
621
|
+
*/
|
|
622
|
+
declare function For<T>(props: ForProps<T>): Node;
|
|
623
|
+
declare namespace For { }
|
|
624
|
+
|
|
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 };
|