@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 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 Event('input', { bubbles: true, composed: true }));
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 Event('change', { bubbles: true,
205
+ this.dispatchEvent(new EventCtor('change', { bubbles: true,
204
206
  composed: true }));
205
207
  });
206
208
  }
@@ -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?.()) return;
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
- } else if (typeof def.hook === 'string') {
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
- } else {
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.attributeChangedCallbackSugar) {
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
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // SPDX-License-Identifier: MIT
4
4
 
5
- const VERSION = "0.1.14";
5
+ const VERSION = "0.1.16";
6
6
 
7
7
  export { HTMLElementSugar } from './htmlelement.mjs';
8
8
  export { HTMLElementSugarInput } from './htmlelement-input.mjs';
package/package.json CHANGED
@@ -62,5 +62,5 @@
62
62
  "./aliases-register"
63
63
  ],
64
64
  "type": "module",
65
- "version": "0.1.14"
65
+ "version": "0.1.16"
66
66
  }