RobinsAIWorld commited on
Commit
bf8ad4a
·
verified ·
1 Parent(s): 47cb9f7

🐳 10/02 - 14:12 - still broken

Browse files
Files changed (1) hide show
  1. script.js +12 -15
script.js CHANGED
@@ -1,4 +1,4 @@
1
- document.addEventListener('DOMContentLoaded', function() {
2
  ======= Sample JSON data
3
  const sampleJSON = {
4
  "name": "John Doe",
@@ -489,7 +489,7 @@ document.addEventListener('DOMContentLoaded', function() {
489
  const currentValue = type === 'key' ? key : getValue(parentKey, key);
490
 
491
  // Handle undefined/null values gracefully
492
- if (currentValue === undefined) {
493
  return;
494
  }
495
 
@@ -641,46 +641,43 @@ document.addEventListener('DOMContentLoaded', function() {
641
  if (parentKey === 'root') {
642
  const keys = Object.keys(jsonData);
643
  const index = keys.indexOf(key);
644
- const newData = {};
645
 
646
  if (index === -1 || index === keys.length - 1) {
647
  // Append at the end
648
- Object.assign(newData, jsonData);
649
- newData[newKey] = '';
650
  } else {
651
- // Insert after current
 
652
  keys.forEach((k, i) => {
653
  newData[k] = jsonData[k];
654
  if (i === index) {
655
  newData[newKey] = '';
656
  }
657
  });
 
 
658
  }
659
-
660
- jsonData = newData;
661
  } else {
662
  const parent = findElementByKey(jsonData, parentKey);
663
  if (parent && typeof parent === 'object' && !Array.isArray(parent)) {
664
  const keys = Object.keys(parent);
665
  const index = keys.indexOf(key);
666
- const newData = {};
667
 
668
  if (index === -1 || index === keys.length - 1) {
669
  // Append at the end
670
- Object.assign(newData, parent);
671
- newData[newKey] = '';
672
  } else {
673
- // Insert after current
 
674
  keys.forEach((k, i) => {
675
  newData[k] = parent[k];
676
  if (i === index) {
677
  newData[newKey] = '';
678
  }
679
  });
 
 
680
  }
681
-
682
- Object.keys(parent).forEach(k => delete parent[k]);
683
- Object.assign(parent, newData);
684
  } else if (parent && Array.isArray(parent)) {
685
  // For arrays, push new empty string
686
  parent.push('');
 
1
+ =======
2
  ======= Sample JSON data
3
  const sampleJSON = {
4
  "name": "John Doe",
 
489
  const currentValue = type === 'key' ? key : getValue(parentKey, key);
490
 
491
  // Handle undefined/null values gracefully
492
+ if (currentValue === undefined && type !== 'value') {
493
  return;
494
  }
495
 
 
641
  if (parentKey === 'root') {
642
  const keys = Object.keys(jsonData);
643
  const index = keys.indexOf(key);
 
644
 
645
  if (index === -1 || index === keys.length - 1) {
646
  // Append at the end
647
+ jsonData[newKey] = '';
 
648
  } else {
649
+ // Insert after current - need to reconstruct
650
+ const newData = {};
651
  keys.forEach((k, i) => {
652
  newData[k] = jsonData[k];
653
  if (i === index) {
654
  newData[newKey] = '';
655
  }
656
  });
657
+ Object.keys(jsonData).forEach(k => delete jsonData[k]);
658
+ Object.assign(jsonData, newData);
659
  }
 
 
660
  } else {
661
  const parent = findElementByKey(jsonData, parentKey);
662
  if (parent && typeof parent === 'object' && !Array.isArray(parent)) {
663
  const keys = Object.keys(parent);
664
  const index = keys.indexOf(key);
 
665
 
666
  if (index === -1 || index === keys.length - 1) {
667
  // Append at the end
668
+ parent[newKey] = '';
 
669
  } else {
670
+ // Insert after current - need to reconstruct
671
+ const newData = {};
672
  keys.forEach((k, i) => {
673
  newData[k] = parent[k];
674
  if (i === index) {
675
  newData[newKey] = '';
676
  }
677
  });
678
+ Object.keys(parent).forEach(k => delete parent[k]);
679
+ Object.assign(parent, newData);
680
  }
 
 
 
681
  } else if (parent && Array.isArray(parent)) {
682
  // For arrays, push new empty string
683
  parent.push('');