@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.17
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 +125 -10
- package/dist/abi/canvas-live.d.ts +67 -0
- package/dist/abi/canvas-live.js +154 -0
- package/dist/abi/cart.d.ts +59 -0
- package/dist/abi/cart.js +387 -0
- package/dist/abi/convert.d.ts +344 -0
- package/dist/abi/convert.js +1278 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +209 -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 +256 -0
- package/dist/abi/page-data.js +678 -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 +38 -0
- package/dist/abi/wire.js +84 -0
- package/dist/build.d.ts +116 -0
- package/dist/build.js +310 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +87 -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 +540 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +37 -0
- package/dist/headless/index.js +38 -0
- package/dist/headless/money.d.ts +25 -0
- package/dist/headless/money.js +61 -0
- package/dist/headless/page.d.ts +43 -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 +186 -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 +190 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/theme.d.ts +99 -0
- package/dist/headless/theme.js +54 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +18 -553
- package/dist/runtime/data/StoreProvider.d.ts +84 -0
- package/dist/runtime/data/StoreProvider.js +373 -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 +281 -0
- package/dist/runtime/data/to-ui.js +977 -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 +215 -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 +199 -0
- package/dist/runtime/kit/contract/content.js +106 -0
- package/dist/runtime/kit/contract/field-types.d.ts +337 -0
- package/dist/runtime/kit/contract/field-types.js +206 -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 +75 -0
- package/dist/runtime/kit/contract/validate.js +480 -0
- package/dist/runtime/kit/data.d.ts +720 -0
- package/dist/runtime/kit/data.js +1117 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/{types → runtime/kit}/dynamic-source.d.ts +40 -18
- package/dist/runtime/kit/dynamic-source.js +294 -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 +639 -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 +147 -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 +166 -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/section-actions.d.ts +66 -0
- package/dist/runtime/render/section-actions.js +202 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +81 -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 +113 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
- package/dist/runtime/shell/RuntimeBridge.js +93 -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/index.d.ts +26 -0
- package/dist/sdk/index.js +26 -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 +202 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +206 -0
- package/dist/sdk/schema.js +121 -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 +27 -0
- package/dist/sdk/store-lookup.js +29 -0
- package/dist/sdk/store.d.ts +149 -0
- package/dist/sdk/store.js +5 -0
- package/dist/sdk/sx.d.ts +40 -0
- package/dist/sdk/sx.js +112 -0
- package/dist/sdk/theme.d.ts +191 -0
- package/dist/sdk/theme.js +10 -0
- package/dist/sdk/types.d.ts +757 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +111 -0
- package/dist/server.js +533 -0
- package/docs/headless-api.md +220 -0
- package/package.json +76 -22
- 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/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,186 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Search, localization, platform forms, consent and the account slot.
|
|
4
|
+
*
|
|
5
|
+
* <SearchForm /> <form role="search" action="/search"> + <input type="search" name="q" data-tq-search>,
|
|
6
|
+
* with predictive suggestions while typing (browser `data:search`)
|
|
7
|
+
* <LocalizationForm /> <form data-tq-localization>: <select name="country"> + <select name="locale">
|
|
8
|
+
* <NewsletterForm /> <form data-tq-form="newsletter" method="post"> (manifest `forms.newsletter`)
|
|
9
|
+
* <ContactForm /> <form data-tq-form="contact" method="post"> (manifest `forms.contact`)
|
|
10
|
+
* <ConsentBanner /> the cookie banner (data-tq-consent-banner), only when the platform asks for one;
|
|
11
|
+
* never on a preview render (the editor canvas)
|
|
12
|
+
* <AccountSlot /> <iframe data-tq-slot="account">: the platform's account area (customer route)
|
|
13
|
+
*/
|
|
14
|
+
import { useId, useState } from 'react';
|
|
15
|
+
import { useData } from '../../runtime/kit/index.js';
|
|
16
|
+
import { useServerRender } from '../../sdk/server-render.js';
|
|
17
|
+
import { useConsent, useCustomer, useLocalization, usePredictiveSearch, useSearch } from '../hooks.js';
|
|
18
|
+
import { useTranslate } from '../i18n.js';
|
|
19
|
+
import { usePage } from '../page.js';
|
|
20
|
+
import { formatMoney } from '../money.js';
|
|
21
|
+
import { cn, renderChildren, visuallyHidden } from './util.js';
|
|
22
|
+
/** The store search (`GET /search?q=`), with predictive suggestions announced politely as the shopper types. */
|
|
23
|
+
export function SearchForm({ className, inputClassName, buttonClassName, submit = true, resultsClassName, predictive = true, limit = 6, renderResults }) {
|
|
24
|
+
const t = useTranslate();
|
|
25
|
+
const search = useSearch();
|
|
26
|
+
const id = useId();
|
|
27
|
+
const [query, setQuery] = useState(search.query);
|
|
28
|
+
const [dirty, setDirty] = useState(false);
|
|
29
|
+
const { results } = usePredictiveSearch(predictive && dirty ? query : '', { limit });
|
|
30
|
+
const shown = results && (results.products.length > 0 || results.collections.length > 0) ? results : null;
|
|
31
|
+
return (_jsxs("form", { role: "search", action: "/search", method: "get", className: className, children: [_jsx("label", { htmlFor: id, className: visuallyHidden(), children: t('search.search') }), _jsx("input", { id: id, className: inputClassName, type: "search", name: "q", "data-tq-search": "", autoComplete: "off", placeholder: t('search.placeholder'), value: query, onChange: (e) => {
|
|
32
|
+
setQuery(e.target.value);
|
|
33
|
+
setDirty(true);
|
|
34
|
+
}, "aria-describedby": `${id}-results` }), submit ? (_jsx("button", { type: "submit", className: buttonClassName, children: t('search.submit') })) : null, _jsx("div", { id: `${id}-results`, className: resultsClassName, "aria-live": "polite", children: shown ? (renderResults ? (renderResults(shown, query)) : (_jsxs(_Fragment, { children: [_jsx("p", { className: visuallyHidden(), children: t('search.suggestions') }), _jsx("ul", { children: shown.products.map((p) => (_jsx("li", { children: _jsxs("a", { href: p.url, children: [_jsx("span", { children: p.title }), p.price ? _jsxs("span", { children: [" ", formatMoney(p.price)] }) : null] }) }, p.handle))) })] }))) : null })] }));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Market and language selectors (`data-tq-localization`): a GET form with `<select name="country">` and
|
|
38
|
+
* `<select name="locale">`. A choice loads the page for that country (its market's currency, with that currency's
|
|
39
|
+
* decimals) or language. The country list needs the page to read the shopper's country
|
|
40
|
+
* (`storefront.plan.localization`).
|
|
41
|
+
*/
|
|
42
|
+
export function LocalizationForm({ className, labelClassName, label = 'visible', selectClassName, show, countryLabel, children }) {
|
|
43
|
+
const l = useLocalization();
|
|
44
|
+
const t = useTranslate();
|
|
45
|
+
const page = usePage();
|
|
46
|
+
const id = useId();
|
|
47
|
+
let action = '/';
|
|
48
|
+
try {
|
|
49
|
+
action = new URL(page.canonical).pathname;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
action = '/';
|
|
53
|
+
}
|
|
54
|
+
const showCountry = show?.country !== false && l.countries.length > 1;
|
|
55
|
+
const showLanguage = show?.language !== false && l.languages.length > 1;
|
|
56
|
+
if (children)
|
|
57
|
+
return _jsx("form", { method: "get", action: action, className: className, "data-tq-localization": "", children: children(l) });
|
|
58
|
+
if (!showCountry && !showLanguage)
|
|
59
|
+
return null;
|
|
60
|
+
const labelCls = label === 'visible' ? labelClassName : cn(visuallyHidden(), labelClassName);
|
|
61
|
+
const nameOf = countryLabel ?? ((c) => `${c.name} (${c.currencyCode}${c.currencySymbol && c.currencySymbol !== c.currencyCode ? ` ${c.currencySymbol}` : ''})`);
|
|
62
|
+
return (_jsxs("form", { method: "get", action: action, className: className, "data-tq-localization": "", onSubmit: (e) => e.preventDefault(), children: [showCountry ? (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-country`, className: labelCls, children: t('localization.country') }), _jsxs("select", { id: `${id}-country`, name: "country", className: selectClassName, value: l.country?.code ?? '', onChange: (e) => l.changeCountry(e.target.value), children: [l.country ? null : _jsx("option", { value: "", children: "\u2014" }), l.countries.map((c) => (_jsx("option", { value: c.code, children: nameOf(c) }, c.code)))] })] })) : null, showLanguage ? (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-language`, className: labelCls, children: t('localization.language') }), _jsx("select", { id: `${id}-language`, name: "locale", className: selectClassName, value: l.language.code, onChange: (e) => l.changeLanguage(e.target.value), children: l.languages.map((x) => (_jsx("option", { value: x.code, lang: x.code, children: x.name }, x.code))) })] })) : null] }));
|
|
63
|
+
}
|
|
64
|
+
// ── platform forms ─────────────────────────────────────────────────────────
|
|
65
|
+
const FORM_FIELD = '_tq_form';
|
|
66
|
+
const CSRF_FIELD = '_tq_csrf';
|
|
67
|
+
const hiddenValue = (el, name) => (el && el.tagName === 'INPUT' && el.getAttribute('name') === name ? (el.getAttribute('value') ?? '') : null);
|
|
68
|
+
/** The fields the gateway put at the start of `<form data-tq-form="<id>">` in the delivered page, or null. */
|
|
69
|
+
function injectedInto(formId) {
|
|
70
|
+
if (typeof document === 'undefined')
|
|
71
|
+
return null;
|
|
72
|
+
for (const form of Array.from(document.querySelectorAll(`form[data-tq-form="${formId}"]`))) {
|
|
73
|
+
const first = form.firstElementChild;
|
|
74
|
+
if (hiddenValue(first, FORM_FIELD) !== null)
|
|
75
|
+
return { csrf: hiddenValue(first.nextElementSibling, CSRF_FIELD) ?? '' };
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The platform gateway injects `_tq_form` and (with the shopper's token) `_tq_csrf` as the FIRST children of a
|
|
81
|
+
* `<form data-tq-form>` after its cache; the server never renders them. The browser mirrors what the delivered
|
|
82
|
+
* page holds on its hydrating render, so the tree matches the injected markup and a re-render keeps the fields.
|
|
83
|
+
*/
|
|
84
|
+
function GatewayFields({ formId }) {
|
|
85
|
+
const server = useServerRender();
|
|
86
|
+
const [present] = useState(() => (server ? null : injectedInto(formId)));
|
|
87
|
+
if (server || !present)
|
|
88
|
+
return null;
|
|
89
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: FORM_FIELD, value: formId }), present.csrf ? _jsx("input", { type: "hidden", name: CSRF_FIELD, value: present.csrf }) : null] }));
|
|
90
|
+
}
|
|
91
|
+
/** A form the gateway never saw (rendered after hydration) gets the two fields from `<meta name="tq-csrf">` before it posts. */
|
|
92
|
+
function ensureGatewayFields(form, formId) {
|
|
93
|
+
if (form.querySelector(`input[name="${FORM_FIELD}"]`))
|
|
94
|
+
return;
|
|
95
|
+
const token = document.querySelector('meta[name="tq-csrf"]')?.getAttribute('content') ?? '';
|
|
96
|
+
const add = (name, value) => {
|
|
97
|
+
const input = document.createElement('input');
|
|
98
|
+
input.type = 'hidden';
|
|
99
|
+
input.name = name;
|
|
100
|
+
input.value = value;
|
|
101
|
+
form.prepend(input);
|
|
102
|
+
};
|
|
103
|
+
if (/^[A-Za-z0-9_-]+$/.test(token))
|
|
104
|
+
add(CSRF_FIELD, token);
|
|
105
|
+
add(FORM_FIELD, formId);
|
|
106
|
+
}
|
|
107
|
+
/** The bot trap the platform form endpoints read (`website`): off screen, out of the tab order, hidden from assistive technology. */
|
|
108
|
+
function Honeypot() {
|
|
109
|
+
const t = useTranslate();
|
|
110
|
+
return (_jsx("div", { className: visuallyHidden(), "aria-hidden": "true", children: _jsxs("label", { children: [t('form.website'), _jsx("input", { type: "text", name: "website", tabIndex: -1, autoComplete: "off", defaultValue: "" })] }) }));
|
|
111
|
+
}
|
|
112
|
+
function usePlatformForm(formId) {
|
|
113
|
+
const data = useData();
|
|
114
|
+
const t = useTranslate();
|
|
115
|
+
const r = data.formResult && (data.formResult.formId === formId || data.formResult.formId === '*') ? data.formResult : null;
|
|
116
|
+
const [invalidField, setInvalid] = useState(null);
|
|
117
|
+
const status = r ? r.status : 'idle';
|
|
118
|
+
const message = invalidField === 'email' || status === 'invalid' ? t('form.invalidEmail') : status === 'rate_limited' ? t('form.rateLimited') : status === 'unavailable' ? t('form.unavailable') : status === 'expired' ? t('form.expired') : '';
|
|
119
|
+
return { endpoint: data.formEndpoint ?? null, state: { status, email: r?.email ?? '', message, invalidField }, setInvalid };
|
|
120
|
+
}
|
|
121
|
+
const EMAIL = /^[^\s@<>"]+@[^\s@<>"]+\.[^\s@<>"]+$/;
|
|
122
|
+
function submitFor(formId, setInvalid) {
|
|
123
|
+
return (e) => {
|
|
124
|
+
const form = e.currentTarget;
|
|
125
|
+
const email = String(new FormData(form).get('email') ?? '');
|
|
126
|
+
if (form.querySelector('input[name="email"]') && !EMAIL.test(email.trim())) {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
setInvalid('email');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
setInvalid(null);
|
|
132
|
+
ensureGatewayFields(form, formId);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Newsletter sign-up, posted natively to the platform (`<form data-tq-form="newsletter" method="post">`): the
|
|
137
|
+
* store's subscriber list. Declare `forms.newsletter` (fields `email`, `website`) in the manifest. Renders nothing
|
|
138
|
+
* on a host without the platform form endpoint.
|
|
139
|
+
*/
|
|
140
|
+
export function NewsletterForm({ className, inputClassName, buttonClassName, labelClassName, messageClassName, children, done }) {
|
|
141
|
+
const { endpoint, state, setInvalid } = usePlatformForm('newsletter');
|
|
142
|
+
const t = useTranslate();
|
|
143
|
+
const id = useId();
|
|
144
|
+
if (!endpoint)
|
|
145
|
+
return null;
|
|
146
|
+
if (state.status === 'ok')
|
|
147
|
+
return _jsx("p", { className: messageClassName, role: "status", children: done ?? t('newsletter.done') });
|
|
148
|
+
return (_jsxs("form", { method: "post", action: endpoint, className: className, "data-tq-form": "newsletter", noValidate: true, onSubmit: submitFor('newsletter', setInvalid), children: [_jsx(GatewayFields, { formId: "newsletter" }), _jsx(Honeypot, {}), renderChildren(children, state, () => (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-email`, className: labelClassName ?? visuallyHidden(), children: t('form.email') }), _jsx("input", { id: `${id}-email`, className: inputClassName, type: "email", name: "email", autoComplete: "email", required: true, defaultValue: state.email, "aria-invalid": state.invalidField === 'email' || state.status === 'invalid' || undefined, "aria-describedby": state.message ? `${id}-msg` : undefined }), _jsx("button", { type: "submit", className: buttonClassName, children: t('newsletter.subscribe') })] }))), state.message ? (_jsx("p", { id: `${id}-msg`, className: messageClassName, role: "alert", children: state.message })) : null] }));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Contact form, posted natively to the platform (`<form data-tq-form="contact" method="post">`): the message
|
|
152
|
+
* reaches the merchant. Declare `forms.contact` (fields `name`, `email`, `phone`, `message`, `website`).
|
|
153
|
+
*/
|
|
154
|
+
export function ContactForm({ className, inputClassName, buttonClassName, labelClassName, messageClassName, children, done }) {
|
|
155
|
+
const { endpoint, state, setInvalid } = usePlatformForm('contact');
|
|
156
|
+
const t = useTranslate();
|
|
157
|
+
const id = useId();
|
|
158
|
+
if (!endpoint)
|
|
159
|
+
return null;
|
|
160
|
+
if (state.status === 'ok')
|
|
161
|
+
return _jsx("p", { className: messageClassName, role: "status", children: done ?? t('contact.done') });
|
|
162
|
+
const field = (name, key, input) => (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-${name}`, className: labelClassName, children: t(key) }), input] }));
|
|
163
|
+
return (_jsxs("form", { method: "post", action: endpoint, className: className, "data-tq-form": "contact", noValidate: true, onSubmit: submitFor('contact', setInvalid), children: [_jsx(GatewayFields, { formId: "contact" }), _jsx(Honeypot, {}), renderChildren(children, state, () => (_jsxs(_Fragment, { children: [field('name', 'contact.name', _jsx("input", { id: `${id}-name`, className: inputClassName, type: "text", name: "name", autoComplete: "name" })), field('email', 'form.email', _jsx("input", { id: `${id}-email`, className: inputClassName, type: "email", name: "email", autoComplete: "email", required: true, defaultValue: state.email, "aria-invalid": state.invalidField === 'email' || state.status === 'invalid' || undefined })), field('phone', 'contact.phone', _jsx("input", { id: `${id}-phone`, className: inputClassName, type: "tel", name: "phone", autoComplete: "tel" })), field('message', 'contact.message', _jsx("textarea", { id: `${id}-message`, className: inputClassName, name: "message", rows: 5 })), _jsx("button", { type: "submit", className: buttonClassName, children: t('contact.send') })] }))), state.message ? (_jsx("p", { className: messageClassName, role: "alert", children: state.message })) : null] }));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The cookie banner (`data-tq-consent-banner`), shown only while the platform says one is needed and the shopper
|
|
167
|
+
* has not answered; never on a preview render. The merchant's own wording (Settings › Customer privacy) wins.
|
|
168
|
+
* Rendered inside `<div data-tq-client-slot="consent">` (empty in the server HTML).
|
|
169
|
+
*/
|
|
170
|
+
export function ConsentBanner({ className, buttonClassName, acceptClassName, children }) {
|
|
171
|
+
const c = useConsent();
|
|
172
|
+
const t = useTranslate();
|
|
173
|
+
const title = c.text.title ?? t('consent.title');
|
|
174
|
+
// The banner is browser-only (the platform answers consent after hydration): it lives in an empty client
|
|
175
|
+
// slot the server renders, so hydration parity holds (theme-abi §10.5, Hyd-2).
|
|
176
|
+
return _jsx("div", { "data-tq-client-slot": "consent", children: c.required ? (_jsx("section", { className: className, "data-tq-consent-banner": "", "aria-label": title, children: children ? (children(c)) : (_jsxs(_Fragment, { children: [_jsxs("p", { children: [_jsx("strong", { children: title }), " ", c.text.body ?? t('consent.body'), ' ', c.privacyUrl ? _jsx("a", { href: c.privacyUrl, children: c.text.privacyLinkLabel ?? t('consent.privacy') }) : null] }), _jsx("button", { type: "button", className: buttonClassName, onClick: c.reject, children: c.text.declineLabel ?? t('consent.reject') }), _jsx("button", { type: "button", className: cn(buttonClassName, acceptClassName), onClick: c.accept, children: c.text.acceptLabel ?? t('consent.accept') })] })) })) : null });
|
|
177
|
+
}
|
|
178
|
+
// ── account ────────────────────────────────────────────────────────────────
|
|
179
|
+
/** The platform's account area (sign-in, orders, addresses) on the customer route: `<iframe data-tq-slot="account">`. */
|
|
180
|
+
export function AccountSlot({ className, title }) {
|
|
181
|
+
const { accountUrl } = useCustomer();
|
|
182
|
+
const t = useTranslate();
|
|
183
|
+
if (!accountUrl)
|
|
184
|
+
return null;
|
|
185
|
+
return _jsx("iframe", { className: className, "data-tq-slot": "account", src: accountUrl, sandbox: "allow-scripts allow-forms allow-same-origin", title: title ?? t('account.title') });
|
|
186
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared plumbing for the headless primitives: render-prop children, the one visually-hidden class the kit
|
|
3
|
+
* needs (a label that must exist for assistive technology but not on screen), and focus management.
|
|
4
|
+
*
|
|
5
|
+
* The kit ships no CSS. The only rule it adds is `visuallyHidden()`, as an `sx()` class (the platform CSP has
|
|
6
|
+
* `style-src-attr 'none'`, so no `style=""` attribute is ever rendered).
|
|
7
|
+
*/
|
|
8
|
+
import type { ReactNode } from 'react';
|
|
9
|
+
/** Children as nodes, or a function of the primitive's state. */
|
|
10
|
+
export type RenderChildren<S> = ReactNode | ((state: S) => ReactNode);
|
|
11
|
+
export declare function renderChildren<S>(children: RenderChildren<S> | undefined, state: S, fallback: () => ReactNode): ReactNode;
|
|
12
|
+
/** Join class names, skipping empty ones. */
|
|
13
|
+
export declare function cn(...names: Array<string | false | null | undefined>): string | undefined;
|
|
14
|
+
/** A class that hides an element on screen and keeps it for screen readers. */
|
|
15
|
+
export declare function visuallyHidden(): string | undefined;
|
|
16
|
+
/** The focusable elements inside `root`, in DOM order. */
|
|
17
|
+
export declare function focusables(root: Element): HTMLElement[];
|
|
18
|
+
/** Keep Tab / Shift+Tab inside `root` (a modal dialog). */
|
|
19
|
+
export declare function trapTab(e: KeyboardEvent, root: Element): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { sx } from '../../sdk/sx.js';
|
|
2
|
+
export function renderChildren(children, state, fallback) {
|
|
3
|
+
if (typeof children === 'function')
|
|
4
|
+
return children(state);
|
|
5
|
+
return children ?? fallback();
|
|
6
|
+
}
|
|
7
|
+
/** Join class names, skipping empty ones. */
|
|
8
|
+
export function cn(...names) {
|
|
9
|
+
const s = names.filter(Boolean).join(' ');
|
|
10
|
+
return s || undefined;
|
|
11
|
+
}
|
|
12
|
+
/** A class that hides an element on screen and keeps it for screen readers. */
|
|
13
|
+
export function visuallyHidden() {
|
|
14
|
+
return sx({ position: 'absolute', width: 1, height: 1, padding: 0, margin: -1, overflow: 'hidden', clip: 'rect(0 0 0 0)', whiteSpace: 'nowrap', border: 0 });
|
|
15
|
+
}
|
|
16
|
+
const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
17
|
+
/** The focusable elements inside `root`, in DOM order. */
|
|
18
|
+
export function focusables(root) {
|
|
19
|
+
return Array.from(root.querySelectorAll(FOCUSABLE)).filter((e) => !e.hasAttribute('inert') && !e.closest('[inert]'));
|
|
20
|
+
}
|
|
21
|
+
/** Keep Tab / Shift+Tab inside `root` (a modal dialog). */
|
|
22
|
+
export function trapTab(e, root) {
|
|
23
|
+
if (e.key !== 'Tab')
|
|
24
|
+
return;
|
|
25
|
+
const list = focusables(root);
|
|
26
|
+
if (!list.length) {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
root.focus();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const first = list[0];
|
|
32
|
+
const last = list[list.length - 1];
|
|
33
|
+
const active = root.ownerDocument.activeElement;
|
|
34
|
+
if (e.shiftKey && (active === first || !root.contains(active))) {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
last.focus();
|
|
37
|
+
}
|
|
38
|
+
else if (!e.shiftKey && (active === last || !root.contains(active))) {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
first.focus();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words the kit's headless primitives render, per language (pure data: the build reads it in Node too).
|
|
3
|
+
* Keys end in the names the storefront check recognises (`addToCart`, `soldOut`, `checkout`, `remove`, …).
|
|
4
|
+
*/
|
|
5
|
+
export type Strings = Readonly<Record<string, string>>;
|
|
6
|
+
/** Every key exists in every language. */
|
|
7
|
+
export declare const KIT_STRINGS: Readonly<Record<'en' | 'th', Strings>>;
|
|
8
|
+
/** The kit's words for `language` (its base language), English when the kit has none for it. */
|
|
9
|
+
export declare function kitStrings(language: string): Strings;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** Every key exists in every language. */
|
|
2
|
+
export const KIT_STRINGS = {
|
|
3
|
+
en: {
|
|
4
|
+
'a11y.skipToContent': 'Skip to content',
|
|
5
|
+
'a11y.close': 'Close',
|
|
6
|
+
'menu.menu': 'Menu',
|
|
7
|
+
'menu.closeMenu': 'Close menu',
|
|
8
|
+
'product.addToCart': 'Add to cart',
|
|
9
|
+
'product.soldOut': 'Sold out',
|
|
10
|
+
'product.unavailable': 'Unavailable',
|
|
11
|
+
'product.adding': 'Adding…',
|
|
12
|
+
'product.quantity': 'Quantity',
|
|
13
|
+
'product.salePrice': 'Sale price',
|
|
14
|
+
'product.regularPrice': 'Regular price',
|
|
15
|
+
'product.inStock': 'In stock',
|
|
16
|
+
'product.lowStock': 'Only {count} left',
|
|
17
|
+
'product.addFailed': 'This item could not be added to your cart.',
|
|
18
|
+
'cart.openCart': 'Cart',
|
|
19
|
+
'cart.cartCount': 'Cart ({count})',
|
|
20
|
+
'cart.title': 'Your cart',
|
|
21
|
+
'cart.empty': 'Your cart is empty.',
|
|
22
|
+
'cart.checkout': 'Check out',
|
|
23
|
+
'cart.remove': 'Remove',
|
|
24
|
+
'cart.increase': 'Increase quantity',
|
|
25
|
+
'cart.decrease': 'Decrease quantity',
|
|
26
|
+
'cart.quantity': 'Quantity',
|
|
27
|
+
'cart.subtotal': 'Subtotal',
|
|
28
|
+
'cart.total': 'Total',
|
|
29
|
+
'cart.close': 'Close cart',
|
|
30
|
+
'cart.loading': 'Loading your cart…',
|
|
31
|
+
'cart.loadError': "We couldn't load your cart. Retrying…",
|
|
32
|
+
'cart.lineFailed': 'This change could not be saved.',
|
|
33
|
+
'cart.limitReached': 'You can buy up to {max} of this item.',
|
|
34
|
+
'collection.sort': 'Sort',
|
|
35
|
+
'collection.filter': 'Filter',
|
|
36
|
+
'collection.clearFilters': 'Clear filters',
|
|
37
|
+
'collection.loadMore': 'Load more',
|
|
38
|
+
'collection.loading': 'Loading…',
|
|
39
|
+
'collection.productCount': '{count} products',
|
|
40
|
+
'collection.empty': 'No products match these filters.',
|
|
41
|
+
'collection.priceFrom': 'From',
|
|
42
|
+
'collection.priceTo': 'To',
|
|
43
|
+
'collection.loadError': "We couldn't load more products.",
|
|
44
|
+
'collection.pagination': 'Pagination',
|
|
45
|
+
'collection.previous': 'Previous page',
|
|
46
|
+
'sort.featured': 'Featured',
|
|
47
|
+
'sort.best-selling': 'Best selling',
|
|
48
|
+
'sort.title-asc': 'Name, A–Z',
|
|
49
|
+
'sort.title-desc': 'Name, Z–A',
|
|
50
|
+
'sort.price-asc': 'Price, low to high',
|
|
51
|
+
'sort.price-desc': 'Price, high to low',
|
|
52
|
+
'sort.created-desc': 'Newest',
|
|
53
|
+
'sort.created-asc': 'Oldest',
|
|
54
|
+
'sort.relevance': 'Relevance',
|
|
55
|
+
'filter.available': 'Availability',
|
|
56
|
+
'filter.available.true': 'In stock',
|
|
57
|
+
'filter.available.false': 'Out of stock',
|
|
58
|
+
'filter.metafield.true': 'Yes',
|
|
59
|
+
'filter.metafield.false': 'No',
|
|
60
|
+
'filter.vendor': 'Brand',
|
|
61
|
+
'filter.productType': 'Product type',
|
|
62
|
+
'filter.price': 'Price',
|
|
63
|
+
'search.search': 'Search',
|
|
64
|
+
'search.placeholder': 'Search the store',
|
|
65
|
+
'search.submit': 'Search',
|
|
66
|
+
'search.results': '{count} results for “{query}”',
|
|
67
|
+
'search.none': 'No results for “{query}”.',
|
|
68
|
+
'search.suggestions': 'Suggestions',
|
|
69
|
+
'search.products': 'Products',
|
|
70
|
+
'localization.country': 'Country/region',
|
|
71
|
+
'localization.language': 'Language',
|
|
72
|
+
'localization.update': 'Update',
|
|
73
|
+
'consent.title': 'Cookies',
|
|
74
|
+
'consent.body': 'We use cookies to run this store and, with your permission, to measure and improve it.',
|
|
75
|
+
'consent.accept': 'Accept',
|
|
76
|
+
'consent.reject': 'Decline',
|
|
77
|
+
'consent.privacy': 'Privacy policy',
|
|
78
|
+
'form.email': 'Email',
|
|
79
|
+
'form.website': 'Website',
|
|
80
|
+
'form.invalidEmail': 'Enter a valid email address.',
|
|
81
|
+
'form.rateLimited': 'Too many attempts. Please try again in a minute.',
|
|
82
|
+
'form.unavailable': "This form isn't available right now. Please try again later.",
|
|
83
|
+
'form.expired': 'This page expired. Please submit the form again.',
|
|
84
|
+
'newsletter.subscribe': 'Subscribe',
|
|
85
|
+
'newsletter.done': "Thanks — you're on the list.",
|
|
86
|
+
'contact.name': 'Name',
|
|
87
|
+
'contact.phone': 'Phone',
|
|
88
|
+
'contact.message': 'Message',
|
|
89
|
+
'contact.send': 'Send message',
|
|
90
|
+
'contact.done': "Thanks — we'll get back to you soon.",
|
|
91
|
+
'account.title': 'Account',
|
|
92
|
+
'breadcrumbs.home': 'Home',
|
|
93
|
+
},
|
|
94
|
+
th: {
|
|
95
|
+
'a11y.skipToContent': 'ข้ามไปยังเนื้อหา',
|
|
96
|
+
'a11y.close': 'ปิด',
|
|
97
|
+
'menu.menu': 'เมนู',
|
|
98
|
+
'menu.closeMenu': 'ปิดเมนู',
|
|
99
|
+
'product.addToCart': 'เพิ่มลงตะกร้า',
|
|
100
|
+
'product.soldOut': 'สินค้าหมด',
|
|
101
|
+
'product.unavailable': 'ไม่มีจำหน่าย',
|
|
102
|
+
'product.adding': 'กำลังเพิ่ม…',
|
|
103
|
+
'product.quantity': 'จำนวน',
|
|
104
|
+
'product.salePrice': 'ราคาลด',
|
|
105
|
+
'product.regularPrice': 'ราคาปกติ',
|
|
106
|
+
'product.inStock': 'มีสินค้า',
|
|
107
|
+
'product.lowStock': 'เหลือเพียง {count} ชิ้น',
|
|
108
|
+
'product.addFailed': 'ไม่สามารถเพิ่มสินค้านี้ลงตะกร้าได้',
|
|
109
|
+
'cart.openCart': 'ตะกร้า',
|
|
110
|
+
'cart.cartCount': 'ตะกร้า ({count})',
|
|
111
|
+
'cart.title': 'ตะกร้าของคุณ',
|
|
112
|
+
'cart.empty': 'ตะกร้าของคุณว่างอยู่',
|
|
113
|
+
'cart.checkout': 'ชำระเงิน',
|
|
114
|
+
'cart.remove': 'นำออก',
|
|
115
|
+
'cart.increase': 'เพิ่มจำนวน',
|
|
116
|
+
'cart.decrease': 'ลดจำนวน',
|
|
117
|
+
'cart.quantity': 'จำนวน',
|
|
118
|
+
'cart.subtotal': 'ยอดรวมย่อย',
|
|
119
|
+
'cart.total': 'ยอดรวม',
|
|
120
|
+
'cart.close': 'ปิดตะกร้า',
|
|
121
|
+
'cart.loading': 'กำลังโหลดตะกร้า…',
|
|
122
|
+
'cart.loadError': 'โหลดตะกร้าไม่สำเร็จ กำลังลองใหม่…',
|
|
123
|
+
'cart.lineFailed': 'บันทึกการเปลี่ยนแปลงนี้ไม่สำเร็จ',
|
|
124
|
+
'cart.limitReached': 'ซื้อสินค้านี้ได้สูงสุด {max} ชิ้น',
|
|
125
|
+
'collection.sort': 'เรียงตาม',
|
|
126
|
+
'collection.filter': 'ตัวกรอง',
|
|
127
|
+
'collection.clearFilters': 'ล้างตัวกรอง',
|
|
128
|
+
'collection.loadMore': 'โหลดเพิ่ม',
|
|
129
|
+
'collection.loading': 'กำลังโหลด…',
|
|
130
|
+
'collection.productCount': 'สินค้า {count} รายการ',
|
|
131
|
+
'collection.empty': 'ไม่มีสินค้าที่ตรงกับตัวกรองนี้',
|
|
132
|
+
'collection.priceFrom': 'ตั้งแต่',
|
|
133
|
+
'collection.priceTo': 'ถึง',
|
|
134
|
+
'collection.loadError': 'โหลดสินค้าเพิ่มไม่สำเร็จ',
|
|
135
|
+
'collection.pagination': 'การแบ่งหน้า',
|
|
136
|
+
'collection.previous': 'หน้าก่อนหน้า',
|
|
137
|
+
'sort.featured': 'แนะนำ',
|
|
138
|
+
'sort.best-selling': 'ขายดี',
|
|
139
|
+
'sort.title-asc': 'ชื่อ ก–ฮ',
|
|
140
|
+
'sort.title-desc': 'ชื่อ ฮ–ก',
|
|
141
|
+
'sort.price-asc': 'ราคา ต่ำไปสูง',
|
|
142
|
+
'sort.price-desc': 'ราคา สูงไปต่ำ',
|
|
143
|
+
'sort.created-desc': 'ใหม่ล่าสุด',
|
|
144
|
+
'sort.created-asc': 'เก่าที่สุด',
|
|
145
|
+
'sort.relevance': 'ความเกี่ยวข้อง',
|
|
146
|
+
'filter.available': 'สถานะสินค้า',
|
|
147
|
+
'filter.available.true': 'มีสินค้า',
|
|
148
|
+
'filter.available.false': 'สินค้าหมด',
|
|
149
|
+
'filter.metafield.true': 'ใช่',
|
|
150
|
+
'filter.metafield.false': 'ไม่ใช่',
|
|
151
|
+
'filter.vendor': 'แบรนด์',
|
|
152
|
+
'filter.productType': 'ประเภทสินค้า',
|
|
153
|
+
'filter.price': 'ราคา',
|
|
154
|
+
'search.search': 'ค้นหา',
|
|
155
|
+
'search.placeholder': 'ค้นหาในร้าน',
|
|
156
|
+
'search.submit': 'ค้นหา',
|
|
157
|
+
'search.results': 'พบ {count} รายการสำหรับ “{query}”',
|
|
158
|
+
'search.none': 'ไม่พบผลลัพธ์สำหรับ “{query}”',
|
|
159
|
+
'search.suggestions': 'คำแนะนำ',
|
|
160
|
+
'search.products': 'สินค้า',
|
|
161
|
+
'localization.country': 'ประเทศ/ภูมิภาค',
|
|
162
|
+
'localization.language': 'ภาษา',
|
|
163
|
+
'localization.update': 'อัปเดต',
|
|
164
|
+
'consent.title': 'คุกกี้',
|
|
165
|
+
'consent.body': 'เราใช้คุกกี้เพื่อให้ร้านค้าทำงาน และเพื่อวัดผลและปรับปรุงร้านเมื่อคุณอนุญาต',
|
|
166
|
+
'consent.accept': 'ยอมรับ',
|
|
167
|
+
'consent.reject': 'ปฏิเสธ',
|
|
168
|
+
'consent.privacy': 'นโยบายความเป็นส่วนตัว',
|
|
169
|
+
'form.email': 'อีเมล',
|
|
170
|
+
'form.website': 'เว็บไซต์',
|
|
171
|
+
'form.invalidEmail': 'กรุณากรอกอีเมลให้ถูกต้อง',
|
|
172
|
+
'form.rateLimited': 'ลองหลายครั้งเกินไป กรุณาลองใหม่ในอีกสักครู่',
|
|
173
|
+
'form.unavailable': 'แบบฟอร์มนี้ใช้งานไม่ได้ในขณะนี้ กรุณาลองใหม่ภายหลัง',
|
|
174
|
+
'form.expired': 'หน้านี้หมดอายุแล้ว กรุณาส่งแบบฟอร์มอีกครั้ง',
|
|
175
|
+
'newsletter.subscribe': 'สมัครรับข่าวสาร',
|
|
176
|
+
'newsletter.done': 'ขอบคุณ คุณได้สมัครรับข่าวสารแล้ว',
|
|
177
|
+
'contact.name': 'ชื่อ',
|
|
178
|
+
'contact.phone': 'โทรศัพท์',
|
|
179
|
+
'contact.message': 'ข้อความ',
|
|
180
|
+
'contact.send': 'ส่งข้อความ',
|
|
181
|
+
'contact.done': 'ขอบคุณ เราจะติดต่อกลับโดยเร็ว',
|
|
182
|
+
'account.title': 'บัญชี',
|
|
183
|
+
'breadcrumbs.home': 'หน้าแรก',
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
/** The kit's words for `language` (its base language), English when the kit has none for it. */
|
|
187
|
+
export function kitStrings(language) {
|
|
188
|
+
const base = language.split('-')[0].toLowerCase();
|
|
189
|
+
return KIT_STRINGS[base] ?? KIT_STRINGS.en;
|
|
190
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schema.org structured data beside the Product JSON-LD the server render already prints on a product page
|
|
3
|
+
* (runtime/seo/structured-data.ts): a BreadcrumbList for detail pages and a CollectionPage with its ItemList for a
|
|
4
|
+
* collection. Pure (no DOM, no React): the server render builds them from the page's data.
|
|
5
|
+
*
|
|
6
|
+
* Only what the store's data says is claimed; anything unknown is left out rather than invented.
|
|
7
|
+
*/
|
|
8
|
+
import type { JsonLd } from '../runtime/seo/structured-data.js';
|
|
9
|
+
export type { JsonLd };
|
|
10
|
+
export { productJsonLd, homeJsonLd, articleJsonLd, serializeJsonLd, jsonLdTag } from '../runtime/seo/structured-data.js';
|
|
11
|
+
/** `path` against `origin`, only when the result is an absolute http(s) URL on that origin. */
|
|
12
|
+
export declare function absoluteOn(origin: string, path: string): string;
|
|
13
|
+
/** One crumb: a name and, except for the current page, a URL. */
|
|
14
|
+
export interface Crumb {
|
|
15
|
+
name: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
}
|
|
18
|
+
/** A BreadcrumbList from Home → … → the current page, or null with fewer than two named crumbs. */
|
|
19
|
+
export declare function breadcrumbJsonLd(crumbs: readonly Crumb[]): JsonLd | null;
|
|
20
|
+
/** A CollectionPage whose main entity lists the collection's products (first page, at most 24), or null without a title. */
|
|
21
|
+
export declare function collectionJsonLd(collection: {
|
|
22
|
+
title?: string | null;
|
|
23
|
+
description?: string | null;
|
|
24
|
+
products?: readonly {
|
|
25
|
+
handle: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
}[];
|
|
28
|
+
} | null | undefined, ctx: {
|
|
29
|
+
url: string;
|
|
30
|
+
origin: string;
|
|
31
|
+
}): JsonLd | null;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export { productJsonLd, homeJsonLd, articleJsonLd, serializeJsonLd, jsonLdTag } from '../runtime/seo/structured-data.js';
|
|
2
|
+
const SCHEMA = 'https://schema.org';
|
|
3
|
+
const MAX_ITEMS = 24;
|
|
4
|
+
const text = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
5
|
+
/** `path` against `origin`, only when the result is an absolute http(s) URL on that origin. */
|
|
6
|
+
export function absoluteOn(origin, path) {
|
|
7
|
+
try {
|
|
8
|
+
const u = new URL(path, origin);
|
|
9
|
+
return /^https?:$/.test(u.protocol) && u.origin === new URL(origin).origin ? u.toString() : '';
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** A BreadcrumbList from Home → … → the current page, or null with fewer than two named crumbs. */
|
|
16
|
+
export function breadcrumbJsonLd(crumbs) {
|
|
17
|
+
const named = crumbs.filter((c) => text(c.name));
|
|
18
|
+
if (named.length < 2)
|
|
19
|
+
return null;
|
|
20
|
+
return {
|
|
21
|
+
'@context': SCHEMA,
|
|
22
|
+
'@type': 'BreadcrumbList',
|
|
23
|
+
itemListElement: named.map((c, i) => ({
|
|
24
|
+
'@type': 'ListItem',
|
|
25
|
+
position: i + 1,
|
|
26
|
+
name: text(c.name),
|
|
27
|
+
...(c.url ? { item: c.url } : {}),
|
|
28
|
+
})),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** A CollectionPage whose main entity lists the collection's products (first page, at most 24), or null without a title. */
|
|
32
|
+
export function collectionJsonLd(collection, ctx) {
|
|
33
|
+
const name = text(collection?.title);
|
|
34
|
+
if (!collection || !name)
|
|
35
|
+
return null;
|
|
36
|
+
const description = text(collection.description);
|
|
37
|
+
const items = (collection.products ?? [])
|
|
38
|
+
.slice(0, MAX_ITEMS)
|
|
39
|
+
.map((p) => ({ url: absoluteOn(ctx.origin, `/products/${encodeURIComponent(p.handle)}`), name: text(p.title) }))
|
|
40
|
+
.filter((p) => p.url);
|
|
41
|
+
return {
|
|
42
|
+
'@context': SCHEMA,
|
|
43
|
+
'@type': 'CollectionPage',
|
|
44
|
+
name,
|
|
45
|
+
url: ctx.url,
|
|
46
|
+
...(description ? { description } : {}),
|
|
47
|
+
...(items.length
|
|
48
|
+
? {
|
|
49
|
+
mainEntity: {
|
|
50
|
+
'@type': 'ItemList',
|
|
51
|
+
numberOfItems: items.length,
|
|
52
|
+
itemListElement: items.map((p, i) => ({ '@type': 'ListItem', position: i + 1, url: p.url, ...(p.name ? { name: p.name } : {}) })),
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
: {}),
|
|
56
|
+
};
|
|
57
|
+
}
|