Skip to content

[WC-2915][WC-2850] readonly resize module and fullscreen editor height and add code mirror #1524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/pluggableWidgets/rich-text-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@
"verify": "rui-verify-package-format"
},
"dependencies": {
"@codemirror/lang-html": "^6.4.9",
"@floating-ui/react": "^0.26.27",
"@melloware/coloris": "^0.24.0",
"@uiw/codemirror-theme-github": "^4.21.25",
"@uiw/react-codemirror": "^4.21.25",
"classnames": "^2.2.6",
"dompurify": "^3.2.4",
"js-beautify": "^1.15.4",
"katex": "^0.16.11",
"linkifyjs": "^4.1.3",
"lodash.merge": "^4.6.2",
Expand All @@ -68,6 +72,7 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-replace": "^6.0.2",
"@types/dompurify": "^2.4.0",
"@types/js-beautify": "^1.14.3",
"@types/katex": "^0.16.7",
"@types/sanitize-html": "^1.27.2",
"cross-env": "^7.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
...QuillTableBetter.keyboardBindings
}
},
resize: RESIZE_MODULE_CONFIG,
table: false,
"table-better": {
language: "en_US",
Expand All @@ -139,6 +138,9 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
readOnly
};

if (!readOnly && options.modules) {
options.modules.resize = RESIZE_MODULE_CONFIG;
}
const quill = new MxQuill(editorContainer, options);
ref.current = quill;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,16 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
theme={"snow"}
ref={quillRef}
defaultValue={stringAttribute.value}
style={{
height: style?.height,
minHeight: style?.minHeight,
maxHeight: style?.maxHeight,
overflowY: style?.overflowY
}}
style={
isFullscreen
? { height: "100%" }
: {
height: style?.height,
minHeight: style?.minHeight,
maxHeight: style?.maxHeight,
overflowY: style?.overflowY
}
}
toolbarId={shouldHideToolbar ? undefined : toolbarOptions ? toolbarOptions : toolbarId}
onTextChange={onTextChange}
onSelectionChange={onSelectionChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
align-items: center;
display: flex;
z-index: 105;

&.mx-underlay {
z-index: 105;
}
}

&-body {
&.modal-dialog {
z-index: 106;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useRole
} from "@floating-ui/react";
import { If } from "@mendix/widget-plugin-component-kit/If";
import { createElement, ReactElement } from "react";
import { createElement, Fragment, ReactElement } from "react";
import LinkDialog, { LinkDialogProps } from "./LinkDialog";
import VideoDialog, { VideoDialogProps } from "./VideoDialog";
import ViewCodeDialog, { ViewCodeDialogProps } from "./ViewCodeDialog";
Expand Down Expand Up @@ -71,10 +71,14 @@ export default function Dialog(props: DialogProps): ReactElement {
return (
<FloatingPortal>
{isOpen && (
<FloatingOverlay lockScroll className="widget-rich-text-modal-overlay">
<Fragment>
<FloatingOverlay
lockScroll
className="widget-rich-text-modal-overlay mx-underlay"
></FloatingOverlay>
<FloatingFocusManager context={context}>
<div
className="Dialog"
className="Dialog mx-layoutgrid"
ref={refs.setFloating}
aria-labelledby={dialogType}
aria-describedby={dialogType}
Expand All @@ -94,7 +98,7 @@ export default function Dialog(props: DialogProps): ReactElement {
</If>
</div>
</FloatingFocusManager>
</FloatingOverlay>
</Fragment>
)}
</FloatingPortal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export function DialogBody(props: PropsWithChildrenWithClass): ReactElement {
}

export interface FormControlProps extends PropsWithChildrenWithClass {
label: string;
label?: string;
}

export function FormControl(props: FormControlProps): ReactElement {
const { children, className, label } = props;

return (
<div className={classNames("form-group", className)}>
<label className="control-label col-sm-3">{label}</label>
<div className="col-sm-9"> {children}</div>
{label && <label className="control-label col-sm-3">{label}</label>}
<div className={`col-sm-${label ? "9" : "12"}`}> {children}</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
import { ChangeEvent, createElement, ReactElement, useState } from "react";
import { createElement, ReactElement, useState, useCallback } from "react";
import { type viewCodeConfigType } from "../../utils/formats";
import { DialogBody, DialogContent, DialogFooter, DialogHeader, FormControl } from "./DialogContent";
import CodeMirror, { ViewUpdate } from "@uiw/react-codemirror";
import { html } from "@codemirror/lang-html";
import { githubLight } from "@uiw/codemirror-theme-github";
import { EditorView } from "codemirror";
import beautify from "js-beautify";

export interface ViewCodeDialogProps {
currentCode?: string;
onSubmit(value: viewCodeConfigType): void;
onClose(): void;
}

const BEAUTIFY_OPTIONS: js_beautify.HTMLBeautifyOptions = {
indent_size: 4,
indent_char: " ",
max_preserve_newlines: 5,
preserve_newlines: true,
indent_scripts: "normal",
end_with_newline: false,
wrap_line_length: 0,
indent_inner_html: false,
indent_empty_lines: false
};

export default function ViewCodeDialog(props: ViewCodeDialogProps): ReactElement {
const { onSubmit, onClose, currentCode } = props;
const [formState, setFormState] = useState({
src: currentCode || ""
src: beautify.html(currentCode ?? "", BEAUTIFY_OPTIONS) || ""
});

const onInputChange = (e: ChangeEvent<HTMLTextAreaElement>): void => {
setFormState({ ...formState, [e.target.name]: e.target.value });
};
const onCodeChange = useCallback((value: string, _viewUpdate: ViewUpdate) => {
setFormState({ ...formState, src: value });
}, []);

return (
<DialogContent className="view-code-dialog">
<DialogHeader onClose={onClose}>View/Edit Code</DialogHeader>
<DialogBody>
<FormControl label="Source Code">
<textarea
name="src"
<div>
<label>Source Code</label>
</div>
<FormControl>
<CodeMirror
className="form-control mx-textarea-input mx-textarea-noresize code-input"
onChange={onInputChange}
value={formState.src}
></textarea>
extensions={[EditorView.lineWrapping, html()]}
onChange={onCodeChange}
basicSetup={true}

Check failure on line 50 in packages/pluggableWidgets/rich-text-web/src/components/ModalDialog/ViewCodeDialog.tsx

View workflow job for this annotation

GitHub Actions / Run code quality check

Value must be omitted for boolean attribute `basicSetup`
theme={githubLight}
maxHeight="70vh"
/>
</FormControl>
<DialogFooter onSubmit={() => onSubmit(formState)} onClose={onClose}></DialogFooter>
</DialogBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $rte-brand-primary: #264ae5;
}
.ql-container {
border: unset;
overflow: hidden;
}

&.fullscreen {
Expand Down
Loading
Loading