Autosave box HTML, fix editor selection, make /shrines a canvas page
Test and deploy / test (push) Successful in 1m56s
Test and deploy / deploy (push) Successful in 48s

The HTML editor's selection was invisible: CodeMirror's focused-selection
rule outranked ours and painted #233, and the opaque active line covered
the selection layer. Match its selector and make the active line
translucent.

Unsaved HTML now saves on leaving a box (selecting another, clicking
empty canvas, Done, closing the panel) instead of asking to discard.

/shrines is no longer a hard-coded route but an ordinary canvas page,
with links placed by hand as Link boxes; the backend no longer reserves
the slug. The Shrine starter layout is gone, and the admin Pages tab
gains a "New shrine" form that makes a blank page under shrines/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-15 12:27:06 +01:00
co-authored by Claude Opus 5.5
parent e54aaac181
commit ca3cd4db30
11 changed files with 83 additions and 110 deletions
+9 -6
View File
@@ -68,7 +68,8 @@ Two layout shells, defined in `src/router/index.js`:
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint): a box canvas, page key `index`; the old fixed page is its starter layout, `views/landing/landingLayout.js` |
| `/stp` | DefaultLayout | The personal home page: an admin-editable canvas of boxes (`views/home3/`, see "The /stp canvas" below) |
| `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` |
| `/automata`, `/hotels`, `/shrines` | DefaultLayout | Each shrine under `/shrines/` is a canvas page |
| `/automata`, `/hotels` | DefaultLayout | |
| `/shrines`, `/shrines/*` | DefaultLayout | All canvas pages via the catch-all: `/shrines` is an index whose links are Link boxes placed by hand |
| `/cv` | CVLayout | Light print theme. Its Jobs button goes to `/jobs/`, the separate job tracker app (`adamf/job-tracker`); nginx redirects the old `/cv/jobs` and `/cv/leads` there |
| `/stp2` | (none) | Bare full-bleed mock, deliberately outside both layouts |
| `:pathMatch(.*)*` | DefaultLayout | `views/canvas/CanvasPage.vue`: an admin-created canvas page if one exists at the path, else the 404 (with a "create a page here" form for admins) |
@@ -209,9 +210,9 @@ renders any page's boxes.
(`Landing.vue`), which is nothing but the canvas. Any other key is the slug of a **`Page`** (GraphQL
type, `stores/pages.js`), an admin-created page served at `/<slug>` by the
router's catch-all (`views/canvas/CanvasPage.vue`). Pages are created from
the admin panel's Pages tab, from `/shrines`, or from the 404 of the address
you want; each can start from a layout in `views/canvas/pageStarters.js`
(Blank, Shrine, Notes board). Title, address and visibility are under "Page
the admin panel's Pages tab (which also has a "New shrine" form, a blank page
under `shrines/`), or from the 404 of the address you want; each can start
from a layout in `views/canvas/pageStarters.js` (Blank, Notes board). Title, address and visibility are under "Page
settings" on the page; renaming moves its boxes, deleting takes them too.
The server refuses slugs that an SPA or nginx route would answer first
(`validateSlug` in `backend/graph/page_helpers.go`) — add to that list when
@@ -248,7 +249,9 @@ renders any page's boxes.
- **Editing.** Admins get an "Edit layout" toggle at desktop width. Geometry
saves on pointer release, and the box is moved locally first and put back if
the save fails. `BoxEditor.vue` is the side panel. Settings save on change;
HTML is a draft that previews live and saves with Save or Ctrl/Cmd+S.
HTML is a draft that previews live and saves with Save or Ctrl/Cmd+S, or
automatically on leaving the box (selecting another, clicking empty canvas,
Done, ✕).
CodeMirror is loaded only when that panel opens; the panel is teleported to
`<body>`.
Image and video files dropped onto the canvas in edit mode are uploaded and
@@ -307,7 +310,7 @@ in its header comment; the summary:
| File | Status |
| --- | --- |
| `views/home3/Home3.vue` | live (`/stp`) — the box canvas; its widget boxes use **Intro3** and **Gym2** |
| `views/home/shrines/{Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old hand-written shrines (Demoman a video wall, the rest `<Wip />`), unrouted; shrines are canvas pages now |
| `views/home/shrines/{Shrines,Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old `/shrines` index and hand-written shrines (Demoman a video wall, the rest `<Wip />`), unrouted; shrines are canvas pages now |
| `views/home/Home.vue` | legacy fixed grid that `/stp` used to be; no route. Its widgets are still live through `home3/widgetRegistry.js` |
| `views/home/Intro.vue` | superseded by `Intro2.vue`; not imported |
| `views/home/Gym.vue` | superseded by `Gym2.vue`; not imported |
+4 -8
View File
@@ -60,14 +60,10 @@ const router = createRouter({
name: "cheap-hotels",
component: () => import("@/views/hotels/CheapHotels.vue"),
},
{
path: "shrines",
name: "shrine links",
component: () => import("@/views/home/shrines/Shrines.vue"),
},
// Individual shrines are canvas pages, made from /shrines and
// served by the catch-all below. The old hand-written ones
// (views/home/shrines/) are unrouted.
// /shrines and the shrines under it are canvas pages, made
// from the admin panel's Pages tab and served by the catch-all
// below. The old hand-written ones (views/home/shrines/) are
// unrouted.
// Anything else is an admin-created canvas page if one exists
// at that address (the Page GraphQL type), else the 404.
{
+13
View File
@@ -3,6 +3,10 @@
* Admin tab: the canvas pages made in the browser (views/canvas/). Lists them
* all, admin-only ones included, and creates new ones. A page's title,
* address and visibility are edited from "Page settings" on the page itself.
*
* "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.
*/
import { usePagesStore } from "@/stores/pages";
import PageForm from "@/views/canvas/PageForm.vue";
@@ -44,6 +48,15 @@ async function remove(page) {
<p v-else-if="pages.loaded" class="text-muted">No pages yet.</p>
</section>
<section>
<h1>New shrine</h1>
<p class="text-muted">
A blank page under /shrines/. Link to it from the /shrines page with a
Link box.
</p>
<PageForm prefix="shrines/" placeholder="address, e.g. evangelion" submit-label="Create shrine" />
</section>
<section>
<h1>New page</h1>
<PageForm />
+8 -5
View File
@@ -2,8 +2,9 @@
/**
* Create a canvas page: its address, title, a starting layout from
* pageStarters.js, and whether only admins may see it. On success it opens
* the new page and emits `created`. Used on the admin panel's Pages tab, on /shrines, and on the
* 404 an admin sees at an address that has no page yet.
* the new page and emits `created`. Used on the admin panel's Pages tab
* (twice: any page, and a shrine under /shrines/) and on the 404 an admin sees
* at an address that has no page yet.
*/
import { ref } from "vue";
import { useRouter } from "vue-router";
@@ -15,9 +16,11 @@ import { STARTERS } from "./pageStarters";
const props = defineProps({
// Pre-filled address, e.g. the path of the 404 being looked at.
slug: { type: String, default: "" },
// Fixed leading part of the address, e.g. "shrines/" on /shrines.
// Fixed leading part of the address, e.g. "shrines/" for a new shrine.
prefix: { type: String, default: "" },
starter: { type: String, default: "blank" },
placeholder: { type: String, default: "address, e.g. shrines/evangelion" },
submitLabel: { type: String, default: "Create page" },
});
const emit = defineEmits(["created"]);
@@ -64,7 +67,7 @@ async function submit() {
<form class="page-form flex flex-col gap-1" @submit.prevent="submit">
<label class="flex items-center gap-1">
<span class="text-muted">/{{ prefix }}</span>
<input v-model="slug" type="text" placeholder="address, e.g. evangelion" required class="flex-1" />
<input v-model="slug" type="text" :placeholder="placeholder" required class="flex-1" />
</label>
<input v-model="title" type="text" placeholder="Title (required)" />
<select v-model="starter">
@@ -74,7 +77,7 @@ async function submit() {
<input v-model="adminOnly" type="checkbox" />
Only admins can see this page
</label>
<Button type="submit" :disabled="busy">{{ busy ? "Creating…" : "Create page" }}</Button>
<Button type="submit" :disabled="busy">{{ busy ? "Creating…" : submitLabel }}</Button>
<p v-if="error" class="text-tertiary">{{ error }}</p>
</form>
</template>
-55
View File
@@ -4,62 +4,8 @@
* stores/boxes.js — without `page`, which the store adds. Everything is an
* ordinary box afterwards: move it, edit it, delete it.
*/
import { galleryHtml, imageHtml } from "@/views/home3/templates";
const escape = (s) =>
s.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
const html = (title, body, geom, extra = {}) => ({ kind: "html", title, html: body, ...geom, ...extra });
function shrine(title) {
const t = escape(title);
return [
html(
"Heading",
`<style>
body { display: grid; place-items: center; text-align: center; }
h1 { margin: 0; font-size: 4.5rem; line-height: 1; }
p { margin: .3rem 0 0; color: var(--color-tertiary); }
</style>
<div>
<h1>${t}</h1>
<p>a shrine</p>
</div>`,
{ x: 300, y: 20, w: 800, h: 160 },
{ framed: false },
),
html(
"Main image",
imageHtml("/img/memes/epic.jpeg"),
{ x: 300, y: 200, w: 380, h: 380 },
{ framed: false },
),
html(
"About",
`<h3>Why ${t}</h3>
<p>What it is, and why it gets a shrine.</p>
<h3>Favourite moments</h3>
<ul>
<li>…</li>
</ul>`,
{ x: 700, y: 200, w: 400, h: 380 },
),
html(
"Gallery",
galleryHtml(["/img/memes/fire-woman.gif", "/img/memes/mix.gif", "/img/memes/lol.jpg"]),
{ x: 300, y: 600, w: 800, h: 320 },
),
html(
"Quote",
`<style>
body { display: grid; place-items: center; text-align: center; font-style: italic; }
</style>
<blockquote>“A line worth remembering.”</blockquote>`,
{ x: 300, y: 940, w: 800, h: 120 },
),
].map((box, i) => ({ z: i + 1, ...box }));
}
function notes() {
const note = (text, x, y) =>
html(
@@ -82,6 +28,5 @@ function notes() {
export const STARTERS = [
{ id: "blank", label: "Blank", boxes: () => [] },
{ id: "shrine", label: "Shrine", boxes: shrine },
{ id: "notes", label: "Notes board (admin-only notes)", boxes: notes },
];
+6 -3
View File
@@ -1,10 +1,13 @@
<script setup>
/**
* Route `/shrines` — index of the shrine pages: every canvas page
* STATUS: unused — unrouted. /shrines is now an admin-made canvas page whose
* links are boxes; new shrines are made on the admin panel's Pages tab.
*
* Was route `/shrines` — index of the shrine pages: every canvas page
* (views/canvas/) whose address starts with "shrines/", from the pages query.
* Admins — and only admins; the server refuses createPage to anyone else
* anyway — get a button that opens a form to start one from the Shrine
* layout.
* layout (since removed).
*/
import { computed, ref } from "vue";
import RouterTable from "@/components/util/RouterTable.vue";
@@ -41,7 +44,7 @@ const shrine_links = computed(() =>
<button type="button" class="bdr-2 bg-surface mt-4 cursor-pointer" @click="creating = !creating">
{{ creating ? "Cancel" : "+ New shrine" }}
</button>
<PageForm v-if="creating" prefix="shrines/" starter="shrine" />
<PageForm v-if="creating" prefix="shrines/" />
</template>
</div>
</main>
+2 -12
View File
@@ -82,7 +82,6 @@ const selectedId = ref(null);
const selected = computed(() => store.boxes.find((b) => b.id === selectedId.value) ?? null);
const preview = ref(null); // unsaved HTML for the selected box, from BoxEditor
const errorMsg = ref("");
const editor = ref(null);
// ---- Scaling -------------------------------------------------------------
const viewport = ref(null);
@@ -271,21 +270,13 @@ async function onDrop(event) {
}
// ---- Selection -----------------------------------------------------------
// Leaving a box saves its unsaved HTML; BoxEditor does that itself as the
// selection changes or it unmounts.
function select(box) {
if (selectedId.value === box.id) return;
// Leaving a box with unsaved HTML goes through the editor's own confirm.
if (editor.value && selected.value) {
editor.value.close();
if (selectedId.value !== null) return; // they chose to keep editing
}
selectedId.value = box.id;
}
function toggleEdit() {
if (editing.value && selected.value) {
editor.value?.close();
if (selectedId.value !== null) return;
}
editing.value = !editing.value;
}
</script>
@@ -391,7 +382,6 @@ function toggleEdit() {
<BoxEditor
v-if="inEditMode && selected"
ref="editor"
:box="selected"
@preview="preview = $event"
@close="selectedId = null"
+26 -11
View File
@@ -8,8 +8,10 @@
* "instant" model as dragging.
* - HTML is a draft. Typing updates the box on the canvas live (through the
* `preview` event, so the parent can render the draft without touching the
* store) and is saved only by Save or Ctrl/Cmd+S. Saving every keystroke
* would push half-written markup to every visitor.
* store) and is saved by Save or Ctrl/Cmd+S, or automatically on leaving
* the box: selecting another one, clicking empty canvas, Done, or closing
* the panel. Saving every keystroke would push half-written markup to
* every visitor; leaving is the point it is finished.
*
* "Insert upload" uploads a file (upload.js) and puts a tag for it at the
* cursor — the way to add pictures to an existing box, e.g. a gallery.
@@ -17,7 +19,7 @@
* The panel is teleported to <body>, so it is fixed to the window whatever
* transform or stacking context the page puts around the canvas.
*/
import { computed, ref, watch } from "vue";
import { computed, onBeforeUnmount, ref, watch } from "vue";
import { useBoxesStore } from "@/stores/boxes";
import { tagFor, uploadFile } from "./upload";
import CodeEditor from "./CodeEditor.vue";
@@ -38,16 +40,33 @@ const draftHtml = ref(props.box.html ?? "");
const saving = ref(false);
const dirty = computed(() => props.box.kind === "html" && draftHtml.value !== (props.box.html ?? ""));
// Switching to another box: drop this one's preview, start from the new
// box's saved html.
// Save the draft of box `id` if it differs from what is stored. Fire and
// forget: it runs as the editor moves on or unmounts, with nothing left to
// show progress in, so a failure is only reported through `error`.
function flush(id) {
const box = store.boxes.find((b) => b.id === id);
if (!box || box.kind !== "html" || draftHtml.value === (box.html ?? "")) return;
store.update(id, { html: draftHtml.value }).catch((err) => emit("error", err));
}
// Switching to another box: save the old one's draft, drop its preview, start
// from the new box's saved html.
watch(
() => props.box.id,
() => {
(_, oldId) => {
flush(oldId);
emit("preview", null);
draftHtml.value = props.box.html ?? "";
},
);
// Deselecting, Done and ✕ all unmount the panel.
onBeforeUnmount(() => {
clearTimeout(previewTimer);
flush(props.box.id);
emit("preview", null);
});
let previewTimer = null;
watch(draftHtml, (html) => {
clearTimeout(previewTimer);
@@ -100,12 +119,8 @@ async function upload(event) {
}
function close() {
if (dirty.value && !confirm("Discard unsaved HTML changes?")) return;
emit("preview", null);
emit("close");
}
defineExpose({ close });
</script>
<template>
@@ -171,7 +186,7 @@ defineExpose({ close });
<footer class="flex items-center justify-between gap-2">
<small class="text-muted">
Runs sandboxed: scripts work, cookies and /api don't. fetch() only reaches
keyless CORS-open APIs. Ctrl+S saves.
keyless CORS-open APIs. Ctrl+S saves; so does leaving the box.
</small>
<input
ref="fileInput"
+11 -2
View File
@@ -37,8 +37,17 @@ onMounted(async () => {
"&": { height: "100%", fontSize: "13px", backgroundColor: "var(--color-surface-deep)", color: "var(--color-muted)" },
".cm-content": { caretColor: "var(--color-primary)" },
".cm-gutters": { backgroundColor: "var(--color-surface)", color: "var(--color-quaternary)", border: "none" },
".cm-activeLine, .cm-activeLineGutter": { backgroundColor: "var(--color-surface-tint)" },
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { backgroundColor: "#24504a" },
// The selection is drawn in a layer *behind* the text, so an opaque
// active-line colour would hide it on the cursor's line: keep it
// translucent.
".cm-activeLine": { backgroundColor: "#55ffbb0d" },
".cm-activeLineGutter": { backgroundColor: "var(--color-surface-tint)" },
// Same selectors as CodeMirror's base theme — a shorter one loses to
// its focused rule, which paints #233, all but invisible here.
"& .cm-selectionBackground, &.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
backgroundColor: "#1f6b5c",
},
".cm-selectionMatch": { backgroundColor: "#55ffbb26" },
".cm-scroller": { fontFamily: "ui-monospace, monospace" },
},
{ dark: true },