Add saved layouts, and make /stp an ordinary canvas page
Test and deploy / test (push) Successful in 1m51s
Test and deploy / deploy (push) Successful in 1m10s

A layout is a named copy of one canvas page's boxes and background
(models.Layout, layout.graphql), saved from the canvas's new Layouts
button and loaded onto any page from there or from the admin Pages
tab. Loading onto a page with boxes asks whether to replace them or
add on top; a replace first saves the page as a "<page> before
<layout>" layout so it can be undone. Copies, not links: editing a
page never changes a layout or another page. The copying is
server-side in one transaction, and everything is @admin since a
layout keeps admin-only boxes.

/stp loses its static route and becomes a Page with slug "stp",
created once at start-up (ensureStpPage), so it can be renamed,
hidden or deleted like a shrine. Its boxes were already keyed "stp".
Home3.vue is kept as legacy; its starter is now "Old /stp grid" in
pageStarters.js. ConfirmDialog gains an optional second button.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 20:33:07 +01:00
co-authored by Claude Opus 5.5
parent 8c535b1cc2
commit 2eacbc2e33
28 changed files with 1947 additions and 68 deletions
+109 -2
View File
@@ -7,8 +7,13 @@
* "New shrine" is the same form with the address fixed under /shrines/. It
* starts blank and adds no link anywhere: /shrines is itself a canvas page,
* and its links are boxes put there by hand.
*
* "Layouts" lists the saved layouts (stores/layouts.js) and copies one onto
* any page without opening it — the same as "Load here" in that page's
* Layouts panel, where layouts are also saved and renamed.
*/
import { usePagesStore } from "@/stores/pages";
import { pagePath, useLayoutsStore } from "@/stores/layouts";
import PageForm from "@/views/canvas/PageForm.vue";
import { ref } from "vue";
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
@@ -19,6 +24,46 @@ const removeTarget = ref(null);
const confirmationOpen = ref(false);
const removeError = ref("");
const layouts = useLayoutsStore();
layouts.fetch();
const layoutError = ref("");
const layoutNotice = ref("");
// { layout, page } waiting on "replace or add?", and the layout to delete.
const copyRequest = ref(null);
const deleteLayoutTarget = ref(null);
function askCopy(layout, event) {
const page = event.target.value;
event.target.value = "";
if (page) copyRequest.value = { layout, page };
}
async function layoutAction(action, done) {
layoutError.value = "";
layoutNotice.value = "";
try {
await action();
layoutNotice.value = done;
} catch (err) {
layoutError.value = err?.message || "Failed";
}
}
function copy(replace) {
const { layout, page } = copyRequest.value;
copyRequest.value = null;
layoutAction(
() => layouts.apply(layout.id, page, replace),
`“${layout.name}” ${replace ? "now fills" : "was added to"} ${pagePath(page)}.`,
);
}
function confirmDeleteLayout() {
const layout = deleteLayoutTarget.value;
deleteLayoutTarget.value = null;
layoutAction(() => layouts.remove(layout.id), `Deleted “${layout.name}”.`);
}
async function remove(page) {
removeTarget.value = page;
confirmationOpen.value = true;
@@ -42,8 +87,8 @@ async function confirmRemove() {
<section>
<h1>Pages</h1>
<p class="text-muted">
The home page (/stp) and the landing page's notes are canvases too —
edit those on the pages themselves.
The landing page (/) is a canvas too, but not listed here — edit it on
the page itself.
</p>
<p v-if="removeError" class="text-tertiary" role="alert">
{{ removeError }}
@@ -64,6 +109,39 @@ async function confirmRemove() {
<p v-else-if="pages.loaded" class="text-muted">No pages yet.</p>
</section>
<section>
<h1>Layouts</h1>
<p class="text-muted">
Saved copies of a page's boxes and background. Save one from a page's
Layouts button; copy it onto another page here or from that page.
Replacing a page's contents saves them as a layout first.
</p>
<p v-if="layoutError" class="text-tertiary" role="alert">{{ layoutError }}</p>
<p v-else-if="layoutNotice" class="text-muted" role="status">{{ layoutNotice }}</p>
<p v-if="layouts.error" class="text-tertiary">Couldn't load the layouts.</p>
<table v-else-if="layouts.layouts.length" class="w-full">
<tr v-for="layout in layouts.layouts" :key="layout.id">
<td>{{ layout.name }}</td>
<td class="text-muted">
from {{ pagePath(layout.sourcePage) }} · {{ layout.boxCount }} box{{ layout.boxCount === 1 ? "" : "es" }}
</td>
<td>
<select class="copy-select" aria-label="Copy onto page" @change="askCopy(layout, $event)">
<option value="">Copy onto…</option>
<option value="index">/ (landing)</option>
<option v-for="page in pages.pages" :key="page.id" :value="page.slug">/{{ page.slug }}</option>
</select>
</td>
<td class="text-right">
<button type="button" class="text-tertiary cursor-pointer" @click="deleteLayoutTarget = layout">
Delete
</button>
</td>
</tr>
</table>
<p v-else-if="layouts.loaded" class="text-muted">No saved layouts yet.</p>
</section>
<section>
<h1>New shrine</h1>
<p class="text-muted">
@@ -87,5 +165,34 @@ async function confirmRemove() {
@confirm="confirmRemove"
@cancel="removeTarget = null"
/>
<ConfirmDialog
v-if="copyRequest"
:model-value="true"
title="Copy layout"
:message="`Replace everything on ${pagePath(copyRequest.page)} with “${copyRequest.layout.name}”, or add it on top? Replacing saves the page as a layout first.`"
confirm-label="Replace"
secondary-label="Add on top"
@confirm="copy(true)"
@secondary="copy(false)"
@cancel="copyRequest = null"
/>
<ConfirmDialog
v-if="deleteLayoutTarget"
:model-value="true"
title="Delete layout"
:message="`Delete the layout “${deleteLayoutTarget.name}”? Pages it was copied onto keep their boxes.`"
confirm-label="Delete"
@confirm="confirmDeleteLayout"
@cancel="deleteLayoutTarget = null"
/>
</div>
</template>
<style scoped>
.copy-select {
padding: 0.25rem;
color: var(--color-primary);
background: var(--color-surface-deep);
border: 1px solid var(--color-primary);
}
</style>
@@ -9,8 +9,8 @@
<DiagramFigure id="frontend-route-tree" title="The route tree and its layouts" :min-width="800">
<svg class="dg" viewBox="0 0 1140 640" role="img" aria-labelledby="frontend-route-tree-t">
<title id="frontend-route-tree-t">
Vue Router table: DefaultLayout holding the landing page, /stp, admin routes, automata, hotels and
the catch-all CanvasPage; /stp2 with no layout; /cv inside CVLayout
Vue Router table: DefaultLayout holding the landing page, admin routes, automata, hotels and
the catch-all CanvasPage (which serves /stp); /stp2 with no layout; /cv inside CVLayout
</title>
<!-- Router -->
@@ -47,14 +47,13 @@
<!-- Trunk to DefaultLayout children -->
<path class="dg-edge dg-edge--plain" d="M450,211 H475" />
<path class="dg-edge dg-edge--plain" d="M475,43 V379" />
<path class="dg-edge dg-edge--plain" d="M475,43 V323" />
<path class="dg-edge" d="M475,43 H496" />
<path class="dg-edge" d="M475,99 H496" />
<path class="dg-edge" d="M475,155 H496" />
<path class="dg-edge dg-edge--pink" d="M475,211 H496" />
<path class="dg-edge dg-edge--pink" d="M475,155 H496" />
<path class="dg-edge" d="M475,211 H496" />
<path class="dg-edge" d="M475,267 H496" />
<path class="dg-edge" d="M475,323 H496" />
<path class="dg-edge" d="M475,379 H496" />
<path class="dg-edge dg-edge--muted" d="M450,453 H496" />
<path class="dg-edge" d="M450,523 H496" />
@@ -110,18 +109,16 @@ import DiagramFigure from "../../DiagramFigure.vue";
const rows = [
{ y: 20, path: "/", name: "landing", file: "views/landing/Landing.vue", static: true,
note: "BoxCanvas page=\"index\"; the canvas itself is a defineAsyncComponent chunk" },
{ y: 76, path: "/stp", name: "home", file: "views/home3/Home3.vue",
note: "BoxCanvas page=\"stp\" with the defaultLayout.js starter" },
{ y: 132, path: "/admin/login", name: "admin-login", file: "views/admin/Login.vue",
{ y: 76, path: "/admin/login", name: "admin-login", file: "views/admin/Login.vue",
note: "not guarded: calls auth.ensureLoaded() itself for its \"Already signed in\" card" },
{ y: 188, path: "/admin", name: "admin", file: "views/admin/Admin.vue", admin: true,
{ y: 132, path: "/admin", name: "admin", file: "views/admin/Admin.vue", admin: true,
note: "meta: { requiresAdmin: true }, the only flag the beforeEach guard acts on" },
{ y: 244, path: "/automata", name: "mobile-automata", file: "views/automata/MobileAutomata.vue",
{ y: 188, path: "/automata", name: "mobile-automata", file: "views/automata/MobileAutomata.vue",
note: "Turing machine / mobile automaton drawn to a <canvas>" },
{ y: 300, path: "/hotels", name: "cheap-hotels", file: "views/hotels/CheapHotels.vue",
{ y: 244, path: "/hotels", name: "cheap-hotels", file: "views/hotels/CheapHotels.vue",
note: "Travelodge price scanner over /py/hotels (NDJSON streams via fetch)" },
{ y: 356, path: "/:pathMatch(.*)*", name: "404", file: "views/canvas/CanvasPage.vue",
note: "any other path: query page(slug) → BoxCanvas for that slug, else the 404 view" },
{ y: 300, path: "/:pathMatch(.*)*", name: "404", file: "views/canvas/CanvasPage.vue",
note: "any other path, /stp included: query page(slug) → BoxCanvas for that slug, else the 404 view" },
{ y: 430, path: "/stp2", name: "home2", file: "views/home2/Home2.vue", bare: true,
note: "static full-bleed CSS mock: no navbar, no footer, unlinked" },
{ y: 500, path: "/cv", name: "cv", file: "views/CV/CV.vue",
+8
View File
@@ -3,7 +3,12 @@
* (PageForm.vue). Each `boxes(title)` returns box inputs for
* stores/boxes.js — without `page`, which the store adds. Everything is an
* ordinary box afterwards: move it, edit it, delete it.
*
* These are built into the code; layouts saved from a page in the browser
* live in stores/layouts.js and are loaded from the canvas's Layouts panel.
*/
import { defaultLayout } from "@/views/home3/defaultLayout";
const html = (title, body, geom, extra = {}) => ({ kind: "html", title, html: body, ...geom, ...extra });
function notes() {
@@ -29,4 +34,7 @@ function notes() {
export const STARTERS = [
{ id: "blank", label: "Blank", boxes: () => [] },
{ id: "notes", label: "Notes board (admin-only notes)", boxes: notes },
// What /stp's "Import current layout" button used to add, from when /stp
// was its own route.
{ id: "stp-grid", label: "Old /stp grid", boxes: defaultLayout },
];
+4 -3
View File
@@ -1,8 +1,9 @@
<script setup>
/**
* STATUS: legacy — no route points here. `/stp` is now views/home3/Home3.vue,
* the admin-editable box canvas; views/home3/defaultLayout.js is this page's
* arrangement redrawn as boxes. Kept for reference.
* STATUS: legacy — no route points here. `/stp` is now a canvas page (see
* views/canvas/CanvasPage.vue); views/home3/defaultLayout.js is this page's
* arrangement redrawn as boxes, offered as the "Old /stp grid" starter.
* Kept for reference.
*
* Was route `/stp` — the personal home page: an A4-shaped widget grid flanked by two
* sidebars.
+28 -4
View File
@@ -1,8 +1,8 @@
<script setup>
/**
* A free-form canvas of boxes the admin arranges in the browser, for one page
* key (see stores/boxes.js). Home3.vue (/stp), the landing page and every
* admin-created page (views/canvas/CanvasPage.vue) are this component.
* key (see stores/boxes.js). The landing page and every admin-created page
* (views/canvas/CanvasPage.vue, /stp included) are this component.
*
* Every box (the `Box` GraphQL type) has a position, size and z-index in px
* on a fixed CANVAS_W-wide design canvas. The canvas is drawn at that width
@@ -26,6 +26,10 @@
* The canvas also owns its page's background (stores/background.js), which
* DefaultLayout paints behind the whole window while the canvas is mounted;
* admins change it with the Background button.
*
* The Layouts button saves the page as a named layout, or loads a saved one
* onto it (LayoutPanel.vue, stores/layouts.js) — which is how a layout moves
* from one page to another.
*/
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { useMediaQuery } from "@vueuse/core";
@@ -33,6 +37,7 @@ import { useAuthStore } from "@/stores/auth";
import { useBoxesStore } from "@/stores/boxes";
import { useBackgroundStore } from "@/stores/background";
import BackgroundEditor from "./BackgroundEditor.vue";
import LayoutPanel from "./LayoutPanel.vue";
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
import UploadPicker from "@/components/util/UploadPicker.vue";
import BoxFrame from "./BoxFrame.vue";
@@ -67,6 +72,7 @@ const background = useBackgroundStore();
background.show(props.page);
onBeforeUnmount(() => background.hide(props.page));
const backgroundOpen = ref(false);
const layoutsOpen = ref(false);
const confirmation = ref(null);
const isMobile = useMediaQuery(MOBILE_QUERY);
@@ -317,12 +323,26 @@ async function placePicked(url) {
// selection changes or it unmounts.
function select(box) {
backgroundOpen.value = false;
layoutsOpen.value = false;
selectedId.value = box.id;
}
// The background and layouts panels sit in the same place, so one closes the
// other, and either closes the box editor.
function toggleBackground() {
backgroundOpen.value = !backgroundOpen.value;
if (backgroundOpen.value) selectedId.value = null;
if (backgroundOpen.value) {
layoutsOpen.value = false;
selectedId.value = null;
}
}
function toggleLayouts() {
layoutsOpen.value = !layoutsOpen.value;
if (layoutsOpen.value) {
backgroundOpen.value = false;
selectedId.value = null;
}
}
function toggleEdit() {
@@ -340,9 +360,12 @@ function toggleEdit() {
<button type="button" class="bar-btn" :class="{ on: editing }" @click="toggleEdit">
{{ editing ? "Done" : "Edit layout" }}
</button>
<button type="button" class="bar-btn" :class="{ on: backgroundOpen }" @click="toggleBackground">
<button type="button" class="bar-btn" :class="{ on: backgroundOpen }" @click="toggleBackground">
Background
</button>
<button type="button" class="bar-btn" :class="{ on: layoutsOpen }" @click="toggleLayouts">
Layouts
</button>
<template v-if="inEditMode">
<select v-model="newChoice" class="bar-btn" @change="addBox">
<option value="" disabled>+ New box…</option>
@@ -430,6 +453,7 @@ function toggleEdit() {
</div>
<BackgroundEditor v-if="backgroundOpen && canEdit" :page="page" @close="backgroundOpen = false" />
<LayoutPanel v-if="layoutsOpen && canEdit" :page="page" @close="layoutsOpen = false" />
<BoxEditor
v-if="inEditMode && selected"
+7 -1
View File
@@ -1,6 +1,12 @@
<script setup>
/**
* Route `/stp` — the home page as a free-form canvas of boxes the admin
* STATUS: legacy — no route points here. `/stp` is now an ordinary canvas
* Page (slug "stp", created by ensureStpPage in backend/services/database.go)
* served by views/canvas/CanvasPage.vue; the "Old /stp grid" starter in
* views/canvas/pageStarters.js replaces this view's import button. Kept for
* reference.
*
* Was route `/stp` — the home page as a free-form canvas of boxes the admin
* arranges in the browser (page key "stp"). Replaces views/home/Home.vue's
* fixed grid. The canvas itself is BoxCanvas.vue, shared with the landing
* page's notes and the admin-created pages.
+228
View File
@@ -0,0 +1,228 @@
<script setup>
/**
* The admin's layouts panel for one canvas page, opened from BoxCanvas's
* "Layouts" button: save the page as a named layout, or load a saved one
* onto it (stores/layouts.js).
*
* Loading onto a page that already has boxes asks whether to replace them or
* add the layout on top. A replace is undoable: the server saves the page
* first, as a layout named "<page> before <layout>, <time>", which shows up
* at the top of this list. Onto an empty page it simply replaces, so the
* layout's background comes with it.
*/
import { ref } from "vue";
import { pagePath, useLayoutsStore } from "@/stores/layouts";
import { useBoxesStore } from "@/stores/boxes";
import OverlayShell from "@/components/util/OverlayShell.vue";
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
const props = defineProps({
page: { type: String, required: true },
});
const emit = defineEmits(["close"]);
const open = ref(true);
const layouts = useLayoutsStore();
layouts.fetch();
const boxes = useBoxesStore(props.page);
const name = ref("");
const busy = ref(false);
const error = ref("");
const loadTarget = ref(null); // the layout waiting on "replace or add?"
const deleteTarget = ref(null);
const renaming = ref(null); // id of the layout whose name is being edited
const renameDraft = ref("");
function close() {
open.value = false;
emit("close");
}
async function act(action, failure) {
error.value = "";
busy.value = true;
try {
await action();
return true;
} catch (err) {
error.value = err?.message || failure;
return false;
} finally {
busy.value = false;
}
}
async function save() {
const ok = await act(() => layouts.create({ name: name.value.trim(), page: props.page }), "Failed to save");
if (ok) name.value = "";
}
function load(layout) {
if (boxes.boxes.length) loadTarget.value = layout;
else apply(layout, true);
}
function apply(layout, replace) {
loadTarget.value = null;
act(() => layouts.apply(layout.id, props.page, replace), "Failed to load");
}
function startRename(layout) {
renaming.value = layout.id;
renameDraft.value = layout.name;
}
async function rename(layout) {
const ok = await act(() => layouts.update(layout.id, { name: renameDraft.value.trim() }), "Failed to rename");
if (ok) renaming.value = null;
}
function confirmDelete() {
const layout = deleteTarget.value;
deleteTarget.value = null;
act(() => layouts.remove(layout.id), "Failed to delete");
}
function describe(layout) {
const parts = [`from ${pagePath(layout.sourcePage)}`, `${layout.boxCount} box${layout.boxCount === 1 ? "" : "es"}`];
if (layout.hasBackground) parts.push("background");
return parts.join(" · ");
}
</script>
<template>
<OverlayShell v-model="open" title="Layouts" @close="close">
<div class="layout-panel bdr-2 bg-surface">
<h3>Layouts</h3>
<form class="row" @submit.prevent="save">
<input v-model="name" type="text" placeholder="Name for this page's layout" required class="flex-1" />
<button type="submit" class="bar-btn" :disabled="busy || !boxes.boxes.length">Save</button>
</form>
<p v-if="layouts.error" class="text-tertiary">Couldn't load the layouts.</p>
<p v-else-if="layouts.loaded && !layouts.layouts.length" class="hint">
No saved layouts yet. Save this page to start one.
</p>
<ul v-else class="list">
<li v-for="layout in layouts.layouts" :key="layout.id">
<form v-if="renaming === layout.id" class="row" @submit.prevent="rename(layout)">
<input v-model="renameDraft" type="text" required class="flex-1" />
<button type="submit" class="bar-btn small" :disabled="busy">Save</button>
<button type="button" class="bar-btn small" @click="renaming = null">Cancel</button>
</form>
<template v-else>
<span class="name">{{ layout.name }}</span>
<span class="hint">{{ describe(layout) }}</span>
<span class="row">
<button type="button" class="bar-btn small" :disabled="busy" @click="load(layout)">Load here</button>
<button type="button" class="bar-btn small" @click="startRename(layout)">Rename</button>
<button type="button" class="bar-btn small danger" @click="deleteTarget = layout">Delete</button>
</span>
</template>
</li>
</ul>
<div class="row">
<button type="button" class="bar-btn" @click="close">Close</button>
<span v-if="busy" class="hint">Working…</span>
</div>
<p v-if="error" class="text-tertiary">{{ error }}</p>
</div>
</OverlayShell>
<ConfirmDialog
v-if="loadTarget"
:model-value="true"
title="Load layout"
:message="`This page already has ${boxes.boxes.length} box${boxes.boxes.length === 1 ? '' : 'es'}. Replace them with “${loadTarget.name}”, or add it on top? Replacing saves the page as a layout first.`"
confirm-label="Replace"
secondary-label="Add on top"
@confirm="apply(loadTarget, true)"
@secondary="apply(loadTarget, false)"
@cancel="loadTarget = null"
/>
<ConfirmDialog
v-if="deleteTarget"
:model-value="true"
title="Delete layout"
:message="`Delete the layout “${deleteTarget.name}”? Pages it was loaded onto keep their boxes.`"
confirm-label="Delete"
@confirm="confirmDelete"
@cancel="deleteTarget = null"
/>
</template>
<style scoped>
.layout-panel {
position: fixed;
top: 80px;
left: 16px;
z-index: 65;
display: flex;
flex-direction: column;
gap: 0.5rem;
width: min(420px, calc(100vw - 32px));
max-height: calc(100vh - 100px);
overflow-y: auto;
padding: 0.75rem;
box-sizing: border-box;
}
h3 {
margin: 0;
}
.row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.4rem;
}
.list {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin: 0;
padding: 0;
list-style: none;
}
.list li {
display: flex;
flex-direction: column;
gap: 2px;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--color-quaternary);
}
.name {
color: var(--color-primary);
}
.hint {
color: var(--color-muted);
font-size: 0.85rem;
}
.bar-btn {
padding: 0.25rem 0.75rem;
color: var(--color-primary);
background: var(--color-link-bg);
border: 2px solid var(--color-quaternary);
font-family: var(--font-heading);
font-size: 1.1rem;
letter-spacing: 0.025em;
cursor: pointer;
}
.bar-btn:hover {
border-color: var(--color-primary);
}
.bar-btn:disabled {
opacity: 0.5;
}
.bar-btn.small {
padding: 0.1rem 0.5rem;
font-size: 0.9rem;
}
.bar-btn.danger:hover {
border-color: var(--color-tertiary);
color: var(--color-tertiary);
}
</style>
+3 -2
View File
@@ -1,6 +1,7 @@
/**
* The pre-Home3 /stp page (views/home/Home.vue) redrawn as boxes, for the
* one-off "Import current layout" button on an empty canvas.
* The pre-Home3 /stp page (views/home/Home.vue) redrawn as boxes, offered
* as the "Old /stp grid" starter when a page is created
* (views/canvas/pageStarters.js).
*
* Home.vue was an A4 sheet (~800×1120px) holding a 10×10 CSS grid with 5px
* gaps, between two 240px sidebars. The grid areas below are copied from its