@lobehub/editor 3.6.0 → 3.8.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.
package/es/global.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ declare module 'lexical' {
2
+ export function resetRandomKey(key?: number): void;
3
+ }
4
+
5
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { $findMatchingParent, mergeRegister } from '@lexical/utils';
2
- import { $getNodeByKey, $getSelection, $insertNodes, $isRangeSelection, $setSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
2
+ import { $createNodeSelection, $createParagraphNode, $getNodeByKey, $getSelection, $insertNodes, $isRangeSelection, $setSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
3
3
  import { UPDATE_CODEBLOCK_LANG } from "../../codeblock";
4
4
  import { $createCodeMirrorNode, $isCodeMirrorNode } from "../node/CodeMirrorNode";
5
5
  export var INSERT_CODEMIRROR_COMMAND = createCommand('INSERT_CODEMIRROR_COMMAND');
@@ -10,6 +10,12 @@ export function registerCodeMirrorCommand(editor) {
10
10
  editor.update(function () {
11
11
  var codeMirrorNode = $createCodeMirrorNode('', '');
12
12
  $insertNodes([codeMirrorNode]);
13
+
14
+ // Select the inserted CodeMirror node so the React decorator can
15
+ // focus into the CodeMirror instance (caret stays "inside" the block).
16
+ var selection = $createNodeSelection();
17
+ selection.add(codeMirrorNode.getKey());
18
+ $setSelection(selection);
13
19
  });
14
20
  return true;
15
21
  }, COMMAND_PRIORITY_EDITOR // Priority
@@ -65,10 +71,19 @@ export function registerCodeMirrorCommand(editor) {
65
71
  return;
66
72
  }
67
73
  var nextNode = node.getNextSibling();
68
- var sel = nextNode === null || nextNode === void 0 ? void 0 : nextNode.selectStart();
69
- console.info('SELECT_AFTER_CODEMIRROR_COMMAND', sel, nextNode, node);
70
- if (sel) {
71
- $setSelection(sel);
74
+ var selection = nextNode === null || nextNode === void 0 ? void 0 : nextNode.selectStart();
75
+
76
+ // If there is no next sibling (e.g. codeblock at end), create a new paragraph
77
+ // after the codeblock and move caret into it.
78
+ if (selection) {
79
+ $setSelection(selection);
80
+ } else {
81
+ var paragraph = $createParagraphNode();
82
+ node.insertAfter(paragraph);
83
+ var paragraphSelection = paragraph.selectStart();
84
+ if (paragraphSelection) {
85
+ $setSelection(paragraphSelection);
86
+ }
72
87
  }
73
88
  editor.focus();
74
89
  });
@@ -197,6 +197,20 @@ var ReactCodemirrorNode = function ReactCodemirrorNode(_ref) {
197
197
  instance.on('keydown', function (instance, e) {
198
198
  e.stopPropagation();
199
199
 
200
+ // Cmd+Enter / Ctrl+Enter: exit codeblock (move caret after the block)
201
+ if ((e.key === 'Enter' || e.keyCode === 13) && (e.metaKey || e.ctrlKey)) {
202
+ var _instanceRef$current3;
203
+ e.preventDefault();
204
+ (_instanceRef$current3 = instanceRef.current) === null || _instanceRef$current3 === void 0 || _instanceRef$current3.blur();
205
+ editor.dispatchCommand(SELECT_AFTER_CODEMIRROR_COMMAND, {
206
+ key: node.getKey()
207
+ });
208
+ queueMicrotask(function () {
209
+ editor.focus();
210
+ });
211
+ return;
212
+ }
213
+
200
214
  // 当代码块为空且按退格键时,删除代码块节点
201
215
  if (e.key === 'Backspace' || e.keyCode === 8) {
202
216
  // 检查代码内容是否为空(使用 ref 中存储的状态)
@@ -222,8 +236,8 @@ var ReactCodemirrorNode = function ReactCodemirrorNode(_ref) {
222
236
  }
223
237
  });
224
238
  instance.on('leftOut', function () {
225
- var _instanceRef$current3;
226
- (_instanceRef$current3 = instanceRef.current) === null || _instanceRef$current3 === void 0 || _instanceRef$current3.blur();
239
+ var _instanceRef$current4;
240
+ (_instanceRef$current4 = instanceRef.current) === null || _instanceRef$current4 === void 0 || _instanceRef$current4.blur();
227
241
  editor.dispatchCommand(SELECT_BEFORE_CODEMIRROR_COMMAND, {
228
242
  key: node.getKey()
229
243
  });
@@ -232,8 +246,8 @@ var ReactCodemirrorNode = function ReactCodemirrorNode(_ref) {
232
246
  });
233
247
  });
234
248
  instance.on('rightOut', function () {
235
- var _instanceRef$current4;
236
- (_instanceRef$current4 = instanceRef.current) === null || _instanceRef$current4 === void 0 || _instanceRef$current4.blur();
249
+ var _instanceRef$current5;
250
+ (_instanceRef$current5 = instanceRef.current) === null || _instanceRef$current5 === void 0 || _instanceRef$current5.blur();
237
251
  editor.dispatchCommand(SELECT_AFTER_CODEMIRROR_COMMAND, {
238
252
  key: node.getKey()
239
253
  });
@@ -8,13 +8,13 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
8
8
  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); }
9
9
  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; }
10
10
  /* eslint-disable @typescript-eslint/no-use-before-define */
11
+ import { $isListItemNode } from '@lexical/list';
11
12
  import { mergeRegister } from '@lexical/utils';
12
13
  import { $createParagraphNode, $getNodeByKey, $insertNodes, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
13
14
  import { $closest } from "../../../editor-kernel";
14
15
  import { createDebugLogger } from "../../../utils/debug";
15
16
  import { $createDiffNode, DiffNode } from "../node/DiffNode";
16
17
  import { $cloneNode, $parseSerializedNodeImpl, charToId } from "../utils";
17
- import { $isListItemNode } from '@lexical/list';
18
18
  var logger = createDebugLogger('plugin', 'litexml');
19
19
 
20
20
  // Helpers to reduce duplication and improve readability
@@ -113,6 +113,22 @@ function finalizeModifyBlocks(modifyBlockNodes, diffNodeMap, editor) {
113
113
  * transitions where we want to show a modify diff.
114
114
  */
115
115
  function wrapBlockModify(oldBlock, editor, changeFn) {
116
+ if ($isListItemNode(oldBlock)) {
117
+ var _diffNode2 = $createDiffNode('listItemModify');
118
+ var p = $createParagraphNode();
119
+ oldBlock.getChildren().forEach(function (child) {
120
+ p.append($cloneNode(child, editor));
121
+ });
122
+ changeFn();
123
+ _diffNode2.append(p);
124
+ var pNew = $createParagraphNode();
125
+ oldBlock.getChildren().forEach(function (child) {
126
+ pNew.append(child);
127
+ });
128
+ _diffNode2.append(pNew);
129
+ oldBlock.append(_diffNode2);
130
+ return;
131
+ }
116
132
  var diffNode = $createDiffNode('modify');
117
133
  diffNode.append($cloneNode(oldBlock, editor));
118
134
  changeFn();
@@ -311,9 +327,9 @@ function handleRemove(editor, key, delay) {
311
327
  node.clear();
312
328
  node.append(diffNode);
313
329
  } else {
314
- var _diffNode2 = $createDiffNode('remove');
315
- _diffNode2.append($cloneNode(node, editor));
316
- node.replace(_diffNode2, false);
330
+ var _diffNode3 = $createDiffNode('remove');
331
+ _diffNode3.append($cloneNode(node, editor));
332
+ node.replace(_diffNode3, false);
317
333
  }
318
334
  } else {
319
335
  var oldBlock = $closest(node, function (node) {
@@ -432,9 +448,9 @@ function handleInsert(editor, payload, dataSource) {
432
448
  node.append(diffNode);
433
449
  referenceNode = referenceNode.insertAfter(node);
434
450
  } else {
435
- var _diffNode3 = $createDiffNode('add');
436
- _diffNode3.append(node);
437
- referenceNode = referenceNode.insertAfter(_diffNode3);
451
+ var _diffNode4 = $createDiffNode('add');
452
+ _diffNode4.append(node);
453
+ referenceNode = referenceNode.insertAfter(_diffNode4);
438
454
  }
439
455
  }
440
456
  });
@@ -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\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);
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='listItemRemove'] {\n display: inline-block;\n min-width: 100%;\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 min-width: 100%;\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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "3.6.0",
3
+ "version": "3.8.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",