Skip to content

Commit 96df6fb

Browse files
committed
chore: update events
1 parent 0b63e3a commit 96df6fb

3 files changed

Lines changed: 58 additions & 37 deletions

File tree

packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import 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";
52
import { Link } from "@tiptap/extension-link";
63
import { Subscript } from "@tiptap/extension-subscript";
74
import { Superscript } from "@tiptap/extension-superscript";
@@ -13,17 +10,12 @@ import { TextStyle } from "@tiptap/extension-text-style";
1310
import { Underline } from "@tiptap/extension-underline";
1411
import { EditorContent, useEditor } from "@tiptap/react";
1512
import { 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";
1715
import { EditorContextProvider, useCurrentEditor } from "./EditorContext";
1816
import { HighlightedCodeEditor } from "./HighlightedCodeEditor";
1917
import { 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";
2719
import { FontFamilyClass } from "../extensions/FontFamilyClass";
2820
import { FontSize } from "../extensions/FontSize";
2921
import { 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

8176
function 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
});

packages/pluggableWidgets/rich-text-web/src/components/EditorWrapper.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactElement, useRef, useState, useEffect } from "react";
22
import { RichTextContainerProps } from "typings/RichTextProps";
33
import { useDebounceWithStatus } from "@mendix/widget-plugin-hooks/useDebounceWithStatus";
4+
import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action";
45
import Editor, { EditorHandle } from "./Editor";
56
import { StatusBar, StatusBarMetricType } from "./StatusBar";
67

@@ -34,7 +35,12 @@ function EditorWrapper(props: EditorWrapperProps): ReactElement {
3435
statusBarContent,
3536
customFonts,
3637
toolbarLocation,
37-
readOnlyStyle
38+
readOnlyStyle,
39+
onFocus,
40+
onBlur,
41+
onLoad,
42+
onChangeType,
43+
onChange
3844
} = props;
3945
const editorRef = useRef<EditorHandle>(null);
4046
const [editorText, setEditorText] = useState<string>("");
@@ -43,6 +49,10 @@ function EditorWrapper(props: EditorWrapperProps): ReactElement {
4349
(html?: string) => {
4450
if (stringAttribute.value !== html) {
4551
stringAttribute.setValue(html);
52+
53+
if (onChangeType === "onDataChange") {
54+
executeAction(onChange);
55+
}
4656
}
4757
},
4858
200,
@@ -79,13 +89,12 @@ function EditorWrapper(props: EditorWrapperProps): ReactElement {
7989
})();
8090

8191
return (
82-
<div className={`${className} toolbar-${toolbarLocation}`}>
92+
<div className={`${className} toolbar-${toolbarLocation} testing-editor-wrapper`}>
8393
{stringAttribute.status === "available" && (
8494
<>
8595
<Editor
8696
ref={editorRef}
8797
defaultValue={stringAttribute.value}
88-
onUpdate={handleUpdate}
8998
readOnly={stringAttribute.readOnly}
9099
className="tiptap-editor"
91100
styleDataFormat={styleDataFormat}
@@ -112,6 +121,12 @@ function EditorWrapper(props: EditorWrapperProps): ReactElement {
112121
toolbarLocation={
113122
stringAttribute.readOnly && readOnlyStyle !== "text" ? "hide" : toolbarLocation
114123
}
124+
onUpdate={handleUpdate}
125+
onFocus={onFocus}
126+
onBlur={onBlur}
127+
onLoad={onLoad}
128+
onChange={onChange}
129+
onChangeType={onChangeType}
115130
/>
116131
{enableStatusBar && (
117132
<StatusBar

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)