@react-fabric/form 1.0.0-beta.32 → 1.0.0-beta.34

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 (89) hide show
  1. package/dist/cjs/builder/FileField.js +4 -4
  2. package/dist/cjs/builder/FormField.js +44 -34
  3. package/dist/cjs/builder/SchemaEditor.js +439 -0
  4. package/dist/cjs/form/Controller.js +1 -1
  5. package/dist/cjs/form/Form.js +10 -4
  6. package/dist/cjs/hooks/useFormBuilder.js +27 -15
  7. package/dist/cjs/index.js +8 -2
  8. package/dist/cjs/input/Checkbox.js +4 -3
  9. package/dist/cjs/input/ColorInput.js +1 -1
  10. package/dist/cjs/input/DateInput.js +183 -0
  11. package/dist/cjs/input/Field.js +1 -1
  12. package/dist/cjs/input/File.js +1 -1
  13. package/dist/cjs/input/Hidden.js +1 -1
  14. package/dist/cjs/input/Input.js +1 -1
  15. package/dist/cjs/input/Number.js +1 -1
  16. package/dist/cjs/input/Password.js +1 -1
  17. package/dist/cjs/input/{Range.js → RangeSlider.js} +3 -3
  18. package/dist/cjs/input/Search.js +1 -1
  19. package/dist/cjs/input/Slider.js +1 -1
  20. package/dist/cjs/input/Switch.js +4 -3
  21. package/dist/cjs/input/Textarea.js +1 -1
  22. package/dist/cjs/internal/Field.module.css +1 -1
  23. package/dist/cjs/internal/InputWrapper.js +4 -2
  24. package/dist/cjs/types/schema.js +40 -0
  25. package/dist/esm/builder/FileField.js +4 -4
  26. package/dist/esm/builder/FormField.js +44 -34
  27. package/dist/esm/builder/SchemaEditor.js +439 -0
  28. package/dist/esm/form/Controller.js +1 -1
  29. package/dist/esm/form/Form.js +11 -5
  30. package/dist/esm/hooks/useFormBuilder.js +25 -13
  31. package/dist/esm/index.js +4 -1
  32. package/dist/esm/input/Checkbox.js +4 -3
  33. package/dist/esm/input/ColorInput.js +1 -1
  34. package/dist/esm/input/DateInput.js +183 -0
  35. package/dist/esm/input/Field.js +1 -1
  36. package/dist/esm/input/File.js +1 -1
  37. package/dist/esm/input/Hidden.js +1 -1
  38. package/dist/esm/input/Input.js +1 -1
  39. package/dist/esm/input/Number.js +1 -1
  40. package/dist/esm/input/Password.js +1 -1
  41. package/dist/esm/input/{Range.js → RangeSlider.js} +3 -3
  42. package/dist/esm/input/Search.js +1 -1
  43. package/dist/esm/input/Slider.js +1 -1
  44. package/dist/esm/input/Switch.js +4 -3
  45. package/dist/esm/input/Textarea.js +1 -1
  46. package/dist/esm/internal/Field.module.css +1 -1
  47. package/dist/esm/internal/InputWrapper.js +4 -2
  48. package/dist/esm/types/schema.js +40 -0
  49. package/dist/types/builder/FileField.d.ts +2 -2
  50. package/dist/types/builder/FormField.d.ts +3 -1
  51. package/dist/types/builder/SchemaEditor.d.ts +16 -0
  52. package/dist/types/form/Controller.d.ts +1 -1
  53. package/dist/types/form/Form.d.ts +1 -0
  54. package/dist/types/hooks/useFormBuilder.d.ts +3 -1
  55. package/dist/types/index.d.ts +4 -2
  56. package/dist/types/input/Checkbox.d.ts +4 -3
  57. package/dist/types/input/ColorInput.d.ts +1 -1
  58. package/dist/types/input/DateInput.d.ts +19 -0
  59. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
  60. package/dist/types/input/Switch.d.ts +1 -1
  61. package/dist/types/internal/InputWrapper.d.ts +1 -1
  62. package/dist/types/types/index.d.ts +7 -3
  63. package/dist/types/types/schema.d.ts +52 -33
  64. package/package.json +5 -4
  65. package/src/builder/FileField.tsx +5 -4
  66. package/src/builder/FormField.tsx +45 -32
  67. package/src/builder/SchemaEditor.tsx +457 -0
  68. package/src/form/Controller.tsx +2 -2
  69. package/src/form/Form.tsx +6 -6
  70. package/src/hooks/useFormBuilder.tsx +29 -15
  71. package/src/index.ts +5 -2
  72. package/src/input/Checkbox.tsx +4 -3
  73. package/src/input/ColorInput.tsx +5 -2
  74. package/src/input/DateInput.tsx +248 -0
  75. package/src/input/Field.tsx +2 -1
  76. package/src/input/File.tsx +1 -1
  77. package/src/input/Hidden.tsx +4 -3
  78. package/src/input/Input.tsx +1 -1
  79. package/src/input/Number.tsx +1 -1
  80. package/src/input/Password.tsx +1 -1
  81. package/src/input/{Range.tsx → RangeSlider.tsx} +2 -2
  82. package/src/input/Search.tsx +1 -1
  83. package/src/input/Slider.tsx +1 -1
  84. package/src/input/Switch.tsx +2 -0
  85. package/src/input/Textarea.tsx +1 -1
  86. package/src/internal/Field.module.css +12 -1
  87. package/src/internal/InputWrapper.tsx +5 -0
  88. package/src/types/index.ts +9 -5
  89. package/src/types/schema.ts +65 -41
@@ -48,7 +48,10 @@ import {
48
48
  import { type InputProps } from "../types";
49
49
  import { ColorPicker, type ColorProps } from "./ColorPicker";
50
50
 
51
- export interface ColorInputProps extends InputProps, ColorProps, RefProp {
51
+ export interface ColorInputProps
52
+ extends InputProps,
53
+ Omit<ColorProps, "onChange">,
54
+ RefProp {
52
55
  /**
53
56
  * show eydrop picker
54
57
  */
@@ -82,7 +85,7 @@ export const ColorInput = ({
82
85
  const handleChange = useCallback(
83
86
  (e?: string) => {
84
87
  setActualValue(e ?? defaultColor);
85
- onChange != null && startTransition(() => onChange(e));
88
+ onChange != null && startTransition(() => onChange(e ?? null));
86
89
  },
87
90
  [onChange],
88
91
  );
@@ -0,0 +1,248 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import {
25
+ arrow,
26
+ autoUpdate,
27
+ flip,
28
+ FloatingArrow,
29
+ offset,
30
+ shift,
31
+ useClick,
32
+ useDismiss,
33
+ useFloating,
34
+ useFocus,
35
+ useInteractions,
36
+ } from "@floating-ui/react";
37
+ import { type RefProp } from "@react-fabric/core/dist/types/types";
38
+ import { type DateLike, DatePanel, DateUtil } from "@react-fabric/date";
39
+ import { mergeRefs } from "@react-fabric/utilities";
40
+ import {
41
+ type ChangeEvent,
42
+ startTransition,
43
+ useCallback,
44
+ useDeferredValue,
45
+ useEffect,
46
+ useMemo,
47
+ useRef,
48
+ useState,
49
+ } from "react";
50
+ import { InputWrapper } from "../internal/InputWrapper";
51
+ import { type InputProps } from "../types";
52
+ import { handleEnter } from "../utils";
53
+ import classNames from "classnames";
54
+
55
+ export interface DateProps
56
+ extends InputProps<string>,
57
+ RefProp<HTMLInputElement> {
58
+ type?: "date" | "datetime";
59
+ /**
60
+ * date format
61
+ */
62
+ format?: string;
63
+ /**
64
+ * minimum value
65
+ */
66
+ min?: DateLike;
67
+ /**
68
+ * maximum value
69
+ */
70
+ max?: DateLike;
71
+ }
72
+
73
+ export const DateInput = ({
74
+ ref,
75
+ name,
76
+ value,
77
+ invalid,
78
+ readOnly,
79
+ disabled,
80
+ required,
81
+ placeholder,
82
+ autoFocus,
83
+ error,
84
+ type = "date",
85
+ onChange,
86
+ onEnterPressed,
87
+ format = "dd/MM/yyyy",
88
+ min,
89
+ max,
90
+ ...rest
91
+ }: DateProps) => {
92
+ const [actualValue, setActualValue] = useState("");
93
+ const [inputValue, setInputValue] = useState("");
94
+ const deferred = useDeferredValue(value);
95
+
96
+ const inputFormat = useMemo(
97
+ () => (type === "datetime" ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd"),
98
+ [type],
99
+ );
100
+
101
+ useEffect(() => {
102
+ setActualValue(deferred ?? "");
103
+ setInputValue(deferred ? DateUtil.format(deferred, inputFormat) : "");
104
+ }, [deferred, inputFormat]);
105
+
106
+ const handleEnterPressed = useMemo(
107
+ () => handleEnter(onEnterPressed),
108
+ [onEnterPressed],
109
+ );
110
+
111
+ const handleChange = useCallback(
112
+ (e?: ChangeEvent<HTMLInputElement>) => {
113
+ const value = e?.currentTarget.value;
114
+ if (value) {
115
+ const parsed = DateUtil.parseDate(value);
116
+ setActualValue(parsed?.toISOString?.());
117
+ setInputValue(DateUtil.format(parsed, inputFormat));
118
+ onChange != null &&
119
+ startTransition(() => onChange(parsed?.toISOString?.()));
120
+ } else {
121
+ setActualValue("");
122
+ setInputValue("");
123
+ onChange != null && startTransition(() => onChange(null));
124
+ }
125
+ },
126
+ [onChange, inputFormat],
127
+ );
128
+
129
+ const handleDateChange = useCallback(
130
+ (value?: string) => {
131
+ if (value) {
132
+ const parsed = DateUtil.parseDate(value);
133
+ setActualValue(parsed?.toISOString?.());
134
+ setInputValue(DateUtil.format(parsed, inputFormat));
135
+ onChange != null &&
136
+ startTransition(() => onChange(parsed?.toISOString?.()));
137
+ } else {
138
+ setActualValue("");
139
+ setInputValue("");
140
+ onChange != null && startTransition(() => onChange(null));
141
+ }
142
+ },
143
+ [onChange, inputFormat],
144
+ );
145
+
146
+ const arrowRef = useRef(null);
147
+ const [isOpen, setIsOpen] = useState(false);
148
+ const { refs, floatingStyles, context } = useFloating({
149
+ open: isOpen,
150
+ onOpenChange: (open, _, reason) => {
151
+ console.log(reason);
152
+ if (reason === "reference-press") return;
153
+ setIsOpen(open);
154
+ },
155
+ strategy: "fixed",
156
+ placement: "bottom-start",
157
+ whileElementsMounted: autoUpdate,
158
+ middleware: [
159
+ shift({ padding: 8 }),
160
+ flip(),
161
+ offset(9),
162
+ arrow({
163
+ element: arrowRef,
164
+ }),
165
+ ],
166
+ });
167
+
168
+ const focus = useFocus(context, {
169
+ enabled: !disabled,
170
+ });
171
+ const click = useClick(context, {
172
+ enabled: !disabled,
173
+ toggle: false,
174
+ });
175
+ const dismiss = useDismiss(context, {
176
+ referencePress: true,
177
+ });
178
+
179
+ const { getReferenceProps, getFloatingProps } = useInteractions([
180
+ dismiss,
181
+ click,
182
+ focus,
183
+ ]);
184
+
185
+ return (
186
+ <InputWrapper
187
+ showClear={!!actualValue}
188
+ onClear={handleChange}
189
+ invalid={invalid}
190
+ readOnly={readOnly}
191
+ disabled={disabled}
192
+ required={required}
193
+ error={error}
194
+ {...rest}
195
+ >
196
+ <input
197
+ className={classNames(
198
+ "appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0 peer",
199
+ !value && "empty",
200
+ )}
201
+ aria-invalid={invalid}
202
+ aria-disabled={disabled}
203
+ aria-readonly={readOnly}
204
+ aria-errormessage={error}
205
+ placeholder={placeholder}
206
+ disabled={disabled}
207
+ readOnly={readOnly}
208
+ data-testid={name}
209
+ name={name}
210
+ size={1}
211
+ type={type === "datetime" ? "datetime-local" : "date"}
212
+ autoComplete="off"
213
+ autoFocus={autoFocus}
214
+ value={inputValue}
215
+ ref={mergeRefs(ref, refs.setReference)}
216
+ {...getReferenceProps()}
217
+ onChange={handleChange}
218
+ onKeyDown={handleEnterPressed}
219
+ />
220
+ {isOpen && (
221
+ <div
222
+ ref={refs.setFloating}
223
+ style={{
224
+ zIndex: "var(--z-popover)",
225
+ ...floatingStyles,
226
+ }}
227
+ className="shadow-lg bg-base ring-1 ring-tint-100"
228
+ data-ref="dropdownBody"
229
+ {...getFloatingProps()}
230
+ >
231
+ <DatePanel
232
+ withTime={type === "datetime"}
233
+ value={actualValue}
234
+ max={max}
235
+ min={min}
236
+ onChange={handleDateChange}
237
+ />
238
+ <FloatingArrow
239
+ ref={arrowRef}
240
+ context={context}
241
+ strokeWidth={0.5}
242
+ className="fill-base stroke-muted"
243
+ />
244
+ </div>
245
+ )}
246
+ </InputWrapper>
247
+ );
248
+ };
@@ -87,8 +87,9 @@ export const Field = ({
87
87
  classes.fieldGroup,
88
88
  !plain && !noOutline && "outline",
89
89
  !plain && "bg-base",
90
+ plain && "flex-wrap",
90
91
  "flex-1 rounded",
91
- !vertical && "flex flex-nowrap",
92
+ !vertical && "flex",
92
93
  )}
93
94
  >
94
95
  {cloneChildren(children, (child: AnyObject) =>
@@ -134,7 +134,7 @@ export const FileInput = ({
134
134
  }
135
135
  } else {
136
136
  setActualValue(e?.target.files?.item(0));
137
- onChange?.(e?.target.files?.item(0) ?? undefined);
137
+ onChange?.(e?.target.files?.item(0) ?? null);
138
138
  if (!e && inputRef.current) inputRef.current.value = "";
139
139
  }
140
140
  },
@@ -54,9 +54,10 @@ export const HiddenInput = ({
54
54
  name,
55
55
  }: Props) => {
56
56
  useEffect(() => {
57
- setTimeout(() => {
58
- onChange?.(hiddenValue);
59
- }, 50);
57
+ hiddenValue &&
58
+ setTimeout(() => {
59
+ onChange?.(hiddenValue);
60
+ }, 50);
60
61
  }, [hiddenValue]);
61
62
  return (
62
63
  <Fragment>
@@ -73,7 +73,7 @@ export const Input = ({
73
73
  (e?: ChangeEvent<HTMLInputElement>) => {
74
74
  const value = e?.target.value;
75
75
  setActualValue(value ?? "");
76
- onChange?.(value ?? undefined);
76
+ onChange?.(value ?? null);
77
77
  },
78
78
  [onchange],
79
79
  );
@@ -84,7 +84,7 @@ export const Number = ({
84
84
  (e?: ChangeEvent<HTMLInputElement>) => {
85
85
  const number = e?.target.valueAsNumber;
86
86
  setActualValue(number ?? "");
87
- onChange?.(number ?? undefined);
87
+ onChange?.(number ?? null);
88
88
  },
89
89
  [onChange],
90
90
  );
@@ -83,7 +83,7 @@ export const Password = ({
83
83
  (e?: ChangeEvent<HTMLInputElement>) => {
84
84
  const value = e?.target.value;
85
85
  setActualValue(value ?? "");
86
- onChange?.(value ?? undefined);
86
+ onChange?.(value ?? null);
87
87
  },
88
88
  [onChange],
89
89
  );
@@ -97,7 +97,7 @@ export interface RangeProps
97
97
  /**
98
98
  * Number Range input
99
99
  */
100
- export const Range = ({
100
+ export const RangeSlider = ({
101
101
  error,
102
102
  name,
103
103
  value,
@@ -141,7 +141,7 @@ export const Range = ({
141
141
  const handleChange = useCallback(
142
142
  (val: [number, number]) => {
143
143
  setActualValue(val ?? [min, max]);
144
- onChange?.(val ?? undefined);
144
+ onChange?.(val ?? null);
145
145
  },
146
146
  [onChange, min, max],
147
147
  );
@@ -96,7 +96,7 @@ export const Search = ({
96
96
  const value = e?.target.value;
97
97
  refValue.current = value ?? "";
98
98
  setActualValue(value ?? "");
99
- onChange?.(value ?? undefined);
99
+ onChange?.(value ?? null);
100
100
 
101
101
  // value was cleared so force fire onSearch
102
102
  if (searchOnChange) {
@@ -146,7 +146,7 @@ export const Slider = ({
146
146
  (value: number) => {
147
147
  const val = useInfinity && value === max ? Infinity : value;
148
148
  setActualValue(val ?? 0);
149
- onChange?.(val ?? undefined);
149
+ onChange?.(val ?? null);
150
150
  },
151
151
  [onChange, max, useInfinity],
152
152
  );
@@ -102,6 +102,8 @@ export const Switch = ({
102
102
  onLabelColor,
103
103
  offLabelColor,
104
104
  defaultColor,
105
+ // @ts-expect-error ignore
106
+ required,
105
107
  onChange,
106
108
  ...rest
107
109
  }: SwitchProps) => {
@@ -86,7 +86,7 @@ export const Textarea = ({
86
86
  (e?: ChangeEvent<HTMLTextAreaElement>) => {
87
87
  const value = e?.target.value;
88
88
  setActualValue(value ?? "");
89
- onChange?.(value ?? undefined);
89
+ onChange?.(value ?? null);
90
90
  },
91
91
  [onChange],
92
92
  );
@@ -71,7 +71,7 @@
71
71
  }
72
72
 
73
73
  & > input[type="number"] + .inputClear {
74
- margin-inline: -3rem 2rem;
74
+ margin-inline: -3rem 0;
75
75
  }
76
76
 
77
77
  & input::-ms-clear,
@@ -90,6 +90,17 @@
90
90
  letter-spacing: 2px;
91
91
  }
92
92
 
93
+ & input[type="date"]::-webkit-calendar-picker-indicator,
94
+ & input[type="datetime-local"]::-webkit-calendar-picker-indicator {
95
+ display: none;
96
+ appearance: none;
97
+ }
98
+
99
+ & input[type="date"]:global(.empty)::-webkit-datetime-edit,
100
+ & input[type="datetime-local"]:global(.empty)::-webkit-datetime-edit {
101
+ color: theme(colors.tint.400);
102
+ }
103
+
93
104
  & input:-webkit-autofill {
94
105
  box-shadow: 0 0 0 999em var(--fabric-input) inset;
95
106
 
@@ -44,6 +44,8 @@ export const InputWrapper = ({
44
44
  showClear,
45
45
  decorateStart,
46
46
  decorateEnd,
47
+ decorateEndShowWhenEmpty,
48
+ decorateEndHideWhenEmpty,
47
49
  children,
48
50
  onClear,
49
51
  noOutline,
@@ -155,6 +157,9 @@ export const InputWrapper = ({
155
157
  classes.decorate,
156
158
  "text-muted leading-none flex-content",
157
159
  isString(decorateEnd) && "px-1",
160
+ decorateEndHideWhenEmpty && "peer-placeholder-shown:hidden",
161
+ decorateEndShowWhenEmpty &&
162
+ "hidden peer-placeholder-shown:inline-block",
158
163
  )}
159
164
  >
160
165
  {decorateEnd}
@@ -34,7 +34,7 @@ export interface InputProps<V = string> extends TestProps {
34
34
  /**
35
35
  * change handler
36
36
  */
37
- onChange?: (value?: V) => void;
37
+ onChange?: (value?: V | null) => void;
38
38
  /**
39
39
  * on focus event handler
40
40
  */
@@ -72,6 +72,8 @@ export interface InputProps<V = string> extends TestProps {
72
72
  *
73
73
  */
74
74
  decorateEnd?: JSX.Element | string | number | boolean;
75
+ decorateEndShowWhenEmpty?: boolean;
76
+ decorateEndHideWhenEmpty?: boolean;
75
77
  /**
76
78
  * info label at bottom
77
79
  */
@@ -120,9 +122,7 @@ export interface InputProps<V = string> extends TestProps {
120
122
  labelWidth?: string;
121
123
  }
122
124
 
123
- export interface BaseSelectProps<T>
124
- extends RefProp<HTMLInputElement>,
125
- Omit<InputProps, "value" | "onChange"> {
125
+ export interface BaseSelectProps<T extends AnyObject = string> {
126
126
  /**
127
127
  * list options
128
128
  */
@@ -165,7 +165,11 @@ export interface BaseSelectProps<T>
165
165
  matcher?: (option: T, query: string) => boolean;
166
166
  }
167
167
 
168
- export type SelectProps<T> = BaseSelectProps<T> &
168
+ type BaseSelectType<T> = BaseSelectProps<T> &
169
+ RefProp<HTMLInputElement> &
170
+ Omit<InputProps, "value" | "onChange">;
171
+
172
+ export type SelectProps<T> = BaseSelectType<T> &
169
173
  (
170
174
  | {
171
175
  /**
@@ -21,80 +21,104 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- interface BaseSchemaDef {
24
+ import { type DateLike } from "@react-fabric/date";
25
+
26
+ export enum DATA_TYPES {
27
+ TEXT = "text",
28
+ COLOR = "color",
29
+ BOOL = "bool",
30
+ DATE = "date",
31
+ STRING = "string",
32
+ NUMBER = "number",
33
+ RANGE = "range",
34
+ FILE = "file",
35
+ AVATAR = "avatar",
36
+ SCHEMA = "schema",
37
+ }
38
+
39
+ interface SingleValue {
40
+ multiple?: false;
41
+ minItems?: never;
42
+ maxItems?: never;
43
+ }
44
+
45
+ interface MultipleValue {
46
+ multiple: true;
47
+ minItems?: number;
48
+ maxItems?: number;
49
+ }
50
+
51
+ export type ValueType = SingleValue | MultipleValue;
52
+
53
+ interface BaseSchema {
25
54
  id: string;
26
55
  label: string;
27
56
  datatype: string;
28
57
  required?: boolean;
29
- multiple?: boolean;
30
- defaultValue?: AnyObject;
31
58
  }
32
59
 
33
- interface SchemaDef extends BaseSchemaDef {
34
- datatype: "text" | "color";
60
+ export interface DefaultSchema extends BaseSchema {
61
+ datatype: DATA_TYPES.TEXT | DATA_TYPES.COLOR;
35
62
  }
36
63
 
37
- interface BooleanSchema extends BaseSchemaDef {
38
- datatype: "boolean";
39
- defaultValue?: boolean;
64
+ export interface BooleanSchema extends BaseSchema {
65
+ datatype: DATA_TYPES.BOOL;
40
66
  }
41
67
 
42
- interface StringSchema extends BaseSchemaDef {
43
- datatype: "string";
44
- options?: string[];
68
+ export interface StringSchema extends BaseSchema {
69
+ datatype: DATA_TYPES.STRING;
45
70
  regex?: string;
46
- identifierType?: string;
71
+ options?: string[];
72
+ optionList?: string;
73
+ allowCustom?: boolean;
47
74
  }
48
75
 
49
- interface RangeSchema extends BaseSchemaDef {
50
- datatype: "range";
76
+ export interface RangeSchema extends BaseSchema {
77
+ datatype: DATA_TYPES.RANGE;
51
78
  min?: number;
52
79
  max?: number;
53
80
  step?: number;
54
- defaultValue?: [number, number];
55
81
  }
56
82
 
57
- interface NumberSchema extends BaseSchemaDef {
58
- datatype: "number";
59
- min?: number;
60
- max?: number;
61
- step?: number;
62
- defaultValue?: number;
83
+ export interface DateSchema extends BaseSchema {
84
+ datatype: DATA_TYPES.DATE;
85
+ type?: "date" | "datetime";
86
+ min?: DateLike;
87
+ max?: DateLike;
63
88
  }
64
89
 
65
- interface DecimalSchema extends BaseSchemaDef {
66
- datatype: "decimal";
90
+ export interface NumberSchema extends BaseSchema {
91
+ datatype: DATA_TYPES.NUMBER;
67
92
  min?: number;
68
93
  max?: number;
69
94
  step?: number;
70
- defaultValue?: number;
71
95
  }
72
96
 
73
- export interface FileSchema extends BaseSchemaDef {
74
- datatype: "file";
97
+ export interface FileSchema extends BaseSchema {
98
+ datatype: DATA_TYPES.FILE;
75
99
  accept?: string;
76
100
  }
77
101
 
78
- export interface AvatarSchema extends BaseSchemaDef {
79
- datatype: "avatar";
102
+ export interface AvatarSchema extends BaseSchema {
103
+ datatype: DATA_TYPES.AVATAR;
80
104
  multiple?: false;
81
105
  }
82
106
 
83
107
  export type SchemaType =
84
- | SchemaDef
85
- | BooleanSchema
86
- | StringSchema
87
- | RangeSchema
88
- | NumberSchema
89
- | DecimalSchema
90
- | FileSchema
91
- | AvatarSchema;
92
-
93
- export interface ChildSchema extends BaseSchemaDef {
94
- datatype: "schema";
108
+ | (DefaultSchema & ValueType)
109
+ | (BooleanSchema & ValueType)
110
+ | (StringSchema & ValueType)
111
+ | (RangeSchema & ValueType)
112
+ | (DateSchema & ValueType)
113
+ | (NumberSchema & ValueType)
114
+ | (FileSchema & ValueType)
115
+ | (AvatarSchema & ValueType);
116
+
117
+ export interface ChildSchema extends BaseSchema {
118
+ datatype: DATA_TYPES.SCHEMA;
95
119
  inline?: boolean;
96
120
  schema: SchemaType[];
97
- defaultValue?: never;
98
121
  }
99
122
 
100
- export type FormSchema = SchemaType | ChildSchema;
123
+ export type SchemaDef = SchemaType | (ChildSchema & ValueType);
124
+ export type FormSchema = SchemaDef[];