@skirbi/sugar 0.1.6 → 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 +11 -0
- package/README.md +12 -0
- package/lib/htmlelement-input.mjs +47 -0
- package/lib/htmlelement.mjs +14 -0
- package/lib/index.mjs +1 -1
- package/package.json +5 -2
package/Changes
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
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
|
+
|
|
8
|
+
0.1.7 2026-06-08 10:59:27Z
|
|
9
|
+
|
|
10
|
+
* Add moveSlot to sugar, multiple components start to create the same logic.
|
|
11
|
+
* Add keywords to dist.toml/package.json
|
|
12
|
+
* Add tests for aliases
|
|
13
|
+
|
|
3
14
|
0.1.6 2026-06-08 01:05:36Z
|
|
4
15
|
|
|
5
16
|
* Add attributeChangedCallback hook system
|
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/htmlelement.mjs
CHANGED
|
@@ -511,5 +511,19 @@ export class HTMLElementSugar extends HTMLElement {
|
|
|
511
511
|
this._morphElement(this, frag);
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
/**
|
|
515
|
+
* Move named slot children into the rendered target.
|
|
516
|
+
*
|
|
517
|
+
* @param {string} name
|
|
518
|
+
* @param {Element} target
|
|
519
|
+
* @returns {void}
|
|
520
|
+
*/
|
|
521
|
+
moveSlot(name, target) {
|
|
522
|
+
for (const node of [...this.$$(`[slot="${name}"]`)]) {
|
|
523
|
+
node.removeAttribute('slot');
|
|
524
|
+
target.appendChild(node);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
514
528
|
}
|
|
515
529
|
|
package/lib/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -35,7 +35,10 @@
|
|
|
35
35
|
"semantic",
|
|
36
36
|
"htmlelementsugar",
|
|
37
37
|
"html",
|
|
38
|
-
"authoring"
|
|
38
|
+
"authoring",
|
|
39
|
+
"light dom",
|
|
40
|
+
"progressive enhancement",
|
|
41
|
+
"design system"
|
|
39
42
|
],
|
|
40
43
|
"license": "MIT",
|
|
41
44
|
"name": "@skirbi/sugar",
|
|
@@ -53,5 +56,5 @@
|
|
|
53
56
|
},
|
|
54
57
|
"sideEffects": true,
|
|
55
58
|
"type": "module",
|
|
56
|
-
"version": "0.1.
|
|
59
|
+
"version": "0.1.8"
|
|
57
60
|
}
|