@payloadcms/plugin-ecommerce 0.0.1-beta.0 → 3.57.0-internal.36ffe2b

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 (284) hide show
  1. package/dist/collections/addresses/createAddressesCollection.d.ts +21 -0
  2. package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -0
  3. package/dist/collections/addresses/createAddressesCollection.js +71 -0
  4. package/dist/collections/addresses/createAddressesCollection.js.map +1 -0
  5. package/dist/collections/addresses/defaultAddressFields.d.ts +3 -0
  6. package/dist/collections/addresses/defaultAddressFields.d.ts.map +1 -0
  7. package/dist/collections/addresses/defaultAddressFields.js +72 -0
  8. package/dist/collections/addresses/defaultAddressFields.js.map +1 -0
  9. package/dist/collections/addresses/defaultCountries.d.ts +9 -0
  10. package/dist/collections/addresses/defaultCountries.d.ts.map +1 -0
  11. package/dist/collections/addresses/defaultCountries.js +169 -0
  12. package/dist/collections/addresses/defaultCountries.js.map +1 -0
  13. package/dist/collections/addresses/hooks/beforeChange.d.ts +8 -0
  14. package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -0
  15. package/dist/collections/addresses/hooks/beforeChange.js +12 -0
  16. package/dist/collections/addresses/hooks/beforeChange.js.map +1 -0
  17. package/dist/collections/carts/beforeChange.d.ts +8 -0
  18. package/dist/collections/carts/beforeChange.d.ts.map +1 -0
  19. package/dist/collections/carts/beforeChange.js +37 -0
  20. package/dist/collections/carts/beforeChange.js.map +1 -0
  21. package/dist/collections/carts/createCartsCollection.d.ts +29 -0
  22. package/dist/collections/carts/createCartsCollection.d.ts.map +1 -0
  23. package/dist/collections/carts/createCartsCollection.js +138 -0
  24. package/dist/collections/carts/createCartsCollection.js.map +1 -0
  25. package/dist/collections/carts/statusBeforeRead.d.ts +3 -0
  26. package/dist/collections/carts/statusBeforeRead.d.ts.map +1 -0
  27. package/dist/collections/carts/statusBeforeRead.js +18 -0
  28. package/dist/collections/carts/statusBeforeRead.js.map +1 -0
  29. package/dist/collections/orders/createOrdersCollection.d.ts +34 -0
  30. package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -0
  31. package/dist/collections/orders/createOrdersCollection.js +162 -0
  32. package/dist/collections/orders/createOrdersCollection.js.map +1 -0
  33. package/dist/collections/products/createProductsCollection.d.ts +26 -0
  34. package/dist/collections/products/createProductsCollection.d.ts.map +1 -0
  35. package/dist/collections/products/createProductsCollection.js +62 -0
  36. package/dist/collections/products/createProductsCollection.js.map +1 -0
  37. package/dist/collections/transactions/createTransactionsCollection.d.ts +40 -0
  38. package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -0
  39. package/dist/collections/transactions/createTransactionsCollection.js +157 -0
  40. package/dist/collections/transactions/createTransactionsCollection.js.map +1 -0
  41. package/dist/collections/variants/createVariantOptionsCollection.d.ts +15 -0
  42. package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -0
  43. package/dist/collections/variants/createVariantOptionsCollection.js +53 -0
  44. package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -0
  45. package/dist/collections/variants/createVariantTypesCollection.d.ts +15 -0
  46. package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -0
  47. package/dist/collections/variants/createVariantTypesCollection.js +49 -0
  48. package/dist/collections/variants/createVariantTypesCollection.js.map +1 -0
  49. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts +8 -0
  50. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -0
  51. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +38 -0
  52. package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -0
  53. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts +7 -0
  54. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -0
  55. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +53 -0
  56. package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -0
  57. package/dist/collections/variants/createVariantsCollection/index.d.ts +24 -0
  58. package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -0
  59. package/dist/collections/variants/createVariantsCollection/index.js +101 -0
  60. package/dist/collections/variants/createVariantsCollection/index.js.map +1 -0
  61. package/dist/currencies/index.d.ts +5 -0
  62. package/dist/currencies/index.d.ts.map +1 -0
  63. package/dist/currencies/index.js +20 -0
  64. package/dist/currencies/index.js.map +1 -0
  65. package/dist/endpoints/confirmOrder.d.ts +42 -0
  66. package/dist/endpoints/confirmOrder.d.ts.map +1 -0
  67. package/dist/endpoints/confirmOrder.js +143 -0
  68. package/dist/endpoints/confirmOrder.js.map +1 -0
  69. package/dist/endpoints/initiatePayment.d.ts +43 -0
  70. package/dist/endpoints/initiatePayment.d.ts.map +1 -0
  71. package/dist/endpoints/initiatePayment.js +220 -0
  72. package/dist/endpoints/initiatePayment.js.map +1 -0
  73. package/dist/exports/client/index.d.ts +3 -0
  74. package/dist/exports/client/index.d.ts.map +1 -0
  75. package/dist/exports/client/index.js +4 -0
  76. package/dist/exports/client/index.js.map +1 -0
  77. package/dist/exports/client/react.d.ts +4 -0
  78. package/dist/exports/client/react.d.ts.map +1 -0
  79. package/dist/exports/client/react.js +5 -0
  80. package/dist/exports/client/react.js.map +1 -0
  81. package/dist/exports/payments/stripe.d.ts +2 -0
  82. package/dist/exports/payments/stripe.d.ts.map +1 -0
  83. package/dist/exports/payments/stripe.js +3 -0
  84. package/dist/exports/payments/stripe.js.map +1 -0
  85. package/dist/exports/rsc.d.ts +3 -0
  86. package/dist/exports/rsc.d.ts.map +1 -0
  87. package/dist/exports/rsc.js +4 -0
  88. package/dist/exports/rsc.js.map +1 -0
  89. package/dist/exports/translations.d.ts +2 -0
  90. package/dist/exports/translations.d.ts.map +1 -0
  91. package/dist/exports/translations.js +3 -0
  92. package/dist/exports/translations.js.map +1 -0
  93. package/dist/exports/types.d.ts +2 -0
  94. package/dist/exports/types.d.ts.map +1 -0
  95. package/dist/exports/types.js +3 -0
  96. package/dist/exports/types.js.map +1 -0
  97. package/dist/fields/amountField.d.ts +13 -0
  98. package/dist/fields/amountField.d.ts.map +1 -0
  99. package/dist/fields/amountField.js +33 -0
  100. package/dist/fields/amountField.js.map +1 -0
  101. package/dist/fields/cartItemsField.d.ts +26 -0
  102. package/dist/fields/cartItemsField.d.ts.map +1 -0
  103. package/dist/fields/cartItemsField.js +55 -0
  104. package/dist/fields/cartItemsField.js.map +1 -0
  105. package/dist/fields/currencyField.d.ts +9 -0
  106. package/dist/fields/currencyField.d.ts.map +1 -0
  107. package/dist/fields/currencyField.js +29 -0
  108. package/dist/fields/currencyField.js.map +1 -0
  109. package/dist/fields/inventoryField.d.ts +7 -0
  110. package/dist/fields/inventoryField.d.ts.map +1 -0
  111. package/dist/fields/inventoryField.js +16 -0
  112. package/dist/fields/inventoryField.js.map +1 -0
  113. package/dist/fields/pricesField.d.ts +12 -0
  114. package/dist/fields/pricesField.d.ts.map +1 -0
  115. package/dist/fields/pricesField.js +54 -0
  116. package/dist/fields/pricesField.js.map +1 -0
  117. package/dist/fields/statusField.d.ts +8 -0
  118. package/dist/fields/statusField.d.ts.map +1 -0
  119. package/dist/fields/statusField.js +49 -0
  120. package/dist/fields/statusField.js.map +1 -0
  121. package/dist/fields/variantsFields.d.ts +14 -0
  122. package/dist/fields/variantsFields.d.ts.map +1 -0
  123. package/dist/fields/variantsFields.js +48 -0
  124. package/dist/fields/variantsFields.js.map +1 -0
  125. package/dist/index.d.ts +19 -0
  126. package/dist/index.d.ts.map +1 -0
  127. package/dist/index.js +238 -0
  128. package/dist/index.js.map +1 -0
  129. package/dist/payments/adapters/stripe/confirmOrder.d.ts +11 -0
  130. package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -0
  131. package/dist/payments/adapters/stripe/confirmOrder.js +101 -0
  132. package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -0
  133. package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts +13 -0
  134. package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts.map +1 -0
  135. package/dist/payments/adapters/stripe/endpoints/webhooks.js +53 -0
  136. package/dist/payments/adapters/stripe/endpoints/webhooks.js.map +1 -0
  137. package/dist/payments/adapters/stripe/index.d.ts +60 -0
  138. package/dist/payments/adapters/stripe/index.d.ts.map +1 -0
  139. package/dist/payments/adapters/stripe/index.js +68 -0
  140. package/dist/payments/adapters/stripe/index.js.map +1 -0
  141. package/dist/payments/adapters/stripe/initiatePayment.d.ts +11 -0
  142. package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -0
  143. package/dist/payments/adapters/stripe/initiatePayment.js +102 -0
  144. package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -0
  145. package/dist/react/provider/index.d.ts +41 -0
  146. package/dist/react/provider/index.d.ts.map +1 -0
  147. package/dist/react/provider/index.js +790 -0
  148. package/dist/react/provider/index.js.map +1 -0
  149. package/dist/react/provider/types.d.ts +171 -0
  150. package/dist/react/provider/types.d.ts.map +1 -0
  151. package/dist/react/provider/types.js +3 -0
  152. package/dist/react/provider/types.js.map +1 -0
  153. package/dist/react/provider/utilities.d.ts +9 -0
  154. package/dist/react/provider/utilities.d.ts.map +1 -0
  155. package/dist/react/provider/utilities.js +13 -0
  156. package/dist/react/provider/utilities.js.map +1 -0
  157. package/dist/translations/en.d.ts +3 -0
  158. package/dist/translations/en.d.ts.map +1 -0
  159. package/dist/translations/en.js +86 -0
  160. package/dist/translations/en.js.map +1 -0
  161. package/dist/translations/index.d.ts +7 -0
  162. package/dist/translations/index.d.ts.map +1 -0
  163. package/dist/translations/index.js +6 -0
  164. package/dist/translations/index.js.map +1 -0
  165. package/dist/types.d.ts +658 -0
  166. package/dist/types.d.ts.map +1 -0
  167. package/dist/types.js +3 -0
  168. package/dist/types.js.map +1 -0
  169. package/dist/ui/PriceCell/index.d.ts +12 -0
  170. package/dist/ui/PriceCell/index.d.ts.map +1 -0
  171. package/dist/ui/PriceCell/index.js +38 -0
  172. package/dist/ui/PriceCell/index.js.map +1 -0
  173. package/dist/ui/PriceInput/FormattedInput.d.ts +17 -0
  174. package/dist/ui/PriceInput/FormattedInput.d.ts.map +1 -0
  175. package/dist/ui/PriceInput/FormattedInput.js +146 -0
  176. package/dist/ui/PriceInput/FormattedInput.js.map +1 -0
  177. package/{src/ui/PriceInput/index.scss → dist/ui/PriceInput/index.css} +7 -0
  178. package/dist/ui/PriceInput/index.d.ts +11 -0
  179. package/dist/ui/PriceInput/index.d.ts.map +1 -0
  180. package/dist/ui/PriceInput/index.js +20 -0
  181. package/dist/ui/PriceInput/index.js.map +1 -0
  182. package/dist/ui/PriceRowLabel/index.d.ts +8 -0
  183. package/dist/ui/PriceRowLabel/index.d.ts.map +1 -0
  184. package/dist/ui/PriceRowLabel/index.js +66 -0
  185. package/dist/ui/PriceRowLabel/index.js.map +1 -0
  186. package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts +8 -0
  187. package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts.map +1 -0
  188. package/dist/ui/VariantOptionsSelector/ErrorBox.js +28 -0
  189. package/dist/ui/VariantOptionsSelector/ErrorBox.js.map +1 -0
  190. package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts +13 -0
  191. package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts.map +1 -0
  192. package/dist/ui/VariantOptionsSelector/OptionsSelect.js +71 -0
  193. package/dist/ui/VariantOptionsSelector/OptionsSelect.js.map +1 -0
  194. package/dist/ui/VariantOptionsSelector/index.d.ts +6 -0
  195. package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -0
  196. package/dist/ui/VariantOptionsSelector/index.js +78 -0
  197. package/dist/ui/VariantOptionsSelector/index.js.map +1 -0
  198. package/dist/ui/utilities.d.ts +16 -0
  199. package/dist/ui/utilities.d.ts.map +1 -0
  200. package/dist/ui/utilities.js +26 -0
  201. package/dist/ui/utilities.js.map +1 -0
  202. package/dist/utilities/defaultProductsValidation.d.ts +3 -0
  203. package/dist/utilities/defaultProductsValidation.d.ts.map +1 -0
  204. package/dist/utilities/defaultProductsValidation.js +40 -0
  205. package/dist/utilities/defaultProductsValidation.js.map +1 -0
  206. package/dist/utilities/errorCodes.d.ts +3 -0
  207. package/dist/utilities/errorCodes.d.ts.map +1 -0
  208. package/dist/utilities/errorCodes.js +4 -0
  209. package/dist/utilities/errorCodes.js.map +1 -0
  210. package/dist/utilities/getCollectionSlugMap.d.ts +11 -0
  211. package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -0
  212. package/dist/utilities/getCollectionSlugMap.js +25 -0
  213. package/dist/utilities/getCollectionSlugMap.js.map +1 -0
  214. package/dist/utilities/sanitizePluginConfig.d.ts +7 -0
  215. package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -0
  216. package/dist/utilities/sanitizePluginConfig.js +67 -0
  217. package/dist/utilities/sanitizePluginConfig.js.map +1 -0
  218. package/package.json +98 -1
  219. package/.prettierignore +0 -12
  220. package/.swcrc +0 -24
  221. package/eslint.config.js +0 -18
  222. package/src/addresses/addressesCollection.ts +0 -76
  223. package/src/addresses/defaultAddressFields.ts +0 -83
  224. package/src/addresses/defaultCountries.ts +0 -50
  225. package/src/carts/beforeChange.ts +0 -51
  226. package/src/carts/cartsCollection.ts +0 -146
  227. package/src/currencies/index.ts +0 -29
  228. package/src/endpoints/confirmOrder.ts +0 -312
  229. package/src/endpoints/initiatePayment.ts +0 -322
  230. package/src/exports/addresses.ts +0 -2
  231. package/src/exports/currencies.ts +0 -1
  232. package/src/exports/fields.ts +0 -5
  233. package/src/exports/orders.ts +0 -1
  234. package/src/exports/payments/stripe.ts +0 -1
  235. package/src/exports/plugin.ts +0 -1
  236. package/src/exports/products.ts +0 -1
  237. package/src/exports/react.ts +0 -8
  238. package/src/exports/transactions.ts +0 -1
  239. package/src/exports/translations.ts +0 -1
  240. package/src/exports/types.ts +0 -7
  241. package/src/exports/ui.ts +0 -3
  242. package/src/exports/variants.ts +0 -5
  243. package/src/fields/amountField.ts +0 -43
  244. package/src/fields/cartItemsField.ts +0 -84
  245. package/src/fields/currencyField.ts +0 -39
  246. package/src/fields/inventoryField.ts +0 -22
  247. package/src/fields/pricesField.ts +0 -65
  248. package/src/fields/statusField.ts +0 -57
  249. package/src/fields/variantsFields.ts +0 -56
  250. package/src/index.ts +0 -275
  251. package/src/orders/ordersCollection.ts +0 -157
  252. package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
  253. package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
  254. package/src/payments/adapters/stripe/index.ts +0 -135
  255. package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
  256. package/src/products/productsCollection.ts +0 -78
  257. package/src/react/provider/index.tsx +0 -893
  258. package/src/react/provider/types.ts +0 -184
  259. package/src/react/provider/utilities.ts +0 -22
  260. package/src/transactions/transactionsCollection.ts +0 -166
  261. package/src/translations/en.ts +0 -64
  262. package/src/translations/index.ts +0 -11
  263. package/src/types.ts +0 -403
  264. package/src/ui/PriceInput/FormattedInput.tsx +0 -134
  265. package/src/ui/PriceInput/index.tsx +0 -43
  266. package/src/ui/PriceInput/utilities.ts +0 -46
  267. package/src/ui/PriceRowLabel/index.tsx +0 -56
  268. package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
  269. package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
  270. package/src/ui/VariantOptionsSelector/index.tsx +0 -83
  271. package/src/utilities/defaultProductsValidation.ts +0 -42
  272. package/src/utilities/errorCodes.ts +0 -14
  273. package/src/utilities/getCollectionSlugMap.ts +0 -84
  274. package/src/utilities/sanitizePluginConfig.ts +0 -80
  275. package/src/variants/variantOptionsCollection.ts +0 -59
  276. package/src/variants/variantTypesCollection.ts +0 -55
  277. package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
  278. package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
  279. package/src/variants/variantsCollection/index.ts +0 -119
  280. package/tsconfig.json +0 -7
  281. package/tsconfig.tsbuildinfo +0 -1
  282. /package/{src → dist}/translations/translation-schema.json +0 -0
  283. /package/{src → dist}/ui/PriceRowLabel/index.css +0 -0
  284. /package/{src → dist}/ui/VariantOptionsSelector/index.css +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n Access,\n CollectionConfig,\n DefaultDocumentIDType,\n Endpoint,\n Field,\n FieldAccess,\n GroupField,\n PayloadRequest,\n SelectType,\n TypedCollection,\n Where,\n} from 'payload'\n\nexport type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]\n\nexport type CollectionOverride = (args: {\n defaultCollection: CollectionConfig\n}) => CollectionConfig | Promise<CollectionConfig>\n\nexport type CartItem = {\n id: DefaultDocumentIDType\n product: DefaultDocumentIDType | TypedCollection['products']\n quantity: number\n variant?: DefaultDocumentIDType | TypedCollection['variants']\n}\n\ntype DefaultCartType = {\n currency?: string\n customer?: DefaultDocumentIDType | TypedCollection['customers']\n id: DefaultDocumentIDType\n items: CartItem[]\n subtotal?: number\n}\n\nexport type Cart = DefaultCartType\n\ntype InitiatePaymentReturnType = {\n /**\n * Allows for additional data to be returned, such as payment method specific data\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n message: string\n}\n\ntype InitiatePayment = (args: {\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n data: {\n /**\n * Billing address for the payment.\n */\n billingAddress: TypedCollection['addresses']\n /**\n * Cart items.\n */\n cart: Cart\n /**\n * Currency code to use for the payment.\n */\n currency: string\n customerEmail: string\n /**\n * Shipping address for the payment.\n */\n shippingAddress?: TypedCollection['addresses']\n }\n req: PayloadRequest\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n * For example, this is used to create a record of the payment intent in the transactions collection.\n */\n transactionsSlug: string\n}) => InitiatePaymentReturnType | Promise<InitiatePaymentReturnType>\n\ntype ConfirmOrderReturnType = {\n /**\n * Allows for additional data to be returned, such as payment method specific data\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n message: string\n orderID: DefaultDocumentIDType\n transactionID: DefaultDocumentIDType\n}\n\ntype ConfirmOrder = (args: {\n /**\n * The slug of the carts collection, defaults to 'carts'.\n * For example, this is used to retrieve the cart for the order.\n */\n cartsSlug?: string\n /**\n * The slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * Data made available to the payment method when confirming an order. You should get the cart items from the transaction.\n */\n data: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any // Allows for additional data to be passed through, such as payment method specific data\n customerEmail?: string\n }\n /**\n * The slug of the orders collection, defaults to 'orders'.\n */\n ordersSlug?: string\n req: PayloadRequest\n /**\n * The slug of the transactions collection, defaults to 'transactions'.\n * For example, this is used to create a record of the payment intent in the transactions collection.\n */\n transactionsSlug?: string\n}) => ConfirmOrderReturnType | Promise<ConfirmOrderReturnType>\n\n/**\n * The full payment adapter config expected as part of the config for the Ecommerce plugin.\n *\n * You can insert this type directly or return it from a function constructing it.\n */\nexport type PaymentAdapter = {\n /**\n * The function that is called via the `/api/payments/{provider_name}/confirm-order` endpoint to confirm an order after a payment has been made.\n *\n * You should handle the order confirmation logic here.\n *\n * @example\n *\n * ```ts\n * const confirmOrder: ConfirmOrder = async ({ data: { customerEmail }, ordersSlug, req, transactionsSlug }) => {\n // Confirm the payment with Stripe or another payment provider here\n // Create an order in the orders collection here\n // Update the record of the payment intent in the transactions collection here\n return {\n message: 'Order confirmed successfully',\n orderID: 'order_123',\n transactionID: 'txn_123',\n // Include any additional data required for the payment method here\n }\n }\n * ```\n */\n confirmOrder: ConfirmOrder\n /**\n * An array of endpoints to be bootstrapped to Payload's API in order to support the payment method. All API paths are relative to `/api/payments/{provider_name}`.\n *\n * So for example, path `/webhooks` in the Stripe adapter becomes `/api/payments/stripe/webhooks`.\n *\n * @example '/webhooks'\n */\n endpoints?: Endpoint[]\n /**\n * A group configuration to be used in the admin interface to display the payment method.\n *\n * @example\n *\n * ```ts\n * const groupField: GroupField = {\n name: 'stripe',\n type: 'group',\n admin: {\n condition: (data) => data?.paymentMethod === 'stripe',\n },\n fields: [\n {\n name: 'stripeCustomerID',\n type: 'text',\n label: 'Stripe Customer ID',\n required: true,\n },\n {\n name: 'stripePaymentIntentID',\n type: 'text',\n label: 'Stripe PaymentIntent ID',\n required: true,\n },\n ],\n }\n * ```\n */\n group: GroupField\n /**\n * The function that is called via the `/api/payments/{provider_name}/initiate` endpoint to initiate a payment for an order.\n *\n * You should handle the payment initiation logic here.\n *\n * @example\n *\n * ```ts\n * const initiatePayment: InitiatePayment = async ({ data: { cart, currency, customerEmail, billingAddress, shippingAddress }, req, transactionsSlug }) => {\n // Create a payment intent with Stripe or another payment provider here\n // Create a record of the payment intent in the transactions collection here\n return {\n message: 'Payment initiated successfully',\n // Include any additional data required for the payment method here\n }\n }\n * ```\n */\n initiatePayment: InitiatePayment\n /**\n * The label of the payment method\n * @example\n * 'Bank Transfer'\n */\n label?: string\n /**\n * The name of the payment method\n * @example 'stripe'\n */\n name: string\n}\n\nexport type PaymentAdapterClient = {\n confirmOrder: boolean\n initiatePayment: boolean\n} & Pick<PaymentAdapter, 'label' | 'name'>\n\nexport type Currency = {\n /**\n * The ISO 4217 currency code\n * @example 'usd'\n */\n code: string\n /**\n * The number of decimal places the currency uses\n * @example 2\n */\n decimals: number\n /**\n * A user friendly name for the currency.\n *\n * @example 'US Dollar'\n */\n label: string\n /**\n * The symbol of the currency\n * @example '$'\n */\n symbol: string\n}\n\n/**\n * Commonly used arguments for a Payment Adapter function, it's use is entirely optional.\n */\nexport type PaymentAdapterArgs = {\n /**\n * Overrides the default fields of the collection. Affects the payment fields on collections such as transactions.\n */\n groupOverrides?: { fields?: FieldsOverride } & Partial<Omit<GroupField, 'fields'>>\n /**\n * The visually readable label for the payment method.\n * @example 'Bank Transfer'\n */\n label?: string\n}\n\n/**\n * Commonly used arguments for a Payment Adapter function, it's use is entirely optional.\n */\nexport type PaymentAdapterClientArgs = {\n /**\n * The visually readable label for the payment method.\n * @example 'Bank Transfer'\n */\n label?: string\n}\n\nexport type VariantsConfig = {\n /**\n * Override the default variants collection. If you override the collection, you should ensure it has the required fields for variants or re-use the default fields.\n *\n * @example\n *\n * ```ts\n * variants: {\n variantOptionsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'customField',\n label: 'Custom Field',\n type: 'text',\n },\n ],\n })\n }\n ```\n */\n variantOptionsCollectionOverride?: CollectionOverride\n /**\n * Override the default variants collection. If you override the collection, you should ensure it has the required fields for variants or re-use the default fields.\n *\n * @example\n *\n * ```ts\n * variants: {\n variantsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'customField',\n label: 'Custom Field',\n type: 'text',\n },\n ],\n })\n }\n ```\n */\n variantsCollectionOverride?: CollectionOverride\n /**\n * Override the default variants collection. If you override the collection, you should ensure it has the required fields for variants or re-use the default fields.\n *\n * @example\n *\n * ```ts\n * variants: {\n variantTypesCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'customField',\n label: 'Custom Field',\n type: 'text',\n },\n ],\n })\n }\n ```\n */\n variantTypesCollectionOverride?: CollectionOverride\n}\n\nexport type ProductsConfig = {\n /**\n * Override the default products collection. If you override the collection, you should ensure it has the required fields for products or re-use the default fields.\n *\n * @example\n *\n * ```ts\n products: {\n productsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'notes',\n label: 'Notes',\n type: 'textarea',\n },\n ],\n })\n }\n ```\n */\n productsCollectionOverride?: CollectionOverride\n /**\n * Customise the validation used for checking products or variants before a transaction is created or a payment can be confirmed.\n */\n validation?: ProductsValidation\n /**\n * Enable variants and provide configuration for the variant collections.\n *\n * Defaults to true.\n */\n variants?: boolean | VariantsConfig\n}\n\nexport type OrdersConfig = {\n /**\n * Override the default orders collection. If you override the collection, you should ensure it has the required fields for orders or re-use the default fields.\n *\n * @example\n *\n * ```ts\n orders: {\n ordersCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'notes',\n label: 'Notes',\n type: 'textarea',\n },\n ],\n })\n }\n ```\n */\n ordersCollectionOverride?: CollectionOverride\n}\n\nexport type TransactionsConfig = {\n /**\n * Override the default transactions collection. If you override the collection, you should ensure it has the required fields for transactions or re-use the default fields.\n *\n * @example\n *\n * ```ts\n transactions: {\n transactionsCollectionOverride: ({ defaultCollection }) => ({\n ...defaultCollection,\n fields: [\n ...defaultCollection.fields,\n {\n name: 'notes',\n label: 'Notes',\n type: 'textarea',\n },\n ],\n })\n }\n ```\n */\n transactionsCollectionOverride?: CollectionOverride\n}\n\nexport type CustomQuery = {\n depth?: number\n select?: SelectType\n where?: Where\n}\n\nexport type PaymentsConfig = {\n paymentMethods?: PaymentAdapter[]\n productsQuery?: CustomQuery\n variantsQuery?: CustomQuery\n}\n\nexport type CountryType = {\n /**\n * A user friendly name for the country.\n */\n label: string\n /**\n * The ISO 3166-1 alpha-2 country code.\n * @example 'US'\n */\n value: string\n}\n\n/**\n * Configuration for the addresses used by the Ecommerce plugin. Use this to override the default collection or fields used throughout\n */\ntype AddressesConfig = {\n /**\n * Override the default addresses collection. If you override the collection, you should ensure it has the required fields for addresses or re-use the default fields.\n *\n * @example\n * ```ts\n * addressesCollectionOverride: (defaultCollection) => {\n * return {\n * ...defaultCollection,\n * fields: [\n * ...defaultCollection.fields,\n * // add custom fields here\n * ],\n * }\n * }\n * ```\n */\n addressesCollectionOverride?: CollectionOverride\n /**\n * These fields will be applied to all locations where addresses are used, such as Orders and Transactions. Preferred use over the collectionOverride config.\n */\n addressFields?: FieldsOverride\n /**\n * Provide an array of countries to support for addresses. This will be used in the admin interface to provide a select field of countries.\n *\n * Defaults to a set of commonly used countries.\n *\n * @example\n * ```\n * [\n { label: 'United States', value: 'US' },\n { label: 'Canada', value: 'CA' },\n ]\n */\n supportedCountries?: CountryType[]\n}\n\nexport type CustomersConfig = {\n /**\n * Slug of the customers collection, defaults to 'users'.\n * This is used to link carts and orders to customers.\n */\n slug: string\n}\n\nexport type CartsConfig = {\n cartsCollectionOverride?: CollectionOverride\n}\n\nexport type InventoryConfig = {\n /**\n * Override the default field used to track inventory levels. Defaults to 'inventory'.\n */\n fieldName?: string\n}\n\nexport type CurrenciesConfig = {\n /**\n * Defaults to the first supported currency.\n *\n * @example 'USD'\n */\n defaultCurrency: string\n /**\n *\n */\n supportedCurrencies: Currency[]\n}\n\n/**\n * A function that validates a product or variant before a transaction is created or completed.\n * This should throw an error if validation fails as it will be caught by the function calling it.\n */\nexport type ProductsValidation = (args: {\n /**\n * The full currencies config, allowing you to check against supported currencies and their settings.\n */\n currenciesConfig?: CurrenciesConfig\n /**\n * The ISO 4217 currency code being usen in this transaction.\n */\n currency?: string\n /**\n * The full product data.\n */\n product: TypedCollection['products']\n /**\n * Quantity to check the inventory amount against.\n */\n quantity: number\n /**\n * The full variant data, if a variant was selected for the product otherwise it will be undefined.\n */\n variant?: TypedCollection['variants']\n}) => Promise<void> | void\n\n/**\n * A map of collection slugs used by the Ecommerce plugin.\n * Provides an easy way to track the slugs of collections even when they are overridden.\n */\nexport type CollectionSlugMap = {\n addresses: string\n carts: string\n customers: string\n orders: string\n products: string\n transactions: string\n variantOptions: string\n variants: string\n variantTypes: string\n}\n\n/**\n * Access control functions used throughout the Ecommerce plugin.\n * You must provide these when configuring the plugin.\n *\n * @example\n *\n * ```ts\n * access: {\n adminOnly,\n adminOnlyFieldAccess,\n adminOrCustomerOwner,\n adminOrPublishedStatus,\n customerOnlyFieldAccess,\n }\n ```\n */\nexport type AccessConfig = {\n /**\n * Limited to only admin users.\n */\n adminOnly: Access\n /**\n * Limited to only admin users, specifically for Field level access control.\n */\n adminOnlyFieldAccess: FieldAccess\n /**\n * Is the owner of the document via the `customer` field or is an admin.\n */\n adminOrCustomerOwner: Access\n /**\n * The document status is published or user is admin.\n */\n adminOrPublishedStatus: Access\n /**\n * Authenticated users only. Defaults to the example function.\n *\n * @example\n * anyUser: ({ req }) => !!req?.user\n */\n authenticatedOnly?: Access\n /**\n * Limited to customers only, specifically for Field level access control.\n */\n customerOnlyFieldAccess: FieldAccess\n /**\n * Entirely public access. Defaults to the example function.\n *\n * @example\n * publicAccess: () => true\n */\n publicAccess?: Access\n}\n\nexport type EcommercePluginConfig = {\n /**\n * Customise the access control for the plugin.\n *\n * @example\n * ```ts\n * ```\n */\n access: AccessConfig\n /**\n * Enable the addresses collection to allow customers, transactions and orders to have multiple addresses for shipping and billing. Accepts an override to customise the addresses collection.\n * Defaults to supporting a default set of countries.\n */\n addresses?: AddressesConfig | boolean\n /**\n * Configure the target collection used for carts.\n *\n * Defaults to true.\n */\n carts?: boolean | CartsConfig\n /**\n * Configure supported currencies and default settings.\n *\n * Defaults to supporting USD.\n */\n currencies?: CurrenciesConfig\n /**\n * Configure the target collection used for customers.\n *\n * @example\n * ```ts\n * customers: {\n * slug: 'users', // default\n * }\n *\n */\n customers: CustomersConfig\n /**\n * Enable tracking of inventory for products and variants. Accepts a config object to override the default collection settings.\n *\n * Defaults to true.\n */\n inventory?: boolean | InventoryConfig\n /**\n * Enables orders and accepts a config object to override the default collection settings.\n *\n * Defaults to true.\n */\n orders?: boolean | OrdersConfig\n /**\n * Enable tracking of payments. Accepts a config object to override the default collection settings.\n *\n * Defaults to true when the paymentMethods array is provided.\n */\n payments?: PaymentsConfig\n /**\n * Enables products and variants. Accepts a config object to override the product collection and each variant collection type.\n *\n * Defaults to true.\n */\n products?: boolean | ProductsConfig\n /**\n * Enable tracking of transactions. Accepts a config object to override the default collection settings.\n *\n * Defaults to true when the paymentMethods array is provided.\n */\n transactions?: boolean | TransactionsConfig\n}\n\nexport type SanitizedEcommercePluginConfig = {\n access: Required<AccessConfig>\n addresses: { addressFields: Field[] } & Omit<AddressesConfig, 'addressFields'>\n currencies: Required<CurrenciesConfig>\n inventory?: InventoryConfig\n payments: {\n paymentMethods: [] | PaymentAdapter[]\n }\n} & Omit<\n Required<EcommercePluginConfig>,\n 'access' | 'addresses' | 'currencies' | 'inventory' | 'payments'\n>\n"],"names":[],"mappings":"AA+qBA,WAWC"}
@@ -0,0 +1,12 @@
1
+ import type { DefaultCellComponentProps, TypedCollection } from 'payload';
2
+ import type { CurrenciesConfig, Currency } from '../../types.js';
3
+ type Props = {
4
+ cellData?: number;
5
+ currenciesConfig: CurrenciesConfig;
6
+ currency?: Currency;
7
+ path: string;
8
+ rowData: Partial<TypedCollection['products']>;
9
+ } & DefaultCellComponentProps;
10
+ export declare const PriceCell: React.FC<Props>;
11
+ export {};
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceCell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAIhE,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAA;CAC9C,GAAG,yBAAyB,CAAA;AAE7B,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA+BrC,CAAA"}
@@ -0,0 +1,38 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useTranslation } from '@payloadcms/ui';
4
+ import { convertFromBaseValue } from '../utilities.js';
5
+ export const PriceCell = (args)=>{
6
+ const { t } = useTranslation();
7
+ const { cellData, currenciesConfig, currency: currencyFromProps, rowData } = args;
8
+ const currency = currencyFromProps || currenciesConfig.supportedCurrencies[0];
9
+ if (!currency) {
10
+ // @ts-expect-error - plugin translations are not typed yet
11
+ return /*#__PURE__*/ _jsx("span", {
12
+ children: t('plugin-ecommerce:currencyNotSet')
13
+ });
14
+ }
15
+ if ((!cellData || typeof cellData !== 'number') && 'enableVariants' in rowData && rowData.enableVariants) {
16
+ // @ts-expect-error - plugin translations are not typed yet
17
+ return /*#__PURE__*/ _jsx("span", {
18
+ children: t('plugin-ecommerce:priceSetInVariants')
19
+ });
20
+ }
21
+ if (!cellData) {
22
+ // @ts-expect-error - plugin translations are not typed yet
23
+ return /*#__PURE__*/ _jsx("span", {
24
+ children: t('plugin-ecommerce:priceNotSet')
25
+ });
26
+ }
27
+ return /*#__PURE__*/ _jsxs("span", {
28
+ children: [
29
+ currency.symbol,
30
+ convertFromBaseValue({
31
+ baseValue: cellData,
32
+ currency
33
+ })
34
+ ]
35
+ });
36
+ };
37
+
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/PriceCell/index.tsx"],"sourcesContent":["'use client'\nimport type { DefaultCellComponentProps, TypedCollection } from 'payload'\n\nimport { useTranslation } from '@payloadcms/ui'\n\nimport type { CurrenciesConfig, Currency } from '../../types.js'\n\nimport { convertFromBaseValue } from '../utilities.js'\n\ntype Props = {\n cellData?: number\n currenciesConfig: CurrenciesConfig\n currency?: Currency\n path: string\n rowData: Partial<TypedCollection['products']>\n} & DefaultCellComponentProps\n\nexport const PriceCell: React.FC<Props> = (args) => {\n const { t } = useTranslation()\n const { cellData, currenciesConfig, currency: currencyFromProps, rowData } = args\n\n const currency = currencyFromProps || currenciesConfig.supportedCurrencies[0]\n\n if (!currency) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:currencyNotSet')}</span>\n }\n\n if (\n (!cellData || typeof cellData !== 'number') &&\n 'enableVariants' in rowData &&\n rowData.enableVariants\n ) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:priceSetInVariants')}</span>\n }\n\n if (!cellData) {\n // @ts-expect-error - plugin translations are not typed yet\n return <span>{t('plugin-ecommerce:priceNotSet')}</span>\n }\n\n return (\n <span>\n {currency.symbol}\n {convertFromBaseValue({ baseValue: cellData, currency })}\n </span>\n )\n}\n"],"names":["useTranslation","convertFromBaseValue","PriceCell","args","t","cellData","currenciesConfig","currency","currencyFromProps","rowData","supportedCurrencies","span","enableVariants","symbol","baseValue"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,oBAAoB,QAAQ,kBAAiB;AAUtD,OAAO,MAAMC,YAA6B,CAACC;IACzC,MAAM,EAAEC,CAAC,EAAE,GAAGJ;IACd,MAAM,EAAEK,QAAQ,EAAEC,gBAAgB,EAAEC,UAAUC,iBAAiB,EAAEC,OAAO,EAAE,GAAGN;IAE7E,MAAMI,WAAWC,qBAAqBF,iBAAiBI,mBAAmB,CAAC,EAAE;IAE7E,IAAI,CAACH,UAAU;QACb,2DAA2D;QAC3D,qBAAO,KAACI;sBAAMP,EAAE;;IAClB;IAEA,IACE,AAAC,CAAA,CAACC,YAAY,OAAOA,aAAa,QAAO,KACzC,oBAAoBI,WACpBA,QAAQG,cAAc,EACtB;QACA,2DAA2D;QAC3D,qBAAO,KAACD;sBAAMP,EAAE;;IAClB;IAEA,IAAI,CAACC,UAAU;QACb,2DAA2D;QAC3D,qBAAO,KAACM;sBAAMP,EAAE;;IAClB;IAEA,qBACE,MAACO;;YACEJ,SAASM,MAAM;YACfZ,qBAAqB;gBAAEa,WAAWT;gBAAUE;YAAS;;;AAG5D,EAAC"}
@@ -0,0 +1,17 @@
1
+ import type { StaticDescription, StaticLabel } from 'payload';
2
+ import type { Currency } from '../../types.js';
3
+ interface Props {
4
+ currency?: Currency;
5
+ description?: StaticDescription;
6
+ disabled?: boolean;
7
+ error?: string;
8
+ id?: string;
9
+ label?: StaticLabel;
10
+ path: string;
11
+ placeholder?: string;
12
+ readOnly?: boolean;
13
+ supportedCurrencies: Currency[];
14
+ }
15
+ export declare const FormattedInput: React.FC<Props>;
16
+ export {};
17
+ //# sourceMappingURL=FormattedInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormattedInput.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceInput/FormattedInput.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAK9C,UAAU,KAAK;IACb,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,mBAAmB,EAAE,QAAQ,EAAE,CAAA;CAChC;AAID,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA0I1C,CAAA"}
@@ -0,0 +1,146 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldDescription, FieldLabel, useField, useFormFields } from '@payloadcms/ui';
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
+ import { USD } from '../../currencies/index.js';
6
+ import { convertFromBaseValue, convertToBaseValue } from '../utilities.js';
7
+ const baseClass = 'formattedPrice';
8
+ export const FormattedInput = ({ id: idFromProps, currency: currencyFromProps, description, disabled = false, label, path, placeholder = '0.00', readOnly, supportedCurrencies })=>{
9
+ const { setValue, value } = useField({
10
+ path
11
+ });
12
+ const [displayValue, setDisplayValue] = useState('');
13
+ const inputRef = useRef(null);
14
+ const isFirstRender = useRef(true);
15
+ const debounceTimer = useRef(null);
16
+ const parentPath = path.split('.').slice(0, -1).join('.');
17
+ const currencyPath = parentPath ? `${parentPath}.currency` : 'currency';
18
+ const currencyFromSelectField = useFormFields(([fields, _])=>fields[currencyPath]);
19
+ const currencyCode = currencyFromProps?.code ?? currencyFromSelectField?.value;
20
+ const id = idFromProps || path;
21
+ const currency = useMemo(()=>{
22
+ if (currencyCode && supportedCurrencies) {
23
+ const foundCurrency = supportedCurrencies.find((supportedCurrency)=>supportedCurrency.code === currencyCode);
24
+ return foundCurrency ?? supportedCurrencies[0] ?? USD;
25
+ }
26
+ return supportedCurrencies[0] ?? USD;
27
+ }, [
28
+ currencyCode,
29
+ supportedCurrencies
30
+ ]);
31
+ useEffect(()=>{
32
+ if (isFirstRender.current) {
33
+ isFirstRender.current = false;
34
+ if (value === undefined || value === null) {
35
+ setDisplayValue('');
36
+ } else {
37
+ setDisplayValue(convertFromBaseValue({
38
+ baseValue: value,
39
+ currency
40
+ }));
41
+ }
42
+ }
43
+ }, [
44
+ currency,
45
+ value,
46
+ currencyFromProps
47
+ ]);
48
+ const updateValue = useCallback((inputValue)=>{
49
+ if (inputValue === '') {
50
+ setValue(null);
51
+ return;
52
+ }
53
+ const baseValue = convertToBaseValue({
54
+ currency,
55
+ displayValue: inputValue
56
+ });
57
+ setValue(baseValue);
58
+ }, [
59
+ currency,
60
+ setValue
61
+ ]);
62
+ const handleInputChange = useCallback((e)=>{
63
+ const inputValue = e.target.value;
64
+ if (!/^\d*(?:\.\d*)?$/.test(inputValue) && inputValue !== '') {
65
+ return;
66
+ }
67
+ setDisplayValue(inputValue);
68
+ // Clear any existing timer
69
+ if (debounceTimer.current) {
70
+ clearTimeout(debounceTimer.current);
71
+ }
72
+ // Only update the base value after a delay to avoid formatting while typing
73
+ debounceTimer.current = setTimeout(()=>{
74
+ updateValue(inputValue);
75
+ }, 500);
76
+ }, [
77
+ updateValue,
78
+ setDisplayValue
79
+ ]);
80
+ const handleInputBlur = useCallback(()=>{
81
+ if (displayValue === '') {
82
+ return;
83
+ }
84
+ // Clear any pending debounce
85
+ if (debounceTimer.current) {
86
+ clearTimeout(debounceTimer.current);
87
+ debounceTimer.current = null;
88
+ }
89
+ const baseValue = convertToBaseValue({
90
+ currency,
91
+ displayValue
92
+ });
93
+ const formattedValue = convertFromBaseValue({
94
+ baseValue,
95
+ currency
96
+ });
97
+ if (value != baseValue) {
98
+ setValue(baseValue);
99
+ }
100
+ setDisplayValue(formattedValue);
101
+ }, [
102
+ currency,
103
+ displayValue,
104
+ setValue,
105
+ value
106
+ ]);
107
+ return /*#__PURE__*/ _jsxs("div", {
108
+ className: `field-type number ${baseClass}`,
109
+ children: [
110
+ label && /*#__PURE__*/ _jsx(FieldLabel, {
111
+ as: "label",
112
+ htmlFor: id,
113
+ label: label
114
+ }),
115
+ /*#__PURE__*/ _jsxs("div", {
116
+ className: `${baseClass}Container`,
117
+ children: [
118
+ /*#__PURE__*/ _jsx("div", {
119
+ className: `${baseClass}CurrencySymbol`,
120
+ children: /*#__PURE__*/ _jsx("span", {
121
+ children: currency.symbol
122
+ })
123
+ }),
124
+ /*#__PURE__*/ _jsx("input", {
125
+ className: `${baseClass}Input`,
126
+ disabled: disabled || readOnly,
127
+ id: id,
128
+ onBlur: handleInputBlur,
129
+ onChange: handleInputChange,
130
+ placeholder: placeholder,
131
+ ref: inputRef,
132
+ type: "text",
133
+ value: displayValue
134
+ })
135
+ ]
136
+ }),
137
+ /*#__PURE__*/ _jsx(FieldDescription, {
138
+ className: `${baseClass}Description`,
139
+ description: description,
140
+ path: path
141
+ })
142
+ ]
143
+ });
144
+ };
145
+
146
+ //# sourceMappingURL=FormattedInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/PriceInput/FormattedInput.tsx"],"sourcesContent":["'use client'\n\nimport type { StaticDescription, StaticLabel } from 'payload'\n\nimport { FieldDescription, FieldLabel, useField, useFormFields } from '@payloadcms/ui'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { Currency } from '../../types.js'\n\nimport { USD } from '../../currencies/index.js'\nimport { convertFromBaseValue, convertToBaseValue } from '../utilities.js'\n\ninterface Props {\n currency?: Currency\n description?: StaticDescription\n disabled?: boolean\n error?: string\n id?: string\n label?: StaticLabel\n path: string\n placeholder?: string\n readOnly?: boolean\n supportedCurrencies: Currency[]\n}\n\nconst baseClass = 'formattedPrice'\n\nexport const FormattedInput: React.FC<Props> = ({\n id: idFromProps,\n currency: currencyFromProps,\n description,\n disabled = false,\n label,\n path,\n placeholder = '0.00',\n readOnly,\n supportedCurrencies,\n}) => {\n const { setValue, value } = useField<number>({ path })\n const [displayValue, setDisplayValue] = useState<string>('')\n\n const inputRef = useRef<HTMLInputElement>(null)\n const isFirstRender = useRef(true)\n const debounceTimer = useRef<NodeJS.Timeout | null>(null)\n\n const parentPath = path.split('.').slice(0, -1).join('.')\n const currencyPath = parentPath ? `${parentPath}.currency` : 'currency'\n\n const currencyFromSelectField = useFormFields(([fields, _]) => fields[currencyPath])\n\n const currencyCode = currencyFromProps?.code ?? (currencyFromSelectField?.value as string)\n const id = idFromProps || path\n\n const currency = useMemo<Currency>(() => {\n if (currencyCode && supportedCurrencies) {\n const foundCurrency = supportedCurrencies.find(\n (supportedCurrency) => supportedCurrency.code === currencyCode,\n )\n\n return foundCurrency ?? supportedCurrencies[0] ?? USD\n }\n\n return supportedCurrencies[0] ?? USD\n }, [currencyCode, supportedCurrencies])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n\n if (value === undefined || value === null) {\n setDisplayValue('')\n } else {\n setDisplayValue(convertFromBaseValue({ baseValue: value, currency }))\n }\n }\n }, [currency, value, currencyFromProps])\n\n const updateValue = useCallback(\n (inputValue: string) => {\n if (inputValue === '') {\n setValue(null)\n\n return\n }\n\n const baseValue = convertToBaseValue({ currency, displayValue: inputValue })\n\n setValue(baseValue)\n },\n [currency, setValue],\n )\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value\n\n if (!/^\\d*(?:\\.\\d*)?$/.test(inputValue) && inputValue !== '') {\n return\n }\n\n setDisplayValue(inputValue)\n\n // Clear any existing timer\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current)\n }\n\n // Only update the base value after a delay to avoid formatting while typing\n debounceTimer.current = setTimeout(() => {\n updateValue(inputValue)\n }, 500)\n },\n [updateValue, setDisplayValue],\n )\n\n const handleInputBlur = useCallback(() => {\n if (displayValue === '') {\n return\n }\n\n // Clear any pending debounce\n if (debounceTimer.current) {\n clearTimeout(debounceTimer.current)\n debounceTimer.current = null\n }\n\n const baseValue = convertToBaseValue({ currency, displayValue })\n const formattedValue = convertFromBaseValue({ baseValue, currency })\n\n if (value != baseValue) {\n setValue(baseValue)\n }\n\n setDisplayValue(formattedValue)\n }, [currency, displayValue, setValue, value])\n\n return (\n <div className={`field-type number ${baseClass}`}>\n {label && <FieldLabel as=\"label\" htmlFor={id} label={label} />}\n\n <div className={`${baseClass}Container`}>\n <div className={`${baseClass}CurrencySymbol`}>\n <span>{currency.symbol}</span>\n </div>\n\n {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}\n <input\n className={`${baseClass}Input`}\n disabled={disabled || readOnly}\n id={id}\n onBlur={handleInputBlur}\n onChange={handleInputChange}\n placeholder={placeholder}\n ref={inputRef}\n type=\"text\"\n value={displayValue}\n />\n </div>\n <FieldDescription\n className={`${baseClass}Description`}\n description={description}\n path={path}\n />\n </div>\n )\n}\n"],"names":["FieldDescription","FieldLabel","useField","useFormFields","useCallback","useEffect","useMemo","useRef","useState","USD","convertFromBaseValue","convertToBaseValue","baseClass","FormattedInput","id","idFromProps","currency","currencyFromProps","description","disabled","label","path","placeholder","readOnly","supportedCurrencies","setValue","value","displayValue","setDisplayValue","inputRef","isFirstRender","debounceTimer","parentPath","split","slice","join","currencyPath","currencyFromSelectField","fields","_","currencyCode","code","foundCurrency","find","supportedCurrency","current","undefined","baseValue","updateValue","inputValue","handleInputChange","e","target","test","clearTimeout","setTimeout","handleInputBlur","formattedValue","div","className","as","htmlFor","span","symbol","input","onBlur","onChange","ref","type"],"mappings":"AAAA;;AAIA,SAASA,gBAAgB,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,iBAAgB;AACtF,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAIzE,SAASC,GAAG,QAAQ,4BAA2B;AAC/C,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,kBAAiB;AAe1E,MAAMC,YAAY;AAElB,OAAO,MAAMC,iBAAkC,CAAC,EAC9CC,IAAIC,WAAW,EACfC,UAAUC,iBAAiB,EAC3BC,WAAW,EACXC,WAAW,KAAK,EAChBC,KAAK,EACLC,IAAI,EACJC,cAAc,MAAM,EACpBC,QAAQ,EACRC,mBAAmB,EACpB;IACC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGxB,SAAiB;QAAEmB;IAAK;IACpD,MAAM,CAACM,cAAcC,gBAAgB,GAAGpB,SAAiB;IAEzD,MAAMqB,WAAWtB,OAAyB;IAC1C,MAAMuB,gBAAgBvB,OAAO;IAC7B,MAAMwB,gBAAgBxB,OAA8B;IAEpD,MAAMyB,aAAaX,KAAKY,KAAK,CAAC,KAAKC,KAAK,CAAC,GAAG,CAAC,GAAGC,IAAI,CAAC;IACrD,MAAMC,eAAeJ,aAAa,GAAGA,WAAW,SAAS,CAAC,GAAG;IAE7D,MAAMK,0BAA0BlC,cAAc,CAAC,CAACmC,QAAQC,EAAE,GAAKD,MAAM,CAACF,aAAa;IAEnF,MAAMI,eAAevB,mBAAmBwB,QAASJ,yBAAyBX;IAC1E,MAAMZ,KAAKC,eAAeM;IAE1B,MAAML,WAAWV,QAAkB;QACjC,IAAIkC,gBAAgBhB,qBAAqB;YACvC,MAAMkB,gBAAgBlB,oBAAoBmB,IAAI,CAC5C,CAACC,oBAAsBA,kBAAkBH,IAAI,KAAKD;YAGpD,OAAOE,iBAAiBlB,mBAAmB,CAAC,EAAE,IAAIf;QACpD;QAEA,OAAOe,mBAAmB,CAAC,EAAE,IAAIf;IACnC,GAAG;QAAC+B;QAAchB;KAAoB;IAEtCnB,UAAU;QACR,IAAIyB,cAAce,OAAO,EAAE;YACzBf,cAAce,OAAO,GAAG;YAExB,IAAInB,UAAUoB,aAAapB,UAAU,MAAM;gBACzCE,gBAAgB;YAClB,OAAO;gBACLA,gBAAgBlB,qBAAqB;oBAAEqC,WAAWrB;oBAAOV;gBAAS;YACpE;QACF;IACF,GAAG;QAACA;QAAUU;QAAOT;KAAkB;IAEvC,MAAM+B,cAAc5C,YAClB,CAAC6C;QACC,IAAIA,eAAe,IAAI;YACrBxB,SAAS;YAET;QACF;QAEA,MAAMsB,YAAYpC,mBAAmB;YAAEK;YAAUW,cAAcsB;QAAW;QAE1ExB,SAASsB;IACX,GACA;QAAC/B;QAAUS;KAAS;IAGtB,MAAMyB,oBAAoB9C,YACxB,CAAC+C;QACC,MAAMF,aAAaE,EAAEC,MAAM,CAAC1B,KAAK;QAEjC,IAAI,CAAC,kBAAkB2B,IAAI,CAACJ,eAAeA,eAAe,IAAI;YAC5D;QACF;QAEArB,gBAAgBqB;QAEhB,2BAA2B;QAC3B,IAAIlB,cAAcc,OAAO,EAAE;YACzBS,aAAavB,cAAcc,OAAO;QACpC;QAEA,4EAA4E;QAC5Ed,cAAcc,OAAO,GAAGU,WAAW;YACjCP,YAAYC;QACd,GAAG;IACL,GACA;QAACD;QAAapB;KAAgB;IAGhC,MAAM4B,kBAAkBpD,YAAY;QAClC,IAAIuB,iBAAiB,IAAI;YACvB;QACF;QAEA,6BAA6B;QAC7B,IAAII,cAAcc,OAAO,EAAE;YACzBS,aAAavB,cAAcc,OAAO;YAClCd,cAAcc,OAAO,GAAG;QAC1B;QAEA,MAAME,YAAYpC,mBAAmB;YAAEK;YAAUW;QAAa;QAC9D,MAAM8B,iBAAiB/C,qBAAqB;YAAEqC;YAAW/B;QAAS;QAElE,IAAIU,SAASqB,WAAW;YACtBtB,SAASsB;QACX;QAEAnB,gBAAgB6B;IAClB,GAAG;QAACzC;QAAUW;QAAcF;QAAUC;KAAM;IAE5C,qBACE,MAACgC;QAAIC,WAAW,CAAC,kBAAkB,EAAE/C,WAAW;;YAC7CQ,uBAAS,KAACnB;gBAAW2D,IAAG;gBAAQC,SAAS/C;gBAAIM,OAAOA;;0BAErD,MAACsC;gBAAIC,WAAW,GAAG/C,UAAU,SAAS,CAAC;;kCACrC,KAAC8C;wBAAIC,WAAW,GAAG/C,UAAU,cAAc,CAAC;kCAC1C,cAAA,KAACkD;sCAAM9C,SAAS+C,MAAM;;;kCAIxB,KAACC;wBACCL,WAAW,GAAG/C,UAAU,KAAK,CAAC;wBAC9BO,UAAUA,YAAYI;wBACtBT,IAAIA;wBACJmD,QAAQT;wBACRU,UAAUhB;wBACV5B,aAAaA;wBACb6C,KAAKtC;wBACLuC,MAAK;wBACL1C,OAAOC;;;;0BAGX,KAAC3B;gBACC2D,WAAW,GAAG/C,UAAU,WAAW,CAAC;gBACpCM,aAAaA;gBACbG,MAAMA;;;;AAId,EAAC"}
@@ -24,5 +24,12 @@
24
24
 
25
25
  .formattedPriceInput {
26
26
  padding: 0.5rem 0.5rem 0.5rem 1.75rem;
27
+ min-width: 2rem;
28
+ width: fit-content;
29
+ max-width: 10rem;
30
+ }
31
+
32
+ .formattedPriceDescription {
33
+ max-width: 46rem;
27
34
  }
28
35
  }
@@ -0,0 +1,11 @@
1
+ import type { NumberFieldServerProps } from 'payload';
2
+ import './index.css';
3
+ import type { CurrenciesConfig, Currency } from '../../types.js';
4
+ type Props = {
5
+ currenciesConfig: CurrenciesConfig;
6
+ currency?: Currency;
7
+ path: string;
8
+ } & NumberFieldServerProps;
9
+ export declare const PriceInput: React.FC<Props>;
10
+ export {};
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceInput/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,OAAO,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAIhE,KAAK,KAAK,GAAG;IACX,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,sBAAsB,CAAA;AAE1B,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA6BtC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import './index.css';
3
+ import { FormattedInput } from './FormattedInput.js';
4
+ export const PriceInput = (args)=>{
5
+ const { clientField: { label }, currenciesConfig, currency: currencyFromProps, field, i18n: { t }, i18n, path, readOnly } = args;
6
+ const description = field.admin?.description ? typeof field.admin.description === 'function' ? field.admin.description({
7
+ i18n,
8
+ t
9
+ }) : field.admin.description : undefined;
10
+ return /*#__PURE__*/ _jsx(FormattedInput, {
11
+ currency: currencyFromProps,
12
+ description: description,
13
+ label: label,
14
+ path: path,
15
+ readOnly: readOnly,
16
+ supportedCurrencies: currenciesConfig?.supportedCurrencies
17
+ });
18
+ };
19
+
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/PriceInput/index.tsx"],"sourcesContent":["import type { NumberFieldServerProps } from 'payload'\n\nimport './index.css'\n\nimport type { CurrenciesConfig, Currency } from '../../types.js'\n\nimport { FormattedInput } from './FormattedInput.js'\n\ntype Props = {\n currenciesConfig: CurrenciesConfig\n currency?: Currency\n path: string\n} & NumberFieldServerProps\n\nexport const PriceInput: React.FC<Props> = (args) => {\n const {\n clientField: { label },\n currenciesConfig,\n currency: currencyFromProps,\n field,\n i18n: { t },\n i18n,\n path,\n readOnly,\n } = args\n\n const description = field.admin?.description\n ? typeof field.admin.description === 'function'\n ? // @ts-expect-error - weird type issue on 't' here\n field.admin.description({ i18n, t })\n : field.admin.description\n : undefined\n\n return (\n <FormattedInput\n currency={currencyFromProps}\n description={description}\n label={label}\n path={path}\n readOnly={readOnly}\n supportedCurrencies={currenciesConfig?.supportedCurrencies}\n />\n )\n}\n"],"names":["FormattedInput","PriceInput","args","clientField","label","currenciesConfig","currency","currencyFromProps","field","i18n","t","path","readOnly","description","admin","undefined","supportedCurrencies"],"mappings":";AAEA,OAAO,cAAa;AAIpB,SAASA,cAAc,QAAQ,sBAAqB;AAQpD,OAAO,MAAMC,aAA8B,CAACC;IAC1C,MAAM,EACJC,aAAa,EAAEC,KAAK,EAAE,EACtBC,gBAAgB,EAChBC,UAAUC,iBAAiB,EAC3BC,KAAK,EACLC,MAAM,EAAEC,CAAC,EAAE,EACXD,IAAI,EACJE,IAAI,EACJC,QAAQ,EACT,GAAGV;IAEJ,MAAMW,cAAcL,MAAMM,KAAK,EAAED,cAC7B,OAAOL,MAAMM,KAAK,CAACD,WAAW,KAAK,aAEjCL,MAAMM,KAAK,CAACD,WAAW,CAAC;QAAEJ;QAAMC;IAAE,KAClCF,MAAMM,KAAK,CAACD,WAAW,GACzBE;IAEJ,qBACE,KAACf;QACCM,UAAUC;QACVM,aAAaA;QACbT,OAAOA;QACPO,MAAMA;QACNC,UAAUA;QACVI,qBAAqBX,kBAAkBW;;AAG7C,EAAC"}
@@ -0,0 +1,8 @@
1
+ import type { CurrenciesConfig } from '../../types.js';
2
+ import './index.css';
3
+ type Props = {
4
+ currenciesConfig: CurrenciesConfig;
5
+ };
6
+ export declare const PriceRowLabel: React.FC<Props>;
7
+ export {};
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/PriceRowLabel/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,aAAa,CAAA;AAGpB,KAAK,KAAK,GAAG;IACX,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyCzC,CAAA"}
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRowLabel } from '@payloadcms/ui';
4
+ import { useMemo } from 'react';
5
+ import './index.css';
6
+ import { convertFromBaseValue } from '../utilities.js';
7
+ export const PriceRowLabel = (props)=>{
8
+ const { currenciesConfig } = props;
9
+ const { defaultCurrency, supportedCurrencies } = currenciesConfig;
10
+ const { data } = useRowLabel();
11
+ const currency = useMemo(()=>{
12
+ if (data.currency) {
13
+ return supportedCurrencies.find((c)=>c.code === data.currency) ?? supportedCurrencies[0];
14
+ }
15
+ const fallbackCurrency = supportedCurrencies.find((c)=>c.code === defaultCurrency);
16
+ if (fallbackCurrency) {
17
+ return fallbackCurrency;
18
+ }
19
+ return supportedCurrencies[0];
20
+ }, [
21
+ data.currency,
22
+ supportedCurrencies,
23
+ defaultCurrency
24
+ ]);
25
+ const amount = useMemo(()=>{
26
+ if (data.amount) {
27
+ return convertFromBaseValue({
28
+ baseValue: data.amount,
29
+ currency: currency
30
+ });
31
+ }
32
+ return '0';
33
+ }, [
34
+ currency,
35
+ data.amount
36
+ ]);
37
+ return /*#__PURE__*/ _jsxs("div", {
38
+ className: "priceRowLabel",
39
+ children: [
40
+ /*#__PURE__*/ _jsx("div", {
41
+ className: "priceLabel",
42
+ children: "Price:"
43
+ }),
44
+ /*#__PURE__*/ _jsxs("div", {
45
+ className: "priceValue",
46
+ children: [
47
+ /*#__PURE__*/ _jsxs("span", {
48
+ children: [
49
+ currency?.symbol,
50
+ amount
51
+ ]
52
+ }),
53
+ /*#__PURE__*/ _jsxs("span", {
54
+ children: [
55
+ "(",
56
+ data.currency,
57
+ ")"
58
+ ]
59
+ })
60
+ ]
61
+ })
62
+ ]
63
+ });
64
+ };
65
+
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/PriceRowLabel/index.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\nimport { useMemo } from 'react'\n\nimport type { CurrenciesConfig } from '../../types.js'\n\nimport './index.css'\nimport { convertFromBaseValue } from '../utilities.js'\n\ntype Props = {\n currenciesConfig: CurrenciesConfig\n}\n\nexport const PriceRowLabel: React.FC<Props> = (props) => {\n const { currenciesConfig } = props\n const { defaultCurrency, supportedCurrencies } = currenciesConfig\n\n const { data } = useRowLabel<{ amount: number; currency: string }>()\n\n const currency = useMemo(() => {\n if (data.currency) {\n return supportedCurrencies.find((c) => c.code === data.currency) ?? supportedCurrencies[0]\n }\n\n const fallbackCurrency = supportedCurrencies.find((c) => c.code === defaultCurrency)\n\n if (fallbackCurrency) {\n return fallbackCurrency\n }\n\n return supportedCurrencies[0]\n }, [data.currency, supportedCurrencies, defaultCurrency])\n\n const amount = useMemo(() => {\n if (data.amount) {\n return convertFromBaseValue({ baseValue: data.amount, currency: currency! })\n }\n\n return '0'\n }, [currency, data.amount])\n\n return (\n <div className=\"priceRowLabel\">\n <div className=\"priceLabel\">Price:</div>\n\n <div className=\"priceValue\">\n <span>\n {currency?.symbol}\n {amount}\n </span>\n <span>({data.currency})</span>\n </div>\n </div>\n )\n}\n"],"names":["useRowLabel","useMemo","convertFromBaseValue","PriceRowLabel","props","currenciesConfig","defaultCurrency","supportedCurrencies","data","currency","find","c","code","fallbackCurrency","amount","baseValue","div","className","span","symbol"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAC5C,SAASC,OAAO,QAAQ,QAAO;AAI/B,OAAO,cAAa;AACpB,SAASC,oBAAoB,QAAQ,kBAAiB;AAMtD,OAAO,MAAMC,gBAAiC,CAACC;IAC7C,MAAM,EAAEC,gBAAgB,EAAE,GAAGD;IAC7B,MAAM,EAAEE,eAAe,EAAEC,mBAAmB,EAAE,GAAGF;IAEjD,MAAM,EAAEG,IAAI,EAAE,GAAGR;IAEjB,MAAMS,WAAWR,QAAQ;QACvB,IAAIO,KAAKC,QAAQ,EAAE;YACjB,OAAOF,oBAAoBG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,KAAKC,QAAQ,KAAKF,mBAAmB,CAAC,EAAE;QAC5F;QAEA,MAAMM,mBAAmBN,oBAAoBG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKN;QAEpE,IAAIO,kBAAkB;YACpB,OAAOA;QACT;QAEA,OAAON,mBAAmB,CAAC,EAAE;IAC/B,GAAG;QAACC,KAAKC,QAAQ;QAAEF;QAAqBD;KAAgB;IAExD,MAAMQ,SAASb,QAAQ;QACrB,IAAIO,KAAKM,MAAM,EAAE;YACf,OAAOZ,qBAAqB;gBAAEa,WAAWP,KAAKM,MAAM;gBAAEL,UAAUA;YAAU;QAC5E;QAEA,OAAO;IACT,GAAG;QAACA;QAAUD,KAAKM,MAAM;KAAC;IAE1B,qBACE,MAACE;QAAIC,WAAU;;0BACb,KAACD;gBAAIC,WAAU;0BAAa;;0BAE5B,MAACD;gBAAIC,WAAU;;kCACb,MAACC;;4BACET,UAAUU;4BACVL;;;kCAEH,MAACI;;4BAAK;4BAAEV,KAAKC,QAAQ;4BAAC;;;;;;;AAI9B,EAAC"}
@@ -0,0 +1,8 @@
1
+ type Props = {
2
+ children?: React.ReactNode;
3
+ existingOptions: string[];
4
+ path: string;
5
+ };
6
+ export declare const ErrorBox: React.FC<Props>;
7
+ export {};
8
+ //# sourceMappingURL=ErrorBox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBox.d.ts","sourceRoot":"","sources":["../../../src/ui/VariantOptionsSelector/ErrorBox.tsx"],"names":[],"mappings":"AAIA,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAgBpC,CAAA"}
@@ -0,0 +1,28 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldError, useField } from '@payloadcms/ui';
4
+ export const ErrorBox = (props)=>{
5
+ const { children, path } = props;
6
+ const { errorMessage, showError } = useField({
7
+ path
8
+ });
9
+ return /*#__PURE__*/ _jsxs("div", {
10
+ className: "variantOptionsSelectorError",
11
+ children: [
12
+ /*#__PURE__*/ _jsx(FieldError, {
13
+ message: errorMessage,
14
+ path: path,
15
+ showError: showError
16
+ }),
17
+ /*#__PURE__*/ _jsx("div", {
18
+ className: [
19
+ 'variantOptionsSelectorErrorWrapper',
20
+ showError && 'showError'
21
+ ].filter(Boolean).join(' '),
22
+ children: children
23
+ })
24
+ ]
25
+ });
26
+ };
27
+
28
+ //# sourceMappingURL=ErrorBox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/VariantOptionsSelector/ErrorBox.tsx"],"sourcesContent":["'use client'\n\nimport { FieldError, useField, useTranslation } from '@payloadcms/ui'\n\ntype Props = {\n children?: React.ReactNode\n existingOptions: string[]\n path: string\n}\n\nexport const ErrorBox: React.FC<Props> = (props) => {\n const { children, path } = props\n const { errorMessage, showError } = useField<(number | string)[]>({ path })\n\n return (\n <div className=\"variantOptionsSelectorError\">\n <FieldError message={errorMessage} path={path} showError={showError} />\n <div\n className={['variantOptionsSelectorErrorWrapper', showError && 'showError']\n .filter(Boolean)\n .join(' ')}\n >\n {children}\n </div>\n </div>\n )\n}\n"],"names":["FieldError","useField","ErrorBox","props","children","path","errorMessage","showError","div","className","message","filter","Boolean","join"],"mappings":"AAAA;;AAEA,SAASA,UAAU,EAAEC,QAAQ,QAAwB,iBAAgB;AAQrE,OAAO,MAAMC,WAA4B,CAACC;IACxC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAE,GAAGF;IAC3B,MAAM,EAAEG,YAAY,EAAEC,SAAS,EAAE,GAAGN,SAA8B;QAAEI;IAAK;IAEzE,qBACE,MAACG;QAAIC,WAAU;;0BACb,KAACT;gBAAWU,SAASJ;gBAAcD,MAAMA;gBAAME,WAAWA;;0BAC1D,KAACC;gBACCC,WAAW;oBAAC;oBAAsCF,aAAa;iBAAY,CACxEI,MAAM,CAACC,SACPC,IAAI,CAAC;0BAEPT;;;;AAIT,EAAC"}
@@ -0,0 +1,13 @@
1
+ import type { SelectFieldClient } from 'payload';
2
+ type Props = {
3
+ field: Omit<SelectFieldClient, 'type'>;
4
+ label: string;
5
+ options: {
6
+ label: string;
7
+ value: number | string;
8
+ }[];
9
+ path: string;
10
+ };
11
+ export declare const OptionsSelect: React.FC<Props>;
12
+ export {};
13
+ //# sourceMappingURL=OptionsSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OptionsSelect.d.ts","sourceRoot":"","sources":["../../../src/ui/VariantOptionsSelector/OptionsSelect.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKhD,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,CAAA;IACpD,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA+DzC,CAAA"}
@@ -0,0 +1,71 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FieldLabel, ReactSelect, useField } from '@payloadcms/ui';
4
+ import { useCallback, useId, useMemo } from 'react';
5
+ export const OptionsSelect = (props)=>{
6
+ const { field: { required }, label, options: optionsFromProps, path } = props;
7
+ const { setValue, value } = useField({
8
+ path
9
+ });
10
+ const id = useId();
11
+ const selectedValue = useMemo(()=>{
12
+ if (!value || !Array.isArray(value) || value.length === 0) {
13
+ return undefined;
14
+ }
15
+ const foundOption = optionsFromProps.find((option)=>{
16
+ return value.find((item)=>item === option.value);
17
+ });
18
+ return foundOption;
19
+ }, [
20
+ optionsFromProps,
21
+ value
22
+ ]);
23
+ const handleChange = useCallback(// @ts-expect-error - TODO: Fix types
24
+ (option)=>{
25
+ if (selectedValue) {
26
+ let selectedValueIndex = -1;
27
+ const valuesWithoutSelected = [
28
+ ...value
29
+ ].filter((o, index)=>{
30
+ if (o === selectedValue.value) {
31
+ selectedValueIndex = index;
32
+ return false;
33
+ }
34
+ return true;
35
+ });
36
+ const newValues = [
37
+ ...valuesWithoutSelected
38
+ ];
39
+ newValues.splice(selectedValueIndex, 0, option.value);
40
+ setValue(newValues);
41
+ } else {
42
+ const values = [
43
+ ...value || [],
44
+ option.value
45
+ ];
46
+ setValue(values);
47
+ }
48
+ }, [
49
+ selectedValue,
50
+ setValue,
51
+ value
52
+ ]);
53
+ return /*#__PURE__*/ _jsxs("div", {
54
+ className: "variantOptionsSelectorItem",
55
+ children: [
56
+ /*#__PURE__*/ _jsx(FieldLabel, {
57
+ htmlFor: id,
58
+ label: label,
59
+ required: required
60
+ }),
61
+ /*#__PURE__*/ _jsx(ReactSelect, {
62
+ inputId: id,
63
+ onChange: handleChange,
64
+ options: optionsFromProps,
65
+ value: selectedValue
66
+ })
67
+ ]
68
+ });
69
+ };
70
+
71
+ //# sourceMappingURL=OptionsSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/VariantOptionsSelector/OptionsSelect.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClient } from 'payload'\n\nimport { FieldLabel, ReactSelect, useField, useForm } from '@payloadcms/ui'\nimport { useCallback, useId, useMemo } from 'react'\n\ntype Props = {\n field: Omit<SelectFieldClient, 'type'>\n label: string\n options: { label: string; value: number | string }[]\n path: string\n}\n\nexport const OptionsSelect: React.FC<Props> = (props) => {\n const {\n field: { required },\n label,\n options: optionsFromProps,\n path,\n } = props\n\n const { setValue, value } = useField<(number | string)[]>({ path })\n const id = useId()\n\n const selectedValue = useMemo(() => {\n if (!value || !Array.isArray(value) || value.length === 0) {\n return undefined\n }\n const foundOption = optionsFromProps.find((option) => {\n return value.find((item) => item === option.value)\n })\n\n return foundOption\n }, [optionsFromProps, value])\n\n const handleChange = useCallback(\n // @ts-expect-error - TODO: Fix types\n (option) => {\n if (selectedValue) {\n let selectedValueIndex = -1\n\n const valuesWithoutSelected = [...value].filter((o, index) => {\n if (o === selectedValue.value) {\n selectedValueIndex = index\n return false\n }\n\n return true\n })\n\n const newValues = [...valuesWithoutSelected]\n\n newValues.splice(selectedValueIndex, 0, option.value)\n\n setValue(newValues)\n } else {\n const values = [...(value || []), option.value]\n\n setValue(values)\n }\n },\n [selectedValue, setValue, value],\n )\n\n return (\n <div className=\"variantOptionsSelectorItem\">\n <FieldLabel htmlFor={id} label={label} required={required} />\n\n <ReactSelect\n inputId={id}\n onChange={handleChange}\n options={optionsFromProps}\n value={selectedValue}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","ReactSelect","useField","useCallback","useId","useMemo","OptionsSelect","props","field","required","label","options","optionsFromProps","path","setValue","value","id","selectedValue","Array","isArray","length","undefined","foundOption","find","option","item","handleChange","selectedValueIndex","valuesWithoutSelected","filter","o","index","newValues","splice","values","div","className","htmlFor","inputId","onChange"],"mappings":"AAAA;;AAIA,SAASA,UAAU,EAAEC,WAAW,EAAEC,QAAQ,QAAiB,iBAAgB;AAC3E,SAASC,WAAW,EAAEC,KAAK,EAAEC,OAAO,QAAQ,QAAO;AASnD,OAAO,MAAMC,gBAAiC,CAACC;IAC7C,MAAM,EACJC,OAAO,EAAEC,QAAQ,EAAE,EACnBC,KAAK,EACLC,SAASC,gBAAgB,EACzBC,IAAI,EACL,GAAGN;IAEJ,MAAM,EAAEO,QAAQ,EAAEC,KAAK,EAAE,GAAGb,SAA8B;QAAEW;IAAK;IACjE,MAAMG,KAAKZ;IAEX,MAAMa,gBAAgBZ,QAAQ;QAC5B,IAAI,CAACU,SAAS,CAACG,MAAMC,OAAO,CAACJ,UAAUA,MAAMK,MAAM,KAAK,GAAG;YACzD,OAAOC;QACT;QACA,MAAMC,cAAcV,iBAAiBW,IAAI,CAAC,CAACC;YACzC,OAAOT,MAAMQ,IAAI,CAAC,CAACE,OAASA,SAASD,OAAOT,KAAK;QACnD;QAEA,OAAOO;IACT,GAAG;QAACV;QAAkBG;KAAM;IAE5B,MAAMW,eAAevB,YACnB,qCAAqC;IACrC,CAACqB;QACC,IAAIP,eAAe;YACjB,IAAIU,qBAAqB,CAAC;YAE1B,MAAMC,wBAAwB;mBAAIb;aAAM,CAACc,MAAM,CAAC,CAACC,GAAGC;gBAClD,IAAID,MAAMb,cAAcF,KAAK,EAAE;oBAC7BY,qBAAqBI;oBACrB,OAAO;gBACT;gBAEA,OAAO;YACT;YAEA,MAAMC,YAAY;mBAAIJ;aAAsB;YAE5CI,UAAUC,MAAM,CAACN,oBAAoB,GAAGH,OAAOT,KAAK;YAEpDD,SAASkB;QACX,OAAO;YACL,MAAME,SAAS;mBAAKnB,SAAS,EAAE;gBAAGS,OAAOT,KAAK;aAAC;YAE/CD,SAASoB;QACX;IACF,GACA;QAACjB;QAAeH;QAAUC;KAAM;IAGlC,qBACE,MAACoB;QAAIC,WAAU;;0BACb,KAACpC;gBAAWqC,SAASrB;gBAAIN,OAAOA;gBAAOD,UAAUA;;0BAEjD,KAACR;gBACCqC,SAAStB;gBACTuB,UAAUb;gBACVf,SAASC;gBACTG,OAAOE;;;;AAIf,EAAC"}
@@ -0,0 +1,6 @@
1
+ import type { SelectFieldServerProps } from 'payload';
2
+ import './index.css';
3
+ type Props = {} & SelectFieldServerProps;
4
+ export declare const VariantOptionsSelector: React.FC<Props>;
5
+ export {};
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/VariantOptionsSelector/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAKrD,OAAO,aAAa,CAAA;AAEpB,KAAK,KAAK,GAAG,EAAE,GAAG,sBAAsB,CAAA;AAExC,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA0ElD,CAAA"}