From ce18b3b9a4a7f25597830090dcac4da9b7411433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ja=C5=A1ek?= Date: Fri, 18 Aug 2023 16:28:59 +0200 Subject: [PATCH] make sure description text is plain text without html (#4309) SDCP-710 --- scripts/apps/authoring/views/article-edit.html | 1 + scripts/core/editor3/components/Editor3Component.tsx | 2 ++ scripts/core/editor3/directive.tsx | 9 +++++++++ scripts/core/editor3/reducers/editor3.tsx | 2 +- scripts/core/editor3/store/index.ts | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/apps/authoring/views/article-edit.html b/scripts/apps/authoring/views/article-edit.html index 834565a013..0bb531ea26 100644 --- a/scripts/apps/authoring/views/article-edit.html +++ b/scripts/apps/authoring/views/article-edit.html @@ -482,6 +482,7 @@ data-tabindex="editor.description_text.order" data-clean-pasted-html="editor.description_text.cleanPastedHTML" data-limit="schema.description_text.maxlength" + data-plain-text="true" > diff --git a/scripts/core/editor3/components/Editor3Component.tsx b/scripts/core/editor3/components/Editor3Component.tsx index e661e62e0a..265eac455e 100644 --- a/scripts/core/editor3/components/Editor3Component.tsx +++ b/scripts/core/editor3/components/Editor3Component.tsx @@ -119,6 +119,7 @@ interface IProps { editorState?: EditorState; scrollContainer?: string; singleLine?: boolean; + plainText?: boolean; editorFormat?: Array; tabindex?: number; suggestingMode?: boolean; @@ -690,6 +691,7 @@ export class Editor3Component extends React.Component { Editor3Component.defaultProps = { readOnly: false, singleLine: false, + plainText: false, cleanPastedHtml: false, editorFormat: [], }; diff --git a/scripts/core/editor3/directive.tsx b/scripts/core/editor3/directive.tsx index 7acd8aa5d3..2523846e2f 100644 --- a/scripts/core/editor3/directive.tsx +++ b/scripts/core/editor3/directive.tsx @@ -64,6 +64,7 @@ class Editor3Directive { readOnly: any; findReplaceTarget: any; singleLine: any; + plainText?: boolean; debounce: any; bindToValue: any; tabindex: any; @@ -202,6 +203,12 @@ class Editor3Directive { cleanPastedHtml: '=?', limit: '=?', + + /** + * @type {String} + * @description Force the output to be plain text and not contain any html. + */ + plainText: '=?', }; } @@ -227,6 +234,7 @@ class Editor3Directive { this.findReplaceTarget = typeof this.findReplaceTarget !== 'undefined'; this.singleLine = this.singleLine || false; + this.plainText = this.plainText || false; this.debounce = parseInt(this.debounce || '100', 10); this.bindToValue = this.bindToValue || false; this.tabindex = this.tabindex || 0; @@ -256,6 +264,7 @@ class Editor3Directive { singleLine={this.singleLine} cleanPastedHtml={this.cleanPastedHtml} autocompleteSuggestions={autocompleteSuggestions} + plainText={this.plainText} /> , diff --git a/scripts/core/editor3/reducers/editor3.tsx b/scripts/core/editor3/reducers/editor3.tsx index b75f60c63a..8cc3f33b64 100644 --- a/scripts/core/editor3/reducers/editor3.tsx +++ b/scripts/core/editor3/reducers/editor3.tsx @@ -160,7 +160,7 @@ export const onChange = ( const contentChanged = state.editorState.getCurrentContent() !== editorStateNext.getCurrentContent(); if (!skipOnChange && (contentChanged || force)) { - const plainText = state.singleLine === true; + const plainText = state.plainText === true || state.singleLine === true; state.onChangeValue(editorStateNext.getCurrentContent(), {plainText}); } diff --git a/scripts/core/editor3/store/index.ts b/scripts/core/editor3/store/index.ts index 0586c0aedb..33b106f30f 100644 --- a/scripts/core/editor3/store/index.ts +++ b/scripts/core/editor3/store/index.ts @@ -55,6 +55,7 @@ interface IProps { onChange?: any; readOnly?: any; singleLine?: any; + plainText?: any; tabindex?: any; showTitle?: any; editorFormat?: Array; @@ -74,6 +75,7 @@ export interface IEditorStore { locked: boolean; showToolbar: any; singleLine: any; + plainText: boolean; tabindex: any; showTitle: any; activeCell?: IActiveCell; @@ -167,6 +169,7 @@ export default function createEditorStore( locked: false, // when true, main editor is disabled (ie. when editing sub-components like tables or images) showToolbar: (props.editorFormat || []).length > 0, singleLine: props.singleLine, + plainText: props.plainText, tabindex: props.tabindex, showTitle: props.showTitle, activeCell: null, // currently focused table cell