@algolia/autocomplete-core 1.11.0 → 1.11.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.
@@ -3,9 +3,8 @@ var _excluded = ["props", "refresh", "store"],
3
3
  _excluded2 = ["inputElement", "formElement", "panelElement"],
4
4
  _excluded3 = ["inputElement"],
5
5
  _excluded4 = ["inputElement", "maxLength"],
6
- _excluded5 = ["sourceIndex"],
7
- _excluded6 = ["sourceIndex"],
8
- _excluded7 = ["item", "source", "sourceIndex"];
6
+ _excluded5 = ["source"],
7
+ _excluded6 = ["item", "source"];
9
8
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
9
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
10
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -16,7 +15,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
16
15
  import { noop } from '@algolia/autocomplete-shared';
17
16
  import { onInput } from './onInput';
18
17
  import { onKeyDown as _onKeyDown } from './onKeyDown';
19
- import { getActiveItem, isOrContainsNode, isSamsung } from './utils';
18
+ import { getActiveItem, getAutocompleteElementId, isOrContainsNode, isSamsung } from './utils';
20
19
  export function getPropGetters(_ref) {
21
20
  var props = _ref.props,
22
21
  refresh = _ref.refresh,
@@ -85,8 +84,11 @@ export function getPropGetters(_ref) {
85
84
  role: 'combobox',
86
85
  'aria-expanded': store.getState().isOpen,
87
86
  'aria-haspopup': 'listbox',
88
- 'aria-owns': store.getState().isOpen ? "".concat(props.id, "-list") : undefined,
89
- 'aria-labelledby': "".concat(props.id, "-label")
87
+ 'aria-owns': store.getState().isOpen ? store.getState().collections.map(function (_ref2) {
88
+ var source = _ref2.source;
89
+ return getAutocompleteElementId(props.id, 'list', source);
90
+ }).join(' ') : undefined,
91
+ 'aria-labelledby': getAutocompleteElementId(props.id, 'label')
90
92
  }, rest);
91
93
  };
92
94
  var getFormProps = function getFormProps(providedProps) {
@@ -136,22 +138,25 @@ export function getPropGetters(_ref) {
136
138
  }
137
139
  store.dispatch('focus', null);
138
140
  }
139
- var _ref2 = providedProps || {},
140
- inputElement = _ref2.inputElement,
141
- _ref2$maxLength = _ref2.maxLength,
142
- maxLength = _ref2$maxLength === void 0 ? 512 : _ref2$maxLength,
143
- rest = _objectWithoutProperties(_ref2, _excluded4);
141
+ var _ref3 = providedProps || {},
142
+ inputElement = _ref3.inputElement,
143
+ _ref3$maxLength = _ref3.maxLength,
144
+ maxLength = _ref3$maxLength === void 0 ? 512 : _ref3$maxLength,
145
+ rest = _objectWithoutProperties(_ref3, _excluded4);
144
146
  var activeItem = getActiveItem(store.getState());
145
147
  var userAgent = ((_props$environment$na = props.environment.navigator) === null || _props$environment$na === void 0 ? void 0 : _props$environment$na.userAgent) || '';
146
148
  var shouldFallbackKeyHint = isSamsung(userAgent);
147
149
  var enterKeyHint = props.enterKeyHint || (activeItem !== null && activeItem !== void 0 && activeItem.itemUrl && !shouldFallbackKeyHint ? 'go' : 'search');
148
150
  return _objectSpread({
149
151
  'aria-autocomplete': 'both',
150
- 'aria-activedescendant': store.getState().isOpen && store.getState().activeItemId !== null ? "".concat(props.id, "-item-").concat(store.getState().activeItemId) : undefined,
151
- 'aria-controls': store.getState().isOpen ? "".concat(props.id, "-list") : undefined,
152
- 'aria-labelledby': "".concat(props.id, "-label"),
152
+ 'aria-activedescendant': store.getState().isOpen && store.getState().activeItemId !== null ? getAutocompleteElementId(props.id, "item-".concat(store.getState().activeItemId), activeItem === null || activeItem === void 0 ? void 0 : activeItem.source) : undefined,
153
+ 'aria-controls': store.getState().isOpen ? store.getState().collections.map(function (_ref4) {
154
+ var source = _ref4.source;
155
+ return getAutocompleteElementId(props.id, 'list', source);
156
+ }).join(' ') : undefined,
157
+ 'aria-labelledby': getAutocompleteElementId(props.id, 'label'),
153
158
  value: store.getState().completion || store.getState().query,
154
- id: "".concat(props.id, "-input"),
159
+ id: getAutocompleteElementId(props.id, 'input'),
155
160
  autoComplete: 'off',
156
161
  autoCorrect: 'off',
157
162
  autoCapitalize: 'off',
@@ -197,26 +202,20 @@ export function getPropGetters(_ref) {
197
202
  }
198
203
  }, rest);
199
204
  };
200
- var getAutocompleteId = function getAutocompleteId(instanceId, sourceId) {
201
- return typeof sourceId !== 'undefined' ? "".concat(instanceId, "-").concat(sourceId) : instanceId;
202
- };
203
- var getLabelProps = function getLabelProps(providedProps) {
204
- var _ref3 = providedProps || {},
205
- sourceIndex = _ref3.sourceIndex,
206
- rest = _objectWithoutProperties(_ref3, _excluded5);
205
+ var getLabelProps = function getLabelProps(rest) {
207
206
  return _objectSpread({
208
- htmlFor: "".concat(getAutocompleteId(props.id, sourceIndex), "-input"),
209
- id: "".concat(getAutocompleteId(props.id, sourceIndex), "-label")
207
+ htmlFor: getAutocompleteElementId(props.id, 'input'),
208
+ id: getAutocompleteElementId(props.id, 'label')
210
209
  }, rest);
211
210
  };
212
211
  var getListProps = function getListProps(providedProps) {
213
- var _ref4 = providedProps || {},
214
- sourceIndex = _ref4.sourceIndex,
215
- rest = _objectWithoutProperties(_ref4, _excluded6);
212
+ var _ref5 = providedProps || {},
213
+ source = _ref5.source,
214
+ rest = _objectWithoutProperties(_ref5, _excluded5);
216
215
  return _objectSpread({
217
216
  role: 'listbox',
218
- 'aria-labelledby': "".concat(getAutocompleteId(props.id, sourceIndex), "-label"),
219
- id: "".concat(getAutocompleteId(props.id, sourceIndex), "-list")
217
+ 'aria-labelledby': getAutocompleteElementId(props.id, 'label'),
218
+ id: getAutocompleteElementId(props.id, 'list', source)
220
219
  }, rest);
221
220
  };
222
221
  var getPanelProps = function getPanelProps(rest) {
@@ -235,10 +234,9 @@ export function getPropGetters(_ref) {
235
234
  var getItemProps = function getItemProps(providedProps) {
236
235
  var item = providedProps.item,
237
236
  source = providedProps.source,
238
- sourceIndex = providedProps.sourceIndex,
239
- rest = _objectWithoutProperties(providedProps, _excluded7);
237
+ rest = _objectWithoutProperties(providedProps, _excluded6);
240
238
  return _objectSpread({
241
- id: "".concat(getAutocompleteId(props.id, sourceIndex), "-item-").concat(item.__autocomplete_id),
239
+ id: getAutocompleteElementId(props.id, "item-".concat(item.__autocomplete_id), source),
242
240
  role: 'option',
243
241
  'aria-selected': store.getState().activeItemId === item.__autocomplete_id,
244
242
  onMouseMove: function onMouseMove(event) {
@@ -8,7 +8,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import { onInput } from './onInput';
11
- import { getActiveItem } from './utils';
11
+ import { getActiveItem, getAutocompleteElementId } from './utils';
12
12
  export function onKeyDown(_ref) {
13
13
  var event = _ref.event,
14
14
  props = _ref.props,
@@ -18,7 +18,8 @@ export function onKeyDown(_ref) {
18
18
  if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
19
19
  // eslint-disable-next-line no-inner-declarations
20
20
  var triggerScrollIntoView = function triggerScrollIntoView() {
21
- var nodeItem = props.environment.document.getElementById("".concat(props.id, "-item-").concat(store.getState().activeItemId));
21
+ var highlightedItem = getActiveItem(store.getState());
22
+ var nodeItem = props.environment.document.getElementById(getAutocompleteElementId(props.id, "item-".concat(store.getState().activeItemId), highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.source));
22
23
  if (nodeItem) {
23
24
  if (nodeItem.scrollIntoViewIfNeeded) {
24
25
  nodeItem.scrollIntoViewIfNeeded(false);
@@ -0,0 +1,9 @@
1
+ import type { InternalAutocompleteSource } from '../types';
2
+ /**
3
+ * Returns a full element id for an autocomplete element.
4
+ *
5
+ * @param autocompleteInstanceId The id of the autocomplete instance
6
+ * @param elementId The specific element id
7
+ * @param source The source of the element, when it needs to be scoped
8
+ */
9
+ export declare function getAutocompleteElementId(autocompleteInstanceId: string, elementId: string, source?: InternalAutocompleteSource<any>): string;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a full element id for an autocomplete element.
3
+ *
4
+ * @param autocompleteInstanceId The id of the autocomplete instance
5
+ * @param elementId The specific element id
6
+ * @param source The source of the element, when it needs to be scoped
7
+ */
8
+ export function getAutocompleteElementId(autocompleteInstanceId, elementId, source) {
9
+ return [autocompleteInstanceId, source === null || source === void 0 ? void 0 : source.sourceId, elementId].filter(Boolean).join('-').replace(/\s/g, '');
10
+ }
@@ -4,6 +4,7 @@ export * from './createConcurrentSafePromise';
4
4
  export * from './getNextActiveItemId';
5
5
  export * from './getNormalizedSources';
6
6
  export * from './getActiveItem';
7
+ export * from './getAutocompleteElementId';
7
8
  export * from './isOrContainsNode';
8
9
  export * from './isSamsung';
9
10
  export * from './mapToAlgoliaResponse';
@@ -4,6 +4,7 @@ export * from './createConcurrentSafePromise';
4
4
  export * from './getNextActiveItemId';
5
5
  export * from './getNormalizedSources';
6
6
  export * from './getActiveItem';
7
+ export * from './getAutocompleteElementId';
7
8
  export * from './isOrContainsNode';
8
9
  export * from './isSamsung';
9
10
  export * from './mapToAlgoliaResponse';
@@ -1,4 +1,4 @@
1
- /*! @algolia/autocomplete-core 1.11.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
1
+ /*! @algolia/autocomplete-core 1.11.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) :
@@ -291,7 +291,7 @@
291
291
  return undefined;
292
292
  }
293
293
 
294
- var version = '1.11.0';
294
+ var version = '1.11.1';
295
295
 
296
296
  var userAgents = [{
297
297
  segment: 'autocomplete-core',
@@ -1256,6 +1256,17 @@
1256
1256
  };
1257
1257
  }
1258
1258
 
1259
+ /**
1260
+ * Returns a full element id for an autocomplete element.
1261
+ *
1262
+ * @param autocompleteInstanceId The id of the autocomplete instance
1263
+ * @param elementId The specific element id
1264
+ * @param source The source of the element, when it needs to be scoped
1265
+ */
1266
+ function getAutocompleteElementId(autocompleteInstanceId, elementId, source) {
1267
+ return [autocompleteInstanceId, source === null || source === void 0 ? void 0 : source.sourceId, elementId].filter(Boolean).join('-').replace(/\s/g, '');
1268
+ }
1269
+
1259
1270
  function isOrContainsNode(parent, child) {
1260
1271
  return parent === child || parent.contains(child);
1261
1272
  }
@@ -1734,7 +1745,8 @@
1734
1745
  if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
1735
1746
  // eslint-disable-next-line no-inner-declarations
1736
1747
  var triggerScrollIntoView = function triggerScrollIntoView() {
1737
- var nodeItem = props.environment.document.getElementById("".concat(props.id, "-item-").concat(store.getState().activeItemId));
1748
+ var highlightedItem = getActiveItem(store.getState());
1749
+ var nodeItem = props.environment.document.getElementById(getAutocompleteElementId(props.id, "item-".concat(store.getState().activeItemId), highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.source));
1738
1750
  if (nodeItem) {
1739
1751
  if (nodeItem.scrollIntoViewIfNeeded) {
1740
1752
  nodeItem.scrollIntoViewIfNeeded(false);
@@ -1912,9 +1924,8 @@
1912
1924
  _excluded2 = ["inputElement", "formElement", "panelElement"],
1913
1925
  _excluded3 = ["inputElement"],
1914
1926
  _excluded4 = ["inputElement", "maxLength"],
1915
- _excluded5 = ["sourceIndex"],
1916
- _excluded6 = ["sourceIndex"],
1917
- _excluded7 = ["item", "source", "sourceIndex"];
1927
+ _excluded5 = ["source"],
1928
+ _excluded6 = ["item", "source"];
1918
1929
  function getPropGetters(_ref) {
1919
1930
  var props = _ref.props,
1920
1931
  refresh = _ref.refresh,
@@ -1983,8 +1994,11 @@
1983
1994
  role: 'combobox',
1984
1995
  'aria-expanded': store.getState().isOpen,
1985
1996
  'aria-haspopup': 'listbox',
1986
- 'aria-owns': store.getState().isOpen ? "".concat(props.id, "-list") : undefined,
1987
- 'aria-labelledby': "".concat(props.id, "-label")
1997
+ 'aria-owns': store.getState().isOpen ? store.getState().collections.map(function (_ref2) {
1998
+ var source = _ref2.source;
1999
+ return getAutocompleteElementId(props.id, 'list', source);
2000
+ }).join(' ') : undefined,
2001
+ 'aria-labelledby': getAutocompleteElementId(props.id, 'label')
1988
2002
  }, rest);
1989
2003
  };
1990
2004
  var getFormProps = function getFormProps(providedProps) {
@@ -2034,22 +2048,25 @@
2034
2048
  }
2035
2049
  store.dispatch('focus', null);
2036
2050
  }
2037
- var _ref2 = providedProps || {};
2038
- _ref2.inputElement;
2039
- var _ref2$maxLength = _ref2.maxLength,
2040
- maxLength = _ref2$maxLength === void 0 ? 512 : _ref2$maxLength,
2041
- rest = _objectWithoutProperties$1(_ref2, _excluded4);
2051
+ var _ref3 = providedProps || {};
2052
+ _ref3.inputElement;
2053
+ var _ref3$maxLength = _ref3.maxLength,
2054
+ maxLength = _ref3$maxLength === void 0 ? 512 : _ref3$maxLength,
2055
+ rest = _objectWithoutProperties$1(_ref3, _excluded4);
2042
2056
  var activeItem = getActiveItem(store.getState());
2043
2057
  var userAgent = ((_props$environment$na = props.environment.navigator) === null || _props$environment$na === void 0 ? void 0 : _props$environment$na.userAgent) || '';
2044
2058
  var shouldFallbackKeyHint = isSamsung(userAgent);
2045
2059
  var enterKeyHint = props.enterKeyHint || (activeItem !== null && activeItem !== void 0 && activeItem.itemUrl && !shouldFallbackKeyHint ? 'go' : 'search');
2046
2060
  return _objectSpread2({
2047
2061
  'aria-autocomplete': 'both',
2048
- 'aria-activedescendant': store.getState().isOpen && store.getState().activeItemId !== null ? "".concat(props.id, "-item-").concat(store.getState().activeItemId) : undefined,
2049
- 'aria-controls': store.getState().isOpen ? "".concat(props.id, "-list") : undefined,
2050
- 'aria-labelledby': "".concat(props.id, "-label"),
2062
+ 'aria-activedescendant': store.getState().isOpen && store.getState().activeItemId !== null ? getAutocompleteElementId(props.id, "item-".concat(store.getState().activeItemId), activeItem === null || activeItem === void 0 ? void 0 : activeItem.source) : undefined,
2063
+ 'aria-controls': store.getState().isOpen ? store.getState().collections.map(function (_ref4) {
2064
+ var source = _ref4.source;
2065
+ return getAutocompleteElementId(props.id, 'list', source);
2066
+ }).join(' ') : undefined,
2067
+ 'aria-labelledby': getAutocompleteElementId(props.id, 'label'),
2051
2068
  value: store.getState().completion || store.getState().query,
2052
- id: "".concat(props.id, "-input"),
2069
+ id: getAutocompleteElementId(props.id, 'input'),
2053
2070
  autoComplete: 'off',
2054
2071
  autoCorrect: 'off',
2055
2072
  autoCapitalize: 'off',
@@ -2095,26 +2112,20 @@
2095
2112
  }
2096
2113
  }, rest);
2097
2114
  };
2098
- var getAutocompleteId = function getAutocompleteId(instanceId, sourceId) {
2099
- return typeof sourceId !== 'undefined' ? "".concat(instanceId, "-").concat(sourceId) : instanceId;
2100
- };
2101
- var getLabelProps = function getLabelProps(providedProps) {
2102
- var _ref3 = providedProps || {},
2103
- sourceIndex = _ref3.sourceIndex,
2104
- rest = _objectWithoutProperties$1(_ref3, _excluded5);
2115
+ var getLabelProps = function getLabelProps(rest) {
2105
2116
  return _objectSpread2({
2106
- htmlFor: "".concat(getAutocompleteId(props.id, sourceIndex), "-input"),
2107
- id: "".concat(getAutocompleteId(props.id, sourceIndex), "-label")
2117
+ htmlFor: getAutocompleteElementId(props.id, 'input'),
2118
+ id: getAutocompleteElementId(props.id, 'label')
2108
2119
  }, rest);
2109
2120
  };
2110
2121
  var getListProps = function getListProps(providedProps) {
2111
- var _ref4 = providedProps || {},
2112
- sourceIndex = _ref4.sourceIndex,
2113
- rest = _objectWithoutProperties$1(_ref4, _excluded6);
2122
+ var _ref5 = providedProps || {},
2123
+ source = _ref5.source,
2124
+ rest = _objectWithoutProperties$1(_ref5, _excluded5);
2114
2125
  return _objectSpread2({
2115
2126
  role: 'listbox',
2116
- 'aria-labelledby': "".concat(getAutocompleteId(props.id, sourceIndex), "-label"),
2117
- id: "".concat(getAutocompleteId(props.id, sourceIndex), "-list")
2127
+ 'aria-labelledby': getAutocompleteElementId(props.id, 'label'),
2128
+ id: getAutocompleteElementId(props.id, 'list', source)
2118
2129
  }, rest);
2119
2130
  };
2120
2131
  var getPanelProps = function getPanelProps(rest) {
@@ -2133,10 +2144,9 @@
2133
2144
  var getItemProps = function getItemProps(providedProps) {
2134
2145
  var item = providedProps.item,
2135
2146
  source = providedProps.source,
2136
- sourceIndex = providedProps.sourceIndex,
2137
- rest = _objectWithoutProperties$1(providedProps, _excluded7);
2147
+ rest = _objectWithoutProperties$1(providedProps, _excluded6);
2138
2148
  return _objectSpread2({
2139
- id: "".concat(getAutocompleteId(props.id, sourceIndex), "-item-").concat(item.__autocomplete_id),
2149
+ id: getAutocompleteElementId(props.id, "item-".concat(item.__autocomplete_id), source),
2140
2150
  role: 'option',
2141
2151
  'aria-selected': store.getState().activeItemId === item.__autocomplete_id,
2142
2152
  onMouseMove: function onMouseMove(event) {