@yuntijs/ui 1.1.0-beta.6 → 1.1.0-beta.8
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/Mentions/index.d.ts +11 -3
- package/es/Mentions/index.js +15 -7
- package/es/Mentions/plugins/editor-ref.d.ts +5 -0
- package/es/Mentions/plugins/editor-ref.js +13 -0
- package/es/Mentions/plugins/mention-converter.d.ts +32 -0
- package/es/Mentions/plugins/mention-converter.js +151 -0
- package/es/Mentions/plugins/mention-picker/index.js +5 -1
- package/es/Mentions/plugins/shift-enter-key.d.ts +6 -0
- package/es/Mentions/plugins/shift-enter-key.js +48 -0
- package/es/Mentions/types.d.ts +1 -0
- package/es/Mentions/utils.d.ts +1 -1
- package/es/Mentions/utils.js +11 -30
- package/es/MonacoEditor/base/helper.js +1 -1
- package/package.json +1 -2
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
- /package/es/Mentions/plugins/{OnBlurBlockPlugin.d.ts → on-blur-block.d.ts} +0 -0
- /package/es/Mentions/plugins/{OnBlurBlockPlugin.js → on-blur-block.js} +0 -0
package/es/Mentions/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type MentionPickerPluginProps } from './plugins/mention-picker';
|
|
3
|
-
import
|
|
3
|
+
import { AutoSize, MentionsEditor } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './utils';
|
|
4
6
|
export interface MentionsProps extends MentionPickerPluginProps {
|
|
5
7
|
className?: string;
|
|
6
8
|
classNames?: {
|
|
@@ -8,7 +10,7 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
8
10
|
menuOverlay?: string;
|
|
9
11
|
};
|
|
10
12
|
wrapperClassname?: string;
|
|
11
|
-
placeholder?:
|
|
13
|
+
placeholder?: React.ReactNode;
|
|
12
14
|
style?: React.CSSProperties;
|
|
13
15
|
value?: string;
|
|
14
16
|
defaultValue?: string;
|
|
@@ -17,9 +19,15 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
17
19
|
onChange?: (text: string) => void;
|
|
18
20
|
onBlur?: () => void;
|
|
19
21
|
onFocus?: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* 按下回车的回调,指定后会改变回车的默认行为,换行需要使用 shift + enter
|
|
24
|
+
*/
|
|
25
|
+
onPressEnter?: (value: string, { event }: {
|
|
26
|
+
event: KeyboardEvent | null;
|
|
27
|
+
}) => void;
|
|
20
28
|
variant?: 'outlined' | 'filled' | 'borderless';
|
|
21
29
|
autoSize?: AutoSize;
|
|
22
30
|
code?: boolean;
|
|
23
31
|
getPopContainer?: () => HTMLElement;
|
|
24
32
|
}
|
|
25
|
-
export declare const Mentions: React.
|
|
33
|
+
export declare const Mentions: React.ForwardRefExoticComponent<MentionsProps & React.RefAttributes<MentionsEditor>>;
|
package/es/Mentions/index.js
CHANGED
|
@@ -9,21 +9,24 @@ import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
|
9
9
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
10
10
|
import { ConfigProvider } from 'antd';
|
|
11
11
|
// @Todo: 升级 0.25.0 后,ops-console 使用的时候出现了只输入 / 无法触发的问题
|
|
12
|
-
|
|
13
12
|
import { $getRoot, TextNode } from 'lexical';
|
|
14
|
-
import React, { useMemo } from 'react';
|
|
13
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
15
14
|
import { isBrowser } from "../utils/tools";
|
|
16
|
-
import { OnBlurBlockPlugin } from "./plugins/OnBlurBlockPlugin";
|
|
17
15
|
import { CustomTextNode } from "./plugins/custom-text/node";
|
|
18
16
|
import { EditablePlugin } from "./plugins/editable";
|
|
17
|
+
import { EditorRefPlugin } from "./plugins/editor-ref";
|
|
19
18
|
import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
|
|
20
19
|
import { MentionPickerPlugin } from "./plugins/mention-picker";
|
|
20
|
+
import { OnBlurBlockPlugin } from "./plugins/on-blur-block";
|
|
21
|
+
import { ShiftEnterKeyPlugin } from "./plugins/shift-enter-key";
|
|
21
22
|
import { MentionsConfigProvider } from "./provider";
|
|
22
23
|
import { useStyles } from "./style";
|
|
23
24
|
import { textToEditorState } from "./utils";
|
|
24
25
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
26
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
-
export
|
|
27
|
+
export * from "./types";
|
|
28
|
+
export * from "./utils";
|
|
29
|
+
export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
27
30
|
var className = _ref.className,
|
|
28
31
|
classNames = _ref.classNames,
|
|
29
32
|
placeholder = _ref.placeholder,
|
|
@@ -49,7 +52,8 @@ export var Mentions = function Mentions(_ref) {
|
|
|
49
52
|
onSelect = _ref.onSelect,
|
|
50
53
|
_ref$code = _ref.code,
|
|
51
54
|
code = _ref$code === void 0 ? false : _ref$code,
|
|
52
|
-
getPopContainer = _ref.getPopContainer
|
|
55
|
+
getPopContainer = _ref.getPopContainer,
|
|
56
|
+
onPressEnter = _ref.onPressEnter;
|
|
53
57
|
var _ConfigProvider$useCo = ConfigProvider.useConfig(),
|
|
54
58
|
componentDisabled = _ConfigProvider$useCo.componentDisabled;
|
|
55
59
|
var _useStyles = useStyles({
|
|
@@ -73,7 +77,7 @@ export var Mentions = function Mentions(_ref) {
|
|
|
73
77
|
return new CustomTextNode(node.__text);
|
|
74
78
|
}
|
|
75
79
|
}, MentionNode],
|
|
76
|
-
editorState: textToEditorState(value || defaultValue || ''),
|
|
80
|
+
editorState: textToEditorState(value || defaultValue || '', triggers),
|
|
77
81
|
onError: function onError(error) {
|
|
78
82
|
throw error;
|
|
79
83
|
}
|
|
@@ -156,8 +160,12 @@ export var Mentions = function Mentions(_ref) {
|
|
|
156
160
|
onFocus: onFocus
|
|
157
161
|
}), /*#__PURE__*/_jsx(EditablePlugin, {
|
|
158
162
|
editable: editable
|
|
163
|
+
}), /*#__PURE__*/_jsx(EditorRefPlugin, {
|
|
164
|
+
editorRef: ref
|
|
165
|
+
}), onPressEnter && /*#__PURE__*/_jsx(ShiftEnterKeyPlugin, {
|
|
166
|
+
onPressEnter: onPressEnter
|
|
159
167
|
})]
|
|
160
168
|
})
|
|
161
169
|
})
|
|
162
170
|
});
|
|
163
|
-
};
|
|
171
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { useImperativeHandle } from 'react';
|
|
4
|
+
export var EditorRefPlugin = function EditorRefPlugin(_ref) {
|
|
5
|
+
var editorRef = _ref.editorRef;
|
|
6
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
7
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
8
|
+
editor = _useLexicalComposerCo2[0];
|
|
9
|
+
useImperativeHandle(editorRef, function () {
|
|
10
|
+
return editor;
|
|
11
|
+
});
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* source:
|
|
3
|
+
* https://github.com/sodenn/lexical-beautiful-mentions/blob/8d2c8fbfaa63fe0100ac9f6c4bcb61e816d14a30/plugin/src/mention-converter.ts
|
|
4
|
+
*/
|
|
5
|
+
import { LexicalNode, TextNode } from 'lexical';
|
|
6
|
+
interface MentionEntry {
|
|
7
|
+
type: 'mention-node';
|
|
8
|
+
trigger: string;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
interface TextEntry {
|
|
12
|
+
type: 'custom-text';
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
type Entry = MentionEntry | TextEntry;
|
|
16
|
+
export declare function convertToMentionEntries(text: string, triggers: string[], punctuation: string): Entry[];
|
|
17
|
+
/**
|
|
18
|
+
* Utility function that takes a string or a text nodes and converts it to a
|
|
19
|
+
* list of mention and text nodes.
|
|
20
|
+
*
|
|
21
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
22
|
+
* via the `allowSpaces` prop.
|
|
23
|
+
*/
|
|
24
|
+
export declare function $convertToMentionNodes(textOrNode: string | TextNode, triggers: string[], punctuation?: string): LexicalNode[];
|
|
25
|
+
/**
|
|
26
|
+
* Transforms text nodes containing mention strings into mention nodes.
|
|
27
|
+
*
|
|
28
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
29
|
+
* via the `allowSpaces` prop.
|
|
30
|
+
*/
|
|
31
|
+
export declare function $transformTextToMentionNodes(triggers: string[], punctuation?: string): void;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
/**
|
|
5
|
+
* source:
|
|
6
|
+
* https://github.com/sodenn/lexical-beautiful-mentions/blob/8d2c8fbfaa63fe0100ac9f6c4bcb61e816d14a30/plugin/src/mention-converter.ts
|
|
7
|
+
*/
|
|
8
|
+
import { $createTextNode, $getRoot, $isElementNode, $isTextNode } from 'lexical';
|
|
9
|
+
import { DEFAULT_PUNCTUATION, LENGTH_LIMIT, TRIGGERS, VALID_CHARS } from "../constants";
|
|
10
|
+
import { $createMentionNode } from "./mention-node";
|
|
11
|
+
function findMentions(text, triggers, punctuation) {
|
|
12
|
+
var regex = new RegExp('(?<=\\s|^|\\()' + TRIGGERS(triggers) + '((?:' + VALID_CHARS(triggers, punctuation) + '){1,' + LENGTH_LIMIT + '})', 'g');
|
|
13
|
+
var matches = [];
|
|
14
|
+
var match;
|
|
15
|
+
regex.lastIndex = 0;
|
|
16
|
+
while ((match = regex.exec(text)) !== null) {
|
|
17
|
+
matches.push({
|
|
18
|
+
value: match[0],
|
|
19
|
+
index: match.index
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return matches;
|
|
23
|
+
}
|
|
24
|
+
export function convertToMentionEntries(text, triggers, punctuation) {
|
|
25
|
+
var matches = findMentions(text, triggers, punctuation);
|
|
26
|
+
var result = [];
|
|
27
|
+
var lastIndex = 0;
|
|
28
|
+
var _iterator = _createForOfIteratorHelper(matches),
|
|
29
|
+
_step;
|
|
30
|
+
try {
|
|
31
|
+
var _loop = function _loop() {
|
|
32
|
+
var _step$value = _step.value,
|
|
33
|
+
value = _step$value.value,
|
|
34
|
+
index = _step$value.index;
|
|
35
|
+
// Add text before mention
|
|
36
|
+
if (index > lastIndex) {
|
|
37
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
38
|
+
var textBeforeMention = text.substring(lastIndex, index);
|
|
39
|
+
result.push({
|
|
40
|
+
type: 'custom-text',
|
|
41
|
+
value: textBeforeMention
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// Add mention
|
|
45
|
+
var triggerRegExp = triggers.find(function (trigger) {
|
|
46
|
+
return new RegExp(trigger).test(value);
|
|
47
|
+
});
|
|
48
|
+
var match = triggerRegExp && new RegExp(triggerRegExp).exec(value);
|
|
49
|
+
if (!match) {
|
|
50
|
+
// should never happen since we only find mentions with the given triggers
|
|
51
|
+
throw new Error('No trigger found for mention');
|
|
52
|
+
}
|
|
53
|
+
var trigger = match[0];
|
|
54
|
+
result.push({
|
|
55
|
+
type: 'mention-node',
|
|
56
|
+
value: value.slice(trigger.length),
|
|
57
|
+
trigger: trigger
|
|
58
|
+
});
|
|
59
|
+
// Update lastIndex
|
|
60
|
+
lastIndex = index + value.length;
|
|
61
|
+
};
|
|
62
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
63
|
+
_loop();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Add text after last mention
|
|
67
|
+
} catch (err) {
|
|
68
|
+
_iterator.e(err);
|
|
69
|
+
} finally {
|
|
70
|
+
_iterator.f();
|
|
71
|
+
}
|
|
72
|
+
if (lastIndex < text.length) {
|
|
73
|
+
var textAfterMentions = text.slice(Math.max(0, lastIndex));
|
|
74
|
+
result.push({
|
|
75
|
+
type: 'custom-text',
|
|
76
|
+
value: textAfterMentions
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Utility function that takes a string or a text nodes and converts it to a
|
|
84
|
+
* list of mention and text nodes.
|
|
85
|
+
*
|
|
86
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
87
|
+
* via the `allowSpaces` prop.
|
|
88
|
+
*/
|
|
89
|
+
export function $convertToMentionNodes(textOrNode, triggers) {
|
|
90
|
+
var punctuation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_PUNCTUATION;
|
|
91
|
+
var text = typeof textOrNode === 'string' ? textOrNode : textOrNode.getTextContent();
|
|
92
|
+
var entries = convertToMentionEntries(text, triggers, punctuation);
|
|
93
|
+
var nodes = [];
|
|
94
|
+
var _iterator2 = _createForOfIteratorHelper(entries),
|
|
95
|
+
_step2;
|
|
96
|
+
try {
|
|
97
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
98
|
+
var entry = _step2.value;
|
|
99
|
+
if (entry.type === 'custom-text') {
|
|
100
|
+
var textNode = $createTextNode(entry.value);
|
|
101
|
+
if (typeof textOrNode !== 'string') {
|
|
102
|
+
textNode.setFormat(textOrNode.getFormat());
|
|
103
|
+
}
|
|
104
|
+
nodes.push(textNode);
|
|
105
|
+
} else {
|
|
106
|
+
nodes.push($createMentionNode(entry.value));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
_iterator2.e(err);
|
|
111
|
+
} finally {
|
|
112
|
+
_iterator2.f();
|
|
113
|
+
}
|
|
114
|
+
return nodes;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Transforms text nodes containing mention strings into mention nodes.
|
|
119
|
+
*
|
|
120
|
+
* 🚨 Only works for mentions without spaces. Ensure spaces are disabled
|
|
121
|
+
* via the `allowSpaces` prop.
|
|
122
|
+
*/
|
|
123
|
+
export function $transformTextToMentionNodes(triggers) {
|
|
124
|
+
var punctuation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_PUNCTUATION;
|
|
125
|
+
var root = $getRoot();
|
|
126
|
+
var nodes = root.getChildren();
|
|
127
|
+
var traverseNodes = function traverseNodes(nodes) {
|
|
128
|
+
var _iterator3 = _createForOfIteratorHelper(nodes),
|
|
129
|
+
_step3;
|
|
130
|
+
try {
|
|
131
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
132
|
+
var node = _step3.value;
|
|
133
|
+
if ($isTextNode(node)) {
|
|
134
|
+
var newNodes = $convertToMentionNodes(node, triggers, punctuation);
|
|
135
|
+
if (newNodes.length > 1) {
|
|
136
|
+
var parent = node.getParent();
|
|
137
|
+
var index = node.getIndexWithinParent();
|
|
138
|
+
parent === null || parent === void 0 || parent.splice(index, 1, newNodes);
|
|
139
|
+
}
|
|
140
|
+
} else if ($isElementNode(node)) {
|
|
141
|
+
traverseNodes(node.getChildren());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch (err) {
|
|
145
|
+
_iterator3.e(err);
|
|
146
|
+
} finally {
|
|
147
|
+
_iterator3.f();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
traverseNodes(nodes);
|
|
151
|
+
}
|
|
@@ -3,6 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
3
3
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
4
4
|
import { LexicalTypeaheadMenuPlugin } from '@lexical/react/LexicalTypeaheadMenuPlugin';
|
|
5
5
|
import { ConfigProvider, Tree } from 'antd';
|
|
6
|
+
import { COMMAND_PRIORITY_NORMAL } from 'lexical';
|
|
6
7
|
import { flatMap } from 'lodash-es';
|
|
7
8
|
import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
8
9
|
import ReactDOM from 'react-dom';
|
|
@@ -163,7 +164,10 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
|
|
|
163
164
|
return null;
|
|
164
165
|
}, [cx, handleDisabledItem, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
|
|
165
166
|
return /*#__PURE__*/_jsx(LexicalTypeaheadMenuPlugin, {
|
|
166
|
-
anchorClassName: styles.anchor
|
|
167
|
+
anchorClassName: styles.anchor
|
|
168
|
+
// 优先级要高于 ShiftEnterKeyPlugin
|
|
169
|
+
,
|
|
170
|
+
commandPriority: COMMAND_PRIORITY_NORMAL,
|
|
167
171
|
menuRenderFn: renderMenu,
|
|
168
172
|
onQueryChange: setQueryString,
|
|
169
173
|
onSelectOption: onSelectOption,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { CAN_USE_BEFORE_INPUT, IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '@lexical/utils';
|
|
4
|
+
import { $getRoot, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from 'lexical';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
export var ShiftEnterKeyPlugin = function ShiftEnterKeyPlugin(_ref) {
|
|
7
|
+
var onPressEnter = _ref.onPressEnter;
|
|
8
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
9
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
10
|
+
editor = _useLexicalComposerCo2[0];
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
// https://github.com/facebook/lexical/discussions/4464#discussioncomment-5833227
|
|
13
|
+
editor.registerCommand(KEY_ENTER_COMMAND, function (event) {
|
|
14
|
+
var selection = $getSelection();
|
|
15
|
+
if (!$isRangeSelection(selection)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (event !== null) {
|
|
19
|
+
// If we have beforeinput, then we can avoid blocking
|
|
20
|
+
// the default behavior. This ensures that the iOS can
|
|
21
|
+
// intercept that we're actually inserting a paragraph,
|
|
22
|
+
// and autocomplete, autocapitalize etc work as intended.
|
|
23
|
+
// This can also cause a strange performance issue in
|
|
24
|
+
// Safari, where there is a noticeable pause due to
|
|
25
|
+
// preventing the key down of enter.
|
|
26
|
+
if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
if (event.shiftKey) {
|
|
31
|
+
return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, void 0);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
event === null || event === void 0 || event.preventDefault();
|
|
35
|
+
var text = editor.read(function () {
|
|
36
|
+
return $getRoot().getTextContent();
|
|
37
|
+
});
|
|
38
|
+
var value = text.replaceAll('\n\n', '\n');
|
|
39
|
+
onPressEnter(value, {
|
|
40
|
+
event: event
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
},
|
|
44
|
+
// 优先级要低于 MentionPickerPlugin
|
|
45
|
+
COMMAND_PRIORITY_LOW);
|
|
46
|
+
}, [editor, onPressEnter]);
|
|
47
|
+
return null;
|
|
48
|
+
};
|
package/es/Mentions/types.d.ts
CHANGED
package/es/Mentions/utils.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare const DELETE_MENTION_COMMAND: import("lexical").LexicalCommand<un
|
|
|
6
6
|
export declare const CLEAR_HIDE_MENU_TIMEOUT: import("lexical").LexicalCommand<unknown>;
|
|
7
7
|
export declare const UPDATE_MENTIONS_OPTIONS: import("lexical").LexicalCommand<unknown>;
|
|
8
8
|
export declare const decoratorTransform: (node: CustomTextNode, getMatch: (text: string) => null | EntityMatch, createNode: (textNode: TextNode) => LexicalNode) => void;
|
|
9
|
-
export declare function textToEditorState(
|
|
9
|
+
export declare function textToEditorState(initialValue: string, triggers: string[]): () => void;
|
package/es/Mentions/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import { $isTextNode, createCommand } from 'lexical';
|
|
3
|
+
import { $createParagraphNode, $getRoot, $isTextNode, createCommand } from 'lexical';
|
|
4
|
+
import { $convertToMentionNodes } from "./plugins/mention-converter";
|
|
3
5
|
export var INSERT_MENTION_COMMAND = createCommand('INSERT_MENTION_COMMAND');
|
|
4
6
|
export var DELETE_MENTION_COMMAND = createCommand('DELETE_MENTION_COMMAND');
|
|
5
7
|
export var CLEAR_HIDE_MENU_TIMEOUT = createCommand('CLEAR_HIDE_MENU_TIMEOUT');
|
|
@@ -63,33 +65,12 @@ export var decoratorTransform = function decoratorTransform(node, getMatch, crea
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
|
-
export function textToEditorState(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
root
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
format: 0,
|
|
75
|
-
mode: 'normal',
|
|
76
|
-
style: '',
|
|
77
|
-
text: p,
|
|
78
|
-
type: 'custom-text',
|
|
79
|
-
version: 1
|
|
80
|
-
}],
|
|
81
|
-
direction: 'ltr',
|
|
82
|
-
format: '',
|
|
83
|
-
indent: 0,
|
|
84
|
-
type: 'paragraph',
|
|
85
|
-
version: 1
|
|
86
|
-
};
|
|
87
|
-
}),
|
|
88
|
-
direction: 'ltr',
|
|
89
|
-
format: '',
|
|
90
|
-
indent: 0,
|
|
91
|
-
type: 'root',
|
|
92
|
-
version: 1
|
|
93
|
-
}
|
|
94
|
-
});
|
|
68
|
+
export function textToEditorState(initialValue, triggers) {
|
|
69
|
+
return function () {
|
|
70
|
+
var root = $getRoot();
|
|
71
|
+
root.clear();
|
|
72
|
+
var paragraph = $createParagraphNode();
|
|
73
|
+
paragraph.append.apply(paragraph, _toConsumableArray($convertToMentionNodes(initialValue, triggers)));
|
|
74
|
+
root.append(paragraph);
|
|
75
|
+
};
|
|
95
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuntijs/ui",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.8",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -80,7 +80,6 @@
|
|
|
80
80
|
]
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@alilc/lowcode-plugin-base-monaco-editor": "^1.1.2",
|
|
84
83
|
"@ant-design/icons": "^5",
|
|
85
84
|
"@babel/runtime": "^7",
|
|
86
85
|
"@lexical/react": "^0.23.1",
|