@pingux/astro 2.130.2-alpha.2 → 2.130.2-alpha.3
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/lib/cjs/components/ComboBox/ComboBoxInput.js +5 -37
- package/lib/cjs/components/MultivaluesField/CondensedMultivaluesField.js +51 -28
- package/lib/cjs/components/MultivaluesField/DefaultMultivaluesField.js +25 -9
- package/lib/cjs/components/MultivaluesField/MultivaluesField.stories.js +11 -3
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +0 -4
- package/lib/cjs/hooks/index.d.ts +1 -0
- package/lib/cjs/hooks/index.js +7 -0
- package/lib/cjs/hooks/useInputLoader/index.d.ts +1 -0
- package/lib/cjs/hooks/useInputLoader/index.js +14 -0
- package/lib/cjs/hooks/useInputLoader/useInputLoader.d.ts +9 -0
- package/lib/cjs/hooks/useInputLoader/useInputLoader.js +55 -0
- package/lib/components/ComboBox/ComboBoxInput.js +7 -39
- package/lib/components/MultivaluesField/CondensedMultivaluesField.js +54 -31
- package/lib/components/MultivaluesField/DefaultMultivaluesField.js +27 -11
- package/lib/components/MultivaluesField/MultivaluesField.stories.js +12 -4
- package/lib/components/MultivaluesField/MultivaluesField.test.js +0 -4
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/useInputLoader/index.js +1 -0
- package/lib/hooks/useInputLoader/useInputLoader.js +47 -0
- package/package.json +1 -1
@@ -15,10 +15,8 @@ _Object$defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
16
16
|
});
|
17
17
|
exports["default"] = void 0;
|
18
|
-
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
19
18
|
var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/values"));
|
20
19
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
21
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
22
20
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
23
21
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
|
24
22
|
var _react = _interopRequireWildcard(require("react"));
|
@@ -74,41 +72,11 @@ var ComboBoxInput = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
74
72
|
var _useHover = (0, _interactions.useHover)({}),
|
75
73
|
hoverProps = _useHover.hoverProps,
|
76
74
|
isHovered = _useHover.isHovered;
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
showLoading =
|
82
|
-
setShowLoading = _useState2[1];
|
83
|
-
var isLoading = loadingState === _loadingStates["default"].LOADING || loadingState === _loadingStates["default"].FILTERING;
|
84
|
-
var inputValue = inputProps.value;
|
85
|
-
var lastInputValue = (0, _react.useRef)(inputValue);
|
86
|
-
var timeout = (0, _react.useRef)(null);
|
87
|
-
(0, _react.useEffect)(function () {
|
88
|
-
if (isLoading && !showLoading) {
|
89
|
-
if (timeout.current === null) {
|
90
|
-
timeout.current = (0, _setTimeout2["default"])(function () {
|
91
|
-
setShowLoading(true);
|
92
|
-
}, 500);
|
93
|
-
}
|
94
|
-
|
95
|
-
// If user is typing, clear the timer and restart since it is a new request
|
96
|
-
if (inputValue !== lastInputValue.current) {
|
97
|
-
clearTimeout(timeout.current);
|
98
|
-
timeout.current = (0, _setTimeout2["default"])(function () {
|
99
|
-
setShowLoading(true);
|
100
|
-
}, 500);
|
101
|
-
}
|
102
|
-
} else if (!isLoading) {
|
103
|
-
// If loading is no longer happening, clear any timers and hide the loader
|
104
|
-
setShowLoading(false);
|
105
|
-
clearTimeout(timeout.current);
|
106
|
-
timeout.current = null;
|
107
|
-
}
|
108
|
-
lastInputValue.current = inputValue;
|
109
|
-
}, [isLoading, showLoading, inputValue]);
|
110
|
-
// END - minimum delay time for loading indicator = 500ms
|
111
|
-
|
75
|
+
var _useInputLoader = (0, _hooks.useInputLoader)({
|
76
|
+
loadingState: loadingState,
|
77
|
+
inputValue: inputProps.value
|
78
|
+
}),
|
79
|
+
showLoading = _useInputLoader.showLoading;
|
112
80
|
(0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
|
113
81
|
var button = !isReadOnly && (0, _react2.jsx)(_.Box, {
|
114
82
|
isRow: true,
|
@@ -15,9 +15,9 @@ _Object$defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
16
16
|
});
|
17
17
|
exports["default"] = void 0;
|
18
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
18
19
|
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
|
19
20
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
20
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
21
21
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
22
22
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
23
23
|
var _flatMap = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/flat-map"));
|
@@ -30,6 +30,7 @@ var _reactAria = require("react-aria");
|
|
30
30
|
var _MenuDownIcon = _interopRequireDefault(require("@pingux/mdi-react/MenuDownIcon"));
|
31
31
|
var _MenuUpIcon = _interopRequireDefault(require("@pingux/mdi-react/MenuUpIcon"));
|
32
32
|
var _i18n = require("@react-aria/i18n");
|
33
|
+
var _interactions = require("@react-aria/interactions");
|
33
34
|
var _utils = require("@react-aria/utils");
|
34
35
|
var _visuallyHidden = require("@react-aria/visually-hidden");
|
35
36
|
var _list = require("@react-stately/list");
|
@@ -45,7 +46,7 @@ var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
|
|
45
46
|
var _statusProp = require("../../utils/docUtils/statusProp");
|
46
47
|
var _ListBox = _interopRequireDefault(require("../ListBox"));
|
47
48
|
var _react2 = require("@emotion/react");
|
48
|
-
var _excluded = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoSelectAll", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "items", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "selectedKeys", "selectedOptionText", "scrollBoxProps", "status"];
|
49
|
+
var _excluded = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "filter", "hasAutoFocus", "hasNoSelectAll", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isFilteringDisabled", "isNotFlippable", "isReadOnly", "isRequired", "items", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "selectedKeys", "selectedOptionText", "scrollBoxProps", "status"];
|
49
50
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
50
51
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
51
52
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty2(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
@@ -57,12 +58,14 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
57
58
|
_props$disabledKeys = props.disabledKeys,
|
58
59
|
disabledKeys = _props$disabledKeys === void 0 ? [] : _props$disabledKeys,
|
59
60
|
containerProps = props.containerProps,
|
61
|
+
filter = (0, _filter["default"])(props),
|
60
62
|
hasAutoFocus = props.hasAutoFocus,
|
61
63
|
hasNoSelectAll = props.hasNoSelectAll,
|
62
64
|
hasNoStatusIndicator = props.hasNoStatusIndicator,
|
63
65
|
helperText = props.helperText,
|
64
66
|
customInputProps = props.inputProps,
|
65
67
|
isDisabled = props.isDisabled,
|
68
|
+
isFilteringDisabled = props.isFilteringDisabled,
|
66
69
|
isNotFlippable = props.isNotFlippable,
|
67
70
|
isReadOnly = props.isReadOnly,
|
68
71
|
isRequired = props.isRequired,
|
@@ -94,15 +97,27 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
94
97
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
95
98
|
isOpen = _useState4[0],
|
96
99
|
setIsOpen = _useState4[1];
|
97
|
-
var _useState5 = (0, _react.useState)(
|
100
|
+
var _useState5 = (0, _react.useState)(false),
|
98
101
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
99
|
-
|
100
|
-
|
102
|
+
hasFocusWithin = _useState6[0],
|
103
|
+
setFocusWithin = _useState6[1];
|
104
|
+
var _useState7 = (0, _react.useState)(''),
|
105
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
106
|
+
activeDescendant = _useState8[0],
|
107
|
+
setActiveDescendant = _useState8[1];
|
101
108
|
var inputWrapperRef = (0, _react.useRef)();
|
102
109
|
var inputRef = (0, _react.useRef)();
|
103
110
|
var buttonRef = (0, _react.useRef)();
|
111
|
+
var _useFocusWithin = (0, _interactions.useFocusWithin)({
|
112
|
+
onFocusWithinChange: setFocusWithin
|
113
|
+
}),
|
114
|
+
focusWithinProps = _useFocusWithin.focusWithinProps;
|
115
|
+
var _useInputLoader = (0, _hooks.useInputLoader)({
|
116
|
+
loadingState: loadingState,
|
117
|
+
inputValue: filterString
|
118
|
+
}),
|
119
|
+
showLoading = _useInputLoader.showLoading;
|
104
120
|
var toggleItems = function toggleItems(keys) {
|
105
|
-
setFilterString('');
|
106
121
|
if (onSelectionChange) onSelectionChange(keys);
|
107
122
|
};
|
108
123
|
var _useFilter = (0, _i18n.useFilter)({
|
@@ -131,14 +146,17 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
131
146
|
});
|
132
147
|
};
|
133
148
|
var state = (0, _list.useListState)(_objectSpread(_objectSpread({}, props), {}, {
|
134
|
-
filter: filterNodesWithChildren,
|
135
149
|
items: items,
|
136
150
|
onSelectionChange: toggleItems,
|
137
151
|
selectionMode: 'multiple'
|
152
|
+
}, !isFilteringDisabled && {
|
153
|
+
filter: filter || filterNodesWithChildren
|
138
154
|
}));
|
139
155
|
var selectionManager = state.selectionManager;
|
140
156
|
var close = function close() {
|
141
|
-
|
157
|
+
if (!hasFocusWithin) {
|
158
|
+
setIsOpen(false);
|
159
|
+
}
|
142
160
|
};
|
143
161
|
|
144
162
|
/* istanbul ignore next */
|
@@ -177,10 +195,10 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
177
195
|
}, [isOpen, selectionManager.selectedKeys, updatePosition]);
|
178
196
|
|
179
197
|
// Measure the width of the input to inform the width of the menu (below).
|
180
|
-
var
|
181
|
-
|
182
|
-
menuWidth =
|
183
|
-
setMenuWidth =
|
198
|
+
var _useState9 = (0, _react.useState)(null),
|
199
|
+
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
200
|
+
menuWidth = _useState10[0],
|
201
|
+
setMenuWidth = _useState10[1];
|
184
202
|
var onResize = (0, _react.useCallback)(function () {
|
185
203
|
/* istanbul ignore next */
|
186
204
|
if (inputWrapperRef.current) {
|
@@ -217,10 +235,7 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
217
235
|
var key = selectionManager.focusedKey;
|
218
236
|
if (!(0, _includes["default"])(disabledKeys).call(disabledKeys, key)) {
|
219
237
|
selectionManager.toggleSelection(selectionManager.focusedKey);
|
220
|
-
setFilterString('');
|
221
238
|
}
|
222
|
-
} else {
|
223
|
-
setFilterString('');
|
224
239
|
}
|
225
240
|
break;
|
226
241
|
}
|
@@ -239,7 +254,7 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
239
254
|
case 'Escape':
|
240
255
|
{
|
241
256
|
setFilterString('');
|
242
|
-
|
257
|
+
setIsOpen(false);
|
243
258
|
break;
|
244
259
|
}
|
245
260
|
default:
|
@@ -253,12 +268,13 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
253
268
|
if ((_inputWrapperRef$curr = inputWrapperRef.current) !== null && _inputWrapperRef$curr !== void 0 && _inputWrapperRef$curr.contains(relatedTarget) || (_listBoxRef$current = listBoxRef.current) !== null && _listBoxRef$current !== void 0 && _listBoxRef$current.contains(relatedTarget) || buttonRef.current === relatedTarget) {
|
254
269
|
return;
|
255
270
|
}
|
271
|
+
setFilterString('');
|
256
272
|
setIsOpen(false);
|
257
273
|
};
|
258
|
-
var
|
259
|
-
|
260
|
-
selectionState =
|
261
|
-
setSelectionState =
|
274
|
+
var _useState11 = (0, _react.useState)('Select All'),
|
275
|
+
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
276
|
+
selectionState = _useState12[0],
|
277
|
+
setSelectionState = _useState12[1];
|
262
278
|
var arrayItems = (0, _from["default"])(items);
|
263
279
|
var itemCount = (0, _reduce["default"])(arrayItems).call(arrayItems, function (count, obj) {
|
264
280
|
return count + (obj.children ? obj.children.length : 1);
|
@@ -309,10 +325,7 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
309
325
|
loadingState: loadingState,
|
310
326
|
isLoading: loadingState === _loadingStates["default"].LOADING_MORE,
|
311
327
|
"aria-label": "List of options",
|
312
|
-
isCondensed: mode === 'condensed'
|
313
|
-
onBlur: function onBlur(e) {
|
314
|
-
return handleBlur(e);
|
315
|
-
}
|
328
|
+
isCondensed: mode === 'condensed'
|
316
329
|
}, overlayProps))), (0, _react2.jsx)(_reactAria.DismissButton, {
|
317
330
|
onDismiss: close
|
318
331
|
}));
|
@@ -361,10 +374,17 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
361
374
|
setIsOpen(true);
|
362
375
|
inputRef.current.focus();
|
363
376
|
} else {
|
364
|
-
|
377
|
+
setIsOpen(false);
|
365
378
|
}
|
366
379
|
};
|
367
380
|
var button = (0, _react2.jsx)(_.Box, {
|
381
|
+
isRow: true,
|
382
|
+
variant: "forms.comboBox.inputInContainerSlot"
|
383
|
+
},
|
384
|
+
// Render loader after delay if filtering or loading
|
385
|
+
showLoading && (isOpen || loadingState === _loadingStates["default"].LOADING) && (0, _react2.jsx)(_.Loader, {
|
386
|
+
variant: "loader.withinInput"
|
387
|
+
}), (0, _react2.jsx)(_.Box, {
|
368
388
|
as: "button",
|
369
389
|
variant: "forms.comboBox.button",
|
370
390
|
tabIndex: -1,
|
@@ -377,10 +397,10 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
377
397
|
title: {
|
378
398
|
name: isOpen ? 'Menu Up Icon' : 'Menu Down Icon'
|
379
399
|
}
|
380
|
-
}));
|
400
|
+
})));
|
381
401
|
return (0, _react2.jsx)(_MultivaluesContext.MultivaluesContext.Provider, {
|
382
402
|
value: setActiveDescendant
|
383
|
-
}, (0, _react2.jsx)(_.Box, containerProps, (0, _react2.jsx)(_.TextField, (0, _extends2["default"])({
|
403
|
+
}, (0, _react2.jsx)(_.Box, (0, _reactAria.mergeProps)(containerProps, focusWithinProps), (0, _react2.jsx)(_.TextField, (0, _extends2["default"])({
|
384
404
|
onBlur: function onBlur(e) {
|
385
405
|
var _popoverRef$current;
|
386
406
|
var blurIntoPopover = (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current.contains(e.relatedTarget);
|
@@ -420,7 +440,10 @@ var CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (pr
|
|
420
440
|
onClose: close,
|
421
441
|
placement: placement,
|
422
442
|
ref: popoverRef,
|
423
|
-
style: style
|
443
|
+
style: style,
|
444
|
+
onBlur: function onBlur(e) {
|
445
|
+
return handleBlur(e);
|
446
|
+
}
|
424
447
|
}, listbox), (0, _react2.jsx)(EmptyVisuallyHidden, null)));
|
425
448
|
});
|
426
449
|
CondensedMultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
@@ -48,7 +48,7 @@ var _statusProp = require("../../utils/docUtils/statusProp");
|
|
48
48
|
var _ListBox = _interopRequireDefault(require("../ListBox"));
|
49
49
|
var _react2 = require("@emotion/react");
|
50
50
|
var _excluded = ["items"],
|
51
|
-
_excluded2 = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
51
|
+
_excluded2 = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isFilteringDisabled", "isNotFlippable", "isReadOnly", "isRequired", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
52
52
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
53
53
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
54
54
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty2(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
@@ -67,6 +67,7 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
67
67
|
helperText = otherProps.helperText,
|
68
68
|
customInputProps = otherProps.inputProps,
|
69
69
|
isDisabled = otherProps.isDisabled,
|
70
|
+
isFilteringDisabled = otherProps.isFilteringDisabled,
|
70
71
|
isNotFlippable = otherProps.isNotFlippable,
|
71
72
|
isReadOnly = otherProps.isReadOnly,
|
72
73
|
isRequired = otherProps.isRequired,
|
@@ -121,26 +122,28 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
121
122
|
var _context;
|
122
123
|
return !(0, _includes["default"])(_context = (0, _from["default"])(keys)).call(_context, item.key);
|
123
124
|
}));
|
124
|
-
setFilterString('');
|
125
125
|
if (onSelectionChange) onSelectionChange(keys);
|
126
126
|
};
|
127
127
|
var _useFilter = (0, _i18n.useFilter)({
|
128
128
|
sensitivity: 'base'
|
129
129
|
}),
|
130
130
|
contains = _useFilter.contains;
|
131
|
+
var defaultFilter = function defaultFilter(nodes) {
|
132
|
+
var _context2;
|
133
|
+
var arr = (0, _filter["default"])(_context2 = (0, _from["default"])(nodes)).call(_context2, function (item) {
|
134
|
+
return contains(item.textValue, filterString);
|
135
|
+
});
|
136
|
+
return arr;
|
137
|
+
};
|
131
138
|
var state = (0, _list.useListState)(_objectSpread(_objectSpread({}, otherProps), {}, {
|
132
|
-
filter: function filter(nodes) {
|
133
|
-
var _context2;
|
134
|
-
return (0, _filter["default"])(_context2 = (0, _from["default"])(nodes)).call(_context2, function (item) {
|
135
|
-
return contains(item.textValue, filterString);
|
136
|
-
});
|
137
|
-
},
|
138
139
|
items: (0, _filter["default"])(items).call(items, function (_ref) {
|
139
140
|
var key = _ref.key;
|
140
141
|
return !(0, _includes["default"])(readOnlyKeys).call(readOnlyKeys, key);
|
141
142
|
}),
|
142
143
|
onSelectionChange: toggleItems,
|
143
144
|
selectionMode: 'multiple'
|
145
|
+
}, !isFilteringDisabled && {
|
146
|
+
filter: defaultFilter
|
144
147
|
}));
|
145
148
|
var selectionManager = state.selectionManager;
|
146
149
|
var filteredItems = (0, _react.useMemo)(function () {
|
@@ -149,6 +152,11 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
149
152
|
var close = function close() {
|
150
153
|
return setIsOpen(false);
|
151
154
|
};
|
155
|
+
var _useInputLoader = (0, _hooks.useInputLoader)({
|
156
|
+
loadingState: loadingState,
|
157
|
+
inputValue: filterString
|
158
|
+
}),
|
159
|
+
showLoading = _useInputLoader.showLoading;
|
152
160
|
var closeBadgeRefs = (0, _react.useRef)([]);
|
153
161
|
var inputWrapperRef = (0, _react.useRef)();
|
154
162
|
var inputRef = (0, _react.useRef)();
|
@@ -280,7 +288,6 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
280
288
|
var key = selectionManager.focusedKey;
|
281
289
|
if (!(0, _includes["default"])(disabledKeys).call(disabledKeys, key)) {
|
282
290
|
selectionManager.toggleSelection(selectionManager.focusedKey);
|
283
|
-
setFilterString('');
|
284
291
|
}
|
285
292
|
} else if (hasCustomValue && !selectionManager.focusedKey) {
|
286
293
|
var _key = e.target.value;
|
@@ -497,6 +504,14 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
497
504
|
},
|
498
505
|
status: status
|
499
506
|
});
|
507
|
+
var loader = (0, _react2.jsx)(_.Box, {
|
508
|
+
isRow: true,
|
509
|
+
variant: "forms.comboBox.inputInContainerSlot"
|
510
|
+
},
|
511
|
+
// Render loader after delay if filtering or loading
|
512
|
+
showLoading && loadingState === _loadingStates["default"].LOADING && (0, _react2.jsx)(_.Loader, {
|
513
|
+
variant: "loader.withinInput"
|
514
|
+
}));
|
500
515
|
return (0, _react2.jsx)(_MultivaluesContext.MultivaluesContext.Provider, {
|
501
516
|
value: setActiveDescendant
|
502
517
|
}, (0, _react2.jsx)(_.Box, containerProps, (0, _react2.jsx)(_.TextField, (0, _extends2["default"])({
|
@@ -518,6 +533,7 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
518
533
|
},
|
519
534
|
"aria-describedby": selectionManager.selectedKeys.size > 0 ? 'selectedKeysState' : 'emptyKeysState',
|
520
535
|
slots: {
|
536
|
+
inContainer: loader,
|
521
537
|
beforeInput: (0, _react2.jsx)(_react["default"].Fragment, null, readOnlyItems && (0, _react2.jsx)(_.Box, {
|
522
538
|
as: "ul",
|
523
539
|
isRow: true,
|
@@ -24,8 +24,8 @@ _Object$defineProperty(exports, "__esModule", {
|
|
24
24
|
exports["default"] = exports.Uncontrolled = exports.ReadOnlyValues = exports.ReadOnlyField = exports.OnLoadPrev = exports.IconSlotsInBadge = exports.Error = exports.DisabledKeys = exports.Default = exports.CustomValues = exports.CustomSize = exports.Controlled = exports.CondensedWithSection = exports.CondensedWithCustomText = exports.CondensedAsyncLoading = exports.Condensed = void 0;
|
25
25
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
26
26
|
var _fill = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/fill"));
|
27
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
28
27
|
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
28
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
29
29
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
30
30
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
31
31
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
@@ -695,13 +695,21 @@ var CondensedAsyncLoading = function CondensedAsyncLoading(args) {
|
|
695
695
|
_useState30 = (0, _slicedToArray2["default"])(_useState29, 2),
|
696
696
|
isOpen = _useState30[0],
|
697
697
|
setIsOpen = _useState30[1];
|
698
|
-
var _useState31 = (0, _react.useState)(_loadingStates["default"].
|
698
|
+
var _useState31 = (0, _react.useState)(_loadingStates["default"].LOADING),
|
699
699
|
_useState32 = (0, _slicedToArray2["default"])(_useState31, 2),
|
700
700
|
loadingState = _useState32[0],
|
701
701
|
setLoadingState = _useState32[1];
|
702
702
|
var onOpenChange = function onOpenChange() {
|
703
703
|
setIsOpen(true);
|
704
704
|
};
|
705
|
+
(0, _react.useEffect)(function () {
|
706
|
+
var timer = (0, _setTimeout2["default"])(function () {
|
707
|
+
setLoadingState(_loadingStates["default"].IDLE);
|
708
|
+
}, 3000);
|
709
|
+
return function () {
|
710
|
+
return clearTimeout(timer);
|
711
|
+
}; // Cleanup the timer on unmount
|
712
|
+
}, []);
|
705
713
|
var onLoadMore = /*#__PURE__*/function () {
|
706
714
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
707
715
|
var _context3, _context4, _context5;
|
@@ -712,7 +720,7 @@ var CondensedAsyncLoading = function CondensedAsyncLoading(args) {
|
|
712
720
|
setLoadingState(_loadingStates["default"].LOADING_MORE);
|
713
721
|
_context6.next = 3;
|
714
722
|
return new _promise["default"](function (resolve) {
|
715
|
-
return (0, _setTimeout2["default"])(resolve,
|
723
|
+
return (0, _setTimeout2["default"])(resolve, 5000);
|
716
724
|
});
|
717
725
|
case 3:
|
718
726
|
newItems = (0, _map["default"])(_context3 = (0, _fill["default"])(_context4 = new Array(10)).call(_context4, {
|
@@ -1179,10 +1179,6 @@ test('list and button are keyboard accessible', function () {
|
|
1179
1179
|
skipClick: true
|
1180
1180
|
});
|
1181
1181
|
expect(secondOption).toHaveFocus();
|
1182
|
-
_userEvent["default"].type(secondOption, '{esc}', {
|
1183
|
-
skipClick: true
|
1184
|
-
});
|
1185
|
-
expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
|
1186
1182
|
});
|
1187
1183
|
test('popover closes on input blur', function () {
|
1188
1184
|
getComponent({
|
package/lib/cjs/hooks/index.d.ts
CHANGED
@@ -8,6 +8,7 @@ export { default as useDevelopmentWarning } from './useDevelopmentWarning';
|
|
8
8
|
export { default as useFallbackImage } from './useFallbackImage';
|
9
9
|
export { default as useField } from './useField';
|
10
10
|
export { default as useGetTheme } from './useGetTheme';
|
11
|
+
export { default as useInputLoader } from './useInputLoader';
|
11
12
|
export { default as useLabelHeight } from './useLabelHeight';
|
12
13
|
export { default as useLocalOrForwardRef } from './useLocalOrForwardRef';
|
13
14
|
export { default as useModalState } from './useModalState';
|
package/lib/cjs/hooks/index.js
CHANGED
@@ -65,6 +65,12 @@ _Object$defineProperty(exports, "useGetTheme", {
|
|
65
65
|
return _useGetTheme["default"];
|
66
66
|
}
|
67
67
|
});
|
68
|
+
_Object$defineProperty(exports, "useInputLoader", {
|
69
|
+
enumerable: true,
|
70
|
+
get: function get() {
|
71
|
+
return _useInputLoader["default"];
|
72
|
+
}
|
73
|
+
});
|
68
74
|
_Object$defineProperty(exports, "useLabelHeight", {
|
69
75
|
enumerable: true,
|
70
76
|
get: function get() {
|
@@ -171,6 +177,7 @@ var _useDevelopmentWarning = _interopRequireDefault(require("./useDevelopmentWar
|
|
171
177
|
var _useFallbackImage = _interopRequireDefault(require("./useFallbackImage"));
|
172
178
|
var _useField = _interopRequireDefault(require("./useField"));
|
173
179
|
var _useGetTheme = _interopRequireDefault(require("./useGetTheme"));
|
180
|
+
var _useInputLoader = _interopRequireDefault(require("./useInputLoader"));
|
174
181
|
var _useLabelHeight = _interopRequireDefault(require("./useLabelHeight"));
|
175
182
|
var _useLocalOrForwardRef = _interopRequireDefault(require("./useLocalOrForwardRef"));
|
176
183
|
var _useModalState = _interopRequireDefault(require("./useModalState"));
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useInputLoader';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
_Object$defineProperty(exports, "default", {
|
9
|
+
enumerable: true,
|
10
|
+
get: function get() {
|
11
|
+
return _useInputLoader["default"];
|
12
|
+
}
|
13
|
+
});
|
14
|
+
var _useInputLoader = _interopRequireDefault(require("./useInputLoader"));
|
@@ -0,0 +1,9 @@
|
|
1
|
+
interface UseInputLoaderProps {
|
2
|
+
loadingState: string;
|
3
|
+
inputValue: string;
|
4
|
+
}
|
5
|
+
interface UseInputLoaderReturn {
|
6
|
+
showLoading: boolean;
|
7
|
+
}
|
8
|
+
declare const useInputLoader: ({ loadingState, inputValue }: UseInputLoaderProps) => UseInputLoaderReturn;
|
9
|
+
export default useInputLoader;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports["default"] = void 0;
|
9
|
+
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
11
|
+
var _react = require("react");
|
12
|
+
var _loadingStates = _interopRequireDefault(require("../../utils/devUtils/constants/loadingStates"));
|
13
|
+
var useInputLoader = function useInputLoader(_ref) {
|
14
|
+
var loadingState = _ref.loadingState,
|
15
|
+
inputValue = _ref.inputValue;
|
16
|
+
// START - minimum delay time for loading indicator = 500ms
|
17
|
+
var _useState = (0, _react.useState)(false),
|
18
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
19
|
+
showLoading = _useState2[0],
|
20
|
+
setShowLoading = _useState2[1];
|
21
|
+
var isLoading = loadingState === _loadingStates["default"].LOADING || loadingState === _loadingStates["default"].FILTERING;
|
22
|
+
var lastInputValue = (0, _react.useRef)(inputValue);
|
23
|
+
var timeout = (0, _react.useRef)(null);
|
24
|
+
(0, _react.useEffect)(function () {
|
25
|
+
if (isLoading && !showLoading) {
|
26
|
+
if (timeout.current === null) {
|
27
|
+
timeout.current = (0, _setTimeout2["default"])(function () {
|
28
|
+
setShowLoading(true);
|
29
|
+
}, 500);
|
30
|
+
}
|
31
|
+
|
32
|
+
// If user is typing, clear the timer and restart since it is a new request
|
33
|
+
if (inputValue !== lastInputValue.current) {
|
34
|
+
clearTimeout(timeout.current);
|
35
|
+
timeout.current = (0, _setTimeout2["default"])(function () {
|
36
|
+
setShowLoading(true);
|
37
|
+
}, 500);
|
38
|
+
}
|
39
|
+
} else if (!isLoading) {
|
40
|
+
// If loading is no longer happening, clear any timers and hide the loader
|
41
|
+
setShowLoading(false);
|
42
|
+
if (timeout.current) {
|
43
|
+
clearTimeout(timeout.current);
|
44
|
+
timeout.current = null;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
lastInputValue.current = inputValue;
|
48
|
+
}, [isLoading, showLoading, inputValue]);
|
49
|
+
return {
|
50
|
+
showLoading: showLoading
|
51
|
+
};
|
52
|
+
// END - minimum delay time for loading indicator = 500ms
|
53
|
+
};
|
54
|
+
var _default = useInputLoader;
|
55
|
+
exports["default"] = _default;
|
@@ -7,20 +7,18 @@ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-st
|
|
7
7
|
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
8
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
13
12
|
var _excluded = ["controlProps", "containerProps", "hasAutoFocus", "isDisabled", "isReadOnly", "isOpen", "loadingState", "style", "inputWrapperRef", "inputRef", "inputProps", "triggerRef", "triggerProps", "menuTrigger", "onInputChange", "onLoadMore", "onOpenChange", "onSelectionChange", "wrapperProps"];
|
14
|
-
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
15
13
|
import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
|
16
14
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
17
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
18
|
-
import React, { forwardRef,
|
16
|
+
import React, { forwardRef, useImperativeHandle } from 'react';
|
19
17
|
import { FocusRing, mergeProps } from 'react-aria';
|
20
18
|
import { PressResponder, useHover } from '@react-aria/interactions';
|
21
19
|
import PropTypes from 'prop-types';
|
22
20
|
import { Box, Button, Icon, Loader, TextField } from '../..';
|
23
|
-
import { usePropWarning } from '../../hooks';
|
21
|
+
import { useInputLoader, usePropWarning } from '../../hooks';
|
24
22
|
import useGetTheme from '../../hooks/useGetTheme';
|
25
23
|
import loadingStates from '../../utils/devUtils/constants/loadingStates';
|
26
24
|
import { ariaAttributesBasePropTypes } from '../../utils/docUtils/ariaAttributes';
|
@@ -63,41 +61,11 @@ var ComboBoxInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
63
61
|
var _useHover = useHover({}),
|
64
62
|
hoverProps = _useHover.hoverProps,
|
65
63
|
isHovered = _useHover.isHovered;
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
showLoading =
|
71
|
-
setShowLoading = _useState2[1];
|
72
|
-
var isLoading = loadingState === loadingStates.LOADING || loadingState === loadingStates.FILTERING;
|
73
|
-
var inputValue = inputProps.value;
|
74
|
-
var lastInputValue = useRef(inputValue);
|
75
|
-
var timeout = useRef(null);
|
76
|
-
useEffect(function () {
|
77
|
-
if (isLoading && !showLoading) {
|
78
|
-
if (timeout.current === null) {
|
79
|
-
timeout.current = _setTimeout(function () {
|
80
|
-
setShowLoading(true);
|
81
|
-
}, 500);
|
82
|
-
}
|
83
|
-
|
84
|
-
// If user is typing, clear the timer and restart since it is a new request
|
85
|
-
if (inputValue !== lastInputValue.current) {
|
86
|
-
clearTimeout(timeout.current);
|
87
|
-
timeout.current = _setTimeout(function () {
|
88
|
-
setShowLoading(true);
|
89
|
-
}, 500);
|
90
|
-
}
|
91
|
-
} else if (!isLoading) {
|
92
|
-
// If loading is no longer happening, clear any timers and hide the loader
|
93
|
-
setShowLoading(false);
|
94
|
-
clearTimeout(timeout.current);
|
95
|
-
timeout.current = null;
|
96
|
-
}
|
97
|
-
lastInputValue.current = inputValue;
|
98
|
-
}, [isLoading, showLoading, inputValue]);
|
99
|
-
// END - minimum delay time for loading indicator = 500ms
|
100
|
-
|
64
|
+
var _useInputLoader = useInputLoader({
|
65
|
+
loadingState: loadingState,
|
66
|
+
inputValue: inputProps.value
|
67
|
+
}),
|
68
|
+
showLoading = _useInputLoader.showLoading;
|
101
69
|
usePropWarning(props, 'disabled', 'isDisabled');
|
102
70
|
var button = !isReadOnly && ___EmotionJSX(Box, {
|
103
71
|
isRow: true,
|
@@ -9,27 +9,28 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoSelectAll", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "items", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "selectedKeys", "selectedOptionText", "scrollBoxProps", "status"];
|
12
|
+
var _excluded = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "filter", "hasAutoFocus", "hasNoSelectAll", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isFilteringDisabled", "isNotFlippable", "isReadOnly", "isRequired", "items", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "selectedKeys", "selectedOptionText", "scrollBoxProps", "status"];
|
13
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
15
16
|
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
16
17
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
17
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
18
18
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
19
19
|
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
20
20
|
import _flatMapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/flat-map";
|
21
21
|
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
22
|
-
import { DismissButton, FocusScope, useOverlayPosition } from 'react-aria';
|
22
|
+
import { DismissButton, FocusScope, mergeProps, useOverlayPosition } from 'react-aria';
|
23
23
|
import MenuDown from '@pingux/mdi-react/MenuDownIcon';
|
24
24
|
import MenuUp from '@pingux/mdi-react/MenuUpIcon';
|
25
25
|
import { useFilter } from '@react-aria/i18n';
|
26
|
+
import { useFocusWithin } from '@react-aria/interactions';
|
26
27
|
import { useLayoutEffect, useResizeObserver } from '@react-aria/utils';
|
27
28
|
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
28
29
|
import { useListState } from '@react-stately/list';
|
29
30
|
import PropTypes from 'prop-types';
|
30
|
-
import { Box, Button, Icon, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
31
|
+
import { Box, Button, Icon, Loader, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
31
32
|
import { MultivaluesContext } from '../../context/MultivaluesContext';
|
32
|
-
import { usePropWarning } from '../../hooks';
|
33
|
+
import { useInputLoader, usePropWarning } from '../../hooks';
|
33
34
|
import loadingStates from '../../utils/devUtils/constants/loadingStates';
|
34
35
|
import { getPendoID } from '../../utils/devUtils/constants/pendoID';
|
35
36
|
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
@@ -45,12 +46,14 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
45
46
|
_props$disabledKeys = props.disabledKeys,
|
46
47
|
disabledKeys = _props$disabledKeys === void 0 ? [] : _props$disabledKeys,
|
47
48
|
containerProps = props.containerProps,
|
49
|
+
filter = _filterInstanceProperty(props),
|
48
50
|
hasAutoFocus = props.hasAutoFocus,
|
49
51
|
hasNoSelectAll = props.hasNoSelectAll,
|
50
52
|
hasNoStatusIndicator = props.hasNoStatusIndicator,
|
51
53
|
helperText = props.helperText,
|
52
54
|
customInputProps = props.inputProps,
|
53
55
|
isDisabled = props.isDisabled,
|
56
|
+
isFilteringDisabled = props.isFilteringDisabled,
|
54
57
|
isNotFlippable = props.isNotFlippable,
|
55
58
|
isReadOnly = props.isReadOnly,
|
56
59
|
isRequired = props.isRequired,
|
@@ -82,15 +85,27 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
82
85
|
_useState4 = _slicedToArray(_useState3, 2),
|
83
86
|
isOpen = _useState4[0],
|
84
87
|
setIsOpen = _useState4[1];
|
85
|
-
var _useState5 = useState(
|
88
|
+
var _useState5 = useState(false),
|
86
89
|
_useState6 = _slicedToArray(_useState5, 2),
|
87
|
-
|
88
|
-
|
90
|
+
hasFocusWithin = _useState6[0],
|
91
|
+
setFocusWithin = _useState6[1];
|
92
|
+
var _useState7 = useState(''),
|
93
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
94
|
+
activeDescendant = _useState8[0],
|
95
|
+
setActiveDescendant = _useState8[1];
|
89
96
|
var inputWrapperRef = useRef();
|
90
97
|
var inputRef = useRef();
|
91
98
|
var buttonRef = useRef();
|
99
|
+
var _useFocusWithin = useFocusWithin({
|
100
|
+
onFocusWithinChange: setFocusWithin
|
101
|
+
}),
|
102
|
+
focusWithinProps = _useFocusWithin.focusWithinProps;
|
103
|
+
var _useInputLoader = useInputLoader({
|
104
|
+
loadingState: loadingState,
|
105
|
+
inputValue: filterString
|
106
|
+
}),
|
107
|
+
showLoading = _useInputLoader.showLoading;
|
92
108
|
var toggleItems = function toggleItems(keys) {
|
93
|
-
setFilterString('');
|
94
109
|
if (onSelectionChange) onSelectionChange(keys);
|
95
110
|
};
|
96
111
|
var _useFilter = useFilter({
|
@@ -119,14 +134,17 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
119
134
|
});
|
120
135
|
};
|
121
136
|
var state = useListState(_objectSpread(_objectSpread({}, props), {}, {
|
122
|
-
filter: filterNodesWithChildren,
|
123
137
|
items: items,
|
124
138
|
onSelectionChange: toggleItems,
|
125
139
|
selectionMode: 'multiple'
|
140
|
+
}, !isFilteringDisabled && {
|
141
|
+
filter: filter || filterNodesWithChildren
|
126
142
|
}));
|
127
143
|
var selectionManager = state.selectionManager;
|
128
144
|
var close = function close() {
|
129
|
-
|
145
|
+
if (!hasFocusWithin) {
|
146
|
+
setIsOpen(false);
|
147
|
+
}
|
130
148
|
};
|
131
149
|
|
132
150
|
/* istanbul ignore next */
|
@@ -165,10 +183,10 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
165
183
|
}, [isOpen, selectionManager.selectedKeys, updatePosition]);
|
166
184
|
|
167
185
|
// Measure the width of the input to inform the width of the menu (below).
|
168
|
-
var
|
169
|
-
|
170
|
-
menuWidth =
|
171
|
-
setMenuWidth =
|
186
|
+
var _useState9 = useState(null),
|
187
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
188
|
+
menuWidth = _useState10[0],
|
189
|
+
setMenuWidth = _useState10[1];
|
172
190
|
var onResize = useCallback(function () {
|
173
191
|
/* istanbul ignore next */
|
174
192
|
if (inputWrapperRef.current) {
|
@@ -205,10 +223,7 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
205
223
|
var key = selectionManager.focusedKey;
|
206
224
|
if (!_includesInstanceProperty(disabledKeys).call(disabledKeys, key)) {
|
207
225
|
selectionManager.toggleSelection(selectionManager.focusedKey);
|
208
|
-
setFilterString('');
|
209
226
|
}
|
210
|
-
} else {
|
211
|
-
setFilterString('');
|
212
227
|
}
|
213
228
|
break;
|
214
229
|
}
|
@@ -227,7 +242,7 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
227
242
|
case 'Escape':
|
228
243
|
{
|
229
244
|
setFilterString('');
|
230
|
-
|
245
|
+
setIsOpen(false);
|
231
246
|
break;
|
232
247
|
}
|
233
248
|
default:
|
@@ -241,12 +256,13 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
241
256
|
if ((_inputWrapperRef$curr = inputWrapperRef.current) !== null && _inputWrapperRef$curr !== void 0 && _inputWrapperRef$curr.contains(relatedTarget) || (_listBoxRef$current = listBoxRef.current) !== null && _listBoxRef$current !== void 0 && _listBoxRef$current.contains(relatedTarget) || buttonRef.current === relatedTarget) {
|
242
257
|
return;
|
243
258
|
}
|
259
|
+
setFilterString('');
|
244
260
|
setIsOpen(false);
|
245
261
|
};
|
246
|
-
var
|
247
|
-
|
248
|
-
selectionState =
|
249
|
-
setSelectionState =
|
262
|
+
var _useState11 = useState('Select All'),
|
263
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
264
|
+
selectionState = _useState12[0],
|
265
|
+
setSelectionState = _useState12[1];
|
250
266
|
var arrayItems = _Array$from(items);
|
251
267
|
var itemCount = _reduceInstanceProperty(arrayItems).call(arrayItems, function (count, obj) {
|
252
268
|
return count + (obj.children ? obj.children.length : 1);
|
@@ -297,10 +313,7 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
297
313
|
loadingState: loadingState,
|
298
314
|
isLoading: loadingState === loadingStates.LOADING_MORE,
|
299
315
|
"aria-label": "List of options",
|
300
|
-
isCondensed: mode === 'condensed'
|
301
|
-
onBlur: function onBlur(e) {
|
302
|
-
return handleBlur(e);
|
303
|
-
}
|
316
|
+
isCondensed: mode === 'condensed'
|
304
317
|
}, overlayProps))), ___EmotionJSX(DismissButton, {
|
305
318
|
onDismiss: close
|
306
319
|
}));
|
@@ -349,10 +362,17 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
349
362
|
setIsOpen(true);
|
350
363
|
inputRef.current.focus();
|
351
364
|
} else {
|
352
|
-
|
365
|
+
setIsOpen(false);
|
353
366
|
}
|
354
367
|
};
|
355
368
|
var button = ___EmotionJSX(Box, {
|
369
|
+
isRow: true,
|
370
|
+
variant: "forms.comboBox.inputInContainerSlot"
|
371
|
+
},
|
372
|
+
// Render loader after delay if filtering or loading
|
373
|
+
showLoading && (isOpen || loadingState === loadingStates.LOADING) && ___EmotionJSX(Loader, {
|
374
|
+
variant: "loader.withinInput"
|
375
|
+
}), ___EmotionJSX(Box, {
|
356
376
|
as: "button",
|
357
377
|
variant: "forms.comboBox.button",
|
358
378
|
tabIndex: -1,
|
@@ -365,10 +385,10 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
365
385
|
title: {
|
366
386
|
name: isOpen ? 'Menu Up Icon' : 'Menu Down Icon'
|
367
387
|
}
|
368
|
-
}));
|
388
|
+
})));
|
369
389
|
return ___EmotionJSX(MultivaluesContext.Provider, {
|
370
390
|
value: setActiveDescendant
|
371
|
-
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
391
|
+
}, ___EmotionJSX(Box, mergeProps(containerProps, focusWithinProps), ___EmotionJSX(TextField, _extends({
|
372
392
|
onBlur: function onBlur(e) {
|
373
393
|
var _popoverRef$current;
|
374
394
|
var blurIntoPopover = (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current.contains(e.relatedTarget);
|
@@ -408,7 +428,10 @@ var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
408
428
|
onClose: close,
|
409
429
|
placement: placement,
|
410
430
|
ref: popoverRef,
|
411
|
-
style: style
|
431
|
+
style: style,
|
432
|
+
onBlur: function onBlur(e) {
|
433
|
+
return handleBlur(e);
|
434
|
+
}
|
412
435
|
}, listbox), ___EmotionJSX(EmptyVisuallyHidden, null)));
|
413
436
|
});
|
414
437
|
CondensedMultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
@@ -10,7 +10,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
10
10
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
12
|
var _excluded = ["items"],
|
13
|
-
_excluded2 = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
13
|
+
_excluded2 = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isFilteringDisabled", "isNotFlippable", "isReadOnly", "isRequired", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
14
14
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
15
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context13, _context14; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context13 = ownKeys(Object(source), !0)).call(_context13, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context14 = ownKeys(Object(source))).call(_context14, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
16
16
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
@@ -30,9 +30,9 @@ import { useLayoutEffect, useResizeObserver } from '@react-aria/utils';
|
|
30
30
|
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
31
31
|
import { useListState } from '@react-stately/list';
|
32
32
|
import PropTypes from 'prop-types';
|
33
|
-
import { Badge, Box, Icon, IconButton, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
33
|
+
import { Badge, Box, Icon, IconButton, Loader, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
34
34
|
import { MultivaluesContext } from '../../context/MultivaluesContext';
|
35
|
-
import { usePropWarning } from '../../hooks';
|
35
|
+
import { useInputLoader, usePropWarning } from '../../hooks';
|
36
36
|
import loadingStates from '../../utils/devUtils/constants/loadingStates';
|
37
37
|
import { getPendoID } from '../../utils/devUtils/constants/pendoID';
|
38
38
|
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
@@ -55,6 +55,7 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
55
55
|
helperText = otherProps.helperText,
|
56
56
|
customInputProps = otherProps.inputProps,
|
57
57
|
isDisabled = otherProps.isDisabled,
|
58
|
+
isFilteringDisabled = otherProps.isFilteringDisabled,
|
58
59
|
isNotFlippable = otherProps.isNotFlippable,
|
59
60
|
isReadOnly = otherProps.isReadOnly,
|
60
61
|
isRequired = otherProps.isRequired,
|
@@ -109,26 +110,28 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
109
110
|
var _context;
|
110
111
|
return !_includesInstanceProperty(_context = _Array$from(keys)).call(_context, item.key);
|
111
112
|
}));
|
112
|
-
setFilterString('');
|
113
113
|
if (onSelectionChange) onSelectionChange(keys);
|
114
114
|
};
|
115
115
|
var _useFilter = useFilter({
|
116
116
|
sensitivity: 'base'
|
117
117
|
}),
|
118
118
|
contains = _useFilter.contains;
|
119
|
+
var defaultFilter = function defaultFilter(nodes) {
|
120
|
+
var _context2;
|
121
|
+
var arr = _filterInstanceProperty(_context2 = _Array$from(nodes)).call(_context2, function (item) {
|
122
|
+
return contains(item.textValue, filterString);
|
123
|
+
});
|
124
|
+
return arr;
|
125
|
+
};
|
119
126
|
var state = useListState(_objectSpread(_objectSpread({}, otherProps), {}, {
|
120
|
-
filter: function filter(nodes) {
|
121
|
-
var _context2;
|
122
|
-
return _filterInstanceProperty(_context2 = _Array$from(nodes)).call(_context2, function (item) {
|
123
|
-
return contains(item.textValue, filterString);
|
124
|
-
});
|
125
|
-
},
|
126
127
|
items: _filterInstanceProperty(items).call(items, function (_ref) {
|
127
128
|
var key = _ref.key;
|
128
129
|
return !_includesInstanceProperty(readOnlyKeys).call(readOnlyKeys, key);
|
129
130
|
}),
|
130
131
|
onSelectionChange: toggleItems,
|
131
132
|
selectionMode: 'multiple'
|
133
|
+
}, !isFilteringDisabled && {
|
134
|
+
filter: defaultFilter
|
132
135
|
}));
|
133
136
|
var selectionManager = state.selectionManager;
|
134
137
|
var filteredItems = useMemo(function () {
|
@@ -137,6 +140,11 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
137
140
|
var close = function close() {
|
138
141
|
return setIsOpen(false);
|
139
142
|
};
|
143
|
+
var _useInputLoader = useInputLoader({
|
144
|
+
loadingState: loadingState,
|
145
|
+
inputValue: filterString
|
146
|
+
}),
|
147
|
+
showLoading = _useInputLoader.showLoading;
|
140
148
|
var closeBadgeRefs = useRef([]);
|
141
149
|
var inputWrapperRef = useRef();
|
142
150
|
var inputRef = useRef();
|
@@ -268,7 +276,6 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
268
276
|
var key = selectionManager.focusedKey;
|
269
277
|
if (!_includesInstanceProperty(disabledKeys).call(disabledKeys, key)) {
|
270
278
|
selectionManager.toggleSelection(selectionManager.focusedKey);
|
271
|
-
setFilterString('');
|
272
279
|
}
|
273
280
|
} else if (hasCustomValue && !selectionManager.focusedKey) {
|
274
281
|
var _key = e.target.value;
|
@@ -485,6 +492,14 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
485
492
|
},
|
486
493
|
status: status
|
487
494
|
});
|
495
|
+
var loader = ___EmotionJSX(Box, {
|
496
|
+
isRow: true,
|
497
|
+
variant: "forms.comboBox.inputInContainerSlot"
|
498
|
+
},
|
499
|
+
// Render loader after delay if filtering or loading
|
500
|
+
showLoading && loadingState === loadingStates.LOADING && ___EmotionJSX(Loader, {
|
501
|
+
variant: "loader.withinInput"
|
502
|
+
}));
|
488
503
|
return ___EmotionJSX(MultivaluesContext.Provider, {
|
489
504
|
value: setActiveDescendant
|
490
505
|
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
@@ -506,6 +521,7 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
506
521
|
},
|
507
522
|
"aria-describedby": selectionManager.selectedKeys.size > 0 ? 'selectedKeysState' : 'emptyKeysState',
|
508
523
|
slots: {
|
524
|
+
inContainer: loader,
|
509
525
|
beforeInput: ___EmotionJSX(React.Fragment, null, readOnlyItems && ___EmotionJSX(Box, {
|
510
526
|
as: "ul",
|
511
527
|
isRow: true,
|
@@ -20,12 +20,12 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
20
20
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context19; _forEachInstanceProperty(_context19 = ["next", "throw", "return"]).call(_context19, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context20; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context20 = this.tryEntries).call(_context20, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
21
21
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
22
22
|
import _fillInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/fill";
|
23
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
24
23
|
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
24
|
+
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
25
25
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
26
26
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
27
27
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context17, _context18; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context17 = ownKeys(Object(source), !0)).call(_context17, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context18 = ownKeys(Object(source))).call(_context18, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
28
|
-
import React, { useState } from 'react';
|
28
|
+
import React, { useEffect, useState } from 'react';
|
29
29
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
30
30
|
import { Box, Icon, Item, MultivaluesField, OverlayProvider, Section } from '../../index';
|
31
31
|
import loadingStates from '../../utils/devUtils/constants/loadingStates';
|
@@ -673,13 +673,21 @@ export var CondensedAsyncLoading = function CondensedAsyncLoading(args) {
|
|
673
673
|
_useState30 = _slicedToArray(_useState29, 2),
|
674
674
|
isOpen = _useState30[0],
|
675
675
|
setIsOpen = _useState30[1];
|
676
|
-
var _useState31 = useState(loadingStates.
|
676
|
+
var _useState31 = useState(loadingStates.LOADING),
|
677
677
|
_useState32 = _slicedToArray(_useState31, 2),
|
678
678
|
loadingState = _useState32[0],
|
679
679
|
setLoadingState = _useState32[1];
|
680
680
|
var onOpenChange = function onOpenChange() {
|
681
681
|
setIsOpen(true);
|
682
682
|
};
|
683
|
+
useEffect(function () {
|
684
|
+
var timer = _setTimeout(function () {
|
685
|
+
setLoadingState(loadingStates.IDLE);
|
686
|
+
}, 3000);
|
687
|
+
return function () {
|
688
|
+
return clearTimeout(timer);
|
689
|
+
}; // Cleanup the timer on unmount
|
690
|
+
}, []);
|
683
691
|
var onLoadMore = /*#__PURE__*/function () {
|
684
692
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
685
693
|
var _context3, _context4, _context5;
|
@@ -690,7 +698,7 @@ export var CondensedAsyncLoading = function CondensedAsyncLoading(args) {
|
|
690
698
|
setLoadingState(loadingStates.LOADING_MORE);
|
691
699
|
_context6.next = 3;
|
692
700
|
return new _Promise(function (resolve) {
|
693
|
-
return _setTimeout(resolve,
|
701
|
+
return _setTimeout(resolve, 5000);
|
694
702
|
});
|
695
703
|
case 3:
|
696
704
|
newItems = _mapInstanceProperty(_context3 = _fillInstanceProperty(_context4 = new Array(10)).call(_context4, {
|
@@ -1172,10 +1172,6 @@ test('list and button are keyboard accessible', function () {
|
|
1172
1172
|
skipClick: true
|
1173
1173
|
});
|
1174
1174
|
expect(secondOption).toHaveFocus();
|
1175
|
-
userEvent.type(secondOption, '{esc}', {
|
1176
|
-
skipClick: true
|
1177
|
-
});
|
1178
|
-
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
1179
1175
|
});
|
1180
1176
|
test('popover closes on input blur', function () {
|
1181
1177
|
getComponent({
|
package/lib/hooks/index.js
CHANGED
@@ -8,6 +8,7 @@ export { default as useDevelopmentWarning } from './useDevelopmentWarning';
|
|
8
8
|
export { default as useFallbackImage } from './useFallbackImage';
|
9
9
|
export { default as useField } from './useField';
|
10
10
|
export { default as useGetTheme } from './useGetTheme';
|
11
|
+
export { default as useInputLoader } from './useInputLoader';
|
11
12
|
export { default as useLabelHeight } from './useLabelHeight';
|
12
13
|
export { default as useLocalOrForwardRef } from './useLocalOrForwardRef';
|
13
14
|
export { default as useModalState } from './useModalState';
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useInputLoader';
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
2
|
+
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
4
|
+
import loadingStates from '../../utils/devUtils/constants/loadingStates';
|
5
|
+
var useInputLoader = function useInputLoader(_ref) {
|
6
|
+
var loadingState = _ref.loadingState,
|
7
|
+
inputValue = _ref.inputValue;
|
8
|
+
// START - minimum delay time for loading indicator = 500ms
|
9
|
+
var _useState = useState(false),
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
11
|
+
showLoading = _useState2[0],
|
12
|
+
setShowLoading = _useState2[1];
|
13
|
+
var isLoading = loadingState === loadingStates.LOADING || loadingState === loadingStates.FILTERING;
|
14
|
+
var lastInputValue = useRef(inputValue);
|
15
|
+
var timeout = useRef(null);
|
16
|
+
useEffect(function () {
|
17
|
+
if (isLoading && !showLoading) {
|
18
|
+
if (timeout.current === null) {
|
19
|
+
timeout.current = _setTimeout(function () {
|
20
|
+
setShowLoading(true);
|
21
|
+
}, 500);
|
22
|
+
}
|
23
|
+
|
24
|
+
// If user is typing, clear the timer and restart since it is a new request
|
25
|
+
if (inputValue !== lastInputValue.current) {
|
26
|
+
clearTimeout(timeout.current);
|
27
|
+
timeout.current = _setTimeout(function () {
|
28
|
+
setShowLoading(true);
|
29
|
+
}, 500);
|
30
|
+
}
|
31
|
+
} else if (!isLoading) {
|
32
|
+
// If loading is no longer happening, clear any timers and hide the loader
|
33
|
+
setShowLoading(false);
|
34
|
+
if (timeout.current) {
|
35
|
+
clearTimeout(timeout.current);
|
36
|
+
timeout.current = null;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
lastInputValue.current = inputValue;
|
40
|
+
}, [isLoading, showLoading, inputValue]);
|
41
|
+
return {
|
42
|
+
showLoading: showLoading
|
43
|
+
};
|
44
|
+
// END - minimum delay time for loading indicator = 500ms
|
45
|
+
};
|
46
|
+
|
47
|
+
export default useInputLoader;
|