Spaces:
Running
Running
🐳 10/02 - 14:48 - can;t load anything buttons and menu bar broken and can;t activate any entry on the left panel
Browse files- index.html +0 -1
- script.js +24 -15
index.html
CHANGED
|
@@ -147,7 +147,6 @@
|
|
| 147 |
</div>
|
| 148 |
</div>
|
| 149 |
</div>
|
| 150 |
-
>
|
| 151 |
</div>
|
| 152 |
|
| 153 |
<div id="notification" class="notification fixed bottom-4 right-4 bg-white shadow-lg rounded-lg p-4 border-l-4 border-green-500 max-w-md z-50">
|
|
|
|
| 147 |
</div>
|
| 148 |
</div>
|
| 149 |
</div>
|
|
|
|
| 150 |
</div>
|
| 151 |
|
| 152 |
<div id="notification" class="notification fixed bottom-4 right-4 bg-white shadow-lg rounded-lg p-4 border-l-4 border-green-500 max-w-md z-50">
|
script.js
CHANGED
|
@@ -254,13 +254,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 254 |
|
| 255 |
// Load JSON data into the editor
|
| 256 |
function loadJSON(data) {
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
jsonData = {};
|
|
|
|
|
|
|
| 261 |
}
|
| 262 |
-
renderEditor();
|
| 263 |
-
updateOutput();
|
| 264 |
}
|
| 265 |
|
| 266 |
// Render the JSON editor
|
|
@@ -542,11 +549,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 542 |
|
| 543 |
// Make an element editable
|
| 544 |
function makeEditable(span, type, key, parentKey) {
|
| 545 |
-
|
| 546 |
|
| 547 |
-
// Handle undefined/null values gracefully
|
| 548 |
-
if (currentValue === undefined
|
| 549 |
-
|
| 550 |
}
|
| 551 |
|
| 552 |
let displayValue = type === 'key' ? currentValue : JSON.stringify(currentValue);
|
|
@@ -1163,18 +1170,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 1163 |
contextMenu.style.display = 'none';
|
| 1164 |
});
|
| 1165 |
|
| 1166 |
-
// Click on empty space between items to insert line
|
| 1167 |
jsonEditor.addEventListener('click', (e) => {
|
| 1168 |
// Only if clicking directly on json-editor (not on an item)
|
| 1169 |
if (e.target === jsonEditor) {
|
| 1170 |
-
// Check if editor is
|
| 1171 |
const isEmpty = jsonEditor.innerHTML.trim() === '' ||
|
| 1172 |
-
|
| 1173 |
-
|
|
|
|
| 1174 |
|
| 1175 |
-
if (isEmpty) {
|
| 1176 |
-
// Initialize new JSON structure
|
| 1177 |
jsonData = {};
|
|
|
|
| 1178 |
insertNewField({ key: null, parentKey: 'root' });
|
| 1179 |
} else {
|
| 1180 |
// Insert at root level
|
|
|
|
| 254 |
|
| 255 |
// Load JSON data into the editor
|
| 256 |
function loadJSON(data) {
|
| 257 |
+
try {
|
| 258 |
+
jsonData = data ? JSON.parse(JSON.stringify(data)) : {};
|
| 259 |
+
// Initialize empty object if data is null/undefined
|
| 260 |
+
if (!jsonData || typeof jsonData !== 'object') {
|
| 261 |
+
jsonData = {};
|
| 262 |
+
}
|
| 263 |
+
renderEditor();
|
| 264 |
+
updateOutput();
|
| 265 |
+
} catch (e) {
|
| 266 |
+
console.error('Error loading JSON:', e);
|
| 267 |
jsonData = {};
|
| 268 |
+
renderEditor();
|
| 269 |
+
updateOutput();
|
| 270 |
}
|
|
|
|
|
|
|
| 271 |
}
|
| 272 |
|
| 273 |
// Render the JSON editor
|
|
|
|
| 549 |
|
| 550 |
// Make an element editable
|
| 551 |
function makeEditable(span, type, key, parentKey) {
|
| 552 |
+
let currentValue = type === 'key' ? key : getValue(parentKey, key);
|
| 553 |
|
| 554 |
+
// Handle undefined/null values gracefully - allow editing even if undefined
|
| 555 |
+
if (currentValue === undefined) {
|
| 556 |
+
currentValue = '';
|
| 557 |
}
|
| 558 |
|
| 559 |
let displayValue = type === 'key' ? currentValue : JSON.stringify(currentValue);
|
|
|
|
| 1170 |
contextMenu.style.display = 'none';
|
| 1171 |
});
|
| 1172 |
|
| 1173 |
+
// Click on empty space between items to insert line or start new JSON
|
| 1174 |
jsonEditor.addEventListener('click', (e) => {
|
| 1175 |
// Only if clicking directly on json-editor (not on an item)
|
| 1176 |
if (e.target === jsonEditor) {
|
| 1177 |
+
// Check if editor is effectively empty
|
| 1178 |
const isEmpty = jsonEditor.innerHTML.trim() === '' ||
|
| 1179 |
+
jsonEditor.querySelectorAll('.json-item').length === 0 ||
|
| 1180 |
+
(jsonEditor.querySelectorAll('.json-item').length === 1 &&
|
| 1181 |
+
jsonEditor.querySelector('.json-item')?.dataset.key === 'closing');
|
| 1182 |
|
| 1183 |
+
if (isEmpty || Object.keys(jsonData).length === 0) {
|
| 1184 |
+
// Initialize new JSON structure with empty object
|
| 1185 |
jsonData = {};
|
| 1186 |
+
// Create a new field and focus it immediately
|
| 1187 |
insertNewField({ key: null, parentKey: 'root' });
|
| 1188 |
} else {
|
| 1189 |
// Insert at root level
|