feat: fix style props of Editor (#3590)

This commit is contained in:
WindSpiritSR 2025-02-17 13:39:49 +08:00 committed by GitHub
parent 2a5722e45b
commit aa52af02b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 10 deletions

View File

@ -272,6 +272,7 @@ class RecordListPage extends BaseListPage {
value={this.getDetailField("response")}
fillHeight
fillWidth
maxWidth={this.getEditorMaxWidth()}
dark
readOnly
/>
@ -282,6 +283,7 @@ class RecordListPage extends BaseListPage {
lang="json"
fillHeight
fillWidth
maxWidth={this.getEditorMaxWidth()}
dark
readOnly
/>
@ -292,6 +294,10 @@ class RecordListPage extends BaseListPage {
);
}
getEditorMaxWidth = () => {
return Setting.isMobile() ? window.innerWidth - 60 : 475;
};
jsonStrFormatter = str => {
try {
return JSON.stringify(JSON.parse(str), null, 2);

View File

@ -18,14 +18,33 @@ import {materialDark} from "@uiw/codemirror-theme-material";
import {langs} from "@uiw/codemirror-extensions-langs";
export const Editor = (props) => {
const fillHeight = props.fillHeight ? {
height: "100%",
style: {height: "100%"},
} : {};
const fillWidth = props.fillWidth ? {
width: "100%",
style: {width: "100%"},
} : {};
let style = {};
let height = props.height;
let width = props.width;
const copy2StyleProps = [
"width", "maxWidth", "minWidth",
"height", "maxHeight", "minHeight",
];
if (props.fillHeight) {
height = "100%";
style = {...style, height: "100%"};
}
if (props.fillWidth) {
width = "100%";
style = {...style, width: "100%"};
}
/**
* @uiw/react-codemirror style props sucha as "height" "width"
* may need to be configured with "style" in some scenarios to take effect
*/
copy2StyleProps.forEach(el => {
if (["number", "string"].includes(typeof props[el])) {
style = {...style, [el]: props[el]};
}
});
if (props.style) {
style = {...style, ...props.style};
}
let extensions = [];
switch (props.lang) {
case "javascript":
@ -50,8 +69,9 @@ export const Editor = (props) => {
<CodeMirror
value={props.value}
{...props}
{...fillHeight}
{...fillWidth}
width={width}
height={height}
style={style}
readOnly={props.readOnly}
theme={props.dark ? materialDark : "light"}
extensions={extensions}