@skirbi/sugar 0.1.14 → 0.1.16
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/lib/fakedom.mjs +1 -0
- package/lib/htmlelement-input.mjs +6 -4
- package/lib/htmlelement.mjs +11 -5
- package/lib/index.mjs +1 -1
- package/package.json +1 -1
package/Changes
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
Revision history for @skirbi/sugar
|
|
2
2
|
|
|
3
|
+
0.1.16 2026-07-08 15:47:05Z
|
|
4
|
+
|
|
5
|
+
* Fix event handling in testsuites. Under jsdom, a bare `Event` reference
|
|
6
|
+
resolves to Node's own global Event class, not a jsdom window.Event.
|
|
7
|
+
Jsdom's dispatchEvent rejects an event instance that isn't its own realm's
|
|
8
|
+
Event, so window.Event must be preferred whenever it exists.
|
|
9
|
+
|
|
10
|
+
0.1.15 2026-07-03 22:08:57Z
|
|
11
|
+
|
|
12
|
+
* Add MouseEvent for @skirbi/semtic
|
|
13
|
+
|
|
3
14
|
0.1.14 2026-07-01 19:35:00Z
|
|
4
15
|
|
|
5
16
|
* withConnectedSucu, not withConnectSucu. Typo's are yya (pun intended).
|
package/lib/fakedom.mjs
CHANGED
|
@@ -41,6 +41,7 @@ export async function setupDomForTesting(
|
|
|
41
41
|
global.window = dom.window;
|
|
42
42
|
global.MutationObserver = dom.window.MutationObserver;
|
|
43
43
|
global.CustomEvent = dom.window.CustomEvent;
|
|
44
|
+
global.MouseEvent = dom.window.MouseEvent;
|
|
44
45
|
|
|
45
46
|
const projectRoot = process.cwd();
|
|
46
47
|
|
|
@@ -94,8 +94,6 @@ export class HTMLElementSugarInput extends HTMLElementSugar {
|
|
|
94
94
|
|
|
95
95
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
96
96
|
super.attributeChangedCallback?.(name, oldValue, newValue);
|
|
97
|
-
|
|
98
|
-
|
|
99
97
|
if (name === 'value') {
|
|
100
98
|
this._value = newValue ?? '';
|
|
101
99
|
this._syncValueToControl();
|
|
@@ -187,6 +185,10 @@ export class HTMLElementSugarInput extends HTMLElementSugar {
|
|
|
187
185
|
setupFormControl(control) {
|
|
188
186
|
const valueAttr = this.constructor.valueAttr || 'value';
|
|
189
187
|
|
|
188
|
+
// Resolve Event from the current runtime (jsdom exposes it on window, not
|
|
189
|
+
// always on globalThis)
|
|
190
|
+
const EventCtor = globalThis.window?.Event || globalThis.Event;
|
|
191
|
+
|
|
190
192
|
const syncHostValue = () => {
|
|
191
193
|
if ('value' in control) {
|
|
192
194
|
this.setAttribute(valueAttr, control.value ?? '');
|
|
@@ -195,12 +197,12 @@ export class HTMLElementSugarInput extends HTMLElementSugar {
|
|
|
195
197
|
|
|
196
198
|
control.addEventListener('input', () => {
|
|
197
199
|
syncHostValue();
|
|
198
|
-
this.dispatchEvent(new
|
|
200
|
+
this.dispatchEvent(new EventCtor('input', { bubbles: true, composed: true }));
|
|
199
201
|
});
|
|
200
202
|
|
|
201
203
|
control.addEventListener('change', () => {
|
|
202
204
|
syncHostValue();
|
|
203
|
-
this.dispatchEvent(new
|
|
205
|
+
this.dispatchEvent(new EventCtor('change', { bubbles: true,
|
|
204
206
|
composed: true }));
|
|
205
207
|
});
|
|
206
208
|
}
|
package/lib/htmlelement.mjs
CHANGED
|
@@ -348,29 +348,35 @@ export class HTMLElementSugar extends HTMLElement {
|
|
|
348
348
|
/**
|
|
349
349
|
* Called when an observed attribute changes.
|
|
350
350
|
* @param {string} name - The attribute name
|
|
351
|
-
* @param {string|null} oldVal - Previous value (unused)
|
|
351
|
+
* @param {string|null} oldVal - Previous value (unused without a hook)
|
|
352
352
|
* @param {string|null} newVal - New value
|
|
353
353
|
*/
|
|
354
354
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
355
355
|
this._applyAttribute(name, newVal);
|
|
356
356
|
|
|
357
|
-
if (!this.hasRenderedShape
|
|
357
|
+
if (!this.hasRenderedShape()) return;
|
|
358
358
|
|
|
359
359
|
const def = this.constructor.attributeDefs?.[name];
|
|
360
360
|
|
|
361
361
|
if (def?.hook) {
|
|
362
362
|
if (typeof def.hook === 'function') {
|
|
363
363
|
def.hook(this, newVal, oldVal);
|
|
364
|
-
}
|
|
364
|
+
}
|
|
365
|
+
else if (typeof def.hook === 'string') {
|
|
365
366
|
const el = this.querySelector(def.hook);
|
|
366
367
|
if (el) el.textContent = newVal ?? '';
|
|
367
368
|
}
|
|
368
|
-
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
369
371
|
const el = this.querySelector(`[semtic-${name}]`);
|
|
370
372
|
if (el) el.textContent = newVal ?? '';
|
|
371
373
|
}
|
|
372
374
|
|
|
373
|
-
if (this.
|
|
375
|
+
if (this.updatedAttributeSugar) {
|
|
376
|
+
this.updatedAttributeSugar(name, oldVal, newVal);
|
|
377
|
+
}
|
|
378
|
+
else if (this.attributeChangedCallbackSugar) {
|
|
379
|
+
console.warn("Using deprecated attributeChangedCallbackSugar");
|
|
374
380
|
this.attributeChangedCallbackSugar(name, oldVal, newVal);
|
|
375
381
|
}
|
|
376
382
|
}
|
package/lib/index.mjs
CHANGED
package/package.json
CHANGED