@lobehub/editor 3.6.0 → 3.7.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
|
@@ -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
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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$
|
|
226
|
-
(_instanceRef$
|
|
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$
|
|
236
|
-
(_instanceRef$
|
|
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
|
});
|
package/package.json
CHANGED