@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,261 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useId, useMemo, useState, useCallback } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { useSensors, useSensor, KeyboardSensor, TouchSensor, PointerSensor, DndContext, closestCenter, DragOverlay } 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';
|
|
6
|
+
import { snapCenterToCursor } from '../../../../../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';
|
|
7
|
+
import { sortableKeyboardCoordinates, arrayMove } 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';
|
|
8
|
+
import { FolderOpen, List } from 'lucide-react';
|
|
9
|
+
import { Button } from '../button.mjs';
|
|
10
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '../dialog.mjs';
|
|
11
|
+
import { Palette, PaletteDragOverlay } from './palette.mjs';
|
|
12
|
+
import { Canvas } from './canvas.mjs';
|
|
13
|
+
import { EditFieldDialog } from './edit-field-dialog.mjs';
|
|
14
|
+
import { FieldDragOverlay } from './sortable-field.mjs';
|
|
15
|
+
import { getComponentByType } from './components/index.mjs';
|
|
16
|
+
import { generateFieldId } from './schema-utils.mjs';
|
|
17
|
+
|
|
18
|
+
function NestedFieldEditorDialog({
|
|
19
|
+
open,
|
|
20
|
+
onOpenChange,
|
|
21
|
+
field,
|
|
22
|
+
components,
|
|
23
|
+
onSave
|
|
24
|
+
}) {
|
|
25
|
+
const dndContextId = useId();
|
|
26
|
+
const initialFields = useMemo(() => {
|
|
27
|
+
if (!field) return [];
|
|
28
|
+
if (field.type === "object") return field.children || [];
|
|
29
|
+
if (field.type === "array") return field.itemTemplate || [];
|
|
30
|
+
return [];
|
|
31
|
+
}, [field]);
|
|
32
|
+
const [nestedFields, setNestedFields] = useState(initialFields);
|
|
33
|
+
const [activeId, setActiveId] = useState(null);
|
|
34
|
+
const [editDialogFieldId, setEditDialogFieldId] = useState(null);
|
|
35
|
+
const [prevField, setPrevField] = useState(field);
|
|
36
|
+
const [prevOpen, setPrevOpen] = useState(open);
|
|
37
|
+
if (prevField !== field || open && !prevOpen) {
|
|
38
|
+
setPrevField(field);
|
|
39
|
+
setPrevOpen(open);
|
|
40
|
+
setNestedFields(initialFields);
|
|
41
|
+
setEditDialogFieldId(null);
|
|
42
|
+
}
|
|
43
|
+
if (prevOpen !== open) {
|
|
44
|
+
setPrevOpen(open);
|
|
45
|
+
}
|
|
46
|
+
const sensors = useSensors(
|
|
47
|
+
useSensor(PointerSensor, {
|
|
48
|
+
activationConstraint: { distance: 8 }
|
|
49
|
+
}),
|
|
50
|
+
useSensor(TouchSensor, {
|
|
51
|
+
activationConstraint: { distance: 8 }
|
|
52
|
+
}),
|
|
53
|
+
useSensor(KeyboardSensor, {
|
|
54
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
const activeDragData = useMemo(() => {
|
|
58
|
+
if (!activeId) return null;
|
|
59
|
+
const idStr = String(activeId);
|
|
60
|
+
if (idStr.startsWith("palette-")) {
|
|
61
|
+
const componentType = idStr.replace("palette-", "");
|
|
62
|
+
return {
|
|
63
|
+
type: "palette",
|
|
64
|
+
componentType,
|
|
65
|
+
component: getComponentByType(componentType, components)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const nestedField = nestedFields.find((f) => f.id === idStr);
|
|
69
|
+
if (nestedField) {
|
|
70
|
+
return {
|
|
71
|
+
type: "field",
|
|
72
|
+
field: nestedField,
|
|
73
|
+
component: getComponentByType(nestedField.type, components)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}, [activeId, nestedFields, components]);
|
|
78
|
+
const handleDragStart = (event) => {
|
|
79
|
+
setActiveId(event.active.id);
|
|
80
|
+
};
|
|
81
|
+
const handleDragEnd = (event) => {
|
|
82
|
+
const { active, over } = event;
|
|
83
|
+
setActiveId(null);
|
|
84
|
+
if (!over) return;
|
|
85
|
+
const activeData = active.data.current;
|
|
86
|
+
if (activeData?.type === "palette") {
|
|
87
|
+
const { componentType } = activeData;
|
|
88
|
+
const component = getComponentByType(componentType, components);
|
|
89
|
+
if (component) {
|
|
90
|
+
const newField = {
|
|
91
|
+
id: generateFieldId(componentType),
|
|
92
|
+
type: componentType,
|
|
93
|
+
props: {
|
|
94
|
+
label: component.defaultProps.label || component.label,
|
|
95
|
+
...component.defaultProps
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
let insertIndex = nestedFields.length;
|
|
99
|
+
const overId = String(over.id);
|
|
100
|
+
if (overId === "drop-zone-start") {
|
|
101
|
+
insertIndex = 0;
|
|
102
|
+
} else if (overId.startsWith("drop-zone-")) {
|
|
103
|
+
const fieldId = overId.replace("drop-zone-", "");
|
|
104
|
+
const overIndex = nestedFields.findIndex((f) => f.id === fieldId);
|
|
105
|
+
if (overIndex !== -1) {
|
|
106
|
+
insertIndex = overIndex + 1;
|
|
107
|
+
}
|
|
108
|
+
} else if (overId !== "canvas") {
|
|
109
|
+
const overIndex = nestedFields.findIndex((f) => f.id === overId);
|
|
110
|
+
if (overIndex !== -1) {
|
|
111
|
+
insertIndex = overIndex + 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const newFields = [...nestedFields];
|
|
115
|
+
newFields.splice(insertIndex, 0, newField);
|
|
116
|
+
setNestedFields(newFields);
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (activeData?.type === "field" && active.id !== over.id) {
|
|
121
|
+
const oldIndex = nestedFields.findIndex((f) => f.id === active.id);
|
|
122
|
+
const newIndex = nestedFields.findIndex((f) => f.id === over.id);
|
|
123
|
+
if (oldIndex !== -1 && newIndex !== -1) {
|
|
124
|
+
setNestedFields(arrayMove(nestedFields, oldIndex, newIndex));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const handleDeleteField = useCallback((id) => {
|
|
129
|
+
setNestedFields((fields) => fields.filter((f) => f.id !== id));
|
|
130
|
+
}, []);
|
|
131
|
+
const handleEditField = useCallback((id) => {
|
|
132
|
+
setEditDialogFieldId(id);
|
|
133
|
+
}, []);
|
|
134
|
+
const handleUpdateField = useCallback(
|
|
135
|
+
(id, props, newId) => {
|
|
136
|
+
if (newId && newId !== id) {
|
|
137
|
+
const idExists = nestedFields.some((f) => f.id === newId && f.id !== id);
|
|
138
|
+
if (idExists) {
|
|
139
|
+
console.warn(`Cannot rename field "${id}" to "${newId}": a field with that ID already exists`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
setNestedFields(
|
|
144
|
+
(fields) => fields.map((f) => {
|
|
145
|
+
if (f.id !== id) return f;
|
|
146
|
+
return {
|
|
147
|
+
...f,
|
|
148
|
+
id: newId || f.id,
|
|
149
|
+
props: { ...f.props, ...props }
|
|
150
|
+
};
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
[nestedFields]
|
|
155
|
+
);
|
|
156
|
+
const handleSave = useCallback(() => {
|
|
157
|
+
if (!field) return;
|
|
158
|
+
onSave(field.id, nestedFields);
|
|
159
|
+
onOpenChange(false);
|
|
160
|
+
}, [field, nestedFields, onSave, onOpenChange]);
|
|
161
|
+
if (!field) return null;
|
|
162
|
+
const isObjectField = field.type === "object";
|
|
163
|
+
const Icon = isObjectField ? FolderOpen : List;
|
|
164
|
+
const fieldTypeLabel = isObjectField ? "Field Group" : "Repeating Group";
|
|
165
|
+
const nestedLabel = isObjectField ? "nested fields" : "item fields";
|
|
166
|
+
const editDialogField = nestedFields.find((f) => f.id === editDialogFieldId) || null;
|
|
167
|
+
const editDialogComponent = editDialogField ? getComponentByType(editDialogField.type, components) || null : null;
|
|
168
|
+
return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange, children: [
|
|
169
|
+
/* @__PURE__ */ jsxs(DialogContent, { className: "max-w-6xl! max-h-[90vh] overflow-hidden flex flex-col", children: [
|
|
170
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
171
|
+
/* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
|
|
172
|
+
/* @__PURE__ */ jsx(Icon, { className: "h-5 w-5 text-muted-foreground" }),
|
|
173
|
+
"Configure ",
|
|
174
|
+
fieldTypeLabel,
|
|
175
|
+
": ",
|
|
176
|
+
field.props.label
|
|
177
|
+
] }),
|
|
178
|
+
/* @__PURE__ */ jsxs(DialogDescription, { children: [
|
|
179
|
+
"Add and arrange the ",
|
|
180
|
+
nestedLabel,
|
|
181
|
+
" for this ",
|
|
182
|
+
fieldTypeLabel.toLowerCase(),
|
|
183
|
+
".",
|
|
184
|
+
isObjectField ? " These fields will be grouped together." : " Each item in the array will have these fields."
|
|
185
|
+
] })
|
|
186
|
+
] }),
|
|
187
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxs(
|
|
188
|
+
DndContext,
|
|
189
|
+
{
|
|
190
|
+
id: dndContextId,
|
|
191
|
+
sensors,
|
|
192
|
+
collisionDetection: closestCenter,
|
|
193
|
+
onDragStart: handleDragStart,
|
|
194
|
+
onDragEnd: handleDragEnd,
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-[50vh] gap-4", children: [
|
|
197
|
+
/* @__PURE__ */ jsx("div", { className: "w-48 overflow-auto shrink-0 border-r pr-4", children: /* @__PURE__ */ jsx(Palette, { components }) }),
|
|
198
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-auto", children: /* @__PURE__ */ jsx(
|
|
199
|
+
Canvas,
|
|
200
|
+
{
|
|
201
|
+
fields: nestedFields,
|
|
202
|
+
components,
|
|
203
|
+
onEditField: handleEditField,
|
|
204
|
+
onDeleteField: handleDeleteField,
|
|
205
|
+
isDraggingFromPalette: activeDragData?.type === "palette",
|
|
206
|
+
steps: [],
|
|
207
|
+
activeStepIndex: 0,
|
|
208
|
+
onActiveStepChange: () => {
|
|
209
|
+
},
|
|
210
|
+
onAddStep: () => {
|
|
211
|
+
},
|
|
212
|
+
onDeleteStep: () => {
|
|
213
|
+
},
|
|
214
|
+
onRenameStep: () => {
|
|
215
|
+
},
|
|
216
|
+
hideStepControls: true
|
|
217
|
+
}
|
|
218
|
+
) })
|
|
219
|
+
] }),
|
|
220
|
+
typeof document !== "undefined" && createPortal(
|
|
221
|
+
/* @__PURE__ */ jsxs(DragOverlay, { dropAnimation: null, modifiers: [snapCenterToCursor], children: [
|
|
222
|
+
activeDragData?.type === "palette" && activeDragData.component && /* @__PURE__ */ jsx(PaletteDragOverlay, { component: activeDragData.component }),
|
|
223
|
+
activeDragData?.type === "field" && activeDragData.field && /* @__PURE__ */ jsx(
|
|
224
|
+
FieldDragOverlay,
|
|
225
|
+
{
|
|
226
|
+
field: activeDragData.field,
|
|
227
|
+
component: activeDragData.component
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
] }),
|
|
231
|
+
document.body
|
|
232
|
+
)
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
) }),
|
|
236
|
+
/* @__PURE__ */ jsxs(DialogFooter, { className: "border-t pt-4", children: [
|
|
237
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground mr-auto", children: [
|
|
238
|
+
nestedFields.length,
|
|
239
|
+
" ",
|
|
240
|
+
nestedFields.length === 1 ? "field" : "fields"
|
|
241
|
+
] }),
|
|
242
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
243
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSave, children: "Save Fields" })
|
|
244
|
+
] })
|
|
245
|
+
] }),
|
|
246
|
+
/* @__PURE__ */ jsx(
|
|
247
|
+
EditFieldDialog,
|
|
248
|
+
{
|
|
249
|
+
open: editDialogFieldId !== null,
|
|
250
|
+
onOpenChange: (open2) => !open2 && setEditDialogFieldId(null),
|
|
251
|
+
field: editDialogField,
|
|
252
|
+
component: editDialogComponent,
|
|
253
|
+
onUpdate: handleUpdateField,
|
|
254
|
+
steps: [],
|
|
255
|
+
allFieldIds: nestedFields.map((f) => f.id)
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
] });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { NestedFieldEditorDialog };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
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');
|
|
6
|
+
const utils = require('../../lib/utils.cjs');
|
|
7
|
+
|
|
8
|
+
function PaletteItem({ component }) {
|
|
9
|
+
const { attributes, listeners, setNodeRef, isDragging } = core_esm.useDraggable({
|
|
10
|
+
id: `palette-${component.type}`,
|
|
11
|
+
data: {
|
|
12
|
+
type: "palette",
|
|
13
|
+
componentType: component.type
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const Icon = component.icon;
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
18
|
+
"div",
|
|
19
|
+
{
|
|
20
|
+
ref: setNodeRef,
|
|
21
|
+
...listeners,
|
|
22
|
+
...attributes,
|
|
23
|
+
className: utils.cn(
|
|
24
|
+
"flex items-center gap-3 p-3 rounded-lg border bg-card cursor-grab active:cursor-grabbing",
|
|
25
|
+
"hover:bg-accent hover:border-accent-foreground/20 transition-colors",
|
|
26
|
+
"touch-none select-none",
|
|
27
|
+
isDragging && "opacity-50"
|
|
28
|
+
),
|
|
29
|
+
children: [
|
|
30
|
+
Icon && /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "h-4 w-4 text-muted-foreground shrink-0" }),
|
|
31
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: component.label })
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
function Palette({ components, className }) {
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils.cn("flex flex-col gap-2", className), "data-testid": "form-builder-palette", children: [
|
|
38
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold text-muted-foreground mb-2", children: "Components" }),
|
|
39
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row flex-wrap lg:flex-col gap-2", children: components.map((component) => /* @__PURE__ */ jsxRuntime.jsx(PaletteItem, { component }, component.type)) })
|
|
40
|
+
] });
|
|
41
|
+
}
|
|
42
|
+
function PaletteDragOverlay({ component }) {
|
|
43
|
+
if (!component) return null;
|
|
44
|
+
const Icon = component.icon;
|
|
45
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 p-3 rounded-lg border bg-card shadow-lg cursor-grabbing", children: [
|
|
46
|
+
Icon && /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "h-4 w-4 text-muted-foreground shrink-0" }),
|
|
47
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: component.label })
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.Palette = Palette;
|
|
52
|
+
exports.PaletteDragOverlay = PaletteDragOverlay;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useDraggable } 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';
|
|
4
|
+
import { cn } from '../../lib/utils.mjs';
|
|
5
|
+
|
|
6
|
+
function PaletteItem({ component }) {
|
|
7
|
+
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
8
|
+
id: `palette-${component.type}`,
|
|
9
|
+
data: {
|
|
10
|
+
type: "palette",
|
|
11
|
+
componentType: component.type
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const Icon = component.icon;
|
|
15
|
+
return /* @__PURE__ */ jsxs(
|
|
16
|
+
"div",
|
|
17
|
+
{
|
|
18
|
+
ref: setNodeRef,
|
|
19
|
+
...listeners,
|
|
20
|
+
...attributes,
|
|
21
|
+
className: cn(
|
|
22
|
+
"flex items-center gap-3 p-3 rounded-lg border bg-card cursor-grab active:cursor-grabbing",
|
|
23
|
+
"hover:bg-accent hover:border-accent-foreground/20 transition-colors",
|
|
24
|
+
"touch-none select-none",
|
|
25
|
+
isDragging && "opacity-50"
|
|
26
|
+
),
|
|
27
|
+
children: [
|
|
28
|
+
Icon && /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4 text-muted-foreground shrink-0" }),
|
|
29
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: component.label })
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function Palette({ components, className }) {
|
|
35
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2", className), "data-testid": "form-builder-palette", children: [
|
|
36
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-muted-foreground mb-2", children: "Components" }),
|
|
37
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-row flex-wrap lg:flex-col gap-2", children: components.map((component) => /* @__PURE__ */ jsx(PaletteItem, { component }, component.type)) })
|
|
38
|
+
] });
|
|
39
|
+
}
|
|
40
|
+
function PaletteDragOverlay({ component }) {
|
|
41
|
+
if (!component) return null;
|
|
42
|
+
const Icon = component.icon;
|
|
43
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 p-3 rounded-lg border bg-card shadow-lg cursor-grabbing", children: [
|
|
44
|
+
Icon && /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4 text-muted-foreground shrink-0" }),
|
|
45
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: component.label })
|
|
46
|
+
] });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { Palette, PaletteDragOverlay };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function fieldsToProperties(fields, components, includeStepGroup = false) {
|
|
4
|
+
const properties = {};
|
|
5
|
+
for (const field of fields) {
|
|
6
|
+
const component = components.find((c) => c.type === field.type);
|
|
7
|
+
if (!component) {
|
|
8
|
+
console.warn(`Unknown component type: ${field.type}`);
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const isRequired = field.props.required ?? false;
|
|
12
|
+
const schemaProp = component.toJSONSchema(field.props, isRequired);
|
|
13
|
+
if (includeStepGroup && field.stepGroup !== void 0) {
|
|
14
|
+
schemaProp.stepGroup = field.stepGroup;
|
|
15
|
+
}
|
|
16
|
+
if (field.type === "object" && field.children && field.children.length > 0) {
|
|
17
|
+
schemaProp.properties = fieldsToProperties(field.children, components, false);
|
|
18
|
+
const childRequired = field.children.filter((child) => child.props.required).map((child) => child.id);
|
|
19
|
+
if (childRequired.length > 0) {
|
|
20
|
+
schemaProp.required = childRequired;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (field.type === "array" && field.itemTemplate && field.itemTemplate.length > 0) {
|
|
24
|
+
schemaProp.items = {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: fieldsToProperties(field.itemTemplate, components, false)
|
|
27
|
+
};
|
|
28
|
+
const itemRequired = field.itemTemplate.filter((item) => item.props.required).map((item) => item.id);
|
|
29
|
+
if (itemRequired.length > 0) {
|
|
30
|
+
schemaProp.items.required = itemRequired;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
properties[field.id] = schemaProp;
|
|
34
|
+
}
|
|
35
|
+
return properties;
|
|
36
|
+
}
|
|
37
|
+
function getRequiredFieldIds(fields) {
|
|
38
|
+
return fields.filter((f) => f.props.required).map((f) => f.id);
|
|
39
|
+
}
|
|
40
|
+
function fieldsToJSONSchema(fields, components, steps) {
|
|
41
|
+
const hasMultipleSteps = steps && steps.length > 1;
|
|
42
|
+
const properties = fieldsToProperties(fields, components, hasMultipleSteps);
|
|
43
|
+
const required = getRequiredFieldIds(fields);
|
|
44
|
+
return {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties,
|
|
47
|
+
...required.length > 0 ? { required } : {},
|
|
48
|
+
// Only include steps if there are multiple steps
|
|
49
|
+
...hasMultipleSteps ? { steps } : {}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function propertiesToFields(properties, requiredSet, components) {
|
|
53
|
+
const fields = [];
|
|
54
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
55
|
+
const isRequired = requiredSet.has(key);
|
|
56
|
+
let field = null;
|
|
57
|
+
for (const component of components) {
|
|
58
|
+
field = component.fromJSONSchema(prop, key, isRequired);
|
|
59
|
+
if (field) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (field) {
|
|
64
|
+
if (prop.stepGroup !== void 0) {
|
|
65
|
+
field.stepGroup = prop.stepGroup;
|
|
66
|
+
}
|
|
67
|
+
if (field.type === "object" && prop.properties) {
|
|
68
|
+
const childRequiredSet = new Set(prop.required || []);
|
|
69
|
+
field.children = propertiesToFields(prop.properties, childRequiredSet, components);
|
|
70
|
+
}
|
|
71
|
+
if (field.type === "array" && prop.items?.properties) {
|
|
72
|
+
const itemRequiredSet = new Set(prop.items.required || []);
|
|
73
|
+
field.itemTemplate = propertiesToFields(prop.items.properties, itemRequiredSet, components);
|
|
74
|
+
}
|
|
75
|
+
fields.push(field);
|
|
76
|
+
} else {
|
|
77
|
+
console.warn(`Could not parse JSON Schema property: ${key}`, prop);
|
|
78
|
+
fields.push({
|
|
79
|
+
id: key,
|
|
80
|
+
type: "text",
|
|
81
|
+
props: {
|
|
82
|
+
label: prop.title || key,
|
|
83
|
+
description: prop.description,
|
|
84
|
+
placeholder: prop.placeholder,
|
|
85
|
+
required: isRequired
|
|
86
|
+
},
|
|
87
|
+
// Include stepGroup even for fallback fields
|
|
88
|
+
...prop.stepGroup !== void 0 ? { stepGroup: prop.stepGroup } : {}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return fields;
|
|
93
|
+
}
|
|
94
|
+
function jsonSchemaToFieldsAndSteps(schema, components) {
|
|
95
|
+
if (!schema || !schema.properties) {
|
|
96
|
+
return { fields: [], steps: [] };
|
|
97
|
+
}
|
|
98
|
+
const requiredSet = new Set(schema.required || []);
|
|
99
|
+
const fields = propertiesToFields(schema.properties, requiredSet, components);
|
|
100
|
+
const steps = schema.steps || [];
|
|
101
|
+
return { fields, steps };
|
|
102
|
+
}
|
|
103
|
+
function generateFieldId(prefix = "field") {
|
|
104
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
105
|
+
}
|
|
106
|
+
function generateStepId() {
|
|
107
|
+
return `step_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
108
|
+
}
|
|
109
|
+
function createStep(index) {
|
|
110
|
+
return {
|
|
111
|
+
id: generateStepId(),
|
|
112
|
+
title: `Step ${index + 1}`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.createStep = createStep;
|
|
117
|
+
exports.fieldsToJSONSchema = fieldsToJSONSchema;
|
|
118
|
+
exports.generateFieldId = generateFieldId;
|
|
119
|
+
exports.generateStepId = generateStepId;
|
|
120
|
+
exports.jsonSchemaToFieldsAndSteps = jsonSchemaToFieldsAndSteps;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
function fieldsToProperties(fields, components, includeStepGroup = false) {
|
|
2
|
+
const properties = {};
|
|
3
|
+
for (const field of fields) {
|
|
4
|
+
const component = components.find((c) => c.type === field.type);
|
|
5
|
+
if (!component) {
|
|
6
|
+
console.warn(`Unknown component type: ${field.type}`);
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
const isRequired = field.props.required ?? false;
|
|
10
|
+
const schemaProp = component.toJSONSchema(field.props, isRequired);
|
|
11
|
+
if (includeStepGroup && field.stepGroup !== void 0) {
|
|
12
|
+
schemaProp.stepGroup = field.stepGroup;
|
|
13
|
+
}
|
|
14
|
+
if (field.type === "object" && field.children && field.children.length > 0) {
|
|
15
|
+
schemaProp.properties = fieldsToProperties(field.children, components, false);
|
|
16
|
+
const childRequired = field.children.filter((child) => child.props.required).map((child) => child.id);
|
|
17
|
+
if (childRequired.length > 0) {
|
|
18
|
+
schemaProp.required = childRequired;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (field.type === "array" && field.itemTemplate && field.itemTemplate.length > 0) {
|
|
22
|
+
schemaProp.items = {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: fieldsToProperties(field.itemTemplate, components, false)
|
|
25
|
+
};
|
|
26
|
+
const itemRequired = field.itemTemplate.filter((item) => item.props.required).map((item) => item.id);
|
|
27
|
+
if (itemRequired.length > 0) {
|
|
28
|
+
schemaProp.items.required = itemRequired;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
properties[field.id] = schemaProp;
|
|
32
|
+
}
|
|
33
|
+
return properties;
|
|
34
|
+
}
|
|
35
|
+
function getRequiredFieldIds(fields) {
|
|
36
|
+
return fields.filter((f) => f.props.required).map((f) => f.id);
|
|
37
|
+
}
|
|
38
|
+
function fieldsToJSONSchema(fields, components, steps) {
|
|
39
|
+
const hasMultipleSteps = steps && steps.length > 1;
|
|
40
|
+
const properties = fieldsToProperties(fields, components, hasMultipleSteps);
|
|
41
|
+
const required = getRequiredFieldIds(fields);
|
|
42
|
+
return {
|
|
43
|
+
type: "object",
|
|
44
|
+
properties,
|
|
45
|
+
...required.length > 0 ? { required } : {},
|
|
46
|
+
// Only include steps if there are multiple steps
|
|
47
|
+
...hasMultipleSteps ? { steps } : {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function propertiesToFields(properties, requiredSet, components) {
|
|
51
|
+
const fields = [];
|
|
52
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
53
|
+
const isRequired = requiredSet.has(key);
|
|
54
|
+
let field = null;
|
|
55
|
+
for (const component of components) {
|
|
56
|
+
field = component.fromJSONSchema(prop, key, isRequired);
|
|
57
|
+
if (field) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (field) {
|
|
62
|
+
if (prop.stepGroup !== void 0) {
|
|
63
|
+
field.stepGroup = prop.stepGroup;
|
|
64
|
+
}
|
|
65
|
+
if (field.type === "object" && prop.properties) {
|
|
66
|
+
const childRequiredSet = new Set(prop.required || []);
|
|
67
|
+
field.children = propertiesToFields(prop.properties, childRequiredSet, components);
|
|
68
|
+
}
|
|
69
|
+
if (field.type === "array" && prop.items?.properties) {
|
|
70
|
+
const itemRequiredSet = new Set(prop.items.required || []);
|
|
71
|
+
field.itemTemplate = propertiesToFields(prop.items.properties, itemRequiredSet, components);
|
|
72
|
+
}
|
|
73
|
+
fields.push(field);
|
|
74
|
+
} else {
|
|
75
|
+
console.warn(`Could not parse JSON Schema property: ${key}`, prop);
|
|
76
|
+
fields.push({
|
|
77
|
+
id: key,
|
|
78
|
+
type: "text",
|
|
79
|
+
props: {
|
|
80
|
+
label: prop.title || key,
|
|
81
|
+
description: prop.description,
|
|
82
|
+
placeholder: prop.placeholder,
|
|
83
|
+
required: isRequired
|
|
84
|
+
},
|
|
85
|
+
// Include stepGroup even for fallback fields
|
|
86
|
+
...prop.stepGroup !== void 0 ? { stepGroup: prop.stepGroup } : {}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return fields;
|
|
91
|
+
}
|
|
92
|
+
function jsonSchemaToFieldsAndSteps(schema, components) {
|
|
93
|
+
if (!schema || !schema.properties) {
|
|
94
|
+
return { fields: [], steps: [] };
|
|
95
|
+
}
|
|
96
|
+
const requiredSet = new Set(schema.required || []);
|
|
97
|
+
const fields = propertiesToFields(schema.properties, requiredSet, components);
|
|
98
|
+
const steps = schema.steps || [];
|
|
99
|
+
return { fields, steps };
|
|
100
|
+
}
|
|
101
|
+
function generateFieldId(prefix = "field") {
|
|
102
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
103
|
+
}
|
|
104
|
+
function generateStepId() {
|
|
105
|
+
return `step_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
106
|
+
}
|
|
107
|
+
function createStep(index) {
|
|
108
|
+
return {
|
|
109
|
+
id: generateStepId(),
|
|
110
|
+
title: `Step ${index + 1}`
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { createStep, fieldsToJSONSchema, generateFieldId, generateStepId, jsonSchemaToFieldsAndSteps };
|