@smartspace/chat-ui 1.13.1-pr.417.eca5649 → 1.13.1-pr.419.f58f7bb
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/dist/index.js +30 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1600,6 +1600,21 @@ function getSchemaNodeType(view, name) {
|
|
|
1600
1600
|
return null;
|
|
1601
1601
|
return t;
|
|
1602
1602
|
}
|
|
1603
|
+
function findMentionTriggerPos(doc, windowStart, from) {
|
|
1604
|
+
let triggerPos = null;
|
|
1605
|
+
doc.nodesBetween(windowStart, from, (node2, pos) => {
|
|
1606
|
+
if (!node2.isText || !node2.text) {
|
|
1607
|
+
triggerPos = null;
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
for (let i = 0; i < node2.text.length; i++) {
|
|
1611
|
+
const charPos = pos + i;
|
|
1612
|
+
if (charPos < windowStart || charPos >= from) continue;
|
|
1613
|
+
if (node2.text[i] === "@") triggerPos = charPos;
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
return triggerPos;
|
|
1617
|
+
}
|
|
1603
1618
|
function EditorInner({
|
|
1604
1619
|
value,
|
|
1605
1620
|
onChange: _onChange,
|
|
@@ -1773,7 +1788,7 @@ function EditorInner({
|
|
|
1773
1788
|
bottom: coords.bottom
|
|
1774
1789
|
});
|
|
1775
1790
|
setMentionPlacement(getMentionPlacement(coords.top));
|
|
1776
|
-
setMentionFromPos(
|
|
1791
|
+
setMentionFromPos(pos);
|
|
1777
1792
|
setMentionQuery("");
|
|
1778
1793
|
setMentionIndex(0);
|
|
1779
1794
|
setMentionOpen(true);
|
|
@@ -2267,7 +2282,8 @@ function EditorInner({
|
|
|
2267
2282
|
const view = viewRef.current;
|
|
2268
2283
|
if (!view) return;
|
|
2269
2284
|
const to = view.state.selection.from;
|
|
2270
|
-
|
|
2285
|
+
if (mentionFromPos == null) return;
|
|
2286
|
+
const start = mentionFromPos;
|
|
2271
2287
|
const type = view.state.schema.nodes["mention"];
|
|
2272
2288
|
if (!type) return;
|
|
2273
2289
|
const node2 = type.create({ id: user.id, label: user.displayName });
|
|
@@ -2292,13 +2308,21 @@ function EditorInner({
|
|
|
2292
2308
|
if (!isEditable || !view) return;
|
|
2293
2309
|
const { from } = view.state.selection;
|
|
2294
2310
|
const windowStart = Math.max(0, from - 200);
|
|
2295
|
-
const
|
|
2296
|
-
|
|
2297
|
-
|
|
2311
|
+
const absoluteFrom = findMentionTriggerPos(
|
|
2312
|
+
view.state.doc,
|
|
2313
|
+
windowStart,
|
|
2314
|
+
from
|
|
2315
|
+
);
|
|
2316
|
+
if (absoluteFrom === null) {
|
|
2298
2317
|
if (mentionOpen) setMentionOpen(false);
|
|
2299
2318
|
return;
|
|
2300
2319
|
}
|
|
2301
|
-
const after =
|
|
2320
|
+
const after = view.state.doc.textBetween(
|
|
2321
|
+
absoluteFrom + 1,
|
|
2322
|
+
from,
|
|
2323
|
+
"\n",
|
|
2324
|
+
"\n"
|
|
2325
|
+
);
|
|
2302
2326
|
if (/[\t\r\n]/.test(after)) {
|
|
2303
2327
|
if (mentionOpen) setMentionOpen(false);
|
|
2304
2328
|
return;
|
|
@@ -2308,7 +2332,6 @@ function EditorInner({
|
|
|
2308
2332
|
if (mentionOpen) setMentionOpen(false);
|
|
2309
2333
|
return;
|
|
2310
2334
|
}
|
|
2311
|
-
const absoluteFrom = windowStart + at;
|
|
2312
2335
|
if (mentionDismissedAtRef.current === absoluteFrom) {
|
|
2313
2336
|
return;
|
|
2314
2337
|
}
|