@btst/stack 1.5.2 → 1.6.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/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/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/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/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/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.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 +54 -1
- 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/dist/shared/{stack.DLhzx1-D.d.cts → stack.CcI4sYJP.d.cts} +1 -1
- package/dist/shared/{stack.DLhzx1-D.d.mts → stack.CcI4sYJP.d.mts} +1 -1
- package/dist/shared/{stack.DLhzx1-D.d.ts → stack.CcI4sYJP.d.ts} +1 -1
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useId, useState, useCallback, useMemo } from 'react';
|
|
4
|
+
import { useSensors, useSensor, DndContext, closestCenter, DragOverlay, KeyboardSensor, TouchSensor, PointerSensor } from '../../../../../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';
|
|
5
|
+
import { arrayMove, sortableKeyboardCoordinates } from '../../../../../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';
|
|
6
|
+
import { cn } from '../../lib/utils.mjs';
|
|
7
|
+
import { Tabs, TabsList, TabsTrigger, TabsContent } from '../tabs.mjs';
|
|
8
|
+
import { Palette, PaletteDragOverlay } from './palette.mjs';
|
|
9
|
+
import { Canvas } from './canvas.mjs';
|
|
10
|
+
import { EditFieldDialog } from './edit-field-dialog.mjs';
|
|
11
|
+
import { NestedFieldEditorDialog } from './nested-field-editor-dialog.mjs';
|
|
12
|
+
import { FormPreview } from './form-preview.mjs';
|
|
13
|
+
import { FieldDragOverlay } from './sortable-field.mjs';
|
|
14
|
+
import { defaultComponents, getComponentByType } from './components/index.mjs';
|
|
15
|
+
export { arrayFieldDefinition, objectFieldDefinition } from './components/index.mjs';
|
|
16
|
+
import { jsonSchemaToFieldsAndSteps, fieldsToJSONSchema, createStep, generateFieldId } from './schema-utils.mjs';
|
|
17
|
+
export { baseMetaSchema, baseMetaSchemaWithPlaceholder } from './validation-schemas.mjs';
|
|
18
|
+
|
|
19
|
+
function FormBuilder({
|
|
20
|
+
components = defaultComponents,
|
|
21
|
+
value,
|
|
22
|
+
onChange,
|
|
23
|
+
className,
|
|
24
|
+
fieldComponents,
|
|
25
|
+
defaultValues
|
|
26
|
+
}) {
|
|
27
|
+
const dndContextId = useId();
|
|
28
|
+
const [fields, setFields] = useState(() => {
|
|
29
|
+
if (!value) return [];
|
|
30
|
+
const { fields: parsedFields } = jsonSchemaToFieldsAndSteps(value, components);
|
|
31
|
+
return parsedFields;
|
|
32
|
+
});
|
|
33
|
+
const [steps, setSteps] = useState(() => {
|
|
34
|
+
if (!value) return [];
|
|
35
|
+
const { steps: parsedSteps } = jsonSchemaToFieldsAndSteps(value, components);
|
|
36
|
+
return parsedSteps;
|
|
37
|
+
});
|
|
38
|
+
const [activeStepIndex, setActiveStepIndex] = useState(0);
|
|
39
|
+
const [editDialogFieldId, setEditDialogFieldId] = useState(null);
|
|
40
|
+
const [nestedEditorFieldId, setNestedEditorFieldId] = useState(null);
|
|
41
|
+
const [activeId, setActiveId] = useState(null);
|
|
42
|
+
const notifyChange = useCallback(
|
|
43
|
+
(newFields, newSteps) => {
|
|
44
|
+
if (onChange) {
|
|
45
|
+
const schema = fieldsToJSONSchema(newFields, components, newSteps ?? steps);
|
|
46
|
+
onChange(schema);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
[onChange, components, steps]
|
|
50
|
+
);
|
|
51
|
+
const currentSchema = useMemo(
|
|
52
|
+
() => fieldsToJSONSchema(fields, components, steps),
|
|
53
|
+
[fields, components, steps]
|
|
54
|
+
);
|
|
55
|
+
const sensors = useSensors(
|
|
56
|
+
useSensor(PointerSensor, {
|
|
57
|
+
activationConstraint: {
|
|
58
|
+
distance: 8
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
useSensor(TouchSensor, {
|
|
62
|
+
activationConstraint: {
|
|
63
|
+
// Use distance instead of delay for better compatibility with
|
|
64
|
+
// automated testing tools and faster touch interactions
|
|
65
|
+
distance: 8
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
useSensor(KeyboardSensor, {
|
|
69
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
const activeDragData = useMemo(() => {
|
|
73
|
+
if (!activeId) return null;
|
|
74
|
+
const idStr = String(activeId);
|
|
75
|
+
if (idStr.startsWith("palette-")) {
|
|
76
|
+
const componentType = idStr.replace("palette-", "");
|
|
77
|
+
return {
|
|
78
|
+
type: "palette",
|
|
79
|
+
componentType,
|
|
80
|
+
component: getComponentByType(componentType, components)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const field = fields.find((f) => f.id === idStr);
|
|
84
|
+
if (field) {
|
|
85
|
+
return {
|
|
86
|
+
type: "field",
|
|
87
|
+
field,
|
|
88
|
+
component: getComponentByType(field.type, components)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}, [activeId, fields, components]);
|
|
93
|
+
const handleDragStart = (event) => {
|
|
94
|
+
setActiveId(event.active.id);
|
|
95
|
+
};
|
|
96
|
+
const handleDragEnd = (event) => {
|
|
97
|
+
const { active, over } = event;
|
|
98
|
+
setActiveId(null);
|
|
99
|
+
if (!over) return;
|
|
100
|
+
const activeData = active.data.current;
|
|
101
|
+
if (activeData?.type === "palette") {
|
|
102
|
+
const { componentType } = activeData;
|
|
103
|
+
const component = getComponentByType(componentType, components);
|
|
104
|
+
if (component) {
|
|
105
|
+
const newField = {
|
|
106
|
+
id: generateFieldId(componentType),
|
|
107
|
+
type: componentType,
|
|
108
|
+
props: {
|
|
109
|
+
label: component.defaultProps.label || component.label,
|
|
110
|
+
...component.defaultProps
|
|
111
|
+
},
|
|
112
|
+
// Assign to active step when in multi-step mode
|
|
113
|
+
...steps.length > 1 ? { stepGroup: activeStepIndex } : {}
|
|
114
|
+
};
|
|
115
|
+
let insertIndex = fields.length;
|
|
116
|
+
const overId = String(over.id);
|
|
117
|
+
if (overId === "drop-zone-start") {
|
|
118
|
+
insertIndex = 0;
|
|
119
|
+
} else if (overId.startsWith("drop-zone-")) {
|
|
120
|
+
const fieldId = overId.replace("drop-zone-", "");
|
|
121
|
+
const overIndex = fields.findIndex((f) => f.id === fieldId);
|
|
122
|
+
if (overIndex !== -1) {
|
|
123
|
+
insertIndex = overIndex + 1;
|
|
124
|
+
}
|
|
125
|
+
} else if (overId !== "canvas") {
|
|
126
|
+
const overIndex = fields.findIndex((f) => f.id === overId);
|
|
127
|
+
if (overIndex !== -1) {
|
|
128
|
+
insertIndex = overIndex + 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const newFields = [...fields];
|
|
132
|
+
newFields.splice(insertIndex, 0, newField);
|
|
133
|
+
setFields(newFields);
|
|
134
|
+
notifyChange(newFields);
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (activeData?.type === "field" && active.id !== over.id) {
|
|
139
|
+
const oldIndex = fields.findIndex((f) => f.id === active.id);
|
|
140
|
+
const newIndex = fields.findIndex((f) => f.id === over.id);
|
|
141
|
+
if (oldIndex !== -1 && newIndex !== -1) {
|
|
142
|
+
const newFields = arrayMove(fields, oldIndex, newIndex);
|
|
143
|
+
setFields(newFields);
|
|
144
|
+
notifyChange(newFields);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const handleUpdateField = useCallback(
|
|
149
|
+
(id, props, newId, stepGroup) => {
|
|
150
|
+
if (newId && newId !== id) {
|
|
151
|
+
const idExists = fields.some((f) => f.id === newId && f.id !== id);
|
|
152
|
+
if (idExists) {
|
|
153
|
+
console.warn(`Cannot rename field "${id}" to "${newId}": a field with that ID already exists`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const newFields = fields.map((f) => {
|
|
158
|
+
if (f.id !== id) return f;
|
|
159
|
+
const updated = {
|
|
160
|
+
...f,
|
|
161
|
+
id: newId || f.id,
|
|
162
|
+
props: { ...f.props, ...props }
|
|
163
|
+
};
|
|
164
|
+
if (stepGroup !== void 0) {
|
|
165
|
+
updated.stepGroup = stepGroup;
|
|
166
|
+
}
|
|
167
|
+
return updated;
|
|
168
|
+
});
|
|
169
|
+
setFields(newFields);
|
|
170
|
+
notifyChange(newFields);
|
|
171
|
+
},
|
|
172
|
+
[fields, notifyChange]
|
|
173
|
+
);
|
|
174
|
+
const handleEditField = useCallback((id) => {
|
|
175
|
+
setEditDialogFieldId(id);
|
|
176
|
+
}, []);
|
|
177
|
+
const handleDeleteField = useCallback(
|
|
178
|
+
(id) => {
|
|
179
|
+
const newFields = fields.filter((f) => f.id !== id);
|
|
180
|
+
setFields(newFields);
|
|
181
|
+
notifyChange(newFields);
|
|
182
|
+
},
|
|
183
|
+
[fields, notifyChange]
|
|
184
|
+
);
|
|
185
|
+
const handleConfigureNested = useCallback((id) => {
|
|
186
|
+
setNestedEditorFieldId(id);
|
|
187
|
+
}, []);
|
|
188
|
+
const handleSaveNestedFields = useCallback(
|
|
189
|
+
(fieldId, nestedFields) => {
|
|
190
|
+
const newFields = fields.map((f) => {
|
|
191
|
+
if (f.id !== fieldId) return f;
|
|
192
|
+
if (f.type === "object") {
|
|
193
|
+
return { ...f, children: nestedFields };
|
|
194
|
+
} else if (f.type === "array") {
|
|
195
|
+
return { ...f, itemTemplate: nestedFields };
|
|
196
|
+
}
|
|
197
|
+
return f;
|
|
198
|
+
});
|
|
199
|
+
setFields(newFields);
|
|
200
|
+
notifyChange(newFields);
|
|
201
|
+
},
|
|
202
|
+
[fields, notifyChange]
|
|
203
|
+
);
|
|
204
|
+
const handleAddStep = useCallback(() => {
|
|
205
|
+
const newStep = createStep(steps.length);
|
|
206
|
+
const newSteps = [...steps, newStep];
|
|
207
|
+
if (steps.length === 1) {
|
|
208
|
+
const updatedFields = fields.map((f) => ({ ...f, stepGroup: 0 }));
|
|
209
|
+
setFields(updatedFields);
|
|
210
|
+
setSteps(newSteps);
|
|
211
|
+
notifyChange(updatedFields, newSteps);
|
|
212
|
+
} else if (steps.length === 0) {
|
|
213
|
+
const firstStep = createStep(0);
|
|
214
|
+
const secondStep = createStep(1);
|
|
215
|
+
const bothSteps = [firstStep, secondStep];
|
|
216
|
+
const updatedFields = fields.map((f) => ({ ...f, stepGroup: 0 }));
|
|
217
|
+
setFields(updatedFields);
|
|
218
|
+
setSteps(bothSteps);
|
|
219
|
+
notifyChange(updatedFields, bothSteps);
|
|
220
|
+
} else {
|
|
221
|
+
setSteps(newSteps);
|
|
222
|
+
notifyChange(fields, newSteps);
|
|
223
|
+
}
|
|
224
|
+
}, [steps, fields, notifyChange]);
|
|
225
|
+
const handleDeleteStep = useCallback(
|
|
226
|
+
(index) => {
|
|
227
|
+
const fieldsWithoutDeleted = fields.filter((f) => f.stepGroup !== index);
|
|
228
|
+
if (steps.length <= 2) {
|
|
229
|
+
const updatedFields = fieldsWithoutDeleted.map((f) => {
|
|
230
|
+
const { stepGroup: _, ...rest } = f;
|
|
231
|
+
return rest;
|
|
232
|
+
});
|
|
233
|
+
setFields(updatedFields);
|
|
234
|
+
setSteps([]);
|
|
235
|
+
setActiveStepIndex(0);
|
|
236
|
+
notifyChange(updatedFields, []);
|
|
237
|
+
} else {
|
|
238
|
+
const newSteps = steps.filter((_, i) => i !== index);
|
|
239
|
+
const updatedFields = fieldsWithoutDeleted.map((f) => {
|
|
240
|
+
if (f.stepGroup !== void 0 && f.stepGroup > index) {
|
|
241
|
+
return { ...f, stepGroup: f.stepGroup - 1 };
|
|
242
|
+
}
|
|
243
|
+
return f;
|
|
244
|
+
});
|
|
245
|
+
setFields(updatedFields);
|
|
246
|
+
setSteps(newSteps);
|
|
247
|
+
if (activeStepIndex >= newSteps.length) {
|
|
248
|
+
setActiveStepIndex(newSteps.length - 1);
|
|
249
|
+
}
|
|
250
|
+
notifyChange(updatedFields, newSteps);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
[steps, fields, activeStepIndex, notifyChange]
|
|
254
|
+
);
|
|
255
|
+
const handleRenameStep = useCallback(
|
|
256
|
+
(index, newTitle) => {
|
|
257
|
+
const newSteps = steps.map(
|
|
258
|
+
(step, i) => i === index ? { ...step, title: newTitle } : step
|
|
259
|
+
);
|
|
260
|
+
setSteps(newSteps);
|
|
261
|
+
notifyChange(fields, newSteps);
|
|
262
|
+
},
|
|
263
|
+
[steps, fields, notifyChange]
|
|
264
|
+
);
|
|
265
|
+
const editDialogField = fields.find((f) => f.id === editDialogFieldId) || null;
|
|
266
|
+
const editDialogComponent = editDialogField ? getComponentByType(editDialogField.type, components) || null : null;
|
|
267
|
+
const nestedEditorField = fields.find((f) => f.id === nestedEditorFieldId) || null;
|
|
268
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col lg:h-full", className), children: [
|
|
269
|
+
/* @__PURE__ */ jsxs(
|
|
270
|
+
DndContext,
|
|
271
|
+
{
|
|
272
|
+
id: dndContextId,
|
|
273
|
+
sensors,
|
|
274
|
+
collisionDetection: closestCenter,
|
|
275
|
+
onDragStart: handleDragStart,
|
|
276
|
+
onDragEnd: handleDragEnd,
|
|
277
|
+
children: [
|
|
278
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col lg:flex-row lg:overflow-hidden", children: [
|
|
279
|
+
/* @__PURE__ */ 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__ */ jsx(Palette, { components }) }),
|
|
280
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 p-4 lg:overflow-auto min-h-[300px]", children: /* @__PURE__ */ jsx(
|
|
281
|
+
Canvas,
|
|
282
|
+
{
|
|
283
|
+
fields,
|
|
284
|
+
components,
|
|
285
|
+
onEditField: handleEditField,
|
|
286
|
+
onDeleteField: handleDeleteField,
|
|
287
|
+
onConfigureNested: handleConfigureNested,
|
|
288
|
+
isDraggingFromPalette: activeDragData?.type === "palette",
|
|
289
|
+
steps,
|
|
290
|
+
activeStepIndex,
|
|
291
|
+
onActiveStepChange: setActiveStepIndex,
|
|
292
|
+
onAddStep: handleAddStep,
|
|
293
|
+
onDeleteStep: handleDeleteStep,
|
|
294
|
+
onRenameStep: handleRenameStep
|
|
295
|
+
}
|
|
296
|
+
) }),
|
|
297
|
+
/* @__PURE__ */ 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__ */ jsxs(Tabs, { defaultValue: "preview", className: "h-full flex flex-col", children: [
|
|
298
|
+
/* @__PURE__ */ jsx("div", { className: "p-4 border-b", children: /* @__PURE__ */ jsxs(TabsList, { className: "w-full", children: [
|
|
299
|
+
/* @__PURE__ */ jsx(TabsTrigger, { value: "preview", className: "flex-1", children: "Preview" }),
|
|
300
|
+
/* @__PURE__ */ jsx(TabsTrigger, { value: "schema", className: "flex-1", children: "JSON Schema" })
|
|
301
|
+
] }) }),
|
|
302
|
+
/* @__PURE__ */ jsx(TabsContent, { value: "preview", className: "flex-1 m-0 lg:overflow-auto", children: /* @__PURE__ */ jsx(FormPreview, { schema: currentSchema, fieldComponents, defaultValues }) }),
|
|
303
|
+
/* @__PURE__ */ jsx(TabsContent, { value: "schema", className: "flex-1 m-0 p-4 lg:overflow-auto", children: /* @__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(currentSchema, null, 2) }) }) })
|
|
304
|
+
] }) })
|
|
305
|
+
] }),
|
|
306
|
+
/* @__PURE__ */ jsxs(DragOverlay, { dropAnimation: null, children: [
|
|
307
|
+
activeDragData?.type === "palette" && activeDragData.component && /* @__PURE__ */ jsx(PaletteDragOverlay, { component: activeDragData.component }),
|
|
308
|
+
activeDragData?.type === "field" && activeDragData.field && /* @__PURE__ */ jsx(
|
|
309
|
+
FieldDragOverlay,
|
|
310
|
+
{
|
|
311
|
+
field: activeDragData.field,
|
|
312
|
+
component: activeDragData.component
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
] })
|
|
316
|
+
]
|
|
317
|
+
}
|
|
318
|
+
),
|
|
319
|
+
/* @__PURE__ */ jsx(
|
|
320
|
+
EditFieldDialog,
|
|
321
|
+
{
|
|
322
|
+
open: editDialogFieldId !== null,
|
|
323
|
+
onOpenChange: (open) => !open && setEditDialogFieldId(null),
|
|
324
|
+
field: editDialogField,
|
|
325
|
+
component: editDialogComponent,
|
|
326
|
+
onUpdate: handleUpdateField,
|
|
327
|
+
steps,
|
|
328
|
+
allFieldIds: fields.map((f) => f.id)
|
|
329
|
+
}
|
|
330
|
+
),
|
|
331
|
+
/* @__PURE__ */ jsx(
|
|
332
|
+
NestedFieldEditorDialog,
|
|
333
|
+
{
|
|
334
|
+
open: nestedEditorFieldId !== null,
|
|
335
|
+
onOpenChange: (open) => !open && setNestedEditorFieldId(null),
|
|
336
|
+
field: nestedEditorField,
|
|
337
|
+
components,
|
|
338
|
+
onSave: handleSaveNestedFields
|
|
339
|
+
}
|
|
340
|
+
)
|
|
341
|
+
] });
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export { FormBuilder, FormBuilder as default, defaultComponents };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const ReactDOM = require('react-dom');
|
|
7
|
+
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');
|
|
8
|
+
const modifiers_esm = require('../../../../../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');
|
|
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 lucideReact = require('lucide-react');
|
|
11
|
+
const button = require('../button.cjs');
|
|
12
|
+
const dialog = require('../dialog.cjs');
|
|
13
|
+
const palette = require('./palette.cjs');
|
|
14
|
+
const canvas = require('./canvas.cjs');
|
|
15
|
+
const editFieldDialog = require('./edit-field-dialog.cjs');
|
|
16
|
+
const sortableField = require('./sortable-field.cjs');
|
|
17
|
+
const index = require('./components/index.cjs');
|
|
18
|
+
const schemaUtils = require('./schema-utils.cjs');
|
|
19
|
+
|
|
20
|
+
function NestedFieldEditorDialog({
|
|
21
|
+
open,
|
|
22
|
+
onOpenChange,
|
|
23
|
+
field,
|
|
24
|
+
components,
|
|
25
|
+
onSave
|
|
26
|
+
}) {
|
|
27
|
+
const dndContextId = React.useId();
|
|
28
|
+
const initialFields = React.useMemo(() => {
|
|
29
|
+
if (!field) return [];
|
|
30
|
+
if (field.type === "object") return field.children || [];
|
|
31
|
+
if (field.type === "array") return field.itemTemplate || [];
|
|
32
|
+
return [];
|
|
33
|
+
}, [field]);
|
|
34
|
+
const [nestedFields, setNestedFields] = React.useState(initialFields);
|
|
35
|
+
const [activeId, setActiveId] = React.useState(null);
|
|
36
|
+
const [editDialogFieldId, setEditDialogFieldId] = React.useState(null);
|
|
37
|
+
const [prevField, setPrevField] = React.useState(field);
|
|
38
|
+
const [prevOpen, setPrevOpen] = React.useState(open);
|
|
39
|
+
if (prevField !== field || open && !prevOpen) {
|
|
40
|
+
setPrevField(field);
|
|
41
|
+
setPrevOpen(open);
|
|
42
|
+
setNestedFields(initialFields);
|
|
43
|
+
setEditDialogFieldId(null);
|
|
44
|
+
}
|
|
45
|
+
if (prevOpen !== open) {
|
|
46
|
+
setPrevOpen(open);
|
|
47
|
+
}
|
|
48
|
+
const sensors = core_esm.useSensors(
|
|
49
|
+
core_esm.useSensor(core_esm.PointerSensor, {
|
|
50
|
+
activationConstraint: { distance: 8 }
|
|
51
|
+
}),
|
|
52
|
+
core_esm.useSensor(core_esm.TouchSensor, {
|
|
53
|
+
activationConstraint: { distance: 8 }
|
|
54
|
+
}),
|
|
55
|
+
core_esm.useSensor(core_esm.KeyboardSensor, {
|
|
56
|
+
coordinateGetter: sortable_esm.sortableKeyboardCoordinates
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
const activeDragData = React.useMemo(() => {
|
|
60
|
+
if (!activeId) return null;
|
|
61
|
+
const idStr = String(activeId);
|
|
62
|
+
if (idStr.startsWith("palette-")) {
|
|
63
|
+
const componentType = idStr.replace("palette-", "");
|
|
64
|
+
return {
|
|
65
|
+
type: "palette",
|
|
66
|
+
componentType,
|
|
67
|
+
component: index.getComponentByType(componentType, components)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const nestedField = nestedFields.find((f) => f.id === idStr);
|
|
71
|
+
if (nestedField) {
|
|
72
|
+
return {
|
|
73
|
+
type: "field",
|
|
74
|
+
field: nestedField,
|
|
75
|
+
component: index.getComponentByType(nestedField.type, components)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}, [activeId, nestedFields, components]);
|
|
80
|
+
const handleDragStart = (event) => {
|
|
81
|
+
setActiveId(event.active.id);
|
|
82
|
+
};
|
|
83
|
+
const handleDragEnd = (event) => {
|
|
84
|
+
const { active, over } = event;
|
|
85
|
+
setActiveId(null);
|
|
86
|
+
if (!over) return;
|
|
87
|
+
const activeData = active.data.current;
|
|
88
|
+
if (activeData?.type === "palette") {
|
|
89
|
+
const { componentType } = activeData;
|
|
90
|
+
const component = index.getComponentByType(componentType, components);
|
|
91
|
+
if (component) {
|
|
92
|
+
const newField = {
|
|
93
|
+
id: schemaUtils.generateFieldId(componentType),
|
|
94
|
+
type: componentType,
|
|
95
|
+
props: {
|
|
96
|
+
label: component.defaultProps.label || component.label,
|
|
97
|
+
...component.defaultProps
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
let insertIndex = nestedFields.length;
|
|
101
|
+
const overId = String(over.id);
|
|
102
|
+
if (overId === "drop-zone-start") {
|
|
103
|
+
insertIndex = 0;
|
|
104
|
+
} else if (overId.startsWith("drop-zone-")) {
|
|
105
|
+
const fieldId = overId.replace("drop-zone-", "");
|
|
106
|
+
const overIndex = nestedFields.findIndex((f) => f.id === fieldId);
|
|
107
|
+
if (overIndex !== -1) {
|
|
108
|
+
insertIndex = overIndex + 1;
|
|
109
|
+
}
|
|
110
|
+
} else if (overId !== "canvas") {
|
|
111
|
+
const overIndex = nestedFields.findIndex((f) => f.id === overId);
|
|
112
|
+
if (overIndex !== -1) {
|
|
113
|
+
insertIndex = overIndex + 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const newFields = [...nestedFields];
|
|
117
|
+
newFields.splice(insertIndex, 0, newField);
|
|
118
|
+
setNestedFields(newFields);
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (activeData?.type === "field" && active.id !== over.id) {
|
|
123
|
+
const oldIndex = nestedFields.findIndex((f) => f.id === active.id);
|
|
124
|
+
const newIndex = nestedFields.findIndex((f) => f.id === over.id);
|
|
125
|
+
if (oldIndex !== -1 && newIndex !== -1) {
|
|
126
|
+
setNestedFields(sortable_esm.arrayMove(nestedFields, oldIndex, newIndex));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const handleDeleteField = React.useCallback((id) => {
|
|
131
|
+
setNestedFields((fields) => fields.filter((f) => f.id !== id));
|
|
132
|
+
}, []);
|
|
133
|
+
const handleEditField = React.useCallback((id) => {
|
|
134
|
+
setEditDialogFieldId(id);
|
|
135
|
+
}, []);
|
|
136
|
+
const handleUpdateField = React.useCallback(
|
|
137
|
+
(id, props, newId) => {
|
|
138
|
+
if (newId && newId !== id) {
|
|
139
|
+
const idExists = nestedFields.some((f) => f.id === newId && f.id !== id);
|
|
140
|
+
if (idExists) {
|
|
141
|
+
console.warn(`Cannot rename field "${id}" to "${newId}": a field with that ID already exists`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
setNestedFields(
|
|
146
|
+
(fields) => fields.map((f) => {
|
|
147
|
+
if (f.id !== id) return f;
|
|
148
|
+
return {
|
|
149
|
+
...f,
|
|
150
|
+
id: newId || f.id,
|
|
151
|
+
props: { ...f.props, ...props }
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
},
|
|
156
|
+
[nestedFields]
|
|
157
|
+
);
|
|
158
|
+
const handleSave = React.useCallback(() => {
|
|
159
|
+
if (!field) return;
|
|
160
|
+
onSave(field.id, nestedFields);
|
|
161
|
+
onOpenChange(false);
|
|
162
|
+
}, [field, nestedFields, onSave, onOpenChange]);
|
|
163
|
+
if (!field) return null;
|
|
164
|
+
const isObjectField = field.type === "object";
|
|
165
|
+
const Icon = isObjectField ? lucideReact.FolderOpen : lucideReact.List;
|
|
166
|
+
const fieldTypeLabel = isObjectField ? "Field Group" : "Repeating Group";
|
|
167
|
+
const nestedLabel = isObjectField ? "nested fields" : "item fields";
|
|
168
|
+
const editDialogField = nestedFields.find((f) => f.id === editDialogFieldId) || null;
|
|
169
|
+
const editDialogComponent = editDialogField ? index.getComponentByType(editDialogField.type, components) || null : null;
|
|
170
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(dialog.Dialog, { open, onOpenChange, children: [
|
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogContent, { className: "max-w-6xl! max-h-[90vh] overflow-hidden flex flex-col", children: [
|
|
172
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogHeader, { children: [
|
|
173
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogTitle, { className: "flex items-center gap-2", children: [
|
|
174
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "h-5 w-5 text-muted-foreground" }),
|
|
175
|
+
"Configure ",
|
|
176
|
+
fieldTypeLabel,
|
|
177
|
+
": ",
|
|
178
|
+
field.props.label
|
|
179
|
+
] }),
|
|
180
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogDescription, { children: [
|
|
181
|
+
"Add and arrange the ",
|
|
182
|
+
nestedLabel,
|
|
183
|
+
" for this ",
|
|
184
|
+
fieldTypeLabel.toLowerCase(),
|
|
185
|
+
".",
|
|
186
|
+
isObjectField ? " These fields will be grouped together." : " Each item in the array will have these fields."
|
|
187
|
+
] })
|
|
188
|
+
] }),
|
|
189
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
190
|
+
core_esm.DndContext,
|
|
191
|
+
{
|
|
192
|
+
id: dndContextId,
|
|
193
|
+
sensors,
|
|
194
|
+
collisionDetection: core_esm.closestCenter,
|
|
195
|
+
onDragStart: handleDragStart,
|
|
196
|
+
onDragEnd: handleDragEnd,
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-[50vh] gap-4", children: [
|
|
199
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-48 overflow-auto shrink-0 border-r pr-4", children: /* @__PURE__ */ jsxRuntime.jsx(palette.Palette, { components }) }),
|
|
200
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
201
|
+
canvas.Canvas,
|
|
202
|
+
{
|
|
203
|
+
fields: nestedFields,
|
|
204
|
+
components,
|
|
205
|
+
onEditField: handleEditField,
|
|
206
|
+
onDeleteField: handleDeleteField,
|
|
207
|
+
isDraggingFromPalette: activeDragData?.type === "palette",
|
|
208
|
+
steps: [],
|
|
209
|
+
activeStepIndex: 0,
|
|
210
|
+
onActiveStepChange: () => {
|
|
211
|
+
},
|
|
212
|
+
onAddStep: () => {
|
|
213
|
+
},
|
|
214
|
+
onDeleteStep: () => {
|
|
215
|
+
},
|
|
216
|
+
onRenameStep: () => {
|
|
217
|
+
},
|
|
218
|
+
hideStepControls: true
|
|
219
|
+
}
|
|
220
|
+
) })
|
|
221
|
+
] }),
|
|
222
|
+
typeof document !== "undefined" && ReactDOM.createPortal(
|
|
223
|
+
/* @__PURE__ */ jsxRuntime.jsxs(core_esm.DragOverlay, { dropAnimation: null, modifiers: [modifiers_esm.snapCenterToCursor], children: [
|
|
224
|
+
activeDragData?.type === "palette" && activeDragData.component && /* @__PURE__ */ jsxRuntime.jsx(palette.PaletteDragOverlay, { component: activeDragData.component }),
|
|
225
|
+
activeDragData?.type === "field" && activeDragData.field && /* @__PURE__ */ jsxRuntime.jsx(
|
|
226
|
+
sortableField.FieldDragOverlay,
|
|
227
|
+
{
|
|
228
|
+
field: activeDragData.field,
|
|
229
|
+
component: activeDragData.component
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
] }),
|
|
233
|
+
document.body
|
|
234
|
+
)
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
) }),
|
|
238
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogFooter, { className: "border-t pt-4", children: [
|
|
239
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground mr-auto", children: [
|
|
240
|
+
nestedFields.length,
|
|
241
|
+
" ",
|
|
242
|
+
nestedFields.length === 1 ? "field" : "fields"
|
|
243
|
+
] }),
|
|
244
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
245
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { onClick: handleSave, children: "Save Fields" })
|
|
246
|
+
] })
|
|
247
|
+
] }),
|
|
248
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
249
|
+
editFieldDialog.EditFieldDialog,
|
|
250
|
+
{
|
|
251
|
+
open: editDialogFieldId !== null,
|
|
252
|
+
onOpenChange: (open2) => !open2 && setEditDialogFieldId(null),
|
|
253
|
+
field: editDialogField,
|
|
254
|
+
component: editDialogComponent,
|
|
255
|
+
onUpdate: handleUpdateField,
|
|
256
|
+
steps: [],
|
|
257
|
+
allFieldIds: nestedFields.map((f) => f.id)
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
] });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
exports.NestedFieldEditorDialog = NestedFieldEditorDialog;
|