@yuntijs/ui 1.1.0-beta.6 → 1.1.0-beta.7
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 +5 -3
- package/es/Mentions/index.js +10 -6
- 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/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;
|
|
@@ -22,4 +24,4 @@ export interface MentionsProps extends MentionPickerPluginProps {
|
|
|
22
24
|
code?: boolean;
|
|
23
25
|
getPopContainer?: () => HTMLElement;
|
|
24
26
|
}
|
|
25
|
-
export declare const Mentions: React.
|
|
27
|
+
export declare const Mentions: React.ForwardRefExoticComponent<MentionsProps & React.RefAttributes<MentionsEditor>>;
|
package/es/Mentions/index.js
CHANGED
|
@@ -9,21 +9,23 @@ 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
21
|
import { MentionsConfigProvider } from "./provider";
|
|
22
22
|
import { useStyles } from "./style";
|
|
23
23
|
import { textToEditorState } from "./utils";
|
|
24
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
25
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
-
export
|
|
26
|
+
export * from "./types";
|
|
27
|
+
export * from "./utils";
|
|
28
|
+
export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
27
29
|
var className = _ref.className,
|
|
28
30
|
classNames = _ref.classNames,
|
|
29
31
|
placeholder = _ref.placeholder,
|
|
@@ -73,7 +75,7 @@ export var Mentions = function Mentions(_ref) {
|
|
|
73
75
|
return new CustomTextNode(node.__text);
|
|
74
76
|
}
|
|
75
77
|
}, MentionNode],
|
|
76
|
-
editorState: textToEditorState(value || defaultValue || ''),
|
|
78
|
+
editorState: textToEditorState(value || defaultValue || '', triggers),
|
|
77
79
|
onError: function onError(error) {
|
|
78
80
|
throw error;
|
|
79
81
|
}
|
|
@@ -156,8 +158,10 @@ export var Mentions = function Mentions(_ref) {
|
|
|
156
158
|
onFocus: onFocus
|
|
157
159
|
}), /*#__PURE__*/_jsx(EditablePlugin, {
|
|
158
160
|
editable: editable
|
|
161
|
+
}), /*#__PURE__*/_jsx(EditorRefPlugin, {
|
|
162
|
+
editorRef: ref
|
|
159
163
|
})]
|
|
160
164
|
})
|
|
161
165
|
})
|
|
162
166
|
});
|
|
163
|
-
};
|
|
167
|
+
});
|
|
@@ -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
|
+
}
|
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.7",
|
|
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",
|