@choc-ui/chakra-autocomplete 5.1.5 → 5.1.7
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/README.md +13 -3
- package/dist/autocomplete-context.d.ts +3 -3
- package/dist/autocomplete-creatable.d.ts +14 -14
- package/dist/autocomplete-group.d.ts +9 -9
- package/dist/autocomplete-input.d.ts +11 -10
- package/dist/autocomplete-item.d.ts +12 -12
- package/dist/autocomplete-list.d.ts +3 -3
- package/dist/autocomplete-tag.d.ts +9 -9
- package/dist/autocomplete.d.ts +13 -13
- package/dist/components/empty-state.d.ts +3 -3
- package/dist/helpers/fuzzySearch.d.ts +1 -1
- package/dist/helpers/group.d.ts +4 -4
- package/dist/helpers/input.d.ts +1 -1
- package/dist/helpers/items.d.ts +9 -9
- package/dist/helpers/list.d.ts +2 -2
- package/dist/index.d.ts +10 -10
- package/dist/index.es.js +3501 -0
- package/dist/index.js +25 -6
- package/dist/types.d.ts +124 -124
- package/dist/use-autocomplete.d.ts +8 -8
- package/package.json +8 -8
- package/Changelog.md +0 -28
- package/dist/chakra-autocomplete.cjs.development.js +0 -1033
- package/dist/chakra-autocomplete.cjs.development.js.map +0 -1
- package/dist/chakra-autocomplete.cjs.production.min.js +0 -2
- package/dist/chakra-autocomplete.cjs.production.min.js.map +0 -1
- package/dist/chakra-autocomplete.esm.js +0 -1015
- package/dist/chakra-autocomplete.esm.js.map +0 -1
|
@@ -1,1033 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var React__default = _interopDefault(React);
|
|
9
|
-
var reactUtils = require('@chakra-ui/react-utils');
|
|
10
|
-
var react = require('@chakra-ui/react');
|
|
11
|
-
var utils = require('@chakra-ui/utils');
|
|
12
|
-
var reactNanny = require('react-nanny');
|
|
13
|
-
var layout = require('@chakra-ui/layout');
|
|
14
|
-
var tag = require('@chakra-ui/tag');
|
|
15
|
-
|
|
16
|
-
var _createContext = /*#__PURE__*/reactUtils.createContext({
|
|
17
|
-
name: "AutoCompleteContext",
|
|
18
|
-
errorMessage: "useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`"
|
|
19
|
-
}),
|
|
20
|
-
AutoCompleteProvider = _createContext[0],
|
|
21
|
-
useAutoCompleteContext = _createContext[1];
|
|
22
|
-
|
|
23
|
-
function _extends() {
|
|
24
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
25
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
26
|
-
var source = arguments[i];
|
|
27
|
-
|
|
28
|
-
for (var key in source) {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
30
|
-
target[key] = source[key];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
return _extends.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
41
|
-
if (source == null) return {};
|
|
42
|
-
var target = {};
|
|
43
|
-
var sourceKeys = Object.keys(source);
|
|
44
|
-
var key, i;
|
|
45
|
-
|
|
46
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
47
|
-
key = sourceKeys[i];
|
|
48
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
49
|
-
target[key] = source[key];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return target;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
56
|
-
if (!o) return;
|
|
57
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
58
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
59
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
60
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
61
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function _arrayLikeToArray(arr, len) {
|
|
65
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
66
|
-
|
|
67
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
68
|
-
|
|
69
|
-
return arr2;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
73
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
74
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
75
|
-
|
|
76
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
77
|
-
if (it) o = it;
|
|
78
|
-
var i = 0;
|
|
79
|
-
return function () {
|
|
80
|
-
if (i >= o.length) return {
|
|
81
|
-
done: true
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
done: false,
|
|
85
|
-
value: o[i++]
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/*
|
|
94
|
-
* @param str1 The first string to compare.
|
|
95
|
-
* @param str2 The second string to compare.
|
|
96
|
-
* @param gramSize The size of the grams. Defaults to length 2.
|
|
97
|
-
*/
|
|
98
|
-
function fuzzyScore(str1, str2, gramSize) {
|
|
99
|
-
if (gramSize === void 0) {
|
|
100
|
-
gramSize = 2;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getNGrams(s, len) {
|
|
104
|
-
s = " ".repeat(len - 1) + s.toLowerCase() + " ".repeat(len - 1);
|
|
105
|
-
var v = new Array(s.length - len + 1);
|
|
106
|
-
|
|
107
|
-
for (var i = 0; i < v.length; i++) {
|
|
108
|
-
v[i] = s.slice(i, i + len);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return v;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!(str1 != null && str1.length) || !(str2 != null && str2.length)) {
|
|
115
|
-
return 0.0;
|
|
116
|
-
} //Order the strings by length so the order they're passed in doesn't matter
|
|
117
|
-
//and so the smaller string's ngrams are always the ones in the set
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var s1 = str1.length < str2.length ? str1 : str2;
|
|
121
|
-
var s2 = str1.length < str2.length ? str2 : str1;
|
|
122
|
-
var pairs1 = getNGrams(s1, gramSize);
|
|
123
|
-
var pairs2 = getNGrams(s2, gramSize);
|
|
124
|
-
var set = new Set(pairs1);
|
|
125
|
-
var total = pairs2.length;
|
|
126
|
-
var hits = 0;
|
|
127
|
-
|
|
128
|
-
for (var _iterator = _createForOfIteratorHelperLoose(pairs2), _step; !(_step = _iterator()).done;) {
|
|
129
|
-
var item = _step.value;
|
|
130
|
-
|
|
131
|
-
if (set["delete"](item)) {
|
|
132
|
-
hits++;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return hits / total;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
var getDefItemValue = function getDefItemValue(item) {
|
|
140
|
-
var _ref;
|
|
141
|
-
|
|
142
|
-
return (_ref = typeof item === "string" ? item : item[Object.keys(item)[0]]) == null ? void 0 : _ref.toString();
|
|
143
|
-
};
|
|
144
|
-
var setEmphasis = function setEmphasis(children, query) {
|
|
145
|
-
if (typeof children !== "string" || utils.isEmpty(query)) {
|
|
146
|
-
return children;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
var newChildren = children.toString().replace(new RegExp(escapeRegex(query), "gi"), function (match) {
|
|
150
|
-
return "<mark>" + match + "</mark>";
|
|
151
|
-
});
|
|
152
|
-
return newChildren;
|
|
153
|
-
};
|
|
154
|
-
var getItemList = function getItemList(children) {
|
|
155
|
-
var itemChildren = reactNanny.getChildrenDeep(children, function (child) {
|
|
156
|
-
var _child$type;
|
|
157
|
-
|
|
158
|
-
return (child == null ? void 0 : (_child$type = child.type) == null ? void 0 : _child$type.displayName) === "AutoCompleteItem";
|
|
159
|
-
});
|
|
160
|
-
return itemChildren.map(function (item) {
|
|
161
|
-
var itemObj = utils.pick(item.props, ["value", "label", "fixed", "disabled"]);
|
|
162
|
-
var _item$props$getValue = item.props.getValue,
|
|
163
|
-
getValue = _item$props$getValue === void 0 ? getDefItemValue : _item$props$getValue;
|
|
164
|
-
var value = getValue(itemObj.value);
|
|
165
|
-
var finObj = utils.isDefined(itemObj.label) ? itemObj : _extends({}, itemObj, {
|
|
166
|
-
label: value
|
|
167
|
-
});
|
|
168
|
-
return _extends({}, finObj, {
|
|
169
|
-
value: value,
|
|
170
|
-
originalValue: itemObj.value
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
var getFocusedStyles = function getFocusedStyles() {
|
|
175
|
-
return {
|
|
176
|
-
bg: "whiteAlpha.100",
|
|
177
|
-
_light: {
|
|
178
|
-
bg: "gray.200"
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
var defaultFilterMethod = function defaultFilterMethod(query, itemValue, itemLabel) {
|
|
183
|
-
return (itemValue == null ? void 0 : itemValue.toLowerCase().indexOf(query == null ? void 0 : query.toLowerCase())) >= 0 || (itemLabel == null ? void 0 : itemLabel.toLowerCase().indexOf(query == null ? void 0 : query.toLowerCase())) >= 0 || fuzzyScore(query, itemValue) >= 0.5 || fuzzyScore(query, itemLabel) >= 0.5;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
function escapeRegex(string) {
|
|
187
|
-
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
var getMultipleWrapStyles = function getMultipleWrapStyles(themeInput, multiple) {
|
|
191
|
-
return _extends({}, multiple && _extends({}, themeInput.field, {
|
|
192
|
-
_focusWithin: themeInput.field._focus,
|
|
193
|
-
pos: "relative",
|
|
194
|
-
minH: 9,
|
|
195
|
-
// px: 3,
|
|
196
|
-
py: 1.5,
|
|
197
|
-
spacing: 3
|
|
198
|
-
}), {
|
|
199
|
-
cursor: "text",
|
|
200
|
-
h: "fit-content"
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
var hasFirstItem = function hasFirstItem(children, firstItem) {
|
|
205
|
-
var result = reactNanny.getChildDeep(children, function (child) {
|
|
206
|
-
var _child$type;
|
|
207
|
-
|
|
208
|
-
return (child == null ? void 0 : (_child$type = child.type) == null ? void 0 : _child$type.displayName) === "AutoCompleteItem" && child.props.value === (firstItem == null ? void 0 : firstItem.value);
|
|
209
|
-
});
|
|
210
|
-
return result;
|
|
211
|
-
};
|
|
212
|
-
var hasLastItem = function hasLastItem(children, lastItem) {
|
|
213
|
-
var result = reactNanny.getChildDeep(children, function (child) {
|
|
214
|
-
var _child$type2;
|
|
215
|
-
|
|
216
|
-
return (child == null ? void 0 : (_child$type2 = child.type) == null ? void 0 : _child$type2.displayName) === "AutoCompleteItem" && child.props.value === (lastItem == null ? void 0 : lastItem.value);
|
|
217
|
-
});
|
|
218
|
-
return result;
|
|
219
|
-
};
|
|
220
|
-
var hasChildren = function hasChildren(children, filteredList) {
|
|
221
|
-
return utils.isDefined(reactNanny.getChildDeep(children, function (child) {
|
|
222
|
-
var _child$props, _child$props2;
|
|
223
|
-
|
|
224
|
-
var value = utils.runIfFn(((_child$props = child.props) == null ? void 0 : _child$props.getValue) || getDefItemValue, ((_child$props2 = child.props) == null ? void 0 : _child$props2.value) || {});
|
|
225
|
-
return filteredList.some(function (i) {
|
|
226
|
-
return i.value === value;
|
|
227
|
-
});
|
|
228
|
-
}));
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
var _excluded = ["onBlur", "onChange", "onFocus", "onKeyDown", "variant"],
|
|
232
|
-
_excluded2 = ["_fixed", "_focus", "children", "disabled", "label", "value", "fixed", "getValue", "onClick", "onMouseOver", "sx"];
|
|
233
|
-
/**
|
|
234
|
-
* useAutoComplete that provides all the state and focus management logic
|
|
235
|
-
* for the autocomplete component. It is consumed by the `Autocomplete` component
|
|
236
|
-
*
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
function useAutoComplete(autoCompleteProps) {
|
|
240
|
-
var _defaultQuery, _itemList$;
|
|
241
|
-
|
|
242
|
-
var _autoCompleteProps$cl = autoCompleteProps.closeOnBlur,
|
|
243
|
-
closeOnBlur = _autoCompleteProps$cl === void 0 ? true : _autoCompleteProps$cl,
|
|
244
|
-
closeOnSelect = autoCompleteProps.closeOnSelect,
|
|
245
|
-
creatable = autoCompleteProps.creatable,
|
|
246
|
-
emphasize = autoCompleteProps.emphasize,
|
|
247
|
-
_autoCompleteProps$em = autoCompleteProps.emptyState,
|
|
248
|
-
emptyState = _autoCompleteProps$em === void 0 ? true : _autoCompleteProps$em,
|
|
249
|
-
freeSolo = autoCompleteProps.freeSolo,
|
|
250
|
-
isReadOnly = autoCompleteProps.isReadOnly,
|
|
251
|
-
listAllValuesOnFocus = autoCompleteProps.listAllValuesOnFocus,
|
|
252
|
-
maxSuggestions = autoCompleteProps.maxSuggestions,
|
|
253
|
-
multiple = autoCompleteProps.multiple,
|
|
254
|
-
defaultValue = autoCompleteProps.defaultValue,
|
|
255
|
-
_autoCompleteProps$de = autoCompleteProps.defaultValues,
|
|
256
|
-
defaultValues = _autoCompleteProps$de === void 0 ? defaultValue ? [defaultValue] : [] : _autoCompleteProps$de,
|
|
257
|
-
onReady = autoCompleteProps.onReady,
|
|
258
|
-
defaultIsOpen = autoCompleteProps.defaultIsOpen,
|
|
259
|
-
disableFilter = autoCompleteProps.disableFilter,
|
|
260
|
-
_autoCompleteProps$re = autoCompleteProps.restoreOnBlurIfEmpty,
|
|
261
|
-
restoreOnBlurIfEmpty = _autoCompleteProps$re === void 0 ? !freeSolo : _autoCompleteProps$re,
|
|
262
|
-
_autoCompleteProps$sh = autoCompleteProps.shouldRenderSuggestions,
|
|
263
|
-
shouldRenderSuggestions = _autoCompleteProps$sh === void 0 ? function () {
|
|
264
|
-
return true;
|
|
265
|
-
} : _autoCompleteProps$sh,
|
|
266
|
-
_autoCompleteProps$su = autoCompleteProps.submitKeys,
|
|
267
|
-
submitKeys = _autoCompleteProps$su === void 0 ? [] : _autoCompleteProps$su,
|
|
268
|
-
suggestWhenEmpty = autoCompleteProps.suggestWhenEmpty,
|
|
269
|
-
value = autoCompleteProps.value,
|
|
270
|
-
_autoCompleteProps$va = autoCompleteProps.values,
|
|
271
|
-
valuesProp = _autoCompleteProps$va === void 0 ? value ? typeof value === "string" ? [value] : [].concat(value) : undefined : _autoCompleteProps$va;
|
|
272
|
-
closeOnSelect = closeOnSelect ? closeOnSelect : multiple ? false : true;
|
|
273
|
-
freeSolo = freeSolo ? freeSolo : multiple ? true : autoCompleteProps.freeSolo;
|
|
274
|
-
|
|
275
|
-
var _useDisclosure = react.useDisclosure({
|
|
276
|
-
defaultIsOpen: defaultIsOpen
|
|
277
|
-
}),
|
|
278
|
-
isOpen = _useDisclosure.isOpen,
|
|
279
|
-
onClose = _useDisclosure.onClose,
|
|
280
|
-
onOpen = _useDisclosure.onOpen;
|
|
281
|
-
|
|
282
|
-
var children = utils.runIfFn(autoCompleteProps.children, {
|
|
283
|
-
isOpen: isOpen,
|
|
284
|
-
onClose: onClose,
|
|
285
|
-
onOpen: onOpen
|
|
286
|
-
});
|
|
287
|
-
var itemList = getItemList(children);
|
|
288
|
-
var inputRef = React.useRef(null);
|
|
289
|
-
var inputWrapperRef = React.useRef(null);
|
|
290
|
-
var listRef = React.useRef(null);
|
|
291
|
-
var interactionRef = React.useRef(null);
|
|
292
|
-
|
|
293
|
-
var _useState = React.useState(false),
|
|
294
|
-
listAll = _useState[0],
|
|
295
|
-
setListAll = _useState[1];
|
|
296
|
-
|
|
297
|
-
var defaultQuery = "";
|
|
298
|
-
if (multiple) defaultQuery = "";else if (!utils.isUndefined(defaultValues)) defaultQuery = defaultValues[0];else if (!utils.isUndefined(valuesProp)) defaultQuery = valuesProp[0];
|
|
299
|
-
|
|
300
|
-
var _useState2 = React.useState((_defaultQuery = defaultQuery) != null ? _defaultQuery : ""),
|
|
301
|
-
query = _useState2[0],
|
|
302
|
-
setQuery = _useState2[1];
|
|
303
|
-
|
|
304
|
-
var filteredResults = disableFilter ? itemList : itemList.filter(function (i) {
|
|
305
|
-
return i.fixed || utils.runIfFn(autoCompleteProps.filter || defaultFilterMethod, query, i.value, i.label) || listAll;
|
|
306
|
-
}).filter(function (i, index) {
|
|
307
|
-
return maxSuggestions ? i.fixed || index < maxSuggestions : true;
|
|
308
|
-
}); // Add Creatable to Filtered List
|
|
309
|
-
|
|
310
|
-
var creatableArr = creatable ? [{
|
|
311
|
-
value: query,
|
|
312
|
-
noFilter: true,
|
|
313
|
-
creatable: true
|
|
314
|
-
}] : [];
|
|
315
|
-
var filteredList = [].concat(filteredResults, creatableArr);
|
|
316
|
-
|
|
317
|
-
var _useControllableState = react.useControllableState({
|
|
318
|
-
defaultValue: defaultValues,
|
|
319
|
-
value: valuesProp,
|
|
320
|
-
onChange: function onChange(newValues) {
|
|
321
|
-
var item = filteredList.find(function (opt) {
|
|
322
|
-
return opt.value === newValues[0];
|
|
323
|
-
});
|
|
324
|
-
var items = newValues.map(function (val) {
|
|
325
|
-
return filteredList.find(function (opt) {
|
|
326
|
-
return opt.value === val;
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
utils.runIfFn(autoCompleteProps.onChange, multiple ? newValues : newValues[0], multiple ? items : item);
|
|
330
|
-
}
|
|
331
|
-
}),
|
|
332
|
-
values = _useControllableState[0],
|
|
333
|
-
setValues = _useControllableState[1];
|
|
334
|
-
|
|
335
|
-
var _useState3 = React.useState((_itemList$ = itemList[0]) == null ? void 0 : _itemList$.value),
|
|
336
|
-
focusedValue = _useState3[0],
|
|
337
|
-
setFocusedValue = _useState3[1];
|
|
338
|
-
|
|
339
|
-
var maxSelections = autoCompleteProps.maxSelections || values.length + 1;
|
|
340
|
-
var focusedIndex = filteredList.findIndex(function (i) {
|
|
341
|
-
return i.value === focusedValue;
|
|
342
|
-
});
|
|
343
|
-
var nextItem = utils.getNextItem(focusedIndex, filteredList, !!autoCompleteProps.rollNavigation);
|
|
344
|
-
var prevItem = utils.getPrevItem(focusedIndex, filteredList, !!autoCompleteProps.rollNavigation);
|
|
345
|
-
var firstItem = utils.getFirstItem(filteredList);
|
|
346
|
-
var lastItem = utils.getLastItem(filteredList);
|
|
347
|
-
react.useUpdateEffect(function () {
|
|
348
|
-
setFocusedValue(firstItem == null ? void 0 : firstItem.value);
|
|
349
|
-
}, [query]);
|
|
350
|
-
React.useEffect(function () {
|
|
351
|
-
var _itemList$2;
|
|
352
|
-
|
|
353
|
-
if (!isOpen) setFocusedValue((_itemList$2 = itemList[0]) == null ? void 0 : _itemList$2.value);
|
|
354
|
-
}, [isOpen]);
|
|
355
|
-
React.useEffect(function () {
|
|
356
|
-
var focusedItem = itemList.find(function (i) {
|
|
357
|
-
return i.value === focusedValue;
|
|
358
|
-
});
|
|
359
|
-
utils.runIfFn(autoCompleteProps.onOptionFocus, {
|
|
360
|
-
item: focusedItem,
|
|
361
|
-
focusMethod: interactionRef.current,
|
|
362
|
-
isNewInput: focusedItem == null ? void 0 : focusedItem.creatable
|
|
363
|
-
});
|
|
364
|
-
}, [focusedValue, autoCompleteProps.onOptionFocus]);
|
|
365
|
-
|
|
366
|
-
var selectItem = function selectItem(optionValue) {
|
|
367
|
-
var _inputRef$current2;
|
|
368
|
-
|
|
369
|
-
if (!values.includes(optionValue) && values.length < maxSelections) {
|
|
370
|
-
setValues(function (v) {
|
|
371
|
-
return multiple ? [].concat(v, [optionValue]) : [optionValue];
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
var option = filteredList.find(function (i) {
|
|
376
|
-
return i.value === optionValue;
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
if (multiple) {
|
|
380
|
-
var _inputRef$current;
|
|
381
|
-
|
|
382
|
-
(_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (autoCompleteProps.focusInputOnSelect) (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.focus();
|
|
386
|
-
utils.runIfFn(autoCompleteProps.onSelectOption, {
|
|
387
|
-
item: option,
|
|
388
|
-
selectMethod: interactionRef.current,
|
|
389
|
-
isNewInput: option == null ? void 0 : option.creatable
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
if (option != null && option.creatable) {
|
|
393
|
-
utils.runIfFn(autoCompleteProps.onCreateOption, {
|
|
394
|
-
item: utils.omit(option, ["noFilter"]),
|
|
395
|
-
selectMethod: interactionRef.current
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
var optionLabel = (option == null ? void 0 : option.label) || (option == null ? void 0 : option.value);
|
|
400
|
-
setQuery(function () {
|
|
401
|
-
return multiple ? "" : optionLabel != null ? optionLabel : "";
|
|
402
|
-
});
|
|
403
|
-
if (closeOnSelect) onClose();
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
var removeItem = function removeItem(itemValue, focusInput) {
|
|
407
|
-
var _inputRef$current3;
|
|
408
|
-
|
|
409
|
-
setValues(function (prevValues) {
|
|
410
|
-
var item = itemList.find(function (opt) {
|
|
411
|
-
return opt.value === itemValue;
|
|
412
|
-
});
|
|
413
|
-
utils.runIfFn(autoCompleteProps.onTagRemoved, itemValue, item, prevValues);
|
|
414
|
-
return prevValues.filter(function (i) {
|
|
415
|
-
return i !== itemValue;
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
if (query === itemValue) setQuery("");
|
|
419
|
-
if (focusInput) (_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.focus();
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
var resetItems = function resetItems(focusInput) {
|
|
423
|
-
var _inputRef$current4;
|
|
424
|
-
|
|
425
|
-
setValues([]);
|
|
426
|
-
if (focusInput) (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus();
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
var tags = multiple ? values.map(function (tag) {
|
|
430
|
-
var _itemList$find;
|
|
431
|
-
|
|
432
|
-
return {
|
|
433
|
-
label: ((_itemList$find = itemList.find(function (item) {
|
|
434
|
-
return item.value === tag;
|
|
435
|
-
})) == null ? void 0 : _itemList$find.label) || tag,
|
|
436
|
-
onRemove: function onRemove() {
|
|
437
|
-
return removeItem(tag);
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
}) : [];
|
|
441
|
-
React.useEffect(function () {
|
|
442
|
-
utils.runIfFn(onReady, {
|
|
443
|
-
tags: tags
|
|
444
|
-
});
|
|
445
|
-
}, [values]); // @ts-ignore
|
|
446
|
-
|
|
447
|
-
var getInputProps = function getInputProps(props, themeInput) {
|
|
448
|
-
var _onBlur = props.onBlur,
|
|
449
|
-
_onChange = props.onChange,
|
|
450
|
-
_onFocus = props.onFocus,
|
|
451
|
-
_onKeyDown = props.onKeyDown,
|
|
452
|
-
variant = props.variant,
|
|
453
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
454
|
-
|
|
455
|
-
return {
|
|
456
|
-
wrapper: _extends({
|
|
457
|
-
ref: inputWrapperRef,
|
|
458
|
-
onClick: function onClick() {
|
|
459
|
-
var _inputRef$current5;
|
|
460
|
-
|
|
461
|
-
inputRef == null ? void 0 : (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus();
|
|
462
|
-
}
|
|
463
|
-
}, getMultipleWrapStyles(themeInput, multiple), rest),
|
|
464
|
-
input: _extends({
|
|
465
|
-
isReadOnly: isReadOnly,
|
|
466
|
-
onFocus: function onFocus(e) {
|
|
467
|
-
utils.runIfFn(_onFocus, e);
|
|
468
|
-
if (autoCompleteProps.openOnFocus && !isReadOnly) onOpen();
|
|
469
|
-
if (autoCompleteProps.selectOnFocus) e.target.select();
|
|
470
|
-
if (listAllValuesOnFocus) setListAll(true);
|
|
471
|
-
},
|
|
472
|
-
onBlur: function onBlur(e) {
|
|
473
|
-
var _listRef$current, _inputWrapperRef$curr;
|
|
474
|
-
|
|
475
|
-
utils.runIfFn(_onBlur, e);
|
|
476
|
-
var listIsFocused = e.relatedTarget === (listRef == null ? void 0 : listRef.current) || ((_listRef$current = listRef.current) == null ? void 0 : _listRef$current.contains(e.relatedTarget));
|
|
477
|
-
var inputWrapperIsFocused = (_inputWrapperRef$curr = inputWrapperRef.current) == null ? void 0 : _inputWrapperRef$curr.contains(e.relatedTarget);
|
|
478
|
-
|
|
479
|
-
if (!listIsFocused && !inputWrapperIsFocused) {
|
|
480
|
-
if (closeOnBlur) onClose();
|
|
481
|
-
|
|
482
|
-
if (!values.includes(e.target.value) && restoreOnBlurIfEmpty) {
|
|
483
|
-
var latestValue = utils.getLastItem(values);
|
|
484
|
-
var latestValueItem = itemList.find(function (i) {
|
|
485
|
-
return i.value === latestValue;
|
|
486
|
-
});
|
|
487
|
-
var latestValueLabel = (latestValueItem == null ? void 0 : latestValueItem.label) || (latestValueItem == null ? void 0 : latestValueItem.value) || "";
|
|
488
|
-
setQuery(latestValueLabel);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
},
|
|
492
|
-
onChange: function onChange(e) {
|
|
493
|
-
var newValue = e.target.value;
|
|
494
|
-
utils.runIfFn(_onChange, e);
|
|
495
|
-
setQuery(newValue);
|
|
496
|
-
var queryIsEmpty = utils.isEmpty(newValue);
|
|
497
|
-
if (utils.runIfFn(shouldRenderSuggestions, newValue) && (!queryIsEmpty || suggestWhenEmpty)) onOpen();else onClose();
|
|
498
|
-
setListAll(false);
|
|
499
|
-
},
|
|
500
|
-
onKeyDown: function onKeyDown(e) {
|
|
501
|
-
utils.runIfFn(_onKeyDown, e);
|
|
502
|
-
interactionRef.current = "keyboard";
|
|
503
|
-
var key = e.key;
|
|
504
|
-
var focusedItem = filteredList[focusedIndex];
|
|
505
|
-
|
|
506
|
-
if (["Enter"].concat(submitKeys).includes(key)) {
|
|
507
|
-
var _inputRef$current6;
|
|
508
|
-
|
|
509
|
-
if (focusedItem && !(focusedItem != null && focusedItem.disabled)) selectItem(focusedItem == null ? void 0 : focusedItem.value);else (_inputRef$current6 = inputRef.current) == null ? void 0 : _inputRef$current6.focus();
|
|
510
|
-
e.preventDefault();
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
if (key === "ArrowDown") {
|
|
515
|
-
setFocusedValue(nextItem == null ? void 0 : nextItem.value);
|
|
516
|
-
e.preventDefault();
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (key === "ArrowUp") {
|
|
521
|
-
setFocusedValue(prevItem == null ? void 0 : prevItem.value);
|
|
522
|
-
e.preventDefault();
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (key === "Tab") {
|
|
527
|
-
setFocusedValue(nextItem == null ? void 0 : nextItem.value);
|
|
528
|
-
|
|
529
|
-
if (isOpen) {
|
|
530
|
-
e.preventDefault();
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
if (key === "Home") {
|
|
537
|
-
setFocusedValue(firstItem == null ? void 0 : firstItem.value);
|
|
538
|
-
e.preventDefault();
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
if (key === "End") {
|
|
543
|
-
setFocusedValue(lastItem == null ? void 0 : lastItem.value);
|
|
544
|
-
e.preventDefault();
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
if (key === "Escape") {
|
|
549
|
-
utils.callAll(onClose, e.preventDefault);
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
value: query,
|
|
553
|
-
variant: multiple ? "unstyled" : variant
|
|
554
|
-
}, rest)
|
|
555
|
-
};
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
var wrapperDim = react.useDimensions(inputWrapperRef, true);
|
|
559
|
-
var inputDim = react.useDimensions(inputRef, true);
|
|
560
|
-
|
|
561
|
-
var getListProps = function getListProps() {
|
|
562
|
-
var width = autoCompleteProps.multiple ? wrapperDim == null ? void 0 : wrapperDim.marginBox.width : inputDim == null ? void 0 : inputDim.marginBox.width;
|
|
563
|
-
return {
|
|
564
|
-
width: width
|
|
565
|
-
};
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
var getItemProps = function getItemProps(props, creatable) {
|
|
569
|
-
var _getValue;
|
|
570
|
-
|
|
571
|
-
var _fixed = props._fixed,
|
|
572
|
-
_focus = props._focus,
|
|
573
|
-
itemChild = props.children,
|
|
574
|
-
disabled = props.disabled,
|
|
575
|
-
label = props.label,
|
|
576
|
-
valueProp = props.value,
|
|
577
|
-
fixed = props.fixed,
|
|
578
|
-
_props$getValue = props.getValue,
|
|
579
|
-
getValue = _props$getValue === void 0 ? getDefItemValue : _props$getValue,
|
|
580
|
-
_onClick = props.onClick,
|
|
581
|
-
_onMouseOver = props.onMouseOver,
|
|
582
|
-
sx = props.sx,
|
|
583
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
584
|
-
|
|
585
|
-
var value = creatable ? valueProp : (_getValue = getValue(valueProp)) == null ? void 0 : _getValue.toString();
|
|
586
|
-
var isFocused = value === focusedValue;
|
|
587
|
-
var isValidSuggestion = filteredList.findIndex(function (i) {
|
|
588
|
-
return i.value === value;
|
|
589
|
-
}) >= 0;
|
|
590
|
-
var itemLabel = itemChild || label || value;
|
|
591
|
-
return {
|
|
592
|
-
item: _extends({}, typeof itemLabel !== "string" || !emphasize ? {
|
|
593
|
-
children: itemLabel
|
|
594
|
-
} : {
|
|
595
|
-
dangerouslySetInnerHTML: {
|
|
596
|
-
__html: setEmphasis(itemLabel, query)
|
|
597
|
-
}
|
|
598
|
-
}, {
|
|
599
|
-
"aria-selected": values.includes(value),
|
|
600
|
-
"aria-disabled": disabled,
|
|
601
|
-
_disabled: {
|
|
602
|
-
opacity: 0.4,
|
|
603
|
-
cursor: "not-allowed",
|
|
604
|
-
userSelect: "none"
|
|
605
|
-
},
|
|
606
|
-
onClick: function onClick(e) {
|
|
607
|
-
var _inputRef$current7;
|
|
608
|
-
|
|
609
|
-
utils.runIfFn(_onClick, e);
|
|
610
|
-
if (!disabled) selectItem(value);else (_inputRef$current7 = inputRef.current) == null ? void 0 : _inputRef$current7.focus();
|
|
611
|
-
},
|
|
612
|
-
onMouseOver: function onMouseOver(e) {
|
|
613
|
-
utils.runIfFn(_onMouseOver, e);
|
|
614
|
-
setFocusedValue(value);
|
|
615
|
-
interactionRef.current = "mouse";
|
|
616
|
-
},
|
|
617
|
-
sx: _extends({}, sx, {
|
|
618
|
-
mark: _extends({
|
|
619
|
-
color: "inherit",
|
|
620
|
-
bg: "transparent"
|
|
621
|
-
}, utils.isObject(emphasize) ? emphasize : {
|
|
622
|
-
fontWeight: emphasize ? "extrabold" : "inherit"
|
|
623
|
-
})
|
|
624
|
-
})
|
|
625
|
-
}, isFocused && (_focus || getFocusedStyles()), fixed && _fixed, rest),
|
|
626
|
-
root: {
|
|
627
|
-
isValidSuggestion: isValidSuggestion,
|
|
628
|
-
value: value
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
var getGroupProps = function getGroupProps(props) {
|
|
634
|
-
var hasItems = hasChildren(props.children, filteredList);
|
|
635
|
-
return {
|
|
636
|
-
divider: {
|
|
637
|
-
hasFirstChild: hasFirstItem(props.children, firstItem),
|
|
638
|
-
hasLastChild: hasLastItem(props.children, utils.getLastItem(filteredList.filter(function (i) {
|
|
639
|
-
return utils.isUndefined(i == null ? void 0 : i.noFilter);
|
|
640
|
-
})))
|
|
641
|
-
},
|
|
642
|
-
group: {
|
|
643
|
-
display: hasItems ? "initial" : "none"
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
var getEmptyStateProps = function getEmptyStateProps(defaultEmptyState) {
|
|
649
|
-
var noSuggestions = filteredList.every(function (i) {
|
|
650
|
-
return i.noFilter;
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
if (noSuggestions && emptyState && !creatable) {
|
|
654
|
-
return typeof emptyState === "boolean" ? defaultEmptyState // @ts-ignore
|
|
655
|
-
: utils.runIfFn(emptyState, {
|
|
656
|
-
query: query
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
return {
|
|
662
|
-
autoCompleteProps: autoCompleteProps,
|
|
663
|
-
children: children,
|
|
664
|
-
filteredList: filteredList,
|
|
665
|
-
filteredResults: filteredResults,
|
|
666
|
-
focusedValue: focusedValue,
|
|
667
|
-
getEmptyStateProps: getEmptyStateProps,
|
|
668
|
-
getGroupProps: getGroupProps,
|
|
669
|
-
getInputProps: getInputProps,
|
|
670
|
-
getItemProps: getItemProps,
|
|
671
|
-
getListProps: getListProps,
|
|
672
|
-
inputRef: inputRef,
|
|
673
|
-
interactionRef: interactionRef,
|
|
674
|
-
isOpen: isOpen,
|
|
675
|
-
itemList: itemList,
|
|
676
|
-
listRef: listRef,
|
|
677
|
-
onClose: onClose,
|
|
678
|
-
onOpen: onOpen,
|
|
679
|
-
query: query,
|
|
680
|
-
removeItem: removeItem,
|
|
681
|
-
resetItems: resetItems,
|
|
682
|
-
setQuery: setQuery,
|
|
683
|
-
tags: tags,
|
|
684
|
-
values: values
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
var AutoComplete = /*#__PURE__*/react.forwardRef(function (props, ref) {
|
|
689
|
-
var context = useAutoComplete(props);
|
|
690
|
-
var children = context.children,
|
|
691
|
-
isOpen = context.isOpen,
|
|
692
|
-
onClose = context.onClose,
|
|
693
|
-
onOpen = context.onOpen,
|
|
694
|
-
resetItems = context.resetItems,
|
|
695
|
-
removeItem = context.removeItem;
|
|
696
|
-
React.useImperativeHandle(ref, function () {
|
|
697
|
-
return {
|
|
698
|
-
resetItems: resetItems,
|
|
699
|
-
removeItem: removeItem
|
|
700
|
-
};
|
|
701
|
-
});
|
|
702
|
-
return React__default.createElement(AutoCompleteProvider, {
|
|
703
|
-
value: context
|
|
704
|
-
}, React__default.createElement(react.Popover, {
|
|
705
|
-
isLazy: true,
|
|
706
|
-
isOpen: isOpen,
|
|
707
|
-
onClose: onClose,
|
|
708
|
-
onOpen: onOpen,
|
|
709
|
-
autoFocus: false,
|
|
710
|
-
placement: "bottom",
|
|
711
|
-
closeOnBlur: true
|
|
712
|
-
}, React__default.createElement(react.chakra.div, {
|
|
713
|
-
sx: {
|
|
714
|
-
".chakra-popover__popper": {
|
|
715
|
-
position: "unset !important"
|
|
716
|
-
}
|
|
717
|
-
},
|
|
718
|
-
w: "full",
|
|
719
|
-
ref: ref
|
|
720
|
-
}, children)));
|
|
721
|
-
});
|
|
722
|
-
AutoComplete.displayName = "AutoComplete";
|
|
723
|
-
|
|
724
|
-
var _excluded$1 = ["children", "dangerouslySetInnerHTML"];
|
|
725
|
-
var AutoCompleteItem = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
726
|
-
var _useAutoCompleteConte = useAutoCompleteContext(),
|
|
727
|
-
focusedValue = _useAutoCompleteConte.focusedValue,
|
|
728
|
-
getItemProps = _useAutoCompleteConte.getItemProps,
|
|
729
|
-
interactionRef = _useAutoCompleteConte.interactionRef;
|
|
730
|
-
|
|
731
|
-
var itemRef = React.useRef();
|
|
732
|
-
var ref = react.useMergeRefs(forwardedRef, itemRef);
|
|
733
|
-
var itemProps = getItemProps(props);
|
|
734
|
-
var _itemProps$root = itemProps.root,
|
|
735
|
-
isValidSuggestion = _itemProps$root.isValidSuggestion,
|
|
736
|
-
value = _itemProps$root.value;
|
|
737
|
-
var isFocused = focusedValue === value;
|
|
738
|
-
React.useEffect(function () {
|
|
739
|
-
var _itemRef$current;
|
|
740
|
-
|
|
741
|
-
if (isFocused && interactionRef.current === "keyboard") itemRef == null ? void 0 : (_itemRef$current = itemRef.current) == null ? void 0 : _itemRef$current.scrollIntoView({
|
|
742
|
-
behavior: "smooth",
|
|
743
|
-
block: "center"
|
|
744
|
-
});
|
|
745
|
-
}, [isFocused, interactionRef]);
|
|
746
|
-
React.useEffect(function () {
|
|
747
|
-
if (typeof value !== "string") console.warn("wow");
|
|
748
|
-
if (typeof value !== "string" && utils.isUndefined(props.getValue)) console.error("You must define the `getValue` prop, when an Item's value is not a string");
|
|
749
|
-
}, []);
|
|
750
|
-
|
|
751
|
-
var _itemProps$item = itemProps.item,
|
|
752
|
-
children = _itemProps$item.children,
|
|
753
|
-
dangerouslySetInnerHTML = _itemProps$item.dangerouslySetInnerHTML,
|
|
754
|
-
restProps = _objectWithoutPropertiesLoose(_itemProps$item, _excluded$1);
|
|
755
|
-
|
|
756
|
-
var rest = utils.omit(restProps, ["groupId"]);
|
|
757
|
-
return isValidSuggestion ? React__default.createElement(react.Flex, Object.assign({
|
|
758
|
-
ref: ref
|
|
759
|
-
}, baseItemStyles, rest), children ? children : React__default.createElement("span", {
|
|
760
|
-
dangerouslySetInnerHTML: dangerouslySetInnerHTML
|
|
761
|
-
})) : null;
|
|
762
|
-
});
|
|
763
|
-
AutoCompleteItem.displayName = "AutoCompleteItem";
|
|
764
|
-
var baseItemStyles = {
|
|
765
|
-
mx: "2",
|
|
766
|
-
px: "2",
|
|
767
|
-
py: "2",
|
|
768
|
-
rounded: "md",
|
|
769
|
-
cursor: "pointer"
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
var _excluded$2 = ["alwaysDisplay", "children"],
|
|
773
|
-
_excluded2$1 = ["children"];
|
|
774
|
-
function AutoCompleteCreatable(props) {
|
|
775
|
-
var alwaysDisplay = props.alwaysDisplay,
|
|
776
|
-
childrenProp = props.children,
|
|
777
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded$2);
|
|
778
|
-
|
|
779
|
-
var _useAutoCompleteConte = useAutoCompleteContext(),
|
|
780
|
-
autoCompleteProps = _useAutoCompleteConte.autoCompleteProps,
|
|
781
|
-
getItemProps = _useAutoCompleteConte.getItemProps,
|
|
782
|
-
query = _useAutoCompleteConte.query,
|
|
783
|
-
filteredResults = _useAutoCompleteConte.filteredResults;
|
|
784
|
-
|
|
785
|
-
var _getItemProps$item = getItemProps(_extends({}, props, {
|
|
786
|
-
value: query,
|
|
787
|
-
children: utils.runIfFn(childrenProp, {
|
|
788
|
-
value: query
|
|
789
|
-
})
|
|
790
|
-
}), true).item,
|
|
791
|
-
children = _getItemProps$item.children,
|
|
792
|
-
itemProps = _objectWithoutPropertiesLoose(_getItemProps$item, _excluded2$1);
|
|
793
|
-
|
|
794
|
-
var queryExistsInList = filteredResults.some(function (i) {
|
|
795
|
-
return i.value === query;
|
|
796
|
-
});
|
|
797
|
-
var showWhenEmpty = utils.isEmpty(query) ? alwaysDisplay : true;
|
|
798
|
-
var showCreatable = autoCompleteProps.creatable && showWhenEmpty && !queryExistsInList;
|
|
799
|
-
return showCreatable ? React__default.createElement(react.Flex, Object.assign({}, baseItemStyles, itemProps, rest), children || "Add " + query) : null;
|
|
800
|
-
}
|
|
801
|
-
AutoCompleteCreatable.displayName = "AutoCompleteCreatable";
|
|
802
|
-
|
|
803
|
-
var _excluded$3 = ["children", "showDivider"];
|
|
804
|
-
var AutoCompleteGroup = /*#__PURE__*/react.forwardRef(function (props, ref) {
|
|
805
|
-
var children = props.children,
|
|
806
|
-
restProps = _objectWithoutPropertiesLoose(props, _excluded$3);
|
|
807
|
-
|
|
808
|
-
var rest = utils.omit(restProps, ["groupSibling"]);
|
|
809
|
-
|
|
810
|
-
var _useAutoCompleteConte = useAutoCompleteContext(),
|
|
811
|
-
getGroupProps = _useAutoCompleteConte.getGroupProps;
|
|
812
|
-
|
|
813
|
-
var _getGroupProps = getGroupProps(props),
|
|
814
|
-
group = _getGroupProps.group;
|
|
815
|
-
|
|
816
|
-
var dividerStyles = useDividerStyles(props);
|
|
817
|
-
return React__default.createElement(react.Box, Object.assign({
|
|
818
|
-
ref: ref
|
|
819
|
-
}, group, rest), React__default.createElement(react.Divider, Object.assign({}, dividerStyles.top)), children, React__default.createElement(react.Divider, Object.assign({}, dividerStyles.bottom)));
|
|
820
|
-
});
|
|
821
|
-
var AutoCompleteGroupTitle = /*#__PURE__*/react.forwardRef(function (props, ref) {
|
|
822
|
-
return React__default.createElement(react.Flex, Object.assign({}, baseTitleStyles, props, {
|
|
823
|
-
ref: ref
|
|
824
|
-
}));
|
|
825
|
-
});
|
|
826
|
-
AutoCompleteGroup.displayName = "AutoCompleteGroup";
|
|
827
|
-
AutoCompleteGroupTitle.displayName = "AutoCompleteGroupTitle";
|
|
828
|
-
var baseTitleStyles = {
|
|
829
|
-
ml: 5,
|
|
830
|
-
my: 1,
|
|
831
|
-
fontSize: "xs",
|
|
832
|
-
letterSpacing: "wider",
|
|
833
|
-
fontWeight: "extrabold",
|
|
834
|
-
textTransform: "uppercase"
|
|
835
|
-
};
|
|
836
|
-
|
|
837
|
-
var useDividerStyles = function useDividerStyles(props) {
|
|
838
|
-
var _useAutoCompleteConte2 = useAutoCompleteContext(),
|
|
839
|
-
getGroupProps = _useAutoCompleteConte2.getGroupProps;
|
|
840
|
-
|
|
841
|
-
var hasGroupSibling = props.groupSibling;
|
|
842
|
-
|
|
843
|
-
var _getGroupProps2 = getGroupProps(props),
|
|
844
|
-
_getGroupProps2$divid = _getGroupProps2.divider,
|
|
845
|
-
hasFirstChild = _getGroupProps2$divid.hasFirstChild,
|
|
846
|
-
hasLastChild = _getGroupProps2$divid.hasLastChild;
|
|
847
|
-
|
|
848
|
-
var baseStyles = {
|
|
849
|
-
my: 2,
|
|
850
|
-
borderColor: props.dividerColor
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
var top = _extends({}, baseStyles, {
|
|
854
|
-
mb: 4,
|
|
855
|
-
display: !props.showDivider || hasFirstChild ? "none" : ""
|
|
856
|
-
});
|
|
857
|
-
|
|
858
|
-
var bottom = _extends({}, baseStyles, {
|
|
859
|
-
display: !props.showDivider || hasLastChild || hasGroupSibling ? "none" : ""
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
return {
|
|
863
|
-
top: top,
|
|
864
|
-
bottom: bottom
|
|
865
|
-
};
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
var _excluded$4 = ["children", "isInvalid"],
|
|
869
|
-
_excluded2$2 = ["ref"];
|
|
870
|
-
var AutoCompleteInput = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
871
|
-
var _useAutoCompleteConte = useAutoCompleteContext(),
|
|
872
|
-
autoCompleteProps = _useAutoCompleteConte.autoCompleteProps,
|
|
873
|
-
inputRef = _useAutoCompleteConte.inputRef,
|
|
874
|
-
getInputProps = _useAutoCompleteConte.getInputProps,
|
|
875
|
-
tags = _useAutoCompleteConte.tags; // const ref = useMergeRefs(forwardedRef, inputRef);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
var childrenProp = props.children,
|
|
879
|
-
isInvalid = props.isInvalid,
|
|
880
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded$4);
|
|
881
|
-
|
|
882
|
-
var themeInput = react.useMultiStyleConfig("Input", props);
|
|
883
|
-
|
|
884
|
-
var _getInputProps = getInputProps(rest, themeInput),
|
|
885
|
-
wrapper = _getInputProps.wrapper,
|
|
886
|
-
inputProps = _getInputProps.input;
|
|
887
|
-
|
|
888
|
-
var wrapperRef = wrapper.ref,
|
|
889
|
-
wrapperProps = _objectWithoutPropertiesLoose(wrapper, _excluded2$2);
|
|
890
|
-
|
|
891
|
-
var ref = react.useMergeRefs(forwardedRef, inputRef);
|
|
892
|
-
var children = utils.runIfFn(childrenProp, {
|
|
893
|
-
tags: tags
|
|
894
|
-
});
|
|
895
|
-
var simpleInput = React__default.createElement(react.Input, Object.assign({
|
|
896
|
-
isInvalid: isInvalid
|
|
897
|
-
}, inputProps, {
|
|
898
|
-
ref: ref
|
|
899
|
-
}));
|
|
900
|
-
var multipleInput = React__default.createElement(react.Wrap, Object.assign({}, wrapperProps, {
|
|
901
|
-
ref: wrapperRef
|
|
902
|
-
}), children, React__default.createElement(react.WrapItem, Object.assign({
|
|
903
|
-
as: react.Input
|
|
904
|
-
}, inputProps, {
|
|
905
|
-
ref: ref
|
|
906
|
-
})));
|
|
907
|
-
return React__default.createElement(React__default.Fragment, null, autoCompleteProps.multiple ? multipleInput : simpleInput);
|
|
908
|
-
});
|
|
909
|
-
AutoCompleteInput.displayName = "Input";
|
|
910
|
-
AutoCompleteInput.id = "Input";
|
|
911
|
-
|
|
912
|
-
var EmptyState = function EmptyState(props) {
|
|
913
|
-
var _useAutoCompleteConte = useAutoCompleteContext(),
|
|
914
|
-
getEmptyStateProps = _useAutoCompleteConte.getEmptyStateProps;
|
|
915
|
-
|
|
916
|
-
var emptyState = getEmptyStateProps(React__default.createElement(layout.Flex, Object.assign({}, emptyStyles), "No options found!"));
|
|
917
|
-
return React__default.createElement(layout.Box, Object.assign({}, props), emptyState);
|
|
918
|
-
};
|
|
919
|
-
var emptyStyles = {
|
|
920
|
-
fontSize: "sm",
|
|
921
|
-
align: "center",
|
|
922
|
-
justify: "center",
|
|
923
|
-
fontWeight: "bold",
|
|
924
|
-
fontStyle: "italic"
|
|
925
|
-
};
|
|
926
|
-
|
|
927
|
-
var VALID_AUTOCOMPLETE_LIST_CHILDREN = ["AutoCompleteGroup", "AutoCompleteItem", "AutoCompleteCreatable"];
|
|
928
|
-
var siblingInfo = function siblingInfo(children) {
|
|
929
|
-
var items = React__default.Children.map(children, function (child, i) {
|
|
930
|
-
var _child$type;
|
|
931
|
-
|
|
932
|
-
if ((child == null ? void 0 : (_child$type = child.type) == null ? void 0 : _child$type.displayName) === "AutoCompleteGroup") {
|
|
933
|
-
var sibling = React__default.Children.toArray(children)[i + 1];
|
|
934
|
-
return React__default.cloneElement(child, {
|
|
935
|
-
groupSibling: sibling ? sibling.type.displayName === "AutoCompleteGroup" : false
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
return child;
|
|
940
|
-
});
|
|
941
|
-
var nonAutocompleteItems = React__default.Children.toArray(items).filter(function (child) {
|
|
942
|
-
var _child$type2;
|
|
943
|
-
|
|
944
|
-
return !VALID_AUTOCOMPLETE_LIST_CHILDREN.includes(child == null ? void 0 : (_child$type2 = child.type) == null ? void 0 : _child$type2.displayName);
|
|
945
|
-
});
|
|
946
|
-
var autoCompleteItems = React__default.Children.toArray(items).filter(function (child) {
|
|
947
|
-
var _child$type3;
|
|
948
|
-
|
|
949
|
-
return VALID_AUTOCOMPLETE_LIST_CHILDREN.includes(child == null ? void 0 : (_child$type3 = child.type) == null ? void 0 : _child$type3.displayName);
|
|
950
|
-
});
|
|
951
|
-
return [autoCompleteItems, nonAutocompleteItems];
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
var _excluded$5 = ["children"];
|
|
955
|
-
var AutoCompleteList = /*#__PURE__*/react.forwardRef(function (props, forwardedRef) {
|
|
956
|
-
var children = props.children,
|
|
957
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded$5);
|
|
958
|
-
|
|
959
|
-
var _useAutoCompleteConte = useAutoCompleteContext(),
|
|
960
|
-
listRef = _useAutoCompleteConte.listRef,
|
|
961
|
-
getListProps = _useAutoCompleteConte.getListProps;
|
|
962
|
-
|
|
963
|
-
var ref = react.useMergeRefs(forwardedRef, listRef);
|
|
964
|
-
var listProps = getListProps();
|
|
965
|
-
|
|
966
|
-
var _siblingInfo = siblingInfo(children),
|
|
967
|
-
autoCompleteItems = _siblingInfo[0],
|
|
968
|
-
nonAutoCompleteItems = _siblingInfo[1];
|
|
969
|
-
|
|
970
|
-
return React__default.createElement(react.PopoverContent, Object.assign({
|
|
971
|
-
ref: ref
|
|
972
|
-
}, baseStyles, listProps, rest), autoCompleteItems, React__default.createElement(EmptyState, null), nonAutoCompleteItems);
|
|
973
|
-
});
|
|
974
|
-
AutoCompleteList.displayName = "AutoCompleteList";
|
|
975
|
-
var baseStyles = {
|
|
976
|
-
mt: "4",
|
|
977
|
-
py: "4",
|
|
978
|
-
opacity: "0",
|
|
979
|
-
bg: "#232934",
|
|
980
|
-
rounded: "md",
|
|
981
|
-
maxH: "350px",
|
|
982
|
-
border: "none",
|
|
983
|
-
shadow: "base",
|
|
984
|
-
pos: "absolute",
|
|
985
|
-
zIndex: "popover",
|
|
986
|
-
overflowY: "auto",
|
|
987
|
-
_light: {
|
|
988
|
-
bg: "#ffffff"
|
|
989
|
-
},
|
|
990
|
-
_focus: {
|
|
991
|
-
boxShadow: "none"
|
|
992
|
-
}
|
|
993
|
-
};
|
|
994
|
-
|
|
995
|
-
var _excluded$6 = ["label", "onRemove", "disabled"];
|
|
996
|
-
var AutoCompleteTag = /*#__PURE__*/React.memo(function (props) {
|
|
997
|
-
var label = props.label,
|
|
998
|
-
onRemove = props.onRemove,
|
|
999
|
-
disabled = props.disabled,
|
|
1000
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded$6);
|
|
1001
|
-
|
|
1002
|
-
return React__default.createElement(layout.WrapItem, null, React__default.createElement(tag.Tag, Object.assign({
|
|
1003
|
-
borderRadius: "md",
|
|
1004
|
-
fontWeight: "normal"
|
|
1005
|
-
}, disabled && disabledStyles, rest), React__default.createElement(tag.TagLabel, null, label), React__default.createElement(tag.TagCloseButton, Object.assign({
|
|
1006
|
-
onClick: function onClick() {
|
|
1007
|
-
return !disabled && utils.runIfFn(onRemove);
|
|
1008
|
-
},
|
|
1009
|
-
cursor: "pointer"
|
|
1010
|
-
}, disabled && disabledStyles))));
|
|
1011
|
-
});
|
|
1012
|
-
var disabledStyles = {
|
|
1013
|
-
cursor: "text",
|
|
1014
|
-
userSelect: "none",
|
|
1015
|
-
opacity: 0.4,
|
|
1016
|
-
_focus: {
|
|
1017
|
-
boxShadow: "none"
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
|
-
exports.AutoComplete = AutoComplete;
|
|
1022
|
-
exports.AutoCompleteCreatable = AutoCompleteCreatable;
|
|
1023
|
-
exports.AutoCompleteGroup = AutoCompleteGroup;
|
|
1024
|
-
exports.AutoCompleteGroupTitle = AutoCompleteGroupTitle;
|
|
1025
|
-
exports.AutoCompleteInput = AutoCompleteInput;
|
|
1026
|
-
exports.AutoCompleteItem = AutoCompleteItem;
|
|
1027
|
-
exports.AutoCompleteList = AutoCompleteList;
|
|
1028
|
-
exports.AutoCompleteProvider = AutoCompleteProvider;
|
|
1029
|
-
exports.AutoCompleteTag = AutoCompleteTag;
|
|
1030
|
-
exports.baseItemStyles = baseItemStyles;
|
|
1031
|
-
exports.useAutoComplete = useAutoComplete;
|
|
1032
|
-
exports.useAutoCompleteContext = useAutoCompleteContext;
|
|
1033
|
-
//# sourceMappingURL=chakra-autocomplete.cjs.development.js.map
|