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]>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package graph
|
|
|
|
// Hand-written helpers for box.resolvers.go. Kept out of that file because
|
|
// gqlgen moves unknown code in a resolvers file to the end, under a warning
|
|
// comment, on every regenerate.
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"adam-french.co.uk/backend/models"
|
|
)
|
|
|
|
// minBoxSize stops a box being resized to nothing, after which it could not
|
|
// be grabbed again on the canvas.
|
|
const minBoxSize = 40
|
|
|
|
func setInt(dst *int, src *int) {
|
|
if src != nil {
|
|
*dst = *src
|
|
}
|
|
}
|
|
|
|
// validateBox checks the fields a box needs to render and clamps geometry
|
|
// rather than rejecting it, because a drag that overshoots the canvas edge
|
|
// should land at the edge, not fail.
|
|
func validateBox(box *models.Box) error {
|
|
if !validPageKey(box.Page) {
|
|
return errors.New("a box needs a valid page")
|
|
}
|
|
switch box.Kind {
|
|
case "widget":
|
|
if box.Widget == nil || *box.Widget == "" {
|
|
return errors.New("a widget box needs a widget name")
|
|
}
|
|
case "html":
|
|
if box.HTML == nil {
|
|
return errors.New("an html box needs html")
|
|
}
|
|
default:
|
|
return errors.New(`box kind must be "widget" or "html"`)
|
|
}
|
|
box.X = max(box.X, 0)
|
|
box.Y = max(box.Y, 0)
|
|
box.W = max(box.W, minBoxSize)
|
|
box.H = max(box.H, minBoxSize)
|
|
return nil
|
|
}
|