@yuntijs/ui 1.1.0 → 1.2.0-beta.1
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 +5 -4
- 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 +16 -3
- package/es/Mentions/index.js +26 -20
- 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-picker/index.d.ts +2 -1
- package/es/Mentions/plugins/mention-picker/index.js +7 -1
- package/es/Mentions/plugins/shift-enter-key.d.ts +6 -0
- package/es/Mentions/plugins/shift-enter-key.js +59 -0
- 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/MonacoEditor2.d.ts +11 -0
- package/es/MonacoEditor/MonacoEditor2.js +103 -0
- package/es/MonacoEditor/base/helper.js +5 -1
- package/es/MonacoEditor/base/style.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/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/package.json +6 -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,22 +16,23 @@ 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:
|
|
19
|
+
var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 4px;\n padding-inline: 8px;\n\n background-color: ", ";\n border-radius: ", "px;\n\n transition: background-color 100ms ", ";\n "])), primary ? isDarkMode ? token.colorFill : '#F6F6F6' : isDarkMode ? token.colorFillSecondary : token.colorBgContainer, token.borderRadius, 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),
|
|
27
28
|
avatarGroupContainer: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n width: ", "px;\n "])), avatarSize),
|
|
28
|
-
container: cx(type === 'pure' && pureContainerStylish, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n max-width: 100vw;\n padding: 16px;\n\n time {\n display: inline-block;\n white-space: nowrap;\n }\n\n div[role='menubar'] {\n display: flex;\n }\n\n time,\n div[role='menubar'] {\n pointer-events: ", ";\n opacity: ", ";\n transition: opacity 200ms ", ";\n }\n\n &:hover {\n time,\n div[role='menubar'] {\n pointer-events: unset;\n opacity: 1;\n }\n }\n\n ", " {\n padding-block: ", ";\n padding-inline: 8px;\n }\n "])), isLatest ? 'unset' : 'none', isLatest ? 1 : 0, token.motionEaseOut, responsive.mobile, type === 'pure' ? '12px' : '6px')),
|
|
29
|
+
container: cx(type === 'pure' && pureContainerStylish, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n max-width: 100vw;\n padding: 16px;\n\n time {\n display: inline-block;\n padding: 0 8px;\n white-space: nowrap;\n }\n\n div[role='menubar'] {\n display: flex;\n padding-inline: 8px;\n }\n\n time,\n div[role='menubar'] {\n pointer-events: ", ";\n opacity: ", ";\n transition: opacity 200ms ", ";\n }\n\n &:hover {\n time,\n div[role='menubar'] {\n pointer-events: unset;\n opacity: 1;\n }\n }\n\n ", " {\n padding-block: ", ";\n padding-inline: 8px;\n }\n "])), isLatest ? 'unset' : 'none', isLatest ? 1 : 0, token.motionEaseOut, responsive.mobile, type === 'pure' ? '12px' : '6px')),
|
|
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
|
-
messageContainer: cx(editingStylish, css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width:
|
|
35
|
+
messageContainer: cx(editingStylish, css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 96%;\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)),
|
|
36
37
|
messageExtra: cx('message-extra'),
|
|
37
38
|
name: css(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n margin-block-end: 6px;\n\n font-size: 12px;\n line-height: 1;\n color: ", ";\n text-align: ", ";\n "])), token.colorTextDescription, placement === 'left' ? 'left' : 'right')
|
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,9 @@
|
|
|
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';
|
|
6
|
+
export { CLEAR_EDITOR_COMMAND } from 'lexical';
|
|
4
7
|
export interface MentionsProps extends MentionPickerPluginProps {
|
|
5
8
|
className?: string;
|
|
6
9
|
classNames?: {
|
|
@@ -8,7 +11,7 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
8
11
|
menuOverlay?: string;
|
|
9
12
|
};
|
|
10
13
|
wrapperClassname?: string;
|
|
11
|
-
placeholder?:
|
|
14
|
+
placeholder?: React.ReactNode;
|
|
12
15
|
style?: React.CSSProperties;
|
|
13
16
|
value?: string;
|
|
14
17
|
defaultValue?: string;
|
|
@@ -17,9 +20,19 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
17
20
|
onChange?: (text: string) => void;
|
|
18
21
|
onBlur?: () => void;
|
|
19
22
|
onFocus?: () => void;
|
|
23
|
+
/**
|
|
24
|
+
* 按下回车的回调,指定后会改变回车的默认行为,换行需要使用 shift + enter
|
|
25
|
+
*/
|
|
26
|
+
onPressEnter?: (value: string, { event }: {
|
|
27
|
+
event: KeyboardEvent | null;
|
|
28
|
+
}) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 用户输入 trigger 后的回调
|
|
31
|
+
*/
|
|
32
|
+
onTrigger?: (trigger: string) => void;
|
|
20
33
|
variant?: 'outlined' | 'filled' | 'borderless';
|
|
21
34
|
autoSize?: AutoSize;
|
|
22
35
|
code?: boolean;
|
|
23
36
|
getPopContainer?: () => HTMLElement;
|
|
24
37
|
}
|
|
25
|
-
export declare const Mentions: React.
|
|
38
|
+
export declare const Mentions: React.ForwardRefExoticComponent<MentionsProps & React.RefAttributes<MentionsEditor>>;
|
package/es/Mentions/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
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; }
|
|
3
3
|
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; }
|
|
4
|
+
import { ClearEditorPlugin } from '@lexical/react/LexicalClearEditorPlugin';
|
|
4
5
|
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
5
6
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
6
7
|
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
@@ -9,21 +10,25 @@ import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
|
9
10
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
10
11
|
import { ConfigProvider } from 'antd';
|
|
11
12
|
// @Todo: 升级 0.25.0 后,ops-console 使用的时候出现了只输入 / 无法触发的问题
|
|
12
|
-
|
|
13
13
|
import { $getRoot, TextNode } from 'lexical';
|
|
14
|
-
import React, { useMemo } from 'react';
|
|
14
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
15
15
|
import { isBrowser } from "../utils/tools";
|
|
16
|
-
import { OnBlurBlockPlugin } from "./plugins/OnBlurBlockPlugin";
|
|
17
16
|
import { CustomTextNode } from "./plugins/custom-text/node";
|
|
18
17
|
import { EditablePlugin } from "./plugins/editable";
|
|
18
|
+
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
|
+
import { OnBlurBlockPlugin } from "./plugins/on-blur-block";
|
|
22
|
+
import { ShiftEnterKeyPlugin } from "./plugins/shift-enter-key";
|
|
21
23
|
import { MentionsConfigProvider } from "./provider";
|
|
22
24
|
import { useStyles } from "./style";
|
|
23
25
|
import { textToEditorState } from "./utils";
|
|
24
26
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
27
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
-
export
|
|
28
|
+
export * from "./types";
|
|
29
|
+
export * from "./utils";
|
|
30
|
+
export { CLEAR_EDITOR_COMMAND } from 'lexical';
|
|
31
|
+
export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
27
32
|
var className = _ref.className,
|
|
28
33
|
classNames = _ref.classNames,
|
|
29
34
|
placeholder = _ref.placeholder,
|
|
@@ -49,7 +54,9 @@ export var Mentions = function Mentions(_ref) {
|
|
|
49
54
|
onSelect = _ref.onSelect,
|
|
50
55
|
_ref$code = _ref.code,
|
|
51
56
|
code = _ref$code === void 0 ? false : _ref$code,
|
|
52
|
-
getPopContainer = _ref.getPopContainer
|
|
57
|
+
getPopContainer = _ref.getPopContainer,
|
|
58
|
+
onPressEnter = _ref.onPressEnter,
|
|
59
|
+
onTrigger = _ref.onTrigger;
|
|
53
60
|
var _ConfigProvider$useCo = ConfigProvider.useConfig(),
|
|
54
61
|
componentDisabled = _ConfigProvider$useCo.componentDisabled;
|
|
55
62
|
var _useStyles = useStyles({
|
|
@@ -73,7 +80,7 @@ export var Mentions = function Mentions(_ref) {
|
|
|
73
80
|
return new CustomTextNode(node.__text);
|
|
74
81
|
}
|
|
75
82
|
}, MentionNode],
|
|
76
|
-
editorState: textToEditorState(value || defaultValue || ''),
|
|
83
|
+
editorState: textToEditorState(value || defaultValue || '', triggers),
|
|
77
84
|
onError: function onError(error) {
|
|
78
85
|
throw error;
|
|
79
86
|
}
|
|
@@ -113,22 +120,13 @@ export var Mentions = function Mentions(_ref) {
|
|
|
113
120
|
if (!isBrowser) {
|
|
114
121
|
return;
|
|
115
122
|
}
|
|
123
|
+
if (getPopContainer) {
|
|
124
|
+
return getPopContainer();
|
|
125
|
+
}
|
|
116
126
|
if (document.fullscreenElement) {
|
|
117
127
|
return document.fullscreenElement;
|
|
118
128
|
}
|
|
119
|
-
}, []);
|
|
120
|
-
if (!isBrowser) {
|
|
121
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
122
|
-
className: cx(styles.wrapper, classNames === null || classNames === void 0 ? void 0 : classNames.wrapper),
|
|
123
|
-
children: [/*#__PURE__*/_jsx("div", {
|
|
124
|
-
className: cx(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.root, true), styles.filled, variant === 'filled'), styles.borderless, variant === 'borderless'), styles.disabled, disabled), className),
|
|
125
|
-
style: style || {}
|
|
126
|
-
}), /*#__PURE__*/_jsx("div", {
|
|
127
|
-
className: styles.placeholder,
|
|
128
|
-
children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
|
|
129
|
-
})]
|
|
130
|
-
});
|
|
131
|
-
}
|
|
129
|
+
}, [getPopContainer]);
|
|
132
130
|
return /*#__PURE__*/_jsx(LexicalComposer, {
|
|
133
131
|
initialConfig: _objectSpread(_objectSpread({}, initialConfig), {}, {
|
|
134
132
|
editable: editable
|
|
@@ -151,6 +149,10 @@ export var Mentions = function Mentions(_ref) {
|
|
|
151
149
|
})
|
|
152
150
|
}), editable && /*#__PURE__*/_jsx(MentionPickerPlugin, {
|
|
153
151
|
allowSpaces: allowSpaces,
|
|
152
|
+
onOpen: function onOpen(resolution) {
|
|
153
|
+
var _resolution$match$rep, _resolution$match;
|
|
154
|
+
return onTrigger === null || onTrigger === void 0 ? void 0 : onTrigger((_resolution$match$rep = (_resolution$match = resolution.match) === null || _resolution$match === void 0 ? void 0 : _resolution$match.replaceableString) !== null && _resolution$match$rep !== void 0 ? _resolution$match$rep : triggers[0]);
|
|
155
|
+
},
|
|
154
156
|
onSelect: onSelect,
|
|
155
157
|
options: options,
|
|
156
158
|
overlayClassName: classNames === null || classNames === void 0 ? void 0 : classNames.menuOverlay,
|
|
@@ -165,8 +167,12 @@ export var Mentions = function Mentions(_ref) {
|
|
|
165
167
|
onFocus: onFocus
|
|
166
168
|
}), /*#__PURE__*/_jsx(EditablePlugin, {
|
|
167
169
|
editable: editable
|
|
170
|
+
}), /*#__PURE__*/_jsx(EditorRefPlugin, {
|
|
171
|
+
editorRef: ref
|
|
172
|
+
}), /*#__PURE__*/_jsx(ClearEditorPlugin, {}), onPressEnter && /*#__PURE__*/_jsx(ShiftEnterKeyPlugin, {
|
|
173
|
+
onPressEnter: onPressEnter
|
|
168
174
|
})]
|
|
169
175
|
})
|
|
170
176
|
})
|
|
171
177
|
});
|
|
172
|
-
};
|
|
178
|
+
});
|
|
@@ -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
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { MenuOption, TypeaheadMenuPluginProps } from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { MentionOption } from '../../types';
|
|
3
4
|
import { type MentionMenuOption } from './utils';
|
|
4
|
-
export interface MentionPickerPluginProps {
|
|
5
|
+
export interface MentionPickerPluginProps extends Pick<TypeaheadMenuPluginProps<MenuOption>, 'onOpen'> {
|
|
5
6
|
/** The className of menu overlay */
|
|
6
7
|
overlayClassName?: string;
|
|
7
8
|
/** The options of menu */
|
|
@@ -3,6 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
3
3
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
4
4
|
import { LexicalTypeaheadMenuPlugin } from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
5
5
|
import { ConfigProvider, Tree } from 'antd';
|
|
6
|
+
import { COMMAND_PRIORITY_NORMAL } from 'lexical';
|
|
6
7
|
import { flatMap } from 'lodash-es';
|
|
7
8
|
import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
8
9
|
import ReactDOM from 'react-dom';
|
|
@@ -26,6 +27,7 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
26
27
|
_ref$preTriggerChars = _ref.preTriggerChars,
|
|
27
28
|
preTriggerChars = _ref$preTriggerChars === void 0 ? PRE_TRIGGER_CHARS : _ref$preTriggerChars,
|
|
28
29
|
onSelect = _ref.onSelect,
|
|
30
|
+
onOpen = _ref.onOpen,
|
|
29
31
|
parent = _ref.parent;
|
|
30
32
|
var _useStyles = useStyles({}),
|
|
31
33
|
cx = _useStyles.cx,
|
|
@@ -163,8 +165,12 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
163
165
|
return null;
|
|
164
166
|
}, [cx, handleDisabledItem, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
|
|
165
167
|
return /*#__PURE__*/_jsx(LexicalTypeaheadMenuPlugin, {
|
|
166
|
-
anchorClassName: styles.anchor
|
|
168
|
+
anchorClassName: styles.anchor
|
|
169
|
+
// 优先级要高于 ShiftEnterKeyPlugin
|
|
170
|
+
,
|
|
171
|
+
commandPriority: COMMAND_PRIORITY_NORMAL,
|
|
167
172
|
menuRenderFn: renderMenu,
|
|
173
|
+
onOpen: onOpen,
|
|
168
174
|
onQueryChange: setQueryString,
|
|
169
175
|
onSelectOption: onSelectOption,
|
|
170
176
|
options: flatOptions,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { CAN_USE_BEFORE_INPUT, IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '@lexical/utils';
|
|
4
|
+
import { $getRoot, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from 'lexical';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
export var ShiftEnterKeyPlugin = function ShiftEnterKeyPlugin(_ref) {
|
|
7
|
+
var onPressEnter = _ref.onPressEnter;
|
|
8
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
9
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
10
|
+
editor = _useLexicalComposerCo2[0];
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
// https://github.com/facebook/lexical/discussions/4464#discussioncomment-5833227
|
|
13
|
+
editor.registerCommand(KEY_ENTER_COMMAND, function (event) {
|
|
14
|
+
var selection = $getSelection();
|
|
15
|
+
if (!$isRangeSelection(selection)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (event !== null) {
|
|
19
|
+
// If we have beforeinput, then we can avoid blocking
|
|
20
|
+
// the default behavior. This ensures that the iOS can
|
|
21
|
+
// intercept that we're actually inserting a paragraph,
|
|
22
|
+
// and autocomplete, autocapitalize etc work as intended.
|
|
23
|
+
// This can also cause a strange performance issue in
|
|
24
|
+
// Safari, where there is a noticeable pause due to
|
|
25
|
+
// preventing the key down of enter.
|
|
26
|
+
if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
if (event.shiftKey) {
|
|
31
|
+
return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, void 0);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
event === null || event === void 0 || event.preventDefault();
|
|
35
|
+
var text = editor.read(function () {
|
|
36
|
+
return $getRoot().getTextContent();
|
|
37
|
+
});
|
|
38
|
+
var value = text.replaceAll('\n\n', '\n');
|
|
39
|
+
// 这里把 onPressEnter 放在下一次事件循环中触发,是为了避免跟 Lexical 还未结束的输入等事务发生冲突
|
|
40
|
+
if (window.queueMicrotask === undefined) {
|
|
41
|
+
setTimeout(function () {
|
|
42
|
+
onPressEnter(value, {
|
|
43
|
+
event: event
|
|
44
|
+
});
|
|
45
|
+
}, 0);
|
|
46
|
+
} else {
|
|
47
|
+
queueMicrotask(function () {
|
|
48
|
+
onPressEnter(value, {
|
|
49
|
+
event: event
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
},
|
|
55
|
+
// 优先级要低于 MentionPickerPlugin
|
|
56
|
+
COMMAND_PRIORITY_LOW);
|
|
57
|
+
}, [editor, onPressEnter]);
|
|
58
|
+
return null;
|
|
59
|
+
};
|
package/es/Mentions/types.d.ts
CHANGED
package/es/Mentions/utils.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ 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 declare function textToEditorState(
|
|
9
|
+
export declare function textToEditorState(initialValue: string, triggers: string[]): () => void;
|