@yuntijs/ui 1.0.0-beta.111 → 1.0.0-beta.113
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.js
CHANGED
|
@@ -8,6 +8,8 @@ import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
|
8
8
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
9
9
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
10
10
|
import { ConfigProvider } from 'antd';
|
|
11
|
+
// @Todo: 升级 0.25.0 后,ops-console 使用的时候出现了只输入 / 无法触发的问题
|
|
12
|
+
|
|
11
13
|
import { $getRoot, TextNode } from 'lexical';
|
|
12
14
|
import React, { useMemo } from 'react';
|
|
13
15
|
import { isBrowser } from "../utils/tools";
|
|
@@ -4,7 +4,7 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
|
|
|
4
4
|
import { LexicalTypeaheadMenuPlugin } from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
5
5
|
import { ConfigProvider, Tree } from 'antd';
|
|
6
6
|
import { flatMap } from 'lodash-es';
|
|
7
|
-
import React, { memo, useCallback, useMemo, useState } from 'react';
|
|
7
|
+
import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
8
8
|
import ReactDOM from 'react-dom';
|
|
9
9
|
import { DEFAULT_PUNCTUATION, PRE_TRIGGER_CHARS } from "../../constants";
|
|
10
10
|
import { useCheckForMentionMatch } from "../../hooks";
|
|
@@ -65,9 +65,36 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
65
65
|
closeMenu();
|
|
66
66
|
});
|
|
67
67
|
}, [editor, onSelect, queryString, trigger]);
|
|
68
|
+
var preSelectedIndex = useRef();
|
|
69
|
+
var handleDisabledItem = useCallback(function (itemProps) {
|
|
70
|
+
var selectedIndex = itemProps.selectedIndex,
|
|
71
|
+
setHighlightedIndex = itemProps.setHighlightedIndex;
|
|
72
|
+
if (selectedIndex !== null) {
|
|
73
|
+
var _flatOptions$selected;
|
|
74
|
+
if ((_flatOptions$selected = flatOptions[selectedIndex]) !== null && _flatOptions$selected !== void 0 && _flatOptions$selected.disabled) {
|
|
75
|
+
var newIndex = selectedIndex;
|
|
76
|
+
// 如果是最后一项,则回到第一项
|
|
77
|
+
if (selectedIndex === flatOptions.length - 1) {
|
|
78
|
+
newIndex = flatOptions.length === 1 ? null : 0;
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
setHighlightedIndex(newIndex);
|
|
81
|
+
} else if (selectedIndex !== preSelectedIndex.current) {
|
|
82
|
+
var _preSelectedIndex$cur;
|
|
83
|
+
if (selectedIndex > ((_preSelectedIndex$cur = preSelectedIndex.current) !== null && _preSelectedIndex$cur !== void 0 ? _preSelectedIndex$cur : 0)) {
|
|
84
|
+
newIndex++;
|
|
85
|
+
} else {
|
|
86
|
+
newIndex--;
|
|
87
|
+
}
|
|
88
|
+
setHighlightedIndex(newIndex);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
preSelectedIndex.current = selectedIndex;
|
|
92
|
+
}
|
|
93
|
+
}, [flatOptions]);
|
|
68
94
|
var renderMenuTree = useCallback(function (itemProps) {
|
|
69
95
|
var selectedIndex = itemProps.selectedIndex,
|
|
70
96
|
selectOptionAndCleanUp = itemProps.selectOptionAndCleanUp;
|
|
97
|
+
handleDisabledItem(itemProps);
|
|
71
98
|
return /*#__PURE__*/_jsx(ConfigProvider, {
|
|
72
99
|
theme: {
|
|
73
100
|
components: {
|
|
@@ -104,11 +131,12 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
104
131
|
treeData: options
|
|
105
132
|
})
|
|
106
133
|
});
|
|
107
|
-
}, [options, editor, flatOptions, queryString]);
|
|
134
|
+
}, [handleDisabledItem, options, editor, flatOptions, queryString]);
|
|
108
135
|
var renderMenu = useCallback(function (anchorElementRef, itemProps, _matchingString) {
|
|
109
136
|
var selectedIndex = itemProps.selectedIndex,
|
|
110
137
|
selectOptionAndCleanUp = itemProps.selectOptionAndCleanUp,
|
|
111
138
|
setHighlightedIndex = itemProps.setHighlightedIndex;
|
|
139
|
+
handleDisabledItem(itemProps);
|
|
112
140
|
if (anchorElementRef.current) {
|
|
113
141
|
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/_jsx("div", {
|
|
114
142
|
className: cx(styles.menuOverlay, overlayClassName),
|
|
@@ -132,7 +160,7 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
132
160
|
}), anchorElementRef.current);
|
|
133
161
|
}
|
|
134
162
|
return null;
|
|
135
|
-
}, [cx, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
|
|
163
|
+
}, [cx, handleDisabledItem, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
|
|
136
164
|
return /*#__PURE__*/_jsx(LexicalTypeaheadMenuPlugin, {
|
|
137
165
|
anchorClassName: styles.anchor,
|
|
138
166
|
menuRenderFn: renderMenu,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flex } from 'antd';
|
|
2
2
|
import { escapeRegExp } from 'lodash-es';
|
|
3
|
-
import React, { memo, useMemo } from 'react';
|
|
3
|
+
import React, { memo, useEffect, useMemo, useRef } from 'react';
|
|
4
4
|
import Typography from "../../../Typography";
|
|
5
5
|
import { useStyles } from "./style";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -43,6 +43,22 @@ export var MentionMenuItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
43
43
|
before = _useMemo.before,
|
|
44
44
|
middle = _useMemo.middle,
|
|
45
45
|
after = _useMemo.after;
|
|
46
|
+
var ref = useRef(null);
|
|
47
|
+
|
|
48
|
+
// 自动滚动
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
if (isSelected) {
|
|
51
|
+
var _ref$current;
|
|
52
|
+
ref === null || ref === void 0 || (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.scrollIntoView({
|
|
53
|
+
behavior: 'smooth',
|
|
54
|
+
block: 'nearest'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}, [isSelected]);
|
|
58
|
+
useEffect(function () {
|
|
59
|
+
option.setRefElement(ref === null || ref === void 0 ? void 0 : ref.current);
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
}, []);
|
|
46
62
|
return /*#__PURE__*/_jsxs(Flex, {
|
|
47
63
|
align: "center",
|
|
48
64
|
className: styles.menuItem,
|
|
@@ -53,7 +69,7 @@ export var MentionMenuItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
53
69
|
onMouseEnter: function onMouseEnter() {
|
|
54
70
|
return _onMouseEnter === null || _onMouseEnter === void 0 ? void 0 : _onMouseEnter(index, option);
|
|
55
71
|
},
|
|
56
|
-
ref:
|
|
72
|
+
ref: ref,
|
|
57
73
|
tabIndex: -1,
|
|
58
74
|
title: option.htmlTitle || option.label,
|
|
59
75
|
children: [showIcon && /*#__PURE__*/_jsx(Flex, {
|