@estjs/template 0.0.16-beta.7 → 0.0.16-beta.9
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-GXUTKBCN.js +1 -0
- package/dist/{chunk-OEKE4VTS.dev.esm.js → chunk-W5LMSADN.dev.js} +37 -27
- package/dist/chunk-W5LMSADN.dev.js.map +1 -0
- package/dist/internal.cjs +1 -0
- package/dist/{internal.dev.cjs.js → internal.dev.cjs} +23 -26
- package/dist/internal.dev.cjs.map +1 -0
- package/dist/internal.dev.js +3 -0
- package/dist/{internal.dev.esm.js.map → internal.dev.js.map} +1 -1
- package/dist/internal.js +1 -0
- package/dist/template.cjs +2 -0
- package/dist/template.d.cts +203 -64
- package/dist/template.d.ts +203 -64
- package/dist/{template.dev.cjs.js → template.dev.cjs} +1094 -201
- package/dist/template.dev.cjs.map +1 -0
- package/dist/{template.dev.esm.js → template.dev.js} +1050 -177
- package/dist/template.dev.js.map +1 -0
- package/dist/template.js +2 -0
- package/package.json +21 -22
- package/dist/chunk-IA4OZ7NW.esm.js +0 -1
- package/dist/chunk-OEKE4VTS.dev.esm.js.map +0 -1
- package/dist/internal.cjs.js +0 -1
- package/dist/internal.dev.cjs.js.map +0 -1
- package/dist/internal.dev.esm.js +0 -3
- package/dist/internal.esm.js +0 -1
- package/dist/template.cjs.js +0 -2
- package/dist/template.dev.cjs.js.map +0 -1
- package/dist/template.dev.esm.js.map +0 -1
- package/dist/template.esm.js +0 -2
package/dist/template.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Signal, Computed } from '@estjs/signals';
|
|
2
|
-
import { S as Scope } from './internal-DR5pJGCO.js';
|
|
3
|
-
export {
|
|
2
|
+
import { S as Scope, I as InjectionKey } from './internal-DR5pJGCO.js';
|
|
3
|
+
export { i as inject, p as provide } from './internal-DR5pJGCO.js';
|
|
4
4
|
import { normalizeClassName } from '@estjs/shared';
|
|
5
5
|
|
|
6
6
|
declare enum COMPONENT_STATE {
|
|
@@ -22,13 +22,11 @@ declare enum COMPONENT_TYPE {
|
|
|
22
22
|
FRAGMENT = "fragment",
|
|
23
23
|
PORTAL = "portal",
|
|
24
24
|
SUSPENSE = "suspense",
|
|
25
|
-
FOR = "for"
|
|
25
|
+
FOR = "for",
|
|
26
|
+
TRANSITION = "transition",
|
|
27
|
+
TRANSITION_GROUP = "transition-group"
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
type AnyNode = Node | Component<any> | Element | string | number | boolean | null | undefined | AnyNode[] | (() => AnyNode) | Signal<AnyNode> | Computed<AnyNode>;
|
|
29
|
-
type ComponentProps = Record<string, unknown>;
|
|
30
|
-
type ComponentFn<P = ComponentProps> = (props: P) => AnyNode;
|
|
31
|
-
|
|
32
30
|
declare class Component<P extends ComponentProps = {}> {
|
|
33
31
|
readonly component: ComponentFn<P>;
|
|
34
32
|
props: P;
|
|
@@ -92,56 +90,112 @@ declare function isComponent(node: unknown): node is Component;
|
|
|
92
90
|
*/
|
|
93
91
|
declare function createComponent<P extends ComponentProps>(componentFn: ComponentFn<P>, props?: P): Component<P>;
|
|
94
92
|
|
|
93
|
+
type AnyNode = Node | Component<any> | Element | string | number | boolean | null | undefined | AnyNode[] | (() => AnyNode) | Signal<AnyNode> | Computed<AnyNode>;
|
|
94
|
+
type ComponentProps = Record<string, unknown>;
|
|
95
|
+
type ComponentFn<P = ComponentProps> = (props: P) => AnyNode;
|
|
96
|
+
/** Phase + plugin name passed to error/warn handlers. */
|
|
97
|
+
interface ErrorInfo {
|
|
98
|
+
phase: 'install' | 'mount' | 'cleanup' | 'effect';
|
|
99
|
+
plugin?: string;
|
|
100
|
+
}
|
|
95
101
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
* Application-level configuration. Plugins and user code can set these to
|
|
103
|
+
* customize framework behaviour without monkey-patching internals.
|
|
104
|
+
*/
|
|
105
|
+
interface AppConfig {
|
|
106
|
+
/** Invoked when an uncaught error propagates out of a plugin / lifecycle hook / effect. */
|
|
107
|
+
errorHandler?: (info: ErrorInfo, error: unknown) => void;
|
|
108
|
+
/** Custom warn handler (dev only). When set, framework `warn()` calls are redirected here. */
|
|
109
|
+
warnHandler?: (info: {
|
|
110
|
+
plugin?: string;
|
|
111
|
+
}, message: string) => void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Context passed to every plugin's setup function. Plugins use this to
|
|
115
|
+
* register providers, hook lifecycle events, and report problems.
|
|
116
|
+
*/
|
|
117
|
+
interface AppContext {
|
|
118
|
+
/** Provide a value at the application root scope, retrievable via `inject()`. */
|
|
119
|
+
provide<T>(key: InjectionKey<T> | string | number, value: T): void;
|
|
120
|
+
/** Inject a value from the application scope. Plugins ordered later can read what earlier plugins provided. */
|
|
121
|
+
inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
|
|
122
|
+
/** Register a callback that runs after the root component mounts. */
|
|
123
|
+
onMount(fn: () => void): void;
|
|
124
|
+
/** Register a callback that runs when the application is unmounted. */
|
|
125
|
+
onCleanup(fn: () => void): void;
|
|
126
|
+
/** Non-fatal report. Routed to config.warnHandler if set, otherwise a dev console warning. */
|
|
127
|
+
warn(message: string): void;
|
|
128
|
+
/** Fatal report. Throws — plugin setup fails, mount() rejects. */
|
|
129
|
+
error(message: string): never;
|
|
130
|
+
/** Application config — readable and mutable by plugins. */
|
|
131
|
+
config: AppConfig;
|
|
132
|
+
/** Framework version (injected by the build; empty string in unbundled tests). */
|
|
133
|
+
version: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Plugin definition.
|
|
108
137
|
*
|
|
109
138
|
* @example
|
|
110
|
-
* ```
|
|
111
|
-
* const
|
|
112
|
-
*
|
|
113
|
-
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* const router = definePlugin<{ routes: Route[] }>({
|
|
141
|
+
* name: 'essor:router',
|
|
142
|
+
* enforce: 'pre',
|
|
143
|
+
* setup(ctx, options) {
|
|
144
|
+
* ctx.provide(RouterKey, createRouter(options.routes));
|
|
145
|
+
* },
|
|
146
|
+
* });
|
|
114
147
|
* ```
|
|
115
148
|
*/
|
|
116
|
-
|
|
149
|
+
interface Plugin<TOptions = void> {
|
|
150
|
+
/** Required. Used for dedup, error messages, ordering. */
|
|
151
|
+
name: string;
|
|
152
|
+
/** Coarse ordering bucket. Default 'default'. Order: pre → default → post; within bucket, array order wins. */
|
|
153
|
+
enforce?: 'pre' | 'default' | 'post';
|
|
154
|
+
/** Setup. May be async; mount() awaits it. */
|
|
155
|
+
setup(ctx: AppContext, options: TOptions): void | Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
/** Plugin entry in `CreateAppOptions.plugins` — bare or paired with options. */
|
|
158
|
+
type PluginEntry = Plugin<void> | readonly [Plugin<any>, unknown];
|
|
159
|
+
/** Options accepted by the config-object form of `createApp(component, options)`. */
|
|
160
|
+
interface CreateAppOptions {
|
|
161
|
+
plugins?: ReadonlyArray<PluginEntry>;
|
|
162
|
+
config?: Partial<AppConfig>;
|
|
163
|
+
}
|
|
117
164
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* This function initializes an application by mounting a root component
|
|
121
|
-
* to a target DOM element. It handles target validation and cleanup.
|
|
122
|
-
*
|
|
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.
|
|
165
|
+
* Application builder returned by `createApp(component)` or `createApp(component, options)`.
|
|
126
166
|
*
|
|
127
167
|
* @example
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* // Or with DOM element
|
|
133
|
-
* const container = document.getElementById('app');
|
|
134
|
-
* const app = createApp(App, container);
|
|
168
|
+
* ```ts
|
|
169
|
+
* await createApp(App, {
|
|
170
|
+
* plugins: [router, [store, { initial: {} }]],
|
|
171
|
+
* }).mount('#root');
|
|
135
172
|
* ```
|
|
136
173
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
174
|
+
interface App {
|
|
175
|
+
/** Application config. Mutate before mounting to install error/warn handlers. */
|
|
176
|
+
config: AppConfig;
|
|
177
|
+
/** Mount into the DOM. Returns a Promise when any plugin has async setup; sync otherwise. */
|
|
178
|
+
mount(target: string | Element): Promise<AppInstance | undefined> | AppInstance | undefined;
|
|
179
|
+
/** Hydrate over SSR HTML. Returns a Promise when any plugin has async setup; sync otherwise. */
|
|
180
|
+
hydrate(target: string | Element): Promise<AppInstance | undefined> | AppInstance | undefined;
|
|
181
|
+
}
|
|
182
|
+
/** A mounted application instance. */
|
|
183
|
+
interface AppInstance {
|
|
184
|
+
/** The root Component wrapper (undefined if mounting produced raw nodes). */
|
|
185
|
+
root: Component | undefined;
|
|
186
|
+
/** Tear down the application: dispose scopes, remove DOM nodes. */
|
|
143
187
|
unmount: () => void;
|
|
144
|
-
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Create a reusable template factory from an HTML string. Parsed once, cloned per call.
|
|
192
|
+
* Caller is responsible for ensuring `html` is trusted.
|
|
193
|
+
*/
|
|
194
|
+
declare function template(html: string): () => Node;
|
|
195
|
+
declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P>): App;
|
|
196
|
+
declare function createApp<P extends ComponentProps = {}, A extends string | Element | CreateAppOptions = string | Element | CreateAppOptions>(component: ComponentFn<P>, arg: A): A extends string | Element ? AppInstance | undefined : App;
|
|
197
|
+
declare function hydrate<P extends ComponentProps = {}>(component: ComponentFn<P>, target: string | Element): AppInstance | undefined | Promise<AppInstance | undefined>;
|
|
198
|
+
declare function definePlugin<T = void>(plugin: Plugin<T>): Plugin<T>;
|
|
145
199
|
|
|
146
200
|
type LifecycleHook = () => void | Promise<void>;
|
|
147
201
|
/**
|
|
@@ -171,20 +225,21 @@ declare function onDestroy(hook: LifecycleHook): void;
|
|
|
171
225
|
* Modifiers for `bind:*` two-way bindings.
|
|
172
226
|
*
|
|
173
227
|
* - `trim` — strip surrounding whitespace
|
|
174
|
-
* - `number` — coerce numeric strings to numbers (no-op on NaN)
|
|
228
|
+
* - `number` — coerce numeric strings to numbers (no-op on NaN / blank)
|
|
175
229
|
* - `lazy` — commit on `change` instead of `input`
|
|
230
|
+
*
|
|
231
|
+
* Unknown keys are ignored at runtime; the compiler rejects them at build time.
|
|
176
232
|
*/
|
|
177
233
|
interface BindModifiers {
|
|
178
234
|
trim?: boolean;
|
|
179
235
|
number?: boolean;
|
|
180
236
|
lazy?: boolean;
|
|
181
|
-
[key: string]: boolean | undefined;
|
|
182
237
|
}
|
|
183
238
|
/**
|
|
184
239
|
* Creates a two-way binding between a DOM element property and a reactive model.
|
|
185
240
|
*
|
|
186
|
-
* -
|
|
187
|
-
* -
|
|
241
|
+
* - Model → DOM via a reactive `effect()`.
|
|
242
|
+
* - DOM → Model via an event listener that calls `setter`.
|
|
188
243
|
*
|
|
189
244
|
* @param node Target element. `null` is tolerated (no-op).
|
|
190
245
|
* @param prop Bound property (`value` / `checked` / `files` / custom).
|
|
@@ -198,13 +253,13 @@ declare function bindElement(node: Element | null, prop: 'value' | 'checked' | '
|
|
|
198
253
|
* Set up event delegation for specified event types.
|
|
199
254
|
*
|
|
200
255
|
* @param eventNames - Array of event names to delegate.
|
|
201
|
-
* @param document - Document to attach events to (defaults to
|
|
256
|
+
* @param document - Document to attach events to (defaults to the global document).
|
|
202
257
|
*/
|
|
203
258
|
declare function delegateEvents(eventNames: string[], document?: Document): void;
|
|
204
259
|
/**
|
|
205
260
|
* Clear all delegated events from document.
|
|
206
261
|
*
|
|
207
|
-
* @param document - Document to clear events from (defaults to
|
|
262
|
+
* @param document - Document to clear events from (defaults to the global document).
|
|
208
263
|
*/
|
|
209
264
|
declare function clearDelegatedEvents(document?: Document): void;
|
|
210
265
|
/**
|
|
@@ -265,17 +320,7 @@ declare function next(node: Node | null, step?: number): Node | null;
|
|
|
265
320
|
*/
|
|
266
321
|
declare function nthChild(node: Node | null, index: number): Node | null;
|
|
267
322
|
|
|
268
|
-
/**
|
|
269
|
-
* Returns a new hydration key.
|
|
270
|
-
*
|
|
271
|
-
* @returns The new hydration key as a string.
|
|
272
|
-
*/
|
|
273
323
|
declare function getHydrationKey(): string;
|
|
274
|
-
/**
|
|
275
|
-
* Resets the client-side hydration key counter.
|
|
276
|
-
*
|
|
277
|
-
* @returns {void}
|
|
278
|
-
*/
|
|
279
324
|
declare function resetHydrationKey(): void;
|
|
280
325
|
/**
|
|
281
326
|
* Returns whether the runtime is currently in the hydration first-pass.
|
|
@@ -303,6 +348,8 @@ declare function beginHydration(root: Element): void;
|
|
|
303
348
|
* @returns {void}
|
|
304
349
|
*/
|
|
305
350
|
declare function endHydration(): void;
|
|
351
|
+
declare function hydrationMarker(parent: Node | null, index: number): Comment | null;
|
|
352
|
+
declare function hydrationAnchor(parent: Node | null, index: number): Node | null;
|
|
306
353
|
/**
|
|
307
354
|
* Returns a factory function that, when called at component render time:
|
|
308
355
|
* - During hydration: increments the key, looks up the pre-built registry,
|
|
@@ -666,7 +713,7 @@ declare function defineAsyncComponent<P extends ComponentProps = ComponentProps>
|
|
|
666
713
|
interface ForProps<T> {
|
|
667
714
|
each: T[] | Signal<T[]> | (() => T[]);
|
|
668
715
|
children: (item: T, index: number) => AnyNode;
|
|
669
|
-
key?: (item: T) => unknown;
|
|
716
|
+
key?: (item: T, index: number) => unknown;
|
|
670
717
|
fallback?: () => AnyNode;
|
|
671
718
|
}
|
|
672
719
|
/**
|
|
@@ -678,4 +725,96 @@ interface ForProps<T> {
|
|
|
678
725
|
declare function For<T>(props: ForProps<T>): Node;
|
|
679
726
|
declare namespace For { }
|
|
680
727
|
|
|
681
|
-
|
|
728
|
+
interface TransitionProps {
|
|
729
|
+
name?: string;
|
|
730
|
+
css?: boolean;
|
|
731
|
+
type?: 'transition' | 'animation';
|
|
732
|
+
appear?: boolean;
|
|
733
|
+
duration?: number | {
|
|
734
|
+
enter: number;
|
|
735
|
+
leave: number;
|
|
736
|
+
};
|
|
737
|
+
enterFromClass?: string;
|
|
738
|
+
enterActiveClass?: string;
|
|
739
|
+
enterToClass?: string;
|
|
740
|
+
appearFromClass?: string;
|
|
741
|
+
appearActiveClass?: string;
|
|
742
|
+
appearToClass?: string;
|
|
743
|
+
leaveFromClass?: string;
|
|
744
|
+
leaveActiveClass?: string;
|
|
745
|
+
leaveToClass?: string;
|
|
746
|
+
onBeforeEnter?: (el: Element) => void;
|
|
747
|
+
onEnter?: (el: Element, done: () => void) => void;
|
|
748
|
+
onAfterEnter?: (el: Element) => void;
|
|
749
|
+
onEnterCancelled?: (el: Element) => void;
|
|
750
|
+
onBeforeLeave?: (el: Element) => void;
|
|
751
|
+
onLeave?: (el: Element, done: () => void) => void;
|
|
752
|
+
onAfterLeave?: (el: Element) => void;
|
|
753
|
+
onLeaveCancelled?: (el: Element) => void;
|
|
754
|
+
children?: AnyNode | (() => AnyNode);
|
|
755
|
+
}
|
|
756
|
+
declare function Transition(props: TransitionProps): Node;
|
|
757
|
+
/**
|
|
758
|
+
* Check if a node is a Transition component.
|
|
759
|
+
*
|
|
760
|
+
* @param node - Node to check.
|
|
761
|
+
* @returns True if node is a Transition.
|
|
762
|
+
*/
|
|
763
|
+
declare function isTransition(node: unknown): boolean;
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Props for `<TransitionGroup>`.
|
|
767
|
+
*
|
|
768
|
+
* Inherits every enter/leave knob from {@link TransitionProps} (name, css,
|
|
769
|
+
* type, duration, JS hooks, custom class overrides) and adds:
|
|
770
|
+
*
|
|
771
|
+
* - `each` / `key` — same shape as `<For>`; required for stable identity.
|
|
772
|
+
* - `tag` — wrapper element. Required so we have a layout root to measure
|
|
773
|
+
* positions against and to anchor leaving items absolutely. Defaults to
|
|
774
|
+
* `'div'`.
|
|
775
|
+
* - `moveClass` — class applied to elements during the FLIP move animation.
|
|
776
|
+
* Defaults to `${name}-move`.
|
|
777
|
+
* - `children` — render function per item. May return an Element or a
|
|
778
|
+
* Component instance (the latter is mounted, its first rendered Element
|
|
779
|
+
* participates in the animations).
|
|
780
|
+
*
|
|
781
|
+
* `appear` is intentionally NOT supported: items mounted on the initial
|
|
782
|
+
* render do NOT animate. The appear-related props from {@link TransitionProps}
|
|
783
|
+
* are therefore omitted from this type. If you need first-frame animation,
|
|
784
|
+
* mount the group with an empty list and push items after mount.
|
|
785
|
+
*/
|
|
786
|
+
type GroupBaseProps = Omit<TransitionProps, 'children' | 'appear' | 'appearFromClass' | 'appearActiveClass' | 'appearToClass'>;
|
|
787
|
+
interface TransitionGroupProps<T = unknown> extends GroupBaseProps {
|
|
788
|
+
each: T[] | Signal<T[]> | (() => T[]);
|
|
789
|
+
key: (item: T, index: number) => unknown;
|
|
790
|
+
tag?: string;
|
|
791
|
+
moveClass?: string;
|
|
792
|
+
children: (item: T, index: number) => unknown;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Animated keyed list with three coordinated animations:
|
|
796
|
+
*
|
|
797
|
+
* - **enter** — new items fade/slide in using `${name}-enter-*` classes
|
|
798
|
+
* - **leave** — removed items animate out (positioned absolutely so the
|
|
799
|
+
* remaining items can reflow under FLIP), then are detached
|
|
800
|
+
* - **move** — items that stayed but changed position run FLIP: snapshot
|
|
801
|
+
* `getBoundingClientRect()` before reconcile, compute delta after,
|
|
802
|
+
* invert via `transform`, then transition to identity under `moveClass`
|
|
803
|
+
*
|
|
804
|
+
* Each row owns its own scope (mirroring `<For>`), so signals/effects
|
|
805
|
+
* created inside `children()` are torn down when the row leaves.
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
* ```tsx
|
|
809
|
+
* <TransitionGroup name="list" each={items} key={(it) => it.id} tag="ul">
|
|
810
|
+
* {(item) => <li>{item.label}</li>}
|
|
811
|
+
* </TransitionGroup>
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
declare function TransitionGroup<T>(props: TransitionGroupProps<T>): Element;
|
|
815
|
+
/**
|
|
816
|
+
* Type guard for the TransitionGroup component reference.
|
|
817
|
+
*/
|
|
818
|
+
declare function isTransitionGroup(node: unknown): boolean;
|
|
819
|
+
|
|
820
|
+
export { type App, type AppConfig, type AppContext, type AppInstance, type AsyncComponentOptions, Component, type ComponentFn, type ComponentProps, type CreateAppOptions, type ErrorInfo, For, Fragment, InjectionKey, type Plugin, type PluginEntry, Portal, Suspense, Transition, TransitionGroup, type TransitionGroupProps, type TransitionProps, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, definePlugin, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, hydrationAnchor, hydrationMarker, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, isTransition, isTransitionGroup, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, resetHydrationKey, setStyle, template };
|