diff --git a/packages/pluggableWidgets/rich-text-web/CHANGELOG.md b/packages/pluggableWidgets/rich-text-web/CHANGELOG.md index 4289f15ca5..38deab1766 100644 --- a/packages/pluggableWidgets/rich-text-web/CHANGELOG.md +++ b/packages/pluggableWidgets/rich-text-web/CHANGELOG.md @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- We added new configuration to allow users to use class names instead of inline styling in generated HTML to support strict CSP. + +### Fixed + +- We fixed an issue where the editor pasting back the whole sentence instead of the single copied word + +### Changed + +- We removed codemirror from code dialog viewer due to unsupported strict CSP policy. A simple internally built code editor using highlightjs is now replacing it. + ## [4.12.0] - 2026-04-22 ### Added diff --git a/packages/pluggableWidgets/rich-text-web/e2e/RichText.spec.js-snapshots/viewCodeDialog-chromium-linux.png b/packages/pluggableWidgets/rich-text-web/e2e/RichText.spec.js-snapshots/viewCodeDialog-chromium-linux.png index b4ca13e1a7..1d733a5a99 100644 Binary files a/packages/pluggableWidgets/rich-text-web/e2e/RichText.spec.js-snapshots/viewCodeDialog-chromium-linux.png and b/packages/pluggableWidgets/rich-text-web/e2e/RichText.spec.js-snapshots/viewCodeDialog-chromium-linux.png differ diff --git a/packages/pluggableWidgets/rich-text-web/package.json b/packages/pluggableWidgets/rich-text-web/package.json index 5fb882b303..cf816f5a2f 100644 --- a/packages/pluggableWidgets/rich-text-web/package.json +++ b/packages/pluggableWidgets/rich-text-web/package.json @@ -43,21 +43,19 @@ "verify": "rui-verify-package-format" }, "dependencies": { - "@codemirror/lang-html": "^6.4.9", - "@codemirror/state": "^6.5.2", "@floating-ui/dom": "^1.7.4", "@floating-ui/react": "^0.26.27", "@melloware/coloris": "^0.25.0", - "@uiw/codemirror-theme-github": "^4.23.13", - "@uiw/react-codemirror": "^4.23.13", "classnames": "^2.5.1", + "highlight.js": "^11.11.1", "js-beautify": "^1.15.4", "katex": "^0.16.22", "linkifyjs": "^4.3.2", "lodash.merge": "^4.6.2", "parchment": "^3.0.0", "quill": "^2.0.3", - "quill-resize-module": "^2.0.4" + "quill-resize-module": "^2.0.4", + "react-scroll-sync": "^1.0.2" }, "devDependencies": { "@mendix/automation-utils": "workspace:*", diff --git a/packages/pluggableWidgets/rich-text-web/src/RichText.xml b/packages/pluggableWidgets/rich-text-web/src/RichText.xml index 8fb841b775..0ce72a407b 100644 --- a/packages/pluggableWidgets/rich-text-web/src/RichText.xml +++ b/packages/pluggableWidgets/rich-text-web/src/RichText.xml @@ -220,6 +220,14 @@ Character count (including HTML) + + Style data format + Choose how to render styling attribute in HTML + + inline + class + + diff --git a/packages/pluggableWidgets/rich-text-web/src/__tests__/RichText.spec.tsx b/packages/pluggableWidgets/rich-text-web/src/__tests__/RichText.spec.tsx index 1ab4c89bad..870d49894d 100644 --- a/packages/pluggableWidgets/rich-text-web/src/__tests__/RichText.spec.tsx +++ b/packages/pluggableWidgets/rich-text-web/src/__tests__/RichText.spec.tsx @@ -47,7 +47,8 @@ describe("Rich Text", () => { customFonts: [], enableDefaultUpload: true, formOrientation: "vertical", - linkValidation: true + linkValidation: true, + styleDataFormat: "inline" }; }); diff --git a/packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx b/packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx index a13fdd1730..47af2073e8 100644 --- a/packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx +++ b/packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx @@ -13,14 +13,15 @@ import { import { RichTextContainerProps } from "../../typings/RichTextProps"; import { EditorDispatchContext } from "../store/EditorProvider"; import { SET_FULLSCREEN_ACTION } from "../store/store"; -import "../utils/customPluginRegisters"; +import { registerCustomFormats } from "../utils/customPluginRegisters"; import "../utils/formats/quill-table-better/assets/css/quill-table-better.scss"; +import { MxQuillModulesOptions } from "../utils/formats"; import { getResizeModuleConfig } from "../utils/formats/resizeModuleConfig"; import { ACTION_DISPATCHER } from "../utils/helpers"; import { getKeyboardBindings } from "../utils/modules/keyboard"; import { getIndentHandler } from "../utils/modules/toolbarHandlers"; import MxUploader from "../utils/modules/uploader"; -import MxQuill, { MxQuillModulesOptions } from "../utils/MxQuill"; +import MxQuill from "../utils/MxQuill"; import { useEmbedModal } from "./CustomToolbars/useEmbedModal"; import Dialog from "./ModalDialog/Dialog"; @@ -68,7 +69,7 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject { @@ -133,7 +134,8 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject(null); const [formState, setFormState] = useState({ // temporarily change tab characters to em space to avoid beautify removing them src: beautify.html(currentCode?.replace(/\t/g, " ") ?? "", BEAUTIFY_OPTIONS)?.replace(/ /g, "\t") || "" }); - const onCodeChange = useCallback((value: string, _viewUpdate: ViewUpdate) => { - setFormState({ ...formState, src: value }); - }, []); + + useEffect(() => { + const codeElement = codeRef.current; + hljs.highlightAll(); + return () => { + if (codeElement) { + delete codeElement.dataset.highlighted; + } + }; + }, [formState]); + const onCodeChange = useCallback( + (value: string) => { + setFormState({ ...formState, src: value }); + }, + [formState] + ); return ( @@ -45,15 +58,35 @@ export default function ViewCodeDialog(props: ViewCodeDialogProps): ReactElement - + +
+ +