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/src/plugins/Attr.js
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @module eleva/plugins/attr
|
|
5
|
+
* @fileoverview Attribute plugin providing ARIA, data, boolean, and dynamic attribute handling.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// TYPE DEFINITIONS
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
// External Type Imports
|
|
14
|
+
// -----------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Type imports from the Eleva core library.
|
|
18
|
+
* @typedef {import('eleva').Eleva} Eleva
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// -----------------------------------------------------------------------------
|
|
22
|
+
// Attr Type Definitions
|
|
23
|
+
// -----------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for the AttrPlugin.
|
|
27
|
+
* @typedef {Object} AttrPluginOptions
|
|
28
|
+
* @property {boolean} [enableAria=true]
|
|
29
|
+
* Enable ARIA attribute handling.
|
|
30
|
+
* @property {boolean} [enableData=true]
|
|
31
|
+
* Enable data attribute handling.
|
|
32
|
+
* @property {boolean} [enableBoolean=true]
|
|
33
|
+
* Enable boolean attribute handling.
|
|
34
|
+
* @property {boolean} [enableDynamic=true]
|
|
35
|
+
* Enable dynamic property detection.
|
|
36
|
+
* @description Configuration options passed to AttrPlugin.install().
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Function signature for attribute update operations.
|
|
41
|
+
* @typedef {(oldEl: HTMLElement, newEl: HTMLElement) => void} AttributeUpdateFunction
|
|
42
|
+
* @description Updates attributes on oldEl to match newEl's attributes.
|
|
43
|
+
*/
|
|
44
|
+
|
|
3
45
|
/**
|
|
4
46
|
* A regular expression to match hyphenated lowercase letters.
|
|
5
47
|
* @private
|
|
@@ -47,7 +89,7 @@ export const AttrPlugin = {
|
|
|
47
89
|
* Plugin version
|
|
48
90
|
* @type {string}
|
|
49
91
|
*/
|
|
50
|
-
version: "1.
|
|
92
|
+
version: "1.1.0",
|
|
51
93
|
|
|
52
94
|
/**
|
|
53
95
|
* Plugin description
|
|
@@ -56,14 +98,48 @@ export const AttrPlugin = {
|
|
|
56
98
|
description: "Advanced attribute handling for Eleva components",
|
|
57
99
|
|
|
58
100
|
/**
|
|
59
|
-
* Installs the plugin into the Eleva instance
|
|
101
|
+
* Installs the plugin into the Eleva instance.
|
|
60
102
|
*
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
103
|
+
* @public
|
|
104
|
+
* Method wrapping behavior:
|
|
105
|
+
* - Stores original `_patchNode` in `renderer._originalPatchNode`
|
|
106
|
+
* - Overrides `renderer._patchNode` to use enhanced attribute handling
|
|
107
|
+
* - Adds `renderer.updateAttributes` and `eleva.updateElementAttributes` helpers
|
|
108
|
+
* - Call `uninstall()` to restore original behavior
|
|
109
|
+
*
|
|
110
|
+
* @param {Eleva} eleva - The Eleva instance to enhance.
|
|
111
|
+
* @param {AttrPluginOptions} options - Plugin configuration options.
|
|
112
|
+
* @param {boolean} [options.enableAria=true] - Enable ARIA attribute handling.
|
|
113
|
+
* Maps aria-* attributes to DOM properties (e.g., aria-expanded → ariaExpanded).
|
|
114
|
+
* @param {boolean} [options.enableData=true] - Enable data attribute handling.
|
|
115
|
+
* Syncs data-* attributes with element.dataset for consistent access.
|
|
116
|
+
* @param {boolean} [options.enableBoolean=true] - Enable boolean attribute handling.
|
|
117
|
+
* Treats empty strings and attribute names as true, "false" string as false.
|
|
118
|
+
* @param {boolean} [options.enableDynamic=true] - Enable dynamic property detection.
|
|
119
|
+
* Searches element prototype chain for property matches (useful for custom elements).
|
|
120
|
+
* @returns {void}
|
|
121
|
+
* @example
|
|
122
|
+
* // Basic installation with defaults
|
|
123
|
+
* app.use(AttrPlugin);
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // Custom configuration
|
|
127
|
+
* app.use(AttrPlugin, {
|
|
128
|
+
* enableAria: true,
|
|
129
|
+
* enableData: true,
|
|
130
|
+
* enableBoolean: true,
|
|
131
|
+
* enableDynamic: false // Disable for performance
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* // Using ARIA attributes in templates
|
|
136
|
+
* template: (ctx) => `
|
|
137
|
+
* <div role="dialog" aria-modal="true" aria-labelledby="title">
|
|
138
|
+
* <h2 id="title">Modal Title</h2>
|
|
139
|
+
* <button aria-expanded="${ctx.isOpen.value}">Toggle</button>
|
|
140
|
+
* </div>
|
|
141
|
+
* `
|
|
142
|
+
* @see uninstall - Remove the plugin and restore original behavior.
|
|
67
143
|
*/
|
|
68
144
|
install(eleva, options = {}) {
|
|
69
145
|
const {
|
|
@@ -75,15 +151,24 @@ export const AttrPlugin = {
|
|
|
75
151
|
|
|
76
152
|
/**
|
|
77
153
|
* Updates the attributes of an element to match a new element's attributes.
|
|
78
|
-
* This method provides sophisticated attribute processing including:
|
|
79
|
-
* - ARIA attribute handling with proper property mapping
|
|
80
|
-
* - Data attribute management
|
|
81
|
-
* - Boolean attribute processing
|
|
82
|
-
* - Dynamic property detection and mapping
|
|
83
|
-
* - Attribute cleanup and removal
|
|
84
154
|
*
|
|
85
|
-
*
|
|
86
|
-
* @
|
|
155
|
+
* Processing order:
|
|
156
|
+
* 1. Skip event attributes (@click, @input) - handled by Eleva's event system
|
|
157
|
+
* 2. Skip unchanged attributes - optimization
|
|
158
|
+
* 3. ARIA attributes (aria-*): Map to DOM properties (aria-expanded → ariaExpanded)
|
|
159
|
+
* 4. Data attributes (data-*): Update both dataset and attribute
|
|
160
|
+
* 5. Boolean attributes: Handle empty string as true, "false" as false
|
|
161
|
+
* 6. Other attributes: Map to properties with dynamic detection for custom elements
|
|
162
|
+
* 7. Remove old attributes not present in new element
|
|
163
|
+
*
|
|
164
|
+
* Dynamic property detection (when enableDynamic=true):
|
|
165
|
+
* - Checks if property exists directly on element
|
|
166
|
+
* - Searches element's prototype chain for case-insensitive matches
|
|
167
|
+
* - Enables compatibility with custom elements and Web Components
|
|
168
|
+
*
|
|
169
|
+
* @inner
|
|
170
|
+
* @param {HTMLElement} oldEl - The original element to update (modified in-place).
|
|
171
|
+
* @param {HTMLElement} newEl - The reference element with desired attributes.
|
|
87
172
|
* @returns {void}
|
|
88
173
|
*/
|
|
89
174
|
const updateAttributes = (oldEl, newEl) => {
|
|
@@ -193,7 +278,14 @@ export const AttrPlugin = {
|
|
|
193
278
|
const originalPatchNode = eleva.renderer._patchNode;
|
|
194
279
|
eleva.renderer._originalPatchNode = originalPatchNode;
|
|
195
280
|
|
|
196
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Overridden _patchNode method that uses enhanced attribute handling.
|
|
283
|
+
* Delegates to `updateAttributes` instead of the basic `_updateAttributes`.
|
|
284
|
+
*
|
|
285
|
+
* @param {Node} oldNode - The original DOM node to update.
|
|
286
|
+
* @param {Node} newNode - The new DOM node with desired state.
|
|
287
|
+
* @returns {void}
|
|
288
|
+
*/
|
|
197
289
|
eleva.renderer._patchNode = function (oldNode, newNode) {
|
|
198
290
|
if (oldNode?._eleva_instance) return;
|
|
199
291
|
|
|
@@ -221,13 +313,23 @@ export const AttrPlugin = {
|
|
|
221
313
|
});
|
|
222
314
|
|
|
223
315
|
// Add utility methods for manual attribute updates
|
|
316
|
+
/** @type {AttributeUpdateFunction} */
|
|
224
317
|
eleva.updateElementAttributes = updateAttributes;
|
|
225
318
|
},
|
|
226
319
|
|
|
227
320
|
/**
|
|
228
|
-
* Uninstalls the plugin from the Eleva instance
|
|
321
|
+
* Uninstalls the plugin from the Eleva instance.
|
|
229
322
|
*
|
|
230
|
-
* @
|
|
323
|
+
* @public
|
|
324
|
+
* @param {Eleva} eleva - The Eleva instance.
|
|
325
|
+
* @returns {void}
|
|
326
|
+
* @description
|
|
327
|
+
* Restores the original renderer patching behavior and removes
|
|
328
|
+
* `eleva.updateElementAttributes`.
|
|
329
|
+
* @example
|
|
330
|
+
* // Uninstall the plugin
|
|
331
|
+
* AttrPlugin.uninstall(app);
|
|
332
|
+
* @see install - Install the plugin.
|
|
231
333
|
*/
|
|
232
334
|
uninstall(eleva) {
|
|
233
335
|
// Restore original _patchNode method if it exists
|