@skirbi/sugar 0.1.9 → 0.1.11
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/boolean.mjs +1 -22
- package/lib/htmlelement-select.mjs +16 -5
- package/lib/index.mjs +2 -2
- package/lib/livewire.mjs +92 -24
- package/lib/testing.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.11 2026-07-01 04:10:34Z
|
|
4
|
+
|
|
5
|
+
* Debugging session start. There is a weird case of it works via local file
|
|
6
|
+
and not via npm. So I can't really rely on the local file mounts. Ship the
|
|
7
|
+
debug.
|
|
8
|
+
|
|
9
|
+
0.1.10 2026-07-01 01:54:46Z
|
|
10
|
+
|
|
11
|
+
* Add tests to semtic-select
|
|
12
|
+
* Debugging artifacts in livewire.mjs
|
|
13
|
+
|
|
3
14
|
0.1.9 2026-06-10 21:49:27Z
|
|
4
15
|
|
|
5
16
|
* Add wc:rendered custom event to sugar
|
package/lib/boolean.mjs
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
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 (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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.
|
|
5
|
+
const VERSION = "0.1.11";
|
|
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 '
|
|
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
|
@@ -15,31 +15,99 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Only import this when using Sugar components inside a Livewire application.
|
|
17
17
|
*/
|
|
18
|
+
console.log('[sugar-livewire] eval', performance.now())
|
|
19
|
+
|
|
20
|
+
console.log('[sugar-livewire] module loaded', {
|
|
21
|
+
hasLivewire: !!window.Livewire,
|
|
22
|
+
hasHook: !!window.Livewire?.hook,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
let registered = false;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Registers the Sugar Livewire hydration hook.
|
|
29
|
+
*
|
|
30
|
+
* @returns {void}
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
function registerSugarLivewire() {
|
|
34
|
+
console.log('[sugar-livewire] register called', {
|
|
35
|
+
registered,
|
|
36
|
+
hasLivewire: !!window.Livewire,
|
|
37
|
+
hasHook: !!window.Livewire?.hook,
|
|
38
|
+
perf: performance.now(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (registered) return;
|
|
42
|
+
if (!window.Livewire?.hook) return;
|
|
43
|
+
|
|
44
|
+
registered = true;
|
|
45
|
+
|
|
46
|
+
window.Livewire.hook('component.init', ({ component }) => {
|
|
47
|
+
|
|
48
|
+
console.log('[sugar-livewire] component.init hit', component.id);
|
|
49
|
+
|
|
50
|
+
const original = component.processEffects.bind(component);
|
|
51
|
+
component.processEffects = function processSugarEffects(effects) {
|
|
52
|
+
|
|
53
|
+
console.log('[sugar-livewire] definitions', {
|
|
54
|
+
dibuho: !!customElements.get('dibuho-container-panel'),
|
|
55
|
+
panel: !!customElements.get('semtic-panel'),
|
|
56
|
+
header: !!customElements.get('semtic-header'),
|
|
57
|
+
perf: performance.now(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
console.log('[sugar-livewire] processEffects hit', {
|
|
61
|
+
hasHtml: !!effects.html,
|
|
62
|
+
sugarHydrated: !!effects._sugarHydrated,
|
|
63
|
+
perf: performance.now(),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!effects.html) return original(effects);
|
|
67
|
+
if (effects._sugarHydrated) return original(effects);
|
|
68
|
+
|
|
69
|
+
const before = effects.html;
|
|
70
|
+
const staging = document.createElement('div');
|
|
71
|
+
staging.style.display = 'none';
|
|
72
|
+
document.body.appendChild(staging);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
staging.innerHTML = before;
|
|
76
|
+
const after = staging.innerHTML;
|
|
77
|
+
effects.html = after;
|
|
78
|
+
effects._sugarHydrated = true;
|
|
79
|
+
|
|
80
|
+
console.group('[sugar-livewire] html');
|
|
81
|
+
console.log('perf:\n',performance.now());
|
|
82
|
+
console.log('before:\n', before);
|
|
83
|
+
console.log('after:\n', after);
|
|
84
|
+
console.log('changed:', before !== after);
|
|
85
|
+
console.log('handoff:\n', effects.html);
|
|
86
|
+
console.log('handoff is after:', effects.html === after);
|
|
87
|
+
console.groupEnd();
|
|
88
|
+
|
|
89
|
+
return original(effects);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
staging.remove();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
18
97
|
|
|
19
98
|
if (typeof document !== 'undefined') {
|
|
20
|
-
document.addEventListener('livewire:init',
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
});
|
|
99
|
+
document.addEventListener('livewire:init', registerSugarLivewire);
|
|
100
|
+
queueMicrotask(() => {
|
|
101
|
+
registerSugarLivewire();
|
|
44
102
|
});
|
|
45
103
|
}
|
|
104
|
+
|
|
105
|
+
document.addEventListener('livewire:init', () => {
|
|
106
|
+
console.log('[sugar-livewire] livewire:init heard');
|
|
107
|
+
registerSugarLivewire();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
queueMicrotask(() => {
|
|
111
|
+
console.log('[sugar-livewire] microtask fallback');
|
|
112
|
+
registerSugarLivewire();
|
|
113
|
+
});
|
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
|
-
*
|
|
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/
|
|
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.
|
|
65
|
+
"version": "0.1.11"
|
|
63
66
|
}
|