@orunelle/theme-engine 0.0.0-stage → 2.0.0-alpha.14

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.
@@ -0,0 +1,77 @@
1
+ import { type ReactNode } from "react";
2
+ import { type OptionVisuals, type PublicProduct, type ThemeNodeProps } from "@orunelle/theme-sdk";
3
+ import type { Variant } from "@orunelle/theme-sdk/commerce";
4
+ interface ProductForm {
5
+ product: PublicProduct;
6
+ variants: readonly Variant[];
7
+ visuals: OptionVisuals;
8
+ selection: Record<string, string>;
9
+ choose: (name: string, value: string) => void;
10
+ variant: Variant | undefined;
11
+ quantity: number;
12
+ setQuantity: (value: number) => void;
13
+ }
14
+ export declare function ProductFormProvider({ product, variants, visuals, children, }: {
15
+ product: PublicProduct;
16
+ variants: readonly Variant[];
17
+ visuals?: OptionVisuals;
18
+ children: ReactNode;
19
+ }): import("react").JSX.Element;
20
+ /** Product blocks read the current product and selection from here. */
21
+ export declare function useProductForm(): ProductForm;
22
+ export declare function ProductGallery({ layout, zoom, }: {
23
+ layout?: "thumbnails" | "grid";
24
+ zoom?: boolean;
25
+ }): import("react").JSX.Element;
26
+ export declare function ProductTitle(): import("react").JSX.Element;
27
+ export declare function ProductPrice({ showBadge }: {
28
+ showBadge?: boolean;
29
+ }): import("react").JSX.Element;
30
+ export declare function VariantPicker(): import("react").JSX.Element | null;
31
+ export declare function BuyButtons({ showQuantity, showBuyNow, lowStock, }: {
32
+ showQuantity?: boolean;
33
+ showBuyNow?: boolean;
34
+ lowStock?: number;
35
+ }): import("react").JSX.Element;
36
+ export declare function ProductDescription({ collapsed, }: {
37
+ collapsed?: boolean;
38
+ }): import("react").JSX.Element | null;
39
+ /** The product's public custom fields as a specification list. */
40
+ export declare function ProductFields({ product, title, }: {
41
+ product: PublicProduct;
42
+ title?: string;
43
+ }): import("react").JSX.Element | null;
44
+ declare function SpecsBlock({ settings }: ThemeNodeProps): import("react").JSX.Element;
45
+ declare function CollapsibleBlock({ settings }: ThemeNodeProps): import("react").JSX.Element | null;
46
+ declare function TextBlock({ settings }: ThemeNodeProps): import("react").JSX.Element | null;
47
+ /**
48
+ * The main product section. With blocks it lays out the gallery beside the
49
+ * merchant's blocks; without blocks it renders the theme's product page, so
50
+ * older configurations and custom themes keep working.
51
+ */
52
+ declare function MainProduct({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
53
+ declare function RelatedProducts({ settings }: ThemeNodeProps): import("react").JSX.Element | null;
54
+ export declare const productSections: Readonly<{
55
+ "product-detail": typeof MainProduct;
56
+ "related-products": typeof RelatedProducts;
57
+ }>;
58
+ export declare const productBlocks: Readonly<{
59
+ "product-title": () => import("react").JSX.Element;
60
+ "product-price": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
61
+ "product-options": () => import("react").JSX.Element;
62
+ "product-buy": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
63
+ "product-description": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
64
+ "product-specs": typeof SpecsBlock;
65
+ "product-collapsible": typeof CollapsibleBlock;
66
+ "product-text": typeof TextBlock;
67
+ }>;
68
+ /** The default product page: the same pieces in a sensible fixed order. */
69
+ export declare function DefaultProductLayout({ product, variants, related, optionVisuals, after, }: {
70
+ product: PublicProduct;
71
+ variants: readonly Variant[];
72
+ related: readonly PublicProduct[];
73
+ optionVisuals: OptionVisuals;
74
+ after?: ReactNode;
75
+ }): import("react").JSX.Element;
76
+ export {};
77
+ //# sourceMappingURL=product.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../src/product.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAgBL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAM5D,UAAU,WAAW;IACnB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAGD,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,QAAQ,EACR,OAAY,EACZ,QAAQ,GACT,EAAE;IACD,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,SAAS,CAAC;CACrB,+BAyCA;AAED,uEAAuE;AACvE,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAOD,wBAAgB,cAAc,CAAC,EAC7B,MAAqB,EACrB,IAAW,GACZ,EAAE;IACD,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,+BAkGA;AAID,wBAAgB,YAAY,gCAI3B;AAED,wBAAgB,YAAY,CAAC,EAAE,SAAgB,EAAE,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,+BA8BzE;AAED,wBAAgB,aAAa,uCAkE5B;AAED,wBAAgB,UAAU,CAAC,EACzB,YAAmB,EACnB,UAAiB,EACjB,QAAY,GACb,EAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,+BA8GA;AAED,wBAAgB,kBAAkB,CAAC,EACjC,SAAiB,GAClB,EAAE;IACD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,sCAuBA;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,KAAK,GACN,EAAE;IACD,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,sCAwCA;AAED,iBAAS,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,+BAU/C;AAED,iBAAS,gBAAgB,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,sCAUrD;AAED,iBAAS,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,sCAU9C;AAID;;;;GAIG;AACH,iBAAS,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,cAAc,+BA+B1D;AAED,iBAAS,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,sCA2BpD;AAED,eAAO,MAAM,eAAe;;;EAG1B,CAAC;AACH,eAAO,MAAM,aAAa;;oCAEQ,cAAc;;kCAIhB,cAAc;0CASN,cAAc;;;;EAMpD,CAAC;AAEH,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,aAAa,EACb,KAAK,GACN,EAAE;IACD,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,aAAa,EAAE,aAAa,CAAC;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,+BA0CA"}
@@ -0,0 +1,241 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
3
+ import { useNavigate } from "@tanstack/react-router";
4
+ import { emitStorefrontEvent, eventProduct, formatFieldValue, formatMoney, imagesForVariant, initialSelection, matchVariant, optionAvailable, optionGroups, useCommerce, useStoreText, useStorefront, useThemeComponents, useThemeRuntime, variantPrice, } from "@orunelle/theme-sdk";
5
+ import { RichText, SmartLink, textOf } from "./library.js";
6
+ import { Failure, useAction } from "./commerce/shared.js";
7
+ const FormContext = createContext(null);
8
+ export function ProductFormProvider({ product, variants, visuals = {}, children, }) {
9
+ const { locale } = useStorefront();
10
+ const [selection, setSelection] = useState(() => initialSelection(variants));
11
+ const [quantity, setQuantity] = useState(1);
12
+ const variant = matchVariant(variants, selection);
13
+ useEffect(() => {
14
+ setSelection(initialSelection(variants));
15
+ setQuantity(1);
16
+ emitStorefrontEvent("product_viewed", {
17
+ product: eventProduct(product, locale),
18
+ });
19
+ // One event and a fresh selection per product shown.
20
+ }, [product.id]);
21
+ const value = {
22
+ product,
23
+ variants,
24
+ visuals,
25
+ selection,
26
+ variant,
27
+ quantity,
28
+ setQuantity: (next) => setQuantity(Math.max(1, Math.min(99, next))),
29
+ choose: (name, choice) => {
30
+ const next = { ...selection, [name]: choice };
31
+ // Keep the visitor on a real variant when the exact combination is missing.
32
+ if (!matchVariant(variants, next)) {
33
+ const fallback = variants.find((v) => v.isActive &&
34
+ Object.entries(v.options ?? {}).some(([k, val]) => k === name && val === choice));
35
+ if (fallback?.options) {
36
+ setSelection({ ...fallback.options });
37
+ return;
38
+ }
39
+ }
40
+ setSelection(next);
41
+ },
42
+ };
43
+ return _jsx(FormContext.Provider, { value: value, children: children });
44
+ }
45
+ /** Product blocks read the current product and selection from here. */
46
+ export function useProductForm() {
47
+ const form = useContext(FormContext);
48
+ if (!form)
49
+ throw new Error("Render product blocks inside ProductFormProvider.");
50
+ return form;
51
+ }
52
+ const money = (price, locale) => formatMoney(price.amountMinor, price.currency, locale);
53
+ // ── Gallery ─────────────────────────────────────────────────────────────────
54
+ export function ProductGallery({ layout = "thumbnails", zoom = true, }) {
55
+ const { product, variant } = useProductForm();
56
+ const { locale } = useStorefront();
57
+ const images = imagesForVariant(product, variant);
58
+ const [active, setActive] = useState(0);
59
+ const [zoomed, setZoomed] = useState(false);
60
+ const dialog = useRef(null);
61
+ useEffect(() => setActive(0), [variant?.id]);
62
+ useEffect(() => {
63
+ if (zoomed)
64
+ dialog.current?.showModal();
65
+ else
66
+ dialog.current?.close();
67
+ }, [zoomed]);
68
+ if (!images.length)
69
+ return (_jsx("div", { className: "product-gallery", children: _jsx("div", { className: "product-image-empty product-detail-image", role: "img", "aria-label": locale === "ar" ? "لا توجد صورة للمنتج" : "No product image" }) }));
70
+ const current = images[Math.min(active, images.length - 1)];
71
+ const alt = (image) => image.alt || product.name[locale];
72
+ if (layout === "grid")
73
+ return (_jsx("div", { className: "product-gallery product-gallery-grid", children: images.map((image, index) => (_jsx("img", { src: image.url, alt: alt(image), width: image.width, height: image.height, loading: index ? "lazy" : "eager", fetchPriority: index ? "auto" : "high", decoding: "async" }, image.url + index))) }));
74
+ return (_jsxs("div", { className: "product-gallery", children: [_jsx("button", { type: "button", className: "product-gallery-main", disabled: !zoom, "aria-label": zoom ? (locale === "ar" ? "تكبير الصورة" : "Zoom image") : undefined, onClick: () => setZoomed(true), children: _jsx("img", { src: current.url, alt: alt(current), width: current.width, height: current.height, fetchPriority: "high", decoding: "async" }) }), images.length > 1 && (_jsx("div", { className: "product-gallery-thumbs", role: "list", children: images.map((image, index) => (_jsx("button", { type: "button", role: "listitem", "aria-current": index === active, "aria-label": `${locale === "ar" ? "الصورة" : "Image"} ${index + 1}`, onClick: () => setActive(index), children: _jsx("img", { src: image.url, alt: "", loading: "lazy", decoding: "async" }) }, image.url + index))) })), zoom && (_jsxs("dialog", { ref: dialog, className: "product-zoom", onClose: () => setZoomed(false), onClick: () => setZoomed(false), children: [_jsx("img", { src: current.url, alt: alt(current) }), _jsx("button", { type: "button", "aria-label": locale === "ar" ? "إغلاق" : "Close", children: "\u00D7" })] }))] }));
75
+ }
76
+ // ── Blocks ──────────────────────────────────────────────────────────────────
77
+ export function ProductTitle() {
78
+ const { product } = useProductForm();
79
+ const { locale } = useStorefront();
80
+ return _jsx("h1", { className: "product-title", children: product.name[locale] });
81
+ }
82
+ export function ProductPrice({ showBadge = true }) {
83
+ const { product, variant } = useProductForm();
84
+ const { locale } = useStorefront();
85
+ const t = useStoreText();
86
+ const price = variantPrice(product, variant);
87
+ const compare = product.compareAtPrice;
88
+ const onSale = !!compare && compare.amountMinor > price.amountMinor;
89
+ const percent = onSale
90
+ ? Math.round((1 - price.amountMinor / compare.amountMinor) * 100)
91
+ : 0;
92
+ return (_jsxs("p", { className: "product-price-block", children: [_jsx("span", { className: "product-price", children: money(price, locale) }), onSale && (_jsxs(_Fragment, { children: [_jsxs("s", { className: "product-compare-price", children: [_jsxs("span", { className: "visually-hidden", children: [locale === "ar" ? "السعر الأصلي" : "Original price", " "] }), money(compare, locale)] }), showBadge && percent > 0 && (_jsxs("span", { className: "product-sale-badge", children: [t("product.sale"), " \u2212", percent, "%"] }))] }))] }));
93
+ }
94
+ export function VariantPicker() {
95
+ const { variants, visuals, selection, choose } = useProductForm();
96
+ const { locale } = useStorefront();
97
+ const groups = useMemo(() => optionGroups(variants, visuals), [variants, visuals]);
98
+ if (!groups.length)
99
+ return null;
100
+ return (_jsx("div", { className: "product-options", children: groups.map((group) => (_jsxs("fieldset", { className: `product-option product-option-${group.kind}`, children: [_jsxs("legend", { children: [group.name, selection[group.name] && _jsxs("span", { children: [": ", selection[group.name]] })] }), _jsx("div", { className: "product-option-values", children: group.values.map((option) => {
101
+ const selected = selection[group.name] === option.value;
102
+ const available = optionAvailable(variants, selection, group.name, option.value);
103
+ return (_jsx("button", { type: "button", className: "product-option-value", "aria-pressed": selected, "data-unavailable": available ? undefined : "true", "aria-label": group.kind === "text"
104
+ ? undefined
105
+ : `${option.value}${available ? "" : locale === "ar" ? " (غير متوفر)" : " (unavailable)"}`, onClick: () => choose(group.name, option.value), children: group.kind === "color" ? (_jsx("span", { className: "product-swatch", style: { background: option.visual?.color } })) : group.kind === "image" && option.visual?.image ? (_jsx("img", { className: "product-swatch", src: option.visual.image, alt: "" })) : (option.value) }, option.value));
106
+ }) })] }, group.name))) }));
107
+ }
108
+ export function BuyButtons({ showQuantity = true, showBuyNow = true, lowStock = 5, }) {
109
+ const { product, variant, quantity, setQuantity } = useProductForm();
110
+ const context = useStorefront();
111
+ const session = useCommerce();
112
+ const t = useStoreText();
113
+ const action = useAction();
114
+ const navigate = useNavigate();
115
+ const inStock = !!variant && variant.availableQuantity > 0;
116
+ const max = Math.max(1, Math.min(99, variant?.availableQuantity ?? 1));
117
+ const live = context.commerce === "api";
118
+ async function add() {
119
+ await session.client.cart.add(variant.id, Math.min(quantity, max));
120
+ emitStorefrontEvent("product_added_to_cart", {
121
+ product: eventProduct(product, context.locale),
122
+ variantId: variant.id,
123
+ quantity: Math.min(quantity, max),
124
+ });
125
+ await session.cache.invalidateQueries();
126
+ }
127
+ const disabled = !live || !session.ready || !inStock || action.pending;
128
+ return (_jsxs("div", { className: "product-buy", children: [inStock && variant.availableQuantity <= lowStock && (_jsx("p", { className: "product-stock-low", role: "status", children: t("product.only_left").replace("{count}", String(variant.availableQuantity)) })), _jsxs("div", { className: "product-buy-row", children: [showQuantity && (_jsxs("div", { className: "product-quantity", role: "group", "aria-label": t("product.quantity"), children: [_jsx("button", { type: "button", "aria-label": "\u2212", disabled: quantity <= 1, onClick: () => setQuantity(quantity - 1), children: "\u2212" }), _jsx("input", { type: "number", inputMode: "numeric", min: 1, max: max, "aria-label": t("product.quantity"), value: quantity, onChange: (e) => setQuantity(e.target.valueAsNumber || 1) }), _jsx("button", { type: "button", "aria-label": "+", disabled: quantity >= max, onClick: () => setQuantity(quantity + 1), children: "+" })] })), _jsx("button", { type: "button", className: "product-add", disabled: disabled, onClick: () => void action.run(async () => {
129
+ await add();
130
+ action.setNotice(t("product.added"));
131
+ }), children: live && (!variant || !inStock)
132
+ ? t("product.out_of_stock")
133
+ : t("product.add_to_cart") })] }), showBuyNow && inStock && (_jsx("button", { type: "button", className: "product-buy-now button-secondary", disabled: disabled, onClick: () => void action.run(async () => {
134
+ await add();
135
+ await navigate({ to: `/${context.locale}/checkout` });
136
+ }), children: t("product.buy_now") })), action.notice && (_jsx("p", { className: "form-notice", role: "status", children: action.notice })), _jsx(Failure, { error: action.error }), !live && (_jsx("p", { className: "sample-notice", children: context.locale === "ar"
137
+ ? "هذا منتج تجريبي. الشراء غير متاح."
138
+ : "This is a sample product. Purchases are unavailable." }))] }));
139
+ }
140
+ export function ProductDescription({ collapsed = false, }) {
141
+ const { product } = useProductForm();
142
+ const { locale } = useStorefront();
143
+ const t = useStoreText();
144
+ const paragraphs = product.description[locale]
145
+ .split(/\n{2,}/)
146
+ .filter((p) => p.trim());
147
+ if (!paragraphs.length)
148
+ return null;
149
+ const body = (_jsx("div", { className: "product-description", children: paragraphs.map((paragraph, index) => (_jsx("p", { children: paragraph }, index))) }));
150
+ return collapsed ? (_jsxs("details", { className: "product-collapsible", children: [_jsx("summary", { children: t("product.description") }), body] })) : (body);
151
+ }
152
+ /** The product's public custom fields as a specification list. */
153
+ export function ProductFields({ product, title, }) {
154
+ const { locale } = useStorefront();
155
+ const fields = (product.fields ?? []).filter((field) => field.kind === "boolean" || formatFieldValue(field, locale));
156
+ if (!fields.length)
157
+ return null;
158
+ return (_jsxs("div", { className: "product-specs", children: [title && _jsx("h2", { children: title }), _jsx("dl", { className: "product-fields", children: fields.map((field) => {
159
+ const text = formatFieldValue(field, locale);
160
+ let value = text;
161
+ if (field.kind === "url")
162
+ value = (_jsx(SmartLink, { href: text, children: text.replace(/^https?:\/\//, "") }));
163
+ else if (field.kind === "color")
164
+ value = (_jsxs("span", { className: "product-field-color", children: [_jsx("span", { "aria-hidden": "true", style: { background: text } }), text] }));
165
+ else if (field.kind === "multiline")
166
+ value = text
167
+ .split("\n")
168
+ .map((line, index) => _jsx("p", { children: line }, index));
169
+ return (_jsxs("div", { "data-field": field.key, children: [_jsx("dt", { children: field.name[locale] }), _jsx("dd", { children: value })] }, field.key));
170
+ }) })] }));
171
+ }
172
+ function SpecsBlock({ settings }) {
173
+ const { product } = useProductForm();
174
+ const { locale } = useStorefront();
175
+ const t = useStoreText();
176
+ return (_jsx(ProductFields, { product: product, title: textOf(settings.title, locale) || t("product.specs") }));
177
+ }
178
+ function CollapsibleBlock({ settings }) {
179
+ const { locale } = useStorefront();
180
+ const title = textOf(settings.title, locale);
181
+ if (!title)
182
+ return null;
183
+ return (_jsxs("details", { className: "product-collapsible", open: settings.open === true, children: [_jsx("summary", { children: title }), _jsx(RichText, { value: settings.body, field: "body" })] }));
184
+ }
185
+ function TextBlock({ settings }) {
186
+ const { locale } = useStorefront();
187
+ const text = textOf(settings.text, locale);
188
+ return text ? (_jsx("p", { className: `product-note product-note-${settings.style === "highlight" ? "highlight" : "plain"}`, children: text })) : null;
189
+ }
190
+ // ── Sections ────────────────────────────────────────────────────────────────
191
+ /**
192
+ * The main product section. With blocks it lays out the gallery beside the
193
+ * merchant's blocks; without blocks it renders the theme's product page, so
194
+ * older configurations and custom themes keep working.
195
+ */
196
+ function MainProduct({ settings, children }) {
197
+ const { products, variants, optionVisuals } = useThemeRuntime();
198
+ const { ProductPage } = useThemeComponents();
199
+ const product = products[0];
200
+ const { locale } = useStorefront();
201
+ if (!product)
202
+ return (_jsx("p", { role: "status", children: locale === "ar" ? "لم يتم اختيار منتج" : "No product selected" }));
203
+ const hasBlocks = Array.isArray(children) ? children.length > 0 : !!children;
204
+ if (!hasBlocks)
205
+ return _jsx(ProductPage, { product: product, variants: variants ?? [] });
206
+ return (_jsx(ProductFormProvider, { product: product, variants: variants ?? [], visuals: optionVisuals ?? {}, children: _jsxs("section", { className: `product-main${settings.sticky === false ? "" : " product-main-sticky"}`, children: [_jsx(ProductGallery, { layout: settings.gallery === "grid" ? "grid" : "thumbnails", zoom: settings.zoom !== false }), _jsx("div", { className: "product-info", children: children })] }) }));
207
+ }
208
+ function RelatedProducts({ settings }) {
209
+ const { related } = useThemeRuntime();
210
+ const { ProductCard } = useThemeComponents();
211
+ const { locale } = useStorefront();
212
+ const t = useStoreText();
213
+ const limit = typeof settings.limit === "number" ? settings.limit : 4;
214
+ const items = (related ?? []).slice(0, limit);
215
+ if (!items.length)
216
+ return null;
217
+ const title = textOf(settings.title, locale) || t("product.related");
218
+ return (_jsxs("section", { className: "theme-section product-related", children: [_jsx("h2", { className: "theme-section-title", children: title }), _jsx("div", { className: "theme-grid", style: {
219
+ "--columns": typeof settings.columns === "number" ? settings.columns : 4,
220
+ }, children: items.map((item) => (_jsx(ProductCard, { product: item }, item.id))) })] }));
221
+ }
222
+ export const productSections = Object.freeze({
223
+ "product-detail": MainProduct,
224
+ "related-products": RelatedProducts,
225
+ });
226
+ export const productBlocks = Object.freeze({
227
+ "product-title": () => _jsx(ProductTitle, {}),
228
+ "product-price": ({ settings }) => (_jsx(ProductPrice, { showBadge: settings["show-badge"] !== false })),
229
+ "product-options": () => _jsx(VariantPicker, {}),
230
+ "product-buy": ({ settings }) => (_jsx(BuyButtons, { showQuantity: settings.quantity !== false, showBuyNow: settings["buy-now"] !== false, lowStock: typeof settings["low-stock"] === "number" ? settings["low-stock"] : 5 })),
231
+ "product-description": ({ settings }) => (_jsx(ProductDescription, { collapsed: settings.collapsed === true })),
232
+ "product-specs": SpecsBlock,
233
+ "product-collapsible": CollapsibleBlock,
234
+ "product-text": TextBlock,
235
+ });
236
+ /** The default product page: the same pieces in a sensible fixed order. */
237
+ export function DefaultProductLayout({ product, variants, related, optionVisuals, after, }) {
238
+ const { ProductCard } = useThemeComponents();
239
+ const t = useStoreText();
240
+ return (_jsxs(ProductFormProvider, { product: product, variants: variants, visuals: optionVisuals, children: [_jsx(SmartLink, { href: "/products", className: "back-link", children: t("product.back") }), _jsxs("section", { className: "product-main product-main-sticky", "data-component": "default-product-page", children: [_jsx(ProductGallery, {}), _jsxs("div", { className: "product-info", children: [_jsx(ProductTitle, {}), _jsx(ProductPrice, {}), _jsx(VariantPicker, {}), _jsx(BuyButtons, {}), _jsx(ProductDescription, {}), _jsx(ProductFields, { product: product, title: t("product.specs") }), after] })] }), related.length > 0 && (_jsxs("section", { className: "theme-section product-related", children: [_jsx("h2", { className: "theme-section-title", children: t("product.related") }), _jsx("div", { className: "theme-grid", style: { "--columns": 4 }, children: related.slice(0, 4).map((item) => (_jsx(ProductCard, { product: item }, item.id))) })] }))] }));
241
+ }
@@ -0,0 +1,48 @@
1
+ import { type ThemeNodeProps } from "@orunelle/theme-sdk";
2
+ declare function Hero({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
3
+ declare function Heading({ settings }: ThemeNodeProps): import("react").JSX.Element;
4
+ declare function Text({ settings }: ThemeNodeProps): import("react").JSX.Element;
5
+ declare function Button({ settings }: ThemeNodeProps): import("react").JSX.Element;
6
+ declare function Image({ settings }: ThemeNodeProps): import("react").JSX.Element;
7
+ declare function Products({ settings }: ThemeNodeProps): import("react").JSX.Element;
8
+ export declare const defaultSections: Readonly<{
9
+ "product-detail": ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
10
+ "related-products": ({ settings }: ThemeNodeProps) => import("react").JSX.Element | null;
11
+ "announcement-bar": ({ settings }: ThemeNodeProps) => import("react").JSX.Element | null;
12
+ "image-banner": ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
13
+ slideshow: ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
14
+ "rich-text": ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
15
+ "image-with-text": ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
16
+ multicolumn: ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
17
+ "featured-products": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
18
+ "featured-collection": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
19
+ "collection-list": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
20
+ testimonials: ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
21
+ faq: ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
22
+ video: ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
23
+ "logo-list": ({ settings, children }: ThemeNodeProps) => import("react").JSX.Element;
24
+ hero: typeof Hero;
25
+ products: typeof Products;
26
+ }>;
27
+ export declare const defaultBlocks: Readonly<{
28
+ "product-title": () => import("react").JSX.Element;
29
+ "product-price": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
30
+ "product-options": () => import("react").JSX.Element;
31
+ "product-buy": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
32
+ "product-description": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
33
+ "product-specs": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
34
+ "product-collapsible": ({ settings }: ThemeNodeProps) => import("react").JSX.Element | null;
35
+ "product-text": ({ settings }: ThemeNodeProps) => import("react").JSX.Element | null;
36
+ slide: ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
37
+ column: ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
38
+ testimonial: ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
39
+ "faq-item": ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
40
+ logo: ({ settings }: ThemeNodeProps) => import("react").JSX.Element;
41
+ heading: typeof Heading;
42
+ text: typeof Text;
43
+ button: typeof Button;
44
+ image: typeof Image;
45
+ container: ({ children }: ThemeNodeProps) => import("react").JSX.Element;
46
+ }>;
47
+ export {};
48
+ //# sourceMappingURL=sections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sections.d.ts","sourceRoot":"","sources":["../src/sections.tsx"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,cAAc,EAEpB,MAAM,qBAAqB,CAAC;AAgB7B,iBAAS,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,cAAc,+BAoBnD;AACD,iBAAS,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,+BAS5C;AACD,iBAAS,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,+BAkBzC;AACD,iBAAS,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,+BAW3C;AACD,iBAAS,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,+BA0B1C;AACD,iBAAS,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,+BA2C7C;AACD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;EAK1B,CAAC;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;8BAKE,cAAc;EAKxC,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { EditableField, localizedHref, useStorefront, useThemeRuntime, useThemeComponents, } from "@orunelle/theme-sdk";
4
+ import { libraryBlocks, librarySections, schemeOf } from "./library.js";
5
+ import { productBlocks, productSections } from "./product.js";
6
+ function localized(value, locale) {
7
+ return typeof value === "string"
8
+ ? value
9
+ : value && typeof value === "object" && locale in value
10
+ ? String(value[locale])
11
+ : "";
12
+ }
13
+ function Hero({ settings, children }) {
14
+ const padding = settings.padding;
15
+ const style = {
16
+ ...(typeof settings.background === "string"
17
+ ? { background: settings.background }
18
+ : {}),
19
+ textAlign: settings.align === "center" ? "center" : "start",
20
+ "--section-padding": `${padding?.base ?? 32}px`,
21
+ "--section-padding-sm": `${padding?.sm ?? padding?.base ?? 32}px`,
22
+ "--section-padding-lg": `${padding?.lg ?? padding?.base ?? 32}px`,
23
+ };
24
+ return (_jsx("section", { className: "theme-introduction", "data-scheme": schemeOf(settings), style: style, children: children }));
25
+ }
26
+ function Heading({ settings }) {
27
+ const { locale } = useStorefront();
28
+ return (_jsx("h1", { children: _jsx(EditableField, { name: "text", children: localized(settings.text, locale) }) }));
29
+ }
30
+ function Text({ settings }) {
31
+ const paragraphs = Array.isArray(settings.body)
32
+ ? settings.body
33
+ : [];
34
+ return (_jsx("div", { className: "theme-copy", "data-orunelle-field": "body", children: paragraphs.map((p, index) => (_jsx("p", { children: p.children.map((run, n) => {
35
+ let value = _jsx(_Fragment, { children: run.text });
36
+ if (run.marks.includes("bold"))
37
+ value = _jsx("strong", { children: value });
38
+ if (run.marks.includes("italic"))
39
+ value = _jsx("em", { children: value });
40
+ return _jsx("span", { children: value }, n);
41
+ }) }, index))) }));
42
+ }
43
+ function Button({ settings }) {
44
+ const { locale } = useStorefront();
45
+ const href = typeof settings.href === "string" ? settings.href : "/";
46
+ const destination = localizedHref(href, locale);
47
+ return (_jsx("a", { className: "theme-link-button", href: destination, children: _jsx(EditableField, { name: "label", children: localized(settings.label, locale) }) }));
48
+ }
49
+ function Image({ settings }) {
50
+ const { media, storefront } = useThemeRuntime();
51
+ const [failed, setFailed] = useState(false);
52
+ const value = settings.image;
53
+ const image = value
54
+ ? media.find((image) => image.id === value.assetId)
55
+ : undefined;
56
+ if (!image || failed)
57
+ return (_jsx("p", { className: "sample-notice", role: "status", children: storefront.locale === "ar"
58
+ ? "الصورة غير متاحة؛ مرجعها محفوظ."
59
+ : "Image unavailable; its reference is retained." }));
60
+ return (_jsx("img", { className: "theme-section-image", src: image.url, alt: value?.alt[storefront.locale] || image.alt, onError: () => setFailed(true), style: {
61
+ objectPosition: `${(value?.focalPoint?.x ?? 0.5) * 100}% ${(value?.focalPoint?.y ?? 0.5) * 100}%`,
62
+ } }));
63
+ }
64
+ function Products({ settings }) {
65
+ const { products, storefront, configuration } = useThemeRuntime();
66
+ const { ProductCard } = useThemeComponents();
67
+ const featured = configuration?.settings.featured;
68
+ const featuredId = featured &&
69
+ typeof featured === "object" &&
70
+ "kind" in featured &&
71
+ featured.kind === "product"
72
+ ? featured.id
73
+ : undefined;
74
+ const orderedProducts = featuredId
75
+ ? [
76
+ ...products.filter((product) => product.id === featuredId),
77
+ ...products.filter((product) => product.id !== featuredId),
78
+ ]
79
+ : products;
80
+ return (_jsxs("section", { className: "theme-products", "data-scheme": schemeOf(settings), "data-hide-prices": settings["show-prices"] === false ? "true" : undefined, children: [_jsx("h2", { children: _jsx(EditableField, { name: "title", children: localized(settings.title, storefront.locale) }) }), products.length ? (_jsx("div", { className: "product-grid", children: orderedProducts.map((product) => (_jsx(ProductCard, { product: product }, product.id))) })) : (_jsx("p", { role: "status", children: storefront.locale === "ar"
81
+ ? "لا توجد منتجات للعرض."
82
+ : "There are no products to display." }))] }));
83
+ }
84
+ export const defaultSections = Object.freeze({
85
+ hero: Hero,
86
+ products: Products,
87
+ ...librarySections,
88
+ ...productSections,
89
+ });
90
+ export const defaultBlocks = Object.freeze({
91
+ heading: Heading,
92
+ text: Text,
93
+ button: Button,
94
+ image: Image,
95
+ container: ({ children }) => (_jsx("div", { className: "theme-block-group", children: children })),
96
+ ...libraryBlocks,
97
+ ...productBlocks,
98
+ });
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@orunelle/theme-engine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0-alpha.14",
4
+ "description": "Orunelle theme engine: section library and rendering for storefront themes",
5
+ "license": "UNLICENSED",
6
+ "homepage": "https://orunelle.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Orunelle/frontend.git",
10
+ "directory": "packages/theme-engine"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "tag": "alpha"
15
+ },
16
+ "type": "module",
17
+ "files": [
18
+ "dist",
19
+ "styles.css",
20
+ "sections.css"
21
+ ],
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ },
27
+ "./styles.css": "./styles.css",
28
+ "./sections.css": "./sections.css"
29
+ },
30
+ "dependencies": {
31
+ "@orunelle/theme-contract": "2.0.0-alpha.14",
32
+ "@orunelle/theme-sdk": "2.0.0-alpha.14"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "^19.3.1",
36
+ "@tanstack/react-router": "1.170.46"
37
+ },
38
+ "devDependencies": {
39
+ "@types/react": "19.3.0",
40
+ "react": "19.3.1",
41
+ "@tanstack/react-router": "1.170.46",
42
+ "typescript": "5.9.3"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc && node tools/sections-css.mjs",
46
+ "typecheck": "tsc --noEmit"
47
+ }
6
48
  }