@vitnode/core 1.2.0-canary.59 → 1.2.0-canary.61

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 (283) hide show
  1. package/dist/scripts/get-config.js +15 -0
  2. package/dist/scripts/plugin.js +188 -0
  3. package/dist/scripts/prepare-database.js +177 -0
  4. package/dist/scripts/prepare-plugins-files.js +134 -0
  5. package/dist/scripts/run-interactive-shell-command.js +21 -0
  6. package/dist/scripts/scripts.js +39 -13
  7. package/dist/scripts/shared/file-utils.js +203 -0
  8. package/dist/src/api/adapters/sso/discord.js +1 -77
  9. package/dist/src/api/adapters/sso/facebook.js +1 -76
  10. package/dist/src/api/adapters/sso/google.js +1 -87
  11. package/dist/src/api/config.js +1 -67
  12. package/dist/src/api/lib/check-plugin-id.js +1 -43
  13. package/dist/src/api/lib/cron.js +1 -22
  14. package/dist/src/api/lib/logger-middleware.js +1 -35
  15. package/dist/src/api/lib/module.js +1 -22
  16. package/dist/src/api/lib/plugin.js +1 -22
  17. package/dist/src/api/lib/route.js +1 -27
  18. package/dist/src/api/lib/with-pagination.js +1 -83
  19. package/dist/src/api/middlewares/captcha.middleware.js +1 -63
  20. package/dist/src/api/middlewares/cron-auth.middleware.js +1 -19
  21. package/dist/src/api/middlewares/global.middleware.d.ts.map +1 -1
  22. package/dist/src/api/middlewares/global.middleware.js +1 -104
  23. package/dist/src/api/middlewares/rate-limiter.middleware.js +1 -32
  24. package/dist/src/api/models/device.js +1 -61
  25. package/dist/src/api/models/email.d.ts.map +1 -1
  26. package/dist/src/api/models/email.js +1 -77
  27. package/dist/src/api/models/password.js +1 -36
  28. package/dist/src/api/models/session-admin.d.ts.map +1 -1
  29. package/dist/src/api/models/session-admin.js +1 -97
  30. package/dist/src/api/models/session.d.ts.map +1 -1
  31. package/dist/src/api/models/session.js +1 -76
  32. package/dist/src/api/models/sso.js +1 -120
  33. package/dist/src/api/models/user/get-user-by-id.js +1 -19
  34. package/dist/src/api/models/user/sign-in-with-passwords.js +1 -22
  35. package/dist/src/api/models/user/sign-up.js +1 -73
  36. package/dist/src/api/models/user.js +1 -8
  37. package/dist/src/api/modules/admin/admin.module.js +1 -19
  38. package/dist/src/api/modules/admin/advanced/advanced.admin.module.js +1 -11
  39. package/dist/src/api/modules/admin/advanced/cron/cron.admin.module.js +1 -12
  40. package/dist/src/api/modules/admin/advanced/cron/routes/get.route.js +1 -66
  41. package/dist/src/api/modules/admin/advanced/cron/routes/run.route.js +1 -95
  42. package/dist/src/api/modules/admin/debug/debug.admin.module.js +1 -10
  43. package/dist/src/api/modules/admin/debug/routes/logs.route.js +1 -94
  44. package/dist/src/api/modules/admin/routes/session.route.js +1 -47
  45. package/dist/src/api/modules/admin/users/routes/list.route.js +1 -79
  46. package/dist/src/api/modules/admin/users/routes/users.route.js +1 -84
  47. package/dist/src/api/modules/admin/users/users.admin.module.js +1 -10
  48. package/dist/src/api/modules/cron/cron/clean.cron.js +1 -24
  49. package/dist/src/api/modules/cron/cron.module.js +1 -14
  50. package/dist/src/api/modules/cron/helpers/process-cron-jobs.d.ts.map +1 -1
  51. package/dist/src/api/modules/cron/helpers/process-cron-jobs.js +1 -72
  52. package/dist/src/api/modules/cron/routes/cron.route.d.ts.map +1 -1
  53. package/dist/src/api/modules/cron/routes/cron.route.js +1 -95
  54. package/dist/src/api/modules/middleware/middleware.module.js +1 -10
  55. package/dist/src/api/modules/middleware/route.js +1 -49
  56. package/dist/src/api/modules/users/avatar-color.js +1 -43
  57. package/dist/src/api/modules/users/routes/change-password.route.js +1 -58
  58. package/dist/src/api/modules/users/routes/reset-passowrd.route.js +1 -91
  59. package/dist/src/api/modules/users/routes/session.route.js +1 -46
  60. package/dist/src/api/modules/users/routes/sign-in.route.js +1 -71
  61. package/dist/src/api/modules/users/routes/sign-out.route.js +1 -43
  62. package/dist/src/api/modules/users/routes/sign-up.route.js +1 -77
  63. package/dist/src/api/modules/users/routes/test.route.js +1 -33
  64. package/dist/src/api/modules/users/sso/routes/callback.route.js +1 -52
  65. package/dist/src/api/modules/users/sso/routes/create-url.route.js +1 -36
  66. package/dist/src/api/modules/users/sso/sso.module.js +1 -12
  67. package/dist/src/api/modules/users/users.module.js +1 -26
  68. package/dist/src/api/plugin.js +1 -15
  69. package/dist/src/app/login/page.js +1 -16
  70. package/dist/src/app/login/reset-password/page.js +1 -18
  71. package/dist/src/app/login/sso/[providerId]/page.js +1 -10
  72. package/dist/src/app/register/page.js +1 -16
  73. package/dist/src/app_admin/core/advanced/cron/page.js +1 -42
  74. package/dist/src/app_admin/core/debug/page.js +1 -45
  75. package/dist/src/app_admin/core/page.js +1 -5
  76. package/dist/src/app_admin/core/test/page.js +1 -5
  77. package/dist/src/app_admin/core/users/page.js +1 -38
  78. package/dist/src/components/avatar.js +1 -14
  79. package/dist/src/components/confirm-action/confirm-action-alert-dialog.js +1 -42
  80. package/dist/src/components/confirm-action/content.js +1 -31
  81. package/dist/src/components/date-format.js +1 -41
  82. package/dist/src/components/form/auto-form.js +1 -103
  83. package/dist/src/components/form/common/desc.js +1 -9
  84. package/dist/src/components/form/common/label.js +1 -18
  85. package/dist/src/components/form/fields/checkbox.js +1 -37
  86. package/dist/src/components/form/fields/combobox-async.js +1 -123
  87. package/dist/src/components/form/fields/combobox.js +1 -87
  88. package/dist/src/components/form/fields/input.js +1 -39
  89. package/dist/src/components/form/fields/radio-group.js +1 -50
  90. package/dist/src/components/form/fields/select.js +1 -58
  91. package/dist/src/components/form/fields/switch.js +1 -36
  92. package/dist/src/components/form/fields/textarea.js +1 -36
  93. package/dist/src/components/i18n-provider.js +1 -43
  94. package/dist/src/components/logo-vitnode.js +1 -119
  95. package/dist/src/components/switchers/langs/language-switcher.js +1 -47
  96. package/dist/src/components/switchers/themes/theme-switcher.js +1 -28
  97. package/dist/src/components/table/content.js +1 -81
  98. package/dist/src/components/table/data-table.js +1 -68
  99. package/dist/src/components/table/order-table-head.js +1 -50
  100. package/dist/src/components/table/pagination.js +1 -122
  101. package/dist/src/components/tiptap/extension.js +1 -33
  102. package/dist/src/components/tiptap/toolbar/actions/alignment-action.js +1 -91
  103. package/dist/src/components/tiptap/toolbar/actions/bold-action.js +1 -39
  104. package/dist/src/components/tiptap/toolbar/actions/headings-action.js +1 -93
  105. package/dist/src/components/tiptap/toolbar/actions/italic-action.js +1 -38
  106. package/dist/src/components/tiptap/toolbar/actions/list-action.js +1 -61
  107. package/dist/src/components/tiptap/toolbar/actions/text-format-more/text-format-more.js +1 -59
  108. package/dist/src/components/tiptap/toolbar/actions/underline-action.js +1 -38
  109. package/dist/src/components/tiptap/toolbar/actions/undo-redo-actions.js +1 -63
  110. package/dist/src/components/tiptap/toolbar/actions/utils/tooltip-shortcut.js +1 -11
  111. package/dist/src/components/tiptap/toolbar/tiptap-toolbar.js +1 -55
  112. package/dist/src/components/tiptap/toolbar/use-toolbar-editor.js +1 -5
  113. package/dist/src/components/ui/accordion.js +1 -46
  114. package/dist/src/components/ui/alert-dialog.js +1 -123
  115. package/dist/src/components/ui/alert.js +1 -39
  116. package/dist/src/components/ui/badge.js +1 -28
  117. package/dist/src/components/ui/button-client.js +1 -57
  118. package/dist/src/components/ui/button.js +1 -32
  119. package/dist/src/components/ui/card.js +1 -52
  120. package/dist/src/components/ui/checkbox.js +1 -20
  121. package/dist/src/components/ui/collapsible.js +1 -22
  122. package/dist/src/components/ui/command.js +1 -98
  123. package/dist/src/components/ui/context-menu.js +1 -140
  124. package/dist/src/components/ui/dialog.js +1 -189
  125. package/dist/src/components/ui/drawer.js +1 -83
  126. package/dist/src/components/ui/dropdown-menu.js +1 -141
  127. package/dist/src/components/ui/editor-content.js +1 -10
  128. package/dist/src/components/ui/editor.js +1 -35
  129. package/dist/src/components/ui/form.js +1 -148
  130. package/dist/src/components/ui/header-content.js +1 -30
  131. package/dist/src/components/ui/hover-card.js +1 -29
  132. package/dist/src/components/ui/input-otp.js +1 -48
  133. package/dist/src/components/ui/input.js +1 -11
  134. package/dist/src/components/ui/label.js +1 -12
  135. package/dist/src/components/ui/loader.js +1 -16
  136. package/dist/src/components/ui/menubar.js +1 -151
  137. package/dist/src/components/ui/navigation-menu.js +1 -82
  138. package/dist/src/components/ui/popover.js +1 -35
  139. package/dist/src/components/ui/progress.js +1 -19
  140. package/dist/src/components/ui/radio-group.js +1 -27
  141. package/dist/src/components/ui/scroll-area.js +1 -33
  142. package/dist/src/components/ui/select.js +1 -113
  143. package/dist/src/components/ui/separator.js +1 -14
  144. package/dist/src/components/ui/sheet.js +1 -92
  145. package/dist/src/components/ui/sidebar.js +1 -433
  146. package/dist/src/components/ui/skeleton.js +1 -10
  147. package/dist/src/components/ui/slider.js +1 -50
  148. package/dist/src/components/ui/sonner.js +1 -26
  149. package/dist/src/components/ui/switch.js +1 -16
  150. package/dist/src/components/ui/table.js +1 -63
  151. package/dist/src/components/ui/tabs.js +1 -33
  152. package/dist/src/components/ui/textarea.js +1 -10
  153. package/dist/src/components/ui/toggle-group.js +1 -45
  154. package/dist/src/components/ui/toggle.js +1 -34
  155. package/dist/src/components/ui/tooltip.js +1 -57
  156. package/dist/src/config.js +1 -4
  157. package/dist/src/database/admins.js +1 -74
  158. package/dist/src/database/cron.js +1 -22
  159. package/dist/src/database/languages.js +1 -52
  160. package/dist/src/database/logs.js +1 -34
  161. package/dist/src/database/moderators.js +1 -37
  162. package/dist/src/database/roles.js +1 -13
  163. package/dist/src/database/sessions.js +1 -60
  164. package/dist/src/database/users.js +1 -145
  165. package/dist/src/drizzle.config.js +1 -67
  166. package/dist/src/emails/default-template.js +1 -99
  167. package/dist/src/emails/reset-password.js +1 -132
  168. package/dist/src/emails/ui/button.js +1 -36
  169. package/dist/src/emails/ui/card.js +1 -39
  170. package/dist/src/hooks/use-before-unload.js +1 -30
  171. package/dist/src/hooks/use-captcha.js +1 -122
  172. package/dist/src/hooks/use-mobile.js +1 -16
  173. package/dist/src/lib/api/get-middleware-api.js +1 -13
  174. package/dist/src/lib/api/get-next-cron-run-date.js +1 -14
  175. package/dist/src/lib/api/get-next-cron-run-date.test.js +1 -55
  176. package/dist/src/lib/api/get-session-admin-api.js +1 -19
  177. package/dist/src/lib/api/get-session-api.js +1 -14
  178. package/dist/src/lib/api/should-cron-job-run.js +1 -16
  179. package/dist/src/lib/api/should-cron-job-run.test.js +1 -213
  180. package/dist/src/lib/api/validate-cron-schedule.d.ts +2 -0
  181. package/dist/src/lib/api/validate-cron-schedule.d.ts.map +1 -0
  182. package/dist/src/lib/api/validate-cron-schedule.js +1 -0
  183. package/dist/src/lib/api/validate-cron-schedule.test.d.ts +2 -0
  184. package/dist/src/lib/api/validate-cron-schedule.test.d.ts.map +1 -0
  185. package/dist/src/lib/api/validate-cron-schedule.test.js +1 -0
  186. package/dist/src/lib/colors.js +1 -140
  187. package/dist/src/lib/colors.test.js +1 -173
  188. package/dist/src/lib/config.js +1 -14
  189. package/dist/src/lib/ctrl-or-command-character.js +1 -5
  190. package/dist/src/lib/fetcher/cookie-from-string-to-object.js +1 -12
  191. package/dist/src/lib/fetcher/cookie-from-string-to-object.test.js +1 -78
  192. package/dist/src/lib/fetcher/core.js +3 -48
  193. package/dist/src/lib/fetcher/helpers-server.js +1 -18
  194. package/dist/src/lib/fetcher/helpers.js +1 -16
  195. package/dist/src/lib/fetcher/helpers.test.js +1 -37
  196. package/dist/src/lib/fetcher/types.js +1 -1
  197. package/dist/src/lib/fetcher-client.js +1 -17
  198. package/dist/src/lib/fetcher.js +1 -33
  199. package/dist/src/lib/helpers/auto-form.js +1 -98
  200. package/dist/src/lib/helpers/auto-form.test.js +1 -336
  201. package/dist/src/lib/navigation.d.ts +15 -13
  202. package/dist/src/lib/navigation.d.ts.map +1 -1
  203. package/dist/src/lib/navigation.js +1 -11
  204. package/dist/src/lib/plugin.js +1 -3
  205. package/dist/src/lib/special-characters.js +1 -4
  206. package/dist/src/lib/special-characters.test.js +1 -56
  207. package/dist/src/lib/utils.js +1 -5
  208. package/dist/src/locales/en.json +308 -0
  209. package/dist/src/tests/setup.js +1 -6
  210. package/dist/src/views/admin/layouts/admin-layout.js +1 -73
  211. package/dist/src/views/admin/layouts/sidebar/nav/item.js +1 -98
  212. package/dist/src/views/admin/layouts/sidebar/nav/nav.js +1 -60
  213. package/dist/src/views/admin/layouts/sidebar/sidebar.js +1 -28
  214. package/dist/src/views/admin/layouts/sidebar/sign-out.js +1 -14
  215. package/dist/src/views/admin/layouts/user-bar/client.js +1 -69
  216. package/dist/src/views/admin/layouts/user-bar/user-bar.js +1 -32
  217. package/dist/src/views/admin/sign-in/sign-in-admin-view.js +1 -27
  218. package/dist/src/views/admin/views/core/advanced/cron/cron-table-view.js +1 -97
  219. package/dist/src/views/admin/views/core/advanced/cron/run-action/mutation-api.js +1 -23
  220. package/dist/src/views/admin/views/core/advanced/cron/run-action/run-action.js +1 -38
  221. package/dist/src/views/admin/views/core/dashboard/dashboard-admin-view.js +1 -44
  222. package/dist/src/views/admin/views/core/debug/actions/clear-cache/clear-cache.js +1 -35
  223. package/dist/src/views/admin/views/core/debug/actions/clear-cache/mutation-api.js +1 -5
  224. package/dist/src/views/admin/views/core/debug/system-logs/actions/more/content.js +1 -281
  225. package/dist/src/views/admin/views/core/debug/system-logs/actions/more/more.js +1 -67
  226. package/dist/src/views/admin/views/core/debug/system-logs/badges/badge-status.js +1 -14
  227. package/dist/src/views/admin/views/core/debug/system-logs/badges/badge-type-log.js +1 -30
  228. package/dist/src/views/admin/views/core/debug/system-logs/system-logs-view.js +1 -96
  229. package/dist/src/views/admin/views/core/test.js +1 -161
  230. package/dist/src/views/admin/views/core/users/users-admin-view.js +1 -89
  231. package/dist/src/views/auth/password-reset/change-password-form/form.js +1 -48
  232. package/dist/src/views/auth/password-reset/change-password-form/mutation-api.js +1 -22
  233. package/dist/src/views/auth/password-reset/change-password-form/use-form.js +1 -36
  234. package/dist/src/views/auth/password-reset/form/form.js +1 -104
  235. package/dist/src/views/auth/password-reset/form/mutation-api.js +1 -21
  236. package/dist/src/views/auth/password-reset/form/use-form.js +1 -33
  237. package/dist/src/views/auth/password-reset/password-reset-view.js +1 -37
  238. package/dist/src/views/auth/sign-in/form/form.js +1 -64
  239. package/dist/src/views/auth/sign-in/form/mutation-api.js +1 -33
  240. package/dist/src/views/auth/sign-in/form/use-form.d.ts.map +1 -1
  241. package/dist/src/views/auth/sign-in/form/use-form.js +1 -38
  242. package/dist/src/views/auth/sign-in/sign-in-view.js +1 -61
  243. package/dist/src/views/auth/sign-up/components/password-input.js +1 -96
  244. package/dist/src/views/auth/sign-up/email-confirmation-view.js +1 -55
  245. package/dist/src/views/auth/sign-up/form/form.js +1 -89
  246. package/dist/src/views/auth/sign-up/form/mutation-api.js +1 -30
  247. package/dist/src/views/auth/sign-up/form/use-form.js +1 -70
  248. package/dist/src/views/auth/sign-up/sign-up-view.js +1 -65
  249. package/dist/src/views/auth/sign-up/wrapper.js +1 -22
  250. package/dist/src/views/auth/sso/buttons/client.js +1 -22
  251. package/dist/src/views/auth/sso/buttons/mutation-api.js +1 -24
  252. package/dist/src/views/auth/sso/buttons/sso-buttons.js +1 -56
  253. package/dist/src/views/auth/sso/callback/callback-sso-view.js +1 -32
  254. package/dist/src/views/auth/sso/callback/client/client.js +1 -68
  255. package/dist/src/views/auth/sso/callback/client/mutation-api.js +1 -32
  256. package/dist/src/views/error/back-button.js +1 -14
  257. package/dist/src/views/error/error-view.js +1 -58
  258. package/dist/src/views/error/global-error-view.js +1 -50
  259. package/dist/src/views/layouts/provider.js +1 -44
  260. package/dist/src/views/layouts/root-layout.js +1 -25
  261. package/dist/src/views/layouts/theme/header/header.js +1 -38
  262. package/dist/src/views/layouts/theme/header/user/auth/auth.js +1 -33
  263. package/dist/src/views/layouts/theme/header/user/auth/client.js +1 -47
  264. package/dist/src/views/layouts/theme/header/user/auth/log-out-mutation-api.js +1 -27
  265. package/dist/src/views/layouts/theme/header/user/user.js +1 -32
  266. package/dist/src/views/layouts/theme/layout.js +1 -16
  267. package/dist/src/vitnode.config.d.ts.map +1 -1
  268. package/dist/src/vitnode.config.js +1 -42
  269. package/dist/tsconfig.tsbuildinfo +1 -1
  270. package/dist/tsup.config.js +18 -0
  271. package/dist/vitest.config.d.ts.map +1 -1
  272. package/dist/vitest.config.js +49 -0
  273. package/eslint.config.mjs +2 -0
  274. package/package.json +40 -44
  275. package/dist/src/api/adapters/cron/node-cron.adapter.d.ts +0 -3
  276. package/dist/src/api/adapters/cron/node-cron.adapter.d.ts.map +0 -1
  277. package/dist/src/api/adapters/cron/node-cron.adapter.js +0 -11
  278. package/dist/src/api/adapters/email/nodemailer.d.ts +0 -10
  279. package/dist/src/api/adapters/email/nodemailer.d.ts.map +0 -1
  280. package/dist/src/api/adapters/email/nodemailer.js +0 -30
  281. package/dist/src/api/adapters/email/resend.d.ts +0 -6
  282. package/dist/src/api/adapters/email/resend.d.ts.map +0 -1
  283. package/dist/src/api/adapters/email/resend.js +0 -21
@@ -1,103 +1 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { zodResolver } from "@hookform/resolvers/zod";
4
- import { useTranslations } from "next-intl";
5
- import { useForm } from "react-hook-form";
6
- import z from "zod";
7
- import { useCaptcha } from "../../hooks/use-captcha.js";
8
- import { getDefaults, getNestedParam, getZodInputParams } from "../../lib/helpers/auto-form.js";
9
- import { Button } from "../ui/button.js";
10
- import { DialogClose, DialogFooter, useDialog } from "../ui/dialog.js";
11
- import { Form, FormField } from "../ui/form.js";
12
- export function AutoForm({ formSchema, mode, onSubmit: onSubmitProp, captcha, fields, submitButtonProps, children, ...props }) {
13
- const { isReady, getToken: getTokenCaptcha, onReset: onResetCaptcha } = useCaptcha(captcha);
14
- const { setIsDirty } = useDialog();
15
- const t = useTranslations("core.global");
16
- const jsonSchema = z.toJSONSchema(formSchema);
17
- const inputParams = getZodInputParams(jsonSchema);
18
- const form = useForm({
19
- resolver: zodResolver(formSchema),
20
- defaultValues: getDefaults(jsonSchema),
21
- mode
22
- });
23
- const onSubmit = async (values)=>{
24
- const parsedValues = formSchema.safeParse(values);
25
- if (parsedValues.success) {
26
- await onSubmitProp?.(parsedValues.data, form, {
27
- captchaToken: captcha ? await getTokenCaptcha() : ""
28
- });
29
- if (captcha) {
30
- onResetCaptcha();
31
- }
32
- }
33
- };
34
- const submitButton = /*#__PURE__*/ _jsx(Button, {
35
- disabled: !form.formState.isValid || form.formState.isSubmitting || captcha && !isReady,
36
- isLoading: form.formState.isSubmitting,
37
- ...submitButtonProps,
38
- "aria-label": submitButtonProps?.["aria-label"] ?? t("submit"),
39
- type: "submit",
40
- children: submitButtonProps?.children ?? t("submit")
41
- });
42
- return /*#__PURE__*/ _jsxs(Form, {
43
- form: form,
44
- onSubmit: onSubmit,
45
- ...props,
46
- children: [
47
- fields.map((item)=>{
48
- const params = getNestedParam(inputParams, item.id);
49
- if (!params) return null;
50
- if (!item.component && (item.label || item.description)) {
51
- return /*#__PURE__*/ _jsxs("div", {
52
- children: [
53
- item.label && /*#__PURE__*/ _jsx("span", {
54
- className: "text-xl font-semibold leading-none tracking-tight",
55
- children: item.label
56
- }),
57
- item.description && /*#__PURE__*/ _jsx("div", {
58
- className: "text-muted-foreground text-sm",
59
- children: item.description
60
- })
61
- ]
62
- }, item.id);
63
- }
64
- if (!item.component) return null;
65
- return /*#__PURE__*/ _jsx(FormField, {
66
- name: item.id,
67
- render: ({ field })=>{
68
- return /*#__PURE__*/ _jsx(_Fragment, {
69
- children: item.component({
70
- field,
71
- description: typeof params.description === "string" ? params.description : "",
72
- otherProps: {
73
- isOptional: !params.required,
74
- enum: Array.isArray(params.enum) ? params.enum : undefined,
75
- maxLength: typeof params.maxLength === "number" ? params.maxLength : undefined,
76
- minLength: typeof params.minLength === "number" ? params.minLength : undefined,
77
- pattern: typeof params.pattern === "string" ? params.pattern : undefined,
78
- type: typeof params.type === "string" ? params.type : undefined
79
- }
80
- })
81
- });
82
- }
83
- }, item.id);
84
- }),
85
- children,
86
- captcha && /*#__PURE__*/ _jsx("div", {
87
- id: "vitnode_captcha"
88
- }),
89
- setIsDirty ? /*#__PURE__*/ _jsxs(DialogFooter, {
90
- children: [
91
- /*#__PURE__*/ _jsx(DialogClose, {
92
- asChild: true,
93
- children: /*#__PURE__*/ _jsx(Button, {
94
- variant: "ghost",
95
- children: t("cancel")
96
- })
97
- }),
98
- submitButton
99
- ]
100
- }) : submitButton
101
- ]
102
- });
103
- }
1
+ "use client";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{zodResolver}from"@hookform/resolvers/zod";import{useTranslations}from"next-intl";import{useForm}from"react-hook-form";import z from"zod";import{useCaptcha}from"../../hooks/use-captcha.js";import{getDefaults,getNestedParam,getZodInputParams}from"../../lib/helpers/auto-form.js";import{Button}from"../ui/button.js";import{DialogClose,DialogFooter,useDialog}from"../ui/dialog.js";import{Form,FormField}from"../ui/form.js";export function AutoForm({formSchema,mode,onSubmit:onSubmitProp,captcha,fields,submitButtonProps,children,...props}){const{isReady,getToken:getTokenCaptcha,onReset:onResetCaptcha}=useCaptcha(captcha);const{setIsDirty}=useDialog();const t=useTranslations("core.global");const jsonSchema=z.toJSONSchema(formSchema);const inputParams=getZodInputParams(jsonSchema);const form=useForm({resolver:zodResolver(formSchema),defaultValues:getDefaults(jsonSchema),mode});const onSubmit=async values=>{const parsedValues=formSchema.safeParse(values);if(parsedValues.success){await onSubmitProp?.(parsedValues.data,form,{captchaToken:captcha?await getTokenCaptcha():""});if(captcha){onResetCaptcha()}}};const submitButton=_jsx(Button,{disabled:!form.formState.isValid||form.formState.isSubmitting||captcha&&!isReady,isLoading:form.formState.isSubmitting,...submitButtonProps,"aria-label":submitButtonProps?.["aria-label"]??t("submit"),type:"submit",children:submitButtonProps?.children??t("submit")});return _jsxs(Form,{form:form,onSubmit:onSubmit,...props,children:[fields.map(item=>{const params=getNestedParam(inputParams,item.id);if(!params)return null;if(!item.component&&(item.label||item.description)){return _jsxs("div",{children:[item.label&&_jsx("span",{className:"text-xl leading-none font-semibold tracking-tight",children:item.label}),item.description&&_jsx("div",{className:"text-muted-foreground text-sm",children:item.description})]},item.id)}if(!item.component)return null;return _jsx(FormField,{name:item.id,render:({field})=>{return _jsx(_Fragment,{children:item.component({field,description:typeof params.description==="string"?params.description:"",otherProps:{isOptional:!params.required,enum:Array.isArray(params.enum)?params.enum:undefined,maxLength:typeof params.maxLength==="number"?params.maxLength:undefined,minLength:typeof params.minLength==="number"?params.minLength:undefined,pattern:typeof params.pattern==="string"?params.pattern:undefined,type:typeof params.type==="string"?params.type:undefined}})})}},item.id)}),children,captcha&&_jsx("div",{id:"vitnode_captcha"}),setIsDirty?_jsxs(DialogFooter,{children:[_jsx(DialogClose,{asChild:true,children:_jsx(Button,{variant:"ghost",children:t("cancel")})}),submitButton]}):submitButton]})}
@@ -1,9 +1 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { cn } from "../../../lib/utils.js";
3
- export const AutoFormDesc = ({ children, className, ...props })=>{
4
- return /*#__PURE__*/ _jsx("p", {
5
- className: cn("text-muted-foreground text-sm", className),
6
- ...props,
7
- children: children
8
- });
9
- };
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{cn}from"../../../lib/utils.js";export const AutoFormDesc=({children,className,...props})=>{return _jsx("p",{className:cn("text-muted-foreground text-sm",className),...props,children:children})};
@@ -1,18 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormLabel } from "../../ui/form.js";
3
- import { cn } from "../../../lib/utils.js";
4
- export const AutoFormLabel = ({ children, labelRight, className, ...props })=>{
5
- return /*#__PURE__*/ _jsxs(FormLabel, {
6
- className: cn({
7
- "flex flex-wrap items-center": labelRight
8
- }, className),
9
- ...props,
10
- children: [
11
- children,
12
- labelRight && /*#__PURE__*/ _jsx("span", {
13
- className: "ml-auto",
14
- children: labelRight
15
- })
16
- ]
17
- });
18
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{FormLabel}from"../../ui/form.js";import{cn}from"../../../lib/utils.js";export const AutoFormLabel=({children,labelRight,className,...props})=>{return _jsxs(FormLabel,{className:cn({"flex flex-wrap items-center":labelRight},className),...props,children:[children,labelRight&&_jsx("span",{className:"ml-auto",children:labelRight})]})};
@@ -1,37 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Checkbox } from "../../ui/checkbox.js";
3
- import { FormControl, FormItem, FormMessage } from "../../ui/form.js";
4
- import { AutoFormDesc } from "../common/desc.js";
5
- import { AutoFormLabel } from "../common/label.js";
6
- export const AutoFormCheckbox = ({ label, labelRight, description, otherProps: { isOptional }, field, ...props })=>{
7
- return /*#__PURE__*/ _jsxs(FormItem, {
8
- className: "flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4",
9
- children: [
10
- /*#__PURE__*/ _jsx(FormControl, {
11
- children: /*#__PURE__*/ _jsx(Checkbox, {
12
- checked: field.value ?? false,
13
- onCheckedChange: (e)=>{
14
- field.onChange(e);
15
- props.onCheckedChange?.(e);
16
- },
17
- ...field,
18
- ...props
19
- })
20
- }),
21
- !!(label ?? description) && /*#__PURE__*/ _jsxs("div", {
22
- className: "space-y-1 leading-none",
23
- children: [
24
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
25
- isOptional: isOptional,
26
- labelRight: labelRight,
27
- children: label
28
- }),
29
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
30
- children: description
31
- }),
32
- /*#__PURE__*/ _jsx(FormMessage, {})
33
- ]
34
- })
35
- ]
36
- });
37
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Checkbox}from"../../ui/checkbox.js";import{FormControl,FormItem,FormMessage}from"../../ui/form.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormCheckbox=({label,labelRight,description,otherProps:{isOptional},field,...props})=>{return _jsxs(FormItem,{className:"flex flex-row items-start space-y-0 space-x-3 rounded-md border p-4",children:[_jsx(FormControl,{children:_jsx(Checkbox,{checked:field.value??false,onCheckedChange:e=>{field.onChange(e);props.onCheckedChange?.(e)},...field,...props})}),!!(label??description)&&_jsxs("div",{className:"space-y-1 leading-none",children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})]})};
@@ -1,123 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useQuery } from "@tanstack/react-query";
3
- import { Check, ChevronsUpDown } from "lucide-react";
4
- import { useTranslations } from "next-intl";
5
- import React from "react";
6
- import { useDebouncedCallback } from "use-debounce";
7
- import { Button } from "../../ui/button.js";
8
- import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../../ui/command.js";
9
- import { FormControl, FormItem, FormMessage } from "../../ui/form.js";
10
- import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover.js";
11
- import { cn } from "../../../lib/utils.js";
12
- import { Skeleton } from "../../ui/skeleton.js";
13
- import { AutoFormDesc } from "../common/desc.js";
14
- import { AutoFormLabel } from "../common/label.js";
15
- export const AutoFormComboboxAsync = ({ label, field, description, placeholder, className, labelRight, id, otherProps: { isOptional }, searchPlaceholder, fetchData, ...props })=>{
16
- const t = useTranslations("core.global");
17
- const [search, setSearch] = React.useState("");
18
- const { data, isLoading } = useQuery({
19
- queryKey: [
20
- id,
21
- {
22
- search
23
- }
24
- ],
25
- queryFn: async ()=>{
26
- return await fetchData({
27
- search
28
- });
29
- }
30
- });
31
- const handleChangeSearch = useDebouncedCallback((value)=>{
32
- setSearch(value);
33
- }, 500);
34
- return /*#__PURE__*/ _jsxs(FormItem, {
35
- className: "flex flex-col",
36
- children: [
37
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
38
- isOptional: isOptional,
39
- labelRight: labelRight,
40
- children: label
41
- }),
42
- /*#__PURE__*/ _jsxs(Popover, {
43
- children: [
44
- /*#__PURE__*/ _jsx(PopoverTrigger, {
45
- asChild: true,
46
- children: /*#__PURE__*/ _jsx(FormControl, {
47
- children: /*#__PURE__*/ _jsxs(Button, {
48
- "aria-label": "Combobox",
49
- className: cn("w-[200px] justify-between bg-transparent", !field.value && "text-muted-foreground", className),
50
- role: "combobox",
51
- variant: "outline",
52
- ...props,
53
- children: [
54
- field.value?.label ?? placeholder ?? t("select_option"),
55
- /*#__PURE__*/ _jsx(ChevronsUpDown, {
56
- className: "ml-2 size-4 shrink-0 opacity-50"
57
- })
58
- ]
59
- })
60
- })
61
- }),
62
- /*#__PURE__*/ _jsx(PopoverContent, {
63
- className: "w-[200px] p-0",
64
- children: /*#__PURE__*/ _jsxs(Command, {
65
- shouldFilter: false,
66
- children: [
67
- /*#__PURE__*/ _jsx(CommandInput, {
68
- onChangeCapture: (e)=>{
69
- handleChangeSearch(e.currentTarget.value);
70
- },
71
- placeholder: searchPlaceholder ?? t("search_placeholder")
72
- }),
73
- /*#__PURE__*/ _jsx(CommandList, {
74
- children: (()=>{
75
- if (isLoading) {
76
- return /*#__PURE__*/ _jsxs("div", {
77
- className: "space-y-2 p-2",
78
- children: [
79
- /*#__PURE__*/ _jsx(Skeleton, {
80
- className: "h-6 rounded-sm"
81
- }),
82
- /*#__PURE__*/ _jsx(Skeleton, {
83
- className: "h-6 rounded-sm"
84
- })
85
- ]
86
- });
87
- }
88
- if ((data ?? []).length === 0) {
89
- return /*#__PURE__*/ _jsx(CommandEmpty, {
90
- children: t("results_not_found")
91
- });
92
- }
93
- return /*#__PURE__*/ _jsx(CommandGroup, {
94
- children: (data ?? []).map(({ label, value })=>/*#__PURE__*/ _jsxs(CommandItem, {
95
- onSelect: ()=>{
96
- field.onChange({
97
- label,
98
- value
99
- });
100
- },
101
- value: label,
102
- children: [
103
- label,
104
- /*#__PURE__*/ _jsx(Check, {
105
- className: cn("ml-auto", value === field.value?.value ? "opacity-100" : "opacity-0")
106
- })
107
- ]
108
- }, value))
109
- });
110
- })()
111
- })
112
- ]
113
- })
114
- })
115
- ]
116
- }),
117
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
118
- children: description
119
- }),
120
- /*#__PURE__*/ _jsx(FormMessage, {})
121
- ]
122
- });
123
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useQuery}from"@tanstack/react-query";import{Check,ChevronsUpDown}from"lucide-react";import{useTranslations}from"next-intl";import React from"react";import{useDebouncedCallback}from"use-debounce";import{Button}from"../../ui/button.js";import{Command,CommandEmpty,CommandGroup,CommandInput,CommandItem,CommandList}from"../../ui/command.js";import{FormControl,FormItem,FormMessage}from"../../ui/form.js";import{Popover,PopoverContent,PopoverTrigger}from"../../ui/popover.js";import{cn}from"../../../lib/utils.js";import{Skeleton}from"../../ui/skeleton.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormComboboxAsync=({label,field,description,placeholder,className,labelRight,id,otherProps:{isOptional},searchPlaceholder,fetchData,...props})=>{const t=useTranslations("core.global");const[search,setSearch]=React.useState("");const{data,isLoading}=useQuery({queryKey:[id,{search}],queryFn:async()=>{return await fetchData({search})}});const handleChangeSearch=useDebouncedCallback(value=>{setSearch(value)},500);return _jsxs(FormItem,{className:"flex flex-col",children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),_jsxs(Popover,{children:[_jsx(PopoverTrigger,{asChild:true,children:_jsx(FormControl,{children:_jsxs(Button,{"aria-label":"Combobox",className:cn("w-[200px] justify-between bg-transparent",!field.value&&"text-muted-foreground",className),role:"combobox",variant:"outline",...props,children:[field.value?.label??placeholder??t("select_option"),_jsx(ChevronsUpDown,{className:"ml-2 size-4 shrink-0 opacity-50"})]})})}),_jsx(PopoverContent,{className:"w-[200px] p-0",children:_jsxs(Command,{shouldFilter:false,children:[_jsx(CommandInput,{onChangeCapture:e=>{handleChangeSearch(e.currentTarget.value)},placeholder:searchPlaceholder??t("search_placeholder")}),_jsx(CommandList,{children:(()=>{if(isLoading){return _jsxs("div",{className:"space-y-2 p-2",children:[_jsx(Skeleton,{className:"h-6 rounded-sm"}),_jsx(Skeleton,{className:"h-6 rounded-sm"})]})}if((data??[]).length===0){return _jsx(CommandEmpty,{children:t("results_not_found")})}return _jsx(CommandGroup,{children:(data??[]).map(({label,value})=>_jsxs(CommandItem,{onSelect:()=>{field.onChange({label,value})},value:label,children:[label,_jsx(Check,{className:cn("ml-auto",value===field.value?.value?"opacity-100":"opacity-0")})]},value))})})()})]})})]}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})};
@@ -1,87 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Check, ChevronsUpDown } from "lucide-react";
3
- import { useTranslations } from "next-intl";
4
- import { Button } from "../../ui/button.js";
5
- import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../../ui/command.js";
6
- import { FormControl, FormItem, FormMessage } from "../../ui/form.js";
7
- import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover.js";
8
- import { cn } from "../../../lib/utils.js";
9
- import { AutoFormDesc } from "../common/desc.js";
10
- import { AutoFormLabel } from "../common/label.js";
11
- export const AutoFormCombobox = ({ label, field, description, placeholder, className, otherProps: { enum: enumValues = [], isOptional }, labels = [], labelRight, searchPlaceholder, ...props })=>{
12
- const t = useTranslations("core.global");
13
- const values = enumValues.map((value)=>{
14
- const label = labels.find((l)=>l.value === value)?.label;
15
- return {
16
- value,
17
- label: label ?? value
18
- };
19
- });
20
- return /*#__PURE__*/ _jsxs(FormItem, {
21
- className: "flex flex-col",
22
- children: [
23
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
24
- isOptional: isOptional,
25
- labelRight: labelRight,
26
- children: label
27
- }),
28
- /*#__PURE__*/ _jsxs(Popover, {
29
- children: [
30
- /*#__PURE__*/ _jsx(PopoverTrigger, {
31
- asChild: true,
32
- children: /*#__PURE__*/ _jsx(FormControl, {
33
- children: /*#__PURE__*/ _jsxs(Button, {
34
- "aria-label": "Combobox",
35
- className: cn("w-[200px] justify-between", !field.value && "text-muted-foreground", className),
36
- role: "combobox",
37
- variant: "outline",
38
- ...props,
39
- children: [
40
- field.value ? values.find(({ value })=>value === field.value)?.label : placeholder ?? t("select_option"),
41
- /*#__PURE__*/ _jsx(ChevronsUpDown, {
42
- className: "ml-2 size-4 shrink-0 opacity-50"
43
- })
44
- ]
45
- })
46
- })
47
- }),
48
- /*#__PURE__*/ _jsx(PopoverContent, {
49
- className: "w-[200px] p-0",
50
- children: /*#__PURE__*/ _jsxs(Command, {
51
- children: [
52
- /*#__PURE__*/ _jsx(CommandInput, {
53
- placeholder: searchPlaceholder ?? t("search_placeholder")
54
- }),
55
- /*#__PURE__*/ _jsxs(CommandList, {
56
- children: [
57
- /*#__PURE__*/ _jsx(CommandEmpty, {
58
- children: t("results_not_found")
59
- }),
60
- /*#__PURE__*/ _jsx(CommandGroup, {
61
- children: values.map(({ label, value })=>/*#__PURE__*/ _jsxs(CommandItem, {
62
- onSelect: ()=>{
63
- field.onChange(value);
64
- },
65
- value: label,
66
- children: [
67
- label,
68
- /*#__PURE__*/ _jsx(Check, {
69
- className: cn("ml-auto", value === field.value ? "opacity-100" : "opacity-0")
70
- })
71
- ]
72
- }, value))
73
- })
74
- ]
75
- })
76
- ]
77
- })
78
- })
79
- ]
80
- }),
81
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
82
- children: description
83
- }),
84
- /*#__PURE__*/ _jsx(FormMessage, {})
85
- ]
86
- });
87
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Check,ChevronsUpDown}from"lucide-react";import{useTranslations}from"next-intl";import{Button}from"../../ui/button.js";import{Command,CommandEmpty,CommandGroup,CommandInput,CommandItem,CommandList}from"../../ui/command.js";import{FormControl,FormItem,FormMessage}from"../../ui/form.js";import{Popover,PopoverContent,PopoverTrigger}from"../../ui/popover.js";import{cn}from"../../../lib/utils.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormCombobox=({label,field,description,placeholder,className,otherProps:{enum:enumValues=[],isOptional},labels=[],labelRight,searchPlaceholder,...props})=>{const t=useTranslations("core.global");const values=enumValues.map(value=>{const label=labels.find(l=>l.value===value)?.label;return{value,label:label??value}});return _jsxs(FormItem,{className:"flex flex-col",children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),_jsxs(Popover,{children:[_jsx(PopoverTrigger,{asChild:true,children:_jsx(FormControl,{children:_jsxs(Button,{"aria-label":"Combobox",className:cn("w-[200px] justify-between",!field.value&&"text-muted-foreground",className),role:"combobox",variant:"outline",...props,children:[field.value?values.find(({value})=>value===field.value)?.label:placeholder??t("select_option"),_jsx(ChevronsUpDown,{className:"ml-2 size-4 shrink-0 opacity-50"})]})})}),_jsx(PopoverContent,{className:"w-[200px] p-0",children:_jsxs(Command,{children:[_jsx(CommandInput,{placeholder:searchPlaceholder??t("search_placeholder")}),_jsxs(CommandList,{children:[_jsx(CommandEmpty,{children:t("results_not_found")}),_jsx(CommandGroup,{children:values.map(({label,value})=>_jsxs(CommandItem,{onSelect:()=>{field.onChange(value)},value:label,children:[label,_jsx(Check,{className:cn("ml-auto",value===field.value?"opacity-100":"opacity-0")})]},value))})]})]})})]}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})};
@@ -1,39 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormControl, FormItem, FormMessage } from "../../ui/form.js";
3
- import { Input } from "../../ui/input.js";
4
- import { AutoFormDesc } from "../common/desc.js";
5
- import { AutoFormLabel } from "../common/label.js";
6
- export const AutoFormInput = ({ label, labelRight, description, otherProps: { isOptional, maxLength, minLength, pattern, type }, field, ...props })=>{
7
- return /*#__PURE__*/ _jsxs(FormItem, {
8
- children: [
9
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
10
- isOptional: isOptional,
11
- labelRight: labelRight,
12
- children: label
13
- }),
14
- /*#__PURE__*/ _jsx(FormControl, {
15
- children: /*#__PURE__*/ _jsx(Input, {
16
- ...field,
17
- maxLength: maxLength,
18
- minLength: minLength,
19
- onBlur: (e)=>{
20
- field.onBlur();
21
- props.onBlur?.(e);
22
- },
23
- onChange: (e)=>{
24
- field.onChange(e);
25
- props.onChange?.(e);
26
- },
27
- pattern: pattern,
28
- type: type ?? "text",
29
- value: field.value ?? "",
30
- ...props
31
- })
32
- }),
33
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
34
- children: description
35
- }),
36
- /*#__PURE__*/ _jsx(FormMessage, {})
37
- ]
38
- });
39
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{FormControl,FormItem,FormMessage}from"../../ui/form.js";import{Input}from"../../ui/input.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormInput=({label,labelRight,description,otherProps:{isOptional,maxLength,minLength,pattern,type},field,...props})=>{return _jsxs(FormItem,{children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),_jsx(FormControl,{children:_jsx(Input,{...field,maxLength:maxLength,minLength:minLength,onBlur:e=>{field.onBlur();props.onBlur?.(e)},onChange:e=>{field.onChange(e);props.onChange?.(e)},pattern:pattern,type:type??"text",value:field.value??"",...props})}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})};
@@ -1,50 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormControl, FormItem, FormLabel, FormMessage } from "../../ui/form.js";
3
- import { RadioGroup, RadioGroupItem } from "../../ui/radio-group.js";
4
- import { AutoFormDesc } from "../common/desc.js";
5
- import { AutoFormLabel } from "../common/label.js";
6
- export const AutoFormRadioGroup = ({ label, labelRight, field, description, otherProps: { enum: enumValues = [], isOptional }, labels = [], ...props })=>{
7
- const values = enumValues.map((value)=>{
8
- const label = labels.find((l)=>l.value === value)?.label;
9
- return {
10
- value,
11
- label: label ?? value
12
- };
13
- });
14
- return /*#__PURE__*/ _jsxs(FormItem, {
15
- className: "space-y-3",
16
- children: [
17
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
18
- isOptional: isOptional,
19
- labelRight: labelRight,
20
- children: label
21
- }),
22
- /*#__PURE__*/ _jsx(FormControl, {
23
- children: /*#__PURE__*/ _jsx(RadioGroup, {
24
- defaultValue: field.value,
25
- disabled: props.disabled,
26
- onValueChange: field.onChange,
27
- ...props,
28
- children: values.map(({ value, label })=>/*#__PURE__*/ _jsxs(FormItem, {
29
- className: "flex items-center space-x-3 space-y-0",
30
- children: [
31
- /*#__PURE__*/ _jsx(FormControl, {
32
- children: /*#__PURE__*/ _jsx(RadioGroupItem, {
33
- value: value
34
- })
35
- }),
36
- /*#__PURE__*/ _jsx(FormLabel, {
37
- className: "font-normal",
38
- children: label
39
- })
40
- ]
41
- }, value))
42
- })
43
- }),
44
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
45
- children: description
46
- }),
47
- /*#__PURE__*/ _jsx(FormMessage, {})
48
- ]
49
- });
50
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{FormControl,FormItem,FormLabel,FormMessage}from"../../ui/form.js";import{RadioGroup,RadioGroupItem}from"../../ui/radio-group.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormRadioGroup=({label,labelRight,field,description,otherProps:{enum:enumValues=[],isOptional},labels=[],...props})=>{const values=enumValues.map(value=>{const label=labels.find(l=>l.value===value)?.label;return{value,label:label??value}});return _jsxs(FormItem,{className:"space-y-3",children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),_jsx(FormControl,{children:_jsx(RadioGroup,{defaultValue:field.value,disabled:props.disabled,onValueChange:field.onChange,...props,children:values.map(({value,label})=>_jsxs(FormItem,{className:"flex items-center space-y-0 space-x-3",children:[_jsx(FormControl,{children:_jsx(RadioGroupItem,{value:value})}),_jsx(FormLabel,{className:"font-normal",children:label})]},value))})}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})};
@@ -1,58 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useTranslations } from "next-intl";
3
- import { FormControl, FormItem, FormMessage } from "../../ui/form.js";
4
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/select.js";
5
- import { AutoFormDesc } from "../common/desc.js";
6
- import { AutoFormLabel } from "../common/label.js";
7
- export const AutoFormSelect = ({ label, field, description, otherProps: { enum: enumValues = [], isOptional }, placeholder, labelRight, labels = [], ...props })=>{
8
- const t = useTranslations("core.global");
9
- const values = enumValues.map((value)=>{
10
- const label = labels.find((l)=>l.value === value)?.label;
11
- return {
12
- value,
13
- label: label ?? value
14
- };
15
- });
16
- const currentPlaceholder = (values ?? labels).find((l)=>l.value === field.value)?.label ?? t("select_option");
17
- return /*#__PURE__*/ _jsxs(FormItem, {
18
- className: "space-y-3",
19
- children: [
20
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
21
- isOptional: isOptional,
22
- labelRight: labelRight,
23
- children: label
24
- }),
25
- /*#__PURE__*/ _jsx(FormControl, {
26
- children: /*#__PURE__*/ _jsxs(Select, {
27
- defaultValue: field.value,
28
- disabled: props.disabled,
29
- onValueChange: (e)=>{
30
- field.onChange(e);
31
- props?.onValueChange?.(e);
32
- },
33
- ...props,
34
- children: [
35
- /*#__PURE__*/ _jsx(SelectTrigger, {
36
- ...props,
37
- children: /*#__PURE__*/ _jsx(SelectValue, {
38
- onBlur: field.onBlur,
39
- placeholder: placeholder ?? currentPlaceholder,
40
- children: currentPlaceholder
41
- })
42
- }),
43
- /*#__PURE__*/ _jsx(SelectContent, {
44
- children: values.map(({ value, label })=>/*#__PURE__*/ _jsx(SelectItem, {
45
- value: value,
46
- children: label
47
- }, value))
48
- })
49
- ]
50
- })
51
- }),
52
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
53
- children: description
54
- }),
55
- /*#__PURE__*/ _jsx(FormMessage, {})
56
- ]
57
- });
58
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useTranslations}from"next-intl";import{FormControl,FormItem,FormMessage}from"../../ui/form.js";import{Select,SelectContent,SelectItem,SelectTrigger,SelectValue}from"../../ui/select.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormSelect=({label,field,description,otherProps:{enum:enumValues=[],isOptional},placeholder,labelRight,labels=[],...props})=>{const t=useTranslations("core.global");const values=enumValues.map(value=>{const label=labels.find(l=>l.value===value)?.label;return{value,label:label??value}});const currentPlaceholder=(values??labels).find(l=>l.value===field.value)?.label??t("select_option");return _jsxs(FormItem,{className:"space-y-3",children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),_jsx(FormControl,{children:_jsxs(Select,{defaultValue:field.value,disabled:props.disabled,onValueChange:e=>{field.onChange(e);props?.onValueChange?.(e)},...props,children:[_jsx(SelectTrigger,{...props,children:_jsx(SelectValue,{onBlur:field.onBlur,placeholder:placeholder??currentPlaceholder,children:currentPlaceholder})}),_jsx(SelectContent,{children:values.map(({value,label})=>_jsx(SelectItem,{value:value,children:label},value))})]})}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})};
@@ -1,36 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormControl, FormItem } from "../../ui/form.js";
3
- import { Switch } from "../../ui/switch.js";
4
- import { AutoFormDesc } from "../common/desc.js";
5
- import { AutoFormLabel } from "../common/label.js";
6
- export const AutoFormSwitch = ({ label, field, labelRight, otherProps: { isOptional }, description, ...props })=>{
7
- return /*#__PURE__*/ _jsxs(FormItem, {
8
- className: "flex flex-row items-center justify-between rounded-lg border p-4",
9
- children: [
10
- (label ?? description) && /*#__PURE__*/ _jsxs("div", {
11
- className: "space-y-0.5",
12
- children: [
13
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
14
- className: "text-base",
15
- isOptional: isOptional,
16
- labelRight: labelRight,
17
- children: label
18
- }),
19
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
20
- children: description
21
- })
22
- ]
23
- }),
24
- /*#__PURE__*/ _jsx(FormControl, {
25
- children: /*#__PURE__*/ _jsx(Switch, {
26
- checked: field.value ?? false,
27
- onCheckedChange: (e)=>{
28
- field.onChange(e);
29
- props?.onCheckedChange?.(e);
30
- },
31
- ...props
32
- })
33
- })
34
- ]
35
- });
36
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{FormControl,FormItem}from"../../ui/form.js";import{Switch}from"../../ui/switch.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormSwitch=({label,field,labelRight,otherProps:{isOptional},description,...props})=>{return _jsxs(FormItem,{className:"flex flex-row items-center justify-between rounded-lg border p-4",children:[(label??description)&&_jsxs("div",{className:"space-y-0.5",children:[label&&_jsx(AutoFormLabel,{className:"text-base",isOptional:isOptional,labelRight:labelRight,children:label}),description&&_jsx(AutoFormDesc,{children:description})]}),_jsx(FormControl,{children:_jsx(Switch,{checked:field.value??false,onCheckedChange:e=>{field.onChange(e);props?.onCheckedChange?.(e)},...props})})]})};
@@ -1,36 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormControl, FormItem, FormMessage } from "../../ui/form.js";
3
- import { Textarea } from "../../ui/textarea.js";
4
- import { AutoFormDesc } from "../common/desc.js";
5
- import { AutoFormLabel } from "../common/label.js";
6
- export const AutoFormTextarea = ({ label, description, labelRight, otherProps: { isOptional, maxLength, minLength }, field, ...props })=>{
7
- return /*#__PURE__*/ _jsxs(FormItem, {
8
- children: [
9
- label && /*#__PURE__*/ _jsx(AutoFormLabel, {
10
- isOptional: isOptional,
11
- labelRight: labelRight,
12
- children: label
13
- }),
14
- /*#__PURE__*/ _jsx(FormControl, {
15
- children: /*#__PURE__*/ _jsx(Textarea, {
16
- maxLength: maxLength,
17
- minLength: minLength,
18
- onBlur: (e)=>{
19
- field.onBlur();
20
- props.onBlur?.(e);
21
- },
22
- onChange: (e)=>{
23
- field.onChange(e);
24
- props.onChange?.(e);
25
- },
26
- value: field.value ?? "",
27
- ...props
28
- })
29
- }),
30
- description && /*#__PURE__*/ _jsx(AutoFormDesc, {
31
- children: description
32
- }),
33
- /*#__PURE__*/ _jsx(FormMessage, {})
34
- ]
35
- });
36
- };
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{FormControl,FormItem,FormMessage}from"../../ui/form.js";import{Textarea}from"../../ui/textarea.js";import{AutoFormDesc}from"../common/desc.js";import{AutoFormLabel}from"../common/label.js";export const AutoFormTextarea=({label,description,labelRight,otherProps:{isOptional,maxLength,minLength},field,...props})=>{return _jsxs(FormItem,{children:[label&&_jsx(AutoFormLabel,{isOptional:isOptional,labelRight:labelRight,children:label}),_jsx(FormControl,{children:_jsx(Textarea,{maxLength:maxLength,minLength:minLength,onBlur:e=>{field.onBlur();props.onBlur?.(e)},onChange:e=>{field.onChange(e);props.onChange?.(e)},value:field.value??"",...props})}),description&&_jsx(AutoFormDesc,{children:description}),_jsx(FormMessage,{})]})};