feat(web): expand folders in place in the file browser
ci / checks (push) Successful in 53s
ci / test (push) Successful in 56s
ci / chart (push) Successful in 4s
ci / web (push) Successful in 18s
ci / docker (push) Successful in 10s
ci / publish-edge-image (push) Successful in 9s
ci / publish-edge-chart (push) Successful in 3s
ci / checks (push) Successful in 53s
ci / test (push) Successful in 56s
ci / chart (push) Successful in 4s
ci / web (push) Successful in 18s
ci / docker (push) Successful in 10s
ci / publish-edge-image (push) Successful in 9s
ci / publish-edge-chart (push) Successful in 3s
Opening a folder replaced the root listing, so every step inward lost the way back and the tree above it. A folder now opens under its parent, nested folders open under theirs, and the root stays visible. Each folder is read again when it is expanded, so files a turn added or removed show up the next time the folder opens. The size column hides below 260px of list width, where the indent leaves no room for both a name and a size.
This commit is contained in:
1 parent
b5babb682e
commit
7d98b04d63
2 files changed
+139
-101
No files matched your search
+43
-37
@@ -1684,6 +1684,7 @@ body.pane-resizing * {
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
container-type: inline-size;
|
||||
}
|
||||
|
||||
.files-resizer {
|
||||
@@ -1729,50 +1730,14 @@ body.files-resizing-y * {
|
||||
user-select: none !important;
|
||||
}
|
||||
|
||||
.crumbs {
|
||||
.tree-head {
|
||||
flex: 0 0 auto;
|
||||
padding: var(--sp-2);
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--sp-1);
|
||||
}
|
||||
|
||||
.crumbs-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-1);
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.crumb {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
color: var(--muted);
|
||||
font-size: var(--fs-small);
|
||||
line-height: var(--lh-body);
|
||||
overflow-wrap: anywhere;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.crumb:hover {
|
||||
color: var(--text);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.crumb-back {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-1);
|
||||
align-self: flex-start;
|
||||
color: var(--muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.file-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
@@ -1787,6 +1752,7 @@ body.files-resizing-y * {
|
||||
align-items: center;
|
||||
gap: var(--sp-1);
|
||||
padding: var(--sp-1) var(--sp-2);
|
||||
padding-left: calc(var(--sp-2) + var(--tree-depth, 0) * var(--sp-3));
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--r-control);
|
||||
background: transparent;
|
||||
@@ -1817,6 +1783,42 @@ body.files-resizing-y * {
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
.tree-caret {
|
||||
flex: 0 0 auto;
|
||||
color: var(--faint);
|
||||
transition: transform 120ms ease;
|
||||
}
|
||||
|
||||
.tree-caret.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.tree-caret-gap {
|
||||
flex: 0 0 auto;
|
||||
width: 14px;
|
||||
}
|
||||
|
||||
.tree-note {
|
||||
margin: 0;
|
||||
padding: var(--sp-1) var(--sp-2);
|
||||
padding-left: calc(var(--sp-2) + var(--tree-depth, 0) * var(--sp-3) + var(--sp-6));
|
||||
color: var(--faint);
|
||||
font-size: var(--fs-small);
|
||||
line-height: var(--lh-body);
|
||||
}
|
||||
|
||||
.tree-note.error {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
/* In a narrow list the name matters more than the size, and the indent
|
||||
for nested rows leaves no room for both. */
|
||||
@container (max-width: 260px) {
|
||||
.file-row-size {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.files-viewer {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
@@ -2543,4 +2545,8 @@ details:not([open]) > *:not(summary) {
|
||||
.sidebar {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.tree-caret {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { ChevronLeft, ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
import { ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
|
||||
import type { FileContentResponse, FileEntry, FileListResponse, GitSummaryResponse } from '~/types'
|
||||
import { apiErrorMessage } from '~/utils/errors'
|
||||
import { formatSize } from '~/utils/format'
|
||||
@@ -18,10 +18,16 @@ 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('')
|
||||
type DirState = { loading: boolean; error: string; entries: FileEntry[] }
|
||||
|
||||
type TreeRow =
|
||||
| { kind: 'entry'; key: string; entry: FileEntry; depth: number }
|
||||
| { kind: 'note'; key: string; text: string; depth: number; error: boolean }
|
||||
|
||||
const dirs = reactive(new Map<string, DirState>())
|
||||
const expanded = reactive(new Set<string>())
|
||||
const dirTokens = new Map<string, number>()
|
||||
let dirSeq = 0
|
||||
|
||||
const filesEl = ref<HTMLElement | null>(null)
|
||||
const browserEl = ref<HTMLElement | null>(null)
|
||||
@@ -51,7 +57,6 @@ const git = ref<GitSummaryResponse | null>(null)
|
||||
const gitLoading = ref(false)
|
||||
const gitError = ref('')
|
||||
|
||||
let dirRequest = 0
|
||||
let fileRequest = 0
|
||||
|
||||
const narrow = computed(() => filesWidth.value > 0 && filesWidth.value <= FILES_STACKED_WIDTH)
|
||||
@@ -177,8 +182,38 @@ function onFilesResizeKey(event: KeyboardEvent) {
|
||||
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)
|
||||
// The visible rows: the root's entries, then the entries of every
|
||||
// expanded folder under it, each one a level deeper.
|
||||
const rows = computed<TreeRow[]>(() => {
|
||||
const out: TreeRow[] = []
|
||||
const walk = (dir: string, depth: number) => {
|
||||
const state = dirs.get(dir)
|
||||
if (!state) return
|
||||
if (state.loading) {
|
||||
out.push({ kind: 'note', key: `${dir}:loading`, text: 'Loading files.', depth, error: false })
|
||||
return
|
||||
}
|
||||
if (state.error) {
|
||||
out.push({ kind: 'note', key: `${dir}:error`, text: state.error, depth, error: true })
|
||||
return
|
||||
}
|
||||
if (state.entries.length === 0) {
|
||||
const text = dir === '' ? 'The workspace is empty.' : 'This folder is empty.'
|
||||
out.push({ kind: 'note', key: `${dir}:empty`, text, depth, error: false })
|
||||
return
|
||||
}
|
||||
for (const entry of state.entries) {
|
||||
out.push({ kind: 'entry', key: entry.path, entry, depth })
|
||||
if (entry.kind === 'dir' && expanded.has(entry.path)) walk(entry.path, depth + 1)
|
||||
}
|
||||
}
|
||||
walk('', 0)
|
||||
return out
|
||||
})
|
||||
|
||||
function indent(depth: number) {
|
||||
return { '--tree-depth': String(depth) }
|
||||
}
|
||||
|
||||
const lineNumbers = computed(() => {
|
||||
const content = file.value?.content ?? ''
|
||||
@@ -186,25 +221,24 @@ const lineNumbers = computed(() => {
|
||||
return Array.from({ length: count }, (_, index) => index + 1).join('\n')
|
||||
})
|
||||
|
||||
function crumbPath(index: number) {
|
||||
return segments.value.slice(0, index + 1).join('/')
|
||||
}
|
||||
|
||||
// Expanding a folder reads it again, so a file a turn added or removed
|
||||
// shows up the next time the folder is opened.
|
||||
async function loadDir(target: string) {
|
||||
const request = ++dirRequest
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
const request = ++dirSeq
|
||||
dirTokens.set(target, request)
|
||||
const previous = dirs.get(target)
|
||||
dirs.set(target, { loading: true, error: '', entries: previous?.entries ?? [] })
|
||||
try {
|
||||
const response = await api.get<FileListResponse>(`/rooms/${props.roomId}/files`, { path: target })
|
||||
if (request !== dirRequest) return
|
||||
path.value = response.path
|
||||
entries.value = response.entries
|
||||
if (dirTokens.get(target) !== request) return
|
||||
dirs.set(target, { loading: false, error: '', entries: response.entries })
|
||||
} catch (err) {
|
||||
if (request !== dirRequest) return
|
||||
entries.value = []
|
||||
error.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
if (request === dirRequest) loading.value = false
|
||||
if (dirTokens.get(target) !== request) return
|
||||
dirs.set(target, {
|
||||
loading: false,
|
||||
error: apiErrorMessage(err),
|
||||
entries: previous?.entries ?? [],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,20 +260,18 @@ async function openFile(entry: FileEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
function openEntry(entry: FileEntry) {
|
||||
if (entry.kind === 'dir') {
|
||||
selected.value = null
|
||||
file.value = null
|
||||
fileError.value = ''
|
||||
void loadDir(entry.path)
|
||||
} else {
|
||||
void openFile(entry)
|
||||
function toggleDir(entry: FileEntry) {
|
||||
if (expanded.has(entry.path)) {
|
||||
expanded.delete(entry.path)
|
||||
return
|
||||
}
|
||||
expanded.add(entry.path)
|
||||
void loadDir(entry.path)
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
const parent = segments.value.slice(0, -1).join('/')
|
||||
void loadDir(parent)
|
||||
function activateEntry(entry: FileEntry) {
|
||||
if (entry.kind === 'dir') toggleDir(entry)
|
||||
else void openFile(entry)
|
||||
}
|
||||
|
||||
async function loadGit() {
|
||||
@@ -282,41 +314,41 @@ onBeforeUnmount(() => {
|
||||
<div class="files-pane">
|
||||
<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" />
|
||||
Back
|
||||
</button>
|
||||
<div class="crumbs-row">
|
||||
<button type="button" class="crumb" @click="loadDir('')">Workspace</button>
|
||||
<template v-for="(segment, index) in segments" :key="crumbPath(index)">
|
||||
<ChevronRight :size="12" class="faint" aria-hidden="true" />
|
||||
<button type="button" class="crumb" @click="loadDir(crumbPath(index))">
|
||||
{{ segment }}
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tree-head">Workspace</div>
|
||||
|
||||
<div class="file-list">
|
||||
<p v-if="loading" class="meta pane-pad">Loading files.</p>
|
||||
<p v-else-if="error" class="form-error pane-pad">{{ error }}</p>
|
||||
<p v-else-if="entries.length === 0" class="empty pane-pad">This folder is empty.</p>
|
||||
<template v-else>
|
||||
<div class="file-list" aria-label="Workspace files">
|
||||
<template v-for="row in rows" :key="row.key">
|
||||
<p
|
||||
v-if="row.kind === 'note'"
|
||||
class="tree-note"
|
||||
:class="{ error: row.error }"
|
||||
:style="indent(row.depth)"
|
||||
>
|
||||
{{ row.text }}
|
||||
</p>
|
||||
<button
|
||||
v-for="entry in entries"
|
||||
:key="entry.path"
|
||||
v-else
|
||||
type="button"
|
||||
class="file-row"
|
||||
:class="{ active: selected?.path === entry.path }"
|
||||
:title="entry.path"
|
||||
@click="openEntry(entry)"
|
||||
:class="{ active: selected?.path === row.entry.path }"
|
||||
:style="indent(row.depth)"
|
||||
:title="row.entry.path"
|
||||
:aria-expanded="row.entry.kind === 'dir' ? expanded.has(row.entry.path) : undefined"
|
||||
@click="activateEntry(row.entry)"
|
||||
>
|
||||
<Folder v-if="entry.kind === 'dir'" :size="14" aria-hidden="true" />
|
||||
<LinkIcon v-else-if="entry.kind === 'link'" :size="14" aria-hidden="true" />
|
||||
<ChevronRight
|
||||
v-if="row.entry.kind === 'dir'"
|
||||
:size="14"
|
||||
class="tree-caret"
|
||||
:class="{ open: expanded.has(row.entry.path) }"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span v-else class="tree-caret-gap" aria-hidden="true"></span>
|
||||
<Folder v-if="row.entry.kind === 'dir'" :size="14" aria-hidden="true" />
|
||||
<LinkIcon v-else-if="row.entry.kind === 'link'" :size="14" aria-hidden="true" />
|
||||
<File v-else :size="14" aria-hidden="true" />
|
||||
<span class="file-row-name">{{ entry.name }}</span>
|
||||
<span v-if="entry.kind === 'file'" class="file-row-size">{{ formatSize(entry.size) }}</span>
|
||||
<span class="file-row-name">{{ row.entry.name }}</span>
|
||||
<span v-if="row.entry.kind === 'file'" class="file-row-size">{{ formatSize(row.entry.size) }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user