@react-fabric/form 1.0.0-beta.9 → 1.0.2
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 +95 -0
- package/{src/internal/Field.module.css → css/_field.css} +94 -33
- package/{src/input/File.module.css → css/_file.css} +21 -6
- package/css/styles.css +27 -0
- package/dist/cjs/builder/FileField.js +107 -78
- package/dist/cjs/builder/FormField.js +60 -39
- package/dist/cjs/builder/SchemaEditor.js +72 -0
- package/dist/cjs/builder/components/AddSchemaFields.js +64 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +146 -0
- package/dist/cjs/builder/components/SchemaField.js +423 -0
- package/dist/cjs/form/Controller.js +66 -19
- package/dist/cjs/form/Form.js +97 -39
- package/dist/cjs/form/useForm.js +32 -0
- package/dist/cjs/hooks/useFileUploader.js +74 -45
- package/dist/cjs/hooks/useFormBuilder.js +85 -31
- package/dist/cjs/i18n/{ar.json.js → ar/form.json.js} +5 -4
- package/dist/cjs/i18n/{en.json.js → en/form.json.js} +5 -5
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +41 -2
- package/dist/cjs/input/ArrayInput.js +259 -135
- package/dist/cjs/input/AvatarInput.js +99 -63
- package/dist/cjs/input/Checkbox.js +24 -25
- package/dist/cjs/input/ColorInput.js +138 -81
- package/dist/cjs/input/ColorPicker.js +78 -95
- package/dist/cjs/input/DateInput.js +192 -0
- package/dist/cjs/input/Field.js +21 -20
- package/dist/cjs/input/File.js +85 -80
- package/dist/cjs/input/Hidden.js +27 -13
- package/dist/cjs/input/Input.js +49 -48
- package/dist/cjs/input/Number.js +46 -44
- package/dist/cjs/input/Password.js +51 -49
- package/dist/cjs/input/Radio.js +26 -16
- package/dist/cjs/input/RadioGroup.js +26 -11
- package/dist/cjs/input/{Range.js → RangeSlider.js} +61 -66
- package/dist/cjs/input/Search.js +58 -64
- package/dist/cjs/input/Slider.js +57 -66
- package/dist/cjs/input/Switch.js +29 -27
- package/dist/cjs/input/Textarea.js +65 -53
- package/dist/cjs/internal/ErrorIcon.js +9 -9
- package/dist/cjs/internal/FieldWrapper.js +23 -13
- package/dist/cjs/internal/InputWrapper.js +85 -87
- package/dist/cjs/ranger/index.js +7 -7
- package/dist/cjs/ranger/utils.js +9 -4
- package/dist/cjs/select/AutoComplete.js +93 -76
- package/dist/cjs/select/DualList.js +235 -154
- package/dist/cjs/select/List.js +122 -89
- package/dist/cjs/select/Options.js +58 -54
- package/dist/cjs/select/Select.js +119 -89
- package/dist/cjs/select/helpers.js +5 -5
- package/dist/cjs/select/useSelect.js +83 -58
- package/dist/cjs/types/schema.js +43 -0
- package/dist/cjs/utils/eventHandlers.js +16 -6
- package/dist/cjs/utils/getColor.js +6 -6
- package/dist/cjs/utils/getProps.js +49 -0
- package/dist/esm/builder/FileField.js +109 -80
- package/dist/esm/builder/FormField.js +60 -39
- package/dist/esm/builder/SchemaEditor.js +72 -0
- package/dist/esm/builder/components/AddSchemaFields.js +64 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +146 -0
- package/dist/esm/builder/components/SchemaField.js +423 -0
- package/dist/esm/form/Controller.js +66 -19
- package/dist/esm/form/Form.js +97 -39
- package/dist/esm/form/useForm.js +32 -0
- package/dist/esm/hooks/useFileUploader.js +75 -46
- package/dist/esm/hooks/useFormBuilder.js +84 -30
- package/dist/esm/i18n/{ar.json.js → ar/form.json.js} +5 -4
- package/dist/esm/i18n/{en.json.js → en/form.json.js} +5 -5
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +36 -1
- package/dist/esm/input/ArrayInput.js +260 -136
- package/dist/esm/input/AvatarInput.js +99 -63
- package/dist/esm/input/Checkbox.js +26 -27
- package/dist/esm/input/ColorInput.js +141 -84
- package/dist/esm/input/ColorPicker.js +80 -97
- package/dist/esm/input/DateInput.js +192 -0
- package/dist/esm/input/Field.js +21 -20
- package/dist/esm/input/File.js +89 -84
- package/dist/esm/input/Hidden.js +28 -14
- package/dist/esm/input/Input.js +51 -50
- package/dist/esm/input/Number.js +48 -46
- package/dist/esm/input/Password.js +54 -52
- package/dist/esm/input/Radio.js +27 -17
- package/dist/esm/input/RadioGroup.js +27 -12
- package/dist/esm/input/{Range.js → RangeSlider.js} +62 -67
- package/dist/esm/input/Search.js +61 -67
- package/dist/esm/input/Slider.js +58 -67
- package/dist/esm/input/Switch.js +31 -29
- package/dist/esm/input/Textarea.js +67 -55
- package/dist/esm/internal/ErrorIcon.js +11 -11
- package/dist/esm/internal/FieldWrapper.js +23 -13
- package/dist/esm/internal/InputWrapper.js +88 -90
- package/dist/esm/ranger/index.js +7 -7
- package/dist/esm/ranger/utils.js +9 -4
- package/dist/esm/select/AutoComplete.js +95 -78
- package/dist/esm/select/DualList.js +233 -152
- package/dist/esm/select/List.js +125 -92
- package/dist/esm/select/Options.js +58 -54
- package/dist/esm/select/Select.js +122 -92
- package/dist/esm/select/helpers.js +5 -5
- package/dist/esm/select/useSelect.js +84 -59
- package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
- package/dist/esm/utils/eventHandlers.js +16 -6
- package/dist/esm/utils/getColor.js +6 -6
- package/dist/esm/utils/getProps.js +49 -0
- package/dist/types/builder/FileField.d.ts +7 -4
- package/dist/types/builder/FormField.d.ts +4 -2
- package/dist/types/builder/SchemaEditor.d.ts +6 -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 +12 -0
- package/dist/types/form/Controller.d.ts +45 -3
- package/dist/types/form/Form.d.ts +38 -7
- package/dist/types/form/useForm.d.ts +6 -0
- package/dist/types/hooks/useFileUploader.d.ts +24 -3
- package/dist/types/hooks/useFormBuilder.d.ts +41 -3
- package/dist/types/index.d.ts +32 -2
- package/dist/types/input/ArrayInput.d.ts +68 -13
- package/dist/types/input/AvatarInput.d.ts +23 -6
- package/dist/types/input/Checkbox.d.ts +12 -10
- package/dist/types/input/ColorInput.d.ts +15 -5
- package/dist/types/input/ColorPicker.d.ts +10 -2
- package/dist/types/input/DateInput.d.ts +21 -0
- package/dist/types/input/Field.d.ts +9 -36
- package/dist/types/input/File.d.ts +16 -4
- package/dist/types/input/Hidden.d.ts +7 -6
- package/dist/types/input/Input.d.ts +11 -4
- package/dist/types/input/Number.d.ts +9 -4
- package/dist/types/input/Password.d.ts +9 -4
- package/dist/types/input/Radio.d.ts +9 -4
- package/dist/types/input/RadioGroup.d.ts +14 -6
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +11 -6
- package/dist/types/input/Search.d.ts +14 -4
- package/dist/types/input/Slider.d.ts +9 -6
- package/dist/types/input/Switch.d.ts +13 -8
- package/dist/types/input/Textarea.d.ts +15 -4
- package/dist/types/internal/ErrorIcon.d.ts +4 -1
- package/dist/types/internal/FieldWrapper.d.ts +10 -1
- package/dist/types/internal/InputWrapper.d.ts +19 -1
- package/dist/types/ranger/index.d.ts +7 -3
- package/dist/types/ranger/utils.d.ts +2 -2
- package/dist/types/select/AutoComplete.d.ts +7 -2
- package/dist/types/select/DualList.d.ts +11 -37
- package/dist/types/select/List.d.ts +7 -2
- package/dist/types/select/Options.d.ts +8 -7
- package/dist/types/select/Select.d.ts +7 -2
- package/dist/types/select/helpers.d.ts +2 -2
- package/dist/types/select/useSelect.d.ts +10 -28
- package/dist/types/types/index.d.ts +73 -39
- package/dist/types/types/schema.d.ts +78 -32
- package/dist/types/utils/eventHandlers.d.ts +4 -4
- package/dist/types/utils/getColor.d.ts +4 -4
- package/dist/types/utils/getProps.d.ts +26 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +25 -25
- package/src/builder/FileField.tsx +73 -56
- package/src/builder/FormField.tsx +66 -58
- package/src/builder/SchemaEditor.tsx +78 -0
- package/src/builder/components/AddSchemaFields.tsx +64 -0
- package/src/builder/components/SchemaArrayForm.tsx +146 -0
- package/src/builder/components/SchemaField.tsx +405 -0
- package/src/form/Controller.tsx +61 -24
- package/src/form/Form.tsx +74 -50
- package/src/form/useForm.ts +53 -0
- package/src/hooks/useFileUploader.ts +115 -84
- package/src/hooks/useFormBuilder.tsx +80 -41
- package/src/i18n/{ar.json → ar/form.json} +5 -4
- package/src/i18n/{en.json → en/form.json} +5 -5
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +34 -20
- package/src/input/ArrayInput.tsx +255 -173
- package/src/input/AvatarInput.tsx +82 -39
- package/src/input/Checkbox.tsx +30 -54
- package/src/input/ColorInput.tsx +146 -105
- package/src/input/ColorPicker.tsx +76 -102
- package/src/input/DateInput.tsx +225 -0
- package/src/input/Field.tsx +23 -65
- package/src/input/File.tsx +76 -98
- package/src/input/Hidden.tsx +36 -24
- package/src/input/Input.tsx +55 -53
- package/src/input/Number.tsx +49 -54
- package/src/input/Password.tsx +61 -66
- package/src/input/Radio.tsx +28 -37
- package/src/input/RadioGroup.tsx +30 -25
- package/src/input/{Range.tsx → RangeSlider.tsx} +81 -109
- package/src/input/Search.tsx +64 -77
- package/src/input/Slider.tsx +80 -109
- package/src/input/Switch.tsx +39 -53
- package/src/input/Textarea.tsx +72 -59
- package/src/internal/ErrorIcon.tsx +22 -21
- package/src/internal/FieldWrapper.tsx +33 -23
- package/src/internal/InputWrapper.tsx +132 -143
- package/src/ranger/index.tsx +37 -117
- package/src/ranger/utils.ts +12 -11
- package/src/select/AutoComplete.tsx +113 -123
- package/src/select/DualList.tsx +218 -204
- package/src/select/List.tsx +130 -97
- package/src/select/Options.tsx +59 -57
- package/src/select/Select.tsx +148 -122
- package/src/select/helpers.ts +13 -8
- package/src/select/useSelect.tsx +110 -127
- package/src/types/index.ts +76 -45
- package/src/types/schema.ts +97 -40
- package/src/utils/eventHandlers.ts +24 -26
- package/src/utils/getColor.ts +9 -8
- package/src/utils/getProps.ts +47 -0
- package/src/utils/index.ts +1 -0
- 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
|
@@ -9,28 +9,34 @@ var react = require('react');
|
|
|
9
9
|
var helpers = require('./helpers.js');
|
|
10
10
|
|
|
11
11
|
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; }
|
|
12
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
options =
|
|
16
|
-
value =
|
|
17
|
-
autoComplete =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
|
|
13
|
+
function useSelect(props) {
|
|
14
|
+
var _props$options = props.options,
|
|
15
|
+
options = _props$options === void 0 ? utilities.EMPTY_ARRAY : _props$options,
|
|
16
|
+
value = props.value,
|
|
17
|
+
autoComplete = props.autoComplete,
|
|
18
|
+
_props$alwaysOpen = props.alwaysOpen,
|
|
19
|
+
alwaysOpen = _props$alwaysOpen === void 0 ? false : _props$alwaysOpen,
|
|
20
|
+
_props$defaultOpen = props.defaultOpen,
|
|
21
|
+
defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
|
|
22
|
+
_props$multiple = props.multiple,
|
|
23
|
+
multiple = _props$multiple === void 0 ? false : _props$multiple,
|
|
24
|
+
_props$allowCreate = props.allowCreate,
|
|
25
|
+
allowCreate = _props$allowCreate === void 0 ? false : _props$allowCreate,
|
|
26
|
+
_props$groupProperty = props.groupProperty,
|
|
27
|
+
groupProperty = _props$groupProperty === void 0 ? "" : _props$groupProperty,
|
|
28
|
+
_props$valueProperty = props.valueProperty,
|
|
29
|
+
valueProperty = _props$valueProperty === void 0 ? "value" : _props$valueProperty,
|
|
30
|
+
_props$labelProperty = props.labelProperty,
|
|
31
|
+
labelProperty = _props$labelProperty === void 0 ? "label" : _props$labelProperty,
|
|
32
|
+
sortProperty = props.sortProperty,
|
|
33
|
+
_props$createOption = props.createOption,
|
|
34
|
+
createOption = _props$createOption === void 0 ? helpers.makeOption : _props$createOption,
|
|
35
|
+
matcher = props.matcher,
|
|
36
|
+
onQuery = props.onQuery,
|
|
37
|
+
onChange = props.onChange,
|
|
38
|
+
onSelect = props.onSelect;
|
|
39
|
+
|
|
34
40
|
// value state
|
|
35
41
|
var emptyValue = react.useMemo(function () {
|
|
36
42
|
return multiple ? [] : "";
|
|
@@ -42,16 +48,17 @@ var useSelect = function useSelect(_ref) {
|
|
|
42
48
|
var focusableRef = react.useRef(null);
|
|
43
49
|
var listContentRef = react.useRef([]);
|
|
44
50
|
var optionsRef = react.useRef([]);
|
|
45
|
-
var
|
|
51
|
+
var matchOption = react.useCallback(function (item, query) {
|
|
46
52
|
var _matcher, _item$labelProperty;
|
|
47
53
|
return (_matcher = matcher === null || matcher === void 0 ? void 0 : matcher(item, query)) !== null && _matcher !== void 0 ? _matcher : utilities.matchString((_item$labelProperty = item[labelProperty]) !== null && _item$labelProperty !== void 0 ? _item$labelProperty : item, query);
|
|
48
|
-
}, [matcher]);
|
|
54
|
+
}, [labelProperty, matcher]);
|
|
49
55
|
var fireChange = react.useCallback(function (value) {
|
|
50
56
|
setTimeout(function () {
|
|
51
57
|
onSelect === null || onSelect === void 0 || onSelect(value !== null && value !== void 0 ? value : emptyValue);
|
|
58
|
+
// @ts-expect-error ignore
|
|
52
59
|
onChange === null || onChange === void 0 || onChange(helpers.getSelectedValue(value, emptyValue, valueProperty));
|
|
53
60
|
}, 50);
|
|
54
|
-
}, [emptyValue,
|
|
61
|
+
}, [onSelect, emptyValue, onChange, valueProperty]);
|
|
55
62
|
var _useReducer = react.useReducer(function (state, action) {
|
|
56
63
|
if (action.type === "open") {
|
|
57
64
|
var index = state.items.indexOf(state.multiple ? state.value[0] : state.value);
|
|
@@ -63,13 +70,15 @@ var useSelect = function useSelect(_ref) {
|
|
|
63
70
|
if (action.type === "close") {
|
|
64
71
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
65
72
|
activeIndex: null,
|
|
73
|
+
activeItem: null,
|
|
66
74
|
open: false
|
|
67
75
|
});
|
|
68
76
|
}
|
|
69
77
|
if (action.type === "active" && state.open) {
|
|
70
78
|
if (autoComplete && action.index !== null) state.query = state.items[action.index];
|
|
71
79
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
72
|
-
activeIndex: action.index
|
|
80
|
+
activeIndex: action.index,
|
|
81
|
+
activeItem: action.index !== null ? state.items[action.index] : null
|
|
73
82
|
});
|
|
74
83
|
}
|
|
75
84
|
if (action.type === "setValue") {
|
|
@@ -83,6 +92,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
83
92
|
var newState = _objectSpread(_objectSpread({}, state), {}, {
|
|
84
93
|
value: state.emptyValue,
|
|
85
94
|
activeIndex: null,
|
|
95
|
+
activeItem: null,
|
|
86
96
|
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
97
|
});
|
|
88
98
|
if (action.value !== undefined) {
|
|
@@ -100,7 +110,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
100
110
|
newState.value = action.value;
|
|
101
111
|
}
|
|
102
112
|
}
|
|
103
|
-
if (!state.multiple) newState.open =
|
|
113
|
+
if (!state.multiple) newState.open = alwaysOpen;
|
|
104
114
|
fireChange(newState.value);
|
|
105
115
|
return newState;
|
|
106
116
|
}
|
|
@@ -133,19 +143,20 @@ var useSelect = function useSelect(_ref) {
|
|
|
133
143
|
if (autoComplete && action.query !== undefined) {
|
|
134
144
|
optionList = utilities.dedupe([action.query].concat(_toConsumableArray(optionList)));
|
|
135
145
|
}
|
|
146
|
+
if (sortProperty) optionList = optionList.sort(utilities.compareValues("asc", sortProperty !== true ? sortProperty : undefined));
|
|
136
147
|
var grouped = utilities.groupBy(optionList, groupProperty, "");
|
|
137
148
|
if (action.open) _newState.open = true;
|
|
138
149
|
_newState.items = [];
|
|
139
150
|
// add new item if allowCreate
|
|
140
151
|
if (allowCreate && action.query) _newState.items.push({
|
|
141
152
|
___create___: true,
|
|
142
|
-
value:
|
|
153
|
+
value: action.query
|
|
143
154
|
});
|
|
144
|
-
Object.entries(grouped).forEach(function (
|
|
155
|
+
Object.entries(grouped).forEach(function (_ref) {
|
|
145
156
|
var _newState$items;
|
|
146
|
-
var
|
|
147
|
-
key =
|
|
148
|
-
list =
|
|
157
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
158
|
+
key = _ref2[0],
|
|
159
|
+
list = _ref2[1];
|
|
149
160
|
if (key) {
|
|
150
161
|
_newState.items.push({
|
|
151
162
|
___group___: true,
|
|
@@ -159,32 +170,38 @@ var useSelect = function useSelect(_ref) {
|
|
|
159
170
|
return !opt.___group___;
|
|
160
171
|
});
|
|
161
172
|
_newState.activeIndex = _index >= 0 ? _index : null;
|
|
173
|
+
_newState.activeItem = _index >= 0 ? _newState.items[_index] : null;
|
|
162
174
|
} else {
|
|
163
175
|
_newState.activeIndex = null;
|
|
176
|
+
_newState.activeItem = null;
|
|
164
177
|
}
|
|
165
178
|
listContentRef.current = _newState.items;
|
|
166
179
|
return _newState;
|
|
167
180
|
}
|
|
168
181
|
return state;
|
|
169
|
-
}, {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
}, {}, function () {
|
|
183
|
+
return {
|
|
184
|
+
multiple: multiple,
|
|
185
|
+
emptyValue: emptyValue,
|
|
186
|
+
open: alwaysOpen || defaultOpen,
|
|
187
|
+
loading: false,
|
|
188
|
+
activeIndex: null,
|
|
189
|
+
activeItem: null,
|
|
190
|
+
selectedIndex: null,
|
|
191
|
+
value: emptyValue,
|
|
192
|
+
// filter
|
|
193
|
+
query: undefined,
|
|
194
|
+
// dropdown items
|
|
195
|
+
items: []
|
|
196
|
+
};
|
|
181
197
|
}),
|
|
182
198
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
183
199
|
state = _useReducer2[0],
|
|
184
200
|
dispatch = _useReducer2[1];
|
|
185
201
|
react.useEffect(function () {
|
|
186
202
|
if (!multiple) {
|
|
187
|
-
var
|
|
203
|
+
var _ref3;
|
|
204
|
+
// @ts-expect-error ignore
|
|
188
205
|
var newOption = (allowCreate || autoComplete) && deferred ? createOption(deferred) : undefined;
|
|
189
206
|
var hasValue = options.find(function (opt) {
|
|
190
207
|
var _opt$valueProperty;
|
|
@@ -201,22 +218,22 @@ var useSelect = function useSelect(_ref) {
|
|
|
201
218
|
});
|
|
202
219
|
dispatch({
|
|
203
220
|
type: "setValue",
|
|
204
|
-
value: (
|
|
221
|
+
value: (_ref3 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref3 !== void 0 ? _ref3 : deferred
|
|
205
222
|
});
|
|
206
223
|
}
|
|
207
224
|
if (multiple) {
|
|
208
225
|
optionsRef.current = [];
|
|
209
226
|
var _value = (utilities.isArray(deferred) ? deferred : []).map(function (item) {
|
|
210
|
-
var
|
|
227
|
+
var _ref4;
|
|
211
228
|
var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
|
|
212
229
|
var hasValue = options.find(function (opt) {
|
|
213
230
|
var _opt$valueProperty2;
|
|
214
|
-
return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) ===
|
|
231
|
+
return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
|
|
215
232
|
});
|
|
216
233
|
if (!hasValue && newOption) {
|
|
217
234
|
optionsRef.current.push(newOption);
|
|
218
235
|
}
|
|
219
|
-
return (
|
|
236
|
+
return (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : item;
|
|
220
237
|
});
|
|
221
238
|
optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
|
|
222
239
|
dispatch({
|
|
@@ -228,14 +245,15 @@ var useSelect = function useSelect(_ref) {
|
|
|
228
245
|
value: _value
|
|
229
246
|
});
|
|
230
247
|
}
|
|
231
|
-
}, [deferred, options, multiple, allowCreate, autoComplete, createOption]);
|
|
248
|
+
}, [deferred, options, multiple, allowCreate, autoComplete, createOption, valueProperty]);
|
|
232
249
|
var fireQuery = core.useDebounce(function (query) {
|
|
233
250
|
void Promise.resolve(onQuery === null || onQuery === void 0 ? void 0 : onQuery(query)).then(function (options) {
|
|
251
|
+
// @ts-expect-error ignore
|
|
234
252
|
var newOptions = _toConsumableArray(options);
|
|
235
253
|
// if autocomplete inject other filtered options from history
|
|
236
254
|
if (autoComplete) {
|
|
237
255
|
newOptions.push.apply(newOptions, _toConsumableArray(optionsRef.current.filter(function (opt) {
|
|
238
|
-
return
|
|
256
|
+
return matchOption === null || matchOption === void 0 ? void 0 : matchOption(opt, query);
|
|
239
257
|
})));
|
|
240
258
|
}
|
|
241
259
|
dispatch({
|
|
@@ -246,7 +264,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
246
264
|
setActive: true
|
|
247
265
|
});
|
|
248
266
|
});
|
|
249
|
-
}, [onQuery]);
|
|
267
|
+
}, [onQuery], 300);
|
|
250
268
|
|
|
251
269
|
// handlers
|
|
252
270
|
var handleQuery = react.useCallback(function (query) {
|
|
@@ -270,11 +288,11 @@ var useSelect = function useSelect(_ref) {
|
|
|
270
288
|
open: true,
|
|
271
289
|
setActive: true,
|
|
272
290
|
options: optionsRef.current.filter(function (opt) {
|
|
273
|
-
return
|
|
291
|
+
return matchOption === null || matchOption === void 0 ? void 0 : matchOption(opt, query);
|
|
274
292
|
})
|
|
275
293
|
});
|
|
276
294
|
}
|
|
277
|
-
}, [
|
|
295
|
+
}, [fireQuery, matchOption, onQuery]);
|
|
278
296
|
var handleChange = react.useCallback(function (value) {
|
|
279
297
|
var values = value;
|
|
280
298
|
if (autoComplete && multiple && value) {
|
|
@@ -298,7 +316,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
298
316
|
type: "options",
|
|
299
317
|
options: optionsRef.current
|
|
300
318
|
});
|
|
301
|
-
}, []);
|
|
319
|
+
}, [autoComplete, createOption, multiple]);
|
|
302
320
|
var handleRemove = react.useCallback(function (index) {
|
|
303
321
|
dispatch({
|
|
304
322
|
type: "removeItem",
|
|
@@ -316,11 +334,17 @@ var useSelect = function useSelect(_ref) {
|
|
|
316
334
|
});
|
|
317
335
|
}, []);
|
|
318
336
|
var setActiveIndex = react.useCallback(function (index) {
|
|
319
|
-
dispatch({
|
|
337
|
+
if (index && index > -1) dispatch({
|
|
320
338
|
type: "active",
|
|
321
339
|
index: index
|
|
322
340
|
});
|
|
323
341
|
}, []);
|
|
342
|
+
var clearActiveIndex = react.useCallback(function () {
|
|
343
|
+
dispatch({
|
|
344
|
+
type: "active",
|
|
345
|
+
index: null
|
|
346
|
+
});
|
|
347
|
+
}, []);
|
|
324
348
|
return {
|
|
325
349
|
state: state,
|
|
326
350
|
listRef: listRef,
|
|
@@ -329,13 +353,14 @@ var useSelect = function useSelect(_ref) {
|
|
|
329
353
|
handleChange: handleChange,
|
|
330
354
|
handleRemove: handleRemove,
|
|
331
355
|
handleQuery: handleQuery,
|
|
332
|
-
|
|
356
|
+
clearActiveIndex: clearActiveIndex,
|
|
357
|
+
macthOption: matchOption,
|
|
333
358
|
setActiveIndex: setActiveIndex,
|
|
334
359
|
setOpen: setOpen,
|
|
335
360
|
setItemRef: function setItemRef(index, node) {
|
|
336
361
|
listRef.current[index] = node;
|
|
337
362
|
}
|
|
338
363
|
};
|
|
339
|
-
}
|
|
364
|
+
}
|
|
340
365
|
|
|
341
366
|
exports.useSelect = useSelect;
|
|
@@ -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
|
-
|
|
30
|
+
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);
|
|
@@ -45,6 +55,6 @@ var handleEnter = function handleEnter(callback) {
|
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
};
|
|
48
|
-
}
|
|
58
|
+
}
|
|
49
59
|
|
|
50
|
-
exports.
|
|
60
|
+
exports.useHandleEnter = useHandleEnter;
|
|
@@ -25,21 +25,21 @@ var utilities = require('@react-fabric/utilities');
|
|
|
25
25
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
function getColor(color) {
|
|
29
29
|
if (color && utilities.isColor(color)) {
|
|
30
30
|
return color;
|
|
31
31
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
32
|
+
}
|
|
33
|
+
function getBgClass(bg) {
|
|
34
34
|
if (bg && !utilities.isColor(bg)) {
|
|
35
35
|
return "bg-".concat(bg);
|
|
36
36
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
37
|
+
}
|
|
38
|
+
function getColorClass(color) {
|
|
39
39
|
if (color && !utilities.isColor(color)) {
|
|
40
40
|
return "text-".concat(color);
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
exports.getBgClass = getBgClass;
|
|
45
45
|
exports.getColor = getColor;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @copyright 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
function getWrapperProps(props) {
|
|
29
|
+
return {
|
|
30
|
+
appendLabel: props.appendLabel,
|
|
31
|
+
name: props.name,
|
|
32
|
+
info: props.info,
|
|
33
|
+
inline: props.inline,
|
|
34
|
+
label: props.label,
|
|
35
|
+
labelWidth: props.labelWidth,
|
|
36
|
+
required: props.required,
|
|
37
|
+
disabled: props.disabled,
|
|
38
|
+
width: props.width,
|
|
39
|
+
error: props.error,
|
|
40
|
+
invalid: props.invalid,
|
|
41
|
+
borderless: props.borderless,
|
|
42
|
+
decorateEnd: props.decorateEnd,
|
|
43
|
+
decorateEndHideWhenEmpty: props.decorateEndHideWhenEmpty,
|
|
44
|
+
decorateEndShowWhenEmpty: props.decorateEndShowWhenEmpty,
|
|
45
|
+
decorateStart: props.decorateStart
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.getWrapperProps = getWrapperProps;
|