Page Tree

Nested pages in favorites, workspace and private sections that you open, drag, rename and add to.

🎙️ Interview: Fieldwork

Move this page in the tree and its trail follows.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/page-tree

Usage

import { PageTree, type TreePage } from "./ui/uicontext/components/kit/PageTree.ts"
const Message = UiSchema.TaggedEnum({	OpenedPage: { page: Schema.String },	RenamedPage: { page: Schema.String, title: Schema.String },})export const Pages = (h: Html.H<typeof Message.Type>, pages: ReadonlyArray<TreePage>, current: string) =>	PageTree(h, {		props: { label: "Pages", pages, current },		onEmit: {			RequestedOpen: ({ page }) => Message.OpenedPage({ page }),			RequestedRename: ({ page, title }) => Message.RenamedPage({ page, title }),			RequestedCreate: () => undefined,			RequestedMove: () => undefined,			RequestedFavorite: () => undefined,			RequestedDuplicate: () => undefined,			RequestedDelete: () => undefined,			RequestedCopyLink: () => undefined,			Expanded: () => undefined,		},	})

Examples

Read-only

For a guest: pages open and expand, and can: [] takes away creating, renaming, moving and deleting.

A large workspace

Two thousand pages in forty teams. Only open pages draw their subpages, so the tree stays quick at any size.

API reference

Props

PageTree props
NameTypeDefaultDescription
labelrequiredstring—The tree's accessible name: "Pages"
pagesrequiredTreePage[]—In order: siblings show in the order they come here
favoritesstring[]—The starred pages, in order
currentstring | null—The page shown now: its row is marked, and its parents are open
expandedstring[]—Pages open at first
canCan(["create", "rename", "move", "delete"])—Create, rename, move, delete; all by default
agentIdstringpage-tree:<label>This tree's id for agents, unique on the page; page-tree:<label> by default

Events

PageTree events
EventPayloadDescription
RequestedOpen{ page: string }A page without a link was opened
RequestedCreate{ parent: string | null; section: PageSection }A new page: inside parent, or at the top of section
RequestedRename{ page: string; title: string }Give this page a new title
RequestedMove{ page: string; parent: string | null; section: PageSection; before: string | null }Into parent (null: the top of section), before before (null: last); movePage applies it
RequestedFavorite{ page: string; favorite: boolean }Add the page to favorites, or take it out
RequestedDuplicate{ page: string }Make a copy of this page beside it
RequestedDelete{ page: string }Move it to the trash
RequestedCopyLink{ page: string }Copy a link to this page
Expanded{ page: string }Opened: load its subpages if they aren't there yet

Agent actions

What agents can do with PageTree
ActionDescription
OpenedPageOpen a page by its id (see page_query for every page)
MovedPageMove a page into another (parent: its id) or to the top of a section (parent: null), before a sibling (before: its id) or last (null)

Accessibility

  • Each section is a WAI-ARIA tree and one Tab stop: Up and Down move, Right opens or moves in, Left closes or moves out, Home and End jump, and typing jumps to a title.
  • F2 renames in place (Enter keeps it, Escape cancels) and Shift+F10 opens a row's menu. Alt with the arrow keys moves a page, and focus follows it.
  • Drops show a line before or after a row, or highlight the row for inside, and every drag has a keyboard twin.

Source