11import type { Editor as TipTapEditor } from "@tiptap/core" ;
2- // import { Color } from "@tiptap/extension-color";
3- // import { Highlight } from "@tiptap/extension-highlight";
4- // import { ListItem } from "@tiptap/extension-list-item";
52import { Link } from "@tiptap/extension-link" ;
63import { Subscript } from "@tiptap/extension-subscript" ;
74import { Superscript } from "@tiptap/extension-superscript" ;
@@ -13,17 +10,12 @@ import { TextStyle } from "@tiptap/extension-text-style";
1310import { Underline } from "@tiptap/extension-underline" ;
1411import { EditorContent , useEditor } from "@tiptap/react" ;
1512import { StarterKit } from "@tiptap/starter-kit" ;
16- import { forwardRef , ReactElement , ReactNode , useImperativeHandle } from "react" ;
13+ import { forwardRef , ReactElement , useImperativeHandle } from "react" ;
14+ import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action" ;
1715import { EditorContextProvider , useCurrentEditor } from "./EditorContext" ;
1816import { HighlightedCodeEditor } from "./HighlightedCodeEditor" ;
1917import { Toolbar } from "./toolbars" ;
20- import {
21- PresetEnum ,
22- ToolbarConfigEnum ,
23- AdvancedConfigType ,
24- CustomFontsType ,
25- RichTextContainerProps
26- } from "../../typings/RichTextProps" ;
18+ import { RichTextContainerProps } from "../../typings/RichTextProps" ;
2719import { FontFamilyClass } from "../extensions/FontFamilyClass" ;
2820import { FontSize } from "../extensions/FontSize" ;
2921import { Fullscreen } from "../extensions/Fullscreen" ;
@@ -50,6 +42,11 @@ export interface EditorProps extends Pick<
5042 | "toolbarLocation"
5143 | "advancedConfig"
5244 | "customFonts"
45+ | "onFocus"
46+ | "onBlur"
47+ | "onLoad"
48+ | "onChangeType"
49+ | "onChange"
5350> {
5451 defaultValue ?: string ;
5552 onUpdate ?: ( html : string ) => void ;
@@ -66,16 +63,14 @@ export interface EditorHandle {
6663 getEditor : ( ) => TipTapEditor | null ;
6764}
6865
69- interface EditorInnerProps {
66+ interface EditorInnerProps extends Pick <
67+ RichTextContainerProps ,
68+ "imageSourceContent" | "preset" | "toolbarConfig" | "advancedConfig" | "customFonts"
69+ > {
7070 showToolbar : boolean ;
7171 readOnly : boolean ;
7272 className ?: string ;
73- imageSourceContent ?: ReactNode ;
74- preset ?: PresetEnum ;
75- toolbarConfig ?: ToolbarConfigEnum ;
7673 toolbarGroups ?: ToolbarGroupsConfig ;
77- advancedConfig ?: AdvancedConfigType [ ] ;
78- customFonts ?: CustomFontsType [ ] ;
7974}
8075
8176function EditorInner ( {
@@ -151,13 +146,8 @@ const Editor = forwardRef<EditorHandle, EditorProps>((props, ref) => {
151146 readOnly,
152147 className,
153148 styleDataFormat = "inline" ,
154- imageSourceContent,
155- preset,
156- toolbarConfig,
157- toolbarGroups,
158149 toolbarLocation,
159- advancedConfig,
160- customFonts
150+ ...others
161151 } = props ;
162152
163153 const extensions = [
@@ -247,6 +237,18 @@ const Editor = forwardRef<EditorHandle, EditorProps>((props, ref) => {
247237 onUpdate : ( { editor } ) => {
248238 const html = editor . getHTML ( ) ;
249239 onUpdate ?.( html ) ;
240+ } ,
241+ onFocus : ( ) => {
242+ executeAction ( props . onFocus ) ;
243+ } ,
244+ onBlur : ( ) => {
245+ executeAction ( props . onBlur ) ;
246+ if ( props . onChangeType === "onLeave" ) {
247+ executeAction ( props . onChange ) ;
248+ }
249+ } ,
250+ onCreate : ( ) => {
251+ executeAction ( props . onLoad ) ;
250252 }
251253 } ) ;
252254
@@ -266,17 +268,7 @@ const Editor = forwardRef<EditorHandle, EditorProps>((props, ref) => {
266268
267269 return (
268270 < EditorContextProvider editor = { editor } >
269- < EditorInner
270- showToolbar = { ! shouldHideToolbar }
271- readOnly = { ! ! readOnly }
272- className = { className }
273- imageSourceContent = { imageSourceContent }
274- preset = { preset }
275- toolbarConfig = { toolbarConfig }
276- toolbarGroups = { toolbarGroups }
277- advancedConfig = { advancedConfig }
278- customFonts = { customFonts }
279- />
271+ < EditorInner showToolbar = { ! shouldHideToolbar } readOnly = { ! ! readOnly } className = { className } { ...others } />
280272 </ EditorContextProvider >
281273 ) ;
282274} ) ;
0 commit comments