@yuntijs/ui 1.2.0-beta.1 → 1.2.0-beta.2
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.
|
@@ -2,12 +2,16 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
3
|
import { CAN_USE_BEFORE_INPUT, IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '@lexical/utils';
|
|
4
4
|
import { $getRoot, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from 'lexical';
|
|
5
|
-
import { useEffect } from 'react';
|
|
5
|
+
import { useEffect, useRef } from 'react';
|
|
6
6
|
export var ShiftEnterKeyPlugin = function ShiftEnterKeyPlugin(_ref) {
|
|
7
7
|
var onPressEnter = _ref.onPressEnter;
|
|
8
8
|
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
9
9
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
10
10
|
editor = _useLexicalComposerCo2[0];
|
|
11
|
+
var onPressEnterRef = useRef(onPressEnter);
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
onPressEnterRef.current = onPressEnter;
|
|
14
|
+
}, [onPressEnter]);
|
|
11
15
|
useEffect(function () {
|
|
12
16
|
// https://github.com/facebook/lexical/discussions/4464#discussioncomment-5833227
|
|
13
17
|
editor.registerCommand(KEY_ENTER_COMMAND, function (event) {
|
|
@@ -39,13 +43,13 @@ export var ShiftEnterKeyPlugin = function ShiftEnterKeyPlugin(_ref) {
|
|
|
39
43
|
// 这里把 onPressEnter 放在下一次事件循环中触发,是为了避免跟 Lexical 还未结束的输入等事务发生冲突
|
|
40
44
|
if (window.queueMicrotask === undefined) {
|
|
41
45
|
setTimeout(function () {
|
|
42
|
-
|
|
46
|
+
onPressEnterRef.current(value, {
|
|
43
47
|
event: event
|
|
44
48
|
});
|
|
45
49
|
}, 0);
|
|
46
50
|
} else {
|
|
47
51
|
queueMicrotask(function () {
|
|
48
|
-
|
|
52
|
+
onPressEnterRef.current(value, {
|
|
49
53
|
event: event
|
|
50
54
|
});
|
|
51
55
|
});
|
|
@@ -54,6 +58,6 @@ export var ShiftEnterKeyPlugin = function ShiftEnterKeyPlugin(_ref) {
|
|
|
54
58
|
},
|
|
55
59
|
// 优先级要低于 MentionPickerPlugin
|
|
56
60
|
COMMAND_PRIORITY_LOW);
|
|
57
|
-
}, [editor
|
|
61
|
+
}, [editor]);
|
|
58
62
|
return null;
|
|
59
63
|
};
|