@flozy/editor 4.1.9 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,8 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
46
46
|
const [deboundedValue] = useDebounce(value, 500);
|
47
47
|
const editor = useMemo(() => {
|
48
48
|
return withCommon(createEditor(), {
|
49
|
-
needLayout
|
49
|
+
needLayout,
|
50
|
+
isChatEditor: true
|
50
51
|
});
|
51
52
|
}, []);
|
52
53
|
const isReadOnly = readOnly === "readonly";
|
@@ -13,7 +13,7 @@ const getStartEnd = ({
|
|
13
13
|
// Get start and end, modify it as we move along.
|
14
14
|
let [start, end] = Range.edges(selection);
|
15
15
|
|
16
|
-
// Move backwards
|
16
|
+
// Move backwards to find the start of the word
|
17
17
|
while (true) {
|
18
18
|
const before = Editor.before(editor, start, {
|
19
19
|
unit: "character"
|
@@ -22,16 +22,15 @@ const getStartEnd = ({
|
|
22
22
|
anchor: before,
|
23
23
|
focus: start
|
24
24
|
});
|
25
|
-
if (before
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
if (before) {
|
26
|
+
if (wordBefore.trim() === "") {
|
27
|
+
break;
|
28
|
+
} else if (SHORTHAND_CMDS.indexOf(wordBefore) < 0) {
|
29
|
+
start = before;
|
30
|
+
} else {
|
31
|
+
start = before;
|
29
32
|
break;
|
30
33
|
}
|
31
|
-
} else if (SHORTHAND_CMDS.indexOf(wordBefore) >= 0) {
|
32
|
-
// reached the character end
|
33
|
-
start = before;
|
34
|
-
break;
|
35
34
|
} else {
|
36
35
|
break;
|
37
36
|
}
|
@@ -41,11 +40,38 @@ const getStartEnd = ({
|
|
41
40
|
focus: end
|
42
41
|
};
|
43
42
|
const word = Editor.string(editor, wordRange);
|
43
|
+
const firstChar = word[0];
|
44
|
+
|
45
|
+
// Handle the commands
|
46
|
+
if (firstChar === '@') {
|
47
|
+
// Only trigger @ if preceded by a space
|
48
|
+
const isPrecededBySpace = Editor.string(editor, {
|
49
|
+
anchor: {
|
50
|
+
path: start.path,
|
51
|
+
offset: start.offset - 1
|
52
|
+
},
|
53
|
+
focus: start
|
54
|
+
}).trim() === "";
|
55
|
+
if (isPrecededBySpace) {
|
56
|
+
return {
|
57
|
+
word,
|
58
|
+
search: word.substring(1),
|
59
|
+
target: wordRange,
|
60
|
+
type: TYPES[firstChar]
|
61
|
+
};
|
62
|
+
}
|
63
|
+
} else if (firstChar === '/') {
|
64
|
+
return {
|
65
|
+
word,
|
66
|
+
search: word.substring(1),
|
67
|
+
target: wordRange,
|
68
|
+
type: TYPES[firstChar]
|
69
|
+
};
|
70
|
+
}
|
44
71
|
return {
|
45
|
-
word,
|
46
|
-
|
47
|
-
|
48
|
-
type: TYPES[word[0]]
|
72
|
+
word: "",
|
73
|
+
wordRange: null,
|
74
|
+
type: null
|
49
75
|
};
|
50
76
|
} catch (err) {
|
51
77
|
return {
|
@@ -9,7 +9,12 @@ import withLayout from "../plugins/withLayout";
|
|
9
9
|
import withHtml from "../plugins/withHTML";
|
10
10
|
import withErrorHandling from "./withErrorHandling";
|
11
11
|
import withCustomDeleteBackward from "../plugins/withCustomDeleteBackward";
|
12
|
-
const withCommon = (props,
|
13
|
-
|
12
|
+
const withCommon = (props, {
|
13
|
+
needLayout = false,
|
14
|
+
isChatEditor = false
|
15
|
+
}) => {
|
16
|
+
const editor = needLayout ? withErrorHandling(withHtml(withEquation(withLayout(withHistory(withEmbeds(withTables(withLinks(withMentions(withCustomDeleteBackward(withReact(props))))))))))) : withErrorHandling(withHtml(withEquation(withHistory(withEmbeds(withTables(withLinks(withMentions(withCustomDeleteBackward(withReact(props))))))))));
|
17
|
+
editor.isChatEditor = isChatEditor;
|
18
|
+
return editor;
|
14
19
|
};
|
15
20
|
export default withCommon;
|
@@ -101,6 +101,9 @@ const withHtml = editor => {
|
|
101
101
|
return element.type === "image" ? true : isVoid(element);
|
102
102
|
};
|
103
103
|
editor.insertData = data => {
|
104
|
+
if (editor.isChatEditor) {
|
105
|
+
return;
|
106
|
+
}
|
104
107
|
const slateHTML = data?.getData("application/x-slate-fragment");
|
105
108
|
const html = data?.getData("text/html");
|
106
109
|
const currentEl = getCurrentElement(editor);
|