vite-plugin-vanjs 0.2.0 → 0.2.2
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/package.json +1 -1
- package/router/helpers.mjs +7 -1
- package/router/router.mjs +10 -4
package/package.json
CHANGED
package/router/helpers.mjs
CHANGED
|
@@ -38,7 +38,13 @@ export const resolveChildren = (module) => {
|
|
|
38
38
|
: typeof module.component === "function"
|
|
39
39
|
? module.component()
|
|
40
40
|
: module.component;
|
|
41
|
-
|
|
41
|
+
// JSX Fragments return their children array directly, so a component
|
|
42
|
+
// returning [<>...</>] produces [[...]] (nested). flatten() ensures
|
|
43
|
+
// callers always receive a flat list of DOM nodes.
|
|
44
|
+
const raw = cp
|
|
45
|
+
? Array.from(unwrap(cp).children)
|
|
46
|
+
: /* istanbul ignore next */ [];
|
|
47
|
+
return raw.flat();
|
|
42
48
|
};
|
|
43
49
|
|
|
44
50
|
/**
|
package/router/router.mjs
CHANGED
|
@@ -60,12 +60,13 @@ const buildChain = (mod, outlet) => {
|
|
|
60
60
|
if (chain.length === 0) {
|
|
61
61
|
const nodes = leafFn ? leafFn() : /* istanbul ignore next */ [];
|
|
62
62
|
/* istanbul ignore next */
|
|
63
|
-
return Array.isArray(nodes) ? nodes : [nodes];
|
|
63
|
+
return Array.isArray(nodes) ? nodes.flat() : [nodes];
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Fill the outlet with the leaf content
|
|
67
|
-
const
|
|
67
|
+
const raw = leafFn ? leafFn() : /* istanbul ignore next */ [];
|
|
68
68
|
/* istanbul ignore else */
|
|
69
|
+
const leafContent = Array.isArray(raw) ? raw.flat() : raw;
|
|
69
70
|
if (Array.isArray(leafContent)) {
|
|
70
71
|
outlet.replaceChildren(...leafContent);
|
|
71
72
|
} else {
|
|
@@ -76,8 +77,12 @@ const buildChain = (mod, outlet) => {
|
|
|
76
77
|
let content = [outlet];
|
|
77
78
|
for (let k = chain.length - 1; k >= 0; k--) {
|
|
78
79
|
content = chain[k].component({ children: content });
|
|
79
|
-
/* istanbul ignore
|
|
80
|
+
/* istanbul ignore next */
|
|
80
81
|
if (!Array.isArray(content)) content = [content];
|
|
82
|
+
// JSX Fragments return their children array directly, so a layout
|
|
83
|
+
// returning [<>...</>] produces [[...]] (nested). flatten() ensures
|
|
84
|
+
// replaceChildren always receives a flat list of DOM nodes.
|
|
85
|
+
content = content.flat();
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
return content;
|
|
@@ -171,8 +176,9 @@ export const Router = (initialProps = /* istanbul ignore next */ {}) => {
|
|
|
171
176
|
// All layouts shared — only the leaf changed.
|
|
172
177
|
// Directly swap the outlet's children; layout DOM is untouched.
|
|
173
178
|
const leafFn = mod.leaf;
|
|
174
|
-
const
|
|
179
|
+
const raw = leafFn ? leafFn() : /* istanbul ignore next */ [];
|
|
175
180
|
/* istanbul ignore else */
|
|
181
|
+
const leafContent = Array.isArray(raw) ? raw.flat() : raw;
|
|
176
182
|
if (Array.isArray(leafContent)) {
|
|
177
183
|
outlet.replaceChildren(...leafContent);
|
|
178
184
|
} else {
|