@lobehub/editor 1.23.1 → 1.25.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/README.md +9 -5
- package/es/editor-kernel/kernel.d.ts +3 -1
- package/es/editor-kernel/kernel.js +27 -8
- package/es/editor-kernel/react/useEditable.d.ts +3 -0
- package/es/editor-kernel/react/useEditable.js +32 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/plugins/auto-complete/index.d.ts +2 -0
- package/es/plugins/auto-complete/index.js +2 -0
- package/es/plugins/auto-complete/node/placeholderNode.d.ts +30 -0
- package/es/plugins/auto-complete/node/placeholderNode.js +171 -0
- package/es/plugins/auto-complete/plugin/index.d.ts +17 -0
- package/es/plugins/auto-complete/plugin/index.js +398 -0
- package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.d.ts +4 -0
- package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.js +35 -0
- package/es/plugins/auto-complete/react/index.d.ts +1 -0
- package/es/plugins/auto-complete/react/index.js +1 -0
- package/es/plugins/auto-complete/react/style.d.ts +4 -0
- package/es/plugins/auto-complete/react/style.js +10 -0
- package/es/plugins/auto-complete/react/type.d.ts +11 -0
- package/es/plugins/auto-complete/react/type.js +1 -0
- package/es/plugins/codeblock/plugin/index.js +28 -1
- package/es/plugins/common/plugin/index.js +0 -1
- package/es/plugins/common/plugin/register.js +3 -0
- package/es/plugins/common/react/ReactPlainText.js +9 -2
- package/es/plugins/common/react/style.js +1 -1
- package/es/plugins/common/react/type.d.ts +1 -0
- package/es/plugins/image/command/index.d.ts +2 -0
- package/es/plugins/image/command/index.js +10 -2
- package/es/plugins/image/node/basie-image-node.d.ts +1 -0
- package/es/plugins/image/node/basie-image-node.js +5 -0
- package/es/plugins/image/node/block-image-node.d.ts +31 -0
- package/es/plugins/image/node/block-image-node.js +209 -0
- package/es/plugins/image/node/image-node.d.ts +3 -0
- package/es/plugins/image/node/image-node.js +17 -0
- package/es/plugins/image/plugin/index.d.ts +4 -1
- package/es/plugins/image/plugin/index.js +51 -11
- package/es/plugins/image/react/ReactImagePlugin.js +3 -1
- package/es/plugins/image/react/components/Image.d.ts +4 -3
- package/es/plugins/image/react/components/Image.js +272 -24
- package/es/plugins/image/react/components/LazyImage.d.ts +7 -1
- package/es/plugins/image/react/components/LazyImage.js +11 -3
- package/es/plugins/image/react/components/style.d.ts +40 -0
- package/es/plugins/image/react/components/style.js +43 -0
- package/es/plugins/image/react/style.d.ts +10 -0
- package/es/plugins/image/react/style.js +10 -0
- package/es/plugins/image/react/type.d.ts +2 -0
- package/es/plugins/link/react/components/LinkEdit.js +4 -1
- package/es/plugins/link/react/components/LinkToolbar.js +5 -1
- package/es/plugins/markdown/service/shortcut.d.ts +7 -2
- package/es/plugins/markdown/service/shortcut.js +12 -1
- package/es/plugins/markdown/utils/index.d.ts +2 -0
- package/es/plugins/markdown/utils/index.js +4 -1
- package/es/react/Editor/Editor.js +2 -0
- package/es/react/Editor/type.d.ts +1 -0
- package/es/react/hooks/useEditorState/index.js +41 -33
- package/es/types/kernel.d.ts +14 -1
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
28
28
|
var content = _ref.content,
|
|
29
29
|
style = _ref.style,
|
|
30
30
|
className = _ref.className,
|
|
31
|
+
editable = _ref.editable,
|
|
31
32
|
editor = _ref.editor,
|
|
32
33
|
onInit = _ref.onInit,
|
|
33
34
|
onChange = _ref.onChange,
|
|
@@ -99,6 +100,7 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
99
100
|
children: [memoPlugins, memoSlash, memoMention, /*#__PURE__*/_jsx(ReactPlainText, {
|
|
100
101
|
autoFocus: autoFocus,
|
|
101
102
|
className: className,
|
|
103
|
+
editable: editable,
|
|
102
104
|
enablePasteMarkdown: enablePasteMarkdown,
|
|
103
105
|
markdownOption: markdownOption,
|
|
104
106
|
onBlur: onBlur,
|
|
@@ -11,6 +11,7 @@ export interface EditorProps extends Partial<ReactEditorContentProps>, Omit<Reac
|
|
|
11
11
|
autoFocus?: boolean;
|
|
12
12
|
children?: ReactNode;
|
|
13
13
|
className?: string;
|
|
14
|
+
editable?: boolean;
|
|
14
15
|
editor?: IEditor;
|
|
15
16
|
/**
|
|
16
17
|
* Enable automatic markdown formatting for pasted content
|
|
@@ -34,6 +34,7 @@ import { $findTopLevelElement, formatParagraph, getSelectedNode } from "./utils"
|
|
|
34
34
|
* @returns Editor state and methods for toolbar functionality
|
|
35
35
|
*/
|
|
36
36
|
export function useEditorState(editor) {
|
|
37
|
+
var _editor$isEditable;
|
|
37
38
|
var _useState = useState(false),
|
|
38
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
39
40
|
canUndo = _useState2[0],
|
|
@@ -42,70 +43,76 @@ export function useEditorState(editor) {
|
|
|
42
43
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
44
|
canRedo = _useState4[0],
|
|
44
45
|
setCanRedo = _useState4[1];
|
|
45
|
-
var _useState5 = useState(
|
|
46
|
+
var _useState5 = useState((_editor$isEditable = editor === null || editor === void 0 ? void 0 : editor.isEditable()) !== null && _editor$isEditable !== void 0 ? _editor$isEditable : true),
|
|
46
47
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
editable = _useState6[0],
|
|
49
|
+
setEditable = _useState6[1];
|
|
49
50
|
var _useState7 = useState(false),
|
|
50
51
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
isBold = _useState8[0],
|
|
53
|
+
setIsBold = _useState8[1];
|
|
53
54
|
var _useState9 = useState(false),
|
|
54
55
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
isItalic = _useState10[0],
|
|
57
|
+
setIsItalic = _useState10[1];
|
|
57
58
|
var _useState11 = useState(false),
|
|
58
59
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
isUnderline = _useState12[0],
|
|
61
|
+
setIsUnderline = _useState12[1];
|
|
61
62
|
var _useState13 = useState(false),
|
|
62
63
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
isStrikethrough = _useState14[0],
|
|
65
|
+
setIsStrikethrough = _useState14[1];
|
|
65
66
|
var _useState15 = useState(false),
|
|
66
67
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
isSubscript = _useState16[0],
|
|
69
|
+
setIsSubscript = _useState16[1];
|
|
69
70
|
var _useState17 = useState(false),
|
|
70
71
|
_useState18 = _slicedToArray(_useState17, 2),
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
isSuperscript = _useState18[0],
|
|
73
|
+
setIsSuperscript = _useState18[1];
|
|
73
74
|
var _useState19 = useState(false),
|
|
74
75
|
_useState20 = _slicedToArray(_useState19, 2),
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
isCode = _useState20[0],
|
|
77
|
+
setIsCode = _useState20[1];
|
|
77
78
|
var _useState21 = useState(false),
|
|
78
79
|
_useState22 = _slicedToArray(_useState21, 2),
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
isLink = _useState22[0],
|
|
81
|
+
setIsLink = _useState22[1];
|
|
81
82
|
var _useState23 = useState(false),
|
|
82
83
|
_useState24 = _slicedToArray(_useState23, 2),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var _useState25 = useState(
|
|
84
|
+
isCodeblock = _useState24[0],
|
|
85
|
+
setIsInCodeblok = _useState24[1];
|
|
86
|
+
var _useState25 = useState(false),
|
|
86
87
|
_useState26 = _slicedToArray(_useState25, 2),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var _useState27 = useState(
|
|
88
|
+
isBlockquote = _useState26[0],
|
|
89
|
+
setIsInBlockquote = _useState26[1];
|
|
90
|
+
var _useState27 = useState(null),
|
|
90
91
|
_useState28 = _slicedToArray(_useState27, 2),
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var _useState29 = useState(
|
|
92
|
+
codeblockLang = _useState28[0],
|
|
93
|
+
setCodeblockLang = _useState28[1];
|
|
94
|
+
var _useState29 = useState(true),
|
|
94
95
|
_useState30 = _slicedToArray(_useState29, 2),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var _useState31 = useState(
|
|
96
|
+
isEmpty = _useState30[0],
|
|
97
|
+
setIsEmpty = _useState30[1];
|
|
98
|
+
var _useState31 = useState(false),
|
|
98
99
|
_useState32 = _slicedToArray(_useState31, 2),
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
isSelected = _useState32[0],
|
|
101
|
+
setIsSelected = _useState32[1];
|
|
102
|
+
var _useState33 = useState(null),
|
|
103
|
+
_useState34 = _slicedToArray(_useState33, 2),
|
|
104
|
+
blockType = _useState34[0],
|
|
105
|
+
setBlockType = _useState34[1];
|
|
101
106
|
var $handleHeadingNode = useCallback(function (selectedElement) {
|
|
102
107
|
var type = $isHeadingNode(selectedElement) ? selectedElement.getTag() : selectedElement.getType();
|
|
103
108
|
setBlockType(type);
|
|
104
109
|
}, [setBlockType]);
|
|
105
110
|
var $updateToolbar = useCallback(function () {
|
|
111
|
+
var _editor$isEditable2;
|
|
106
112
|
var selection = $getSelection();
|
|
107
113
|
var lexicalEditor = editor === null || editor === void 0 ? void 0 : editor.getLexicalEditor();
|
|
108
114
|
setIsSelected(false);
|
|
115
|
+
setEditable((_editor$isEditable2 = editor === null || editor === void 0 ? void 0 : editor.isEditable()) !== null && _editor$isEditable2 !== void 0 ? _editor$isEditable2 : true);
|
|
109
116
|
if (lexicalEditor) {
|
|
110
117
|
setIsEmpty($isRootTextContentEmpty(lexicalEditor.isComposing(), false));
|
|
111
118
|
}
|
|
@@ -417,6 +424,7 @@ export function useEditorState(editor) {
|
|
|
417
424
|
code: code,
|
|
418
425
|
codeblock: codeblock,
|
|
419
426
|
codeblockLang: codeblockLang,
|
|
427
|
+
editable: editable,
|
|
420
428
|
insertLink: insertLink,
|
|
421
429
|
insertMath: insertMath,
|
|
422
430
|
isBlockquote: isBlockquote,
|
package/es/types/kernel.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type IServiceID<Service> = {
|
|
|
14
14
|
__serviceType?: Service;
|
|
15
15
|
};
|
|
16
16
|
export interface IKernelEventMap {
|
|
17
|
+
/**
|
|
18
|
+
* Editor editable state change event
|
|
19
|
+
*/
|
|
20
|
+
editableChange: (editable: boolean) => void;
|
|
17
21
|
/**
|
|
18
22
|
* Editor error event
|
|
19
23
|
*/
|
|
@@ -84,6 +88,10 @@ export interface IEditor {
|
|
|
84
88
|
* Get node editor instance
|
|
85
89
|
*/
|
|
86
90
|
initNodeEditor(): LexicalEditor | null;
|
|
91
|
+
/**
|
|
92
|
+
* Check if editor is editable
|
|
93
|
+
*/
|
|
94
|
+
isEditable(): boolean;
|
|
87
95
|
/**
|
|
88
96
|
* Check if editor content is empty
|
|
89
97
|
* @returns true if editor content is empty, false otherwise
|
|
@@ -166,11 +174,16 @@ export interface IEditor {
|
|
|
166
174
|
* @param content
|
|
167
175
|
*/
|
|
168
176
|
setDocument(type: string, content: any): void;
|
|
177
|
+
/**
|
|
178
|
+
* Enable or disable editor editing capability
|
|
179
|
+
* @param editable
|
|
180
|
+
*/
|
|
181
|
+
setEditable(editable: boolean): void;
|
|
169
182
|
/**
|
|
170
183
|
* Set document editor root node
|
|
171
184
|
* @param dom
|
|
172
185
|
*/
|
|
173
|
-
setRootElement(dom: HTMLElement): LexicalEditor;
|
|
186
|
+
setRootElement(dom: HTMLElement, editable?: boolean): LexicalEditor;
|
|
174
187
|
/**
|
|
175
188
|
* Get translation text
|
|
176
189
|
* @param key Translation key
|
package/package.json
CHANGED