diff --git a/backend/graph/page_helpers.go b/backend/graph/page_helpers.go
index 70f265f..41ba17a 100644
--- a/backend/graph/page_helpers.go
+++ b/backend/graph/page_helpers.go
@@ -36,8 +36,7 @@ var reservedFirstSegments = map[string]bool{
// reservedSlugs are individual paths the SPA routes itself.
var reservedSlugs = map[string]bool{
- "shrines": true,
- "shrines/demoman": true,
+ "shrines": true,
}
func validPageKey(key string) bool {
diff --git a/backend/graph/page_helpers_test.go b/backend/graph/page_helpers_test.go
index 5b34d75..bdb0fe8 100644
--- a/backend/graph/page_helpers_test.go
+++ b/backend/graph/page_helpers_test.go
@@ -18,7 +18,7 @@ func TestValidateSlug(t *testing.T) {
{"shrines/gto-", false}, // trailing hyphen
{"shrines/../admin", false}, // dots
{"shrines", false}, // the SPA's own index
- {"shrines/demoman", false}, // an existing SPA route
+ {"shrines/demoman", true}, // no longer an SPA route
{"admin/pages", false}, // under an SPA route
{"jobs/x", false}, // under an nginx route
{"stp", false}, // a built-in canvas's key
diff --git a/vue/README.md b/vue/README.md
index 6d5e780..64bb6ab 100644
--- a/vue/README.md
+++ b/vue/README.md
@@ -68,7 +68,7 @@ Two layout shells, defined in `src/router/index.js`:
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint), with a canvas overlay for pinned notes (page key `index`) |
| `/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`, `/shrines/demoman` | DefaultLayout | Every other shrine is a canvas page |
+| `/automata`, `/hotels`, `/shrines` | DefaultLayout | Each shrine under `/shrines/` is a canvas page |
| `/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) |
@@ -243,7 +243,10 @@ renders any page's boxes.
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.
- CodeMirror is loaded only when that panel opens. "Insert upload" stores a
+ CodeMirror is loaded only when that panel opens; the panel is teleported to
+ `
` so the landing overlay's `pointer-events: none` doesn't reach it.
+ Image and video files dropped onto the canvas in edit mode are uploaded and
+ each becomes an unframed box at the drop point. "Insert upload" stores a
file through the chat's public upload endpoint and puts an ` `/``
tag for it at the cursor. Starter HTML is in `templates.js`. On `/stp`,
"Import current layout" (shown only on an empty canvas) recreates the old
@@ -295,7 +298,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/{GTO,Evangelion,Skipskipbenben}.vue` | ` ` placeholders, unrouted; those shrines are canvas pages now |
+| `views/home/shrines/{Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old hand-written shrines (Demoman a video wall, the rest ` `), 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 |
diff --git a/vue/src/router/index.js b/vue/src/router/index.js
index 18cca09..8a94d79 100644
--- a/vue/src/router/index.js
+++ b/vue/src/router/index.js
@@ -65,14 +65,9 @@ const router = createRouter({
name: "shrine links",
component: () => import("@/views/home/shrines/Shrines.vue"),
},
- // The GTO, Evangelion and Skipskipbenben shrines were
- // placeholders; they are canvas pages now, made from /shrines
- // and served by the catch-all below.
- {
- path: "shrines/demoman",
- name: "demoman shrine",
- component: () => import("@/views/home/shrines/Demoman.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.
// Anything else is an admin-created canvas page if one exists
// at that address (the Page GraphQL type), else the 404.
{
diff --git a/vue/src/views/home/shrines/Demoman.vue b/vue/src/views/home/shrines/Demoman.vue
index 337667c..244dc80 100644
--- a/vue/src/views/home/shrines/Demoman.vue
+++ b/vue/src/views/home/shrines/Demoman.vue
@@ -1,6 +1,10 @@
@@ -34,10 +34,15 @@ const shrine_links = computed(() =>
class="page-a4 bdr-1 flex flex-col relative overflow-scroll gap-1"
>
-
+
+ No shrines yet.
+
+
+
+ {{ creating ? "Cancel" : "+ New shrine" }}
+
+
+
diff --git a/vue/src/views/home3/BoxCanvas.vue b/vue/src/views/home3/BoxCanvas.vue
index 8cc6877..e64137b 100644
--- a/vue/src/views/home3/BoxCanvas.vue
+++ b/vue/src/views/home3/BoxCanvas.vue
@@ -19,7 +19,8 @@
* Admins get an Edit toggle. In edit mode boxes drag and resize (BoxFrame),
* changes save on release, and the selected box opens in BoxEditor. Boxes
* marked adminOnly are never sent to anyone else (the server filters them);
- * admins see them outlined.
+ * admins see them outlined. Image and video files dropped onto the canvas in
+ * edit mode are uploaded and each becomes a box where it was dropped.
*
* `overlay` lays the canvas over whatever the parent already renders instead
* of taking space of its own — the landing page uses it to pin notes over its
@@ -38,7 +39,8 @@ import BoxEditor from "./BoxEditor.vue";
import HtmlBox from "./HtmlBox.vue";
import WidgetBox from "./WidgetBox.vue";
import { WIDGETS } from "./widgetRegistry";
-import { TEMPLATES } from "./templates";
+import { TEMPLATES, imageHtml, videoHtml } from "./templates";
+import { mediaSize, uploadFile } from "./upload";
const props = defineProps({
page: { type: String, required: true },
@@ -218,6 +220,55 @@ async function importStarter() {
}
}
+// ---- Dropping files -----------------------------------------------------
+const DROP_MAX = 400; // longest side of a dropped picture's box, canvas px
+const dragOver = ref(false);
+const uploading = ref(0);
+
+function isMedia(file) {
+ return file.type.startsWith("image/") || file.type.startsWith("video/");
+}
+
+// Each file is uploaded and placed at the drop point, sized to its own
+// aspect ratio so nothing is cropped, then cascaded like visibleOrigin().
+async function onDrop(event) {
+ dragOver.value = false;
+ const files = [...(event.dataTransfer?.files ?? [])].filter(isMedia);
+ if (!files.length) return;
+ const rect = canvasEl.value.getBoundingClientRect();
+ const snap = (n) => Math.max(0, Math.round(n / 5) * 5);
+ let x = snap((event.clientX - rect.left) / scale.value);
+ let y = snap((event.clientY - rect.top) / scale.value);
+ uploading.value += files.length;
+ for (const file of files) {
+ try {
+ const [url, size] = await Promise.all([uploadFile(file), mediaSize(file)]);
+ const fit = size ? Math.min(1, DROP_MAX / Math.max(size.w, size.h)) : 1;
+ const w = size ? Math.max(40, Math.round(size.w * fit)) : 300;
+ const h = size ? Math.max(40, Math.round(size.h * fit)) : 300;
+ const video = file.type.startsWith("video/");
+ const created = await store.create({
+ kind: "html",
+ title: file.name,
+ html: video ? videoHtml(url) : imageHtml(url),
+ framed: false,
+ x,
+ y,
+ w,
+ h,
+ z: store.topZ(),
+ });
+ selectedId.value = created.id;
+ x += 20;
+ y += 20;
+ } catch (err) {
+ report(err);
+ } finally {
+ uploading.value--;
+ }
+ }
+}
+
// ---- Selection -----------------------------------------------------------
function select(box) {
if (selectedId.value === box.id) return;
@@ -271,6 +322,9 @@ function toggleEdit() {
{{ importing ? "Importing…" : starterLabel }}
+
+ {{ uploading ? `Uploading ${uploading}…` : "Drop images or videos onto the canvas to add them" }}
+
{{ errorMsg }}
@@ -303,9 +357,12 @@ function toggleEdit() {
. On the landing page the canvas is an
+ * overlay with pointer-events: none, which a panel rendered inside it would
+ * inherit — it would show but ignore every click and keystroke.
*/
import { computed, ref, watch } from "vue";
import { useBoxesStore } from "@/stores/boxes";
-import { api } from "@/api";
+import { tagFor, uploadFile } from "./upload";
import CodeEditor from "./CodeEditor.vue";
import { WIDGETS } from "./widgetRegistry";
@@ -84,25 +85,13 @@ function saveNumber(field, event) {
save({ [field]: value });
}
-// The markup an upload is inserted as, by file type. Anything else (a PDF,
-// a text file) becomes a link.
-function tagFor(url) {
- if (/\.(jpe?g|png|gif|webp)$/i.test(url)) return ` `;
- if (/\.(mp4|webm)$/i.test(url)) return ` `;
- if (/\.(mp3|ogg)$/i.test(url)) return ` `;
- return `${url.split("/").pop()} `;
-}
-
async function upload(event) {
const file = event.target.files?.[0];
event.target.value = "";
if (!file) return;
uploading.value = true;
try {
- const body = new FormData();
- body.append("file", file);
- const { url } = await api.post("/messages/upload", body, { fallback: "Upload failed" });
- const tag = tagFor(url);
+ const tag = tagFor(await uploadFile(file));
if (!codeEditor.value?.insert(tag)) draftHtml.value += `\n${tag}`;
} catch (err) {
emit("error", err);
@@ -121,91 +110,93 @@ defineExpose({ close });
-
+
- `;
+ `;
/**
* Menu entries; `size` is [w, h] in canvas px. `adminOnly` sets the new
@@ -147,10 +147,10 @@ export const TEMPLATES = [
{ label: "Text", title: "Text", html: TEXT, size: [400, 260] },
{ label: "Image / GIF", title: "Image", html: imageHtml("/img/memes/fire-woman.gif"), size: [240, 240], framed: false },
{ label: "Image gallery", title: "Gallery", html: galleryHtml(["/img/memes/fire-woman.gif", "/img/memes/epic.jpeg"]), size: [460, 320] },
- { label: "Video", title: "Video", html: VIDEO, size: [400, 260], framed: false },
+ { label: "Video", title: "Video", html: videoHtml("/img/demoman/1760582395316219.webm"), size: [400, 260], framed: false },
{ label: "Clock", title: "Clock", html: CLOCK, size: [240, 120] },
{ label: "Weather", title: "Weather", html: WEATHER, size: [240, 170] },
{ label: "Empty HTML", title: "HTML", html: EMPTY, size: [300, 200] },
];
-export { imageHtml, galleryHtml };
+export { imageHtml, galleryHtml, videoHtml };
diff --git a/vue/src/views/home3/upload.js b/vue/src/views/home3/upload.js
new file mode 100644
index 0000000..abcd832
--- /dev/null
+++ b/vue/src/views/home3/upload.js
@@ -0,0 +1,53 @@
+/**
+ * Uploading a file for use in a box: stores it through the chat's upload
+ * endpoint (public, unguessable URLs under /uploads/) and says what markup
+ * shows it. Used by BoxEditor's "Insert upload" and by dropping files onto
+ * the canvas in edit mode.
+ *
+ * Never the private upload directory: that one is behind a cookie check, and
+ * a box's sandboxed frame loads as an opaque origin, so its requests may not
+ * carry the cookie.
+ */
+import { api } from "@/api";
+
+/** Upload one file; resolves to its URL. Throws an ApiError on failure. */
+export async function uploadFile(file) {
+ const body = new FormData();
+ body.append("file", file);
+ const { url } = await api.post("/messages/upload", body, { fallback: `Upload of ${file.name} failed` });
+ return url;
+}
+
+export const isImage = (url) => /\.(jpe?g|png|gif|webp)$/i.test(url);
+export const isVideo = (url) => /\.(mp4|webm)$/i.test(url);
+
+/** The markup an uploaded file is shown with, by type. Anything else (a PDF,
+ * a text file) becomes a link. */
+export function tagFor(url) {
+ if (isImage(url)) return ` `;
+ if (isVideo(url)) return ` `;
+ if (/\.(mp3|ogg)$/i.test(url)) return ` `;
+ return `${url.split("/").pop()} `;
+}
+
+/** Natural size of an image or video file, or null if it can't be read. */
+export function mediaSize(file) {
+ return new Promise((resolve) => {
+ const src = URL.createObjectURL(file);
+ const done = (size) => {
+ URL.revokeObjectURL(src);
+ resolve(size);
+ };
+ if (file.type.startsWith("video/")) {
+ const v = document.createElement("video");
+ v.onloadedmetadata = () => done({ w: v.videoWidth, h: v.videoHeight });
+ v.onerror = () => done(null);
+ v.src = src;
+ } else {
+ const img = new Image();
+ img.onload = () => done({ w: img.naturalWidth, h: img.naturalHeight });
+ img.onerror = () => done(null);
+ img.src = src;
+ }
+ });
+}