@k3-universe/react-kit 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.js +413 -403
  2. package/dist/kit/builder/data-table/types.d.ts +1 -1
  3. package/dist/kit/builder/data-table/types.d.ts.map +1 -1
  4. package/dist/kit/builder/form/components/FormBuilder.d.ts +3 -172
  5. package/dist/kit/builder/form/components/FormBuilder.d.ts.map +1 -1
  6. package/dist/kit/builder/form/components/FormBuilderField.d.ts +8 -8
  7. package/dist/kit/builder/form/components/FormBuilderField.d.ts.map +1 -1
  8. package/dist/kit/builder/form/components/fields/types.d.ts +3 -3
  9. package/dist/kit/builder/form/components/fields/types.d.ts.map +1 -1
  10. package/dist/kit/builder/form/index.d.ts +1 -0
  11. package/dist/kit/builder/form/index.d.ts.map +1 -1
  12. package/dist/kit/builder/form/types.d.ts +175 -0
  13. package/dist/kit/builder/form/types.d.ts.map +1 -0
  14. package/dist/kit/builder/form/utils/common-forms.d.ts +1 -1
  15. package/dist/kit/builder/form/utils/common-forms.d.ts.map +1 -1
  16. package/dist/kit/builder/form/utils/field-factories.d.ts +3 -3
  17. package/dist/kit/builder/form/utils/field-factories.d.ts.map +1 -1
  18. package/dist/kit/builder/form/utils/section-factories.d.ts +4 -4
  19. package/dist/kit/builder/form/utils/section-factories.d.ts.map +1 -1
  20. package/dist/kit/builder/stack-dialog/provider.d.ts.map +1 -1
  21. package/dist/kit/builder/stack-dialog/renderer.d.ts.map +1 -1
  22. package/dist/kit/components/autocomplete/Autocomplete.d.ts +8 -8
  23. package/dist/kit/components/autocomplete/Autocomplete.d.ts.map +1 -1
  24. package/dist/kit/components/autocomplete/types.d.ts +6 -4
  25. package/dist/kit/components/autocomplete/types.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/kit/builder/data-table/components/DataTable.tsx +1 -1
  28. package/src/kit/builder/data-table/types.ts +1 -1
  29. package/src/kit/builder/form/components/FormBuilder.tsx +43 -237
  30. package/src/kit/builder/form/components/FormBuilderField.tsx +42 -34
  31. package/src/kit/builder/form/components/fields/AutocompleteField.tsx +2 -2
  32. package/src/kit/builder/form/components/fields/types.ts +3 -3
  33. package/src/kit/builder/form/index.ts +1 -0
  34. package/src/kit/builder/form/types.ts +198 -0
  35. package/src/kit/builder/form/utils/common-forms.ts +1 -1
  36. package/src/kit/builder/form/utils/field-factories.ts +5 -5
  37. package/src/kit/builder/form/utils/section-factories.ts +10 -10
  38. package/src/kit/builder/stack-dialog/provider.tsx +2 -1
  39. package/src/kit/builder/stack-dialog/renderer.tsx +6 -7
  40. package/src/kit/components/autocomplete/Autocomplete.tsx +33 -25
  41. package/src/kit/components/autocomplete/types.ts +7 -5
@@ -1,9 +1,9 @@
1
1
  import { useCallback } from 'react';
2
- import type { Control, FieldValues } from 'react-hook-form';
2
+ import type { Control, FieldValues, Path } from 'react-hook-form';
3
3
  import { useController } from 'react-hook-form';
4
4
  import { cn } from '../../../../shadcn/lib/utils';
5
5
  import { Label } from '../../../../shadcn/ui/label';
6
- import type { FormBuilderFieldConfig } from './FormBuilder';
6
+ import type { FormBuilderFieldConfig } from '../types';
7
7
  import {
8
8
  AutocompleteField,
9
9
  TextField,
@@ -27,29 +27,37 @@ import {
27
27
  ArrayField,
28
28
  } from './fields';
29
29
 
30
- export interface FormBuilderFieldProps {
31
- field: FormBuilderFieldConfig;
32
- control: Control<FieldValues>;
33
- onChange?: (value: unknown) => void;
34
- onFieldChange?: (name: string, value: unknown, allValues: Record<string, unknown>) => void;
30
+ export interface FormBuilderFieldProps<
31
+ TFieldValues extends FieldValues = FieldValues,
32
+ TName extends string | Path<TFieldValues> = Path<TFieldValues>
33
+ > {
34
+ field: FormBuilderFieldConfig<TFieldValues, TName>;
35
+ control: Control<TFieldValues>;
36
+ onChange?: (value: unknown, ...extras: unknown[]) => void;
37
+ onFieldChange?: (name: import('react-hook-form').Path<TFieldValues> | string, value: unknown, allValues: TFieldValues) => void;
35
38
  parentPath?: string;
36
39
  }
37
40
 
38
- export function FormBuilderField({ field, control, onChange, parentPath }: FormBuilderFieldProps) {
39
- const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name;
41
+ export function FormBuilderField<
42
+ TFieldValues extends FieldValues = FieldValues,
43
+ TName extends string | Path<TFieldValues> = Path<TFieldValues>
44
+ >({ field, control, onChange, parentPath }: FormBuilderFieldProps<TFieldValues, TName>) {
45
+ const fieldPath = parentPath ? `${parentPath}.${field.name}` : (field.name as string);
40
46
 
41
47
  const {
42
48
  field: controllerField,
43
49
  fieldState: { error },
44
- } = useController({
45
- name: fieldPath,
50
+ } = useController<TFieldValues>({
51
+ name: fieldPath as unknown as Path<TFieldValues>,
46
52
  control,
47
53
  disabled: field.disabled,
48
54
  });
49
55
 
50
- const handleChange = useCallback((value: unknown) => {
56
+ const handleChange = useCallback((value: unknown, ...extras: unknown[]) => {
57
+ // Only patch the RHF value with the first argument (the canonical value)
51
58
  controllerField.onChange(value);
52
- onChange?.(value);
59
+ // Forward any extra metadata upstream (e.g., option, raw)
60
+ onChange?.(value, ...extras);
53
61
  }, [controllerField, onChange]);
54
62
  const baseClassName = cn(
55
63
  error && 'border-destructive focus-visible:ring-destructive',
@@ -62,7 +70,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
62
70
  return (
63
71
  <AutocompleteField
64
72
  field={field}
65
- control={control}
73
+ control={control as unknown as Control<FieldValues>}
66
74
  fieldPath={fieldPath}
67
75
  value={controllerField.value}
68
76
  onChange={handleChange}
@@ -75,7 +83,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
75
83
  return (
76
84
  <TextField
77
85
  field={field}
78
- control={control}
86
+ control={control as unknown as Control<FieldValues>}
79
87
  fieldPath={fieldPath}
80
88
  value={controllerField.value}
81
89
  onChange={handleChange}
@@ -86,7 +94,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
86
94
  return (
87
95
  <NumberField
88
96
  field={field}
89
- control={control}
97
+ control={control as unknown as Control<FieldValues>}
90
98
  fieldPath={fieldPath}
91
99
  value={controllerField.value}
92
100
  onChange={handleChange}
@@ -97,7 +105,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
97
105
  return (
98
106
  <TextareaField
99
107
  field={field}
100
- control={control}
108
+ control={control as unknown as Control<FieldValues>}
101
109
  fieldPath={fieldPath}
102
110
  value={controllerField.value}
103
111
  onChange={handleChange}
@@ -108,7 +116,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
108
116
  return (
109
117
  <SelectField
110
118
  field={field}
111
- control={control}
119
+ control={control as unknown as Control<FieldValues>}
112
120
  fieldPath={fieldPath}
113
121
  value={controllerField.value}
114
122
  onChange={handleChange}
@@ -119,7 +127,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
119
127
  return (
120
128
  <CheckboxField
121
129
  field={field}
122
- control={control}
130
+ control={control as unknown as Control<FieldValues>}
123
131
  fieldPath={fieldPath}
124
132
  value={controllerField.value}
125
133
  onChange={handleChange}
@@ -130,7 +138,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
130
138
  return (
131
139
  <SwitchField
132
140
  field={field}
133
- control={control}
141
+ control={control as unknown as Control<FieldValues>}
134
142
  fieldPath={fieldPath}
135
143
  value={controllerField.value}
136
144
  onChange={handleChange}
@@ -141,7 +149,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
141
149
  return (
142
150
  <RadioField
143
151
  field={field}
144
- control={control}
152
+ control={control as unknown as Control<FieldValues>}
145
153
  fieldPath={fieldPath}
146
154
  value={controllerField.value}
147
155
  onChange={handleChange}
@@ -152,7 +160,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
152
160
  return (
153
161
  <DateField
154
162
  field={field}
155
- control={control}
163
+ control={control as unknown as Control<FieldValues>}
156
164
  fieldPath={fieldPath}
157
165
  value={controllerField.value}
158
166
  onChange={handleChange}
@@ -163,7 +171,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
163
171
  return (
164
172
  <DatePickerField
165
173
  field={field}
166
- control={control}
174
+ control={control as unknown as Control<FieldValues>}
167
175
  fieldPath={fieldPath}
168
176
  value={controllerField.value}
169
177
  onChange={handleChange}
@@ -174,7 +182,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
174
182
  return (
175
183
  <DateRangePickerField
176
184
  field={field}
177
- control={control}
185
+ control={control as unknown as Control<FieldValues>}
178
186
  fieldPath={fieldPath}
179
187
  value={controllerField.value}
180
188
  onChange={handleChange}
@@ -185,7 +193,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
185
193
  return (
186
194
  <MonthPickerField
187
195
  field={field}
188
- control={control}
196
+ control={control as unknown as Control<FieldValues>}
189
197
  fieldPath={fieldPath}
190
198
  value={controllerField.value}
191
199
  onChange={handleChange}
@@ -196,7 +204,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
196
204
  return (
197
205
  <MonthRangePickerField
198
206
  field={field}
199
- control={control}
207
+ control={control as unknown as Control<FieldValues>}
200
208
  fieldPath={fieldPath}
201
209
  value={controllerField.value}
202
210
  onChange={handleChange}
@@ -207,7 +215,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
207
215
  return (
208
216
  <TimePickerField
209
217
  field={field}
210
- control={control}
218
+ control={control as unknown as Control<FieldValues>}
211
219
  fieldPath={fieldPath}
212
220
  value={controllerField.value}
213
221
  onChange={handleChange}
@@ -218,7 +226,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
218
226
  return (
219
227
  <TimeRangePickerField
220
228
  field={field}
221
- control={control}
229
+ control={control as unknown as Control<FieldValues>}
222
230
  fieldPath={fieldPath}
223
231
  value={controllerField.value}
224
232
  onChange={handleChange}
@@ -229,7 +237,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
229
237
  return (
230
238
  <DateTimePickerField
231
239
  field={field}
232
- control={control}
240
+ control={control as unknown as Control<FieldValues>}
233
241
  fieldPath={fieldPath}
234
242
  value={controllerField.value}
235
243
  onChange={handleChange}
@@ -240,7 +248,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
240
248
  return (
241
249
  <DateTimeRangePickerField
242
250
  field={field}
243
- control={control}
251
+ control={control as unknown as Control<FieldValues>}
244
252
  fieldPath={fieldPath}
245
253
  value={controllerField.value}
246
254
  onChange={handleChange}
@@ -251,7 +259,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
251
259
  return (
252
260
  <FileField
253
261
  field={field}
254
- control={control}
262
+ control={control as unknown as Control<FieldValues>}
255
263
  fieldPath={fieldPath}
256
264
  value={controllerField.value}
257
265
  onChange={handleChange}
@@ -262,7 +270,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
262
270
  return (
263
271
  <ObjectField
264
272
  field={field}
265
- control={control}
273
+ control={control as unknown as Control<FieldValues>}
266
274
  fieldPath={fieldPath}
267
275
  value={controllerField.value}
268
276
  onChange={handleChange}
@@ -273,7 +281,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
273
281
  return (
274
282
  <ArrayField
275
283
  field={field}
276
- control={control}
284
+ control={control as unknown as Control<FieldValues>}
277
285
  fieldPath={fieldPath}
278
286
  value={controllerField.value}
279
287
  onChange={handleChange}
@@ -284,7 +292,7 @@ export function FormBuilderField({ field, control, onChange, parentPath }: FormB
284
292
  return (
285
293
  <TextField
286
294
  field={field}
287
- control={control}
295
+ control={control as unknown as Control<FieldValues>}
288
296
  fieldPath={fieldPath}
289
297
  value={controllerField.value}
290
298
  onChange={handleChange}
@@ -5,7 +5,7 @@ import type { FieldRenderProps } from './types'
5
5
  export function AutocompleteField({ field, value, onChange, className }: FieldRenderProps) {
6
6
  const options: AutocompleteOption[] = (field.options ?? [])
7
7
  .filter((o): o is { label: string; value: string | number } => o.value !== null && o.value !== undefined)
8
- .map(o => ({ label: o.label, value: o.value as string | number }))
8
+ .map(o => ({ label: o.label, value: o.value as string | number, raw: (o as unknown as AutocompleteOption).raw }))
9
9
 
10
10
  // Shape defaultValue according to single/multiple
11
11
  let defaultValueShaped: string | number | null | Array<string | number> | undefined = undefined
@@ -42,7 +42,7 @@ export function AutocompleteField({ field, value, onChange, className }: FieldRe
42
42
  initialSelectedOptions={field.initialSelectedOptions ?? null}
43
43
  loadSelected={field.loadSelected}
44
44
  value={field.multiple ? ((Array.isArray(value) ? value : (value ? [value] : [])) as Array<string | number>) : ((value as string | number | null) ?? null)}
45
- onChange={(val) => onChange(val)}
45
+ onChange={(val, option, raw) => onChange(val, option, raw)}
46
46
  placeholder={field.placeholder}
47
47
  searchPlaceholder={field.searchPlaceholder}
48
48
  renderOption={field.renderOption}
@@ -1,12 +1,12 @@
1
1
  import type { Control, FieldValues } from 'react-hook-form'
2
- import type { FormBuilderFieldConfig } from '../FormBuilder'
2
+ import type { FormBuilderFieldConfig } from '../../types'
3
3
 
4
4
  export interface FieldRenderProps {
5
- field: FormBuilderFieldConfig
5
+ field: FormBuilderFieldConfig<any, any>
6
6
  control: Control<FieldValues>
7
7
  fieldPath: string
8
8
  value: unknown
9
- onChange: (value: unknown) => void
9
+ onChange: (value: unknown, ...extras: unknown[]) => void
10
10
  className?: string
11
11
  disabled?: boolean
12
12
  errorMessage?: string
@@ -1,2 +1,3 @@
1
1
  export * from './components';
2
2
  export * from './utils';
3
+ export * from './types';
@@ -0,0 +1,198 @@
1
+ import type React from 'react'
2
+ import type {
3
+ Control,
4
+ DeepPartial,
5
+ FieldValues,
6
+ Path,
7
+ UseFormGetValues,
8
+ UseFormSetValue,
9
+ DefaultValues,
10
+ } from 'react-hook-form'
11
+ import type { z } from 'zod'
12
+ import type { Accept } from 'react-dropzone'
13
+ import type { SectionFlexOptions, SectionGridOptions, SectionLayout, SectionNode } from '../section/types'
14
+ import type { AutocompleteFetcher, AutocompleteOption } from '../../components/autocomplete/types'
15
+ import type { FileRecord, FileUploaderLayout } from '../../components/fileuploader/types'
16
+
17
+ export type FieldType =
18
+ | 'text'
19
+ | 'email'
20
+ | 'password'
21
+ | 'number'
22
+ | 'textarea'
23
+ | 'select'
24
+ | 'autocomplete'
25
+ | 'checkbox'
26
+ | 'switch'
27
+ | 'radio'
28
+ | 'date'
29
+ | 'date_picker'
30
+ | 'date_range'
31
+ | 'month'
32
+ | 'month_range'
33
+ | 'time'
34
+ | 'time_range'
35
+ | 'date_time'
36
+ | 'date_time_range'
37
+ | 'file'
38
+ | 'object'
39
+ | 'array'
40
+
41
+ export interface Dependency<TFieldValues extends FieldValues> {
42
+ field: Path<TFieldValues>
43
+ condition: (value: unknown) => boolean
44
+ action: 'show' | 'hide' | 'enable' | 'disable' | 'setValue'
45
+ value?: unknown
46
+ }
47
+
48
+ export interface FormBuilderFieldConfig<
49
+ TFieldValues extends FieldValues = FieldValues,
50
+ TName extends Path<TFieldValues> | string = Path<TFieldValues>
51
+ > {
52
+ id?: string
53
+ name: TName
54
+ label: string
55
+ type: FieldType
56
+ placeholder?: string
57
+ description?: string
58
+ required?: boolean
59
+ disabled?: boolean
60
+ options?: { label: string; value: string | number | null }[]
61
+ autocompleteMode?: 'client' | 'server'
62
+ fetcher?: AutocompleteFetcher
63
+ pageSize?: number
64
+ searchPlaceholder?: string
65
+ renderOption?: (option: AutocompleteOption, selected: boolean) => React.ReactNode
66
+ multiple?: boolean
67
+ allowCustomValue?: boolean
68
+ chipVariant?: 'default' | 'secondary' | 'destructive' | 'outline'
69
+ chipClassName?: string
70
+ clearable?: boolean
71
+ initialSelectedOptions?: AutocompleteOption | AutocompleteOption[] | null
72
+ loadSelected?: (values: Array<string | number>) => Promise<AutocompleteOption[]>
73
+ validation?:
74
+ | z.ZodType<unknown>
75
+ | {
76
+ pattern?: { value: RegExp; message: string }
77
+ min?: { value: number; message: string }
78
+ max?: { value: number; message: string }
79
+ minLength?: { value: number; message: string }
80
+ maxLength?: { value: number; message: string }
81
+ minItems?: { value: number; message: string }
82
+ maxItems?: { value: number; message: string }
83
+ }
84
+ // Accept any for defaultValue to support relative string names for nested fields
85
+ defaultValue?: unknown
86
+ // For nested object/array fields, use relative names (eg. 'uomName')
87
+ fields?: Array<FormBuilderFieldConfig<TFieldValues, string>>
88
+ dependencies?: Array<Dependency<TFieldValues>>
89
+ onChange?: (
90
+ value: unknown,
91
+ extras: unknown,
92
+ setValue: UseFormSetValue<TFieldValues>,
93
+ getValues: UseFormGetValues<TFieldValues>
94
+ ) => void
95
+ className?: string
96
+ gridCols?: number
97
+ rows?: number
98
+ itemType?: string
99
+ arrayLayout?: 'card' | 'table' | 'custom'
100
+ arrayRender?: (params: {
101
+ field: FormBuilderFieldConfig<TFieldValues>
102
+ control: Control<TFieldValues>
103
+ fieldPath: string
104
+ value: unknown
105
+ onChange: (value: unknown) => void
106
+ addItem: () => void
107
+ removeItem: (index: number) => void
108
+ disabled?: boolean
109
+ rows?: { id: string }[]
110
+ }) => React.ReactNode
111
+ arrayColors?: {
112
+ headerBgClass?: string
113
+ headerTextClass?: string
114
+ rowAltBgClass?: string
115
+ }
116
+ conditional?: {
117
+ field: Path<TFieldValues>
118
+ value: unknown
119
+ }
120
+ hidden?: boolean
121
+ labelPlacement?: 'stacked' | 'inline' | 'hidden'
122
+ wrapperClassName?: string
123
+ minDate?: Date
124
+ maxDate?: Date
125
+ disabledDates?: Array<Date | { from: Date; to: Date }>
126
+ numberOfMonths?: number
127
+ popoverSide?: 'top' | 'right' | 'bottom' | 'left'
128
+ showFooter?: boolean
129
+ cancelLabel?: string
130
+ applyLabel?: string
131
+ timePrecision?: 'hour' | 'minute' | 'second'
132
+ hourCycle?: 12 | 24
133
+ minuteStep?: number
134
+ secondStep?: number
135
+ fileMultiple?: boolean
136
+ fileMaxFiles?: number
137
+ fileAccept?: Accept
138
+ fileLayout?: FileUploaderLayout
139
+ fileWithDownload?: boolean
140
+ fileUploader?: (file: File, onProgress: (pct: number) => void) => Promise<Partial<FileRecord>>
141
+ fileOnUploadSuccess?: (file: FileRecord) => void
142
+ fileOnUploadError?: (file: FileRecord, error: unknown) => void
143
+ fileOnRemove?: (file: FileRecord) => void | Promise<void>
144
+ fileOnRetry?: (file: FileRecord) => void
145
+ fileOnRetryAll?: (files: FileRecord[]) => void
146
+ }
147
+
148
+ export interface FormBuilderSectionConfig<TFieldValues extends FieldValues = FieldValues> {
149
+ id?: string
150
+ title?: string
151
+ description?: string
152
+ fields?: Array<FormBuilderFieldConfig<TFieldValues>>
153
+ variant?: 'card' | 'separator' | 'plain'
154
+ className?: string
155
+ collapsible?: boolean
156
+ defaultCollapsed?: boolean
157
+ layout?: SectionLayout
158
+ grid?: SectionGridOptions
159
+ flex?: SectionFlexOptions
160
+ hidden?: boolean
161
+ tabs?: Array<{
162
+ id: string
163
+ label: React.ReactNode
164
+ sections: Array<FormBuilderSectionConfig<TFieldValues>>
165
+ className?: string
166
+ contentClassName?: string
167
+ }>
168
+ defaultTabId?: string
169
+ tabsListClassName?: string
170
+ tabsContentClassName?: string
171
+ }
172
+
173
+ export interface FormBuilderProps<TFieldValues extends FieldValues = FieldValues> {
174
+ sections: Array<FormBuilderSectionConfig<TFieldValues>>
175
+ schema?: z.ZodType<TFieldValues>
176
+ defaultValues?: DeepPartial<TFieldValues> | DefaultValues<TFieldValues> | null
177
+ onSubmit: (data: TFieldValues) => void | Promise<void>
178
+ onCancel?: () => void
179
+ onReset?: () => void
180
+ onFieldChange?: (
181
+ name: Path<TFieldValues> | string,
182
+ value: unknown,
183
+ allValues: TFieldValues
184
+ ) => void
185
+ submitLabel?: string
186
+ cancelLabel?: string
187
+ resetLabel?: string
188
+ isSubmitting?: boolean
189
+ className?: string
190
+ formClassName?: string
191
+ actionsClassName?: string
192
+ showActions?: boolean
193
+ customActions?: React.ReactNode
194
+ showActionsSeparator?: boolean
195
+ }
196
+
197
+ // Re-export for external consumers that build custom section nodes
198
+ export type { SectionNode }
@@ -1,4 +1,4 @@
1
- import { FormBuilderSectionConfig } from '../components/FormBuilder';
1
+ import type { FormBuilderSectionConfig } from '../types';
2
2
  import { createField } from './field-factories';
3
3
  import { createSection } from './section-factories';
4
4
  import { commonValidations } from './validations';
@@ -1,4 +1,4 @@
1
- import { FormBuilderFieldConfig } from '../components/FormBuilder';
1
+ import type { FormBuilderFieldConfig } from '../types';
2
2
  import { commonValidations } from './validations';
3
3
 
4
4
  // Field factory functions
@@ -7,7 +7,7 @@ export const createField = {
7
7
  name: string,
8
8
  label: string,
9
9
  options: Partial<FormBuilderFieldConfig> = {},
10
- ): FormBuilderFieldConfig => ({
10
+ ): FormBuilderFieldConfig<any> => ({
11
11
  name,
12
12
  label,
13
13
  type: 'text',
@@ -147,9 +147,9 @@ export const createField = {
147
147
  object: (
148
148
  name: string,
149
149
  label: string,
150
- fields: FormBuilderFieldConfig[],
151
- options: Partial<FormBuilderFieldConfig> = {},
152
- ): FormBuilderFieldConfig => ({
150
+ fields: FormBuilderFieldConfig<any>[],
151
+ options: Partial<FormBuilderFieldConfig<any>> = {},
152
+ ): FormBuilderFieldConfig<any> => ({
153
153
  name,
154
154
  label,
155
155
  type: 'object',
@@ -1,12 +1,12 @@
1
- import { FormBuilderFieldConfig, FormBuilderSectionConfig } from '../components/FormBuilder';
1
+ import type { FormBuilderFieldConfig, FormBuilderSectionConfig } from '../types';
2
2
 
3
3
  // Section factory functions
4
4
  export const createSection = {
5
5
  card: (
6
6
  title: string,
7
- fields: FormBuilderFieldConfig[],
8
- options: Partial<FormBuilderSectionConfig> = {},
9
- ): FormBuilderSectionConfig => ({
7
+ fields: FormBuilderFieldConfig<any>[],
8
+ options: Partial<FormBuilderSectionConfig<any>> = {},
9
+ ): FormBuilderSectionConfig<any> => ({
10
10
  title,
11
11
  fields,
12
12
  variant: 'card',
@@ -15,9 +15,9 @@ export const createSection = {
15
15
 
16
16
  separator: (
17
17
  title: string,
18
- fields: FormBuilderFieldConfig[],
19
- options: Partial<FormBuilderSectionConfig> = {},
20
- ): FormBuilderSectionConfig => ({
18
+ fields: FormBuilderFieldConfig<any>[],
19
+ options: Partial<FormBuilderSectionConfig<any>> = {},
20
+ ): FormBuilderSectionConfig<any> => ({
21
21
  title,
22
22
  fields,
23
23
  variant: 'separator',
@@ -25,9 +25,9 @@ export const createSection = {
25
25
  }),
26
26
 
27
27
  plain: (
28
- fields: FormBuilderFieldConfig[],
29
- options: Partial<FormBuilderSectionConfig> = {},
30
- ): FormBuilderSectionConfig => ({
28
+ fields: FormBuilderFieldConfig<any>[],
29
+ options: Partial<FormBuilderSectionConfig<any>> = {},
30
+ ): FormBuilderSectionConfig<any> => ({
31
31
  fields,
32
32
  variant: 'plain',
33
33
  ...options,
@@ -27,7 +27,8 @@ export function StackDialogContextProvider(props: PropsWithChildren) {
27
27
  const handleCloseDialog = useCallback((id?: string) => {
28
28
  setActiveDialogs(prev => {
29
29
  const clone = [...prev];
30
- clone.splice(clone.findIndex(d => d.id === (id || '')));
30
+ if (!id) clone.splice(clone.length - 1, 1);
31
+ else clone.splice(clone.findIndex((d) => (d.id === id)));
31
32
  return clone;
32
33
  });
33
34
  }, [setActiveDialogs]);
@@ -1,5 +1,4 @@
1
- import { DialogContent } from '@radix-ui/react-dialog';
2
- import { Dialog } from '../../../shadcn/ui/dialog';
1
+ import { Dialog, DialogContent } from '../../../shadcn/ui/dialog';
3
2
  import { StackDialogInstance } from './types';
4
3
 
5
4
  export function StackDialogRenderer(props: {
@@ -10,19 +9,19 @@ export function StackDialogRenderer(props: {
10
9
  props.closeDialog(id)
11
10
  }
12
11
 
13
- return props.dialogs.map((dialog) => (
12
+ return props.dialogs.map((dialog, i) => (
14
13
  (
15
14
  <Dialog
16
- open
17
- onOpenChange={(open) => (!open && handleCloseDialog(dialog.id))}
15
+ open={!!props.dialogs[i]}
16
+ onOpenChange={handleCloseDialog(dialog.id)}
18
17
  key={dialog.id}
19
18
  >
20
19
  <DialogContent
21
20
  onEscapeKeyDown={e => {
22
- if (!dialog.closeOnEscapePressed) e.preventDefault();
21
+ if (dialog.closeOnEscapePressed === false) e.preventDefault();
23
22
  }}
24
23
  onInteractOutside={e => {
25
- if (!dialog.closeOnInteractOutside) e.preventDefault();
24
+ if (dialog.closeOnInteractOutside === false) e.preventDefault();
26
25
  }}
27
26
  >
28
27
  {dialog.template}