webcake-storefront-mcp 1.31.7 → 1.31.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,6 +157,41 @@ export function buildElement(type, opts = {}) {
157
157
  }
158
158
  // Guarantee children-using factories never throw on a missing children array.
159
159
  const node = fn({ children: [], ...opts });
160
+ // Some factories (container, menu, menu-droppable, …) IGNORE opts.config / opts.style — they
161
+ // only wire children/specials. That silently dropped base layout keys like config.isHidden
162
+ // (e.g. a "hidden on desktop" mobile bar stayed visible). Backfill them into runtime so EVERY
163
+ // element honours opts.config/opts.style. Existing values from factories that DO handle them are
164
+ // kept (opts wins only where the factory left it unset) — idempotent for those.
165
+ if (opts.config && typeof opts.config === "object") {
166
+ node.runtime = node.runtime || {};
167
+ node.runtime.config = { ...opts.config, ...(node.runtime.config || {}) };
168
+ }
169
+ if (opts.style && typeof opts.style === "object") {
170
+ node.runtime = node.runtime || {};
171
+ node.runtime.style = { ...opts.style, ...(node.runtime.style || {}) };
172
+ }
173
+ // Generic horizontal ALIGNMENT control: opts.align maps to the renderer's constraintX so
174
+ // ANY element (button, text, image, container…) can be placed left / centre / right, or
175
+ // told to FILL its grid cell. Without this a content-sized element (e.g. a button) lands
176
+ // wherever the default constraint puts it; authors had no clean knob to centre or pin it.
177
+ // 'fill' also forces a 100%-width cell so the element truly spans the column.
178
+ if (opts.align) {
179
+ const ALIGN = {
180
+ left: ["left"], center: ["centerLeft"], centre: ["centerLeft"],
181
+ right: ["right"], fill: ["left", "right"], stretch: ["left", "right"],
182
+ };
183
+ const cx = ALIGN[String(opts.align).toLowerCase()];
184
+ if (cx) {
185
+ node.runtime = node.runtime || {};
186
+ const rc = (node.runtime.config = node.runtime.config || {});
187
+ rc.constraintX = cx;
188
+ if (cx.length === 2) {
189
+ rc.widthUnit = "%";
190
+ if (rc.relWidth == null)
191
+ rc.relWidth = 100;
192
+ }
193
+ }
194
+ }
160
195
  // Some factories ignore opts.bindings/events — attach them so any element the AI passes
161
196
  // them to gets them — then normalize so each binding/event has a valid id (+ name/eventName).
162
197
  if (opts.bindings && !node.bindings)
@@ -135,12 +135,26 @@ export const createButton = (opts = {}) => {
135
135
  button.id = 'BUTTON-' + randomString(8);
136
136
  button.type = 'button';
137
137
  button.runtime.style = {
138
- width: 142,
139
- height: 46,
138
+ height: 48,
140
139
  fontSize: '16px',
140
+ // Generous horizontal padding so the label never sits edge-to-edge — the #1 "ugly
141
+ // button" complaint when a button stretched full width. Centred text keeps it tidy
142
+ // whatever the width. Override any of these via opts.style.
143
+ paddingTop: '0px',
144
+ paddingBottom: '0px',
145
+ paddingLeft: '28px',
146
+ paddingRight: '28px',
147
+ textAlign: 'center',
141
148
  ...(opts.style || {}),
142
149
  };
143
150
  button.runtime.config = {
151
+ // A button sizes to its CONTENT (label + padding), NOT the full grid cell. Without
152
+ // this, stackChildren's sizeDefaults stretches it to widthUnit:'%'/relWidth:100 — i.e.
153
+ // an edge-to-edge bar with cramped text. Content-width + the default centred
154
+ // constraintX means a standalone CTA sits centred with breathing room instead of being
155
+ // slammed flush-left. To make a button FILL its container, pass opts.align:'fill' (or
156
+ // opts.config.widthUnit:'%').
157
+ widthUnit: 'auto',
144
158
  ...(opts.config || {})
145
159
  };
146
160
  button.specials.text = opts.text || 'Button';
@@ -725,9 +739,19 @@ export const createSubmitButton = (opts = {}) => {
725
739
  const button = cloneDeep(SKELETON);
726
740
  button.id = 'SUBMIT-BUTTON-' + randomString(8);
727
741
  button.type = 'submit-button';
728
- button.runtime.style = opts.style || {};
729
- button.runtime.config = opts.config || {};
742
+ // A form submit button stays full-width (the norm inside a form column) but gets a real
743
+ // height + side padding + centred label so it never renders as a cramped sliver.
744
+ button.runtime.style = {
745
+ height: 48,
746
+ fontSize: '16px',
747
+ paddingLeft: '24px',
748
+ paddingRight: '24px',
749
+ textAlign: 'center',
750
+ ...(opts.style || {}),
751
+ };
752
+ button.runtime.config = { ...(opts.config || {}) };
730
753
  button.specials = {
754
+ ...(opts.specials || {}),
731
755
  text: opts.specials?.text || 'Submit'
732
756
  };
733
757
  return button;
@@ -94,6 +94,20 @@ children with a grid:
94
94
  new_section does ALL of this for you: pass children and they are stacked one row each in
95
95
  the centre column.
96
96
 
97
+ ### ALIGNMENT inside a cell — how children line up (avoid the "snapped to a corner" look)
98
+ \`constraintX\`/\`constraintY\` decide where a child sits in its grid cell. The renderer maps:
99
+ - \`["left","right"]\` → justify-self: STRETCH — the element FILLS the cell width (this is what makes
100
+ columns, cards, and images line up edge-to-edge). This is the DEFAULT new_section/new_row give to
101
+ every width-filling element (text, image, container, repeaters), so siblings stay in straight rows.
102
+ - \`["centerLeft"]\` → justify-self: CENTER (shrinks a content-width element to its content and centres it),
103
+ \`["left"]\` → left, \`["right"]\` → right. \`constraintY\`: \`["top"]\` (default) / \`["bottom"]\` / \`["centerTop"]\` (middle).
104
+ DON'T hand-set \`["centerLeft"]\` on a full-width element (text/container/card) — that snaps it to its
105
+ content width and floats it, so it no longer lines up with its neighbours (the classic "cắn/lệch" bug).
106
+ Instead: leave the default stretch and control the LOOK with \`textAlign\` (for text) or, for a
107
+ content-width element like a button, with \`opts.align\` ('left'|'center'|'right'|'fill'). A button is
108
+ content-width + centred by DEFAULT; pass \`align:"left"\` so it lines up with left-aligned text above it,
109
+ or \`align:"fill"\` to span the column.
110
+
97
111
  ## Multi-column rows (cards side by side) — USE THIS, real pages are full of them
98
112
  A plain vertical stack looks like a blog post, not a designed page. Feature cards,
99
113
  category tiles, footer columns, a text+image hero — all are HORIZONTAL rows. Two ways:
@@ -147,6 +161,13 @@ A bare stack of default elements looks unfinished. Apply real styling:
147
161
  - BUTTONS HAVE NO DEFAULT COLOUR — you MUST style them or they look like plain text:
148
162
  \`{ type:"button", opts:{ text:"Mua ngay", style:{ background:"var(--color_24)", color:"var(--color_00)",
149
163
  borderRadius:"8px", fontWeight:"600", height:48 } } }\` (DARK brand background, white label — always readable).
164
+ - BUTTON WIDTH & ALIGNMENT (don't fight it): a \`button\` is CONTENT-SIZED by default (label + built-in
165
+ 28px side padding) and CENTRED in its cell — so a standalone CTA looks like a real button, never a
166
+ full-width bar with cramped text or one slammed flush-left. To place/size it, pass \`opts.align\`:
167
+ \`"left"\` | \`"center"\` (default) | \`"right"\` | \`"fill"\` (span the whole column, e.g. two side-by-side
168
+ Add-to-cart / Buy-now buttons, or a button inside a narrow summary card). \`align\` works on ANY element
169
+ (text/image/container too). A form \`submit-button\` stays full-width by design. Do NOT try to force a
170
+ button's width via \`style.width\` — the renderer ignores it (use \`align:"fill"\` instead).
150
171
  - HERO: build it as a section whose FIRST child is a full-width \`image\` element (the background photo,
151
172
  width:"100%", height ~480), then overlay the heading/sub/button on top. ⚠️ Do NOT rely on a CSS
152
173
  \`background:"linear-gradient(...), url(...)"\` SHORTHAND on the section — the storefront renderer
@@ -176,6 +197,11 @@ The four breakpoints (largest → smallest), keyed bp1..bp4, are:
176
197
  For NEW pages you author once in \`runtime\` (the bp1/desktop base); on save the build expands
177
198
  it into bp1..bp4. By default all four are the same (renders identically across devices), PLUS
178
199
  sections re-centre their grid per breakpoint and multi-column rows auto-collapse (4→2→1 cols).
200
+ AUTO-RESPONSIVE DEFAULTS (you get these for free, no diffs needed): on tablet/mobile the build
201
+ also shrinks oversized TYPOGRAPHY (any fontSize ≥22px scales ~0.86× on tablet / ~0.72× on mobile,
202
+ floored at 15px) and TALL images (height >320px shrinks on mobile) so hero headlines and big media
203
+ don't blow out small screens. Body text (<22px) is left alone. Pass \`opts.responsive\` only to
204
+ OVERRIDE this default for a specific node/breakpoint (your explicit diff always wins).
179
205
 
180
206
  RESPONSIVE CASCADE (reason about each breakpoint, don't hand-copy): to make a node look
181
207
  different on smaller screens, pass \`opts.responsive\` = SPARSE per-breakpoint diffs and the
@@ -313,6 +339,27 @@ create the globals — they embed into each page's source. If you later overwrit
313
339
  (delete_global_section by the section NODE id, then create once) to re-embed cleanly. Edit a global
314
340
  later with update_global_section_element(s) and it updates on every page at once.
315
341
 
342
+ ### HEADER must be RESPONSIVE — add a MOBILE MENUBAR, don't just let nav stack
343
+ A header built as one horizontal row of nav links looks fine on desktop but on a phone the links
344
+ squash or collapse into an ugly vertical pile. Build a header that carries TWO navs and swap them
345
+ per breakpoint with the \`isHidden\` config (it cascades bp1→bp4 like any config key):
346
+ - DESKTOP nav — the inline row of links in the top bar. Keep it on desktop+laptop, hide from tablet
347
+ down: \`responsive:{ bp3:{ config:{ isHidden:true } } }\` (base visible).
348
+ - MOBILE MENUBAR — a SEPARATE container, a centred horizontal row of the same links placed as a
349
+ second row of the header section (below the logo/cart bar). Hide it on desktop+laptop, show from
350
+ tablet down: base \`config:{ isHidden:true }\` + \`responsive:{ bp3:{ config:{ isHidden:false } } }\`.
351
+ RELIABILITY NOTE (storefront-verified): this two-nav \`isHidden\`-SWAP is the dependable mobile
352
+ menubar. AVOID these — they do NOT render dependably from raw MCP data: the native \`menu\`
353
+ \`type:"hamburger"\` (its ☰ trigger paints as a 0-width empty box; an inline-SVG \`mask\` is ignored);
354
+ a \`toggle\`-revealed panel (the storefront only makes a toggle target's hidden state reactive when
355
+ it's wired in the builder UI, so a click can't show an \`isHidden\` element); and \`open_popup\` drawers
356
+ (popups are global_sources and the publish pipeline doesn't always emit them, so the popup isn't on
357
+ the page). A plain visible mobile nav row, shown via \`isHidden\` swap, always works.
358
+ Lay the bar as a 2-column row [logo | (desktop-nav + cart, aligned right)] and add the mobile nav row
359
+ as the section's 2nd child. Keep the logo + cart-icon visible on every breakpoint.
360
+ (If you do want a real collapsible hamburger, finish it in the WebCake builder UI, which wires the
361
+ toggle/menu reactively — the MCP can't reproduce that wiring from data alone.)
362
+
316
363
  ## Popups (newsletter / promo / age-gate)
317
364
  A popup is a GLOBAL SOURCE, not a page section. Compose it from elements (there is no scaffold
318
365
  shortcut), then save it as a "popup" global source:
@@ -10,6 +10,42 @@ import { validateEvents } from "./events.js";
10
10
  import { validateBindings } from "./bindings.js";
11
11
  import { BREAKPOINTS, genGridByBp, SECTION_CONTENT_COL_START, SECTION_CONTENT_COL_END, } from "./grid.js";
12
12
  const clone = (o) => structuredClone(o);
13
+ /** Parse a CSS px length ("52px") or a bare number (52) → number, else null. */
14
+ function pxToNum(v) {
15
+ if (typeof v === "number")
16
+ return Number.isFinite(v) ? v : null;
17
+ const m = /^(-?\d+(?:\.\d+)?)px$/.exec(String(v ?? "").trim());
18
+ return m ? parseFloat(m[1]) : null;
19
+ }
20
+ /** AUTO-RESPONSIVE down-scaling per breakpoint. Headings/large text and very tall media
21
+ * keep their desktop size on phones unless the author hand-writes a responsive diff —
22
+ * which makes generated pages look broken on mobile. These factors shrink oversized
23
+ * typography (and tall images) on tablet/mobile by DEFAULT. Applied only when the author
24
+ * did NOT already override the property at this breakpoint (resolved value === base). */
25
+ const AUTO_FONT_FACTOR = { bp1: 1, bp2: 1, bp3: 0.86, bp4: 0.72 };
26
+ const AUTO_IMG_HEIGHT_FACTOR = { bp1: 1, bp2: 1, bp3: 0.82, bp4: 0.58 };
27
+ /** Mutate a resolved per-breakpoint `style` in place: shrink big fonts (≥22px) and tall
28
+ * images (>320px) for smaller breakpoints. `baseStyle` is the bp1/authored style — we only
29
+ * auto-scale a property the author left untouched at this bp (resolved === base). */
30
+ function applyAutoResponsive(node, bp, baseStyle, style) {
31
+ const ff = AUTO_FONT_FACTOR[bp];
32
+ if (ff != null && ff < 1) {
33
+ const baseF = pxToNum(baseStyle.fontSize);
34
+ const curF = pxToNum(style.fontSize);
35
+ if (baseF != null && curF != null && curF === baseF && baseF >= 22) {
36
+ style.fontSize = Math.max(15, Math.round(baseF * ff)) + "px";
37
+ }
38
+ }
39
+ const hf = AUTO_IMG_HEIGHT_FACTOR[bp];
40
+ if (hf != null && hf < 1 && (node.type === "image" || node.type === "image-dataset")) {
41
+ const baseH = pxToNum(baseStyle.height);
42
+ const curH = pxToNum(style.height);
43
+ if (baseH != null && curH != null && curH === baseH && baseH > 320) {
44
+ const nh = Math.round(baseH * hf);
45
+ style.height = typeof baseStyle.height === "number" ? nh : nh + "px";
46
+ }
47
+ }
48
+ }
13
49
  /** Walk every node in a source tree (depth-first). Return false from fn to stop. */
14
50
  export function walk(source, fn) {
15
51
  const sections = source && Array.isArray(source.sections) ? source.sections : [];
@@ -64,11 +100,28 @@ const FILL_WIDTH_TYPES = new Set([
64
100
  "grid-category", "grid-blog", "product-gallery", "product-image-carousel",
65
101
  "custom-layout", "layout-dataset", "form",
66
102
  ]);
67
- /** Default horizontal constraint for a child: stretch for fill-width components,
68
- * else the builder's usual centred placement. Respects an explicit constraintX. */
103
+ /**
104
+ * Default horizontal constraint for a child in its grid cell. THE ALIGNMENT RULE:
105
+ * an element that FILLS its cell width (widthUnit "%", relWidth 100 — the default for
106
+ * text/image/container/repeaters) must STRETCH (`["left","right"]` → justify-self:stretch),
107
+ * NOT centre. The old default `["centerLeft"]` (justify-self:center) snapped such elements
108
+ * to their content width and floated them — so sibling columns/cards/images did NOT line up
109
+ * (the "cắn left-top / không thẳng hàng" bug). Stretch makes every full-width child span its
110
+ * cell edge-to-edge, so its OWN textAlign / inner stacking controls layout and rows align.
111
+ * Only a genuinely CONTENT-WIDTH element (widthUnit "auto", e.g. a button) gets a point
112
+ * constraint, defaulting to centre. An explicit constraintX (e.g. set by opts.align) always wins.
113
+ */
69
114
  function defaultConstraintX(child) {
70
- return ((child.runtime && child.runtime.config && child.runtime.config.constraintX) ||
71
- (FILL_WIDTH_TYPES.has(child.type) ? ["left", "right"] : ["centerLeft"]));
115
+ const cfg = (child.runtime && child.runtime.config) || {};
116
+ if (cfg.constraintX)
117
+ return cfg.constraintX; // explicit / from opts.align
118
+ if (FILL_WIDTH_TYPES.has(child.type))
119
+ return ["left", "right"];
120
+ // Content-sized elements (a button opts into widthUnit:"auto") centre by default; everything
121
+ // else fills its cell, so it must stretch to line up with its neighbours.
122
+ if (cfg.widthUnit === "auto")
123
+ return ["centerLeft"];
124
+ return ["left", "right"];
72
125
  }
73
126
  export function stackChildren(container, children, opts = {}) {
74
127
  const gridCols = opts.gridCols || 1;
@@ -340,6 +393,8 @@ function expandNodeToBreakpoints(node) {
340
393
  delete config.__row;
341
394
  delete config.__cell;
342
395
  delete config.responsive;
396
+ // Shrink oversized fonts / tall images on tablet & mobile by default (author diffs win).
397
+ applyAutoResponsive(node, bp, rt.style || {}, style);
343
398
  if (isSection) {
344
399
  const g = genGridByBp(minW);
345
400
  const sectionRows = baseConfig.rows && baseConfig.rows.length ? clone(baseConfig.rows) : clone(g.rows);
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "v": "1.31.8",
4
+ "d": "29/06/2026",
5
+ "type": "Fixed",
6
+ "en": "Elements placed by new_section, new_row, and build_page that fill their grid cell (text, image, container, columns, repeaters) now receive…",
7
+ "vi": "Các phần tử được đặt bởi new_section, new_row và build_page mà lấp đầy ô lưới (text, image, container, columns, repeaters) nay nhận constraintX:…"
8
+ },
2
9
  {
3
10
  "v": "1.31.7",
4
11
  "d": "26/06/2026",
@@ -33,12 +40,5 @@
33
40
  "type": "Added",
34
41
  "en": "New update_collection_columns tool reads the current collection schema and PATCHes it with the system columns plus the provided custom columns,…",
35
42
  "vi": "Tool mới update_collection_columns đọc schema hiện tại của collection rồi PATCH lại với các cột hệ thống cộng các cột tùy chỉnh được cung cấp, cho…"
36
- },
37
- {
38
- "v": "1.31.2",
39
- "d": "26/06/2026",
40
- "type": "Changed",
41
- "en": "The HTTP_FUNCTION_GUIDE embedded in get_http_function and get_site_custom_code now includes a \"Common patterns\" section with battle-tested…",
42
- "vi": "HTTP_FUNCTION_GUIDE được nhúng trong get_http_function và get_site_custom_code nay bổ sung phần \"Common patterns\" với các recipe đã được kiểm chứng…"
43
43
  }
44
44
  ]
@@ -83,7 +83,7 @@ export function registerBuilderTools(server, api, handle) {
83
83
  server.tool("list_bindings", "List every dynamic-data BINDING target: the datasets (product, cart_item, order, order_item, post, category, customer, customer_address, …) and their exact field names ('product::product_price', …), which page type each needs (store/member/blog), and how repeater children (grid-product, cart-items, post-list) bind per-item. Attach via new_element opts.bindings (ids auto-minted, e.g. opts.bindings=[{ target:'product::product_price' }]).", {}, () => handle(async () => describeBindingsCatalog()));
84
84
  server.tool("new_element", "Build a single structurally-valid element node from the real builder factory. Returns the node — edit its specials/style, then place it in a section's children.", {
85
85
  type: z.string().describe("Element type (see list_elements)"),
86
- opts: z.record(z.any()).optional().describe("Factory opts: { text, src, width, height, style, config, specials, events }"),
86
+ opts: z.record(z.any()).optional().describe("Factory opts: { text, src, width, height, style, config, specials, events, bindings, responsive, align }. align = horizontal placement in the grid cell: 'left'|'center'|'right'|'fill' (works on any element; buttons are content-width+centred by default — use align:'fill' to span the column)."),
87
87
  }, ({ type, opts }) => handle(async () => buildElement(type, opts || {})));
88
88
  server.tool("new_section", `Build a complete section node with children laid out in the builder's vertical grid.
89
89
  Pass an array of element specs; each child is stacked top-to-bottom. Nest containers via the child's own 'children'.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcake-storefront-mcp",
3
- "version": "1.31.7",
3
+ "version": "1.31.8",
4
4
  "description": "MCP server for the WebCake/StoreCake storefront builder — page CRUD, page authoring, products, orders, and more",
5
5
  "mcpName": "io.github.vuluu2k/webcake-storefront-mcp",
6
6
  "license": "MIT",