From 7f03b6e778374aca1eca4f8c6f29cbf8a8b1aeda Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 28 Oct 2026 10:25:04 +0900 Subject: [PATCH] refac --- backend/open_webui/models/folders.py | 1 + src/app.css | 15 +++--- .../common/RichTextInput/Collaboration.ts | 52 +++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/models/folders.py b/backend/open_webui/models/folders.py index 2349cfb491..828119440d 100644 --- a/backend/open_webui/models/folders.py +++ b/backend/open_webui/models/folders.py @@ -54,6 +54,7 @@ class FolderMetadataResponse(BaseModel): class FolderNameIdResponse(BaseModel): id: str + user_id: str name: str meta: Optional[FolderMetadataResponse] = None parent_id: Optional[str] = None diff --git a/src/app.css b/src/app.css index 07e9631d16..b7ba3c0155 100644 --- a/src/app.css +++ b/src/app.css @@ -757,10 +757,6 @@ html.high-contrast.dark .ProseMirror p.is-editor-empty:first-child::before { @apply bg-transparent p-0 m-0 text-inherit; } -/* this is a rough fix for the first cursor position when the first paragraph is empty */ -.ProseMirror > .ProseMirror-yjs-cursor:first-child { - margin-top: 1rem; -} /* This gives the remote user caret. The colors are automatically overwritten*/ .ProseMirror-yjs-cursor { position: relative; @@ -773,17 +769,20 @@ html.high-contrast.dark .ProseMirror p.is-editor-empty:first-child::before { pointer-events: none; } /* This renders the username above the caret */ -.ProseMirror-yjs-cursor > div { - position: absolute; - top: -1.05em; - left: -1px; +.ProseMirror-yjs-cursor-label { font-size: 0.8125rem; + line-height: 1.25; background-color: rgb(250, 129, 0); user-select: none; color: white; padding-left: 0.125rem; padding-right: 0.125rem; white-space: nowrap; + pointer-events: none; +} + +.ProseMirror-yjs-cursor-label[data-popper-reference-hidden] { + opacity: 0; } body { diff --git a/src/lib/components/common/RichTextInput/Collaboration.ts b/src/lib/components/common/RichTextInput/Collaboration.ts index 713ef6056e..ab5fa87b7c 100644 --- a/src/lib/components/common/RichTextInput/Collaboration.ts +++ b/src/lib/components/common/RichTextInput/Collaboration.ts @@ -16,6 +16,7 @@ import { createNodeFromContent, Editor, Extension } from '@tiptap/core'; import { keymap } from 'prosemirror-keymap'; import { Plugin } from 'prosemirror-state'; import { tick } from 'svelte'; +import tippy, { type Instance } from 'tippy.js'; const USER_COLORS = [ '#FF6B6B', @@ -116,6 +117,57 @@ export class SocketIOCollaborationProvider { tr.setMeta('preventAutolink', true); } return true; + }, + view: (view) => { + const labels = new Map(); + const update = () => { + for (const [cursor, label] of labels) { + if (!view.dom.contains(cursor)) { + label.destroy(); + labels.delete(cursor); + } + } + for (const cursor of view.dom.querySelectorAll( + '.ProseMirror-yjs-cursor' + )) { + if (!labels.has(cursor)) { + const label = cursor.querySelector('div'); + if (!label) continue; + // Float above the caret without being clipped by the editor's scroll area. + label.remove(); + label.className = 'ProseMirror-yjs-cursor-label'; + labels.set( + cursor, + tippy(cursor, { + appendTo: () => document.body, + render: () => ({ popper: label }), + trigger: 'manual', + showOnCreate: true, + hideOnClick: false, + animation: false, + placement: 'top-start', + offset: [0, 2], + zIndex: 30, + popperOptions: { + strategy: 'fixed', + modifiers: [{ name: 'flip', enabled: false }] + } + }) + ); + } + labels.get(cursor)?.popperInstance?.forceUpdate(); + } + }; + update(); + const resizeObserver = new ResizeObserver(update); + resizeObserver.observe(view.dom); + return { + update, + destroy: () => { + resizeObserver.disconnect(); + labels.forEach((label) => label.destroy()); + } + }; } }), ySyncPlugin(yXmlFragment),