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:
@@ -73,7 +73,7 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi.
|
|||||||
- `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout)
|
- `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout)
|
||||||
- `graph/generated.go` — auto-generated by gqlgen, do not edit
|
- `graph/generated.go` — auto-generated by gqlgen, do not edit
|
||||||
- `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit
|
- `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit
|
||||||
- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box)
|
- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page)
|
||||||
- `graph/directives.go` — the `@admin` / `@signedIn` schema directives (see Key Patterns)
|
- `graph/directives.go` — the `@admin` / `@signedIn` schema directives (see Key Patterns)
|
||||||
- `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, the Python-service call helper (`python_call.go`), the `.env` registry (`env_manager.go`), DB seeding. There is no Claude client in Go any more
|
- `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, the Python-service call helper (`python_call.go`), the `.env` registry (`env_manager.go`), DB seeding. There is no Claude client in Go any more
|
||||||
|
|
||||||
@@ -81,8 +81,8 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi.
|
|||||||
|
|
||||||
- `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`)
|
- `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`)
|
||||||
- `src/api.js` — thin REST client for the `/api` JSON endpoints; failures become an `ApiError` carrying the backend's `error` message and the status
|
- `src/api.js` — thin REST client for the `/api` JSON endpoints; failures become an `ApiError` carrying the backend's `error` message and the status
|
||||||
- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes. `createCrudStore.js` is the factory behind places and boxes; `createMirrorStore.js` is the one behind the home-page slices
|
- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages. `createCrudStore.js` is the factory behind places, boxes and pages; `createMirrorStore.js` is the one behind the home-page slices
|
||||||
- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). `/stp` is `views/home3/Home3.vue`: a canvas of admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type. See "The /stp canvas" in `vue/README.md`
|
- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). `/stp` is `views/home3/Home3.vue`: a canvas of admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type. The canvas (`views/home3/BoxCanvas.vue`) is reusable per page key: the landing page overlays one for notes, and admin-created `Page`s (e.g. shrines) are served at `/<slug>` by the router's catch-all, `views/canvas/CanvasPage.vue`. Boxes and pages can be admin-only, filtered server-side. See "The /stp canvas" in `vue/README.md`
|
||||||
- `src/components/` — reusable UI components
|
- `src/components/` — reusable UI components
|
||||||
- `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`.
|
- `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`.
|
||||||
|
|
||||||
|
|||||||
@@ -82,3 +82,9 @@ models:
|
|||||||
fields:
|
fields:
|
||||||
deletedAt:
|
deletedAt:
|
||||||
resolver: false
|
resolver: false
|
||||||
|
Page:
|
||||||
|
model:
|
||||||
|
- adam-french.co.uk/backend/models.Page
|
||||||
|
fields:
|
||||||
|
deletedAt:
|
||||||
|
resolver: false
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI
|
|||||||
// comment on models.Box.Framed. Sizes not supplied fall back to the
|
// comment on models.Box.Framed. Sizes not supplied fall back to the
|
||||||
// same 300x200 the column defaults use.
|
// same 300x200 the column defaults use.
|
||||||
box := models.Box{
|
box := models.Box{
|
||||||
|
Page: input.Page,
|
||||||
Kind: input.Kind,
|
Kind: input.Kind,
|
||||||
Widget: input.Widget,
|
Widget: input.Widget,
|
||||||
HTML: input.HTML,
|
HTML: input.HTML,
|
||||||
@@ -37,6 +38,9 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI
|
|||||||
if input.HideOnMobile != nil {
|
if input.HideOnMobile != nil {
|
||||||
box.HideOnMobile = *input.HideOnMobile
|
box.HideOnMobile = *input.HideOnMobile
|
||||||
}
|
}
|
||||||
|
if input.AdminOnly != nil {
|
||||||
|
box.AdminOnly = *input.AdminOnly
|
||||||
|
}
|
||||||
if err := validateBox(&box); err != nil {
|
if err := validateBox(&box); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -76,6 +80,9 @@ func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.Up
|
|||||||
if input.HideOnMobile != nil {
|
if input.HideOnMobile != nil {
|
||||||
box.HideOnMobile = *input.HideOnMobile
|
box.HideOnMobile = *input.HideOnMobile
|
||||||
}
|
}
|
||||||
|
if input.AdminOnly != nil {
|
||||||
|
box.AdminOnly = *input.AdminOnly
|
||||||
|
}
|
||||||
if err := validateBox(&box); err != nil {
|
if err := validateBox(&box); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -98,13 +105,27 @@ func (r *mutationResolver) DeleteBox(ctx context.Context, id int) (*models.Box,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Boxes is the resolver for the boxes field.
|
// Boxes is the resolver for the boxes field.
|
||||||
func (r *queryResolver) Boxes(ctx context.Context) ([]*models.Box, error) {
|
func (r *queryResolver) Boxes(ctx context.Context, page string) ([]*models.Box, error) {
|
||||||
// Public: this is the page layout every visitor loads. Ordered by z so
|
// Public: this is the page layout every visitor loads. Ordered by z so
|
||||||
// DOM order matches stacking order, which keeps tab order sensible.
|
// DOM order matches stacking order, which keeps tab order sensible.
|
||||||
|
//
|
||||||
|
// What is admin-only is filtered here rather than hidden in the browser,
|
||||||
|
// so a private note never reaches anyone else: an adminOnly page answers
|
||||||
|
// with no boxes at all, and adminOnly boxes are left out of the rest.
|
||||||
|
hidden, err := pageHiddenFrom(ctx, r.Store.DB, page)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if hidden {
|
||||||
|
return []*models.Box{}, nil
|
||||||
|
}
|
||||||
|
query := r.Store.DB.Where("page = ?", page)
|
||||||
|
if !IsAdminFromCtx(ctx) {
|
||||||
|
query = query.Where("admin_only = ?", false)
|
||||||
|
}
|
||||||
var boxes []models.Box
|
var boxes []models.Box
|
||||||
if err := r.Store.DB.Order("z ASC, id ASC").Find(&boxes).Error; err != nil {
|
if err := query.Order("z ASC, id ASC").Find(&boxes).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ptrs(boxes), nil
|
return ptrs(boxes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ func setInt(dst *int, src *int) {
|
|||||||
// rather than rejecting it, because a drag that overshoots the canvas edge
|
// rather than rejecting it, because a drag that overshoots the canvas edge
|
||||||
// should land at the edge, not fail.
|
// should land at the edge, not fail.
|
||||||
func validateBox(box *models.Box) error {
|
func validateBox(box *models.Box) error {
|
||||||
|
if !validPageKey(box.Page) {
|
||||||
|
return errors.New("a box needs a valid page")
|
||||||
|
}
|
||||||
switch box.Kind {
|
switch box.Kind {
|
||||||
case "widget":
|
case "widget":
|
||||||
if box.Widget == nil || *box.Widget == "" {
|
if box.Widget == nil || *box.Widget == "" {
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ func TestValidateBox(t *testing.T) {
|
|||||||
box models.Box
|
box models.Box
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"widget with a name", models.Box{Kind: "widget", Widget: str("Chat")}, false},
|
{"widget with a name", models.Box{Page: "stp", Kind: "widget", Widget: str("Chat")}, false},
|
||||||
{"widget without a name", models.Box{Kind: "widget"}, true},
|
{"widget without a name", models.Box{Page: "stp", Kind: "widget"}, true},
|
||||||
{"widget with an empty name", models.Box{Kind: "widget", Widget: str("")}, true},
|
{"widget with an empty name", models.Box{Page: "stp", Kind: "widget", Widget: str("")}, true},
|
||||||
{"html with html", models.Box{Kind: "html", HTML: str("<p>hi</p>")}, false},
|
{"html with html", models.Box{Page: "stp", Kind: "html", HTML: str("<p>hi</p>")}, false},
|
||||||
{"html with empty html", models.Box{Kind: "html", HTML: str("")}, false},
|
{"html with empty html", models.Box{Page: "stp", Kind: "html", HTML: str("")}, false},
|
||||||
{"html without html", models.Box{Kind: "html"}, true},
|
{"html without html", models.Box{Page: "stp", Kind: "html"}, true},
|
||||||
{"unknown kind", models.Box{Kind: "iframe", HTML: str("x")}, true},
|
{"no page", models.Box{Kind: "widget", Widget: str("Chat")}, true},
|
||||||
|
{"bad page", models.Box{Page: "Shrines/GTO", Kind: "widget", Widget: str("Chat")}, true},
|
||||||
|
{"unknown kind", models.Box{Page: "stp", Kind: "iframe", HTML: str("x")}, true},
|
||||||
} {
|
} {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
err := validateBox(&c.box)
|
err := validateBox(&c.box)
|
||||||
@@ -32,7 +34,7 @@ func TestValidateBox(t *testing.T) {
|
|||||||
|
|
||||||
// Geometry is clamped, not rejected: a drag past the canvas edge lands
|
// Geometry is clamped, not rejected: a drag past the canvas edge lands
|
||||||
// at the edge, and a box can never shrink below a grabbable size.
|
// at the edge, and a box can never shrink below a grabbable size.
|
||||||
box := models.Box{Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0}
|
box := models.Box{Page: "stp", Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0}
|
||||||
if err := validateBox(&box); err != nil {
|
if err := validateBox(&box); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+969
-8
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,7 @@ type CreateBookmarkInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CreateBoxInput struct {
|
type CreateBoxInput struct {
|
||||||
|
Page string `json:"page"`
|
||||||
Kind string `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
Widget *string `json:"widget,omitempty"`
|
Widget *string `json:"widget,omitempty"`
|
||||||
HTML *string `json:"html,omitempty"`
|
HTML *string `json:"html,omitempty"`
|
||||||
@@ -36,6 +37,7 @@ type CreateBoxInput struct {
|
|||||||
Z *int `json:"z,omitempty"`
|
Z *int `json:"z,omitempty"`
|
||||||
Framed *bool `json:"framed,omitempty"`
|
Framed *bool `json:"framed,omitempty"`
|
||||||
HideOnMobile *bool `json:"hideOnMobile,omitempty"`
|
HideOnMobile *bool `json:"hideOnMobile,omitempty"`
|
||||||
|
AdminOnly *bool `json:"adminOnly,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateFavoriteInput struct {
|
type CreateFavoriteInput struct {
|
||||||
@@ -44,6 +46,12 @@ type CreateFavoriteInput struct {
|
|||||||
Link *string `json:"link,omitempty"`
|
Link *string `json:"link,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreatePageInput struct {
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
AdminOnly *bool `json:"adminOnly,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreatePlaceInput struct {
|
type CreatePlaceInput struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Location *string `json:"location,omitempty"`
|
Location *string `json:"location,omitempty"`
|
||||||
@@ -138,6 +146,13 @@ type UpdateBoxInput struct {
|
|||||||
Z *int `json:"z,omitempty"`
|
Z *int `json:"z,omitempty"`
|
||||||
Framed *bool `json:"framed,omitempty"`
|
Framed *bool `json:"framed,omitempty"`
|
||||||
HideOnMobile *bool `json:"hideOnMobile,omitempty"`
|
HideOnMobile *bool `json:"hideOnMobile,omitempty"`
|
||||||
|
AdminOnly *bool `json:"adminOnly,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdatePageInput struct {
|
||||||
|
Slug *string `json:"slug,omitempty"`
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
AdminOnly *bool `json:"adminOnly,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdatePlaceInput struct {
|
type UpdatePlaceInput struct {
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
// This file will be automatically regenerated based on the schema, any resolver
|
||||||
|
// implementations
|
||||||
|
// will be copied through when generating and any unknown code will be moved to the end.
|
||||||
|
// Code generated by github.com/99designs/gqlgen version v0.17.95
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"adam-french.co.uk/backend/graph/model"
|
||||||
|
"adam-french.co.uk/backend/models"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreatePage is the resolver for the createPage field.
|
||||||
|
func (r *mutationResolver) CreatePage(ctx context.Context, input model.CreatePageInput) (*models.Page, error) {
|
||||||
|
page := models.Page{
|
||||||
|
Slug: input.Slug,
|
||||||
|
Title: strings.TrimSpace(input.Title),
|
||||||
|
}
|
||||||
|
if input.AdminOnly != nil {
|
||||||
|
page.AdminOnly = *input.AdminOnly
|
||||||
|
}
|
||||||
|
if err := validateSlug(page.Slug); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if page.Title == "" {
|
||||||
|
return nil, errors.New("a page needs a title")
|
||||||
|
}
|
||||||
|
taken, err := slugTaken(r.Store.DB, page.Slug, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if taken {
|
||||||
|
return nil, errors.New("there is already a page at that address")
|
||||||
|
}
|
||||||
|
if err := r.Store.DB.Create(&page).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &page, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePage is the resolver for the updatePage field.
|
||||||
|
func (r *mutationResolver) UpdatePage(ctx context.Context, id int, input model.UpdatePageInput) (*models.Page, error) {
|
||||||
|
// Partial update, like updateBox. A new slug moves the page's boxes with
|
||||||
|
// it in the same transaction, since boxes find their page by slug.
|
||||||
|
var page models.Page
|
||||||
|
if err := r.Store.DB.First(&page, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
oldSlug := page.Slug
|
||||||
|
if input.Slug != nil {
|
||||||
|
page.Slug = *input.Slug
|
||||||
|
}
|
||||||
|
if input.Title != nil {
|
||||||
|
page.Title = strings.TrimSpace(*input.Title)
|
||||||
|
}
|
||||||
|
if input.AdminOnly != nil {
|
||||||
|
page.AdminOnly = *input.AdminOnly
|
||||||
|
}
|
||||||
|
if page.Title == "" {
|
||||||
|
return nil, errors.New("a page needs a title")
|
||||||
|
}
|
||||||
|
if page.Slug != oldSlug {
|
||||||
|
if err := validateSlug(page.Slug); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
taken, err := slugTaken(r.Store.DB, page.Slug, page.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if taken {
|
||||||
|
return nil, errors.New("there is already a page at that address")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := r.Store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
if page.Slug != oldSlug {
|
||||||
|
if err := tx.Model(&models.Box{}).Where("page = ?", oldSlug).Update("page", page.Slug).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tx.Save(&page).Error
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &page, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletePage is the resolver for the deletePage field.
|
||||||
|
func (r *mutationResolver) DeletePage(ctx context.Context, id int) (*models.Page, error) {
|
||||||
|
// The boxes go too: left behind, they would reappear on any page later
|
||||||
|
// created at the same address.
|
||||||
|
var page models.Page
|
||||||
|
if err := r.Store.DB.First(&page, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err := r.Store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
if err := tx.Where("page = ?", page.Slug).Delete(&models.Box{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return tx.Delete(&page).Error
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &page, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pages is the resolver for the pages field.
|
||||||
|
func (r *queryResolver) Pages(ctx context.Context) ([]*models.Page, error) {
|
||||||
|
// Public, for page indexes such as /shrines; adminOnly pages are only
|
||||||
|
// listed for an admin.
|
||||||
|
query := r.Store.DB.Order("slug ASC")
|
||||||
|
if !IsAdminFromCtx(ctx) {
|
||||||
|
query = query.Where("admin_only = ?", false)
|
||||||
|
}
|
||||||
|
var pages []models.Page
|
||||||
|
if err := query.Find(&pages).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ptrs(pages), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Page is the resolver for the page field.
|
||||||
|
func (r *queryResolver) Page(ctx context.Context, slug string) (*models.Page, error) {
|
||||||
|
// Null, not an error, for a missing page: the SPA's catch-all route asks
|
||||||
|
// this for every unknown path and shows its 404 on null. An adminOnly
|
||||||
|
// page reads as missing to everyone else, so its existence isn't leaked.
|
||||||
|
var page models.Page
|
||||||
|
err := r.Store.DB.Where("slug = ?", slug).First(&page).Error
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if page.AdminOnly && !IsAdminFromCtx(ctx) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &page, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
// Hand-written helpers for page.resolvers.go and box.resolvers.go, kept out
|
||||||
|
// of the resolver files for the same reason as box_helpers.go.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"adam-french.co.uk/backend/models"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// pageKeyPattern is the shape of a box's page key and of a page slug: lower
|
||||||
|
// case words joined by hyphens, in one or more /-separated segments. It is
|
||||||
|
// URL-safe as it stands, so the front end can use a slug as a path without
|
||||||
|
// escaping it.
|
||||||
|
var pageKeyPattern = regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*(/[a-z0-9]+(-[a-z0-9]+)*)*$`)
|
||||||
|
|
||||||
|
const maxSlugLen = 100
|
||||||
|
|
||||||
|
// reservedFirstSegments are paths a page could never be reached at, because
|
||||||
|
// nginx or one of the SPA's own routes answers them first (see
|
||||||
|
// nginx/nginx_routes.conf.template and vue/src/router/index.js), plus the
|
||||||
|
// built-in canvases' page keys, whose boxes a page of the same slug would
|
||||||
|
// share. "shrines" is deliberately absent: shrine pages live under it.
|
||||||
|
var reservedFirstSegments = map[string]bool{
|
||||||
|
"stp": true, "stp2": true, "index": true, "admin": true, "cv": true,
|
||||||
|
"automata": true, "hotels": true, "api": true, "py": true, "radio": true,
|
||||||
|
"gitea": true, "notes": true, "sb": true, "jobs": true, "tracker": true,
|
||||||
|
"usaco": true, "uploads": true, "img": true, "fonts": true, "pdf": true,
|
||||||
|
"sound": true, "assets": true, "internal": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// reservedSlugs are individual paths the SPA routes itself.
|
||||||
|
var reservedSlugs = map[string]bool{
|
||||||
|
"shrines": true,
|
||||||
|
"shrines/demoman": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func validPageKey(key string) bool {
|
||||||
|
return len(key) <= maxSlugLen && pageKeyPattern.MatchString(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateSlug reports why slug can't be a page's address, or nil.
|
||||||
|
func validateSlug(slug string) error {
|
||||||
|
if !validPageKey(slug) {
|
||||||
|
return errors.New("a page address is lower-case letters, digits and hyphens, in /-separated parts, e.g. shrines/evangelion")
|
||||||
|
}
|
||||||
|
first, _, _ := strings.Cut(slug, "/")
|
||||||
|
if reservedFirstSegments[first] || reservedSlugs[slug] {
|
||||||
|
return errors.New("that address is already used by the site")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pageHiddenFrom reports whether the page with this key is an adminOnly page
|
||||||
|
// and the caller is not an admin. A key with no Page row (a built-in canvas,
|
||||||
|
// or a page that doesn't exist) is not hidden.
|
||||||
|
func pageHiddenFrom(ctx context.Context, db *gorm.DB, key string) (bool, error) {
|
||||||
|
if IsAdminFromCtx(ctx) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
var count int64
|
||||||
|
err := db.Model(&models.Page{}).Where("slug = ? AND admin_only = ?", key, true).Count(&count).Error
|
||||||
|
return count > 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// slugTaken reports whether a live page other than exceptID has this slug.
|
||||||
|
// Checked up front so the admin gets a sentence rather than a constraint
|
||||||
|
// violation; the partial unique index still backs it up.
|
||||||
|
func slugTaken(db *gorm.DB, slug string, exceptID uint) (bool, error) {
|
||||||
|
var count int64
|
||||||
|
err := db.Model(&models.Page{}).Where("slug = ? AND id <> ?", slug, exceptID).Count(&count).Error
|
||||||
|
return count > 0, err
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestValidateSlug(t *testing.T) {
|
||||||
|
for _, c := range []struct {
|
||||||
|
slug string
|
||||||
|
ok bool
|
||||||
|
}{
|
||||||
|
{"notes-to-self", true},
|
||||||
|
{"shrines/evangelion", true},
|
||||||
|
{"shrines/neon-genesis/rei2", true},
|
||||||
|
{"", false},
|
||||||
|
{"Shrines/GTO", false}, // upper case
|
||||||
|
{"shrines/", false}, // empty segment
|
||||||
|
{"/shrines/gto", false}, // leading slash
|
||||||
|
{"shrines//gto", false}, // empty segment
|
||||||
|
{"shrines/gto-", false}, // trailing hyphen
|
||||||
|
{"shrines/../admin", false}, // dots
|
||||||
|
{"shrines", false}, // the SPA's own index
|
||||||
|
{"shrines/demoman", false}, // an existing SPA route
|
||||||
|
{"admin/pages", false}, // under an SPA route
|
||||||
|
{"jobs/x", false}, // under an nginx route
|
||||||
|
{"stp", false}, // a built-in canvas's key
|
||||||
|
{"index", false}, // likewise
|
||||||
|
{"stp-fan-page", true}, // only whole segments are reserved
|
||||||
|
} {
|
||||||
|
err := validateSlug(c.slug)
|
||||||
|
if (err == nil) != c.ok {
|
||||||
|
t.Errorf("validateSlug(%q) = %v, want ok=%v", c.slug, err, c.ok)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
# Boxes on the home page canvas (/stp). Anyone may read the layout — it is
|
# Boxes on a canvas page: the home page (/stp, page "stp"), the landing
|
||||||
# the page — but only an admin may change it. x/y/w/h are px on a fixed
|
# page's overlay (page "index") or an admin-created Page (page = its slug).
|
||||||
# 1400px-wide design canvas; see models.Box.
|
# Anyone may read a page's layout — it is the page — but only an admin may
|
||||||
|
# change it, and adminOnly boxes are only ever returned to an admin. x/y/w/h
|
||||||
|
# are px on a fixed 1400px-wide design canvas; see models.Box.
|
||||||
#
|
#
|
||||||
# kind is "widget" (a built-in Vue component named by `widget`) or "html"
|
# kind is "widget" (a built-in Vue component named by `widget`) or "html"
|
||||||
# (`html` rendered in a sandboxed iframe on the front end).
|
# (`html` rendered in a sandboxed iframe on the front end).
|
||||||
@@ -9,6 +11,7 @@ type Box {
|
|||||||
id: ID!
|
id: ID!
|
||||||
createdAt: Time!
|
createdAt: Time!
|
||||||
updatedAt: Time!
|
updatedAt: Time!
|
||||||
|
page: String!
|
||||||
kind: String!
|
kind: String!
|
||||||
widget: String
|
widget: String
|
||||||
html: String
|
html: String
|
||||||
@@ -20,9 +23,11 @@ type Box {
|
|||||||
z: Int!
|
z: Int!
|
||||||
framed: Boolean!
|
framed: Boolean!
|
||||||
hideOnMobile: Boolean!
|
hideOnMobile: Boolean!
|
||||||
|
adminOnly: Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
input CreateBoxInput {
|
input CreateBoxInput {
|
||||||
|
page: String!
|
||||||
kind: String!
|
kind: String!
|
||||||
widget: String
|
widget: String
|
||||||
html: String
|
html: String
|
||||||
@@ -34,6 +39,7 @@ input CreateBoxInput {
|
|||||||
z: Int
|
z: Int
|
||||||
framed: Boolean
|
framed: Boolean
|
||||||
hideOnMobile: Boolean
|
hideOnMobile: Boolean
|
||||||
|
adminOnly: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
input UpdateBoxInput {
|
input UpdateBoxInput {
|
||||||
@@ -47,10 +53,11 @@ input UpdateBoxInput {
|
|||||||
z: Int
|
z: Int
|
||||||
framed: Boolean
|
framed: Boolean
|
||||||
hideOnMobile: Boolean
|
hideOnMobile: Boolean
|
||||||
|
adminOnly: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
extend type Query {
|
extend type Query {
|
||||||
boxes: [Box!]!
|
boxes(page: String!): [Box!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
extend type Mutation {
|
extend type Mutation {
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Admin-created canvas pages. A page is just a slug and a title; its content
|
||||||
|
# is the boxes whose `page` is the slug (see box.graphql). The SPA serves it
|
||||||
|
# at /<slug> through its catch-all route, so a slug may not start with a path
|
||||||
|
# the site already uses — see validateSlug in page_helpers.go.
|
||||||
|
#
|
||||||
|
# adminOnly pages, and their boxes, are invisible to everyone but an admin:
|
||||||
|
# `page` answers null and `pages` leaves them out.
|
||||||
|
|
||||||
|
type Page {
|
||||||
|
id: ID!
|
||||||
|
createdAt: Time!
|
||||||
|
updatedAt: Time!
|
||||||
|
slug: String!
|
||||||
|
title: String!
|
||||||
|
adminOnly: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
|
input CreatePageInput {
|
||||||
|
slug: String!
|
||||||
|
title: String!
|
||||||
|
adminOnly: Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
input UpdatePageInput {
|
||||||
|
slug: String
|
||||||
|
title: String
|
||||||
|
adminOnly: Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
extend type Query {
|
||||||
|
pages: [Page!]!
|
||||||
|
page(slug: String!): Page
|
||||||
|
}
|
||||||
|
|
||||||
|
extend type Mutation {
|
||||||
|
createPage(input: CreatePageInput!): Page! @admin
|
||||||
|
# Renaming a page moves its boxes with it.
|
||||||
|
updatePage(id: ID!, input: UpdatePageInput!): Page! @admin
|
||||||
|
# Deletes the page's boxes too.
|
||||||
|
deletePage(id: ID!): Page! @admin
|
||||||
|
}
|
||||||
@@ -156,10 +156,12 @@ type Place struct {
|
|||||||
Done bool `gorm:"default:false" json:"done"`
|
Done bool `gorm:"default:false" json:"done"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Box is one panel on the home page canvas (/stp). Its position and size are
|
// Box is one panel on a canvas page. Page names the canvas it belongs to:
|
||||||
// in px on a fixed 1400px-wide design canvas, which the page scales down on
|
// "stp" for the home page, "index" for the landing page's overlay, or a
|
||||||
// narrower screens — so the stored numbers mean the same thing for every
|
// Page.Slug for an admin-created page — it is a key, not a foreign key, so the
|
||||||
// visitor. Kind "widget" renders a built-in Vue component named by Widget;
|
// built-in canvases need no Page row. Its position and size are in px on a
|
||||||
|
// fixed 1400px-wide design canvas, which the page scales down on narrower
|
||||||
|
// screens — so the stored numbers mean the same thing for every visitor. Kind "widget" renders a built-in Vue component named by Widget;
|
||||||
// kind "html" renders HTML in a sandboxed iframe on the front end, which is
|
// kind "html" renders HTML in a sandboxed iframe on the front end, which is
|
||||||
// what makes storing admin-authored script here acceptable.
|
// what makes storing admin-authored script here acceptable.
|
||||||
type Box struct {
|
type Box struct {
|
||||||
@@ -167,6 +169,8 @@ type Box struct {
|
|||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
|
||||||
|
// default:stp is what the boxes that predate pages are migrated to.
|
||||||
|
Page string `gorm:"not null;default:stp;index" json:"page"`
|
||||||
Kind string `gorm:"not null" json:"kind"`
|
Kind string `gorm:"not null" json:"kind"`
|
||||||
Widget *string `json:"widget"`
|
Widget *string `json:"widget"`
|
||||||
HTML *string `json:"html"`
|
HTML *string `json:"html"`
|
||||||
@@ -181,4 +185,23 @@ type Box struct {
|
|||||||
// CreateBox applies the true default itself.
|
// CreateBox applies the true default itself.
|
||||||
Framed bool `gorm:"not null" json:"framed"`
|
Framed bool `gorm:"not null" json:"framed"`
|
||||||
HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"`
|
HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"`
|
||||||
|
// AdminOnly boxes are never sent to anyone but an admin (the boxes
|
||||||
|
// resolver filters them out), so they suit private notes.
|
||||||
|
AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Page is an admin-created canvas page, served by the SPA's catch-all route
|
||||||
|
// at /<Slug> (e.g. "shrines/evangelion"). Its content is the Boxes whose Page
|
||||||
|
// equals Slug. The unique index is partial so that a deleted page's slug can
|
||||||
|
// be reused — a plain uniqueIndex would still collide with the soft-deleted
|
||||||
|
// row.
|
||||||
|
type Page struct {
|
||||||
|
ID uint `gorm:"primarykey" json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
|
||||||
|
Slug string `gorm:"not null;index:idx_pages_slug,unique,where:deleted_at IS NULL" json:"slug"`
|
||||||
|
Title string `gorm:"not null" json:"title"`
|
||||||
|
// AdminOnly hides the whole page, boxes included, from everyone else.
|
||||||
|
AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func migrateDatabase(db *gorm.DB) error {
|
|||||||
&models.Bookmark{},
|
&models.Bookmark{},
|
||||||
&models.Place{},
|
&models.Place{},
|
||||||
&models.Box{},
|
&models.Box{},
|
||||||
|
&models.Page{},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+35
-10
@@ -65,13 +65,13 @@ Two layout shells, defined in `src/router/index.js`:
|
|||||||
|
|
||||||
| Path | Layout | Notes |
|
| Path | Layout | Notes |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint) |
|
| `/` | 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) |
|
| `/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` |
|
| `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` |
|
||||||
| `/automata`, `/hotels`, `/shrines/*` | DefaultLayout | |
|
| `/automata`, `/hotels`, `/shrines`, `/shrines/demoman` | DefaultLayout | Every other shrine 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 |
|
| `/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 |
|
| `/stp2` | (none) | Bare full-bleed mock, deliberately outside both layouts |
|
||||||
| `:pathMatch(.*)*` | DefaultLayout | 404 |
|
| `: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) |
|
||||||
|
|
||||||
Everything except the landing page is a dynamic `import()`, so Vite gives each
|
Everything except the landing page is a dynamic `import()`, so Vite gives each
|
||||||
view its own chunk.
|
view its own chunk.
|
||||||
@@ -169,7 +169,8 @@ true only once a fetch has succeeded, meaning the data is real. Waiting on
|
|||||||
| `auth` | current user (`ensureLoaded()`, see Routing), plus login/logout mutations |
|
| `auth` | current user (`ensureLoaded()`, see Routing), plus login/logout mutations |
|
||||||
| `posts`, `favorites`, `activity`, `songs`, `steam` | mirror one slice of `homeData` via an `immediate` watch, and keep a placeholder value until real data arrives |
|
| `posts`, `favorites`, `activity`, `songs`, `steam` | mirror one slice of `homeData` via an `immediate` watch, and keep a placeholder value until real data arrives |
|
||||||
| `places` | CRUD via `createCrudStore`; sign-in only, so it is fetched lazily |
|
| `places` | CRUD via `createCrudStore`; sign-in only, so it is fetched lazily |
|
||||||
| `boxes` | CRUD via `createCrudStore`; the `/stp` canvas layout. Public read, admin write |
|
| `boxes` | CRUD via `createCrudStore`, one store per canvas page: `useBoxesStore(page)`. Public read (admin-only boxes excepted), admin write |
|
||||||
|
| `pages` | CRUD via `createCrudStore`; the admin-created canvas pages. Public read (admin-only pages excepted), admin write |
|
||||||
| `messages` | the chat WebSocket — not GraphQL at all |
|
| `messages` | the chat WebSocket — not GraphQL at all |
|
||||||
| `models` | dormant; not imported anywhere |
|
| `models` | dormant; not imported anywhere |
|
||||||
|
|
||||||
@@ -188,7 +189,9 @@ Two factories keep the repeated shapes in one place:
|
|||||||
differences between types: `itemsKey` (the name the array is
|
differences between types: `itemsKey` (the name the array is
|
||||||
exposed under), `insert` (`"prepend"` or `"append"`), `deleteReturns`
|
exposed under), `insert` (`"prepend"` or `"append"`), `deleteReturns`
|
||||||
(`"object"` for `deletePlace`, `"boolean"` for a delete that returns a
|
(`"object"` for `deletePlace`, `"boolean"` for a delete that returns a
|
||||||
scalar — a scalar must not be given a selection set) and `extend` for extra actions.
|
scalar — a scalar must not be given a selection set), `args` (fixed
|
||||||
|
arguments for the list query, e.g. the boxes store's `page`) and `extend`
|
||||||
|
for extra actions.
|
||||||
|
|
||||||
The error contract is deliberate: `fetch()` never throws and records the
|
The error contract is deliberate: `fetch()` never throws and records the
|
||||||
failure on `error`; the mutations throw, so the form that called them can
|
failure on `error`; the mutations throw, so the form that called them can
|
||||||
@@ -198,10 +201,29 @@ Two factories keep the repeated shapes in one place:
|
|||||||
|
|
||||||
`/stp` is a set of **boxes** (`Box` in GraphQL, `stores/boxes.js`) that an admin
|
`/stp` is a set of **boxes** (`Box` in GraphQL, `stores/boxes.js`) that an admin
|
||||||
creates, drags, resizes and edits in the browser. Changes save to the database,
|
creates, drags, resizes and edits in the browser. Changes save to the database,
|
||||||
so every visitor sees the saved layout. All of it lives in `views/home3/`:
|
so every visitor sees the saved layout. The canvas is `views/home3/BoxCanvas.vue`,
|
||||||
|
and it is not only `/stp`: every box has a `page` key, and the same component
|
||||||
|
renders any page's boxes.
|
||||||
|
|
||||||
|
- **Pages.** `"stp"` is `/stp` (`Home3.vue`). `"index"` is the landing page,
|
||||||
|
where the canvas is an `overlay` over the page's own content: it takes no
|
||||||
|
room when empty, lets clicks through except on boxes, and reports its height
|
||||||
|
so the page grows to fit. 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
|
||||||
|
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
|
||||||
|
adding a route.
|
||||||
|
- **Admin only.** A box or a page can be marked admin-only. The server never
|
||||||
|
sends those to anyone else, so they are fit for private notes; admins see
|
||||||
|
such boxes outlined, with a 🔒 in edit mode. The "Note" template starts
|
||||||
|
admin-only.
|
||||||
- **Coordinates.** `x`/`y`/`w`/`h` are px on a fixed 1400px-wide design canvas.
|
- **Coordinates.** `x`/`y`/`w`/`h` are px on a fixed 1400px-wide design canvas.
|
||||||
`Home3.vue` draws the canvas at that width and shrinks it with
|
`BoxCanvas.vue` draws the canvas at that width and shrinks it with
|
||||||
`transform: scale()` to fit the window, so the arrangement is identical at
|
`transform: scale()` to fit the window, so the arrangement is identical at
|
||||||
every desktop width. `BoxFrame.vue` divides pointer deltas by that scale.
|
every desktop width. `BoxFrame.vue` divides pointer deltas by that scale.
|
||||||
`z` is the CSS z-index.
|
`z` is the CSS z-index.
|
||||||
@@ -221,9 +243,11 @@ so every visitor sees the saved layout. All of it lives in `views/home3/`:
|
|||||||
saves on pointer release, and the box is moved locally first and put back if
|
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;
|
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.
|
||||||
CodeMirror is loaded only when that panel opens. Starter HTML is in
|
CodeMirror is loaded only when that panel opens. "Insert upload" stores a
|
||||||
`templates.js`. "Import current layout" (shown only on an empty canvas)
|
file through the chat's public upload endpoint and puts an `<img>`/`<video>`
|
||||||
recreates the old `Home.vue` grid from `defaultLayout.js`.
|
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
|
||||||
|
`Home.vue` grid from `defaultLayout.js`.
|
||||||
- **Phones (≤700px)** get no canvas: boxes stack full-width in `(y, x)` order at
|
- **Phones (≤700px)** get no canvas: boxes stack full-width in `(y, x)` order at
|
||||||
their saved height, skipping any with `hideOnMobile`. There is no separate
|
their saved height, skipping any with `hideOnMobile`. There is no separate
|
||||||
mobile layout. To change the order, move boxes on the desktop canvas.
|
mobile layout. To change the order, move boxes on the desktop canvas.
|
||||||
@@ -271,6 +295,7 @@ in its header comment; the summary:
|
|||||||
| File | Status |
|
| File | Status |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `views/home3/Home3.vue` | live (`/stp`) — the box canvas; its widget boxes use **Intro3** and **Gym2** |
|
| `views/home3/Home3.vue` | live (`/stp`) — the box canvas; its widget boxes use **Intro3** and **Gym2** |
|
||||||
|
| `views/home/shrines/{GTO,Evangelion,Skipskipbenben}.vue` | `<Wip />` placeholders, unrouted; those 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/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/Intro.vue` | superseded by `Intro2.vue`; not imported |
|
||||||
| `views/home/Gym.vue` | superseded by `Gym2.vue`; not imported |
|
| `views/home/Gym.vue` | superseded by `Gym2.vue`; not imported |
|
||||||
|
|||||||
+9
-18
@@ -5,6 +5,9 @@
|
|||||||
* theme) and holds most routes; `/cv` mounts CVLayout (light print theme).
|
* theme) and holds most routes; `/cv` mounts CVLayout (light print theme).
|
||||||
* `/stp2` is deliberately outside both — it is a bare full-bleed mock.
|
* `/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
|
* Only the landing page is statically imported; every other view is a dynamic
|
||||||
* import so Vite code-splits it into its own chunk.
|
* import so Vite code-splits it into its own chunk.
|
||||||
*
|
*
|
||||||
@@ -62,32 +65,20 @@ const router = createRouter({
|
|||||||
name: "shrine links",
|
name: "shrine links",
|
||||||
component: () => import("@/views/home/shrines/Shrines.vue"),
|
component: () => import("@/views/home/shrines/Shrines.vue"),
|
||||||
},
|
},
|
||||||
{
|
// The GTO, Evangelion and Skipskipbenben shrines were <Wip />
|
||||||
path: "shrines/gto",
|
// placeholders; they are canvas pages now, made from /shrines
|
||||||
name: "gto shrine",
|
// and served by the catch-all below.
|
||||||
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"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "shrines/demoman",
|
path: "shrines/demoman",
|
||||||
name: "demoman shrine",
|
name: "demoman shrine",
|
||||||
component: () => import("@/views/home/shrines/Demoman.vue"),
|
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(.*)*",
|
path: ":pathMatch(.*)*",
|
||||||
name: "404",
|
name: "404",
|
||||||
component: () => import("@/views/404/404.vue"),
|
component: () => import("@/views/canvas/CanvasPage.vue"),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
+27
-5
@@ -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().
|
* 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
|
* 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
|
* 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.
|
* 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)
|
* 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";
|
import { createCrudStore } from "@/stores/createCrudStore";
|
||||||
|
|
||||||
const BOX_FIELDS = `
|
const BOX_FIELDS = `
|
||||||
id
|
id
|
||||||
|
page
|
||||||
kind
|
kind
|
||||||
widget
|
widget
|
||||||
html
|
html
|
||||||
@@ -25,24 +32,32 @@ const BOX_FIELDS = `
|
|||||||
z
|
z
|
||||||
framed
|
framed
|
||||||
hideOnMobile
|
hideOnMobile
|
||||||
|
adminOnly
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// The fields a duplicate copies. kind and widget/html are what make it the
|
// 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.
|
// 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", {
|
const stores = new Map();
|
||||||
|
|
||||||
|
function defineFor(page) {
|
||||||
|
return createCrudStore(`boxes:${page}`, {
|
||||||
type: "Box",
|
type: "Box",
|
||||||
list: "boxes",
|
list: "boxes",
|
||||||
fields: BOX_FIELDS,
|
fields: BOX_FIELDS,
|
||||||
insert: "append",
|
insert: "append",
|
||||||
deleteReturns: "object",
|
deleteReturns: "object",
|
||||||
|
args: { page: { type: "String!", value: page } },
|
||||||
extend: ({ items, create, update }) => {
|
extend: ({ items, create, update }) => {
|
||||||
const topZ = () => Math.max(0, ...items.value.map((b) => b.z)) + 1;
|
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 bottomZ = () => Math.min(0, ...items.value.map((b) => b.z)) - 1;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
page,
|
||||||
topZ,
|
topZ,
|
||||||
|
// Every box this store creates belongs to its page.
|
||||||
|
create: (input) => create({ ...input, page }),
|
||||||
bringToFront: (box) => update(box.id, { z: topZ() }),
|
bringToFront: (box) => update(box.id, { z: topZ() }),
|
||||||
sendToBack: (box) => update(box.id, { z: bottomZ() }),
|
sendToBack: (box) => update(box.id, { z: bottomZ() }),
|
||||||
duplicate: (box) => {
|
duplicate: (box) => {
|
||||||
@@ -51,4 +66,11 @@ export const useBoxesStore = createCrudStore("boxes", {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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.
|
* one, so the mutation text differs; the schema has both kinds.
|
||||||
* @param {(ctx: object) => object} [options.extend] extra state/actions merged
|
* @param {(ctx: object) => object} [options.extend] extra state/actions merged
|
||||||
* into the store; receives the base members
|
* 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(
|
export function createCrudStore(
|
||||||
id,
|
id,
|
||||||
@@ -48,10 +52,20 @@ export function createCrudStore(
|
|||||||
insert = "prepend",
|
insert = "prepend",
|
||||||
deleteReturns = "object",
|
deleteReturns = "object",
|
||||||
extend,
|
extend,
|
||||||
|
args = {},
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const deleteSelection = deleteReturns === "object" ? "{ id }" : "";
|
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, () => {
|
return defineStore(id, () => {
|
||||||
const items = ref([]);
|
const items = ref([]);
|
||||||
const loaded = ref(false);
|
const loaded = ref(false);
|
||||||
@@ -62,7 +76,10 @@ export function createCrudStore(
|
|||||||
async function fetch() {
|
async function fetch() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
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] || [];
|
items.value = data[list] || [];
|
||||||
loaded.value = true;
|
loaded.value = true;
|
||||||
error.value = null;
|
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 CreateRowing from "./CreateRowing.vue";
|
||||||
import CreateBookmark from "./CreateBookmark.vue";
|
import CreateBookmark from "./CreateBookmark.vue";
|
||||||
import CreatePlace from "./CreatePlace.vue";
|
import CreatePlace from "./CreatePlace.vue";
|
||||||
|
import ManagePages from "./ManagePages.vue";
|
||||||
import ManageUsers from "./ManageUsers.vue";
|
import ManageUsers from "./ManageUsers.vue";
|
||||||
import ManageRadio from "./ManageRadio.vue";
|
import ManageRadio from "./ManageRadio.vue";
|
||||||
import Environment from "./Environment.vue";
|
import Environment from "./Environment.vue";
|
||||||
@@ -31,6 +32,7 @@ const sections = [
|
|||||||
{ id: "rowing", label: "Rowing", component: CreateRowing },
|
{ id: "rowing", label: "Rowing", component: CreateRowing },
|
||||||
{ id: "bookmark", label: "Bookmark", component: CreateBookmark },
|
{ id: "bookmark", label: "Bookmark", component: CreateBookmark },
|
||||||
{ id: "place", label: "Place / Thing To Do", component: CreatePlace },
|
{ id: "place", label: "Place / Thing To Do", component: CreatePlace },
|
||||||
|
{ id: "pages", label: "Pages", component: ManagePages },
|
||||||
{ id: "users", label: "Manage Users", component: ManageUsers },
|
{ id: "users", label: "Manage Users", component: ManageUsers },
|
||||||
{ id: "radio", label: "Manage Radio", component: ManageRadio },
|
{ id: "radio", label: "Manage Radio", component: ManageRadio },
|
||||||
{ id: "environment", label: "Environment", component: Environment },
|
{ 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>
|
<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";
|
import Wip from "@/components/util/Wip.vue";
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script setup>
|
<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";
|
import Wip from "@/components/util/Wip.vue";
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,14 +1,31 @@
|
|||||||
<script setup>
|
<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";
|
import RouterTable from "@/components/util/RouterTable.vue";
|
||||||
const shrine_links = [
|
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" },
|
{ name: "Demoman", link: "/shrines/demoman" },
|
||||||
{ name: "Evangelion", link: "/shrines/evangelion" },
|
...pages.pages
|
||||||
{ name: "GTO", link: "/shrines/gto" },
|
.filter((p) => p.slug.startsWith("shrines/"))
|
||||||
{ name: "Skipskipbenben", link: "/shrines/skipskipbenben" },
|
.map((p) => ({ name: p.adminOnly ? `${p.title} 🔒` : p.title, link: `/${p.slug}` })),
|
||||||
];
|
].sort((a, b) => a.name.localeCompare(b.name)),
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -17,6 +34,10 @@ const shrine_links = [
|
|||||||
class="page-a4 bdr-1 flex flex-col relative overflow-scroll gap-1"
|
class="page-a4 bdr-1 flex flex-col relative overflow-scroll gap-1"
|
||||||
>
|
>
|
||||||
<RouterTable :linkArr="shrine_links" />
|
<RouterTable :linkArr="shrine_links" />
|
||||||
|
<section v-if="isAdmin" class="mt-4">
|
||||||
|
<h3>New shrine</h3>
|
||||||
|
<PageForm prefix="shrines/" starter="shrine" />
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script setup>
|
<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";
|
import Wip from "@/components/util/Wip.vue";
|
||||||
</script>
|
</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
|
* `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
|
* store) and is saved only by Save or Ctrl/Cmd+S. Saving every keystroke
|
||||||
* would push half-written markup to every visitor.
|
* 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 { computed, ref, watch } from "vue";
|
||||||
import { useBoxesStore } from "@/stores/boxes";
|
import { useBoxesStore } from "@/stores/boxes";
|
||||||
|
import { api } from "@/api";
|
||||||
import CodeEditor from "./CodeEditor.vue";
|
import CodeEditor from "./CodeEditor.vue";
|
||||||
import { WIDGETS } from "./widgetRegistry";
|
import { WIDGETS } from "./widgetRegistry";
|
||||||
|
|
||||||
@@ -21,7 +28,11 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
const emit = defineEmits(["preview", "close", "error"]);
|
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 draftHtml = ref(props.box.html ?? "");
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
@@ -73,6 +84,33 @@ function saveNumber(field, event) {
|
|||||||
save({ [field]: value });
|
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() {
|
function close() {
|
||||||
if (dirty.value && !confirm("Discard unsaved HTML changes?")) return;
|
if (dirty.value && !confirm("Discard unsaved HTML changes?")) return;
|
||||||
emit("preview", null);
|
emit("preview", null);
|
||||||
@@ -120,7 +158,7 @@ defineExpose({ close });
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex gap-4">
|
<div class="flex flex-wrap gap-x-4 gap-y-1">
|
||||||
<label class="check">
|
<label class="check">
|
||||||
<input type="checkbox" :checked="box.framed" @change="save({ framed: $event.target.checked })" />
|
<input type="checkbox" :checked="box.framed" @change="save({ framed: $event.target.checked })" />
|
||||||
Frame
|
Frame
|
||||||
@@ -133,15 +171,35 @@ defineExpose({ close });
|
|||||||
/>
|
/>
|
||||||
Hide on mobile
|
Hide on mobile
|
||||||
</label>
|
</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>
|
</div>
|
||||||
|
|
||||||
<template v-if="box.kind === 'html'">
|
<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">
|
<footer class="flex items-center justify-between gap-2">
|
||||||
<small class="text-muted">
|
<small class="text-muted">
|
||||||
Runs sandboxed: scripts work, cookies and /api don't. fetch() only reaches
|
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.
|
||||||
</small>
|
</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">
|
<button type="button" class="save" :disabled="!dirty || saving" @click="saveHtml">
|
||||||
{{ saving ? "Saving…" : dirty ? "Save" : "Saved" }}
|
{{ saving ? "Saving…" : dirty ? "Save" : "Saved" }}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ function end() {
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="box"
|
class="box"
|
||||||
:class="{ framed: box.framed, editing, selected }"
|
:class="{ framed: box.framed, editing, selected, 'admin-only': box.adminOnly }"
|
||||||
:style="style"
|
:style="style"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
@@ -146,6 +146,12 @@ function end() {
|
|||||||
background-color: var(--color-surface);
|
background-color: var(--color-surface);
|
||||||
border: 2px solid var(--color-quaternary);
|
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 {
|
.overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -71,6 +71,17 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
onBeforeUnmount(() => view?.destroy());
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,288 +1,17 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* Route `/stp` — the home page as a free-form canvas of boxes the admin
|
* 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.
|
* 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
|
||||||
* Every box (stores/boxes.js, the `Box` GraphQL type) has a position, size and
|
* page's notes and the admin-created pages.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
import BoxCanvas from "./BoxCanvas.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 { defaultLayout } from "./defaultLayout";
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="home3" :class="{ 'with-editor': inEditMode && selected }">
|
<main class="home3">
|
||||||
<div v-if="canEdit" class="admin-bar">
|
<BoxCanvas page="stp" :starter="defaultLayout" starter-label="Import current layout" />
|
||||||
<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>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -293,78 +22,4 @@ function toggleEdit() {
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 10px 16px;
|
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>
|
</style>
|
||||||
|
|||||||
@@ -85,12 +85,72 @@ const imageHtml = (src) => `<style>
|
|||||||
const EMPTY = `<h3>New box</h3>
|
const EMPTY = `<h3>New box</h3>
|
||||||
<p>Edit me.</p>`;
|
<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 = [
|
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: "Clock", title: "Clock", html: CLOCK, size: [240, 120] },
|
||||||
{ label: "Weather", title: "Weather", html: WEATHER, size: [240, 170] },
|
{ 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] },
|
{ label: "Empty HTML", title: "HTML", html: EMPTY, size: [300, 200] },
|
||||||
];
|
];
|
||||||
|
|
||||||
export { imageHtml };
|
export { imageHtml, galleryHtml };
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* Route `/` — the professional front door. Deliberately plain: a short bio and a
|
* 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
|
* row of links out to the CV, the personal home page (/stp), the shrines, the
|
||||||
* run as their own containers, and social profiles.
|
* projects that run as their own containers, and social profiles.
|
||||||
* Statically imported by the router (it is the first paint).
|
* 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 Link from "@/components/text/Link.vue";
|
||||||
import InlineLink from "@/components/text/InlineLink.vue";
|
import InlineLink from "@/components/text/InlineLink.vue";
|
||||||
import Header from "@/components/text/Header.vue";
|
import Header from "@/components/text/Header.vue";
|
||||||
@@ -18,6 +23,15 @@ const projects = [
|
|||||||
{ name: "USACO", href: "/usaco/" },
|
{ 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 = [
|
const links = [
|
||||||
{ name: "GitHub", href: "https://github.com/SteveThePug" },
|
{ name: "GitHub", href: "https://github.com/SteveThePug" },
|
||||||
{ name: "Gitea", href: "/gitea/explore/repos" },
|
{ name: "Gitea", href: "/gitea/explore/repos" },
|
||||||
@@ -26,7 +40,8 @@ const links = [
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="flex justify-center px-4 py-16">
|
<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">
|
<div class="max-w-xl w-full flex flex-col gap-12">
|
||||||
<section>
|
<section>
|
||||||
<Header>Adam French</Header>
|
<Header>Adam French</Header>
|
||||||
@@ -52,6 +67,7 @@ const links = [
|
|||||||
<nav class="navRow flex flex-row flex-wrap gap-4 justify-around">
|
<nav class="navRow flex flex-row flex-wrap gap-4 justify-around">
|
||||||
<Link to="/cv"> CV </Link>
|
<Link to="/cv"> CV </Link>
|
||||||
<Link to="/stp"> STP </Link>
|
<Link to="/stp"> STP </Link>
|
||||||
|
<Link to="/shrines"> Shrines </Link>
|
||||||
<Link v-for="p in projects" :key="p.name" :href="p.href">
|
<Link v-for="p in projects" :key="p.name" :href="p.href">
|
||||||
{{ p.name }}
|
{{ p.name }}
|
||||||
</Link>
|
</Link>
|
||||||
@@ -61,6 +77,8 @@ const links = [
|
|||||||
</Link>
|
</Link>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<BoxCanvas page="index" overlay @height="overlayHeight = $event" />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user