@rettangoli/fe 1.0.0-rc4 → 1.0.0-rc5
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/src/parser.js +7 -8
package/package.json
CHANGED
package/src/parser.js
CHANGED
|
@@ -65,6 +65,8 @@ export const createVirtualDom = ({
|
|
|
65
65
|
function processItems(currentItems, parentPath = "") {
|
|
66
66
|
return currentItems
|
|
67
67
|
.map((item, index) => {
|
|
68
|
+
const nodePath = parentPath ? `${parentPath}.${index}` : String(index);
|
|
69
|
+
|
|
68
70
|
// Handle text nodes
|
|
69
71
|
if (typeof item === "string" || typeof item === "number") {
|
|
70
72
|
return String(item);
|
|
@@ -86,11 +88,11 @@ export const createVirtualDom = ({
|
|
|
86
88
|
// Skip numeric keys that might come from array indices
|
|
87
89
|
if (!isNaN(Number(keyString))) {
|
|
88
90
|
if (Array.isArray(value)) {
|
|
89
|
-
return processItems(value,
|
|
91
|
+
return processItems(value, nodePath);
|
|
90
92
|
} else if (typeof value === "object" && value !== null) {
|
|
91
93
|
const nestedEntries = Object.entries(value);
|
|
92
94
|
if (nestedEntries.length > 0) {
|
|
93
|
-
return processItems([value],
|
|
95
|
+
return processItems([value], nodePath);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
return String(value);
|
|
@@ -182,7 +184,7 @@ export const createVirtualDom = ({
|
|
|
182
184
|
if (typeof value === "string" || typeof value === "number") {
|
|
183
185
|
childrenOrText = String(value);
|
|
184
186
|
} else if (Array.isArray(value)) {
|
|
185
|
-
childrenOrText = processItems(value,
|
|
187
|
+
childrenOrText = processItems(value, nodePath);
|
|
186
188
|
} else {
|
|
187
189
|
childrenOrText = [];
|
|
188
190
|
}
|
|
@@ -246,11 +248,8 @@ export const createVirtualDom = ({
|
|
|
246
248
|
if (elementIdForRefs) {
|
|
247
249
|
snabbdomData.key = elementIdForRefs;
|
|
248
250
|
} else if (selector) {
|
|
249
|
-
// Generate a key
|
|
250
|
-
|
|
251
|
-
? `${parentPath}.${index}`
|
|
252
|
-
: String(index);
|
|
253
|
-
snabbdomData.key = `${selector}-${itemPath}`;
|
|
251
|
+
// Generate a key from selector and stable structural path.
|
|
252
|
+
snabbdomData.key = `${selector}-${nodePath}`;
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
if (Object.keys(attrs).length > 0) {
|