@lobehub/editor 3.4.1 → 3.5.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.
@@ -45,13 +45,46 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
45
45
  _inherits(CommonPlugin, _KernelPlugin);
46
46
  var _super = _createSuper(CommonPlugin);
47
47
  function CommonPlugin(kernel) {
48
+ var _config$markdownOptio;
48
49
  var _this;
49
50
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
50
51
  _classCallCheck(this, CommonPlugin);
51
52
  _this = _super.call(this);
52
- // Register the JSON data source
53
+
54
+ // Parse markdown options and update formats
55
+ _defineProperty(_assertThisInitialized(_this), "formats", {
56
+ bold: true,
57
+ header: true,
58
+ italic: true,
59
+ quote: true,
60
+ strikethrough: true,
61
+ subscript: false,
62
+ superscript: false
63
+ });
53
64
  _this.kernel = kernel;
54
65
  _this.config = config;
66
+ var markdownOption = (_config$markdownOptio = config.markdownOption) !== null && _config$markdownOptio !== void 0 ? _config$markdownOptio : true;
67
+ if (_typeof(markdownOption) === 'object') {
68
+ var _markdownOption$bold, _markdownOption$heade, _markdownOption$itali, _markdownOption$quote, _markdownOption$strik, _markdownOption$subsc, _markdownOption$super;
69
+ _this.formats.bold = (_markdownOption$bold = markdownOption.bold) !== null && _markdownOption$bold !== void 0 ? _markdownOption$bold : true;
70
+ _this.formats.header = (_markdownOption$heade = markdownOption.header) !== null && _markdownOption$heade !== void 0 ? _markdownOption$heade : true;
71
+ _this.formats.italic = (_markdownOption$itali = markdownOption.italic) !== null && _markdownOption$itali !== void 0 ? _markdownOption$itali : true;
72
+ _this.formats.quote = (_markdownOption$quote = markdownOption.quote) !== null && _markdownOption$quote !== void 0 ? _markdownOption$quote : true;
73
+ _this.formats.strikethrough = (_markdownOption$strik = markdownOption.strikethrough) !== null && _markdownOption$strik !== void 0 ? _markdownOption$strik : true;
74
+ _this.formats.subscript = (_markdownOption$subsc = markdownOption.subscript) !== null && _markdownOption$subsc !== void 0 ? _markdownOption$subsc : false;
75
+ _this.formats.superscript = (_markdownOption$super = markdownOption.superscript) !== null && _markdownOption$super !== void 0 ? _markdownOption$super : false;
76
+ } else if (markdownOption === false) {
77
+ // Disable all formats if markdown is disabled
78
+ _this.formats.bold = false;
79
+ _this.formats.header = false;
80
+ _this.formats.italic = false;
81
+ _this.formats.quote = false;
82
+ _this.formats.strikethrough = false;
83
+ _this.formats.subscript = false;
84
+ _this.formats.superscript = false;
85
+ }
86
+
87
+ // Register the JSON data source
55
88
  kernel.registerDataSource(new JSONDataSource('json'));
56
89
  // Register the text data source
57
90
  kernel.registerDataSource(new TextDataSource('text'));
@@ -88,29 +121,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
88
121
  var markdownOption = (_this$config$markdown = (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.markdownOption) !== null && _this$config$markdown !== void 0 ? _this$config$markdown : true;
89
122
  var isMarkdownEnabled = markdownOption !== false;
90
123
  var breakMark = isMarkdownEnabled ? '\n\n' : '\n';
91
-
92
- // Determine which formats are enabled
93
- var formats = {
94
- bold: true,
95
- header: true,
96
- italic: true,
97
- quote: true,
98
- strikethrough: true,
99
- subscript: false,
100
- // Disabled by default
101
- superscript: false // Disabled by default
102
- // Note: code, underline, underlineStrikethrough are handled by other plugins/writers
103
- };
104
- if (_typeof(markdownOption) === 'object') {
105
- var _markdownOption$bold, _markdownOption$heade, _markdownOption$itali, _markdownOption$quote, _markdownOption$strik, _markdownOption$subsc, _markdownOption$super;
106
- formats.bold = (_markdownOption$bold = markdownOption.bold) !== null && _markdownOption$bold !== void 0 ? _markdownOption$bold : true;
107
- formats.header = (_markdownOption$heade = markdownOption.header) !== null && _markdownOption$heade !== void 0 ? _markdownOption$heade : true;
108
- formats.italic = (_markdownOption$itali = markdownOption.italic) !== null && _markdownOption$itali !== void 0 ? _markdownOption$itali : true;
109
- formats.quote = (_markdownOption$quote = markdownOption.quote) !== null && _markdownOption$quote !== void 0 ? _markdownOption$quote : true;
110
- formats.strikethrough = (_markdownOption$strik = markdownOption.strikethrough) !== null && _markdownOption$strik !== void 0 ? _markdownOption$strik : true;
111
- formats.subscript = (_markdownOption$subsc = markdownOption.subscript) !== null && _markdownOption$subsc !== void 0 ? _markdownOption$subsc : false;
112
- formats.superscript = (_markdownOption$super = markdownOption.superscript) !== null && _markdownOption$super !== void 0 ? _markdownOption$super : false;
113
- }
124
+ var formats = this.formats;
114
125
 
115
126
  // Register quote shortcut if enabled
116
127
  if (formats.quote) {
@@ -202,64 +213,74 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
202
213
  markdownService.registerMarkdownShortCuts(textFormatShortcuts);
203
214
  }
204
215
  markdownService.registerMarkdownWriter('paragraph', function (ctx) {
205
- ctx.wrap('', '\n\n');
206
- });
207
- markdownService.registerMarkdownWriter('quote', function (ctx, node) {
208
- if ($isQuoteNode(node)) {
209
- ctx.wrap('> ', breakMark);
210
- }
216
+ ctx.wrap('', breakMark);
211
217
  });
212
- markdownService.registerMarkdownWriter('heading', function (ctx, node) {
213
- if ($isHeadingNode(node)) {
214
- switch (node.getTag()) {
215
- case 'h1':
216
- {
217
- ctx.wrap('# ', breakMark);
218
- break;
219
- }
220
- case 'h2':
221
- {
222
- ctx.wrap('## ', breakMark);
223
- break;
224
- }
225
- case 'h3':
226
- {
227
- ctx.wrap('### ', breakMark);
228
- break;
229
- }
230
- case 'h4':
231
- {
232
- ctx.wrap('#### ', breakMark);
233
- break;
234
- }
235
- case 'h5':
236
- {
237
- ctx.wrap('##### ', breakMark);
238
- break;
239
- }
240
- case 'h6':
241
- {
242
- ctx.wrap('###### ', breakMark);
243
- break;
244
- }
245
- default:
246
- {
247
- ctx.wrap('', '\n');
248
- break;
249
- }
218
+
219
+ // Register quote writer only if quote format is enabled
220
+ if (formats.quote) {
221
+ markdownService.registerMarkdownWriter('quote', function (ctx, node) {
222
+ if ($isQuoteNode(node)) {
223
+ ctx.wrap('> ', breakMark);
250
224
  }
251
- }
252
- });
225
+ });
226
+ }
227
+
228
+ // Register heading writer only if header format is enabled
229
+ if (formats.header) {
230
+ markdownService.registerMarkdownWriter('heading', function (ctx, node) {
231
+ if ($isHeadingNode(node)) {
232
+ switch (node.getTag()) {
233
+ case 'h1':
234
+ {
235
+ ctx.wrap('# ', '\n\n');
236
+ break;
237
+ }
238
+ case 'h2':
239
+ {
240
+ ctx.wrap('## ', '\n\n');
241
+ break;
242
+ }
243
+ case 'h3':
244
+ {
245
+ ctx.wrap('### ', '\n\n');
246
+ break;
247
+ }
248
+ case 'h4':
249
+ {
250
+ ctx.wrap('#### ', '\n\n');
251
+ break;
252
+ }
253
+ case 'h5':
254
+ {
255
+ ctx.wrap('##### ', '\n\n');
256
+ break;
257
+ }
258
+ case 'h6':
259
+ {
260
+ ctx.wrap('###### ', '\n\n');
261
+ break;
262
+ }
263
+ default:
264
+ {
265
+ ctx.wrap('', '\n\n');
266
+ break;
267
+ }
268
+ }
269
+ }
270
+ });
271
+ }
272
+
273
+ // Register text writer with conditional format handling
253
274
  markdownService.registerMarkdownWriter('text', function (ctx, node) {
254
275
  if (!$isTextNode(node)) {
255
276
  return;
256
277
  }
257
- var isBold = node.hasFormat('bold');
258
- var isItalic = node.hasFormat('italic');
278
+ var isBold = formats.bold && node.hasFormat('bold');
279
+ var isItalic = formats.italic && node.hasFormat('italic');
259
280
  var isUnderline = node.hasFormat('underline');
260
- var isStrikethrough = node.hasFormat('strikethrough');
261
- var isSuperscript = node.hasFormat('superscript');
262
- var isSubscript = node.hasFormat('subscript');
281
+ var isStrikethrough = formats.strikethrough && node.hasFormat('strikethrough');
282
+ var isSuperscript = formats.superscript && node.hasFormat('superscript');
283
+ var isSubscript = formats.subscript && node.hasFormat('subscript');
263
284
  if (isBold) {
264
285
  ctx.appendLine('**');
265
286
  }
@@ -315,7 +336,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
315
336
  // Register markdown writer for linebreak nodes (soft line breaks)
316
337
  markdownService.registerMarkdownWriter('linebreak', function (ctx) {
317
338
  // In markdown, soft line breaks are represented as two spaces followed by a newline
318
- ctx.appendLine(' \n');
339
+ ctx.appendLine('\n');
319
340
  });
320
341
 
321
342
  // 注册 markdown reader
@@ -383,35 +404,44 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
383
404
  if (!litexmlService) {
384
405
  return;
385
406
  }
407
+ var formats = this.formats;
386
408
  litexmlService.registerXMLWriter(TextNode.getType(), function (node, ctx) {
387
409
  var attr = {};
388
410
  if ($isTextNode(node)) {
389
- if (node.hasFormat('bold')) {
411
+ if (formats.bold && node.hasFormat('bold')) {
390
412
  attr['bold'] = 'true';
391
413
  }
392
- if (node.hasFormat('italic')) {
414
+ if (formats.italic && node.hasFormat('italic')) {
393
415
  attr['italic'] = 'true';
394
416
  }
395
417
  if (node.hasFormat('underline')) {
396
418
  attr['underline'] = 'true';
397
419
  }
398
- if (node.hasFormat('strikethrough')) {
420
+ if (formats.strikethrough && node.hasFormat('strikethrough')) {
399
421
  attr['strikethrough'] = 'true';
400
422
  }
401
- if (node.hasFormat('subscript')) {
423
+ if (formats.subscript && node.hasFormat('subscript')) {
402
424
  attr['subscript'] = 'true';
403
425
  }
404
- if (node.hasFormat('superscript')) {
426
+ if (formats.superscript && node.hasFormat('superscript')) {
405
427
  attr['superscript'] = 'true';
406
428
  }
407
429
  return ctx.createXmlNode('span', attr, node.getTextContent());
408
430
  }
409
431
  return false;
410
432
  });
411
- litexmlService.registerXMLReader('b', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['bold']));
412
- litexmlService.registerXMLReader('strong', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['bold']));
413
- litexmlService.registerXMLReader('i', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['italic']));
414
- litexmlService.registerXMLReader('emphasis', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['italic']));
433
+
434
+ // Register bold readers only if bold format is enabled
435
+ if (formats.bold) {
436
+ litexmlService.registerXMLReader('b', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['bold']));
437
+ litexmlService.registerXMLReader('strong', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['bold']));
438
+ }
439
+
440
+ // Register italic readers only if italic format is enabled
441
+ if (formats.italic) {
442
+ litexmlService.registerXMLReader('i', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['italic']));
443
+ litexmlService.registerXMLReader('emphasis', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['italic']));
444
+ }
415
445
  litexmlService.registerXMLReader('u', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['underline']));
416
446
  litexmlService.registerXMLReader('ins', sampleReader.bind(this, TEXT_TYPE_TO_FORMAT['underline']));
417
447
  litexmlService.registerXMLReader('span', function (xmlElement, children) {
@@ -422,22 +452,22 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
422
452
  var subscript = xmlElement.getAttribute('subscript');
423
453
  var superscript = xmlElement.getAttribute('superscript');
424
454
  var format = 0;
425
- if (bold === 'true') {
455
+ if (formats.bold && bold === 'true') {
426
456
  format |= TEXT_TYPE_TO_FORMAT['bold'];
427
457
  }
428
- if (italic === 'true') {
458
+ if (formats.italic && italic === 'true') {
429
459
  format |= TEXT_TYPE_TO_FORMAT['italic'];
430
460
  }
431
461
  if (underline === 'true') {
432
462
  format |= TEXT_TYPE_TO_FORMAT['underline'];
433
463
  }
434
- if (strikethrough === 'true') {
464
+ if (formats.strikethrough && strikethrough === 'true') {
435
465
  format |= TEXT_TYPE_TO_FORMAT['strikethrough'];
436
466
  }
437
- if (subscript === 'true') {
467
+ if (formats.subscript && subscript === 'true') {
438
468
  format |= TEXT_TYPE_TO_FORMAT['subscript'];
439
469
  }
440
- if (superscript === 'true') {
470
+ if (formats.superscript && superscript === 'true') {
441
471
  format |= TEXT_TYPE_TO_FORMAT['superscript'];
442
472
  }
443
473
  children.forEach(function (child) {
@@ -447,40 +477,48 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
447
477
  });
448
478
  return children;
449
479
  });
450
- litexmlService.registerXMLWriter('quote', function (node, ctx) {
451
- if ($isQuoteNode(node)) {
452
- return ctx.createXmlNode('quote', {});
453
- }
454
- return false;
455
- });
456
- litexmlService.registerXMLWriter('heading', function (node, ctx) {
457
- if ($isHeadingNode(node)) {
458
- return ctx.createXmlNode(node.getTag(), {});
459
- }
460
- return false;
461
- });
480
+
481
+ // Register quote writer/reader only if quote format is enabled
482
+ if (formats.quote) {
483
+ litexmlService.registerXMLWriter('quote', function (node, ctx) {
484
+ if ($isQuoteNode(node)) {
485
+ return ctx.createXmlNode('quote', {});
486
+ }
487
+ return false;
488
+ });
489
+ litexmlService.registerXMLReader('quote', function (xmlElement, children) {
490
+ return INodeHelper.createElementNode(QuoteNode.getType(), {
491
+ children: children
492
+ });
493
+ });
494
+ }
495
+
496
+ // Register heading writer/reader only if header format is enabled
497
+ if (formats.header) {
498
+ litexmlService.registerXMLWriter('heading', function (node, ctx) {
499
+ if ($isHeadingNode(node)) {
500
+ return ctx.createXmlNode(node.getTag(), {});
501
+ }
502
+ return false;
503
+ });
504
+ var headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
505
+ headingTags.forEach(function (tag) {
506
+ litexmlService.registerXMLReader(tag, function (xmlElement, children) {
507
+ return INodeHelper.createElementNode(HeadingNode.getType(), {
508
+ children: children,
509
+ tag: tag
510
+ });
511
+ });
512
+ });
513
+ }
462
514
  litexmlService.registerXMLWriter(ParagraphNode.getType(), function (node, ctx) {
463
515
  return ctx.createXmlNode('p', {});
464
516
  });
465
- litexmlService.registerXMLReader('quote', function (xmlElement, children) {
466
- return INodeHelper.createElementNode(QuoteNode.getType(), {
467
- children: children
468
- });
469
- });
470
517
  litexmlService.registerXMLReader('p', function (xmlElement, children) {
471
518
  return INodeHelper.createElementNode(ParagraphNode.getType(), {
472
519
  children: children
473
520
  });
474
521
  });
475
- var headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
476
- headingTags.forEach(function (tag) {
477
- litexmlService.registerXMLReader(tag, function (xmlElement, children) {
478
- return INodeHelper.createElementNode(HeadingNode.getType(), {
479
- children: children,
480
- tag: tag
481
- });
482
- });
483
- });
484
522
  }
485
523
  }, {
486
524
  key: "destroy",
@@ -59,7 +59,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
59
59
  _theme$headerMultiple = theme.headerMultiple,
60
60
  headerMultiple = _theme$headerMultiple === void 0 ? isChat ? 0.25 : 0.6 : _theme$headerMultiple,
61
61
  _theme$lineHeight = theme.lineHeight,
62
- lineHeight = _theme$lineHeight === void 0 ? isChat ? 1.6 : 1.8 : _theme$lineHeight,
62
+ lineHeight = _theme$lineHeight === void 0 ? isChat ? 1.4 : 1.6 : _theme$lineHeight,
63
63
  _theme$marginMultiple = theme.marginMultiple,
64
64
  marginMultiple = _theme$marginMultiple === void 0 ? isChat ? 1 : 2 : _theme$marginMultiple,
65
65
  restTheme = _objectWithoutProperties(theme, _excluded);
@@ -220,7 +220,7 @@ var ReactPlainText = /*#__PURE__*/memo(function (_ref) {
220
220
  });
221
221
  };
222
222
  return /*#__PURE__*/_jsxs("div", {
223
- className: cx(styles.root, markdownOption === true && styles.variant, markdownOption === false && styles.noStyle, markdownOption === false && styles.noHeader, _typeof(markdownOption) === 'object' && markdownOption.header === true && styles.header, _typeof(markdownOption) === 'object' && markdownOption.header === false && styles.noHeader, _typeof(markdownOption) === 'object' && markdownOption.code === true && styles.code, _typeof(markdownOption) === 'object' && markdownOption.quote === true && styles.blockquote, className),
223
+ className: cx(styles.root, styles.variant, className),
224
224
  style: _objectSpread(_objectSpread({}, cssVariables), style),
225
225
  children: [/*#__PURE__*/_jsx("div", {
226
226
  className: styles.editorContent,
@@ -17,8 +17,6 @@ export declare const styles: {
17
17
  code: string;
18
18
  editorContent: string;
19
19
  header: string;
20
- noHeader: string;
21
- noStyle: string;
22
20
  p: string;
23
21
  root: string;
24
22
  variant: string;
@@ -1,6 +1,6 @@
1
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19;
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
- import { createStaticStyles, keyframes, cx } from 'antd-style';
3
+ import { createStaticStyles, cx, keyframes } from 'antd-style';
4
4
  var cursorBlink = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n to {\n visibility: hidden;\n }\n"])));
5
5
  export var themeStyles = createStaticStyles(function (_ref) {
6
6
  var css = _ref.css,
@@ -23,7 +23,7 @@ export var themeStyles = createStaticStyles(function (_ref) {
23
23
  export var styles = createStaticStyles(function (_ref2) {
24
24
  var css = _ref2.css,
25
25
  cssVar = _ref2.cssVar;
26
- var __root = css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: var(--common-font-size, 16px);\n --lobe-markdown-header-multiple: var(--common-header-multiple, 1);\n --lobe-markdown-margin-multiple: var(--common-margin-multiple, 2);\n --lobe-markdown-line-height: var(--common-line-height, 1.8);\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n display: flex;\n flex-direction: column;\n\n width: 100%;\n max-width: 100%;\n height: 100%;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n [data-placeholder] {\n position: relative;\n }\n\n [data-placeholder]::after {\n pointer-events: none;\n content: attr(data-placeholder);\n user-select: none;\n\n position: absolute;\n inset-block-start: 50%;\n transform: translateY(-50%);\n\n padding-inline-start: 2px;\n\n color: ", ";\n white-space: nowrap;\n }\n\n [data-lexical-cursor='true'] {\n pointer-events: none;\n position: absolute;\n display: block;\n\n &::after {\n content: '';\n\n position: absolute;\n inset-block-start: -2px;\n\n display: block;\n\n width: 20px;\n border-block-start: 1px solid ", ";\n\n animation: ", " 1.1s steps(2, start) infinite;\n }\n }\n "])), cssVar.borderRadiusLG, cssVar.colorFillQuaternary, cssVar.colorTextDescription, cssVar.colorText, cursorBlink);
26
+ var __root = css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: var(--common-font-size, 16px);\n --lobe-markdown-header-multiple: var(--common-header-multiple, 1);\n --lobe-markdown-margin-multiple: var(--common-margin-multiple, 2);\n --lobe-markdown-line-height: var(--common-line-height, 1.6);\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n display: flex;\n flex-direction: column;\n\n width: 100%;\n max-width: 100%;\n height: 100%;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n [data-placeholder] {\n position: relative;\n }\n\n [data-placeholder]::after {\n pointer-events: none;\n content: attr(data-placeholder);\n user-select: none;\n\n position: absolute;\n inset-block-start: 50%;\n transform: translateY(-50%);\n\n padding-inline-start: 2px;\n\n color: ", ";\n white-space: nowrap;\n }\n\n [data-lexical-cursor='true'] {\n pointer-events: none;\n position: absolute;\n display: block;\n\n &::after {\n content: '';\n\n position: absolute;\n inset-block-start: -2px;\n\n display: block;\n\n width: 20px;\n border-block-start: 1px solid ", ";\n\n animation: ", " 1.1s steps(2, start) infinite;\n }\n }\n "])), cssVar.borderRadiusLG, cssVar.colorFillQuaternary, cssVar.colorTextDescription, cssVar.colorText, cursorBlink);
27
27
  var header = css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-block: max(\n calc(var(--lobe-markdown-header-multiple) * var(--lobe-markdown-margin-multiple) * 0.4em),\n var(--lobe-markdown-font-size)\n );\n font-weight: bold;\n line-height: 1.25;\n }\n\n h1 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 1.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h2 {\n font-size: calc(var(--lobe-markdown-font-size) * (1 + var(--lobe-markdown-header-multiple)));\n }\n\n h3 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.5 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h4 {\n font-size: calc(\n var(--lobe-markdown-font-size) * (1 + 0.25 * var(--lobe-markdown-header-multiple))\n );\n }\n\n h5,\n h6 {\n font-size: calc(var(--lobe-markdown-font-size) * 1);\n }\n "])));
28
28
  var p = css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n p {\n margin-block: 4px;\n line-height: var(--lobe-markdown-line-height);\n letter-spacing: 0.02em;\n\n &:not(:first-child) {\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n\n &:not(:last-child) {\n margin-block-end: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n }\n }\n "])));
29
29
  var blockquote = css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n .editor_quote {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline: 0;\n padding-block: 0;\n padding-inline: 1em;\n border-inline-start: solid 4px ", ";\n\n color: ", ";\n }\n "])), cssVar.colorBorder, cssVar.colorTextSecondary);
@@ -34,8 +34,6 @@ export var styles = createStaticStyles(function (_ref2) {
34
34
  code: code,
35
35
  editorContent: editorContent,
36
36
  header: header,
37
- noHeader: css(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-block: 0;\n font-size: var(--lobe-markdown-font-size);\n font-weight: normal;\n line-height: var(--lobe-markdown-line-height);\n }\n "]))),
38
- noStyle: css(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n --lobe-markdown-header-multiple: 0;\n --lobe-markdown-margin-multiple: 0;\n --lobe-markdown-line-height: 1.5;\n\n p {\n margin-block: 4px;\n }\n "]))),
39
37
  p: p,
40
38
  root: __root,
41
39
  variant: cx(header, p, blockquote, code)
@@ -61,6 +61,29 @@ function doAction(node, action) {
61
61
  _parent.selectEnd();
62
62
  }
63
63
  }
64
+ if (node.diffType === 'listItemRemove') {
65
+ if (action === DiffAction.Accept) {
66
+ node.getParentOrThrow().remove();
67
+ } else if (action === DiffAction.Reject) {
68
+ node.getChildren().forEach(function (child) {
69
+ node.getParentOrThrow().append(child);
70
+ });
71
+ node.getParentOrThrow().selectEnd();
72
+ node.remove();
73
+ }
74
+ }
75
+ if (node.diffType === 'listItemAdd') {
76
+ if (action === DiffAction.Accept) {
77
+ var _children4 = node.getChildren();
78
+ _children4.forEach(function (child) {
79
+ node.getParentOrThrow().append(child);
80
+ });
81
+ node.getParentOrThrow().selectEnd();
82
+ node.remove();
83
+ } else if (action === DiffAction.Reject) {
84
+ node.remove();
85
+ }
86
+ }
64
87
  }
65
88
  export function registerLiteXMLDiffCommand(editor) {
66
89
  return mergeRegister(editor.registerCommand(LITEXML_DIFFNODE_COMMAND, function (payload) {
@@ -14,6 +14,7 @@ import { $closest } from "../../../editor-kernel";
14
14
  import { createDebugLogger } from "../../../utils/debug";
15
15
  import { $createDiffNode, DiffNode } from "../node/DiffNode";
16
16
  import { $cloneNode, $parseSerializedNodeImpl, charToId } from "../utils";
17
+ import { $isListItemNode } from '@lexical/list';
17
18
  var logger = createDebugLogger('plugin', 'litexml');
18
19
 
19
20
  // Helpers to reduce duplication and improve readability
@@ -136,39 +137,44 @@ export function registerLiteXMLCommand(editor, dataSource) {
136
137
  }
137
138
  return acc;
138
139
  }, []);
139
- resultPayload.forEach(function (item) {
140
- var action = item.action;
141
- switch (action) {
142
- case 'modify':
143
- {
144
- var litexml = item.litexml;
145
- var arrayXml = toArrayXml(litexml);
146
- // handle modfy action
147
- handleModify(editor, dataSource, arrayXml, true);
148
- break;
149
- }
150
- case 'remove':
151
- {
152
- var id = item.id;
153
- var key = charToId(id);
154
- // handle remove action
155
- handleRemove(editor, key, true);
156
- break;
157
- }
158
- case 'insert':
159
- {
160
- handleInsert(editor, _objectSpread(_objectSpread({}, item), {}, {
161
- delay: true
162
- }), dataSource);
163
- break;
164
- }
165
- default:
166
- {
167
- logger.warn("\u26A0\uFE0F Unknown action type: ".concat(action));
168
- }
169
- }
170
- });
171
- return false;
140
+ try {
141
+ resultPayload.forEach(function (item) {
142
+ var action = item.action;
143
+ switch (action) {
144
+ case 'modify':
145
+ {
146
+ var litexml = item.litexml;
147
+ var arrayXml = toArrayXml(litexml);
148
+ // handle modfy action
149
+ handleModify(editor, dataSource, arrayXml, true);
150
+ break;
151
+ }
152
+ case 'remove':
153
+ {
154
+ var id = item.id;
155
+ var key = charToId(id);
156
+ // handle remove action
157
+ handleRemove(editor, key, true);
158
+ break;
159
+ }
160
+ case 'insert':
161
+ {
162
+ handleInsert(editor, _objectSpread(_objectSpread({}, item), {}, {
163
+ delay: true
164
+ }), dataSource);
165
+ break;
166
+ }
167
+ default:
168
+ {
169
+ logger.warn("\u26A0\uFE0F Unknown action type: ".concat(action));
170
+ }
171
+ }
172
+ });
173
+ return false;
174
+ } catch (error) {
175
+ logger.error('❌ Error processing LITEXML_MODIFY_COMMAND:', error);
176
+ return false;
177
+ }
172
178
  }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(LITEXML_APPLY_COMMAND, function (payload) {
173
179
  var litexml = payload.litexml,
174
180
  delay = payload.delay;
@@ -297,9 +303,18 @@ function handleRemove(editor, key, delay) {
297
303
  }
298
304
  return;
299
305
  }
300
- var diffNode = $createDiffNode('remove');
301
- diffNode.append($cloneNode(node, editor));
302
- node.replace(diffNode, false);
306
+ if ($isListItemNode(node)) {
307
+ var diffNode = $createDiffNode('listItemRemove');
308
+ node.getChildren().forEach(function (child) {
309
+ diffNode.append($cloneNode(child, editor));
310
+ });
311
+ node.clear();
312
+ node.append(diffNode);
313
+ } else {
314
+ var _diffNode2 = $createDiffNode('remove');
315
+ _diffNode2.append($cloneNode(node, editor));
316
+ node.replace(_diffNode2, false);
317
+ }
303
318
  } else {
304
319
  var oldBlock = $closest(node, function (node) {
305
320
  return node.isInline() === false;
@@ -409,9 +424,18 @@ function handleInsert(editor, payload, dataSource) {
409
424
  }
410
425
  newNodes.forEach(function (node) {
411
426
  if (referenceNode) {
412
- var diffNode = $createDiffNode('add');
413
- diffNode.append(node);
414
- referenceNode = referenceNode.insertAfter(diffNode);
427
+ if ($isListItemNode(node)) {
428
+ var diffNode = $createDiffNode('listItemAdd');
429
+ node.getChildren().forEach(function (child) {
430
+ diffNode.append(child);
431
+ });
432
+ node.append(diffNode);
433
+ referenceNode = referenceNode.insertAfter(node);
434
+ } else {
435
+ var _diffNode3 = $createDiffNode('add');
436
+ _diffNode3.append(node);
437
+ referenceNode = referenceNode.insertAfter(_diffNode3);
438
+ }
415
439
  }
416
440
  });
417
441
  } else {
@@ -1,6 +1,6 @@
1
1
  import { DOMExportOutput, EditorConfig, ElementDOMSlot, LexicalEditor, LexicalUpdateJSON, SerializedElementNode, Spread } from 'lexical';
2
2
  import { CardLikeElementNode } from "../../common/node/cursor";
3
- export type DiffType = 'add' | 'remove' | 'modify' | 'unchanged' | 'listItemModify';
3
+ export type DiffType = 'add' | 'remove' | 'modify' | 'unchanged' | 'listItemModify' | 'listItemRemove' | 'listItemAdd';
4
4
  export type SerializedDiffNode = Spread<{
5
5
  diffType: DiffType;
6
6
  }, SerializedElementNode>;
@@ -4,5 +4,5 @@ import { createStaticStyles } from 'antd-style';
4
4
  export var styles = createStaticStyles(function (_ref) {
5
5
  var css = _ref.css,
6
6
  cssVar = _ref.cssVar;
7
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: 0;\n inset-inline-end: 8px;\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n &[data-diff-type='listItemModify'] {\n display: inline-block;\n\n p {\n display: block !important;\n }\n }\n\n &[data-diff-type='listItemModify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), cssVar.colorSuccess, cssVar.colorError, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary);
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: 0;\n inset-inline-end: 8px;\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n\n &[data-diff-type='listItemRemove'] {\n display: inline-block;\n }\n\n &[data-diff-type='listItemRemove'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n\n &[data-diff-type='listItemModify'] {\n display: inline-block;\n\n p {\n display: block !important;\n }\n }\n\n &[data-diff-type='listItemModify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), cssVar.colorSuccess, cssVar.colorError, cssVar.colorTextQuaternary, cssVar.colorError, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary, cssVar.colorWarning, cssVar.colorTextQuaternary);
8
8
  });
@@ -7,6 +7,7 @@ export default class MarkdownDataSource extends DataSource {
7
7
  protected dataType: string;
8
8
  protected markdownService: MarkdownShortCutService;
9
9
  protected getService?: (<T>(serviceId: IServiceID<T>) => T | null) | undefined;
10
+ private formatMarkdown;
10
11
  constructor(dataType: string, markdownService: MarkdownShortCutService, getService?: (<T>(serviceId: IServiceID<T>) => T | null) | undefined);
11
12
  read(editor: LexicalEditor, data: string): void;
12
13
  write(editor: LexicalEditor, options?: IWriteOptions): any;
@@ -27,6 +27,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
27
27
  /* eslint-disable unicorn/no-for-loop */
28
28
  import { $isTableSelection } from '@lexical/table';
29
29
  import { $getCharacterOffsets, $getNodeByKey, $getRoot, $getSelection, $isElementNode, $isRangeSelection, $isTextNode } from 'lexical';
30
+ import { remark } from 'remark';
31
+ import remarkGfm from 'remark-gfm';
30
32
  import { DataSource } from "../../../editor-kernel";
31
33
  import { INodeHelper } from "../../../editor-kernel/inode/helper";
32
34
  import { INodeService } from "../../inode";
@@ -46,6 +48,26 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
46
48
  return _this;
47
49
  }
48
50
  _createClass(MarkdownDataSource, [{
51
+ key: "formatMarkdown",
52
+ value: function formatMarkdown(markdown) {
53
+ try {
54
+ var result = remark().use([[remarkGfm, {
55
+ singleTilde: false
56
+ }]]).data('settings', {
57
+ bullet: '-',
58
+ emphasis: '*',
59
+ fences: true,
60
+ rule: '-',
61
+ strong: '*',
62
+ tightDefinitions: true
63
+ }).processSync(markdown);
64
+ return String(result);
65
+ } catch (error) {
66
+ logger.error('Failed to format markdown:', error);
67
+ return markdown;
68
+ }
69
+ }
70
+ }, {
49
71
  key: "read",
50
72
  value: function read(editor, data) {
51
73
  var _this$getService;
@@ -179,7 +201,7 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
179
201
  _lexicalRootNode.getChildren().forEach(function (child) {
180
202
  return _rootCtx.processChild(_rootCtx, child);
181
203
  });
182
- return _rootCtx.toString();
204
+ return _this2.formatMarkdown(_rootCtx.toString());
183
205
  });
184
206
  } else if ($isTableSelection(selection)) {
185
207
  // todo
@@ -217,7 +239,7 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
217
239
  rootNode.getChildren().forEach(function (child) {
218
240
  return rootCtx.processChild(rootCtx, child);
219
241
  });
220
- return rootCtx.toString();
242
+ return _this2.formatMarkdown(rootCtx.toString());
221
243
  });
222
244
  }
223
245
  }]);
@@ -4,6 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  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; }
5
5
  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; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { cx } from 'antd-style';
7
8
  import { CLICK_COMMAND, COMMAND_PRIORITY_LOW } from 'lexical';
8
9
  import { useCallback, useEffect, useRef } from 'react';
9
10
  import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
@@ -30,7 +31,7 @@ var Mention = function Mention(_ref) {
30
31
  return editor.registerCommand(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW);
31
32
  }, [editor, node, onClick]);
32
33
  return /*#__PURE__*/_jsxs("span", {
33
- className: className,
34
+ className: cx('editor_mention', className),
34
35
  ref: spanRef,
35
36
  children: ["@", node.label]
36
37
  });
@@ -6,6 +6,6 @@ export var styles = createStaticStyles(function (_ref) {
6
6
  var css = _ref.css,
7
7
  cssVar = _ref.cssVar;
8
8
  return {
9
- mention: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n position: relative;\n\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-size: 0.875em;\n line-height: 1;\n color: ", ";\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n\n &.selected {\n color: #000;\n background: ", ";\n }\n "])), cssVar.colorFillTertiary, cssVar.colorInfo, cssVar.colorFillTertiary, cssVar.yellow)
9
+ mention: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n position: relative;\n\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-size: 0.875em;\n line-height: 1;\n color: ", ";\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n\n .editor_mention {\n padding: 0;\n }\n\n &.selected {\n color: #000;\n background: ", ";\n }\n "])), cssVar.colorInfoBgHover, cssVar.colorInfo, cssVar.colorInfoBg, cssVar.yellow)
10
10
  };
11
11
  });
@@ -47,7 +47,7 @@ export var ReactTablePlugin = function ReactTablePlugin(_ref) {
47
47
  useLexicalEditor(function (editor) {
48
48
  setLexicalEditor(editor);
49
49
  editor.registerUpdateListener(function () {
50
- editor.getEditorState().read(function () {
50
+ editor.read(function () {
51
51
  var selection = $getSelection();
52
52
  if (!$isTableSelection(selection) && !$isRangeSelection(selection)) {
53
53
  return null;
@@ -15,6 +15,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
15
15
  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; }
16
16
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
17
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+ import { debounce } from 'es-toolkit';
18
19
  import { createElement, memo, useMemo } from 'react';
19
20
  import { ReactEditor } from "../../editor-kernel/react/react-editor";
20
21
  import { ReactEditorContent, ReactPlainText } from "../../plugins/common";
@@ -29,6 +30,8 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
29
30
  var content = _ref.content,
30
31
  style = _ref.style,
31
32
  className = _ref.className,
33
+ _ref$debounceWait = _ref.debounceWait,
34
+ debounceWait = _ref$debounceWait === void 0 ? 100 : _ref$debounceWait,
32
35
  editable = _ref.editable,
33
36
  editor = _ref.editor,
34
37
  onInit = _ref.onInit,
@@ -64,6 +67,14 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
64
67
  var enableMention = Boolean((mentionOption === null || mentionOption === void 0 ? void 0 : mentionOption.items) && mentionOption.items.length > 0);
65
68
  var markdownWriter = mentionOption.markdownWriter,
66
69
  restMentionOption = _objectWithoutProperties(mentionOption, _excluded);
70
+
71
+ // Create debounced versions of onChange and onTextChange
72
+ var debouncedOnChange = useMemo(function () {
73
+ return onChange ? debounce(onChange, debounceWait) : undefined;
74
+ }, [onChange, debounceWait]);
75
+ var debouncedOnTextChange = useMemo(function () {
76
+ return onTextChange ? debounce(onTextChange, debounceWait) : undefined;
77
+ }, [onTextChange, debounceWait]);
67
78
  var memoPlugins = useMemo(function () {
68
79
  return [enablePasteMarkdown && ReactMarkdownPlugin].concat(_toConsumableArray(plugins)).filter(Boolean).map(function (plugin, index) {
69
80
  var withNoProps = typeof plugin === 'function';
@@ -105,14 +116,14 @@ var Editor = /*#__PURE__*/memo(function (_ref) {
105
116
  enablePasteMarkdown: enablePasteMarkdown,
106
117
  markdownOption: markdownOption,
107
118
  onBlur: onBlur,
108
- onChange: onChange,
119
+ onChange: debouncedOnChange,
109
120
  onCompositionEnd: onCompositionEnd,
110
121
  onCompositionStart: onCompositionStart,
111
122
  onContextMenu: onContextMenu,
112
123
  onFocus: onFocus,
113
124
  onKeyDown: onKeyDown,
114
125
  onPressEnter: onPressEnter,
115
- onTextChange: onTextChange,
126
+ onTextChange: debouncedOnTextChange,
116
127
  style: style,
117
128
  variant: variant,
118
129
  children: /*#__PURE__*/_jsx(ReactEditorContent, {
@@ -11,6 +11,11 @@ export interface EditorProps extends Partial<ReactEditorContentProps>, Omit<Reac
11
11
  autoFocus?: boolean;
12
12
  children?: ReactNode;
13
13
  className?: string;
14
+ /**
15
+ * Debounce wait time in milliseconds for onChange and onTextChange callbacks
16
+ * @default 100
17
+ */
18
+ debounceWait?: number;
14
19
  editable?: boolean;
15
20
  editor?: IEditor;
16
21
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "3.4.1",
3
+ "version": "3.5.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",
@@ -56,7 +56,7 @@
56
56
  "lucide-react": "^0.562.0",
57
57
  "polished": "^4.3.1",
58
58
  "re-resizable": "^6.11.2",
59
- "react-error-boundary": "^6.0.0",
59
+ "react-error-boundary": "^6.0.2",
60
60
  "react-merge-refs": "^3.0.2",
61
61
  "remark-cjk-friendly": "^1.2.3",
62
62
  "remark-supersub": "^1.0.0",