@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,67 @@
|
|
|
1
|
+
import type { CartAddStock, CartRefusal } from '../kit/cart.js';
|
|
2
|
+
import type { AddToCartOptions, DiscountCodeRefusal, DiscountCodeResult } from '../../sdk/runtime-context.js';
|
|
3
|
+
/**
|
|
4
|
+
* The shopper-facing words for a refusal, in the page's language (locales/*.json): the merchant's
|
|
5
|
+
* limit when it is known, else that the most has been reached. A company location's quantity rule (Cart-3)
|
|
6
|
+
* carries no number, so the kit says the quantity is not allowed there; a theme that shows the rule names it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function refusalMessage(t: (key: string, fallback?: string) => string, refusal: CartRefusal): string;
|
|
9
|
+
/**
|
|
10
|
+
* The shopper-facing words for an add stock cut (theme-abi Cart-2), in the page's language (locales/*.json): sold out,
|
|
11
|
+
* only some added, or none added because the cart already holds all that is in stock.
|
|
12
|
+
*/
|
|
13
|
+
export declare function addStockMessage(t: (key: string, fallback?: string) => string, stock: CartAddStock): string;
|
|
14
|
+
/** The well-formed `{ key, value }` string pairs of an add's `options.attributes` (anything else is dropped). */
|
|
15
|
+
export declare function cartLineAttributes(raw: unknown): {
|
|
16
|
+
key: string;
|
|
17
|
+
value: string;
|
|
18
|
+
}[];
|
|
19
|
+
export interface CartActions {
|
|
20
|
+
/**
|
|
21
|
+
* Resolves true when the line is in the cart; never rejects. `options.sellingPlanId` adds a subscription line;
|
|
22
|
+
* `options.attributes` the line's custom attributes. An add stock cut (Cart-2) never opens the cart; it is told in a
|
|
23
|
+
* toast unless `options.showsStock` (the theme reads `lastAddStock`).
|
|
24
|
+
*/
|
|
25
|
+
addToCart: (variantId: string, quantity: number, options?: AddToCartOptions) => Promise<boolean>;
|
|
26
|
+
/** What stock let the last add put in the cart when the platform cut it (Cart-2), else null. */
|
|
27
|
+
lastAddStock: () => CartAddStock | null;
|
|
28
|
+
setQuantity: (lineId: string, quantity: number) => Promise<void>;
|
|
29
|
+
removeLine: (lineId: string) => Promise<void>;
|
|
30
|
+
/** Lines with a request in flight — one slot per line, never one for the whole cart. */
|
|
31
|
+
busyLines: ReadonlySet<string>;
|
|
32
|
+
failedLines: ReadonlySet<string>;
|
|
33
|
+
/** Failed lines the store said why for (Cart-1). */
|
|
34
|
+
refusedLines: ReadonlyMap<string, CartRefusal>;
|
|
35
|
+
setNote: (note: string) => Promise<void>;
|
|
36
|
+
/** Absent when the cart source cannot tell whether a code applied (`CartApi.applyDiscountCode`). */
|
|
37
|
+
applyDiscountCode?: (code: string) => Promise<DiscountCodeResult>;
|
|
38
|
+
removeDiscountCode?: (code: string) => Promise<boolean>;
|
|
39
|
+
lastDiscountRefusal?: () => DiscountCodeRefusal | null;
|
|
40
|
+
lastDiscountReplaced?: () => readonly string[];
|
|
41
|
+
}
|
|
42
|
+
export declare function useCartActions(): CartActions;
|
|
43
|
+
/** Go to a storefront URL through the SPA router when it is on (a real click), else a full load. */
|
|
44
|
+
export declare function navigate(href: string): void;
|
|
45
|
+
export declare const searchHref: (query: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* The URL a Region & language choice loads: `?country=CC` when the country changes, `?locale=ll`
|
|
48
|
+
* when the language changes (the platform honours both and remembers them for later pages). Only
|
|
49
|
+
* what changed is set, so a language switch never pins a country the visitor never picked.
|
|
50
|
+
*/
|
|
51
|
+
export declare function localeHref(href: string, next: {
|
|
52
|
+
countryCode?: string;
|
|
53
|
+
languageCode?: string;
|
|
54
|
+
}, current?: {
|
|
55
|
+
countryCode?: string;
|
|
56
|
+
languageCode?: string;
|
|
57
|
+
}): string | null;
|
|
58
|
+
/** Region & language change: a fresh load, since prices and copy are answered for the new market and language. */
|
|
59
|
+
export declare function changeLocale(next: {
|
|
60
|
+
countryCode?: string;
|
|
61
|
+
languageCode?: string;
|
|
62
|
+
}, current?: {
|
|
63
|
+
countryCode?: string;
|
|
64
|
+
languageCode?: string;
|
|
65
|
+
}): void;
|
|
66
|
+
/** Market change: prices are fetched for a country, so a change is a fresh load (same as the old switcher). */
|
|
67
|
+
export declare function changeCountry(countryCode: string): void;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The actions Nova's sections expose as props, wired to the platform: cart
|
|
3
|
+
* mutations, search, locale/market change. Sections stay presentational; this
|
|
4
|
+
* is the one place a click becomes a request.
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
7
|
+
import { useCart } from '../kit/cart.js';
|
|
8
|
+
import { useT } from '../kit/theme-context.js';
|
|
9
|
+
import { useOpenCartAfterAdd, useOverlays } from '../shell/overlay-state.js';
|
|
10
|
+
/** A quantity change the store refused and said why (theme-abi Cart-1). */
|
|
11
|
+
class RefusedWrite extends Error {
|
|
12
|
+
constructor(refusal) {
|
|
13
|
+
super(refusal.code);
|
|
14
|
+
this.refusal = refusal;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The shopper-facing words for a refusal, in the page's language (locales/*.json): the merchant's
|
|
19
|
+
* limit when it is known, else that the most has been reached. A company location's quantity rule (Cart-3)
|
|
20
|
+
* carries no number, so the kit says the quantity is not allowed there; a theme that shows the rule names it.
|
|
21
|
+
*/
|
|
22
|
+
export function refusalMessage(t, refusal) {
|
|
23
|
+
if (refusal.code === 'quantity_rule')
|
|
24
|
+
return t('cartQuantityRuleRefused', 'This quantity is not allowed for your company location.');
|
|
25
|
+
return refusal.maxQuantity
|
|
26
|
+
? t('cartLimitReached', 'You can buy up to {max} of this item.').replace('{max}', String(refusal.maxQuantity))
|
|
27
|
+
: t('cartLimitReachedAny', "You've reached the maximum quantity for this item.");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The shopper-facing words for an add stock cut (theme-abi Cart-2), in the page's language (locales/*.json): sold out,
|
|
31
|
+
* only some added, or none added because the cart already holds all that is in stock.
|
|
32
|
+
*/
|
|
33
|
+
export function addStockMessage(t, stock) {
|
|
34
|
+
if (stock.code === 'out_of_stock')
|
|
35
|
+
return t('cartSoldOut', 'Sold out. This item is no longer in stock.');
|
|
36
|
+
if (stock.added === 0)
|
|
37
|
+
return t('cartNoMoreStock', 'Your cart already has all we have in stock of this item.');
|
|
38
|
+
if (stock.added === 1)
|
|
39
|
+
return t('cartAddedOnlyOne', "Only 1 was added to your cart. That's all we have in stock.");
|
|
40
|
+
return t('cartAddedOnly', "Only {count} were added to your cart. That's all we have in stock.").replace('{count}', String(stock.added));
|
|
41
|
+
}
|
|
42
|
+
/** The well-formed `{ key, value }` string pairs of an add's `options.attributes` (anything else is dropped). */
|
|
43
|
+
export function cartLineAttributes(raw) {
|
|
44
|
+
if (!Array.isArray(raw))
|
|
45
|
+
return [];
|
|
46
|
+
return raw
|
|
47
|
+
.filter((a) => !!a && typeof a === 'object' && typeof a.key === 'string' && typeof a.value === 'string')
|
|
48
|
+
.map((a) => ({ key: a.key, value: a.value }));
|
|
49
|
+
}
|
|
50
|
+
export function useCartActions() {
|
|
51
|
+
const cart = useCart();
|
|
52
|
+
const overlays = useOverlays();
|
|
53
|
+
const openCartAfterAdd = useOpenCartAfterAdd();
|
|
54
|
+
const [busy, setBusy] = useState(() => new Set());
|
|
55
|
+
const [failed, setFailed] = useState(() => new Set());
|
|
56
|
+
const [refused, setRefused] = useState(() => new Map());
|
|
57
|
+
const t = useT();
|
|
58
|
+
// A second click on the same line while its request is open is dropped: the
|
|
59
|
+
// state update above is async, so the guard reads a ref.
|
|
60
|
+
const inFlight = useRef(new Set());
|
|
61
|
+
const mark = (set, id, on) => set((prev) => {
|
|
62
|
+
const next = new Set(prev);
|
|
63
|
+
if (on)
|
|
64
|
+
next.add(id);
|
|
65
|
+
else
|
|
66
|
+
next.delete(id);
|
|
67
|
+
return next;
|
|
68
|
+
});
|
|
69
|
+
const withLine = useCallback(async (lineId, run) => {
|
|
70
|
+
if (inFlight.current.has(lineId))
|
|
71
|
+
return;
|
|
72
|
+
inFlight.current.add(lineId);
|
|
73
|
+
mark(setBusy, lineId, true);
|
|
74
|
+
mark(setFailed, lineId, false);
|
|
75
|
+
const refuse = (refusal) => setRefused((prev) => {
|
|
76
|
+
if (!refusal && !prev.has(lineId))
|
|
77
|
+
return prev;
|
|
78
|
+
const next = new Map(prev);
|
|
79
|
+
if (refusal)
|
|
80
|
+
next.set(lineId, refusal);
|
|
81
|
+
else
|
|
82
|
+
next.delete(lineId);
|
|
83
|
+
return next;
|
|
84
|
+
});
|
|
85
|
+
refuse(null);
|
|
86
|
+
try {
|
|
87
|
+
await run();
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
mark(setFailed, lineId, true);
|
|
91
|
+
if (e instanceof RefusedWrite)
|
|
92
|
+
refuse(e.refusal);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
inFlight.current.delete(lineId);
|
|
96
|
+
mark(setBusy, lineId, false);
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
const addToCart = useCallback(async (variantId, quantity, options) => {
|
|
100
|
+
const attributes = cartLineAttributes(options?.attributes);
|
|
101
|
+
const ok = await cart.add({ variantId, quantity, ...(options?.sellingPlanId ? { sellingPlanId: options.sellingPlanId } : {}), ...(attributes.length ? { attributes } : {}) });
|
|
102
|
+
// Cart-2: a sold-out or partly added line is said where the shopper is, not hidden behind the opened cart.
|
|
103
|
+
const stock = cart.lastAddStock?.() ?? null;
|
|
104
|
+
if (stock) {
|
|
105
|
+
if (options?.showsStock !== true)
|
|
106
|
+
overlays.toast(addStockMessage(t, stock), ok ? 'default' : 'error');
|
|
107
|
+
return ok;
|
|
108
|
+
}
|
|
109
|
+
if (ok)
|
|
110
|
+
openCartAfterAdd();
|
|
111
|
+
else {
|
|
112
|
+
// Read now, not from `cart.error`: this render's cart predates the add.
|
|
113
|
+
const refusal = cart.lastRefusal?.() ?? null;
|
|
114
|
+
overlays.toast(refusal ? refusalMessage(t, refusal) : t('addFailed', 'This item could not be added to your cart.'), 'error');
|
|
115
|
+
}
|
|
116
|
+
return ok;
|
|
117
|
+
}, [cart, openCartAfterAdd, overlays, t]);
|
|
118
|
+
return useMemo(() => ({
|
|
119
|
+
addToCart,
|
|
120
|
+
lastAddStock: () => cart.lastAddStock?.() ?? null,
|
|
121
|
+
setQuantity: (lineId, quantity) => withLine(lineId, async () => {
|
|
122
|
+
await cart.updateQuantity(lineId, quantity);
|
|
123
|
+
// A refusal the store explained marks the line failed, with its reason (Cart-1).
|
|
124
|
+
const refusal = cart.lastRefusal?.() ?? null;
|
|
125
|
+
if (refusal)
|
|
126
|
+
throw new RefusedWrite(refusal);
|
|
127
|
+
}),
|
|
128
|
+
removeLine: (lineId) => withLine(lineId, () => cart.remove(lineId)),
|
|
129
|
+
busyLines: busy,
|
|
130
|
+
failedLines: failed,
|
|
131
|
+
refusedLines: refused,
|
|
132
|
+
setNote: (note) => cart.updateNote(note),
|
|
133
|
+
...(cart.applyDiscountCode && cart.removeDiscountCode ? { applyDiscountCode: cart.applyDiscountCode, removeDiscountCode: cart.removeDiscountCode } : {}),
|
|
134
|
+
...(cart.lastDiscountRefusal ? { lastDiscountRefusal: cart.lastDiscountRefusal } : {}),
|
|
135
|
+
...(cart.lastDiscountReplaced ? { lastDiscountReplaced: cart.lastDiscountReplaced } : {}),
|
|
136
|
+
}), [addToCart, withLine, cart, busy, failed, refused]);
|
|
137
|
+
}
|
|
138
|
+
/** Go to a storefront URL through the SPA router when it is on (a real click), else a full load. */
|
|
139
|
+
export function navigate(href) {
|
|
140
|
+
if (typeof window === 'undefined')
|
|
141
|
+
return;
|
|
142
|
+
const a = document.createElement('a');
|
|
143
|
+
a.href = href;
|
|
144
|
+
a.hidden = true;
|
|
145
|
+
document.body.appendChild(a);
|
|
146
|
+
a.click();
|
|
147
|
+
a.remove();
|
|
148
|
+
}
|
|
149
|
+
export const searchHref = (query) => `/search?q=${encodeURIComponent(query.trim())}`;
|
|
150
|
+
const LANGUAGE_TAG = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
151
|
+
/**
|
|
152
|
+
* The URL a Region & language choice loads: `?country=CC` when the country changes, `?locale=ll`
|
|
153
|
+
* when the language changes (the platform honours both and remembers them for later pages). Only
|
|
154
|
+
* what changed is set, so a language switch never pins a country the visitor never picked.
|
|
155
|
+
*/
|
|
156
|
+
export function localeHref(href, next, current = {}) {
|
|
157
|
+
const url = new URL(href);
|
|
158
|
+
const country = (next.countryCode ?? '').toUpperCase();
|
|
159
|
+
const language = next.languageCode ?? '';
|
|
160
|
+
let changed = false;
|
|
161
|
+
if (/^[A-Z]{2}$/.test(country) && country !== (current.countryCode ?? '').toUpperCase()) {
|
|
162
|
+
url.searchParams.set('country', country);
|
|
163
|
+
changed = true;
|
|
164
|
+
}
|
|
165
|
+
if (LANGUAGE_TAG.test(language) && language.toLowerCase() !== (current.languageCode ?? '').toLowerCase()) {
|
|
166
|
+
url.searchParams.set('locale', language);
|
|
167
|
+
changed = true;
|
|
168
|
+
}
|
|
169
|
+
if (!changed)
|
|
170
|
+
return null;
|
|
171
|
+
// A new market or language is a new listing: the page number belongs to the old one.
|
|
172
|
+
url.searchParams.delete('page');
|
|
173
|
+
return url.toString();
|
|
174
|
+
}
|
|
175
|
+
/** Region & language change: a fresh load, since prices and copy are answered for the new market and language. */
|
|
176
|
+
export function changeLocale(next, current) {
|
|
177
|
+
if (typeof window === 'undefined')
|
|
178
|
+
return;
|
|
179
|
+
const href = localeHref(window.location.href, next, current);
|
|
180
|
+
if (!href)
|
|
181
|
+
return;
|
|
182
|
+
if (next.countryCode && /^[A-Za-z]{2}$/.test(next.countryCode)) {
|
|
183
|
+
try {
|
|
184
|
+
window.localStorage.setItem('tq-country', next.countryCode.toUpperCase());
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
/* private mode */
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
window.location.href = href;
|
|
191
|
+
}
|
|
192
|
+
/** Market change: prices are fetched for a country, so a change is a fresh load (same as the old switcher). */
|
|
193
|
+
export function changeCountry(countryCode) {
|
|
194
|
+
if (typeof window === 'undefined' || !/^[A-Za-z]{2}$/.test(countryCode))
|
|
195
|
+
return;
|
|
196
|
+
try {
|
|
197
|
+
window.localStorage.setItem('tq-country', countryCode.toUpperCase());
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
/* private mode */
|
|
201
|
+
}
|
|
202
|
+
const url = new URL(window.location.href);
|
|
203
|
+
url.searchParams.set('country', countryCode.toUpperCase());
|
|
204
|
+
window.location.href = url.toString();
|
|
205
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContentNode } from '../kit/types.js';
|
|
2
|
+
/** True where starter text is the point — the editor's "Add section" preview shows a section as its preset reads. */
|
|
3
|
+
export declare const ShowStarterContext: import("react").Context<boolean>;
|
|
4
|
+
/** A node type's setting defaults — what an unset field renders. */
|
|
5
|
+
export type DefaultsOf = (type: string) => Record<string, unknown> | undefined;
|
|
6
|
+
/** A node type's copy fields (text / textarea / richtext) — what a shopper reads. */
|
|
7
|
+
export type CopyFieldsOf = (type: string) => ReadonlySet<string> | undefined;
|
|
8
|
+
/** The node a shopper sees, or null when the section is still starter content. */
|
|
9
|
+
export declare function withoutStarter(node: ContentNode, starter: ReadonlySet<string>, defaultsOf?: DefaultsOf, copyFieldsOf?: CopyFieldsOf): ContentNode | null;
|
|
10
|
+
/** The theme's starter text as a lookup set (built once per theme). */
|
|
11
|
+
export declare function starterSet(list: readonly string[] | undefined): ReadonlySet<string>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starter content on the live storefront (theme `starterText`).
|
|
3
|
+
*
|
|
4
|
+
* A theme's starter templates guide the merchant with instructions in place of
|
|
5
|
+
* content. Those must never reach a shopper: a field still holding one renders
|
|
6
|
+
* empty, a section whose copy is nothing but starter text is not rendered, and
|
|
7
|
+
* a block holding one is left out (a testimonial nobody wrote, a "Milestone 1").
|
|
8
|
+
* A section the merchant wrote copy into stays — an untouched subtext must not
|
|
9
|
+
* take the merchant's own heading down with it, and so does a section holding
|
|
10
|
+
* an app block (theme-abi §7.2): the merchant placed it, so it renders with the
|
|
11
|
+
* section's starter fields emptied. The editor renders nodes as they are, so the
|
|
12
|
+
* merchant still sees every field to fill.
|
|
13
|
+
*/
|
|
14
|
+
import { createContext } from 'react';
|
|
15
|
+
import { isAppBlockType } from '../kit/contract/content.js';
|
|
16
|
+
/** True where starter text is the point — the editor's "Add section" preview shows a section as its preset reads. */
|
|
17
|
+
export const ShowStarterContext = createContext(false);
|
|
18
|
+
const plain = (v) => v.replace(/<[^>]*>/g, '').trim();
|
|
19
|
+
// An unset field renders its default, so a default is checked like a saved value.
|
|
20
|
+
const holdsStarter = (type, settings, starter, defaultsOf) => {
|
|
21
|
+
for (const v of Object.values({ ...defaultsOf?.(type), ...settings }))
|
|
22
|
+
if (typeof v === 'string' && starter.has(v.trim()))
|
|
23
|
+
return true;
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
function pruneBlocks(blocks, starter, defaultsOf) {
|
|
27
|
+
if (!blocks)
|
|
28
|
+
return blocks;
|
|
29
|
+
const kept = [];
|
|
30
|
+
for (const b of blocks) {
|
|
31
|
+
if (holdsStarter(b.type, b.settings, starter, defaultsOf))
|
|
32
|
+
continue;
|
|
33
|
+
kept.push(b.blocks ? { ...b, blocks: pruneBlocks(b.blocks, starter, defaultsOf) } : b);
|
|
34
|
+
}
|
|
35
|
+
return kept;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A section's settings with its starter fields emptied, or null when none of
|
|
39
|
+
* its copy is the merchant's (or its copy fields are unknown).
|
|
40
|
+
*/
|
|
41
|
+
function sectionWithoutStarter(node, starter, defaultsOf, copyFieldsOf) {
|
|
42
|
+
const copy = copyFieldsOf?.(node.type);
|
|
43
|
+
if (!copy)
|
|
44
|
+
return null;
|
|
45
|
+
const merged = { ...defaultsOf?.(node.type), ...node.settings };
|
|
46
|
+
const cleared = {};
|
|
47
|
+
let authored = false;
|
|
48
|
+
for (const [k, v] of Object.entries(merged)) {
|
|
49
|
+
if (typeof v !== 'string')
|
|
50
|
+
continue;
|
|
51
|
+
if (starter.has(v.trim()))
|
|
52
|
+
cleared[k] = '';
|
|
53
|
+
// Only saved copy counts: a default nobody wrote does not keep a section up.
|
|
54
|
+
else if (copy.has(k) && k in (node.settings ?? {}) && plain(v))
|
|
55
|
+
authored = true;
|
|
56
|
+
}
|
|
57
|
+
return authored ? { ...node.settings, ...cleared } : null;
|
|
58
|
+
}
|
|
59
|
+
/** Does any block at any depth of `blocks` place an app's block? */
|
|
60
|
+
const holdsAppBlock = (blocks) => !!blocks?.some((b) => isAppBlockType(b.type) || holdsAppBlock(b.blocks));
|
|
61
|
+
/** A section's settings with every starter value emptied (saved or default), whoever wrote the rest. */
|
|
62
|
+
function starterEmptied(node, starter, defaultsOf) {
|
|
63
|
+
const cleared = {};
|
|
64
|
+
for (const [k, v] of Object.entries({ ...defaultsOf?.(node.type), ...node.settings }))
|
|
65
|
+
if (typeof v === 'string' && starter.has(v.trim()))
|
|
66
|
+
cleared[k] = '';
|
|
67
|
+
return { ...node.settings, ...cleared };
|
|
68
|
+
}
|
|
69
|
+
/** The node a shopper sees, or null when the section is still starter content. */
|
|
70
|
+
export function withoutStarter(node, starter, defaultsOf, copyFieldsOf) {
|
|
71
|
+
if (starter.size === 0)
|
|
72
|
+
return node;
|
|
73
|
+
if (holdsStarter(node.type, node.settings, starter, defaultsOf)) {
|
|
74
|
+
const settings = sectionWithoutStarter(node, starter, defaultsOf, copyFieldsOf);
|
|
75
|
+
// AppBlocks-1: an app block the merchant placed keeps its section up (a reviews app in the starter "Our story"
|
|
76
|
+
// rich text rendered nothing on a live store, 2026-11-23); the section's own starter copy is still emptied
|
|
77
|
+
if (!settings && !holdsAppBlock(pruneBlocks(node.blocks, starter, defaultsOf)))
|
|
78
|
+
return null;
|
|
79
|
+
node = { ...node, settings: settings ?? starterEmptied(node, starter, defaultsOf) };
|
|
80
|
+
}
|
|
81
|
+
if (!node.blocks?.length)
|
|
82
|
+
return node;
|
|
83
|
+
const blocks = pruneBlocks(node.blocks, starter, defaultsOf);
|
|
84
|
+
return blocks && blocks.length === node.blocks.length && blocks.every((b, i) => b === node.blocks[i]) ? node : { ...node, blocks };
|
|
85
|
+
}
|
|
86
|
+
const sets = new WeakMap();
|
|
87
|
+
/** The theme's starter text as a lookup set (built once per theme). */
|
|
88
|
+
export function starterSet(list) {
|
|
89
|
+
if (!list?.length)
|
|
90
|
+
return EMPTY;
|
|
91
|
+
let s = sets.get(list);
|
|
92
|
+
if (!s)
|
|
93
|
+
sets.set(list, (s = new Set(list.map((x) => x.trim()).filter(Boolean))));
|
|
94
|
+
return s;
|
|
95
|
+
}
|
|
96
|
+
const EMPTY = new Set();
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-route document head — title, description, canonical, Open Graph, Twitter
|
|
3
|
+
* card and favicon — computed from the merchant's own SEO fields.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from `browser-entry.tsx` so BOTH entry points can use it: the boot path
|
|
6
|
+
* (which runs once) and the SPA router in `layouts/layout.tsx` (which runs on
|
|
7
|
+
* every soft navigation). Previously only boot applied a head, so every page a
|
|
8
|
+
* shopper reached by clicking kept the previous page's <title>, canonical and
|
|
9
|
+
* og: tags — including the link they then shared.
|
|
10
|
+
*
|
|
11
|
+
* Title precedence: the resource's SEO title verbatim (the merchant owns it) →
|
|
12
|
+
* "<resource title> — <shop>" → the shop name. Description: SEO description →
|
|
13
|
+
* page bodySummary → shop description (home only).
|
|
14
|
+
*/
|
|
15
|
+
import type { DataApi } from '../kit/data.js';
|
|
16
|
+
import type { MetaobjectPage } from '../kit/data.js';
|
|
17
|
+
import { type JsonLd } from './structured-data.js';
|
|
18
|
+
/**
|
|
19
|
+
* A meta description from a resource's own text when the merchant wrote no SEO
|
|
20
|
+
* one: tags stripped, whitespace collapsed, cut at a word near 160 characters
|
|
21
|
+
* (what results pages show).
|
|
22
|
+
*/
|
|
23
|
+
export declare function summary(text: string | null | undefined, max?: number): string;
|
|
24
|
+
/** Build a HeadMeta from a resource's SEO (shared by blog/article, which resolve
|
|
25
|
+
* their SEO asynchronously rather than from the sync bootstrap). */
|
|
26
|
+
export declare function headFrom(seo: {
|
|
27
|
+
title?: string | null;
|
|
28
|
+
description?: string | null;
|
|
29
|
+
keywords?: string[] | null;
|
|
30
|
+
} | null | undefined, resourceTitle: string, shopName: string, fallbackDesc?: string | null, image?: string | null): HeadMeta;
|
|
31
|
+
/**
|
|
32
|
+
* Per-route document head (title + meta description) from the merchant's SEO
|
|
33
|
+
* fields. Precedence — title: the resource's SEO title verbatim (merchant owns
|
|
34
|
+
* it) → "<resource title> — <shop>" → shop name; description: SEO description →
|
|
35
|
+
* page bodySummary → shop description (home only). Runs client-side on every
|
|
36
|
+
* route (the SSG only prerenders home), so product/collection/page pages that
|
|
37
|
+
* are client-rendered still get a correct, unique title + description.
|
|
38
|
+
*/
|
|
39
|
+
export interface HeadMeta {
|
|
40
|
+
title: string;
|
|
41
|
+
description: string;
|
|
42
|
+
keywords: string[];
|
|
43
|
+
/** Absolute URL of the page's lead image, for og:image / twitter:image. */
|
|
44
|
+
image: string;
|
|
45
|
+
/** 'website' for the home page, 'product'/'article' for detail pages. */
|
|
46
|
+
type: string;
|
|
47
|
+
/** Shop name — og:site_name. */
|
|
48
|
+
siteName: string;
|
|
49
|
+
/** Absolute URL for the favicon / tab icon (square brand mark). */
|
|
50
|
+
favicon: string;
|
|
51
|
+
/** schema.org JSON-LD for the page (a Product on product routes), or null. */
|
|
52
|
+
jsonLd?: JsonLd | null;
|
|
53
|
+
}
|
|
54
|
+
/** Resolve a possibly-relative asset URL to an absolute one, against the
|
|
55
|
+
* current origin — social scrapers require absolute og:image URLs. */
|
|
56
|
+
export declare function absUrl(url: string | undefined | null): string;
|
|
57
|
+
/**
|
|
58
|
+
* The metaobject page entry whose head this is: the route's own (`<definitionHandle>/<handle>` equal to the route
|
|
59
|
+
* handle), else null. Exported for tests.
|
|
60
|
+
*/
|
|
61
|
+
export declare function metaobjectHeadSource(entry: MetaobjectPage | null | undefined, routeHandle: string): MetaobjectPage | null;
|
|
62
|
+
export declare function computeHead(pathname: string, data: DataApi, settings: {
|
|
63
|
+
shopName?: unknown;
|
|
64
|
+
},
|
|
65
|
+
/** The request origin on the server render; the browser origin when omitted. */
|
|
66
|
+
origin?: string): HeadMeta;
|
|
67
|
+
/**
|
|
68
|
+
* Write the computed head into the live document (client-side).
|
|
69
|
+
*
|
|
70
|
+
* Beyond title/description/keywords this now emits the canonical link + Open
|
|
71
|
+
* Graph + Twitter card tags that were missing entirely — which is why a shared
|
|
72
|
+
* product link previewed as the bare shop name on every page. The canonical and
|
|
73
|
+
* og:url use the page's own URL (the host the storefront is served on is the
|
|
74
|
+
* correct canonical for that page); forcing canonical to a configured primary
|
|
75
|
+
* domain when a shopper is on a different host is the store-api#558 follow-up.
|
|
76
|
+
*/
|
|
77
|
+
export declare function applyHead({ title, description, keywords, image, type, siteName, favicon, jsonLd }: HeadMeta): void;
|
|
78
|
+
/**
|
|
79
|
+
* The shop's name as the storefront shows it: the store's own name
|
|
80
|
+
* (Settings › General), else the theme's `shopName` setting (an AI-built theme
|
|
81
|
+
* may still carry the name it was built under), else 'Store'. The store name
|
|
82
|
+
* wins so a rename in Settings reaches the header, footer and titles (D-13).
|
|
83
|
+
*/
|
|
84
|
+
export declare function shopNameOf(themeShopName: unknown, storeName: unknown): string;
|
|
85
|
+
/**
|
|
86
|
+
* A route's title: the resource's SEO title verbatim (the merchant owns it),
|
|
87
|
+
* else "<resource title> — <shop>", else the shop name alone.
|
|
88
|
+
*/
|
|
89
|
+
export declare function documentTitle(input: {
|
|
90
|
+
seoTitle?: string | null;
|
|
91
|
+
resourceTitle?: string | null;
|
|
92
|
+
shopName: string;
|
|
93
|
+
}): string;
|
|
94
|
+
/**
|
|
95
|
+
* The page name in the `<title>` of a route that has no resource of its own (board 35 #76): the cart, search, the
|
|
96
|
+
* collections list, a policy and the Not found page each name the page, as "<page> — <shop>" does on a product,
|
|
97
|
+
* instead of the bare shop name on every one of them. The reference storefront does the same: its `page_title` names
|
|
98
|
+
* the cart, the search with its terms, the collection list, the policy and the 404 page, and only the home page takes
|
|
99
|
+
* the shop's own title (Online Store > Preferences; that stays `homeHead`).
|
|
100
|
+
*
|
|
101
|
+
* The words are the theme's strings (`seo.title.*`, translated per language and by the merchant like any theme
|
|
102
|
+
* word), with these English fallbacks for a theme that ships none. `{query}` in `seo.title.searchResults` is the
|
|
103
|
+
* shopper's search; the caller escapes the whole title. Null for every other route (the head keeps its title).
|
|
104
|
+
*/
|
|
105
|
+
export declare const ROUTE_TITLE_FALLBACK: Readonly<Record<string, string>>;
|
|
106
|
+
export declare function routeTitleOf(input: {
|
|
107
|
+
kind: string;
|
|
108
|
+
/** The route's resource is missing (an unknown product, collection, page, blog or policy): a Not found page. */
|
|
109
|
+
missing?: boolean;
|
|
110
|
+
/** The theme's words for the page's language, the merchant's translation first. */
|
|
111
|
+
t: (key: string) => string | undefined;
|
|
112
|
+
searchQuery?: string | null;
|
|
113
|
+
/** The policy's own title (Settings > Policies), on a policy route. */
|
|
114
|
+
policyTitle?: string | null;
|
|
115
|
+
}): string | null;
|