@react-fabric/form 1.0.0-beta.6 → 1.0.0-beta.60
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.
- package/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
- package/css/_colorPicker.css +65 -0
- package/{src/internal/Field.module.css → css/_field.css} +66 -30
- package/{src/input/File.module.css → css/_file.css} +21 -6
- package/css/styles.css +27 -0
- package/dist/cjs/builder/FileField.js +40 -28
- package/dist/cjs/builder/FormField.js +50 -34
- package/dist/cjs/builder/SchemaEditor.js +72 -0
- package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +145 -0
- package/dist/cjs/builder/components/SchemaField.js +414 -0
- package/dist/cjs/form/Controller.js +46 -1
- package/dist/cjs/form/Form.js +70 -9
- package/dist/cjs/hooks/useFileUploader.js +16 -0
- package/dist/cjs/hooks/useFormBuilder.js +57 -15
- package/dist/cjs/i18n/ar.json.js +5 -4
- package/dist/cjs/i18n/en.json.js +5 -5
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/input/ArrayInput.js +126 -36
- package/dist/cjs/input/AvatarInput.js +43 -23
- package/dist/cjs/input/Checkbox.js +16 -6
- package/dist/cjs/input/ColorInput.js +113 -58
- package/dist/cjs/input/ColorPicker.js +60 -76
- package/dist/cjs/input/DateInput.js +197 -0
- package/dist/cjs/input/Field.js +10 -4
- package/dist/cjs/input/File.js +14 -7
- package/dist/cjs/input/Hidden.js +13 -2
- package/dist/cjs/input/Input.js +24 -10
- package/dist/cjs/input/Number.js +22 -10
- package/dist/cjs/input/Password.js +22 -12
- package/dist/cjs/input/Radio.js +12 -3
- package/dist/cjs/input/RadioGroup.js +10 -1
- package/dist/cjs/input/{Range.js → RangeSlider.js} +16 -8
- package/dist/cjs/input/Search.js +30 -19
- package/dist/cjs/input/Slider.js +12 -6
- package/dist/cjs/input/Switch.js +20 -9
- package/dist/cjs/input/Textarea.js +29 -8
- package/dist/cjs/internal/ErrorIcon.js +1 -1
- package/dist/cjs/internal/FieldWrapper.js +11 -4
- package/dist/cjs/internal/InputWrapper.js +27 -20
- package/dist/cjs/select/AutoComplete.js +21 -11
- package/dist/cjs/select/DualList.js +34 -12
- package/dist/cjs/select/List.js +68 -22
- package/dist/cjs/select/Options.js +49 -42
- package/dist/cjs/select/Select.js +40 -10
- package/dist/cjs/select/useSelect.js +22 -11
- package/dist/cjs/types/schema.js +43 -0
- package/dist/cjs/utils/eventHandlers.js +15 -5
- package/dist/esm/builder/FileField.js +42 -30
- package/dist/esm/builder/FormField.js +50 -34
- package/dist/esm/builder/SchemaEditor.js +72 -0
- package/dist/esm/builder/components/AddSchemaFields.js +62 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +145 -0
- package/dist/esm/builder/components/SchemaField.js +414 -0
- package/dist/esm/form/Controller.js +46 -1
- package/dist/esm/form/Form.js +72 -12
- package/dist/esm/hooks/useFileUploader.js +16 -0
- package/dist/esm/hooks/useFormBuilder.js +55 -13
- package/dist/esm/i18n/ar.json.js +5 -4
- package/dist/esm/i18n/en.json.js +5 -5
- package/dist/esm/index.js +6 -2
- package/dist/esm/input/ArrayInput.js +126 -36
- package/dist/esm/input/AvatarInput.js +44 -24
- package/dist/esm/input/Checkbox.js +16 -6
- package/dist/esm/input/ColorInput.js +115 -60
- package/dist/esm/input/ColorPicker.js +60 -76
- package/dist/esm/input/DateInput.js +197 -0
- package/dist/esm/input/Field.js +11 -5
- package/dist/esm/input/File.js +16 -9
- package/dist/esm/input/Hidden.js +13 -2
- package/dist/esm/input/Input.js +26 -12
- package/dist/esm/input/Number.js +24 -12
- package/dist/esm/input/Password.js +24 -14
- package/dist/esm/input/Radio.js +12 -3
- package/dist/esm/input/RadioGroup.js +11 -2
- package/dist/esm/input/{Range.js → RangeSlider.js} +16 -8
- package/dist/esm/input/Search.js +32 -21
- package/dist/esm/input/Slider.js +12 -6
- package/dist/esm/input/Switch.js +20 -9
- package/dist/esm/input/Textarea.js +30 -9
- package/dist/esm/internal/ErrorIcon.js +1 -1
- package/dist/esm/internal/FieldWrapper.js +11 -4
- package/dist/esm/internal/InputWrapper.js +27 -20
- package/dist/esm/select/AutoComplete.js +21 -11
- package/dist/esm/select/DualList.js +34 -12
- package/dist/esm/select/List.js +69 -23
- package/dist/esm/select/Options.js +49 -42
- package/dist/esm/select/Select.js +40 -10
- package/dist/esm/select/useSelect.js +23 -12
- package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
- package/dist/esm/utils/eventHandlers.js +15 -5
- package/dist/types/builder/FileField.d.ts +4 -2
- package/dist/types/builder/FormField.d.ts +3 -1
- package/dist/types/builder/SchemaEditor.d.ts +9 -0
- package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
- package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
- package/dist/types/builder/components/SchemaField.d.ts +10 -0
- package/dist/types/form/Controller.d.ts +47 -2
- package/dist/types/form/Form.d.ts +48 -2
- package/dist/types/hooks/useFileUploader.d.ts +16 -0
- package/dist/types/hooks/useFormBuilder.d.ts +32 -1
- package/dist/types/index.d.ts +6 -3
- package/dist/types/input/ArrayInput.d.ts +69 -12
- package/dist/types/input/AvatarInput.d.ts +23 -3
- package/dist/types/input/Checkbox.d.ts +13 -4
- package/dist/types/input/ColorInput.d.ts +15 -2
- package/dist/types/input/ColorPicker.d.ts +11 -1
- package/dist/types/input/DateInput.d.ts +28 -0
- package/dist/types/input/Field.d.ts +5 -1
- package/dist/types/input/File.d.ts +9 -0
- package/dist/types/input/Hidden.d.ts +13 -1
- package/dist/types/input/Input.d.ts +9 -1
- package/dist/types/input/Number.d.ts +9 -1
- package/dist/types/input/Password.d.ts +7 -1
- package/dist/types/input/Radio.d.ts +9 -1
- package/dist/types/input/RadioGroup.d.ts +8 -1
- package/dist/types/input/RangeSlider.d.ts +67 -0
- package/dist/types/input/Search.d.ts +14 -1
- package/dist/types/input/Slider.d.ts +8 -2
- package/dist/types/input/Switch.d.ts +10 -2
- package/dist/types/input/Textarea.d.ts +15 -1
- package/dist/types/internal/FieldWrapper.d.ts +1 -1
- package/dist/types/internal/InputWrapper.d.ts +1 -1
- package/dist/types/ranger/index.d.ts +2 -2
- package/dist/types/select/AutoComplete.d.ts +8 -1
- package/dist/types/select/DualList.d.ts +17 -2
- package/dist/types/select/List.d.ts +9 -1
- package/dist/types/select/Options.d.ts +4 -3
- package/dist/types/select/Select.d.ts +9 -1
- package/dist/types/select/useSelect.d.ts +10 -6
- package/dist/types/types/index.d.ts +34 -5
- package/dist/types/types/schema.d.ts +78 -33
- package/dist/types/utils/eventHandlers.d.ts +2 -2
- package/package.json +22 -20
- package/src/builder/FileField.tsx +62 -30
- package/src/builder/FormField.tsx +52 -32
- package/src/builder/SchemaEditor.tsx +79 -0
- package/src/builder/components/AddSchemaFields.tsx +74 -0
- package/src/builder/components/SchemaArrayForm.tsx +161 -0
- package/src/builder/components/SchemaField.tsx +436 -0
- package/src/form/Controller.tsx +48 -3
- package/src/form/Form.tsx +80 -8
- package/src/hooks/useFileUploader.ts +16 -0
- package/src/hooks/useFormBuilder.tsx +58 -15
- package/src/i18n/ar.json +5 -4
- package/src/i18n/en.json +5 -5
- package/src/index.ts +12 -3
- package/src/input/ArrayInput.tsx +199 -64
- package/src/input/AvatarInput.tsx +67 -19
- package/src/input/Checkbox.tsx +16 -6
- package/src/input/ColorInput.tsx +131 -71
- package/src/input/ColorPicker.tsx +54 -72
- package/src/input/DateInput.tsx +260 -0
- package/src/input/Field.tsx +15 -11
- package/src/input/File.tsx +16 -14
- package/src/input/Hidden.tsx +17 -2
- package/src/input/Input.tsx +27 -13
- package/src/input/Number.tsx +22 -13
- package/src/input/Password.tsx +24 -16
- package/src/input/Radio.tsx +12 -3
- package/src/input/RadioGroup.tsx +12 -3
- package/src/input/{Range.tsx → RangeSlider.tsx} +17 -9
- package/src/input/Search.tsx +33 -22
- package/src/input/Slider.tsx +20 -11
- package/src/input/Switch.tsx +17 -6
- package/src/input/Textarea.tsx +34 -9
- package/src/internal/ErrorIcon.tsx +1 -1
- package/src/internal/FieldWrapper.tsx +8 -4
- package/src/internal/InputWrapper.tsx +49 -27
- package/src/select/AutoComplete.tsx +14 -3
- package/src/select/DualList.tsx +31 -16
- package/src/select/List.tsx +52 -8
- package/src/select/Options.tsx +50 -46
- package/src/select/Select.tsx +25 -5
- package/src/select/useSelect.tsx +26 -9
- package/src/types/index.ts +37 -6
- package/src/types/schema.ts +96 -41
- package/src/utils/eventHandlers.ts +14 -4
- package/dist/cjs/input/ArrayInput.module.css +0 -1
- package/dist/cjs/input/ColorPicker.module.css +0 -1
- package/dist/cjs/input/File.module.css +0 -1
- package/dist/cjs/internal/Field.module.css +0 -1
- package/dist/esm/input/ArrayInput.module.css +0 -1
- package/dist/esm/input/ColorPicker.module.css +0 -1
- package/dist/esm/input/File.module.css +0 -1
- package/dist/esm/internal/Field.module.css +0 -1
- package/dist/types/input/Range.d.ts +0 -59
|
@@ -15,6 +15,10 @@ var useSelect = function useSelect(_ref) {
|
|
|
15
15
|
options = _ref$options === void 0 ? utilities.EMPTY_ARRAY : _ref$options,
|
|
16
16
|
value = _ref.value,
|
|
17
17
|
autoComplete = _ref.autoComplete,
|
|
18
|
+
_ref$alwaysOpen = _ref.alwaysOpen,
|
|
19
|
+
alwaysOpen = _ref$alwaysOpen === void 0 ? false : _ref$alwaysOpen,
|
|
20
|
+
_ref$defaultOpen = _ref.defaultOpen,
|
|
21
|
+
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
18
22
|
_ref$multiple = _ref.multiple,
|
|
19
23
|
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
|
20
24
|
_ref$allowCreate = _ref.allowCreate,
|
|
@@ -25,6 +29,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
25
29
|
valueProperty = _ref$valueProperty === void 0 ? "id" : _ref$valueProperty,
|
|
26
30
|
_ref$labelProperty = _ref.labelProperty,
|
|
27
31
|
labelProperty = _ref$labelProperty === void 0 ? "label" : _ref$labelProperty,
|
|
32
|
+
sortProperty = _ref.sortProperty,
|
|
28
33
|
_ref$createOption = _ref.createOption,
|
|
29
34
|
createOption = _ref$createOption === void 0 ? helpers.makeOption : _ref$createOption,
|
|
30
35
|
matcher = _ref.matcher,
|
|
@@ -63,13 +68,16 @@ var useSelect = function useSelect(_ref) {
|
|
|
63
68
|
if (action.type === "close") {
|
|
64
69
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
65
70
|
activeIndex: null,
|
|
71
|
+
activeItem: null,
|
|
66
72
|
open: false
|
|
67
73
|
});
|
|
68
74
|
}
|
|
69
75
|
if (action.type === "active" && state.open) {
|
|
76
|
+
var _action$index;
|
|
70
77
|
if (autoComplete && action.index !== null) state.query = state.items[action.index];
|
|
71
78
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
72
|
-
activeIndex: action.index
|
|
79
|
+
activeIndex: action.index,
|
|
80
|
+
activeItem: state.items[(_action$index = action.index) !== null && _action$index !== void 0 ? _action$index : -1]
|
|
73
81
|
});
|
|
74
82
|
}
|
|
75
83
|
if (action.type === "setValue") {
|
|
@@ -83,6 +91,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
83
91
|
var newState = _objectSpread(_objectSpread({}, state), {}, {
|
|
84
92
|
value: state.emptyValue,
|
|
85
93
|
activeIndex: null,
|
|
94
|
+
activeItem: null,
|
|
86
95
|
selectedIndex: autoComplete ? state.multiple ? (_action$value = action.value) === null || _action$value === void 0 ? void 0 : _action$value.length : 0 : state.items.indexOf(action.value)
|
|
87
96
|
});
|
|
88
97
|
if (action.value !== undefined) {
|
|
@@ -100,16 +109,16 @@ var useSelect = function useSelect(_ref) {
|
|
|
100
109
|
newState.value = action.value;
|
|
101
110
|
}
|
|
102
111
|
}
|
|
103
|
-
if (!state.multiple) newState.open =
|
|
112
|
+
if (!state.multiple) newState.open = alwaysOpen;
|
|
104
113
|
fireChange(newState.value);
|
|
105
114
|
return newState;
|
|
106
115
|
}
|
|
107
116
|
if (action.type === "removeItem") {
|
|
108
117
|
var newValue = state.value;
|
|
109
118
|
if (state.multiple) {
|
|
110
|
-
var _action$
|
|
119
|
+
var _action$index2;
|
|
111
120
|
newValue = _toConsumableArray(newValue);
|
|
112
|
-
newValue.splice((_action$
|
|
121
|
+
newValue.splice((_action$index2 = action.index) !== null && _action$index2 !== void 0 ? _action$index2 : -1, 1);
|
|
113
122
|
} else {
|
|
114
123
|
newValue = "";
|
|
115
124
|
}
|
|
@@ -133,13 +142,14 @@ var useSelect = function useSelect(_ref) {
|
|
|
133
142
|
if (autoComplete && action.query !== undefined) {
|
|
134
143
|
optionList = utilities.dedupe([action.query].concat(_toConsumableArray(optionList)));
|
|
135
144
|
}
|
|
145
|
+
if (sortProperty) optionList = optionList.sort(utilities.compareValues("asc", sortProperty));
|
|
136
146
|
var grouped = utilities.groupBy(optionList, groupProperty, "");
|
|
137
147
|
if (action.open) _newState.open = true;
|
|
138
148
|
_newState.items = [];
|
|
139
149
|
// add new item if allowCreate
|
|
140
150
|
if (allowCreate && action.query) _newState.items.push({
|
|
141
151
|
___create___: true,
|
|
142
|
-
value:
|
|
152
|
+
value: action.query
|
|
143
153
|
});
|
|
144
154
|
Object.entries(grouped).forEach(function (_ref2) {
|
|
145
155
|
var _newState$items;
|
|
@@ -169,9 +179,10 @@ var useSelect = function useSelect(_ref) {
|
|
|
169
179
|
}, {
|
|
170
180
|
multiple: multiple,
|
|
171
181
|
emptyValue: emptyValue,
|
|
172
|
-
open:
|
|
182
|
+
open: alwaysOpen || defaultOpen,
|
|
173
183
|
loading: false,
|
|
174
184
|
activeIndex: null,
|
|
185
|
+
activeItem: null,
|
|
175
186
|
selectedIndex: null,
|
|
176
187
|
value: emptyValue,
|
|
177
188
|
// filter
|
|
@@ -201,7 +212,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
201
212
|
});
|
|
202
213
|
dispatch({
|
|
203
214
|
type: "setValue",
|
|
204
|
-
value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 :
|
|
215
|
+
value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : deferred
|
|
205
216
|
});
|
|
206
217
|
}
|
|
207
218
|
if (multiple) {
|
|
@@ -211,12 +222,12 @@ var useSelect = function useSelect(_ref) {
|
|
|
211
222
|
var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
|
|
212
223
|
var hasValue = options.find(function (opt) {
|
|
213
224
|
var _opt$valueProperty2;
|
|
214
|
-
return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) ===
|
|
225
|
+
return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
|
|
215
226
|
});
|
|
216
227
|
if (!hasValue && newOption) {
|
|
217
228
|
optionsRef.current.push(newOption);
|
|
218
229
|
}
|
|
219
|
-
return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 :
|
|
230
|
+
return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : item;
|
|
220
231
|
});
|
|
221
232
|
optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
|
|
222
233
|
dispatch({
|
|
@@ -246,7 +257,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
246
257
|
setActive: true
|
|
247
258
|
});
|
|
248
259
|
});
|
|
249
|
-
}, [onQuery]);
|
|
260
|
+
}, [onQuery], 300);
|
|
250
261
|
|
|
251
262
|
// handlers
|
|
252
263
|
var handleQuery = react.useCallback(function (query) {
|
|
@@ -316,7 +327,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
316
327
|
});
|
|
317
328
|
}, []);
|
|
318
329
|
var setActiveIndex = react.useCallback(function (index) {
|
|
319
|
-
dispatch({
|
|
330
|
+
index && index > -1 && dispatch({
|
|
320
331
|
type: "active",
|
|
321
332
|
index: index
|
|
322
333
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
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["DATETIME"] = "datetime";
|
|
32
|
+
DATA_TYPES["STRING"] = "string";
|
|
33
|
+
DATA_TYPES["NUMBER"] = "number";
|
|
34
|
+
DATA_TYPES["RANGE"] = "range";
|
|
35
|
+
DATA_TYPES["FILE"] = "file";
|
|
36
|
+
DATA_TYPES["AVATAR"] = "avatar";
|
|
37
|
+
DATA_TYPES["SCHEMA"] = "schema";
|
|
38
|
+
return DATA_TYPES;
|
|
39
|
+
}({});
|
|
40
|
+
var SCHEMA_CUSTOM_LIST = "--CUSTOM--";
|
|
41
|
+
|
|
42
|
+
exports.DATA_TYPES = DATA_TYPES;
|
|
43
|
+
exports.SCHEMA_CUSTOM_LIST = SCHEMA_CUSTOM_LIST;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var react = require('@floating-ui/react');
|
|
4
|
+
var core = require('@react-fabric/core');
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* React Fabric
|
|
@@ -26,16 +27,25 @@ var utilities = require('@react-fabric/utilities');
|
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
29
|
/** ***************** common handler for enter press *******************/
|
|
29
|
-
var
|
|
30
|
+
var useHandleEnter = function useHandleEnter(callback) {
|
|
30
31
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
31
32
|
_ref$stopPropagation = _ref.stopPropagation,
|
|
32
33
|
stopPropagation = _ref$stopPropagation === void 0 ? false : _ref$stopPropagation,
|
|
33
34
|
_ref$preventDefault = _ref.preventDefault,
|
|
34
35
|
preventDefault = _ref$preventDefault === void 0 ? false : _ref$preventDefault;
|
|
35
|
-
var cbHandle =
|
|
36
|
+
var cbHandle = core.useDebounce(callback !== null && callback !== void 0 ? callback : function () {
|
|
36
37
|
return undefined;
|
|
37
|
-
}, 100);
|
|
38
|
+
}, [callback], 100);
|
|
39
|
+
var tree = react.useFloatingTree();
|
|
38
40
|
return function (e) {
|
|
41
|
+
// prevent propagation of event if input within dropdown (work around for floating-ui typeahead)
|
|
42
|
+
if (tree && e.key !== "Escape") {
|
|
43
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
44
|
+
}
|
|
45
|
+
// blur input on escape key press
|
|
46
|
+
if (e.key === "Escape") {
|
|
47
|
+
e.currentTarget.blur();
|
|
48
|
+
}
|
|
39
49
|
if (!e.shiftKey && !e.altKey && !e.metaKey && e.key === "Enter" && callback) {
|
|
40
50
|
if (stopPropagation) e === null || e === void 0 || e.stopPropagation();
|
|
41
51
|
cbHandle(e);
|
|
@@ -47,4 +57,4 @@ var handleEnter = function handleEnter(callback) {
|
|
|
47
57
|
};
|
|
48
58
|
};
|
|
49
59
|
|
|
50
|
-
exports.
|
|
60
|
+
exports.useHandleEnter = useHandleEnter;
|
|
@@ -4,26 +4,32 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
4
4
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
6
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
7
|
-
import { Button, Icon, ProgressBar } from '@react-fabric/core';
|
|
8
|
-
import { FileUtil, Format } from '@react-fabric/utilities';
|
|
7
|
+
import { Tooltip, Button, Icon, CoreIcons, ProgressBar } from '@react-fabric/core';
|
|
8
|
+
import { isString, FileUtil, Format } from '@react-fabric/utilities';
|
|
9
9
|
import { Fragment } from 'react';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
10
11
|
import { useFileUploader } from '../hooks/useFileUploader.js';
|
|
11
12
|
import { Field } from '../input/Field.js';
|
|
12
13
|
import { HiddenInput } from '../input/Hidden.js';
|
|
13
14
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
15
|
|
|
15
|
-
var _excluded = ["uploadHandler", "inline", "label", "accept", "multiple", "
|
|
16
|
+
var _excluded = ["uploadHandler", "inline", "label", "accept", "value", "fileUrl", "multiple", "invalid", "error"];
|
|
16
17
|
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
18
|
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
19
|
var FileField = function FileField(_ref) {
|
|
20
|
+
var _error$values$label, _error$values, _error$values2;
|
|
19
21
|
var uploadHandler = _ref.uploadHandler,
|
|
20
22
|
inline = _ref.inline,
|
|
21
23
|
label = _ref.label,
|
|
22
24
|
accept = _ref.accept,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
value = _ref.value;
|
|
26
|
+
_ref.fileUrl;
|
|
27
|
+
var multiple = _ref.multiple;
|
|
28
|
+
_ref.invalid;
|
|
29
|
+
var error = _ref.error,
|
|
26
30
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
+
var _useTranslation = useTranslation(),
|
|
32
|
+
t = _useTranslation.t;
|
|
27
33
|
var _useFileUploader = useFileUploader( /*#__PURE__*/function () {
|
|
28
34
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
|
|
29
35
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -49,32 +55,38 @@ var FileField = function FileField(_ref) {
|
|
|
49
55
|
upload = _useFileUploader.upload,
|
|
50
56
|
remove = _useFileUploader.remove;
|
|
51
57
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
52
|
-
children: [/*#__PURE__*/
|
|
58
|
+
children: [/*#__PURE__*/jsx(Field, {
|
|
53
59
|
plain: true,
|
|
54
60
|
inline: inline,
|
|
55
61
|
label: label,
|
|
56
|
-
|
|
57
|
-
children: [/*#__PURE__*/jsx(HiddenInput, _objectSpread({
|
|
62
|
+
children: /*#__PURE__*/jsx(HiddenInput, _objectSpread({
|
|
58
63
|
hiddenValue: multiple ? list : list === null || list === void 0 ? void 0 : list[0]
|
|
59
|
-
}, rest))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
}, rest))
|
|
65
|
+
}), /*#__PURE__*/jsx(Tooltip, {
|
|
66
|
+
color: "danger-200",
|
|
67
|
+
content: isString(error) ? "".concat(error) : error && t(error === null || error === void 0 ? void 0 : error.key, error.values ? _objectSpread(_objectSpread({}, error === null || error === void 0 ? void 0 : error.values), {}, {
|
|
68
|
+
label: t((_error$values$label = (_error$values = error.values) === null || _error$values === void 0 ? void 0 : _error$values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", (_error$values2 = error.values) === null || _error$values2 === void 0 ? void 0 : _error$values2.path)
|
|
69
|
+
}) : {}),
|
|
70
|
+
disabled: !error,
|
|
71
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
72
|
+
badge: pending > 0 ? "".concat(pending) : undefined,
|
|
73
|
+
color: error ? "danger" : undefined,
|
|
74
|
+
variant: error ? "soft" : undefined,
|
|
75
|
+
"data-ref": "filebtn",
|
|
76
|
+
children: /*#__PURE__*/jsxs(Fragment, {
|
|
77
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
78
|
+
children: "Add file"
|
|
79
|
+
}), /*#__PURE__*/jsx("input", {
|
|
80
|
+
type: "file",
|
|
81
|
+
accept: accept,
|
|
82
|
+
multiple: multiple,
|
|
83
|
+
className: "absolute inset-0 opacity-0 z-5",
|
|
84
|
+
onChange: function onChange(e) {
|
|
85
|
+
return [upload(e.target.files), e.target.value = ""];
|
|
86
|
+
}
|
|
87
|
+
})]
|
|
76
88
|
})
|
|
77
|
-
})
|
|
89
|
+
})
|
|
78
90
|
}), /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx("div", {
|
|
79
91
|
className: "bg-alternate",
|
|
80
92
|
children: files.map(function (file, idx) {
|
|
@@ -98,18 +110,18 @@ var FileField = function FileField(_ref) {
|
|
|
98
110
|
children: file.error
|
|
99
111
|
})
|
|
100
112
|
}), file.progress && /*#__PURE__*/jsx(Icon, {
|
|
101
|
-
icon:
|
|
113
|
+
icon: CoreIcons.stop,
|
|
102
114
|
bg: "danger",
|
|
103
115
|
color: "white",
|
|
104
116
|
size: "sm",
|
|
105
|
-
className: "p-
|
|
117
|
+
className: "p-0.5",
|
|
106
118
|
"aria-label": "abort",
|
|
107
119
|
onClick: function onClick() {
|
|
108
120
|
var _file$abort;
|
|
109
121
|
return (_file$abort = file.abort) === null || _file$abort === void 0 ? void 0 : _file$abort.call(file);
|
|
110
122
|
}
|
|
111
123
|
}), !file.progress && /*#__PURE__*/jsx(Icon, {
|
|
112
|
-
icon:
|
|
124
|
+
icon: CoreIcons.trash,
|
|
113
125
|
color: "danger",
|
|
114
126
|
size: "sm",
|
|
115
127
|
"aria-label": "remove",
|
|
@@ -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 {
|
|
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", "
|
|
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.
|
|
31
|
-
|
|
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,61 @@ 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 ===
|
|
41
|
-
if (rest.datatype ===
|
|
42
|
-
if (rest.datatype ===
|
|
43
|
-
if (rest.datatype ===
|
|
44
|
-
if (rest.datatype ===
|
|
45
|
-
if (rest.datatype ===
|
|
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.DATETIME) return DateInput;
|
|
53
|
+
if (rest.datatype === DATA_TYPES.COLOR) return ColorInput;
|
|
54
|
+
if (hasOptions) return Select;
|
|
46
55
|
return Input;
|
|
47
|
-
}, [rest.datatype]);
|
|
56
|
+
}, [rest.datatype, hasOptions]);
|
|
48
57
|
var props = useMemo(function () {
|
|
49
|
-
var _rest$step, _rest$
|
|
50
|
-
if (rest.datatype ===
|
|
58
|
+
var _rest$step, _rest$min, _rest$max, _rest$step2, _optionLists, _rest$optionList2;
|
|
59
|
+
if (rest.datatype === DATA_TYPES.NUMBER) return {
|
|
51
60
|
min: rest.min,
|
|
52
61
|
max: rest.max,
|
|
53
62
|
step: (_rest$step = rest.step) !== null && _rest$step !== void 0 ? _rest$step : 1
|
|
54
63
|
};
|
|
55
|
-
if (rest.datatype ===
|
|
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 {
|
|
64
|
+
if (rest.datatype === DATA_TYPES.RANGE) return {
|
|
61
65
|
min: (_rest$min = rest.min) !== null && _rest$min !== void 0 ? _rest$min : 1,
|
|
62
66
|
max: (_rest$max = rest.max) !== null && _rest$max !== void 0 ? _rest$max : 99,
|
|
63
|
-
step: (_rest$
|
|
67
|
+
step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 1,
|
|
64
68
|
showValue: true,
|
|
65
69
|
showLabels: true
|
|
66
70
|
};
|
|
67
|
-
if (rest.datatype ===
|
|
71
|
+
if (rest.datatype === DATA_TYPES.DATE) return {
|
|
72
|
+
min: rest.min,
|
|
73
|
+
max: rest.max,
|
|
74
|
+
type: "date"
|
|
75
|
+
};
|
|
76
|
+
if (rest.datatype === DATA_TYPES.DATETIME) return {
|
|
77
|
+
min: rest.min,
|
|
78
|
+
max: rest.max,
|
|
79
|
+
type: "datetime"
|
|
80
|
+
};
|
|
81
|
+
if (rest.datatype === DATA_TYPES.TEXT) return {
|
|
68
82
|
rows: 3
|
|
69
83
|
};
|
|
70
|
-
if (rest.datatype ===
|
|
84
|
+
if (rest.datatype === DATA_TYPES.COLOR) return {
|
|
71
85
|
showPicker: true
|
|
72
86
|
};
|
|
73
|
-
if (rest.datatype ===
|
|
74
|
-
options: rest.options,
|
|
87
|
+
if (rest.datatype === DATA_TYPES.STRING && hasOptions) return _objectSpread({
|
|
75
88
|
multiple: rest.multiple,
|
|
89
|
+
allowCreate: rest.allowCustom,
|
|
76
90
|
searchable: true
|
|
77
|
-
}
|
|
91
|
+
}, (_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 : {
|
|
92
|
+
options: rest.options
|
|
93
|
+
});
|
|
78
94
|
return {};
|
|
79
|
-
}, [rest]);
|
|
80
|
-
if (rest.datatype ===
|
|
95
|
+
}, [rest, hasOptions, optionLists]);
|
|
96
|
+
if (rest.datatype === DATA_TYPES.AVATAR) return uploadHandler && /*#__PURE__*/jsx(Controller, {
|
|
81
97
|
name: fieldName,
|
|
82
98
|
children: /*#__PURE__*/jsx(AvatarInput, {
|
|
83
99
|
uploadHandler: uploadHandler,
|
|
@@ -85,7 +101,7 @@ var FormField = function FormField(_ref) {
|
|
|
85
101
|
name: fieldName
|
|
86
102
|
})
|
|
87
103
|
});
|
|
88
|
-
if (rest.datatype ===
|
|
104
|
+
if (rest.datatype === DATA_TYPES.FILE) return uploadHandler && /*#__PURE__*/jsx(Controller, {
|
|
89
105
|
name: fieldName,
|
|
90
106
|
children: /*#__PURE__*/jsx(FileField, _objectSpread({
|
|
91
107
|
uploadHandler: uploadHandler,
|
|
@@ -94,12 +110,12 @@ var FormField = function FormField(_ref) {
|
|
|
94
110
|
id: id
|
|
95
111
|
}, rest))
|
|
96
112
|
});
|
|
97
|
-
return rest.multiple && !
|
|
113
|
+
return rest.multiple && !hasOptions ? /*#__PURE__*/jsx(ArrayInput, {
|
|
98
114
|
name: fieldName,
|
|
99
|
-
label: t(
|
|
115
|
+
label: t("fb.".concat(id), label || id),
|
|
100
116
|
required: required,
|
|
101
117
|
onAdd: function onAdd() {
|
|
102
|
-
return "";
|
|
118
|
+
return String("");
|
|
103
119
|
},
|
|
104
120
|
children: /*#__PURE__*/jsx(Controller, {
|
|
105
121
|
children: /*#__PURE__*/jsx(E, _objectSpread({}, props))
|
|
@@ -108,8 +124,8 @@ var FormField = function FormField(_ref) {
|
|
|
108
124
|
name: fieldName,
|
|
109
125
|
children: /*#__PURE__*/jsx(E, _objectSpread(_objectSpread({}, props), {}, {
|
|
110
126
|
autoFocus: autoFocus,
|
|
111
|
-
label: t(
|
|
112
|
-
placeholder: t(
|
|
127
|
+
label: t("fb.".concat(id), label || id),
|
|
128
|
+
placeholder: t("fb.".concat(id), label || id),
|
|
113
129
|
required: required,
|
|
114
130
|
inline: inline
|
|
115
131
|
}))
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Footer } from '@react-fabric/core';
|
|
4
|
+
import { EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
5
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
6
|
+
import { Form } from '../form/Form.js';
|
|
7
|
+
import { DATA_TYPES } from '../types/schema.js';
|
|
8
|
+
import { SchemaArrayForm } from './components/SchemaArrayForm.js';
|
|
9
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
10
|
+
|
|
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,
|
|
38
|
+
_ref$optionLists = _ref.optionLists,
|
|
39
|
+
optionLists = _ref$optionLists === void 0 ? EMPTY_ARRAY : _ref$optionLists,
|
|
40
|
+
children = _ref.children,
|
|
41
|
+
onSubmit = _ref.onSubmit,
|
|
42
|
+
onChange = _ref.onChange;
|
|
43
|
+
var formRef = useRef(null);
|
|
44
|
+
var handleChange = useCallback(function (model) {
|
|
45
|
+
onChange === null || onChange === void 0 || onChange(model.schema);
|
|
46
|
+
}, []);
|
|
47
|
+
var handleSubmit = useCallback(function (model) {
|
|
48
|
+
onSubmit === null || onSubmit === void 0 || onSubmit(model.schema);
|
|
49
|
+
}, []);
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
var _formRef$current;
|
|
52
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
|
|
53
|
+
schema: schemaDef
|
|
54
|
+
});
|
|
55
|
+
}, [schemaDef]);
|
|
56
|
+
return /*#__PURE__*/jsxs(Form, {
|
|
57
|
+
formRef: formRef,
|
|
58
|
+
onChange: handleChange,
|
|
59
|
+
onSubmit: handleSubmit,
|
|
60
|
+
children: [/*#__PURE__*/jsx(SchemaArrayForm, {
|
|
61
|
+
dynamic: dynamic,
|
|
62
|
+
optionLists: optionLists,
|
|
63
|
+
acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(DATA_TYPES)
|
|
64
|
+
}), children && /*#__PURE__*/jsx(Footer, {
|
|
65
|
+
flex: true,
|
|
66
|
+
className: "border-t bg-base px-6 py-2",
|
|
67
|
+
children: children
|
|
68
|
+
})]
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { SchemaEditor };
|
|
@@ -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 };
|