@lobehub/editor 3.10.0 → 3.12.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/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from './plugins/slash';
20
20
  export * from './plugins/table';
21
21
  export * from './plugins/toolbar';
22
22
  export * from './plugins/upload';
23
+ export * from './plugins/virtual-block';
23
24
  export type { IEditor } from './types';
24
25
  export * from './types/hotkey';
25
26
  export { getHotkeyById } from './utils/hotkey/registerHotkey';
package/es/index.js CHANGED
@@ -20,6 +20,7 @@ export * from "./plugins/slash";
20
20
  export * from "./plugins/table";
21
21
  export * from "./plugins/toolbar";
22
22
  export * from "./plugins/upload";
23
+ export * from "./plugins/virtual-block";
23
24
  // Hotkey utilities
24
25
  export * from "./types/hotkey";
25
26
  export { getHotkeyById } from "./utils/hotkey/registerHotkey";
@@ -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;
@@ -0,0 +1,2 @@
1
+ export * from './plugin';
2
+ export * from './react';
@@ -0,0 +1,2 @@
1
+ export * from "./plugin";
2
+ export * from "./react";
@@ -0,0 +1,5 @@
1
+ import { IEditorPluginConstructor } from "../../../types";
2
+ export interface VirtualBlockPluginOptions {
3
+ theme?: string;
4
+ }
5
+ export declare const VirtualBlockPlugin: IEditorPluginConstructor<VirtualBlockPluginOptions>;
@@ -0,0 +1,41 @@
1
+ var _class;
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
7
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
8
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
10
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
+ 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); }
16
+ import { KernelPlugin } from "../../../editor-kernel/plugin";
17
+ import { registerRichKeydown } from "./register";
18
+
19
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
20
+
21
+ export var VirtualBlockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
22
+ _inherits(VirtualBlockPlugin, _KernelPlugin);
23
+ var _super = _createSuper(VirtualBlockPlugin);
24
+ function VirtualBlockPlugin(kernel, config) {
25
+ var _this;
26
+ _classCallCheck(this, VirtualBlockPlugin);
27
+ _this = _super.call(this);
28
+ _this.kernel = kernel;
29
+ kernel.registerThemes({
30
+ virtualBlock: (config === null || config === void 0 ? void 0 : config.theme) || ''
31
+ });
32
+ return _this;
33
+ }
34
+ _createClass(VirtualBlockPlugin, [{
35
+ key: "onInit",
36
+ value: function onInit(editor) {
37
+ this.register(registerRichKeydown(editor, this.kernel));
38
+ }
39
+ }]);
40
+ return VirtualBlockPlugin;
41
+ }(KernelPlugin), _defineProperty(_class, "pluginName", 'VirtualBlockPlugin'), _class);
@@ -0,0 +1,6 @@
1
+ import { ElementNode, LexicalEditor, LexicalNode, PointType } from 'lexical';
2
+ import { IEditor } from "../../../types";
3
+ export declare function toRootElement(node: LexicalNode): ElementNode;
4
+ export declare function $getAdjacentNode(focus: PointType, isBackward: boolean): null | LexicalNode;
5
+ export declare function $getDownUpNode(focus: PointType, isUp: boolean): null | LexicalNode;
6
+ export declare function registerRichKeydown(editor: LexicalEditor, kernel: IEditor): () => void;
@@ -0,0 +1,274 @@
1
+ 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
+ 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); }
3
+ 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; }
4
+ import { $isCodeHighlightNode, $isCodeNode } from '@lexical/code';
5
+ import { mergeRegister } from '@lexical/utils';
6
+ import { $createParagraphNode, $getNodeByKey, $getRoot, $getSelection, $isDecoratorNode, $isLineBreakNode, $isNodeSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, COMMAND_PRIORITY_NORMAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, ParagraphNode } from 'lexical';
7
+ import { $closest } from "../../../editor-kernel";
8
+ import { SELECT_AFTER_CODEMIRROR_COMMAND, SELECT_BEFORE_CODEMIRROR_COMMAND } from "../../codemirror-block";
9
+ import { createDebugLogger } from "../../../utils/debug";
10
+ var logger = createDebugLogger('plugin', 'virtual-block');
11
+ function resolveElement(element, isBackward, focusOffset) {
12
+ var parent = element.getParent();
13
+ var offset = focusOffset;
14
+ var block = element;
15
+ if (parent !== null) {
16
+ if (isBackward && focusOffset === 0) {
17
+ offset = block.getIndexWithinParent();
18
+ block = parent;
19
+ } else if (!isBackward && focusOffset === block.getChildrenSize()) {
20
+ offset = block.getIndexWithinParent() + 1;
21
+ block = parent;
22
+ }
23
+ }
24
+ return block.getChildAtIndex(isBackward ? offset - 1 : offset);
25
+ }
26
+ function isCodeNodeLastLine(focusNode) {
27
+ if (!$isCodeHighlightNode(focusNode)) {
28
+ return false;
29
+ }
30
+ var codeNode = focusNode.getParent();
31
+ if (!$isCodeNode(codeNode)) {
32
+ return false;
33
+ }
34
+ var last = codeNode.getLastChild();
35
+ do {
36
+ var _last;
37
+ if ($isLineBreakNode(last)) {
38
+ return false;
39
+ }
40
+ if (last === focusNode) {
41
+ return codeNode;
42
+ }
43
+ last = (_last = last) === null || _last === void 0 ? void 0 : _last.getPreviousSibling();
44
+ } while (last !== focusNode && last);
45
+ if (last === focusNode) {
46
+ return codeNode;
47
+ }
48
+ return false;
49
+ }
50
+ export function toRootElement(node) {
51
+ var currentNode = node;
52
+ var parent = currentNode.getParent();
53
+ while (parent !== null && !$isRootOrShadowRoot(parent)) {
54
+ currentNode = parent;
55
+ parent = currentNode.getParent();
56
+ }
57
+ return currentNode;
58
+ }
59
+ export function $getAdjacentNode(focus, isBackward) {
60
+ var focusOffset = focus.offset;
61
+ if (focus.type === 'element') {
62
+ var block = focus.getNode();
63
+ return resolveElement(block, isBackward, focusOffset);
64
+ } else {
65
+ var focusNode = focus.getNode();
66
+ if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
67
+ var possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
68
+ if (possibleNode === null) {
69
+ return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
70
+ }
71
+ return possibleNode;
72
+ } else if (!isBackward && isCodeNodeLastLine(focusNode)) {
73
+ var _focusNode$getParent;
74
+ return ((_focusNode$getParent = focusNode.getParent()) === null || _focusNode$getParent === void 0 ? void 0 : _focusNode$getParent.getNextSibling()) || null;
75
+ }
76
+ }
77
+ return null;
78
+ }
79
+ export function $getDownUpNode(focus, isUp) {
80
+ var focusNode = focus.getNode();
81
+ var blockParent = focusNode;
82
+ while (blockParent !== null && blockParent.isInline()) {
83
+ blockParent = blockParent.getParent();
84
+ }
85
+ if (!blockParent) {
86
+ return null;
87
+ }
88
+ var nextNode = isUp ? blockParent.getPreviousSibling() : blockParent.getNextSibling();
89
+ while (!nextNode && !$isRootOrShadowRoot(blockParent)) {
90
+ blockParent = blockParent.getParent();
91
+ if (!blockParent) {
92
+ return null;
93
+ }
94
+ nextNode = isUp ? blockParent.getPreviousSibling() : blockParent.getNextSibling();
95
+ }
96
+ if (!nextNode) {
97
+ return null;
98
+ }
99
+ return nextNode;
100
+ }
101
+ function $isEmptyNode(node) {
102
+ if (node.getChildrenSize() === 0) {
103
+ return true;
104
+ }
105
+ var _iterator = _createForOfIteratorHelper(node.getChildren()),
106
+ _step;
107
+ try {
108
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
109
+ var child = _step.value;
110
+ if ($isTextNode(child)) {
111
+ if (child.getTextContent().trim().length > 0) {
112
+ return false;
113
+ }
114
+ } else if (!$isEmptyNode(child)) {
115
+ return false;
116
+ }
117
+ }
118
+ } catch (err) {
119
+ _iterator.e(err);
120
+ } finally {
121
+ _iterator.f();
122
+ }
123
+ return true;
124
+ }
125
+ export function registerRichKeydown(editor, kernel) {
126
+ var needRemoveOnFocusNode = null;
127
+ return mergeRegister(editor.registerUpdateListener(function (payload) {
128
+ var mutatedNodes = payload.mutatedNodes;
129
+ if (needRemoveOnFocusNode) {
130
+ var _mutatedNodes$get;
131
+ if ((mutatedNodes === null || mutatedNodes === void 0 || (_mutatedNodes$get = mutatedNodes.get(ParagraphNode)) === null || _mutatedNodes$get === void 0 ? void 0 : _mutatedNodes$get.get(needRemoveOnFocusNode.getKey())) === 'destroyed') {
132
+ console.info('Virtual block node was removed externally', needRemoveOnFocusNode);
133
+ needRemoveOnFocusNode = null;
134
+ return;
135
+ }
136
+ editor.update(function () {
137
+ try {
138
+ var selection = $getSelection();
139
+ if ($isRangeSelection(selection)) {
140
+ var focusNode = selection.focus.getNode();
141
+ if (needRemoveOnFocusNode && !$closest(focusNode, function (node) {
142
+ return node === needRemoveOnFocusNode;
143
+ })) {
144
+ if ($isEmptyNode(needRemoveOnFocusNode)) {
145
+ var _needRemoveOnFocusNod;
146
+ logger.info('Removing virtual block node after focus moved away', needRemoveOnFocusNode);
147
+ (_needRemoveOnFocusNod = needRemoveOnFocusNode) === null || _needRemoveOnFocusNod === void 0 || _needRemoveOnFocusNod.remove();
148
+ needRemoveOnFocusNode = null;
149
+ } else {
150
+ needRemoveOnFocusNode = null;
151
+ }
152
+ return;
153
+ }
154
+ } else if ($isNodeSelection(selection) && needRemoveOnFocusNode) {
155
+ if ($isEmptyNode(needRemoveOnFocusNode)) {
156
+ var _needRemoveOnFocusNod2;
157
+ (_needRemoveOnFocusNod2 = needRemoveOnFocusNode) === null || _needRemoveOnFocusNod2 === void 0 || _needRemoveOnFocusNod2.remove();
158
+ needRemoveOnFocusNode = null;
159
+ } else {
160
+ needRemoveOnFocusNode = null;
161
+ }
162
+ return;
163
+ }
164
+ } catch (error) {
165
+ console.error('Error during virtual block cleanup', error);
166
+ }
167
+ });
168
+ }
169
+ }), kernel.registerHighCommand(KEY_ARROW_UP_COMMAND, function (event) {
170
+ var selection = $getSelection();
171
+ if (event.shiftKey) {
172
+ return false;
173
+ }
174
+ if ($isNodeSelection(selection)) {
175
+ // If selection is on a node, let's try and move selection
176
+ // back to being a range selection.
177
+ var nodes = selection.getNodes();
178
+ if (nodes.length > 0) {
179
+ var elementNode = toRootElement(nodes[0]);
180
+ event.preventDefault();
181
+ var p = $createParagraphNode();
182
+ needRemoveOnFocusNode = p;
183
+ elementNode.insertBefore(p);
184
+ p.selectEnd();
185
+ return true;
186
+ }
187
+ } else if ($isRangeSelection(selection)) {
188
+ var possibleNode = toRootElement(selection.focus.getNode());
189
+ if (possibleNode === needRemoveOnFocusNode || $isEmptyNode(possibleNode)) {
190
+ return false;
191
+ }
192
+ if ($getRoot().getFirstChild() === possibleNode) {
193
+ event.preventDefault();
194
+ var _p = $createParagraphNode();
195
+ possibleNode.insertBefore(_p);
196
+ needRemoveOnFocusNode = _p;
197
+ _p.selectStart();
198
+ return true;
199
+ } else if ($isDecoratorNode(possibleNode.getPreviousSibling())) {
200
+ event.preventDefault();
201
+ var _p2 = $createParagraphNode();
202
+ possibleNode.insertBefore(_p2);
203
+ needRemoveOnFocusNode = _p2;
204
+ _p2.selectStart();
205
+ return true;
206
+ }
207
+ }
208
+ return false;
209
+ }, COMMAND_PRIORITY_NORMAL), kernel.registerHighCommand(KEY_ARROW_DOWN_COMMAND, function (event) {
210
+ var selection = $getSelection();
211
+ if ($isNodeSelection(selection)) {
212
+ // If selection is on a node, let's try and move selection
213
+ // back to being a range selection.
214
+ var nodes = selection.getNodes();
215
+ if (nodes.length > 0) {
216
+ var node = nodes[0];
217
+ var blockNode = toRootElement(node);
218
+ event.preventDefault();
219
+ var p = $createParagraphNode();
220
+ needRemoveOnFocusNode = p;
221
+ blockNode.insertAfter(p);
222
+ p.selectStart();
223
+ return true;
224
+ }
225
+ } else if ($isRangeSelection(selection)) {
226
+ if (!selection.isCollapsed()) {
227
+ return false;
228
+ }
229
+ var focusNode = selection.focus.getNode();
230
+ var possibleNode = toRootElement(focusNode);
231
+ if (possibleNode === needRemoveOnFocusNode || $isEmptyNode(possibleNode)) {
232
+ return false;
233
+ }
234
+ var root = $getRoot();
235
+ if (root.getLastChild() === possibleNode) {
236
+ event.preventDefault();
237
+ var _p3 = $createParagraphNode();
238
+ possibleNode.insertAfter(_p3);
239
+ needRemoveOnFocusNode = _p3;
240
+ _p3.selectStart();
241
+ }
242
+ return true;
243
+ }
244
+ return false;
245
+ }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(SELECT_BEFORE_CODEMIRROR_COMMAND, function (payload) {
246
+ editor.update(function () {
247
+ var node = $getNodeByKey(payload.key);
248
+ if (!node) {
249
+ return;
250
+ }
251
+ var p = $createParagraphNode();
252
+ needRemoveOnFocusNode = p;
253
+ node.insertBefore(p);
254
+ p.selectEnd();
255
+ editor.focus();
256
+ return true;
257
+ });
258
+ return true;
259
+ }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(SELECT_AFTER_CODEMIRROR_COMMAND, function (payload) {
260
+ editor.update(function () {
261
+ var node = $getNodeByKey(payload.key);
262
+ if (!node) {
263
+ return;
264
+ }
265
+ var p = $createParagraphNode();
266
+ needRemoveOnFocusNode = p;
267
+ node.insertAfter(p);
268
+ p.selectEnd();
269
+ editor.focus();
270
+ return true;
271
+ });
272
+ return true;
273
+ }, COMMAND_PRIORITY_NORMAL));
274
+ }
@@ -0,0 +1,3 @@
1
+ import { type FC } from 'react';
2
+ declare const ReactVirtualBlockPlugin: FC;
3
+ export default ReactVirtualBlockPlugin;
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ 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."); }
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); }
6
+ 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; }
7
+ 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; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ import { useLayoutEffect } from 'react';
10
+ import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
11
+ import { VirtualBlockPlugin } from "../plugin";
12
+ var ReactVirtualBlockPlugin = function ReactVirtualBlockPlugin() {
13
+ var _useLexicalComposerCo = useLexicalComposerContext(),
14
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
15
+ editor = _useLexicalComposerCo2[0];
16
+ useLayoutEffect(function () {
17
+ editor.registerPlugin(VirtualBlockPlugin);
18
+ }, []);
19
+ return null;
20
+ };
21
+ ReactVirtualBlockPlugin.displayName = 'ReactVirtualBlockPlugin';
22
+ export default ReactVirtualBlockPlugin;
@@ -0,0 +1 @@
1
+ export { default as ReactVirtualBlockPlugin } from './ReactVirtualBlock';
@@ -0,0 +1 @@
1
+ export { default as ReactVirtualBlockPlugin } from "./ReactVirtualBlock";
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "3.10.0",
3
+ "version": "3.12.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",