@shop-on/create-theme 0.9.0 → 0.11.0
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.
- package/dist/cli.mjs +1 -2
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +1 -2
- package/package.json +3 -3
- package/template/.claude/skills/theme-dev/SKILL.md +4 -4
- package/template/.claude/skills/theme-dev/recipes/concepts.md +2 -2
- package/template/.claude/skills/theme-dev/recipes/custom-sections.md +28 -226
- package/template/.claude/skills/theme-dev/recipes/customer-auth.md +2 -1
- package/template/.claude/skills/theme-dev/recipes/data-fetching.md +2 -2
- package/template/.claude/skills/theme-dev/recipes/input-settings.md +5 -6
- package/template/.claude/skills/theme-dev/recipes/locales.md +1 -1
- package/template/.claude/skills/theme-dev/recipes/picker-data.md +2 -2
- package/template/.env.example +2 -3
- package/template/.oxfmtrc.json +0 -1
- package/template/package.json +21 -22
- package/template/src/ai/guide.md +25 -0
- package/template/src/blocks/custom-block.json +4 -0
- package/template/src/blocks/custom-block.test.ts +16 -0
- package/template/src/blocks/custom-block.tsx +26 -0
- package/template/src/lib/i18n.server.ts +2 -2
- package/template/src/lib/i18n.ts +9 -0
- package/template/src/lib/listing-search.ts +7 -12
- package/template/src/lib/use-analytics.ts +11 -11
- package/template/src/locales/en.default.json +4 -0
- package/template/src/locales/en.default.schema.json +16 -2
- package/template/src/locales/mn.default.json +4 -0
- package/template/src/locales/mn.default.schema.json +16 -2
- package/template/src/route-adapter.tsx +0 -2
- package/template/src/routeTree.gen.ts +22 -0
- package/template/src/routes/__root.tsx +2 -2
- package/template/src/routes/robots[.]txt.tsx +5 -5
- package/template/src/routes/sitemap[.]xml.tsx +5 -4
- package/template/src/routes/{-$locale}/checkout.tsx +13 -8
- package/template/src/routes/{-$locale}/collections/index.tsx +1 -1
- package/template/src/routes/{-$locale}/orders/find.tsx +13 -0
- package/template/src/sections/custom-section.json +39 -0
- package/template/src/sections/custom-section.test.ts +14 -0
- package/template/src/sections/custom-section.tsx +73 -0
- package/template/src/sections/hero.json +6 -1
- package/template/src/sections/main-collection.test.tsx +21 -7
- package/template/src/sections/main-product.json +1 -0
- package/template/src/sections/main-product.tsx +15 -0
- package/template/src/server/i18n.server.test.ts +2 -2
- package/template/src/server/i18n.server.ts +7 -19
- package/template/src/server/settings.ts +26 -7
- package/template/src/server/template-loader.ts +2 -2
- package/template/tsconfig.json +0 -7
- package/template/src/server/checkout-redirect.ts +0 -21
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { packageManagerCommands, scaffoldTheme } from "./index.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
|
|
4
|
+
// src/cli.ts
|
|
5
5
|
const USAGE = "usage: npm create @shop-on/theme <dir>";
|
|
6
6
|
const dir = process.argv[2];
|
|
7
7
|
if (dir === "-h" || dir === "--help") {
|
|
@@ -36,5 +36,4 @@ ${steps.map((step, i) => ` ${i + 1}. ${step}`).join("\n")}
|
|
|
36
36
|
|
|
37
37
|
Once the Shop-On CLI is published, \`shop-on theme init\` does all this and fills in .env for you.
|
|
38
38
|
`);
|
|
39
|
-
//#endregion
|
|
40
39
|
export {};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* `{ [name]: packedName }`: the files `npm pack` leaves out of a tarball, which
|
|
4
3
|
* `template/` stores renamed and `scaffoldTheme` restores.
|
|
@@ -28,5 +27,4 @@ export declare function scaffoldTheme({ dir }: {
|
|
|
28
27
|
export declare function packageManagerCommands(userAgent: string | undefined): {
|
|
29
28
|
install: string[];
|
|
30
29
|
dev: string[];
|
|
31
|
-
};
|
|
32
|
-
//#endregion
|
|
30
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
4
|
+
// src/index.ts
|
|
5
5
|
/**
|
|
6
6
|
* `{ [name]: packedName }`: the files `npm pack` leaves out of a tarball, which
|
|
7
7
|
* `template/` stores renamed and `scaffoldTheme` restores.
|
|
@@ -77,5 +77,4 @@ function packageManagerCommands(userAgent) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
//#endregion
|
|
81
80
|
export { PACKED_NAMES, packageManagerCommands, scaffoldTheme };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shop-on/create-theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Scaffolds a Shop-On storefront theme: `npm create @shop-on/theme <dir>`.",
|
|
5
5
|
"license": "SEE LICENSE IN dist/LICENSE.md",
|
|
6
6
|
"bin": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/node": "26.6.
|
|
19
|
+
"@types/node": "26.6.6",
|
|
20
20
|
"typescript": "7.0.2",
|
|
21
|
-
"vitest": "5.0
|
|
21
|
+
"vitest": "5.1.0"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": "^20.19.0 || >=22.12.0"
|
|
@@ -98,7 +98,7 @@ Pick the matching recipe and follow it end-to-end:
|
|
|
98
98
|
- [Wire a picker (image/video/menu/collection/product_list/metaobject)](recipes/picker-data.md)
|
|
99
99
|
- [Dynamic sources (editor "dynamic values")](recipes/dynamic-sources.md) — the loader-side resolution pass; raw `product_attribute:title` on the storefront means it's missing
|
|
100
100
|
- [Design or optimize data fetching](recipes/data-fetching.md) — SSR, payload sizing, lazy interaction data, route loaders
|
|
101
|
-
- [
|
|
101
|
+
- [AI-built sections and blocks](recipes/custom-sections.md) — the shipped `custom-section` / `custom-block`: how they work, the rules for changing them, what to do as the theme grows
|
|
102
102
|
- [Add buyer auth to a theme](recipes/customer-auth.md) — consume the `@shop-on/theme-server` auth surface: bouncers, handoff consume, customer-aware cart, logout, header account control
|
|
103
103
|
- [Add a translation key](recipes/locales.md)
|
|
104
104
|
- [Input setting types reference](recipes/input-settings.md) — every supported `type`, value shape, gotchas
|
|
@@ -129,8 +129,8 @@ Pick the matching recipe and follow it end-to-end:
|
|
|
129
129
|
| `product_list` | Multi-product picker → resolved sibling: `{id}Data: ProductData[]`. `limit?` caps |
|
|
130
130
|
| `metaobject` | Entry picker scoped by `metaobject_type` → stores a GID; resolved sibling: `{id}Data: MetaobjectData \| null` |
|
|
131
131
|
| `metaobject_list` | Multi-entry picker, same `metaobject_type` → stores GIDs; `{id}Data: MetaobjectData[]` (unresolved drop). `limit?` ≤ 50 |
|
|
132
|
-
| `review` | Published-review picker (shop-wide) → stores
|
|
133
|
-
| `review_list` | Multi-review picker → stores
|
|
132
|
+
| `review` | Published-review picker (shop-wide) → stores an id; `{id}Data: ReviewCardData \| null` |
|
|
133
|
+
| `review_list` | Multi-review picker → stores ids; `{id}Data: ReviewCardData[]` (unresolved drop). `limit?` ≤ 50 |
|
|
134
134
|
| `page` | CMS-page handle picker → resolved sibling: `{id}Data` (narrow title + body), both scopes |
|
|
135
135
|
| `html` | CodeMirror HTML editor → raw, **unsanitized** merchant markup; render via the theme's `CustomHtml` snippet, never by hand |
|
|
136
136
|
| `liquid` | CodeMirror Liquid editor → merchant Liquid, rendered **server-side** during enrichment into a `liquidData` sibling |
|
|
@@ -275,7 +275,7 @@ AI assistants connected to a store (Claude, ChatGPT) and `shop-on theme mcp` edi
|
|
|
275
275
|
- **The rule is strict:** `ai/` holds exactly `guide.md` and `recipes/*.json`. No other file, subdir or dotfile — the build and the upload both refuse it.
|
|
276
276
|
- **Recipes are checked at build — but only shallowly.** Every section/block type and setting id must exist, or `pnpm build` fails. Setting values are checked only when a merchant applies the recipe: a select value outside its options, an out-of-range number or a `palette:` ref the shop no longer has makes `apply_recipe` refuse the whole recipe. Keep literal values to the schema's options; leave colours to the theme's defaults.
|
|
277
277
|
- **Optional params drop their line.** The editor tools store a rich-text value with nothing to show as `""` — `<p>{{tagline}}</p>` or `<a href="tel:{{phone}}">{{phone}}</a>` with the param omitted, or `<p> </p>` — so a theme that hides empty rich text drops it. A plain `text` setting, a button label or an FAQ row's question is not emptied for you: make that param required, or check the block renders nothing when it is blank.
|
|
278
|
-
- **Custom sections need a guide section too.** If the theme ships `custom-section` / `custom-block`, `guide.md` says how to style one for this theme: see [custom-sections.md](recipes/custom-sections.md#
|
|
278
|
+
- **Custom sections need a guide section too.** If the theme ships `custom-section` / `custom-block`, `guide.md` says how to style one for this theme, and changes with the theme's CSS variables: see [custom-sections.md](recipes/custom-sections.md#as-the-theme-grows).
|
|
279
279
|
- **Keep it in step with the sections.** Adding, renaming or removing a section or block, or changing a setting the guide names, means editing `guide.md` and any recipe that uses it in the same change.
|
|
280
280
|
|
|
281
281
|
## Building in the editor (Save to source)
|
|
@@ -69,8 +69,8 @@ locales. The `@shop-on/*` packages own the plumbing, and you don't edit them:
|
|
|
69
69
|
|
|
70
70
|
- `@shop-on/theme-routes` — what each route does (load a product, run a search,
|
|
71
71
|
sign a buyer in). Your `src/routes/` files stay thin and call into it.
|
|
72
|
-
- `@shop-on/theme-server` — server-only data loaders
|
|
73
|
-
|
|
72
|
+
- `@shop-on/theme-server` — server-only data loaders on the store's storefront
|
|
73
|
+
API (its typed procedures client), cart, buyer auth.
|
|
74
74
|
- `@shop-on/theme-loader`, `@shop-on/theme-react` — load the right template for
|
|
75
75
|
a request and render it; the editor preview bridge.
|
|
76
76
|
- `@shop-on/theme-runtime` — small pure helpers: money, prices on sale,
|
|
@@ -1,240 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AI-built sections and blocks (custom sections)
|
|
2
2
|
|
|
3
|
-
When no section your theme ships fits what a merchant asks for ("a comparison table", "our three stores with opening hours"), an AI assistant connected to the store can write one. It writes Liquid, the platform validates it, and your theme renders the result.
|
|
3
|
+
When no section your theme ships fits what a merchant asks for ("a comparison table", "our three stores with opening hours"), an AI assistant connected to the store can write one. It writes Liquid, the platform validates it, and your theme renders the result. Two theme-shipped types make that possible:
|
|
4
4
|
|
|
5
5
|
- `sections/custom-section.{json,tsx}`: an AI-built section, a band of its own on the page.
|
|
6
|
-
- `blocks/custom-block.{json,tsx}`: an AI-built block inside a section that lists it (the product page's
|
|
6
|
+
- `blocks/custom-block.{json,tsx}`: an AI-built block inside a section that lists it (the product page's info column, say).
|
|
7
7
|
|
|
8
|
-
Each file is the **capability gate** for its feature
|
|
8
|
+
**The starter ships both, wired.** This recipe is what each piece does and the rules for changing it. Each file is also the **capability gate** for its feature: delete `custom-section` and the theme gets no custom sections; delete `custom-block` and it gets no custom blocks.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## How it works
|
|
11
11
|
|
|
12
|
-
An instance carries a `definition` field next to its `settings`: `{ settings: SchemaSetting[], liquid: string }`. The AI declares its own settings and writes the template. The values sit in the instance's ordinary `settings`, and its CSS goes in `custom_css`.
|
|
12
|
+
An instance carries a `definition` field next to its `settings`: `{ settings: SchemaSetting[], liquid: string }`. The AI declares its own settings and writes the template. The values sit in the instance's ordinary `settings`, and its CSS goes in `custom_css`. The theme never reads `definition`: the render pass turns it into HTML and deletes it before the component renders.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
| Piece | Where |
|
|
15
|
+
| ---------------------------------------------- | --------------------------------------------------------- |
|
|
16
|
+
| Section shell: width + padding settings | `src/sections/custom-section.json` |
|
|
17
|
+
| Draws the finished HTML, or the editor's error | `src/sections/custom-section.tsx` |
|
|
18
|
+
| Block (no settings, no shell) | `src/blocks/custom-block.{json,tsx}` |
|
|
19
|
+
| The render pass | `loadTemplate` in `src/server/settings.ts` |
|
|
20
|
+
| The section that takes custom blocks | `main-product` (`"blocks": [{ "type": "custom-block" }]`) |
|
|
21
|
+
| How the AI should style for this theme | `## Custom sections` in `src/ai/guide.md` |
|
|
15
22
|
|
|
16
|
-
##
|
|
23
|
+
## Rules when you change them
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
- **The section declares only reserved ids.** The contract reserves four, `color_scheme`, `container`, `padding_top` and `padding_bottom` (`BASE_SETTING_IDS`, `@shop-on/theme-contract/custom-section`), and the AI reads them as `settings.<id>`. Any other id on the type could clash with one the AI declares. `custom-section.test.ts` pins the set.
|
|
26
|
+
- **No `presets` on the section.** Without one the type never shows in the merchant's "Add section" picker. The AI adds instances with its own tool, `create_custom_section`. (`theme:check` knows this and doesn't ask for presets.)
|
|
27
|
+
- **Render through `CustomSectionHtml`, never anything else.** Not a bare `dangerouslySetInnerHTML`, and never a Custom HTML snippet that re-activates `<script>` tags: AI-written markup must never run one. `CustomSectionHtml` doesn't activate scripts, and it hands same-origin link clicks to the router, so internal links navigate client-side and keep the editor's preview.
|
|
28
|
+
- **Empty renders nothing.** `customHtml` is `""` when there is nothing to draw, and the section returns `null` so it takes no space. `customError` exists only in editor preview, since the pass writes it only when the request carries an editor `sid`.
|
|
29
|
+
- **The block declares no settings at all**: every setting it has comes from its definition. It has no shell either. The section around it owns width and spacing, and the base ids read as `nil` inside a block.
|
|
30
|
+
- **The pass runs after `runEnrichment`.** The enrichment's last phase re-scans string settings, so rendered HTML has to land after it. If you add a Custom Liquid pass, run this one after that too. Keep the `import()` dynamic, so liquidjs stays out of the client bundle. A page with no custom section loads neither liquidjs nor the validator.
|
|
31
|
+
- **`localizePath` only takes a locale the shop serves.** `req.locale` is server-fn input, and a crafted one would turn a site path into another host's (`//evil.example/…`). That's what the `isValidLocale` guard is for.
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
"name": "t:sections.custom_section",
|
|
23
|
-
"tag": "section",
|
|
24
|
-
"settings": [
|
|
25
|
-
{
|
|
26
|
-
"type": "color_scheme",
|
|
27
|
-
"id": "color_scheme",
|
|
28
|
-
"label": "t:settings.color_scheme",
|
|
29
|
-
"default": "scheme_1"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"type": "select",
|
|
33
|
-
"id": "container",
|
|
34
|
-
"label": "t:settings.content_width",
|
|
35
|
-
"options": [
|
|
36
|
-
{ "value": "small", "label": "t:content_width_options.small" },
|
|
37
|
-
{ "value": "medium", "label": "t:content_width_options.medium" },
|
|
38
|
-
{ "value": "large", "label": "t:content_width_options.large" },
|
|
39
|
-
{ "value": "page", "label": "t:content_width_options.page" },
|
|
40
|
-
{ "value": "full", "label": "t:content_width_options.full" }
|
|
41
|
-
],
|
|
42
|
-
"default": "page"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"type": "range",
|
|
46
|
-
"id": "padding_top",
|
|
47
|
-
"label": "t:settings.padding_top",
|
|
48
|
-
"min": 0,
|
|
49
|
-
"max": 100,
|
|
50
|
-
"step": 4,
|
|
51
|
-
"unit": "px",
|
|
52
|
-
"default": 0
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"type": "range",
|
|
56
|
-
"id": "padding_bottom",
|
|
57
|
-
"label": "t:settings.padding_bottom",
|
|
58
|
-
"min": 0,
|
|
59
|
-
"max": 100,
|
|
60
|
-
"step": 4,
|
|
61
|
-
"unit": "px",
|
|
62
|
-
"default": 0
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
```
|
|
33
|
+
## As the theme grows
|
|
67
34
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
import schema from "./custom-section.json";
|
|
74
|
-
|
|
75
|
-
it("declares exactly the base settings the custom-section contract reserves", () => {
|
|
76
|
-
const ids = schema.settings.flatMap((s) => ("id" in s ? [s.id] : []));
|
|
77
|
-
expect(ids.toSorted()).toEqual(BASE_SETTING_IDS.toSorted());
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## 2. The section component
|
|
82
|
-
|
|
83
|
-
The pass hands you two strings: `customHtml` (the finished markup, `""` when there is nothing to draw) and `customError` (editor preview only, since the pass writes it only when the request carries an editor `sid`). Draw the HTML through `CustomSectionHtml`:
|
|
84
|
-
|
|
85
|
-
```tsx
|
|
86
|
-
import { useTranslations } from "@shop-on/i18n";
|
|
87
|
-
import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
|
|
88
|
-
|
|
89
|
-
const WIDTHS: Record<string, string> = { small: "44rem", medium: "60rem", large: "78rem" };
|
|
90
|
-
|
|
91
|
-
export default function CustomSectionSection({
|
|
92
|
-
sectionId,
|
|
93
|
-
color_scheme = "scheme_1",
|
|
94
|
-
customHtml = null,
|
|
95
|
-
customError = null,
|
|
96
|
-
container = "page",
|
|
97
|
-
padding_top = 0,
|
|
98
|
-
padding_bottom = 0,
|
|
99
|
-
}: {
|
|
100
|
-
sectionId?: string;
|
|
101
|
-
color_scheme?: string | null;
|
|
102
|
-
customHtml?: string | null;
|
|
103
|
-
customError?: string | null;
|
|
104
|
-
container?: string | null;
|
|
105
|
-
padding_top?: number | null;
|
|
106
|
-
padding_bottom?: number | null;
|
|
107
|
-
}) {
|
|
108
|
-
const t = useTranslations("custom_section");
|
|
109
|
-
if (!customError && !customHtml?.trim()) return null;
|
|
110
|
-
|
|
111
|
-
const measure = WIDTHS[container ?? "page"];
|
|
112
|
-
const body = customError ? (
|
|
113
|
-
<p className="border p-4">
|
|
114
|
-
{t("error")}: {customError}
|
|
115
|
-
</p>
|
|
116
|
-
) : (
|
|
117
|
-
<CustomSectionHtml html={customHtml ?? ""} />
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<section
|
|
122
|
-
data-section-id={sectionId}
|
|
123
|
-
data-color-scheme={color_scheme ?? undefined}
|
|
124
|
-
className="bg-background text-foreground"
|
|
125
|
-
style={{ paddingTop: `${padding_top ?? 0}px`, paddingBottom: `${padding_bottom ?? 0}px` }}
|
|
126
|
-
>
|
|
127
|
-
<div className={container === "full" ? undefined : "mx-auto max-w-6xl px-6"}>
|
|
128
|
-
{measure ? (
|
|
129
|
-
<div className="mx-auto w-full" style={{ maxWidth: measure }}>
|
|
130
|
-
{body}
|
|
131
|
-
</div>
|
|
132
|
-
) : (
|
|
133
|
-
body
|
|
134
|
-
)}
|
|
135
|
-
</div>
|
|
136
|
-
</section>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
- **Never render `customHtml` through your Custom HTML snippet** or with a bare `dangerouslySetInnerHTML`. The Custom HTML snippet re-activates `<script>` tags, and AI-written markup must never run one. `CustomSectionHtml` doesn't activate scripts, and it hands same-origin link clicks to the router, so internal links navigate client-side and keep the editor's preview.
|
|
142
|
-
- **Empty renders nothing**, as `custom-liquid` does. A section with no output takes no space on the page.
|
|
143
|
-
- Map `container` onto your own width vocabulary. `page` is your theme container (the starter's is `mx-auto max-w-6xl px-6`) and `full` is edge to edge.
|
|
144
|
-
- Keep `color_scheme` even if your theme has no color schemes yet: the id is reserved, and the AI reads it. Put the value on `data-color-scheme` so your scheme CSS applies once you add some.
|
|
145
|
-
|
|
146
|
-
## 3. Run the pass in `enrich()`
|
|
147
|
-
|
|
148
|
-
In `src/server/settings.ts`, after `runEnrichment` (and after the Custom Liquid pass, if your theme has one), call `renderCustomSections`. The enrichment's last phase re-scans string settings, so rendered HTML has to land after it. Import it dynamically, as the other loaders are, so liquidjs stays out of the client bundle:
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
import { isValidLocale } from "@/src/lib/i18n"; // top of the file
|
|
152
|
-
|
|
153
|
-
// inside enrich():
|
|
154
|
-
const [{ renderCustomSections }] = await Promise.all([
|
|
155
|
-
import("@shop-on/theme-loader/custom-sections"),
|
|
156
|
-
// …your other dynamic imports
|
|
157
|
-
]);
|
|
158
|
-
await runEnrichment(loaderConfig, template, enrichAdapter, req);
|
|
159
|
-
|
|
160
|
-
// Only a locale the shop serves may prefix a path: `req.locale` is server-fn
|
|
161
|
-
// input, and a crafted one would turn a site path into another host's.
|
|
162
|
-
const pathLocale = isValidLocale(req.locale) ? req.locale : undefined;
|
|
163
|
-
await renderCustomSections(loaderConfig, template, {
|
|
164
|
-
sid: req.sid,
|
|
165
|
-
locale: req.locale,
|
|
166
|
-
// If your TemplateRequest carries them (the starter's carries only sid + locale):
|
|
167
|
-
// product: req.product, // the route product, product pages only
|
|
168
|
-
// getCollection: req.getCollection, // the route collection, lazily, collection pages only
|
|
169
|
-
localizePath: (path) => (pathLocale ? `/${pathLocale}${path === "/" ? "" : path}` : path),
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
- `product` and `getCollection` are optional. Without them, the template's `product` / `collection` drops are `nil` on the route page, but pickers the AI declared still resolve. Pass them once your product and collection routes load the route resource through `settings.ts` (see [dynamic-sources.md](dynamic-sources.md)).
|
|
174
|
-
- `localizePath` gives the template's `link_url` the request's locale prefix, so a crawler and a no-JS load get the right address. Leave it out and links stay unprefixed until clicked.
|
|
175
|
-
- A page with no enabled custom section loads neither liquidjs nor the validator, so the call costs nothing elsewhere.
|
|
176
|
-
|
|
177
|
-
## 4. Custom blocks (optional)
|
|
178
|
-
|
|
179
|
-
`src/blocks/custom-block.json` declares **no settings**: every setting a block has is one its definition declares, and a type-level id could clash with one.
|
|
180
|
-
|
|
181
|
-
```json
|
|
182
|
-
{ "name": "t:blocks.custom_block", "settings": [] }
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
The component draws `customHtml` with no shell of its own. The section around it owns the scheme, width and spacing:
|
|
186
|
-
|
|
187
|
-
```tsx
|
|
188
|
-
import { useTranslations } from "@shop-on/i18n";
|
|
189
|
-
import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
|
|
190
|
-
|
|
191
|
-
export default function CustomBlock({
|
|
192
|
-
customHtml = null,
|
|
193
|
-
customError = null,
|
|
194
|
-
}: {
|
|
195
|
-
customHtml?: string | null;
|
|
196
|
-
customError?: string | null;
|
|
197
|
-
}) {
|
|
198
|
-
const t = useTranslations("custom_section");
|
|
199
|
-
if (customError)
|
|
200
|
-
return (
|
|
201
|
-
<p className="border p-4">
|
|
202
|
-
{t("block_error")}: {customError}
|
|
203
|
-
</p>
|
|
204
|
-
);
|
|
205
|
-
return <CustomSectionHtml html={customHtml ?? ""} />;
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Then **list it** in the `blocks` of each section that should take one, typically `main-product`: `{ "type": "custom-block" }`. A container block can list it too. `create_custom_block` refuses any section that doesn't.
|
|
210
|
-
|
|
211
|
-
**Drop empty ones from your spacing.** An AI block that rendered nothing still sits in `blocks`. If the section wraps each block in a row with a gap, skip it with `hasCustomOutput`, or it opens an empty gap:
|
|
212
|
-
|
|
213
|
-
```tsx
|
|
214
|
-
import { hasCustomOutput } from "@shop-on/theme-react/custom-section-html";
|
|
215
|
-
|
|
216
|
-
const visible = blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings));
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## 5. Locales
|
|
220
|
-
|
|
221
|
-
Add the display names and the editor-only error labels, in every catalog you ship:
|
|
222
|
-
|
|
223
|
-
- `*.schema.json`: `sections.custom_section` ("AI-built section") and `blocks.custom_block` ("AI-built block").
|
|
224
|
-
- `*.json`: `custom_section.error` ("Section error") and `custom_section.block_error` ("Block error").
|
|
225
|
-
- `*.schema.json`, if your catalog lacks them: the labels the section schema names, `settings.color_scheme`, `settings.content_width`, `settings.padding_top`, `settings.padding_bottom` and `content_width_options.{small,medium,large,page,full}`. A fresh starter has none of them.
|
|
226
|
-
|
|
227
|
-
`pnpm theme:check` lists any key still missing.
|
|
228
|
-
|
|
229
|
-
## 6. Tell the AI how to style for your theme
|
|
230
|
-
|
|
231
|
-
The AI's markup can't use your Tailwind classes: Tailwind emits only the classes it finds in your source, and the AI's HTML isn't in it. It writes plain CSS into `custom_css`. Add a `## Custom sections` section to `src/ai/guide.md` that says:
|
|
232
|
-
|
|
233
|
-
- which CSS variables to use for color (the starter's are `--color-background`, `--color-foreground`, `--color-muted`, `--color-border`, `--color-accent` and `--color-accent-foreground`; name the ones that follow the color scheme, if you have schemes), plus your font and spacing variables;
|
|
234
|
-
- that the shell already provides background, width and padding, so its markup needs no outer background or page margins;
|
|
235
|
-
- your root font size, if `1rem` isn't 16px;
|
|
236
|
-
- when to build one: only when no section you ship does the job, after checking their settings and blocks;
|
|
237
|
-
- for blocks, which sections take one, and to keep them compact with no outer padding or background.
|
|
35
|
+
- **Adding color schemes:** the starter's section leaves out `color_scheme`, because with no schemes its picker would do nothing. When you add a `color_scheme_group` to the theme settings, add a `color_scheme` setting to `custom-section.json`, put its value on `data-color-scheme` on the section root, add the `settings.color_scheme` label to every schema catalog, and switch `custom-section.test.ts` to expect all four ids. Then tell the guide which CSS variables follow the scheme.
|
|
36
|
+
- **Loading the route product or collection in `settings.ts`:** pass `product` (the `ProductData`) and `getCollection` (a lazy provider) to `renderCustomSections`. Until you do, the template's `product` / `collection` drops are `nil` on those pages, but pickers the AI declared still resolve. See [dynamic-sources.md](dynamic-sources.md) for loading the route resource.
|
|
37
|
+
- **Letting another section take custom blocks:** add `{ "type": "custom-block" }` to its `blocks`. A container block can list it too. `create_custom_block` refuses any section that doesn't.
|
|
38
|
+
- **Drop empty blocks from your spacing.** An AI block that rendered nothing still sits in `blocks`. A section that wraps each block in a spaced row has to skip it, or it opens an empty gap. `main-product` shows how: `blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings))`, with `hasCustomOutput` from `@shop-on/theme-react/custom-section-html`.
|
|
39
|
+
- **Restyling the theme:** keep the guide's `## Custom sections` honest. The AI's HTML renders inside your page, so your stylesheet applies, and the AI is told to use the classes and CSS variables the guide names. Name your own heading, text and button classes there (`.button`, `.h2`: classes your stylesheet defines outright), and say whether plain `h1`–`h6` are styled (Tailwind's preflight resets them unless your base styles put them back). Don't name Tailwind utilities: Tailwind emits only the ones your own source uses, so the rest don't exist. Everything else the AI writes as plain CSS in `custom_css` against the variables the guide names. Rename a class or variable, and the guide changes in the same commit. Also tell it your root font size if `1rem` isn't 16px.
|
|
238
40
|
|
|
239
41
|
## What the AI can and can't do
|
|
240
42
|
|
|
@@ -50,7 +50,8 @@ rides inside theme-server.
|
|
|
50
50
|
5. **Cart adapter** — read the customer token via `readCustomerSession()`;
|
|
51
51
|
`resolveCart` branches anonymous-read vs `resolveCartForCustomer`;
|
|
52
52
|
cookie-less adds go through `mintOrClaimCart({session, customerToken})`
|
|
53
|
-
(handles anonymous too)
|
|
53
|
+
(handles anonymous too). The cart's own ops (`cart-mutations`) take only the
|
|
54
|
+
cart token: the api's cart has no customer link until buyer sign-in.
|
|
54
55
|
Checkout: the `/checkout` route reads `checkout_state` in `validateSearch`
|
|
55
56
|
and passes it to `startCheckoutHandoff({ state, customerToken })` (`state`
|
|
56
57
|
is a required key). Without a state it returns checkout's `/begin`, which
|
|
@@ -39,12 +39,12 @@ The shared fetchers in `@shop-on/theme-server` are a published API with a compat
|
|
|
39
39
|
|
|
40
40
|
## Writing a new loader
|
|
41
41
|
|
|
42
|
-
**
|
|
42
|
+
**Build on a loader, don't re-map its answer.** The theme reads the api only through `@shop-on/theme-server`'s loaders (`/product`, `/collection`, `/search`, `/page`, `/menu`, …): each calls the api's storefront procedures through a typed client and maps the answer to the shapes the theme renders (`ProductData`, `CollectionData`, …) once. Before writing a new mapping, check whether a loader already returns the shape. Re-mapped copies of one shape drift apart silently (a search card missing `tags` draws no badges its collection page draws). Narrow a loader with its own arguments (`first`, `mediaFirst`, `includeOptions`) rather than trimming its answer after the fact.
|
|
43
43
|
|
|
44
44
|
**Catch the failure OUTSIDE `memoTTL`, not inside the memoized function.** `memoTTL` (`@shop-on/theme-server/cache`) never caches a rejection, which is the whole mechanism for "don't pin a transient 500 for a TTL". A `try/catch` inside the wrapped function defeats it: the failure is flattened into the same `[]` / `null` an empty-but-successful read returns, and no `shouldCache` predicate can tell them apart afterwards. Guarding with `shouldCache: (v) => v.length > 0` then makes the _legitimately empty_ answer uncacheable — a new shop with nothing published re-queries on every render, forever. Let the memoized function throw and wrap the exported one:
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
|
-
const loadThing = memoTTL(async (…) => { const res = await
|
|
47
|
+
const loadThing = memoTTL(async (…) => { const res = await fetchUpstream(…); return map(res); }, { key, version: getContentVersion });
|
|
48
48
|
|
|
49
49
|
export async function fetchThing(…) {
|
|
50
50
|
try {
|
|
@@ -402,14 +402,13 @@ Product-review pickers, for social-proof surfaces that feature hand-picked revie
|
|
|
402
402
|
{ "type": "review_list", "id": "reviews", "label": "t:settings.reviews", "limit": 6 }
|
|
403
403
|
```
|
|
404
404
|
|
|
405
|
-
- **Value:** `string` (review
|
|
406
|
-
- **Sibling prop:** `reviewData:
|
|
405
|
+
- **Value:** `string` (review id, `review_…`) / `string[]` (review ids). Reviews have no handle
|
|
406
|
+
- **Sibling prop:** `reviewData: ReviewCardData | null` / `reviewsData: ReviewCardData[]` (from `@shop-on/theme-server/review`) — `{ id, rating, title, body, authorName, verifiedBuyer, createdAt, answers[], reply, product: { id, handle, title, url, image } }`. No votes and no buyer photos
|
|
407
407
|
- **Single keeps null, list drops.** An unpublished / deleted pick leaves `reviewData` null (the section decides its fallback); in a list it's dropped, so a grid never null-guards per entry — same contract as `metaobject_list`
|
|
408
408
|
- **`limit` defaults to and caps at 50**
|
|
409
|
-
- **No defaults** — review
|
|
409
|
+
- **No defaults** — review ids are tenant-specific
|
|
410
410
|
- **`body` is plain text, not HTML.** Render as text; never `dangerouslySetInnerHTML`
|
|
411
|
-
- **
|
|
412
|
-
- **No viewer-dependent fields.** `mine` / `myVote` / `pending` are deliberately absent — the loader result is memoized shop-wide, so caching them would leak one buyer's vote state to everyone
|
|
411
|
+
- **A picked review carries its product** (`product.url` links to it); the api only answers reviews of live products, so there is no status to check
|
|
413
412
|
- **No id allowlist:** any setting declared `review` / `review_list` in a section or block schema resolves, under whatever id you give it
|
|
414
413
|
- Not dynamic-source bindable — there's no review metafield reference type
|
|
415
414
|
|
|
@@ -526,7 +525,7 @@ Hide a setting based on a sibling's value:
|
|
|
526
525
|
- Evaluated by the editor as a small subset of Liquid: `==` / `!=` against a quoted literal or `blank`, `<` `<=` `>` `>=` on numbers, a bare `settings.<id>` for truthiness, `and` / `or`, and parentheses.
|
|
527
526
|
- **`and` / `or` read right to left, like Liquid, with no precedence:** `a and b or c` is `a and (b or c)`. When you mean `(a and b) or c`, write the parentheses.
|
|
528
527
|
- **An unsaved setting reads as its schema `default`**, as it renders on the storefront. So a checkbox that defaults on gates its dependents with a bare `{{ settings.show_x }}` (or `== true`), and they still show on an instance that never saved it.
|
|
529
|
-
- **Gate a field only when it does nothing**: a hidden field that still worked is a setting the merchant can no longer reach.
|
|
528
|
+
- **Gate a field only when it does nothing**: a hidden field that still worked is a setting the merchant can no longer reach. A `!= blank` gate on a picker also hides its dependents while the picker is bound to a dynamic source, because a binding is not stored in `settings`.
|
|
530
529
|
|
|
531
530
|
---
|
|
532
531
|
|
|
@@ -105,7 +105,7 @@ Plain `.ts` helpers (no JSX, not a component) cannot call the hook either: have
|
|
|
105
105
|
This starter ships all four pieces already; they are listed so you know where each lives:
|
|
106
106
|
|
|
107
107
|
1. `src/locales/<locale>.default.json` per declared locale.
|
|
108
|
-
2. `src/server/i18n.server.ts` — `getMessagesForLocale`,
|
|
108
|
+
2. `src/server/i18n.server.ts` — `getMessagesForLocale`, laying the merchant's `strings` rows over the shipped catalog with `themeStrings` from `@shop-on/theme-server/translations` (this is what makes admin → Translations able to override the theme's own copy).
|
|
109
109
|
3. `src/server/i18n.ts` — a `createServerFn` wrapper, so the `node:*`/env-reading module stays out of the client bundle.
|
|
110
110
|
4. `__root.tsx` — fetch it in the loader (pass the **display** locale, `getCurrentLocale()`, not `getContentLocale()`) and wrap the shell in `<IntlProvider locale messages timeZone>`.
|
|
111
111
|
|
|
@@ -24,8 +24,8 @@ The sibling is always the setting's own `id` plus `Data`, verbatim.
|
|
|
24
24
|
| `article` | `article` | `articleData` |
|
|
25
25
|
| `metaobject` | `author` | `authorData: MetaobjectData \| null` |
|
|
26
26
|
| `metaobject_list` | `authors` | `authorsData: MetaobjectData[]` |
|
|
27
|
-
| `review` | `review` | `reviewData:
|
|
28
|
-
| `review_list` | `reviews` | `reviewsData:
|
|
27
|
+
| `review` | `review` | `reviewData: ReviewCardData \| null` |
|
|
28
|
+
| `review_list` | `reviews` | `reviewsData: ReviewCardData[]` |
|
|
29
29
|
|
|
30
30
|
Every one of these resolves at **both** section and block scope, including a container block's children.
|
|
31
31
|
|
package/template/.env.example
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
# Your store's storefront
|
|
1
|
+
# Your store's storefront key (`shop-on theme init` writes all of this).
|
|
2
2
|
STOREFRONT_API_URL=
|
|
3
|
-
|
|
4
|
-
STOREFRONT_CLIENT_SECRET=
|
|
3
|
+
STOREFRONT_KEY=
|
|
5
4
|
STORE_SLUG=
|
|
6
5
|
|
|
7
6
|
# Signs the buyer session cookies the theme sets. Any random value:
|
package/template/.oxfmtrc.json
CHANGED
package/template/package.json
CHANGED
|
@@ -17,37 +17,36 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@bprogress/core": "1.3.4",
|
|
20
|
-
"@shop-on/i18n": "^0.
|
|
21
|
-
"@shop-on/theme-contract": "^0.
|
|
22
|
-
"@shop-on/theme-loader": "^0.
|
|
23
|
-
"@shop-on/theme-react": "^0.
|
|
24
|
-
"@shop-on/theme-routes": "^0.
|
|
25
|
-
"@shop-on/theme-runtime": "^0.
|
|
26
|
-
"@shop-on/theme-server": "^0.
|
|
27
|
-
"@shop-on/theme-system": "^0.
|
|
28
|
-
"@tailwindcss/vite": "4.3.
|
|
29
|
-
"@tanstack/react-router": "1.170.
|
|
30
|
-
"@tanstack/react-start": "1.169.
|
|
31
|
-
"dotenv": "18.0.
|
|
32
|
-
"nitro": "3.0.
|
|
20
|
+
"@shop-on/i18n": "^0.11.0",
|
|
21
|
+
"@shop-on/theme-contract": "^0.11.0",
|
|
22
|
+
"@shop-on/theme-loader": "^0.11.0",
|
|
23
|
+
"@shop-on/theme-react": "^0.11.0",
|
|
24
|
+
"@shop-on/theme-routes": "^0.11.0",
|
|
25
|
+
"@shop-on/theme-runtime": "^0.11.0",
|
|
26
|
+
"@shop-on/theme-server": "^0.11.0",
|
|
27
|
+
"@shop-on/theme-system": "^0.11.0",
|
|
28
|
+
"@tailwindcss/vite": "4.3.5",
|
|
29
|
+
"@tanstack/react-router": "1.170.46",
|
|
30
|
+
"@tanstack/react-start": "1.169.5",
|
|
31
|
+
"dotenv": "18.0.10",
|
|
32
|
+
"nitro": "3.0.261103-rc",
|
|
33
33
|
"react": "19.3.1",
|
|
34
34
|
"react-dom": "19.3.1",
|
|
35
|
-
"tailwindcss": "4.3.
|
|
35
|
+
"tailwindcss": "4.3.5"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@shop-on/theme-config": "^0.
|
|
39
|
-
"@shop-on/theme-dev-host": "^0.
|
|
38
|
+
"@shop-on/theme-config": "^0.11.0",
|
|
39
|
+
"@shop-on/theme-dev-host": "^0.11.0",
|
|
40
40
|
"@spiriit/vite-plugin-svg-spritemap": "7.2.0",
|
|
41
|
-
"@types/node": "26.6.
|
|
41
|
+
"@types/node": "26.6.6",
|
|
42
42
|
"@types/react": "19.3.0",
|
|
43
43
|
"@types/react-dom": "19.3.0",
|
|
44
|
-
"@vitejs/plugin-react": "6.
|
|
45
|
-
"gql.tada": "1.11.4",
|
|
44
|
+
"@vitejs/plugin-react": "6.3.0",
|
|
46
45
|
"happy-dom": "21.0.4",
|
|
47
|
-
"oxfmt": "^0.
|
|
46
|
+
"oxfmt": "^0.78.0",
|
|
48
47
|
"tsx": "^4.23.15",
|
|
49
48
|
"typescript": "7.0.2",
|
|
50
|
-
"vite": "8.3.
|
|
51
|
-
"vitest": "5.0
|
|
49
|
+
"vite": "8.3.8",
|
|
50
|
+
"vitest": "5.1.0"
|
|
52
51
|
}
|
|
53
52
|
}
|
package/template/src/ai/guide.md
CHANGED
|
@@ -22,6 +22,31 @@ one they won't reach for.
|
|
|
22
22
|
(`cta_label`, `cta_url`). Keep the headline short; leave the button out
|
|
23
23
|
rather than pointing it nowhere.
|
|
24
24
|
|
|
25
|
+
## Custom sections
|
|
26
|
+
|
|
27
|
+
Build a custom section only when no section above can do the job, after
|
|
28
|
+
checking their settings. Its width (`container`: small, medium, large, page or
|
|
29
|
+
full) and padding come from the theme, so its own markup needs no outer
|
|
30
|
+
background or page margins.
|
|
31
|
+
|
|
32
|
+
The theme's utility classes don't exist inside it: write plain CSS in the
|
|
33
|
+
section's CSS against these variables:
|
|
34
|
+
|
|
35
|
+
- Colors: `--color-background`, `--color-foreground` (text), `--color-muted`
|
|
36
|
+
(secondary text), `--color-border` (hairlines), `--color-accent` (buttons
|
|
37
|
+
and links) and `--color-accent-foreground` (text on the accent).
|
|
38
|
+
|
|
39
|
+
Use the variables rather than fixed colors, so the section follows the theme
|
|
40
|
+
when its palette changes.
|
|
41
|
+
|
|
42
|
+
## Custom blocks
|
|
43
|
+
|
|
44
|
+
For content that belongs in the product page's info column rather than as its
|
|
45
|
+
own band (a delivery note, a size hint, a trust badge), build a custom block
|
|
46
|
+
with `create_custom_block` in `main-product`, the one section that takes one.
|
|
47
|
+
It follows the CSS rules above, but the section around it owns the width and
|
|
48
|
+
spacing: keep it compact, with no outer padding or background of its own.
|
|
49
|
+
|
|
25
50
|
## What to avoid
|
|
26
51
|
|
|
27
52
|
- Don't stack two `hero` sections.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import mainProduct from "../sections/main-product.json";
|
|
3
|
+
import schema from "./custom-block.json";
|
|
4
|
+
|
|
5
|
+
// A custom block's settings are the ones its `definition` declares, and a
|
|
6
|
+
// declared id may not repeat one of the type's: any setting here could clash
|
|
7
|
+
// with a declared one.
|
|
8
|
+
it("declares no settings of its own", () => {
|
|
9
|
+
expect(schema.settings).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// The case for custom blocks: AI-written content in the product page's info
|
|
13
|
+
// column. `create_custom_block` refuses a section that doesn't list the type.
|
|
14
|
+
it("is one of the blocks the product information section takes", () => {
|
|
15
|
+
expect(mainProduct.blocks.map((b) => b.type)).toContain("custom-block");
|
|
16
|
+
});
|