CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Successful in 1h36m55s
CI / mobile (push) Failing after 1m47s
CI / go (Media) (push) Successful in 19m45s
CI / go (Server) (push) Failing after 26m1s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 8m49s
CI / docker (push) Failing after 37m4s
Turn into: the selection toolbar starts with the block's kind ("Heading 1")
and opens the list of kinds it can become, with a tick on the current
one. In a list it turns the whole list, as the block menu did; the grip
menu no longer has it.
Page icons: an editor clicks a page's icon in the sidebar tree to pick an
emoji from groups, recent picks or a search by name (any pasted emoji
works too), or to remove it. The emoji now stands in for the page glyph
rather than sitting before the title. Strings in all five languages.
Block handles: the link and grip buttons stay on the block the cursor is
in, which is highlighted while the editor has focus, sit centred on the
block's height, and no longer vanish crossing the gap from the text.
The sidebar shows the Docwell logo above the workspace switcher.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
5.9 KiB
Vue
196 lines
5.9 KiB
Vue
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
|
<script setup lang="ts">
|
|
import type { PageNode } from "@docwell/api-client";
|
|
import { DwButton, DwIcon, DwTreeItem } from "@docwell/ui";
|
|
import { computed, ref } from "vue";
|
|
import { useRouter } from "vue-router";
|
|
import { dropPlacement, zoneAt, type DropZone } from "../lib/tree";
|
|
import { useSpacesStore } from "../stores/spaces";
|
|
import EmojiPicker from "./EmojiPicker.vue";
|
|
|
|
const props = defineProps<{ spaceId: string; node: PageNode; depth: number }>();
|
|
const emit = defineEmits<{ error: [err: unknown] }>();
|
|
const spaces = useSpacesStore();
|
|
const router = useRouter();
|
|
|
|
const kids = computed(() => spaces.childrenOf(props.spaceId, props.node.id));
|
|
const open = computed(() => spaces.isExpanded(props.node.id));
|
|
const editable = computed(() => spaces.canEdit(props.spaceId));
|
|
const active = computed(() => spaces.active.page === props.node.id);
|
|
const zone = ref<DropZone | null>(null);
|
|
|
|
// The page's icon: an emoji, or the page glyph. Editors click it to pick another.
|
|
const iconButton = ref<HTMLElement | null>(null);
|
|
const picking = ref(false);
|
|
async function setIcon(icon: string) {
|
|
picking.value = false;
|
|
try {
|
|
await spaces.setIcon(props.spaceId, props.node.id, icon);
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
|
|
function onDragStart(e: DragEvent) {
|
|
spaces.dragging = { spaceId: props.spaceId, id: props.node.id };
|
|
e.dataTransfer?.setData("text/plain", props.node.id);
|
|
if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
|
|
}
|
|
|
|
// Pages move only within their space; a drop is allowed when it changes something valid.
|
|
function placement(z: DropZone) {
|
|
const d = spaces.dragging;
|
|
if (!d || d.spaceId !== props.spaceId) return null;
|
|
return dropPlacement(spaces.trees[props.spaceId] ?? [], d.id, props.node.id, z);
|
|
}
|
|
|
|
function onDragOver(e: DragEvent) {
|
|
const el = e.currentTarget as HTMLElement;
|
|
const z = zoneAt(e.offsetY, el.clientHeight);
|
|
zone.value = placement(z) ? z : null;
|
|
if (zone.value) e.preventDefault();
|
|
}
|
|
|
|
async function onDrop() {
|
|
const z = zone.value;
|
|
zone.value = null;
|
|
const d = spaces.dragging;
|
|
const to = z && placement(z);
|
|
spaces.dragging = null;
|
|
if (!d || !to) return;
|
|
try {
|
|
await spaces.move(props.spaceId, d.id, to.parent, to.index);
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
|
|
async function addChild() {
|
|
try {
|
|
const page = await spaces.createPage(props.spaceId, props.node.id);
|
|
router.push({ name: "page", params: { id: page.id } });
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
|
|
async function trash() {
|
|
try {
|
|
await spaces.trash(props.spaceId, props.node.id);
|
|
if (active.value) router.push({ name: "space", params: { id: props.spaceId } });
|
|
} catch (e) {
|
|
emit("error", e);
|
|
}
|
|
}
|
|
|
|
const dropClass = computed(() => {
|
|
switch (zone.value) {
|
|
case "before":
|
|
return "shadow-[inset_0_2px_0_var(--color-focus-ring)]";
|
|
case "after":
|
|
return "shadow-[inset_0_-2px_0_var(--color-focus-ring)]";
|
|
case "inside":
|
|
return "bg-accent-soft";
|
|
}
|
|
return "";
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<li>
|
|
<DwTreeItem
|
|
:title="node.title || $t('home.untitled')"
|
|
:depth="depth"
|
|
:has-children="kids.length > 0"
|
|
:expanded="open"
|
|
:active="active"
|
|
:toggle-label="open ? $t('sidebar.collapse') : $t('sidebar.expand')"
|
|
:class="dropClass"
|
|
:draggable="editable"
|
|
data-testid="tree-row"
|
|
@toggle="spaces.setExpanded(node.id, !open)"
|
|
@dragstart="onDragStart"
|
|
@dragend="spaces.dragging = null"
|
|
@dragover="onDragOver"
|
|
@dragleave="zone = null"
|
|
@drop.prevent="onDrop"
|
|
>
|
|
<template #icon>
|
|
<button
|
|
v-if="editable"
|
|
ref="iconButton"
|
|
type="button"
|
|
class="grid size-5 shrink-0 cursor-pointer place-items-center rounded-xs hover:bg-line"
|
|
:class="{ 'bg-line': picking }"
|
|
:aria-label="$t('emoji.changeIcon')"
|
|
:title="$t('emoji.changeIcon')"
|
|
aria-haspopup="dialog"
|
|
:aria-expanded="picking"
|
|
data-testid="page-icon"
|
|
@click.stop="picking = !picking"
|
|
>
|
|
<span v-if="node.icon" class="text-ui-md leading-none">{{ node.icon }}</span>
|
|
<DwIcon v-else name="page" :size="16" />
|
|
</button>
|
|
<span v-else-if="node.icon" class="grid size-5 shrink-0 place-items-center text-ui-md leading-none">{{
|
|
node.icon
|
|
}}</span>
|
|
<DwIcon v-else name="page" :size="16" />
|
|
</template>
|
|
<RouterLink
|
|
:to="{ name: 'page', params: { id: node.id } }"
|
|
class="block truncate rounded-xs"
|
|
:class="active ? 'text-accent' : 'text-inherit'"
|
|
:aria-current="active ? 'page' : undefined"
|
|
>
|
|
{{ node.title || $t("home.untitled") }}
|
|
<DwIcon
|
|
v-if="node.restricted"
|
|
name="lock"
|
|
:size="12"
|
|
class="ml-1 !inline-block align-[-1px] text-ink-muted"
|
|
:label="$t('share.restrictedBadge')"
|
|
/>
|
|
</RouterLink>
|
|
<template v-if="editable" #actions>
|
|
<DwButton
|
|
variant="ghost"
|
|
size="sm"
|
|
icon="plus"
|
|
class="!size-6"
|
|
:aria-label="$t('sidebar.addSubpage')"
|
|
:title="$t('sidebar.addSubpage')"
|
|
@click="addChild"
|
|
/>
|
|
<DwButton
|
|
variant="ghost"
|
|
size="sm"
|
|
icon="trash"
|
|
class="!size-6"
|
|
:aria-label="$t('page.moveToTrash')"
|
|
:title="$t('page.moveToTrash')"
|
|
@click="trash"
|
|
/>
|
|
</template>
|
|
</DwTreeItem>
|
|
<EmojiPicker
|
|
v-if="picking && iconButton"
|
|
:anchor="iconButton"
|
|
:current="node.icon"
|
|
@pick="setIcon"
|
|
@remove="setIcon('')"
|
|
@close="picking = false"
|
|
/>
|
|
<ul v-if="open && kids.length" role="group" class="mt-px flex flex-col gap-px">
|
|
<PageTreeNode
|
|
v-for="k in kids"
|
|
:key="k.id"
|
|
:space-id="spaceId"
|
|
:node="k"
|
|
:depth="depth + 1"
|
|
@error="emit('error', $event)"
|
|
/>
|
|
</ul>
|
|
</li>
|
|
</template>
|