Make the box canvas reusable: canvas pages, admin-only boxes, landing notes
Test and deploy / test (push) Successful in 2m8s
Test and deploy / deploy (push) Successful in 1m8s

The /stp canvas is now BoxCanvas.vue, keyed by a page. Boxes carry a
page ("stp", "index" for the landing page's notes overlay, or a Page
slug) and an adminOnly flag that the boxes resolver filters server-side.

A new Page type lets the admin create canvas pages in the browser,
served at /<slug> by the router's catch-all (CanvasPage.vue), starting
from a Blank, Shrine or Notes-board layout. Slugs that an SPA or nginx
route would answer first are refused. Renaming a page moves its boxes;
deleting it deletes them.

The GTO, Evangelion and Skipskipbenben placeholder routes are dropped
in favour of canvas pages listed on /shrines, which the landing page
now links to. The box editor gains an admin-only toggle and an
upload-and-insert button, and there are Note, Heading, Text, Gallery
and Video templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 23:36:48 +01:00
co-authored by Claude Opus 5.5
parent 44347e40eb
commit bb5fd2bef9
35 changed files with 2638 additions and 499 deletions
+45 -23
View File
@@ -1,19 +1,26 @@
/**
* Boxes on the /stp canvas (views/home3/) — full CRUD, built on
* Boxes on one canvas page (views/home3/BoxCanvas.vue) — full CRUD, built on
* createCrudStore().
*
* `useBoxesStore(page)` returns the store for that page key: "stp" for the
* home page, "index" for the landing page's overlay, or a Page slug. Each key
* gets its own Pinia store (id `boxes:<page>`), so moving between pages
* neither refetches a page already visited nor mixes two pages' boxes.
*
* Not part of the homeData query: the canvas has to know which boxes exist
* before it can mount the widgets that then trigger homeData, and keeping the
* two apart means a failing Spotify/Steam upstream can't blank the layout.
*
* The list query returns boxes ordered by z, so a new box (given the top z)
* belongs at the end.
* belongs at the end. adminOnly boxes only come back for an admin — the
* server filters them — so the canvas refetches when the session changes.
*/
import { createCrudStore } from "@/stores/createCrudStore";
const BOX_FIELDS = `
id
page
kind
widget
html
@@ -25,30 +32,45 @@ const BOX_FIELDS = `
z
framed
hideOnMobile
adminOnly
`;
// The fields a duplicate copies. kind and widget/html are what make it the
// same box; geometry is offset so the copy is visibly separate.
const COPIED = ["kind", "widget", "html", "title", "w", "h", "framed", "hideOnMobile"];
const COPIED = ["page", "kind", "widget", "html", "title", "w", "h", "framed", "hideOnMobile", "adminOnly"];
export const useBoxesStore = createCrudStore("boxes", {
type: "Box",
list: "boxes",
fields: BOX_FIELDS,
insert: "append",
deleteReturns: "object",
extend: ({ items, create, update }) => {
const topZ = () => Math.max(0, ...items.value.map((b) => b.z)) + 1;
const bottomZ = () => Math.min(0, ...items.value.map((b) => b.z)) - 1;
const stores = new Map();
return {
topZ,
bringToFront: (box) => update(box.id, { z: topZ() }),
sendToBack: (box) => update(box.id, { z: bottomZ() }),
duplicate: (box) => {
const input = Object.fromEntries(COPIED.map((k) => [k, box[k]]));
return create({ ...input, x: box.x + 20, y: box.y + 20, z: topZ() });
},
};
},
});
function defineFor(page) {
return createCrudStore(`boxes:${page}`, {
type: "Box",
list: "boxes",
fields: BOX_FIELDS,
insert: "append",
deleteReturns: "object",
args: { page: { type: "String!", value: page } },
extend: ({ items, create, update }) => {
const topZ = () => Math.max(0, ...items.value.map((b) => b.z)) + 1;
const bottomZ = () => Math.min(0, ...items.value.map((b) => b.z)) - 1;
return {
page,
topZ,
// Every box this store creates belongs to its page.
create: (input) => create({ ...input, page }),
bringToFront: (box) => update(box.id, { z: topZ() }),
sendToBack: (box) => update(box.id, { z: bottomZ() }),
duplicate: (box) => {
const input = Object.fromEntries(COPIED.map((k) => [k, box[k]]));
return create({ ...input, x: box.x + 20, y: box.y + 20, z: topZ() });
},
};
},
});
}
/** The boxes store for one page key. */
export function useBoxesStore(page) {
if (!stores.has(page)) stores.set(page, defineFor(page));
return stores.get(page)();
}
+18 -1
View File
@@ -37,6 +37,10 @@ import { gql } from "@/graphql";
* one, so the mutation text differs; the schema has both kinds.
* @param {(ctx: object) => object} [options.extend] extra state/actions merged
* into the store; receives the base members
* @param {Record<string, {type: string, value: *}>} [options.args] arguments
* for the list query, e.g. `{ page: { type: "String!", value: "stp" } }`.
* Fixed for the store's lifetime, so a list that varies needs one store per
* value (stores/boxes.js does this per page).
*/
export function createCrudStore(
id,
@@ -48,10 +52,20 @@ export function createCrudStore(
insert = "prepend",
deleteReturns = "object",
extend,
args = {},
},
) {
const deleteSelection = deleteReturns === "object" ? "{ id }" : "";
const argNames = Object.keys(args);
const listVarDecl = argNames.length
? `(${argNames.map((n) => `$${n}: ${args[n].type}`).join(", ")})`
: "";
const listArgs = argNames.length
? `(${argNames.map((n) => `${n}: $${n}`).join(", ")})`
: "";
const listVars = Object.fromEntries(argNames.map((n) => [n, args[n].value]));
return defineStore(id, () => {
const items = ref([]);
const loaded = ref(false);
@@ -62,7 +76,10 @@ export function createCrudStore(
async function fetch() {
loading.value = true;
try {
const data = await gql(`query ${type}List { ${list} { ${fields} } }`);
const data = await gql(
`query ${type}List${listVarDecl} { ${list}${listArgs} { ${fields} } }`,
listVars,
);
items.value = data[list] || [];
loaded.value = true;
error.value = null;
+27
View File
@@ -0,0 +1,27 @@
/**
* Admin-created canvas pages (the `Page` GraphQL type) — full CRUD, built on
* createCrudStore().
*
* A page is only a slug and a title; what is on it lives in that slug's boxes
* store (stores/boxes.js). The list is public apart from adminOnly pages,
* which the server only returns to an admin. Single pages are looked up by
* views/canvas/CanvasPage.vue with its own `page(slug:)` query, so that
* opening one page doesn't download the whole list.
*/
import { createCrudStore } from "@/stores/createCrudStore";
export const PAGE_FIELDS = `
id
slug
title
adminOnly
`;
export const usePagesStore = createCrudStore("pages", {
type: "Page",
list: "pages",
fields: PAGE_FIELDS,
insert: "append",
deleteReturns: "object",
});