@btst/stack 1.5.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.cjs +7 -1
- package/dist/api/index.d.cts +2 -2
- package/dist/api/index.d.mts +2 -2
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.mjs +7 -1
- package/dist/client/index.d.cts +1 -1
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/node_modules/.pnpm/@dnd-kit_accessibility@3.1.1_react@19.2.0/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.cjs +68 -0
- package/dist/node_modules/.pnpm/@dnd-kit_accessibility@3.1.1_react@19.2.0/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.mjs +60 -0
- package/dist/node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.cjs +3937 -0
- package/dist/node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.mjs +3907 -0
- package/dist/node_modules/.pnpm/@dnd-kit_modifiers@9.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/modifiers/dist/modifiers.esm.cjs +30 -0
- package/dist/node_modules/.pnpm/@dnd-kit_modifiers@9.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/modifiers/dist/modifiers.esm.mjs +28 -0
- package/dist/node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.cjs +675 -0
- package/dist/node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.mjs +661 -0
- package/dist/node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@19.2.0/node_modules/@dnd-kit/utilities/dist/utilities.esm.cjs +358 -0
- package/dist/node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@19.2.0/node_modules/@dnd-kit/utilities/dist/utilities.esm.mjs +332 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-tabs@1.1.13_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_865f042350eb43f3338b0fffb33f6246/node_modules/@radix-ui/react-tabs/dist/index.cjs +211 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-tabs@1.1.13_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_865f042350eb43f3338b0fffb33f6246/node_modules/@radix-ui/react-tabs/dist/index.mjs +188 -0
- package/dist/packages/better-stack/src/plugins/cms/api/plugin.cjs +3 -2
- package/dist/packages/better-stack/src/plugins/cms/api/plugin.mjs +3 -2
- package/dist/packages/better-stack/src/plugins/cms/client/components/forms/content-form.cjs +15 -15
- package/dist/packages/better-stack/src/plugins/cms/client/components/forms/content-form.mjs +16 -16
- package/dist/packages/better-stack/src/plugins/form-builder/api/plugin.cjs +588 -0
- package/dist/packages/better-stack/src/plugins/form-builder/api/plugin.mjs +586 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/forms/form-renderer.cjs +131 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/forms/form-renderer.mjs +129 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-builder-skeleton.cjs +32 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-builder-skeleton.mjs +30 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-list-skeleton.cjs +21 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-list-skeleton.mjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/submissions-skeleton.cjs +34 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/submissions-skeleton.mjs +32 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/404-page.cjs +20 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/404-page.mjs +18 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.cjs +186 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.mjs +184 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.cjs +165 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.mjs +163 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +177 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +175 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/default-error.cjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/default-error.mjs +15 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/empty-state.cjs +16 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/empty-state.mjs +14 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/page-wrapper.cjs +27 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/page-wrapper.mjs +25 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.cjs +39 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.mjs +37 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.cjs +551 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.mjs +537 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-common.cjs +36 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-common.mjs +34 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-editor.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-editor.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-list.cjs +21 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-list.mjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-submissions.cjs +19 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-submissions.mjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-toasts.cjs +14 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-toasts.mjs +12 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/index.cjs +17 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/localization/index.mjs +15 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/plugin.cjs +278 -0
- package/dist/packages/better-stack/src/plugins/form-builder/client/plugin.mjs +276 -0
- package/dist/packages/better-stack/src/plugins/form-builder/db.cjs +99 -0
- package/dist/packages/better-stack/src/plugins/form-builder/db.mjs +97 -0
- package/dist/packages/better-stack/src/plugins/form-builder/schemas.cjs +82 -0
- package/dist/packages/better-stack/src/plugins/form-builder/schemas.mjs +74 -0
- package/dist/packages/better-stack/src/plugins/form-builder/utils.cjs +37 -0
- package/dist/packages/better-stack/src/plugins/form-builder/utils.mjs +29 -0
- package/dist/packages/better-stack/src/plugins/open-api/api/generator.cjs +300 -0
- package/dist/packages/better-stack/src/plugins/open-api/api/generator.mjs +284 -0
- package/dist/packages/better-stack/src/plugins/open-api/api/plugin.cjs +115 -0
- package/dist/packages/better-stack/src/plugins/open-api/api/plugin.mjs +113 -0
- package/dist/packages/better-stack/src/plugins/open-api/db.cjs +7 -0
- package/dist/packages/better-stack/src/plugins/open-api/db.mjs +5 -0
- package/dist/packages/better-stack/src/plugins/open-api/logo.cjs +8 -0
- package/dist/packages/better-stack/src/plugins/open-api/logo.mjs +6 -0
- package/dist/packages/ui/src/components/auto-form/index.cjs +2 -12
- package/dist/packages/ui/src/components/auto-form/index.mjs +2 -9
- package/dist/packages/ui/src/components/auto-form/stepped-auto-form.cjs +377 -0
- package/dist/packages/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
- package/dist/packages/ui/src/components/auto-form/utils.cjs +1 -56
- package/dist/packages/ui/src/components/auto-form/utils.mjs +2 -56
- package/dist/packages/ui/src/components/form-builder/canvas.cjs +111 -0
- package/dist/packages/ui/src/components/form-builder/canvas.mjs +109 -0
- package/dist/packages/ui/src/components/form-builder/components/index.cjs +570 -0
- package/dist/packages/ui/src/components/form-builder/components/index.mjs +553 -0
- package/dist/packages/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
- package/dist/packages/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
- package/dist/packages/ui/src/components/form-builder/form-preview.cjs +73 -0
- package/dist/packages/ui/src/components/form-builder/form-preview.mjs +71 -0
- package/dist/packages/ui/src/components/form-builder/index.cjs +353 -0
- package/dist/packages/ui/src/components/form-builder/index.mjs +344 -0
- package/dist/packages/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
- package/dist/packages/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
- package/dist/packages/ui/src/components/form-builder/palette.cjs +52 -0
- package/dist/packages/ui/src/components/form-builder/palette.mjs +49 -0
- package/dist/packages/ui/src/components/form-builder/schema-utils.cjs +120 -0
- package/dist/packages/ui/src/components/form-builder/schema-utils.mjs +114 -0
- package/dist/packages/ui/src/components/form-builder/sortable-field.cjs +151 -0
- package/dist/packages/ui/src/components/form-builder/sortable-field.mjs +148 -0
- package/dist/packages/ui/src/components/form-builder/step-tabs.cjs +180 -0
- package/dist/packages/ui/src/components/form-builder/step-tabs.mjs +178 -0
- package/dist/packages/ui/src/components/form-builder/types.cjs +7 -0
- package/dist/packages/ui/src/components/form-builder/types.mjs +5 -0
- package/dist/packages/ui/src/components/form-builder/validation-schemas.cjs +67 -0
- package/dist/packages/ui/src/components/form-builder/validation-schemas.mjs +56 -0
- package/dist/packages/ui/src/components/tabs.cjs +70 -0
- package/dist/packages/ui/src/components/tabs.mjs +65 -0
- package/dist/packages/ui/src/lib/schema-converter.cjs +130 -0
- package/dist/packages/ui/src/lib/schema-converter.mjs +124 -0
- package/dist/plugins/api/index.d.cts +2 -2
- package/dist/plugins/api/index.d.mts +2 -2
- package/dist/plugins/api/index.d.ts +2 -2
- package/dist/plugins/blog/api/index.d.cts +1 -1
- package/dist/plugins/blog/api/index.d.mts +1 -1
- package/dist/plugins/blog/api/index.d.ts +1 -1
- package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
- package/dist/plugins/blog/client/index.d.cts +1 -1
- package/dist/plugins/blog/client/index.d.mts +1 -1
- package/dist/plugins/blog/client/index.d.ts +1 -1
- package/dist/plugins/blog/query-keys.d.cts +2 -2
- package/dist/plugins/blog/query-keys.d.mts +2 -2
- package/dist/plugins/blog/query-keys.d.ts +2 -2
- package/dist/plugins/client/index.d.cts +2 -2
- package/dist/plugins/client/index.d.mts +2 -2
- package/dist/plugins/client/index.d.ts +2 -2
- package/dist/plugins/cms/client/index.cjs +6 -0
- package/dist/plugins/cms/client/index.d.cts +6 -113
- package/dist/plugins/cms/client/index.d.mts +6 -113
- package/dist/plugins/cms/client/index.d.ts +6 -113
- package/dist/plugins/cms/client/index.mjs +1 -0
- package/dist/plugins/form-builder/api/index.cjs +7 -0
- package/dist/plugins/form-builder/api/index.d.cts +141 -0
- package/dist/plugins/form-builder/api/index.d.mts +141 -0
- package/dist/plugins/form-builder/api/index.d.ts +141 -0
- package/dist/plugins/form-builder/api/index.mjs +1 -0
- package/dist/plugins/form-builder/client/components/index.cjs +29 -0
- package/dist/plugins/form-builder/client/components/index.d.cts +93 -0
- package/dist/plugins/form-builder/client/components/index.d.mts +93 -0
- package/dist/plugins/form-builder/client/components/index.d.ts +93 -0
- package/dist/plugins/form-builder/client/components/index.mjs +18 -0
- package/dist/plugins/form-builder/client/hooks/index.cjs +19 -0
- package/dist/plugins/form-builder/client/hooks/index.d.cts +154 -0
- package/dist/plugins/form-builder/client/hooks/index.d.mts +154 -0
- package/dist/plugins/form-builder/client/hooks/index.d.ts +154 -0
- package/dist/plugins/form-builder/client/hooks/index.mjs +1 -0
- package/dist/plugins/form-builder/client/index.cjs +13 -0
- package/dist/plugins/form-builder/client/index.d.cts +381 -0
- package/dist/plugins/form-builder/client/index.d.mts +381 -0
- package/dist/plugins/form-builder/client/index.d.ts +381 -0
- package/dist/plugins/form-builder/client/index.mjs +2 -0
- package/dist/plugins/form-builder/client.css +3 -0
- package/dist/plugins/form-builder/query-keys.cjs +143 -0
- package/dist/plugins/form-builder/query-keys.d.cts +74 -0
- package/dist/plugins/form-builder/query-keys.d.mts +74 -0
- package/dist/plugins/form-builder/query-keys.d.ts +74 -0
- package/dist/plugins/form-builder/query-keys.mjs +141 -0
- package/dist/plugins/form-builder/style.css +19 -0
- package/dist/plugins/open-api/api/index.cjs +9 -0
- package/dist/plugins/open-api/api/index.d.cts +95 -0
- package/dist/plugins/open-api/api/index.d.mts +95 -0
- package/dist/plugins/open-api/api/index.d.ts +95 -0
- package/dist/plugins/open-api/api/index.mjs +2 -0
- package/dist/shared/stack.AX5nZ6A3.d.cts +86 -0
- package/dist/shared/stack.AX5nZ6A3.d.mts +86 -0
- package/dist/shared/stack.AX5nZ6A3.d.ts +86 -0
- package/dist/shared/stack.BIh2AXaW.d.cts +123 -0
- package/dist/shared/stack.BIh2AXaW.d.mts +123 -0
- package/dist/shared/stack.BIh2AXaW.d.ts +123 -0
- package/dist/shared/{stack.ByOugz9d.d.cts → stack.CSce37mX.d.cts} +15 -2
- package/dist/shared/{stack.ByOugz9d.d.mts → stack.CSce37mX.d.mts} +15 -2
- package/dist/shared/{stack.ByOugz9d.d.ts → stack.CSce37mX.d.ts} +15 -2
- package/dist/shared/stack.DzH_wcvr.d.cts +195 -0
- package/dist/shared/stack.DzH_wcvr.d.mts +195 -0
- package/dist/shared/stack.DzH_wcvr.d.ts +195 -0
- package/package.json +67 -1
- package/src/api/index.ts +14 -2
- package/src/plugins/cms/api/plugin.ts +9 -4
- package/src/plugins/cms/client/components/forms/content-form.tsx +23 -25
- package/src/plugins/cms/client/index.ts +11 -0
- package/src/plugins/form-builder/api/index.ts +1 -0
- package/src/plugins/form-builder/api/plugin.ts +776 -0
- package/src/plugins/form-builder/client/components/forms/form-renderer.tsx +253 -0
- package/src/plugins/form-builder/client/components/index.tsx +24 -0
- package/src/plugins/form-builder/client/components/loading/form-builder-skeleton.tsx +42 -0
- package/src/plugins/form-builder/client/components/loading/form-list-skeleton.tsx +25 -0
- package/src/plugins/form-builder/client/components/loading/index.tsx +3 -0
- package/src/plugins/form-builder/client/components/loading/submissions-skeleton.tsx +40 -0
- package/src/plugins/form-builder/client/components/pages/404-page.tsx +28 -0
- package/src/plugins/form-builder/client/components/pages/form-builder-page.internal.tsx +253 -0
- package/src/plugins/form-builder/client/components/pages/form-builder-page.tsx +26 -0
- package/src/plugins/form-builder/client/components/pages/form-list-page.internal.tsx +231 -0
- package/src/plugins/form-builder/client/components/pages/form-list-page.tsx +22 -0
- package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +268 -0
- package/src/plugins/form-builder/client/components/pages/submissions-page.tsx +26 -0
- package/src/plugins/form-builder/client/components/shared/default-error.tsx +30 -0
- package/src/plugins/form-builder/client/components/shared/empty-state.tsx +26 -0
- package/src/plugins/form-builder/client/components/shared/page-wrapper.tsx +32 -0
- package/src/plugins/form-builder/client/components/shared/pagination.tsx +52 -0
- package/src/plugins/form-builder/client/hooks/form-builder-hooks.tsx +799 -0
- package/src/plugins/form-builder/client/hooks/index.tsx +1 -0
- package/src/plugins/form-builder/client/index.ts +22 -0
- package/src/plugins/form-builder/client/localization/form-builder-common.ts +36 -0
- package/src/plugins/form-builder/client/localization/form-builder-editor.ts +18 -0
- package/src/plugins/form-builder/client/localization/form-builder-list.ts +17 -0
- package/src/plugins/form-builder/client/localization/form-builder-submissions.ts +17 -0
- package/src/plugins/form-builder/client/localization/form-builder-toasts.ts +10 -0
- package/src/plugins/form-builder/client/localization/index.ts +15 -0
- package/src/plugins/form-builder/client/overrides.ts +146 -0
- package/src/plugins/form-builder/client/plugin.tsx +488 -0
- package/src/plugins/form-builder/client.css +3 -0
- package/src/plugins/form-builder/db.ts +99 -0
- package/src/plugins/form-builder/query-keys.ts +198 -0
- package/src/plugins/form-builder/schemas.ts +122 -0
- package/src/plugins/form-builder/style.css +19 -0
- package/src/plugins/form-builder/types.ts +317 -0
- package/src/plugins/form-builder/utils.ts +63 -0
- package/src/plugins/open-api/api/generator.ts +433 -0
- package/src/plugins/open-api/api/index.ts +8 -0
- package/src/plugins/open-api/api/plugin.ts +243 -0
- package/src/plugins/open-api/db.ts +7 -0
- package/src/plugins/open-api/logo.ts +7 -0
- package/src/types.ts +15 -1
- package/dist/shared/{stack.DLhzx1-D.d.mts → stack.CcI4sYJP.d.cts} +1 -1
- package/dist/shared/{stack.DLhzx1-D.d.ts → stack.CcI4sYJP.d.mts} +1 -1
- package/dist/shared/{stack.DLhzx1-D.d.cts → stack.CcI4sYJP.d.ts} +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { useMemo, useState, useCallback } from 'react';
|
|
4
|
+
import AutoForm from '../auto-form/index.mjs';
|
|
5
|
+
import { buildFieldConfigFromJsonSchema } from '../auto-form/utils.mjs';
|
|
6
|
+
import { Input } from '../input.mjs';
|
|
7
|
+
import { Label } from '../label.mjs';
|
|
8
|
+
import { Button } from '../button.mjs';
|
|
9
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '../dialog.mjs';
|
|
10
|
+
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../select.mjs';
|
|
11
|
+
|
|
12
|
+
function EditFieldDialog({
|
|
13
|
+
open,
|
|
14
|
+
onOpenChange,
|
|
15
|
+
field,
|
|
16
|
+
component,
|
|
17
|
+
onUpdate,
|
|
18
|
+
steps = [],
|
|
19
|
+
allFieldIds = []
|
|
20
|
+
}) {
|
|
21
|
+
const initialValues = useMemo(() => {
|
|
22
|
+
if (!field) return { fieldName: "", props: {}, key: "" };
|
|
23
|
+
const values = { ...field.props };
|
|
24
|
+
if (Array.isArray(values.options)) {
|
|
25
|
+
values.options = values.options.join("\n");
|
|
26
|
+
}
|
|
27
|
+
return { fieldName: field.id, props: values, key: `${field.id}-${open}` };
|
|
28
|
+
}, [field, open]);
|
|
29
|
+
const [fieldNameOverride, setFieldNameOverride] = useState(null);
|
|
30
|
+
const [localPropsOverride, setLocalPropsOverride] = useState(null);
|
|
31
|
+
const [stepGroupOverride, setStepGroupOverride] = useState(null);
|
|
32
|
+
const fieldName = fieldNameOverride ?? initialValues.fieldName;
|
|
33
|
+
const localProps = localPropsOverride ?? initialValues.props;
|
|
34
|
+
const localStepGroup = stepGroupOverride ?? field?.stepGroup ?? 0;
|
|
35
|
+
const isDuplicateId = useMemo(() => {
|
|
36
|
+
if (!field || fieldName === field.id) return false;
|
|
37
|
+
return allFieldIds.some((id) => id === fieldName && id !== field.id);
|
|
38
|
+
}, [fieldName, field, allFieldIds]);
|
|
39
|
+
const [prevInitial, setPrevInitial] = useState(initialValues);
|
|
40
|
+
if (prevInitial !== initialValues) {
|
|
41
|
+
setPrevInitial(initialValues);
|
|
42
|
+
setFieldNameOverride(null);
|
|
43
|
+
setLocalPropsOverride(null);
|
|
44
|
+
setStepGroupOverride(null);
|
|
45
|
+
}
|
|
46
|
+
const formKey = initialValues.key;
|
|
47
|
+
const handleValuesChange = useCallback(
|
|
48
|
+
(values) => {
|
|
49
|
+
setLocalPropsOverride(values);
|
|
50
|
+
},
|
|
51
|
+
[]
|
|
52
|
+
);
|
|
53
|
+
const handleSave = useCallback(() => {
|
|
54
|
+
if (!field) return;
|
|
55
|
+
const props = { ...localProps };
|
|
56
|
+
if (typeof props.options === "string") {
|
|
57
|
+
props.options = props.options.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
const newId = fieldName !== field.id ? fieldName : void 0;
|
|
60
|
+
const stepGroup = stepGroupOverride !== null && stepGroupOverride !== field.stepGroup ? stepGroupOverride : void 0;
|
|
61
|
+
onUpdate(field.id, props, newId, stepGroup);
|
|
62
|
+
onOpenChange(false);
|
|
63
|
+
}, [field, localProps, fieldName, onUpdate, onOpenChange, stepGroupOverride]);
|
|
64
|
+
if (!field || !component) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const Icon = component.icon;
|
|
68
|
+
const jsonSchema = component.propertiesSchema.toJSONSchema();
|
|
69
|
+
const fieldConfig = buildFieldConfigFromJsonSchema(jsonSchema);
|
|
70
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-w-md max-h-[90vh] overflow-y-auto", children: [
|
|
71
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
72
|
+
/* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
|
|
73
|
+
Icon && /* @__PURE__ */ jsx(Icon, { className: "h-5 w-5 text-muted-foreground" }),
|
|
74
|
+
"Edit ",
|
|
75
|
+
component.label
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: "Configure the properties for this field" })
|
|
78
|
+
] }),
|
|
79
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4 py-4", children: [
|
|
80
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
81
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "field-name", children: "Field Name" }),
|
|
82
|
+
/* @__PURE__ */ jsx(
|
|
83
|
+
Input,
|
|
84
|
+
{
|
|
85
|
+
id: "field-name",
|
|
86
|
+
value: fieldName,
|
|
87
|
+
onChange: (e) => setFieldNameOverride(e.target.value),
|
|
88
|
+
placeholder: "Enter field name",
|
|
89
|
+
className: isDuplicateId ? "border-destructive focus-visible:ring-destructive" : "",
|
|
90
|
+
"aria-invalid": isDuplicateId
|
|
91
|
+
}
|
|
92
|
+
),
|
|
93
|
+
isDuplicateId ? /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: "A field with this name already exists. Please choose a different name." }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "This is the key used in the form data and JSON schema" })
|
|
94
|
+
] }),
|
|
95
|
+
steps.length > 1 && field && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
96
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "field-step", children: "Step" }),
|
|
97
|
+
/* @__PURE__ */ jsxs(
|
|
98
|
+
Select,
|
|
99
|
+
{
|
|
100
|
+
value: String(localStepGroup),
|
|
101
|
+
onValueChange: (value) => setStepGroupOverride(parseInt(value, 10)),
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsx(SelectTrigger, { id: "field-step", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select step" }) }),
|
|
104
|
+
/* @__PURE__ */ jsx(SelectContent, { children: steps.map((step, index) => /* @__PURE__ */ jsx(SelectItem, { value: String(index), children: step.title }, step.id)) })
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Which step this field belongs to" })
|
|
109
|
+
] }),
|
|
110
|
+
/* @__PURE__ */ jsx("div", { className: "border-t pt-4", children: /* @__PURE__ */ jsx(
|
|
111
|
+
AutoForm,
|
|
112
|
+
{
|
|
113
|
+
formSchema: component.propertiesSchema,
|
|
114
|
+
values: localProps,
|
|
115
|
+
onValuesChange: handleValuesChange,
|
|
116
|
+
fieldConfig,
|
|
117
|
+
className: "space-y-4"
|
|
118
|
+
},
|
|
119
|
+
formKey
|
|
120
|
+
) })
|
|
121
|
+
] }),
|
|
122
|
+
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
123
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
124
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSave, disabled: isDuplicateId, children: "Save Changes" })
|
|
125
|
+
] })
|
|
126
|
+
] }) });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { EditFieldDialog };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const steppedAutoForm = require('../auto-form/stepped-auto-form.cjs');
|
|
7
|
+
const utils = require('../auto-form/utils.cjs');
|
|
8
|
+
const button = require('../button.cjs');
|
|
9
|
+
const utils$1 = require('../../lib/utils.cjs');
|
|
10
|
+
const schemaConverter = require('../../lib/schema-converter.cjs');
|
|
11
|
+
|
|
12
|
+
function FormPreview({ schema, className, fieldComponents, defaultValues }) {
|
|
13
|
+
const [submittedValues, setSubmittedValues] = React.useState(null);
|
|
14
|
+
const zodSchema = React.useMemo(() => {
|
|
15
|
+
try {
|
|
16
|
+
if (!schema.properties || Object.keys(schema.properties).length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return schemaConverter.formSchemaToZod(schema);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Failed to parse JSON Schema:", error);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}, [schema]);
|
|
25
|
+
const mergedFieldComponents = React.useMemo(() => fieldComponents ?? {}, [fieldComponents]);
|
|
26
|
+
const fieldConfig = React.useMemo(() => {
|
|
27
|
+
try {
|
|
28
|
+
return utils.buildFieldConfigFromJsonSchema(
|
|
29
|
+
schema,
|
|
30
|
+
mergedFieldComponents
|
|
31
|
+
);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error("Failed to build field config:", error);
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}, [schema, mergedFieldComponents]);
|
|
37
|
+
const handleSubmit = (values) => {
|
|
38
|
+
setSubmittedValues(values);
|
|
39
|
+
};
|
|
40
|
+
const handleReset = () => {
|
|
41
|
+
setSubmittedValues(null);
|
|
42
|
+
};
|
|
43
|
+
if (!zodSchema) {
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils$1.cn("p-8 text-center text-muted-foreground", className), children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-lg font-medium mb-2", children: "No fields to preview" }),
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm", children: "Add some fields to your form to see a preview" })
|
|
47
|
+
] });
|
|
48
|
+
}
|
|
49
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: utils$1.cn("p-4 md:p-6", className), children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-2xl mx-auto", children: submittedValues ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
50
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
51
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-lg font-semibold", children: "Submitted Values" }),
|
|
52
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "outline", onClick: handleReset, children: "Try Again" })
|
|
53
|
+
] }),
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border bg-muted/50 p-4", children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-sm overflow-auto whitespace-pre-wrap", children: JSON.stringify(submittedValues, null, 2) }) })
|
|
55
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
56
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center mb-6", children: [
|
|
57
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-lg font-semibold", children: "Form Preview" }),
|
|
58
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Test your form and see the submitted values" })
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border bg-card p-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
61
|
+
steppedAutoForm.default,
|
|
62
|
+
{
|
|
63
|
+
formSchema: zodSchema,
|
|
64
|
+
onSubmit: handleSubmit,
|
|
65
|
+
fieldConfig,
|
|
66
|
+
values: defaultValues,
|
|
67
|
+
submitButtonText: "Submit"
|
|
68
|
+
}
|
|
69
|
+
) })
|
|
70
|
+
] }) }) });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.FormPreview = FormPreview;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState, useMemo } from 'react';
|
|
4
|
+
import SteppedAutoForm from '../auto-form/stepped-auto-form.mjs';
|
|
5
|
+
import { buildFieldConfigFromJsonSchema } from '../auto-form/utils.mjs';
|
|
6
|
+
import { Button } from '../button.mjs';
|
|
7
|
+
import { cn } from '../../lib/utils.mjs';
|
|
8
|
+
import { formSchemaToZod } from '../../lib/schema-converter.mjs';
|
|
9
|
+
|
|
10
|
+
function FormPreview({ schema, className, fieldComponents, defaultValues }) {
|
|
11
|
+
const [submittedValues, setSubmittedValues] = useState(null);
|
|
12
|
+
const zodSchema = useMemo(() => {
|
|
13
|
+
try {
|
|
14
|
+
if (!schema.properties || Object.keys(schema.properties).length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return formSchemaToZod(schema);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("Failed to parse JSON Schema:", error);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}, [schema]);
|
|
23
|
+
const mergedFieldComponents = useMemo(() => fieldComponents ?? {}, [fieldComponents]);
|
|
24
|
+
const fieldConfig = useMemo(() => {
|
|
25
|
+
try {
|
|
26
|
+
return buildFieldConfigFromJsonSchema(
|
|
27
|
+
schema,
|
|
28
|
+
mergedFieldComponents
|
|
29
|
+
);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error("Failed to build field config:", error);
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}, [schema, mergedFieldComponents]);
|
|
35
|
+
const handleSubmit = (values) => {
|
|
36
|
+
setSubmittedValues(values);
|
|
37
|
+
};
|
|
38
|
+
const handleReset = () => {
|
|
39
|
+
setSubmittedValues(null);
|
|
40
|
+
};
|
|
41
|
+
if (!zodSchema) {
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("p-8 text-center text-muted-foreground", className), children: [
|
|
43
|
+
/* @__PURE__ */ jsx("p", { className: "text-lg font-medium mb-2", children: "No fields to preview" }),
|
|
44
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "Add some fields to your form to see a preview" })
|
|
45
|
+
] });
|
|
46
|
+
}
|
|
47
|
+
return /* @__PURE__ */ jsx("div", { className: cn("p-4 md:p-6", className), children: /* @__PURE__ */ jsx("div", { className: "max-w-2xl mx-auto", children: submittedValues ? /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
48
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
49
|
+
/* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold", children: "Submitted Values" }),
|
|
50
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: handleReset, children: "Try Again" })
|
|
51
|
+
] }),
|
|
52
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-lg border bg-muted/50 p-4", children: /* @__PURE__ */ jsx("pre", { className: "text-sm overflow-auto whitespace-pre-wrap", children: JSON.stringify(submittedValues, null, 2) }) })
|
|
53
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
54
|
+
/* @__PURE__ */ jsxs("div", { className: "text-center mb-6", children: [
|
|
55
|
+
/* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold", children: "Form Preview" }),
|
|
56
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Test your form and see the submitted values" })
|
|
57
|
+
] }),
|
|
58
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-lg border bg-card p-6", children: /* @__PURE__ */ jsx(
|
|
59
|
+
SteppedAutoForm,
|
|
60
|
+
{
|
|
61
|
+
formSchema: zodSchema,
|
|
62
|
+
onSubmit: handleSubmit,
|
|
63
|
+
fieldConfig,
|
|
64
|
+
values: defaultValues,
|
|
65
|
+
submitButtonText: "Submit"
|
|
66
|
+
}
|
|
67
|
+
) })
|
|
68
|
+
] }) }) });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { FormPreview };
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
const React = require('react');
|
|
8
|
+
const core_esm = require('../../../../../node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.cjs');
|
|
9
|
+
const sortable_esm = require('../../../../../node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.cjs');
|
|
10
|
+
const utils = require('../../lib/utils.cjs');
|
|
11
|
+
const tabs = require('../tabs.cjs');
|
|
12
|
+
const palette = require('./palette.cjs');
|
|
13
|
+
const canvas = require('./canvas.cjs');
|
|
14
|
+
const editFieldDialog = require('./edit-field-dialog.cjs');
|
|
15
|
+
const nestedFieldEditorDialog = require('./nested-field-editor-dialog.cjs');
|
|
16
|
+
const formPreview = require('./form-preview.cjs');
|
|
17
|
+
const sortableField = require('./sortable-field.cjs');
|
|
18
|
+
const index = require('./components/index.cjs');
|
|
19
|
+
const schemaUtils = require('./schema-utils.cjs');
|
|
20
|
+
const validationSchemas = require('./validation-schemas.cjs');
|
|
21
|
+
|
|
22
|
+
function FormBuilder({
|
|
23
|
+
components = index.defaultComponents,
|
|
24
|
+
value,
|
|
25
|
+
onChange,
|
|
26
|
+
className,
|
|
27
|
+
fieldComponents,
|
|
28
|
+
defaultValues
|
|
29
|
+
}) {
|
|
30
|
+
const dndContextId = React.useId();
|
|
31
|
+
const [fields, setFields] = React.useState(() => {
|
|
32
|
+
if (!value) return [];
|
|
33
|
+
const { fields: parsedFields } = schemaUtils.jsonSchemaToFieldsAndSteps(value, components);
|
|
34
|
+
return parsedFields;
|
|
35
|
+
});
|
|
36
|
+
const [steps, setSteps] = React.useState(() => {
|
|
37
|
+
if (!value) return [];
|
|
38
|
+
const { steps: parsedSteps } = schemaUtils.jsonSchemaToFieldsAndSteps(value, components);
|
|
39
|
+
return parsedSteps;
|
|
40
|
+
});
|
|
41
|
+
const [activeStepIndex, setActiveStepIndex] = React.useState(0);
|
|
42
|
+
const [editDialogFieldId, setEditDialogFieldId] = React.useState(null);
|
|
43
|
+
const [nestedEditorFieldId, setNestedEditorFieldId] = React.useState(null);
|
|
44
|
+
const [activeId, setActiveId] = React.useState(null);
|
|
45
|
+
const notifyChange = React.useCallback(
|
|
46
|
+
(newFields, newSteps) => {
|
|
47
|
+
if (onChange) {
|
|
48
|
+
const schema = schemaUtils.fieldsToJSONSchema(newFields, components, newSteps ?? steps);
|
|
49
|
+
onChange(schema);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[onChange, components, steps]
|
|
53
|
+
);
|
|
54
|
+
const currentSchema = React.useMemo(
|
|
55
|
+
() => schemaUtils.fieldsToJSONSchema(fields, components, steps),
|
|
56
|
+
[fields, components, steps]
|
|
57
|
+
);
|
|
58
|
+
const sensors = core_esm.useSensors(
|
|
59
|
+
core_esm.useSensor(core_esm.PointerSensor, {
|
|
60
|
+
activationConstraint: {
|
|
61
|
+
distance: 8
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
core_esm.useSensor(core_esm.TouchSensor, {
|
|
65
|
+
activationConstraint: {
|
|
66
|
+
// Use distance instead of delay for better compatibility with
|
|
67
|
+
// automated testing tools and faster touch interactions
|
|
68
|
+
distance: 8
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
core_esm.useSensor(core_esm.KeyboardSensor, {
|
|
72
|
+
coordinateGetter: sortable_esm.sortableKeyboardCoordinates
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
const activeDragData = React.useMemo(() => {
|
|
76
|
+
if (!activeId) return null;
|
|
77
|
+
const idStr = String(activeId);
|
|
78
|
+
if (idStr.startsWith("palette-")) {
|
|
79
|
+
const componentType = idStr.replace("palette-", "");
|
|
80
|
+
return {
|
|
81
|
+
type: "palette",
|
|
82
|
+
componentType,
|
|
83
|
+
component: index.getComponentByType(componentType, components)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const field = fields.find((f) => f.id === idStr);
|
|
87
|
+
if (field) {
|
|
88
|
+
return {
|
|
89
|
+
type: "field",
|
|
90
|
+
field,
|
|
91
|
+
component: index.getComponentByType(field.type, components)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}, [activeId, fields, components]);
|
|
96
|
+
const handleDragStart = (event) => {
|
|
97
|
+
setActiveId(event.active.id);
|
|
98
|
+
};
|
|
99
|
+
const handleDragEnd = (event) => {
|
|
100
|
+
const { active, over } = event;
|
|
101
|
+
setActiveId(null);
|
|
102
|
+
if (!over) return;
|
|
103
|
+
const activeData = active.data.current;
|
|
104
|
+
if (activeData?.type === "palette") {
|
|
105
|
+
const { componentType } = activeData;
|
|
106
|
+
const component = index.getComponentByType(componentType, components);
|
|
107
|
+
if (component) {
|
|
108
|
+
const newField = {
|
|
109
|
+
id: schemaUtils.generateFieldId(componentType),
|
|
110
|
+
type: componentType,
|
|
111
|
+
props: {
|
|
112
|
+
label: component.defaultProps.label || component.label,
|
|
113
|
+
...component.defaultProps
|
|
114
|
+
},
|
|
115
|
+
// Assign to active step when in multi-step mode
|
|
116
|
+
...steps.length > 1 ? { stepGroup: activeStepIndex } : {}
|
|
117
|
+
};
|
|
118
|
+
let insertIndex = fields.length;
|
|
119
|
+
const overId = String(over.id);
|
|
120
|
+
if (overId === "drop-zone-start") {
|
|
121
|
+
insertIndex = 0;
|
|
122
|
+
} else if (overId.startsWith("drop-zone-")) {
|
|
123
|
+
const fieldId = overId.replace("drop-zone-", "");
|
|
124
|
+
const overIndex = fields.findIndex((f) => f.id === fieldId);
|
|
125
|
+
if (overIndex !== -1) {
|
|
126
|
+
insertIndex = overIndex + 1;
|
|
127
|
+
}
|
|
128
|
+
} else if (overId !== "canvas") {
|
|
129
|
+
const overIndex = fields.findIndex((f) => f.id === overId);
|
|
130
|
+
if (overIndex !== -1) {
|
|
131
|
+
insertIndex = overIndex + 1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const newFields = [...fields];
|
|
135
|
+
newFields.splice(insertIndex, 0, newField);
|
|
136
|
+
setFields(newFields);
|
|
137
|
+
notifyChange(newFields);
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (activeData?.type === "field" && active.id !== over.id) {
|
|
142
|
+
const oldIndex = fields.findIndex((f) => f.id === active.id);
|
|
143
|
+
const newIndex = fields.findIndex((f) => f.id === over.id);
|
|
144
|
+
if (oldIndex !== -1 && newIndex !== -1) {
|
|
145
|
+
const newFields = sortable_esm.arrayMove(fields, oldIndex, newIndex);
|
|
146
|
+
setFields(newFields);
|
|
147
|
+
notifyChange(newFields);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const handleUpdateField = React.useCallback(
|
|
152
|
+
(id, props, newId, stepGroup) => {
|
|
153
|
+
if (newId && newId !== id) {
|
|
154
|
+
const idExists = fields.some((f) => f.id === newId && f.id !== id);
|
|
155
|
+
if (idExists) {
|
|
156
|
+
console.warn(`Cannot rename field "${id}" to "${newId}": a field with that ID already exists`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const newFields = fields.map((f) => {
|
|
161
|
+
if (f.id !== id) return f;
|
|
162
|
+
const updated = {
|
|
163
|
+
...f,
|
|
164
|
+
id: newId || f.id,
|
|
165
|
+
props: { ...f.props, ...props }
|
|
166
|
+
};
|
|
167
|
+
if (stepGroup !== void 0) {
|
|
168
|
+
updated.stepGroup = stepGroup;
|
|
169
|
+
}
|
|
170
|
+
return updated;
|
|
171
|
+
});
|
|
172
|
+
setFields(newFields);
|
|
173
|
+
notifyChange(newFields);
|
|
174
|
+
},
|
|
175
|
+
[fields, notifyChange]
|
|
176
|
+
);
|
|
177
|
+
const handleEditField = React.useCallback((id) => {
|
|
178
|
+
setEditDialogFieldId(id);
|
|
179
|
+
}, []);
|
|
180
|
+
const handleDeleteField = React.useCallback(
|
|
181
|
+
(id) => {
|
|
182
|
+
const newFields = fields.filter((f) => f.id !== id);
|
|
183
|
+
setFields(newFields);
|
|
184
|
+
notifyChange(newFields);
|
|
185
|
+
},
|
|
186
|
+
[fields, notifyChange]
|
|
187
|
+
);
|
|
188
|
+
const handleConfigureNested = React.useCallback((id) => {
|
|
189
|
+
setNestedEditorFieldId(id);
|
|
190
|
+
}, []);
|
|
191
|
+
const handleSaveNestedFields = React.useCallback(
|
|
192
|
+
(fieldId, nestedFields) => {
|
|
193
|
+
const newFields = fields.map((f) => {
|
|
194
|
+
if (f.id !== fieldId) return f;
|
|
195
|
+
if (f.type === "object") {
|
|
196
|
+
return { ...f, children: nestedFields };
|
|
197
|
+
} else if (f.type === "array") {
|
|
198
|
+
return { ...f, itemTemplate: nestedFields };
|
|
199
|
+
}
|
|
200
|
+
return f;
|
|
201
|
+
});
|
|
202
|
+
setFields(newFields);
|
|
203
|
+
notifyChange(newFields);
|
|
204
|
+
},
|
|
205
|
+
[fields, notifyChange]
|
|
206
|
+
);
|
|
207
|
+
const handleAddStep = React.useCallback(() => {
|
|
208
|
+
const newStep = schemaUtils.createStep(steps.length);
|
|
209
|
+
const newSteps = [...steps, newStep];
|
|
210
|
+
if (steps.length === 1) {
|
|
211
|
+
const updatedFields = fields.map((f) => ({ ...f, stepGroup: 0 }));
|
|
212
|
+
setFields(updatedFields);
|
|
213
|
+
setSteps(newSteps);
|
|
214
|
+
notifyChange(updatedFields, newSteps);
|
|
215
|
+
} else if (steps.length === 0) {
|
|
216
|
+
const firstStep = schemaUtils.createStep(0);
|
|
217
|
+
const secondStep = schemaUtils.createStep(1);
|
|
218
|
+
const bothSteps = [firstStep, secondStep];
|
|
219
|
+
const updatedFields = fields.map((f) => ({ ...f, stepGroup: 0 }));
|
|
220
|
+
setFields(updatedFields);
|
|
221
|
+
setSteps(bothSteps);
|
|
222
|
+
notifyChange(updatedFields, bothSteps);
|
|
223
|
+
} else {
|
|
224
|
+
setSteps(newSteps);
|
|
225
|
+
notifyChange(fields, newSteps);
|
|
226
|
+
}
|
|
227
|
+
}, [steps, fields, notifyChange]);
|
|
228
|
+
const handleDeleteStep = React.useCallback(
|
|
229
|
+
(index) => {
|
|
230
|
+
const fieldsWithoutDeleted = fields.filter((f) => f.stepGroup !== index);
|
|
231
|
+
if (steps.length <= 2) {
|
|
232
|
+
const updatedFields = fieldsWithoutDeleted.map((f) => {
|
|
233
|
+
const { stepGroup: _, ...rest } = f;
|
|
234
|
+
return rest;
|
|
235
|
+
});
|
|
236
|
+
setFields(updatedFields);
|
|
237
|
+
setSteps([]);
|
|
238
|
+
setActiveStepIndex(0);
|
|
239
|
+
notifyChange(updatedFields, []);
|
|
240
|
+
} else {
|
|
241
|
+
const newSteps = steps.filter((_, i) => i !== index);
|
|
242
|
+
const updatedFields = fieldsWithoutDeleted.map((f) => {
|
|
243
|
+
if (f.stepGroup !== void 0 && f.stepGroup > index) {
|
|
244
|
+
return { ...f, stepGroup: f.stepGroup - 1 };
|
|
245
|
+
}
|
|
246
|
+
return f;
|
|
247
|
+
});
|
|
248
|
+
setFields(updatedFields);
|
|
249
|
+
setSteps(newSteps);
|
|
250
|
+
if (activeStepIndex >= newSteps.length) {
|
|
251
|
+
setActiveStepIndex(newSteps.length - 1);
|
|
252
|
+
}
|
|
253
|
+
notifyChange(updatedFields, newSteps);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
[steps, fields, activeStepIndex, notifyChange]
|
|
257
|
+
);
|
|
258
|
+
const handleRenameStep = React.useCallback(
|
|
259
|
+
(index, newTitle) => {
|
|
260
|
+
const newSteps = steps.map(
|
|
261
|
+
(step, i) => i === index ? { ...step, title: newTitle } : step
|
|
262
|
+
);
|
|
263
|
+
setSteps(newSteps);
|
|
264
|
+
notifyChange(fields, newSteps);
|
|
265
|
+
},
|
|
266
|
+
[steps, fields, notifyChange]
|
|
267
|
+
);
|
|
268
|
+
const editDialogField = fields.find((f) => f.id === editDialogFieldId) || null;
|
|
269
|
+
const editDialogComponent = editDialogField ? index.getComponentByType(editDialogField.type, components) || null : null;
|
|
270
|
+
const nestedEditorField = fields.find((f) => f.id === nestedEditorFieldId) || null;
|
|
271
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils.cn("flex flex-col lg:h-full", className), children: [
|
|
272
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
273
|
+
core_esm.DndContext,
|
|
274
|
+
{
|
|
275
|
+
id: dndContextId,
|
|
276
|
+
sensors,
|
|
277
|
+
collisionDetection: core_esm.closestCenter,
|
|
278
|
+
onDragStart: handleDragStart,
|
|
279
|
+
onDragEnd: handleDragEnd,
|
|
280
|
+
children: [
|
|
281
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 flex flex-col lg:flex-row lg:overflow-hidden", children: [
|
|
282
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full lg:w-64 p-4 border-b lg:border-b-0 lg:border-r lg:overflow-auto shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(palette.Palette, { components }) }),
|
|
283
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 p-4 lg:overflow-auto min-h-[300px]", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
284
|
+
canvas.Canvas,
|
|
285
|
+
{
|
|
286
|
+
fields,
|
|
287
|
+
components,
|
|
288
|
+
onEditField: handleEditField,
|
|
289
|
+
onDeleteField: handleDeleteField,
|
|
290
|
+
onConfigureNested: handleConfigureNested,
|
|
291
|
+
isDraggingFromPalette: activeDragData?.type === "palette",
|
|
292
|
+
steps,
|
|
293
|
+
activeStepIndex,
|
|
294
|
+
onActiveStepChange: setActiveStepIndex,
|
|
295
|
+
onAddStep: handleAddStep,
|
|
296
|
+
onDeleteStep: handleDeleteStep,
|
|
297
|
+
onRenameStep: handleRenameStep
|
|
298
|
+
}
|
|
299
|
+
) }),
|
|
300
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1 lg:w-96 border-t lg:border-t-0 lg:border-l lg:overflow-auto min-h-[300px]", children: /* @__PURE__ */ jsxRuntime.jsxs(tabs.Tabs, { defaultValue: "preview", className: "h-full flex flex-col", children: [
|
|
301
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 border-b", children: /* @__PURE__ */ jsxRuntime.jsxs(tabs.TabsList, { className: "w-full", children: [
|
|
302
|
+
/* @__PURE__ */ jsxRuntime.jsx(tabs.TabsTrigger, { value: "preview", className: "flex-1", children: "Preview" }),
|
|
303
|
+
/* @__PURE__ */ jsxRuntime.jsx(tabs.TabsTrigger, { value: "schema", className: "flex-1", children: "JSON Schema" })
|
|
304
|
+
] }) }),
|
|
305
|
+
/* @__PURE__ */ jsxRuntime.jsx(tabs.TabsContent, { value: "preview", className: "flex-1 m-0 lg:overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsx(formPreview.FormPreview, { schema: currentSchema, fieldComponents, defaultValues }) }),
|
|
306
|
+
/* @__PURE__ */ jsxRuntime.jsx(tabs.TabsContent, { value: "schema", className: "flex-1 m-0 p-4 lg:overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border bg-muted/50 p-4", children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-sm overflow-auto whitespace-pre-wrap", children: JSON.stringify(currentSchema, null, 2) }) }) })
|
|
307
|
+
] }) })
|
|
308
|
+
] }),
|
|
309
|
+
/* @__PURE__ */ jsxRuntime.jsxs(core_esm.DragOverlay, { dropAnimation: null, children: [
|
|
310
|
+
activeDragData?.type === "palette" && activeDragData.component && /* @__PURE__ */ jsxRuntime.jsx(palette.PaletteDragOverlay, { component: activeDragData.component }),
|
|
311
|
+
activeDragData?.type === "field" && activeDragData.field && /* @__PURE__ */ jsxRuntime.jsx(
|
|
312
|
+
sortableField.FieldDragOverlay,
|
|
313
|
+
{
|
|
314
|
+
field: activeDragData.field,
|
|
315
|
+
component: activeDragData.component
|
|
316
|
+
}
|
|
317
|
+
)
|
|
318
|
+
] })
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
),
|
|
322
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
323
|
+
editFieldDialog.EditFieldDialog,
|
|
324
|
+
{
|
|
325
|
+
open: editDialogFieldId !== null,
|
|
326
|
+
onOpenChange: (open) => !open && setEditDialogFieldId(null),
|
|
327
|
+
field: editDialogField,
|
|
328
|
+
component: editDialogComponent,
|
|
329
|
+
onUpdate: handleUpdateField,
|
|
330
|
+
steps,
|
|
331
|
+
allFieldIds: fields.map((f) => f.id)
|
|
332
|
+
}
|
|
333
|
+
),
|
|
334
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
335
|
+
nestedFieldEditorDialog.NestedFieldEditorDialog,
|
|
336
|
+
{
|
|
337
|
+
open: nestedEditorFieldId !== null,
|
|
338
|
+
onOpenChange: (open) => !open && setNestedEditorFieldId(null),
|
|
339
|
+
field: nestedEditorField,
|
|
340
|
+
components,
|
|
341
|
+
onSave: handleSaveNestedFields
|
|
342
|
+
}
|
|
343
|
+
)
|
|
344
|
+
] });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
exports.arrayFieldDefinition = index.arrayFieldDefinition;
|
|
348
|
+
exports.defaultComponents = index.defaultComponents;
|
|
349
|
+
exports.objectFieldDefinition = index.objectFieldDefinition;
|
|
350
|
+
exports.baseMetaSchema = validationSchemas.baseMetaSchema;
|
|
351
|
+
exports.baseMetaSchemaWithPlaceholder = validationSchemas.baseMetaSchemaWithPlaceholder;
|
|
352
|
+
exports.FormBuilder = FormBuilder;
|
|
353
|
+
exports.default = FormBuilder;
|