@rudra-js/react 0.9.1 → 0.10.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/README.md +17 -17
- package/dist/blocks/block-renderers.d.ts.map +1 -1
- package/dist/blocks/block-renderers.js +3 -3
- package/dist/blocks/block-renderers.js.map +1 -1
- package/dist/blocks/product-card.d.ts.map +1 -1
- package/dist/blocks/product-card.js +2 -2
- package/dist/blocks/product-card.js.map +1 -1
- package/dist/render-context.d.ts +1 -4
- package/dist/render-context.d.ts.map +1 -1
- package/dist/render-context.js +1 -31
- package/dist/render-context.js.map +1 -1
- package/dist/rudra-component.js +2 -2
- package/dist/rudra-component.js.map +1 -1
- package/package.json +4 -4
- package/src/blocks/block-renderers.tsx +3 -3
- package/src/blocks/product-card.tsx +2 -2
- package/src/render-context.ts +7 -42
- package/src/rudra-component.tsx +2 -2
package/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
# @rudra-js/react
|
|
2
2
|
|
|
3
|
-
This package is part of [rudra-js](https://rudrajs.com)
|
|
3
|
+
This package is part of [rudra-js](https://rudrajs.com), an open-source TypeScript library (MIT) you
|
|
4
|
+
install from npm. With rudra-js, a language model designs one product-recommendation block for a
|
|
5
|
+
page in your shop by picking the layout and writing the words. rudra-js checks the model's output
|
|
6
|
+
against your catalog before React renders the block with your own titles and prices. rudra-js is not
|
|
7
|
+
a hosted platform, a visual or low-code app builder, or a workspace you sign up for.
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
It is not a hosted platform, a visual or low-code app builder, or a workspace you sign up for.
|
|
8
|
-
|
|
9
|
-
You can use this package to render a component spec with React 18 or 19. This spec is a description
|
|
10
|
-
of the block generated by
|
|
11
|
-
[`@rudra-js/core`](https://github.com/clivedsouza1010/rudra-js/tree/main/packages/core).
|
|
12
|
-
|
|
13
|
-
For more on [`RudraComponent`](https://rudrajs.com/reference/react/RudraComponent) and [`extendRegistry`](https://rudrajs.com/reference/react/extendRegistry), see the reference on rudrajs.com.
|
|
9
|
+
This package renders a spec with React 18 or 19. The spec is a description of the block that
|
|
10
|
+
[`@rudra-js/core`](https://github.com/clivedsouza1010/rudra-js/tree/main/packages/core) generates.
|
|
14
11
|
|
|
15
12
|
All the components are just plain functions with no hooks, state or effects. They can be rendered:
|
|
16
13
|
|
|
17
14
|
- with `renderToString`
|
|
18
15
|
- in a client-rendered app
|
|
19
|
-
- as Server Components,
|
|
16
|
+
- as Server Components, where supported (like the Next.js App Router)
|
|
17
|
+
|
|
18
|
+
Server-rendered recommendations will be in the first HTML response and won't need any client
|
|
19
|
+
JavaScript. They don't show up late like a client-fetched recommendation rail. Crawlers that don't
|
|
20
|
+
run JavaScript will also see them.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
a crawler that doesn't run JavaScript reads the recommendations.
|
|
22
|
+
You can read more about [`RudraComponent`](https://rudrajs.com/reference/react/RudraComponent) and
|
|
23
|
+
[`extendRegistry`](https://rudrajs.com/reference/react/extendRegistry) on rudrajs.com.
|
|
24
24
|
|
|
25
25
|
## Install
|
|
26
26
|
|
|
@@ -106,9 +106,9 @@ This package doesn't ship any CSS. Without styles, the block will render as a si
|
|
|
106
106
|
All of the card elements are inline. This means a card's parts sit on a single line with spaces in
|
|
107
107
|
between. There is nothing to separate a card from the next. You style it from there.
|
|
108
108
|
|
|
109
|
-
For a working stylesheet, see `examples/
|
|
110
|
-
the
|
|
111
|
-
|
|
109
|
+
For a working stylesheet, see `examples/demo/public/demo-styles.css`. It uses just the classes and
|
|
110
|
+
attributes in the tables below. You can copy it as a starting point. It isn't a supported API
|
|
111
|
+
though. The demo applies it by default. You can use `?styles=off` to see the raw markup.
|
|
112
112
|
|
|
113
113
|
All of the elements the component renders have a class. Here is the full list:
|
|
114
114
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-renderers.d.ts","sourceRoot":"","sources":["../../src/blocks/block-renderers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,SAAS,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"block-renderers.d.ts","sourceRoot":"","sources":["../../src/blocks/block-renderers.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,SAAS,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGpF,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,+BAmBA;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,+BAWA;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,+BAWA;AAED,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,+BAO/D;AAED,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,+BAO3D;AAED,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,sCA+BA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { findSellableProduct } from '../render-context.js';
|
|
3
3
|
import { ProductCard } from './product-card.js';
|
|
4
4
|
export function HeroRenderer({ block, context, }) {
|
|
5
|
-
const product = block.sku ?
|
|
5
|
+
const product = block.sku ? findSellableProduct(context.products, block.sku) : undefined;
|
|
6
6
|
return (_jsxs("section", { className: "rudra-hero", children: [block.headline ? _jsx("h3", { className: "rudra-hero__headline", children: block.headline }) : null, block.body ? _jsx("p", { className: "rudra-hero__body", children: block.body }) : null, product ? (_jsxs("a", { className: "rudra-hero__link", href: context.hrefForSku(product.sku), "data-rudra-sku": product.sku, children: [product.title, " ", _jsx("span", { className: "rudra-hero__price", children: context.formatPrice(product) }), ' ', block.ctaLabel ? _jsx("span", { className: "rudra-hero__cta", children: block.ctaLabel }) : null] })) : null] }));
|
|
7
7
|
}
|
|
8
8
|
export function GridRenderer({ block, context, }) {
|
|
@@ -23,7 +23,7 @@ export function BundleRenderer({ block, context, }) {
|
|
|
23
23
|
return null;
|
|
24
24
|
const products = [];
|
|
25
25
|
for (const sku of bundle.skus) {
|
|
26
|
-
const product =
|
|
26
|
+
const product = findSellableProduct(context.products, sku);
|
|
27
27
|
if (!product)
|
|
28
28
|
return null;
|
|
29
29
|
products.push(product);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-renderers.js","sourceRoot":"","sources":["../../src/blocks/block-renderers.tsx"],"names":[],"mappings":";AASA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"block-renderers.js","sourceRoot":"","sources":["../../src/blocks/block-renderers.tsx"],"names":[],"mappings":";AASA,OAAO,EAAE,mBAAmB,EAA2B,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,UAAU,YAAY,CAAC,EAC3B,KAAK,EACL,OAAO,GAIR;IACC,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,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AO,CAAC,KAAK,GACZ,IAHG,OAAO,CAAC,GAAG,CAIf,CACN,CAAC,GACC,EAEL,YAAG,SAAS,EAAC,qBAAqB,YAAE,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAK,EACzE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,mBAAmB,YAAE,KAAK,CAAC,QAAQ,GAAQ,CAAC,CAAC,CAAC,IAAI,IAC5E,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card.d.ts","sourceRoot":"","sources":["../../src/blocks/product-card.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"product-card.d.ts","sourceRoot":"","sources":["../../src/blocks/product-card.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEpF,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,OAAO,GACR,EAAE;IACD,SAAS,EAAE,gBAAgB,CAAC;IAC5B,OAAO,EAAE,kBAAkB,CAAC;CAC7B,sCAyBA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { findSellableProduct } from '../render-context.js';
|
|
3
3
|
export function ProductCard({ reference, context, }) {
|
|
4
|
-
const product =
|
|
4
|
+
const product = findSellableProduct(context.products, reference.sku);
|
|
5
5
|
if (!product)
|
|
6
6
|
return null;
|
|
7
7
|
const isFeatured = reference.emphasis === 'featured';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card.js","sourceRoot":"","sources":["../../src/blocks/product-card.tsx"],"names":[],"mappings":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,YAAE,SAAS,CAAC,MAAM,GAAQ,CAAC,CAAC,CAAC,IAAI,IACpF,IACL,CACL,CAAC;AACJ,CAAC"}
|
package/dist/render-context.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Bundle, Product } from '@rudra-js/core';
|
|
2
|
+
export { defaultFormatBundlePrice, defaultFormatPrice, defaultHrefForSku, findSellableProduct, } from '@rudra-js/core/schemas';
|
|
2
3
|
export interface BlockRenderContext {
|
|
3
4
|
readonly products: ReadonlyMap<string, Product>;
|
|
4
5
|
readonly bundles: ReadonlyMap<string, Bundle>;
|
|
@@ -6,8 +7,4 @@ export interface BlockRenderContext {
|
|
|
6
7
|
readonly formatPrice: (product: Product) => string;
|
|
7
8
|
readonly formatBundlePrice: (bundle: Bundle) => string;
|
|
8
9
|
}
|
|
9
|
-
export declare function defaultHrefForSku(sku: string): string;
|
|
10
|
-
export declare function sellableProduct(products: ReadonlyMap<string, Product>, sku: string): Product | undefined;
|
|
11
|
-
export declare function defaultFormatPrice(product: Product, locale?: string): string;
|
|
12
|
-
export declare function defaultFormatBundlePrice(bundle: Bundle, locale?: string): string;
|
|
13
10
|
//# sourceMappingURL=render-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-context.d.ts","sourceRoot":"","sources":["../src/render-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IACnD,QAAQ,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CACxD
|
|
1
|
+
{"version":3,"file":"render-context.d.ts","sourceRoot":"","sources":["../src/render-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IACnD,QAAQ,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CACxD"}
|
package/dist/render-context.js
CHANGED
|
@@ -1,32 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
return `/product/${encodeURIComponent(sku)}`;
|
|
3
|
-
}
|
|
4
|
-
export function sellableProduct(products, sku) {
|
|
5
|
-
const product = products.get(sku);
|
|
6
|
-
return product?.isInStock === false ? undefined : product;
|
|
7
|
-
}
|
|
8
|
-
function formatMoney(price, currency, locale) {
|
|
9
|
-
let formatter;
|
|
10
|
-
try {
|
|
11
|
-
formatter = new Intl.NumberFormat(locale, { style: 'currency', currency });
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
return `${currency} ${price}`;
|
|
15
|
-
}
|
|
16
|
-
return formatter.format(price);
|
|
17
|
-
}
|
|
18
|
-
export function defaultFormatPrice(product, locale) {
|
|
19
|
-
if (!Number.isFinite(product.price)) {
|
|
20
|
-
throw new TypeError(`price for SKU ${product.sku} is ${String(product.price)}, not a finite number. ` +
|
|
21
|
-
'Catalog objects must satisfy productSchema from @rudra-js/core');
|
|
22
|
-
}
|
|
23
|
-
return formatMoney(product.price, product.currency, locale);
|
|
24
|
-
}
|
|
25
|
-
export function defaultFormatBundlePrice(bundle, locale) {
|
|
26
|
-
if (!Number.isFinite(bundle.price)) {
|
|
27
|
-
throw new TypeError(`price for bundle ${bundle.id} is ${String(bundle.price)}, not a finite number. ` +
|
|
28
|
-
'Bundle objects must satisfy bundleSchema from @rudra-js/core');
|
|
29
|
-
}
|
|
30
|
-
return formatMoney(bundle.price, bundle.currency, locale);
|
|
31
|
-
}
|
|
1
|
+
export { defaultFormatBundlePrice, defaultFormatPrice, defaultHrefForSku, findSellableProduct, } from '@rudra-js/core/schemas';
|
|
32
2
|
//# sourceMappingURL=render-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-context.js","sourceRoot":"","sources":["../src/render-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-context.js","sourceRoot":"","sources":["../src/render-context.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC"}
|
package/dist/rudra-component.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { defaultFormatBundlePrice, defaultFormatPrice, defaultHrefForSku,
|
|
2
|
+
import { defaultFormatBundlePrice, defaultFormatPrice, defaultHrefForSku, findSellableProduct, } from './render-context.js';
|
|
3
3
|
import { defaultRegistry } from './registry.js';
|
|
4
4
|
function isKeyedBySku(catalog) {
|
|
5
5
|
const candidate = catalog;
|
|
@@ -15,7 +15,7 @@ function toProductMap(catalog) {
|
|
|
15
15
|
return new Map(catalog.map((product) => [product.sku, product]));
|
|
16
16
|
}
|
|
17
17
|
function hasContent(block, context) {
|
|
18
|
-
const isSellable = (sku) =>
|
|
18
|
+
const isSellable = (sku) => findSellableProduct(context.products, sku) !== undefined;
|
|
19
19
|
switch (block.kind) {
|
|
20
20
|
case 'grid':
|
|
21
21
|
case 'carousel':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rudra-component.js","sourceRoot":"","sources":["../src/rudra-component.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"rudra-component.js","sourceRoot":"","sources":["../src/rudra-component.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAsB,MAAM,eAAe,CAAC;AAiBpE,SAAS,YAAY,CAAC,OAAuB;IAC3C,MAAM,SAAS,GAAG,OAA2C,CAAC;IAC9D,OAAO,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU,IAAI,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU,CAAC;AACpF,CAAC;AAED,SAAS,YAAY,CAAC,OAAuB;IAC3C,IAAI,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC1C,IAAI,OAAQ,OAA6B,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;QAC7D,MAAM,IAAI,SAAS,CACjB,yFAAyF;YACvF,YAAY,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CACxD,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,S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AG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAE3E,cAAc,CAAC,CAAC,CAAC,YAAG,SAAS,EAAC,kBAAkB,YAAE,IAAI,CAAC,SAAS,GAAK,CAAC,CAAC,CAAC,IAAI,IACrE,CACX,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rudra-js/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Renders rudra-js product recommendations with React, on the server or in the browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rudra-js",
|
|
7
7
|
"product-recommendations",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@rudra-js/core": "^0.
|
|
57
|
+
"@rudra-js/core": "^0.10.0",
|
|
58
58
|
"react": "^18.2.0 || ^19.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@rudra-js/core": "0.
|
|
61
|
+
"@rudra-js/core": "0.10.0",
|
|
62
62
|
"@types/react": "^19.3.0",
|
|
63
63
|
"@types/react-dom": "^19.3.0",
|
|
64
64
|
"react": "^19.3.1",
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
HeroBlock,
|
|
8
8
|
Product,
|
|
9
9
|
} from '@rudra-js/core';
|
|
10
|
-
import {
|
|
10
|
+
import { findSellableProduct, type BlockRenderContext } from '../render-context.js';
|
|
11
11
|
import { ProductCard } from './product-card.js';
|
|
12
12
|
|
|
13
13
|
export function HeroRenderer({
|
|
@@ -17,7 +17,7 @@ export function HeroRenderer({
|
|
|
17
17
|
block: HeroBlock;
|
|
18
18
|
context: BlockRenderContext;
|
|
19
19
|
}) {
|
|
20
|
-
const product = block.sku ?
|
|
20
|
+
const product = block.sku ? findSellableProduct(context.products, block.sku) : undefined;
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<section className="rudra-hero">
|
|
@@ -105,7 +105,7 @@ export function BundleRenderer({
|
|
|
105
105
|
|
|
106
106
|
const products: Product[] = [];
|
|
107
107
|
for (const sku of bundle.skus) {
|
|
108
|
-
const product =
|
|
108
|
+
const product = findSellableProduct(context.products, sku);
|
|
109
109
|
if (!product) return null;
|
|
110
110
|
products.push(product);
|
|
111
111
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProductReference } from '@rudra-js/core';
|
|
2
|
-
import {
|
|
2
|
+
import { findSellableProduct, type BlockRenderContext } from '../render-context.js';
|
|
3
3
|
|
|
4
4
|
export function ProductCard({
|
|
5
5
|
reference,
|
|
@@ -8,7 +8,7 @@ export function ProductCard({
|
|
|
8
8
|
reference: ProductReference;
|
|
9
9
|
context: BlockRenderContext;
|
|
10
10
|
}) {
|
|
11
|
-
const product =
|
|
11
|
+
const product = findSellableProduct(context.products, reference.sku);
|
|
12
12
|
if (!product) return null;
|
|
13
13
|
|
|
14
14
|
const isFeatured = reference.emphasis === 'featured';
|
package/src/render-context.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { Bundle, Product } from '@rudra-js/core';
|
|
2
2
|
|
|
3
|
+
export {
|
|
4
|
+
defaultFormatBundlePrice,
|
|
5
|
+
defaultFormatPrice,
|
|
6
|
+
defaultHrefForSku,
|
|
7
|
+
findSellableProduct,
|
|
8
|
+
} from '@rudra-js/core/schemas';
|
|
9
|
+
|
|
3
10
|
export interface BlockRenderContext {
|
|
4
11
|
readonly products: ReadonlyMap<string, Product>;
|
|
5
12
|
readonly bundles: ReadonlyMap<string, Bundle>;
|
|
@@ -7,45 +14,3 @@ export interface BlockRenderContext {
|
|
|
7
14
|
readonly formatPrice: (product: Product) => string;
|
|
8
15
|
readonly formatBundlePrice: (bundle: Bundle) => string;
|
|
9
16
|
}
|
|
10
|
-
|
|
11
|
-
export function defaultHrefForSku(sku: string): string {
|
|
12
|
-
return `/product/${encodeURIComponent(sku)}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function sellableProduct(
|
|
16
|
-
products: ReadonlyMap<string, Product>,
|
|
17
|
-
sku: string,
|
|
18
|
-
): Product | undefined {
|
|
19
|
-
const product = products.get(sku);
|
|
20
|
-
return product?.isInStock === false ? undefined : product;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function formatMoney(price: number, currency: string, locale?: string): string {
|
|
24
|
-
let formatter: Intl.NumberFormat;
|
|
25
|
-
try {
|
|
26
|
-
formatter = new Intl.NumberFormat(locale, { style: 'currency', currency });
|
|
27
|
-
} catch {
|
|
28
|
-
return `${currency} ${price}`;
|
|
29
|
-
}
|
|
30
|
-
return formatter.format(price);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function defaultFormatPrice(product: Product, locale?: string): string {
|
|
34
|
-
if (!Number.isFinite(product.price)) {
|
|
35
|
-
throw new TypeError(
|
|
36
|
-
`price for SKU ${product.sku} is ${String(product.price)}, not a finite number. ` +
|
|
37
|
-
'Catalog objects must satisfy productSchema from @rudra-js/core',
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return formatMoney(product.price, product.currency, locale);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function defaultFormatBundlePrice(bundle: Bundle, locale?: string): string {
|
|
44
|
-
if (!Number.isFinite(bundle.price)) {
|
|
45
|
-
throw new TypeError(
|
|
46
|
-
`price for bundle ${bundle.id} is ${String(bundle.price)}, not a finite number. ` +
|
|
47
|
-
'Bundle objects must satisfy bundleSchema from @rudra-js/core',
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return formatMoney(bundle.price, bundle.currency, locale);
|
|
51
|
-
}
|
package/src/rudra-component.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
defaultFormatBundlePrice,
|
|
4
4
|
defaultFormatPrice,
|
|
5
5
|
defaultHrefForSku,
|
|
6
|
-
|
|
6
|
+
findSellableProduct,
|
|
7
7
|
type BlockRenderContext,
|
|
8
8
|
} from './render-context.js';
|
|
9
9
|
import { defaultRegistry, type BlockRegistry } from './registry.js';
|
|
@@ -40,7 +40,7 @@ function toProductMap(catalog: ProductCatalog): ReadonlyMap<string, Product> {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function hasContent(block: Block, context: BlockRenderContext): boolean {
|
|
43
|
-
const isSellable = (sku: string) =>
|
|
43
|
+
const isSellable = (sku: string) => findSellableProduct(context.products, sku) !== undefined;
|
|
44
44
|
|
|
45
45
|
switch (block.kind) {
|
|
46
46
|
case 'grid':
|