downshift 9.0.12 → 9.1.0-alpha.0
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/LICENSE +20 -20
- package/README.md +1533 -1533
- package/dist/downshift.cjs.js +960 -548
- package/dist/downshift.esm.js +938 -545
- package/dist/downshift.native.cjs.js +960 -541
- package/dist/downshift.nativeweb.cjs.js +960 -548
- package/dist/downshift.umd.js +963 -583
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/reducer.d.ts +1 -0
- package/dist/hooks/useCombobox/index.d.ts +76 -0
- package/dist/hooks/useCombobox/reducer.d.ts +1 -0
- package/dist/hooks/useCombobox/stateChangeTypes.d.ts +23 -0
- package/dist/hooks/useCombobox/utils.d.ts +71 -0
- package/dist/hooks/useMultipleSelection/index.d.ts +30 -0
- package/dist/hooks/useMultipleSelection/reducer.d.ts +1 -0
- package/dist/hooks/useMultipleSelection/stateChangeTypes.d.ts +13 -0
- package/dist/hooks/useMultipleSelection/utils.d.ts +45 -0
- package/dist/hooks/useSelect/index.d.ts +56 -0
- package/dist/hooks/useSelect/reducer.d.ts +1 -0
- package/dist/hooks/useSelect/stateChangeTypes.d.ts +22 -0
- package/dist/hooks/useSelect/utils/defaultProps.d.ts +8 -0
- package/dist/hooks/useSelect/utils/getItemIndexByCharacterKey.d.ts +2 -0
- package/dist/hooks/useSelect/utils/index.d.ts +3 -0
- package/dist/hooks/useSelect/utils/propTypes.d.ts +38 -0
- package/dist/hooks/useTagGroup/__tests__/getTagGroupProps.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/__tests__/getTagProps.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/__tests__/getTagRemoveProps.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/__tests__/props.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/__tests__/reducer.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/__tests__/returnProps.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/__tests__/utils/defaultIds.d.ts +4 -0
- package/dist/hooks/useTagGroup/__tests__/utils/defaultProps.d.ts +4 -0
- package/dist/hooks/useTagGroup/__tests__/utils/index.d.ts +5 -0
- package/dist/hooks/useTagGroup/__tests__/utils/renderTagGroup.d.ts +64 -0
- package/dist/hooks/useTagGroup/__tests__/utils/renderUseTagGroup.d.ts +2 -0
- package/dist/hooks/useTagGroup/index.d.ts +3 -0
- package/dist/hooks/useTagGroup/index.types.d.ts +111 -0
- package/dist/hooks/useTagGroup/reducer.d.ts +2 -0
- package/dist/hooks/useTagGroup/stateChangeTypes.d.ts +8 -0
- package/dist/hooks/useTagGroup/utils/__tests__/useAccessibleDescription.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/utils/__tests__/utils.use-element-ids.r18.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/utils/__tests__/utils.use-element-ids.test.d.ts +1 -0
- package/dist/hooks/useTagGroup/utils/getInitialState.d.ts +2 -0
- package/dist/hooks/useTagGroup/utils/getMergedProps.d.ts +2 -0
- package/dist/hooks/useTagGroup/utils/index.d.ts +7 -0
- package/dist/hooks/useTagGroup/utils/isStateEqual.d.ts +2 -0
- package/dist/hooks/useTagGroup/utils/useAccessibleDescription.d.ts +2 -0
- package/dist/hooks/useTagGroup/utils/useElementIds.d.ts +4 -0
- package/dist/hooks/utils-ts/__tests__/getItemAndIndex.test.d.ts +1 -0
- package/dist/hooks/utils-ts/callOnChangeProps.d.ts +2 -0
- package/dist/hooks/utils-ts/capitalizeString.d.ts +1 -0
- package/dist/hooks/utils-ts/getDefaultValue.d.ts +2 -0
- package/dist/hooks/utils-ts/getInitialValue.d.ts +2 -0
- package/dist/hooks/utils-ts/getItemAndIndex.d.ts +10 -0
- package/dist/hooks/utils-ts/index.d.ts +11 -0
- package/dist/hooks/utils-ts/propTypes.d.ts +16 -0
- package/dist/hooks/utils-ts/stateReducer.d.ts +6 -0
- package/dist/hooks/utils-ts/useA11yMessageStatus.d.ts +10 -0
- package/dist/hooks/utils-ts/useControlledReducer.d.ts +12 -0
- package/dist/hooks/utils-ts/useEnhancedReducer.d.ts +13 -0
- package/dist/hooks/utils-ts/useIsInitialMount.d.ts +4 -0
- package/dist/hooks/utils.d.ts +85 -0
- package/dist/hooks/utils.dropdown/defaultProps.d.ts +9 -0
- package/dist/hooks/utils.dropdown/defaultStateValues.d.ts +6 -0
- package/dist/hooks/utils.dropdown/index.d.ts +3 -0
- package/dist/hooks/utils.dropdown/propTypes.d.ts +36 -0
- package/dist/utils-ts/__tests__/getState.test.d.ts +1 -0
- package/dist/utils-ts/__tests__/handleRefs.test.d.ts +1 -0
- package/dist/utils-ts/callAllEventHandlers.d.ts +13 -0
- package/dist/utils-ts/debounce.d.ts +8 -0
- package/dist/utils-ts/generateId.d.ts +14 -0
- package/dist/utils-ts/getState.d.ts +22 -0
- package/dist/utils-ts/handleRefs.d.ts +2 -0
- package/dist/utils-ts/index.d.ts +11 -0
- package/dist/utils-ts/noop.d.ts +1 -0
- package/dist/utils-ts/scrollIntoView.d.ts +6 -0
- package/dist/utils-ts/setA11yStatus.d.ts +8 -0
- package/dist/utils-ts/useLatestRef.d.ts +2 -0
- package/dist/utils-ts/validatePropTypes.d.ts +2 -0
- package/dist/{src/utils.d.ts → utils.d.ts} +2 -34
- package/flow-typed/npm/downshift_v2.x.x.js.flow +248 -248
- package/package.json +218 -214
- package/preact/dist/dist/hooks/index.d.ts +4 -0
- package/preact/dist/dist/hooks/reducer.d.ts +1 -0
- package/preact/dist/dist/hooks/useCombobox/index.d.ts +76 -0
- package/preact/dist/dist/hooks/useCombobox/reducer.d.ts +1 -0
- package/preact/dist/dist/hooks/useCombobox/stateChangeTypes.d.ts +23 -0
- package/preact/dist/dist/hooks/useCombobox/utils.d.ts +71 -0
- package/preact/dist/dist/hooks/useMultipleSelection/index.d.ts +30 -0
- package/preact/dist/dist/hooks/useMultipleSelection/reducer.d.ts +1 -0
- package/preact/dist/dist/hooks/useMultipleSelection/stateChangeTypes.d.ts +13 -0
- package/preact/dist/dist/hooks/useMultipleSelection/utils.d.ts +45 -0
- package/preact/dist/dist/hooks/useSelect/__tests__/utils.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useSelect/index.d.ts +56 -0
- package/preact/dist/dist/hooks/useSelect/reducer.d.ts +1 -0
- package/preact/dist/dist/hooks/useSelect/stateChangeTypes.d.ts +22 -0
- package/preact/dist/dist/hooks/useSelect/types.d.ts +7 -0
- package/preact/dist/dist/hooks/useSelect/utils/defaultProps.d.ts +8 -0
- package/preact/dist/dist/hooks/useSelect/utils/getItemIndexByCharacterKey.d.ts +2 -0
- package/preact/dist/dist/hooks/useSelect/utils/index.d.ts +3 -0
- package/preact/dist/dist/hooks/useSelect/utils/propTypes.d.ts +38 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/getTagGroupProps.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/getTagProps.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/getTagRemoveProps.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/props.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/reducer.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/returnProps.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/utils/defaultIds.d.ts +4 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/utils/defaultProps.d.ts +4 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/utils/index.d.ts +5 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/utils/renderTagGroup.d.ts +64 -0
- package/preact/dist/dist/hooks/useTagGroup/__tests__/utils/renderUseTagGroup.d.ts +2 -0
- package/preact/dist/dist/hooks/useTagGroup/index.d.ts +3 -0
- package/preact/dist/dist/hooks/useTagGroup/index.types.d.ts +111 -0
- package/preact/dist/dist/hooks/useTagGroup/reducer.d.ts +2 -0
- package/preact/dist/dist/hooks/useTagGroup/stateChangeTypes.d.ts +8 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/__tests__/useAccessibleDescription.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/__tests__/utils.use-element-ids.r18.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/__tests__/utils.use-element-ids.test.d.ts +1 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/getInitialState.d.ts +2 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/getMergedProps.d.ts +2 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/index.d.ts +7 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/isStateEqual.d.ts +2 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/useAccessibleDescription.d.ts +2 -0
- package/preact/dist/dist/hooks/useTagGroup/utils/useElementIds.d.ts +4 -0
- package/preact/dist/dist/hooks/utils-ts/__tests__/getItemAndIndex.test.d.ts +1 -0
- package/preact/dist/dist/hooks/utils-ts/callOnChangeProps.d.ts +2 -0
- package/preact/dist/dist/hooks/utils-ts/capitalizeString.d.ts +1 -0
- package/preact/dist/dist/hooks/utils-ts/getDefaultValue.d.ts +2 -0
- package/preact/dist/dist/hooks/utils-ts/getInitialValue.d.ts +2 -0
- package/preact/dist/dist/hooks/utils-ts/getItemAndIndex.d.ts +10 -0
- package/preact/dist/dist/hooks/utils-ts/index.d.ts +11 -0
- package/preact/dist/dist/hooks/utils-ts/propTypes.d.ts +16 -0
- package/preact/dist/dist/hooks/utils-ts/stateReducer.d.ts +6 -0
- package/preact/dist/dist/hooks/utils-ts/useA11yMessageStatus.d.ts +10 -0
- package/preact/dist/dist/hooks/utils-ts/useControlledReducer.d.ts +12 -0
- package/preact/dist/dist/hooks/utils-ts/useEnhancedReducer.d.ts +13 -0
- package/preact/dist/dist/hooks/utils-ts/useIsInitialMount.d.ts +4 -0
- package/preact/dist/dist/hooks/utils.d.ts +87 -0
- package/preact/dist/dist/hooks/utils.dropdown/defaultProps.d.ts +9 -0
- package/preact/dist/dist/hooks/utils.dropdown/defaultStateValues.d.ts +6 -0
- package/preact/dist/dist/hooks/utils.dropdown/index.d.ts +3 -0
- package/preact/dist/dist/hooks/utils.dropdown/propTypes.d.ts +36 -0
- package/preact/dist/dist/is.macro.d.ts +2 -0
- package/preact/dist/dist/productionEnum.macro.d.ts +2 -0
- package/preact/dist/dist/utils-ts/__tests__/getState.test.d.ts +1 -0
- package/preact/dist/dist/utils-ts/__tests__/handleRefs.test.d.ts +1 -0
- package/preact/dist/dist/utils-ts/callAllEventHandlers.d.ts +13 -0
- package/preact/dist/dist/utils-ts/debounce.d.ts +8 -0
- package/preact/dist/dist/utils-ts/generateId.d.ts +14 -0
- package/preact/dist/dist/utils-ts/getState.d.ts +22 -0
- package/preact/dist/dist/utils-ts/handleRefs.d.ts +2 -0
- package/preact/dist/dist/utils-ts/index.d.ts +11 -0
- package/preact/dist/dist/utils-ts/noop.d.ts +1 -0
- package/preact/dist/dist/utils-ts/scrollIntoView.d.ts +6 -0
- package/preact/dist/dist/utils-ts/setA11yStatus.d.ts +8 -0
- package/preact/dist/dist/utils-ts/useLatestRef.d.ts +2 -0
- package/preact/dist/dist/utils-ts/validatePropTypes.d.ts +2 -0
- package/preact/dist/dist/utils.d.ts +123 -0
- package/preact/dist/downshift.cjs.js +961 -549
- package/preact/dist/downshift.esm.js +939 -546
- package/preact/dist/downshift.umd.js +961 -581
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +2 -2
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/preact/package.json +3 -3
- package/typings/index.d.ts +133 -906
- package/typings/index.legacy.d.ts +892 -0
- package/dist/src/hooks/reducer.d.ts +0 -1
- package/dist/src/hooks/useSelect/reducer.d.ts +0 -1
- package/dist/src/hooks/useSelect/stateChangeTypes.d.ts +0 -22
- package/dist/src/hooks/useSelect/utils.d.ts +0 -11
- package/dist/src/hooks/utils.d.ts +0 -201
- package/dist/src/set-a11y-status.d.ts +0 -10
- package/dist/src/types.d.ts +0 -10
- package/dist/test/basic.test.d.ts +0 -15
- package/dist/test/custom.test.d.ts +0 -13
- package/dist/test/downshift.test.d.ts +0 -3
- package/dist/test/setup.d.ts +0 -1
- package/dist/test/useCombobox.test.d.ts +0 -3
- package/dist/test/useMultipleSelect.test.d.ts +0 -3
- package/dist/test/useSelect.test.d.ts +0 -3
- /package/dist/{src/hooks → hooks}/useSelect/__tests__/utils.test.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useSelect/types.d.ts +0 -0
- /package/dist/{src/is.macro.d.ts → is.macro.d.ts} +0 -0
- /package/dist/{src/productionEnum.macro.d.ts → productionEnum.macro.d.ts} +0 -0
package/dist/downshift.cjs.js
CHANGED
|
@@ -9,27 +9,255 @@ var PropTypes = require('prop-types');
|
|
|
9
9
|
var React = require('react');
|
|
10
10
|
var reactIs = require('react-is');
|
|
11
11
|
var computeScrollIntoView = require('compute-scroll-into-view');
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
function _interopNamespaceDefault(e) {
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
31
|
+
|
|
32
|
+
var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
33
|
+
var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
34
|
+
var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
35
|
+
var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
|
|
36
|
+
var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
|
|
37
|
+
var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
|
|
38
|
+
var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
|
|
39
|
+
var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
|
|
40
|
+
var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
|
|
41
|
+
var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
|
|
42
|
+
var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
|
|
43
|
+
var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
|
|
44
|
+
var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
|
|
45
|
+
var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
|
|
46
|
+
var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
|
|
47
|
+
var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
|
|
48
|
+
var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
|
|
49
|
+
|
|
50
|
+
var stateChangeTypes$4 = /*#__PURE__*/Object.freeze({
|
|
51
|
+
__proto__: null,
|
|
52
|
+
blurButton: blurButton,
|
|
53
|
+
blurInput: blurInput,
|
|
54
|
+
changeInput: changeInput,
|
|
55
|
+
clickButton: clickButton,
|
|
56
|
+
clickItem: clickItem,
|
|
57
|
+
controlledPropUpdatedSelectedItem: controlledPropUpdatedSelectedItem,
|
|
58
|
+
itemMouseEnter: itemMouseEnter,
|
|
59
|
+
keyDownArrowDown: keyDownArrowDown,
|
|
60
|
+
keyDownArrowUp: keyDownArrowUp,
|
|
61
|
+
keyDownEnd: keyDownEnd,
|
|
62
|
+
keyDownEnter: keyDownEnter,
|
|
63
|
+
keyDownEscape: keyDownEscape,
|
|
64
|
+
keyDownHome: keyDownHome,
|
|
65
|
+
keyDownSpaceButton: keyDownSpaceButton,
|
|
66
|
+
mouseUp: mouseUp,
|
|
67
|
+
touchEnd: touchEnd,
|
|
68
|
+
unknown: unknown
|
|
69
|
+
});
|
|
13
70
|
|
|
14
71
|
var idCounter = 0;
|
|
15
72
|
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* accept a callback, but not worry about it if it's not
|
|
20
|
-
* passed.
|
|
21
|
-
* @param {Function} cb the callback
|
|
22
|
-
* @return {Function} a function
|
|
73
|
+
/**
|
|
74
|
+
* This generates a unique ID for an instance of Downshift
|
|
75
|
+
* @return {string} the unique ID
|
|
23
76
|
*/
|
|
24
|
-
function
|
|
25
|
-
return
|
|
77
|
+
function generateId() {
|
|
78
|
+
return String(idCounter++);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resets idCounter to 0. Used for SSR.
|
|
83
|
+
*/
|
|
84
|
+
function resetIdCounter() {
|
|
85
|
+
// istanbul ignore next
|
|
86
|
+
if ('useId' in React__namespace) {
|
|
87
|
+
console.warn("It is not necessary to call resetIdCounter when using React 18+");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
idCounter = 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function useLatestRef(val) {
|
|
94
|
+
var ref = React__namespace.useRef(val);
|
|
95
|
+
// technically this is not "concurrent mode safe" because we're manipulating
|
|
96
|
+
// the value during render (so it's not idempotent). However, the places this
|
|
97
|
+
// hook is used is to support memoizing callbacks which will be called
|
|
98
|
+
// *during* render, so we need the latest values *during* render.
|
|
99
|
+
// If not for this, then we'd probably want to use useLayoutEffect instead.
|
|
100
|
+
ref.current = val;
|
|
101
|
+
return ref;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleRefs$1() {
|
|
105
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
106
|
+
refs[_key] = arguments[_key];
|
|
107
|
+
}
|
|
108
|
+
return function (node) {
|
|
109
|
+
refs.forEach(function (ref) {
|
|
110
|
+
if (typeof ref === 'function') {
|
|
111
|
+
ref(node);
|
|
112
|
+
} else if (ref) {
|
|
113
|
+
ref.current = node;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* This is intended to be used to compose event handlers.
|
|
121
|
+
* They are executed in order until one of them sets
|
|
122
|
+
* `event.preventDownshiftDefault = true`.
|
|
123
|
+
* @param fns the event handler functions
|
|
124
|
+
* @return the event handler to add to an element
|
|
125
|
+
*/
|
|
126
|
+
function callAllEventHandlers$1() {
|
|
127
|
+
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
128
|
+
fns[_key] = arguments[_key];
|
|
129
|
+
}
|
|
130
|
+
return function (event) {
|
|
131
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
132
|
+
args[_key2 - 1] = arguments[_key2];
|
|
133
|
+
}
|
|
134
|
+
return fns.some(function (fn) {
|
|
135
|
+
if (fn) {
|
|
136
|
+
fn.apply(void 0, [event].concat(args));
|
|
137
|
+
}
|
|
138
|
+
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Simple debounce implementation. Will call the given
|
|
145
|
+
* function once after the time given has passed since
|
|
146
|
+
* it was last called.
|
|
147
|
+
*/
|
|
148
|
+
function debounce$1(fn, time) {
|
|
149
|
+
var timeoutId;
|
|
150
|
+
function cancel() {
|
|
151
|
+
if (timeoutId) {
|
|
152
|
+
clearTimeout(timeoutId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function wrapper() {
|
|
156
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
157
|
+
args[_key] = arguments[_key];
|
|
158
|
+
}
|
|
159
|
+
cancel();
|
|
160
|
+
timeoutId = setTimeout(function () {
|
|
161
|
+
timeoutId = null;
|
|
162
|
+
fn.apply(void 0, args);
|
|
163
|
+
}, time);
|
|
164
|
+
}
|
|
165
|
+
wrapper.cancel = cancel;
|
|
166
|
+
return wrapper;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var cleanupStatus = debounce$1(function (document) {
|
|
170
|
+
getStatusDiv(document).textContent = '';
|
|
171
|
+
}, 500);
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Get the status node or create it if it does not already exist.
|
|
175
|
+
*/
|
|
176
|
+
function getStatusDiv(document) {
|
|
177
|
+
var statusDiv = document.getElementById('a11y-status-message');
|
|
178
|
+
if (statusDiv) {
|
|
179
|
+
return statusDiv;
|
|
180
|
+
}
|
|
181
|
+
statusDiv = document.createElement('div');
|
|
182
|
+
statusDiv.setAttribute('id', 'a11y-status-message');
|
|
183
|
+
statusDiv.setAttribute('role', 'status');
|
|
184
|
+
statusDiv.setAttribute('aria-live', 'polite');
|
|
185
|
+
statusDiv.setAttribute('aria-relevant', 'additions text');
|
|
186
|
+
Object.assign(statusDiv.style, {
|
|
187
|
+
border: '0',
|
|
188
|
+
clip: 'rect(0 0 0 0)',
|
|
189
|
+
height: '1px',
|
|
190
|
+
margin: '-1px',
|
|
191
|
+
overflow: 'hidden',
|
|
192
|
+
padding: '0',
|
|
193
|
+
position: 'absolute',
|
|
194
|
+
width: '1px'
|
|
195
|
+
});
|
|
196
|
+
document.body.appendChild(statusDiv);
|
|
197
|
+
return statusDiv;
|
|
26
198
|
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Sets aria live status to a div element that's visually hidden.
|
|
202
|
+
*/
|
|
203
|
+
function setStatus(status, document) {
|
|
204
|
+
if (!status || !document) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
var div = getStatusDiv(document);
|
|
208
|
+
div.textContent = status;
|
|
209
|
+
cleanupStatus(document);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Removes the status element from the DOM
|
|
214
|
+
*/
|
|
215
|
+
function cleanupStatusDiv(document) {
|
|
216
|
+
var statusDiv = document == null ? void 0 : document.getElementById('a11y-status-message');
|
|
217
|
+
if (statusDiv) {
|
|
218
|
+
statusDiv.remove();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
27
222
|
function noop() {}
|
|
28
223
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
224
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
225
|
+
var validatePropTypes$1 = noop;
|
|
226
|
+
/* istanbul ignore next */
|
|
227
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
228
|
+
validatePropTypes$1 = function validatePropTypes(options, caller, propTypes) {
|
|
229
|
+
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* This will perform a shallow merge of the given state object
|
|
235
|
+
* with the state coming from props
|
|
236
|
+
* (for the controlled component scenario)
|
|
237
|
+
* This is used in state updater functions so they're referencing
|
|
238
|
+
* the right state regardless of where it comes from.
|
|
239
|
+
*
|
|
240
|
+
* @param state The state of the component/hook.
|
|
241
|
+
* @param props The props that may contain controlled values.
|
|
242
|
+
* @returns The merged controlled state.
|
|
243
|
+
*/
|
|
244
|
+
function getState(state, props) {
|
|
245
|
+
if (!props) {
|
|
246
|
+
return state;
|
|
247
|
+
}
|
|
248
|
+
var keys = Object.keys(state);
|
|
249
|
+
return keys.reduce(function (newState, key) {
|
|
250
|
+
if (props[key] !== undefined) {
|
|
251
|
+
newState[key] = props[key];
|
|
252
|
+
}
|
|
253
|
+
return newState;
|
|
254
|
+
}, _extends({}, state));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Scroll node into view if necessary
|
|
259
|
+
* @param {HTMLElement} node the element that should scroll into view
|
|
260
|
+
* @param {HTMLElement} menuNode the menu element of the component
|
|
33
261
|
*/
|
|
34
262
|
function scrollIntoView(node, menuNode) {
|
|
35
263
|
if (!node) {
|
|
@@ -49,6 +277,18 @@ function scrollIntoView(node, menuNode) {
|
|
|
49
277
|
});
|
|
50
278
|
}
|
|
51
279
|
|
|
280
|
+
/**
|
|
281
|
+
* Accepts a parameter and returns it if it's a function
|
|
282
|
+
* or a noop function if it's not. This allows us to
|
|
283
|
+
* accept a callback, but not worry about it if it's not
|
|
284
|
+
* passed.
|
|
285
|
+
* @param {Function} cb the callback
|
|
286
|
+
* @return {Function} a function
|
|
287
|
+
*/
|
|
288
|
+
function cbToCb(cb) {
|
|
289
|
+
return typeof cb === 'function' ? cb : noop;
|
|
290
|
+
}
|
|
291
|
+
|
|
52
292
|
/**
|
|
53
293
|
* @param {HTMLElement} parent the parent node
|
|
54
294
|
* @param {HTMLElement} child the child node
|
|
@@ -127,26 +367,6 @@ function handleRefs() {
|
|
|
127
367
|
};
|
|
128
368
|
}
|
|
129
369
|
|
|
130
|
-
/**
|
|
131
|
-
* This generates a unique ID for an instance of Downshift
|
|
132
|
-
* @return {String} the unique ID
|
|
133
|
-
*/
|
|
134
|
-
function generateId() {
|
|
135
|
-
return String(idCounter++);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Resets idCounter to 0. Used for SSR.
|
|
140
|
-
*/
|
|
141
|
-
function resetIdCounter() {
|
|
142
|
-
// istanbul ignore next
|
|
143
|
-
if ('useId' in React) {
|
|
144
|
-
console.warn("It is not necessary to call resetIdCounter when using React 18+");
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
idCounter = 0;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
370
|
/**
|
|
151
371
|
* Default implementation for status message. Only added when menu is open.
|
|
152
372
|
* Will specify if there are results in the list, and if so, how many,
|
|
@@ -155,10 +375,10 @@ function resetIdCounter() {
|
|
|
155
375
|
* @param {Object} param the downshift state and other relevant properties
|
|
156
376
|
* @return {String} the a11y status message
|
|
157
377
|
*/
|
|
158
|
-
function getA11yStatusMessage(
|
|
159
|
-
var isOpen =
|
|
160
|
-
resultCount =
|
|
161
|
-
previousResultCount =
|
|
378
|
+
function getA11yStatusMessage(_ref) {
|
|
379
|
+
var isOpen = _ref.isOpen,
|
|
380
|
+
resultCount = _ref.resultCount,
|
|
381
|
+
previousResultCount = _ref.previousResultCount;
|
|
162
382
|
if (!isOpen) {
|
|
163
383
|
return '';
|
|
164
384
|
}
|
|
@@ -233,27 +453,6 @@ function pickState(state) {
|
|
|
233
453
|
return result;
|
|
234
454
|
}
|
|
235
455
|
|
|
236
|
-
/**
|
|
237
|
-
* This will perform a shallow merge of the given state object
|
|
238
|
-
* with the state coming from props
|
|
239
|
-
* (for the controlled component scenario)
|
|
240
|
-
* This is used in state updater functions so they're referencing
|
|
241
|
-
* the right state regardless of where it comes from.
|
|
242
|
-
*
|
|
243
|
-
* @param {Object} state The state of the component/hook.
|
|
244
|
-
* @param {Object} props The props that may contain controlled values.
|
|
245
|
-
* @returns {Object} The merged controlled state.
|
|
246
|
-
*/
|
|
247
|
-
function getState(state, props) {
|
|
248
|
-
if (!state || !props) {
|
|
249
|
-
return state;
|
|
250
|
-
}
|
|
251
|
-
return Object.keys(state).reduce(function (prevState, key) {
|
|
252
|
-
prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
|
|
253
|
-
return prevState;
|
|
254
|
-
}, {});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
456
|
/**
|
|
258
457
|
* This determines whether a prop is a "controlled prop" meaning it is
|
|
259
458
|
* state which is controlled by the outside of this component rather
|
|
@@ -397,105 +596,9 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
397
596
|
};
|
|
398
597
|
}
|
|
399
598
|
|
|
400
|
-
var
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Get the status node or create it if it does not already exist.
|
|
406
|
-
* @param {Object} documentProp document passed by the user.
|
|
407
|
-
* @return {HTMLElement} the status node.
|
|
408
|
-
*/
|
|
409
|
-
function getStatusDiv(documentProp) {
|
|
410
|
-
var statusDiv = documentProp.getElementById('a11y-status-message');
|
|
411
|
-
if (statusDiv) {
|
|
412
|
-
return statusDiv;
|
|
413
|
-
}
|
|
414
|
-
statusDiv = documentProp.createElement('div');
|
|
415
|
-
statusDiv.setAttribute('id', 'a11y-status-message');
|
|
416
|
-
statusDiv.setAttribute('role', 'status');
|
|
417
|
-
statusDiv.setAttribute('aria-live', 'polite');
|
|
418
|
-
statusDiv.setAttribute('aria-relevant', 'additions text');
|
|
419
|
-
Object.assign(statusDiv.style, {
|
|
420
|
-
border: '0',
|
|
421
|
-
clip: 'rect(0 0 0 0)',
|
|
422
|
-
height: '1px',
|
|
423
|
-
margin: '-1px',
|
|
424
|
-
overflow: 'hidden',
|
|
425
|
-
padding: '0',
|
|
426
|
-
position: 'absolute',
|
|
427
|
-
width: '1px'
|
|
428
|
-
});
|
|
429
|
-
documentProp.body.appendChild(statusDiv);
|
|
430
|
-
return statusDiv;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* @param {String} status the status message
|
|
435
|
-
* @param {Object} documentProp document passed by the user.
|
|
436
|
-
*/
|
|
437
|
-
function setStatus(status, documentProp) {
|
|
438
|
-
if (!status || !documentProp) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
var div = getStatusDiv(documentProp);
|
|
442
|
-
div.textContent = status;
|
|
443
|
-
cleanupStatus(documentProp);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Removes the status element from the DOM
|
|
448
|
-
* @param {Document} documentProp
|
|
449
|
-
*/
|
|
450
|
-
function cleanupStatusDiv(documentProp) {
|
|
451
|
-
var statusDiv = documentProp == null ? void 0 : documentProp.getElementById('a11y-status-message');
|
|
452
|
-
if (statusDiv) {
|
|
453
|
-
statusDiv.remove();
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
458
|
-
var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
459
|
-
var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
460
|
-
var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
|
|
461
|
-
var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
|
|
462
|
-
var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
|
|
463
|
-
var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
|
|
464
|
-
var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
|
|
465
|
-
var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
|
|
466
|
-
var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
|
|
467
|
-
var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
|
|
468
|
-
var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
|
|
469
|
-
var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
|
|
470
|
-
var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
|
|
471
|
-
var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
|
|
472
|
-
var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
|
|
473
|
-
var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
|
|
474
|
-
|
|
475
|
-
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
476
|
-
__proto__: null,
|
|
477
|
-
blurButton: blurButton,
|
|
478
|
-
blurInput: blurInput,
|
|
479
|
-
changeInput: changeInput,
|
|
480
|
-
clickButton: clickButton,
|
|
481
|
-
clickItem: clickItem,
|
|
482
|
-
controlledPropUpdatedSelectedItem: controlledPropUpdatedSelectedItem,
|
|
483
|
-
itemMouseEnter: itemMouseEnter,
|
|
484
|
-
keyDownArrowDown: keyDownArrowDown,
|
|
485
|
-
keyDownArrowUp: keyDownArrowUp,
|
|
486
|
-
keyDownEnd: keyDownEnd,
|
|
487
|
-
keyDownEnter: keyDownEnter,
|
|
488
|
-
keyDownEscape: keyDownEscape,
|
|
489
|
-
keyDownHome: keyDownHome,
|
|
490
|
-
keyDownSpaceButton: keyDownSpaceButton,
|
|
491
|
-
mouseUp: mouseUp,
|
|
492
|
-
touchEnd: touchEnd,
|
|
493
|
-
unknown: unknown
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
var _excluded$3 = ["refKey", "ref"],
|
|
497
|
-
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
498
|
-
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
599
|
+
var _excluded$4 = ["refKey", "ref"],
|
|
600
|
+
_excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
601
|
+
_excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
499
602
|
_excluded4$2 = ["refKey", "ref"],
|
|
500
603
|
_excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
501
604
|
var Downshift = /*#__PURE__*/function () {
|
|
@@ -685,7 +788,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
685
788
|
_ref$refKey = _ref.refKey,
|
|
686
789
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
687
790
|
ref = _ref.ref,
|
|
688
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
791
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
689
792
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
690
793
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
691
794
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
@@ -841,7 +944,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
841
944
|
var onKeyDown = _ref3.onKeyDown,
|
|
842
945
|
onKeyUp = _ref3.onKeyUp,
|
|
843
946
|
onBlur = _ref3.onBlur,
|
|
844
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$
|
|
947
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$4);
|
|
845
948
|
var _this$getState5 = _this.getState(),
|
|
846
949
|
isOpen = _this$getState5.isOpen;
|
|
847
950
|
var enabledEventHandlers = {
|
|
@@ -931,7 +1034,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
931
1034
|
onChange = _ref4.onChange,
|
|
932
1035
|
onInput = _ref4.onInput;
|
|
933
1036
|
_ref4.onChangeText;
|
|
934
|
-
var rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$
|
|
1037
|
+
var rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$3);
|
|
935
1038
|
var onChangeKey;
|
|
936
1039
|
var eventHandlers = {};
|
|
937
1040
|
|
|
@@ -1475,7 +1578,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1475
1578
|
suppressRefError: false,
|
|
1476
1579
|
scrollIntoView: scrollIntoView
|
|
1477
1580
|
};
|
|
1478
|
-
Downshift.stateChangeTypes = stateChangeTypes$
|
|
1581
|
+
Downshift.stateChangeTypes = stateChangeTypes$4;
|
|
1479
1582
|
return Downshift;
|
|
1480
1583
|
}();
|
|
1481
1584
|
process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
|
|
@@ -1548,62 +1651,275 @@ function validateGetRootPropsCalledCorrectly(element, _ref11) {
|
|
|
1548
1651
|
}
|
|
1549
1652
|
}
|
|
1550
1653
|
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
function callOnChangeProps(action, state, newState) {
|
|
1558
|
-
var props = action.props,
|
|
1559
|
-
type = action.type;
|
|
1654
|
+
function capitalizeString(string) {
|
|
1655
|
+
return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
function callOnChangeProps(action, props, state, newState) {
|
|
1659
|
+
var type = action.type;
|
|
1560
1660
|
var changes = {};
|
|
1561
|
-
Object.keys(state)
|
|
1562
|
-
|
|
1661
|
+
var keys = Object.keys(state);
|
|
1662
|
+
for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
|
|
1663
|
+
var key = _keys[_i];
|
|
1664
|
+
invokeOnChangeHandler(key, action, props, state, newState);
|
|
1563
1665
|
if (newState[key] !== state[key]) {
|
|
1564
1666
|
changes[key] = newState[key];
|
|
1565
1667
|
}
|
|
1566
|
-
}
|
|
1668
|
+
}
|
|
1567
1669
|
if (props.onStateChange && Object.keys(changes).length) {
|
|
1568
1670
|
props.onStateChange(_extends({
|
|
1569
1671
|
type: type
|
|
1570
1672
|
}, changes));
|
|
1571
1673
|
}
|
|
1572
1674
|
}
|
|
1573
|
-
function invokeOnChangeHandler(key, action, state, newState) {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
var handler = "on" + capitalizeString(key) + "Change";
|
|
1577
|
-
if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
|
|
1578
|
-
props[handler](_extends({
|
|
1579
|
-
type: type
|
|
1580
|
-
}, newState));
|
|
1675
|
+
function invokeOnChangeHandler(key, action, props, state, newState) {
|
|
1676
|
+
if (newState[key] === state[key]) {
|
|
1677
|
+
return;
|
|
1581
1678
|
}
|
|
1679
|
+
var handlerKey = "on" + capitalizeString(key) + "Change";
|
|
1680
|
+
var handler = props[handlerKey];
|
|
1681
|
+
if (typeof handler !== 'function') {
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
var type = action.type;
|
|
1685
|
+
handler(_extends({
|
|
1686
|
+
type: type
|
|
1687
|
+
}, newState));
|
|
1582
1688
|
}
|
|
1583
1689
|
|
|
1584
|
-
/**
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
* @
|
|
1690
|
+
/**
|
|
1691
|
+
* Computes the controlled state using a the previous state, props,
|
|
1692
|
+
* two reducers, one from downshift and an optional one from the user.
|
|
1693
|
+
* Also calls the onChange handlers for state values that have changed.
|
|
1694
|
+
*
|
|
1695
|
+
* @param {Function} reducer Reducer function from downshift.
|
|
1696
|
+
* @param {Object} props The hook props, also passed to createInitialState.
|
|
1697
|
+
* @param {Function} createInitialState Function that returns the initial state.
|
|
1698
|
+
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
1699
|
+
* @returns {Array} An array with the state and an action dispatcher.
|
|
1700
|
+
*/
|
|
1701
|
+
function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
|
|
1702
|
+
var prevStateRef = React__namespace.useRef(null);
|
|
1703
|
+
var actionRef = React__namespace.useRef(undefined);
|
|
1704
|
+
var propsRef = useLatestRef(props);
|
|
1705
|
+
var enhancedReducer = React__namespace.useCallback(function (state, action) {
|
|
1706
|
+
actionRef.current = action;
|
|
1707
|
+
state = getState(state, propsRef.current);
|
|
1708
|
+
var changes = reducer(state, propsRef.current, action);
|
|
1709
|
+
var newState = propsRef.current.stateReducer(state, _extends({}, action, {
|
|
1710
|
+
changes: changes
|
|
1711
|
+
}));
|
|
1712
|
+
return _extends({}, state, newState);
|
|
1713
|
+
}, [propsRef, reducer]);
|
|
1714
|
+
var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
|
|
1715
|
+
state = _React$useReducer[0],
|
|
1716
|
+
dispatch = _React$useReducer[1];
|
|
1717
|
+
var action = actionRef.current;
|
|
1718
|
+
React__namespace.useEffect(function () {
|
|
1719
|
+
var _prevStateRef$current;
|
|
1720
|
+
var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
|
|
1721
|
+
var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
|
|
1722
|
+
if (shouldCallOnChangeProps) {
|
|
1723
|
+
callOnChangeProps(action, propsRef.current, prevState, state);
|
|
1724
|
+
}
|
|
1725
|
+
prevStateRef.current = state;
|
|
1726
|
+
}, [state, action, isStateEqual, propsRef]);
|
|
1727
|
+
return [state, dispatch];
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
/**
|
|
1731
|
+
* Wraps the useEnhancedReducer and applies the controlled prop values before
|
|
1732
|
+
* returning the new state.
|
|
1733
|
+
*
|
|
1734
|
+
* @param {Function} reducer Reducer function from downshift.
|
|
1735
|
+
* @param {Object} props The hook props, also passed to createInitialState.
|
|
1736
|
+
* @param {Function} createInitialState Function that returns the initial state.
|
|
1737
|
+
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
1738
|
+
* @returns {Array} An array with the state and an action dispatcher.
|
|
1739
|
+
*/
|
|
1740
|
+
function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
|
|
1741
|
+
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
1742
|
+
state = _useEnhancedReducer[0],
|
|
1743
|
+
dispatch = _useEnhancedReducer[1];
|
|
1744
|
+
return [getState(state, props), dispatch];
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
/**
|
|
1748
|
+
* Returns both the item and index when both or either is passed.
|
|
1749
|
+
*
|
|
1750
|
+
* @param itemProp The item which could be undefined.
|
|
1751
|
+
* @param indexProp The index which could be undefined.
|
|
1752
|
+
* @param items The array of items to get the item based on index.
|
|
1753
|
+
* @param errorMessage The error to be thrown if index and item could not be returned for any reason.
|
|
1754
|
+
* @returns An array with item and index.
|
|
1755
|
+
*/
|
|
1756
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1757
|
+
if (itemProp !== undefined && indexProp !== undefined) {
|
|
1758
|
+
return [itemProp, indexProp];
|
|
1759
|
+
}
|
|
1760
|
+
if (itemProp !== undefined) {
|
|
1761
|
+
var index = items.indexOf(itemProp);
|
|
1762
|
+
if (index < 0) {
|
|
1763
|
+
throw new Error(errorMessage);
|
|
1764
|
+
}
|
|
1765
|
+
return [itemProp, items.indexOf(itemProp)];
|
|
1766
|
+
}
|
|
1767
|
+
if (indexProp !== undefined) {
|
|
1768
|
+
var item = items[indexProp];
|
|
1769
|
+
if (item === undefined) {
|
|
1770
|
+
throw new Error(errorMessage);
|
|
1771
|
+
}
|
|
1772
|
+
return [item, indexProp];
|
|
1773
|
+
}
|
|
1774
|
+
throw new Error(errorMessage);
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Tracks if it's the first render.
|
|
1779
|
+
*/
|
|
1780
|
+
function useIsInitialMount() {
|
|
1781
|
+
var isInitialMountRef = React__namespace.useRef(true);
|
|
1782
|
+
React__namespace.useEffect(function () {
|
|
1783
|
+
isInitialMountRef.current = false;
|
|
1784
|
+
return function () {
|
|
1785
|
+
isInitialMountRef.current = true;
|
|
1786
|
+
};
|
|
1787
|
+
}, []);
|
|
1788
|
+
return isInitialMountRef.current;
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
/**
|
|
1792
|
+
* Default state reducer that returns the changes.
|
|
1793
|
+
*
|
|
1590
1794
|
*/
|
|
1591
|
-
function stateReducer(
|
|
1795
|
+
function stateReducer(_s, a) {
|
|
1592
1796
|
return a.changes;
|
|
1593
1797
|
}
|
|
1594
1798
|
|
|
1595
|
-
|
|
1596
|
-
|
|
1799
|
+
// Shared between all exports.
|
|
1800
|
+
var propTypes$5 = {
|
|
1801
|
+
environment: PropTypes.shape({
|
|
1802
|
+
addEventListener: PropTypes.func.isRequired,
|
|
1803
|
+
removeEventListener: PropTypes.func.isRequired,
|
|
1804
|
+
document: PropTypes.shape({
|
|
1805
|
+
createElement: PropTypes.func.isRequired,
|
|
1806
|
+
getElementById: PropTypes.func.isRequired,
|
|
1807
|
+
activeElement: PropTypes.any.isRequired,
|
|
1808
|
+
body: PropTypes.any.isRequired
|
|
1809
|
+
}).isRequired,
|
|
1810
|
+
Node: PropTypes.func.isRequired
|
|
1811
|
+
}),
|
|
1812
|
+
itemToKey: PropTypes.func,
|
|
1813
|
+
stateReducer: PropTypes.func
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1816
|
+
function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
1817
|
+
var defaultValue = props["default" + capitalizeString(propKey)];
|
|
1818
|
+
if (defaultValue !== undefined) {
|
|
1819
|
+
return defaultValue;
|
|
1820
|
+
}
|
|
1821
|
+
return defaultStateValues[propKey];
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
1825
|
+
var value = props[propKey];
|
|
1826
|
+
if (value !== undefined) {
|
|
1827
|
+
return value;
|
|
1828
|
+
}
|
|
1829
|
+
var initialValue = props["initial" + capitalizeString(propKey)];
|
|
1830
|
+
if (initialValue !== undefined) {
|
|
1831
|
+
return initialValue;
|
|
1832
|
+
}
|
|
1833
|
+
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* Debounced call for updating the a11y message.
|
|
1597
1838
|
*/
|
|
1598
|
-
var updateA11yStatus = debounce(function (status, document) {
|
|
1839
|
+
var updateA11yStatus = debounce$1(function (status, document) {
|
|
1599
1840
|
setStatus(status, document);
|
|
1600
1841
|
}, 200);
|
|
1601
1842
|
|
|
1843
|
+
/**
|
|
1844
|
+
* Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1845
|
+
* @param getA11yStatusMessage The function that builds the status message.
|
|
1846
|
+
* @param options The options to be passed to getA11yStatusMessage if called.
|
|
1847
|
+
* @param dependencyArray The dependency array that triggers the status message setter via useEffect.
|
|
1848
|
+
* @param environment The environment object containing the document.
|
|
1849
|
+
*/
|
|
1850
|
+
function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, environment) {
|
|
1851
|
+
var document = environment == null ? void 0 : environment.document;
|
|
1852
|
+
var isInitialMount = useIsInitialMount();
|
|
1853
|
+
|
|
1854
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1855
|
+
React__namespace.useEffect(function () {
|
|
1856
|
+
if (!getA11yStatusMessage || isInitialMount || false || !document) {
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
var status = getA11yStatusMessage(options);
|
|
1860
|
+
updateA11yStatus(status, document);
|
|
1861
|
+
|
|
1862
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1863
|
+
}, dependencyArray);
|
|
1864
|
+
|
|
1865
|
+
// Cleanup the status message container.
|
|
1866
|
+
React__namespace.useEffect(function () {
|
|
1867
|
+
return function () {
|
|
1868
|
+
updateA11yStatus.cancel();
|
|
1869
|
+
cleanupStatusDiv(document);
|
|
1870
|
+
};
|
|
1871
|
+
}, [document]);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// Shared between useSelect, useCombobox, Downshift.
|
|
1875
|
+
var propTypes$4 = _extends({}, propTypes$5, {
|
|
1876
|
+
getA11yStatusMessage: PropTypes.func,
|
|
1877
|
+
highlightedIndex: PropTypes.number,
|
|
1878
|
+
defaultHighlightedIndex: PropTypes.number,
|
|
1879
|
+
initialHighlightedIndex: PropTypes.number,
|
|
1880
|
+
isOpen: PropTypes.bool,
|
|
1881
|
+
defaultIsOpen: PropTypes.bool,
|
|
1882
|
+
initialIsOpen: PropTypes.bool,
|
|
1883
|
+
selectedItem: PropTypes.any,
|
|
1884
|
+
initialSelectedItem: PropTypes.any,
|
|
1885
|
+
defaultSelectedItem: PropTypes.any,
|
|
1886
|
+
id: PropTypes.string,
|
|
1887
|
+
labelId: PropTypes.string,
|
|
1888
|
+
menuId: PropTypes.string,
|
|
1889
|
+
getItemId: PropTypes.func,
|
|
1890
|
+
toggleButtonId: PropTypes.string,
|
|
1891
|
+
onSelectedItemChange: PropTypes.func,
|
|
1892
|
+
onHighlightedIndexChange: PropTypes.func,
|
|
1893
|
+
onStateChange: PropTypes.func,
|
|
1894
|
+
onIsOpenChange: PropTypes.func,
|
|
1895
|
+
scrollIntoView: PropTypes.func
|
|
1896
|
+
});
|
|
1897
|
+
|
|
1898
|
+
var defaultProps$3 = {
|
|
1899
|
+
itemToString: function itemToString(item) {
|
|
1900
|
+
return item ? String(item) : '';
|
|
1901
|
+
},
|
|
1902
|
+
itemToKey: function itemToKey(item) {
|
|
1903
|
+
return item;
|
|
1904
|
+
},
|
|
1905
|
+
stateReducer: stateReducer,
|
|
1906
|
+
scrollIntoView: scrollIntoView,
|
|
1907
|
+
environment: /* istanbul ignore next (ssr) */
|
|
1908
|
+
typeof window === 'undefined' || false ? undefined : window
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1911
|
+
var defaultStateValues$1 = {
|
|
1912
|
+
highlightedIndex: -1,
|
|
1913
|
+
isOpen: false,
|
|
1914
|
+
selectedItem: null,
|
|
1915
|
+
inputValue: ''
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1602
1918
|
// istanbul ignore next
|
|
1603
|
-
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ?
|
|
1919
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
1604
1920
|
|
|
1605
1921
|
// istanbul ignore next
|
|
1606
|
-
var useElementIds = 'useId' in
|
|
1922
|
+
var useElementIds$1 = 'useId' in React__namespace // Avoid conditional useId call
|
|
1607
1923
|
? function useElementIds(_ref) {
|
|
1608
1924
|
var id = _ref.id,
|
|
1609
1925
|
labelId = _ref.labelId,
|
|
@@ -1612,11 +1928,11 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
|
|
|
1612
1928
|
toggleButtonId = _ref.toggleButtonId,
|
|
1613
1929
|
inputId = _ref.inputId;
|
|
1614
1930
|
// Avoid conditional useId call
|
|
1615
|
-
var reactId = "downshift-" +
|
|
1931
|
+
var reactId = "downshift-" + React__namespace.useId();
|
|
1616
1932
|
if (!id) {
|
|
1617
1933
|
id = reactId;
|
|
1618
1934
|
}
|
|
1619
|
-
var elementIds =
|
|
1935
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
1620
1936
|
return {
|
|
1621
1937
|
labelId: labelId || id + "-label",
|
|
1622
1938
|
menuId: menuId || id + "-menu",
|
|
@@ -1636,7 +1952,7 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
|
|
|
1636
1952
|
getItemId = _ref2.getItemId,
|
|
1637
1953
|
toggleButtonId = _ref2.toggleButtonId,
|
|
1638
1954
|
inputId = _ref2.inputId;
|
|
1639
|
-
var elementIds =
|
|
1955
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
1640
1956
|
return {
|
|
1641
1957
|
labelId: labelId || id + "-label",
|
|
1642
1958
|
menuId: menuId || id + "-menu",
|
|
@@ -1649,138 +1965,14 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
|
|
|
1649
1965
|
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
1650
1966
|
return elementIds;
|
|
1651
1967
|
};
|
|
1652
|
-
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1653
|
-
var item, index;
|
|
1654
|
-
if (itemProp === undefined) {
|
|
1655
|
-
if (indexProp === undefined) {
|
|
1656
|
-
throw new Error(errorMessage);
|
|
1657
|
-
}
|
|
1658
|
-
item = items[indexProp];
|
|
1659
|
-
index = indexProp;
|
|
1660
|
-
} else {
|
|
1661
|
-
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
1662
|
-
item = itemProp;
|
|
1663
|
-
}
|
|
1664
|
-
return [item, index];
|
|
1665
|
-
}
|
|
1666
1968
|
function isAcceptedCharacterKey(key) {
|
|
1667
1969
|
return /^\S{1}$/.test(key);
|
|
1668
1970
|
}
|
|
1669
|
-
function
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
function useLatestRef(val) {
|
|
1673
|
-
var ref = React.useRef(val);
|
|
1674
|
-
// technically this is not "concurrent mode safe" because we're manipulating
|
|
1675
|
-
// the value during render (so it's not idempotent). However, the places this
|
|
1676
|
-
// hook is used is to support memoizing callbacks which will be called
|
|
1677
|
-
// *during* render, so we need the latest values *during* render.
|
|
1678
|
-
// If not for this, then we'd probably want to use useLayoutEffect instead.
|
|
1679
|
-
ref.current = val;
|
|
1680
|
-
return ref;
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
/**
|
|
1684
|
-
* Computes the controlled state using a the previous state, props,
|
|
1685
|
-
* two reducers, one from downshift and an optional one from the user.
|
|
1686
|
-
* Also calls the onChange handlers for state values that have changed.
|
|
1687
|
-
*
|
|
1688
|
-
* @param {Function} reducer Reducer function from downshift.
|
|
1689
|
-
* @param {Object} props The hook props, also passed to createInitialState.
|
|
1690
|
-
* @param {Function} createInitialState Function that returns the initial state.
|
|
1691
|
-
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
1692
|
-
* @returns {Array} An array with the state and an action dispatcher.
|
|
1693
|
-
*/
|
|
1694
|
-
function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
|
|
1695
|
-
var prevStateRef = React.useRef();
|
|
1696
|
-
var actionRef = React.useRef();
|
|
1697
|
-
var enhancedReducer = React.useCallback(function (state, action) {
|
|
1698
|
-
actionRef.current = action;
|
|
1699
|
-
state = getState(state, action.props);
|
|
1700
|
-
var changes = reducer(state, action);
|
|
1701
|
-
var newState = action.props.stateReducer(state, _extends({}, action, {
|
|
1702
|
-
changes: changes
|
|
1703
|
-
}));
|
|
1704
|
-
return newState;
|
|
1705
|
-
}, [reducer]);
|
|
1706
|
-
var _useReducer = React.useReducer(enhancedReducer, props, createInitialState),
|
|
1707
|
-
state = _useReducer[0],
|
|
1708
|
-
dispatch = _useReducer[1];
|
|
1709
|
-
var propsRef = useLatestRef(props);
|
|
1710
|
-
var dispatchWithProps = React.useCallback(function (action) {
|
|
1711
|
-
return dispatch(_extends({
|
|
1712
|
-
props: propsRef.current
|
|
1713
|
-
}, action));
|
|
1714
|
-
}, [propsRef]);
|
|
1715
|
-
var action = actionRef.current;
|
|
1716
|
-
React.useEffect(function () {
|
|
1717
|
-
var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
|
|
1718
|
-
var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
|
|
1719
|
-
if (shouldCallOnChangeProps) {
|
|
1720
|
-
callOnChangeProps(action, prevState, state);
|
|
1721
|
-
}
|
|
1722
|
-
prevStateRef.current = state;
|
|
1723
|
-
}, [state, action, isStateEqual]);
|
|
1724
|
-
return [state, dispatchWithProps];
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
/**
|
|
1728
|
-
* Wraps the useEnhancedReducer and applies the controlled prop values before
|
|
1729
|
-
* returning the new state.
|
|
1730
|
-
*
|
|
1731
|
-
* @param {Function} reducer Reducer function from downshift.
|
|
1732
|
-
* @param {Object} props The hook props, also passed to createInitialState.
|
|
1733
|
-
* @param {Function} createInitialState Function that returns the initial state.
|
|
1734
|
-
* @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
|
|
1735
|
-
* @returns {Array} An array with the state and an action dispatcher.
|
|
1736
|
-
*/
|
|
1737
|
-
function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
|
|
1738
|
-
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
1739
|
-
state = _useEnhancedReducer[0],
|
|
1740
|
-
dispatch = _useEnhancedReducer[1];
|
|
1741
|
-
return [getState(state, props), dispatch];
|
|
1742
|
-
}
|
|
1743
|
-
var defaultProps$3 = {
|
|
1744
|
-
itemToString: function itemToString(item) {
|
|
1745
|
-
return item ? String(item) : '';
|
|
1746
|
-
},
|
|
1747
|
-
itemToKey: function itemToKey(item) {
|
|
1748
|
-
return item;
|
|
1749
|
-
},
|
|
1750
|
-
stateReducer: stateReducer,
|
|
1751
|
-
scrollIntoView: scrollIntoView,
|
|
1752
|
-
environment: /* istanbul ignore next (ssr) */
|
|
1753
|
-
typeof window === 'undefined' || false ? undefined : window
|
|
1754
|
-
};
|
|
1755
|
-
function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
1756
|
-
if (defaultStateValues === void 0) {
|
|
1757
|
-
defaultStateValues = dropdownDefaultStateValues;
|
|
1758
|
-
}
|
|
1759
|
-
var defaultValue = props["default" + capitalizeString(propKey)];
|
|
1760
|
-
if (defaultValue !== undefined) {
|
|
1761
|
-
return defaultValue;
|
|
1762
|
-
}
|
|
1763
|
-
return defaultStateValues[propKey];
|
|
1764
|
-
}
|
|
1765
|
-
function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
1766
|
-
if (defaultStateValues === void 0) {
|
|
1767
|
-
defaultStateValues = dropdownDefaultStateValues;
|
|
1768
|
-
}
|
|
1769
|
-
var value = props[propKey];
|
|
1770
|
-
if (value !== undefined) {
|
|
1771
|
-
return value;
|
|
1772
|
-
}
|
|
1773
|
-
var initialValue = props["initial" + capitalizeString(propKey)];
|
|
1774
|
-
if (initialValue !== undefined) {
|
|
1775
|
-
return initialValue;
|
|
1776
|
-
}
|
|
1777
|
-
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
1778
|
-
}
|
|
1779
|
-
function getInitialState$2(props) {
|
|
1780
|
-
var selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1781
|
-
var isOpen = getInitialValue$1(props, 'isOpen');
|
|
1971
|
+
function getInitialState$3(props) {
|
|
1972
|
+
var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
|
|
1973
|
+
var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
|
|
1782
1974
|
var highlightedIndex = getInitialHighlightedIndex(props);
|
|
1783
|
-
var inputValue = getInitialValue$1(props, 'inputValue');
|
|
1975
|
+
var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
|
|
1784
1976
|
return {
|
|
1785
1977
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
|
|
1786
1978
|
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
@@ -1830,20 +2022,18 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1830
2022
|
* @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
|
|
1831
2023
|
* @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
|
|
1832
2024
|
*/
|
|
1833
|
-
function useMouseAndTouchTracker(environment, handleBlur,
|
|
1834
|
-
var mouseAndTouchTrackersRef =
|
|
2025
|
+
function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
|
|
2026
|
+
var mouseAndTouchTrackersRef = React__namespace.useRef({
|
|
1835
2027
|
isMouseDown: false,
|
|
1836
2028
|
isTouchMove: false,
|
|
1837
2029
|
isTouchEnd: false
|
|
1838
2030
|
});
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
function getDownshiftElements() {
|
|
1842
|
-
return downshiftElementsRefs.map(function (ref) {
|
|
2031
|
+
var getDownshiftElements = React__namespace.useCallback(function () {
|
|
2032
|
+
return downshiftRefs.map(function (ref) {
|
|
1843
2033
|
return ref.current;
|
|
1844
2034
|
});
|
|
1845
|
-
}
|
|
1846
|
-
|
|
2035
|
+
}, [downshiftRefs]);
|
|
2036
|
+
React__namespace.useEffect(function () {
|
|
1847
2037
|
if (!environment) {
|
|
1848
2038
|
return noop;
|
|
1849
2039
|
}
|
|
@@ -1882,7 +2072,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
|
|
|
1882
2072
|
environment.removeEventListener('touchmove', onTouchMove);
|
|
1883
2073
|
environment.removeEventListener('touchend', onTouchEnd);
|
|
1884
2074
|
};
|
|
1885
|
-
}, [
|
|
2075
|
+
}, [environment, getDownshiftElements, handleBlur]);
|
|
1886
2076
|
return mouseAndTouchTrackersRef.current;
|
|
1887
2077
|
}
|
|
1888
2078
|
|
|
@@ -1903,11 +2093,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1903
2093
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1904
2094
|
propKeys[_key] = arguments[_key];
|
|
1905
2095
|
}
|
|
1906
|
-
var getterPropsCalledRef =
|
|
2096
|
+
var getterPropsCalledRef = React__namespace.useRef(propKeys.reduce(function (acc, propKey) {
|
|
1907
2097
|
acc[propKey] = {};
|
|
1908
2098
|
return acc;
|
|
1909
2099
|
}, {}));
|
|
1910
|
-
|
|
2100
|
+
React__namespace.useEffect(function () {
|
|
1911
2101
|
Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
|
|
1912
2102
|
var propCallInfo = getterPropsCalledRef.current[propKey];
|
|
1913
2103
|
if (!Object.keys(propCallInfo).length) {
|
|
@@ -1924,52 +2114,18 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1924
2114
|
if (!(elementRef != null && elementRef.current)) {
|
|
1925
2115
|
// eslint-disable-next-line no-console
|
|
1926
2116
|
console.error("downshift: The ref prop \"" + refKey + "\" from " + propKey + " was not applied correctly on your element.");
|
|
1927
|
-
}
|
|
1928
|
-
});
|
|
1929
|
-
}, []);
|
|
1930
|
-
var setGetterPropCallInfo =
|
|
1931
|
-
getterPropsCalledRef.current[propKey] = {
|
|
1932
|
-
suppressRefError: suppressRefError,
|
|
1933
|
-
refKey: refKey,
|
|
1934
|
-
elementRef: elementRef
|
|
1935
|
-
};
|
|
1936
|
-
}, []);
|
|
1937
|
-
return setGetterPropCallInfo;
|
|
1938
|
-
};
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
/**
|
|
1942
|
-
* Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1943
|
-
* @param {(options: Object) => string} getA11yStatusMessage The function that builds the status message.
|
|
1944
|
-
* @param {Object} options The options to be passed to getA11yStatusMessage if called.
|
|
1945
|
-
* @param {Array<unknown>} dependencyArray The dependency array that triggers the status message setter via useEffect.
|
|
1946
|
-
* @param {{document: Document}} environment The environment object containing the document.
|
|
1947
|
-
*/
|
|
1948
|
-
function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, environment) {
|
|
1949
|
-
if (environment === void 0) {
|
|
1950
|
-
environment = {};
|
|
1951
|
-
}
|
|
1952
|
-
var document = environment.document;
|
|
1953
|
-
var isInitialMount = useIsInitialMount();
|
|
1954
|
-
|
|
1955
|
-
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1956
|
-
React.useEffect(function () {
|
|
1957
|
-
if (!getA11yStatusMessage || isInitialMount || false || !document) {
|
|
1958
|
-
return;
|
|
1959
|
-
}
|
|
1960
|
-
var status = getA11yStatusMessage(options);
|
|
1961
|
-
updateA11yStatus(status, document);
|
|
1962
|
-
|
|
1963
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1964
|
-
}, dependencyArray);
|
|
1965
|
-
|
|
1966
|
-
// Cleanup the status message container.
|
|
1967
|
-
React.useEffect(function () {
|
|
1968
|
-
return function () {
|
|
1969
|
-
updateA11yStatus.cancel();
|
|
1970
|
-
cleanupStatusDiv(document);
|
|
1971
|
-
};
|
|
1972
|
-
}, [document]);
|
|
2117
|
+
}
|
|
2118
|
+
});
|
|
2119
|
+
}, []);
|
|
2120
|
+
var setGetterPropCallInfo = React__namespace.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
|
|
2121
|
+
getterPropsCalledRef.current[propKey] = {
|
|
2122
|
+
suppressRefError: suppressRefError,
|
|
2123
|
+
refKey: refKey,
|
|
2124
|
+
elementRef: elementRef
|
|
2125
|
+
};
|
|
2126
|
+
}, []);
|
|
2127
|
+
return setGetterPropCallInfo;
|
|
2128
|
+
};
|
|
1973
2129
|
}
|
|
1974
2130
|
function useScrollIntoView(_ref3) {
|
|
1975
2131
|
var highlightedIndex = _ref3.highlightedIndex,
|
|
@@ -1979,7 +2135,7 @@ function useScrollIntoView(_ref3) {
|
|
|
1979
2135
|
menuElement = _ref3.menuElement,
|
|
1980
2136
|
scrollIntoViewProp = _ref3.scrollIntoView;
|
|
1981
2137
|
// used not to scroll on highlight by mouse.
|
|
1982
|
-
var shouldScrollRef =
|
|
2138
|
+
var shouldScrollRef = React__namespace.useRef(true);
|
|
1983
2139
|
// Scroll on highlighted item if change comes from keyboard.
|
|
1984
2140
|
useIsomorphicLayoutEffect(function () {
|
|
1985
2141
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
@@ -2003,9 +2159,9 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2003
2159
|
var props = _ref4.props,
|
|
2004
2160
|
state = _ref4.state;
|
|
2005
2161
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
2006
|
-
var prevPropsRef =
|
|
2162
|
+
var prevPropsRef = React__namespace.useRef(props);
|
|
2007
2163
|
var isInitialMount = useIsInitialMount();
|
|
2008
|
-
|
|
2164
|
+
React__namespace.useEffect(function () {
|
|
2009
2165
|
if (isInitialMount) {
|
|
2010
2166
|
return;
|
|
2011
2167
|
}
|
|
@@ -2034,8 +2190,8 @@ function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
|
2034
2190
|
highlightedIndex: -1
|
|
2035
2191
|
}, shouldSelect && _extends({
|
|
2036
2192
|
selectedItem: props.items[highlightedIndex],
|
|
2037
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2038
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2193
|
+
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
2194
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
|
|
2039
2195
|
}, inputValue && {
|
|
2040
2196
|
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
2041
2197
|
}));
|
|
@@ -2053,20 +2209,6 @@ function isDropdownsStateEqual(prevState, newState) {
|
|
|
2053
2209
|
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
2054
2210
|
}
|
|
2055
2211
|
|
|
2056
|
-
/**
|
|
2057
|
-
* Tracks if it's the first render.
|
|
2058
|
-
*/
|
|
2059
|
-
function useIsInitialMount() {
|
|
2060
|
-
var isInitialMountRef = React.useRef(true);
|
|
2061
|
-
React.useEffect(function () {
|
|
2062
|
-
isInitialMountRef.current = false;
|
|
2063
|
-
return function () {
|
|
2064
|
-
isInitialMountRef.current = true;
|
|
2065
|
-
};
|
|
2066
|
-
}, []);
|
|
2067
|
-
return isInitialMountRef.current;
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
2212
|
/**
|
|
2071
2213
|
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
2072
2214
|
*
|
|
@@ -2074,7 +2216,7 @@ function useIsInitialMount() {
|
|
|
2074
2216
|
* @returns {number} The highlighted index.
|
|
2075
2217
|
*/
|
|
2076
2218
|
function getDefaultHighlightedIndex(props) {
|
|
2077
|
-
var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex');
|
|
2219
|
+
var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
|
|
2078
2220
|
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2079
2221
|
return -1;
|
|
2080
2222
|
}
|
|
@@ -2088,58 +2230,15 @@ function getDefaultHighlightedIndex(props) {
|
|
|
2088
2230
|
* @returns {number} The highlighted index.
|
|
2089
2231
|
*/
|
|
2090
2232
|
function getInitialHighlightedIndex(props) {
|
|
2091
|
-
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
2233
|
+
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
|
|
2092
2234
|
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2093
2235
|
return -1;
|
|
2094
2236
|
}
|
|
2095
2237
|
return highlightedIndex;
|
|
2096
2238
|
}
|
|
2097
2239
|
|
|
2098
|
-
|
|
2099
|
-
var
|
|
2100
|
-
environment: PropTypes.shape({
|
|
2101
|
-
addEventListener: PropTypes.func.isRequired,
|
|
2102
|
-
removeEventListener: PropTypes.func.isRequired,
|
|
2103
|
-
document: PropTypes.shape({
|
|
2104
|
-
createElement: PropTypes.func.isRequired,
|
|
2105
|
-
getElementById: PropTypes.func.isRequired,
|
|
2106
|
-
activeElement: PropTypes.any.isRequired,
|
|
2107
|
-
body: PropTypes.any.isRequired
|
|
2108
|
-
}).isRequired,
|
|
2109
|
-
Node: PropTypes.func.isRequired
|
|
2110
|
-
}),
|
|
2111
|
-
itemToString: PropTypes.func,
|
|
2112
|
-
itemToKey: PropTypes.func,
|
|
2113
|
-
stateReducer: PropTypes.func
|
|
2114
|
-
};
|
|
2115
|
-
|
|
2116
|
-
// Shared between useSelect, useCombobox, Downshift.
|
|
2117
|
-
var commonDropdownPropTypes = _extends({}, commonPropTypes, {
|
|
2118
|
-
getA11yStatusMessage: PropTypes.func,
|
|
2119
|
-
highlightedIndex: PropTypes.number,
|
|
2120
|
-
defaultHighlightedIndex: PropTypes.number,
|
|
2121
|
-
initialHighlightedIndex: PropTypes.number,
|
|
2122
|
-
isOpen: PropTypes.bool,
|
|
2123
|
-
defaultIsOpen: PropTypes.bool,
|
|
2124
|
-
initialIsOpen: PropTypes.bool,
|
|
2125
|
-
selectedItem: PropTypes.any,
|
|
2126
|
-
initialSelectedItem: PropTypes.any,
|
|
2127
|
-
defaultSelectedItem: PropTypes.any,
|
|
2128
|
-
id: PropTypes.string,
|
|
2129
|
-
labelId: PropTypes.string,
|
|
2130
|
-
menuId: PropTypes.string,
|
|
2131
|
-
getItemId: PropTypes.func,
|
|
2132
|
-
toggleButtonId: PropTypes.string,
|
|
2133
|
-
onSelectedItemChange: PropTypes.func,
|
|
2134
|
-
onHighlightedIndexChange: PropTypes.func,
|
|
2135
|
-
onStateChange: PropTypes.func,
|
|
2136
|
-
onIsOpenChange: PropTypes.func,
|
|
2137
|
-
scrollIntoView: PropTypes.func
|
|
2138
|
-
});
|
|
2139
|
-
|
|
2140
|
-
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
2141
|
-
var type = action.type,
|
|
2142
|
-
props = action.props;
|
|
2240
|
+
function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
2241
|
+
var type = action.type;
|
|
2143
2242
|
var changes;
|
|
2144
2243
|
switch (type) {
|
|
2145
2244
|
case stateChangeTypes.ItemMouseMove:
|
|
@@ -2183,9 +2282,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2183
2282
|
case stateChangeTypes.FunctionReset:
|
|
2184
2283
|
changes = {
|
|
2185
2284
|
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2186
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2187
|
-
selectedItem: getDefaultValue$1(props, 'selectedItem'),
|
|
2188
|
-
inputValue: getDefaultValue$1(props, 'inputValue')
|
|
2285
|
+
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
2286
|
+
selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
|
|
2287
|
+
inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
|
|
2189
2288
|
};
|
|
2190
2289
|
break;
|
|
2191
2290
|
default:
|
|
@@ -2195,32 +2294,33 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2195
2294
|
}
|
|
2196
2295
|
/* eslint-enable complexity */
|
|
2197
2296
|
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2297
|
+
var propTypes$3 = _extends({}, propTypes$4, {
|
|
2298
|
+
items: PropTypes.array.isRequired,
|
|
2299
|
+
isItemDisabled: PropTypes.func
|
|
2300
|
+
});
|
|
2301
|
+
|
|
2302
|
+
var defaultProps$2 = _extends({}, defaultProps$3, {
|
|
2303
|
+
isItemDisabled: function isItemDisabled() {
|
|
2304
|
+
return false;
|
|
2305
|
+
}
|
|
2306
|
+
});
|
|
2307
|
+
|
|
2308
|
+
function getItemIndexByCharacterKey(_ref) {
|
|
2309
|
+
var keysSoFar = _ref.keysSoFar,
|
|
2310
|
+
highlightedIndex = _ref.highlightedIndex,
|
|
2311
|
+
items = _ref.items,
|
|
2312
|
+
itemToString = _ref.itemToString,
|
|
2313
|
+
isItemDisabled = _ref.isItemDisabled;
|
|
2314
|
+
var lowerCasedKeysSoFar = keysSoFar.toLowerCase();
|
|
2315
|
+
for (var index = 0; index < items.length; index++) {
|
|
2316
|
+
// if we already have a search query in progress, we also consider the current highlighted item.
|
|
2317
|
+
var offsetIndex = (index + highlightedIndex + (keysSoFar.length < 2 ? 1 : 0)) % items.length;
|
|
2318
|
+
var item = items[offsetIndex];
|
|
2319
|
+
if (item !== undefined && itemToString(item).toLowerCase().startsWith(lowerCasedKeysSoFar) && !isItemDisabled(item, offsetIndex)) {
|
|
2320
|
+
return offsetIndex;
|
|
2210
2321
|
}
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
var propTypes$2 = tslib.__assign(tslib.__assign({}, commonDropdownPropTypes), { items: PropTypes.array.isRequired, isItemDisabled: PropTypes.func });
|
|
2214
|
-
var defaultProps$2 = tslib.__assign(tslib.__assign({}, defaultProps$3), { isItemDisabled: function () {
|
|
2215
|
-
return false;
|
|
2216
|
-
} });
|
|
2217
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
2218
|
-
var validatePropTypes$2 = noop;
|
|
2219
|
-
/* istanbul ignore next */
|
|
2220
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2221
|
-
validatePropTypes$2 = function (options, caller) {
|
|
2222
|
-
PropTypes.checkPropTypes(propTypes$2, options, 'prop', caller.name);
|
|
2223
|
-
};
|
|
2322
|
+
}
|
|
2323
|
+
return highlightedIndex;
|
|
2224
2324
|
}
|
|
2225
2325
|
|
|
2226
2326
|
var ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
|
|
@@ -2246,7 +2346,7 @@ var FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_s
|
|
|
2246
2346
|
var FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
|
|
2247
2347
|
var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
|
|
2248
2348
|
|
|
2249
|
-
var stateChangeTypes$
|
|
2349
|
+
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
2250
2350
|
__proto__: null,
|
|
2251
2351
|
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
2252
2352
|
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
@@ -2273,16 +2373,15 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2273
2373
|
});
|
|
2274
2374
|
|
|
2275
2375
|
/* eslint-disable complexity */
|
|
2276
|
-
function downshiftSelectReducer(state, action) {
|
|
2376
|
+
function downshiftSelectReducer(state, props, action) {
|
|
2277
2377
|
var _props$items;
|
|
2278
2378
|
var type = action.type,
|
|
2279
|
-
props = action.props,
|
|
2280
2379
|
altKey = action.altKey;
|
|
2281
2380
|
var changes;
|
|
2282
2381
|
switch (type) {
|
|
2283
2382
|
case ItemClick$1:
|
|
2284
2383
|
changes = {
|
|
2285
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2384
|
+
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
2286
2385
|
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2287
2386
|
selectedItem: props.items[action.index]
|
|
2288
2387
|
};
|
|
@@ -2375,29 +2474,29 @@ function downshiftSelectReducer(state, action) {
|
|
|
2375
2474
|
};
|
|
2376
2475
|
break;
|
|
2377
2476
|
default:
|
|
2378
|
-
return downshiftCommonReducer(state, action, stateChangeTypes$
|
|
2477
|
+
return downshiftCommonReducer(state, props, action, stateChangeTypes$3);
|
|
2379
2478
|
}
|
|
2380
2479
|
return _extends({}, state, changes);
|
|
2381
2480
|
}
|
|
2382
2481
|
/* eslint-enable complexity */
|
|
2383
2482
|
|
|
2384
|
-
var _excluded$
|
|
2385
|
-
_excluded2$
|
|
2386
|
-
_excluded3$
|
|
2483
|
+
var _excluded$3 = ["onClick"],
|
|
2484
|
+
_excluded2$3 = ["onMouseLeave", "refKey", "ref"],
|
|
2485
|
+
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
|
|
2387
2486
|
_excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
|
|
2388
|
-
useSelect.stateChangeTypes = stateChangeTypes$
|
|
2487
|
+
useSelect.stateChangeTypes = stateChangeTypes$3;
|
|
2389
2488
|
function useSelect(userProps) {
|
|
2390
2489
|
if (userProps === void 0) {
|
|
2391
2490
|
userProps = {};
|
|
2392
2491
|
}
|
|
2393
|
-
validatePropTypes$
|
|
2492
|
+
validatePropTypes$1(userProps, useSelect, propTypes$3);
|
|
2394
2493
|
// Props defaults and destructuring.
|
|
2395
2494
|
var props = _extends({}, defaultProps$2, userProps);
|
|
2396
2495
|
var scrollIntoView = props.scrollIntoView,
|
|
2397
2496
|
environment = props.environment,
|
|
2398
2497
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2399
2498
|
// Initial state depending on controlled props.
|
|
2400
|
-
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$
|
|
2499
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
|
|
2401
2500
|
state = _useControlledReducer[0],
|
|
2402
2501
|
dispatch = _useControlledReducer[1];
|
|
2403
2502
|
var isOpen = state.isOpen,
|
|
@@ -2412,7 +2511,7 @@ function useSelect(userProps) {
|
|
|
2412
2511
|
// used to keep the inputValue clearTimeout object between renders.
|
|
2413
2512
|
var clearTimeoutRef = React.useRef(null);
|
|
2414
2513
|
// prevent id re-generation between renders.
|
|
2415
|
-
var elementIds = useElementIds(props);
|
|
2514
|
+
var elementIds = useElementIds$1(props);
|
|
2416
2515
|
// utility callback to get item element.
|
|
2417
2516
|
var latest = useLatestRef({
|
|
2418
2517
|
state: state,
|
|
@@ -2464,23 +2563,23 @@ function useSelect(userProps) {
|
|
|
2464
2563
|
});
|
|
2465
2564
|
// Focus the toggle button on first render if required.
|
|
2466
2565
|
React.useEffect(function () {
|
|
2467
|
-
var focusOnOpen = getInitialValue$1(props, 'isOpen');
|
|
2566
|
+
var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
|
|
2468
2567
|
if (focusOnOpen && toggleButtonRef.current) {
|
|
2469
2568
|
toggleButtonRef.current.focus();
|
|
2470
2569
|
}
|
|
2471
2570
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2472
2571
|
}, []);
|
|
2473
|
-
var
|
|
2572
|
+
var handleBlurInTracker = React.useCallback(function handleBlur() {
|
|
2474
2573
|
if (latest.current.state.isOpen) {
|
|
2475
2574
|
dispatch({
|
|
2476
2575
|
type: ToggleButtonBlur
|
|
2477
2576
|
});
|
|
2478
2577
|
}
|
|
2479
|
-
}, [dispatch, latest])
|
|
2578
|
+
}, [dispatch, latest]);
|
|
2579
|
+
var downshiftRefs = React.useMemo(function () {
|
|
2480
2580
|
return [menuRef, toggleButtonRef];
|
|
2481
|
-
},
|
|
2482
|
-
|
|
2483
|
-
[]));
|
|
2581
|
+
}, []);
|
|
2582
|
+
var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, handleBlurInTracker, downshiftRefs);
|
|
2484
2583
|
var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
|
|
2485
2584
|
// Reset itemRefs on close.
|
|
2486
2585
|
React.useEffect(function () {
|
|
@@ -2613,7 +2712,7 @@ function useSelect(userProps) {
|
|
|
2613
2712
|
var getLabelProps = React.useCallback(function (_temp) {
|
|
2614
2713
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
2615
2714
|
onClick = _ref.onClick,
|
|
2616
|
-
labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
2715
|
+
labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2617
2716
|
var labelHandleClick = function labelHandleClick() {
|
|
2618
2717
|
var _toggleButtonRef$curr;
|
|
2619
2718
|
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
@@ -2631,7 +2730,7 @@ function useSelect(userProps) {
|
|
|
2631
2730
|
_ref2$refKey = _ref2.refKey,
|
|
2632
2731
|
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
2633
2732
|
ref = _ref2.ref,
|
|
2634
|
-
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$
|
|
2733
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
|
|
2635
2734
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
2636
2735
|
_ref3$suppressRefErro = _ref3.suppressRefError,
|
|
2637
2736
|
suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
|
|
@@ -2655,7 +2754,7 @@ function useSelect(userProps) {
|
|
|
2655
2754
|
_ref4$refKey = _ref4.refKey,
|
|
2656
2755
|
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
2657
2756
|
ref = _ref4.ref,
|
|
2658
|
-
rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$
|
|
2757
|
+
rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
|
|
2659
2758
|
var _ref5 = _temp5 === void 0 ? {} : _temp5,
|
|
2660
2759
|
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
2661
2760
|
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
@@ -2802,7 +2901,7 @@ var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_
|
|
|
2802
2901
|
var FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
|
|
2803
2902
|
var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 22;
|
|
2804
2903
|
|
|
2805
|
-
var stateChangeTypes$
|
|
2904
|
+
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2806
2905
|
__proto__: null,
|
|
2807
2906
|
ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem,
|
|
2808
2907
|
FunctionCloseMenu: FunctionCloseMenu,
|
|
@@ -2829,8 +2928,8 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
2829
2928
|
ToggleButtonClick: ToggleButtonClick
|
|
2830
2929
|
});
|
|
2831
2930
|
|
|
2832
|
-
function getInitialState$
|
|
2833
|
-
var initialState = getInitialState$
|
|
2931
|
+
function getInitialState$2(props) {
|
|
2932
|
+
var initialState = getInitialState$3(props);
|
|
2834
2933
|
var selectedItem = initialState.selectedItem;
|
|
2835
2934
|
var inputValue = initialState.inputValue;
|
|
2836
2935
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
@@ -2840,7 +2939,7 @@ function getInitialState$1(props) {
|
|
|
2840
2939
|
inputValue: inputValue
|
|
2841
2940
|
});
|
|
2842
2941
|
}
|
|
2843
|
-
var propTypes$
|
|
2942
|
+
var propTypes$2 = _extends({}, propTypes$4, {
|
|
2844
2943
|
items: PropTypes.array.isRequired,
|
|
2845
2944
|
isItemDisabled: PropTypes.func,
|
|
2846
2945
|
inputValue: PropTypes.string,
|
|
@@ -2888,15 +2987,6 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
|
|
|
2888
2987
|
}, [state.selectedItem, props.selectedItem]);
|
|
2889
2988
|
return [getState(state, props), dispatch];
|
|
2890
2989
|
}
|
|
2891
|
-
|
|
2892
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
2893
|
-
var validatePropTypes$1 = noop;
|
|
2894
|
-
/* istanbul ignore next */
|
|
2895
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2896
|
-
validatePropTypes$1 = function validatePropTypes(options, caller) {
|
|
2897
|
-
PropTypes.checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
2898
|
-
};
|
|
2899
|
-
}
|
|
2900
2990
|
var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
2901
2991
|
isItemDisabled: function isItemDisabled() {
|
|
2902
2992
|
return false;
|
|
@@ -2904,16 +2994,15 @@ var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
|
2904
2994
|
});
|
|
2905
2995
|
|
|
2906
2996
|
/* eslint-disable complexity */
|
|
2907
|
-
function downshiftUseComboboxReducer(state, action) {
|
|
2997
|
+
function downshiftUseComboboxReducer(state, props, action) {
|
|
2908
2998
|
var _props$items;
|
|
2909
2999
|
var type = action.type,
|
|
2910
|
-
props = action.props,
|
|
2911
3000
|
altKey = action.altKey;
|
|
2912
3001
|
var changes;
|
|
2913
3002
|
switch (type) {
|
|
2914
3003
|
case ItemClick:
|
|
2915
3004
|
changes = {
|
|
2916
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3005
|
+
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
2917
3006
|
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2918
3007
|
selectedItem: props.items[action.index],
|
|
2919
3008
|
inputValue: props.itemToString(props.items[action.index])
|
|
@@ -3013,22 +3102,22 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3013
3102
|
};
|
|
3014
3103
|
break;
|
|
3015
3104
|
default:
|
|
3016
|
-
return downshiftCommonReducer(state, action, stateChangeTypes$
|
|
3105
|
+
return downshiftCommonReducer(state, props, action, stateChangeTypes$2);
|
|
3017
3106
|
}
|
|
3018
3107
|
return _extends({}, state, changes);
|
|
3019
3108
|
}
|
|
3020
3109
|
/* eslint-enable complexity */
|
|
3021
3110
|
|
|
3022
|
-
var _excluded$
|
|
3023
|
-
_excluded2$
|
|
3024
|
-
_excluded3 = ["onClick", "onPress", "refKey", "ref"],
|
|
3111
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
3112
|
+
_excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
3113
|
+
_excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
|
|
3025
3114
|
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
3026
|
-
useCombobox.stateChangeTypes = stateChangeTypes$
|
|
3115
|
+
useCombobox.stateChangeTypes = stateChangeTypes$2;
|
|
3027
3116
|
function useCombobox(userProps) {
|
|
3028
3117
|
if (userProps === void 0) {
|
|
3029
3118
|
userProps = {};
|
|
3030
3119
|
}
|
|
3031
|
-
validatePropTypes$1(userProps, useCombobox);
|
|
3120
|
+
validatePropTypes$1(userProps, useCombobox, propTypes$2);
|
|
3032
3121
|
// Props defaults and destructuring.
|
|
3033
3122
|
var props = _extends({}, defaultProps$1, userProps);
|
|
3034
3123
|
var items = props.items,
|
|
@@ -3036,7 +3125,7 @@ function useCombobox(userProps) {
|
|
|
3036
3125
|
environment = props.environment,
|
|
3037
3126
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3038
3127
|
// Initial state depending on controlled props.
|
|
3039
|
-
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$
|
|
3128
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
|
|
3040
3129
|
state = _useControlledReducer[0],
|
|
3041
3130
|
dispatch = _useControlledReducer[1];
|
|
3042
3131
|
var isOpen = state.isOpen,
|
|
@@ -3052,7 +3141,7 @@ function useCombobox(userProps) {
|
|
|
3052
3141
|
var isInitialMount = useIsInitialMount();
|
|
3053
3142
|
|
|
3054
3143
|
// prevent id re-generation between renders.
|
|
3055
|
-
var elementIds = useElementIds(props);
|
|
3144
|
+
var elementIds = useElementIds$1(props);
|
|
3056
3145
|
// used to keep track of how many items we had on previous cycle.
|
|
3057
3146
|
var previousResultCountRef = React.useRef();
|
|
3058
3147
|
// utility callback to get item element.
|
|
@@ -3082,7 +3171,7 @@ function useCombobox(userProps) {
|
|
|
3082
3171
|
});
|
|
3083
3172
|
// Focus the input on first render if required.
|
|
3084
3173
|
React.useEffect(function () {
|
|
3085
|
-
var focusOnOpen = getInitialValue$1(props, 'isOpen');
|
|
3174
|
+
var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
|
|
3086
3175
|
if (focusOnOpen && inputRef.current) {
|
|
3087
3176
|
inputRef.current.focus();
|
|
3088
3177
|
}
|
|
@@ -3093,18 +3182,17 @@ function useCombobox(userProps) {
|
|
|
3093
3182
|
previousResultCountRef.current = items.length;
|
|
3094
3183
|
}
|
|
3095
3184
|
});
|
|
3096
|
-
var
|
|
3185
|
+
var handleBlurInTracker = React.useCallback(function handleBlur() {
|
|
3097
3186
|
if (latest.current.state.isOpen) {
|
|
3098
3187
|
dispatch({
|
|
3099
|
-
type: InputBlur
|
|
3100
|
-
selectItem: false
|
|
3188
|
+
type: InputBlur
|
|
3101
3189
|
});
|
|
3102
3190
|
}
|
|
3103
|
-
}, [dispatch, latest])
|
|
3191
|
+
}, [dispatch, latest]);
|
|
3192
|
+
var downshiftRefs = React.useMemo(function () {
|
|
3104
3193
|
return [menuRef, toggleButtonRef, inputRef];
|
|
3105
|
-
},
|
|
3106
|
-
|
|
3107
|
-
[]));
|
|
3194
|
+
}, []);
|
|
3195
|
+
var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, handleBlurInTracker, downshiftRefs);
|
|
3108
3196
|
var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
|
|
3109
3197
|
// Reset itemRefs on close.
|
|
3110
3198
|
React.useEffect(function () {
|
|
@@ -3212,7 +3300,7 @@ function useCombobox(userProps) {
|
|
|
3212
3300
|
_ref$refKey = _ref.refKey,
|
|
3213
3301
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3214
3302
|
ref = _ref.ref,
|
|
3215
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
3303
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
3216
3304
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
3217
3305
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3218
3306
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
@@ -3238,7 +3326,7 @@ function useCombobox(userProps) {
|
|
|
3238
3326
|
onClick = _ref3.onClick;
|
|
3239
3327
|
_ref3.onPress;
|
|
3240
3328
|
var disabledProp = _ref3.disabled,
|
|
3241
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$
|
|
3329
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$2);
|
|
3242
3330
|
if (disabledProp !== undefined) {
|
|
3243
3331
|
console.warn('Passing "disabled" as an argument to getItemProps is not supported anymore. Please use the isItemDisabled prop from useCombobox.');
|
|
3244
3332
|
}
|
|
@@ -3289,7 +3377,7 @@ function useCombobox(userProps) {
|
|
|
3289
3377
|
var _ref5$refKey = _ref5.refKey,
|
|
3290
3378
|
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3291
3379
|
ref = _ref5.ref,
|
|
3292
|
-
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3);
|
|
3380
|
+
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
|
|
3293
3381
|
var latestState = latest.current.state;
|
|
3294
3382
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3295
3383
|
dispatch({
|
|
@@ -3459,7 +3547,7 @@ function getDefaultValue(props, propKey) {
|
|
|
3459
3547
|
* @param {Object} props Props passed to the hook.
|
|
3460
3548
|
* @returns {Object} The initial state.
|
|
3461
3549
|
*/
|
|
3462
|
-
function getInitialState(props) {
|
|
3550
|
+
function getInitialState$1(props) {
|
|
3463
3551
|
var activeIndex = getInitialValue(props, 'activeIndex');
|
|
3464
3552
|
var selectedItems = getInitialValue(props, 'selectedItems');
|
|
3465
3553
|
return {
|
|
@@ -3501,13 +3589,13 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3501
3589
|
* @param {Object} newState
|
|
3502
3590
|
* @returns {boolean} Wheather the states are deeply equal.
|
|
3503
3591
|
*/
|
|
3504
|
-
function isStateEqual(prevState, newState) {
|
|
3592
|
+
function isStateEqual$1(prevState, newState) {
|
|
3505
3593
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3506
3594
|
}
|
|
3507
|
-
var propTypes = {
|
|
3508
|
-
stateReducer:
|
|
3509
|
-
itemToKey:
|
|
3510
|
-
environment:
|
|
3595
|
+
var propTypes$1 = {
|
|
3596
|
+
stateReducer: propTypes$4.stateReducer,
|
|
3597
|
+
itemToKey: propTypes$4.itemToKey,
|
|
3598
|
+
environment: propTypes$4.environment,
|
|
3511
3599
|
selectedItems: PropTypes.array,
|
|
3512
3600
|
initialSelectedItems: PropTypes.array,
|
|
3513
3601
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3533,7 +3621,7 @@ var validatePropTypes = noop;
|
|
|
3533
3621
|
/* istanbul ignore next */
|
|
3534
3622
|
if (process.env.NODE_ENV !== 'production') {
|
|
3535
3623
|
validatePropTypes = function validatePropTypes(options, caller) {
|
|
3536
|
-
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
3624
|
+
PropTypes.checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
3537
3625
|
};
|
|
3538
3626
|
}
|
|
3539
3627
|
|
|
@@ -3551,7 +3639,7 @@ var FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__functi
|
|
|
3551
3639
|
var FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
|
|
3552
3640
|
var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
|
|
3553
3641
|
|
|
3554
|
-
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3642
|
+
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
3555
3643
|
__proto__: null,
|
|
3556
3644
|
DropdownClick: DropdownClick,
|
|
3557
3645
|
DropdownKeyDownBackspace: DropdownKeyDownBackspace,
|
|
@@ -3569,10 +3657,9 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3569
3657
|
});
|
|
3570
3658
|
|
|
3571
3659
|
/* eslint-disable complexity */
|
|
3572
|
-
function downshiftMultipleSelectionReducer(state, action) {
|
|
3660
|
+
function downshiftMultipleSelectionReducer(state, props, action) {
|
|
3573
3661
|
var type = action.type,
|
|
3574
3662
|
index = action.index,
|
|
3575
|
-
props = action.props,
|
|
3576
3663
|
selectedItem = action.selectedItem;
|
|
3577
3664
|
var activeIndex = state.activeIndex,
|
|
3578
3665
|
selectedItems = state.selectedItems;
|
|
@@ -3680,9 +3767,9 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3680
3767
|
return _extends({}, state, changes);
|
|
3681
3768
|
}
|
|
3682
3769
|
|
|
3683
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
3684
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
3685
|
-
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
3770
|
+
var _excluded$1 = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
3771
|
+
_excluded2$1 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
3772
|
+
useMultipleSelection.stateChangeTypes = stateChangeTypes$1;
|
|
3686
3773
|
function useMultipleSelection(userProps) {
|
|
3687
3774
|
if (userProps === void 0) {
|
|
3688
3775
|
userProps = {};
|
|
@@ -3696,7 +3783,7 @@ function useMultipleSelection(userProps) {
|
|
|
3696
3783
|
keyNavigationPrevious = props.keyNavigationPrevious;
|
|
3697
3784
|
|
|
3698
3785
|
// Reducer init.
|
|
3699
|
-
var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, props, getInitialState, isStateEqual),
|
|
3786
|
+
var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, props, getInitialState$1, isStateEqual$1),
|
|
3700
3787
|
state = _useControlledReducer[0],
|
|
3701
3788
|
dispatch = _useControlledReducer[1];
|
|
3702
3789
|
var activeIndex = state.activeIndex,
|
|
@@ -3782,7 +3869,7 @@ function useMultipleSelection(userProps) {
|
|
|
3782
3869
|
onKeyDown = _ref3.onKeyDown,
|
|
3783
3870
|
selectedItemProp = _ref3.selectedItem,
|
|
3784
3871
|
indexProp = _ref3.index,
|
|
3785
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
3872
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
|
|
3786
3873
|
var latestState = latest.current.state;
|
|
3787
3874
|
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
3788
3875
|
index = _getItemAndIndex[1];
|
|
@@ -3815,7 +3902,7 @@ function useMultipleSelection(userProps) {
|
|
|
3815
3902
|
onClick = _ref4.onClick,
|
|
3816
3903
|
_ref4$preventKeyActio = _ref4.preventKeyAction,
|
|
3817
3904
|
preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
|
|
3818
|
-
rest = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
3905
|
+
rest = _objectWithoutPropertiesLoose(_ref4, _excluded2$1);
|
|
3819
3906
|
var _ref5 = _temp3 === void 0 ? {} : _temp3,
|
|
3820
3907
|
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
3821
3908
|
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
@@ -3884,8 +3971,333 @@ function useMultipleSelection(userProps) {
|
|
|
3884
3971
|
};
|
|
3885
3972
|
}
|
|
3886
3973
|
|
|
3974
|
+
var TagClick = process.env.NODE_ENV !== "production" ? '__tag_click__' : 0;
|
|
3975
|
+
var TagGroupKeyDownArrowLeft = process.env.NODE_ENV !== "production" ? '__taggroup_keydown_arrowleft__' : 1;
|
|
3976
|
+
var TagGroupKeyDownArrowRight = process.env.NODE_ENV !== "production" ? '__taggroup_keydown_arrowright__' : 2;
|
|
3977
|
+
var TagGroupKeyDownDelete = process.env.NODE_ENV !== "production" ? '__taggroup_keydown_delete__' : 3;
|
|
3978
|
+
var TagGroupKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__taggroup_keydown_backspace__' : 4;
|
|
3979
|
+
var TagRemoveClick = process.env.NODE_ENV !== "production" ? '__tagremove_click__' : 5;
|
|
3980
|
+
var FunctionAddItem = process.env.NODE_ENV !== "production" ? '__function_add_item__' : 6;
|
|
3981
|
+
|
|
3982
|
+
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3983
|
+
__proto__: null,
|
|
3984
|
+
FunctionAddItem: FunctionAddItem,
|
|
3985
|
+
TagClick: TagClick,
|
|
3986
|
+
TagGroupKeyDownArrowLeft: TagGroupKeyDownArrowLeft,
|
|
3987
|
+
TagGroupKeyDownArrowRight: TagGroupKeyDownArrowRight,
|
|
3988
|
+
TagGroupKeyDownBackspace: TagGroupKeyDownBackspace,
|
|
3989
|
+
TagGroupKeyDownDelete: TagGroupKeyDownDelete,
|
|
3990
|
+
TagRemoveClick: TagRemoveClick
|
|
3991
|
+
});
|
|
3992
|
+
|
|
3993
|
+
function useTagGroupReducer(state, _props, action) {
|
|
3994
|
+
var type = action.type;
|
|
3995
|
+
var changes;
|
|
3996
|
+
switch (type) {
|
|
3997
|
+
case TagClick:
|
|
3998
|
+
changes = {
|
|
3999
|
+
activeIndex: action.index
|
|
4000
|
+
};
|
|
4001
|
+
break;
|
|
4002
|
+
case TagGroupKeyDownArrowLeft:
|
|
4003
|
+
changes = {
|
|
4004
|
+
activeIndex: state.activeIndex === 0 ? state.items.length - 1 : state.activeIndex - 1
|
|
4005
|
+
};
|
|
4006
|
+
break;
|
|
4007
|
+
case TagGroupKeyDownArrowRight:
|
|
4008
|
+
changes = {
|
|
4009
|
+
activeIndex: state.activeIndex === state.items.length - 1 ? 0 : state.activeIndex + 1
|
|
4010
|
+
};
|
|
4011
|
+
break;
|
|
4012
|
+
case TagGroupKeyDownBackspace:
|
|
4013
|
+
case TagGroupKeyDownDelete:
|
|
4014
|
+
{
|
|
4015
|
+
var newItems = [].concat(state.items.slice(0, state.activeIndex), state.items.slice(state.activeIndex + 1));
|
|
4016
|
+
var newActiveIndex = newItems.length === 0 ? -1 : newItems.length === state.activeIndex ? state.activeIndex - 1 : state.activeIndex;
|
|
4017
|
+
changes = {
|
|
4018
|
+
items: [].concat(state.items.slice(0, state.activeIndex), state.items.slice(state.activeIndex + 1)),
|
|
4019
|
+
activeIndex: newActiveIndex
|
|
4020
|
+
};
|
|
4021
|
+
break;
|
|
4022
|
+
}
|
|
4023
|
+
case TagRemoveClick:
|
|
4024
|
+
{
|
|
4025
|
+
var _newItems = [].concat(state.items.slice(0, action.index), state.items.slice(action.index + 1));
|
|
4026
|
+
var _newActiveIndex = _newItems.length === 0 ? -1 : _newItems.length === action.index ? action.index - 1 : action.index;
|
|
4027
|
+
changes = {
|
|
4028
|
+
items: _newItems,
|
|
4029
|
+
activeIndex: _newActiveIndex
|
|
4030
|
+
};
|
|
4031
|
+
}
|
|
4032
|
+
break;
|
|
4033
|
+
case FunctionAddItem:
|
|
4034
|
+
{
|
|
4035
|
+
var _newItems2 = [];
|
|
4036
|
+
if (action.index === undefined) {
|
|
4037
|
+
_newItems2 = [].concat(state.items, [action.item]);
|
|
4038
|
+
} else {
|
|
4039
|
+
_newItems2 = [].concat(state.items.slice(0, action.index), [action.item], state.items.slice(action.index));
|
|
4040
|
+
}
|
|
4041
|
+
var _newActiveIndex2 = state.activeIndex === -1 ? _newItems2.length - 1 : state.activeIndex;
|
|
4042
|
+
changes = {
|
|
4043
|
+
items: _newItems2,
|
|
4044
|
+
activeIndex: _newActiveIndex2
|
|
4045
|
+
};
|
|
4046
|
+
break;
|
|
4047
|
+
}
|
|
4048
|
+
default:
|
|
4049
|
+
throw new Error('Invalid useTagGroup reducer action.');
|
|
4050
|
+
}
|
|
4051
|
+
return _extends({}, state, changes);
|
|
4052
|
+
}
|
|
4053
|
+
|
|
4054
|
+
// istanbul ignore next
|
|
4055
|
+
var useElementIds = 'useId' in React__namespace // Avoid conditional useId call
|
|
4056
|
+
? useElementIdsR18 : useElementIdsLegacy;
|
|
4057
|
+
function useElementIdsR18(_ref) {
|
|
4058
|
+
var id = _ref.id,
|
|
4059
|
+
tagGroupId = _ref.tagGroupId,
|
|
4060
|
+
getTagId = _ref.getTagId;
|
|
4061
|
+
// Avoid conditional useId call
|
|
4062
|
+
var reactId = "downshift-" + React__namespace.useId();
|
|
4063
|
+
if (!id) {
|
|
4064
|
+
id = reactId;
|
|
4065
|
+
}
|
|
4066
|
+
var elementIdsRef = React__namespace.useRef({
|
|
4067
|
+
tagGroupId: tagGroupId != null ? tagGroupId : id + "-tag-group",
|
|
4068
|
+
getTagId: getTagId != null ? getTagId : function (index) {
|
|
4069
|
+
return id + "-tag-" + index;
|
|
4070
|
+
}
|
|
4071
|
+
});
|
|
4072
|
+
return elementIdsRef.current;
|
|
4073
|
+
}
|
|
4074
|
+
function useElementIdsLegacy(_ref2) {
|
|
4075
|
+
var _ref2$id = _ref2.id,
|
|
4076
|
+
id = _ref2$id === void 0 ? "downshift-" + generateId() : _ref2$id,
|
|
4077
|
+
getTagId = _ref2.getTagId,
|
|
4078
|
+
tagGroupId = _ref2.tagGroupId;
|
|
4079
|
+
var elementIdsRef = React__namespace.useRef({
|
|
4080
|
+
tagGroupId: tagGroupId != null ? tagGroupId : id + "-tag-group",
|
|
4081
|
+
getTagId: getTagId != null ? getTagId : function (index) {
|
|
4082
|
+
return id + "-tag-" + index;
|
|
4083
|
+
}
|
|
4084
|
+
});
|
|
4085
|
+
return elementIdsRef.current;
|
|
4086
|
+
}
|
|
4087
|
+
|
|
4088
|
+
function getInitialState(props) {
|
|
4089
|
+
var _ref, _props$items, _ref2, _props$activeIndex;
|
|
4090
|
+
var items = (_ref = (_props$items = props.items) != null ? _props$items : props.initialItems) != null ? _ref : [];
|
|
4091
|
+
var activeIndex = (_ref2 = (_props$activeIndex = props.activeIndex) != null ? _props$activeIndex : props.initialActiveIndex) != null ? _ref2 : items.length === 0 ? -1 : 0;
|
|
4092
|
+
return {
|
|
4093
|
+
activeIndex: activeIndex,
|
|
4094
|
+
items: items
|
|
4095
|
+
};
|
|
4096
|
+
}
|
|
4097
|
+
|
|
4098
|
+
function isStateEqual(oldState, newState) {
|
|
4099
|
+
return oldState.activeIndex === newState.activeIndex && oldState.items === newState.items;
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
var A11Y_DESCRIPTION_ELEMENT_ID = 'tag-group-a11y-description';
|
|
4103
|
+
function useAccessibleDescription(document, description) {
|
|
4104
|
+
React__namespace.useEffect(function () {
|
|
4105
|
+
if (!document) {
|
|
4106
|
+
return;
|
|
4107
|
+
}
|
|
4108
|
+
var accessibleDescriptionElement = document.createElement('div');
|
|
4109
|
+
accessibleDescriptionElement.setAttribute('id', A11Y_DESCRIPTION_ELEMENT_ID);
|
|
4110
|
+
accessibleDescriptionElement.style.display = 'none';
|
|
4111
|
+
accessibleDescriptionElement.textContent = description;
|
|
4112
|
+
document.body.appendChild(accessibleDescriptionElement);
|
|
4113
|
+
return function () {
|
|
4114
|
+
accessibleDescriptionElement.remove();
|
|
4115
|
+
};
|
|
4116
|
+
}, [description, document]);
|
|
4117
|
+
}
|
|
4118
|
+
|
|
4119
|
+
function getMergedProps(userProps) {
|
|
4120
|
+
return _extends({
|
|
4121
|
+
stateReducer: function stateReducer(_s, _ref) {
|
|
4122
|
+
var changes = _ref.changes;
|
|
4123
|
+
return changes;
|
|
4124
|
+
},
|
|
4125
|
+
environment: /* istanbul ignore next (ssr) */
|
|
4126
|
+
typeof window === 'undefined' || false ? undefined : window,
|
|
4127
|
+
removeElementDescription: 'Press Delete to remove tag.'
|
|
4128
|
+
}, userProps);
|
|
4129
|
+
}
|
|
4130
|
+
|
|
4131
|
+
var propTypes = {
|
|
4132
|
+
isItemDisabled: PropTypes.func
|
|
4133
|
+
};
|
|
4134
|
+
|
|
4135
|
+
var _excluded = ["onKeyDown"],
|
|
4136
|
+
_excluded2 = ["index", "refKey", "ref", "onClick"],
|
|
4137
|
+
_excluded3 = ["index", "onClick"];
|
|
4138
|
+
var _useTagGroup = function useTagGroup(userProps) {
|
|
4139
|
+
var _props$environment;
|
|
4140
|
+
if (userProps === void 0) {
|
|
4141
|
+
userProps = {};
|
|
4142
|
+
}
|
|
4143
|
+
/* State and Props */
|
|
4144
|
+
|
|
4145
|
+
validatePropTypes$1(userProps, _useTagGroup, propTypes);
|
|
4146
|
+
var props = getMergedProps(userProps);
|
|
4147
|
+
var _useControlledReducer = useControlledReducer$1(useTagGroupReducer, props, getInitialState, isStateEqual),
|
|
4148
|
+
state = _useControlledReducer[0],
|
|
4149
|
+
dispatch = _useControlledReducer[1];
|
|
4150
|
+
var activeIndex = state.activeIndex,
|
|
4151
|
+
items = state.items;
|
|
4152
|
+
|
|
4153
|
+
/* Refs */
|
|
4154
|
+
|
|
4155
|
+
var latest = useLatestRef({
|
|
4156
|
+
state: state,
|
|
4157
|
+
props: props
|
|
4158
|
+
});
|
|
4159
|
+
var elementIds = useElementIds({
|
|
4160
|
+
getTagId: props.getTagId,
|
|
4161
|
+
id: props.id,
|
|
4162
|
+
tagGroupId: props.tagGroupId
|
|
4163
|
+
});
|
|
4164
|
+
var itemRefs = React.useRef({});
|
|
4165
|
+
var previousItemsLengthRef = React.useRef(items.length);
|
|
4166
|
+
var isInitialMount = useIsInitialMount();
|
|
4167
|
+
|
|
4168
|
+
/* Effects */
|
|
4169
|
+
|
|
4170
|
+
useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
|
|
4171
|
+
React.useEffect(function () {
|
|
4172
|
+
if (isInitialMount) {
|
|
4173
|
+
return;
|
|
4174
|
+
}
|
|
4175
|
+
if (previousItemsLengthRef.current < items.length) {
|
|
4176
|
+
return;
|
|
4177
|
+
}
|
|
4178
|
+
if (activeIndex >= 0 && activeIndex < Object.keys(itemRefs.current).length) {
|
|
4179
|
+
var _itemRefs$current$ele;
|
|
4180
|
+
(_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
|
|
4181
|
+
}
|
|
4182
|
+
}, [activeIndex, elementIds, isInitialMount, items.length]);
|
|
4183
|
+
React.useEffect(function () {
|
|
4184
|
+
previousItemsLengthRef.current = items.length;
|
|
4185
|
+
});
|
|
4186
|
+
|
|
4187
|
+
/* Getter functions */
|
|
4188
|
+
|
|
4189
|
+
var getTagGroupProps = React.useCallback(function (options) {
|
|
4190
|
+
var _ref = options != null ? options : {},
|
|
4191
|
+
onKeyDown = _ref.onKeyDown,
|
|
4192
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
4193
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
4194
|
+
switch (e.key) {
|
|
4195
|
+
case 'ArrowLeft':
|
|
4196
|
+
dispatch({
|
|
4197
|
+
type: TagGroupKeyDownArrowLeft
|
|
4198
|
+
});
|
|
4199
|
+
break;
|
|
4200
|
+
case 'ArrowRight':
|
|
4201
|
+
dispatch({
|
|
4202
|
+
type: TagGroupKeyDownArrowRight
|
|
4203
|
+
});
|
|
4204
|
+
break;
|
|
4205
|
+
case 'Delete':
|
|
4206
|
+
dispatch({
|
|
4207
|
+
type: TagGroupKeyDownDelete
|
|
4208
|
+
});
|
|
4209
|
+
break;
|
|
4210
|
+
case 'Backspace':
|
|
4211
|
+
dispatch({
|
|
4212
|
+
type: TagGroupKeyDownBackspace
|
|
4213
|
+
});
|
|
4214
|
+
break;
|
|
4215
|
+
}
|
|
4216
|
+
};
|
|
4217
|
+
var tagGroupProps = _extends({
|
|
4218
|
+
id: elementIds.tagGroupId,
|
|
4219
|
+
'aria-live': 'polite',
|
|
4220
|
+
'aria-atomic': 'false',
|
|
4221
|
+
'aria-relevant': 'additions',
|
|
4222
|
+
role: 'listbox',
|
|
4223
|
+
onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
|
|
4224
|
+
}, rest);
|
|
4225
|
+
return tagGroupProps;
|
|
4226
|
+
}, [dispatch, elementIds.tagGroupId]);
|
|
4227
|
+
var getTagProps = React.useCallback(function (options) {
|
|
4228
|
+
var _extends2;
|
|
4229
|
+
var index = options.index,
|
|
4230
|
+
_options$refKey = options.refKey,
|
|
4231
|
+
refKey = _options$refKey === void 0 ? 'ref' : _options$refKey,
|
|
4232
|
+
ref = options.ref,
|
|
4233
|
+
onClick = options.onClick,
|
|
4234
|
+
rest = _objectWithoutPropertiesLoose(options, _excluded2);
|
|
4235
|
+
if (!Number.isInteger(index) || index < 0) {
|
|
4236
|
+
throw new Error('Pass correct item index to getTagProps!');
|
|
4237
|
+
}
|
|
4238
|
+
var latestState = latest.current.state;
|
|
4239
|
+
var handleClick = function handleClick() {
|
|
4240
|
+
dispatch({
|
|
4241
|
+
type: TagClick,
|
|
4242
|
+
index: index
|
|
4243
|
+
});
|
|
4244
|
+
};
|
|
4245
|
+
var tagId = elementIds.getTagId(index);
|
|
4246
|
+
return _extends((_extends2 = {
|
|
4247
|
+
'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
|
|
4248
|
+
}, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
|
|
4249
|
+
if (itemNode) {
|
|
4250
|
+
itemRefs.current[tagId] = itemNode;
|
|
4251
|
+
}
|
|
4252
|
+
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4253
|
+
}, [dispatch, elementIds, latest]);
|
|
4254
|
+
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4255
|
+
var index = options.index,
|
|
4256
|
+
onClick = options.onClick,
|
|
4257
|
+
rest = _objectWithoutPropertiesLoose(options, _excluded3);
|
|
4258
|
+
if (!Number.isInteger(index) || index < 0) {
|
|
4259
|
+
throw new Error('Pass correct item index to getTagRemoveProps!');
|
|
4260
|
+
}
|
|
4261
|
+
var handleClick = function handleClick(event) {
|
|
4262
|
+
event.stopPropagation();
|
|
4263
|
+
dispatch({
|
|
4264
|
+
type: TagRemoveClick,
|
|
4265
|
+
index: index
|
|
4266
|
+
});
|
|
4267
|
+
};
|
|
4268
|
+
var tagId = elementIds.getTagId(index);
|
|
4269
|
+
var tagRemoveId = tagId + "-remove";
|
|
4270
|
+
return _extends({
|
|
4271
|
+
id: tagRemoveId,
|
|
4272
|
+
tabIndex: -1,
|
|
4273
|
+
'aria-labelledby': tagRemoveId + " " + tagId,
|
|
4274
|
+
onClick: callAllEventHandlers$1(onClick, handleClick)
|
|
4275
|
+
}, rest);
|
|
4276
|
+
}, [elementIds, dispatch]);
|
|
4277
|
+
|
|
4278
|
+
/* Imperative Functions */
|
|
4279
|
+
|
|
4280
|
+
var addItem = React.useCallback(function (item, index) {
|
|
4281
|
+
dispatch({
|
|
4282
|
+
type: FunctionAddItem,
|
|
4283
|
+
item: item,
|
|
4284
|
+
index: index
|
|
4285
|
+
});
|
|
4286
|
+
}, [dispatch]);
|
|
4287
|
+
return {
|
|
4288
|
+
activeIndex: activeIndex,
|
|
4289
|
+
addItem: addItem,
|
|
4290
|
+
getTagGroupProps: getTagGroupProps,
|
|
4291
|
+
getTagProps: getTagProps,
|
|
4292
|
+
getTagRemoveProps: getTagRemoveProps,
|
|
4293
|
+
items: items
|
|
4294
|
+
};
|
|
4295
|
+
};
|
|
4296
|
+
_useTagGroup.stateChangeTypes = stateChangeTypes;
|
|
4297
|
+
|
|
3887
4298
|
exports.default = Downshift;
|
|
3888
4299
|
exports.resetIdCounter = resetIdCounter;
|
|
3889
4300
|
exports.useCombobox = useCombobox;
|
|
3890
4301
|
exports.useMultipleSelection = useMultipleSelection;
|
|
3891
4302
|
exports.useSelect = useSelect;
|
|
4303
|
+
exports.useTagGroup = _useTagGroup;
|