diff --git a/web/app/assets/css/main.css b/web/app/assets/css/main.css index ebe4efb..1a0a5ca 100644 --- a/web/app/assets/css/main.css +++ b/web/app/assets/css/main.css @@ -1117,13 +1117,50 @@ button { bottom: var(--sp-2); } +.pane-resizer { + flex: 0 0 var(--sp-2); + position: relative; + cursor: col-resize; + touch-action: none; + background: transparent; +} + +.pane-resizer::before { + content: ""; + position: absolute; + top: 0; + bottom: 0; + left: calc(50% - 0.5px); + width: 1px; + background: var(--border); + transition: background-color 120ms ease, width 120ms ease, left 120ms ease; +} + +.pane-resizer:hover::before, +.pane-resizer:focus-visible::before, +body.pane-resizing .pane-resizer::before { + left: calc(50% - 1px); + width: 2px; + background: var(--accent); +} + +.pane-resizer:focus-visible { + outline: 2px solid var(--accent); + outline-offset: -2px; +} + +body.pane-resizing, +body.pane-resizing * { + cursor: col-resize !important; + user-select: none !important; +} + .right-pane { - flex: 0 0 44%; + flex: 0 0 var(--pane-width, 44%); min-width: 380px; display: flex; flex-direction: column; min-height: 0; - border-left: 1px solid var(--border); background: var(--surface); container-type: inline-size; } @@ -1614,6 +1651,10 @@ button { } @media (max-width: 1099px) { + .pane-resizer { + display: none; + } + .right-pane { position: fixed; top: 0; @@ -1630,6 +1671,12 @@ button { } } +@media (min-width: 1100px) { + .chat-column { + min-width: 420px; + } +} + @container (max-width: 430px) { .files { grid-template-columns: 1fr; diff --git a/web/app/pages/room/[id].vue b/web/app/pages/room/[id].vue index 3a4e934..6900fae 100644 --- a/web/app/pages/room/[id].vue +++ b/web/app/pages/room/[id].vue @@ -59,6 +59,26 @@ const paneOpen = ref(typeof window === 'undefined' ? true : !window.matchMedia(' const inviteOpen = ref(false) const settingsOpen = ref(false) +const PANE_WIDTH_KEY = 'together.pane-width' +const DEFAULT_PANE_PERCENT = 44 +const PANE_MIN_WIDTH = 380 +const CHAT_MIN_WIDTH = 420 +const DIVIDER_WIDTH = 8 + +const roomBody = ref(null) +const paneWidth = ref(null) +const paneBodyWidth = ref(0) +let paneBodyObserver: ResizeObserver | null = null + +type PaneDrag = { + pointerId: number + startX: number + startWidth: number + moved: boolean +} + +let paneDrag: PaneDrag | null = null + const seenMessages = new Set() const seenNotices = new Set() let lastDurable = 0 @@ -93,6 +113,44 @@ const memberById = computed(() => { return map }) +const paneMaxWidth = computed(() => { + const total = paneBodyWidth.value + if (!total) return PANE_MIN_WIDTH + return Math.max(PANE_MIN_WIDTH, total - CHAT_MIN_WIDTH - DIVIDER_WIDTH) +}) + +function clampPaneWidth(width: number): number { + const rounded = Math.round(width) + if (!paneBodyWidth.value) return Math.max(rounded, PANE_MIN_WIDTH) + return Math.min(Math.max(rounded, PANE_MIN_WIDTH), paneMaxWidth.value) +} + +const effectivePaneWidth = computed(() => { + if (paneWidth.value === null) return null + return clampPaneWidth(paneWidth.value) +}) + +const paneStyle = computed | undefined>(() => { + const width = effectivePaneWidth.value + return width === null ? undefined : { '--pane-width': `${width}px` } +}) + +function panePercentFor(width: number): number { + const total = paneBodyWidth.value + if (!total) return DEFAULT_PANE_PERCENT + return Math.round((width / total) * 100) +} + +const paneValue = computed(() => { + const total = paneBodyWidth.value + if (!total) return DEFAULT_PANE_PERCENT + const width = effectivePaneWidth.value ?? (total * DEFAULT_PANE_PERCENT) / 100 + return panePercentFor(width) +}) + +const paneMinPercent = computed(() => (paneBodyWidth.value ? panePercentFor(PANE_MIN_WIDTH) : 25)) +const paneMaxPercent = computed(() => (paneBodyWidth.value ? panePercentFor(paneMaxWidth.value) : 75)) + const timeline = computed(() => { const entries: TimelineEntry[] = [] for (const message of messages.value) { @@ -446,6 +504,86 @@ function onTyping(active: boolean) { sendPresenceState(active) } +function readPaneWidth(): number | null { + try { + const stored = window.localStorage.getItem(PANE_WIDTH_KEY) + if (!stored) return null + const value = Number.parseInt(stored, 10) + return Number.isFinite(value) && value > 0 ? value : null + } catch { + return null + } +} + +function savePaneWidth(width: number) { + try { + window.localStorage.setItem(PANE_WIDTH_KEY, String(Math.round(width))) + } catch { + // A browser that refuses storage keeps the width for this visit. + } +} + +function currentPaneElement(): HTMLElement | null { + return roomBody.value?.querySelector('.right-pane') ?? null +} + +function onPaneResizeStart(event: PointerEvent) { + if (event.button !== 0) return + const pane = currentPaneElement() + if (!pane) return + event.preventDefault() + paneDrag = { + pointerId: event.pointerId, + startX: event.clientX, + startWidth: pane.getBoundingClientRect().width, + moved: false, + } + ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId) + document.body.classList.add('pane-resizing') +} + +function onPaneResizeMove(event: PointerEvent) { + if (!paneDrag || event.pointerId !== paneDrag.pointerId) return + const next = paneDrag.startWidth + paneDrag.startX - event.clientX + if (Math.abs(event.clientX - paneDrag.startX) >= 1) paneDrag.moved = true + paneWidth.value = clampPaneWidth(next) +} + +function endPaneResize() { + if (!paneDrag) return + const moved = paneDrag.moved + paneDrag = null + document.body.classList.remove('pane-resizing') + if (moved && paneWidth.value !== null) savePaneWidth(paneWidth.value) +} + +function onPaneResizeKey(event: KeyboardEvent) { + const pane = currentPaneElement() + const current = pane?.getBoundingClientRect().width ?? effectivePaneWidth.value ?? 0 + const step = event.shiftKey ? 64 : 16 + let next: number + switch (event.key) { + case 'ArrowLeft': + next = current + step + break + case 'ArrowRight': + next = current - step + break + case 'Home': + next = PANE_MIN_WIDTH + break + case 'End': + next = paneMaxWidth.value + break + default: + return + } + event.preventDefault() + const clamped = clampPaneWidth(next) + paneWidth.value = clamped + savePaneWidth(clamped) +} + function colorFor(message: Message): string | null { if (!message.author_id) return null return memberById.value.get(message.author_id)?.color ?? null @@ -573,11 +711,19 @@ async function onArchived() { } onMounted(async () => { + paneWidth.value = readPaneWidth() await loadDetail() await loadMessages() if (!detailError.value) { await nextTick() + if (roomBody.value) { + paneBodyWidth.value = roomBody.value.clientWidth + paneBodyObserver = new ResizeObserver(() => { + paneBodyWidth.value = roomBody.value?.clientWidth ?? 0 + }) + paneBodyObserver.observe(roomBody.value) + } scrollToBottom() window.requestAnimationFrame(() => { if (stick.value) scrollToBottom() @@ -598,6 +744,9 @@ onMounted(async () => { onBeforeUnmount(() => { disposed = true eventGeneration += 1 + paneBodyObserver?.disconnect() + paneBodyObserver = null + document.body.classList.remove('pane-resizing') chatObserver?.disconnect() chatObserver = null eventController?.abort() @@ -632,7 +781,7 @@ onBeforeUnmount(() => { @toggle-pane="paneOpen = !paneOpen" /> -
+
@@ -690,6 +839,26 @@ onBeforeUnmount(() => {
+ +