@skirbi/sugar 0.0.10 → 0.0.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 +28 -0
- package/lib/index.mjs +1 -1
- package/lib/testing.mjs +23 -2
- package/package.json +1 -1
package/Changes
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
Revision history for @skirbi/sugar
|
|
2
2
|
|
|
3
|
+
0.0.11 2026-02-24 16:53:49Z
|
|
4
|
+
|
|
5
|
+
* Fix comparing HTML nodes. Whitespace text nodes are a PITA, we deal with
|
|
6
|
+
them and now you can just compare two nodes regardless how you wrote it.
|
|
7
|
+
Whitespace kinda matters in HTML I guess, until it doesn't.
|
|
8
|
+
|
|
3
9
|
0.0.10 2026-02-24 03:09:34Z
|
|
4
10
|
|
|
5
11
|
* Improve Livewire/morphdom support in withConnectedSugar
|
|
@@ -30,6 +36,28 @@ Revision history for @skirbi/sugar
|
|
|
30
36
|
Where `your-tag-here` represents the authored child element that
|
|
31
37
|
indicates the component has been reverted to its pre-compiled state.
|
|
32
38
|
|
|
39
|
+
The `_compile` function is part of the contract as it authors child
|
|
40
|
+
elements into the final DOM structure. But you are free give it any name
|
|
41
|
+
you'd like. An example implementation may look like this:
|
|
42
|
+
|
|
43
|
+
_compile() {
|
|
44
|
+
const steps = Array.from(this.children)
|
|
45
|
+
.filter(n => n.tagName?.toLowerCase() === 'x-step')
|
|
46
|
+
.map(n => n.textContent ?? '');
|
|
47
|
+
|
|
48
|
+
const frag = this.renderFromTemplate();
|
|
49
|
+
const ol = frag.querySelector('ol[data-steps]');
|
|
50
|
+
|
|
51
|
+
for (const label of steps) {
|
|
52
|
+
const li = document.createElement('li');
|
|
53
|
+
li.textContent = label;
|
|
54
|
+
ol.appendChild(li);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.replaceChildren(frag);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
33
61
|
0.0.9 2026-02-23 10:56:27Z
|
|
34
62
|
|
|
35
63
|
* Fix a bug for connectedCallbacks with Livewire
|
package/lib/index.mjs
CHANGED
package/lib/testing.mjs
CHANGED
|
@@ -129,8 +129,29 @@ export async function assertComponentContract(Class, example) {
|
|
|
129
129
|
*/
|
|
130
130
|
function htmlToFragment(html) {
|
|
131
131
|
const tpl = document.createElement('template');
|
|
132
|
-
tpl.innerHTML = html.trim();
|
|
133
|
-
return tpl.content;
|
|
132
|
+
tpl.innerHTML = html.trim().normalize();
|
|
133
|
+
return stripWhitespaceTextNodes(tpl.content);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Strip whitespace textnodes from an HTML fragment
|
|
138
|
+
*
|
|
139
|
+
* Use primairly to sanitize HTML to compare it
|
|
140
|
+
*
|
|
141
|
+
* @param {node} node - an HTML node
|
|
142
|
+
* @returns {node}
|
|
143
|
+
*/
|
|
144
|
+
function stripWhitespaceTextNodes(node) {
|
|
145
|
+
for (const child of Array.from(node.childNodes)) {
|
|
146
|
+
if (child.nodeType === 3) { // TEXT_NODE
|
|
147
|
+
if (!child.nodeValue.trim()) {
|
|
148
|
+
child.remove();
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
stripWhitespaceTextNodes(child);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return node;
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
/**
|
package/package.json
CHANGED