feat: global block library tree + grouping tool — 19 files, 588 tests green
This commit is contained in:
@@ -510,6 +510,102 @@ export async function deleteProjectShare(token: string, shareId: string): Promis
|
||||
if (!res.ok) throw new Error('Failed to delete share');
|
||||
}
|
||||
|
||||
// ─── Global Block Folders ───────────────────────────────────
|
||||
export interface GlobalBlockFolder {
|
||||
id: string;
|
||||
name: string;
|
||||
parent_id: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export async function getGlobalFolders(token: string, parentId?: string | null): Promise<GlobalBlockFolder[]> {
|
||||
const url = parentId !== undefined
|
||||
? `${API_BASE}/api/global-folders?parentId=${parentId === null ? 'null' : parentId}`
|
||||
: `${API_BASE}/api/global-folders`;
|
||||
const res = await fetch(url, { headers: authHeaders(token) });
|
||||
if (!res.ok) throw new Error('Failed to load global folders');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function createGlobalFolder(token: string, name: string, parentId?: string | null): Promise<GlobalBlockFolder> {
|
||||
const res = await fetch(`${API_BASE}/api/global-folders`, {
|
||||
method: 'POST',
|
||||
headers: authHeaders(token),
|
||||
body: JSON.stringify({ name, parent_id: parentId ?? null }),
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to create global folder');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function renameGlobalFolder(token: string, id: string, name: string): Promise<GlobalBlockFolder> {
|
||||
const res = await fetch(`${API_BASE}/api/global-folders/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: authHeaders(token),
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to rename global folder');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function deleteGlobalFolder(token: string, id: string): Promise<void> {
|
||||
await fetch(`${API_BASE}/api/global-folders/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: authHeaders(token),
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Global Blocks ────────────────────────────────────────
|
||||
export interface GlobalBlock {
|
||||
id: string;
|
||||
folder_id: string | null;
|
||||
name: string;
|
||||
block_data: string;
|
||||
svg_data: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export async function getGlobalBlocks(token: string, folderId?: string | null): Promise<GlobalBlock[]> {
|
||||
const url = folderId !== undefined
|
||||
? `${API_BASE}/api/global-blocks?folderId=${folderId === null ? 'null' : folderId}`
|
||||
: `${API_BASE}/api/global-blocks`;
|
||||
const res = await fetch(url, { headers: authHeaders(token) });
|
||||
if (!res.ok) throw new Error('Failed to load global blocks');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function createGlobalBlock(token: string, data: {
|
||||
name: string;
|
||||
folder_id?: string | null;
|
||||
block_data?: string;
|
||||
svg_data?: string;
|
||||
}): Promise<GlobalBlock> {
|
||||
const res = await fetch(`${API_BASE}/api/global-blocks`, {
|
||||
method: 'POST',
|
||||
headers: authHeaders(token),
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to create global block');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function renameGlobalBlock(token: string, id: string, name: string): Promise<GlobalBlock> {
|
||||
const res = await fetch(`${API_BASE}/api/global-blocks/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: authHeaders(token),
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to rename global block');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function deleteGlobalBlock(token: string, id: string): Promise<void> {
|
||||
await fetch(`${API_BASE}/api/global-blocks/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: authHeaders(token),
|
||||
});
|
||||
}
|
||||
|
||||
export { API_BASE };
|
||||
|
||||
// ─── AI Copilot ─────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user