@lobehub/editor 1.21.0 → 1.21.2

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.
@@ -1,8 +1,7 @@
1
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
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
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 { $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
5
- import { $createCursorNode } from "../../common/node/cursor";
4
+ import { $createTextNode, $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
6
5
  import { $createLinkHighlightNode, $isLinkHighlightNode, getLinkHighlightNode } from "../node/link-highlight";
7
6
  export var INSERT_LINK_HIGHLIGHT_COMMAND = createCommand('INSERT_LINK_HIGHLIGHT_COMMAND');
8
7
  export function registerLinkHighlightCommand(editor) {
@@ -37,8 +36,11 @@ export function registerLinkHighlightCommand(editor) {
37
36
  }
38
37
 
39
38
  // Create link highlight with selected text
40
- var linkHighlightNode = $createLinkHighlightNode(selection.getTextContent());
41
- $insertNodes([linkHighlightNode, $createCursorNode()]);
39
+ var selectedText = selection.getTextContent();
40
+ var linkHighlightNode = $createLinkHighlightNode();
41
+ var textNode = $createTextNode(selectedText);
42
+ linkHighlightNode.append(textNode);
43
+ $insertNodes([linkHighlightNode]);
42
44
  linkHighlightNode.select();
43
45
  });
44
46
  return true;
@@ -1,29 +1,25 @@
1
- import { EditorConfig, LexicalEditor, LexicalNode, SerializedElementNode } from 'lexical';
2
- import { CardLikeElementNode } from "../../common/node/cursor";
1
+ import { EditorConfig, ElementNode, LexicalEditor, LexicalNode, SerializedElementNode } from 'lexical';
3
2
  export type SerializedLinkHighlightNode = SerializedElementNode;
4
- export declare class LinkHighlightNode extends CardLikeElementNode {
3
+ export declare class LinkHighlightNode extends ElementNode {
5
4
  static getType(): string;
6
5
  static clone(node: LinkHighlightNode): LinkHighlightNode;
7
6
  static importJSON(serializedNode: SerializedLinkHighlightNode): LinkHighlightNode;
8
- createDOM(config: EditorConfig, editor: LexicalEditor): HTMLElement;
7
+ createDOM(config: EditorConfig): HTMLElement;
9
8
  /**
10
9
  * Format URL to ensure it has proper protocol
11
10
  */
12
11
  private formatUrl;
13
- getDOMSlot(element: HTMLElement): import("lexical").ElementDOMSlot<HTMLElement>;
14
- canBeEmpty(): boolean;
15
- isCardLike(): boolean;
16
- isInline(): boolean;
17
- canIndent(): boolean;
18
- canInsertTextBefore(): boolean;
19
- canInsertTextAfter(): boolean;
12
+ canBeEmpty(): false;
13
+ isInline(): true;
14
+ canInsertTextBefore(): false;
15
+ canInsertTextAfter(): false;
20
16
  updateDOM(prevNode: LinkHighlightNode, dom: HTMLElement, config: EditorConfig): boolean;
21
17
  /**
22
18
  * Get the URL from the text content
23
19
  */
24
20
  getURL(): string;
25
21
  }
26
- export declare function $createLinkHighlightNode(textContent?: string): LinkHighlightNode;
22
+ export declare function $createLinkHighlightNode(): LinkHighlightNode;
27
23
  export declare function $isLinkHighlightNode(node: unknown): node is LinkHighlightNode;
28
- export declare function getLinkHighlightNode(node: LexicalNode): LexicalNode | null;
24
+ export declare function getLinkHighlightNode(node: LexicalNode): LinkHighlightNode | null;
29
25
  export declare function $isSelectionInLinkHighlight(editor: LexicalEditor): boolean;
@@ -4,8 +4,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
4
4
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
8
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
9
7
  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); }
10
8
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
9
  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); }; }
@@ -15,10 +13,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
15
13
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
14
  /* eslint-disable @typescript-eslint/no-use-before-define */
17
15
  import { addClassNamesToElement } from '@lexical/utils';
18
- import { $applyNodeReplacement, $createTextNode, $getSelection, $isNodeSelection, $isRangeSelection } from 'lexical';
19
- import { $createCursorNode, $isCursorNode, CardLikeElementNode } from "../../common/node/cursor";
20
- export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
21
- _inherits(LinkHighlightNode, _CardLikeElementNode);
16
+ import { $applyNodeReplacement, $getSelection, $isNodeSelection, $isRangeSelection, ElementNode } from 'lexical';
17
+ export var LinkHighlightNode = /*#__PURE__*/function (_ElementNode) {
18
+ _inherits(LinkHighlightNode, _ElementNode);
22
19
  var _super = _createSuper(LinkHighlightNode);
23
20
  function LinkHighlightNode() {
24
21
  _classCallCheck(this, LinkHighlightNode);
@@ -26,33 +23,17 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
26
23
  }
27
24
  _createClass(LinkHighlightNode, [{
28
25
  key: "createDOM",
29
- value: function createDOM(config, editor) {
30
- var _this = this;
31
- var element = document.createElement('span');
32
- // eslint-disable-next-line unicorn/prefer-dom-node-dataset
33
- element.setAttribute('data-lexical-key', this.getKey());
34
- var childContainer = document.createElement('ne-content');
35
- element.append(childContainer);
36
- addClassNamesToElement(element, config.theme.linkHighlight);
37
-
38
- // Add click handler to open link in new window
39
- element.addEventListener('click', function (event) {
40
- // Only handle left click without modifier keys
41
- if (event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey) {
42
- event.preventDefault();
43
- event.stopPropagation();
26
+ value: function createDOM(config) {
27
+ var element = document.createElement('a');
44
28
 
45
- // Read URL in editor context
46
- editor.read(function () {
47
- var url = _this.getURL();
48
- if (url) {
49
- // Format URL to ensure it has proper protocol
50
- var formattedUrl = _this.formatUrl(url);
51
- window.open(formattedUrl, '_blank', 'noopener,noreferrer');
52
- }
53
- });
54
- }
55
- });
29
+ // Set link attributes
30
+ var url = this.getURL();
31
+ if (url) {
32
+ element.href = this.formatUrl(url);
33
+ }
34
+ element.setAttribute('target', '_blank');
35
+ element.setAttribute('rel', 'noopener noreferrer');
36
+ addClassNamesToElement(element, config.theme.linkHighlight);
56
37
  return element;
57
38
  }
58
39
 
@@ -88,44 +69,25 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
88
69
  }
89
70
  return url;
90
71
  }
91
- }, {
92
- key: "getDOMSlot",
93
- value: function getDOMSlot(element) {
94
- var neContent = element.querySelector('ne-content');
95
- if (!neContent) {
96
- throw new Error('LinkHighlightNode: ne-content not found');
97
- }
98
- return _get(_getPrototypeOf(LinkHighlightNode.prototype), "getDOMSlot", this).call(this, element).withElement(neContent);
99
- }
100
72
  }, {
101
73
  key: "canBeEmpty",
102
74
  value: function canBeEmpty() {
103
75
  return false;
104
76
  }
105
- }, {
106
- key: "isCardLike",
107
- value: function isCardLike() {
108
- return true;
109
- }
110
77
  }, {
111
78
  key: "isInline",
112
79
  value: function isInline() {
113
80
  return true;
114
81
  }
115
- }, {
116
- key: "canIndent",
117
- value: function canIndent() {
118
- return false;
119
- }
120
82
  }, {
121
83
  key: "canInsertTextBefore",
122
84
  value: function canInsertTextBefore() {
123
- return true;
85
+ return false;
124
86
  }
125
87
  }, {
126
88
  key: "canInsertTextAfter",
127
89
  value: function canInsertTextAfter() {
128
- return true;
90
+ return false;
129
91
  }
130
92
  }, {
131
93
  key: "updateDOM",
@@ -135,6 +97,16 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
135
97
  if (prevTheme !== this) {
136
98
  addClassNamesToElement(dom, config.theme.linkHighlight);
137
99
  }
100
+
101
+ // Update href attribute if it's an anchor element
102
+ if (dom instanceof HTMLAnchorElement) {
103
+ var url = this.getURL();
104
+ if (url) {
105
+ dom.href = this.formatUrl(url);
106
+ } else {
107
+ dom.removeAttribute('href');
108
+ }
109
+ }
138
110
  return false;
139
111
  }
140
112
 
@@ -163,35 +135,20 @@ export var LinkHighlightNode = /*#__PURE__*/function (_CardLikeElementNode) {
163
135
  }
164
136
  }]);
165
137
  return LinkHighlightNode;
166
- }(CardLikeElementNode);
167
- export function $createLinkHighlightNode(textContent) {
168
- var linkHighlightNode = $applyNodeReplacement(new LinkHighlightNode());
169
- var cursorNode = $createCursorNode();
170
- linkHighlightNode.append(cursorNode);
171
- if (textContent) {
172
- linkHighlightNode.append($createTextNode(textContent));
173
- }
174
- return linkHighlightNode;
138
+ }(ElementNode);
139
+ export function $createLinkHighlightNode() {
140
+ return $applyNodeReplacement(new LinkHighlightNode());
175
141
  }
176
142
  export function $isLinkHighlightNode(node) {
177
143
  return node instanceof LinkHighlightNode;
178
144
  }
179
145
  export function getLinkHighlightNode(node) {
180
- if ($isCursorNode(node)) {
181
- var parent = node.getParent();
182
- if ($isLinkHighlightNode(parent)) {
183
- return parent;
184
- }
185
- if ($isLinkHighlightNode(node.getNextSibling())) {
186
- return node.getNextSibling();
187
- }
188
- if ($isLinkHighlightNode(node.getPreviousSibling())) {
189
- return node.getPreviousSibling();
190
- }
191
- return null;
146
+ if ($isLinkHighlightNode(node)) {
147
+ return node;
192
148
  }
193
- if ($isLinkHighlightNode(node.getParent())) {
194
- return node.getParent();
149
+ var parent = node.getParent();
150
+ if ($isLinkHighlightNode(parent)) {
151
+ return parent;
195
152
  }
196
153
  return null;
197
154
  }
@@ -204,19 +161,15 @@ export function $isSelectionInLinkHighlight(editor) {
204
161
  if ($isRangeSelection(selection)) {
205
162
  var focusNode = selection.focus.getNode();
206
163
  var anchorNode = selection.anchor.getNode();
207
- var linkHighlight = getLinkHighlightNode(focusNode);
208
- if (linkHighlight !== getLinkHighlightNode(anchorNode)) {
209
- return false;
210
- }
211
- if ($isLinkHighlightNode(linkHighlight)) {
212
- return true;
213
- }
214
- return false;
215
- } else if ($isNodeSelection(selection)) {
164
+ var focusLinkHighlight = getLinkHighlightNode(focusNode);
165
+ var anchorLinkHighlight = getLinkHighlightNode(anchorNode);
166
+
167
+ // Both nodes should be in the same link-highlight node
168
+ return focusLinkHighlight !== null && anchorLinkHighlight !== null && focusLinkHighlight === anchorLinkHighlight;
169
+ }
170
+ if ($isNodeSelection(selection)) {
216
171
  var nodes = selection.getNodes();
217
- if (nodes.length === 1 && $isLinkHighlightNode(nodes[0])) {
218
- return true;
219
- }
172
+ return nodes.length === 1 && $isLinkHighlightNode(nodes[0]);
220
173
  }
221
174
  return false;
222
175
  });
@@ -19,10 +19,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
19
19
  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; }
20
20
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
21
21
  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); }
22
- import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical';
22
+ import { $createTextNode, $getSelection, $isRangeSelection, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical';
23
23
  import { INodeHelper } from "../../../editor-kernel/inode/helper";
24
24
  import { KernelPlugin } from "../../../editor-kernel/plugin";
25
- import { $createCursorNode, cursorNodeSerialized } from "../../common/node/cursor";
26
25
  import { IMarkdownShortCutService, MARKDOWN_READER_LEVEL_HIGH } from "../../markdown/service/shortcut";
27
26
  import { createDebugLogger } from "../../../utils/debug";
28
27
  import { registerLinkHighlightCommand } from "../command";
@@ -77,9 +76,10 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
77
76
  editor.update(function () {
78
77
  var selection = $getSelection();
79
78
  if ($isRangeSelection(selection)) {
80
- var linkHighlightNode = $createLinkHighlightNode(data);
81
- var cursorNode = $createCursorNode();
82
- selection.insertNodes([linkHighlightNode, cursorNode]);
79
+ var linkHighlightNode = $createLinkHighlightNode();
80
+ var textNode = $createTextNode(data);
81
+ linkHighlightNode.append(textNode);
82
+ selection.insertNodes([linkHighlightNode]);
83
83
  }
84
84
  });
85
85
  return true;
@@ -95,7 +95,7 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
95
95
 
96
96
  // Register markdown writer for <link> format
97
97
  markdownService.registerMarkdownWriter(LinkHighlightNode.getType(), function (ctx, node) {
98
- ctx.appendLine("<".concat(node.getTextContent(), ">"));
98
+ ctx.appendLine(node.getTextContent());
99
99
  return true;
100
100
  });
101
101
 
@@ -110,10 +110,10 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
110
110
  return;
111
111
  }
112
112
  _this2.logger.debug('Converting markdown auto-link to LinkHighlightNode:', url);
113
- var linkHighlightNode = $createLinkHighlightNode(url);
114
- var cursorNode = $createCursorNode();
113
+ var linkHighlightNode = $createLinkHighlightNode();
114
+ var textNodeContent = $createTextNode(url);
115
+ linkHighlightNode.append(textNodeContent);
115
116
  textNode.replace(linkHighlightNode);
116
- linkHighlightNode.insertAfter(cursorNode);
117
117
  return undefined;
118
118
  },
119
119
  trigger: '>',
@@ -129,14 +129,14 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
129
129
  if (match) {
130
130
  var url = match[1].replaceAll(/[\u200B-\u200D\u2060\uFEFF]/g, '');
131
131
  _this2.logger.debug('Converting HTML auto-link to LinkHighlightNode:', url);
132
- return [INodeHelper.createElementNode('linkHighlight', {
133
- children: [cursorNodeSerialized, INodeHelper.createTextNode(url, {})],
132
+ return INodeHelper.createElementNode('linkHighlight', {
133
+ children: [INodeHelper.createTextNode(url, {})],
134
134
  direction: 'ltr',
135
135
  format: '',
136
136
  indent: 0,
137
137
  type: 'linkHighlight',
138
138
  version: 1
139
- }), cursorNodeSerialized];
139
+ });
140
140
  }
141
141
 
142
142
  // Not an auto-link, let other handlers process it
@@ -164,16 +164,14 @@ export var LinkHighlightPlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
164
164
  // If text matches URL exactly (auto-link syntax), convert to LinkHighlightNode
165
165
  if (textContent === url) {
166
166
  _this2.logger.debug('Converting markdown auto-link to LinkHighlightNode:', url);
167
- // Return array with LinkHighlightNode and trailing cursor
168
- // Structure matches CodeNode: [node with internal cursor + text, external cursor]
169
- return [INodeHelper.createElementNode('linkHighlight', {
170
- children: [cursorNodeSerialized, INodeHelper.createTextNode(url, {})],
167
+ return INodeHelper.createElementNode('linkHighlight', {
168
+ children: [INodeHelper.createTextNode(url, {})],
171
169
  direction: 'ltr',
172
170
  format: '',
173
171
  indent: 0,
174
172
  type: 'linkHighlight',
175
173
  version: 1
176
- }), cursorNodeSerialized];
174
+ });
177
175
  }
178
176
 
179
177
  // Otherwise, let standard Link plugin handle it
@@ -2,9 +2,8 @@ var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
- var css = _ref.css,
6
- token = _ref.token;
5
+ var css = _ref.css;
7
6
  return {
8
- linkHighlight: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n display: inline;\n\n padding: 2px;\n\n color: ", ";\n text-decoration: none;\n\n transition: all 0.2s ease;\n\n &:hover {\n color: ", ";\n text-decoration: underline;\n }\n\n ne-content {\n display: inline;\n }\n "])), token.colorLink, token.colorLinkHover)
7
+ linkHighlight: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: unset;\n\n margin-block: 1em;\n margin-inline: 0;\n padding: 2px;\n border: none;\n "])))
9
8
  };
10
9
  });
@@ -13,17 +13,15 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
13
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
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
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 { $createCodeNode, $isCodeHighlightNode, $isCodeNode } from '@lexical/code';
16
+ import { $isCodeNode } from '@lexical/code';
17
17
  import { $getNodeByKey, $getSelection, $isRangeSelection, $isTextNode, COLLABORATION_TAG, COMMAND_PRIORITY_CRITICAL, HISTORIC_TAG, KEY_ENTER_COMMAND, PASTE_COMMAND } from 'lexical';
18
18
  import { KernelPlugin } from "../../../editor-kernel/plugin";
19
- import { $isCodeInlineNode } from "../../code/node/code";
20
19
  import { createDebugLogger } from "../../../utils/debug";
21
20
  import { registerMarkdownCommand } from "../command";
22
21
  import MarkdownDataSource from "../data-source/markdown-data-source";
23
22
  import { IMarkdownShortCutService, MarkdownShortCutService } from "../service/shortcut";
24
23
  import { canContainTransformableMarkdown } from "../utils";
25
24
  import { detectCodeLanguage, detectLanguage } from "../utils/detectLanguage";
26
- import { isValidUrl as isValidLinkUrl } from "../utils/url-validator";
27
25
  export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
28
26
  _inherits(MarkdownPlugin, _KernelPlugin);
29
27
  var _super = _createSuper(MarkdownPlugin);
@@ -122,7 +120,6 @@ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
122
120
  return false;
123
121
  }, COMMAND_PRIORITY_CRITICAL));
124
122
  this.register(editor.registerCommand(PASTE_COMMAND, function (event) {
125
- var _this2$config$enableP, _this2$config;
126
123
  if (!(event instanceof ClipboardEvent)) return false;
127
124
  var clipboardData = event.clipboardData;
128
125
  if (!clipboardData) return false;
@@ -142,107 +139,6 @@ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
142
139
  textLength: text.length
143
140
  });
144
141
 
145
- // Check if the pasted content is a pure URL
146
- // If so, let Link/LinkHighlight plugins handle it
147
- if (clipboardData.types.length === 1 && clipboardData.types[0] === 'text/plain' && isValidLinkUrl(text)) {
148
- _this2.logger.debug('pure URL detected, letting Link/LinkHighlight plugins handle');
149
- return false; // Let other plugins handle URL paste
150
- }
151
-
152
- // Check if cursor is inside code block or inline code
153
- // If so, always paste as plain text
154
- var isInCodeBlock = editor.read(function () {
155
- var selection = $getSelection();
156
- if (!$isRangeSelection(selection)) return false;
157
- var anchorNode = selection.anchor.getNode();
158
- var focusNode = selection.focus.getNode();
159
-
160
- // Check if in code block (CodeNode or CodeHighlightNode)
161
- var anchorParent = anchorNode.getParent();
162
- var focusParent = focusNode.getParent();
163
- if ($isCodeNode(anchorNode) || $isCodeNode(focusNode)) {
164
- return true;
165
- }
166
- if ($isCodeNode(anchorParent) || $isCodeNode(focusParent)) {
167
- return true;
168
- }
169
- if ($isCodeHighlightNode(anchorNode) || $isCodeHighlightNode(focusNode)) {
170
- return true;
171
- }
172
-
173
- // Check if in inline code
174
- if ($isCodeInlineNode(anchorNode) || $isCodeInlineNode(focusNode)) {
175
- return true;
176
- }
177
- if ($isCodeInlineNode(anchorParent) || $isCodeInlineNode(focusParent)) {
178
- return true;
179
- }
180
- return false;
181
- });
182
- if (isInCodeBlock) {
183
- _this2.logger.debug('cursor in code block, pasting as plain text');
184
- event.preventDefault();
185
- event.stopPropagation();
186
- editor.update(function () {
187
- var selection = $getSelection();
188
- if (!$isRangeSelection(selection)) return;
189
- selection.insertText(text);
190
- });
191
- return true;
192
- }
193
- var enablePasteMarkdown = (_this2$config$enableP = (_this2$config = _this2.config) === null || _this2$config === void 0 ? void 0 : _this2$config.enablePasteMarkdown) !== null && _this2$config$enableP !== void 0 ? _this2$config$enableP : true;
194
-
195
- // If markdown formatting is disabled, we're done
196
- if (!enablePasteMarkdown) {
197
- // Force plain text paste for external content
198
- event.preventDefault();
199
- event.stopPropagation();
200
- editor.update(function () {
201
- var selection = $getSelection();
202
- if (!$isRangeSelection(selection)) return;
203
-
204
- // Insert plain text
205
- selection.insertText(text);
206
- });
207
- _this2.logger.debug('markdown formatting disabled, plain text inserted');
208
- return true;
209
- }
210
-
211
- // Check if this is likely a rich-text paste from the editor or other rich editor
212
- // Rich text pastes typically have HTML that's more complex than just wrapping text
213
- if (clipboardData.types.includes('application/x-lexical-editor')) {
214
- _this2.logger.debug('rich content detected, letting Lexical handle paste');
215
- return false;
216
- }
217
-
218
- // Check if markdown paste formatting is enabled (default: true)
219
- // Note: URL pasting is handled by Link/LinkHighlight plugins themselves
220
-
221
- // Check if content is code (JSON, SQL, etc.) and should be inserted as code block
222
- var codeInfo = _this2.detectCodeContent(text);
223
- if (codeInfo) {
224
- // Code detected - insert as code block
225
- _this2.logger.debug("code detected (".concat(codeInfo.language, "), inserting as code block"));
226
- event.preventDefault();
227
- event.stopPropagation();
228
- editor.update(function () {
229
- var selection = $getSelection();
230
- if (!$isRangeSelection(selection)) return;
231
-
232
- // Create code block node with detected language
233
- var codeNode = $createCodeNode(codeInfo.language);
234
- selection.insertNodes([codeNode]);
235
-
236
- // Insert the code text into the code block
237
- codeNode.select();
238
- var codeSelection = $getSelection();
239
- if ($isRangeSelection(codeSelection)) {
240
- codeSelection.insertText(text);
241
- }
242
- });
243
- return true; // Command handled
244
- }
245
-
246
142
  // Check if the pasted plain text contains markdown patterns
247
143
  var hasMarkdownContent = _this2.detectMarkdownContent(text);
248
144
  if (hasMarkdownContent) {
@@ -258,48 +154,7 @@ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
258
154
  // No markdown detected - plain text is already inserted
259
155
  _this2.logger.debug('no markdown patterns detected, keeping as plain text');
260
156
  }
261
-
262
- // word 一类富文本编辑器会同时包含 text/html 和 text/rtf 类型的内容
263
- // if (
264
- // clipboardData.types.includes('text/html') &&
265
- // clipboardData.types.includes('text/rtf')
266
- // ) {
267
- // // Code detected - insert as code block
268
- // this.logger.debug(`code like, inserting as code block`);
269
- //
270
- // event.preventDefault();
271
- // event.stopPropagation();
272
- //
273
- // editor.update(() => {
274
- // const selection = $getSelection();
275
- // if (!$isRangeSelection(selection)) return;
276
- //
277
- // // Create code block node with detected language
278
- // const codeNode = $createCodeNode('plaintext');
279
- // selection.insertNodes([codeNode]);
280
- //
281
- // // Insert the code text into the code block
282
- // codeNode.select();
283
- // const codeSelection = $getSelection();
284
- // if ($isRangeSelection(codeSelection)) {
285
- // codeSelection.insertText(text);
286
- // }
287
- // });
288
- //
289
- // return true; // Command handled
290
- // }
291
-
292
- // Force plain text paste for external content
293
- event.preventDefault();
294
- event.stopPropagation();
295
- editor.update(function () {
296
- var selection = $getSelection();
297
- if (!$isRangeSelection(selection)) return;
298
-
299
- // Insert plain text
300
- selection.insertText(text);
301
- });
302
- return true; // Command handled
157
+ return false;
303
158
  }, COMMAND_PRIORITY_CRITICAL));
304
159
  this.register(registerMarkdownCommand(editor, this.service));
305
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.21.0",
3
+ "version": "1.21.2",
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",