@skirbi/sugar 0.1.7 → 0.1.8

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/Changes CHANGED
@@ -1,5 +1,10 @@
1
1
  Revision history for @skirbi/sugar
2
2
 
3
+ 0.1.8 2026-06-08 22:43:46Z
4
+
5
+ * Forward value for htmlelement-input.mjs in all cases not just with
6
+ data-sync. Value is a special case for inputs.
7
+
3
8
  0.1.7 2026-06-08 10:59:27Z
4
9
 
5
10
  * Add moveSlot to sugar, multiple components start to create the same logic.
package/README.md CHANGED
@@ -46,6 +46,18 @@ And to register them:
46
46
  MyNewElement.register();
47
47
  ```
48
48
 
49
+ ## Installation
50
+
51
+ Just like any other npm package:
52
+
53
+ ```sh
54
+ npm install @skirbi/sugar
55
+ ```
56
+
57
+ It is however advised to use an override on your project for `@skirbi/sugar` if
58
+ you either use `@skirbi/semtic`, `@skibri/dibuho` or `@skirbi/bolbe`. This will
59
+ allow correct hoisting.
60
+
49
61
  ## Observable patterns
50
62
 
51
63
  You can define attributes to be observable:
@@ -71,6 +71,37 @@ export class HTMLElementSugarInput extends HTMLElementSugar {
71
71
  return parseBoolean(raw);
72
72
  }
73
73
 
74
+ /**
75
+ * Find the wrapped form control.
76
+ *
77
+ * @returns {HTMLInputElement|HTMLSelectElement|HTMLTextAreaElement|null}
78
+ */
79
+ get control() {
80
+ return this.querySelector(this.constructor.controlSelector);
81
+ }
82
+
83
+ set value(value) {
84
+ this._value = value ?? '';
85
+ this._syncValueToControl();
86
+ }
87
+
88
+ get value() {
89
+ const control = this.control;
90
+ if (control && 'value' in control) return control.value;
91
+
92
+ return this._value ?? this.getAttribute('value') ?? '';
93
+ }
94
+
95
+ attributeChangedCallback(name, oldValue, newValue) {
96
+ super.attributeChangedCallback?.(name, oldValue, newValue);
97
+
98
+
99
+ if (name === 'value') {
100
+ this._value = newValue ?? '';
101
+ this._syncValueToControl();
102
+ }
103
+ }
104
+
74
105
  /**
75
106
  * Resolve the effective label position for form-control components.
76
107
  *
@@ -217,6 +248,18 @@ export class HTMLElementSugarInput extends HTMLElementSugar {
217
248
  this._attrObserver.observe(this, { attributes: true });
218
249
  }
219
250
 
251
+ /**
252
+ * Sync the host value attribute/property to the wrapped control property.
253
+ *
254
+ * @returns {void}
255
+ */
256
+ _syncValueToControl() {
257
+ const control = this.control;
258
+ if (!control || !('value' in control)) return;
259
+
260
+ control.value = this.getAttribute('value') ?? this._value ?? '';
261
+ }
262
+
220
263
  /**
221
264
  * One-liner for subclasses:
222
265
  * - find control in fragment
@@ -229,6 +272,10 @@ export class HTMLElementSugarInput extends HTMLElementSugar {
229
272
  enhanceControl(frag) {
230
273
  const control = this.findControl(frag);
231
274
 
275
+ if (this._value !== undefined) {
276
+ control.value = this._value;
277
+ }
278
+
232
279
  const deny = this.getForwardDenySet();
233
280
  const skip = this.getForwardSkipSet();
234
281
 
package/lib/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // SPDX-License-Identifier: MIT
4
4
 
5
- const VERSION = "0.1.7";
5
+ const VERSION = "0.1.8";
6
6
 
7
7
  export { HTMLElementSugar } from './htmlelement.mjs';
8
8
  export { HTMLElementSugarInput } from './htmlelement-input.mjs';
package/package.json CHANGED
@@ -56,5 +56,5 @@
56
56
  },
57
57
  "sideEffects": true,
58
58
  "type": "module",
59
- "version": "0.1.7"
59
+ "version": "0.1.8"
60
60
  }