create-znode-plugin 0.2.1 → 0.2.2

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.
Files changed (33) hide show
  1. package/README.md +10 -5
  2. package/package.json +1 -1
  3. package/template/theme/README.md +56 -7
  4. package/template/theme/package.json +1 -1
  5. package/template/theme/src/agents/index.ts +5 -0
  6. package/template/theme/src/api/highlights/route.ts +7 -0
  7. package/template/theme/src/api/index.ts +9 -0
  8. package/template/theme/src/api/store/index.ts +6 -0
  9. package/template/theme/src/browser.tsx +11 -18
  10. package/template/theme/src/components/client/layout/AnnouncementBar.tsx +17 -0
  11. package/template/theme/src/components/client/product/ProductBadge.tsx +13 -0
  12. package/template/theme/src/{server → components/server/layout}/ThemeLayout.tsx +2 -2
  13. package/template/theme/src/{server → components/server/welcome}/WelcomePage.tsx +2 -2
  14. package/template/theme/src/constants/index.ts +5 -0
  15. package/template/theme/src/messages/fr-FR.json +1 -0
  16. package/template/theme/src/pages/index.ts +9 -0
  17. package/template/theme/src/pages/welcome/page.tsx +13 -0
  18. package/template/theme/src/server.tsx +20 -23
  19. package/template/theme/src/slots/index.ts +13 -0
  20. package/template/theme/src/slots/layout-header/index.tsx +9 -0
  21. package/template/theme/src/slots/product-card/index.tsx +14 -0
  22. package/template/theme/src/slots/server/index.ts +9 -0
  23. package/template/theme/src/slots/server/layout-root/index.tsx +9 -0
  24. package/template/theme/src/utils/index.ts +5 -0
  25. package/template/theme/src/widgets/hero/index.ts +4 -0
  26. package/template/theme/src/widgets/index.ts +9 -0
  27. package/template/theme/znode-package.json +2 -1
  28. package/template/theme/src/slots/AnnouncementBar.tsx +0 -19
  29. package/template/theme/src/slots/ProductBadge.tsx +0 -17
  30. /package/template/theme/src/{server → lib}/fonts.ts +0 -0
  31. /package/template/theme/src/{server/data.ts → lib/server/highlights.ts} +0 -0
  32. /package/template/theme/src/{i18n/labels.json → messages/en-US.json} +0 -0
  33. /package/template/theme/src/widgets/{Hero.tsx → hero/Hero.tsx} +0 -0
package/README.md CHANGED
@@ -162,13 +162,18 @@ first (see [Versions](https://www.npmjs.com/package/znode-plugin#versions)); the
162
162
  ```
163
163
  my-theme/
164
164
  znode-package.json name, version, kind "theme", settings, server pages
165
- src/browser.tsx slots (wrap or replace parts of the store) and page-builder widgets
166
- src/server.tsx layouts around pages, whole pages at new URLs, API routes
167
- src/slots/ AnnouncementBar (layout.header), ProductBadge (product.card)
165
+ src/browser.tsx links the browser part: slots, widgets, utils, constants
166
+ src/server.tsx links the server part: server slots, pages, API routes, agents
167
+ src/components/client/ UI the browser part renders: AnnouncementBar, ProductBadge
168
+ src/components/server/ UI the server part renders: ThemeLayout, WelcomePage
169
+ src/slots/ slot adapters: layout.header, product.card; slots/server/: layout.root
170
+ src/pages/ pages at new URLs (/my-theme-welcome) and store pages you take over
171
+ src/api/ your API (highlights); api/store/: store API routes you take over
172
+ src/agents/ store agents you answer
168
173
  src/widgets/ a Hero widget for the page builder
169
- src/server/ ThemeLayout (layout.root), WelcomePage (/my-theme-welcome)
174
+ src/lib/ your own helpers (settings, fonts, lib/server/ data access)
170
175
  src/styles/theme.css the theme's styles
171
- src/i18n/labels.json the theme's labels
176
+ src/messages/ the theme's labels, one file per store locale (en-US.json, fr-FR.json)
172
177
  tsconfig.store.json this machine's link to the store's types (git-ignored)
173
178
  znode.local.json this machine's runtime-plugin-store (git-ignored)
174
179
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-znode-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Create a Znode runtime theme project: npm create znode-plugin@latest <name>.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -21,18 +21,67 @@ for the stores it is enabled for: no fork of the store, no webstore rebuild.
21
21
  straight into it: the theme folder keeps no `dist/` or `.build/`. After the first deploy, enable the theme for your
22
22
  stores in its `plugins.json` (`"enabled": true`, `"stores": ["<store code>"]`).
23
23
 
24
+ ## How the project is laid out
25
+
26
+ `src/browser.tsx` and `src/server.tsx` only **link**. Each kind has a **map** (`index.ts`: name -> reference);
27
+ **adapters** (slots, pages, api) only connect the store to a component; **components** hold the UI and its logic, in
28
+ `components/client/` when the browser part renders them and `components/server/` when the server part does.
29
+
30
+ ```
31
+ src/
32
+ browser.tsx links slots, widgets, utils, constants
33
+ server.tsx links serverSlots, serverPages, routes, apiRoutes, agents
34
+
35
+ components/
36
+ client/ rendered by the browser part (hooks, events)
37
+ layout/AnnouncementBar.tsx
38
+ product/ProductBadge.tsx
39
+ server/ rendered by the server part (async, data)
40
+ layout/ThemeLayout.tsx
41
+ welcome/WelcomePage.tsx
42
+ shared/ plain UI both may use (create it when you need it)
43
+
44
+ slots/index.ts "layout.header", "product.card" -> slots/<slot>/index.tsx (adapters)
45
+ slots/server/index.ts "layout.root" -> slots/server/layout-root/index.tsx (adapter)
46
+ pages/index.ts "/__NAME__-welcome" -> pages/welcome/page.tsx
47
+ api/index.ts highlights -> api/highlights/route.ts
48
+ api/store/index.ts (npx znode eject /api/...) -> api/store/<route>/route.ts
49
+ agents/index.ts (npx znode eject <agent>) -> agents/<area>/<fn>.ts
50
+ utils/index.ts (npx znode eject <util>) -> utils/component/...
51
+ constants/index.ts (npx znode eject <CONSTANT>) -> constants/<area>/<NAME>.ts
52
+ widgets/index.ts __PASCAL__Hero -> widgets/hero/
53
+ messages/ en-US.json, fr-FR.json (one per store language)
54
+ lib/ host.ts (settings), fonts.ts, server/highlights.ts (server data access)
55
+ styles/theme.css
56
+ ```
57
+
58
+ It links like this: `browser.tsx` → `slots/index.ts` → `slots/product-card/index.tsx` →
59
+ `components/client/product/ProductBadge.tsx`; `server.tsx` → `pages/index.ts` → `pages/welcome/page.tsx` →
60
+ `components/server/welcome/WelcomePage.tsx`.
61
+
62
+ - An **adapter** turns the store's signature into your component's props: `LayoutRootSlot(props, context)` renders
63
+ `<ThemeLayout settings={context.settings}>`, `ProductCardSlot` works out whether the product is new.
64
+ - `npx znode eject …` writes its copy into the right folder and adds the entry to the right map (a store component goes
65
+ to `components/client/` with its adapter in `slots/<slot>/`; a store page to `pages/<route>/page.tsx`).
66
+ - `npm run check` warns when the browser part imports server code (`components/server`, `pages`, `api`, `agents`,
67
+ `lib/server`), when a component imports the adapter that renders it, and when code imports an override file instead of
68
+ the store's `@znode/...` path.
69
+
24
70
  ## Where each customization goes
25
71
 
26
72
  | You want to | Do it in | Example here |
27
73
  | --- | --- | --- |
28
- | Change colors, fonts, spacing | `src/styles/*.css`, settings, `next/font/google` | `theme.css`, `src/server/fonts.ts` |
29
- | Wrap every page in your layout | Server slot `layout.root` in `src/server.tsx` | `src/server/ThemeLayout.tsx` |
30
- | Add to or replace a store part | A slot in `src/browser.tsx` (names in `znode-plugin/types/extension-api.d.ts`) | `src/slots/AnnouncementBar.tsx`, `src/slots/ProductBadge.tsx` |
31
- | Add a page-builder block | A widget in `src/browser.tsx` and `"widgets"` in `znode-package.json` | `src/widgets/Hero.tsx` |
32
- | Add a page at a new URL | `serverPages` in `src/server.tsx` and `"serverPages"` in `znode-package.json` | `/__NAME__-welcome`, `src/server/WelcomePage.tsx` |
33
- | Add your own API | `routes` in `src/server.tsx` | `GET /api/extensions/plugins/__NAME__/highlights` |
74
+ | Change colors, fonts, spacing | `src/styles/*.css`, settings, `next/font/google` | `theme.css`, `src/lib/fonts.ts` |
75
+ | Wrap every page in your layout | Server slot `layout.root` in `src/slots/server/index.ts` | `src/slots/server/layout-root/index.tsx`, `src/components/server/layout/ThemeLayout.tsx` |
76
+ | Add to or replace a store part | A slot in `src/slots/index.ts` (names: `npx znode slot list`), its UI in `src/components/client/` | `src/slots/product-card/index.tsx`, `src/components/client/product/ProductBadge.tsx` |
77
+ | Take over a store component | `npx znode eject <Component>` | copy in `src/components/client/…`, adapter in `src/slots/<slot>/` |
78
+ | Take over a store page | `npx znode eject <Page>` (e.g. `ForgotPasswordPage`) | `src/pages/<route>/page.tsx` |
79
+ | Add a page-builder block | A widget in `src/widgets/index.ts` and `"widgets"` in `znode-package.json` | `src/widgets/hero/` |
80
+ | Add a page at a new URL | `src/pages/index.ts` and `"serverPages"` in `znode-package.json` | `/__NAME__-welcome`, `src/pages/welcome/page.tsx` |
81
+ | Add your own API | `src/api/index.ts` | `GET /api/extensions/plugins/__NAME__/highlights` (`src/api/highlights/route.ts`) |
82
+ | Change the data behind a store page | `npx znode eject <agent>` | `src/agents/<area>/<fn>.ts` |
34
83
  | Let the merchant configure it | `settingsSchema` in `znode-package.json` | `accentColor`, `announcement`, `showBadge` |
35
- | Change labels | `src/i18n/labels.json` (next-intl namespaces) | `{ "Product": { "addToCart": "Add to bag" } }` |
84
+ | Change labels | `src/messages/en-US.json`, `src/messages/fr-FR.json` (one per store locale, next-intl namespaces) | `{ "Product": { "addToCart": "Add to bag" } }` |
36
85
  | Use the store's components | `import { SearchBox } from "@znode/base-components/…"` in browser parts | needs `npm run link-store` for types |
37
86
 
38
87
  Imports work as in a Next.js app: `next/image`, `next/link`, `next/navigation`, `next/font/google`, `react`. They use
@@ -17,6 +17,6 @@
17
17
  "next": "16.1.6",
18
18
  "react": "19.2.4",
19
19
  "react-dom": "19.2.4",
20
- "znode-plugin": "^0.2.3"
20
+ "znode-plugin": "^0.2.11"
21
21
  }
22
22
  }
@@ -0,0 +1,5 @@
1
+ import type { IStoreAgents } from "znode-plugin/types/extension-api";
2
+
3
+ // The store agents this package answers (server): agent hook name -> function. References only: the copies live in
4
+ // agents/<area>/ (agents/wrap/ for a wrap). npx znode agent list shows the agents; npx znode eject <agent> adds one here.
5
+ export const agents: IStoreAgents = {};
@@ -0,0 +1,7 @@
1
+ import type { IPluginRouteContext, IPluginRouteRequest } from "znode-plugin/types/extension-api";
2
+ import { getHighlights, IHighlight } from "../../lib/server/highlights.js";
3
+
4
+ // GET /api/extensions/plugins/__NAME__/highlights: the store's highlights, as JSON.
5
+ export async function highlights(_request: IPluginRouteRequest, context: IPluginRouteContext): Promise<{ store: string; items: IHighlight[] }> {
6
+ return { store: context.store.code, items: await getHighlights(context.store.code) };
7
+ }
@@ -0,0 +1,9 @@
1
+ import type { IPluginRoutes } from "znode-plugin/types/extension-api";
2
+ import { highlights } from "./highlights/route.js";
3
+
4
+ // This package's API routes (/api/extensions/plugins/__NAME__/<name>): name -> handler. References only: each handler
5
+ // lives in api/<name>/route.ts, its data access in lib/server/. Needs "permissions": ["routes"]. A store API route taken
6
+ // over with npx znode eject /api/... goes to api/store/ instead.
7
+ export const routes: IPluginRoutes = {
8
+ highlights,
9
+ };
@@ -0,0 +1,6 @@
1
+ import type { IStoreApiRoutes } from "znode-plugin/types/extension-api";
2
+
3
+ // The store's own API routes this package answers (server): route hook name -> its handlers (GET, POST, ...). References
4
+ // only: each copy lives in api/store/<route>/route.ts. npx znode route list shows the routes; npx znode eject /api/...
5
+ // adds one here. Needs "permissions": ["storeRoutes"] (eject adds it).
6
+ export const apiRoutes: IStoreApiRoutes = {};
@@ -1,26 +1,19 @@
1
1
  import type { IBrowserHost, IBrowserPlugin } from "znode-plugin/types/extension-api";
2
2
  import { bindHost } from "./lib/host.js";
3
- import { AnnouncementBar } from "./slots/AnnouncementBar.js";
4
- import { ProductBadge } from "./slots/ProductBadge.js";
5
- import { Hero, HERO_EDITOR } from "./widgets/Hero.js";
3
+ import { slots } from "./slots/index.js";
4
+ import { widgets } from "./widgets/index.js";
5
+ import { utils } from "./utils/index.js";
6
+ import { constants } from "./constants/index.js";
6
7
 
7
8
  // __LABEL__, browser part: what renders in the store's pages (on the server first, then hydrated in the browser).
8
- // Slots: wrap or replace a part of the store; the component gets the slot's props, and the store's own rendering as
9
- // children (keep it, add to it, or replace it). Slot names: znode-plugin/types/extension-api.d.ts.
10
- // Widgets: blocks for the page builder, with their settings.
11
- // Server parts (layouts around pages, whole pages, API routes): server.tsx.
9
+ // This file only links: each kind has its map (slots/, widgets/, utils/, constants/ index.ts: name -> reference), and
10
+ // the code lives in the folders next to it. Keep logic out of here.
11
+ // slots: wrap or replace a part of the store (the component gets the slot's props and the store's own rendering)
12
+ // widgets: blocks for the page builder, with their settings
13
+ // utils: store helper functions this package answers; constants: store values it changes
14
+ // Server parts (layouts around pages, whole pages, API routes, agents): server.tsx.
12
15
 
13
16
  export default function setup(host: IBrowserHost): IBrowserPlugin {
14
17
  bindHost(host);
15
- return {
16
- slots: {
17
- // an announcement bar above the store's header
18
- "layout.header": AnnouncementBar,
19
- // a New badge on product cards
20
- "product.card": ProductBadge,
21
- },
22
- widgets: {
23
- __PASCAL__Hero: { render: Hero, ...HERO_EDITOR },
24
- },
25
- };
18
+ return { slots, widgets, utils, constants };
26
19
  }
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ // A bar above the store's header (children) with a short text. Plain UI: it knows nothing about slots or settings; the
4
+ // slot layout.header (slots/layout-header/index.tsx) passes the text. No text: the store's header as it is.
5
+
6
+ export function AnnouncementBar(props: { text?: string; children?: ReactNode }) {
7
+ return (
8
+ <>
9
+ {props.text && (
10
+ <div className="__NAME__-announcement" data-test-selector="divAnnouncement">
11
+ {props.text}
12
+ </div>
13
+ )}
14
+ {props.children}
15
+ </>
16
+ );
17
+ }
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ // A New badge on a product card (children). Plain UI: the slot product.card (slots/product-card/index.tsx) decides
4
+ // whether the product is new and whether badges are on.
5
+
6
+ export function ProductBadge(props: { show?: boolean; children?: ReactNode }) {
7
+ return (
8
+ <div className="__NAME__-card">
9
+ {props.show && <span className="__NAME__-badge">New</span>}
10
+ {props.children}
11
+ </div>
12
+ );
13
+ }
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode } from "react";
2
- import { inter } from "./fonts.js";
2
+ import { inter } from "../../../lib/fonts.js";
3
3
 
4
- // Server slot layout.root: every store page, header to footer (children), in the theme's font and accent color. The
4
+ // The theme layout around every store page, header to footer (children), in the theme's font and accent color. The
5
5
  // store's body is a flex column whose main area grows, so this wrapper grows too and the footer stays at the bottom.
6
6
 
7
7
  // a CSS value from settings, without what could end the declaration
@@ -1,8 +1,8 @@
1
1
  import Image from "next/image";
2
2
  import Link from "next/link";
3
- import { getHighlights } from "./data.js";
3
+ import { getHighlights } from "../../../lib/server/highlights.js";
4
4
 
5
- // A whole page at a new URL, /__NAME__-welcome (server.tsx serverPages and znode-package.json "serverPages"): an async
5
+ // A whole page at a new URL, /__NAME__-welcome (pages/welcome/page.tsx renders it; pages/index.ts and znode-package.json "serverPages" list it): an async
6
6
  // server component that awaits its data and renders into the page's HTML, inside the store's layout.
7
7
 
8
8
  export async function WelcomePage(props: { storeCode: string }) {
@@ -0,0 +1,5 @@
1
+ import type { IConstants } from "znode-plugin/types/extension-api";
2
+
3
+ // The store constants this package changes, in the browser: constant hook name -> values. References only: the values
4
+ // live in constants/<area>/<NAME>.ts. npx znode constant list shows them; npx znode eject <CONSTANT> adds one here.
5
+ export const constants: IConstants = {};
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,9 @@
1
+ import type { IServerPages } from "znode-plugin/types/extension-api";
2
+ import { welcomePage } from "./welcome/page.js";
3
+
4
+ // The pages this package adds at new URLs: path -> page. References only: each page lives in its folder
5
+ // (pages/<page>/page.tsx: its render and <title>) and renders a component from components/server/. List every path in
6
+ // znode-package.json "serverPages" too.
7
+ export const serverPages: IServerPages = {
8
+ "/__NAME__-welcome": welcomePage,
9
+ };
@@ -0,0 +1,13 @@
1
+ import type { IServerPage, IServerSlotContext } from "znode-plugin/types/extension-api";
2
+ import { WelcomePage } from "../../components/server/welcome/WelcomePage.js";
3
+
4
+ // The page at /__NAME__-welcome (also listed in znode-package.json "serverPages"): its render and its <title>. The page
5
+ // itself is components/server/welcome/WelcomePage.tsx.
6
+ function render(_props: { path: string; searchParams: Record<string, string> }, context: IServerSlotContext) {
7
+ return <WelcomePage storeCode={context.store.code} />;
8
+ }
9
+
10
+ export const welcomePage: IServerPage = {
11
+ render,
12
+ metadata: { title: "Welcome", description: "What __LABEL__ brings to this store." },
13
+ };
@@ -1,33 +1,30 @@
1
- import type { ReactNode } from "react";
2
- import type { IPluginRouteContext, IPluginRouteRequest, IRuntimePlugin, IServerSlotContext } from "znode-plugin/types/extension-api";
3
- import { getHighlights, IHighlight } from "./server/data.js";
4
- import { ThemeLayout } from "./server/ThemeLayout.js";
5
- import { WelcomePage } from "./server/WelcomePage.js";
1
+ import type { IRuntimePlugin } from "znode-plugin/types/extension-api";
2
+ import { agents } from "./agents/index.js";
3
+ import { routes } from "./api/index.js";
4
+ import { apiRoutes } from "./api/store/index.js";
5
+ import { serverSlots } from "./slots/server/index.js";
6
+ import { serverPages } from "./pages/index.js";
6
7
 
7
8
  // __LABEL__, server part: runs only on the store's server, never in the browser.
8
- // serverSlots: server components around a part of a store page (layout.root = every page, header to footer)
9
- // serverPages: whole pages at new URLs (list them in znode-package.json "serverPages" too)
10
- // routes: your API, /api/extensions/plugins/__NAME__/<route>
11
- // They may be async (fetch data, call an API) and use next/image, next/link and next/font/google.
12
-
13
- async function highlights(_request: IPluginRouteRequest, context: IPluginRouteContext): Promise<{ store: string; items: IHighlight[] }> {
14
- return { store: context.store.code, items: await getHighlights(context.store.code) };
15
- }
9
+ // This file only links: each kind has its map (index.ts: name -> reference), and the code lives in the folders next to
10
+ // it. Keep logic out of here.
11
+ // serverSlots: slots/server/ server adapters around a part of a store page (layout.root = every page), and store
12
+ // pages taken over (copies in pages/<route>/page.tsx)
13
+ // serverPages: pages/ whole pages at new URLs (list them in znode-package.json "serverPages" too)
14
+ // routes: api/ your API, /api/extensions/plugins/__NAME__/<route>
15
+ // apiRoutes: api/store/ the store's own API routes this package answers (npx znode eject /api/...)
16
+ // agents: agents/ store agents this package answers
17
+ // The UI they render lives in components/server/ (async, may fetch data) and components/client/ (interactive).
16
18
 
17
19
  const plugin: IRuntimePlugin = {
18
20
  name: "__NAME__",
19
21
  apiVersion: 1,
20
22
  hooks: {},
21
- routes: { highlights },
22
- serverSlots: {
23
- "layout.root": (props: { children?: ReactNode }, context: IServerSlotContext) => <ThemeLayout settings={context.settings}>{props.children}</ThemeLayout>,
24
- },
25
- serverPages: {
26
- "/__NAME__-welcome": {
27
- render: (_props, context) => <WelcomePage storeCode={context.store.code} />,
28
- metadata: { title: "Welcome", description: "What __LABEL__ brings to this store." },
29
- },
30
- },
23
+ agents,
24
+ routes,
25
+ apiRoutes,
26
+ serverSlots,
27
+ serverPages,
31
28
  };
32
29
 
33
30
  export default plugin;
@@ -0,0 +1,13 @@
1
+ import type { IBrowserSlots } from "znode-plugin/types/extension-api";
2
+ import { LayoutHeaderSlot } from "./layout-header/index.js";
3
+ import { ProductCardSlot } from "./product-card/index.js";
4
+
5
+ // The store slots this package fills, in the browser: slot name -> adapter. References only: each slot's adapter lives
6
+ // in its folder (slots/<slot-name>/index.tsx) and renders a component from components/client/. Slot names:
7
+ // npx znode slot list. npx znode eject <Component> copies the component into components/client/ and adds its slot here.
8
+ export const slots: IBrowserSlots = {
9
+ // an announcement bar above the store's header
10
+ "layout.header": LayoutHeaderSlot,
11
+ // a New badge on product cards
12
+ "product.card": ProductCardSlot,
13
+ };
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ import { AnnouncementBar } from "../../components/client/layout/AnnouncementBar.js";
3
+ import { settings } from "../../lib/host.js";
4
+
5
+ // Slot layout.header (an adapter): the store's header comes in as children; the text comes from the announcement
6
+ // setting. The UI is components/client/layout/AnnouncementBar.tsx.
7
+ export function LayoutHeaderSlot(props: { children?: ReactNode }) {
8
+ return <AnnouncementBar text={String(settings.announcement || "")}>{props.children}</AnnouncementBar>;
9
+ }
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from "react";
2
+ import { ProductBadge } from "../../components/client/product/ProductBadge.js";
3
+ import { settings } from "../../lib/host.js";
4
+
5
+ // Slot product.card (an adapter): the store's product card comes in as children, with the product. A product is new
6
+ // when its NewProduct attribute is true; the showBadge setting turns badges off. The UI is
7
+ // components/client/product/ProductBadge.tsx.
8
+
9
+ type IProduct = { attributes?: { attributeCode?: string; attributeValues?: string }[] };
10
+
11
+ export function ProductCardSlot(props: { children?: ReactNode; product?: IProduct }) {
12
+ const isNew = Boolean(props.product?.attributes?.some((item) => item.attributeCode === "NewProduct" && item.attributeValues === "true"));
13
+ return <ProductBadge show={settings.showBadge !== false && isNew}>{props.children}</ProductBadge>;
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { IServerSlots } from "znode-plugin/types/extension-api";
2
+ import { LayoutRootSlot } from "./layout-root/index.js";
3
+
4
+ // The store's server slots this package fills: slot name -> adapter. References only: each adapter lives in its folder
5
+ // (slots/server/<slot-name>/index.tsx) and renders a component from components/server/. A store page taken over with
6
+ // npx znode eject <Page> is registered here too (its copy in pages/<route>/page.tsx).
7
+ export const serverSlots: IServerSlots = {
8
+ "layout.root": LayoutRootSlot,
9
+ };
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ import type { IServerSlotContext } from "znode-plugin/types/extension-api";
3
+ import { ThemeLayout } from "../../../components/server/layout/ThemeLayout.js";
4
+
5
+ // Server slot layout.root (an adapter; every page, header to footer): hands the slot's children (the store's page
6
+ // layout) and this package's settings to ThemeLayout (components/server/layout/), which knows nothing about slots.
7
+ export function LayoutRootSlot(props: { children?: ReactNode }, context: IServerSlotContext) {
8
+ return <ThemeLayout settings={context.settings}>{props.children}</ThemeLayout>;
9
+ }
@@ -0,0 +1,5 @@
1
+ import type { IUtils } from "znode-plugin/types/extension-api";
2
+
3
+ // The store utils this package answers, in the browser: util hook name -> function. References only: the functions
4
+ // live in utils/<component|common|wrap>/. npx znode util list shows the utils; npx znode eject <util> adds one here.
5
+ export const utils: IUtils = {};
@@ -0,0 +1,4 @@
1
+ import { Hero, HERO_EDITOR } from "./Hero.js";
2
+
3
+ // The __PASCAL__Hero page-builder widget: its render and its editor settings (label, fields, defaultProps).
4
+ export const HeroWidget = { render: Hero, ...HERO_EDITOR };
@@ -0,0 +1,9 @@
1
+ import type { IWidgets } from "znode-plugin/types/extension-api";
2
+ import { HeroWidget } from "./hero/index.js";
3
+
4
+ // The page-builder widgets of this package: widget type -> widget. References only: each widget lives in its own
5
+ // folder (widgets/<name>/, or widgets/<group>/<name>/ for one taken over from the store with npx znode eject widget).
6
+ // List every type in znode-package.json "widgets".
7
+ export const widgets: IWidgets = {
8
+ __PASCAL__Hero: HeroWidget,
9
+ };
@@ -3,6 +3,7 @@
3
3
  "version": "1.0.0",
4
4
  "kind": "theme",
5
5
  "apiVersion": 1,
6
+ "layout": 2,
6
7
  "label": "__LABEL__",
7
8
  "publisher": "__PUBLISHER__",
8
9
  "description": "__LABEL__: a store layout with its own font, an announcement bar, a New badge on product cards, a hero block for the page builder and a welcome page.",
@@ -16,7 +17,7 @@
16
17
  },
17
18
  "styles": ["src/styles/*.css"],
18
19
  "assets": ["src/assets/*"],
19
- "messages": "src/i18n/labels.json",
20
+ "messages": "src/messages/*.json",
20
21
  "widgets": ["__PASCAL__Hero"],
21
22
  "serverPages": ["/__NAME__-welcome"],
22
23
  "settingsSchema": {
@@ -1,19 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import { settings } from "../lib/host.js";
3
-
4
- // Slot layout.header: a bar above the store's header (children), text from the announcement setting. Empty setting:
5
- // the store's header as it is.
6
-
7
- export function AnnouncementBar(props: { children?: ReactNode }) {
8
- const text = String(settings.announcement || "");
9
- return (
10
- <>
11
- {text && (
12
- <div className="__NAME__-announcement" data-test-selector="divAnnouncement">
13
- {text}
14
- </div>
15
- )}
16
- {props.children}
17
- </>
18
- );
19
- }
@@ -1,17 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import { settings } from "../lib/host.js";
3
-
4
- // Slot product.card: a New badge on the store's product card (children) when the product's NewProduct attribute is
5
- // true, unless the showBadge setting is off.
6
-
7
- type IProduct = { attributes?: { attributeCode?: string; attributeValues?: string }[] };
8
-
9
- export function ProductBadge(props: { children?: ReactNode; product?: IProduct }) {
10
- const isNew = props.product?.attributes?.some((item) => item.attributeCode === "NewProduct" && item.attributeValues === "true");
11
- return (
12
- <div className="__NAME__-card">
13
- {settings.showBadge !== false && isNew && <span className="__NAME__-badge">New</span>}
14
- {props.children}
15
- </div>
16
- );
17
- }
File without changes