@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
@@ -2,22 +2,25 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import { isEmpty } from '@react-fabric/utilities';
5
6
  import { useMemo } from 'react';
6
7
  import { useTranslation } from 'react-i18next';
7
8
  import { Controller } from '../form/Controller.js';
8
9
  import { ArrayInput } from '../input/ArrayInput.js';
9
10
  import { AvatarInput } from '../input/AvatarInput.js';
10
11
  import { ColorInput } from '../input/ColorInput.js';
12
+ import { DateInput } from '../input/DateInput.js';
11
13
  import { Input } from '../input/Input.js';
12
14
  import { Number } from '../input/Number.js';
13
- import { Range } from '../input/Range.js';
15
+ import { RangeSlider } from '../input/RangeSlider.js';
14
16
  import { Switch } from '../input/Switch.js';
15
17
  import { Textarea } from '../input/Textarea.js';
16
18
  import { Select } from '../select/Select.js';
19
+ import { DATA_TYPES } from '../types/schema.js';
17
20
  import { FileField } from './FileField.js';
18
21
  import { jsx } from 'react/jsx-runtime';
19
22
 
20
- var _excluded = ["id", "label", "required", "inline", "prefix", "autoFocus", "defaultValue", "fileUrl", "uploadHandler"];
23
+ var _excluded = ["id", "label", "required", "inline", "prefix", "autoFocus", "optionLists", "fileUrl", "uploadHandler"];
21
24
  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; }
22
25
  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; }
23
26
  var FormField = function FormField(_ref) {
@@ -26,9 +29,9 @@ var FormField = function FormField(_ref) {
26
29
  required = _ref.required,
27
30
  inline = _ref.inline,
28
31
  prefix = _ref.prefix,
29
- autoFocus = _ref.autoFocus;
30
- _ref.defaultValue;
31
- var fileUrl = _ref.fileUrl,
32
+ autoFocus = _ref.autoFocus,
33
+ optionLists = _ref.optionLists,
34
+ fileUrl = _ref.fileUrl,
32
35
  uploadHandler = _ref.uploadHandler,
33
36
  rest = _objectWithoutProperties(_ref, _excluded);
34
37
  var _useTranslation = useTranslation(),
@@ -36,48 +39,55 @@ var FormField = function FormField(_ref) {
36
39
  var fieldName = useMemo(function () {
37
40
  return [prefix, id].filter(Boolean).join(".");
38
41
  }, [id, prefix]);
42
+ var hasOptions = useMemo(function () {
43
+ var _rest$optionList;
44
+ return rest.datatype === DATA_TYPES.STRING && (rest.optionList === "--CUSTOM--" && !isEmpty(rest.options) || !isEmpty(optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList = rest.optionList) !== null && _rest$optionList !== void 0 ? _rest$optionList : ""]));
45
+ }, [rest]);
39
46
  var E = useMemo(function () {
40
- if (rest.datatype === "number" || rest.datatype === "decimal") return Number;
41
- if (rest.datatype === "range") return Range;
42
- if (rest.datatype === "boolean") return Switch;
43
- if (rest.datatype === "text") return Textarea;
44
- if (rest.datatype === "color") return ColorInput;
45
- if (rest.datatype === "string" && rest.options) return Select;
47
+ if (rest.datatype === DATA_TYPES.NUMBER) return Number;
48
+ if (rest.datatype === DATA_TYPES.RANGE) return RangeSlider;
49
+ if (rest.datatype === DATA_TYPES.BOOL) return Switch;
50
+ if (rest.datatype === DATA_TYPES.TEXT) return Textarea;
51
+ if (rest.datatype === DATA_TYPES.DATE) return DateInput;
52
+ if (rest.datatype === DATA_TYPES.COLOR) return ColorInput;
53
+ if (hasOptions) return Select;
46
54
  return Input;
47
- }, [rest.datatype]);
55
+ }, [rest.datatype, hasOptions]);
48
56
  var props = useMemo(function () {
49
- var _rest$step, _rest$step2, _rest$min, _rest$max, _rest$step3;
50
- if (rest.datatype === "number") return {
57
+ var _rest$step, _rest$min, _rest$max, _rest$step2, _optionLists, _rest$optionList2;
58
+ if (rest.datatype === DATA_TYPES.NUMBER) return {
51
59
  min: rest.min,
52
60
  max: rest.max,
53
61
  step: (_rest$step = rest.step) !== null && _rest$step !== void 0 ? _rest$step : 1
54
62
  };
55
- if (rest.datatype === "decimal") return {
56
- min: rest.min,
57
- max: rest.max,
58
- step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 0.1
59
- };
60
- if (rest.datatype === "range") return {
63
+ if (rest.datatype === DATA_TYPES.RANGE) return {
61
64
  min: (_rest$min = rest.min) !== null && _rest$min !== void 0 ? _rest$min : 1,
62
65
  max: (_rest$max = rest.max) !== null && _rest$max !== void 0 ? _rest$max : 99,
63
- step: (_rest$step3 = rest.step) !== null && _rest$step3 !== void 0 ? _rest$step3 : 1,
66
+ step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 1,
64
67
  showValue: true,
65
68
  showLabels: true
66
69
  };
67
- if (rest.datatype === "text") return {
70
+ if (rest.datatype === DATA_TYPES.DATE) return {
71
+ min: rest.min,
72
+ max: rest.max,
73
+ type: rest.type
74
+ };
75
+ if (rest.datatype === DATA_TYPES.TEXT) return {
68
76
  rows: 3
69
77
  };
70
- if (rest.datatype === "color") return {
78
+ if (rest.datatype === DATA_TYPES.COLOR) return {
71
79
  showPicker: true
72
80
  };
73
- if (rest.datatype === "string" && rest.options) return {
74
- options: rest.options,
81
+ if (rest.datatype === DATA_TYPES.STRING && hasOptions) return _objectSpread({
75
82
  multiple: rest.multiple,
83
+ allowCreate: rest.allowCustom,
76
84
  searchable: true
77
- };
85
+ }, (_optionLists = optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList2 = rest.optionList) !== null && _rest$optionList2 !== void 0 ? _rest$optionList2 : ""]) !== null && _optionLists !== void 0 ? _optionLists : {
86
+ options: rest.options
87
+ });
78
88
  return {};
79
- }, [rest]);
80
- if (rest.datatype === "avatar") return uploadHandler && /*#__PURE__*/jsx(Controller, {
89
+ }, [rest, hasOptions, optionLists]);
90
+ if (rest.datatype === DATA_TYPES.AVATAR) return uploadHandler && /*#__PURE__*/jsx(Controller, {
81
91
  name: fieldName,
82
92
  children: /*#__PURE__*/jsx(AvatarInput, {
83
93
  uploadHandler: uploadHandler,
@@ -85,7 +95,7 @@ var FormField = function FormField(_ref) {
85
95
  name: fieldName
86
96
  })
87
97
  });
88
- if (rest.datatype === "file") return uploadHandler && /*#__PURE__*/jsx(Controller, {
98
+ if (rest.datatype === DATA_TYPES.FILE) return uploadHandler && /*#__PURE__*/jsx(Controller, {
89
99
  name: fieldName,
90
100
  children: /*#__PURE__*/jsx(FileField, _objectSpread({
91
101
  uploadHandler: uploadHandler,
@@ -94,12 +104,12 @@ var FormField = function FormField(_ref) {
94
104
  id: id
95
105
  }, rest))
96
106
  });
97
- return rest.multiple && !("options" in rest) ? /*#__PURE__*/jsx(ArrayInput, {
107
+ return rest.multiple && !hasOptions ? /*#__PURE__*/jsx(ArrayInput, {
98
108
  name: fieldName,
99
- label: t(label, label),
109
+ label: t("fb.".concat(id), label || id),
100
110
  required: required,
101
111
  onAdd: function onAdd() {
102
- return "";
112
+ return String("");
103
113
  },
104
114
  children: /*#__PURE__*/jsx(Controller, {
105
115
  children: /*#__PURE__*/jsx(E, _objectSpread({}, props))
@@ -108,8 +118,8 @@ var FormField = function FormField(_ref) {
108
118
  name: fieldName,
109
119
  children: /*#__PURE__*/jsx(E, _objectSpread(_objectSpread({}, props), {}, {
110
120
  autoFocus: autoFocus,
111
- label: t(label, label),
112
- placeholder: t(label, label),
121
+ label: t("fb.".concat(id), label || id),
122
+ placeholder: t("fb.".concat(id), label || id),
113
123
  required: required,
114
124
  inline: inline
115
125
  }))
@@ -0,0 +1,439 @@
1
+ 'use client';
2
+
3
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
+ import { Content, Footer, useOverlayService, Modal, Button, Collapsable, CoreIcons, ToggleButtonGroup } from '@react-fabric/core';
7
+ import { EMPTY_ARRAY } from '@react-fabric/utilities';
8
+ import { useRef, useState, useEffect, useCallback, Fragment } from 'react';
9
+ import { Controller } from '../form/Controller.js';
10
+ import { Form } from '../form/Form.js';
11
+ import { ArrayInput } from '../input/ArrayInput.js';
12
+ import { Checkbox } from '../input/Checkbox.js';
13
+ import { DateInput } from '../input/DateInput.js';
14
+ import { Field } from '../input/Field.js';
15
+ import { HiddenInput } from '../input/Hidden.js';
16
+ import { Input } from '../input/Input.js';
17
+ import { Number } from '../input/Number.js';
18
+ import { Select } from '../select/Select.js';
19
+ import { DATA_TYPES } from '../types/schema.js';
20
+ import { jsxs, jsx } from 'react/jsx-runtime';
21
+
22
+ 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; }
23
+ 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; }
24
+ var CUSTOM_LIST = "--CUSTOM--";
25
+ var SchemaField = function SchemaField(_ref) {
26
+ var field = _ref.field,
27
+ getModel = _ref.getModel,
28
+ onRemove = _ref.onRemove,
29
+ _ref$optionLists = _ref.optionLists,
30
+ optionLists = _ref$optionLists === void 0 ? EMPTY_ARRAY : _ref$optionLists,
31
+ allowRemove = _ref.allowRemove,
32
+ onTypeChange = _ref.onTypeChange,
33
+ acceptableTypes = _ref.acceptableTypes;
34
+ var _useState = useState(),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ type = _useState2[0],
37
+ setType = _useState2[1];
38
+ var _useState3 = useState(false),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ multiple = _useState4[0],
41
+ setMultiple = _useState4[1];
42
+ var _useState5 = useState(false),
43
+ _useState6 = _slicedToArray(_useState5, 2),
44
+ hasOptions = _useState6[0],
45
+ setHasOptions = _useState6[1];
46
+ var _useState7 = useState(false),
47
+ _useState8 = _slicedToArray(_useState7, 2),
48
+ customOptions = _useState8[0],
49
+ setCustomOptions = _useState8[1];
50
+ var _useOverlayService = useOverlayService(function (props) {
51
+ return /*#__PURE__*/jsxs(Modal, _objectSpread(_objectSpread({}, props), {}, {
52
+ children: [/*#__PURE__*/jsx(Content, {
53
+ children: /*#__PURE__*/jsx(ArrayInput, {
54
+ name: "".concat(field, ".options"),
55
+ onAdd: function onAdd() {
56
+ return String("");
57
+ },
58
+ children: /*#__PURE__*/jsx(Controller, {
59
+ children: /*#__PURE__*/jsx(Input, {})
60
+ })
61
+ })
62
+ }), /*#__PURE__*/jsx(Footer, {
63
+ flex: true,
64
+ justify: "end",
65
+ className: "sticky bottom-0 border-t bg-base px-6 py-2",
66
+ children: /*#__PURE__*/jsx(Button, {
67
+ variant: "link",
68
+ onClick: props.onClose,
69
+ children: "Close"
70
+ })
71
+ })]
72
+ }));
73
+ }),
74
+ _useOverlayService2 = _slicedToArray(_useOverlayService, 2),
75
+ OptionModal = _useOverlayService2[0],
76
+ openOptionModal = _useOverlayService2[1];
77
+ useEffect(function () {
78
+ setTimeout(function () {
79
+ var model = getModel();
80
+ setType(model.datatype);
81
+ setMultiple(model.multiple);
82
+ setHasOptions(!!model.optionList);
83
+ setCustomOptions(model.optionList === CUSTOM_LIST);
84
+ }, 10);
85
+ }, []);
86
+ var handleTypeChange = useCallback(function (type) {
87
+ if (type) {
88
+ var modelRef = getModel();
89
+ var reset = {
90
+ datatype: type,
91
+ id: field,
92
+ label: modelRef.label,
93
+ defaultValue: modelRef.defaultValue,
94
+ required: modelRef.required,
95
+ multiple: type === DATA_TYPES.AVATAR ? false : modelRef.multiple,
96
+ minItems: modelRef.minItems,
97
+ maxItems: modelRef.maxItems
98
+ };
99
+ if (type === DATA_TYPES.STRING) {
100
+ reset = Object.assign(reset, {
101
+ optionList: modelRef.optionList,
102
+ options: modelRef.options,
103
+ regex: modelRef.regex
104
+ });
105
+ } else if (type === DATA_TYPES.DATE) {
106
+ reset = Object.assign(reset, {
107
+ type: "date"
108
+ });
109
+ } else if (type === DATA_TYPES.NUMBER || type === DATA_TYPES.RANGE) {
110
+ reset = Object.assign(reset, {
111
+ min: modelRef.min,
112
+ max: modelRef.max,
113
+ step: modelRef.step
114
+ });
115
+ }
116
+ if (type === DATA_TYPES.AVATAR) {
117
+ setMultiple(false);
118
+ }
119
+ onTypeChange(reset);
120
+ setType(type);
121
+ }
122
+ }, []);
123
+ return /*#__PURE__*/jsxs(Collapsable, {
124
+ open: true,
125
+ children: [/*#__PURE__*/jsxs("div", {
126
+ className: "flex flex-nowrap group/field",
127
+ children: [/*#__PURE__*/jsx("span", {
128
+ className: "flex-1 truncate",
129
+ children: field
130
+ }), allowRemove && /*#__PURE__*/jsx(Button, {
131
+ size: "sm",
132
+ color: "danger",
133
+ variant: "link",
134
+ "aria-label": "Delete",
135
+ stopPropagation: true,
136
+ icon: CoreIcons.trash,
137
+ onClick: onRemove,
138
+ className: "invisible group-hover/field:visible"
139
+ })]
140
+ }), /*#__PURE__*/jsxs("div", {
141
+ className: "flex flex-col gap-1 pb-4",
142
+ children: [/*#__PURE__*/jsx(Controller, {
143
+ name: "".concat(field, ".id"),
144
+ children: /*#__PURE__*/jsx(HiddenInput, {
145
+ hiddenValue: field
146
+ })
147
+ }), /*#__PURE__*/jsx(Controller, {
148
+ name: "".concat(field, ".datatype"),
149
+ children: /*#__PURE__*/jsx(Select, {
150
+ inline: true,
151
+ label: "Type",
152
+ placeholder: "Data type",
153
+ options: acceptableTypes,
154
+ onChange: function onChange(val) {
155
+ return handleTypeChange(val);
156
+ }
157
+ })
158
+ }), /*#__PURE__*/jsx(Controller, {
159
+ name: "".concat(field, ".label"),
160
+ children: /*#__PURE__*/jsx(Input, {
161
+ inline: true,
162
+ label: "Label",
163
+ allowClear: true,
164
+ placeholder: "Label...",
165
+ decorateEndShowWhenEmpty: true,
166
+ decorateEnd: /*#__PURE__*/jsx("span", {
167
+ className: "text-sm text-muted/50 px-1",
168
+ children: "OPTIONAL"
169
+ })
170
+ })
171
+ }), type === DATA_TYPES.STRING && /*#__PURE__*/jsxs(Fragment, {
172
+ children: [/*#__PURE__*/jsx(Controller, {
173
+ name: "".concat(field, ".regex"),
174
+ children: /*#__PURE__*/jsx(Input, {
175
+ inline: true,
176
+ label: "Regex validation",
177
+ allowClear: true,
178
+ placeholder: "Regex value...",
179
+ decorateEndShowWhenEmpty: true,
180
+ decorateEnd: /*#__PURE__*/jsx("span", {
181
+ className: "text-sm text-muted/50 px-1",
182
+ children: "OPTIONAL"
183
+ })
184
+ })
185
+ }), /*#__PURE__*/jsxs(Field, {
186
+ inline: true,
187
+ label: "Option list",
188
+ children: [/*#__PURE__*/jsx(Controller, {
189
+ name: "".concat(field, ".optionList"),
190
+ children: /*#__PURE__*/jsx(Select, {
191
+ allowClear: true,
192
+ options: [CUSTOM_LIST].concat(_toConsumableArray(optionLists)),
193
+ onChange: function onChange(v) {
194
+ return setCustomOptions(v === CUSTOM_LIST);
195
+ }
196
+ })
197
+ }), customOptions && /*#__PURE__*/jsx(Button, {
198
+ icon: CoreIcons.list,
199
+ "aria-label": "Custom options",
200
+ onClick: function onClick() {
201
+ void openOptionModal();
202
+ }
203
+ })]
204
+ }), OptionModal]
205
+ }), type === DATA_TYPES.FILE && /*#__PURE__*/jsx(Fragment, {
206
+ children: /*#__PURE__*/jsx(Controller, {
207
+ name: "".concat(field, ".accept"),
208
+ children: /*#__PURE__*/jsx(Input, {
209
+ inline: true,
210
+ label: "Accept types",
211
+ allowClear: true,
212
+ placeholder: "Accept value...",
213
+ decorateEndShowWhenEmpty: true,
214
+ decorateEnd: /*#__PURE__*/jsx("span", {
215
+ className: "text-sm text-muted/50 px-1",
216
+ children: "OPTIONAL"
217
+ })
218
+ })
219
+ })
220
+ }), [DATA_TYPES.NUMBER, DATA_TYPES.RANGE].includes(type) && /*#__PURE__*/jsxs(Fragment, {
221
+ children: [/*#__PURE__*/jsx(Controller, {
222
+ name: "".concat(field, ".min"),
223
+ children: /*#__PURE__*/jsx(Number, {
224
+ inline: true,
225
+ label: "Min value",
226
+ allowClear: true,
227
+ placeholder: "Minimum value...",
228
+ decorateEndShowWhenEmpty: true,
229
+ decorateEnd: /*#__PURE__*/jsx("span", {
230
+ className: "text-sm text-muted/50 px-1",
231
+ children: "OPTIONAL"
232
+ })
233
+ })
234
+ }), /*#__PURE__*/jsx(Controller, {
235
+ name: "".concat(field, ".max"),
236
+ children: /*#__PURE__*/jsx(Number, {
237
+ inline: true,
238
+ label: "Max value",
239
+ allowClear: true,
240
+ placeholder: "Maximum value...",
241
+ decorateEndShowWhenEmpty: true,
242
+ decorateEnd: /*#__PURE__*/jsx("span", {
243
+ className: "text-sm text-muted/50 px-1",
244
+ children: "OPTIONAL"
245
+ })
246
+ })
247
+ }), /*#__PURE__*/jsx(Controller, {
248
+ name: "".concat(field, ".step"),
249
+ children: /*#__PURE__*/jsx(Number, {
250
+ inline: true,
251
+ label: "Step value",
252
+ allowClear: true,
253
+ placeholder: "Step value...",
254
+ decorateEndShowWhenEmpty: true,
255
+ decorateEnd: /*#__PURE__*/jsx("span", {
256
+ className: "text-sm text-muted/50 px-1",
257
+ children: "OPTIONAL"
258
+ })
259
+ })
260
+ })]
261
+ }), type === DATA_TYPES.DATE && /*#__PURE__*/jsxs(Fragment, {
262
+ children: [/*#__PURE__*/jsx(Field, {
263
+ inline: true,
264
+ label: "Type",
265
+ plain: true,
266
+ children: /*#__PURE__*/jsx(Controller, {
267
+ name: "".concat(field, ".type"),
268
+ children: /*#__PURE__*/jsxs(ToggleButtonGroup, {
269
+ value: "",
270
+ fullWidth: true,
271
+ className: "flex-1",
272
+ children: [/*#__PURE__*/jsx(Button, {
273
+ className: "flex-1",
274
+ value: "date",
275
+ children: "Date"
276
+ }), /*#__PURE__*/jsx(Button, {
277
+ className: "flex-1",
278
+ value: "datetime",
279
+ children: "Date Time"
280
+ })]
281
+ })
282
+ })
283
+ }), /*#__PURE__*/jsx(Controller, {
284
+ name: "".concat(field, ".min"),
285
+ children: /*#__PURE__*/jsx(DateInput, {
286
+ inline: true,
287
+ label: "Min value",
288
+ allowClear: true,
289
+ placeholder: "Minimum value...",
290
+ decorateEndShowWhenEmpty: true,
291
+ decorateEnd: /*#__PURE__*/jsx("span", {
292
+ className: "text-sm text-muted/50 px-1",
293
+ children: "OPTIONAL"
294
+ })
295
+ })
296
+ }), /*#__PURE__*/jsx(Controller, {
297
+ name: "".concat(field, ".max"),
298
+ children: /*#__PURE__*/jsx(DateInput, {
299
+ inline: true,
300
+ label: "Max value",
301
+ allowClear: true,
302
+ placeholder: "Maximum value...",
303
+ decorateEndShowWhenEmpty: true,
304
+ decorateEnd: /*#__PURE__*/jsx("span", {
305
+ className: "text-sm text-muted/50 px-1",
306
+ children: "OPTIONAL"
307
+ })
308
+ })
309
+ })]
310
+ }), /*#__PURE__*/jsxs(Field, {
311
+ label: " ",
312
+ inline: true,
313
+ plain: true,
314
+ children: [/*#__PURE__*/jsx(Controller, {
315
+ name: "".concat(field, ".required"),
316
+ children: /*#__PURE__*/jsx(Checkbox, {
317
+ label: "Required"
318
+ })
319
+ }), type !== DATA_TYPES.AVATAR && /*#__PURE__*/jsx(Controller, {
320
+ name: "".concat(field, ".multiple"),
321
+ children: /*#__PURE__*/jsx(Checkbox, {
322
+ label: "Multiple",
323
+ onChange: setMultiple
324
+ })
325
+ }), hasOptions && /*#__PURE__*/jsx(Controller, {
326
+ name: "".concat(field, ".allowCustom"),
327
+ children: /*#__PURE__*/jsx(Checkbox, {
328
+ label: "Allow custom value"
329
+ })
330
+ })]
331
+ }), multiple && /*#__PURE__*/jsxs(Fragment, {
332
+ children: [/*#__PURE__*/jsx(Controller, {
333
+ name: "".concat(field, ".minItems"),
334
+ children: /*#__PURE__*/jsx(Number, {
335
+ inline: true,
336
+ label: "Min items",
337
+ allowClear: true,
338
+ placeholder: "Minimum items...",
339
+ decorateEndShowWhenEmpty: true,
340
+ decorateEnd: /*#__PURE__*/jsx("span", {
341
+ className: "text-sm text-muted/50 px-1",
342
+ children: "OPTIONAL"
343
+ })
344
+ })
345
+ }), /*#__PURE__*/jsx(Controller, {
346
+ name: "".concat(field, ".maxItems"),
347
+ children: /*#__PURE__*/jsx(Number, {
348
+ inline: true,
349
+ label: "Max items",
350
+ allowClear: true,
351
+ placeholder: "Maximum items...",
352
+ decorateEndShowWhenEmpty: true,
353
+ decorateEnd: /*#__PURE__*/jsx("span", {
354
+ className: "text-sm text-muted/50 px-1",
355
+ children: "OPTIONAL"
356
+ })
357
+ })
358
+ })]
359
+ })]
360
+ })]
361
+ }, field);
362
+ };
363
+ var SchemaEditor = function SchemaEditor(_ref2) {
364
+ var schemaDef = _ref2.schemaDef,
365
+ allowRemove = _ref2.allowRemove,
366
+ acceptableTypes = _ref2.acceptableTypes,
367
+ _ref2$optionLists = _ref2.optionLists,
368
+ optionLists = _ref2$optionLists === void 0 ? EMPTY_ARRAY : _ref2$optionLists,
369
+ children = _ref2.children,
370
+ onChange = _ref2.onChange;
371
+ var formRef = useRef(null);
372
+ var _useState9 = useState([]),
373
+ _useState10 = _slicedToArray(_useState9, 2),
374
+ schemaFields = _useState10[0],
375
+ setSchemaFields = _useState10[1];
376
+ useEffect(function () {
377
+ var _formRef$current$getV, _formRef$current, _formRef$current2;
378
+ var schemaMap = Object.fromEntries(schemaDef.map(function (schema) {
379
+ return [schema.id, schema];
380
+ }));
381
+ var currentModel = (_formRef$current$getV = (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.getValues()) !== null && _formRef$current$getV !== void 0 ? _formRef$current$getV : {};
382
+ var schema = Object.fromEntries(Object.keys(schemaMap).map(function (field) {
383
+ var _currentModel$field;
384
+ return [field, (_currentModel$field = currentModel[field]) !== null && _currentModel$field !== void 0 ? _currentModel$field : schemaMap[field]];
385
+ }));
386
+ (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues(schema);
387
+ setTimeout(function () {
388
+ setSchemaFields(Object.keys(schema));
389
+ }, 100);
390
+ }, [schemaDef]);
391
+ var handleChange = useCallback(function (model) {
392
+ onChange === null || onChange === void 0 || onChange(Object.values(model));
393
+ }, []);
394
+ var handleTypeChange = useCallback(function (field, val) {
395
+ var _formRef$current3;
396
+ (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.setValue(field, val);
397
+ }, []);
398
+ var handleRemove = useCallback(function (field) {
399
+ var _formRef$current$getV2, _formRef$current4, _formRef$current5;
400
+ var newSchema = (_formRef$current$getV2 = (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : _formRef$current4.getValues()) !== null && _formRef$current$getV2 !== void 0 ? _formRef$current$getV2 : {};
401
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
402
+ delete newSchema[field];
403
+ (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 || _formRef$current5.setValues(newSchema);
404
+ setTimeout(function () {
405
+ setSchemaFields(Object.keys(newSchema));
406
+ }, 100);
407
+ }, []);
408
+ return /*#__PURE__*/jsxs(Form, {
409
+ formRef: formRef,
410
+ onSubmit: handleChange,
411
+ children: [/*#__PURE__*/jsx(Content, {
412
+ className: "divide-y",
413
+ children: schemaFields.map(function (field) {
414
+ return /*#__PURE__*/jsx(SchemaField, {
415
+ field: field,
416
+ allowRemove: allowRemove,
417
+ optionLists: optionLists,
418
+ onRemove: function onRemove() {
419
+ return handleRemove(field);
420
+ },
421
+ getModel: function getModel() {
422
+ var _formRef$current6;
423
+ return (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.getValues()[field];
424
+ },
425
+ onTypeChange: function onTypeChange(val) {
426
+ return handleTypeChange(field, val);
427
+ },
428
+ acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(DATA_TYPES)
429
+ }, field);
430
+ })
431
+ }), children && /*#__PURE__*/jsx(Footer, {
432
+ flex: true,
433
+ className: "border-t bg-base px-6 py-2",
434
+ children: children
435
+ })]
436
+ });
437
+ };
438
+
439
+ export { SchemaEditor };
@@ -46,7 +46,7 @@ var Controller = function Controller(_ref) {
46
46
  (_children$props$onCha = (_children$props = children.props).onChange) === null || _children$props$onCha === void 0 || _children$props$onCha.call(_children$props, v);
47
47
  }
48
48
  })) : children(_objectSpread(_objectSpread(_objectSpread({}, field), rest), {}, {
49
- inputRef: function inputRef(el) {
49
+ ref: function ref(el) {
50
50
  el && _ref3(el);
51
51
  },
52
52
  readOnly: isSubmitting,
@@ -7,7 +7,8 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
7
7
  import _regeneratorRuntime from '@babel/runtime/regenerator';
8
8
  import { yupResolver } from '@hookform/resolvers/yup';
9
9
  import { useDebounce } from '@react-fabric/core';
10
- import { useRef, useEffect, useTransition, useCallback, useImperativeHandle } from 'react';
10
+ import { EMPTY_OBJECT } from '@react-fabric/utilities';
11
+ import { useRef, useTransition, useEffect, useCallback, useImperativeHandle } from 'react';
11
12
  import { useForm, FormProvider } from 'react-hook-form';
12
13
  import { jsx, jsxs } from 'react/jsx-runtime';
13
14
 
@@ -21,7 +22,8 @@ var Form = function Form(_ref) {
21
22
  var formRef = _ref.formRef,
22
23
  schema = _ref.schema,
23
24
  children = _ref.children,
24
- defaultValues = _ref.defaultValues,
25
+ _ref$defaultValues = _ref.defaultValues,
26
+ defaultValues = _ref$defaultValues === void 0 ? EMPTY_OBJECT : _ref$defaultValues,
25
27
  _ref$onSubmit = _ref.onSubmit,
26
28
  onSubmit = _ref$onSubmit === void 0 ? DEFAULT_SUBMIT : _ref$onSubmit,
27
29
  onChange = _ref.onChange,
@@ -29,12 +31,10 @@ var Form = function Form(_ref) {
29
31
  var ref = useRef(null);
30
32
  var form = useForm({
31
33
  shouldFocusError: true,
34
+ shouldUnregister: true,
32
35
  resolver: schema && yupResolver(schema),
33
36
  defaultValues: defaultValues
34
37
  });
35
- useEffect(function () {
36
- form.reset();
37
- }, []);
38
38
  var _useTransition = useTransition(),
39
39
  _useTransition2 = _slicedToArray(_useTransition, 2),
40
40
  startTransition = _useTransition2[1];
@@ -96,6 +96,12 @@ var Form = function Form(_ref) {
96
96
  return form.reset(v);
97
97
  }, 50);
98
98
  },
99
+ removeField: function removeField(field) {
100
+ return form.unregister(field, {
101
+ keepDefaultValue: false,
102
+ keepValue: false
103
+ });
104
+ },
99
105
  setValue: function setValue(k, v) {
100
106
  return setTimeout(function () {
101
107
  return form.setValue(k, v, {