downshift 9.0.4 → 9.0.5
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/dist/downshift.cjs.js +254 -234
- package/dist/downshift.esm.js +92 -64
- package/dist/downshift.native.cjs.js +254 -234
- package/dist/downshift.nativeweb.cjs.js +254 -234
- package/dist/downshift.umd.js +133 -108
- 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/src/hooks/utils.d.ts +7 -0
- package/package.json +37 -37
- package/preact/dist/downshift.cjs.js +216 -196
- package/preact/dist/downshift.esm.js +92 -64
- package/preact/dist/downshift.umd.js +187 -163
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
|
|
2
2
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
3
|
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
|
4
|
-
import React, { cloneElement, Component, useRef, useEffect,
|
|
4
|
+
import React, { cloneElement, Component, useRef, useEffect, useLayoutEffect, useCallback, useReducer, useMemo } from 'preact/compat';
|
|
5
5
|
import { isForwardRef } from 'react-is';
|
|
6
6
|
import { compute } from 'compute-scroll-into-view';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
@@ -477,23 +477,23 @@ var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend_
|
|
|
477
477
|
|
|
478
478
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
479
479
|
__proto__: null,
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
blurButton: blurButton,
|
|
481
|
+
blurInput: blurInput,
|
|
482
|
+
changeInput: changeInput,
|
|
483
|
+
clickButton: clickButton,
|
|
484
|
+
clickItem: clickItem,
|
|
485
|
+
controlledPropUpdatedSelectedItem: controlledPropUpdatedSelectedItem,
|
|
482
486
|
itemMouseEnter: itemMouseEnter,
|
|
483
|
-
keyDownArrowUp: keyDownArrowUp,
|
|
484
487
|
keyDownArrowDown: keyDownArrowDown,
|
|
485
|
-
|
|
488
|
+
keyDownArrowUp: keyDownArrowUp,
|
|
489
|
+
keyDownEnd: keyDownEnd,
|
|
486
490
|
keyDownEnter: keyDownEnter,
|
|
491
|
+
keyDownEscape: keyDownEscape,
|
|
487
492
|
keyDownHome: keyDownHome,
|
|
488
|
-
keyDownEnd: keyDownEnd,
|
|
489
|
-
clickItem: clickItem,
|
|
490
|
-
blurInput: blurInput,
|
|
491
|
-
changeInput: changeInput,
|
|
492
493
|
keyDownSpaceButton: keyDownSpaceButton,
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
touchEnd: touchEnd
|
|
494
|
+
mouseUp: mouseUp,
|
|
495
|
+
touchEnd: touchEnd,
|
|
496
|
+
unknown: unknown
|
|
497
497
|
});
|
|
498
498
|
|
|
499
499
|
var _excluded$3 = ["refKey", "ref"],
|
|
@@ -1733,7 +1733,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1733
1733
|
function getInitialState$2(props) {
|
|
1734
1734
|
var selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1735
1735
|
var isOpen = getInitialValue$1(props, 'isOpen');
|
|
1736
|
-
var highlightedIndex =
|
|
1736
|
+
var highlightedIndex = getInitialHighlightedIndex(props);
|
|
1737
1737
|
var inputValue = getInitialValue$1(props, 'inputValue');
|
|
1738
1738
|
return {
|
|
1739
1739
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
|
|
@@ -1757,10 +1757,10 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1757
1757
|
}
|
|
1758
1758
|
|
|
1759
1759
|
// initialHighlightedIndex will give value to highlightedIndex on initial state only.
|
|
1760
|
-
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex])) {
|
|
1760
|
+
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
1761
1761
|
return initialHighlightedIndex;
|
|
1762
1762
|
}
|
|
1763
|
-
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex])) {
|
|
1763
|
+
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
1764
1764
|
return defaultHighlightedIndex;
|
|
1765
1765
|
}
|
|
1766
1766
|
if (selectedItem) {
|
|
@@ -1768,10 +1768,10 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1768
1768
|
return itemToKey(selectedItem) === itemToKey(item);
|
|
1769
1769
|
});
|
|
1770
1770
|
}
|
|
1771
|
-
if (offset < 0 && !isItemDisabled(items[items.length - 1])) {
|
|
1771
|
+
if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
1772
1772
|
return items.length - 1;
|
|
1773
1773
|
}
|
|
1774
|
-
if (offset > 0 && !isItemDisabled(items[0])) {
|
|
1774
|
+
if (offset > 0 && !isItemDisabled(items[0], 0)) {
|
|
1775
1775
|
return 0;
|
|
1776
1776
|
}
|
|
1777
1777
|
return -1;
|
|
@@ -2019,6 +2019,34 @@ function useIsInitialMount() {
|
|
|
2019
2019
|
return isInitialMountRef.current;
|
|
2020
2020
|
}
|
|
2021
2021
|
|
|
2022
|
+
/**
|
|
2023
|
+
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
2024
|
+
*
|
|
2025
|
+
* @param {Object} props Props from useCombobox or useSelect.
|
|
2026
|
+
* @returns {number} The highlighted index.
|
|
2027
|
+
*/
|
|
2028
|
+
function getDefaultHighlightedIndex(props) {
|
|
2029
|
+
var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex');
|
|
2030
|
+
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2031
|
+
return -1;
|
|
2032
|
+
}
|
|
2033
|
+
return highlightedIndex;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
/**
|
|
2037
|
+
* Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
|
|
2038
|
+
*
|
|
2039
|
+
* @param {Object} props Props from useCombobox or useSelect.
|
|
2040
|
+
* @returns {number} The highlighted index.
|
|
2041
|
+
*/
|
|
2042
|
+
function getInitialHighlightedIndex(props) {
|
|
2043
|
+
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
2044
|
+
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2045
|
+
return -1;
|
|
2046
|
+
}
|
|
2047
|
+
return highlightedIndex;
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2022
2050
|
// Shared between all exports.
|
|
2023
2051
|
var commonPropTypes = {
|
|
2024
2052
|
environment: PropTypes.shape({
|
|
@@ -2096,7 +2124,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2096
2124
|
break;
|
|
2097
2125
|
case stateChangeTypes.FunctionSetHighlightedIndex:
|
|
2098
2126
|
changes = {
|
|
2099
|
-
highlightedIndex: action.highlightedIndex
|
|
2127
|
+
highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
|
|
2100
2128
|
};
|
|
2101
2129
|
break;
|
|
2102
2130
|
case stateChangeTypes.FunctionSetInputValue:
|
|
@@ -2106,7 +2134,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2106
2134
|
break;
|
|
2107
2135
|
case stateChangeTypes.FunctionReset:
|
|
2108
2136
|
changes = {
|
|
2109
|
-
highlightedIndex:
|
|
2137
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2110
2138
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2111
2139
|
selectedItem: getDefaultValue$1(props, 'selectedItem'),
|
|
2112
2140
|
inputValue: getDefaultValue$1(props, 'inputValue')
|
|
@@ -2172,28 +2200,28 @@ var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset_
|
|
|
2172
2200
|
|
|
2173
2201
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2174
2202
|
__proto__: null,
|
|
2203
|
+
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
2204
|
+
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
2205
|
+
FunctionReset: FunctionReset$2,
|
|
2206
|
+
FunctionSelectItem: FunctionSelectItem$1,
|
|
2207
|
+
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
|
|
2208
|
+
FunctionSetInputValue: FunctionSetInputValue$1,
|
|
2209
|
+
FunctionToggleMenu: FunctionToggleMenu$1,
|
|
2210
|
+
ItemClick: ItemClick$1,
|
|
2211
|
+
ItemMouseMove: ItemMouseMove$1,
|
|
2212
|
+
MenuMouseLeave: MenuMouseLeave$1,
|
|
2213
|
+
ToggleButtonBlur: ToggleButtonBlur,
|
|
2175
2214
|
ToggleButtonClick: ToggleButtonClick$1,
|
|
2176
2215
|
ToggleButtonKeyDownArrowDown: ToggleButtonKeyDownArrowDown,
|
|
2177
2216
|
ToggleButtonKeyDownArrowUp: ToggleButtonKeyDownArrowUp,
|
|
2178
2217
|
ToggleButtonKeyDownCharacter: ToggleButtonKeyDownCharacter,
|
|
2179
|
-
ToggleButtonKeyDownEscape: ToggleButtonKeyDownEscape,
|
|
2180
|
-
ToggleButtonKeyDownHome: ToggleButtonKeyDownHome,
|
|
2181
2218
|
ToggleButtonKeyDownEnd: ToggleButtonKeyDownEnd,
|
|
2182
2219
|
ToggleButtonKeyDownEnter: ToggleButtonKeyDownEnter,
|
|
2183
|
-
|
|
2184
|
-
|
|
2220
|
+
ToggleButtonKeyDownEscape: ToggleButtonKeyDownEscape,
|
|
2221
|
+
ToggleButtonKeyDownHome: ToggleButtonKeyDownHome,
|
|
2185
2222
|
ToggleButtonKeyDownPageDown: ToggleButtonKeyDownPageDown,
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
ItemMouseMove: ItemMouseMove$1,
|
|
2189
|
-
ItemClick: ItemClick$1,
|
|
2190
|
-
FunctionToggleMenu: FunctionToggleMenu$1,
|
|
2191
|
-
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
2192
|
-
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
2193
|
-
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
|
|
2194
|
-
FunctionSelectItem: FunctionSelectItem$1,
|
|
2195
|
-
FunctionSetInputValue: FunctionSetInputValue$1,
|
|
2196
|
-
FunctionReset: FunctionReset$2
|
|
2223
|
+
ToggleButtonKeyDownPageUp: ToggleButtonKeyDownPageUp,
|
|
2224
|
+
ToggleButtonKeyDownSpaceButton: ToggleButtonKeyDownSpaceButton
|
|
2197
2225
|
});
|
|
2198
2226
|
|
|
2199
2227
|
/* eslint-disable complexity */
|
|
@@ -2207,7 +2235,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2207
2235
|
case ItemClick$1:
|
|
2208
2236
|
changes = {
|
|
2209
2237
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2210
|
-
highlightedIndex:
|
|
2238
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2211
2239
|
selectedItem: props.items[action.index]
|
|
2212
2240
|
};
|
|
2213
2241
|
break;
|
|
@@ -2723,29 +2751,29 @@ var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ?
|
|
|
2723
2751
|
|
|
2724
2752
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
2725
2753
|
__proto__: null,
|
|
2754
|
+
ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem,
|
|
2755
|
+
FunctionCloseMenu: FunctionCloseMenu,
|
|
2756
|
+
FunctionOpenMenu: FunctionOpenMenu,
|
|
2757
|
+
FunctionReset: FunctionReset$1,
|
|
2758
|
+
FunctionSelectItem: FunctionSelectItem,
|
|
2759
|
+
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
|
2760
|
+
FunctionSetInputValue: FunctionSetInputValue,
|
|
2761
|
+
FunctionToggleMenu: FunctionToggleMenu,
|
|
2762
|
+
InputBlur: InputBlur,
|
|
2763
|
+
InputChange: InputChange,
|
|
2764
|
+
InputClick: InputClick,
|
|
2726
2765
|
InputKeyDownArrowDown: InputKeyDownArrowDown,
|
|
2727
2766
|
InputKeyDownArrowUp: InputKeyDownArrowUp,
|
|
2767
|
+
InputKeyDownEnd: InputKeyDownEnd,
|
|
2768
|
+
InputKeyDownEnter: InputKeyDownEnter,
|
|
2728
2769
|
InputKeyDownEscape: InputKeyDownEscape,
|
|
2729
2770
|
InputKeyDownHome: InputKeyDownHome,
|
|
2730
|
-
InputKeyDownEnd: InputKeyDownEnd,
|
|
2731
|
-
InputKeyDownPageUp: InputKeyDownPageUp,
|
|
2732
2771
|
InputKeyDownPageDown: InputKeyDownPageDown,
|
|
2733
|
-
|
|
2734
|
-
InputChange: InputChange,
|
|
2735
|
-
InputBlur: InputBlur,
|
|
2736
|
-
InputClick: InputClick,
|
|
2737
|
-
MenuMouseLeave: MenuMouseLeave,
|
|
2738
|
-
ItemMouseMove: ItemMouseMove,
|
|
2772
|
+
InputKeyDownPageUp: InputKeyDownPageUp,
|
|
2739
2773
|
ItemClick: ItemClick,
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
FunctionCloseMenu: FunctionCloseMenu,
|
|
2744
|
-
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
|
2745
|
-
FunctionSelectItem: FunctionSelectItem,
|
|
2746
|
-
FunctionSetInputValue: FunctionSetInputValue,
|
|
2747
|
-
FunctionReset: FunctionReset$1,
|
|
2748
|
-
ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem
|
|
2774
|
+
ItemMouseMove: ItemMouseMove,
|
|
2775
|
+
MenuMouseLeave: MenuMouseLeave,
|
|
2776
|
+
ToggleButtonClick: ToggleButtonClick
|
|
2749
2777
|
});
|
|
2750
2778
|
|
|
2751
2779
|
function getInitialState$1(props) {
|
|
@@ -2833,7 +2861,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2833
2861
|
case ItemClick:
|
|
2834
2862
|
changes = {
|
|
2835
2863
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2836
|
-
highlightedIndex:
|
|
2864
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2837
2865
|
selectedItem: props.items[action.index],
|
|
2838
2866
|
inputValue: props.itemToString(props.items[action.index])
|
|
2839
2867
|
};
|
|
@@ -2910,7 +2938,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2910
2938
|
case InputChange:
|
|
2911
2939
|
changes = {
|
|
2912
2940
|
isOpen: true,
|
|
2913
|
-
highlightedIndex:
|
|
2941
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2914
2942
|
inputValue: action.inputValue
|
|
2915
2943
|
};
|
|
2916
2944
|
break;
|
|
@@ -3468,19 +3496,19 @@ var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__'
|
|
|
3468
3496
|
|
|
3469
3497
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3470
3498
|
__proto__: null,
|
|
3471
|
-
SelectedItemClick: SelectedItemClick,
|
|
3472
|
-
SelectedItemKeyDownDelete: SelectedItemKeyDownDelete,
|
|
3473
|
-
SelectedItemKeyDownBackspace: SelectedItemKeyDownBackspace,
|
|
3474
|
-
SelectedItemKeyDownNavigationNext: SelectedItemKeyDownNavigationNext,
|
|
3475
|
-
SelectedItemKeyDownNavigationPrevious: SelectedItemKeyDownNavigationPrevious,
|
|
3476
|
-
DropdownKeyDownNavigationPrevious: DropdownKeyDownNavigationPrevious,
|
|
3477
|
-
DropdownKeyDownBackspace: DropdownKeyDownBackspace,
|
|
3478
3499
|
DropdownClick: DropdownClick,
|
|
3500
|
+
DropdownKeyDownBackspace: DropdownKeyDownBackspace,
|
|
3501
|
+
DropdownKeyDownNavigationPrevious: DropdownKeyDownNavigationPrevious,
|
|
3479
3502
|
FunctionAddSelectedItem: FunctionAddSelectedItem,
|
|
3480
3503
|
FunctionRemoveSelectedItem: FunctionRemoveSelectedItem,
|
|
3481
|
-
|
|
3504
|
+
FunctionReset: FunctionReset,
|
|
3482
3505
|
FunctionSetActiveIndex: FunctionSetActiveIndex,
|
|
3483
|
-
|
|
3506
|
+
FunctionSetSelectedItems: FunctionSetSelectedItems,
|
|
3507
|
+
SelectedItemClick: SelectedItemClick,
|
|
3508
|
+
SelectedItemKeyDownBackspace: SelectedItemKeyDownBackspace,
|
|
3509
|
+
SelectedItemKeyDownDelete: SelectedItemKeyDownDelete,
|
|
3510
|
+
SelectedItemKeyDownNavigationNext: SelectedItemKeyDownNavigationNext,
|
|
3511
|
+
SelectedItemKeyDownNavigationPrevious: SelectedItemKeyDownNavigationPrevious
|
|
3484
3512
|
});
|
|
3485
3513
|
|
|
3486
3514
|
/* eslint-disable complexity */
|