@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,175 +1,134 @@
1
- 'use server';
2
- import { createClient as o, getServiceRoleSupabaseClient as d } from "@nextblock-cms/db/server";
3
- import { getProduct as l, getProducts as _, copyProductFromLanguage as m } from "../../../product-actions.es.js";
4
- import { syncSingleFreemiusProduct as p, syncFreemiusProductsToSupabase as g } from "../../../providers/freemius.es.js";
5
- import { revalidatePath as c } from "next/cache";
6
- async function v(r) {
7
- const t = o(), { data: a, count: e, error: s } = await await _(t, { ...r, status: "all" });
8
- if (s) throw new Error(s.message);
9
- return { data: a, count: e };
1
+ "use server";
2
+ import { copyProductFromLanguage as e, getProduct as t, getProducts as n } from "../../../product-actions.es.js";
3
+ import { syncFreemiusProductsToSupabase as r, syncSingleFreemiusProduct as i } from "../../../providers/freemius.es.js";
4
+ import { createClient as a, getServiceRoleSupabaseClient as o } from "@nextblock-cms/db/server";
5
+ import { revalidatePath as s } from "next/cache";
6
+ //#region libs/ecommerce/src/lib/pages/cms/products/actions.ts
7
+ async function c(e) {
8
+ let t = a(), { data: r, count: i, error: o } = await await n(t, {
9
+ ...e,
10
+ status: "all"
11
+ });
12
+ if (o) throw Error(o.message);
13
+ return {
14
+ data: r,
15
+ count: i
16
+ };
10
17
  }
11
- async function P(r) {
12
- const t = o(), { data: a, error: e } = await l(t, r);
13
- if (e) throw new Error(e.message);
14
- return a;
18
+ async function l(e) {
19
+ let n = a(), { data: r, error: i } = await t(n, e);
20
+ if (i) throw Error(i.message);
21
+ return r;
15
22
  }
16
- async function E() {
17
- try {
18
- const r = await g();
19
- return c("/cms/products", "page"), { success: !0, data: r };
20
- } catch (r) {
21
- return { error: r.message || "Failed to sync with Freemius" };
22
- }
23
+ async function u() {
24
+ try {
25
+ let e = await r();
26
+ return s("/cms/products", "page"), {
27
+ success: !0,
28
+ data: e
29
+ };
30
+ } catch (e) {
31
+ return { error: e.message || "Failed to sync with Freemius" };
32
+ }
23
33
  }
24
- async function F(r) {
25
- try {
26
- const t = await p(r);
27
- return c("/cms/products", "page"), c("/cms/products/[id]/edit", "page"), { success: !0, data: t };
28
- } catch (t) {
29
- return { error: t.message || "Failed to sync product with Freemius" };
30
- }
34
+ async function d(e) {
35
+ try {
36
+ let t = await i(e);
37
+ return s("/cms/products", "page"), s("/cms/products/[id]/edit", "page"), {
38
+ success: !0,
39
+ data: t
40
+ };
41
+ } catch (e) {
42
+ return { error: e.message || "Failed to sync product with Freemius" };
43
+ }
31
44
  }
32
- async function S(r, t) {
33
- try {
34
- const a = o();
35
- return await m(a, r, t), c("/cms/products"), c(`/cms/products/${r}/edit`), { success: !0 };
36
- } catch (a) {
37
- return { success: !1, error: a.message || "Failed to copy product content" };
38
- }
45
+ async function f(t, n) {
46
+ try {
47
+ let r = a();
48
+ return await e(r, t, n), s("/cms/products"), s(`/cms/products/${t}/edit`), { success: !0 };
49
+ } catch (e) {
50
+ return {
51
+ success: !1,
52
+ error: e.message || "Failed to copy product content"
53
+ };
54
+ }
39
55
  }
40
- async function q(r) {
41
- const t = o(), { data: a, error: e } = await t.from("products").select("id, title, language_id, slug").eq("translation_group_id", r);
42
- if (e) throw new Error(e.message);
43
- return a;
56
+ async function p(e) {
57
+ let { data: t, error: n } = await a().from("products").select("id, title, language_id, slug").eq("translation_group_id", e);
58
+ if (n) throw Error(n.message);
59
+ return t;
44
60
  }
45
- async function C() {
46
- const r = d(), { data: t, error: a } = await r.from("product_attributes").select(`
47
- id,
48
- name,
49
- name_translations,
50
- slug,
51
- product_attribute_terms (
52
- id,
53
- attribute_id,
54
- value,
55
- slug,
56
- sort_order,
57
- value_translations
58
- )
59
- `);
60
- if (a)
61
- throw new Error(a.message);
62
- return (t || []).map((e) => ({
63
- ...e,
64
- product_attribute_terms: (e.product_attribute_terms || []).sort(
65
- (s, u) => (s.sort_order ?? Number.MAX_SAFE_INTEGER) - (u.sort_order ?? Number.MAX_SAFE_INTEGER) || s.value.localeCompare(u.value)
66
- )
67
- })).sort((e, s) => e.name.localeCompare(s.name));
61
+ async function m() {
62
+ let { data: e, error: t } = await o().from("product_attributes").select("\n id,\n name,\n name_translations,\n slug,\n product_attribute_terms (\n id,\n attribute_id,\n value,\n slug,\n sort_order,\n value_translations\n )\n ");
63
+ if (t) throw Error(t.message);
64
+ return (e || []).map((e) => ({
65
+ ...e,
66
+ product_attribute_terms: (e.product_attribute_terms || []).sort((e, t) => (e.sort_order ?? 2 ** 53 - 1) - (t.sort_order ?? 2 ** 53 - 1) || e.value.localeCompare(t.value))
67
+ })).sort((e, t) => e.name.localeCompare(t.name));
68
68
  }
69
- async function A(r) {
70
- const t = o(), { data: a, error: e } = await t.from("freemius_plans").select(`
71
- id,
72
- name,
73
- title,
74
- freemius_pricing (
75
- id,
76
- license_quota,
77
- api_monthly_price,
78
- api_annual_price,
79
- api_lifetime_price,
80
- override_monthly_price,
81
- override_annual_price,
82
- override_lifetime_price,
83
- is_active
84
- )
85
- `).eq("product_id", r);
86
- if (e) throw new Error(e.message);
87
- return a;
69
+ async function h(e) {
70
+ let { data: t, error: n } = await a().from("freemius_plans").select("\n id,\n name,\n title,\n freemius_pricing (\n id,\n license_quota,\n api_monthly_price,\n api_annual_price,\n api_lifetime_price,\n override_monthly_price,\n override_annual_price,\n override_lifetime_price,\n is_active\n )\n ").eq("product_id", e);
71
+ if (n) throw Error(n.message);
72
+ return t;
88
73
  }
89
- async function N(r, t) {
90
- const a = o(), { error: e } = await a.from("freemius_pricing").update({
91
- ...t,
92
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
93
- }).eq("id", r);
94
- return e ? { success: !1, error: e.message } : (c("/cms/products"), { success: !0 });
74
+ async function g(e, t) {
75
+ let { error: n } = await a().from("freemius_pricing").update({
76
+ ...t,
77
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
78
+ }).eq("id", e);
79
+ return n ? {
80
+ success: !1,
81
+ error: n.message
82
+ } : (s("/cms/products"), { success: !0 });
95
83
  }
96
- async function T(r) {
97
- const t = o(), { data: a } = await t.from("products").select("translation_group_id").eq("id", r).maybeSingle();
98
- let e = [r];
99
- if (a?.translation_group_id) {
100
- const { data: n } = await t.from("products").select("id").eq("translation_group_id", a.translation_group_id);
101
- n && n.length > 0 && (e = n.map((i) => i.id));
102
- }
103
- const { data: s, error: u } = await t.from("freemius_plans").select(`
104
- id,
105
- name,
106
- title,
107
- freemius_pricing (
108
- id,
109
- license_quota,
110
- api_monthly_price,
111
- api_annual_price,
112
- api_lifetime_price,
113
- override_monthly_price,
114
- override_annual_price,
115
- override_lifetime_price,
116
- is_active
117
- )
118
- `).in("product_id", e);
119
- if (u) throw new Error(u.message);
120
- return (s || []).map((n) => ({
121
- id: n.id,
122
- name: n.name,
123
- title: n.title,
124
- pricing: (n.freemius_pricing || []).filter((i) => i.is_active !== !1).map((i) => ({
125
- id: i.id,
126
- license_quota: i.license_quota,
127
- monthly_price: i.override_monthly_price ?? i.api_monthly_price,
128
- annual_price: i.override_annual_price ?? i.api_annual_price,
129
- lifetime_price: i.override_lifetime_price ?? i.api_lifetime_price,
130
- is_active: i.is_active
131
- }))
132
- }));
84
+ async function _(e) {
85
+ let t = a(), { data: n } = await t.from("products").select("translation_group_id").eq("id", e).maybeSingle(), r = [e];
86
+ if (n?.translation_group_id) {
87
+ let { data: e } = await t.from("products").select("id").eq("translation_group_id", n.translation_group_id);
88
+ e && e.length > 0 && (r = e.map((e) => e.id));
89
+ }
90
+ let { data: i, error: o } = await t.from("freemius_plans").select("\n id,\n name,\n title,\n freemius_pricing (\n id,\n license_quota,\n api_monthly_price,\n api_annual_price,\n api_lifetime_price,\n override_monthly_price,\n override_annual_price,\n override_lifetime_price,\n is_active\n )\n ").in("product_id", r);
91
+ if (o) throw Error(o.message);
92
+ return (i || []).map((e) => ({
93
+ id: e.id,
94
+ name: e.name,
95
+ title: e.title,
96
+ pricing: (e.freemius_pricing || []).filter((e) => e.is_active !== !1).map((e) => ({
97
+ id: e.id,
98
+ license_quota: e.license_quota,
99
+ monthly_price: e.override_monthly_price ?? e.api_monthly_price,
100
+ annual_price: e.override_annual_price ?? e.api_annual_price,
101
+ lifetime_price: e.override_lifetime_price ?? e.api_lifetime_price,
102
+ is_active: e.is_active
103
+ }))
104
+ }));
133
105
  }
134
- async function B() {
135
- const r = o(), { data: t, error: a } = await r.from("categories").select("id, name, slug, description, created_at, name_translations, description_translations, product_categories(count)").order("name", { ascending: !0 });
136
- if (a) throw new Error(a.message);
137
- return (t || []).map((e) => {
138
- const s = e.product_categories?.[0]?.count ?? e.product_categories?.count ?? 0;
139
- return {
140
- id: e.id,
141
- name: e.name,
142
- slug: e.slug,
143
- description: e.description ?? "",
144
- created_at: e.created_at,
145
- productCount: Number(s),
146
- name_translations: e.name_translations || {},
147
- description_translations: e.description_translations || {}
148
- };
149
- });
106
+ async function v() {
107
+ let { data: e, error: t } = await a().from("categories").select("id, name, slug, description, created_at, name_translations, description_translations, product_categories(count)").order("name", { ascending: !0 });
108
+ if (t) throw Error(t.message);
109
+ return (e || []).map((e) => {
110
+ let t = e.product_categories?.[0]?.count ?? e.product_categories?.count ?? 0;
111
+ return {
112
+ id: e.id,
113
+ name: e.name,
114
+ slug: e.slug,
115
+ description: e.description ?? "",
116
+ created_at: e.created_at,
117
+ productCount: Number(t),
118
+ name_translations: e.name_translations || {},
119
+ description_translations: e.description_translations || {}
120
+ };
121
+ });
150
122
  }
151
- async function G(r) {
152
- const t = o(), { data: a, error: e } = await t.from("categories").select("id, name, slug, description, created_at").eq("slug", r).maybeSingle();
153
- if (e) throw new Error(e.message);
154
- return a;
123
+ async function y(e) {
124
+ let { data: t, error: n } = await a().from("categories").select("id, name, slug, description, created_at").eq("slug", e).maybeSingle();
125
+ if (n) throw Error(n.message);
126
+ return t;
155
127
  }
156
- async function I(r) {
157
- const t = o(), { data: a, error: e } = await t.from("product_categories").select("category:categories(id, name, slug, description, name_translations, description_translations, created_at)").eq("product_id", r);
158
- if (e) throw new Error(e.message);
159
- return (a || []).map((s) => s.category).filter(Boolean);
128
+ async function b(e) {
129
+ let { data: t, error: n } = await a().from("product_categories").select("category:categories(id, name, slug, description, name_translations, description_translations, created_at)").eq("product_id", e);
130
+ if (n) throw Error(n.message);
131
+ return (t || []).map((e) => e.category).filter(Boolean);
160
132
  }
161
- export {
162
- S as copyProductFromLanguageAction,
163
- B as getCategoriesWithCount,
164
- G as getCategoryBySlug,
165
- A as getFreemiusPricingByProductId,
166
- C as getGlobalProductAttributes,
167
- P as getProduct,
168
- I as getProductCategories,
169
- q as getProductTranslations,
170
- v as getProducts,
171
- T as getPublicFreemiusPricing,
172
- E as triggerFreemiusSync,
173
- F as triggerSingleProductSync,
174
- N as updateFreemiusOverride
175
- };
133
+ //#endregion
134
+ export { f as copyProductFromLanguageAction, v as getCategoriesWithCount, y as getCategoryBySlug, h as getFreemiusPricingByProductId, m as getGlobalProductAttributes, l as getProduct, b as getProductCategories, p as getProductTranslations, c as getProducts, _ as getPublicFreemiusPricing, u as triggerFreemiusSync, d as triggerSingleProductSync, g as updateFreemiusOverride };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("next/link"),o=require("lucide-react"),u=require("@nextblock-cms/ui"),l=require("@nextblock-cms/db/server"),d=require("../actions.cjs.js"),t=require("../server-actions.cjs.js"),m=require("./components/AttributeManager.cjs.js");async function A(){const[a,i]=await Promise.all([d.getGlobalProductAttributes(),l.getActiveLanguagesServerSide()]),n=(a||[]).map(r=>({id:r.id,name:r.name,name_translations:r.name_translations||{},slug:r.slug,terms:(r.product_attribute_terms||[]).map(s=>({...s,value_translations:s.value_translations||{}}))}));return e.jsxs("div",{className:"space-y-8 w-full max-w-[1200px] mx-auto px-6 py-8",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(u.Button,{variant:"outline",size:"icon",asChild:!0,children:e.jsx(c,{href:"/cms/products",children:e.jsx(o.ArrowLeft,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Global Attribute Management"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Define reusable attributes and terms for variation-based physical products."})]})]})}),e.jsx(m.AttributeManager,{attributes:n,createAttributeAction:t.createProductAttributeAction,deleteAttributeAction:t.deleteProductAttributeAction,createTermAction:t.createProductAttributeTermAction,deleteTermAction:t.deleteProductAttributeTermAction,reorderTermsAction:t.reorderProductAttributeTermsAction,updateTranslationsAction:t.updateProductAttributeTranslationsAction,languages:i})]})}exports.AttributeManagementPage=A;
1
+ const e=require("../../../../../_virtual/_rolldown/runtime.cjs.js"),t=require("../actions.cjs.js"),n=require("../server-actions.cjs.js"),r=require("./components/AttributeManager.cjs.js");let i=require("next/link");i=e.__toESM(i,1);let a=require("lucide-react"),o=require("react/jsx-runtime"),s=require("@nextblock-cms/db/server"),c=require("@nextblock-cms/ui");async function l(){let[e,l]=await Promise.all([t.getGlobalProductAttributes(),(0,s.getActiveLanguagesServerSide)()]),u=(e||[]).map(e=>({id:e.id,name:e.name,name_translations:e.name_translations||{},slug:e.slug,terms:(e.product_attribute_terms||[]).map(e=>({...e,value_translations:e.value_translations||{}}))}));return(0,o.jsxs)(`div`,{className:`space-y-8 w-full max-w-[1200px] mx-auto px-6 py-8`,children:[(0,o.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:(0,o.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,o.jsx)(c.Button,{variant:`outline`,size:`icon`,asChild:!0,children:(0,o.jsx)(i.default,{href:`/cms/products`,children:(0,o.jsx)(a.ArrowLeft,{className:`h-4 w-4`})})}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Global Attribute Management`}),(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Define reusable attributes and terms for variation-based physical products.`})]})]})}),(0,o.jsx)(r.AttributeManager,{attributes:u,createAttributeAction:n.createProductAttributeAction,deleteAttributeAction:n.deleteProductAttributeAction,createTermAction:n.createProductAttributeTermAction,deleteTermAction:n.deleteProductAttributeTermAction,reorderTermsAction:n.reorderProductAttributeTermsAction,updateTranslationsAction:n.updateProductAttributeTranslationsAction,languages:l})]})}exports.AttributeManagementPage=l;
@@ -1 +1 @@
1
- export declare function AttributeManagementPage(): Promise<import("react").JSX.Element>;
1
+ export declare function AttributeManagementPage(): Promise<import('react').JSX.Element>;
@@ -1,48 +1,56 @@
1
- import { jsxs as r, jsx as t } from "react/jsx-runtime";
2
- import s from "next/link";
3
- import { ArrowLeft as c } from "lucide-react";
4
- import { Button as l } from "@nextblock-cms/ui";
5
- import { getActiveLanguagesServerSide as m } from "@nextblock-cms/db/server";
6
- import { getGlobalProductAttributes as u } from "../actions.es.js";
7
- import { updateProductAttributeTranslationsAction as d, reorderProductAttributeTermsAction as A, deleteProductAttributeTermAction as p, createProductAttributeTermAction as f, deleteProductAttributeAction as b, createProductAttributeAction as g } from "../server-actions.es.js";
8
- import { AttributeManager as x } from "./components/AttributeManager.es.js";
9
- async function j() {
10
- const [i, o] = await Promise.all([
11
- u(),
12
- m()
13
- ]), n = (i || []).map((e) => ({
14
- id: e.id,
15
- name: e.name,
16
- name_translations: e.name_translations || {},
17
- slug: e.slug,
18
- terms: (e.product_attribute_terms || []).map((a) => ({
19
- ...a,
20
- value_translations: a.value_translations || {}
21
- }))
22
- }));
23
- return /* @__PURE__ */ r("div", { className: "space-y-8 w-full max-w-[1200px] mx-auto px-6 py-8", children: [
24
- /* @__PURE__ */ t("div", { className: "flex flex-wrap items-center justify-between gap-4", children: /* @__PURE__ */ r("div", { className: "flex items-center gap-3", children: [
25
- /* @__PURE__ */ t(l, { variant: "outline", size: "icon", asChild: !0, children: /* @__PURE__ */ t(s, { href: "/cms/products", children: /* @__PURE__ */ t(c, { className: "h-4 w-4" }) }) }),
26
- /* @__PURE__ */ r("div", { children: [
27
- /* @__PURE__ */ t("h1", { className: "text-2xl font-bold", children: "Global Attribute Management" }),
28
- /* @__PURE__ */ t("p", { className: "text-sm text-muted-foreground", children: "Define reusable attributes and terms for variation-based physical products." })
29
- ] })
30
- ] }) }),
31
- /* @__PURE__ */ t(
32
- x,
33
- {
34
- attributes: n,
35
- createAttributeAction: g,
36
- deleteAttributeAction: b,
37
- createTermAction: f,
38
- deleteTermAction: p,
39
- reorderTermsAction: A,
40
- updateTranslationsAction: d,
41
- languages: o
42
- }
43
- )
44
- ] });
1
+ import { getGlobalProductAttributes as e } from "../actions.es.js";
2
+ import { createProductAttributeAction as t, createProductAttributeTermAction as n, deleteProductAttributeAction as r, deleteProductAttributeTermAction as i, reorderProductAttributeTermsAction as a, updateProductAttributeTranslationsAction as o } from "../server-actions.es.js";
3
+ import { AttributeManager as s } from "./components/AttributeManager.es.js";
4
+ import c from "next/link";
5
+ import { ArrowLeft as l } from "lucide-react";
6
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
7
+ import { getActiveLanguagesServerSide as f } from "@nextblock-cms/db/server";
8
+ import { Button as p } from "@nextblock-cms/ui";
9
+ //#region libs/ecommerce/src/lib/pages/cms/products/attributes/AttributeManagementPage.tsx
10
+ async function m() {
11
+ let [m, h] = await Promise.all([e(), f()]), g = (m || []).map((e) => ({
12
+ id: e.id,
13
+ name: e.name,
14
+ name_translations: e.name_translations || {},
15
+ slug: e.slug,
16
+ terms: (e.product_attribute_terms || []).map((e) => ({
17
+ ...e,
18
+ value_translations: e.value_translations || {}
19
+ }))
20
+ }));
21
+ return /* @__PURE__ */ d("div", {
22
+ className: "space-y-8 w-full max-w-[1200px] mx-auto px-6 py-8",
23
+ children: [/* @__PURE__ */ u("div", {
24
+ className: "flex flex-wrap items-center justify-between gap-4",
25
+ children: /* @__PURE__ */ d("div", {
26
+ className: "flex items-center gap-3",
27
+ children: [/* @__PURE__ */ u(p, {
28
+ variant: "outline",
29
+ size: "icon",
30
+ asChild: !0,
31
+ children: /* @__PURE__ */ u(c, {
32
+ href: "/cms/products",
33
+ children: /* @__PURE__ */ u(l, { className: "h-4 w-4" })
34
+ })
35
+ }), /* @__PURE__ */ d("div", { children: [/* @__PURE__ */ u("h1", {
36
+ className: "text-2xl font-bold",
37
+ children: "Global Attribute Management"
38
+ }), /* @__PURE__ */ u("p", {
39
+ className: "text-sm text-muted-foreground",
40
+ children: "Define reusable attributes and terms for variation-based physical products."
41
+ })] })]
42
+ })
43
+ }), /* @__PURE__ */ u(s, {
44
+ attributes: g,
45
+ createAttributeAction: t,
46
+ deleteAttributeAction: r,
47
+ createTermAction: n,
48
+ deleteTermAction: i,
49
+ reorderTermsAction: a,
50
+ updateTranslationsAction: o,
51
+ languages: h
52
+ })]
53
+ });
45
54
  }
46
- export {
47
- j as AttributeManagementPage
48
- };
55
+ //#endregion
56
+ export { m as AttributeManagementPage };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),d=require("react"),H=require("next/navigation"),t=require("@nextblock-cms/ui"),c=require("lucide-react");function J({attributes:o,languages:C,createAttributeAction:F,deleteAttributeAction:B,createTermAction:D,deleteTermAction:P,reorderTermsAction:k,updateTranslationsAction:q}){const i=H.useRouter(),[m,v]=d.useState(""),[f,j]=d.useState(null),[z,g]=d.useState(null),[N,y]=d.useState(null),[w,T]=d.useState(null),[h,b]=d.useState({}),[A,L]=d.useState(()=>o.reduce((e,n)=>(e[n.id]=n.name_translations||{},e),{})),[S,M]=d.useState(()=>o.reduce((e,n)=>{for(const r of n.terms)e[r.id]=r.value_translations||{};return e},{})),u=C.filter(e=>!e.is_default),R=async e=>{e.preventDefault();const n=await F({name:m});if(!n.success){alert(n.error||"Failed to create attribute.");return}v(""),i.refresh()},_=async(e,n)=>{e.preventDefault(),j(n);const r=await D({attributeId:n,value:h[n]||""});if(j(null),!r.success){alert(r.error||"Failed to create term.");return}b(a=>({...a,[n]:""})),i.refresh()},O=async e=>{if(!window.confirm("Delete this attribute and all of its terms?"))return;const r=await B(e);if(!r.success){alert(r.error||"Failed to delete attribute.");return}i.refresh()},U=async e=>{g(e);const n=await P(e);if(g(null),!n.success){alert(n.error||"Failed to delete term.");return}i.refresh()},I=async(e,n,r)=>{const a=e.terms.findIndex(p=>p.id===n),l=a+r;if(a===-1||l<0||l>=e.terms.length)return;const x=[...e.terms],[G]=x.splice(a,1);x.splice(l,0,G),y(e.id);const $=await k({attributeId:e.id,orderedTermIds:x.map(p=>p.id)});if(y(null),!$.success){alert($.error||"Failed to reorder terms.");return}i.refresh()},E=async e=>{T(e.id);const n=await q({attributeId:e.id,nameTranslations:A[e.id]||{},termTranslations:e.terms.map(r=>({termId:r.id,valueTranslations:S[r.id]||{}}))});if(T(null),!n.success){alert(n.error||"Failed to save translations.");return}i.refresh()};return s.jsxs("div",{className:"space-y-6",children:[s.jsx("form",{onSubmit:R,className:"rounded-lg border bg-card p-6 shadow-sm",children:s.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[s.jsxs("div",{className:"flex-1 min-w-[220px] space-y-2",children:[s.jsx(t.Label,{htmlFor:"attribute-name",children:"New Attribute"}),s.jsx(t.Input,{id:"attribute-name",value:m,onChange:e=>v(e.target.value),placeholder:"Material, Size, Color..."})]}),s.jsxs(t.Button,{type:"submit",disabled:!m.trim(),children:[s.jsx(c.Plus,{className:"mr-2 h-4 w-4"}),"Create Attribute"]})]})}),o.length===0?s.jsx("div",{className:"rounded-lg border border-dashed p-6 text-sm text-muted-foreground",children:"No global attributes have been created yet."}):s.jsx("div",{className:"grid gap-6",children:o.map(e=>s.jsxs("div",{className:"rounded-lg border bg-card p-6 shadow-sm",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-lg font-semibold",children:e.name}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e.slug})]}),s.jsx(t.Button,{type:"button",variant:"ghost",size:"icon",onClick:()=>O(e.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(c.Trash2,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"mt-4 space-y-2",children:e.terms.map((n,r)=>s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-muted/20 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(t.Badge,{variant:"secondary",className:"py-1.5",children:n.value}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:["Position ",r+1]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(t.Button,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>I(e,n.id,-1),disabled:r===0||N===e.id,children:s.jsx(c.ChevronUp,{className:"h-4 w-4"})}),s.jsx(t.Button,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>I(e,n.id,1),disabled:r===e.terms.length-1||N===e.id,children:s.jsx(c.ChevronDown,{className:"h-4 w-4"})}),s.jsx(t.Button,{type:"button",variant:"ghost",size:"icon",onClick:()=>U(n.id),className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:z===n.id,children:s.jsx(c.Trash2,{className:"h-4 w-4"})})]})]},n.id))}),s.jsxs("form",{onSubmit:n=>_(n,e.id),className:"mt-6 flex flex-wrap items-end gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-[220px] space-y-2",children:[s.jsx(t.Label,{htmlFor:`term-input-${e.id}`,children:"Add Term"}),s.jsx(t.Input,{id:`term-input-${e.id}`,value:h[e.id]||"",onChange:n=>b(r=>({...r,[e.id]:n.target.value})),placeholder:`Add a term for ${e.name}`})]}),s.jsxs(t.Button,{type:"submit",variant:"outline",disabled:!h[e.id]?.trim()||f===e.id,children:[s.jsx(c.Plus,{className:"mr-2 h-4 w-4"}),f===e.id?"Saving...":"Add Term"]})]}),u.length>0&&s.jsxs("div",{className:"mt-6 border-t pt-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium",children:"Translations"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"Translate the attribute label and each term for every active site language."})]}),s.jsx(t.Button,{type:"button",variant:"outline",onClick:()=>E(e),disabled:w===e.id,children:w===e.id?"Saving...":"Save Translations"})]}),s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:u.map(n=>s.jsxs("div",{className:"space-y-2",children:[s.jsxs(t.Label,{htmlFor:`attribute-translation-${e.id}-${n.code}`,children:["Attribute Name (",n.name,")"]}),s.jsx(t.Input,{id:`attribute-translation-${e.id}-${n.code}`,value:A[e.id]?.[n.code]||"",onChange:r=>L(a=>({...a,[e.id]:{...a[e.id]||{},[n.code]:r.target.value}})),placeholder:e.name})]},`${e.id}-${n.code}`))}),s.jsx("div",{className:"space-y-3",children:e.terms.map(n=>s.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"font-medium",children:n.value}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Translate this term for each language."})]}),s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:u.map(r=>s.jsxs("div",{className:"space-y-2",children:[s.jsx(t.Label,{htmlFor:`term-translation-${n.id}-${r.code}`,children:r.name}),s.jsx(t.Input,{id:`term-translation-${n.id}-${r.code}`,value:S[n.id]?.[r.code]||"",onChange:a=>M(l=>({...l,[n.id]:{...l[n.id]||{},[r.code]:a.target.value}})),placeholder:n.value})]},`${n.id}-${r.code}`))})]},`translations-${n.id}`))})]})]},e.id))})]})}exports.AttributeManager=J;
1
+ "use client";let e=require("react"),t=require("lucide-react"),n=require("react/jsx-runtime"),r=require("next/navigation"),i=require("@nextblock-cms/ui");function a({attributes:a,languages:o,createAttributeAction:s,deleteAttributeAction:c,createTermAction:l,deleteTermAction:u,reorderTermsAction:d,updateTranslationsAction:f}){let p=(0,r.useRouter)(),[m,h]=(0,e.useState)(``),[g,_]=(0,e.useState)(null),[v,y]=(0,e.useState)(null),[b,x]=(0,e.useState)(null),[S,C]=(0,e.useState)(null),[w,T]=(0,e.useState)({}),[E,D]=(0,e.useState)(()=>a.reduce((e,t)=>(e[t.id]=t.name_translations||{},e),{})),[O,k]=(0,e.useState)(()=>a.reduce((e,t)=>{for(let n of t.terms)e[n.id]=n.value_translations||{};return e},{})),A=o.filter(e=>!e.is_default),j=async e=>{e.preventDefault();let t=await s({name:m});if(!t.success){alert(t.error||`Failed to create attribute.`);return}h(``),p.refresh()},M=async(e,t)=>{e.preventDefault(),_(t);let n=await l({attributeId:t,value:w[t]||``});if(_(null),!n.success){alert(n.error||`Failed to create term.`);return}T(e=>({...e,[t]:``})),p.refresh()},N=async e=>{if(!window.confirm(`Delete this attribute and all of its terms?`))return;let t=await c(e);if(!t.success){alert(t.error||`Failed to delete attribute.`);return}p.refresh()},P=async e=>{y(e);let t=await u(e);if(y(null),!t.success){alert(t.error||`Failed to delete term.`);return}p.refresh()},F=async(e,t,n)=>{let r=e.terms.findIndex(e=>e.id===t),i=r+n;if(r===-1||i<0||i>=e.terms.length)return;let a=[...e.terms],[o]=a.splice(r,1);a.splice(i,0,o),x(e.id);let s=await d({attributeId:e.id,orderedTermIds:a.map(e=>e.id)});if(x(null),!s.success){alert(s.error||`Failed to reorder terms.`);return}p.refresh()},I=async e=>{C(e.id);let t=await f({attributeId:e.id,nameTranslations:E[e.id]||{},termTranslations:e.terms.map(e=>({termId:e.id,valueTranslations:O[e.id]||{}}))});if(C(null),!t.success){alert(t.error||`Failed to save translations.`);return}p.refresh()};return(0,n.jsxs)(`div`,{className:`space-y-6`,children:[(0,n.jsx)(`form`,{onSubmit:j,className:`rounded-lg border bg-card p-6 shadow-sm`,children:(0,n.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,n.jsxs)(`div`,{className:`flex-1 min-w-[220px] space-y-2`,children:[(0,n.jsx)(i.Label,{htmlFor:`attribute-name`,children:`New Attribute`}),(0,n.jsx)(i.Input,{id:`attribute-name`,value:m,onChange:e=>h(e.target.value),placeholder:`Material, Size, Color...`})]}),(0,n.jsxs)(i.Button,{type:`submit`,disabled:!m.trim(),children:[(0,n.jsx)(t.Plus,{className:`mr-2 h-4 w-4`}),`Create Attribute`]})]})}),a.length===0?(0,n.jsx)(`div`,{className:`rounded-lg border border-dashed p-6 text-sm text-muted-foreground`,children:`No global attributes have been created yet.`}):(0,n.jsx)(`div`,{className:`grid gap-6`,children:a.map(e=>(0,n.jsxs)(`div`,{className:`rounded-lg border bg-card p-6 shadow-sm`,children:[(0,n.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,n.jsxs)(`div`,{children:[(0,n.jsx)(`h2`,{className:`text-lg font-semibold`,children:e.name}),(0,n.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.slug})]}),(0,n.jsx)(i.Button,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>N(e.id),className:`text-muted-foreground hover:text-destructive`,children:(0,n.jsx)(t.Trash2,{className:`h-4 w-4`})})]}),(0,n.jsx)(`div`,{className:`mt-4 space-y-2`,children:e.terms.map((r,a)=>(0,n.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-muted/20 px-3 py-2`,children:[(0,n.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,n.jsx)(i.Badge,{variant:`secondary`,className:`py-1.5`,children:r.value}),(0,n.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Position `,a+1]})]}),(0,n.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,n.jsx)(i.Button,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>F(e,r.id,-1),disabled:a===0||b===e.id,children:(0,n.jsx)(t.ChevronUp,{className:`h-4 w-4`})}),(0,n.jsx)(i.Button,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>F(e,r.id,1),disabled:a===e.terms.length-1||b===e.id,children:(0,n.jsx)(t.ChevronDown,{className:`h-4 w-4`})}),(0,n.jsx)(i.Button,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>P(r.id),className:`h-8 w-8 text-muted-foreground hover:text-destructive`,disabled:v===r.id,children:(0,n.jsx)(t.Trash2,{className:`h-4 w-4`})})]})]},r.id))}),(0,n.jsxs)(`form`,{onSubmit:t=>M(t,e.id),className:`mt-6 flex flex-wrap items-end gap-3`,children:[(0,n.jsxs)(`div`,{className:`flex-1 min-w-[220px] space-y-2`,children:[(0,n.jsx)(i.Label,{htmlFor:`term-input-${e.id}`,children:`Add Term`}),(0,n.jsx)(i.Input,{id:`term-input-${e.id}`,value:w[e.id]||``,onChange:t=>T(n=>({...n,[e.id]:t.target.value})),placeholder:`Add a term for ${e.name}`})]}),(0,n.jsxs)(i.Button,{type:`submit`,variant:`outline`,disabled:!w[e.id]?.trim()||g===e.id,children:[(0,n.jsx)(t.Plus,{className:`mr-2 h-4 w-4`}),g===e.id?`Saving...`:`Add Term`]})]}),A.length>0&&(0,n.jsxs)(`div`,{className:`mt-6 border-t pt-6 space-y-4`,children:[(0,n.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,n.jsxs)(`div`,{children:[(0,n.jsx)(`h3`,{className:`font-medium`,children:`Translations`}),(0,n.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Translate the attribute label and each term for every active site language.`})]}),(0,n.jsx)(i.Button,{type:`button`,variant:`outline`,onClick:()=>I(e),disabled:S===e.id,children:S===e.id?`Saving...`:`Save Translations`})]}),(0,n.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:A.map(t=>(0,n.jsxs)(`div`,{className:`space-y-2`,children:[(0,n.jsxs)(i.Label,{htmlFor:`attribute-translation-${e.id}-${t.code}`,children:[`Attribute Name (`,t.name,`)`]}),(0,n.jsx)(i.Input,{id:`attribute-translation-${e.id}-${t.code}`,value:E[e.id]?.[t.code]||``,onChange:n=>D(r=>({...r,[e.id]:{...r[e.id]||{},[t.code]:n.target.value}})),placeholder:e.name})]},`${e.id}-${t.code}`))}),(0,n.jsx)(`div`,{className:`space-y-3`,children:e.terms.map(e=>(0,n.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-3`,children:[(0,n.jsxs)(`div`,{children:[(0,n.jsx)(`p`,{className:`font-medium`,children:e.value}),(0,n.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Translate this term for each language.`})]}),(0,n.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:A.map(t=>(0,n.jsxs)(`div`,{className:`space-y-2`,children:[(0,n.jsx)(i.Label,{htmlFor:`term-translation-${e.id}-${t.code}`,children:t.name}),(0,n.jsx)(i.Input,{id:`term-translation-${e.id}-${t.code}`,value:O[e.id]?.[t.code]||``,onChange:n=>k(r=>({...r,[e.id]:{...r[e.id]||{},[t.code]:n.target.value}})),placeholder:e.value})]},`${e.id}-${t.code}`))})]},`translations-${e.id}`))})]})]},e.id))})]})}exports.AttributeManager=a;
@@ -46,5 +46,5 @@ interface AttributeManagerProps {
46
46
  error?: string;
47
47
  }>;
48
48
  }
49
- export declare function AttributeManager({ attributes, languages, createAttributeAction, deleteAttributeAction, createTermAction, deleteTermAction, reorderTermsAction, updateTranslationsAction, }: AttributeManagerProps): import("react").JSX.Element;
49
+ export declare function AttributeManager({ attributes, languages, createAttributeAction, deleteAttributeAction, createTermAction, deleteTermAction, reorderTermsAction, updateTranslationsAction, }: AttributeManagerProps): import('react').JSX.Element;
50
50
  export {};