@algolia/autocomplete-core 1.5.4 → 1.5.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.
@@ -16,7 +16,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
16
16
 
17
17
  import { onInput } from './onInput';
18
18
  import { onKeyDown as _onKeyDown } from './onKeyDown';
19
- import { getActiveItem, isOrContainsNode } from './utils';
19
+ import { getActiveItem, isChrome, isOrContainsNode, isSamsung } from './utils';
20
20
  export function getPropGetters(_ref) {
21
21
  var props = _ref.props,
22
22
  refresh = _ref.refresh,
@@ -125,6 +125,8 @@ export function getPropGetters(_ref) {
125
125
  };
126
126
 
127
127
  var getInputProps = function getInputProps(providedProps) {
128
+ var _props$environment$na;
129
+
128
130
  function onFocus(event) {
129
131
  // We want to trigger a query when `openOnFocus` is true
130
132
  // because the panel should open with the current query.
@@ -150,6 +152,9 @@ export function getPropGetters(_ref) {
150
152
  rest = _objectWithoutProperties(_ref2, _excluded4);
151
153
 
152
154
  var activeItem = getActiveItem(store.getState());
155
+ var userAgent = (_props$environment$na = props.environment.navigator) === null || _props$environment$na === void 0 ? void 0 : _props$environment$na.userAgent;
156
+ var shouldFallbackKeyHint = isSamsung(userAgent) && isChrome(userAgent);
157
+ var enterKeyHint = activeItem !== null && activeItem !== void 0 && activeItem.itemUrl && !shouldFallbackKeyHint ? 'go' : 'search';
153
158
  return _objectSpread({
154
159
  'aria-autocomplete': 'both',
155
160
  'aria-activedescendant': store.getState().isOpen && store.getState().activeItemId !== null ? "".concat(props.id, "-item-").concat(store.getState().activeItemId) : undefined,
@@ -160,7 +165,7 @@ export function getPropGetters(_ref) {
160
165
  autoComplete: 'off',
161
166
  autoCorrect: 'off',
162
167
  autoCapitalize: 'off',
163
- enterKeyHint: activeItem !== null && activeItem !== void 0 && activeItem.itemUrl ? 'go' : 'search',
168
+ enterKeyHint: enterKeyHint,
164
169
  spellCheck: 'false',
165
170
  autoFocus: props.autoFocus,
166
171
  placeholder: props.placeholder,
@@ -3,6 +3,8 @@ export * from './createCancelablePromiseList';
3
3
  export * from './createConcurrentSafePromise';
4
4
  export * from './getNextActiveItemId';
5
5
  export * from './getNormalizedSources';
6
+ export * from './isChrome';
6
7
  export * from './getActiveItem';
7
8
  export * from './isOrContainsNode';
9
+ export * from './isSamsung';
8
10
  export * from './mapToAlgoliaResponse';
@@ -3,6 +3,8 @@ export * from './createCancelablePromiseList';
3
3
  export * from './createConcurrentSafePromise';
4
4
  export * from './getNextActiveItemId';
5
5
  export * from './getNormalizedSources';
6
+ export * from './isChrome';
6
7
  export * from './getActiveItem';
7
8
  export * from './isOrContainsNode';
9
+ export * from './isSamsung';
8
10
  export * from './mapToAlgoliaResponse';
@@ -0,0 +1 @@
1
+ export declare function isChrome(userAgent: string): boolean;
@@ -0,0 +1,7 @@
1
+ var chromeRegex = /(crmo|crios|chrome)/i;
2
+ var edgeRegex = /edg(e|ios|a)?/i;
3
+ var samsungBrowserRegex = /samsungbrowser/i;
4
+ var chromiumRegex = /chromium/i;
5
+ export function isChrome(userAgent) {
6
+ return Boolean(userAgent && userAgent.match(chromeRegex) && !userAgent.match(edgeRegex) && !userAgent.match(samsungBrowserRegex) && !userAgent.match(chromiumRegex));
7
+ }
@@ -0,0 +1 @@
1
+ export declare function isSamsung(userAgent: string): boolean;
@@ -0,0 +1,4 @@
1
+ var regex = /((gt|sm)-|galaxy nexus)|samsung[- ]/i;
2
+ export function isSamsung(userAgent) {
3
+ return Boolean(userAgent && userAgent.match(regex));
4
+ }
@@ -1,4 +1,4 @@
1
- /*! @algolia/autocomplete-core 1.5.4 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
1
+ /*! @algolia/autocomplete-core 1.5.5 | 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) :
@@ -264,7 +264,7 @@
264
264
 
265
265
  var noop = function noop() {};
266
266
 
267
- var version = '1.5.4';
267
+ var version = '1.5.5';
268
268
 
269
269
  var userAgents = [{
270
270
  segment: 'autocomplete-core',
@@ -487,6 +487,14 @@
487
487
  });
488
488
  }
489
489
 
490
+ var chromeRegex = /(crmo|crios|chrome)/i;
491
+ var edgeRegex = /edg(e|ios|a)?/i;
492
+ var samsungBrowserRegex = /samsungbrowser/i;
493
+ var chromiumRegex = /chromium/i;
494
+ function isChrome(userAgent) {
495
+ return Boolean(userAgent && userAgent.match(chromeRegex) && !userAgent.match(edgeRegex) && !userAgent.match(samsungBrowserRegex) && !userAgent.match(chromiumRegex));
496
+ }
497
+
490
498
  // We don't have access to the autocomplete source when we call `onKeyDown`
491
499
  // or `onClick` because those are native browser events.
492
500
  // However, we can get the source from the suggestion index.
@@ -577,6 +585,11 @@
577
585
  return parent === child || parent.contains(child);
578
586
  }
579
587
 
588
+ var regex = /((gt|sm)-|galaxy nexus)|samsung[- ]/i;
589
+ function isSamsung(userAgent) {
590
+ return Boolean(userAgent && userAgent.match(regex));
591
+ }
592
+
580
593
  function mapToAlgoliaResponse(rawResults) {
581
594
  var results = rawResults.map(function (result) {
582
595
  var _hits;
@@ -1340,6 +1353,8 @@
1340
1353
  };
1341
1354
 
1342
1355
  var getInputProps = function getInputProps(providedProps) {
1356
+ var _props$environment$na;
1357
+
1343
1358
  function onFocus(event) {
1344
1359
  // We want to trigger a query when `openOnFocus` is true
1345
1360
  // because the panel should open with the current query.
@@ -1365,6 +1380,9 @@
1365
1380
  rest = _objectWithoutProperties(_ref2, _excluded4);
1366
1381
 
1367
1382
  var activeItem = getActiveItem(store.getState());
1383
+ var userAgent = (_props$environment$na = props.environment.navigator) === null || _props$environment$na === void 0 ? void 0 : _props$environment$na.userAgent;
1384
+ var shouldFallbackKeyHint = isSamsung(userAgent) && isChrome(userAgent);
1385
+ var enterKeyHint = activeItem !== null && activeItem !== void 0 && activeItem.itemUrl && !shouldFallbackKeyHint ? 'go' : 'search';
1368
1386
  return _objectSpread2({
1369
1387
  'aria-autocomplete': 'both',
1370
1388
  'aria-activedescendant': store.getState().isOpen && store.getState().activeItemId !== null ? "".concat(props.id, "-item-").concat(store.getState().activeItemId) : undefined,
@@ -1375,7 +1393,7 @@
1375
1393
  autoComplete: 'off',
1376
1394
  autoCorrect: 'off',
1377
1395
  autoCapitalize: 'off',
1378
- enterKeyHint: activeItem !== null && activeItem !== void 0 && activeItem.itemUrl ? 'go' : 'search',
1396
+ enterKeyHint: enterKeyHint,
1379
1397
  spellCheck: 'false',
1380
1398
  autoFocus: props.autoFocus,
1381
1399
  placeholder: props.placeholder,