@lobehub/editor 1.1.0 → 1.2.1
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/editor-kernel/react/react-editor.js +2 -2
- package/es/plugins/common/react/ReactPlainText.js +53 -6
- package/es/plugins/common/react/type.d.ts +30 -8
- package/es/react/Editor/Editor.js +3 -31
- package/es/react/Editor/type.d.ts +3 -13
- package/es/react/Editor/useEditor.d.ts +2 -2
- package/es/react/Editor/useEditor.js +3 -2
- package/package.json +1 -1
|
@@ -39,15 +39,15 @@ export var ReactEditor = function ReactEditor(_ref2) {
|
|
|
39
39
|
config = _ref2.config;
|
|
40
40
|
var composerContext = useMemo(function () {
|
|
41
41
|
var editor = Editor.createEditor();
|
|
42
|
-
updateRef(editorRef, editor);
|
|
43
42
|
var theme = createLexicalComposerContext(null, null);
|
|
44
43
|
return [editor, theme];
|
|
45
44
|
}, []);
|
|
46
45
|
useEffect(function () {
|
|
46
|
+
updateRef(editorRef, composerContext[0]);
|
|
47
47
|
return function () {
|
|
48
48
|
updateRef(editorRef, undefined);
|
|
49
49
|
};
|
|
50
|
-
}, [editorRef]);
|
|
50
|
+
}, [editorRef, composerContext]);
|
|
51
51
|
return /*#__PURE__*/_jsxs(LexicalComposerContext, {
|
|
52
52
|
value: composerContext,
|
|
53
53
|
children: [/*#__PURE__*/_jsx(ConfigInjector, {
|
|
@@ -37,6 +37,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
37
37
|
onFocus = _ref.onFocus,
|
|
38
38
|
onBlur = _ref.onBlur,
|
|
39
39
|
autoFocus = _ref.autoFocus,
|
|
40
|
+
onPressEnter = _ref.onPressEnter,
|
|
40
41
|
onCompositionStart = _ref.onCompositionStart,
|
|
41
42
|
onCompositionEnd = _ref.onCompositionEnd,
|
|
42
43
|
onContextMenu = _ref.onContextMenu;
|
|
@@ -100,17 +101,63 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
100
101
|
editorContainerRef.current.focus();
|
|
101
102
|
}
|
|
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
|
+
};
|
|
103
150
|
return /*#__PURE__*/_jsxs("div", {
|
|
104
151
|
className: cx(styles.root, styles.variant, className),
|
|
105
152
|
style: style,
|
|
106
153
|
children: [/*#__PURE__*/_jsx("div", {
|
|
107
154
|
contentEditable: true,
|
|
108
|
-
onBlur:
|
|
109
|
-
onCompositionEnd:
|
|
110
|
-
onCompositionStart:
|
|
111
|
-
onContextMenu:
|
|
112
|
-
onFocus:
|
|
113
|
-
onKeyDown:
|
|
155
|
+
onBlur: handleBlur,
|
|
156
|
+
onCompositionEnd: handleCompositionEnd,
|
|
157
|
+
onCompositionStart: handleCompositionStart,
|
|
158
|
+
onContextMenu: handleContextMenu,
|
|
159
|
+
onFocus: handleFocus,
|
|
160
|
+
onKeyDown: handleKeyDown,
|
|
114
161
|
ref: editorContainerRef,
|
|
115
162
|
style: {
|
|
116
163
|
outline: 'none'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CSSProperties,
|
|
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;
|
|
@@ -10,13 +10,35 @@ export interface ReactPlainTextProps {
|
|
|
10
10
|
autoFocus?: boolean;
|
|
11
11
|
children: ReactElement<ReactEditorContentProps>;
|
|
12
12
|
className?: string;
|
|
13
|
-
onBlur?:
|
|
13
|
+
onBlur?: (props: {
|
|
14
|
+
editor: IEditor;
|
|
15
|
+
event: FocusEvent<HTMLDivElement>;
|
|
16
|
+
}) => void;
|
|
14
17
|
onChange?: (editor: IEditor) => void;
|
|
15
|
-
onCompositionEnd?:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
20
42
|
style?: CSSProperties;
|
|
21
43
|
theme?: CommonPluginOptions['theme'] & {
|
|
22
44
|
fontSize?: number;
|
|
@@ -9,16 +9,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
9
9
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
10
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
11
11
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
-
import { isModifierMatch } from 'lexical';
|
|
13
12
|
import { createElement, memo, useMemo } from 'react';
|
|
14
|
-
import { mergeRefs } from 'react-merge-refs';
|
|
15
|
-
import { CONTROL_OR_META } from "../../common/sys";
|
|
16
13
|
import { ReactEditor } from "../../editor-kernel/react/react-editor";
|
|
17
14
|
import { ReactEditorContent, ReactPlainText } from "../../plugins/common";
|
|
18
15
|
import { ReactMentionPlugin } from "../../plugins/mention";
|
|
19
16
|
import { ReactSlashOption, ReactSlashPlugin } from "../../plugins/slash";
|
|
20
17
|
import { useEditorContent } from "../EditorProvider";
|
|
21
|
-
import { useEditor } from "./useEditor";
|
|
22
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
20
|
var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
@@ -36,7 +32,6 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
36
32
|
mentionOption = _ref$mentionOption === void 0 ? {} : _ref$mentionOption,
|
|
37
33
|
variant = _ref.variant,
|
|
38
34
|
onKeyDown = _ref.onKeyDown,
|
|
39
|
-
theme = _ref.theme,
|
|
40
35
|
children = _ref.children,
|
|
41
36
|
_ref$type = _ref.type,
|
|
42
37
|
type = _ref$type === void 0 ? 'json' : _ref$type,
|
|
@@ -47,7 +42,6 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
47
42
|
onCompositionStart = _ref.onCompositionStart,
|
|
48
43
|
onCompositionEnd = _ref.onCompositionEnd,
|
|
49
44
|
onContextMenu = _ref.onContextMenu;
|
|
50
|
-
var ref = useEditor();
|
|
51
45
|
var _useEditorContent = useEditorContent(),
|
|
52
46
|
config = _useEditorContent.config;
|
|
53
47
|
var enableSlash = Boolean((slashOption === null || slashOption === void 0 ? void 0 : slashOption.items) && slashOption.items.length > 0);
|
|
@@ -83,31 +77,9 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
83
77
|
}, restMentionOption)) : undefined]
|
|
84
78
|
});
|
|
85
79
|
}, [enableSlash, enableMention, slashOption, restMentionOption]);
|
|
86
|
-
var handleKeyDown = function handleKeyDown(e) {
|
|
87
|
-
// Check if currently composing (e.g., typing with IME)
|
|
88
|
-
var isComposing = e.nativeEvent.isComposing;
|
|
89
|
-
|
|
90
|
-
// Handle Enter key press
|
|
91
|
-
if (e.key === 'Enter' && !isComposing) {
|
|
92
|
-
// Support for Ctrl/Cmd + Enter for forced submit
|
|
93
|
-
if (isModifierMatch(e.nativeEvent, CONTROL_OR_META) && onPressEnter) {
|
|
94
|
-
// Force submit with modifier key
|
|
95
|
-
onPressEnter(e);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Regular Enter key handling
|
|
100
|
-
if (onPressEnter) {
|
|
101
|
-
onPressEnter(e);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Call the optional onKeyDown handler
|
|
106
|
-
onKeyDown === null || onKeyDown === void 0 || onKeyDown(e);
|
|
107
|
-
};
|
|
108
80
|
return /*#__PURE__*/_jsxs(ReactEditor, {
|
|
109
81
|
config: config,
|
|
110
|
-
editorRef:
|
|
82
|
+
editorRef: editorRef,
|
|
111
83
|
children: [memoPlugins, memoSlash, memoMention, /*#__PURE__*/_jsx(ReactPlainText, {
|
|
112
84
|
autoFocus: autoFocus,
|
|
113
85
|
className: className,
|
|
@@ -117,9 +89,9 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
117
89
|
onCompositionStart: onCompositionStart,
|
|
118
90
|
onContextMenu: onContextMenu,
|
|
119
91
|
onFocus: onFocus,
|
|
120
|
-
onKeyDown:
|
|
92
|
+
onKeyDown: onKeyDown,
|
|
93
|
+
onPressEnter: onPressEnter,
|
|
121
94
|
style: style,
|
|
122
|
-
theme: theme,
|
|
123
95
|
variant: variant,
|
|
124
96
|
children: /*#__PURE__*/_jsx(ReactEditorContent, {
|
|
125
97
|
content: content,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSSProperties,
|
|
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,24 +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
11
|
autoFocus?: boolean;
|
|
12
12
|
children?: ReactNode;
|
|
13
13
|
className?: string;
|
|
14
|
-
editorRef?:
|
|
14
|
+
editorRef?: RefObject<IEditor | null>;
|
|
15
15
|
mentionOption?: MentionOption;
|
|
16
|
-
onBlur?: FocusEventHandler<HTMLDivElement>;
|
|
17
|
-
onChange?: (editor: IEditor) => void;
|
|
18
|
-
onCompositionEnd?: CompositionEventHandler<HTMLDivElement>;
|
|
19
|
-
onCompositionStart?: CompositionEventHandler<HTMLDivElement>;
|
|
20
|
-
onContextMenu?: MouseEventHandler<HTMLDivElement>;
|
|
21
|
-
onFocus?: FocusEventHandler<HTMLDivElement>;
|
|
22
|
-
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
23
|
-
onPressEnter?: KeyboardEventHandler<HTMLDivElement>;
|
|
24
16
|
plugins?: EditorPlugin[];
|
|
25
17
|
slashOption?: Partial<ReactSlashOptionProps>;
|
|
26
18
|
style?: CSSProperties;
|
|
27
|
-
theme?: ReactPlainTextProps['theme'];
|
|
28
|
-
variant?: ReactPlainTextProps['variant'];
|
|
29
19
|
}
|
|
30
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