@yuntijs/ui 1.0.0 → 1.1.0-beta.10
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/ChatItem/index.js +3 -2
- package/es/ChatItem/style.js +3 -2
- package/es/ChatItem/type.d.ts +4 -0
- package/es/Form/collapse-list/index.js +16 -9
- package/es/Form/collapse-list/utils.d.ts +1 -0
- package/es/Form/collapse-list/utils.js +2 -1
- package/es/Mentions/index.d.ts +13 -3
- package/es/Mentions/index.js +33 -19
- package/es/Mentions/plugins/editor-ref.d.ts +5 -0
- package/es/Mentions/plugins/editor-ref.js +13 -0
- package/es/Mentions/plugins/mention-converter.d.ts +32 -0
- package/es/Mentions/plugins/mention-converter.js +151 -0
- package/es/Mentions/plugins/mention-node/component.js +1 -1
- package/es/Mentions/plugins/mention-picker/hooks.js +1 -0
- package/es/Mentions/plugins/mention-picker/index.d.ts +4 -0
- package/es/Mentions/plugins/mention-picker/index.js +54 -13
- package/es/Mentions/plugins/mention-picker/menu-item.js +19 -3
- package/es/Mentions/plugins/mention-picker/style.js +1 -1
- package/es/Mentions/plugins/mention-picker/utils.d.ts +3 -1
- package/es/Mentions/plugins/mention-picker/utils.js +3 -0
- package/es/Mentions/plugins/shift-enter-key.d.ts +6 -0
- package/es/Mentions/plugins/shift-enter-key.js +48 -0
- package/es/Mentions/style.d.ts +1 -0
- package/es/Mentions/style.js +4 -4
- package/es/Mentions/types.d.ts +1 -0
- package/es/Mentions/utils.d.ts +1 -1
- package/es/Mentions/utils.js +11 -30
- package/es/MonacoEditor/base/helper.d.ts +4 -0
- package/es/MonacoEditor/base/helper.js +13 -4
- package/es/MonacoEditor/base/index.d.ts +2 -2
- package/es/MonacoEditor/base/index.js +33 -10
- package/es/MonacoEditor/base/style.js +1 -1
- package/es/MonacoEditor/index.js +1 -1
- package/es/SelectCard/index.js +1 -1
- package/es/hooks/useHighlight.d.ts +1 -3
- package/es/hooks/useHighlight.js +65 -67
- package/package.json +5 -5
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
- /package/es/Mentions/plugins/{OnBlurBlockPlugin.d.ts → on-blur-block.d.ts} +0 -0
- /package/es/Mentions/plugins/{OnBlurBlockPlugin.js → on-blur-block.js} +0 -0
package/es/ChatItem/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "affixation", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "markdownProps", "markdownClassname", "isLatest"];
|
|
5
|
+
var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "affixation", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "markdownProps", "markdownClassname", "isLatest", "hideAvatar"];
|
|
6
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
8
|
import Avatar from '@lobehub/ui/es/chat/ChatItem/components/Avatar';
|
|
@@ -48,6 +48,7 @@ export var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
48
48
|
markdownProps = _ref.markdownProps,
|
|
49
49
|
markdownClassname = _ref.markdownClassname,
|
|
50
50
|
isLatest = _ref.isLatest,
|
|
51
|
+
hideAvatar = _ref.hideAvatar,
|
|
51
52
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
52
53
|
var _useResponsive = useResponsive(),
|
|
53
54
|
mobile = _useResponsive.mobile;
|
|
@@ -68,7 +69,7 @@ export var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
68
69
|
direction: placement === 'left' ? 'horizontal' : 'horizontal-reverse',
|
|
69
70
|
gap: mobile ? 6 : 12
|
|
70
71
|
}, rest), {}, {
|
|
71
|
-
children: [/*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, avatarProps), {}, {
|
|
72
|
+
children: [hideAvatar ? null : /*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, avatarProps), {}, {
|
|
72
73
|
addon: avatarAddon,
|
|
73
74
|
avatar: avatar,
|
|
74
75
|
loading: loading,
|
package/es/ChatItem/style.js
CHANGED
|
@@ -16,11 +16,12 @@ export var useStyles = createStyles(function (_ref, _ref2) {
|
|
|
16
16
|
editing = _ref2.editing,
|
|
17
17
|
time = _ref2.time,
|
|
18
18
|
isLatest = _ref2.isLatest;
|
|
19
|
-
var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 8px;\n padding-inline: 12px
|
|
19
|
+
var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n /* padding-block: 8px;\n padding-inline: 12px; */\n\n background-color: ", ";\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n "])), primary ? isDarkMode ? token.colorFill : token.colorBgElevated : isDarkMode ? token.colorFillSecondary : token.colorBgContainer, token.borderRadiusLG, token.motionEaseOut);
|
|
20
20
|
var pureStylish = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-block-start: ", ";\n "])), title ? 0 : '6px');
|
|
21
21
|
var pureContainerStylish = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n margin-block-end: -16px;\n transition: background-color 100ms ", ";\n "])), token.motionEaseOut);
|
|
22
22
|
var typeStylish = type === 'block' ? blockStylish : pureStylish;
|
|
23
23
|
var editingStylish = editing && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n width: 100%;\n "])));
|
|
24
|
+
var insetInline = placement === 'right' ? '-4px unset' : 'unset -4px';
|
|
24
25
|
return {
|
|
25
26
|
actions: cx(css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n flex: none;\n align-self: ", ";\n justify-content: ", ";\n "])), placement === 'left' ? 'flex-start' : 'flex-end', placement === 'left' ? 'flex-end' : 'flex-start'), editing && css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n pointer-events: none !important;\n opacity: 0 !important;\n "])))),
|
|
26
27
|
avatarContainer: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n flex: none;\n width: ", "px;\n height: ", "px;\n "])), avatarSize, avatarSize),
|
|
@@ -29,7 +30,7 @@ export var useStyles = createStyles(function (_ref, _ref2) {
|
|
|
29
30
|
editingContainer: cx(editingStylish, css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n padding-block: 8px 12px;\n padding-inline: 12px;\n border: 1px solid ", ";\n\n &:active,\n &:hover {\n border-color: ", ";\n }\n "])), token.colorBorderSecondary, token.colorBorder), type === 'pure' && css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n background: ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadius)),
|
|
30
31
|
editingInput: css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n width: 100%;\n "]))),
|
|
31
32
|
errorContainer: css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n width: 100%;\n "]))),
|
|
32
|
-
loading: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n inset-block-end: 0;\n inset-inline: ", "
|
|
33
|
+
loading: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n inset-block-end: 0;\n inset-inline: ", ";\n\n width: 16px;\n height: 16px;\n\n color: ", ";\n\n background: ", ";\n border-radius: 50%;\n "])), insetInline, token.colorBgLayout, token.colorPrimary),
|
|
33
34
|
message: cx(typeStylish, css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n ", " {\n width: 100%;\n }\n "])), responsive.mobile)),
|
|
34
35
|
messageContainer: cx(editingStylish, css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n margin-block-start: ", "px;\n\n ", " {\n overflow-x: auto;\n }\n "])), time ? -16 : 0, responsive.mobile)),
|
|
35
36
|
messageContent: cx(editingStylish, css(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n ", " {\n flex-direction: column !important;\n }\n "])), responsive.mobile)),
|
package/es/ChatItem/type.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { CollapseGroup } from "../../CollapseGroup";
|
|
|
19
19
|
import { FormCollapseListFieldsWatcher } from "./FieldsWatcher";
|
|
20
20
|
import { useFormCollapseListHooks } from "./hooks";
|
|
21
21
|
import { useStyles } from "./style";
|
|
22
|
-
import { FIELD_KEY_PATH, toRowKey } from "./utils";
|
|
22
|
+
import { FIELD_KEY_PATH, TEXT_INPUT_COMPOENT_TYPES, toRowKey } from "./utils";
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
25
|
var Text = Typography.Text;
|
|
@@ -222,14 +222,21 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
|
|
|
222
222
|
chidrenProps.disabled = disabled;
|
|
223
223
|
}
|
|
224
224
|
if (readOnly === true) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
var _props, _type;
|
|
226
|
+
chidrenProps.disabled = true;
|
|
227
|
+
if (children !== null && children !== void 0 && (_props = children.props) !== null && _props !== void 0 && _props.showCount) {
|
|
228
|
+
chidrenProps.showCount = undefined;
|
|
229
|
+
}
|
|
230
|
+
if (TEXT_INPUT_COMPOENT_TYPES.includes(children === null || children === void 0 || (_type = children.type) === null || _type === void 0 ? void 0 : _type.displayName)) {
|
|
231
|
+
return /*#__PURE__*/_jsx(Flex, {
|
|
232
|
+
align: "center",
|
|
233
|
+
className: cx(styles.readOnlyItem, className),
|
|
234
|
+
children: text !== null && text !== void 0 ? text : /*#__PURE__*/_jsx(Text, {
|
|
235
|
+
type: "secondary",
|
|
236
|
+
children: "-"
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
}
|
|
233
240
|
}
|
|
234
241
|
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread(_objectSpread({
|
|
235
242
|
className: className
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export var FIELD_KEY_PATH = '__YUNTI_FORM_COLLAPSE_LIST_FIELD_KEY_PATH';
|
|
2
2
|
export var toRowKey = function toRowKey(keyPath) {
|
|
3
3
|
return keyPath.join('-');
|
|
4
|
-
};
|
|
4
|
+
};
|
|
5
|
+
export var TEXT_INPUT_COMPOENT_TYPES = ['Input', 'InputNumber', 'AutoComplete', 'Mentions', 'Radio', 'RadioGroup', 'CheckBox', 'CheckBoxGroup', 'Rate', 'Slider', 'Switch'];
|
package/es/Mentions/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type MentionPickerPluginProps } from './plugins/mention-picker';
|
|
3
|
-
import
|
|
3
|
+
import { AutoSize, MentionsEditor } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './utils';
|
|
4
6
|
export interface MentionsProps extends MentionPickerPluginProps {
|
|
5
7
|
className?: string;
|
|
6
8
|
classNames?: {
|
|
@@ -8,7 +10,7 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
8
10
|
menuOverlay?: string;
|
|
9
11
|
};
|
|
10
12
|
wrapperClassname?: string;
|
|
11
|
-
placeholder?:
|
|
13
|
+
placeholder?: React.ReactNode;
|
|
12
14
|
style?: React.CSSProperties;
|
|
13
15
|
value?: string;
|
|
14
16
|
defaultValue?: string;
|
|
@@ -17,7 +19,15 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
17
19
|
onChange?: (text: string) => void;
|
|
18
20
|
onBlur?: () => void;
|
|
19
21
|
onFocus?: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* 按下回车的回调,指定后会改变回车的默认行为,换行需要使用 shift + enter
|
|
24
|
+
*/
|
|
25
|
+
onPressEnter?: (value: string, { event }: {
|
|
26
|
+
event: KeyboardEvent | null;
|
|
27
|
+
}) => void;
|
|
20
28
|
variant?: 'outlined' | 'filled' | 'borderless';
|
|
21
29
|
autoSize?: AutoSize;
|
|
30
|
+
code?: boolean;
|
|
31
|
+
getPopContainer?: () => HTMLElement;
|
|
22
32
|
}
|
|
23
|
-
export declare const Mentions: React.
|
|
33
|
+
export declare const Mentions: React.ForwardRefExoticComponent<MentionsProps & React.RefAttributes<MentionsEditor>>;
|
package/es/Mentions/index.js
CHANGED
|
@@ -8,20 +8,25 @@ 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 使用的时候出现了只输入 / 无法触发的问题
|
|
11
12
|
import { $getRoot, TextNode } from 'lexical';
|
|
12
|
-
import React, { useMemo } from 'react';
|
|
13
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
13
14
|
import { isBrowser } from "../utils/tools";
|
|
14
|
-
import { OnBlurBlockPlugin } from "./plugins/OnBlurBlockPlugin";
|
|
15
15
|
import { CustomTextNode } from "./plugins/custom-text/node";
|
|
16
16
|
import { EditablePlugin } from "./plugins/editable";
|
|
17
|
+
import { EditorRefPlugin } from "./plugins/editor-ref";
|
|
17
18
|
import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
|
|
18
19
|
import { MentionPickerPlugin } from "./plugins/mention-picker";
|
|
20
|
+
import { OnBlurBlockPlugin } from "./plugins/on-blur-block";
|
|
21
|
+
import { ShiftEnterKeyPlugin } from "./plugins/shift-enter-key";
|
|
19
22
|
import { MentionsConfigProvider } from "./provider";
|
|
20
23
|
import { useStyles } from "./style";
|
|
21
24
|
import { textToEditorState } from "./utils";
|
|
22
25
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
26
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
-
export
|
|
27
|
+
export * from "./types";
|
|
28
|
+
export * from "./utils";
|
|
29
|
+
export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
25
30
|
var className = _ref.className,
|
|
26
31
|
classNames = _ref.classNames,
|
|
27
32
|
placeholder = _ref.placeholder,
|
|
@@ -44,11 +49,16 @@ export var Mentions = function Mentions(_ref) {
|
|
|
44
49
|
allowSpaces = _ref.allowSpaces,
|
|
45
50
|
punctuation = _ref.punctuation,
|
|
46
51
|
preTriggerChars = _ref.preTriggerChars,
|
|
47
|
-
onSelect = _ref.onSelect
|
|
52
|
+
onSelect = _ref.onSelect,
|
|
53
|
+
_ref$code = _ref.code,
|
|
54
|
+
code = _ref$code === void 0 ? false : _ref$code,
|
|
55
|
+
getPopContainer = _ref.getPopContainer,
|
|
56
|
+
onPressEnter = _ref.onPressEnter;
|
|
48
57
|
var _ConfigProvider$useCo = ConfigProvider.useConfig(),
|
|
49
58
|
componentDisabled = _ConfigProvider$useCo.componentDisabled;
|
|
50
59
|
var _useStyles = useStyles({
|
|
51
|
-
autoSize: autoSize
|
|
60
|
+
autoSize: autoSize,
|
|
61
|
+
code: code
|
|
52
62
|
}),
|
|
53
63
|
styles = _useStyles.styles,
|
|
54
64
|
cx = _useStyles.cx;
|
|
@@ -67,7 +77,7 @@ export var Mentions = function Mentions(_ref) {
|
|
|
67
77
|
return new CustomTextNode(node.__text);
|
|
68
78
|
}
|
|
69
79
|
}, MentionNode],
|
|
70
|
-
editorState: textToEditorState(value || defaultValue || ''),
|
|
80
|
+
editorState: textToEditorState(value || defaultValue || '', triggers),
|
|
71
81
|
onError: function onError(error) {
|
|
72
82
|
throw error;
|
|
73
83
|
}
|
|
@@ -103,18 +113,17 @@ export var Mentions = function Mentions(_ref) {
|
|
|
103
113
|
};
|
|
104
114
|
return buildMap(options);
|
|
105
115
|
}, [options]);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
116
|
+
var parent = useMemo(function () {
|
|
117
|
+
if (!isBrowser) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (getPopContainer) {
|
|
121
|
+
return getPopContainer();
|
|
122
|
+
}
|
|
123
|
+
if (document.fullscreenElement) {
|
|
124
|
+
return document.fullscreenElement;
|
|
125
|
+
}
|
|
126
|
+
}, [getPopContainer]);
|
|
118
127
|
return /*#__PURE__*/_jsx(LexicalComposer, {
|
|
119
128
|
initialConfig: _objectSpread(_objectSpread({}, initialConfig), {}, {
|
|
120
129
|
editable: editable
|
|
@@ -140,6 +149,7 @@ export var Mentions = function Mentions(_ref) {
|
|
|
140
149
|
onSelect: onSelect,
|
|
141
150
|
options: options,
|
|
142
151
|
overlayClassName: classNames === null || classNames === void 0 ? void 0 : classNames.menuOverlay,
|
|
152
|
+
parent: parent,
|
|
143
153
|
preTriggerChars: preTriggerChars,
|
|
144
154
|
punctuation: punctuation,
|
|
145
155
|
triggers: triggers
|
|
@@ -150,8 +160,12 @@ export var Mentions = function Mentions(_ref) {
|
|
|
150
160
|
onFocus: onFocus
|
|
151
161
|
}), /*#__PURE__*/_jsx(EditablePlugin, {
|
|
152
162
|
editable: editable
|
|
163
|
+
}), /*#__PURE__*/_jsx(EditorRefPlugin, {
|
|
164
|
+
editorRef: ref
|
|
165
|
+
}), onPressEnter && /*#__PURE__*/_jsx(ShiftEnterKeyPlugin, {
|
|
166
|
+
onPressEnter: onPressEnter
|
|
153
167
|
})]
|
|
154
168
|
})
|
|
155
169
|
})
|
|
156
170
|
});
|
|
157
|
-
};
|
|
171
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { useImperativeHandle } from 'react';
|
|
4
|
+
export var EditorRefPlugin = function EditorRefPlugin(_ref) {
|
|
5
|
+
var editorRef = _ref.editorRef;
|
|
6
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
7
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
8
|
+
editor = _useLexicalComposerCo2[0];
|
|
9
|
+
useImperativeHandle(editorRef, function () {
|
|
10
|
+
return editor;
|
|
11
|
+
});
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* source:
|
|
3
|
+
* https://github.com/sodenn/lexical-beautiful-mentions/blob/8d2c8fbfaa63fe0100ac9f6c4bcb61e816d14a30/plugin/src/mention-converter.ts
|
|
4
|
+
*/
|
|
5
|
+
import { LexicalNode, TextNode } from 'lexical';
|
|
6
|
+
interface MentionEntry {
|
|
7
|
+
type: 'mention-node';
|
|
8
|
+
trigger: string;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
interface TextEntry {
|
|
12
|
+
type: 'custom-text';
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
type Entry = MentionEntry | TextEntry;
|
|
16
|
+
export declare function convertToMentionEntries(text: string, triggers: string[], punctuation: string): Entry[];
|
|
17
|
+
/**
|
|
18
|
+
* Utility function that takes a string or a text nodes and converts it to a
|
|
19
|
+
* list of mention and text nodes.
|
|
20
|
+
*
|
|
21
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
22
|
+
* via the `allowSpaces` prop.
|
|
23
|
+
*/
|
|
24
|
+
export declare function $convertToMentionNodes(textOrNode: string | TextNode, triggers: string[], punctuation?: string): LexicalNode[];
|
|
25
|
+
/**
|
|
26
|
+
* Transforms text nodes containing mention strings into mention nodes.
|
|
27
|
+
*
|
|
28
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
29
|
+
* via the `allowSpaces` prop.
|
|
30
|
+
*/
|
|
31
|
+
export declare function $transformTextToMentionNodes(triggers: string[], punctuation?: string): void;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
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; } } }; }
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
/**
|
|
5
|
+
* source:
|
|
6
|
+
* https://github.com/sodenn/lexical-beautiful-mentions/blob/8d2c8fbfaa63fe0100ac9f6c4bcb61e816d14a30/plugin/src/mention-converter.ts
|
|
7
|
+
*/
|
|
8
|
+
import { $createTextNode, $getRoot, $isElementNode, $isTextNode } from 'lexical';
|
|
9
|
+
import { DEFAULT_PUNCTUATION, LENGTH_LIMIT, TRIGGERS, VALID_CHARS } from "../constants";
|
|
10
|
+
import { $createMentionNode } from "./mention-node";
|
|
11
|
+
function findMentions(text, triggers, punctuation) {
|
|
12
|
+
var regex = new RegExp('(?<=\\s|^|\\()' + TRIGGERS(triggers) + '((?:' + VALID_CHARS(triggers, punctuation) + '){1,' + LENGTH_LIMIT + '})', 'g');
|
|
13
|
+
var matches = [];
|
|
14
|
+
var match;
|
|
15
|
+
regex.lastIndex = 0;
|
|
16
|
+
while ((match = regex.exec(text)) !== null) {
|
|
17
|
+
matches.push({
|
|
18
|
+
value: match[0],
|
|
19
|
+
index: match.index
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return matches;
|
|
23
|
+
}
|
|
24
|
+
export function convertToMentionEntries(text, triggers, punctuation) {
|
|
25
|
+
var matches = findMentions(text, triggers, punctuation);
|
|
26
|
+
var result = [];
|
|
27
|
+
var lastIndex = 0;
|
|
28
|
+
var _iterator = _createForOfIteratorHelper(matches),
|
|
29
|
+
_step;
|
|
30
|
+
try {
|
|
31
|
+
var _loop = function _loop() {
|
|
32
|
+
var _step$value = _step.value,
|
|
33
|
+
value = _step$value.value,
|
|
34
|
+
index = _step$value.index;
|
|
35
|
+
// Add text before mention
|
|
36
|
+
if (index > lastIndex) {
|
|
37
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
38
|
+
var textBeforeMention = text.substring(lastIndex, index);
|
|
39
|
+
result.push({
|
|
40
|
+
type: 'custom-text',
|
|
41
|
+
value: textBeforeMention
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// Add mention
|
|
45
|
+
var triggerRegExp = triggers.find(function (trigger) {
|
|
46
|
+
return new RegExp(trigger).test(value);
|
|
47
|
+
});
|
|
48
|
+
var match = triggerRegExp && new RegExp(triggerRegExp).exec(value);
|
|
49
|
+
if (!match) {
|
|
50
|
+
// should never happen since we only find mentions with the given triggers
|
|
51
|
+
throw new Error('No trigger found for mention');
|
|
52
|
+
}
|
|
53
|
+
var trigger = match[0];
|
|
54
|
+
result.push({
|
|
55
|
+
type: 'mention-node',
|
|
56
|
+
value: value.slice(trigger.length),
|
|
57
|
+
trigger: trigger
|
|
58
|
+
});
|
|
59
|
+
// Update lastIndex
|
|
60
|
+
lastIndex = index + value.length;
|
|
61
|
+
};
|
|
62
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
63
|
+
_loop();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Add text after last mention
|
|
67
|
+
} catch (err) {
|
|
68
|
+
_iterator.e(err);
|
|
69
|
+
} finally {
|
|
70
|
+
_iterator.f();
|
|
71
|
+
}
|
|
72
|
+
if (lastIndex < text.length) {
|
|
73
|
+
var textAfterMentions = text.slice(Math.max(0, lastIndex));
|
|
74
|
+
result.push({
|
|
75
|
+
type: 'custom-text',
|
|
76
|
+
value: textAfterMentions
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Utility function that takes a string or a text nodes and converts it to a
|
|
84
|
+
* list of mention and text nodes.
|
|
85
|
+
*
|
|
86
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
87
|
+
* via the `allowSpaces` prop.
|
|
88
|
+
*/
|
|
89
|
+
export function $convertToMentionNodes(textOrNode, triggers) {
|
|
90
|
+
var punctuation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_PUNCTUATION;
|
|
91
|
+
var text = typeof textOrNode === 'string' ? textOrNode : textOrNode.getTextContent();
|
|
92
|
+
var entries = convertToMentionEntries(text, triggers, punctuation);
|
|
93
|
+
var nodes = [];
|
|
94
|
+
var _iterator2 = _createForOfIteratorHelper(entries),
|
|
95
|
+
_step2;
|
|
96
|
+
try {
|
|
97
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
98
|
+
var entry = _step2.value;
|
|
99
|
+
if (entry.type === 'custom-text') {
|
|
100
|
+
var textNode = $createTextNode(entry.value);
|
|
101
|
+
if (typeof textOrNode !== 'string') {
|
|
102
|
+
textNode.setFormat(textOrNode.getFormat());
|
|
103
|
+
}
|
|
104
|
+
nodes.push(textNode);
|
|
105
|
+
} else {
|
|
106
|
+
nodes.push($createMentionNode(entry.value));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
_iterator2.e(err);
|
|
111
|
+
} finally {
|
|
112
|
+
_iterator2.f();
|
|
113
|
+
}
|
|
114
|
+
return nodes;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Transforms text nodes containing mention strings into mention nodes.
|
|
119
|
+
*
|
|
120
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
121
|
+
* via the `allowSpaces` prop.
|
|
122
|
+
*/
|
|
123
|
+
export function $transformTextToMentionNodes(triggers) {
|
|
124
|
+
var punctuation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_PUNCTUATION;
|
|
125
|
+
var root = $getRoot();
|
|
126
|
+
var nodes = root.getChildren();
|
|
127
|
+
var traverseNodes = function traverseNodes(nodes) {
|
|
128
|
+
var _iterator3 = _createForOfIteratorHelper(nodes),
|
|
129
|
+
_step3;
|
|
130
|
+
try {
|
|
131
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
132
|
+
var node = _step3.value;
|
|
133
|
+
if ($isTextNode(node)) {
|
|
134
|
+
var newNodes = $convertToMentionNodes(node, triggers, punctuation);
|
|
135
|
+
if (newNodes.length > 1) {
|
|
136
|
+
var parent = node.getParent();
|
|
137
|
+
var index = node.getIndexWithinParent();
|
|
138
|
+
parent === null || parent === void 0 || parent.splice(index, 1, newNodes);
|
|
139
|
+
}
|
|
140
|
+
} else if ($isElementNode(node)) {
|
|
141
|
+
traverseNodes(node.getChildren());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch (err) {
|
|
145
|
+
_iterator3.e(err);
|
|
146
|
+
} finally {
|
|
147
|
+
_iterator3.f();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
traverseNodes(nodes);
|
|
151
|
+
}
|
|
@@ -47,7 +47,7 @@ export var MentionNodeComponent = /*#__PURE__*/memo(function (_ref) {
|
|
|
47
47
|
}), /*#__PURE__*/_jsx(Flex, {
|
|
48
48
|
className: styles.text,
|
|
49
49
|
gap: 2,
|
|
50
|
-
title: (option === null || option === void 0 ? void 0 : option.label) || variable,
|
|
50
|
+
title: (option === null || option === void 0 ? void 0 : option.selectedLabel) || (option === null || option === void 0 ? void 0 : option.label) || variable,
|
|
51
51
|
children: /*#__PURE__*/_jsx("span", {
|
|
52
52
|
children: (option === null || option === void 0 ? void 0 : option.selectedLabel) || (option === null || option === void 0 ? void 0 : option.label) || variable
|
|
53
53
|
})
|
|
@@ -32,6 +32,7 @@ export var useOptions = function useOptions(allOptions, queryString) {
|
|
|
32
32
|
var options = useMemo(function () {
|
|
33
33
|
var _addOnselect = function _addOnselect(option) {
|
|
34
34
|
var menuOption = _objectSpread(_objectSpread({}, option), {}, {
|
|
35
|
+
title: option.title || option.selectedLabel,
|
|
35
36
|
children: undefined,
|
|
36
37
|
onSelect: function onSelect() {
|
|
37
38
|
editor.dispatchCommand(INSERT_MENTION_COMMAND, option.value);
|
|
@@ -35,5 +35,9 @@ export interface MentionPickerPluginProps {
|
|
|
35
35
|
* When mention selected, this func will be called
|
|
36
36
|
*/
|
|
37
37
|
onSelect?: (option: MentionMenuOption, trigger: string | null, queryString: string | null) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Parent element
|
|
40
|
+
*/
|
|
41
|
+
parent?: HTMLElement;
|
|
38
42
|
}
|
|
39
43
|
export declare const MentionPickerPlugin: React.FC<MentionPickerPluginProps>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
4
|
import { LexicalTypeaheadMenuPlugin } from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
4
5
|
import { ConfigProvider, Tree } from 'antd';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import React, { memo, useCallback, useState } from 'react';
|
|
6
|
+
import { COMMAND_PRIORITY_NORMAL } from 'lexical';
|
|
7
|
+
import { flatMap } from 'lodash-es';
|
|
8
|
+
import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
10
9
|
import ReactDOM from 'react-dom';
|
|
11
10
|
import { DEFAULT_PUNCTUATION, PRE_TRIGGER_CHARS } from "../../constants";
|
|
12
11
|
import { useCheckForMentionMatch } from "../../hooks";
|
|
@@ -27,7 +26,8 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
27
26
|
punctuation = _ref$punctuation === void 0 ? DEFAULT_PUNCTUATION : _ref$punctuation,
|
|
28
27
|
_ref$preTriggerChars = _ref.preTriggerChars,
|
|
29
28
|
preTriggerChars = _ref$preTriggerChars === void 0 ? PRE_TRIGGER_CHARS : _ref$preTriggerChars,
|
|
30
|
-
onSelect = _ref.onSelect
|
|
29
|
+
onSelect = _ref.onSelect,
|
|
30
|
+
parent = _ref.parent;
|
|
31
31
|
var _useStyles = useStyles({}),
|
|
32
32
|
cx = _useStyles.cx,
|
|
33
33
|
styles = _useStyles.styles;
|
|
@@ -47,6 +47,14 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
47
47
|
setQueryString = _useState2[1];
|
|
48
48
|
var _useOptions = useOptions(allOptions, queryString),
|
|
49
49
|
options = _useOptions.options;
|
|
50
|
+
var flatOptions = useMemo(function () {
|
|
51
|
+
var _flattenTree = function _flattenTree(nodes) {
|
|
52
|
+
return flatMap(nodes, function (node) {
|
|
53
|
+
return [node].concat(_toConsumableArray(node.children ? _flattenTree(node.children) : []));
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return _flattenTree(options);
|
|
57
|
+
}, [options]);
|
|
50
58
|
var onSelectOption = useCallback(function (selectedOption, nodeToRemove, closeMenu, matchingString) {
|
|
51
59
|
onSelect === null || onSelect === void 0 || onSelect(selectedOption, trigger, queryString);
|
|
52
60
|
editor.update(function () {
|
|
@@ -59,9 +67,36 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
59
67
|
closeMenu();
|
|
60
68
|
});
|
|
61
69
|
}, [editor, onSelect, queryString, trigger]);
|
|
70
|
+
var preSelectedIndex = useRef();
|
|
71
|
+
var handleDisabledItem = useCallback(function (itemProps) {
|
|
72
|
+
var selectedIndex = itemProps.selectedIndex,
|
|
73
|
+
setHighlightedIndex = itemProps.setHighlightedIndex;
|
|
74
|
+
if (selectedIndex !== null) {
|
|
75
|
+
var _flatOptions$selected;
|
|
76
|
+
if ((_flatOptions$selected = flatOptions[selectedIndex]) !== null && _flatOptions$selected !== void 0 && _flatOptions$selected.disabled) {
|
|
77
|
+
var newIndex = selectedIndex;
|
|
78
|
+
// 如果是最后一项,则回到第一项
|
|
79
|
+
if (selectedIndex === flatOptions.length - 1) {
|
|
80
|
+
newIndex = flatOptions.length === 1 ? null : 0;
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
setHighlightedIndex(newIndex);
|
|
83
|
+
} else if (selectedIndex !== preSelectedIndex.current) {
|
|
84
|
+
var _preSelectedIndex$cur;
|
|
85
|
+
if (selectedIndex > ((_preSelectedIndex$cur = preSelectedIndex.current) !== null && _preSelectedIndex$cur !== void 0 ? _preSelectedIndex$cur : 0)) {
|
|
86
|
+
newIndex++;
|
|
87
|
+
} else {
|
|
88
|
+
newIndex--;
|
|
89
|
+
}
|
|
90
|
+
setHighlightedIndex(newIndex);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
preSelectedIndex.current = selectedIndex;
|
|
94
|
+
}
|
|
95
|
+
}, [flatOptions]);
|
|
62
96
|
var renderMenuTree = useCallback(function (itemProps) {
|
|
63
97
|
var selectedIndex = itemProps.selectedIndex,
|
|
64
98
|
selectOptionAndCleanUp = itemProps.selectOptionAndCleanUp;
|
|
99
|
+
handleDisabledItem(itemProps);
|
|
65
100
|
return /*#__PURE__*/_jsx(ConfigProvider, {
|
|
66
101
|
theme: {
|
|
67
102
|
components: {
|
|
@@ -69,7 +104,8 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
69
104
|
indentSize: 16,
|
|
70
105
|
lineHeight: 32,
|
|
71
106
|
titleHeight: 32,
|
|
72
|
-
paddingXS: 0
|
|
107
|
+
paddingXS: 0,
|
|
108
|
+
nodeHoverBg: 'transparent'
|
|
73
109
|
}
|
|
74
110
|
}
|
|
75
111
|
},
|
|
@@ -86,9 +122,9 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
86
122
|
selectOptionAndCleanUp(info.node);
|
|
87
123
|
},
|
|
88
124
|
titleRender: function titleRender(option) {
|
|
89
|
-
var
|
|
125
|
+
var _flatOptions;
|
|
90
126
|
return /*#__PURE__*/_jsx(MentionMenuItem, {
|
|
91
|
-
isSelected: ((
|
|
127
|
+
isSelected: ((_flatOptions = flatOptions[selectedIndex]) === null || _flatOptions === void 0 ? void 0 : _flatOptions.value) === option.value,
|
|
92
128
|
option: option,
|
|
93
129
|
queryString: queryString,
|
|
94
130
|
showIcon: !option.isChild
|
|
@@ -97,11 +133,12 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
97
133
|
treeData: options
|
|
98
134
|
})
|
|
99
135
|
});
|
|
100
|
-
}, [options, editor, queryString]);
|
|
136
|
+
}, [handleDisabledItem, options, editor, flatOptions, queryString]);
|
|
101
137
|
var renderMenu = useCallback(function (anchorElementRef, itemProps, _matchingString) {
|
|
102
138
|
var selectedIndex = itemProps.selectedIndex,
|
|
103
139
|
selectOptionAndCleanUp = itemProps.selectOptionAndCleanUp,
|
|
104
140
|
setHighlightedIndex = itemProps.setHighlightedIndex;
|
|
141
|
+
handleDisabledItem(itemProps);
|
|
105
142
|
if (anchorElementRef.current) {
|
|
106
143
|
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/_jsx("div", {
|
|
107
144
|
className: cx(styles.menuOverlay, overlayClassName),
|
|
@@ -125,13 +162,17 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
125
162
|
}), anchorElementRef.current);
|
|
126
163
|
}
|
|
127
164
|
return null;
|
|
128
|
-
}, [cx, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
|
|
165
|
+
}, [cx, handleDisabledItem, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
|
|
129
166
|
return /*#__PURE__*/_jsx(LexicalTypeaheadMenuPlugin, {
|
|
130
|
-
anchorClassName: styles.anchor
|
|
167
|
+
anchorClassName: styles.anchor
|
|
168
|
+
// 优先级要高于 ShiftEnterKeyPlugin
|
|
169
|
+
,
|
|
170
|
+
commandPriority: COMMAND_PRIORITY_NORMAL,
|
|
131
171
|
menuRenderFn: renderMenu,
|
|
132
172
|
onQueryChange: setQueryString,
|
|
133
173
|
onSelectOption: onSelectOption,
|
|
134
|
-
options:
|
|
174
|
+
options: flatOptions,
|
|
175
|
+
parent: parent,
|
|
135
176
|
triggerFn: checkForMentionMatch
|
|
136
177
|
});
|
|
137
178
|
});
|