@react-fabric/form 1.0.0-beta.31 → 1.0.0-beta.33

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