@nextblock-cms/ecom 0.18.8 → 0.19.2

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 (150) 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.es.js +154 -381
  16. package/lib/components/CartDrawer.cjs.js +1 -1
  17. package/lib/components/CartDrawer.es.js +143 -297
  18. package/lib/components/CartIcon.cjs.js +1 -1
  19. package/lib/components/CartIcon.es.js +21 -47
  20. package/lib/components/Checkout.cjs.js +1 -1
  21. package/lib/components/Checkout.es.js +814 -1614
  22. package/lib/components/CouponForm.cjs.js +1 -1
  23. package/lib/components/CouponForm.es.js +104 -155
  24. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  25. package/lib/components/CurrencySwitcher.es.js +14 -33
  26. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  27. package/lib/components/CustomerProfileForm.es.js +264 -672
  28. package/lib/components/FeaturedProduct.cjs.js +1 -1
  29. package/lib/components/FeaturedProduct.es.js +46 -125
  30. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  31. package/lib/components/FreemiusLicensePanel.es.js +45 -125
  32. package/lib/components/InvoiceDocument.cjs.js +1 -1
  33. package/lib/components/InvoiceDocument.es.js +148 -487
  34. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  35. package/lib/components/InvoiceViewerShell.d.ts +4 -1
  36. package/lib/components/InvoiceViewerShell.es.js +59 -142
  37. package/lib/components/ProductCard.cjs.js +1 -1
  38. package/lib/components/ProductCard.d.ts +3 -1
  39. package/lib/components/ProductCard.es.js +128 -242
  40. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  41. package/lib/components/ProductDetailsLayout.es.js +311 -652
  42. package/lib/components/ProductGallery.cjs.js +1 -1
  43. package/lib/components/ProductGallery.d.ts +2 -0
  44. package/lib/components/ProductGallery.es.js +37 -66
  45. package/lib/components/ProductGrid.cjs.js +1 -1
  46. package/lib/components/ProductGrid.es.js +23 -32
  47. package/lib/components/ShippingEstimator.cjs.js +1 -1
  48. package/lib/components/ShippingEstimator.es.js +118 -231
  49. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  50. package/lib/components/SimpleTiptapRenderer.es.js +111 -294
  51. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  52. package/lib/components/SubscriptionSelector.es.js +120 -181
  53. package/lib/freemius-trial-provision.cjs.js +1 -0
  54. package/lib/freemius-trial-provision.d.ts +85 -0
  55. package/lib/freemius-trial-provision.es.js +136 -0
  56. package/lib/invoice.cjs.js +1 -1
  57. package/lib/invoice.d.ts +1 -1
  58. package/lib/invoice.es.js +6 -5
  59. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  60. package/lib/pages/cms/coupons/CouponEditorForm.es.js +115 -375
  61. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  62. package/lib/pages/cms/coupons/CouponsPage.es.js +116 -368
  63. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  64. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +26 -62
  65. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  66. package/lib/pages/cms/coupons/EditCouponPage.es.js +35 -71
  67. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  68. package/lib/pages/cms/coupons/ProductScopePicker.es.js +72 -167
  69. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  70. package/lib/pages/cms/orders/ExportReportsDialog.es.js +87 -247
  71. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  72. package/lib/pages/cms/orders/OrderDetailPage.es.js +95 -283
  73. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  74. package/lib/pages/cms/orders/OrderPrintButton.es.js +9 -21
  75. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  76. package/lib/pages/cms/orders/OrderStatusForm.es.js +46 -106
  77. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  78. package/lib/pages/cms/orders/OrdersPage.es.js +78 -257
  79. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  80. package/lib/pages/cms/payments/PaymentsClient.es.js +192 -580
  81. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  82. package/lib/pages/cms/payments/PaymentsPage.es.js +14 -22
  83. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  84. package/lib/pages/cms/products/ProductsPage.es.js +47 -87
  85. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  86. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +97 -177
  87. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  88. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +40 -84
  89. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  90. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +192 -455
  91. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  92. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +28 -72
  93. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  94. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +183 -490
  95. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  96. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +69 -177
  97. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  98. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +102 -213
  99. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  100. package/lib/pages/cms/products/components/DeleteProductButton.es.js +25 -45
  101. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  102. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +58 -202
  103. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  104. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +89 -235
  105. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  106. package/lib/pages/cms/products/components/ProductForm.es.js +526 -1110
  107. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  108. package/lib/pages/cms/products/components/ProductMediaManager.es.js +63 -154
  109. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  110. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +213 -544
  111. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  112. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +91 -207
  113. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  114. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +16 -28
  115. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  116. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +25 -37
  117. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  118. package/lib/pages/cms/products/components/VariationsEditor.es.js +261 -492
  119. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  120. package/lib/pages/cms/products/inventory/InventoryPage.es.js +12 -32
  121. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  122. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +145 -365
  123. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  124. package/lib/pages/cms/products/new/NewProductPage.es.js +30 -42
  125. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  126. package/lib/pages/cms/shipping/ShippingPage.es.js +155 -507
  127. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  128. package/lib/pages/cms/shipping/components/RateForm.es.js +334 -717
  129. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  130. package/lib/pages/cms/shipping/components/ZoneForm.es.js +158 -392
  131. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  132. package/lib/pages/cms/taxes/TaxesPage.es.js +119 -447
  133. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  134. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +52 -156
  135. package/lib/product-context.cjs.js +1 -1
  136. package/lib/product-context.es.js +10 -14
  137. package/lib/trials.cjs.js +1 -1
  138. package/lib/trials.d.ts +10 -3
  139. package/lib/trials.es.js +28 -21
  140. package/lib/types.d.ts +2 -0
  141. package/lib/use-price-formatter.cjs.js +1 -0
  142. package/lib/use-price-formatter.d.ts +11 -0
  143. package/lib/use-price-formatter.es.js +13 -0
  144. package/lib/variation-utils.cjs.js +1 -1
  145. package/lib/variation-utils.d.ts +10 -0
  146. package/lib/variation-utils.es.js +139 -123
  147. package/package.json +4 -4
  148. package/server.cjs.js +1 -1
  149. package/server.d.ts +1 -0
  150. package/server.es.js +180 -172
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-dev-runtime"),r=require("@nextblock-cms/ui"),n=require("react"),u=require("../../../../countries.cjs.js"),c=require("../../../../states.cjs.js"),R=require("../actions.cjs.js");function j({initialData:e,submitLabel:x="Save tax rate",compact:l=!1}){const d=u.normalizeCountryCode(e?.country_code)||"US",[o,N]=n.useState(d),[m,a]=n.useState(c.normalizeSubdivisionCode(d,e?.state_code)||e?.state_code||""),b=n.useMemo(()=>c.getStatesForCountry(o),[o]),p=c.countryUsesStructuredStates(o);return s.jsxDEV("form",{action:R.saveTaxRateAction,className:"space-y-4",children:[e?.id?s.jsxDEV("input",{type:"hidden",name:"id",value:e.id},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:39,columnNumber:26},this):null,s.jsxDEV("div",{className:l?"grid gap-4 md:grid-cols-4":"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[s.jsxDEV("div",{className:"space-y-2",children:[s.jsxDEV(r.Label,{htmlFor:e?.id?`country-${e.id}`:"tax-rate-country",children:"Country"},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:43,columnNumber:11},this),s.jsxDEV("select",{id:e?.id?`country-${e.id}`:"tax-rate-country",name:"country_code",value:o,onChange:t=>{const i=t.target.value,f=c.getStatesForCountry(i);N(i),a(f.some(h=>h.code===m)?m:"")},className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:u.countries.map(t=>s.jsxDEV("option",{value:t.code,children:t.name},t.code,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:62,columnNumber:15},this))},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:46,columnNumber:11},this)]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:42,columnNumber:9},this),s.jsxDEV("div",{className:"space-y-2",children:[s.jsxDEV(r.Label,{htmlFor:e?.id?`state-${e.id}`:"tax-rate-state",children:"State / Province"},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:70,columnNumber:11},this),p?s.jsxDEV("select",{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:m,onChange:t=>a(t.target.value),className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[s.jsxDEV("option",{value:"",children:"Country-wide / federal"},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:81,columnNumber:15},this),b.map(t=>s.jsxDEV("option",{value:t.code,children:t.name},t.code,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:83,columnNumber:17},this))]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:74,columnNumber:13},this):s.jsxDEV(r.Input,{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:m,onChange:t=>a(t.target.value),placeholder:"Optional"},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:89,columnNumber:13},this)]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:69,columnNumber:9},this),s.jsxDEV("div",{className:"space-y-2",children:[s.jsxDEV(r.Label,{htmlFor:e?.id?`name-${e.id}`:"tax-rate-name",children:"Tax name"},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:100,columnNumber:11},this),s.jsxDEV(r.Input,{id:e?.id?`name-${e.id}`:"tax-rate-name",name:"tax_name",defaultValue:e?.tax_name||"",placeholder:"GST, PST, State Sales Tax",required:!0},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:103,columnNumber:11},this)]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:99,columnNumber:9},this),s.jsxDEV("div",{className:"space-y-2",children:[s.jsxDEV(r.Label,{htmlFor:e?.id?`rate-${e.id}`:"tax-rate-rate",children:"Rate (%)"},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:113,columnNumber:11},this),s.jsxDEV(r.Input,{id:e?.id?`rate-${e.id}`:"tax-rate-rate",name:"tax_rate",type:"number",min:"0",max:"100",step:"0.0001",defaultValue:typeof e?.tax_rate=="number"?e.tax_rate.toString():"",placeholder:"5.0000",required:!0},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:116,columnNumber:11},this)]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:112,columnNumber:9},this)]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:41,columnNumber:7},this),s.jsxDEV("div",{className:"flex justify-end",children:s.jsxDEV(r.Button,{type:"submit",size:l?"sm":"default",children:x},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:133,columnNumber:9},this)},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:132,columnNumber:7},this)]},void 0,!0,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",lineNumber:38,columnNumber:5},this)}exports.TaxRateForm=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),s=require("@nextblock-cms/ui"),u=require("react"),m=require("../../../../countries.cjs.js"),c=require("../../../../states.cjs.js"),S=require("../actions.cjs.js");function C({initialData:e,submitLabel:p="Save tax rate",compact:a=!1}){const l=m.normalizeCountryCode(e?.country_code)||"US",[d,h]=u.useState(l),[o,n]=u.useState(c.normalizeSubdivisionCode(l,e?.state_code)||e?.state_code||""),y=u.useMemo(()=>c.getStatesForCountry(d),[d]),j=c.countryUsesStructuredStates(d);return t.jsxs("form",{action:S.saveTaxRateAction,className:"space-y-4",children:[e?.id?t.jsx("input",{type:"hidden",name:"id",value:e.id}):null,t.jsxs("div",{className:a?"grid gap-4 md:grid-cols-4":"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`country-${e.id}`:"tax-rate-country",children:"Country"}),t.jsx("select",{id:e?.id?`country-${e.id}`:"tax-rate-country",name:"country_code",value:d,onChange:r=>{const x=r.target.value,g=c.getStatesForCountry(x);h(x),n(g.some(v=>v.code===o)?o:"")},className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:m.countries.map(r=>t.jsx("option",{value:r.code,children:r.name},r.code))})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`state-${e.id}`:"tax-rate-state",children:"State / Province"}),j?t.jsxs("select",{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:o,onChange:r=>n(r.target.value),className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[t.jsx("option",{value:"",children:"Country-wide / federal"}),y.map(r=>t.jsx("option",{value:r.code,children:r.name},r.code))]}):t.jsx(s.Input,{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:o,onChange:r=>n(r.target.value),placeholder:"Optional"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`name-${e.id}`:"tax-rate-name",children:"Tax name"}),t.jsx(s.Input,{id:e?.id?`name-${e.id}`:"tax-rate-name",name:"tax_name",defaultValue:e?.tax_name||"",placeholder:"GST, PST, State Sales Tax",required:!0})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`rate-${e.id}`:"tax-rate-rate",children:"Rate (%)"}),t.jsx(s.Input,{id:e?.id?`rate-${e.id}`:"tax-rate-rate",name:"tax_rate",type:"number",min:"0",max:"100",step:"0.0001",defaultValue:typeof e?.tax_rate=="number"?e.tax_rate.toString():"",placeholder:"5.0000",required:!0})]})]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(s.Button,{type:"submit",size:a?"sm":"default",children:p})})]})}exports.TaxRateForm=C;
@@ -1,129 +1,69 @@
1
1
  'use client';
2
- import { jsxDEV as s } from "react/jsx-dev-runtime";
3
- import { Label as m, Input as a, Button as R } from "@nextblock-cms/ui";
4
- import { useState as i, useMemo as k } from "react";
5
- import { normalizeCountryCode as g, countries as v } from "../../../../countries.es.js";
6
- import { normalizeSubdivisionCode as C, getStatesForCountry as u, countryUsesStructuredStates as F } from "../../../../states.es.js";
7
- import { saveTaxRateAction as T } from "../actions.es.js";
8
- function _({
2
+ import { jsxs as t, jsx as r } from "react/jsx-runtime";
3
+ import { Label as c, Input as a, Button as S } from "@nextblock-cms/ui";
4
+ import { useState as p, useMemo as b } from "react";
5
+ import { normalizeCountryCode as i, countries as _ } from "../../../../countries.es.js";
6
+ import { normalizeSubdivisionCode as N, getStatesForCountry as x, countryUsesStructuredStates as $ } from "../../../../states.es.js";
7
+ import { saveTaxRateAction as F } from "../actions.es.js";
8
+ function q({
9
9
  initialData: e,
10
- submitLabel: x = "Save tax rate",
11
- compact: n = !1
10
+ submitLabel: h = "Save tax rate",
11
+ compact: u = !1
12
12
  }) {
13
- const l = g(e?.country_code) || "US", [o, N] = i(l), [t, c] = i(
14
- C(l, e?.state_code) || e?.state_code || ""
15
- ), p = k(() => u(o), [o]), b = F(o);
16
- return /* @__PURE__ */ s("form", { action: T, className: "space-y-4", children: [
17
- e?.id ? /* @__PURE__ */ s("input", { type: "hidden", name: "id", value: e.id }, void 0, !1, {
18
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
19
- lineNumber: 39,
20
- columnNumber: 26
21
- }, this) : null,
22
- /* @__PURE__ */ s("div", { className: n ? "grid gap-4 md:grid-cols-4" : "grid gap-4 md:grid-cols-2 xl:grid-cols-4", children: [
23
- /* @__PURE__ */ s("div", { className: "space-y-2", children: [
24
- /* @__PURE__ */ s(m, { htmlFor: e?.id ? `country-${e.id}` : "tax-rate-country", children: "Country" }, void 0, !1, {
25
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
26
- lineNumber: 43,
27
- columnNumber: 11
28
- }, this),
29
- /* @__PURE__ */ s(
13
+ const m = i(e?.country_code) || "US", [o, y] = p(m), [s, n] = p(
14
+ N(m, e?.state_code) || e?.state_code || ""
15
+ ), f = b(() => x(o), [o]), v = $(o);
16
+ return /* @__PURE__ */ t("form", { action: F, className: "space-y-4", children: [
17
+ e?.id ? /* @__PURE__ */ r("input", { type: "hidden", name: "id", value: e.id }) : null,
18
+ /* @__PURE__ */ t("div", { className: u ? "grid gap-4 md:grid-cols-4" : "grid gap-4 md:grid-cols-2 xl:grid-cols-4", children: [
19
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
20
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `country-${e.id}` : "tax-rate-country", children: "Country" }),
21
+ /* @__PURE__ */ r(
30
22
  "select",
31
23
  {
32
24
  id: e?.id ? `country-${e.id}` : "tax-rate-country",
33
25
  name: "country_code",
34
26
  value: o,
35
- onChange: (r) => {
36
- const d = r.target.value, f = u(d);
37
- N(d), c(
38
- f.some((h) => h.code === t) ? t : ""
27
+ onChange: (d) => {
28
+ const l = d.target.value, g = x(l);
29
+ y(l), n(
30
+ g.some((C) => C.code === s) ? s : ""
39
31
  );
40
32
  },
41
33
  className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
42
- children: v.map((r) => /* @__PURE__ */ s("option", { value: r.code, children: r.name }, r.code, !1, {
43
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
44
- lineNumber: 62,
45
- columnNumber: 15
46
- }, this))
47
- },
48
- void 0,
49
- !1,
50
- {
51
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
52
- lineNumber: 46,
53
- columnNumber: 11
54
- },
55
- this
34
+ children: _.map((d) => /* @__PURE__ */ r("option", { value: d.code, children: d.name }, d.code))
35
+ }
56
36
  )
57
- ] }, void 0, !0, {
58
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
59
- lineNumber: 42,
60
- columnNumber: 9
61
- }, this),
62
- /* @__PURE__ */ s("div", { className: "space-y-2", children: [
63
- /* @__PURE__ */ s(m, { htmlFor: e?.id ? `state-${e.id}` : "tax-rate-state", children: "State / Province" }, void 0, !1, {
64
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
65
- lineNumber: 70,
66
- columnNumber: 11
67
- }, this),
68
- b ? /* @__PURE__ */ s(
37
+ ] }),
38
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
39
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `state-${e.id}` : "tax-rate-state", children: "State / Province" }),
40
+ v ? /* @__PURE__ */ t(
69
41
  "select",
70
42
  {
71
43
  id: e?.id ? `state-${e.id}` : "tax-rate-state",
72
44
  name: "state_code",
73
- value: t,
74
- onChange: (r) => c(r.target.value),
45
+ value: s,
46
+ onChange: (d) => n(d.target.value),
75
47
  className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
76
48
  children: [
77
- /* @__PURE__ */ s("option", { value: "", children: "Country-wide / federal" }, void 0, !1, {
78
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
79
- lineNumber: 81,
80
- columnNumber: 15
81
- }, this),
82
- p.map((r) => /* @__PURE__ */ s("option", { value: r.code, children: r.name }, r.code, !1, {
83
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
84
- lineNumber: 83,
85
- columnNumber: 17
86
- }, this))
49
+ /* @__PURE__ */ r("option", { value: "", children: "Country-wide / federal" }),
50
+ f.map((d) => /* @__PURE__ */ r("option", { value: d.code, children: d.name }, d.code))
87
51
  ]
88
- },
89
- void 0,
90
- !0,
91
- {
92
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
93
- lineNumber: 74,
94
- columnNumber: 13
95
- },
96
- this
97
- ) : /* @__PURE__ */ s(
52
+ }
53
+ ) : /* @__PURE__ */ r(
98
54
  a,
99
55
  {
100
56
  id: e?.id ? `state-${e.id}` : "tax-rate-state",
101
57
  name: "state_code",
102
- value: t,
103
- onChange: (r) => c(r.target.value),
58
+ value: s,
59
+ onChange: (d) => n(d.target.value),
104
60
  placeholder: "Optional"
105
- },
106
- void 0,
107
- !1,
108
- {
109
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
110
- lineNumber: 89,
111
- columnNumber: 13
112
- },
113
- this
61
+ }
114
62
  )
115
- ] }, void 0, !0, {
116
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
117
- lineNumber: 69,
118
- columnNumber: 9
119
- }, this),
120
- /* @__PURE__ */ s("div", { className: "space-y-2", children: [
121
- /* @__PURE__ */ s(m, { htmlFor: e?.id ? `name-${e.id}` : "tax-rate-name", children: "Tax name" }, void 0, !1, {
122
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
123
- lineNumber: 100,
124
- columnNumber: 11
125
- }, this),
126
- /* @__PURE__ */ s(
63
+ ] }),
64
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
65
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `name-${e.id}` : "tax-rate-name", children: "Tax name" }),
66
+ /* @__PURE__ */ r(
127
67
  a,
128
68
  {
129
69
  id: e?.id ? `name-${e.id}` : "tax-rate-name",
@@ -131,28 +71,12 @@ function _({
131
71
  defaultValue: e?.tax_name || "",
132
72
  placeholder: "GST, PST, State Sales Tax",
133
73
  required: !0
134
- },
135
- void 0,
136
- !1,
137
- {
138
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
139
- lineNumber: 103,
140
- columnNumber: 11
141
- },
142
- this
74
+ }
143
75
  )
144
- ] }, void 0, !0, {
145
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
146
- lineNumber: 99,
147
- columnNumber: 9
148
- }, this),
149
- /* @__PURE__ */ s("div", { className: "space-y-2", children: [
150
- /* @__PURE__ */ s(m, { htmlFor: e?.id ? `rate-${e.id}` : "tax-rate-rate", children: "Rate (%)" }, void 0, !1, {
151
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
152
- lineNumber: 113,
153
- columnNumber: 11
154
- }, this),
155
- /* @__PURE__ */ s(
76
+ ] }),
77
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
78
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `rate-${e.id}` : "tax-rate-rate", children: "Rate (%)" }),
79
+ /* @__PURE__ */ r(
156
80
  a,
157
81
  {
158
82
  id: e?.id ? `rate-${e.id}` : "tax-rate-rate",
@@ -164,41 +88,13 @@ function _({
164
88
  defaultValue: typeof e?.tax_rate == "number" ? e.tax_rate.toString() : "",
165
89
  placeholder: "5.0000",
166
90
  required: !0
167
- },
168
- void 0,
169
- !1,
170
- {
171
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
172
- lineNumber: 116,
173
- columnNumber: 11
174
- },
175
- this
91
+ }
176
92
  )
177
- ] }, void 0, !0, {
178
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
179
- lineNumber: 112,
180
- columnNumber: 9
181
- }, this)
182
- ] }, void 0, !0, {
183
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
184
- lineNumber: 41,
185
- columnNumber: 7
186
- }, this),
187
- /* @__PURE__ */ s("div", { className: "flex justify-end", children: /* @__PURE__ */ s(R, { type: "submit", size: n ? "sm" : "default", children: x }, void 0, !1, {
188
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
189
- lineNumber: 133,
190
- columnNumber: 9
191
- }, this) }, void 0, !1, {
192
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
193
- lineNumber: 132,
194
- columnNumber: 7
195
- }, this)
196
- ] }, void 0, !0, {
197
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx",
198
- lineNumber: 38,
199
- columnNumber: 5
200
- }, this);
93
+ ] })
94
+ ] }),
95
+ /* @__PURE__ */ r("div", { className: "flex justify-end", children: /* @__PURE__ */ r(S, { type: "submit", size: u ? "sm" : "default", children: h }) })
96
+ ] });
201
97
  }
202
98
  export {
203
- _ as TaxRateForm
99
+ q as TaxRateForm
204
100
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-dev-runtime"),r=require("react"),t=r.createContext(void 0),c=({product:e,children:o})=>u.jsxDEV(t.Provider,{value:{product:e},children:o},void 0,!1,{fileName:"C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/product-context.tsx",lineNumber:17,columnNumber:5},void 0),n=()=>{const e=r.useContext(t);if(!e)throw new Error("useProduct must be used within a ProductProvider. Ensure the component is wrapped in a ProductProvider.");return e.product};exports.ProductProvider=c;exports.useProduct=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("react"),r=e.createContext(void 0),c=({product:t,children:o})=>u.jsx(r.Provider,{value:{product:t},children:o}),n=()=>{const t=e.useContext(r);if(!t)throw new Error("useProduct must be used within a ProductProvider. Ensure the component is wrapped in a ProductProvider.");return t.product};exports.ProductProvider=c;exports.useProduct=n;
@@ -1,20 +1,16 @@
1
1
  'use client';
2
- import { jsxDEV as t } from "react/jsx-dev-runtime";
3
- import { createContext as n, useContext as c } from "react";
4
- const r = n(void 0), d = ({
5
- product: e,
2
+ import { jsx as e } from "react/jsx-runtime";
3
+ import { createContext as n, useContext as u } from "react";
4
+ const t = n(void 0), i = ({
5
+ product: r,
6
6
  children: o
7
- }) => /* @__PURE__ */ t(r.Provider, { value: { product: e }, children: o }, void 0, !1, {
8
- fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/product-context.tsx",
9
- lineNumber: 17,
10
- columnNumber: 5
11
- }, void 0), i = () => {
12
- const e = c(r);
13
- if (!e)
7
+ }) => /* @__PURE__ */ e(t.Provider, { value: { product: r }, children: o }), s = () => {
8
+ const r = u(t);
9
+ if (!r)
14
10
  throw new Error("useProduct must be used within a ProductProvider. Ensure the component is wrapped in a ProductProvider.");
15
- return e.product;
11
+ return r.product;
16
12
  };
17
13
  export {
18
- d as ProductProvider,
19
- i as useProduct
14
+ i as ProductProvider,
15
+ s as useProduct
20
16
  };
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
  };