@asteby/storefront-react 0.13.1 → 0.15.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/README.md +2 -0
- package/dist/account-server.cjs +41 -8
- package/dist/account-server.cjs.map +1 -1
- package/dist/account-server.d.cts +2 -2
- package/dist/account-server.d.ts +2 -2
- package/dist/account-server.js +42 -9
- package/dist/account-server.js.map +1 -1
- package/dist/account.cjs +3 -1
- package/dist/account.cjs.map +1 -1
- package/dist/account.d.cts +2 -2
- package/dist/account.d.ts +2 -2
- package/dist/account.js +3 -1
- package/dist/account.js.map +1 -1
- package/dist/checkout.cjs +20 -2
- package/dist/checkout.cjs.map +1 -1
- package/dist/checkout.d.cts +20 -3
- package/dist/checkout.d.ts +20 -3
- package/dist/checkout.js +20 -3
- package/dist/checkout.js.map +1 -1
- package/dist/{types-HcEUd9hW.d.cts → types-D7pVK0GK.d.cts} +5 -0
- package/dist/{types-HcEUd9hW.d.ts → types-D7pVK0GK.d.ts} +5 -0
- package/package.json +2 -2
package/dist/checkout.d.cts
CHANGED
|
@@ -355,9 +355,12 @@ type DeliveryOptionsProps = {
|
|
|
355
355
|
* `list` (default): every rate, as the server orders them. `recommended`: up to `recommendedCount` rates (cheapest,
|
|
356
356
|
* fastest and the best balance, tagged) and the rest under "Show more options (N)", grouped by carrier so the carrier
|
|
357
357
|
* name is not repeated on every row. Repeated services are dropped (the cheapest stays). Works without JavaScript
|
|
358
|
-
* (`<details>`); it opens by itself when the chosen rate is inside.
|
|
358
|
+
* (`<details>`); it opens by itself when the chosen rate is inside. `flat`: ONE plain list like most online shops:
|
|
359
|
+
* every service ordered from the lowest to the highest price, repeated services dropped (the cheapest stays), the
|
|
360
|
+
* cheapest / fastest / recommended tags on the rows that earn them, no `<details>` and no groups. The chosen rate is
|
|
361
|
+
* always listed, and with no explicit default the preselected row is the first one (the cheapest).
|
|
359
362
|
*/
|
|
360
|
-
layout?: 'list' | 'recommended';
|
|
363
|
+
layout?: 'list' | 'recommended' | 'flat';
|
|
361
364
|
/** Rates recommended in `layout="recommended"`. Default 3. */
|
|
362
365
|
recommendedCount?: number;
|
|
363
366
|
/**
|
|
@@ -432,5 +435,19 @@ declare function dedupeRates<R extends ShippingRate>(rates: readonly R[]): R[];
|
|
|
432
435
|
* Recommended rows come back cheapest first. Pickup is not a rate and is never hidden (the component shows it apart).
|
|
433
436
|
*/
|
|
434
437
|
declare function recommendRates<R extends ShippingRate>(input: readonly R[], options?: RecommendRatesOptions): RecommendedRates<R>;
|
|
438
|
+
type FlatRatesOptions = {
|
|
439
|
+
/** Count used to decide the `best_value` tag, as in `recommendRates` (default 3: only with more than 4 services). */
|
|
440
|
+
count?: number;
|
|
441
|
+
/** Drop repeated services keeping the cheapest. Default true. */
|
|
442
|
+
dedupe?: boolean;
|
|
443
|
+
/** Id of the chosen rate: it stays in the list even if it is a repeated service. */
|
|
444
|
+
keepId?: string | null;
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* ONE flat list for `layout="flat"`: every service (repeated ones dropped, the cheapest stays), ordered from the
|
|
448
|
+
* lowest to the highest price, with the same tags `recommendRates` assigns (cheapest, fastest and, on long quotes,
|
|
449
|
+
* best_value) on the rows that earn them. Nothing is hidden or grouped.
|
|
450
|
+
*/
|
|
451
|
+
declare function flatRates<R extends ShippingRate>(input: readonly R[], options?: FlatRatesOptions): RecommendedRate<R>[];
|
|
435
452
|
|
|
436
|
-
export { type AddressFieldKey, AddressFields, type AddressFieldsMessages, type AddressFieldsProps, type Brand, type BrandKind, BrandMark, type BrandMarkProps, type BrandMarkSource, CheckoutFieldClassNames, type ContactFieldKey, ContactFields, type ContactFieldsProps, type DeliveryMessages, DeliveryOptions, type DeliveryOptionsClassNames, type DeliveryOptionsProps, FieldErrors, type FieldLayoutClassNames, FieldMessages, OrderSummary, type OrderSummaryClassNames, OrderSummaryDisclosure, type OrderSummaryDisclosureProps, type OrderSummaryMessages, type OrderSummaryProps, type PostalCodeInfo, type QuoteNote, type RateBadge, type RateGroup, type RateTag, type RecommendRatesOptions, type RecommendedRate, type RecommendedRates, addressFieldsMessages, brandKey, brandLogo, brandName, dedupeRates, deliveryMessages, findBrand, isQuoteChange, listBrands, matchRate, orderSummaryMessages, quoteDeadline, quoteNote, rateBadges, rateCarrier, rateEta, rateService, recommendRates };
|
|
453
|
+
export { type AddressFieldKey, AddressFields, type AddressFieldsMessages, type AddressFieldsProps, type Brand, type BrandKind, BrandMark, type BrandMarkProps, type BrandMarkSource, CheckoutFieldClassNames, type ContactFieldKey, ContactFields, type ContactFieldsProps, type DeliveryMessages, DeliveryOptions, type DeliveryOptionsClassNames, type DeliveryOptionsProps, FieldErrors, type FieldLayoutClassNames, FieldMessages, type FlatRatesOptions, OrderSummary, type OrderSummaryClassNames, OrderSummaryDisclosure, type OrderSummaryDisclosureProps, type OrderSummaryMessages, type OrderSummaryProps, type PostalCodeInfo, type QuoteNote, type RateBadge, type RateGroup, type RateTag, type RecommendRatesOptions, type RecommendedRate, type RecommendedRates, addressFieldsMessages, brandKey, brandLogo, brandName, dedupeRates, deliveryMessages, findBrand, flatRates, isQuoteChange, listBrands, matchRate, orderSummaryMessages, quoteDeadline, quoteNote, rateBadges, rateCarrier, rateEta, rateService, recommendRates };
|
package/dist/checkout.d.ts
CHANGED
|
@@ -355,9 +355,12 @@ type DeliveryOptionsProps = {
|
|
|
355
355
|
* `list` (default): every rate, as the server orders them. `recommended`: up to `recommendedCount` rates (cheapest,
|
|
356
356
|
* fastest and the best balance, tagged) and the rest under "Show more options (N)", grouped by carrier so the carrier
|
|
357
357
|
* name is not repeated on every row. Repeated services are dropped (the cheapest stays). Works without JavaScript
|
|
358
|
-
* (`<details>`); it opens by itself when the chosen rate is inside.
|
|
358
|
+
* (`<details>`); it opens by itself when the chosen rate is inside. `flat`: ONE plain list like most online shops:
|
|
359
|
+
* every service ordered from the lowest to the highest price, repeated services dropped (the cheapest stays), the
|
|
360
|
+
* cheapest / fastest / recommended tags on the rows that earn them, no `<details>` and no groups. The chosen rate is
|
|
361
|
+
* always listed, and with no explicit default the preselected row is the first one (the cheapest).
|
|
359
362
|
*/
|
|
360
|
-
layout?: 'list' | 'recommended';
|
|
363
|
+
layout?: 'list' | 'recommended' | 'flat';
|
|
361
364
|
/** Rates recommended in `layout="recommended"`. Default 3. */
|
|
362
365
|
recommendedCount?: number;
|
|
363
366
|
/**
|
|
@@ -432,5 +435,19 @@ declare function dedupeRates<R extends ShippingRate>(rates: readonly R[]): R[];
|
|
|
432
435
|
* Recommended rows come back cheapest first. Pickup is not a rate and is never hidden (the component shows it apart).
|
|
433
436
|
*/
|
|
434
437
|
declare function recommendRates<R extends ShippingRate>(input: readonly R[], options?: RecommendRatesOptions): RecommendedRates<R>;
|
|
438
|
+
type FlatRatesOptions = {
|
|
439
|
+
/** Count used to decide the `best_value` tag, as in `recommendRates` (default 3: only with more than 4 services). */
|
|
440
|
+
count?: number;
|
|
441
|
+
/** Drop repeated services keeping the cheapest. Default true. */
|
|
442
|
+
dedupe?: boolean;
|
|
443
|
+
/** Id of the chosen rate: it stays in the list even if it is a repeated service. */
|
|
444
|
+
keepId?: string | null;
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* ONE flat list for `layout="flat"`: every service (repeated ones dropped, the cheapest stays), ordered from the
|
|
448
|
+
* lowest to the highest price, with the same tags `recommendRates` assigns (cheapest, fastest and, on long quotes,
|
|
449
|
+
* best_value) on the rows that earn them. Nothing is hidden or grouped.
|
|
450
|
+
*/
|
|
451
|
+
declare function flatRates<R extends ShippingRate>(input: readonly R[], options?: FlatRatesOptions): RecommendedRate<R>[];
|
|
435
452
|
|
|
436
|
-
export { type AddressFieldKey, AddressFields, type AddressFieldsMessages, type AddressFieldsProps, type Brand, type BrandKind, BrandMark, type BrandMarkProps, type BrandMarkSource, CheckoutFieldClassNames, type ContactFieldKey, ContactFields, type ContactFieldsProps, type DeliveryMessages, DeliveryOptions, type DeliveryOptionsClassNames, type DeliveryOptionsProps, FieldErrors, type FieldLayoutClassNames, FieldMessages, OrderSummary, type OrderSummaryClassNames, OrderSummaryDisclosure, type OrderSummaryDisclosureProps, type OrderSummaryMessages, type OrderSummaryProps, type PostalCodeInfo, type QuoteNote, type RateBadge, type RateGroup, type RateTag, type RecommendRatesOptions, type RecommendedRate, type RecommendedRates, addressFieldsMessages, brandKey, brandLogo, brandName, dedupeRates, deliveryMessages, findBrand, isQuoteChange, listBrands, matchRate, orderSummaryMessages, quoteDeadline, quoteNote, rateBadges, rateCarrier, rateEta, rateService, recommendRates };
|
|
453
|
+
export { type AddressFieldKey, AddressFields, type AddressFieldsMessages, type AddressFieldsProps, type Brand, type BrandKind, BrandMark, type BrandMarkProps, type BrandMarkSource, CheckoutFieldClassNames, type ContactFieldKey, ContactFields, type ContactFieldsProps, type DeliveryMessages, DeliveryOptions, type DeliveryOptionsClassNames, type DeliveryOptionsProps, FieldErrors, type FieldLayoutClassNames, FieldMessages, type FlatRatesOptions, OrderSummary, type OrderSummaryClassNames, OrderSummaryDisclosure, type OrderSummaryDisclosureProps, type OrderSummaryMessages, type OrderSummaryProps, type PostalCodeInfo, type QuoteNote, type RateBadge, type RateGroup, type RateTag, type RecommendRatesOptions, type RecommendedRate, type RecommendedRates, addressFieldsMessages, brandKey, brandLogo, brandName, dedupeRates, deliveryMessages, findBrand, flatRates, isQuoteChange, listBrands, matchRate, orderSummaryMessages, quoteDeadline, quoteNote, rateBadges, rateCarrier, rateEta, rateService, recommendRates };
|
package/dist/checkout.js
CHANGED
|
@@ -347,6 +347,17 @@ function recommendRates(input, options = {}) {
|
|
|
347
347
|
const more = [...groups.values()];
|
|
348
348
|
return { recommended, more, moreCount: more.reduce((n, g) => n + g.rates.length, 0) };
|
|
349
349
|
}
|
|
350
|
+
function flatRates(input, options = {}) {
|
|
351
|
+
const count = options.count ?? 3;
|
|
352
|
+
const rates = options.dedupe === false ? [...input] : dedupeRates(input);
|
|
353
|
+
const tags = /* @__PURE__ */ new Map();
|
|
354
|
+
for (const { rate, tags: t } of recommendRates(rates, { count, dedupe: false }).recommended) tags.set(rate, t);
|
|
355
|
+
const list = [...rates];
|
|
356
|
+
const kept = options.keepId ? input.find((r) => r.id === options.keepId) : void 0;
|
|
357
|
+
if (kept && !list.includes(kept)) list.push(kept);
|
|
358
|
+
const byCost = (a, b) => (costOf(a) ?? Infinity) - (costOf(b) ?? Infinity);
|
|
359
|
+
return list.sort(byCost).map((rate) => ({ rate, tags: tags.get(rate) ?? [] }));
|
|
360
|
+
}
|
|
350
361
|
|
|
351
362
|
// src/checkout/delivery.ts
|
|
352
363
|
var ES3 = {
|
|
@@ -535,7 +546,13 @@ function DeliveryOptions(props) {
|
|
|
535
546
|
const m = useMemo(() => deliveryMessages(locale, props.messages), [locale, props.messages]);
|
|
536
547
|
const hydrated = useHydrated();
|
|
537
548
|
const badges = useMemo(() => showBadges ? rateBadges(rates) : /* @__PURE__ */ new Map(), [rates, showBadges]);
|
|
538
|
-
const
|
|
549
|
+
const flat = useMemo(
|
|
550
|
+
() => layout === "flat" ? flatRates(rates, { count: props.recommendedCount ?? 3, keepId: value ? rates.find((r) => rateValue(r) === value)?.id ?? null : null }) : null,
|
|
551
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
552
|
+
[layout, rates, props.recommendedCount, value]
|
|
553
|
+
);
|
|
554
|
+
const firstRate = flat ? flat[0]?.rate : rates[0];
|
|
555
|
+
const firstValue = firstRate ? rateValue(firstRate) : null;
|
|
539
556
|
const defaultValue = props.defaultValue === void 0 ? firstValue : props.defaultValue;
|
|
540
557
|
const amount = (money) => Number(money.amount) === 0 ? /* @__PURE__ */ jsx("span", { className: cx.free, "data-sf-delivery-free": true, children: m.free }) : renderAmount ? renderAmount(money) : formatMoney(money, locale);
|
|
541
558
|
const mode = props.quoteNote ?? "always";
|
|
@@ -601,7 +618,7 @@ function DeliveryOptions(props) {
|
|
|
601
618
|
] }) : null,
|
|
602
619
|
children,
|
|
603
620
|
loading && rates.length === 0 ? [0, 1, 2].map((i) => /* @__PURE__ */ jsx("div", { className: cx.skeleton, "data-sf-delivery-skeleton": true, "aria-hidden": "true" }, i)) : null,
|
|
604
|
-
plan ? plan.recommended.map(({ rate, tags }) => rateRow(rate, { tags: showBadges ? tags : [] })) : rates.map((rate) => rateRow(rate, { tags: badges.get(rate.id) ?? [] })),
|
|
621
|
+
flat ? flat.map(({ rate, tags }) => rateRow(rate, { tags: showBadges ? tags : [] })) : plan ? plan.recommended.map(({ rate, tags }) => rateRow(rate, { tags: showBadges ? tags : [] })) : rates.map((rate) => rateRow(rate, { tags: badges.get(rate.id) ?? [] })),
|
|
605
622
|
plan && plan.moreCount > 0 ? /* @__PURE__ */ jsxs("details", { className: cx.more, "data-sf-delivery-more": true, ...inMore ? { open: true } : {}, children: [
|
|
606
623
|
/* @__PURE__ */ jsx("summary", { className: cx.moreSummary, "data-sf-delivery-more-summary": true, children: m.moreOptions.replace("{n}", String(plan.moreCount)) }),
|
|
607
624
|
/* @__PURE__ */ jsx("div", { "data-sf-delivery-groups": true, children: plan.more.map((g) => {
|
|
@@ -629,6 +646,6 @@ function DeliveryOptions(props) {
|
|
|
629
646
|
] });
|
|
630
647
|
}
|
|
631
648
|
|
|
632
|
-
export { AddressFields, ContactFields, DeliveryOptions, OrderSummary, OrderSummaryDisclosure, addressFieldsMessages, dedupeRates, deliveryMessages, isQuoteChange, matchRate, orderSummaryMessages, quoteDeadline, quoteNote, rateBadges, rateCarrier, rateEta, rateService, recommendRates };
|
|
649
|
+
export { AddressFields, ContactFields, DeliveryOptions, OrderSummary, OrderSummaryDisclosure, addressFieldsMessages, dedupeRates, deliveryMessages, flatRates, isQuoteChange, matchRate, orderSummaryMessages, quoteDeadline, quoteNote, rateBadges, rateCarrier, rateEta, rateService, recommendRates };
|
|
633
650
|
//# sourceMappingURL=checkout.js.map
|
|
634
651
|
//# sourceMappingURL=checkout.js.map
|