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;
|
min-height: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
container-type: inline-size;
|
||||||
}
|
}
|
||||||
|
|
||||||
.files-resizer {
|
.files-resizer {
|
||||||
@@ -1729,50 +1730,14 @@ body.files-resizing-y * {
|
|||||||
user-select: none !important;
|
user-select: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.crumbs {
|
.tree-head {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
padding: var(--sp-2);
|
padding: var(--sp-2);
|
||||||
border-bottom: 1px solid var(--border);
|
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);
|
font-size: var(--fs-small);
|
||||||
color: var(--muted);
|
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 {
|
.file-list {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
@@ -1787,6 +1752,7 @@ body.files-resizing-y * {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--sp-1);
|
gap: var(--sp-1);
|
||||||
padding: var(--sp-1) var(--sp-2);
|
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: 1px solid transparent;
|
||||||
border-radius: var(--r-control);
|
border-radius: var(--r-control);
|
||||||
background: transparent;
|
background: transparent;
|
||||||
@@ -1817,6 +1783,42 @@ body.files-resizing-y * {
|
|||||||
font-size: var(--fs-small);
|
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 {
|
.files-viewer {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
@@ -2543,4 +2545,8 @@ details:not([open]) > *:not(summary) {
|
|||||||
.sidebar {
|
.sidebar {
|
||||||
transition: none;
|
transition: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tree-caret {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||||
import { ChevronLeft, ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
|
import { ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
|
||||||
import type { FileContentResponse, FileEntry, FileListResponse, GitSummaryResponse } from '~/types'
|
import type { FileContentResponse, FileEntry, FileListResponse, GitSummaryResponse } from '~/types'
|
||||||
import { apiErrorMessage } from '~/utils/errors'
|
import { apiErrorMessage } from '~/utils/errors'
|
||||||
import { formatSize } from '~/utils/format'
|
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_MAX_HEIGHT_PERCENT = 0.6
|
||||||
const FILES_STACKED_WIDTH = 430
|
const FILES_STACKED_WIDTH = 430
|
||||||
|
|
||||||
const path = ref('.')
|
type DirState = { loading: boolean; error: string; entries: FileEntry[] }
|
||||||
const entries = ref<FileEntry[]>([])
|
|
||||||
const loading = ref(false)
|
type TreeRow =
|
||||||
const error = ref('')
|
| { 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 filesEl = ref<HTMLElement | null>(null)
|
||||||
const browserEl = 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 gitLoading = ref(false)
|
||||||
const gitError = ref('')
|
const gitError = ref('')
|
||||||
|
|
||||||
let dirRequest = 0
|
|
||||||
let fileRequest = 0
|
let fileRequest = 0
|
||||||
|
|
||||||
const narrow = computed(() => filesWidth.value > 0 && filesWidth.value <= FILES_STACKED_WIDTH)
|
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)
|
saveSize(isNarrow ? FILES_HEIGHT_KEY : FILES_WIDTH_KEY, clamped)
|
||||||
}
|
}
|
||||||
|
|
||||||
const segments = computed(() => (path.value === '.' ? [] : path.value.split('/').filter(Boolean)))
|
// The visible rows: the root's entries, then the entries of every
|
||||||
const hasParent = computed(() => segments.value.length > 0)
|
// 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 lineNumbers = computed(() => {
|
||||||
const content = file.value?.content ?? ''
|
const content = file.value?.content ?? ''
|
||||||
@@ -186,25 +221,24 @@ const lineNumbers = computed(() => {
|
|||||||
return Array.from({ length: count }, (_, index) => index + 1).join('\n')
|
return Array.from({ length: count }, (_, index) => index + 1).join('\n')
|
||||||
})
|
})
|
||||||
|
|
||||||
function crumbPath(index: number) {
|
// Expanding a folder reads it again, so a file a turn added or removed
|
||||||
return segments.value.slice(0, index + 1).join('/')
|
// shows up the next time the folder is opened.
|
||||||
}
|
|
||||||
|
|
||||||
async function loadDir(target: string) {
|
async function loadDir(target: string) {
|
||||||
const request = ++dirRequest
|
const request = ++dirSeq
|
||||||
loading.value = true
|
dirTokens.set(target, request)
|
||||||
error.value = ''
|
const previous = dirs.get(target)
|
||||||
|
dirs.set(target, { loading: true, error: '', entries: previous?.entries ?? [] })
|
||||||
try {
|
try {
|
||||||
const response = await api.get<FileListResponse>(`/rooms/${props.roomId}/files`, { path: target })
|
const response = await api.get<FileListResponse>(`/rooms/${props.roomId}/files`, { path: target })
|
||||||
if (request !== dirRequest) return
|
if (dirTokens.get(target) !== request) return
|
||||||
path.value = response.path
|
dirs.set(target, { loading: false, error: '', entries: response.entries })
|
||||||
entries.value = response.entries
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (request !== dirRequest) return
|
if (dirTokens.get(target) !== request) return
|
||||||
entries.value = []
|
dirs.set(target, {
|
||||||
error.value = apiErrorMessage(err)
|
loading: false,
|
||||||
} finally {
|
error: apiErrorMessage(err),
|
||||||
if (request === dirRequest) loading.value = false
|
entries: previous?.entries ?? [],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,20 +260,18 @@ async function openFile(entry: FileEntry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEntry(entry: FileEntry) {
|
function toggleDir(entry: FileEntry) {
|
||||||
if (entry.kind === 'dir') {
|
if (expanded.has(entry.path)) {
|
||||||
selected.value = null
|
expanded.delete(entry.path)
|
||||||
file.value = null
|
return
|
||||||
fileError.value = ''
|
|
||||||
void loadDir(entry.path)
|
|
||||||
} else {
|
|
||||||
void openFile(entry)
|
|
||||||
}
|
}
|
||||||
|
expanded.add(entry.path)
|
||||||
|
void loadDir(entry.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
function goBack() {
|
function activateEntry(entry: FileEntry) {
|
||||||
const parent = segments.value.slice(0, -1).join('/')
|
if (entry.kind === 'dir') toggleDir(entry)
|
||||||
void loadDir(parent)
|
else void openFile(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadGit() {
|
async function loadGit() {
|
||||||
@@ -282,41 +314,41 @@ onBeforeUnmount(() => {
|
|||||||
<div class="files-pane">
|
<div class="files-pane">
|
||||||
<div ref="filesEl" class="files" :style="filesStyle">
|
<div ref="filesEl" class="files" :style="filesStyle">
|
||||||
<div ref="browserEl" class="files-browser">
|
<div ref="browserEl" class="files-browser">
|
||||||
<div class="crumbs">
|
<div class="tree-head">Workspace</div>
|
||||||
<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="file-list">
|
<div class="file-list" aria-label="Workspace files">
|
||||||
<p v-if="loading" class="meta pane-pad">Loading files.</p>
|
<template v-for="row in rows" :key="row.key">
|
||||||
<p v-else-if="error" class="form-error pane-pad">{{ error }}</p>
|
<p
|
||||||
<p v-else-if="entries.length === 0" class="empty pane-pad">This folder is empty.</p>
|
v-if="row.kind === 'note'"
|
||||||
<template v-else>
|
class="tree-note"
|
||||||
|
:class="{ error: row.error }"
|
||||||
|
:style="indent(row.depth)"
|
||||||
|
>
|
||||||
|
{{ row.text }}
|
||||||
|
</p>
|
||||||
<button
|
<button
|
||||||
v-for="entry in entries"
|
v-else
|
||||||
:key="entry.path"
|
|
||||||
type="button"
|
type="button"
|
||||||
class="file-row"
|
class="file-row"
|
||||||
:class="{ active: selected?.path === entry.path }"
|
:class="{ active: selected?.path === row.entry.path }"
|
||||||
:title="entry.path"
|
:style="indent(row.depth)"
|
||||||
@click="openEntry(entry)"
|
: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" />
|
<ChevronRight
|
||||||
<LinkIcon v-else-if="entry.kind === 'link'" :size="14" aria-hidden="true" />
|
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" />
|
<File v-else :size="14" aria-hidden="true" />
|
||||||
<span class="file-row-name">{{ entry.name }}</span>
|
<span class="file-row-name">{{ row.entry.name }}</span>
|
||||||
<span v-if="entry.kind === 'file'" class="file-row-size">{{ formatSize(entry.size) }}</span>
|
<span v-if="row.entry.kind === 'file'" class="file-row-size">{{ formatSize(row.entry.size) }}</span>
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user