@lobehub/editor 1.5.1 → 1.5.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.
@@ -20,6 +20,8 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
20
20
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
21
  import { mergeRegister } from '@lexical/utils';
22
22
  import { $createTextNode, $getNodeByKey, $getSelection, $isDecoratorNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_HIGH, DecoratorNode, ElementNode, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, TextNode } from 'lexical';
23
+ import { createDebugLogger } from "../../../utils/debug";
24
+ var logger = createDebugLogger('common', 'cursor');
23
25
  export var CardLikeElementNode = /*#__PURE__*/function (_ElementNode) {
24
26
  _inherits(CardLikeElementNode, _ElementNode);
25
27
  var _super = _createSuper(CardLikeElementNode);
@@ -87,7 +89,7 @@ export function registerCursorNode(editor) {
87
89
  key = _step2$value[0],
88
90
  mutation = _step2$value[1];
89
91
  var node = $getNodeByKey(key);
90
- console.info('DecoratorNode mutated', node, mutation);
92
+ logger.debug('🎭 DecoratorNode mutated:', node === null || node === void 0 ? void 0 : node.getType(), mutation, node);
91
93
  if (mutation === 'created' && node !== null && node !== void 0 && node.isInline() && node.getNextSibling() === null) {
92
94
  needAddCursor.push(node);
93
95
  }
@@ -237,7 +239,7 @@ export function registerCursorNode(editor) {
237
239
  $setSelection(sel);
238
240
  return true;
239
241
  } catch (error) {
240
- console.error(error);
242
+ logger.error('❌ Cursor selection error:', error);
241
243
  }
242
244
  } else if ($isCursorNode(focusNode)) {
243
245
  try {
@@ -255,7 +257,7 @@ export function registerCursorNode(editor) {
255
257
  $setSelection(_sel);
256
258
  return true;
257
259
  } catch (error) {
258
- console.error(error);
260
+ logger.error('❌ Cursor navigation error:', error);
259
261
  }
260
262
  }
261
263
  return false;
@@ -1,6 +1,8 @@
1
1
  import { $wrapNodeInElement } from '@lexical/utils';
2
2
  import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_HIGH, createCommand } from 'lexical';
3
+ import { createDebugLogger } from "../../../utils/debug";
3
4
  import { $createFileNode } from "../node/FileNode";
5
+ var logger = createDebugLogger('plugin', 'file');
4
6
  export var INSERT_FILE_COMMAND = createCommand('INSERT_FILE_COMMAND');
5
7
  export function registerFileCommand(editor, handleUpload) {
6
8
  return editor.registerCommand(INSERT_FILE_COMMAND, function (payload) {
@@ -16,7 +18,7 @@ export function registerFileCommand(editor, handleUpload) {
16
18
  fileNode.setUploaded(url.url);
17
19
  });
18
20
  }).catch(function (error) {
19
- console.error('File upload failed:', error);
21
+ logger.error('File upload failed:', error);
20
22
  editor.update(function () {
21
23
  fileNode.setError('File upload failed : ' + error.message);
22
24
  });
@@ -21,6 +21,7 @@ import { $createParagraphNode, $createRangeSelection, $insertNodes, $isRootOrSha
21
21
  import { KernelPlugin } from "../../../editor-kernel/plugin";
22
22
  import { IMarkdownShortCutService } from "../../markdown";
23
23
  import { IUploadService } from "../../upload";
24
+ import { createDebugLogger } from "../../../utils/debug";
24
25
  import { registerFileCommand } from "../command";
25
26
  import { $createFileNode, $isFileNode, FileNode } from "../node/FileNode";
26
27
  import { registerFileNodeSelectionObserver } from "../utils";
@@ -36,13 +37,14 @@ export var FilePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
36
37
  _classCallCheck(this, FilePlugin);
37
38
  _this = _super.call(this);
38
39
  // Register the file node
40
+ _defineProperty(_assertThisInitialized(_this), "logger", createDebugLogger('plugin', 'file'));
39
41
  _this.kernel = kernel;
40
42
  _this.config = config;
41
43
  kernel.registerNodes([FileNode]);
42
44
  if (config !== null && config !== void 0 && config.theme) {
43
45
  kernel.registerThemes(config === null || config === void 0 ? void 0 : config.theme);
44
46
  }
45
- kernel.registerDecorator(FileNode.getType(), function (node, editor) {
47
+ _this.registerDecorator(kernel, FileNode.getType(), function (node, editor) {
46
48
  return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
47
49
  });
48
50
  (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(FileNode.getType(), function (ctx, node) {
@@ -91,7 +93,7 @@ export var FilePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
91
93
  fileNode.setUploaded(url.url);
92
94
  });
93
95
  }).catch(function (error) {
94
- console.error('File upload failed:', error);
96
+ _this2.logger.error('File upload failed:', error);
95
97
  editor.update(function () {
96
98
  fileNode.setError('File upload failed : ' + error.message);
97
99
  });
@@ -34,7 +34,7 @@ export var HRPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
34
34
  kernel.registerThemes({
35
35
  hr: (config === null || config === void 0 ? void 0 : config.theme) || ''
36
36
  });
37
- kernel.registerDecorator('horizontalrule', function (node, editor) {
37
+ _this.registerDecorator(kernel, 'horizontalrule', function (node, editor) {
38
38
  return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
39
39
  });
40
40
  (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownShortCut({
@@ -1,6 +1,8 @@
1
1
  import { $wrapNodeInElement } from '@lexical/utils';
2
2
  import { $createParagraphNode, $createRangeSelection, $insertNodes, $isRootOrShadowRoot, $setSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
3
+ import { createDebugLogger } from "../../../utils/debug";
3
4
  import { $createImageNode } from "../node/image-node";
5
+ var logger = createDebugLogger('plugin', 'image');
4
6
  export var INSERT_IMAGE_COMMAND = createCommand('INSERT_IMAGE_COMMAND');
5
7
  function isImageFile(file) {
6
8
  return file.type.startsWith('image/');
@@ -34,7 +36,7 @@ export function registerImageCommand(editor, handleUpload) {
34
36
  imageNode.setUploaded(res.url);
35
37
  });
36
38
  }).catch(function (error) {
37
- console.error('Image upload failed:', error);
39
+ logger.error('Image upload failed:', error);
38
40
  editor.update(function () {
39
41
  imageNode.setError('Image upload failed : ' + error.message);
40
42
  });
@@ -90,6 +90,7 @@ export declare class MarkdownShortCutService implements IMarkdownShortCutService
90
90
  private elementTransformers;
91
91
  private textFormatTransformers;
92
92
  private textMatchTransformers;
93
+ private logger;
93
94
  private _markdownWriters;
94
95
  constructor(kernel?: import("../../../types/kernel").IEditorKernel | undefined);
95
96
  get markdownWriters(): Record<string, (ctx: IMarkdownWriterContext, node: LexicalNode) => boolean | void>;
@@ -20,6 +20,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
20
20
  /* eslint-disable @typescript-eslint/no-redeclare */
21
21
  import { $createRangeSelection, $getSelection, $isLineBreakNode, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection } from 'lexical';
22
22
  import { genServiceId } from "../../../editor-kernel";
23
+ import { createDebugLogger } from "../../../utils/debug";
23
24
  import { PUNCTUATION_OR_SPACE, getOpenTagStartIndex, indexBy, isEqualSubString } from "../utils";
24
25
  export var IMarkdownShortCutService = genServiceId('MarkdownShortCutService');
25
26
  function testElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers, fromTrigger) {
@@ -293,6 +294,7 @@ export var MarkdownShortCutService = /*#__PURE__*/function () {
293
294
  _defineProperty(this, "elementTransformers", []);
294
295
  _defineProperty(this, "textFormatTransformers", []);
295
296
  _defineProperty(this, "textMatchTransformers", []);
297
+ _defineProperty(this, "logger", createDebugLogger('service', 'markdown'));
296
298
  _defineProperty(this, "_markdownWriters", {});
297
299
  _defineProperty(this, "_textFormatTransformersByTrigger", null);
298
300
  _defineProperty(this, "_textMatchTransformersByTrigger", null);
@@ -397,7 +399,7 @@ export var MarkdownShortCutService = /*#__PURE__*/function () {
397
399
  return;
398
400
  }
399
401
  if ((_this$kernel = this.kernel) !== null && _this$kernel !== void 0 && _this$kernel.isHotReloadMode()) {
400
- console.warn("[Hot Reload] Overriding markdown writer for type \"".concat(type, "\""));
402
+ this.logger.warn("\uD83D\uDD04 Hot reload: markdown writer \"".concat(type, "\""));
401
403
  this._markdownWriters[type] = writer;
402
404
  return;
403
405
  }
@@ -22,6 +22,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
22
22
  import { $createNodeSelection, $setSelection } from 'lexical';
23
23
  import { KernelPlugin } from "../../../editor-kernel/plugin";
24
24
  import { IMarkdownShortCutService } from "../../markdown";
25
+ import { createDebugLogger } from "../../../utils/debug";
25
26
  import { registerMathCommand } from "../command";
26
27
  import { $createMathBlockNode, $createMathInlineNode, MathBlockNode, MathInlineNode } from "../node";
27
28
 
@@ -35,16 +36,17 @@ export var MathPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
35
36
  var _this;
36
37
  _classCallCheck(this, MathPlugin);
37
38
  _this = _super.call(this);
39
+ _defineProperty(_assertThisInitialized(_this), "logger", createDebugLogger('plugin', 'math'));
38
40
  _this.kernel = kernel;
39
41
  _this.config = config;
40
42
  kernel.registerNodes([MathInlineNode, MathBlockNode]);
41
43
  if (config !== null && config !== void 0 && config.theme) {
42
44
  kernel.registerThemes(config === null || config === void 0 ? void 0 : config.theme);
43
45
  }
44
- kernel.registerDecorator(MathInlineNode.getType(), function (node, editor) {
46
+ _this.registerDecorator(kernel, MathInlineNode.getType(), function (node, editor) {
45
47
  return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
46
48
  });
47
- kernel.registerDecorator(MathBlockNode.getType(), function (node, editor) {
49
+ _this.registerDecorator(kernel, MathBlockNode.getType(), function (node, editor) {
48
50
  return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
49
51
  });
50
52
  (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownShortCut({
@@ -53,7 +55,7 @@ export var MathPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
53
55
  var _match = _slicedToArray(match, 2),
54
56
  code = _match[1];
55
57
  var mathNode = $createMathInlineNode(code);
56
- console.log(mathNode);
58
+ _this.logger.debug('Math node inserted:', mathNode);
57
59
  // textNode.replace(mathNode);
58
60
  textNode.insertBefore(mathNode);
59
61
  textNode.setTextContent('');
@@ -10,9 +10,11 @@ import { $getSelection, $isNodeSelection, CLICK_COMMAND, COMMAND_PRIORITY_NORMAL
10
10
  import { memo, useEffect, useRef, useState } from 'react';
11
11
  import { useLexicalEditor } from "../../../../editor-kernel/react";
12
12
  import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
13
+ import { createDebugLogger } from "../../../../utils/debug";
13
14
  import { $isMathNode, MathBlockNode } from "../../node";
14
15
  import Placeholder from "./Placeholder";
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
+ var logger = createDebugLogger('plugin', 'math');
16
18
  var MathInline = /*#__PURE__*/memo(function (_ref) {
17
19
  var editor = _ref.editor,
18
20
  node = _ref.node,
@@ -56,7 +58,7 @@ var MathInline = /*#__PURE__*/memo(function (_ref) {
56
58
  }, [isSelected, isEditing, editor, node]);
57
59
  useLexicalEditor(function (editor) {
58
60
  return editor.registerCommand(CLICK_COMMAND, function (payload) {
59
- console.info(payload, payload.target, ref.current);
61
+ logger.debug('📊 Math click event:', payload.target === ref.current);
60
62
  if (payload.target && payload.target instanceof Node) {
61
63
  var _ref$current;
62
64
  // 获取节点对应的 DOM 元素
@@ -35,7 +35,7 @@ export var ReactMathPlugin = function ReactMathPlugin(_ref) {
35
35
  },
36
36
  theme: theme || styles
37
37
  });
38
- }, [editor]);
38
+ }, [editor, className, theme, styles]);
39
39
  return /*#__PURE__*/_jsx(MathEdit, {
40
40
  renderComp: renderComp
41
41
  });
@@ -36,7 +36,7 @@ export var MentionPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
36
36
  if (config !== null && config !== void 0 && config.theme) {
37
37
  kernel.registerThemes(config === null || config === void 0 ? void 0 : config.theme);
38
38
  }
39
- kernel.registerDecorator(MentionNode.getType(), function (node, editor) {
39
+ _this.registerDecorator(kernel, MentionNode.getType(), function (node, editor) {
40
40
  return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
41
41
  });
42
42
  (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(MentionNode.getType(), function (ctx, node) {
@@ -35,7 +35,7 @@ var ReactMentionPlugin = function ReactMentionPlugin(_ref) {
35
35
  markdownWriter: markdownWriter,
36
36
  theme: theme || styles
37
37
  });
38
- }, [editor]);
38
+ }, [editor, className, markdownWriter, theme, styles]);
39
39
  return null;
40
40
  };
41
41
  ReactMentionPlugin.displayName = 'ReactMentionPlugin';
@@ -30,6 +30,7 @@ export declare class SlashService implements ISlashService {
30
30
  private triggerMap;
31
31
  private triggerFnMap;
32
32
  private triggerFuseMap;
33
+ private logger;
33
34
  constructor(kernel: IEditorKernel);
34
35
  registerSlash(options: SlashOptions): void;
35
36
  getSlashOptions(trigger: string): SlashOptions | undefined;
@@ -10,6 +10,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
10
10
 
11
11
  import Fuse from 'fuse.js';
12
12
  import { genServiceId } from "../../../editor-kernel";
13
+ import { createDebugLogger } from "../../../utils/debug";
13
14
  import { getBasicTypeaheadTriggerMatch } from "../utils/utils";
14
15
  export var ISlashService = genServiceId('SlashService');
15
16
  export var SlashService = /*#__PURE__*/function () {
@@ -18,6 +19,7 @@ export var SlashService = /*#__PURE__*/function () {
18
19
  _defineProperty(this, "triggerMap", new Map());
19
20
  _defineProperty(this, "triggerFnMap", new Map());
20
21
  _defineProperty(this, "triggerFuseMap", new Map());
22
+ _defineProperty(this, "logger", createDebugLogger('service', 'slash'));
21
23
  this.kernel = kernel;
22
24
  }
23
25
  // Specific service methods can be added here
@@ -26,7 +28,7 @@ export var SlashService = /*#__PURE__*/function () {
26
28
  value: function registerSlash(options) {
27
29
  if (this.triggerMap.has(options.trigger)) {
28
30
  if (this.kernel.isHotReloadMode()) {
29
- console.warn("[Hot Reload] Overriding slash trigger \"".concat(options.trigger, "\""));
31
+ this.logger.warn("\uD83D\uDD04 Overriding slash trigger \"".concat(options.trigger, "\""));
30
32
  } else {
31
33
  throw new Error("Slash trigger \"".concat(options.trigger, "\" is already registered."));
32
34
  }
@@ -38,6 +40,7 @@ export var SlashService = /*#__PURE__*/function () {
38
40
  minLength: options.minLength,
39
41
  punctuation: options.punctuation
40
42
  }));
43
+ this.logger.debug("\u26A1 Slash trigger: ".concat(options.trigger));
41
44
  if (Array.isArray(options.items)) {
42
45
  // Filter out divider items for search functionality
43
46
  var searchableItems = options.items.filter(function (item) {
@@ -19,6 +19,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
19
19
  import { DRAG_DROP_PASTE } from '@lexical/rich-text';
20
20
  import { COMMAND_PRIORITY_HIGH, DROP_COMMAND } from 'lexical';
21
21
  import { KernelPlugin } from "../../../editor-kernel/plugin";
22
+ import { createDebugLogger } from "../../../utils/debug";
22
23
  import { IUploadService, UploadService } from "../service/i-upload-service";
23
24
  import { getDragSelection } from "../utils";
24
25
 
@@ -32,6 +33,7 @@ export var UploadPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
32
33
  _classCallCheck(this, UploadPlugin);
33
34
  _this = _super.call(this);
34
35
  // Register the upload service
36
+ _defineProperty(_assertThisInitialized(_this), "logger", createDebugLogger('plugin', 'upload'));
35
37
  _this.kernel = kernel;
36
38
  _this.config = config;
37
39
  kernel.registerService(IUploadService, new UploadService());
@@ -50,7 +52,7 @@ export var UploadPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
50
52
  var uploadService = _this2.kernel.requireService(IUploadService);
51
53
  if (uploadService) {
52
54
  uploadService.uploadFile(file, 'drop', getDragSelection(event)).catch(function (error) {
53
- console.error('Upload failed:', error);
55
+ _this2.logger.error('Upload failed:', error);
54
56
  });
55
57
  }
56
58
  }
@@ -65,7 +67,7 @@ export var UploadPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
65
67
  var uploadService = _this2.kernel.requireService(IUploadService);
66
68
  if (uploadService) {
67
69
  uploadService.uploadFile(file, 'drag-drop-paste', null).catch(function (error) {
68
- console.error('Upload failed:', error);
70
+ _this2.logger.error('Upload failed:', error);
69
71
  });
70
72
  }
71
73
  }
@@ -63,9 +63,10 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
63
63
  var memoMention = useMemo(function () {
64
64
  if (!enableMention) return;
65
65
  return /*#__PURE__*/_jsx(ReactMentionPlugin, {
66
+ className: className,
66
67
  markdownWriter: markdownWriter
67
68
  });
68
- }, [enableMention, markdownWriter]);
69
+ }, [enableMention, markdownWriter, className]);
69
70
  var memoSlash = useMemo(function () {
70
71
  if (!enableSlash && !enableMention) return null;
71
72
  return /*#__PURE__*/_jsxs(ReactSlashPlugin, {
@@ -171,6 +171,10 @@ export interface IEditorKernel extends IEditor {
171
171
  * @param name
172
172
  */
173
173
  getDecorator(name: string): ((_node: DecoratorNode<any>, _editor: LexicalEditor) => any) | undefined;
174
+ /**
175
+ * Get all registered decorator names
176
+ */
177
+ getRegisteredDecorators(): string[];
174
178
  /**
175
179
  * Check if hot reload mode is enabled
176
180
  */
@@ -213,6 +217,11 @@ export interface IEditorKernel extends IEditor {
213
217
  * @param enabled Whether to enable hot reload mode
214
218
  */
215
219
  setHotReloadMode(enabled: boolean): void;
220
+ /**
221
+ * Unregister editor node decorator
222
+ * @param name Decorator name
223
+ */
224
+ unregisterDecorator(name: string): boolean;
216
225
  }
217
226
  /**
218
227
  * Plugin interface