@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/parser.js +7 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/fe",
3
- "version": "1.0.0-rc4",
3
+ "version": "1.0.0-rc5",
4
4
  "description": "Frontend framework for building reactive web components",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
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, `${parentPath}.${keyString}`);
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], `${parentPath}.${keyString}`);
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, `${parentPath}.${keyString}`);
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 based on selector, parent path, and index for list items
250
- const itemPath = parentPath
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) {