Add a customisable shadow to canvas boxes
Test and deploy / test (push) Successful in 2m11s
Test and deploy / deploy (push) Successful in 1m21s
Weekly Maintenance / maintenance (push) Successful in 6m55s

A box can now cast a shadow, independent of its frame: ticking "Shadow" in
the box editor gives a hard offset shadow, and Hard/Soft/Glow presets or any
typed CSS box-shadow value customise it. The value is stored on Box and
Component and carried through duplicates, components and layouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 23:18:35 +01:00
co-authored by Claude Opus 5.5
parent e764078aaf
commit 8bf70c98e8
15 changed files with 243 additions and 19 deletions
+6
View File
@@ -36,6 +36,9 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI
if input.Framed != nil { if input.Framed != nil {
box.Framed = *input.Framed box.Framed = *input.Framed
} }
if input.Shadow != nil {
box.Shadow = *input.Shadow
}
if input.HideOnMobile != nil { if input.HideOnMobile != nil {
box.HideOnMobile = *input.HideOnMobile box.HideOnMobile = *input.HideOnMobile
} }
@@ -102,6 +105,9 @@ func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.Up
if input.Framed != nil { if input.Framed != nil {
box.Framed = *input.Framed box.Framed = *input.Framed
} }
if input.Shadow != nil {
box.Shadow = *input.Shadow
}
if input.HideOnMobile != nil { if input.HideOnMobile != nil {
box.HideOnMobile = *input.HideOnMobile box.HideOnMobile = *input.HideOnMobile
} }
+20
View File
@@ -6,6 +6,8 @@ package graph
import ( import (
"errors" "errors"
"fmt"
"strings"
"adam-french.co.uk/backend/models" "adam-french.co.uk/backend/models"
) )
@@ -14,6 +16,10 @@ import (
// be grabbed again on the canvas. // be grabbed again on the canvas.
const minBoxSize = 40 const minBoxSize = 40
// maxShadowLen bounds a box's shadow, which is a single CSS value: even a
// stack of a few comma-separated shadows is well under it.
const maxShadowLen = 200
func setInt(dst *int, src *int) { func setInt(dst *int, src *int) {
if src != nil { if src != nil {
*dst = *src *dst = *src
@@ -43,9 +49,23 @@ func validateBox(box *models.Box) error {
if box.ComponentID != nil && box.Kind != "html" { if box.ComponentID != nil && box.Kind != "html" {
return errors.New("only an html box can be linked to a component") return errors.New("only an html box can be linked to a component")
} }
if err := validateShadow(&box.Shadow); err != nil {
return err
}
box.X = max(box.X, 0) box.X = max(box.X, 0)
box.Y = max(box.Y, 0) box.Y = max(box.Y, 0)
box.W = max(box.W, minBoxSize) box.W = max(box.W, minBoxSize)
box.H = max(box.H, minBoxSize) box.H = max(box.H, minBoxSize)
return nil return nil
} }
// validateShadow trims a box-shadow value and bounds its length. The value is
// not parsed: the front end sets it through a style binding, so it can only
// ever be the one property, and an invalid value just draws no shadow.
func validateShadow(shadow *string) error {
*shadow = strings.TrimSpace(*shadow)
if len(*shadow) > maxShadowLen {
return fmt.Errorf("a shadow is at most %d characters", maxShadowLen)
}
return nil
}
+13 -1
View File
@@ -38,11 +38,17 @@ func (r *mutationResolver) CreateComponent(ctx context.Context, input model.Crea
if input.Framed != nil { if input.Framed != nil {
c.Framed = *input.Framed c.Framed = *input.Framed
} }
if input.Shadow != nil {
c.Shadow = *input.Shadow
}
if input.AdminOnly != nil { if input.AdminOnly != nil {
c.AdminOnly = *input.AdminOnly c.AdminOnly = *input.AdminOnly
} }
c.W = max(c.W, minBoxSize) c.W = max(c.W, minBoxSize)
c.H = max(c.H, minBoxSize) c.H = max(c.H, minBoxSize)
if err := validateShadow(&c.Shadow); err != nil {
return nil, err
}
if err := r.Store.DB.Create(&c).Error; err != nil { if err := r.Store.DB.Create(&c).Error; err != nil {
return nil, err return nil, err
} }
@@ -75,11 +81,17 @@ func (r *mutationResolver) UpdateComponent(ctx context.Context, id int, input mo
if input.Framed != nil { if input.Framed != nil {
c.Framed = *input.Framed c.Framed = *input.Framed
} }
if input.Shadow != nil {
c.Shadow = *input.Shadow
}
if input.AdminOnly != nil { if input.AdminOnly != nil {
c.AdminOnly = *input.AdminOnly c.AdminOnly = *input.AdminOnly
} }
c.W = max(c.W, minBoxSize) c.W = max(c.W, minBoxSize)
c.H = max(c.H, minBoxSize) c.H = max(c.H, minBoxSize)
if err := validateShadow(&c.Shadow); err != nil {
return nil, err
}
if err := r.Store.DB.Save(&c).Error; err != nil { if err := r.Store.DB.Save(&c).Error; err != nil {
return nil, err return nil, err
} }
@@ -128,7 +140,7 @@ func (r *mutationResolver) SaveBoxAsComponent(ctx context.Context, id int, name
} }
c := models.Component{ c := models.Component{
Name: name, Title: box.Title, HTML: *box.HTML, Name: name, Title: box.Title, HTML: *box.HTML,
W: box.W, H: box.H, Framed: box.Framed, AdminOnly: box.AdminOnly, W: box.W, H: box.H, Framed: box.Framed, Shadow: box.Shadow, AdminOnly: box.AdminOnly,
} }
err = r.Store.DB.Transaction(func(tx *gorm.DB) error { err = r.Store.DB.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&c).Error; err != nil { if err := tx.Create(&c).Error; err != nil {
+106 -4
View File
@@ -88,6 +88,7 @@ type ComplexityRoot struct {
ID func(childComplexity int) int ID func(childComplexity int) int
Kind func(childComplexity int) int Kind func(childComplexity int) int
Page func(childComplexity int) int Page func(childComplexity int) int
Shadow func(childComplexity int) int
Title func(childComplexity int) int Title func(childComplexity int) int
UpdatedAt func(childComplexity int) int UpdatedAt func(childComplexity int) int
W func(childComplexity int) int W func(childComplexity int) int
@@ -105,6 +106,7 @@ type ComplexityRoot struct {
HTML func(childComplexity int) int HTML func(childComplexity int) int
ID func(childComplexity int) int ID func(childComplexity int) int
Name func(childComplexity int) int Name func(childComplexity int) int
Shadow func(childComplexity int) int
Title func(childComplexity int) int Title func(childComplexity int) int
UpdatedAt func(childComplexity int) int UpdatedAt func(childComplexity int) int
Uses func(childComplexity int) int Uses func(childComplexity int) int
@@ -587,6 +589,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
} }
return e.ComplexityRoot.Box.Page(childComplexity), true return e.ComplexityRoot.Box.Page(childComplexity), true
case "Box.shadow":
if e.ComplexityRoot.Box.Shadow == nil {
break
}
return e.ComplexityRoot.Box.Shadow(childComplexity), true
case "Box.title": case "Box.title":
if e.ComplexityRoot.Box.Title == nil { if e.ComplexityRoot.Box.Title == nil {
break break
@@ -672,6 +680,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
} }
return e.ComplexityRoot.Component.Name(childComplexity), true return e.ComplexityRoot.Component.Name(childComplexity), true
case "Component.shadow":
if e.ComplexityRoot.Component.Shadow == nil {
break
}
return e.ComplexityRoot.Component.Shadow(childComplexity), true
case "Component.title": case "Component.title":
if e.ComplexityRoot.Component.Title == nil { if e.ComplexityRoot.Component.Title == nil {
break break
@@ -1966,6 +1980,8 @@ func (ec *executionContext) childFields_Box(ctx context.Context, field graphql.C
return ec.fieldContext_Box_z(ctx, field) return ec.fieldContext_Box_z(ctx, field)
case "framed": case "framed":
return ec.fieldContext_Box_framed(ctx, field) return ec.fieldContext_Box_framed(ctx, field)
case "shadow":
return ec.fieldContext_Box_shadow(ctx, field)
case "hideOnMobile": case "hideOnMobile":
return ec.fieldContext_Box_hideOnMobile(ctx, field) return ec.fieldContext_Box_hideOnMobile(ctx, field)
case "adminOnly": case "adminOnly":
@@ -1996,6 +2012,8 @@ func (ec *executionContext) childFields_Component(ctx context.Context, field gra
return ec.fieldContext_Component_h(ctx, field) return ec.fieldContext_Component_h(ctx, field)
case "framed": case "framed":
return ec.fieldContext_Component_framed(ctx, field) return ec.fieldContext_Component_framed(ctx, field)
case "shadow":
return ec.fieldContext_Component_shadow(ctx, field)
case "adminOnly": case "adminOnly":
return ec.fieldContext_Component_adminOnly(ctx, field) return ec.fieldContext_Component_adminOnly(ctx, field)
case "uses": case "uses":
@@ -3848,6 +3866,29 @@ func (ec *executionContext) fieldContext_Box_framed(_ context.Context, field gra
return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean does not have child fields")) return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean does not have child fields"))
} }
func (ec *executionContext) _Box_shadow(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return ec.fieldContext_Box_shadow(ctx, field)
},
func(ctx context.Context) (any, error) {
return obj.Shadow, nil
},
nil,
func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler {
return ec.marshalNString2string(ctx, selections, v)
},
true,
true,
)
}
func (ec *executionContext) fieldContext_Box_shadow(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type String does not have child fields"))
}
func (ec *executionContext) _Box_hideOnMobile(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { func (ec *executionContext) _Box_hideOnMobile(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) {
return graphql.ResolveField( return graphql.ResolveField(
ctx, ctx,
@@ -4124,6 +4165,29 @@ func (ec *executionContext) fieldContext_Component_framed(_ context.Context, fie
return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Boolean does not have child fields")) return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Boolean does not have child fields"))
} }
func (ec *executionContext) _Component_shadow(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return ec.fieldContext_Component_shadow(ctx, field)
},
func(ctx context.Context) (any, error) {
return obj.Shadow, nil
},
nil,
func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler {
return ec.marshalNString2string(ctx, selections, v)
},
true,
true,
)
}
func (ec *executionContext) fieldContext_Component_shadow(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type String does not have child fields"))
}
func (ec *executionContext) _Component_adminOnly(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { func (ec *executionContext) _Component_adminOnly(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) {
return graphql.ResolveField( return graphql.ResolveField(
ctx, ctx,
@@ -10128,7 +10192,7 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob
asMap[k] = v asMap[k] = v
} }
fieldsInOrder := [...]string{"page", "kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile", "adminOnly", "componentId"} fieldsInOrder := [...]string{"page", "kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "shadow", "hideOnMobile", "adminOnly", "componentId"}
for _, k := range fieldsInOrder { for _, k := range fieldsInOrder {
v, ok := asMap[k] v, ok := asMap[k]
if !ok { if !ok {
@@ -10212,6 +10276,13 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob
return it, err return it, err
} }
it.Framed = data it.Framed = data
case "shadow":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("shadow"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.Shadow = data
case "hideOnMobile": case "hideOnMobile":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile"))
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
@@ -10249,7 +10320,7 @@ func (ec *executionContext) unmarshalInputCreateComponentInput(ctx context.Conte
asMap[k] = v asMap[k] = v
} }
fieldsInOrder := [...]string{"name", "title", "html", "w", "h", "framed", "adminOnly"} fieldsInOrder := [...]string{"name", "title", "html", "w", "h", "framed", "shadow", "adminOnly"}
for _, k := range fieldsInOrder { for _, k := range fieldsInOrder {
v, ok := asMap[k] v, ok := asMap[k]
if !ok { if !ok {
@@ -10298,6 +10369,13 @@ func (ec *executionContext) unmarshalInputCreateComponentInput(ctx context.Conte
return it, err return it, err
} }
it.Framed = data it.Framed = data
case "shadow":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("shadow"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.Shadow = data
case "adminOnly": case "adminOnly":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly"))
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
@@ -10636,7 +10714,7 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob
asMap[k] = v asMap[k] = v
} }
fieldsInOrder := [...]string{"widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile", "adminOnly"} fieldsInOrder := [...]string{"widget", "html", "title", "x", "y", "w", "h", "z", "framed", "shadow", "hideOnMobile", "adminOnly"}
for _, k := range fieldsInOrder { for _, k := range fieldsInOrder {
v, ok := asMap[k] v, ok := asMap[k]
if !ok { if !ok {
@@ -10706,6 +10784,13 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob
return it, err return it, err
} }
it.Framed = data it.Framed = data
case "shadow":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("shadow"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.Shadow = data
case "hideOnMobile": case "hideOnMobile":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile"))
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
@@ -10736,7 +10821,7 @@ func (ec *executionContext) unmarshalInputUpdateComponentInput(ctx context.Conte
asMap[k] = v asMap[k] = v
} }
fieldsInOrder := [...]string{"name", "title", "html", "w", "h", "framed", "adminOnly"} fieldsInOrder := [...]string{"name", "title", "html", "w", "h", "framed", "shadow", "adminOnly"}
for _, k := range fieldsInOrder { for _, k := range fieldsInOrder {
v, ok := asMap[k] v, ok := asMap[k]
if !ok { if !ok {
@@ -10785,6 +10870,13 @@ func (ec *executionContext) unmarshalInputUpdateComponentInput(ctx context.Conte
return it, err return it, err
} }
it.Framed = data it.Framed = data
case "shadow":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("shadow"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.Shadow = data
case "adminOnly": case "adminOnly":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly"))
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
@@ -11304,6 +11396,11 @@ func (ec *executionContext) _Box(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
out.Invalids++ out.Invalids++
} }
case "shadow":
out.Values[i] = ec._Box_shadow(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "hideOnMobile": case "hideOnMobile":
out.Values[i] = ec._Box_hideOnMobile(ctx, field, obj) out.Values[i] = ec._Box_hideOnMobile(ctx, field, obj)
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
@@ -11397,6 +11494,11 @@ func (ec *executionContext) _Component(ctx context.Context, sel ast.SelectionSet
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1) atomic.AddUint32(&out.Invalids, 1)
} }
case "shadow":
out.Values[i] = ec._Component_shadow(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
}
case "adminOnly": case "adminOnly":
out.Values[i] = ec._Component_adminOnly(ctx, field, obj) out.Values[i] = ec._Component_adminOnly(ctx, field, obj)
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
+3 -2
View File
@@ -31,6 +31,7 @@ type layoutBox struct {
H int `json:"h"` H int `json:"h"`
Z int `json:"z"` Z int `json:"z"`
Framed bool `json:"framed"` Framed bool `json:"framed"`
Shadow string `json:"shadow,omitempty"`
HideOnMobile bool `json:"hideOnMobile"` HideOnMobile bool `json:"hideOnMobile"`
AdminOnly bool `json:"adminOnly"` AdminOnly bool `json:"adminOnly"`
// ComponentID is the component a linked box was linked to. HTML is // ComponentID is the component a linked box was linked to. HTML is
@@ -104,7 +105,7 @@ func snapshotPage(db *gorm.DB, page, name string) (layout models.Layout, empty b
stored[i] = layoutBox{ stored[i] = layoutBox{
Kind: b.Kind, Widget: b.Widget, HTML: b.HTML, Title: b.Title, Kind: b.Kind, Widget: b.Widget, HTML: b.HTML, Title: b.Title,
X: b.X, Y: b.Y, W: b.W, H: b.H, Z: b.Z, X: b.X, Y: b.Y, W: b.W, H: b.H, Z: b.Z,
Framed: b.Framed, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly, Framed: b.Framed, Shadow: b.Shadow, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly,
ComponentID: b.ComponentID, ComponentID: b.ComponentID,
} }
} }
@@ -217,7 +218,7 @@ func applyLayoutTo(tx *gorm.DB, layout *models.Layout, page string, replace bool
boxes[i] = models.Box{ boxes[i] = models.Box{
Page: page, Kind: b.Kind, Widget: b.Widget, HTML: b.HTML, Title: b.Title, Page: page, Kind: b.Kind, Widget: b.Widget, HTML: b.HTML, Title: b.Title,
X: b.X, Y: b.Y, W: b.W, H: b.H, Z: b.Z + zShift, X: b.X, Y: b.Y, W: b.W, H: b.H, Z: b.Z + zShift,
Framed: b.Framed, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly, Framed: b.Framed, Shadow: b.Shadow, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly,
} }
if b.ComponentID != nil && live[*b.ComponentID] { if b.ComponentID != nil && live[*b.ComponentID] {
boxes[i].ComponentID = b.ComponentID boxes[i].ComponentID = b.ComponentID
+4
View File
@@ -42,6 +42,7 @@ type CreateBoxInput struct {
H *int `json:"h,omitempty"` H *int `json:"h,omitempty"`
Z *int `json:"z,omitempty"` Z *int `json:"z,omitempty"`
Framed *bool `json:"framed,omitempty"` Framed *bool `json:"framed,omitempty"`
Shadow *string `json:"shadow,omitempty"`
HideOnMobile *bool `json:"hideOnMobile,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"`
AdminOnly *bool `json:"adminOnly,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"`
ComponentID *int `json:"componentId,omitempty"` ComponentID *int `json:"componentId,omitempty"`
@@ -54,6 +55,7 @@ type CreateComponentInput struct {
W *int `json:"w,omitempty"` W *int `json:"w,omitempty"`
H *int `json:"h,omitempty"` H *int `json:"h,omitempty"`
Framed *bool `json:"framed,omitempty"` Framed *bool `json:"framed,omitempty"`
Shadow *string `json:"shadow,omitempty"`
AdminOnly *bool `json:"adminOnly,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"`
} }
@@ -167,6 +169,7 @@ type UpdateBoxInput struct {
H *int `json:"h,omitempty"` H *int `json:"h,omitempty"`
Z *int `json:"z,omitempty"` Z *int `json:"z,omitempty"`
Framed *bool `json:"framed,omitempty"` Framed *bool `json:"framed,omitempty"`
Shadow *string `json:"shadow,omitempty"`
HideOnMobile *bool `json:"hideOnMobile,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"`
AdminOnly *bool `json:"adminOnly,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"`
} }
@@ -178,6 +181,7 @@ type UpdateComponentInput struct {
W *int `json:"w,omitempty"` W *int `json:"w,omitempty"`
H *int `json:"h,omitempty"` H *int `json:"h,omitempty"`
Framed *bool `json:"framed,omitempty"` Framed *bool `json:"framed,omitempty"`
Shadow *string `json:"shadow,omitempty"`
AdminOnly *bool `json:"adminOnly,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"`
} }
+4
View File
@@ -24,6 +24,8 @@ type Box {
h: Int! h: Int!
z: Int! z: Int!
framed: Boolean! framed: Boolean!
# A CSS box-shadow value, or "" for none.
shadow: String!
hideOnMobile: Boolean! hideOnMobile: Boolean!
adminOnly: Boolean! adminOnly: Boolean!
componentId: ID componentId: ID
@@ -41,6 +43,7 @@ input CreateBoxInput {
h: Int h: Int
z: Int z: Int
framed: Boolean framed: Boolean
shadow: String
hideOnMobile: Boolean hideOnMobile: Boolean
adminOnly: Boolean adminOnly: Boolean
# Links the new box to this component; kind is then "html" and html is # Links the new box to this component; kind is then "html" and html is
@@ -58,6 +61,7 @@ input UpdateBoxInput {
h: Int h: Int
z: Int z: Int
framed: Boolean framed: Boolean
shadow: String
hideOnMobile: Boolean hideOnMobile: Boolean
adminOnly: Boolean adminOnly: Boolean
} }
+5 -2
View File
@@ -2,7 +2,7 @@
# as a copy (an ordinary box) or linked (a Box whose componentId is set). # as a copy (an ordinary box) or linked (a Box whose componentId is set).
# Linked boxes share only the html — editing a component changes every box # Linked boxes share only the html — editing a component changes every box
# linked to it — while title, geometry, frame and visibility stay each box's # linked to it — while title, geometry, frame and visibility stay each box's
# own. title, w, h, framed and adminOnly here are what a newly placed box # own. title, w, h, framed, shadow and adminOnly here are what a newly placed box
# starts with. See models.Component and graph/component_helpers.go. # starts with. See models.Component and graph/component_helpers.go.
# #
# Admin only throughout, reads included, because a component may have been # Admin only throughout, reads included, because a component may have been
@@ -19,6 +19,7 @@ type Component {
w: Int! w: Int!
h: Int! h: Int!
framed: Boolean! framed: Boolean!
shadow: String!
adminOnly: Boolean! adminOnly: Boolean!
# How many boxes are linked to it. # How many boxes are linked to it.
uses: Int! uses: Int!
@@ -31,6 +32,7 @@ input CreateComponentInput {
w: Int w: Int
h: Int h: Int
framed: Boolean framed: Boolean
shadow: String
adminOnly: Boolean adminOnly: Boolean
} }
@@ -41,6 +43,7 @@ input UpdateComponentInput {
w: Int w: Int
h: Int h: Int
framed: Boolean framed: Boolean
shadow: String
adminOnly: Boolean adminOnly: Boolean
} }
@@ -57,7 +60,7 @@ extend type Mutation {
# no page changes. # no page changes.
deleteComponent(id: ID!): Component! @admin deleteComponent(id: ID!): Component! @admin
# Makes html box `id` into a component named `name`, from its html, title, # Makes html box `id` into a component named `name`, from its html, title,
# size, frame and adminOnly, and links the box to it. Answers with the box. # size, frame, shadow and adminOnly, and links the box to it. Answers with the box.
saveBoxAsComponent(id: ID!, name: String!): Box! @admin saveBoxAsComponent(id: ID!, name: String!): Box! @admin
# Gives linked box `id` its own copy of the component's html and unlinks it. # Gives linked box `id` its own copy of the component's html and unlinks it.
detachBox(id: ID!): Box! @admin detachBox(id: ID!): Box! @admin
+10 -5
View File
@@ -191,8 +191,11 @@ type Box struct {
// No gorm default on Framed: GORM omits zero values for defaulted columns // No gorm default on Framed: GORM omits zero values for defaulted columns
// on insert, so default:true would turn an explicit false into true. // on insert, so default:true would turn an explicit false into true.
// 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"` // Shadow is a CSS box-shadow value drawn around the box, or "" for none.
// It is independent of Framed, so an unframed box can still cast one.
Shadow string `gorm:"not null;default:''" json:"shadow"`
HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"`
// AdminOnly boxes are never sent to anyone but an admin (the boxes // AdminOnly boxes are never sent to anyone but an admin (the boxes
// resolver filters them out), so they suit private notes. // resolver filters them out), so they suit private notes.
AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"`
@@ -266,7 +269,8 @@ type Layout struct {
// boxes share only the HTML — editing it changes every one of them at once — // boxes share only the HTML — editing it changes every one of them at once —
// while title, geometry, frame and visibility stay each box's own, since // while title, geometry, frame and visibility stay each box's own, since
// those are about where it sits on a page rather than what it is. Title, W, // those are about where it sits on a page rather than what it is. Title, W,
// H, Framed and AdminOnly are the defaults a newly placed box starts with. // H, Framed, Shadow and AdminOnly are the defaults a newly placed box starts
// with.
// Widgets are not components: a widget box is just a name, with nothing // Widgets are not components: a widget box is just a name, with nothing
// worth sharing. The unique index is partial for the same reason as Page's. // worth sharing. The unique index is partial for the same reason as Page's.
type Component struct { type Component struct {
@@ -280,6 +284,7 @@ type Component struct {
W int `gorm:"not null" json:"w"` W int `gorm:"not null" json:"w"`
H int `gorm:"not null" json:"h"` H int `gorm:"not null" json:"h"`
// No gorm default on Framed, for the same reason as Box.Framed. // No gorm default on Framed, for the same reason as Box.Framed.
Framed bool `gorm:"not null" json:"framed"` Framed bool `gorm:"not null" json:"framed"`
AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` Shadow string `gorm:"not null;default:''" json:"shadow"`
AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"`
} }
+1 -1
View File
@@ -271,7 +271,7 @@ renders any page's boxes.
component's html in its `html` (`fillLinked` in component's html in its `html` (`fillLinked` in
`backend/graph/component_helpers.go`), and saving the html in `BoxEditor` `backend/graph/component_helpers.go`), and saving the html in `BoxEditor`
saves the component, so every linked box on every page changes. Only the saves the component, so every linked box on every page changes. Only the
html is shared; title, geometry, frame and visibility stay each box's own. html is shared; title, geometry, frame, shadow and visibility stay each box's own.
"Save as component" in the editor makes a component from an html box and "Save as component" in the editor makes a component from an html box and
links it; "Detach" gives a linked box its own copy. Deleting a component links it; "Detach" gives a linked box its own copy. Deleting a component
detaches its boxes first, so no page changes. A layout keeps both the link detaches its boxes first, so no page changes. A layout keeps both the link
+2 -1
View File
@@ -36,6 +36,7 @@ const BOX_FIELDS = `
h h
z z
framed framed
shadow
hideOnMobile hideOnMobile
adminOnly adminOnly
componentId componentId
@@ -45,7 +46,7 @@ const BOX_FIELDS = `
// same box — or componentId, which keeps a copy of a linked box linked; // same box — or componentId, which keeps a copy of a linked box linked;
// geometry is offset so the copy is visibly separate. // geometry is offset so the copy is visibly separate.
const COPIED = [ const COPIED = [
"page", "kind", "widget", "html", "title", "w", "h", "framed", "hideOnMobile", "adminOnly", "componentId", "page", "kind", "widget", "html", "title", "w", "h", "framed", "shadow", "hideOnMobile", "adminOnly", "componentId",
]; ];
const stores = new Map(); const stores = new Map();
+3 -1
View File
@@ -28,6 +28,7 @@ const COMPONENT_FIELDS = `
w w
h h
framed framed
shadow
adminOnly adminOnly
uses uses
`; `;
@@ -35,7 +36,7 @@ const COMPONENT_FIELDS = `
// Matches BOX_FIELDS in stores/boxes.js, for the mutations that answer with // Matches BOX_FIELDS in stores/boxes.js, for the mutations that answer with
// a box. // a box.
const BOX_FIELDS = ` const BOX_FIELDS = `
id page kind widget html title x y w h z framed hideOnMobile adminOnly componentId id page kind widget html title x y w h z framed shadow hideOnMobile adminOnly componentId
`; `;
export const useComponentsStore = createCrudStore("components", { export const useComponentsStore = createCrudStore("components", {
@@ -110,6 +111,7 @@ export const useComponentsStore = createCrudStore("components", {
w: component.w, w: component.w,
h: component.h, h: component.h,
framed: component.framed, framed: component.framed,
shadow: component.shadow,
adminOnly: component.adminOnly, adminOnly: component.adminOnly,
...at, ...at,
}; };
+1 -1
View File
@@ -459,7 +459,7 @@ function toggleEdit() {
:key="box.id" :key="box.id"
class="stack-item" class="stack-item"
:class="{ framed: box.framed, 'admin-only': box.adminOnly }" :class="{ framed: box.framed, 'admin-only': box.adminOnly }"
:style="{ height: `${box.h}px` }" :style="{ height: `${box.h}px`, boxShadow: box.shadow || undefined }"
> >
<WidgetBox v-if="box.kind === 'widget'" :name="box.widget" /> <WidgetBox v-if="box.kind === 'widget'" :name="box.widget" />
<HtmlBox v-else :html="box.html" :title="box.title" /> <HtmlBox v-else :html="box.html" :title="box.title" />
+63 -1
View File
@@ -3,7 +3,7 @@
* Side panel for the selected box in edit mode. * Side panel for the selected box in edit mode.
* *
* Two save rhythms, matching how each kind of field is used: * Two save rhythms, matching how each kind of field is used:
* - Settings (title, geometry, frame, mobile, widget) save as soon as they * - Settings (title, geometry, frame, shadow, mobile, widget) save as soon as they
* change — on blur/Enter for numbers, on change for the rest — the same * change — on blur/Enter for numbers, on change for the rest — the same
* "instant" model as dragging. * "instant" model as dragging.
* - HTML is a draft. Typing updates the box on the canvas live (through the * - HTML is a draft. Typing updates the box on the canvas live (through the
@@ -102,6 +102,19 @@ watch(draftHtml, (html) => {
previewTimer = setTimeout(() => emit("preview", dirty.value ? html : null), 300); previewTimer = setTimeout(() => emit("preview", dirty.value ? html : null), 300);
}); });
// Starting points for a box's shadow, which is any CSS box-shadow value.
// Ticking "Shadow" uses the first; the text field takes anything else.
const SHADOWS = {
Hard: "6px 6px 0 var(--color-quaternary)",
Soft: "0 6px 18px rgb(0 0 0 / 0.5)",
Glow: "0 0 14px var(--color-primary)",
};
function saveShadow(event) {
const value = event.target.value.trim();
if (value !== props.box.shadow) save({ shadow: value });
}
async function save(patch) { async function save(patch) {
try { try {
await store.update(props.box.id, patch); await store.update(props.box.id, patch);
@@ -292,6 +305,14 @@ function resizeByKey(event) {
<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
</label> </label>
<label class="check">
<input
type="checkbox"
:checked="!!box.shadow"
@change="save({ shadow: $event.target.checked ? SHADOWS.Hard : '' })"
/>
Shadow
</label>
<label class="check"> <label class="check">
<input <input
type="checkbox" type="checkbox"
@@ -306,6 +327,27 @@ function resizeByKey(event) {
</label> </label>
</div> </div>
<div v-if="box.shadow" class="shadow">
<button
v-for="(value, name) in SHADOWS"
:key="name"
type="button"
class="save small"
:class="{ active: box.shadow === value }"
@click="save({ shadow: value })"
>
{{ name }}
</button>
<input
type="text"
:value="box.shadow"
spellcheck="false"
title="Any CSS box-shadow value, e.g. 4px 4px 0 red, 0 0 10px #0f0"
@change="saveShadow"
@keydown.enter="$event.target.blur()"
/>
</div>
<template v-if="box.kind === 'html'"> <template v-if="box.kind === 'html'">
<CodeEditor <CodeEditor
ref="codeEditor" ref="codeEditor"
@@ -496,6 +538,26 @@ function resizeByKey(event) {
font-size: 0.95rem; font-size: 0.95rem;
} }
.shadow {
display: flex;
align-items: center;
gap: 0.4rem;
}
.shadow .active {
color: var(--color-tertiary);
border-color: var(--color-tertiary);
}
.shadow input {
flex: 1;
min-width: 0;
padding: 3px 5px;
font-family: monospace;
font-size: 0.85rem;
color: var(--color-secondary);
background: var(--color-surface-deep);
border: 1px solid var(--color-quaternary);
}
.linked { .linked {
display: flex; display: flex;
align-items: center; align-items: center;
+2
View File
@@ -90,6 +90,8 @@ const style = computed(() => ({
// handles sit just outside its edges, where an overlapping neighbour with a // handles sit just outside its edges, where an overlapping neighbour with a
// higher z would otherwise cover them and take the press. // higher z would otherwise cover them and take the press.
zIndex: props.selected ? 100000 : props.box.z, zIndex: props.selected ? 100000 : props.box.z,
// Applied inline because it is any CSS box-shadow value the admin typed.
boxShadow: props.box.shadow || undefined,
})); }));
</script> </script>