feat(workspace): integrate persisted canvas, element editing and session renewal

This commit is contained in:
2026-11-06 12:50:43 +08:00
parent 45e78f2e43
commit 373582906d
36 changed files with 1028 additions and 193 deletions
+5 -3
View File
@@ -1,15 +1,17 @@
import type { Profile } from "./api";
export type Workspace = { id: string; name: string; role?: "admin" | "editor" | "viewer" };
export type Workspace = { id: string; slug?: string; name: string; role?: "admin" | "editor" | "viewer" };
export type Board = {
id: string;
workspace_id: string;
slug?: string;
kind: "board";
title: string;
version: number;
content?: { schema_version: number };
description?: string;
};
export function matchesRef(item: { id: string; slug?: string } | null | undefined, ref: string | undefined) { return Boolean(item && ref && (item.id === ref || item.slug === ref)); }
export const DEFAULT_BOARD_TITLE = "未命名图谱";
export function boardHref(workspace: string, board: string, demo = false) {
@@ -47,7 +49,7 @@ export async function createBoard(
onWorkspaceCreated(workspace);
}
const name = title.trim() || DEFAULT_BOARD_TITLE;
const result = await request<{ id: string; workspace_id: string; kind: "board"; version: number }>("workspaces/" + id + "/materials", {
const result = await request<{ id: string; workspace_id: string; kind: "board"; version: number; slug?: string }>("workspaces/" + id + "/materials", {
method: "POST",
body: JSON.stringify({
kind: "board",
@@ -64,7 +66,7 @@ export async function renameBoard(request: Request, workspaceId: string, boardId
if (!name || new TextEncoder().encode(name).length > 300) throw new Error("invalid_title");
const path = `workspaces/${encodeURIComponent(workspaceId)}/materials/${encodeURIComponent(boardId)}`;
const current = await request<Board>(path);
if (current.kind !== "board" || current.id !== boardId || current.workspace_id !== workspaceId) throw new Error("invalid_reference");
if (current.kind !== "board" || !matchesRef(current, boardId) || current.workspace_id !== workspaceId) throw new Error("invalid_reference");
await request(path, {
method: "PATCH",
headers: { "If-Match": `"${current.version}"` },