- {formatValue(currentData)}
+
+ {formatFullValue(currentData)}
Type: {getValueType(currentData)}
diff --git a/src/components/StructuredEditor.js b/src/components/StructuredEditor.js
index c0dca7c1..74919de0 100644
--- a/src/components/StructuredEditor.js
+++ b/src/components/StructuredEditor.js
@@ -4,6 +4,7 @@ import { Plus, Minus, ChevronDown, ChevronRight, Type, Hash, ToggleLeft, List, B
const StructuredEditor = ({ onDataChange, initialData = {} }) => {
const [data, setData] = useState(initialData);
const [expandedNodes, setExpandedNodes] = useState(new Set(['root']));
+ const [fieldTypes, setFieldTypes] = useState({}); // Track intended types for fields
const isInternalUpdate = useRef(false);
// Update internal data when initialData prop changes (but not from internal updates)
@@ -14,11 +15,6 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
return;
}
- console.log('๐ฅ EXTERNAL DATA CHANGED:', {
- keys: Object.keys(initialData),
- hasData: Object.keys(initialData).length > 0,
- data: initialData
- });
setData(initialData);
// Expand root node if there's data
if (Object.keys(initialData).length > 0) {
@@ -27,7 +23,6 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
}, [initialData]);
const updateData = (newData) => {
- console.log('๐ INTERNAL DATA UPDATE:', { keys: Object.keys(newData), totalProps: JSON.stringify(newData).length });
isInternalUpdate.current = true; // Mark as internal update
setData(newData);
onDataChange(newData);
@@ -44,8 +39,6 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
};
const addProperty = (obj, path) => {
- console.log('๐ง ADD PROPERTY - Before:', { path, dataKeys: Object.keys(data), objKeys: Object.keys(obj) });
-
const pathParts = path.split('.');
const newData = { ...data };
let current = newData;
@@ -60,8 +53,6 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
const newKey = `property${keys.length + 1}`;
current[newKey] = '';
- console.log('๐ง ADD PROPERTY - After:', { path, newKey, dataKeys: Object.keys(newData), targetKeys: Object.keys(current) });
-
updateData(newData);
setExpandedNodes(new Set([...expandedNodes, path]));
};
@@ -86,8 +77,6 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
};
const removeProperty = (key, parentPath) => {
- console.log('๐๏ธ REMOVE PROPERTY:', { key, parentPath });
-
const pathParts = parentPath.split('.');
const newData = { ...data };
let current = newData;
@@ -97,6 +86,12 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
current = current[pathParts[i]];
}
+ // Remove field type tracking for the removed property
+ const removedPath = parentPath === 'root' ? `root.${key}` : `${parentPath}.${key}`;
+ const newFieldTypes = { ...fieldTypes };
+ delete newFieldTypes[removedPath];
+ setFieldTypes(newFieldTypes);
+
// Delete the property/item from the parent
if (Array.isArray(current)) {
// For arrays, remove by index and reindex
@@ -110,21 +105,12 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
if (parentPath === 'root' && Object.keys(newData).length === 0) {
// Add an empty property to maintain initial state, like TableEditor maintains at least one row
newData[''] = '';
- console.log('๐ ADDED INITIAL EMPTY PROPERTY - Last root property was deleted');
}
- console.log('๐๏ธ REMOVE PROPERTY - After:', {
- parentPath,
- remainingKeys: Array.isArray(current) ? current.length : Object.keys(current),
- totalRootKeys: Object.keys(newData).length
- });
-
updateData(newData);
};
const updateValue = (value, path) => {
- console.log('โ๏ธ UPDATE VALUE:', { path, value, currentType: typeof getValue(path) });
-
const pathParts = path.split('.');
const newData = { ...data };
let current = newData;
@@ -172,13 +158,10 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
}
}
- console.log('โ๏ธ UPDATE VALUE - Result:', { path, newValue: current[key], newType: typeof current[key] });
updateData(newData);
};
const changeType = (newType, path) => {
- console.log('๐ CHANGE TYPE:', { path, newType, currentValue: getValue(path) });
-
const pathParts = path.split('.');
const newData = { ...data };
let current = newData;
@@ -190,6 +173,11 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
const key = pathParts[pathParts.length - 1];
const currentValue = current[key];
+ // Track the intended type for this field
+ const newFieldTypes = { ...fieldTypes };
+ newFieldTypes[path] = newType;
+ setFieldTypes(newFieldTypes);
+
// Try to preserve value when changing types if possible
switch (newType) {
case 'string':
@@ -227,19 +215,10 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
current[key] = '';
}
- console.log('๐ CHANGE TYPE - Result:', { path, newValue: current[key], actualType: typeof current[key] });
updateData(newData);
setExpandedNodes(new Set([...expandedNodes, path]));
};
- const getValue = (path) => {
- const pathParts = path.split('.');
- let current = data;
- for (let i = 1; i < pathParts.length; i++) {
- current = current[pathParts[i]];
- }
- return current;
- };
// Helper function to display string values with proper unescaping
const getDisplayValue = (value) => {
@@ -277,6 +256,16 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
return; // Don't rename if key already exists
}
+ // Update field type tracking for renamed key
+ const oldPath = path;
+ const newPath = path.replace(new RegExp(`\\.${oldKey}$`), `.${newKey}`);
+ const newFieldTypes = { ...fieldTypes };
+ if (newFieldTypes[oldPath]) {
+ newFieldTypes[newPath] = newFieldTypes[oldPath];
+ delete newFieldTypes[oldPath];
+ setFieldTypes(newFieldTypes);
+ }
+
// Rename the key
const value = current[oldKey];
delete current[oldKey];
@@ -354,13 +343,19 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
const canExpand = typeof value === 'object' && value !== null;
// Check if parent is an array by looking at the parent path
- const isArrayItem = parentPath !== 'root' && (() => {
- const parentPathParts = parentPath.split('.');
- let current = data;
- for (let i = 1; i < parentPathParts.length; i++) {
- current = current[parentPathParts[i]];
+ const isArrayItem = (() => {
+ if (parentPath === 'root') {
+ // If parent is root, check if root data is an array
+ return Array.isArray(data);
+ } else {
+ // Navigate to parent and check if it's an array
+ const parentPathParts = parentPath.split('.');
+ let current = data;
+ for (let i = 1; i < parentPathParts.length; i++) {
+ current = current[parentPathParts[i]];
+ }
+ return Array.isArray(current);
}
- return Array.isArray(current);
})();
return (
@@ -436,11 +431,11 @@ const StructuredEditor = ({ onDataChange, initialData = {} }) => {
) : (
- typeof value === 'string' && value.includes('\n') ? (
+ (fieldTypes[path] === 'longtext' || (typeof value === 'string' && value.includes('\n'))) ? (