@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
@@ -1,33 +1,42 @@
1
1
  'use client';
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import { EmptyContent } from '@react-fabric/core';
4
5
  import { yup, isNil, isEmpty } from '@react-fabric/utilities';
5
6
  import { useMemo, Fragment } from 'react';
6
7
  import { FormField } from '../builder/FormField.js';
7
- import { jsx } from 'react/jsx-runtime';
8
+ import { DATA_TYPES } from '../types/schema.js';
9
+ import { jsxs, jsx } from 'react/jsx-runtime';
8
10
 
9
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
12
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
13
  var makeYupField = function makeYupField(field) {
12
- var yupField = yup.string();
13
- if (field.datatype === "schema") {
14
+ var yupField = yup.string().trim();
15
+ if (field.datatype === DATA_TYPES.SCHEMA) {
14
16
  var child = Object.fromEntries(field.schema.map(function (field) {
15
17
  return [field.id, makeYupField(field)];
16
18
  }));
17
19
  yupField = yup.object(child);
18
20
  }
19
- if (field.datatype === "boolean") yupField = yup["boolean"]();
20
- if (field.datatype === "decimal" || field.datatype === "number" || field.datatype === "range") {
21
+ if (field.datatype === DATA_TYPES.BOOL) {
22
+ yupField = yup["boolean"]();
23
+ if (field.required) yupField = yupField.test({
24
+ test: function test(value) {
25
+ return !!value;
26
+ }
27
+ });
28
+ }
29
+ if (field.datatype === DATA_TYPES.NUMBER || field.datatype === DATA_TYPES.RANGE) {
21
30
  yupField = yup.number();
22
31
  !isNil(field.min) && (yupField = yupField.min(field.min));
23
32
  !isNil(field.max) && (yupField = yupField.max(field.max));
24
- if (field.datatype === "range") yupField = yup.array(yupField);
33
+ if (field.datatype === DATA_TYPES.RANGE) yupField = yup.array(yupField);
25
34
  }
26
- if (field.datatype === "string") {
27
- field.options && (yupField = yupField.oneOf(field.options));
35
+ if (field.datatype === DATA_TYPES.STRING) {
36
+ field.options && !field.allowCustom && (yupField = yupField.oneOf(field.options));
28
37
  field.regex && (yupField = yupField.matches(new RegExp(field.regex)));
29
38
  }
30
- if (field.datatype === "file") {
39
+ if (field.datatype === DATA_TYPES.FILE) {
31
40
  yupField = yup.object({
32
41
  filename: yup.string().required(),
33
42
  path: yup.string().required()
@@ -64,19 +73,22 @@ var useFormBuilder = function useFormBuilder(schema) {
64
73
  var schemaDef = yup.object(Object.fromEntries(filteredSchema.map(function (field) {
65
74
  return [field.id, makeYupField(field)];
66
75
  })));
67
- var formDef = /*#__PURE__*/jsx(Fragment, {
68
- children: filteredSchema.map(function (field, idx) {
76
+ var formDef = /*#__PURE__*/jsxs(Fragment, {
77
+ children: [filteredSchema.map(function (field, idx) {
69
78
  return /*#__PURE__*/jsx("div", {
70
79
  className: "mb-4",
71
- children: field.datatype === "schema" ? null : /*#__PURE__*/jsx(FormField, _objectSpread(_objectSpread({}, field), {}, {
80
+ children: field.datatype === DATA_TYPES.SCHEMA ? null : /*#__PURE__*/jsx(FormField, _objectSpread(_objectSpread({}, field), {}, {
72
81
  autoFocus: idx === 0,
73
82
  fileUrl: options.fileUrl,
83
+ optionLists: options.optionLists,
74
84
  uploadHandler: options.uploadHandler,
75
85
  inline: options.inline,
76
86
  prefix: options.prefix
77
87
  }))
78
88
  }, field.id);
79
- })
89
+ }), filteredSchema.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
90
+ message: "No schema defined"
91
+ })]
80
92
  });
81
93
  return {
82
94
  formDef: formDef,
package/dist/esm/index.js CHANGED
@@ -3,12 +3,15 @@
3
3
  import './i18n/index.js';
4
4
  export { Controller } from './form/Controller.js';
5
5
  export { Form } from './form/Form.js';
6
+ export { SchemaEditor } from './builder/SchemaEditor.js';
6
7
  export { useFileUploader } from './hooks/useFileUploader.js';
7
8
  export { useFormBuilder } from './hooks/useFormBuilder.js';
9
+ export { DATA_TYPES } from './types/schema.js';
8
10
  export { ArrayInput } from './input/ArrayInput.js';
9
11
  export { Checkbox } from './input/Checkbox.js';
10
12
  export { ColorInput } from './input/ColorInput.js';
11
13
  export { ColorPicker } from './input/ColorPicker.js';
14
+ export { DateInput } from './input/DateInput.js';
12
15
  export { Field } from './input/Field.js';
13
16
  export { FileInput } from './input/File.js';
14
17
  export { HiddenInput } from './input/Hidden.js';
@@ -17,7 +20,7 @@ export { Number } from './input/Number.js';
17
20
  export { Password } from './input/Password.js';
18
21
  export { Radio } from './input/Radio.js';
19
22
  export { RadioGroup } from './input/RadioGroup.js';
20
- export { Range } from './input/Range.js';
23
+ export { RangeSlider } from './input/RangeSlider.js';
21
24
  export { Search } from './input/Search.js';
22
25
  export { Slider } from './input/Slider.js';
23
26
  export { Switch } from './input/Switch.js';
@@ -9,7 +9,7 @@ import { useState, useDeferredValue, useMemo, useEffect, useCallback } from 'rea
9
9
  import { ErrorIcon } from '../internal/ErrorIcon.js';
10
10
  import { jsxs, jsx } from 'react/jsx-runtime';
11
11
 
12
- var _excluded = ["ref", "label", "value", "name", "checked", "invalid", "disabled", "error", "width", "icon", "iconChecked", "onChange"];
12
+ var _excluded = ["ref", "label", "value", "name", "checked", "invalid", "disabled", "error", "width", "icon", "iconChecked", "required", "onChange"];
13
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
15
  var Checkbox = function Checkbox(_ref) {
@@ -23,8 +23,9 @@ var Checkbox = function Checkbox(_ref) {
23
23
  error = _ref.error,
24
24
  width = _ref.width,
25
25
  icon = _ref.icon,
26
- iconChecked = _ref.iconChecked,
27
- onChange = _ref.onChange,
26
+ iconChecked = _ref.iconChecked;
27
+ _ref.required;
28
+ var onChange = _ref.onChange,
28
29
  rest = _objectWithoutProperties(_ref, _excluded);
29
30
  var _useState = useState(false),
30
31
  _useState2 = _slicedToArray(_useState, 2),
@@ -41,7 +41,7 @@ var ColorInput = function ColorInput(_ref) {
41
41
  var handleChange = useCallback(function (e) {
42
42
  setActualValue(e !== null && e !== void 0 ? e : defaultColor);
43
43
  onChange != null && startTransition(function () {
44
- return onChange(e);
44
+ return onChange(e !== null && e !== void 0 ? e : null);
45
45
  });
46
46
  }, [onChange]);
47
47
  var arrowRef = useRef(null);
@@ -0,0 +1,183 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
+ import { useFloating, autoUpdate, shift, flip, offset, arrow, useFocus, useClick, useDismiss, useInteractions, FloatingArrow } from '@floating-ui/react';
7
+ import { DateUtil, DatePanel } from '@react-fabric/date';
8
+ import { mergeRefs } from '@react-fabric/utilities';
9
+ import { useState, useDeferredValue, useMemo, useEffect, useCallback, startTransition, useRef } from 'react';
10
+ import { InputWrapper } from '../internal/InputWrapper.js';
11
+ import { handleEnter } from '../utils/eventHandlers.js';
12
+ import classNames from 'classnames';
13
+ import { jsxs, jsx } from 'react/jsx-runtime';
14
+
15
+ var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "type", "onChange", "onEnterPressed", "format", "min", "max"];
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
+ var DateInput = function DateInput(_ref) {
19
+ var ref = _ref.ref,
20
+ name = _ref.name,
21
+ value = _ref.value,
22
+ invalid = _ref.invalid,
23
+ readOnly = _ref.readOnly,
24
+ disabled = _ref.disabled,
25
+ required = _ref.required,
26
+ placeholder = _ref.placeholder,
27
+ autoFocus = _ref.autoFocus,
28
+ error = _ref.error,
29
+ _ref$type = _ref.type,
30
+ type = _ref$type === void 0 ? "date" : _ref$type,
31
+ onChange = _ref.onChange,
32
+ onEnterPressed = _ref.onEnterPressed;
33
+ _ref.format;
34
+ var min = _ref.min,
35
+ max = _ref.max,
36
+ rest = _objectWithoutProperties(_ref, _excluded);
37
+ var _useState = useState(""),
38
+ _useState2 = _slicedToArray(_useState, 2),
39
+ actualValue = _useState2[0],
40
+ setActualValue = _useState2[1];
41
+ var _useState3 = useState(""),
42
+ _useState4 = _slicedToArray(_useState3, 2),
43
+ inputValue = _useState4[0],
44
+ setInputValue = _useState4[1];
45
+ var deferred = useDeferredValue(value);
46
+ var inputFormat = useMemo(function () {
47
+ return type === "datetime" ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd";
48
+ }, [type]);
49
+ useEffect(function () {
50
+ setActualValue(deferred !== null && deferred !== void 0 ? deferred : "");
51
+ setInputValue(deferred ? DateUtil.format(deferred, inputFormat) : "");
52
+ }, [deferred, inputFormat]);
53
+ var handleEnterPressed = useMemo(function () {
54
+ return handleEnter(onEnterPressed);
55
+ }, [onEnterPressed]);
56
+ var handleChange = useCallback(function (e) {
57
+ var value = e === null || e === void 0 ? void 0 : e.currentTarget.value;
58
+ if (value) {
59
+ var _parsed$toISOString;
60
+ var parsed = DateUtil.parseDate(value);
61
+ setActualValue(parsed === null || parsed === void 0 || (_parsed$toISOString = parsed.toISOString) === null || _parsed$toISOString === void 0 ? void 0 : _parsed$toISOString.call(parsed));
62
+ setInputValue(DateUtil.format(parsed, inputFormat));
63
+ onChange != null && startTransition(function () {
64
+ var _parsed$toISOString2;
65
+ return onChange(parsed === null || parsed === void 0 || (_parsed$toISOString2 = parsed.toISOString) === null || _parsed$toISOString2 === void 0 ? void 0 : _parsed$toISOString2.call(parsed));
66
+ });
67
+ } else {
68
+ setActualValue("");
69
+ setInputValue("");
70
+ onChange != null && startTransition(function () {
71
+ return onChange(null);
72
+ });
73
+ }
74
+ }, [onChange, inputFormat]);
75
+ var handleDateChange = useCallback(function (value) {
76
+ if (value) {
77
+ var _parsed$toISOString3;
78
+ var parsed = DateUtil.parseDate(value);
79
+ setActualValue(parsed === null || parsed === void 0 || (_parsed$toISOString3 = parsed.toISOString) === null || _parsed$toISOString3 === void 0 ? void 0 : _parsed$toISOString3.call(parsed));
80
+ setInputValue(DateUtil.format(parsed, inputFormat));
81
+ onChange != null && startTransition(function () {
82
+ var _parsed$toISOString4;
83
+ return onChange(parsed === null || parsed === void 0 || (_parsed$toISOString4 = parsed.toISOString) === null || _parsed$toISOString4 === void 0 ? void 0 : _parsed$toISOString4.call(parsed));
84
+ });
85
+ } else {
86
+ setActualValue("");
87
+ setInputValue("");
88
+ onChange != null && startTransition(function () {
89
+ return onChange(null);
90
+ });
91
+ }
92
+ }, [onChange, inputFormat]);
93
+ var arrowRef = useRef(null);
94
+ var _useState5 = useState(false),
95
+ _useState6 = _slicedToArray(_useState5, 2),
96
+ isOpen = _useState6[0],
97
+ setIsOpen = _useState6[1];
98
+ var _useFloating = useFloating({
99
+ open: isOpen,
100
+ onOpenChange: function onOpenChange(open, _, reason) {
101
+ console.log(reason);
102
+ if (reason === "reference-press") return;
103
+ setIsOpen(open);
104
+ },
105
+ strategy: "fixed",
106
+ placement: "bottom-start",
107
+ whileElementsMounted: autoUpdate,
108
+ middleware: [shift({
109
+ padding: 8
110
+ }), flip(), offset(9), arrow({
111
+ element: arrowRef
112
+ })]
113
+ }),
114
+ refs = _useFloating.refs,
115
+ floatingStyles = _useFloating.floatingStyles,
116
+ context = _useFloating.context;
117
+ var focus = useFocus(context, {
118
+ enabled: !disabled
119
+ });
120
+ var click = useClick(context, {
121
+ enabled: !disabled,
122
+ toggle: false
123
+ });
124
+ var dismiss = useDismiss(context, {
125
+ referencePress: true
126
+ });
127
+ var _useInteractions = useInteractions([dismiss, click, focus]),
128
+ getReferenceProps = _useInteractions.getReferenceProps,
129
+ getFloatingProps = _useInteractions.getFloatingProps;
130
+ return /*#__PURE__*/jsxs(InputWrapper, _objectSpread(_objectSpread({
131
+ showClear: !!actualValue,
132
+ onClear: handleChange,
133
+ invalid: invalid,
134
+ readOnly: readOnly,
135
+ disabled: disabled,
136
+ required: required,
137
+ error: error
138
+ }, rest), {}, {
139
+ children: [/*#__PURE__*/jsx("input", _objectSpread(_objectSpread({
140
+ className: classNames("appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0 peer", !value && "empty"),
141
+ "aria-invalid": invalid,
142
+ "aria-disabled": disabled,
143
+ "aria-readonly": readOnly,
144
+ "aria-errormessage": error,
145
+ placeholder: placeholder,
146
+ disabled: disabled,
147
+ readOnly: readOnly,
148
+ "data-testid": name,
149
+ name: name,
150
+ size: 1,
151
+ type: type === "datetime" ? "datetime-local" : "date",
152
+ autoComplete: "off",
153
+ autoFocus: autoFocus,
154
+ value: inputValue,
155
+ ref: mergeRefs(ref, refs.setReference)
156
+ }, getReferenceProps()), {}, {
157
+ onChange: handleChange,
158
+ onKeyDown: handleEnterPressed
159
+ })), isOpen && /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
160
+ ref: refs.setFloating,
161
+ style: _objectSpread({
162
+ zIndex: "var(--z-popover)"
163
+ }, floatingStyles),
164
+ className: "shadow-lg bg-base ring-1 ring-tint-100",
165
+ "data-ref": "dropdownBody"
166
+ }, getFloatingProps()), {}, {
167
+ children: [/*#__PURE__*/jsx(DatePanel, {
168
+ withTime: type === "datetime",
169
+ value: actualValue,
170
+ max: max,
171
+ min: min,
172
+ onChange: handleDateChange
173
+ }), /*#__PURE__*/jsx(FloatingArrow, {
174
+ ref: arrowRef,
175
+ context: context,
176
+ strokeWidth: 0.5,
177
+ className: "fill-base stroke-muted"
178
+ })]
179
+ }))]
180
+ }));
181
+ };
182
+
183
+ export { DateInput };
@@ -20,7 +20,7 @@ var Field = function Field(_ref) {
20
20
  rest = _objectWithoutProperties(_ref, _excluded);
21
21
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
22
22
  children: /*#__PURE__*/jsx("div", {
23
- className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex flex-nowrap"),
23
+ className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", plain && "flex-wrap", "flex-1 rounded", !vertical && "flex"),
24
24
  children: cloneChildren(children, function (child) {
25
25
  return /*#__PURE__*/cloneElement(child, {
26
26
  "data-inner": true
@@ -90,7 +90,7 @@ var FileInput = function FileInput(_ref) {
90
90
  } else {
91
91
  var _e$target$files, _e$target$files$item, _e$target$files2;
92
92
  setActualValue(e === null || e === void 0 || (_e$target$files = e.target.files) === null || _e$target$files === void 0 ? void 0 : _e$target$files.item(0));
93
- onChange === null || onChange === void 0 || onChange((_e$target$files$item = e === null || e === void 0 || (_e$target$files2 = e.target.files) === null || _e$target$files2 === void 0 ? void 0 : _e$target$files2.item(0)) !== null && _e$target$files$item !== void 0 ? _e$target$files$item : undefined);
93
+ onChange === null || onChange === void 0 || onChange((_e$target$files$item = e === null || e === void 0 || (_e$target$files2 = e.target.files) === null || _e$target$files2 === void 0 ? void 0 : _e$target$files2.item(0)) !== null && _e$target$files$item !== void 0 ? _e$target$files$item : null);
94
94
  if (!e && inputRef.current) inputRef.current.value = "";
95
95
  }
96
96
  }, [onChange, multiple, showList]);
@@ -36,7 +36,7 @@ var HiddenInput = function HiddenInput(_ref) {
36
36
  value = _ref$value === void 0 ? "" : _ref$value,
37
37
  name = _ref.name;
38
38
  useEffect(function () {
39
- setTimeout(function () {
39
+ hiddenValue && setTimeout(function () {
40
40
  onChange === null || onChange === void 0 || onChange(hiddenValue);
41
41
  }, 50);
42
42
  }, [hiddenValue]);
@@ -42,7 +42,7 @@ var Input = function Input(_ref) {
42
42
  var handleChange = useCallback(function (e) {
43
43
  var value = e === null || e === void 0 ? void 0 : e.target.value;
44
44
  setActualValue(value !== null && value !== void 0 ? value : "");
45
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
45
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
46
46
  }, [onchange]);
47
47
  return /*#__PURE__*/jsx(InputWrapper, _objectSpread(_objectSpread({
48
48
  showClear: !!actualValue,
@@ -42,7 +42,7 @@ var Number = function Number(_ref) {
42
42
  var handleChange = useCallback(function (e) {
43
43
  var number = e === null || e === void 0 ? void 0 : e.target.valueAsNumber;
44
44
  setActualValue(number !== null && number !== void 0 ? number : "");
45
- onChange === null || onChange === void 0 || onChange(number !== null && number !== void 0 ? number : undefined);
45
+ onChange === null || onChange === void 0 || onChange(number !== null && number !== void 0 ? number : null);
46
46
  }, [onChange]);
47
47
  return /*#__PURE__*/jsx(InputWrapper, _objectSpread(_objectSpread({
48
48
  showClear: !!actualValue,
@@ -50,7 +50,7 @@ var Password = function Password(_ref) {
50
50
  var handleChange = useCallback(function (e) {
51
51
  var value = e === null || e === void 0 ? void 0 : e.target.value;
52
52
  setActualValue(value !== null && value !== void 0 ? value : "");
53
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
53
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
54
54
  }, [onChange]);
55
55
  return /*#__PURE__*/jsxs(InputWrapper, _objectSpread(_objectSpread({
56
56
  showClear: !!actualValue,
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  /**
17
17
  * Number Range input
18
18
  */
19
- var Range = function Range(_ref) {
19
+ var RangeSlider = function RangeSlider(_ref) {
20
20
  var error = _ref.error;
21
21
  _ref.name;
22
22
  var value = _ref.value,
@@ -71,7 +71,7 @@ var Range = function Range(_ref) {
71
71
  }, [showValue]);
72
72
  var handleChange = useCallback(function (val) {
73
73
  setActualValue(val !== null && val !== void 0 ? val : [min, max]);
74
- onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : undefined);
74
+ onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : null);
75
75
  }, [onChange, min, max]);
76
76
  var minDisplay = useMemo(function () {
77
77
  return /*#__PURE__*/jsx("span", {
@@ -166,4 +166,4 @@ var Range = function Range(_ref) {
166
166
  }));
167
167
  };
168
168
 
169
- export { Range };
169
+ export { RangeSlider };
@@ -53,7 +53,7 @@ var Search = function Search(_ref) {
53
53
  var value = e === null || e === void 0 ? void 0 : e.target.value;
54
54
  refValue.current = value !== null && value !== void 0 ? value : "";
55
55
  setActualValue(value !== null && value !== void 0 ? value : "");
56
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
56
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
57
57
 
58
58
  // value was cleared so force fire onSearch
59
59
  if (searchOnChange) {
@@ -73,7 +73,7 @@ var Slider = function Slider(_ref) {
73
73
  var handleChange = useCallback(function (value) {
74
74
  var val = useInfinity && value === max ? Infinity : value;
75
75
  setActualValue(val !== null && val !== void 0 ? val : 0);
76
- onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : undefined);
76
+ onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : null);
77
77
  }, [onChange, max, useInfinity]);
78
78
  var minDisplay = useMemo(function () {
79
79
  return /*#__PURE__*/jsx("span", {
@@ -10,7 +10,7 @@ import '@react-fabric/utilities';
10
10
  import { getBgClass, getColor, getColorClass } from '../utils/getColor.js';
11
11
  import { jsxs, jsx } from 'react/jsx-runtime';
12
12
 
13
- var _excluded = ["ref", "label", "checked", "invalid", "disabled", "error", "width", "color", "name", "onLabel", "offLabel", "onLabelColor", "offLabelColor", "defaultColor", "onChange"];
13
+ var _excluded = ["ref", "label", "checked", "invalid", "disabled", "error", "width", "color", "name", "onLabel", "offLabel", "onLabelColor", "offLabelColor", "defaultColor", "required", "onChange"];
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
16
  var Switch = function Switch(_ref) {
@@ -27,8 +27,9 @@ var Switch = function Switch(_ref) {
27
27
  offLabel = _ref.offLabel,
28
28
  onLabelColor = _ref.onLabelColor,
29
29
  offLabelColor = _ref.offLabelColor,
30
- defaultColor = _ref.defaultColor,
31
- onChange = _ref.onChange,
30
+ defaultColor = _ref.defaultColor;
31
+ _ref.required;
32
+ var onChange = _ref.onChange,
32
33
  rest = _objectWithoutProperties(_ref, _excluded);
33
34
  var _useState = useState(false),
34
35
  _useState2 = _slicedToArray(_useState, 2),
@@ -47,7 +47,7 @@ var Textarea = function Textarea(_ref) {
47
47
  var handleChange = useCallback(function (e) {
48
48
  var value = e === null || e === void 0 ? void 0 : e.target.value;
49
49
  setActualValue(value !== null && value !== void 0 ? value : "");
50
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
50
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
51
51
  }, [onChange]);
52
52
  useEffect(function () {
53
53
  if (variableRows) {
@@ -1 +1 @@
1
- @layer comp{}@layer var{.inputWrapper{&:after{inset-inline:50%;transition:all .3s;transition-delay:.1s}& .decorate:has([data-ref=button]){align-self:stretch;display:flex}&:has(input[disabled],textarea[disabled]){background-color:theme(colors.tint.50);cursor:not-allowed;& input,& textarea{cursor:not-allowed}}&:focus-within,&:has([data-open=true]){background-color:var(--fabric-input-focus);outline-color:var(--primary);z-index:1;&:not(:has([aria-readonly=true]:not([hidden]))):after{inset-inline:0}}&:global(.fixed){box-shadow:0 0 2rem .5rem var(--fabric-shadow)}& input,& textarea{max-width:100%}&>input[type=number]+.inputClear{margin-inline:-3rem 2rem}& input::-ms-clear,& select::-ms-clear,& textarea::-ms-clear{display:none}& input[type=search]::-webkit-search-cancel-button{display:none}& input[type=password]:not(:placeholder-shown){font-family:caption;letter-spacing:2px}& input:-webkit-autofill{box-shadow:0 0 0 999em var(--fabric-input) inset;-webkit-text-fill-color:theme(colors.accent.700)}& input:-webkit-autofill:focus{box-shadow:0 0 0 999em var(--fabric-input-focus) inset;-webkit-text-fill-color:theme(colors.accent.700)}&.invalidWrapper{outline-color:theme(colors.danger.500);&:after{background-color:theme(colors.danger.500)}}}.fieldGroup{>*{line-height:1}>:not(:first-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-start-radius:0;border-start-start-radius:0}}>:not(:last-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-end-radius:0;border-start-end-radius:0}}}}
1
+ @layer comp{}@layer var{.inputWrapper{&:after{inset-inline:50%;transition:all .3s;transition-delay:.1s}& .decorate:has([data-ref=button]){align-self:stretch;display:flex}&:has(input[disabled],textarea[disabled]){background-color:theme(colors.tint.50);cursor:not-allowed;& input,& textarea{cursor:not-allowed}}&:focus-within,&:has([data-open=true]){background-color:var(--fabric-input-focus);outline-color:var(--primary);z-index:1;&:not(:has([aria-readonly=true]:not([hidden]))):after{inset-inline:0}}&:global(.fixed){box-shadow:0 0 2rem .5rem var(--fabric-shadow)}& input,& textarea{max-width:100%}&>input[type=number]+.inputClear{margin-inline:-3rem 0}& input::-ms-clear,& select::-ms-clear,& textarea::-ms-clear{display:none}& input[type=search]::-webkit-search-cancel-button{display:none}& input[type=password]:not(:placeholder-shown){font-family:caption;letter-spacing:2px}& input[type=date]::-webkit-calendar-picker-indicator,& input[type=datetime-local]::-webkit-calendar-picker-indicator{appearance:none;display:none}& input[type=date]:global(.empty)::-webkit-datetime-edit,& input[type=datetime-local]:global(.empty)::-webkit-datetime-edit{color:theme(colors.tint.400)}& input:-webkit-autofill{box-shadow:0 0 0 999em var(--fabric-input) inset;-webkit-text-fill-color:theme(colors.accent.700)}& input:-webkit-autofill:focus{box-shadow:0 0 0 999em var(--fabric-input-focus) inset;-webkit-text-fill-color:theme(colors.accent.700)}&.invalidWrapper{outline-color:theme(colors.danger.500);&:after{background-color:theme(colors.danger.500)}}}.fieldGroup{>*{line-height:1}>:not(:first-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-start-radius:0;border-start-start-radius:0}}>:not(:last-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-end-radius:0;border-start-end-radius:0}}}}
@@ -12,7 +12,7 @@ import { ErrorIcon } from './ErrorIcon.js';
12
12
  import classes from './Field.module.css';
13
13
  import { FieldWrapper } from './FieldWrapper.js';
14
14
 
15
- var _excluded = ["invalid", "error", "allowClear", "showClear", "decorateStart", "decorateEnd", "children", "onClear", "noOutline", "noBorder", "textarea", "textareaExpandable", "data-inner", "data-open", "floatingExpand", "wrapperRef", "width"];
15
+ var _excluded = ["invalid", "error", "allowClear", "showClear", "decorateStart", "decorateEnd", "decorateEndShowWhenEmpty", "decorateEndHideWhenEmpty", "children", "onClear", "noOutline", "noBorder", "textarea", "textareaExpandable", "data-inner", "data-open", "floatingExpand", "wrapperRef", "width"];
16
16
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
18
  var InputWrapper = function InputWrapper(_ref) {
@@ -22,6 +22,8 @@ var InputWrapper = function InputWrapper(_ref) {
22
22
  showClear = _ref.showClear,
23
23
  decorateStart = _ref.decorateStart,
24
24
  decorateEnd = _ref.decorateEnd,
25
+ decorateEndShowWhenEmpty = _ref.decorateEndShowWhenEmpty,
26
+ decorateEndHideWhenEmpty = _ref.decorateEndHideWhenEmpty,
25
27
  children = _ref.children,
26
28
  onClear = _ref.onClear,
27
29
  noOutline = _ref.noOutline,
@@ -84,7 +86,7 @@ var InputWrapper = function InputWrapper(_ref) {
84
86
  className: classNames("text-tint-500 hover:text-tint-700 p-1 z-1 flex-content", classes.inputClear, textarea && "self-start mt-1 me-1")
85
87
  }), decorateEnd && /*#__PURE__*/jsx("div", {
86
88
  onClickCapture: doFocus,
87
- className: classNames(classes.decorate, "text-muted leading-none flex-content", isString(decorateEnd) && "px-1"),
89
+ className: classNames(classes.decorate, "text-muted leading-none flex-content", isString(decorateEnd) && "px-1", decorateEndHideWhenEmpty && "peer-placeholder-shown:hidden", decorateEndShowWhenEmpty && "hidden peer-placeholder-shown:inline-block"),
88
90
  children: decorateEnd
89
91
  }), textareaExpandable && /*#__PURE__*/jsx(Icon, {
90
92
  onClick: function onClick() {
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+
3
+ /*
4
+ * React Fabric
5
+ * @version: 1.0.0
6
+ *
7
+ *
8
+ * The MIT License (MIT)
9
+ * Copyright (c) 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
12
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
13
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
15
+ * subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
18
+ * portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+
26
+ var DATA_TYPES = /*#__PURE__*/function (DATA_TYPES) {
27
+ DATA_TYPES["TEXT"] = "text";
28
+ DATA_TYPES["COLOR"] = "color";
29
+ DATA_TYPES["BOOL"] = "bool";
30
+ DATA_TYPES["DATE"] = "date";
31
+ DATA_TYPES["STRING"] = "string";
32
+ DATA_TYPES["NUMBER"] = "number";
33
+ DATA_TYPES["RANGE"] = "range";
34
+ DATA_TYPES["FILE"] = "file";
35
+ DATA_TYPES["AVATAR"] = "avatar";
36
+ DATA_TYPES["SCHEMA"] = "schema";
37
+ return DATA_TYPES;
38
+ }({});
39
+
40
+ export { DATA_TYPES };
@@ -1,6 +1,6 @@
1
1
  import { type UploadHandler } from "../hooks/useFileUploader";
2
- import { type FileSchema } from "../types/schema";
3
- export declare const FileField: ({ uploadHandler, inline, label, accept, multiple, value, ...rest }: Partial<FileSchema> & {
2
+ import { type FileSchema, type ValueType } from "../types/schema";
3
+ export declare const FileField: ({ uploadHandler, inline, label, accept, value, fileUrl, multiple, ...rest }: Partial<FileSchema & ValueType> & {
4
4
  value?: AnyObject;
5
5
  inline?: boolean;
6
6
  fileUrl?: (path: string) => string;
@@ -1,9 +1,11 @@
1
1
  import { type UploadHandler } from "../hooks/useFileUploader";
2
+ import { type BaseSelectProps } from "../types";
2
3
  import { type SchemaType } from "../types/schema";
3
- export declare const FormField: ({ id, label, required, inline, prefix, autoFocus, defaultValue, fileUrl, uploadHandler, ...rest }: SchemaType & {
4
+ export declare const FormField: ({ id, label, required, inline, prefix, autoFocus, optionLists, fileUrl, uploadHandler, ...rest }: SchemaType & {
4
5
  inline?: boolean;
5
6
  prefix?: string;
6
7
  autoFocus?: boolean;
8
+ optionLists?: KeyValue<BaseSelectProps<any>>;
7
9
  fileUrl?: (path: string) => string;
8
10
  uploadHandler?: UploadHandler;
9
11
  }) => import("react/jsx-runtime").JSX.Element | undefined;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { type Elements } from "@react-fabric/core/dist/types/types";
3
+ import { DATA_TYPES, type FormSchema } from "../types/schema";
4
+ interface Props {
5
+ schemaDef: FormSchema;
6
+ allowRemove?: boolean;
7
+ acceptableTypes?: DATA_TYPES[];
8
+ optionLists?: string[];
9
+ /**
10
+ * Footer actions
11
+ */
12
+ children?: Elements<JSX.Element> | Array<Elements<JSX.Element>>;
13
+ onChange: (schema: FormSchema) => void;
14
+ }
15
+ export declare const SchemaEditor: ({ schemaDef, allowRemove, acceptableTypes, optionLists, children, onChange, }: Props) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -14,7 +14,7 @@ export interface ControllerProps {
14
14
  disabled?: boolean;
15
15
  onBlur: () => void;
16
16
  onChange: (value: AnyObject) => void;
17
- inputRef?: React.Ref<HTMLInputElement>;
17
+ ref?: React.Ref<HTMLInputElement>;
18
18
  }) => ReactElement);
19
19
  }
20
20
  export declare const Controller: ({ name, children, ...rest }: ControllerProps) => import("react/jsx-runtime").JSX.Element;
@@ -8,6 +8,7 @@ export interface FormRef<K extends KeyValue> {
8
8
  submit: () => void;
9
9
  validate: () => Promise<boolean>;
10
10
  getValues: () => K;
11
+ removeField: (field: string) => void;
11
12
  setValue: (key: keyof K, value: AnyObject) => void;
12
13
  setValues: (values: K) => void;
13
14
  }
@@ -1,11 +1,13 @@
1
1
  import { yup } from "@react-fabric/utilities";
2
+ import { type BaseSelectProps } from "../types";
2
3
  import { type FormSchema } from "../types/schema";
3
4
  import { type UploadHandler } from "./useFileUploader";
4
- export declare const useFormBuilder: (schema: FormSchema[], options?: {
5
+ export declare const useFormBuilder: <T extends unknown = string>(schema: FormSchema, options?: {
5
6
  prefix?: string;
6
7
  inline?: boolean;
7
8
  fileUrl?: (path: string) => string;
8
9
  uploadHandler?: UploadHandler;
10
+ optionLists?: KeyValue<BaseSelectProps<T>>;
9
11
  }) => {
10
12
  formDef: import("react/jsx-runtime").JSX.Element;
11
13
  schemaDef: yup.ObjectSchema<{