mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
chore: fix formatting
This commit is contained in:
parent
7c8e269190
commit
eb6192d480
2 changed files with 45 additions and 46 deletions
|
|
@ -90,7 +90,7 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
|
||||||
// Get plain text content (excluding chips)
|
// Get plain text content (excluding chips)
|
||||||
const getText = useCallback((): string => {
|
const getText = useCallback((): string => {
|
||||||
if (!editorRef.current) return "";
|
if (!editorRef.current) return "";
|
||||||
|
|
||||||
let text = "";
|
let text = "";
|
||||||
const walker = document.createTreeWalker(
|
const walker = document.createTreeWalker(
|
||||||
editorRef.current,
|
editorRef.current,
|
||||||
|
|
@ -127,47 +127,50 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
|
||||||
}, [mentionedDocs]);
|
}, [mentionedDocs]);
|
||||||
|
|
||||||
// Create a chip element for a document
|
// Create a chip element for a document
|
||||||
const createChipElement = useCallback((doc: MentionedDocument): HTMLSpanElement => {
|
const createChipElement = useCallback(
|
||||||
const chip = document.createElement("span");
|
(doc: MentionedDocument): HTMLSpanElement => {
|
||||||
chip.setAttribute(CHIP_DATA_ATTR, "true");
|
const chip = document.createElement("span");
|
||||||
chip.setAttribute(CHIP_ID_ATTR, String(doc.id));
|
chip.setAttribute(CHIP_DATA_ATTR, "true");
|
||||||
chip.contentEditable = "false";
|
chip.setAttribute(CHIP_ID_ATTR, String(doc.id));
|
||||||
chip.className =
|
chip.contentEditable = "false";
|
||||||
"inline-flex items-center gap-0.5 mx-0.5 pl-1 pr-0.5 py-0.5 rounded bg-primary/10 text-xs font-bold text-primary border border-primary/10 select-none";
|
chip.className =
|
||||||
chip.style.userSelect = "none";
|
"inline-flex items-center gap-0.5 mx-0.5 pl-1 pr-0.5 py-0.5 rounded bg-primary/10 text-xs font-bold text-primary border border-primary/10 select-none";
|
||||||
chip.style.verticalAlign = "baseline";
|
chip.style.userSelect = "none";
|
||||||
|
chip.style.verticalAlign = "baseline";
|
||||||
|
|
||||||
const titleSpan = document.createElement("span");
|
const titleSpan = document.createElement("span");
|
||||||
titleSpan.className = "max-w-[80px] truncate";
|
titleSpan.className = "max-w-[80px] truncate";
|
||||||
titleSpan.textContent = doc.title;
|
titleSpan.textContent = doc.title;
|
||||||
titleSpan.title = doc.title;
|
titleSpan.title = doc.title;
|
||||||
|
|
||||||
const removeBtn = document.createElement("button");
|
const removeBtn = document.createElement("button");
|
||||||
removeBtn.type = "button";
|
removeBtn.type = "button";
|
||||||
removeBtn.className =
|
removeBtn.className =
|
||||||
"size-3 flex items-center justify-center rounded-full hover:bg-primary/20 transition-colors ml-0.5";
|
"size-3 flex items-center justify-center rounded-full hover:bg-primary/20 transition-colors ml-0.5";
|
||||||
removeBtn.innerHTML = ReactDOMServer.renderToString(
|
removeBtn.innerHTML = ReactDOMServer.renderToString(
|
||||||
createElement(X, { className: "h-2.5 w-2.5", strokeWidth: 2.5 })
|
createElement(X, { className: "h-2.5 w-2.5", strokeWidth: 2.5 })
|
||||||
);
|
);
|
||||||
removeBtn.onclick = (e) => {
|
removeBtn.onclick = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
chip.remove();
|
chip.remove();
|
||||||
setMentionedDocs((prev) => {
|
setMentionedDocs((prev) => {
|
||||||
const next = new Map(prev);
|
const next = new Map(prev);
|
||||||
next.delete(doc.id);
|
next.delete(doc.id);
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
// Notify parent that a document was removed
|
// Notify parent that a document was removed
|
||||||
onDocumentRemove?.(doc.id);
|
onDocumentRemove?.(doc.id);
|
||||||
focusAtEnd();
|
focusAtEnd();
|
||||||
};
|
};
|
||||||
|
|
||||||
chip.appendChild(titleSpan);
|
chip.appendChild(titleSpan);
|
||||||
chip.appendChild(removeBtn);
|
chip.appendChild(removeBtn);
|
||||||
|
|
||||||
return chip;
|
return chip;
|
||||||
}, [focusAtEnd, onDocumentRemove]);
|
},
|
||||||
|
[focusAtEnd, onDocumentRemove]
|
||||||
|
);
|
||||||
|
|
||||||
// Insert a document chip at the current cursor position
|
// Insert a document chip at the current cursor position
|
||||||
const insertDocumentChip = useCallback(
|
const insertDocumentChip = useCallback(
|
||||||
|
|
@ -222,8 +225,8 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
|
||||||
// Replace text node content
|
// Replace text node content
|
||||||
const parent = textNode.parentNode;
|
const parent = textNode.parentNode;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const beforeNode = document.createTextNode(beforeAt);
|
const beforeNode = document.createTextNode(beforeAt);
|
||||||
const afterNode = document.createTextNode(` ${afterCursor}`);
|
const afterNode = document.createTextNode(` ${afterCursor}`);
|
||||||
|
|
||||||
parent.insertBefore(beforeNode, textNode);
|
parent.insertBefore(beforeNode, textNode);
|
||||||
parent.insertBefore(chip, textNode);
|
parent.insertBefore(chip, textNode);
|
||||||
|
|
@ -243,7 +246,7 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
|
||||||
range.insertNode(chip);
|
range.insertNode(chip);
|
||||||
range.setStartAfter(chip);
|
range.setStartAfter(chip);
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
|
|
||||||
// Add space after chip
|
// Add space after chip
|
||||||
const space = document.createTextNode(" ");
|
const space = document.createTextNode(" ");
|
||||||
range.insertNode(space);
|
range.insertNode(space);
|
||||||
|
|
@ -491,4 +494,3 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
|
||||||
);
|
);
|
||||||
|
|
||||||
InlineMentionEditor.displayName = "InlineMentionEditor";
|
InlineMentionEditor.displayName = "InlineMentionEditor";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -558,10 +558,7 @@ const Composer: FC = () => {
|
||||||
<ComposerPrimitive.AttachmentDropzone className="aui-composer-attachment-dropzone flex w-full flex-col rounded-2xl border-input bg-muted px-1 pt-2 outline-none transition-shadow data-[dragging=true]:border-ring data-[dragging=true]:border-dashed data-[dragging=true]:bg-accent/50">
|
<ComposerPrimitive.AttachmentDropzone className="aui-composer-attachment-dropzone flex w-full flex-col rounded-2xl border-input bg-muted px-1 pt-2 outline-none transition-shadow data-[dragging=true]:border-ring data-[dragging=true]:border-dashed data-[dragging=true]:bg-accent/50">
|
||||||
<ComposerAttachments />
|
<ComposerAttachments />
|
||||||
{/* -------- Inline Mention Editor -------- */}
|
{/* -------- Inline Mention Editor -------- */}
|
||||||
<div
|
<div ref={editorContainerRef} className="aui-composer-input-wrapper px-3 pt-3 pb-6">
|
||||||
ref={editorContainerRef}
|
|
||||||
className="aui-composer-input-wrapper px-3 pt-3 pb-6"
|
|
||||||
>
|
|
||||||
<InlineMentionEditor
|
<InlineMentionEditor
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
placeholder="Ask SurfSense (type @ to mention docs)"
|
placeholder="Ask SurfSense (type @ to mention docs)"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue