@nextblock-cms/ecom 0.8.1 → 0.8.7

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 (241) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +136 -3224
  3. package/lib/CurrencyProvider.cjs.js +1 -0
  4. package/lib/CurrencyProvider.es.js +99 -0
  5. package/lib/cart-store.cjs.js +1 -0
  6. package/lib/cart-store.es.js +116 -0
  7. package/lib/components/AccountNavigationMenu.cjs.js +1 -0
  8. package/lib/components/AccountNavigationMenu.es.js +44 -0
  9. package/lib/components/AddToCartButton.cjs.js +1 -0
  10. package/lib/components/AddToCartButton.es.js +60 -0
  11. package/lib/components/Cart.cjs.js +1 -0
  12. package/lib/components/Cart.es.js +148 -0
  13. package/lib/components/CartDrawer.cjs.js +1 -0
  14. package/lib/components/CartDrawer.es.js +119 -0
  15. package/lib/components/CartIcon.cjs.js +1 -0
  16. package/lib/components/CartIcon.es.js +34 -0
  17. package/lib/components/Checkout.cjs.js +1 -0
  18. package/lib/components/Checkout.es.js +987 -0
  19. package/lib/components/CouponForm.cjs.js +1 -0
  20. package/lib/components/CouponForm.es.js +136 -0
  21. package/lib/components/CurrencySwitcher.cjs.js +1 -0
  22. package/lib/components/CurrencySwitcher.es.js +18 -0
  23. package/lib/components/CustomerProfileForm.cjs.js +1 -0
  24. package/lib/components/CustomerProfileForm.es.js +355 -0
  25. package/lib/components/FeaturedProduct.cjs.js +1 -0
  26. package/lib/components/FeaturedProduct.es.js +72 -0
  27. package/lib/components/InvoiceDocument.cjs.js +1 -0
  28. package/lib/components/InvoiceDocument.es.js +196 -0
  29. package/lib/components/InvoiceViewerShell.cjs.js +29 -0
  30. package/lib/components/InvoiceViewerShell.es.js +100 -0
  31. package/lib/components/ProductCard.cjs.js +1 -0
  32. package/lib/components/ProductCard.es.js +119 -0
  33. package/lib/components/ProductDetailsLayout.cjs.js +1 -0
  34. package/lib/components/ProductDetailsLayout.es.js +361 -0
  35. package/lib/components/ProductGallery.cjs.js +1 -0
  36. package/lib/components/ProductGallery.es.js +41 -0
  37. package/lib/components/ProductGrid.cjs.js +1 -0
  38. package/lib/components/ProductGrid.es.js +19 -0
  39. package/lib/components/ShippingEstimator.cjs.js +1 -0
  40. package/lib/components/ShippingEstimator.es.js +125 -0
  41. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -0
  42. package/lib/components/SimpleTiptapRenderer.es.js +187 -0
  43. package/lib/components/SubscriptionSelector.cjs.js +1 -0
  44. package/lib/components/SubscriptionSelector.es.js +140 -0
  45. package/lib/countries.cjs.js +1 -0
  46. package/lib/countries.es.js +77 -0
  47. package/lib/coupon-server.cjs.js +1 -0
  48. package/lib/coupon-server.es.js +234 -0
  49. package/lib/coupons.cjs.js +1 -0
  50. package/lib/coupons.es.js +17 -0
  51. package/lib/currency-constants.cjs.js +1 -0
  52. package/lib/currency-constants.es.js +4 -0
  53. package/lib/currency-store.cjs.js +1 -0
  54. package/lib/currency-store.es.js +27 -0
  55. package/lib/currency-sync.cjs.js +1 -0
  56. package/lib/currency-sync.es.js +180 -0
  57. package/lib/currency.cjs.js +1 -0
  58. package/lib/currency.es.js +312 -0
  59. package/lib/customer-addresses.cjs.js +1 -0
  60. package/lib/customer-addresses.es.js +116 -0
  61. package/lib/customer-orders.cjs.js +1 -0
  62. package/lib/customer-orders.es.js +45 -0
  63. package/lib/customer.cjs.js +1 -0
  64. package/lib/customer.es.js +58 -0
  65. package/lib/export-helpers.cjs.js +1 -0
  66. package/lib/export-helpers.es.js +56 -0
  67. package/lib/factory.cjs.js +1 -0
  68. package/lib/factory.es.js +8 -0
  69. package/lib/freemius-coupons.cjs.js +1 -0
  70. package/lib/freemius-coupons.es.js +272 -0
  71. package/lib/freemius-order-sync.cjs.js +1 -0
  72. package/lib/freemius-order-sync.es.js +284 -0
  73. package/lib/inventory-settings.cjs.js +1 -0
  74. package/lib/inventory-settings.es.js +86 -0
  75. package/lib/invoice-server.cjs.js +33 -0
  76. package/lib/invoice-server.es.js +141 -0
  77. package/lib/invoice-ui.cjs.js +1 -0
  78. package/lib/invoice-ui.es.js +71 -0
  79. package/lib/invoice.cjs.js +1 -0
  80. package/lib/invoice.es.js +102 -0
  81. package/lib/order-inventory.cjs.js +61 -0
  82. package/lib/order-inventory.es.js +128 -0
  83. package/lib/order-tax-details.cjs.js +1 -0
  84. package/lib/order-tax-details.es.js +164 -0
  85. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
  86. package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
  87. package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
  88. package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
  89. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
  90. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
  91. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
  92. package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
  93. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
  94. package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
  95. package/lib/pages/cms/coupons/actions.cjs.js +1 -0
  96. package/lib/pages/cms/coupons/actions.es.js +128 -0
  97. package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
  98. package/lib/pages/cms/coupons/product-options.es.js +27 -0
  99. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
  100. package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
  101. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
  102. package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
  103. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
  104. package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
  105. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
  106. package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
  107. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
  108. package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
  109. package/lib/pages/cms/orders/actions.cjs.js +7 -0
  110. package/lib/pages/cms/orders/actions.es.js +71 -0
  111. package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
  112. package/lib/pages/cms/orders/export-actions.es.js +27 -0
  113. package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
  114. package/lib/pages/cms/orders/server-actions.es.js +55 -0
  115. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
  116. package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
  117. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
  118. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
  119. package/lib/pages/cms/payments/actions.cjs.js +1 -0
  120. package/lib/pages/cms/payments/actions.es.js +23 -0
  121. package/lib/pages/cms/payments/queries.cjs.js +1 -0
  122. package/lib/pages/cms/payments/queries.es.js +30 -0
  123. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
  124. package/lib/pages/cms/products/ProductsPage.es.js +46 -0
  125. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
  126. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
  127. package/lib/pages/cms/products/actions.cjs.js +44 -0
  128. package/lib/pages/cms/products/actions.es.js +175 -0
  129. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
  130. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
  131. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
  132. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
  133. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
  134. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
  135. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
  136. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
  137. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
  138. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
  139. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
  140. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
  141. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
  142. package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
  143. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
  144. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
  145. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
  146. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
  147. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
  148. package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
  149. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
  150. package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
  151. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
  152. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
  153. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
  154. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
  155. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
  156. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
  157. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
  158. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
  159. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
  160. package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
  161. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
  162. package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
  163. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
  164. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
  165. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
  166. package/lib/pages/cms/products/inventory/actions.es.js +95 -0
  167. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
  168. package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
  169. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
  170. package/lib/pages/cms/products/product-price-sync.es.js +98 -0
  171. package/lib/pages/cms/products/server-actions.cjs.js +1 -0
  172. package/lib/pages/cms/products/server-actions.es.js +193 -0
  173. package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
  174. package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
  175. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
  176. package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
  177. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
  178. package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
  179. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
  180. package/lib/pages/cms/shipping/server-actions.es.js +159 -0
  181. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
  182. package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
  183. package/lib/pages/cms/taxes/actions.cjs.js +1 -0
  184. package/lib/pages/cms/taxes/actions.es.js +57 -0
  185. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
  186. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
  187. package/lib/product-actions.cjs.js +237 -0
  188. package/lib/product-actions.es.js +524 -0
  189. package/lib/product-context.cjs.js +1 -0
  190. package/lib/product-context.es.js +16 -0
  191. package/lib/product-schema.cjs.js +1 -0
  192. package/lib/product-schema.es.js +134 -0
  193. package/lib/providers/freemius.cjs.js +5 -0
  194. package/lib/providers/freemius.es.js +538 -0
  195. package/lib/providers/stripe.cjs.js +1 -0
  196. package/lib/providers/stripe.es.js +473 -0
  197. package/lib/server-actions/coupon-actions.cjs.js +1 -0
  198. package/lib/server-actions/coupon-actions.es.js +23 -0
  199. package/lib/server-actions/customer-actions.cjs.js +1 -0
  200. package/lib/server-actions/customer-actions.es.js +30 -0
  201. package/lib/server-actions/product-actions.cjs.js +1 -0
  202. package/lib/server-actions/product-actions.es.js +16 -0
  203. package/lib/server-actions/shipping-actions.cjs.js +1 -0
  204. package/lib/server-actions/shipping-actions.es.js +27 -0
  205. package/lib/server-actions/tax-actions.cjs.js +1 -0
  206. package/lib/server-actions/tax-actions.es.js +40 -0
  207. package/lib/shared-inventory.cjs.js +15 -0
  208. package/lib/shared-inventory.es.js +171 -0
  209. package/lib/shipping/resolver.cjs.js +7 -0
  210. package/lib/shipping/resolver.es.js +62 -0
  211. package/lib/shipping-rate-currency.cjs.js +1 -0
  212. package/lib/shipping-rate-currency.es.js +72 -0
  213. package/lib/states.cjs.js +1 -0
  214. package/lib/states.es.js +127 -0
  215. package/lib/stripe/checkout.cjs.js +1 -0
  216. package/lib/stripe/checkout.es.js +182 -0
  217. package/lib/stripe/client.cjs.js +1 -0
  218. package/lib/stripe/client.es.js +7 -0
  219. package/lib/stripe/order-sync.cjs.js +1 -0
  220. package/lib/stripe/order-sync.es.js +130 -0
  221. package/lib/stripe/webhooks.cjs.js +1 -0
  222. package/lib/stripe/webhooks.es.js +30 -0
  223. package/lib/tax-calculation.cjs.js +1 -0
  224. package/lib/tax-calculation.es.js +101 -0
  225. package/lib/trials.cjs.js +1 -0
  226. package/lib/trials.es.js +29 -0
  227. package/lib/types.cjs.js +1 -0
  228. package/lib/types.es.js +33 -0
  229. package/lib/use-cart.cjs.js +1 -0
  230. package/lib/use-cart.es.js +44 -0
  231. package/lib/variation-utils.cjs.js +1 -0
  232. package/lib/variation-utils.es.js +246 -0
  233. package/lib/zod-config.cjs.js +1 -0
  234. package/lib/zod-config.es.js +6 -0
  235. package/package.json +10 -5
  236. package/server.cjs.js +1 -110
  237. package/server.es.js +178 -6037
  238. package/invoice-ui-BJZfedDd.cjs +0 -332
  239. package/invoice-ui-GJ1ADAjn.js +0 -5759
  240. /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
  241. /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),n=require("react"),h=require("@nextblock-cms/utils"),f=require("./currency.cjs.js"),v=require("./currency-store.cjs.js"),z=require("./currency-constants.cjs.js"),g=n.createContext(null);function x(o){return f.sortCurrencies(o.filter(r=>r.is_active!==!1))}function M(o){const{currencies:r,storedCurrencyCode:C,hasHydrated:y,initialCurrencyCode:t,locale:l}=o,u=new Set(r.map(a=>h.normalizeCurrencyCode(a.code))),i=f.getDefaultCurrency(r),s=t?h.normalizeCurrencyCode(t):null,e=C?h.normalizeCurrencyCode(C):null;if(y&&e&&u.has(e))return e;if(s&&u.has(s))return s;const d=f.inferCurrencyCodeFromLocale(l,r);return u.has(d)?d:i.code}function p({children:o,initialCurrencies:r,initialCurrencyCode:C,locale:y}){const[t,l]=n.useState(()=>x(r)),u=v.useCurrencyPreferenceStore(c=>c.activeCurrencyCode),i=v.useCurrencyPreferenceStore(c=>c.hasHydrated),s=v.useCurrencyPreferenceStore(c=>c.setActiveCurrencyCode);n.useEffect(()=>{v.useCurrencyPreferenceStore.persist.rehydrate()},[]),n.useEffect(()=>{r.length>0&&l(x(r))},[r]),n.useEffect(()=>{if(r.length>0)return;async function c(){const{fetchActiveCurrenciesFromRest:m}=await Promise.resolve().then(()=>require("./currency-rest-client.cjs.js")),S=await m();S.length>0&&l(x(S.map(P=>f.normalizeCurrencyRecord(P))))}c()},[r.length]);const e=n.useMemo(()=>M({currencies:t,storedCurrencyCode:u,hasHydrated:i,initialCurrencyCode:C,locale:y}),[t,u,i,C,y]);n.useEffect(()=>{e&&u!==e&&s(e)},[e,s,u]),n.useEffect(()=>{!e||typeof document>"u"||(document.cookie=`${z.CURRENCY_COOKIE_NAME}=${e}; Path=/; Max-Age=31536000; SameSite=Lax`)},[e]);const d=n.useMemo(()=>f.getDefaultCurrency(t),[t]),a=n.useMemo(()=>t.find(c=>c.code===e)??d,[t,d,e]),E=n.useMemo(()=>({currencies:t,defaultCurrency:d,activeCurrency:a,activeCurrencyCode:a.code,isHydrated:i,setActiveCurrencyCode:c=>{const m=h.normalizeCurrencyCode(c);t.some(P=>P.code===m)&&s(m)}}),[a,t,d,i,s]);return q.jsx(g.Provider,{value:E,children:o})}function A(){const o=n.useContext(g);if(!o)throw new Error("useCurrency must be used inside a CurrencyProvider");return o}exports.CurrencyProvider=p;exports.useCurrency=A;
@@ -0,0 +1,99 @@
1
+ 'use client';
2
+ import { jsx as w } from "react/jsx-runtime";
3
+ import { createContext as E, useState as z, useEffect as a, useMemo as l, useContext as H } from "react";
4
+ import { normalizeCurrencyCode as h } from "@nextblock-cms/utils";
5
+ import { getDefaultCurrency as S, sortCurrencies as R, normalizeCurrencyRecord as M, inferCurrencyCodeFromLocale as _ } from "./currency.es.js";
6
+ import { useCurrencyPreferenceStore as v } from "./currency-store.es.js";
7
+ import { CURRENCY_COOKIE_NAME as F } from "./currency-constants.es.js";
8
+ const A = E(null);
9
+ function g(n) {
10
+ return R(
11
+ n.filter((r) => r.is_active !== !1)
12
+ );
13
+ }
14
+ function L(n) {
15
+ const { currencies: r, storedCurrencyCode: i, hasHydrated: f, initialCurrencyCode: t, locale: y } = n, c = new Set(
16
+ r.map((C) => h(C.code))
17
+ ), d = S(r), s = t ? h(t) : null, e = i ? h(i) : null;
18
+ if (f && e && c.has(e))
19
+ return e;
20
+ if (s && c.has(s))
21
+ return s;
22
+ const u = _(y, r);
23
+ return c.has(u) ? u : d.code;
24
+ }
25
+ function D({
26
+ children: n,
27
+ initialCurrencies: r,
28
+ initialCurrencyCode: i,
29
+ locale: f
30
+ }) {
31
+ const [t, y] = z(
32
+ () => g(r)
33
+ ), c = v(
34
+ (o) => o.activeCurrencyCode
35
+ ), d = v((o) => o.hasHydrated), s = v(
36
+ (o) => o.setActiveCurrencyCode
37
+ );
38
+ a(() => {
39
+ v.persist.rehydrate();
40
+ }, []), a(() => {
41
+ r.length > 0 && y(g(r));
42
+ }, [r]), a(() => {
43
+ if (r.length > 0)
44
+ return;
45
+ async function o() {
46
+ const { fetchActiveCurrenciesFromRest: m } = await import("./currency-rest-client.es.js"), p = await m();
47
+ p.length > 0 && y(
48
+ g(p.map((x) => M(x)))
49
+ );
50
+ }
51
+ o();
52
+ }, [r.length]);
53
+ const e = l(
54
+ () => L({
55
+ currencies: t,
56
+ storedCurrencyCode: c,
57
+ hasHydrated: d,
58
+ initialCurrencyCode: i,
59
+ locale: f
60
+ }),
61
+ [t, c, d, i, f]
62
+ );
63
+ a(() => {
64
+ e && c !== e && s(e);
65
+ }, [e, s, c]), a(() => {
66
+ !e || typeof document > "u" || (document.cookie = `${F}=${e}; Path=/; Max-Age=31536000; SameSite=Lax`);
67
+ }, [e]);
68
+ const u = l(
69
+ () => S(t),
70
+ [t]
71
+ ), C = l(
72
+ () => t.find((o) => o.code === e) ?? u,
73
+ [t, u, e]
74
+ ), P = l(
75
+ () => ({
76
+ currencies: t,
77
+ defaultCurrency: u,
78
+ activeCurrency: C,
79
+ activeCurrencyCode: C.code,
80
+ isHydrated: d,
81
+ setActiveCurrencyCode: (o) => {
82
+ const m = h(o);
83
+ t.some((x) => x.code === m) && s(m);
84
+ }
85
+ }),
86
+ [C, t, u, d, s]
87
+ );
88
+ return /* @__PURE__ */ w(A.Provider, { value: P, children: n });
89
+ }
90
+ function I() {
91
+ const n = H(A);
92
+ if (!n)
93
+ throw new Error("useCurrency must be used inside a CurrencyProvider");
94
+ return n;
95
+ }
96
+ export {
97
+ D as CurrencyProvider,
98
+ I as useCurrency
99
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("zustand"),p=require("zustand/middleware"),o=require("./types.cjs.js"),k=require("./CurrencyProvider.cjs.js"),_=require("./currency.cjs.js");function a(r,c,e){return r.reduce((t,s)=>o.isDigitalItem(s)||s.sku!==c||e&&s.id===e?t:t+s.quantity,0)}const l=y.create()(p.persist((r,c)=>({items:[],appliedCoupon:null,isOpen:!1,addItem:e=>{const{items:t}=c(),s=e.quantity??1,i=typeof e.stock=="number"?e.stock:null,u=i!==null?a(t,e.sku):0;if(o.isDigitalItem(e))return t.find(d=>d.product_id===e.product_id&&o.isDigitalItem(d))?{success:!1,error:"This software license is already in your cart."}:(r({items:[...t,{...e,quantity:1}],isOpen:!0}),{success:!0});const C=t.find(n=>n.id===e.id);return i!==null&&i<=0?{success:!1,error:"This item is out of stock."}:i!==null&&u+s>i?{success:!1,error:`Only ${i} available for this SKU.`}:(r(C?{items:t.map(n=>n.id===e.id?{...n,...e,quantity:n.quantity+s}:n),isOpen:!0}:{items:[...t,{...e,quantity:s}],isOpen:!0}),{success:!0})},removeItem:e=>{const{items:t}=c();r({items:t.filter(s=>s.id!==e)})},updateQuantity:(e,t)=>{const{items:s}=c(),i=s.find(u=>u.id===e);i&&o.isDigitalItem(i)||(i&&typeof i.stock=="number"&&t+a(s,i.sku,e)>i.stock&&(t=Math.max(i.stock-a(s,i.sku,e),0)),t<=0?r({items:s.filter(u=>u.id!==e)}):r({items:s.map(u=>u.id===e?{...u,quantity:t}:u)}))},setAppliedCoupon:e=>{const t=c().appliedCoupon;t?.code===e?.code&&t?.couponId===e?.couponId||r({appliedCoupon:e})},removeCoupon:()=>{c().appliedCoupon&&r({appliedCoupon:null})},clearCart:()=>r({items:[],appliedCoupon:null}),toggleCart:()=>r(e=>({isOpen:!e.isOpen})),setIsOpen:e=>r({isOpen:e}),setItems:e=>r({items:e})}),{name:"cart-storage",storage:p.createJSONStorage(()=>localStorage),skipHydration:!0})),S=()=>l(c=>c.items).reduce((c,e)=>c+e.quantity,0);function f(r,c){return _.resolveEffectivePriceForCurrency({prices:r.prices,salePrices:r.sale_prices,fallbackPrice:r.price,fallbackSalePrice:r.sale_price,saleStartAt:r.sale_start_at,saleEndAt:r.sale_end_at,scheduledPrice:r.scheduled_price,scheduledPrices:r.scheduled_prices,scheduledPriceAt:r.scheduled_price_at,currencyCode:c.currencyCode,currencies:c.currencies})}const b=()=>{const r=l(t=>t.items),{activeCurrencyCode:c,currencies:e}=k.useCurrency();return r.reduce((t,s)=>{const{price:i,sale_price:u}=f(s,{currencyCode:c,currencies:e});return t+(u??i)*s.quantity},0)};exports.getCartItemActivePrice=f;exports.useCartStore=l;exports.useCartSubtotal=b;exports.useCartTotalItems=S;
@@ -0,0 +1,116 @@
1
+ import { create as f } from "zustand";
2
+ import { persist as C, createJSONStorage as y } from "zustand/middleware";
3
+ import { isDigitalItem as n } from "./types.es.js";
4
+ import { useCurrency as k } from "./CurrencyProvider.es.js";
5
+ import { resolveEffectivePriceForCurrency as _ } from "./currency.es.js";
6
+ function a(r, i, e) {
7
+ return r.reduce((s, t) => n(t) || t.sku !== i || e && t.id === e ? s : s + t.quantity, 0);
8
+ }
9
+ const p = f()(
10
+ C(
11
+ (r, i) => ({
12
+ items: [],
13
+ appliedCoupon: null,
14
+ isOpen: !1,
15
+ addItem: (e) => {
16
+ const { items: s } = i(), t = e.quantity ?? 1, c = typeof e.stock == "number" ? e.stock : null, o = c !== null ? a(s, e.sku) : 0;
17
+ if (n(e))
18
+ return s.find(
19
+ (l) => l.product_id === e.product_id && n(l)
20
+ ) ? {
21
+ success: !1,
22
+ error: "This software license is already in your cart."
23
+ } : (r({
24
+ items: [...s, { ...e, quantity: 1 }],
25
+ isOpen: !0
26
+ }), { success: !0 });
27
+ const d = s.find((u) => u.id === e.id);
28
+ return c !== null && c <= 0 ? {
29
+ success: !1,
30
+ error: "This item is out of stock."
31
+ } : c !== null && o + t > c ? {
32
+ success: !1,
33
+ error: `Only ${c} available for this SKU.`
34
+ } : (r(d ? {
35
+ items: s.map(
36
+ (u) => u.id === e.id ? {
37
+ ...u,
38
+ ...e,
39
+ quantity: u.quantity + t
40
+ } : u
41
+ ),
42
+ isOpen: !0
43
+ } : {
44
+ items: [...s, { ...e, quantity: t }],
45
+ isOpen: !0
46
+ }), { success: !0 });
47
+ },
48
+ removeItem: (e) => {
49
+ const { items: s } = i();
50
+ r({
51
+ items: s.filter((t) => t.id !== e)
52
+ });
53
+ },
54
+ updateQuantity: (e, s) => {
55
+ const { items: t } = i(), c = t.find((o) => o.id === e);
56
+ c && n(c) || (c && typeof c.stock == "number" && s + a(t, c.sku, e) > c.stock && (s = Math.max(
57
+ c.stock - a(t, c.sku, e),
58
+ 0
59
+ )), s <= 0 ? r({
60
+ items: t.filter((o) => o.id !== e)
61
+ }) : r({
62
+ items: t.map(
63
+ (o) => o.id === e ? { ...o, quantity: s } : o
64
+ )
65
+ }));
66
+ },
67
+ setAppliedCoupon: (e) => {
68
+ const s = i().appliedCoupon;
69
+ s?.code === e?.code && s?.couponId === e?.couponId || r({ appliedCoupon: e });
70
+ },
71
+ removeCoupon: () => {
72
+ i().appliedCoupon && r({ appliedCoupon: null });
73
+ },
74
+ clearCart: () => r({ items: [], appliedCoupon: null }),
75
+ toggleCart: () => r((e) => ({ isOpen: !e.isOpen })),
76
+ setIsOpen: (e) => r({ isOpen: e }),
77
+ setItems: (e) => r({ items: e })
78
+ }),
79
+ {
80
+ name: "cart-storage",
81
+ storage: y(() => localStorage),
82
+ skipHydration: !0
83
+ }
84
+ )
85
+ ), b = () => p((i) => i.items).reduce((i, e) => i + e.quantity, 0);
86
+ function S(r, i) {
87
+ return _({
88
+ prices: r.prices,
89
+ salePrices: r.sale_prices,
90
+ fallbackPrice: r.price,
91
+ fallbackSalePrice: r.sale_price,
92
+ saleStartAt: r.sale_start_at,
93
+ saleEndAt: r.sale_end_at,
94
+ scheduledPrice: r.scheduled_price,
95
+ scheduledPrices: r.scheduled_prices,
96
+ scheduledPriceAt: r.scheduled_price_at,
97
+ currencyCode: i.currencyCode,
98
+ currencies: i.currencies
99
+ });
100
+ }
101
+ const g = () => {
102
+ const r = p((s) => s.items), { activeCurrencyCode: i, currencies: e } = k();
103
+ return r.reduce((s, t) => {
104
+ const { price: c, sale_price: o } = S(t, {
105
+ currencyCode: i,
106
+ currencies: e
107
+ });
108
+ return s + (o ?? c) * t.quantity;
109
+ }, 0);
110
+ };
111
+ export {
112
+ S as getCartItemActivePrice,
113
+ p as useCartStore,
114
+ g as useCartSubtotal,
115
+ b as useCartTotalItems
116
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),m=require("next/link"),h=require("next/navigation"),i=require("lucide-react"),c=require("@nextblock-cms/utils");function u(t,s,a){const n=t(s);return n===s?a:n}function f(t){return t==="password"?i.KeyRound:i.Package2}function g({links:t,title:s,className:a}){const n=h.usePathname(),{t:o}=c.useTranslations();return t.length?r.jsxs("div",{className:c.cn("w-full space-y-3",a),children:[r.jsx("div",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:s||u(o,"account_navigation","Account")}),r.jsx("div",{className:"space-y-2",children:t.map(e=>{const l=f(e.icon),d=n===e.href||n.startsWith(`${e.href}/`);return r.jsxs(m,{href:e.href,className:c.cn("flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors",d?"border-slate-900 bg-slate-900 text-white":"border-border bg-background hover:bg-muted/40"),children:[r.jsx(l,{className:"h-4 w-4 shrink-0"}),r.jsx("span",{children:u(o,e.labelKey,e.fallbackLabel)})]},e.href)})})]}):null}exports.AccountNavigationMenu=g;
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+ import { jsxs as c, jsx as a } from "react/jsx-runtime";
3
+ import l from "next/link";
4
+ import { usePathname as f } from "next/navigation";
5
+ import { KeyRound as h, Package2 as p } from "lucide-react";
6
+ import { useTranslations as b, cn as i } from "@nextblock-cms/utils";
7
+ function m(r, n, o) {
8
+ const t = r(n);
9
+ return t === n ? o : t;
10
+ }
11
+ function g(r) {
12
+ return r === "password" ? h : p;
13
+ }
14
+ function A({
15
+ links: r,
16
+ title: n,
17
+ className: o
18
+ }) {
19
+ const t = f(), { t: s } = b();
20
+ return r.length ? /* @__PURE__ */ c("div", { className: i("w-full space-y-3", o), children: [
21
+ /* @__PURE__ */ a("div", { className: "text-sm font-medium text-muted-foreground uppercase tracking-wider", children: n || m(s, "account_navigation", "Account") }),
22
+ /* @__PURE__ */ a("div", { className: "space-y-2", children: r.map((e) => {
23
+ const u = g(e.icon), d = t === e.href || t.startsWith(`${e.href}/`);
24
+ return /* @__PURE__ */ c(
25
+ l,
26
+ {
27
+ href: e.href,
28
+ className: i(
29
+ "flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors",
30
+ d ? "border-slate-900 bg-slate-900 text-white" : "border-border bg-background hover:bg-muted/40"
31
+ ),
32
+ children: [
33
+ /* @__PURE__ */ a(u, { className: "h-4 w-4 shrink-0" }),
34
+ /* @__PURE__ */ a("span", { children: m(s, e.labelKey, e.fallbackLabel) })
35
+ ]
36
+ },
37
+ e.href
38
+ );
39
+ }) })
40
+ ] }) : null;
41
+ }
42
+ export {
43
+ A as AccountNavigationMenu
44
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),a=require("@nextblock-cms/ui/button"),_=require("lucide-react"),l=require("sonner"),v=require("next/link"),y=require("../use-cart.cjs.js"),q=require("@nextblock-cms/utils"),o=require("../types.cjs.js"),C=require("../CurrencyProvider.cjs.js"),b=({product:e,className:s,quantity:c})=>{const n=y.useCart(t=>t),{t:r}=q.useTranslations(),{activeCurrencyCode:d}=C.useCurrency();if(!!e.has_variants&&!e.variant_id&&!o.isDigitalProduct(e))return i.jsx(a.Button,{asChild:!0,className:s,children:i.jsx(v,{href:`/product/${e.slug}`,children:"Select Options"})});if(!n)return i.jsxs(a.Button,{disabled:!0,className:s,children:[i.jsx(_.ShoppingCart,{className:"mr-2 h-4 w-4"}),r("ecommerce.add_to_cart")]});const{addItem:u}=n,m=()=>{const t=o.getProductPaymentProvider(e)??"stripe",{success:g,error:h}=u({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,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:d,quantity:c});g?l.toast.success(r("ecommerce.added_to_cart_success",{item:e.title})):l.toast.error(h||r("ecommerce.added_to_cart_error"))};return i.jsxs(a.Button,{onClick:m,className:s,children:[i.jsx(_.ShoppingCart,{className:"mr-2 h-4 w-4"}),r("ecommerce.add_to_cart")]})};exports.AddToCartButton=b;
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+ import { jsx as a, jsxs as n } from "react/jsx-runtime";
3
+ import { Button as s } from "@nextblock-cms/ui/button";
4
+ import { ShoppingCart as o } from "lucide-react";
5
+ import { toast as l } from "sonner";
6
+ import p from "next/link";
7
+ import { useCart as g } from "../use-cart.es.js";
8
+ import { useTranslations as v } from "@nextblock-cms/utils";
9
+ import { isDigitalProduct as u, getProductPaymentProvider as y } from "../types.es.js";
10
+ import { useCurrency as C } from "../CurrencyProvider.es.js";
11
+ const V = ({ product: e, className: t, quantity: m }) => {
12
+ const _ = g((r) => r), { t: i } = v(), { activeCurrencyCode: d } = C();
13
+ if (!!e.has_variants && !e.variant_id && !u(e))
14
+ return /* @__PURE__ */ a(s, { asChild: !0, className: t, children: /* @__PURE__ */ a(p, { href: `/product/${e.slug}`, children: "Select Options" }) });
15
+ if (!_)
16
+ return /* @__PURE__ */ n(s, { disabled: !0, className: t, children: [
17
+ /* @__PURE__ */ a(o, { className: "mr-2 h-4 w-4" }),
18
+ i("ecommerce.add_to_cart")
19
+ ] });
20
+ const { addItem: c } = _;
21
+ return /* @__PURE__ */ n(s, { onClick: () => {
22
+ const r = y(e) ?? "stripe", { success: f, error: h } = c({
23
+ id: e.variant_id || e.id,
24
+ product_id: e.id,
25
+ title: e.title,
26
+ price: e.price,
27
+ prices: e.prices,
28
+ sale_price: e.sale_price,
29
+ sale_prices: e.sale_prices,
30
+ is_taxable: e.is_taxable,
31
+ image_url: e.image_url,
32
+ slug: e.slug,
33
+ sku: e.sku,
34
+ stock: e.stock,
35
+ language_id: e.language_id,
36
+ translation_group_id: e.translation_group_id,
37
+ product_type: e.product_type,
38
+ payment_provider: e.payment_provider ?? r,
39
+ provider: r,
40
+ freemius_product_id: e.freemius_product_id,
41
+ // include just in case it wasn't intercepted
42
+ freemius_plan_id: e.freemius_plan_id,
43
+ trial_period_days: e.trial_period_days ?? 0,
44
+ trial_requires_payment_method: e.trial_requires_payment_method ?? !1,
45
+ has_variants: e.has_variants,
46
+ variant_id: e.variant_id,
47
+ variant_label: e.variant_label,
48
+ selected_options: e.selected_options,
49
+ currency_code: d,
50
+ quantity: m
51
+ });
52
+ f ? l.success(i("ecommerce.added_to_cart_success", { item: e.title })) : l.error(h || i("ecommerce.added_to_cart_error"));
53
+ }, className: t, children: [
54
+ /* @__PURE__ */ a(o, { className: "mr-2 h-4 w-4" }),
55
+ i("ecommerce.add_to_cart")
56
+ ] });
57
+ };
58
+ export {
59
+ V as AddToCartButton
60
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),C=require("react"),_=require("@nextblock-cms/ui/badge"),n=require("@nextblock-cms/ui/button"),r=require("@nextblock-cms/ui/table"),h=require("lucide-react"),j=require("../cart-store.cjs.js"),q=require("../use-cart.cjs.js"),o=require("../types.cjs.js"),T=require("next/navigation"),d=require("@nextblock-cms/utils"),w=require("./ShippingEstimator.cjs.js"),k=require("../CurrencyProvider.cjs.js"),S=require("../trials.cjs.js"),P=require("./CouponForm.cjs.js"),B=()=>{const g=T.useRouter(),u=q.useCart(s=>s),b=j.useCartSubtotal(),{t}=d.useTranslations(),{activeCurrencyCode:l,currencies:m}=k.useCurrency(),i=u?.items??[],f=C.useMemo(()=>i.reduce((s,a)=>{if(o.isDigitalItem(a))return s;const c=j.getCartItemActivePrice(a,{currencyCode:l,currencies:m});return s+(c.sale_price??c.price)*a.quantity},0),[l,m,i]);if(!u)return null;const{updateQuantity:p,removeItem:N}=u,v=s=>i.reduce((a,c)=>o.isDigitalItem(c)||c.sku!==s?a:a+c.quantity,0),y=()=>{g.push("/checkout")};return i.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 py-12",children:[e.jsx("h2",{className:"text-2xl font-bold",children:t("ecommerce.cart_empty")}),e.jsx("p",{className:"text-muted-foreground",children:t("ecommerce.cart_empty_description")}),e.jsx(n.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:t("ecommerce.continue_shopping")})})]}):e.jsxs("div",{className:"container mx-auto py-12",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:t("ecommerce.shopping_cart")}),e.jsxs("div",{className:"grid gap-12 lg:grid-cols-12 lg:items-start",children:[e.jsx("div",{className:"lg:col-span-8",children:e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(r.Table,{children:[e.jsx(r.TableHeader,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableHead,{children:t("ecommerce.product")}),e.jsx(r.TableHead,{children:t("ecommerce.quantity")}),e.jsx(r.TableHead,{className:"text-right",children:t("ecommerce.price")}),e.jsx(r.TableHead,{className:"text-right",children:t("ecommerce.total")}),e.jsx(r.TableHead,{className:"w-[50px]"})]})}),e.jsx(r.TableBody,{children:i.map(s=>{const a=v(s.sku),c=j.getCartItemActivePrice(s,{currencyCode:l,currencies:m}),x=S.getTrialSummary(s);return e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[s.image_url?e.jsx("div",{className:"h-16 w-16 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-[10px] text-muted-foreground",children:t("ecommerce.no_image")})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.title}),s.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s.variant_label}),o.isDigitalItem(s)&&s.billing_cycle&&e.jsxs("div",{className:"mt-1 text-xs capitalize text-muted-foreground",children:[s.billing_cycle," Subscription"]}),x&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[x.label," - ",x.paymentRequirementLabel]})]})]})}),e.jsx(r.TableCell,{children:o.isDigitalItem(s)?e.jsx(_.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>p(s.id,s.quantity-1),children:e.jsx(h.Minus,{className:"h-4 w-4"})}),e.jsx("span",{className:"w-8 text-center",children:s.quantity}),e.jsx(n.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>p(s.id,s.quantity+1),disabled:typeof s.stock=="number"&&a>=s.stock,children:e.jsx(h.Plus,{className:"h-4 w-4"})})]})}),e.jsx(r.TableCell,{className:"text-right",children:e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-medium",children:d.formatPrice(c.sale_price??c.price,l)}),c.sale_price&&e.jsx("span",{className:"text-xs text-muted-foreground line-through",children:d.formatPrice(c.price,l)})]})}),e.jsx(r.TableCell,{className:"text-right font-medium",children:d.formatPrice((c.sale_price??c.price)*s.quantity,l)}),e.jsx(r.TableCell,{children:e.jsx(n.Button,{variant:"ghost",size:"icon",onClick:()=>N(s.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(h.Trash2,{className:"h-4 w-4"})})})]},s.id)})})]})})}),e.jsx("div",{className:"lg:col-span-4",children:e.jsxs("div",{className:"rounded-lg border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"mb-4 text-lg font-semibold",children:t("ecommerce.order_summary")}),e.jsxs("div",{className:"flex justify-between border-b pb-4",children:[e.jsx("span",{children:t("ecommerce.subtotal")}),e.jsx("span",{className:"font-medium",children:d.formatPrice(b,l)})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("ecommerce.shipping_taxes_calculated")}),i.some(s=>!o.isDigitalItem(s))&&e.jsx(w.ShippingEstimator,{physicalSubtotal:f}),e.jsx(P.CouponForm,{items:i,currencyCode:l,compact:!0}),e.jsx(n.Button,{className:"w-full mt-4",size:"lg",onClick:y,children:t("ecommerce.proceed_to_checkout")})]})]})})]})]})};exports.Cart=B;
@@ -0,0 +1,148 @@
1
+ 'use client';
2
+ import { jsxs as c, jsx as e } from "react/jsx-runtime";
3
+ import { useMemo as k } from "react";
4
+ import { Badge as T } from "@nextblock-cms/ui/badge";
5
+ import { Button as n } from "@nextblock-cms/ui/button";
6
+ import { Table as q, TableHeader as S, TableRow as g, TableHead as o, TableBody as j, TableCell as d } from "@nextblock-cms/ui/table";
7
+ import { Minus as z, Plus as P, Trash2 as B } from "lucide-react";
8
+ import { useCartSubtotal as Q, getCartItemActivePrice as N } from "../cart-store.es.js";
9
+ import { useCart as R } from "../use-cart.es.js";
10
+ import { isDigitalItem as m } from "../types.es.js";
11
+ import { useRouter as A } from "next/navigation";
12
+ import { useTranslations as H, formatPrice as u } from "@nextblock-cms/utils";
13
+ import { ShippingEstimator as L } from "./ShippingEstimator.es.js";
14
+ import { useCurrency as M } from "../CurrencyProvider.es.js";
15
+ import { getTrialSummary as D } from "../trials.es.js";
16
+ import { CouponForm as E } from "./CouponForm.es.js";
17
+ const ce = () => {
18
+ const b = A(), h = R((r) => r), v = Q(), { t } = H(), { activeCurrencyCode: a, currencies: p } = M(), s = h?.items ?? [], y = k(
19
+ () => s.reduce((r, i) => {
20
+ if (m(i))
21
+ return r;
22
+ const l = N(i, {
23
+ currencyCode: a,
24
+ currencies: p
25
+ });
26
+ return r + (l.sale_price ?? l.price) * i.quantity;
27
+ }, 0),
28
+ [a, p, s]
29
+ );
30
+ if (!h) return null;
31
+ const { updateQuantity: x, removeItem: _ } = h, C = (r) => s.reduce((i, l) => m(l) || l.sku !== r ? i : i + l.quantity, 0), w = () => {
32
+ b.push("/checkout");
33
+ };
34
+ return s.length === 0 ? /* @__PURE__ */ c("div", { className: "flex flex-col items-center justify-center space-y-4 py-12", children: [
35
+ /* @__PURE__ */ e("h2", { className: "text-2xl font-bold", children: t("ecommerce.cart_empty") }),
36
+ /* @__PURE__ */ e("p", { className: "text-muted-foreground", children: t("ecommerce.cart_empty_description") }),
37
+ /* @__PURE__ */ e(n, { asChild: !0, children: /* @__PURE__ */ e("a", { href: "/shop", children: t("ecommerce.continue_shopping") }) })
38
+ ] }) : /* @__PURE__ */ c("div", { className: "container mx-auto py-12", children: [
39
+ /* @__PURE__ */ e("h1", { className: "mb-8 text-3xl font-bold", children: t("ecommerce.shopping_cart") }),
40
+ /* @__PURE__ */ c("div", { className: "grid gap-12 lg:grid-cols-12 lg:items-start", children: [
41
+ /* @__PURE__ */ e("div", { className: "lg:col-span-8", children: /* @__PURE__ */ e("div", { className: "rounded-lg border overflow-hidden", children: /* @__PURE__ */ c(q, { children: [
42
+ /* @__PURE__ */ e(S, { children: /* @__PURE__ */ c(g, { children: [
43
+ /* @__PURE__ */ e(o, { children: t("ecommerce.product") }),
44
+ /* @__PURE__ */ e(o, { children: t("ecommerce.quantity") }),
45
+ /* @__PURE__ */ e(o, { className: "text-right", children: t("ecommerce.price") }),
46
+ /* @__PURE__ */ e(o, { className: "text-right", children: t("ecommerce.total") }),
47
+ /* @__PURE__ */ e(o, { className: "w-[50px]" })
48
+ ] }) }),
49
+ /* @__PURE__ */ e(j, { children: s.map((r) => {
50
+ const i = C(r.sku), l = N(r, {
51
+ currencyCode: a,
52
+ currencies: p
53
+ }), f = D(r);
54
+ return /* @__PURE__ */ c(g, { children: [
55
+ /* @__PURE__ */ e(d, { children: /* @__PURE__ */ c("div", { className: "flex items-center gap-4", children: [
56
+ r.image_url ? /* @__PURE__ */ e("div", { className: "h-16 w-16 overflow-hidden rounded border bg-neutral-100", children: /* @__PURE__ */ e(
57
+ "img",
58
+ {
59
+ src: r.image_url,
60
+ alt: r.title,
61
+ className: "h-full w-full object-cover"
62
+ }
63
+ ) }) : /* @__PURE__ */ e("div", { className: "flex h-16 w-16 items-center justify-center rounded bg-secondary", children: /* @__PURE__ */ e("span", { className: "text-[10px] text-muted-foreground", children: t("ecommerce.no_image") }) }),
64
+ /* @__PURE__ */ c("div", { children: [
65
+ /* @__PURE__ */ e("div", { className: "font-medium", children: r.title }),
66
+ r.variant_label && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: r.variant_label }),
67
+ m(r) && r.billing_cycle && /* @__PURE__ */ c("div", { className: "mt-1 text-xs capitalize text-muted-foreground", children: [
68
+ r.billing_cycle,
69
+ " Subscription"
70
+ ] }),
71
+ f && /* @__PURE__ */ c("div", { className: "mt-1 text-xs font-medium text-emerald-700", children: [
72
+ f.label,
73
+ " - ",
74
+ f.paymentRequirementLabel
75
+ ] })
76
+ ] })
77
+ ] }) }),
78
+ /* @__PURE__ */ e(d, { children: m(r) ? /* @__PURE__ */ e(T, { variant: "secondary", className: "font-normal text-xs", children: "1 (License)" }) : /* @__PURE__ */ c("div", { className: "flex items-center gap-2", children: [
79
+ /* @__PURE__ */ e(
80
+ n,
81
+ {
82
+ variant: "outline",
83
+ size: "icon",
84
+ className: "h-8 w-8",
85
+ onClick: () => x(r.id, r.quantity - 1),
86
+ children: /* @__PURE__ */ e(z, { className: "h-4 w-4" })
87
+ }
88
+ ),
89
+ /* @__PURE__ */ e("span", { className: "w-8 text-center", children: r.quantity }),
90
+ /* @__PURE__ */ e(
91
+ n,
92
+ {
93
+ variant: "outline",
94
+ size: "icon",
95
+ className: "h-8 w-8",
96
+ onClick: () => x(r.id, r.quantity + 1),
97
+ disabled: typeof r.stock == "number" && i >= r.stock,
98
+ children: /* @__PURE__ */ e(P, { className: "h-4 w-4" })
99
+ }
100
+ )
101
+ ] }) }),
102
+ /* @__PURE__ */ e(d, { className: "text-right", children: /* @__PURE__ */ c("div", { className: "flex flex-col items-end", children: [
103
+ /* @__PURE__ */ e("span", { className: "font-medium", children: u(l.sale_price ?? l.price, a) }),
104
+ l.sale_price && /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground line-through", children: u(l.price, a) })
105
+ ] }) }),
106
+ /* @__PURE__ */ e(d, { className: "text-right font-medium", children: u(
107
+ (l.sale_price ?? l.price) * r.quantity,
108
+ a
109
+ ) }),
110
+ /* @__PURE__ */ e(d, { children: /* @__PURE__ */ e(
111
+ n,
112
+ {
113
+ variant: "ghost",
114
+ size: "icon",
115
+ onClick: () => _(r.id),
116
+ className: "text-muted-foreground hover:text-destructive",
117
+ children: /* @__PURE__ */ e(B, { className: "h-4 w-4" })
118
+ }
119
+ ) })
120
+ ] }, r.id);
121
+ }) })
122
+ ] }) }) }),
123
+ /* @__PURE__ */ e("div", { className: "lg:col-span-4", children: /* @__PURE__ */ c("div", { className: "rounded-lg border bg-card p-6 shadow-sm", children: [
124
+ /* @__PURE__ */ e("h2", { className: "mb-4 text-lg font-semibold", children: t("ecommerce.order_summary") }),
125
+ /* @__PURE__ */ c("div", { className: "flex justify-between border-b pb-4", children: [
126
+ /* @__PURE__ */ e("span", { children: t("ecommerce.subtotal") }),
127
+ /* @__PURE__ */ e("span", { className: "font-medium", children: u(v, a) })
128
+ ] }),
129
+ /* @__PURE__ */ c("div", { className: "mt-4 flex flex-col gap-4", children: [
130
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: t("ecommerce.shipping_taxes_calculated") }),
131
+ s.some((r) => !m(r)) && /* @__PURE__ */ e(L, { physicalSubtotal: y }),
132
+ /* @__PURE__ */ e(
133
+ E,
134
+ {
135
+ items: s,
136
+ currencyCode: a,
137
+ compact: !0
138
+ }
139
+ ),
140
+ /* @__PURE__ */ e(n, { className: "w-full mt-4", size: "lg", onClick: w, children: t("ecommerce.proceed_to_checkout") })
141
+ ] })
142
+ ] }) })
143
+ ] })
144
+ ] });
145
+ };
146
+ export {
147
+ ce as Cart
148
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("@nextblock-cms/ui/sheet"),_=require("@nextblock-cms/ui/badge"),d=require("@nextblock-cms/ui/button"),q=require("next/navigation"),m=require("lucide-react"),j=require("../cart-store.cjs.js"),k=require("../use-cart.cjs.js"),o=require("@nextblock-cms/utils"),p=require("../types.cjs.js"),S=require("../CurrencyProvider.cjs.js"),P=require("../trials.cjs.js"),D=require("./CouponForm.cjs.js"),T=()=>{const x=q.useRouter(),h=k.useCart(t=>t),b=j.useCartSubtotal(),{t:s}=o.useTranslations(),{activeCurrencyCode:c,currencies:g}=S.useCurrency();if(!h)return null;const{isOpen:y,setIsOpen:a,items:n,updateQuantity:f,removeItem:v}=h,N=t=>n.reduce((i,r)=>p.isDigitalItem(r)||r.sku!==t?i:i+r.quantity,0),w=()=>{a(!1),x.push("/cart")},C=()=>{a(!1),x.push("/checkout")};return e.jsx(l.Sheet,{open:y,onOpenChange:a,children:e.jsxs(l.SheetContent,{className:"flex w-full flex-col pr-0 sm:max-w-lg",children:[e.jsxs(l.SheetHeader,{className:"px-1 text-left",children:[e.jsxs(l.SheetTitle,{children:[s("ecommerce.shopping_cart")," (",n.length,")"]}),e.jsx(l.SheetDescription,{className:"sr-only",children:s("ecommerce.shopping_cart")})]}),n.length>0?e.jsx("div",{className:"flex flex-1 flex-col gap-5 overflow-y-auto p-1 pr-6 pt-4",children:n.map(t=>{const i=N(t.sku);return e.jsx("div",{className:"flex gap-4",children:(()=>{const r=j.getCartItemActivePrice(t,{currencyCode:c,currencies:g}),u=P.getTrialSummary(t);return e.jsxs(e.Fragment,{children:[t.image_url?e.jsx("div",{className:"relative aspect-square h-20 w-20 min-w-fit overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:t.image_url,alt:t.title,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:s("ecommerce.no_image")})}),e.jsxs("div",{className:"flex flex-1 flex-col justify-between",children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"line-clamp-2 text-sm font-medium leading-tight",children:t.title}),t.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:t.variant_label}),u&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[u.label," - ",u.paymentRequirementLabel]})]}),e.jsxs("span",{className:"text-sm font-semibold",children:[r.sale_price&&e.jsx("span",{className:"mr-1.5 text-xs font-normal text-muted-foreground line-through",children:o.formatPrice(r.price,c)}),o.formatPrice(r.sale_price??r.price,c)]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[p.isDigitalItem(t)?e.jsx(_.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center rounded-md border text-xs",children:[e.jsx("button",{onClick:()=>f(t.id,t.quantity-1),className:"flex h-7 w-7 items-center justify-center border-r",type:"button",children:e.jsx(m.Minus,{className:"h-3 w-3"})}),e.jsx("span",{className:"flex h-7 w-8 items-center justify-center",children:t.quantity}),e.jsx("button",{onClick:()=>f(t.id,t.quantity+1),className:"flex h-7 w-7 items-center justify-center border-l",type:"button",disabled:typeof t.stock=="number"&&i>=t.stock,children:e.jsx(m.Plus,{className:"h-3 w-3"})})]}),e.jsx("button",{onClick:()=>v(t.id),className:"text-muted-foreground hover:text-destructive",type:"button",children:e.jsx(m.Trash2,{className:"h-4 w-4"})})]})]})]})})()},t.id)})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center space-y-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s("ecommerce.cart_empty")}),e.jsx(d.Button,{variant:"outline",onClick:()=>a(!1),children:s("ecommerce.continue_shopping")})]}),n.length>0&&e.jsxs("div",{className:"border-t pr-6 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-base font-medium",children:[e.jsx("span",{children:s("ecommerce.subtotal")}),e.jsx("span",{children:o.formatPrice(b,c)})]}),e.jsx("p",{className:"mb-4 mt-1 text-xs text-muted-foreground",children:s("ecommerce.shipping_taxes_calculated")}),e.jsx("div",{className:"mb-4",children:e.jsx(D.CouponForm,{items:n,currencyCode:c,compact:!0})}),e.jsx(d.Button,{variant:"outline",className:"w-full mb-3",onClick:w,children:s("ecommerce.view_full_cart")}),e.jsx(d.Button,{className:"w-full",onClick:C,children:s("ecommerce.ready_to_checkout")})]})]})})};exports.CartDrawer=T;
@@ -0,0 +1,119 @@
1
+ 'use client';
2
+ import { jsx as e, jsxs as r, Fragment as C } from "react/jsx-runtime";
3
+ import { Sheet as _, SheetContent as k, SheetHeader as j, SheetTitle as S, SheetDescription as q } from "@nextblock-cms/ui/sheet";
4
+ import { Badge as P } from "@nextblock-cms/ui/badge";
5
+ import { Button as m } from "@nextblock-cms/ui/button";
6
+ import { useRouter as T } from "next/navigation";
7
+ import { Minus as D, Plus as O, Trash2 as Q } from "lucide-react";
8
+ import { useCartSubtotal as A, getCartItemActivePrice as B } from "../cart-store.es.js";
9
+ import { useCart as F } from "../use-cart.es.js";
10
+ import { useTranslations as I, formatPrice as d } from "@nextblock-cms/utils";
11
+ import { isDigitalItem as p } from "../types.es.js";
12
+ import { useCurrency as L } from "../CurrencyProvider.es.js";
13
+ import { getTrialSummary as R } from "../trials.es.js";
14
+ import { CouponForm as H } from "./CouponForm.es.js";
15
+ const ee = () => {
16
+ const u = T(), h = F((t) => t), x = A(), { t: l } = I(), { activeCurrencyCode: s, currencies: y } = L();
17
+ if (!h) return null;
18
+ const { isOpen: N, setIsOpen: a, items: n, updateQuantity: f, removeItem: g } = h, b = (t) => n.reduce((i, c) => p(c) || c.sku !== t ? i : i + c.quantity, 0), v = () => {
19
+ a(!1), u.push("/cart");
20
+ }, w = () => {
21
+ a(!1), u.push("/checkout");
22
+ };
23
+ return /* @__PURE__ */ e(_, { open: N, onOpenChange: a, children: /* @__PURE__ */ r(k, { className: "flex w-full flex-col pr-0 sm:max-w-lg", children: [
24
+ /* @__PURE__ */ r(j, { className: "px-1 text-left", children: [
25
+ /* @__PURE__ */ r(S, { children: [
26
+ l("ecommerce.shopping_cart"),
27
+ " (",
28
+ n.length,
29
+ ")"
30
+ ] }),
31
+ /* @__PURE__ */ e(q, { className: "sr-only", children: l("ecommerce.shopping_cart") })
32
+ ] }),
33
+ n.length > 0 ? /* @__PURE__ */ e("div", { className: "flex flex-1 flex-col gap-5 overflow-y-auto p-1 pr-6 pt-4", children: n.map((t) => {
34
+ const i = b(t.sku);
35
+ return /* @__PURE__ */ e("div", { className: "flex gap-4", children: (() => {
36
+ const c = B(t, {
37
+ currencyCode: s,
38
+ currencies: y
39
+ }), o = R(t);
40
+ return /* @__PURE__ */ r(C, { children: [
41
+ t.image_url ? /* @__PURE__ */ e("div", { className: "relative aspect-square h-20 w-20 min-w-fit overflow-hidden rounded border bg-neutral-100", children: /* @__PURE__ */ e(
42
+ "img",
43
+ {
44
+ src: t.image_url,
45
+ alt: t.title,
46
+ className: "h-full w-full object-cover"
47
+ }
48
+ ) }) : /* @__PURE__ */ e("div", { className: "flex h-20 w-20 items-center justify-center rounded bg-secondary", children: /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground", children: l("ecommerce.no_image") }) }),
49
+ /* @__PURE__ */ r("div", { className: "flex flex-1 flex-col justify-between", children: [
50
+ /* @__PURE__ */ r("div", { className: "flex justify-between gap-2", children: [
51
+ /* @__PURE__ */ r("div", { children: [
52
+ /* @__PURE__ */ e("span", { className: "line-clamp-2 text-sm font-medium leading-tight", children: t.title }),
53
+ t.variant_label && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: t.variant_label }),
54
+ o && /* @__PURE__ */ r("div", { className: "mt-1 text-xs font-medium text-emerald-700", children: [
55
+ o.label,
56
+ " - ",
57
+ o.paymentRequirementLabel
58
+ ] })
59
+ ] }),
60
+ /* @__PURE__ */ r("span", { className: "text-sm font-semibold", children: [
61
+ c.sale_price && /* @__PURE__ */ e("span", { className: "mr-1.5 text-xs font-normal text-muted-foreground line-through", children: d(c.price, s) }),
62
+ d(c.sale_price ?? c.price, s)
63
+ ] })
64
+ ] }),
65
+ /* @__PURE__ */ r("div", { className: "flex items-center justify-between text-sm", children: [
66
+ p(t) ? /* @__PURE__ */ e(P, { variant: "secondary", className: "font-normal text-xs", children: "1 (License)" }) : /* @__PURE__ */ r("div", { className: "flex items-center rounded-md border text-xs", children: [
67
+ /* @__PURE__ */ e(
68
+ "button",
69
+ {
70
+ onClick: () => f(t.id, t.quantity - 1),
71
+ className: "flex h-7 w-7 items-center justify-center border-r",
72
+ type: "button",
73
+ children: /* @__PURE__ */ e(D, { className: "h-3 w-3" })
74
+ }
75
+ ),
76
+ /* @__PURE__ */ e("span", { className: "flex h-7 w-8 items-center justify-center", children: t.quantity }),
77
+ /* @__PURE__ */ e(
78
+ "button",
79
+ {
80
+ onClick: () => f(t.id, t.quantity + 1),
81
+ className: "flex h-7 w-7 items-center justify-center border-l",
82
+ type: "button",
83
+ disabled: typeof t.stock == "number" && i >= t.stock,
84
+ children: /* @__PURE__ */ e(O, { className: "h-3 w-3" })
85
+ }
86
+ )
87
+ ] }),
88
+ /* @__PURE__ */ e(
89
+ "button",
90
+ {
91
+ onClick: () => g(t.id),
92
+ className: "text-muted-foreground hover:text-destructive",
93
+ type: "button",
94
+ children: /* @__PURE__ */ e(Q, { className: "h-4 w-4" })
95
+ }
96
+ )
97
+ ] })
98
+ ] })
99
+ ] });
100
+ })() }, t.id);
101
+ }) }) : /* @__PURE__ */ r("div", { className: "flex h-full flex-col items-center justify-center space-y-2", children: [
102
+ /* @__PURE__ */ e("span", { className: "text-muted-foreground", children: l("ecommerce.cart_empty") }),
103
+ /* @__PURE__ */ e(m, { variant: "outline", onClick: () => a(!1), children: l("ecommerce.continue_shopping") })
104
+ ] }),
105
+ n.length > 0 && /* @__PURE__ */ r("div", { className: "border-t pr-6 pt-4", children: [
106
+ /* @__PURE__ */ r("div", { className: "flex items-center justify-between text-base font-medium", children: [
107
+ /* @__PURE__ */ e("span", { children: l("ecommerce.subtotal") }),
108
+ /* @__PURE__ */ e("span", { children: d(x, s) })
109
+ ] }),
110
+ /* @__PURE__ */ e("p", { className: "mb-4 mt-1 text-xs text-muted-foreground", children: l("ecommerce.shipping_taxes_calculated") }),
111
+ /* @__PURE__ */ e("div", { className: "mb-4", children: /* @__PURE__ */ e(H, { items: n, currencyCode: s, compact: !0 }) }),
112
+ /* @__PURE__ */ e(m, { variant: "outline", className: "w-full mb-3", onClick: v, children: l("ecommerce.view_full_cart") }),
113
+ /* @__PURE__ */ e(m, { className: "w-full", onClick: w, children: l("ecommerce.ready_to_checkout") })
114
+ ] })
115
+ ] }) });
116
+ };
117
+ export {
118
+ ee as CartDrawer
119
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("@nextblock-cms/ui/badge"),a=require("@nextblock-cms/ui/button"),s=require("lucide-react"),i=require("../cart-store.cjs.js"),c=require("../use-cart.cjs.js"),l=()=>{const n=i.useCartStore(t=>t.toggleCart),r=i.useCartTotalItems();return c.useCart(t=>t.isOpen)!==void 0?e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"relative",onClick:n,"aria-label":"Open cart",children:[e.jsx(s.ShoppingBag,{className:"h-5 w-5"}),r>0&&e.jsx(o.Badge,{variant:"destructive",className:"absolute -right-1 -top-1 h-4 w-4 items-center justify-center p-0 text-[10px]",children:r})]}):e.jsx(a.Button,{variant:"ghost",size:"icon",className:"relative","aria-label":"Open cart",children:e.jsx(s.ShoppingBag,{className:"h-5 w-5"})})};exports.CartIcon=l;