From 8bf70c98e8ced8fe87e82b95782d2359e686f7e9 Mon Sep 17 00:00:00 2001 From: Adam French Date: Fri, 23 Oct 2026 23:18:35 +0100 Subject: [PATCH] Add a customisable shadow to canvas boxes 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 --- backend/graph/box.resolvers.go | 6 ++ backend/graph/box_helpers.go | 20 +++++ backend/graph/component.resolvers.go | 14 +++- backend/graph/generated.go | 110 ++++++++++++++++++++++++- backend/graph/layout_helpers.go | 5 +- backend/graph/model/models_gen.go | 4 + backend/graph/schema/box.graphql | 4 + backend/graph/schema/component.graphql | 7 +- backend/models/models.go | 15 ++-- vue/README.md | 2 +- vue/src/stores/boxes.js | 3 +- vue/src/stores/components.js | 4 +- vue/src/views/home3/BoxCanvas.vue | 2 +- vue/src/views/home3/BoxEditor.vue | 64 +++++++++++++- vue/src/views/home3/BoxFrame.vue | 2 + 15 files changed, 243 insertions(+), 19 deletions(-) diff --git a/backend/graph/box.resolvers.go b/backend/graph/box.resolvers.go index 1500455..15332fb 100644 --- a/backend/graph/box.resolvers.go +++ b/backend/graph/box.resolvers.go @@ -36,6 +36,9 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI if input.Framed != nil { box.Framed = *input.Framed } + if input.Shadow != nil { + box.Shadow = *input.Shadow + } if input.HideOnMobile != nil { box.HideOnMobile = *input.HideOnMobile } @@ -102,6 +105,9 @@ func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.Up if input.Framed != nil { box.Framed = *input.Framed } + if input.Shadow != nil { + box.Shadow = *input.Shadow + } if input.HideOnMobile != nil { box.HideOnMobile = *input.HideOnMobile } diff --git a/backend/graph/box_helpers.go b/backend/graph/box_helpers.go index 00de91d..98a19d2 100644 --- a/backend/graph/box_helpers.go +++ b/backend/graph/box_helpers.go @@ -6,6 +6,8 @@ package graph import ( "errors" + "fmt" + "strings" "adam-french.co.uk/backend/models" ) @@ -14,6 +16,10 @@ import ( // be grabbed again on the canvas. 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) { if src != nil { *dst = *src @@ -43,9 +49,23 @@ func validateBox(box *models.Box) error { if box.ComponentID != nil && box.Kind != "html" { 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.Y = max(box.Y, 0) box.W = max(box.W, minBoxSize) box.H = max(box.H, minBoxSize) 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 +} diff --git a/backend/graph/component.resolvers.go b/backend/graph/component.resolvers.go index 166a623..8d0d361 100644 --- a/backend/graph/component.resolvers.go +++ b/backend/graph/component.resolvers.go @@ -38,11 +38,17 @@ func (r *mutationResolver) CreateComponent(ctx context.Context, input model.Crea if input.Framed != nil { c.Framed = *input.Framed } + if input.Shadow != nil { + c.Shadow = *input.Shadow + } if input.AdminOnly != nil { c.AdminOnly = *input.AdminOnly } c.W = max(c.W, 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 { return nil, err } @@ -75,11 +81,17 @@ func (r *mutationResolver) UpdateComponent(ctx context.Context, id int, input mo if input.Framed != nil { c.Framed = *input.Framed } + if input.Shadow != nil { + c.Shadow = *input.Shadow + } if input.AdminOnly != nil { c.AdminOnly = *input.AdminOnly } c.W = max(c.W, 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 { return nil, err } @@ -128,7 +140,7 @@ func (r *mutationResolver) SaveBoxAsComponent(ctx context.Context, id int, name } c := models.Component{ 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 { if err := tx.Create(&c).Error; err != nil { diff --git a/backend/graph/generated.go b/backend/graph/generated.go index f3790f6..20012fb 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -88,6 +88,7 @@ type ComplexityRoot struct { ID func(childComplexity int) int Kind func(childComplexity int) int Page func(childComplexity int) int + Shadow func(childComplexity int) int Title func(childComplexity int) int UpdatedAt func(childComplexity int) int W func(childComplexity int) int @@ -105,6 +106,7 @@ type ComplexityRoot struct { HTML func(childComplexity int) int ID func(childComplexity int) int Name func(childComplexity int) int + Shadow func(childComplexity int) int Title func(childComplexity int) int UpdatedAt 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 + case "Box.shadow": + if e.ComplexityRoot.Box.Shadow == nil { + break + } + + return e.ComplexityRoot.Box.Shadow(childComplexity), true case "Box.title": if e.ComplexityRoot.Box.Title == nil { break @@ -672,6 +680,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } 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": if e.ComplexityRoot.Component.Title == nil { break @@ -1966,6 +1980,8 @@ func (ec *executionContext) childFields_Box(ctx context.Context, field graphql.C return ec.fieldContext_Box_z(ctx, field) case "framed": return ec.fieldContext_Box_framed(ctx, field) + case "shadow": + return ec.fieldContext_Box_shadow(ctx, field) case "hideOnMobile": return ec.fieldContext_Box_hideOnMobile(ctx, field) case "adminOnly": @@ -1996,6 +2012,8 @@ func (ec *executionContext) childFields_Component(ctx context.Context, field gra return ec.fieldContext_Component_h(ctx, field) case "framed": return ec.fieldContext_Component_framed(ctx, field) + case "shadow": + return ec.fieldContext_Component_shadow(ctx, field) case "adminOnly": return ec.fieldContext_Component_adminOnly(ctx, field) 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")) } +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) { return graphql.ResolveField( 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")) } +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) { return graphql.ResolveField( ctx, @@ -10128,7 +10192,7 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob 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 { v, ok := asMap[k] if !ok { @@ -10212,6 +10276,13 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob return it, err } 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": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -10249,7 +10320,7 @@ func (ec *executionContext) unmarshalInputCreateComponentInput(ctx context.Conte 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 { v, ok := asMap[k] if !ok { @@ -10298,6 +10369,13 @@ func (ec *executionContext) unmarshalInputCreateComponentInput(ctx context.Conte return it, err } 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": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -10636,7 +10714,7 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob 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 { v, ok := asMap[k] if !ok { @@ -10706,6 +10784,13 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob return it, err } 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": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile")) data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) @@ -10736,7 +10821,7 @@ func (ec *executionContext) unmarshalInputUpdateComponentInput(ctx context.Conte 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 { v, ok := asMap[k] if !ok { @@ -10785,6 +10870,13 @@ func (ec *executionContext) unmarshalInputUpdateComponentInput(ctx context.Conte return it, err } 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": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) 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 { out.Invalids++ } + case "shadow": + out.Values[i] = ec._Box_shadow(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "hideOnMobile": out.Values[i] = ec._Box_hideOnMobile(ctx, field, obj) 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 { 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": out.Values[i] = ec._Component_adminOnly(ctx, field, obj) if out.Values[i] == graphql.Null { diff --git a/backend/graph/layout_helpers.go b/backend/graph/layout_helpers.go index c51bb30..d9d0205 100644 --- a/backend/graph/layout_helpers.go +++ b/backend/graph/layout_helpers.go @@ -31,6 +31,7 @@ type layoutBox struct { H int `json:"h"` Z int `json:"z"` Framed bool `json:"framed"` + Shadow string `json:"shadow,omitempty"` HideOnMobile bool `json:"hideOnMobile"` AdminOnly bool `json:"adminOnly"` // 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{ 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, - Framed: b.Framed, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly, + Framed: b.Framed, Shadow: b.Shadow, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly, ComponentID: b.ComponentID, } } @@ -217,7 +218,7 @@ func applyLayoutTo(tx *gorm.DB, layout *models.Layout, page string, replace bool boxes[i] = models.Box{ 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, - 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] { boxes[i].ComponentID = b.ComponentID diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index 6417b02..846d6c3 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -42,6 +42,7 @@ type CreateBoxInput struct { H *int `json:"h,omitempty"` Z *int `json:"z,omitempty"` Framed *bool `json:"framed,omitempty"` + Shadow *string `json:"shadow,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"` ComponentID *int `json:"componentId,omitempty"` @@ -54,6 +55,7 @@ type CreateComponentInput struct { W *int `json:"w,omitempty"` H *int `json:"h,omitempty"` Framed *bool `json:"framed,omitempty"` + Shadow *string `json:"shadow,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"` } @@ -167,6 +169,7 @@ type UpdateBoxInput struct { H *int `json:"h,omitempty"` Z *int `json:"z,omitempty"` Framed *bool `json:"framed,omitempty"` + Shadow *string `json:"shadow,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"` } @@ -178,6 +181,7 @@ type UpdateComponentInput struct { W *int `json:"w,omitempty"` H *int `json:"h,omitempty"` Framed *bool `json:"framed,omitempty"` + Shadow *string `json:"shadow,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"` } diff --git a/backend/graph/schema/box.graphql b/backend/graph/schema/box.graphql index 89b6052..9cacd89 100644 --- a/backend/graph/schema/box.graphql +++ b/backend/graph/schema/box.graphql @@ -24,6 +24,8 @@ type Box { h: Int! z: Int! framed: Boolean! + # A CSS box-shadow value, or "" for none. + shadow: String! hideOnMobile: Boolean! adminOnly: Boolean! componentId: ID @@ -41,6 +43,7 @@ input CreateBoxInput { h: Int z: Int framed: Boolean + shadow: String hideOnMobile: Boolean adminOnly: Boolean # Links the new box to this component; kind is then "html" and html is @@ -58,6 +61,7 @@ input UpdateBoxInput { h: Int z: Int framed: Boolean + shadow: String hideOnMobile: Boolean adminOnly: Boolean } diff --git a/backend/graph/schema/component.graphql b/backend/graph/schema/component.graphql index ce3a02d..67703da 100644 --- a/backend/graph/schema/component.graphql +++ b/backend/graph/schema/component.graphql @@ -2,7 +2,7 @@ # 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 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. # # Admin only throughout, reads included, because a component may have been @@ -19,6 +19,7 @@ type Component { w: Int! h: Int! framed: Boolean! + shadow: String! adminOnly: Boolean! # How many boxes are linked to it. uses: Int! @@ -31,6 +32,7 @@ input CreateComponentInput { w: Int h: Int framed: Boolean + shadow: String adminOnly: Boolean } @@ -41,6 +43,7 @@ input UpdateComponentInput { w: Int h: Int framed: Boolean + shadow: String adminOnly: Boolean } @@ -57,7 +60,7 @@ extend type Mutation { # no page changes. deleteComponent(id: ID!): Component! @admin # 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 # Gives linked box `id` its own copy of the component's html and unlinks it. detachBox(id: ID!): Box! @admin diff --git a/backend/models/models.go b/backend/models/models.go index 6acd99b..368d973 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -191,8 +191,11 @@ type Box struct { // No gorm default on Framed: GORM omits zero values for defaulted columns // on insert, so default:true would turn an explicit false into true. // CreateBox applies the true default itself. - Framed bool `gorm:"not null" json:"framed"` - HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"` + Framed bool `gorm:"not null" json:"framed"` + // 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 // resolver filters them out), so they suit private notes. 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 — // 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, -// 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 // worth sharing. The unique index is partial for the same reason as Page's. type Component struct { @@ -280,6 +284,7 @@ type Component struct { W int `gorm:"not null" json:"w"` H int `gorm:"not null" json:"h"` // No gorm default on Framed, for the same reason as Box.Framed. - Framed bool `gorm:"not null" json:"framed"` - AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` + Framed bool `gorm:"not null" json:"framed"` + Shadow string `gorm:"not null;default:''" json:"shadow"` + AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` } diff --git a/vue/README.md b/vue/README.md index 2200641..8a3935b 100644 --- a/vue/README.md +++ b/vue/README.md @@ -271,7 +271,7 @@ renders any page's boxes. component's html in its `html` (`fillLinked` in `backend/graph/component_helpers.go`), and saving the html in `BoxEditor` 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 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 diff --git a/vue/src/stores/boxes.js b/vue/src/stores/boxes.js index b1b154b..302218e 100644 --- a/vue/src/stores/boxes.js +++ b/vue/src/stores/boxes.js @@ -36,6 +36,7 @@ const BOX_FIELDS = ` h z framed + shadow hideOnMobile adminOnly componentId @@ -45,7 +46,7 @@ const BOX_FIELDS = ` // same box — or componentId, which keeps a copy of a linked box linked; // geometry is offset so the copy is visibly separate. 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(); diff --git a/vue/src/stores/components.js b/vue/src/stores/components.js index df74036..e62d806 100644 --- a/vue/src/stores/components.js +++ b/vue/src/stores/components.js @@ -28,6 +28,7 @@ const COMPONENT_FIELDS = ` w h framed + shadow adminOnly uses `; @@ -35,7 +36,7 @@ const COMPONENT_FIELDS = ` // Matches BOX_FIELDS in stores/boxes.js, for the mutations that answer with // a box. 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", { @@ -110,6 +111,7 @@ export const useComponentsStore = createCrudStore("components", { w: component.w, h: component.h, framed: component.framed, + shadow: component.shadow, adminOnly: component.adminOnly, ...at, }; diff --git a/vue/src/views/home3/BoxCanvas.vue b/vue/src/views/home3/BoxCanvas.vue index 47d1d74..806e64d 100644 --- a/vue/src/views/home3/BoxCanvas.vue +++ b/vue/src/views/home3/BoxCanvas.vue @@ -459,7 +459,7 @@ function toggleEdit() { :key="box.id" class="stack-item" :class="{ framed: box.framed, 'admin-only': box.adminOnly }" - :style="{ height: `${box.h}px` }" + :style="{ height: `${box.h}px`, boxShadow: box.shadow || undefined }" > diff --git a/vue/src/views/home3/BoxEditor.vue b/vue/src/views/home3/BoxEditor.vue index 3636778..ad5a054 100644 --- a/vue/src/views/home3/BoxEditor.vue +++ b/vue/src/views/home3/BoxEditor.vue @@ -3,7 +3,7 @@ * Side panel for the selected box in edit mode. * * 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 * "instant" model as dragging. * - 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); }); +// 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) { try { await store.update(props.box.id, patch); @@ -292,6 +305,14 @@ function resizeByKey(event) { Frame +