Sidebar (web/components/sidebar.tsx) reorganized to the requested structure:
Quick find at the top; a Pages group (All Pages tree with the existing
rename/reorder/pin/subpage/delete interactions, Pinned Pages, Untagged
Pages); a Bookmarks group (All Bookmarks, Calendar, and expandable carets
for Tags / Kanban / Collections / Contacts listing their entities with
deep-links /tags?tag=, /kanban?column=, /collections?id=, /contacts?open=);
Trash at the bottom. Collapsed desktop rail is a flat icon list; the mobile
drawer shows the full grouped nav.
Page tagging (new): PageTag join (migration 023 + schema.sql, db-converge
proven), POST/DELETE /api/pages/{id}/tags with owner-or-TagShare validation
(same rule as bookmark tags), tags exposed in the page list/detail
projections so the sidebar can compute the untagged subset. Tagging is
metadata (no content-version bump) and cascades on page/tag delete.
Dragging a page from Untagged Pages onto a tag assigns it (custom drag MIME
keeps it distinct from page reorder).
Kanban: only explicitly-placed cards render (no auto-populate of unassigned
bookmarks); the sidebar caret lists the existing columns and ?column=
scrolls/rings the target. e2e updated to assert no-auto-populate then place
the card explicitly.
All Bookmarks: a Group by selector (None/Calendar/Tags/Kanban/Collections/
Contacts) rendering grouped sections via shared row/card renderers; the
default None path is byte-identical to before (205-row table, same keys).
Collections grouping fetches membership once, sequence-guarded.
Calendar: Day/Week/Month/Year/List views (Month default), adaptive
prev/next + Today, date-sorted list; SSR-safe (date-fns only, post-mount
today), internal overflow containers so no page-level horizontal scroll.
Deep-link page wrappers for kanban/collections/contacts pass searchParams
into the clients' initial selection.
Test gate: the -race internal/http suite now exceeds the default 10m go
test timeout (~14m cold-cache), so the tests service and Makefile test
target use -timeout 30m; the suite passes in full.
Verified: regressions 20/20, real-stack e2e all pass, lint/SSR-lint/build
0 errors, db-converge green, full Go integration suite green; browser
checks of the grouped sidebar, drag-to-tag, bookmark group-by and every
calendar view show correct rendering with no horizontal overflow.
90 lines
3.5 KiB
TypeScript
90 lines
3.5 KiB
TypeScript
export const PAGES_CHANGED = 'superbrain:pages-changed'
|
|
|
|
export const notifyPagesChanged = () => window.dispatchEvent(new Event(PAGES_CHANGED))
|
|
|
|
// Notion-style breadcrumbs: the pages workspace announces which page is open
|
|
// so the top bar can show "superbrain / Pages / <title>" without refetching.
|
|
export const ACTIVE_PAGE_CHANGED = 'superbrain:active-page-changed'
|
|
|
|
export const notifyActivePage = (title: string | null) =>
|
|
window.dispatchEvent(new CustomEvent<string | null>(ACTIVE_PAGE_CHANGED, { detail: title }))
|
|
|
|
export type PageSummary = {
|
|
id: string
|
|
title: string
|
|
pinned: boolean
|
|
position: number
|
|
parentId: string | null
|
|
tags?: { tag: { id: string; name: string; color: string } }[]
|
|
_count?: { bookmarks: number; children?: number }
|
|
}
|
|
|
|
// Connected pages (phase 3): the same link forms the editor understands,
|
|
// shared by the page client, sidebar and Markdown preview. Page links use
|
|
// `superbrain:page/<id>`; /pages?id=<id> is accepted for hand-written links.
|
|
export function internalPageId(href: string): string | null {
|
|
const value = href.trim().replace(/^<|>$/g, '')
|
|
let raw = ''
|
|
if (value.startsWith('superbrain://page/')) raw = value.slice('superbrain://page/'.length)
|
|
else if (value.startsWith('superbrain:page/')) raw = value.slice('superbrain:page/'.length)
|
|
else if (value.startsWith('page/')) raw = value.slice('page/'.length)
|
|
else if (value.startsWith('/pages/')) raw = value.slice('/pages/'.length)
|
|
else if (value.startsWith('/pages?') || value.startsWith('superbrain:page?id=') || value.startsWith('superbrain://page?id=')) {
|
|
try {
|
|
const id = new URL(value, 'http://localhost').searchParams.get('id')
|
|
raw = id ?? ''
|
|
} catch { raw = '' }
|
|
}
|
|
raw = raw.replace(/\/$/, '')
|
|
return /^[A-Za-z0-9_-]{1,128}$/.test(raw) ? raw : null
|
|
}
|
|
|
|
export const pageLinkMarkdown = (page: Pick<PageSummary, 'id' | 'title'>) =>
|
|
`[${page.title.replace(/[\[\]\n]/g, ' ')}](superbrain:page/${page.id})`
|
|
|
|
export type PageEmbedMarker = { collectionId: string; viewId: string | null }
|
|
|
|
export function parsePageEmbed(value: string): PageEmbedMarker | null {
|
|
const m = /^\{\{\s*collection:([A-Za-z0-9_-]{1,128})(?:\s*\|\s*view=([A-Za-z0-9_-]{1,128}))?\s*\}\}$/.exec(value.trim())
|
|
if (!m) return null
|
|
return { collectionId: m[1], viewId: m[2] ?? null }
|
|
}
|
|
|
|
export const collectionEmbedMarkdown = (collectionId: string, viewId?: string | null) =>
|
|
`{{collection:${collectionId}${viewId ? `|view=${viewId}` : ''}}}`
|
|
|
|
// Ids below `id` in the current page tree. Used to keep the parent picker
|
|
// from offering a descendant (the server rejects the cycle regardless).
|
|
export function descendantPageIds(pages: PageSummary[], id: string): Set<string> {
|
|
const out = new Set<string>()
|
|
const children = new Map<string, string[]>()
|
|
for (const p of pages) {
|
|
if (!p.parentId) continue
|
|
const list = children.get(p.parentId) ?? []
|
|
list.push(p.id)
|
|
children.set(p.parentId, list)
|
|
}
|
|
const walk = (parent: string) => {
|
|
for (const child of children.get(parent) ?? []) {
|
|
if (out.has(child)) continue
|
|
out.add(child)
|
|
walk(child)
|
|
}
|
|
}
|
|
walk(id)
|
|
return out
|
|
}
|
|
|
|
// Pages start as "Untitled 1", "Untitled 2", ... until the user renames them.
|
|
// Pick the lowest positive integer not already used by an untitled page.
|
|
export function nextUntitledTitle(titles: string[]): string {
|
|
const used = new Set<number>()
|
|
for (const t of titles) {
|
|
const m = /^Untitled (\d+)$/.exec(t.trim())
|
|
if (m) used.add(parseInt(m[1], 10))
|
|
}
|
|
let n = 1
|
|
while (used.has(n)) n++
|
|
return `Untitled ${n}`
|
|
}
|