@@ -2,12 +2,13 @@ import { If } from "@mendix/widget-plugin-component-kit/If";
22import { useDebounceWithStatus } from "@mendix/widget-plugin-hooks/useDebounceWithStatus" ;
33import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action" ;
44import classNames from "classnames" ;
5- import Quill , { Range } from "quill" ;
5+ import Quill from "quill" ;
66import "quill/dist/quill.core.css" ;
77import "quill/dist/quill.snow.css" ;
88import { CSSProperties , ReactElement , useCallback , useContext , useEffect , useRef , useState } from "react" ;
99import { RichTextContainerProps } from "typings/RichTextProps" ;
1010import { EditorContext , EditorProvider } from "../store/EditorProvider" ;
11+ import { useActionEvents } from "../store/useActionEvents" ;
1112import { updateLegacyQuillFormats } from "../utils/helpers" ;
1213import MendixTheme from "../utils/themes/mxTheme" ;
1314import { createPreset } from "./CustomToolbars/presets" ;
@@ -50,11 +51,9 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
5051 } = props ;
5152
5253 const globalState = useContext ( EditorContext ) ;
53-
5454 const isFirstLoad = useRef < boolean > ( false ) ;
5555 const quillRef = useRef < Quill > ( null ) ;
56- const [ isFocus , setIsFocus ] = useState ( false ) ;
57- const editorValueRef = useRef < string > ( "" ) ;
56+ const actionEvents = useActionEvents ( { onBlur, onFocus, onChange, onChangeType, quill : quillRef ?. current } ) ;
5857 const toolbarRef = useRef < HTMLDivElement > ( null ) ;
5958 const [ wordCount , setWordCount ] = useState ( 0 ) ;
6059
@@ -128,34 +127,6 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
128127 // eslint-disable-next-line react-hooks/exhaustive-deps
129128 } , [ quillRef . current , stringAttribute , calculateCounts , onChange ?. isExecuting ] ) ;
130129
131- const onSelectionChange = useCallback (
132- ( range : Range ) => {
133- if ( range ) {
134- // User cursor is selecting
135- if ( ! isFocus ) {
136- setIsFocus ( true ) ;
137- executeAction ( onFocus ) ;
138- editorValueRef . current = quillRef . current ?. getText ( ) || "" ;
139- }
140- } else {
141- // Cursor not in the editor
142- if ( isFocus ) {
143- setIsFocus ( false ) ;
144- executeAction ( onBlur ) ;
145-
146- if ( onChangeType === "onLeave" ) {
147- if ( editorValueRef . current !== quillRef . current ?. getText ( ) ) {
148- executeAction ( onChange ) ;
149- }
150- }
151- }
152- }
153- ( quillRef . current ?. theme as MendixTheme ) . updatePicker ( range ) ;
154- } ,
155-
156- [ isFocus , onFocus , onBlur , onChange , onChangeType ]
157- ) ;
158-
159130 const toolbarId = `widget_${ id . replaceAll ( "." , "_" ) } _toolbar` ;
160131 const shouldHideToolbar = ( stringAttribute . readOnly && readOnlyStyle !== "text" ) || toolbarLocation === "hide" ;
161132 const toolbarPreset = shouldHideToolbar ? [ ] : createPreset ( props ) ;
@@ -183,6 +154,7 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
183154 } }
184155 spellCheck = { props . spellCheck }
185156 tabIndex = { tabIndex }
157+ { ...actionEvents }
186158 >
187159 < If condition = { toolbarLocation === "auto" } >
188160 < StickySentinel />
@@ -220,7 +192,7 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
220192 }
221193 toolbarId = { shouldHideToolbar ? undefined : toolbarOptions ? toolbarOptions : toolbarId }
222194 onTextChange = { onTextChange }
223- onSelectionChange = { onSelectionChange }
195+ // onSelectionChange={onSelectionChange}
224196 className = { "widget-rich-text-container" }
225197 readOnly = { stringAttribute . readOnly }
226198 key = { `${ toolbarId } _${ stringAttribute . readOnly } ` }
0 commit comments