@usethrottle/storefront-react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +67 -0
- package/README.md +119 -2
- package/dist/StorefrontProvider-Br4wUHui.d.cts +559 -0
- package/dist/StorefrontProvider-DLEPEjg6.d.ts +559 -0
- package/dist/account/index.cjs +69 -0
- package/dist/account/index.cjs.map +1 -0
- package/dist/account/index.d.cts +23 -0
- package/dist/account/index.d.ts +23 -0
- package/dist/account/index.js +68 -0
- package/dist/account/index.js.map +1 -0
- package/dist/chunk-2LCPIY2P.cjs +16 -0
- package/dist/chunk-2LCPIY2P.cjs.map +1 -0
- package/dist/chunk-3A72UY6T.js +2126 -0
- package/dist/chunk-3A72UY6T.js.map +1 -0
- package/dist/chunk-3JMIVAHN.js +185 -0
- package/dist/chunk-3JMIVAHN.js.map +1 -0
- package/dist/chunk-4J6AGWNC.cjs +24 -0
- package/dist/chunk-4J6AGWNC.cjs.map +1 -0
- package/dist/chunk-4U6MYDZV.js +17 -0
- package/dist/chunk-4U6MYDZV.js.map +1 -0
- package/dist/chunk-66HDJVPS.js +22 -0
- package/dist/chunk-66HDJVPS.js.map +1 -0
- package/dist/chunk-6X2OZSNV.cjs +83 -0
- package/dist/chunk-6X2OZSNV.cjs.map +1 -0
- package/dist/chunk-6ZMMZ245.cjs +2127 -0
- package/dist/chunk-6ZMMZ245.cjs.map +1 -0
- package/dist/chunk-7R37CVAB.cjs +23 -0
- package/dist/chunk-7R37CVAB.cjs.map +1 -0
- package/dist/chunk-A3IFWQUV.js +368 -0
- package/dist/chunk-A3IFWQUV.js.map +1 -0
- package/dist/chunk-AYC2YK4E.cjs +95 -0
- package/dist/chunk-AYC2YK4E.cjs.map +1 -0
- package/dist/chunk-AZV5U7YB.cjs +18 -0
- package/dist/chunk-AZV5U7YB.cjs.map +1 -0
- package/dist/chunk-CE2SKNQP.cjs +71 -0
- package/dist/chunk-CE2SKNQP.cjs.map +1 -0
- package/dist/chunk-D76CRI4X.js +2175 -0
- package/dist/chunk-D76CRI4X.js.map +1 -0
- package/dist/chunk-DOAII637.cjs +186 -0
- package/dist/chunk-DOAII637.cjs.map +1 -0
- package/dist/chunk-DYHHAOMG.cjs +17 -0
- package/dist/chunk-DYHHAOMG.cjs.map +1 -0
- package/dist/chunk-EYSVU5SJ.js +196 -0
- package/dist/chunk-EYSVU5SJ.js.map +1 -0
- package/dist/chunk-HSUUDZWS.js +37 -0
- package/dist/chunk-HSUUDZWS.js.map +1 -0
- package/dist/chunk-HZ6VEN6Q.cjs +101 -0
- package/dist/chunk-HZ6VEN6Q.cjs.map +1 -0
- package/dist/chunk-IJOTLGPT.js +16 -0
- package/dist/chunk-IJOTLGPT.js.map +1 -0
- package/dist/chunk-ISDATHVC.js +219 -0
- package/dist/chunk-ISDATHVC.js.map +1 -0
- package/dist/chunk-LW2A6USV.js +100 -0
- package/dist/chunk-LW2A6USV.js.map +1 -0
- package/dist/chunk-M4YXSLRG.cjs +369 -0
- package/dist/chunk-M4YXSLRG.cjs.map +1 -0
- package/dist/chunk-NDUEJJLP.cjs +2176 -0
- package/dist/chunk-NDUEJJLP.cjs.map +1 -0
- package/dist/chunk-NNE4FYRT.js +820 -0
- package/dist/chunk-NNE4FYRT.js.map +1 -0
- package/dist/chunk-NW3EFHY2.js +15 -0
- package/dist/chunk-NW3EFHY2.js.map +1 -0
- package/dist/chunk-NZRUQUN5.js +167 -0
- package/dist/chunk-NZRUQUN5.js.map +1 -0
- package/dist/chunk-P6HHE57S.cjs +38 -0
- package/dist/chunk-P6HHE57S.cjs.map +1 -0
- package/dist/chunk-PHY7AY27.cjs +197 -0
- package/dist/chunk-PHY7AY27.cjs.map +1 -0
- package/dist/chunk-PNJOFFTL.cjs +128 -0
- package/dist/chunk-PNJOFFTL.cjs.map +1 -0
- package/dist/chunk-PXZQ4ONA.js +127 -0
- package/dist/chunk-PXZQ4ONA.js.map +1 -0
- package/dist/chunk-Q3VTUBPP.js +82 -0
- package/dist/chunk-Q3VTUBPP.js.map +1 -0
- package/dist/chunk-Q3XFD5UI.js +45 -0
- package/dist/chunk-Q3XFD5UI.js.map +1 -0
- package/dist/chunk-QM7KTT7F.js +94 -0
- package/dist/chunk-QM7KTT7F.js.map +1 -0
- package/dist/chunk-RLWZOLXL.js +70 -0
- package/dist/chunk-RLWZOLXL.js.map +1 -0
- package/dist/chunk-SV53BRP2.js +23 -0
- package/dist/chunk-SV53BRP2.js.map +1 -0
- package/dist/chunk-VWXJO427.cjs +821 -0
- package/dist/chunk-VWXJO427.cjs.map +1 -0
- package/dist/chunk-WIIOJDHR.cjs +220 -0
- package/dist/chunk-WIIOJDHR.cjs.map +1 -0
- package/dist/chunk-XQHGFWLG.cjs +46 -0
- package/dist/chunk-XQHGFWLG.cjs.map +1 -0
- package/dist/chunk-ZHCXI2ZZ.cjs +168 -0
- package/dist/chunk-ZHCXI2ZZ.cjs.map +1 -0
- package/dist/index-RSj2Rg62.d.cts +8 -0
- package/dist/index-RSj2Rg62.d.ts +8 -0
- package/dist/index.cjs +2829 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1718 -0
- package/dist/index.d.ts +1718 -0
- package/dist/index.js +2828 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata-QhKw-tvz.d.cts +188 -0
- package/dist/metadata-QhKw-tvz.d.ts +188 -0
- package/dist/next/client.cjs +84 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.cts +40 -0
- package/dist/next/client.d.ts +40 -0
- package/dist/next/client.js +83 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/index.cjs +1090 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +218 -0
- package/dist/next/index.d.ts +218 -0
- package/dist/next/index.js +1049 -0
- package/dist/next/index.js.map +1 -0
- package/dist/server/index.cjs +994 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +229 -0
- package/dist/server/index.d.ts +229 -0
- package/dist/server/index.js +951 -0
- package/dist/server/index.js.map +1 -0
- package/dist/styles.css +2111 -0
- package/dist/use-part-DCfFk7kf.d.ts +24 -0
- package/dist/use-part-DgjPBL_O.d.cts +24 -0
- package/package.json +121 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-HZ6VEN6Q.cjs","../src/url/routes.ts","../src/analytics/items.ts","../src/pieces/Money.tsx","../src/pieces/Price.tsx","../src/pieces/StarRating.tsx"],"names":["jsxs","jsx"],"mappings":"AAAA,6rBAAY;AACZ;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACNA,IAAM,KAAA,EAAO,CAAC,OAAA,EAAiB,IAAA,EAAc,KAAA,EAAA,GAC3C,OAAA,CAAQ,KAAA,CAAM,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,CAAG,CAAA,CAAE,IAAA,CAAK,kBAAA,CAAmB,KAAK,CAAC,CAAA;AAQpD,SAAS,SAAA,CACd,QAAA,EACA,IAAA,EACA,KAAA,EACA,IAAA,EACQ;AACR,EAAA,GAAA,CAAI,KAAA,IAAS,QAAA,EAAU,OAAO,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,MAAA,EAAQ,GAAA,EAAK,KAAK,CAAA;AACrE,EAAA,MAAM,QAAA,EAAU,KAAA,IAAS,OAAA,mBAAU,IAAA,2BAAM,MAAA,qBAAO,OAAA,EAAO,IAAA,CAAK,MAAA,CAAO,KAAA,EAAO,QAAA,CAAS,MAAA,CAAO,IAAI,CAAA;AAC9F,EAAA,OAAO,IAAA,CAAK,OAAA,EAAS,KAAA,IAAS,MAAA,EAAQ,MAAA,EAAQ,QAAA,EAAU,KAAK,CAAA;AAC/D;ADLA;AACA;AEhBA,2CAAgC;AAGhC,IAAM,QAAA,EAAU,CAAC,KAAA,EAAe,QAAA,EAAA,GAA6B,MAAA,CAAO,oCAAA,K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AK,EAAA;AAChC,EAAA,uBACED,8BAAAA,MAAC,EAAA,EAAM,GAAG,IAAA,EAAM,WAAA,EAAW,IAAA,EACzB,QAAA,EAAA;AAAA,oBAAAC,6BAAAA,MAAC,EAAA,EAAM,GAAG,KAAA,EAAO,IAAA,EAAK,KAAA,EAAM,YAAA,EAAY,KAAA,EACrC,QAAA,EAAA,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,EAAA,mBACVA,6BAAAA,QAAC,EAAA,EAAa,IAAA,EAAM,OAAA,GAAU,EAAA,EAAI,EAAA,EAAI,OAAA,EAAS,OAAA,IAAW,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,YAAA,EAAc,YAAA,EAAc,IAAA,EAAM,GAAA,CAAA,EAA7F,CAAiG,CAC7G,EAAA,CACH,CAAA;AAAA,IACC,MAAA,IAAU,KAAA,EAAA,kBACTA,6BAAAA,MAAC,EAAA,EAAM,GAAG,SAAA,EAAW,aAAA,EAAY,MAAA,EAC9B,QAAA,EAAA,CAAA,CAAE,qBAAA,EAAuB,EAAE,MAAM,CAAC,EAAA,CACrC,EAAA,EACE;AAAA,EAAA,EAAA,CACN,CAAA;AAEJ;AL8CA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,4IAAC","file":"/home/runner/work/app-throttle/app-throttle/packages/storefront-react/dist/chunk-HZ6VEN6Q.cjs","sourcesContent":[null,"import type { NormalizedSettings } from '../settings/normalize';\nimport type { ResolvedSiteDesign } from '../site/resolve';\n\nconst fill = (pattern: string, name: string, value: string) =>\n pattern.split(`{${name}}`).join(encodeURIComponent(value));\n\n/**\n * A link by the store's route patterns (`settings.routes`). `'page'` uses the\n * site design's page route when it names one (a Builder site owns it), and\n * `'search'` fills `{q}`. Ported from Meridian `lib/menu.ts`\n * (`routeHref` / `searchHref`). Server-safe.\n */\nexport function routeHref(\n settings: NormalizedSettings,\n kind: 'product' | 'collection' | 'category' | 'tag' | 'page' | 'search',\n value: string,\n site?: ResolvedSiteDesign,\n): string {\n if (kind === 'search') return fill(settings.routes.search, 'q', value);\n const pattern = kind === 'page' && site?.routes.page ? site.routes.page : settings.routes[kind];\n return fill(pattern, kind === 'tag' ? 'tag' : 'handle', value);\n}\n","import type { ListProduct, StorefrontProduct } from '@usethrottle/catalog';\nimport { toDecimalString } from '@usethrottle/money';\nimport type { Ga4Item } from './types';\n\nconst decimal = (minor: number, currency: string): number => Number(toDecimalString(minor, currency));\n\n/**\n * A GA4 item for a product. The price is the chosen variant's (`variantSku`),\n * else the product's lowest, as a decimal amount through `@usethrottle/money`.\n */\nexport function toGa4Item(\n product: ListProduct | StorefrontProduct,\n o: { index?: number; listName?: string; variantSku?: string | null; quantity?: number } = {},\n): Ga4Item {\n const variant = o.variantSku ? product.variants?.find((v) => v.sku === o.variantSku) : undefined;\n const currency = variant?.currency ?? product.priceRange?.currency;\n const minor = variant ? (variant.salePriceMinor ?? variant.priceMinor) : product.priceRange?.minMinor;\n return {\n item_id: variant?.sku ?? product.handle,\n item_name: product.title ?? product.handle,\n ...(product.brand ? { item_brand: product.brand } : {}),\n ...(variant?.title ? { item_variant: variant.title } : {}),\n ...(o.listName ? { item_list_name: o.listName } : {}),\n ...(o.index !== undefined ? { index: o.index } : {}),\n ...(minor !== null && minor !== undefined && currency ? { price: decimal(minor, currency) } : {}),\n ...(o.quantity !== undefined ? { quantity: o.quantity } : {}),\n };\n}\n","import { formatMoney } from '@usethrottle/money';\nimport { VisuallyHidden } from '@usethrottle/ui';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { useStrings } from '../strings';\n\n/** An amount in its own currency, drawn by `formatMoney`. */\nexport type MoneyProps = UsePartLocal & {\n /** The amount in the currency's minor units (cents for USD, whole yen for JPY). */\n minor: number;\n /** The ISO 4217 code of this amount: the record's own currency, never a default. */\n currency: string;\n /** Shown struck through beside the amount when it is higher. */\n compareAtMinor?: number;\n};\n\n/** An amount in its own currency, by `formatMoney` and nothing else. */\nexport function Money({ minor, currency, compareAtMinor, classNames, className, unstyled }: MoneyProps) {\n const local = { classNames, unstyled };\n const part = usePart('money', { ...local, className });\n const compare = usePart('money-compare', local);\n const { t } = useStrings();\n return (\n <>\n <span {...part} data-minor={minor} data-currency={currency}>\n {formatMoney(minor, currency)}\n </span>\n {compareAtMinor !== undefined && compareAtMinor > minor ? (\n <s {...compare} data-minor={compareAtMinor} data-currency={currency}>\n <VisuallyHidden>{t('pieces.price.compareAt')}</VisuallyHidden>\n {formatMoney(compareAtMinor, currency)}\n </s>\n ) : null}\n </>\n );\n}\n","import { usePart, type UsePartLocal } from '../parts';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport { Money } from './Money';\n\n/** The catalog list and product answers' `priceContext`. */\nexport type PriceContext = 'anonymous' | 'customer' | 'email_unverified' | 'anonymous_fallback';\n\n/** One price: a `Money` with the labels a customer price or an unverified email needs. */\nexport type PriceProps = UsePartLocal & {\n /** The price in the currency's minor units. */\n minor: number;\n /** The ISO 4217 code of the price. */\n currency: string;\n /** The price it was before, in minor units. Shown struck through when higher than `minor`. */\n compareAtMinor?: number;\n /**\n * Whose price this is, from the catalog answer. `customer` adds the \"Your price\" label; `email_unverified` adds a hint to verify the email.\n */\n priceContext?: PriceContext;\n};\n\n/**\n * One price. A `customer` price carries the \"Your price\" label and hides the\n * compare-at price unless `card.showCompareAt`; an `email_unverified` one\n * carries the verify hint; the others are the plain price.\n */\nexport function Price({ minor, currency, compareAtMinor, priceContext, classNames, className, unstyled }: PriceProps) {\n const local = { classNames, unstyled };\n const part = usePart('price', { ...local, className });\n const label = usePart('price-label', local);\n const hint = usePart('price-hint', local);\n const { settings } = useStorefront();\n const { t } = useStrings();\n const showCompare = priceContext === 'customer' ? settings.card.showCompareAt : true;\n return (\n <span {...part} data-price-context={priceContext} data-minor={minor} data-currency={currency}>\n {priceContext === 'customer' ? <span {...label}>{t('pieces.price.customer')}</span> : null}\n <Money {...local} minor={minor} currency={currency} compareAtMinor={showCompare ? compareAtMinor : undefined} />\n {priceContext === 'email_unverified' ? <span {...hint}>{t('pieces.price.verifyEmail')}</span> : null}\n </span>\n );\n}\n","import { Icon } from '@usethrottle/ui';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { useStrings } from '../strings';\n\n/** A rating as five stars. */\nexport type StarRatingProps = UsePartLocal & {\n /** The average, 0 to 5. */\n value: number;\n /** The number of ratings, shown beside the stars. */\n count?: number;\n /** The star size. Default `md`. */\n size?: 'sm' | 'md';\n};\n\nconst STARS = [1, 2, 3, 4, 5];\n\n/** Five stars filled to the average (halves rounded to the nearest half), one image to a screen reader. */\nexport function StarRating({ value, count, size = 'md', classNames, className, unstyled }: StarRatingProps) {\n const local = { classNames, unstyled };\n const root = usePart('star-rating', { ...local, className });\n const stars = usePart('star-rating-stars', local);\n const countPart = usePart('star-rating-count', local);\n const { t } = useStrings();\n const average = Math.min(5, Math.max(0, Number.isFinite(value) ? value : 0));\n const halves = Math.round(average * 2);\n const shown = Math.round(average * 10) / 10;\n const label =\n count === undefined\n ? t('pieces.rating.label', { value: shown })\n : t(count === 1 ? 'pieces.rating.labelWithOne' : 'pieces.rating.labelWithCount', { value: shown, count });\n const px = size === 'sm' ? 14 : 18;\n return (\n <span {...root} data-size={size}>\n <span {...stars} role=\"img\" aria-label={label}>\n {STARS.map((n) => (\n <Icon key={n} name={halves >= n * 2 ? 'star' : halves === n * 2 - 1 ? 'star-half' : 'star-empty'} size={px} />\n ))}\n </span>\n {count !== undefined ? (\n <span {...countPart} aria-hidden=\"true\">\n {t('pieces.rating.count', { count })}\n </span>\n ) : null}\n </span>\n );\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useStorefront
|
|
4
|
+
} from "./chunk-NNE4FYRT.js";
|
|
5
|
+
|
|
6
|
+
// src/analytics/use-track.ts
|
|
7
|
+
import { useCallback } from "react";
|
|
8
|
+
function useTrack() {
|
|
9
|
+
const { analytics } = useStorefront();
|
|
10
|
+
return useCallback((event, payload) => analytics.track(event, payload), [analytics]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
useTrack
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-IJOTLGPT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/analytics/use-track.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useStorefront } from '../provider/context';\nimport type { StorefrontAnalytics } from './types';\n\n/** Reports an event to the provider's `analytics` adapter (a no-op unless one was given). */\nexport function useTrack(): StorefrontAnalytics['track'] {\n const { analytics } = useStorefront();\n return useCallback((event, payload) => analytics.track(event, payload), [analytics]);\n}\n"],"mappings":";;;;;;AAAA,SAAS,mBAAmB;AAKrB,SAAS,WAAyC;AACvD,QAAM,EAAE,UAAU,IAAI,cAAc;AACpC,SAAO,YAAY,CAAC,OAAO,YAAY,UAAU,MAAM,OAAO,OAAO,GAAG,CAAC,SAAS,CAAC;AACrF;","names":[]}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
CartLine,
|
|
4
|
+
lineToGa4Item
|
|
5
|
+
} from "./chunk-QM7KTT7F.js";
|
|
6
|
+
import {
|
|
7
|
+
useCartDrawer
|
|
8
|
+
} from "./chunk-NW3EFHY2.js";
|
|
9
|
+
import {
|
|
10
|
+
useTrack
|
|
11
|
+
} from "./chunk-IJOTLGPT.js";
|
|
12
|
+
import "./chunk-HSUUDZWS.js";
|
|
13
|
+
import {
|
|
14
|
+
useStrings
|
|
15
|
+
} from "./chunk-Q3XFD5UI.js";
|
|
16
|
+
import {
|
|
17
|
+
usePart,
|
|
18
|
+
useStorefront
|
|
19
|
+
} from "./chunk-NNE4FYRT.js";
|
|
20
|
+
|
|
21
|
+
// src/shopper/CartDrawerBody.tsx
|
|
22
|
+
import { isCatalogError } from "@usethrottle/catalog";
|
|
23
|
+
import { useCart } from "@usethrottle/catalog/react";
|
|
24
|
+
import { toDecimalString } from "@usethrottle/money";
|
|
25
|
+
import { Drawer, Icon, Skeleton } from "@usethrottle/ui";
|
|
26
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
27
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
28
|
+
var decimal = (minor, currency) => Number(toDecimalString(minor, currency));
|
|
29
|
+
function CartView({ onContinue, urls, ...local }) {
|
|
30
|
+
const { currency, settings, Link: Anchor } = useStorefront();
|
|
31
|
+
const { t } = useStrings();
|
|
32
|
+
const track = useTrack();
|
|
33
|
+
const cart = useCart(currency ? { currency } : void 0);
|
|
34
|
+
const lines = cart.cart?.lineItems ?? [];
|
|
35
|
+
const cartCurrency = cart.cart?.currency ?? currency;
|
|
36
|
+
const [error, setError] = useState(null);
|
|
37
|
+
const [notice, setNotice] = useState("");
|
|
38
|
+
const [checkingOut, setCheckingOut] = useState(false);
|
|
39
|
+
const body = usePart("cart-drawer-body", local);
|
|
40
|
+
const status = usePart("cart-status", local);
|
|
41
|
+
const errorPart = usePart("cart-error", local);
|
|
42
|
+
const loading = usePart("cart-loading", local);
|
|
43
|
+
const empty = usePart("cart-empty", local);
|
|
44
|
+
const emptyText = usePart("cart-empty-text", local);
|
|
45
|
+
const list = usePart("cart-lines", local);
|
|
46
|
+
const footer = usePart("cart-footer", local);
|
|
47
|
+
const subtotal = usePart("cart-subtotal", local);
|
|
48
|
+
const subtotalLabel = usePart("cart-subtotal-label", local);
|
|
49
|
+
const subtotalAmount = usePart("cart-subtotal-amount", local);
|
|
50
|
+
const checkoutPart = usePart("cart-checkout", local);
|
|
51
|
+
const continuePart = usePart("cart-continue", local);
|
|
52
|
+
const viewed = useRef(false);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (viewed.current || !cart.cart || lines.length === 0 || !cartCurrency) return;
|
|
55
|
+
viewed.current = true;
|
|
56
|
+
track("view_cart", {
|
|
57
|
+
currency: cartCurrency,
|
|
58
|
+
value: decimal(cart.cart.subtotal, cartCurrency),
|
|
59
|
+
items: lines.map((line) => lineToGa4Item(line, cartCurrency))
|
|
60
|
+
});
|
|
61
|
+
}, [cart.cart, lines, cartCurrency, track]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const onShow = (event) => {
|
|
64
|
+
if (event.persisted) setCheckingOut(false);
|
|
65
|
+
};
|
|
66
|
+
window.addEventListener("pageshow", onShow);
|
|
67
|
+
return () => window.removeEventListener("pageshow", onShow);
|
|
68
|
+
}, []);
|
|
69
|
+
const change = useCallback(
|
|
70
|
+
async (work) => {
|
|
71
|
+
setError(null);
|
|
72
|
+
setNotice("");
|
|
73
|
+
try {
|
|
74
|
+
await work();
|
|
75
|
+
} catch (caught) {
|
|
76
|
+
if (caught instanceof DOMException && caught.name === "AbortError") return;
|
|
77
|
+
setError(t("shopper.cart.updateFailed"));
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
[t]
|
|
81
|
+
);
|
|
82
|
+
const checkout = async () => {
|
|
83
|
+
if (checkingOut || lines.length === 0) return;
|
|
84
|
+
setError(null);
|
|
85
|
+
setCheckingOut(true);
|
|
86
|
+
try {
|
|
87
|
+
const { checkoutUrl } = await cart.checkout({
|
|
88
|
+
returnUrl: urls?.returnUrl ?? `${window.location.origin}/`,
|
|
89
|
+
cancelUrl: urls?.cancelUrl ?? window.location.href.split("#")[0]
|
|
90
|
+
});
|
|
91
|
+
if (cartCurrency && cart.cart) {
|
|
92
|
+
track("begin_checkout", {
|
|
93
|
+
currency: cartCurrency,
|
|
94
|
+
value: decimal(cart.cart.subtotal, cartCurrency),
|
|
95
|
+
items: lines.map((line) => lineToGa4Item(line, cartCurrency))
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
window.location.assign(checkoutUrl);
|
|
99
|
+
} catch (caught) {
|
|
100
|
+
setCheckingOut(false);
|
|
101
|
+
if (caught instanceof DOMException && caught.name === "AbortError") return;
|
|
102
|
+
setError(
|
|
103
|
+
isCatalogError(caught) && caught.code === "cart_prices_changed" ? t("shopper.cart.pricesChanged") : t("shopper.cart.checkoutFailed")
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const continueLabel = t("cart.continueShopping");
|
|
108
|
+
return /* @__PURE__ */ jsxs("div", { ...body, "data-cart-status": cart.status, children: [
|
|
109
|
+
/* @__PURE__ */ jsx("p", { ...status, role: "status", "aria-live": "polite", children: notice }),
|
|
110
|
+
error ? /* @__PURE__ */ jsx("p", { ...errorPart, role: "alert", children: error }) : null,
|
|
111
|
+
cart.status === "loading" && !cart.cart ? /* @__PURE__ */ jsx("div", { ...loading, "aria-busy": "true", "aria-label": t("shopper.cart.loading"), children: /* @__PURE__ */ jsx(Skeleton, { count: 3 }) }) : lines.length === 0 ? /* @__PURE__ */ jsxs("div", { ...empty, children: [
|
|
112
|
+
/* @__PURE__ */ jsx("p", { ...emptyText, children: t("empty.cart") }),
|
|
113
|
+
onContinue ? /* @__PURE__ */ jsx("button", { type: "button", ...continuePart, onClick: onContinue, children: continueLabel }) : /* @__PURE__ */ jsx(Anchor, { ...continuePart, href: settings.routes.shop, children: continueLabel })
|
|
114
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
/* @__PURE__ */ jsx("ul", { ...list, "aria-label": t("shopper.cart.lines"), children: lines.map((line) => /* @__PURE__ */ jsx(
|
|
116
|
+
CartLine,
|
|
117
|
+
{
|
|
118
|
+
line,
|
|
119
|
+
format: cart.format,
|
|
120
|
+
busy: cart.pending,
|
|
121
|
+
onQuantity: (quantity) => void change(async () => {
|
|
122
|
+
await cart.update(line.id, quantity);
|
|
123
|
+
setNotice(t("shopper.cart.updated", { name: line.name, quantity }));
|
|
124
|
+
}),
|
|
125
|
+
onRemove: () => void change(async () => {
|
|
126
|
+
await cart.remove(line.id);
|
|
127
|
+
setNotice(t("shopper.cart.removed", { name: line.name }));
|
|
128
|
+
if (cartCurrency) {
|
|
129
|
+
track("remove_from_cart", {
|
|
130
|
+
currency: cartCurrency,
|
|
131
|
+
value: decimal(line.unitPrice * line.quantity, cartCurrency),
|
|
132
|
+
items: [lineToGa4Item(line, cartCurrency)]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
...local
|
|
137
|
+
},
|
|
138
|
+
line.id
|
|
139
|
+
)) }),
|
|
140
|
+
/* @__PURE__ */ jsxs("div", { ...footer, children: [
|
|
141
|
+
/* @__PURE__ */ jsxs("p", { ...subtotal, children: [
|
|
142
|
+
/* @__PURE__ */ jsx("span", { ...subtotalLabel, children: t("shopper.cart.subtotal") }),
|
|
143
|
+
/* @__PURE__ */ jsx("span", { ...subtotalAmount, "data-minor": cart.cart?.subtotal, children: cart.format(cart.cart?.subtotal ?? 0) })
|
|
144
|
+
] }),
|
|
145
|
+
/* @__PURE__ */ jsx(
|
|
146
|
+
"button",
|
|
147
|
+
{
|
|
148
|
+
type: "button",
|
|
149
|
+
...checkoutPart,
|
|
150
|
+
disabled: cart.pending && !checkingOut,
|
|
151
|
+
"aria-disabled": checkingOut || void 0,
|
|
152
|
+
"aria-busy": checkingOut || void 0,
|
|
153
|
+
"data-checking-out": checkingOut ? "true" : void 0,
|
|
154
|
+
onClick: () => void checkout(),
|
|
155
|
+
children: checkingOut ? t("shopper.cart.checkingOut") : t("cart.checkout")
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
onContinue ? /* @__PURE__ */ jsx("button", { type: "button", ...continuePart, onClick: onContinue, children: continueLabel }) : /* @__PURE__ */ jsx(Anchor, { ...continuePart, href: settings.routes.shop, children: continueLabel })
|
|
159
|
+
] })
|
|
160
|
+
] })
|
|
161
|
+
] });
|
|
162
|
+
}
|
|
163
|
+
function DrawerCart({ className, checkoutUrls, ...local }) {
|
|
164
|
+
const { open, setOpen } = useCartDrawer();
|
|
165
|
+
const { t } = useStrings();
|
|
166
|
+
const titleId = useId();
|
|
167
|
+
const sentinel = useRef(null);
|
|
168
|
+
const [target, setTarget] = useState(null);
|
|
169
|
+
useLayoutEffect(() => {
|
|
170
|
+
if (!open) {
|
|
171
|
+
setTarget(null);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const root2 = sentinel.current?.closest(".tsf-root") ?? null;
|
|
175
|
+
setTarget({ container: root2, opener: root2?.querySelector('[data-throttle-part="cart-button"]') ?? null });
|
|
176
|
+
}, [open]);
|
|
177
|
+
const root = usePart("cart-drawer", { ...local, className });
|
|
178
|
+
const top = usePart("cart-drawer-top", local);
|
|
179
|
+
const title = usePart("cart-drawer-title", local);
|
|
180
|
+
const close = usePart("cart-drawer-close", local);
|
|
181
|
+
const closeDrawer = () => setOpen(false);
|
|
182
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
183
|
+
/* @__PURE__ */ jsx("span", { ref: sentinel, hidden: true }),
|
|
184
|
+
/* @__PURE__ */ jsx(
|
|
185
|
+
Drawer,
|
|
186
|
+
{
|
|
187
|
+
open: open && target !== null,
|
|
188
|
+
onClose: closeDrawer,
|
|
189
|
+
labelledBy: titleId,
|
|
190
|
+
container: target?.container ?? null,
|
|
191
|
+
restoreFocusTo: target?.opener ?? void 0,
|
|
192
|
+
children: /* @__PURE__ */ jsxs("div", { ...root, children: [
|
|
193
|
+
/* @__PURE__ */ jsxs("div", { ...top, children: [
|
|
194
|
+
/* @__PURE__ */ jsx("h2", { ...title, id: titleId, children: t("cart.title") }),
|
|
195
|
+
/* @__PURE__ */ jsx("button", { type: "button", ...close, "aria-label": t("shopper.cart.close"), onClick: closeDrawer, children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 22 }) })
|
|
196
|
+
] }),
|
|
197
|
+
/* @__PURE__ */ jsx(CartView, { onContinue: closeDrawer, urls: checkoutUrls, ...local })
|
|
198
|
+
] })
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
] });
|
|
202
|
+
}
|
|
203
|
+
function InlineCart({ className, checkoutUrls, ...local }) {
|
|
204
|
+
const { t } = useStrings();
|
|
205
|
+
const titleId = useId();
|
|
206
|
+
const root = usePart("cart-drawer", { ...local, className });
|
|
207
|
+
const title = usePart("cart-drawer-title", local);
|
|
208
|
+
return /* @__PURE__ */ jsxs("section", { ...root, "data-inline": "", "aria-labelledby": titleId, children: [
|
|
209
|
+
/* @__PURE__ */ jsx("h2", { ...title, id: titleId, "data-inline": "", children: t("cart.title") }),
|
|
210
|
+
/* @__PURE__ */ jsx(CartView, { urls: checkoutUrls, ...local })
|
|
211
|
+
] });
|
|
212
|
+
}
|
|
213
|
+
function CartDrawerBody({ inline, ...local }) {
|
|
214
|
+
return inline ? /* @__PURE__ */ jsx(InlineCart, { ...local }) : /* @__PURE__ */ jsx(DrawerCart, { ...local });
|
|
215
|
+
}
|
|
216
|
+
export {
|
|
217
|
+
CartDrawerBody
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=chunk-ISDATHVC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shopper/CartDrawerBody.tsx"],"sourcesContent":["import { isCatalogError } from '@usethrottle/catalog';\nimport { useCart } from '@usethrottle/catalog/react';\nimport { toDecimalString } from '@usethrottle/money';\nimport { Drawer, Icon, Skeleton } from '@usethrottle/ui';\nimport { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';\nimport { useTrack } from '../analytics/use-track';\nimport { usePart } from '../parts';\nimport { useCartDrawer } from '../provider/cart-drawer';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport type { CartDrawerProps } from './CartDrawer';\nimport { CartLine, lineToGa4Item, type CartLineData } from './CartLine';\n\ntype Local = Pick<CartDrawerProps, 'classNames' | 'unstyled'>;\n\nconst decimal = (minor: number, currency: string): number => Number(toDecimalString(minor, currency));\n\n/** The lines, the subtotal and the checkout button: what the drawer and the inline cart share. */\nfunction CartView({ onContinue, urls, ...local }: Local & { onContinue?: () => void; urls?: CartDrawerProps['checkoutUrls'] }) {\n const { currency, settings, Link: Anchor } = useStorefront();\n const { t } = useStrings();\n const track = useTrack();\n const cart = useCart(currency ? { currency } : undefined);\n const lines: CartLineData[] = cart.cart?.lineItems ?? [];\n const cartCurrency = cart.cart?.currency ?? currency;\n const [error, setError] = useState<string | null>(null);\n const [notice, setNotice] = useState('');\n const [checkingOut, setCheckingOut] = useState(false);\n\n const body = usePart('cart-drawer-body', local);\n const status = usePart('cart-status', local);\n const errorPart = usePart('cart-error', local);\n const loading = usePart('cart-loading', local);\n const empty = usePart('cart-empty', local);\n const emptyText = usePart('cart-empty-text', local);\n const list = usePart('cart-lines', local);\n const footer = usePart('cart-footer', local);\n const subtotal = usePart('cart-subtotal', local);\n const subtotalLabel = usePart('cart-subtotal-label', local);\n const subtotalAmount = usePart('cart-subtotal-amount', local);\n const checkoutPart = usePart('cart-checkout', local);\n const continuePart = usePart('cart-continue', local);\n\n // view_cart: once, when the lines first show.\n const viewed = useRef(false);\n useEffect(() => {\n if (viewed.current || !cart.cart || lines.length === 0 || !cartCurrency) return;\n viewed.current = true;\n track('view_cart', {\n currency: cartCurrency,\n value: decimal(cart.cart.subtotal, cartCurrency),\n items: lines.map((line) => lineToGa4Item(line, cartCurrency)),\n });\n }, [cart.cart, lines, cartCurrency, track]);\n\n // A page restored from the back/forward cache comes back mid hand-off: let the button work again.\n useEffect(() => {\n const onShow = (event: PageTransitionEvent) => {\n if (event.persisted) setCheckingOut(false);\n };\n window.addEventListener('pageshow', onShow);\n return () => window.removeEventListener('pageshow', onShow);\n }, []);\n\n const change = useCallback(\n async (work: () => Promise<void>) => {\n setError(null);\n // Emptied first, so the same words said twice in a row are read twice.\n setNotice('');\n try {\n await work();\n } catch (caught) {\n // A sign-out cancels the change; there is nothing to say.\n if (caught instanceof DOMException && caught.name === 'AbortError') return;\n setError(t('shopper.cart.updateFailed'));\n }\n },\n [t],\n );\n\n const checkout = async () => {\n if (checkingOut || lines.length === 0) return;\n setError(null);\n setCheckingOut(true);\n try {\n const { checkoutUrl } = await cart.checkout({\n returnUrl: urls?.returnUrl ?? `${window.location.origin}/`,\n cancelUrl: urls?.cancelUrl ?? window.location.href.split('#')[0]!,\n });\n if (cartCurrency && cart.cart) {\n track('begin_checkout', {\n currency: cartCurrency,\n value: decimal(cart.cart.subtotal, cartCurrency),\n items: lines.map((line) => lineToGa4Item(line, cartCurrency)),\n });\n }\n window.location.assign(checkoutUrl);\n } catch (caught) {\n setCheckingOut(false);\n if (caught instanceof DOMException && caught.name === 'AbortError') return;\n setError(\n isCatalogError(caught) && caught.code === 'cart_prices_changed'\n ? t('shopper.cart.pricesChanged')\n : t('shopper.cart.checkoutFailed'),\n );\n }\n };\n\n const continueLabel = t('cart.continueShopping');\n return (\n <div {...body} data-cart-status={cart.status}>\n <p {...status} role=\"status\" aria-live=\"polite\">{notice}</p>\n {error ? <p {...errorPart} role=\"alert\">{error}</p> : null}\n {cart.status === 'loading' && !cart.cart ? (\n <div {...loading} aria-busy=\"true\" aria-label={t('shopper.cart.loading')}>\n <Skeleton count={3} />\n </div>\n ) : lines.length === 0 ? (\n <div {...empty}>\n <p {...emptyText}>{t('empty.cart')}</p>\n {onContinue ? (\n <button type=\"button\" {...continuePart} onClick={onContinue}>{continueLabel}</button>\n ) : (\n <Anchor {...continuePart} href={settings.routes.shop}>{continueLabel}</Anchor>\n )}\n </div>\n ) : (\n <>\n <ul {...list} aria-label={t('shopper.cart.lines')}>\n {lines.map((line) => (\n <CartLine\n key={line.id}\n line={line}\n format={cart.format}\n busy={cart.pending}\n onQuantity={(quantity) =>\n void change(async () => {\n await cart.update(line.id, quantity);\n setNotice(t('shopper.cart.updated', { name: line.name, quantity }));\n })\n }\n onRemove={() =>\n void change(async () => {\n await cart.remove(line.id);\n setNotice(t('shopper.cart.removed', { name: line.name }));\n if (cartCurrency) {\n track('remove_from_cart', {\n currency: cartCurrency,\n value: decimal(line.unitPrice * line.quantity, cartCurrency),\n items: [lineToGa4Item(line, cartCurrency)],\n });\n }\n })\n }\n {...local}\n />\n ))}\n </ul>\n <div {...footer}>\n <p {...subtotal}>\n <span {...subtotalLabel}>{t('shopper.cart.subtotal')}</span>\n <span {...subtotalAmount} data-minor={cart.cart?.subtotal}>{cart.format(cart.cart?.subtotal ?? 0)}</span>\n </p>\n <button\n type=\"button\"\n {...checkoutPart}\n disabled={cart.pending && !checkingOut}\n aria-disabled={checkingOut || undefined}\n aria-busy={checkingOut || undefined}\n data-checking-out={checkingOut ? 'true' : undefined}\n onClick={() => void checkout()}\n >\n {checkingOut ? t('shopper.cart.checkingOut') : t('cart.checkout')}\n </button>\n {onContinue ? (\n <button type=\"button\" {...continuePart} onClick={onContinue}>{continueLabel}</button>\n ) : (\n <Anchor {...continuePart} href={settings.routes.shop}>{continueLabel}</Anchor>\n )}\n </div>\n </>\n )}\n </div>\n );\n}\n\n/** The drawer: a dialog in the storefront root, opened and closed by `useCartDrawer`. */\nfunction DrawerCart({ className, checkoutUrls, ...local }: Local & { className?: string; checkoutUrls?: CartDrawerProps['checkoutUrls'] }) {\n const { open, setOpen } = useCartDrawer();\n const { t } = useStrings();\n const titleId = useId();\n const sentinel = useRef<HTMLSpanElement>(null);\n // Found when it opens: the root it goes into (so the preset and theme apply) and the cart button, which gets focus back.\n const [target, setTarget] = useState<{ container: HTMLElement | null; opener: HTMLElement | null } | null>(null);\n useLayoutEffect(() => {\n if (!open) {\n setTarget(null);\n return;\n }\n const root = sentinel.current?.closest<HTMLElement>('.tsf-root') ?? null;\n setTarget({ container: root, opener: root?.querySelector<HTMLElement>('[data-throttle-part=\"cart-button\"]') ?? null });\n }, [open]);\n\n const root = usePart('cart-drawer', { ...local, className });\n const top = usePart('cart-drawer-top', local);\n const title = usePart('cart-drawer-title', local);\n const close = usePart('cart-drawer-close', local);\n const closeDrawer = () => setOpen(false);\n\n return (\n <>\n <span ref={sentinel} hidden />\n <Drawer\n open={open && target !== null}\n onClose={closeDrawer}\n labelledBy={titleId}\n container={target?.container ?? null}\n restoreFocusTo={target?.opener ?? undefined}\n >\n <div {...root}>\n <div {...top}>\n <h2 {...title} id={titleId}>{t('cart.title')}</h2>\n <button type=\"button\" {...close} aria-label={t('shopper.cart.close')} onClick={closeDrawer}>\n <Icon name=\"close\" size={22} />\n </button>\n </div>\n <CartView onContinue={closeDrawer} urls={checkoutUrls} {...local} />\n </div>\n </Drawer>\n </>\n );\n}\n\nfunction InlineCart({ className, checkoutUrls, ...local }: Local & { className?: string; checkoutUrls?: CartDrawerProps['checkoutUrls'] }) {\n const { t } = useStrings();\n const titleId = useId();\n const root = usePart('cart-drawer', { ...local, className });\n const title = usePart('cart-drawer-title', local);\n return (\n <section {...root} data-inline=\"\" aria-labelledby={titleId}>\n <h2 {...title} id={titleId} data-inline=\"\">{t('cart.title')}</h2>\n <CartView urls={checkoutUrls} {...local} />\n </section>\n );\n}\n\n/** The cart panel. `CartDrawer` loads this file the first time the cart opens or is drawn. */\nexport function CartDrawerBody({ inline, ...local }: CartDrawerProps) {\n return inline ? <InlineCart {...local} /> : <DrawerCart {...local} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,QAAQ,MAAM,gBAAgB;AACvC,SAAS,aAAa,WAAW,OAAO,iBAAiB,QAAQ,gBAAgB;AA2G3E,SAgBE,UAhBF,KAOE,YAPF;AAhGN,IAAM,UAAU,CAAC,OAAe,aAA6B,OAAO,gBAAgB,OAAO,QAAQ,CAAC;AAGpG,SAAS,SAAS,EAAE,YAAY,MAAM,GAAG,MAAM,GAAgF;AAC7H,QAAM,EAAE,UAAU,UAAU,MAAM,OAAO,IAAI,cAAc;AAC3D,QAAM,EAAE,EAAE,IAAI,WAAW;AACzB,QAAM,QAAQ,SAAS;AACvB,QAAM,OAAO,QAAQ,WAAW,EAAE,SAAS,IAAI,MAAS;AACxD,QAAM,QAAwB,KAAK,MAAM,aAAa,CAAC;AACvD,QAAM,eAAe,KAAK,MAAM,YAAY;AAC5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,CAA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AAY,GAAG,OAAO;AACrE;","names":["root"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useStrings
|
|
4
|
+
} from "./chunk-Q3XFD5UI.js";
|
|
5
|
+
import {
|
|
6
|
+
usePart,
|
|
7
|
+
useStorefront
|
|
8
|
+
} from "./chunk-NNE4FYRT.js";
|
|
9
|
+
|
|
10
|
+
// src/url/routes.ts
|
|
11
|
+
var fill = (pattern, name, value) => pattern.split(`{${name}}`).join(encodeURIComponent(value));
|
|
12
|
+
function routeHref(settings, kind, value, site) {
|
|
13
|
+
if (kind === "search") return fill(settings.routes.search, "q", value);
|
|
14
|
+
const pattern = kind === "page" && site?.routes.page ? site.routes.page : settings.routes[kind];
|
|
15
|
+
return fill(pattern, kind === "tag" ? "tag" : "handle", value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/analytics/items.ts
|
|
19
|
+
import { toDecimalString } from "@usethrottle/money";
|
|
20
|
+
var decimal = (minor, currency) => Number(toDecimalString(minor, currency));
|
|
21
|
+
function toGa4Item(product, o = {}) {
|
|
22
|
+
const variant = o.variantSku ? product.variants?.find((v) => v.sku === o.variantSku) : void 0;
|
|
23
|
+
const currency = variant?.currency ?? product.priceRange?.currency;
|
|
24
|
+
const minor = variant ? variant.salePriceMinor ?? variant.priceMinor : product.priceRange?.minMinor;
|
|
25
|
+
return {
|
|
26
|
+
item_id: variant?.sku ?? product.handle,
|
|
27
|
+
item_name: product.title ?? product.handle,
|
|
28
|
+
...product.brand ? { item_brand: product.brand } : {},
|
|
29
|
+
...variant?.title ? { item_variant: variant.title } : {},
|
|
30
|
+
...o.listName ? { item_list_name: o.listName } : {},
|
|
31
|
+
...o.index !== void 0 ? { index: o.index } : {},
|
|
32
|
+
...minor !== null && minor !== void 0 && currency ? { price: decimal(minor, currency) } : {},
|
|
33
|
+
...o.quantity !== void 0 ? { quantity: o.quantity } : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/pieces/Money.tsx
|
|
38
|
+
import { formatMoney } from "@usethrottle/money";
|
|
39
|
+
import { VisuallyHidden } from "@usethrottle/ui";
|
|
40
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
41
|
+
function Money({ minor, currency, compareAtMinor, classNames, className, unstyled }) {
|
|
42
|
+
const local = { classNames, unstyled };
|
|
43
|
+
const part = usePart("money", { ...local, className });
|
|
44
|
+
const compare = usePart("money-compare", local);
|
|
45
|
+
const { t } = useStrings();
|
|
46
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
|
+
/* @__PURE__ */ jsx("span", { ...part, "data-minor": minor, "data-currency": currency, children: formatMoney(minor, currency) }),
|
|
48
|
+
compareAtMinor !== void 0 && compareAtMinor > minor ? /* @__PURE__ */ jsxs("s", { ...compare, "data-minor": compareAtMinor, "data-currency": currency, children: [
|
|
49
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: t("pieces.price.compareAt") }),
|
|
50
|
+
formatMoney(compareAtMinor, currency)
|
|
51
|
+
] }) : null
|
|
52
|
+
] });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/pieces/Price.tsx
|
|
56
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
57
|
+
function Price({ minor, currency, compareAtMinor, priceContext, classNames, className, unstyled }) {
|
|
58
|
+
const local = { classNames, unstyled };
|
|
59
|
+
const part = usePart("price", { ...local, className });
|
|
60
|
+
const label = usePart("price-label", local);
|
|
61
|
+
const hint = usePart("price-hint", local);
|
|
62
|
+
const { settings } = useStorefront();
|
|
63
|
+
const { t } = useStrings();
|
|
64
|
+
const showCompare = priceContext === "customer" ? settings.card.showCompareAt : true;
|
|
65
|
+
return /* @__PURE__ */ jsxs2("span", { ...part, "data-price-context": priceContext, "data-minor": minor, "data-currency": currency, children: [
|
|
66
|
+
priceContext === "customer" ? /* @__PURE__ */ jsx2("span", { ...label, children: t("pieces.price.customer") }) : null,
|
|
67
|
+
/* @__PURE__ */ jsx2(Money, { ...local, minor, currency, compareAtMinor: showCompare ? compareAtMinor : void 0 }),
|
|
68
|
+
priceContext === "email_unverified" ? /* @__PURE__ */ jsx2("span", { ...hint, children: t("pieces.price.verifyEmail") }) : null
|
|
69
|
+
] });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/pieces/StarRating.tsx
|
|
73
|
+
import { Icon } from "@usethrottle/ui";
|
|
74
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
75
|
+
var STARS = [1, 2, 3, 4, 5];
|
|
76
|
+
function StarRating({ value, count, size = "md", classNames, className, unstyled }) {
|
|
77
|
+
const local = { classNames, unstyled };
|
|
78
|
+
const root = usePart("star-rating", { ...local, className });
|
|
79
|
+
const stars = usePart("star-rating-stars", local);
|
|
80
|
+
const countPart = usePart("star-rating-count", local);
|
|
81
|
+
const { t } = useStrings();
|
|
82
|
+
const average = Math.min(5, Math.max(0, Number.isFinite(value) ? value : 0));
|
|
83
|
+
const halves = Math.round(average * 2);
|
|
84
|
+
const shown = Math.round(average * 10) / 10;
|
|
85
|
+
const label = count === void 0 ? t("pieces.rating.label", { value: shown }) : t(count === 1 ? "pieces.rating.labelWithOne" : "pieces.rating.labelWithCount", { value: shown, count });
|
|
86
|
+
const px = size === "sm" ? 14 : 18;
|
|
87
|
+
return /* @__PURE__ */ jsxs3("span", { ...root, "data-size": size, children: [
|
|
88
|
+
/* @__PURE__ */ jsx3("span", { ...stars, role: "img", "aria-label": label, children: STARS.map((n) => /* @__PURE__ */ jsx3(Icon, { name: halves >= n * 2 ? "star" : halves === n * 2 - 1 ? "star-half" : "star-empty", size: px }, n)) }),
|
|
89
|
+
count !== void 0 ? /* @__PURE__ */ jsx3("span", { ...countPart, "aria-hidden": "true", children: t("pieces.rating.count", { count }) }) : null
|
|
90
|
+
] });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
routeHref,
|
|
95
|
+
toGa4Item,
|
|
96
|
+
Money,
|
|
97
|
+
Price,
|
|
98
|
+
StarRating
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=chunk-LW2A6USV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/url/routes.ts","../src/analytics/items.ts","../src/pieces/Money.tsx","../src/pieces/Price.tsx","../src/pieces/StarRating.tsx"],"sourcesContent":["import type { NormalizedSettings } from '../settings/normalize';\nimport type { ResolvedSiteDesign } from '../site/resolve';\n\nconst fill = (pattern: string, name: string, value: string) =>\n pattern.split(`{${name}}`).join(encodeURIComponent(value));\n\n/**\n * A link by the store's route patterns (`settings.routes`). `'page'` uses the\n * site design's page route when it names one (a Builder site owns it), and\n * `'search'` fills `{q}`. Ported from Meridian `lib/menu.ts`\n * (`routeHref` / `searchHref`). Server-safe.\n */\nexport function routeHref(\n settings: NormalizedSettings,\n kind: 'product' | 'collection' | 'category' | 'tag' | 'page' | 'search',\n value: string,\n site?: ResolvedSiteDesign,\n): string {\n if (kind === 'search') return fill(settings.routes.search, 'q', value);\n const pattern = kind === 'page' && site?.routes.page ? site.routes.page : settings.routes[kind];\n return fill(pattern, kind === 'tag' ? 'tag' : 'handle', value);\n}\n","import type { ListProduct, StorefrontProduct } from '@usethrottle/catalog';\nimport { toDecimalString } from '@usethrottle/money';\nimport type { Ga4Item } from './types';\n\nconst decimal = (minor: number, currency: string): number => Number(toDecimalString(minor, currency));\n\n/**\n * A GA4 item for a product. The price is the chosen variant's (`variantSku`),\n * else the product's lowest, as a decimal amount through `@usethrottle/money`.\n */\nexport function toGa4Item(\n product: ListProduct | StorefrontProduct,\n o: { index?: number; listName?: string; variantSku?: string | null; quantity?: number } = {},\n): Ga4Item {\n const variant = o.variantSku ? product.variants?.find((v) => v.sku === o.variantSku) : undefined;\n const currency = variant?.currency ?? product.priceRange?.currency;\n const minor = variant ? (variant.salePriceMinor ?? variant.priceMinor) : product.priceRange?.minMinor;\n return {\n item_id: variant?.sku ?? product.handle,\n item_name: product.title ?? product.handle,\n ...(product.brand ? { item_brand: product.brand } : {}),\n ...(variant?.title ? { item_variant: variant.title } : {}),\n ...(o.listName ? { item_list_name: o.listName } : {}),\n ...(o.index !== undefined ? { index: o.index } : {}),\n ...(minor !== null && minor !== undefined && currency ? { price: decimal(minor, currency) } : {}),\n ...(o.quantity !== undefined ? { quantity: o.quantity } : {}),\n };\n}\n","import { formatMoney } from '@usethrottle/money';\nimport { VisuallyHidden } from '@usethrottle/ui';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { useStrings } from '../strings';\n\n/** An amount in its own currency, drawn by `formatMoney`. */\nexport type MoneyProps = UsePartLocal & {\n /** The amount in the currency's minor units (cents for USD, whole yen for JPY). */\n minor: number;\n /** The ISO 4217 code of this amount: the record's own currency, never a default. */\n currency: string;\n /** Shown struck through beside the amount when it is higher. */\n compareAtMinor?: number;\n};\n\n/** An amount in its own currency, by `formatMoney` and nothing else. */\nexport function Money({ minor, currency, compareAtMinor, classNames, className, unstyled }: MoneyProps) {\n const local = { classNames, unstyled };\n const part = usePart('money', { ...local, className });\n const compare = usePart('money-compare', local);\n const { t } = useStrings();\n return (\n <>\n <span {...part} data-minor={minor} data-currency={currency}>\n {formatMoney(minor, currency)}\n </span>\n {compareAtMinor !== undefined && compareAtMinor > minor ? (\n <s {...compare} data-minor={compareAtMinor} data-currency={currency}>\n <VisuallyHidden>{t('pieces.price.compareAt')}</VisuallyHidden>\n {formatMoney(compareAtMinor, currency)}\n </s>\n ) : null}\n </>\n );\n}\n","import { usePart, type UsePartLocal } from '../parts';\nimport { useStorefront } from '../provider/context';\nimport { useStrings } from '../strings';\nimport { Money } from './Money';\n\n/** The catalog list and product answers' `priceContext`. */\nexport type PriceContext = 'anonymous' | 'customer' | 'email_unverified' | 'anonymous_fallback';\n\n/** One price: a `Money` with the labels a customer price or an unverified email needs. */\nexport type PriceProps = UsePartLocal & {\n /** The price in the currency's minor units. */\n minor: number;\n /** The ISO 4217 code of the price. */\n currency: string;\n /** The price it was before, in minor units. Shown struck through when higher than `minor`. */\n compareAtMinor?: number;\n /**\n * Whose price this is, from the catalog answer. `customer` adds the \"Your price\" label; `email_unverified` adds a hint to verify the email.\n */\n priceContext?: PriceContext;\n};\n\n/**\n * One price. A `customer` price carries the \"Your price\" label and hides the\n * compare-at price unless `card.showCompareAt`; an `email_unverified` one\n * carries the verify hint; the others are the plain price.\n */\nexport function Price({ minor, currency, compareAtMinor, priceContext, classNames, className, unstyled }: PriceProps) {\n const local = { classNames, unstyled };\n const part = usePart('price', { ...local, className });\n const label = usePart('price-label', local);\n const hint = usePart('price-hint', local);\n const { settings } = useStorefront();\n const { t } = useStrings();\n const showCompare = priceContext === 'customer' ? settings.card.showCompareAt : true;\n return (\n <span {...part} data-price-context={priceContext} data-minor={minor} data-currency={currency}>\n {priceContext === 'customer' ? <span {...label}>{t('pieces.price.customer')}</span> : null}\n <Money {...local} minor={minor} currency={currency} compareAtMinor={showCompare ? compareAtMinor : undefined} />\n {priceContext === 'email_unverified' ? <span {...hint}>{t('pieces.price.verifyEmail')}</span> : null}\n </span>\n );\n}\n","import { Icon } from '@usethrottle/ui';\nimport { usePart, type UsePartLocal } from '../parts';\nimport { useStrings } from '../strings';\n\n/** A rating as five stars. */\nexport type StarRatingProps = UsePartLocal & {\n /** The average, 0 to 5. */\n value: number;\n /** The number of ratings, shown beside the stars. */\n count?: number;\n /** The star size. Default `md`. */\n size?: 'sm' | 'md';\n};\n\nconst STARS = [1, 2, 3, 4, 5];\n\n/** Five stars filled to the average (halves rounded to the nearest half), one image to a screen reader. */\nexport function StarRating({ value, count, size = 'md', classNames, className, unstyled }: StarRatingProps) {\n const local = { classNames, unstyled };\n const root = usePart('star-rating', { ...local, className });\n const stars = usePart('star-rating-stars', local);\n const countPart = usePart('star-rating-count', local);\n const { t } = useStrings();\n const average = Math.min(5, Math.max(0, Number.isFinite(value) ? value : 0));\n const halves = Math.round(average * 2);\n const shown = Math.round(average * 10) / 10;\n const label =\n count === undefined\n ? t('pieces.rating.label', { value: shown })\n : t(count === 1 ? 'pieces.rating.labelWithOne' : 'pieces.rating.labelWithCount', { value: shown, count });\n const px = size === 'sm' ? 14 : 18;\n return (\n <span {...root} data-size={size}>\n <span {...stars} role=\"img\" aria-label={label}>\n {STARS.map((n) => (\n <Icon key={n} name={halves >= n * 2 ? 'star' : halves === n * 2 - 1 ? 'star-half' : 'star-empty'} size={px} />\n ))}\n </span>\n {count !== undefined ? (\n <span {...countPart} aria-hidden=\"true\">\n {t('pieces.rating.count', { count })}\n </span>\n ) : null}\n </span>\n );\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAM,OAAO,CAAC,SAAiB,MAAc,UAC3C,QAAQ,MAAM,IAAI,IAAI,GAAG,EAAE,KAAK,mBAAmB,KAAK,CAAC;AAQpD,SAAS,UACd,UACA,MACA,OACA,MACQ;AACR,MAAI,SAAS,SAAU,QAAO,KAAK,SAAS,OAAO,QAAQ,KAAK,KAAK;AACrE,QAAM,UAAU,SAAS,UAAU,MAAM,OAAO,OAAO,KAAK,OAAO,OAAO,SAAS,OAAO,IAAI;AAC9F,SAAO,KAAK,SAAS,SAAS,QAAQ,QAAQ,UAAU,KAAK;AAC/D;;;ACpBA,SAAS,uBAAuB;AAGhC,IAAM,UAAU,CAAC,OAAe,aAA6B,OAAO,gBAAgB,OAAO,QAAQ,CAAC;AAM7F,SAAS,UACd,SACA,IAA0F,CAAC,GAClF;AACT,QAAM,UAAU,EAAE,aAAa,QAAQ,UAAU,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,IAAI;AACvF,QAAM,WAAW,SAAS,YAAY,QAAQ,YAAY;AAC1D,QAAM,QAAQ,UAAW,QAAQ,kBAAkB,QAAQ,aAAc,QAAQ,YAAY;AAC7F,SAAO;AAAA,IACL,SAAS,SAAS,OAAO,QAAQ;AAAA,IACjC,WAAW,QAAQ,SAAS,QAAQ;AAAA,IACpC,GAAI,QAAQ,QAAQ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