mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
feat: improve code editor
This commit is contained in:
parent
5006644732
commit
f4a92e4959
@ -225,6 +225,7 @@ interface CodeEditorProps {
|
|||||||
onChange?: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
height?: string | number;
|
height?: string | number;
|
||||||
|
minHeight?: string | number;
|
||||||
theme?: 'light' | 'dark';
|
theme?: 'light' | 'dark';
|
||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
enableLinter?: boolean;
|
enableLinter?: boolean;
|
||||||
@ -235,6 +236,7 @@ const CodeEditorComponent: React.FC<CodeEditorProps> = ({
|
|||||||
onChange,
|
onChange,
|
||||||
placeholder = '',
|
placeholder = '',
|
||||||
height = '300px',
|
height = '300px',
|
||||||
|
minHeight,
|
||||||
theme = 'light',
|
theme = 'light',
|
||||||
readonly = false,
|
readonly = false,
|
||||||
enableLinter = false,
|
enableLinter = false,
|
||||||
@ -263,7 +265,14 @@ const CodeEditorComponent: React.FC<CodeEditorProps> = ({
|
|||||||
}),
|
}),
|
||||||
EditorView.theme({
|
EditorView.theme({
|
||||||
'&': {
|
'&': {
|
||||||
height: typeof height === 'string' ? height : `${height}px`,
|
// 如果设置了 minHeight,则使用 minHeight,否则使用 height
|
||||||
|
...(minHeight
|
||||||
|
? {
|
||||||
|
minHeight: typeof minHeight === 'string' ? minHeight : `${minHeight}px`,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
height: typeof height === 'string' ? height : `${height}px`,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
'.cm-editor': {
|
'.cm-editor': {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
@ -354,7 +363,7 @@ const CodeEditorComponent: React.FC<CodeEditorProps> = ({
|
|||||||
view.destroy();
|
view.destroy();
|
||||||
viewRef.current = null;
|
viewRef.current = null;
|
||||||
};
|
};
|
||||||
}, [theme, height, placeholder, readonly, enableLinter]);
|
}, [theme, height, minHeight, placeholder, readonly, enableLinter]);
|
||||||
|
|
||||||
// Update editor content when value prop changes
|
// Update editor content when value prop changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -407,6 +416,7 @@ export const CodeEditor = connect(
|
|||||||
onChange: props.onChange,
|
onChange: props.onChange,
|
||||||
placeholder: props.placeholder,
|
placeholder: props.placeholder,
|
||||||
height: props.height,
|
height: props.height,
|
||||||
|
minHeight: props.minHeight,
|
||||||
theme: props.theme,
|
theme: props.theme,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user