eleva 1.2.16-beta → 1.2.18-beta
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 +27 -15
- package/dist/eleva.cjs.js +358 -172
- package/dist/eleva.cjs.js.map +1 -1
- package/dist/eleva.d.ts +260 -109
- package/dist/eleva.esm.js +358 -172
- package/dist/eleva.esm.js.map +1 -1
- package/dist/eleva.umd.js +358 -172
- package/dist/eleva.umd.js.map +1 -1
- package/dist/eleva.umd.min.js +2 -2
- package/dist/eleva.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/core/Eleva.js +163 -92
- package/src/modules/Emitter.js +23 -7
- package/src/modules/Renderer.js +183 -82
- package/src/modules/Signal.js +10 -7
- package/src/modules/TemplateEngine.js +6 -3
- package/types/core/Eleva.d.ts +167 -71
- package/types/core/Eleva.d.ts.map +1 -1
- package/types/modules/Emitter.d.ts +26 -10
- package/types/modules/Emitter.d.ts.map +1 -1
- package/types/modules/Renderer.d.ts +56 -19
- package/types/modules/Renderer.d.ts.map +1 -1
- package/types/modules/Signal.d.ts +11 -9
- package/types/modules/Signal.d.ts.map +1 -1
- package/types/modules/TemplateEngine.d.ts +8 -5
- package/types/modules/TemplateEngine.d.ts.map +1 -1
package/dist/eleva.d.ts
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* @classdesc A robust event emitter that enables inter-component communication through a publish-subscribe pattern.
|
|
4
4
|
* Components can emit events and listen for events from other components, facilitating loose coupling
|
|
5
5
|
* and reactive updates across the application.
|
|
6
|
+
* Events are handled synchronously in the order they were registered, with proper cleanup
|
|
7
|
+
* of unsubscribed handlers.
|
|
8
|
+
* Event names should follow the format 'namespace:action' (e.g., 'user:login', 'cart:update').
|
|
6
9
|
*
|
|
7
10
|
* @example
|
|
8
11
|
* const emitter = new Emitter();
|
|
@@ -10,42 +13,55 @@
|
|
|
10
13
|
* emitter.emit('user:login', { name: 'John' }); // Logs: "User logged in: John"
|
|
11
14
|
*/
|
|
12
15
|
declare class Emitter {
|
|
13
|
-
/** @private {Map<string, Set<
|
|
16
|
+
/** @private {Map<string, Set<(data: unknown) => void>>} Map of event names to their registered handler functions */
|
|
14
17
|
private _events;
|
|
15
18
|
/**
|
|
16
19
|
* Registers an event handler for the specified event name.
|
|
17
20
|
* The handler will be called with the event data when the event is emitted.
|
|
21
|
+
* Event names should follow the format 'namespace:action' for consistency.
|
|
18
22
|
*
|
|
19
23
|
* @public
|
|
20
|
-
* @param {string} event - The name of the event to listen for.
|
|
21
|
-
* @param {
|
|
22
|
-
* @returns {
|
|
24
|
+
* @param {string} event - The name of the event to listen for (e.g., 'user:login').
|
|
25
|
+
* @param {(data: unknown) => void} handler - The callback function to invoke when the event occurs.
|
|
26
|
+
* @returns {() => void} A function to unsubscribe the event handler.
|
|
23
27
|
* @example
|
|
24
28
|
* const unsubscribe = emitter.on('user:login', (user) => console.log(user));
|
|
25
29
|
* // Later...
|
|
26
30
|
* unsubscribe(); // Stops listening for the event
|
|
27
31
|
*/
|
|
28
|
-
public on(event: string, handler: (
|
|
32
|
+
public on(event: string, handler: (data: unknown) => void): () => void;
|
|
29
33
|
/**
|
|
30
34
|
* Removes an event handler for the specified event name.
|
|
31
35
|
* If no handler is provided, all handlers for the event are removed.
|
|
36
|
+
* Automatically cleans up empty event sets to prevent memory leaks.
|
|
32
37
|
*
|
|
33
38
|
* @public
|
|
34
|
-
* @param {string} event - The name of the event.
|
|
35
|
-
* @param {
|
|
39
|
+
* @param {string} event - The name of the event to remove handlers from.
|
|
40
|
+
* @param {(data: unknown) => void} [handler] - The specific handler function to remove.
|
|
36
41
|
* @returns {void}
|
|
42
|
+
* @example
|
|
43
|
+
* // Remove a specific handler
|
|
44
|
+
* emitter.off('user:login', loginHandler);
|
|
45
|
+
* // Remove all handlers for an event
|
|
46
|
+
* emitter.off('user:login');
|
|
37
47
|
*/
|
|
38
|
-
public off(event: string, handler?: (
|
|
48
|
+
public off(event: string, handler?: (data: unknown) => void): void;
|
|
39
49
|
/**
|
|
40
50
|
* Emits an event with the specified data to all registered handlers.
|
|
41
51
|
* Handlers are called synchronously in the order they were registered.
|
|
52
|
+
* If no handlers are registered for the event, the emission is silently ignored.
|
|
42
53
|
*
|
|
43
54
|
* @public
|
|
44
55
|
* @param {string} event - The name of the event to emit.
|
|
45
|
-
* @param {...
|
|
56
|
+
* @param {...unknown} args - Optional arguments to pass to the event handlers.
|
|
46
57
|
* @returns {void}
|
|
58
|
+
* @example
|
|
59
|
+
* // Emit an event with data
|
|
60
|
+
* emitter.emit('user:login', { name: 'John', role: 'admin' });
|
|
61
|
+
* // Emit an event with multiple arguments
|
|
62
|
+
* emitter.emit('cart:update', { items: [] }, { total: 0 });
|
|
47
63
|
*/
|
|
48
|
-
public emit(event: string, ...args:
|
|
64
|
+
public emit(event: string, ...args: unknown[]): void;
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
/**
|
|
@@ -53,6 +69,8 @@ declare class Emitter {
|
|
|
53
69
|
* @classdesc A reactive data holder that enables fine-grained reactivity in the Eleva framework.
|
|
54
70
|
* Signals notify registered watchers when their value changes, enabling efficient DOM updates
|
|
55
71
|
* through targeted patching rather than full re-renders.
|
|
72
|
+
* Updates are batched using microtasks to prevent multiple synchronous notifications.
|
|
73
|
+
* The class is generic, allowing type-safe handling of any value type T.
|
|
56
74
|
*
|
|
57
75
|
* @example
|
|
58
76
|
* const count = new Signal(0);
|
|
@@ -65,12 +83,12 @@ declare class Signal<T> {
|
|
|
65
83
|
* Creates a new Signal instance with the specified initial value.
|
|
66
84
|
*
|
|
67
85
|
* @public
|
|
68
|
-
* @param {
|
|
86
|
+
* @param {T} value - The initial value of the signal.
|
|
69
87
|
*/
|
|
70
|
-
constructor(value:
|
|
71
|
-
/** @private {T} Internal storage for the signal's current value
|
|
88
|
+
constructor(value: T);
|
|
89
|
+
/** @private {T} Internal storage for the signal's current value */
|
|
72
90
|
private _value;
|
|
73
|
-
/** @private {Set<
|
|
91
|
+
/** @private {Set<(value: T) => void>} Collection of callback functions to be notified when value changes */
|
|
74
92
|
private _watchers;
|
|
75
93
|
/** @private {boolean} Flag to prevent multiple synchronous watcher notifications and batch updates into microtasks */
|
|
76
94
|
private _pending;
|
|
@@ -79,7 +97,7 @@ declare class Signal<T> {
|
|
|
79
97
|
* The notification is batched using microtasks to prevent multiple synchronous updates.
|
|
80
98
|
*
|
|
81
99
|
* @public
|
|
82
|
-
* @param {T} newVal - The new value to set
|
|
100
|
+
* @param {T} newVal - The new value to set.
|
|
83
101
|
* @returns {void}
|
|
84
102
|
*/
|
|
85
103
|
public set value(newVal: T);
|
|
@@ -87,7 +105,7 @@ declare class Signal<T> {
|
|
|
87
105
|
* Gets the current value of the signal.
|
|
88
106
|
*
|
|
89
107
|
* @public
|
|
90
|
-
* @returns {T} The current value
|
|
108
|
+
* @returns {T} The current value.
|
|
91
109
|
*/
|
|
92
110
|
public get value(): T;
|
|
93
111
|
/**
|
|
@@ -95,14 +113,14 @@ declare class Signal<T> {
|
|
|
95
113
|
* The watcher will receive the new value as its argument.
|
|
96
114
|
*
|
|
97
115
|
* @public
|
|
98
|
-
* @param {
|
|
99
|
-
* @returns {
|
|
116
|
+
* @param {(value: T) => void} fn - The callback function to invoke on value change.
|
|
117
|
+
* @returns {() => boolean} A function to unsubscribe the watcher.
|
|
100
118
|
* @example
|
|
101
119
|
* const unsubscribe = signal.watch((value) => console.log(value));
|
|
102
120
|
* // Later...
|
|
103
121
|
* unsubscribe(); // Stops watching for changes
|
|
104
122
|
*/
|
|
105
|
-
public watch(fn: (
|
|
123
|
+
public watch(fn: (value: T) => void): () => boolean;
|
|
106
124
|
/**
|
|
107
125
|
* Notifies all registered watchers of a value change using microtask scheduling.
|
|
108
126
|
* Uses a pending flag to batch multiple synchronous updates into a single notification.
|
|
@@ -116,9 +134,18 @@ declare class Signal<T> {
|
|
|
116
134
|
|
|
117
135
|
/**
|
|
118
136
|
* @class 🎨 Renderer
|
|
119
|
-
* @classdesc A DOM renderer that
|
|
120
|
-
*
|
|
121
|
-
*
|
|
137
|
+
* @classdesc A high-performance DOM renderer that implements an optimized direct DOM diffing algorithm.
|
|
138
|
+
*
|
|
139
|
+
* Key features:
|
|
140
|
+
* - Single-pass diffing algorithm for efficient DOM updates
|
|
141
|
+
* - Key-based node reconciliation for optimal performance
|
|
142
|
+
* - Intelligent attribute handling for ARIA, data attributes, and boolean properties
|
|
143
|
+
* - Preservation of special Eleva-managed instances and style elements
|
|
144
|
+
* - Memory-efficient with reusable temporary containers
|
|
145
|
+
*
|
|
146
|
+
* The renderer is designed to minimize DOM operations while maintaining
|
|
147
|
+
* exact attribute synchronization and proper node identity preservation.
|
|
148
|
+
* It's particularly optimized for frequent updates and complex DOM structures.
|
|
122
149
|
*
|
|
123
150
|
* @example
|
|
124
151
|
* const renderer = new Renderer();
|
|
@@ -127,70 +154,137 @@ declare class Signal<T> {
|
|
|
127
154
|
* renderer.patchDOM(container, newHtml);
|
|
128
155
|
*/
|
|
129
156
|
declare class Renderer {
|
|
130
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* A temporary container to hold the new HTML content while diffing.
|
|
159
|
+
* @private
|
|
160
|
+
* @type {HTMLElement}
|
|
161
|
+
*/
|
|
131
162
|
private _tempContainer;
|
|
132
163
|
/**
|
|
133
|
-
* Patches the DOM of
|
|
134
|
-
* Efficiently updates the DOM by parsing new HTML into a reusable container
|
|
135
|
-
* and applying only the necessary changes.
|
|
164
|
+
* Patches the DOM of the given container with the provided HTML string.
|
|
136
165
|
*
|
|
137
166
|
* @public
|
|
138
|
-
* @param {HTMLElement} container - The container
|
|
139
|
-
* @param {string} newHtml - The new HTML
|
|
167
|
+
* @param {HTMLElement} container - The container whose DOM will be patched.
|
|
168
|
+
* @param {string} newHtml - The new HTML string.
|
|
169
|
+
* @throws {TypeError} If the container is not an HTMLElement or newHtml is not a string.
|
|
170
|
+
* @throws {Error} If the DOM patching fails.
|
|
140
171
|
* @returns {void}
|
|
141
|
-
* @throws {Error} If container is not an HTMLElement, newHtml is not a string, or patching fails.
|
|
142
172
|
*/
|
|
143
173
|
public patchDOM(container: HTMLElement, newHtml: string): void;
|
|
144
174
|
/**
|
|
145
|
-
*
|
|
146
|
-
* This method recursively compares nodes and their attributes, applying only
|
|
147
|
-
* the necessary changes to minimize DOM operations.
|
|
175
|
+
* Performs a diff between two DOM nodes and patches the old node to match the new node.
|
|
148
176
|
*
|
|
149
177
|
* @private
|
|
150
|
-
* @param {
|
|
151
|
-
* @param {
|
|
178
|
+
* @param {Node} oldParent - The old parent node to be patched.
|
|
179
|
+
* @param {Node} newParent - The new parent node to compare.
|
|
152
180
|
* @returns {void}
|
|
153
181
|
*/
|
|
154
182
|
private _diff;
|
|
155
183
|
/**
|
|
156
|
-
*
|
|
157
|
-
* Handles special cases for ARIA attributes, data attributes, and boolean properties.
|
|
184
|
+
* Checks if the node types match.
|
|
158
185
|
*
|
|
159
186
|
* @private
|
|
160
|
-
* @param {
|
|
161
|
-
* @param {
|
|
187
|
+
* @param {Node} oldNode - The old node.
|
|
188
|
+
* @param {Node} newNode - The new node.
|
|
189
|
+
* @returns {boolean} True if the nodes match, false otherwise.
|
|
190
|
+
*/
|
|
191
|
+
private _keysMatch;
|
|
192
|
+
/**
|
|
193
|
+
* Patches a node.
|
|
194
|
+
*
|
|
195
|
+
* @private
|
|
196
|
+
* @param {Node} oldNode - The old node to patch.
|
|
197
|
+
* @param {Node} newNode - The new node to patch.
|
|
198
|
+
* @returns {void}
|
|
199
|
+
*/
|
|
200
|
+
private _patchNode;
|
|
201
|
+
/**
|
|
202
|
+
* Updates the attributes of an element.
|
|
203
|
+
*
|
|
204
|
+
* @private
|
|
205
|
+
* @param {HTMLElement} oldEl - The old element to update.
|
|
206
|
+
* @param {HTMLElement} newEl - The new element to update.
|
|
162
207
|
* @returns {void}
|
|
163
208
|
*/
|
|
164
209
|
private _updateAttributes;
|
|
210
|
+
/**
|
|
211
|
+
* Creates a key map for the children of a parent node.
|
|
212
|
+
*
|
|
213
|
+
* @private
|
|
214
|
+
* @param {Array<Node>} children - The children of the parent node.
|
|
215
|
+
* @param {number} start - The start index of the children.
|
|
216
|
+
* @param {number} end - The end index of the children.
|
|
217
|
+
* @returns {Map<string, number>} A map of key to child index.
|
|
218
|
+
*/
|
|
219
|
+
private _createKeyMap;
|
|
165
220
|
}
|
|
166
221
|
|
|
167
222
|
/**
|
|
168
223
|
* @typedef {Object} ComponentDefinition
|
|
169
|
-
* @property {function(
|
|
224
|
+
* @property {function(ComponentContext): (Record<string, unknown>|Promise<Record<string, unknown>>)} [setup]
|
|
170
225
|
* Optional setup function that initializes the component's state and returns reactive data
|
|
171
|
-
* @property {function(
|
|
226
|
+
* @property {(function(ComponentContext): string|Promise<string>)} template
|
|
172
227
|
* Required function that defines the component's HTML structure
|
|
173
|
-
* @property {function(
|
|
174
|
-
* Optional function that provides component-scoped CSS styles
|
|
175
|
-
* @property {
|
|
228
|
+
* @property {(function(ComponentContext): string)|string} [style]
|
|
229
|
+
* Optional function or string that provides component-scoped CSS styles
|
|
230
|
+
* @property {Record<string, ComponentDefinition>} [children]
|
|
176
231
|
* Optional object defining nested child components
|
|
177
232
|
*/
|
|
178
233
|
/**
|
|
179
|
-
* @typedef {Object}
|
|
180
|
-
* @property {
|
|
181
|
-
*
|
|
182
|
-
* @property {
|
|
183
|
-
*
|
|
234
|
+
* @typedef {Object} ComponentContext
|
|
235
|
+
* @property {Record<string, unknown>} props
|
|
236
|
+
* Component properties passed during mounting
|
|
237
|
+
* @property {Emitter} emitter
|
|
238
|
+
* Event emitter instance for component event handling
|
|
239
|
+
* @property {function<T>(value: T): Signal<T>} signal
|
|
240
|
+
* Factory function to create reactive Signal instances
|
|
241
|
+
* @property {function(LifecycleHookContext): Promise<void>} [onBeforeMount]
|
|
242
|
+
* Hook called before component mounting
|
|
243
|
+
* @property {function(LifecycleHookContext): Promise<void>} [onMount]
|
|
244
|
+
* Hook called after component mounting
|
|
245
|
+
* @property {function(LifecycleHookContext): Promise<void>} [onBeforeUpdate]
|
|
246
|
+
* Hook called before component update
|
|
247
|
+
* @property {function(LifecycleHookContext): Promise<void>} [onUpdate]
|
|
248
|
+
* Hook called after component update
|
|
249
|
+
* @property {function(UnmountHookContext): Promise<void>} [onUnmount]
|
|
250
|
+
* Hook called during component unmounting
|
|
251
|
+
*/
|
|
252
|
+
/**
|
|
253
|
+
* @typedef {Object} LifecycleHookContext
|
|
254
|
+
* @property {HTMLElement} container
|
|
255
|
+
* The DOM element where the component is mounted
|
|
256
|
+
* @property {ComponentContext} context
|
|
257
|
+
* The component's reactive state and context data
|
|
258
|
+
*/
|
|
259
|
+
/**
|
|
260
|
+
* @typedef {Object} UnmountHookContext
|
|
261
|
+
* @property {HTMLElement} container
|
|
262
|
+
* The DOM element where the component is mounted
|
|
263
|
+
* @property {ComponentContext} context
|
|
264
|
+
* The component's reactive state and context data
|
|
265
|
+
* @property {{
|
|
266
|
+
* watchers: Array<() => void>, // Signal watcher cleanup functions
|
|
267
|
+
* listeners: Array<() => void>, // Event listener cleanup functions
|
|
268
|
+
* children: Array<MountResult> // Child component instances
|
|
269
|
+
* }} cleanup
|
|
270
|
+
* Object containing cleanup functions and instances
|
|
184
271
|
*/
|
|
185
272
|
/**
|
|
186
273
|
* @typedef {Object} MountResult
|
|
187
274
|
* @property {HTMLElement} container
|
|
188
275
|
* The DOM element where the component is mounted
|
|
189
|
-
* @property {
|
|
276
|
+
* @property {ComponentContext} data
|
|
190
277
|
* The component's reactive state and context data
|
|
191
|
-
* @property {function(): void} unmount
|
|
278
|
+
* @property {function(): Promise<void>} unmount
|
|
192
279
|
* Function to clean up and unmount the component
|
|
193
280
|
*/
|
|
281
|
+
/**
|
|
282
|
+
* @typedef {Object} ElevaPlugin
|
|
283
|
+
* @property {function(Eleva, Record<string, unknown>): void} install
|
|
284
|
+
* Function that installs the plugin into the Eleva instance
|
|
285
|
+
* @property {string} name
|
|
286
|
+
* Unique identifier name for the plugin
|
|
287
|
+
*/
|
|
194
288
|
/**
|
|
195
289
|
* @class 🧩 Eleva
|
|
196
290
|
* @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,
|
|
@@ -198,12 +292,26 @@ declare class Renderer {
|
|
|
198
292
|
* event handling, and DOM rendering with a focus on performance and developer experience.
|
|
199
293
|
*
|
|
200
294
|
* @example
|
|
295
|
+
* // Basic component creation and mounting
|
|
201
296
|
* const app = new Eleva("myApp");
|
|
202
297
|
* app.component("myComponent", {
|
|
203
|
-
*
|
|
204
|
-
*
|
|
298
|
+
* setup: (ctx) => ({ count: ctx.signal(0) }),
|
|
299
|
+
* template: (ctx) => `<div>Hello ${ctx.props.name}</div>`
|
|
205
300
|
* });
|
|
206
301
|
* app.mount(document.getElementById("app"), "myComponent", { name: "World" });
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* // Using lifecycle hooks
|
|
305
|
+
* app.component("lifecycleDemo", {
|
|
306
|
+
* setup: () => {
|
|
307
|
+
* return {
|
|
308
|
+
* onMount: ({ container, context }) => {
|
|
309
|
+
* console.log('Component mounted!');
|
|
310
|
+
* }
|
|
311
|
+
* };
|
|
312
|
+
* },
|
|
313
|
+
* template: `<div>Lifecycle Demo</div>`
|
|
314
|
+
* });
|
|
207
315
|
*/
|
|
208
316
|
declare class Eleva {
|
|
209
317
|
/**
|
|
@@ -211,18 +319,25 @@ declare class Eleva {
|
|
|
211
319
|
*
|
|
212
320
|
* @public
|
|
213
321
|
* @param {string} name - The unique identifier name for this Eleva instance.
|
|
214
|
-
* @param {
|
|
322
|
+
* @param {Record<string, unknown>} [config={}] - Optional configuration object for the instance.
|
|
215
323
|
* May include framework-wide settings and default behaviors.
|
|
324
|
+
* @throws {Error} If the name is not provided or is not a string.
|
|
325
|
+
* @returns {Eleva} A new Eleva instance.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const app = new Eleva("myApp");
|
|
329
|
+
* app.component("myComponent", {
|
|
330
|
+
* setup: (ctx) => ({ count: ctx.signal(0) }),
|
|
331
|
+
* template: (ctx) => `<div>Hello ${ctx.props.name}!</div>`
|
|
332
|
+
* });
|
|
333
|
+
* app.mount(document.getElementById("app"), "myComponent", { name: "World" });
|
|
334
|
+
*
|
|
216
335
|
*/
|
|
217
|
-
constructor(name: string, config?:
|
|
218
|
-
[x: string]: any;
|
|
219
|
-
});
|
|
336
|
+
constructor(name: string, config?: Record<string, unknown>);
|
|
220
337
|
/** @public {string} The unique identifier name for this Eleva instance */
|
|
221
338
|
public name: string;
|
|
222
|
-
/** @public {Object<string,
|
|
223
|
-
public config:
|
|
224
|
-
[x: string]: any;
|
|
225
|
-
};
|
|
339
|
+
/** @public {Object<string, unknown>} Optional configuration object for the Eleva instance */
|
|
340
|
+
public config: Record<string, unknown>;
|
|
226
341
|
/** @public {Emitter} Instance of the event emitter for handling component events */
|
|
227
342
|
public emitter: Emitter;
|
|
228
343
|
/** @public {typeof Signal} Static reference to the Signal class for creating reactive state */
|
|
@@ -233,8 +348,6 @@ declare class Eleva {
|
|
|
233
348
|
private _components;
|
|
234
349
|
/** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */
|
|
235
350
|
private _plugins;
|
|
236
|
-
/** @private {string[]} Array of lifecycle hook names supported by components */
|
|
237
|
-
private _lifecycleHooks;
|
|
238
351
|
/** @private {boolean} Flag indicating if the root component is currently mounted */
|
|
239
352
|
private _isMounted;
|
|
240
353
|
/**
|
|
@@ -244,13 +357,13 @@ declare class Eleva {
|
|
|
244
357
|
*
|
|
245
358
|
* @public
|
|
246
359
|
* @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.
|
|
247
|
-
* @param {Object<string,
|
|
360
|
+
* @param {Object<string, unknown>} [options={}] - Optional configuration options for the plugin.
|
|
248
361
|
* @returns {Eleva} The Eleva instance (for method chaining).
|
|
249
362
|
* @example
|
|
250
363
|
* app.use(myPlugin, { option1: "value1" });
|
|
251
364
|
*/
|
|
252
365
|
public use(plugin: ElevaPlugin, options?: {
|
|
253
|
-
[x: string]:
|
|
366
|
+
[x: string]: unknown;
|
|
254
367
|
}): Eleva;
|
|
255
368
|
/**
|
|
256
369
|
* Registers a new component with the Eleva instance.
|
|
@@ -264,7 +377,7 @@ declare class Eleva {
|
|
|
264
377
|
* @example
|
|
265
378
|
* app.component("myButton", {
|
|
266
379
|
* template: (ctx) => `<button>${ctx.props.text}</button>`,
|
|
267
|
-
* style:
|
|
380
|
+
* style: `button { color: blue; }`
|
|
268
381
|
* });
|
|
269
382
|
*/
|
|
270
383
|
public component(name: string, definition: ComponentDefinition): Eleva;
|
|
@@ -275,7 +388,7 @@ declare class Eleva {
|
|
|
275
388
|
* @public
|
|
276
389
|
* @param {HTMLElement} container - The DOM element where the component will be mounted.
|
|
277
390
|
* @param {string|ComponentDefinition} compName - The name of the registered component or a direct component definition.
|
|
278
|
-
* @param {Object<string,
|
|
391
|
+
* @param {Object<string, unknown>} [props={}] - Optional properties to pass to the component.
|
|
279
392
|
* @returns {Promise<MountResult>}
|
|
280
393
|
* A Promise that resolves to an object containing:
|
|
281
394
|
* - container: The mounted component's container element
|
|
@@ -288,25 +401,16 @@ declare class Eleva {
|
|
|
288
401
|
* instance.unmount();
|
|
289
402
|
*/
|
|
290
403
|
public mount(container: HTMLElement, compName: string | ComponentDefinition, props?: {
|
|
291
|
-
[x: string]:
|
|
404
|
+
[x: string]: unknown;
|
|
292
405
|
}): Promise<MountResult>;
|
|
293
|
-
/**
|
|
294
|
-
* Prepares default no-operation lifecycle hook functions for a component.
|
|
295
|
-
* These hooks will be called at various stages of the component's lifecycle.
|
|
296
|
-
*
|
|
297
|
-
* @private
|
|
298
|
-
* @returns {Object<string, function(): void>} An object mapping lifecycle hook names to empty functions.
|
|
299
|
-
* The returned object will be merged with the component's context.
|
|
300
|
-
*/
|
|
301
|
-
private _prepareLifecycleHooks;
|
|
302
406
|
/**
|
|
303
407
|
* Processes DOM elements for event binding based on attributes starting with "@".
|
|
304
408
|
* This method handles the event delegation system and ensures proper cleanup of event listeners.
|
|
305
409
|
*
|
|
306
410
|
* @private
|
|
307
411
|
* @param {HTMLElement} container - The container element in which to search for event attributes.
|
|
308
|
-
* @param {
|
|
309
|
-
* @param {Array<
|
|
412
|
+
* @param {ComponentContext} context - The current component context containing event handler definitions.
|
|
413
|
+
* @param {Array<() => void>} listeners - Array to collect cleanup functions for each event listener.
|
|
310
414
|
* @returns {void}
|
|
311
415
|
*/
|
|
312
416
|
private _processEvents;
|
|
@@ -317,8 +421,8 @@ declare class Eleva {
|
|
|
317
421
|
* @private
|
|
318
422
|
* @param {HTMLElement} container - The container element where styles should be injected.
|
|
319
423
|
* @param {string} compName - The component name used to identify the style element.
|
|
320
|
-
* @param {function(
|
|
321
|
-
* @param {
|
|
424
|
+
* @param {(function(ComponentContext): string)|string} styleDef - The component's style definition (function or string).
|
|
425
|
+
* @param {ComponentContext} context - The current component context for style interpolation.
|
|
322
426
|
* @returns {void}
|
|
323
427
|
*/
|
|
324
428
|
private _injectStyles;
|
|
@@ -329,7 +433,7 @@ declare class Eleva {
|
|
|
329
433
|
* @private
|
|
330
434
|
* @param {HTMLElement} element - The DOM element to extract props from
|
|
331
435
|
* @param {string} prefix - The prefix to look for in attributes
|
|
332
|
-
* @returns {
|
|
436
|
+
* @returns {Record<string, string>} An object containing the extracted props
|
|
333
437
|
* @example
|
|
334
438
|
* // For an element with attributes:
|
|
335
439
|
* // <div :name="John" :age="25">
|
|
@@ -363,45 +467,66 @@ type ComponentDefinition = {
|
|
|
363
467
|
/**
|
|
364
468
|
* Optional setup function that initializes the component's state and returns reactive data
|
|
365
469
|
*/
|
|
366
|
-
setup?: ((arg0:
|
|
367
|
-
[x: string]: any;
|
|
368
|
-
}) => ({
|
|
369
|
-
[x: string]: any;
|
|
370
|
-
} | Promise<{
|
|
371
|
-
[x: string]: any;
|
|
372
|
-
}>)) | undefined;
|
|
470
|
+
setup?: ((arg0: ComponentContext) => (Record<string, unknown> | Promise<Record<string, unknown>>)) | undefined;
|
|
373
471
|
/**
|
|
374
472
|
* Required function that defines the component's HTML structure
|
|
375
473
|
*/
|
|
376
|
-
template: (arg0:
|
|
377
|
-
[x: string]: any;
|
|
378
|
-
}) => string | Promise<string>;
|
|
474
|
+
template: ((arg0: ComponentContext) => string | Promise<string>);
|
|
379
475
|
/**
|
|
380
|
-
* Optional function that provides component-scoped CSS styles
|
|
476
|
+
* Optional function or string that provides component-scoped CSS styles
|
|
381
477
|
*/
|
|
382
|
-
style?: ((arg0:
|
|
383
|
-
[x: string]: any;
|
|
384
|
-
}) => string) | undefined;
|
|
478
|
+
style?: string | ((arg0: ComponentContext) => string) | undefined;
|
|
385
479
|
/**
|
|
386
480
|
* Optional object defining nested child components
|
|
387
481
|
*/
|
|
388
|
-
children?:
|
|
389
|
-
[x: string]: ComponentDefinition;
|
|
390
|
-
} | undefined;
|
|
482
|
+
children?: Record<string, ComponentDefinition> | undefined;
|
|
391
483
|
};
|
|
392
|
-
type
|
|
484
|
+
type ComponentContext = {
|
|
393
485
|
/**
|
|
394
|
-
*
|
|
486
|
+
* Component properties passed during mounting
|
|
395
487
|
*/
|
|
396
|
-
|
|
397
|
-
[x: string]: any;
|
|
398
|
-
}) => void;
|
|
488
|
+
props: Record<string, unknown>;
|
|
399
489
|
/**
|
|
400
|
-
*
|
|
490
|
+
* Event emitter instance for component event handling
|
|
401
491
|
*/
|
|
402
|
-
|
|
492
|
+
emitter: Emitter;
|
|
493
|
+
/**
|
|
494
|
+
* <T>(value: T): Signal<T>} signal
|
|
495
|
+
* Factory function to create reactive Signal instances
|
|
496
|
+
*/
|
|
497
|
+
"": Function;
|
|
498
|
+
/**
|
|
499
|
+
* Hook called before component mounting
|
|
500
|
+
*/
|
|
501
|
+
onBeforeMount?: ((arg0: LifecycleHookContext) => Promise<void>) | undefined;
|
|
502
|
+
/**
|
|
503
|
+
* Hook called after component mounting
|
|
504
|
+
*/
|
|
505
|
+
onMount?: ((arg0: LifecycleHookContext) => Promise<void>) | undefined;
|
|
506
|
+
/**
|
|
507
|
+
* Hook called before component update
|
|
508
|
+
*/
|
|
509
|
+
onBeforeUpdate?: ((arg0: LifecycleHookContext) => Promise<void>) | undefined;
|
|
510
|
+
/**
|
|
511
|
+
* Hook called after component update
|
|
512
|
+
*/
|
|
513
|
+
onUpdate?: ((arg0: LifecycleHookContext) => Promise<void>) | undefined;
|
|
514
|
+
/**
|
|
515
|
+
* Hook called during component unmounting
|
|
516
|
+
*/
|
|
517
|
+
onUnmount?: ((arg0: UnmountHookContext) => Promise<void>) | undefined;
|
|
403
518
|
};
|
|
404
|
-
type
|
|
519
|
+
type LifecycleHookContext = {
|
|
520
|
+
/**
|
|
521
|
+
* The DOM element where the component is mounted
|
|
522
|
+
*/
|
|
523
|
+
container: HTMLElement;
|
|
524
|
+
/**
|
|
525
|
+
* The component's reactive state and context data
|
|
526
|
+
*/
|
|
527
|
+
context: ComponentContext;
|
|
528
|
+
};
|
|
529
|
+
type UnmountHookContext = {
|
|
405
530
|
/**
|
|
406
531
|
* The DOM element where the component is mounted
|
|
407
532
|
*/
|
|
@@ -409,13 +534,39 @@ type MountResult = {
|
|
|
409
534
|
/**
|
|
410
535
|
* The component's reactive state and context data
|
|
411
536
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
537
|
+
context: ComponentContext;
|
|
538
|
+
/**
|
|
539
|
+
* Object containing cleanup functions and instances
|
|
540
|
+
*/
|
|
541
|
+
cleanup: {
|
|
542
|
+
watchers: Array<() => void>;
|
|
543
|
+
listeners: Array<() => void>;
|
|
544
|
+
children: Array<MountResult>;
|
|
414
545
|
};
|
|
546
|
+
};
|
|
547
|
+
type MountResult = {
|
|
548
|
+
/**
|
|
549
|
+
* The DOM element where the component is mounted
|
|
550
|
+
*/
|
|
551
|
+
container: HTMLElement;
|
|
552
|
+
/**
|
|
553
|
+
* The component's reactive state and context data
|
|
554
|
+
*/
|
|
555
|
+
data: ComponentContext;
|
|
415
556
|
/**
|
|
416
557
|
* Function to clean up and unmount the component
|
|
417
558
|
*/
|
|
418
|
-
unmount: () => void
|
|
559
|
+
unmount: () => Promise<void>;
|
|
560
|
+
};
|
|
561
|
+
type ElevaPlugin = {
|
|
562
|
+
/**
|
|
563
|
+
* Function that installs the plugin into the Eleva instance
|
|
564
|
+
*/
|
|
565
|
+
install: (arg0: Eleva, arg1: Record<string, unknown>) => void;
|
|
566
|
+
/**
|
|
567
|
+
* Unique identifier name for the plugin
|
|
568
|
+
*/
|
|
569
|
+
name: string;
|
|
419
570
|
};
|
|
420
571
|
|
|
421
572
|
//# sourceMappingURL=index.d.ts.map
|