Give the web app an AFFiNE-style shell
- The main view is an inset panel beside the sidebar; views put their breadcrumbs and actions in its header via <Teleport to="#app-header">. - The sidebar resizes from its edge (220-480px, double-click resets) and folds away with a button or Ctrl+/; both are remembered per browser. - A workspace card at the top opens a menu to switch, configure or add a workspace, replacing the select. - Search sits beside a new-page button, followed by Home and Settings; space headings show open, trash and add-page actions on hover. - The footer has a theme button cycling system, light and dark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5fce899524
commit
e717c1d69f
10 files changed
+420
-158
No files matched your search
@@ -32,6 +32,12 @@ export const iconPaths = {
|
||||
open: ["M8 16L16 8", "M9 8h7v7"],
|
||||
restore: ["M4.5 13a7.5 7.5 0 1 0 2.2-6.3", "M5 4v4h4"],
|
||||
"sign-out": ["M14 4h5v16h-5", "M10 8l-4 4 4 4", "M6 12h9"],
|
||||
sidebar: ["M4 5h16v14H4z", "M9.5 5v14"],
|
||||
home: ["M4 11l8-7 8 7", "M6 9.5V20h12V9.5", "M10 20v-5h4v5"],
|
||||
sun: ["M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z", "M12 3v1.5", "M12 19.5V21", "M3 12h1.5", "M19.5 12H21", "M5.6 5.6l1.1 1.1", "M17.3 17.3l1.1 1.1", "M5.6 18.4l1.1-1.1", "M17.3 6.7l1.1-1.1"],
|
||||
moon: ["M19.5 14.5A8 8 0 0 1 9.5 4.5a8 8 0 1 0 10 10z"],
|
||||
monitor: ["M4 5h16v11H4z", "M9 20h6", "M12 16v4"],
|
||||
selector: ["M8 9l4-4 4 4", "M8 15l4 4 4-4"],
|
||||
} as const;
|
||||
|
||||
export type IconName = keyof typeof iconPaths;
|
||||
@@ -1,14 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { DwButton, DwCallout, DwIcon, DwLogo, useTheme, type ThemeMode } from "@docwell/ui";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { DwButton, DwCallout, DwIcon, useTheme, type IconName, type ThemeMode } from "@docwell/ui";
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useFormErrors } from "../composables/useFormErrors";
|
||||
import { SIDEBAR_DEFAULT, clampWidth, useSidebar } from "../composables/useSidebar";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { useSpacesStore } from "../stores/spaces";
|
||||
import { atLeast, useWorkspacesStore } from "../stores/workspaces";
|
||||
import PageTreeNode from "./PageTreeNode.vue";
|
||||
import ServerStatus from "./ServerStatus.vue";
|
||||
import WorkspaceSwitcher from "./WorkspaceSwitcher.vue";
|
||||
|
||||
// The app shell: a sidebar on the sunken background and the main view inset
|
||||
// beside it as a panel. Views fill the panel's header by teleporting into
|
||||
// #app-header (use <Teleport defer to="#app-header">).
|
||||
const auth = useAuthStore();
|
||||
const workspaces = useWorkspacesStore();
|
||||
const spaces = useSpacesStore();
|
||||
@@ -16,9 +21,8 @@ const router = useRouter();
|
||||
const route = useRoute();
|
||||
const { mode } = useTheme();
|
||||
const errors = useFormErrors();
|
||||
const sidebar = useSidebar();
|
||||
|
||||
const themes: ThemeMode[] = ["system", "light", "dark"];
|
||||
const sidebarOpen = ref(false);
|
||||
const error = ref("");
|
||||
|
||||
function showError(e: unknown) {
|
||||
@@ -32,7 +36,17 @@ watch(
|
||||
(id) => id && spaces.load(id).catch(showError),
|
||||
{ immediate: true },
|
||||
);
|
||||
watch(() => route.fullPath, () => (sidebarOpen.value = false));
|
||||
watch(() => route.fullPath, () => (sidebar.mobileOpen.value = false));
|
||||
|
||||
// Ctrl+/ (Cmd+/ on macOS) folds the sidebar, as in other editors.
|
||||
function onKey(e: KeyboardEvent) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === "/") {
|
||||
e.preventDefault();
|
||||
sidebar.toggle();
|
||||
}
|
||||
}
|
||||
onMounted(() => document.addEventListener("keydown", onKey));
|
||||
onBeforeUnmount(() => document.removeEventListener("keydown", onKey));
|
||||
|
||||
const ws = computed(() => workspaces.current);
|
||||
const canCreateSpace = computed(() => atLeast(ws.value?.role, "admin"));
|
||||
@@ -53,11 +67,6 @@ async function newPage(spaceId = targetSpace.value) {
|
||||
}
|
||||
}
|
||||
|
||||
function selectWorkspace(id: string) {
|
||||
workspaces.select(id);
|
||||
router.push({ name: "home" });
|
||||
}
|
||||
|
||||
// Dropping a page on a space's header moves it to the end of the top level.
|
||||
async function dropOnSpace(spaceId: string) {
|
||||
const d = spaces.dragging;
|
||||
@@ -70,9 +79,45 @@ async function dropOnSpace(spaceId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Dragging the sidebar's edge resizes it; a double click resets it.
|
||||
const resizing = ref(false);
|
||||
function startResize(e: PointerEvent) {
|
||||
const el = e.currentTarget as HTMLElement;
|
||||
el.setPointerCapture(e.pointerId);
|
||||
resizing.value = true;
|
||||
const startX = e.clientX;
|
||||
const startWidth = sidebar.width.value;
|
||||
const move = (ev: PointerEvent) => (sidebar.width.value = clampWidth(startWidth + ev.clientX - startX));
|
||||
const end = () => {
|
||||
resizing.value = false;
|
||||
el.removeEventListener("pointermove", move);
|
||||
el.removeEventListener("pointerup", end);
|
||||
el.removeEventListener("pointercancel", end);
|
||||
};
|
||||
el.addEventListener("pointermove", move);
|
||||
el.addEventListener("pointerup", end);
|
||||
el.addEventListener("pointercancel", end);
|
||||
}
|
||||
function resizeByKey(e: KeyboardEvent) {
|
||||
const step = e.key === "ArrowLeft" ? -16 : e.key === "ArrowRight" ? 16 : 0;
|
||||
if (step) sidebar.width.value = clampWidth(sidebar.width.value + step);
|
||||
}
|
||||
|
||||
const themes: { mode: ThemeMode; icon: IconName }[] = [
|
||||
{ mode: "system", icon: "monitor" },
|
||||
{ mode: "light", icon: "sun" },
|
||||
{ mode: "dark", icon: "moon" },
|
||||
];
|
||||
const theme = computed(() => themes.find((t) => t.mode === mode.value) ?? themes[0]!);
|
||||
function cycleTheme() {
|
||||
mode.value = themes[(themes.indexOf(theme.value) + 1) % themes.length]!.mode;
|
||||
}
|
||||
|
||||
const iconLink =
|
||||
"grid size-control-sm shrink-0 cursor-pointer place-items-center rounded-sm text-ink-muted hover:bg-surface-hover hover:text-ink";
|
||||
const rowLink = "flex h-control-sm items-center gap-2 rounded-sm px-2 text-ink-muted hover:bg-surface-hover hover:text-ink";
|
||||
"grid size-6 shrink-0 cursor-pointer place-items-center rounded-xs text-ink-muted hover:bg-line hover:text-ink";
|
||||
const navRow =
|
||||
"flex h-control-sm w-full cursor-pointer items-center gap-2 rounded-sm px-2 text-left text-ink-muted hover:bg-surface-hover hover:text-ink";
|
||||
const navActive = "bg-surface-hover font-semibold text-ink";
|
||||
|
||||
function signOut() {
|
||||
auth.logout();
|
||||
@@ -81,93 +126,104 @@ function signOut() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-dvh">
|
||||
<div class="flex h-dvh bg-surface-sunken" :class="{ 'cursor-col-resize select-none': resizing }">
|
||||
<aside
|
||||
class="fixed inset-y-0 left-0 z-20 flex w-sidebar flex-col border-r border-line bg-surface-sunken transition-transform duration-200 ease-out md:static md:translate-x-0"
|
||||
:class="sidebarOpen ? 'translate-x-0' : '-translate-x-full'"
|
||||
class="fixed inset-y-0 left-0 z-30 flex max-w-[85vw] flex-col bg-surface-sunken transition-transform duration-200 ease-out md:relative md:z-auto md:translate-x-0 md:transition-none"
|
||||
:class="[sidebar.mobileOpen.value ? 'translate-x-0 shadow-dialog' : '-translate-x-full', { 'md:hidden': sidebar.collapsed.value }]"
|
||||
:style="{ width: `${sidebar.width.value}px` }"
|
||||
data-testid="sidebar"
|
||||
>
|
||||
<div class="flex h-12 shrink-0 items-center px-4">
|
||||
<RouterLink to="/" class="rounded-sm" :aria-label="$t('app.name')"><DwLogo class="h-6" /></RouterLink>
|
||||
<div class="flex shrink-0 items-center gap-1 px-2 pt-2">
|
||||
<WorkspaceSwitcher />
|
||||
<DwButton
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="sidebar"
|
||||
:aria-label="$t('sidebar.collapseSidebar')"
|
||||
:title="`${$t('sidebar.collapseSidebar')} (Ctrl /)`"
|
||||
@click="sidebar.toggle()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 px-3">
|
||||
<div class="mt-2 space-y-px px-2">
|
||||
<div class="flex items-center gap-1">
|
||||
<select
|
||||
v-if="workspaces.items.length"
|
||||
:value="ws?.id"
|
||||
:aria-label="$t('sidebar.workspace')"
|
||||
class="dw-input h-control-sm flex-1 px-2"
|
||||
data-testid="workspace-select"
|
||||
@change="selectWorkspace(($event.target as HTMLSelectElement).value)"
|
||||
<button
|
||||
class="flex h-control-sm min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-sm border border-line bg-surface px-2 text-left text-ink-muted hover:border-line-strong hover:text-ink"
|
||||
>
|
||||
<option v-for="w in workspaces.items" :key="w.id" :value="w.id">{{ w.name }}</option>
|
||||
</select>
|
||||
<p v-else-if="workspaces.loaded" class="flex-1 px-1 text-ui-sm text-ink-muted">
|
||||
{{ $t(auth.user?.organization || auth.user?.role === "superadmin" ? "sidebar.noWorkspaces" : "sidebar.noOrg") }}
|
||||
</p>
|
||||
<RouterLink
|
||||
v-if="ws"
|
||||
:to="{ name: 'workspace-settings', params: { id: ws.id } }"
|
||||
:class="iconLink"
|
||||
:aria-label="$t('workspace.settings')"
|
||||
:title="$t('workspace.settings')"
|
||||
>
|
||||
<DwIcon name="settings" :size="16" />
|
||||
</RouterLink>
|
||||
<RouterLink
|
||||
v-if="workspaces.canCreate()"
|
||||
to="/workspaces/new"
|
||||
:class="iconLink"
|
||||
:aria-label="$t('workspace.newTitle')"
|
||||
:title="$t('workspace.newTitle')"
|
||||
>
|
||||
<DwIcon name="plus" :size="16" />
|
||||
</RouterLink>
|
||||
<DwIcon name="search" :size="16" />
|
||||
<span class="flex-1 truncate">{{ $t("app.search") }}</span>
|
||||
<kbd class="font-mono text-[11px] leading-4 text-ink-faint">Ctrl K</kbd>
|
||||
</button>
|
||||
<DwButton
|
||||
v-if="targetSpace"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="plus"
|
||||
class="border-line bg-surface hover:!border-line-strong"
|
||||
:aria-label="$t('app.newPage')"
|
||||
:title="$t('app.newPage')"
|
||||
data-testid="new-page"
|
||||
@click="newPage()"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
class="flex h-control-sm w-full items-center gap-2 rounded-sm border border-line bg-surface px-2 text-left text-ui-md text-ink-muted hover:bg-surface-hover"
|
||||
>
|
||||
<DwIcon name="search" :size="16" />
|
||||
<span class="flex-1">{{ $t("app.search") }}</span>
|
||||
<kbd class="font-mono text-[11px] leading-4">Ctrl K</kbd>
|
||||
</button>
|
||||
<RouterLink to="/" :class="[navRow, 'mt-1.5']" :exact-active-class="navActive">
|
||||
<DwIcon name="home" :size="16" />{{ $t("sidebar.home") }}
|
||||
</RouterLink>
|
||||
<RouterLink v-if="ws" :to="{ name: 'workspace-settings', params: { id: ws.id } }" :class="navRow" :active-class="navActive">
|
||||
<DwIcon name="settings" :size="16" />{{ $t("app.settings") }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
|
||||
<nav class="mt-5 flex-1 space-y-5 overflow-y-auto px-3" data-testid="space-list">
|
||||
<nav class="mt-4 flex-1 space-y-4 overflow-y-auto px-2 pb-4" data-testid="space-list">
|
||||
<DwCallout v-if="error" tone="danger" size="ui">{{ error }}</DwCallout>
|
||||
|
||||
<template v-if="ws">
|
||||
<section v-for="s in spaces.items" :key="s.id">
|
||||
<div
|
||||
class="group flex h-control-sm items-center gap-1 rounded-sm pl-2"
|
||||
class="group flex h-7 items-center gap-1 rounded-sm pr-1 pl-2 hover:bg-surface-hover"
|
||||
@dragover="spaces.dragging?.spaceId === s.id && $event.preventDefault()"
|
||||
@drop.prevent="dropOnSpace(s.id)"
|
||||
>
|
||||
<button
|
||||
class="dw-label flex min-w-0 flex-1 cursor-pointer items-center gap-1 text-left hover:text-ink"
|
||||
class="flex min-w-0 flex-1 cursor-pointer items-center gap-1 text-left text-ui-xs font-medium text-ink-muted hover:text-ink"
|
||||
:aria-expanded="spaces.spaceOpen(s.id)"
|
||||
@click="spaces.toggleSpace(s.id)"
|
||||
>
|
||||
<span class="truncate">{{ s.icon ? `${s.icon} ` : "" }}{{ s.name }}</span>
|
||||
<DwIcon v-if="s.visibility === 'private'" name="lock" :size="12" :label="$t('space.private')" />
|
||||
<DwIcon
|
||||
:name="spaces.spaceOpen(s.id) ? 'chevron-down' : 'chevron-right'"
|
||||
:size="12"
|
||||
class="opacity-0 group-hover:opacity-100"
|
||||
/>
|
||||
</button>
|
||||
<RouterLink
|
||||
:to="{ name: 'space', params: { id: s.id } }"
|
||||
:class="[iconLink, 'size-6 opacity-0 group-hover:opacity-100 focus-visible:opacity-100']"
|
||||
:aria-label="$t('space.open', { name: s.name })"
|
||||
:title="$t('space.open', { name: s.name })"
|
||||
>
|
||||
<DwIcon name="open" :size="14" />
|
||||
</RouterLink>
|
||||
<button
|
||||
v-if="spaces.canEdit(s.id)"
|
||||
:class="[iconLink, 'size-6']"
|
||||
:aria-label="$t('sidebar.addPage')"
|
||||
:title="$t('sidebar.addPage')"
|
||||
@click="newPage(s.id)"
|
||||
>
|
||||
<DwIcon name="plus" :size="14" />
|
||||
</button>
|
||||
<span class="flex items-center opacity-0 group-focus-within:opacity-100 group-hover:opacity-100">
|
||||
<RouterLink
|
||||
:to="{ name: 'space', params: { id: s.id } }"
|
||||
:class="iconLink"
|
||||
:aria-label="$t('space.open', { name: s.name })"
|
||||
:title="$t('space.open', { name: s.name })"
|
||||
>
|
||||
<DwIcon name="open" :size="14" />
|
||||
</RouterLink>
|
||||
<RouterLink
|
||||
:to="{ name: 'trash', params: { id: s.id } }"
|
||||
:class="iconLink"
|
||||
:aria-label="$t('sidebar.trash')"
|
||||
:title="$t('sidebar.trash')"
|
||||
>
|
||||
<DwIcon name="trash" :size="14" />
|
||||
</RouterLink>
|
||||
<button
|
||||
v-if="spaces.canEdit(s.id)"
|
||||
:class="iconLink"
|
||||
:aria-label="$t('sidebar.addPage')"
|
||||
:title="$t('sidebar.addPage')"
|
||||
@click="newPage(s.id)"
|
||||
>
|
||||
<DwIcon name="plus" :size="14" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<template v-if="spaces.spaceOpen(s.id)">
|
||||
<ul class="mt-0.5 flex flex-col gap-px" role="tree" :aria-label="s.name" data-testid="page-tree">
|
||||
@@ -180,37 +236,44 @@ function signOut() {
|
||||
@error="showError"
|
||||
/>
|
||||
</ul>
|
||||
<p v-if="spaces.trees[s.id] && !spaces.trees[s.id]!.length" class="px-2 py-1 text-ui-sm text-ink-muted">
|
||||
<p v-if="spaces.trees[s.id] && !spaces.trees[s.id]!.length" class="px-2 py-1 text-ui-sm text-ink-faint">
|
||||
{{ $t("space.noPages") }}
|
||||
</p>
|
||||
<RouterLink :to="{ name: 'trash', params: { id: s.id } }" :class="rowLink">
|
||||
<DwIcon name="trash" :size="16" />
|
||||
{{ $t("sidebar.trash") }}
|
||||
</RouterLink>
|
||||
</template>
|
||||
</section>
|
||||
<p v-if="spaces.loaded && !spaces.items.length" class="px-2 text-ui-sm text-ink-muted">{{ $t("sidebar.noSpaces") }}</p>
|
||||
<RouterLink v-if="canCreateSpace" :to="{ name: 'new-space', params: { id: ws.id } }" :class="rowLink">
|
||||
<RouterLink v-if="canCreateSpace" :to="{ name: 'new-space', params: { id: ws.id } }" :class="navRow">
|
||||
<DwIcon name="plus" :size="16" />
|
||||
{{ $t("space.new") }}
|
||||
</RouterLink>
|
||||
</template>
|
||||
</nav>
|
||||
|
||||
<div class="space-y-3 border-t border-line p-3">
|
||||
<div v-if="auth.user" class="flex items-center gap-2">
|
||||
<span
|
||||
class="grid size-7 shrink-0 place-items-center rounded-full bg-primary text-ui-sm font-semibold text-on-primary"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{{ auth.user.name.slice(0, 1).toUpperCase() }}
|
||||
</span>
|
||||
<RouterLink to="/settings/organization" class="min-w-0 flex-1 rounded-sm">
|
||||
<div class="truncate font-medium text-ink" data-testid="user-name">{{ auth.user.name }}</div>
|
||||
<div class="truncate text-ui-sm text-ink-muted" data-testid="user-org">
|
||||
{{ $t(`roles.${auth.user.role}`) }}{{ auth.user.organizationName ? ` · ${auth.user.organizationName}` : "" }}
|
||||
</div>
|
||||
<div class="space-y-2 border-t border-line px-2 py-2">
|
||||
<div v-if="auth.user" class="flex items-center gap-1">
|
||||
<RouterLink to="/settings/organization" class="flex min-w-0 flex-1 items-center gap-2 rounded-sm px-1.5 py-1 hover:bg-surface-hover">
|
||||
<span
|
||||
class="grid size-7 shrink-0 place-items-center rounded-full bg-primary text-ui-sm font-semibold text-on-primary"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{{ auth.user.name.slice(0, 1).toUpperCase() }}
|
||||
</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate font-medium text-ink" data-testid="user-name">{{ auth.user.name }}</span>
|
||||
<span class="block truncate text-ui-xs text-ink-muted" data-testid="user-org">
|
||||
{{ $t(`roles.${auth.user.role}`) }}{{ auth.user.organizationName ? ` · ${auth.user.organizationName}` : "" }}
|
||||
</span>
|
||||
</span>
|
||||
</RouterLink>
|
||||
<DwButton
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
:icon="theme.icon"
|
||||
:aria-label="`${$t('app.theme')}: ${$t(`theme.${theme.mode}`)}`"
|
||||
:title="`${$t('app.theme')}: ${$t(`theme.${theme.mode}`)}`"
|
||||
data-testid="theme-toggle"
|
||||
@click="cycleTheme"
|
||||
/>
|
||||
<DwButton
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
@@ -220,30 +283,45 @@ function signOut() {
|
||||
@click="signOut"
|
||||
/>
|
||||
</div>
|
||||
<label class="flex items-center justify-between gap-2">
|
||||
<span class="text-ink-muted">{{ $t("app.theme") }}</span>
|
||||
<select v-model="mode" class="dw-input h-control-sm px-2 text-ui-sm">
|
||||
<option v-for="t in themes" :key="t" :value="t">{{ $t(`theme.${t}`) }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<ServerStatus />
|
||||
<ServerStatus class="px-1.5" />
|
||||
</div>
|
||||
|
||||
<div
|
||||
role="separator"
|
||||
aria-orientation="vertical"
|
||||
:aria-label="$t('sidebar.resize')"
|
||||
:aria-valuenow="sidebar.width.value"
|
||||
tabindex="0"
|
||||
class="group absolute inset-y-0 -right-1.5 z-10 hidden w-3 cursor-col-resize md:block"
|
||||
@pointerdown.prevent="startResize"
|
||||
@dblclick="sidebar.width.value = SIDEBAR_DEFAULT"
|
||||
@keydown="resizeByKey"
|
||||
>
|
||||
<span
|
||||
class="mx-auto block h-full w-0.5 rounded-full bg-focus-ring opacity-0 transition-opacity group-hover:opacity-60"
|
||||
:class="{ '!opacity-100': resizing }"
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div v-if="sidebarOpen" class="fixed inset-0 z-10 bg-black/40 md:hidden" @click="sidebarOpen = false" />
|
||||
<div v-if="sidebar.mobileOpen.value" class="fixed inset-0 z-20 bg-black/40 md:hidden" @click="sidebar.mobileOpen.value = false" />
|
||||
|
||||
<main class="flex min-w-0 flex-1 flex-col bg-surface">
|
||||
<header class="flex h-12 shrink-0 items-center justify-between gap-2 border-b border-line px-4">
|
||||
<main
|
||||
class="flex min-w-0 flex-1 flex-col bg-surface md:my-2 md:mr-2 md:overflow-hidden md:rounded-md md:border md:border-line"
|
||||
:class="{ 'md:ml-2': sidebar.collapsed.value }"
|
||||
>
|
||||
<header class="flex h-12 shrink-0 items-center gap-2 px-3">
|
||||
<DwButton
|
||||
class="md:hidden"
|
||||
:class="{ 'md:hidden': !sidebar.collapsed.value }"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="menu"
|
||||
:aria-label="$t('sidebar.menu')"
|
||||
@click="sidebarOpen = true"
|
||||
icon="sidebar"
|
||||
:aria-label="$t('sidebar.expandSidebar')"
|
||||
:title="`${$t('sidebar.expandSidebar')} (Ctrl /)`"
|
||||
data-testid="sidebar-expand"
|
||||
@click="sidebar.toggle()"
|
||||
/>
|
||||
<span class="min-w-0 flex-1" />
|
||||
<DwButton v-if="targetSpace" variant="primary" icon="plus" @click="newPage()">{{ $t("app.newPage") }}</DwButton>
|
||||
<div id="app-header" class="flex min-w-0 flex-1 items-center gap-2" />
|
||||
</header>
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
<RouterView @error="showError" />
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<script setup lang="ts">
|
||||
import { DwIcon } from "@docwell/ui";
|
||||
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { useWorkspacesStore } from "../stores/workspaces";
|
||||
|
||||
// The sidebar's top card: the current workspace, opening a menu to switch,
|
||||
// configure or add one.
|
||||
const auth = useAuthStore();
|
||||
const workspaces = useWorkspacesStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
const open = ref(false);
|
||||
const root = ref<HTMLElement | null>(null);
|
||||
const ws = computed(() => workspaces.current);
|
||||
|
||||
function select(id: string) {
|
||||
open.value = false;
|
||||
workspaces.select(id);
|
||||
router.push({ name: "home" });
|
||||
}
|
||||
|
||||
function onPointerDown(e: PointerEvent) {
|
||||
if (!root.value?.contains(e.target as Node)) open.value = false;
|
||||
}
|
||||
function onKey(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") open.value = false;
|
||||
}
|
||||
watch(open, (o) => {
|
||||
if (o) {
|
||||
document.addEventListener("pointerdown", onPointerDown);
|
||||
document.addEventListener("keydown", onKey);
|
||||
} else {
|
||||
document.removeEventListener("pointerdown", onPointerDown);
|
||||
document.removeEventListener("keydown", onKey);
|
||||
}
|
||||
});
|
||||
watch(() => route.fullPath, () => (open.value = false));
|
||||
onBeforeUnmount(() => (open.value = false));
|
||||
|
||||
const item = "flex h-control-sm w-full cursor-pointer items-center gap-2 rounded-sm px-2 text-left text-ink hover:bg-surface-hover";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="relative min-w-0 flex-1">
|
||||
<button
|
||||
v-if="ws"
|
||||
class="flex h-10 w-full cursor-pointer items-center gap-2 rounded-sm px-1.5 text-left hover:bg-surface-hover"
|
||||
:aria-label="$t('sidebar.switchWorkspace')"
|
||||
aria-haspopup="menu"
|
||||
:aria-expanded="open"
|
||||
data-testid="workspace-select"
|
||||
@click="open = !open"
|
||||
>
|
||||
<span
|
||||
class="grid size-7 shrink-0 place-items-center rounded-sm bg-primary text-ui-sm font-semibold text-on-primary"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{{ ws.name.slice(0, 1).toUpperCase() }}
|
||||
</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate font-semibold text-ink">{{ ws.name }}</span>
|
||||
<span v-if="ws.organizationName" class="block truncate text-ui-xs text-ink-muted">{{ ws.organizationName }}</span>
|
||||
</span>
|
||||
<DwIcon name="selector" :size="14" class="text-ink-muted" />
|
||||
</button>
|
||||
<p v-else-if="workspaces.loaded" class="px-1 py-2 text-ui-sm text-ink-muted">
|
||||
{{ $t(auth.user?.organization || auth.user?.role === "superadmin" ? "sidebar.noWorkspaces" : "sidebar.noOrg") }}
|
||||
</p>
|
||||
<RouterLink
|
||||
v-if="!ws && workspaces.canCreate()"
|
||||
to="/workspaces/new"
|
||||
class="flex h-control-sm items-center gap-2 rounded-sm px-2 text-ink-muted hover:bg-surface-hover hover:text-ink"
|
||||
>
|
||||
<DwIcon name="plus" :size="16" />{{ $t("workspace.newTitle") }}
|
||||
</RouterLink>
|
||||
|
||||
<div
|
||||
v-if="open && ws"
|
||||
role="menu"
|
||||
class="absolute inset-x-0 top-full z-40 mt-1 rounded-md border border-line bg-surface-raised p-1 shadow-menu"
|
||||
>
|
||||
<p class="dw-label px-2 pt-1 pb-1.5">{{ $t("sidebar.workspaces") }}</p>
|
||||
<button v-for="w in workspaces.items" :key="w.id" role="menuitem" :class="item" @click="select(w.id)">
|
||||
<span
|
||||
class="grid size-5 shrink-0 place-items-center rounded-xs bg-surface-hover text-ui-xs font-semibold text-ink-muted"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{{ w.name.slice(0, 1).toUpperCase() }}
|
||||
</span>
|
||||
<span class="min-w-0 flex-1 truncate">{{ w.name }}</span>
|
||||
<DwIcon v-if="w.id === ws.id" name="check" :size="16" class="text-accent" :label="$t('sidebar.workspace')" />
|
||||
</button>
|
||||
<div class="my-1 border-t border-line" />
|
||||
<RouterLink role="menuitem" :to="{ name: 'workspace-settings', params: { id: ws.id } }" :class="item">
|
||||
<DwIcon name="settings" :size="16" class="text-ink-muted" />{{ $t("workspace.settings") }}
|
||||
</RouterLink>
|
||||
<RouterLink v-if="workspaces.canCreate()" role="menuitem" to="/workspaces/new" :class="item">
|
||||
<DwIcon name="plus" :size="16" class="text-ink-muted" />{{ $t("workspace.newTitle") }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
const storageKey = "docwell.sidebar";
|
||||
export const SIDEBAR_MIN = 220;
|
||||
export const SIDEBAR_MAX = 480;
|
||||
export const SIDEBAR_DEFAULT = 264;
|
||||
|
||||
function remembered(): { width: number; collapsed: boolean } {
|
||||
try {
|
||||
const v = JSON.parse(localStorage.getItem(storageKey) ?? "{}") as { width?: unknown; collapsed?: unknown };
|
||||
return {
|
||||
width: typeof v.width === "number" ? clampWidth(v.width) : SIDEBAR_DEFAULT,
|
||||
collapsed: v.collapsed === true,
|
||||
};
|
||||
} catch {
|
||||
return { width: SIDEBAR_DEFAULT, collapsed: false };
|
||||
}
|
||||
}
|
||||
|
||||
export function clampWidth(w: number) {
|
||||
return Math.round(Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, w)));
|
||||
}
|
||||
|
||||
const start = remembered();
|
||||
/** Width on wide screens, dragged from the sidebar's edge. */
|
||||
const width = ref(start.width);
|
||||
/** Folded away on wide screens. */
|
||||
const collapsed = ref(start.collapsed);
|
||||
/** Slid in over the page on narrow screens. */
|
||||
const mobileOpen = ref(false);
|
||||
|
||||
watch([width, collapsed], () => {
|
||||
try {
|
||||
localStorage.setItem(storageKey, JSON.stringify({ width: width.value, collapsed: collapsed.value }));
|
||||
} catch {
|
||||
// per-browser convenience only
|
||||
}
|
||||
});
|
||||
|
||||
/** The app sidebar's shared state: width and collapse persist per browser. */
|
||||
export function useSidebar() {
|
||||
const narrow = () => typeof window !== "undefined" && !window.matchMedia("(min-width: 48rem)").matches;
|
||||
function toggle() {
|
||||
if (narrow()) mobileOpen.value = !mobileOpen.value;
|
||||
else collapsed.value = !collapsed.value;
|
||||
}
|
||||
return { width, collapsed, mobileOpen, toggle };
|
||||
}
|
||||
@@ -19,7 +19,12 @@
|
||||
"addSubpage": "Add a page inside",
|
||||
"expand": "Expand",
|
||||
"collapse": "Collapse",
|
||||
"menu": "Menu"
|
||||
"menu": "Menu",
|
||||
"home": "Home",
|
||||
"collapseSidebar": "Collapse sidebar",
|
||||
"expandSidebar": "Expand sidebar",
|
||||
"resize": "Resize sidebar",
|
||||
"switchWorkspace": "Switch workspace"
|
||||
},
|
||||
"home": {
|
||||
"untitled": "Untitled",
|
||||
|
||||
@@ -19,7 +19,12 @@
|
||||
"addSubpage": "Dodaj stronę wewnątrz",
|
||||
"expand": "Rozwiń",
|
||||
"collapse": "Zwiń",
|
||||
"menu": "Menu"
|
||||
"menu": "Menu",
|
||||
"home": "Strona główna",
|
||||
"collapseSidebar": "Zwiń pasek boczny",
|
||||
"expandSidebar": "Rozwiń pasek boczny",
|
||||
"resize": "Zmień szerokość paska bocznego",
|
||||
"switchWorkspace": "Przełącz obszar roboczy"
|
||||
},
|
||||
"home": {
|
||||
"untitled": "Bez tytułu",
|
||||
|
||||
@@ -13,7 +13,7 @@ onMounted(() => (spaces.active = { space: "", page: "" }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="mx-auto max-w-doc-wide px-4 pt-8 pb-16 sm:px-16 sm:pt-12">
|
||||
<article class="mx-auto max-w-doc-wide px-4 pt-6 pb-16 sm:px-16 sm:pt-10">
|
||||
<div class="flex items-center gap-3">
|
||||
<DwIcon name="drop" :size="28" class="text-spring" />
|
||||
<h1 class="font-serif text-doc-h1">{{ ws?.name ?? $t("app.name") }}</h1>
|
||||
|
||||
@@ -185,12 +185,39 @@ const purge = () =>
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="mx-auto max-w-doc px-4 pt-8 pb-16 sm:px-16 sm:pt-12">
|
||||
<Teleport v-if="page" defer to="#app-header">
|
||||
<DwBreadcrumbs :items="crumbs" :label="$t('page.breadcrumbs')" class="min-w-0 flex-1" />
|
||||
<p
|
||||
role="status"
|
||||
class="hidden truncate text-ui-sm text-ink-muted sm:block"
|
||||
data-testid="collab-status"
|
||||
:class="{ 'text-danger': collabStatus === 'denied' }"
|
||||
>
|
||||
<template v-if="collabStatus === 'denied'">{{ $t("page.collab.denied") }}</template>
|
||||
<template v-else-if="collabStatus === 'offline'">{{ $t("page.collab.offline") }}</template>
|
||||
<template v-else-if="!synced">{{ $t("page.collab.connecting") }}</template>
|
||||
<template v-else-if="others.length">
|
||||
{{ $t("page.collab.alsoHere") }}
|
||||
<span v-for="o in others" :key="o.name + o.color" class="ml-1 font-semibold" :style="{ color: o.color }">{{ o.name }}</span>
|
||||
</template>
|
||||
</p>
|
||||
<DwButton
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="restore"
|
||||
:class="{ 'bg-surface-hover text-ink': historyOpen }"
|
||||
:aria-pressed="historyOpen"
|
||||
data-testid="history-toggle"
|
||||
@click="historyOpen = !historyOpen"
|
||||
>
|
||||
{{ $t("page.history.title") }}
|
||||
</DwButton>
|
||||
</Teleport>
|
||||
|
||||
<article class="mx-auto max-w-doc px-4 pt-6 pb-16 sm:px-16 sm:pt-10">
|
||||
<DwCallout v-if="notFound" tone="info" size="ui">{{ $t("page.notFound") }}</DwCallout>
|
||||
<template v-if="page">
|
||||
<DwBreadcrumbs :items="crumbs" :label="$t('page.breadcrumbs')" />
|
||||
|
||||
<DwCallout v-if="page.inTrash" tone="warning" size="ui" class="mt-4 items-center" role="status">
|
||||
<DwCallout v-if="page.inTrash" tone="warning" size="ui" class="mb-4 items-center" role="status">
|
||||
{{ page.deletedAt ? $t("page.inTrash") : $t("page.parentInTrash") }}
|
||||
<template v-if="page.deletedAt && spaceAtLeast(page.role, 'editor')" #actions>
|
||||
<span class="flex shrink-0 flex-wrap gap-2">
|
||||
@@ -208,7 +235,7 @@ const purge = () =>
|
||||
:placeholder="$t('home.untitled')"
|
||||
:aria-label="$t('page.title')"
|
||||
maxlength="500"
|
||||
class="mt-6 w-full rounded-xs bg-transparent font-serif text-doc-title text-ink outline-none placeholder:text-ink-faint"
|
||||
class="w-full rounded-xs bg-transparent font-serif text-doc-title text-ink outline-none placeholder:text-ink-faint"
|
||||
data-testid="page-title"
|
||||
@input="onTitleInput"
|
||||
@blur="saveTitle"
|
||||
@@ -216,21 +243,6 @@ const purge = () =>
|
||||
/>
|
||||
<p v-if="!spaceAtLeast(page.role, 'editor')" class="mt-2 text-ui-sm text-ink-muted">{{ $t("page.readOnly") }}</p>
|
||||
|
||||
<div class="mt-3 flex min-h-6 flex-wrap items-center justify-between gap-2 text-ui-sm text-ink-muted">
|
||||
<p role="status" data-testid="collab-status" :class="{ 'text-danger': collabStatus === 'denied' }">
|
||||
<template v-if="collabStatus === 'denied'">{{ $t("page.collab.denied") }}</template>
|
||||
<template v-else-if="collabStatus === 'offline'">{{ $t("page.collab.offline") }}</template>
|
||||
<template v-else-if="!synced">{{ $t("page.collab.connecting") }}</template>
|
||||
<template v-else-if="others.length">
|
||||
{{ $t("page.collab.alsoHere") }}
|
||||
<span v-for="o in others" :key="o.name + o.color" class="ml-1 font-semibold" :style="{ color: o.color }">{{ o.name }}</span>
|
||||
</template>
|
||||
</p>
|
||||
<DwButton variant="ghost" size="sm" icon="restore" data-testid="history-toggle" @click="historyOpen = !historyOpen">
|
||||
{{ $t("page.history.title") }}
|
||||
</DwButton>
|
||||
</div>
|
||||
|
||||
<PageHistory v-if="historyOpen" :page="page" :can-restore="editable" class="mt-4" @close="historyOpen = false" @error="emit('error', $event)" />
|
||||
|
||||
<DocwellEditor
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { Space } from "@docwell/api-client";
|
||||
import { DwBadge, DwButton, DwCallout, DwIcon } from "@docwell/ui";
|
||||
import { DwBadge, DwBreadcrumbs, DwButton, DwCallout, DwIcon } from "@docwell/ui";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useApi } from "../../api";
|
||||
@@ -47,26 +47,26 @@ async function newPage() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="mx-auto max-w-doc px-4 pt-8 pb-16 sm:px-16 sm:pt-12">
|
||||
<Teleport v-if="space" defer to="#app-header">
|
||||
<DwBreadcrumbs :items="[{ label: space.name }]" :label="$t('page.breadcrumbs')" class="min-w-0 flex-1" />
|
||||
<RouterLink :to="{ name: 'trash', params: { id: space.id } }" :class="headerLink">
|
||||
<DwIcon name="trash" :size="16" />{{ $t("sidebar.trash") }}
|
||||
</RouterLink>
|
||||
<RouterLink :to="{ name: 'space-settings', params: { id: space.id } }" :class="headerLink">
|
||||
<DwIcon name="settings" :size="16" />{{ $t("space.settings") }}
|
||||
</RouterLink>
|
||||
</Teleport>
|
||||
|
||||
<article class="mx-auto max-w-doc px-4 pt-6 pb-16 sm:px-16 sm:pt-10">
|
||||
<DwCallout v-if="notFound" tone="info" size="ui">{{ $t("space.notFound") }}</DwCallout>
|
||||
<template v-if="space">
|
||||
<div class="flex flex-wrap items-start justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h1 class="font-serif text-doc-h1">{{ space.icon ? `${space.icon} ` : "" }}{{ space.name }}</h1>
|
||||
<p v-if="space.description" class="mt-2 text-doc-body text-ink-muted">{{ space.description }}</p>
|
||||
<p class="mt-3 flex flex-wrap items-center gap-2">
|
||||
<DwBadge v-if="space.visibility === 'private'">{{ $t("space.private") }}</DwBadge>
|
||||
<DwBadge tone="accent">{{ $t(`space.roles.${space.role}`) }}</DwBadge>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-1">
|
||||
<RouterLink :to="{ name: 'trash', params: { id: space.id } }" :class="headerLink">
|
||||
<DwIcon name="trash" :size="16" />{{ $t("sidebar.trash") }}
|
||||
</RouterLink>
|
||||
<RouterLink :to="{ name: 'space-settings', params: { id: space.id } }" :class="headerLink">
|
||||
<DwIcon name="settings" :size="16" />{{ $t("space.settings") }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="font-serif text-doc-h1">{{ space.icon ? `${space.icon} ` : "" }}{{ space.name }}</h1>
|
||||
<p v-if="space.description" class="mt-2 text-doc-body text-ink-muted">{{ space.description }}</p>
|
||||
<p class="mt-3 flex flex-wrap items-center gap-2">
|
||||
<DwBadge v-if="space.visibility === 'private'">{{ $t("space.private") }}</DwBadge>
|
||||
<DwBadge tone="accent">{{ $t(`space.roles.${space.role}`) }}</DwBadge>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="mt-10 flex items-center justify-between gap-2">
|
||||
|
||||
@@ -54,14 +54,17 @@ const when = (s: string) =>
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="mx-auto max-w-doc px-4 pt-8 pb-16 sm:px-16 sm:pt-12">
|
||||
<Teleport v-if="space" defer to="#app-header">
|
||||
<DwBreadcrumbs
|
||||
:items="[{ label: space.name, to: { name: 'space', params: { id: space.id } } }, { label: $t('sidebar.trash') }]"
|
||||
:label="$t('page.breadcrumbs')"
|
||||
/>
|
||||
</Teleport>
|
||||
|
||||
<article class="mx-auto max-w-doc px-4 pt-6 pb-16 sm:px-16 sm:pt-10">
|
||||
<DwCallout v-if="notFound" tone="info" size="ui">{{ $t("space.notFound") }}</DwCallout>
|
||||
<template v-if="space">
|
||||
<DwBreadcrumbs
|
||||
:items="[{ label: space.name, to: { name: 'space', params: { id: space.id } } }, { label: $t('sidebar.trash') }]"
|
||||
:label="$t('page.breadcrumbs')"
|
||||
/>
|
||||
<h1 class="mt-6 font-serif text-doc-h1">{{ $t("sidebar.trash") }}</h1>
|
||||
<h1 class="font-serif text-doc-h1">{{ $t("sidebar.trash") }}</h1>
|
||||
<p class="mt-2 text-ui-md text-ink-muted">{{ $t("trash.hint") }}</p>
|
||||
|
||||
<PageList v-if="items.length" :items="items" class="mt-8" data-testid="trash-list">
|
||||
|
||||
Reference in new issue
Block a user