bsky-richtext-react 1.0.2 → 2.0.0
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/CHANGELOG.md +68 -0
- package/README.md +38 -82
- package/dist/index.cjs +49 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +49 -46
- package/dist/index.js.map +1 -1
- package/package.json +27 -30
- package/dist/styles.css +0 -106
- package/dist/styles.css.map +0 -1
- package/dist/styles.d.cts +0 -2
- package/dist/styles.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { HardBreak } from '@tiptap/extension-hard-break';
|
|
|
9
9
|
import { Placeholder } from '@tiptap/extension-placeholder';
|
|
10
10
|
import { RichText } from '@atproto/api';
|
|
11
11
|
import { Mention } from '@tiptap/extension-mention';
|
|
12
|
-
import
|
|
12
|
+
import { computePosition, offset, flip, shift } from '@floating-ui/dom';
|
|
13
13
|
import { Extension } from '@tiptap/core';
|
|
14
14
|
import { PluginKey, Plugin } from '@tiptap/pm/state';
|
|
15
15
|
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
@@ -29,29 +29,28 @@ function isTagFeature(feature) {
|
|
|
29
29
|
|
|
30
30
|
// src/defaults/classNames.ts
|
|
31
31
|
var defaultDisplayClassNames = {
|
|
32
|
-
root: "
|
|
33
|
-
mention: "
|
|
34
|
-
link: "
|
|
35
|
-
tag: "
|
|
32
|
+
root: "inline break-words",
|
|
33
|
+
mention: "inline text-blue-500 hover:underline cursor-pointer",
|
|
34
|
+
link: "inline text-blue-500 hover:underline",
|
|
35
|
+
tag: "inline text-blue-500 hover:underline cursor-pointer"
|
|
36
36
|
};
|
|
37
37
|
var defaultSuggestionClassNames = {
|
|
38
|
-
root: "
|
|
39
|
-
item: "
|
|
40
|
-
itemSelected: "
|
|
41
|
-
avatar: "
|
|
42
|
-
avatarImg: "
|
|
43
|
-
avatarPlaceholder: "
|
|
44
|
-
text: "
|
|
45
|
-
name: "
|
|
46
|
-
handle: "
|
|
47
|
-
empty: "
|
|
38
|
+
root: "flex flex-col max-h-80 overflow-y-auto bg-white rounded-lg shadow-lg border border-gray-200 min-w-60",
|
|
39
|
+
item: "flex items-center gap-3 w-full px-3 py-2 text-left cursor-pointer border-none bg-transparent hover:bg-gray-100 select-none",
|
|
40
|
+
itemSelected: "bg-gray-100",
|
|
41
|
+
avatar: "flex-shrink-0 w-10 h-10 rounded-full overflow-hidden bg-gray-200 flex items-center justify-center",
|
|
42
|
+
avatarImg: "block w-full h-full object-cover",
|
|
43
|
+
avatarPlaceholder: "flex items-center justify-center w-full h-full text-gray-500 font-medium text-sm",
|
|
44
|
+
text: "flex flex-col flex-1 min-w-0 overflow-hidden",
|
|
45
|
+
name: "block truncate font-medium text-gray-900 text-sm",
|
|
46
|
+
handle: "block truncate text-xs text-gray-500",
|
|
47
|
+
empty: "block px-3 py-2 text-sm text-gray-500"
|
|
48
48
|
};
|
|
49
49
|
var defaultEditorClassNames = {
|
|
50
|
-
root: "
|
|
51
|
-
content: "
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
link: "autolink",
|
|
50
|
+
root: "block w-full relative",
|
|
51
|
+
content: "block w-full",
|
|
52
|
+
mention: "inline text-blue-500",
|
|
53
|
+
link: "inline text-blue-500",
|
|
55
54
|
suggestion: defaultSuggestionClassNames
|
|
56
55
|
};
|
|
57
56
|
|
|
@@ -366,13 +365,7 @@ function createDebouncedSearch(delayMs = 300) {
|
|
|
366
365
|
});
|
|
367
366
|
};
|
|
368
367
|
}
|
|
369
|
-
var MentionSuggestionList = forwardRef(function MentionSuggestionListImpl({
|
|
370
|
-
items,
|
|
371
|
-
command,
|
|
372
|
-
showAvatars = true,
|
|
373
|
-
noResultsText = "No results",
|
|
374
|
-
classNames: classNamesProp
|
|
375
|
-
}, ref) {
|
|
368
|
+
var MentionSuggestionList = forwardRef(function MentionSuggestionListImpl({ items, command, showAvatars = true, noResultsText = "No results", classNames: classNamesProp }, ref) {
|
|
376
369
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
377
370
|
const cn = useMemo(
|
|
378
371
|
() => generateClassNames([defaultSuggestionClassNames, classNamesProp]),
|
|
@@ -456,12 +449,6 @@ function createDefaultSuggestionRenderer(options = {}) {
|
|
|
456
449
|
return () => {
|
|
457
450
|
let renderer;
|
|
458
451
|
let popup;
|
|
459
|
-
const destroy = () => {
|
|
460
|
-
popup?.[0]?.destroy();
|
|
461
|
-
renderer?.destroy();
|
|
462
|
-
renderer = void 0;
|
|
463
|
-
popup = void 0;
|
|
464
|
-
};
|
|
465
452
|
const buildProps = (props) => ({
|
|
466
453
|
...props,
|
|
467
454
|
showAvatars: options.showAvatars ?? true,
|
|
@@ -476,33 +463,49 @@ function createDefaultSuggestionRenderer(options = {}) {
|
|
|
476
463
|
});
|
|
477
464
|
if (!props.clientRect) return;
|
|
478
465
|
const clientRect = props.clientRect;
|
|
479
|
-
popup =
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
placement: "bottom-start"
|
|
466
|
+
popup = document.createElement("div");
|
|
467
|
+
popup.style.position = "fixed";
|
|
468
|
+
popup.style.zIndex = "9999";
|
|
469
|
+
popup.appendChild(renderer.element);
|
|
470
|
+
document.body.appendChild(popup);
|
|
471
|
+
const virtualEl = { getBoundingClientRect: () => clientRect?.() ?? new DOMRect() };
|
|
472
|
+
void computePosition(virtualEl, popup, {
|
|
473
|
+
placement: "bottom-start",
|
|
474
|
+
middleware: [offset(8), flip(), shift({ padding: 8 })]
|
|
475
|
+
}).then(({ x, y }) => {
|
|
476
|
+
if (popup) {
|
|
477
|
+
popup.style.left = `${x}px`;
|
|
478
|
+
popup.style.top = `${y}px`;
|
|
479
|
+
}
|
|
487
480
|
});
|
|
488
481
|
},
|
|
489
482
|
onUpdate(props) {
|
|
490
483
|
renderer?.updateProps(buildProps(props));
|
|
491
|
-
if (!props.clientRect) return;
|
|
484
|
+
if (!props.clientRect || !popup) return;
|
|
492
485
|
const clientRect = props.clientRect;
|
|
493
|
-
|
|
494
|
-
|
|
486
|
+
const virtualEl = { getBoundingClientRect: () => clientRect?.() ?? new DOMRect() };
|
|
487
|
+
void computePosition(virtualEl, popup, {
|
|
488
|
+
placement: "bottom-start",
|
|
489
|
+
middleware: [offset(8), flip(), shift({ padding: 8 })]
|
|
490
|
+
}).then(({ x, y }) => {
|
|
491
|
+
if (popup) {
|
|
492
|
+
popup.style.left = `${x}px`;
|
|
493
|
+
popup.style.top = `${y}px`;
|
|
494
|
+
}
|
|
495
495
|
});
|
|
496
496
|
},
|
|
497
497
|
onKeyDown(props) {
|
|
498
498
|
if (props.event.key === "Escape") {
|
|
499
|
-
popup
|
|
499
|
+
if (popup) popup.style.display = "none";
|
|
500
500
|
return true;
|
|
501
501
|
}
|
|
502
502
|
return renderer?.ref?.onKeyDown(props) ?? false;
|
|
503
503
|
},
|
|
504
504
|
onExit() {
|
|
505
|
-
|
|
505
|
+
popup?.remove();
|
|
506
|
+
renderer?.destroy();
|
|
507
|
+
popup = void 0;
|
|
508
|
+
renderer = void 0;
|
|
506
509
|
}
|
|
507
510
|
};
|
|
508
511
|
};
|