eleva 1.0.1 → 1.1.0
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/README.md +21 -10
- package/dist/{eleva-plugins.cjs.js → eleva-plugins.cjs} +1002 -292
- package/dist/eleva-plugins.cjs.map +1 -0
- package/dist/eleva-plugins.d.cts +1352 -0
- package/dist/eleva-plugins.d.cts.map +1 -0
- package/dist/eleva-plugins.d.ts +1352 -0
- package/dist/eleva-plugins.d.ts.map +1 -0
- package/dist/{eleva-plugins.esm.js → eleva-plugins.js} +1002 -292
- package/dist/eleva-plugins.js.map +1 -0
- package/dist/eleva-plugins.umd.js +1001 -291
- package/dist/eleva-plugins.umd.js.map +1 -1
- package/dist/eleva-plugins.umd.min.js +1 -1
- package/dist/eleva-plugins.umd.min.js.map +1 -1
- package/dist/{eleva.cjs.js → eleva.cjs} +421 -191
- package/dist/eleva.cjs.map +1 -0
- package/dist/eleva.d.cts +1329 -0
- package/dist/eleva.d.cts.map +1 -0
- package/dist/eleva.d.ts +473 -226
- package/dist/eleva.d.ts.map +1 -0
- package/dist/{eleva.esm.js → eleva.js} +422 -192
- package/dist/eleva.js.map +1 -0
- package/dist/eleva.umd.js +420 -190
- package/dist/eleva.umd.js.map +1 -1
- package/dist/eleva.umd.min.js +1 -1
- package/dist/eleva.umd.min.js.map +1 -1
- package/dist/plugins/attr.cjs +279 -0
- package/dist/plugins/attr.cjs.map +1 -0
- package/dist/plugins/attr.d.cts +101 -0
- package/dist/plugins/attr.d.cts.map +1 -0
- package/dist/plugins/attr.d.ts +101 -0
- package/dist/plugins/attr.d.ts.map +1 -0
- package/dist/plugins/attr.js +276 -0
- package/dist/plugins/attr.js.map +1 -0
- package/dist/plugins/attr.umd.js +111 -22
- package/dist/plugins/attr.umd.js.map +1 -1
- package/dist/plugins/attr.umd.min.js +1 -1
- package/dist/plugins/attr.umd.min.js.map +1 -1
- package/dist/plugins/router.cjs +1873 -0
- package/dist/plugins/router.cjs.map +1 -0
- package/dist/plugins/router.d.cts +1296 -0
- package/dist/plugins/router.d.cts.map +1 -0
- package/dist/plugins/router.d.ts +1296 -0
- package/dist/plugins/router.d.ts.map +1 -0
- package/dist/plugins/router.js +1870 -0
- package/dist/plugins/router.js.map +1 -0
- package/dist/plugins/router.umd.js +482 -186
- package/dist/plugins/router.umd.js.map +1 -1
- package/dist/plugins/router.umd.min.js +1 -1
- package/dist/plugins/router.umd.min.js.map +1 -1
- package/dist/plugins/store.cjs +920 -0
- package/dist/plugins/store.cjs.map +1 -0
- package/dist/plugins/store.d.cts +266 -0
- package/dist/plugins/store.d.cts.map +1 -0
- package/dist/plugins/store.d.ts +266 -0
- package/dist/plugins/store.d.ts.map +1 -0
- package/dist/plugins/store.js +917 -0
- package/dist/plugins/store.js.map +1 -0
- package/dist/plugins/store.umd.js +410 -85
- package/dist/plugins/store.umd.js.map +1 -1
- package/dist/plugins/store.umd.min.js +1 -1
- package/dist/plugins/store.umd.min.js.map +1 -1
- package/package.json +112 -68
- package/src/core/Eleva.js +195 -115
- package/src/index.cjs +10 -0
- package/src/index.js +11 -0
- package/src/modules/Emitter.js +68 -20
- package/src/modules/Renderer.js +82 -20
- package/src/modules/Signal.js +43 -15
- package/src/modules/TemplateEngine.js +50 -9
- package/src/plugins/Attr.js +121 -19
- package/src/plugins/Router.js +526 -181
- package/src/plugins/Store.js +448 -69
- package/src/plugins/index.js +1 -0
- package/types/core/Eleva.d.ts +263 -169
- package/types/core/Eleva.d.ts.map +1 -1
- package/types/index.d.cts +3 -0
- package/types/index.d.cts.map +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.d.ts.map +1 -1
- package/types/modules/Emitter.d.ts +73 -30
- package/types/modules/Emitter.d.ts.map +1 -1
- package/types/modules/Renderer.d.ts +48 -18
- package/types/modules/Renderer.d.ts.map +1 -1
- package/types/modules/Signal.d.ts +44 -16
- package/types/modules/Signal.d.ts.map +1 -1
- package/types/modules/TemplateEngine.d.ts +46 -11
- package/types/modules/TemplateEngine.d.ts.map +1 -1
- package/types/plugins/Attr.d.ts +83 -16
- package/types/plugins/Attr.d.ts.map +1 -1
- package/types/plugins/Router.d.ts +498 -207
- package/types/plugins/Router.d.ts.map +1 -1
- package/types/plugins/Store.d.ts +211 -37
- package/types/plugins/Store.d.ts.map +1 -1
- package/dist/eleva-plugins.cjs.js.map +0 -1
- package/dist/eleva-plugins.esm.js.map +0 -1
- package/dist/eleva.cjs.js.map +0 -1
- package/dist/eleva.esm.js.map +0 -1
package/types/core/Eleva.d.ts
CHANGED
|
@@ -1,167 +1,194 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* Enable debug mode for verbose logging
|
|
5
|
-
* @property {string} [prefix='e']
|
|
6
|
-
* Prefix for component style scoping
|
|
7
|
-
* @property {boolean} [async=true]
|
|
8
|
-
* Enable async component setup
|
|
2
|
+
* Configuration options for the Eleva instance (reserved for future use).
|
|
3
|
+
* @typedef {Record<string, unknown>} ElevaConfig
|
|
9
4
|
*/
|
|
10
5
|
/**
|
|
6
|
+
* Component definition object.
|
|
11
7
|
* @typedef {Object} ComponentDefinition
|
|
12
8
|
* @property {SetupFunction} [setup]
|
|
13
|
-
* Optional setup function that initializes the component's state and returns reactive data
|
|
14
|
-
* @property {TemplateFunction|string} template
|
|
15
|
-
* Required function or string that defines the component's HTML structure
|
|
16
|
-
* @property {StyleFunction|string} [style]
|
|
17
|
-
* Optional function or string that provides
|
|
9
|
+
* Optional setup function that initializes the component's state and returns reactive data.
|
|
10
|
+
* @property {TemplateFunction | string} template
|
|
11
|
+
* Required function or string that defines the component's HTML structure.
|
|
12
|
+
* @property {StyleFunction | string} [style]
|
|
13
|
+
* Optional function or string that provides CSS styles for the component.
|
|
14
|
+
* Styles are preserved across DOM diffs via data-e-style markers.
|
|
18
15
|
* @property {ChildrenMap} [children]
|
|
19
|
-
* Optional object defining nested child components
|
|
16
|
+
* Optional object defining nested child components.
|
|
20
17
|
*/
|
|
21
18
|
/**
|
|
19
|
+
* Setup function that initializes component state.
|
|
22
20
|
* @callback SetupFunction
|
|
23
|
-
* @param {ComponentContext} ctx
|
|
24
|
-
*
|
|
21
|
+
* @param {ComponentContext} ctx
|
|
22
|
+
* The component context with props, emitter, and signal factory.
|
|
23
|
+
* @returns {SetupResult | Promise<SetupResult>}
|
|
24
|
+
* Reactive data and lifecycle hooks.
|
|
25
25
|
*/
|
|
26
26
|
/**
|
|
27
|
+
* Data returned from setup function, may include lifecycle hooks.
|
|
27
28
|
* @typedef {Record<string, unknown> & LifecycleHooks} SetupResult
|
|
28
|
-
* Data returned from setup function, may include lifecycle hooks
|
|
29
29
|
*/
|
|
30
30
|
/**
|
|
31
|
+
* Template function that returns HTML markup.
|
|
31
32
|
* @callback TemplateFunction
|
|
32
|
-
* @param {ComponentContext} ctx
|
|
33
|
-
*
|
|
33
|
+
* @param {ComponentContext & SetupResult} ctx
|
|
34
|
+
* The merged component context and setup data.
|
|
35
|
+
* @returns {string | Promise<string>}
|
|
36
|
+
* HTML template string.
|
|
34
37
|
*/
|
|
35
38
|
/**
|
|
39
|
+
* Style function that returns CSS styles.
|
|
36
40
|
* @callback StyleFunction
|
|
37
|
-
* @param {ComponentContext} ctx
|
|
38
|
-
*
|
|
41
|
+
* @param {ComponentContext & SetupResult} ctx
|
|
42
|
+
* The merged component context and setup data.
|
|
43
|
+
* @returns {string}
|
|
44
|
+
* CSS styles string.
|
|
39
45
|
*/
|
|
40
46
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
47
|
+
* Map of CSS selectors to component definitions or registered component names.
|
|
48
|
+
* @typedef {Record<string, ComponentDefinition | string>} ChildrenMap
|
|
43
49
|
*/
|
|
44
50
|
/**
|
|
51
|
+
* Context passed to component setup function.
|
|
45
52
|
* @typedef {Object} ComponentContext
|
|
46
53
|
* @property {ComponentProps} props
|
|
47
|
-
* Component properties passed during mounting
|
|
54
|
+
* Component properties passed during mounting.
|
|
48
55
|
* @property {Emitter} emitter
|
|
49
|
-
* Event emitter instance for component event handling
|
|
56
|
+
* Event emitter instance for component event handling.
|
|
50
57
|
* @property {SignalFactory} signal
|
|
51
|
-
* Factory function to create reactive Signal instances
|
|
58
|
+
* Factory function to create reactive Signal instances.
|
|
59
|
+
* @description
|
|
60
|
+
* Plugins may extend this context with additional properties (e.g., `ctx.router`, `ctx.store`).
|
|
61
|
+
* @see RouterContext - Router plugin injected context.
|
|
62
|
+
* @see StoreApi - Store plugin injected context.
|
|
52
63
|
*/
|
|
53
64
|
/**
|
|
65
|
+
* Properties passed to a component during mounting.
|
|
54
66
|
* @typedef {Record<string, unknown>} ComponentProps
|
|
55
|
-
* Properties passed to a component during mounting
|
|
56
67
|
*/
|
|
57
68
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
* @param {T} initialValue - The initial value for the signal
|
|
61
|
-
* @returns {Signal<T>} A new Signal instance
|
|
69
|
+
* Factory function to create reactive Signal instances.
|
|
70
|
+
* @typedef {<T>(initialValue: T) => Signal<T>} SignalFactory
|
|
62
71
|
*/
|
|
63
72
|
/**
|
|
73
|
+
* Lifecycle hooks that can be returned from setup function.
|
|
64
74
|
* @typedef {Object} LifecycleHooks
|
|
65
75
|
* @property {LifecycleHook} [onBeforeMount]
|
|
66
|
-
*
|
|
76
|
+
* Called before component mounting.
|
|
67
77
|
* @property {LifecycleHook} [onMount]
|
|
68
|
-
*
|
|
78
|
+
* Called after component mounting.
|
|
69
79
|
* @property {LifecycleHook} [onBeforeUpdate]
|
|
70
|
-
*
|
|
80
|
+
* Called before component update.
|
|
71
81
|
* @property {LifecycleHook} [onUpdate]
|
|
72
|
-
*
|
|
82
|
+
* Called after component update.
|
|
73
83
|
* @property {UnmountHook} [onUnmount]
|
|
74
|
-
*
|
|
84
|
+
* Called during component unmounting.
|
|
75
85
|
*/
|
|
76
86
|
/**
|
|
87
|
+
* Lifecycle hook function.
|
|
77
88
|
* @callback LifecycleHook
|
|
78
|
-
* @param {LifecycleHookContext} ctx
|
|
79
|
-
*
|
|
89
|
+
* @param {LifecycleHookContext} ctx
|
|
90
|
+
* Context with container and component data.
|
|
91
|
+
* @returns {void | Promise<void>}
|
|
80
92
|
*/
|
|
81
93
|
/**
|
|
94
|
+
* Unmount hook function with cleanup resources.
|
|
82
95
|
* @callback UnmountHook
|
|
83
|
-
* @param {UnmountHookContext} ctx
|
|
84
|
-
*
|
|
96
|
+
* @param {UnmountHookContext} ctx
|
|
97
|
+
* Context with cleanup resources.
|
|
98
|
+
* @returns {void | Promise<void>}
|
|
85
99
|
*/
|
|
86
100
|
/**
|
|
101
|
+
* Context passed to lifecycle hooks.
|
|
87
102
|
* @typedef {Object} LifecycleHookContext
|
|
88
103
|
* @property {HTMLElement} container
|
|
89
|
-
* The DOM element where the component is mounted
|
|
104
|
+
* The DOM element where the component is mounted.
|
|
90
105
|
* @property {ComponentContext & SetupResult} context
|
|
91
|
-
* The component's reactive state and context data
|
|
106
|
+
* The component's reactive state and context data.
|
|
92
107
|
*/
|
|
93
108
|
/**
|
|
109
|
+
* Context passed to unmount hook with cleanup resources.
|
|
94
110
|
* @typedef {Object} UnmountHookContext
|
|
95
111
|
* @property {HTMLElement} container
|
|
96
|
-
* The DOM element where the component is mounted
|
|
112
|
+
* The DOM element where the component is mounted.
|
|
97
113
|
* @property {ComponentContext & SetupResult} context
|
|
98
|
-
* The component's reactive state and context data
|
|
114
|
+
* The component's reactive state and context data.
|
|
99
115
|
* @property {CleanupResources} cleanup
|
|
100
|
-
* Object containing cleanup functions and instances
|
|
116
|
+
* Object containing cleanup functions and instances.
|
|
101
117
|
*/
|
|
102
118
|
/**
|
|
119
|
+
* Resources available for cleanup during unmount.
|
|
103
120
|
* @typedef {Object} CleanupResources
|
|
104
|
-
* @property {
|
|
105
|
-
* Signal watcher cleanup functions
|
|
106
|
-
* @property {
|
|
107
|
-
* Event listener cleanup functions
|
|
108
|
-
* @property {
|
|
109
|
-
* Child component instances
|
|
121
|
+
* @property {UnsubscribeFunction[]} watchers
|
|
122
|
+
* Signal watcher cleanup functions.
|
|
123
|
+
* @property {UnsubscribeFunction[]} listeners
|
|
124
|
+
* Event listener cleanup functions.
|
|
125
|
+
* @property {MountResult[]} children
|
|
126
|
+
* Child component instances.
|
|
110
127
|
*/
|
|
111
128
|
/**
|
|
129
|
+
* Result of mounting a component.
|
|
112
130
|
* @typedef {Object} MountResult
|
|
113
131
|
* @property {HTMLElement} container
|
|
114
|
-
* The DOM element where the component is mounted
|
|
132
|
+
* The DOM element where the component is mounted.
|
|
115
133
|
* @property {ComponentContext & SetupResult} data
|
|
116
|
-
* The component's reactive state and context data
|
|
134
|
+
* The component's reactive state and context data.
|
|
117
135
|
* @property {UnmountFunction} unmount
|
|
118
|
-
* Function to clean up and unmount the component
|
|
136
|
+
* Function to clean up and unmount the component.
|
|
119
137
|
*/
|
|
120
138
|
/**
|
|
139
|
+
* Function to unmount a component and clean up resources.
|
|
121
140
|
* @callback UnmountFunction
|
|
122
141
|
* @returns {Promise<void>}
|
|
123
142
|
*/
|
|
124
143
|
/**
|
|
144
|
+
* Function to unsubscribe from events or watchers.
|
|
125
145
|
* @callback UnsubscribeFunction
|
|
126
|
-
* @returns {void|boolean}
|
|
146
|
+
* @returns {void | boolean}
|
|
127
147
|
*/
|
|
128
148
|
/**
|
|
149
|
+
* Plugin interface for extending Eleva.
|
|
129
150
|
* @typedef {Object} ElevaPlugin
|
|
130
|
-
* @property {PluginInstallFunction} install
|
|
131
|
-
* Function that installs the plugin into the Eleva instance
|
|
132
151
|
* @property {string} name
|
|
133
|
-
* Unique identifier name for the plugin
|
|
152
|
+
* Unique identifier name for the plugin.
|
|
153
|
+
* @property {string} [version]
|
|
154
|
+
* Optional version string for the plugin.
|
|
155
|
+
* @property {PluginInstallFunction} install
|
|
156
|
+
* Function that installs the plugin.
|
|
134
157
|
* @property {PluginUninstallFunction} [uninstall]
|
|
135
|
-
* Optional function to uninstall the plugin
|
|
158
|
+
* Optional function to uninstall the plugin.
|
|
136
159
|
*/
|
|
137
160
|
/**
|
|
161
|
+
* Plugin install function.
|
|
138
162
|
* @callback PluginInstallFunction
|
|
139
|
-
* @param {Eleva} eleva
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
163
|
+
* @param {Eleva} eleva
|
|
164
|
+
* The Eleva instance.
|
|
165
|
+
* @param {PluginOptions} [options]
|
|
166
|
+
* Plugin configuration options.
|
|
167
|
+
* @returns {void | Eleva | unknown}
|
|
142
168
|
*/
|
|
143
169
|
/**
|
|
170
|
+
* Plugin uninstall function.
|
|
144
171
|
* @callback PluginUninstallFunction
|
|
145
|
-
* @param {Eleva} eleva
|
|
146
|
-
*
|
|
172
|
+
* @param {Eleva} eleva
|
|
173
|
+
* The Eleva instance.
|
|
174
|
+
* @returns {void | Promise<void>}
|
|
147
175
|
*/
|
|
148
176
|
/**
|
|
177
|
+
* Configuration options passed to a plugin during installation.
|
|
149
178
|
* @typedef {Record<string, unknown>} PluginOptions
|
|
150
|
-
* Configuration options passed to a plugin during installation
|
|
151
179
|
*/
|
|
152
180
|
/**
|
|
153
|
-
*
|
|
154
|
-
* @
|
|
155
|
-
* @returns {void}
|
|
181
|
+
* Handler function for DOM events (e.g., click, input, submit).
|
|
182
|
+
* @typedef {(event: Event) => void} DOMEventHandler
|
|
156
183
|
*/
|
|
157
184
|
/**
|
|
185
|
+
* Common DOM event names (prefixed with @ in templates).
|
|
158
186
|
* @typedef {'click'|'submit'|'input'|'change'|'focus'|'blur'|'keydown'|'keyup'|'keypress'|'mouseenter'|'mouseleave'|'mouseover'|'mouseout'|'mousedown'|'mouseup'|'touchstart'|'touchend'|'touchmove'|'scroll'|'resize'|'load'|'error'|string} DOMEventName
|
|
159
|
-
* Common DOM event names (prefixed with @ in templates)
|
|
160
187
|
*/
|
|
161
188
|
/**
|
|
162
189
|
* @class 🧩 Eleva
|
|
163
190
|
* @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,
|
|
164
|
-
*
|
|
191
|
+
* component styles, and plugin support. Eleva manages component registration, plugin integration,
|
|
165
192
|
* event handling, and DOM rendering with a focus on performance and developer experience.
|
|
166
193
|
*
|
|
167
194
|
* @example
|
|
@@ -191,11 +218,10 @@ export class Eleva {
|
|
|
191
218
|
* Creates a new Eleva instance with the specified name and configuration.
|
|
192
219
|
*
|
|
193
220
|
* @public
|
|
221
|
+
* @constructor
|
|
194
222
|
* @param {string} name - The unique identifier name for this Eleva instance.
|
|
195
|
-
* @param {
|
|
196
|
-
* May include framework-wide settings and default behaviors.
|
|
223
|
+
* @param {ElevaConfig} [config={}] - Optional configuration object for the instance.
|
|
197
224
|
* @throws {Error} If the name is not provided or is not a string.
|
|
198
|
-
* @returns {Eleva} A new Eleva instance.
|
|
199
225
|
*
|
|
200
226
|
* @example
|
|
201
227
|
* const app = new Eleva("myApp");
|
|
@@ -206,19 +232,19 @@ export class Eleva {
|
|
|
206
232
|
* app.mount(document.getElementById("app"), "myComponent", { name: "World" });
|
|
207
233
|
*
|
|
208
234
|
*/
|
|
209
|
-
constructor(name: string, config?:
|
|
210
|
-
/** @public {string} The unique identifier name for this Eleva instance */
|
|
211
|
-
public name: string;
|
|
212
|
-
/** @public {
|
|
213
|
-
public config:
|
|
214
|
-
/** @public {Emitter}
|
|
215
|
-
public emitter: Emitter;
|
|
216
|
-
/** @public {typeof Signal}
|
|
217
|
-
public signal: typeof Signal;
|
|
218
|
-
/** @public {typeof TemplateEngine}
|
|
219
|
-
public templateEngine: typeof TemplateEngine;
|
|
220
|
-
/** @public {Renderer}
|
|
221
|
-
public renderer: Renderer;
|
|
235
|
+
constructor(name: string, config?: ElevaConfig);
|
|
236
|
+
/** @public @readonly {string} The unique identifier name for this Eleva instance */
|
|
237
|
+
public readonly name: string;
|
|
238
|
+
/** @public @readonly {Record<string, unknown>} Configuration object for the Eleva instance */
|
|
239
|
+
public readonly config: ElevaConfig;
|
|
240
|
+
/** @public @readonly {Emitter} Event emitter for handling component events */
|
|
241
|
+
public readonly emitter: Emitter;
|
|
242
|
+
/** @public @readonly {typeof Signal} Signal class for creating reactive state */
|
|
243
|
+
public readonly signal: typeof Signal;
|
|
244
|
+
/** @public @readonly {typeof TemplateEngine} TemplateEngine class for template parsing */
|
|
245
|
+
public readonly templateEngine: typeof TemplateEngine;
|
|
246
|
+
/** @public @readonly {Renderer} Renderer for handling DOM updates and patching */
|
|
247
|
+
public readonly renderer: Renderer;
|
|
222
248
|
/** @private {Map<string, ComponentDefinition>} Registry of all component definitions by name */
|
|
223
249
|
private _components;
|
|
224
250
|
/** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */
|
|
@@ -230,14 +256,16 @@ export class Eleva {
|
|
|
230
256
|
* The plugin's install function will be called with the Eleva instance and provided options.
|
|
231
257
|
* After installation, the plugin will be available for use by components.
|
|
232
258
|
*
|
|
233
|
-
*
|
|
259
|
+
* @note Plugins that wrap core methods (e.g., mount) must be uninstalled in reverse order
|
|
234
260
|
* of installation (LIFO - Last In, First Out) to avoid conflicts.
|
|
235
261
|
*
|
|
236
262
|
* @public
|
|
237
263
|
* @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.
|
|
238
|
-
* @param {
|
|
239
|
-
* @returns {Eleva} The Eleva instance (for method chaining).
|
|
264
|
+
* @param {PluginOptions} [options={}] - Optional configuration options for the plugin.
|
|
265
|
+
* @returns {Eleva | unknown} The Eleva instance (for method chaining) or the result returned by the plugin.
|
|
240
266
|
* @throws {Error} If plugin does not have an install function.
|
|
267
|
+
* @see component - Register components after installing plugins.
|
|
268
|
+
* @see mount - Mount components to the DOM.
|
|
241
269
|
* @example
|
|
242
270
|
* app.use(myPlugin, { option1: "value1" });
|
|
243
271
|
*
|
|
@@ -249,9 +277,7 @@ export class Eleva {
|
|
|
249
277
|
* PluginB.uninstall(app);
|
|
250
278
|
* PluginA.uninstall(app);
|
|
251
279
|
*/
|
|
252
|
-
public use(plugin: ElevaPlugin, options?:
|
|
253
|
-
[x: string]: unknown;
|
|
254
|
-
}): Eleva;
|
|
280
|
+
public use(plugin: ElevaPlugin, options?: PluginOptions): Eleva | unknown;
|
|
255
281
|
/**
|
|
256
282
|
* Registers a new component with the Eleva instance.
|
|
257
283
|
* The component will be available for mounting using its registered name.
|
|
@@ -261,6 +287,7 @@ export class Eleva {
|
|
|
261
287
|
* @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
|
|
262
288
|
* @returns {Eleva} The Eleva instance (for method chaining).
|
|
263
289
|
* @throws {Error} If name is not a non-empty string or definition has no template.
|
|
290
|
+
* @see mount - Mount this component to the DOM.
|
|
264
291
|
* @example
|
|
265
292
|
* app.component("myButton", {
|
|
266
293
|
* template: (ctx) => `<button>${ctx.props.text}</button>`,
|
|
@@ -271,45 +298,57 @@ export class Eleva {
|
|
|
271
298
|
/**
|
|
272
299
|
* Mounts a registered component to a DOM element.
|
|
273
300
|
* This will initialize the component, set up its reactive state, and render it to the DOM.
|
|
301
|
+
* If the container already has a mounted Eleva instance, it is returned as-is.
|
|
302
|
+
* Unmount clears the container contents and removes the internal instance marker.
|
|
274
303
|
*
|
|
275
304
|
* @public
|
|
305
|
+
* @async
|
|
276
306
|
* @param {HTMLElement} container - The DOM element where the component will be mounted.
|
|
277
|
-
* @param {string|ComponentDefinition} compName - The name of the registered component or a direct component definition.
|
|
278
|
-
* @param {
|
|
307
|
+
* @param {string | ComponentDefinition} compName - The name of the registered component or a direct component definition.
|
|
308
|
+
* @param {ComponentProps} [props={}] - Optional properties to pass to the component.
|
|
279
309
|
* @returns {Promise<MountResult>}
|
|
280
310
|
* A Promise that resolves to an object containing:
|
|
281
311
|
* - container: The mounted component's container element
|
|
282
312
|
* - data: The component's reactive state and context
|
|
283
313
|
* - unmount: Function to clean up and unmount the component
|
|
284
314
|
* @throws {Error} If container is not a DOM element or component is not registered.
|
|
315
|
+
* @throws {Error} If setup function, template function, or style function throws.
|
|
285
316
|
* @example
|
|
286
317
|
* const instance = await app.mount(document.getElementById("app"), "myComponent", { text: "Click me" });
|
|
287
318
|
* // Later...
|
|
288
|
-
* instance.unmount();
|
|
319
|
+
* await instance.unmount();
|
|
289
320
|
*/
|
|
290
|
-
public mount(container: HTMLElement, compName: string | ComponentDefinition, props?:
|
|
291
|
-
[x: string]: unknown;
|
|
292
|
-
}): Promise<MountResult>;
|
|
321
|
+
public mount(container: HTMLElement, compName: string | ComponentDefinition, props?: ComponentProps): Promise<MountResult>;
|
|
293
322
|
/**
|
|
294
323
|
* Processes DOM elements for event binding based on attributes starting with "@".
|
|
295
|
-
* This method
|
|
324
|
+
* This method attaches event listeners directly to elements and ensures proper cleanup.
|
|
325
|
+
* Bound `@event` attributes are removed after listeners are attached.
|
|
326
|
+
*
|
|
327
|
+
* Handler resolution order:
|
|
328
|
+
* 1. Direct context property lookup (e.g., context["handleClick"])
|
|
329
|
+
* 2. Template expression evaluation via TemplateEngine (e.g., "increment()")
|
|
296
330
|
*
|
|
297
331
|
* @private
|
|
298
332
|
* @param {HTMLElement} container - The container element in which to search for event attributes.
|
|
299
|
-
* @param {ComponentContext} context - The
|
|
300
|
-
* @param {
|
|
333
|
+
* @param {ComponentContext & SetupResult} context - The merged component context and setup data.
|
|
334
|
+
* @param {UnsubscribeFunction[]} listeners - Array to collect cleanup functions for each event listener.
|
|
301
335
|
* @returns {void}
|
|
336
|
+
* @see TemplateEngine.evaluate - Expression evaluation. fallback.
|
|
302
337
|
*/
|
|
303
338
|
private _processEvents;
|
|
304
339
|
/**
|
|
305
|
-
* Injects
|
|
306
|
-
*
|
|
340
|
+
* Injects styles into the component's container.
|
|
341
|
+
* Styles are placed in a `<style>` element with a `data-e-style` attribute for identification.
|
|
342
|
+
*
|
|
343
|
+
* @note Styles are not automatically scoped - use unique class names or CSS nesting for isolation.
|
|
344
|
+
*
|
|
345
|
+
* Optimization: Skips DOM update if style content hasn't changed.
|
|
307
346
|
*
|
|
308
347
|
* @private
|
|
309
348
|
* @param {HTMLElement} container - The container element where styles should be injected.
|
|
310
349
|
* @param {string} compId - The component ID used to identify the style element.
|
|
311
|
-
* @param {
|
|
312
|
-
* @param {ComponentContext} context - The
|
|
350
|
+
* @param {StyleFunction | string} styleDef - The component's style definition (function or string).
|
|
351
|
+
* @param {ComponentContext & SetupResult} context - The merged component context and setup data.
|
|
313
352
|
* @returns {void}
|
|
314
353
|
*/
|
|
315
354
|
private _injectStyles;
|
|
@@ -317,11 +356,13 @@ export class Eleva {
|
|
|
317
356
|
* Extracts and evaluates props from an element's attributes that start with `:`.
|
|
318
357
|
* Prop values are evaluated as expressions against the component context,
|
|
319
358
|
* allowing direct passing of objects, arrays, and other complex types.
|
|
359
|
+
* Processed attributes are removed from the element after extraction.
|
|
320
360
|
*
|
|
321
361
|
* @private
|
|
322
|
-
* @param {HTMLElement} element - The DOM element to extract props from
|
|
323
|
-
* @param {ComponentContext} context - The component context
|
|
324
|
-
* @returns {
|
|
362
|
+
* @param {HTMLElement} element - The DOM element to extract props from.
|
|
363
|
+
* @param {ComponentContext & SetupResult} context - The merged component context and setup data.
|
|
364
|
+
* @returns {ComponentProps} An object containing the evaluated props.
|
|
365
|
+
* @see TemplateEngine.evaluate - Expression evaluation.
|
|
325
366
|
* @example
|
|
326
367
|
* // For an element with attributes:
|
|
327
368
|
* // <div :name="user.name" :data="items">
|
|
@@ -334,188 +375,241 @@ export class Eleva {
|
|
|
334
375
|
* This method handles mounting of explicitly defined children components.
|
|
335
376
|
*
|
|
336
377
|
* The mounting process follows these steps:
|
|
337
|
-
* 1.
|
|
378
|
+
* 1. Finds matching DOM nodes within the container
|
|
338
379
|
* 2. Mounts explicitly defined children components
|
|
339
380
|
*
|
|
340
381
|
* @private
|
|
341
|
-
* @
|
|
342
|
-
* @param {
|
|
343
|
-
* @param {
|
|
344
|
-
* @param {
|
|
382
|
+
* @async
|
|
383
|
+
* @param {HTMLElement} container - The container element to mount components in.
|
|
384
|
+
* @param {ChildrenMap} children - Map of selectors to component definitions for explicit children.
|
|
385
|
+
* @param {MountResult[]} childInstances - Array to store all mounted component instances.
|
|
386
|
+
* @param {ComponentContext & SetupResult} context - The merged component context and setup data.
|
|
345
387
|
* @returns {Promise<void>}
|
|
346
388
|
*
|
|
347
389
|
* @example
|
|
348
390
|
* // Explicit children mounting:
|
|
349
391
|
* const children = {
|
|
350
|
-
* '
|
|
392
|
+
* 'user-profile': UserProfileComponent,
|
|
351
393
|
* '#settings-panel': "settings-panel"
|
|
352
394
|
* };
|
|
353
395
|
*/
|
|
354
396
|
private _mountComponents;
|
|
355
397
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
*/
|
|
364
|
-
prefix?: string | undefined;
|
|
365
|
-
/**
|
|
366
|
-
* Enable async component setup
|
|
367
|
-
*/
|
|
368
|
-
async?: boolean | undefined;
|
|
369
|
-
};
|
|
398
|
+
/**
|
|
399
|
+
* Configuration options for the Eleva instance (reserved for future use).
|
|
400
|
+
*/
|
|
401
|
+
export type ElevaConfig = Record<string, unknown>;
|
|
402
|
+
/**
|
|
403
|
+
* Component definition object.
|
|
404
|
+
*/
|
|
370
405
|
export type ComponentDefinition = {
|
|
371
406
|
/**
|
|
372
|
-
* Optional setup function that initializes the component's state and returns reactive data
|
|
407
|
+
* Optional setup function that initializes the component's state and returns reactive data.
|
|
373
408
|
*/
|
|
374
409
|
setup?: SetupFunction | undefined;
|
|
375
410
|
/**
|
|
376
|
-
* Required function or string that defines the component's HTML structure
|
|
411
|
+
* Required function or string that defines the component's HTML structure.
|
|
377
412
|
*/
|
|
378
413
|
template: TemplateFunction | string;
|
|
379
414
|
/**
|
|
380
|
-
* Optional function or string that provides
|
|
415
|
+
* Optional function or string that provides CSS styles for the component.
|
|
416
|
+
* Styles are preserved across DOM diffs via data-e-style markers.
|
|
381
417
|
*/
|
|
382
418
|
style?: string | StyleFunction | undefined;
|
|
383
419
|
/**
|
|
384
|
-
* Optional object defining nested child components
|
|
420
|
+
* Optional object defining nested child components.
|
|
385
421
|
*/
|
|
386
422
|
children?: ChildrenMap | undefined;
|
|
387
423
|
};
|
|
424
|
+
/**
|
|
425
|
+
* Setup function that initializes component state.
|
|
426
|
+
*/
|
|
388
427
|
export type SetupFunction = (ctx: ComponentContext) => SetupResult | Promise<SetupResult>;
|
|
389
428
|
/**
|
|
390
|
-
* Data returned from setup function, may include lifecycle hooks
|
|
429
|
+
* Data returned from setup function, may include lifecycle hooks.
|
|
391
430
|
*/
|
|
392
431
|
export type SetupResult = Record<string, unknown> & LifecycleHooks;
|
|
393
|
-
export type TemplateFunction = (ctx: ComponentContext) => string | Promise<string>;
|
|
394
|
-
export type StyleFunction = (ctx: ComponentContext) => string;
|
|
395
432
|
/**
|
|
396
|
-
*
|
|
433
|
+
* Template function that returns HTML markup.
|
|
434
|
+
*/
|
|
435
|
+
export type TemplateFunction = (ctx: ComponentContext & SetupResult) => string | Promise<string>;
|
|
436
|
+
/**
|
|
437
|
+
* Style function that returns CSS styles.
|
|
438
|
+
*/
|
|
439
|
+
export type StyleFunction = (ctx: ComponentContext & SetupResult) => string;
|
|
440
|
+
/**
|
|
441
|
+
* Map of CSS selectors to component definitions or registered component names.
|
|
397
442
|
*/
|
|
398
443
|
export type ChildrenMap = Record<string, ComponentDefinition | string>;
|
|
444
|
+
/**
|
|
445
|
+
* Context passed to component setup function.
|
|
446
|
+
*/
|
|
399
447
|
export type ComponentContext = {
|
|
400
448
|
/**
|
|
401
|
-
* Component properties passed during mounting
|
|
449
|
+
* Component properties passed during mounting.
|
|
402
450
|
*/
|
|
403
451
|
props: ComponentProps;
|
|
404
452
|
/**
|
|
405
|
-
* Event emitter instance for component event handling
|
|
453
|
+
* Event emitter instance for component event handling.
|
|
406
454
|
*/
|
|
407
455
|
emitter: Emitter;
|
|
408
456
|
/**
|
|
409
|
-
* Factory function to create reactive Signal instances
|
|
457
|
+
* Factory function to create reactive Signal instances.
|
|
410
458
|
*/
|
|
411
459
|
signal: SignalFactory;
|
|
412
460
|
};
|
|
413
461
|
/**
|
|
414
|
-
* Properties passed to a component during mounting
|
|
462
|
+
* Properties passed to a component during mounting.
|
|
415
463
|
*/
|
|
416
464
|
export type ComponentProps = Record<string, unknown>;
|
|
417
|
-
|
|
465
|
+
/**
|
|
466
|
+
* Factory function to create reactive Signal instances.
|
|
467
|
+
*/
|
|
468
|
+
export type SignalFactory = <T>(initialValue: T) => Signal<T>;
|
|
469
|
+
/**
|
|
470
|
+
* Lifecycle hooks that can be returned from setup function.
|
|
471
|
+
*/
|
|
418
472
|
export type LifecycleHooks = {
|
|
419
473
|
/**
|
|
420
|
-
*
|
|
474
|
+
* Called before component mounting.
|
|
421
475
|
*/
|
|
422
476
|
onBeforeMount?: LifecycleHook | undefined;
|
|
423
477
|
/**
|
|
424
|
-
*
|
|
478
|
+
* Called after component mounting.
|
|
425
479
|
*/
|
|
426
480
|
onMount?: LifecycleHook | undefined;
|
|
427
481
|
/**
|
|
428
|
-
*
|
|
482
|
+
* Called before component update.
|
|
429
483
|
*/
|
|
430
484
|
onBeforeUpdate?: LifecycleHook | undefined;
|
|
431
485
|
/**
|
|
432
|
-
*
|
|
486
|
+
* Called after component update.
|
|
433
487
|
*/
|
|
434
488
|
onUpdate?: LifecycleHook | undefined;
|
|
435
489
|
/**
|
|
436
|
-
*
|
|
490
|
+
* Called during component unmounting.
|
|
437
491
|
*/
|
|
438
492
|
onUnmount?: UnmountHook | undefined;
|
|
439
493
|
};
|
|
494
|
+
/**
|
|
495
|
+
* Lifecycle hook function.
|
|
496
|
+
*/
|
|
440
497
|
export type LifecycleHook = (ctx: LifecycleHookContext) => void | Promise<void>;
|
|
498
|
+
/**
|
|
499
|
+
* Unmount hook function with cleanup resources.
|
|
500
|
+
*/
|
|
441
501
|
export type UnmountHook = (ctx: UnmountHookContext) => void | Promise<void>;
|
|
502
|
+
/**
|
|
503
|
+
* Context passed to lifecycle hooks.
|
|
504
|
+
*/
|
|
442
505
|
export type LifecycleHookContext = {
|
|
443
506
|
/**
|
|
444
|
-
* The DOM element where the component is mounted
|
|
507
|
+
* The DOM element where the component is mounted.
|
|
445
508
|
*/
|
|
446
509
|
container: HTMLElement;
|
|
447
510
|
/**
|
|
448
|
-
* The component's reactive state and context data
|
|
511
|
+
* The component's reactive state and context data.
|
|
449
512
|
*/
|
|
450
513
|
context: ComponentContext & SetupResult;
|
|
451
514
|
};
|
|
515
|
+
/**
|
|
516
|
+
* Context passed to unmount hook with cleanup resources.
|
|
517
|
+
*/
|
|
452
518
|
export type UnmountHookContext = {
|
|
453
519
|
/**
|
|
454
|
-
* The DOM element where the component is mounted
|
|
520
|
+
* The DOM element where the component is mounted.
|
|
455
521
|
*/
|
|
456
522
|
container: HTMLElement;
|
|
457
523
|
/**
|
|
458
|
-
* The component's reactive state and context data
|
|
524
|
+
* The component's reactive state and context data.
|
|
459
525
|
*/
|
|
460
526
|
context: ComponentContext & SetupResult;
|
|
461
527
|
/**
|
|
462
|
-
* Object containing cleanup functions and instances
|
|
528
|
+
* Object containing cleanup functions and instances.
|
|
463
529
|
*/
|
|
464
530
|
cleanup: CleanupResources;
|
|
465
531
|
};
|
|
532
|
+
/**
|
|
533
|
+
* Resources available for cleanup during unmount.
|
|
534
|
+
*/
|
|
466
535
|
export type CleanupResources = {
|
|
467
536
|
/**
|
|
468
|
-
* Signal watcher cleanup functions
|
|
537
|
+
* Signal watcher cleanup functions.
|
|
469
538
|
*/
|
|
470
|
-
watchers:
|
|
539
|
+
watchers: UnsubscribeFunction[];
|
|
471
540
|
/**
|
|
472
|
-
* Event listener cleanup functions
|
|
541
|
+
* Event listener cleanup functions.
|
|
473
542
|
*/
|
|
474
|
-
listeners:
|
|
543
|
+
listeners: UnsubscribeFunction[];
|
|
475
544
|
/**
|
|
476
|
-
* Child component instances
|
|
545
|
+
* Child component instances.
|
|
477
546
|
*/
|
|
478
|
-
children:
|
|
547
|
+
children: MountResult[];
|
|
479
548
|
};
|
|
549
|
+
/**
|
|
550
|
+
* Result of mounting a component.
|
|
551
|
+
*/
|
|
480
552
|
export type MountResult = {
|
|
481
553
|
/**
|
|
482
|
-
* The DOM element where the component is mounted
|
|
554
|
+
* The DOM element where the component is mounted.
|
|
483
555
|
*/
|
|
484
556
|
container: HTMLElement;
|
|
485
557
|
/**
|
|
486
|
-
* The component's reactive state and context data
|
|
558
|
+
* The component's reactive state and context data.
|
|
487
559
|
*/
|
|
488
560
|
data: ComponentContext & SetupResult;
|
|
489
561
|
/**
|
|
490
|
-
* Function to clean up and unmount the component
|
|
562
|
+
* Function to clean up and unmount the component.
|
|
491
563
|
*/
|
|
492
564
|
unmount: UnmountFunction;
|
|
493
565
|
};
|
|
566
|
+
/**
|
|
567
|
+
* Function to unmount a component and clean up resources.
|
|
568
|
+
*/
|
|
494
569
|
export type UnmountFunction = () => Promise<void>;
|
|
570
|
+
/**
|
|
571
|
+
* Function to unsubscribe from events or watchers.
|
|
572
|
+
*/
|
|
495
573
|
export type UnsubscribeFunction = () => void | boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Plugin interface for extending Eleva.
|
|
576
|
+
*/
|
|
496
577
|
export type ElevaPlugin = {
|
|
497
578
|
/**
|
|
498
|
-
*
|
|
579
|
+
* Unique identifier name for the plugin.
|
|
499
580
|
*/
|
|
500
|
-
|
|
581
|
+
name: string;
|
|
501
582
|
/**
|
|
502
|
-
*
|
|
583
|
+
* Optional version string for the plugin.
|
|
503
584
|
*/
|
|
504
|
-
|
|
585
|
+
version?: string | undefined;
|
|
586
|
+
/**
|
|
587
|
+
* Function that installs the plugin.
|
|
588
|
+
*/
|
|
589
|
+
install: PluginInstallFunction;
|
|
505
590
|
/**
|
|
506
|
-
* Optional function to uninstall the plugin
|
|
591
|
+
* Optional function to uninstall the plugin.
|
|
507
592
|
*/
|
|
508
593
|
uninstall?: PluginUninstallFunction | undefined;
|
|
509
594
|
};
|
|
510
|
-
export type PluginInstallFunction = (eleva: Eleva, options: PluginOptions) => void | Eleva | unknown;
|
|
511
|
-
export type PluginUninstallFunction = (eleva: Eleva) => void;
|
|
512
595
|
/**
|
|
513
|
-
*
|
|
596
|
+
* Plugin install function.
|
|
597
|
+
*/
|
|
598
|
+
export type PluginInstallFunction = (eleva: Eleva, options?: PluginOptions | undefined) => void | Eleva | unknown;
|
|
599
|
+
/**
|
|
600
|
+
* Plugin uninstall function.
|
|
601
|
+
*/
|
|
602
|
+
export type PluginUninstallFunction = (eleva: Eleva) => void | Promise<void>;
|
|
603
|
+
/**
|
|
604
|
+
* Configuration options passed to a plugin during installation.
|
|
514
605
|
*/
|
|
515
606
|
export type PluginOptions = Record<string, unknown>;
|
|
516
|
-
export type EventHandler = (event: Event) => void;
|
|
517
607
|
/**
|
|
518
|
-
*
|
|
608
|
+
* Handler function for DOM events (e.g., click, input, submit).
|
|
609
|
+
*/
|
|
610
|
+
export type DOMEventHandler = (event: Event) => void;
|
|
611
|
+
/**
|
|
612
|
+
* Common DOM event names (prefixed with @ in templates).
|
|
519
613
|
*/
|
|
520
614
|
export type DOMEventName = "click" | "submit" | "input" | "change" | "focus" | "blur" | "keydown" | "keyup" | "keypress" | "mouseenter" | "mouseleave" | "mouseover" | "mouseout" | "mousedown" | "mouseup" | "touchstart" | "touchend" | "touchmove" | "scroll" | "resize" | "load" | "error" | string;
|
|
521
615
|
import { Emitter } from "../modules/Emitter.js";
|