@yuntijs/ui 1.0.0-beta.8 → 1.0.0-beta.80
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/Alert/index.d.ts +13 -0
- package/es/Alert/index.js +25 -0
- package/es/Alert/style.d.ts +4 -0
- package/es/Alert/style.js +13 -0
- package/es/App/index.d.ts +7 -0
- package/es/App/index.js +19 -0
- package/es/ButtonGroup/index.d.ts +24 -0
- package/es/ButtonGroup/index.js +66 -0
- package/es/Card/index.d.ts +1 -0
- package/es/Card/index.js +1 -0
- package/es/CardList/Item/index.d.ts +4 -0
- package/es/CardList/Item/index.js +43 -0
- package/es/CardList/Item/style.d.ts +0 -0
- package/es/CardList/Item/style.js +0 -0
- package/es/CardList/index.d.ts +2 -0
- package/es/CardList/index.js +39 -0
- package/es/ChatInputArea/desktop/ChatInputArea.d.ts +19 -0
- package/es/ChatInputArea/desktop/ChatInputArea.js +72 -0
- package/es/ChatInputArea/index.d.ts +6 -0
- package/es/ChatInputArea/index.js +6 -0
- package/es/ChatItem/components/MessageContent.d.ts +21 -0
- package/es/ChatItem/components/MessageContent.js +59 -0
- package/es/ChatItem/index.d.ts +4 -0
- package/es/ChatItem/index.js +120 -0
- package/es/ChatItem/style.d.ts +24 -0
- package/es/ChatItem/style.js +38 -0
- package/es/ChatItem/type.d.ts +82 -0
- package/es/ChatItem/type.js +1 -0
- package/es/CollapseGroup/index.d.ts +4 -0
- package/es/CollapseGroup/index.js +23 -0
- package/es/CollapseGroup/style.d.ts +3 -0
- package/es/CollapseGroup/style.js +11 -0
- package/es/ConfigProvider/index.d.ts +3 -0
- package/es/ConfigProvider/index.js +17 -11
- package/es/Descriptions/index.d.ts +14 -0
- package/es/Descriptions/index.js +31 -0
- package/es/Descriptions/style.d.ts +4 -0
- package/es/Descriptions/style.js +24 -0
- package/es/Divider/index.d.ts +38 -0
- package/es/Divider/index.js +66 -0
- package/es/Divider/style.d.ts +3 -0
- package/es/Divider/style.js +12 -0
- package/es/DragPanel/index.d.ts +10 -0
- package/es/DragPanel/index.js +97 -0
- package/es/DragPanel/style.d.ts +7 -0
- package/es/DragPanel/style.js +15 -0
- package/es/Drawer/index.d.ts +13 -0
- package/es/Drawer/index.js +20 -0
- package/es/Drawer/style.d.ts +4 -0
- package/es/Drawer/style.js +16 -0
- package/es/Dropdown/index.d.ts +14 -0
- package/es/Dropdown/index.js +59 -0
- package/es/Dropdown/style.d.ts +7 -0
- package/es/Dropdown/style.js +13 -0
- package/es/EditableMessage/index.d.ts +75 -0
- package/es/EditableMessage/index.js +99 -0
- package/es/Form/collapse-list/index.d.ts +40 -0
- package/es/Form/collapse-list/index.js +209 -0
- package/es/Form/collapse-list/style.d.ts +5 -0
- package/es/Form/collapse-list/style.js +13 -0
- package/es/Form/index.d.ts +8 -0
- package/es/Form/index.js +5 -0
- package/es/FormHelper/autoFocus.d.ts +10 -0
- package/es/FormHelper/autoFocus.js +38 -0
- package/es/FormHelper/index.d.ts +13 -0
- package/es/FormHelper/index.js +41 -0
- package/es/Highlighter/FullFeatured.d.ts +18 -0
- package/es/Highlighter/FullFeatured.js +102 -0
- package/es/Highlighter/SyntaxHighlighter/index.d.ts +7 -0
- package/es/Highlighter/SyntaxHighlighter/index.js +51 -0
- package/es/Highlighter/SyntaxHighlighter/style.d.ts +5 -0
- package/es/Highlighter/SyntaxHighlighter/style.js +16 -0
- package/es/Highlighter/index.d.ts +50 -0
- package/es/Highlighter/index.js +77 -0
- package/es/Highlighter/style.d.ts +9 -0
- package/es/Highlighter/style.js +23 -0
- package/es/Highlighter/theme.d.ts +1 -0
- package/es/Highlighter/theme.js +1661 -0
- package/es/LogViewer/index.d.ts +10 -0
- package/es/LogViewer/index.js +141 -0
- package/es/LogViewer/style.d.ts +6 -0
- package/es/LogViewer/style.js +16 -0
- package/es/LogViewer/types.d.ts +235 -0
- package/es/LogViewer/types.js +1 -0
- package/es/Mentions/constants.d.ts +6 -0
- package/es/Mentions/constants.js +28 -0
- package/es/Mentions/hooks.d.ts +20 -0
- package/es/Mentions/hooks.js +133 -0
- package/es/Mentions/index.d.ts +19 -0
- package/es/Mentions/index.js +136 -0
- package/es/Mentions/plugins/custom-text/node.d.ts +11 -0
- package/es/Mentions/plugins/custom-text/node.js +72 -0
- package/es/Mentions/plugins/mention-node/component.d.ts +6 -0
- package/es/Mentions/plugins/mention-node/component.js +64 -0
- package/es/Mentions/plugins/mention-node/index.d.ts +9 -0
- package/es/Mentions/plugins/mention-node/index.js +32 -0
- package/es/Mentions/plugins/mention-node/node.d.ts +23 -0
- package/es/Mentions/plugins/mention-node/node.js +97 -0
- package/es/Mentions/plugins/mention-node/replacement.d.ts +5 -0
- package/es/Mentions/plugins/mention-node/replacement.js +42 -0
- package/es/Mentions/plugins/mention-node/style.d.ts +8 -0
- package/es/Mentions/plugins/mention-node/style.js +47 -0
- package/es/Mentions/plugins/mention-node/utils.d.ts +4 -0
- package/es/Mentions/plugins/mention-node/utils.js +5 -0
- package/es/Mentions/plugins/mention-picker/hooks.d.ts +5 -0
- package/es/Mentions/plugins/mention-picker/hooks.js +39 -0
- package/es/Mentions/plugins/mention-picker/index.d.ts +36 -0
- package/es/Mentions/plugins/mention-picker/index.js +87 -0
- package/es/Mentions/plugins/mention-picker/menu-item.d.ts +11 -0
- package/es/Mentions/plugins/mention-picker/menu-item.js +71 -0
- package/es/Mentions/plugins/mention-picker/menu.d.ts +9 -0
- package/es/Mentions/plugins/mention-picker/menu.js +30 -0
- package/es/Mentions/plugins/mention-picker/style.d.ts +11 -0
- package/es/Mentions/plugins/mention-picker/style.js +19 -0
- package/es/Mentions/plugins/mention-picker/utils.d.ts +22 -0
- package/es/Mentions/plugins/mention-picker/utils.js +39 -0
- package/es/Mentions/plugins/on-blur-or-focus-block.d.ts +7 -0
- package/es/Mentions/plugins/on-blur-or-focus-block.js +36 -0
- package/es/Mentions/provider.d.ts +12 -0
- package/es/Mentions/provider.js +15 -0
- package/es/Mentions/style.d.ts +11 -0
- package/es/Mentions/style.js +22 -0
- package/es/Mentions/types.d.ts +17 -0
- package/es/Mentions/types.js +1 -0
- package/es/Mentions/utils.d.ts +9 -0
- package/es/Mentions/utils.js +95 -0
- package/es/Modal/index.d.ts +19 -0
- package/es/Modal/index.js +36 -0
- package/es/Modal/style.d.ts +4 -0
- package/es/Modal/style.js +17 -0
- package/es/MonacoEditor/base/controller.d.ts +17 -0
- package/es/MonacoEditor/base/controller.js +49 -0
- package/es/MonacoEditor/base/helper.d.ts +65 -0
- package/es/MonacoEditor/base/helper.js +324 -0
- package/es/MonacoEditor/base/index.d.ts +35 -0
- package/es/MonacoEditor/base/index.js +236 -0
- package/es/MonacoEditor/base/monaco.d.ts +6 -0
- package/es/MonacoEditor/base/monaco.js +64 -0
- package/es/MonacoEditor/base/style.d.ts +12 -0
- package/es/MonacoEditor/base/style.js +26 -0
- package/es/MonacoEditor/index.d.ts +2 -4
- package/es/MonacoEditor/index.js +26 -62
- package/es/MonacoEditor/style.js +3 -2
- package/es/Page/Breadcrumb/index.d.ts +9 -0
- package/es/Page/Breadcrumb/index.js +56 -0
- package/es/Page/Content/index.d.ts +4 -0
- package/es/Page/Content/index.js +59 -0
- package/es/Page/Content/style.d.ts +3 -0
- package/es/Page/Content/style.js +12 -0
- package/es/Page/Footer/index.d.ts +2 -0
- package/es/Page/Footer/index.js +6 -0
- package/es/Page/Header/Icon.d.ts +17 -0
- package/es/Page/Header/Icon.js +42 -0
- package/es/Page/Header/index.d.ts +43 -0
- package/es/Page/Header/index.js +202 -0
- package/es/Page/Header/style.d.ts +12 -0
- package/es/Page/Header/style.js +21 -0
- package/es/Page/Page.d.ts +9 -0
- package/es/Page/Page.js +49 -0
- package/es/Page/PageContext.d.ts +15 -0
- package/es/Page/PageContext.js +21 -0
- package/es/Page/Title/index.d.ts +5 -0
- package/es/Page/Title/index.js +18 -0
- package/es/Page/Title/style.d.ts +3 -0
- package/es/Page/Title/style.js +10 -0
- package/es/Page/index.d.ts +18 -0
- package/es/Page/index.js +15 -0
- package/es/Page/style.d.ts +3 -0
- package/es/Page/style.js +10 -0
- package/es/ProCard/Card/index.d.ts +6 -0
- package/es/ProCard/Card/index.js +25 -0
- package/es/ProCard/Card/style.d.ts +7 -0
- package/es/ProCard/Card/style.js +15 -0
- package/es/ProCard/Content/index.d.ts +4 -0
- package/es/ProCard/Content/index.js +24 -0
- package/es/ProCard/Content/style.d.ts +3 -0
- package/es/ProCard/Content/style.js +10 -0
- package/es/ProCard/Descriptions/index.d.ts +4 -0
- package/es/ProCard/Descriptions/index.js +28 -0
- package/es/ProCard/Descriptions/style.d.ts +3 -0
- package/es/ProCard/Descriptions/style.js +12 -0
- package/es/ProCard/Header/index.d.ts +15 -0
- package/es/ProCard/Header/index.js +86 -0
- package/es/ProCard/Header/style.d.ts +12 -0
- package/es/ProCard/Header/style.js +21 -0
- package/es/ProCard/index.d.ts +13 -0
- package/es/ProCard/index.js +8 -0
- package/es/Radio/index.d.ts +36 -0
- package/es/Radio/index.js +26 -0
- package/es/Radio/style.d.ts +4 -0
- package/es/Radio/style.js +66 -0
- package/es/SelectCard/index.d.ts +33 -0
- package/es/SelectCard/index.js +132 -0
- package/es/SelectCard/style.d.ts +10 -0
- package/es/SelectCard/style.js +42 -0
- package/es/SliderInput/index.js +2 -2
- package/es/Status/index.d.ts +7 -0
- package/es/Status/index.js +39 -0
- package/es/Status/style.d.ts +4 -0
- package/es/Status/style.js +14 -0
- package/es/Table/collapse/index.d.ts +8 -0
- package/es/Table/collapse/index.js +39 -0
- package/es/Table/collapse/style.d.ts +3 -0
- package/es/Table/collapse/style.js +11 -0
- package/es/Table/index.d.ts +20 -0
- package/es/Table/index.js +56 -0
- package/es/Typography/index.d.ts +32 -0
- package/es/Typography/index.js +77 -0
- package/es/WaveformIcon/index.d.ts +9 -0
- package/es/WaveformIcon/index.js +51 -0
- package/es/hooks/languageMap.d.ts +1 -0
- package/es/hooks/languageMap.js +1 -0
- package/es/hooks/useHighlight.d.ts +5 -0
- package/es/hooks/useHighlight.js +78 -0
- package/es/index.d.ts +38 -1
- package/es/index.js +52 -1
- package/es/notification/index.d.ts +24 -0
- package/es/notification/index.js +237 -0
- package/es/notification/style.d.ts +2 -0
- package/es/notification/style.js +28 -0
- package/es/styles/colors/colors.d.ts +39 -0
- package/es/styles/colors/colors.js +86 -0
- package/es/styles/colors/generateColorPalette.d.ts +11 -0
- package/es/styles/colors/generateColorPalette.js +31 -0
- package/es/styles/colors/neutralColors.d.ts +9 -0
- package/es/styles/colors/neutralColors.js +32 -0
- package/es/styles/index.d.ts +4 -0
- package/es/styles/index.js +4 -0
- package/es/useSpeechSynthes/const/polyfill.d.ts +3 -0
- package/es/useSpeechSynthes/const/polyfill.js +21 -0
- package/es/useSpeechSynthes/index.d.ts +13 -0
- package/es/useSpeechSynthes/index.js +69 -0
- package/es/utils/constants.d.ts +1 -0
- package/es/utils/constants.js +1 -0
- package/es/utils/tools.d.ts +1 -0
- package/es/utils/tools.js +1 -0
- package/package.json +30 -9
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
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
|
+
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 { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
5
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
6
|
+
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
7
|
+
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
8
|
+
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
9
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
10
|
+
import { $getRoot, TextNode } from 'lexical';
|
|
11
|
+
import React, { useMemo } from 'react';
|
|
12
|
+
import { isBrowser } from "../utils/tools";
|
|
13
|
+
import { CustomTextNode } from "./plugins/custom-text/node";
|
|
14
|
+
import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
|
|
15
|
+
import { MentionPickerPlugin } from "./plugins/mention-picker";
|
|
16
|
+
import OnBlurBlock from "./plugins/on-blur-or-focus-block";
|
|
17
|
+
import { MentionsConfigProvider } from "./provider";
|
|
18
|
+
import { useStyles } from "./style";
|
|
19
|
+
import { textToEditorState } from "./utils";
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
export var Mentions = function Mentions(_ref) {
|
|
23
|
+
var className = _ref.className,
|
|
24
|
+
wrapperClassname = _ref.wrapperClassname,
|
|
25
|
+
placeholder = _ref.placeholder,
|
|
26
|
+
style = _ref.style,
|
|
27
|
+
value = _ref.value,
|
|
28
|
+
defaultValue = _ref.defaultValue,
|
|
29
|
+
_ref$readOnly = _ref.readOnly,
|
|
30
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
31
|
+
_ref$disabled = _ref.disabled,
|
|
32
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
33
|
+
onChange = _ref.onChange,
|
|
34
|
+
onBlur = _ref.onBlur,
|
|
35
|
+
onFocus = _ref.onFocus,
|
|
36
|
+
_ref$variant = _ref.variant,
|
|
37
|
+
variant = _ref$variant === void 0 ? 'outlined' : _ref$variant,
|
|
38
|
+
_ref$options = _ref.options,
|
|
39
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
40
|
+
autoSize = _ref.autoSize,
|
|
41
|
+
_ref$triggers = _ref.triggers,
|
|
42
|
+
triggers = _ref$triggers === void 0 ? ['@'] : _ref$triggers,
|
|
43
|
+
allowSpaces = _ref.allowSpaces,
|
|
44
|
+
punctuation = _ref.punctuation,
|
|
45
|
+
preTriggerChars = _ref.preTriggerChars,
|
|
46
|
+
onSelect = _ref.onSelect;
|
|
47
|
+
var _useStyles = useStyles({
|
|
48
|
+
autoSize: autoSize
|
|
49
|
+
}),
|
|
50
|
+
styles = _useStyles.styles,
|
|
51
|
+
cx = _useStyles.cx;
|
|
52
|
+
var editable = !readOnly && !disabled;
|
|
53
|
+
var initialConfig = useMemo(function () {
|
|
54
|
+
return {
|
|
55
|
+
namespace: 'mentions',
|
|
56
|
+
nodes: [CustomTextNode, {
|
|
57
|
+
replace: TextNode,
|
|
58
|
+
with: function _with(node) {
|
|
59
|
+
return new CustomTextNode(node.__text);
|
|
60
|
+
}
|
|
61
|
+
}, MentionNode],
|
|
62
|
+
editorState: textToEditorState(value || defaultValue || ''),
|
|
63
|
+
onError: function onError(error) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
+
[]);
|
|
70
|
+
var handleEditorChange = function handleEditorChange(editorState) {
|
|
71
|
+
var text = editorState.read(function () {
|
|
72
|
+
return $getRoot().getTextContent();
|
|
73
|
+
});
|
|
74
|
+
onChange === null || onChange === void 0 || onChange(text.replaceAll('\n\n', '\n'));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// @Todo: set value when value change
|
|
78
|
+
// useEffect(() => {
|
|
79
|
+
// //
|
|
80
|
+
// }, [value])
|
|
81
|
+
|
|
82
|
+
var optionsMap = useMemo(function () {
|
|
83
|
+
return options.reduce(function (acc, option) {
|
|
84
|
+
acc[option.value] = option;
|
|
85
|
+
return acc;
|
|
86
|
+
}, {});
|
|
87
|
+
}, [options]);
|
|
88
|
+
if (!isBrowser) {
|
|
89
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
90
|
+
className: cx(styles.wrapper, wrapperClassname),
|
|
91
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
92
|
+
className: cx(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.root, true), styles.filled, variant === 'filled'), styles.borderless, variant === 'borderless'), styles.disabled, disabled), className),
|
|
93
|
+
style: style || {}
|
|
94
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
95
|
+
className: styles.placeholder,
|
|
96
|
+
children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
|
|
97
|
+
})]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return /*#__PURE__*/_jsx(LexicalComposer, {
|
|
101
|
+
initialConfig: _objectSpread(_objectSpread({}, initialConfig), {}, {
|
|
102
|
+
editable: editable
|
|
103
|
+
}),
|
|
104
|
+
children: /*#__PURE__*/_jsx(MentionsConfigProvider, {
|
|
105
|
+
value: {
|
|
106
|
+
optionsMap: optionsMap
|
|
107
|
+
},
|
|
108
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
109
|
+
className: cx(styles.wrapper, wrapperClassname),
|
|
110
|
+
children: [/*#__PURE__*/_jsx(RichTextPlugin, {
|
|
111
|
+
ErrorBoundary: LexicalErrorBoundary,
|
|
112
|
+
contentEditable: /*#__PURE__*/_jsx(ContentEditable, {
|
|
113
|
+
className: cx(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.root, true), styles.filled, variant === 'filled'), styles.borderless, variant === 'borderless'), styles.disabled, disabled), className),
|
|
114
|
+
style: style || {}
|
|
115
|
+
}),
|
|
116
|
+
placeholder: /*#__PURE__*/_jsx("div", {
|
|
117
|
+
className: styles.placeholder,
|
|
118
|
+
children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
|
|
119
|
+
})
|
|
120
|
+
}), /*#__PURE__*/_jsx(MentionPickerPlugin, {
|
|
121
|
+
allowSpaces: allowSpaces,
|
|
122
|
+
onSelect: onSelect,
|
|
123
|
+
options: options,
|
|
124
|
+
preTriggerChars: preTriggerChars,
|
|
125
|
+
punctuation: punctuation,
|
|
126
|
+
triggers: triggers
|
|
127
|
+
}), /*#__PURE__*/_jsx(MentionNodePlugin, {}), /*#__PURE__*/_jsx(MentionNodePluginReplacement, {}), /*#__PURE__*/_jsx(HistoryPlugin, {}), /*#__PURE__*/_jsx(OnChangePlugin, {
|
|
128
|
+
onChange: handleEditorChange
|
|
129
|
+
}), /*#__PURE__*/_jsx(OnBlurBlock, {
|
|
130
|
+
onBlur: onBlur,
|
|
131
|
+
onFocus: onFocus
|
|
132
|
+
})]
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EditorConfig, SerializedTextNode } from 'lexical';
|
|
2
|
+
import { TextNode } from 'lexical';
|
|
3
|
+
export declare class CustomTextNode extends TextNode {
|
|
4
|
+
static getType(): string;
|
|
5
|
+
static clone(node: CustomTextNode): CustomTextNode;
|
|
6
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
7
|
+
static importJSON(serializedNode: SerializedTextNode): TextNode;
|
|
8
|
+
exportJSON(): SerializedTextNode;
|
|
9
|
+
isSimpleText(): boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function $createCustomTextNode(text: string): CustomTextNode;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _get from "@babel/runtime/helpers/esm/get";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
9
|
+
import { $createTextNode, TextNode } from 'lexical';
|
|
10
|
+
export var CustomTextNode = /*#__PURE__*/function (_TextNode) {
|
|
11
|
+
_inherits(CustomTextNode, _TextNode);
|
|
12
|
+
var _super = _createSuper(CustomTextNode);
|
|
13
|
+
function CustomTextNode() {
|
|
14
|
+
_classCallCheck(this, CustomTextNode);
|
|
15
|
+
return _super.apply(this, arguments);
|
|
16
|
+
}
|
|
17
|
+
_createClass(CustomTextNode, [{
|
|
18
|
+
key: "createDOM",
|
|
19
|
+
value:
|
|
20
|
+
// constructor(text: string, key?: NodeKey) {
|
|
21
|
+
// super(text, key)
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
function createDOM(config) {
|
|
25
|
+
var dom = _get(_getPrototypeOf(CustomTextNode.prototype), "createDOM", this).call(this, config);
|
|
26
|
+
dom.classList.add('align-middle');
|
|
27
|
+
return dom;
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "exportJSON",
|
|
31
|
+
value: function exportJSON() {
|
|
32
|
+
return {
|
|
33
|
+
detail: this.getDetail(),
|
|
34
|
+
format: this.getFormat(),
|
|
35
|
+
mode: this.getMode(),
|
|
36
|
+
style: this.getStyle(),
|
|
37
|
+
text: this.getTextContent(),
|
|
38
|
+
type: 'custom-text',
|
|
39
|
+
version: 1
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "isSimpleText",
|
|
44
|
+
value: function isSimpleText() {
|
|
45
|
+
return (this.__type === 'text' || this.__type === 'custom-text') && this.__mode === 0;
|
|
46
|
+
}
|
|
47
|
+
}], [{
|
|
48
|
+
key: "getType",
|
|
49
|
+
value: function getType() {
|
|
50
|
+
return 'custom-text';
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "clone",
|
|
54
|
+
value: function clone(node) {
|
|
55
|
+
return new CustomTextNode(node.__text, node.__key);
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "importJSON",
|
|
59
|
+
value: function importJSON(serializedNode) {
|
|
60
|
+
var node = $createTextNode(serializedNode.text);
|
|
61
|
+
node.setFormat(serializedNode.format);
|
|
62
|
+
node.setDetail(serializedNode.detail);
|
|
63
|
+
node.setMode(serializedNode.mode);
|
|
64
|
+
node.setStyle(serializedNode.style);
|
|
65
|
+
return node;
|
|
66
|
+
}
|
|
67
|
+
}]);
|
|
68
|
+
return CustomTextNode;
|
|
69
|
+
}(TextNode);
|
|
70
|
+
export function $createCustomTextNode(text) {
|
|
71
|
+
return new CustomTextNode(text);
|
|
72
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { Icon } from '@lobehub/ui';
|
|
4
|
+
import { Flex, Tooltip } from 'antd';
|
|
5
|
+
import { CircleAlert } from 'lucide-react';
|
|
6
|
+
import React, { memo, useEffect } from 'react';
|
|
7
|
+
import { useOptionsMap } from "../../provider";
|
|
8
|
+
import { useSelectOrDelete } from "../../hooks";
|
|
9
|
+
import { MentionNode } from "./node";
|
|
10
|
+
import { useStyles } from "./style";
|
|
11
|
+
import { DELETE_MENTION_COMMAND } from "./utils";
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export var MentionNodeComponent = /*#__PURE__*/memo(function (_ref) {
|
|
15
|
+
var nodeKey = _ref.nodeKey,
|
|
16
|
+
variable = _ref.variable;
|
|
17
|
+
var optionsMap = useOptionsMap();
|
|
18
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
19
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
20
|
+
editor = _useLexicalComposerCo2[0];
|
|
21
|
+
var _useSelectOrDelete = useSelectOrDelete(nodeKey, DELETE_MENTION_COMMAND),
|
|
22
|
+
_useSelectOrDelete2 = _slicedToArray(_useSelectOrDelete, 2),
|
|
23
|
+
ref = _useSelectOrDelete2[0],
|
|
24
|
+
isSelected = _useSelectOrDelete2[1];
|
|
25
|
+
var option = optionsMap === null || optionsMap === void 0 ? void 0 : optionsMap[variable];
|
|
26
|
+
var _useStyles = useStyles({
|
|
27
|
+
isSelected: isSelected,
|
|
28
|
+
isError: !option || !!option.error
|
|
29
|
+
}),
|
|
30
|
+
styles = _useStyles.styles;
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
if (!editor.hasNodes([MentionNode])) {
|
|
33
|
+
throw new Error('MentionsNodePlugin: MentionNode not registered on editor');
|
|
34
|
+
}
|
|
35
|
+
}, [editor]);
|
|
36
|
+
var Item = /*#__PURE__*/_jsx(Flex, {
|
|
37
|
+
className: styles.root,
|
|
38
|
+
ref: ref,
|
|
39
|
+
children: /*#__PURE__*/_jsxs(Flex, {
|
|
40
|
+
align: "center",
|
|
41
|
+
gap: 2,
|
|
42
|
+
children: [(!option || option.error) && /*#__PURE__*/_jsx(Icon, {
|
|
43
|
+
className: styles.error,
|
|
44
|
+
icon: CircleAlert
|
|
45
|
+
}), (option === null || option === void 0 ? void 0 : option.icon) && /*#__PURE__*/_jsx(Flex, {
|
|
46
|
+
children: option.icon
|
|
47
|
+
}), /*#__PURE__*/_jsx(Flex, {
|
|
48
|
+
className: styles.text,
|
|
49
|
+
gap: 2,
|
|
50
|
+
title: (option === null || option === void 0 ? void 0 : option.label) || variable,
|
|
51
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
52
|
+
children: (option === null || option === void 0 ? void 0 : option.label) || variable
|
|
53
|
+
})
|
|
54
|
+
})]
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
if (option !== null && option !== void 0 && option.error) {
|
|
58
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
59
|
+
title: option === null || option === void 0 ? void 0 : option.error,
|
|
60
|
+
children: Item
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return Item;
|
|
64
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export * from './node';
|
|
3
|
+
export * from './replacement';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export interface MentionNodePluginProps {
|
|
6
|
+
onInsert?: () => void;
|
|
7
|
+
onDelete?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const MentionNodePlugin: React.FC<MentionNodePluginProps>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { mergeRegister } from '@lexical/utils';
|
|
4
|
+
import { $insertNodes, COMMAND_PRIORITY_EDITOR } from 'lexical';
|
|
5
|
+
import { memo, useEffect } from 'react';
|
|
6
|
+
import { $createMentionNode, MentionNode } from "./node";
|
|
7
|
+
import { CLEAR_HIDE_MENU_TIMEOUT, DELETE_MENTION_COMMAND, INSERT_MENTION_COMMAND } from "./utils";
|
|
8
|
+
export * from "./node";
|
|
9
|
+
export * from "./replacement";
|
|
10
|
+
export * from "./utils";
|
|
11
|
+
export var MentionNodePlugin = /*#__PURE__*/memo(function (_ref) {
|
|
12
|
+
var onInsert = _ref.onInsert,
|
|
13
|
+
onDelete = _ref.onDelete;
|
|
14
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
15
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
16
|
+
editor = _useLexicalComposerCo2[0];
|
|
17
|
+
useEffect(function () {
|
|
18
|
+
if (!editor.hasNodes([MentionNode])) throw new Error('MentionsNodePlugin: MentionNode not registered on editor');
|
|
19
|
+
return mergeRegister(editor.registerCommand(INSERT_MENTION_COMMAND, function (variable) {
|
|
20
|
+
editor.dispatchCommand(CLEAR_HIDE_MENU_TIMEOUT, null);
|
|
21
|
+
var mentionNode = $createMentionNode(variable);
|
|
22
|
+
$insertNodes([mentionNode]);
|
|
23
|
+
if (onInsert) onInsert();
|
|
24
|
+
return true;
|
|
25
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_MENTION_COMMAND, function () {
|
|
26
|
+
if (onDelete) onDelete();
|
|
27
|
+
return true;
|
|
28
|
+
}, COMMAND_PRIORITY_EDITOR));
|
|
29
|
+
}, [editor, onInsert, onDelete]);
|
|
30
|
+
return null;
|
|
31
|
+
});
|
|
32
|
+
MentionNodePlugin.displayName = 'MentionNodePlugin';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LexicalNode, NodeKey, SerializedLexicalNode } from 'lexical';
|
|
3
|
+
import { DecoratorNode } from 'lexical';
|
|
4
|
+
import type { MentionsOptionsMap } from '../../types';
|
|
5
|
+
export type SerializedNode = SerializedLexicalNode & {
|
|
6
|
+
variable: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class MentionNode extends DecoratorNode<JSX.Element> {
|
|
9
|
+
__variable: string;
|
|
10
|
+
static getType(): string;
|
|
11
|
+
static clone(node: MentionNode): MentionNode;
|
|
12
|
+
isInline(): boolean;
|
|
13
|
+
constructor(variable: string, optionsMap?: MentionsOptionsMap, key?: NodeKey);
|
|
14
|
+
createDOM(): HTMLElement;
|
|
15
|
+
updateDOM(): false;
|
|
16
|
+
decorate(): JSX.Element;
|
|
17
|
+
static importJSON(serializedNode: SerializedNode): MentionNode;
|
|
18
|
+
exportJSON(): SerializedNode;
|
|
19
|
+
getVariable(): string;
|
|
20
|
+
getTextContent(): string;
|
|
21
|
+
}
|
|
22
|
+
export declare function $createMentionNode(variable: string): MentionNode;
|
|
23
|
+
export declare function $isMentionNode(node: MentionNode | LexicalNode | null | undefined): node is MentionNode;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
+
import { DecoratorNode } from 'lexical';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { MentionNodeComponent } from "./component";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export var MentionNode = /*#__PURE__*/function (_DecoratorNode) {
|
|
15
|
+
_inherits(MentionNode, _DecoratorNode);
|
|
16
|
+
var _super = _createSuper(MentionNode);
|
|
17
|
+
function MentionNode(variable, optionsMap, key) {
|
|
18
|
+
var _this;
|
|
19
|
+
_classCallCheck(this, MentionNode);
|
|
20
|
+
_this = _super.call(this, key);
|
|
21
|
+
_defineProperty(_assertThisInitialized(_this), "__variable", void 0);
|
|
22
|
+
_this.__variable = variable;
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
_createClass(MentionNode, [{
|
|
26
|
+
key: "isInline",
|
|
27
|
+
value: function isInline() {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
key: "createDOM",
|
|
32
|
+
value: function createDOM() {
|
|
33
|
+
var div = document.createElement('div');
|
|
34
|
+
div.style.display = 'inline-flex';
|
|
35
|
+
div.style.alignItems = 'center';
|
|
36
|
+
div.style.verticalAlign = 'middle';
|
|
37
|
+
return div;
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "updateDOM",
|
|
41
|
+
value: function updateDOM() {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "decorate",
|
|
46
|
+
value: function decorate() {
|
|
47
|
+
return /*#__PURE__*/_jsx(MentionNodeComponent, {
|
|
48
|
+
nodeKey: this.getKey(),
|
|
49
|
+
variable: this.__variable
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "exportJSON",
|
|
54
|
+
value: function exportJSON() {
|
|
55
|
+
return {
|
|
56
|
+
type: 'mention-node',
|
|
57
|
+
version: 1,
|
|
58
|
+
variable: this.getVariable()
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "getVariable",
|
|
63
|
+
value: function getVariable() {
|
|
64
|
+
var self = this.getLatest();
|
|
65
|
+
return self.__variable;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "getTextContent",
|
|
69
|
+
value: function getTextContent() {
|
|
70
|
+
return "{{".concat(this.getVariable(), "}}");
|
|
71
|
+
}
|
|
72
|
+
}], [{
|
|
73
|
+
key: "getType",
|
|
74
|
+
value: function getType() {
|
|
75
|
+
return 'mention-node';
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "clone",
|
|
79
|
+
value: function clone(node) {
|
|
80
|
+
return new MentionNode(node.__variable);
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "importJSON",
|
|
84
|
+
value: function importJSON(serializedNode) {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
86
|
+
var node = $createMentionNode(serializedNode.variable);
|
|
87
|
+
return node;
|
|
88
|
+
}
|
|
89
|
+
}]);
|
|
90
|
+
return MentionNode;
|
|
91
|
+
}(DecoratorNode);
|
|
92
|
+
export function $createMentionNode(variable) {
|
|
93
|
+
return new MentionNode(variable);
|
|
94
|
+
}
|
|
95
|
+
export function $isMentionNode(node) {
|
|
96
|
+
return node instanceof MentionNode;
|
|
97
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { mergeRegister } from '@lexical/utils';
|
|
4
|
+
import { $applyNodeReplacement } from 'lexical';
|
|
5
|
+
import { memo, useCallback, useEffect } from 'react';
|
|
6
|
+
import { decoratorTransform } from "../../utils";
|
|
7
|
+
import { CustomTextNode } from "../custom-text/node";
|
|
8
|
+
import { $createMentionNode, MentionNode } from "./node";
|
|
9
|
+
import { MENTION_REGEX } from "./utils";
|
|
10
|
+
export var MentionNodePluginReplacement = /*#__PURE__*/memo(function (_ref) {
|
|
11
|
+
var onInsert = _ref.onInsert;
|
|
12
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
13
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
14
|
+
editor = _useLexicalComposerCo2[0];
|
|
15
|
+
useEffect(function () {
|
|
16
|
+
if (!editor.hasNodes([MentionNode])) throw new Error('MentionNodePlugin: MentionNode not registered on editor');
|
|
17
|
+
}, [editor]);
|
|
18
|
+
var createMentionNode = useCallback(function (textNode) {
|
|
19
|
+
if (onInsert) onInsert();
|
|
20
|
+
var nodePathString = textNode.getTextContent().slice(2, -2);
|
|
21
|
+
return $applyNodeReplacement($createMentionNode(nodePathString));
|
|
22
|
+
}, [onInsert]);
|
|
23
|
+
var getMatch = useCallback(function (text) {
|
|
24
|
+
var matchArr = MENTION_REGEX.exec(text);
|
|
25
|
+
if (matchArr === null) return null;
|
|
26
|
+
var startOffset = matchArr.index;
|
|
27
|
+
var endOffset = startOffset + matchArr[0].length;
|
|
28
|
+
return {
|
|
29
|
+
end: endOffset,
|
|
30
|
+
start: startOffset
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
var transformListener = useCallback(function (textNode) {
|
|
34
|
+
return decoratorTransform(textNode, getMatch, createMentionNode);
|
|
35
|
+
}, [createMentionNode, getMatch]);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
MENTION_REGEX.lastIndex = 0;
|
|
38
|
+
return mergeRegister(editor.registerNodeTransform(CustomTextNode, transformListener));
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, []);
|
|
41
|
+
return null;
|
|
42
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const useStyles: (props?: {
|
|
2
|
+
isSelected?: boolean | undefined;
|
|
3
|
+
isError?: boolean | undefined;
|
|
4
|
+
} | undefined) => import("antd-style").ReturnStyles<{
|
|
5
|
+
root: import("antd-style").SerializedStyles;
|
|
6
|
+
text: import("antd-style").SerializedStyles;
|
|
7
|
+
error: import("antd-style").SerializedStyles;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
export var useStyles = createStyles(function (_ref, _ref2) {
|
|
5
|
+
var css = _ref.css,
|
|
6
|
+
token = _ref.token,
|
|
7
|
+
prefixCls = _ref.prefixCls;
|
|
8
|
+
var isSelected = _ref2.isSelected,
|
|
9
|
+
isError = _ref2.isError;
|
|
10
|
+
var getColors = function getColors() {
|
|
11
|
+
if (isError) {
|
|
12
|
+
if (isSelected) {
|
|
13
|
+
return {
|
|
14
|
+
background: token.colorErrorBgActive,
|
|
15
|
+
border: token.colorErrorBorderHover,
|
|
16
|
+
color: token.colorErrorTextActive
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
background: token.colorErrorBg,
|
|
21
|
+
border: token.colorErrorBorder,
|
|
22
|
+
color: token.colorErrorText
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (isSelected) {
|
|
26
|
+
return {
|
|
27
|
+
background: token.colorInfoBgHover,
|
|
28
|
+
border: token.colorInfoBorder,
|
|
29
|
+
color: token.colorInfoText
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
background: token.colorFillTertiary,
|
|
34
|
+
border: 'transparent',
|
|
35
|
+
color: token.colorInfoText
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
var _getColors = getColors(),
|
|
39
|
+
background = _getColors.background,
|
|
40
|
+
border = _getColors.border,
|
|
41
|
+
color = _getColors.color;
|
|
42
|
+
return {
|
|
43
|
+
root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n margin: 1px 2px;\n padding: 0 4px;\n\n font-family: ", ";\n color: ", ";\n\n background-color: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n "])), token.fontFamilyCode, color, background, border, token.borderRadius),
|
|
44
|
+
text: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: inline-block;\n\n max-width: 200px;\n\n color: ", ";\n text-overflow: ellipsis;\n white-space: nowrap;\n "])), token.colorTextSecondary),
|
|
45
|
+
error: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n color: ", ";\n "])), token.colorErrorText)
|
|
46
|
+
};
|
|
47
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const INSERT_MENTION_COMMAND: import("lexical").LexicalCommand<unknown>;
|
|
2
|
+
export declare const DELETE_MENTION_COMMAND: import("lexical").LexicalCommand<unknown>;
|
|
3
|
+
export declare const CLEAR_HIDE_MENU_TIMEOUT: import("lexical").LexicalCommand<unknown>;
|
|
4
|
+
export declare const MENTION_REGEX: RegExp;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createCommand } from 'lexical';
|
|
2
|
+
export var INSERT_MENTION_COMMAND = createCommand('INSERT_MENTION_COMMAND');
|
|
3
|
+
export var DELETE_MENTION_COMMAND = createCommand('DELETE_MENTION_COMMAND');
|
|
4
|
+
export var CLEAR_HIDE_MENU_TIMEOUT = createCommand('CLEAR_HIDE_MENU_TIMEOUT');
|
|
5
|
+
export var MENTION_REGEX = /{{([\w-]{1,50}(\.[_a-z]\w{0,29}){1,10})}}/gi;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { escapeRegExp } from 'lodash-es';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { INSERT_MENTION_COMMAND } from "../mention-node";
|
|
6
|
+
import { MentionMenuOption } from "./utils";
|
|
7
|
+
export var useOptions = function useOptions(allOptions, queryString) {
|
|
8
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
9
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
10
|
+
editor = _useLexicalComposerCo2[0];
|
|
11
|
+
var options = useMemo(function () {
|
|
12
|
+
var menuOptions = allOptions.map(function (o) {
|
|
13
|
+
return new MentionMenuOption(o.value, o.label, {
|
|
14
|
+
icon: o.icon,
|
|
15
|
+
onSelect: function onSelect() {
|
|
16
|
+
editor.dispatchCommand(INSERT_MENTION_COMMAND, o.value);
|
|
17
|
+
},
|
|
18
|
+
disabled: o.disabled,
|
|
19
|
+
data: o.data,
|
|
20
|
+
extraElement: o.extraElement,
|
|
21
|
+
keywords: o.keywords,
|
|
22
|
+
keyboardShortcut: o.keyboardShortcut
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
if (!queryString) {
|
|
26
|
+
return menuOptions;
|
|
27
|
+
}
|
|
28
|
+
var regex = new RegExp(escapeRegExp(queryString), 'i');
|
|
29
|
+
return menuOptions.filter(function (o) {
|
|
30
|
+
var _o$keywords;
|
|
31
|
+
return regex.test(o.label) || ((_o$keywords = o.keywords) === null || _o$keywords === void 0 ? void 0 : _o$keywords.some(function (keyword) {
|
|
32
|
+
return regex.test(keyword);
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
}, [allOptions, queryString, editor]);
|
|
36
|
+
return {
|
|
37
|
+
options: options
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { MentionOption } from '../../types';
|
|
3
|
+
import { type MentionMenuOption } from './utils';
|
|
4
|
+
export interface MentionPickerPluginProps {
|
|
5
|
+
options?: MentionOption[];
|
|
6
|
+
/**
|
|
7
|
+
* The characters that trigger the mention menu. Needed to tell the plugin
|
|
8
|
+
* when to call the query function.
|
|
9
|
+
*/
|
|
10
|
+
triggers: string[];
|
|
11
|
+
/**
|
|
12
|
+
* If `true`, mentions can contain spaces.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
allowSpaces?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Regular expression that matches punctuation characters when looking for
|
|
18
|
+
* mentions.
|
|
19
|
+
*
|
|
20
|
+
* In addition to spaces, these characters can appear directly after a mention.
|
|
21
|
+
* E.g. `@John!` or `@John,`.
|
|
22
|
+
* @default \.,\*\?\$\|#{}\(\)\^\[\]\/!%'\"~=<>_:;
|
|
23
|
+
*/
|
|
24
|
+
punctuation?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Regular expression that matches characters that can appear directly
|
|
27
|
+
* before the trigger character.
|
|
28
|
+
* @default \(
|
|
29
|
+
*/
|
|
30
|
+
preTriggerChars?: string;
|
|
31
|
+
/**
|
|
32
|
+
* When mention selected, this func will be called
|
|
33
|
+
*/
|
|
34
|
+
onSelect?: (option: MentionMenuOption, trigger: string | null, queryString: string | null) => void;
|
|
35
|
+
}
|
|
36
|
+
export declare const MentionPickerPlugin: React.FC<MentionPickerPluginProps>;
|