Feat: Add a data compilation layer. (#16777)

### Summary

Feat: Add a data compilation layer.
This commit is contained in:
balibabu
2026-07-09 17:49:16 +08:00
committed by GitHub
parent 5de823eab9
commit 0083ad0deb
171 changed files with 14477 additions and 791 deletions

View File

@@ -22,6 +22,7 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
height = '400px',
className = '',
options = {},
defaultExpanded = false,
}) => {
const containerRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<any>(null);
@@ -66,6 +67,10 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
if (value) {
editorRef.current.set(value);
if (defaultExpanded) {
editorRef.current.expandAll?.();
}
}
setIsLoading(false);
@@ -138,6 +143,10 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
editorRef.current = new JSONEditor(containerRef.current, newOptions);
editorRef.current.set(currentData);
if (defaultExpanded) {
editorRef.current.expandAll?.();
}
} catch (error) {
console.error(
'Failed to reload jsoneditor with new language:',
@@ -148,7 +157,7 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
initEditorWithNewLanguage();
}
}, [i18n.language, value, onChange, options]);
}, [i18n.language, value, onChange, options, defaultExpanded]);
useEffect(() => {
if (editorRef.current && value !== undefined) {
@@ -157,14 +166,22 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
const currentJson = editorRef.current.get();
if (JSON.stringify(currentJson) !== JSON.stringify(value)) {
editorRef.current.set(value);
if (defaultExpanded) {
editorRef.current.expandAll?.();
}
}
} catch (err) {
console.error(err);
// Skip update if there is a syntax error in the current editor
editorRef.current.set(value);
if (defaultExpanded) {
editorRef.current.expandAll?.();
}
}
}
}, [value]);
}, [value, defaultExpanded]);
return (
<div

View File

@@ -336,4 +336,7 @@ export interface JsonEditorProps {
// Configuration options for the JSONEditor
options?: JsonEditorOptions;
// Whether to expand all nodes by default in tree/view/form modes
defaultExpanded?: boolean;
}