@yuntijs/ui 1.0.0-beta.9 → 1.0.0-beta.90

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.
Files changed (241) hide show
  1. package/es/App/index.d.ts +7 -0
  2. package/es/App/index.js +19 -0
  3. package/es/ButtonGroup/index.d.ts +24 -0
  4. package/es/ButtonGroup/index.js +66 -0
  5. package/es/Card/index.d.ts +1 -0
  6. package/es/Card/index.js +1 -0
  7. package/es/CardList/Item/index.d.ts +4 -0
  8. package/es/CardList/Item/index.js +43 -0
  9. package/es/CardList/Item/style.d.ts +0 -0
  10. package/es/CardList/Item/style.js +0 -0
  11. package/es/CardList/index.d.ts +2 -0
  12. package/es/CardList/index.js +39 -0
  13. package/es/ChatInputArea/desktop/ChatInputArea.d.ts +19 -0
  14. package/es/ChatInputArea/desktop/ChatInputArea.js +72 -0
  15. package/es/ChatInputArea/index.d.ts +6 -0
  16. package/es/ChatInputArea/index.js +6 -0
  17. package/es/ChatItem/components/Actions.d.ts +10 -0
  18. package/es/ChatItem/components/Actions.js +23 -0
  19. package/es/ChatItem/components/MessageContent.d.ts +21 -0
  20. package/es/ChatItem/components/MessageContent.js +59 -0
  21. package/es/ChatItem/index.d.ts +4 -0
  22. package/es/ChatItem/index.js +120 -0
  23. package/es/ChatItem/style.d.ts +25 -0
  24. package/es/ChatItem/style.js +39 -0
  25. package/es/ChatItem/type.d.ts +86 -0
  26. package/es/ChatItem/type.js +1 -0
  27. package/es/CollapseGroup/index.d.ts +4 -0
  28. package/es/CollapseGroup/index.js +23 -0
  29. package/es/CollapseGroup/style.d.ts +3 -0
  30. package/es/CollapseGroup/style.js +11 -0
  31. package/es/ConfigProvider/index.d.ts +3 -0
  32. package/es/ConfigProvider/index.js +17 -11
  33. package/es/Descriptions/index.d.ts +14 -0
  34. package/es/Descriptions/index.js +31 -0
  35. package/es/Descriptions/style.d.ts +4 -0
  36. package/es/Descriptions/style.js +24 -0
  37. package/es/Divider/index.d.ts +38 -0
  38. package/es/Divider/index.js +66 -0
  39. package/es/Divider/style.d.ts +3 -0
  40. package/es/Divider/style.js +12 -0
  41. package/es/DragPanel/index.d.ts +10 -0
  42. package/es/DragPanel/index.js +97 -0
  43. package/es/DragPanel/style.d.ts +7 -0
  44. package/es/DragPanel/style.js +15 -0
  45. package/es/Drawer/index.d.ts +13 -0
  46. package/es/Drawer/index.js +20 -0
  47. package/es/Drawer/style.d.ts +4 -0
  48. package/es/Drawer/style.js +16 -0
  49. package/es/Dropdown/index.d.ts +14 -0
  50. package/es/Dropdown/index.js +59 -0
  51. package/es/Dropdown/style.d.ts +7 -0
  52. package/es/Dropdown/style.js +13 -0
  53. package/es/EditableMessage/index.d.ts +75 -0
  54. package/es/EditableMessage/index.js +99 -0
  55. package/es/Form/collapse-list/index.d.ts +40 -0
  56. package/es/Form/collapse-list/index.js +209 -0
  57. package/es/Form/collapse-list/style.d.ts +5 -0
  58. package/es/Form/collapse-list/style.js +13 -0
  59. package/es/Form/index.d.ts +8 -0
  60. package/es/Form/index.js +5 -0
  61. package/es/FormHelper/autoFocus.d.ts +10 -0
  62. package/es/FormHelper/autoFocus.js +38 -0
  63. package/es/FormHelper/index.d.ts +13 -0
  64. package/es/FormHelper/index.js +41 -0
  65. package/es/Highlighter/FullFeatured.d.ts +18 -0
  66. package/es/Highlighter/FullFeatured.js +102 -0
  67. package/es/Highlighter/SyntaxHighlighter/index.d.ts +7 -0
  68. package/es/Highlighter/SyntaxHighlighter/index.js +51 -0
  69. package/es/Highlighter/SyntaxHighlighter/style.d.ts +5 -0
  70. package/es/Highlighter/SyntaxHighlighter/style.js +16 -0
  71. package/es/Highlighter/index.d.ts +50 -0
  72. package/es/Highlighter/index.js +77 -0
  73. package/es/Highlighter/style.d.ts +9 -0
  74. package/es/Highlighter/style.js +23 -0
  75. package/es/Highlighter/theme.d.ts +1 -0
  76. package/es/Highlighter/theme.js +1661 -0
  77. package/es/JsonViewer/index.d.ts +21 -0
  78. package/es/JsonViewer/index.js +120 -0
  79. package/es/JsonViewer/style.d.ts +7 -0
  80. package/es/JsonViewer/style.js +19 -0
  81. package/es/LogViewer/index.d.ts +10 -0
  82. package/es/LogViewer/index.js +141 -0
  83. package/es/LogViewer/style.d.ts +6 -0
  84. package/es/LogViewer/style.js +16 -0
  85. package/es/LogViewer/types.d.ts +235 -0
  86. package/es/LogViewer/types.js +1 -0
  87. package/es/Mentions/constants.d.ts +6 -0
  88. package/es/Mentions/constants.js +28 -0
  89. package/es/Mentions/hooks.d.ts +20 -0
  90. package/es/Mentions/hooks.js +133 -0
  91. package/es/Mentions/index.d.ts +23 -0
  92. package/es/Mentions/index.js +157 -0
  93. package/es/Mentions/plugins/OnBlurBlockPlugin.d.ts +7 -0
  94. package/es/Mentions/plugins/OnBlurBlockPlugin.js +35 -0
  95. package/es/Mentions/plugins/custom-text/node.d.ts +11 -0
  96. package/es/Mentions/plugins/custom-text/node.js +72 -0
  97. package/es/Mentions/plugins/editable.d.ts +4 -0
  98. package/es/Mentions/plugins/editable.js +13 -0
  99. package/es/Mentions/plugins/mention-node/component.d.ts +6 -0
  100. package/es/Mentions/plugins/mention-node/component.js +64 -0
  101. package/es/Mentions/plugins/mention-node/index.d.ts +9 -0
  102. package/es/Mentions/plugins/mention-node/index.js +32 -0
  103. package/es/Mentions/plugins/mention-node/node.d.ts +22 -0
  104. package/es/Mentions/plugins/mention-node/node.js +100 -0
  105. package/es/Mentions/plugins/mention-node/replacement.d.ts +5 -0
  106. package/es/Mentions/plugins/mention-node/replacement.js +43 -0
  107. package/es/Mentions/plugins/mention-node/style.d.ts +8 -0
  108. package/es/Mentions/plugins/mention-node/style.js +47 -0
  109. package/es/Mentions/plugins/mention-node/utils.d.ts +4 -0
  110. package/es/Mentions/plugins/mention-node/utils.js +10 -0
  111. package/es/Mentions/plugins/mention-picker/hooks.d.ts +5 -0
  112. package/es/Mentions/plugins/mention-picker/hooks.js +65 -0
  113. package/es/Mentions/plugins/mention-picker/index.d.ts +39 -0
  114. package/es/Mentions/plugins/mention-picker/index.js +137 -0
  115. package/es/Mentions/plugins/mention-picker/menu-item.d.ts +12 -0
  116. package/es/Mentions/plugins/mention-picker/menu-item.js +73 -0
  117. package/es/Mentions/plugins/mention-picker/menu.d.ts +10 -0
  118. package/es/Mentions/plugins/mention-picker/menu.js +31 -0
  119. package/es/Mentions/plugins/mention-picker/style.d.ts +11 -0
  120. package/es/Mentions/plugins/mention-picker/style.js +19 -0
  121. package/es/Mentions/plugins/mention-picker/utils.d.ts +31 -0
  122. package/es/Mentions/plugins/mention-picker/utils.js +66 -0
  123. package/es/Mentions/provider.d.ts +12 -0
  124. package/es/Mentions/provider.js +15 -0
  125. package/es/Mentions/style.d.ts +11 -0
  126. package/es/Mentions/style.js +22 -0
  127. package/es/Mentions/types.d.ts +12 -0
  128. package/es/Mentions/types.js +1 -0
  129. package/es/Mentions/utils.d.ts +9 -0
  130. package/es/Mentions/utils.js +95 -0
  131. package/es/Modal/index.d.ts +19 -0
  132. package/es/Modal/index.js +36 -0
  133. package/es/Modal/style.d.ts +4 -0
  134. package/es/Modal/style.js +17 -0
  135. package/es/MonacoEditor/base/controller.d.ts +17 -0
  136. package/es/MonacoEditor/base/controller.js +49 -0
  137. package/es/MonacoEditor/base/helper.d.ts +65 -0
  138. package/es/MonacoEditor/base/helper.js +324 -0
  139. package/es/MonacoEditor/base/index.d.ts +39 -0
  140. package/es/MonacoEditor/base/index.js +238 -0
  141. package/es/MonacoEditor/base/monaco.d.ts +6 -0
  142. package/es/MonacoEditor/base/monaco.js +64 -0
  143. package/es/MonacoEditor/{style.d.ts → base/style.d.ts} +4 -1
  144. package/es/MonacoEditor/base/style.js +43 -0
  145. package/es/MonacoEditor/index.d.ts +5 -4
  146. package/es/MonacoEditor/index.js +26 -62
  147. package/es/Page/Breadcrumb/index.d.ts +9 -0
  148. package/es/Page/Breadcrumb/index.js +56 -0
  149. package/es/Page/Content/index.d.ts +4 -0
  150. package/es/Page/Content/index.js +59 -0
  151. package/es/Page/Content/style.d.ts +3 -0
  152. package/es/Page/Content/style.js +12 -0
  153. package/es/Page/Footer/index.d.ts +2 -0
  154. package/es/Page/Footer/index.js +6 -0
  155. package/es/Page/Header/Icon.d.ts +17 -0
  156. package/es/Page/Header/Icon.js +42 -0
  157. package/es/Page/Header/index.d.ts +43 -0
  158. package/es/Page/Header/index.js +202 -0
  159. package/es/Page/Header/style.d.ts +12 -0
  160. package/es/Page/Header/style.js +21 -0
  161. package/es/Page/Page.d.ts +9 -0
  162. package/es/Page/Page.js +49 -0
  163. package/es/Page/PageContext.d.ts +15 -0
  164. package/es/Page/PageContext.js +21 -0
  165. package/es/Page/Title/index.d.ts +5 -0
  166. package/es/Page/Title/index.js +18 -0
  167. package/es/Page/Title/style.d.ts +3 -0
  168. package/es/Page/Title/style.js +10 -0
  169. package/es/Page/index.d.ts +18 -0
  170. package/es/Page/index.js +15 -0
  171. package/es/Page/style.d.ts +3 -0
  172. package/es/Page/style.js +10 -0
  173. package/es/ProCard/Card/index.d.ts +6 -0
  174. package/es/ProCard/Card/index.js +25 -0
  175. package/es/ProCard/Card/style.d.ts +7 -0
  176. package/es/ProCard/Card/style.js +15 -0
  177. package/es/ProCard/Content/index.d.ts +4 -0
  178. package/es/ProCard/Content/index.js +24 -0
  179. package/es/ProCard/Content/style.d.ts +3 -0
  180. package/es/ProCard/Content/style.js +10 -0
  181. package/es/ProCard/Descriptions/index.d.ts +4 -0
  182. package/es/ProCard/Descriptions/index.js +28 -0
  183. package/es/ProCard/Descriptions/style.d.ts +3 -0
  184. package/es/ProCard/Descriptions/style.js +12 -0
  185. package/es/ProCard/Header/index.d.ts +15 -0
  186. package/es/ProCard/Header/index.js +86 -0
  187. package/es/ProCard/Header/style.d.ts +12 -0
  188. package/es/ProCard/Header/style.js +21 -0
  189. package/es/ProCard/index.d.ts +13 -0
  190. package/es/ProCard/index.js +8 -0
  191. package/es/SelectCard/index.d.ts +33 -0
  192. package/es/SelectCard/index.js +132 -0
  193. package/es/SelectCard/style.d.ts +10 -0
  194. package/es/SelectCard/style.js +42 -0
  195. package/es/SliderInput/index.js +2 -2
  196. package/es/Status/index.d.ts +7 -0
  197. package/es/Status/index.js +39 -0
  198. package/es/Status/style.d.ts +4 -0
  199. package/es/Status/style.js +14 -0
  200. package/es/Table/collapse/index.d.ts +9 -0
  201. package/es/Table/collapse/index.js +39 -0
  202. package/es/Table/collapse/style.d.ts +3 -0
  203. package/es/Table/collapse/style.js +11 -0
  204. package/es/Table/index.d.ts +20 -0
  205. package/es/Table/index.js +56 -0
  206. package/es/Typography/index.d.ts +32 -0
  207. package/es/Typography/index.js +77 -0
  208. package/es/WaveformIcon/index.d.ts +9 -0
  209. package/es/WaveformIcon/index.js +51 -0
  210. package/es/hooks/languageMap.d.ts +1 -0
  211. package/es/hooks/languageMap.js +1 -0
  212. package/es/hooks/useHighlight.d.ts +5 -0
  213. package/es/hooks/useHighlight.js +78 -0
  214. package/es/index.d.ts +38 -3
  215. package/es/index.js +48 -3
  216. package/es/notification/index.d.ts +24 -0
  217. package/es/notification/index.js +237 -0
  218. package/es/notification/style.d.ts +2 -0
  219. package/es/notification/style.js +28 -0
  220. package/es/styles/colors/colors.d.ts +39 -0
  221. package/es/styles/colors/colors.js +86 -0
  222. package/es/styles/colors/generateColorPalette.d.ts +11 -0
  223. package/es/styles/colors/generateColorPalette.js +31 -0
  224. package/es/styles/colors/neutralColors.d.ts +9 -0
  225. package/es/styles/colors/neutralColors.js +32 -0
  226. package/es/styles/index.d.ts +4 -0
  227. package/es/styles/index.js +4 -0
  228. package/es/useSpeechSynthes/const/polyfill.d.ts +3 -0
  229. package/es/useSpeechSynthes/const/polyfill.js +21 -0
  230. package/es/useSpeechSynthes/index.d.ts +13 -0
  231. package/es/useSpeechSynthes/index.js +69 -0
  232. package/es/utils/constants.d.ts +1 -0
  233. package/es/utils/constants.js +1 -0
  234. package/es/utils/tools.d.ts +1 -0
  235. package/es/utils/tools.js +1 -0
  236. package/package.json +31 -9
  237. package/umd/index.min.css +2 -0
  238. package/umd/index.min.css.map +1 -0
  239. package/umd/index.min.js +1 -1
  240. package/umd/index.min.js.map +1 -1
  241. package/es/MonacoEditor/style.js +0 -24
@@ -0,0 +1,133 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ /* eslint-disable unicorn/no-useless-undefined */
3
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
+ import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
5
+ import { mergeRegister } from '@lexical/utils';
6
+ import { $getNodeByKey, $getSelection, $isDecoratorNode, $isNodeSelection, COMMAND_PRIORITY_LOW, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND } from 'lexical';
7
+ import { useCallback, useEffect, useRef, useState } from 'react';
8
+ import { LENGTH_LIMIT, TRIGGERS, VALID_CHARS, VALID_JOINS } from "./constants";
9
+ export var useSelectOrDelete = function useSelectOrDelete(nodeKey, command) {
10
+ var ref = useRef(null);
11
+ var _useLexicalComposerCo = useLexicalComposerContext(),
12
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
13
+ editor = _useLexicalComposerCo2[0];
14
+ var _useLexicalNodeSelect = useLexicalNodeSelection(nodeKey),
15
+ _useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 3),
16
+ isSelected = _useLexicalNodeSelect2[0],
17
+ setSelected = _useLexicalNodeSelect2[1],
18
+ clearSelection = _useLexicalNodeSelect2[2];
19
+ var handleDelete = useCallback(function (event) {
20
+ var selection = $getSelection();
21
+ var nodes = selection === null || selection === void 0 ? void 0 : selection.getNodes();
22
+ if (!isSelected && (nodes === null || nodes === void 0 ? void 0 : nodes.length) === 1) {
23
+ editor.dispatchCommand(command, undefined);
24
+ }
25
+ if (isSelected && $isNodeSelection(selection)) {
26
+ event.preventDefault();
27
+ var node = $getNodeByKey(nodeKey);
28
+ if ($isDecoratorNode(node)) {
29
+ if (command) {
30
+ editor.dispatchCommand(command, undefined);
31
+ }
32
+ node.remove();
33
+ return true;
34
+ }
35
+ }
36
+ return false;
37
+ }, [isSelected, nodeKey, command, editor]);
38
+ var handleSelect = useCallback(function (e) {
39
+ e.stopPropagation();
40
+ clearSelection();
41
+ setSelected(true);
42
+ }, [setSelected, clearSelection]);
43
+ useEffect(function () {
44
+ var ele = ref.current;
45
+ if (ele) ele.addEventListener('click', handleSelect);
46
+ return function () {
47
+ if (ele) ele.removeEventListener('click', handleSelect);
48
+ };
49
+ }, [handleSelect]);
50
+ useEffect(function () {
51
+ return mergeRegister(editor.registerCommand(KEY_DELETE_COMMAND, handleDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, handleDelete, COMMAND_PRIORITY_LOW));
52
+ }, [editor, clearSelection, handleDelete]);
53
+ return [ref, isSelected];
54
+ };
55
+ export var useTrigger = function useTrigger() {
56
+ var triggerRef = useRef(null);
57
+ var _useState = useState(false),
58
+ _useState2 = _slicedToArray(_useState, 2),
59
+ open = _useState2[0],
60
+ setOpen = _useState2[1];
61
+ var handleOpen = useCallback(function (e) {
62
+ e.stopPropagation();
63
+ setOpen(function (v) {
64
+ return !v;
65
+ });
66
+ }, []);
67
+ useEffect(function () {
68
+ var trigger = triggerRef.current;
69
+ if (trigger) trigger.addEventListener('click', handleOpen);
70
+ return function () {
71
+ if (trigger) trigger.removeEventListener('click', handleOpen);
72
+ };
73
+ }, [handleOpen]);
74
+ return [triggerRef, open, setOpen];
75
+ };
76
+
77
+ // Regex used to trigger the mention menu.
78
+ function createMentionsRegex(triggers, preTriggerChars, punctuation, allowSpaces) {
79
+ return new RegExp((preTriggerChars ? "(^|\\s|".concat(preTriggerChars, ")(") : '(^|\\s)(') + TRIGGERS(triggers) + '((?:' + VALID_CHARS(triggers, punctuation) + (allowSpaces ? VALID_JOINS(punctuation) : '') + '){0,' + LENGTH_LIMIT + '})' + ')$');
80
+ }
81
+ export function checkForMentions(text, triggers, preTriggerChars, punctuation, allowSpaces) {
82
+ var match = createMentionsRegex(triggers, preTriggerChars, punctuation, allowSpaces).exec(text);
83
+ if (match !== null) {
84
+ // The strategy ignores leading whitespace, but we need to know its
85
+ // length to add it to the leadOffset
86
+ var maybeLeadingWhitespace = match[1];
87
+ var matchingStringWithTrigger = match[2];
88
+ var matchingString = match[3];
89
+ if (matchingStringWithTrigger.length > 0) {
90
+ return {
91
+ leadOffset: match.index + maybeLeadingWhitespace.length,
92
+ matchingString: matchingString,
93
+ replaceableString: matchingStringWithTrigger
94
+ };
95
+ }
96
+ }
97
+ return null;
98
+ }
99
+ export var useCheckForMentionMatch = function useCheckForMentionMatch(triggers, _ref) {
100
+ var punctuation = _ref.punctuation,
101
+ preTriggerChars = _ref.preTriggerChars,
102
+ allowSpaces = _ref.allowSpaces;
103
+ var _useState3 = useState(null),
104
+ _useState4 = _slicedToArray(_useState3, 2),
105
+ trigger = _useState4[0],
106
+ setTrigger = _useState4[1];
107
+ var checkForMentionMatch = useCallback(function (text) {
108
+ // Don't show the menu if the next character is a word character
109
+ // const selectionInfo = $getSelectionInfo(triggers, punctuation);
110
+ // if (selectionInfo?.isTextNode && selectionInfo.wordCharAfterCursor) {
111
+ // return null;
112
+ // }
113
+
114
+ var queryMatch = checkForMentions(text, triggers, preTriggerChars, punctuation, allowSpaces);
115
+ if (queryMatch) {
116
+ var replaceableString = queryMatch.replaceableString,
117
+ matchingString = queryMatch.matchingString;
118
+ var index = replaceableString.lastIndexOf(matchingString);
119
+ var _trigger = index === -1 ? replaceableString : replaceableString.slice(0, Math.max(0, index)) + replaceableString.slice(Math.max(0, index + matchingString.length));
120
+ setTrigger(_trigger || null);
121
+ if (queryMatch.replaceableString) {
122
+ return queryMatch;
123
+ }
124
+ } else {
125
+ setTrigger(null);
126
+ }
127
+ return null;
128
+ }, [preTriggerChars, allowSpaces, punctuation, triggers]);
129
+ return {
130
+ trigger: trigger,
131
+ checkForMentionMatch: checkForMentionMatch
132
+ };
133
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { type MentionPickerPluginProps } from './plugins/mention-picker';
3
+ import type { AutoSize } from './types';
4
+ export interface MentionsProps extends MentionPickerPluginProps {
5
+ className?: string;
6
+ classNames?: {
7
+ wrapper?: string;
8
+ menuOverlay?: string;
9
+ };
10
+ wrapperClassname?: string;
11
+ placeholder?: string;
12
+ style?: React.CSSProperties;
13
+ value?: string;
14
+ defaultValue?: string;
15
+ readOnly?: boolean;
16
+ disabled?: boolean;
17
+ onChange?: (text: string) => void;
18
+ onBlur?: () => void;
19
+ onFocus?: () => void;
20
+ variant?: 'outlined' | 'filled' | 'borderless';
21
+ autoSize?: AutoSize;
22
+ }
23
+ export declare const Mentions: React.FC<MentionsProps>;
@@ -0,0 +1,157 @@
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 { ConfigProvider } from 'antd';
11
+ import { $getRoot, TextNode } from 'lexical';
12
+ import React, { useMemo } from 'react';
13
+ import { isBrowser } from "../utils/tools";
14
+ import { OnBlurBlockPlugin } from "./plugins/OnBlurBlockPlugin";
15
+ import { CustomTextNode } from "./plugins/custom-text/node";
16
+ import { EditablePlugin } from "./plugins/editable";
17
+ import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
18
+ import { MentionPickerPlugin } from "./plugins/mention-picker";
19
+ import { MentionsConfigProvider } from "./provider";
20
+ import { useStyles } from "./style";
21
+ import { textToEditorState } from "./utils";
22
+ import { jsx as _jsx } from "react/jsx-runtime";
23
+ import { jsxs as _jsxs } from "react/jsx-runtime";
24
+ export var Mentions = function Mentions(_ref) {
25
+ var className = _ref.className,
26
+ classNames = _ref.classNames,
27
+ placeholder = _ref.placeholder,
28
+ style = _ref.style,
29
+ value = _ref.value,
30
+ defaultValue = _ref.defaultValue,
31
+ _ref$readOnly = _ref.readOnly,
32
+ readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
33
+ customDisabled = _ref.disabled,
34
+ onChange = _ref.onChange,
35
+ onBlur = _ref.onBlur,
36
+ onFocus = _ref.onFocus,
37
+ _ref$variant = _ref.variant,
38
+ variant = _ref$variant === void 0 ? 'outlined' : _ref$variant,
39
+ _ref$options = _ref.options,
40
+ options = _ref$options === void 0 ? [] : _ref$options,
41
+ autoSize = _ref.autoSize,
42
+ _ref$triggers = _ref.triggers,
43
+ triggers = _ref$triggers === void 0 ? ['@'] : _ref$triggers,
44
+ allowSpaces = _ref.allowSpaces,
45
+ punctuation = _ref.punctuation,
46
+ preTriggerChars = _ref.preTriggerChars,
47
+ onSelect = _ref.onSelect;
48
+ var _ConfigProvider$useCo = ConfigProvider.useConfig(),
49
+ componentDisabled = _ConfigProvider$useCo.componentDisabled;
50
+ var _useStyles = useStyles({
51
+ autoSize: autoSize
52
+ }),
53
+ styles = _useStyles.styles,
54
+ cx = _useStyles.cx;
55
+ var disabled = useMemo(function () {
56
+ return customDisabled !== null && customDisabled !== void 0 ? customDisabled : componentDisabled;
57
+ }, [componentDisabled, customDisabled]);
58
+ var editable = useMemo(function () {
59
+ return !readOnly && !disabled;
60
+ }, [disabled, readOnly]);
61
+ var initialConfig = useMemo(function () {
62
+ return {
63
+ namespace: 'mentions',
64
+ nodes: [CustomTextNode, {
65
+ replace: TextNode,
66
+ with: function _with(node) {
67
+ return new CustomTextNode(node.__text);
68
+ }
69
+ }, MentionNode],
70
+ editorState: textToEditorState(value || defaultValue || ''),
71
+ onError: function onError(error) {
72
+ throw error;
73
+ }
74
+ };
75
+ },
76
+ // eslint-disable-next-line react-hooks/exhaustive-deps
77
+ []);
78
+ var handleEditorChange = function handleEditorChange(editorState) {
79
+ var text = editorState.read(function () {
80
+ return $getRoot().getTextContent();
81
+ });
82
+ onChange === null || onChange === void 0 || onChange(text.replaceAll('\n\n', '\n'));
83
+ };
84
+
85
+ // @Todo: set value when value change
86
+ // useEffect(() => {
87
+ // //
88
+ // }, [value])
89
+
90
+ var optionsMap = useMemo(function () {
91
+ var buildMap = function buildMap(_options, parentIcon) {
92
+ return _options.reduce(function (acc, option) {
93
+ acc[option.value] = option;
94
+ if (!acc[option.value].icon) {
95
+ acc[option.value].icon = parentIcon;
96
+ }
97
+ if (option.children && option.children.length > 0) {
98
+ var childrenMap = buildMap(option.children, option.icon);
99
+ Object.assign(acc, childrenMap);
100
+ }
101
+ return acc;
102
+ }, {});
103
+ };
104
+ return buildMap(options);
105
+ }, [options]);
106
+ if (!isBrowser) {
107
+ return /*#__PURE__*/_jsxs("div", {
108
+ className: cx(styles.wrapper, classNames === null || classNames === void 0 ? void 0 : classNames.wrapper),
109
+ children: [/*#__PURE__*/_jsx("div", {
110
+ className: cx(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.root, true), styles.filled, variant === 'filled'), styles.borderless, variant === 'borderless'), styles.disabled, disabled), className),
111
+ style: style || {}
112
+ }), /*#__PURE__*/_jsx("div", {
113
+ className: styles.placeholder,
114
+ children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
115
+ })]
116
+ });
117
+ }
118
+ return /*#__PURE__*/_jsx(LexicalComposer, {
119
+ initialConfig: _objectSpread(_objectSpread({}, initialConfig), {}, {
120
+ editable: editable
121
+ }),
122
+ children: /*#__PURE__*/_jsx(MentionsConfigProvider, {
123
+ value: {
124
+ optionsMap: optionsMap
125
+ },
126
+ children: /*#__PURE__*/_jsxs("div", {
127
+ className: cx(styles.wrapper, classNames === null || classNames === void 0 ? void 0 : classNames.wrapper),
128
+ children: [/*#__PURE__*/_jsx(RichTextPlugin, {
129
+ ErrorBoundary: LexicalErrorBoundary,
130
+ contentEditable: /*#__PURE__*/_jsx(ContentEditable, {
131
+ className: cx(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.root, true), styles.filled, variant === 'filled'), styles.borderless, variant === 'borderless'), styles.disabled, disabled), className),
132
+ style: style || {}
133
+ }),
134
+ placeholder: /*#__PURE__*/_jsx("div", {
135
+ className: styles.placeholder,
136
+ children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
137
+ })
138
+ }), editable && /*#__PURE__*/_jsx(MentionPickerPlugin, {
139
+ allowSpaces: allowSpaces,
140
+ onSelect: onSelect,
141
+ options: options,
142
+ overlayClassName: classNames === null || classNames === void 0 ? void 0 : classNames.menuOverlay,
143
+ preTriggerChars: preTriggerChars,
144
+ punctuation: punctuation,
145
+ triggers: triggers
146
+ }), /*#__PURE__*/_jsx(MentionNodePlugin, {}), /*#__PURE__*/_jsx(MentionNodePluginReplacement, {}), /*#__PURE__*/_jsx(HistoryPlugin, {}), /*#__PURE__*/_jsx(OnChangePlugin, {
147
+ onChange: handleEditorChange
148
+ }), /*#__PURE__*/_jsx(OnBlurBlockPlugin, {
149
+ onBlur: onBlur,
150
+ onFocus: onFocus
151
+ }), /*#__PURE__*/_jsx(EditablePlugin, {
152
+ editable: editable
153
+ })]
154
+ })
155
+ })
156
+ });
157
+ };
@@ -0,0 +1,7 @@
1
+ import type { FC } from 'react';
2
+ type OnBlurBlockPluginProps = {
3
+ onBlur?: () => void;
4
+ onFocus?: () => void;
5
+ };
6
+ export declare const OnBlurBlockPlugin: FC<OnBlurBlockPluginProps>;
7
+ export {};
@@ -0,0 +1,35 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { mergeRegister } from '@lexical/utils';
4
+ import { BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, FOCUS_COMMAND, KEY_ESCAPE_COMMAND } from 'lexical';
5
+ import { useEffect, useRef } from 'react';
6
+ import { CLEAR_HIDE_MENU_TIMEOUT } from "./mention-node";
7
+ export var OnBlurBlockPlugin = function OnBlurBlockPlugin(_ref) {
8
+ var onBlur = _ref.onBlur,
9
+ onFocus = _ref.onFocus;
10
+ var _useLexicalComposerCo = useLexicalComposerContext(),
11
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
12
+ editor = _useLexicalComposerCo2[0];
13
+ var ref = useRef(null);
14
+ useEffect(function () {
15
+ return mergeRegister(editor.registerCommand(CLEAR_HIDE_MENU_TIMEOUT, function () {
16
+ if (ref.current) {
17
+ clearTimeout(ref.current);
18
+ ref.current = null;
19
+ }
20
+ return true;
21
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(BLUR_COMMAND, function (_payload, _editor) {
22
+ ref.current = setTimeout(function () {
23
+ editor.dispatchCommand(KEY_ESCAPE_COMMAND, new KeyboardEvent('keydown', {
24
+ key: 'Escape'
25
+ }));
26
+ }, 200);
27
+ if (onBlur) onBlur();
28
+ return true;
29
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(FOCUS_COMMAND, function () {
30
+ if (onFocus) onFocus();
31
+ return true;
32
+ }, COMMAND_PRIORITY_EDITOR));
33
+ }, [editor, onBlur, onFocus]);
34
+ return null;
35
+ };
@@ -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,4 @@
1
+ import React from 'react';
2
+ export declare const EditablePlugin: React.FC<{
3
+ editable: boolean;
4
+ }>;
@@ -0,0 +1,13 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { useEffect } from 'react';
4
+ export var EditablePlugin = function EditablePlugin(_ref) {
5
+ var editable = _ref.editable;
6
+ var _useLexicalComposerCo = useLexicalComposerContext(),
7
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
8
+ editor = _useLexicalComposerCo2[0];
9
+ useEffect(function () {
10
+ editor.setEditable(editable);
11
+ }, [editable, editor]);
12
+ return null;
13
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export interface MentionNodeComponentProps {
3
+ nodeKey: string;
4
+ variable: string;
5
+ }
6
+ export declare const MentionNodeComponent: React.FC<MentionNodeComponentProps>;
@@ -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.selectedLabel) || (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,22 @@
1
+ /// <reference types="react" />
2
+ import type { LexicalNode, NodeKey, SerializedLexicalNode } from 'lexical';
3
+ import { DecoratorNode } from 'lexical';
4
+ export type SerializedNode = SerializedLexicalNode & {
5
+ variable: string;
6
+ };
7
+ export declare class MentionNode extends DecoratorNode<JSX.Element> {
8
+ __variable: string;
9
+ static getType(): string;
10
+ static clone(node: MentionNode): MentionNode;
11
+ isInline(): boolean;
12
+ constructor(variable: string, key?: NodeKey);
13
+ createDOM(): HTMLElement;
14
+ updateDOM(): false;
15
+ decorate(): JSX.Element;
16
+ static importJSON(serializedNode: SerializedNode): MentionNode;
17
+ exportJSON(): SerializedNode;
18
+ getVariable(): string;
19
+ getTextContent(): string;
20
+ }
21
+ export declare function $createMentionNode(variable: string): MentionNode;
22
+ export declare function $isMentionNode(node: MentionNode | LexicalNode | null | undefined): node is MentionNode;