123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
- 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."); }
- 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); }
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
- 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; }
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- import { getItemsCount, generateAutocompleteId, flatten } from '@algolia/autocomplete-shared';
- import { getNormalizedSources } from './utils';
- export function getDefaultProps(props, pluginSubscribers) {
- var _props$id;
- /* eslint-disable no-restricted-globals */
- var environment = typeof window !== 'undefined' ? window : {};
- /* eslint-enable no-restricted-globals */
- var plugins = props.plugins || [];
- return _objectSpread(_objectSpread({
- debug: false,
- openOnFocus: false,
- placeholder: '',
- autoFocus: false,
- defaultActiveItemId: null,
- stallThreshold: 300,
- environment: environment,
- shouldPanelOpen: function shouldPanelOpen(_ref) {
- var state = _ref.state;
- return getItemsCount(state) > 0;
- },
- reshape: function reshape(_ref2) {
- var sources = _ref2.sources;
- return sources;
- }
- }, props), {}, {
- // Since `generateAutocompleteId` triggers a side effect (it increments
- // an internal counter), we don't want to execute it if unnecessary.
- id: (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generateAutocompleteId(),
- plugins: plugins,
- // The following props need to be deeply defaulted.
- initialState: _objectSpread({
- activeItemId: null,
- query: '',
- completion: null,
- collections: [],
- isOpen: false,
- status: 'idle',
- context: {}
- }, props.initialState),
- onStateChange: function onStateChange(params) {
- var _props$onStateChange;
- (_props$onStateChange = props.onStateChange) === null || _props$onStateChange === void 0 ? void 0 : _props$onStateChange.call(props, params);
- plugins.forEach(function (x) {
- var _x$onStateChange;
- return (_x$onStateChange = x.onStateChange) === null || _x$onStateChange === void 0 ? void 0 : _x$onStateChange.call(x, params);
- });
- },
- onSubmit: function onSubmit(params) {
- var _props$onSubmit;
- (_props$onSubmit = props.onSubmit) === null || _props$onSubmit === void 0 ? void 0 : _props$onSubmit.call(props, params);
- plugins.forEach(function (x) {
- var _x$onSubmit;
- return (_x$onSubmit = x.onSubmit) === null || _x$onSubmit === void 0 ? void 0 : _x$onSubmit.call(x, params);
- });
- },
- onReset: function onReset(params) {
- var _props$onReset;
- (_props$onReset = props.onReset) === null || _props$onReset === void 0 ? void 0 : _props$onReset.call(props, params);
- plugins.forEach(function (x) {
- var _x$onReset;
- return (_x$onReset = x.onReset) === null || _x$onReset === void 0 ? void 0 : _x$onReset.call(x, params);
- });
- },
- getSources: function getSources(params) {
- return Promise.all([].concat(_toConsumableArray(plugins.map(function (plugin) {
- return plugin.getSources;
- })), [props.getSources]).filter(Boolean).map(function (getSources) {
- return getNormalizedSources(getSources, params);
- })).then(function (nested) {
- return flatten(nested);
- }).then(function (sources) {
- return sources.map(function (source) {
- return _objectSpread(_objectSpread({}, source), {}, {
- onSelect: function onSelect(params) {
- source.onSelect(params);
- pluginSubscribers.forEach(function (x) {
- var _x$onSelect;
- return (_x$onSelect = x.onSelect) === null || _x$onSelect === void 0 ? void 0 : _x$onSelect.call(x, params);
- });
- },
- onActive: function onActive(params) {
- source.onActive(params);
- pluginSubscribers.forEach(function (x) {
- var _x$onActive;
- return (_x$onActive = x.onActive) === null || _x$onActive === void 0 ? void 0 : _x$onActive.call(x, params);
- });
- }
- });
- });
- });
- },
- navigator: _objectSpread({
- navigate: function navigate(_ref3) {
- var itemUrl = _ref3.itemUrl;
- environment.location.assign(itemUrl);
- },
- navigateNewTab: function navigateNewTab(_ref4) {
- var itemUrl = _ref4.itemUrl;
- var windowReference = environment.open(itemUrl, '_blank', 'noopener');
- windowReference === null || windowReference === void 0 ? void 0 : windowReference.focus();
- },
- navigateNewWindow: function navigateNewWindow(_ref5) {
- var itemUrl = _ref5.itemUrl;
- environment.open(itemUrl, '_blank', 'noopener');
- }
- }, props.navigator)
- });
- }
|