feat(web): resize the file list in the Files pane
ci / checks (push) Successful in 1m58s
ci / test (push) Successful in 2m1s
ci / chart (push) Successful in 6s
ci / web (push) Successful in 16s
ci / docker (push) Successful in 1m45s
ci / publish-edge-image (push) Successful in 11s
ci / publish-edge-chart (push) Successful in 4s
ci / checks (push) Successful in 1m58s
ci / test (push) Successful in 2m1s
ci / chart (push) Successful in 6s
ci / web (push) Successful in 16s
ci / docker (push) Successful in 1m45s
ci / publish-edge-image (push) Successful in 11s
ci / publish-edge-chart (push) Successful in 4s
The split between the file browser and viewer was fixed. A separator now drags it, with a 140px minimum and a 55% cap, and the arrow keys, Home, and End do the same. The width survives a reload. When the pane stacks the list above the viewer, the separator turns horizontal and saves a separate height.
This commit is contained in:
1 parent
ca333509a2
commit
d4aac727ad
2 files changed
+264
-8
No files matched your search
@@ -1537,17 +1537,60 @@ body.pane-resizing * {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(140px, 34%) 1fr;
|
||||
grid-template-columns: clamp(140px, var(--files-browser-width, 34%), 55%) var(--sp-2) minmax(0, 1fr);
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.files-browser {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
border-right: 1px solid var(--border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.files-resizer {
|
||||
position: relative;
|
||||
cursor: col-resize;
|
||||
touch-action: none;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.files-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, height 120ms ease, top 120ms ease;
|
||||
}
|
||||
|
||||
.files-resizer:hover::before,
|
||||
.files-resizer:focus-visible::before,
|
||||
body.files-resizing-x .files-resizer::before {
|
||||
left: calc(50% - 1px);
|
||||
width: 2px;
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.files-resizer:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
body.files-resizing-x,
|
||||
body.files-resizing-x * {
|
||||
cursor: col-resize !important;
|
||||
user-select: none !important;
|
||||
}
|
||||
|
||||
body.files-resizing-y,
|
||||
body.files-resizing-y * {
|
||||
cursor: row-resize !important;
|
||||
user-select: none !important;
|
||||
}
|
||||
|
||||
.crumbs {
|
||||
flex: 0 0 auto;
|
||||
padding: var(--sp-2);
|
||||
@@ -2001,13 +2044,37 @@ body.pane-resizing * {
|
||||
|
||||
@container (max-width: 430px) {
|
||||
.files {
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-rows: minmax(120px, 38%) 1fr;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: clamp(120px, var(--files-browser-height, 38%), 60%) var(--sp-2) minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.files-browser {
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.files-resizer {
|
||||
cursor: row-resize;
|
||||
}
|
||||
|
||||
.files-resizer::before {
|
||||
top: calc(50% - 0.5px);
|
||||
bottom: auto;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: auto;
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
.files-resizer:hover::before,
|
||||
.files-resizer:focus-visible::before,
|
||||
body.files-resizing-y .files-resizer::before {
|
||||
top: calc(50% - 1px);
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: auto;
|
||||
height: 2px;
|
||||
background: var(--accent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { ChevronLeft, ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
|
||||
import type { FileContentResponse, FileEntry, FileListResponse, GitSummaryResponse } from '~/types'
|
||||
import { apiErrorMessage } from '~/utils/errors'
|
||||
@@ -8,11 +8,40 @@ import { formatSize } from '~/utils/format'
|
||||
const props = defineProps<{ roomId: string; roomName: string }>()
|
||||
const api = useApi()
|
||||
|
||||
const FILES_WIDTH_KEY = 'together.files-list-width'
|
||||
const FILES_HEIGHT_KEY = 'together.files-list-height'
|
||||
const FILES_MIN_WIDTH = 140
|
||||
const FILES_MIN_HEIGHT = 120
|
||||
const FILES_DEFAULT_WIDTH_PERCENT = 0.34
|
||||
const FILES_DEFAULT_HEIGHT_PERCENT = 0.38
|
||||
const FILES_MAX_WIDTH_PERCENT = 0.55
|
||||
const FILES_MAX_HEIGHT_PERCENT = 0.6
|
||||
const FILES_STACKED_WIDTH = 430
|
||||
|
||||
const path = ref('.')
|
||||
const entries = ref<FileEntry[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const filesEl = ref<HTMLElement | null>(null)
|
||||
const browserEl = ref<HTMLElement | null>(null)
|
||||
const filesWidth = ref(0)
|
||||
const filesHeight = ref(0)
|
||||
const listWidth = ref<number | null>(null)
|
||||
const listHeight = ref<number | null>(null)
|
||||
let filesObserver: ResizeObserver | null = null
|
||||
|
||||
type FilesDrag = {
|
||||
pointerId: number
|
||||
startX: number
|
||||
startY: number
|
||||
startSize: number
|
||||
narrow: boolean
|
||||
moved: boolean
|
||||
}
|
||||
|
||||
let filesDrag: FilesDrag | null = null
|
||||
|
||||
const selected = ref<FileEntry | null>(null)
|
||||
const file = ref<FileContentResponse | null>(null)
|
||||
const fileLoading = ref(false)
|
||||
@@ -25,6 +54,129 @@ const gitError = ref('')
|
||||
let dirRequest = 0
|
||||
let fileRequest = 0
|
||||
|
||||
const narrow = computed(() => filesWidth.value > 0 && filesWidth.value <= FILES_STACKED_WIDTH)
|
||||
|
||||
function fileListRange(stacked: boolean): { min: number; max: number } {
|
||||
const total = stacked ? filesHeight.value : filesWidth.value
|
||||
const ratio = stacked ? FILES_MAX_HEIGHT_PERCENT : FILES_MAX_WIDTH_PERCENT
|
||||
const minimum = stacked ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH
|
||||
return { min: minimum, max: Math.max(minimum, Math.floor(total * ratio)) }
|
||||
}
|
||||
|
||||
function clampFileListSize(size: number, stacked = narrow.value): number {
|
||||
const range = fileListRange(stacked)
|
||||
return Math.min(Math.max(Math.round(size), range.min), range.max)
|
||||
}
|
||||
|
||||
const fileListMax = computed(() => fileListRange(narrow.value).max)
|
||||
|
||||
const fileListValue = computed(() => {
|
||||
const stored = narrow.value ? listHeight.value : listWidth.value
|
||||
if (stored !== null) return clampFileListSize(stored)
|
||||
const total = narrow.value ? filesHeight.value : filesWidth.value
|
||||
const ratio = narrow.value ? FILES_DEFAULT_HEIGHT_PERCENT : FILES_DEFAULT_WIDTH_PERCENT
|
||||
const minimum = narrow.value ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH
|
||||
return clampFileListSize(Math.round(total * ratio) || minimum)
|
||||
})
|
||||
|
||||
const filesStyle = computed(() => {
|
||||
const style: Record<string, string> = {}
|
||||
if (narrow.value) {
|
||||
if (listHeight.value !== null) {
|
||||
style['--files-browser-height'] = `${clampFileListSize(listHeight.value)}px`
|
||||
}
|
||||
} else if (listWidth.value !== null) {
|
||||
style['--files-browser-width'] = `${clampFileListSize(listWidth.value)}px`
|
||||
}
|
||||
return Object.keys(style).length > 0 ? style : undefined
|
||||
})
|
||||
|
||||
function readSize(key: string): number | null {
|
||||
if (typeof window === 'undefined') return null
|
||||
try {
|
||||
const raw = window.localStorage.getItem(key)
|
||||
if (!raw) return null
|
||||
const value = Number.parseInt(raw, 10)
|
||||
return Number.isFinite(value) && value > 0 ? value : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function saveSize(key: string, size: number) {
|
||||
try {
|
||||
window.localStorage.setItem(key, String(Math.round(size)))
|
||||
} catch {
|
||||
// A browser that refuses storage keeps the size for this visit.
|
||||
}
|
||||
}
|
||||
|
||||
function onFilesResizeStart(event: PointerEvent) {
|
||||
if (event.button !== 0) return
|
||||
const browser = browserEl.value
|
||||
const container = filesEl.value
|
||||
if (!browser || !container) return
|
||||
event.preventDefault()
|
||||
filesWidth.value = container.clientWidth
|
||||
filesHeight.value = container.clientHeight
|
||||
const isNarrow = narrow.value
|
||||
const rect = browser.getBoundingClientRect()
|
||||
filesDrag = {
|
||||
pointerId: event.pointerId,
|
||||
startX: event.clientX,
|
||||
startY: event.clientY,
|
||||
startSize: isNarrow ? rect.height : rect.width,
|
||||
narrow: isNarrow,
|
||||
moved: false,
|
||||
}
|
||||
;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)
|
||||
document.body.classList.add(isNarrow ? 'files-resizing-y' : 'files-resizing-x')
|
||||
}
|
||||
|
||||
function onFilesResizeMove(event: PointerEvent) {
|
||||
if (!filesDrag || event.pointerId !== filesDrag.pointerId) return
|
||||
const delta = filesDrag.narrow ? event.clientY - filesDrag.startY : event.clientX - filesDrag.startX
|
||||
if (Math.abs(delta) >= 1) filesDrag.moved = true
|
||||
const next = clampFileListSize(filesDrag.startSize + delta, filesDrag.narrow)
|
||||
if (filesDrag.narrow) listHeight.value = next
|
||||
else listWidth.value = next
|
||||
}
|
||||
|
||||
function endFilesResize() {
|
||||
if (!filesDrag) return
|
||||
const { moved, narrow: wasNarrow } = filesDrag
|
||||
filesDrag = null
|
||||
document.body.classList.remove('files-resizing-x', 'files-resizing-y')
|
||||
if (!moved) return
|
||||
if (wasNarrow) {
|
||||
if (listHeight.value !== null) saveSize(FILES_HEIGHT_KEY, listHeight.value)
|
||||
} else if (listWidth.value !== null) {
|
||||
saveSize(FILES_WIDTH_KEY, listWidth.value)
|
||||
}
|
||||
}
|
||||
|
||||
function onFilesResizeKey(event: KeyboardEvent) {
|
||||
const isNarrow = narrow.value
|
||||
const browser = browserEl.value
|
||||
const current = isNarrow
|
||||
? (browser?.getBoundingClientRect().height ?? fileListValue.value)
|
||||
: (browser?.getBoundingClientRect().width ?? fileListValue.value)
|
||||
const step = event.shiftKey ? 64 : 16
|
||||
const decrease = isNarrow ? 'ArrowUp' : 'ArrowLeft'
|
||||
const increase = isNarrow ? 'ArrowDown' : 'ArrowRight'
|
||||
let next: number
|
||||
if (event.key === decrease) next = current - step
|
||||
else if (event.key === increase) next = current + step
|
||||
else if (event.key === 'Home') next = isNarrow ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH
|
||||
else if (event.key === 'End') next = fileListMax.value
|
||||
else return
|
||||
event.preventDefault()
|
||||
const clamped = clampFileListSize(next, isNarrow)
|
||||
if (isNarrow) listHeight.value = clamped
|
||||
else listWidth.value = clamped
|
||||
saveSize(isNarrow ? FILES_HEIGHT_KEY : FILES_WIDTH_KEY, clamped)
|
||||
}
|
||||
|
||||
const segments = computed(() => (path.value === '.' ? [] : path.value.split('/').filter(Boolean)))
|
||||
const hasParent = computed(() => segments.value.length > 0)
|
||||
|
||||
@@ -103,15 +255,33 @@ async function loadGit() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
listWidth.value = readSize(FILES_WIDTH_KEY)
|
||||
listHeight.value = readSize(FILES_HEIGHT_KEY)
|
||||
const element = filesEl.value
|
||||
if (element) {
|
||||
filesWidth.value = element.clientWidth
|
||||
filesHeight.value = element.clientHeight
|
||||
filesObserver = new ResizeObserver(() => {
|
||||
filesWidth.value = filesEl.value?.clientWidth ?? 0
|
||||
filesHeight.value = filesEl.value?.clientHeight ?? 0
|
||||
})
|
||||
filesObserver.observe(element)
|
||||
}
|
||||
void loadDir('')
|
||||
void loadGit()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
filesObserver?.disconnect()
|
||||
filesObserver = null
|
||||
document.body.classList.remove('files-resizing-x', 'files-resizing-y')
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="files-pane">
|
||||
<div class="files">
|
||||
<div class="files-browser">
|
||||
<div ref="filesEl" class="files" :style="filesStyle">
|
||||
<div ref="browserEl" class="files-browser">
|
||||
<div class="crumbs">
|
||||
<button v-if="hasParent" type="button" class="crumb-back" @click="goBack">
|
||||
<ChevronLeft :size="12" aria-hidden="true" />
|
||||
@@ -152,6 +322,25 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="files-resizer"
|
||||
role="separator"
|
||||
:aria-orientation="narrow ? 'horizontal' : 'vertical'"
|
||||
aria-label="Resize file list"
|
||||
:aria-valuemin="narrow ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH"
|
||||
:aria-valuemax="fileListMax"
|
||||
:aria-valuenow="fileListValue"
|
||||
:aria-valuetext="`${fileListValue} pixels`"
|
||||
title="Drag to resize. Arrow keys also work."
|
||||
tabindex="0"
|
||||
@pointerdown="onFilesResizeStart"
|
||||
@pointermove="onFilesResizeMove"
|
||||
@pointerup="endFilesResize"
|
||||
@pointercancel="endFilesResize"
|
||||
@lostpointercapture="endFilesResize"
|
||||
@keydown="onFilesResizeKey"
|
||||
></div>
|
||||
|
||||
<div class="files-viewer">
|
||||
<template v-if="selected">
|
||||
<div class="viewer-head">
|
||||
|
||||
Reference in new issue
Block a user