Make /stp an admin-editable canvas of boxes
/stp is now views/home3/Home3.vue: boxes an admin creates, drags, resizes and edits in the browser, saved to the database so every visitor sees the same layout. - backend: a Box GraphQL type (kind widget|html, x/y/w/h/z in px on a 1400px design canvas, framed, hideOnMobile). Public `boxes` query; create/update/delete are @admin. Geometry is clamped rather than rejected. Framed has no gorm default, since GORM would turn an explicit false into true on insert. - vue: widget boxes render the existing widgets from a registry; html boxes render in an iframe sandboxed with allow-scripts and no allow-same-origin, so admin script can't read cookies or call /api. The site tokens and fonts (inlined as data: URLs) are injected into each frame. The canvas scales to fit the window; phones get a single column in (y, x) order. Edit mode saves geometry on release and has a CodeMirror side panel (lazy-loaded) with a live HTML preview. Templates cover Clock, Weather (Open-Meteo) and Image/GIF. "Import current layout" recreates the old Home.vue grid on an empty canvas. - Home.vue is kept with a STATUS: legacy header. Docs updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Boxes on the /stp canvas (views/home3/) — full CRUD, built on
|
||||
* createCrudStore().
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { createCrudStore } from "@/stores/createCrudStore";
|
||||
|
||||
const BOX_FIELDS = `
|
||||
id
|
||||
kind
|
||||
widget
|
||||
html
|
||||
title
|
||||
x
|
||||
y
|
||||
w
|
||||
h
|
||||
z
|
||||
framed
|
||||
hideOnMobile
|
||||
`;
|
||||
|
||||
// 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"];
|
||||
|
||||
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;
|
||||
|
||||
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() });
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user