@lobehub/editor 3.10.0 → 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.
@@ -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;
@@ -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.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",