@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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
3
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
|
+
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
5
7
|
import { useFloating, autoUpdate, shift, flip, offset, useClick, useDismiss, useListNavigation, useTypeahead, useInteractions, FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
|
|
6
8
|
import { Chip, Icon, CoreIcons } from '@react-fabric/core';
|
|
7
9
|
import { isArray, isEmpty } from '@react-fabric/utilities';
|
|
@@ -12,11 +14,11 @@ import { Options } from './Options.js';
|
|
|
12
14
|
import { useSelect } from './useSelect.js';
|
|
13
15
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
16
|
|
|
15
|
-
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "options", "groupProperty", "labelProperty", "valueProperty", "multiple", "searchable", "allowCreate", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed"];
|
|
17
|
+
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "options", "defaultOpen", "hideHandle", "groupProperty", "labelProperty", "valueProperty", "sortProperty", "infoProperty", "multiple", "searchable", "allowCreate", "emptyDisplay", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed"];
|
|
16
18
|
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
19
|
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
20
|
var Select = function Select(_ref) {
|
|
19
|
-
var _state$query, _refs$reference$curre;
|
|
21
|
+
var _state$query, _refs$reference$curre, _state$activeItem;
|
|
20
22
|
var ref = _ref.ref,
|
|
21
23
|
name = _ref.name,
|
|
22
24
|
value = _ref.value,
|
|
@@ -28,14 +30,19 @@ var Select = function Select(_ref) {
|
|
|
28
30
|
autoFocus = _ref.autoFocus,
|
|
29
31
|
error = _ref.error,
|
|
30
32
|
options = _ref.options,
|
|
33
|
+
defaultOpen = _ref.defaultOpen,
|
|
34
|
+
hideHandle = _ref.hideHandle,
|
|
31
35
|
groupProperty = _ref.groupProperty,
|
|
32
36
|
_ref$labelProperty = _ref.labelProperty,
|
|
33
37
|
labelProperty = _ref$labelProperty === void 0 ? "label" : _ref$labelProperty,
|
|
34
38
|
_ref$valueProperty = _ref.valueProperty,
|
|
35
39
|
valueProperty = _ref$valueProperty === void 0 ? "id" : _ref$valueProperty,
|
|
40
|
+
sortProperty = _ref.sortProperty,
|
|
41
|
+
infoProperty = _ref.infoProperty,
|
|
36
42
|
multiple = _ref.multiple,
|
|
37
43
|
searchable = _ref.searchable,
|
|
38
44
|
allowCreate = _ref.allowCreate,
|
|
45
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
39
46
|
createOption = _ref.createOption,
|
|
40
47
|
matcher = _ref.matcher,
|
|
41
48
|
renderer = _ref.renderer,
|
|
@@ -48,9 +55,11 @@ var Select = function Select(_ref) {
|
|
|
48
55
|
value: value,
|
|
49
56
|
options: options,
|
|
50
57
|
multiple: multiple,
|
|
58
|
+
defaultOpen: defaultOpen,
|
|
51
59
|
groupProperty: groupProperty,
|
|
52
60
|
labelProperty: labelProperty,
|
|
53
61
|
valueProperty: valueProperty,
|
|
62
|
+
sortProperty: sortProperty,
|
|
54
63
|
allowCreate: allowCreate,
|
|
55
64
|
createOption: createOption,
|
|
56
65
|
matcher: matcher,
|
|
@@ -140,6 +149,9 @@ var Select = function Select(_ref) {
|
|
|
140
149
|
return false;
|
|
141
150
|
} else if (state.query) {
|
|
142
151
|
handleQuery("");
|
|
152
|
+
evt.preventDefault();
|
|
153
|
+
evt.stopPropagation();
|
|
154
|
+
return false;
|
|
143
155
|
} else {
|
|
144
156
|
onEnterPressed === null || onEnterPressed === void 0 || onEnterPressed(evt);
|
|
145
157
|
}
|
|
@@ -215,7 +227,7 @@ var Select = function Select(_ref) {
|
|
|
215
227
|
required: required,
|
|
216
228
|
error: error,
|
|
217
229
|
wrapperRef: refs.setReference,
|
|
218
|
-
className: state.open ? "
|
|
230
|
+
className: state.open ? "z-99!" : ""
|
|
219
231
|
}, rest), {}, {
|
|
220
232
|
children: [/*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
221
233
|
role: "none",
|
|
@@ -236,13 +248,13 @@ var Select = function Select(_ref) {
|
|
|
236
248
|
size: 1,
|
|
237
249
|
ref: ref,
|
|
238
250
|
autoFocus: autoFocus,
|
|
239
|
-
className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
|
|
251
|
+
className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 peer", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
|
|
240
252
|
placeholder: isEmpty(state.value) ? placeholder : "",
|
|
241
253
|
onChange: function onChange(evt) {
|
|
242
254
|
return handleQuery(evt.target.value);
|
|
243
255
|
}
|
|
244
256
|
})]
|
|
245
|
-
})), !state.loading && /*#__PURE__*/jsx(Icon, {
|
|
257
|
+
})), !state.loading && !hideHandle && /*#__PURE__*/jsx(Icon, {
|
|
246
258
|
className: classNames("flex-content p-2 z-0 order-9 text-muted cursor-pointer self-stretch flex items-center h-auto", state.open && "-scale-y-100 pointer-events-none", disabled && "pointer-events-none"),
|
|
247
259
|
onClick: function onClick() {
|
|
248
260
|
return !disabled && openDropdown();
|
|
@@ -259,7 +271,7 @@ var Select = function Select(_ref) {
|
|
|
259
271
|
visuallyHiddenDismiss: true,
|
|
260
272
|
children: /*#__PURE__*/jsx(Options, _objectSpread(_objectSpread({
|
|
261
273
|
ref: refs.setFloating,
|
|
262
|
-
className: "outline shadow-lg max-h-[40vh] z-
|
|
274
|
+
className: "outline shadow-lg max-h-[40vh] z-(--z-popover)",
|
|
263
275
|
style: _objectSpread({
|
|
264
276
|
width: (_refs$reference$curre = refs.reference.current) === null || _refs$reference$curre === void 0 ? void 0 : _refs$reference$curre.getBoundingClientRect().width
|
|
265
277
|
}, floatingStyles)
|
|
@@ -270,10 +282,28 @@ var Select = function Select(_ref) {
|
|
|
270
282
|
labelProperty: labelProperty,
|
|
271
283
|
itemRef: setItemRef,
|
|
272
284
|
itemProps: makeItemProps,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
285
|
+
empty: emptyDisplay,
|
|
286
|
+
info: (_state$activeItem = state.activeItem) === null || _state$activeItem === void 0 ? void 0 : _state$activeItem[infoProperty !== null && infoProperty !== void 0 ? infoProperty : "info"],
|
|
287
|
+
children: ( /*#__PURE__*/function () {
|
|
288
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(item, label) {
|
|
289
|
+
var _renderer3;
|
|
290
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
291
|
+
while (1) switch (_context.prev = _context.next) {
|
|
292
|
+
case 0:
|
|
293
|
+
_context.next = 2;
|
|
294
|
+
return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
|
|
295
|
+
case 2:
|
|
296
|
+
return _context.abrupt("return", _context.sent);
|
|
297
|
+
case 3:
|
|
298
|
+
case "end":
|
|
299
|
+
return _context.stop();
|
|
300
|
+
}
|
|
301
|
+
}, _callee);
|
|
302
|
+
}));
|
|
303
|
+
return function (_x, _x2) {
|
|
304
|
+
return _ref4.apply(this, arguments);
|
|
305
|
+
};
|
|
306
|
+
}())
|
|
277
307
|
}))
|
|
278
308
|
})
|
|
279
309
|
})]
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
|
4
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
6
|
import { useDebounce } from '@react-fabric/core';
|
|
7
|
-
import { matchString, isString, dedupe, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
7
|
+
import { matchString, isString, dedupe, compareValues, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
8
8
|
import { useMemo, useDeferredValue, useRef, useCallback, useReducer, useEffect } from 'react';
|
|
9
9
|
import { getSelectedValue, makeOption } from './helpers.js';
|
|
10
10
|
|
|
@@ -15,6 +15,10 @@ var useSelect = function useSelect(_ref) {
|
|
|
15
15
|
options = _ref$options === void 0 ? 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 ? 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 = dedupe([action.query].concat(_toConsumableArray(optionList)));
|
|
135
144
|
}
|
|
145
|
+
if (sortProperty) optionList = optionList.sort(compareValues("asc", sortProperty));
|
|
136
146
|
var grouped = 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 = useCallback(function (query) {
|
|
@@ -316,7 +327,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
316
327
|
});
|
|
317
328
|
}, []);
|
|
318
329
|
var setActiveIndex = useCallback(function (index) {
|
|
319
|
-
dispatch({
|
|
330
|
+
index && index > -1 && dispatch({
|
|
320
331
|
type: "active",
|
|
321
332
|
index: index
|
|
322
333
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
* React Fabric
|
|
3
5
|
* @version: 1.0.0
|
|
@@ -21,31 +23,20 @@
|
|
|
21
23
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
& :global(.flexbox-fix) {
|
|
40
|
-
@apply !border-t-muted justify-center;
|
|
41
|
-
|
|
42
|
-
& > div > div {
|
|
43
|
-
@apply text-center;
|
|
44
|
-
}
|
|
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--";
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
box-shadow: 0 0 1px 1px theme(borderColor.base) inset !important;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
42
|
+
export { DATA_TYPES, SCHEMA_CUSTOM_LIST };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useFloatingTree } from '@floating-ui/react';
|
|
4
|
+
import { useDebounce } from '@react-fabric/core';
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* React Fabric
|
|
@@ -26,16 +27,25 @@ import { debounce } from '@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 = useDebounce(callback !== null && callback !== void 0 ? callback : function () {
|
|
36
37
|
return undefined;
|
|
37
|
-
}, 100);
|
|
38
|
+
}, [callback], 100);
|
|
39
|
+
var tree = 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
|
-
export {
|
|
60
|
+
export { useHandleEnter };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type UploadHandler } from "../hooks/useFileUploader";
|
|
2
|
-
import { type FileSchema } from "../types/schema";
|
|
3
|
-
export declare const FileField: ({ uploadHandler, inline, label, accept, multiple,
|
|
2
|
+
import { type FileSchema, type ValueType } from "../types/schema";
|
|
3
|
+
export declare const FileField: ({ uploadHandler, inline, label, accept, value, fileUrl, multiple, invalid, error, ...rest }: Partial<FileSchema & ValueType> & {
|
|
4
4
|
value?: AnyObject;
|
|
5
5
|
inline?: boolean;
|
|
6
|
+
invalid?: boolean;
|
|
7
|
+
error?: AnyObject;
|
|
6
8
|
fileUrl?: (path: string) => string;
|
|
7
9
|
uploadHandler: UploadHandler;
|
|
8
10
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type UploadHandler } from "../hooks/useFileUploader";
|
|
2
|
+
import { type BaseSelectProps } from "../types";
|
|
2
3
|
import { type SchemaType } from "../types/schema";
|
|
3
|
-
export declare const FormField: ({ id, label, required, inline, prefix, autoFocus,
|
|
4
|
+
export declare const FormField: ({ id, label, required, inline, prefix, autoFocus, optionLists, fileUrl, uploadHandler, ...rest }: SchemaType & {
|
|
4
5
|
inline?: boolean;
|
|
5
6
|
prefix?: string;
|
|
6
7
|
autoFocus?: boolean;
|
|
8
|
+
optionLists?: KeyValue<BaseSelectProps<any>>;
|
|
7
9
|
fileUrl?: (path: string) => string;
|
|
8
10
|
uploadHandler?: UploadHandler;
|
|
9
11
|
}) => import("react/jsx-runtime").JSX.Element | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type SchemaEditorProps } from "../types/schema";
|
|
2
|
+
/**
|
|
3
|
+
* SchemaEditor component allows users to edit a schema definition.
|
|
4
|
+
* It provides a form interface to modify schema properties dynamically.
|
|
5
|
+
*
|
|
6
|
+
* @param {SchemaEditorProps} props - The properties for the SchemaEditor component.
|
|
7
|
+
* @returns {JSX.Element} The rendered SchemaEditor component.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SchemaEditor: ({ schemaDef, dynamic, acceptableTypes, optionLists, children, onSubmit, onChange, }: SchemaEditorProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type SchemaEditorProps } from "../../types/schema";
|
|
2
|
+
export declare const SchemaField: ({ id, field, fieldId, getModel, onRemove, defaultOpen, optionLists, dynamic, onTypeChange, acceptableTypes, }: {
|
|
3
|
+
id: string;
|
|
4
|
+
field: string;
|
|
5
|
+
fieldId: string;
|
|
6
|
+
defaultOpen?: boolean;
|
|
7
|
+
onRemove: () => void;
|
|
8
|
+
getModel: () => KeyValue;
|
|
9
|
+
onTypeChange: (val: KeyValue) => void;
|
|
10
|
+
} & Omit<SchemaEditorProps, "schemaDef" | "onChange">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,7 @@ export interface ControllerProps {
|
|
|
4
4
|
* field name
|
|
5
5
|
*/
|
|
6
6
|
name?: string;
|
|
7
|
-
children: ReactElement | ((props: {
|
|
7
|
+
children: ReactElement<KeyValue> | ((props: {
|
|
8
8
|
name: string;
|
|
9
9
|
error?: string;
|
|
10
10
|
checked: boolean;
|
|
@@ -14,7 +14,52 @@ export interface ControllerProps {
|
|
|
14
14
|
disabled?: boolean;
|
|
15
15
|
onBlur: () => void;
|
|
16
16
|
onChange: (value: AnyObject) => void;
|
|
17
|
-
|
|
17
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
18
18
|
}) => ReactElement);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* This component is used to wrap form controls
|
|
22
|
+
* and provide them with the necessary props and state management.
|
|
23
|
+
*
|
|
24
|
+
* It uses the `Controller` component from `react-hook-form`
|
|
25
|
+
* to manage the form state and validation.
|
|
26
|
+
*
|
|
27
|
+
* It accepts a `name` prop to identify the form control,
|
|
28
|
+
* and a `children` prop which can either be a React element
|
|
29
|
+
* or a function that receives the necessary props to render the control.
|
|
30
|
+
*
|
|
31
|
+
* The component will pass down the following props to the child:
|
|
32
|
+
* - `name`: the name of the form control
|
|
33
|
+
* - `error`: any validation error message
|
|
34
|
+
* - `checked`: whether the control is checked (for checkboxes/radios)
|
|
35
|
+
* - `value`: the current value of the control
|
|
36
|
+
* - `invalid`: whether the control is invalid
|
|
37
|
+
* - `readOnly`: whether the control is read-only (disabled during submission)
|
|
38
|
+
* - `disabled`: whether the control is disabled
|
|
39
|
+
* - `onBlur`: function to call when the control loses focus
|
|
40
|
+
* - `onChange`: function to call when the control value changes
|
|
41
|
+
* - `ref`: a ref to the control element
|
|
42
|
+
* * The component also handles the `ref` prop to ensure that it is passed correctly
|
|
43
|
+
* to the child component, allowing for proper focus management and DOM access.
|
|
44
|
+
*
|
|
45
|
+
* @param {ControllerProps} props - The properties for the Controller component.
|
|
46
|
+
* @returns {JSX.Element} The rendered Controller component.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```jsx
|
|
50
|
+
* <Controller
|
|
51
|
+
* name="username"
|
|
52
|
+
* children={({ name, error, checked, value, invalid, readOnly, onChange }) => (
|
|
53
|
+
* <input
|
|
54
|
+
* type="text"
|
|
55
|
+
* name={name}
|
|
56
|
+
* onChange={onChange}
|
|
57
|
+
* readOnly={readOnly}
|
|
58
|
+
* aria-invalid={invalid}
|
|
59
|
+
* value={value}
|
|
60
|
+
* />
|
|
61
|
+
* )}
|
|
62
|
+
* />
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
20
65
|
export declare const Controller: ({ name, children, ...rest }: ControllerProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type yup } from "@react-fabric/utilities";
|
|
2
2
|
import { type PropsWithChildren, type Ref } from "react";
|
|
3
3
|
import { type FormState } from "react-hook-form";
|
|
4
|
+
type NestedKeyOf<T extends object> = {
|
|
5
|
+
[K in keyof T & (string | number)]: T[K] extends object ? `${K}` | `${K}.${NestedKeyOf<T[K]>}` : K;
|
|
6
|
+
}[keyof T & (string | number)];
|
|
4
7
|
export interface FormRef<K extends KeyValue> {
|
|
5
8
|
state: FormState<K>;
|
|
6
9
|
reset: () => void;
|
|
@@ -8,7 +11,7 @@ export interface FormRef<K extends KeyValue> {
|
|
|
8
11
|
submit: () => void;
|
|
9
12
|
validate: () => Promise<boolean>;
|
|
10
13
|
getValues: () => K;
|
|
11
|
-
setValue: (key:
|
|
14
|
+
setValue: (key: NestedKeyOf<K>, value: AnyObject) => void;
|
|
12
15
|
setValues: (values: K) => void;
|
|
13
16
|
}
|
|
14
17
|
export interface FormProps<K extends KeyValue = KeyValue> {
|
|
@@ -30,4 +33,47 @@ export interface FormProps<K extends KeyValue = KeyValue> {
|
|
|
30
33
|
*/
|
|
31
34
|
onSubmit?: (values: K) => void;
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Form component for managing form state and validation using react-hook-form and yup.
|
|
38
|
+
* It provides a simple interface for form handling, including submission, validation, and value management.
|
|
39
|
+
* It supports nested form structures and allows for custom validation schemas using Yup.
|
|
40
|
+
*
|
|
41
|
+
* @param {FormProps<K>} props - The properties for the Form component.
|
|
42
|
+
* @returns {JSX.Element} The rendered Form component.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```jsx
|
|
46
|
+
* <Form
|
|
47
|
+
* formRef={formRef}
|
|
48
|
+
* schema={yup.object().shape({
|
|
49
|
+
* name: yup.string().required("Name is required"),
|
|
50
|
+
* email: yup.string().email("Invalid email").required("Email is required"),
|
|
51
|
+
* })}
|
|
52
|
+
* defaultValues={{ name: "", email: "" }}
|
|
53
|
+
* onSubmit={(values) => {
|
|
54
|
+
* console.log("Form submitted with values:", values);
|
|
55
|
+
* }}
|
|
56
|
+
* >
|
|
57
|
+
* <input name="name" ref={form.register} placeholder="Name" />
|
|
58
|
+
* <input name="email" ref={form.register} placeholder="Email" />
|
|
59
|
+
* <button type="submit">Submit</button>
|
|
60
|
+
* </Form>
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/form-form--docs} for the properties that can be passed to this component.
|
|
64
|
+
* @see {@link https://react-hook-form.com/docs/useform} for more details on the properties.
|
|
65
|
+
* @see {@link https://github.com/jquense/yup} for more details on the Yup validation schema.
|
|
66
|
+
*/
|
|
67
|
+
export declare const Form: <K extends KeyValue>({ formRef, schema, children, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
|
|
68
|
+
export declare const useForm: <K extends KeyValue = KeyValue>() => {
|
|
69
|
+
values: import("react-hook-form").DeepPartialSkipArrayKey<K> & K;
|
|
70
|
+
formState: FormState<K>;
|
|
71
|
+
getValues: import("react-hook-form").UseFormGetValues<K>;
|
|
72
|
+
setValue: import("react-hook-form").UseFormSetValue<K>;
|
|
73
|
+
watch: import("react-hook-form").UseFormWatch<K>;
|
|
74
|
+
reset: import("react-hook-form").UseFormReset<K>;
|
|
75
|
+
resetField: import("react-hook-form").UseFormResetField<K>;
|
|
76
|
+
setError: import("react-hook-form").UseFormSetError<K>;
|
|
77
|
+
setFocus: import("react-hook-form").UseFormSetFocus<K>;
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -12,6 +12,22 @@ interface FileInfo {
|
|
|
12
12
|
progress?: number;
|
|
13
13
|
abort?: AbortController["abort"];
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* useFileUploader hook provides a way to handle file uploads
|
|
17
|
+
* with progress tracking, error handling, and file management.
|
|
18
|
+
* It uses a reducer to manage the state of uploaded files and their statuses.
|
|
19
|
+
*
|
|
20
|
+
* @param uploader - The function that handles the file upload.
|
|
21
|
+
* @param initialList - Initial list of files to be managed by the uploader.
|
|
22
|
+
* @param multiple - Whether to allow multiple file uploads or not.
|
|
23
|
+
* @returns An object containing methods to upload, remove, retry files,
|
|
24
|
+
* and the current state of the uploader including pending uploads and file list.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* const { upload, remove, retry, state } = useFileUploader(uploader, initialList, multiple);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
15
31
|
export declare const useFileUploader: (uploader: UploadHandler, initialList?: string | FileInfo | FileInfo[], multiple?: boolean) => {
|
|
16
32
|
upload: (files: FileList | null) => void;
|
|
17
33
|
remove: (key: string) => void;
|
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
import { yup } from "@react-fabric/utilities";
|
|
2
|
+
import { type BaseSelectProps } from "../types";
|
|
2
3
|
import { type FormSchema } from "../types/schema";
|
|
3
4
|
import { type UploadHandler } from "./useFileUploader";
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* useFormBuilder hook to create a form definition based on a schema.
|
|
7
|
+
* It generates a Yup validation schema and a form definition component.
|
|
8
|
+
*
|
|
9
|
+
* @param {FormSchema} schema - The schema defining the form fields.
|
|
10
|
+
* @param {Object} options - Optional parameters for the form builder.
|
|
11
|
+
* @returns An object containing the form definition and the Yup validation schema.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* const { formDef, schemaDef } = useFormBuilder(schema, {
|
|
16
|
+
* prefix: "form",
|
|
17
|
+
* inline: true,
|
|
18
|
+
* fileUrl: (path) => `/files/${path}`,
|
|
19
|
+
* uploadHandler: async (file) => {
|
|
20
|
+
* // handle file upload
|
|
21
|
+
* },
|
|
22
|
+
* optionLists: {
|
|
23
|
+
* // define option lists for select fields
|
|
24
|
+
* }
|
|
25
|
+
* * });
|
|
26
|
+
* <FormBuilder
|
|
27
|
+
* schema={schemaDef}
|
|
28
|
+
* onSubmit={(data) => console.log(data)}
|
|
29
|
+
* >
|
|
30
|
+
* {formDef}
|
|
31
|
+
* </FormBuilder>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const useFormBuilder: <T extends AnyObject = string>(schema: FormSchema, options?: {
|
|
5
35
|
prefix?: string;
|
|
6
36
|
inline?: boolean;
|
|
7
37
|
fileUrl?: (path: string) => string;
|
|
8
38
|
uploadHandler?: UploadHandler;
|
|
39
|
+
optionLists?: KeyValue<BaseSelectProps<T>>;
|
|
9
40
|
}) => {
|
|
10
41
|
formDef: import("react/jsx-runtime").JSX.Element;
|
|
11
42
|
schemaDef: yup.ObjectSchema<{
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
2
|
export { Controller } from "./form/Controller";
|
|
3
|
-
export { Form, type FormRef } from "./form/Form";
|
|
3
|
+
export { Form, useForm, type FormRef } from "./form/Form";
|
|
4
|
+
export { SchemaEditor } from "./builder/SchemaEditor";
|
|
4
5
|
export { useFileUploader } from "./hooks/useFileUploader";
|
|
5
6
|
export { useFormBuilder } from "./hooks/useFormBuilder";
|
|
6
|
-
export { type FormSchema } from "./types/schema";
|
|
7
|
+
export { DATA_TYPES, SCHEMA_CUSTOM_LIST, type FormSchema, type SchemaDef, } from "./types/schema";
|
|
7
8
|
export { ArrayInput } from "./input/ArrayInput";
|
|
9
|
+
export { AvatarInput } from "./input/AvatarInput";
|
|
8
10
|
export { Checkbox } from "./input/Checkbox";
|
|
9
11
|
export { ColorInput } from "./input/ColorInput";
|
|
10
12
|
export { ColorPicker } from "./input/ColorPicker";
|
|
13
|
+
export { DateInput } from "./input/DateInput";
|
|
11
14
|
export { Field } from "./input/Field";
|
|
12
15
|
export { FileInput } from "./input/File";
|
|
13
16
|
export { HiddenInput } from "./input/Hidden";
|
|
@@ -16,7 +19,7 @@ export { Number } from "./input/Number";
|
|
|
16
19
|
export { Password } from "./input/Password";
|
|
17
20
|
export { Radio } from "./input/Radio";
|
|
18
21
|
export { RadioGroup } from "./input/RadioGroup";
|
|
19
|
-
export {
|
|
22
|
+
export { RangeSlider } from "./input/RangeSlider";
|
|
20
23
|
export { Search } from "./input/Search";
|
|
21
24
|
export { Slider } from "./input/Slider";
|
|
22
25
|
export { Switch } from "./input/Switch";
|