Pages can now be shared with people and groups beyond their space, and restricted so that only those grants count. A grant covers the page and everything under it. Space admins always keep access, and an editor who restricts a page keeps editor through a grant of their own. Sharing a page with someone from the organization who is outside the workspace adds them as a guest. Anyone else gets a guest invite that carries the page grant, which is made when they accept. Guests see a "limited" space holding only the pages shared with them. The page tree, breadcrumbs, search, favorites, recents, trash and import all follow the page role. Public links skip restricted subtrees. Grants are cleaned up when a member leaves or a group is deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
154 lines
4.6 KiB
Vue
154 lines
4.6 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";
|
|
|
|
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);
|
|
|
|
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"
|
|
>
|
|
<RouterLink
|
|
:to="{ name: 'page', params: { id: node.id } }"
|
|
class="block truncate rounded-xs"
|
|
:class="active ? 'text-accent' : 'text-inherit'"
|
|
:aria-current="active ? 'page' : undefined"
|
|
>
|
|
<span v-if="node.icon" class="mr-1">{{ node.icon }}</span
|
|
>{{ 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>
|
|
<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>
|