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

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 (69) hide show
  1. package/dist/cjs/builder/FormField.js +3 -3
  2. package/dist/cjs/builder/SchemaEditor.js +43 -404
  3. package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
  4. package/dist/cjs/builder/components/SchemaArrayForm.js +144 -0
  5. package/dist/cjs/builder/components/SchemaField.js +411 -0
  6. package/dist/cjs/form/Form.js +11 -8
  7. package/dist/cjs/index.js +1 -0
  8. package/dist/cjs/input/ColorInput.js +1 -1
  9. package/dist/cjs/input/DateInput.js +2 -2
  10. package/dist/cjs/input/File.js +1 -1
  11. package/dist/cjs/input/Hidden.js +1 -1
  12. package/dist/cjs/input/Input.js +1 -1
  13. package/dist/cjs/input/Number.js +1 -1
  14. package/dist/cjs/input/Password.js +1 -1
  15. package/dist/cjs/input/RangeSlider.js +1 -1
  16. package/dist/cjs/input/Search.js +1 -1
  17. package/dist/cjs/input/Slider.js +1 -1
  18. package/dist/cjs/input/Textarea.js +1 -1
  19. package/dist/cjs/types/schema.js +2 -0
  20. package/dist/esm/builder/FormField.js +3 -3
  21. package/dist/esm/builder/SchemaEditor.js +45 -406
  22. package/dist/esm/builder/components/AddSchemaFields.js +62 -0
  23. package/dist/esm/builder/components/SchemaArrayForm.js +144 -0
  24. package/dist/esm/builder/components/SchemaField.js +411 -0
  25. package/dist/esm/form/Form.js +11 -8
  26. package/dist/esm/index.js +1 -1
  27. package/dist/esm/input/ColorInput.js +1 -1
  28. package/dist/esm/input/DateInput.js +2 -2
  29. package/dist/esm/input/File.js +1 -1
  30. package/dist/esm/input/Hidden.js +1 -1
  31. package/dist/esm/input/Input.js +1 -1
  32. package/dist/esm/input/Number.js +1 -1
  33. package/dist/esm/input/Password.js +1 -1
  34. package/dist/esm/input/RangeSlider.js +1 -1
  35. package/dist/esm/input/Search.js +1 -1
  36. package/dist/esm/input/Slider.js +1 -1
  37. package/dist/esm/input/Textarea.js +1 -1
  38. package/dist/esm/types/schema.js +2 -1
  39. package/dist/types/builder/SchemaEditor.d.ts +2 -10
  40. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  41. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  42. package/dist/types/builder/components/SchemaField.d.ts +10 -0
  43. package/dist/types/form/Form.d.ts +1 -5
  44. package/dist/types/index.d.ts +1 -1
  45. package/dist/types/input/ColorInput.d.ts +1 -1
  46. package/dist/types/types/index.d.ts +1 -1
  47. package/dist/types/types/schema.d.ts +26 -0
  48. package/package.json +5 -5
  49. package/src/builder/FormField.tsx +3 -3
  50. package/src/builder/SchemaEditor.tsx +24 -398
  51. package/src/builder/components/AddSchemaFields.tsx +74 -0
  52. package/src/builder/components/SchemaArrayForm.tsx +158 -0
  53. package/src/builder/components/SchemaField.tsx +432 -0
  54. package/src/form/Form.tsx +6 -9
  55. package/src/index.ts +6 -1
  56. package/src/input/ArrayInput.tsx +1 -0
  57. package/src/input/ColorInput.tsx +5 -2
  58. package/src/input/DateInput.tsx +2 -2
  59. package/src/input/File.tsx +1 -1
  60. package/src/input/Hidden.tsx +4 -3
  61. package/src/input/Input.tsx +1 -1
  62. package/src/input/Number.tsx +1 -1
  63. package/src/input/Password.tsx +1 -1
  64. package/src/input/RangeSlider.tsx +1 -1
  65. package/src/input/Search.tsx +1 -1
  66. package/src/input/Slider.tsx +1 -1
  67. package/src/input/Textarea.tsx +1 -1
  68. package/src/types/index.ts +1 -1
  69. package/src/types/schema.ts +30 -0
@@ -42,7 +42,7 @@ var Input = function Input(_ref) {
42
42
  var handleChange = react.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__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
48
48
  showClear: !!actualValue,
@@ -42,7 +42,7 @@ var Number = function Number(_ref) {
42
42
  var handleChange = react.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__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
48
48
  showClear: !!actualValue,
@@ -50,7 +50,7 @@ var Password = function Password(_ref) {
50
50
  var handleChange = react.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__*/jsxRuntime.jsxs(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
56
56
  showClear: !!actualValue,
@@ -71,7 +71,7 @@ var RangeSlider = function RangeSlider(_ref) {
71
71
  }, [showValue]);
72
72
  var handleChange = react.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 = react.useMemo(function () {
77
77
  return /*#__PURE__*/jsxRuntime.jsx("span", {
@@ -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 = react.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 = react.useMemo(function () {
79
79
  return /*#__PURE__*/jsxRuntime.jsx("span", {
@@ -47,7 +47,7 @@ var Textarea = function Textarea(_ref) {
47
47
  var handleChange = react.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
  react.useEffect(function () {
53
53
  if (variableRows) {
@@ -36,5 +36,7 @@ var DATA_TYPES = /*#__PURE__*/function (DATA_TYPES) {
36
36
  DATA_TYPES["SCHEMA"] = "schema";
37
37
  return DATA_TYPES;
38
38
  }({});
39
+ var SCHEMA_CUSTOM_LIST = "--CUSTOM--";
39
40
 
40
41
  exports.DATA_TYPES = DATA_TYPES;
42
+ exports.SCHEMA_CUSTOM_LIST = SCHEMA_CUSTOM_LIST;
@@ -106,7 +106,7 @@ var FormField = function FormField(_ref) {
106
106
  });
107
107
  return rest.multiple && !hasOptions ? /*#__PURE__*/jsx(ArrayInput, {
108
108
  name: fieldName,
109
- label: t(label, label),
109
+ label: t("fb.".concat(id), label || id),
110
110
  required: required,
111
111
  onAdd: function onAdd() {
112
112
  return String("");
@@ -118,8 +118,8 @@ var FormField = function FormField(_ref) {
118
118
  name: fieldName,
119
119
  children: /*#__PURE__*/jsx(E, _objectSpread(_objectSpread({}, props), {}, {
120
120
  autoFocus: autoFocus,
121
- label: t(label, label),
122
- placeholder: t(label, label),
121
+ label: t("fb.".concat(id), label || id),
122
+ placeholder: t("fb.".concat(id), label || id),
123
123
  required: required,
124
124
  inline: inline
125
125
  }))
@@ -1,426 +1,65 @@
1
1
  'use client';
2
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';
3
+ import { Footer } from '@react-fabric/core';
7
4
  import { EMPTY_ARRAY } from '@react-fabric/utilities';
8
- import { useRef, useState, useEffect, useCallback, Fragment } from 'react';
9
- import { Controller } from '../form/Controller.js';
5
+ import { useRef, useCallback, useEffect } from 'react';
10
6
  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
7
  import { DATA_TYPES } from '../types/schema.js';
8
+ import { SchemaArrayForm } from './components/SchemaArrayForm.js';
19
9
  import { jsxs, jsx } from 'react/jsx-runtime';
20
10
 
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,
11
+ /*
12
+ * React Fabric
13
+ * @version: 1.0.0
14
+ *
15
+ *
16
+ * The MIT License (MIT)
17
+ * Copyright (c) 2025 Adarsh Pastakia
18
+ *
19
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
20
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
21
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
22
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
23
+ * subject to the following conditions:
24
+ *
25
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
26
+ * portions of the Software.
27
+ *
28
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
29
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
+ */
33
+
34
+ var SchemaEditor = function SchemaEditor(_ref) {
35
+ var schemaDef = _ref.schemaDef,
36
+ dynamic = _ref.dynamic,
37
+ acceptableTypes = _ref.acceptableTypes,
27
38
  _ref$optionLists = _ref.optionLists,
28
39
  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;
40
+ children = _ref.children,
41
+ onChange = _ref.onChange;
361
42
  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
43
  var handleChange = useCallback(function (model) {
383
- onChange === null || onChange === void 0 || onChange(Object.values(model));
44
+ onChange === null || onChange === void 0 || onChange(model.schema);
384
45
  }, []);
385
- var handleTypeChange = useCallback(function (field, val) {
46
+ useEffect(function () {
386
47
  var _formRef$current;
387
- (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValue(field, val);
388
- }, []);
48
+ (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
49
+ schema: schemaDef
50
+ });
51
+ }, [schemaDef]);
389
52
  return /*#__PURE__*/jsxs(Form, {
390
53
  formRef: formRef,
391
- values: schema,
392
- defaultValues: schema,
393
54
  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, {
55
+ children: [/*#__PURE__*/jsx(SchemaArrayForm, {
56
+ dynamic: dynamic,
57
+ optionLists: optionLists,
58
+ acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(DATA_TYPES)
59
+ }), children && /*#__PURE__*/jsx(Footer, {
412
60
  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
- })]
61
+ className: "border-t bg-base px-6 py-2",
62
+ children: children
424
63
  })]
425
64
  });
426
65
  };
@@ -0,0 +1,62 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import { Modal, Content, Footer, Button } from '@react-fabric/core';
5
+ import { yup } from '@react-fabric/utilities';
6
+ import { useCallback } from 'react';
7
+ import { Controller } from '../../form/Controller.js';
8
+ import { Form } from '../../form/Form.js';
9
+ import { ArrayInput } from '../../input/ArrayInput.js';
10
+ import { Input } from '../../input/Input.js';
11
+ import { jsx, jsxs } from 'react/jsx-runtime';
12
+
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
+ 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
+ var fieldSchema = yup.object({
16
+ fields: yup.array(yup.string().trim().required()).required().min(1)
17
+ });
18
+ var AddSchemaFields = function AddSchemaFields(props) {
19
+ var handleSubmit = useCallback(function (model) {
20
+ props.onClose(model.fields.map(function (f) {
21
+ return f.split(",").map(function (ff) {
22
+ return ff.trim();
23
+ });
24
+ }).flat(2));
25
+ }, []);
26
+ return /*#__PURE__*/jsx(Modal, _objectSpread(_objectSpread({}, props), {}, {
27
+ children: /*#__PURE__*/jsxs(Form, {
28
+ schema: fieldSchema,
29
+ defaultValues: {
30
+ fields: [" "]
31
+ },
32
+ onSubmit: handleSubmit,
33
+ children: [/*#__PURE__*/jsxs(Content, {
34
+ children: [/*#__PURE__*/jsx(ArrayInput, {
35
+ minItems: 1,
36
+ name: "fields",
37
+ onAdd: function onAdd() {
38
+ return String("");
39
+ },
40
+ children: /*#__PURE__*/jsx(Controller, {
41
+ children: /*#__PURE__*/jsx(Input, {
42
+ autoFocus: true
43
+ })
44
+ })
45
+ }), /*#__PURE__*/jsx("p", {
46
+ className: "text-sm text-muted",
47
+ children: "Provide list of fields or comma-separated value"
48
+ })]
49
+ }), /*#__PURE__*/jsx(Footer, {
50
+ flex: true,
51
+ justify: "end",
52
+ className: "px-2 py-1",
53
+ children: /*#__PURE__*/jsx(Button, {
54
+ type: "submit",
55
+ children: "Add"
56
+ })
57
+ })]
58
+ })
59
+ }));
60
+ };
61
+
62
+ export { AddSchemaFields };