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")} value={this.getDetailField("response")}
fillHeight fillHeight
fillWidth fillWidth
maxWidth={this.getEditorMaxWidth()}
dark dark
readOnly readOnly
/> />
@ -282,6 +283,7 @@ class RecordListPage extends BaseListPage {
lang="json" lang="json"
fillHeight fillHeight
fillWidth fillWidth
maxWidth={this.getEditorMaxWidth()}
dark dark
readOnly readOnly
/> />
@ -292,6 +294,10 @@ class RecordListPage extends BaseListPage {
); );
} }
getEditorMaxWidth = () => {
return Setting.isMobile() ? window.innerWidth - 60 : 475;
};
jsonStrFormatter = str => { jsonStrFormatter = str => {
try { try {
return JSON.stringify(JSON.parse(str), null, 2); 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"; import {langs} from "@uiw/codemirror-extensions-langs";
export const Editor = (props) => { export const Editor = (props) => {
const fillHeight = props.fillHeight ? { let style = {};
height: "100%", let height = props.height;
style: {height: "100%"}, let width = props.width;
} : {}; const copy2StyleProps = [
const fillWidth = props.fillWidth ? { "width", "maxWidth", "minWidth",
width: "100%", "height", "maxHeight", "minHeight",
style: {width: "100%"}, ];
} : {}; 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 = []; let extensions = [];
switch (props.lang) { switch (props.lang) {
case "javascript": case "javascript":
@ -50,8 +69,9 @@ export const Editor = (props) => {
<CodeMirror <CodeMirror
value={props.value} value={props.value}
{...props} {...props}
{...fillHeight} width={width}
{...fillWidth} height={height}
style={style}
readOnly={props.readOnly} readOnly={props.readOnly}
theme={props.dark ? materialDark : "light"} theme={props.dark ? materialDark : "light"}
extensions={extensions} extensions={extensions}