react-instantsearch 7.16.3 → 7.17.0
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/cjs/components/Autocomplete.js +114 -0
- package/dist/cjs/components/Carousel.js +19 -1
- package/dist/cjs/components/useAutocomplete.js +237 -0
- package/dist/cjs/index.umd.js +38 -0
- package/dist/cjs/lib/useStickToBottom.js +20 -0
- package/dist/cjs/ui/SearchBox.js +5 -4
- package/dist/cjs/widgets/Chat.js +258 -0
- package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +120 -0
- package/dist/cjs/widgets/index.js +22 -11
- package/dist/cjs/widgets/index.umd.js +282 -0
- package/dist/es/components/Autocomplete.d.ts +20 -0
- package/dist/es/components/Autocomplete.js +106 -0
- package/dist/es/components/Carousel.d.ts +1 -1
- package/dist/es/components/Carousel.js +20 -2
- package/dist/es/components/useAutocomplete.d.ts +35 -0
- package/dist/es/components/useAutocomplete.js +231 -0
- package/dist/es/index.umd.d.ts +3 -0
- package/dist/es/index.umd.js +3 -0
- package/dist/es/lib/useStickToBottom.d.ts +1 -0
- package/dist/es/lib/useStickToBottom.js +14 -0
- package/dist/es/ui/SearchBox.d.ts +2 -1
- package/dist/es/ui/SearchBox.js +5 -4
- package/dist/es/widgets/Chat.d.ts +45 -0
- package/dist/es/widgets/Chat.js +238 -0
- package/dist/es/widgets/chat/tools/SearchIndexTool.d.ts +5 -0
- package/dist/es/widgets/chat/tools/SearchIndexTool.js +113 -0
- package/dist/es/widgets/index.d.ts +2 -1
- package/dist/es/widgets/index.js +3 -2
- package/dist/es/widgets/index.umd.d.ts +26 -0
- package/dist/es/widgets/index.umd.js +28 -0
- package/dist/umd/ReactInstantSearch.js +216 -162
- package/dist/umd/ReactInstantSearch.js.map +1 -1
- package/dist/umd/ReactInstantSearch.min.js +1 -1
- package/dist/umd/ReactInstantSearch.min.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.EXPERIMENTAL_Autocomplete = EXPERIMENTAL_Autocomplete;
|
|
8
|
+
var _instantsearchUiComponents = require("instantsearch-ui-components");
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
11
|
+
var _SearchBox = require("../widgets/SearchBox");
|
|
12
|
+
var _useAutocomplete2 = require("./useAutocomplete");
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
21
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
22
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
24
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
25
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
27
|
+
var Autocomplete = (0, _instantsearchUiComponents.createAutocompleteComponent)({
|
|
28
|
+
createElement: _react.createElement,
|
|
29
|
+
Fragment: _react.Fragment
|
|
30
|
+
});
|
|
31
|
+
var AutocompletePanel = (0, _instantsearchUiComponents.createAutocompletePanelComponent)({
|
|
32
|
+
createElement: _react.createElement,
|
|
33
|
+
Fragment: _react.Fragment
|
|
34
|
+
});
|
|
35
|
+
var AutocompleteIndex = (0, _instantsearchUiComponents.createAutocompleteIndexComponent)({
|
|
36
|
+
createElement: _react.createElement,
|
|
37
|
+
Fragment: _react.Fragment
|
|
38
|
+
});
|
|
39
|
+
var AutocompleteSuggestion = (0, _instantsearchUiComponents.createAutocompleteSuggestionComponent)({
|
|
40
|
+
createElement: _react.createElement,
|
|
41
|
+
Fragment: _react.Fragment
|
|
42
|
+
});
|
|
43
|
+
function VirtualSearchBox() {
|
|
44
|
+
(0, _reactInstantsearchCore.useSearchBox)();
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var _ref3 = /*#__PURE__*/_react.default.createElement(VirtualSearchBox, null);
|
|
48
|
+
function EXPERIMENTAL_Autocomplete(_ref) {
|
|
49
|
+
var _ref$indices = _ref.indices,
|
|
50
|
+
userIndices = _ref$indices === void 0 ? [] : _ref$indices,
|
|
51
|
+
showSuggestions = _ref.showSuggestions;
|
|
52
|
+
var indices = _toConsumableArray(userIndices);
|
|
53
|
+
if (showSuggestions !== null && showSuggestions !== void 0 && showSuggestions.indexName) {
|
|
54
|
+
var _showSuggestions$clas, _showSuggestions$clas2, _showSuggestions$clas3;
|
|
55
|
+
indices.unshift({
|
|
56
|
+
indexName: showSuggestions.indexName,
|
|
57
|
+
// Temporarily force casting until the coming refactoring
|
|
58
|
+
itemComponent: showSuggestions.itemComponent || AutocompleteSuggestion,
|
|
59
|
+
classNames: {
|
|
60
|
+
root: (0, _instantsearchUiComponents.cx)('ais-AutocompleteSuggestions', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions$clas = showSuggestions.classNames) === null || _showSuggestions$clas === void 0 ? void 0 : _showSuggestions$clas.root),
|
|
61
|
+
list: (0, _instantsearchUiComponents.cx)('ais-AutocompleteSuggestionsList', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions$clas2 = showSuggestions.classNames) === null || _showSuggestions$clas2 === void 0 ? void 0 : _showSuggestions$clas2.list),
|
|
62
|
+
item: (0, _instantsearchUiComponents.cx)('ais-AutocompleteSuggestionsItem', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions$clas3 = showSuggestions.classNames) === null || _showSuggestions$clas3 === void 0 ? void 0 : _showSuggestions$clas3.item)
|
|
63
|
+
},
|
|
64
|
+
getQuery: function getQuery(item) {
|
|
65
|
+
return item.query;
|
|
66
|
+
},
|
|
67
|
+
onSelect: function onSelect(_ref2) {
|
|
68
|
+
var getQuery = _ref2.getQuery,
|
|
69
|
+
setQuery = _ref2.setQuery;
|
|
70
|
+
setQuery(getQuery());
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
var _useAutocomplete = (0, _useAutocomplete2.useAutocomplete)({
|
|
75
|
+
indices: indices
|
|
76
|
+
}),
|
|
77
|
+
getIndexProps = _useAutocomplete.getIndexProps,
|
|
78
|
+
getInputProps = _useAutocomplete.getInputProps,
|
|
79
|
+
getItemProps = _useAutocomplete.getItemProps,
|
|
80
|
+
getPanelProps = _useAutocomplete.getPanelProps,
|
|
81
|
+
getRootProps = _useAutocomplete.getRootProps;
|
|
82
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, _ref3, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.Index, _extends({
|
|
83
|
+
EXPERIMENTAL_isolated: true
|
|
84
|
+
}, getIndexProps()), /*#__PURE__*/_react.default.createElement(Autocomplete, getRootProps(), /*#__PURE__*/_react.default.createElement(_SearchBox.SearchBox, {
|
|
85
|
+
inputProps: getInputProps()
|
|
86
|
+
}), /*#__PURE__*/_react.default.createElement(AutocompletePanel, getPanelProps(), indices.map(function (index) {
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.Index, {
|
|
88
|
+
key: index.indexName,
|
|
89
|
+
indexName: index.indexName
|
|
90
|
+
}, /*#__PURE__*/_react.default.createElement(AutocompleteIndexComponent, _extends({}, index, {
|
|
91
|
+
getItemProps: getItemProps
|
|
92
|
+
})));
|
|
93
|
+
})))));
|
|
94
|
+
}
|
|
95
|
+
function AutocompleteIndexComponent(_ref4) {
|
|
96
|
+
var indexName = _ref4.indexName,
|
|
97
|
+
ItemComponent = _ref4.itemComponent,
|
|
98
|
+
getItemProps = _ref4.getItemProps,
|
|
99
|
+
classNames = _ref4.classNames;
|
|
100
|
+
var _useHits = (0, _reactInstantsearchCore.useHits)(),
|
|
101
|
+
items = _useHits.items;
|
|
102
|
+
return /*#__PURE__*/_react.default.createElement(AutocompleteIndex
|
|
103
|
+
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
104
|
+
, {
|
|
105
|
+
ItemComponent: ItemComponent,
|
|
106
|
+
items: items.map(function (item) {
|
|
107
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
108
|
+
__indexName: indexName
|
|
109
|
+
});
|
|
110
|
+
}),
|
|
111
|
+
getItemProps: getItemProps,
|
|
112
|
+
classNames: classNames
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -10,16 +10,34 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
12
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
13
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
19
|
var CarouselUiComponent = (0, _instantsearchUiComponents.createCarouselComponent)({
|
|
14
20
|
createElement: _react.createElement,
|
|
15
21
|
Fragment: _react.Fragment
|
|
16
22
|
});
|
|
17
23
|
function Carousel(props) {
|
|
24
|
+
var _useState = (0, _react.useState)(false),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
canScrollLeft = _useState2[0],
|
|
27
|
+
setCanScrollLeft = _useState2[1];
|
|
28
|
+
var _useState3 = (0, _react.useState)(true),
|
|
29
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
30
|
+
canScrollRight = _useState4[0],
|
|
31
|
+
setCanScrollRight = _useState4[1];
|
|
18
32
|
var carouselRefs = {
|
|
19
33
|
listRef: (0, _react.useRef)(null),
|
|
20
34
|
nextButtonRef: (0, _react.useRef)(null),
|
|
21
35
|
previousButtonRef: (0, _react.useRef)(null),
|
|
22
|
-
carouselIdRef: (0, _react.useRef)((0, _instantsearchUiComponents.generateCarouselId)())
|
|
36
|
+
carouselIdRef: (0, _react.useRef)((0, _instantsearchUiComponents.generateCarouselId)()),
|
|
37
|
+
canScrollLeft: canScrollLeft,
|
|
38
|
+
canScrollRight: canScrollRight,
|
|
39
|
+
setCanScrollLeft: setCanScrollLeft,
|
|
40
|
+
setCanScrollRight: setCanScrollRight
|
|
23
41
|
};
|
|
24
42
|
return /*#__PURE__*/_react.default.createElement(CarouselUiComponent, _extends({}, carouselRefs, props));
|
|
25
43
|
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useAutocomplete = useAutocomplete;
|
|
8
|
+
var _connectors = require("instantsearch.js/cjs/connectors");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
11
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
12
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
21
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
22
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
24
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
25
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
+
function useAutocomplete(_ref) {
|
|
27
|
+
var indices = _ref.indices;
|
|
28
|
+
var _useConnector = (0, _reactInstantsearchCore.useConnector)(_connectors.connectAutocomplete, {}),
|
|
29
|
+
connectorIndices = _useConnector.indices,
|
|
30
|
+
refine = _useConnector.refine;
|
|
31
|
+
var _useInstantSearch = (0, _reactInstantsearchCore.useInstantSearch)(),
|
|
32
|
+
setUiState = _useInstantSearch.setUiState;
|
|
33
|
+
var getElementId = createGetElementId((0, _react.useId)());
|
|
34
|
+
var rootRef = (0, _react.useRef)(null);
|
|
35
|
+
var panelRef = (0, _react.useRef)(null);
|
|
36
|
+
var _useState = (0, _react.useState)(false),
|
|
37
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
+
isOpen = _useState2[0],
|
|
39
|
+
setIsOpen = _useState2[1];
|
|
40
|
+
var _useState3 = (0, _react.useState)(undefined),
|
|
41
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
|
+
activeDescendent = _useState4[0],
|
|
43
|
+
setActiveDescendent = _useState4[1];
|
|
44
|
+
var items = indices.reduce(function (itemsAcc, index) {
|
|
45
|
+
var _connectorIndices$fin;
|
|
46
|
+
var indexItems = ((_connectorIndices$fin = connectorIndices.find(function (_ref2) {
|
|
47
|
+
var indexName = _ref2.indexName;
|
|
48
|
+
return index.indexName === indexName;
|
|
49
|
+
})) === null || _connectorIndices$fin === void 0 ? void 0 : _connectorIndices$fin.hits.reduce(function (indexItemsAcc, item, i) {
|
|
50
|
+
return _objectSpread(_objectSpread({}, indexItemsAcc), {}, _defineProperty({}, getElementId('item', index.indexName, i), {
|
|
51
|
+
item: item,
|
|
52
|
+
indexName: index.indexName,
|
|
53
|
+
getQuery: function getQuery() {
|
|
54
|
+
var _index$getQuery;
|
|
55
|
+
return ((_index$getQuery = index.getQuery) === null || _index$getQuery === void 0 ? void 0 : _index$getQuery.call(index, item)) || '';
|
|
56
|
+
},
|
|
57
|
+
getURL: function getURL() {
|
|
58
|
+
var _index$getURL;
|
|
59
|
+
return ((_index$getURL = index.getURL) === null || _index$getURL === void 0 ? void 0 : _index$getURL.call(index, item)) || '';
|
|
60
|
+
},
|
|
61
|
+
onSelect: index.onSelect
|
|
62
|
+
}));
|
|
63
|
+
}, {})) || {};
|
|
64
|
+
return _objectSpread(_objectSpread({}, itemsAcc), indexItems);
|
|
65
|
+
}, {});
|
|
66
|
+
(0, _react.useLayoutEffect)(function () {
|
|
67
|
+
var onBodyClick = function onBodyClick(event) {
|
|
68
|
+
var _rootRef$current;
|
|
69
|
+
if ((_rootRef$current = rootRef.current) !== null && _rootRef$current !== void 0 && _rootRef$current.contains(event.target)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setIsOpen(false);
|
|
73
|
+
};
|
|
74
|
+
document.body.addEventListener('click', onBodyClick);
|
|
75
|
+
return function () {
|
|
76
|
+
document.body.removeEventListener('click', onBodyClick);
|
|
77
|
+
};
|
|
78
|
+
}, [rootRef]);
|
|
79
|
+
var getNextActiveDescendent = function getNextActiveDescendent(key) {
|
|
80
|
+
if (!panelRef.current) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
var rows = _toConsumableArray(panelRef.current.querySelectorAll('[role="row"]'));
|
|
84
|
+
switch (key) {
|
|
85
|
+
case 'ArrowLeft':
|
|
86
|
+
case 'ArrowUp':
|
|
87
|
+
{
|
|
88
|
+
var prevIndex = rows.findIndex(function (row) {
|
|
89
|
+
return row.id === activeDescendent;
|
|
90
|
+
}) - 1;
|
|
91
|
+
if (rows[prevIndex]) {
|
|
92
|
+
return rows[prevIndex].id;
|
|
93
|
+
}
|
|
94
|
+
return rows[rows.length - 1].id;
|
|
95
|
+
}
|
|
96
|
+
case 'ArrowRight':
|
|
97
|
+
case 'ArrowDown':
|
|
98
|
+
{
|
|
99
|
+
var nextIndex = rows.findIndex(function (row) {
|
|
100
|
+
return row.id === activeDescendent;
|
|
101
|
+
}) + 1;
|
|
102
|
+
if (rows[nextIndex]) {
|
|
103
|
+
return rows[nextIndex].id;
|
|
104
|
+
}
|
|
105
|
+
return rows[0].id;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var submit = function submit() {
|
|
112
|
+
setIsOpen(false);
|
|
113
|
+
if (activeDescendent && items[activeDescendent]) {
|
|
114
|
+
var _items$activeDescende = items[activeDescendent],
|
|
115
|
+
_item = _items$activeDescende.item,
|
|
116
|
+
onSelect = _items$activeDescende.onSelect,
|
|
117
|
+
getQuery = _items$activeDescende.getQuery,
|
|
118
|
+
getURL = _items$activeDescende.getURL;
|
|
119
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect({
|
|
120
|
+
item: _item,
|
|
121
|
+
getQuery: getQuery,
|
|
122
|
+
getURL: getURL,
|
|
123
|
+
setQuery: function setQuery(query) {
|
|
124
|
+
refine(query);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
setUiState(function (uiState) {
|
|
128
|
+
return _objectSpread(_objectSpread({}, uiState), {}, _defineProperty({}, getElementId('index'), {
|
|
129
|
+
query: getQuery()
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
setActiveDescendent(undefined);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
getIndexProps: function getIndexProps() {
|
|
137
|
+
return {
|
|
138
|
+
indexId: getElementId('index')
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
getInputProps: function getInputProps() {
|
|
142
|
+
return {
|
|
143
|
+
id: getElementId('input'),
|
|
144
|
+
role: 'combobox',
|
|
145
|
+
'aria-autocomplete': 'list',
|
|
146
|
+
'aria-expanded': isOpen,
|
|
147
|
+
'aria-haspopup': 'grid',
|
|
148
|
+
'aria-controls': getElementId('panel'),
|
|
149
|
+
'aria-activedescendant': activeDescendent,
|
|
150
|
+
onFocus: function onFocus() {
|
|
151
|
+
return setIsOpen(true);
|
|
152
|
+
},
|
|
153
|
+
onKeyDown: function onKeyDown(event) {
|
|
154
|
+
if (event.key === 'Escape') {
|
|
155
|
+
setActiveDescendent(undefined);
|
|
156
|
+
setIsOpen(false);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
switch (event.key) {
|
|
160
|
+
case 'ArrowLeft':
|
|
161
|
+
case 'ArrowUp':
|
|
162
|
+
case 'ArrowRight':
|
|
163
|
+
case 'ArrowDown':
|
|
164
|
+
setActiveDescendent(getNextActiveDescendent(event.key));
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
break;
|
|
167
|
+
case 'Enter':
|
|
168
|
+
{
|
|
169
|
+
submit();
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case 'Tab':
|
|
173
|
+
setIsOpen(false);
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
onKeyUp: function onKeyUp(event) {
|
|
180
|
+
switch (event.key) {
|
|
181
|
+
case 'ArrowLeft':
|
|
182
|
+
case 'ArrowUp':
|
|
183
|
+
case 'ArrowRight':
|
|
184
|
+
case 'ArrowDown':
|
|
185
|
+
case 'Escape':
|
|
186
|
+
case 'Return':
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
return;
|
|
189
|
+
default:
|
|
190
|
+
setActiveDescendent(undefined);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
getItemProps: function getItemProps(item, index) {
|
|
197
|
+
var id = getElementId('item', item.__indexName, index);
|
|
198
|
+
return {
|
|
199
|
+
id: id,
|
|
200
|
+
role: 'row',
|
|
201
|
+
'aria-selected': id === activeDescendent,
|
|
202
|
+
onMouseEnter: function onMouseEnter() {
|
|
203
|
+
return setActiveDescendent(id);
|
|
204
|
+
},
|
|
205
|
+
onMouseLeave: function onMouseLeave() {
|
|
206
|
+
return setActiveDescendent(undefined);
|
|
207
|
+
},
|
|
208
|
+
onSelect: function onSelect() {
|
|
209
|
+
return submit();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
getPanelProps: function getPanelProps() {
|
|
214
|
+
return {
|
|
215
|
+
ref: panelRef,
|
|
216
|
+
hidden: !isOpen,
|
|
217
|
+
id: getElementId('panel'),
|
|
218
|
+
role: 'grid',
|
|
219
|
+
'aria-labelledby': getElementId('input')
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
getRootProps: function getRootProps() {
|
|
223
|
+
return {
|
|
224
|
+
ref: rootRef
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function createGetElementId(autocompleteId) {
|
|
230
|
+
return function getElementId() {
|
|
231
|
+
var prefix = 'autocomplete';
|
|
232
|
+
for (var _len = arguments.length, suffixes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
233
|
+
suffixes[_key] = arguments[_key];
|
|
234
|
+
}
|
|
235
|
+
return "".concat(prefix).concat(autocompleteId).concat(suffixes.join(':'));
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _index = require("react-instantsearch-core/dist/es/index.umd");
|
|
7
|
+
Object.keys(_index).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _index[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _index2 = require("./widgets/index.umd");
|
|
18
|
+
Object.keys(_index2).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _index2[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _index2[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _components = require("./components");
|
|
29
|
+
Object.keys(_components).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _components[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _components[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useStickToBottom = void 0;
|
|
7
|
+
var _instantsearchUiComponents = require("instantsearch-ui-components");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
/* !---------------------------------------------------------------------------------------------
|
|
10
|
+
* Copyright (c) StackBlitz. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
12
|
+
*--------------------------------------------------------------------------------------------*/
|
|
13
|
+
|
|
14
|
+
var useStickToBottom = exports.useStickToBottom = (0, _instantsearchUiComponents.createStickToBottom)({
|
|
15
|
+
useCallback: _react.useCallback,
|
|
16
|
+
useEffect: _react.useEffect,
|
|
17
|
+
useMemo: _react.useMemo,
|
|
18
|
+
useRef: _react.useRef,
|
|
19
|
+
useState: _react.useState
|
|
20
|
+
});
|
package/dist/cjs/ui/SearchBox.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.SearchBox = SearchBox;
|
|
7
7
|
var _instantsearchUiComponents = require("instantsearch-ui-components");
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _excluded = ["formRef", "inputRef", "isSearchStalled", "onChange", "onReset", "onSubmit", "placeholder", "value", "autoFocus", "resetIconComponent", "submitIconComponent", "loadingIconComponent", "classNames", "translations"];
|
|
9
|
+
var _excluded = ["formRef", "inputRef", "inputProps", "isSearchStalled", "onChange", "onReset", "onSubmit", "placeholder", "value", "autoFocus", "resetIconComponent", "submitIconComponent", "loadingIconComponent", "classNames", "translations"];
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
12
12
|
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; }
|
|
@@ -73,6 +73,7 @@ function DefaultLoadingIcon(_ref5) {
|
|
|
73
73
|
function SearchBox(_ref7) {
|
|
74
74
|
var formRef = _ref7.formRef,
|
|
75
75
|
inputRef = _ref7.inputRef,
|
|
76
|
+
inputProps = _ref7.inputProps,
|
|
76
77
|
isSearchStalled = _ref7.isSearchStalled,
|
|
77
78
|
onChange = _ref7.onChange,
|
|
78
79
|
onReset = _ref7.onReset,
|
|
@@ -119,9 +120,9 @@ function SearchBox(_ref7) {
|
|
|
119
120
|
onSubmit: handleSubmit,
|
|
120
121
|
onReset: handleReset,
|
|
121
122
|
role: "search"
|
|
122
|
-
}, /*#__PURE__*/_react.default.createElement("input", {
|
|
123
|
+
}, /*#__PURE__*/_react.default.createElement("input", _extends({}, inputProps, {
|
|
123
124
|
ref: inputRef,
|
|
124
|
-
className: (0, _instantsearchUiComponents.cx)('ais-SearchBox-input', classNames.input),
|
|
125
|
+
className: (0, _instantsearchUiComponents.cx)('ais-SearchBox-input', classNames.input, inputProps === null || inputProps === void 0 ? void 0 : inputProps.className),
|
|
125
126
|
"aria-label": "Search",
|
|
126
127
|
autoComplete: "off",
|
|
127
128
|
autoCorrect: "off",
|
|
@@ -134,7 +135,7 @@ function SearchBox(_ref7) {
|
|
|
134
135
|
onChange: onChange,
|
|
135
136
|
onCompositionEnd: onChange,
|
|
136
137
|
autoFocus: autoFocus
|
|
137
|
-
}), /*#__PURE__*/_react.default.createElement("button", {
|
|
138
|
+
})), /*#__PURE__*/_react.default.createElement("button", {
|
|
138
139
|
className: (0, _instantsearchUiComponents.cx)('ais-SearchBox-submit', classNames.submit),
|
|
139
140
|
type: "submit",
|
|
140
141
|
title: translations.submitButtonTitle
|