@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.19
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/LICENSE +21 -0
- package/README.md +128 -10
- package/dist/abi/canvas-live.d.ts +72 -0
- package/dist/abi/canvas-live.js +159 -0
- package/dist/abi/cart.d.ts +60 -0
- package/dist/abi/cart.js +396 -0
- package/dist/abi/convert.d.ts +360 -0
- package/dist/abi/convert.js +1330 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +213 -0
- package/dist/abi/jcs.d.ts +6 -0
- package/dist/abi/jcs.js +28 -0
- package/dist/abi/labels.d.ts +3 -0
- package/dist/abi/labels.js +34 -0
- package/dist/abi/page-data.d.ts +264 -0
- package/dist/abi/page-data.js +746 -0
- package/dist/abi/page.d.ts +28 -0
- package/dist/abi/page.js +57 -0
- package/dist/abi/referrals.d.ts +23 -0
- package/dist/abi/referrals.js +89 -0
- package/dist/abi/rewards.d.ts +27 -0
- package/dist/abi/rewards.js +82 -0
- package/dist/abi/seo.d.ts +47 -0
- package/dist/abi/seo.js +68 -0
- package/dist/abi/shell.d.ts +23 -0
- package/dist/abi/shell.js +10 -0
- package/dist/abi/state-pack.d.ts +17 -0
- package/dist/abi/state-pack.js +43 -0
- package/dist/abi/wire.d.ts +46 -0
- package/dist/abi/wire.js +114 -0
- package/dist/build.d.ts +121 -0
- package/dist/build.js +401 -0
- package/dist/chunks.d.ts +23 -0
- package/dist/chunks.js +41 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.js +101 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +6 -0
- package/dist/headless/ai.d.ts +132 -0
- package/dist/headless/ai.js +99 -0
- package/dist/headless/hooks.d.ts +276 -0
- package/dist/headless/hooks.js +544 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +44 -0
- package/dist/headless/index.js +48 -0
- package/dist/headless/lazy-component.d.ts +72 -0
- package/dist/headless/lazy-component.js +225 -0
- package/dist/headless/lazy-section.d.ts +38 -0
- package/dist/headless/lazy-section.js +97 -0
- package/dist/headless/model.d.ts +73 -0
- package/dist/headless/model.js +115 -0
- package/dist/headless/money.d.ts +17 -0
- package/dist/headless/money.js +63 -0
- package/dist/headless/page.d.ts +45 -0
- package/dist/headless/page.js +53 -0
- package/dist/headless/platform.d.ts +55 -0
- package/dist/headless/platform.js +77 -0
- package/dist/headless/primitives/cart.d.ts +90 -0
- package/dist/headless/primitives/cart.js +153 -0
- package/dist/headless/primitives/collection.d.ts +68 -0
- package/dist/headless/primitives/collection.js +80 -0
- package/dist/headless/primitives/product.d.ts +101 -0
- package/dist/headless/primitives/product.js +117 -0
- package/dist/headless/primitives/storefront.d.ts +106 -0
- package/dist/headless/primitives/storefront.js +187 -0
- package/dist/headless/primitives/util.d.ts +19 -0
- package/dist/headless/primitives/util.js +42 -0
- package/dist/headless/strings.d.ts +9 -0
- package/dist/headless/strings.js +198 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/tanqory-money.generated.d.ts +493 -0
- package/dist/headless/tanqory-money.generated.js +507 -0
- package/dist/headless/theme.d.ts +109 -0
- package/dist/headless/theme.js +62 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -553
- package/dist/runtime/data/StoreProvider.d.ts +84 -0
- package/dist/runtime/data/StoreProvider.js +380 -0
- package/dist/runtime/data/handle.d.ts +14 -0
- package/dist/runtime/data/handle.js +16 -0
- package/dist/runtime/data/routes.d.ts +87 -0
- package/dist/runtime/data/routes.js +158 -0
- package/dist/runtime/data/to-ui.d.ts +286 -0
- package/dist/runtime/data/to-ui.js +1009 -0
- package/dist/runtime/entries/register.d.ts +9 -0
- package/dist/runtime/entries/register.js +9 -0
- package/dist/runtime/entries/sections.d.ts +16 -0
- package/dist/runtime/entries/sections.js +19 -0
- package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
- package/dist/runtime/kit/SectionTree.js +100 -0
- package/dist/runtime/kit/analytics.d.ts +63 -0
- package/dist/runtime/kit/analytics.js +250 -0
- package/dist/runtime/kit/cart.d.ts +222 -0
- package/dist/runtime/kit/cart.js +545 -0
- package/dist/{types → runtime/kit}/composition.d.ts +1 -1
- package/dist/runtime/kit/composition.js +3 -0
- package/dist/{types → runtime/kit}/config.d.ts +2 -2
- package/dist/runtime/kit/config.js +6 -0
- package/dist/runtime/kit/consent.d.ts +29 -0
- package/dist/runtime/kit/consent.js +159 -0
- package/dist/runtime/kit/contract/content.d.ts +213 -0
- package/dist/runtime/kit/contract/content.js +119 -0
- package/dist/runtime/kit/contract/field-types.d.ts +360 -0
- package/dist/runtime/kit/contract/field-types.js +216 -0
- package/dist/runtime/kit/contract/groups.d.ts +230 -0
- package/dist/runtime/kit/contract/groups.js +402 -0
- package/dist/runtime/kit/contract/index.d.ts +33 -0
- package/dist/runtime/kit/contract/index.js +33 -0
- package/dist/runtime/kit/contract/transform.d.ts +82 -0
- package/dist/runtime/kit/contract/transform.js +133 -0
- package/dist/runtime/kit/contract/validate.d.ts +77 -0
- package/dist/runtime/kit/contract/validate.js +520 -0
- package/dist/runtime/kit/data.d.ts +732 -0
- package/dist/runtime/kit/data.js +1131 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/runtime/kit/dynamic-source.d.ts +118 -0
- package/dist/runtime/kit/dynamic-source.js +311 -0
- package/dist/runtime/kit/index.d.ts +24 -0
- package/dist/runtime/kit/index.js +24 -0
- package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
- package/dist/runtime/kit/jsx-to-json.js +28 -0
- package/dist/{types → runtime/kit}/mount.d.ts +25 -4
- package/dist/runtime/kit/mount.js +124 -0
- package/dist/{types → runtime/kit}/registry.d.ts +1 -1
- package/dist/runtime/kit/registry.js +12 -0
- package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
- package/dist/runtime/kit/ssg.js +56 -0
- package/dist/runtime/kit/storefront.d.ts +652 -0
- package/dist/runtime/kit/storefront.js +723 -0
- package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
- package/dist/runtime/kit/theme-context.js +25 -0
- package/dist/runtime/kit/types.d.ts +155 -0
- package/dist/runtime/kit/types.js +1 -0
- package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
- package/dist/runtime/platform/TrackingPixels.js +63 -0
- package/dist/runtime/platform/environment.d.ts +68 -0
- package/dist/runtime/platform/environment.js +85 -0
- package/dist/runtime/platform/locale.d.ts +27 -0
- package/dist/runtime/platform/locale.js +42 -0
- package/dist/runtime/platform/route-analytics.d.ts +15 -0
- package/dist/runtime/platform/route-analytics.js +72 -0
- package/dist/runtime/platform/safe-href.d.ts +25 -0
- package/dist/runtime/platform/safe-href.js +69 -0
- package/dist/runtime/platform/safe-values.d.ts +37 -0
- package/dist/runtime/platform/safe-values.js +140 -0
- package/dist/runtime/render/SectionRenderer.d.ts +4 -0
- package/dist/runtime/render/SectionRenderer.js +199 -0
- package/dist/runtime/render/listing-query.d.ts +52 -0
- package/dist/runtime/render/listing-query.js +122 -0
- package/dist/runtime/render/localized-copy.d.ts +86 -0
- package/dist/runtime/render/localized-copy.js +129 -0
- package/dist/runtime/render/product-listing.d.ts +11 -0
- package/dist/runtime/render/product-listing.js +243 -0
- package/dist/runtime/render/resolved.d.ts +47 -0
- package/dist/runtime/render/resolved.js +80 -0
- package/dist/runtime/render/section-actions.d.ts +67 -0
- package/dist/runtime/render/section-actions.js +205 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +96 -0
- package/dist/runtime/seo/head.d.ts +115 -0
- package/dist/runtime/seo/head.js +281 -0
- package/dist/runtime/seo/structured-data.d.ts +83 -0
- package/dist/runtime/seo/structured-data.js +252 -0
- package/dist/runtime/shell/PageShell.d.ts +18 -0
- package/dist/runtime/shell/PageShell.js +118 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
- package/dist/runtime/shell/RuntimeBridge.js +124 -0
- package/dist/runtime/shell/overlay-state.d.ts +31 -0
- package/dist/runtime/shell/overlay-state.js +59 -0
- package/dist/runtime/shell/preview-mode.d.ts +2 -0
- package/dist/runtime/shell/preview-mode.js +11 -0
- package/dist/runtime/shell/spa-router.d.ts +14 -0
- package/dist/runtime/shell/spa-router.js +76 -0
- package/dist/runtime/shell/url-redirects.d.ts +6 -0
- package/dist/runtime/shell/url-redirects.js +37 -0
- package/dist/runtime/slots.d.ts +74 -0
- package/dist/runtime/slots.js +16 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.js +40 -0
- package/dist/sdk/app-block.d.ts +29 -0
- package/dist/sdk/app-block.js +22 -0
- package/dist/sdk/font-hooks.d.ts +7 -0
- package/dist/sdk/font-hooks.js +21 -0
- package/dist/sdk/fonts.d.ts +144 -0
- package/dist/sdk/fonts.js +241 -0
- package/dist/sdk/index.d.ts +32 -0
- package/dist/sdk/index.js +36 -0
- package/dist/sdk/motion-hooks.d.ts +23 -0
- package/dist/sdk/motion-hooks.js +46 -0
- package/dist/sdk/motion.d.ts +78 -0
- package/dist/sdk/motion.js +292 -0
- package/dist/sdk/referrals.d.ts +62 -0
- package/dist/sdk/referrals.js +20 -0
- package/dist/sdk/rewards.d.ts +85 -0
- package/dist/sdk/rewards.js +29 -0
- package/dist/sdk/runtime-context.d.ts +230 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +249 -0
- package/dist/sdk/schema.js +168 -0
- package/dist/sdk/server-render.d.ts +8 -0
- package/dist/sdk/server-render.js +12 -0
- package/dist/sdk/store-lookup.d.ts +32 -0
- package/dist/sdk/store-lookup.js +48 -0
- package/dist/sdk/store.d.ts +164 -0
- package/dist/sdk/store.js +5 -0
- package/dist/sdk/sx.d.ts +45 -0
- package/dist/sdk/sx.js +117 -0
- package/dist/sdk/theme.d.ts +212 -0
- package/dist/sdk/theme.js +27 -0
- package/dist/sdk/types.d.ts +789 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +112 -0
- package/dist/server.js +589 -0
- package/dist/vite-chunks.d.ts +10 -0
- package/dist/vite-chunks.js +44 -0
- package/docs/headless-api.md +250 -0
- package/package.json +72 -26
- package/dist/index.js.map +0 -1
- package/dist/ssg-BZ5FYTw7.js +0 -1802
- package/dist/ssg-BZ5FYTw7.js.map +0 -1
- package/dist/ssg.js +0 -8
- package/dist/ssg.js.map +0 -1
- package/dist/types/cart.d.ts +0 -86
- package/dist/types/data.d.ts +0 -357
- package/dist/types/dynamic-source.d.ts +0 -84
- package/dist/types/editor.d.ts +0 -5
- package/dist/types/index.d.ts +0 -20
- package/dist/types/preview-bridge.d.ts +0 -9
- package/dist/types/storefront.d.ts +0 -333
- package/dist/types/types.d.ts +0 -44
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `<ModelViewer>` — a product's 3D model on the storefront, through the PLATFORM's viewer (theme-abi-v2 "Host capability:
|
|
4
|
+
* 3D models"). The ready way to show a model: an AI custom theme has no other (theme-standard refuses its own 3D code),
|
|
5
|
+
* and a partner or first-party theme may use it or build its own (Partner-1). This component adds nothing to the theme
|
|
6
|
+
* bundle but a poster and a button; the viewer
|
|
7
|
+
* (@google/model-viewer 4.0.0, served by the storefront at MODEL_VIEWER_SRC from the shop's own origin) is loaded once
|
|
8
|
+
* per page, only after the shopper asks to see the model, with its Subresource Integrity value (W3C SRI §3.3).
|
|
9
|
+
*
|
|
10
|
+
* media a product media item of `type: 'model'` (`Product.media`): `src` is the same-origin `/_tq/model/…` GLB, `iosSrc`
|
|
11
|
+
* the USDZ for iOS Quick Look when the merchant uploaded one, `poster` the preview image.
|
|
12
|
+
* ar offer "View in your space" (Android Scene Viewer, iOS Quick Look, WebXR); on by default.
|
|
13
|
+
*
|
|
14
|
+
* Accessible: a real `<button>` (keyboard, focus), the model's alt text (else `alt`), the poster as the still, and a
|
|
15
|
+
* text message when the viewer cannot run (no WebGL, a model it refuses). The page CSP needs nothing from the theme:
|
|
16
|
+
* the gateway adds what the viewer needs when the render asserted `x-tq-media: model` (theme-kit does that for any
|
|
17
|
+
* product with a model).
|
|
18
|
+
*/
|
|
19
|
+
import { useContext, useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { modelSrc } from '../runtime/data/to-ui.js';
|
|
21
|
+
import { useTranslate } from './i18n.js';
|
|
22
|
+
import { HeadSinkContext } from './page.js';
|
|
23
|
+
/** The platform viewer (storefront-edge core/viewer-route.ts `MODEL_VIEWER_PATH` / `MODEL_VIEWER_INTEGRITY`). */
|
|
24
|
+
export const MODEL_VIEWER_SRC = '/_tq/viewer/model-viewer-a6a461d0.js';
|
|
25
|
+
export const MODEL_VIEWER_INTEGRITY = 'sha384-6U1WsPbbcCmcM+VtFw4f1C1xP+8qeErdfS/9UwVjKxj1j+HkyFgfWE3RZHXqCNh7';
|
|
26
|
+
/** Where the viewer would look for decoders: a same-origin path that answers 404, so a compressed model fails at once. */
|
|
27
|
+
export const MODEL_VIEWER_NO_DECODERS = '/_tq/viewer/no-decoders/';
|
|
28
|
+
let pending = null;
|
|
29
|
+
/** Defines `<model-viewer>` once per page (the platform file, SRI-pinned); resolves when the element is ready. */
|
|
30
|
+
export function loadModelViewer(doc = document) {
|
|
31
|
+
const w = doc.defaultView;
|
|
32
|
+
if (!w)
|
|
33
|
+
return Promise.reject(new Error('browser only'));
|
|
34
|
+
if (w.customElements?.get('model-viewer'))
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
if (pending)
|
|
37
|
+
return pending;
|
|
38
|
+
// The viewer reads these before it defines the element: no decoder is ever fetched from another origin.
|
|
39
|
+
// meshopt is left unset: set, the viewer inserts a <script> for it on every load; unset, it inserts none.
|
|
40
|
+
w.ModelViewerElement = { ...(w.ModelViewerElement ?? {}), dracoDecoderLocation: MODEL_VIEWER_NO_DECODERS, ktx2TranscoderLocation: MODEL_VIEWER_NO_DECODERS };
|
|
41
|
+
pending = new Promise((resolve, reject) => {
|
|
42
|
+
const s = doc.createElement('script');
|
|
43
|
+
s.type = 'module';
|
|
44
|
+
s.src = MODEL_VIEWER_SRC;
|
|
45
|
+
s.setAttribute('integrity', MODEL_VIEWER_INTEGRITY);
|
|
46
|
+
s.setAttribute('crossorigin', 'anonymous');
|
|
47
|
+
s.onload = () => { w.customElements.whenDefined('model-viewer').then(() => resolve(), reject); };
|
|
48
|
+
s.onerror = () => {
|
|
49
|
+
pending = null;
|
|
50
|
+
s.remove();
|
|
51
|
+
reject(new Error('model-viewer failed to load'));
|
|
52
|
+
};
|
|
53
|
+
doc.head.appendChild(s);
|
|
54
|
+
});
|
|
55
|
+
return pending;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A source as the platform's same-origin model route: a `/_tq/model/…` path as given, or a store-media URL (a `model`
|
|
59
|
+
* setting's value, B.4) mapped onto it (theme-kit `modelSrc`). Anything else is not shown.
|
|
60
|
+
*/
|
|
61
|
+
const routeOf = (u) => (typeof u === 'string' ? modelSrc(u.trim()) : null);
|
|
62
|
+
/** The model with the kit's words for its labels (`useTranslate`: the merchant's, the theme's, then the kit's). */
|
|
63
|
+
export function ModelViewer(props) {
|
|
64
|
+
const t = useTranslate();
|
|
65
|
+
return (_jsx(ModelViewerBase, { ...props, labels: { view3d: t('media.view3d'), loading3d: t('media.loading3d'), unavailable: t('media.model3dUnavailable'), viewInYourSpace: t('media.viewInYourSpace') } }));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `<ModelViewer>` for a theme that has its own words for these four labels (its locale files carry the `media.*` keys).
|
|
69
|
+
* It renders exactly what `<ModelViewer>` renders, but does not use the kit's translations, so the kit's fallback word
|
|
70
|
+
* table (English and Thai) stays out of the theme's client bundle.
|
|
71
|
+
*/
|
|
72
|
+
export function ModelViewerBase({ media, alt, ar = true, className, fallback, labels }) {
|
|
73
|
+
const [state, setState] = useState('idle');
|
|
74
|
+
const ref = useRef(null);
|
|
75
|
+
const sink = useContext(HeadSinkContext);
|
|
76
|
+
const routed = routeOf(media.src);
|
|
77
|
+
const src = routed && routed.endsWith('.glb') ? routed : null;
|
|
78
|
+
const ios = routeOf(media.iosSrc);
|
|
79
|
+
const iosSrc = ios && ios.endsWith('.usdz') ? ios : null;
|
|
80
|
+
// A model rendered on the server makes the page assert `x-tq-media: model`, so the gateway lets the viewer read
|
|
81
|
+
// its textures (a model from a setting, not only one in Product.media; theme-abi §2.6).
|
|
82
|
+
if (src && sink)
|
|
83
|
+
sink.model = true;
|
|
84
|
+
const poster = media.poster?.src ?? media.poster?.url ?? null;
|
|
85
|
+
const label = media.alt || alt || '';
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
const el = ref.current;
|
|
88
|
+
if (state !== 'ready' || !el)
|
|
89
|
+
return;
|
|
90
|
+
const fail = () => setState('failed');
|
|
91
|
+
el.addEventListener('error', fail);
|
|
92
|
+
return () => el.removeEventListener('error', fail);
|
|
93
|
+
}, [state]);
|
|
94
|
+
if (!src)
|
|
95
|
+
return null;
|
|
96
|
+
if (state === 'ready') {
|
|
97
|
+
const attrs = { src, alt: label, 'camera-controls': '', 'touch-action': 'pan-y', 'interaction-prompt': 'none', 'shadow-intensity': '1' };
|
|
98
|
+
if (poster)
|
|
99
|
+
attrs.poster = poster;
|
|
100
|
+
if (ar) {
|
|
101
|
+
attrs.ar = '';
|
|
102
|
+
attrs['ar-modes'] = 'webxr scene-viewer quick-look';
|
|
103
|
+
if (iosSrc)
|
|
104
|
+
attrs['ios-src'] = iosSrc;
|
|
105
|
+
}
|
|
106
|
+
return (_jsx("div", { className: className, "data-tq-model": "", children: _jsx("model-viewer", { ref: ref, ...attrs, children: ar ? _jsx("button", { slot: "ar-button", type: "button", children: labels.viewInYourSpace }) : null }) }));
|
|
107
|
+
}
|
|
108
|
+
const open = () => {
|
|
109
|
+
if (state === 'loading')
|
|
110
|
+
return;
|
|
111
|
+
setState('loading');
|
|
112
|
+
loadModelViewer().then(() => setState('ready'), () => setState('failed'));
|
|
113
|
+
};
|
|
114
|
+
return (_jsxs("div", { className: className, "data-tq-model": "", "data-state": state, children: [fallback ?? (poster ? _jsx("img", { src: poster, alt: "", loading: "lazy", decoding: "async" }) : null), _jsx("button", { type: "button", onClick: open, disabled: state === 'loading', "aria-label": label ? `${labels.view3d}: ${label}` : labels.view3d, children: state === 'loading' ? labels.loading3d : state === 'failed' ? labels.unavailable : labels.view3d })] }));
|
|
115
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A price: `amount` as the data plane sends it (a decimal string) or as the theme types use it (a number). */
|
|
2
|
+
export interface MoneyLike {
|
|
3
|
+
amount: number | string;
|
|
4
|
+
currencyCode: string;
|
|
5
|
+
}
|
|
6
|
+
/** Minor units of an ISO 4217 currency, as amounts carry them (0 for JPY, 2 for USD/THB/IDR, 3 for KWD). */
|
|
7
|
+
export declare function currencyDecimals(currencyCode: string): number;
|
|
8
|
+
/** The symbol the kit prints for a currency, or '' when it prints the code instead. */
|
|
9
|
+
export declare function currencySymbol(currencyCode: string): string;
|
|
10
|
+
export interface FormatMoneyOptions {
|
|
11
|
+
/** `symbol` "$37.50" (default) · `code` "37.50 USD" · `symbol-code` "$37.50 USD" · `amount` "37.50". */
|
|
12
|
+
display?: 'symbol' | 'code' | 'symbol-code' | 'amount';
|
|
13
|
+
/** Drop a zero fraction ("$40" for 40.00). Default false. */
|
|
14
|
+
trimZeros?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** "$37.50", "¥5,600", "฿1,234.00". An amount that is not a number prints as given, with its code. */
|
|
17
|
+
export declare function formatMoney(money: MoneyLike | null | undefined, options?: FormatMoneyOptions): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money as a shopper reads it, in the currency's own minor units (JPY 0 decimals, THB 2, KWD 3).
|
|
3
|
+
*
|
|
4
|
+
* Deterministic on purpose: the server render and the hydrating browser must print the same characters, and
|
|
5
|
+
* `Intl.NumberFormat` currency output differs between engines (symbols, spaces, narrow no-break spaces). The
|
|
6
|
+
* digits are grouped by hand. How many decimals: the platform's one currency table (@tanqory/money, generated copy
|
|
7
|
+
* tanqory-money.generated.ts; docs/STANDARDS.md API-6): ISO 4217's, except HUF, IDR and TWD, which are shown in whole
|
|
8
|
+
* units (CLDR display digits). Never Intl's, which differ by engine and give CLDR's digits for amounts (IQD 0).
|
|
9
|
+
*/
|
|
10
|
+
import { currencyDigits, displayAmount } from './tanqory-money.generated.js';
|
|
11
|
+
const SYMBOLS = {
|
|
12
|
+
USD: '$', THB: '฿', EUR: '€', GBP: '£', JPY: '¥', KRW: '₩', VND: '₫', IDR: 'Rp', SGD: 'S$', HKD: 'HK$', TWD: 'NT$',
|
|
13
|
+
AUD: 'A$', CAD: 'CA$', NZD: 'NZ$', CNY: 'CN¥', INR: '₹', MYR: 'RM', PHP: '₱', CHF: 'CHF ', SEK: 'kr ', NOK: 'kr ',
|
|
14
|
+
DKK: 'kr ', MXN: 'MX$', BRL: 'R$', AED: 'AED ', SAR: 'SAR ', ILS: '₪', TRY: '₺', PLN: 'zł ', ZAR: 'R ',
|
|
15
|
+
};
|
|
16
|
+
/** The amount as shown, exact: its text when it is a decimal, else the number's; null when neither is (1e400). */
|
|
17
|
+
function fixedOf(amount, n, code) {
|
|
18
|
+
for (const v of [amount, n]) {
|
|
19
|
+
try {
|
|
20
|
+
return displayAmount(v, code);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// the next form, then none
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
/** Minor units of an ISO 4217 currency, as amounts carry them (0 for JPY, 2 for USD/THB/IDR, 3 for KWD). */
|
|
29
|
+
export function currencyDecimals(currencyCode) {
|
|
30
|
+
return currencyDigits(currencyCode);
|
|
31
|
+
}
|
|
32
|
+
/** The symbol the kit prints for a currency, or '' when it prints the code instead. */
|
|
33
|
+
export function currencySymbol(currencyCode) {
|
|
34
|
+
return SYMBOLS[String(currencyCode || '').toUpperCase()]?.trim() ?? '';
|
|
35
|
+
}
|
|
36
|
+
/** "$37.50", "¥5,600", "฿1,234.00". An amount that is not a number prints as given, with its code. */
|
|
37
|
+
export function formatMoney(money, options = {}) {
|
|
38
|
+
if (!money)
|
|
39
|
+
return '';
|
|
40
|
+
const code = String(money.currencyCode || '').toUpperCase();
|
|
41
|
+
const n = typeof money.amount === 'number' ? money.amount : Number(money.amount);
|
|
42
|
+
if (!Number.isFinite(n))
|
|
43
|
+
return `${money.amount} ${code}`.trim();
|
|
44
|
+
// Exact decimal text (a JS number's toFixed rounds 1.005 to 1.00); the number itself only when the text is not a decimal.
|
|
45
|
+
const fixed = fixedOf(money.amount, n, code);
|
|
46
|
+
if (fixed === null)
|
|
47
|
+
return `${money.amount} ${code}`.trim();
|
|
48
|
+
let [int, frac = ''] = fixed.replace(/^-/, '').split('.');
|
|
49
|
+
if (options.trimZeros && /^0*$/.test(frac))
|
|
50
|
+
frac = '';
|
|
51
|
+
const digits = `${fixed.startsWith('-') ? '-' : ''}${int.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}${frac ? `.${frac}` : ''}`;
|
|
52
|
+
const symbol = SYMBOLS[code];
|
|
53
|
+
switch (options.display ?? 'symbol') {
|
|
54
|
+
case 'amount':
|
|
55
|
+
return digits;
|
|
56
|
+
case 'code':
|
|
57
|
+
return `${digits} ${code}`;
|
|
58
|
+
case 'symbol-code':
|
|
59
|
+
return symbol ? `${symbol}${digits} ${code}` : `${digits} ${code}`;
|
|
60
|
+
default:
|
|
61
|
+
return symbol ? `${symbol}${digits}` : `${digits} ${code}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** What `usePage()` returns. Every member is public page data (it is printed into the page's state block). */
|
|
2
|
+
export interface PageInfo {
|
|
3
|
+
/** `ctx.route.kind`: `home`, `product`, `collection`, `search`, `cart`, `page`, `blog`, `article`, `policy`, `customer`, `not_found`, `custom:<id>`. */
|
|
4
|
+
kind: string;
|
|
5
|
+
/** The route resource's handle (product, collection, page, blog, article, policy). */
|
|
6
|
+
handle?: string;
|
|
7
|
+
/** The article's blog handle on the `article` kind. */
|
|
8
|
+
blogHandle?: string;
|
|
9
|
+
/** Query params the platform decoded for this route (`page`, `sort`, `q`, `variant`, `tag`, …), strings only. */
|
|
10
|
+
params: Readonly<Record<string, string>>;
|
|
11
|
+
/** `https://<host><path>`: no query, no fragment (`ctx.route.canonical`). */
|
|
12
|
+
canonical: string;
|
|
13
|
+
/** The page's content language (`ctx.locale.language`). */
|
|
14
|
+
language: string;
|
|
15
|
+
/** The language the theme's own strings are drawn from (a bundled `locales/<ui>.json`). */
|
|
16
|
+
ui: string;
|
|
17
|
+
/** Every language the store publishes. */
|
|
18
|
+
languages: readonly string[];
|
|
19
|
+
/** A preview render (the editor canvas or a preview link), not the live storefront. */
|
|
20
|
+
preview: boolean;
|
|
21
|
+
/** Base URL of this artifact's client files (`ctx.assets.base`): `asset:client/<file>` resolves under it. */
|
|
22
|
+
assetsBase: string;
|
|
23
|
+
/** The merchant's dashboard wording for the theme's strings, where it differs from the theme's own (`ctx.data.localization.strings`). */
|
|
24
|
+
strings: Readonly<Record<string, string>>;
|
|
25
|
+
}
|
|
26
|
+
/** A page with no platform around it (a unit test, a component preview): English, the home route, no overrides. */
|
|
27
|
+
export declare const DETACHED_PAGE: PageInfo;
|
|
28
|
+
/** Provided by the server render. In the browser it is absent and the hydration state answers instead. */
|
|
29
|
+
export declare const PageInfoContext: import("react").Context<PageInfo | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Head contributions collected during ONE server render (`<Seo>`): the server reads them after
|
|
32
|
+
* `renderToString` and prints them in `<head>`. Absent in the browser, where `<Seo>` renders nothing.
|
|
33
|
+
*/
|
|
34
|
+
export interface HeadSink {
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
image?: string;
|
|
38
|
+
noindex?: boolean;
|
|
39
|
+
jsonLd: Record<string, unknown>[];
|
|
40
|
+
/** A `<ModelViewer>` rendered on this page (theme-abi §2.6): the page asserts `x-tq-media: model`. */
|
|
41
|
+
model?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare const HeadSinkContext: import("react").Context<HeadSink | null>;
|
|
44
|
+
/** The page this component renders on (route, params, languages, assets, merchant wording). */
|
|
45
|
+
export declare function usePage(): PageInfo;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page facts a headless theme reads that the section data does not carry: which route this is (kind, handle,
|
|
3
|
+
* the query params the platform decoded), the canonical URL, the languages the store publishes, where the
|
|
4
|
+
* artifact's assets live, and the merchant's own wording for the theme's strings.
|
|
5
|
+
*
|
|
6
|
+
* server `createRender({ storefront })` provides the value and copies it into the hydration state (`kit`);
|
|
7
|
+
* browser the same value is read back from that state, so the hydrating render sees the same bytes.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here is cached across renders on the server: the value is created inside `render()`. In the browser a
|
|
10
|
+
* page is one store and one render tree, so the parsed state is kept for the page's lifetime.
|
|
11
|
+
*/
|
|
12
|
+
import { createContext, useContext } from 'react';
|
|
13
|
+
/** A page with no platform around it (a unit test, a component preview): English, the home route, no overrides. */
|
|
14
|
+
export const DETACHED_PAGE = {
|
|
15
|
+
kind: 'home',
|
|
16
|
+
params: {},
|
|
17
|
+
canonical: '',
|
|
18
|
+
language: 'en',
|
|
19
|
+
ui: 'en',
|
|
20
|
+
languages: ['en'],
|
|
21
|
+
preview: false,
|
|
22
|
+
assetsBase: '',
|
|
23
|
+
strings: {},
|
|
24
|
+
};
|
|
25
|
+
/** Provided by the server render. In the browser it is absent and the hydration state answers instead. */
|
|
26
|
+
export const PageInfoContext = createContext(null);
|
|
27
|
+
export const HeadSinkContext = createContext(null);
|
|
28
|
+
let clientPage = null;
|
|
29
|
+
/** The `kit` member of the page's `<script type="application/json" id="tq-state">`, parsed once per page. */
|
|
30
|
+
function pageFromState() {
|
|
31
|
+
if (typeof document === 'undefined')
|
|
32
|
+
return DETACHED_PAGE;
|
|
33
|
+
const el = document.getElementById('tq-state');
|
|
34
|
+
if (!el)
|
|
35
|
+
return DETACHED_PAGE;
|
|
36
|
+
if (clientPage && clientPage.el === el)
|
|
37
|
+
return clientPage.value;
|
|
38
|
+
let value = DETACHED_PAGE;
|
|
39
|
+
try {
|
|
40
|
+
const kit = JSON.parse(el.textContent ?? '{}').kit;
|
|
41
|
+
if (kit && typeof kit === 'object' && typeof kit.kind === 'string')
|
|
42
|
+
value = { ...DETACHED_PAGE, ...kit };
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
value = DETACHED_PAGE;
|
|
46
|
+
}
|
|
47
|
+
clientPage = { el, value };
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
/** The page this component renders on (route, params, languages, assets, merchant wording). */
|
|
51
|
+
export function usePage() {
|
|
52
|
+
return useContext(PageInfoContext) ?? pageFromState();
|
|
53
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform helpers of the headless API: `<Image>` with the platform's asset rules, `<Seo>` for the document head,
|
|
3
|
+
* and `<SkipLink>` to the page's main content.
|
|
4
|
+
*/
|
|
5
|
+
import { type ImgHTMLAttributes, type ReactNode } from 'react';
|
|
6
|
+
import type { Image as ImageData } from '../sdk/types.js';
|
|
7
|
+
import type { JsonLd } from './structured-data.js';
|
|
8
|
+
/**
|
|
9
|
+
* An image URL a page may print: an absolute `https:` URL as given, or `asset:client/<file>` (a file the theme
|
|
10
|
+
* ships, valid in its defaults and presets) under the artifact's asset base. Anything else is refused (null):
|
|
11
|
+
* `http:`, `data:`, `javascript:`, a relative path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveImageUrl(value: string | null | undefined, assetsBase: string): string | null;
|
|
14
|
+
type ImageInput = ImageData | {
|
|
15
|
+
url?: string | null;
|
|
16
|
+
altText?: string | null;
|
|
17
|
+
width?: number | null;
|
|
18
|
+
height?: number | null;
|
|
19
|
+
} | string | null | undefined;
|
|
20
|
+
export interface ImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt'> {
|
|
21
|
+
/** An image from the data (`Product.featuredImage`, a variant's image), or an image setting's value. */
|
|
22
|
+
image?: ImageInput;
|
|
23
|
+
/** Alternative text; the image's own `alt` by default, '' (decorative) when it has none. */
|
|
24
|
+
alt?: string;
|
|
25
|
+
/** What renders when there is no usable image (nothing by default). */
|
|
26
|
+
fallback?: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `<img>` under the platform's asset rules (`resolveImageUrl`), with its intrinsic width and height (no layout
|
|
30
|
+
* shift), lazy loading and async decoding by default.
|
|
31
|
+
*/
|
|
32
|
+
export declare function Image({ image, alt, fallback, loading, decoding, width, height, ...rest }: ImageProps): JSX.Element | null;
|
|
33
|
+
export interface SeoProps {
|
|
34
|
+
/** The document title, verbatim (the default is the resource's SEO title, else "<title> — <shop>"). */
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
/** An absolute https: URL for the share image. */
|
|
38
|
+
image?: string;
|
|
39
|
+
/** Ask search engines not to index this page. */
|
|
40
|
+
noindex?: boolean;
|
|
41
|
+
/** Extra schema.org objects. A Product object is ignored: the render already prints exactly one on a product page. */
|
|
42
|
+
jsonLd?: JsonLd | readonly JsonLd[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What this page says about itself in `<head>`. Rendered in a section or the Layout during the server render
|
|
46
|
+
* (`createRender({ storefront })`); renders nothing itself, and nothing at all in the browser.
|
|
47
|
+
* The defaults need no `<Seo>`: title, description, canonical, Open Graph, hreflang, Product, Collection and
|
|
48
|
+
* Breadcrumb JSON-LD are printed by the render from the page's data.
|
|
49
|
+
*/
|
|
50
|
+
export declare function Seo({ title, description, image, noindex, jsonLd }: SeoProps): null;
|
|
51
|
+
/** "Skip to content": the first focusable element of the page, to `#main` (the `<main>` the section renderer wraps the page body in). */
|
|
52
|
+
export declare function SkipLink({ className }: {
|
|
53
|
+
className?: string;
|
|
54
|
+
}): JSX.Element;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Platform helpers of the headless API: `<Image>` with the platform's asset rules, `<Seo>` for the document head,
|
|
4
|
+
* and `<SkipLink>` to the page's main content.
|
|
5
|
+
*/
|
|
6
|
+
import { useContext } from 'react';
|
|
7
|
+
import { HeadSinkContext, usePage } from './page.js';
|
|
8
|
+
import { useTranslate } from './i18n.js';
|
|
9
|
+
const ASSET = /^asset:client\/([A-Za-z0-9._/-]+)$/;
|
|
10
|
+
/**
|
|
11
|
+
* An image URL a page may print: an absolute `https:` URL as given, or `asset:client/<file>` (a file the theme
|
|
12
|
+
* ships, valid in its defaults and presets) under the artifact's asset base. Anything else is refused (null):
|
|
13
|
+
* `http:`, `data:`, `javascript:`, a relative path.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveImageUrl(value, assetsBase) {
|
|
16
|
+
const v = typeof value === 'string' ? value.trim() : '';
|
|
17
|
+
if (!v)
|
|
18
|
+
return null;
|
|
19
|
+
const asset = ASSET.exec(v);
|
|
20
|
+
if (asset) {
|
|
21
|
+
if (asset[1].split('/').some((seg) => seg === '..' || seg === '.'))
|
|
22
|
+
return null;
|
|
23
|
+
return /^https:\/\//.test(assetsBase) ? `${assetsBase.replace(/\/+$/, '')}/${asset[1]}` : null;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const u = new URL(v);
|
|
27
|
+
return u.protocol === 'https:' && u.hostname ? u.toString() : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `<img>` under the platform's asset rules (`resolveImageUrl`), with its intrinsic width and height (no layout
|
|
35
|
+
* shift), lazy loading and async decoding by default.
|
|
36
|
+
*/
|
|
37
|
+
export function Image({ image, alt, fallback = null, loading = 'lazy', decoding = 'async', width, height, ...rest }) {
|
|
38
|
+
const page = usePage();
|
|
39
|
+
const obj = image && typeof image === 'object' ? image : null;
|
|
40
|
+
const raw = typeof image === 'string' ? image : (obj?.src ?? obj?.url);
|
|
41
|
+
const src = resolveImageUrl(raw, page.assetsBase);
|
|
42
|
+
if (!src)
|
|
43
|
+
return _jsx(_Fragment, { children: fallback });
|
|
44
|
+
const w = width ?? (typeof obj?.width === 'number' && obj.width > 0 ? obj.width : undefined);
|
|
45
|
+
const h = height ?? (typeof obj?.height === 'number' && obj.height > 0 ? obj.height : undefined);
|
|
46
|
+
const srcSet = typeof obj?.srcSet === 'string' ? obj.srcSet : undefined;
|
|
47
|
+
const text = alt ?? (obj?.alt ?? obj?.altText) ?? '';
|
|
48
|
+
return _jsx("img", { ...rest, src: src, ...(srcSet ? { srcSet } : {}), alt: text, ...(w ? { width: w } : {}), ...(h ? { height: h } : {}), loading: loading, decoding: decoding });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What this page says about itself in `<head>`. Rendered in a section or the Layout during the server render
|
|
52
|
+
* (`createRender({ storefront })`); renders nothing itself, and nothing at all in the browser.
|
|
53
|
+
* The defaults need no `<Seo>`: title, description, canonical, Open Graph, hreflang, Product, Collection and
|
|
54
|
+
* Breadcrumb JSON-LD are printed by the render from the page's data.
|
|
55
|
+
*/
|
|
56
|
+
export function Seo({ title, description, image, noindex, jsonLd }) {
|
|
57
|
+
const sink = useContext(HeadSinkContext);
|
|
58
|
+
if (!sink)
|
|
59
|
+
return null;
|
|
60
|
+
if (title?.trim())
|
|
61
|
+
sink.title = title.trim();
|
|
62
|
+
if (description?.trim())
|
|
63
|
+
sink.description = description.trim();
|
|
64
|
+
if (image && /^https:\/\//.test(image))
|
|
65
|
+
sink.image = image;
|
|
66
|
+
if (noindex)
|
|
67
|
+
sink.noindex = true;
|
|
68
|
+
for (const b of jsonLd ? (Array.isArray(jsonLd) ? jsonLd : [jsonLd]) : [])
|
|
69
|
+
if (b && typeof b === 'object')
|
|
70
|
+
sink.jsonLd.push(b);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
/** "Skip to content": the first focusable element of the page, to `#main` (the `<main>` the section renderer wraps the page body in). */
|
|
74
|
+
export function SkipLink({ className }) {
|
|
75
|
+
const t = useTranslate();
|
|
76
|
+
return (_jsx("a", { className: className, href: "#main", children: t('a11y.skipToContent') }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cart primitives. The cart itself is the runtime's (versioned `/_tq/actions/cart.*`, one request per line at a
|
|
3
|
+
* time, conflicts retried); these render its controls.
|
|
4
|
+
*
|
|
5
|
+
* <CartToggle /> <a href="/cart" data-tq-action="cart:open">: opens the drawer (or goes to /cart)
|
|
6
|
+
* <CartDrawer>…</…> role="dialog" aria-modal while open: focus moves in, Tab stays in, Escape closes,
|
|
7
|
+
* focus returns to the opener
|
|
8
|
+
* <CartLine line> one line's state for the controls inside it:
|
|
9
|
+
* <CartLineQuantity /> <input type="number" data-tq-quantity>, saved on Enter / blur
|
|
10
|
+
* <CartLineIncrement /> <CartLineDecrement /> data-tq-action="cart:increment" / step down
|
|
11
|
+
* <CartLineRemove /> data-tq-action="cart:remove"
|
|
12
|
+
* <CheckoutButton /> <a data-tq-action="cart:checkout" href={cart.checkoutUrl}>: checkout is the platform's
|
|
13
|
+
*/
|
|
14
|
+
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ReactNode } from 'react';
|
|
15
|
+
import type { CartLine as CartLineData } from '../../sdk/types.js';
|
|
16
|
+
import type { CartLineRefusal } from '../../sdk/runtime-context.js';
|
|
17
|
+
import { type CartStateHeadless } from '../hooks.js';
|
|
18
|
+
import { type RenderChildren } from './util.js';
|
|
19
|
+
export interface CartToggleProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'children'> {
|
|
20
|
+
/** Open the cart drawer (default). `false`: the link goes to the cart page. */
|
|
21
|
+
drawer?: boolean;
|
|
22
|
+
children?: RenderChildren<{
|
|
23
|
+
itemCount: number;
|
|
24
|
+
isOpen: boolean;
|
|
25
|
+
label: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The header's cart control: a link to `/cart` that opens the drawer instead when there is one. The item count
|
|
30
|
+
* renders in `<span data-tq-client-slot="cart-count">` (the server never knows the shopper's cart); a theme that
|
|
31
|
+
* renders its own count from `children` should do the same.
|
|
32
|
+
*/
|
|
33
|
+
export declare function CartToggle({ drawer, children, onClick, ...rest }: CartToggleProps): JSX.Element;
|
|
34
|
+
export interface CartDrawerProps {
|
|
35
|
+
className?: string;
|
|
36
|
+
/** A full-screen layer behind the dialog; clicking it closes the drawer. */
|
|
37
|
+
backdropClassName?: string;
|
|
38
|
+
/** The dialog's accessible name; "Your cart" by default. */
|
|
39
|
+
label?: string;
|
|
40
|
+
children?: RenderChildren<CartStateHeadless>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The cart drawer's behaviour around the theme's own markup: rendered only while the cart is open (after an add,
|
|
44
|
+
* or from `<CartToggle>`), as a modal dialog that takes focus, keeps Tab inside, closes on Escape and gives focus
|
|
45
|
+
* back to what opened it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function CartDrawer({ className, backdropClassName, label, children }: CartDrawerProps): JSX.Element;
|
|
48
|
+
export interface CartLineState {
|
|
49
|
+
line: CartLineData;
|
|
50
|
+
busy: boolean;
|
|
51
|
+
failed: boolean;
|
|
52
|
+
refusal: CartLineRefusal | null;
|
|
53
|
+
setQuantity(quantity: number): Promise<void>;
|
|
54
|
+
increment(): Promise<void>;
|
|
55
|
+
decrement(): Promise<void>;
|
|
56
|
+
remove(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/** The enclosing `<CartLine>`'s state, or null outside one. */
|
|
59
|
+
export declare function useCartLine(): CartLineState | null;
|
|
60
|
+
export interface CartLineProps {
|
|
61
|
+
line: CartLineData;
|
|
62
|
+
/** `li` by default (lines are a list); `div` or `tr` for other layouts. */
|
|
63
|
+
as?: 'li' | 'div' | 'tr' | 'article';
|
|
64
|
+
className?: string;
|
|
65
|
+
children?: RenderChildren<CartLineState>;
|
|
66
|
+
}
|
|
67
|
+
/** One cart line: gives the line's controls their line (and marks busy / failed lines with data attributes). */
|
|
68
|
+
export declare function CartLine({ line, as, className, children }: CartLineProps): JSX.Element;
|
|
69
|
+
export interface CartLineQuantityProps {
|
|
70
|
+
className?: string;
|
|
71
|
+
labelClassName?: string;
|
|
72
|
+
label?: 'visible' | 'hidden';
|
|
73
|
+
}
|
|
74
|
+
/** The line's quantity (`data-tq-quantity`): typed freely, saved on Enter or when it loses focus; 0 removes the line. */
|
|
75
|
+
export declare function CartLineQuantity({ className, labelClassName, label }: CartLineQuantityProps): JSX.Element;
|
|
76
|
+
type LineButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'onClick'> & {
|
|
77
|
+
children?: ReactNode;
|
|
78
|
+
};
|
|
79
|
+
/** Quantity + 1 (`data-tq-action="cart:increment"`). Its accessible name is the "Increase quantity" string. */
|
|
80
|
+
export declare function CartLineIncrement({ children, disabled, ...rest }: LineButtonProps): JSX.Element;
|
|
81
|
+
/** Quantity − 1; at 1 it removes the line. Its accessible name is the "Decrease quantity" string. */
|
|
82
|
+
export declare function CartLineDecrement({ children, disabled, ...rest }: LineButtonProps): JSX.Element;
|
|
83
|
+
/** Remove the line (`data-tq-action="cart:remove"`). */
|
|
84
|
+
export declare function CartLineRemove({ children, disabled, ...rest }: LineButtonProps): JSX.Element;
|
|
85
|
+
export interface CheckoutButtonProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
|
86
|
+
children?: ReactNode;
|
|
87
|
+
}
|
|
88
|
+
/** The checkout link: exactly `Cart.checkoutUrl` (`data-tq-action="cart:checkout"`). Checkout never renders in a theme. */
|
|
89
|
+
export declare function CheckoutButton({ children, ...rest }: CheckoutButtonProps): JSX.Element;
|
|
90
|
+
export {};
|