@lobehub/editor 1.0.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/plugins/common/react/ReactPlainText.js +66 -1
- package/es/plugins/common/react/type.d.ts +31 -2
- package/es/react/Editor/Editor.js +17 -3
- package/es/react/Editor/type.d.ts +4 -6
- package/es/react/Editor/useEditor.d.ts +2 -2
- package/es/react/Editor/useEditor.js +3 -2
- package/package.json +2 -1
|
@@ -32,7 +32,15 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
32
32
|
theme = _ref$theme === void 0 ? {} : _ref$theme,
|
|
33
33
|
onChange = _ref.onChange,
|
|
34
34
|
className = _ref.className,
|
|
35
|
-
variant = _ref.variant
|
|
35
|
+
variant = _ref.variant,
|
|
36
|
+
onKeyDown = _ref.onKeyDown,
|
|
37
|
+
onFocus = _ref.onFocus,
|
|
38
|
+
onBlur = _ref.onBlur,
|
|
39
|
+
autoFocus = _ref.autoFocus,
|
|
40
|
+
onPressEnter = _ref.onPressEnter,
|
|
41
|
+
onCompositionStart = _ref.onCompositionStart,
|
|
42
|
+
onCompositionEnd = _ref.onCompositionEnd,
|
|
43
|
+
onContextMenu = _ref.onContextMenu;
|
|
36
44
|
var isChat = variant === 'chat';
|
|
37
45
|
var _theme$fontSize = theme.fontSize,
|
|
38
46
|
fontSize = _theme$fontSize === void 0 ? isChat ? 14 : 16 : _theme$fontSize,
|
|
@@ -88,11 +96,68 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
88
96
|
onChange === null || onChange === void 0 || onChange(editor);
|
|
89
97
|
});
|
|
90
98
|
}, [editor, type, content, onChange, isInitialized]);
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
if (autoFocus && editorContainerRef.current) {
|
|
101
|
+
editorContainerRef.current.focus();
|
|
102
|
+
}
|
|
103
|
+
}, [autoFocus]);
|
|
104
|
+
var handleBlur = function handleBlur(event) {
|
|
105
|
+
onBlur === null || onBlur === void 0 || onBlur({
|
|
106
|
+
editor: editor,
|
|
107
|
+
event: event
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
var handleCompositionEnd = function handleCompositionEnd(event) {
|
|
111
|
+
onCompositionEnd === null || onCompositionEnd === void 0 || onCompositionEnd({
|
|
112
|
+
editor: editor,
|
|
113
|
+
event: event
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
var handleCompositionStart = function handleCompositionStart(event) {
|
|
117
|
+
onCompositionStart === null || onCompositionStart === void 0 || onCompositionStart({
|
|
118
|
+
editor: editor,
|
|
119
|
+
event: event
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
var handleContextMenu = function handleContextMenu(event) {
|
|
123
|
+
onContextMenu === null || onContextMenu === void 0 || onContextMenu({
|
|
124
|
+
editor: editor,
|
|
125
|
+
event: event
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var handleFocus = function handleFocus(event) {
|
|
129
|
+
onFocus === null || onFocus === void 0 || onFocus({
|
|
130
|
+
editor: editor,
|
|
131
|
+
event: event
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
135
|
+
var isComposing = event.nativeEvent.isComposing;
|
|
136
|
+
if (event.key === 'Enter' && !isComposing &&
|
|
137
|
+
// Regular Enter key handling
|
|
138
|
+
onPressEnter) {
|
|
139
|
+
onPressEnter({
|
|
140
|
+
editor: editor,
|
|
141
|
+
event: event
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// Call the optional onKeyDown handler
|
|
145
|
+
onKeyDown === null || onKeyDown === void 0 || onKeyDown({
|
|
146
|
+
editor: editor,
|
|
147
|
+
event: event
|
|
148
|
+
});
|
|
149
|
+
};
|
|
91
150
|
return /*#__PURE__*/_jsxs("div", {
|
|
92
151
|
className: cx(styles.root, styles.variant, className),
|
|
93
152
|
style: style,
|
|
94
153
|
children: [/*#__PURE__*/_jsx("div", {
|
|
95
154
|
contentEditable: true,
|
|
155
|
+
onBlur: handleBlur,
|
|
156
|
+
onCompositionEnd: handleCompositionEnd,
|
|
157
|
+
onCompositionStart: handleCompositionStart,
|
|
158
|
+
onContextMenu: handleContextMenu,
|
|
159
|
+
onFocus: handleFocus,
|
|
160
|
+
onKeyDown: handleKeyDown,
|
|
96
161
|
ref: editorContainerRef,
|
|
97
162
|
style: {
|
|
98
163
|
outline: 'none'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
2
|
-
import { CommonPluginOptions } from "..";
|
|
1
|
+
import type { CSSProperties, CompositionEvent, FocusEvent, KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { CommonPluginOptions } from "..";
|
|
3
3
|
import type { IEditor } from "../../../types";
|
|
4
4
|
export interface ReactEditorContentProps {
|
|
5
5
|
content: any;
|
|
@@ -7,9 +7,38 @@ export interface ReactEditorContentProps {
|
|
|
7
7
|
type: string;
|
|
8
8
|
}
|
|
9
9
|
export interface ReactPlainTextProps {
|
|
10
|
+
autoFocus?: boolean;
|
|
10
11
|
children: ReactElement<ReactEditorContentProps>;
|
|
11
12
|
className?: string;
|
|
13
|
+
onBlur?: (props: {
|
|
14
|
+
editor: IEditor;
|
|
15
|
+
event: FocusEvent<HTMLDivElement>;
|
|
16
|
+
}) => void;
|
|
12
17
|
onChange?: (editor: IEditor) => void;
|
|
18
|
+
onCompositionEnd?: (props: {
|
|
19
|
+
editor: IEditor;
|
|
20
|
+
event: CompositionEvent<HTMLDivElement>;
|
|
21
|
+
}) => void;
|
|
22
|
+
onCompositionStart?: (props: {
|
|
23
|
+
editor: IEditor;
|
|
24
|
+
event: CompositionEvent<HTMLDivElement>;
|
|
25
|
+
}) => void;
|
|
26
|
+
onContextMenu?: (props: {
|
|
27
|
+
editor: IEditor;
|
|
28
|
+
event: MouseEvent<HTMLDivElement>;
|
|
29
|
+
}) => void;
|
|
30
|
+
onFocus?: (props: {
|
|
31
|
+
editor: IEditor;
|
|
32
|
+
event: FocusEvent<HTMLDivElement>;
|
|
33
|
+
}) => void;
|
|
34
|
+
onKeyDown?: (props: {
|
|
35
|
+
editor: IEditor;
|
|
36
|
+
event: KeyboardEvent<HTMLDivElement>;
|
|
37
|
+
}) => void;
|
|
38
|
+
onPressEnter?: (props: {
|
|
39
|
+
editor: IEditor;
|
|
40
|
+
event: KeyboardEvent<HTMLDivElement>;
|
|
41
|
+
}) => void;
|
|
13
42
|
style?: CSSProperties;
|
|
14
43
|
theme?: CommonPluginOptions['theme'] & {
|
|
15
44
|
fontSize?: number;
|
|
@@ -31,10 +31,17 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
31
31
|
_ref$mentionOption = _ref.mentionOption,
|
|
32
32
|
mentionOption = _ref$mentionOption === void 0 ? {} : _ref$mentionOption,
|
|
33
33
|
variant = _ref.variant,
|
|
34
|
-
|
|
34
|
+
onKeyDown = _ref.onKeyDown,
|
|
35
35
|
children = _ref.children,
|
|
36
36
|
_ref$type = _ref.type,
|
|
37
|
-
type = _ref$type === void 0 ? 'json' : _ref$type
|
|
37
|
+
type = _ref$type === void 0 ? 'json' : _ref$type,
|
|
38
|
+
onPressEnter = _ref.onPressEnter,
|
|
39
|
+
onFocus = _ref.onFocus,
|
|
40
|
+
onBlur = _ref.onBlur,
|
|
41
|
+
autoFocus = _ref.autoFocus,
|
|
42
|
+
onCompositionStart = _ref.onCompositionStart,
|
|
43
|
+
onCompositionEnd = _ref.onCompositionEnd,
|
|
44
|
+
onContextMenu = _ref.onContextMenu;
|
|
38
45
|
var _useEditorContent = useEditorContent(),
|
|
39
46
|
config = _useEditorContent.config;
|
|
40
47
|
var enableSlash = Boolean((slashOption === null || slashOption === void 0 ? void 0 : slashOption.items) && slashOption.items.length > 0);
|
|
@@ -74,10 +81,17 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
74
81
|
config: config,
|
|
75
82
|
editorRef: editorRef,
|
|
76
83
|
children: [memoPlugins, memoSlash, memoMention, /*#__PURE__*/_jsx(ReactPlainText, {
|
|
84
|
+
autoFocus: autoFocus,
|
|
77
85
|
className: className,
|
|
86
|
+
onBlur: onBlur,
|
|
78
87
|
onChange: onChange,
|
|
88
|
+
onCompositionEnd: onCompositionEnd,
|
|
89
|
+
onCompositionStart: onCompositionStart,
|
|
90
|
+
onContextMenu: onContextMenu,
|
|
91
|
+
onFocus: onFocus,
|
|
92
|
+
onKeyDown: onKeyDown,
|
|
93
|
+
onPressEnter: onPressEnter,
|
|
79
94
|
style: style,
|
|
80
|
-
theme: theme,
|
|
81
95
|
variant: variant,
|
|
82
96
|
children: /*#__PURE__*/_jsx(ReactEditorContent, {
|
|
83
97
|
content: content,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSSProperties, FC, ReactNode,
|
|
1
|
+
import type { CSSProperties, FC, ReactNode, RefObject } from 'react';
|
|
2
2
|
import type { ReactEditorContentProps, ReactPlainTextProps } from "../../plugins/common/react";
|
|
3
3
|
import type { ReactMentionPluginProps } from "../../plugins/mention/react";
|
|
4
4
|
import type { ReactSlashOptionProps } from "../../plugins/slash/react";
|
|
@@ -7,16 +7,14 @@ export type EditorPlugin = FC<any> | [FC<any>, Record<string, any>];
|
|
|
7
7
|
interface MentionOption extends Partial<ReactSlashOptionProps> {
|
|
8
8
|
markdownWriter?: ReactMentionPluginProps['markdownWriter'];
|
|
9
9
|
}
|
|
10
|
-
export interface EditorProps extends Partial<ReactEditorContentProps> {
|
|
10
|
+
export interface EditorProps extends Partial<ReactEditorContentProps>, Omit<ReactPlainTextProps, 'theme' | 'children'> {
|
|
11
|
+
autoFocus?: boolean;
|
|
11
12
|
children?: ReactNode;
|
|
12
13
|
className?: string;
|
|
13
|
-
editorRef?:
|
|
14
|
+
editorRef?: RefObject<IEditor | null>;
|
|
14
15
|
mentionOption?: MentionOption;
|
|
15
|
-
onChange?: (editor: IEditor) => void;
|
|
16
16
|
plugins?: EditorPlugin[];
|
|
17
17
|
slashOption?: Partial<ReactSlashOptionProps>;
|
|
18
18
|
style?: CSSProperties;
|
|
19
|
-
theme?: ReactPlainTextProps['theme'];
|
|
20
|
-
variant?: ReactPlainTextProps['variant'];
|
|
21
19
|
}
|
|
22
20
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
2
|
import type { IEditor } from "../../types";
|
|
3
|
-
export declare const useEditor: () =>
|
|
3
|
+
export declare const useEditor: (editorRef?: RefObject<IEditor | null>) => RefObject<IEditor | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"polished": "^4.3.1",
|
|
53
53
|
"react-error-boundary": "^6.0.0",
|
|
54
54
|
"react-layout-kit": "^2.0.0",
|
|
55
|
+
"react-merge-refs": "^3.0.2",
|
|
55
56
|
"shiki": "^3.9.2",
|
|
56
57
|
"use-merge-value": "^1.2.0"
|
|
57
58
|
},
|