Spaces:
Running
Running
🐳 10/02 - 14:24 - 1. Can you please change :Edit JSON with intuitive visual editing and keyboard navigation" to "The way JSON should ALWAYS (italics) been editored!"2. Problem with dragon drop: it no
Browse files- index.html +1 -1
- script.js +38 -4
index.html
CHANGED
|
@@ -26,7 +26,7 @@
|
|
| 26 |
<div class="max-w-7xl mx-auto">
|
| 27 |
<header class="mb-8 text-center">
|
| 28 |
<h1 class="text-3xl md:text-4xl font-bold text-slate-100 mb-2">Visual JSON Editor</h1>
|
| 29 |
-
<p class="text-slate-300">
|
| 30 |
</header>
|
| 31 |
|
| 32 |
<!-- Menu Bar -->
|
|
|
|
| 26 |
<div class="max-w-7xl mx-auto">
|
| 27 |
<header class="mb-8 text-center">
|
| 28 |
<h1 class="text-3xl md:text-4xl font-bold text-slate-100 mb-2">Visual JSON Editor</h1>
|
| 29 |
+
<p class="text-slate-300">The way JSON should <i class="italic font-semibold">ALWAYS</i> been edited!</p>
|
| 30 |
</header>
|
| 31 |
|
| 32 |
<!-- Menu Bar -->
|
script.js
CHANGED
|
@@ -1025,11 +1025,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 1025 |
return;
|
| 1026 |
}
|
| 1027 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
// Get the value being moved BEFORE removing
|
| 1029 |
const draggedParent = findElementByKey(jsonData, draggedParentKey);
|
| 1030 |
let movedValue = null;
|
| 1031 |
|
| 1032 |
-
if (draggedParent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1033 |
if (Array.isArray(draggedParent)) {
|
| 1034 |
const index = parseInt(draggedKey);
|
| 1035 |
if (!isNaN(index) && index >= 0 && index < draggedParent.length) {
|
|
@@ -1072,13 +1086,33 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 1072 |
}
|
| 1073 |
|
| 1074 |
// Get the new parent object
|
| 1075 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1076 |
|
| 1077 |
-
if (!newParent
|
| 1078 |
-
showNotification('Cannot move here -
|
| 1079 |
return;
|
| 1080 |
}
|
| 1081 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1082 |
// Remove from original location
|
| 1083 |
if (draggedParent === 'root') {
|
| 1084 |
if (Array.isArray(jsonData)) {
|
|
|
|
| 1025 |
return;
|
| 1026 |
}
|
| 1027 |
|
| 1028 |
+
// Don't allow dropping on closing brackets
|
| 1029 |
+
if (dropKey === 'closing') {
|
| 1030 |
+
return;
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
// Get the value being moved BEFORE removing
|
| 1034 |
const draggedParent = findElementByKey(jsonData, draggedParentKey);
|
| 1035 |
let movedValue = null;
|
| 1036 |
|
| 1037 |
+
if (draggedParent === 'root') {
|
| 1038 |
+
if (Array.isArray(jsonData)) {
|
| 1039 |
+
const index = parseInt(draggedKey);
|
| 1040 |
+
if (!isNaN(index) && index >= 0 && index < jsonData.length) {
|
| 1041 |
+
movedValue = jsonData[index];
|
| 1042 |
+
}
|
| 1043 |
+
} else {
|
| 1044 |
+
movedValue = jsonData[draggedKey];
|
| 1045 |
+
}
|
| 1046 |
+
} else if (draggedParent && typeof draggedParent === 'object') {
|
| 1047 |
if (Array.isArray(draggedParent)) {
|
| 1048 |
const index = parseInt(draggedKey);
|
| 1049 |
if (!isNaN(index) && index >= 0 && index < draggedParent.length) {
|
|
|
|
| 1086 |
}
|
| 1087 |
|
| 1088 |
// Get the new parent object
|
| 1089 |
+
let newParent = null;
|
| 1090 |
+
if (newParentKey === 'root') {
|
| 1091 |
+
newParent = jsonData;
|
| 1092 |
+
} else {
|
| 1093 |
+
newParent = findElementByKey(jsonData, newParentKey);
|
| 1094 |
+
}
|
| 1095 |
|
| 1096 |
+
if (!newParent) {
|
| 1097 |
+
showNotification('Cannot move here - parent not found', true);
|
| 1098 |
return;
|
| 1099 |
}
|
| 1100 |
|
| 1101 |
+
// If parent is a primitive, we can't insert inside - move to parent's parent
|
| 1102 |
+
if (typeof newParent !== 'object' || newParent === null) {
|
| 1103 |
+
// Try to find the parent's parent
|
| 1104 |
+
const grandParent = findElementByKey(jsonData, dropParentKey);
|
| 1105 |
+
if (grandParent && typeof grandParent === 'object') {
|
| 1106 |
+
newParent = grandParent;
|
| 1107 |
+
newParentKey = dropParentKey;
|
| 1108 |
+
insertPosition = 'after';
|
| 1109 |
+
insertKey = dropKey;
|
| 1110 |
+
} else {
|
| 1111 |
+
showNotification('Cannot move here - invalid parent type', true);
|
| 1112 |
+
return;
|
| 1113 |
+
}
|
| 1114 |
+
}
|
| 1115 |
+
|
| 1116 |
// Remove from original location
|
| 1117 |
if (draggedParent === 'root') {
|
| 1118 |
if (Array.isArray(jsonData)) {
|