@nextblock-cms/ecom 0.20.1 → 0.21.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.
Files changed (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1,124 +1,112 @@
1
- import { create as f } from "zustand";
2
- import { persist as y, createJSONStorage as C } from "zustand/middleware";
3
- import { isDigitalItem as n } from "./types.es.js";
4
- import { useCurrency as _ } from "./CurrencyProvider.es.js";
5
- import { resolveEffectivePriceForCurrency as k } from "./currency.es.js";
6
- function a(e, o, r) {
7
- return e.reduce((t, s) => n(s) || s.sku !== o || r && s.id === r ? t : t + s.quantity, 0);
1
+ import { isDigitalItem as e } from "./types.es.js";
2
+ import { resolveEffectivePriceForCurrency as t } from "./currency.es.js";
3
+ import { useCurrency as n } from "./CurrencyProvider.es.js";
4
+ import { create as r } from "zustand";
5
+ import { createJSONStorage as i, persist as a } from "zustand/middleware";
6
+ //#region libs/ecommerce/src/lib/cart-store.ts
7
+ function o(t, n, r) {
8
+ return t.reduce((t, i) => e(i) || i.sku !== n || r && i.id === r ? t : t + i.quantity, 0);
8
9
  }
9
- const p = f()(
10
- y(
11
- (e, o) => ({
12
- items: [],
13
- appliedCoupon: null,
14
- isOpen: !1,
15
- addItem: (r) => {
16
- const { items: t } = o(), s = r.quantity ?? 1, c = typeof r.stock == "number" ? r.stock : null, i = c !== null ? a(t, r.sku) : 0;
17
- if (n(r))
18
- return t.find(
19
- (l) => l.product_id === r.product_id && n(l)
20
- ) ? {
21
- success: !1,
22
- error: "This software license is already in your cart.",
23
- errorKey: "ecommerce.cart_error_license_in_cart"
24
- } : (e({
25
- items: [...t, { ...r, quantity: 1 }],
26
- isOpen: !0
27
- }), { success: !0 });
28
- const d = t.find((u) => u.id === r.id);
29
- return c !== null && c <= 0 ? {
30
- success: !1,
31
- error: "This item is out of stock.",
32
- errorKey: "ecommerce.cart_error_out_of_stock"
33
- } : c !== null && i + s > c ? {
34
- success: !1,
35
- error: `Only ${c} available for this SKU.`,
36
- errorKey: "ecommerce.cart_error_stock_limit",
37
- errorParams: { count: c }
38
- } : (e(d ? {
39
- items: t.map(
40
- (u) => u.id === r.id ? {
41
- ...u,
42
- ...r,
43
- quantity: u.quantity + s
44
- } : u
45
- ),
46
- isOpen: !0
47
- } : {
48
- items: [...t, { ...r, quantity: s }],
49
- isOpen: !0
50
- }), { success: !0 });
51
- },
52
- removeItem: (r) => {
53
- const { items: t } = o();
54
- e({
55
- items: t.filter((s) => s.id !== r)
56
- });
57
- },
58
- updateQuantity: (r, t) => {
59
- const { items: s } = o(), c = s.find((i) => i.id === r);
60
- c && n(c) || (c && typeof c.stock == "number" && t + a(s, c.sku, r) > c.stock && (t = Math.max(
61
- c.stock - a(s, c.sku, r),
62
- 0
63
- )), t <= 0 ? e({
64
- items: s.filter((i) => i.id !== r)
65
- }) : e({
66
- items: s.map(
67
- (i) => i.id === r ? { ...i, quantity: t } : i
68
- )
69
- }));
70
- },
71
- setAppliedCoupon: (r) => {
72
- const t = o().appliedCoupon;
73
- t?.code === r?.code && t?.couponId === r?.couponId || e({ appliedCoupon: r });
74
- },
75
- removeCoupon: () => {
76
- o().appliedCoupon && e({ appliedCoupon: null });
77
- },
78
- clearCart: () => e({ items: [], appliedCoupon: null }),
79
- toggleCart: () => e((r) => ({ isOpen: !r.isOpen })),
80
- setIsOpen: (r) => e({ isOpen: r }),
81
- setItems: (r) => e({ items: r })
82
- }),
83
- {
84
- name: "cart-storage",
85
- storage: C(() => localStorage),
86
- skipHydration: !0,
87
- // Persist the cart, not the UI. `isOpen` used to be stored too, so a visitor who left
88
- // with the drawer open got it thrown open again (stealing focus) on the next page load
89
- // and in every new tab.
90
- partialize: (e) => ({ items: e.items, appliedCoupon: e.appliedCoupon })
91
- }
92
- )
93
- ), b = () => p((o) => o.items).reduce((o, r) => o + r.quantity, 0);
94
- function m(e, o) {
95
- return k({
96
- prices: e.prices,
97
- salePrices: e.sale_prices,
98
- fallbackPrice: e.price,
99
- fallbackSalePrice: e.sale_price,
100
- saleStartAt: e.sale_start_at,
101
- saleEndAt: e.sale_end_at,
102
- scheduledPrice: e.scheduled_price,
103
- scheduledPrices: e.scheduled_prices,
104
- scheduledPriceAt: e.scheduled_price_at,
105
- currencyCode: o.currencyCode,
106
- currencies: o.currencies
107
- });
10
+ var s = r()(a((t, n) => ({
11
+ items: [],
12
+ appliedCoupon: null,
13
+ isOpen: !1,
14
+ addItem: (r) => {
15
+ let { items: i } = n(), a = r.quantity ?? 1, s = typeof r.stock == "number" ? r.stock : null, c = s === null ? 0 : o(i, r.sku);
16
+ if (e(r)) return i.find((t) => t.product_id === r.product_id && e(t)) ? {
17
+ success: !1,
18
+ error: "This software license is already in your cart.",
19
+ errorKey: "ecommerce.cart_error_license_in_cart"
20
+ } : (t({
21
+ items: [...i, {
22
+ ...r,
23
+ quantity: 1
24
+ }],
25
+ isOpen: !0
26
+ }), { success: !0 });
27
+ let l = i.find((e) => e.id === r.id);
28
+ return s !== null && s <= 0 ? {
29
+ success: !1,
30
+ error: "This item is out of stock.",
31
+ errorKey: "ecommerce.cart_error_out_of_stock"
32
+ } : s !== null && c + a > s ? {
33
+ success: !1,
34
+ error: `Only ${s} available for this SKU.`,
35
+ errorKey: "ecommerce.cart_error_stock_limit",
36
+ errorParams: { count: s }
37
+ } : (t(l ? {
38
+ items: i.map((e) => e.id === r.id ? {
39
+ ...e,
40
+ ...r,
41
+ quantity: e.quantity + a
42
+ } : e),
43
+ isOpen: !0
44
+ } : {
45
+ items: [...i, {
46
+ ...r,
47
+ quantity: a
48
+ }],
49
+ isOpen: !0
50
+ }), { success: !0 });
51
+ },
52
+ removeItem: (e) => {
53
+ let { items: r } = n();
54
+ t({ items: r.filter((t) => t.id !== e) });
55
+ },
56
+ updateQuantity: (r, i) => {
57
+ let { items: a } = n(), s = a.find((e) => e.id === r);
58
+ s && e(s) || (s && typeof s.stock == "number" && i + o(a, s.sku, r) > s.stock && (i = Math.max(s.stock - o(a, s.sku, r), 0)), t(i <= 0 ? { items: a.filter((e) => e.id !== r) } : { items: a.map((e) => e.id === r ? {
59
+ ...e,
60
+ quantity: i
61
+ } : e) }));
62
+ },
63
+ setAppliedCoupon: (e) => {
64
+ let r = n().appliedCoupon;
65
+ (r?.code !== e?.code || r?.couponId !== e?.couponId) && t({ appliedCoupon: e });
66
+ },
67
+ removeCoupon: () => {
68
+ n().appliedCoupon && t({ appliedCoupon: null });
69
+ },
70
+ clearCart: () => t({
71
+ items: [],
72
+ appliedCoupon: null
73
+ }),
74
+ toggleCart: () => t((e) => ({ isOpen: !e.isOpen })),
75
+ setIsOpen: (e) => t({ isOpen: e }),
76
+ setItems: (e) => t({ items: e })
77
+ }), {
78
+ name: "cart-storage",
79
+ storage: i(() => localStorage),
80
+ skipHydration: !0,
81
+ partialize: (e) => ({
82
+ items: e.items,
83
+ appliedCoupon: e.appliedCoupon
84
+ })
85
+ })), c = () => s((e) => e.items).reduce((e, t) => e + t.quantity, 0);
86
+ function l(e, n) {
87
+ return t({
88
+ prices: e.prices,
89
+ salePrices: e.sale_prices,
90
+ fallbackPrice: e.price,
91
+ fallbackSalePrice: e.sale_price,
92
+ saleStartAt: e.sale_start_at,
93
+ saleEndAt: e.sale_end_at,
94
+ scheduledPrice: e.scheduled_price,
95
+ scheduledPrices: e.scheduled_prices,
96
+ scheduledPriceAt: e.scheduled_price_at,
97
+ currencyCode: n.currencyCode,
98
+ currencies: n.currencies
99
+ });
108
100
  }
109
- const g = () => {
110
- const e = p((t) => t.items), { activeCurrencyCode: o, currencies: r } = _();
111
- return e.reduce((t, s) => {
112
- const { price: c, sale_price: i } = m(s, {
113
- currencyCode: o,
114
- currencies: r
115
- });
116
- return t + (i ?? c) * s.quantity;
117
- }, 0);
118
- };
119
- export {
120
- m as getCartItemActivePrice,
121
- p as useCartStore,
122
- g as useCartSubtotal,
123
- b as useCartTotalItems
101
+ var u = () => {
102
+ let e = s((e) => e.items), { activeCurrencyCode: t, currencies: r } = n();
103
+ return e.reduce((e, n) => {
104
+ let { price: i, sale_price: a } = l(n, {
105
+ currencyCode: t,
106
+ currencies: r
107
+ });
108
+ return e + (a ?? i) * n.quantity;
109
+ }, 0);
124
110
  };
111
+ //#endregion
112
+ export { l as getCartItemActivePrice, s as useCartStore, u as useCartSubtotal, c as useCartTotalItems };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),m=require("next/link"),f=require("next/navigation"),d=require("lucide-react"),o=require("@nextblock-cms/utils");function i(r,t,c){const a=r(t);return a===t?c:a}function g(r){return r==="password"?d.KeyRound:d.Package2}function h({links:r,title:t,className:c}){const a=f.usePathname(),{t:s}=o.useTranslations();return r.length?n.jsxs("nav",{"aria-label":t||i(s,"account_navigation","Account"),className:o.cn("w-full space-y-3",c),children:[n.jsx("div",{"aria-hidden":"true",className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:t||i(s,"account_navigation","Account")}),n.jsx("div",{className:"space-y-2",children:r.map(e=>{const l=g(e.icon),u=a===e.href||a.startsWith(`${e.href}/`);return n.jsxs(m,{href:e.href,"aria-current":u?"page":void 0,className:o.cn("flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors",u?"border-primary bg-primary text-primary-foreground":"border-border bg-background hover:bg-muted/40"),children:[n.jsx(l,{className:"h-4 w-4 shrink-0"}),n.jsx("span",{children:i(s,e.labelKey,e.fallbackLabel)})]},e.href)})})]}):null}exports.AccountNavigationMenu=h;
1
+ "use client";const e=require("../../_virtual/_rolldown/runtime.cjs.js");let t=require("next/link");t=e.__toESM(t,1);let n=require("lucide-react"),r=require("@nextblock-cms/utils"),i=require("react/jsx-runtime"),a=require("next/navigation");function o(e,t,n){let r=e(t);return r===t?n:r}function s(e){return e===`password`?n.KeyRound:n.Package2}function c({links:e,title:n,className:c}){let l=(0,a.usePathname)(),{t:u}=(0,r.useTranslations)();return e.length?(0,i.jsxs)(`nav`,{"aria-label":n||o(u,`account_navigation`,`Account`),className:(0,r.cn)(`w-full space-y-3`,c),children:[(0,i.jsx)(`div`,{"aria-hidden":`true`,className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:n||o(u,`account_navigation`,`Account`)}),(0,i.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>{let n=s(e.icon),a=l===e.href||l.startsWith(`${e.href}/`);return(0,i.jsxs)(t.default,{href:e.href,"aria-current":a?`page`:void 0,className:(0,r.cn)(`flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors`,a?`border-primary bg-primary text-primary-foreground`:`border-border bg-background hover:bg-muted/40`),children:[(0,i.jsx)(n,{className:`h-4 w-4 shrink-0`}),(0,i.jsx)(`span`,{children:o(u,e.labelKey,e.fallbackLabel)})]},e.href)})})]}):null}exports.AccountNavigationMenu=c;
@@ -10,5 +10,5 @@ interface AccountNavigationMenuProps {
10
10
  title?: string;
11
11
  className?: string;
12
12
  }
13
- export declare function AccountNavigationMenu({ links, title, className, }: AccountNavigationMenuProps): import("react").JSX.Element | null;
13
+ export declare function AccountNavigationMenu({ links, title, className, }: AccountNavigationMenuProps): import('react').JSX.Element | null;
14
14
  export {};
@@ -1,53 +1,39 @@
1
- 'use client';
2
- import { jsxs as u, jsx as n } from "react/jsx-runtime";
3
- import l from "next/link";
4
- import { usePathname as f } from "next/navigation";
5
- import { KeyRound as p, Package2 as h } from "lucide-react";
6
- import { useTranslations as g, cn as m } from "@nextblock-cms/utils";
7
- function s(e, a, o) {
8
- const t = e(a);
9
- return t === a ? o : t;
1
+ "use client";
2
+ import e from "next/link";
3
+ import { KeyRound as t, Package2 as n } from "lucide-react";
4
+ import { cn as r, useTranslations as i } from "@nextblock-cms/utils";
5
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
6
+ import { usePathname as s } from "next/navigation";
7
+ //#region libs/ecommerce/src/lib/components/AccountNavigationMenu.tsx
8
+ function c(e, t, n) {
9
+ let r = e(t);
10
+ return r === t ? n : r;
10
11
  }
11
- function b(e) {
12
- return e === "password" ? p : h;
12
+ function l(e) {
13
+ return e === "password" ? t : n;
13
14
  }
14
- function A({
15
- links: e,
16
- title: a,
17
- className: o
18
- }) {
19
- const t = f(), { t: c } = g();
20
- return e.length ? /* @__PURE__ */ u(
21
- "nav",
22
- {
23
- "aria-label": a || s(c, "account_navigation", "Account"),
24
- className: m("w-full space-y-3", o),
25
- children: [
26
- /* @__PURE__ */ n("div", { "aria-hidden": "true", className: "text-sm font-medium text-muted-foreground uppercase tracking-wider", children: a || s(c, "account_navigation", "Account") }),
27
- /* @__PURE__ */ n("div", { className: "space-y-2", children: e.map((r) => {
28
- const d = b(r.icon), i = t === r.href || t.startsWith(`${r.href}/`);
29
- return /* @__PURE__ */ u(
30
- l,
31
- {
32
- href: r.href,
33
- "aria-current": i ? "page" : void 0,
34
- className: m(
35
- "flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors",
36
- // Theme tokens: slate-900 on a dark theme was a dark pill on a dark card.
37
- i ? "border-primary bg-primary text-primary-foreground" : "border-border bg-background hover:bg-muted/40"
38
- ),
39
- children: [
40
- /* @__PURE__ */ n(d, { className: "h-4 w-4 shrink-0" }),
41
- /* @__PURE__ */ n("span", { children: s(c, r.labelKey, r.fallbackLabel) })
42
- ]
43
- },
44
- r.href
45
- );
46
- }) })
47
- ]
48
- }
49
- ) : null;
15
+ function u({ links: t, title: n, className: u }) {
16
+ let d = s(), { t: f } = i();
17
+ return t.length ? /* @__PURE__ */ o("nav", {
18
+ "aria-label": n || c(f, "account_navigation", "Account"),
19
+ className: r("w-full space-y-3", u),
20
+ children: [/* @__PURE__ */ a("div", {
21
+ "aria-hidden": "true",
22
+ className: "text-sm font-medium text-muted-foreground uppercase tracking-wider",
23
+ children: n || c(f, "account_navigation", "Account")
24
+ }), /* @__PURE__ */ a("div", {
25
+ className: "space-y-2",
26
+ children: t.map((t) => {
27
+ let n = l(t.icon), i = d === t.href || d.startsWith(`${t.href}/`);
28
+ return /* @__PURE__ */ o(e, {
29
+ href: t.href,
30
+ "aria-current": i ? "page" : void 0,
31
+ className: r("flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors", i ? "border-primary bg-primary text-primary-foreground" : "border-border bg-background hover:bg-muted/40"),
32
+ children: [/* @__PURE__ */ a(n, { className: "h-4 w-4 shrink-0" }), /* @__PURE__ */ a("span", { children: c(f, t.labelKey, t.fallbackLabel) })]
33
+ }, t.href);
34
+ })
35
+ })]
36
+ }) : null;
50
37
  }
51
- export {
52
- A as AccountNavigationMenu
53
- };
38
+ //#endregion
39
+ export { u as AccountNavigationMenu };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("@nextblock-cms/ui/button"),n=require("lucide-react"),d=require("sonner"),u=require("next/link"),p=require("../use-cart.cjs.js"),q=require("@nextblock-cms/utils"),m=require("../types.cjs.js"),P=require("../CurrencyProvider.cjs.js"),S=require("../PaymentReadinessProvider.cjs.js"),B=({product:e,className:i,quantity:h})=>{const l=p.useCart(t=>t),{t:r}=q.useTranslations(),{activeCurrencyCode:g}=P.useCurrency(),f=S.useCanPurchase(e),_=m.isDigitalProduct(e),y=!!e.has_variants&&!e.variant_id&&!_,v=!_&&typeof e.stock=="number"&&e.stock<=0;if(!f){const t=r("ecommerce.contact_seller");return s.jsx(a.Button,{asChild:!0,variant:"outline",className:i,children:s.jsxs(u,{href:`/product/${e.slug}#contact-seller`,children:[s.jsx(n.Mail,{className:"mr-2 h-4 w-4"}),t==="ecommerce.contact_seller"?"Contact the seller":t]})})}if(y)return s.jsx(a.Button,{asChild:!0,className:i,children:s.jsx(u,{href:`/product/${e.slug}`,children:r("ecommerce.select_options")==="ecommerce.select_options"?"Select options":r("ecommerce.select_options")})});if(v){const t=r("ecommerce.out_of_stock");return s.jsxs(a.Button,{disabled:!0,className:i,children:[s.jsx(n.ShoppingCart,{className:"mr-2 h-4 w-4"}),t==="ecommerce.out_of_stock"?"Out of stock":t]})}if(!l)return s.jsxs(a.Button,{disabled:!0,className:i,children:[s.jsx(n.ShoppingCart,{className:"mr-2 h-4 w-4"}),r("ecommerce.add_to_cart")]});const{addItem:C}=l,b=()=>{const t=m.getProductPaymentProvider(e)??"stripe",{success:x,error:j,errorKey:c,errorParams:k}=C({id:e.variant_id||e.id,product_id:e.id,title:e.title,price:e.price,prices:e.prices,sale_price:e.sale_price,sale_prices:e.sale_prices,sale_start_at:e.sale_start_at,sale_end_at:e.sale_end_at,scheduled_price:e.scheduled_price,scheduled_prices:e.scheduled_prices,scheduled_price_at:e.scheduled_price_at,is_taxable:e.is_taxable,image_url:e.image_url,slug:e.slug,sku:e.sku,stock:e.stock,language_id:e.language_id,translation_group_id:e.translation_group_id,product_type:e.product_type,payment_provider:e.payment_provider??t,provider:t,freemius_product_id:e.freemius_product_id,freemius_plan_id:e.freemius_plan_id,trial_period_days:e.trial_period_days??0,trial_requires_payment_method:e.trial_requires_payment_method??!1,has_variants:e.has_variants,variant_id:e.variant_id,variant_label:e.variant_label,selected_options:e.selected_options,currency_code:g,quantity:h});if(x)d.toast.success(r("ecommerce.added_to_cart_success",{item:e.title}));else{const o=c?r(c,k):null;d.toast.error(o&&o!==c?o:j||r("ecommerce.added_to_cart_error"))}};return s.jsxs(a.Button,{onClick:b,className:i,children:[s.jsx(n.ShoppingCart,{className:"mr-2 h-4 w-4"}),r("ecommerce.add_to_cart")]})};exports.AddToCartButton=B;
1
+ "use client";const e=require("../../_virtual/_rolldown/runtime.cjs.js"),t=require("../types.cjs.js"),n=require("../CurrencyProvider.cjs.js"),r=require("../use-cart.cjs.js"),i=require("../PaymentReadinessProvider.cjs.js");let a=require("@nextblock-cms/ui/button"),o=require("next/link");o=e.__toESM(o,1);let s=require("lucide-react"),c=require("@nextblock-cms/utils"),l=require("react/jsx-runtime"),u=require("sonner");var d=({product:e,className:d,quantity:f})=>{let p=r.useCart(e=>e),{t:m}=(0,c.useTranslations)(),{activeCurrencyCode:h}=n.useCurrency(),g=i.useCanPurchase(e),_=t.isDigitalProduct(e),v=!!e.has_variants&&!e.variant_id&&!_,y=!_&&typeof e.stock==`number`&&e.stock<=0;if(!g){let t=m(`ecommerce.contact_seller`);return(0,l.jsx)(a.Button,{asChild:!0,variant:`outline`,className:d,children:(0,l.jsxs)(o.default,{href:`/product/${e.slug}#contact-seller`,children:[(0,l.jsx)(s.Mail,{className:`mr-2 h-4 w-4`}),t===`ecommerce.contact_seller`?`Contact the seller`:t]})})}if(v)return(0,l.jsx)(a.Button,{asChild:!0,className:d,children:(0,l.jsx)(o.default,{href:`/product/${e.slug}`,children:m(`ecommerce.select_options`)===`ecommerce.select_options`?`Select options`:m(`ecommerce.select_options`)})});if(y){let e=m(`ecommerce.out_of_stock`);return(0,l.jsxs)(a.Button,{disabled:!0,className:d,children:[(0,l.jsx)(s.ShoppingCart,{className:`mr-2 h-4 w-4`}),e===`ecommerce.out_of_stock`?`Out of stock`:e]})}if(!p)return(0,l.jsxs)(a.Button,{disabled:!0,className:d,children:[(0,l.jsx)(s.ShoppingCart,{className:`mr-2 h-4 w-4`}),m(`ecommerce.add_to_cart`)]});let{addItem:b}=p;return(0,l.jsxs)(a.Button,{onClick:()=>{let n=t.getProductPaymentProvider(e)??`stripe`,{success:r,error:i,errorKey:a,errorParams:o}=b({id:e.variant_id||e.id,product_id:e.id,title:e.title,price:e.price,prices:e.prices,sale_price:e.sale_price,sale_prices:e.sale_prices,sale_start_at:e.sale_start_at,sale_end_at:e.sale_end_at,scheduled_price:e.scheduled_price,scheduled_prices:e.scheduled_prices,scheduled_price_at:e.scheduled_price_at,is_taxable:e.is_taxable,image_url:e.image_url,slug:e.slug,sku:e.sku,stock:e.stock,language_id:e.language_id,translation_group_id:e.translation_group_id,product_type:e.product_type,payment_provider:e.payment_provider??n,provider:n,freemius_product_id:e.freemius_product_id,freemius_plan_id:e.freemius_plan_id,trial_period_days:e.trial_period_days??0,trial_requires_payment_method:e.trial_requires_payment_method??!1,has_variants:e.has_variants,variant_id:e.variant_id,variant_label:e.variant_label,selected_options:e.selected_options,currency_code:h,quantity:f});if(r)u.toast.success(m(`ecommerce.added_to_cart_success`,{item:e.title}));else{let e=a?m(a,o):null;u.toast.error(e&&e!==a?e:i||m(`ecommerce.added_to_cart_error`))}},className:d,children:[(0,l.jsx)(s.ShoppingCart,{className:`mr-2 h-4 w-4`}),m(`ecommerce.add_to_cart`)]})};exports.AddToCartButton=d;
@@ -4,5 +4,5 @@ interface AddToCartButtonProps {
4
4
  className?: string;
5
5
  quantity?: number;
6
6
  }
7
- export declare const AddToCartButton: ({ product, className, quantity }: AddToCartButtonProps) => import("react").JSX.Element;
7
+ export declare const AddToCartButton: ({ product, className, quantity }: AddToCartButtonProps) => import('react').JSX.Element;
8
8
  export {};
@@ -1,91 +1,96 @@
1
- 'use client';
2
- import { jsx as s, jsxs as o } from "react/jsx-runtime";
1
+ "use client";
2
+ import { getProductPaymentProvider as e, isDigitalProduct as t } from "../types.es.js";
3
+ import { useCurrency as n } from "../CurrencyProvider.es.js";
4
+ import { useCart as r } from "../use-cart.es.js";
5
+ import { useCanPurchase as i } from "../PaymentReadinessProvider.es.js";
3
6
  import { Button as a } from "@nextblock-cms/ui/button";
4
- import { Mail as P, ShoppingCart as l } from "lucide-react";
5
- import { toast as d } from "sonner";
6
- import h from "next/link";
7
- import { useCart as x } from "../use-cart.es.js";
8
- import { useTranslations as S } from "@nextblock-cms/utils";
9
- import { isDigitalProduct as w, getProductPaymentProvider as O } from "../types.es.js";
10
- import { useCurrency as T } from "../CurrencyProvider.es.js";
11
- import { useCanPurchase as q } from "../PaymentReadinessProvider.es.js";
12
- const z = ({ product: e, className: i, quantity: f }) => {
13
- const c = x((r) => r), { t } = S(), { activeCurrencyCode: u } = T(), p = q(e), m = w(e), g = !!e.has_variants && !e.variant_id && !m, v = !m && typeof e.stock == "number" && e.stock <= 0;
14
- if (!p) {
15
- const r = t("ecommerce.contact_seller");
16
- return /* @__PURE__ */ s(a, { asChild: !0, variant: "outline", className: i, children: /* @__PURE__ */ o(h, { href: `/product/${e.slug}#contact-seller`, children: [
17
- /* @__PURE__ */ s(P, { className: "mr-2 h-4 w-4" }),
18
- r === "ecommerce.contact_seller" ? "Contact the seller" : r
19
- ] }) });
20
- }
21
- if (g)
22
- return /* @__PURE__ */ s(a, { asChild: !0, className: i, children: /* @__PURE__ */ s(h, { href: `/product/${e.slug}`, children: t("ecommerce.select_options") === "ecommerce.select_options" ? "Select options" : t("ecommerce.select_options") }) });
23
- if (v) {
24
- const r = t("ecommerce.out_of_stock");
25
- return /* @__PURE__ */ o(a, { disabled: !0, className: i, children: [
26
- /* @__PURE__ */ s(l, { className: "mr-2 h-4 w-4" }),
27
- r === "ecommerce.out_of_stock" ? "Out of stock" : r
28
- ] });
29
- }
30
- if (!c)
31
- return /* @__PURE__ */ o(a, { disabled: !0, className: i, children: [
32
- /* @__PURE__ */ s(l, { className: "mr-2 h-4 w-4" }),
33
- t("ecommerce.add_to_cart")
34
- ] });
35
- const { addItem: y } = c;
36
- return /* @__PURE__ */ o(a, { onClick: () => {
37
- const r = O(e) ?? "stripe", { success: k, error: C, errorKey: n, errorParams: b } = y({
38
- id: e.variant_id || e.id,
39
- product_id: e.id,
40
- title: e.title,
41
- price: e.price,
42
- prices: e.prices,
43
- sale_price: e.sale_price,
44
- sale_prices: e.sale_prices,
45
- // The sale window and the scheduled price travel with the line. The cart prices a line
46
- // with `resolveEffectivePriceForCurrency`, where a missing window means "always on":
47
- // without these an expired or not-yet-started sale showed the regular price on the
48
- // product page and the sale price in the cart, the drawer and the subtotal.
49
- sale_start_at: e.sale_start_at,
50
- sale_end_at: e.sale_end_at,
51
- scheduled_price: e.scheduled_price,
52
- scheduled_prices: e.scheduled_prices,
53
- scheduled_price_at: e.scheduled_price_at,
54
- is_taxable: e.is_taxable,
55
- image_url: e.image_url,
56
- slug: e.slug,
57
- sku: e.sku,
58
- stock: e.stock,
59
- language_id: e.language_id,
60
- translation_group_id: e.translation_group_id,
61
- product_type: e.product_type,
62
- payment_provider: e.payment_provider ?? r,
63
- provider: r,
64
- freemius_product_id: e.freemius_product_id,
65
- // include just in case it wasn't intercepted
66
- freemius_plan_id: e.freemius_plan_id,
67
- trial_period_days: e.trial_period_days ?? 0,
68
- trial_requires_payment_method: e.trial_requires_payment_method ?? !1,
69
- has_variants: e.has_variants,
70
- variant_id: e.variant_id,
71
- variant_label: e.variant_label,
72
- selected_options: e.selected_options,
73
- currency_code: u,
74
- quantity: f
75
- });
76
- if (k)
77
- d.success(t("ecommerce.added_to_cart_success", { item: e.title }));
78
- else {
79
- const _ = n ? t(n, b) : null;
80
- d.error(
81
- _ && _ !== n ? _ : C || t("ecommerce.added_to_cart_error")
82
- );
83
- }
84
- }, className: i, children: [
85
- /* @__PURE__ */ s(l, { className: "mr-2 h-4 w-4" }),
86
- t("ecommerce.add_to_cart")
87
- ] });
88
- };
89
- export {
90
- z as AddToCartButton
7
+ import o from "next/link";
8
+ import { Mail as s, ShoppingCart as c } from "lucide-react";
9
+ import { useTranslations as l } from "@nextblock-cms/utils";
10
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
11
+ import { toast as f } from "sonner";
12
+ //#region libs/ecommerce/src/lib/components/AddToCartButton.tsx
13
+ var p = ({ product: p, className: m, quantity: h }) => {
14
+ let g = r((e) => e), { t: _ } = l(), { activeCurrencyCode: v } = n(), y = i(p), b = t(p), x = !!p.has_variants && !p.variant_id && !b, S = !b && typeof p.stock == "number" && p.stock <= 0;
15
+ if (!y) {
16
+ let e = _("ecommerce.contact_seller");
17
+ return /* @__PURE__ */ u(a, {
18
+ asChild: !0,
19
+ variant: "outline",
20
+ className: m,
21
+ children: /* @__PURE__ */ d(o, {
22
+ href: `/product/${p.slug}#contact-seller`,
23
+ children: [/* @__PURE__ */ u(s, { className: "mr-2 h-4 w-4" }), e === "ecommerce.contact_seller" ? "Contact the seller" : e]
24
+ })
25
+ });
26
+ }
27
+ if (x) return /* @__PURE__ */ u(a, {
28
+ asChild: !0,
29
+ className: m,
30
+ children: /* @__PURE__ */ u(o, {
31
+ href: `/product/${p.slug}`,
32
+ children: _("ecommerce.select_options") === "ecommerce.select_options" ? "Select options" : _("ecommerce.select_options")
33
+ })
34
+ });
35
+ if (S) {
36
+ let e = _("ecommerce.out_of_stock");
37
+ return /* @__PURE__ */ d(a, {
38
+ disabled: !0,
39
+ className: m,
40
+ children: [/* @__PURE__ */ u(c, { className: "mr-2 h-4 w-4" }), e === "ecommerce.out_of_stock" ? "Out of stock" : e]
41
+ });
42
+ }
43
+ if (!g) return /* @__PURE__ */ d(a, {
44
+ disabled: !0,
45
+ className: m,
46
+ children: [/* @__PURE__ */ u(c, { className: "mr-2 h-4 w-4" }), _("ecommerce.add_to_cart")]
47
+ });
48
+ let { addItem: C } = g;
49
+ return /* @__PURE__ */ d(a, {
50
+ onClick: () => {
51
+ let t = e(p) ?? "stripe", { success: n, error: r, errorKey: i, errorParams: a } = C({
52
+ id: p.variant_id || p.id,
53
+ product_id: p.id,
54
+ title: p.title,
55
+ price: p.price,
56
+ prices: p.prices,
57
+ sale_price: p.sale_price,
58
+ sale_prices: p.sale_prices,
59
+ sale_start_at: p.sale_start_at,
60
+ sale_end_at: p.sale_end_at,
61
+ scheduled_price: p.scheduled_price,
62
+ scheduled_prices: p.scheduled_prices,
63
+ scheduled_price_at: p.scheduled_price_at,
64
+ is_taxable: p.is_taxable,
65
+ image_url: p.image_url,
66
+ slug: p.slug,
67
+ sku: p.sku,
68
+ stock: p.stock,
69
+ language_id: p.language_id,
70
+ translation_group_id: p.translation_group_id,
71
+ product_type: p.product_type,
72
+ payment_provider: p.payment_provider ?? t,
73
+ provider: t,
74
+ freemius_product_id: p.freemius_product_id,
75
+ freemius_plan_id: p.freemius_plan_id,
76
+ trial_period_days: p.trial_period_days ?? 0,
77
+ trial_requires_payment_method: p.trial_requires_payment_method ?? !1,
78
+ has_variants: p.has_variants,
79
+ variant_id: p.variant_id,
80
+ variant_label: p.variant_label,
81
+ selected_options: p.selected_options,
82
+ currency_code: v,
83
+ quantity: h
84
+ });
85
+ if (n) f.success(_("ecommerce.added_to_cart_success", { item: p.title }));
86
+ else {
87
+ let e = i ? _(i, a) : null;
88
+ f.error(e && e !== i ? e : r || _("ecommerce.added_to_cart_error"));
89
+ }
90
+ },
91
+ className: m,
92
+ children: [/* @__PURE__ */ u(c, { className: "mr-2 h-4 w-4" }), _("ecommerce.add_to_cart")]
93
+ });
91
94
  };
95
+ //#endregion
96
+ export { p as AddToCartButton };