diff --git a/web/src/RecordListPage.js b/web/src/RecordListPage.js index f608128f..68998e51 100644 --- a/web/src/RecordListPage.js +++ b/web/src/RecordListPage.js @@ -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); diff --git a/web/src/common/Editor.js b/web/src/common/Editor.js index c0043bfb..a45b2a89 100644 --- a/web/src/common/Editor.js +++ b/web/src/common/Editor.js @@ -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) => {