@yuntijs/ui 1.2.0-beta.2 → 1.2.0-beta.3
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/Mentions/index.d.ts +7 -0
- package/es/Mentions/index.js +4 -0
- package/es/Mentions/plugins/on-key-down.d.ts +6 -0
- package/es/Mentions/plugins/on-key-down.js +31 -0
- package/es/Mentions/utils.d.ts +5 -1
- package/es/Mentions/utils.js +16 -2
- package/package.json +1 -1
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
package/es/Mentions/index.d.ts
CHANGED
|
@@ -26,6 +26,13 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
26
26
|
onPressEnter?: (value: string, { event }: {
|
|
27
27
|
event: KeyboardEvent | null;
|
|
28
28
|
}) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 用户输入 trigger 后的回调
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* 按下键盘的回调
|
|
34
|
+
*/
|
|
35
|
+
onKeyDown?: (event: KeyboardEvent | null) => void;
|
|
29
36
|
/**
|
|
30
37
|
* 用户输入 trigger 后的回调
|
|
31
38
|
*/
|
package/es/Mentions/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { EditorRefPlugin } from "./plugins/editor-ref";
|
|
|
19
19
|
import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
|
|
20
20
|
import { MentionPickerPlugin } from "./plugins/mention-picker";
|
|
21
21
|
import { OnBlurBlockPlugin } from "./plugins/on-blur-block";
|
|
22
|
+
import { OnKeyDownPlugin } from "./plugins/on-key-down";
|
|
22
23
|
import { ShiftEnterKeyPlugin } from "./plugins/shift-enter-key";
|
|
23
24
|
import { MentionsConfigProvider } from "./provider";
|
|
24
25
|
import { useStyles } from "./style";
|
|
@@ -56,6 +57,7 @@ export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
56
57
|
code = _ref$code === void 0 ? false : _ref$code,
|
|
57
58
|
getPopContainer = _ref.getPopContainer,
|
|
58
59
|
onPressEnter = _ref.onPressEnter,
|
|
60
|
+
onKeyDown = _ref.onKeyDown,
|
|
59
61
|
onTrigger = _ref.onTrigger;
|
|
60
62
|
var _ConfigProvider$useCo = ConfigProvider.useConfig(),
|
|
61
63
|
componentDisabled = _ConfigProvider$useCo.componentDisabled;
|
|
@@ -171,6 +173,8 @@ export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
171
173
|
editorRef: ref
|
|
172
174
|
}), /*#__PURE__*/_jsx(ClearEditorPlugin, {}), onPressEnter && /*#__PURE__*/_jsx(ShiftEnterKeyPlugin, {
|
|
173
175
|
onPressEnter: onPressEnter
|
|
176
|
+
}), onKeyDown && /*#__PURE__*/_jsx(OnKeyDownPlugin, {
|
|
177
|
+
onKeyDown: onKeyDown
|
|
174
178
|
})]
|
|
175
179
|
})
|
|
176
180
|
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { COMMAND_PRIORITY_LOW, KEY_DOWN_COMMAND } from 'lexical';
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
export var OnKeyDownPlugin = function OnKeyDownPlugin(_ref) {
|
|
6
|
+
var onKeyDown = _ref.onKeyDown;
|
|
7
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
8
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
9
|
+
editor = _useLexicalComposerCo2[0];
|
|
10
|
+
var onKeyDownRef = useRef(onKeyDown);
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
onKeyDownRef.current = onKeyDown;
|
|
13
|
+
}, [onKeyDown]);
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
// https://github.com/facebook/lexical/discussions/4464#discussioncomment-5833227
|
|
16
|
+
editor.registerCommand(KEY_DOWN_COMMAND, function (event) {
|
|
17
|
+
// 这里把 onKeyDown 放在下一次事件循环中触发,是为了避免跟 Lexical 还未结束的输入等事务发生冲突
|
|
18
|
+
if (window.queueMicrotask === undefined) {
|
|
19
|
+
setTimeout(function () {
|
|
20
|
+
onKeyDownRef.current(event);
|
|
21
|
+
}, 0);
|
|
22
|
+
} else {
|
|
23
|
+
queueMicrotask(function () {
|
|
24
|
+
onKeyDownRef.current(event);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}, COMMAND_PRIORITY_LOW);
|
|
29
|
+
}, [editor]);
|
|
30
|
+
return null;
|
|
31
|
+
};
|
package/es/Mentions/utils.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ export declare const DELETE_MENTION_COMMAND: import("lexical").LexicalCommand<un
|
|
|
6
6
|
export declare const CLEAR_HIDE_MENU_TIMEOUT: import("lexical").LexicalCommand<unknown>;
|
|
7
7
|
export declare const UPDATE_MENTIONS_OPTIONS: import("lexical").LexicalCommand<unknown>;
|
|
8
8
|
export declare const decoratorTransform: (node: CustomTextNode, getMatch: (text: string) => null | EntityMatch, createNode: (textNode: TextNode) => LexicalNode) => void;
|
|
9
|
-
export
|
|
9
|
+
export interface TextToEditorStateOptions {
|
|
10
|
+
/** 光标位置,默认为 end */
|
|
11
|
+
cursor?: 'start' | 'end' | 'all';
|
|
12
|
+
}
|
|
13
|
+
export declare function textToEditorState(initialValue: string, triggers: string[], options?: TextToEditorStateOptions): () => void;
|
package/es/Mentions/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import { $createParagraphNode, $getRoot, $isTextNode, createCommand } from 'lexical';
|
|
3
|
+
import { $createParagraphNode, $getRoot, $isTextNode, $selectAll, createCommand } from 'lexical';
|
|
4
4
|
import { $convertToMentionNodes } from "./plugins/mention-converter";
|
|
5
5
|
export var INSERT_MENTION_COMMAND = createCommand('INSERT_MENTION_COMMAND');
|
|
6
6
|
export var DELETE_MENTION_COMMAND = createCommand('DELETE_MENTION_COMMAND');
|
|
@@ -65,12 +65,26 @@ export var decoratorTransform = function decoratorTransform(node, getMatch, crea
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
-
export function textToEditorState(initialValue, triggers) {
|
|
68
|
+
export function textToEditorState(initialValue, triggers, options) {
|
|
69
69
|
return function () {
|
|
70
70
|
var root = $getRoot();
|
|
71
71
|
root.clear();
|
|
72
72
|
var paragraph = $createParagraphNode();
|
|
73
73
|
paragraph.append.apply(paragraph, _toConsumableArray($convertToMentionNodes(initialValue, triggers)));
|
|
74
74
|
root.append(paragraph);
|
|
75
|
+
var _ref = options || {
|
|
76
|
+
cursor: 'end'
|
|
77
|
+
},
|
|
78
|
+
cursor = _ref.cursor;
|
|
79
|
+
if (!cursor || cursor === 'end') {
|
|
80
|
+
// 👇 把光标移动到文本末尾
|
|
81
|
+
var lastNode = paragraph.getLastDescendant();
|
|
82
|
+
if ($isTextNode(lastNode)) {
|
|
83
|
+
lastNode.select(); // 选中并聚焦尾部
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (cursor === 'all') {
|
|
87
|
+
$selectAll();
|
|
88
|
+
}
|
|
75
89
|
};
|
|
76
90
|
}
|