mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-28 08:09:27 -05:00
refac
This commit is contained in:
1 parent
86e912697a
commit
f80331e08c
5 files changed
+273
-266
No files matched your search
@@ -173,6 +173,7 @@
|
||||
import Sidebar from '../icons/Sidebar.svelte';
|
||||
import Image from '../common/Image.svelte';
|
||||
import XMark from '../icons/XMark.svelte';
|
||||
import ChevronDown from '../icons/ChevronDown.svelte';
|
||||
import EmbeddedChatHistoryDropdown from './EmbeddedChatHistoryDropdown.svelte';
|
||||
import ChatMenu from '$lib/components/layout/Navbar/Menu.svelte';
|
||||
import ShareChatModal from './ShareChatModal.svelte';
|
||||
@@ -239,6 +240,11 @@
|
||||
export let onBeforeNoteSubmit: (() => Promise<void>) | null = null;
|
||||
export let onInsertToNote: ((content: string) => void) | null = null;
|
||||
export let onCloseEmbedded: (() => void) | null = null;
|
||||
// Collapsed embedded chats render only the composer; the host expands them on demand.
|
||||
export let embeddedCollapsed = false;
|
||||
export let onCollapseEmbedded: (() => void) | null = null;
|
||||
// Pads the header and messages when the host draws the composer flush to its frame.
|
||||
export let embeddedInset = false;
|
||||
export let onNewEmbeddedChat: (() => void | Promise<void>) | null = null;
|
||||
export let onCreateEmbeddedChat:
|
||||
| ((chat: {
|
||||
@@ -6170,9 +6176,11 @@
|
||||
{/if}
|
||||
{:else}
|
||||
<FilesOverlay show={dragged} />
|
||||
{#if embedded && !tabbed}
|
||||
{#if embedded && !tabbed && !embeddedCollapsed}
|
||||
<div
|
||||
class="h-8 shrink-0 flex items-center justify-between gap-2 border-b border-base-50/80 px-3 pb-1 text-base-700 dark:border-base-850/40 dark:text-base-200"
|
||||
class="h-8 shrink-0 flex items-center justify-between gap-2 border-b border-base-50/80 pb-1 text-base-700 dark:border-base-850/40 dark:text-base-200 {embeddedInset
|
||||
? 'px-4'
|
||||
: 'px-3'}"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<EmbeddedChatHistoryDropdown
|
||||
@@ -6186,6 +6194,16 @@
|
||||
onDeleteChat={onDeleteEmbeddedChat}
|
||||
/>
|
||||
</div>
|
||||
{#if onCollapseEmbedded}<Tooltip content={$i18n.t('Collapse')} placement="bottom">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md py-1 text-base-500 transition hover:text-base-900 dark:hover:text-base-0 px-0"
|
||||
on:click={() => onCollapseEmbedded?.()}
|
||||
aria-label={$i18n.t('Collapse')}
|
||||
>
|
||||
<ChevronDown className="size-4" strokeWidth="2" />
|
||||
</button>
|
||||
</Tooltip>{/if}
|
||||
{#if onCloseEmbedded}<Tooltip content={$i18n.t('Close')} placement="bottom">
|
||||
<button
|
||||
type="button"
|
||||
@@ -6270,12 +6288,16 @@
|
||||
{/if}
|
||||
<div
|
||||
id="chat-pane"
|
||||
class="flex min-h-0 flex-col flex-auto z-10 w-full @container overflow-auto"
|
||||
class="flex min-h-0 flex-col flex-auto z-10 w-full @container {embeddedCollapsed
|
||||
? 'overflow-visible'
|
||||
: 'overflow-auto'}"
|
||||
>
|
||||
<div class="sr-only" aria-live="polite" aria-atomic="true">{liveStatus}</div>
|
||||
{#if (!tabbed && $settings?.landingPageMode === 'chat' && !$selectedFolder) || (!contextOnly && createMessagesList(history, history.currentId).length > 0)}
|
||||
<div
|
||||
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0 max-w-full z-10 scrollbar-hidden"
|
||||
class:hidden={embeddedCollapsed}
|
||||
class:px-2={embeddedInset}
|
||||
id={messagesContainerId}
|
||||
bind:this={messagesContainerElement}
|
||||
on:scroll={(e) => {
|
||||
@@ -6387,6 +6409,7 @@
|
||||
{contextUsage}
|
||||
{contextCompactionEnabled}
|
||||
{embedded}
|
||||
autofocus={!embeddedCollapsed}
|
||||
compactHandler={handleManualCompact}
|
||||
statusHandler={handleStatusCommand}
|
||||
forkHandler={handleForkChat}
|
||||
@@ -6444,7 +6467,7 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{:else if suggestedPrompts.length > 0}
|
||||
{:else if suggestedPrompts.length > 0 && !embeddedCollapsed}
|
||||
<div class="flex flex-1 items-end px-5 pb-8">
|
||||
<div class="w-full">
|
||||
<div class="mb-2 text-[0.75rem] text-base-300 dark:text-base-700">
|
||||
@@ -6509,6 +6532,7 @@
|
||||
{contextUsage}
|
||||
{contextCompactionEnabled}
|
||||
{embedded}
|
||||
autofocus={!embeddedCollapsed}
|
||||
compactHandler={handleManualCompact}
|
||||
statusHandler={handleStatusCommand}
|
||||
forkHandler={handleForkChat}
|
||||
|
||||
@@ -179,6 +179,7 @@
|
||||
export let contextUsage = null;
|
||||
export let contextCompactionEnabled = false;
|
||||
export let embedded = false;
|
||||
export let autofocus = true;
|
||||
export let callActive = false;
|
||||
export let callEnabled = true;
|
||||
|
||||
@@ -1903,7 +1904,7 @@
|
||||
loaded = true;
|
||||
|
||||
window.setTimeout(() => {
|
||||
if (!$mobile && !$voiceCall) {
|
||||
if (autofocus && !$mobile && !$voiceCall) {
|
||||
const chatInput = document.getElementById(inputId);
|
||||
chatInput?.focus();
|
||||
}
|
||||
@@ -2426,6 +2427,7 @@
|
||||
json={true}
|
||||
richText={$settings?.richTextInput ?? true}
|
||||
messageInput={true}
|
||||
{autofocus}
|
||||
followUpSuggestion={!generating &&
|
||||
history?.messages?.[history?.currentId]?.role === 'assistant' &&
|
||||
history?.messages?.[history?.currentId]?.done
|
||||
|
||||
@@ -421,6 +421,7 @@
|
||||
}
|
||||
|
||||
export let messageInput = false;
|
||||
export let autofocus = true;
|
||||
export let shiftEnter = false;
|
||||
export let largeTextAsFile = false;
|
||||
export let insertPromptAsRichText = false;
|
||||
@@ -1106,7 +1107,7 @@
|
||||
],
|
||||
content: provider ? undefined : content,
|
||||
editable,
|
||||
autofocus: messageInput && !$mobile && !$voiceCall,
|
||||
autofocus: autofocus && messageInput && !$mobile && !$voiceCall,
|
||||
onTransaction: ({ transaction }) => {
|
||||
if (!editor) return;
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
import CommentsPanel, {
|
||||
type CommentsRequest
|
||||
} from '$lib/components/comments/CommentsPanel.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||
import ChevronUp from '$lib/components/icons/ChevronUp.svelte';
|
||||
import { getContext, onDestroy, onMount, tick } from 'svelte';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import fileSaver from 'file-saver';
|
||||
@@ -75,7 +76,6 @@
|
||||
deleteNoteById,
|
||||
createNoteChatById,
|
||||
getNoteById,
|
||||
getNoteChatById,
|
||||
getNoteChatsById,
|
||||
updateNoteById,
|
||||
updateNotePages,
|
||||
@@ -104,7 +104,6 @@
|
||||
import ArrowUturnLeft from '../icons/ArrowUturnLeft.svelte';
|
||||
import ArrowUturnRight from '../icons/ArrowUturnRight.svelte';
|
||||
import Sidebar from '../icons/Sidebar.svelte';
|
||||
import ChatBubbleOval from '../icons/ChatBubbleOval.svelte';
|
||||
|
||||
export let id: null | string = null;
|
||||
let noteRoot: HTMLDivElement;
|
||||
@@ -352,7 +351,6 @@
|
||||
let recording = false;
|
||||
let displayMediaRecord = false;
|
||||
|
||||
let showNoteChat = false;
|
||||
$: commentsEnabled = !!($config?.features?.enable_comments && $user && note?.id);
|
||||
let currentNoteComments: CommentsRequest | null = null;
|
||||
let linkedComment = '';
|
||||
@@ -364,16 +362,6 @@
|
||||
}
|
||||
$: if (currentNoteComments && (!commentsEnabled || currentNoteComments.resource_id !== note?.id))
|
||||
currentNoteComments = null;
|
||||
onMount(() => {
|
||||
const close = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape' && currentNoteComments) closeNotePanel();
|
||||
};
|
||||
document.addEventListener('keydown', close);
|
||||
return () => {
|
||||
document.removeEventListener('keydown', close);
|
||||
};
|
||||
});
|
||||
let noteCommentCount = 0;
|
||||
// Editable notes comment from the formatting toolbar instead of the floating selection button.
|
||||
$: selectionCommentsEnabled = commentsEnabled && versionIdx === null && !!note?.write_access;
|
||||
const commentOnSelection = async () => {
|
||||
@@ -391,15 +379,17 @@
|
||||
commentSelectionDraft.set(selected);
|
||||
window.getSelection()?.removeAllRanges();
|
||||
};
|
||||
$: if (currentNoteComments) showNoteChat = true;
|
||||
const closeNotePanel = async () => {
|
||||
currentNoteComments = null;
|
||||
showNoteChat = false;
|
||||
|
||||
await tick();
|
||||
if (document.activeElement === document.body) noteChatButtonElement?.focus();
|
||||
};
|
||||
let noteChatId = null;
|
||||
let noteChatExpanded = false;
|
||||
// Opening a note lands in its body; the docked chat composer no longer takes focus.
|
||||
let focusedNoteId = '';
|
||||
const focusOpenedNote = (instance) => {
|
||||
if (!instance || instance.isDestroyed || !note?.id || note.id === focusedNoteId) return;
|
||||
focusedNoteId = note.id;
|
||||
if (note.write_access && !$mobile && document.activeElement === document.body)
|
||||
instance.commands.focus('start', { scrollIntoView: false });
|
||||
};
|
||||
let noteChatNoteId = '';
|
||||
let noteChatLoading = false;
|
||||
let noteChats = [];
|
||||
let noteChatDraftKey = '';
|
||||
@@ -424,7 +414,6 @@
|
||||
let titleInputFocused = false;
|
||||
let titleGenerating = false;
|
||||
let titleInputElement: HTMLInputElement;
|
||||
let noteChatButtonElement: HTMLButtonElement;
|
||||
let pagesToggleElement: HTMLButtonElement;
|
||||
|
||||
let dragged = false;
|
||||
@@ -839,53 +828,35 @@ ${content}
|
||||
input.click();
|
||||
};
|
||||
|
||||
const openNoteChat = async () => {
|
||||
console.info('[note-chat] open requested', {
|
||||
noteId: note?.id,
|
||||
alreadyLoading: noteChatLoading,
|
||||
currentChatId: noteChatId,
|
||||
sidebarOpen: showNoteChat
|
||||
});
|
||||
if (!note?.id) return;
|
||||
currentNoteComments = null;
|
||||
showNoteChat = true;
|
||||
if (noteChatLoading || noteChatId || noteChatDraftKey) return;
|
||||
|
||||
// The docked composer is always mounted, so list existing chats without creating one;
|
||||
// an empty note gets a draft whose backing chat is created on the first message.
|
||||
const loadNoteChat = async (noteId: string) => {
|
||||
noteChatId = null;
|
||||
noteChats = [];
|
||||
noteChatDraftKey = '';
|
||||
noteChatExpanded = false;
|
||||
noteChatLoading = true;
|
||||
const chat = await getNoteChatById(localStorage.token, note.id).catch((error) => {
|
||||
console.error('[note-chat] open failed', { noteId: note?.id, error });
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
const chats = await getNoteChatsById(localStorage.token, noteId).catch((error) => {
|
||||
console.error('[note-chat] history failed', { noteId, error });
|
||||
return [];
|
||||
});
|
||||
const chats = chat
|
||||
? await getNoteChatsById(localStorage.token, note.id).catch((error) => {
|
||||
console.error('[note-chat] history failed', { noteId: note?.id, error });
|
||||
return null;
|
||||
})
|
||||
: null;
|
||||
if (noteId !== noteChatNoteId) return;
|
||||
noteChatLoading = false;
|
||||
|
||||
if (chat?.id) {
|
||||
console.info('[note-chat] open resolved', {
|
||||
noteId: note.id,
|
||||
chatId: chat.id,
|
||||
title: chat.title,
|
||||
hasChatPayload: !!chat.chat
|
||||
});
|
||||
noteChatId = chat.id;
|
||||
noteChats = chats ?? [chat];
|
||||
showNoteChat = true;
|
||||
} else {
|
||||
console.warn('[note-chat] open returned no chat id', { noteId: note.id, chat });
|
||||
}
|
||||
noteChats = chats ?? [];
|
||||
if (noteChats.length > 0) noteChatId = noteChats[0].id;
|
||||
else noteChatDraftKey = `${Date.now()}`;
|
||||
};
|
||||
$: if (note?.id && note.id !== noteChatNoteId) {
|
||||
noteChatNoteId = note.id;
|
||||
loadNoteChat(note.id);
|
||||
}
|
||||
|
||||
const createNoteChat = async () => {
|
||||
if (!note?.id || noteChatLoading) return;
|
||||
|
||||
noteChatId = null;
|
||||
noteChatDraftKey = `${Date.now()}`;
|
||||
showNoteChat = true;
|
||||
noteChatExpanded = true;
|
||||
};
|
||||
|
||||
const createNoteChatOnFirstMessage = async () => {
|
||||
@@ -907,7 +878,6 @@ ${content}
|
||||
|
||||
if (chat?.id) {
|
||||
noteChats = chats ?? [chat, ...noteChats.filter((item) => item.id !== chat.id)];
|
||||
showNoteChat = true;
|
||||
}
|
||||
|
||||
return chat;
|
||||
@@ -936,16 +906,8 @@ ${content}
|
||||
})) ?? [];
|
||||
|
||||
if (noteChatId === chatId) {
|
||||
let nextChat = chats[0];
|
||||
if (!nextChat) {
|
||||
nextChat = await getNoteChatById(localStorage.token, note.id).catch((error) => {
|
||||
console.error('[note-chat] recreate failed after delete', { noteId: note?.id, error });
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
chats = nextChat ? [nextChat] : [];
|
||||
}
|
||||
noteChatId = nextChat?.id ?? null;
|
||||
noteChatId = chats[0]?.id ?? null;
|
||||
if (!noteChatId) noteChatDraftKey = `${Date.now()}`;
|
||||
}
|
||||
|
||||
noteChats = chats;
|
||||
@@ -1293,23 +1255,35 @@ ${content}
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<Tooltip content={$i18n.t('Chat')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="p-1 bg-transparent hover:bg-base-0/5 transition rounded-lg"
|
||||
aria-label={$i18n.t('Chat')}
|
||||
bind:this={noteChatButtonElement}
|
||||
on:click={openNoteChat}
|
||||
{#if commentsEnabled}
|
||||
<Dropdown
|
||||
show={!!currentNoteComments}
|
||||
align="end"
|
||||
maxHeight="min(36rem, calc(100dvh - 6rem))"
|
||||
contentClass="w-[min(24rem,calc(100vw-2rem))] h-[min(36rem,calc(100dvh-6rem))] rounded-2xl border border-base-100 dark:border-base-800 bg-base-0 dark:bg-base-900 shadow-lg overflow-hidden! z-50"
|
||||
onOpenChange={(open) => {
|
||||
if (!open) currentNoteComments = null;
|
||||
else currentNoteComments ??= { resource_type: 'note', resource_id: note.id };
|
||||
}}
|
||||
>
|
||||
<ChatBubbleOval className="size-4" strokeWidth="1.8" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
<CommentButton
|
||||
className="flex items-center justify-center p-1 bg-transparent hover:bg-base-0/5 transition rounded-lg"
|
||||
onComment={(request) => (currentNoteComments = request)}
|
||||
resource={{ resource_type: 'note', resource_id: note.id }}
|
||||
/>
|
||||
<CommentButton
|
||||
className="flex items-center justify-center p-1 bg-transparent hover:bg-base-0/5 transition rounded-lg"
|
||||
onComment={(request) =>
|
||||
(currentNoteComments = currentNoteComments ? null : request)}
|
||||
resource={{ resource_type: 'note', resource_id: note.id }}
|
||||
/>
|
||||
<div slot="content" class="h-full">
|
||||
{#if currentNoteComments}
|
||||
{#key `${$user.id}:${note.id}:${currentNoteComments.comment_id ?? ''}`}
|
||||
<CommentsPanel
|
||||
bind:view={currentNoteComments}
|
||||
onClose={() => (currentNoteComments = null)}
|
||||
/>
|
||||
{/key}
|
||||
{/if}
|
||||
</div>
|
||||
</Dropdown>
|
||||
{/if}
|
||||
|
||||
{#if note?.write_access}
|
||||
<RecordMenu
|
||||
@@ -1539,22 +1513,27 @@ ${content}
|
||||
{#if previousPage}
|
||||
<div
|
||||
role="status"
|
||||
class="flex items-center gap-3 px-4 py-2 text-sm bg-amber-50 dark:bg-amber-950"
|
||||
class="mx-3 mt-2 mb-1 flex items-center gap-3 rounded-xl bg-base-50 px-3 py-1.5 text-xs text-base-600 dark:bg-base-850 dark:text-base-300"
|
||||
>
|
||||
<span class="flex-1"
|
||||
<span class="min-w-0 flex-1"
|
||||
>{$i18n.t(
|
||||
'A page changed elsewhere. Your previous text is available to download.'
|
||||
)}</span
|
||||
>
|
||||
<button
|
||||
class="underline"
|
||||
type="button"
|
||||
class="shrink-0 text-base-900 transition hover:underline dark:text-base-100"
|
||||
on:click={() =>
|
||||
saveAs(
|
||||
new Blob([previousPage.content.md], { type: 'text/markdown' }),
|
||||
`${previousPage.title}.md`
|
||||
)}>{$i18n.t('Download')}</button
|
||||
>
|
||||
<button on:click={() => (previousPage = null)}>{$i18n.t('Dismiss')}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 text-base-500 transition hover:text-base-900 dark:text-base-400 dark:hover:text-base-100"
|
||||
on:click={() => (previousPage = null)}>{$i18n.t('Dismiss')}</button
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex min-h-0 flex-1">
|
||||
@@ -1597,92 +1576,179 @@ ${content}
|
||||
onDownload={(pageId, format) => downloadHandler(format, pageId)}
|
||||
/>
|
||||
</NotePanel>
|
||||
<div
|
||||
class="min-w-0 flex-1 h-full overflow-auto px-3 relative flex flex-col"
|
||||
id="note-content-container"
|
||||
bind:this={noteContent}
|
||||
role="tabpanel"
|
||||
aria-label={activePage?.id === 'main' && activePage.inherit_note_title !== false
|
||||
? note.title || $i18n.t('Untitled')
|
||||
: activePage?.title}
|
||||
>
|
||||
<div class="relative min-w-0 flex-1 h-full flex flex-col">
|
||||
<div
|
||||
use:commentSurface={{
|
||||
resource_type: 'note',
|
||||
resource_id: note.id,
|
||||
target_type: 'note_page',
|
||||
target_id: activePageId,
|
||||
surface_id: activePageId,
|
||||
content_hash: note.write_access
|
||||
? contentHash(noteCommentText(activePage.content))
|
||||
: savedCommentHashes[activePageId],
|
||||
enabled: versionIdx === null,
|
||||
toolbar_id: selectionCommentsEnabled ? `note-${note.id}-formatting` : undefined,
|
||||
prepare: flushActivePage,
|
||||
onComment: (target) =>
|
||||
(currentNoteComments = {
|
||||
resource_type: 'note',
|
||||
resource_id: note.id,
|
||||
...target
|
||||
})
|
||||
}}
|
||||
class="min-w-0 flex-1 h-full overflow-auto px-3 pb-32 relative flex flex-col"
|
||||
id="note-content-container"
|
||||
bind:this={noteContent}
|
||||
role="tabpanel"
|
||||
aria-label={activePage?.id === 'main' && activePage.inherit_note_title !== false
|
||||
? note.title || $i18n.t('Untitled')
|
||||
: activePage?.title}
|
||||
>
|
||||
{#each [activePage] as renderedPage (`${note.id}:${renderedPage.id}:${renderedPage.generation}:${autoFormat}`)}
|
||||
<RichTextInput
|
||||
{autoFormat}
|
||||
bind:this={inputElement}
|
||||
on:editor={(event) => (editor = event.detail)}
|
||||
id={`note-${note.id}-${renderedPage.id}`}
|
||||
className="input-prose-sm ps-4 pe-0.5 pt-2 flex-1 min-h-[12rem]"
|
||||
json={true}
|
||||
bind:value={renderedPage.content.json}
|
||||
html={editorHtml}
|
||||
documentId={activeDocumentId}
|
||||
bind:cursorTarget
|
||||
collaboration={true}
|
||||
socket={$socket}
|
||||
user={$user}
|
||||
dragHandle={true}
|
||||
link={true}
|
||||
image={true}
|
||||
attachments={true}
|
||||
placeholder={$i18n.t('Write something...')}
|
||||
editable={versionIdx === null && note?.write_access}
|
||||
onComment={selectionCommentsEnabled ? commentOnSelection : null}
|
||||
onSelectionUpdate={({ editor }) => {
|
||||
const { from, to } = editor.state.selection;
|
||||
const selectedText = editor.state.doc.textBetween(from, to, ' ');
|
||||
<div
|
||||
use:commentSurface={{
|
||||
resource_type: 'note',
|
||||
resource_id: note.id,
|
||||
target_type: 'note_page',
|
||||
target_id: activePageId,
|
||||
surface_id: activePageId,
|
||||
content_hash: note.write_access
|
||||
? contentHash(noteCommentText(activePage.content))
|
||||
: savedCommentHashes[activePageId],
|
||||
enabled: versionIdx === null,
|
||||
toolbar_id: selectionCommentsEnabled ? `note-${note.id}-formatting` : undefined,
|
||||
prepare: flushActivePage,
|
||||
onComment: (target) =>
|
||||
(currentNoteComments = {
|
||||
resource_type: 'note',
|
||||
resource_id: note.id,
|
||||
...target
|
||||
})
|
||||
}}
|
||||
>
|
||||
{#each [activePage] as renderedPage (`${note.id}:${renderedPage.id}:${renderedPage.generation}:${autoFormat}`)}
|
||||
<RichTextInput
|
||||
{autoFormat}
|
||||
bind:this={inputElement}
|
||||
on:editor={(event) => {
|
||||
editor = event.detail;
|
||||
focusOpenedNote(event.detail);
|
||||
}}
|
||||
id={`note-${note.id}-${renderedPage.id}`}
|
||||
className="input-prose-sm ps-4 pe-0.5 pt-2 flex-1 min-h-[12rem]"
|
||||
json={true}
|
||||
bind:value={renderedPage.content.json}
|
||||
html={editorHtml}
|
||||
documentId={activeDocumentId}
|
||||
bind:cursorTarget
|
||||
collaboration={true}
|
||||
socket={$socket}
|
||||
user={$user}
|
||||
dragHandle={true}
|
||||
link={true}
|
||||
image={true}
|
||||
attachments={true}
|
||||
placeholder={$i18n.t('Write something...')}
|
||||
editable={versionIdx === null && note?.write_access}
|
||||
onComment={selectionCommentsEnabled ? commentOnSelection : null}
|
||||
onSelectionUpdate={({ editor }) => {
|
||||
const { from, to } = editor.state.selection;
|
||||
const selectedText = editor.state.doc.textBetween(from, to, ' ');
|
||||
|
||||
if (selectedText.length === 0) {
|
||||
selectedContent = null;
|
||||
} else {
|
||||
selectedContent = {
|
||||
text: selectedText,
|
||||
from: from,
|
||||
to: to
|
||||
};
|
||||
}
|
||||
}}
|
||||
onChange={(content) => {
|
||||
renderedPage.content.json = content.json;
|
||||
renderedPage.content.html = content.html;
|
||||
renderedPage.content.md = content.md;
|
||||
}}
|
||||
fileHandler={true}
|
||||
onFileDrop={(currentEditor, files, pos) =>
|
||||
inputFilesHandler(files, currentEditor, pos)}
|
||||
onFilePaste={() => {}}
|
||||
on:paste={(event) => {
|
||||
const e = event.detail.event || event;
|
||||
const pasted = Array.from(e.clipboardData?.files ?? []);
|
||||
if (pasted.length) {
|
||||
e.preventDefault();
|
||||
inputFilesHandler(pasted);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{/each}
|
||||
if (selectedText.length === 0) {
|
||||
selectedContent = null;
|
||||
} else {
|
||||
selectedContent = {
|
||||
text: selectedText,
|
||||
from: from,
|
||||
to: to
|
||||
};
|
||||
}
|
||||
}}
|
||||
onChange={(content) => {
|
||||
renderedPage.content.json = content.json;
|
||||
renderedPage.content.html = content.html;
|
||||
renderedPage.content.md = content.md;
|
||||
}}
|
||||
fileHandler={true}
|
||||
onFileDrop={(currentEditor, files, pos) =>
|
||||
inputFilesHandler(files, currentEditor, pos)}
|
||||
onFilePaste={() => {}}
|
||||
on:paste={(event) => {
|
||||
const e = event.detail.event || event;
|
||||
const pasted = Array.from(e.clipboardData?.files ?? []);
|
||||
if (pasted.length) {
|
||||
e.preventDefault();
|
||||
inputFilesHandler(pasted);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{#if note && !noteChatLoading && (noteChatId || noteChatDraftKey)}
|
||||
<!-- The composer keeps its position; expanding only grows the conversation above it. -->
|
||||
<div class="pointer-events-none absolute inset-x-0 bottom-0 z-30 flex flex-col">
|
||||
{#if !noteChatExpanded}
|
||||
<div
|
||||
class="h-6 shrink-0 bg-linear-to-t from-base-0 to-transparent dark:from-base-900"
|
||||
></div>
|
||||
{/if}
|
||||
<div
|
||||
class="flex justify-center {noteChatExpanded
|
||||
? ''
|
||||
: 'pointer-events-auto bg-base-0 dark:bg-base-900'}"
|
||||
>
|
||||
<!-- Side padding lives on the column so the composer keeps its box in both states. -->
|
||||
<div
|
||||
class="pointer-events-auto flex w-full max-w-3xl flex-col rounded-t-3xl border border-b-0 {noteChatExpanded
|
||||
? 'h-[min(60dvh,36rem)] border-base-100/40 bg-base-0 pt-1.5 dark:border-base-800/25 dark:bg-base-900'
|
||||
: 'border-transparent'}"
|
||||
>
|
||||
{#if !noteChatExpanded}
|
||||
<button
|
||||
type="button"
|
||||
class="mb-0.5 ml-3 flex max-w-full items-center gap-1 self-start rounded-lg px-1.5 py-0.5 text-xs text-base-500 transition hover:text-base-800 dark:text-base-400 dark:hover:text-base-100"
|
||||
aria-label={$i18n.t('Expand')}
|
||||
aria-expanded="false"
|
||||
on:click={() => (noteChatExpanded = true)}
|
||||
>
|
||||
<ChevronUp className="size-3 shrink-0" strokeWidth="2" />
|
||||
<span class="truncate"
|
||||
>{noteChats.find((chat) => chat.id === noteChatId)?.title ||
|
||||
$i18n.t('Chat')}</span
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
{#key note.id}
|
||||
<Chat
|
||||
embedded={true}
|
||||
chatIdProp={noteChatId ?? ''}
|
||||
embeddedChats={noteChats}
|
||||
embeddedDraftKey={noteChatDraftKey}
|
||||
suggestedPrompts={noteChatSuggestedPrompts}
|
||||
selectedText={selectedContent?.text ?? ''}
|
||||
notePageId={activePageId}
|
||||
noteFiles={noteAttachmentFiles}
|
||||
embeddedCollapsed={!noteChatExpanded}
|
||||
embeddedInset
|
||||
onCollapseEmbedded={() => (noteChatExpanded = false)}
|
||||
onBeforeNoteSubmit={async () => {
|
||||
noteChatExpanded = true;
|
||||
await flushActivePage();
|
||||
}}
|
||||
onInsertToNote={note?.write_access ? insertHandler : null}
|
||||
onNewEmbeddedChat={createNoteChat}
|
||||
onCreateEmbeddedChat={createNoteChatOnFirstMessage}
|
||||
onSelectEmbeddedChat={(chatId) => {
|
||||
if (!chatId || chatId === noteChatId) return;
|
||||
noteChatId = chatId;
|
||||
noteChatDraftKey = '';
|
||||
}}
|
||||
onDeleteEmbeddedChat={deleteNoteChat}
|
||||
onEmbeddedChatTitle={(chatId, title) => {
|
||||
noteChats = noteChats.map((chat) =>
|
||||
chat.id === chatId
|
||||
? {
|
||||
...chat,
|
||||
title,
|
||||
chat: {
|
||||
...(chat.chat ?? {}),
|
||||
title
|
||||
}
|
||||
}
|
||||
: chat
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1715,90 +1781,4 @@ ${content}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<NotePanel bind:show={showNoteChat} ariaLabel={$i18n.t('Chat')} onClose={closeNotePanel}>
|
||||
<div class="flex items-center justify-between px-2 pt-2 pb-1 shrink-0">
|
||||
<div class="flex gap-1 min-w-0 overflow-x-auto scrollbar-hidden">
|
||||
{#each commentsEnabled ? ['Chat', 'Comments'] : ['Chat'] as tab}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={tab === 'Comments' ? !!currentNoteComments : !currentNoteComments}
|
||||
class="inline-flex items-center justify-center gap-1 px-2.5 py-0.5 text-sm rounded-lg transition whitespace-nowrap {(
|
||||
tab === 'Comments' ? !!currentNoteComments : !currentNoteComments
|
||||
)
|
||||
? 'bg-base-100/40 dark:bg-base-800/25 font-normal text-base-700 dark:text-base-200'
|
||||
: 'text-base-500 dark:text-base-400 hover:bg-base-100/30 dark:hover:bg-base-800/20 hover:text-base-600 dark:hover:text-base-300'}"
|
||||
on:click={() =>
|
||||
tab === 'Comments'
|
||||
? (currentNoteComments = { resource_type: 'note', resource_id: note.id })
|
||||
: openNoteChat()}
|
||||
>
|
||||
{$i18n.t(tab)}
|
||||
{#if tab === 'Comments' && noteCommentCount > 0}<span
|
||||
class="text-[0.8125rem] leading-none text-base-400/70 dark:text-base-500/70"
|
||||
>{noteCommentCount}</span
|
||||
>{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Close')}
|
||||
class="py-1 px-0 text-base-500 hover:text-base-900 dark:text-base-400 dark:hover:text-base-100"
|
||||
on:click={closeNotePanel}><XMark className="size-4" /></button
|
||||
>
|
||||
</div>
|
||||
{#if currentNoteComments}
|
||||
<div class="flex-1 min-h-0">
|
||||
{#key `${$user.id}:${note.id}:${currentNoteComments.comment_id ?? ''}`}
|
||||
<CommentsPanel
|
||||
embedded
|
||||
bind:view={currentNoteComments}
|
||||
onCountChange={(count) => (noteCommentCount = count)}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex-1 min-h-0" class:hidden={!!currentNoteComments}>
|
||||
{#if noteChatLoading}
|
||||
<div class="flex h-full items-center justify-center">
|
||||
<Spinner className="size-5" />
|
||||
</div>
|
||||
{:else if note && (noteChatId || noteChatDraftKey)}
|
||||
<Chat
|
||||
embedded={true}
|
||||
chatIdProp={noteChatId ?? ''}
|
||||
embeddedChats={noteChats}
|
||||
embeddedDraftKey={noteChatDraftKey}
|
||||
suggestedPrompts={noteChatSuggestedPrompts}
|
||||
selectedText={selectedContent?.text ?? ''}
|
||||
notePageId={activePageId}
|
||||
noteFiles={noteAttachmentFiles}
|
||||
onBeforeNoteSubmit={flushActivePage}
|
||||
onInsertToNote={note?.write_access ? insertHandler : null}
|
||||
onNewEmbeddedChat={createNoteChat}
|
||||
onCreateEmbeddedChat={createNoteChatOnFirstMessage}
|
||||
onSelectEmbeddedChat={(chatId) => {
|
||||
if (!chatId || chatId === noteChatId) return;
|
||||
noteChatId = chatId;
|
||||
noteChatDraftKey = '';
|
||||
}}
|
||||
onDeleteEmbeddedChat={deleteNoteChat}
|
||||
onEmbeddedChatTitle={(chatId, title) => {
|
||||
noteChats = noteChats.map((chat) =>
|
||||
chat.id === chatId
|
||||
? {
|
||||
...chat,
|
||||
title,
|
||||
chat: {
|
||||
...(chat.chat ?? {}),
|
||||
title
|
||||
}
|
||||
}
|
||||
: chat
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</NotePanel>
|
||||
</div>
|
||||
@@ -54,7 +54,7 @@
|
||||
>
|
||||
<div class="flex-1 max-h-full overflow-y-auto">
|
||||
{#if loaded}
|
||||
<div class="pb-1 px-1.5 md:px-2.5">
|
||||
<div class="h-full pb-1 px-1.5 md:px-2.5">
|
||||
<Notes />
|
||||
</div>
|
||||
{:else}
|
||||
|
||||
Reference in new issue
Block a user