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.
Files changed (97) hide show
  1. package/README.md +21 -10
  2. package/dist/{eleva-plugins.cjs.js → eleva-plugins.cjs} +1002 -292
  3. package/dist/eleva-plugins.cjs.map +1 -0
  4. package/dist/eleva-plugins.d.cts +1352 -0
  5. package/dist/eleva-plugins.d.cts.map +1 -0
  6. package/dist/eleva-plugins.d.ts +1352 -0
  7. package/dist/eleva-plugins.d.ts.map +1 -0
  8. package/dist/{eleva-plugins.esm.js → eleva-plugins.js} +1002 -292
  9. package/dist/eleva-plugins.js.map +1 -0
  10. package/dist/eleva-plugins.umd.js +1001 -291
  11. package/dist/eleva-plugins.umd.js.map +1 -1
  12. package/dist/eleva-plugins.umd.min.js +1 -1
  13. package/dist/eleva-plugins.umd.min.js.map +1 -1
  14. package/dist/{eleva.cjs.js → eleva.cjs} +421 -191
  15. package/dist/eleva.cjs.map +1 -0
  16. package/dist/eleva.d.cts +1329 -0
  17. package/dist/eleva.d.cts.map +1 -0
  18. package/dist/eleva.d.ts +473 -226
  19. package/dist/eleva.d.ts.map +1 -0
  20. package/dist/{eleva.esm.js → eleva.js} +422 -192
  21. package/dist/eleva.js.map +1 -0
  22. package/dist/eleva.umd.js +420 -190
  23. package/dist/eleva.umd.js.map +1 -1
  24. package/dist/eleva.umd.min.js +1 -1
  25. package/dist/eleva.umd.min.js.map +1 -1
  26. package/dist/plugins/attr.cjs +279 -0
  27. package/dist/plugins/attr.cjs.map +1 -0
  28. package/dist/plugins/attr.d.cts +101 -0
  29. package/dist/plugins/attr.d.cts.map +1 -0
  30. package/dist/plugins/attr.d.ts +101 -0
  31. package/dist/plugins/attr.d.ts.map +1 -0
  32. package/dist/plugins/attr.js +276 -0
  33. package/dist/plugins/attr.js.map +1 -0
  34. package/dist/plugins/attr.umd.js +111 -22
  35. package/dist/plugins/attr.umd.js.map +1 -1
  36. package/dist/plugins/attr.umd.min.js +1 -1
  37. package/dist/plugins/attr.umd.min.js.map +1 -1
  38. package/dist/plugins/router.cjs +1873 -0
  39. package/dist/plugins/router.cjs.map +1 -0
  40. package/dist/plugins/router.d.cts +1296 -0
  41. package/dist/plugins/router.d.cts.map +1 -0
  42. package/dist/plugins/router.d.ts +1296 -0
  43. package/dist/plugins/router.d.ts.map +1 -0
  44. package/dist/plugins/router.js +1870 -0
  45. package/dist/plugins/router.js.map +1 -0
  46. package/dist/plugins/router.umd.js +482 -186
  47. package/dist/plugins/router.umd.js.map +1 -1
  48. package/dist/plugins/router.umd.min.js +1 -1
  49. package/dist/plugins/router.umd.min.js.map +1 -1
  50. package/dist/plugins/store.cjs +920 -0
  51. package/dist/plugins/store.cjs.map +1 -0
  52. package/dist/plugins/store.d.cts +266 -0
  53. package/dist/plugins/store.d.cts.map +1 -0
  54. package/dist/plugins/store.d.ts +266 -0
  55. package/dist/plugins/store.d.ts.map +1 -0
  56. package/dist/plugins/store.js +917 -0
  57. package/dist/plugins/store.js.map +1 -0
  58. package/dist/plugins/store.umd.js +410 -85
  59. package/dist/plugins/store.umd.js.map +1 -1
  60. package/dist/plugins/store.umd.min.js +1 -1
  61. package/dist/plugins/store.umd.min.js.map +1 -1
  62. package/package.json +112 -68
  63. package/src/core/Eleva.js +195 -115
  64. package/src/index.cjs +10 -0
  65. package/src/index.js +11 -0
  66. package/src/modules/Emitter.js +68 -20
  67. package/src/modules/Renderer.js +82 -20
  68. package/src/modules/Signal.js +43 -15
  69. package/src/modules/TemplateEngine.js +50 -9
  70. package/src/plugins/Attr.js +121 -19
  71. package/src/plugins/Router.js +526 -181
  72. package/src/plugins/Store.js +448 -69
  73. package/src/plugins/index.js +1 -0
  74. package/types/core/Eleva.d.ts +263 -169
  75. package/types/core/Eleva.d.ts.map +1 -1
  76. package/types/index.d.cts +3 -0
  77. package/types/index.d.cts.map +1 -0
  78. package/types/index.d.ts +5 -0
  79. package/types/index.d.ts.map +1 -1
  80. package/types/modules/Emitter.d.ts +73 -30
  81. package/types/modules/Emitter.d.ts.map +1 -1
  82. package/types/modules/Renderer.d.ts +48 -18
  83. package/types/modules/Renderer.d.ts.map +1 -1
  84. package/types/modules/Signal.d.ts +44 -16
  85. package/types/modules/Signal.d.ts.map +1 -1
  86. package/types/modules/TemplateEngine.d.ts +46 -11
  87. package/types/modules/TemplateEngine.d.ts.map +1 -1
  88. package/types/plugins/Attr.d.ts +83 -16
  89. package/types/plugins/Attr.d.ts.map +1 -1
  90. package/types/plugins/Router.d.ts +498 -207
  91. package/types/plugins/Router.d.ts.map +1 -1
  92. package/types/plugins/Store.d.ts +211 -37
  93. package/types/plugins/Store.d.ts.map +1 -1
  94. package/dist/eleva-plugins.cjs.js.map +0 -1
  95. package/dist/eleva-plugins.esm.js.map +0 -1
  96. package/dist/eleva.cjs.js.map +0 -1
  97. package/dist/eleva.esm.js.map +0 -1
@@ -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.0.0",
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
- * @param {Object} eleva - The Eleva instance
62
- * @param {Object} options - Plugin configuration options
63
- * @param {boolean} [options.enableAria=true] - Enable ARIA attribute handling
64
- * @param {boolean} [options.enableData=true] - Enable data attribute handling
65
- * @param {boolean} [options.enableBoolean=true] - Enable boolean attribute handling
66
- * @param {boolean} [options.enableDynamic=true] - Enable dynamic property detection
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
- * @param {HTMLElement} oldEl - The original element to update
86
- * @param {HTMLElement} newEl - The new element to update
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
- // Override the _patchNode method to use our attribute handler
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
- * @param {Object} eleva - The Eleva instance
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