@nextblock-cms/ecom 0.19.0 → 0.19.3

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.
Files changed (161) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +26 -25
  3. package/lib/CurrencyProvider.cjs.js +1 -1
  4. package/lib/CurrencyProvider.es.js +41 -45
  5. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  6. package/lib/PaymentReadinessProvider.es.js +15 -19
  7. package/lib/cart-store.cjs.js +1 -1
  8. package/lib/cart-store.d.ts +4 -0
  9. package/lib/cart-store.es.js +77 -69
  10. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  11. package/lib/components/AccountNavigationMenu.es.js +44 -62
  12. package/lib/components/AddToCartButton.cjs.js +1 -1
  13. package/lib/components/AddToCartButton.es.js +50 -78
  14. package/lib/components/Cart.cjs.js +1 -1
  15. package/lib/components/Cart.d.ts +1 -1
  16. package/lib/components/Cart.es.js +158 -377
  17. package/lib/components/CartDrawer.cjs.js +1 -1
  18. package/lib/components/CartDrawer.es.js +143 -297
  19. package/lib/components/CartIcon.cjs.js +1 -1
  20. package/lib/components/CartIcon.es.js +21 -47
  21. package/lib/components/Checkout.cjs.js +1 -1
  22. package/lib/components/Checkout.d.ts +1 -1
  23. package/lib/components/Checkout.es.js +839 -1627
  24. package/lib/components/CouponForm.cjs.js +1 -1
  25. package/lib/components/CouponForm.es.js +104 -155
  26. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  27. package/lib/components/CurrencySwitcher.es.js +14 -33
  28. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  29. package/lib/components/CustomerProfileForm.d.ts +1 -1
  30. package/lib/components/CustomerProfileForm.es.js +264 -672
  31. package/lib/components/FeaturedProduct.cjs.js +1 -1
  32. package/lib/components/FeaturedProduct.es.js +54 -126
  33. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  34. package/lib/components/FreemiusLicensePanel.es.js +45 -125
  35. package/lib/components/InvoiceDocument.cjs.js +1 -1
  36. package/lib/components/InvoiceDocument.es.js +148 -487
  37. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  38. package/lib/components/InvoiceViewerShell.d.ts +4 -1
  39. package/lib/components/InvoiceViewerShell.es.js +59 -142
  40. package/lib/components/ProductCard.cjs.js +1 -1
  41. package/lib/components/ProductCard.d.ts +3 -1
  42. package/lib/components/ProductCard.es.js +128 -242
  43. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  44. package/lib/components/ProductDetailsLayout.es.js +315 -657
  45. package/lib/components/ProductGallery.cjs.js +1 -1
  46. package/lib/components/ProductGallery.d.ts +2 -0
  47. package/lib/components/ProductGallery.es.js +37 -66
  48. package/lib/components/ProductGrid.cjs.js +1 -1
  49. package/lib/components/ProductGrid.es.js +23 -32
  50. package/lib/components/ShippingEstimator.cjs.js +1 -1
  51. package/lib/components/ShippingEstimator.es.js +124 -231
  52. package/lib/components/ShortDescription.cjs.js +1 -0
  53. package/lib/components/ShortDescription.d.ts +19 -0
  54. package/lib/components/ShortDescription.es.js +18 -0
  55. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  56. package/lib/components/SimpleTiptapRenderer.es.js +111 -294
  57. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  58. package/lib/components/SubscriptionSelector.es.js +120 -181
  59. package/lib/components/media/MediaPickerDialog.d.ts +1 -1
  60. package/lib/components/media/MediaUploadForm.d.ts +1 -1
  61. package/lib/invoice.cjs.js +1 -1
  62. package/lib/invoice.d.ts +1 -1
  63. package/lib/invoice.es.js +6 -5
  64. package/lib/order-inventory.d.ts +1 -1
  65. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  66. package/lib/pages/cms/coupons/CouponEditorForm.es.js +115 -375
  67. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  68. package/lib/pages/cms/coupons/CouponsPage.es.js +116 -368
  69. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  70. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +26 -62
  71. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  72. package/lib/pages/cms/coupons/EditCouponPage.es.js +35 -71
  73. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  74. package/lib/pages/cms/coupons/ProductScopePicker.es.js +72 -167
  75. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  76. package/lib/pages/cms/orders/ExportReportsDialog.es.js +87 -247
  77. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  78. package/lib/pages/cms/orders/OrderDetailPage.es.js +95 -283
  79. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  80. package/lib/pages/cms/orders/OrderPrintButton.es.js +9 -21
  81. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  82. package/lib/pages/cms/orders/OrderStatusForm.es.js +46 -106
  83. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  84. package/lib/pages/cms/orders/OrdersPage.es.js +78 -257
  85. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  86. package/lib/pages/cms/payments/PaymentsClient.es.js +192 -580
  87. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  88. package/lib/pages/cms/payments/PaymentsPage.es.js +14 -22
  89. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  90. package/lib/pages/cms/products/ProductsPage.es.js +47 -87
  91. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  92. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +97 -177
  93. package/lib/pages/cms/products/actions.d.ts +20 -20
  94. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  95. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +40 -84
  96. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  97. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  98. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +192 -455
  99. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  100. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +28 -72
  101. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  102. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +183 -490
  103. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  104. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +69 -177
  105. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  106. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +102 -213
  107. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  108. package/lib/pages/cms/products/components/DeleteProductButton.es.js +25 -45
  109. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  110. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +58 -202
  111. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  112. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +89 -235
  113. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  114. package/lib/pages/cms/products/components/ProductForm.es.js +526 -1110
  115. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  116. package/lib/pages/cms/products/components/ProductMediaManager.es.js +63 -154
  117. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  118. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +213 -544
  119. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  120. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +91 -207
  121. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  122. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +16 -28
  123. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  124. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +25 -37
  125. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  126. package/lib/pages/cms/products/components/VariationsEditor.es.js +261 -492
  127. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  128. package/lib/pages/cms/products/inventory/InventoryPage.es.js +12 -32
  129. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  130. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +145 -365
  131. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  132. package/lib/pages/cms/products/new/NewProductPage.es.js +30 -42
  133. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  134. package/lib/pages/cms/shipping/ShippingPage.es.js +155 -507
  135. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  136. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  137. package/lib/pages/cms/shipping/components/RateForm.es.js +334 -717
  138. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  139. package/lib/pages/cms/shipping/components/ZoneForm.es.js +158 -392
  140. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  141. package/lib/pages/cms/taxes/TaxesPage.es.js +119 -447
  142. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  143. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +52 -156
  144. package/lib/product-actions.d.ts +31 -31
  145. package/lib/product-context.cjs.js +1 -1
  146. package/lib/product-context.es.js +10 -14
  147. package/lib/shared-inventory.d.ts +1 -1
  148. package/lib/states.cjs.js +1 -1
  149. package/lib/states.d.ts +2 -0
  150. package/lib/states.es.js +63 -29
  151. package/lib/trials.cjs.js +1 -1
  152. package/lib/trials.d.ts +10 -3
  153. package/lib/trials.es.js +28 -21
  154. package/lib/types.d.ts +2 -0
  155. package/lib/use-price-formatter.cjs.js +1 -0
  156. package/lib/use-price-formatter.d.ts +11 -0
  157. package/lib/use-price-formatter.es.js +13 -0
  158. package/lib/variation-utils.cjs.js +1 -1
  159. package/lib/variation-utils.d.ts +10 -0
  160. package/lib/variation-utils.es.js +139 -123
  161. package/package.json +4 -4
package/lib/states.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { normalizeCountryCode as t } from "./countries.es.js";
1
+ import { normalizeCountryCode as i } from "./countries.es.js";
2
2
  const C = [
3
3
  { code: "AL", name: "Alabama" },
4
4
  { code: "AK", name: "Alaska" },
@@ -51,7 +51,7 @@ const C = [
51
51
  { code: "WV", name: "West Virginia" },
52
52
  { code: "WI", name: "Wisconsin" },
53
53
  { code: "WY", name: "Wyoming" }
54
- ], u = [
54
+ ], A = [
55
55
  { code: "AB", name: "Alberta" },
56
56
  { code: "BC", name: "British Columbia" },
57
57
  { code: "MB", name: "Manitoba" },
@@ -65,10 +65,43 @@ const C = [
65
65
  { code: "QC", name: "Quebec" },
66
66
  { code: "SK", name: "Saskatchewan" },
67
67
  { code: "YT", name: "Yukon" }
68
- ], i = {
68
+ ], t = {
69
69
  US: C,
70
- CA: u
71
- }, N = {
70
+ CA: A
71
+ }, l = {
72
+ CA: {
73
+ BC: "Colombie-Britannique",
74
+ NB: "Nouveau-Brunswick",
75
+ NL: "Terre-Neuve-et-Labrador",
76
+ NS: "Nouvelle-Écosse",
77
+ NT: "Territoires du Nord-Ouest",
78
+ PE: "Île-du-Prince-Édouard",
79
+ QC: "Québec"
80
+ },
81
+ US: {
82
+ CA: "Californie",
83
+ DC: "District de Columbia",
84
+ FL: "Floride",
85
+ GA: "Géorgie",
86
+ HI: "Hawaï",
87
+ LA: "Louisiane",
88
+ NC: "Caroline du Nord",
89
+ ND: "Dakota du Nord",
90
+ NM: "Nouveau-Mexique",
91
+ PA: "Pennsylvanie",
92
+ SC: "Caroline du Sud",
93
+ SD: "Dakota du Sud",
94
+ VA: "Virginie",
95
+ WV: "Virginie-Occidentale"
96
+ }
97
+ };
98
+ function T(n, e, o) {
99
+ if (!o || !o.toLowerCase().startsWith("fr"))
100
+ return e.name;
101
+ const a = i(n);
102
+ return a && l[a]?.[e.code] || e.name;
103
+ }
104
+ const s = {
72
105
  US: {
73
106
  CALIFORNIA: "CA",
74
107
  NEWYORK: "NY",
@@ -89,39 +122,40 @@ const C = [
89
122
  PRINCEEDWARDISLAND: "PE"
90
123
  }
91
124
  };
92
- function I(e) {
93
- const n = t(e);
94
- return n ? i[n] ?? [] : [];
125
+ function S(n) {
126
+ const e = i(n);
127
+ return e ? t[e] ?? [] : [];
95
128
  }
96
- function T(e) {
97
- return I(e).length > 0;
129
+ function R(n) {
130
+ return S(n).length > 0;
98
131
  }
99
- function l(e, n) {
100
- const o = t(e), a = n?.trim();
132
+ function I(n, e) {
133
+ const o = i(n), a = e?.trim();
101
134
  if (!o || !a)
102
135
  return a || null;
103
- const d = i[o];
136
+ const d = t[o];
104
137
  if (!d?.length)
105
138
  return a.toUpperCase();
106
- const c = a.toUpperCase(), r = d.find((m) => m.code === c);
107
- if (r)
108
- return r.code;
109
- const s = d.find((m) => m.name.toUpperCase() === c);
110
- if (s)
111
- return s.code;
112
- const A = c.replace(/\s+/g, "");
113
- return N[o]?.[c] ?? N[o]?.[A] ?? c;
139
+ const c = a.toUpperCase(), m = d.find((r) => r.code === c);
140
+ if (m)
141
+ return m.code;
142
+ const N = d.find((r) => r.name.toUpperCase() === c);
143
+ if (N)
144
+ return N.code;
145
+ const u = c.replace(/\s+/g, "");
146
+ return s[o]?.[c] ?? s[o]?.[u] ?? c;
114
147
  }
115
- function R(e, n) {
116
- const o = t(e), a = l(e, n);
117
- return !o || !a ? n ?? null : i[o]?.find(
148
+ function E(n, e) {
149
+ const o = i(n), a = I(n, e);
150
+ return !o || !a ? e ?? null : t[o]?.find(
118
151
  (c) => c.code === a
119
152
  )?.name ?? a;
120
153
  }
121
154
  export {
122
- i as STATES_BY_COUNTRY,
123
- T as countryUsesStructuredStates,
124
- I as getStatesForCountry,
125
- l as normalizeSubdivisionCode,
126
- R as resolveSubdivisionName
155
+ t as STATES_BY_COUNTRY,
156
+ R as countryUsesStructuredStates,
157
+ S as getStatesForCountry,
158
+ T as getSubdivisionLabel,
159
+ I as normalizeSubdivisionCode,
160
+ E as resolveSubdivisionName
127
161
  };
package/lib/trials.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){const r=Number(e?.trial_period_days??0);return!Number.isFinite(r)||r<=0?0:Math.round(r)}function i(e){return t(e)===0?null:e?.trial_requires_payment_method?"paid":"free"}function a(e){const r=t(typeof e=="number"?{trial_period_days:e}:e);return r>0?`${r}-day free trial`:null}function n(e){return e?.trial_requires_payment_method?"Payment method required":"No credit card required"}function o(e){const r=a(e);return r?{label:r,paymentRequirementLabel:n(e),checkoutMode:i(e)}:null}exports.getTrialCheckoutMode=i;exports.getTrialLabel=a;exports.getTrialPaymentRequirementLabel=n;exports.getTrialPeriodDays=t;exports.getTrialSummary=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(e){const r=Number(e?.trial_period_days??0);return!Number.isFinite(r)||r<=0?0:Math.round(r)}function o(e){return i(e)===0?null:e?.trial_requires_payment_method?"paid":"free"}function a(e,r,t,d){if(!e)return t;const n=e(r,d);return n===r?t:n}function l(e,r){const t=i(typeof e=="number"?{trial_period_days:e}:e);return t>0?a(r,"ecommerce.trial_days",`${t}-day free trial`,{count:t}):null}function u(e,r){return e?.trial_requires_payment_method?a(r,"ecommerce.trial_payment_required","Payment method required"):a(r,"ecommerce.trial_no_card","No credit card required")}function m(e,r){const t=l(e,r);return t?{label:t,paymentRequirementLabel:u(e,r),checkoutMode:o(e)}:null}exports.getTrialCheckoutMode=o;exports.getTrialLabel=l;exports.getTrialPaymentRequirementLabel=u;exports.getTrialPeriodDays=i;exports.getTrialSummary=m;
package/lib/trials.d.ts CHANGED
@@ -5,9 +5,16 @@ type TrialCarrier = {
5
5
  };
6
6
  export declare function getTrialPeriodDays(value: TrialCarrier | null | undefined): number;
7
7
  export declare function getTrialCheckoutMode(value: TrialCarrier | null | undefined): FreemiusTrialMode | null;
8
- export declare function getTrialLabel(value: TrialCarrier | number | null | undefined): string | null;
9
- export declare function getTrialPaymentRequirementLabel(value: TrialCarrier | null | undefined): "Payment method required" | "No credit card required";
10
- export declare function getTrialSummary(value: TrialCarrier | null | undefined): {
8
+ /** The `t` of `useTranslations()`. It answers an unseeded key with the key itself. */
9
+ export type TrialTranslate = (key: string, params?: Record<string, string | number>) => string;
10
+ /**
11
+ * Pass `t` from a component to get the label in the visitor's language. Without it the copy
12
+ * is English: these helpers used to return English only, so every product card, the cart
13
+ * and the checkout showed "14-day free trial" on French pages.
14
+ */
15
+ export declare function getTrialLabel(value: TrialCarrier | number | null | undefined, t?: TrialTranslate): string | null;
16
+ export declare function getTrialPaymentRequirementLabel(value: TrialCarrier | null | undefined, t?: TrialTranslate): string;
17
+ export declare function getTrialSummary(value: TrialCarrier | null | undefined, t?: TrialTranslate): {
11
18
  label: string;
12
19
  paymentRequirementLabel: string;
13
20
  checkoutMode: FreemiusTrialMode | null;
package/lib/trials.es.js CHANGED
@@ -1,29 +1,36 @@
1
- function t(e) {
2
- const r = Number(e?.trial_period_days ?? 0);
3
- return !Number.isFinite(r) || r <= 0 ? 0 : Math.round(r);
1
+ function i(r) {
2
+ const e = Number(r?.trial_period_days ?? 0);
3
+ return !Number.isFinite(e) || e <= 0 ? 0 : Math.round(e);
4
4
  }
5
- function i(e) {
6
- return t(e) === 0 ? null : e?.trial_requires_payment_method ? "paid" : "free";
5
+ function u(r) {
6
+ return i(r) === 0 ? null : r?.trial_requires_payment_method ? "paid" : "free";
7
7
  }
8
- function n(e) {
9
- const r = t(typeof e == "number" ? { trial_period_days: e } : e);
10
- return r > 0 ? `${r}-day free trial` : null;
8
+ function n(r, e, t, o) {
9
+ if (!r) return t;
10
+ const a = r(e, o);
11
+ return a === e ? t : a;
11
12
  }
12
- function a(e) {
13
- return e?.trial_requires_payment_method ? "Payment method required" : "No credit card required";
13
+ function d(r, e) {
14
+ const t = i(typeof r == "number" ? { trial_period_days: r } : r);
15
+ return t > 0 ? n(e, "ecommerce.trial_days", `${t}-day free trial`, {
16
+ count: t
17
+ }) : null;
14
18
  }
15
- function o(e) {
16
- const r = n(e);
17
- return r ? {
18
- label: r,
19
- paymentRequirementLabel: a(e),
20
- checkoutMode: i(e)
19
+ function l(r, e) {
20
+ return r?.trial_requires_payment_method ? n(e, "ecommerce.trial_payment_required", "Payment method required") : n(e, "ecommerce.trial_no_card", "No credit card required");
21
+ }
22
+ function c(r, e) {
23
+ const t = d(r, e);
24
+ return t ? {
25
+ label: t,
26
+ paymentRequirementLabel: l(r, e),
27
+ checkoutMode: u(r)
21
28
  } : null;
22
29
  }
23
30
  export {
24
- i as getTrialCheckoutMode,
25
- n as getTrialLabel,
26
- a as getTrialPaymentRequirementLabel,
27
- t as getTrialPeriodDays,
28
- o as getTrialSummary
31
+ u as getTrialCheckoutMode,
32
+ d as getTrialLabel,
33
+ l as getTrialPaymentRequirementLabel,
34
+ i as getTrialPeriodDays,
35
+ c as getTrialSummary
29
36
  };
package/lib/types.d.ts CHANGED
@@ -89,6 +89,8 @@ export interface Product {
89
89
  images?: {
90
90
  url: string;
91
91
  alt?: string;
92
+ width?: number;
93
+ height?: number;
92
94
  }[];
93
95
  short_description?: string | null;
94
96
  description_json?: any;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@nextblock-cms/utils");function t(e){return e?e==="fr"?"fr-CA":e==="en"?"en-US":e:"en-US"}function c(){const{lang:e}=r.useTranslations(),n=t(e);return(i,o)=>r.formatPrice(i,o,n)}exports.getPriceLocale=t;exports.usePriceFormatter=c;
@@ -0,0 +1,11 @@
1
+ /** The regional locale prices are formatted in, from the site language. */
2
+ export declare function getPriceLocale(lang?: string | null): string;
3
+ /**
4
+ * `formatPrice` bound to the visitor's language.
5
+ *
6
+ * The shared helper defaults to `en-US`, and no shop component passed a locale, so a French
7
+ * page showed `$1,234.50` instead of `1 234,50 $`. Components take this hook and keep calling
8
+ * `formatPrice(amount, currency)` as before. The language comes from the translations
9
+ * provider, which is the same on the server and in the browser: no hydration mismatch.
10
+ */
11
+ export declare function usePriceFormatter(): (amount: number, currencyCode?: string) => string;
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+ import { useTranslations as o, formatPrice as i } from "@nextblock-cms/utils";
3
+ function c(r) {
4
+ return r ? r === "fr" ? "fr-CA" : r === "en" ? "en-US" : r : "en-US";
5
+ }
6
+ function u() {
7
+ const { lang: r } = o(), e = c(r);
8
+ return (t, n) => i(t, n, e);
9
+ }
10
+ export {
11
+ c as getPriceLocale,
12
+ u as usePriceFormatter
13
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./currency.cjs.js");function f(e){return!e||typeof e!="object"||Array.isArray(e)?null:Object.entries(e).reduce((r,[n,t])=>(typeof t=="string"&&t.trim()&&(r[n]=t.trim()),r),{})}function p(e,r,n){return!n||!r?e:r[n]?.trim()||e}function k(e,r){return p(e.name,e.name_translations,r)}function E(e,r){return p(e.value,e.value_translations,r)}function V(e){return e?e.startsWith("http")?e:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}`:e:null}function I(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function A(e){return[...e].sort().join("__")}function S(e){return e.map(r=>r.term_value).join(" / ")}function P(e){return e.length===0?[]:e.reduce((r,n)=>r.flatMap(t=>n.map(s=>[...t,s])),[[]])}function B(e){const{baseSku:r,basePrice:n,basePrices:t={},baseSalePrice:s=null,baseSalePrices:i={},selectedAttributes:o,previousVariants:c=[]}=e;if(o.length===0||o.some(l=>l.terms.length===0))return[];const u=new Map(c.map(l=>[l.combination_key,l])),a=o.map(l=>l.terms.map(d=>({attribute_id:l.attribute_id,attribute_name:l.attribute_name,term:d})));return P(a).map(l=>{const d=l.map(({attribute_id:m,attribute_name:M,term:g})=>({attribute_id:m,attribute_name:M,term_id:g.id,term_value:g.value,term_slug:g.slug})),T=d.map(m=>m.term_id),h=A(T),_=u.get(h),y=d.map(m=>(m.term_slug?m.term_slug:I(m.term_value)).toUpperCase()).filter(Boolean).join("-");return{id:_?.id,combination_key:h,sku:_?.sku||[r.trim(),y].filter(Boolean).join("-"),upc:_?.upc??null,price:_?.price??n,prices:_?.prices??b.normalizePriceMap(t),sale_price:_?.sale_price??s,sale_prices:_?.sale_prices??b.normalizeSalePriceMap(i),sale_start_at:_?.sale_start_at??null,sale_end_at:_?.sale_end_at??null,stock_quantity:_?.stock_quantity??0,main_media_id:_?.main_media_id??null,main_image_url:_?.main_image_url??null,attribute_term_ids:T,selected_options:d,label:S(d)}})}function R(e){const r={};for(const n of e)for(const t of n.selected_options??[]){const s=new Set(r[t.attribute_id]??[]);s.add(t.term_id),r[t.attribute_id]=[...s]}return r}function U(e,r){const n=Object.values(r).filter(Boolean);return n.length===0?null:e.find(t=>t.attribute_term_ids.length===n.length&&n.every(s=>t.attribute_term_ids.includes(s)))??null}function v(e,r,n){const t=new Set;for(const s of e){if(!Object.entries(n).every(([c,u])=>!u||c===r?!0:s.attribute_term_ids.includes(u)))continue;const o=s.selected_options.find(c=>c.attribute_id===r);o&&t.add(o.term_id)}return t}function j(e,r){const n=r.find(t=>t.stock_quantity>0)??r[0]??null;return n?n.selected_options.reduce((t,s)=>(t[s.attribute_id]=s.term_id,t),{}):e.reduce((t,s)=>{const i=s.terms[0];return i&&(t[s.id]=i.id),t},{})}function z(e,r,n){const t={...n};for(const s of e){const i=v(r,s.id,t);if(i.size===0){delete t[s.id];continue}const o=t[s.id];if(o&&i.has(o))continue;const c=s.terms.find(u=>i.has(u.id));c&&(t[s.id]=c.id)}return t}function L(e=[],r){const n=new Map,t=e.map(i=>{const o=(i.variant_attribute_mapping||[]).map(u=>{const a=u.product_attribute_terms,l=a?.product_attributes;if(!a||!l)return null;const d=n.get(l.id)||{id:l.id,name:p(l.name,f(l.name_translations),r),slug:l.slug,name_translations:f(l.name_translations),terms:[],_termIds:new Set};return d._termIds.has(a.id)||(d.terms.push({id:a.id,attribute_id:a.attribute_id,value:p(a.value,f(a.value_translations),r),slug:a.slug,sort_order:a.sort_order??null,value_translations:f(a.value_translations)}),d._termIds.add(a.id)),n.set(l.id,d),{attribute_id:l.id,attribute_name:p(l.name,f(l.name_translations),r),term_id:a.id,term_value:p(a.value,f(a.value_translations),r),term_slug:a.slug}}).filter(u=>u!==null).sort((u,a)=>u.attribute_name.localeCompare(a.attribute_name)),c=o.map(u=>u.term_id);return{id:i.id,combination_key:A(c),sku:i.sku,upc:i.upc??null,price:i.price??0,prices:b.normalizePriceMap(i.prices),sale_price:i.sale_price??null,sale_prices:b.normalizeSalePriceMap(i.sale_prices),sale_start_at:i.sale_start_at??null,sale_end_at:i.sale_end_at??null,scheduled_price:i.scheduled_price??null,scheduled_prices:b.normalizePriceMap(i.scheduled_prices),scheduled_price_at:i.scheduled_price_at??null,stock_quantity:i.stock_quantity??0,main_media_id:i.main_media_id??null,image_url:V(i.media?.file_path??i.media?.object_key??null),attribute_term_ids:c,selected_options:o,label:S(o)}});return{attributes:[...n.values()].map(i=>({id:i.id,name:i.name,slug:i.slug,name_translations:i.name_translations,terms:[...i.terms].sort((o,c)=>{const u=o.sort_order??Number.MAX_SAFE_INTEGER,a=c.sort_order??Number.MAX_SAFE_INTEGER;return u!==a?u-a:o.value.localeCompare(c.value)})})).sort((i,o)=>i.name.localeCompare(o.name)),variants:t}}function N(e,r){if(!e.length)return null;const n=e.map(t=>b.isSaleWindowActive({saleStartAt:t.sale_start_at,saleEndAt:t.sale_end_at,now:r})&&typeof t.sale_price=="number"?t.sale_price:t.price);return{min:Math.min(...n),max:Math.max(...n)}}exports.buildCombinationKey=A;exports.buildVariantLabel=S;exports.chooseInitialVariantSelections=j;exports.extractSelectedTermsByAttribute=R;exports.findMatchingVariant=U;exports.generateVariantDrafts=B;exports.getAvailableTermIdsForAttribute=v;exports.getVariantEffectivePriceRange=N;exports.mapRawVariantRelations=L;exports.normalizeSelectionsToAvailableVariants=z;exports.resolveAttributeName=k;exports.resolveTermValue=E;exports.resolveTranslatedText=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./currency.cjs.js");function f(e){return!e||typeof e!="object"||Array.isArray(e)?null:Object.entries(e).reduce((i,[n,t])=>(typeof t=="string"&&t.trim()&&(i[n]=t.trim()),i),{})}function p(e,i,n){return!n||!i?e:i[n]?.trim()||e}function V(e,i){return p(e.name,e.name_translations,i)}function M(e,i){return p(e.value,e.value_translations,i)}function E(e){return e?e.startsWith("http")?e:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}`:e:null}function I(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function S(e){return[...e].sort().join("__")}function A(e){return e.map(i=>i.term_value).join(" / ")}function P(e){return e.length===0?[]:e.reduce((i,n)=>i.flatMap(t=>n.map(a=>[...t,a])),[[]])}function B(e){const{baseSku:i,basePrice:n,basePrices:t={},baseSalePrice:a=null,baseSalePrices:r={},selectedAttributes:s,previousVariants:c=[]}=e;if(s.length===0||s.some(o=>o.terms.length===0))return[];const u=new Map(c.map(o=>[o.combination_key,o])),l=s.map(o=>o.terms.map(d=>({attribute_id:o.attribute_id,attribute_name:o.attribute_name,term:d})));return P(l).map(o=>{const d=o.map(({attribute_id:m,attribute_name:k,term:g})=>({attribute_id:m,attribute_name:k,term_id:g.id,term_value:g.value,term_slug:g.slug})),h=d.map(m=>m.term_id),y=S(h),_=u.get(y),v=d.map(m=>(m.term_slug?m.term_slug:I(m.term_value)).toUpperCase()).filter(Boolean).join("-");return{id:_?.id,combination_key:y,sku:_?.sku||[i.trim(),v].filter(Boolean).join("-"),upc:_?.upc??null,price:_?.price??n,prices:_?.prices??b.normalizePriceMap(t),sale_price:_?.sale_price??a,sale_prices:_?.sale_prices??b.normalizeSalePriceMap(r),sale_start_at:_?.sale_start_at??null,sale_end_at:_?.sale_end_at??null,stock_quantity:_?.stock_quantity??0,main_media_id:_?.main_media_id??null,main_image_url:_?.main_image_url??null,attribute_term_ids:h,selected_options:d,label:A(d)}})}function R(e){const i={};for(const n of e)for(const t of n.selected_options??[]){const a=new Set(i[t.attribute_id]??[]);a.add(t.term_id),i[t.attribute_id]=[...a]}return i}function U(e,i){const n=Object.values(i).filter(Boolean);return n.length===0?null:e.find(t=>t.attribute_term_ids.length===n.length&&n.every(a=>t.attribute_term_ids.includes(a)))??null}function T(e,i,n){const t=new Set;for(const a of e){if(!Object.entries(n).every(([c,u])=>!u||c===i?!0:a.attribute_term_ids.includes(u)))continue;const s=a.selected_options.find(c=>c.attribute_id===i);s&&t.add(s.term_id)}return t}function j(e,i){const n=i.find(t=>t.stock_quantity>0)??i[0]??null;return n?n.selected_options.reduce((t,a)=>(t[a.attribute_id]=a.term_id,t),{}):e.reduce((t,a)=>{const r=a.terms[0];return r&&(t[a.id]=r.id),t},{})}function z(e,i,n,t,a){const r={[t]:a};for(const s of e){if(s.id===t)continue;const c=T(i,s.id,r),u=n[s.id];if(u&&c.has(u)){r[s.id]=u;continue}const l=s.terms.find(o=>c.has(o.id));l&&(r[s.id]=l.id)}return r}function L(e,i,n){const t={...n};for(const a of e){const r=T(i,a.id,t);if(r.size===0){delete t[a.id];continue}const s=t[a.id];if(s&&r.has(s))continue;const c=a.terms.find(u=>r.has(u.id));c&&(t[a.id]=c.id)}return t}function N(e=[],i){const n=new Map,t=e.map(r=>{const s=(r.variant_attribute_mapping||[]).map(u=>{const l=u.product_attribute_terms,o=l?.product_attributes;if(!l||!o)return null;const d=n.get(o.id)||{id:o.id,name:p(o.name,f(o.name_translations),i),slug:o.slug,name_translations:f(o.name_translations),terms:[],_termIds:new Set};return d._termIds.has(l.id)||(d.terms.push({id:l.id,attribute_id:l.attribute_id,value:p(l.value,f(l.value_translations),i),slug:l.slug,sort_order:l.sort_order??null,value_translations:f(l.value_translations)}),d._termIds.add(l.id)),n.set(o.id,d),{attribute_id:o.id,attribute_name:p(o.name,f(o.name_translations),i),term_id:l.id,term_value:p(l.value,f(l.value_translations),i),term_slug:l.slug}}).filter(u=>u!==null).sort((u,l)=>u.attribute_name.localeCompare(l.attribute_name)),c=s.map(u=>u.term_id);return{id:r.id,combination_key:S(c),sku:r.sku,upc:r.upc??null,price:r.price??0,prices:b.normalizePriceMap(r.prices),sale_price:r.sale_price??null,sale_prices:b.normalizeSalePriceMap(r.sale_prices),sale_start_at:r.sale_start_at??null,sale_end_at:r.sale_end_at??null,scheduled_price:r.scheduled_price??null,scheduled_prices:b.normalizePriceMap(r.scheduled_prices),scheduled_price_at:r.scheduled_price_at??null,stock_quantity:r.stock_quantity??0,main_media_id:r.main_media_id??null,image_url:E(r.media?.file_path??r.media?.object_key??null),attribute_term_ids:c,selected_options:s,label:A(s)}});return{attributes:[...n.values()].map(r=>({id:r.id,name:r.name,slug:r.slug,name_translations:r.name_translations,terms:[...r.terms].sort((s,c)=>{const u=s.sort_order??Number.MAX_SAFE_INTEGER,l=c.sort_order??Number.MAX_SAFE_INTEGER;return u!==l?u-l:s.value.localeCompare(c.value)})})).sort((r,s)=>r.name.localeCompare(s.name)),variants:t}}function O(e,i){if(!e.length)return null;const n=e.map(t=>b.isSaleWindowActive({saleStartAt:t.sale_start_at,saleEndAt:t.sale_end_at,now:i})&&typeof t.sale_price=="number"?t.sale_price:t.price);return{min:Math.min(...n),max:Math.max(...n)}}exports.applyVariantSelection=z;exports.buildCombinationKey=S;exports.buildVariantLabel=A;exports.chooseInitialVariantSelections=j;exports.extractSelectedTermsByAttribute=R;exports.findMatchingVariant=U;exports.generateVariantDrafts=B;exports.getAvailableTermIdsForAttribute=T;exports.getVariantEffectivePriceRange=O;exports.mapRawVariantRelations=N;exports.normalizeSelectionsToAvailableVariants=L;exports.resolveAttributeName=V;exports.resolveTermValue=M;exports.resolveTranslatedText=p;
@@ -59,6 +59,16 @@ export declare function extractSelectedTermsByAttribute(variants: Array<{
59
59
  export declare function findMatchingVariant(variants: ProductVariant[], selections: Record<string, string | undefined>): ProductVariant | null;
60
60
  export declare function getAvailableTermIdsForAttribute(variants: ProductVariant[], attributeId: string, selections: Record<string, string | undefined>): Set<string>;
61
61
  export declare function chooseInitialVariantSelections(attributes: ProductAttribute[], variants: ProductVariant[]): Record<string, string>;
62
+ /**
63
+ * The selections after the shopper picks `termId` for `attributeId`.
64
+ *
65
+ * The pick always wins. Every other attribute keeps its current term when some variant
66
+ * combines it with everything chosen so far, and otherwise moves to the first term that
67
+ * does. With a sparse matrix (only Red/S and Blue/M exist) choosing Blue therefore lands on
68
+ * Blue/M. The old flow re-normalized `{...current, [attributeId]: termId}` attribute by
69
+ * attribute, which reverted the pick itself whenever it clashed with another dropdown.
70
+ */
71
+ export declare function applyVariantSelection(attributes: ProductAttribute[], variants: ProductVariant[], current: Record<string, string | undefined>, attributeId: string, termId: string): Record<string, string | undefined>;
62
72
  export declare function normalizeSelectionsToAvailableVariants(attributes: ProductAttribute[], variants: ProductVariant[], selections: Record<string, string | undefined>): {
63
73
  [x: string]: string | undefined;
64
74
  };