@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,553 @@
|
|
|
1
|
+
import { FolderOpen, List, Lock, Globe, Phone, Calendar, AlignLeft, ToggleLeft, Circle, ChevronDown, CheckSquare, Hash, Type, Mail } from 'lucide-react';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defineComponent } from '../types.mjs';
|
|
4
|
+
import { baseMetaSchema, objectValidationSchema, arrayValidationSchema, baseMetaSchemaWithPlaceholder, DEFAULT_VALUE_SCHEMAS, stringValidationSchema, dateValidationSchema, booleanValidationSchema, enumOptionsSchema, numberValidationSchema } from '../validation-schemas.mjs';
|
|
5
|
+
|
|
6
|
+
function toNumber(value) {
|
|
7
|
+
if (value == null || value === "") return void 0;
|
|
8
|
+
const num = Number(value);
|
|
9
|
+
return isNaN(num) ? void 0 : num;
|
|
10
|
+
}
|
|
11
|
+
function buildInputProps(placeholder, inputType) {
|
|
12
|
+
const props = {};
|
|
13
|
+
if (placeholder) props.placeholder = placeholder;
|
|
14
|
+
if (inputType) props.type = inputType;
|
|
15
|
+
return Object.keys(props).length > 0 ? props : void 0;
|
|
16
|
+
}
|
|
17
|
+
function getPlaceholder(prop) {
|
|
18
|
+
return prop.inputProps?.placeholder || prop.placeholder;
|
|
19
|
+
}
|
|
20
|
+
function getLabel(prop, key) {
|
|
21
|
+
return prop.label || prop.title || key;
|
|
22
|
+
}
|
|
23
|
+
const textFieldDefinition = defineComponent({
|
|
24
|
+
type: "text",
|
|
25
|
+
backingType: "string",
|
|
26
|
+
label: "Text Input",
|
|
27
|
+
icon: Type,
|
|
28
|
+
defaultProps: {
|
|
29
|
+
label: "Text Field",
|
|
30
|
+
placeholder: "",
|
|
31
|
+
required: false
|
|
32
|
+
},
|
|
33
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(stringValidationSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.string })),
|
|
34
|
+
toJSONSchema: (props) => ({
|
|
35
|
+
type: "string",
|
|
36
|
+
label: props.label,
|
|
37
|
+
description: props.description,
|
|
38
|
+
inputProps: buildInputProps(props.placeholder),
|
|
39
|
+
default: props.defaultValue,
|
|
40
|
+
minLength: toNumber(props.minLength),
|
|
41
|
+
maxLength: toNumber(props.maxLength)
|
|
42
|
+
}),
|
|
43
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
44
|
+
if (prop.type !== "string" || prop.enum || prop.fieldType || prop.inputType || prop.format || prop.inputProps?.type) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
id: key,
|
|
49
|
+
type: "text",
|
|
50
|
+
props: {
|
|
51
|
+
label: getLabel(prop, key),
|
|
52
|
+
placeholder: getPlaceholder(prop),
|
|
53
|
+
description: prop.description,
|
|
54
|
+
required: isRequired,
|
|
55
|
+
defaultValue: prop.default,
|
|
56
|
+
minLength: prop.minLength,
|
|
57
|
+
maxLength: prop.maxLength
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const emailFieldDefinition = defineComponent({
|
|
63
|
+
type: "email",
|
|
64
|
+
backingType: "string",
|
|
65
|
+
label: "Email",
|
|
66
|
+
icon: Mail,
|
|
67
|
+
defaultProps: {
|
|
68
|
+
label: "Email",
|
|
69
|
+
placeholder: "email@example.com",
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
72
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.string })),
|
|
73
|
+
toJSONSchema: (props) => ({
|
|
74
|
+
type: "string",
|
|
75
|
+
label: props.label,
|
|
76
|
+
description: props.description,
|
|
77
|
+
inputProps: buildInputProps(props.placeholder, "email"),
|
|
78
|
+
default: props.defaultValue,
|
|
79
|
+
format: "email"
|
|
80
|
+
}),
|
|
81
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
82
|
+
if (prop.type !== "string" || prop.format !== "email" && prop.inputType !== "email" && prop.inputProps?.type !== "email") {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
id: key,
|
|
87
|
+
type: "email",
|
|
88
|
+
props: {
|
|
89
|
+
label: getLabel(prop, key),
|
|
90
|
+
placeholder: getPlaceholder(prop),
|
|
91
|
+
description: prop.description,
|
|
92
|
+
required: isRequired,
|
|
93
|
+
defaultValue: prop.default
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const numberFieldDefinition = defineComponent({
|
|
99
|
+
type: "number",
|
|
100
|
+
backingType: "number",
|
|
101
|
+
label: "Number",
|
|
102
|
+
icon: Hash,
|
|
103
|
+
defaultProps: {
|
|
104
|
+
label: "Number",
|
|
105
|
+
required: false
|
|
106
|
+
},
|
|
107
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(numberValidationSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.number })),
|
|
108
|
+
toJSONSchema: (props) => ({
|
|
109
|
+
type: "number",
|
|
110
|
+
label: props.label,
|
|
111
|
+
description: props.description,
|
|
112
|
+
inputProps: buildInputProps(props.placeholder),
|
|
113
|
+
default: props.defaultValue,
|
|
114
|
+
// toNumber handles form input which may come as strings
|
|
115
|
+
minimum: toNumber(props.min),
|
|
116
|
+
maximum: toNumber(props.max)
|
|
117
|
+
}),
|
|
118
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
119
|
+
if (prop.type !== "number" && prop.type !== "integer") {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
id: key,
|
|
124
|
+
type: "number",
|
|
125
|
+
props: {
|
|
126
|
+
label: getLabel(prop, key),
|
|
127
|
+
placeholder: getPlaceholder(prop),
|
|
128
|
+
description: prop.description,
|
|
129
|
+
required: isRequired,
|
|
130
|
+
defaultValue: prop.default,
|
|
131
|
+
min: prop.minimum,
|
|
132
|
+
max: prop.maximum
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const textareaFieldDefinition = defineComponent({
|
|
138
|
+
type: "textarea",
|
|
139
|
+
backingType: "string",
|
|
140
|
+
label: "Text Area",
|
|
141
|
+
icon: AlignLeft,
|
|
142
|
+
defaultProps: {
|
|
143
|
+
label: "Text Area",
|
|
144
|
+
placeholder: "",
|
|
145
|
+
required: false
|
|
146
|
+
},
|
|
147
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(stringValidationSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.string })),
|
|
148
|
+
toJSONSchema: (props) => ({
|
|
149
|
+
type: "string",
|
|
150
|
+
label: props.label,
|
|
151
|
+
description: props.description,
|
|
152
|
+
fieldType: "textarea",
|
|
153
|
+
inputProps: buildInputProps(props.placeholder),
|
|
154
|
+
default: props.defaultValue,
|
|
155
|
+
minLength: toNumber(props.minLength),
|
|
156
|
+
maxLength: toNumber(props.maxLength)
|
|
157
|
+
}),
|
|
158
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
159
|
+
if (prop.type !== "string" || prop.fieldType !== "textarea") {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
id: key,
|
|
164
|
+
type: "textarea",
|
|
165
|
+
props: {
|
|
166
|
+
label: getLabel(prop, key),
|
|
167
|
+
placeholder: getPlaceholder(prop),
|
|
168
|
+
description: prop.description,
|
|
169
|
+
required: isRequired,
|
|
170
|
+
defaultValue: prop.default,
|
|
171
|
+
minLength: prop.minLength,
|
|
172
|
+
maxLength: prop.maxLength
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
const checkboxFieldDefinition = defineComponent({
|
|
178
|
+
type: "checkbox",
|
|
179
|
+
backingType: "boolean",
|
|
180
|
+
label: "Checkbox",
|
|
181
|
+
icon: CheckSquare,
|
|
182
|
+
defaultProps: {
|
|
183
|
+
label: "Checkbox",
|
|
184
|
+
required: false
|
|
185
|
+
},
|
|
186
|
+
propertiesSchema: baseMetaSchema.merge(booleanValidationSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.boolean })),
|
|
187
|
+
toJSONSchema: (props) => ({
|
|
188
|
+
type: "boolean",
|
|
189
|
+
label: props.label,
|
|
190
|
+
description: props.description,
|
|
191
|
+
default: props.defaultValue
|
|
192
|
+
}),
|
|
193
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
194
|
+
if (prop.type !== "boolean" || prop.fieldType === "switch") {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
id: key,
|
|
199
|
+
type: "checkbox",
|
|
200
|
+
props: {
|
|
201
|
+
label: getLabel(prop, key),
|
|
202
|
+
description: prop.description,
|
|
203
|
+
required: isRequired,
|
|
204
|
+
defaultValue: prop.default
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
const switchFieldDefinition = defineComponent({
|
|
210
|
+
type: "switch",
|
|
211
|
+
backingType: "boolean",
|
|
212
|
+
label: "Switch",
|
|
213
|
+
icon: ToggleLeft,
|
|
214
|
+
defaultProps: {
|
|
215
|
+
label: "Switch",
|
|
216
|
+
required: false
|
|
217
|
+
},
|
|
218
|
+
propertiesSchema: baseMetaSchema.merge(booleanValidationSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.boolean })),
|
|
219
|
+
toJSONSchema: (props) => ({
|
|
220
|
+
type: "boolean",
|
|
221
|
+
label: props.label,
|
|
222
|
+
description: props.description,
|
|
223
|
+
fieldType: "switch",
|
|
224
|
+
default: props.defaultValue
|
|
225
|
+
}),
|
|
226
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
227
|
+
if (prop.type !== "boolean" || prop.fieldType !== "switch") {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
id: key,
|
|
232
|
+
type: "switch",
|
|
233
|
+
props: {
|
|
234
|
+
label: getLabel(prop, key),
|
|
235
|
+
description: prop.description,
|
|
236
|
+
required: isRequired,
|
|
237
|
+
defaultValue: prop.default
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
const selectFieldDefinition = defineComponent({
|
|
243
|
+
type: "select",
|
|
244
|
+
backingType: "enum",
|
|
245
|
+
label: "Select",
|
|
246
|
+
icon: ChevronDown,
|
|
247
|
+
defaultProps: {
|
|
248
|
+
label: "Select Field",
|
|
249
|
+
required: false,
|
|
250
|
+
options: ["Option 1", "Option 2", "Option 3"]
|
|
251
|
+
},
|
|
252
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(enumOptionsSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.enum })),
|
|
253
|
+
toJSONSchema: (props) => ({
|
|
254
|
+
type: "string",
|
|
255
|
+
label: props.label,
|
|
256
|
+
description: props.description,
|
|
257
|
+
inputProps: buildInputProps(props.placeholder),
|
|
258
|
+
default: props.defaultValue,
|
|
259
|
+
enum: props.options
|
|
260
|
+
}),
|
|
261
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
262
|
+
if (prop.type !== "string" || !prop.enum || prop.fieldType === "radio") {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
id: key,
|
|
267
|
+
type: "select",
|
|
268
|
+
props: {
|
|
269
|
+
label: getLabel(prop, key),
|
|
270
|
+
placeholder: getPlaceholder(prop),
|
|
271
|
+
description: prop.description,
|
|
272
|
+
required: isRequired,
|
|
273
|
+
defaultValue: prop.default,
|
|
274
|
+
options: prop.enum
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const radioFieldDefinition = defineComponent({
|
|
280
|
+
type: "radio",
|
|
281
|
+
backingType: "enum",
|
|
282
|
+
label: "Radio Group",
|
|
283
|
+
icon: Circle,
|
|
284
|
+
defaultProps: {
|
|
285
|
+
label: "Radio Group",
|
|
286
|
+
required: false,
|
|
287
|
+
options: ["Option 1", "Option 2", "Option 3"]
|
|
288
|
+
},
|
|
289
|
+
propertiesSchema: baseMetaSchema.merge(enumOptionsSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.enum })),
|
|
290
|
+
toJSONSchema: (props) => ({
|
|
291
|
+
type: "string",
|
|
292
|
+
label: props.label,
|
|
293
|
+
description: props.description,
|
|
294
|
+
fieldType: "radio",
|
|
295
|
+
default: props.defaultValue,
|
|
296
|
+
enum: props.options
|
|
297
|
+
}),
|
|
298
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
299
|
+
if (prop.type !== "string" || !prop.enum || prop.fieldType !== "radio") {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
id: key,
|
|
304
|
+
type: "radio",
|
|
305
|
+
props: {
|
|
306
|
+
label: getLabel(prop, key),
|
|
307
|
+
description: prop.description,
|
|
308
|
+
required: isRequired,
|
|
309
|
+
defaultValue: prop.default,
|
|
310
|
+
options: prop.enum
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
const passwordFieldDefinition = defineComponent({
|
|
316
|
+
type: "password",
|
|
317
|
+
backingType: "string",
|
|
318
|
+
label: "Password",
|
|
319
|
+
icon: Lock,
|
|
320
|
+
defaultProps: {
|
|
321
|
+
label: "Password",
|
|
322
|
+
placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",
|
|
323
|
+
required: false
|
|
324
|
+
},
|
|
325
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(stringValidationSchema).merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.string })),
|
|
326
|
+
toJSONSchema: (props) => ({
|
|
327
|
+
type: "string",
|
|
328
|
+
label: props.label,
|
|
329
|
+
description: props.description,
|
|
330
|
+
inputProps: buildInputProps(props.placeholder, "password"),
|
|
331
|
+
default: props.defaultValue,
|
|
332
|
+
minLength: toNumber(props.minLength),
|
|
333
|
+
maxLength: toNumber(props.maxLength)
|
|
334
|
+
}),
|
|
335
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
336
|
+
if (prop.type !== "string" || prop.inputType !== "password" && prop.inputProps?.type !== "password") {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
id: key,
|
|
341
|
+
type: "password",
|
|
342
|
+
props: {
|
|
343
|
+
label: getLabel(prop, key),
|
|
344
|
+
placeholder: getPlaceholder(prop),
|
|
345
|
+
description: prop.description,
|
|
346
|
+
required: isRequired,
|
|
347
|
+
defaultValue: prop.default,
|
|
348
|
+
minLength: prop.minLength,
|
|
349
|
+
maxLength: prop.maxLength
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
const urlFieldDefinition = defineComponent({
|
|
355
|
+
type: "url",
|
|
356
|
+
backingType: "string",
|
|
357
|
+
label: "Website URL",
|
|
358
|
+
icon: Globe,
|
|
359
|
+
defaultProps: {
|
|
360
|
+
label: "Website",
|
|
361
|
+
placeholder: "https://example.com",
|
|
362
|
+
required: false
|
|
363
|
+
},
|
|
364
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.string })),
|
|
365
|
+
toJSONSchema: (props) => ({
|
|
366
|
+
type: "string",
|
|
367
|
+
label: props.label,
|
|
368
|
+
description: props.description,
|
|
369
|
+
inputProps: buildInputProps(props.placeholder),
|
|
370
|
+
default: props.defaultValue,
|
|
371
|
+
format: "uri"
|
|
372
|
+
}),
|
|
373
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
374
|
+
if (prop.type !== "string" || prop.format !== "uri") {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
id: key,
|
|
379
|
+
type: "url",
|
|
380
|
+
props: {
|
|
381
|
+
label: getLabel(prop, key),
|
|
382
|
+
placeholder: getPlaceholder(prop),
|
|
383
|
+
description: prop.description,
|
|
384
|
+
required: isRequired,
|
|
385
|
+
defaultValue: prop.default
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
const phoneFieldDefinition = defineComponent({
|
|
391
|
+
type: "phone",
|
|
392
|
+
backingType: "string",
|
|
393
|
+
label: "Phone Number",
|
|
394
|
+
icon: Phone,
|
|
395
|
+
defaultProps: {
|
|
396
|
+
label: "Phone Number",
|
|
397
|
+
placeholder: "+1 (555) 123-4567",
|
|
398
|
+
required: false
|
|
399
|
+
},
|
|
400
|
+
propertiesSchema: baseMetaSchemaWithPlaceholder.merge(z.object({ defaultValue: DEFAULT_VALUE_SCHEMAS.string })),
|
|
401
|
+
toJSONSchema: (props) => ({
|
|
402
|
+
type: "string",
|
|
403
|
+
label: props.label,
|
|
404
|
+
description: props.description,
|
|
405
|
+
inputProps: buildInputProps(props.placeholder, "tel"),
|
|
406
|
+
default: props.defaultValue
|
|
407
|
+
}),
|
|
408
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
409
|
+
if (prop.type !== "string" || prop.inputType !== "tel" && prop.inputProps?.type !== "tel") {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
id: key,
|
|
414
|
+
type: "phone",
|
|
415
|
+
props: {
|
|
416
|
+
label: getLabel(prop, key),
|
|
417
|
+
placeholder: getPlaceholder(prop),
|
|
418
|
+
description: prop.description,
|
|
419
|
+
required: isRequired,
|
|
420
|
+
defaultValue: prop.default
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
const dateFieldDefinition = defineComponent({
|
|
426
|
+
type: "date",
|
|
427
|
+
backingType: "date",
|
|
428
|
+
label: "Date Picker",
|
|
429
|
+
icon: Calendar,
|
|
430
|
+
defaultProps: {
|
|
431
|
+
label: "Date",
|
|
432
|
+
required: false
|
|
433
|
+
},
|
|
434
|
+
propertiesSchema: baseMetaSchema.merge(dateValidationSchema),
|
|
435
|
+
toJSONSchema: (props) => ({
|
|
436
|
+
type: "string",
|
|
437
|
+
format: "date-time",
|
|
438
|
+
fieldType: "date",
|
|
439
|
+
label: props.label,
|
|
440
|
+
description: props.description
|
|
441
|
+
}),
|
|
442
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
443
|
+
if (prop.type !== "string" || prop.format !== "date-time" && prop.fieldType !== "date") {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
id: key,
|
|
448
|
+
type: "date",
|
|
449
|
+
props: {
|
|
450
|
+
label: getLabel(prop, key),
|
|
451
|
+
description: prop.description,
|
|
452
|
+
required: isRequired
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
const objectFieldDefinition = {
|
|
458
|
+
type: "object",
|
|
459
|
+
label: "Field Group",
|
|
460
|
+
icon: FolderOpen,
|
|
461
|
+
defaultProps: {
|
|
462
|
+
label: "Field Group",
|
|
463
|
+
required: false
|
|
464
|
+
},
|
|
465
|
+
propertiesSchema: baseMetaSchema.extend(objectValidationSchema.shape),
|
|
466
|
+
toJSONSchema: (props) => ({
|
|
467
|
+
type: "object",
|
|
468
|
+
label: props.label,
|
|
469
|
+
description: props.description,
|
|
470
|
+
// properties will be filled in by schema-utils from field.children
|
|
471
|
+
properties: {}
|
|
472
|
+
}),
|
|
473
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
474
|
+
if (prop.type !== "object" || !prop.properties) {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
id: key,
|
|
479
|
+
type: "object",
|
|
480
|
+
props: {
|
|
481
|
+
label: getLabel(prop, key),
|
|
482
|
+
description: prop.description,
|
|
483
|
+
required: isRequired
|
|
484
|
+
},
|
|
485
|
+
// children will be filled in by schema-utils
|
|
486
|
+
children: []
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const arrayFieldDefinition = {
|
|
491
|
+
type: "array",
|
|
492
|
+
label: "Repeating Group",
|
|
493
|
+
icon: List,
|
|
494
|
+
defaultProps: {
|
|
495
|
+
label: "Items",
|
|
496
|
+
required: false
|
|
497
|
+
},
|
|
498
|
+
propertiesSchema: baseMetaSchema.extend(arrayValidationSchema.shape),
|
|
499
|
+
toJSONSchema: (props) => ({
|
|
500
|
+
type: "array",
|
|
501
|
+
label: props.label,
|
|
502
|
+
description: props.description,
|
|
503
|
+
minItems: props.minItems,
|
|
504
|
+
maxItems: props.maxItems,
|
|
505
|
+
// items will be filled in by schema-utils from field.itemTemplate
|
|
506
|
+
items: {
|
|
507
|
+
type: "object",
|
|
508
|
+
properties: {}
|
|
509
|
+
}
|
|
510
|
+
}),
|
|
511
|
+
fromJSONSchema: (prop, key, isRequired) => {
|
|
512
|
+
if (prop.type !== "array" || !prop.items) {
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
id: key,
|
|
517
|
+
type: "array",
|
|
518
|
+
props: {
|
|
519
|
+
label: getLabel(prop, key),
|
|
520
|
+
description: prop.description,
|
|
521
|
+
required: isRequired,
|
|
522
|
+
minItems: prop.minItems,
|
|
523
|
+
maxItems: prop.maxItems
|
|
524
|
+
},
|
|
525
|
+
// itemTemplate will be filled in by schema-utils
|
|
526
|
+
itemTemplate: []
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
const defaultComponents = [
|
|
531
|
+
// Container types (must be before primitives to match object/array JSON Schema)
|
|
532
|
+
objectFieldDefinition,
|
|
533
|
+
arrayFieldDefinition,
|
|
534
|
+
// Specific types first
|
|
535
|
+
emailFieldDefinition,
|
|
536
|
+
passwordFieldDefinition,
|
|
537
|
+
urlFieldDefinition,
|
|
538
|
+
phoneFieldDefinition,
|
|
539
|
+
dateFieldDefinition,
|
|
540
|
+
textareaFieldDefinition,
|
|
541
|
+
switchFieldDefinition,
|
|
542
|
+
radioFieldDefinition,
|
|
543
|
+
selectFieldDefinition,
|
|
544
|
+
checkboxFieldDefinition,
|
|
545
|
+
numberFieldDefinition,
|
|
546
|
+
// Generic fallback last
|
|
547
|
+
textFieldDefinition
|
|
548
|
+
];
|
|
549
|
+
function getComponentByType(type, components = defaultComponents) {
|
|
550
|
+
return components.find((c) => c.type === type);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export { arrayFieldDefinition, checkboxFieldDefinition, dateFieldDefinition, defaultComponents, emailFieldDefinition, getComponentByType, numberFieldDefinition, objectFieldDefinition, passwordFieldDefinition, phoneFieldDefinition, radioFieldDefinition, selectFieldDefinition, switchFieldDefinition, textFieldDefinition, textareaFieldDefinition, urlFieldDefinition };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const index = require('../auto-form/index.cjs');
|
|
7
|
+
const utils = require('../auto-form/utils.cjs');
|
|
8
|
+
const input = require('../input.cjs');
|
|
9
|
+
const label = require('../label.cjs');
|
|
10
|
+
const button = require('../button.cjs');
|
|
11
|
+
const dialog = require('../dialog.cjs');
|
|
12
|
+
const select = require('../select.cjs');
|
|
13
|
+
|
|
14
|
+
function EditFieldDialog({
|
|
15
|
+
open,
|
|
16
|
+
onOpenChange,
|
|
17
|
+
field,
|
|
18
|
+
component,
|
|
19
|
+
onUpdate,
|
|
20
|
+
steps = [],
|
|
21
|
+
allFieldIds = []
|
|
22
|
+
}) {
|
|
23
|
+
const initialValues = React.useMemo(() => {
|
|
24
|
+
if (!field) return { fieldName: "", props: {}, key: "" };
|
|
25
|
+
const values = { ...field.props };
|
|
26
|
+
if (Array.isArray(values.options)) {
|
|
27
|
+
values.options = values.options.join("\n");
|
|
28
|
+
}
|
|
29
|
+
return { fieldName: field.id, props: values, key: `${field.id}-${open}` };
|
|
30
|
+
}, [field, open]);
|
|
31
|
+
const [fieldNameOverride, setFieldNameOverride] = React.useState(null);
|
|
32
|
+
const [localPropsOverride, setLocalPropsOverride] = React.useState(null);
|
|
33
|
+
const [stepGroupOverride, setStepGroupOverride] = React.useState(null);
|
|
34
|
+
const fieldName = fieldNameOverride ?? initialValues.fieldName;
|
|
35
|
+
const localProps = localPropsOverride ?? initialValues.props;
|
|
36
|
+
const localStepGroup = stepGroupOverride ?? field?.stepGroup ?? 0;
|
|
37
|
+
const isDuplicateId = React.useMemo(() => {
|
|
38
|
+
if (!field || fieldName === field.id) return false;
|
|
39
|
+
return allFieldIds.some((id) => id === fieldName && id !== field.id);
|
|
40
|
+
}, [fieldName, field, allFieldIds]);
|
|
41
|
+
const [prevInitial, setPrevInitial] = React.useState(initialValues);
|
|
42
|
+
if (prevInitial !== initialValues) {
|
|
43
|
+
setPrevInitial(initialValues);
|
|
44
|
+
setFieldNameOverride(null);
|
|
45
|
+
setLocalPropsOverride(null);
|
|
46
|
+
setStepGroupOverride(null);
|
|
47
|
+
}
|
|
48
|
+
const formKey = initialValues.key;
|
|
49
|
+
const handleValuesChange = React.useCallback(
|
|
50
|
+
(values) => {
|
|
51
|
+
setLocalPropsOverride(values);
|
|
52
|
+
},
|
|
53
|
+
[]
|
|
54
|
+
);
|
|
55
|
+
const handleSave = React.useCallback(() => {
|
|
56
|
+
if (!field) return;
|
|
57
|
+
const props = { ...localProps };
|
|
58
|
+
if (typeof props.options === "string") {
|
|
59
|
+
props.options = props.options.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
const newId = fieldName !== field.id ? fieldName : void 0;
|
|
62
|
+
const stepGroup = stepGroupOverride !== null && stepGroupOverride !== field.stepGroup ? stepGroupOverride : void 0;
|
|
63
|
+
onUpdate(field.id, props, newId, stepGroup);
|
|
64
|
+
onOpenChange(false);
|
|
65
|
+
}, [field, localProps, fieldName, onUpdate, onOpenChange, stepGroupOverride]);
|
|
66
|
+
if (!field || !component) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const Icon = component.icon;
|
|
70
|
+
const jsonSchema = component.propertiesSchema.toJSONSchema();
|
|
71
|
+
const fieldConfig = utils.buildFieldConfigFromJsonSchema(jsonSchema);
|
|
72
|
+
return /* @__PURE__ */ jsxRuntime.jsx(dialog.Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogContent, { className: "max-w-md max-h-[90vh] overflow-y-auto", children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogHeader, { children: [
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogTitle, { className: "flex items-center gap-2", children: [
|
|
75
|
+
Icon && /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "h-5 w-5 text-muted-foreground" }),
|
|
76
|
+
"Edit ",
|
|
77
|
+
component.label
|
|
78
|
+
] }),
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogDescription, { children: "Configure the properties for this field" })
|
|
80
|
+
] }),
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 py-4", children: [
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(label.Label, { htmlFor: "field-name", children: "Field Name" }),
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
85
|
+
input.Input,
|
|
86
|
+
{
|
|
87
|
+
id: "field-name",
|
|
88
|
+
value: fieldName,
|
|
89
|
+
onChange: (e) => setFieldNameOverride(e.target.value),
|
|
90
|
+
placeholder: "Enter field name",
|
|
91
|
+
className: isDuplicateId ? "border-destructive focus-visible:ring-destructive" : "",
|
|
92
|
+
"aria-invalid": isDuplicateId
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
isDuplicateId ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-destructive", children: "A field with this name already exists. Please choose a different name." }) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "This is the key used in the form data and JSON schema" })
|
|
96
|
+
] }),
|
|
97
|
+
steps.length > 1 && field && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
98
|
+
/* @__PURE__ */ jsxRuntime.jsx(label.Label, { htmlFor: "field-step", children: "Step" }),
|
|
99
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
100
|
+
select.Select,
|
|
101
|
+
{
|
|
102
|
+
value: String(localStepGroup),
|
|
103
|
+
onValueChange: (value) => setStepGroupOverride(parseInt(value, 10)),
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectTrigger, { id: "field-step", children: /* @__PURE__ */ jsxRuntime.jsx(select.SelectValue, { placeholder: "Select step" }) }),
|
|
106
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectContent, { children: steps.map((step, index) => /* @__PURE__ */ jsxRuntime.jsx(select.SelectItem, { value: String(index), children: step.title }, step.id)) })
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
),
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Which step this field belongs to" })
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t pt-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
113
|
+
index,
|
|
114
|
+
{
|
|
115
|
+
formSchema: component.propertiesSchema,
|
|
116
|
+
values: localProps,
|
|
117
|
+
onValuesChange: handleValuesChange,
|
|
118
|
+
fieldConfig,
|
|
119
|
+
className: "space-y-4"
|
|
120
|
+
},
|
|
121
|
+
formKey
|
|
122
|
+
) })
|
|
123
|
+
] }),
|
|
124
|
+
/* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogFooter, { children: [
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsx(button.Button, { onClick: handleSave, disabled: isDuplicateId, children: "Save Changes" })
|
|
127
|
+
] })
|
|
128
|
+
] }) });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
exports.EditFieldDialog = EditFieldDialog;
|