@lobehub/editor 2.0.5 → 2.1.1

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.
@@ -136,7 +136,7 @@ export var AutoCompletePlugin = (_class = /*#__PURE__*/function (_KernelPlugin)
136
136
  key: "handleCursorStable",
137
137
  value: function handleCursorStable(editor, position) {
138
138
  var _this3 = this;
139
- editor.read(function () {
139
+ editor.getEditorState().read(function () {
140
140
  var _this3$config;
141
141
  if (editor.isComposing()) {
142
142
  return;
@@ -140,7 +140,7 @@ export function getCodeInlineNode(node) {
140
140
  return null;
141
141
  }
142
142
  export function $isSelectionInCodeInline(editor) {
143
- return editor.read(function () {
143
+ return editor.getEditorState().read(function () {
144
144
  var selection = $getSelection();
145
145
  if (!selection) {
146
146
  return false;
@@ -16,7 +16,7 @@ export function registerCodeInline(editor, kernel, options) {
16
16
  var codeChanged = mutatedNodes === null || mutatedNodes === void 0 ? void 0 : mutatedNodes.get(CodeNode);
17
17
  var keys = (codeChanged === null || codeChanged === void 0 ? void 0 : codeChanged.keys()) || [];
18
18
  var needAddBefore = new Set();
19
- editor.read(function () {
19
+ editor.getEditorState().read(function () {
20
20
  var _iterator = _createForOfIteratorHelper(keys),
21
21
  _step;
22
22
  try {
@@ -35,7 +35,7 @@ function getAllCodeNode(rootNode) {
35
35
  export function registerCodeCommand(editor) {
36
36
  var unregisterLangCommand = editor.registerCommand(UPDATE_CODEBLOCK_LANG, function (payload) {
37
37
  CustomShikiTokenizer.defaultLanguage = payload.lang;
38
- var codeNode = editor.read(function () {
38
+ var codeNode = editor.getEditorState().read(function () {
39
39
  var selection = $getSelection();
40
40
  if ($isRangeSelection(selection)) {
41
41
  if (selection.isCollapsed()) {
@@ -164,7 +164,7 @@ function codeNodeTransform(node, editor, tokenizer) {
164
164
  if (!next) return;
165
165
  waitingNodesCurrentlyHighlighting.delete(next);
166
166
  requestAnimationFrame(function () {
167
- editor.read(function () {
167
+ editor.getEditorState().read(function () {
168
168
  codeNodeTransform($getNodeByKey(next), editor, tokenizer);
169
169
  });
170
170
  });
@@ -98,7 +98,7 @@ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
98
98
  if (!(event instanceof ClipboardEvent)) return false;
99
99
  var clipboardData = event.clipboardData;
100
100
  if (!clipboardData) return false;
101
- var isInHighlightNodeSelection = editor.read(function () {
101
+ var isInHighlightNodeSelection = editor.getEditorState().read(function () {
102
102
  var sel = $getSelection();
103
103
  if (!$isRangeSelection(sel)) {
104
104
  return false;
@@ -69,7 +69,7 @@ var JSONDataSource = /*#__PURE__*/function (_DataSource) {
69
69
  key: "write",
70
70
  value: function write(editor, options) {
71
71
  if (options !== null && options !== void 0 && options.selection) {
72
- return editor.read(function () {
72
+ return editor.getEditorState().read(function () {
73
73
  var selection = $getSelection();
74
74
  if (!selection) {
75
75
  return null;
@@ -45,7 +45,7 @@ var TextDataSource = /*#__PURE__*/function (_DataSource) {
45
45
  key: "write",
46
46
  value: function write(editor, options) {
47
47
  if (options !== null && options !== void 0 && options.selection) {
48
- return editor.read(function () {
48
+ return editor.getEditorState().read(function () {
49
49
  var selection = $getSelection();
50
50
  return selection ? selection.getTextContent().replaceAll("\uFEFF", '') : null;
51
51
  });
@@ -78,7 +78,7 @@ export function $isCursorNode(node) {
78
78
  export function registerCursorNode(editor) {
79
79
  return mergeRegister(editor.registerUpdateListener(function (_ref) {
80
80
  var mutatedNodes = _ref.mutatedNodes;
81
- editor.read(function () {
81
+ editor.getEditorState().read(function () {
82
82
  if (!mutatedNodes) return;
83
83
  var needAddCursor = [];
84
84
  var _iterator = _createForOfIteratorHelper(mutatedNodes),
@@ -126,7 +126,7 @@ export function registerCursorNode(editor) {
126
126
  });
127
127
  }), editor.registerUpdateListener(function (_ref2) {
128
128
  var mutatedNodes = _ref2.mutatedNodes;
129
- editor.read(function () {
129
+ editor.getEditorState().read(function () {
130
130
  var cursorNodes = mutatedNodes === null || mutatedNodes === void 0 ? void 0 : mutatedNodes.get(CursorNode);
131
131
  var needRemove = new Set();
132
132
  if (cursorNodes) {
@@ -169,7 +169,7 @@ export function registerCursorNode(editor) {
169
169
  return false;
170
170
  });
171
171
  }), editor.registerUpdateListener(function () {
172
- editor.read(function () {
172
+ editor.getEditorState().read(function () {
173
173
  var selection = $getSelection();
174
174
  var isComposing = editor.isComposing();
175
175
  if (isComposing) {
@@ -332,7 +332,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
332
332
  // Convert soft line breaks (Shift+Enter) to hard line breaks (paragraph breaks)
333
333
  // This allows breaking out of code blocks with Shift+Enter
334
334
  editor.registerCommand(INSERT_LINE_BREAK_COMMAND, function () {
335
- // editor.read(() => {
335
+ // editor.getEditorState().read(() => {
336
336
  var selection = $getSelection();
337
337
  if (!$isRangeSelection(selection)) {
338
338
  return false;
@@ -96,7 +96,7 @@ function $isSelectionAtEndOfRoot(selection) {
96
96
  export function registerHeaderBackspace(editor) {
97
97
  return editor.registerCommand(KEY_BACKSPACE_COMMAND, function (payload) {
98
98
  // Handle backspace key press for heading nodes
99
- var headingNode = editor.read(function () {
99
+ var headingNode = editor.getEditorState().read(function () {
100
100
  var selection = $getSelection();
101
101
  // Do not handle non-collapsed selection
102
102
  if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
@@ -378,7 +378,7 @@ export function registerLastElement(editor) {
378
378
  return;
379
379
  }
380
380
  if (isProcessing) return;
381
- var needsParagraph = editor.read(function () {
381
+ var needsParagraph = editor.getEditorState().read(function () {
382
382
  var root = $getRoot();
383
383
  var lastChild = root.getLastChild();
384
384
 
@@ -50,7 +50,7 @@ var Placeholder = /*#__PURE__*/memo(function (_ref) {
50
50
  return mergeRegister(editor.registerUpdateListener(function () {
51
51
  var show = resetCanShowPlaceholder();
52
52
  if (!show && lineEmptyPlaceholder) {
53
- editor.read(function () {
53
+ editor.getEditorState().read(function () {
54
54
  var sel = $getSelection();
55
55
  if ($isRangeSelection(sel) && sel.isCollapsed()) {
56
56
  var anchor = sel.anchor;
@@ -19,12 +19,12 @@ export function registerLinkCommands(editor, kernel, options) {
19
19
  isLink: false
20
20
  };
21
21
  var registrations = [editor.registerUpdateListener(function () {
22
- var selection = editor.read(function () {
22
+ var selection = editor.getEditorState().read(function () {
23
23
  return $getSelection();
24
24
  });
25
25
  if (!selection) return;
26
26
  if ($isRangeSelection(selection)) {
27
- editor.read(function () {
27
+ editor.getEditorState().read(function () {
28
28
  var node = getSelectedNode(selection);
29
29
  var parent = node.getParent();
30
30
  var isLink = $isLinkNode(parent) || $isLinkNode(node);
@@ -5,7 +5,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
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
7
  import { mergeRegister } from '@lexical/utils';
8
- import { Block, Button, Hotkey, Icon, Input, Text, Flexbox } from '@lobehub/ui';
8
+ import { Block, Button, Flexbox, Hotkey, Icon, Input, Text } from '@lobehub/ui';
9
9
  import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, createCommand } from 'lexical';
10
10
  import { BaselineIcon, LinkIcon } from 'lucide-react';
11
11
  import { memo, useCallback, useEffect, useRef, useState } from 'react';
@@ -64,7 +64,7 @@ var LinkEdit = /*#__PURE__*/memo(function (_ref) {
64
64
  var textInputDOM = textInput.input;
65
65
 
66
66
  // 更新链接URL
67
- var currentURL = editor.read(function () {
67
+ var currentURL = editor.getEditorState().read(function () {
68
68
  return linkNode.getURL();
69
69
  });
70
70
  if (currentURL !== inputDOM.value) {
@@ -74,7 +74,7 @@ var LinkEdit = /*#__PURE__*/memo(function (_ref) {
74
74
  }
75
75
 
76
76
  // 更新链接文本
77
- var currentText = editor.read(function () {
77
+ var currentText = editor.getEditorState().read(function () {
78
78
  return linkNode.getTextContent();
79
79
  });
80
80
  if (currentText !== textInputDOM.value) {
@@ -104,7 +104,7 @@ var LinkEdit = /*#__PURE__*/memo(function (_ref) {
104
104
  {
105
105
  event.preventDefault();
106
106
  if (event.currentTarget === textInputDOM) {
107
- var currentText = editor.read(function () {
107
+ var currentText = editor.getEditorState().read(function () {
108
108
  return linkNode.getTextContent();
109
109
  });
110
110
  if (currentText !== textInputDOM.value) {
@@ -88,7 +88,7 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
88
88
  }, [editor, linkNode]);
89
89
  var handleOpenLink = useCallback(function () {
90
90
  if (!linkNode) return;
91
- var url = editor.read(function () {
91
+ var url = editor.getEditorState().read(function () {
92
92
  return linkNode.getURL();
93
93
  });
94
94
  window.open(url, '_blank');
@@ -96,13 +96,13 @@ var LinkToolbar = /*#__PURE__*/memo(function (_ref) {
96
96
  useLexicalEditor(function (editor) {
97
97
  if (!editable) return;
98
98
  return mergeRegister(editor.registerUpdateListener(function () {
99
- var selection = editor.read(function () {
99
+ var selection = editor.getEditorState().read(function () {
100
100
  return $getSelection();
101
101
  });
102
102
  if (!selection) return;
103
103
  if ($isRangeSelection(selection)) {
104
104
  // Update links for UI components
105
- editor.read(function () {
105
+ editor.getEditorState().read(function () {
106
106
  var node = getSelectedNode(selection);
107
107
  var parent = node.getParent();
108
108
  var isLink = $isLinkNode(parent) || $isLinkNode(node);
@@ -154,7 +154,7 @@ export function getLinkHighlightNode(node) {
154
154
  return null;
155
155
  }
156
156
  export function $isSelectionInLinkHighlight(editor) {
157
- return editor.read(function () {
157
+ return editor.getEditorState().read(function () {
158
158
  var selection = $getSelection();
159
159
  if (!selection) {
160
160
  return false;
@@ -18,7 +18,7 @@ export function registerLinkHighlight(editor, kernel, options) {
18
18
  var linkHighlightChanged = mutatedNodes === null || mutatedNodes === void 0 ? void 0 : mutatedNodes.get(LinkHighlightNode);
19
19
  var keys = (linkHighlightChanged === null || linkHighlightChanged === void 0 ? void 0 : linkHighlightChanged.keys()) || [];
20
20
  var needAddBefore = new Set();
21
- editor.read(function () {
21
+ editor.getEditorState().read(function () {
22
22
  var _iterator = _createForOfIteratorHelper(keys),
23
23
  _step;
24
24
  try {
@@ -66,7 +66,7 @@ export function registerLiteXMLDiffCommand(editor) {
66
66
  return mergeRegister(editor.registerCommand(LITEXML_DIFFNODE_COMMAND, function (payload) {
67
67
  var action = payload.action,
68
68
  nodeKey = payload.nodeKey;
69
- var node = editor.read(function () {
69
+ var node = editor.getEditorState().read(function () {
70
70
  return $getNodeByKey(nodeKey);
71
71
  });
72
72
  if (!node) {
@@ -78,7 +78,7 @@ export function registerLiteXMLDiffCommand(editor) {
78
78
  return false;
79
79
  }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(LITEXML_DIFFNODE_ALL_COMMAND, function (payload) {
80
80
  var action = payload.action;
81
- var nodes = editor.read(function () {
81
+ var nodes = editor.getEditorState().read(function () {
82
82
  return Array.from(editor._editorState._nodeMap.values()).filter(function (n) {
83
83
  return n instanceof DiffNode && !!n.getParent();
84
84
  });
@@ -116,7 +116,7 @@ var LitexmlDataSource = /*#__PURE__*/function (_DataSource) {
116
116
  var _this2 = this;
117
117
  try {
118
118
  if (options !== null && options !== void 0 && options.selection) {
119
- return editor.read(function () {
119
+ return editor.getEditorState().read(function () {
120
120
  var selection = $getSelection();
121
121
  if (!selection) {
122
122
  return null;
@@ -80,7 +80,7 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
80
80
  }
81
81
  };
82
82
  if (options !== null && options !== void 0 && options.selection) {
83
- return editor.read(function () {
83
+ return editor.getEditorState().read(function () {
84
84
  var selection = $getSelection();
85
85
  if (!selection) {
86
86
  return null;
@@ -84,7 +84,7 @@ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
84
84
  });
85
85
  }));
86
86
  this.register(editor.registerCommand(KEY_ENTER_COMMAND, function (payload) {
87
- var ret = editor.read(function () {
87
+ var ret = editor.getEditorState().read(function () {
88
88
  var selection = $getSelection();
89
89
  if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
90
90
  return false;
@@ -182,7 +182,7 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
182
182
  }
183
183
 
184
184
  // Handle editor state updates
185
- var canEdit = editor.read(function () {
185
+ var canEdit = editor.getEditorState().read(function () {
186
186
  var selection = $getSelection();
187
187
  if (!$isNodeSelection(selection)) {
188
188
  return false;
@@ -215,7 +215,7 @@ var MathEdit = /*#__PURE__*/memo(function (_ref) {
215
215
  var node = sel.anchor.key;
216
216
  return node;
217
217
  });
218
- editor.read(function () {
218
+ editor.getEditorState().read(function () {
219
219
  var anchorNode = anchorNodeKey ? $getNodeByKey(anchorNodeKey) : null;
220
220
  var isPrev = anchorNode && compareNodeOrder(anchorNode, canEdit) < 0;
221
221
  if (isPrev) {
@@ -81,7 +81,7 @@ var MathInline = /*#__PURE__*/memo(function (_ref) {
81
81
  // 监听编辑器状态变化来检测编辑状态
82
82
  useLexicalEditor(function (editor) {
83
83
  return editor.registerUpdateListener(function () {
84
- editor.read(function () {
84
+ editor.getEditorState().read(function () {
85
85
  var selection = $getSelection();
86
86
  if (!$isNodeSelection(selection)) {
87
87
  setIsEditing(false);
@@ -49,7 +49,7 @@ export var ReactTablePlugin = function ReactTablePlugin(_ref) {
49
49
  useLexicalEditor(function (editor) {
50
50
  setLexicalEditor(editor);
51
51
  editor.registerUpdateListener(function () {
52
- editor.read(function () {
52
+ editor.getEditorState().read(function () {
53
53
  var selection = $getSelection();
54
54
  if (!$isTableSelection(selection) && !$isRangeSelection(selection)) {
55
55
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "2.0.5",
3
+ "version": "2.1.1",
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",
@@ -29,16 +29,16 @@
29
29
  "dependencies": {
30
30
  "@floating-ui/dom": "^1.7.4",
31
31
  "@floating-ui/react": "^0.27.16",
32
- "@lexical/code": "^0.38.2",
33
- "@lexical/code-shiki": "^0.38.2",
34
- "@lexical/dragon": "^0.38.2",
35
- "@lexical/history": "^0.38.2",
36
- "@lexical/link": "^0.38.2",
37
- "@lexical/list": "^0.38.2",
38
- "@lexical/rich-text": "^0.38.2",
39
- "@lexical/selection": "^0.38.2",
40
- "@lexical/table": "^0.38.2",
41
- "@lexical/utils": "^0.38.2",
32
+ "@lexical/code": "^0.39.0",
33
+ "@lexical/code-shiki": "^0.39.0",
34
+ "@lexical/dragon": "^0.39.0",
35
+ "@lexical/history": "^0.39.0",
36
+ "@lexical/link": "^0.39.0",
37
+ "@lexical/list": "^0.39.0",
38
+ "@lexical/rich-text": "^0.39.0",
39
+ "@lexical/selection": "^0.39.0",
40
+ "@lexical/table": "^0.39.0",
41
+ "@lexical/utils": "^0.39.0",
42
42
  "@shikijs/core": "^3.20.0",
43
43
  "@shikijs/engine-javascript": "^3.20.0",
44
44
  "@xmldom/xmldom": "^0.8.11",
@@ -48,7 +48,7 @@
48
48
  "eventemitter3": "^5.0.1",
49
49
  "fuse.js": "^7.1.0",
50
50
  "katex": "^0.16.27",
51
- "lexical": "^0.38.2",
51
+ "lexical": "^0.39.0",
52
52
  "lodash-es": "^4.17.22",
53
53
  "lucide-react": "^0.562.0",
54
54
  "motion": "^12.23.26",