@yuntijs/ui 1.0.0-beta.31 → 1.0.0-beta.33
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/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 +1 -0
- package/es/Divider/index.js +6 -4
- package/es/DragPanel/index.d.ts +10 -0
- package/es/DragPanel/index.js +96 -0
- package/es/DragPanel/style.d.ts +7 -0
- package/es/DragPanel/style.js +15 -0
- package/es/Form/collapse-list/index.d.ts +38 -0
- package/es/Form/collapse-list/index.js +205 -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/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 +120 -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 +8 -0
- package/es/Mentions/plugins/mention-node/component.js +72 -0
- package/es/Mentions/plugins/mention-node/index.d.ts +11 -0
- package/es/Mentions/plugins/mention-node/index.js +39 -0
- package/es/Mentions/plugins/mention-node/node.d.ts +26 -0
- package/es/Mentions/plugins/mention-node/node.js +110 -0
- package/es/Mentions/plugins/mention-node/replacement.d.ts +7 -0
- package/es/Mentions/plugins/mention-node/replacement.js +43 -0
- package/es/Mentions/plugins/mention-node/style.d.ts +8 -0
- package/es/Mentions/plugins/mention-node/style.js +49 -0
- package/es/Mentions/plugins/mention-node/utils.d.ts +5 -0
- package/es/Mentions/plugins/mention-node/utils.js +6 -0
- package/es/Mentions/plugins/mention-picker/hooks.d.ts +5 -0
- package/es/Mentions/plugins/mention-picker/hooks.js +38 -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 +70 -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/style.d.ts +11 -0
- package/es/Mentions/style.js +20 -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/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 +3 -0
- package/es/Table/index.js +7 -5
- package/es/index.d.ts +6 -2
- package/es/index.js +6 -2
- package/package.json +10 -4
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -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,19 @@
|
|
|
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
|
+
wrapperClassname?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
value?: string;
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
onChange?: (text: string) => void;
|
|
14
|
+
onBlur?: () => void;
|
|
15
|
+
onFocus?: () => void;
|
|
16
|
+
variant?: 'outlined' | 'filled' | 'borderless';
|
|
17
|
+
autoSize?: AutoSize;
|
|
18
|
+
}
|
|
19
|
+
export declare const Mentions: React.FC<MentionsProps>;
|
|
@@ -0,0 +1,120 @@
|
|
|
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 { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
8
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
9
|
+
import { $getRoot, TextNode } from 'lexical';
|
|
10
|
+
import React, { useMemo } from 'react';
|
|
11
|
+
import { CustomTextNode } from "./plugins/custom-text/node";
|
|
12
|
+
import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
|
|
13
|
+
import { MentionPickerPlugin } from "./plugins/mention-picker";
|
|
14
|
+
import OnBlurBlock from "./plugins/on-blur-or-focus-block";
|
|
15
|
+
import { useStyles } from "./style";
|
|
16
|
+
import { textToEditorState } from "./utils";
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export var Mentions = function Mentions(_ref) {
|
|
20
|
+
var _cx;
|
|
21
|
+
var className = _ref.className,
|
|
22
|
+
wrapperClassname = _ref.wrapperClassname,
|
|
23
|
+
placeholder = _ref.placeholder,
|
|
24
|
+
style = _ref.style,
|
|
25
|
+
value = _ref.value,
|
|
26
|
+
defaultValue = _ref.defaultValue,
|
|
27
|
+
_ref$readOnly = _ref.readOnly,
|
|
28
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
29
|
+
_ref$disabled = _ref.disabled,
|
|
30
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
31
|
+
onChange = _ref.onChange,
|
|
32
|
+
onBlur = _ref.onBlur,
|
|
33
|
+
onFocus = _ref.onFocus,
|
|
34
|
+
_ref$variant = _ref.variant,
|
|
35
|
+
variant = _ref$variant === void 0 ? 'outlined' : _ref$variant,
|
|
36
|
+
_ref$options = _ref.options,
|
|
37
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
38
|
+
autoSize = _ref.autoSize,
|
|
39
|
+
_ref$triggers = _ref.triggers,
|
|
40
|
+
triggers = _ref$triggers === void 0 ? ['@'] : _ref$triggers,
|
|
41
|
+
allowSpaces = _ref.allowSpaces,
|
|
42
|
+
punctuation = _ref.punctuation,
|
|
43
|
+
preTriggerChars = _ref.preTriggerChars,
|
|
44
|
+
onSelect = _ref.onSelect;
|
|
45
|
+
var _useStyles = useStyles({
|
|
46
|
+
autoSize: autoSize
|
|
47
|
+
}),
|
|
48
|
+
styles = _useStyles.styles,
|
|
49
|
+
cx = _useStyles.cx;
|
|
50
|
+
var editable = !readOnly && !disabled;
|
|
51
|
+
var initialConfig = useMemo(function () {
|
|
52
|
+
return {
|
|
53
|
+
namespace: 'mentions',
|
|
54
|
+
nodes: [CustomTextNode, {
|
|
55
|
+
replace: TextNode,
|
|
56
|
+
with: function _with(node) {
|
|
57
|
+
return new CustomTextNode(node.__text);
|
|
58
|
+
}
|
|
59
|
+
}, MentionNode],
|
|
60
|
+
editorState: textToEditorState(value || defaultValue || ''),
|
|
61
|
+
onError: function onError(error) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
var handleEditorChange = function handleEditorChange(editorState) {
|
|
68
|
+
var text = editorState.read(function () {
|
|
69
|
+
return $getRoot().getTextContent();
|
|
70
|
+
});
|
|
71
|
+
onChange === null || onChange === void 0 || onChange(text.replaceAll('\n\n', '\n'));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// @Todo: set value when value change
|
|
75
|
+
// useEffect(() => {
|
|
76
|
+
// //
|
|
77
|
+
// }, [value])
|
|
78
|
+
|
|
79
|
+
var optionsMap = useMemo(function () {
|
|
80
|
+
return options.reduce(function (acc, option) {
|
|
81
|
+
acc[option.value] = option;
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
}, [options]);
|
|
85
|
+
return /*#__PURE__*/_jsx(LexicalComposer, {
|
|
86
|
+
initialConfig: _objectSpread(_objectSpread({}, initialConfig), {}, {
|
|
87
|
+
editable: editable
|
|
88
|
+
}),
|
|
89
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
90
|
+
className: cx(styles.wrapper, wrapperClassname),
|
|
91
|
+
children: [/*#__PURE__*/_jsx(RichTextPlugin, {
|
|
92
|
+
ErrorBoundary: LexicalErrorBoundary,
|
|
93
|
+
contentEditable: /*#__PURE__*/_jsx(ContentEditable, {
|
|
94
|
+
className: cx((_cx = {}, _defineProperty(_cx, styles.root, true), _defineProperty(_cx, styles.filled, variant === 'filled'), _defineProperty(_cx, styles.borderless, variant === 'borderless'), _defineProperty(_cx, styles.disabled, disabled), _cx), className),
|
|
95
|
+
style: style || {}
|
|
96
|
+
}),
|
|
97
|
+
placeholder: /*#__PURE__*/_jsx("div", {
|
|
98
|
+
className: styles.placeholder,
|
|
99
|
+
children: placeholder || "\u8F93\u5165 ".concat(triggers.join(' 或 '), " \u63D2\u5165\u5F15\u7528")
|
|
100
|
+
})
|
|
101
|
+
}), /*#__PURE__*/_jsx(MentionPickerPlugin, {
|
|
102
|
+
allowSpaces: allowSpaces,
|
|
103
|
+
onSelect: onSelect,
|
|
104
|
+
options: options,
|
|
105
|
+
preTriggerChars: preTriggerChars,
|
|
106
|
+
punctuation: punctuation,
|
|
107
|
+
triggers: triggers
|
|
108
|
+
}), /*#__PURE__*/_jsx(MentionNodePlugin, {
|
|
109
|
+
optionsMap: optionsMap
|
|
110
|
+
}), /*#__PURE__*/_jsx(MentionNodePluginReplacement, {
|
|
111
|
+
optionsMap: optionsMap
|
|
112
|
+
}), /*#__PURE__*/_jsx(OnChangePlugin, {
|
|
113
|
+
onChange: handleEditorChange
|
|
114
|
+
}), /*#__PURE__*/_jsx(OnBlurBlock, {
|
|
115
|
+
onBlur: onBlur,
|
|
116
|
+
onFocus: onFocus
|
|
117
|
+
})]
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
};
|
|
@@ -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,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MentionsOptionsMap } from '../../types';
|
|
3
|
+
export interface MentionNodeComponentProps {
|
|
4
|
+
nodeKey: string;
|
|
5
|
+
variable: string;
|
|
6
|
+
optionsMap: MentionsOptionsMap;
|
|
7
|
+
}
|
|
8
|
+
export declare const MentionNodeComponent: React.FC<MentionNodeComponentProps>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { mergeRegister } from '@lexical/utils';
|
|
4
|
+
import { Icon } from '@lobehub/ui';
|
|
5
|
+
import { Flex, Tooltip } from 'antd';
|
|
6
|
+
import { COMMAND_PRIORITY_EDITOR } from 'lexical';
|
|
7
|
+
import { CircleAlert } from 'lucide-react';
|
|
8
|
+
import React, { memo, useEffect, useState } from 'react';
|
|
9
|
+
import { useSelectOrDelete } from "../../hooks";
|
|
10
|
+
import { MentionNode } from "./node";
|
|
11
|
+
import { useStyles } from "./style";
|
|
12
|
+
import { DELETE_MENTION_COMMAND, UPDATE_MENTIONS_OPTIONS } from "./utils";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
export var MentionNodeComponent = /*#__PURE__*/memo(function (_ref) {
|
|
16
|
+
var nodeKey = _ref.nodeKey,
|
|
17
|
+
variable = _ref.variable,
|
|
18
|
+
_ref$optionsMap = _ref.optionsMap,
|
|
19
|
+
optionsMap = _ref$optionsMap === void 0 ? {} : _ref$optionsMap;
|
|
20
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
21
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
22
|
+
editor = _useLexicalComposerCo2[0];
|
|
23
|
+
var _useSelectOrDelete = useSelectOrDelete(nodeKey, DELETE_MENTION_COMMAND),
|
|
24
|
+
_useSelectOrDelete2 = _slicedToArray(_useSelectOrDelete, 2),
|
|
25
|
+
ref = _useSelectOrDelete2[0],
|
|
26
|
+
isSelected = _useSelectOrDelete2[1];
|
|
27
|
+
var _useState = useState(optionsMap),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
localMentionsOptionsMap = _useState2[0],
|
|
30
|
+
setLocalMentionsOptionsMap = _useState2[1];
|
|
31
|
+
var option = localMentionsOptionsMap === null || localMentionsOptionsMap === void 0 ? void 0 : localMentionsOptionsMap[variable];
|
|
32
|
+
var _useStyles = useStyles({
|
|
33
|
+
isSelected: isSelected,
|
|
34
|
+
isError: !option || !!option.error
|
|
35
|
+
}),
|
|
36
|
+
styles = _useStyles.styles;
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
if (!editor.hasNodes([MentionNode])) throw new Error('MentionsNodePlugin: MentionNode not registered on editor');
|
|
39
|
+
return mergeRegister(editor.registerCommand(UPDATE_MENTIONS_OPTIONS, function (newOptionsMap) {
|
|
40
|
+
setLocalMentionsOptionsMap(newOptionsMap);
|
|
41
|
+
return true;
|
|
42
|
+
}, COMMAND_PRIORITY_EDITOR));
|
|
43
|
+
}, [editor]);
|
|
44
|
+
var Item = /*#__PURE__*/_jsx(Flex, {
|
|
45
|
+
className: styles.root,
|
|
46
|
+
ref: ref,
|
|
47
|
+
children: /*#__PURE__*/_jsxs(Flex, {
|
|
48
|
+
align: "center",
|
|
49
|
+
gap: 2,
|
|
50
|
+
children: [(!option || option.error) && /*#__PURE__*/_jsx(Icon, {
|
|
51
|
+
className: styles.error,
|
|
52
|
+
icon: CircleAlert
|
|
53
|
+
}), (option === null || option === void 0 ? void 0 : option.icon) && /*#__PURE__*/_jsx(Flex, {
|
|
54
|
+
children: option.icon
|
|
55
|
+
}), /*#__PURE__*/_jsx(Flex, {
|
|
56
|
+
className: styles.text,
|
|
57
|
+
gap: 2,
|
|
58
|
+
title: (option === null || option === void 0 ? void 0 : option.label) || variable,
|
|
59
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
60
|
+
children: (option === null || option === void 0 ? void 0 : option.label) || variable
|
|
61
|
+
})
|
|
62
|
+
})]
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
if (option !== null && option !== void 0 && option.error) {
|
|
66
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
67
|
+
title: option === null || option === void 0 ? void 0 : option.error,
|
|
68
|
+
children: Item
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return Item;
|
|
72
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MentionsOptionsMap } from '../../types';
|
|
3
|
+
export * from './node';
|
|
4
|
+
export * from './replacement';
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export interface MentionNodePluginProps {
|
|
7
|
+
onInsert?: () => void;
|
|
8
|
+
onDelete?: () => void;
|
|
9
|
+
optionsMap: MentionsOptionsMap;
|
|
10
|
+
}
|
|
11
|
+
export declare const MentionNodePlugin: React.FC<MentionNodePluginProps>;
|
|
@@ -0,0 +1,39 @@
|
|
|
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, UPDATE_MENTIONS_OPTIONS } from "./utils";
|
|
8
|
+
export * from "./node";
|
|
9
|
+
export * from "./replacement";
|
|
10
|
+
export * from "./utils";
|
|
11
|
+
export var MentionNodePlugin = /*#__PURE__*/memo(function (_ref) {
|
|
12
|
+
var optionsMap = _ref.optionsMap,
|
|
13
|
+
onInsert = _ref.onInsert,
|
|
14
|
+
onDelete = _ref.onDelete;
|
|
15
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
16
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
17
|
+
editor = _useLexicalComposerCo2[0];
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
editor.update(function () {
|
|
20
|
+
editor.dispatchCommand(UPDATE_MENTIONS_OPTIONS, optionsMap);
|
|
21
|
+
});
|
|
22
|
+
}, [editor, optionsMap]);
|
|
23
|
+
useEffect(function () {
|
|
24
|
+
if (!editor.hasNodes([MentionNode])) throw new Error('MentionsNodePlugin: MentionNode not registered on editor');
|
|
25
|
+
return mergeRegister(editor.registerCommand(INSERT_MENTION_COMMAND, function (variable) {
|
|
26
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
27
|
+
editor.dispatchCommand(CLEAR_HIDE_MENU_TIMEOUT, undefined);
|
|
28
|
+
var mentionNode = $createMentionNode(variable, optionsMap);
|
|
29
|
+
$insertNodes([mentionNode]);
|
|
30
|
+
if (onInsert) onInsert();
|
|
31
|
+
return true;
|
|
32
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_MENTION_COMMAND, function () {
|
|
33
|
+
if (onDelete) onDelete();
|
|
34
|
+
return true;
|
|
35
|
+
}, COMMAND_PRIORITY_EDITOR));
|
|
36
|
+
}, [editor, onInsert, onDelete, optionsMap]);
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
MentionNodePlugin.displayName = 'MentionNodePlugin';
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
optionsMap: MentionsOptionsMap;
|
|
8
|
+
};
|
|
9
|
+
export declare class MentionNode extends DecoratorNode<JSX.Element> {
|
|
10
|
+
__variable: string;
|
|
11
|
+
__optionsMap: MentionsOptionsMap;
|
|
12
|
+
static getType(): string;
|
|
13
|
+
static clone(node: MentionNode): MentionNode;
|
|
14
|
+
isInline(): boolean;
|
|
15
|
+
constructor(variable: string, optionsMap: MentionsOptionsMap, key?: NodeKey);
|
|
16
|
+
createDOM(): HTMLElement;
|
|
17
|
+
updateDOM(): false;
|
|
18
|
+
decorate(): JSX.Element;
|
|
19
|
+
static importJSON(serializedNode: SerializedNode): MentionNode;
|
|
20
|
+
exportJSON(): SerializedNode;
|
|
21
|
+
getVariable(): string;
|
|
22
|
+
getOptionsMap(): MentionsOptionsMap;
|
|
23
|
+
getTextContent(): string;
|
|
24
|
+
}
|
|
25
|
+
export declare function $createMentionNode(variable: string, workflowNodesMap: MentionsOptionsMap): MentionNode;
|
|
26
|
+
export declare function $isMentionNode(node: MentionNode | LexicalNode | null | undefined): node is MentionNode;
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
_defineProperty(_assertThisInitialized(_this), "__optionsMap", void 0);
|
|
23
|
+
_this.__variable = variable;
|
|
24
|
+
_this.__optionsMap = optionsMap;
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
_createClass(MentionNode, [{
|
|
28
|
+
key: "isInline",
|
|
29
|
+
value: function isInline() {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "createDOM",
|
|
34
|
+
value: function createDOM() {
|
|
35
|
+
var div = document.createElement('div');
|
|
36
|
+
div.style.display = 'inline-flex';
|
|
37
|
+
div.style.alignItems = 'center';
|
|
38
|
+
div.style.verticalAlign = 'middle';
|
|
39
|
+
// div.style['align-items'] = 'center';
|
|
40
|
+
// div.style['vertical-align'] = 'middle';
|
|
41
|
+
|
|
42
|
+
return div;
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "updateDOM",
|
|
46
|
+
value: function updateDOM() {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "decorate",
|
|
51
|
+
value: function decorate() {
|
|
52
|
+
return /*#__PURE__*/_jsx(MentionNodeComponent, {
|
|
53
|
+
nodeKey: this.getKey(),
|
|
54
|
+
optionsMap: this.__optionsMap,
|
|
55
|
+
variable: this.__variable
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "exportJSON",
|
|
60
|
+
value: function exportJSON() {
|
|
61
|
+
return {
|
|
62
|
+
type: 'mention-node',
|
|
63
|
+
version: 1,
|
|
64
|
+
variable: this.getVariable(),
|
|
65
|
+
optionsMap: this.getOptionsMap()
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "getVariable",
|
|
70
|
+
value: function getVariable() {
|
|
71
|
+
var self = this.getLatest();
|
|
72
|
+
return self.__variable;
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "getOptionsMap",
|
|
76
|
+
value: function getOptionsMap() {
|
|
77
|
+
var self = this.getLatest();
|
|
78
|
+
return self.__optionsMap;
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "getTextContent",
|
|
82
|
+
value: function getTextContent() {
|
|
83
|
+
return "{{".concat(this.getVariable(), "}}");
|
|
84
|
+
}
|
|
85
|
+
}], [{
|
|
86
|
+
key: "getType",
|
|
87
|
+
value: function getType() {
|
|
88
|
+
return 'mention-node';
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "clone",
|
|
92
|
+
value: function clone(node) {
|
|
93
|
+
return new MentionNode(node.__variable, node.__optionsMap);
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "importJSON",
|
|
97
|
+
value: function importJSON(serializedNode) {
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
99
|
+
var node = $createMentionNode(serializedNode.variable, serializedNode.optionsMap);
|
|
100
|
+
return node;
|
|
101
|
+
}
|
|
102
|
+
}]);
|
|
103
|
+
return MentionNode;
|
|
104
|
+
}(DecoratorNode);
|
|
105
|
+
export function $createMentionNode(variable, workflowNodesMap) {
|
|
106
|
+
return new MentionNode(variable, workflowNodesMap);
|
|
107
|
+
}
|
|
108
|
+
export function $isMentionNode(node) {
|
|
109
|
+
return node instanceof MentionNode;
|
|
110
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MentionsOptionsMap } from '../../types';
|
|
3
|
+
export interface MentionNodePluginReplacementProps {
|
|
4
|
+
optionsMap: MentionsOptionsMap;
|
|
5
|
+
onInsert?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const MentionNodePluginReplacement: React.FC<MentionNodePluginReplacementProps>;
|