Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170<script setup lang="ts">import type { Category, PageMeta, SiteVisibility } from "@typbase/typing";
import { pushToast } from "~/composables/toasts";import { PAGE_KIND_ICONS } from "~/lib/view";
const props = defineProps<{ page: PageMeta; categories: Category[]; current: boolean; home: boolean; /** The row is first or last in its group, so that move has nowhere to go. */ first: boolean; last: boolean; /** This row is the one being dragged. */ dragging: boolean; /** How the page appears in the workspace site. */ siteVisibility: SiteVisibility; /** A shared workspace without write access. */ readOnly?: boolean;}>();
const emit = defineEmits<{ (e: "select"): void; (e: "rename"): void; (e: "setHome"): void; (e: "setCategory", categoryId: string | null): void; (e: "setSiteVisibility", visibility: SiteVisibility): void; (e: "convert", kind: PageMeta["kind"]): void; (e: "remove"): void; (e: "move", delta: -1 | 1): void; (e: "dragStart", event: PointerEvent): void;}>();
const { t } = useI18n();
/** The page id is opaque, so the row menu is where a user gets at it. */async function copyId(): Promise<void> { try { await navigator.clipboard.writeText(props.page.id); pushToast({ titleKey: "common.copied", duration: 1800 }); } catch (cause) { console.error("[sidebar] copy id failed:", cause); }}</script>
<template> <li class="sidebar__item" :class="{ 'sidebar__item--active': current, 'sidebar__item--drag': dragging }" data-drag-page @pointerdown="readOnly ? undefined : emit('dragStart', $event)" > <button type="button" class="sidebar__row" :aria-current="current ? 'page' : undefined" @click="emit('select')" > <MsIcon :name="PAGE_KIND_ICONS[page.kind]" :size="20" class="sidebar__row-kind" /> <UiTruncatedText class="sidebar__row-label" :text="page.title" /> <UiTooltip v-if="home" :text="$t('sidebar.homePage')"> <span class="sidebar__row-home"> <MsIcon name="home" :size="18" /> </span> </UiTooltip> </button>
<UiMenu> <template #trigger> <UiIconButton icon="more_vert" :size="20" :label="t('sidebar.actions', { title: page.title })" variant="ghost" class="button--tiny sidebar__row-more" /> </template>
<UiMenuItem icon="edit" :disabled="readOnly" @select="emit('rename')"> {{ $t("common.rename") }} </UiMenuItem> <UiMenuItem icon="content_copy" @select="copyId">{{ $t("common.copyId") }}</UiMenuItem> <UiMenuItem icon="keyboard_double_arrow_up" :disabled="readOnly || first" @select="emit('move', -1)" > {{ $t("common.moveUp") }} </UiMenuItem> <UiMenuItem icon="keyboard_double_arrow_down" :disabled="readOnly || last" @select="emit('move', 1)" > {{ $t("common.moveDown") }} </UiMenuItem> <UiMenuItem icon="home" :disabled="readOnly" @select="emit('setHome')"> {{ $t("sidebar.setHome") }} </UiMenuItem> <UiMenuSub icon="category" :label="$t('common.setCategory')" :disabled="readOnly"> <UiMenuItem :checked="!page.categoryId" @select="emit('setCategory', null)"> {{ $t("newPage.noCategory") }} </UiMenuItem> <UiMenuItem v-for="category in categories" :key="category.id" :checked="page.categoryId === category.id" @select="emit('setCategory', category.id)" > {{ category.name }} </UiMenuItem> </UiMenuSub> <UiMenuItem v-if="page.kind === 'notebook'" icon="description" :disabled="readOnly" @select="emit('convert', 'document')" > {{ $t("common.convertToDocument") }} </UiMenuItem> <UiMenuItem v-else icon="view_agenda" :disabled="readOnly" @select="emit('convert', 'notebook')" > {{ $t("common.convertToNotebook") }} </UiMenuItem> <UiMenuSub v-if="!readOnly" icon="public" :label="$t('site.menu')"> <UiMenuItem :checked="siteVisibility === 'public'" @select="emit('setSiteVisibility', 'public')" > {{ $t("site.visibilityPublic") }} </UiMenuItem> <UiMenuItem :checked="siteVisibility === 'unlisted'" @select="emit('setSiteVisibility', 'unlisted')" > {{ $t("site.visibilityUnlisted") }} </UiMenuItem> <UiMenuItem :checked="siteVisibility === 'private'" @select="emit('setSiteVisibility', 'private')" > {{ $t("site.visibilityPrivate") }} </UiMenuItem> </UiMenuSub> <UiMenuSeparator /> <UiMenuItem danger icon="delete" :disabled="readOnly" @select="emit('remove')"> {{ $t("sidebar.delete") }} </UiMenuItem> </UiMenu> </li></template>
<style>/* The dragged row is a card in the hand: the drag takes it out of the flow and follows the pointer, and this makes it read as lifted. The slight shrink leaves the open slot visible around it. */.sidebar__item--drag { z-index: 2; transform: scale(0.97); background: var(--color-surface); box-shadow: 0 6px 16px rgb(0 0 0 / 0.18);}</style>