@lobehub/editor 3.9.1 → 3.11.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/const/hotkey.js +12 -12
- package/es/editor-kernel/data-source.d.ts +1 -1
- package/es/editor-kernel/data-source.js +1 -1
- package/es/editor-kernel/kernel.d.ts +1 -1
- package/es/editor-kernel/kernel.js +2 -2
- package/es/plugins/common/data-source/json-data-source.d.ts +1 -1
- package/es/plugins/common/data-source/json-data-source.js +2 -1
- package/es/plugins/common/plugin/index.d.ts +5 -0
- package/es/plugins/common/plugin/index.js +32 -1
- package/es/plugins/common/react/ReactPlainText.js +4 -1
- package/es/plugins/common/react/type.d.ts +5 -0
- package/es/plugins/litexml/index.d.ts +1 -0
- package/es/plugins/litexml/index.js +1 -0
- package/es/plugins/litexml/react/hooks/useHasDiffNode.d.ts +4 -0
- package/es/plugins/litexml/react/hooks/useHasDiffNode.js +61 -0
- package/es/react/Editor/Editor.js +3 -0
- package/es/types/kernel.d.ts +1 -1
- package/package.json +30 -1
package/es/const/hotkey.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { COMMAND_PRIORITY_LOW } from 'lexical';
|
|
2
2
|
import { HotkeyEnum, HotkeyScopeEnum, KeyEnum } from "../types/hotkey";
|
|
3
3
|
var combineKeys = function combineKeys(keys) {
|
|
4
4
|
return keys.join('+');
|
|
@@ -6,58 +6,58 @@ var combineKeys = function combineKeys(keys) {
|
|
|
6
6
|
export var HOTKEYS_REGISTRATION = [{
|
|
7
7
|
id: HotkeyEnum.Undo,
|
|
8
8
|
keys: combineKeys([KeyEnum.Mod, 'z']),
|
|
9
|
-
priority:
|
|
9
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
10
10
|
scopes: [HotkeyScopeEnum.Format]
|
|
11
11
|
}, {
|
|
12
12
|
id: HotkeyEnum.Redo,
|
|
13
13
|
keys: combineKeys([KeyEnum.Mod, 'y']),
|
|
14
|
-
priority:
|
|
14
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
15
15
|
scopes: [HotkeyScopeEnum.Format]
|
|
16
16
|
}, {
|
|
17
17
|
id: HotkeyEnum.Bold,
|
|
18
18
|
keys: combineKeys([KeyEnum.Mod, 'b']),
|
|
19
|
-
priority:
|
|
19
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
20
20
|
scopes: [HotkeyScopeEnum.Format]
|
|
21
21
|
}, {
|
|
22
22
|
id: HotkeyEnum.Italic,
|
|
23
23
|
keys: combineKeys([KeyEnum.Mod, 'i']),
|
|
24
|
-
priority:
|
|
24
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
25
25
|
scopes: [HotkeyScopeEnum.Format]
|
|
26
26
|
}, {
|
|
27
27
|
id: HotkeyEnum.Underline,
|
|
28
28
|
keys: combineKeys([KeyEnum.Mod, 'u']),
|
|
29
|
-
priority:
|
|
29
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
30
30
|
scopes: [HotkeyScopeEnum.Format]
|
|
31
31
|
}, {
|
|
32
32
|
id: HotkeyEnum.Strikethrough,
|
|
33
33
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, 'x']),
|
|
34
|
-
priority:
|
|
34
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
35
35
|
scopes: [HotkeyScopeEnum.Format]
|
|
36
36
|
}, {
|
|
37
37
|
id: HotkeyEnum.CodeInline,
|
|
38
38
|
keys: combineKeys([KeyEnum.Mod, 'e']),
|
|
39
|
-
priority:
|
|
39
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
40
40
|
scopes: [HotkeyScopeEnum.Format, HotkeyScopeEnum.Plugin]
|
|
41
41
|
}, {
|
|
42
42
|
id: HotkeyEnum.Link,
|
|
43
43
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, 'k']),
|
|
44
|
-
priority:
|
|
44
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
45
45
|
scopes: [HotkeyScopeEnum.Format, HotkeyScopeEnum.Plugin]
|
|
46
46
|
},
|
|
47
47
|
// List hotkeys
|
|
48
48
|
{
|
|
49
49
|
id: HotkeyEnum.NumberList,
|
|
50
50
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, '7']),
|
|
51
|
-
priority:
|
|
51
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
52
52
|
scopes: [HotkeyScopeEnum.Insert, HotkeyScopeEnum.Plugin]
|
|
53
53
|
}, {
|
|
54
54
|
id: HotkeyEnum.BulletList,
|
|
55
55
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, '8']),
|
|
56
|
-
priority:
|
|
56
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
57
57
|
scopes: [HotkeyScopeEnum.Insert, HotkeyScopeEnum.Plugin]
|
|
58
58
|
}, {
|
|
59
59
|
id: HotkeyEnum.PasteAsPlainText,
|
|
60
60
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, 'v']),
|
|
61
|
-
priority:
|
|
61
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
62
62
|
scopes: [HotkeyScopeEnum.Format]
|
|
63
63
|
}];
|
|
@@ -6,6 +6,6 @@ export default class DataSource {
|
|
|
6
6
|
protected dataType: string;
|
|
7
7
|
constructor(dataType: string);
|
|
8
8
|
get type(): string;
|
|
9
|
-
read(editor: LexicalEditor, data: any): void;
|
|
9
|
+
read(editor: LexicalEditor, data: any, options?: Record<string, unknown>): void;
|
|
10
10
|
write(editor: LexicalEditor, options?: IWriteOptions): any;
|
|
11
11
|
}
|
|
@@ -40,7 +40,7 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
|
|
|
40
40
|
setRootElement(dom: HTMLElement, editable?: boolean): LexicalEditor;
|
|
41
41
|
setEditable(editable: boolean): void;
|
|
42
42
|
initNodeEditor(): LexicalEditor;
|
|
43
|
-
setDocument(type: string, content: any): void;
|
|
43
|
+
setDocument(type: string, content: any, options?: Record<string, unknown>): void;
|
|
44
44
|
focus(): void;
|
|
45
45
|
blur(): void;
|
|
46
46
|
getDocument(type: string): DataSource | undefined;
|
|
@@ -261,7 +261,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
261
261
|
}
|
|
262
262
|
}, {
|
|
263
263
|
key: "setDocument",
|
|
264
|
-
value: function setDocument(type, content) {
|
|
264
|
+
value: function setDocument(type, content, options) {
|
|
265
265
|
var datasource = this.dataTypeMap.get(type);
|
|
266
266
|
if (!datasource) {
|
|
267
267
|
this.logger.error("\u274C DataSource for type \"".concat(type, "\" not found"));
|
|
@@ -271,7 +271,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
271
271
|
this.logger.error('❌ Editor not initialized');
|
|
272
272
|
throw new Error("Editor is not initialized.");
|
|
273
273
|
}
|
|
274
|
-
datasource.read(this.editor, content);
|
|
274
|
+
datasource.read(this.editor, content, options);
|
|
275
275
|
this.emit('documentChange', type, content);
|
|
276
276
|
this.logger.debug("\uD83D\uDCE5 Set ".concat(type, " document"));
|
|
277
277
|
}
|
|
@@ -2,6 +2,6 @@ import type { LexicalEditor } from 'lexical';
|
|
|
2
2
|
import { DataSource } from "../../../editor-kernel";
|
|
3
3
|
import type { IWriteOptions } from "../../../editor-kernel/data-source";
|
|
4
4
|
export default class JSONDataSource extends DataSource {
|
|
5
|
-
read(editor: LexicalEditor, data: any): void;
|
|
5
|
+
read(editor: LexicalEditor, data: any, options?: Record<string, unknown>): void;
|
|
6
6
|
write(editor: LexicalEditor, options?: IWriteOptions): any;
|
|
7
7
|
}
|
|
@@ -40,6 +40,7 @@ var JSONDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
40
40
|
_createClass(JSONDataSource, [{
|
|
41
41
|
key: "read",
|
|
42
42
|
value: function read(editor, data) {
|
|
43
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
43
44
|
var dataObj;
|
|
44
45
|
if (typeof data === 'string') {
|
|
45
46
|
dataObj = JSON.parse(data);
|
|
@@ -69,7 +70,7 @@ var JSONDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
69
70
|
};
|
|
70
71
|
process(dataObj.root);
|
|
71
72
|
// @ts-expect-error add id option
|
|
72
|
-
if (dataObj.keepId) {
|
|
73
|
+
if (dataObj.keepId || options.keepId) {
|
|
73
74
|
var state = editor.parseEditorState({
|
|
74
75
|
root: INodeHelper.createRootNode()
|
|
75
76
|
}, function (state) {
|
|
@@ -17,6 +17,11 @@ export interface CommonPluginOptions {
|
|
|
17
17
|
underline?: boolean;
|
|
18
18
|
underlineStrikethrough?: boolean;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Force paste as plain text, stripping all rich text formatting
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
pasteAsPlainText?: boolean;
|
|
20
25
|
theme?: {
|
|
21
26
|
quote?: string;
|
|
22
27
|
textBold?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
var _class;
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
3
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
4
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -25,7 +26,7 @@ import { registerDragonSupport } from '@lexical/dragon';
|
|
|
25
26
|
import { registerHistory } from '@lexical/history';
|
|
26
27
|
import { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode, HeadingNode, QuoteNode, registerRichText } from '@lexical/rich-text';
|
|
27
28
|
import { CAN_USE_DOM } from '@lexical/utils';
|
|
28
|
-
import { $createLineBreakNode, $createParagraphNode, $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, PASTE_COMMAND, ParagraphNode, TEXT_TYPE_TO_FORMAT, TextNode } from 'lexical';
|
|
29
|
+
import { $createLineBreakNode, $createParagraphNode, $getSelection, $isRangeSelection, $isTextNode, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, CONTROLLED_TEXT_INSERTION_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, PASTE_COMMAND, ParagraphNode, TEXT_TYPE_TO_FORMAT, TextNode } from 'lexical';
|
|
29
30
|
import { noop } from "../../../editor-kernel";
|
|
30
31
|
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
31
32
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
@@ -349,10 +350,40 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
349
350
|
var _this2 = this,
|
|
350
351
|
_this$config2;
|
|
351
352
|
this.register(this.kernel.registerHighCommand(PASTE_COMMAND, function (event) {
|
|
353
|
+
var _this2$config;
|
|
352
354
|
if (!(event instanceof ClipboardEvent)) return false;
|
|
353
355
|
var clipboardData = event.clipboardData;
|
|
354
356
|
if (!clipboardData) return false;
|
|
355
357
|
_this2.kernel.emit('onPaste', event);
|
|
358
|
+
|
|
359
|
+
// If pasteAsPlainText is enabled, intercept and paste as plain text
|
|
360
|
+
if ((_this2$config = _this2.config) !== null && _this2$config !== void 0 && _this2$config.pasteAsPlainText) {
|
|
361
|
+
// Check if it's a file paste - don't interfere with file uploads
|
|
362
|
+
var items = clipboardData.items;
|
|
363
|
+
var _iterator = _createForOfIteratorHelper(items),
|
|
364
|
+
_step;
|
|
365
|
+
try {
|
|
366
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
367
|
+
var item = _step.value;
|
|
368
|
+
if (item.kind === 'file') {
|
|
369
|
+
return false; // Let file paste be handled normally
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Get plain text from clipboard
|
|
374
|
+
} catch (err) {
|
|
375
|
+
_iterator.e(err);
|
|
376
|
+
} finally {
|
|
377
|
+
_iterator.f();
|
|
378
|
+
}
|
|
379
|
+
var text = clipboardData.getData('text/plain');
|
|
380
|
+
if (!text) return false;
|
|
381
|
+
|
|
382
|
+
// Prevent default paste behavior and insert plain text
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
editor.dispatchCommand(CONTROLLED_TEXT_INSERTION_COMMAND, text);
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
356
387
|
return false;
|
|
357
388
|
}, COMMAND_PRIORITY_CRITICAL));
|
|
358
389
|
this.registerClears(registerRichText(editor), CAN_USE_DOM ? registerDragonSupport(editor) : noop, registerHistory(editor, this.kernel.getHistoryState(), 300), registerHeaderBackspace(editor), registerRichKeydown(editor, this.kernel, {
|
|
@@ -44,6 +44,8 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
44
44
|
enablePasteMarkdown = _ref$enablePasteMarkd === void 0 ? true : _ref$enablePasteMarkd,
|
|
45
45
|
_ref$markdownOption = _ref.markdownOption,
|
|
46
46
|
markdownOption = _ref$markdownOption === void 0 ? true : _ref$markdownOption,
|
|
47
|
+
_ref$pasteAsPlainText = _ref.pasteAsPlainText,
|
|
48
|
+
pasteAsPlainText = _ref$pasteAsPlainText === void 0 ? false : _ref$pasteAsPlainText,
|
|
47
49
|
onKeyDown = _ref.onKeyDown,
|
|
48
50
|
onFocus = _ref.onFocus,
|
|
49
51
|
onBlur = _ref.onBlur,
|
|
@@ -109,9 +111,10 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
|
|
|
109
111
|
editor.registerPlugin(CommonPlugin, {
|
|
110
112
|
enableHotkey: enableHotkey,
|
|
111
113
|
markdownOption: markdownOption,
|
|
114
|
+
pasteAsPlainText: pasteAsPlainText,
|
|
112
115
|
theme: restTheme ? _objectSpread(_objectSpread({}, computedThemeStyles), restTheme) : computedThemeStyles
|
|
113
116
|
});
|
|
114
|
-
}, [editor, enableHotkey, enablePasteMarkdown, markdownOption, restTheme, computedThemeStyles]);
|
|
117
|
+
}, [editor, enableHotkey, enablePasteMarkdown, markdownOption, pasteAsPlainText, restTheme, computedThemeStyles]);
|
|
115
118
|
useEffect(function () {
|
|
116
119
|
var _editor$getLexicalEdi;
|
|
117
120
|
var container = editorContainerRef.current;
|
|
@@ -57,6 +57,11 @@ export interface ReactPlainTextProps {
|
|
|
57
57
|
* Unlike onChange, this won't trigger on cursor movement or selection changes
|
|
58
58
|
*/
|
|
59
59
|
onTextChange?: (editor: IEditor) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Force paste as plain text, stripping all rich text formatting
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
pasteAsPlainText?: boolean;
|
|
60
65
|
style?: CSSProperties;
|
|
61
66
|
theme?: CommonPluginOptions['theme'] & {
|
|
62
67
|
fontSize?: number;
|
|
@@ -4,5 +4,6 @@ export { default as LitexmlDataSource } from './data-source/litexml-data-source'
|
|
|
4
4
|
export type { LitexmlPluginOptions } from './plugin';
|
|
5
5
|
export { LitexmlPlugin } from './plugin';
|
|
6
6
|
export { ReactLiteXmlPlugin } from './react';
|
|
7
|
+
export { useHasDiffNode } from './react/hooks/useHasDiffNode';
|
|
7
8
|
export type { XMLReaderFunc, XMLReaderRecord, XMLWriterFunc, XMLWriterRecord, } from './service/litexml-service';
|
|
8
9
|
export { ILitexmlService, LitexmlService } from './service/litexml-service';
|
|
@@ -3,4 +3,5 @@ export { DiffAction, LITEXML_DIFFNODE_ALL_COMMAND, LITEXML_DIFFNODE_COMMAND } fr
|
|
|
3
3
|
export { default as LitexmlDataSource } from "./data-source/litexml-data-source";
|
|
4
4
|
export { LitexmlPlugin } from "./plugin";
|
|
5
5
|
export { ReactLiteXmlPlugin } from "./react";
|
|
6
|
+
export { useHasDiffNode } from "./react/hooks/useHasDiffNode";
|
|
6
7
|
export { ILitexmlService, LitexmlService } from "./service/litexml-service";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
import { useEffect, useState } from 'react';
|
|
9
|
+
function hasDiffNode(editor) {
|
|
10
|
+
var _editor$getLexicalEdi;
|
|
11
|
+
var values = (_editor$getLexicalEdi = editor.getLexicalEditor()) === null || _editor$getLexicalEdi === void 0 ? void 0 : _editor$getLexicalEdi.getEditorState()._nodeMap.values();
|
|
12
|
+
if (!values) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
var _iterator = _createForOfIteratorHelper(values),
|
|
16
|
+
_step;
|
|
17
|
+
try {
|
|
18
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
19
|
+
var node = _step.value;
|
|
20
|
+
if (node.getType() === 'diff') {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
_iterator.e(err);
|
|
26
|
+
} finally {
|
|
27
|
+
_iterator.f();
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
export function useHasDiffNode(editor) {
|
|
32
|
+
var _useState = useState(!!editor.getLexicalEditor()),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
hasInit = _useState2[0],
|
|
35
|
+
setHasInit = _useState2[1];
|
|
36
|
+
var _useState3 = useState(hasDiffNode(editor)),
|
|
37
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
38
|
+
hasDiff = _useState4[0],
|
|
39
|
+
setHasDiff = _useState4[1];
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
var handle = function handle() {
|
|
42
|
+
setHasInit(true);
|
|
43
|
+
};
|
|
44
|
+
editor.on('initialized', handle);
|
|
45
|
+
return function () {
|
|
46
|
+
editor.off('initialized', handle);
|
|
47
|
+
};
|
|
48
|
+
}, [editor]);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
var _editor$getLexicalEdi2;
|
|
51
|
+
var unregister = (_editor$getLexicalEdi2 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi2 === void 0 ? void 0 : _editor$getLexicalEdi2.registerUpdateListener(function () {
|
|
52
|
+
setHasDiff(hasDiffNode(editor));
|
|
53
|
+
});
|
|
54
|
+
return function () {
|
|
55
|
+
unregister === null || unregister === void 0 || unregister();
|
|
56
|
+
};
|
|
57
|
+
}, [editor, hasInit]);
|
|
58
|
+
return {
|
|
59
|
+
hasDiff: hasDiff
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -57,6 +57,8 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
57
57
|
enablePasteMarkdown = _ref$enablePasteMarkd === void 0 ? true : _ref$enablePasteMarkd,
|
|
58
58
|
_ref$markdownOption = _ref.markdownOption,
|
|
59
59
|
markdownOption = _ref$markdownOption === void 0 ? true : _ref$markdownOption,
|
|
60
|
+
_ref$pasteAsPlainText = _ref.pasteAsPlainText,
|
|
61
|
+
pasteAsPlainText = _ref$pasteAsPlainText === void 0 ? false : _ref$pasteAsPlainText,
|
|
60
62
|
onCompositionStart = _ref.onCompositionStart,
|
|
61
63
|
onCompositionEnd = _ref.onCompositionEnd,
|
|
62
64
|
onContextMenu = _ref.onContextMenu,
|
|
@@ -124,6 +126,7 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
|
|
|
124
126
|
onKeyDown: onKeyDown,
|
|
125
127
|
onPressEnter: onPressEnter,
|
|
126
128
|
onTextChange: debouncedOnTextChange,
|
|
129
|
+
pasteAsPlainText: pasteAsPlainText,
|
|
127
130
|
style: style,
|
|
128
131
|
variant: variant,
|
|
129
132
|
children: /*#__PURE__*/_jsx(ReactEditorContent, {
|
package/es/types/kernel.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ export interface IEditor {
|
|
|
186
186
|
* @param type
|
|
187
187
|
* @param content
|
|
188
188
|
*/
|
|
189
|
-
setDocument(type: string, content: any): void;
|
|
189
|
+
setDocument(type: string, content: any, options?: Record<string, unknown>): void;
|
|
190
190
|
/**
|
|
191
191
|
* Enable or disable editor editing capability
|
|
192
192
|
* @param editable
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.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",
|
|
@@ -29,6 +29,35 @@
|
|
|
29
29
|
"react.d.ts",
|
|
30
30
|
"react.js"
|
|
31
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "npm run build:clean && father build && npm run build:packages",
|
|
34
|
+
"build:clean": "tsx ./scripts/clean.ts",
|
|
35
|
+
"build:packages": "tsx ./scripts/build.ts",
|
|
36
|
+
"build:watch": "father dev",
|
|
37
|
+
"ci": "npm run lint:circular && npm run lint && npm run type-check",
|
|
38
|
+
"clean": "rm -r es lib dist coverage .dumi/tmp .eslintcache node_modules/.cache",
|
|
39
|
+
"dev": "dumi dev",
|
|
40
|
+
"docs:build": "dumi build",
|
|
41
|
+
"docs:build-analyze": "ANALYZE=1 dumi build",
|
|
42
|
+
"docs:dev": "dumi dev",
|
|
43
|
+
"doctor": "father doctor",
|
|
44
|
+
"postinstall": "node scripts/patch-lexical.js",
|
|
45
|
+
"lint": "eslint \"{src,tests}/**/*.{js,jsx,ts,tsx}\" --fix",
|
|
46
|
+
"lint:circular": "dpdm src/**/*.{ts,tsx} --warning false --tree false --exit-code circular:1 -T true",
|
|
47
|
+
"lint:md": "remark . --quiet --frail --output",
|
|
48
|
+
"lint:style": "stylelint \"{src,tests}/**/*.{js,jsx,ts,tsx,less}\" --fix",
|
|
49
|
+
"prepack": "clean-package",
|
|
50
|
+
"postpack": "clean-package restore",
|
|
51
|
+
"prepare": "husky && npm run setup",
|
|
52
|
+
"prettier": "prettier -c --write --no-error-on-unmatched-pattern \"**/**\"",
|
|
53
|
+
"release": "semantic-release",
|
|
54
|
+
"setup": "dumi setup",
|
|
55
|
+
"start": "npm run docs:dev",
|
|
56
|
+
"test": "vitest",
|
|
57
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
58
|
+
"test:watch": "vitest --watch",
|
|
59
|
+
"type-check": "tsc --noEmit"
|
|
60
|
+
},
|
|
32
61
|
"dependencies": {
|
|
33
62
|
"@floating-ui/dom": "^1.7.4",
|
|
34
63
|
"@floating-ui/react": "^0.27.16",
|