Make the box canvas reusable: canvas pages, admin-only boxes, landing notes
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:
+9
-18
@@ -5,6 +5,9 @@
|
||||
* theme) and holds most routes; `/cv` mounts CVLayout (light print theme).
|
||||
* `/stp2` is deliberately outside both — it is a bare full-bleed mock.
|
||||
*
|
||||
* Pages made in the browser (views/canvas/) have no entries here: the
|
||||
* catch-all at the end looks the path up and renders the page if one exists.
|
||||
*
|
||||
* Only the landing page is statically imported; every other view is a dynamic
|
||||
* import so Vite code-splits it into its own chunk.
|
||||
*
|
||||
@@ -62,32 +65,20 @@ const router = createRouter({
|
||||
name: "shrine links",
|
||||
component: () => import("@/views/home/shrines/Shrines.vue"),
|
||||
},
|
||||
{
|
||||
path: "shrines/gto",
|
||||
name: "gto shrine",
|
||||
component: () => import("@/views/home/shrines/GTO.vue"),
|
||||
},
|
||||
{
|
||||
path: "shrines/skipskipbenben",
|
||||
name: "skipskipbenben shrine",
|
||||
component: () =>
|
||||
import("@/views/home/shrines/Skipskipbenben.vue"),
|
||||
},
|
||||
{
|
||||
path: "shrines/evangelion",
|
||||
name: "evangelion shrine",
|
||||
component: () =>
|
||||
import("@/views/home/shrines/Evangelion.vue"),
|
||||
},
|
||||
// The GTO, Evangelion and Skipskipbenben shrines were <Wip />
|
||||
// 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"),
|
||||
},
|
||||
// Anything else is an admin-created canvas page if one exists
|
||||
// at that address (the Page GraphQL type), else the 404.
|
||||
{
|
||||
path: ":pathMatch(.*)*",
|
||||
name: "404",
|
||||
component: () => import("@/views/404/404.vue"),
|
||||
component: () => import("@/views/canvas/CanvasPage.vue"),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
+45
-23
@@ -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)();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
@@ -16,6 +16,7 @@ import CreateActivity from "./CreateActivity.vue";
|
||||
import CreateRowing from "./CreateRowing.vue";
|
||||
import CreateBookmark from "./CreateBookmark.vue";
|
||||
import CreatePlace from "./CreatePlace.vue";
|
||||
import ManagePages from "./ManagePages.vue";
|
||||
import ManageUsers from "./ManageUsers.vue";
|
||||
import ManageRadio from "./ManageRadio.vue";
|
||||
import Environment from "./Environment.vue";
|
||||
@@ -31,6 +32,7 @@ const sections = [
|
||||
{ id: "rowing", label: "Rowing", component: CreateRowing },
|
||||
{ id: "bookmark", label: "Bookmark", component: CreateBookmark },
|
||||
{ id: "place", label: "Place / Thing To Do", component: CreatePlace },
|
||||
{ id: "pages", label: "Pages", component: ManagePages },
|
||||
{ id: "users", label: "Manage Users", component: ManageUsers },
|
||||
{ id: "radio", label: "Manage Radio", component: ManageRadio },
|
||||
{ id: "environment", label: "Environment", component: Environment },
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup>
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import { usePagesStore } from "@/stores/pages";
|
||||
import PageForm from "@/views/canvas/PageForm.vue";
|
||||
|
||||
const pages = usePagesStore();
|
||||
pages.fetch();
|
||||
|
||||
async function remove(page) {
|
||||
if (!confirm(`Delete the page “${page.title}” and everything on it?`)) return;
|
||||
try {
|
||||
await pages.remove(page.id);
|
||||
} catch (err) {
|
||||
alert(err?.message || "Failed to delete");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<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.
|
||||
</p>
|
||||
<p v-if="pages.error" class="text-tertiary">Couldn't load the pages.</p>
|
||||
<table v-else-if="pages.pages.length" class="w-full">
|
||||
<tr v-for="page in pages.pages" :key="page.id">
|
||||
<td>
|
||||
<RouterLink :to="`/${page.slug}`">/{{ page.slug }}</RouterLink>
|
||||
</td>
|
||||
<td>{{ page.title }}</td>
|
||||
<td>{{ page.adminOnly ? "🔒 admin only" : "public" }}</td>
|
||||
<td class="text-right">
|
||||
<button type="button" class="text-tertiary cursor-pointer" @click="remove(page)">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p v-else-if="pages.loaded" class="text-muted">No pages yet.</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h1>New page</h1>
|
||||
<PageForm />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,191 @@
|
||||
<script setup>
|
||||
/**
|
||||
* The router's catch-all: any path no other route claims is looked up as an
|
||||
* admin-created canvas page (the `Page` GraphQL type) and, if there is one,
|
||||
* rendered as a BoxCanvas whose page key is the slug. Otherwise it is the
|
||||
* site's 404 — with, for an admin, a form to create a page right here.
|
||||
*
|
||||
* Static routes always win, which is why the server refuses slugs under the
|
||||
* SPA's and nginx's own paths (validateSlug in backend/graph/page_helpers.go).
|
||||
*
|
||||
* An adminOnly page answers null to anyone else, so to them it is simply a
|
||||
* 404.
|
||||
*/
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { gql } from "@/graphql";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { PAGE_FIELDS, usePagesStore } from "@/stores/pages";
|
||||
import BoxCanvas from "@/views/home3/BoxCanvas.vue";
|
||||
import NotFound from "@/views/404/404.vue";
|
||||
import PageForm from "./PageForm.vue";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
const pages = usePagesStore();
|
||||
|
||||
const isAdmin = computed(() => auth.loggedIn && !!auth.user.admin);
|
||||
|
||||
// pathMatch is the path split on "/"; a trailing slash leaves an empty last
|
||||
// part.
|
||||
const slug = computed(() => {
|
||||
const parts = route.params.pathMatch;
|
||||
return (Array.isArray(parts) ? parts : [parts]).filter(Boolean).join("/");
|
||||
});
|
||||
|
||||
const page = ref(null);
|
||||
const state = ref("loading"); // loading | found | missing | error
|
||||
|
||||
async function load() {
|
||||
const wanted = slug.value;
|
||||
state.value = "loading";
|
||||
try {
|
||||
const data = await gql(`query Page($slug: String!) { page(slug: $slug) { ${PAGE_FIELDS} } }`, {
|
||||
slug: wanted,
|
||||
});
|
||||
if (wanted !== slug.value) return; // navigated on while it loaded
|
||||
page.value = data.page;
|
||||
state.value = data.page ? "found" : "missing";
|
||||
} catch {
|
||||
if (wanted === slug.value) state.value = "error";
|
||||
}
|
||||
}
|
||||
// The session matters too: signing in may reveal an adminOnly page.
|
||||
watch([slug, isAdmin], load, { immediate: true });
|
||||
auth.ensureLoaded();
|
||||
|
||||
// ---- Page settings (admin) -----------------------------------------------
|
||||
const settingsOpen = ref(false);
|
||||
const draft = ref({ title: "", slug: "", adminOnly: false });
|
||||
const settingsError = ref("");
|
||||
|
||||
function openSettings() {
|
||||
draft.value = { title: page.value.title, slug: page.value.slug, adminOnly: page.value.adminOnly };
|
||||
settingsError.value = "";
|
||||
settingsOpen.value = !settingsOpen.value;
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
settingsError.value = "";
|
||||
try {
|
||||
const updated = await pages.update(page.value.id, {
|
||||
title: draft.value.title.trim(),
|
||||
slug: draft.value.slug.trim().replace(/^\/+|\/+$/g, ""),
|
||||
adminOnly: draft.value.adminOnly,
|
||||
});
|
||||
settingsOpen.value = false;
|
||||
if (updated.slug !== page.value.slug) router.replace(`/${updated.slug}`);
|
||||
else page.value = updated;
|
||||
} catch (err) {
|
||||
settingsError.value = err?.message || "Failed to save";
|
||||
}
|
||||
}
|
||||
|
||||
async function deletePage() {
|
||||
if (!confirm(`Delete the page “${page.value.title}” and everything on it?`)) return;
|
||||
try {
|
||||
await pages.remove(page.value.id);
|
||||
router.push("/");
|
||||
} catch (err) {
|
||||
settingsError.value = err?.message || "Failed to delete";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main v-if="state === 'found'" class="canvas-page">
|
||||
<BoxCanvas :key="page.slug" :page="page.slug">
|
||||
<template #admin-bar>
|
||||
<button type="button" class="bar-btn" :class="{ on: settingsOpen }" @click="openSettings">
|
||||
Page settings
|
||||
</button>
|
||||
<span v-if="page.adminOnly" class="text-tertiary" title="Only admins can see this page">🔒 admin only</span>
|
||||
</template>
|
||||
</BoxCanvas>
|
||||
|
||||
<form v-if="settingsOpen" class="settings bdr-2 bg-surface" @submit.prevent="saveSettings">
|
||||
<label>Title <input v-model="draft.title" type="text" required /></label>
|
||||
<label>Address <input v-model="draft.slug" type="text" required /></label>
|
||||
<label class="check"><input v-model="draft.adminOnly" type="checkbox" /> Only admins can see this page</label>
|
||||
<div class="flex gap-2">
|
||||
<button type="submit" class="bar-btn">Save</button>
|
||||
<button type="button" class="bar-btn" @click="settingsOpen = false">Cancel</button>
|
||||
<button type="button" class="bar-btn danger" @click="deletePage">Delete page</button>
|
||||
</div>
|
||||
<p v-if="settingsError" class="text-tertiary">{{ settingsError }}</p>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<p v-else-if="state === 'error'" class="state">Couldn't load this page.</p>
|
||||
|
||||
<template v-else-if="state === 'missing'">
|
||||
<section v-if="isAdmin" class="create bdr-2 bg-surface">
|
||||
<h3>No page here yet — make one?</h3>
|
||||
<PageForm :slug="slug" @created="load" />
|
||||
</section>
|
||||
<NotFound />
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.canvas-page {
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 10px 16px;
|
||||
}
|
||||
.state {
|
||||
text-align: center;
|
||||
color: var(--color-muted);
|
||||
}
|
||||
|
||||
.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,
|
||||
.bar-btn.on {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
.bar-btn.danger:hover {
|
||||
border-color: var(--color-tertiary);
|
||||
color: var(--color-tertiary);
|
||||
}
|
||||
|
||||
.settings,
|
||||
.create {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-width: 420px;
|
||||
margin: 0 auto 10px;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
.settings {
|
||||
position: fixed;
|
||||
top: 80px;
|
||||
left: 16px;
|
||||
z-index: 65;
|
||||
}
|
||||
.settings label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
color: var(--color-muted);
|
||||
}
|
||||
.settings label.check {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.settings label.check input {
|
||||
width: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup>
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
import { ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import Button from "@/components/input/Button.vue";
|
||||
import { usePagesStore } from "@/stores/pages";
|
||||
import { useBoxesStore } from "@/stores/boxes";
|
||||
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.
|
||||
prefix: { type: String, default: "" },
|
||||
starter: { type: String, default: "blank" },
|
||||
});
|
||||
|
||||
const emit = defineEmits(["created"]);
|
||||
const router = useRouter();
|
||||
const pages = usePagesStore();
|
||||
|
||||
const slug = ref(props.slug);
|
||||
const title = ref("");
|
||||
const starter = ref(props.starter);
|
||||
const adminOnly = ref(false);
|
||||
const busy = ref(false);
|
||||
const error = ref("");
|
||||
|
||||
async function submit() {
|
||||
const fullSlug = props.prefix + slug.value.trim().replace(/^\/+|\/+$/g, "");
|
||||
if (!title.value.trim()) {
|
||||
error.value = "Title is required";
|
||||
return;
|
||||
}
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
try {
|
||||
const page = await pages.create({ slug: fullSlug, title: title.value.trim(), adminOnly: adminOnly.value });
|
||||
// Page first, then its boxes: a starter that fails halfway leaves a page
|
||||
// with some boxes, which is easy to finish by hand, rather than boxes
|
||||
// under an address with no page.
|
||||
const boxes = useBoxesStore(page.slug);
|
||||
for (const box of STARTERS.find((s) => s.id === starter.value).boxes(page.title)) {
|
||||
await boxes.create(box);
|
||||
}
|
||||
// On the 404 of the address just created the push is a no-op, since the
|
||||
// route is unchanged; `created` is what tells that view to reload.
|
||||
await router.push(`/${page.slug}`);
|
||||
emit("created", page);
|
||||
} catch (err) {
|
||||
error.value = err?.message || "Failed to create the page";
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<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" />
|
||||
</label>
|
||||
<input v-model="title" type="text" placeholder="Title (required)" />
|
||||
<select v-model="starter">
|
||||
<option v-for="s in STARTERS" :key="s.id" :value="s.id">Start from: {{ s.label }}</option>
|
||||
</select>
|
||||
<label class="check">
|
||||
<input v-model="adminOnly" type="checkbox" />
|
||||
Only admins can see this page
|
||||
</label>
|
||||
<Button type="submit" :disabled="busy">{{ busy ? "Creating…" : "Create page" }}</Button>
|
||||
<p v-if="error" class="text-tertiary">{{ error }}</p>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-form select {
|
||||
padding: 0.5rem;
|
||||
color: var(--color-primary);
|
||||
background: var(--color-surface-deep);
|
||||
border: 1px solid var(--color-primary);
|
||||
}
|
||||
.check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
.check input {
|
||||
width: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Starting layouts for a new canvas page, offered when one is created
|
||||
* (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.
|
||||
*/
|
||||
import { galleryHtml, imageHtml } from "@/views/home3/templates";
|
||||
|
||||
const escape = (s) =>
|
||||
s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[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(
|
||||
"Note",
|
||||
`<style>
|
||||
body { padding: 0; }
|
||||
.note { box-sizing: border-box; height: 100%; padding: .75rem 1rem; background: #f6e27a;
|
||||
color: #2b2610; box-shadow: 2px 3px 0 rgba(0, 0, 0, .35); overflow: auto; }
|
||||
.note h3 { margin: 0 0 .3rem; color: inherit; }
|
||||
</style>
|
||||
<div class="note"><h3>${text}</h3><ul><li>…</li></ul></div>`,
|
||||
{ x, y, w: 260, h: 220 },
|
||||
{ framed: false, adminOnly: true },
|
||||
);
|
||||
return [note("To do", 40, 40), note("Ideas", 330, 40), note("Bugs", 620, 40)].map((box, i) => ({
|
||||
z: i + 1,
|
||||
...box,
|
||||
}));
|
||||
}
|
||||
|
||||
export const STARTERS = [
|
||||
{ id: "blank", label: "Blank", boxes: () => [] },
|
||||
{ id: "shrine", label: "Shrine", boxes: shrine },
|
||||
{ id: "notes", label: "Notes board (admin-only notes)", boxes: notes },
|
||||
];
|
||||
@@ -1,6 +1,9 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/shrines/evangelion` — placeholder, renders <Wip>.
|
||||
* STATUS: no route points here — /shrines/<name> is a canvas page now
|
||||
* (views/canvas/CanvasPage.vue), created from the /shrines index.
|
||||
*
|
||||
* Was route `/shrines/evangelion` — placeholder, renders <Wip>.
|
||||
*/
|
||||
import Wip from "@/components/util/Wip.vue";
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/shrines/gto` — placeholder, renders <Wip>.
|
||||
* STATUS: no route points here — /shrines/<name> is a canvas page now
|
||||
* (views/canvas/CanvasPage.vue), created from the /shrines index.
|
||||
*
|
||||
* Was route `/shrines/gto` — placeholder, renders <Wip>.
|
||||
*/
|
||||
import Wip from "@/components/util/Wip.vue";
|
||||
</script>
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/shrines` — index of the shrine pages.
|
||||
* Route `/shrines` — index of the shrine pages. Demoman is a hand-written
|
||||
* view; every other shrine is a canvas page (views/canvas/) whose address
|
||||
* starts with "shrines/", listed from the pages query. Admins get a form to
|
||||
* start a new one from the Shrine layout.
|
||||
*/
|
||||
import { computed } from "vue";
|
||||
import RouterTable from "@/components/util/RouterTable.vue";
|
||||
const shrine_links = [
|
||||
{ name: "Demoman", link: "/shrines/demoman" },
|
||||
{ name: "Evangelion", link: "/shrines/evangelion" },
|
||||
{ name: "GTO", link: "/shrines/gto" },
|
||||
{ name: "Skipskipbenben", link: "/shrines/skipskipbenben" },
|
||||
];
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { usePagesStore } from "@/stores/pages";
|
||||
import PageForm from "@/views/canvas/PageForm.vue";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const pages = usePagesStore();
|
||||
auth.ensureLoaded();
|
||||
pages.fetch();
|
||||
|
||||
const isAdmin = computed(() => auth.loggedIn && !!auth.user.admin);
|
||||
|
||||
const shrine_links = computed(() =>
|
||||
[
|
||||
{ name: "Demoman", link: "/shrines/demoman" },
|
||||
...pages.pages
|
||||
.filter((p) => p.slug.startsWith("shrines/"))
|
||||
.map((p) => ({ name: p.adminOnly ? `${p.title} 🔒` : p.title, link: `/${p.slug}` })),
|
||||
].sort((a, b) => a.name.localeCompare(b.name)),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -17,6 +34,10 @@ const shrine_links = [
|
||||
class="page-a4 bdr-1 flex flex-col relative overflow-scroll gap-1"
|
||||
>
|
||||
<RouterTable :linkArr="shrine_links" />
|
||||
<section v-if="isAdmin" class="mt-4">
|
||||
<h3>New shrine</h3>
|
||||
<PageForm prefix="shrines/" starter="shrine" />
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/shrines/skipskipbenben` — placeholder, renders <Wip>.
|
||||
* STATUS: no route points here — /shrines/<name> is a canvas page now
|
||||
* (views/canvas/CanvasPage.vue), created from the /shrines index.
|
||||
*
|
||||
* Was route `/shrines/skipskipbenben` — placeholder, renders <Wip>.
|
||||
*/
|
||||
import Wip from "@/components/util/Wip.vue";
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
<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's overlay and
|
||||
* every admin-created page (views/canvas/CanvasPage.vue) 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
|
||||
* and shrunk with transform: scale() to fit narrower windows, so what the
|
||||
* admin arranges is exactly what every desktop visitor sees, just smaller.
|
||||
* The canvas is as tall as its lowest box.
|
||||
*
|
||||
* At phone width the canvas would be unreadably small, so the boxes are laid
|
||||
* out in a single column instead: reading order is top-to-bottom then
|
||||
* left-to-right by their canvas position, each keeps its height, and any box
|
||||
* flagged hideOnMobile is skipped. There is no separate mobile layout to
|
||||
* maintain, and no editing at that width.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* `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
|
||||
* fixed content. The parent must be position: relative; the canvas covers it
|
||||
* from the top, lets clicks through everywhere except on boxes (until edit
|
||||
* mode, which owns the whole area), and reports its height through `height`
|
||||
* so the parent can grow to contain it. On a phone the overlay's boxes stack
|
||||
* below the parent's content like any other canvas.
|
||||
*/
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { useMediaQuery } from "@vueuse/core";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useBoxesStore } from "@/stores/boxes";
|
||||
import BoxFrame from "./BoxFrame.vue";
|
||||
import BoxEditor from "./BoxEditor.vue";
|
||||
import HtmlBox from "./HtmlBox.vue";
|
||||
import WidgetBox from "./WidgetBox.vue";
|
||||
import { WIDGETS } from "./widgetRegistry";
|
||||
import { TEMPLATES } from "./templates";
|
||||
|
||||
const props = defineProps({
|
||||
page: { type: String, required: true },
|
||||
overlay: { type: Boolean, default: false },
|
||||
// Layout offered by "Import starter layout" on an empty canvas: a function
|
||||
// returning box inputs, or null for no button.
|
||||
starter: { type: Function, default: null },
|
||||
starterLabel: { type: String, default: "Import starter layout" },
|
||||
});
|
||||
const emit = defineEmits(["height"]);
|
||||
|
||||
const CANVAS_W = 1400;
|
||||
const MOBILE_QUERY = "(max-width: 700px)";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const store = useBoxesStore(props.page);
|
||||
// The standalone `me` query, not the home query: a canvas of only HTML boxes
|
||||
// mounts no widget, and the landing page must not fan out to Spotify and
|
||||
// Steam just to learn whether to show an Edit button.
|
||||
auth.ensureLoaded();
|
||||
|
||||
store.fetch();
|
||||
|
||||
const isMobile = useMediaQuery(MOBILE_QUERY);
|
||||
const isAdmin = computed(() => auth.loggedIn && !!auth.user.admin);
|
||||
// adminOnly boxes come and go with the session.
|
||||
watch(isAdmin, () => store.fetch());
|
||||
|
||||
const editing = ref(false);
|
||||
const canEdit = computed(() => isAdmin.value && !isMobile.value);
|
||||
const inEditMode = computed(() => editing.value && canEdit.value);
|
||||
|
||||
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);
|
||||
const availableW = ref(CANVAS_W);
|
||||
let observer = null;
|
||||
onMounted(() => {
|
||||
observer = new ResizeObserver(([entry]) => (availableW.value = entry.contentRect.width));
|
||||
if (viewport.value) observer.observe(viewport.value);
|
||||
});
|
||||
onBeforeUnmount(() => observer?.disconnect());
|
||||
// The viewport is only rendered on desktop, so it appears and disappears as
|
||||
// the window crosses the phone breakpoint.
|
||||
watch(viewport, (el, old) => {
|
||||
if (old) observer?.unobserve(old);
|
||||
if (el) observer?.observe(el);
|
||||
});
|
||||
|
||||
const scale = computed(() => Math.min(1, availableW.value / CANVAS_W));
|
||||
const contentH = computed(() => Math.max(0, ...store.boxes.map((b) => b.y + b.h)));
|
||||
// Spare room below the lowest box while editing, so there is somewhere to
|
||||
// drag to. An overlay has no floor of its own: empty, it should take no room.
|
||||
const canvasH = computed(() => {
|
||||
const floor = props.overlay && !inEditMode.value ? 0 : 400;
|
||||
return Math.max(floor, contentH.value + (inEditMode.value ? 400 : 40));
|
||||
});
|
||||
|
||||
watch(
|
||||
() => (props.overlay && !isMobile.value ? canvasH.value * scale.value : 0),
|
||||
(h) => emit("height", h),
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// ---- Mobile ordering -----------------------------------------------------
|
||||
const stacked = computed(() =>
|
||||
store.boxes.filter((b) => !b.hideOnMobile).sort((a, b) => a.y - b.y || a.x - b.x),
|
||||
);
|
||||
|
||||
// ---- Saving --------------------------------------------------------------
|
||||
function report(err) {
|
||||
errorMsg.value = err?.message ?? String(err);
|
||||
setTimeout(() => (errorMsg.value = ""), 6000);
|
||||
}
|
||||
|
||||
// The new geometry is applied locally before the request so the box stays
|
||||
// where it was dropped instead of snapping back until the server answers;
|
||||
// on failure it is put back.
|
||||
async function commitGeometry(box, geom) {
|
||||
const before = { x: box.x, y: box.y, w: box.w, h: box.h };
|
||||
Object.assign(box, geom);
|
||||
try {
|
||||
await store.update(box.id, geom);
|
||||
} catch (err) {
|
||||
Object.assign(box, before);
|
||||
report(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function run(action) {
|
||||
try {
|
||||
await action();
|
||||
} catch (err) {
|
||||
report(err);
|
||||
}
|
||||
}
|
||||
|
||||
function onAction(box, action) {
|
||||
if (action === "front") run(() => store.bringToFront(box));
|
||||
else if (action === "back") run(() => store.sendToBack(box));
|
||||
else if (action === "duplicate") {
|
||||
run(async () => (selectedId.value = (await store.duplicate(box)).id));
|
||||
} else if (action === "delete") {
|
||||
if (!confirm(`Delete “${labelOf(box)}”? This can't be undone from here.`)) return;
|
||||
if (selectedId.value === box.id) selectedId.value = null;
|
||||
run(() => store.remove(box.id));
|
||||
}
|
||||
}
|
||||
|
||||
function labelOf(box) {
|
||||
const name = box.title || (box.kind === "widget" ? box.widget : "HTML");
|
||||
return box.adminOnly ? `🔒 ${name}` : name;
|
||||
}
|
||||
|
||||
// ---- Creating ------------------------------------------------------------
|
||||
const canvasEl = ref(null);
|
||||
|
||||
// Top-left of the part of the canvas currently on screen, so a new box
|
||||
// appears where the admin is looking rather than at the top of the page.
|
||||
function visibleOrigin() {
|
||||
const rect = canvasEl.value?.getBoundingClientRect();
|
||||
const top = rect ? Math.max(0, -rect.top / scale.value) : 0;
|
||||
const origin = { x: 40, y: Math.round(top / 5) * 5 + 40 };
|
||||
// Cascade, so adding several boxes in a row doesn't stack them exactly on
|
||||
// top of one another.
|
||||
while (store.boxes.some((b) => b.x === origin.x && b.y === origin.y)) {
|
||||
origin.x += 20;
|
||||
origin.y += 20;
|
||||
}
|
||||
return origin;
|
||||
}
|
||||
|
||||
const newChoice = ref("");
|
||||
function addBox() {
|
||||
const choice = newChoice.value;
|
||||
newChoice.value = "";
|
||||
if (!choice) return;
|
||||
const [kind, key] = choice.split(":");
|
||||
const { x, y } = visibleOrigin();
|
||||
let input;
|
||||
if (kind === "widget") {
|
||||
const [w, h] = WIDGETS[key].size;
|
||||
input = { kind: "widget", widget: key, w, h };
|
||||
} else {
|
||||
const t = TEMPLATES[Number(key)];
|
||||
input = {
|
||||
kind: "html",
|
||||
html: t.html,
|
||||
title: t.title,
|
||||
w: t.size[0],
|
||||
h: t.size[1],
|
||||
framed: t.framed ?? true,
|
||||
adminOnly: t.adminOnly ?? false,
|
||||
};
|
||||
}
|
||||
run(async () => {
|
||||
const created = await store.create({ ...input, x, y, z: store.topZ() });
|
||||
selectedId.value = created.id;
|
||||
});
|
||||
}
|
||||
|
||||
const importing = ref(false);
|
||||
async function importStarter() {
|
||||
importing.value = true;
|
||||
try {
|
||||
// Sequential, so the boxes come back in z order without a refetch.
|
||||
for (const box of props.starter()) await store.create(box);
|
||||
} catch (err) {
|
||||
report(err);
|
||||
} finally {
|
||||
importing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Selection -----------------------------------------------------------
|
||||
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>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="box-canvas"
|
||||
:class="{
|
||||
'with-editor': inEditMode && selected,
|
||||
overlay: overlay && !isMobile,
|
||||
'overlay-editing': overlay && inEditMode,
|
||||
}"
|
||||
>
|
||||
<div v-if="canEdit" class="admin-bar">
|
||||
<button type="button" class="bar-btn" :class="{ on: editing }" @click="toggleEdit">
|
||||
{{ editing ? "Done" : overlay ? "Edit notes" : "Edit layout" }}
|
||||
</button>
|
||||
<template v-if="inEditMode">
|
||||
<select v-model="newChoice" class="bar-btn" @change="addBox">
|
||||
<option value="" disabled>+ New box…</option>
|
||||
<optgroup label="HTML">
|
||||
<option v-for="(t, i) in TEMPLATES" :key="t.label" :value="`html:${i}`">{{ t.label }}</option>
|
||||
</optgroup>
|
||||
<optgroup label="Widget">
|
||||
<option v-for="name in Object.keys(WIDGETS)" :key="name" :value="`widget:${name}`">{{ name }}</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
<button
|
||||
v-if="starter && store.loaded && store.boxes.length === 0"
|
||||
type="button"
|
||||
class="bar-btn"
|
||||
:disabled="importing"
|
||||
@click="importStarter"
|
||||
>
|
||||
{{ importing ? "Importing…" : starterLabel }}
|
||||
</button>
|
||||
</template>
|
||||
<slot name="admin-bar" :editing="inEditMode" />
|
||||
<span v-if="errorMsg" class="error">{{ errorMsg }}</span>
|
||||
</div>
|
||||
|
||||
<p v-if="store.error" class="state">Couldn't load the page layout.</p>
|
||||
<p v-else-if="!overlay && store.loaded && store.boxes.length === 0 && !canEdit" class="state">
|
||||
Nothing here yet.
|
||||
</p>
|
||||
|
||||
<!-- Phone: one column, no editing -->
|
||||
<div v-if="isMobile" class="stack">
|
||||
<div
|
||||
v-for="box in stacked"
|
||||
:key="box.id"
|
||||
class="stack-item"
|
||||
:class="{ framed: box.framed, 'admin-only': box.adminOnly }"
|
||||
:style="{ height: `${box.h}px` }"
|
||||
>
|
||||
<WidgetBox v-if="box.kind === 'widget'" :name="box.widget" />
|
||||
<HtmlBox v-else :html="box.html" :title="box.title" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Desktop: the scaled canvas -->
|
||||
<div v-else ref="viewport" class="viewport">
|
||||
<div
|
||||
class="canvas-size"
|
||||
:style="{ width: `${CANVAS_W * scale}px`, height: `${canvasH * scale}px` }"
|
||||
>
|
||||
<div
|
||||
ref="canvasEl"
|
||||
class="canvas"
|
||||
:class="{ editing: inEditMode }"
|
||||
:style="{ width: `${CANVAS_W}px`, height: `${canvasH}px`, transform: `scale(${scale})` }"
|
||||
@pointerdown.self="selectedId = null"
|
||||
>
|
||||
<BoxFrame
|
||||
v-for="box in store.boxes"
|
||||
:key="box.id"
|
||||
:box="box"
|
||||
:scale="scale"
|
||||
:editing="inEditMode"
|
||||
:selected="inEditMode && box.id === selectedId"
|
||||
:label="labelOf(box)"
|
||||
@select="select(box)"
|
||||
@commit="commitGeometry(box, $event)"
|
||||
@action="onAction(box, $event)"
|
||||
>
|
||||
<WidgetBox v-if="box.kind === 'widget'" :name="box.widget" />
|
||||
<HtmlBox
|
||||
v-else
|
||||
:html="box.id === selectedId && preview !== null ? preview : box.html"
|
||||
:title="box.title"
|
||||
/>
|
||||
</BoxFrame>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<BoxEditor
|
||||
v-if="inEditMode && selected"
|
||||
ref="editor"
|
||||
:box="selected"
|
||||
@preview="preview = $event"
|
||||
@close="selectedId = null"
|
||||
@error="report"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.box-canvas {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
/* Leave room for the fixed editor panel so the canvas rescales beside it
|
||||
instead of disappearing under it. */
|
||||
.box-canvas.with-editor {
|
||||
padding-right: calc(min(460px, 100vw) + 16px);
|
||||
}
|
||||
|
||||
/* Over the parent's content: only the boxes take clicks, so the page
|
||||
underneath stays usable. In edit mode the whole area does, so a click on
|
||||
empty canvas deselects rather than following a link underneath. */
|
||||
.box-canvas.overlay {
|
||||
position: absolute;
|
||||
inset: 0 0 auto 0;
|
||||
z-index: 20;
|
||||
pointer-events: none;
|
||||
}
|
||||
.box-canvas.overlay :deep(.box),
|
||||
.box-canvas.overlay .admin-bar,
|
||||
.box-canvas.overlay-editing .canvas {
|
||||
pointer-events: auto;
|
||||
}
|
||||
/* An overlay's bar must not push the canvas down off the content it is
|
||||
aligned with, so it floats in the corner of the window — above the
|
||||
layout's footer bar. */
|
||||
.box-canvas.overlay .admin-bar {
|
||||
position: fixed;
|
||||
left: 16px;
|
||||
bottom: 56px;
|
||||
z-index: 70;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin: 0 auto 10px;
|
||||
max-width: 1400px;
|
||||
}
|
||||
.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,
|
||||
.bar-btn.on {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
.bar-btn:disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.error {
|
||||
color: var(--color-tertiary);
|
||||
}
|
||||
.state {
|
||||
text-align: center;
|
||||
color: var(--color-muted);
|
||||
}
|
||||
|
||||
.viewport {
|
||||
width: 100%;
|
||||
}
|
||||
.canvas-size {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.canvas {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
/* 20px dot grid while editing, to line things up by eye. */
|
||||
.canvas.editing {
|
||||
outline: 1px dashed var(--color-quaternary);
|
||||
background-image: radial-gradient(var(--color-quaternary) 1px, transparent 1px);
|
||||
background-size: 20px 20px;
|
||||
}
|
||||
|
||||
.stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
.stack-item {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.stack-item.framed {
|
||||
background-color: var(--color-surface);
|
||||
border: 2px solid var(--color-quaternary);
|
||||
}
|
||||
.stack-item.admin-only {
|
||||
outline: 2px dashed var(--color-tertiary);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
</style>
|
||||
@@ -10,9 +10,16 @@
|
||||
* `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.
|
||||
*
|
||||
* "Insert upload" stores a file through the chat's upload endpoint (public,
|
||||
* unguessable URLs under /uploads/) and puts a tag for it at the cursor —
|
||||
* the quick way to fill a shrine with images. It is never the private upload
|
||||
* directory: that one is behind a cookie check, and the sandboxed frame
|
||||
* loads as an opaque origin, so its requests may not carry the cookie.
|
||||
*/
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useBoxesStore } from "@/stores/boxes";
|
||||
import { api } from "@/api";
|
||||
import CodeEditor from "./CodeEditor.vue";
|
||||
import { WIDGETS } from "./widgetRegistry";
|
||||
|
||||
@@ -21,7 +28,11 @@ const props = defineProps({
|
||||
});
|
||||
const emit = defineEmits(["preview", "close", "error"]);
|
||||
|
||||
const store = useBoxesStore();
|
||||
// A box only ever moves within its own page's store.
|
||||
const store = useBoxesStore(props.box.page);
|
||||
const codeEditor = ref(null);
|
||||
const fileInput = ref(null);
|
||||
const uploading = ref(false);
|
||||
|
||||
const draftHtml = ref(props.box.html ?? "");
|
||||
const saving = ref(false);
|
||||
@@ -73,6 +84,33 @@ 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 `<img src="${url}" alt="">`;
|
||||
if (/\.(mp4|webm)$/i.test(url)) return `<video src="${url}" controls loop muted></video>`;
|
||||
if (/\.(mp3|ogg)$/i.test(url)) return `<audio src="${url}" controls></audio>`;
|
||||
return `<a href="${url}" target="_blank">${url.split("/").pop()}</a>`;
|
||||
}
|
||||
|
||||
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);
|
||||
if (!codeEditor.value?.insert(tag)) draftHtml.value += `\n${tag}`;
|
||||
} catch (err) {
|
||||
emit("error", err);
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (dirty.value && !confirm("Discard unsaved HTML changes?")) return;
|
||||
emit("preview", null);
|
||||
@@ -120,7 +158,7 @@ defineExpose({ close });
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4">
|
||||
<div class="flex flex-wrap gap-x-4 gap-y-1">
|
||||
<label class="check">
|
||||
<input type="checkbox" :checked="box.framed" @change="save({ framed: $event.target.checked })" />
|
||||
Frame
|
||||
@@ -133,15 +171,35 @@ defineExpose({ close });
|
||||
/>
|
||||
Hide on mobile
|
||||
</label>
|
||||
<label class="check" title="Only signed-in admins are sent this box">
|
||||
<input type="checkbox" :checked="box.adminOnly" @change="save({ adminOnly: $event.target.checked })" />
|
||||
Admin only
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<template v-if="box.kind === 'html'">
|
||||
<CodeEditor v-model="draftHtml" class="flex-1" @save="saveHtml" />
|
||||
<CodeEditor ref="codeEditor" v-model="draftHtml" class="flex-1" @save="saveHtml" />
|
||||
<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.
|
||||
</small>
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept="image/*,video/mp4,video/webm,audio/mpeg,audio/ogg"
|
||||
hidden
|
||||
@change="upload"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="save"
|
||||
:disabled="uploading"
|
||||
title="Upload a file and insert it at the cursor"
|
||||
@click="fileInput.click()"
|
||||
>
|
||||
{{ uploading ? "Uploading…" : "Insert upload" }}
|
||||
</button>
|
||||
<button type="button" class="save" :disabled="!dirty || saving" @click="saveHtml">
|
||||
{{ saving ? "Saving…" : dirty ? "Save" : "Saved" }}
|
||||
</button>
|
||||
|
||||
@@ -105,7 +105,7 @@ function end() {
|
||||
<template>
|
||||
<div
|
||||
class="box"
|
||||
:class="{ framed: box.framed, editing, selected }"
|
||||
:class="{ framed: box.framed, editing, selected, 'admin-only': box.adminOnly }"
|
||||
:style="style"
|
||||
>
|
||||
<slot />
|
||||
@@ -146,6 +146,12 @@ function end() {
|
||||
background-color: var(--color-surface);
|
||||
border: 2px solid var(--color-quaternary);
|
||||
}
|
||||
/* Only admins are ever sent an adminOnly box; the outline reminds them that
|
||||
nobody else can see it. */
|
||||
.box.admin-only:not(.editing) {
|
||||
outline: 2px dashed var(--color-tertiary);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
position: absolute;
|
||||
|
||||
@@ -71,6 +71,17 @@ watch(
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => view?.destroy());
|
||||
|
||||
/** Put text at the cursor (replacing any selection); false if the editor
|
||||
* isn't loaded, so the caller can fall back to appending it. */
|
||||
function insert(text) {
|
||||
if (!view) return false;
|
||||
view.dispatch(view.state.replaceSelection(text));
|
||||
view.focus();
|
||||
return true;
|
||||
}
|
||||
|
||||
defineExpose({ insert });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,288 +1,17 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/stp` — the home page as a free-form canvas of boxes the admin
|
||||
* arranges in the browser. Replaces views/home/Home.vue's fixed grid.
|
||||
*
|
||||
* Every box (stores/boxes.js, 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 and shrunk with transform: scale() to fit narrower windows, so
|
||||
* what the admin arranges is exactly what every desktop visitor sees, just
|
||||
* smaller. The canvas is as tall as its lowest box.
|
||||
*
|
||||
* At phone width the canvas would be unreadably small, so the boxes are laid
|
||||
* out in a single column instead: reading order is top-to-bottom then
|
||||
* left-to-right by their canvas position, each keeps its height, and any box
|
||||
* flagged hideOnMobile is skipped. There is no separate mobile layout to
|
||||
* maintain, and no editing at that width.
|
||||
*
|
||||
* Admins get an Edit toggle. In edit mode boxes drag and resize (BoxFrame),
|
||||
* changes save on release, and the selected box opens in BoxEditor.
|
||||
* 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.
|
||||
*/
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { useMediaQuery } from "@vueuse/core";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useBoxesStore } from "@/stores/boxes";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
import BoxFrame from "./BoxFrame.vue";
|
||||
import BoxEditor from "./BoxEditor.vue";
|
||||
import HtmlBox from "./HtmlBox.vue";
|
||||
import WidgetBox from "./WidgetBox.vue";
|
||||
import { WIDGETS } from "./widgetRegistry";
|
||||
import { TEMPLATES } from "./templates";
|
||||
import BoxCanvas from "./BoxCanvas.vue";
|
||||
import { defaultLayout } from "./defaultLayout";
|
||||
|
||||
const CANVAS_W = 1400;
|
||||
const MOBILE_QUERY = "(max-width: 700px)";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const store = useBoxesStore();
|
||||
// The widgets each start the shared home query when they mount, but a canvas
|
||||
// of only HTML boxes would mount none — and that query is also what tells
|
||||
// auth who is signed in on this page (see stores/auth.js), so without it the
|
||||
// Edit button would never appear. Instantiating the store fires it.
|
||||
useHomeDataStore();
|
||||
|
||||
store.fetch();
|
||||
|
||||
const isMobile = useMediaQuery(MOBILE_QUERY);
|
||||
const isAdmin = computed(() => auth.loggedIn && !!auth.user.admin);
|
||||
const editing = ref(false);
|
||||
const canEdit = computed(() => isAdmin.value && !isMobile.value);
|
||||
const inEditMode = computed(() => editing.value && canEdit.value);
|
||||
|
||||
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);
|
||||
const availableW = ref(CANVAS_W);
|
||||
let observer = null;
|
||||
onMounted(() => {
|
||||
observer = new ResizeObserver(([entry]) => (availableW.value = entry.contentRect.width));
|
||||
if (viewport.value) observer.observe(viewport.value);
|
||||
});
|
||||
onBeforeUnmount(() => observer?.disconnect());
|
||||
|
||||
const scale = computed(() => Math.min(1, availableW.value / CANVAS_W));
|
||||
const contentH = computed(() => Math.max(0, ...store.boxes.map((b) => b.y + b.h)));
|
||||
// Spare room below the lowest box while editing, so there is somewhere to
|
||||
// drag to.
|
||||
const canvasH = computed(() => Math.max(400, contentH.value + (inEditMode.value ? 400 : 40)));
|
||||
|
||||
// ---- Mobile ordering -----------------------------------------------------
|
||||
const stacked = computed(() =>
|
||||
store.boxes.filter((b) => !b.hideOnMobile).sort((a, b) => a.y - b.y || a.x - b.x),
|
||||
);
|
||||
|
||||
// ---- Saving --------------------------------------------------------------
|
||||
function report(err) {
|
||||
errorMsg.value = err?.message ?? String(err);
|
||||
setTimeout(() => (errorMsg.value = ""), 6000);
|
||||
}
|
||||
|
||||
// The new geometry is applied locally before the request so the box stays
|
||||
// where it was dropped instead of snapping back until the server answers;
|
||||
// on failure it is put back.
|
||||
async function commitGeometry(box, geom) {
|
||||
const before = { x: box.x, y: box.y, w: box.w, h: box.h };
|
||||
Object.assign(box, geom);
|
||||
try {
|
||||
await store.update(box.id, geom);
|
||||
} catch (err) {
|
||||
Object.assign(box, before);
|
||||
report(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function run(action) {
|
||||
try {
|
||||
await action();
|
||||
} catch (err) {
|
||||
report(err);
|
||||
}
|
||||
}
|
||||
|
||||
function onAction(box, action) {
|
||||
if (action === "front") run(() => store.bringToFront(box));
|
||||
else if (action === "back") run(() => store.sendToBack(box));
|
||||
else if (action === "duplicate") {
|
||||
run(async () => (selectedId.value = (await store.duplicate(box)).id));
|
||||
} else if (action === "delete") {
|
||||
if (!confirm(`Delete “${labelOf(box)}”? This can't be undone from here.`)) return;
|
||||
if (selectedId.value === box.id) selectedId.value = null;
|
||||
run(() => store.remove(box.id));
|
||||
}
|
||||
}
|
||||
|
||||
function labelOf(box) {
|
||||
return box.title || (box.kind === "widget" ? box.widget : "HTML");
|
||||
}
|
||||
|
||||
// ---- Creating ------------------------------------------------------------
|
||||
const canvasEl = ref(null);
|
||||
|
||||
// Top-left of the part of the canvas currently on screen, so a new box
|
||||
// appears where the admin is looking rather than at the top of the page.
|
||||
function visibleOrigin() {
|
||||
const rect = canvasEl.value?.getBoundingClientRect();
|
||||
const top = rect ? Math.max(0, -rect.top / scale.value) : 0;
|
||||
const origin = { x: 40, y: Math.round(top / 5) * 5 + 40 };
|
||||
// Cascade, so adding several boxes in a row doesn't stack them exactly on
|
||||
// top of one another.
|
||||
while (store.boxes.some((b) => b.x === origin.x && b.y === origin.y)) {
|
||||
origin.x += 20;
|
||||
origin.y += 20;
|
||||
}
|
||||
return origin;
|
||||
}
|
||||
|
||||
const newChoice = ref("");
|
||||
function addBox() {
|
||||
const choice = newChoice.value;
|
||||
newChoice.value = "";
|
||||
if (!choice) return;
|
||||
const [kind, key] = choice.split(":");
|
||||
const { x, y } = visibleOrigin();
|
||||
let input;
|
||||
if (kind === "widget") {
|
||||
const [w, h] = WIDGETS[key].size;
|
||||
input = { kind: "widget", widget: key, w, h };
|
||||
} else {
|
||||
const t = TEMPLATES[Number(key)];
|
||||
input = { kind: "html", html: t.html, title: t.title, w: t.size[0], h: t.size[1], framed: t.framed ?? true };
|
||||
}
|
||||
run(async () => {
|
||||
const created = await store.create({ ...input, x, y, z: store.topZ() });
|
||||
selectedId.value = created.id;
|
||||
});
|
||||
}
|
||||
|
||||
const importing = ref(false);
|
||||
async function importDefault() {
|
||||
importing.value = true;
|
||||
try {
|
||||
// Sequential, so the boxes come back in z order without a refetch.
|
||||
for (const box of defaultLayout()) await store.create(box);
|
||||
} catch (err) {
|
||||
report(err);
|
||||
} finally {
|
||||
importing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Selection -----------------------------------------------------------
|
||||
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>
|
||||
|
||||
<template>
|
||||
<main class="home3" :class="{ 'with-editor': inEditMode && selected }">
|
||||
<div v-if="canEdit" class="admin-bar">
|
||||
<button type="button" class="bar-btn" :class="{ on: editing }" @click="toggleEdit">
|
||||
{{ editing ? "Done" : "Edit layout" }}
|
||||
</button>
|
||||
<template v-if="inEditMode">
|
||||
<select v-model="newChoice" class="bar-btn" @change="addBox">
|
||||
<option value="" disabled>+ New box…</option>
|
||||
<optgroup label="HTML">
|
||||
<option v-for="(t, i) in TEMPLATES" :key="t.label" :value="`html:${i}`">{{ t.label }}</option>
|
||||
</optgroup>
|
||||
<optgroup label="Widget">
|
||||
<option v-for="name in Object.keys(WIDGETS)" :key="name" :value="`widget:${name}`">{{ name }}</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
<button
|
||||
v-if="store.loaded && store.boxes.length === 0"
|
||||
type="button"
|
||||
class="bar-btn"
|
||||
:disabled="importing"
|
||||
@click="importDefault"
|
||||
>
|
||||
{{ importing ? "Importing…" : "Import current layout" }}
|
||||
</button>
|
||||
</template>
|
||||
<span v-if="errorMsg" class="error">{{ errorMsg }}</span>
|
||||
</div>
|
||||
|
||||
<p v-if="store.error" class="state">Couldn't load the page layout.</p>
|
||||
<p v-else-if="store.loaded && store.boxes.length === 0 && !canEdit" class="state">Nothing here yet.</p>
|
||||
|
||||
<!-- Phone: one column, no editing -->
|
||||
<div v-if="isMobile" class="stack">
|
||||
<div
|
||||
v-for="box in stacked"
|
||||
:key="box.id"
|
||||
class="stack-item"
|
||||
:class="{ framed: box.framed }"
|
||||
:style="{ height: `${box.h}px` }"
|
||||
>
|
||||
<WidgetBox v-if="box.kind === 'widget'" :name="box.widget" />
|
||||
<HtmlBox v-else :html="box.html" :title="box.title" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Desktop: the scaled canvas -->
|
||||
<div v-else ref="viewport" class="viewport">
|
||||
<div
|
||||
class="canvas-size"
|
||||
:style="{ width: `${CANVAS_W * scale}px`, height: `${canvasH * scale}px` }"
|
||||
>
|
||||
<div
|
||||
ref="canvasEl"
|
||||
class="canvas"
|
||||
:class="{ editing: inEditMode }"
|
||||
:style="{ width: `${CANVAS_W}px`, height: `${canvasH}px`, transform: `scale(${scale})` }"
|
||||
@pointerdown.self="selectedId = null"
|
||||
>
|
||||
<BoxFrame
|
||||
v-for="box in store.boxes"
|
||||
:key="box.id"
|
||||
:box="box"
|
||||
:scale="scale"
|
||||
:editing="inEditMode"
|
||||
:selected="inEditMode && box.id === selectedId"
|
||||
:label="labelOf(box)"
|
||||
@select="select(box)"
|
||||
@commit="commitGeometry(box, $event)"
|
||||
@action="onAction(box, $event)"
|
||||
>
|
||||
<WidgetBox v-if="box.kind === 'widget'" :name="box.widget" />
|
||||
<HtmlBox
|
||||
v-else
|
||||
:html="box.id === selectedId && preview !== null ? preview : box.html"
|
||||
:title="box.title"
|
||||
/>
|
||||
</BoxFrame>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<BoxEditor
|
||||
v-if="inEditMode && selected"
|
||||
ref="editor"
|
||||
:box="selected"
|
||||
@preview="preview = $event"
|
||||
@close="selectedId = null"
|
||||
@error="report"
|
||||
/>
|
||||
<main class="home3">
|
||||
<BoxCanvas page="stp" :starter="defaultLayout" starter-label="Import current layout" />
|
||||
</main>
|
||||
</template>
|
||||
|
||||
@@ -293,78 +22,4 @@ function toggleEdit() {
|
||||
box-sizing: border-box;
|
||||
padding: 10px 16px;
|
||||
}
|
||||
/* Leave room for the fixed editor panel so the canvas rescales beside it
|
||||
instead of disappearing under it. */
|
||||
.home3.with-editor {
|
||||
padding-right: calc(min(460px, 100vw) + 16px);
|
||||
}
|
||||
|
||||
.admin-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin: 0 auto 10px;
|
||||
max-width: 1400px;
|
||||
}
|
||||
.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,
|
||||
.bar-btn.on {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
.bar-btn:disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.error {
|
||||
color: var(--color-tertiary);
|
||||
}
|
||||
.state {
|
||||
text-align: center;
|
||||
color: var(--color-muted);
|
||||
}
|
||||
|
||||
.viewport {
|
||||
width: 100%;
|
||||
}
|
||||
.canvas-size {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.canvas {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
/* 20px dot grid while editing, to line things up by eye. */
|
||||
.canvas.editing {
|
||||
outline: 1px dashed var(--color-quaternary);
|
||||
background-image: radial-gradient(var(--color-quaternary) 1px, transparent 1px);
|
||||
background-size: 20px 20px;
|
||||
}
|
||||
|
||||
.stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
.stack-item {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.stack-item.framed {
|
||||
background-color: var(--color-surface);
|
||||
border: 2px solid var(--color-quaternary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -85,12 +85,72 @@ const imageHtml = (src) => `<style>
|
||||
const EMPTY = `<h3>New box</h3>
|
||||
<p>Edit me.</p>`;
|
||||
|
||||
/** Menu entries; `size` is [w, h] in canvas px. */
|
||||
// A sticky note for reminders to self. Unframed, since the note is its own
|
||||
// frame; the menu entry makes it adminOnly.
|
||||
const NOTE = `<style>
|
||||
body { padding: 0; }
|
||||
.note {
|
||||
box-sizing: border-box; height: 100%; padding: .75rem 1rem;
|
||||
background: #f6e27a; color: #2b2610; transform: rotate(-1deg);
|
||||
box-shadow: 2px 3px 0 rgba(0, 0, 0, .35); overflow: auto;
|
||||
}
|
||||
.note h3 { margin: 0 0 .3rem; color: inherit; font-family: var(--font-heading); }
|
||||
.note ul { margin: 0; padding-left: 1.1rem; }
|
||||
</style>
|
||||
<div class="note">
|
||||
<h3>TODO</h3>
|
||||
<ul>
|
||||
<li>Something to implement</li>
|
||||
</ul>
|
||||
</div>`;
|
||||
|
||||
const HEADING = `<style>
|
||||
body { display: grid; place-items: center; text-align: center; }
|
||||
h1 { margin: 0; font-family: var(--font-heading); color: var(--color-primary); font-size: 3.5rem; line-height: 1; }
|
||||
p { margin: .25rem 0 0; color: var(--color-tertiary); }
|
||||
</style>
|
||||
<div>
|
||||
<h1>Title</h1>
|
||||
<p>subtitle</p>
|
||||
</div>`;
|
||||
|
||||
const TEXT = `<h3>Heading</h3>
|
||||
<p>
|
||||
A paragraph about it. <b>Bold</b>, <i>italic</i> and
|
||||
<a href="https://example.com" target="_blank">links</a> all work.
|
||||
</p>
|
||||
<blockquote>“A quote you like.”</blockquote>`;
|
||||
|
||||
// A scrolling grid of images. "Insert upload" in the editor adds more.
|
||||
const galleryHtml = (srcs) => `<style>
|
||||
body { padding: 4px; }
|
||||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }
|
||||
.grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
|
||||
</style>
|
||||
<div class="grid">
|
||||
${srcs.map((src) => ` <img src="${src}" alt="">`).join("\n")}
|
||||
</div>`;
|
||||
|
||||
const VIDEO = `<style>
|
||||
body { padding: 0; overflow: hidden; background: #000; }
|
||||
video { display: block; width: 100%; height: 100%; object-fit: contain; }
|
||||
</style>
|
||||
<video src="/img/demoman/1760582395316219.webm" controls loop muted></video>`;
|
||||
|
||||
/**
|
||||
* Menu entries; `size` is [w, h] in canvas px. `adminOnly` sets the new
|
||||
* box's flag, which can be changed afterwards in the editor.
|
||||
*/
|
||||
export const TEMPLATES = [
|
||||
{ label: "Note (admin only)", title: "Note", html: NOTE, size: [260, 200], framed: false, adminOnly: true },
|
||||
{ label: "Heading", title: "Heading", html: HEADING, size: [600, 140], framed: false },
|
||||
{ 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: "Clock", title: "Clock", html: CLOCK, size: [240, 120] },
|
||||
{ label: "Weather", title: "Weather", html: WEATHER, size: [240, 170] },
|
||||
{ label: "Image / GIF", title: "Image", html: imageHtml("/img/memes/fire-woman.gif"), size: [240, 240], framed: false },
|
||||
{ label: "Empty HTML", title: "HTML", html: EMPTY, size: [300, 200] },
|
||||
];
|
||||
|
||||
export { imageHtml };
|
||||
export { imageHtml, galleryHtml };
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Route `/` — the professional front door. Deliberately plain: a short bio and a
|
||||
* row of links out to the CV, the personal home page (/stp), the projects that
|
||||
* run as their own containers, and social profiles.
|
||||
* row of links out to the CV, the personal home page (/stp), the shrines, the
|
||||
* projects that run as their own containers, and social profiles.
|
||||
* Statically imported by the router (it is the first paint).
|
||||
*
|
||||
* Over it lies a BoxCanvas overlay (page key "index"), where the admin pins
|
||||
* notes and anything else; admin-only notes are never sent to visitors. With
|
||||
* no boxes the overlay takes no room and the page is exactly as before.
|
||||
*/
|
||||
import { defineAsyncComponent, ref } from "vue";
|
||||
import Link from "@/components/text/Link.vue";
|
||||
import InlineLink from "@/components/text/InlineLink.vue";
|
||||
import Header from "@/components/text/Header.vue";
|
||||
@@ -18,6 +23,15 @@ const projects = [
|
||||
{ name: "USACO", href: "/usaco/" },
|
||||
];
|
||||
|
||||
// Loaded after first paint, in its own chunk: the landing page is the one
|
||||
// view in the main bundle, and the canvas brings the box editor with it.
|
||||
const BoxCanvas = defineAsyncComponent(() =>
|
||||
import("@/views/home3/BoxCanvas.vue"),
|
||||
);
|
||||
|
||||
// The overlay is absolutely positioned, so the page grows to contain it.
|
||||
const overlayHeight = ref(0);
|
||||
|
||||
const links = [
|
||||
{ name: "GitHub", href: "https://github.com/SteveThePug" },
|
||||
{ name: "Gitea", href: "/gitea/explore/repos" },
|
||||
@@ -26,41 +40,45 @@ const links = [
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="flex justify-center px-4 py-16">
|
||||
<div class="max-w-xl w-full flex flex-col gap-12">
|
||||
<section>
|
||||
<Header>Adam French</Header>
|
||||
<Paragraph>
|
||||
Junior software engineer focused on full-stack development, systems
|
||||
programming, and infrastructure. First Class Honours in Computer
|
||||
Science with Mathematics from Leeds and Waterloo.
|
||||
</Paragraph>
|
||||
</section>
|
||||
<main class="relative" :style="{ minHeight: `${overlayHeight}px` }">
|
||||
<div class="flex justify-center px-4 py-16">
|
||||
<div class="max-w-xl w-full flex flex-col gap-12">
|
||||
<section>
|
||||
<Header>Adam French</Header>
|
||||
<Paragraph>
|
||||
Junior software engineer focused on full-stack development, systems
|
||||
programming, and infrastructure. First Class Honours in Computer
|
||||
Science with Mathematics from Leeds and Waterloo.
|
||||
</Paragraph>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Header>About</Header>
|
||||
<Paragraph>
|
||||
This website is self-hosted and has a lot more on it than it needs to.
|
||||
Please have a look at my
|
||||
<InlineLink to="/cv">CV</InlineLink> for a full breakdown of my
|
||||
experience, projects, and skills. Please visit
|
||||
<InlineLink to="/stp">STP</InlineLink> for the prefered but less
|
||||
professional experience.
|
||||
</Paragraph>
|
||||
</section>
|
||||
<section>
|
||||
<Header>About</Header>
|
||||
<Paragraph>
|
||||
This website is self-hosted and has a lot more on it than it needs to.
|
||||
Please have a look at my
|
||||
<InlineLink to="/cv">CV</InlineLink> for a full breakdown of my
|
||||
experience, projects, and skills. Please visit
|
||||
<InlineLink to="/stp">STP</InlineLink> for the prefered but less
|
||||
professional experience.
|
||||
</Paragraph>
|
||||
</section>
|
||||
|
||||
<nav class="navRow flex flex-row flex-wrap gap-4 justify-around">
|
||||
<Link to="/cv"> CV </Link>
|
||||
<Link to="/stp"> STP </Link>
|
||||
<Link v-for="p in projects" :key="p.name" :href="p.href">
|
||||
{{ p.name }}
|
||||
</Link>
|
||||
<Link href="mailto:[email protected]"> Email </Link>
|
||||
<Link v-for="link in links" :key="link.name" :href="link.href">
|
||||
{{ link.name }}
|
||||
</Link>
|
||||
</nav>
|
||||
<nav class="navRow flex flex-row flex-wrap gap-4 justify-around">
|
||||
<Link to="/cv"> CV </Link>
|
||||
<Link to="/stp"> STP </Link>
|
||||
<Link to="/shrines"> Shrines </Link>
|
||||
<Link v-for="p in projects" :key="p.name" :href="p.href">
|
||||
{{ p.name }}
|
||||
</Link>
|
||||
<Link href="mailto:[email protected]"> Email </Link>
|
||||
<Link v-for="link in links" :key="link.name" :href="link.href">
|
||||
{{ link.name }}
|
||||
</Link>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<BoxCanvas page="index" overlay @height="overlayHeight = $event" />
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user