@ringcentral/juno 1.12.4-beta.5864-e73e0ffc → 1.12.5-beta.5892-381bb03b
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/components/Downshift/Downshift.d.ts +1 -1
- package/components/Downshift/Downshift.js +1 -2
- package/components/Downshift/SuggestionList/SuggestionList.js +4 -5
- package/components/Downshift/SuggestionList/utils/useSuggestionList.d.ts +20 -7
- package/components/Downshift/SuggestionList/utils/useSuggestionList.js +88 -70
- package/components/Downshift/utils/DownshiftUtils.d.ts +2 -0
- package/components/Downshift/utils/DownshiftUtils.js +6 -0
- package/components/Downshift/utils/SelectItem.d.ts +3 -1
- package/components/Downshift/utils/index.d.ts +2 -0
- package/components/Downshift/utils/index.js +2 -0
- package/components/Downshift/utils/useDownshift.d.ts +13 -272
- package/components/Downshift/utils/useDownshift.js +132 -429
- package/components/Downshift/utils/useDownshiftGroup.js +1 -0
- package/components/Downshift/utils/useDownshiftTag.d.ts +554 -0
- package/components/Downshift/utils/useDownshiftTag.js +229 -0
- package/components/Forms/TextField/styles/OutlineTextFieldStyle.js +2 -2
- package/components/Forms/TextField/utils/OutlineTextFieldUtils.d.ts +1 -0
- package/components/Forms/TextField/utils/OutlineTextFieldUtils.js +3 -0
- package/components/Forms/Textarea/Textarea.d.ts +2 -2
- package/components/PortalHost/PortalManager/types.d.ts +1 -1
- package/es6/components/Downshift/Downshift.js +1 -2
- package/es6/components/Downshift/SuggestionList/SuggestionList.js +4 -5
- package/es6/components/Downshift/SuggestionList/utils/useSuggestionList.js +90 -72
- package/es6/components/Downshift/utils/DownshiftUtils.js +5 -0
- package/es6/components/Downshift/utils/index.js +2 -0
- package/es6/components/Downshift/utils/useDownshift.js +135 -432
- package/es6/components/Downshift/utils/useDownshiftGroup.js +1 -0
- package/es6/components/Downshift/utils/useDownshiftTag.js +227 -0
- package/es6/components/Forms/TextField/styles/OutlineTextFieldStyle.js +2 -2
- package/es6/components/Forms/TextField/utils/OutlineTextFieldUtils.js +3 -0
- package/es6/foundation/hooks/useRefState/useRefState.js +6 -1
- package/es6/foundation/theme/ThemeProvider.js +22 -6
- package/foundation/hooks/useRefState/useRefState.js +6 -1
- package/foundation/theme/ThemeProvider.d.ts +12 -10
- package/foundation/theme/ThemeProvider.js +22 -6
- package/package.json +1 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { __read, __rest } from "tslib";
|
|
2
|
-
import { useMemo, useRef } from 'react';
|
|
3
|
-
import uniqueId from 'lodash/uniqueId';
|
|
1
|
+
import { __assign, __read, __rest } from "tslib";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, } from 'react';
|
|
4
3
|
import { useControlled } from '@material-ui/core/utils';
|
|
5
|
-
import { combineProps, useForceUpdate,
|
|
6
|
-
import { DEFAULT_GET_OPTION_LABEL, isItemCanSelected, } from '../../utils';
|
|
4
|
+
import { combineProps, useForceUpdate, useId, useKeyboardMoveFocus, } from '../../../../foundation';
|
|
5
|
+
import { DEFAULT_GET_OPTION_LABEL, isItemCanSelected, } from '../../utils/DownshiftUtils';
|
|
7
6
|
import { useDownshiftGroup } from '../../utils/useDownshiftGroup';
|
|
8
7
|
var DEFAULT_HIGHLIGHTED_INDEX = -1;
|
|
9
8
|
var componentName = 'useSuggestionList';
|
|
@@ -11,7 +10,8 @@ var componentName = 'useSuggestionList';
|
|
|
11
10
|
* provide suggestion list with search function and expandable group with virtualized list
|
|
12
11
|
*/
|
|
13
12
|
export var useSuggestionList = function (_a) {
|
|
14
|
-
var inputValueProp = _a.inputValue, _b = _a.getOptionLabel, getOptionLabel = _b === void 0 ? DEFAULT_GET_OPTION_LABEL : _b, filterOptions = _a.filterOptions, disabledItemsHighlightable = _a.disabledItemsHighlightable, options = _a.options, onInputChangeProp = _a.onInputChange, inputRef = _a.inputRef, onKeyDownProp = _a.onKeyDown, onSelect = _a.onSelect, onClear = _a.onClear, getOptionDisabled = _a.getOptionDisabled, groupBy = _a.groupBy, onGroupExpanded = _a.onGroupExpanded, groupVariant = _a.groupVariant, groupExpanded = _a.groupExpanded, groupDefaultExpanded = _a.groupDefaultExpanded, getExpandIconProps = _a.getExpandIconProps;
|
|
13
|
+
var id = _a.id, inputValueProp = _a.inputValue, _b = _a.getOptionLabel, getOptionLabel = _b === void 0 ? DEFAULT_GET_OPTION_LABEL : _b, filterOptions = _a.filterOptions, disabledItemsHighlightable = _a.disabledItemsHighlightable, options = _a.options, onInputChangeProp = _a.onInputChange, inputRef = _a.inputRef, onKeyDownProp = _a.onKeyDown, onSelect = _a.onSelect, onClear = _a.onClear, getOptionDisabled = _a.getOptionDisabled, groupBy = _a.groupBy, onGroupExpanded = _a.onGroupExpanded, groupVariant = _a.groupVariant, groupExpanded = _a.groupExpanded, groupDefaultExpanded = _a.groupDefaultExpanded, getExpandIconProps = _a.getExpandIconProps, processFilteredResult = _a.processFilteredResult;
|
|
14
|
+
var isTitleMode = groupVariant === 'normal';
|
|
15
15
|
var _c = __read(useControlled({
|
|
16
16
|
controlled: inputValueProp,
|
|
17
17
|
default: '',
|
|
@@ -22,44 +22,44 @@ export var useSuggestionList = function (_a) {
|
|
|
22
22
|
setInputValue(newValue);
|
|
23
23
|
};
|
|
24
24
|
var focusInput = function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
25
|
-
var
|
|
26
|
-
return uniqueId("suggestion-list-");
|
|
27
|
-
}).current;
|
|
28
|
-
// * use -2 for us know that is init state, for recalculate defaultHighlightedIndex
|
|
25
|
+
var currUniqueId = useId(id || 'suggestion-list', !id);
|
|
29
26
|
var highlightedIndexRef = useRef(DEFAULT_HIGHLIGHTED_INDEX);
|
|
30
|
-
var
|
|
27
|
+
var changeHighlightedIndexReasonRef = useRef();
|
|
31
28
|
var forceUpdate = useForceUpdate();
|
|
29
|
+
var getFilteredItems = useCallback(function (items) {
|
|
30
|
+
if (filterOptions) {
|
|
31
|
+
return filterOptions(items, {
|
|
32
|
+
inputValue: inputValue,
|
|
33
|
+
getOptionLabel: getOptionLabel,
|
|
34
|
+
selectedItems: [],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return items;
|
|
38
|
+
}, [filterOptions, getOptionLabel, inputValue]);
|
|
32
39
|
var filteredResult = useMemo(function () {
|
|
33
|
-
var getFilteredItems = function (items) {
|
|
34
|
-
if (filterOptions) {
|
|
35
|
-
return filterOptions(items, {
|
|
36
|
-
inputValue: inputValue,
|
|
37
|
-
getOptionLabel: getOptionLabel,
|
|
38
|
-
selectedItems: [],
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return items;
|
|
42
|
-
};
|
|
43
40
|
// * only when isOpen calculate the filtered result
|
|
44
41
|
var results = getFilteredItems(options);
|
|
42
|
+
results = processFilteredResult
|
|
43
|
+
? processFilteredResult(results, inputValue)
|
|
44
|
+
: results;
|
|
45
45
|
return results;
|
|
46
|
-
}, [
|
|
46
|
+
}, [getFilteredItems, inputValue, options, processFilteredResult]);
|
|
47
47
|
var _d = useDownshiftGroup({
|
|
48
|
-
|
|
48
|
+
id: currUniqueId,
|
|
49
49
|
options: options,
|
|
50
50
|
filteredResult: filteredResult,
|
|
51
|
-
getExpandIconProps: getExpandIconProps,
|
|
52
51
|
groupExpanded: groupExpanded,
|
|
53
52
|
groupDefaultExpanded: groupDefaultExpanded,
|
|
54
|
-
onGroupExpanded: onGroupExpanded,
|
|
55
53
|
groupVariant: groupVariant,
|
|
54
|
+
groupBy: groupBy,
|
|
55
|
+
getExpandIconProps: getExpandIconProps,
|
|
56
|
+
onGroupExpanded: onGroupExpanded,
|
|
56
57
|
getOptionDisabled: getOptionDisabled,
|
|
57
|
-
id: suggestionListId,
|
|
58
58
|
}), groupedResult = _d.groupedResult, handleGroupExpandedChange = _d.handleGroupExpandedChange, optionsGroupList = _d.optionsGroupList;
|
|
59
59
|
var optionItems = groupBy ? groupedResult : filteredResult;
|
|
60
60
|
var setHighlightedIndex = function (index, _a) {
|
|
61
61
|
var _b = _a.reRender, reRender = _b === void 0 ? false : _b, reason = _a.reason;
|
|
62
|
-
|
|
62
|
+
changeHighlightedIndexReasonRef.current = reason;
|
|
63
63
|
if (highlightedIndexRef.current !== index) {
|
|
64
64
|
highlightedIndexRef.current = index;
|
|
65
65
|
if (reRender)
|
|
@@ -77,25 +77,25 @@ export var useSuggestionList = function (_a) {
|
|
|
77
77
|
return ((!!item && item.freeSolo) ||
|
|
78
78
|
(isItemCanSelected(item) && !(getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(item))));
|
|
79
79
|
};
|
|
80
|
-
var
|
|
80
|
+
var selectItem = function (e, selectedItem) {
|
|
81
81
|
if (getIsItemCanSelected(selectedItem)) {
|
|
82
82
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(e, selectedItem);
|
|
83
83
|
return true;
|
|
84
84
|
}
|
|
85
85
|
return false;
|
|
86
86
|
};
|
|
87
|
-
var
|
|
87
|
+
var clearInput = function () {
|
|
88
88
|
if (inputRef.current && inputRef.current.value.length > 0) {
|
|
89
89
|
updateInputValue('');
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
var reset = function (isFocus) {
|
|
93
|
-
|
|
93
|
+
clearInput();
|
|
94
94
|
onInputChangeProp === null || onInputChangeProp === void 0 ? void 0 : onInputChangeProp('');
|
|
95
95
|
if (isFocus)
|
|
96
96
|
focusInput();
|
|
97
97
|
};
|
|
98
|
-
var
|
|
98
|
+
var _e = useKeyboardMoveFocus({
|
|
99
99
|
options: optionItems,
|
|
100
100
|
focusedIndexRef: highlightedIndexRef,
|
|
101
101
|
infinite: true,
|
|
@@ -108,29 +108,44 @@ export var useSuggestionList = function (_a) {
|
|
|
108
108
|
: function (child) {
|
|
109
109
|
return !getIsItemCanSelected(child);
|
|
110
110
|
},
|
|
111
|
-
}).onKeyFocusedIndexHandle;
|
|
111
|
+
}), onKeyFocusedIndexHandle = _e.onKeyFocusedIndexHandle, getNextFocusableOption = _e.getNextFocusableOption;
|
|
112
112
|
var getItemProps = function (_a) {
|
|
113
|
-
var item = _a.item,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
onMouseDown: function (e) {
|
|
113
|
+
var item = _a.item, _b = _a.index, index = _b === void 0 ? 0 : _b, itemRest = __rest(_a, ["item", "index"]);
|
|
114
|
+
var currGroup = item.group;
|
|
115
|
+
var isGroupTitle = item === (currGroup === null || currGroup === void 0 ? void 0 : currGroup.options[0]);
|
|
116
|
+
var itemCount = optionItems.length;
|
|
117
|
+
var groupOrder = (currGroup === null || currGroup === void 0 ? void 0 : currGroup.order) || 0;
|
|
118
|
+
return combineProps(__assign({ id: currUniqueId + "-option-" + index, onClick: function (e) {
|
|
119
|
+
selectItem(e, item);
|
|
120
|
+
}, onMouseDown: function (e) {
|
|
121
121
|
e.preventDefault();
|
|
122
122
|
e.stopPropagation();
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
}, onMouseOver: function () {
|
|
124
|
+
if (highlightedIndexRef.current !== index &&
|
|
125
|
+
getIsItemCanSelected(item)) {
|
|
126
126
|
setHighlightedIndex(index, { reason: 'mouse', reRender: true });
|
|
127
127
|
}
|
|
128
|
-
},
|
|
129
|
-
|
|
128
|
+
} }, (isTitleMode && isGroupTitle
|
|
129
|
+
? {}
|
|
130
|
+
: {
|
|
131
|
+
role: 'option',
|
|
132
|
+
'aria-setsize': itemCount - (isTitleMode ? (optionsGroupList === null || optionsGroupList === void 0 ? void 0 : optionsGroupList.length) || 0 : 0),
|
|
133
|
+
'aria-posinset': index - (isTitleMode ? groupOrder + 1 : 0),
|
|
134
|
+
})), itemRest);
|
|
135
|
+
};
|
|
136
|
+
var handleF10KeyDown = function (e) {
|
|
137
|
+
var highlightedIndex = highlightedIndexRef.current;
|
|
138
|
+
if (e.shiftKey) {
|
|
139
|
+
var currOption = optionItems[highlightedIndex];
|
|
140
|
+
var currentGroup = currOption.group;
|
|
141
|
+
if (currentGroup && currentGroup.options.length > 1) {
|
|
142
|
+
handleGroupExpandedChange(currentGroup.group);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
130
145
|
};
|
|
131
146
|
var getInputProps = function (props) {
|
|
132
147
|
return combineProps({
|
|
133
|
-
id:
|
|
148
|
+
id: currUniqueId + "-input",
|
|
134
149
|
autoComplete: 'off',
|
|
135
150
|
onChange: function (e) {
|
|
136
151
|
var changeValue = e.target.value;
|
|
@@ -139,18 +154,12 @@ export var useSuggestionList = function (_a) {
|
|
|
139
154
|
onKeyDown: function (e) {
|
|
140
155
|
var _a;
|
|
141
156
|
onKeyDownProp === null || onKeyDownProp === void 0 ? void 0 : onKeyDownProp(e, highlightedIndexRef.current);
|
|
142
|
-
var highlightedIndex = highlightedIndexRef.current;
|
|
143
157
|
switch (e.key) {
|
|
144
158
|
case 'F10':
|
|
145
|
-
|
|
146
|
-
var currOption = optionItems[highlightedIndex];
|
|
147
|
-
var currentGroup = currOption.group;
|
|
148
|
-
if (currentGroup && currentGroup.options.length > 1) {
|
|
149
|
-
handleGroupExpandedChange(currentGroup.group);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
159
|
+
handleF10KeyDown(e);
|
|
152
160
|
break;
|
|
153
|
-
case 'Enter':
|
|
161
|
+
case 'Enter': {
|
|
162
|
+
var highlightedIndex = highlightedIndexRef.current;
|
|
154
163
|
if (e.which === 229)
|
|
155
164
|
return;
|
|
156
165
|
if (highlightedIndex !== DEFAULT_HIGHLIGHTED_INDEX) {
|
|
@@ -161,13 +170,14 @@ export var useSuggestionList = function (_a) {
|
|
|
161
170
|
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
162
171
|
}
|
|
163
172
|
else {
|
|
164
|
-
|
|
173
|
+
selectItem(e, currOption);
|
|
165
174
|
}
|
|
166
175
|
e.stopPropagation();
|
|
167
176
|
}
|
|
168
177
|
// always preventDefault for not inset all enter into textarea
|
|
169
178
|
e.preventDefault();
|
|
170
179
|
break;
|
|
180
|
+
}
|
|
171
181
|
default:
|
|
172
182
|
onKeyFocusedIndexHandle(e);
|
|
173
183
|
break;
|
|
@@ -181,57 +191,65 @@ export var useSuggestionList = function (_a) {
|
|
|
181
191
|
onContainerClick: focusInput,
|
|
182
192
|
role: 'combobox',
|
|
183
193
|
'aria-autocomplete': 'list',
|
|
184
|
-
// TODO
|
|
185
194
|
'aria-expanded': true,
|
|
186
195
|
'aria-haspopup': true,
|
|
187
|
-
'aria-owns':
|
|
196
|
+
'aria-owns': currUniqueId + "-menu",
|
|
188
197
|
'aria-activedescendant': highlightedIndexRef.current > -1
|
|
189
|
-
?
|
|
198
|
+
? currUniqueId + "-option-" + highlightedIndexRef.current
|
|
190
199
|
: undefined,
|
|
191
200
|
}, props);
|
|
192
201
|
};
|
|
193
202
|
var getLabelProps = function (props) {
|
|
194
203
|
return combineProps({
|
|
195
|
-
htmlFor:
|
|
196
|
-
id:
|
|
204
|
+
htmlFor: currUniqueId + "-input",
|
|
205
|
+
id: currUniqueId + "-label",
|
|
197
206
|
}, props);
|
|
198
207
|
};
|
|
199
208
|
var getMenuProps = function (restMenuProps) {
|
|
200
209
|
return combineProps({
|
|
201
|
-
'aria-labelledby':
|
|
202
|
-
id:
|
|
210
|
+
'aria-labelledby': currUniqueId + "-label",
|
|
211
|
+
id: currUniqueId + "-menu",
|
|
203
212
|
role: 'listbox',
|
|
204
213
|
}, restMenuProps);
|
|
205
214
|
};
|
|
206
215
|
var getClearButtonProps = function (props) {
|
|
207
216
|
return combineProps({
|
|
208
|
-
id:
|
|
217
|
+
id: currUniqueId + "-clear-button",
|
|
209
218
|
onClick: function (e) {
|
|
210
219
|
onClear === null || onClear === void 0 ? void 0 : onClear(e);
|
|
211
220
|
reset(true);
|
|
212
221
|
},
|
|
213
222
|
}, props);
|
|
214
223
|
};
|
|
215
|
-
|
|
224
|
+
useEffect(function () {
|
|
225
|
+
changeHighlightedIndexReasonRef.current = undefined;
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
reset: reset,
|
|
229
|
+
clearInput: clearInput,
|
|
230
|
+
forceUpdate: forceUpdate,
|
|
216
231
|
focusInput: focusInput,
|
|
232
|
+
updateInputValue: updateInputValue,
|
|
233
|
+
selectItem: selectItem,
|
|
234
|
+
onKeyFocusedIndexHandle: onKeyFocusedIndexHandle,
|
|
217
235
|
getClearButtonProps: getClearButtonProps,
|
|
218
236
|
getLabelProps: getLabelProps,
|
|
219
237
|
getMenuProps: getMenuProps,
|
|
220
238
|
getInputProps: getInputProps,
|
|
221
239
|
getInputAriaProps: getInputAriaProps,
|
|
222
240
|
getItemProps: getItemProps,
|
|
241
|
+
highlightedIndexRef: highlightedIndexRef,
|
|
223
242
|
highlightedIndex: highlightedIndexRef.current,
|
|
224
243
|
optionItems: optionItems,
|
|
225
244
|
inputValue: inputValue,
|
|
226
245
|
onInputChange: handleInputChange,
|
|
227
246
|
setHighlightedIndex: setHighlightedIndex,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
forceUpdate: forceUpdate,
|
|
247
|
+
changeHighlightedIndexReasonRef: changeHighlightedIndexReasonRef,
|
|
248
|
+
changeHighlightedIndexReason: changeHighlightedIndexReasonRef.current,
|
|
231
249
|
optionsGroupList: optionsGroupList,
|
|
232
|
-
/** current
|
|
233
|
-
id:
|
|
250
|
+
/** current unique id */
|
|
251
|
+
id: currUniqueId,
|
|
252
|
+
getNextFocusableOption: getNextFocusableOption,
|
|
253
|
+
handleF10KeyDown: handleF10KeyDown,
|
|
234
254
|
};
|
|
235
|
-
changeHighlightedIndexReason.current = undefined;
|
|
236
|
-
return resultObj;
|
|
237
255
|
};
|
|
@@ -38,3 +38,8 @@ export var RcAutocompleteDefaultFilterOptions = function (options, _a) {
|
|
|
38
38
|
}
|
|
39
39
|
return options.filter(function (item) { return getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(item).toLowerCase().startsWith((inputValue === null || inputValue === void 0 ? void 0 : inputValue.toLowerCase()) || ''); });
|
|
40
40
|
};
|
|
41
|
+
export var downshiftComponentName = 'RcDownshift';
|
|
42
|
+
export function stringArrToRegExp(keyToTags) {
|
|
43
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
44
|
+
return new RegExp((keyToTags === null || keyToTags === void 0 ? void 0 : keyToTags.join('|')) || '', 'g');
|
|
45
|
+
}
|