@skirbi/sugar 0.1.9 → 0.1.10

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.10 2026-07-01 01:54:46Z
4
+
5
+ * Add tests to semtic-select
6
+ * Debugging artifacts in livewire.mjs
7
+
3
8
  0.1.9 2026-06-10 21:49:27Z
4
9
 
5
10
  * Add wc:rendered custom event to sugar
package/lib/boolean.mjs CHANGED
@@ -1,22 +1 @@
1
- // SPDX-FileCopyrightText: 2025 Wesley Schwengle <wesleys@opperschaap.net>
2
- //
3
- // SPDX-License-Identifier: MIT
4
-
5
- /**
6
- * Normalize an HTML attribute value to a boolean.
7
- *
8
- * This function interprets a variety of string-like inputs as either `true` or `false`:
9
- * - Empty string ("") becomes true (e.g. <input disabled>)
10
- * - "false" and "0" become false
11
- * - All other defined values become true
12
- *
13
- * @param {string | null | undefined} value - The attribute value to parse
14
- * @returns {boolean} The normalized boolean result
15
- */
16
- export function parseBoolean(value) {
17
- if (value === null || value === undefined) return false;
18
-
19
- const val = String(value).toLowerCase().trim();
20
-
21
- return val !== 'false' && val !== '0';
22
- }
1
+ export { parseBoolean } from '@opndev/html';
@@ -156,11 +156,12 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
156
156
  else if (hasEndpoint) {
157
157
  this._setupRemote(select, searchEl, cfg);
158
158
  }
159
- else {
160
- if (cfg.placeholder) this._addPlaceholder(select, cfg.placeholder);
161
-
162
- for (const option of authoredOptions) {
163
- select.appendChild(option);
159
+ else {
160
+ if (hasAuthored) {
161
+ this._setAuthoredOptions(select, authoredOptions, cfg);
162
+ }
163
+ else {
164
+ this._setOptions(select, opts, cfg);
164
165
  }
165
166
 
166
167
  if (searchEl) this._setupLocalSearch(select, searchEl);
@@ -173,6 +174,16 @@ export class HTMLElementSugarSelect extends HTMLElementSugarInput {
173
174
  return select;
174
175
  }
175
176
 
177
+ _setAuthoredOptions(select, authoredOptions, cfg) {
178
+ this._clearOptions(select);
179
+
180
+ if (cfg.placeholder) this._addPlaceholder(select, cfg.placeholder);
181
+
182
+ for (const node of authoredOptions) {
183
+ select.appendChild(node);
184
+ }
185
+ }
186
+
176
187
  // TODO: getByPath(x, json) might want to return a console.warn when it
177
188
  // returns undefined. This would help developers spot mistakes? Yes/no/maybe?
178
189
 
package/lib/index.mjs CHANGED
@@ -2,12 +2,12 @@
2
2
  //
3
3
  // SPDX-License-Identifier: MIT
4
4
 
5
- const VERSION = "0.1.9";
5
+ const VERSION = "0.1.10";
6
6
 
7
7
  export { HTMLElementSugar } from './htmlelement.mjs';
8
8
  export { HTMLElementSugarInput } from './htmlelement-input.mjs';
9
9
  export { HTMLElementSugarSelect } from './htmlelement-select.mjs';
10
- export { parseBoolean } from './boolean.mjs';
10
+ export { parseBoolean } from '@opndev/html';
11
11
  export { registerDevAlias, applyDevAliases } from './aliases.mjs';
12
12
  export { registerAliases } from './aliases-register.mjs';
13
13
  export { withConnectedSugar } from './with-connected-sugar.mjs';
package/lib/livewire.mjs CHANGED
@@ -16,30 +16,105 @@
16
16
  * Only import this when using Sugar components inside a Livewire application.
17
17
  */
18
18
 
19
+ /*
20
+ console.log('[sugar-livewire] module loaded', {
21
+ hasLivewire: !!window.Livewire,
22
+ hasHook: !!window.Livewire?.hook,
23
+ });
24
+ */
25
+
26
+ let registered = false;
27
+
28
+
29
+ /**
30
+ * Registers the Sugar Livewire hydration hook.
31
+ *
32
+ * @returns {void}
33
+ */
34
+ function registerSugarLivewire() {
35
+ /*
36
+ console.log('[sugar-livewire] register called', {
37
+ registered,
38
+ hasLivewire: !!window.Livewire,
39
+ hasHook: !!window.Livewire?.hook,
40
+ });
41
+ */
42
+
43
+ if (registered) return;
44
+ if (!window.Livewire?.hook) return;
45
+
46
+ registered = true;
47
+
48
+ window.Livewire.hook('component.init', ({ component }) => {
49
+
50
+ // console.log('[sugar-livewire] component.init hit', component.id);
51
+
52
+ const original = component.processEffects.bind(component);
53
+
54
+ component.processEffects = function processSugarEffects(effects) {
55
+ /*
56
+ console.log('[sugar-livewire] definitions', {
57
+ dibuho: !!customElements.get('dibuho-container-panel'),
58
+ panel: !!customElements.get('semtic-panel'),
59
+ header: !!customElements.get('semtic-header'),
60
+ });
61
+
62
+ console.log('[sugar-livewire] processEffects hit', {
63
+ hasHtml: !!effects.html,
64
+ sugarHydrated: !!effects._sugarHydrated,
65
+ });
66
+ */
67
+
68
+ if (!effects.html) return original(effects);
69
+ if (effects._sugarHydrated) return original(effects);
70
+
71
+ const before = effects.html;
72
+
73
+ const staging = document.createElement('div');
74
+ staging.style.display = 'none';
75
+ document.body.appendChild(staging);
76
+
77
+ try {
78
+ staging.innerHTML = before;
79
+
80
+ const after = staging.innerHTML;
81
+
82
+ effects.html = after;
83
+ effects._sugarHydrated = true;
84
+
85
+ /*
86
+ console.group('[sugar-livewire] html');
87
+ console.log('before:\n', before);
88
+ console.log('after:\n', after);
89
+ console.log('changed:', before !== after);
90
+ console.log('handoff:\n', effects.html);
91
+ console.log('handoff is after:', effects.html === after);
92
+ console.groupEnd();
93
+ */
94
+
95
+ return original(effects);
96
+ } finally {
97
+ staging.remove();
98
+ }
99
+ };
100
+
101
+ });
102
+ }
103
+
19
104
  if (typeof document !== 'undefined') {
20
- document.addEventListener('livewire:init', () => {
21
- window.Livewire.hook('component.init', ({ component }) => {
22
- const original = component.processEffects.bind(component);
23
-
24
- component.processEffects = function(effects) {
25
- if (!effects.html) return original(effects);
26
- if (effects._sugarHydrated) return original(effects);
27
-
28
- const staging = document.createElement('div');
29
- staging.style.display = 'none';
30
- document.body.appendChild(staging);
31
- staging.innerHTML = effects.html;
32
-
33
- console.log(effects.html);
34
-
35
- Promise.resolve().then(() => Promise.resolve().then(() => {
36
- effects.html = staging.innerHTML;
37
- effects._sugarHydrated = true;
38
- staging.remove();
39
- original(effects);
40
- }));
41
- console.log(effects.html);
42
- };
43
- });
105
+ document.addEventListener('livewire:init', registerSugarLivewire);
106
+
107
+ queueMicrotask(() => {
108
+ registerSugarLivewire();
44
109
  });
45
110
  }
111
+
112
+ document.addEventListener('livewire:init', () => {
113
+ ///console.log('[sugar-livewire] livewire:init heard');
114
+ registerSugarLivewire();
115
+ });
116
+
117
+ queueMicrotask(() => {
118
+ //console.log('[sugar-livewire] microtask fallback');
119
+ registerSugarLivewire();
120
+ });
package/lib/testing.mjs CHANGED
@@ -12,7 +12,7 @@ import t from 'tap';
12
12
  * This helper verifies:
13
13
  *
14
14
  * 1. `Class.exampleHTML` matches the provided `options.example` snippet.
15
- * 2. After mounting and lifecycle execution, the rendered output matches
15
+ * 1. After mounting and lifecycle execution, the rendered output matches
16
16
  * `Class.exampleRenderedHTML`.
17
17
  *
18
18
  * The component class must define:
package/package.json CHANGED
@@ -7,7 +7,8 @@
7
7
  "url": "https://gitlab.com/skirbi/skirbi/-/issues"
8
8
  },
9
9
  "dependencies": {
10
- "@opndev/util": "latest"
10
+ "@opndev/html": ">=0.0.3",
11
+ "@opndev/util": "*"
11
12
  },
12
13
  "description": "Lightweight base layer for writing custom elements with declarative attributes and template sugar.",
13
14
  "devDependencies": {
@@ -55,9 +56,11 @@
55
56
  "test": "tap"
56
57
  },
57
58
  "sideEffects": [
59
+ "lib/livewire.mjs",
60
+ "lib/aliases-register.mjs",
58
61
  "./livewire",
59
62
  "./aliases-register"
60
63
  ],
61
64
  "type": "module",
62
- "version": "0.1.9"
65
+ "version": "0.1.10"
63
66
  }