@lobehub/editor 1.4.7 → 1.5.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.
Files changed (98) hide show
  1. package/es/editor-kernel/kernel.d.ts +4 -1
  2. package/es/editor-kernel/kernel.js +56 -1
  3. package/es/index.d.ts +2 -0
  4. package/es/index.js +2 -0
  5. package/es/locale/index.d.ts +7 -0
  6. package/es/locale/index.js +7 -0
  7. package/es/plugins/code/command/index.d.ts +3 -0
  8. package/es/plugins/code/command/index.js +48 -0
  9. package/es/plugins/code/index.d.ts +3 -0
  10. package/es/plugins/code/index.js +3 -0
  11. package/es/plugins/code/node/code.d.ts +19 -0
  12. package/es/plugins/{common/node/LexicalLineBreakNode.js → code/node/code.js} +93 -95
  13. package/es/plugins/code/plugin/index.d.ts +5 -0
  14. package/es/plugins/{common/node/ParagraphNode.js → code/plugin/index.js} +40 -33
  15. package/es/plugins/code/plugin/registry.d.ts +3 -0
  16. package/es/plugins/code/plugin/registry.js +48 -0
  17. package/es/plugins/code/react/CodeReactPlugin.d.ts +4 -0
  18. package/es/plugins/code/react/CodeReactPlugin.js +31 -0
  19. package/es/plugins/code/react/index.d.ts +1 -0
  20. package/es/plugins/code/react/index.js +1 -0
  21. package/es/plugins/code/react/style.d.ts +3 -0
  22. package/es/plugins/code/react/style.js +10 -0
  23. package/es/plugins/code/react/type.d.ts +3 -0
  24. package/es/plugins/code/react/type.js +1 -0
  25. package/es/plugins/common/data-source/json-data-source.js +42 -5
  26. package/es/plugins/common/data-source/text-data-source.js +2 -2
  27. package/es/plugins/common/index.d.ts +1 -0
  28. package/es/plugins/common/index.js +1 -0
  29. package/es/plugins/common/node/ElementDOMSlot.d.ts +3 -5
  30. package/es/plugins/common/node/ElementDOMSlot.js +29 -56
  31. package/es/plugins/common/node/cursor.d.ts +12 -0
  32. package/es/plugins/common/node/cursor.js +303 -0
  33. package/es/plugins/common/plugin/index.js +11 -9
  34. package/es/plugins/common/plugin/register.d.ts +3 -1
  35. package/es/plugins/common/plugin/register.js +46 -13
  36. package/es/plugins/link/command/index.d.ts +5 -1
  37. package/es/plugins/link/command/index.js +21 -3
  38. package/es/plugins/link/react/ReactLinkPlugin.js +6 -9
  39. package/es/plugins/link/react/components/LinkEdit.d.ts +2 -1
  40. package/es/plugins/link/react/components/LinkEdit.js +195 -51
  41. package/es/plugins/link/react/components/LinkToolbar.d.ts +10 -0
  42. package/es/plugins/link/react/components/LinkToolbar.js +73 -0
  43. package/es/plugins/link/react/style.d.ts +3 -2
  44. package/es/plugins/link/react/style.js +8 -5
  45. package/es/plugins/list/command/index.d.ts +1 -0
  46. package/es/plugins/list/command/index.js +1 -0
  47. package/es/plugins/list/plugin/checkList.d.ts +3 -0
  48. package/es/plugins/list/plugin/checkList.js +167 -0
  49. package/es/plugins/list/plugin/index.js +9 -2
  50. package/es/plugins/list/react/style.js +4 -2
  51. package/es/plugins/markdown/data-source/markdown-data-source.js +5 -1
  52. package/es/plugins/markdown/service/shortcut.d.ts +3 -3
  53. package/es/plugins/math/command/index.d.ts +13 -0
  54. package/es/plugins/math/command/index.js +47 -0
  55. package/es/plugins/math/index.d.ts +3 -0
  56. package/es/plugins/math/index.js +3 -0
  57. package/es/plugins/math/node/index.d.ts +45 -0
  58. package/es/plugins/math/node/index.js +259 -0
  59. package/es/plugins/math/plugin/index.d.ts +11 -0
  60. package/es/plugins/math/plugin/index.js +103 -0
  61. package/es/plugins/math/react/component/MathEditor.d.ts +10 -0
  62. package/es/plugins/math/react/component/MathEditor.js +253 -0
  63. package/es/plugins/math/react/component/MathEditorContainer.d.ts +14 -0
  64. package/es/plugins/math/react/component/MathEditorContainer.js +60 -0
  65. package/es/plugins/math/react/component/MathEditorContent.d.ts +26 -0
  66. package/es/plugins/math/react/component/MathEditorContent.js +163 -0
  67. package/es/plugins/math/react/component/MathInline.d.ts +10 -0
  68. package/es/plugins/math/react/component/MathInline.js +105 -0
  69. package/es/plugins/math/react/component/Placeholder.d.ts +3 -0
  70. package/es/plugins/math/react/component/Placeholder.js +19 -0
  71. package/es/plugins/math/react/index.d.ts +3 -0
  72. package/es/plugins/math/react/index.js +43 -0
  73. package/es/plugins/math/react/style.d.ts +6 -0
  74. package/es/plugins/math/react/style.js +16 -0
  75. package/es/plugins/math/react/type.d.ts +13 -0
  76. package/es/plugins/math/react/type.js +1 -0
  77. package/es/plugins/slash/react/ReactSlashPlugin.js +12 -10
  78. package/es/react/FloatMenu/FloatMenu.d.ts +4 -0
  79. package/es/react/FloatMenu/FloatMenu.js +49 -0
  80. package/es/react/FloatMenu/index.d.ts +2 -0
  81. package/es/react/FloatMenu/index.js +2 -0
  82. package/es/react/FloatMenu/type.d.ts +19 -0
  83. package/es/react/FloatMenu/type.js +1 -0
  84. package/es/react/SlashMenu/SlashMenu.js +32 -48
  85. package/es/react/SlashMenu/type.d.ts +5 -13
  86. package/es/react/hooks/useEditorState/index.d.ts +4 -0
  87. package/es/react/hooks/useEditorState/index.js +40 -4
  88. package/es/react/index.d.ts +1 -0
  89. package/es/react/index.js +1 -0
  90. package/es/types/global.d.ts +4 -0
  91. package/es/types/kernel.d.ts +26 -1
  92. package/package.json +2 -1
  93. package/es/plugins/common/node/LexicalLineBreakNode.d.ts +0 -31
  94. package/es/plugins/common/node/ParagraphNode.d.ts +0 -7
  95. package/es/plugins/link/react/components/Toolbar.d.ts +0 -7
  96. package/es/plugins/link/react/components/Toolbar.js +0 -63
  97. /package/es/react/{SlashMenu → FloatMenu}/style.d.ts +0 -0
  98. /package/es/react/{SlashMenu → FloatMenu}/style.js +0 -0
@@ -0,0 +1,303 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ 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; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
+ 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); }
8
+ 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; }
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
15
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ import { mergeRegister } from '@lexical/utils';
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
+ export var CardLikeElementNode = /*#__PURE__*/function (_ElementNode) {
24
+ _inherits(CardLikeElementNode, _ElementNode);
25
+ var _super = _createSuper(CardLikeElementNode);
26
+ function CardLikeElementNode() {
27
+ _classCallCheck(this, CardLikeElementNode);
28
+ return _super.apply(this, arguments);
29
+ }
30
+ _createClass(CardLikeElementNode, [{
31
+ key: "isCardLike",
32
+ value: function isCardLike() {
33
+ return true;
34
+ }
35
+ }]);
36
+ return CardLikeElementNode;
37
+ }(ElementNode);
38
+ export var CursorNode = /*#__PURE__*/function (_TextNode) {
39
+ _inherits(CursorNode, _TextNode);
40
+ var _super2 = _createSuper(CursorNode);
41
+ function CursorNode() {
42
+ _classCallCheck(this, CursorNode);
43
+ return _super2.apply(this, arguments);
44
+ }
45
+ _createClass(CursorNode, [{
46
+ key: "isUnmergeable",
47
+ value: function isUnmergeable() {
48
+ return true;
49
+ }
50
+ }], [{
51
+ key: "getType",
52
+ value: function getType() {
53
+ return 'cursor';
54
+ }
55
+ }]);
56
+ return CursorNode;
57
+ }(TextNode);
58
+ export function $createCursorNode() {
59
+ return new CursorNode("\uFEFF");
60
+ }
61
+ export function $isCardLikeElementNode(node) {
62
+ return node instanceof CardLikeElementNode;
63
+ }
64
+ export function $isCursorNode(node) {
65
+ return node instanceof CursorNode;
66
+ }
67
+ export function registerCursorNode(editor) {
68
+ return mergeRegister(editor.registerUpdateListener(function (_ref) {
69
+ var mutatedNodes = _ref.mutatedNodes;
70
+ editor.read(function () {
71
+ if (!mutatedNodes) return;
72
+ var needAddCursor = [];
73
+ var _iterator = _createForOfIteratorHelper(mutatedNodes),
74
+ _step;
75
+ try {
76
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
77
+ var _step$value = _slicedToArray(_step.value, 2),
78
+ kClass = _step$value[0],
79
+ nodeMaps = _step$value[1];
80
+ // eslint-disable-next-line no-prototype-builtins
81
+ if (DecoratorNode.prototype.isPrototypeOf(kClass.prototype)) {
82
+ var _iterator2 = _createForOfIteratorHelper(nodeMaps),
83
+ _step2;
84
+ try {
85
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
86
+ var _step2$value = _slicedToArray(_step2.value, 2),
87
+ key = _step2$value[0],
88
+ mutation = _step2$value[1];
89
+ var node = $getNodeByKey(key);
90
+ console.info('DecoratorNode mutated', node, mutation);
91
+ if (mutation === 'created' && node !== null && node !== void 0 && node.isInline() && node.getNextSibling() === null) {
92
+ needAddCursor.push(node);
93
+ }
94
+ }
95
+ } catch (err) {
96
+ _iterator2.e(err);
97
+ } finally {
98
+ _iterator2.f();
99
+ }
100
+ }
101
+ }
102
+ } catch (err) {
103
+ _iterator.e(err);
104
+ } finally {
105
+ _iterator.f();
106
+ }
107
+ if (needAddCursor.length > 0) {
108
+ editor.update(function () {
109
+ needAddCursor.forEach(function (node) {
110
+ node.insertAfter($createCursorNode());
111
+ });
112
+ });
113
+ }
114
+ return false;
115
+ });
116
+ }), editor.registerUpdateListener(function (_ref2) {
117
+ var mutatedNodes = _ref2.mutatedNodes;
118
+ editor.read(function () {
119
+ var cursorNodes = mutatedNodes === null || mutatedNodes === void 0 ? void 0 : mutatedNodes.get(CursorNode);
120
+ var needRemove = new Set();
121
+ if (cursorNodes) {
122
+ var _iterator3 = _createForOfIteratorHelper(cursorNodes),
123
+ _step3;
124
+ try {
125
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
126
+ var _step3$value = _slicedToArray(_step3.value, 2),
127
+ key = _step3$value[0],
128
+ mutation = _step3$value[1];
129
+ if (mutation === 'updated') {
130
+ var cursorNode = $getNodeByKey(key);
131
+ var element = cursorNode === null || cursorNode === void 0 ? void 0 : cursorNode.getPreviousSibling();
132
+ if (!$isCardLikeElementNode(element) && !$isDecoratorNode(element) && !$isCardLikeElementNode(cursorNode === null || cursorNode === void 0 ? void 0 : cursorNode.getParent())) {
133
+ needRemove.add(cursorNode);
134
+ }
135
+ }
136
+ }
137
+ } catch (err) {
138
+ _iterator3.e(err);
139
+ } finally {
140
+ _iterator3.f();
141
+ }
142
+ }
143
+ if (needRemove.size > 0) {
144
+ editor.update(function () {
145
+ needRemove.forEach(function (node) {
146
+ node.remove();
147
+ });
148
+ });
149
+ }
150
+ return false;
151
+ });
152
+ }), editor.registerUpdateListener(function () {
153
+ editor.read(function () {
154
+ var selection = $getSelection();
155
+ if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
156
+ return false;
157
+ }
158
+ var node = selection.anchor.getNode();
159
+ if (node instanceof CursorNode) {
160
+ if (node.__text !== "\uFEFF") {
161
+ editor.update(function () {
162
+ node.setTextContent("\uFEFF");
163
+ var data = node.__text.replace("\uFEFF", '');
164
+ if (data) {
165
+ var textNode = $createTextNode(data);
166
+ node.insertAfter(textNode);
167
+ textNode.selectEnd();
168
+ }
169
+ });
170
+ }
171
+ return false;
172
+ }
173
+ });
174
+ }), editor.registerCommand(KEY_BACKSPACE_COMMAND, function (event) {
175
+ var selection = $getSelection();
176
+ if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
177
+ return false;
178
+ }
179
+ var node = selection.anchor.getNode();
180
+ if (node instanceof CursorNode) {
181
+ event.preventDefault();
182
+ var prev = node.getPreviousSibling();
183
+ var parent = node.getParent();
184
+ var parentPrev = parent === null || parent === void 0 ? void 0 : parent.getPreviousSibling();
185
+ var needDispatch = false;
186
+ if ($isDecoratorNode(prev)) {
187
+ prev.selectPrevious();
188
+ node.remove();
189
+ prev.remove();
190
+ event.preventDefault();
191
+ return true;
192
+ } else if (prev) {
193
+ prev.selectEnd();
194
+ needDispatch = true;
195
+ } else if (parent) {
196
+ if (parent.getChildrenSize() === 1) {
197
+ parent.remove();
198
+ } else if (parentPrev) {
199
+ parentPrev.selectEnd();
200
+ needDispatch = true;
201
+ }
202
+ }
203
+ if (needDispatch) {
204
+ queueMicrotask(function () {
205
+ editor.dispatchCommand(KEY_BACKSPACE_COMMAND, event);
206
+ });
207
+ }
208
+ return true;
209
+ }
210
+ return false;
211
+ }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, function (event) {
212
+ var selection = $getSelection();
213
+ if (!$isRangeSelection(selection)) {
214
+ return false;
215
+ }
216
+ var focusNode = selection.focus.getNode();
217
+ if (!event.shiftKey) {
218
+ if (focusNode instanceof CursorNode && !$isCardLikeElementNode(focusNode.getParent()) && !$isCardLikeElementNode(focusNode.getPreviousSibling())) {
219
+ focusNode.selectStart();
220
+ }
221
+ return false;
222
+ }
223
+ var prev = focusNode.getPreviousSibling();
224
+ if (selection.focus.offset === 0 && $isCursorNode(prev)) {
225
+ try {
226
+ var _selection$anchor = selection.anchor,
227
+ anchorKey = _selection$anchor.key,
228
+ anchorOffset = _selection$anchor.offset,
229
+ anchorType = _selection$anchor.type;
230
+ var sel = prev.selectPrevious();
231
+ var _sel$anchor = sel.anchor,
232
+ key = _sel$anchor.key,
233
+ offset = _sel$anchor.offset,
234
+ type = _sel$anchor.type;
235
+ sel.anchor.set(anchorKey, anchorOffset, anchorType);
236
+ sel.focus.set(key, offset, type);
237
+ $setSelection(sel);
238
+ return true;
239
+ } catch (error) {
240
+ console.error(error);
241
+ }
242
+ } else if ($isCursorNode(focusNode)) {
243
+ try {
244
+ var _selection$anchor2 = selection.anchor,
245
+ _anchorKey = _selection$anchor2.key,
246
+ _anchorOffset = _selection$anchor2.offset,
247
+ _anchorType = _selection$anchor2.type;
248
+ var _sel = focusNode.selectPrevious();
249
+ var _sel$anchor2 = _sel.anchor,
250
+ _key = _sel$anchor2.key,
251
+ _offset = _sel$anchor2.offset,
252
+ _type = _sel$anchor2.type;
253
+ _sel.anchor.set(_anchorKey, _anchorOffset, _anchorType);
254
+ _sel.focus.set(_key, _offset, _type);
255
+ $setSelection(_sel);
256
+ return true;
257
+ } catch (error) {
258
+ console.error(error);
259
+ }
260
+ }
261
+ return false;
262
+ }, COMMAND_PRIORITY_HIGH), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, function (event) {
263
+ var selection = $getSelection();
264
+ if (!$isRangeSelection(selection)) {
265
+ return false;
266
+ }
267
+ if (!event.shiftKey) {
268
+ var _focusNode = selection.focus.getNode();
269
+ if (_focusNode instanceof CursorNode && !$isCardLikeElementNode(_focusNode.getParent()) && !$isCardLikeElementNode(_focusNode.getPreviousSibling())) {
270
+ _focusNode.selectEnd();
271
+ }
272
+ return false;
273
+ }
274
+ var _selection$anchor3 = selection.anchor,
275
+ anchorKey = _selection$anchor3.key,
276
+ anchorOffset = _selection$anchor3.offset,
277
+ anchorType = _selection$anchor3.type;
278
+ var _selection$focus = selection.focus,
279
+ focusKey = _selection$focus.key,
280
+ focusOffset = _selection$focus.offset,
281
+ focusType = _selection$focus.type;
282
+ var focusNode = selection.focus.getNode();
283
+ if (focusType === 'text' && focusOffset !== focusNode.getTextContentSize() || focusType === 'element' && focusOffset !== focusNode.getChildrenSize()) {
284
+ return false;
285
+ }
286
+ var sel = focusNode.selectNext();
287
+ if ($isCursorNode(sel.focus.getNode())) {
288
+ sel.focus.getNode().selectNext();
289
+ var _sel$anchor3 = sel.anchor,
290
+ key = _sel$anchor3.key,
291
+ offset = _sel$anchor3.offset,
292
+ type = _sel$anchor3.type;
293
+ sel.anchor.set(anchorKey, anchorOffset, anchorType);
294
+ sel.focus.set(key, offset, type);
295
+ $setSelection(sel);
296
+ return true;
297
+ } else {
298
+ selection.anchor.set(anchorKey, anchorOffset, anchorType);
299
+ selection.focus.set(focusKey, focusOffset, focusType);
300
+ }
301
+ return false;
302
+ }, COMMAND_PRIORITY_HIGH));
303
+ }
@@ -30,8 +30,11 @@ import { IMarkdownShortCutService, isPunctuationChar } from "../../markdown";
30
30
  import { registerCommands } from "../command";
31
31
  import JSONDataSource from "../data-source/json-data-source";
32
32
  import TextDataSource from "../data-source/text-data-source";
33
+ import { patchBreakLine, registerBreakLineClick } from "../node/ElementDOMSlot";
34
+ import { CursorNode, registerCursorNode } from "../node/cursor";
33
35
  import { createBlockNode } from "../utils";
34
36
  import { registerHeaderBackspace, registerRichKeydown } from "./register";
37
+ patchBreakLine();
35
38
  export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
36
39
  _inherits(CommonPlugin, _KernelPlugin);
37
40
  var _super = _createSuper(CommonPlugin);
@@ -47,7 +50,7 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
47
50
  // Register the text data source
48
51
  kernel.registerDataSource(new TextDataSource('text'));
49
52
  // Register common nodes and themes
50
- kernel.registerNodes([HeadingNode, QuoteNode]);
53
+ kernel.registerNodes([HeadingNode, QuoteNode, CursorNode]);
51
54
  if (config !== null && config !== void 0 && config.theme) {
52
55
  kernel.registerThemes({
53
56
  quote: config.theme.quote,
@@ -189,10 +192,6 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
189
192
  var isItalic = node.hasFormat('italic');
190
193
  var isUnderline = node.hasFormat('underline');
191
194
  var isStrikethrough = node.hasFormat('strikethrough');
192
- var isCode = node.hasFormat('code');
193
- if (isCode) {
194
- ctx.appendLine('`');
195
- }
196
195
  if (isBold) {
197
196
  ctx.appendLine('**');
198
197
  }
@@ -226,20 +225,23 @@ export var CommonPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
226
225
  if (isBold) {
227
226
  ctx.appendLine('**');
228
227
  }
229
- if (isCode) {
230
- ctx.appendLine('`');
231
- }
232
228
  if (tailSpace) {
233
229
  ctx.appendLine(tailSpace);
234
230
  } else if (lastChar && isPunctuationChar(lastChar)) {
235
231
  ctx.appendLine(' ');
236
232
  }
237
233
  });
234
+
235
+ // Register markdown writer for linebreak nodes (soft line breaks)
236
+ markdownService.registerMarkdownWriter('linebreak', function (ctx) {
237
+ // In markdown, soft line breaks are represented as two spaces followed by a newline
238
+ ctx.appendLine(' \n');
239
+ });
238
240
  }
239
241
  }, {
240
242
  key: "onInit",
241
243
  value: function onInit(editor) {
242
- this.registerClears(registerRichText(editor), registerDragonSupport(editor), registerHistory(editor, createEmptyHistoryState(), 300), registerHeaderBackspace(editor), registerRichKeydown(editor), registerCommands(editor));
244
+ this.registerClears(registerRichText(editor), registerDragonSupport(editor), registerHistory(editor, createEmptyHistoryState(), 300), registerHeaderBackspace(editor), registerRichKeydown(editor, this.kernel), registerCommands(editor), registerBreakLineClick(editor), registerCursorNode(editor));
243
245
  }
244
246
  }, {
245
247
  key: "destroy",
@@ -1,4 +1,6 @@
1
1
  import { LexicalEditor, LexicalNode, PointType } from 'lexical';
2
+ import { IEditor } from "../../../types";
2
3
  export declare function $getAdjacentNode(focus: PointType, isBackward: boolean): null | LexicalNode;
4
+ export declare function $getDownUpNode(focus: PointType, isUp: boolean): null | LexicalNode;
3
5
  export declare function registerHeaderBackspace(editor: LexicalEditor): () => void;
4
- export declare function registerRichKeydown(editor: LexicalEditor): () => void;
6
+ export declare function registerRichKeydown(editor: LexicalEditor, kernel: IEditor): () => void;
@@ -2,7 +2,7 @@ import { $isCodeHighlightNode, $isCodeNode } from '@lexical/code';
2
2
  import { $isHeadingNode } from '@lexical/rich-text';
3
3
  import { mergeRegister } from '@lexical/utils';
4
4
  import { $createNodeSelection, $createParagraphNode, $getRoot, $getSelection, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, FORMAT_TEXT_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DOWN_COMMAND, isModifierMatch } from 'lexical';
5
- import { CONTROL_OR_META, CONTROL_OR_META_AND_SHIFT } from "../../../common/sys";
5
+ import { CONTROL_OR_META_AND_SHIFT } from "../../../common/sys";
6
6
  function resolveElement(element, isBackward, focusOffset) {
7
7
  var parent = element.getParent();
8
8
  var offset = focusOffset;
@@ -62,6 +62,28 @@ export function $getAdjacentNode(focus, isBackward) {
62
62
  }
63
63
  return null;
64
64
  }
65
+ export function $getDownUpNode(focus, isUp) {
66
+ var focusNode = focus.getNode();
67
+ var blockParent = focusNode;
68
+ while (blockParent !== null && blockParent.isInline()) {
69
+ blockParent = blockParent.getParent();
70
+ }
71
+ if (!blockParent) {
72
+ return null;
73
+ }
74
+ var nextNode = isUp ? blockParent.getPreviousSibling() : blockParent.getNextSibling();
75
+ while (!nextNode && !$isRootOrShadowRoot(blockParent)) {
76
+ blockParent = blockParent.getParent();
77
+ if (!blockParent) {
78
+ return null;
79
+ }
80
+ nextNode = isUp ? blockParent.getPreviousSibling() : blockParent.getNextSibling();
81
+ }
82
+ if (!nextNode) {
83
+ return null;
84
+ }
85
+ return nextNode;
86
+ }
65
87
  function $isSelectionAtEndOfRoot(selection) {
66
88
  var focus = selection.focus;
67
89
  return focus.key === 'root' && focus.offset === $getRoot().getChildrenSize();
@@ -110,8 +132,8 @@ export function registerHeaderBackspace(editor) {
110
132
  return false;
111
133
  }, COMMAND_PRIORITY_NORMAL);
112
134
  }
113
- export function registerRichKeydown(editor) {
114
- return mergeRegister(editor.registerCommand(KEY_DOWN_COMMAND, function (payload) {
135
+ export function registerRichKeydown(editor, kernel) {
136
+ return mergeRegister(kernel.registerHighCommand(KEY_DOWN_COMMAND, function (payload) {
115
137
  // ctrl + shift + x
116
138
  if (isModifierMatch(payload, CONTROL_OR_META_AND_SHIFT) && payload.code === 'KeyX') {
117
139
  // Handle the custom key combination
@@ -120,15 +142,8 @@ export function registerRichKeydown(editor) {
120
142
  editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough');
121
143
  return true;
122
144
  }
123
- // ctrl + e
124
- if (isModifierMatch(payload, CONTROL_OR_META) && payload.code === 'KeyE') {
125
- payload.stopImmediatePropagation();
126
- payload.preventDefault();
127
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code');
128
- return true;
129
- }
130
145
  return false;
131
- }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_UP_COMMAND, function (event) {
146
+ }, COMMAND_PRIORITY_EDITOR), kernel.registerHighCommand(KEY_ARROW_UP_COMMAND, function (event) {
132
147
  var selection = $getSelection();
133
148
  if ($isNodeSelection(selection)) {
134
149
  // If selection is on a node, let's try and move selection
@@ -141,6 +156,7 @@ export function registerRichKeydown(editor) {
141
156
  }
142
157
  } else if ($isRangeSelection(selection)) {
143
158
  var possibleNode = $getAdjacentNode(selection.focus, true);
159
+ var upblock = possibleNode || $getDownUpNode(selection.focus, true);
144
160
  if (!event.shiftKey && $isDecoratorNode(possibleNode)) {
145
161
  var nodeSelection = $createNodeSelection();
146
162
  nodeSelection.add(possibleNode.getKey());
@@ -149,6 +165,14 @@ export function registerRichKeydown(editor) {
149
165
  });
150
166
  event.preventDefault();
151
167
  return true;
168
+ } else if (!event.shiftKey && $isDecoratorNode(upblock)) {
169
+ var _nodeSelection = $createNodeSelection();
170
+ _nodeSelection.add(upblock.getKey());
171
+ editor.update(function () {
172
+ $setSelection(_nodeSelection);
173
+ });
174
+ event.preventDefault();
175
+ return true;
152
176
  } else if (possibleNode) {
153
177
  possibleNode === null || possibleNode === void 0 || possibleNode.selectEnd();
154
178
  event.preventDefault();
@@ -156,7 +180,7 @@ export function registerRichKeydown(editor) {
156
180
  }
157
181
  }
158
182
  return false;
159
- }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, function (event) {
183
+ }, COMMAND_PRIORITY_EDITOR), kernel.registerHighCommand(KEY_ARROW_DOWN_COMMAND, function (event) {
160
184
  var selection = $getSelection();
161
185
  if ($isNodeSelection(selection)) {
162
186
  // If selection is on a node, let's try and move selection
@@ -184,6 +208,7 @@ export function registerRichKeydown(editor) {
184
208
  return true;
185
209
  }
186
210
  var possibleNode = $getAdjacentNode(selection.focus, false);
211
+ var upblock = possibleNode || $getDownUpNode(selection.focus, false);
187
212
  if (!event.shiftKey && $isDecoratorNode(possibleNode)) {
188
213
  var nodeSelection = $createNodeSelection();
189
214
  nodeSelection.add(possibleNode.getKey());
@@ -192,6 +217,14 @@ export function registerRichKeydown(editor) {
192
217
  });
193
218
  event.preventDefault();
194
219
  return true;
220
+ } else if (!event.shiftKey && $isDecoratorNode(upblock)) {
221
+ var _nodeSelection2 = $createNodeSelection();
222
+ _nodeSelection2.add(upblock.getKey());
223
+ editor.update(function () {
224
+ $setSelection(_nodeSelection2);
225
+ });
226
+ event.preventDefault();
227
+ return true;
195
228
  } else if (possibleNode) {
196
229
  possibleNode === null || possibleNode === void 0 || possibleNode.selectStart();
197
230
  event.preventDefault();
@@ -199,7 +232,7 @@ export function registerRichKeydown(editor) {
199
232
  }
200
233
  }
201
234
  return false;
202
- }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, function (event) {
235
+ }, COMMAND_PRIORITY_EDITOR), kernel.registerHighCommand(KEY_ARROW_RIGHT_COMMAND, function (event) {
203
236
  var selection = $getSelection();
204
237
  if ($isRangeSelection(selection)) {
205
238
  var _focusNode$getChildAt;
@@ -1,6 +1,10 @@
1
- import { LexicalEditor } from 'lexical';
1
+ import { LexicalEditor, NodeKey } from 'lexical';
2
2
  export declare const INSERT_LINK_COMMAND: import("lexical").LexicalCommand<{
3
3
  title?: string | undefined;
4
4
  url?: string | undefined;
5
5
  }>;
6
+ export declare const UPDATE_LINK_TEXT_COMMAND: import("lexical").LexicalCommand<{
7
+ key: NodeKey;
8
+ text: string;
9
+ }>;
6
10
  export declare function registerLinkCommand(editor: LexicalEditor): () => void;
@@ -1,8 +1,10 @@
1
- import { $createTextNode, $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
1
+ import { mergeRegister } from '@lexical/utils';
2
+ import { $createTextNode, $getNodeByKey, $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
2
3
  import { $createLinkNode } from "../node/LinkNode";
3
4
  export var INSERT_LINK_COMMAND = createCommand('INSERT_LINK_COMMAND');
5
+ export var UPDATE_LINK_TEXT_COMMAND = createCommand('UPDATE_LINK_TEXT_COMMAND');
4
6
  export function registerLinkCommand(editor) {
5
- return editor.registerCommand(INSERT_LINK_COMMAND, function (payload) {
7
+ return mergeRegister(editor.registerCommand(INSERT_LINK_COMMAND, function (payload) {
6
8
  var url = payload.url,
7
9
  _payload$title = payload.title,
8
10
  title = _payload$title === void 0 ? url : _payload$title;
@@ -16,5 +18,21 @@ export function registerLinkCommand(editor) {
16
18
  });
17
19
  return false;
18
20
  }, COMMAND_PRIORITY_EDITOR // Priority
19
- );
21
+ ), editor.registerCommand(UPDATE_LINK_TEXT_COMMAND, function (payload) {
22
+ var key = payload.key,
23
+ text = payload.text;
24
+ editor.update(function () {
25
+ var linkNode = $getNodeByKey(key);
26
+ if (linkNode) {
27
+ var newLinkNode = $createLinkNode(linkNode.getURL(), {
28
+ title: text
29
+ });
30
+ var textNode = $createTextNode(text);
31
+ newLinkNode.append(textNode);
32
+ linkNode === null || linkNode === void 0 || linkNode.replace(newLinkNode);
33
+ newLinkNode.select(1);
34
+ }
35
+ });
36
+ return false;
37
+ }, COMMAND_PRIORITY_EDITOR));
20
38
  }
@@ -23,8 +23,8 @@ import { MarkdownPlugin } from "../../markdown";
23
23
  import { $isLinkNode, $toggleLink, HOVER_LINK_COMMAND, HOVER_OUT_LINK_COMMAND, TOGGLE_LINK_COMMAND } from "../node/LinkNode";
24
24
  import { LinkPlugin } from "../plugin";
25
25
  import { getSelectedNode, sanitizeUrl } from "../utils";
26
- import { EDIT_LINK_COMMAND, LinkEdit } from "./components/LinkEdit";
27
- import { Toolbar } from "./components/Toolbar";
26
+ import LinkEdit, { EDIT_LINK_COMMAND } from "./components/LinkEdit";
27
+ import LinkToolbar from "./components/LinkToolbar";
28
28
  import { useStyles } from "./style";
29
29
  import { jsx as _jsx } from "react/jsx-runtime";
30
30
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -151,16 +151,13 @@ export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
151
151
  }, COMMAND_PRIORITY_NORMAL));
152
152
  }, []);
153
153
  return /*#__PURE__*/_jsxs(_Fragment, {
154
- children: [/*#__PURE__*/_jsx("div", {
155
- className: styles.editor_linkPlugin,
154
+ children: [/*#__PURE__*/_jsx(LinkToolbar, {
155
+ editor: editor.getLexicalEditor(),
156
+ linkNode: linkNode,
156
157
  onMouseEnter: function onMouseEnter() {
157
158
  clearTimeout(clearTimerRef.current);
158
159
  },
159
- ref: divRef,
160
- children: /*#__PURE__*/_jsx(Toolbar, {
161
- editor: editor.getLexicalEditor(),
162
- linkNode: linkNode
163
- })
160
+ ref: divRef
164
161
  }), /*#__PURE__*/_jsx(LinkEdit, {})]
165
162
  });
166
163
  };
@@ -4,4 +4,5 @@ export declare const EDIT_LINK_COMMAND: import("lexical").LexicalCommand<{
4
4
  linkNode: LinkNode | null;
5
5
  linkNodeDOM: HTMLElement | null;
6
6
  }>;
7
- export declare const LinkEdit: FC;
7
+ declare const LinkEdit: FC;
8
+ export default LinkEdit;