@lobehub/editor 1.21.1 → 1.21.3

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.
@@ -182,7 +182,8 @@ export var ListPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
182
182
  version: 1
183
183
  });
184
184
  }
185
- throw new Error('ListItem node children must be paragraph or list node ' + v.type);
185
+ // keep node unchanged
186
+ return v;
186
187
  });
187
188
  });
188
189
  }
@@ -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.1",
3
+ "version": "1.21.3",
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",