@algolia/autocomplete-core 1.0.0 → 1.2.1
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/esm/getCompletion.js +3 -4
- package/dist/esm/getDefaultProps.js +3 -0
- package/dist/esm/onKeyDown.js +88 -61
- package/dist/esm/resolve.js +3 -2
- package/dist/esm/stateReducer.js +3 -1
- package/dist/esm/types/AutocompleteStore.d.ts +1 -1
- package/dist/esm/utils/getNextActiveItemId.js +4 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/index.development.js +106 -70
- package/dist/umd/index.development.js.map +1 -1
- package/dist/umd/index.production.js +2 -2
- package/dist/umd/index.production.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { getActiveItem } from './utils';
|
|
2
2
|
export function getCompletion(_ref) {
|
|
3
|
+
var _getActiveItem;
|
|
4
|
+
|
|
3
5
|
var state = _ref.state;
|
|
4
6
|
|
|
5
7
|
if (state.isOpen === false || state.activeItemId === null) {
|
|
6
8
|
return null;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
itemInputValue = _ref2.itemInputValue;
|
|
11
|
-
|
|
12
|
-
return itemInputValue || null;
|
|
11
|
+
return ((_getActiveItem = getActiveItem(state)) === null || _getActiveItem === void 0 ? void 0 : _getActiveItem.itemInputValue) || null;
|
|
13
12
|
}
|
|
@@ -21,7 +21,10 @@ import { getNormalizedSources, flatten } from './utils';
|
|
|
21
21
|
export function getDefaultProps(props, pluginSubscribers) {
|
|
22
22
|
var _props$id;
|
|
23
23
|
|
|
24
|
+
/* eslint-disable no-restricted-globals */
|
|
24
25
|
var environment = typeof window !== 'undefined' ? window : {};
|
|
26
|
+
/* eslint-enable no-restricted-globals */
|
|
27
|
+
|
|
25
28
|
var plugins = props.plugins || [];
|
|
26
29
|
return _objectSpread(_objectSpread({
|
|
27
30
|
debug: false,
|
package/dist/esm/onKeyDown.js
CHANGED
|
@@ -18,36 +18,66 @@ export function onKeyDown(_ref) {
|
|
|
18
18
|
setters = _objectWithoutProperties(_ref, ["event", "props", "refresh", "store"]);
|
|
19
19
|
|
|
20
20
|
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
// eslint-disable-next-line no-inner-declarations
|
|
22
|
+
var triggerScrollIntoView = function triggerScrollIntoView() {
|
|
23
|
+
var nodeItem = props.environment.document.getElementById("".concat(props.id, "-item-").concat(store.getState().activeItemId));
|
|
24
|
+
|
|
25
|
+
if (nodeItem) {
|
|
26
|
+
if (nodeItem.scrollIntoViewIfNeeded) {
|
|
27
|
+
nodeItem.scrollIntoViewIfNeeded(false);
|
|
28
|
+
} else {
|
|
29
|
+
nodeItem.scrollIntoView(false);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}; // eslint-disable-next-line no-inner-declarations
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
|
|
35
|
+
var triggerOnActive = function triggerOnActive() {
|
|
36
|
+
var highlightedItem = getActiveItem(store.getState());
|
|
37
|
+
|
|
38
|
+
if (store.getState().activeItemId !== null && highlightedItem) {
|
|
39
|
+
var item = highlightedItem.item,
|
|
40
|
+
itemInputValue = highlightedItem.itemInputValue,
|
|
41
|
+
itemUrl = highlightedItem.itemUrl,
|
|
42
|
+
source = highlightedItem.source;
|
|
43
|
+
source.onActive(_objectSpread({
|
|
44
|
+
event: event,
|
|
45
|
+
item: item,
|
|
46
|
+
itemInputValue: itemInputValue,
|
|
47
|
+
itemUrl: itemUrl,
|
|
48
|
+
refresh: refresh,
|
|
49
|
+
source: source,
|
|
50
|
+
state: store.getState()
|
|
51
|
+
}, setters));
|
|
32
52
|
}
|
|
33
|
-
}
|
|
53
|
+
}; // Default browser behavior changes the caret placement on ArrowUp and
|
|
54
|
+
// ArrowDown.
|
|
55
|
+
|
|
34
56
|
|
|
35
|
-
|
|
57
|
+
event.preventDefault(); // When re-opening the panel, we need to split the logic to keep the actions
|
|
58
|
+
// synchronized as `onInput` returns a promise.
|
|
36
59
|
|
|
37
|
-
if (store.getState().
|
|
38
|
-
|
|
39
|
-
itemInputValue = highlightedItem.itemInputValue,
|
|
40
|
-
itemUrl = highlightedItem.itemUrl,
|
|
41
|
-
source = highlightedItem.source;
|
|
42
|
-
source.onActive(_objectSpread({
|
|
60
|
+
if (store.getState().isOpen === false && (props.openOnFocus || Boolean(store.getState().query))) {
|
|
61
|
+
onInput(_objectSpread({
|
|
43
62
|
event: event,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
itemUrl: itemUrl,
|
|
63
|
+
props: props,
|
|
64
|
+
query: store.getState().query,
|
|
47
65
|
refresh: refresh,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
store: store
|
|
67
|
+
}, setters)).then(function () {
|
|
68
|
+
store.dispatch(event.key, {
|
|
69
|
+
nextActiveItemId: props.defaultActiveItemId
|
|
70
|
+
});
|
|
71
|
+
triggerOnActive(); // Since we rely on the DOM, we need to wait for all the micro tasks to
|
|
72
|
+
// finish (which include re-opening the panel) to make sure all the
|
|
73
|
+
// elements are available.
|
|
74
|
+
|
|
75
|
+
setTimeout(triggerScrollIntoView, 0);
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
store.dispatch(event.key, {});
|
|
79
|
+
triggerOnActive();
|
|
80
|
+
triggerScrollIntoView();
|
|
51
81
|
}
|
|
52
82
|
} else if (event.key === 'Escape') {
|
|
53
83
|
// This prevents the default browser behavior on `input[type="search"]`
|
|
@@ -69,63 +99,60 @@ export function onKeyDown(_ref) {
|
|
|
69
99
|
event.preventDefault();
|
|
70
100
|
|
|
71
101
|
var _ref2 = getActiveItem(store.getState()),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
102
|
+
item = _ref2.item,
|
|
103
|
+
itemInputValue = _ref2.itemInputValue,
|
|
104
|
+
itemUrl = _ref2.itemUrl,
|
|
105
|
+
source = _ref2.source;
|
|
76
106
|
|
|
77
107
|
if (event.metaKey || event.ctrlKey) {
|
|
78
|
-
if (
|
|
79
|
-
|
|
108
|
+
if (itemUrl !== undefined) {
|
|
109
|
+
source.onSelect(_objectSpread({
|
|
80
110
|
event: event,
|
|
81
|
-
item:
|
|
82
|
-
itemInputValue:
|
|
83
|
-
itemUrl:
|
|
111
|
+
item: item,
|
|
112
|
+
itemInputValue: itemInputValue,
|
|
113
|
+
itemUrl: itemUrl,
|
|
84
114
|
refresh: refresh,
|
|
85
|
-
source:
|
|
115
|
+
source: source,
|
|
86
116
|
state: store.getState()
|
|
87
117
|
}, setters));
|
|
88
|
-
|
|
89
118
|
props.navigator.navigateNewTab({
|
|
90
|
-
itemUrl:
|
|
91
|
-
item:
|
|
119
|
+
itemUrl: itemUrl,
|
|
120
|
+
item: item,
|
|
92
121
|
state: store.getState()
|
|
93
122
|
});
|
|
94
123
|
}
|
|
95
124
|
} else if (event.shiftKey) {
|
|
96
|
-
if (
|
|
97
|
-
|
|
125
|
+
if (itemUrl !== undefined) {
|
|
126
|
+
source.onSelect(_objectSpread({
|
|
98
127
|
event: event,
|
|
99
|
-
item:
|
|
100
|
-
itemInputValue:
|
|
101
|
-
itemUrl:
|
|
128
|
+
item: item,
|
|
129
|
+
itemInputValue: itemInputValue,
|
|
130
|
+
itemUrl: itemUrl,
|
|
102
131
|
refresh: refresh,
|
|
103
|
-
source:
|
|
132
|
+
source: source,
|
|
104
133
|
state: store.getState()
|
|
105
134
|
}, setters));
|
|
106
|
-
|
|
107
135
|
props.navigator.navigateNewWindow({
|
|
108
|
-
itemUrl:
|
|
109
|
-
item:
|
|
136
|
+
itemUrl: itemUrl,
|
|
137
|
+
item: item,
|
|
110
138
|
state: store.getState()
|
|
111
139
|
});
|
|
112
140
|
}
|
|
113
141
|
} else if (event.altKey) {// Keep native browser behavior
|
|
114
142
|
} else {
|
|
115
|
-
if (
|
|
116
|
-
|
|
143
|
+
if (itemUrl !== undefined) {
|
|
144
|
+
source.onSelect(_objectSpread({
|
|
117
145
|
event: event,
|
|
118
|
-
item:
|
|
119
|
-
itemInputValue:
|
|
120
|
-
itemUrl:
|
|
146
|
+
item: item,
|
|
147
|
+
itemInputValue: itemInputValue,
|
|
148
|
+
itemUrl: itemUrl,
|
|
121
149
|
refresh: refresh,
|
|
122
|
-
source:
|
|
150
|
+
source: source,
|
|
123
151
|
state: store.getState()
|
|
124
152
|
}, setters));
|
|
125
|
-
|
|
126
153
|
props.navigator.navigate({
|
|
127
|
-
itemUrl:
|
|
128
|
-
item:
|
|
154
|
+
itemUrl: itemUrl,
|
|
155
|
+
item: item,
|
|
129
156
|
state: store.getState()
|
|
130
157
|
});
|
|
131
158
|
return;
|
|
@@ -137,17 +164,17 @@ export function onKeyDown(_ref) {
|
|
|
137
164
|
isOpen: false
|
|
138
165
|
},
|
|
139
166
|
props: props,
|
|
140
|
-
query:
|
|
167
|
+
query: itemInputValue,
|
|
141
168
|
refresh: refresh,
|
|
142
169
|
store: store
|
|
143
170
|
}, setters)).then(function () {
|
|
144
|
-
|
|
171
|
+
source.onSelect(_objectSpread({
|
|
145
172
|
event: event,
|
|
146
|
-
item:
|
|
147
|
-
itemInputValue:
|
|
148
|
-
itemUrl:
|
|
173
|
+
item: item,
|
|
174
|
+
itemInputValue: itemInputValue,
|
|
175
|
+
itemUrl: itemUrl,
|
|
149
176
|
refresh: refresh,
|
|
150
|
-
source:
|
|
177
|
+
source: source,
|
|
151
178
|
state: store.getState()
|
|
152
179
|
}, setters));
|
|
153
180
|
});
|
package/dist/esm/resolve.js
CHANGED
|
@@ -26,7 +26,7 @@ function isDescription(item) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function isRequesterDescription(description) {
|
|
29
|
-
return Boolean(description.execute);
|
|
29
|
+
return Boolean(description === null || description === void 0 ? void 0 : description.execute);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function preResolve(itemsOrDescription, sourceId) {
|
|
@@ -105,7 +105,8 @@ export function postResolve(responses, sources) {
|
|
|
105
105
|
});
|
|
106
106
|
var transform = matches[0].transformResponse;
|
|
107
107
|
var items = transform ? transform(mapToAlgoliaResponse(results)) : results;
|
|
108
|
-
invariant(Array.isArray(items), "The `getItems` function must return an array of items but returned type ".concat(JSON.stringify(_typeof(items)), ":\n\n").concat(JSON.stringify(items, null, 2)));
|
|
108
|
+
invariant(Array.isArray(items), "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned type ").concat(JSON.stringify(_typeof(items)), ":\n\n").concat(JSON.stringify(items, null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
|
|
109
|
+
invariant(items.every(Boolean), "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned ").concat(JSON.stringify(undefined), ".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
|
|
109
110
|
return {
|
|
110
111
|
source: source,
|
|
111
112
|
items: items
|
package/dist/esm/stateReducer.js
CHANGED
|
@@ -55,7 +55,7 @@ export var stateReducer = function stateReducer(state, action) {
|
|
|
55
55
|
case 'ArrowDown':
|
|
56
56
|
{
|
|
57
57
|
var nextState = _objectSpread(_objectSpread({}, state), {}, {
|
|
58
|
-
activeItemId: getNextActiveItemId(1, state.activeItemId, getItemsCount(state), action.props.defaultActiveItemId)
|
|
58
|
+
activeItemId: action.payload.hasOwnProperty('nextActiveItemId') ? action.payload.nextActiveItemId : getNextActiveItemId(1, state.activeItemId, getItemsCount(state), action.props.defaultActiveItemId)
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
return _objectSpread(_objectSpread({}, nextState), {}, {
|
|
@@ -82,12 +82,14 @@ export var stateReducer = function stateReducer(state, action) {
|
|
|
82
82
|
{
|
|
83
83
|
if (state.isOpen) {
|
|
84
84
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
85
|
+
activeItemId: null,
|
|
85
86
|
isOpen: false,
|
|
86
87
|
completion: null
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
92
|
+
activeItemId: null,
|
|
91
93
|
query: '',
|
|
92
94
|
status: 'idle',
|
|
93
95
|
collections: []
|
|
@@ -11,5 +11,5 @@ declare type Action<TItem extends BaseItem, TPayload> = {
|
|
|
11
11
|
props: InternalAutocompleteOptions<TItem>;
|
|
12
12
|
payload: TPayload;
|
|
13
13
|
};
|
|
14
|
-
declare type ActionType = 'setActiveItemId' | 'setQuery' | 'setCollections' | 'setIsOpen' | 'setStatus' | 'setContext' | 'ArrowUp' | 'ArrowDown' | 'Escape' | 'Enter' | 'submit' | 'reset' | 'focus' | 'blur' | 'mousemove' | 'mouseleave' | 'click';
|
|
14
|
+
export declare type ActionType = 'setActiveItemId' | 'setQuery' | 'setCollections' | 'setIsOpen' | 'setStatus' | 'setContext' | 'ArrowUp' | 'ArrowDown' | 'Escape' | 'Enter' | 'submit' | 'reset' | 'focus' | 'blur' | 'mousemove' | 'mouseleave' | 'click';
|
|
15
15
|
export {};
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
* @param defaultActiveItemId The default active index to fallback to
|
|
16
16
|
*/
|
|
17
17
|
export function getNextActiveItemId(moveAmount, baseIndex, itemCount, defaultActiveItemId) {
|
|
18
|
+
if (!itemCount) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
if (moveAmount < 0 && (baseIndex === null || defaultActiveItemId !== null && baseIndex === 0)) {
|
|
19
23
|
return itemCount + moveAmount;
|
|
20
24
|
}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.2.1";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '1.
|
|
1
|
+
export var version = '1.2.1';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @algolia/autocomplete-core 1.
|
|
1
|
+
/*! @algolia/autocomplete-core 1.2.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -239,6 +239,10 @@
|
|
|
239
239
|
* @param defaultActiveItemId The default active index to fallback to
|
|
240
240
|
*/
|
|
241
241
|
function getNextActiveItemId(moveAmount, baseIndex, itemCount, defaultActiveItemId) {
|
|
242
|
+
if (!itemCount) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
242
246
|
if (moveAmount < 0 && (baseIndex === null || defaultActiveItemId !== null && baseIndex === 0)) {
|
|
243
247
|
return itemCount + moveAmount;
|
|
244
248
|
}
|
|
@@ -472,7 +476,10 @@
|
|
|
472
476
|
function getDefaultProps(props, pluginSubscribers) {
|
|
473
477
|
var _props$id;
|
|
474
478
|
|
|
479
|
+
/* eslint-disable no-restricted-globals */
|
|
475
480
|
var environment = typeof window !== 'undefined' ? window : {};
|
|
481
|
+
/* eslint-enable no-restricted-globals */
|
|
482
|
+
|
|
476
483
|
var plugins = props.plugins || [];
|
|
477
484
|
return _objectSpread2(_objectSpread2({
|
|
478
485
|
debug: false,
|
|
@@ -584,7 +591,7 @@
|
|
|
584
591
|
}
|
|
585
592
|
|
|
586
593
|
function isRequesterDescription(description) {
|
|
587
|
-
return Boolean(description.execute);
|
|
594
|
+
return Boolean(description === null || description === void 0 ? void 0 : description.execute);
|
|
588
595
|
}
|
|
589
596
|
|
|
590
597
|
function preResolve(itemsOrDescription, sourceId) {
|
|
@@ -663,7 +670,8 @@
|
|
|
663
670
|
});
|
|
664
671
|
var transform = matches[0].transformResponse;
|
|
665
672
|
var items = transform ? transform(mapToAlgoliaResponse(results)) : results;
|
|
666
|
-
invariant(Array.isArray(items), "The `getItems` function must return an array of items but returned type ".concat(JSON.stringify(_typeof(items)), ":\n\n").concat(JSON.stringify(items, null, 2)));
|
|
673
|
+
invariant(Array.isArray(items), "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned type ").concat(JSON.stringify(_typeof(items)), ":\n\n").concat(JSON.stringify(items, null, 2), ".\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
|
|
674
|
+
invariant(items.every(Boolean), "The `getItems` function from source \"".concat(source.sourceId, "\" must return an array of items but returned ").concat(JSON.stringify(undefined), ".\n\nDid you forget to return items?\n\nSee: https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getitems"));
|
|
667
675
|
return {
|
|
668
676
|
source: source,
|
|
669
677
|
items: items
|
|
@@ -771,36 +779,66 @@
|
|
|
771
779
|
setters = _objectWithoutProperties(_ref, ["event", "props", "refresh", "store"]);
|
|
772
780
|
|
|
773
781
|
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
774
|
-
//
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
782
|
+
// eslint-disable-next-line no-inner-declarations
|
|
783
|
+
var triggerScrollIntoView = function triggerScrollIntoView() {
|
|
784
|
+
var nodeItem = props.environment.document.getElementById("".concat(props.id, "-item-").concat(store.getState().activeItemId));
|
|
785
|
+
|
|
786
|
+
if (nodeItem) {
|
|
787
|
+
if (nodeItem.scrollIntoViewIfNeeded) {
|
|
788
|
+
nodeItem.scrollIntoViewIfNeeded(false);
|
|
789
|
+
} else {
|
|
790
|
+
nodeItem.scrollIntoView(false);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}; // eslint-disable-next-line no-inner-declarations
|
|
779
794
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
795
|
+
|
|
796
|
+
var triggerOnActive = function triggerOnActive() {
|
|
797
|
+
var highlightedItem = getActiveItem(store.getState());
|
|
798
|
+
|
|
799
|
+
if (store.getState().activeItemId !== null && highlightedItem) {
|
|
800
|
+
var item = highlightedItem.item,
|
|
801
|
+
itemInputValue = highlightedItem.itemInputValue,
|
|
802
|
+
itemUrl = highlightedItem.itemUrl,
|
|
803
|
+
source = highlightedItem.source;
|
|
804
|
+
source.onActive(_objectSpread2({
|
|
805
|
+
event: event,
|
|
806
|
+
item: item,
|
|
807
|
+
itemInputValue: itemInputValue,
|
|
808
|
+
itemUrl: itemUrl,
|
|
809
|
+
refresh: refresh,
|
|
810
|
+
source: source,
|
|
811
|
+
state: store.getState()
|
|
812
|
+
}, setters));
|
|
785
813
|
}
|
|
786
|
-
}
|
|
814
|
+
}; // Default browser behavior changes the caret placement on ArrowUp and
|
|
815
|
+
// ArrowDown.
|
|
787
816
|
|
|
788
|
-
var highlightedItem = getActiveItem(store.getState());
|
|
789
817
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
source.onActive(_objectSpread2({
|
|
818
|
+
event.preventDefault(); // When re-opening the panel, we need to split the logic to keep the actions
|
|
819
|
+
// synchronized as `onInput` returns a promise.
|
|
820
|
+
|
|
821
|
+
if (store.getState().isOpen === false && (props.openOnFocus || Boolean(store.getState().query))) {
|
|
822
|
+
onInput(_objectSpread2({
|
|
796
823
|
event: event,
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
itemUrl: itemUrl,
|
|
824
|
+
props: props,
|
|
825
|
+
query: store.getState().query,
|
|
800
826
|
refresh: refresh,
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
827
|
+
store: store
|
|
828
|
+
}, setters)).then(function () {
|
|
829
|
+
store.dispatch(event.key, {
|
|
830
|
+
nextActiveItemId: props.defaultActiveItemId
|
|
831
|
+
});
|
|
832
|
+
triggerOnActive(); // Since we rely on the DOM, we need to wait for all the micro tasks to
|
|
833
|
+
// finish (which include re-opening the panel) to make sure all the
|
|
834
|
+
// elements are available.
|
|
835
|
+
|
|
836
|
+
setTimeout(triggerScrollIntoView, 0);
|
|
837
|
+
});
|
|
838
|
+
} else {
|
|
839
|
+
store.dispatch(event.key, {});
|
|
840
|
+
triggerOnActive();
|
|
841
|
+
triggerScrollIntoView();
|
|
804
842
|
}
|
|
805
843
|
} else if (event.key === 'Escape') {
|
|
806
844
|
// This prevents the default browser behavior on `input[type="search"]`
|
|
@@ -822,62 +860,59 @@
|
|
|
822
860
|
event.preventDefault();
|
|
823
861
|
|
|
824
862
|
var _ref2 = getActiveItem(store.getState()),
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
863
|
+
item = _ref2.item,
|
|
864
|
+
itemInputValue = _ref2.itemInputValue,
|
|
865
|
+
itemUrl = _ref2.itemUrl,
|
|
866
|
+
source = _ref2.source;
|
|
829
867
|
|
|
830
868
|
if (event.metaKey || event.ctrlKey) {
|
|
831
|
-
if (
|
|
832
|
-
|
|
869
|
+
if (itemUrl !== undefined) {
|
|
870
|
+
source.onSelect(_objectSpread2({
|
|
833
871
|
event: event,
|
|
834
|
-
item:
|
|
835
|
-
itemInputValue:
|
|
836
|
-
itemUrl:
|
|
872
|
+
item: item,
|
|
873
|
+
itemInputValue: itemInputValue,
|
|
874
|
+
itemUrl: itemUrl,
|
|
837
875
|
refresh: refresh,
|
|
838
|
-
source:
|
|
876
|
+
source: source,
|
|
839
877
|
state: store.getState()
|
|
840
878
|
}, setters));
|
|
841
|
-
|
|
842
879
|
props.navigator.navigateNewTab({
|
|
843
|
-
itemUrl:
|
|
844
|
-
item:
|
|
880
|
+
itemUrl: itemUrl,
|
|
881
|
+
item: item,
|
|
845
882
|
state: store.getState()
|
|
846
883
|
});
|
|
847
884
|
}
|
|
848
885
|
} else if (event.shiftKey) {
|
|
849
|
-
if (
|
|
850
|
-
|
|
886
|
+
if (itemUrl !== undefined) {
|
|
887
|
+
source.onSelect(_objectSpread2({
|
|
851
888
|
event: event,
|
|
852
|
-
item:
|
|
853
|
-
itemInputValue:
|
|
854
|
-
itemUrl:
|
|
889
|
+
item: item,
|
|
890
|
+
itemInputValue: itemInputValue,
|
|
891
|
+
itemUrl: itemUrl,
|
|
855
892
|
refresh: refresh,
|
|
856
|
-
source:
|
|
893
|
+
source: source,
|
|
857
894
|
state: store.getState()
|
|
858
895
|
}, setters));
|
|
859
|
-
|
|
860
896
|
props.navigator.navigateNewWindow({
|
|
861
|
-
itemUrl:
|
|
862
|
-
item:
|
|
897
|
+
itemUrl: itemUrl,
|
|
898
|
+
item: item,
|
|
863
899
|
state: store.getState()
|
|
864
900
|
});
|
|
865
901
|
}
|
|
866
902
|
} else if (event.altKey) ; else {
|
|
867
|
-
if (
|
|
868
|
-
|
|
903
|
+
if (itemUrl !== undefined) {
|
|
904
|
+
source.onSelect(_objectSpread2({
|
|
869
905
|
event: event,
|
|
870
|
-
item:
|
|
871
|
-
itemInputValue:
|
|
872
|
-
itemUrl:
|
|
906
|
+
item: item,
|
|
907
|
+
itemInputValue: itemInputValue,
|
|
908
|
+
itemUrl: itemUrl,
|
|
873
909
|
refresh: refresh,
|
|
874
|
-
source:
|
|
910
|
+
source: source,
|
|
875
911
|
state: store.getState()
|
|
876
912
|
}, setters));
|
|
877
|
-
|
|
878
913
|
props.navigator.navigate({
|
|
879
|
-
itemUrl:
|
|
880
|
-
item:
|
|
914
|
+
itemUrl: itemUrl,
|
|
915
|
+
item: item,
|
|
881
916
|
state: store.getState()
|
|
882
917
|
});
|
|
883
918
|
return;
|
|
@@ -889,17 +924,17 @@
|
|
|
889
924
|
isOpen: false
|
|
890
925
|
},
|
|
891
926
|
props: props,
|
|
892
|
-
query:
|
|
927
|
+
query: itemInputValue,
|
|
893
928
|
refresh: refresh,
|
|
894
929
|
store: store
|
|
895
930
|
}, setters)).then(function () {
|
|
896
|
-
|
|
931
|
+
source.onSelect(_objectSpread2({
|
|
897
932
|
event: event,
|
|
898
|
-
item:
|
|
899
|
-
itemInputValue:
|
|
900
|
-
itemUrl:
|
|
933
|
+
item: item,
|
|
934
|
+
itemInputValue: itemInputValue,
|
|
935
|
+
itemUrl: itemUrl,
|
|
901
936
|
refresh: refresh,
|
|
902
|
-
source:
|
|
937
|
+
source: source,
|
|
903
938
|
state: store.getState()
|
|
904
939
|
}, setters));
|
|
905
940
|
});
|
|
@@ -1201,16 +1236,15 @@
|
|
|
1201
1236
|
}
|
|
1202
1237
|
|
|
1203
1238
|
function getCompletion(_ref) {
|
|
1239
|
+
var _getActiveItem;
|
|
1240
|
+
|
|
1204
1241
|
var state = _ref.state;
|
|
1205
1242
|
|
|
1206
1243
|
if (state.isOpen === false || state.activeItemId === null) {
|
|
1207
1244
|
return null;
|
|
1208
1245
|
}
|
|
1209
1246
|
|
|
1210
|
-
|
|
1211
|
-
itemInputValue = _ref2.itemInputValue;
|
|
1212
|
-
|
|
1213
|
-
return itemInputValue || null;
|
|
1247
|
+
return ((_getActiveItem = getActiveItem(state)) === null || _getActiveItem === void 0 ? void 0 : _getActiveItem.itemInputValue) || null;
|
|
1214
1248
|
}
|
|
1215
1249
|
|
|
1216
1250
|
var stateReducer = function stateReducer(state, action) {
|
|
@@ -1261,7 +1295,7 @@
|
|
|
1261
1295
|
case 'ArrowDown':
|
|
1262
1296
|
{
|
|
1263
1297
|
var nextState = _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1264
|
-
activeItemId: getNextActiveItemId(1, state.activeItemId, getItemsCount(state), action.props.defaultActiveItemId)
|
|
1298
|
+
activeItemId: action.payload.hasOwnProperty('nextActiveItemId') ? action.payload.nextActiveItemId : getNextActiveItemId(1, state.activeItemId, getItemsCount(state), action.props.defaultActiveItemId)
|
|
1265
1299
|
});
|
|
1266
1300
|
|
|
1267
1301
|
return _objectSpread2(_objectSpread2({}, nextState), {}, {
|
|
@@ -1288,12 +1322,14 @@
|
|
|
1288
1322
|
{
|
|
1289
1323
|
if (state.isOpen) {
|
|
1290
1324
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1325
|
+
activeItemId: null,
|
|
1291
1326
|
isOpen: false,
|
|
1292
1327
|
completion: null
|
|
1293
1328
|
});
|
|
1294
1329
|
}
|
|
1295
1330
|
|
|
1296
1331
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1332
|
+
activeItemId: null,
|
|
1297
1333
|
query: '',
|
|
1298
1334
|
status: 'idle',
|
|
1299
1335
|
collections: []
|
|
@@ -1423,7 +1459,7 @@
|
|
|
1423
1459
|
}, propGetters), setters);
|
|
1424
1460
|
}
|
|
1425
1461
|
|
|
1426
|
-
var version = '1.
|
|
1462
|
+
var version = '1.2.1';
|
|
1427
1463
|
|
|
1428
1464
|
exports.createAutocomplete = createAutocomplete;
|
|
1429
1465
|
exports.getDefaultProps = getDefaultProps;
|