/*! InstantSearch.js 3.1.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.instantsearch = factory());
}(this, function () { 'use strict';
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
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;
}
function _extends() {
_extends = Object.assign || 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);
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
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;
}
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;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
/**
* The base implementation of `_.times` without support for iteratee shorthands
* or max array length checks.
*
* @private
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the array of results.
*/
function baseTimes(n, iteratee) {
var index = -1,
result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
var _baseTimes = baseTimes;
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
var _freeGlobal = freeGlobal;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = _freeGlobal || freeSelf || Function('return this')();
var _root = root;
/** Built-in value references. */
var Symbol$1 = _root.Symbol;
var _Symbol = Symbol$1;
/** Used for built-in method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/** Built-in value references. */
var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag),
tag = value[symToStringTag];
try {
value[symToStringTag] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}
var _getRawTag = getRawTag;
/** Used for built-in method references. */
var objectProto$1 = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString$1 = objectProto$1.toString;
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString$1.call(value);
}
var _objectToString = objectToString;
/** `Object#toString` result references. */
var nullTag = '[object Null]',
undefinedTag = '[object Undefined]';
/** Built-in value references. */
var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag$1 && symToStringTag$1 in Object(value))
? _getRawTag(value)
: _objectToString(value);
}
var _baseGetTag = baseGetTag;
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
var isObjectLike_1 = isObjectLike;
/** `Object#toString` result references. */
var argsTag = '[object Arguments]';
/**
* The base implementation of `_.isArguments`.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
*/
function baseIsArguments(value) {
return isObjectLike_1(value) && _baseGetTag(value) == argsTag;
}
var _baseIsArguments = baseIsArguments;
/** Used for built-in method references. */
var objectProto$2 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
/** Built-in value references. */
var propertyIsEnumerable = objectProto$2.propertyIsEnumerable;
/**
* Checks if `value` is likely an `arguments` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
* else `false`.
* @example
*
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
var isArguments = _baseIsArguments(function() { return arguments; }()) ? _baseIsArguments : function(value) {
return isObjectLike_1(value) && hasOwnProperty$1.call(value, 'callee') &&
!propertyIsEnumerable.call(value, 'callee');
};
var isArguments_1 = isArguments;
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
var isArray_1 = isArray;
/**
* This method returns `false`.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {boolean} Returns `false`.
* @example
*
* _.times(2, _.stubFalse);
* // => [false, false]
*/
function stubFalse() {
return false;
}
var stubFalse_1 = stubFalse;
var isBuffer_1 = createCommonjsModule(function (module, exports) {
/** Detect free variable `exports`. */
var freeExports = exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Built-in value references. */
var Buffer = moduleExports ? _root.Buffer : undefined;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
/**
* Checks if `value` is a buffer.
*
* @static
* @memberOf _
* @since 4.3.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
* @example
*
* _.isBuffer(new Buffer(2));
* // => true
*
* _.isBuffer(new Uint8Array(2));
* // => false
*/
var isBuffer = nativeIsBuffer || stubFalse_1;
module.exports = isBuffer;
});
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;
/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
var type = typeof value;
length = length == null ? MAX_SAFE_INTEGER : length;
return !!length &&
(type == 'number' ||
(type != 'symbol' && reIsUint.test(value))) &&
(value > -1 && value % 1 == 0 && value < length);
}
var _isIndex = isIndex;
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER$1 = 9007199254740991;
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This method is loosely based on
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$1;
}
var isLength_1 = isLength;
/** `Object#toString` result references. */
var argsTag$1 = '[object Arguments]',
arrayTag = '[object Array]',
boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
mapTag = '[object Map]',
numberTag = '[object Number]',
objectTag = '[object Object]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]',
dataViewTag = '[object DataView]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]';
/** Used to identify `toStringTag` values of typed arrays. */
var typedArrayTags = {};
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
typedArrayTags[uint32Tag] = true;
typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] =
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
typedArrayTags[errorTag] = typedArrayTags[funcTag] =
typedArrayTags[mapTag] = typedArrayTags[numberTag] =
typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
typedArrayTags[setTag] = typedArrayTags[stringTag] =
typedArrayTags[weakMapTag] = false;
/**
* The base implementation of `_.isTypedArray` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
*/
function baseIsTypedArray(value) {
return isObjectLike_1(value) &&
isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
}
var _baseIsTypedArray = baseIsTypedArray;
/**
* The base implementation of `_.unary` without support for storing metadata.
*
* @private
* @param {Function} func The function to cap arguments for.
* @returns {Function} Returns the new capped function.
*/
function baseUnary(func) {
return function(value) {
return func(value);
};
}
var _baseUnary = baseUnary;
var _nodeUtil = createCommonjsModule(function (module, exports) {
/** Detect free variable `exports`. */
var freeExports = exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Detect free variable `process` from Node.js. */
var freeProcess = moduleExports && _freeGlobal.process;
/** Used to access faster Node.js helpers. */
var nodeUtil = (function() {
try {
// Use `util.types` for Node.js 10+.
var types = freeModule && freeModule.require && freeModule.require('util').types;
if (types) {
return types;
}
// Legacy `process.binding('util')` for Node.js < 10.
return freeProcess && freeProcess.binding && freeProcess.binding('util');
} catch (e) {}
}());
module.exports = nodeUtil;
});
/* Node.js helper references. */
var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
/**
* Checks if `value` is classified as a typed array.
*
* @static
* @memberOf _
* @since 3.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
* @example
*
* _.isTypedArray(new Uint8Array);
* // => true
*
* _.isTypedArray([]);
* // => false
*/
var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
var isTypedArray_1 = isTypedArray;
/** Used for built-in method references. */
var objectProto$3 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
/**
* Creates an array of the enumerable property names of the array-like `value`.
*
* @private
* @param {*} value The value to query.
* @param {boolean} inherited Specify returning inherited property names.
* @returns {Array} Returns the array of property names.
*/
function arrayLikeKeys(value, inherited) {
var isArr = isArray_1(value),
isArg = !isArr && isArguments_1(value),
isBuff = !isArr && !isArg && isBuffer_1(value),
isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
skipIndexes = isArr || isArg || isBuff || isType,
result = skipIndexes ? _baseTimes(value.length, String) : [],
length = result.length;
for (var key in value) {
if ((inherited || hasOwnProperty$2.call(value, key)) &&
!(skipIndexes && (
// Safari 9 has enumerable `arguments.length` in strict mode.
key == 'length' ||
// Node.js 0.10 has enumerable non-index properties on buffers.
(isBuff && (key == 'offset' || key == 'parent')) ||
// PhantomJS 2 has enumerable non-index properties on typed arrays.
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
// Skip index properties.
_isIndex(key, length)
))) {
result.push(key);
}
}
return result;
}
var _arrayLikeKeys = arrayLikeKeys;
/** Used for built-in method references. */
var objectProto$4 = Object.prototype;
/**
* Checks if `value` is likely a prototype object.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
*/
function isPrototype(value) {
var Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$4;
return value === proto;
}
var _isPrototype = isPrototype;
/**
* Creates a unary function that invokes `func` with its argument transformed.
*
* @private
* @param {Function} func The function to wrap.
* @param {Function} transform The argument transform.
* @returns {Function} Returns the new function.
*/
function overArg(func, transform) {
return function(arg) {
return func(transform(arg));
};
}
var _overArg = overArg;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeKeys = _overArg(Object.keys, Object);
var _nativeKeys = nativeKeys;
/** Used for built-in method references. */
var objectProto$5 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$3 = objectProto$5.hasOwnProperty;
/**
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
if (!_isPrototype(object)) {
return _nativeKeys(object);
}
var result = [];
for (var key in Object(object)) {
if (hasOwnProperty$3.call(object, key) && key != 'constructor') {
result.push(key);
}
}
return result;
}
var _baseKeys = baseKeys;
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
var isObject_1 = isObject;
/** `Object#toString` result references. */
var asyncTag = '[object AsyncFunction]',
funcTag$1 = '[object Function]',
genTag = '[object GeneratorFunction]',
proxyTag = '[object Proxy]';
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
if (!isObject_1(value)) {
return false;
}
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 9 which returns 'object' for typed arrays and other constructors.
var tag = _baseGetTag(value);
return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag;
}
var isFunction_1 = isFunction;
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null && isLength_1(value.length) && !isFunction_1(value);
}
var isArrayLike_1 = isArrayLike;
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
* for more details.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keys(new Foo);
* // => ['a', 'b'] (iteration order is not guaranteed)
*
* _.keys('hi');
* // => ['0', '1']
*/
function keys(object) {
return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
}
var keys_1 = keys;
/**
* A specialized version of `_.map` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function arrayMap(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
var _arrayMap = arrayMap;
/** Used to detect overreaching core-js shims. */
var coreJsData = _root['__core-js_shared__'];
var _coreJsData = coreJsData;
/** Used to detect methods masquerading as native. */
var maskSrcKey = (function() {
var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || '');
return uid ? ('Symbol(src)_1.' + uid) : '';
}());
/**
* Checks if `func` has its source masked.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
*/
function isMasked(func) {
return !!maskSrcKey && (maskSrcKey in func);
}
var _isMasked = isMasked;
/** Used for built-in method references. */
var funcProto = Function.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/**
* Converts `func` to its source code.
*
* @private
* @param {Function} func The function to convert.
* @returns {string} Returns the source code.
*/
function toSource(func) {
if (func != null) {
try {
return funcToString.call(func);
} catch (e) {}
try {
return (func + '');
} catch (e) {}
}
return '';
}
var _toSource = toSource;
/**
* Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
*/
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
/** Used to detect host constructors (Safari). */
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used for built-in method references. */
var funcProto$1 = Function.prototype,
objectProto$6 = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString$1 = funcProto$1.toString;
/** Used to check objects for own properties. */
var hasOwnProperty$4 = objectProto$6.hasOwnProperty;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
funcToString$1.call(hasOwnProperty$4).replace(reRegExpChar, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
/**
* The base implementation of `_.isNative` without bad shim checks.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a native function,
* else `false`.
*/
function baseIsNative(value) {
if (!isObject_1(value) || _isMasked(value)) {
return false;
}
var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
return pattern.test(_toSource(value));
}
var _baseIsNative = baseIsNative;
/**
* Gets the value at `key` of `object`.
*
* @private
* @param {Object} [object] The object to query.
* @param {string} key The key of the property to get.
* @returns {*} Returns the property value.
*/
function getValue(object, key) {
return object == null ? undefined : object[key];
}
var _getValue = getValue;
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = _getValue(object, key);
return _baseIsNative(value) ? value : undefined;
}
var _getNative = getNative;
/* Built-in method references that are verified to be native. */
var nativeCreate = _getNative(Object, 'create');
var _nativeCreate = nativeCreate;
/**
* Removes all key-value entries from the hash.
*
* @private
* @name clear
* @memberOf Hash
*/
function hashClear() {
this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
this.size = 0;
}
var _hashClear = hashClear;
/**
* Removes `key` and its value from the hash.
*
* @private
* @name delete
* @memberOf Hash
* @param {Object} hash The hash to modify.
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function hashDelete(key) {
var result = this.has(key) && delete this.__data__[key];
this.size -= result ? 1 : 0;
return result;
}
var _hashDelete = hashDelete;
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED = '__lodash_hash_undefined__';
/** Used for built-in method references. */
var objectProto$7 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$5 = objectProto$7.hasOwnProperty;
/**
* Gets the hash value for `key`.
*
* @private
* @name get
* @memberOf Hash
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function hashGet(key) {
var data = this.__data__;
if (_nativeCreate) {
var result = data[key];
return result === HASH_UNDEFINED ? undefined : result;
}
return hasOwnProperty$5.call(data, key) ? data[key] : undefined;
}
var _hashGet = hashGet;
/** Used for built-in method references. */
var objectProto$8 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$6 = objectProto$8.hasOwnProperty;
/**
* Checks if a hash value for `key` exists.
*
* @private
* @name has
* @memberOf Hash
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function hashHas(key) {
var data = this.__data__;
return _nativeCreate ? (data[key] !== undefined) : hasOwnProperty$6.call(data, key);
}
var _hashHas = hashHas;
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
/**
* Sets the hash `key` to `value`.
*
* @private
* @name set
* @memberOf Hash
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the hash instance.
*/
function hashSet(key, value) {
var data = this.__data__;
this.size += this.has(key) ? 0 : 1;
data[key] = (_nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
return this;
}
var _hashSet = hashSet;
/**
* Creates a hash object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Hash(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
// Add methods to `Hash`.
Hash.prototype.clear = _hashClear;
Hash.prototype['delete'] = _hashDelete;
Hash.prototype.get = _hashGet;
Hash.prototype.has = _hashHas;
Hash.prototype.set = _hashSet;
var _Hash = Hash;
/**
* Removes all key-value entries from the list cache.
*
* @private
* @name clear
* @memberOf ListCache
*/
function listCacheClear() {
this.__data__ = [];
this.size = 0;
}
var _listCacheClear = listCacheClear;
/**
* Performs a
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* comparison between two values to determine if they are equivalent.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.eq(object, object);
* // => true
*
* _.eq(object, other);
* // => false
*
* _.eq('a', 'a');
* // => true
*
* _.eq('a', Object('a'));
* // => false
*
* _.eq(NaN, NaN);
* // => true
*/
function eq(value, other) {
return value === other || (value !== value && other !== other);
}
var eq_1 = eq;
/**
* Gets the index at which the `key` is found in `array` of key-value pairs.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} key The key to search for.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function assocIndexOf(array, key) {
var length = array.length;
while (length--) {
if (eq_1(array[length][0], key)) {
return length;
}
}
return -1;
}
var _assocIndexOf = assocIndexOf;
/** Used for built-in method references. */
var arrayProto = Array.prototype;
/** Built-in value references. */
var splice = arrayProto.splice;
/**
* Removes `key` and its value from the list cache.
*
* @private
* @name delete
* @memberOf ListCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function listCacheDelete(key) {
var data = this.__data__,
index = _assocIndexOf(data, key);
if (index < 0) {
return false;
}
var lastIndex = data.length - 1;
if (index == lastIndex) {
data.pop();
} else {
splice.call(data, index, 1);
}
--this.size;
return true;
}
var _listCacheDelete = listCacheDelete;
/**
* Gets the list cache value for `key`.
*
* @private
* @name get
* @memberOf ListCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function listCacheGet(key) {
var data = this.__data__,
index = _assocIndexOf(data, key);
return index < 0 ? undefined : data[index][1];
}
var _listCacheGet = listCacheGet;
/**
* Checks if a list cache value for `key` exists.
*
* @private
* @name has
* @memberOf ListCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function listCacheHas(key) {
return _assocIndexOf(this.__data__, key) > -1;
}
var _listCacheHas = listCacheHas;
/**
* Sets the list cache `key` to `value`.
*
* @private
* @name set
* @memberOf ListCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the list cache instance.
*/
function listCacheSet(key, value) {
var data = this.__data__,
index = _assocIndexOf(data, key);
if (index < 0) {
++this.size;
data.push([key, value]);
} else {
data[index][1] = value;
}
return this;
}
var _listCacheSet = listCacheSet;
/**
* Creates an list cache object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function ListCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
// Add methods to `ListCache`.
ListCache.prototype.clear = _listCacheClear;
ListCache.prototype['delete'] = _listCacheDelete;
ListCache.prototype.get = _listCacheGet;
ListCache.prototype.has = _listCacheHas;
ListCache.prototype.set = _listCacheSet;
var _ListCache = ListCache;
/* Built-in method references that are verified to be native. */
var Map$1 = _getNative(_root, 'Map');
var _Map = Map$1;
/**
* Removes all key-value entries from the map.
*
* @private
* @name clear
* @memberOf MapCache
*/
function mapCacheClear() {
this.size = 0;
this.__data__ = {
'hash': new _Hash,
'map': new (_Map || _ListCache),
'string': new _Hash
};
}
var _mapCacheClear = mapCacheClear;
/**
* Checks if `value` is suitable for use as unique object key.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
*/
function isKeyable(value) {
var type = typeof value;
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
? (value !== '__proto__')
: (value === null);
}
var _isKeyable = isKeyable;
/**
* Gets the data for `map`.
*
* @private
* @param {Object} map The map to query.
* @param {string} key The reference key.
* @returns {*} Returns the map data.
*/
function getMapData(map, key) {
var data = map.__data__;
return _isKeyable(key)
? data[typeof key == 'string' ? 'string' : 'hash']
: data.map;
}
var _getMapData = getMapData;
/**
* Removes `key` and its value from the map.
*
* @private
* @name delete
* @memberOf MapCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function mapCacheDelete(key) {
var result = _getMapData(this, key)['delete'](key);
this.size -= result ? 1 : 0;
return result;
}
var _mapCacheDelete = mapCacheDelete;
/**
* Gets the map value for `key`.
*
* @private
* @name get
* @memberOf MapCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function mapCacheGet(key) {
return _getMapData(this, key).get(key);
}
var _mapCacheGet = mapCacheGet;
/**
* Checks if a map value for `key` exists.
*
* @private
* @name has
* @memberOf MapCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function mapCacheHas(key) {
return _getMapData(this, key).has(key);
}
var _mapCacheHas = mapCacheHas;
/**
* Sets the map `key` to `value`.
*
* @private
* @name set
* @memberOf MapCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the map cache instance.
*/
function mapCacheSet(key, value) {
var data = _getMapData(this, key),
size = data.size;
data.set(key, value);
this.size += data.size == size ? 0 : 1;
return this;
}
var _mapCacheSet = mapCacheSet;
/**
* Creates a map cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function MapCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
// Add methods to `MapCache`.
MapCache.prototype.clear = _mapCacheClear;
MapCache.prototype['delete'] = _mapCacheDelete;
MapCache.prototype.get = _mapCacheGet;
MapCache.prototype.has = _mapCacheHas;
MapCache.prototype.set = _mapCacheSet;
var _MapCache = MapCache;
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
/**
* Adds `value` to the array cache.
*
* @private
* @name add
* @memberOf SetCache
* @alias push
* @param {*} value The value to cache.
* @returns {Object} Returns the cache instance.
*/
function setCacheAdd(value) {
this.__data__.set(value, HASH_UNDEFINED$2);
return this;
}
var _setCacheAdd = setCacheAdd;
/**
* Checks if `value` is in the array cache.
*
* @private
* @name has
* @memberOf SetCache
* @param {*} value The value to search for.
* @returns {number} Returns `true` if `value` is found, else `false`.
*/
function setCacheHas(value) {
return this.__data__.has(value);
}
var _setCacheHas = setCacheHas;
/**
*
* Creates an array cache object to store unique values.
*
* @private
* @constructor
* @param {Array} [values] The values to cache.
*/
function SetCache(values) {
var index = -1,
length = values == null ? 0 : values.length;
this.__data__ = new _MapCache;
while (++index < length) {
this.add(values[index]);
}
}
// Add methods to `SetCache`.
SetCache.prototype.add = SetCache.prototype.push = _setCacheAdd;
SetCache.prototype.has = _setCacheHas;
var _SetCache = SetCache;
/**
* The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for iteratee shorthands.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} predicate The function invoked per iteration.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseFindIndex(array, predicate, fromIndex, fromRight) {
var length = array.length,
index = fromIndex + (fromRight ? 1 : -1);
while ((fromRight ? index-- : ++index < length)) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
}
var _baseFindIndex = baseFindIndex;
/**
* The base implementation of `_.isNaN` without support for number objects.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
*/
function baseIsNaN(value) {
return value !== value;
}
var _baseIsNaN = baseIsNaN;
/**
* A specialized version of `_.indexOf` which performs strict equality
* comparisons of values, i.e. `===`.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} value The value to search for.
* @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function strictIndexOf(array, value, fromIndex) {
var index = fromIndex - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
var _strictIndexOf = strictIndexOf;
/**
* The base implementation of `_.indexOf` without `fromIndex` bounds checks.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} value The value to search for.
* @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseIndexOf(array, value, fromIndex) {
return value === value
? _strictIndexOf(array, value, fromIndex)
: _baseFindIndex(array, _baseIsNaN, fromIndex);
}
var _baseIndexOf = baseIndexOf;
/**
* A specialized version of `_.includes` for arrays without support for
* specifying an index to search from.
*
* @private
* @param {Array} [array] The array to inspect.
* @param {*} target The value to search for.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludes(array, value) {
var length = array == null ? 0 : array.length;
return !!length && _baseIndexOf(array, value, 0) > -1;
}
var _arrayIncludes = arrayIncludes;
/**
* This function is like `arrayIncludes` except that it accepts a comparator.
*
* @private
* @param {Array} [array] The array to inspect.
* @param {*} target The value to search for.
* @param {Function} comparator The comparator invoked per element.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludesWith(array, value, comparator) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
}
var _arrayIncludesWith = arrayIncludesWith;
/**
* Checks if a `cache` value for `key` exists.
*
* @private
* @param {Object} cache The cache to query.
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function cacheHas(cache, key) {
return cache.has(key);
}
var _cacheHas = cacheHas;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMin = Math.min;
/**
* The base implementation of methods like `_.intersection`, without support
* for iteratee shorthands, that accepts an array of arrays to inspect.
*
* @private
* @param {Array} arrays The arrays to inspect.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of shared values.
*/
function baseIntersection(arrays, iteratee, comparator) {
var includes = comparator ? _arrayIncludesWith : _arrayIncludes,
length = arrays[0].length,
othLength = arrays.length,
othIndex = othLength,
caches = Array(othLength),
maxLength = Infinity,
result = [];
while (othIndex--) {
var array = arrays[othIndex];
if (othIndex && iteratee) {
array = _arrayMap(array, _baseUnary(iteratee));
}
maxLength = nativeMin(array.length, maxLength);
caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
? new _SetCache(othIndex && array)
: undefined;
}
array = arrays[0];
var index = -1,
seen = caches[0];
outer:
while (++index < length && result.length < maxLength) {
var value = array[index],
computed = iteratee ? iteratee(value) : value;
value = (comparator || value !== 0) ? value : 0;
if (!(seen
? _cacheHas(seen, computed)
: includes(result, computed, comparator)
)) {
othIndex = othLength;
while (--othIndex) {
var cache = caches[othIndex];
if (!(cache
? _cacheHas(cache, computed)
: includes(arrays[othIndex], computed, comparator))
) {
continue outer;
}
}
if (seen) {
seen.push(computed);
}
result.push(value);
}
}
return result;
}
var _baseIntersection = baseIntersection;
/**
* This method returns the first argument it receives.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Util
* @param {*} value Any value.
* @returns {*} Returns `value`.
* @example
*
* var object = { 'a': 1 };
*
* console.log(_.identity(object) === object);
* // => true
*/
function identity(value) {
return value;
}
var identity_1 = identity;
/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {Array} args The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
switch (args.length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
var _apply = apply;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* A specialized version of `baseRest` which transforms the rest array.
*
* @private
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @param {Function} transform The rest array transform.
* @returns {Function} Returns the new function.
*/
function overRest(func, start, transform) {
start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
return function() {
var args = arguments,
index = -1,
length = nativeMax(args.length - start, 0),
array = Array(length);
while (++index < length) {
array[index] = args[start + index];
}
index = -1;
var otherArgs = Array(start + 1);
while (++index < start) {
otherArgs[index] = args[index];
}
otherArgs[start] = transform(array);
return _apply(func, this, otherArgs);
};
}
var _overRest = overRest;
/**
* Creates a function that returns `value`.
*
* @static
* @memberOf _
* @since 2.4.0
* @category Util
* @param {*} value The value to return from the new function.
* @returns {Function} Returns the new constant function.
* @example
*
* var objects = _.times(2, _.constant({ 'a': 1 }));
*
* console.log(objects);
* // => [{ 'a': 1 }, { 'a': 1 }]
*
* console.log(objects[0] === objects[1]);
* // => true
*/
function constant(value) {
return function() {
return value;
};
}
var constant_1 = constant;
var defineProperty = (function() {
try {
var func = _getNative(Object, 'defineProperty');
func({}, '', {});
return func;
} catch (e) {}
}());
var _defineProperty$1 = defineProperty;
/**
* The base implementation of `setToString` without support for hot loop shorting.
*
* @private
* @param {Function} func The function to modify.
* @param {Function} string The `toString` result.
* @returns {Function} Returns `func`.
*/
var baseSetToString = !_defineProperty$1 ? identity_1 : function(func, string) {
return _defineProperty$1(func, 'toString', {
'configurable': true,
'enumerable': false,
'value': constant_1(string),
'writable': true
});
};
var _baseSetToString = baseSetToString;
/** Used to detect hot functions by number of calls within a span of milliseconds. */
var HOT_COUNT = 800,
HOT_SPAN = 16;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeNow = Date.now;
/**
* Creates a function that'll short out and invoke `identity` instead
* of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
* milliseconds.
*
* @private
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new shortable function.
*/
function shortOut(func) {
var count = 0,
lastCalled = 0;
return function() {
var stamp = nativeNow(),
remaining = HOT_SPAN - (stamp - lastCalled);
lastCalled = stamp;
if (remaining > 0) {
if (++count >= HOT_COUNT) {
return arguments[0];
}
} else {
count = 0;
}
return func.apply(undefined, arguments);
};
}
var _shortOut = shortOut;
/**
* Sets the `toString` method of `func` to return `string`.
*
* @private
* @param {Function} func The function to modify.
* @param {Function} string The `toString` result.
* @returns {Function} Returns `func`.
*/
var setToString = _shortOut(_baseSetToString);
var _setToString = setToString;
/**
* The base implementation of `_.rest` which doesn't validate or coerce arguments.
*
* @private
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @returns {Function} Returns the new function.
*/
function baseRest(func, start) {
return _setToString(_overRest(func, start, identity_1), func + '');
}
var _baseRest = baseRest;
/**
* This method is like `_.isArrayLike` except that it also checks if `value`
* is an object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array-like object,
* else `false`.
* @example
*
* _.isArrayLikeObject([1, 2, 3]);
* // => true
*
* _.isArrayLikeObject(document.body.children);
* // => true
*
* _.isArrayLikeObject('abc');
* // => false
*
* _.isArrayLikeObject(_.noop);
* // => false
*/
function isArrayLikeObject(value) {
return isObjectLike_1(value) && isArrayLike_1(value);
}
var isArrayLikeObject_1 = isArrayLikeObject;
/**
* Casts `value` to an empty array if it's not an array like object.
*
* @private
* @param {*} value The value to inspect.
* @returns {Array|Object} Returns the cast array-like object.
*/
function castArrayLikeObject(value) {
return isArrayLikeObject_1(value) ? value : [];
}
var _castArrayLikeObject = castArrayLikeObject;
/**
* Creates an array of unique values that are included in all given arrays
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons. The order and references of result values are
* determined by the first array.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of intersecting values.
* @example
*
* _.intersection([2, 1], [2, 3]);
* // => [2]
*/
var intersection = _baseRest(function(arrays) {
var mapped = _arrayMap(arrays, _castArrayLikeObject);
return (mapped.length && mapped[0] === arrays[0])
? _baseIntersection(mapped)
: [];
});
var intersection_1 = intersection;
/**
* Creates a base function for methods like `_.forIn` and `_.forOwn`.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseFor(fromRight) {
return function(object, iteratee, keysFunc) {
var index = -1,
iterable = Object(object),
props = keysFunc(object),
length = props.length;
while (length--) {
var key = props[fromRight ? length : ++index];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
};
}
var _createBaseFor = createBaseFor;
/**
* The base implementation of `baseForOwn` which iterates over `object`
* properties returned by `keysFunc` and invokes `iteratee` for each property.
* Iteratee functions may exit iteration early by explicitly returning `false`.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
var baseFor = _createBaseFor();
var _baseFor = baseFor;
/**
* The base implementation of `_.forOwn` without support for iteratee shorthands.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
*/
function baseForOwn(object, iteratee) {
return object && _baseFor(object, iteratee, keys_1);
}
var _baseForOwn = baseForOwn;
/**
* Casts `value` to `identity` if it's not a function.
*
* @private
* @param {*} value The value to inspect.
* @returns {Function} Returns cast function.
*/
function castFunction(value) {
return typeof value == 'function' ? value : identity_1;
}
var _castFunction = castFunction;
/**
* Iterates over own enumerable string keyed properties of an object and
* invokes `iteratee` for each property. The iteratee is invoked with three
* arguments: (value, key, object). Iteratee functions may exit iteration
* early by explicitly returning `false`.
*
* @static
* @memberOf _
* @since 0.3.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @returns {Object} Returns `object`.
* @see _.forOwnRight
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.forOwn(new Foo, function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forOwn(object, iteratee) {
return object && _baseForOwn(object, _castFunction(iteratee));
}
var forOwn_1 = forOwn;
/**
* A specialized version of `_.forEach` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`.
*/
function arrayEach(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (iteratee(array[index], index, array) === false) {
break;
}
}
return array;
}
var _arrayEach = arrayEach;
/**
* Creates a `baseEach` or `baseEachRight` function.
*
* @private
* @param {Function} eachFunc The function to iterate over a collection.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
if (collection == null) {
return collection;
}
if (!isArrayLike_1(collection)) {
return eachFunc(collection, iteratee);
}
var length = collection.length,
index = fromRight ? length : -1,
iterable = Object(collection);
while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
};
}
var _createBaseEach = createBaseEach;
/**
* The base implementation of `_.forEach` without support for iteratee shorthands.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object} Returns `collection`.
*/
var baseEach = _createBaseEach(_baseForOwn);
var _baseEach = baseEach;
/**
* Iterates over elements of `collection` and invokes `iteratee` for each element.
* The iteratee is invoked with three arguments: (value, index|key, collection).
* Iteratee functions may exit iteration early by explicitly returning `false`.
*
* **Note:** As with other "Collections" methods, objects with a "length"
* property are iterated like arrays. To avoid this behavior use `_.forIn`
* or `_.forOwn` for object iteration.
*
* @static
* @memberOf _
* @since 0.1.0
* @alias each
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @returns {Array|Object} Returns `collection`.
* @see _.forEachRight
* @example
*
* _.forEach([1, 2], function(value) {
* console.log(value);
* });
* // => Logs `1` then `2`.
*
* _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
* console.log(key);
* });
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forEach(collection, iteratee) {
var func = isArray_1(collection) ? _arrayEach : _baseEach;
return func(collection, _castFunction(iteratee));
}
var forEach_1 = forEach;
/**
* A specialized version of `_.filter` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function arrayFilter(array, predicate) {
var index = -1,
length = array == null ? 0 : array.length,
resIndex = 0,
result = [];
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result[resIndex++] = value;
}
}
return result;
}
var _arrayFilter = arrayFilter;
/**
* The base implementation of `_.filter` without support for iteratee shorthands.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function baseFilter(collection, predicate) {
var result = [];
_baseEach(collection, function(value, index, collection) {
if (predicate(value, index, collection)) {
result.push(value);
}
});
return result;
}
var _baseFilter = baseFilter;
/**
* Removes all key-value entries from the stack.
*
* @private
* @name clear
* @memberOf Stack
*/
function stackClear() {
this.__data__ = new _ListCache;
this.size = 0;
}
var _stackClear = stackClear;
/**
* Removes `key` and its value from the stack.
*
* @private
* @name delete
* @memberOf Stack
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function stackDelete(key) {
var data = this.__data__,
result = data['delete'](key);
this.size = data.size;
return result;
}
var _stackDelete = stackDelete;
/**
* Gets the stack value for `key`.
*
* @private
* @name get
* @memberOf Stack
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function stackGet(key) {
return this.__data__.get(key);
}
var _stackGet = stackGet;
/**
* Checks if a stack value for `key` exists.
*
* @private
* @name has
* @memberOf Stack
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function stackHas(key) {
return this.__data__.has(key);
}
var _stackHas = stackHas;
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/**
* Sets the stack `key` to `value`.
*
* @private
* @name set
* @memberOf Stack
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the stack cache instance.
*/
function stackSet(key, value) {
var data = this.__data__;
if (data instanceof _ListCache) {
var pairs = data.__data__;
if (!_Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
pairs.push([key, value]);
this.size = ++data.size;
return this;
}
data = this.__data__ = new _MapCache(pairs);
}
data.set(key, value);
this.size = data.size;
return this;
}
var _stackSet = stackSet;
/**
* Creates a stack cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Stack(entries) {
var data = this.__data__ = new _ListCache(entries);
this.size = data.size;
}
// Add methods to `Stack`.
Stack.prototype.clear = _stackClear;
Stack.prototype['delete'] = _stackDelete;
Stack.prototype.get = _stackGet;
Stack.prototype.has = _stackHas;
Stack.prototype.set = _stackSet;
var _Stack = Stack;
/**
* A specialized version of `_.some` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
*/
function arraySome(array, predicate) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (predicate(array[index], index, array)) {
return true;
}
}
return false;
}
var _arraySome = arraySome;
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG = 1,
COMPARE_UNORDERED_FLAG = 2;
/**
* A specialized version of `baseIsEqualDeep` for arrays with support for
* partial deep comparisons.
*
* @private
* @param {Array} array The array to compare.
* @param {Array} other The other array to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `array` and `other` objects.
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
*/
function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
arrLength = array.length,
othLength = other.length;
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(array);
if (stacked && stack.get(other)) {
return stacked == other;
}
var index = -1,
result = true,
seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new _SetCache : undefined;
stack.set(array, other);
stack.set(other, array);
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index],
othValue = other[index];
if (customizer) {
var compared = isPartial
? customizer(othValue, arrValue, index, other, array, stack)
: customizer(arrValue, othValue, index, array, other, stack);
}
if (compared !== undefined) {
if (compared) {
continue;
}
result = false;
break;
}
// Recursively compare arrays (susceptible to call stack limits).
if (seen) {
if (!_arraySome(other, function(othValue, othIndex) {
if (!_cacheHas(seen, othIndex) &&
(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
return seen.push(othIndex);
}
})) {
result = false;
break;
}
} else if (!(
arrValue === othValue ||
equalFunc(arrValue, othValue, bitmask, customizer, stack)
)) {
result = false;
break;
}
}
stack['delete'](array);
stack['delete'](other);
return result;
}
var _equalArrays = equalArrays;
/** Built-in value references. */
var Uint8Array = _root.Uint8Array;
var _Uint8Array = Uint8Array;
/**
* Converts `map` to its key-value pairs.
*
* @private
* @param {Object} map The map to convert.
* @returns {Array} Returns the key-value pairs.
*/
function mapToArray(map) {
var index = -1,
result = Array(map.size);
map.forEach(function(value, key) {
result[++index] = [key, value];
});
return result;
}
var _mapToArray = mapToArray;
/**
* Converts `set` to an array of its values.
*
* @private
* @param {Object} set The set to convert.
* @returns {Array} Returns the values.
*/
function setToArray(set) {
var index = -1,
result = Array(set.size);
set.forEach(function(value) {
result[++index] = value;
});
return result;
}
var _setToArray = setToArray;
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG$1 = 1,
COMPARE_UNORDERED_FLAG$1 = 2;
/** `Object#toString` result references. */
var boolTag$1 = '[object Boolean]',
dateTag$1 = '[object Date]',
errorTag$1 = '[object Error]',
mapTag$1 = '[object Map]',
numberTag$1 = '[object Number]',
regexpTag$1 = '[object RegExp]',
setTag$1 = '[object Set]',
stringTag$1 = '[object String]',
symbolTag = '[object Symbol]';
var arrayBufferTag$1 = '[object ArrayBuffer]',
dataViewTag$1 = '[object DataView]';
/** Used to convert symbols to primitives and strings. */
var symbolProto = _Symbol ? _Symbol.prototype : undefined,
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
/**
* A specialized version of `baseIsEqualDeep` for comparing objects of
* the same `toStringTag`.
*
* **Note:** This function only supports comparing values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {string} tag The `toStringTag` of the objects to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
switch (tag) {
case dataViewTag$1:
if ((object.byteLength != other.byteLength) ||
(object.byteOffset != other.byteOffset)) {
return false;
}
object = object.buffer;
other = other.buffer;
case arrayBufferTag$1:
if ((object.byteLength != other.byteLength) ||
!equalFunc(new _Uint8Array(object), new _Uint8Array(other))) {
return false;
}
return true;
case boolTag$1:
case dateTag$1:
case numberTag$1:
// Coerce booleans to `1` or `0` and dates to milliseconds.
// Invalid dates are coerced to `NaN`.
return eq_1(+object, +other);
case errorTag$1:
return object.name == other.name && object.message == other.message;
case regexpTag$1:
case stringTag$1:
// Coerce regexes to strings and treat strings, primitives and objects,
// as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
// for more details.
return object == (other + '');
case mapTag$1:
var convert = _mapToArray;
case setTag$1:
var isPartial = bitmask & COMPARE_PARTIAL_FLAG$1;
convert || (convert = _setToArray);
if (object.size != other.size && !isPartial) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked) {
return stacked == other;
}
bitmask |= COMPARE_UNORDERED_FLAG$1;
// Recursively compare objects (susceptible to call stack limits).
stack.set(object, other);
var result = _equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
stack['delete'](object);
return result;
case symbolTag:
if (symbolValueOf) {
return symbolValueOf.call(object) == symbolValueOf.call(other);
}
}
return false;
}
var _equalByTag = equalByTag;
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
}
var _arrayPush = arrayPush;
/**
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
* symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Function} keysFunc The function to get the keys of `object`.
* @param {Function} symbolsFunc The function to get the symbols of `object`.
* @returns {Array} Returns the array of property names and symbols.
*/
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
var result = keysFunc(object);
return isArray_1(object) ? result : _arrayPush(result, symbolsFunc(object));
}
var _baseGetAllKeys = baseGetAllKeys;
/**
* This method returns a new empty array.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {Array} Returns the new empty array.
* @example
*
* var arrays = _.times(2, _.stubArray);
*
* console.log(arrays);
* // => [[], []]
*
* console.log(arrays[0] === arrays[1]);
* // => false
*/
function stubArray() {
return [];
}
var stubArray_1 = stubArray;
/** Used for built-in method references. */
var objectProto$9 = Object.prototype;
/** Built-in value references. */
var propertyIsEnumerable$1 = objectProto$9.propertyIsEnumerable;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetSymbols = Object.getOwnPropertySymbols;
/**
* Creates an array of the own enumerable symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of symbols.
*/
var getSymbols = !nativeGetSymbols ? stubArray_1 : function(object) {
if (object == null) {
return [];
}
object = Object(object);
return _arrayFilter(nativeGetSymbols(object), function(symbol) {
return propertyIsEnumerable$1.call(object, symbol);
});
};
var _getSymbols = getSymbols;
/**
* Creates an array of own enumerable property names and symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names and symbols.
*/
function getAllKeys(object) {
return _baseGetAllKeys(object, keys_1, _getSymbols);
}
var _getAllKeys = getAllKeys;
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG$2 = 1;
/** Used for built-in method references. */
var objectProto$a = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$7 = objectProto$a.hasOwnProperty;
/**
* A specialized version of `baseIsEqualDeep` for objects with support for
* partial deep comparisons.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
var isPartial = bitmask & COMPARE_PARTIAL_FLAG$2,
objProps = _getAllKeys(object),
objLength = objProps.length,
othProps = _getAllKeys(other),
othLength = othProps.length;
if (objLength != othLength && !isPartial) {
return false;
}
var index = objLength;
while (index--) {
var key = objProps[index];
if (!(isPartial ? key in other : hasOwnProperty$7.call(other, key))) {
return false;
}
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked && stack.get(other)) {
return stacked == other;
}
var result = true;
stack.set(object, other);
stack.set(other, object);
var skipCtor = isPartial;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key];
if (customizer) {
var compared = isPartial
? customizer(othValue, objValue, key, other, object, stack)
: customizer(objValue, othValue, key, object, other, stack);
}
// Recursively compare objects (susceptible to call stack limits).
if (!(compared === undefined
? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
: compared
)) {
result = false;
break;
}
skipCtor || (skipCtor = key == 'constructor');
}
if (result && !skipCtor) {
var objCtor = object.constructor,
othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor &&
('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
result = false;
}
}
stack['delete'](object);
stack['delete'](other);
return result;
}
var _equalObjects = equalObjects;
/* Built-in method references that are verified to be native. */
var DataView = _getNative(_root, 'DataView');
var _DataView = DataView;
/* Built-in method references that are verified to be native. */
var Promise$1 = _getNative(_root, 'Promise');
var _Promise = Promise$1;
/* Built-in method references that are verified to be native. */
var Set = _getNative(_root, 'Set');
var _Set = Set;
/* Built-in method references that are verified to be native. */
var WeakMap$1 = _getNative(_root, 'WeakMap');
var _WeakMap = WeakMap$1;
/** `Object#toString` result references. */
var mapTag$2 = '[object Map]',
objectTag$1 = '[object Object]',
promiseTag = '[object Promise]',
setTag$2 = '[object Set]',
weakMapTag$1 = '[object WeakMap]';
var dataViewTag$2 = '[object DataView]';
/** Used to detect maps, sets, and weakmaps. */
var dataViewCtorString = _toSource(_DataView),
mapCtorString = _toSource(_Map),
promiseCtorString = _toSource(_Promise),
setCtorString = _toSource(_Set),
weakMapCtorString = _toSource(_WeakMap);
/**
* Gets the `toStringTag` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
var getTag = _baseGetTag;
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
if ((_DataView && getTag(new _DataView(new ArrayBuffer(1))) != dataViewTag$2) ||
(_Map && getTag(new _Map) != mapTag$2) ||
(_Promise && getTag(_Promise.resolve()) != promiseTag) ||
(_Set && getTag(new _Set) != setTag$2) ||
(_WeakMap && getTag(new _WeakMap) != weakMapTag$1)) {
getTag = function(value) {
var result = _baseGetTag(value),
Ctor = result == objectTag$1 ? value.constructor : undefined,
ctorString = Ctor ? _toSource(Ctor) : '';
if (ctorString) {
switch (ctorString) {
case dataViewCtorString: return dataViewTag$2;
case mapCtorString: return mapTag$2;
case promiseCtorString: return promiseTag;
case setCtorString: return setTag$2;
case weakMapCtorString: return weakMapTag$1;
}
}
return result;
};
}
var _getTag = getTag;
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG$3 = 1;
/** `Object#toString` result references. */
var argsTag$2 = '[object Arguments]',
arrayTag$1 = '[object Array]',
objectTag$2 = '[object Object]';
/** Used for built-in method references. */
var objectProto$b = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$8 = objectProto$b.hasOwnProperty;
/**
* A specialized version of `baseIsEqual` for arrays and objects which performs
* deep comparisons and tracks traversed objects enabling objects with circular
* references to be compared.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} [stack] Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
var objIsArr = isArray_1(object),
othIsArr = isArray_1(other),
objTag = objIsArr ? arrayTag$1 : _getTag(object),
othTag = othIsArr ? arrayTag$1 : _getTag(other);
objTag = objTag == argsTag$2 ? objectTag$2 : objTag;
othTag = othTag == argsTag$2 ? objectTag$2 : othTag;
var objIsObj = objTag == objectTag$2,
othIsObj = othTag == objectTag$2,
isSameTag = objTag == othTag;
if (isSameTag && isBuffer_1(object)) {
if (!isBuffer_1(other)) {
return false;
}
objIsArr = true;
objIsObj = false;
}
if (isSameTag && !objIsObj) {
stack || (stack = new _Stack);
return (objIsArr || isTypedArray_1(object))
? _equalArrays(object, other, bitmask, customizer, equalFunc, stack)
: _equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
}
if (!(bitmask & COMPARE_PARTIAL_FLAG$3)) {
var objIsWrapped = objIsObj && hasOwnProperty$8.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty$8.call(other, '__wrapped__');
if (objIsWrapped || othIsWrapped) {
var objUnwrapped = objIsWrapped ? object.value() : object,
othUnwrapped = othIsWrapped ? other.value() : other;
stack || (stack = new _Stack);
return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
}
}
if (!isSameTag) {
return false;
}
stack || (stack = new _Stack);
return _equalObjects(object, other, bitmask, customizer, equalFunc, stack);
}
var _baseIsEqualDeep = baseIsEqualDeep;
/**
* The base implementation of `_.isEqual` which supports partial comparisons
* and tracks traversed objects.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {boolean} bitmask The bitmask flags.
* 1 - Unordered comparison
* 2 - Partial comparison
* @param {Function} [customizer] The function to customize comparisons.
* @param {Object} [stack] Tracks traversed `value` and `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, bitmask, customizer, stack) {
if (value === other) {
return true;
}
if (value == null || other == null || (!isObjectLike_1(value) && !isObjectLike_1(other))) {
return value !== value && other !== other;
}
return _baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
}
var _baseIsEqual = baseIsEqual;
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG$4 = 1,
COMPARE_UNORDERED_FLAG$2 = 2;
/**
* The base implementation of `_.isMatch` without support for iteratee shorthands.
*
* @private
* @param {Object} object The object to inspect.
* @param {Object} source The object of property values to match.
* @param {Array} matchData The property names, values, and compare flags to match.
* @param {Function} [customizer] The function to customize comparisons.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, source, matchData, customizer) {
var index = matchData.length,
length = index,
noCustomizer = !customizer;
if (object == null) {
return !length;
}
object = Object(object);
while (index--) {
var data = matchData[index];
if ((noCustomizer && data[2])
? data[1] !== object[data[0]]
: !(data[0] in object)
) {
return false;
}
}
while (++index < length) {
data = matchData[index];
var key = data[0],
objValue = object[key],
srcValue = data[1];
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
} else {
var stack = new _Stack;
if (customizer) {
var result = customizer(objValue, srcValue, key, object, source, stack);
}
if (!(result === undefined
? _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$4 | COMPARE_UNORDERED_FLAG$2, customizer, stack)
: result
)) {
return false;
}
}
}
return true;
}
var _baseIsMatch = baseIsMatch;
/**
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` if suitable for strict
* equality comparisons, else `false`.
*/
function isStrictComparable(value) {
return value === value && !isObject_1(value);
}
var _isStrictComparable = isStrictComparable;
/**
* Gets the property names, values, and compare flags of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the match data of `object`.
*/
function getMatchData(object) {
var result = keys_1(object),
length = result.length;
while (length--) {
var key = result[length],
value = object[key];
result[length] = [key, value, _isStrictComparable(value)];
}
return result;
}
var _getMatchData = getMatchData;
/**
* A specialized version of `matchesProperty` for source values suitable
* for strict equality comparisons, i.e. `===`.
*
* @private
* @param {string} key The key of the property to get.
* @param {*} srcValue The value to match.
* @returns {Function} Returns the new spec function.
*/
function matchesStrictComparable(key, srcValue) {
return function(object) {
if (object == null) {
return false;
}
return object[key] === srcValue &&
(srcValue !== undefined || (key in Object(object)));
};
}
var _matchesStrictComparable = matchesStrictComparable;
/**
* The base implementation of `_.matches` which doesn't clone `source`.
*
* @private
* @param {Object} source The object of property values to match.
* @returns {Function} Returns the new spec function.
*/
function baseMatches(source) {
var matchData = _getMatchData(source);
if (matchData.length == 1 && matchData[0][2]) {
return _matchesStrictComparable(matchData[0][0], matchData[0][1]);
}
return function(object) {
return object === source || _baseIsMatch(object, source, matchData);
};
}
var _baseMatches = baseMatches;
/** `Object#toString` result references. */
var symbolTag$1 = '[object Symbol]';
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(isObjectLike_1(value) && _baseGetTag(value) == symbolTag$1);
}
var isSymbol_1 = isSymbol;
/** Used to match property names within property paths. */
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
reIsPlainProp = /^\w*$/;
/**
* Checks if `value` is a property name and not a property path.
*
* @private
* @param {*} value The value to check.
* @param {Object} [object] The object to query keys on.
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
*/
function isKey(value, object) {
if (isArray_1(value)) {
return false;
}
var type = typeof value;
if (type == 'number' || type == 'symbol' || type == 'boolean' ||
value == null || isSymbol_1(value)) {
return true;
}
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
(object != null && value in Object(object));
}
var _isKey = isKey;
/** Error message constants. */
var FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided, it determines the cache key for storing the result based on the
* arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is used as the map cache key. The `func`
* is invoked with the `this` binding of the memoized function.
*
* **Note:** The cache is exposed as the `cache` property on the memoized
* function. Its creation may be customized by replacing the `_.memoize.Cache`
* constructor with one whose instances implement the
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
* method interface of `clear`, `delete`, `get`, `has`, and `set`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to have its output memoized.
* @param {Function} [resolver] The function to resolve the cache key.
* @returns {Function} Returns the new memoized function.
* @example
*
* var object = { 'a': 1, 'b': 2 };
* var other = { 'c': 3, 'd': 4 };
*
* var values = _.memoize(_.values);
* values(object);
* // => [1, 2]
*
* values(other);
* // => [3, 4]
*
* object.a = 2;
* values(object);
* // => [1, 2]
*
* // Modify the result cache.
* values.cache.set(object, ['a', 'b']);
* values(object);
* // => ['a', 'b']
*
* // Replace `_.memoize.Cache`.
* _.memoize.Cache = WeakMap;
*/
function memoize(func, resolver) {
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
var args = arguments,
key = resolver ? resolver.apply(this, args) : args[0],
cache = memoized.cache;
if (cache.has(key)) {
return cache.get(key);
}
var result = func.apply(this, args);
memoized.cache = cache.set(key, result) || cache;
return result;
};
memoized.cache = new (memoize.Cache || _MapCache);
return memoized;
}
// Expose `MapCache`.
memoize.Cache = _MapCache;
var memoize_1 = memoize;
/** Used as the maximum memoize cache size. */
var MAX_MEMOIZE_SIZE = 500;
/**
* A specialized version of `_.memoize` which clears the memoized function's
* cache when it exceeds `MAX_MEMOIZE_SIZE`.
*
* @private
* @param {Function} func The function to have its output memoized.
* @returns {Function} Returns the new memoized function.
*/
function memoizeCapped(func) {
var result = memoize_1(func, function(key) {
if (cache.size === MAX_MEMOIZE_SIZE) {
cache.clear();
}
return key;
});
var cache = result.cache;
return result;
}
var _memoizeCapped = memoizeCapped;
/** Used to match property names within property paths. */
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
/** Used to match backslashes in property paths. */
var reEscapeChar = /\\(\\)?/g;
/**
* Converts `string` to a property path array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the property path array.
*/
var stringToPath = _memoizeCapped(function(string) {
var result = [];
if (string.charCodeAt(0) === 46 /* . */) {
result.push('');
}
string.replace(rePropName, function(match, number, quote, subString) {
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
});
return result;
});
var _stringToPath = stringToPath;
/** Used as references for various `Number` constants. */
var INFINITY = 1 / 0;
/** Used to convert symbols to primitives and strings. */
var symbolProto$1 = _Symbol ? _Symbol.prototype : undefined,
symbolToString = symbolProto$1 ? symbolProto$1.toString : undefined;
/**
* The base implementation of `_.toString` which doesn't convert nullish
* values to empty strings.
*
* @private
* @param {*} value The value to process.
* @returns {string} Returns the string.
*/
function baseToString(value) {
// Exit early for strings to avoid a performance hit in some environments.
if (typeof value == 'string') {
return value;
}
if (isArray_1(value)) {
// Recursively convert values (susceptible to call stack limits).
return _arrayMap(value, baseToString) + '';
}
if (isSymbol_1(value)) {
return symbolToString ? symbolToString.call(value) : '';
}
var result = (value + '');
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
}
var _baseToString = baseToString;
/**
* Converts `value` to a string. An empty string is returned for `null`
* and `undefined` values. The sign of `-0` is preserved.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
* @example
*
* _.toString(null);
* // => ''
*
* _.toString(-0);
* // => '-0'
*
* _.toString([1, 2, 3]);
* // => '1,2,3'
*/
function toString(value) {
return value == null ? '' : _baseToString(value);
}
var toString_1 = toString;
/**
* Casts `value` to a path array if it's not one.
*
* @private
* @param {*} value The value to inspect.
* @param {Object} [object] The object to query keys on.
* @returns {Array} Returns the cast property path array.
*/
function castPath(value, object) {
if (isArray_1(value)) {
return value;
}
return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
}
var _castPath = castPath;
/** Used as references for various `Number` constants. */
var INFINITY$1 = 1 / 0;
/**
* Converts `value` to a string key if it's not a string or symbol.
*
* @private
* @param {*} value The value to inspect.
* @returns {string|symbol} Returns the key.
*/
function toKey(value) {
if (typeof value == 'string' || isSymbol_1(value)) {
return value;
}
var result = (value + '');
return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
}
var _toKey = toKey;
/**
* The base implementation of `_.get` without support for default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @returns {*} Returns the resolved value.
*/
function baseGet(object, path) {
path = _castPath(path, object);
var index = 0,
length = path.length;
while (object != null && index < length) {
object = object[_toKey(path[index++])];
}
return (index && index == length) ? object : undefined;
}
var _baseGet = baseGet;
/**
* Gets the value at `path` of `object`. If the resolved value is
* `undefined`, the `defaultValue` is returned in its place.
*
* @static
* @memberOf _
* @since 3.7.0
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
function get(object, path, defaultValue) {
var result = object == null ? undefined : _baseGet(object, path);
return result === undefined ? defaultValue : result;
}
var get_1 = get;
/**
* The base implementation of `_.hasIn` without support for deep paths.
*
* @private
* @param {Object} [object] The object to query.
* @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHasIn(object, key) {
return object != null && key in Object(object);
}
var _baseHasIn = baseHasIn;
/**
* Checks if `path` exists on `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @param {Function} hasFunc The function to check properties.
* @returns {boolean} Returns `true` if `path` exists, else `false`.
*/
function hasPath(object, path, hasFunc) {
path = _castPath(path, object);
var index = -1,
length = path.length,
result = false;
while (++index < length) {
var key = _toKey(path[index]);
if (!(result = object != null && hasFunc(object, key))) {
break;
}
object = object[key];
}
if (result || ++index != length) {
return result;
}
length = object == null ? 0 : object.length;
return !!length && isLength_1(length) && _isIndex(key, length) &&
(isArray_1(object) || isArguments_1(object));
}
var _hasPath = hasPath;
/**
* Checks if `path` is a direct or inherited property of `object`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `path` exists, else `false`.
* @example
*
* var object = _.create({ 'a': _.create({ 'b': 2 }) });
*
* _.hasIn(object, 'a');
* // => true
*
* _.hasIn(object, 'a.b');
* // => true
*
* _.hasIn(object, ['a', 'b']);
* // => true
*
* _.hasIn(object, 'b');
* // => false
*/
function hasIn(object, path) {
return object != null && _hasPath(object, path, _baseHasIn);
}
var hasIn_1 = hasIn;
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG$5 = 1,
COMPARE_UNORDERED_FLAG$3 = 2;
/**
* The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
*
* @private
* @param {string} path The path of the property to get.
* @param {*} srcValue The value to match.
* @returns {Function} Returns the new spec function.
*/
function baseMatchesProperty(path, srcValue) {
if (_isKey(path) && _isStrictComparable(srcValue)) {
return _matchesStrictComparable(_toKey(path), srcValue);
}
return function(object) {
var objValue = get_1(object, path);
return (objValue === undefined && objValue === srcValue)
? hasIn_1(object, path)
: _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$5 | COMPARE_UNORDERED_FLAG$3);
};
}
var _baseMatchesProperty = baseMatchesProperty;
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new accessor function.
*/
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
var _baseProperty = baseProperty;
/**
* A specialized version of `baseProperty` which supports deep paths.
*
* @private
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new accessor function.
*/
function basePropertyDeep(path) {
return function(object) {
return _baseGet(object, path);
};
}
var _basePropertyDeep = basePropertyDeep;
/**
* Creates a function that returns the value at `path` of a given object.
*
* @static
* @memberOf _
* @since 2.4.0
* @category Util
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new accessor function.
* @example
*
* var objects = [
* { 'a': { 'b': 2 } },
* { 'a': { 'b': 1 } }
* ];
*
* _.map(objects, _.property('a.b'));
* // => [2, 1]
*
* _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
* // => [1, 2]
*/
function property(path) {
return _isKey(path) ? _baseProperty(_toKey(path)) : _basePropertyDeep(path);
}
var property_1 = property;
/**
* The base implementation of `_.iteratee`.
*
* @private
* @param {*} [value=_.identity] The value to convert to an iteratee.
* @returns {Function} Returns the iteratee.
*/
function baseIteratee(value) {
// Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
// See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
if (typeof value == 'function') {
return value;
}
if (value == null) {
return identity_1;
}
if (typeof value == 'object') {
return isArray_1(value)
? _baseMatchesProperty(value[0], value[1])
: _baseMatches(value);
}
return property_1(value);
}
var _baseIteratee = baseIteratee;
/**
* Iterates over elements of `collection`, returning an array of all elements
* `predicate` returns truthy for. The predicate is invoked with three
* arguments: (value, index|key, collection).
*
* **Note:** Unlike `_.remove`, this method returns a new array.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
* @see _.reject
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* _.filter(users, function(o) { return !o.active; });
* // => objects for ['fred']
*
* // The `_.matches` iteratee shorthand.
* _.filter(users, { 'age': 36, 'active': true });
* // => objects for ['barney']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.filter(users, ['active', false]);
* // => objects for ['fred']
*
* // The `_.property` iteratee shorthand.
* _.filter(users, 'active');
* // => objects for ['barney']
*/
function filter(collection, predicate) {
var func = isArray_1(collection) ? _arrayFilter : _baseFilter;
return func(collection, _baseIteratee(predicate, 3));
}
var filter_1 = filter;
/**
* The base implementation of `_.map` without support for iteratee shorthands.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function baseMap(collection, iteratee) {
var index = -1,
result = isArrayLike_1(collection) ? Array(collection.length) : [];
_baseEach(collection, function(value, key, collection) {
result[++index] = iteratee(value, key, collection);
});
return result;
}
var _baseMap = baseMap;
/**
* Creates an array of values by running each element in `collection` thru
* `iteratee`. The iteratee is invoked with three arguments:
* (value, index|key, collection).
*
* Many lodash methods are guarded to work as iteratees for methods like
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
*
* The guarded methods are:
* `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
* `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
* `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
* `template`, `trim`, `trimEnd`, `trimStart`, and `words`
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
* @example
*
* function square(n) {
* return n * n;
* }
*
* _.map([4, 8], square);
* // => [16, 64]
*
* _.map({ 'a': 4, 'b': 8 }, square);
* // => [16, 64] (iteration order is not guaranteed)
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* // The `_.property` iteratee shorthand.
* _.map(users, 'user');
* // => ['barney', 'fred']
*/
function map(collection, iteratee) {
var func = isArray_1(collection) ? _arrayMap : _baseMap;
return func(collection, _baseIteratee(iteratee, 3));
}
var map_1 = map;
/**
* A specialized version of `_.reduce` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initAccum] Specify using the first element of `array` as
* the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduce(array, iteratee, accumulator, initAccum) {
var index = -1,
length = array == null ? 0 : array.length;
if (initAccum && length) {
accumulator = array[++index];
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array);
}
return accumulator;
}
var _arrayReduce = arrayReduce;
/**
* The base implementation of `_.reduce` and `_.reduceRight`, without support
* for iteratee shorthands, which iterates over `collection` using `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} accumulator The initial value.
* @param {boolean} initAccum Specify using the first or last element of
* `collection` as the initial value.
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the accumulated value.
*/
function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
eachFunc(collection, function(value, index, collection) {
accumulator = initAccum
? (initAccum = false, value)
: iteratee(accumulator, value, index, collection);
});
return accumulator;
}
var _baseReduce = baseReduce;
/**
* Reduces `collection` to a value which is the accumulated result of running
* each element in `collection` thru `iteratee`, where each successive
* invocation is supplied the return value of the previous. If `accumulator`
* is not given, the first element of `collection` is used as the initial
* value. The iteratee is invoked with four arguments:
* (accumulator, value, index|key, collection).
*
* Many lodash methods are guarded to work as iteratees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
* and `sortBy`
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @returns {*} Returns the accumulated value.
* @see _.reduceRight
* @example
*
* _.reduce([1, 2], function(sum, n) {
* return sum + n;
* }, 0);
* // => 3
*
* _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
* (result[value] || (result[value] = [])).push(key);
* return result;
* }, {});
* // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
*/
function reduce(collection, iteratee, accumulator) {
var func = isArray_1(collection) ? _arrayReduce : _baseReduce,
initAccum = arguments.length < 3;
return func(collection, _baseIteratee(iteratee, 4), accumulator, initAccum, _baseEach);
}
var reduce_1 = reduce;
/**
* The base implementation of `assignValue` and `assignMergeValue` without
* value checks.
*
* @private
* @param {Object} object The object to modify.
* @param {string} key The key of the property to assign.
* @param {*} value The value to assign.
*/
function baseAssignValue(object, key, value) {
if (key == '__proto__' && _defineProperty$1) {
_defineProperty$1(object, key, {
'configurable': true,
'enumerable': true,
'value': value,
'writable': true
});
} else {
object[key] = value;
}
}
var _baseAssignValue = baseAssignValue;
/** Used for built-in method references. */
var objectProto$c = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$9 = objectProto$c.hasOwnProperty;
/**
* Assigns `value` to `key` of `object` if the existing value is not equivalent
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons.
*
* @private
* @param {Object} object The object to modify.
* @param {string} key The key of the property to assign.
* @param {*} value The value to assign.
*/
function assignValue(object, key, value) {
var objValue = object[key];
if (!(hasOwnProperty$9.call(object, key) && eq_1(objValue, value)) ||
(value === undefined && !(key in object))) {
_baseAssignValue(object, key, value);
}
}
var _assignValue = assignValue;
/**
* Copies properties of `source` to `object`.
*
* @private
* @param {Object} source The object to copy properties from.
* @param {Array} props The property identifiers to copy.
* @param {Object} [object={}] The object to copy properties to.
* @param {Function} [customizer] The function to customize copied values.
* @returns {Object} Returns `object`.
*/
function copyObject(source, props, object, customizer) {
var isNew = !object;
object || (object = {});
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index];
var newValue = customizer
? customizer(object[key], source[key], key, object, source)
: undefined;
if (newValue === undefined) {
newValue = source[key];
}
if (isNew) {
_baseAssignValue(object, key, newValue);
} else {
_assignValue(object, key, newValue);
}
}
return object;
}
var _copyObject = copyObject;
/**
* The base implementation of `_.assign` without support for multiple sources
* or `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @returns {Object} Returns `object`.
*/
function baseAssign(object, source) {
return object && _copyObject(source, keys_1(source), object);
}
var _baseAssign = baseAssign;
/**
* This function is like
* [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
* except that it includes inherited enumerable properties.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function nativeKeysIn(object) {
var result = [];
if (object != null) {
for (var key in Object(object)) {
result.push(key);
}
}
return result;
}
var _nativeKeysIn = nativeKeysIn;
/** Used for built-in method references. */
var objectProto$d = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$a = objectProto$d.hasOwnProperty;
/**
* The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeysIn(object) {
if (!isObject_1(object)) {
return _nativeKeysIn(object);
}
var isProto = _isPrototype(object),
result = [];
for (var key in object) {
if (!(key == 'constructor' && (isProto || !hasOwnProperty$a.call(object, key)))) {
result.push(key);
}
}
return result;
}
var _baseKeysIn = baseKeysIn;
/**
* Creates an array of the own and inherited enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @memberOf _
* @since 3.0.0
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keysIn(new Foo);
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
*/
function keysIn$1(object) {
return isArrayLike_1(object) ? _arrayLikeKeys(object, true) : _baseKeysIn(object);
}
var keysIn_1 = keysIn$1;
/**
* The base implementation of `_.assignIn` without support for multiple sources
* or `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @returns {Object} Returns `object`.
*/
function baseAssignIn(object, source) {
return object && _copyObject(source, keysIn_1(source), object);
}
var _baseAssignIn = baseAssignIn;
var _cloneBuffer = createCommonjsModule(function (module, exports) {
/** Detect free variable `exports`. */
var freeExports = exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Built-in value references. */
var Buffer = moduleExports ? _root.Buffer : undefined,
allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
/**
* Creates a clone of `buffer`.
*
* @private
* @param {Buffer} buffer The buffer to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Buffer} Returns the cloned buffer.
*/
function cloneBuffer(buffer, isDeep) {
if (isDeep) {
return buffer.slice();
}
var length = buffer.length,
result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
buffer.copy(result);
return result;
}
module.exports = cloneBuffer;
});
/**
* Copies the values of `source` to `array`.
*
* @private
* @param {Array} source The array to copy values from.
* @param {Array} [array=[]] The array to copy values to.
* @returns {Array} Returns `array`.
*/
function copyArray(source, array) {
var index = -1,
length = source.length;
array || (array = Array(length));
while (++index < length) {
array[index] = source[index];
}
return array;
}
var _copyArray = copyArray;
/**
* Copies own symbols of `source` to `object`.
*
* @private
* @param {Object} source The object to copy symbols from.
* @param {Object} [object={}] The object to copy symbols to.
* @returns {Object} Returns `object`.
*/
function copySymbols(source, object) {
return _copyObject(source, _getSymbols(source), object);
}
var _copySymbols = copySymbols;
/** Built-in value references. */
var getPrototype = _overArg(Object.getPrototypeOf, Object);
var _getPrototype = getPrototype;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetSymbols$1 = Object.getOwnPropertySymbols;
/**
* Creates an array of the own and inherited enumerable symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of symbols.
*/
var getSymbolsIn = !nativeGetSymbols$1 ? stubArray_1 : function(object) {
var result = [];
while (object) {
_arrayPush(result, _getSymbols(object));
object = _getPrototype(object);
}
return result;
};
var _getSymbolsIn = getSymbolsIn;
/**
* Copies own and inherited symbols of `source` to `object`.
*
* @private
* @param {Object} source The object to copy symbols from.
* @param {Object} [object={}] The object to copy symbols to.
* @returns {Object} Returns `object`.
*/
function copySymbolsIn(source, object) {
return _copyObject(source, _getSymbolsIn(source), object);
}
var _copySymbolsIn = copySymbolsIn;
/**
* Creates an array of own and inherited enumerable property names and
* symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names and symbols.
*/
function getAllKeysIn(object) {
return _baseGetAllKeys(object, keysIn_1, _getSymbolsIn);
}
var _getAllKeysIn = getAllKeysIn;
/** Used for built-in method references. */
var objectProto$e = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$b = objectProto$e.hasOwnProperty;
/**
* Initializes an array clone.
*
* @private
* @param {Array} array The array to clone.
* @returns {Array} Returns the initialized clone.
*/
function initCloneArray(array) {
var length = array.length,
result = new array.constructor(length);
// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty$b.call(array, 'index')) {
result.index = array.index;
result.input = array.input;
}
return result;
}
var _initCloneArray = initCloneArray;
/**
* Creates a clone of `arrayBuffer`.
*
* @private
* @param {ArrayBuffer} arrayBuffer The array buffer to clone.
* @returns {ArrayBuffer} Returns the cloned array buffer.
*/
function cloneArrayBuffer(arrayBuffer) {
var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
new _Uint8Array(result).set(new _Uint8Array(arrayBuffer));
return result;
}
var _cloneArrayBuffer = cloneArrayBuffer;
/**
* Creates a clone of `dataView`.
*
* @private
* @param {Object} dataView The data view to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the cloned data view.
*/
function cloneDataView(dataView, isDeep) {
var buffer = isDeep ? _cloneArrayBuffer(dataView.buffer) : dataView.buffer;
return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
}
var _cloneDataView = cloneDataView;
/** Used to match `RegExp` flags from their coerced string values. */
var reFlags = /\w*$/;
/**
* Creates a clone of `regexp`.
*
* @private
* @param {Object} regexp The regexp to clone.
* @returns {Object} Returns the cloned regexp.
*/
function cloneRegExp(regexp) {
var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
result.lastIndex = regexp.lastIndex;
return result;
}
var _cloneRegExp = cloneRegExp;
/** Used to convert symbols to primitives and strings. */
var symbolProto$2 = _Symbol ? _Symbol.prototype : undefined,
symbolValueOf$1 = symbolProto$2 ? symbolProto$2.valueOf : undefined;
/**
* Creates a clone of the `symbol` object.
*
* @private
* @param {Object} symbol The symbol object to clone.
* @returns {Object} Returns the cloned symbol object.
*/
function cloneSymbol(symbol) {
return symbolValueOf$1 ? Object(symbolValueOf$1.call(symbol)) : {};
}
var _cloneSymbol = cloneSymbol;
/**
* Creates a clone of `typedArray`.
*
* @private
* @param {Object} typedArray The typed array to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the cloned typed array.
*/
function cloneTypedArray(typedArray, isDeep) {
var buffer = isDeep ? _cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
}
var _cloneTypedArray = cloneTypedArray;
/** `Object#toString` result references. */
var boolTag$2 = '[object Boolean]',
dateTag$2 = '[object Date]',
mapTag$3 = '[object Map]',
numberTag$2 = '[object Number]',
regexpTag$2 = '[object RegExp]',
setTag$3 = '[object Set]',
stringTag$2 = '[object String]',
symbolTag$2 = '[object Symbol]';
var arrayBufferTag$2 = '[object ArrayBuffer]',
dataViewTag$3 = '[object DataView]',
float32Tag$1 = '[object Float32Array]',
float64Tag$1 = '[object Float64Array]',
int8Tag$1 = '[object Int8Array]',
int16Tag$1 = '[object Int16Array]',
int32Tag$1 = '[object Int32Array]',
uint8Tag$1 = '[object Uint8Array]',
uint8ClampedTag$1 = '[object Uint8ClampedArray]',
uint16Tag$1 = '[object Uint16Array]',
uint32Tag$1 = '[object Uint32Array]';
/**
* Initializes an object clone based on its `toStringTag`.
*
* **Note:** This function only supports cloning values with tags of
* `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
*
* @private
* @param {Object} object The object to clone.
* @param {string} tag The `toStringTag` of the object to clone.
* @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the initialized clone.
*/
function initCloneByTag(object, tag, isDeep) {
var Ctor = object.constructor;
switch (tag) {
case arrayBufferTag$2:
return _cloneArrayBuffer(object);
case boolTag$2:
case dateTag$2:
return new Ctor(+object);
case dataViewTag$3:
return _cloneDataView(object, isDeep);
case float32Tag$1: case float64Tag$1:
case int8Tag$1: case int16Tag$1: case int32Tag$1:
case uint8Tag$1: case uint8ClampedTag$1: case uint16Tag$1: case uint32Tag$1:
return _cloneTypedArray(object, isDeep);
case mapTag$3:
return new Ctor;
case numberTag$2:
case stringTag$2:
return new Ctor(object);
case regexpTag$2:
return _cloneRegExp(object);
case setTag$3:
return new Ctor;
case symbolTag$2:
return _cloneSymbol(object);
}
}
var _initCloneByTag = initCloneByTag;
/** Built-in value references. */
var objectCreate = Object.create;
/**
* The base implementation of `_.create` without support for assigning
* properties to the created object.
*
* @private
* @param {Object} proto The object to inherit from.
* @returns {Object} Returns the new object.
*/
var baseCreate = (function() {
function object() {}
return function(proto) {
if (!isObject_1(proto)) {
return {};
}
if (objectCreate) {
return objectCreate(proto);
}
object.prototype = proto;
var result = new object;
object.prototype = undefined;
return result;
};
}());
var _baseCreate = baseCreate;
/**
* Initializes an object clone.
*
* @private
* @param {Object} object The object to clone.
* @returns {Object} Returns the initialized clone.
*/
function initCloneObject(object) {
return (typeof object.constructor == 'function' && !_isPrototype(object))
? _baseCreate(_getPrototype(object))
: {};
}
var _initCloneObject = initCloneObject;
/** `Object#toString` result references. */
var mapTag$4 = '[object Map]';
/**
* The base implementation of `_.isMap` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a map, else `false`.
*/
function baseIsMap(value) {
return isObjectLike_1(value) && _getTag(value) == mapTag$4;
}
var _baseIsMap = baseIsMap;
/* Node.js helper references. */
var nodeIsMap = _nodeUtil && _nodeUtil.isMap;
/**
* Checks if `value` is classified as a `Map` object.
*
* @static
* @memberOf _
* @since 4.3.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a map, else `false`.
* @example
*
* _.isMap(new Map);
* // => true
*
* _.isMap(new WeakMap);
* // => false
*/
var isMap = nodeIsMap ? _baseUnary(nodeIsMap) : _baseIsMap;
var isMap_1 = isMap;
/** `Object#toString` result references. */
var setTag$4 = '[object Set]';
/**
* The base implementation of `_.isSet` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a set, else `false`.
*/
function baseIsSet(value) {
return isObjectLike_1(value) && _getTag(value) == setTag$4;
}
var _baseIsSet = baseIsSet;
/* Node.js helper references. */
var nodeIsSet = _nodeUtil && _nodeUtil.isSet;
/**
* Checks if `value` is classified as a `Set` object.
*
* @static
* @memberOf _
* @since 4.3.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a set, else `false`.
* @example
*
* _.isSet(new Set);
* // => true
*
* _.isSet(new WeakSet);
* // => false
*/
var isSet = nodeIsSet ? _baseUnary(nodeIsSet) : _baseIsSet;
var isSet_1 = isSet;
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1,
CLONE_FLAT_FLAG = 2,
CLONE_SYMBOLS_FLAG = 4;
/** `Object#toString` result references. */
var argsTag$3 = '[object Arguments]',
arrayTag$2 = '[object Array]',
boolTag$3 = '[object Boolean]',
dateTag$3 = '[object Date]',
errorTag$2 = '[object Error]',
funcTag$2 = '[object Function]',
genTag$1 = '[object GeneratorFunction]',
mapTag$5 = '[object Map]',
numberTag$3 = '[object Number]',
objectTag$3 = '[object Object]',
regexpTag$3 = '[object RegExp]',
setTag$5 = '[object Set]',
stringTag$3 = '[object String]',
symbolTag$3 = '[object Symbol]',
weakMapTag$2 = '[object WeakMap]';
var arrayBufferTag$3 = '[object ArrayBuffer]',
dataViewTag$4 = '[object DataView]',
float32Tag$2 = '[object Float32Array]',
float64Tag$2 = '[object Float64Array]',
int8Tag$2 = '[object Int8Array]',
int16Tag$2 = '[object Int16Array]',
int32Tag$2 = '[object Int32Array]',
uint8Tag$2 = '[object Uint8Array]',
uint8ClampedTag$2 = '[object Uint8ClampedArray]',
uint16Tag$2 = '[object Uint16Array]',
uint32Tag$2 = '[object Uint32Array]';
/** Used to identify `toStringTag` values supported by `_.clone`. */
var cloneableTags = {};
cloneableTags[argsTag$3] = cloneableTags[arrayTag$2] =
cloneableTags[arrayBufferTag$3] = cloneableTags[dataViewTag$4] =
cloneableTags[boolTag$3] = cloneableTags[dateTag$3] =
cloneableTags[float32Tag$2] = cloneableTags[float64Tag$2] =
cloneableTags[int8Tag$2] = cloneableTags[int16Tag$2] =
cloneableTags[int32Tag$2] = cloneableTags[mapTag$5] =
cloneableTags[numberTag$3] = cloneableTags[objectTag$3] =
cloneableTags[regexpTag$3] = cloneableTags[setTag$5] =
cloneableTags[stringTag$3] = cloneableTags[symbolTag$3] =
cloneableTags[uint8Tag$2] = cloneableTags[uint8ClampedTag$2] =
cloneableTags[uint16Tag$2] = cloneableTags[uint32Tag$2] = true;
cloneableTags[errorTag$2] = cloneableTags[funcTag$2] =
cloneableTags[weakMapTag$2] = false;
/**
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
* traversed objects.
*
* @private
* @param {*} value The value to clone.
* @param {boolean} bitmask The bitmask flags.
* 1 - Deep clone
* 2 - Flatten inherited properties
* 4 - Clone symbols
* @param {Function} [customizer] The function to customize cloning.
* @param {string} [key] The key of `value`.
* @param {Object} [object] The parent object of `value`.
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
* @returns {*} Returns the cloned value.
*/
function baseClone(value, bitmask, customizer, key, object, stack) {
var result,
isDeep = bitmask & CLONE_DEEP_FLAG,
isFlat = bitmask & CLONE_FLAT_FLAG,
isFull = bitmask & CLONE_SYMBOLS_FLAG;
if (customizer) {
result = object ? customizer(value, key, object, stack) : customizer(value);
}
if (result !== undefined) {
return result;
}
if (!isObject_1(value)) {
return value;
}
var isArr = isArray_1(value);
if (isArr) {
result = _initCloneArray(value);
if (!isDeep) {
return _copyArray(value, result);
}
} else {
var tag = _getTag(value),
isFunc = tag == funcTag$2 || tag == genTag$1;
if (isBuffer_1(value)) {
return _cloneBuffer(value, isDeep);
}
if (tag == objectTag$3 || tag == argsTag$3 || (isFunc && !object)) {
result = (isFlat || isFunc) ? {} : _initCloneObject(value);
if (!isDeep) {
return isFlat
? _copySymbolsIn(value, _baseAssignIn(result, value))
: _copySymbols(value, _baseAssign(result, value));
}
} else {
if (!cloneableTags[tag]) {
return object ? value : {};
}
result = _initCloneByTag(value, tag, isDeep);
}
}
// Check for circular references and return its corresponding clone.
stack || (stack = new _Stack);
var stacked = stack.get(value);
if (stacked) {
return stacked;
}
stack.set(value, result);
if (isSet_1(value)) {
value.forEach(function(subValue) {
result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
});
return result;
}
if (isMap_1(value)) {
value.forEach(function(subValue, key) {
result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
});
return result;
}
var keysFunc = isFull
? (isFlat ? _getAllKeysIn : _getAllKeys)
: (isFlat ? keysIn : keys_1);
var props = isArr ? undefined : keysFunc(value);
_arrayEach(props || value, function(subValue, key) {
if (props) {
key = subValue;
subValue = value[key];
}
// Recursively populate clone (susceptible to call stack limits).
_assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
});
return result;
}
var _baseClone = baseClone;
/**
* Gets the last element of `array`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to query.
* @returns {*} Returns the last element of `array`.
* @example
*
* _.last([1, 2, 3]);
* // => 3
*/
function last(array) {
var length = array == null ? 0 : array.length;
return length ? array[length - 1] : undefined;
}
var last_1 = last;
/**
* The base implementation of `_.slice` without an iteratee call guard.
*
* @private
* @param {Array} array The array to slice.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the slice of `array`.
*/
function baseSlice(array, start, end) {
var index = -1,
length = array.length;
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = end > length ? length : end;
if (end < 0) {
end += length;
}
length = start > end ? 0 : ((end - start) >>> 0);
start >>>= 0;
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
}
var _baseSlice = baseSlice;
/**
* Gets the parent value at `path` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} path The path to get the parent value of.
* @returns {*} Returns the parent value.
*/
function parent(object, path) {
return path.length < 2 ? object : _baseGet(object, _baseSlice(path, 0, -1));
}
var _parent = parent;
/**
* The base implementation of `_.unset`.
*
* @private
* @param {Object} object The object to modify.
* @param {Array|string} path The property path to unset.
* @returns {boolean} Returns `true` if the property is deleted, else `false`.
*/
function baseUnset(object, path) {
path = _castPath(path, object);
object = _parent(object, path);
return object == null || delete object[_toKey(last_1(path))];
}
var _baseUnset = baseUnset;
/** `Object#toString` result references. */
var objectTag$4 = '[object Object]';
/** Used for built-in method references. */
var funcProto$2 = Function.prototype,
objectProto$f = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString$2 = funcProto$2.toString;
/** Used to check objects for own properties. */
var hasOwnProperty$c = objectProto$f.hasOwnProperty;
/** Used to infer the `Object` constructor. */
var objectCtorString = funcToString$2.call(Object);
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @static
* @memberOf _
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
function isPlainObject(value) {
if (!isObjectLike_1(value) || _baseGetTag(value) != objectTag$4) {
return false;
}
var proto = _getPrototype(value);
if (proto === null) {
return true;
}
var Ctor = hasOwnProperty$c.call(proto, 'constructor') && proto.constructor;
return typeof Ctor == 'function' && Ctor instanceof Ctor &&
funcToString$2.call(Ctor) == objectCtorString;
}
var isPlainObject_1 = isPlainObject;
/**
* Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
* objects.
*
* @private
* @param {*} value The value to inspect.
* @param {string} key The key of the property to inspect.
* @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
*/
function customOmitClone(value) {
return isPlainObject_1(value) ? undefined : value;
}
var _customOmitClone = customOmitClone;
/** Built-in value references. */
var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
/**
* Checks if `value` is a flattenable `arguments` object or array.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
*/
function isFlattenable(value) {
return isArray_1(value) || isArguments_1(value) ||
!!(spreadableSymbol && value && value[spreadableSymbol]);
}
var _isFlattenable = isFlattenable;
/**
* The base implementation of `_.flatten` with support for restricting flattening.
*
* @private
* @param {Array} array The array to flatten.
* @param {number} depth The maximum recursion depth.
* @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
* @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
* @param {Array} [result=[]] The initial result value.
* @returns {Array} Returns the new flattened array.
*/
function baseFlatten(array, depth, predicate, isStrict, result) {
var index = -1,
length = array.length;
predicate || (predicate = _isFlattenable);
result || (result = []);
while (++index < length) {
var value = array[index];
if (depth > 0 && predicate(value)) {
if (depth > 1) {
// Recursively flatten arrays (susceptible to call stack limits).
baseFlatten(value, depth - 1, predicate, isStrict, result);
} else {
_arrayPush(result, value);
}
} else if (!isStrict) {
result[result.length] = value;
}
}
return result;
}
var _baseFlatten = baseFlatten;
/**
* Flattens `array` a single level deep.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to flatten.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flatten([1, [2, [3, [4]], 5]]);
* // => [1, 2, [3, [4]], 5]
*/
function flatten(array) {
var length = array == null ? 0 : array.length;
return length ? _baseFlatten(array, 1) : [];
}
var flatten_1 = flatten;
/**
* A specialized version of `baseRest` which flattens the rest array.
*
* @private
* @param {Function} func The function to apply a rest parameter to.
* @returns {Function} Returns the new function.
*/
function flatRest(func) {
return _setToString(_overRest(func, undefined, flatten_1), func + '');
}
var _flatRest = flatRest;
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG$1 = 1,
CLONE_FLAT_FLAG$1 = 2,
CLONE_SYMBOLS_FLAG$1 = 4;
/**
* The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable property paths of `object` that are not omitted.
*
* **Note:** This method is considerably slower than `_.pick`.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {...(string|string[])} [paths] The property paths to omit.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
*
* _.omit(object, ['a', 'c']);
* // => { 'b': '2' }
*/
var omit = _flatRest(function(object, paths) {
var result = {};
if (object == null) {
return result;
}
var isDeep = false;
paths = _arrayMap(paths, function(path) {
path = _castPath(path, object);
isDeep || (isDeep = path.length > 1);
return path;
});
_copyObject(object, _getAllKeysIn(object), result);
if (isDeep) {
result = _baseClone(result, CLONE_DEEP_FLAG$1 | CLONE_FLAT_FLAG$1 | CLONE_SYMBOLS_FLAG$1, _customOmitClone);
}
var length = paths.length;
while (length--) {
_baseUnset(result, paths[length]);
}
return result;
});
var omit_1 = omit;
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3.2);
* // => 3.2
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3.2');
* // => 3.2
*/
function toNumber(value) {
if (typeof value == 'number') {
return value;
}
if (isSymbol_1(value)) {
return NAN;
}
if (isObject_1(value)) {
var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
value = isObject_1(other) ? (other + '') : other;
}
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = value.replace(reTrim, '');
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: (reIsBadHex.test(value) ? NAN : +value);
}
var toNumber_1 = toNumber;
/** Used as references for various `Number` constants. */
var INFINITY$2 = 1 / 0,
MAX_INTEGER = 1.7976931348623157e+308;
/**
* Converts `value` to a finite number.
*
* @static
* @memberOf _
* @since 4.12.0
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted number.
* @example
*
* _.toFinite(3.2);
* // => 3.2
*
* _.toFinite(Number.MIN_VALUE);
* // => 5e-324
*
* _.toFinite(Infinity);
* // => 1.7976931348623157e+308
*
* _.toFinite('3.2');
* // => 3.2
*/
function toFinite(value) {
if (!value) {
return value === 0 ? value : 0;
}
value = toNumber_1(value);
if (value === INFINITY$2 || value === -INFINITY$2) {
var sign = (value < 0 ? -1 : 1);
return sign * MAX_INTEGER;
}
return value === value ? value : 0;
}
var toFinite_1 = toFinite;
/**
* Converts `value` to an integer.
*
* **Note:** This method is loosely based on
* [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted integer.
* @example
*
* _.toInteger(3.2);
* // => 3
*
* _.toInteger(Number.MIN_VALUE);
* // => 0
*
* _.toInteger(Infinity);
* // => 1.7976931348623157e+308
*
* _.toInteger('3.2');
* // => 3
*/
function toInteger(value) {
var result = toFinite_1(value),
remainder = result % 1;
return result === result ? (remainder ? result - remainder : result) : 0;
}
var toInteger_1 = toInteger;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax$1 = Math.max;
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it's used as the
* offset from the end of `array`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to inspect.
* @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
* _.indexOf([1, 2, 1, 2], 2);
* // => 1
*
* // Search from the `fromIndex`.
* _.indexOf([1, 2, 1, 2], 2, 2);
* // => 3
*/
function indexOf(array, value, fromIndex) {
var length = array == null ? 0 : array.length;
if (!length) {
return -1;
}
var index = fromIndex == null ? 0 : toInteger_1(fromIndex);
if (index < 0) {
index = nativeMax$1(length + index, 0);
}
return _baseIndexOf(array, value, index);
}
var indexOf_1 = indexOf;
/** `Object#toString` result references. */
var numberTag$4 = '[object Number]';
/**
* Checks if `value` is classified as a `Number` primitive or object.
*
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
* classified as numbers, use the `_.isFinite` method.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a number, else `false`.
* @example
*
* _.isNumber(3);
* // => true
*
* _.isNumber(Number.MIN_VALUE);
* // => true
*
* _.isNumber(Infinity);
* // => true
*
* _.isNumber('3');
* // => false
*/
function isNumber(value) {
return typeof value == 'number' ||
(isObjectLike_1(value) && _baseGetTag(value) == numberTag$4);
}
var isNumber_1 = isNumber;
/**
* Checks if `value` is `NaN`.
*
* **Note:** This method is based on
* [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
* global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
* `undefined` and other non-number values.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
* @example
*
* _.isNaN(NaN);
* // => true
*
* _.isNaN(new Number(NaN));
* // => true
*
* isNaN(undefined);
* // => true
*
* _.isNaN(undefined);
* // => false
*/
function isNaN$1(value) {
// An `NaN` primitive is the only value that is not equal to itself.
// Perform the `toStringTag` check first to avoid errors with some
// ActiveX objects in IE.
return isNumber_1(value) && value != +value;
}
var _isNaN = isNaN$1;
/** `Object#toString` result references. */
var mapTag$6 = '[object Map]',
setTag$6 = '[object Set]';
/** Used for built-in method references. */
var objectProto$g = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$d = objectProto$g.hasOwnProperty;
/**
* Checks if `value` is an empty object, collection, map, or set.
*
* Objects are considered empty if they have no own enumerable string keyed
* properties.
*
* Array-like values such as `arguments` objects, arrays, buffers, strings, or
* jQuery-like collections are considered empty if they have a `length` of `0`.
* Similarly, maps and sets are considered empty if they have a `size` of `0`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
* @example
*
* _.isEmpty(null);
* // => true
*
* _.isEmpty(true);
* // => true
*
* _.isEmpty(1);
* // => true
*
* _.isEmpty([1, 2, 3]);
* // => false
*
* _.isEmpty({ 'a': 1 });
* // => false
*/
function isEmpty(value) {
if (value == null) {
return true;
}
if (isArrayLike_1(value) &&
(isArray_1(value) || typeof value == 'string' || typeof value.splice == 'function' ||
isBuffer_1(value) || isTypedArray_1(value) || isArguments_1(value))) {
return !value.length;
}
var tag = _getTag(value);
if (tag == mapTag$6 || tag == setTag$6) {
return !value.size;
}
if (_isPrototype(value)) {
return !_baseKeys(value).length;
}
for (var key in value) {
if (hasOwnProperty$d.call(value, key)) {
return false;
}
}
return true;
}
var isEmpty_1 = isEmpty;
/**
* Performs a deep comparison between two values to determine if they are
* equivalent.
*
* **Note:** This method supports comparing arrays, array buffers, booleans,
* date objects, error objects, maps, numbers, `Object` objects, regexes,
* sets, strings, symbols, and typed arrays. `Object` objects are compared
* by their own, not inherited, enumerable properties. Functions and DOM
* nodes are compared by strict equality, i.e. `===`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.isEqual(object, other);
* // => true
*
* object === other;
* // => false
*/
function isEqual(value, other) {
return _baseIsEqual(value, other);
}
var isEqual_1 = isEqual;
/**
* Checks if `value` is `undefined`.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
* @example
*
* _.isUndefined(void 0);
* // => true
*
* _.isUndefined(null);
* // => false
*/
function isUndefined(value) {
return value === undefined;
}
var isUndefined_1 = isUndefined;
/** `Object#toString` result references. */
var stringTag$4 = '[object String]';
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a string, else `false`.
* @example
*
* _.isString('abc');
* // => true
*
* _.isString(1);
* // => false
*/
function isString(value) {
return typeof value == 'string' ||
(!isArray_1(value) && isObjectLike_1(value) && _baseGetTag(value) == stringTag$4);
}
var isString_1 = isString;
/**
* Creates a `_.find` or `_.findLast` function.
*
* @private
* @param {Function} findIndexFunc The function to find the collection index.
* @returns {Function} Returns the new find function.
*/
function createFind(findIndexFunc) {
return function(collection, predicate, fromIndex) {
var iterable = Object(collection);
if (!isArrayLike_1(collection)) {
var iteratee = _baseIteratee(predicate, 3);
collection = keys_1(collection);
predicate = function(key) { return iteratee(iterable[key], key, iterable); };
}
var index = findIndexFunc(collection, predicate, fromIndex);
return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
};
}
var _createFind = createFind;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax$2 = Math.max;
/**
* This method is like `_.find` except that it returns the index of the first
* element `predicate` returns truthy for instead of the element itself.
*
* @static
* @memberOf _
* @since 1.1.0
* @category Array
* @param {Array} array The array to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {number} [fromIndex=0] The index to search from.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var users = [
* { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'active': true }
* ];
*
* _.findIndex(users, function(o) { return o.user == 'barney'; });
* // => 0
*
* // The `_.matches` iteratee shorthand.
* _.findIndex(users, { 'user': 'fred', 'active': false });
* // => 1
*
* // The `_.matchesProperty` iteratee shorthand.
* _.findIndex(users, ['active', false]);
* // => 0
*
* // The `_.property` iteratee shorthand.
* _.findIndex(users, 'active');
* // => 2
*/
function findIndex(array, predicate, fromIndex) {
var length = array == null ? 0 : array.length;
if (!length) {
return -1;
}
var index = fromIndex == null ? 0 : toInteger_1(fromIndex);
if (index < 0) {
index = nativeMax$2(length + index, 0);
}
return _baseFindIndex(array, _baseIteratee(predicate, 3), index);
}
var findIndex_1 = findIndex;
/**
* Iterates over elements of `collection`, returning the first element
* `predicate` returns truthy for. The predicate is invoked with three
* arguments: (value, index|key, collection).
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {number} [fromIndex=0] The index to search from.
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': true }
* ];
*
* _.find(users, function(o) { return o.age < 40; });
* // => object for 'barney'
*
* // The `_.matches` iteratee shorthand.
* _.find(users, { 'age': 1, 'active': true });
* // => object for 'pebbles'
*
* // The `_.matchesProperty` iteratee shorthand.
* _.find(users, ['active', false]);
* // => object for 'fred'
*
* // The `_.property` iteratee shorthand.
* _.find(users, 'active');
* // => object for 'barney'
*/
var find = _createFind(findIndex_1);
var find_1 = find;
/**
* Casts `array` to a slice if it's needed.
*
* @private
* @param {Array} array The array to inspect.
* @param {number} start The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the cast slice.
*/
function castSlice(array, start, end) {
var length = array.length;
end = end === undefined ? length : end;
return (!start && end >= length) ? array : _baseSlice(array, start, end);
}
var _castSlice = castSlice;
/**
* Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
* that is not found in the character symbols.
*
* @private
* @param {Array} strSymbols The string symbols to inspect.
* @param {Array} chrSymbols The character symbols to find.
* @returns {number} Returns the index of the last unmatched string symbol.
*/
function charsEndIndex(strSymbols, chrSymbols) {
var index = strSymbols.length;
while (index-- && _baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
return index;
}
var _charsEndIndex = charsEndIndex;
/**
* Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
* that is not found in the character symbols.
*
* @private
* @param {Array} strSymbols The string symbols to inspect.
* @param {Array} chrSymbols The character symbols to find.
* @returns {number} Returns the index of the first unmatched string symbol.
*/
function charsStartIndex(strSymbols, chrSymbols) {
var index = -1,
length = strSymbols.length;
while (++index < length && _baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
return index;
}
var _charsStartIndex = charsStartIndex;
/**
* Converts an ASCII `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function asciiToArray(string) {
return string.split('');
}
var _asciiToArray = asciiToArray;
/** Used to compose unicode character classes. */
var rsAstralRange = '\\ud800-\\udfff',
rsComboMarksRange = '\\u0300-\\u036f',
reComboHalfMarksRange = '\\ufe20-\\ufe2f',
rsComboSymbolsRange = '\\u20d0-\\u20ff',
rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
rsVarRange = '\\ufe0e\\ufe0f';
/** Used to compose unicode capture groups. */
var rsZWJ = '\\u200d';
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
/**
* Checks if `string` contains Unicode symbols.
*
* @private
* @param {string} string The string to inspect.
* @returns {boolean} Returns `true` if a symbol is found, else `false`.
*/
function hasUnicode(string) {
return reHasUnicode.test(string);
}
var _hasUnicode = hasUnicode;
/** Used to compose unicode character classes. */
var rsAstralRange$1 = '\\ud800-\\udfff',
rsComboMarksRange$1 = '\\u0300-\\u036f',
reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f',
rsComboSymbolsRange$1 = '\\u20d0-\\u20ff',
rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1,
rsVarRange$1 = '\\ufe0e\\ufe0f';
/** Used to compose unicode capture groups. */
var rsAstral = '[' + rsAstralRange$1 + ']',
rsCombo = '[' + rsComboRange$1 + ']',
rsFitz = '\\ud83c[\\udffb-\\udfff]',
rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
rsNonAstral = '[^' + rsAstralRange$1 + ']',
rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
rsZWJ$1 = '\\u200d';
/** Used to compose unicode regexes. */
var reOptMod = rsModifier + '?',
rsOptVar = '[' + rsVarRange$1 + ']?',
rsOptJoin = '(?:' + rsZWJ$1 + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
rsSeq = rsOptVar + reOptMod + rsOptJoin,
rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
/**
* Converts a Unicode `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function unicodeToArray(string) {
return string.match(reUnicode) || [];
}
var _unicodeToArray = unicodeToArray;
/**
* Converts `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function stringToArray(string) {
return _hasUnicode(string)
? _unicodeToArray(string)
: _asciiToArray(string);
}
var _stringToArray = stringToArray;
/** Used to match leading and trailing whitespace. */
var reTrim$1 = /^\s+|\s+$/g;
/**
* Removes leading and trailing whitespace or specified characters from `string`.
*
* @static
* @memberOf _
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to trim.
* @param {string} [chars=whitespace] The characters to trim.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
* @returns {string} Returns the trimmed string.
* @example
*
* _.trim(' abc ');
* // => 'abc'
*
* _.trim('-_-abc-_-', '_-');
* // => 'abc'
*
* _.map([' foo ', ' bar '], _.trim);
* // => ['foo', 'bar']
*/
function trim(string, chars, guard) {
string = toString_1(string);
if (string && (guard || chars === undefined)) {
return string.replace(reTrim$1, '');
}
if (!string || !(chars = _baseToString(chars))) {
return string;
}
var strSymbols = _stringToArray(string),
chrSymbols = _stringToArray(chars),
start = _charsStartIndex(strSymbols, chrSymbols),
end = _charsEndIndex(strSymbols, chrSymbols) + 1;
return _castSlice(strSymbols, start, end).join('');
}
var trim_1 = trim;
/**
* Checks if the given arguments are from an iteratee call.
*
* @private
* @param {*} value The potential iteratee value argument.
* @param {*} index The potential iteratee index or key argument.
* @param {*} object The potential iteratee object argument.
* @returns {boolean} Returns `true` if the arguments are from an iteratee call,
* else `false`.
*/
function isIterateeCall(value, index, object) {
if (!isObject_1(object)) {
return false;
}
var type = typeof index;
if (type == 'number'
? (isArrayLike_1(object) && _isIndex(index, object.length))
: (type == 'string' && index in object)
) {
return eq_1(object[index], value);
}
return false;
}
var _isIterateeCall = isIterateeCall;
/** Used for built-in method references. */
var objectProto$h = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$e = objectProto$h.hasOwnProperty;
/**
* Assigns own and inherited enumerable string keyed properties of source
* objects to the destination object for all destination properties that
* resolve to `undefined`. Source objects are applied from left to right.
* Once a property is set, additional values of the same property are ignored.
*
* **Note:** This method mutates `object`.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
* @see _.defaultsDeep
* @example
*
* _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
* // => { 'a': 1, 'b': 2 }
*/
var defaults = _baseRest(function(object, sources) {
object = Object(object);
var index = -1;
var length = sources.length;
var guard = length > 2 ? sources[2] : undefined;
if (guard && _isIterateeCall(sources[0], sources[1], guard)) {
length = 1;
}
while (++index < length) {
var source = sources[index];
var props = keysIn_1(source);
var propsIndex = -1;
var propsLength = props.length;
while (++propsIndex < propsLength) {
var key = props[propsIndex];
var value = object[key];
if (value === undefined ||
(eq_1(value, objectProto$h[key]) && !hasOwnProperty$e.call(object, key))) {
object[key] = source[key];
}
}
}
return object;
});
var defaults_1 = defaults;
/**
* This function is like `assignValue` except that it doesn't assign
* `undefined` values.
*
* @private
* @param {Object} object The object to modify.
* @param {string} key The key of the property to assign.
* @param {*} value The value to assign.
*/
function assignMergeValue(object, key, value) {
if ((value !== undefined && !eq_1(object[key], value)) ||
(value === undefined && !(key in object))) {
_baseAssignValue(object, key, value);
}
}
var _assignMergeValue = assignMergeValue;
/**
* Gets the value at `key`, unless `key` is "__proto__".
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the property to get.
* @returns {*} Returns the property value.
*/
function safeGet(object, key) {
if (key == '__proto__') {
return;
}
return object[key];
}
var _safeGet = safeGet;
/**
* Converts `value` to a plain object flattening inherited enumerable string
* keyed properties of `value` to own properties of the plain object.
*
* @static
* @memberOf _
* @since 3.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {Object} Returns the converted plain object.
* @example
*
* function Foo() {
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.assign({ 'a': 1 }, new Foo);
* // => { 'a': 1, 'b': 2 }
*
* _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
* // => { 'a': 1, 'b': 2, 'c': 3 }
*/
function toPlainObject(value) {
return _copyObject(value, keysIn_1(value));
}
var toPlainObject_1 = toPlainObject;
/**
* A specialized version of `baseMerge` for arrays and objects which performs
* deep merges and tracks traversed objects enabling objects with circular
* references to be merged.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {string} key The key of the value to merge.
* @param {number} srcIndex The index of `source`.
* @param {Function} mergeFunc The function to merge values.
* @param {Function} [customizer] The function to customize assigned values.
* @param {Object} [stack] Tracks traversed source values and their merged
* counterparts.
*/
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
var objValue = _safeGet(object, key),
srcValue = _safeGet(source, key),
stacked = stack.get(srcValue);
if (stacked) {
_assignMergeValue(object, key, stacked);
return;
}
var newValue = customizer
? customizer(objValue, srcValue, (key + ''), object, source, stack)
: undefined;
var isCommon = newValue === undefined;
if (isCommon) {
var isArr = isArray_1(srcValue),
isBuff = !isArr && isBuffer_1(srcValue),
isTyped = !isArr && !isBuff && isTypedArray_1(srcValue);
newValue = srcValue;
if (isArr || isBuff || isTyped) {
if (isArray_1(objValue)) {
newValue = objValue;
}
else if (isArrayLikeObject_1(objValue)) {
newValue = _copyArray(objValue);
}
else if (isBuff) {
isCommon = false;
newValue = _cloneBuffer(srcValue, true);
}
else if (isTyped) {
isCommon = false;
newValue = _cloneTypedArray(srcValue, true);
}
else {
newValue = [];
}
}
else if (isPlainObject_1(srcValue) || isArguments_1(srcValue)) {
newValue = objValue;
if (isArguments_1(objValue)) {
newValue = toPlainObject_1(objValue);
}
else if (!isObject_1(objValue) || isFunction_1(objValue)) {
newValue = _initCloneObject(srcValue);
}
}
else {
isCommon = false;
}
}
if (isCommon) {
// Recursively merge objects and arrays (susceptible to call stack limits).
stack.set(srcValue, newValue);
mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
stack['delete'](srcValue);
}
_assignMergeValue(object, key, newValue);
}
var _baseMergeDeep = baseMergeDeep;
/**
* The base implementation of `_.merge` without support for multiple sources.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {number} srcIndex The index of `source`.
* @param {Function} [customizer] The function to customize merged values.
* @param {Object} [stack] Tracks traversed source values and their merged
* counterparts.
*/
function baseMerge(object, source, srcIndex, customizer, stack) {
if (object === source) {
return;
}
_baseFor(source, function(srcValue, key) {
if (isObject_1(srcValue)) {
stack || (stack = new _Stack);
_baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
}
else {
var newValue = customizer
? customizer(_safeGet(object, key), srcValue, (key + ''), object, source, stack)
: undefined;
if (newValue === undefined) {
newValue = srcValue;
}
_assignMergeValue(object, key, newValue);
}
}, keysIn_1);
}
var _baseMerge = baseMerge;
/**
* Creates a function like `_.assign`.
*
* @private
* @param {Function} assigner The function to assign values.
* @returns {Function} Returns the new assigner function.
*/
function createAssigner(assigner) {
return _baseRest(function(object, sources) {
var index = -1,
length = sources.length,
customizer = length > 1 ? sources[length - 1] : undefined,
guard = length > 2 ? sources[2] : undefined;
customizer = (assigner.length > 3 && typeof customizer == 'function')
? (length--, customizer)
: undefined;
if (guard && _isIterateeCall(sources[0], sources[1], guard)) {
customizer = length < 3 ? undefined : customizer;
length = 1;
}
object = Object(object);
while (++index < length) {
var source = sources[index];
if (source) {
assigner(object, source, index, customizer);
}
}
return object;
});
}
var _createAssigner = createAssigner;
/**
* This method is like `_.assign` except that it recursively merges own and
* inherited enumerable string keyed properties of source objects into the
* destination object. Source properties that resolve to `undefined` are
* skipped if a destination value exists. Array and plain object properties
* are merged recursively. Other objects and value types are overridden by
* assignment. Source objects are applied from left to right. Subsequent
* sources overwrite property assignments of previous sources.
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @since 0.5.0
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
* @example
*
* var object = {
* 'a': [{ 'b': 2 }, { 'd': 4 }]
* };
*
* var other = {
* 'a': [{ 'c': 3 }, { 'e': 5 }]
* };
*
* _.merge(object, other);
* // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
*/
var merge = _createAssigner(function(object, source, srcIndex) {
_baseMerge(object, source, srcIndex);
});
var merge_1 = merge;
function valToNumber(v) {
if (isNumber_1(v)) {
return v;
} else if (isString_1(v)) {
return parseFloat(v);
} else if (Array.isArray(v)) {
return map_1(v, valToNumber);
}
throw new Error('The value should be a number, a parseable string or an array of those.');
}
var valToNumber_1 = valToNumber;
function filterState(state, filters) {
var partialState = {};
var attributeFilters = filter_1(filters, function(f) { return f.indexOf('attribute:') !== -1; });
var attributes = map_1(attributeFilters, function(aF) { return aF.split(':')[1]; });
if (indexOf_1(attributes, '*') === -1) {
forEach_1(attributes, function(attr) {
if (state.isConjunctiveFacet(attr) && state.isFacetRefined(attr)) {
if (!partialState.facetsRefinements) partialState.facetsRefinements = {};
partialState.facetsRefinements[attr] = state.facetsRefinements[attr];
}
if (state.isDisjunctiveFacet(attr) && state.isDisjunctiveFacetRefined(attr)) {
if (!partialState.disjunctiveFacetsRefinements) partialState.disjunctiveFacetsRefinements = {};
partialState.disjunctiveFacetsRefinements[attr] = state.disjunctiveFacetsRefinements[attr];
}
if (state.isHierarchicalFacet(attr) && state.isHierarchicalFacetRefined(attr)) {
if (!partialState.hierarchicalFacetsRefinements) partialState.hierarchicalFacetsRefinements = {};
partialState.hierarchicalFacetsRefinements[attr] = state.hierarchicalFacetsRefinements[attr];
}
var numericRefinements = state.getNumericRefinements(attr);
if (!isEmpty_1(numericRefinements)) {
if (!partialState.numericRefinements) partialState.numericRefinements = {};
partialState.numericRefinements[attr] = state.numericRefinements[attr];
}
});
} else {
if (!isEmpty_1(state.numericRefinements)) {
partialState.numericRefinements = state.numericRefinements;
}
if (!isEmpty_1(state.facetsRefinements)) partialState.facetsRefinements = state.facetsRefinements;
if (!isEmpty_1(state.disjunctiveFacetsRefinements)) {
partialState.disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements;
}
if (!isEmpty_1(state.hierarchicalFacetsRefinements)) {
partialState.hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements;
}
}
var searchParameters = filter_1(
filters,
function(f) {
return f.indexOf('attribute:') === -1;
}
);
forEach_1(
searchParameters,
function(parameterKey) {
partialState[parameterKey] = state[parameterKey];
}
);
return partialState;
}
var filterState_1 = filterState;
/**
* Functions to manipulate refinement lists
*
* The RefinementList is not formally defined through a prototype but is based
* on a specific structure.
*
* @module SearchParameters.refinementList
*
* @typedef {string[]} SearchParameters.refinementList.Refinements
* @typedef {Object.} SearchParameters.refinementList.RefinementList
*/
var lib = {
/**
* Adds a refinement to a RefinementList
* @param {RefinementList} refinementList the initial list
* @param {string} attribute the attribute to refine
* @param {string} value the value of the refinement, if the value is not a string it will be converted
* @return {RefinementList} a new and updated refinement list
*/
addRefinement: function addRefinement(refinementList, attribute, value) {
if (lib.isRefined(refinementList, attribute, value)) {
return refinementList;
}
var valueAsString = '' + value;
var facetRefinement = !refinementList[attribute] ?
[valueAsString] :
refinementList[attribute].concat(valueAsString);
var mod = {};
mod[attribute] = facetRefinement;
return defaults_1({}, mod, refinementList);
},
/**
* Removes refinement(s) for an attribute:
* - if the value is specified removes the refinement for the value on the attribute
* - if no value is specified removes all the refinements for this attribute
* @param {RefinementList} refinementList the initial list
* @param {string} attribute the attribute to refine
* @param {string} [value] the value of the refinement
* @return {RefinementList} a new and updated refinement lst
*/
removeRefinement: function removeRefinement(refinementList, attribute, value) {
if (isUndefined_1(value)) {
return lib.clearRefinement(refinementList, attribute);
}
var valueAsString = '' + value;
return lib.clearRefinement(refinementList, function(v, f) {
return attribute === f && valueAsString === v;
});
},
/**
* Toggles the refinement value for an attribute.
* @param {RefinementList} refinementList the initial list
* @param {string} attribute the attribute to refine
* @param {string} value the value of the refinement
* @return {RefinementList} a new and updated list
*/
toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
if (isUndefined_1(value)) throw new Error('toggleRefinement should be used with a value');
if (lib.isRefined(refinementList, attribute, value)) {
return lib.removeRefinement(refinementList, attribute, value);
}
return lib.addRefinement(refinementList, attribute, value);
},
/**
* Clear all or parts of a RefinementList. Depending on the arguments, three
* kinds of behavior can happen:
* - if no attribute is provided: clears the whole list
* - if an attribute is provided as a string: clears the list for the specific attribute
* - if an attribute is provided as a function: discards the elements for which the function returns true
* @param {RefinementList} refinementList the initial list
* @param {string} [attribute] the attribute or function to discard
* @param {string} [refinementType] optional parameter to give more context to the attribute function
* @return {RefinementList} a new and updated refinement list
*/
clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
if (isUndefined_1(attribute)) {
if (isEmpty_1(refinementList)) return refinementList;
return {};
} else if (isString_1(attribute)) {
if (isEmpty_1(refinementList[attribute])) return refinementList;
return omit_1(refinementList, attribute);
} else if (isFunction_1(attribute)) {
var hasChanged = false;
var newRefinementList = reduce_1(refinementList, function(memo, values, key) {
var facetList = filter_1(values, function(value) {
return !attribute(value, key, refinementType);
});
if (!isEmpty_1(facetList)) {
if (facetList.length !== values.length) hasChanged = true;
memo[key] = facetList;
}
else hasChanged = true;
return memo;
}, {});
if (hasChanged) return newRefinementList;
return refinementList;
}
},
/**
* Test if the refinement value is used for the attribute. If no refinement value
* is provided, test if the refinementList contains any refinement for the
* given attribute.
* @param {RefinementList} refinementList the list of refinement
* @param {string} attribute name of the attribute
* @param {string} [refinementValue] value of the filter/refinement
* @return {boolean}
*/
isRefined: function isRefined(refinementList, attribute, refinementValue) {
var indexOf = indexOf_1;
var containsRefinements = !!refinementList[attribute] &&
refinementList[attribute].length > 0;
if (isUndefined_1(refinementValue) || !containsRefinements) {
return containsRefinements;
}
var refinementValueAsString = '' + refinementValue;
return indexOf(refinementList[attribute], refinementValueAsString) !== -1;
}
};
var RefinementList = lib;
/**
* like _.find but using _.isEqual to be able to use it
* to find arrays.
* @private
* @param {any[]} array array to search into
* @param {any} searchedValue the value we're looking for
* @return {any} the searched value or undefined
*/
function findArray(array, searchedValue) {
return find_1(array, function(currentValue) {
return isEqual_1(currentValue, searchedValue);
});
}
/**
* The facet list is the structure used to store the list of values used to
* filter a single attribute.
* @typedef {string[]} SearchParameters.FacetList
*/
/**
* Structure to store numeric filters with the operator as the key. The supported operators
* are `=`, `>`, `<`, `>=`, `<=` and `!=`.
* @typedef {Object.>} SearchParameters.OperatorList
*/
/**
* SearchParameters is the data structure that contains all the information
* usable for making a search to Algolia API. It doesn't do the search itself,
* nor does it contains logic about the parameters.
* It is an immutable object, therefore it has been created in a way that each
* changes does not change the object itself but returns a copy with the
* modification.
* This object should probably not be instantiated outside of the helper. It will
* be provided when needed. This object is documented for reference as you'll
* get it from events generated by the {@link AlgoliaSearchHelper}.
* If need be, instantiate the Helper from the factory function {@link SearchParameters.make}
* @constructor
* @classdesc contains all the parameters of a search
* @param {object|SearchParameters} newParameters existing parameters or partial object
* for the properties of a new SearchParameters
* @see SearchParameters.make
* @example SearchParameters of the first query in
* the instant search demo
{
"query": "",
"disjunctiveFacets": [
"customerReviewCount",
"category",
"salePrice_range",
"manufacturer"
],
"maxValuesPerFacet": 30,
"page": 0,
"hitsPerPage": 10,
"facets": [
"type",
"shipping"
]
}
*/
function SearchParameters(newParameters) {
var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
/**
* Targeted index. This parameter is mandatory.
* @member {string}
*/
this.index = params.index || '';
// Query
/**
* Query string of the instant search. The empty string is a valid query.
* @member {string}
* @see https://www.algolia.com/doc/rest#param-query
*/
this.query = params.query || '';
// Facets
/**
* This attribute contains the list of all the conjunctive facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
* @member {string[]}
*/
this.facets = params.facets || [];
/**
* This attribute contains the list of all the disjunctive facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
* @member {string[]}
*/
this.disjunctiveFacets = params.disjunctiveFacets || [];
/**
* This attribute contains the list of all the hierarchical facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
* Hierarchical facets are a sub type of disjunctive facets that
* let you filter faceted attributes hierarchically.
* @member {string[]|object[]}
*/
this.hierarchicalFacets = params.hierarchicalFacets || [];
// Refinements
/**
* This attribute contains all the filters that need to be
* applied on the conjunctive facets. Each facet must be properly
* defined in the `facets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
* @member {Object.}
*/
this.facetsRefinements = params.facetsRefinements || {};
/**
* This attribute contains all the filters that need to be
* excluded from the conjunctive facets. Each facet must be properly
* defined in the `facets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters excluded for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
* @member {Object.}
*/
this.facetsExcludes = params.facetsExcludes || {};
/**
* This attribute contains all the filters that need to be
* applied on the disjunctive facets. Each facet must be properly
* defined in the `disjunctiveFacets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
* @member {Object.}
*/
this.disjunctiveFacetsRefinements = params.disjunctiveFacetsRefinements || {};
/**
* This attribute contains all the filters that need to be
* applied on the numeric attributes.
*
* The key is the name of the attribute, and the value is the
* filters to apply to this attribute.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `numericFilters` attribute.
* @member {Object.}
*/
this.numericRefinements = params.numericRefinements || {};
/**
* This attribute contains all the tags used to refine the query.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `tagFilters` attribute.
* @member {string[]}
*/
this.tagRefinements = params.tagRefinements || [];
/**
* This attribute contains all the filters that need to be
* applied on the hierarchical facets. Each facet must be properly
* defined in the `hierarchicalFacets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name. The FacetList values
* are structured as a string that contain the values for each level
* separated by the configured separator.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
* @member {Object.}
*/
this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
/**
* Contains the numeric filters in the raw format of the Algolia API. Setting
* this parameter is not compatible with the usage of numeric filters methods.
* @see https://www.algolia.com/doc/javascript#numericFilters
* @member {string}
*/
this.numericFilters = params.numericFilters;
/**
* Contains the tag filters in the raw format of the Algolia API. Setting this
* parameter is not compatible with the of the add/remove/toggle methods of the
* tag api.
* @see https://www.algolia.com/doc/rest#param-tagFilters
* @member {string}
*/
this.tagFilters = params.tagFilters;
/**
* Contains the optional tag filters in the raw format of the Algolia API.
* @see https://www.algolia.com/doc/rest#param-tagFilters
* @member {string}
*/
this.optionalTagFilters = params.optionalTagFilters;
/**
* Contains the optional facet filters in the raw format of the Algolia API.
* @see https://www.algolia.com/doc/rest#param-tagFilters
* @member {string}
*/
this.optionalFacetFilters = params.optionalFacetFilters;
// Misc. parameters
/**
* Number of hits to be returned by the search API
* @member {number}
* @see https://www.algolia.com/doc/rest#param-hitsPerPage
*/
this.hitsPerPage = params.hitsPerPage;
/**
* Number of values for each faceted attribute
* @member {number}
* @see https://www.algolia.com/doc/rest#param-maxValuesPerFacet
*/
this.maxValuesPerFacet = params.maxValuesPerFacet;
/**
* The current page number
* @member {number}
* @see https://www.algolia.com/doc/rest#param-page
*/
this.page = params.page || 0;
/**
* How the query should be treated by the search engine.
* Possible values: prefixAll, prefixLast, prefixNone
* @see https://www.algolia.com/doc/rest#param-queryType
* @member {string}
*/
this.queryType = params.queryType;
/**
* How the typo tolerance behave in the search engine.
* Possible values: true, false, min, strict
* @see https://www.algolia.com/doc/rest#param-typoTolerance
* @member {string}
*/
this.typoTolerance = params.typoTolerance;
/**
* Number of characters to wait before doing one character replacement.
* @see https://www.algolia.com/doc/rest#param-minWordSizefor1Typo
* @member {number}
*/
this.minWordSizefor1Typo = params.minWordSizefor1Typo;
/**
* Number of characters to wait before doing a second character replacement.
* @see https://www.algolia.com/doc/rest#param-minWordSizefor2Typos
* @member {number}
*/
this.minWordSizefor2Typos = params.minWordSizefor2Typos;
/**
* Configure the precision of the proximity ranking criterion
* @see https://www.algolia.com/doc/rest#param-minProximity
*/
this.minProximity = params.minProximity;
/**
* Should the engine allow typos on numerics.
* @see https://www.algolia.com/doc/rest#param-allowTyposOnNumericTokens
* @member {boolean}
*/
this.allowTyposOnNumericTokens = params.allowTyposOnNumericTokens;
/**
* Should the plurals be ignored
* @see https://www.algolia.com/doc/rest#param-ignorePlurals
* @member {boolean}
*/
this.ignorePlurals = params.ignorePlurals;
/**
* Restrict which attribute is searched.
* @see https://www.algolia.com/doc/rest#param-restrictSearchableAttributes
* @member {string}
*/
this.restrictSearchableAttributes = params.restrictSearchableAttributes;
/**
* Enable the advanced syntax.
* @see https://www.algolia.com/doc/rest#param-advancedSyntax
* @member {boolean}
*/
this.advancedSyntax = params.advancedSyntax;
/**
* Enable the analytics
* @see https://www.algolia.com/doc/rest#param-analytics
* @member {boolean}
*/
this.analytics = params.analytics;
/**
* Tag of the query in the analytics.
* @see https://www.algolia.com/doc/rest#param-analyticsTags
* @member {string}
*/
this.analyticsTags = params.analyticsTags;
/**
* Enable the synonyms
* @see https://www.algolia.com/doc/rest#param-synonyms
* @member {boolean}
*/
this.synonyms = params.synonyms;
/**
* Should the engine replace the synonyms in the highlighted results.
* @see https://www.algolia.com/doc/rest#param-replaceSynonymsInHighlight
* @member {boolean}
*/
this.replaceSynonymsInHighlight = params.replaceSynonymsInHighlight;
/**
* Add some optional words to those defined in the dashboard
* @see https://www.algolia.com/doc/rest#param-optionalWords
* @member {string}
*/
this.optionalWords = params.optionalWords;
/**
* Possible values are "lastWords" "firstWords" "allOptional" "none" (default)
* @see https://www.algolia.com/doc/rest#param-removeWordsIfNoResults
* @member {string}
*/
this.removeWordsIfNoResults = params.removeWordsIfNoResults;
/**
* List of attributes to retrieve
* @see https://www.algolia.com/doc/rest#param-attributesToRetrieve
* @member {string}
*/
this.attributesToRetrieve = params.attributesToRetrieve;
/**
* List of attributes to highlight
* @see https://www.algolia.com/doc/rest#param-attributesToHighlight
* @member {string}
*/
this.attributesToHighlight = params.attributesToHighlight;
/**
* Code to be embedded on the left part of the highlighted results
* @see https://www.algolia.com/doc/rest#param-highlightPreTag
* @member {string}
*/
this.highlightPreTag = params.highlightPreTag;
/**
* Code to be embedded on the right part of the highlighted results
* @see https://www.algolia.com/doc/rest#param-highlightPostTag
* @member {string}
*/
this.highlightPostTag = params.highlightPostTag;
/**
* List of attributes to snippet
* @see https://www.algolia.com/doc/rest#param-attributesToSnippet
* @member {string}
*/
this.attributesToSnippet = params.attributesToSnippet;
/**
* Enable the ranking informations in the response, set to 1 to activate
* @see https://www.algolia.com/doc/rest#param-getRankingInfo
* @member {number}
*/
this.getRankingInfo = params.getRankingInfo;
/**
* Remove duplicates based on the index setting attributeForDistinct
* @see https://www.algolia.com/doc/rest#param-distinct
* @member {boolean|number}
*/
this.distinct = params.distinct;
/**
* Center of the geo search.
* @see https://www.algolia.com/doc/rest#param-aroundLatLng
* @member {string}
*/
this.aroundLatLng = params.aroundLatLng;
/**
* Center of the search, retrieve from the user IP.
* @see https://www.algolia.com/doc/rest#param-aroundLatLngViaIP
* @member {boolean}
*/
this.aroundLatLngViaIP = params.aroundLatLngViaIP;
/**
* Radius of the geo search.
* @see https://www.algolia.com/doc/rest#param-aroundRadius
* @member {number}
*/
this.aroundRadius = params.aroundRadius;
/**
* Precision of the geo search.
* @see https://www.algolia.com/doc/rest#param-aroundPrecision
* @member {number}
*/
this.minimumAroundRadius = params.minimumAroundRadius;
/**
* Precision of the geo search.
* @see https://www.algolia.com/doc/rest#param-minimumAroundRadius
* @member {number}
*/
this.aroundPrecision = params.aroundPrecision;
/**
* Geo search inside a box.
* @see https://www.algolia.com/doc/rest#param-insideBoundingBox
* @member {string}
*/
this.insideBoundingBox = params.insideBoundingBox;
/**
* Geo search inside a polygon.
* @see https://www.algolia.com/doc/rest#param-insidePolygon
* @member {string}
*/
this.insidePolygon = params.insidePolygon;
/**
* Allows to specify an ellipsis character for the snippet when we truncate the text
* (added before and after if truncated).
* The default value is an empty string and we recommend to set it to "…"
* @see https://www.algolia.com/doc/rest#param-insidePolygon
* @member {string}
*/
this.snippetEllipsisText = params.snippetEllipsisText;
/**
* Allows to specify some attributes name on which exact won't be applied.
* Attributes are separated with a comma (for example "name,address" ), you can also use a
* JSON string array encoding (for example encodeURIComponent('["name","address"]') ).
* By default the list is empty.
* @see https://www.algolia.com/doc/rest#param-disableExactOnAttributes
* @member {string|string[]}
*/
this.disableExactOnAttributes = params.disableExactOnAttributes;
/**
* Applies 'exact' on single word queries if the word contains at least 3 characters
* and is not a stop word.
* Can take two values: true or false.
* By default, its set to false.
* @see https://www.algolia.com/doc/rest#param-enableExactOnSingleWordQuery
* @member {boolean}
*/
this.enableExactOnSingleWordQuery = params.enableExactOnSingleWordQuery;
// Undocumented parameters, still needed otherwise we fail
this.offset = params.offset;
this.length = params.length;
var self = this;
forOwn_1(params, function checkForUnknownParameter(paramValue, paramName) {
if (SearchParameters.PARAMETERS.indexOf(paramName) === -1) {
self[paramName] = paramValue;
}
});
}
/**
* List all the properties in SearchParameters and therefore all the known Algolia properties
* This doesn't contain any beta/hidden features.
* @private
*/
SearchParameters.PARAMETERS = keys_1(new SearchParameters());
/**
* @private
* @param {object} partialState full or part of a state
* @return {object} a new object with the number keys as number
*/
SearchParameters._parseNumbers = function(partialState) {
// Do not reparse numbers in SearchParameters, they ought to be parsed already
if (partialState instanceof SearchParameters) return partialState;
var numbers = {};
var numberKeys = [
'aroundPrecision',
'aroundRadius',
'getRankingInfo',
'minWordSizefor2Typos',
'minWordSizefor1Typo',
'page',
'maxValuesPerFacet',
'distinct',
'minimumAroundRadius',
'hitsPerPage',
'minProximity'
];
forEach_1(numberKeys, function(k) {
var value = partialState[k];
if (isString_1(value)) {
var parsedValue = parseFloat(value);
numbers[k] = _isNaN(parsedValue) ? value : parsedValue;
}
});
// there's two formats of insideBoundingBox, we need to parse
// the one which is an array of float geo rectangles
if (Array.isArray(partialState.insideBoundingBox)) {
numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
return geoRect.map(function(value) {
return parseFloat(value);
});
});
}
if (partialState.numericRefinements) {
var numericRefinements = {};
forEach_1(partialState.numericRefinements, function(operators, attribute) {
numericRefinements[attribute] = {};
forEach_1(operators, function(values, operator) {
var parsedValues = map_1(values, function(v) {
if (Array.isArray(v)) {
return map_1(v, function(vPrime) {
if (isString_1(vPrime)) {
return parseFloat(vPrime);
}
return vPrime;
});
} else if (isString_1(v)) {
return parseFloat(v);
}
return v;
});
numericRefinements[attribute][operator] = parsedValues;
});
});
numbers.numericRefinements = numericRefinements;
}
return merge_1({}, partialState, numbers);
};
/**
* Factory for SearchParameters
* @param {object|SearchParameters} newParameters existing parameters or partial
* object for the properties of a new SearchParameters
* @return {SearchParameters} frozen instance of SearchParameters
*/
SearchParameters.make = function makeSearchParameters(newParameters) {
var instance = new SearchParameters(newParameters);
forEach_1(newParameters.hierarchicalFacets, function(facet) {
if (facet.rootPath) {
var currentRefinement = instance.getHierarchicalRefinement(facet.name);
if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
instance = instance.clearRefinements(facet.name);
}
// get it again in case it has been cleared
currentRefinement = instance.getHierarchicalRefinement(facet.name);
if (currentRefinement.length === 0) {
instance = instance.toggleHierarchicalFacetRefinement(facet.name, facet.rootPath);
}
}
});
return instance;
};
/**
* Validates the new parameters based on the previous state
* @param {SearchParameters} currentState the current state
* @param {object|SearchParameters} parameters the new parameters to set
* @return {Error|null} Error if the modification is invalid, null otherwise
*/
SearchParameters.validate = function(currentState, parameters) {
var params = parameters || {};
if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
return new Error(
'[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
'an error, if it is really what you want, you should first clear the tags with clearTags method.');
}
if (currentState.tagRefinements.length > 0 && params.tagFilters) {
return new Error(
'[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
'an error, if it is not, you should first clear the tags with clearTags method.');
}
if (currentState.numericFilters && params.numericRefinements && !isEmpty_1(params.numericRefinements)) {
return new Error(
"[Numeric filters] Can't switch from the advanced to the managed API. It" +
' is probably an error, if this is really what you want, you have to first' +
' clear the numeric filters.');
}
if (!isEmpty_1(currentState.numericRefinements) && params.numericFilters) {
return new Error(
"[Numeric filters] Can't switch from the managed API to the advanced. It" +
' is probably an error, if this is really what you want, you have to first' +
' clear the numeric filters.');
}
return null;
};
SearchParameters.prototype = {
constructor: SearchParameters,
/**
* Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
* @method
* @param {undefined|string|SearchParameters.clearCallback} [attribute] optional string or function
* - If not given, means to clear all the filters.
* - If `string`, means to clear all refinements for the `attribute` named filter.
* - If `function`, means to clear all the refinements that return truthy values.
* @return {SearchParameters}
*/
clearRefinements: function clearRefinements(attribute) {
var clear = RefinementList.clearRefinement;
var patch = {
numericRefinements: this._clearNumericRefinements(attribute),
facetsRefinements: clear(this.facetsRefinements, attribute, 'conjunctiveFacet'),
facetsExcludes: clear(this.facetsExcludes, attribute, 'exclude'),
disjunctiveFacetsRefinements: clear(this.disjunctiveFacetsRefinements, attribute, 'disjunctiveFacet'),
hierarchicalFacetsRefinements: clear(this.hierarchicalFacetsRefinements, attribute, 'hierarchicalFacet')
};
if (patch.numericRefinements === this.numericRefinements &&
patch.facetsRefinements === this.facetsRefinements &&
patch.facetsExcludes === this.facetsExcludes &&
patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements) {
return this;
}
return this.setQueryParameters(patch);
},
/**
* Remove all the refined tags from the SearchParameters
* @method
* @return {SearchParameters}
*/
clearTags: function clearTags() {
if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
return this.setQueryParameters({
tagFilters: undefined,
tagRefinements: []
});
},
/**
* Set the index.
* @method
* @param {string} index the index name
* @return {SearchParameters}
*/
setIndex: function setIndex(index) {
if (index === this.index) return this;
return this.setQueryParameters({
index: index
});
},
/**
* Query setter
* @method
* @param {string} newQuery value for the new query
* @return {SearchParameters}
*/
setQuery: function setQuery(newQuery) {
if (newQuery === this.query) return this;
return this.setQueryParameters({
query: newQuery
});
},
/**
* Page setter
* @method
* @param {number} newPage new page number
* @return {SearchParameters}
*/
setPage: function setPage(newPage) {
if (newPage === this.page) return this;
return this.setQueryParameters({
page: newPage
});
},
/**
* Facets setter
* The facets are the simple facets, used for conjunctive (and) faceting.
* @method
* @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
* @return {SearchParameters}
*/
setFacets: function setFacets(facets) {
return this.setQueryParameters({
facets: facets
});
},
/**
* Disjunctive facets setter
* Change the list of disjunctive (or) facets the helper chan handle.
* @method
* @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
* @return {SearchParameters}
*/
setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
return this.setQueryParameters({
disjunctiveFacets: facets
});
},
/**
* HitsPerPage setter
* Hits per page represents the number of hits retrieved for this query
* @method
* @param {number} n number of hits retrieved per page of results
* @return {SearchParameters}
*/
setHitsPerPage: function setHitsPerPage(n) {
if (this.hitsPerPage === n) return this;
return this.setQueryParameters({
hitsPerPage: n
});
},
/**
* typoTolerance setter
* Set the value of typoTolerance
* @method
* @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
* @return {SearchParameters}
*/
setTypoTolerance: function setTypoTolerance(typoTolerance) {
if (this.typoTolerance === typoTolerance) return this;
return this.setQueryParameters({
typoTolerance: typoTolerance
});
},
/**
* Add a numeric filter for a given attribute
* When value is an array, they are combined with OR
* When value is a single value, it will combined with AND
* @method
* @param {string} attribute attribute to set the filter on
* @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
* @param {number | number[]} value value of the filter
* @return {SearchParameters}
* @example
* // for price = 50 or 40
* searchparameter.addNumericRefinement('price', '=', [50, 40]);
* @example
* // for size = 38 and 40
* searchparameter.addNumericRefinement('size', '=', 38);
* searchparameter.addNumericRefinement('size', '=', 40);
*/
addNumericRefinement: function(attribute, operator, v) {
var value = valToNumber_1(v);
if (this.isNumericRefined(attribute, operator, value)) return this;
var mod = merge_1({}, this.numericRefinements);
mod[attribute] = merge_1({}, mod[attribute]);
if (mod[attribute][operator]) {
// Array copy
mod[attribute][operator] = mod[attribute][operator].slice();
// Add the element. Concat can't be used here because value can be an array.
mod[attribute][operator].push(value);
} else {
mod[attribute][operator] = [value];
}
return this.setQueryParameters({
numericRefinements: mod
});
},
/**
* Get the list of conjunctive refinements for a single facet
* @param {string} facetName name of the attribute used for faceting
* @return {string[]} list of refinements
*/
getConjunctiveRefinements: function(facetName) {
if (!this.isConjunctiveFacet(facetName)) {
throw new Error(facetName + ' is not defined in the facets attribute of the helper configuration');
}
return this.facetsRefinements[facetName] || [];
},
/**
* Get the list of disjunctive refinements for a single facet
* @param {string} facetName name of the attribute used for faceting
* @return {string[]} list of refinements
*/
getDisjunctiveRefinements: function(facetName) {
if (!this.isDisjunctiveFacet(facetName)) {
throw new Error(
facetName + ' is not defined in the disjunctiveFacets attribute of the helper configuration'
);
}
return this.disjunctiveFacetsRefinements[facetName] || [];
},
/**
* Get the list of hierarchical refinements for a single facet
* @param {string} facetName name of the attribute used for faceting
* @return {string[]} list of refinements
*/
getHierarchicalRefinement: function(facetName) {
// we send an array but we currently do not support multiple
// hierarchicalRefinements for a hierarchicalFacet
return this.hierarchicalFacetsRefinements[facetName] || [];
},
/**
* Get the list of exclude refinements for a single facet
* @param {string} facetName name of the attribute used for faceting
* @return {string[]} list of refinements
*/
getExcludeRefinements: function(facetName) {
if (!this.isConjunctiveFacet(facetName)) {
throw new Error(facetName + ' is not defined in the facets attribute of the helper configuration');
}
return this.facetsExcludes[facetName] || [];
},
/**
* Remove all the numeric filter for a given (attribute, operator)
* @method
* @param {string} attribute attribute to set the filter on
* @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
* @param {number} [number] the value to be removed
* @return {SearchParameters}
*/
removeNumericRefinement: function(attribute, operator, paramValue) {
if (paramValue !== undefined) {
var paramValueAsNumber = valToNumber_1(paramValue);
if (!this.isNumericRefined(attribute, operator, paramValueAsNumber)) return this;
return this.setQueryParameters({
numericRefinements: this._clearNumericRefinements(function(value, key) {
return key === attribute && value.op === operator && isEqual_1(value.val, paramValueAsNumber);
})
});
} else if (operator !== undefined) {
if (!this.isNumericRefined(attribute, operator)) return this;
return this.setQueryParameters({
numericRefinements: this._clearNumericRefinements(function(value, key) {
return key === attribute && value.op === operator;
})
});
}
if (!this.isNumericRefined(attribute)) return this;
return this.setQueryParameters({
numericRefinements: this._clearNumericRefinements(function(value, key) {
return key === attribute;
})
});
},
/**
* Get the list of numeric refinements for a single facet
* @param {string} facetName name of the attribute used for faceting
* @return {SearchParameters.OperatorList[]} list of refinements
*/
getNumericRefinements: function(facetName) {
return this.numericRefinements[facetName] || {};
},
/**
* Return the current refinement for the (attribute, operator)
* @param {string} attribute attribute in the record
* @param {string} operator operator applied on the refined values
* @return {Array.} refined values
*/
getNumericRefinement: function(attribute, operator) {
return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
},
/**
* Clear numeric filters.
* @method
* @private
* @param {string|SearchParameters.clearCallback} [attribute] optional string or function
* - If not given, means to clear all the filters.
* - If `string`, means to clear all refinements for the `attribute` named filter.
* - If `function`, means to clear all the refinements that return truthy values.
* @return {Object.}
*/
_clearNumericRefinements: function _clearNumericRefinements(attribute) {
if (isUndefined_1(attribute)) {
if (isEmpty_1(this.numericRefinements)) return this.numericRefinements;
return {};
} else if (isString_1(attribute)) {
if (isEmpty_1(this.numericRefinements[attribute])) return this.numericRefinements;
return omit_1(this.numericRefinements, attribute);
} else if (isFunction_1(attribute)) {
var hasChanged = false;
var newNumericRefinements = reduce_1(this.numericRefinements, function(memo, operators, key) {
var operatorList = {};
forEach_1(operators, function(values, operator) {
var outValues = [];
forEach_1(values, function(value) {
var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
if (!predicateResult) outValues.push(value);
});
if (!isEmpty_1(outValues)) {
if (outValues.length !== values.length) hasChanged = true;
operatorList[operator] = outValues;
}
else hasChanged = true;
});
if (!isEmpty_1(operatorList)) memo[key] = operatorList;
return memo;
}, {});
if (hasChanged) return newNumericRefinements;
return this.numericRefinements;
}
},
/**
* Add a facet to the facets attribute of the helper configuration, if it
* isn't already present.
* @method
* @param {string} facet facet name to add
* @return {SearchParameters}
*/
addFacet: function addFacet(facet) {
if (this.isConjunctiveFacet(facet)) {
return this;
}
return this.setQueryParameters({
facets: this.facets.concat([facet])
});
},
/**
* Add a disjunctive facet to the disjunctiveFacets attribute of the helper
* configuration, if it isn't already present.
* @method
* @param {string} facet disjunctive facet name to add
* @return {SearchParameters}
*/
addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
if (this.isDisjunctiveFacet(facet)) {
return this;
}
return this.setQueryParameters({
disjunctiveFacets: this.disjunctiveFacets.concat([facet])
});
},
/**
* Add a hierarchical facet to the hierarchicalFacets attribute of the helper
* configuration.
* @method
* @param {object} hierarchicalFacet hierarchical facet to add
* @return {SearchParameters}
* @throws will throw an error if a hierarchical facet with the same name was already declared
*/
addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
throw new Error(
'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
}
return this.setQueryParameters({
hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
});
},
/**
* Add a refinement on a "normal" facet
* @method
* @param {string} facet attribute to apply the faceting on
* @param {string} value value of the attribute (will be converted to string)
* @return {SearchParameters}
*/
addFacetRefinement: function addFacetRefinement(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
return this.setQueryParameters({
facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
});
},
/**
* Exclude a value from a "normal" facet
* @method
* @param {string} facet attribute to apply the exclusion on
* @param {string} value value of the attribute (will be converted to string)
* @return {SearchParameters}
*/
addExcludeRefinement: function addExcludeRefinement(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
return this.setQueryParameters({
facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
});
},
/**
* Adds a refinement on a disjunctive facet.
* @method
* @param {string} facet attribute to apply the faceting on
* @param {string} value value of the attribute (will be converted to string)
* @return {SearchParameters}
*/
addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
if (!this.isDisjunctiveFacet(facet)) {
throw new Error(
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
}
if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
return this.setQueryParameters({
disjunctiveFacetsRefinements: RefinementList.addRefinement(
this.disjunctiveFacetsRefinements, facet, value)
});
},
/**
* addTagRefinement adds a tag to the list used to filter the results
* @param {string} tag tag to be added
* @return {SearchParameters}
*/
addTagRefinement: function addTagRefinement(tag) {
if (this.isTagRefined(tag)) return this;
var modification = {
tagRefinements: this.tagRefinements.concat(tag)
};
return this.setQueryParameters(modification);
},
/**
* Remove a facet from the facets attribute of the helper configuration, if it
* is present.
* @method
* @param {string} facet facet name to remove
* @return {SearchParameters}
*/
removeFacet: function removeFacet(facet) {
if (!this.isConjunctiveFacet(facet)) {
return this;
}
return this.clearRefinements(facet).setQueryParameters({
facets: filter_1(this.facets, function(f) {
return f !== facet;
})
});
},
/**
* Remove a disjunctive facet from the disjunctiveFacets attribute of the
* helper configuration, if it is present.
* @method
* @param {string} facet disjunctive facet name to remove
* @return {SearchParameters}
*/
removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
if (!this.isDisjunctiveFacet(facet)) {
return this;
}
return this.clearRefinements(facet).setQueryParameters({
disjunctiveFacets: filter_1(this.disjunctiveFacets, function(f) {
return f !== facet;
})
});
},
/**
* Remove a hierarchical facet from the hierarchicalFacets attribute of the
* helper configuration, if it is present.
* @method
* @param {string} facet hierarchical facet name to remove
* @return {SearchParameters}
*/
removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
if (!this.isHierarchicalFacet(facet)) {
return this;
}
return this.clearRefinements(facet).setQueryParameters({
hierarchicalFacets: filter_1(this.hierarchicalFacets, function(f) {
return f.name !== facet;
})
});
},
/**
* Remove a refinement set on facet. If a value is provided, it will clear the
* refinement for the given value, otherwise it will clear all the refinement
* values for the faceted attribute.
* @method
* @param {string} facet name of the attribute used for faceting
* @param {string} [value] value used to filter
* @return {SearchParameters}
*/
removeFacetRefinement: function removeFacetRefinement(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
return this.setQueryParameters({
facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
});
},
/**
* Remove a negative refinement on a facet
* @method
* @param {string} facet name of the attribute used for faceting
* @param {string} value value used to filter
* @return {SearchParameters}
*/
removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
return this.setQueryParameters({
facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
});
},
/**
* Remove a refinement on a disjunctive facet
* @method
* @param {string} facet name of the attribute used for faceting
* @param {string} value value used to filter
* @return {SearchParameters}
*/
removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
if (!this.isDisjunctiveFacet(facet)) {
throw new Error(
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
}
if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
return this.setQueryParameters({
disjunctiveFacetsRefinements: RefinementList.removeRefinement(
this.disjunctiveFacetsRefinements, facet, value)
});
},
/**
* Remove a tag from the list of tag refinements
* @method
* @param {string} tag the tag to remove
* @return {SearchParameters}
*/
removeTagRefinement: function removeTagRefinement(tag) {
if (!this.isTagRefined(tag)) return this;
var modification = {
tagRefinements: filter_1(this.tagRefinements, function(t) { return t !== tag; })
};
return this.setQueryParameters(modification);
},
/**
* Generic toggle refinement method to use with facet, disjunctive facets
* and hierarchical facets
* @param {string} facet the facet to refine
* @param {string} value the associated value
* @return {SearchParameters}
* @throws will throw an error if the facet is not declared in the settings of the helper
* @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
*/
toggleRefinement: function toggleRefinement(facet, value) {
return this.toggleFacetRefinement(facet, value);
},
/**
* Generic toggle refinement method to use with facet, disjunctive facets
* and hierarchical facets
* @param {string} facet the facet to refine
* @param {string} value the associated value
* @return {SearchParameters}
* @throws will throw an error if the facet is not declared in the settings of the helper
*/
toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
if (this.isHierarchicalFacet(facet)) {
return this.toggleHierarchicalFacetRefinement(facet, value);
} else if (this.isConjunctiveFacet(facet)) {
return this.toggleConjunctiveFacetRefinement(facet, value);
} else if (this.isDisjunctiveFacet(facet)) {
return this.toggleDisjunctiveFacetRefinement(facet, value);
}
throw new Error('Cannot refine the undeclared facet ' + facet +
'; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
},
/**
* Switch the refinement applied over a facet/value
* @method
* @param {string} facet name of the attribute used for faceting
* @param {value} value value used for filtering
* @return {SearchParameters}
*/
toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
return this.setQueryParameters({
facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
});
},
/**
* Switch the refinement applied over a facet/value
* @method
* @param {string} facet name of the attribute used for faceting
* @param {value} value value used for filtering
* @return {SearchParameters}
*/
toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
return this.setQueryParameters({
facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
});
},
/**
* Switch the refinement applied over a facet/value
* @method
* @param {string} facet name of the attribute used for faceting
* @param {value} value value used for filtering
* @return {SearchParameters}
*/
toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
if (!this.isDisjunctiveFacet(facet)) {
throw new Error(
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
}
return this.setQueryParameters({
disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
this.disjunctiveFacetsRefinements, facet, value)
});
},
/**
* Switch the refinement applied over a facet/value
* @method
* @param {string} facet name of the attribute used for faceting
* @param {value} value value used for filtering
* @return {SearchParameters}
*/
toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
if (!this.isHierarchicalFacet(facet)) {
throw new Error(
facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
}
var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
var mod = {};
var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
this.hierarchicalFacetsRefinements[facet].length > 0 && (
// remove current refinement:
// refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
this.hierarchicalFacetsRefinements[facet][0] === value ||
// remove a parent refinement of the current refinement:
// - refinement was 'beer > IPA > Flying dog'
// - call is toggleRefine('beer > IPA')
// - refinement should be `beer`
this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
);
if (upOneOrMultipleLevel) {
if (value.indexOf(separator) === -1) {
// go back to root level
mod[facet] = [];
} else {
mod[facet] = [value.slice(0, value.lastIndexOf(separator))];
}
} else {
mod[facet] = [value];
}
return this.setQueryParameters({
hierarchicalFacetsRefinements: defaults_1({}, mod, this.hierarchicalFacetsRefinements)
});
},
/**
* Adds a refinement on a hierarchical facet.
* @param {string} facet the facet name
* @param {string} path the hierarchical facet path
* @return {SearchParameter} the new state
* @throws Error if the facet is not defined or if the facet is refined
*/
addHierarchicalFacetRefinement: function(facet, path) {
if (this.isHierarchicalFacetRefined(facet)) {
throw new Error(facet + ' is already refined.');
}
var mod = {};
mod[facet] = [path];
return this.setQueryParameters({
hierarchicalFacetsRefinements: defaults_1({}, mod, this.hierarchicalFacetsRefinements)
});
},
/**
* Removes the refinement set on a hierarchical facet.
* @param {string} facet the facet name
* @return {SearchParameter} the new state
* @throws Error if the facet is not defined or if the facet is not refined
*/
removeHierarchicalFacetRefinement: function(facet) {
if (!this.isHierarchicalFacetRefined(facet)) {
throw new Error(facet + ' is not refined.');
}
var mod = {};
mod[facet] = [];
return this.setQueryParameters({
hierarchicalFacetsRefinements: defaults_1({}, mod, this.hierarchicalFacetsRefinements)
});
},
/**
* Switch the tag refinement
* @method
* @param {string} tag the tag to remove or add
* @return {SearchParameters}
*/
toggleTagRefinement: function toggleTagRefinement(tag) {
if (this.isTagRefined(tag)) {
return this.removeTagRefinement(tag);
}
return this.addTagRefinement(tag);
},
/**
* Test if the facet name is from one of the disjunctive facets
* @method
* @param {string} facet facet name to test
* @return {boolean}
*/
isDisjunctiveFacet: function(facet) {
return indexOf_1(this.disjunctiveFacets, facet) > -1;
},
/**
* Test if the facet name is from one of the hierarchical facets
* @method
* @param {string} facetName facet name to test
* @return {boolean}
*/
isHierarchicalFacet: function(facetName) {
return this.getHierarchicalFacetByName(facetName) !== undefined;
},
/**
* Test if the facet name is from one of the conjunctive/normal facets
* @method
* @param {string} facet facet name to test
* @return {boolean}
*/
isConjunctiveFacet: function(facet) {
return indexOf_1(this.facets, facet) > -1;
},
/**
* Returns true if the facet is refined, either for a specific value or in
* general.
* @method
* @param {string} facet name of the attribute for used for faceting
* @param {string} value, optional value. If passed will test that this value
* is filtering the given facet.
* @return {boolean} returns true if refined
*/
isFacetRefined: function isFacetRefined(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
return RefinementList.isRefined(this.facetsRefinements, facet, value);
},
/**
* Returns true if the facet contains exclusions or if a specific value is
* excluded.
*
* @method
* @param {string} facet name of the attribute for used for faceting
* @param {string} [value] optional value. If passed will test that this value
* is filtering the given facet.
* @return {boolean} returns true if refined
*/
isExcludeRefined: function isExcludeRefined(facet, value) {
if (!this.isConjunctiveFacet(facet)) {
throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
}
return RefinementList.isRefined(this.facetsExcludes, facet, value);
},
/**
* Returns true if the facet contains a refinement, or if a value passed is a
* refinement for the facet.
* @method
* @param {string} facet name of the attribute for used for faceting
* @param {string} value optional, will test if the value is used for refinement
* if there is one, otherwise will test if the facet contains any refinement
* @return {boolean}
*/
isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
if (!this.isDisjunctiveFacet(facet)) {
throw new Error(
facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
}
return RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value);
},
/**
* Returns true if the facet contains a refinement, or if a value passed is a
* refinement for the facet.
* @method
* @param {string} facet name of the attribute for used for faceting
* @param {string} value optional, will test if the value is used for refinement
* if there is one, otherwise will test if the facet contains any refinement
* @return {boolean}
*/
isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
if (!this.isHierarchicalFacet(facet)) {
throw new Error(
facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
}
var refinements = this.getHierarchicalRefinement(facet);
if (!value) {
return refinements.length > 0;
}
return indexOf_1(refinements, value) !== -1;
},
/**
* Test if the triple (attribute, operator, value) is already refined.
* If only the attribute and the operator are provided, it tests if the
* contains any refinement value.
* @method
* @param {string} attribute attribute for which the refinement is applied
* @param {string} [operator] operator of the refinement
* @param {string} [value] value of the refinement
* @return {boolean} true if it is refined
*/
isNumericRefined: function isNumericRefined(attribute, operator, value) {
if (isUndefined_1(value) && isUndefined_1(operator)) {
return !!this.numericRefinements[attribute];
}
var isOperatorDefined = this.numericRefinements[attribute] &&
!isUndefined_1(this.numericRefinements[attribute][operator]);
if (isUndefined_1(value) || !isOperatorDefined) {
return isOperatorDefined;
}
var parsedValue = valToNumber_1(value);
var isAttributeValueDefined = !isUndefined_1(
findArray(this.numericRefinements[attribute][operator], parsedValue)
);
return isOperatorDefined && isAttributeValueDefined;
},
/**
* Returns true if the tag refined, false otherwise
* @method
* @param {string} tag the tag to check
* @return {boolean}
*/
isTagRefined: function isTagRefined(tag) {
return indexOf_1(this.tagRefinements, tag) !== -1;
},
/**
* Returns the list of all disjunctive facets refined
* @method
* @param {string} facet name of the attribute used for faceting
* @param {value} value value used for filtering
* @return {string[]}
*/
getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
// attributes used for numeric filter can also be disjunctive
var disjunctiveNumericRefinedFacets = intersection_1(
keys_1(this.numericRefinements),
this.disjunctiveFacets
);
return keys_1(this.disjunctiveFacetsRefinements)
.concat(disjunctiveNumericRefinedFacets)
.concat(this.getRefinedHierarchicalFacets());
},
/**
* Returns the list of all disjunctive facets refined
* @method
* @param {string} facet name of the attribute used for faceting
* @param {value} value value used for filtering
* @return {string[]}
*/
getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
return intersection_1(
// enforce the order between the two arrays,
// so that refinement name index === hierarchical facet index
map_1(this.hierarchicalFacets, 'name'),
keys_1(this.hierarchicalFacetsRefinements)
);
},
/**
* Returned the list of all disjunctive facets not refined
* @method
* @return {string[]}
*/
getUnrefinedDisjunctiveFacets: function() {
var refinedFacets = this.getRefinedDisjunctiveFacets();
return filter_1(this.disjunctiveFacets, function(f) {
return indexOf_1(refinedFacets, f) === -1;
});
},
managedParameters: [
'index',
'facets', 'disjunctiveFacets', 'facetsRefinements',
'facetsExcludes', 'disjunctiveFacetsRefinements',
'numericRefinements', 'tagRefinements', 'hierarchicalFacets', 'hierarchicalFacetsRefinements'
],
getQueryParams: function getQueryParams() {
var managedParameters = this.managedParameters;
var queryParams = {};
forOwn_1(this, function(paramValue, paramName) {
if (indexOf_1(managedParameters, paramName) === -1 && paramValue !== undefined) {
queryParams[paramName] = paramValue;
}
});
return queryParams;
},
/**
* Let the user retrieve any parameter value from the SearchParameters
* @param {string} paramName name of the parameter
* @return {any} the value of the parameter
*/
getQueryParameter: function getQueryParameter(paramName) {
if (!this.hasOwnProperty(paramName)) {
throw new Error(
"Parameter '" + paramName + "' is not an attribute of SearchParameters " +
'(http://algolia.github.io/algoliasearch-helper-js/docs/SearchParameters.html)');
}
return this[paramName];
},
/**
* Let the user set a specific value for a given parameter. Will return the
* same instance if the parameter is invalid or if the value is the same as the
* previous one.
* @method
* @param {string} parameter the parameter name
* @param {any} value the value to be set, must be compliant with the definition
* of the attribute on the object
* @return {SearchParameters} the updated state
*/
setQueryParameter: function setParameter(parameter, value) {
if (this[parameter] === value) return this;
var modification = {};
modification[parameter] = value;
return this.setQueryParameters(modification);
},
/**
* Let the user set any of the parameters with a plain object.
* @method
* @param {object} params all the keys and the values to be updated
* @return {SearchParameters} a new updated instance
*/
setQueryParameters: function setQueryParameters(params) {
if (!params) return this;
var error = SearchParameters.validate(this, params);
if (error) {
throw error;
}
var parsedParams = SearchParameters._parseNumbers(params);
return this.mutateMe(function mergeWith(newInstance) {
var ks = keys_1(params);
forEach_1(ks, function(k) {
newInstance[k] = parsedParams[k];
});
return newInstance;
});
},
/**
* Returns an object with only the selected attributes.
* @param {string[]} filters filters to retrieve only a subset of the state. It
* accepts strings that can be either attributes of the SearchParameters (e.g. hitsPerPage)
* or attributes of the index with the notation 'attribute:nameOfMyAttribute'
* @return {object}
*/
filter: function(filters) {
return filterState_1(this, filters);
},
/**
* Helper function to make it easier to build new instances from a mutating
* function
* @private
* @param {function} fn newMutableState -> previousState -> () function that will
* change the value of the newMutable to the desired state
* @return {SearchParameters} a new instance with the specified modifications applied
*/
mutateMe: function mutateMe(fn) {
var newState = new this.constructor(this);
fn(newState, this);
return newState;
},
/**
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
* @param {object} hierarchicalFacet
* @return {string} returns the hierarchicalFacet.separator or `>` as default
*/
_getHierarchicalFacetSortBy: function(hierarchicalFacet) {
return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
},
/**
* Helper function to get the hierarchicalFacet separator or the default one (`>`)
* @private
* @param {object} hierarchicalFacet
* @return {string} returns the hierarchicalFacet.separator or `>` as default
*/
_getHierarchicalFacetSeparator: function(hierarchicalFacet) {
return hierarchicalFacet.separator || ' > ';
},
/**
* Helper function to get the hierarchicalFacet prefix path or null
* @private
* @param {object} hierarchicalFacet
* @return {string} returns the hierarchicalFacet.rootPath or null as default
*/
_getHierarchicalRootPath: function(hierarchicalFacet) {
return hierarchicalFacet.rootPath || null;
},
/**
* Helper function to check if we show the parent level of the hierarchicalFacet
* @private
* @param {object} hierarchicalFacet
* @return {string} returns the hierarchicalFacet.showParentLevel or true as default
*/
_getHierarchicalShowParentLevel: function(hierarchicalFacet) {
if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
return hierarchicalFacet.showParentLevel;
}
return true;
},
/**
* Helper function to get the hierarchicalFacet by it's name
* @param {string} hierarchicalFacetName
* @return {object} a hierarchicalFacet
*/
getHierarchicalFacetByName: function(hierarchicalFacetName) {
return find_1(
this.hierarchicalFacets,
{name: hierarchicalFacetName}
);
},
/**
* Get the current breadcrumb for a hierarchical facet, as an array
* @param {string} facetName Hierarchical facet name
* @return {array.} the path as an array of string
*/
getHierarchicalFacetBreadcrumb: function(facetName) {
if (!this.isHierarchicalFacet(facetName)) {
throw new Error(
'Cannot get the breadcrumb of an unknown hierarchical facet: `' + facetName + '`');
}
var refinement = this.getHierarchicalRefinement(facetName)[0];
if (!refinement) return [];
var separator = this._getHierarchicalFacetSeparator(
this.getHierarchicalFacetByName(facetName)
);
var path = refinement.split(separator);
return map_1(path, trim_1);
},
toString: function() {
return JSON.stringify(this, null, 2);
}
};
/**
* Callback used for clearRefinement method
* @callback SearchParameters.clearCallback
* @param {OperatorList|FacetList} value the value of the filter
* @param {string} key the current attribute name
* @param {string} type `numeric`, `disjunctiveFacet`, `conjunctiveFacet`, `hierarchicalFacet` or `exclude`
* depending on the type of facet
* @return {boolean} `true` if the element should be removed. `false` otherwise.
*/
var SearchParameters_1 = SearchParameters;
/**
* Creates an array with all falsey values removed. The values `false`, `null`,
* `0`, `""`, `undefined`, and `NaN` are falsey.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to compact.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.compact([0, 1, false, 2, '', 3]);
* // => [1, 2, 3]
*/
function compact(array) {
var index = -1,
length = array == null ? 0 : array.length,
resIndex = 0,
result = [];
while (++index < length) {
var value = array[index];
if (value) {
result[resIndex++] = value;
}
}
return result;
}
var compact_1 = compact;
/**
* The base implementation of `_.sum` and `_.sumBy` without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sum.
*/
function baseSum(array, iteratee) {
var result,
index = -1,
length = array.length;
while (++index < length) {
var current = iteratee(array[index]);
if (current !== undefined) {
result = result === undefined ? current : (result + current);
}
}
return result;
}
var _baseSum = baseSum;
/**
* This method is like `_.sum` except that it accepts `iteratee` which is
* invoked for each element in `array` to generate the value to be summed.
* The iteratee is invoked with one argument: (value).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Math
* @param {Array} array The array to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @returns {number} Returns the sum.
* @example
*
* var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
*
* _.sumBy(objects, function(o) { return o.n; });
* // => 20
*
* // The `_.property` iteratee shorthand.
* _.sumBy(objects, 'n');
* // => 20
*/
function sumBy(array, iteratee) {
return (array && array.length)
? _baseSum(array, _baseIteratee(iteratee, 2))
: 0;
}
var sumBy_1 = sumBy;
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* of `props`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
*/
function baseValues(object, props) {
return _arrayMap(props, function(key) {
return object[key];
});
}
var _baseValues = baseValues;
/**
* Creates an array of the own enumerable string keyed property values of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property values.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.values(new Foo);
* // => [1, 2] (iteration order is not guaranteed)
*
* _.values('hi');
* // => ['h', 'i']
*/
function values(object) {
return object == null ? [] : _baseValues(object, keys_1(object));
}
var values_1 = values;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax$3 = Math.max;
/**
* Checks if `value` is in `collection`. If `collection` is a string, it's
* checked for a substring of `value`, otherwise
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* is used for equality comparisons. If `fromIndex` is negative, it's used as
* the offset from the end of `collection`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object|string} collection The collection to inspect.
* @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
* @returns {boolean} Returns `true` if `value` is found, else `false`.
* @example
*
* _.includes([1, 2, 3], 1);
* // => true
*
* _.includes([1, 2, 3], 1, 2);
* // => false
*
* _.includes({ 'a': 1, 'b': 2 }, 1);
* // => true
*
* _.includes('abcd', 'bc');
* // => true
*/
function includes(collection, value, fromIndex, guard) {
collection = isArrayLike_1(collection) ? collection : values_1(collection);
fromIndex = (fromIndex && !guard) ? toInteger_1(fromIndex) : 0;
var length = collection.length;
if (fromIndex < 0) {
fromIndex = nativeMax$3(length + fromIndex, 0);
}
return isString_1(collection)
? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
: (!!length && _baseIndexOf(collection, value, fromIndex) > -1);
}
var includes_1 = includes;
/**
* The base implementation of `_.sortBy` which uses `comparer` to define the
* sort order of `array` and replaces criteria objects with their corresponding
* values.
*
* @private
* @param {Array} array The array to sort.
* @param {Function} comparer The function to define sort order.
* @returns {Array} Returns `array`.
*/
function baseSortBy(array, comparer) {
var length = array.length;
array.sort(comparer);
while (length--) {
array[length] = array[length].value;
}
return array;
}
var _baseSortBy = baseSortBy;
/**
* Compares values to sort them in ascending order.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {number} Returns the sort order indicator for `value`.
*/
function compareAscending(value, other) {
if (value !== other) {
var valIsDefined = value !== undefined,
valIsNull = value === null,
valIsReflexive = value === value,
valIsSymbol = isSymbol_1(value);
var othIsDefined = other !== undefined,
othIsNull = other === null,
othIsReflexive = other === other,
othIsSymbol = isSymbol_1(other);
if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
(valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
(valIsNull && othIsDefined && othIsReflexive) ||
(!valIsDefined && othIsReflexive) ||
!valIsReflexive) {
return 1;
}
if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
(othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
(othIsNull && valIsDefined && valIsReflexive) ||
(!othIsDefined && valIsReflexive) ||
!othIsReflexive) {
return -1;
}
}
return 0;
}
var _compareAscending = compareAscending;
/**
* Used by `_.orderBy` to compare multiple properties of a value to another
* and stable sort them.
*
* If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
* specify an order of "desc" for descending or "asc" for ascending sort order
* of corresponding values.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {boolean[]|string[]} orders The order to sort by for each property.
* @returns {number} Returns the sort order indicator for `object`.
*/
function compareMultiple(object, other, orders) {
var index = -1,
objCriteria = object.criteria,
othCriteria = other.criteria,
length = objCriteria.length,
ordersLength = orders.length;
while (++index < length) {
var result = _compareAscending(objCriteria[index], othCriteria[index]);
if (result) {
if (index >= ordersLength) {
return result;
}
var order = orders[index];
return result * (order == 'desc' ? -1 : 1);
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provide the same value for
// `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
// for more details.
//
// This also ensures a stable sort in V8 and other engines.
// See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
return object.index - other.index;
}
var _compareMultiple = compareMultiple;
/**
* The base implementation of `_.orderBy` without param guards.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {string[]} orders The sort orders of `iteratees`.
* @returns {Array} Returns the new sorted array.
*/
function baseOrderBy(collection, iteratees, orders) {
var index = -1;
iteratees = _arrayMap(iteratees.length ? iteratees : [identity_1], _baseUnary(_baseIteratee));
var result = _baseMap(collection, function(value, key, collection) {
var criteria = _arrayMap(iteratees, function(iteratee) {
return iteratee(value);
});
return { 'criteria': criteria, 'index': ++index, 'value': value };
});
return _baseSortBy(result, function(object, other) {
return _compareMultiple(object, other, orders);
});
}
var _baseOrderBy = baseOrderBy;
/**
* This method is like `_.sortBy` except that it allows specifying the sort
* orders of the iteratees to sort by. If `orders` is unspecified, all values
* are sorted in ascending order. Otherwise, specify an order of "desc" for
* descending or "asc" for ascending sort order of corresponding values.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
* The iteratees to sort by.
* @param {string[]} [orders] The sort orders of `iteratees`.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 34 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 }
* ];
*
* // Sort by `user` in ascending order and by `age` in descending order.
* _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
*/
function orderBy(collection, iteratees, orders, guard) {
if (collection == null) {
return [];
}
if (!isArray_1(iteratees)) {
iteratees = iteratees == null ? [] : [iteratees];
}
orders = guard ? undefined : orders;
if (!isArray_1(orders)) {
orders = orders == null ? [] : [orders];
}
return _baseOrderBy(collection, iteratees, orders);
}
var orderBy_1 = orderBy;
/** Used to store function metadata. */
var metaMap = _WeakMap && new _WeakMap;
var _metaMap = metaMap;
/**
* The base implementation of `setData` without support for hot loop shorting.
*
* @private
* @param {Function} func The function to associate metadata with.
* @param {*} data The metadata.
* @returns {Function} Returns `func`.
*/
var baseSetData = !_metaMap ? identity_1 : function(func, data) {
_metaMap.set(func, data);
return func;
};
var _baseSetData = baseSetData;
/**
* Creates a function that produces an instance of `Ctor` regardless of
* whether it was invoked as part of a `new` expression or by `call` or `apply`.
*
* @private
* @param {Function} Ctor The constructor to wrap.
* @returns {Function} Returns the new wrapped function.
*/
function createCtor(Ctor) {
return function() {
// Use a `switch` statement to work with class constructors. See
// http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
// for more details.
var args = arguments;
switch (args.length) {
case 0: return new Ctor;
case 1: return new Ctor(args[0]);
case 2: return new Ctor(args[0], args[1]);
case 3: return new Ctor(args[0], args[1], args[2]);
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
}
var thisBinding = _baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, args);
// Mimic the constructor's `return` behavior.
// See https://es5.github.io/#x13.2.2 for more details.
return isObject_1(result) ? result : thisBinding;
};
}
var _createCtor = createCtor;
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG = 1;
/**
* Creates a function that wraps `func` to invoke it with the optional `this`
* binding of `thisArg`.
*
* @private
* @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @param {*} [thisArg] The `this` binding of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createBind(func, bitmask, thisArg) {
var isBind = bitmask & WRAP_BIND_FLAG,
Ctor = _createCtor(func);
function wrapper() {
var fn = (this && this !== _root && this instanceof wrapper) ? Ctor : func;
return fn.apply(isBind ? thisArg : this, arguments);
}
return wrapper;
}
var _createBind = createBind;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax$4 = Math.max;
/**
* Creates an array that is the composition of partially applied arguments,
* placeholders, and provided arguments into a single array of arguments.
*
* @private
* @param {Array} args The provided arguments.
* @param {Array} partials The arguments to prepend to those provided.
* @param {Array} holders The `partials` placeholder indexes.
* @params {boolean} [isCurried] Specify composing for a curried function.
* @returns {Array} Returns the new array of composed arguments.
*/
function composeArgs(args, partials, holders, isCurried) {
var argsIndex = -1,
argsLength = args.length,
holdersLength = holders.length,
leftIndex = -1,
leftLength = partials.length,
rangeLength = nativeMax$4(argsLength - holdersLength, 0),
result = Array(leftLength + rangeLength),
isUncurried = !isCurried;
while (++leftIndex < leftLength) {
result[leftIndex] = partials[leftIndex];
}
while (++argsIndex < holdersLength) {
if (isUncurried || argsIndex < argsLength) {
result[holders[argsIndex]] = args[argsIndex];
}
}
while (rangeLength--) {
result[leftIndex++] = args[argsIndex++];
}
return result;
}
var _composeArgs = composeArgs;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax$5 = Math.max;
/**
* This function is like `composeArgs` except that the arguments composition
* is tailored for `_.partialRight`.
*
* @private
* @param {Array} args The provided arguments.
* @param {Array} partials The arguments to append to those provided.
* @param {Array} holders The `partials` placeholder indexes.
* @params {boolean} [isCurried] Specify composing for a curried function.
* @returns {Array} Returns the new array of composed arguments.
*/
function composeArgsRight(args, partials, holders, isCurried) {
var argsIndex = -1,
argsLength = args.length,
holdersIndex = -1,
holdersLength = holders.length,
rightIndex = -1,
rightLength = partials.length,
rangeLength = nativeMax$5(argsLength - holdersLength, 0),
result = Array(rangeLength + rightLength),
isUncurried = !isCurried;
while (++argsIndex < rangeLength) {
result[argsIndex] = args[argsIndex];
}
var offset = argsIndex;
while (++rightIndex < rightLength) {
result[offset + rightIndex] = partials[rightIndex];
}
while (++holdersIndex < holdersLength) {
if (isUncurried || argsIndex < argsLength) {
result[offset + holders[holdersIndex]] = args[argsIndex++];
}
}
return result;
}
var _composeArgsRight = composeArgsRight;
/**
* Gets the number of `placeholder` occurrences in `array`.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} placeholder The placeholder to search for.
* @returns {number} Returns the placeholder count.
*/
function countHolders(array, placeholder) {
var length = array.length,
result = 0;
while (length--) {
if (array[length] === placeholder) {
++result;
}
}
return result;
}
var _countHolders = countHolders;
/**
* The function whose prototype chain sequence wrappers inherit from.
*
* @private
*/
function baseLodash() {
// No operation performed.
}
var _baseLodash = baseLodash;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = 4294967295;
/**
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
*
* @private
* @constructor
* @param {*} value The value to wrap.
*/
function LazyWrapper(value) {
this.__wrapped__ = value;
this.__actions__ = [];
this.__dir__ = 1;
this.__filtered__ = false;
this.__iteratees__ = [];
this.__takeCount__ = MAX_ARRAY_LENGTH;
this.__views__ = [];
}
// Ensure `LazyWrapper` is an instance of `baseLodash`.
LazyWrapper.prototype = _baseCreate(_baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
var _LazyWrapper = LazyWrapper;
/**
* This method returns `undefined`.
*
* @static
* @memberOf _
* @since 2.3.0
* @category Util
* @example
*
* _.times(2, _.noop);
* // => [undefined, undefined]
*/
function noop() {
// No operation performed.
}
var noop_1 = noop;
/**
* Gets metadata for `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {*} Returns the metadata for `func`.
*/
var getData = !_metaMap ? noop_1 : function(func) {
return _metaMap.get(func);
};
var _getData = getData;
/** Used to lookup unminified function names. */
var realNames = {};
var _realNames = realNames;
/** Used for built-in method references. */
var objectProto$i = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$f = objectProto$i.hasOwnProperty;
/**
* Gets the name of `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {string} Returns the function name.
*/
function getFuncName(func) {
var result = (func.name + ''),
array = _realNames[result],
length = hasOwnProperty$f.call(_realNames, result) ? array.length : 0;
while (length--) {
var data = array[length],
otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
}
}
return result;
}
var _getFuncName = getFuncName;
/**
* The base constructor for creating `lodash` wrapper objects.
*
* @private
* @param {*} value The value to wrap.
* @param {boolean} [chainAll] Enable explicit method chain sequences.
*/
function LodashWrapper(value, chainAll) {
this.__wrapped__ = value;
this.__actions__ = [];
this.__chain__ = !!chainAll;
this.__index__ = 0;
this.__values__ = undefined;
}
LodashWrapper.prototype = _baseCreate(_baseLodash.prototype);
LodashWrapper.prototype.constructor = LodashWrapper;
var _LodashWrapper = LodashWrapper;
/**
* Creates a clone of `wrapper`.
*
* @private
* @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the cloned wrapper.
*/
function wrapperClone(wrapper) {
if (wrapper instanceof _LazyWrapper) {
return wrapper.clone();
}
var result = new _LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
result.__actions__ = _copyArray(wrapper.__actions__);
result.__index__ = wrapper.__index__;
result.__values__ = wrapper.__values__;
return result;
}
var _wrapperClone = wrapperClone;
/** Used for built-in method references. */
var objectProto$j = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$g = objectProto$j.hasOwnProperty;
/**
* Creates a `lodash` object which wraps `value` to enable implicit method
* chain sequences. Methods that operate on and return arrays, collections,
* and functions can be chained together. Methods that retrieve a single value
* or may return a primitive value will automatically end the chain sequence
* and return the unwrapped value. Otherwise, the value must be unwrapped
* with `_#value`.
*
* Explicit chain sequences, which must be unwrapped with `_#value`, may be
* enabled using `_.chain`.
*
* The execution of chained methods is lazy, that is, it's deferred until
* `_#value` is implicitly or explicitly called.
*
* Lazy evaluation allows several methods to support shortcut fusion.
* Shortcut fusion is an optimization to merge iteratee calls; this avoids
* the creation of intermediate arrays and can greatly reduce the number of
* iteratee executions. Sections of a chain sequence qualify for shortcut
* fusion if the section is applied to an array and iteratees accept only
* one argument. The heuristic for whether a section qualifies for shortcut
* fusion is subject to change.
*
* Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build.
*
* In addition to lodash methods, wrappers have `Array` and `String` methods.
*
* The wrapper `Array` methods are:
* `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
*
* The wrapper `String` methods are:
* `replace` and `split`
*
* The wrapper methods that support shortcut fusion are:
* `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
* `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
* `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
*
* The chainable wrapper methods are:
* `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
* `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
* `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
* `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
* `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
* `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
* `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
* `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
* `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
* `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
* `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
* `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
* `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
* `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
* `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
* `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
* `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
* `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
* `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
* `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
* `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
* `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
* `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
* `zipObject`, `zipObjectDeep`, and `zipWith`
*
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
* `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
* `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
* `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
* `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
* `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
* `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
* `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
* `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
* `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
* `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
* `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
* `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
* `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
* `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
* `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
* `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
* `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
* `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
* `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
* `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
* `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
* `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
* `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
* `upperFirst`, `value`, and `words`
*
* @name _
* @constructor
* @category Seq
* @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* function square(n) {
* return n * n;
* }
*
* var wrapped = _([1, 2, 3]);
*
* // Returns an unwrapped value.
* wrapped.reduce(_.add);
* // => 6
*
* // Returns a wrapped value.
* var squares = wrapped.map(square);
*
* _.isArray(squares);
* // => false
*
* _.isArray(squares.value());
* // => true
*/
function lodash(value) {
if (isObjectLike_1(value) && !isArray_1(value) && !(value instanceof _LazyWrapper)) {
if (value instanceof _LodashWrapper) {
return value;
}
if (hasOwnProperty$g.call(value, '__wrapped__')) {
return _wrapperClone(value);
}
}
return new _LodashWrapper(value);
}
// Ensure wrappers are instances of `baseLodash`.
lodash.prototype = _baseLodash.prototype;
lodash.prototype.constructor = lodash;
var wrapperLodash = lodash;
/**
* Checks if `func` has a lazy counterpart.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` has a lazy counterpart,
* else `false`.
*/
function isLaziable(func) {
var funcName = _getFuncName(func),
other = wrapperLodash[funcName];
if (typeof other != 'function' || !(funcName in _LazyWrapper.prototype)) {
return false;
}
if (func === other) {
return true;
}
var data = _getData(other);
return !!data && func === data[0];
}
var _isLaziable = isLaziable;
/**
* Sets metadata for `func`.
*
* **Note:** If this function becomes hot, i.e. is invoked a lot in a short
* period of time, it will trip its breaker and transition to an identity
* function to avoid garbage collection pauses in V8. See
* [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
* for more details.
*
* @private
* @param {Function} func The function to associate metadata with.
* @param {*} data The metadata.
* @returns {Function} Returns `func`.
*/
var setData = _shortOut(_baseSetData);
var _setData = setData;
/** Used to match wrap detail comments. */
var reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
reSplitDetails = /,? & /;
/**
* Extracts wrapper details from the `source` body comment.
*
* @private
* @param {string} source The source to inspect.
* @returns {Array} Returns the wrapper details.
*/
function getWrapDetails(source) {
var match = source.match(reWrapDetails);
return match ? match[1].split(reSplitDetails) : [];
}
var _getWrapDetails = getWrapDetails;
/** Used to match wrap detail comments. */
var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/;
/**
* Inserts wrapper `details` in a comment at the top of the `source` body.
*
* @private
* @param {string} source The source to modify.
* @returns {Array} details The details to insert.
* @returns {string} Returns the modified source.
*/
function insertWrapDetails(source, details) {
var length = details.length;
if (!length) {
return source;
}
var lastIndex = length - 1;
details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
details = details.join(length > 2 ? ', ' : ' ');
return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
}
var _insertWrapDetails = insertWrapDetails;
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$1 = 1,
WRAP_BIND_KEY_FLAG = 2,
WRAP_CURRY_FLAG = 8,
WRAP_CURRY_RIGHT_FLAG = 16,
WRAP_PARTIAL_FLAG = 32,
WRAP_PARTIAL_RIGHT_FLAG = 64,
WRAP_ARY_FLAG = 128,
WRAP_REARG_FLAG = 256,
WRAP_FLIP_FLAG = 512;
/** Used to associate wrap methods with their bit flags. */
var wrapFlags = [
['ary', WRAP_ARY_FLAG],
['bind', WRAP_BIND_FLAG$1],
['bindKey', WRAP_BIND_KEY_FLAG],
['curry', WRAP_CURRY_FLAG],
['curryRight', WRAP_CURRY_RIGHT_FLAG],
['flip', WRAP_FLIP_FLAG],
['partial', WRAP_PARTIAL_FLAG],
['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
['rearg', WRAP_REARG_FLAG]
];
/**
* Updates wrapper `details` based on `bitmask` flags.
*
* @private
* @returns {Array} details The details to modify.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @returns {Array} Returns `details`.
*/
function updateWrapDetails(details, bitmask) {
_arrayEach(wrapFlags, function(pair) {
var value = '_.' + pair[0];
if ((bitmask & pair[1]) && !_arrayIncludes(details, value)) {
details.push(value);
}
});
return details.sort();
}
var _updateWrapDetails = updateWrapDetails;
/**
* Sets the `toString` method of `wrapper` to mimic the source of `reference`
* with wrapper details in a comment at the top of the source body.
*
* @private
* @param {Function} wrapper The function to modify.
* @param {Function} reference The reference function.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @returns {Function} Returns `wrapper`.
*/
function setWrapToString(wrapper, reference, bitmask) {
var source = (reference + '');
return _setToString(wrapper, _insertWrapDetails(source, _updateWrapDetails(_getWrapDetails(source), bitmask)));
}
var _setWrapToString = setWrapToString;
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$2 = 1,
WRAP_BIND_KEY_FLAG$1 = 2,
WRAP_CURRY_BOUND_FLAG = 4,
WRAP_CURRY_FLAG$1 = 8,
WRAP_PARTIAL_FLAG$1 = 32,
WRAP_PARTIAL_RIGHT_FLAG$1 = 64;
/**
* Creates a function that wraps `func` to continue currying.
*
* @private
* @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @param {Function} wrapFunc The function to create the `func` wrapper.
* @param {*} placeholder The placeholder value.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to
* the new function.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
var isCurry = bitmask & WRAP_CURRY_FLAG$1,
newHolders = isCurry ? holders : undefined,
newHoldersRight = isCurry ? undefined : holders,
newPartials = isCurry ? partials : undefined,
newPartialsRight = isCurry ? undefined : partials;
bitmask |= (isCurry ? WRAP_PARTIAL_FLAG$1 : WRAP_PARTIAL_RIGHT_FLAG$1);
bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG$1 : WRAP_PARTIAL_FLAG$1);
if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
bitmask &= ~(WRAP_BIND_FLAG$2 | WRAP_BIND_KEY_FLAG$1);
}
var newData = [
func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
newHoldersRight, argPos, ary, arity
];
var result = wrapFunc.apply(undefined, newData);
if (_isLaziable(func)) {
_setData(result, newData);
}
result.placeholder = placeholder;
return _setWrapToString(result, func, bitmask);
}
var _createRecurry = createRecurry;
/**
* Gets the argument placeholder value for `func`.
*
* @private
* @param {Function} func The function to inspect.
* @returns {*} Returns the placeholder value.
*/
function getHolder(func) {
var object = func;
return object.placeholder;
}
var _getHolder = getHolder;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMin$1 = Math.min;
/**
* Reorder `array` according to the specified indexes where the element at
* the first index is assigned as the first element, the element at
* the second index is assigned as the second element, and so on.
*
* @private
* @param {Array} array The array to reorder.
* @param {Array} indexes The arranged array indexes.
* @returns {Array} Returns `array`.
*/
function reorder(array, indexes) {
var arrLength = array.length,
length = nativeMin$1(indexes.length, arrLength),
oldArray = _copyArray(array);
while (length--) {
var index = indexes[length];
array[length] = _isIndex(index, arrLength) ? oldArray[index] : undefined;
}
return array;
}
var _reorder = reorder;
/** Used as the internal argument placeholder. */
var PLACEHOLDER = '__lodash_placeholder__';
/**
* Replaces all `placeholder` elements in `array` with an internal placeholder
* and returns an array of their indexes.
*
* @private
* @param {Array} array The array to modify.
* @param {*} placeholder The placeholder to replace.
* @returns {Array} Returns the new array of placeholder indexes.
*/
function replaceHolders(array, placeholder) {
var index = -1,
length = array.length,
resIndex = 0,
result = [];
while (++index < length) {
var value = array[index];
if (value === placeholder || value === PLACEHOLDER) {
array[index] = PLACEHOLDER;
result[resIndex++] = index;
}
}
return result;
}
var _replaceHolders = replaceHolders;
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$3 = 1,
WRAP_BIND_KEY_FLAG$2 = 2,
WRAP_CURRY_FLAG$2 = 8,
WRAP_CURRY_RIGHT_FLAG$1 = 16,
WRAP_ARY_FLAG$1 = 128,
WRAP_FLIP_FLAG$1 = 512;
/**
* Creates a function that wraps `func` to invoke it with optional `this`
* binding of `thisArg`, partial application, and currying.
*
* @private
* @param {Function|string} func The function or method name to wrap.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to
* the new function.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [partialsRight] The arguments to append to those provided
* to the new function.
* @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
var isAry = bitmask & WRAP_ARY_FLAG$1,
isBind = bitmask & WRAP_BIND_FLAG$3,
isBindKey = bitmask & WRAP_BIND_KEY_FLAG$2,
isCurried = bitmask & (WRAP_CURRY_FLAG$2 | WRAP_CURRY_RIGHT_FLAG$1),
isFlip = bitmask & WRAP_FLIP_FLAG$1,
Ctor = isBindKey ? undefined : _createCtor(func);
function wrapper() {
var length = arguments.length,
args = Array(length),
index = length;
while (index--) {
args[index] = arguments[index];
}
if (isCurried) {
var placeholder = _getHolder(wrapper),
holdersCount = _countHolders(args, placeholder);
}
if (partials) {
args = _composeArgs(args, partials, holders, isCurried);
}
if (partialsRight) {
args = _composeArgsRight(args, partialsRight, holdersRight, isCurried);
}
length -= holdersCount;
if (isCurried && length < arity) {
var newHolders = _replaceHolders(args, placeholder);
return _createRecurry(
func, bitmask, createHybrid, wrapper.placeholder, thisArg,
args, newHolders, argPos, ary, arity - length
);
}
var thisBinding = isBind ? thisArg : this,
fn = isBindKey ? thisBinding[func] : func;
length = args.length;
if (argPos) {
args = _reorder(args, argPos);
} else if (isFlip && length > 1) {
args.reverse();
}
if (isAry && ary < length) {
args.length = ary;
}
if (this && this !== _root && this instanceof wrapper) {
fn = Ctor || _createCtor(fn);
}
return fn.apply(thisBinding, args);
}
return wrapper;
}
var _createHybrid = createHybrid;
/**
* Creates a function that wraps `func` to enable currying.
*
* @private
* @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @param {number} arity The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createCurry(func, bitmask, arity) {
var Ctor = _createCtor(func);
function wrapper() {
var length = arguments.length,
args = Array(length),
index = length,
placeholder = _getHolder(wrapper);
while (index--) {
args[index] = arguments[index];
}
var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
? []
: _replaceHolders(args, placeholder);
length -= holders.length;
if (length < arity) {
return _createRecurry(
func, bitmask, _createHybrid, wrapper.placeholder, undefined,
args, holders, undefined, undefined, arity - length);
}
var fn = (this && this !== _root && this instanceof wrapper) ? Ctor : func;
return _apply(fn, this, args);
}
return wrapper;
}
var _createCurry = createCurry;
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$4 = 1;
/**
* Creates a function that wraps `func` to invoke it with the `this` binding
* of `thisArg` and `partials` prepended to the arguments it receives.
*
* @private
* @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask flags. See `createWrap` for more details.
* @param {*} thisArg The `this` binding of `func`.
* @param {Array} partials The arguments to prepend to those provided to
* the new function.
* @returns {Function} Returns the new wrapped function.
*/
function createPartial(func, bitmask, thisArg, partials) {
var isBind = bitmask & WRAP_BIND_FLAG$4,
Ctor = _createCtor(func);
function wrapper() {
var argsIndex = -1,
argsLength = arguments.length,
leftIndex = -1,
leftLength = partials.length,
args = Array(leftLength + argsLength),
fn = (this && this !== _root && this instanceof wrapper) ? Ctor : func;
while (++leftIndex < leftLength) {
args[leftIndex] = partials[leftIndex];
}
while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex];
}
return _apply(fn, isBind ? thisArg : this, args);
}
return wrapper;
}
var _createPartial = createPartial;
/** Used as the internal argument placeholder. */
var PLACEHOLDER$1 = '__lodash_placeholder__';
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$5 = 1,
WRAP_BIND_KEY_FLAG$3 = 2,
WRAP_CURRY_BOUND_FLAG$1 = 4,
WRAP_CURRY_FLAG$3 = 8,
WRAP_ARY_FLAG$2 = 128,
WRAP_REARG_FLAG$1 = 256;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMin$2 = Math.min;
/**
* Merges the function metadata of `source` into `data`.
*
* Merging metadata reduces the number of wrappers used to invoke a function.
* This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
* may be applied regardless of execution order. Methods like `_.ary` and
* `_.rearg` modify function arguments, making the order in which they are
* executed important, preventing the merging of metadata. However, we make
* an exception for a safe combined case where curried functions have `_.ary`
* and or `_.rearg` applied.
*
* @private
* @param {Array} data The destination metadata.
* @param {Array} source The source metadata.
* @returns {Array} Returns `data`.
*/
function mergeData(data, source) {
var bitmask = data[1],
srcBitmask = source[1],
newBitmask = bitmask | srcBitmask,
isCommon = newBitmask < (WRAP_BIND_FLAG$5 | WRAP_BIND_KEY_FLAG$3 | WRAP_ARY_FLAG$2);
var isCombo =
((srcBitmask == WRAP_ARY_FLAG$2) && (bitmask == WRAP_CURRY_FLAG$3)) ||
((srcBitmask == WRAP_ARY_FLAG$2) && (bitmask == WRAP_REARG_FLAG$1) && (data[7].length <= source[8])) ||
((srcBitmask == (WRAP_ARY_FLAG$2 | WRAP_REARG_FLAG$1)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG$3));
// Exit early if metadata can't be merged.
if (!(isCommon || isCombo)) {
return data;
}
// Use source `thisArg` if available.
if (srcBitmask & WRAP_BIND_FLAG$5) {
data[2] = source[2];
// Set when currying a bound function.
newBitmask |= bitmask & WRAP_BIND_FLAG$5 ? 0 : WRAP_CURRY_BOUND_FLAG$1;
}
// Compose partial arguments.
var value = source[3];
if (value) {
var partials = data[3];
data[3] = partials ? _composeArgs(partials, value, source[4]) : value;
data[4] = partials ? _replaceHolders(data[3], PLACEHOLDER$1) : source[4];
}
// Compose partial right arguments.
value = source[5];
if (value) {
partials = data[5];
data[5] = partials ? _composeArgsRight(partials, value, source[6]) : value;
data[6] = partials ? _replaceHolders(data[5], PLACEHOLDER$1) : source[6];
}
// Use source `argPos` if available.
value = source[7];
if (value) {
data[7] = value;
}
// Use source `ary` if it's smaller.
if (srcBitmask & WRAP_ARY_FLAG$2) {
data[8] = data[8] == null ? source[8] : nativeMin$2(data[8], source[8]);
}
// Use source `arity` if one is not provided.
if (data[9] == null) {
data[9] = source[9];
}
// Use source `func` and merge bitmasks.
data[0] = source[0];
data[1] = newBitmask;
return data;
}
var _mergeData = mergeData;
/** Error message constants. */
var FUNC_ERROR_TEXT$1 = 'Expected a function';
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$6 = 1,
WRAP_BIND_KEY_FLAG$4 = 2,
WRAP_CURRY_FLAG$4 = 8,
WRAP_CURRY_RIGHT_FLAG$2 = 16,
WRAP_PARTIAL_FLAG$2 = 32,
WRAP_PARTIAL_RIGHT_FLAG$2 = 64;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax$6 = Math.max;
/**
* Creates a function that either curries or invokes `func` with optional
* `this` binding and partially applied arguments.
*
* @private
* @param {Function|string} func The function or method name to wrap.
* @param {number} bitmask The bitmask flags.
* 1 - `_.bind`
* 2 - `_.bindKey`
* 4 - `_.curry` or `_.curryRight` of a bound function
* 8 - `_.curry`
* 16 - `_.curryRight`
* 32 - `_.partial`
* 64 - `_.partialRight`
* 128 - `_.rearg`
* 256 - `_.ary`
* 512 - `_.flip`
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to be partially applied.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & WRAP_BIND_KEY_FLAG$4;
if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT$1);
}
var length = partials ? partials.length : 0;
if (!length) {
bitmask &= ~(WRAP_PARTIAL_FLAG$2 | WRAP_PARTIAL_RIGHT_FLAG$2);
partials = holders = undefined;
}
ary = ary === undefined ? ary : nativeMax$6(toInteger_1(ary), 0);
arity = arity === undefined ? arity : toInteger_1(arity);
length -= holders ? holders.length : 0;
if (bitmask & WRAP_PARTIAL_RIGHT_FLAG$2) {
var partialsRight = partials,
holdersRight = holders;
partials = holders = undefined;
}
var data = isBindKey ? undefined : _getData(func);
var newData = [
func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
argPos, ary, arity
];
if (data) {
_mergeData(newData, data);
}
func = newData[0];
bitmask = newData[1];
thisArg = newData[2];
partials = newData[3];
holders = newData[4];
arity = newData[9] = newData[9] === undefined
? (isBindKey ? 0 : func.length)
: nativeMax$6(newData[9] - length, 0);
if (!arity && bitmask & (WRAP_CURRY_FLAG$4 | WRAP_CURRY_RIGHT_FLAG$2)) {
bitmask &= ~(WRAP_CURRY_FLAG$4 | WRAP_CURRY_RIGHT_FLAG$2);
}
if (!bitmask || bitmask == WRAP_BIND_FLAG$6) {
var result = _createBind(func, bitmask, thisArg);
} else if (bitmask == WRAP_CURRY_FLAG$4 || bitmask == WRAP_CURRY_RIGHT_FLAG$2) {
result = _createCurry(func, bitmask, arity);
} else if ((bitmask == WRAP_PARTIAL_FLAG$2 || bitmask == (WRAP_BIND_FLAG$6 | WRAP_PARTIAL_FLAG$2)) && !holders.length) {
result = _createPartial(func, bitmask, thisArg, partials);
} else {
result = _createHybrid.apply(undefined, newData);
}
var setter = data ? _baseSetData : _setData;
return _setWrapToString(setter(result, newData), func, bitmask);
}
var _createWrap = createWrap;
/** Used to compose bitmasks for function metadata. */
var WRAP_PARTIAL_FLAG$3 = 32;
/**
* Creates a function that invokes `func` with `partials` prepended to the
* arguments it receives. This method is like `_.bind` except it does **not**
* alter the `this` binding.
*
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* **Note:** This method doesn't set the "length" property of partially
* applied functions.
*
* @static
* @memberOf _
* @since 0.2.0
* @category Function
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* function greet(greeting, name) {
* return greeting + ' ' + name;
* }
*
* var sayHelloTo = _.partial(greet, 'hello');
* sayHelloTo('fred');
* // => 'hello fred'
*
* // Partially applied with placeholders.
* var greetFred = _.partial(greet, _, 'fred');
* greetFred('hi');
* // => 'hi fred'
*/
var partial = _baseRest(function(func, partials) {
var holders = _replaceHolders(partials, _getHolder(partial));
return _createWrap(func, WRAP_PARTIAL_FLAG$3, undefined, partials, holders);
});
// Assign default placeholders.
partial.placeholder = {};
var partial_1 = partial;
/** Used to compose bitmasks for function metadata. */
var WRAP_PARTIAL_RIGHT_FLAG$3 = 64;
/**
* This method is like `_.partial` except that partially applied arguments
* are appended to the arguments it receives.
*
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* **Note:** This method doesn't set the "length" property of partially
* applied functions.
*
* @static
* @memberOf _
* @since 1.0.0
* @category Function
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* function greet(greeting, name) {
* return greeting + ' ' + name;
* }
*
* var greetFred = _.partialRight(greet, 'fred');
* greetFred('hi');
* // => 'hi fred'
*
* // Partially applied with placeholders.
* var sayHelloTo = _.partialRight(greet, 'hello', _);
* sayHelloTo('fred');
* // => 'hello fred'
*/
var partialRight = _baseRest(function(func, partials) {
var holders = _replaceHolders(partials, _getHolder(partialRight));
return _createWrap(func, WRAP_PARTIAL_RIGHT_FLAG$3, undefined, partials, holders);
});
// Assign default placeholders.
partialRight.placeholder = {};
var partialRight_1 = partialRight;
/**
* The base implementation of `_.clamp` which doesn't coerce arguments.
*
* @private
* @param {number} number The number to clamp.
* @param {number} [lower] The lower bound.
* @param {number} upper The upper bound.
* @returns {number} Returns the clamped number.
*/
function baseClamp(number, lower, upper) {
if (number === number) {
if (upper !== undefined) {
number = number <= upper ? number : upper;
}
if (lower !== undefined) {
number = number >= lower ? number : lower;
}
}
return number;
}
var _baseClamp = baseClamp;
/**
* Checks if `string` starts with the given target string.
*
* @static
* @memberOf _
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to inspect.
* @param {string} [target] The string to search for.
* @param {number} [position=0] The position to search from.
* @returns {boolean} Returns `true` if `string` starts with `target`,
* else `false`.
* @example
*
* _.startsWith('abc', 'a');
* // => true
*
* _.startsWith('abc', 'b');
* // => false
*
* _.startsWith('abc', 'b', 1);
* // => true
*/
function startsWith(string, target, position) {
string = toString_1(string);
position = position == null
? 0
: _baseClamp(toInteger_1(position), 0, string.length);
target = _baseToString(target);
return string.slice(position, position + target.length) == target;
}
var startsWith_1 = startsWith;
/**
* Transform sort format from user friendly notation to lodash format
* @param {string[]} sortBy array of predicate of the form "attribute:order"
* @return {array.} array containing 2 elements : attributes, orders
*/
var formatSort = function formatSort(sortBy, defaults) {
return reduce_1(sortBy, function preparePredicate(out, sortInstruction) {
var sortInstructions = sortInstruction.split(':');
if (defaults && sortInstructions.length === 1) {
var similarDefault = find_1(defaults, function(predicate) {
return startsWith_1(predicate, sortInstruction[0]);
});
if (similarDefault) {
sortInstructions = similarDefault.split(':');
}
}
out[0].push(sortInstructions[0]);
out[1].push(sortInstructions[1]);
return out;
}, [[], []]);
};
/**
* The base implementation of `_.set`.
*
* @private
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set.
* @param {*} value The value to set.
* @param {Function} [customizer] The function to customize path creation.
* @returns {Object} Returns `object`.
*/
function baseSet(object, path, value, customizer) {
if (!isObject_1(object)) {
return object;
}
path = _castPath(path, object);
var index = -1,
length = path.length,
lastIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = _toKey(path[index]),
newValue = value;
if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefined;
if (newValue === undefined) {
newValue = isObject_1(objValue)
? objValue
: (_isIndex(path[index + 1]) ? [] : {});
}
}
_assignValue(nested, key, newValue);
nested = nested[key];
}
return object;
}
var _baseSet = baseSet;
/**
* The base implementation of `_.pickBy` without support for iteratee shorthands.
*
* @private
* @param {Object} object The source object.
* @param {string[]} paths The property paths to pick.
* @param {Function} predicate The function invoked per property.
* @returns {Object} Returns the new object.
*/
function basePickBy(object, paths, predicate) {
var index = -1,
length = paths.length,
result = {};
while (++index < length) {
var path = paths[index],
value = _baseGet(object, path);
if (predicate(value, path)) {
_baseSet(result, _castPath(path, object), value);
}
}
return result;
}
var _basePickBy = basePickBy;
/**
* Creates an object composed of the `object` properties `predicate` returns
* truthy for. The predicate is invoked with two arguments: (value, key).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Object
* @param {Object} object The source object.
* @param {Function} [predicate=_.identity] The function invoked per property.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
*
* _.pickBy(object, _.isNumber);
* // => { 'a': 1, 'c': 3 }
*/
function pickBy(object, predicate) {
if (object == null) {
return {};
}
var props = _arrayMap(_getAllKeysIn(object), function(prop) {
return [prop];
});
predicate = _baseIteratee(predicate);
return _basePickBy(object, props, function(value, path) {
return predicate(value, path[0]);
});
}
var pickBy_1 = pickBy;
var generateHierarchicalTree_1 = generateTrees;
function generateTrees(state) {
return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
var hierarchicalFacetRefinement = state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0] || '';
var hierarchicalSeparator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
var hierarchicalRootPath = state._getHierarchicalRootPath(hierarchicalFacet);
var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(hierarchicalFacet);
var sortBy = formatSort(state._getHierarchicalFacetSortBy(hierarchicalFacet));
var generateTreeFn = generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath,
hierarchicalShowParentLevel, hierarchicalFacetRefinement);
var results = hierarchicalFacetResult;
if (hierarchicalRootPath) {
results = hierarchicalFacetResult.slice(hierarchicalRootPath.split(hierarchicalSeparator).length);
}
return reduce_1(results, generateTreeFn, {
name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
count: null, // root level, no count
isRefined: true, // root level, always refined
path: null, // root level, no path
data: null
});
};
}
function generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath,
hierarchicalShowParentLevel, currentRefinement) {
return function generateTree(hierarchicalTree, hierarchicalFacetResult, currentHierarchicalLevel) {
var parent = hierarchicalTree;
if (currentHierarchicalLevel > 0) {
var level = 0;
parent = hierarchicalTree;
while (level < currentHierarchicalLevel) {
parent = parent && find_1(parent.data, {isRefined: true});
level++;
}
}
// we found a refined parent, let's add current level data under it
if (parent) {
// filter values in case an object has multiple categories:
// {
// categories: {
// level0: ['beers', 'bières'],
// level1: ['beers > IPA', 'bières > Belges']
// }
// }
//
// If parent refinement is `beers`, then we do not want to have `bières > Belges`
// showing up
var onlyMatchingValuesFn = filterFacetValues(parent.path || hierarchicalRootPath,
currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel);
parent.data = orderBy_1(
map_1(
pickBy_1(hierarchicalFacetResult.data, onlyMatchingValuesFn),
formatHierarchicalFacetValue(hierarchicalSeparator, currentRefinement)
),
sortBy[0], sortBy[1]
);
}
return hierarchicalTree;
};
}
function filterFacetValues(parentPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath,
hierarchicalShowParentLevel) {
return function(facetCount, facetValue) {
// we want the facetValue is a child of hierarchicalRootPath
if (hierarchicalRootPath &&
(facetValue.indexOf(hierarchicalRootPath) !== 0 || hierarchicalRootPath === facetValue)) {
return false;
}
// we always want root levels (only when there is no prefix path)
return !hierarchicalRootPath && facetValue.indexOf(hierarchicalSeparator) === -1 ||
// if there is a rootPath, being root level mean 1 level under rootPath
hierarchicalRootPath &&
facetValue.split(hierarchicalSeparator).length - hierarchicalRootPath.split(hierarchicalSeparator).length === 1 ||
// if current refinement is a root level and current facetValue is a root level,
// keep the facetValue
facetValue.indexOf(hierarchicalSeparator) === -1 &&
currentRefinement.indexOf(hierarchicalSeparator) === -1 ||
// currentRefinement is a child of the facet value
currentRefinement.indexOf(facetValue) === 0 ||
// facetValue is a child of the current parent, add it
facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
(hierarchicalShowParentLevel || facetValue.indexOf(currentRefinement) === 0);
};
}
function formatHierarchicalFacetValue(hierarchicalSeparator, currentRefinement) {
return function format(facetCount, facetValue) {
return {
name: trim_1(last_1(facetValue.split(hierarchicalSeparator))),
path: facetValue,
count: facetCount,
isRefined: currentRefinement === facetValue || currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
data: null
};
};
}
/**
* @typedef SearchResults.Facet
* @type {object}
* @property {string} name name of the attribute in the record
* @property {object} data the faceting data: value, number of entries
* @property {object} stats undefined unless facet_stats is retrieved from algolia
*/
/**
* @typedef SearchResults.HierarchicalFacet
* @type {object}
* @property {string} name name of the current value given the hierarchical level, trimmed.
* If root node, you get the facet name
* @property {number} count number of objects matching this hierarchical value
* @property {string} path the current hierarchical value full path
* @property {boolean} isRefined `true` if the current value was refined, `false` otherwise
* @property {HierarchicalFacet[]} data sub values for the current level
*/
/**
* @typedef SearchResults.FacetValue
* @type {object}
* @property {string} name the facet value itself
* @property {number} count times this facet appears in the results
* @property {boolean} isRefined is the facet currently selected
* @property {boolean} isExcluded is the facet currently excluded (only for conjunctive facets)
*/
/**
* @typedef Refinement
* @type {object}
* @property {string} type the type of filter used:
* `numeric`, `facet`, `exclude`, `disjunctive`, `hierarchical`
* @property {string} attributeName name of the attribute used for filtering
* @property {string} name the value of the filter
* @property {number} numericValue the value as a number. Only for numeric filters.
* @property {string} operator the operator used. Only for numeric filters.
* @property {number} count the number of computed hits for this filter. Only on facets.
* @property {boolean} exhaustive if the count is exhaustive
*/
function getIndices(obj) {
var indices = {};
forEach_1(obj, function(val, idx) { indices[val] = idx; });
return indices;
}
function assignFacetStats(dest, facetStats, key) {
if (facetStats && facetStats[key]) {
dest.stats = facetStats[key];
}
}
function findMatchingHierarchicalFacetFromAttributeName(hierarchicalFacets, hierarchicalAttributeName) {
return find_1(
hierarchicalFacets,
function facetKeyMatchesAttribute(hierarchicalFacet) {
return includes_1(hierarchicalFacet.attributes, hierarchicalAttributeName);
}
);
}
/*eslint-disable */
/**
* Constructor for SearchResults
* @class
* @classdesc SearchResults contains the results of a query to Algolia using the
* {@link AlgoliaSearchHelper}.
* @param {SearchParameters} state state that led to the response
* @param {array.} results the results from algolia client
* @example SearchResults of the first query in
* the instant search demo
{
"hitsPerPage": 10,
"processingTimeMS": 2,
"facets": [
{
"name": "type",
"data": {
"HardGood": 6627,
"BlackTie": 550,
"Music": 665,
"Software": 131,
"Game": 456,
"Movie": 1571
},
"exhaustive": false
},
{
"exhaustive": false,
"data": {
"Free shipping": 5507
},
"name": "shipping"
}
],
"hits": [
{
"thumbnailImage": "http://img.bbystatic.com/BestBuy_US/images/products/1688/1688832_54x108_s.gif",
"_highlightResult": {
"shortDescription": {
"matchLevel": "none",
"value": "Safeguard your PC, Mac, Android and iOS devices with comprehensive Internet protection",
"matchedWords": []
},
"category": {
"matchLevel": "none",
"value": "Computer Security Software",
"matchedWords": []
},
"manufacturer": {
"matchedWords": [],
"value": "Webroot",
"matchLevel": "none"
},
"name": {
"value": "Webroot SecureAnywhere Internet Security (3-Device) (1-Year Subscription) - Mac/Windows",
"matchedWords": [],
"matchLevel": "none"
}
},
"image": "http://img.bbystatic.com/BestBuy_US/images/products/1688/1688832_105x210_sc.jpg",
"shipping": "Free shipping",
"bestSellingRank": 4,
"shortDescription": "Safeguard your PC, Mac, Android and iOS devices with comprehensive Internet protection",
"url": "http://www.bestbuy.com/site/webroot-secureanywhere-internet-security-3-devi…d=1219060687969&skuId=1688832&cmp=RMX&ky=2d3GfEmNIzjA0vkzveHdZEBgpPCyMnLTJ",
"name": "Webroot SecureAnywhere Internet Security (3-Device) (1-Year Subscription) - Mac/Windows",
"category": "Computer Security Software",
"salePrice_range": "1 - 50",
"objectID": "1688832",
"type": "Software",
"customerReviewCount": 5980,
"salePrice": 49.99,
"manufacturer": "Webroot"
},
....
],
"nbHits": 10000,
"disjunctiveFacets": [
{
"exhaustive": false,
"data": {
"5": 183,
"12": 112,
"7": 149,
...
},
"name": "customerReviewCount",
"stats": {
"max": 7461,
"avg": 157.939,
"min": 1
}
},
{
"data": {
"Printer Ink": 142,
"Wireless Speakers": 60,
"Point & Shoot Cameras": 48,
...
},
"name": "category",
"exhaustive": false
},
{
"exhaustive": false,
"data": {
"> 5000": 2,
"1 - 50": 6524,
"501 - 2000": 566,
"201 - 500": 1501,
"101 - 200": 1360,
"2001 - 5000": 47
},
"name": "salePrice_range"
},
{
"data": {
"Dynex™": 202,
"Insignia™": 230,
"PNY": 72,
...
},
"name": "manufacturer",
"exhaustive": false
}
],
"query": "",
"nbPages": 100,
"page": 0,
"index": "bestbuy"
}
**/
/*eslint-enable */
function SearchResults(state, results) {
var mainSubResponse = results[0];
this._rawResults = results;
/**
* query used to generate the results
* @member {string}
*/
this.query = mainSubResponse.query;
/**
* The query as parsed by the engine given all the rules.
* @member {string}
*/
this.parsedQuery = mainSubResponse.parsedQuery;
/**
* all the records that match the search parameters. Each record is
* augmented with a new attribute `_highlightResult`
* which is an object keyed by attribute and with the following properties:
* - `value` : the value of the facet highlighted (html)
* - `matchLevel`: full, partial or none depending on how the query terms match
* @member {object[]}
*/
this.hits = mainSubResponse.hits;
/**
* index where the results come from
* @member {string}
*/
this.index = mainSubResponse.index;
/**
* number of hits per page requested
* @member {number}
*/
this.hitsPerPage = mainSubResponse.hitsPerPage;
/**
* total number of hits of this query on the index
* @member {number}
*/
this.nbHits = mainSubResponse.nbHits;
/**
* total number of pages with respect to the number of hits per page and the total number of hits
* @member {number}
*/
this.nbPages = mainSubResponse.nbPages;
/**
* current page
* @member {number}
*/
this.page = mainSubResponse.page;
/**
* sum of the processing time of all the queries
* @member {number}
*/
this.processingTimeMS = sumBy_1(results, 'processingTimeMS');
/**
* The position if the position was guessed by IP.
* @member {string}
* @example "48.8637,2.3615",
*/
this.aroundLatLng = mainSubResponse.aroundLatLng;
/**
* The radius computed by Algolia.
* @member {string}
* @example "126792922",
*/
this.automaticRadius = mainSubResponse.automaticRadius;
/**
* String identifying the server used to serve this request.
* @member {string}
* @example "c7-use-2.algolia.net",
*/
this.serverUsed = mainSubResponse.serverUsed;
/**
* Boolean that indicates if the computation of the counts did time out.
* @deprecated
* @member {boolean}
*/
this.timeoutCounts = mainSubResponse.timeoutCounts;
/**
* Boolean that indicates if the computation of the hits did time out.
* @deprecated
* @member {boolean}
*/
this.timeoutHits = mainSubResponse.timeoutHits;
/**
* True if the counts of the facets is exhaustive
* @member {boolean}
*/
this.exhaustiveFacetsCount = mainSubResponse.exhaustiveFacetsCount;
/**
* True if the number of hits is exhaustive
* @member {boolean}
*/
this.exhaustiveNbHits = mainSubResponse.exhaustiveNbHits;
/**
* Contains the userData if they are set by a [query rule](https://www.algolia.com/doc/guides/query-rules/query-rules-overview/).
* @member {object[]}
*/
this.userData = mainSubResponse.userData;
/**
* queryID is the unique identifier of the query used to generate the current search results.
* This value is only available if the `clickAnalytics` search parameter is set to `true`.
* @member {string}
*/
this.queryID = mainSubResponse.queryID;
/**
* disjunctive facets results
* @member {SearchResults.Facet[]}
*/
this.disjunctiveFacets = [];
/**
* disjunctive facets results
* @member {SearchResults.HierarchicalFacet[]}
*/
this.hierarchicalFacets = map_1(state.hierarchicalFacets, function initFutureTree() {
return [];
});
/**
* other facets results
* @member {SearchResults.Facet[]}
*/
this.facets = [];
var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
var facetsIndices = getIndices(state.facets);
var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
var nextDisjunctiveResult = 1;
var self = this;
// Since we send request only for disjunctive facets that have been refined,
// we get the facets informations from the first, general, response.
forEach_1(mainSubResponse.facets, function(facetValueObject, facetKey) {
var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
state.hierarchicalFacets,
facetKey
);
if (hierarchicalFacet) {
// Place the hierarchicalFacet data at the correct index depending on
// the attributes order that was defined at the helper initialization
var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
var idxAttributeName = findIndex_1(state.hierarchicalFacets, {name: hierarchicalFacet.name});
self.hierarchicalFacets[idxAttributeName][facetIndex] = {
attribute: facetKey,
data: facetValueObject,
exhaustive: mainSubResponse.exhaustiveFacetsCount
};
} else {
var isFacetDisjunctive = indexOf_1(state.disjunctiveFacets, facetKey) !== -1;
var isFacetConjunctive = indexOf_1(state.facets, facetKey) !== -1;
var position;
if (isFacetDisjunctive) {
position = disjunctiveFacetsIndices[facetKey];
self.disjunctiveFacets[position] = {
name: facetKey,
data: facetValueObject,
exhaustive: mainSubResponse.exhaustiveFacetsCount
};
assignFacetStats(self.disjunctiveFacets[position], mainSubResponse.facets_stats, facetKey);
}
if (isFacetConjunctive) {
position = facetsIndices[facetKey];
self.facets[position] = {
name: facetKey,
data: facetValueObject,
exhaustive: mainSubResponse.exhaustiveFacetsCount
};
assignFacetStats(self.facets[position], mainSubResponse.facets_stats, facetKey);
}
}
});
// Make sure we do not keep holes within the hierarchical facets
this.hierarchicalFacets = compact_1(this.hierarchicalFacets);
// aggregate the refined disjunctive facets
forEach_1(disjunctiveFacets, function(disjunctiveFacet) {
var result = results[nextDisjunctiveResult];
var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
// There should be only item in facets.
forEach_1(result.facets, function(facetResults, dfacet) {
var position;
if (hierarchicalFacet) {
position = findIndex_1(state.hierarchicalFacets, {name: hierarchicalFacet.name});
var attributeIndex = findIndex_1(self.hierarchicalFacets[position], {attribute: dfacet});
// previous refinements and no results so not able to find it
if (attributeIndex === -1) {
return;
}
self.hierarchicalFacets[position][attributeIndex].data = merge_1(
{},
self.hierarchicalFacets[position][attributeIndex].data,
facetResults
);
} else {
position = disjunctiveFacetsIndices[dfacet];
var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
self.disjunctiveFacets[position] = {
name: dfacet,
data: defaults_1({}, facetResults, dataFromMainRequest),
exhaustive: result.exhaustiveFacetsCount
};
assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
if (state.disjunctiveFacetsRefinements[dfacet]) {
forEach_1(state.disjunctiveFacetsRefinements[dfacet], function(refinementValue) {
// add the disjunctive refinements if it is no more retrieved
if (!self.disjunctiveFacets[position].data[refinementValue] &&
indexOf_1(state.disjunctiveFacetsRefinements[dfacet], refinementValue) > -1) {
self.disjunctiveFacets[position].data[refinementValue] = 0;
}
});
}
}
});
nextDisjunctiveResult++;
});
// if we have some root level values for hierarchical facets, merge them
forEach_1(state.getRefinedHierarchicalFacets(), function(refinedFacet) {
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
// if we are already at a root refinement (or no refinement at all), there is no
// root level values request
if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
return;
}
var result = results[nextDisjunctiveResult];
forEach_1(result.facets, function(facetResults, dfacet) {
var position = findIndex_1(state.hierarchicalFacets, {name: hierarchicalFacet.name});
var attributeIndex = findIndex_1(self.hierarchicalFacets[position], {attribute: dfacet});
// previous refinements and no results so not able to find it
if (attributeIndex === -1) {
return;
}
// when we always get root levels, if the hits refinement is `beers > IPA` (count: 5),
// then the disjunctive values will be `beers` (count: 100),
// but we do not want to display
// | beers (100)
// > IPA (5)
// We want
// | beers (5)
// > IPA (5)
var defaultData = {};
if (currentRefinement.length > 0) {
var root = currentRefinement[0].split(separator)[0];
defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
}
self.hierarchicalFacets[position][attributeIndex].data = defaults_1(
defaultData,
facetResults,
self.hierarchicalFacets[position][attributeIndex].data
);
});
nextDisjunctiveResult++;
});
// add the excludes
forEach_1(state.facetsExcludes, function(excludes, facetName) {
var position = facetsIndices[facetName];
self.facets[position] = {
name: facetName,
data: mainSubResponse.facets[facetName],
exhaustive: mainSubResponse.exhaustiveFacetsCount
};
forEach_1(excludes, function(facetValue) {
self.facets[position] = self.facets[position] || {name: facetName};
self.facets[position].data = self.facets[position].data || {};
self.facets[position].data[facetValue] = 0;
});
});
this.hierarchicalFacets = map_1(this.hierarchicalFacets, generateHierarchicalTree_1(state));
this.facets = compact_1(this.facets);
this.disjunctiveFacets = compact_1(this.disjunctiveFacets);
this._state = state;
}
/**
* Get a facet object with its name
* @deprecated
* @param {string} name name of the faceted attribute
* @return {SearchResults.Facet} the facet object
*/
SearchResults.prototype.getFacetByName = function(name) {
var predicate = {name: name};
return find_1(this.facets, predicate) ||
find_1(this.disjunctiveFacets, predicate) ||
find_1(this.hierarchicalFacets, predicate);
};
/**
* Get the facet values of a specified attribute from a SearchResults object.
* @private
* @param {SearchResults} results the search results to search in
* @param {string} attribute name of the faceted attribute to search for
* @return {array|object} facet values. For the hierarchical facets it is an object.
*/
function extractNormalizedFacetValues(results, attribute) {
var predicate = {name: attribute};
if (results._state.isConjunctiveFacet(attribute)) {
var facet = find_1(results.facets, predicate);
if (!facet) return [];
return map_1(facet.data, function(v, k) {
return {
name: k,
count: v,
isRefined: results._state.isFacetRefined(attribute, k),
isExcluded: results._state.isExcludeRefined(attribute, k)
};
});
} else if (results._state.isDisjunctiveFacet(attribute)) {
var disjunctiveFacet = find_1(results.disjunctiveFacets, predicate);
if (!disjunctiveFacet) return [];
return map_1(disjunctiveFacet.data, function(v, k) {
return {
name: k,
count: v,
isRefined: results._state.isDisjunctiveFacetRefined(attribute, k)
};
});
} else if (results._state.isHierarchicalFacet(attribute)) {
return find_1(results.hierarchicalFacets, predicate);
}
}
/**
* Sort nodes of a hierarchical facet results
* @private
* @param {HierarchicalFacet} node node to upon which we want to apply the sort
*/
function recSort(sortFn, node) {
if (!node.data || node.data.length === 0) {
return node;
}
var children = map_1(node.data, partial_1(recSort, sortFn));
var sortedChildren = sortFn(children);
var newNode = merge_1({}, node, {data: sortedChildren});
return newNode;
}
SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
function vanillaSortFn(order, data) {
return data.sort(order);
}
/**
* Get a the list of values for a given facet attribute. Those values are sorted
* refinement first, descending count (bigger value on top), and name ascending
* (alphabetical order). The sort formula can overridden using either string based
* predicates or a function.
*
* This method will return all the values returned by the Algolia engine plus all
* the values already refined. This means that it can happen that the
* `maxValuesPerFacet` [configuration](https://www.algolia.com/doc/rest-api/search#param-maxValuesPerFacet)
* might not be respected if you have facet values that are already refined.
* @param {string} attribute attribute name
* @param {object} opts configuration options.
* @param {Array. | function} opts.sortBy
* When using strings, it consists of
* the name of the [FacetValue](#SearchResults.FacetValue) or the
* [HierarchicalFacet](#SearchResults.HierarchicalFacet) attributes with the
* order (`asc` or `desc`). For example to order the value by count, the
* argument would be `['count:asc']`.
*
* If only the attribute name is specified, the ordering defaults to the one
* specified in the default value for this attribute.
*
* When not specified, the order is
* ascending. This parameter can also be a function which takes two facet
* values and should return a number, 0 if equal, 1 if the first argument is
* bigger or -1 otherwise.
*
* The default value for this attribute `['isRefined:desc', 'count:desc', 'name:asc']`
* @return {FacetValue[]|HierarchicalFacet} depending on the type of facet of
* the attribute requested (hierarchical, disjunctive or conjunctive)
* @example
* helper.on('results', function(content){
* //get values ordered only by name ascending using the string predicate
* content.getFacetValues('city', {sortBy: ['name:asc']});
* //get values ordered only by count ascending using a function
* content.getFacetValues('city', {
* // this is equivalent to ['count:asc']
* sortBy: function(a, b) {
* if (a.count === b.count) return 0;
* if (a.count > b.count) return 1;
* if (b.count > a.count) return -1;
* }
* });
* });
*/
SearchResults.prototype.getFacetValues = function(attribute, opts) {
var facetValues = extractNormalizedFacetValues(this, attribute);
if (!facetValues) throw new Error(attribute + ' is not a retrieved facet.');
var options = defaults_1({}, opts, {sortBy: SearchResults.DEFAULT_SORT});
if (Array.isArray(options.sortBy)) {
var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
if (Array.isArray(facetValues)) {
return orderBy_1(facetValues, order[0], order[1]);
}
// If facetValues is not an array, it's an object thus a hierarchical facet object
return recSort(partialRight_1(orderBy_1, order[0], order[1]), facetValues);
} else if (isFunction_1(options.sortBy)) {
if (Array.isArray(facetValues)) {
return facetValues.sort(options.sortBy);
}
// If facetValues is not an array, it's an object thus a hierarchical facet object
return recSort(partial_1(vanillaSortFn, options.sortBy), facetValues);
}
throw new Error(
'options.sortBy is optional but if defined it must be ' +
'either an array of string (predicates) or a sorting function'
);
};
/**
* Returns the facet stats if attribute is defined and the facet contains some.
* Otherwise returns undefined.
* @param {string} attribute name of the faceted attribute
* @return {object} The stats of the facet
*/
SearchResults.prototype.getFacetStats = function(attribute) {
if (this._state.isConjunctiveFacet(attribute)) {
return getFacetStatsIfAvailable(this.facets, attribute);
} else if (this._state.isDisjunctiveFacet(attribute)) {
return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
}
throw new Error(attribute + ' is not present in `facets` or `disjunctiveFacets`');
};
function getFacetStatsIfAvailable(facetList, facetName) {
var data = find_1(facetList, {name: facetName});
return data && data.stats;
}
/**
* Returns all refinements for all filters + tags. It also provides
* additional information: count and exhausistivity for each filter.
*
* See the [refinement type](#Refinement) for an exhaustive view of the available
* data.
*
* @return {Array.} all the refinements
*/
SearchResults.prototype.getRefinements = function() {
var state = this._state;
var results = this;
var res = [];
forEach_1(state.facetsRefinements, function(refinements, attributeName) {
forEach_1(refinements, function(name) {
res.push(getRefinement(state, 'facet', attributeName, name, results.facets));
});
});
forEach_1(state.facetsExcludes, function(refinements, attributeName) {
forEach_1(refinements, function(name) {
res.push(getRefinement(state, 'exclude', attributeName, name, results.facets));
});
});
forEach_1(state.disjunctiveFacetsRefinements, function(refinements, attributeName) {
forEach_1(refinements, function(name) {
res.push(getRefinement(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
});
});
forEach_1(state.hierarchicalFacetsRefinements, function(refinements, attributeName) {
forEach_1(refinements, function(name) {
res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
});
});
forEach_1(state.numericRefinements, function(operators, attributeName) {
forEach_1(operators, function(values, operator) {
forEach_1(values, function(value) {
res.push({
type: 'numeric',
attributeName: attributeName,
name: value,
numericValue: value,
operator: operator
});
});
});
});
forEach_1(state.tagRefinements, function(name) {
res.push({type: 'tag', attributeName: '_tags', name: name});
});
return res;
};
function getRefinement(state, type, attributeName, name, resultsFacets) {
var facet = find_1(resultsFacets, {name: attributeName});
var count = get_1(facet, 'data[' + name + ']');
var exhaustive = get_1(facet, 'exhaustive');
return {
type: type,
attributeName: attributeName,
name: name,
count: count || 0,
exhaustive: exhaustive || false
};
}
function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
var facet = find_1(resultsFacets, {name: attributeName});
var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
var splitted = name.split(facetDeclaration.separator);
var configuredName = splitted[splitted.length - 1];
for (var i = 0; facet !== undefined && i < splitted.length; ++i) {
facet = find_1(facet.data, {name: splitted[i]});
}
var count = get_1(facet, 'count');
var exhaustive = get_1(facet, 'exhaustive');
return {
type: 'hierarchical',
attributeName: attributeName,
name: configuredName,
count: count || 0,
exhaustive: exhaustive || false
};
}
var SearchResults_1 = SearchResults;
var isBufferBrowser = function isBuffer(arg) {
return arg && typeof arg === 'object'
&& typeof arg.copy === 'function'
&& typeof arg.fill === 'function'
&& typeof arg.readUInt8 === 'function';
};
var inherits_browser = createCommonjsModule(function (module) {
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function () {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
};
}
});
var util = createCommonjsModule(function (module, exports) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var formatRegExp = /%[sdj%]/g;
exports.format = function(f) {
if (!isString(f)) {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
}
return objects.join(' ');
}
var i = 1;
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function(x) {
if (x === '%%') return '%';
if (i >= len) return x;
switch (x) {
case '%s': return String(args[i++]);
case '%d': return Number(args[i++]);
case '%j':
try {
return JSON.stringify(args[i++]);
} catch (_) {
return '[Circular]';
}
default:
return x;
}
});
for (var x = args[i]; i < len; x = args[++i]) {
if (isNull(x) || !isObject(x)) {
str += ' ' + x;
} else {
str += ' ' + inspect(x);
}
}
return str;
};
// Mark that a method should not be used.
// Returns a modified function which warns once by default.
// If --no-deprecation is set, then it is a no-op.
exports.deprecate = function(fn, msg) {
// Allow for deprecating things in the process of starting up.
if (isUndefined(commonjsGlobal.process)) {
return function() {
return exports.deprecate(fn, msg).apply(this, arguments);
};
}
if (process.noDeprecation === true) {
return fn;
}
var warned = false;
function deprecated() {
if (!warned) {
if (process.throwDeprecation) {
throw new Error(msg);
} else if (process.traceDeprecation) {
console.trace(msg);
} else {
console.error(msg);
}
warned = true;
}
return fn.apply(this, arguments);
}
return deprecated;
};
var debugs = {};
var debugEnviron;
exports.debuglog = function(set) {
if (isUndefined(debugEnviron))
debugEnviron = process.env.NODE_DEBUG || '';
set = set.toUpperCase();
if (!debugs[set]) {
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
var pid = process.pid;
debugs[set] = function() {
var msg = exports.format.apply(exports, arguments);
console.error('%s %d: %s', set, pid, msg);
};
} else {
debugs[set] = function() {};
}
}
return debugs[set];
};
/**
* Echos the value of a value. Trys to print the value out
* in the best way possible given the different types.
*
* @param {Object} obj The object to print out.
* @param {Object} opts Optional options object that alters the output.
*/
/* legacy: obj, showHidden, depth, colors*/
function inspect(obj, opts) {
// default options
var ctx = {
seen: [],
stylize: stylizeNoColor
};
// legacy...
if (arguments.length >= 3) ctx.depth = arguments[2];
if (arguments.length >= 4) ctx.colors = arguments[3];
if (isBoolean(opts)) {
// legacy...
ctx.showHidden = opts;
} else if (opts) {
// got an "options" object
exports._extend(ctx, opts);
}
// set default options
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
if (isUndefined(ctx.depth)) ctx.depth = 2;
if (isUndefined(ctx.colors)) ctx.colors = false;
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
if (ctx.colors) ctx.stylize = stylizeWithColor;
return formatValue(ctx, obj, ctx.depth);
}
exports.inspect = inspect;
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
inspect.colors = {
'bold' : [1, 22],
'italic' : [3, 23],
'underline' : [4, 24],
'inverse' : [7, 27],
'white' : [37, 39],
'grey' : [90, 39],
'black' : [30, 39],
'blue' : [34, 39],
'cyan' : [36, 39],
'green' : [32, 39],
'magenta' : [35, 39],
'red' : [31, 39],
'yellow' : [33, 39]
};
// Don't use 'blue' not visible on cmd.exe
inspect.styles = {
'special': 'cyan',
'number': 'yellow',
'boolean': 'yellow',
'undefined': 'grey',
'null': 'bold',
'string': 'green',
'date': 'magenta',
// "name": intentionally not styling
'regexp': 'red'
};
function stylizeWithColor(str, styleType) {
var style = inspect.styles[styleType];
if (style) {
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
'\u001b[' + inspect.colors[style][1] + 'm';
} else {
return str;
}
}
function stylizeNoColor(str, styleType) {
return str;
}
function arrayToHash(array) {
var hash = {};
array.forEach(function(val, idx) {
hash[val] = true;
});
return hash;
}
function formatValue(ctx, value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
// Check that value is an object with an inspect function on it
if (ctx.customInspect &&
value &&
isFunction(value.inspect) &&
// Filter out the util module, it's inspect function is special
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
var ret = value.inspect(recurseTimes, ctx);
if (!isString(ret)) {
ret = formatValue(ctx, ret, recurseTimes);
}
return ret;
}
// Primitive types cannot have properties
var primitive = formatPrimitive(ctx, value);
if (primitive) {
return primitive;
}
// Look up the keys of the object.
var keys = Object.keys(value);
var visibleKeys = arrayToHash(keys);
if (ctx.showHidden) {
keys = Object.getOwnPropertyNames(value);
}
// IE doesn't make error fields non-enumerable
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
if (isError(value)
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
return formatError(value);
}
// Some type of object without properties can be shortcutted.
if (keys.length === 0) {
if (isFunction(value)) {
var name = value.name ? ': ' + value.name : '';
return ctx.stylize('[Function' + name + ']', 'special');
}
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
}
if (isDate(value)) {
return ctx.stylize(Date.prototype.toString.call(value), 'date');
}
if (isError(value)) {
return formatError(value);
}
}
var base = '', array = false, braces = ['{', '}'];
// Make Array say that they are Array
if (isArray(value)) {
array = true;
braces = ['[', ']'];
}
// Make functions say that they are functions
if (isFunction(value)) {
var n = value.name ? ': ' + value.name : '';
base = ' [Function' + n + ']';
}
// Make RegExps say that they are RegExps
if (isRegExp(value)) {
base = ' ' + RegExp.prototype.toString.call(value);
}
// Make dates with properties first say the date
if (isDate(value)) {
base = ' ' + Date.prototype.toUTCString.call(value);
}
// Make error with message first say the error
if (isError(value)) {
base = ' ' + formatError(value);
}
if (keys.length === 0 && (!array || value.length == 0)) {
return braces[0] + base + braces[1];
}
if (recurseTimes < 0) {
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
} else {
return ctx.stylize('[Object]', 'special');
}
}
ctx.seen.push(value);
var output;
if (array) {
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
} else {
output = keys.map(function(key) {
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
});
}
ctx.seen.pop();
return reduceToSingleString(output, base, braces);
}
function formatPrimitive(ctx, value) {
if (isUndefined(value))
return ctx.stylize('undefined', 'undefined');
if (isString(value)) {
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
}
if (isNumber(value))
return ctx.stylize('' + value, 'number');
if (isBoolean(value))
return ctx.stylize('' + value, 'boolean');
// For some reason typeof null is "object", so special case here.
if (isNull(value))
return ctx.stylize('null', 'null');
}
function formatError(value) {
return '[' + Error.prototype.toString.call(value) + ']';
}
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
var output = [];
for (var i = 0, l = value.length; i < l; ++i) {
if (hasOwnProperty(value, String(i))) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
String(i), true));
} else {
output.push('');
}
}
keys.forEach(function(key) {
if (!key.match(/^\d+$/)) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
key, true));
}
});
return output;
}
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
var name, str, desc;
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
if (desc.get) {
if (desc.set) {
str = ctx.stylize('[Getter/Setter]', 'special');
} else {
str = ctx.stylize('[Getter]', 'special');
}
} else {
if (desc.set) {
str = ctx.stylize('[Setter]', 'special');
}
}
if (!hasOwnProperty(visibleKeys, key)) {
name = '[' + key + ']';
}
if (!str) {
if (ctx.seen.indexOf(desc.value) < 0) {
if (isNull(recurseTimes)) {
str = formatValue(ctx, desc.value, null);
} else {
str = formatValue(ctx, desc.value, recurseTimes - 1);
}
if (str.indexOf('\n') > -1) {
if (array) {
str = str.split('\n').map(function(line) {
return ' ' + line;
}).join('\n').substr(2);
} else {
str = '\n' + str.split('\n').map(function(line) {
return ' ' + line;
}).join('\n');
}
}
} else {
str = ctx.stylize('[Circular]', 'special');
}
}
if (isUndefined(name)) {
if (array && key.match(/^\d+$/)) {
return str;
}
name = JSON.stringify('' + key);
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
name = name.substr(1, name.length - 2);
name = ctx.stylize(name, 'name');
} else {
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
name = ctx.stylize(name, 'string');
}
}
return name + ': ' + str;
}
function reduceToSingleString(output, base, braces) {
var length = output.reduce(function(prev, cur) {
if (cur.indexOf('\n') >= 0) ;
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
}, 0);
if (length > 60) {
return braces[0] +
(base === '' ? '' : base + '\n ') +
' ' +
output.join(',\n ') +
' ' +
braces[1];
}
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
}
// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(ar) {
return Array.isArray(ar);
}
exports.isArray = isArray;
function isBoolean(arg) {
return typeof arg === 'boolean';
}
exports.isBoolean = isBoolean;
function isNull(arg) {
return arg === null;
}
exports.isNull = isNull;
function isNullOrUndefined(arg) {
return arg == null;
}
exports.isNullOrUndefined = isNullOrUndefined;
function isNumber(arg) {
return typeof arg === 'number';
}
exports.isNumber = isNumber;
function isString(arg) {
return typeof arg === 'string';
}
exports.isString = isString;
function isSymbol(arg) {
return typeof arg === 'symbol';
}
exports.isSymbol = isSymbol;
function isUndefined(arg) {
return arg === void 0;
}
exports.isUndefined = isUndefined;
function isRegExp(re) {
return isObject(re) && objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
exports.isObject = isObject;
function isDate(d) {
return isObject(d) && objectToString(d) === '[object Date]';
}
exports.isDate = isDate;
function isError(e) {
return isObject(e) &&
(objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;
function isFunction(arg) {
return typeof arg === 'function';
}
exports.isFunction = isFunction;
function isPrimitive(arg) {
return arg === null ||
typeof arg === 'boolean' ||
typeof arg === 'number' ||
typeof arg === 'string' ||
typeof arg === 'symbol' || // ES6 symbol
typeof arg === 'undefined';
}
exports.isPrimitive = isPrimitive;
exports.isBuffer = isBufferBrowser;
function objectToString(o) {
return Object.prototype.toString.call(o);
}
function pad(n) {
return n < 10 ? '0' + n.toString(10) : n.toString(10);
}
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'];
// 26 Feb 16:19:34
function timestamp() {
var d = new Date();
var time = [pad(d.getHours()),
pad(d.getMinutes()),
pad(d.getSeconds())].join(':');
return [d.getDate(), months[d.getMonth()], time].join(' ');
}
// log is just a thin wrapper to console.log that prepends a timestamp
exports.log = function() {
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
};
/**
* Inherit the prototype methods from one constructor into another.
*
* The Function.prototype.inherits from lang.js rewritten as a standalone
* function (not on Function.prototype). NOTE: If this file is to be loaded
* during bootstrapping this function needs to be rewritten using some native
* functions as prototype setup using normal JavaScript does not work as
* expected during bootstrapping (see mirror.js in r114903).
*
* @param {function} ctor Constructor function which needs to inherit the
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
*/
exports.inherits = inherits_browser;
exports._extend = function(origin, add) {
// Don't do anything if add isn't an object
if (!add || !isObject(add)) return origin;
var keys = Object.keys(add);
var i = keys.length;
while (i--) {
origin[keys[i]] = add[keys[i]];
}
return origin;
};
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
});
var util_1 = util.format;
var util_2 = util.deprecate;
var util_3 = util.debuglog;
var util_4 = util.inspect;
var util_5 = util.isArray;
var util_6 = util.isBoolean;
var util_7 = util.isNull;
var util_8 = util.isNullOrUndefined;
var util_9 = util.isNumber;
var util_10 = util.isString;
var util_11 = util.isSymbol;
var util_12 = util.isUndefined;
var util_13 = util.isRegExp;
var util_14 = util.isObject;
var util_15 = util.isDate;
var util_16 = util.isError;
var util_17 = util.isFunction;
var util_18 = util.isPrimitive;
var util_19 = util.isBuffer;
var util_20 = util.log;
var util_21 = util.inherits;
var util_22 = util._extend;
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
var events = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber$1(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
if (!this._events)
this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject$1(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
// At least give some kind of context to the user
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
err.context = er;
throw err;
}
}
}
handler = this._events[type];
if (isUndefined$1(handler))
return false;
if (isFunction$1(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
args = Array.prototype.slice.call(arguments, 1);
handler.apply(this, args);
}
} else if (isObject$1(handler)) {
args = Array.prototype.slice.call(arguments, 1);
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
}
return true;
};
EventEmitter.prototype.addListener = function(type, listener) {
var m;
if (!isFunction$1(listener))
throw TypeError('listener must be a function');
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction$1(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject$1(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject$1(this._events[type]) && !this._events[type].warned) {
if (!isUndefined$1(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction$1(listener))
throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!isFunction$1(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(isFunction$1(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject$1(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
if (!this._events)
return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction$1(listeners)) {
this.removeListener(type, listeners);
} else if (listeners) {
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction$1(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
EventEmitter.prototype.listenerCount = function(type) {
if (this._events) {
var evlistener = this._events[type];
if (isFunction$1(evlistener))
return 1;
else if (evlistener)
return evlistener.length;
}
return 0;
};
EventEmitter.listenerCount = function(emitter, type) {
return emitter.listenerCount(type);
};
function isFunction$1(arg) {
return typeof arg === 'function';
}
function isNumber$1(arg) {
return typeof arg === 'number';
}
function isObject$1(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined$1(arg) {
return arg === void 0;
}
/**
* A DerivedHelper is a way to create sub requests to
* Algolia from a main helper.
* @class
* @classdesc The DerivedHelper provides an event based interface for search callbacks:
* - search: when a search is triggered using the `search()` method.
* - result: when the response is retrieved from Algolia and is processed.
* This event contains a {@link SearchResults} object and the
* {@link SearchParameters} corresponding to this answer.
*/
function DerivedHelper(mainHelper, fn) {
this.main = mainHelper;
this.fn = fn;
this.lastResults = null;
}
util.inherits(DerivedHelper, events.EventEmitter);
/**
* Detach this helper from the main helper
* @return {undefined}
* @throws Error if the derived helper is already detached
*/
DerivedHelper.prototype.detach = function() {
this.removeAllListeners();
this.main.detachDerivedHelper(this);
};
DerivedHelper.prototype.getModifiedState = function(parameters) {
return this.fn(parameters);
};
var DerivedHelper_1 = DerivedHelper;
var requestBuilder = {
/**
* Get all the queries to send to the client, those queries can used directly
* with the Algolia client.
* @private
* @return {object[]} The queries
*/
_getQueries: function getQueries(index, state) {
var queries = [];
// One query for the hits
queries.push({
indexName: index,
params: requestBuilder._getHitsSearchParams(state)
});
// One for each disjunctive facets
forEach_1(state.getRefinedDisjunctiveFacets(), function(refinedFacet) {
queries.push({
indexName: index,
params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
});
});
// maybe more to get the root level of hierarchical facets when activated
forEach_1(state.getRefinedHierarchicalFacets(), function(refinedFacet) {
var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
// if we are deeper than level 0 (starting from `beer > IPA`)
// we want to get the root values
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
queries.push({
indexName: index,
params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet, true)
});
}
});
return queries;
},
/**
* Build search parameters used to fetch hits
* @private
* @return {object.}
*/
_getHitsSearchParams: function(state) {
var facets = state.facets
.concat(state.disjunctiveFacets)
.concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
var facetFilters = requestBuilder._getFacetFilters(state);
var numericFilters = requestBuilder._getNumericFilters(state);
var tagFilters = requestBuilder._getTagFilters(state);
var additionalParams = {
facets: facets,
tagFilters: tagFilters
};
if (facetFilters.length > 0) {
additionalParams.facetFilters = facetFilters;
}
if (numericFilters.length > 0) {
additionalParams.numericFilters = numericFilters;
}
return merge_1(state.getQueryParams(), additionalParams);
},
/**
* Build search parameters used to fetch a disjunctive facet
* @private
* @param {string} facet the associated facet name
* @param {boolean} hierarchicalRootLevel ?? FIXME
* @return {object}
*/
_getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
var numericFilters = requestBuilder._getNumericFilters(state, facet);
var tagFilters = requestBuilder._getTagFilters(state);
var additionalParams = {
hitsPerPage: 1,
page: 0,
attributesToRetrieve: [],
attributesToHighlight: [],
attributesToSnippet: [],
tagFilters: tagFilters,
analytics: false,
clickAnalytics: false
};
var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
if (hierarchicalFacet) {
additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
state,
hierarchicalFacet,
hierarchicalRootLevel
);
} else {
additionalParams.facets = facet;
}
if (numericFilters.length > 0) {
additionalParams.numericFilters = numericFilters;
}
if (facetFilters.length > 0) {
additionalParams.facetFilters = facetFilters;
}
return merge_1(state.getQueryParams(), additionalParams);
},
/**
* Return the numeric filters in an algolia request fashion
* @private
* @param {string} [facetName] the name of the attribute for which the filters should be excluded
* @return {string[]} the numeric filters in the algolia format
*/
_getNumericFilters: function(state, facetName) {
if (state.numericFilters) {
return state.numericFilters;
}
var numericFilters = [];
forEach_1(state.numericRefinements, function(operators, attribute) {
forEach_1(operators, function(values, operator) {
if (facetName !== attribute) {
forEach_1(values, function(value) {
if (Array.isArray(value)) {
var vs = map_1(value, function(v) {
return attribute + operator + v;
});
numericFilters.push(vs);
} else {
numericFilters.push(attribute + operator + value);
}
});
}
});
});
return numericFilters;
},
/**
* Return the tags filters depending
* @private
* @return {string}
*/
_getTagFilters: function(state) {
if (state.tagFilters) {
return state.tagFilters;
}
return state.tagRefinements.join(',');
},
/**
* Build facetFilters parameter based on current refinements. The array returned
* contains strings representing the facet filters in the algolia format.
* @private
* @param {string} [facet] if set, the current disjunctive facet
* @return {array.}
*/
_getFacetFilters: function(state, facet, hierarchicalRootLevel) {
var facetFilters = [];
forEach_1(state.facetsRefinements, function(facetValues, facetName) {
forEach_1(facetValues, function(facetValue) {
facetFilters.push(facetName + ':' + facetValue);
});
});
forEach_1(state.facetsExcludes, function(facetValues, facetName) {
forEach_1(facetValues, function(facetValue) {
facetFilters.push(facetName + ':-' + facetValue);
});
});
forEach_1(state.disjunctiveFacetsRefinements, function(facetValues, facetName) {
if (facetName === facet || !facetValues || facetValues.length === 0) return;
var orFilters = [];
forEach_1(facetValues, function(facetValue) {
orFilters.push(facetName + ':' + facetValue);
});
facetFilters.push(orFilters);
});
forEach_1(state.hierarchicalFacetsRefinements, function(facetValues, facetName) {
var facetValue = facetValues[0];
if (facetValue === undefined) {
return;
}
var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
var attributeToRefine;
var attributesIndex;
// we ask for parent facet values only when the `facet` is the current hierarchical facet
if (facet === facetName) {
// if we are at the root level already, no need to ask for facet values, we get them from
// the hits query
if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
(rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
return;
}
if (!rootPath) {
attributesIndex = facetValue.split(separator).length - 2;
facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
} else {
attributesIndex = rootPath.split(separator).length - 1;
facetValue = rootPath;
}
attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
} else {
attributesIndex = facetValue.split(separator).length - 1;
attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
}
if (attributeToRefine) {
facetFilters.push([attributeToRefine + ':' + facetValue]);
}
});
return facetFilters;
},
_getHitsHierarchicalFacetsAttributes: function(state) {
var out = [];
return reduce_1(
state.hierarchicalFacets,
// ask for as much levels as there's hierarchical refinements
function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
// if no refinement, ask for root level
if (!hierarchicalRefinement) {
allAttributes.push(hierarchicalFacet.attributes[0]);
return allAttributes;
}
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
var level = hierarchicalRefinement.split(separator).length;
var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
return allAttributes.concat(newAttributes);
}, out);
},
_getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
if (rootLevel === true) {
var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
var attributeIndex = 0;
if (rootPath) {
attributeIndex = rootPath.split(separator).length;
}
return [hierarchicalFacet.attributes[attributeIndex]];
}
var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
// if refinement is 'beers > IPA > Flying dog',
// then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
var parentLevel = hierarchicalRefinement.split(separator).length - 1;
return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
},
getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
state.clearRefinements(facetName) :
state;
var searchForFacetSearchParameters = {
facetQuery: query,
facetName: facetName
};
if (typeof maxFacetHits === 'number') {
searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
}
var queries = merge_1(requestBuilder._getHitsSearchParams(stateForSearchForFacetValues), searchForFacetSearchParameters);
return queries;
}
};
var requestBuilder_1 = requestBuilder;
/**
* The base implementation of `_.invert` and `_.invertBy` which inverts
* `object` with values transformed by `iteratee` and set by `setter`.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} setter The function to set `accumulator` values.
* @param {Function} iteratee The iteratee to transform values.
* @param {Object} accumulator The initial inverted object.
* @returns {Function} Returns `accumulator`.
*/
function baseInverter(object, setter, iteratee, accumulator) {
_baseForOwn(object, function(value, key, object) {
setter(accumulator, iteratee(value), key, object);
});
return accumulator;
}
var _baseInverter = baseInverter;
/**
* Creates a function like `_.invertBy`.
*
* @private
* @param {Function} setter The function to set accumulator values.
* @param {Function} toIteratee The function to resolve iteratees.
* @returns {Function} Returns the new inverter function.
*/
function createInverter(setter, toIteratee) {
return function(object, iteratee) {
return _baseInverter(object, setter, toIteratee(iteratee), {});
};
}
var _createInverter = createInverter;
/** Used for built-in method references. */
var objectProto$k = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString$2 = objectProto$k.toString;
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite
* property assignments of previous values.
*
* @static
* @memberOf _
* @since 0.7.0
* @category Object
* @param {Object} object The object to invert.
* @returns {Object} Returns the new inverted object.
* @example
*
* var object = { 'a': 1, 'b': 2, 'c': 1 };
*
* _.invert(object);
* // => { '1': 'c', '2': 'b' }
*/
var invert = _createInverter(function(result, value, key) {
if (value != null &&
typeof value.toString != 'function') {
value = nativeObjectToString$2.call(value);
}
result[value] = key;
}, constant_1(identity_1));
var invert_1 = invert;
var keys2Short = {
advancedSyntax: 'aS',
allowTyposOnNumericTokens: 'aTONT',
analyticsTags: 'aT',
analytics: 'a',
aroundLatLngViaIP: 'aLLVIP',
aroundLatLng: 'aLL',
aroundPrecision: 'aP',
aroundRadius: 'aR',
attributesToHighlight: 'aTH',
attributesToRetrieve: 'aTR',
attributesToSnippet: 'aTS',
disjunctiveFacetsRefinements: 'dFR',
disjunctiveFacets: 'dF',
distinct: 'd',
facetsExcludes: 'fE',
facetsRefinements: 'fR',
facets: 'f',
getRankingInfo: 'gRI',
hierarchicalFacetsRefinements: 'hFR',
hierarchicalFacets: 'hF',
highlightPostTag: 'hPoT',
highlightPreTag: 'hPrT',
hitsPerPage: 'hPP',
ignorePlurals: 'iP',
index: 'idx',
insideBoundingBox: 'iBB',
insidePolygon: 'iPg',
length: 'l',
maxValuesPerFacet: 'mVPF',
minimumAroundRadius: 'mAR',
minProximity: 'mP',
minWordSizefor1Typo: 'mWS1T',
minWordSizefor2Typos: 'mWS2T',
numericFilters: 'nF',
numericRefinements: 'nR',
offset: 'o',
optionalWords: 'oW',
page: 'p',
queryType: 'qT',
query: 'q',
removeWordsIfNoResults: 'rWINR',
replaceSynonymsInHighlight: 'rSIH',
restrictSearchableAttributes: 'rSA',
synonyms: 's',
tagFilters: 'tF',
tagRefinements: 'tR',
typoTolerance: 'tT',
optionalTagFilters: 'oTF',
optionalFacetFilters: 'oFF',
snippetEllipsisText: 'sET',
disableExactOnAttributes: 'dEOA',
enableExactOnSingleWordQuery: 'eEOSWQ'
};
var short2Keys = invert_1(keys2Short);
var shortener = {
/**
* All the keys of the state, encoded.
* @const
*/
ENCODED_PARAMETERS: keys_1(short2Keys),
/**
* Decode a shorten attribute
* @param {string} shortKey the shorten attribute
* @return {string} the decoded attribute, undefined otherwise
*/
decode: function(shortKey) {
return short2Keys[shortKey];
},
/**
* Encode an attribute into a short version
* @param {string} key the attribute
* @return {string} the shorten attribute
*/
encode: function(key) {
return keys2Short[key];
}
};
var has = Object.prototype.hasOwnProperty;
var hexTable = (function () {
var array = [];
for (var i = 0; i < 256; ++i) {
array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
}
return array;
}());
var compactQueue = function compactQueue(queue) {
while (queue.length > 1) {
var item = queue.pop();
var obj = item.obj[item.prop];
if (Array.isArray(obj)) {
var compacted = [];
for (var j = 0; j < obj.length; ++j) {
if (typeof obj[j] !== 'undefined') {
compacted.push(obj[j]);
}
}
item.obj[item.prop] = compacted;
}
}
};
var arrayToObject = function arrayToObject(source, options) {
var obj = options && options.plainObjects ? Object.create(null) : {};
for (var i = 0; i < source.length; ++i) {
if (typeof source[i] !== 'undefined') {
obj[i] = source[i];
}
}
return obj;
};
var merge$1 = function merge(target, source, options) {
if (!source) {
return target;
}
if (typeof source !== 'object') {
if (Array.isArray(target)) {
target.push(source);
} else if (typeof target === 'object') {
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
target[source] = true;
}
} else {
return [target, source];
}
return target;
}
if (typeof target !== 'object') {
return [target].concat(source);
}
var mergeTarget = target;
if (Array.isArray(target) && !Array.isArray(source)) {
mergeTarget = arrayToObject(target, options);
}
if (Array.isArray(target) && Array.isArray(source)) {
source.forEach(function (item, i) {
if (has.call(target, i)) {
if (target[i] && typeof target[i] === 'object') {
target[i] = merge(target[i], item, options);
} else {
target.push(item);
}
} else {
target[i] = item;
}
});
return target;
}
return Object.keys(source).reduce(function (acc, key) {
var value = source[key];
if (has.call(acc, key)) {
acc[key] = merge(acc[key], value, options);
} else {
acc[key] = value;
}
return acc;
}, mergeTarget);
};
var assign = function assignSingleSource(target, source) {
return Object.keys(source).reduce(function (acc, key) {
acc[key] = source[key];
return acc;
}, target);
};
var decode = function (str, decoder, charset) {
var strWithoutPlus = str.replace(/\+/g, ' ');
if (charset === 'iso-8859-1') {
// unescape never throws, no try...catch needed:
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
}
// utf-8
try {
return decodeURIComponent(strWithoutPlus);
} catch (e) {
return strWithoutPlus;
}
};
var encode = function encode(str, defaultEncoder, charset) {
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
// It has been adapted here for stricter adherence to RFC 3986
if (str.length === 0) {
return str;
}
var string = typeof str === 'string' ? str : String(str);
if (charset === 'iso-8859-1') {
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
});
}
var out = '';
for (var i = 0; i < string.length; ++i) {
var c = string.charCodeAt(i);
if (
c === 0x2D // -
|| c === 0x2E // .
|| c === 0x5F // _
|| c === 0x7E // ~
|| (c >= 0x30 && c <= 0x39) // 0-9
|| (c >= 0x41 && c <= 0x5A) // a-z
|| (c >= 0x61 && c <= 0x7A) // A-Z
) {
out += string.charAt(i);
continue;
}
if (c < 0x80) {
out = out + hexTable[c];
continue;
}
if (c < 0x800) {
out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
continue;
}
if (c < 0xD800 || c >= 0xE000) {
out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
continue;
}
i += 1;
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
out += hexTable[0xF0 | (c >> 18)]
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
+ hexTable[0x80 | (c & 0x3F)];
}
return out;
};
var compact$1 = function compact(value) {
var queue = [{ obj: { o: value }, prop: 'o' }];
var refs = [];
for (var i = 0; i < queue.length; ++i) {
var item = queue[i];
var obj = item.obj[item.prop];
var keys = Object.keys(obj);
for (var j = 0; j < keys.length; ++j) {
var key = keys[j];
var val = obj[key];
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
queue.push({ obj: obj, prop: key });
refs.push(val);
}
}
}
compactQueue(queue);
return value;
};
var isRegExp = function isRegExp(obj) {
return Object.prototype.toString.call(obj) === '[object RegExp]';
};
var isBuffer = function isBuffer(obj) {
if (obj === null || typeof obj === 'undefined') {
return false;
}
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
};
var combine = function combine(a, b) {
return [].concat(a, b);
};
var utils = {
arrayToObject: arrayToObject,
assign: assign,
combine: combine,
compact: compact$1,
decode: decode,
encode: encode,
isBuffer: isBuffer,
isRegExp: isRegExp,
merge: merge$1
};
var replace = String.prototype.replace;
var percentTwenties = /%20/g;
var formats = {
'default': 'RFC3986',
formatters: {
RFC1738: function (value) {
return replace.call(value, percentTwenties, '+');
},
RFC3986: function (value) {
return value;
}
},
RFC1738: 'RFC1738',
RFC3986: 'RFC3986'
};
var arrayPrefixGenerators = {
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
return prefix + '[]';
},
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
return prefix + '[' + key + ']';
},
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
return prefix;
}
};
var isArray$1 = Array.isArray;
var push = Array.prototype.push;
var pushToArray = function (arr, valueOrArray) {
push.apply(arr, isArray$1(valueOrArray) ? valueOrArray : [valueOrArray]);
};
var toISO = Date.prototype.toISOString;
var defaults$1 = {
addQueryPrefix: false,
allowDots: false,
charset: 'utf-8',
charsetSentinel: false,
delimiter: '&',
encode: true,
encoder: utils.encode,
encodeValuesOnly: false,
// deprecated
indices: false,
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
return toISO.call(date);
},
skipNulls: false,
strictNullHandling: false
};
var stringify = function stringify( // eslint-disable-line func-name-matching
object,
prefix,
generateArrayPrefix,
strictNullHandling,
skipNulls,
encoder,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
) {
var obj = object;
if (typeof filter === 'function') {
obj = filter(prefix, obj);
} else if (obj instanceof Date) {
obj = serializeDate(obj);
}
if (obj === null) {
if (strictNullHandling) {
return encoder && !encodeValuesOnly ? encoder(prefix, defaults$1.encoder, charset) : prefix;
}
obj = '';
}
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
if (encoder) {
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults$1.encoder, charset);
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults$1.encoder, charset))];
}
return [formatter(prefix) + '=' + formatter(String(obj))];
}
var values = [];
if (typeof obj === 'undefined') {
return values;
}
var objKeys;
if (Array.isArray(filter)) {
objKeys = filter;
} else {
var keys = Object.keys(obj);
objKeys = sort ? keys.sort(sort) : keys;
}
for (var i = 0; i < objKeys.length; ++i) {
var key = objKeys[i];
if (skipNulls && obj[key] === null) {
continue;
}
if (Array.isArray(obj)) {
pushToArray(values, stringify(
obj[key],
generateArrayPrefix(prefix, key),
generateArrayPrefix,
strictNullHandling,
skipNulls,
encoder,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
));
} else {
pushToArray(values, stringify(
obj[key],
prefix + (allowDots ? '.' + key : '[' + key + ']'),
generateArrayPrefix,
strictNullHandling,
skipNulls,
encoder,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
));
}
}
return values;
};
var stringify_1 = function (object, opts) {
var obj = object;
var options = opts ? utils.assign({}, opts) : {};
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
throw new TypeError('Encoder has to be a function.');
}
var delimiter = typeof options.delimiter === 'undefined' ? defaults$1.delimiter : options.delimiter;
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults$1.strictNullHandling;
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults$1.skipNulls;
var encode = typeof options.encode === 'boolean' ? options.encode : defaults$1.encode;
var encoder = typeof options.encoder === 'function' ? options.encoder : defaults$1.encoder;
var sort = typeof options.sort === 'function' ? options.sort : null;
var allowDots = typeof options.allowDots === 'undefined' ? defaults$1.allowDots : !!options.allowDots;
var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults$1.serializeDate;
var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults$1.encodeValuesOnly;
var charset = options.charset || defaults$1.charset;
if (typeof options.charset !== 'undefined' && options.charset !== 'utf-8' && options.charset !== 'iso-8859-1') {
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
}
if (typeof options.format === 'undefined') {
options.format = formats['default'];
} else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
throw new TypeError('Unknown format option provided.');
}
var formatter = formats.formatters[options.format];
var objKeys;
var filter;
if (typeof options.filter === 'function') {
filter = options.filter;
obj = filter('', obj);
} else if (Array.isArray(options.filter)) {
filter = options.filter;
objKeys = filter;
}
var keys = [];
if (typeof obj !== 'object' || obj === null) {
return '';
}
var arrayFormat;
if (options.arrayFormat in arrayPrefixGenerators) {
arrayFormat = options.arrayFormat;
} else if ('indices' in options) {
arrayFormat = options.indices ? 'indices' : 'repeat';
} else {
arrayFormat = 'indices';
}
var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
if (!objKeys) {
objKeys = Object.keys(obj);
}
if (sort) {
objKeys.sort(sort);
}
for (var i = 0; i < objKeys.length; ++i) {
var key = objKeys[i];
if (skipNulls && obj[key] === null) {
continue;
}
pushToArray(keys, stringify(
obj[key],
key,
generateArrayPrefix,
strictNullHandling,
skipNulls,
encode ? encoder : null,
filter,
sort,
allowDots,
serializeDate,
formatter,
encodeValuesOnly,
charset
));
}
var joined = keys.join(delimiter);
var prefix = options.addQueryPrefix === true ? '?' : '';
if (options.charsetSentinel) {
if (charset === 'iso-8859-1') {
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
prefix += 'utf8=%26%2310003%3B&';
} else {
// encodeURIComponent('✓')
prefix += 'utf8=%E2%9C%93&';
}
}
return joined.length > 0 ? prefix + joined : '';
};
var has$1 = Object.prototype.hasOwnProperty;
var defaults$2 = {
allowDots: false,
allowPrototypes: false,
arrayLimit: 20,
charset: 'utf-8',
charsetSentinel: false,
decoder: utils.decode,
delimiter: '&',
depth: 5,
ignoreQueryPrefix: false,
interpretNumericEntities: false,
parameterLimit: 1000,
parseArrays: true,
plainObjects: false,
strictNullHandling: false
};
var interpretNumericEntities = function (str) {
return str.replace(/(\d+);/g, function ($0, numberStr) {
return String.fromCharCode(parseInt(numberStr, 10));
});
};
// This is what browsers will submit when the ✓ character occurs in an
// application/x-www-form-urlencoded body and the encoding of the page containing
// the form is iso-8859-1, or when the submitted form has an accept-charset
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
// the ✓ character, such as us-ascii.
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
var parseValues = function parseQueryStringValues(str, options) {
var obj = {};
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
var parts = cleanStr.split(options.delimiter, limit);
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
var i;
var charset = options.charset;
if (options.charsetSentinel) {
for (i = 0; i < parts.length; ++i) {
if (parts[i].indexOf('utf8=') === 0) {
if (parts[i] === charsetSentinel) {
charset = 'utf-8';
} else if (parts[i] === isoSentinel) {
charset = 'iso-8859-1';
}
skipIndex = i;
i = parts.length; // The eslint settings do not allow break;
}
}
}
for (i = 0; i < parts.length; ++i) {
if (i === skipIndex) {
continue;
}
var part = parts[i];
var bracketEqualsPos = part.indexOf(']=');
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
var key, val;
if (pos === -1) {
key = options.decoder(part, defaults$2.decoder, charset);
val = options.strictNullHandling ? null : '';
} else {
key = options.decoder(part.slice(0, pos), defaults$2.decoder, charset);
val = options.decoder(part.slice(pos + 1), defaults$2.decoder, charset);
}
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
val = interpretNumericEntities(val);
}
if (has$1.call(obj, key)) {
obj[key] = utils.combine(obj[key], val);
} else {
obj[key] = val;
}
}
return obj;
};
var parseObject = function (chain, val, options) {
var leaf = val;
for (var i = chain.length - 1; i >= 0; --i) {
var obj;
var root = chain[i];
if (root === '[]' && options.parseArrays) {
obj = [].concat(leaf);
} else {
obj = options.plainObjects ? Object.create(null) : {};
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
var index = parseInt(cleanRoot, 10);
if (!options.parseArrays && cleanRoot === '') {
obj = { 0: leaf };
} else if (
!isNaN(index)
&& root !== cleanRoot
&& String(index) === cleanRoot
&& index >= 0
&& (options.parseArrays && index <= options.arrayLimit)
) {
obj = [];
obj[index] = leaf;
} else {
obj[cleanRoot] = leaf;
}
}
leaf = obj;
}
return leaf;
};
var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
if (!givenKey) {
return;
}
// Transform dot notation to bracket notation
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
// The regex chunks
var brackets = /(\[[^[\]]*])/;
var child = /(\[[^[\]]*])/g;
// Get the parent
var segment = brackets.exec(key);
var parent = segment ? key.slice(0, segment.index) : key;
// Stash the parent if it exists
var keys = [];
if (parent) {
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
if (!options.plainObjects && has$1.call(Object.prototype, parent)) {
if (!options.allowPrototypes) {
return;
}
}
keys.push(parent);
}
// Loop through children appending to the array until we hit depth
var i = 0;
while ((segment = child.exec(key)) !== null && i < options.depth) {
i += 1;
if (!options.plainObjects && has$1.call(Object.prototype, segment[1].slice(1, -1))) {
if (!options.allowPrototypes) {
return;
}
}
keys.push(segment[1]);
}
// If there's a remainder, just add whatever is left
if (segment) {
keys.push('[' + key.slice(segment.index) + ']');
}
return parseObject(keys, val, options);
};
var parse = function (str, opts) {
var options = opts ? utils.assign({}, opts) : {};
if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') {
throw new TypeError('Decoder has to be a function.');
}
options.ignoreQueryPrefix = options.ignoreQueryPrefix === true;
options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults$2.delimiter;
options.depth = typeof options.depth === 'number' ? options.depth : defaults$2.depth;
options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults$2.arrayLimit;
options.parseArrays = options.parseArrays !== false;
options.decoder = typeof options.decoder === 'function' ? options.decoder : defaults$2.decoder;
options.allowDots = typeof options.allowDots === 'undefined' ? defaults$2.allowDots : !!options.allowDots;
options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : defaults$2.plainObjects;
options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : defaults$2.allowPrototypes;
options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : defaults$2.parameterLimit;
options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults$2.strictNullHandling;
if (typeof options.charset !== 'undefined' && options.charset !== 'utf-8' && options.charset !== 'iso-8859-1') {
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
}
if (typeof options.charset === 'undefined') {
options.charset = defaults$2.charset;
}
if (str === '' || str === null || typeof str === 'undefined') {
return options.plainObjects ? Object.create(null) : {};
}
var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
var obj = options.plainObjects ? Object.create(null) : {};
// Iterate over the keys and setup the new object
var keys = Object.keys(tempObj);
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
var newObj = parseKeys(key, tempObj[key], options);
obj = utils.merge(obj, newObj, options);
}
return utils.compact(obj);
};
var lib$1 = {
formats: formats,
parse: parse,
stringify: stringify_1
};
/** Used to compose bitmasks for function metadata. */
var WRAP_BIND_FLAG$7 = 1,
WRAP_PARTIAL_FLAG$4 = 32;
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and `partials` prepended to the arguments it receives.
*
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for partially applied arguments.
*
* **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
* property of bound functions.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to bind.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* function greet(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* }
*
* var object = { 'user': 'fred' };
*
* var bound = _.bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* // Bound with placeholders.
* var bound = _.bind(greet, object, _, '!');
* bound('hi');
* // => 'hi fred!'
*/
var bind = _baseRest(function(func, thisArg, partials) {
var bitmask = WRAP_BIND_FLAG$7;
if (partials.length) {
var holders = _replaceHolders(partials, _getHolder(bind));
bitmask |= WRAP_PARTIAL_FLAG$4;
}
return _createWrap(func, bitmask, thisArg, partials, holders);
});
// Assign default placeholders.
bind.placeholder = {};
var bind_1 = bind;
/**
* The base implementation of `_.pick` without support for individual
* property identifiers.
*
* @private
* @param {Object} object The source object.
* @param {string[]} paths The property paths to pick.
* @returns {Object} Returns the new object.
*/
function basePick(object, paths) {
return _basePickBy(object, paths, function(value, path) {
return hasIn_1(object, path);
});
}
var _basePick = basePick;
/**
* Creates an object composed of the picked `object` properties.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {...(string|string[])} [paths] The property paths to pick.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
*
* _.pick(object, ['a', 'c']);
* // => { 'a': 1, 'c': 3 }
*/
var pick = _flatRest(function(object, paths) {
return object == null ? {} : _basePick(object, paths);
});
var pick_1 = pick;
/**
* The opposite of `_.mapValues`; this method creates an object with the
* same values as `object` and keys generated by running each own enumerable
* string keyed property of `object` thru `iteratee`. The iteratee is invoked
* with three arguments: (value, key, object).
*
* @static
* @memberOf _
* @since 3.8.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @returns {Object} Returns the new mapped object.
* @see _.mapValues
* @example
*
* _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
* return key + value;
* });
* // => { 'a1': 1, 'b2': 2 }
*/
function mapKeys(object, iteratee) {
var result = {};
iteratee = _baseIteratee(iteratee, 3);
_baseForOwn(object, function(value, key, object) {
_baseAssignValue(result, iteratee(value, key, object), value);
});
return result;
}
var mapKeys_1 = mapKeys;
/**
* Creates an object with the same keys as `object` and values generated
* by running each own enumerable string keyed property of `object` thru
* `iteratee`. The iteratee is invoked with three arguments:
* (value, key, object).
*
* @static
* @memberOf _
* @since 2.4.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @returns {Object} Returns the new mapped object.
* @see _.mapKeys
* @example
*
* var users = {
* 'fred': { 'user': 'fred', 'age': 40 },
* 'pebbles': { 'user': 'pebbles', 'age': 1 }
* };
*
* _.mapValues(users, function(o) { return o.age; });
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*
* // The `_.property` iteratee shorthand.
* _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/
function mapValues(object, iteratee) {
var result = {};
iteratee = _baseIteratee(iteratee, 3);
_baseForOwn(object, function(value, key, object) {
_baseAssignValue(result, key, iteratee(value, key, object));
});
return result;
}
var mapValues_1 = mapValues;
/**
* Module containing the functions to serialize and deserialize
* {SearchParameters} in the query string format
* @module algoliasearchHelper.url
*/
var encode$1 = utils.encode;
function recursiveEncode(input) {
if (isPlainObject_1(input)) {
return mapValues_1(input, recursiveEncode);
}
if (Array.isArray(input)) {
return map_1(input, recursiveEncode);
}
if (isString_1(input)) {
return encode$1(input);
}
return input;
}
var refinementsParameters = ['dFR', 'fR', 'nR', 'hFR', 'tR'];
var stateKeys = shortener.ENCODED_PARAMETERS;
function sortQueryStringValues(prefixRegexp, invertedMapping, a, b) {
if (prefixRegexp !== null) {
a = a.replace(prefixRegexp, '');
b = b.replace(prefixRegexp, '');
}
a = invertedMapping[a] || a;
b = invertedMapping[b] || b;
if (stateKeys.indexOf(a) !== -1 || stateKeys.indexOf(b) !== -1) {
if (a === 'q') return -1;
if (b === 'q') return 1;
var isARefinements = refinementsParameters.indexOf(a) !== -1;
var isBRefinements = refinementsParameters.indexOf(b) !== -1;
if (isARefinements && !isBRefinements) {
return 1;
} else if (isBRefinements && !isARefinements) {
return -1;
}
}
return a.localeCompare(b);
}
/**
* Read a query string and return an object containing the state
* @param {string} queryString the query string that will be decoded
* @param {object} [options] accepted options :
* - prefix : the prefix used for the saved attributes, you have to provide the
* same that was used for serialization
* - mapping : map short attributes to another value e.g. {q: 'query'}
* @return {object} partial search parameters object (same properties than in the
* SearchParameters but not exhaustive)
*/
var getStateFromQueryString = function(queryString, options) {
var prefixForParameters = options && options.prefix || '';
var mapping = options && options.mapping || {};
var invertedMapping = invert_1(mapping);
var partialStateWithPrefix = lib$1.parse(queryString);
var prefixRegexp = new RegExp('^' + prefixForParameters);
var partialState = mapKeys_1(
partialStateWithPrefix,
function(v, k) {
var hasPrefix = prefixForParameters && prefixRegexp.test(k);
var unprefixedKey = hasPrefix ? k.replace(prefixRegexp, '') : k;
var decodedKey = shortener.decode(invertedMapping[unprefixedKey] || unprefixedKey);
return decodedKey || unprefixedKey;
}
);
var partialStateWithParsedNumbers = SearchParameters_1._parseNumbers(partialState);
return pick_1(partialStateWithParsedNumbers, SearchParameters_1.PARAMETERS);
};
/**
* Retrieve an object of all the properties that are not understandable as helper
* parameters.
* @param {string} queryString the query string to read
* @param {object} [options] the options
* - prefixForParameters : prefix used for the helper configuration keys
* - mapping : map short attributes to another value e.g. {q: 'query'}
* @return {object} the object containing the parsed configuration that doesn't
* to the helper
*/
var getUnrecognizedParametersInQueryString = function(queryString, options) {
var prefixForParameters = options && options.prefix;
var mapping = options && options.mapping || {};
var invertedMapping = invert_1(mapping);
var foreignConfig = {};
var config = lib$1.parse(queryString);
if (prefixForParameters) {
var prefixRegexp = new RegExp('^' + prefixForParameters);
forEach_1(config, function(v, key) {
if (!prefixRegexp.test(key)) foreignConfig[key] = v;
});
} else {
forEach_1(config, function(v, key) {
if (!shortener.decode(invertedMapping[key] || key)) foreignConfig[key] = v;
});
}
return foreignConfig;
};
/**
* Generate a query string for the state passed according to the options
* @param {SearchParameters} state state to serialize
* @param {object} [options] May contain the following parameters :
* - prefix : prefix in front of the keys
* - mapping : map short attributes to another value e.g. {q: 'query'}
* - moreAttributes : more values to be added in the query string. Those values
* won't be prefixed.
* - safe : get safe urls for use in emails, chat apps or any application auto linking urls.
* All parameters and values will be encoded in a way that it's safe to share them.
* Default to false for legacy reasons ()
* @return {string} the query string
*/
var getQueryStringFromState = function(state, options) {
var moreAttributes = options && options.moreAttributes;
var prefixForParameters = options && options.prefix || '';
var mapping = options && options.mapping || {};
var safe = options && options.safe || false;
var invertedMapping = invert_1(mapping);
var stateForUrl = safe ? state : recursiveEncode(state);
var encodedState = mapKeys_1(
stateForUrl,
function(v, k) {
var shortK = shortener.encode(k);
return prefixForParameters + (mapping[shortK] || shortK);
}
);
var prefixRegexp = prefixForParameters === '' ? null : new RegExp('^' + prefixForParameters);
var sort = bind_1(sortQueryStringValues, null, prefixRegexp, invertedMapping);
if (!isEmpty_1(moreAttributes)) {
var stateQs = lib$1.stringify(encodedState, {encode: safe, sort: sort});
var moreQs = lib$1.stringify(moreAttributes, {encode: safe});
if (!stateQs) return moreQs;
return stateQs + '&' + moreQs;
}
return lib$1.stringify(encodedState, {encode: safe, sort: sort});
};
var url = {
getStateFromQueryString: getStateFromQueryString,
getUnrecognizedParametersInQueryString: getUnrecognizedParametersInQueryString,
getQueryStringFromState: getQueryStringFromState
};
var version = '2.26.1';
/**
* Event triggered when a parameter is set or updated
* @event AlgoliaSearchHelper#event:change
* @property {SearchParameters} state the current parameters with the latest changes applied
* @property {SearchResults} lastResults the previous results received from Algolia. `null` before
* the first request
* @example
* helper.on('change', function(state, lastResults) {
* console.log('The parameters have changed');
* });
*/
/**
* Event triggered when a main search is sent to Algolia
* @event AlgoliaSearchHelper#event:search
* @property {SearchParameters} state the parameters used for this search
* @property {SearchResults} lastResults the results from the previous search. `null` if
* it is the first search.
* @example
* helper.on('search', function(state, lastResults) {
* console.log('Search sent');
* });
*/
/**
* Event triggered when a search using `searchForFacetValues` is sent to Algolia
* @event AlgoliaSearchHelper#event:searchForFacetValues
* @property {SearchParameters} state the parameters used for this search
* it is the first search.
* @property {string} facet the facet searched into
* @property {string} query the query used to search in the facets
* @example
* helper.on('searchForFacetValues', function(state, facet, query) {
* console.log('searchForFacetValues sent');
* });
*/
/**
* Event triggered when a search using `searchOnce` is sent to Algolia
* @event AlgoliaSearchHelper#event:searchOnce
* @property {SearchParameters} state the parameters used for this search
* it is the first search.
* @example
* helper.on('searchOnce', function(state) {
* console.log('searchOnce sent');
* });
*/
/**
* Event triggered when the results are retrieved from Algolia
* @event AlgoliaSearchHelper#event:result
* @property {SearchResults} results the results received from Algolia
* @property {SearchParameters} state the parameters used to query Algolia. Those might
* be different from the one in the helper instance (for example if the network is unreliable).
* @example
* helper.on('result', function(results, state) {
* console.log('Search results received');
* });
*/
/**
* Event triggered when Algolia sends back an error. For example, if an unknown parameter is
* used, the error can be caught using this event.
* @event AlgoliaSearchHelper#event:error
* @property {Error} error the error returned by the Algolia.
* @example
* helper.on('error', function(error) {
* console.log('Houston we got a problem.');
* });
*/
/**
* Event triggered when the queue of queries have been depleted (with any result or outdated queries)
* @event AlgoliaSearchHelper#event:searchQueueEmpty
* @example
* helper.on('searchQueueEmpty', function() {
* console.log('No more search pending');
* // This is received before the result event if we're not expecting new results
* });
*
* helper.search();
*/
/**
* Initialize a new AlgoliaSearchHelper
* @class
* @classdesc The AlgoliaSearchHelper is a class that ease the management of the
* search. It provides an event based interface for search callbacks:
* - change: when the internal search state is changed.
* This event contains a {@link SearchParameters} object and the
* {@link SearchResults} of the last result if any.
* - search: when a search is triggered using the `search()` method.
* - result: when the response is retrieved from Algolia and is processed.
* This event contains a {@link SearchResults} object and the
* {@link SearchParameters} corresponding to this answer.
* - error: when the response is an error. This event contains the error returned by the server.
* @param {AlgoliaSearch} client an AlgoliaSearch client
* @param {string} index the index name to query
* @param {SearchParameters | object} options an object defining the initial
* config of the search. It doesn't have to be a {SearchParameters},
* just an object containing the properties you need from it.
*/
function AlgoliaSearchHelper(client, index, options) {
if (client.addAlgoliaAgent && !doesClientAgentContainsHelper(client)) {
client.addAlgoliaAgent('JS Helper ' + version);
}
this.setClient(client);
var opts = options || {};
opts.index = index;
this.state = SearchParameters_1.make(opts);
this.lastResults = null;
this._queryId = 0;
this._lastQueryIdReceived = -1;
this.derivedHelpers = [];
this._currentNbQueries = 0;
}
util.inherits(AlgoliaSearchHelper, events.EventEmitter);
/**
* Start the search with the parameters set in the state. When the
* method is called, it triggers a `search` event. The results will
* be available through the `result` event. If an error occurs, an
* `error` will be fired instead.
* @return {AlgoliaSearchHelper}
* @fires search
* @fires result
* @fires error
* @chainable
*/
AlgoliaSearchHelper.prototype.search = function() {
this._search();
return this;
};
/**
* Gets the search query parameters that would be sent to the Algolia Client
* for the hits
* @return {object} Query Parameters
*/
AlgoliaSearchHelper.prototype.getQuery = function() {
var state = this.state;
return requestBuilder_1._getHitsSearchParams(state);
};
/**
* Start a search using a modified version of the current state. This method does
* not trigger the helper lifecycle and does not modify the state kept internally
* by the helper. This second aspect means that the next search call will be the
* same as a search call before calling searchOnce.
* @param {object} options can contain all the parameters that can be set to SearchParameters
* plus the index
* @param {function} [callback] optional callback executed when the response from the
* server is back.
* @return {promise|undefined} if a callback is passed the method returns undefined
* otherwise it returns a promise containing an object with two keys :
* - content with a SearchResults
* - state with the state used for the query as a SearchParameters
* @example
* // Changing the number of records returned per page to 1
* // This example uses the callback API
* var state = helper.searchOnce({hitsPerPage: 1},
* function(error, content, state) {
* // if an error occurred it will be passed in error, otherwise its value is null
* // content contains the results formatted as a SearchResults
* // state is the instance of SearchParameters used for this search
* });
* @example
* // Changing the number of records returned per page to 1
* // This example uses the promise API
* var state1 = helper.searchOnce({hitsPerPage: 1})
* .then(promiseHandler);
*
* function promiseHandler(res) {
* // res contains
* // {
* // content : SearchResults
* // state : SearchParameters (the one used for this specific search)
* // }
* }
*/
AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
var tempState = !options ? this.state : this.state.setQueryParameters(options);
var queries = requestBuilder_1._getQueries(tempState.index, tempState);
var self = this;
this._currentNbQueries++;
this.emit('searchOnce', tempState);
if (cb) {
this.client
.search(queries)
.then(function(content) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) {
self.emit('searchQueueEmpty');
}
cb(null, new SearchResults_1(tempState, content.results), tempState);
})
.catch(function(err) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) {
self.emit('searchQueueEmpty');
}
cb(err, null, tempState);
});
return undefined;
}
return this.client.search(queries).then(function(content) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
return {
content: new SearchResults_1(tempState, content.results),
state: tempState,
_originalResponse: content
};
}, function(e) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
throw e;
});
};
/**
* Structure of each result when using
* [`searchForFacetValues()`](reference.html#AlgoliaSearchHelper#searchForFacetValues)
* @typedef FacetSearchHit
* @type {object}
* @property {string} value the facet value
* @property {string} highlighted the facet value highlighted with the query string
* @property {number} count number of occurrence of this facet value
* @property {boolean} isRefined true if the value is already refined
*/
/**
* Structure of the data resolved by the
* [`searchForFacetValues()`](reference.html#AlgoliaSearchHelper#searchForFacetValues)
* promise.
* @typedef FacetSearchResult
* @type {object}
* @property {FacetSearchHit} facetHits the results for this search for facet values
* @property {number} processingTimeMS time taken by the query inside the engine
*/
/**
* Search for facet values based on an query and the name of a faceted attribute. This
* triggers a search and will return a promise. On top of using the query, it also sends
* the parameters from the state so that the search is narrowed down to only the possible values.
*
* See the description of [FacetSearchResult](reference.html#FacetSearchResult)
* @param {string} facet the name of the faceted attribute
* @param {string} query the string query for the search
* @param {number} [maxFacetHits] the maximum number values returned. Should be > 0 and <= 100
* @param {object} [userState] the set of custom parameters to use on top of the current state. Setting a property to `undefined` removes
* it in the generated query.
* @return {promise.} the results of the search
*/
AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
var state = this.state.setQueryParameters(userState || {});
var isDisjunctive = state.isDisjunctiveFacet(facet);
var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
this._currentNbQueries++;
var self = this;
this.emit('searchForFacetValues', state, facet, query);
var searchForFacetValuesPromise = typeof this.client.searchForFacetValues === 'function'
? this.client.searchForFacetValues([{indexName: state.index, params: algoliaQuery}])
: this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
return searchForFacetValuesPromise.then(function addIsRefined(content) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
content = Array.isArray(content) ? content[0] : content;
content.facetHits = forEach_1(content.facetHits, function(f) {
f.isRefined = isDisjunctive ?
state.isDisjunctiveFacetRefined(facet, f.value) :
state.isFacetRefined(facet, f.value);
});
return content;
}, function(e) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
throw e;
});
};
/**
* Sets the text query used for the search.
*
* This method resets the current page to 0.
* @param {string} q the user query
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.setQuery = function(q) {
this._change(this.state.setPage(0).setQuery(q));
return this;
};
/**
* Remove all the types of refinements except tags. A string can be provided to remove
* only the refinements of a specific attribute. For more advanced use case, you can
* provide a function instead. This function should follow the
* [clearCallback definition](#SearchParameters.clearCallback).
*
* This method resets the current page to 0.
* @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
* @example
* // Removing all the refinements
* helper.clearRefinements().search();
* @example
* // Removing all the filters on a the category attribute.
* helper.clearRefinements('category').search();
* @example
* // Removing only the exclude filters on the category facet.
* helper.clearRefinements(function(value, attribute, type) {
* return type === 'exclude' && attribute === 'category';
* }).search();
*/
AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
this._change(this.state.setPage(0).clearRefinements(name));
return this;
};
/**
* Remove all the tag filters.
*
* This method resets the current page to 0.
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.clearTags = function() {
this._change(this.state.setPage(0).clearTags());
return this;
};
/**
* Adds a disjunctive filter to a faceted attribute with the `value` provided. If the
* filter is already set, it doesn't change the filters.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} value the associated value (will be converted to string)
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
this._change(this.state.setPage(0).addDisjunctiveFacetRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
*/
AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
return this.addDisjunctiveFacetRefinement.apply(this, arguments);
};
/**
* Adds a refinement on a hierarchical facet. It will throw
* an exception if the facet is not defined or if the facet
* is already refined.
*
* This method resets the current page to 0.
* @param {string} facet the facet name
* @param {string} path the hierarchical facet path
* @return {AlgoliaSearchHelper}
* @throws Error if the facet is not defined or if the facet is refined
* @chainable
* @fires change
*/
AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
this._change(this.state.setPage(0).addHierarchicalFacetRefinement(facet, value));
return this;
};
/**
* Adds a an numeric filter to an attribute with the `operator` and `value` provided. If the
* filter is already set, it doesn't change the filters.
*
* This method resets the current page to 0.
* @param {string} attribute the attribute on which the numeric filter applies
* @param {string} operator the operator of the filter
* @param {number} value the value of the filter
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
this._change(this.state.setPage(0).addNumericRefinement(attribute, operator, value));
return this;
};
/**
* Adds a filter to a faceted attribute with the `value` provided. If the
* filter is already set, it doesn't change the filters.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} value the associated value (will be converted to string)
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
this._change(this.state.setPage(0).addFacetRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
*/
AlgoliaSearchHelper.prototype.addRefine = function() {
return this.addFacetRefinement.apply(this, arguments);
};
/**
* Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
* filter is already set, it doesn't change the filters.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} value the associated value (will be converted to string)
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
this._change(this.state.setPage(0).addExcludeRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
*/
AlgoliaSearchHelper.prototype.addExclude = function() {
return this.addFacetExclusion.apply(this, arguments);
};
/**
* Adds a tag filter with the `tag` provided. If the
* filter is already set, it doesn't change the filters.
*
* This method resets the current page to 0.
* @param {string} tag the tag to add to the filter
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.addTag = function(tag) {
this._change(this.state.setPage(0).addTagRefinement(tag));
return this;
};
/**
* Removes an numeric filter to an attribute with the `operator` and `value` provided. If the
* filter is not set, it doesn't change the filters.
*
* Some parameters are optional, triggering different behavior:
* - if the value is not provided, then all the numeric value will be removed for the
* specified attribute/operator couple.
* - if the operator is not provided either, then all the numeric filter on this attribute
* will be removed.
*
* This method resets the current page to 0.
* @param {string} attribute the attribute on which the numeric filter applies
* @param {string} [operator] the operator of the filter
* @param {number} [value] the value of the filter
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
this._change(this.state.setPage(0).removeNumericRefinement(attribute, operator, value));
return this;
};
/**
* Removes a disjunctive filter to a faceted attribute with the `value` provided. If the
* filter is not set, it doesn't change the filters.
*
* If the value is omitted, then this method will remove all the filters for the
* attribute.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} [value] the associated value
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
this._change(this.state.setPage(0).removeDisjunctiveFacetRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
*/
AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
};
/**
* Removes the refinement set on a hierarchical facet.
* @param {string} facet the facet name
* @return {AlgoliaSearchHelper}
* @throws Error if the facet is not defined or if the facet is not refined
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
this._change(this.state.setPage(0).removeHierarchicalFacetRefinement(facet));
return this;
};
/**
* Removes a filter to a faceted attribute with the `value` provided. If the
* filter is not set, it doesn't change the filters.
*
* If the value is omitted, then this method will remove all the filters for the
* attribute.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} [value] the associated value
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
this._change(this.state.setPage(0).removeFacetRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
*/
AlgoliaSearchHelper.prototype.removeRefine = function() {
return this.removeFacetRefinement.apply(this, arguments);
};
/**
* Removes an exclusion filter to a faceted attribute with the `value` provided. If the
* filter is not set, it doesn't change the filters.
*
* If the value is omitted, then this method will remove all the filters for the
* attribute.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} [value] the associated value
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
this._change(this.state.setPage(0).removeExcludeRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
*/
AlgoliaSearchHelper.prototype.removeExclude = function() {
return this.removeFacetExclusion.apply(this, arguments);
};
/**
* Removes a tag filter with the `tag` provided. If the
* filter is not set, it doesn't change the filters.
*
* This method resets the current page to 0.
* @param {string} tag tag to remove from the filter
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.removeTag = function(tag) {
this._change(this.state.setPage(0).removeTagRefinement(tag));
return this;
};
/**
* Adds or removes an exclusion filter to a faceted attribute with the `value` provided. If
* the value is set then it removes it, otherwise it adds the filter.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} value the associated value
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
this._change(this.state.setPage(0).toggleExcludeFacetRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
*/
AlgoliaSearchHelper.prototype.toggleExclude = function() {
return this.toggleFacetExclusion.apply(this, arguments);
};
/**
* Adds or removes a filter to a faceted attribute with the `value` provided. If
* the value is set then it removes it, otherwise it adds the filter.
*
* This method can be used for conjunctive, disjunctive and hierarchical filters.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} value the associated value
* @return {AlgoliaSearchHelper}
* @throws Error will throw an error if the facet is not declared in the settings of the helper
* @fires change
* @chainable
* @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
*/
AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
return this.toggleFacetRefinement(facet, value);
};
/**
* Adds or removes a filter to a faceted attribute with the `value` provided. If
* the value is set then it removes it, otherwise it adds the filter.
*
* This method can be used for conjunctive, disjunctive and hierarchical filters.
*
* This method resets the current page to 0.
* @param {string} facet the facet to refine
* @param {string} value the associated value
* @return {AlgoliaSearchHelper}
* @throws Error will throw an error if the facet is not declared in the settings of the helper
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
this._change(this.state.setPage(0).toggleFacetRefinement(facet, value));
return this;
};
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
*/
AlgoliaSearchHelper.prototype.toggleRefine = function() {
return this.toggleFacetRefinement.apply(this, arguments);
};
/**
* Adds or removes a tag filter with the `value` provided. If
* the value is set then it removes it, otherwise it adds the filter.
*
* This method resets the current page to 0.
* @param {string} tag tag to remove or add
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
this._change(this.state.setPage(0).toggleTagRefinement(tag));
return this;
};
/**
* Increments the page number by one.
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
* @example
* helper.setPage(0).nextPage().getPage();
* // returns 1
*/
AlgoliaSearchHelper.prototype.nextPage = function() {
return this.setPage(this.state.page + 1);
};
/**
* Decrements the page number by one.
* @fires change
* @return {AlgoliaSearchHelper}
* @chainable
* @example
* helper.setPage(1).previousPage().getPage();
* // returns 0
*/
AlgoliaSearchHelper.prototype.previousPage = function() {
return this.setPage(this.state.page - 1);
};
/**
* @private
*/
function setCurrentPage(page) {
if (page < 0) throw new Error('Page requested below 0.');
this._change(this.state.setPage(page));
return this;
}
/**
* Change the current page
* @deprecated
* @param {number} page The page number
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.setCurrentPage = setCurrentPage;
/**
* Updates the current page.
* @function
* @param {number} page The page number
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.setPage = setCurrentPage;
/**
* Updates the name of the index that will be targeted by the query.
*
* This method resets the current page to 0.
* @param {string} name the index name
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.setIndex = function(name) {
this._change(this.state.setPage(0).setIndex(name));
return this;
};
/**
* Update a parameter of the search. This method reset the page
*
* The complete list of parameters is available on the
* [Algolia website](https://www.algolia.com/doc/rest#query-an-index).
* The most commonly used parameters have their own [shortcuts](#query-parameters-shortcuts)
* or benefit from higher-level APIs (all the kind of filters and facets have their own API)
*
* This method resets the current page to 0.
* @param {string} parameter name of the parameter to update
* @param {any} value new value of the parameter
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
* @example
* helper.setQueryParameter('hitsPerPage', 20).search();
*/
AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
this._change(this.state.setPage(0).setQueryParameter(parameter, value));
return this;
};
/**
* Set the whole state (warning: will erase previous state)
* @param {SearchParameters} newState the whole new state
* @return {AlgoliaSearchHelper}
* @fires change
* @chainable
*/
AlgoliaSearchHelper.prototype.setState = function(newState) {
this._change(SearchParameters_1.make(newState));
return this;
};
/**
* Get the current search state stored in the helper. This object is immutable.
* @param {string[]} [filters] optional filters to retrieve only a subset of the state
* @return {SearchParameters|object} if filters is specified a plain object is
* returned containing only the requested fields, otherwise return the unfiltered
* state
* @example
* // Get the complete state as stored in the helper
* helper.getState();
* @example
* // Get a part of the state with all the refinements on attributes and the query
* helper.getState(['query', 'attribute:category']);
*/
AlgoliaSearchHelper.prototype.getState = function(filters) {
if (filters === undefined) return this.state;
return this.state.filter(filters);
};
/**
* DEPRECATED Get part of the state as a query string. By default, the output keys will not
* be prefixed and will only take the applied refinements and the query.
* @deprecated
* @param {object} [options] May contain the following parameters :
*
* **filters** : possible values are all the keys of the [SearchParameters](#searchparameters), `index` for
* the index, all the refinements with `attribute:*` or for some specific attributes with
* `attribute:theAttribute`
*
* **prefix** : prefix in front of the keys
*
* **moreAttributes** : more values to be added in the query string. Those values
* won't be prefixed.
* @return {string} the query string
*/
AlgoliaSearchHelper.prototype.getStateAsQueryString = function getStateAsQueryString(options) {
var filters = options && options.filters || ['query', 'attribute:*'];
var partialState = this.getState(filters);
return url.getQueryStringFromState(partialState, options);
};
/**
* DEPRECATED Read a query string and return an object containing the state. Use
* url module.
* @deprecated
* @static
* @param {string} queryString the query string that will be decoded
* @param {object} options accepted options :
* - prefix : the prefix used for the saved attributes, you have to provide the
* same that was used for serialization
* @return {object} partial search parameters object (same properties than in the
* SearchParameters but not exhaustive)
* @see {@link url#getStateFromQueryString}
*/
AlgoliaSearchHelper.getConfigurationFromQueryString = url.getStateFromQueryString;
/**
* DEPRECATED Retrieve an object of all the properties that are not understandable as helper
* parameters. Use url module.
* @deprecated
* @static
* @param {string} queryString the query string to read
* @param {object} options the options
* - prefixForParameters : prefix used for the helper configuration keys
* @return {object} the object containing the parsed configuration that doesn't
* to the helper
*/
AlgoliaSearchHelper.getForeignConfigurationInQueryString = url.getUnrecognizedParametersInQueryString;
/**
* DEPRECATED Overrides part of the state with the properties stored in the provided query
* string.
* @deprecated
* @param {string} queryString the query string containing the informations to url the state
* @param {object} options optional parameters :
* - prefix : prefix used for the algolia parameters
* - triggerChange : if set to true the state update will trigger a change event
*/
AlgoliaSearchHelper.prototype.setStateFromQueryString = function(queryString, options) {
var triggerChange = options && options.triggerChange || false;
var configuration = url.getStateFromQueryString(queryString, options);
var updatedState = this.state.setQueryParameters(configuration);
if (triggerChange) this.setState(updatedState);
else this.overrideStateWithoutTriggeringChangeEvent(updatedState);
};
/**
* Override the current state without triggering a change event.
* Do not use this method unless you know what you are doing. (see the example
* for a legit use case)
* @param {SearchParameters} newState the whole new state
* @return {AlgoliaSearchHelper}
* @example
* helper.on('change', function(state){
* // In this function you might want to find a way to store the state in the url/history
* updateYourURL(state)
* })
* window.onpopstate = function(event){
* // This is naive though as you should check if the state is really defined etc.
* helper.overrideStateWithoutTriggeringChangeEvent(event.state).search()
* }
* @chainable
*/
AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
this.state = new SearchParameters_1(newState);
return this;
};
/**
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
*/
AlgoliaSearchHelper.prototype.isRefined = function(facet, value) {
if (this.state.isConjunctiveFacet(facet)) {
return this.state.isFacetRefined(facet, value);
} else if (this.state.isDisjunctiveFacet(facet)) {
return this.state.isDisjunctiveFacetRefined(facet, value);
}
throw new Error(facet +
' is not properly defined in this helper configuration' +
'(use the facets or disjunctiveFacets keys to configure it)');
};
/**
* Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
* @param {string} attribute the name of the attribute
* @return {boolean} true if the attribute is filtered by at least one value
* @example
* // hasRefinements works with numeric, conjunctive, disjunctive and hierarchical filters
* helper.hasRefinements('price'); // false
* helper.addNumericRefinement('price', '>', 100);
* helper.hasRefinements('price'); // true
*
* helper.hasRefinements('color'); // false
* helper.addFacetRefinement('color', 'blue');
* helper.hasRefinements('color'); // true
*
* helper.hasRefinements('material'); // false
* helper.addDisjunctiveFacetRefinement('material', 'plastic');
* helper.hasRefinements('material'); // true
*
* helper.hasRefinements('categories'); // false
* helper.toggleFacetRefinement('categories', 'kitchen > knife');
* helper.hasRefinements('categories'); // true
*
*/
AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
if (!isEmpty_1(this.state.getNumericRefinements(attribute))) {
return true;
} else if (this.state.isConjunctiveFacet(attribute)) {
return this.state.isFacetRefined(attribute);
} else if (this.state.isDisjunctiveFacet(attribute)) {
return this.state.isDisjunctiveFacetRefined(attribute);
} else if (this.state.isHierarchicalFacet(attribute)) {
return this.state.isHierarchicalFacetRefined(attribute);
}
// there's currently no way to know that the user did call `addNumericRefinement` at some point
// thus we cannot distinguish if there once was a numeric refinement that was cleared
// so we will return false in every other situations to be consistent
// while what we should do here is throw because we did not find the attribute in any type
// of refinement
return false;
};
/**
* Check if a value is excluded for a specific faceted attribute. If the value
* is omitted then the function checks if there is any excluding refinements.
*
* @param {string} facet name of the attribute for used for faceting
* @param {string} [value] optional value. If passed will test that this value
* is filtering the given facet.
* @return {boolean} true if refined
* @example
* helper.isExcludeRefined('color'); // false
* helper.isExcludeRefined('color', 'blue') // false
* helper.isExcludeRefined('color', 'red') // false
*
* helper.addFacetExclusion('color', 'red');
*
* helper.isExcludeRefined('color'); // true
* helper.isExcludeRefined('color', 'blue') // false
* helper.isExcludeRefined('color', 'red') // true
*/
AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
return this.state.isExcludeRefined(facet, value);
};
/**
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
*/
AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
return this.state.isDisjunctiveFacetRefined(facet, value);
};
/**
* Check if the string is a currently filtering tag.
* @param {string} tag tag to check
* @return {boolean}
*/
AlgoliaSearchHelper.prototype.hasTag = function(tag) {
return this.state.isTagRefined(tag);
};
/**
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
*/
AlgoliaSearchHelper.prototype.isTagRefined = function() {
return this.hasTagRefinements.apply(this, arguments);
};
/**
* Get the name of the currently used index.
* @return {string}
* @example
* helper.setIndex('highestPrice_products').getIndex();
* // returns 'highestPrice_products'
*/
AlgoliaSearchHelper.prototype.getIndex = function() {
return this.state.index;
};
function getCurrentPage() {
return this.state.page;
}
/**
* Get the currently selected page
* @deprecated
* @return {number} the current page
*/
AlgoliaSearchHelper.prototype.getCurrentPage = getCurrentPage;
/**
* Get the currently selected page
* @function
* @return {number} the current page
*/
AlgoliaSearchHelper.prototype.getPage = getCurrentPage;
/**
* Get all the tags currently set to filters the results.
*
* @return {string[]} The list of tags currently set.
*/
AlgoliaSearchHelper.prototype.getTags = function() {
return this.state.tagRefinements;
};
/**
* Get a parameter of the search by its name. It is possible that a parameter is directly
* defined in the index dashboard, but it will be undefined using this method.
*
* The complete list of parameters is
* available on the
* [Algolia website](https://www.algolia.com/doc/rest#query-an-index).
* The most commonly used parameters have their own [shortcuts](#query-parameters-shortcuts)
* or benefit from higher-level APIs (all the kind of filters have their own API)
* @param {string} parameterName the parameter name
* @return {any} the parameter value
* @example
* var hitsPerPage = helper.getQueryParameter('hitsPerPage');
*/
AlgoliaSearchHelper.prototype.getQueryParameter = function(parameterName) {
return this.state.getQueryParameter(parameterName);
};
/**
* Get the list of refinements for a given attribute. This method works with
* conjunctive, disjunctive, excluding and numerical filters.
*
* See also SearchResults#getRefinements
*
* @param {string} facetName attribute name used for faceting
* @return {Array.} All Refinement are objects that contain a value, and
* a type. Numeric also contains an operator.
* @example
* helper.addNumericRefinement('price', '>', 100);
* helper.getRefinements('price');
* // [
* // {
* // "value": [
* // 100
* // ],
* // "operator": ">",
* // "type": "numeric"
* // }
* // ]
* @example
* helper.addFacetRefinement('color', 'blue');
* helper.addFacetExclusion('color', 'red');
* helper.getRefinements('color');
* // [
* // {
* // "value": "blue",
* // "type": "conjunctive"
* // },
* // {
* // "value": "red",
* // "type": "exclude"
* // }
* // ]
* @example
* helper.addDisjunctiveFacetRefinement('material', 'plastic');
* // [
* // {
* // "value": "plastic",
* // "type": "disjunctive"
* // }
* // ]
*/
AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
var refinements = [];
if (this.state.isConjunctiveFacet(facetName)) {
var conjRefinements = this.state.getConjunctiveRefinements(facetName);
forEach_1(conjRefinements, function(r) {
refinements.push({
value: r,
type: 'conjunctive'
});
});
var excludeRefinements = this.state.getExcludeRefinements(facetName);
forEach_1(excludeRefinements, function(r) {
refinements.push({
value: r,
type: 'exclude'
});
});
} else if (this.state.isDisjunctiveFacet(facetName)) {
var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
forEach_1(disjRefinements, function(r) {
refinements.push({
value: r,
type: 'disjunctive'
});
});
}
var numericRefinements = this.state.getNumericRefinements(facetName);
forEach_1(numericRefinements, function(value, operator) {
refinements.push({
value: value,
operator: operator,
type: 'numeric'
});
});
return refinements;
};
/**
* Return the current refinement for the (attribute, operator)
* @param {string} attribute attribute in the record
* @param {string} operator operator applied on the refined values
* @return {Array.} refined values
*/
AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
return this.state.getNumericRefinement(attribute, operator);
};
/**
* Get the current breadcrumb for a hierarchical facet, as an array
* @param {string} facetName Hierarchical facet name
* @return {array.} the path as an array of string
*/
AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
return this.state.getHierarchicalFacetBreadcrumb(facetName);
};
// /////////// PRIVATE
/**
* Perform the underlying queries
* @private
* @return {undefined}
* @fires search
* @fires result
* @fires error
*/
AlgoliaSearchHelper.prototype._search = function() {
var state = this.state;
var mainQueries = requestBuilder_1._getQueries(state.index, state);
var states = [{
state: state,
queriesCount: mainQueries.length,
helper: this
}];
this.emit('search', state, this.lastResults);
var derivedQueries = map_1(this.derivedHelpers, function(derivedHelper) {
var derivedState = derivedHelper.getModifiedState(state);
var queries = requestBuilder_1._getQueries(derivedState.index, derivedState);
states.push({
state: derivedState,
queriesCount: queries.length,
helper: derivedHelper
});
derivedHelper.emit('search', derivedState, derivedHelper.lastResults);
return queries;
});
var queries = mainQueries.concat(flatten_1(derivedQueries));
var queryId = this._queryId++;
this._currentNbQueries++;
try {
this.client.search(queries)
.then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
.catch(this._dispatchAlgoliaError.bind(this, queryId));
} catch (err) {
// If we reach this part, we're in an internal error state
this.emit('error', err);
}
};
/**
* Transform the responses as sent by the server and transform them into a user
* usable object that merge the results of all the batch requests. It will dispatch
* over the different helper + derived helpers (when there are some).
* @private
* @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
* state state used for to generate the request
* @param {number} queryId id of the current request
* @param {object} content content of the response
* @return {undefined}
*/
AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
// FIXME remove the number of outdated queries discarded instead of just one
if (queryId < this._lastQueryIdReceived) {
// Outdated answer
return;
}
this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
this._lastQueryIdReceived = queryId;
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
var results = content.results.slice();
forEach_1(states, function(s) {
var state = s.state;
var queriesCount = s.queriesCount;
var helper = s.helper;
var specificResults = results.splice(0, queriesCount);
var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
helper.emit('result', formattedResponse, state);
});
};
AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, err) {
if (queryId < this._lastQueryIdReceived) {
// Outdated answer
return;
}
this._currentNbQueries -= queryId - this._lastQueryIdReceived;
this._lastQueryIdReceived = queryId;
this.emit('error', err);
if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
};
AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
return query ||
facetFilters.length !== 0 ||
numericFilters.length !== 0 ||
tagFilters.length !== 0;
};
/**
* Test if there are some disjunctive refinements on the facet
* @private
* @param {string} facet the attribute to test
* @return {boolean}
*/
AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
return this.state.disjunctiveRefinements[facet] &&
this.state.disjunctiveRefinements[facet].length > 0;
};
AlgoliaSearchHelper.prototype._change = function(newState) {
if (newState !== this.state) {
this.state = newState;
this.emit('change', this.state, this.lastResults);
}
};
/**
* Clears the cache of the underlying Algolia client.
* @return {AlgoliaSearchHelper}
*/
AlgoliaSearchHelper.prototype.clearCache = function() {
this.client.clearCache && this.client.clearCache();
return this;
};
/**
* Updates the internal client instance. If the reference of the clients
* are equal then no update is actually done.
* @param {AlgoliaSearch} newClient an AlgoliaSearch client
* @return {AlgoliaSearchHelper}
*/
AlgoliaSearchHelper.prototype.setClient = function(newClient) {
if (this.client === newClient) return this;
if (newClient.addAlgoliaAgent && !doesClientAgentContainsHelper(newClient)) newClient.addAlgoliaAgent('JS Helper ' + version);
this.client = newClient;
return this;
};
/**
* Gets the instance of the currently used client.
* @return {AlgoliaSearch}
*/
AlgoliaSearchHelper.prototype.getClient = function() {
return this.client;
};
/**
* Creates an derived instance of the Helper. A derived helper
* is a way to request other indices synchronised with the lifecycle
* of the main Helper. This mechanism uses the multiqueries feature
* of Algolia to aggregate all the requests in a single network call.
*
* This method takes a function that is used to create a new SearchParameter
* that will be used to create requests to Algolia. Those new requests
* are created just before the `search` event. The signature of the function
* is `SearchParameters -> SearchParameters`.
*
* This method returns a new DerivedHelper which is an EventEmitter
* that fires the same `search`, `result` and `error` events. Those
* events, however, will receive data specific to this DerivedHelper
* and the SearchParameters that is returned by the call of the
* parameter function.
* @param {function} fn SearchParameters -> SearchParameters
* @return {DerivedHelper}
*/
AlgoliaSearchHelper.prototype.derive = function(fn) {
var derivedHelper = new DerivedHelper_1(this, fn);
this.derivedHelpers.push(derivedHelper);
return derivedHelper;
};
/**
* This method detaches a derived Helper from the main one. Prefer using the one from the
* derived helper itself, to remove the event listeners too.
* @private
* @return {undefined}
* @throws Error
*/
AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
var pos = this.derivedHelpers.indexOf(derivedHelper);
if (pos === -1) throw new Error('Derived helper already detached');
this.derivedHelpers.splice(pos, 1);
};
/**
* This method returns true if there is currently at least one on-going search.
* @return {boolean} true if there is a search pending
*/
AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
return this._currentNbQueries > 0;
};
/**
* @typedef AlgoliaSearchHelper.NumericRefinement
* @type {object}
* @property {number[]} value the numbers that are used for filtering this attribute with
* the operator specified.
* @property {string} operator the faceting data: value, number of entries
* @property {string} type will be 'numeric'
*/
/**
* @typedef AlgoliaSearchHelper.FacetRefinement
* @type {object}
* @property {string} value the string use to filter the attribute
* @property {string} type the type of filter: 'conjunctive', 'disjunctive', 'exclude'
*/
/*
* This function tests if the _ua parameter of the client
* already contains the JS Helper UA
*/
function doesClientAgentContainsHelper(client) {
// this relies on JS Client internal variable, this might break if implementation changes
var currentAgent = client._ua;
return !currentAgent ? false :
currentAgent.indexOf('JS Helper') !== -1;
}
var algoliasearch_helper = AlgoliaSearchHelper;
/**
* The algoliasearchHelper module is the function that will let its
* contains everything needed to use the Algoliasearch
* Helper. It is a also a function that instanciate the helper.
* To use the helper, you also need the Algolia JS client v3.
* @example
* //using the UMD build
* var client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
* var helper = algoliasearchHelper(client, 'bestbuy', {
* facets: ['shipping'],
* disjunctiveFacets: ['category']
* });
* helper.on('result', function(result) {
* console.log(result);
* });
* helper.toggleRefine('Movies & TV Shows')
* .toggleRefine('Free shipping')
* .search();
* @example
* // The helper is an event emitter using the node API
* helper.on('result', updateTheResults);
* helper.once('result', updateTheResults);
* helper.removeListener('result', updateTheResults);
* helper.removeAllListeners('result');
* @module algoliasearchHelper
* @param {AlgoliaSearch} client an AlgoliaSearch client
* @param {string} index the name of the index to query
* @param {SearchParameters|object} opts an object defining the initial config of the search. It doesn't have to be a {SearchParameters}, just an object containing the properties you need from it.
* @return {AlgoliaSearchHelper}
*/
function algoliasearchHelper(client, index, opts) {
return new algoliasearch_helper(client, index, opts);
}
/**
* The version currently used
* @member module:algoliasearchHelper.version
* @type {number}
*/
algoliasearchHelper.version = version;
/**
* Constructor for the Helper.
* @member module:algoliasearchHelper.AlgoliaSearchHelper
* @type {AlgoliaSearchHelper}
*/
algoliasearchHelper.AlgoliaSearchHelper = algoliasearch_helper;
/**
* Constructor for the object containing all the parameters of the search.
* @member module:algoliasearchHelper.SearchParameters
* @type {SearchParameters}
*/
algoliasearchHelper.SearchParameters = SearchParameters_1;
/**
* Constructor for the object containing the results of the search.
* @member module:algoliasearchHelper.SearchResults
* @type {SearchResults}
*/
algoliasearchHelper.SearchResults = SearchResults_1;
/**
* URL tools to generate query string and parse them from/into
* SearchParameters
* @member module:algoliasearchHelper.url
* @type {object} {@link url}
*
*/
algoliasearchHelper.url = url;
var algoliasearchHelper_1 = algoliasearchHelper;
/**
* This method is like `_.merge` except that it accepts `customizer` which
* is invoked to produce the merged values of the destination and source
* properties. If `customizer` returns `undefined`, merging is handled by the
* method instead. The `customizer` is invoked with six arguments:
* (objValue, srcValue, key, object, source, stack).
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Object
* @param {Object} object The destination object.
* @param {...Object} sources The source objects.
* @param {Function} customizer The function to customize assigned values.
* @returns {Object} Returns `object`.
* @example
*
* function customizer(objValue, srcValue) {
* if (_.isArray(objValue)) {
* return objValue.concat(srcValue);
* }
* }
*
* var object = { 'a': [1], 'b': [2] };
* var other = { 'a': [3], 'b': [4] };
*
* _.mergeWith(object, other, customizer);
* // => { 'a': [1, 3], 'b': [2, 4] }
*/
var mergeWith = _createAssigner(function(object, source, srcIndex, customizer) {
_baseMerge(object, source, srcIndex, customizer);
});
var mergeWith_1 = mergeWith;
/** Used as references for various `Number` constants. */
var INFINITY$3 = 1 / 0;
/**
* Creates a set object of `values`.
*
* @private
* @param {Array} values The values to add to the set.
* @returns {Object} Returns the new set.
*/
var createSet = !(_Set && (1 / _setToArray(new _Set([,-0]))[1]) == INFINITY$3) ? noop_1 : function(values) {
return new _Set(values);
};
var _createSet = createSet;
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE$1 = 200;
/**
* The base implementation of `_.uniqBy` without support for iteratee shorthands.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new duplicate free array.
*/
function baseUniq(array, iteratee, comparator) {
var index = -1,
includes = _arrayIncludes,
length = array.length,
isCommon = true,
result = [],
seen = result;
if (comparator) {
isCommon = false;
includes = _arrayIncludesWith;
}
else if (length >= LARGE_ARRAY_SIZE$1) {
var set = iteratee ? null : _createSet(array);
if (set) {
return _setToArray(set);
}
isCommon = false;
includes = _cacheHas;
seen = new _SetCache;
}
else {
seen = iteratee ? [] : result;
}
outer:
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value) : value;
value = (comparator || value !== 0) ? value : 0;
if (isCommon && computed === computed) {
var seenIndex = seen.length;
while (seenIndex--) {
if (seen[seenIndex] === computed) {
continue outer;
}
}
if (iteratee) {
seen.push(computed);
}
result.push(value);
}
else if (!includes(seen, computed, comparator)) {
if (seen !== result) {
seen.push(computed);
}
result.push(value);
}
}
return result;
}
var _baseUniq = baseUniq;
/**
* Creates an array of unique values, in order, from all given arrays using
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of combined values.
* @example
*
* _.union([2], [1, 2]);
* // => [2, 1]
*/
var union = _baseRest(function(arrays) {
return _baseUniq(_baseFlatten(arrays, 1, isArrayLikeObject_1, true));
});
var union_1 = union;
var RoutingManager =
/*#__PURE__*/
function () {
function RoutingManager() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
instantSearchInstance = _ref.instantSearchInstance,
router = _ref.router,
stateMapping = _ref.stateMapping;
_classCallCheck(this, RoutingManager);
this.originalConfig = null;
this.firstRender = true;
this.router = router;
this.stateMapping = stateMapping;
this.instantSearchInstance = instantSearchInstance;
this.originalUIState = this.stateMapping.routeToState(this.router.read());
}
_createClass(RoutingManager, [{
key: "init",
value: function init(_ref2) {
var state = _ref2.state;
// store the initial state from the storage
// so that we can compare it with the state after the first render
// in case the searchFunction has modifyied it.
this.initState = this.getAllUIStates({
searchParameters: state
});
}
}, {
key: "getConfiguration",
value: function getConfiguration(currentConfiguration) {
// we need to create a REAL helper to then get its state. Because some parameters
// like hierarchicalFacet.rootPath are then triggering a default refinement that would
// be not present if it was not going trough the SearchParameters constructor
this.originalConfig = algoliasearchHelper_1({}, currentConfiguration.index, currentConfiguration).state; // The content of getAllSearchParameters is destructured to return a plain object
return _objectSpread({}, this.getAllSearchParameters({
currentSearchParameters: this.originalConfig,
uiState: this.originalUIState
}));
}
}, {
key: "render",
value: function render(_ref3) {
var state = _ref3.state;
if (this.firstRender) {
this.firstRender = false;
this.setupRouting(state);
}
}
}, {
key: "setupRouting",
value: function setupRouting(state) {
var _this = this;
var helper = this.instantSearchInstance.helper;
this.router.onUpdate(function (route) {
var uiState = _this.stateMapping.routeToState(route);
var currentUIState = _this.getAllUIStates({
searchParameters: helper.state
});
if (isEqual_1(uiState, currentUIState)) return;
var searchParameters = _this.getAllSearchParameters({
currentSearchParameters: state,
instantSearchInstance: _this.instantSearchInstance,
uiState: uiState
});
var fullHelperState = _objectSpread({}, _this.originalConfig, searchParameters);
if (isEqual_1(fullHelperState, searchParameters)) return;
helper.overrideStateWithoutTriggeringChangeEvent(searchParameters).search();
});
this.renderURLFromState = function (searchParameters) {
var uiState = _this.getAllUIStates({
searchParameters: searchParameters
});
var route = _this.stateMapping.stateToRoute(uiState);
_this.router.write(route);
};
helper.on('change', this.renderURLFromState); // Compare initial state and post first render state, in order
// to see if the query has been changed by a searchFunction
var firstRenderState = this.getAllUIStates({
searchParameters: state
});
if (!isEqual_1(this.initState, firstRenderState)) {
// force update the URL, if the state has changed since the initial URL read
// We do this in order to make a URL update when there is search function
// that prevent the search of the initial rendering
// See: https://github.com/algolia/instantsearch.js/issues/2523#issuecomment-339356157
var route = this.stateMapping.stateToRoute(firstRenderState);
this.router.write(route);
}
}
}, {
key: "dispose",
value: function dispose() {
if (this.renderURLFromState) {
this.instantSearchInstance.helper.removeListener('change', this.renderURLFromState);
}
this.router.dispose();
}
}, {
key: "getAllSearchParameters",
value: function getAllSearchParameters(_ref4) {
var currentSearchParameters = _ref4.currentSearchParameters,
uiState = _ref4.uiState;
var widgets = this.instantSearchInstance.widgets;
var searchParameters = widgets.reduce(function (sp, w) {
if (!w.getWidgetSearchParameters) return sp;
return w.getWidgetSearchParameters(sp, {
uiState: uiState
});
}, currentSearchParameters);
return searchParameters;
}
}, {
key: "getAllUIStates",
value: function getAllUIStates(_ref5) {
var searchParameters = _ref5.searchParameters;
var _this$instantSearchIn = this.instantSearchInstance,
widgets = _this$instantSearchIn.widgets,
helper = _this$instantSearchIn.helper;
var uiState = widgets.filter(function (w) {
return Boolean(w.getWidgetState);
}).reduce(function (u, w) {
return w.getWidgetState(u, {
helper: helper,
searchParameters: searchParameters
});
}, {});
return uiState;
} // External API's
}, {
key: "createURL",
value: function createURL(state) {
var uiState = this.getAllUIStates({
searchParameters: state
});
var route = this.stateMapping.stateToRoute(uiState);
return this.router.createURL(route);
}
}, {
key: "onHistoryChange",
value: function onHistoryChange(fn) {
var _this2 = this;
var helper = this.instantSearchInstance.helper;
this.router.onUpdate(function (route) {
var uiState = _this2.stateMapping.routeToState(route);
var currentUIState = _this2.getAllUIStates({
searchParameters: helper.state
});
if (isEqual_1(uiState, currentUIState)) return;
var searchParameters = _this2.getAllSearchParameters({
currentSearchParameters: helper.state,
instantSearchInstance: _this2.instantSearchInstance,
uiState: uiState
});
var fullSearchParameters = _objectSpread({}, _this2.originalConfig, searchParameters);
fn(fullSearchParameters);
});
return;
}
}]);
return RoutingManager;
}();
var SimpleUIStateMapping =
/*#__PURE__*/
function () {
function SimpleUIStateMapping() {
_classCallCheck(this, SimpleUIStateMapping);
}
_createClass(SimpleUIStateMapping, [{
key: "stateToRoute",
value: function stateToRoute(uiState) {
return uiState;
}
}, {
key: "routeToState",
value: function routeToState(routeState) {
return routeState;
}
}]);
return SimpleUIStateMapping;
}();
function simpleMapping () {
return new SimpleUIStateMapping();
}
function defaultCreateURL(_ref) {
var qsModule = _ref.qsModule,
routeState = _ref.routeState,
location = _ref.location;
var protocol = location.protocol,
hostname = location.hostname,
_location$port = location.port,
port = _location$port === void 0 ? '' : _location$port,
pathname = location.pathname,
hash = location.hash;
var queryString = qsModule.stringify(routeState);
var portWithPrefix = port === '' ? '' : ":".concat(port); // IE <= 11 has no location.origin or buggy. Therefore we don't rely on it
if (!routeState || Object.keys(routeState).length === 0) return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname).concat(hash);else return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
}
function defaultParseURL(_ref2) {
var qsModule = _ref2.qsModule,
location = _ref2.location;
return qsModule.parse(location.search.slice(1));
}
var BrowserHistory =
/*#__PURE__*/
function () {
/**
* Initializes a new storage provider that will sync the search state in the URL
* using web API (window.location.pushState and onpopstate event).
* @param {object} $0 the options.
* @param {function(object):string} [$0.windowTitle] function that transforms a UI state
* into a title for the page. It takes one parameter: a syncable object (generated by the mapping
* provided to the URL sync). It should return a string that will be the title.
* @param {number} [$0.writeDelay = 400] time before a write is actually done.
* Prevent having too much entries in the history and thus make the back button more friendly.
* @param {function(qs, object):string} [$0.createURL] generates the full URL. If not provided,
* the storage adaptor will mapped all syncable keys to the query string of the URL. The first
* parameter is a utility object that has two methods: `stringify` that creates a query string
* from an object and `parse` that transforms a query string into an object.
* @param {function(qs): object} [$0.parseURL] parses an URL into an object. It should symetrical
* to `createURL`. It gets as an argument an object that contains two methods: `stringify` that
* creates a query string from an object and `parse` that transforms a query string into an object.
*/
function BrowserHistory() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
windowTitle = _ref3.windowTitle,
_ref3$writeDelay = _ref3.writeDelay,
writeDelay = _ref3$writeDelay === void 0 ? 400 : _ref3$writeDelay,
_ref3$createURL = _ref3.createURL,
createURL = _ref3$createURL === void 0 ? defaultCreateURL : _ref3$createURL,
_ref3$parseURL = _ref3.parseURL,
parseURL = _ref3$parseURL === void 0 ? defaultParseURL : _ref3$parseURL;
_classCallCheck(this, BrowserHistory);
this.windowTitle = windowTitle;
this.writeTimer = undefined;
this.writeDelay = writeDelay;
this._createURL = createURL;
this.parseURL = parseURL;
}
/**
* This method pushes a search state into the URL.
* @param {object} routeState a syncable UI state
* @return {undefined}
*/
_createClass(BrowserHistory, [{
key: "write",
value: function write(routeState) {
var _this = this;
var url = this.createURL(routeState);
var title = this.windowTitle && this.windowTitle(routeState);
if (this.writeTimer) {
window.clearTimeout(this.writeTimer);
}
this.writeTimer = setTimeout(function () {
if (title) window.document.title = title;
window.history.pushState(routeState, title || '', url);
_this.writeTimer = undefined;
}, this.writeDelay);
}
/**
* This methods read the URL and returns a syncable UI search state.
* @return {object} the equivalent to what is store in the URL as an object
*/
}, {
key: "read",
value: function read() {
return this.parseURL({
qsModule: lib$1,
location: window.location
});
}
/**
* This methods sets a callback on the `onpopstate` event of the history API
* of the current page. This way, the URL sync can keep track of the changes.
* @param {function(object)} cb the callback that will receive the latest routeState.
* It is called when the URL is updated.
* @returns {undefined}
*/
}, {
key: "onUpdate",
value: function onUpdate(cb) {
var _this2 = this;
this._onPopState = function (event) {
if (_this2.writeTimer) {
window.clearTimeout(_this2.writeTimer);
_this2.writeTimer = undefined;
}
var routeState = event.state; // at initial load, the state is read from the URL without
// update. Therefore the state object is not there. In this
// case we fallback and read the URL.
if (!routeState) {
cb(_this2.read());
} else {
cb(routeState);
}
};
window.addEventListener('popstate', this._onPopState);
}
/**
* This method creates a complete URL from a given syncable UI state.
*
* It always generates the full url, not a relative one.
* This way we can handle cases like using a , see
* https://github.com/algolia/instantsearch.js/issues/790 for the original issue
*
* @param {object} routeState a syncable UI state
* @returns {string} the full URL for the provided syncable state
*/
}, {
key: "createURL",
value: function createURL(routeState) {
return this._createURL({
qsModule: lib$1,
routeState: routeState,
location: window.location
});
}
/**
* This method removes the event listener and cleans up the URL.
* @returns {undefined}
*/
}, {
key: "dispose",
value: function dispose() {
window.removeEventListener('popstate', this._onPopState);
if (this.writeTimer) window.clearTimeout(this.writeTimer);
this.write();
}
}]);
return BrowserHistory;
}();
function historyRouter () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _construct(BrowserHistory, args);
}
var version$1 = '3.1.0';
/**
* Creates a duplicate-free version of an array, using
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons, in which only the first occurrence of each element
* is kept. The order of result values is determined by the order they occur
* in the array.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to inspect.
* @returns {Array} Returns the new duplicate free array.
* @example
*
* _.uniq([2, 1, 2]);
* // => [2, 1]
*/
function uniq(array) {
return (array && array.length) ? _baseUniq(array) : [];
}
var uniq_1 = uniq;
/** Used to compose bitmasks for function metadata. */
var WRAP_CURRY_FLAG$5 = 8;
/**
* Creates a function that accepts arguments of `func` and either invokes
* `func` returning its result, if at least `arity` number of arguments have
* been provided, or returns a function that accepts the remaining `func`
* arguments, and so on. The arity of `func` may be specified if `func.length`
* is not sufficient.
*
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for provided arguments.
*
* **Note:** This method doesn't set the "length" property of curried functions.
*
* @static
* @memberOf _
* @since 2.0.0
* @category Function
* @param {Function} func The function to curry.
* @param {number} [arity=func.length] The arity of `func`.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
* @returns {Function} Returns the new curried function.
* @example
*
* var abc = function(a, b, c) {
* return [a, b, c];
* };
*
* var curried = _.curry(abc);
*
* curried(1)(2)(3);
* // => [1, 2, 3]
*
* curried(1, 2)(3);
* // => [1, 2, 3]
*
* curried(1, 2, 3);
* // => [1, 2, 3]
*
* // Curried with placeholders.
* curried(1)(_, 3)(2);
* // => [1, 2, 3]
*/
function curry(func, arity, guard) {
arity = guard ? undefined : arity;
var result = _createWrap(func, WRAP_CURRY_FLAG$5, undefined, undefined, undefined, undefined, undefined, arity);
result.placeholder = curry.placeholder;
return result;
}
// Assign default placeholders.
curry.placeholder = {};
var curry_1 = curry;
var compiler = createCommonjsModule(function (module, exports) {
/*
* Copyright 2011 Twitter, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function (Hogan) {
// Setup regex assignments
// remove whitespace according to Mustache spec
var rIsWhitespace = /\S/,
rQuot = /\"/g,
rNewline = /\n/g,
rCr = /\r/g,
rSlash = /\\/g,
rLineSep = /\u2028/,
rParagraphSep = /\u2029/;
Hogan.tags = {
'#': 1, '^': 2, '<': 3, '$': 4,
'/': 5, '!': 6, '>': 7, '=': 8, '_v': 9,
'{': 10, '&': 11, '_t': 12
};
Hogan.scan = function scan(text, delimiters) {
var len = text.length,
IN_TEXT = 0,
IN_TAG_TYPE = 1,
IN_TAG = 2,
state = IN_TEXT,
tagType = null,
tag = null,
buf = '',
tokens = [],
seenTag = false,
i = 0,
lineStart = 0,
otag = '{{',
ctag = '}}';
function addBuf() {
if (buf.length > 0) {
tokens.push({tag: '_t', text: new String(buf)});
buf = '';
}
}
function lineIsWhitespace() {
var isAllWhitespace = true;
for (var j = lineStart; j < tokens.length; j++) {
isAllWhitespace =
(Hogan.tags[tokens[j].tag] < Hogan.tags['_v']) ||
(tokens[j].tag == '_t' && tokens[j].text.match(rIsWhitespace) === null);
if (!isAllWhitespace) {
return false;
}
}
return isAllWhitespace;
}
function filterLine(haveSeenTag, noNewLine) {
addBuf();
if (haveSeenTag && lineIsWhitespace()) {
for (var j = lineStart, next; j < tokens.length; j++) {
if (tokens[j].text) {
if ((next = tokens[j+1]) && next.tag == '>') {
// set indent to token value
next.indent = tokens[j].text.toString();
}
tokens.splice(j, 1);
}
}
} else if (!noNewLine) {
tokens.push({tag:'\n'});
}
seenTag = false;
lineStart = tokens.length;
}
function changeDelimiters(text, index) {
var close = '=' + ctag,
closeIndex = text.indexOf(close, index),
delimiters = trim(
text.substring(text.indexOf('=', index) + 1, closeIndex)
).split(' ');
otag = delimiters[0];
ctag = delimiters[delimiters.length - 1];
return closeIndex + close.length - 1;
}
if (delimiters) {
delimiters = delimiters.split(' ');
otag = delimiters[0];
ctag = delimiters[1];
}
for (i = 0; i < len; i++) {
if (state == IN_TEXT) {
if (tagChange(otag, text, i)) {
--i;
addBuf();
state = IN_TAG_TYPE;
} else {
if (text.charAt(i) == '\n') {
filterLine(seenTag);
} else {
buf += text.charAt(i);
}
}
} else if (state == IN_TAG_TYPE) {
i += otag.length - 1;
tag = Hogan.tags[text.charAt(i + 1)];
tagType = tag ? text.charAt(i + 1) : '_v';
if (tagType == '=') {
i = changeDelimiters(text, i);
state = IN_TEXT;
} else {
if (tag) {
i++;
}
state = IN_TAG;
}
seenTag = i;
} else {
if (tagChange(ctag, text, i)) {
tokens.push({tag: tagType, n: trim(buf), otag: otag, ctag: ctag,
i: (tagType == '/') ? seenTag - otag.length : i + ctag.length});
buf = '';
i += ctag.length - 1;
state = IN_TEXT;
if (tagType == '{') {
if (ctag == '}}') {
i++;
} else {
cleanTripleStache(tokens[tokens.length - 1]);
}
}
} else {
buf += text.charAt(i);
}
}
}
filterLine(seenTag, true);
return tokens;
};
function cleanTripleStache(token) {
if (token.n.substr(token.n.length - 1) === '}') {
token.n = token.n.substring(0, token.n.length - 1);
}
}
function trim(s) {
if (s.trim) {
return s.trim();
}
return s.replace(/^\s*|\s*$/g, '');
}
function tagChange(tag, text, index) {
if (text.charAt(index) != tag.charAt(0)) {
return false;
}
for (var i = 1, l = tag.length; i < l; i++) {
if (text.charAt(index + i) != tag.charAt(i)) {
return false;
}
}
return true;
}
// the tags allowed inside super templates
var allowedInSuper = {'_t': true, '\n': true, '$': true, '/': true};
function buildTree(tokens, kind, stack, customTags) {
var instructions = [],
opener = null,
tail = null,
token = null;
tail = stack[stack.length - 1];
while (tokens.length > 0) {
token = tokens.shift();
if (tail && tail.tag == '<' && !(token.tag in allowedInSuper)) {
throw new Error('Illegal content in < super tag.');
}
if (Hogan.tags[token.tag] <= Hogan.tags['$'] || isOpener(token, customTags)) {
stack.push(token);
token.nodes = buildTree(tokens, token.tag, stack, customTags);
} else if (token.tag == '/') {
if (stack.length === 0) {
throw new Error('Closing tag without opener: /' + token.n);
}
opener = stack.pop();
if (token.n != opener.n && !isCloser(token.n, opener.n, customTags)) {
throw new Error('Nesting error: ' + opener.n + ' vs. ' + token.n);
}
opener.end = token.i;
return instructions;
} else if (token.tag == '\n') {
token.last = (tokens.length == 0) || (tokens[0].tag == '\n');
}
instructions.push(token);
}
if (stack.length > 0) {
throw new Error('missing closing tag: ' + stack.pop().n);
}
return instructions;
}
function isOpener(token, tags) {
for (var i = 0, l = tags.length; i < l; i++) {
if (tags[i].o == token.n) {
token.tag = '#';
return true;
}
}
}
function isCloser(close, open, tags) {
for (var i = 0, l = tags.length; i < l; i++) {
if (tags[i].c == close && tags[i].o == open) {
return true;
}
}
}
function stringifySubstitutions(obj) {
var items = [];
for (var key in obj) {
items.push('"' + esc(key) + '": function(c,p,t,i) {' + obj[key] + '}');
}
return "{ " + items.join(",") + " }";
}
function stringifyPartials(codeObj) {
var partials = [];
for (var key in codeObj.partials) {
partials.push('"' + esc(key) + '":{name:"' + esc(codeObj.partials[key].name) + '", ' + stringifyPartials(codeObj.partials[key]) + "}");
}
return "partials: {" + partials.join(",") + "}, subs: " + stringifySubstitutions(codeObj.subs);
}
Hogan.stringify = function(codeObj, text, options) {
return "{code: function (c,p,i) { " + Hogan.wrapMain(codeObj.code) + " }," + stringifyPartials(codeObj) + "}";
};
var serialNo = 0;
Hogan.generate = function(tree, text, options) {
serialNo = 0;
var context = { code: '', subs: {}, partials: {} };
Hogan.walk(tree, context);
if (options.asString) {
return this.stringify(context, text, options);
}
return this.makeTemplate(context, text, options);
};
Hogan.wrapMain = function(code) {
return 'var t=this;t.b(i=i||"");' + code + 'return t.fl();';
};
Hogan.template = Hogan.Template;
Hogan.makeTemplate = function(codeObj, text, options) {
var template = this.makePartials(codeObj);
template.code = new Function('c', 'p', 'i', this.wrapMain(codeObj.code));
return new this.template(template, text, this, options);
};
Hogan.makePartials = function(codeObj) {
var key, template = {subs: {}, partials: codeObj.partials, name: codeObj.name};
for (key in template.partials) {
template.partials[key] = this.makePartials(template.partials[key]);
}
for (key in codeObj.subs) {
template.subs[key] = new Function('c', 'p', 't', 'i', codeObj.subs[key]);
}
return template;
};
function esc(s) {
return s.replace(rSlash, '\\\\')
.replace(rQuot, '\\\"')
.replace(rNewline, '\\n')
.replace(rCr, '\\r')
.replace(rLineSep, '\\u2028')
.replace(rParagraphSep, '\\u2029');
}
function chooseMethod(s) {
return (~s.indexOf('.')) ? 'd' : 'f';
}
function createPartial(node, context) {
var prefix = "<" + (context.prefix || "");
var sym = prefix + node.n + serialNo++;
context.partials[sym] = {name: node.n, partials: {}};
context.code += 't.b(t.rp("' + esc(sym) + '",c,p,"' + (node.indent || '') + '"));';
return sym;
}
Hogan.codegen = {
'#': function(node, context) {
context.code += 'if(t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),' +
'c,p,0,' + node.i + ',' + node.end + ',"' + node.otag + " " + node.ctag + '")){' +
't.rs(c,p,' + 'function(c,p,t){';
Hogan.walk(node.nodes, context);
context.code += '});c.pop();}';
},
'^': function(node, context) {
context.code += 'if(!t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),c,p,1,0,0,"")){';
Hogan.walk(node.nodes, context);
context.code += '};';
},
'>': createPartial,
'<': function(node, context) {
var ctx = {partials: {}, code: '', subs: {}, inPartial: true};
Hogan.walk(node.nodes, ctx);
var template = context.partials[createPartial(node, context)];
template.subs = ctx.subs;
template.partials = ctx.partials;
},
'$': function(node, context) {
var ctx = {subs: {}, code: '', partials: context.partials, prefix: node.n};
Hogan.walk(node.nodes, ctx);
context.subs[node.n] = ctx.code;
if (!context.inPartial) {
context.code += 't.sub("' + esc(node.n) + '",c,p,i);';
}
},
'\n': function(node, context) {
context.code += write('"\\n"' + (node.last ? '' : ' + i'));
},
'_v': function(node, context) {
context.code += 't.b(t.v(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));';
},
'_t': function(node, context) {
context.code += write('"' + esc(node.text) + '"');
},
'{': tripleStache,
'&': tripleStache
};
function tripleStache(node, context) {
context.code += 't.b(t.t(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));';
}
function write(s) {
return 't.b(' + s + ');';
}
Hogan.walk = function(nodelist, context) {
var func;
for (var i = 0, l = nodelist.length; i < l; i++) {
func = Hogan.codegen[nodelist[i].tag];
func && func(nodelist[i], context);
}
return context;
};
Hogan.parse = function(tokens, text, options) {
options = options || {};
return buildTree(tokens, '', [], options.sectionTags || []);
};
Hogan.cache = {};
Hogan.cacheKey = function(text, options) {
return [text, !!options.asString, !!options.disableLambda, options.delimiters, !!options.modelGet].join('||');
};
Hogan.compile = function(text, options) {
options = options || {};
var key = Hogan.cacheKey(text, options);
var template = this.cache[key];
if (template) {
var partials = template.partials;
for (var name in partials) {
delete partials[name].instance;
}
return template;
}
template = this.generate(this.parse(this.scan(text, options.delimiters), text, options), text, options);
return this.cache[key] = template;
};
})(exports);
});
var template = createCommonjsModule(function (module, exports) {
(function (Hogan) {
Hogan.Template = function (codeObj, text, compiler, options) {
codeObj = codeObj || {};
this.r = codeObj.code || this.r;
this.c = compiler;
this.options = options || {};
this.text = text || '';
this.partials = codeObj.partials || {};
this.subs = codeObj.subs || {};
this.buf = '';
};
Hogan.Template.prototype = {
// render: replaced by generated code.
r: function (context, partials, indent) { return ''; },
// variable escaping
v: hoganEscape,
// triple stache
t: coerceToString,
render: function render(context, partials, indent) {
return this.ri([context], partials || {}, indent);
},
// render internal -- a hook for overrides that catches partials too
ri: function (context, partials, indent) {
return this.r(context, partials, indent);
},
// ensurePartial
ep: function(symbol, partials) {
var partial = this.partials[symbol];
// check to see that if we've instantiated this partial before
var template = partials[partial.name];
if (partial.instance && partial.base == template) {
return partial.instance;
}
if (typeof template == 'string') {
if (!this.c) {
throw new Error("No compiler available.");
}
template = this.c.compile(template, this.options);
}
if (!template) {
return null;
}
// We use this to check whether the partials dictionary has changed
this.partials[symbol].base = template;
if (partial.subs) {
// Make sure we consider parent template now
if (!partials.stackText) partials.stackText = {};
for (key in partial.subs) {
if (!partials.stackText[key]) {
partials.stackText[key] = (this.activeSub !== undefined && partials.stackText[this.activeSub]) ? partials.stackText[this.activeSub] : this.text;
}
}
template = createSpecializedPartial(template, partial.subs, partial.partials,
this.stackSubs, this.stackPartials, partials.stackText);
}
this.partials[symbol].instance = template;
return template;
},
// tries to find a partial in the current scope and render it
rp: function(symbol, context, partials, indent) {
var partial = this.ep(symbol, partials);
if (!partial) {
return '';
}
return partial.ri(context, partials, indent);
},
// render a section
rs: function(context, partials, section) {
var tail = context[context.length - 1];
if (!isArray(tail)) {
section(context, partials, this);
return;
}
for (var i = 0; i < tail.length; i++) {
context.push(tail[i]);
section(context, partials, this);
context.pop();
}
},
// maybe start a section
s: function(val, ctx, partials, inverted, start, end, tags) {
var pass;
if (isArray(val) && val.length === 0) {
return false;
}
if (typeof val == 'function') {
val = this.ms(val, ctx, partials, inverted, start, end, tags);
}
pass = !!val;
if (!inverted && pass && ctx) {
ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
}
return pass;
},
// find values with dotted names
d: function(key, ctx, partials, returnFound) {
var found,
names = key.split('.'),
val = this.f(names[0], ctx, partials, returnFound),
doModelGet = this.options.modelGet,
cx = null;
if (key === '.' && isArray(ctx[ctx.length - 2])) {
val = ctx[ctx.length - 1];
} else {
for (var i = 1; i < names.length; i++) {
found = findInScope(names[i], val, doModelGet);
if (found !== undefined) {
cx = val;
val = found;
} else {
val = '';
}
}
}
if (returnFound && !val) {
return false;
}
if (!returnFound && typeof val == 'function') {
ctx.push(cx);
val = this.mv(val, ctx, partials);
ctx.pop();
}
return val;
},
// find values with normal names
f: function(key, ctx, partials, returnFound) {
var val = false,
v = null,
found = false,
doModelGet = this.options.modelGet;
for (var i = ctx.length - 1; i >= 0; i--) {
v = ctx[i];
val = findInScope(key, v, doModelGet);
if (val !== undefined) {
found = true;
break;
}
}
if (!found) {
return (returnFound) ? false : "";
}
if (!returnFound && typeof val == 'function') {
val = this.mv(val, ctx, partials);
}
return val;
},
// higher order templates
ls: function(func, cx, partials, text, tags) {
var oldTags = this.options.delimiters;
this.options.delimiters = tags;
this.b(this.ct(coerceToString(func.call(cx, text)), cx, partials));
this.options.delimiters = oldTags;
return false;
},
// compile text
ct: function(text, cx, partials) {
if (this.options.disableLambda) {
throw new Error('Lambda features disabled.');
}
return this.c.compile(text, this.options).render(cx, partials);
},
// template result buffering
b: function(s) { this.buf += s; },
fl: function() { var r = this.buf; this.buf = ''; return r; },
// method replace section
ms: function(func, ctx, partials, inverted, start, end, tags) {
var textSource,
cx = ctx[ctx.length - 1],
result = func.call(cx);
if (typeof result == 'function') {
if (inverted) {
return true;
} else {
textSource = (this.activeSub && this.subsText && this.subsText[this.activeSub]) ? this.subsText[this.activeSub] : this.text;
return this.ls(result, cx, partials, textSource.substring(start, end), tags);
}
}
return result;
},
// method replace variable
mv: function(func, ctx, partials) {
var cx = ctx[ctx.length - 1];
var result = func.call(cx);
if (typeof result == 'function') {
return this.ct(coerceToString(result.call(cx)), cx, partials);
}
return result;
},
sub: function(name, context, partials, indent) {
var f = this.subs[name];
if (f) {
this.activeSub = name;
f(context, partials, this, indent);
this.activeSub = false;
}
}
};
//Find a key in an object
function findInScope(key, scope, doModelGet) {
var val;
if (scope && typeof scope == 'object') {
if (scope[key] !== undefined) {
val = scope[key];
// try lookup with get for backbone or similar model data
} else if (doModelGet && scope.get && typeof scope.get == 'function') {
val = scope.get(key);
}
}
return val;
}
function createSpecializedPartial(instance, subs, partials, stackSubs, stackPartials, stackText) {
function PartialTemplate() {} PartialTemplate.prototype = instance;
function Substitutions() {} Substitutions.prototype = instance.subs;
var key;
var partial = new PartialTemplate();
partial.subs = new Substitutions();
partial.subsText = {}; //hehe. substext.
partial.buf = '';
stackSubs = stackSubs || {};
partial.stackSubs = stackSubs;
partial.subsText = stackText;
for (key in subs) {
if (!stackSubs[key]) stackSubs[key] = subs[key];
}
for (key in stackSubs) {
partial.subs[key] = stackSubs[key];
}
stackPartials = stackPartials || {};
partial.stackPartials = stackPartials;
for (key in partials) {
if (!stackPartials[key]) stackPartials[key] = partials[key];
}
for (key in stackPartials) {
partial.partials[key] = stackPartials[key];
}
return partial;
}
var rAmp = /&/g,
rLt = //g,
rApos = /\'/g,
rQuot = /\"/g,
hChars = /[&<>\"\']/;
function coerceToString(val) {
return String((val === null || val === undefined) ? '' : val);
}
function hoganEscape(str) {
str = coerceToString(str);
return hChars.test(str) ?
str
.replace(rAmp, '&')
.replace(rLt, '<')
.replace(rGt, '>')
.replace(rApos, ''')
.replace(rQuot, '"') :
str;
}
var isArray = Array.isArray || function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
};
})(exports);
});
/*
* Copyright 2011 Twitter, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file is for use with Node.js. See dist/ for browser files.
compiler.Template = template.Template;
compiler.template = compiler.Template;
var hogan = compiler;
function capitalize(string) {
return string.toString().charAt(0).toUpperCase() + string.toString().slice(1);
}
/**
* Return the container. If it's a string, it is considered a
* css selector and retrieves the first matching element. Otherwise
* test if it validates that it's a correct DOMElement.
* @param {string|HTMLElement} selectorOrHTMLElement a selector or a node
* @return {HTMLElement} The resolved HTMLElement
* @throws Error when the type is not correct
*/
function getContainerNode(selectorOrHTMLElement) {
var isFromString = typeof selectorOrHTMLElement === 'string';
var domElement;
if (isFromString) {
domElement = document.querySelector(selectorOrHTMLElement);
} else {
domElement = selectorOrHTMLElement;
}
if (!isDomElement(domElement)) {
var errorMessage = 'Container must be `string` or `HTMLElement`.';
if (isFromString) {
errorMessage += " Unable to find ".concat(selectorOrHTMLElement);
}
throw new Error(errorMessage);
}
return domElement;
}
/**
* Returns true if the parameter is a DOMElement.
* @param {any} o the value to test
* @return {boolean} true if o is a DOMElement
*/
function isDomElement(o) {
return o instanceof window.HTMLElement || Boolean(o) && o.nodeType > 0;
}
function isSpecialClick(event) {
var isMiddleClick = event.button === 1;
return isMiddleClick || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
}
/**
* Prepares an object to be passed to the Template widget
* @param {object} unknownBecauseES6 an object with the following attributes:
* - defaultTemplate
* - templates
* - templatesConfig
* @return {object} the configuration with the attributes:
* - defaultTemplate
* - templates
* - useCustomCompileOptions
*/
function prepareTemplateProps(_ref) {
var defaultTemplates = _ref.defaultTemplates,
templates = _ref.templates,
templatesConfig = _ref.templatesConfig;
var preparedTemplates = prepareTemplates(defaultTemplates, templates);
return _objectSpread({
templatesConfig: templatesConfig
}, preparedTemplates);
}
function prepareTemplates() {
var defaultTemplates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var templates = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var allKeys = uniq_1([].concat(_toConsumableArray(keys_1(defaultTemplates)), _toConsumableArray(keys_1(templates))));
return reduce_1(allKeys, function (config, key) {
var defaultTemplate = defaultTemplates[key];
var customTemplate = templates[key];
var isCustomTemplate = customTemplate !== undefined && customTemplate !== defaultTemplate;
config.templates[key] = isCustomTemplate ? customTemplate : defaultTemplate;
config.useCustomCompileOptions[key] = isCustomTemplate;
return config;
}, {
templates: {},
useCustomCompileOptions: {}
});
}
function renderTemplate(_ref2) {
var templates = _ref2.templates,
templateKey = _ref2.templateKey,
compileOptions = _ref2.compileOptions,
helpers = _ref2.helpers,
data = _ref2.data;
var template = templates[templateKey];
var templateType = _typeof(template);
var isTemplateString = templateType === 'string';
var isTemplateFunction = templateType === 'function';
if (!isTemplateString && !isTemplateFunction) {
throw new Error("Template must be 'string' or 'function', was '".concat(templateType, "' (key: ").concat(templateKey, ")"));
}
if (isTemplateFunction) {
return template(data);
}
var transformedHelpers = transformHelpersToHogan(helpers, compileOptions, data);
return hogan.compile(template, compileOptions).render(_objectSpread({}, data, {
helpers: transformedHelpers
})).replace(/[ \n\r\t\f\xA0]+/g, function (spaces) {
return spaces.replace(/(^|\xA0+)[^\xA0]+/g, '$1 ');
}).trim();
} // We add all our template helper methods to the template as lambdas. Note
// that lambdas in Mustache are supposed to accept a second argument of
// `render` to get the rendered value, not the literal `{{value}}`. But
// this is currently broken (see https://github.com/twitter/hogan.js/issues/222).
function transformHelpersToHogan(helpers, compileOptions, data) {
return mapValues_1(helpers, function (method) {
return curry_1(function (text) {
var _this = this;
var render = function render(value) {
return hogan.compile(value, compileOptions).render(_this);
};
return method.call(data, text, render);
});
});
}
function getRefinement$1(state, type, attributeName, name, resultsFacets) {
var res = {
type: type,
attributeName: attributeName,
name: name
};
var facet = find_1(resultsFacets, {
name: attributeName
});
var count;
if (type === 'hierarchical') {
var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
var split = name.split(facetDeclaration.separator);
for (var i = 0; facet !== undefined && i < split.length; ++i) {
facet = find_1(facet.data, {
name: split[i]
});
}
count = get_1(facet, 'count');
} else {
count = get_1(facet, "data[\"".concat(res.name, "\"]"));
}
var exhaustive = get_1(facet, 'exhaustive');
if (count !== undefined) {
res.count = count;
}
if (exhaustive !== undefined) {
res.exhaustive = exhaustive;
}
return res;
}
function getRefinements(results, state, clearsQuery) {
var res = [];
forEach_1(state.facetsRefinements, function (refinements, attributeName) {
forEach_1(refinements, function (name) {
res.push(getRefinement$1(state, 'facet', attributeName, name, results.facets));
});
});
forEach_1(state.facetsExcludes, function (refinements, attributeName) {
forEach_1(refinements, function (name) {
res.push({
type: 'exclude',
attributeName: attributeName,
name: name,
exclude: true
});
});
});
forEach_1(state.disjunctiveFacetsRefinements, function (refinements, attributeName) {
forEach_1(refinements, function (name) {
res.push(getRefinement$1(state, 'disjunctive', attributeName, // we unescapeRefinement any disjunctive refined value since they can be escaped
// when negative numeric values search `escapeRefinement` usage in code
unescapeRefinement(name), results.disjunctiveFacets));
});
});
forEach_1(state.hierarchicalFacetsRefinements, function (refinements, attributeName) {
forEach_1(refinements, function (name) {
res.push(getRefinement$1(state, 'hierarchical', attributeName, name, results.hierarchicalFacets));
});
});
forEach_1(state.numericRefinements, function (operators, attributeName) {
forEach_1(operators, function (values, operator) {
forEach_1(values, function (value) {
res.push({
type: 'numeric',
attributeName: attributeName,
name: "".concat(value),
numericValue: value,
operator: operator
});
});
});
});
forEach_1(state.tagRefinements, function (name) {
res.push({
type: 'tag',
attributeName: '_tags',
name: name
});
});
if (clearsQuery && state.query && state.query.trim()) {
res.push({
attributeName: 'query',
type: 'query',
name: state.query,
query: state.query
});
}
return res;
}
/**
* Clears the refinements of a SearchParameters object based on rules provided.
* The included attributes list is applied before the excluded attributes list. If the list
* is not provided, this list of all the currently refined attributes is used as included attributes.
* @param {object} $0 parameters
* @param {Helper} $0.helper instance of the Helper
* @param {string[]} [$0.attributesToClear = []] list of parameters to clear
* @returns {SearchParameters} search parameters with refinements cleared
*/
function clearRefinements(_ref3) {
var helper = _ref3.helper,
_ref3$attributesToCle = _ref3.attributesToClear,
attributesToClear = _ref3$attributesToCle === void 0 ? [] : _ref3$attributesToCle;
var finalState = helper.state;
attributesToClear.forEach(function (attribute) {
if (attribute === '_tags') {
finalState = finalState.clearTags();
} else {
finalState = finalState.clearRefinements(attribute);
}
});
if (attributesToClear.indexOf('query') !== -1) {
finalState = finalState.setQuery('');
}
return finalState;
}
function escapeRefinement(value) {
if (typeof value === 'number' && value < 0) {
value = String(value).replace(/^-/, '\\-');
}
return value;
}
function unescapeRefinement(value) {
return String(value).replace(/^\\-/, '-');
}
function checkRendering(rendering, usage) {
if (rendering === undefined || typeof rendering !== 'function') {
throw new Error("The render function is not valid (got type \"".concat(_typeof(rendering), "\").\n\n").concat(usage));
}
}
var latLngRegExp = /^(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)$/;
function aroundLatLngToPosition(value) {
var pattern = value.match(latLngRegExp); // Since the value provided is the one send with the request, the API should
// throw an error due to the wrong format. So throw an error should be safe.
if (!pattern) {
throw new Error("Invalid value for \"aroundLatLng\" parameter: \"".concat(value, "\""));
}
return {
lat: parseFloat(pattern[1]),
lng: parseFloat(pattern[2])
};
}
function insideBoundingBoxArrayToBoundingBox(value) {
var _value = _slicedToArray(value, 1),
_value$ = _value[0];
_value$ = _value$ === void 0 ? [] : _value$;
var _value$2 = _slicedToArray(_value$, 4),
neLat = _value$2[0],
neLng = _value$2[1],
swLat = _value$2[2],
swLng = _value$2[3]; // Since the value provided is the one send with the request, the API should
// throw an error due to the wrong format. So throw an error should be safe.
if (!neLat || !neLng || !swLat || !swLng) {
throw new Error("Invalid value for \"insideBoundingBox\" parameter: [".concat(value, "]"));
}
return {
northEast: {
lat: neLat,
lng: neLng
},
southWest: {
lat: swLat,
lng: swLng
}
};
}
function insideBoundingBoxStringToBoundingBox(value) {
var _value$split$map = value.split(',').map(parseFloat),
_value$split$map2 = _slicedToArray(_value$split$map, 4),
neLat = _value$split$map2[0],
neLng = _value$split$map2[1],
swLat = _value$split$map2[2],
swLng = _value$split$map2[3]; // Since the value provided is the one send with the request, the API should
// throw an error due to the wrong format. So throw an error should be safe.
if (!neLat || !neLng || !swLat || !swLng) {
throw new Error("Invalid value for \"insideBoundingBox\" parameter: \"".concat(value, "\""));
}
return {
northEast: {
lat: neLat,
lng: neLng
},
southWest: {
lat: swLat,
lng: swLng
}
};
}
function insideBoundingBoxToBoundingBox(value) {
if (Array.isArray(value)) {
return insideBoundingBoxArrayToBoundingBox(value);
}
return insideBoundingBoxStringToBoundingBox(value);
}
function getPropertyByPath(object, path) {
var parts = path.split('.');
return parts.reduce(function (current, key) {
return current && current[key];
}, object);
}
/**
* Logs a warning if the condition is not met.
* This is used to log issues in development environment only.
*
* @return {undefined}
*/
var _warning = function warning() {};
{
var warn = function warn(message) {
// eslint-disable-next-line no-console
console.warn("[InstantSearch.js]: ".concat(message.trim()));
};
_warning = function warning(condition, message) {
if (condition) {
return;
}
var hasAlreadyPrinted = _warning.cache[message];
if (!hasAlreadyPrinted) {
_warning.cache[message] = true;
warn(message);
}
};
_warning.cache = {};
}
function createDocumentationLink() {
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
name = _ref4.name,
_ref4$connector = _ref4.connector,
connector = _ref4$connector === void 0 ? false : _ref4$connector;
return ['https://www.algolia.com/doc/api-reference/widgets/', name, '/js/', connector ? '#connector' : ''].join('');
}
function createDocumentationMessageGenerator() {
for (var _len = arguments.length, widgets = new Array(_len), _key = 0; _key < _len; _key++) {
widgets[_key] = arguments[_key];
}
var links = widgets.map(function (widget) {
return createDocumentationLink(widget);
}).join(', ');
return function (message) {
return [message, "See documentation: ".concat(links)].filter(Boolean).join('\n\n');
};
}
/**
* The base implementation of `_.propertyOf` without support for deep paths.
*
* @private
* @param {Object} object The object to query.
* @returns {Function} Returns the new accessor function.
*/
function basePropertyOf(object) {
return function(key) {
return object == null ? undefined : object[key];
};
}
var _basePropertyOf = basePropertyOf;
/** Used to map characters to HTML entities. */
var htmlEscapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
/**
* Used by `_.escape` to convert characters to HTML entities.
*
* @private
* @param {string} chr The matched character to escape.
* @returns {string} Returns the escaped character.
*/
var escapeHtmlChar = _basePropertyOf(htmlEscapes);
var _escapeHtmlChar = escapeHtmlChar;
/** Used to match HTML entities and HTML characters. */
var reUnescapedHtml = /[&<>"']/g,
reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
/**
* Converts the characters "&", "<", ">", '"', and "'" in `string` to their
* corresponding HTML entities.
*
* **Note:** No other characters are escaped. To escape additional
* characters use a third-party library like [_he_](https://mths.be/he).
*
* Though the ">" character is escaped for symmetry, characters like
* ">" and "/" don't need escaping in HTML and have no special meaning
* unless they're part of a tag or unquoted attribute value. See
* [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
* (under "semi-related fun fact") for more details.
*
* When working with HTML you should always
* [quote attribute values](http://wonko.com/post/html-escaping) to reduce
* XSS vectors.
*
* @static
* @since 0.1.0
* @memberOf _
* @category String
* @param {string} [string=''] The string to escape.
* @returns {string} Returns the escaped string.
* @example
*
* _.escape('fred, barney, & pebbles');
* // => 'fred, barney, & pebbles'
*/
function escape$1(string) {
string = toString_1(string);
return (string && reHasUnescapedHtml.test(string))
? string.replace(reUnescapedHtml, _escapeHtmlChar)
: string;
}
var _escape = escape$1;
var TAG_PLACEHOLDER = {
highlightPreTag: '__ais-highlight__',
highlightPostTag: '__/ais-highlight__'
};
var TAG_REPLACEMENT = {
highlightPreTag: '',
highlightPostTag: ' '
};
function replaceTagsAndEscape(value) {
return _escape(value).replace(new RegExp(TAG_PLACEHOLDER.highlightPreTag, 'g'), TAG_REPLACEMENT.highlightPreTag).replace(new RegExp(TAG_PLACEHOLDER.highlightPostTag, 'g'), TAG_REPLACEMENT.highlightPostTag);
}
function recursiveEscape(input) {
if (isPlainObject_1(input) && typeof input.value !== 'string') {
return reduce_1(input, function (acc, item, key) {
return _objectSpread({}, acc, _defineProperty({}, key, recursiveEscape(item)));
}, {});
}
if (isArray_1(input)) {
return input.map(recursiveEscape);
}
return _objectSpread({}, input, {
value: replaceTagsAndEscape(input.value)
});
}
function escapeHits(hits) {
if (hits.__escaped === undefined) {
hits = hits.map(function (hit) {
if (hit._highlightResult) {
hit._highlightResult = recursiveEscape(hit._highlightResult);
}
if (hit._snippetResult) {
hit._snippetResult = recursiveEscape(hit._snippetResult);
}
return hit;
});
hits.__escaped = true;
}
return hits;
}
function escapeFacets(facetHits) {
return facetHits.map(function (h) {
return _objectSpread({}, h, {
highlighted: replaceTagsAndEscape(h.highlighted)
});
});
}
var NAMESPACE = 'ais';
var component = function component(componentName) {
return function () {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
modifierName = _ref.modifierName,
descendantName = _ref.descendantName;
var d = descendantName ? "-".concat(descendantName) : '';
var m = modifierName ? "--".concat(modifierName) : '';
return "".concat(NAMESPACE, "-").concat(componentName).concat(d).concat(m);
};
};
var suit = component('Highlight');
function highlight() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
attribute = _ref.attribute,
_ref$highlightedTagNa = _ref.highlightedTagName,
highlightedTagName = _ref$highlightedTagNa === void 0 ? 'mark' : _ref$highlightedTagNa,
hit = _ref.hit;
var attributeValue = getPropertyByPath(hit, "_highlightResult.".concat(attribute, ".value")) || '';
var className = suit({
descendantName: 'highlighted'
});
return attributeValue.replace(new RegExp(TAG_REPLACEMENT.highlightPreTag, 'g'), "<".concat(highlightedTagName, " class=\"").concat(className, "\">")).replace(new RegExp(TAG_REPLACEMENT.highlightPostTag, 'g'), "".concat(highlightedTagName, ">"));
}
var suit$1 = component('Snippet');
function snippet() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
attribute = _ref.attribute,
_ref$highlightedTagNa = _ref.highlightedTagName,
highlightedTagName = _ref$highlightedTagNa === void 0 ? 'mark' : _ref$highlightedTagNa,
hit = _ref.hit;
var attributeValue = getPropertyByPath(hit, "_snippetResult.".concat(attribute, ".value")) || '';
var className = suit$1({
descendantName: 'highlighted'
});
return attributeValue.replace(new RegExp(TAG_REPLACEMENT.highlightPreTag, 'g'), "<".concat(highlightedTagName, " class=\"").concat(className, "\">")).replace(new RegExp(TAG_REPLACEMENT.highlightPostTag, 'g'), "".concat(highlightedTagName, ">"));
}
function createHelpers (_ref) {
var numberLocale = _ref.numberLocale;
return {
formatNumber: function formatNumber(number, render) {
return Number(render(number)).toLocaleString(numberLocale);
},
highlight: function highlight$$1(options, render) {
try {
var highlightOptions = JSON.parse(options);
return render(highlight(_objectSpread({}, highlightOptions, {
hit: this
})));
} catch (error) {
throw new Error("\nThe highlight helper expects a JSON object of the format:\n{ \"attribute\": \"name\", \"highlightedTagName\": \"mark\" }");
}
},
snippet: function snippet$$1(options, render) {
try {
var snippetOptions = JSON.parse(options);
return render(snippet(_objectSpread({}, snippetOptions, {
hit: this
})));
} catch (error) {
throw new Error("\nThe snippet helper expects a JSON object of the format:\n{ \"attribute\": \"name\", \"highlightedTagName\": \"mark\" }");
}
}
};
}
var ROUTING_DEFAULT_OPTIONS = {
stateMapping: simpleMapping(),
router: historyRouter()
};
function defaultCreateURL$1() {
return '#';
}
/**
* Widgets are the building blocks of InstantSearch.js. Any
* valid widget must have at least a `render` or a `init` function.
* @typedef {Object} Widget
* @property {function} [render] Called after each search response has been received
* @property {function} [getConfiguration] Let the widget update the configuration
* of the search with new parameters
* @property {function} [init] Called once before the first search
*/
/**
* The actual implementation of the InstantSearch. This is
* created using the `instantsearch` factory function.
* @fires Instantsearch#render This event is triggered each time a render is done
*/
var InstantSearch =
/*#__PURE__*/
function (_EventEmitter) {
_inherits(InstantSearch, _EventEmitter);
function InstantSearch(options) {
var _this;
_classCallCheck(this, InstantSearch);
_this = _possibleConstructorReturn(this, _getPrototypeOf(InstantSearch).call(this));
var _options$indexName = options.indexName,
indexName = _options$indexName === void 0 ? null : _options$indexName,
numberLocale = options.numberLocale,
_options$searchParame = options.searchParameters,
searchParameters = _options$searchParame === void 0 ? {} : _options$searchParame,
_options$routing = options.routing,
routing = _options$routing === void 0 ? null : _options$routing,
searchFunction = options.searchFunction,
_options$stalledSearc = options.stalledSearchDelay,
stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
_options$searchClient = options.searchClient,
searchClient = _options$searchClient === void 0 ? null : _options$searchClient;
if (indexName === null || searchClient === null) {
throw new Error("Usage: instantsearch({\n indexName: 'indexName',\n searchClient: algoliasearch('appId', 'apiKey')\n});");
}
if (typeof options.urlSync !== 'undefined') {
throw new Error('InstantSearch.js V3: `urlSync` option has been removed. You can now use the new `routing` option');
}
if (typeof searchClient.search !== 'function') {
throw new Error('The search client must implement a `search(requests)` method.');
}
if (typeof searchClient.addAlgoliaAgent === 'function') {
searchClient.addAlgoliaAgent("instantsearch.js ".concat(version$1));
}
_this.client = searchClient;
_this.helper = null;
_this.indexName = indexName;
_this.searchParameters = _objectSpread({}, searchParameters, {
index: indexName
});
_this.widgets = [];
_this.templatesConfig = {
helpers: createHelpers({
numberLocale: numberLocale
}),
compileOptions: {}
};
_this._stalledSearchDelay = stalledSearchDelay;
if (searchFunction) {
_this._searchFunction = searchFunction;
}
if (routing === true) _this.routing = ROUTING_DEFAULT_OPTIONS;else if (isPlainObject_1(routing)) _this.routing = _objectSpread({}, ROUTING_DEFAULT_OPTIONS, routing);
return _this;
}
/**
* Adds a widget. This can be done before and after InstantSearch has been started. Adding a
* widget after InstantSearch started is considered **EXPERIMENTAL** and therefore
* it is possibly buggy, if you find anything please
* [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20hot%20addWidget).
* @param {Widget} widget The widget to add to InstantSearch. Widgets are simple objects
* that have methods that map the search life cycle in a UI perspective. Usually widgets are
* created by [widget factories](widgets.html) like the one provided with InstantSearch.js.
* @return {undefined} This method does not return anything
*/
_createClass(InstantSearch, [{
key: "addWidget",
value: function addWidget(widget) {
this.addWidgets([widget]);
}
/**
* Adds multiple widgets. This can be done before and after the InstantSearch has been started. This feature
* is considered **EXPERIMENTAL** and therefore it is possibly buggy, if you find anything please
* [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20addWidgets).
* @param {Widget[]} widgets The array of widgets to add to InstantSearch.
* @return {undefined} This method does not return anything
*/
}, {
key: "addWidgets",
value: function addWidgets(widgets) {
var _this2 = this;
if (!Array.isArray(widgets)) {
throw new Error('You need to provide an array of widgets or call `addWidget()`');
} // The routing manager widget is always added manually at the last position.
// By removing it from the last position and adding it back after, we ensure
// it keeps this position.
// fixes #3148
var lastWidget = this.widgets.pop();
widgets.forEach(function (widget) {
// Add the widget to the list of widget
if (widget.render === undefined && widget.init === undefined) {
throw new Error('Widget definition missing render or init method');
}
_this2.widgets.push(widget);
}); // Second part of the fix for #3148
if (lastWidget) this.widgets.push(lastWidget); // Init the widget directly if instantsearch has been already started
if (this.started && Boolean(widgets.length)) {
this.searchParameters = this.widgets.reduce(enhanceConfiguration({}), _objectSpread({}, this.helper.state));
this.helper.setState(this.searchParameters);
widgets.forEach(function (widget) {
if (widget.init) {
widget.init({
state: _this2.helper.state,
helper: _this2.helper,
templatesConfig: _this2.templatesConfig,
createURL: _this2._createAbsoluteURL,
onHistoryChange: _this2._onHistoryChange,
instantSearchInstance: _this2
});
}
});
this.helper.search();
}
}
/**
* Removes a widget. This can be done after the InstantSearch has been started. This feature
* is considered **EXPERIMENTAL** and therefore it is possibly buggy, if you find anything please
* [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20removeWidget).
* @param {Widget} widget The widget instance to remove from InstantSearch. This widget must implement a `dispose()` method in order to be gracefully removed.
* @return {undefined} This method does not return anything
*/
}, {
key: "removeWidget",
value: function removeWidget(widget) {
this.removeWidgets([widget]);
}
/**
* Removes multiple widgets. This can be done only after the InstantSearch has been started. This feature
* is considered **EXPERIMENTAL** and therefore it is possibly buggy, if you find anything please
* [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20addWidgets).
* @param {Widget[]} widgets Array of widgets instances to remove from InstantSearch.
* @return {undefined} This method does not return anything
*/
}, {
key: "removeWidgets",
value: function removeWidgets(widgets) {
var _this3 = this;
if (!Array.isArray(widgets)) {
throw new Error('You need to provide an array of widgets or call `removeWidget()`');
}
widgets.forEach(function (widget) {
if (!_this3.widgets.includes(widget) || typeof widget.dispose !== 'function') {
throw new Error('The widget you tried to remove does not implement the dispose method, therefore it is not possible to remove this widget');
}
_this3.widgets = _this3.widgets.filter(function (w) {
return w !== widget;
});
var nextState = widget.dispose({
helper: _this3.helper,
state: _this3.helper.getState()
}); // re-compute remaining widgets to the state
// in a case two widgets were using the same configuration but we removed one
if (nextState) {
_this3.searchParameters = _this3.widgets.reduce(enhanceConfiguration({}), _objectSpread({}, nextState));
_this3.helper.setState(_this3.searchParameters);
}
}); // If there's multiple call to `removeWidget()` let's wait until they are all made
// and then check for widgets.length & make a search on next tick
//
// This solves an issue where you unmount a page and removing widget by widget
setTimeout(function () {
// no need to trigger a search if we don't have any widgets left
if (_this3.widgets.length > 0) {
_this3.helper.search();
}
}, 0);
}
/**
* Clears the cached answers from Algolia and triggers a new search.
*
* @return {undefined} Does not return anything
*/
}, {
key: "refresh",
value: function refresh() {
if (this.helper) {
this.helper.clearCache().search();
}
}
/**
* Ends the initialization of InstantSearch.js and triggers the
* first search. This method should be called after all widgets have been added
* to the instance of InstantSearch.js. InstantSearch.js also supports adding and removing
* widgets after the start as an **EXPERIMENTAL** feature.
*
* @return {undefined} Does not return anything
*/
}, {
key: "start",
value: function start() {
var _this4 = this;
if (this.started) throw new Error('start() has been already called once');
var searchParametersFromUrl;
if (this.routing) {
var routingManager = new RoutingManager(_objectSpread({}, this.routing, {
instantSearchInstance: this
}));
this._onHistoryChange = routingManager.onHistoryChange.bind(routingManager);
this._createURL = routingManager.createURL.bind(routingManager);
this._createAbsoluteURL = this._createURL;
this.widgets.push(routingManager);
} else {
this._createURL = defaultCreateURL$1;
this._createAbsoluteURL = defaultCreateURL$1;
this._onHistoryChange = function () {};
}
this.searchParameters = this.widgets.reduce(enhanceConfiguration(searchParametersFromUrl), this.searchParameters);
var helper = algoliasearchHelper_1(this.client, this.searchParameters.index || this.indexName, this.searchParameters);
if (this._searchFunction) {
this._mainHelperSearch = helper.search.bind(helper);
helper.search = function () {
var helperSearchFunction = algoliasearchHelper_1({
search: function search() {
return new Promise(function () {});
}
}, helper.state.index, helper.state);
helperSearchFunction.once('search', function (state) {
helper.overrideStateWithoutTriggeringChangeEvent(state);
_this4._mainHelperSearch();
});
_this4._searchFunction(helperSearchFunction);
};
}
this.helper = helper;
this._init(helper.state, this.helper);
this.helper.on('result', this._render.bind(this, this.helper));
this.helper.on('error', function (e) {
_this4.emit('error', e);
});
this._searchStalledTimer = null;
this._isSearchStalled = true;
this.helper.search();
this.helper.on('search', function () {
if (!_this4._isSearchStalled && !_this4._searchStalledTimer) {
_this4._searchStalledTimer = setTimeout(function () {
_this4._isSearchStalled = true;
_this4._render(_this4.helper, _this4.helper.lastResults, _this4.helper.lastResults._state);
}, _this4._stalledSearchDelay);
}
}); // track we started the search if we add more widgets,
// to init them directly after add
this.started = true;
}
/**
* Removes all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature,
* if you find an issue with it, please
* [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20dispose).
* @return {undefined} This method does not return anything
*/
}, {
key: "dispose",
value: function dispose() {
this.removeWidgets(this.widgets); // You can not start an instance two times, therefore a disposed instance needs to set started as false
// otherwise this can not be restarted at a later point.
this.started = false; // The helper needs to be reset to perform the next search from a fresh state.
// If not reset, it would use the state stored before calling `dispose()`.
this.helper.removeAllListeners();
this.helper = null;
}
}, {
key: "createURL",
value: function createURL(params) {
if (!this._createURL) {
throw new Error('You need to call start() before calling createURL()');
}
return this._createURL(this.helper.state.setQueryParameters(params));
}
}, {
key: "_render",
value: function _render(helper, results, state) {
var _this5 = this;
if (!this.helper.hasPendingRequests()) {
clearTimeout(this._searchStalledTimer);
this._searchStalledTimer = null;
this._isSearchStalled = false;
}
this.widgets.forEach(function (widget) {
if (!widget.render) {
return;
}
widget.render({
templatesConfig: _this5.templatesConfig,
results: results,
state: state,
helper: helper,
createURL: _this5._createAbsoluteURL,
instantSearchInstance: _this5,
searchMetadata: {
isSearchStalled: _this5._isSearchStalled
}
});
});
/**
* Render is triggered when the rendering of the widgets has been completed
* after a search.
* @event InstantSearch#render
*/
this.emit('render');
}
}, {
key: "_init",
value: function _init(state, helper) {
var _this6 = this;
this.widgets.forEach(function (widget) {
if (widget.init) {
widget.init({
state: state,
helper: helper,
templatesConfig: _this6.templatesConfig,
createURL: _this6._createAbsoluteURL,
onHistoryChange: _this6._onHistoryChange,
instantSearchInstance: _this6
});
}
});
}
}]);
return InstantSearch;
}(events);
function enhanceConfiguration(searchParametersFromUrl) {
return function (configuration, widgetDefinition) {
if (!widgetDefinition.getConfiguration) return configuration; // Get the relevant partial configuration asked by the widget
var partialConfiguration = widgetDefinition.getConfiguration(configuration, searchParametersFromUrl);
var customizer = function customizer(a, b) {
// always create a unified array for facets refinements
if (Array.isArray(a)) {
return union_1(a, b);
} // avoid mutating objects
if (isPlainObject_1(a)) {
return mergeWith_1({}, a, b, customizer);
}
return undefined;
};
return mergeWith_1({}, configuration, partialConfiguration, customizer);
};
}
var withUsage = createDocumentationMessageGenerator({
name: 'clear-refinements',
connector: true
});
/**
* @typedef {Object} CustomClearRefinementsWidgetOptions
* @property {string[]} [includedAttributes = []] The attributes to include in the refinements to clear (all by default). Cannot be used with `excludedAttributes`.
* @property {string[]} [excludedAttributes = ['query']] The attributes to exclude from the refinements to clear. Cannot be used with `includedAttributes`.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} ClearRefinementsRenderingOptions
* @property {function} refine Triggers the clear of all the currently refined values.
* @property {boolean} hasRefinements Indicates if search state is refined.
* @property {function} createURL Creates a url for the next state when refinements are cleared.
* @property {Object} widgetParams All original `CustomClearRefinementsWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **ClearRefinements** connector provides the logic to build a custom widget that will give the user
* the ability to reset the search state.
*
* This connector provides a `refine` function to remove the current refined facets.
*
* The behaviour of this function can be changed with widget options. If `clearsQuery`
* is set to `true`, `refine` will also clear the query and `excludedAttributes` can
* prevent certain attributes from being cleared.
*
* @type {Connector}
* @param {function(ClearRefinementsRenderingOptions, boolean)} renderFn Rendering function for the custom **ClearRefinements** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomClearRefinementsWidgetOptions)} Re-usable widget factory for a custom **ClearRefinements** widget.
* @example
* // custom `renderFn` to render the custom ClearRefinements widget
* function renderFn(ClearRefinementsRenderingOptions, isFirstRendering) {
* var containerNode = ClearRefinementsRenderingOptions.widgetParams.containerNode;
* if (isFirstRendering) {
* var markup = $('Clear All ');
* containerNode.append(markup);
*
* markup.on('click', function(event) {
* event.preventDefault();
* ClearRefinementsRenderingOptions.refine();
* })
* }
*
* var clearRefinementsCTA = containerNode.find('#custom-clear-all');
* clearRefinementsCTA.attr('disabled', !ClearRefinementsRenderingOptions.hasRefinements)
* };
*
* // connect `renderFn` to ClearRefinements logic
* var customClearRefinementsWidget = instantsearch.connectors.connectClearRefinements(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customClearRefinementsWidget({
* containerNode: $('#custom-clear-all-container'),
* })
* );
*/
function connectClearRefinements(renderFn, unmountFn) {
checkRendering(renderFn, withUsage());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (widgetParams.includedAttributes && widgetParams.excludedAttributes) {
throw new Error(withUsage('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
}
var _widgetParams$include = widgetParams.includedAttributes,
includedAttributes = _widgetParams$include === void 0 ? [] : _widgetParams$include,
_widgetParams$exclude = widgetParams.excludedAttributes,
excludedAttributes = _widgetParams$exclude === void 0 ? ['query'] : _widgetParams$exclude,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
return {
init: function init(_ref) {
var helper = _ref.helper,
instantSearchInstance = _ref.instantSearchInstance,
createURL = _ref.createURL;
var attributesToClear = getAttributesToClear({
helper: helper,
includedAttributes: includedAttributes,
excludedAttributes: excludedAttributes,
transformItems: transformItems
});
var hasRefinements = attributesToClear.length > 0;
this._refine = function () {
helper.setState(clearRefinements({
helper: helper,
attributesToClear: getAttributesToClear({
helper: helper,
includedAttributes: includedAttributes,
excludedAttributes: excludedAttributes,
transformItems: transformItems
})
})).search();
};
this._createURL = function () {
return createURL(clearRefinements({
helper: helper,
attributesToClear: getAttributesToClear({
helper: helper,
includedAttributes: includedAttributes,
excludedAttributes: excludedAttributes,
transformItems: transformItems
})
}));
};
renderFn({
hasRefinements: hasRefinements,
refine: this._refine,
createURL: this._createURL,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, true);
},
render: function render(_ref2) {
var helper = _ref2.helper,
instantSearchInstance = _ref2.instantSearchInstance;
var attributesToClear = getAttributesToClear({
helper: helper,
includedAttributes: includedAttributes,
excludedAttributes: excludedAttributes,
transformItems: transformItems
});
var hasRefinements = attributesToClear.length > 0;
renderFn({
hasRefinements: hasRefinements,
refine: this._refine,
createURL: this._createURL,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
function getAttributesToClear(_ref3) {
var helper = _ref3.helper,
includedAttributes = _ref3.includedAttributes,
excludedAttributes = _ref3.excludedAttributes,
transformItems = _ref3.transformItems;
var clearsQuery = includedAttributes.indexOf('query') !== -1 || excludedAttributes.indexOf('query') === -1;
return transformItems(getRefinements(helper.lastResults || {}, helper.state, clearsQuery).map(function (refinement) {
return refinement.attributeName;
}).filter(function (attribute) {
return (// If the array is empty (default case), we keep all the attributes
includedAttributes.length === 0 || // Otherwise, only add the specified attributes
includedAttributes.indexOf(attribute) !== -1
);
}).filter(function (attribute) {
return (// If the query is included, we ignore the default `excludedAttributes = ['query']`
attribute === 'query' && clearsQuery || // Otherwise, ignore the excluded attributes
excludedAttributes.indexOf(attribute) === -1
);
}));
}
var withUsage$1 = createDocumentationMessageGenerator({
name: 'current-refinements',
connector: true
});
/**
* @typedef {Object} Refinement
* @property {"facet"|"exclude"|"disjunctive"|"hierarchical"|"numeric"|"query"} type The type of the refinement
* @property {string} attribute The attribute on which the refinement is applied
* @property {string} label The label of the refinement to display
* @property {string} value The raw value of the refinement
* @property {string} [operator] The value of the operator, only if applicable
* @property {boolean} [exhaustive] Whether the count is exhaustive, only if applicable
* @property {number} [count] number of items found, if applicable
*/
/**
* @typedef {Object} RefinementItem
* @property {string} attribute The attribute on which the refinement is applied
* @property {function} refine The function to remove the refinement
* @property {Refinement[]} refinements The current refinements
*/
/**
* @typedef {Object} CurrentRefinementsRenderingOptions
* @property {function(item)} refine Clears a single refinement
* @property {function(item): string} createURL Creates an individual URL where a single refinement is cleared
* @property {RefinementItem[]} items All the refinement items
* @property {Object} widgetParams All original `CustomCurrentRefinementsWidgetOptions` forwarded to the `renderFn`.
*/
/**
* @typedef {Object} CustomCurrentRefinementsWidgetOptions
* @property {string[]} [includedAttributes] The attributes to include in the refinements (all by default). Cannot be used with `excludedAttributes`.
* @property {string[]} [excludedAttributes = ["query"]] The attributes to exclude from the refinements. Cannot be used with `includedAttributes`.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* **CurrentRefinements** connector provides the logic to build a widget that will give
* the user the ability to see all the currently applied filters and, remove some or all of
* them.
*
* This provides a `refine(item)` function to remove a selected refinement.
* Those functions can see their behaviour change based on the widget options used.
* @type {Connector}
* @param {function(CurrentRefinementsRenderingOptions)} renderFn Rendering function for the custom **CurrentRefinements** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomCurrentRefinementsWidgetOptions)} Re-usable widget factory for a custom **CurrentRefinements** widget.
* @example
* // custom `renderFn` to render the custom ClearRefinements widget
* function renderFn(currentRefinementsRenderingOptions, isFirstRendering) {
* var containerNode = currentRefinementsRenderingOptions.widgetParams.containerNode;
* if (isFirstRendering) {
* containerNode
* .html('
');
* }
*
* containerNode
* .find('#cta-container > a')
* .off('click');
*
* containerNode
* .find('li > a')
* .each(function() { $(this).off('click') });
*
* if (currentRefinementsRenderingOptions.items
* && currentRefinementsRenderingOptions.items.length > 0) {
* var list = currentRefinementsRenderingOptions.items.map(function(item) {
* return '' + item.attribute +
* ''
* ' ';
* });
*
* currentRefinementsRenderingOptions.find('ul').html(list);
* } else {
* containerNode.find('#cta-container').html('');
* containerNode.find('ul').html('');
* }
* }
*
* // connect `renderFn` to CurrentRefinements logic
* var customCurrentRefinements = instantsearch.connectors.connectCurrentRefinements(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customCurrentRefinements({
* containerNode: $('#custom-crv-container'),
* })
* );
*/
function connectCurrentRefinements(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$1());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (widgetParams.includedAttributes && widgetParams.excludedAttributes) {
throw new Error(withUsage$1('The options `includedAttributes` and `excludedAttributes` cannot be used together.'));
}
var includedAttributes = widgetParams.includedAttributes,
_widgetParams$exclude = widgetParams.excludedAttributes,
excludedAttributes = _widgetParams$exclude === void 0 ? ['query'] : _widgetParams$exclude,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
return {
init: function init(_ref) {
var helper = _ref.helper,
_createURL = _ref.createURL,
instantSearchInstance = _ref.instantSearchInstance;
var items = transformItems(getFilteredRefinements({
results: {},
state: helper.state,
helper: helper,
includedAttributes: includedAttributes,
excludedAttributes: excludedAttributes
}));
renderFn({
items: items,
refine: function refine(refinement) {
return clearRefinement(helper, refinement);
},
createURL: function createURL(refinement) {
return _createURL(clearRefinementFromState(helper.state, refinement));
},
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, true);
},
render: function render(_ref2) {
var results = _ref2.results,
helper = _ref2.helper,
state = _ref2.state,
_createURL2 = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance;
var items = transformItems(getFilteredRefinements({
results: results,
state: state,
helper: helper,
includedAttributes: includedAttributes,
excludedAttributes: excludedAttributes
}));
renderFn({
items: items,
refine: function refine(refinement) {
return clearRefinement(helper, refinement);
},
createURL: function createURL(refinement) {
return _createURL2(clearRefinementFromState(helper.state, refinement));
},
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
function getFilteredRefinements(_ref3) {
var results = _ref3.results,
state = _ref3.state,
helper = _ref3.helper,
includedAttributes = _ref3.includedAttributes,
excludedAttributes = _ref3.excludedAttributes;
var clearsQuery = (includedAttributes || []).indexOf('query') !== -1 || (excludedAttributes || []).indexOf('query') === -1;
var filterFunction = includedAttributes ? function (item) {
return includedAttributes.indexOf(item.attributeName) !== -1;
} : function (item) {
return excludedAttributes.indexOf(item.attributeName) === -1;
};
var items = getRefinements(results, state, clearsQuery).filter(filterFunction).map(normalizeRefinement);
return groupItemsByRefinements(items, helper);
}
function clearRefinementFromState(state, refinement) {
switch (refinement.type) {
case 'facet':
return state.removeFacetRefinement(refinement.attribute, refinement.value);
case 'disjunctive':
return state.removeDisjunctiveFacetRefinement(refinement.attribute, refinement.value);
case 'hierarchical':
return state.removeHierarchicalFacetRefinement(refinement.attribute);
case 'exclude':
return state.removeExcludeRefinement(refinement.attribute, refinement.value);
case 'numeric':
return state.removeNumericRefinement(refinement.attribute, refinement.operator, refinement.value);
case 'tag':
return state.removeTagRefinement(refinement.value);
case 'query':
return state.setQueryParameter('query', '');
default:
throw new Error("clearRefinement: type ".concat(refinement.type, " is not handled"));
}
}
function clearRefinement(helper, refinement) {
helper.setState(clearRefinementFromState(helper.state, refinement)).search();
}
function getOperatorSymbol(operator) {
switch (operator) {
case '>=':
return '≥';
case '<=':
return '≤';
default:
return operator;
}
}
function normalizeRefinement(refinement) {
var value = refinement.type === 'numeric' ? Number(refinement.name) : refinement.name;
var label = refinement.operator ? "".concat(getOperatorSymbol(refinement.operator), " ").concat(refinement.name) : refinement.name;
return _objectSpread({
attribute: refinement.attributeName,
type: refinement.type,
value: value,
label: label
}, refinement.operator !== undefined && {
operator: refinement.operator
}, refinement.count !== undefined && {
count: refinement.count
}, refinement.exhaustive !== undefined && {
exhaustive: refinement.exhaustive
});
}
function groupItemsByRefinements(items, helper) {
return items.reduce(function (results, currentItem) {
return [].concat(_toConsumableArray(results.filter(function (result) {
return result.attribute !== currentItem.attribute;
})), [{
attribute: currentItem.attribute,
label: currentItem.attribute,
refinements: items.filter(function (result) {
return result.attribute === currentItem.attribute;
}) // We want to keep the order of refinements except the numeric ones.
.sort(function (a, b) {
return a.type === 'numeric' ? a.value - b.value : 0;
}),
refine: function refine(refinement) {
return clearRefinement(helper, refinement);
}
}]);
}, []);
}
var withUsage$2 = createDocumentationMessageGenerator({
name: 'hierarchical-menu',
connector: true
});
/**
* @typedef {Object} HierarchicalMenuItem
* @property {string} value Value of the menu item.
* @property {string} label Human-readable value of the menu item.
* @property {number} count Number of matched results after refinement is applied.
* @property {isRefined} boolean Indicates if the refinement is applied.
* @property {Object} [data = undefined] n+1 level of items, same structure HierarchicalMenuItem (default: `undefined`).
*/
/**
* @typedef {Object} CustomHierarchicalMenuWidgetOptions
* @property {string[]} attributes Attributes to use to generate the hierarchy of the menu.
* @property {string} [separator = '>'] Separator used in the attributes to separate level values.
* @property {string} [rootPath = null] Prefix path to use if the first level is not the root level.
* @property {boolean} [showParentLevel=false] Show the siblings of the selected parent levels of the current refined value. This
* does not impact the root level.
* @property {number} [limit = 10] Max number of values to display.
* @property {boolean} [showMore = false] Whether to display the "show more" button.
* @property {number} [showMoreLimit = 20] Max number of values to display when showing more.
* @property {string[]|function} [sortBy = ['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} HierarchicalMenuRenderingOptions
* @property {function(item.value): string} createURL Creates an url for the next state for a clicked item.
* @property {HierarchicalMenuItem[]} items Values to be rendered.
* @property {function(item.value)} refine Sets the path of the hierarchical filter and triggers a new search.
* @property {Object} widgetParams All original `CustomHierarchicalMenuWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **HierarchicalMenu** connector provides the logic to build a custom widget
* that will give the user the ability to explore facets in a tree-like structure.
*
* This is commonly used for multi-level categorization of products on e-commerce
* websites. From a UX point of view, we suggest not displaying more than two
* levels deep.
*
* There's a complete example available on how to write a custom **HierarchicalMenu**:
* [hierarchicalMenu.js](https://github.com/algolia/instantsearch.js/blob/develop/storybook/app/jquery/widgets/hierarchicalMenu.js)
* @type {Connector}
* @param {function(HierarchicalMenuRenderingOptions)} renderFn Rendering function for the custom **HierarchicalMenu** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomHierarchicalMenuWidgetOptions)} Re-usable widget factory for a custom **HierarchicalMenu** widget.
*/
function connectHierarchicalMenu(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$2());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attributes = widgetParams.attributes,
_widgetParams$separat = widgetParams.separator,
separator = _widgetParams$separat === void 0 ? ' > ' : _widgetParams$separat,
_widgetParams$rootPat = widgetParams.rootPath,
rootPath = _widgetParams$rootPat === void 0 ? null : _widgetParams$rootPat,
_widgetParams$showPar = widgetParams.showParentLevel,
showParentLevel = _widgetParams$showPar === void 0 ? true : _widgetParams$showPar,
_widgetParams$limit = widgetParams.limit,
limit = _widgetParams$limit === void 0 ? 10 : _widgetParams$limit,
_widgetParams$showMor = widgetParams.showMore,
showMore = _widgetParams$showMor === void 0 ? false : _widgetParams$showMor,
_widgetParams$showMor2 = widgetParams.showMoreLimit,
showMoreLimit = _widgetParams$showMor2 === void 0 ? 20 : _widgetParams$showMor2,
_widgetParams$sortBy = widgetParams.sortBy,
sortBy = _widgetParams$sortBy === void 0 ? ['name:asc'] : _widgetParams$sortBy,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
throw new Error(withUsage$2('The `attributes` option expects an array of strings.'));
}
if (showMore === true && showMoreLimit <= limit) {
throw new Error(withUsage$2('The `showMoreLimit` option must be greater than `limit`.'));
} // we need to provide a hierarchicalFacet name for the search state
// so that we can always map $hierarchicalFacetName => real attributes
// we use the first attribute name
var _attributes = _slicedToArray(attributes, 1),
hierarchicalFacetName = _attributes[0];
return {
isShowingMore: false,
// Provide the same function to the `renderFn` so that way the user
// has to only bind it once when `isFirstRendering` for instance
toggleShowMore: function toggleShowMore() {},
cachedToggleShowMore: function cachedToggleShowMore() {
this.toggleShowMore();
},
createToggleShowMore: function createToggleShowMore(renderOptions) {
var _this = this;
return function () {
_this.isShowingMore = !_this.isShowingMore;
_this.render(renderOptions);
};
},
getLimit: function getLimit() {
return this.isShowingMore ? showMoreLimit : limit;
},
getConfiguration: function getConfiguration(currentConfiguration) {
if (currentConfiguration.hierarchicalFacets) {
var isFacetSet = find_1(currentConfiguration.hierarchicalFacets, function (_ref) {
var name = _ref.name;
return name === hierarchicalFacetName;
});
if (isFacetSet && !(isEqual_1(isFacetSet.attributes, attributes) && isFacetSet.separator === separator)) {
_warning(isEqual_1(isFacetSet.attributes, attributes) && isFacetSet.separator === separator, 'Using Breadcrumb and HierarchicalMenu on the same facet with different options overrides the configuration of the HierarchicalMenu.');
return {};
}
}
var widgetConfiguration = {
hierarchicalFacets: [{
name: hierarchicalFacetName,
attributes: attributes,
separator: separator,
rootPath: rootPath,
showParentLevel: showParentLevel
}]
};
var currentMaxValuesPerFacet = currentConfiguration.maxValuesPerFacet || 0;
widgetConfiguration.maxValuesPerFacet = Math.max(currentMaxValuesPerFacet, showMore ? showMoreLimit : limit);
return widgetConfiguration;
},
init: function init(_ref2) {
var helper = _ref2.helper,
createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance;
this.cachedToggleShowMore = this.cachedToggleShowMore.bind(this);
this._refine = function (facetValue) {
helper.toggleRefinement(hierarchicalFacetName, facetValue).search();
}; // Bind createURL to this specific attribute
function _createURL(facetValue) {
return createURL(helper.state.toggleRefinement(hierarchicalFacetName, facetValue));
}
renderFn({
items: [],
createURL: _createURL,
refine: this._refine,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams,
isShowingMore: false,
toggleShowMore: this.cachedToggleShowMore,
canToggleShowMore: false
}, true);
},
_prepareFacetValues: function _prepareFacetValues(facetValues, state) {
var _this2 = this;
return facetValues.slice(0, this.getLimit()).map(function (_ref3) {
var label = _ref3.name,
value = _ref3.path,
subValue = _objectWithoutProperties(_ref3, ["name", "path"]);
if (Array.isArray(subValue.data)) {
subValue.data = _this2._prepareFacetValues(subValue.data, state);
}
return _objectSpread({}, subValue, {
label: label,
value: value
});
});
},
render: function render(renderOptions) {
var results = renderOptions.results,
state = renderOptions.state,
createURL = renderOptions.createURL,
instantSearchInstance = renderOptions.instantSearchInstance;
var facetValues = results.getFacetValues(hierarchicalFacetName, {
sortBy: sortBy
}).data || [];
var items = transformItems(this._prepareFacetValues(facetValues), state); // Bind createURL to this specific attribute
function _createURL(facetValue) {
return createURL(state.toggleRefinement(hierarchicalFacetName, facetValue));
}
var maxValuesPerFacetConfig = state.getQueryParameter('maxValuesPerFacet');
var currentLimit = this.getLimit(); // If the limit is the max number of facet retrieved it is impossible to know
// if the facets are exhaustive. The only moment we are sure it is exhaustive
// is when it is strictly under the number requested unless we know that another
// widget has requested more values (maxValuesPerFacet > getLimit()).
// Because this is used for making the search of facets unable or not, it is important
// to be conservative here.
var hasExhaustiveItems = maxValuesPerFacetConfig > currentLimit ? facetValues.length <= currentLimit : facetValues.length < currentLimit;
this.toggleShowMore = this.createToggleShowMore(renderOptions);
renderFn({
items: items,
refine: this._refine,
createURL: _createURL,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams,
isShowingMore: this.isShowingMore,
toggleShowMore: this.cachedToggleShowMore,
canToggleShowMore: showMore && (this.isShowingMore || !hasExhaustiveItems)
}, false);
},
dispose: function dispose(_ref4) {
var state = _ref4.state;
// unmount widget from DOM
unmountFn(); // compute nextState for the search
var nextState = state;
if (state.isHierarchicalFacetRefined(hierarchicalFacetName)) {
nextState = state.removeHierarchicalFacetRefinement(hierarchicalFacetName);
}
nextState = nextState.removeHierarchicalFacet(hierarchicalFacetName);
if (nextState.maxValuesPerFacet === limit) {
nextState.setQueryParameters('maxValuesPerFacet', undefined);
}
return nextState;
},
getWidgetState: function getWidgetState(uiState, _ref5) {
var searchParameters = _ref5.searchParameters;
var path = searchParameters.getHierarchicalFacetBreadcrumb(hierarchicalFacetName);
if (!path || path.length === 0) return uiState;
if (uiState.hierarchicalMenu && isEqual_1(path, uiState.hierarchicalMenu[hierarchicalFacetName])) {
return uiState;
}
return _objectSpread({}, uiState, {
hierarchicalMenu: _objectSpread({}, uiState.hierarchicalMenu, _defineProperty({}, hierarchicalFacetName, path))
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
var uiState = _ref6.uiState;
if (uiState.hierarchicalMenu && uiState.hierarchicalMenu[hierarchicalFacetName]) {
return searchParameters.clearRefinements(hierarchicalFacetName).toggleRefinement(hierarchicalFacetName, uiState.hierarchicalMenu[hierarchicalFacetName].join(separator));
} else {
return searchParameters;
}
}
};
};
}
var withUsage$3 = createDocumentationMessageGenerator({
name: 'hits',
connector: true
});
/**
* @typedef {Object} HitsRenderingOptions
* @property {Object[]} hits The matched hits from Algolia API.
* @property {Object} results The complete results response from Algolia API.
* @property {Object} widgetParams All original widget options forwarded to the `renderFn`.
*/
/**
* @typedef {Object} CustomHitsWidgetOptions
* @property {boolean} [escapeHTML = true] Whether to escape HTML tags from `hits[i]._highlightResult`.
* @property {function(Object[]):Object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* **Hits** connector provides the logic to create custom widgets that will render the results retrieved from Algolia.
* @type {Connector}
* @param {function(HitsRenderingOptions, boolean)} renderFn Rendering function for the custom **Hits** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomHitsWidgetOptions)} Re-usable widget factory for a custom **Hits** widget.
* @example
* // custom `renderFn` to render the custom Hits widget
* function renderFn(HitsRenderingOptions) {
* HitsRenderingOptions.widgetParams.containerNode.html(
* HitsRenderingOptions.hits.map(function(hit) {
* return '' + hit._highlightResult.name.value + '
';
* })
* );
* }
*
* // connect `renderFn` to Hits logic
* var customHits = instantsearch.connectors.connectHits(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customHits({
* containerNode: $('#custom-hits-container'),
* })
* );
*/
function connectHits(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$3());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _widgetParams$escapeH = widgetParams.escapeHTML,
escapeHTML = _widgetParams$escapeH === void 0 ? true : _widgetParams$escapeH,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
return {
getConfiguration: function getConfiguration() {
return escapeHTML ? TAG_PLACEHOLDER : undefined;
},
init: function init(_ref) {
var instantSearchInstance = _ref.instantSearchInstance;
renderFn({
hits: [],
results: undefined,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, true);
},
render: function render(_ref2) {
var results = _ref2.results,
instantSearchInstance = _ref2.instantSearchInstance;
if (escapeHTML && results.hits && results.hits.length > 0) {
results.hits = escapeHits(results.hits);
}
results.hits = transformItems(results.hits);
renderFn({
hits: results.hits,
results: results,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
/**
* The base implementation of `_.some` without support for iteratee shorthands.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
*/
function baseSome(collection, predicate) {
var result;
_baseEach(collection, function(value, index, collection) {
result = predicate(value, index, collection);
return !result;
});
return !!result;
}
var _baseSome = baseSome;
/**
* Checks if `predicate` returns truthy for **any** element of `collection`.
* Iteration is stopped once `predicate` returns truthy. The predicate is
* invoked with three arguments: (value, index|key, collection).
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
* @example
*
* _.some([null, 0, 'yes', false], Boolean);
* // => true
*
* var users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false }
* ];
*
* // The `_.matches` iteratee shorthand.
* _.some(users, { 'user': 'barney', 'active': false });
* // => false
*
* // The `_.matchesProperty` iteratee shorthand.
* _.some(users, ['active', false]);
* // => true
*
* // The `_.property` iteratee shorthand.
* _.some(users, 'active');
* // => true
*/
function some(collection, predicate, guard) {
var func = isArray_1(collection) ? _arraySome : _baseSome;
if (guard && _isIterateeCall(collection, predicate, guard)) {
predicate = undefined;
}
return func(collection, _baseIteratee(predicate, 3));
}
var some_1 = some;
var withUsage$4 = createDocumentationMessageGenerator({
name: 'hits-per-page',
connector: true
});
/**
* @typedef {Object} HitsPerPageRenderingOptionsItem
* @property {number} value Number of hits to display per page.
* @property {string} label Label to display in the option.
* @property {boolean} isRefined Indicates if it's the current refined value.
*/
/**
* @typedef {Object} HitsPerPageWidgetOptionsItem
* @property {number} value Number of hits to display per page.
* @property {string} label Label to display in the option.
* @property {boolean} default The default hits per page on first search.
*/
/**
* @typedef {Object} HitsPerPageRenderingOptions
* @property {HitsPerPageRenderingOptionsItem[]} items Array of objects defining the different values and labels.
* @property {function(item.value)} createURL Creates the URL for a single item name in the list.
* @property {function(number)} refine Sets the number of hits per page and trigger a search.
* @property {boolean} hasNoResults `true` if the last search contains no result.
* @property {Object} widgetParams Original `HitsPerPageWidgetOptions` forwarded to `renderFn`.
*/
/**
* @typedef {Object} HitsPerPageWidgetOptions
* @property {HitsPerPageWidgetOptionsItem[]} items Array of objects defining the different values and labels.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* **HitsPerPage** connector provides the logic to create custom widget that will
* allow a user to choose to display more or less results from Algolia.
*
* This connector provides a `refine()` function to change the hits per page configuration and trigger a new search.
* @type {Connector}
* @param {function(HitsPerPageRenderingOptions, boolean)} renderFn Rendering function for the custom **HitsPerPage** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(HitsPerPageWidgetOptions)} Re-usable widget factory for a custom **HitsPerPage** widget.
* @example
* // custom `renderFn` to render the custom HitsPerPage widget
* function renderFn(HitsPerPageRenderingOptions, isFirstRendering) {
* var containerNode = HitsPerPageRenderingOptions.widgetParams.containerNode
* var items = HitsPerPageRenderingOptions.items
* var refine = HitsPerPageRenderingOptions.refine
*
* if (isFirstRendering) {
* var markup = ' ';
* containerNode.append(markup);
* }
*
* const itemsHTML = items.map(({value, label, isRefined}) => `
*
* ${label}
*
* `);
*
* containerNode
* .find('select')
* .html(itemsHTML);
*
* containerNode
* .find('select')
* .off('change')
* .on('change', e => { refine(e.target.value); });
* }
*
* // connect `renderFn` to HitsPerPage logic
* var customHitsPerPage = instantsearch.connectors.connectHitsPerPage(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customHitsPerPage({
* containerNode: $('#custom-hits-per-page-container'),
* items: [
* {value: 6, label: '6 per page', default: true},
* {value: 12, label: '12 per page'},
* {value: 24, label: '24 per page'},
* ],
* })
* );
*/
function connectHitsPerPage(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$4());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var userItems = widgetParams.items,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
var items = userItems;
if (!Array.isArray(items)) {
throw new Error(withUsage$4('The `items` option expects an array of objects.'));
}
var defaultValues = items.filter(function (item) {
return item.default;
});
if (defaultValues.length > 1) {
throw new Error(withUsage$4('More than one default value is specified in `items`.'));
}
var defaultValue = find_1(userItems, function (item) {
return item.default === true;
});
return {
getConfiguration: function getConfiguration() {
return defaultValues.length > 0 ? {
hitsPerPage: defaultValues[0].value
} : {};
},
init: function init(_ref) {
var helper = _ref.helper,
createURL = _ref.createURL,
state = _ref.state,
instantSearchInstance = _ref.instantSearchInstance;
var isCurrentInOptions = some_1(items, function (item) {
return Number(state.hitsPerPage) === Number(item.value);
});
if (!isCurrentInOptions) {
_warning(state.hitsPerPage !== undefined, "\n`hitsPerPage` is not defined.\nThe option `hitsPerPage` needs to be set using the `configure` widget.\n\nLearn more: https://community.algolia.com/instantsearch.js/v2/widgets/configure.html\n ");
_warning(false, "No items in HitsPerPage `items` with `value: hitsPerPage` (hitsPerPage: ".concat(state.hitsPerPage, ")"));
items = [{
value: '',
label: ''
}].concat(_toConsumableArray(items));
}
this.setHitsPerPage = function (value) {
return !value && value !== 0 ? helper.setQueryParameter('hitsPerPage', undefined).search() : helper.setQueryParameter('hitsPerPage', value).search();
};
this.createURL = function (helperState) {
return function (value) {
return createURL(helperState.setQueryParameter('hitsPerPage', !value && value !== 0 ? undefined : value));
};
};
renderFn({
items: transformItems(this._normalizeItems(state)),
refine: this.setHitsPerPage,
createURL: this.createURL(helper.state),
hasNoResults: true,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, true);
},
render: function render(_ref2) {
var state = _ref2.state,
results = _ref2.results,
instantSearchInstance = _ref2.instantSearchInstance;
var hasNoResults = results.nbHits === 0;
renderFn({
items: transformItems(this._normalizeItems(state)),
refine: this.setHitsPerPage,
createURL: this.createURL(state),
hasNoResults: hasNoResults,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, false);
},
_normalizeItems: function _normalizeItems(_ref3) {
var hitsPerPage = _ref3.hitsPerPage;
return items.map(function (item) {
return _objectSpread({}, item, {
isRefined: Number(item.value) === Number(hitsPerPage)
});
});
},
dispose: function dispose() {
unmountFn();
},
getWidgetState: function getWidgetState(uiState, _ref4) {
var searchParameters = _ref4.searchParameters;
var hitsPerPage = searchParameters.hitsPerPage;
if (defaultValue && hitsPerPage === defaultValue.value || hitsPerPage === undefined || uiState.hitsPerPage === hitsPerPage) {
return uiState;
}
return _objectSpread({}, uiState, {
hitsPerPage: hitsPerPage
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
var uiState = _ref5.uiState;
var hitsPerPage = uiState.hitsPerPage;
if (hitsPerPage) return searchParameters.setQueryParameter('hitsPerPage', uiState.hitsPerPage);
if (defaultValue) {
return searchParameters.setQueryParameter('hitsPerPage', defaultValue.value);
}
return searchParameters.setQueryParameter('hitsPerPage', undefined);
}
};
};
}
var withUsage$5 = createDocumentationMessageGenerator({
name: 'infinite-hits',
connector: true
});
/**
* @typedef {Object} InfiniteHitsRenderingOptions
* @property {Array} hits The aggregated matched hits from Algolia API of all pages.
* @property {Object} results The complete results response from Algolia API.
* @property {function} showMore Loads the next page of hits.
* @property {boolean} isLastPage Indicates if the last page of hits has been reached.
* @property {Object} widgetParams All original widget options forwarded to the `renderFn`.
*/
/**
* @typedef {Object} CustomInfiniteHitsWidgetOptions
* @property {boolean} [escapeHTML = true] Whether to escape HTML tags from `hits[i]._highlightResult`.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* **InfiniteHits** connector provides the logic to create custom widgets that will render an continuous list of results retrieved from Algolia.
*
* This connector provides a `InfiniteHitsRenderingOptions.showMore()` function to load next page of matched results.
* @type {Connector}
* @param {function(InfiniteHitsRenderingOptions, boolean)} renderFn Rendering function for the custom **InfiniteHits** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomInfiniteHitsWidgetOptions)} Re-usable widget factory for a custom **InfiniteHits** widget.
* @example
* // custom `renderFn` to render the custom InfiniteHits widget
* function renderFn(InfiniteHitsRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* InfiniteHitsRenderingOptions.widgetParams.containerNode
* .html('
Load more ');
*
* InfiniteHitsRenderingOptions.widgetParams.containerNode
* .find('#show-more')
* .on('click', function(event) {
* event.preventDefault();
* InfiniteHitsRenderingOptions.showMore();
* });
* }
*
* InfiniteHitsRenderingOptions.widgetParams.containerNode.find('#hits').html(
* InfiniteHitsRenderingOptions.hits.map(function(hit) {
* return '' + hit._highlightResult.name.value + '
';
* })
* );
* };
*
* // connect `renderFn` to InfiniteHits logic
* var customInfiniteHits = instantsearch.connectors.connectInfiniteHits(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customInfiniteHits({
* containerNode: $('#custom-infinite-hits-container'),
* })
* );
*/
function connectInfiniteHits(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$5());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _widgetParams$escapeH = widgetParams.escapeHTML,
escapeHTML = _widgetParams$escapeH === void 0 ? true : _widgetParams$escapeH,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
var hitsCache = [];
var lastReceivedPage = -1;
var getShowMore = function getShowMore(helper) {
return function () {
return helper.nextPage().search();
};
};
return {
getConfiguration: function getConfiguration() {
return escapeHTML ? TAG_PLACEHOLDER : undefined;
},
init: function init(_ref) {
var instantSearchInstance = _ref.instantSearchInstance,
helper = _ref.helper;
this.showMore = getShowMore(helper);
renderFn({
hits: hitsCache,
results: undefined,
showMore: this.showMore,
isLastPage: true,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, true);
},
render: function render(_ref2) {
var results = _ref2.results,
state = _ref2.state,
instantSearchInstance = _ref2.instantSearchInstance;
if (state.page === 0) {
hitsCache = [];
lastReceivedPage = -1;
}
if (escapeHTML && results.hits && results.hits.length > 0) {
results.hits = escapeHits(results.hits);
}
results.hits = transformItems(results.hits);
if (lastReceivedPage < state.page) {
hitsCache = [].concat(_toConsumableArray(hitsCache), _toConsumableArray(results.hits));
lastReceivedPage = state.page;
}
var isLastPage = results.nbPages <= results.page + 1;
renderFn({
hits: hitsCache,
results: results,
showMore: this.showMore,
isLastPage: isLastPage,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
var withUsage$6 = createDocumentationMessageGenerator({
name: 'menu',
connector: true
});
/**
* @typedef {Object} MenuItem
* @property {string} value The value of the menu item.
* @property {string} label Human-readable value of the menu item.
* @property {number} count Number of results matched after refinement is applied.
* @property {boolean} isRefined Indicates if the refinement is applied.
*/
/**
* @typedef {Object} CustomMenuWidgetOptions
* @property {string} attribute Name of the attribute for faceting (eg. "free_shipping").
* @property {number} [limit = 10] How many facets values to retrieve.
* @property {boolean} [showMore = false] Whether to display a button that expands the number of items.
* @property {number} [showMoreLimit = 20] How many facets values to retrieve when `toggleShowMore` is called, this value is meant to be greater than `limit` option.
* @property {string[]|function} [sortBy = ['isRefined', 'name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} MenuRenderingOptions
* @property {MenuItem[]} items The elements that can be refined for the current search results.
* @property {function(item.value): string} createURL Creates the URL for a single item name in the list.
* @property {function(item.value)} refine Filter the search to item value.
* @property {boolean} canRefine True if refinement can be applied.
* @property {Object} widgetParams All original `CustomMenuWidgetOptions` forwarded to the `renderFn`.
* @property {boolean} isShowingMore True if the menu is displaying all the menu items.
* @property {function} toggleShowMore Toggles the number of values displayed between `limit` and `showMore.limit`.
* @property {boolean} canToggleShowMore `true` if the toggleShowMore button can be activated (enough items to display more or
* already displaying more than `limit` items)
*/
/**
* **Menu** connector provides the logic to build a widget that will give the user the ability to choose a single value for a specific facet. The typical usage of menu is for navigation in categories.
*
* This connector provides a `toggleShowMore()` function to display more or less items and a `refine()`
* function to select an item. While selecting a new element, the `refine` will also unselect the
* one that is currently selected.
*
* **Requirement:** the attribute passed as `attribute` must be present in "attributes for faceting" on the Algolia dashboard or configured as attributesForFaceting via a set settings call to the Algolia API.
* @type {Connector}
* @param {function(MenuRenderingOptions, boolean)} renderFn Rendering function for the custom **Menu** widget. widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomMenuWidgetOptions)} Re-usable widget factory for a custom **Menu** widget.
* @example
* // custom `renderFn` to render the custom Menu widget
* function renderFn(MenuRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* MenuRenderingOptions.widgetParams.containerNode
* .html(' ' + item.label + ''
* : '' + item.label + ' ';
* });
*
* MenuRenderingOptions.widgetParams.containerNode
* .find('select')
* .html(options);
* }
*
* // connect `renderFn` to Menu logic
* var customMenu = instantsearch.connectors.connectMenu(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customMenu({
* containerNode: $('#custom-menu-container'),
* attribute: 'categories',
* limit: 10,
* })
* );
*/
function connectMenu(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$6());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attribute = widgetParams.attribute,
_widgetParams$limit = widgetParams.limit,
limit = _widgetParams$limit === void 0 ? 10 : _widgetParams$limit,
_widgetParams$showMor = widgetParams.showMore,
showMore = _widgetParams$showMor === void 0 ? false : _widgetParams$showMor,
_widgetParams$showMor2 = widgetParams.showMoreLimit,
showMoreLimit = _widgetParams$showMor2 === void 0 ? 20 : _widgetParams$showMor2,
_widgetParams$sortBy = widgetParams.sortBy,
sortBy = _widgetParams$sortBy === void 0 ? ['isRefined', 'name:asc'] : _widgetParams$sortBy,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
if (!attribute) {
throw new Error(withUsage$6('The `attribute` option is required.'));
}
if (showMore === true && showMoreLimit <= limit) {
throw new Error(withUsage$6('The `showMoreLimit` option must be greater than `limit`.'));
}
return {
isShowingMore: false,
// Provide the same function to the `renderFn` so that way the user
// has to only bind it once when `isFirstRendering` for instance
toggleShowMore: function toggleShowMore() {},
cachedToggleShowMore: function cachedToggleShowMore() {
this.toggleShowMore();
},
createToggleShowMore: function createToggleShowMore(_ref) {
var _this = this;
var results = _ref.results,
instantSearchInstance = _ref.instantSearchInstance;
return function () {
_this.isShowingMore = !_this.isShowingMore;
_this.render({
results: results,
instantSearchInstance: instantSearchInstance
});
};
},
getLimit: function getLimit() {
return this.isShowingMore ? showMoreLimit : limit;
},
refine: function refine(helper) {
return function (facetValue) {
var _helper$getHierarchic = helper.getHierarchicalFacetBreadcrumb(attribute),
_helper$getHierarchic2 = _slicedToArray(_helper$getHierarchic, 1),
refinedItem = _helper$getHierarchic2[0];
helper.toggleRefinement(attribute, facetValue ? facetValue : refinedItem).search();
};
},
getConfiguration: function getConfiguration(configuration) {
var widgetConfiguration = {
hierarchicalFacets: [{
name: attribute,
attributes: [attribute]
}]
};
var currentMaxValuesPerFacet = configuration.maxValuesPerFacet || 0;
widgetConfiguration.maxValuesPerFacet = Math.max(currentMaxValuesPerFacet, showMore ? showMoreLimit : limit);
return widgetConfiguration;
},
init: function init(_ref2) {
var helper = _ref2.helper,
createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance;
this.cachedToggleShowMore = this.cachedToggleShowMore.bind(this);
this._createURL = function (facetValue) {
return createURL(helper.state.toggleRefinement(attribute, facetValue));
};
this._refine = this.refine(helper);
renderFn({
items: [],
createURL: this._createURL,
refine: this._refine,
instantSearchInstance: instantSearchInstance,
canRefine: false,
widgetParams: widgetParams,
isShowingMore: this.isShowingMore,
toggleShowMore: this.cachedToggleShowMore,
canToggleShowMore: false
}, true);
},
render: function render(_ref3) {
var results = _ref3.results,
instantSearchInstance = _ref3.instantSearchInstance;
var facetItems = results.getFacetValues(attribute, {
sortBy: sortBy
}).data || [];
var items = transformItems(facetItems.slice(0, this.getLimit()).map(function (_ref4) {
var label = _ref4.name,
value = _ref4.path,
item = _objectWithoutProperties(_ref4, ["name", "path"]);
return _objectSpread({}, item, {
label: label,
value: value
});
}));
this.toggleShowMore = this.createToggleShowMore({
results: results,
instantSearchInstance: instantSearchInstance
});
renderFn({
items: items,
createURL: this._createURL,
refine: this._refine,
instantSearchInstance: instantSearchInstance,
canRefine: items.length > 0,
widgetParams: widgetParams,
isShowingMore: this.isShowingMore,
toggleShowMore: this.cachedToggleShowMore,
canToggleShowMore: showMore && (this.isShowingMore || facetItems.length > this.getLimit())
}, false);
},
dispose: function dispose(_ref5) {
var state = _ref5.state;
unmountFn();
var nextState = state;
if (state.isHierarchicalFacetRefined(attribute)) {
nextState = state.removeHierarchicalFacetRefinement(attribute);
}
nextState = nextState.removeHierarchicalFacet(attribute);
if (nextState.maxValuesPerFacet === limit || showMoreLimit && nextState.maxValuesPerFacet === showMoreLimit) {
nextState.setQueryParameters('maxValuesPerFacet', undefined);
}
return nextState;
},
getWidgetState: function getWidgetState(uiState, _ref6) {
var searchParameters = _ref6.searchParameters;
var _searchParameters$get = searchParameters.getHierarchicalFacetBreadcrumb(attribute),
_searchParameters$get2 = _slicedToArray(_searchParameters$get, 1),
refinedItem = _searchParameters$get2[0];
if (!refinedItem || uiState.menu && uiState.menu[attribute] === refinedItem) {
return uiState;
}
return _objectSpread({}, uiState, {
menu: _objectSpread({}, uiState.menu, _defineProperty({}, attribute, refinedItem))
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
var uiState = _ref7.uiState;
if (uiState.menu && uiState.menu[attribute]) {
var uiStateRefinedItem = uiState.menu[attribute];
var isAlreadyRefined = searchParameters.isHierarchicalFacetRefined(attribute, uiStateRefinedItem);
if (isAlreadyRefined) return searchParameters;
return searchParameters.toggleRefinement(attribute, uiStateRefinedItem);
}
if (searchParameters.isHierarchicalFacetRefined(attribute)) {
var _searchParameters$get3 = searchParameters.getHierarchicalFacetBreadcrumb(attribute),
_searchParameters$get4 = _slicedToArray(_searchParameters$get3, 1),
refinedItem = _searchParameters$get4[0];
return searchParameters.toggleRefinement(attribute, refinedItem);
}
return searchParameters;
}
};
};
}
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeIsFinite = _root.isFinite;
/**
* Checks if `value` is a finite primitive number.
*
* **Note:** This method is based on
* [`Number.isFinite`](https://mdn.io/Number/isFinite).
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
* @example
*
* _.isFinite(3);
* // => true
*
* _.isFinite(Number.MIN_VALUE);
* // => true
*
* _.isFinite(Infinity);
* // => false
*
* _.isFinite('3');
* // => false
*/
function isFinite(value) {
return typeof value == 'number' && nativeIsFinite(value);
}
var _isFinite = isFinite;
var withUsage$7 = createDocumentationMessageGenerator({
name: 'numeric-menu',
connector: true
});
/**
* @typedef {Object} NumericMenuOption
* @property {string} name Name of the option.
* @property {number} start Lower bound of the option (>=).
* @property {number} end Higher bound of the option (<=).
*/
/**
* @typedef {Object} NumericMenuItem
* @property {string} label Name of the option.
* @property {string} value URL encoded of the bounds object with the form `{start, end}`. This value can be used verbatim in the webpage and can be read by `refine` directly. If you want to inspect the value, you can do `JSON.parse(window.decodeURI(value))` to get the object.
* @property {boolean} isRefined True if the value is selected.
*/
/**
* @typedef {Object} CustomNumericMenuWidgetOptions
* @property {string} attribute Name of the attribute for filtering.
* @property {NumericMenuOption[]} items List of all the items.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} NumericMenuRenderingOptions
* @property {function(item.value): string} createURL Creates URLs for the next state, the string is the name of the selected option.
* @property {NumericMenuItem[]} items The list of available choices.
* @property {boolean} hasNoResults `true` if the last search contains no result.
* @property {function(item.value)} refine Sets the selected value and trigger a new search.
* @property {Object} widgetParams All original `CustomNumericMenuWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **NumericMenu** connector provides the logic to build a custom widget that will give the user the ability to choose a range on to refine the search results.
*
* It provides a `refine(item)` function to refine on the selected range.
*
* **Requirement:** the attribute passed as `attribute` must be present in "attributes for faceting" on the Algolia dashboard or configured as attributesForFaceting via a set settings call to the Algolia API.
* @function connectNumericMenu
* @type {Connector}
* @param {function(NumericMenuRenderingOptions, boolean)} renderFn Rendering function for the custom **NumericMenu** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomNumericMenuWidgetOptions)} Re-usable widget factory for a custom **NumericMenu** widget.
* @example
* // custom `renderFn` to render the custom NumericMenu widget
* function renderFn(NumericMenuRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* NumericMenuRenderingOptions.widgetParams.containerNode.html('');
* }
*
* NumericMenuRenderingOptions.widgetParams.containerNode
* .find('li[data-refine-value]')
* .each(function() { $(this).off('click'); });
*
* var list = NumericMenuRenderingOptions.items.map(function(item) {
* return '' +
* ' ' +
* item.label + ' ';
* });
*
* NumericMenuRenderingOptions.widgetParams.containerNode.find('ul').html(list);
* NumericMenuRenderingOptions.widgetParams.containerNode
* .find('li[data-refine-value]')
* .each(function() {
* $(this).on('click', function(event) {
* event.preventDefault();
* event.stopPropagation();
* NumericMenuRenderingOptions.refine($(this).data('refine-value'));
* });
* });
* }
*
* // connect `renderFn` to NumericMenu logic
* var customNumericMenu = instantsearch.connectors.connectNumericMenu(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customNumericMenu({
* containerNode: $('#custom-numeric-menu-container'),
* attribute: 'price',
* items: [
* {name: 'All'},
* {end: 4, name: 'less than 4'},
* {start: 4, end: 4, name: '4'},
* {start: 5, end: 10, name: 'between 5 and 10'},
* {start: 10, name: 'more than 10'},
* ],
* })
* );
*/
function connectNumericMenu(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$7());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attribute = widgetParams.attribute,
items = widgetParams.items,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (x) {
return x;
} : _widgetParams$transfo;
if (!attribute) {
throw new Error(withUsage$7('The `attribute` option is required.'));
}
if (!items) {
throw new Error(withUsage$7('The `items` option expects an array of objects.'));
}
return {
init: function init(_ref) {
var helper = _ref.helper,
createURL = _ref.createURL,
instantSearchInstance = _ref.instantSearchInstance;
this._refine = function (facetValue) {
var refinedState = refine(helper.state, attribute, items, facetValue);
helper.setState(refinedState).search();
};
this._createURL = function (state) {
return function (facetValue) {
return createURL(refine(state, attribute, items, facetValue));
};
};
this._prepareItems = function (state) {
return items.map(function (_ref2) {
var start = _ref2.start,
end = _ref2.end,
label = _ref2.label;
return {
label: label,
value: window.encodeURI(JSON.stringify({
start: start,
end: end
})),
isRefined: isRefined(state, attribute, {
start: start,
end: end
})
};
});
};
renderFn({
createURL: this._createURL(helper.state),
items: transformItems(this._prepareItems(helper.state)),
hasNoResults: true,
refine: this._refine,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, true);
},
render: function render(_ref3) {
var results = _ref3.results,
state = _ref3.state,
instantSearchInstance = _ref3.instantSearchInstance;
renderFn({
createURL: this._createURL(state),
items: transformItems(this._prepareItems(state)),
hasNoResults: results.nbHits === 0,
refine: this._refine,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, false);
},
dispose: function dispose(_ref4) {
var state = _ref4.state;
unmountFn();
return state.clearRefinements(attribute);
},
getWidgetState: function getWidgetState(uiState, _ref5) {
var searchParameters = _ref5.searchParameters;
var currentRefinements = searchParameters.getNumericRefinements(attribute);
var equal = currentRefinements['='] && currentRefinements['='][0];
if (equal || equal === 0) {
return _objectSpread({}, uiState, {
numericMenu: _objectSpread({}, uiState.numericMenu, _defineProperty({}, attribute, "".concat(currentRefinements['='])))
});
}
var lowerBound = currentRefinements['>='] && currentRefinements['>='][0] || '';
var upperBound = currentRefinements['<='] && currentRefinements['<='][0] || '';
if (lowerBound !== '' || upperBound !== '') {
if (uiState.numericMenu && uiState.numericMenu[attribute] === "".concat(lowerBound, ":").concat(upperBound)) return uiState;
return _objectSpread({}, uiState, {
numericMenu: _objectSpread({}, uiState.numericMenu, _defineProperty({}, attribute, "".concat(lowerBound, ":").concat(upperBound)))
});
}
return uiState;
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
var uiState = _ref6.uiState;
var clearedParams = searchParameters.clearRefinements(attribute);
var value = uiState.numericMenu && uiState.numericMenu[attribute];
if (!value) {
return clearedParams;
}
var valueAsEqual = value.indexOf(':') === -1 && value;
if (valueAsEqual) {
return clearedParams.addNumericRefinement(attribute, '=', valueAsEqual);
}
var _value$split$map = value.split(':').map(parseFloat),
_value$split$map2 = _slicedToArray(_value$split$map, 2),
lowerBound = _value$split$map2[0],
upperBound = _value$split$map2[1];
if (_isFinite(lowerBound)) {
clearedParams = clearedParams.addNumericRefinement(attribute, '>=', lowerBound);
}
if (_isFinite(upperBound)) {
clearedParams = clearedParams.addNumericRefinement(attribute, '<=', upperBound);
}
return clearedParams;
}
};
};
}
function isRefined(state, attribute, option) {
var currentRefinements = state.getNumericRefinements(attribute);
if (option.start !== undefined && option.end !== undefined) {
if (option.start === option.end) {
return hasNumericRefinement(currentRefinements, '=', option.start);
}
}
if (option.start !== undefined) {
return hasNumericRefinement(currentRefinements, '>=', option.start);
}
if (option.end !== undefined) {
return hasNumericRefinement(currentRefinements, '<=', option.end);
}
if (option.start === undefined && option.end === undefined) {
return Object.keys(currentRefinements).length === 0;
}
return undefined;
}
function refine(state, attribute, items, facetValue) {
var resolvedState = state;
var refinedOption = JSON.parse(window.decodeURI(facetValue));
var currentRefinements = resolvedState.getNumericRefinements(attribute);
if (refinedOption.start === undefined && refinedOption.end === undefined) {
return resolvedState.clearRefinements(attribute);
}
if (!isRefined(resolvedState, attribute, refinedOption)) {
resolvedState = resolvedState.clearRefinements(attribute);
}
if (refinedOption.start !== undefined && refinedOption.end !== undefined) {
if (refinedOption.start > refinedOption.end) {
throw new Error('option.start should be > to option.end');
}
if (refinedOption.start === refinedOption.end) {
if (hasNumericRefinement(currentRefinements, '=', refinedOption.start)) {
resolvedState = resolvedState.removeNumericRefinement(attribute, '=', refinedOption.start);
} else {
resolvedState = resolvedState.addNumericRefinement(attribute, '=', refinedOption.start);
}
return resolvedState;
}
}
if (refinedOption.start !== undefined) {
if (hasNumericRefinement(currentRefinements, '>=', refinedOption.start)) {
resolvedState = resolvedState.removeNumericRefinement(attribute, '>=', refinedOption.start);
} else {
resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
}
}
if (refinedOption.end !== undefined) {
if (hasNumericRefinement(currentRefinements, '<=', refinedOption.end)) {
resolvedState = resolvedState.removeNumericRefinement(attribute, '<=', refinedOption.end);
} else {
resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
}
}
resolvedState.page = 0;
return resolvedState;
}
function hasNumericRefinement(currentRefinements, operator, value) {
var hasOperatorRefinements = currentRefinements[operator] !== undefined;
return hasOperatorRefinements && currentRefinements[operator].includes(value);
}
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeCeil = Math.ceil,
nativeMax$7 = Math.max;
/**
* The base implementation of `_.range` and `_.rangeRight` which doesn't
* coerce arguments.
*
* @private
* @param {number} start The start of the range.
* @param {number} end The end of the range.
* @param {number} step The value to increment or decrement by.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Array} Returns the range of numbers.
*/
function baseRange(start, end, step, fromRight) {
var index = -1,
length = nativeMax$7(nativeCeil((end - start) / (step || 1)), 0),
result = Array(length);
while (length--) {
result[fromRight ? length : ++index] = start;
start += step;
}
return result;
}
var _baseRange = baseRange;
/**
* Creates a `_.range` or `_.rangeRight` function.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new range function.
*/
function createRange(fromRight) {
return function(start, end, step) {
if (step && typeof step != 'number' && _isIterateeCall(start, end, step)) {
end = step = undefined;
}
// Ensure the sign of `-0` is preserved.
start = toFinite_1(start);
if (end === undefined) {
end = start;
start = 0;
} else {
end = toFinite_1(end);
}
step = step === undefined ? (start < end ? 1 : -1) : toFinite_1(step);
return _baseRange(start, end, step, fromRight);
};
}
var _createRange = createRange;
/**
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to, but not including, `end`. A step of `-1` is used if a negative
* `start` is specified without an `end` or `step`. If `end` is not specified,
* it's set to `start` with `start` then set to `0`.
*
* **Note:** JavaScript follows the IEEE-754 standard for resolving
* floating-point values which can produce unexpected results.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Util
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @param {number} [step=1] The value to increment or decrement by.
* @returns {Array} Returns the range of numbers.
* @see _.inRange, _.rangeRight
* @example
*
* _.range(4);
* // => [0, 1, 2, 3]
*
* _.range(-4);
* // => [0, -1, -2, -3]
*
* _.range(1, 5);
* // => [1, 2, 3, 4]
*
* _.range(0, 20, 5);
* // => [0, 5, 10, 15]
*
* _.range(0, -4, -1);
* // => [0, -1, -2, -3]
*
* _.range(1, 4, 0);
* // => [1, 1, 1]
*
* _.range(0);
* // => []
*/
var range = _createRange();
var range_1 = range;
var Paginator =
/*#__PURE__*/
function () {
function Paginator(params) {
_classCallCheck(this, Paginator);
this.currentPage = params.currentPage;
this.total = params.total;
this.padding = params.padding;
}
_createClass(Paginator, [{
key: "pages",
value: function pages() {
var total = this.total,
currentPage = this.currentPage,
padding = this.padding;
if (total === 0) return [0];
var totalDisplayedPages = this.nbPagesDisplayed(padding, total);
if (totalDisplayedPages === total) return range_1(0, total);
var paddingLeft = this.calculatePaddingLeft(currentPage, padding, total, totalDisplayedPages);
var paddingRight = totalDisplayedPages - paddingLeft;
var first = currentPage - paddingLeft;
var last = currentPage + paddingRight;
return range_1(first, last);
}
}, {
key: "nbPagesDisplayed",
value: function nbPagesDisplayed(padding, total) {
return Math.min(2 * padding + 1, total);
}
}, {
key: "calculatePaddingLeft",
value: function calculatePaddingLeft(current, padding, total, totalDisplayedPages) {
if (current <= padding) {
return current;
}
if (current >= total - padding) {
return totalDisplayedPages - (total - current);
}
return padding;
}
}, {
key: "isLastPage",
value: function isLastPage() {
return this.currentPage === this.total - 1;
}
}, {
key: "isFirstPage",
value: function isFirstPage() {
return this.currentPage === 0;
}
}]);
return Paginator;
}();
var withUsage$8 = createDocumentationMessageGenerator({
name: 'pagination',
connector: true
});
/**
* @typedef {Object} CustomPaginationWidgetOptions
* @property {number} [totalPages] The total number of pages to browse.
* @property {number} [padding = 3] The padding of pages to show around the current page
*/
/**
* @typedef {Object} PaginationRenderingOptions
* @property {function(page): string} createURL Creates URLs for the next state, the number is the page to generate the URL for.
* @property {number} currentRefinement The number of the page currently displayed.
* @property {number} nbHits The number of hits computed for the last query (can be approximated).
* @property {number} nbPages The number of pages for the result set.
* @property {number[]} pages The actual pages relevant to the current situation and padding
* @property {boolean} isFirstPage true if the current page is also the first page
* @property {boolean} isLastPage true if the current page is also the last page
* @property {function(page)} refine Sets the current page and trigger a search.
* @property {Object} widgetParams All original `CustomPaginationWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **Pagination** connector provides the logic to build a widget that will let the user
* choose the current page of the results.
*
* When using the pagination with Algolia, you should be aware that the engine won't provide you pages
* beyond the 1000th hits by default. You can find more information on the [Algolia documentation](https://www.algolia.com/doc/guides/searching/pagination/#pagination-limitations).
*
* @type {Connector}
* @param {function(PaginationRenderingOptions, boolean)} renderFn Rendering function for the custom **Pagination** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomPaginationWidgetOptions)} Re-usable widget factory for a custom **Pagination** widget.
* @example
* // custom `renderFn` to render the custom Pagination widget
* function renderFn(PaginationRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* PaginationRenderingOptions.widgetParams.containerNode.html('');
* }
*
* // remove event listeners before replacing markup
* PaginationRenderingOptions.widgetParams.containerNode
* .find('a[data-page]')
* .each(function() { $(this).off('click'); });
*
* var pages = PaginationRenderingOptions.pages
* .map(function(page) {
* return '' +
* '' +
* (parseInt(page) + 1) + ' ';
* });
*
* PaginationRenderingOptions.widgetParams.containerNode
* .find('ul')
* .html(pages);
*
* PaginationRenderingOptions.widgetParams.containerNode
* .find('a[data-page]')
* .each(function() {
* $(this).on('click', function(event) {
* event.preventDefault();
* PaginationRenderingOptions.refine($(this).data('page'));
* });
* });
* }
*
* // connect `renderFn` to Pagination logic
* var customPagination = instantsearch.connectors.connectPagination(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customPagination({
* containerNode: $('#custom-pagination-container'),
* totalPages: 20,
* padding: 4,
* })
* );
*/
function connectPagination(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$8());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var totalPages = widgetParams.totalPages,
_widgetParams$padding = widgetParams.padding,
padding = _widgetParams$padding === void 0 ? 3 : _widgetParams$padding;
var pager = new Paginator({
currentPage: 0,
total: 0,
padding: padding
});
return {
init: function init(_ref) {
var helper = _ref.helper,
createURL = _ref.createURL,
instantSearchInstance = _ref.instantSearchInstance;
this.refine = function (page) {
helper.setPage(page);
helper.search();
};
this.createURL = function (state) {
return function (page) {
return createURL(state.setPage(page));
};
};
renderFn({
createURL: this.createURL(helper.state),
currentRefinement: helper.getPage() || 0,
nbHits: 0,
nbPages: 0,
pages: [],
isFirstPage: true,
isLastPage: true,
refine: this.refine,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, true);
},
getMaxPage: function getMaxPage(_ref2) {
var nbPages = _ref2.nbPages;
return totalPages !== undefined ? Math.min(totalPages, nbPages) : nbPages;
},
render: function render(_ref3) {
var results = _ref3.results,
state = _ref3.state,
instantSearchInstance = _ref3.instantSearchInstance;
var nbPages = this.getMaxPage(results);
pager.currentPage = state.page;
pager.total = nbPages;
renderFn({
createURL: this.createURL(state),
currentRefinement: state.page,
refine: this.refine,
nbHits: results.nbHits,
nbPages: nbPages,
pages: pager.pages(),
isFirstPage: pager.isFirstPage(),
isLastPage: pager.isLastPage(),
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, false);
},
dispose: function dispose() {
unmountFn();
},
getWidgetState: function getWidgetState(uiState, _ref4) {
var searchParameters = _ref4.searchParameters;
var page = searchParameters.page;
if (page === 0 || page + 1 === uiState.page) return uiState;
return _objectSpread({}, uiState, {
page: page + 1
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
var uiState = _ref5.uiState;
var uiPage = uiState.page;
if (uiPage) return searchParameters.setQueryParameter('page', uiState.page - 1);
return searchParameters.setQueryParameter('page', 0);
}
};
};
}
var withUsage$9 = createDocumentationMessageGenerator({
name: 'range-input',
connector: true
}, {
name: 'range-slider',
connector: true
});
/**
* @typedef {Object} CustomRangeWidgetOptions
* @property {string} attribute Name of the attribute for faceting.
* @property {number} [min = undefined] Minimal range value, default to automatically computed from the result set.
* @property {number} [max = undefined] Maximal range value, default to automatically computed from the result set.
* @property {number} [precision = 2] Number of digits after decimal point to use.
*/
/**
* @typedef {Object} RangeRenderingOptions
* @property {function(Array)} refine Sets a range to filter the results on. Both values
* are optional, and will default to the higher and lower bounds. You can use `undefined` to remove a
* previously set bound or to set an infinite bound.
* @property {{min: number, max: number}} range Results bounds without the current range filter.
* @property {Array} start Current numeric bounds of the search.
* @property {{from: function, to: function}} formatter Transform for the rendering `from` and/or `to` values.
* Both functions take a `number` as input and should output a `string`.
* @property {Object} widgetParams All original `CustomRangeWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **Range** connector provides the logic to create custom widget that will let
* the user refine results using a numeric range.
*
* This connectors provides a `refine()` function that accepts bounds. It will also provide
* information about the min and max bounds for the current result set.
* @type {Connector}
* @param {function(RangeRenderingOptions, boolean)} renderFn Rendering function for the custom **Range** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomRangeWidgetOptions)} Re-usable widget factory for a custom **Range** widget.
*/
function connectRange(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$9());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attribute = widgetParams.attribute,
minBound = widgetParams.min,
maxBound = widgetParams.max,
_widgetParams$precisi = widgetParams.precision,
precision = _widgetParams$precisi === void 0 ? 2 : _widgetParams$precisi;
if (!attribute) {
throw new Error(withUsage$9('The `attribute` option is required.'));
}
var hasMinBound = _isFinite(minBound);
var hasMaxBound = _isFinite(maxBound);
var formatToNumber = function formatToNumber(v) {
return Number(Number(v).toFixed(precision));
};
var rangeFormatter = {
from: function from(v) {
return v;
},
to: function to(v) {
return formatToNumber(v).toLocaleString();
}
};
return {
_getCurrentRange: function _getCurrentRange(stats) {
var pow = Math.pow(10, precision);
var min;
if (hasMinBound) {
min = minBound;
} else if (_isFinite(stats.min)) {
min = stats.min;
} else {
min = 0;
}
var max;
if (hasMaxBound) {
max = maxBound;
} else if (_isFinite(stats.max)) {
max = stats.max;
} else {
max = 0;
}
return {
min: Math.floor(min * pow) / pow,
max: Math.ceil(max * pow) / pow
};
},
_getCurrentRefinement: function _getCurrentRefinement(helper) {
var _ref = helper.getNumericRefinement(attribute, '>=') || [],
_ref2 = _slicedToArray(_ref, 1),
minValue = _ref2[0];
var _ref3 = helper.getNumericRefinement(attribute, '<=') || [],
_ref4 = _slicedToArray(_ref3, 1),
maxValue = _ref4[0];
var min = _isFinite(minValue) ? minValue : -Infinity;
var max = _isFinite(maxValue) ? maxValue : Infinity;
return [min, max];
},
_refine: function _refine(helper, currentRange) {
// eslint-disable-next-line complexity
return function () {
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [],
_ref6 = _slicedToArray(_ref5, 2),
nextMin = _ref6[0],
nextMax = _ref6[1];
var currentRangeMin = currentRange.min,
currentRangeMax = currentRange.max;
var _ref7 = helper.getNumericRefinement(attribute, '>=') || [],
_ref8 = _slicedToArray(_ref7, 1),
min = _ref8[0];
var _ref9 = helper.getNumericRefinement(attribute, '<=') || [],
_ref10 = _slicedToArray(_ref9, 1),
max = _ref10[0];
var isResetMin = nextMin === undefined || nextMin === '';
var isResetMax = nextMax === undefined || nextMax === '';
var nextMinAsNumber = !isResetMin ? parseFloat(nextMin) : undefined;
var nextMaxAsNumber = !isResetMax ? parseFloat(nextMax) : undefined;
var newNextMin;
if (!hasMinBound && currentRangeMin === nextMinAsNumber) {
newNextMin = undefined;
} else if (hasMinBound && isResetMin) {
newNextMin = minBound;
} else {
newNextMin = nextMinAsNumber;
}
var newNextMax;
if (!hasMaxBound && currentRangeMax === nextMaxAsNumber) {
newNextMax = undefined;
} else if (hasMaxBound && isResetMax) {
newNextMax = maxBound;
} else {
newNextMax = nextMaxAsNumber;
}
var isResetNewNextMin = newNextMin === undefined;
var isValidNewNextMin = _isFinite(newNextMin);
var isValidMinCurrentRange = _isFinite(currentRangeMin);
var isGreaterThanCurrentRange = isValidMinCurrentRange && currentRangeMin <= newNextMin;
var isMinValid = isResetNewNextMin || isValidNewNextMin && (!isValidMinCurrentRange || isGreaterThanCurrentRange);
var isResetNewNextMax = newNextMax === undefined;
var isValidNewNextMax = _isFinite(newNextMax);
var isValidMaxCurrentRange = _isFinite(currentRangeMax);
var isLowerThanRange = isValidMaxCurrentRange && currentRangeMax >= newNextMax;
var isMaxValid = isResetNewNextMax || isValidNewNextMax && (!isValidMaxCurrentRange || isLowerThanRange);
var hasMinChange = min !== newNextMin;
var hasMaxChange = max !== newNextMax;
if ((hasMinChange || hasMaxChange) && isMinValid && isMaxValid) {
helper.clearRefinements(attribute);
if (isValidNewNextMin) {
helper.addNumericRefinement(attribute, '>=', formatToNumber(newNextMin));
}
if (isValidNewNextMax) {
helper.addNumericRefinement(attribute, '<=', formatToNumber(newNextMax));
}
helper.search();
}
};
},
getConfiguration: function getConfiguration(currentConfiguration) {
var configuration = {
disjunctiveFacets: [attribute]
};
var isBoundsDefined = hasMinBound || hasMaxBound;
var boundsAlreadyDefined = currentConfiguration && currentConfiguration.numericRefinements && currentConfiguration.numericRefinements[attribute] !== undefined;
var isMinBoundValid = _isFinite(minBound);
var isMaxBoundValid = _isFinite(maxBound);
var isAbleToRefine = isMinBoundValid && isMaxBoundValid ? minBound < maxBound : isMinBoundValid || isMaxBoundValid;
if (isBoundsDefined && !boundsAlreadyDefined && isAbleToRefine) {
configuration.numericRefinements = _defineProperty({}, attribute, {});
if (hasMinBound) {
configuration.numericRefinements[attribute]['>='] = [minBound];
}
if (hasMaxBound) {
configuration.numericRefinements[attribute]['<='] = [maxBound];
}
}
return configuration;
},
init: function init(_ref11) {
var helper = _ref11.helper,
instantSearchInstance = _ref11.instantSearchInstance;
var stats = {};
var currentRange = this._getCurrentRange(stats);
var start = this._getCurrentRefinement(helper);
renderFn({
// On first render pass an empty range
// to be able to bypass the validation
// related to it
refine: this._refine(helper, {}),
format: rangeFormatter,
range: currentRange,
widgetParams: _objectSpread({}, widgetParams, {
precision: precision
}),
start: start,
instantSearchInstance: instantSearchInstance
}, true);
},
render: function render(_ref12) {
var results = _ref12.results,
helper = _ref12.helper,
instantSearchInstance = _ref12.instantSearchInstance;
var facetsFromResults = results.disjunctiveFacets || [];
var facet = find_1(facetsFromResults, {
name: attribute
});
var stats = facet && facet.stats || {};
var currentRange = this._getCurrentRange(stats);
var start = this._getCurrentRefinement(helper);
renderFn({
refine: this._refine(helper, currentRange),
format: rangeFormatter,
range: currentRange,
widgetParams: _objectSpread({}, widgetParams, {
precision: precision
}),
start: start,
instantSearchInstance: instantSearchInstance
}, false);
},
dispose: function dispose(_ref13) {
var state = _ref13.state;
unmountFn();
var nextState = state.removeNumericRefinement(attribute).removeDisjunctiveFacet(attribute);
return nextState;
},
getWidgetState: function getWidgetState(uiState, _ref14) {
var searchParameters = _ref14.searchParameters;
var _searchParameters$get = searchParameters.getNumericRefinements(attribute),
_searchParameters$get2 = _searchParameters$get['>='],
min = _searchParameters$get2 === void 0 ? '' : _searchParameters$get2,
_searchParameters$get3 = _searchParameters$get['<='],
max = _searchParameters$get3 === void 0 ? '' : _searchParameters$get3;
if (min === '' && max === '' || uiState && uiState.range && uiState.range[attribute] === "".concat(min, ":").concat(max)) {
return uiState;
}
return _objectSpread({}, uiState, {
range: _objectSpread({}, uiState.range, _defineProperty({}, attribute, "".concat(min, ":").concat(max)))
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref15) {
var uiState = _ref15.uiState;
var value = uiState && uiState.range && uiState.range[attribute];
if (!value || value.indexOf(':') === -1) {
return searchParameters;
}
var _searchParameters$get4 = searchParameters.getNumericRefinements(attribute),
_searchParameters$get5 = _searchParameters$get4['>='],
previousMin = _searchParameters$get5 === void 0 ? [NaN] : _searchParameters$get5,
_searchParameters$get6 = _searchParameters$get4['<='],
previousMax = _searchParameters$get6 === void 0 ? [NaN] : _searchParameters$get6;
var clearedParams = searchParameters.clearRefinements(attribute);
var _value$split$map = value.split(':').map(parseFloat),
_value$split$map2 = _slicedToArray(_value$split$map, 2),
lowerBound = _value$split$map2[0],
upperBound = _value$split$map2[1];
if (previousMin.includes(lowerBound) && previousMax.includes(upperBound)) {
return searchParameters;
}
if (_isFinite(lowerBound)) {
clearedParams = clearedParams.addNumericRefinement(attribute, '>=', lowerBound);
}
if (_isFinite(upperBound)) {
clearedParams = clearedParams.addNumericRefinement(attribute, '<=', upperBound);
}
return clearedParams;
}
};
};
}
var withUsage$a = createDocumentationMessageGenerator({
name: 'refinement-list',
connector: true
});
/**
* @typedef {Object} RefinementListItem
* @property {string} value The value of the refinement list item.
* @property {string} label Human-readable value of the refinement list item.
* @property {number} count Number of matched results after refinement is applied.
* @property {boolean} isRefined Indicates if the list item is refined.
*/
/**
* @typedef {Object} CustomRefinementListWidgetOptions
* @property {string} attribute The name of the attribute in the records.
* @property {"and"|"or"} [operator = 'or'] How the filters are combined together.
* @property {number} [limit = 10] The max number of items to display when
* `showMoreLimit` is not set or if the widget is showing less value.
* @property {boolean} [showMore = false] Whether to display a button that expands the number of items.
* @property {number} [showMoreLimit = 20] The max number of items to display if the widget
* is showing more items.
* @property {string[]|function} [sortBy = ['isRefined', 'count:desc', 'name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
* @property {boolean} [escapeFacetValues = true] Escapes the content of the facet values.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} RefinementListRenderingOptions
* @property {RefinementListItem[]} items The list of filtering values returned from Algolia API.
* @property {function(item.value): string} createURL Creates the next state url for a selected refinement.
* @property {function(item.value)} refine Action to apply selected refinements.
* @property {function} searchForItems Searches for values inside the list.
* @property {boolean} isFromSearch `true` if the values are from an index search.
* @property {boolean} canRefine `true` if a refinement can be applied.
* @property {boolean} canToggleShowMore `true` if the toggleShowMore button can be activated (enough items to display more or
* already displaying more than `limit` items)
* @property {Object} widgetParams All original `CustomRefinementListWidgetOptions` forwarded to the `renderFn`.
* @property {boolean} isShowingMore True if the menu is displaying all the menu items.
* @property {function} toggleShowMore Toggles the number of values displayed between `limit` and `showMoreLimit`.
*/
/**
* **RefinementList** connector provides the logic to build a custom widget that will let the
* user filter the results based on the values of a specific facet.
*
* This connector provides a `toggleShowMore()` function to display more or less items and a `refine()`
* function to select an item.
* @type {Connector}
* @param {function(RefinementListRenderingOptions, boolean)} renderFn Rendering function for the custom **RefinementList** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomRefinementListWidgetOptions)} Re-usable widget factory for a custom **RefinementList** widget.
* @example
* // custom `renderFn` to render the custom RefinementList widget
* function renderFn(RefinementListRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* RefinementListRenderingOptions.widgetParams.containerNode
* .html('')
* }
*
* RefinementListRenderingOptions.widgetParams.containerNode
* .find('li[data-refine-value]')
* .each(function() { $(this).off('click'); });
*
* if (RefinementListRenderingOptions.canRefine) {
* var list = RefinementListRenderingOptions.items.map(function(item) {
* return `
*
*
*
* ${item.label} (${item.count})
*
*
* `;
* });
*
* RefinementListRenderingOptions.widgetParams.containerNode.find('ul').html(list);
* RefinementListRenderingOptions.widgetParams.containerNode
* .find('li[data-refine-value]')
* .each(function() {
* $(this).on('click', function(event) {
* event.stopPropagation();
* event.preventDefault();
*
* RefinementListRenderingOptions.refine($(this).data('refine-value'));
* });
* });
* } else {
* RefinementListRenderingOptions.widgetParams.containerNode.find('ul').html('');
* }
* }
*
* // connect `renderFn` to RefinementList logic
* var customRefinementList = instantsearch.connectors.connectRefinementList(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customRefinementList({
* containerNode: $('#custom-refinement-list-container'),
* attribute: 'categories',
* limit: 10,
* })
* );
*/
function connectRefinementList(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$a());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attribute = widgetParams.attribute,
_widgetParams$operato = widgetParams.operator,
operator = _widgetParams$operato === void 0 ? 'or' : _widgetParams$operato,
_widgetParams$limit = widgetParams.limit,
limit = _widgetParams$limit === void 0 ? 10 : _widgetParams$limit,
_widgetParams$showMor = widgetParams.showMore,
showMore = _widgetParams$showMor === void 0 ? false : _widgetParams$showMor,
_widgetParams$showMor2 = widgetParams.showMoreLimit,
showMoreLimit = _widgetParams$showMor2 === void 0 ? 20 : _widgetParams$showMor2,
_widgetParams$sortBy = widgetParams.sortBy,
sortBy = _widgetParams$sortBy === void 0 ? ['isRefined', 'count:desc', 'name:asc'] : _widgetParams$sortBy,
_widgetParams$escapeF = widgetParams.escapeFacetValues,
escapeFacetValues = _widgetParams$escapeF === void 0 ? true : _widgetParams$escapeF,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
if (!attribute) {
throw new Error(withUsage$a('The `attribute` option is required.'));
}
if (!/^(and|or)$/.test(operator)) {
throw new Error(withUsage$a("The `operator` must one of: `\"and\"`, `\"or\"` (got \"".concat(operator, "\").")));
}
if (showMore === true && showMoreLimit <= limit) {
throw new Error(withUsage$a('`showMoreLimit` should be greater than `limit`.'));
}
var formatItems = function formatItems(_ref) {
var label = _ref.name,
item = _objectWithoutProperties(_ref, ["name"]);
return _objectSpread({}, item, {
label: label,
value: label,
highlighted: label
});
};
var _render = function render(_ref2) {
var items = _ref2.items,
state = _ref2.state,
createURL = _ref2.createURL,
helperSpecializedSearchFacetValues = _ref2.helperSpecializedSearchFacetValues,
refine = _ref2.refine,
isFromSearch = _ref2.isFromSearch,
isFirstSearch = _ref2.isFirstSearch,
isShowingMore = _ref2.isShowingMore,
toggleShowMore = _ref2.toggleShowMore,
hasExhaustiveItems = _ref2.hasExhaustiveItems,
instantSearchInstance = _ref2.instantSearchInstance;
// Compute a specific createURL method able to link to any facet value state change
var _createURL = function _createURL(facetValue) {
return createURL(state.toggleRefinement(attribute, facetValue));
}; // Do not mistake searchForFacetValues and searchFacetValues which is the actual search
// function
var searchFacetValues = helperSpecializedSearchFacetValues && helperSpecializedSearchFacetValues(state, createURL, helperSpecializedSearchFacetValues, refine, instantSearchInstance);
renderFn({
createURL: _createURL,
items: items,
refine: refine,
searchForItems: searchFacetValues,
instantSearchInstance: instantSearchInstance,
isFromSearch: isFromSearch,
canRefine: isFromSearch || items.length > 0,
widgetParams: widgetParams,
isShowingMore: isShowingMore,
canToggleShowMore: showMore && (isShowingMore || !hasExhaustiveItems),
toggleShowMore: toggleShowMore,
hasExhaustiveItems: hasExhaustiveItems
}, isFirstSearch);
};
var lastResultsFromMainSearch;
var searchForFacetValues;
var refine;
var createSearchForFacetValues = function createSearchForFacetValues(helper) {
return function (state, createURL, helperSpecializedSearchFacetValues, toggleRefinement, instantSearchInstance) {
return function (query) {
if (query === '' && lastResultsFromMainSearch) {
// render with previous data from the helper.
_render({
items: lastResultsFromMainSearch,
state: state,
createURL: createURL,
helperSpecializedSearchFacetValues: helperSpecializedSearchFacetValues,
refine: toggleRefinement,
isFromSearch: false,
isFirstSearch: false,
instantSearchInstance: instantSearchInstance,
hasExhaustiveItems: false // SFFV should not be used with show more
});
} else {
var tags = {
highlightPreTag: escapeFacetValues ? TAG_PLACEHOLDER.highlightPreTag : TAG_REPLACEMENT.highlightPreTag,
highlightPostTag: escapeFacetValues ? TAG_PLACEHOLDER.highlightPostTag : TAG_REPLACEMENT.highlightPostTag
};
helper.searchForFacetValues(attribute, query, limit, tags).then(function (results) {
var facetValues = escapeFacetValues ? escapeFacets(results.facetHits) : results.facetHits;
var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
var value = _ref3.value,
item = _objectWithoutProperties(_ref3, ["value"]);
return _objectSpread({}, item, {
value: value,
label: value
});
}));
_render({
items: normalizedFacetValues,
state: state,
createURL: createURL,
helperSpecializedSearchFacetValues: helperSpecializedSearchFacetValues,
refine: toggleRefinement,
isFromSearch: true,
isFirstSearch: false,
instantSearchInstance: instantSearchInstance,
hasExhaustiveItems: false // SFFV should not be used with show more
});
});
}
};
};
};
return {
isShowingMore: false,
// Provide the same function to the `renderFn` so that way the user
// has to only bind it once when `isFirstRendering` for instance
toggleShowMore: function toggleShowMore() {},
cachedToggleShowMore: function cachedToggleShowMore() {
this.toggleShowMore();
},
createToggleShowMore: function createToggleShowMore(renderOptions) {
var _this = this;
return function () {
_this.isShowingMore = !_this.isShowingMore;
_this.render(renderOptions);
};
},
getLimit: function getLimit() {
return this.isShowingMore ? showMoreLimit : limit;
},
getConfiguration: function getConfiguration() {
var configuration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var widgetConfiguration = _defineProperty({}, operator === 'and' ? 'facets' : 'disjunctiveFacets', [attribute]);
var currentMaxValuesPerFacet = configuration.maxValuesPerFacet || 0;
widgetConfiguration.maxValuesPerFacet = Math.max(currentMaxValuesPerFacet, showMore ? showMoreLimit : limit);
return widgetConfiguration;
},
init: function init(_ref4) {
var helper = _ref4.helper,
createURL = _ref4.createURL,
instantSearchInstance = _ref4.instantSearchInstance;
this.cachedToggleShowMore = this.cachedToggleShowMore.bind(this);
refine = function refine(facetValue) {
return helper.toggleRefinement(attribute, facetValue).search();
};
searchForFacetValues = createSearchForFacetValues(helper);
_render({
items: [],
state: helper.state,
createURL: createURL,
helperSpecializedSearchFacetValues: searchForFacetValues,
refine: refine,
isFromSearch: false,
isFirstSearch: true,
instantSearchInstance: instantSearchInstance,
isShowingMore: this.isShowingMore,
toggleShowMore: this.cachedToggleShowMore,
hasExhaustiveItems: true
});
},
render: function render(renderOptions) {
var results = renderOptions.results,
state = renderOptions.state,
createURL = renderOptions.createURL,
instantSearchInstance = renderOptions.instantSearchInstance;
var facetValues = results.getFacetValues(attribute, {
sortBy: sortBy
});
var items = transformItems(facetValues.slice(0, this.getLimit()).map(formatItems));
var maxValuesPerFacetConfig = state.getQueryParameter('maxValuesPerFacet');
var currentLimit = this.getLimit(); // If the limit is the max number of facet retrieved it is impossible to know
// if the facets are exhaustive. The only moment we are sure it is exhaustive
// is when it is strictly under the number requested unless we know that another
// widget has requested more values (maxValuesPerFacet > getLimit()).
// Because this is used for making the search of facets unable or not, it is important
// to be conservative here.
var hasExhaustiveItems = maxValuesPerFacetConfig > currentLimit ? facetValues.length <= currentLimit : facetValues.length < currentLimit;
lastResultsFromMainSearch = items;
this.toggleShowMore = this.createToggleShowMore(renderOptions);
_render({
items: items,
state: state,
createURL: createURL,
helperSpecializedSearchFacetValues: searchForFacetValues,
refine: refine,
isFromSearch: false,
isFirstSearch: false,
instantSearchInstance: instantSearchInstance,
isShowingMore: this.isShowingMore,
toggleShowMore: this.cachedToggleShowMore,
hasExhaustiveItems: hasExhaustiveItems
});
},
dispose: function dispose(_ref5) {
var state = _ref5.state;
unmountFn();
if (operator === 'and') {
return state.removeFacetRefinement(attribute).removeFacet(attribute);
} else {
return state.removeDisjunctiveFacetRefinement(attribute).removeDisjunctiveFacet(attribute);
}
},
getWidgetState: function getWidgetState(uiState, _ref6) {
var searchParameters = _ref6.searchParameters;
var values = operator === 'or' ? searchParameters.getDisjunctiveRefinements(attribute) : searchParameters.getConjunctiveRefinements(attribute);
if (values.length === 0 || uiState.refinementList && isEqual_1(values, uiState.refinementList[attribute])) {
return uiState;
}
return _objectSpread({}, uiState, {
refinementList: _objectSpread({}, uiState.refinementList, _defineProperty({}, attribute, values))
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
var uiState = _ref7.uiState;
var values = uiState.refinementList && uiState.refinementList[attribute];
if (values === undefined) return searchParameters;
return values.reduce(function (sp, v) {
return operator === 'or' ? sp.addDisjunctiveFacetRefinement(attribute, v) : sp.addFacetRefinement(attribute, v);
}, searchParameters.clearRefinements(attribute));
}
};
};
}
var withUsage$b = createDocumentationMessageGenerator({
name: 'search-box',
connector: true
});
/**
* @typedef {Object} CustomSearchBoxWidgetOptions
* @property {function(string, function(string))} [queryHook = undefined] A function that will be called every time
* a new value for the query is set. The first parameter is the query and the second is a
* function to actually trigger the search. The function takes the query as the parameter.
*
* This queryHook can be used to debounce the number of searches done from the searchBox.
*/
/**
* @typedef {Object} SearchBoxRenderingOptions
* @property {string} query The query from the last search.
* @property {function(SearchParameters)} onHistoryChange Registers a callback when the browser history changes.
* @property {function(string)} refine Sets a new query and searches.
* @property {function()} clear Remove the query and perform search.
* @property {Object} widgetParams All original `CustomSearchBoxWidgetOptions` forwarded to the `renderFn`.
* @property {boolean} isSearchStalled `true` if the search results takes more than a certain time to come back
* from Algolia servers. This can be configured on the InstantSearch constructor with the attribute
* `stalledSearchDelay` which is 200ms, by default.
*/
/**
* **SearchBox** connector provides the logic to build a widget that will let the user search for a query.
*
* The connector provides to the rendering: `refine()` to set the query. The behaviour of this function
* may be impacted by the `queryHook` widget parameter.
* @type {Connector}
* @param {function(SearchBoxRenderingOptions, boolean)} renderFn Rendering function for the custom **SearchBox** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomSearchBoxWidgetOptions)} Re-usable widget factory for a custom **SearchBox** widget.
* @example
* // custom `renderFn` to render the custom SearchBox widget
* function renderFn(SearchBoxRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* SearchBoxRenderingOptions.widgetParams.containerNode.html(' ');
* SearchBoxRenderingOptions.widgetParams.containerNode
* .find('input')
* .on('keyup', function() {
* SearchBoxRenderingOptions.refine($(this).val());
* });
* SearchBoxRenderingOptions.widgetParams.containerNode
* .find('input')
* .val(SearchBoxRenderingOptions.query);
* }
* }
*
* // connect `renderFn` to SearchBox logic
* var customSearchBox = instantsearch.connectors.connectSearchBox(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customSearchBox({
* containerNode: $('#custom-searchbox'),
* })
* );
*/
function connectSearchBox(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$b());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var queryHook = widgetParams.queryHook;
function clear(helper) {
return function () {
helper.setQuery('');
helper.search();
};
}
return {
_clear: function _clear() {},
_cachedClear: function _cachedClear() {
this._clear();
},
init: function init(_ref) {
var helper = _ref.helper,
onHistoryChange = _ref.onHistoryChange,
instantSearchInstance = _ref.instantSearchInstance;
this._cachedClear = this._cachedClear.bind(this);
this._clear = clear(helper);
this._refine = function () {
var previousQuery;
var setQueryAndSearch = function setQueryAndSearch(q) {
var doSearch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (q !== helper.state.query) {
previousQuery = helper.state.query;
helper.setQuery(q);
}
if (doSearch && previousQuery !== undefined && previousQuery !== q) helper.search();
};
return queryHook ? function (q) {
return queryHook(q, setQueryAndSearch);
} : setQueryAndSearch;
}();
this._onHistoryChange = onHistoryChange;
renderFn({
query: helper.state.query,
onHistoryChange: this._onHistoryChange,
refine: this._refine,
clear: this._cachedClear,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, true);
},
render: function render(_ref2) {
var helper = _ref2.helper,
instantSearchInstance = _ref2.instantSearchInstance,
searchMetadata = _ref2.searchMetadata;
this._clear = clear(helper);
renderFn({
query: helper.state.query,
onHistoryChange: this._onHistoryChange,
refine: this._refine,
clear: this._cachedClear,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance,
isSearchStalled: searchMetadata.isSearchStalled
}, false);
},
dispose: function dispose(_ref3) {
var state = _ref3.state;
unmountFn();
return state.setQuery('');
},
getWidgetState: function getWidgetState(uiState, _ref4) {
var searchParameters = _ref4.searchParameters;
var query = searchParameters.query;
if (query === '' || uiState && uiState.query === query) {
return uiState;
}
return _objectSpread({}, uiState, {
query: query
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
var uiState = _ref5.uiState;
return searchParameters.setQuery(uiState.query || '');
}
};
};
}
var withUsage$c = createDocumentationMessageGenerator({
name: 'sort-by',
connector: true
});
/**
* @typedef {Object} SortByItem
* @property {string} value The name of the index to target.
* @property {string} label The label of the index to display.
*/
/**
* @typedef {Object} CustomSortByWidgetOptions
* @property {SortByItem[]} items Array of objects defining the different indices to choose from.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} SortByRenderingOptions
* @property {string} currentRefinement The currently selected index.
* @property {SortByItem[]} options All the available indices
* @property {function(string)} refine Switches indices and triggers a new search.
* @property {boolean} hasNoResults `true` if the last search contains no result.
* @property {Object} widgetParams All original `CustomSortByWidgetOptions` forwarded to the `renderFn`.
*/
/**
* The **SortBy** connector provides the logic to build a custom widget that will display a
* list of indices. With Algolia, this is most commonly used for changing ranking strategy. This allows
* a user to change how the hits are being sorted.
*
* This connector provides the `refine` function that allows to switch indices.
* The connector provides to the rendering: `refine()` to switch the current index and
* `options` that are the values that can be selected. `refine` should be used
* with `options.value`.
* @type {Connector}
* @param {function(SortByRenderingOptions, boolean)} renderFn Rendering function for the custom **SortBy** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomSortByWidgetOptions)} Re-usable widget factory for a custom **SortBy** widget.
* @example
* // custom `renderFn` to render the custom SortBy widget
* function renderFn(SortByRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* SortByRenderingOptions.widgetParams.containerNode.html(' ');
* SortByRenderingOptions.widgetParams.containerNode
* .find('select')
* .on('change', function(event) {
* SortByRenderingOptions.refine(event.target.value);
* });
* }
*
* var optionsHTML = SortByRenderingOptions.options.map(function(option) {
* return `
*
* ${option.label}
*
* `;
* });
*
* SortByRenderingOptions.widgetParams.containerNode
* .find('select')
* .html(optionsHTML);
* }
*
* // connect `renderFn` to SortBy logic
* var customSortBy = instantsearch.connectors.connectSortBy(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customSortBy({
* containerNode: $('#custom-sort-by-container'),
* items: [
* { value: 'instant_search', label: 'Most relevant' },
* { value: 'instant_search_price_asc', label: 'Lowest price' },
* { value: 'instant_search_price_desc', label: 'Highest price' },
* ],
* })
* );
*/
function connectSortBy(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$c());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var items = widgetParams.items,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (x) {
return x;
} : _widgetParams$transfo;
if (!items) {
throw new Error(withUsage$c('The `items` option expects an array of objects.'));
}
return {
init: function init(_ref) {
var helper = _ref.helper,
instantSearchInstance = _ref.instantSearchInstance;
var currentIndex = helper.getIndex();
var isIndexInList = find_1(items, function (item) {
return item.value === currentIndex;
});
if (!isIndexInList) {
throw new Error("[sortBy]: Index ".concat(currentIndex, " not present in `items`"));
}
this.initialIndex = instantSearchInstance.indexName;
this.setIndex = function (indexName) {
return helper.setIndex(indexName).search();
};
renderFn({
currentRefinement: currentIndex,
options: transformItems(items),
refine: this.setIndex,
hasNoResults: true,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, true);
},
render: function render(_ref2) {
var helper = _ref2.helper,
results = _ref2.results,
instantSearchInstance = _ref2.instantSearchInstance;
renderFn({
currentRefinement: helper.getIndex(),
options: transformItems(items),
refine: this.setIndex,
hasNoResults: results.nbHits === 0,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, false);
},
dispose: function dispose(_ref3) {
var state = _ref3.state;
unmountFn();
return state.setIndex(this.initialIndex);
},
getWidgetState: function getWidgetState(uiState, _ref4) {
var searchParameters = _ref4.searchParameters;
var currentIndex = searchParameters.getQueryParameter('index');
var isInitialIndex = currentIndex === this.initialIndex;
if (isInitialIndex || uiState && uiState.sortBy === currentIndex) {
return uiState;
}
return _objectSpread({}, uiState, {
sortBy: searchParameters.getQueryParameter('index')
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
var uiState = _ref5.uiState;
return searchParameters.setQueryParameter('index', uiState.sortBy || this.initialIndex);
}
};
};
}
var withUsage$d = createDocumentationMessageGenerator({
name: 'rating-menu',
connector: true
});
/**
* @typedef {Object} StarRatingItems
* @property {string} name Name corresponding to the number of stars.
* @property {string} value Number of stars as string.
* @property {number} count Count of matched results corresponding to the number of stars.
* @property {boolean[]} stars Array of length of maximum rating value with stars to display or not.
* @property {boolean} isRefined Indicates if star rating refinement is applied.
*/
/**
* @typedef {Object} CustomStarRatingWidgetOptions
* @property {string} attribute Name of the attribute for faceting (eg. "free_shipping").
* @property {number} [max = 5] The maximum rating value.
*/
/**
* @typedef {Object} StarRatingRenderingOptions
* @property {StarRatingItems[]} items Possible star ratings the user can apply.
* @property {function(string): string} createURL Creates an URL for the next
* state (takes the item value as parameter). Takes the value of an item as parameter.
* @property {function(string)} refine Selects a rating to filter the results
* (takes the filter value as parameter). Takes the value of an item as parameter.
* @property {boolean} hasNoResults `true` if the last search contains no result.
* @property {Object} widgetParams All original `CustomStarRatingWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **StarRating** connector provides the logic to build a custom widget that will let
* the user refine search results based on ratings.
*
* The connector provides to the rendering: `refine()` to select a value and
* `items` that are the values that can be selected. `refine` should be used
* with `items.value`.
* @type {Connector}
* @param {function(StarRatingRenderingOptions, boolean)} renderFn Rendering function for the custom **StarRating** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomStarRatingWidgetOptions)} Re-usable widget factory for a custom **StarRating** widget.
* @example
* // custom `renderFn` to render the custom StarRating widget
* function renderFn(StarRatingRenderingOptions, isFirstRendering) {
* if (isFirstRendering) {
* StarRatingRenderingOptions.widgetParams.containerNode.html('');
* }
*
* StarRatingRenderingOptions.widgetParams.containerNode
* .find('li[data-refine-value]')
* .each(function() { $(this).off('click'); });
*
* var listHTML = StarRatingRenderingOptions.items.map(function(item) {
* return '' +
* '' +
* item.stars.map(function(star) { return star === false ? '☆' : '★'; }).join(' ') +
* '& up (' + item.count + ')' +
* ' ';
* });
*
* StarRatingRenderingOptions.widgetParams.containerNode
* .find('ul')
* .html(listHTML);
*
* StarRatingRenderingOptions.widgetParams.containerNode
* .find('li[data-refine-value]')
* .each(function() {
* $(this).on('click', function(event) {
* event.preventDefault();
* event.stopPropagation();
*
* StarRatingRenderingOptions.refine($(this).data('refine-value'));
* });
* });
* }
*
* // connect `renderFn` to StarRating logic
* var customStarRating = instantsearch.connectors.connectRatingMenu(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customStarRating({
* containerNode: $('#custom-rating-menu-container'),
* attribute: 'rating',
* max: 5,
* })
* );
*/
function connectRatingMenu(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$d());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attribute = widgetParams.attribute,
_widgetParams$max = widgetParams.max,
max = _widgetParams$max === void 0 ? 5 : _widgetParams$max;
if (!attribute) {
throw new Error(withUsage$d('The `attribute` option is required.'));
}
return {
getConfiguration: function getConfiguration() {
return {
disjunctiveFacets: [attribute]
};
},
init: function init(_ref) {
var helper = _ref.helper,
createURL = _ref.createURL,
instantSearchInstance = _ref.instantSearchInstance;
this._toggleRefinement = this._toggleRefinement.bind(this, helper);
this._createURL = function (state) {
return function (facetValue) {
return createURL(state.toggleRefinement(attribute, facetValue));
};
};
renderFn({
instantSearchInstance: instantSearchInstance,
items: [],
hasNoResults: true,
refine: this._toggleRefinement,
createURL: this._createURL(helper.state),
widgetParams: widgetParams
}, true);
},
render: function render(_ref2) {
var helper = _ref2.helper,
results = _ref2.results,
state = _ref2.state,
instantSearchInstance = _ref2.instantSearchInstance;
var facetValues = [];
var allValues = {};
for (var v = max; v >= 0; --v) {
allValues[v] = 0;
}
results.getFacetValues(attribute).forEach(function (facet) {
var val = Math.round(facet.name);
if (!val || val > max) {
return;
}
for (var _v = val; _v >= 1; --_v) {
allValues[_v] += facet.count;
}
});
var refinedStar = this._getRefinedStar(helper.state);
for (var star = max - 1; star >= 1; --star) {
var count = allValues[star];
if (refinedStar && star !== refinedStar && count === 0) {
// skip count==0 when at least 1 refinement is enabled
// eslint-disable-next-line no-continue
continue;
}
var stars = [];
for (var i = 1; i <= max; ++i) {
stars.push(i <= star);
}
facetValues.push({
stars: stars,
name: String(star),
value: String(star),
count: count,
isRefined: refinedStar === star
});
}
renderFn({
instantSearchInstance: instantSearchInstance,
items: facetValues,
hasNoResults: results.nbHits === 0,
refine: this._toggleRefinement,
createURL: this._createURL(state),
widgetParams: widgetParams
}, false);
},
dispose: function dispose(_ref3) {
var state = _ref3.state;
unmountFn();
var nextState = state.removeDisjunctiveFacetRefinement(attribute).removeDisjunctiveFacet(attribute);
return nextState;
},
getWidgetState: function getWidgetState(uiState, _ref4) {
var searchParameters = _ref4.searchParameters;
var refinedStar = this._getRefinedStar(searchParameters);
if (refinedStar === undefined || uiState && uiState.ratingMenu && uiState.ratingMenu[attribute] === refinedStar) return uiState;
return _objectSpread({}, uiState, {
ratingMenu: _objectSpread({}, uiState.ratingMenu, _defineProperty({}, attribute, refinedStar))
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
var uiState = _ref5.uiState;
var starRatingFromURL = uiState.ratingMenu && uiState.ratingMenu[attribute];
var refinedStar = this._getRefinedStar(searchParameters);
if (starRatingFromURL === refinedStar) return searchParameters;
var clearedSearchParam = searchParameters.clearRefinements(attribute);
if (starRatingFromURL !== undefined) {
for (var val = Number(starRatingFromURL); val <= max; ++val) {
clearedSearchParam = clearedSearchParam.addDisjunctiveFacetRefinement(attribute, val);
}
}
return clearedSearchParam;
},
_toggleRefinement: function _toggleRefinement(helper, facetValue) {
var isRefined = this._getRefinedStar(helper.state) === Number(facetValue);
helper.clearRefinements(attribute);
if (!isRefined) {
for (var val = Number(facetValue); val <= max; ++val) {
helper.addDisjunctiveFacetRefinement(attribute, val);
}
}
helper.search();
},
_getRefinedStar: function _getRefinedStar(searchParameters) {
var refinedStar = undefined;
var refinements = searchParameters.getDisjunctiveRefinements(attribute);
refinements.forEach(function (r) {
if (!refinedStar || Number(r) < refinedStar) {
refinedStar = Number(r);
}
});
return refinedStar;
}
};
};
}
var withUsage$e = createDocumentationMessageGenerator({
name: 'stats',
connector: true
});
/**
* @typedef {Object} StatsRenderingOptions
* @property {number} hitsPerPage The maximum number of hits per page returned by Algolia.
* @property {number} nbHits The number of hits in the result set.
* @property {number} nbPages The number of pages computed for the result set.
* @property {number} page The current page.
* @property {number} processingTimeMS The time taken to compute the results inside the Algolia engine.
* @property {string} query The query used for the current search.
* @property {object} widgetParams All original `CustomStatsWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **Stats** connector provides the logic to build a custom widget that will displays
* search statistics (hits number and processing time).
*
* @type {Connector}
* @param {function(StatsRenderingOptions, boolean)} renderFn Rendering function for the custom **Stats** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function} Re-usable widget factory for a custom **Stats** widget.
* @example
* // custom `renderFn` to render the custom Stats widget
* function renderFn(StatsRenderingOptions, isFirstRendering) {
* if (isFirstRendering) return;
*
* StatsRenderingOptions.widgetParams.containerNode
* .html(StatsRenderingOptions.nbHits + ' results found in ' + StatsRenderingOptions.processingTimeMS);
* }
*
* // connect `renderFn` to Stats logic
* var customStatsWidget = instantsearch.connectors.connectStats(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customStatsWidget({
* containerNode: $('#custom-stats-container'),
* })
* );
*/
function connectStats(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$e());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return {
init: function init(_ref) {
var helper = _ref.helper,
instantSearchInstance = _ref.instantSearchInstance;
renderFn({
instantSearchInstance: instantSearchInstance,
hitsPerPage: helper.state.hitsPerPage,
nbHits: 0,
nbPages: 0,
page: helper.state.page,
processingTimeMS: -1,
query: helper.state.query,
widgetParams: widgetParams
}, true);
},
render: function render(_ref2) {
var results = _ref2.results,
instantSearchInstance = _ref2.instantSearchInstance;
renderFn({
instantSearchInstance: instantSearchInstance,
hitsPerPage: results.hitsPerPage,
nbHits: results.nbHits,
nbPages: results.nbPages,
page: results.page,
processingTimeMS: results.processingTimeMS,
query: results.query,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
var withUsage$f = createDocumentationMessageGenerator({
name: 'toggle-refinement',
connector: true
});
/**
* @typedef {Object} ToggleValue
* @property {boolean} isRefined `true` if the toggle is on.
* @property {number} count Number of results matched after applying the toggle refinement.
* @property {Object} onFacetValue Value of the toggle when it's on.
* @property {Object} offFacetValue Value of the toggle when it's off.
*/
/**
* @typedef {Object} CustomToggleWidgetOptions
* @property {string} attribute Name of the attribute for faceting (eg. "free_shipping").
* @property {Object} [on = true] Value to filter on when toggled.
* @property {Object} [off] Value to filter on when not toggled.
*/
/**
* @typedef {Object} ToggleRenderingOptions
* @property {ToggleValue} value The current toggle value.
* @property {function():string} createURL Creates an URL for the next state.
* @property {function(value)} refine Updates to the next state by applying the toggle refinement.
* @property {Object} widgetParams All original `CustomToggleWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **Toggle** connector provides the logic to build a custom widget that will provide
* an on/off filtering feature based on an attribute value or values.
*
* Two modes are implemented in the custom widget:
* - with or without the value filtered
* - switch between two values.
*
* @type {Connector}
* @param {function(ToggleRenderingOptions, boolean)} renderFn Rendering function for the custom **Toggle** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomToggleWidgetOptions)} Re-usable widget factory for a custom **Toggle** widget.
* @example
* // custom `renderFn` to render the custom ClearAll widget
* function renderFn(ToggleRenderingOptions, isFirstRendering) {
* ToggleRenderingOptions.widgetParams.containerNode
* .find('a')
* .off('click');
*
* var buttonHTML = `
*
*
* ${ToggleRenderingOptions.value.name} (${ToggleRenderingOptions.value.count})
*
* `;
*
* ToggleRenderingOptions.widgetParams.containerNode.html(buttonHTML);
* ToggleRenderingOptions.widgetParams.containerNode
* .find('a')
* .on('click', function(event) {
* event.preventDefault();
* event.stopPropagation();
*
* ToggleRenderingOptions.refine(ToggleRenderingOptions.value);
* });
* }
*
* // connect `renderFn` to Toggle logic
* var customToggle = instantsearch.connectors.connectToggleRefinement(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customToggle({
* containerNode: $('#custom-toggle-container'),
* attribute: 'free_shipping',
* })
* );
*/
function connectToggleRefinement(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$f());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attribute = widgetParams.attribute,
_widgetParams$on = widgetParams.on,
userOn = _widgetParams$on === void 0 ? true : _widgetParams$on,
userOff = widgetParams.off;
if (!attribute) {
throw new Error(withUsage$f('The `attribute` option is required.'));
}
var hasAnOffValue = userOff !== undefined;
var on = userOn ? escapeRefinement(userOn) : undefined;
var off = userOff ? escapeRefinement(userOff) : undefined;
return {
getConfiguration: function getConfiguration() {
return {
disjunctiveFacets: [attribute]
};
},
_toggleRefinement: function _toggleRefinement(helper) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
isRefined = _ref.isRefined;
// Checking
if (!isRefined) {
if (hasAnOffValue) {
helper.removeDisjunctiveFacetRefinement(attribute, off);
}
helper.addDisjunctiveFacetRefinement(attribute, on);
} else {
// Unchecking
helper.removeDisjunctiveFacetRefinement(attribute, on);
if (hasAnOffValue) {
helper.addDisjunctiveFacetRefinement(attribute, off);
}
}
helper.search();
},
init: function init(_ref2) {
var _this = this;
var state = _ref2.state,
helper = _ref2.helper,
createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance;
this._createURL = function (isCurrentlyRefined) {
return function () {
return createURL(state.removeDisjunctiveFacetRefinement(attribute, isCurrentlyRefined ? on : off).addDisjunctiveFacetRefinement(attribute, isCurrentlyRefined ? off : on));
};
};
this.toggleRefinement = function (opts) {
_this._toggleRefinement(helper, opts);
};
var isRefined = state.isDisjunctiveFacetRefined(attribute, on); // no need to refine anything at init if no custom off values
if (hasAnOffValue) {
// Add filtering on the 'off' value if set
if (!isRefined) {
var currentPage = helper.getPage();
helper.addDisjunctiveFacetRefinement(attribute, off).setPage(currentPage);
}
}
var onFacetValue = {
isRefined: isRefined,
count: 0
};
var offFacetValue = {
isRefined: hasAnOffValue && !isRefined,
count: 0
};
var value = {
name: attribute,
isRefined: isRefined,
count: null,
onFacetValue: onFacetValue,
offFacetValue: offFacetValue
};
renderFn({
value: value,
createURL: this._createURL(value.isRefined),
refine: this.toggleRefinement,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, true);
},
render: function render(_ref3) {
var helper = _ref3.helper,
results = _ref3.results,
state = _ref3.state,
instantSearchInstance = _ref3.instantSearchInstance;
var isRefined = helper.state.isDisjunctiveFacetRefined(attribute, on);
var offValue = off === undefined ? false : off;
var allFacetValues = results.getFacetValues(attribute);
var onData = find_1(allFacetValues, function (_ref4) {
var name = _ref4.name;
return name === unescapeRefinement(on);
});
var onFacetValue = {
isRefined: onData !== undefined ? onData.isRefined : false,
count: onData === undefined ? null : onData.count
};
var offData = hasAnOffValue ? find_1(allFacetValues, function (_ref5) {
var name = _ref5.name;
return name === unescapeRefinement(offValue);
}) : undefined;
var offFacetValue = {
isRefined: offData !== undefined ? offData.isRefined : false,
count: offData === undefined ? allFacetValues.reduce(function (total, _ref6) {
var count = _ref6.count;
return total + count;
}, 0) : offData.count
}; // what will we show by default,
// if checkbox is not checked, show: [ ] free shipping (countWhenChecked)
// if checkbox is checked, show: [x] free shipping (countWhenNotChecked)
var nextRefinement = isRefined ? offFacetValue : onFacetValue;
var value = {
name: attribute,
isRefined: isRefined,
count: nextRefinement === undefined ? null : nextRefinement.count,
onFacetValue: onFacetValue,
offFacetValue: offFacetValue
};
renderFn({
value: value,
state: state,
createURL: this._createURL(value.isRefined),
refine: this.toggleRefinement,
helper: helper,
instantSearchInstance: instantSearchInstance,
widgetParams: widgetParams
}, false);
},
dispose: function dispose(_ref7) {
var state = _ref7.state;
unmountFn();
var nextState = state.removeDisjunctiveFacetRefinement(attribute).removeDisjunctiveFacet(attribute);
return nextState;
},
getWidgetState: function getWidgetState(uiState, _ref8) {
var searchParameters = _ref8.searchParameters;
var isRefined = searchParameters.isDisjunctiveFacetRefined(attribute, on);
if (!isRefined || uiState && uiState.toggle && uiState.toggle[attribute] === isRefined) {
return uiState;
}
return _objectSpread({}, uiState, {
toggle: _objectSpread({}, uiState.toggle, _defineProperty({}, attribute, isRefined))
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref9) {
var uiState = _ref9.uiState;
var isRefined = Boolean(uiState.toggle && uiState.toggle[attribute]);
if (isRefined) {
if (hasAnOffValue) return searchParameters.removeDisjunctiveFacetRefinement(attribute, off).addDisjunctiveFacetRefinement(attribute, on);
return searchParameters.addDisjunctiveFacetRefinement(attribute, on);
}
if (hasAnOffValue) return searchParameters.removeDisjunctiveFacetRefinement(attribute, on).addDisjunctiveFacetRefinement(attribute, off);
return searchParameters.removeDisjunctiveFacetRefinement(attribute, on);
}
};
};
}
var withUsage$g = createDocumentationMessageGenerator({
name: 'breadcrumb',
connector: true
});
/**
* @typedef {Object} BreadcrumbItem
* @property {string} label Label of the category or subcategory.
* @property {string} value Value of breadcrumb item.
*/
/**
* @typedef {Object} CustomBreadcrumbWidgetOptions
* @property {string[]} attributes Attributes to use to generate the hierarchy of the breadcrumb.
* @property {string} [rootPath = null] Prefix path to use if the first level is not the root level.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
*/
/**
* @typedef {Object} BreadcrumbRenderingOptions
* @property {function(item.value): string} createURL Creates an url for the next state for a clicked item. The special value `null` is used for the `Home` (or root) item of the breadcrumb and will return an empty array.
* @property {BreadcrumbItem[]} items Values to be rendered.
* @property {function(item.value)} refine Sets the path of the hierarchical filter and triggers a new search.
* @property {Object} widgetParams All original `CustomBreadcrumbWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **Breadcrumb** connector provides the logic to build a custom widget
* that will give the user the ability to see the current path in a hierarchical facet.
*
* This is commonly used in websites that have a large amount of content organized in a hierarchical manner (usually e-commerce websites).
* @type {Connector}
* @param {function(BreadcrumbRenderingOptions, boolean)} renderFn Rendering function for the custom **Breadcrumb* widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomBreadcrumbWidgetOptions)} Re-usable widget factory for a custom **Breadcrumb** widget.
*/
function connectBreadcrumb(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$g());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var attributes = widgetParams.attributes,
_widgetParams$separat = widgetParams.separator,
separator = _widgetParams$separat === void 0 ? ' > ' : _widgetParams$separat,
_widgetParams$rootPat = widgetParams.rootPath,
rootPath = _widgetParams$rootPat === void 0 ? null : _widgetParams$rootPat,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo;
if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
throw new Error(withUsage$g('The `attributes` option expects an array of strings.'));
}
var _attributes = _slicedToArray(attributes, 1),
hierarchicalFacetName = _attributes[0];
return {
getConfiguration: function getConfiguration(currentConfiguration) {
if (currentConfiguration.hierarchicalFacets) {
var isFacetSet = find_1(currentConfiguration.hierarchicalFacets, function (_ref) {
var name = _ref.name;
return name === hierarchicalFacetName;
});
if (isFacetSet) {
_warning(isEqual_1(isFacetSet.attributes, attributes) && isFacetSet.separator === separator, 'Using Breadcrumb and HierarchicalMenu on the same facet with different options overrides the configuration of the HierarchicalMenu.');
return {};
}
}
return {
hierarchicalFacets: [{
attributes: attributes,
name: hierarchicalFacetName,
separator: separator,
rootPath: rootPath
}]
};
},
init: function init(_ref2) {
var createURL = _ref2.createURL,
helper = _ref2.helper,
instantSearchInstance = _ref2.instantSearchInstance;
this._createURL = function (facetValue) {
if (!facetValue) {
var breadcrumb = helper.getHierarchicalFacetBreadcrumb(hierarchicalFacetName);
if (breadcrumb.length > 0) {
return createURL(helper.state.toggleRefinement(hierarchicalFacetName, breadcrumb[0]));
}
}
return createURL(helper.state.toggleRefinement(hierarchicalFacetName, facetValue));
};
this._refine = function (facetValue) {
if (!facetValue) {
var breadcrumb = helper.getHierarchicalFacetBreadcrumb(hierarchicalFacetName);
if (breadcrumb.length > 0) {
helper.toggleRefinement(hierarchicalFacetName, breadcrumb[0]).search();
}
} else {
helper.toggleRefinement(hierarchicalFacetName, facetValue).search();
}
};
renderFn({
createURL: this._createURL,
canRefine: false,
instantSearchInstance: instantSearchInstance,
items: [],
refine: this._refine,
widgetParams: widgetParams
}, true);
},
render: function render(_ref3) {
var instantSearchInstance = _ref3.instantSearchInstance,
results = _ref3.results,
state = _ref3.state;
var _state$hierarchicalFa = _slicedToArray(state.hierarchicalFacets, 1),
facetName = _state$hierarchicalFa[0].name;
var facetValues = results.getFacetValues(facetName);
var data = Array.isArray(facetValues.data) ? facetValues.data : [];
var items = transformItems(shiftItemsValues(prepareItems(data)));
renderFn({
canRefine: items.length > 0,
createURL: this._createURL,
instantSearchInstance: instantSearchInstance,
items: items,
refine: this._refine,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
function prepareItems(data) {
return data.reduce(function (result, currentItem) {
if (currentItem.isRefined) {
result.push({
label: currentItem.name,
value: currentItem.path
});
if (Array.isArray(currentItem.data)) {
result = result.concat(prepareItems(currentItem.data));
}
}
return result;
}, []);
}
function shiftItemsValues(array) {
return array.map(function (x, idx) {
return {
label: x.label,
value: idx + 1 === array.length ? null : array[idx + 1].value
};
});
}
var withUsage$h = createDocumentationMessageGenerator({
name: 'geo-search',
connector: true
});
/**
* @typedef {Object} LatLng
* @property {number} lat The latitude in degrees.
* @property {number} lng The longitude in degrees.
*/
/**
* @typedef {Object} Bounds
* @property {LatLng} northEast The top right corner of the map view.
* @property {LatLng} southWest The bottom left corner of the map view.
*/
/**
* @typedef {Object} CustomGeoSearchWidgetOptions
* @property {boolean} [enableRefineOnMapMove=true] If true, refine will be triggered as you move the map.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* @typedef {Object} GeoSearchRenderingOptions
* @property {Object[]} items The matched hits from Algolia API.
* @property {LatLng} position The current position of the search.
* @property {Bounds} currentRefinement The current bounding box of the search.
* @property {function(Bounds)} refine Sets a bounding box to filter the results from the given map bounds.
* @property {function()} clearMapRefinement Reset the current bounding box refinement.
* @property {function(): boolean} isRefinedWithMap Return true if the current refinement is set with the map bounds.
* @property {function()} toggleRefineOnMapMove Toggle the fact that the user is able to refine on map move.
* @property {function(): boolean} isRefineOnMapMove Return true if the user is able to refine on map move.
* @property {function()} setMapMoveSinceLastRefine Set the fact that the map has moved since the last refinement, should be call on each map move. The call to the function triggers a new rendering only when the value change.
* @property {function(): boolean} hasMapMoveSinceLastRefine Return true if the map has move since the last refinement.
* @property {Object} widgetParams All original `CustomGeoSearchWidgetOptions` forwarded to the `renderFn`.
* @property {LatLng} [position] The current position of the search.
*/
/**
* The **GeoSearch** connector provides the logic to build a widget that will display the results on a map. It also provides a way to search for results based on their position. The connector provides functions to manage the search experience (search on map interaction or control the interaction for example).
*
* @requirements
*
* Note that the GeoSearch connector uses the [geosearch](https://www.algolia.com/doc/guides/searching/geo-search) capabilities of Algolia. Your hits **must** have a `_geoloc` attribute in order to be passed to the rendering function.
*
* Currently, the feature is not compatible with multiple values in the _geoloc attribute.
*
* @type {Connector}
* @param {function(GeoSearchRenderingOptions, boolean)} renderFn Rendering function for the custom **GeoSearch** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomGeoSearchWidgetOptions)} Re-usable widget factory for a custom **GeoSearch** widget.
* @staticExample
* // This example use Leaflet for the rendering, be sure to have the library correctly setup
* // before trying the demo. You can find more details in their documentation (link below).
* // We choose Leaflet for the example but you can use any libraries that you want.
* // See: http://leafletjs.com/examples/quick-start
*
* let map = null;
* let markers = [];
*
* // custom `renderFn` to render the custom GeoSearch widget
* function renderFn(GeoSearchRenderingOptions, isFirstRendering) {
* const { items, widgetParams } = GeoSearchRenderingOptions;
*
* if (isFirstRendering) {
* map = L.map(widgetParams.container);
*
* L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
* attribution:
* '© OpenStreetMap contributors',
* }).addTo(map);
* }
*
* markers.forEach(marker => marker.remove());
*
* markers = items.map(({ _geoloc }) =>
* L.marker([_geoloc.lat, _geoloc.lng]).addTo(map)
* );
*
* if (markers.length) {
* map.fitBounds(L.featureGroup(markers).getBounds());
* }
* }
*
* // connect `renderFn` to GeoSearch logic
* const customGeoSearch = instantsearch.connectors.connectGeoSearch(renderFn);
*
* // mount widget on the page
* search.addWidget(
* customGeoSearch({
* container: document.getElementById('custom-geo-search'),
* })
* );
*/
var connectGeoSearch = function connectGeoSearch(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$h());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _widgetParams$enableR = widgetParams.enableRefineOnMapMove,
enableRefineOnMapMove = _widgetParams$enableR === void 0 ? true : _widgetParams$enableR,
_widgetParams$transfo = widgetParams.transformItems,
transformItems = _widgetParams$transfo === void 0 ? function (items) {
return items;
} : _widgetParams$transfo; // Always trigger this message because the default value was `true`. We can't
// display the message only when the parameter is defined otherwise a user that was
// relying on the default value won't have any information about the changes.
_warning(false, "\nThe option `enableGeolocationWithIP` has been removed from the GeoSearch widget.\nPlease consider using the `Configure` widget instead:\n\nsearch.addWidget(\n configure({\n aroundLatLngViaIP: ".concat(widgetParams.enableGeolocationWithIP || 'true', ",\n })\n);\n\nYou can find more information inside the migration guide:\nhttp://community.algolia.com/instantsearch.js/migration-guide\n "));
_warning(typeof widgetParams.position === 'undefined', "\nThe option `position` has been removed from the GeoSearch widget.\nPlease consider using the `Configure` widget instead:\n\nsearch.addWidget(\n configure({\n aroundLatLng: '".concat(widgetParams.position && widgetParams.position.lat, ", ").concat(widgetParams.position && widgetParams.position.lng, "',\n })\n);\n\nYou can find more information inside the migration guide:\nhttp://community.algolia.com/instantsearch.js/migration-guide\n "));
_warning(typeof widgetParams.radius === 'undefined', "\nThe option `radius` has been removed from the GeoSearch widget.\nPlease consider using the `Configure` widget instead:\n\nsearch.addWidget(\n configure({\n aroundRadius: ".concat(widgetParams.radius, ",\n })\n);\n\nYou can find more information inside the migration guide:\n\nhttp://community.algolia.com/instantsearch.js/migration-guide\n "));
_warning(typeof widgetParams.precision === 'undefined', "\nThe option `precision` has been removed from the GeoSearch widget.\nPlease consider using the `Configure` widget instead:\n\nsearch.addWidget(\n configure({\n aroundPrecision: ".concat(widgetParams.precision, ",\n })\n);\n\nYou can find more information inside the migration guide:\n\nhttp://community.algolia.com/instantsearch.js/migration-guide\n "));
var widgetState = {
isRefineOnMapMove: enableRefineOnMapMove,
hasMapMoveSinceLastRefine: false,
lastRefinePosition: '',
lastRefineBoundingBox: '',
internalToggleRefineOnMapMove: noop_1,
internalSetMapMoveSinceLastRefine: noop_1
};
var getPositionFromState = function getPositionFromState(state) {
return state.aroundLatLng && aroundLatLngToPosition(state.aroundLatLng);
};
var getCurrentRefinementFromState = function getCurrentRefinementFromState(state) {
return state.insideBoundingBox && insideBoundingBoxToBoundingBox(state.insideBoundingBox);
};
var refine = function refine(helper) {
return function (_ref) {
var ne = _ref.northEast,
sw = _ref.southWest;
var boundingBox = [ne.lat, ne.lng, sw.lat, sw.lng].join();
helper.setQueryParameter('insideBoundingBox', boundingBox).search();
widgetState.hasMapMoveSinceLastRefine = false;
widgetState.lastRefineBoundingBox = boundingBox;
};
};
var clearMapRefinement = function clearMapRefinement(helper) {
return function () {
helper.setQueryParameter('insideBoundingBox').search();
};
};
var isRefinedWithMap = function isRefinedWithMap(state) {
return function () {
return Boolean(state.insideBoundingBox);
};
};
var toggleRefineOnMapMove = function toggleRefineOnMapMove() {
return widgetState.internalToggleRefineOnMapMove();
};
var createInternalToggleRefinementOnMapMove = function createInternalToggleRefinementOnMapMove(render, args) {
return function () {
widgetState.isRefineOnMapMove = !widgetState.isRefineOnMapMove;
render(args);
};
};
var isRefineOnMapMove = function isRefineOnMapMove() {
return widgetState.isRefineOnMapMove;
};
var setMapMoveSinceLastRefine = function setMapMoveSinceLastRefine() {
return widgetState.internalSetMapMoveSinceLastRefine();
};
var createInternalSetMapMoveSinceLastRefine = function createInternalSetMapMoveSinceLastRefine(render, args) {
return function () {
var shouldTriggerRender = widgetState.hasMapMoveSinceLastRefine !== true;
widgetState.hasMapMoveSinceLastRefine = true;
if (shouldTriggerRender) {
render(args);
}
};
};
var hasMapMoveSinceLastRefine = function hasMapMoveSinceLastRefine() {
return widgetState.hasMapMoveSinceLastRefine;
};
var init = function init(initArgs) {
var state = initArgs.state,
helper = initArgs.helper,
instantSearchInstance = initArgs.instantSearchInstance;
var isFirstRendering = true;
widgetState.internalToggleRefineOnMapMove = createInternalToggleRefinementOnMapMove(noop_1, initArgs);
widgetState.internalSetMapMoveSinceLastRefine = createInternalSetMapMoveSinceLastRefine(noop_1, initArgs);
renderFn({
items: [],
position: getPositionFromState(state),
currentRefinement: getCurrentRefinementFromState(state),
refine: refine(helper),
clearMapRefinement: clearMapRefinement(helper),
isRefinedWithMap: isRefinedWithMap(state),
toggleRefineOnMapMove: toggleRefineOnMapMove,
isRefineOnMapMove: isRefineOnMapMove,
setMapMoveSinceLastRefine: setMapMoveSinceLastRefine,
hasMapMoveSinceLastRefine: hasMapMoveSinceLastRefine,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, isFirstRendering);
};
var render = function render(renderArgs) {
var results = renderArgs.results,
helper = renderArgs.helper,
instantSearchInstance = renderArgs.instantSearchInstance;
var isFirstRendering = false; // We don't use the state provided by the render function because we need
// to be sure that the state is the latest one for the following condition
var state = helper.getState();
var positionChangedSinceLastRefine = Boolean(state.aroundLatLng) && Boolean(widgetState.lastRefinePosition) && state.aroundLatLng !== widgetState.lastRefinePosition;
var boundingBoxChangedSinceLastRefine = !state.insideBoundingBox && Boolean(widgetState.lastRefineBoundingBox) && state.insideBoundingBox !== widgetState.lastRefineBoundingBox;
if (positionChangedSinceLastRefine || boundingBoxChangedSinceLastRefine) {
widgetState.hasMapMoveSinceLastRefine = false;
}
widgetState.lastRefinePosition = state.aroundLatLng || '';
widgetState.lastRefineBoundingBox = state.insideBoundingBox || '';
widgetState.internalToggleRefineOnMapMove = createInternalToggleRefinementOnMapMove(render, renderArgs);
widgetState.internalSetMapMoveSinceLastRefine = createInternalSetMapMoveSinceLastRefine(render, renderArgs);
var items = transformItems(results.hits.filter(function (hit) {
return hit._geoloc;
}));
renderFn({
items: items,
position: getPositionFromState(state),
currentRefinement: getCurrentRefinementFromState(state),
refine: refine(helper),
clearMapRefinement: clearMapRefinement(helper),
isRefinedWithMap: isRefinedWithMap(state),
toggleRefineOnMapMove: toggleRefineOnMapMove,
isRefineOnMapMove: isRefineOnMapMove,
setMapMoveSinceLastRefine: setMapMoveSinceLastRefine,
hasMapMoveSinceLastRefine: hasMapMoveSinceLastRefine,
widgetParams: widgetParams,
instantSearchInstance: instantSearchInstance
}, isFirstRendering);
};
return {
init: init,
render: render,
dispose: function dispose(_ref2) {
var state = _ref2.state;
unmountFn();
return state.setQueryParameter('insideBoundingBox');
},
getWidgetState: function getWidgetState(uiState, _ref3) {
var searchParameters = _ref3.searchParameters;
var boundingBox = searchParameters.insideBoundingBox;
if (!boundingBox || uiState && uiState.geoSearch && uiState.geoSearch.boundingBox === boundingBox) {
return uiState;
}
return _objectSpread({}, uiState, {
geoSearch: {
boundingBox: boundingBox
}
});
},
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref4) {
var uiState = _ref4.uiState;
if (!uiState || !uiState.geoSearch) {
return searchParameters.setQueryParameter('insideBoundingBox');
}
return searchParameters.setQueryParameter('insideBoundingBox', uiState.geoSearch.boundingBox);
}
};
};
};
var withUsage$i = createDocumentationMessageGenerator({
name: 'powered-by',
connector: true
});
/**
* @typedef {Object} PoweredByWidgetOptions
* @property {string} [theme] The theme of the logo ("light" or "dark").
* @property {string} [url] The URL to redirect to.
*/
/**
* @typedef {Object} PoweredByRenderingOptions
* @property {Object} widgetParams All original `PoweredByWidgetOptions` forwarded to the `renderFn`.
*/
/**
* **PoweredBy** connector provides the logic to build a custom widget that will displays
* the logo to redirect to Algolia.
*
* @type {Connector}
* @param {function(PoweredByRenderingOptions, boolean)} renderFn Rendering function for the custom **PoweredBy** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function} Re-usable widget factory for a custom **PoweredBy** widget.
*/
function connectPoweredBy(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$i());
var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat(typeof window !== 'undefined' && window.location ? window.location.hostname : '', "&") + 'utm_campaign=poweredby';
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _widgetParams$url = widgetParams.url,
url = _widgetParams$url === void 0 ? defaultUrl : _widgetParams$url;
return {
init: function init() {
renderFn({
url: url,
widgetParams: widgetParams
}, true);
},
render: function render() {
renderFn({
url: url,
widgetParams: widgetParams
}, false);
},
dispose: function dispose() {
unmountFn();
}
};
};
}
var withUsage$j = createDocumentationMessageGenerator({
name: 'configure',
connector: true
});
/**
* @typedef {Object} CustomConfigureWidgetOptions
* @property {Object} searchParameters The Configure widget options are search parameters
*/
/**
* @typedef {Object} ConfigureRenderingOptions
* @property {function(searchParameters: Object)} refine Sets new `searchParameters` and trigger a search.
* @property {Object} widgetParams All original `CustomConfigureWidgetOptions` forwarded to the `renderFn`.
*/
/**
* The **Configure** connector provides the logic to build a custom widget
* that will give you ability to override or force some search parameters sent to Algolia API.
*
* @type {Connector}
* @param {function(ConfigureRenderingOptions)} renderFn Rendering function for the custom **Configure** Widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomConfigureWidgetOptions)} Re-usable widget factory for a custom **Configure** widget.
*/
function connectConfigure() {
var renderFn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop_1;
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop_1;
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (!isPlainObject_1(widgetParams.searchParameters)) {
throw new Error(withUsage$j('The `searchParameters` option expects an object.'));
}
return {
getConfiguration: function getConfiguration() {
return widgetParams.searchParameters;
},
init: function init(_ref) {
var helper = _ref.helper;
this._refine = this.refine(helper);
renderFn({
refine: this._refine,
widgetParams: widgetParams
}, true);
},
refine: function refine(helper) {
var _this = this;
return function (searchParameters) {
// merge new `searchParameters` with the ones set from other widgets
var actualState = _this.removeSearchParameters(helper.getState());
var nextSearchParameters = enhanceConfiguration({})(_objectSpread({}, actualState), {
getConfiguration: function getConfiguration() {
return searchParameters;
}
}); // trigger a search with the new merged searchParameters
helper.setState(nextSearchParameters).search(); // update original `widgetParams.searchParameters` to the new refined one
widgetParams.searchParameters = searchParameters;
};
},
render: function render() {
renderFn({
refine: this._refine,
widgetParams: widgetParams
}, false);
},
dispose: function dispose(_ref2) {
var state = _ref2.state;
unmountFn();
return this.removeSearchParameters(state);
},
removeSearchParameters: function removeSearchParameters(state) {
// widgetParams are assumed 'controlled',
// so they override whatever other widgets give the state
return state.mutateMe(function (mutableState) {
Object.keys(widgetParams.searchParameters).forEach(function (key) {
delete mutableState[key];
});
});
}
};
};
}
var withUsage$k = createDocumentationMessageGenerator({
name: 'autocomplete',
connector: true
});
/**
* @typedef {Object} Index
* @property {string} index Name of the index.
* @property {string} label Label of the index (for display purpose).
* @property {Object[]} hits The hits resolved from the index matching the query.
* @property {Object} results The full results object from Algolia API.
*/
/**
* @typedef {Object} AutocompleteRenderingOptions
* @property {Index[]} indices The indices you provided with their hits and results and the main index as first position.
* @property {function(string)} refine Search into the indices with the query provided.
* @property {string} currentRefinement The actual value of the query.
* @property {Object} widgetParams All original widget options forwarded to the `renderFn`.
*/
/**
* @typedef {Object} CustomAutocompleteWidgetOptions
* @property {{value: string, label: string}[]} [indices = []] Name of the others indices to search into.
* @property {boolean} [escapeHTML = true] If true, escape HTML tags from `hits[i]._highlightResult`.
*/
/**
* **Autocomplete** connector provides the logic to build a widget that will give the user the ability to search into multiple indices.
*
* This connector provides a `refine()` function to search for a query and a `currentRefinement` as the current query used to search.
* @type {Connector}
* @param {function(AutocompleteRenderingOptions, boolean)} renderFn Rendering function for the custom **Autocomplete** widget.
* @param {function} unmountFn Unmount function called when the widget is disposed.
* @return {function(CustomAutocompleteWidgetOptions)} Re-usable widget factory for a custom **Autocomplete** widget.
*/
function connectAutocomplete(renderFn, unmountFn) {
checkRendering(renderFn, withUsage$k());
return function () {
var widgetParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _widgetParams$escapeH = widgetParams.escapeHTML,
escapeHTML = _widgetParams$escapeH === void 0 ? true : _widgetParams$escapeH,
_widgetParams$indices = widgetParams.indices,
indices = _widgetParams$indices === void 0 ? [] : _widgetParams$indices; // user passed a wrong `indices` option type
if (!Array.isArray(indices)) {
throw new Error(withUsage$k('The `indices` option expects an array of objects.'));
}
return {
getConfiguration: function getConfiguration() {
return escapeHTML ? TAG_PLACEHOLDER : undefined;
},
init: function init(_ref) {
var _this = this;
var instantSearchInstance = _ref.instantSearchInstance,
helper = _ref.helper;
this._refine = this.refine(helper);
this.indices = [{
helper: helper,
label: 'primary',
index: helper.getIndex(),
results: undefined,
hits: []
}]; // add additionnal indices into `this.indices`
indices.forEach(function (_ref2) {
var label = _ref2.label,
value = _ref2.value;
var derivedHelper = helper.derive(function (searchParameters) {
return searchParameters.setIndex(value);
});
_this.indices.push({
label: label,
index: value,
helper: derivedHelper,
results: undefined,
hits: []
}); // update results then trigger render after a search from any helper
derivedHelper.on('result', function (results) {
return _this.saveResults({
results: results,
label: label
});
});
});
this.instantSearchInstance = instantSearchInstance;
this.renderWithAllIndices({
isFirstRendering: true
});
},
saveResults: function saveResults(_ref3) {
var results = _ref3.results,
label = _ref3.label;
var derivedIndex = this.indices.find(function (i) {
return i.label === label;
});
if (escapeHTML && results && results.hits && results.hits.length > 0) {
results.hits = escapeHits(results.hits);
}
derivedIndex.results = results;
derivedIndex.hits = results && results.hits && Array.isArray(results.hits) ? results.hits : [];
this.renderWithAllIndices();
},
refine: function refine(helper) {
return function (query) {
return helper.setQuery(query).search();
};
},
render: function render(_ref4) {
var results = _ref4.results;
this.saveResults({
results: results,
label: this.indices[0].label
});
},
renderWithAllIndices: function renderWithAllIndices() {
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref5$isFirstRenderin = _ref5.isFirstRendering,
isFirstRendering = _ref5$isFirstRenderin === void 0 ? false : _ref5$isFirstRenderin;
var currentRefinement = this.indices[0].helper.state.query;
renderFn({
widgetParams: widgetParams,
currentRefinement: currentRefinement,
// we do not want to provide the `helper` to the end-user
indices: this.indices.map(function (_ref6) {
var index = _ref6.index,
label = _ref6.label,
hits = _ref6.hits,
results = _ref6.results;
return {
index: index,
label: label,
hits: hits,
results: results
};
}),
instantSearchInstance: this.instantSearchInstance,
refine: this._refine
}, isFirstRendering);
},
dispose: function dispose() {
// detach every derived indices from the main helper instance
this.indices.slice(1).forEach(function (_ref7) {
var helper = _ref7.helper;
return helper.detach();
});
unmountFn();
}
};
};
}
var connectors = /*#__PURE__*/Object.freeze({
connectClearRefinements: connectClearRefinements,
connectCurrentRefinements: connectCurrentRefinements,
connectHierarchicalMenu: connectHierarchicalMenu,
connectHits: connectHits,
connectHitsPerPage: connectHitsPerPage,
connectInfiniteHits: connectInfiniteHits,
connectMenu: connectMenu,
connectNumericMenu: connectNumericMenu,
connectPagination: connectPagination,
connectRange: connectRange,
connectRefinementList: connectRefinementList,
connectSearchBox: connectSearchBox,
connectSortBy: connectSortBy,
connectRatingMenu: connectRatingMenu,
connectStats: connectStats,
connectToggleRefinement: connectToggleRefinement,
connectBreadcrumb: connectBreadcrumb,
connectGeoSearch: connectGeoSearch,
connectPoweredBy: connectPoweredBy,
connectConfigure: connectConfigure,
connectAutocomplete: connectAutocomplete
});
var reactIs_production_min = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports,"__esModule",{value:!0});
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?Symbol.for("react.memo"):
60115,r=b?Symbol.for("react.lazy"):60116;function t(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case h:return a;default:return u}}case r:case q:case d:return u}}}function v(a){return t(a)===m}exports.typeOf=t;exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;
exports.Fragment=e;exports.Lazy=r;exports.Memo=q;exports.Portal=d;exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p;exports.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||"object"===typeof a&&null!==a&&(a.$$typeof===r||a.$$typeof===q||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n)};exports.isAsyncMode=function(a){return v(a)||t(a)===l};exports.isConcurrentMode=v;exports.isContextConsumer=function(a){return t(a)===k};
exports.isContextProvider=function(a){return t(a)===h};exports.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return t(a)===n};exports.isFragment=function(a){return t(a)===e};exports.isLazy=function(a){return t(a)===r};exports.isMemo=function(a){return t(a)===q};exports.isPortal=function(a){return t(a)===d};exports.isProfiler=function(a){return t(a)===g};exports.isStrictMode=function(a){return t(a)===f};
exports.isSuspense=function(a){return t(a)===p};
});
unwrapExports(reactIs_production_min);
var reactIs_production_min_1 = reactIs_production_min.typeOf;
var reactIs_production_min_2 = reactIs_production_min.AsyncMode;
var reactIs_production_min_3 = reactIs_production_min.ConcurrentMode;
var reactIs_production_min_4 = reactIs_production_min.ContextConsumer;
var reactIs_production_min_5 = reactIs_production_min.ContextProvider;
var reactIs_production_min_6 = reactIs_production_min.Element;
var reactIs_production_min_7 = reactIs_production_min.ForwardRef;
var reactIs_production_min_8 = reactIs_production_min.Fragment;
var reactIs_production_min_9 = reactIs_production_min.Lazy;
var reactIs_production_min_10 = reactIs_production_min.Memo;
var reactIs_production_min_11 = reactIs_production_min.Portal;
var reactIs_production_min_12 = reactIs_production_min.Profiler;
var reactIs_production_min_13 = reactIs_production_min.StrictMode;
var reactIs_production_min_14 = reactIs_production_min.Suspense;
var reactIs_production_min_15 = reactIs_production_min.isValidElementType;
var reactIs_production_min_16 = reactIs_production_min.isAsyncMode;
var reactIs_production_min_17 = reactIs_production_min.isConcurrentMode;
var reactIs_production_min_18 = reactIs_production_min.isContextConsumer;
var reactIs_production_min_19 = reactIs_production_min.isContextProvider;
var reactIs_production_min_20 = reactIs_production_min.isElement;
var reactIs_production_min_21 = reactIs_production_min.isForwardRef;
var reactIs_production_min_22 = reactIs_production_min.isFragment;
var reactIs_production_min_23 = reactIs_production_min.isLazy;
var reactIs_production_min_24 = reactIs_production_min.isMemo;
var reactIs_production_min_25 = reactIs_production_min.isPortal;
var reactIs_production_min_26 = reactIs_production_min.isProfiler;
var reactIs_production_min_27 = reactIs_production_min.isStrictMode;
var reactIs_production_min_28 = reactIs_production_min.isSuspense;
var reactIs_development = createCommonjsModule(function (module, exports) {
});
unwrapExports(reactIs_development);
var reactIs_development_1 = reactIs_development.typeOf;
var reactIs_development_2 = reactIs_development.AsyncMode;
var reactIs_development_3 = reactIs_development.ConcurrentMode;
var reactIs_development_4 = reactIs_development.ContextConsumer;
var reactIs_development_5 = reactIs_development.ContextProvider;
var reactIs_development_6 = reactIs_development.Element;
var reactIs_development_7 = reactIs_development.ForwardRef;
var reactIs_development_8 = reactIs_development.Fragment;
var reactIs_development_9 = reactIs_development.Lazy;
var reactIs_development_10 = reactIs_development.Memo;
var reactIs_development_11 = reactIs_development.Portal;
var reactIs_development_12 = reactIs_development.Profiler;
var reactIs_development_13 = reactIs_development.StrictMode;
var reactIs_development_14 = reactIs_development.Suspense;
var reactIs_development_15 = reactIs_development.isValidElementType;
var reactIs_development_16 = reactIs_development.isAsyncMode;
var reactIs_development_17 = reactIs_development.isConcurrentMode;
var reactIs_development_18 = reactIs_development.isContextConsumer;
var reactIs_development_19 = reactIs_development.isContextProvider;
var reactIs_development_20 = reactIs_development.isElement;
var reactIs_development_21 = reactIs_development.isForwardRef;
var reactIs_development_22 = reactIs_development.isFragment;
var reactIs_development_23 = reactIs_development.isLazy;
var reactIs_development_24 = reactIs_development.isMemo;
var reactIs_development_25 = reactIs_development.isPortal;
var reactIs_development_26 = reactIs_development.isProfiler;
var reactIs_development_27 = reactIs_development.isStrictMode;
var reactIs_development_28 = reactIs_development.isSuspense;
var reactIs = createCommonjsModule(function (module) {
{
module.exports = reactIs_production_min;
}
});
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty$h = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty$h.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
var has$3 = Function.call.bind(Object.prototype.hasOwnProperty);
function emptyFunction() {}
function emptyFunctionWithReset() {}
emptyFunctionWithReset.resetWarningCache = emptyFunction;
var factoryWithThrowingShims = function() {
function shim(props, propName, componentName, location, propFullName, secret) {
if (secret === ReactPropTypesSecret_1) {
// It is still safe when called from React.
return;
}
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use PropTypes.checkPropTypes() to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
err.name = 'Invariant Violation';
throw err;
} shim.isRequired = shim;
function getShim() {
return shim;
} // Important!
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
var ReactPropTypes = {
array: shim,
bool: shim,
func: shim,
number: shim,
object: shim,
string: shim,
symbol: shim,
any: shim,
arrayOf: getShim,
element: shim,
elementType: shim,
instanceOf: getShim,
node: shim,
objectOf: getShim,
oneOf: getShim,
oneOfType: getShim,
shape: getShim,
exact: getShim,
checkPropTypes: emptyFunctionWithReset,
resetWarningCache: emptyFunction
};
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
var propTypes = createCommonjsModule(function (module) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
{
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = factoryWithThrowingShims();
}
});
var VNode = function VNode() {};
var options = {};
var stack = [];
var EMPTY_CHILDREN = [];
function h(nodeName, attributes) {
var children = EMPTY_CHILDREN,
lastSimple,
child,
simple,
i;
for (i = arguments.length; i-- > 2;) {
stack.push(arguments[i]);
}
if (attributes && attributes.children != null) {
if (!stack.length) stack.push(attributes.children);
delete attributes.children;
}
while (stack.length) {
if ((child = stack.pop()) && child.pop !== undefined) {
for (i = child.length; i--;) {
stack.push(child[i]);
}
} else {
if (typeof child === 'boolean') child = null;
if (simple = typeof nodeName !== 'function') {
if (child == null) child = '';else if (typeof child === 'number') child = String(child);else if (typeof child !== 'string') simple = false;
}
if (simple && lastSimple) {
children[children.length - 1] += child;
} else if (children === EMPTY_CHILDREN) {
children = [child];
} else {
children.push(child);
}
lastSimple = simple;
}
}
var p = new VNode();
p.nodeName = nodeName;
p.children = children;
p.attributes = attributes == null ? undefined : attributes;
p.key = attributes == null ? undefined : attributes.key;
if (options.vnode !== undefined) options.vnode(p);
return p;
}
function extend(obj, props) {
for (var i in props) {
obj[i] = props[i];
}return obj;
}
function applyRef(ref, value) {
if (ref != null) {
if (typeof ref == 'function') ref(value);else ref.current = value;
}
}
var defer = typeof Promise == 'function' ? Promise.resolve().then.bind(Promise.resolve()) : setTimeout;
function cloneElement(vnode, props) {
return h(vnode.nodeName, extend(extend({}, vnode.attributes), props), arguments.length > 2 ? [].slice.call(arguments, 2) : vnode.children);
}
var IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i;
var items = [];
function enqueueRender(component) {
if (!component._dirty && (component._dirty = true) && items.push(component) == 1) {
(defer)(rerender);
}
}
function rerender() {
var p;
while (p = items.pop()) {
if (p._dirty) renderComponent(p);
}
}
function isSameNodeType(node, vnode, hydrating) {
if (typeof vnode === 'string' || typeof vnode === 'number') {
return node.splitText !== undefined;
}
if (typeof vnode.nodeName === 'string') {
return !node._componentConstructor && isNamedNode(node, vnode.nodeName);
}
return hydrating || node._componentConstructor === vnode.nodeName;
}
function isNamedNode(node, nodeName) {
return node.normalizedNodeName === nodeName || node.nodeName.toLowerCase() === nodeName.toLowerCase();
}
function getNodeProps(vnode) {
var props = extend({}, vnode.attributes);
props.children = vnode.children;
var defaultProps = vnode.nodeName.defaultProps;
if (defaultProps !== undefined) {
for (var i in defaultProps) {
if (props[i] === undefined) {
props[i] = defaultProps[i];
}
}
}
return props;
}
function createNode(nodeName, isSvg) {
var node = isSvg ? document.createElementNS('http://www.w3.org/2000/svg', nodeName) : document.createElement(nodeName);
node.normalizedNodeName = nodeName;
return node;
}
function removeNode(node) {
var parentNode = node.parentNode;
if (parentNode) parentNode.removeChild(node);
}
function setAccessor(node, name, old, value, isSvg) {
if (name === 'className') name = 'class';
if (name === 'key') ; else if (name === 'ref') {
applyRef(old, null);
applyRef(value, node);
} else if (name === 'class' && !isSvg) {
node.className = value || '';
} else if (name === 'style') {
if (!value || typeof value === 'string' || typeof old === 'string') {
node.style.cssText = value || '';
}
if (value && typeof value === 'object') {
if (typeof old !== 'string') {
for (var i in old) {
if (!(i in value)) node.style[i] = '';
}
}
for (var i in value) {
node.style[i] = typeof value[i] === 'number' && IS_NON_DIMENSIONAL.test(i) === false ? value[i] + 'px' : value[i];
}
}
} else if (name === 'dangerouslySetInnerHTML') {
if (value) node.innerHTML = value.__html || '';
} else if (name[0] == 'o' && name[1] == 'n') {
var useCapture = name !== (name = name.replace(/Capture$/, ''));
name = name.toLowerCase().substring(2);
if (value) {
if (!old) node.addEventListener(name, eventProxy, useCapture);
} else {
node.removeEventListener(name, eventProxy, useCapture);
}
(node._listeners || (node._listeners = {}))[name] = value;
} else if (name !== 'list' && name !== 'type' && !isSvg && name in node) {
try {
node[name] = value == null ? '' : value;
} catch (e) {}
if ((value == null || value === false) && name != 'spellcheck') node.removeAttribute(name);
} else {
var ns = isSvg && name !== (name = name.replace(/^xlink:?/, ''));
if (value == null || value === false) {
if (ns) node.removeAttributeNS('http://www.w3.org/1999/xlink', name.toLowerCase());else node.removeAttribute(name);
} else if (typeof value !== 'function') {
if (ns) node.setAttributeNS('http://www.w3.org/1999/xlink', name.toLowerCase(), value);else node.setAttribute(name, value);
}
}
}
function eventProxy(e) {
return this._listeners[e.type](options.event && options.event(e) || e);
}
var mounts = [];
var diffLevel = 0;
var isSvgMode = false;
var hydrating = false;
function flushMounts() {
var c;
while (c = mounts.shift()) {
if (c.componentDidMount) c.componentDidMount();
}
}
function diff(dom, vnode, context, mountAll, parent, componentRoot) {
if (!diffLevel++) {
isSvgMode = parent != null && parent.ownerSVGElement !== undefined;
hydrating = dom != null && !('__preactattr_' in dom);
}
var ret = idiff(dom, vnode, context, mountAll, componentRoot);
if (parent && ret.parentNode !== parent) parent.appendChild(ret);
if (! --diffLevel) {
hydrating = false;
if (!componentRoot) flushMounts();
}
return ret;
}
function idiff(dom, vnode, context, mountAll, componentRoot) {
var out = dom,
prevSvgMode = isSvgMode;
if (vnode == null || typeof vnode === 'boolean') vnode = '';
if (typeof vnode === 'string' || typeof vnode === 'number') {
if (dom && dom.splitText !== undefined && dom.parentNode && (!dom._component || componentRoot)) {
if (dom.nodeValue != vnode) {
dom.nodeValue = vnode;
}
} else {
out = document.createTextNode(vnode);
if (dom) {
if (dom.parentNode) dom.parentNode.replaceChild(out, dom);
recollectNodeTree(dom, true);
}
}
out['__preactattr_'] = true;
return out;
}
var vnodeName = vnode.nodeName;
if (typeof vnodeName === 'function') {
return buildComponentFromVNode(dom, vnode, context, mountAll);
}
isSvgMode = vnodeName === 'svg' ? true : vnodeName === 'foreignObject' ? false : isSvgMode;
vnodeName = String(vnodeName);
if (!dom || !isNamedNode(dom, vnodeName)) {
out = createNode(vnodeName, isSvgMode);
if (dom) {
while (dom.firstChild) {
out.appendChild(dom.firstChild);
}
if (dom.parentNode) dom.parentNode.replaceChild(out, dom);
recollectNodeTree(dom, true);
}
}
var fc = out.firstChild,
props = out['__preactattr_'],
vchildren = vnode.children;
if (props == null) {
props = out['__preactattr_'] = {};
for (var a = out.attributes, i = a.length; i--;) {
props[a[i].name] = a[i].value;
}
}
if (!hydrating && vchildren && vchildren.length === 1 && typeof vchildren[0] === 'string' && fc != null && fc.splitText !== undefined && fc.nextSibling == null) {
if (fc.nodeValue != vchildren[0]) {
fc.nodeValue = vchildren[0];
}
} else if (vchildren && vchildren.length || fc != null) {
innerDiffNode(out, vchildren, context, mountAll, hydrating || props.dangerouslySetInnerHTML != null);
}
diffAttributes(out, vnode.attributes, props);
isSvgMode = prevSvgMode;
return out;
}
function innerDiffNode(dom, vchildren, context, mountAll, isHydrating) {
var originalChildren = dom.childNodes,
children = [],
keyed = {},
keyedLen = 0,
min = 0,
len = originalChildren.length,
childrenLen = 0,
vlen = vchildren ? vchildren.length : 0,
j,
c,
f,
vchild,
child;
if (len !== 0) {
for (var i = 0; i < len; i++) {
var _child = originalChildren[i],
props = _child['__preactattr_'],
key = vlen && props ? _child._component ? _child._component.__key : props.key : null;
if (key != null) {
keyedLen++;
keyed[key] = _child;
} else if (props || (_child.splitText !== undefined ? isHydrating ? _child.nodeValue.trim() : true : isHydrating)) {
children[childrenLen++] = _child;
}
}
}
if (vlen !== 0) {
for (var i = 0; i < vlen; i++) {
vchild = vchildren[i];
child = null;
var key = vchild.key;
if (key != null) {
if (keyedLen && keyed[key] !== undefined) {
child = keyed[key];
keyed[key] = undefined;
keyedLen--;
}
} else if (min < childrenLen) {
for (j = min; j < childrenLen; j++) {
if (children[j] !== undefined && isSameNodeType(c = children[j], vchild, isHydrating)) {
child = c;
children[j] = undefined;
if (j === childrenLen - 1) childrenLen--;
if (j === min) min++;
break;
}
}
}
child = idiff(child, vchild, context, mountAll);
f = originalChildren[i];
if (child && child !== dom && child !== f) {
if (f == null) {
dom.appendChild(child);
} else if (child === f.nextSibling) {
removeNode(f);
} else {
dom.insertBefore(child, f);
}
}
}
}
if (keyedLen) {
for (var i in keyed) {
if (keyed[i] !== undefined) recollectNodeTree(keyed[i], false);
}
}
while (min <= childrenLen) {
if ((child = children[childrenLen--]) !== undefined) recollectNodeTree(child, false);
}
}
function recollectNodeTree(node, unmountOnly) {
var component = node._component;
if (component) {
unmountComponent(component);
} else {
if (node['__preactattr_'] != null) applyRef(node['__preactattr_'].ref, null);
if (unmountOnly === false || node['__preactattr_'] == null) {
removeNode(node);
}
removeChildren(node);
}
}
function removeChildren(node) {
node = node.lastChild;
while (node) {
var next = node.previousSibling;
recollectNodeTree(node, true);
node = next;
}
}
function diffAttributes(dom, attrs, old) {
var name;
for (name in old) {
if (!(attrs && attrs[name] != null) && old[name] != null) {
setAccessor(dom, name, old[name], old[name] = undefined, isSvgMode);
}
}
for (name in attrs) {
if (name !== 'children' && name !== 'innerHTML' && (!(name in old) || attrs[name] !== (name === 'value' || name === 'checked' ? dom[name] : old[name]))) {
setAccessor(dom, name, old[name], old[name] = attrs[name], isSvgMode);
}
}
}
var recyclerComponents = [];
function createComponent(Ctor, props, context) {
var inst,
i = recyclerComponents.length;
if (Ctor.prototype && Ctor.prototype.render) {
inst = new Ctor(props, context);
Component.call(inst, props, context);
} else {
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
}
while (i--) {
if (recyclerComponents[i].constructor === Ctor) {
inst.nextBase = recyclerComponents[i].nextBase;
recyclerComponents.splice(i, 1);
return inst;
}
}
return inst;
}
function doRender(props, state, context) {
return this.constructor(props, context);
}
function setComponentProps(component, props, renderMode, context, mountAll) {
if (component._disable) return;
component._disable = true;
component.__ref = props.ref;
component.__key = props.key;
delete props.ref;
delete props.key;
if (typeof component.constructor.getDerivedStateFromProps === 'undefined') {
if (!component.base || mountAll) {
if (component.componentWillMount) component.componentWillMount();
} else if (component.componentWillReceiveProps) {
component.componentWillReceiveProps(props, context);
}
}
if (context && context !== component.context) {
if (!component.prevContext) component.prevContext = component.context;
component.context = context;
}
if (!component.prevProps) component.prevProps = component.props;
component.props = props;
component._disable = false;
if (renderMode !== 0) {
if (renderMode === 1 || options.syncComponentUpdates !== false || !component.base) {
renderComponent(component, 1, mountAll);
} else {
enqueueRender(component);
}
}
applyRef(component.__ref, component);
}
function renderComponent(component, renderMode, mountAll, isChild) {
if (component._disable) return;
var props = component.props,
state = component.state,
context = component.context,
previousProps = component.prevProps || props,
previousState = component.prevState || state,
previousContext = component.prevContext || context,
isUpdate = component.base,
nextBase = component.nextBase,
initialBase = isUpdate || nextBase,
initialChildComponent = component._component,
skip = false,
snapshot = previousContext,
rendered,
inst,
cbase;
if (component.constructor.getDerivedStateFromProps) {
state = extend(extend({}, state), component.constructor.getDerivedStateFromProps(props, state));
component.state = state;
}
if (isUpdate) {
component.props = previousProps;
component.state = previousState;
component.context = previousContext;
if (renderMode !== 2 && component.shouldComponentUpdate && component.shouldComponentUpdate(props, state, context) === false) {
skip = true;
} else if (component.componentWillUpdate) {
component.componentWillUpdate(props, state, context);
}
component.props = props;
component.state = state;
component.context = context;
}
component.prevProps = component.prevState = component.prevContext = component.nextBase = null;
component._dirty = false;
if (!skip) {
rendered = component.render(props, state, context);
if (component.getChildContext) {
context = extend(extend({}, context), component.getChildContext());
}
if (isUpdate && component.getSnapshotBeforeUpdate) {
snapshot = component.getSnapshotBeforeUpdate(previousProps, previousState);
}
var childComponent = rendered && rendered.nodeName,
toUnmount,
base;
if (typeof childComponent === 'function') {
var childProps = getNodeProps(rendered);
inst = initialChildComponent;
if (inst && inst.constructor === childComponent && childProps.key == inst.__key) {
setComponentProps(inst, childProps, 1, context, false);
} else {
toUnmount = inst;
component._component = inst = createComponent(childComponent, childProps, context);
inst.nextBase = inst.nextBase || nextBase;
inst._parentComponent = component;
setComponentProps(inst, childProps, 0, context, false);
renderComponent(inst, 1, mountAll, true);
}
base = inst.base;
} else {
cbase = initialBase;
toUnmount = initialChildComponent;
if (toUnmount) {
cbase = component._component = null;
}
if (initialBase || renderMode === 1) {
if (cbase) cbase._component = null;
base = diff(cbase, rendered, context, mountAll || !isUpdate, initialBase && initialBase.parentNode, true);
}
}
if (initialBase && base !== initialBase && inst !== initialChildComponent) {
var baseParent = initialBase.parentNode;
if (baseParent && base !== baseParent) {
baseParent.replaceChild(base, initialBase);
if (!toUnmount) {
initialBase._component = null;
recollectNodeTree(initialBase, false);
}
}
}
if (toUnmount) {
unmountComponent(toUnmount);
}
component.base = base;
if (base && !isChild) {
var componentRef = component,
t = component;
while (t = t._parentComponent) {
(componentRef = t).base = base;
}
base._component = componentRef;
base._componentConstructor = componentRef.constructor;
}
}
if (!isUpdate || mountAll) {
mounts.push(component);
} else if (!skip) {
if (component.componentDidUpdate) {
component.componentDidUpdate(previousProps, previousState, snapshot);
}
}
while (component._renderCallbacks.length) {
component._renderCallbacks.pop().call(component);
}if (!diffLevel && !isChild) flushMounts();
}
function buildComponentFromVNode(dom, vnode, context, mountAll) {
var c = dom && dom._component,
originalComponent = c,
oldDom = dom,
isDirectOwner = c && dom._componentConstructor === vnode.nodeName,
isOwner = isDirectOwner,
props = getNodeProps(vnode);
while (c && !isOwner && (c = c._parentComponent)) {
isOwner = c.constructor === vnode.nodeName;
}
if (c && isOwner && (!mountAll || c._component)) {
setComponentProps(c, props, 3, context, mountAll);
dom = c.base;
} else {
if (originalComponent && !isDirectOwner) {
unmountComponent(originalComponent);
dom = oldDom = null;
}
c = createComponent(vnode.nodeName, props, context);
if (dom && !c.nextBase) {
c.nextBase = dom;
oldDom = null;
}
setComponentProps(c, props, 1, context, mountAll);
dom = c.base;
if (oldDom && dom !== oldDom) {
oldDom._component = null;
recollectNodeTree(oldDom, false);
}
}
return dom;
}
function unmountComponent(component) {
var base = component.base;
component._disable = true;
if (component.componentWillUnmount) component.componentWillUnmount();
component.base = null;
var inner = component._component;
if (inner) {
unmountComponent(inner);
} else if (base) {
if (base['__preactattr_'] != null) applyRef(base['__preactattr_'].ref, null);
component.nextBase = base;
removeNode(base);
recyclerComponents.push(component);
removeChildren(base);
}
applyRef(component.__ref, null);
}
function Component(props, context) {
this._dirty = true;
this.context = context;
this.props = props;
this.state = this.state || {};
this._renderCallbacks = [];
}
extend(Component.prototype, {
setState: function setState(state, callback) {
if (!this.prevState) this.prevState = this.state;
this.state = extend(extend({}, this.state), typeof state === 'function' ? state(this.state, this.props) : state);
if (callback) this._renderCallbacks.push(callback);
enqueueRender(this);
},
forceUpdate: function forceUpdate(callback) {
if (callback) this._renderCallbacks.push(callback);
renderComponent(this, 2);
},
render: function render() {}
});
function render(vnode, parent, merge) {
return diff(merge, vnode, {}, false, parent, false);
}
var version$2 = '15.1.0'; // trick libraries to think we are react
var ELEMENTS = 'a abbr address area article aside audio b base bdi bdo big blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td textarea tfoot th thead time title tr track u ul var video wbr circle clipPath defs ellipse g image line linearGradient mask path pattern polygon polyline radialGradient rect stop svg text tspan'.split(' ');
var REACT_ELEMENT_TYPE$1 = (typeof Symbol!=='undefined' && Symbol.for && Symbol.for('react.element')) || 0xeac7;
var COMPONENT_WRAPPER_KEY = (typeof Symbol!=='undefined' && Symbol.for) ? Symbol.for('__preactCompatWrapper') : '__preactCompatWrapper';
// don't autobind these methods since they already have guaranteed context.
var AUTOBIND_BLACKLIST = {
constructor: 1,
render: 1,
shouldComponentUpdate: 1,
componentWillReceiveProps: 1,
componentWillUpdate: 1,
componentDidUpdate: 1,
componentWillMount: 1,
componentDidMount: 1,
componentWillUnmount: 1,
componentDidUnmount: 1
};
var CAMEL_PROPS = /^(?:accent|alignment|arabic|baseline|cap|clip|color|fill|flood|font|glyph|horiz|marker|overline|paint|stop|strikethrough|stroke|text|underline|unicode|units|v|vector|vert|word|writing|x)[A-Z]/;
var BYPASS_HOOK = {};
/*global process*/
var DEV = false;
try {
DEV = "production"!=='production';
}
catch (e) {}
// a component that renders nothing. Used to replace components for unmountComponentAtNode.
function EmptyComponent() { return null; }
// make react think we're react.
var VNode$1 = h('a', null).constructor;
VNode$1.prototype.$$typeof = REACT_ELEMENT_TYPE$1;
VNode$1.prototype.preactCompatUpgraded = false;
VNode$1.prototype.preactCompatNormalized = false;
Object.defineProperty(VNode$1.prototype, 'type', {
get: function() { return this.nodeName; },
set: function(v) { this.nodeName = v; },
configurable:true
});
Object.defineProperty(VNode$1.prototype, 'props', {
get: function() { return this.attributes; },
set: function(v) { this.attributes = v; },
configurable:true
});
var oldEventHook = options.event;
options.event = function (e) {
if (oldEventHook) { e = oldEventHook(e); }
e.persist = Object;
e.nativeEvent = e;
return e;
};
var oldVnodeHook = options.vnode;
options.vnode = function (vnode) {
if (!vnode.preactCompatUpgraded) {
vnode.preactCompatUpgraded = true;
var tag = vnode.nodeName,
attrs = vnode.attributes = vnode.attributes==null ? {} : extend$1({}, vnode.attributes);
if (typeof tag==='function') {
if (tag[COMPONENT_WRAPPER_KEY]===true || (tag.prototype && 'isReactComponent' in tag.prototype)) {
if (vnode.children && String(vnode.children)==='') { vnode.children = undefined; }
if (vnode.children) { attrs.children = vnode.children; }
if (!vnode.preactCompatNormalized) {
normalizeVNode(vnode);
}
handleComponentVNode(vnode);
}
}
else {
if (vnode.children && String(vnode.children)==='') { vnode.children = undefined; }
if (vnode.children) { attrs.children = vnode.children; }
if (attrs.defaultValue) {
if (!attrs.value && attrs.value!==0) {
attrs.value = attrs.defaultValue;
}
delete attrs.defaultValue;
}
handleElementVNode(vnode, attrs);
}
}
if (oldVnodeHook) { oldVnodeHook(vnode); }
};
function handleComponentVNode(vnode) {
var tag = vnode.nodeName,
a = vnode.attributes;
vnode.attributes = {};
if (tag.defaultProps) { extend$1(vnode.attributes, tag.defaultProps); }
if (a) { extend$1(vnode.attributes, a); }
}
function handleElementVNode(vnode, a) {
var shouldSanitize, attrs, i;
if (a) {
for (i in a) { if ((shouldSanitize = CAMEL_PROPS.test(i))) { break; } }
if (shouldSanitize) {
attrs = vnode.attributes = {};
for (i in a) {
if (a.hasOwnProperty(i)) {
attrs[ CAMEL_PROPS.test(i) ? i.replace(/([A-Z0-9])/, '-$1').toLowerCase() : i ] = a[i];
}
}
}
}
}
// proxy render() since React returns a Component reference.
function render$1(vnode, parent, callback) {
var prev = parent && parent._preactCompatRendered && parent._preactCompatRendered.base;
// ignore impossible previous renders
if (prev && prev.parentNode!==parent) { prev = null; }
// default to first Element child
if (!prev && parent) { prev = parent.firstElementChild; }
// remove unaffected siblings
for (var i=parent.childNodes.length; i--; ) {
if (parent.childNodes[i]!==prev) {
parent.removeChild(parent.childNodes[i]);
}
}
var out = render(vnode, parent, prev);
if (parent) { parent._preactCompatRendered = out && (out._component || { base: out }); }
if (typeof callback==='function') { callback(); }
return out && out._component || out;
}
var ContextProvider = function () {};
ContextProvider.prototype.getChildContext = function () {
return this.props.context;
};
ContextProvider.prototype.render = function (props) {
return props.children[0];
};
function renderSubtreeIntoContainer(parentComponent, vnode, container, callback) {
var wrap = h(ContextProvider, { context: parentComponent.context }, vnode);
var renderContainer = render$1(wrap, container);
var component = renderContainer._component || renderContainer.base;
if (callback) { callback.call(component, renderContainer); }
return component;
}
function Portal(props) {
renderSubtreeIntoContainer(this, props.vnode, props.container);
}
function createPortal(vnode, container) {
return h(Portal, { vnode: vnode, container: container });
}
function unmountComponentAtNode(container) {
var existing = container._preactCompatRendered && container._preactCompatRendered.base;
if (existing && existing.parentNode===container) {
render(h(EmptyComponent), container, existing);
return true;
}
return false;
}
var ARR = [];
// This API is completely unnecessary for Preact, so it's basically passthrough.
var Children = {
map: function(children, fn, ctx) {
if (children == null) { return null; }
children = Children.toArray(children);
if (ctx && ctx!==children) { fn = fn.bind(ctx); }
return children.map(fn);
},
forEach: function(children, fn, ctx) {
if (children == null) { return null; }
children = Children.toArray(children);
if (ctx && ctx!==children) { fn = fn.bind(ctx); }
children.forEach(fn);
},
count: function(children) {
return children && children.length || 0;
},
only: function(children) {
children = Children.toArray(children);
if (children.length!==1) { throw new Error('Children.only() expects only one child.'); }
return children[0];
},
toArray: function(children) {
if (children == null) { return []; }
return ARR.concat(children);
}
};
/** Track current render() component for ref assignment */
var currentComponent;
function createFactory(type) {
return createElement.bind(null, type);
}
var DOM = {};
for (var i=ELEMENTS.length; i--; ) {
DOM[ELEMENTS[i]] = createFactory(ELEMENTS[i]);
}
function upgradeToVNodes(arr, offset) {
for (var i=offset || 0; i 0 ) children[ len ] = arguments[ len + 2 ];
if (!isValidElement(element)) { return element; }
var elementProps = element.attributes || element.props;
var node = h(
element.nodeName || element.type,
extend$1({}, elementProps),
element.children || elementProps && elementProps.children
);
// Only provide the 3rd argument if needed.
// Arguments 3+ overwrite element.children in preactCloneElement
var cloneArgs = [node, props];
if (children && children.length) {
cloneArgs.push(children);
}
else if (props && props.children) {
cloneArgs.push(props.children);
}
return normalizeVNode(cloneElement.apply(void 0, cloneArgs));
}
function isValidElement(element) {
return element && ((element instanceof VNode$1) || element.$$typeof===REACT_ELEMENT_TYPE$1);
}
function createStringRefProxy(name, component) {
return component._refProxies[name] || (component._refProxies[name] = function (resolved) {
if (component && component.refs) {
component.refs[name] = resolved;
if (resolved===null) {
delete component._refProxies[name];
component = null;
}
}
});
}
function applyEventNormalization(ref) {
var nodeName = ref.nodeName;
var attributes = ref.attributes;
if (!attributes || typeof nodeName!=='string') { return; }
var props = {};
for (var i in attributes) {
props[i.toLowerCase()] = i;
}
if (props.ondoubleclick) {
attributes.ondblclick = attributes[props.ondoubleclick];
delete attributes[props.ondoubleclick];
}
// for *textual inputs* (incl textarea), normalize `onChange` -> `onInput`:
if (props.onchange && (nodeName==='textarea' || (nodeName.toLowerCase()==='input' && !/^fil|che|rad/i.test(attributes.type)))) {
var normalized = props.oninput || 'oninput';
if (!attributes[normalized]) {
attributes[normalized] = multihook([attributes[normalized], attributes[props.onchange]]);
delete attributes[props.onchange];
}
}
}
function applyClassName(vnode) {
var a = vnode.attributes || (vnode.attributes = {});
classNameDescriptor.enumerable = 'className' in a;
if (a.className) { a.class = a.className; }
Object.defineProperty(a, 'className', classNameDescriptor);
}
var classNameDescriptor = {
configurable: true,
get: function() { return this.class; },
set: function(v) { this.class = v; }
};
function extend$1(base, props) {
var arguments$1 = arguments;
for (var i=1, obj = (void 0); iYour custom HTML Marker
',
reset: 'Clear the map refinement',
toggle: 'Search as I move the map',
redo: 'Redo search here'
};
var createHTMLMarker = function createHTMLMarker(googleReference) {
var HTMLMarker =
/*#__PURE__*/
function (_googleReference$maps) {
_inherits(HTMLMarker, _googleReference$maps);
function HTMLMarker(_ref) {
var _this;
var __id = _ref.__id,
position = _ref.position,
map = _ref.map,
template = _ref.template,
className = _ref.className,
_ref$anchor = _ref.anchor,
anchor = _ref$anchor === void 0 ? {
x: 0,
y: 0
} : _ref$anchor;
_classCallCheck(this, HTMLMarker);
_this = _possibleConstructorReturn(this, _getPrototypeOf(HTMLMarker).call(this));
_this.__id = __id;
_this.anchor = anchor;
_this.listeners = {};
_this.latLng = new googleReference.maps.LatLng(position);
_this.element = document.createElement('div');
_this.element.className = className;
_this.element.style.position = 'absolute';
_this.element.innerHTML = template;
_this.setMap(map);
return _this;
}
_createClass(HTMLMarker, [{
key: "onAdd",
value: function onAdd() {
// Append the element to the map
this.getPanes().overlayMouseTarget.appendChild(this.element); // Compute the offset onAdd & cache it because afterwards
// it won't retrieve the correct values, we also avoid
// to read the values on every draw
var bbBox = this.element.getBoundingClientRect();
this.offset = {
x: this.anchor.x + bbBox.width / 2,
y: this.anchor.y + bbBox.height
}; // Force the width of the element will avoid the
// content to collapse when we move the map
this.element.style.width = "".concat(bbBox.width, "px");
}
}, {
key: "draw",
value: function draw() {
var position = this.getProjection().fromLatLngToDivPixel(this.latLng);
this.element.style.left = "".concat(Math.round(position.x - this.offset.x), "px");
this.element.style.top = "".concat(Math.round(position.y - this.offset.y), "px"); // Markers to the south are in front of markers to the north
// This is the default behaviour of Google Maps
this.element.style.zIndex = parseInt(this.element.style.top, 10);
}
}, {
key: "onRemove",
value: function onRemove() {
var _this2 = this;
if (this.element) {
this.element.parentNode.removeChild(this.element);
Object.keys(this.listeners).forEach(function (eventName) {
_this2.element.removeEventListener(eventName, _this2.listeners[eventName]);
});
delete this.element;
delete this.listeners;
}
}
}, {
key: "addListener",
value: function addListener(eventName, listener) {
this.listeners[eventName] = listener;
this.element.addEventListener(eventName, listener);
}
}, {
key: "getPosition",
value: function getPosition() {
return this.latLng;
}
}]);
return HTMLMarker;
}(googleReference.maps.OverlayView);
return HTMLMarker;
};
var withUsage$n = createDocumentationMessageGenerator({
name: 'geo-search'
});
var suit$4 = component('GeoSearch');
/**
* @typedef {object} HTMLMarkerOptions
* @property {object} [anchor] The offset from the marker's position.
*/
/**
* @typedef {object} CustomHTMLMarkerOptions
* @property {function(item): HTMLMarkerOptions} [createOptions] Function used to create the options passed to the HTMLMarker.
* @property {{ eventType: function(object) }} [events] Object that takes an event type (ex: `click`, `mouseover`) as key and a listener as value. The listener is provided with an object that contains `event`, `item`, `marker`, `map`.
*/
/**
* @typedef {object} BuiltInMarkerOptions
* @property {function(item): MarkerOptions} [createOptions] Function used to create the options passed to the Google Maps marker.
* See [the documentation](https://developers.google.com/maps/documentation/javascript/reference/3/#MarkerOptions) for more information.
* @property {{ eventType: function(object) }} [events] Object that takes an event type (ex: `click`, `mouseover`) as key and a listener as value. The listener is provided with an object that contains `event`, `item`, `marker`, `map`.
*/
/**
* @typedef {object} GeoSearchCSSClasses
* @property {string|Array} [root] The root div of the widget.
* @property {string|Array} [map] The map container of the widget.
* @property {string|Array} [control] The control element of the widget.
* @property {string|Array} [label] The label of the control element.
* @property {string|Array} [selectedLabel] The selected label of the control element.
* @property {string|Array} [input] The input of the control element.
* @property {string|Array} [redo] The redo search button.
* @property {string|Array} [disabledRedo] The disabled redo search button.
* @property {string|Array} [reset] The reset refinement button.
*/
/**
* @typedef {object} GeoSearchTemplates
* @property {string|function(object): string} [HTMLMarker] Template to use for the marker.
* @property {string|function(object): string} [reset] Template for the reset button.
* @property {string|function(object): string} [toggle] Template for the toggle label.
* @property {string|function(object): string} [redo] Template for the redo button.
*/
/**
* @typedef {object} LatLng
* @property {number} lat The latitude in degrees.
* @property {number} lng The longitude in degrees.
*/
/**
* @typedef {object} GeoSearchWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {object} googleReference Reference to the global `window.google` object.
* See [the documentation](https://developers.google.com/maps/documentation/javascript/tutorial) for more information.
* @property {number} [initialZoom=1] By default the map will set the zoom accordingly to the markers displayed on it. When we refine it may happen that the results are empty. For those situations we need to provide a zoom to render the map.
* @property {LatLng} [initialPosition={ lat: 0, lng: 0 }] By default the map will set the position accordingly to the markers displayed on it. When we refine it may happen that the results are empty. For those situations we need to provide a position to render the map. This option is ignored when the `position` is provided.
* @property {GeoSearchTemplates} [templates] Templates to use for the widget.
* @property {GeoSearchCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
* @property {object} [mapOptions] Option forwarded to the Google Maps constructor.
* See [the documentation](https://developers.google.com/maps/documentation/javascript/reference/3/#MapOptions) for more information.
* @property {BuiltInMarkerOptions} [builtInMarker] Options for customize the built-in Google Maps marker. This option is ignored when the `customHTMLMarker` is provided.
* @property {CustomHTMLMarkerOptions} [customHTMLMarker] Options for customize the HTML marker. We provide an alternative to the built-in Google Maps marker in order to have a full control of the marker rendering. You can use plain HTML to build your marker.
* @property {boolean} [enableRefine=true] If true, the map is used to search - otherwise it's for display purposes only.
* @property {boolean} [enableClearMapRefinement=true] If true, a button is displayed on the map when the refinement is coming from the map in order to remove it.
* @property {boolean} [enableRefineControl=true] If true, the user can toggle the option `enableRefineOnMapMove` directly from the map.
* @property {boolean} [enableRefineOnMapMove=true] If true, refine will be triggered as you move the map.
* @property {function} [transformItems] Function to transform the items passed to the templates.
*/
/**
* The **GeoSearch** widget displays the list of results from the search on a Google Maps. It also provides a way to search for results based on their position. The widget also provide some of the common GeoSearch patterns like search on map interaction.
*
* @requirements
*
* Note that the GeoSearch widget uses the [geosearch](https://www.algolia.com/doc/guides/searching/geo-search) capabilities of Algolia. Your hits **must** have a `_geoloc` attribute in order to be displayed on the map.
*
* Currently, the feature is not compatible with multiple values in the _geoloc attribute.
*
* You are also responsible for loading the Google Maps library, it's not shipped with InstantSearch. You need to load the Google Maps library and pass a reference to the widget. You can find more information about how to install the library in [the Google Maps documentation](https://developers.google.com/maps/documentation/javascript/tutorial).
*
* Don't forget to explicitly set the `height` of the map container (default class `.ais-geo-search--map`), otherwise it won't be shown (it's a requirement of Google Maps).
*
* @type {WidgetFactory}
* @devNovel GeoSearch
* @param {GeoSearchWidgetOptions} $0 Options of the GeoSearch widget.
* @return {Widget} A new instance of GeoSearch widget.
* @staticExample
* search.addWidget(
* instantsearch.widgets.geoSearch({
* container: '#geo-search-container',
* googleReference: window.google,
* })
* );
*/
var geoSearch = function geoSearch() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$initialZoom = _ref.initialZoom,
initialZoom = _ref$initialZoom === void 0 ? 1 : _ref$initialZoom,
_ref$initialPosition = _ref.initialPosition,
initialPosition = _ref$initialPosition === void 0 ? {
lat: 0,
lng: 0
} : _ref$initialPosition,
_ref$templates = _ref.templates,
userTemplates = _ref$templates === void 0 ? {} : _ref$templates,
_ref$cssClasses = _ref.cssClasses,
userCssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses,
_ref$builtInMarker = _ref.builtInMarker,
userBuiltInMarker = _ref$builtInMarker === void 0 ? {} : _ref$builtInMarker,
userCustomHTMLMarker = _ref.customHTMLMarker,
_ref$enableRefine = _ref.enableRefine,
enableRefine = _ref$enableRefine === void 0 ? true : _ref$enableRefine,
_ref$enableClearMapRe = _ref.enableClearMapRefinement,
enableClearMapRefinement = _ref$enableClearMapRe === void 0 ? true : _ref$enableClearMapRe,
_ref$enableRefineCont = _ref.enableRefineControl,
enableRefineControl = _ref$enableRefineCont === void 0 ? true : _ref$enableRefineCont,
container = _ref.container,
googleReference = _ref.googleReference,
widgetParams = _objectWithoutProperties(_ref, ["initialZoom", "initialPosition", "templates", "cssClasses", "builtInMarker", "customHTMLMarker", "enableRefine", "enableClearMapRefinement", "enableRefineControl", "container", "googleReference"]);
var defaultBuiltInMarker = {
createOptions: noop_1,
events: {}
};
var defaultCustomHTMLMarker = {
createOptions: noop_1,
events: {}
};
if (!container) {
throw new Error(withUsage$n('The `container` option is required.'));
}
if (!googleReference) {
throw new Error(withUsage$n('The `googleReference` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$4(), userCssClasses.root),
// Required only to mount / unmount the Preact tree
tree: suit$4({
descendantName: 'tree'
}),
map: classnames(suit$4({
descendantName: 'map'
}), userCssClasses.map),
control: classnames(suit$4({
descendantName: 'control'
}), userCssClasses.control),
label: classnames(suit$4({
descendantName: 'label'
}), userCssClasses.label),
selectedLabel: classnames(suit$4({
descendantName: 'label',
modifierName: 'selected'
}), userCssClasses.selectedLabel),
input: classnames(suit$4({
descendantName: 'input'
}), userCssClasses.input),
redo: classnames(suit$4({
descendantName: 'redo'
}), userCssClasses.redo),
disabledRedo: classnames(suit$4({
descendantName: 'redo',
modifierName: 'disabled'
}), userCssClasses.disabledRedo),
reset: classnames(suit$4({
descendantName: 'reset'
}), userCssClasses.reset)
};
var templates = _objectSpread({}, defaultTemplates$1, userTemplates);
var builtInMarker = _objectSpread({}, defaultBuiltInMarker, userBuiltInMarker);
var isCustomHTMLMarker = Boolean(userCustomHTMLMarker) || Boolean(userTemplates.HTMLMarker);
var customHTMLMarker = isCustomHTMLMarker && _objectSpread({}, defaultCustomHTMLMarker, userCustomHTMLMarker);
var createBuiltInMarker = function createBuiltInMarker(_ref2) {
var item = _ref2.item,
rest = _objectWithoutProperties(_ref2, ["item"]);
return new googleReference.maps.Marker(_objectSpread({}, builtInMarker.createOptions(item), rest, {
__id: item.objectID,
position: item._geoloc
}));
};
var HTMLMarker = createHTMLMarker(googleReference);
var createCustomHTMLMarker = function createCustomHTMLMarker(_ref3) {
var item = _ref3.item,
rest = _objectWithoutProperties(_ref3, ["item"]);
return new HTMLMarker(_objectSpread({}, customHTMLMarker.createOptions(item), rest, {
__id: item.objectID,
position: item._geoloc,
className: classnames(suit$4({
descendantName: 'marker'
})),
template: renderTemplate({
templateKey: 'HTMLMarker',
templates: templates,
data: item
})
}));
};
var createMarker = !customHTMLMarker ? createBuiltInMarker : createCustomHTMLMarker; // prettier-ignore
var markerOptions = !customHTMLMarker ? builtInMarker : customHTMLMarker;
var makeGeoSearch = connectGeoSearch(renderer$2, function () {
unmountComponentAtNode(containerNode.querySelector(".".concat(cssClasses.tree)));
while (containerNode.firstChild) {
containerNode.removeChild(containerNode.firstChild);
}
});
return makeGeoSearch(_objectSpread({}, widgetParams, {
renderState: {},
container: containerNode,
googleReference: googleReference,
initialZoom: initialZoom,
initialPosition: initialPosition,
templates: templates,
cssClasses: cssClasses,
createMarker: createMarker,
markerOptions: markerOptions,
enableRefine: enableRefine,
enableClearMapRefinement: enableClearMapRefinement,
enableRefineControl: enableRefineControl
}));
};
var RefinementListItem =
/*#__PURE__*/
function (_Component) {
_inherits(RefinementListItem, _Component);
function RefinementListItem() {
_classCallCheck(this, RefinementListItem);
return _possibleConstructorReturn(this, _getPrototypeOf(RefinementListItem).apply(this, arguments));
}
_createClass(RefinementListItem, [{
key: "componentWillMount",
value: function componentWillMount() {
this.handleClick = this.handleClick.bind(this);
}
}, {
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps) {
return !isEqual_1(this.props, nextProps);
}
}, {
key: "handleClick",
value: function handleClick(originalEvent) {
this.props.handleClick({
facetValueToRefine: this.props.facetValueToRefine,
isRefined: this.props.isRefined,
originalEvent: originalEvent
});
}
}, {
key: "render",
value: function render() {
return index.createElement("li", {
className: this.props.className,
onClick: this.handleClick
}, index.createElement(Template, _extends({}, this.props.templateProps, {
templateKey: this.props.templateKey,
data: this.props.templateData
})), this.props.subItems);
}
}]);
return RefinementListItem;
}(Component$1);
var suit$5 = component('SearchBox');
var cssClasses = {
root: suit$5(),
form: suit$5({
descendantName: 'form'
}),
input: suit$5({
descendantName: 'input'
}),
submit: suit$5({
descendantName: 'submit'
}),
submitIcon: suit$5({
descendantName: 'submitIcon'
}),
reset: suit$5({
descendantName: 'reset'
}),
resetIcon: suit$5({
descendantName: 'resetIcon'
}),
loadingIndicator: suit$5({
descendantName: 'loadingIndicator'
}),
loadingIcon: suit$5({
descendantName: 'loadingIcon'
})
};
var _ref =
/*#__PURE__*/
index.createElement("path", {
d: "M26.804 29.01c-2.832 2.34-6.465 3.746-10.426 3.746C7.333 32.756 0 25.424 0 16.378 0 7.333 7.333 0 16.378 0c9.046 0 16.378 7.333 16.378 16.378 0 3.96-1.406 7.594-3.746 10.426l10.534 10.534c.607.607.61 1.59-.004 2.202-.61.61-1.597.61-2.202.004L26.804 29.01zm-10.426.627c7.323 0 13.26-5.936 13.26-13.26 0-7.32-5.937-13.257-13.26-13.257C9.056 3.12 3.12 9.056 3.12 16.378c0 7.323 5.936 13.26 13.258 13.26z"
});
var _ref2 =
/*#__PURE__*/
index.createElement("path", {
d: "M8.114 10L.944 2.83 0 1.885 1.886 0l.943.943L10 8.113l7.17-7.17.944-.943L20 1.886l-.943.943-7.17 7.17 7.17 7.17.943.944L18.114 20l-.943-.943-7.17-7.17-7.17 7.17-.944.943L0 18.114l.943-.943L8.113 10z"
});
var _ref3 =
/*#__PURE__*/
index.createElement("g", {
fill: "none",
fillRule: "evenodd"
}, index.createElement("g", {
transform: "translate(1 1)",
strokeWidth: "2"
}, index.createElement("circle", {
strokeOpacity: ".5",
cx: "18",
cy: "18",
r: "18"
}), index.createElement("path", {
d: "M36 18c0-9.94-8.06-18-18-18"
}, index.createElement("animateTransform", {
attributeName: "transform",
type: "rotate",
from: "0 18 18",
to: "360 18 18",
dur: "1s",
repeatCount: "indefinite"
}))));
var SearchBox =
/*#__PURE__*/
function (_Component) {
_inherits(SearchBox, _Component);
function SearchBox() {
_classCallCheck(this, SearchBox);
return _possibleConstructorReturn(this, _getPrototypeOf(SearchBox).apply(this, arguments));
}
_createClass(SearchBox, [{
key: "clearInput",
value: function clearInput() {
if (this.input) {
this.input.value = '';
}
}
}, {
key: "validateSearch",
value: function validateSearch(event) {
event.preventDefault();
if (this.input) {
var inputValue = this.input.value;
if (inputValue) {
this.props.onValidate();
}
}
}
}, {
key: "render",
value: function render() {
var _this = this;
var _this$props = this.props,
placeholder = _this$props.placeholder,
_onChange = _this$props.onChange;
return index.createElement("div", {
className: cssClasses.root
}, index.createElement("form", {
action: "",
role: "search",
noValidate: "novalidate",
className: cssClasses.form,
onReset: function onReset() {
return _onChange('');
},
onSubmit: function onSubmit(event) {
return _this.validateSearch(event);
}
}, index.createElement("input", {
className: cssClasses.input,
autoComplete: "off",
autoCorrect: "off",
autoCapitalize: "off",
placeholder: placeholder,
spellCheck: "false",
maxLength: "512",
type: "search",
onChange: function onChange(event) {
return _onChange(event.target.value);
},
ref: function ref(input) {
return _this.input = input;
},
disabled: this.props.disabled
}), index.createElement("button", {
className: cssClasses.submit,
type: "submit",
title: "Submit the search query."
}, index.createElement("svg", {
className: cssClasses.submitIcon,
xmlns: "http://www.w3.org/2000/svg",
width: "10",
height: "10",
viewBox: "0 0 40 40"
}, _ref)), index.createElement("button", {
className: cssClasses.reset,
type: "reset",
title: "Clear the search query.",
hidden: !this.input || this.input.value.length === 0
}, index.createElement("svg", {
className: cssClasses.resetIcon,
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 20 20",
width: "10",
height: "10"
}, _ref2)), index.createElement("span", {
className: cssClasses.loadingIndicator,
hidden: true
}, index.createElement("svg", {
width: "16",
height: "16",
viewBox: "0 0 38 38",
xmlns: "http://www.w3.org/2000/svg",
stroke: "#444",
className: cssClasses.loadingIcon
}, _ref3))));
}
}]);
return SearchBox;
}(Component$1);
var RefinementList$1 =
/*#__PURE__*/
function (_Component) {
_inherits(RefinementList, _Component);
function RefinementList(props) {
var _this;
_classCallCheck(this, RefinementList);
_this = _possibleConstructorReturn(this, _getPrototypeOf(RefinementList).call(this, props));
_this.handleItemClick = _this.handleItemClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
return _this;
}
_createClass(RefinementList, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps, nextState) {
var isStateDifferent = nextState !== this.state;
var isFacetValuesDifferent = !isEqual_1(this.props.facetValues, nextProps.facetValues);
var shouldUpdate = isStateDifferent || isFacetValuesDifferent;
return shouldUpdate;
}
}, {
key: "refine",
value: function refine(facetValueToRefine, isRefined) {
this.props.toggleRefinement(facetValueToRefine, isRefined);
}
}, {
key: "_generateFacetItem",
value: function _generateFacetItem(facetValue) {
var _cx;
var subItems;
var hasChildren = facetValue.data && facetValue.data.length > 0;
if (hasChildren) {
subItems = index.createElement(RefinementList, _extends({}, this.props, {
depth: this.props.depth + 1,
facetValues: facetValue.data,
showMore: false,
className: this.props.cssClasses.childList
}));
}
var url = this.props.createURL(facetValue.value);
var templateData = _objectSpread({}, facetValue, {
url: url,
attribute: this.props.attribute,
cssClasses: this.props.cssClasses
});
var key = facetValue.value;
if (facetValue.isRefined !== undefined) {
key += "/".concat(facetValue.isRefined);
}
if (facetValue.count !== undefined) {
key += "/".concat(facetValue.count);
}
return index.createElement(RefinementListItem, {
templateKey: "item",
key: key,
facetValueToRefine: facetValue.value,
handleClick: this.handleItemClick,
isRefined: facetValue.isRefined,
className: classnames(this.props.cssClasses.item, (_cx = {}, _defineProperty(_cx, this.props.cssClasses.selectedItem, facetValue.isRefined), _defineProperty(_cx, this.props.cssClasses.disabledItem, !facetValue.count), _defineProperty(_cx, this.props.cssClasses.parentItem, hasChildren), _cx)),
subItems: subItems,
templateData: templateData,
templateProps: this.props.templateProps
});
} // Click events on DOM tree like LABEL > INPUT will result in two click events
// instead of one.
// No matter the framework, see https://www.google.com/search?q=click+label+twice
//
// Thus making it hard to distinguish activation from deactivation because both click events
// are very close. Debounce is a solution but hacky.
//
// So the code here checks if the click was done on or in a LABEL. If this LABEL
// has a checkbox inside, we ignore the first click event because we will get another one.
//
// We also check if the click was done inside a link and then e.preventDefault() because we already
// handle the url
//
// Finally, we always stop propagation of the event to avoid multiple levels RefinementLists to fail: click
// on child would click on parent also
}, {
key: "handleItemClick",
value: function handleItemClick(_ref) {
var facetValueToRefine = _ref.facetValueToRefine,
originalEvent = _ref.originalEvent,
isRefined = _ref.isRefined;
if (isSpecialClick(originalEvent)) {
// do not alter the default browser behavior
// if one special key is down
return;
}
if (originalEvent.target.tagName === 'INPUT') {
this.refine(facetValueToRefine, isRefined);
return;
}
var parent = originalEvent.target;
while (parent !== originalEvent.currentTarget) {
if (parent.tagName === 'LABEL' && (parent.querySelector('input[type="checkbox"]') || parent.querySelector('input[type="radio"]'))) {
return;
}
if (parent.tagName === 'A' && parent.href) {
originalEvent.preventDefault();
}
parent = parent.parentNode;
}
originalEvent.stopPropagation();
this.refine(facetValueToRefine, isRefined);
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
if (this.searchbox && !nextProps.isFromSearch) {
this.searchbox.clearInput();
}
}
}, {
key: "refineFirstValue",
value: function refineFirstValue() {
var firstValue = this.props.facetValues[0];
if (firstValue) {
var actualValue = firstValue.value;
this.props.toggleRefinement(actualValue);
}
}
}, {
key: "render",
value: function render() {
var _this2 = this;
// Adding `-lvl0` classes
var cssClassList = classnames(this.props.cssClasses.list, _defineProperty({}, "".concat(this.props.cssClasses.depth).concat(this.props.depth), this.props.cssClasses.depth));
var showMoreButtonClassName = classnames(this.props.cssClasses.showMore, _defineProperty({}, this.props.cssClasses.disabledShowMore, !(this.props.showMore === true && this.props.canToggleShowMore)));
var showMoreButton = this.props.showMore === true && index.createElement(Template, _extends({}, this.props.templateProps, {
templateKey: "showMoreText",
rootTagName: "button",
rootProps: {
className: showMoreButtonClassName,
onClick: this.props.toggleShowMore
},
data: {
isShowingMore: this.props.isShowingMore
}
}));
var shouldDisableSearchBox = this.props.searchIsAlwaysActive !== true && !(this.props.isFromSearch || !this.props.hasExhaustiveItems);
var searchBox = this.props.searchFacetValues && index.createElement("div", {
className: this.props.cssClasses.searchBox
}, index.createElement(SearchBox, {
ref: function ref(i) {
_this2.searchbox = i;
},
placeholder: this.props.searchPlaceholder,
onChange: this.props.searchFacetValues,
onValidate: function onValidate() {
return _this2.refineFirstValue();
},
disabled: shouldDisableSearchBox
}));
var facetValues = this.props.facetValues && this.props.facetValues.length > 0 && index.createElement("ul", {
className: cssClassList
}, this.props.facetValues.map(this._generateFacetItem, this));
var noResults = this.props.searchFacetValues && this.props.isFromSearch && this.props.facetValues.length === 0 && index.createElement(Template, _extends({}, this.props.templateProps, {
templateKey: "searchableNoResults",
rootProps: {
className: this.props.cssClasses.noResults
}
}));
return index.createElement("div", {
className: classnames(this.props.cssClasses.root, _defineProperty({}, this.props.cssClasses.noRefinementRoot, !this.props.facetValues || this.props.facetValues.length === 0), this.props.className)
}, this.props.children, searchBox, facetValues, noResults, showMoreButton);
}
}]);
return RefinementList;
}(Component$1);
RefinementList$1.defaultProps = {
cssClasses: {},
depth: 0
};
var defaultTemplates$2 = {
item: '' + '{{label}} ' + '{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}} ' + ' ',
showMoreText: "\n {{#isShowingMore}}\n Show less\n {{/isShowingMore}}\n {{^isShowingMore}}\n Show more\n {{/isShowingMore}}\n "
};
var withUsage$o = createDocumentationMessageGenerator({
name: 'hierarchical-menu'
});
var suit$6 = component('HierarchicalMenu');
var renderer$3 = function renderer(_ref) {
var cssClasses = _ref.cssClasses,
containerNode = _ref.containerNode,
showMore = _ref.showMore,
templates = _ref.templates,
renderState = _ref.renderState;
return function (_ref2, isFirstRendering) {
var createURL = _ref2.createURL,
items = _ref2.items,
refine = _ref2.refine,
instantSearchInstance = _ref2.instantSearchInstance,
isShowingMore = _ref2.isShowingMore,
toggleShowMore = _ref2.toggleShowMore,
canToggleShowMore = _ref2.canToggleShowMore;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$2,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(RefinementList$1, {
createURL: createURL,
cssClasses: cssClasses,
facetValues: items,
templateProps: renderState.templateProps,
toggleRefinement: refine,
showMore: showMore,
toggleShowMore: toggleShowMore,
isShowingMore: isShowingMore,
canToggleShowMore: canToggleShowMore
}), containerNode);
};
};
/**
* @typedef {Object} HierarchicalMenuCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element when no refinements.
* @property {string|string[]} [list] CSS class to add to the list element.
* @property {string|string[]} [childList] CSS class to add to the child list element.
* @property {string|string[]} [item] CSS class to add to each item element.
* @property {string|string[]} [selectedItem] CSS class to add to each selected item element.
* @property {string|string[]} [parentItem] CSS class to add to each parent item element.
* @property {string|string[]} [link] CSS class to add to each link (when using the default template).
* @property {string|string[]} [label] CSS class to add to each label (when using the default template).
* @property {string|string[]} [count] CSS class to add to each count element (when using the default template).
* @property {string|string[]} [showMore] CSS class to add to the show more element.
* @property {string|string[]} [disabledShowMore] CSS class to add to the disabled show more element.
*/
/**
* @typedef {Object} HierarchicalMenuTemplates
* @property {string|function(object):string} [item] Item template, provided with `name`, `count`, `isRefined`, `url` data properties.
* @property {string|function} [showMoreText] Template used for the show more text, provided with `isShowingMore` data property.
*/
/**
* @typedef {Object} HierarchicalMenuWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {string[]} attributes Array of attributes to use to generate the hierarchy of the menu.
* @property {string} [separator = " > "] Separator used in the attributes to separate level values.
* @property {string} [rootPath] Prefix path to use if the first level is not the root level.
* @property {boolean} [showParentLevel = true] Show the siblings of the selected parent level of the current refined value. This
* @property {number} [limit = 10] Max number of values to display.
* @property {boolean} [showMore = false] Whether to display the "show more" button.
* @property {number} [showMoreLimit = 20] Max number of values to display when showing more.
* does not impact the root level.
*
* The hierarchical menu is able to show or hide the siblings with `showParentLevel`.
*
* With `showParentLevel` set to `true` (default):
* - Parent lvl0
* - **lvl1**
* - **lvl2**
* - lvl2
* - lvl2
* - lvl 1
* - lvl 1
* - Parent lvl0
* - Parent lvl0
*
* With `showParentLevel` set to `false`:
* - Parent lvl0
* - **lvl1**
* - **lvl2**
* - Parent lvl0
* - Parent lvl0
* @property {string[]|function} [sortBy = ['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
* @property {HierarchicalMenuTemplates} [templates] Templates to use for the widget.
* @property {HierarchicalMenuCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
*/
/**
* The hierarchical menu widget is used to create a navigation based on a hierarchy of facet attributes.
*
* It is commonly used for categories with subcategories.
*
* All attributes (lvl0, lvl1 here) must be declared as [attributes for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting) in your
* Algolia settings.
*
* By default, the separator we expect is ` > ` (with spaces) but you can use
* a different one by using the `separator` option.
* @requirements
* Your objects must be formatted in a specific way to be
* able to display hierarchical menus. Here's an example:
*
* ```javascript
* {
* "objectID": "123",
* "name": "orange",
* "categories": {
* "lvl0": "fruits",
* "lvl1": "fruits > citrus"
* }
* }
* ```
*
* Every level must be specified entirely.
* It's also possible to have multiple values per level, for example:
*
* ```javascript
* {
* "objectID": "123",
* "name": "orange",
* "categories": {
* "lvl0": ["fruits", "vitamins"],
* "lvl1": ["fruits > citrus", "vitamins > C"]
* }
* }
* ```
* @type {WidgetFactory}
* @devNovel HierarchicalMenu
* @category filter
* @param {HierarchicalMenuWidgetOptions} $0 The HierarchicalMenu widget options.
* @return {Widget} A new HierarchicalMenu widget instance.
* @example
* search.addWidget(
* instantsearch.widgets.hierarchicalMenu({
* container: '#hierarchical-categories',
* attributes: ['hierarchicalCategories.lvl0', 'hierarchicalCategories.lvl1', 'hierarchicalCategories.lvl2'],
* })
* );
*/
function hierarchicalMenu() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attributes = _ref3.attributes,
separator = _ref3.separator,
rootPath = _ref3.rootPath,
showParentLevel = _ref3.showParentLevel,
limit = _ref3.limit,
_ref3$showMore = _ref3.showMore,
showMore = _ref3$showMore === void 0 ? false : _ref3$showMore,
showMoreLimit = _ref3.showMoreLimit,
sortBy = _ref3.sortBy,
transformItems = _ref3.transformItems,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$2 : _ref3$templates,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
if (!container) {
throw new Error(withUsage$o('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$6(), userCssClasses.root),
noRefinementRoot: classnames(suit$6({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$6({
descendantName: 'list'
}), userCssClasses.list),
childList: classnames(suit$6({
descendantName: 'list',
modifierName: 'child'
}), userCssClasses.childList),
item: classnames(suit$6({
descendantName: 'item'
}), userCssClasses.item),
selectedItem: classnames(suit$6({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
parentItem: classnames(suit$6({
descendantName: 'item',
modifierName: 'parent'
}), userCssClasses.parentItem),
link: classnames(suit$6({
descendantName: 'link'
}), userCssClasses.link),
label: classnames(suit$6({
descendantName: 'label'
}), userCssClasses.label),
count: classnames(suit$6({
descendantName: 'count'
}), userCssClasses.count),
showMore: classnames(suit$6({
descendantName: 'showMore'
}), userCssClasses.showMore),
disabledShowMore: classnames(suit$6({
descendantName: 'showMore',
modifierName: 'disabled'
}), userCssClasses.disabledShowMore)
};
var specializedRenderer = renderer$3({
cssClasses: cssClasses,
containerNode: containerNode,
templates: templates,
showMore: showMore,
renderState: {}
});
var makeHierarchicalMenu = connectHierarchicalMenu(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeHierarchicalMenu({
attributes: attributes,
separator: separator,
rootPath: rootPath,
showParentLevel: showParentLevel,
limit: limit,
showMore: showMore,
showMoreLimit: showMoreLimit,
sortBy: sortBy,
transformItems: transformItems
});
}
var Hits = function Hits(_ref) {
var results = _ref.results,
hits = _ref.hits,
cssClasses = _ref.cssClasses,
templateProps = _ref.templateProps;
if (results.hits.length === 0) {
return index.createElement(Template, _extends({}, templateProps, {
templateKey: "empty",
rootProps: {
className: classnames(cssClasses.root, cssClasses.emptyRoot)
},
data: results
}));
}
return index.createElement("div", {
className: cssClasses.root
}, index.createElement("ol", {
className: cssClasses.list
}, hits.map(function (hit, position) {
return index.createElement(Template, _extends({}, templateProps, {
templateKey: "item",
rootTagName: "li",
rootProps: {
className: cssClasses.item
},
key: hit.objectID,
data: _objectSpread({}, hit, {
__hitIndex: position
})
}));
})));
};
Hits.defaultProps = {
results: {
hits: []
},
hits: []
};
var defaultTemplates$3 = {
empty: 'No results',
item: function item(data) {
return JSON.stringify(data, null, 2);
}
};
var withUsage$p = createDocumentationMessageGenerator({
name: 'hits'
});
var suit$7 = component('Hits');
var renderer$4 = function renderer(_ref) {
var renderState = _ref.renderState,
cssClasses = _ref.cssClasses,
containerNode = _ref.containerNode,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var receivedHits = _ref2.hits,
results = _ref2.results,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$3,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(Hits, {
cssClasses: cssClasses,
hits: receivedHits,
results: results,
templateProps: renderState.templateProps
}), containerNode);
};
};
/**
* @typedef {Object} HitsCSSClasses
* @property {string|string[]} [root] CSS class to add to the wrapping element.
* @property {string|string[]} [emptyRoot] CSS class to add to the wrapping element when no results.
* @property {string|string[]} [list] CSS class to add to the list of results.
* @property {string|string[]} [item] CSS class to add to each result.
*/
/**
* @typedef {Object} HitsTemplates
* @property {string|function(object):string} [empty=''] Template to use when there are no results.
* @property {string|function(object):string} [item=''] Template to use for each result. This template will receive an object containing a single record. The record will have a new property `__hitIndex` for the position of the record in the list of displayed hits.
*/
/**
* @typedef {Object} HitsWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {HitsTemplates} [templates] Templates to use for the widget.
* @property {HitsCSSClasses} [cssClasses] CSS classes to add.
* @property {boolean} [escapeHTML = true] Escape HTML entities from hits string values.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* Display the list of results (hits) from the current search.
*
* This is a traditional display of the hits. It has to be implemented
* together with a pagination widget, to let the user browse the results
* beyond the first page.
* @type {WidgetFactory}
* @devNovel Hits
* @category basic
* @param {HitsWidgetOptions} $0 Options of the Hits widget.
* @return {Widget} A new instance of Hits widget.
* @example
* search.addWidget(
* instantsearch.widgets.hits({
* container: '#hits-container',
* templates: {
* empty: 'No results',
* item: 'Hit {{objectID}} : {{{_highlightResult.name.value}}}'
* },
* transformItems: items => items.map(item => item),
* })
* );
*/
function hits(_ref3) {
var container = _ref3.container,
escapeHTML = _ref3.escapeHTML,
transformItems = _ref3.transformItems,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$3 : _ref3$templates,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
if (!container) {
throw new Error(withUsage$p('The `container` option is required.'));
}
_warning(typeof templates.allItems === 'undefined', "The template `allItems` does not exist since InstantSearch.js 3.\n\nYou may want to migrate using `connectHits`: ".concat(createDocumentationLink({
name: 'hits',
connector: true
}), "."));
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$7(), userCssClasses.root),
emptyRoot: classnames(suit$7({
modifierName: 'empty'
}), userCssClasses.emptyRoot),
list: classnames(suit$7({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$7({
descendantName: 'item'
}), userCssClasses.item)
};
var specializedRenderer = renderer$4({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeHits = connectHits(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeHits({
escapeHTML: escapeHTML,
transformItems: transformItems
});
}
var Selector =
/*#__PURE__*/
function (_Component) {
_inherits(Selector, _Component);
function Selector() {
_classCallCheck(this, Selector);
return _possibleConstructorReturn(this, _getPrototypeOf(Selector).apply(this, arguments));
}
_createClass(Selector, [{
key: "componentWillMount",
value: function componentWillMount() {
this.handleChange = this.handleChange.bind(this);
}
}, {
key: "handleChange",
value: function handleChange(event) {
this.props.setValue(event.target.value);
}
}, {
key: "render",
value: function render() {
var _this = this;
var _this$props = this.props,
currentValue = _this$props.currentValue,
options = _this$props.options;
return index.createElement("select", {
className: classnames(this.props.cssClasses.select),
onChange: this.handleChange,
value: "".concat(currentValue)
}, options.map(function (option) {
return index.createElement("option", {
className: classnames(_this.props.cssClasses.option),
key: option.label + option.value,
value: "".concat(option.value)
}, option.label);
}));
}
}]);
return Selector;
}(Component$1);
var withUsage$q = createDocumentationMessageGenerator({
name: 'hits-per-page'
});
var suit$8 = component('HitsPerPage');
var renderer$5 = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses;
return function (_ref2, isFirstRendering) {
var items = _ref2.items,
refine = _ref2.refine;
if (isFirstRendering) return;
var _ref3 = find_1(items, function (_ref4) {
var isRefined = _ref4.isRefined;
return isRefined;
}) || {},
currentValue = _ref3.value;
render$1(index.createElement("div", {
className: cssClasses.root
}, index.createElement(Selector, {
cssClasses: cssClasses,
currentValue: currentValue,
options: items,
setValue: refine
})), containerNode);
};
};
/**
* @typedef {Object} HitsPerPageCSSClasses
* @property {string|string[]} [root] CSS classes added to the outer ``.
* @property {string|string[]} [select] CSS classes added to the parent `
`.
* @property {string|string[]} [option] CSS classes added to each ``.
*/
/**
* @typedef {Object} HitsPerPageItems
* @property {number} value number of hits to display per page.
* @property {string} label Label to display in the option.
* @property {boolean} default The default hits per page on first search.
*/
/**
* @typedef {Object} HitsPerPageWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {HitsPerPageItems[]} items Array of objects defining the different values and labels.
* @property {HitsPerPageCSSClasses} [cssClasses] CSS classes to be added.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* The hitsPerPage widget gives the user the ability to change the number of results
* displayed in the hits widget.
*
* You can specify the default hits per page using a boolean in the items[] array. If none is specified, this first hits per page option will be picked.
* @type {WidgetFactory}
* @devNovel HitsPerPage
* @category basic
* @param {HitsPerPageWidgetOptions} $0 The options of the HitPerPageSelector widget.
* @return {Widget} A new instance of the HitPerPageSelector widget.
* @example
* search.addWidget(
* instantsearch.widgets.hitsPerPage({
* container: '#hits-per-page',
* items: [
* {value: 3, label: '3 per page', default: true},
* {value: 6, label: '6 per page'},
* {value: 12, label: '12 per page'},
* ]
* })
* );
*/
function hitsPerPage() {
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref5.container,
items = _ref5.items,
_ref5$cssClasses = _ref5.cssClasses,
userCssClasses = _ref5$cssClasses === void 0 ? {} : _ref5$cssClasses,
transformItems = _ref5.transformItems;
if (!container) {
throw new Error(withUsage$q('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$8(), userCssClasses.root),
select: classnames(suit$8({
descendantName: 'select'
}), userCssClasses.select),
option: classnames(suit$8({
descendantName: 'option'
}), userCssClasses.option)
};
var specializedRenderer = renderer$5({
containerNode: containerNode,
cssClasses: cssClasses
});
var makeHitsPerPage = connectHitsPerPage(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeHitsPerPage({
items: items,
transformItems: transformItems
});
}
var InfiniteHits = function InfiniteHits(_ref) {
var results = _ref.results,
hits = _ref.hits,
showMore = _ref.showMore,
isLastPage = _ref.isLastPage,
cssClasses = _ref.cssClasses,
templateProps = _ref.templateProps;
if (results.hits.length === 0) {
return index.createElement(Template, _extends({}, templateProps, {
templateKey: "empty",
rootProps: {
className: classnames(cssClasses.root, cssClasses.emptyRoot)
},
data: results
}));
}
return index.createElement("div", {
className: cssClasses.root
}, index.createElement("ol", {
className: cssClasses.list
}, hits.map(function (hit, position) {
return index.createElement(Template, _extends({}, templateProps, {
templateKey: "item",
rootTagName: "li",
rootProps: {
className: cssClasses.item
},
key: hit.objectID,
data: _objectSpread({}, hit, {
__hitIndex: position
})
}));
})), index.createElement(Template, _extends({}, templateProps, {
templateKey: "showMoreText",
rootTagName: "button",
rootProps: {
className: classnames(cssClasses.loadMore, _defineProperty({}, cssClasses.disabledLoadMore, isLastPage)),
disabled: isLastPage,
onClick: showMore
}
})));
};
var defaultTemplates$4 = {
empty: 'No results',
showMoreText: 'Show more results',
item: function item(data) {
return JSON.stringify(data, null, 2);
}
};
var withUsage$r = createDocumentationMessageGenerator({
name: 'infinite-hits'
});
var suit$9 = component('InfiniteHits');
var renderer$6 = function renderer(_ref) {
var cssClasses = _ref.cssClasses,
containerNode = _ref.containerNode,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var hits = _ref2.hits,
results = _ref2.results,
showMore = _ref2.showMore,
isLastPage = _ref2.isLastPage,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$4,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(InfiniteHits, {
cssClasses: cssClasses,
hits: hits,
results: results,
showMore: showMore,
templateProps: renderState.templateProps,
isLastPage: isLastPage
}), containerNode);
};
};
/**
* @typedef {Object} InfiniteHitsTemplates
* @property {string|function} [empty = "No results"] Template used when there are no results.
* @property {string|function} [showMoreText = "Show more results"] Template used for the "load more" button.
* @property {string|function} [item = ""] Template used for each result. This template will receive an object containing a single record.
*/
/**
* @typedef {object} InfiniteHitsCSSClasses
* @property {string|string[]} [root] CSS class to add to the wrapping element.
* @property {string|string[]} [emptyRoot] CSS class to add to the wrapping element when no results.
* @property {string|string[]} [list] CSS class to add to the list of results.
* @property {string|string[]} [item] CSS class to add to each result.
* @property {string|string[]} [loadMore] CSS class to add to the load more button.
* @property {string|string[]} [disabledLoadMore] CSS class to add to the load more button when disabled.
*/
/**
* @typedef {Object} InfiniteHitsWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {InfiniteHitsTemplates} [templates] Templates to use for the widget.
* @property {InfiniteHitsCSSClasses} [cssClasses] CSS classes to add.
* @property {boolean} [escapeHTML = true] Escape HTML entities from hits string values.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* Display the list of results (hits) from the current search.
*
* This widget uses the infinite hits pattern. It contains a button that
* will let the user load more results to the list. This is particularly
* handy on mobile implementations.
* @type {WidgetFactory}
* @devNovel InfiniteHits
* @category basic
* @param {InfiniteHitsWidgetOptions} $0 The options for the InfiniteHits widget.
* @return {Widget} Creates a new instance of the InfiniteHits widget.
* @example
* search.addWidget(
* instantsearch.widgets.infiniteHits({
* container: '#infinite-hits-container',
* templates: {
* empty: 'No results',
* showMoreText: 'Show more results',
* item: 'Hit {{objectID}} : {{{_highlightResult.name.value}}}'
* },
* transformItems: items => items.map(item => item),
* })
* );
*/
function infiniteHits() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
escapeHTML = _ref3.escapeHTML,
transformItems = _ref3.transformItems,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$4 : _ref3$templates,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
if (!container) {
throw new Error(withUsage$r('The `container` option is required.'));
} // We have this specific check because unlike `hits`, `infiniteHits` does not support
// the `allItems` template. This can be misleading as they are very similar.
_warning(typeof templates.allItems === 'undefined', "The template `allItems` does not exist since InstantSearch.js 3.\n\n You may want to migrate using `connectInfiniteHits`: ".concat(createDocumentationLink({
name: 'infinite-hits',
connector: true
}), "."));
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$9(), userCssClasses.root),
emptyRoot: classnames(suit$9({
modifierName: 'empty'
}), userCssClasses.emptyRoot),
item: classnames(suit$9({
descendantName: 'item'
}), userCssClasses.item),
list: classnames(suit$9({
descendantName: 'list'
}), userCssClasses.list),
loadMore: classnames(suit$9({
descendantName: 'loadMore'
}), userCssClasses.loadMore),
disabledLoadMore: classnames(suit$9({
descendantName: 'loadMore',
modifierName: 'disabled'
}), userCssClasses.disabledLoadMore)
};
var specializedRenderer = renderer$6({
containerNode: containerNode,
cssClasses: cssClasses,
templates: templates,
renderState: {}
});
var makeInfiniteHits = connectInfiniteHits(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeInfiniteHits({
escapeHTML: escapeHTML,
transformItems: transformItems
});
}
/* eslint-disable max-len */
var defaultTemplates$5 = {
item: '' + '{{label}} ' + '{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}} ' + ' ',
showMoreText: "\n {{#isShowingMore}}\n Show less\n {{/isShowingMore}}\n {{^isShowingMore}}\n Show more\n {{/isShowingMore}}\n "
};
var withUsage$s = createDocumentationMessageGenerator({
name: 'menu'
});
var suit$a = component('Menu');
var renderer$7 = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates,
showMore = _ref.showMore;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
items = _ref2.items,
createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance,
isShowingMore = _ref2.isShowingMore,
toggleShowMore = _ref2.toggleShowMore,
canToggleShowMore = _ref2.canToggleShowMore;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$5,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
var facetValues = items.map(function (facetValue) {
return _objectSpread({}, facetValue, {
url: createURL(facetValue.name)
});
});
render$1(index.createElement(RefinementList$1, {
createURL: createURL,
cssClasses: cssClasses,
facetValues: facetValues,
showMore: showMore,
templateProps: renderState.templateProps,
toggleRefinement: refine,
toggleShowMore: toggleShowMore,
isShowingMore: isShowingMore,
canToggleShowMore: canToggleShowMore
}), containerNode);
};
};
/**
* @typedef {Object} MenuCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element when no refinements.
* @property {string|string[]} [list] CSS class to add to the list element.
* @property {string|string[]} [item] CSS class to add to each item element.
* @property {string|string[]} [selectedItem] CSS class to add to each selected item element.
* @property {string|string[]} [link] CSS class to add to each link (when using the default template).
* @property {string|string[]} [label] CSS class to add to each label (when using the default template).
* @property {string|string[]} [count] CSS class to add to each count element (when using the default template).
* @property {string|string[]} [showMore] CSS class to add to the show more button.
* @property {string|string[]} [disabledShowMore] CSS class to add to the disabled show more button.
*/
/**
* @typedef {Object} MenuTemplates
* @property {string|function({count: number, cssClasses: object, isRefined: boolean, label: string, url: string, value: string}):string} [item] Item template. The string template gets the same values as the function.
* @property {string} [showMoreText] Template used for the show more text, provided with `isShowingMore` data property.
*/
/**
* @typedef {Object} MenuWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {string} attribute Name of the attribute for faceting
* @property {string[]|function} [sortBy=['isRefined', 'name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
* @property {MenuTemplates} [templates] Customize the output through templating.
* @property {number} [limit=10] How many facets values to retrieve.
* @property {boolean} [showMore=false] Limit the number of results and display a showMore button.
* @property {number} [showMoreLimit=20] Max number of values to display when showing more.
* @property {MenuCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* Create a menu based on a facet. A menu displays facet values and let the user selects only one value at a time.
* It also displays an empty value which lets the user "unselect" any previous selection.
*
* @requirements
* The attribute passed to `attribute` must be declared as an
* [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting)
* in your Algolia settings.
* @type {WidgetFactory}
* @devNovel Menu
* @category filter
* @param {MenuWidgetOptions} $0 The Menu widget options.
* @return {Widget} Creates a new instance of the Menu widget.
* @example
* search.addWidget(
* instantsearch.widgets.menu({
* container: '#categories',
* attribute: 'hierarchicalCategories.lvl0',
* limit: 10,
* })
* );
*/
function menu(_ref3) {
var container = _ref3.container,
attribute = _ref3.attribute,
sortBy = _ref3.sortBy,
limit = _ref3.limit,
showMore = _ref3.showMore,
showMoreLimit = _ref3.showMoreLimit,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$5 : _ref3$templates,
transformItems = _ref3.transformItems;
if (!container) {
throw new Error(withUsage$s('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$a(), userCssClasses.root),
noRefinementRoot: classnames(suit$a({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$a({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$a({
descendantName: 'item'
}), userCssClasses.item),
selectedItem: classnames(suit$a({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
link: classnames(suit$a({
descendantName: 'link'
}), userCssClasses.link),
label: classnames(suit$a({
descendantName: 'label'
}), userCssClasses.label),
count: classnames(suit$a({
descendantName: 'count'
}), userCssClasses.count),
showMore: classnames(suit$a({
descendantName: 'showMore'
}), userCssClasses.showMore),
disabledShowMore: classnames(suit$a({
descendantName: 'showMore',
modifierName: 'disabled'
}), userCssClasses.disabledShowMore)
};
var specializedRenderer = renderer$7({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates,
showMore: showMore
});
var makeWidget = connectMenu(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
attribute: attribute,
limit: limit,
showMore: showMore,
showMoreLimit: showMoreLimit,
sortBy: sortBy,
transformItems: transformItems
});
}
var defaultTemplates$6 = {
item: "\n \n {{{highlighted}}} \n {{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}} \n ",
showMoreText: "\n {{#isShowingMore}}\n Show less\n {{/isShowingMore}}\n {{^isShowingMore}}\n Show more\n {{/isShowingMore}}\n ",
searchableNoResults: 'No results'
};
var withUsage$t = createDocumentationMessageGenerator({
name: 'refinement-list'
});
var suit$b = component('RefinementList');
var renderer$8 = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
templates = _ref.templates,
renderState = _ref.renderState,
showMore = _ref.showMore,
searchable = _ref.searchable,
searchablePlaceholder = _ref.searchablePlaceholder,
searchableIsAlwaysActive = _ref.searchableIsAlwaysActive;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
items = _ref2.items,
createURL = _ref2.createURL,
searchForItems = _ref2.searchForItems,
isFromSearch = _ref2.isFromSearch,
instantSearchInstance = _ref2.instantSearchInstance,
toggleShowMore = _ref2.toggleShowMore,
isShowingMore = _ref2.isShowingMore,
hasExhaustiveItems = _ref2.hasExhaustiveItems,
canToggleShowMore = _ref2.canToggleShowMore;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$6,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(RefinementList$1, {
createURL: createURL,
cssClasses: cssClasses,
facetValues: items,
templateProps: renderState.templateProps,
toggleRefinement: refine,
searchFacetValues: searchable ? searchForItems : undefined,
searchPlaceholder: searchablePlaceholder,
searchIsAlwaysActive: searchableIsAlwaysActive,
isFromSearch: isFromSearch,
showMore: showMore,
toggleShowMore: toggleShowMore,
isShowingMore: isShowingMore,
hasExhaustiveItems: hasExhaustiveItems,
canToggleShowMore: canToggleShowMore
}), containerNode);
};
};
/**
* @typedef {Object} RefinementListTemplates
* @property {string|function(RefinementListItemData):string} [item] Item template, provided with `label`, `highlighted`, `value`, `count`, `isRefined`, `url` data properties.
* @property {string|function} [searchableNoResults] Templates to use for search for facet values.
* @property {string|function} [showMoreText] Template used for the show more text, provided with `isShowingMore` data property.
*/
/**
* @typedef {Object} RefinementListItemData
* @property {number} count The number of occurrences of the facet in the result set.
* @property {boolean} isRefined True if the value is selected.
* @property {string} label The label to display.
* @property {string} value The value used for refining.
* @property {string} highlighted The label highlighted (when using search for facet values). This value is displayed in the default template.
* @property {string} url The url with this refinement selected.
* @property {object} cssClasses Object containing all the classes computed for the item.
*/
/**
* @typedef {Object} RefinementListCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element when no refinements.
* @property {string|string[]} [noResults] CSS class to add to the root element with no results.
* @property {string|string[]} [list] CSS class to add to the list element.
* @property {string|string[]} [item] CSS class to add to each item element.
* @property {string|string[]} [selectedItem] CSS class to add to each selected element.
* @property {string|string[]} [label] CSS class to add to each label element (when using the default template).
* @property {string|string[]} [checkbox] CSS class to add to each checkbox element (when using the default template).
* @property {string|string[]} [labelText] CSS class to add to each label text element.
* @property {string|string[]} [showMore] CSS class to add to the show more element
* @property {string|string[]} [disabledShowMore] CSS class to add to the disabledshow more element
* @property {string|string[]} [count] CSS class to add to each count element (when using the default template).
*/
/**
* @typedef {Object} RefinementListWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {string} attribute Name of the attribute for faceting.
* @property {"and"|"or"} [operator="or"] How to apply refinements. Possible values: `or`, `and`
* @property {string[]|function} [sortBy=["isRefined", "count:desc", "name:asc"]] How to sort refinements. Possible values: `count:asc` `count:desc` `name:asc` `name:desc` `isRefined`.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
* @property {boolean} [searchable=false] Add a search input to let the user search for more facet values. In order to make this feature work, you need to make the attribute searchable [using the API](https://www.algolia.com/doc/guides/searching/faceting/?language=js#declaring-a-searchable-attribute-for-faceting) or [the dashboard](https://www.algolia.com/explorer/display/).
* @property {number} [limit = 10] The minimum number of facet values to retrieve.
* @property {boolean} [showMore = false] Whether to display a button that expands the number of items.
* @property {number} [showMoreLimit = 20] The max number of items to display if the widget
* @property {string} [searchablePlaceholder] Value of the search field placeholder.
* @property {boolean} [searchableIsAlwaysActive=true] When `false` the search field will become disabled if
* there are less items to display than the `options.limit`, otherwise the search field is always usable.
* @property {boolean} [searchableEscapeFacetValues=true] When activated, it will escape the facet values that are returned
* from Algolia. In this case, the surrounding tags will always be ` `.
* @property {RefinementListTemplates} [templates] Templates to use for the widget.
* @property {RefinementListCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
*/
/**
* The refinement list widget is one of the most common widget that you can find
* in a search UI. With this widget, the user can filter the dataset based on facets.
*
* The refinement list displays only the most relevant facets for the current search
* context. The sort option only affects the facet that are returned by the engine,
* not which facets are returned.
*
* This widget also implements search for facet values, which is a mini search inside the
* values of the facets. This makes easy to deal with uncommon facet values.
*
* @requirements
*
* The attribute passed to `attribute` must be declared as an
* [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting)
* in your Algolia settings.
*
* If you also want to use search for facet values on this attribute, you need to make it searchable using the [dashboard](https://www.algolia.com/explorer/display/) or using the [API](https://www.algolia.com/doc/guides/searching/faceting/#search-for-facet-values).
*
* @type {WidgetFactory}
* @devNovel RefinementList
* @category filter
* @param {RefinementListWidgetOptions} $0 The RefinementList widget options that you use to customize the widget.
* @return {Widget} Creates a new instance of the RefinementList widget.
* @example
* search.addWidget(
* instantsearch.widgets.refinementList({
* container: '#brands',
* attribute: 'brand',
* operator: 'or',
* limit: 10,
* })
* );
*/
function refinementList() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attribute = _ref3.attribute,
operator = _ref3.operator,
sortBy = _ref3.sortBy,
limit = _ref3.limit,
showMore = _ref3.showMore,
showMoreLimit = _ref3.showMoreLimit,
_ref3$searchable = _ref3.searchable,
searchable = _ref3$searchable === void 0 ? false : _ref3$searchable,
_ref3$searchablePlace = _ref3.searchablePlaceholder,
searchablePlaceholder = _ref3$searchablePlace === void 0 ? 'Search...' : _ref3$searchablePlace,
_ref3$searchableEscap = _ref3.searchableEscapeFacetValues,
searchableEscapeFacetValues = _ref3$searchableEscap === void 0 ? true : _ref3$searchableEscap,
_ref3$searchableIsAlw = _ref3.searchableIsAlwaysActive,
searchableIsAlwaysActive = _ref3$searchableIsAlw === void 0 ? true : _ref3$searchableIsAlw,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$6 : _ref3$templates,
transformItems = _ref3.transformItems;
if (!container) {
throw new Error(withUsage$t('The `container` option is required.'));
}
var escapeFacetValues = searchable ? Boolean(searchableEscapeFacetValues) : false;
var containerNode = getContainerNode(container);
var allTemplates = _objectSpread({}, defaultTemplates$6, templates);
var cssClasses = {
root: classnames(suit$b(), userCssClasses.root),
noRefinementRoot: classnames(suit$b({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$b({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$b({
descendantName: 'item'
}), userCssClasses.item),
selectedItem: classnames(suit$b({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
searchBox: classnames(suit$b({
descendantName: 'searchBox'
}), userCssClasses.searchBox),
label: classnames(suit$b({
descendantName: 'label'
}), userCssClasses.label),
checkbox: classnames(suit$b({
descendantName: 'checkbox'
}), userCssClasses.checkbox),
labelText: classnames(suit$b({
descendantName: 'labelText'
}), userCssClasses.labelText),
count: classnames(suit$b({
descendantName: 'count'
}), userCssClasses.count),
noResults: classnames(suit$b({
descendantName: 'noResults'
}), userCssClasses.noResults),
showMore: classnames(suit$b({
descendantName: 'showMore'
}), userCssClasses.showMore),
disabledShowMore: classnames(suit$b({
descendantName: 'showMore',
modifierName: 'disabled'
}), userCssClasses.disabledShowMore)
};
var specializedRenderer = renderer$8({
containerNode: containerNode,
cssClasses: cssClasses,
templates: allTemplates,
renderState: {},
searchable: searchable,
searchablePlaceholder: searchablePlaceholder,
searchableIsAlwaysActive: searchableIsAlwaysActive,
showMore: showMore
});
var makeWidget = connectRefinementList(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
attribute: attribute,
operator: operator,
limit: limit,
showMore: showMore,
showMoreLimit: showMoreLimit,
sortBy: sortBy,
escapeFacetValues: escapeFacetValues,
transformItems: transformItems
});
}
/* eslint-disable max-len */
var defaultTemplates$7 = {
item: "\n \n {{label}} \n "
};
var withUsage$u = createDocumentationMessageGenerator({
name: 'numeric-menu'
});
var suit$c = component('NumericMenu');
var renderer$9 = function renderer(_ref) {
var containerNode = _ref.containerNode,
attribute = _ref.attribute,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance,
refine = _ref2.refine,
items = _ref2.items;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$7,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(RefinementList$1, {
createURL: createURL,
cssClasses: cssClasses,
facetValues: items,
templateProps: renderState.templateProps,
toggleRefinement: refine,
attribute: attribute
}), containerNode);
};
};
/**
* @typedef {Object} NumericMenuCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element when no refinements.
* @property {string|string[]} [list] CSS class to add to the list element.
* @property {string|string[]} [item] CSS class to add to each item element.
* @property {string|string[]} [selectedItem] CSS class to add to each selected item element.
* @property {string|string[]} [label] CSS class to add to each label element.
* @property {string|string[]} [labelText] CSS class to add to each label text element.
* @property {string|string[]} [radio] CSS class to add to each radio element (when using the default template).
*/
/**
* @typedef {Object} NumericMenuTemplates
* @property {string|function} [item] Item template, provided with `label` (the name in the configuration), `isRefined`, `url`, `value` (the setting for the filter) data properties.
*/
/**
* @typedef {Object} NumericMenuOption
* @property {string} label Label of the option.
* @property {number} [start] Low bound of the option (>=).
* @property {number} [end] High bound of the option (<=).
*/
/**
* @typedef {Object} NumericMenuWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {string} attribute Name of the attribute for filtering.
* @property {NumericMenuOption[]} items List of all the items.
* @property {NumericMenuTemplates} [templates] Templates to use for the widget.
* @property {NumericMenuCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* The numeric menu is a widget that displays a list of numeric filters in a list. Those numeric filters
* are pre-configured with creating the widget.
*
* @requirements
* The attribute passed to `attribute` must be declared as an [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting) in your
* Algolia settings.
*
* The values inside this attribute must be JavaScript numbers and not strings.
*
* @type {WidgetFactory}
* @devNovel NumericMenu
* @category filter
* @param {NumericMenuWidgetOptions} $0 The NumericMenu widget items
* @return {Widget} Creates a new instance of the NumericMenu widget.
* @example
* search.addWidget(
* instantsearch.widgets.numericMenu({
* container: '#popularity',
* attribute: 'popularity',
* items: [
* { label: 'All' },
* { end: 500, label: 'less than 500' },
* { start: 500, end: 2000, label: 'between 500 and 2000' },
* { start: 2000, label: 'more than 2000' }
* ]
* })
* );
*/
function numericMenu() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attribute = _ref3.attribute,
items = _ref3.items,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$7 : _ref3$templates,
transformItems = _ref3.transformItems;
if (!container) {
throw new Error(withUsage$u('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$c(), userCssClasses.root),
noRefinementRoot: classnames(suit$c({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$c({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$c({
descendantName: 'item'
}), userCssClasses.item),
selectedItem: classnames(suit$c({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
label: classnames(suit$c({
descendantName: 'label'
}), userCssClasses.label),
radio: classnames(suit$c({
descendantName: 'radio'
}), userCssClasses.radio),
labelText: classnames(suit$c({
descendantName: 'labelText'
}), userCssClasses.labelText)
};
var specializedRenderer = renderer$9({
containerNode: containerNode,
attribute: attribute,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeNumericMenu = connectNumericMenu(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeNumericMenu({
attribute: attribute,
items: items,
transformItems: transformItems
});
}
/**
* Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
* objects into destination objects that are passed thru.
*
* @private
* @param {*} objValue The destination value.
* @param {*} srcValue The source value.
* @param {string} key The key of the property to merge.
* @param {Object} object The parent object of `objValue`.
* @param {Object} source The parent object of `srcValue`.
* @param {Object} [stack] Tracks traversed source values and their merged
* counterparts.
* @returns {*} Returns the value to assign.
*/
function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
if (isObject_1(objValue) && isObject_1(srcValue)) {
// Recursively merge objects and arrays (susceptible to call stack limits).
stack.set(srcValue, objValue);
_baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
stack['delete'](srcValue);
}
return objValue;
}
var _customDefaultsMerge = customDefaultsMerge;
/**
* This method is like `_.defaults` except that it recursively assigns
* default properties.
*
* **Note:** This method mutates `object`.
*
* @static
* @memberOf _
* @since 3.10.0
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
* @see _.defaults
* @example
*
* _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
* // => { 'a': { 'b': 2, 'c': 3 } }
*/
var defaultsDeep = _baseRest(function(args) {
args.push(undefined, _customDefaultsMerge);
return _apply(mergeWith_1, undefined, args);
});
var defaultsDeep_1 = defaultsDeep;
var PaginationLink =
/*#__PURE__*/
function (_Component) {
_inherits(PaginationLink, _Component);
function PaginationLink() {
_classCallCheck(this, PaginationLink);
return _possibleConstructorReturn(this, _getPrototypeOf(PaginationLink).apply(this, arguments));
}
_createClass(PaginationLink, [{
key: "componentWillMount",
value: function componentWillMount() {
this.handleClick = this.handleClick.bind(this);
}
}, {
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps) {
return !isEqual_1(this.props, nextProps);
}
}, {
key: "handleClick",
value: function handleClick(e) {
this.props.handleClick(this.props.pageNumber, e);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
cssClasses = _this$props.cssClasses,
label = _this$props.label,
ariaLabel = _this$props.ariaLabel,
url = _this$props.url,
isDisabled = _this$props.isDisabled;
var tagName = 'span';
var attributes = {
className: cssClasses.link,
dangerouslySetInnerHTML: {
__html: label
}
}; // "Enable" the element, by making it a link
if (!isDisabled) {
tagName = 'a';
attributes = _objectSpread({}, attributes, {
'aria-label': ariaLabel,
href: url,
onClick: this.handleClick
});
}
var element = index.createElement(tagName, attributes);
return index.createElement("li", {
className: cssClasses.item
}, element);
}
}]);
return PaginationLink;
}(Component$1);
var Pagination =
/*#__PURE__*/
function (_Component) {
_inherits(Pagination, _Component);
function Pagination(props) {
var _this;
_classCallCheck(this, Pagination);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Pagination).call(this, defaultsDeep_1(props, Pagination.defaultProps)));
_this.handleClick = _this.handleClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
return _this;
}
_createClass(Pagination, [{
key: "pageLink",
value: function pageLink(_ref) {
var label = _ref.label,
ariaLabel = _ref.ariaLabel,
pageNumber = _ref.pageNumber,
_ref$additionalClassN = _ref.additionalClassName,
additionalClassName = _ref$additionalClassN === void 0 ? null : _ref$additionalClassN,
_ref$isDisabled = _ref.isDisabled,
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
_ref$isSelected = _ref.isSelected,
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
createURL = _ref.createURL;
var cssClasses = {
item: classnames(this.props.cssClasses.item, additionalClassName),
link: this.props.cssClasses.link
};
if (isDisabled) {
cssClasses.item = classnames(cssClasses.item, this.props.cssClasses.disabledItem);
} else if (isSelected) {
cssClasses.item = classnames(cssClasses.item, this.props.cssClasses.selectedItem);
}
var url = createURL && !isDisabled ? createURL(pageNumber) : '#';
return index.createElement(PaginationLink, {
ariaLabel: ariaLabel,
cssClasses: cssClasses,
handleClick: this.handleClick,
isDisabled: isDisabled,
key: label + pageNumber + ariaLabel,
label: label,
pageNumber: pageNumber,
url: url
});
}
}, {
key: "previousPageLink",
value: function previousPageLink(_ref2) {
var isFirstPage = _ref2.isFirstPage,
currentPage = _ref2.currentPage,
createURL = _ref2.createURL;
return this.pageLink({
ariaLabel: 'Previous',
additionalClassName: this.props.cssClasses.previousPageItem,
isDisabled: this.props.nbHits === 0 || isFirstPage,
label: this.props.templates.previous,
pageNumber: currentPage - 1,
createURL: createURL
});
}
}, {
key: "nextPageLink",
value: function nextPageLink(_ref3) {
var isLastPage = _ref3.isLastPage,
currentPage = _ref3.currentPage,
createURL = _ref3.createURL;
return this.pageLink({
ariaLabel: 'Next',
additionalClassName: this.props.cssClasses.nextPageItem,
isDisabled: this.props.nbHits === 0 || isLastPage,
label: this.props.templates.next,
pageNumber: currentPage + 1,
createURL: createURL
});
}
}, {
key: "firstPageLink",
value: function firstPageLink(_ref4) {
var isFirstPage = _ref4.isFirstPage,
createURL = _ref4.createURL;
return this.pageLink({
ariaLabel: 'First',
additionalClassName: this.props.cssClasses.firstPageItem,
isDisabled: this.props.nbHits === 0 || isFirstPage,
label: this.props.templates.first,
pageNumber: 0,
createURL: createURL
});
}
}, {
key: "lastPageLink",
value: function lastPageLink(_ref5) {
var isLastPage = _ref5.isLastPage,
nbPages = _ref5.nbPages,
createURL = _ref5.createURL;
return this.pageLink({
ariaLabel: 'Last',
additionalClassName: this.props.cssClasses.lastPageItem,
isDisabled: this.props.nbHits === 0 || isLastPage,
label: this.props.templates.last,
pageNumber: nbPages - 1,
createURL: createURL
});
}
}, {
key: "pages",
value: function pages(_ref6) {
var _this2 = this;
var currentPage = _ref6.currentPage,
_pages = _ref6.pages,
createURL = _ref6.createURL;
return _pages.map(function (pageNumber) {
return _this2.pageLink({
ariaLabel: pageNumber + 1,
additionalClassName: _this2.props.cssClasses.pageItem,
isSelected: pageNumber === currentPage,
label: pageNumber + 1,
pageNumber: pageNumber,
createURL: createURL
});
});
}
}, {
key: "handleClick",
value: function handleClick(pageNumber, event) {
if (isSpecialClick(event)) {
// do not alter the default browser behavior
// if one special key is down
return;
}
event.preventDefault();
this.props.setCurrentPage(pageNumber);
}
}, {
key: "render",
value: function render() {
return index.createElement("div", {
className: classnames(this.props.cssClasses.root, _defineProperty({}, this.props.cssClasses.noRefinementRoot, this.props.isFirstPage))
}, index.createElement("ul", {
className: this.props.cssClasses.list
}, this.props.showFirst && this.firstPageLink(this.props), this.props.showPrevious && this.previousPageLink(this.props), this.pages(this.props), this.props.showNext && this.nextPageLink(this.props), this.props.showLast && this.lastPageLink(this.props)));
}
}]);
return Pagination;
}(Component$1);
Pagination.defaultProps = {
nbHits: 0,
currentPage: 0,
nbPages: 0
};
var withUsage$v = createDocumentationMessageGenerator({
name: 'pagination'
});
var suit$d = component('Pagination');
var defaultTemplates$8 = {
previous: '‹',
next: '›',
first: '«',
last: '»'
};
var renderer$a = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
templates = _ref.templates,
totalPages = _ref.totalPages,
showFirst = _ref.showFirst,
showLast = _ref.showLast,
showPrevious = _ref.showPrevious,
showNext = _ref.showNext,
scrollToNode = _ref.scrollToNode;
return function (_ref2, isFirstRendering) {
var createURL = _ref2.createURL,
currentRefinement = _ref2.currentRefinement,
nbHits = _ref2.nbHits,
nbPages = _ref2.nbPages,
pages = _ref2.pages,
isFirstPage = _ref2.isFirstPage,
isLastPage = _ref2.isLastPage,
refine = _ref2.refine;
if (isFirstRendering) return;
var setCurrentPage = function setCurrentPage(pageNumber) {
refine(pageNumber);
if (scrollToNode !== false) {
scrollToNode.scrollIntoView();
}
};
render$1(index.createElement(Pagination, {
createURL: createURL,
cssClasses: cssClasses,
currentPage: currentRefinement,
templates: templates,
nbHits: nbHits,
nbPages: nbPages,
pages: pages,
totalPages: totalPages,
isFirstPage: isFirstPage,
isLastPage: isLastPage,
setCurrentPage: setCurrentPage,
showFirst: showFirst,
showLast: showLast,
showPrevious: showPrevious,
showNext: showNext
}), containerNode);
};
};
/**
* @typedef {Object} PaginationCSSClasses
* @property {string|string[]} [root] CSS classes added to the root element of the widget.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element of the widget if there are no refinements.
* @property {string|string[]} [list] CSS classes added to the wrapping ``.
* @property {string|string[]} [item] CSS classes added to each ``.
* @property {string|string[]} [itemFirstPage] CSS classes added to the first ` `.
* @property {string|string[]} [itemLastPage] CSS classes added to the last ` `.
* @property {string|string[]} [itemPreviousPage] CSS classes added to the previous ` `.
* @property {string|string[]} [itemNextPage] CSS classes added to the next ` `.
* @property {string|string[]} [itemPage] CSS classes added to page ` `.
* @property {string|string[]} [selectedItem] CSS classes added to the selected ` `.
* @property {string|string[]} [disabledItem] CSS classes added to the disabled ` `.
* @property {string|string[]} [link] CSS classes added to each link.
*/
/**
* @typedef {Object} PaginationTemplates
* @property {string} [previous] Label for the Previous link.
* @property {string} [next] Label for the Next link.
* @property {string} [first] Label for the First link.
* @property {string} [last] Label for the Last link.
*/
/**
* @typedef {Object} PaginationWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {number} [totalPages] The max number of pages to browse.
* @property {number} [padding=3] The number of pages to display on each side of the current page.
* @property {string|HTMLElement|boolean} [scrollTo='body'] Where to scroll after a click, set to `false` to disable.
* @property {boolean} [showFirst=true] Whether to show the “first page” control
* @property {boolean} [showLast=true] Whether to show the last page” control
* @property {boolean} [showNext=true] Whether to show the “next page” control
* @property {boolean} [showPrevious=true] Whether to show the “previous page” control
* @property {PaginationTemplates} [templates] Text to display in the links.
* @property {PaginationCSSClasses} [cssClasses] CSS classes to be added.
*/
/**
* The pagination widget allow the user to switch between pages of the results.
*
* This is an alternative to using the *show more* pattern, that allows the user
* only to display more items. The *show more* pattern is usually preferred
* because it is simpler to use, and it is more convenient in a mobile context.
* See the infinite hits widget, for more information.
*
* When using the pagination with Algolia, you should be aware that the engine won't provide you pages
* beyond the 1000th hits by default. You can find more information on the [Algolia documentation](https://www.algolia.com/doc/guides/searching/pagination/#pagination-limitations).
*
* @type {WidgetFactory}
* @devNovel Pagination
* @category navigation
* @param {PaginationWidgetOptions} $0 Options for the Pagination widget.
* @return {Widget} A new instance of Pagination widget.
* @example
* search.addWidget(
* instantsearch.widgets.pagination({
* container: '#pagination-container',
* totalPages: 20,
* // default is to scroll to 'body', here we disable this behavior
* scrollTo: false,
* showFirst: false,
* showLast: false,
* })
* );
*/
function pagination() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
_ref3$templates = _ref3.templates,
userTemplates = _ref3$templates === void 0 ? {} : _ref3$templates,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
totalPages = _ref3.totalPages,
padding = _ref3.padding,
_ref3$showFirst = _ref3.showFirst,
showFirst = _ref3$showFirst === void 0 ? true : _ref3$showFirst,
_ref3$showLast = _ref3.showLast,
showLast = _ref3$showLast === void 0 ? true : _ref3$showLast,
_ref3$showPrevious = _ref3.showPrevious,
showPrevious = _ref3$showPrevious === void 0 ? true : _ref3$showPrevious,
_ref3$showNext = _ref3.showNext,
showNext = _ref3$showNext === void 0 ? true : _ref3$showNext,
_ref3$scrollTo = _ref3.scrollTo,
userScrollTo = _ref3$scrollTo === void 0 ? 'body' : _ref3$scrollTo;
if (!container) {
throw new Error(withUsage$v('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var scrollTo = userScrollTo === true ? 'body' : userScrollTo;
var scrollToNode = scrollTo !== false ? getContainerNode(scrollTo) : false;
var cssClasses = {
root: classnames(suit$d(), userCssClasses.root),
noRefinementRoot: classnames(suit$d({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$d({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$d({
descendantName: 'item'
}), userCssClasses.item),
firstPageItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'firstPage'
}), userCssClasses.firstPageItem),
lastPageItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'lastPage'
}), userCssClasses.lastPageItem),
previousPageItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'previousPage'
}), userCssClasses.previousPageItem),
nextPageItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'nextPage'
}), userCssClasses.nextPageItem),
pageItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'page'
}), userCssClasses.pageItem),
selectedItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
disabledItem: classnames(suit$d({
descendantName: 'item',
modifierName: 'disabled'
}), userCssClasses.disabledItem),
link: classnames(suit$d({
descendantName: 'link'
}), userCssClasses.link)
};
var templates = _objectSpread({}, defaultTemplates$8, userTemplates);
var specializedRenderer = renderer$a({
containerNode: containerNode,
cssClasses: cssClasses,
templates: templates,
showFirst: showFirst,
showLast: showLast,
showPrevious: showPrevious,
showNext: showNext,
padding: padding,
scrollToNode: scrollToNode
});
var makeWidget = connectPagination(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
totalPages: totalPages,
padding: padding
});
}
var RangeInput =
/*#__PURE__*/
function (_Component) {
_inherits(RangeInput, _Component);
function RangeInput(props) {
var _this;
_classCallCheck(this, RangeInput);
_this = _possibleConstructorReturn(this, _getPrototypeOf(RangeInput).call(this, props));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (name) {
return function (event) {
_this.setState(_defineProperty({}, name, event.currentTarget.value));
};
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onSubmit", function (event) {
event.preventDefault();
_this.props.refine([_this.state.min, _this.state.max]);
});
_this.state = {
min: props.values.min,
max: props.values.max
};
return _this;
}
_createClass(RangeInput, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
this.setState({
min: nextProps.values.min,
max: nextProps.values.max
});
}
}, {
key: "render",
value: function render() {
var _this$state = this.state,
minValue = _this$state.min,
maxValue = _this$state.max;
var _this$props = this.props,
min = _this$props.min,
max = _this$props.max,
step = _this$props.step,
cssClasses = _this$props.cssClasses,
templateProps = _this$props.templateProps;
var isDisabled = min >= max;
var hasRefinements = Boolean(minValue || maxValue);
var rootClassNames = classnames(cssClasses.root, _defineProperty({}, cssClasses.noRefinement, !hasRefinements));
return index.createElement("div", {
className: rootClassNames
}, index.createElement("form", {
className: cssClasses.form,
onSubmit: this.onSubmit
}, index.createElement("label", {
className: cssClasses.label
}, index.createElement("input", {
className: classnames(cssClasses.input, cssClasses.inputMin),
type: "number",
min: min,
max: max,
step: step,
value: minValue,
onChange: this.onChange('min'),
placeholder: min,
disabled: isDisabled
})), index.createElement(Template, _extends({}, templateProps, {
templateKey: "separatorText",
rootTagName: "span",
rootProps: {
className: cssClasses.separator
}
})), index.createElement("label", {
className: cssClasses.label
}, index.createElement("input", {
className: classnames(cssClasses.input, cssClasses.inputMax),
type: "number",
min: min,
max: max,
step: step,
value: maxValue,
onChange: this.onChange('max'),
placeholder: max,
disabled: isDisabled
})), index.createElement(Template, _extends({}, templateProps, {
templateKey: "submitText",
rootTagName: "button",
rootProps: {
type: 'submit',
className: cssClasses.submit,
disabled: isDisabled
}
}))));
}
}]);
return RangeInput;
}(Component$1);
var withUsage$w = createDocumentationMessageGenerator({
name: 'range-input'
});
var suit$e = component('RangeInput');
var renderer$b = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
range = _ref2.range,
start = _ref2.start,
widgetParams = _ref2.widgetParams,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
var rangeMin = range.min,
rangeMax = range.max;
var _start = _slicedToArray(start, 2),
minValue = _start[0],
maxValue = _start[1];
var step = 1 / Math.pow(10, widgetParams.precision);
var values = {
min: minValue !== -Infinity && minValue !== rangeMin ? minValue : undefined,
max: maxValue !== Infinity && maxValue !== rangeMax ? maxValue : undefined
};
render$1(index.createElement(RangeInput, {
min: rangeMin,
max: rangeMax,
step: step,
values: values,
cssClasses: cssClasses,
refine: refine,
templateProps: renderState.templateProps
}), containerNode);
};
};
/**
* @typedef {Object} RangeInputClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinement] CSS class to add to the root element when there's no refinements.
* @property {string|string[]} [form] CSS class to add to the form element.
* @property {string|string[]} [label] CSS class to add to the label element.
* @property {string|string[]} [input] CSS class to add to the input element.
* @property {string|string[]} [inputMin] CSS class to add to the min input element.
* @property {string|string[]} [inputMax] CSS class to add to the max input element.
* @property {string|string[]} [separator] CSS class to add to the separator of the form.
* @property {string|string[]} [submit] CSS class to add to the submit button of the form.
*/
/**
* @typedef {Object} RangeInputTemplates
* @property {string} [separatorText = "to"] The label of the separator, between min and max.
* @property {string} [submitText = "Go"] The label of the submit button.
*/
/**
* @typedef {Object} RangeInputWidgetOptions
* @property {string|HTMLElement} container Valid CSS Selector as a string or DOMElement.
* @property {string} attribute Name of the attribute for faceting.
* @property {number} [min] Minimal slider value, default to automatically computed from the result set.
* @property {number} [max] Maximal slider value, defaults to automatically computed from the result set.
* @property {number} [precision = 0] Number of digits after decimal point to use.
* @property {RangeInputTemplates} [templates] Labels to use for the widget.
* @property {RangeInputClasses} [cssClasses] CSS classes to add.
*/
/**
* The range input widget allows a user to select a numeric range using a minimum and maximum input.
*
* @requirements
* The attribute passed to `attribute` must be declared as an
* [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting)
* in your Algolia settings.
*
* The values inside this attribute must be JavaScript numbers (not strings).
* @type {WidgetFactory}
* @devNovel RangeInput
* @category filter
* @param {RangeInputWidgetOptions} $0 The RangeInput widget options.
* @return {Widget} A new instance of RangeInput widget.
* @example
* search.addWidget(
* instantsearch.widgets.rangeInput({
* container: '#range-input',
* attribute: 'price',
* templates: {
* separatorText: 'to',
* submitText: 'Go'
* },
* })
* );
*/
function rangeInput() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attribute = _ref3.attribute,
min = _ref3.min,
max = _ref3.max,
_ref3$precision = _ref3.precision,
precision = _ref3$precision === void 0 ? 0 : _ref3$precision,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
userTemplates = _ref3$templates === void 0 ? {} : _ref3$templates;
if (!container) {
throw new Error(withUsage$w('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var templates = _objectSpread({
separatorText: 'to',
submitText: 'Go'
}, userTemplates);
var cssClasses = {
root: classnames(suit$e(), userCssClasses.root),
noRefinement: classnames(suit$e({
modifierName: 'noRefinement'
})),
form: classnames(suit$e({
descendantName: 'form'
}), userCssClasses.form),
label: classnames(suit$e({
descendantName: 'label'
}), userCssClasses.label),
input: classnames(suit$e({
descendantName: 'input'
}), userCssClasses.input),
inputMin: classnames(suit$e({
descendantName: 'input',
modifierName: 'min'
}), userCssClasses.inputMin),
inputMax: classnames(suit$e({
descendantName: 'input',
modifierName: 'max'
}), userCssClasses.inputMax),
separator: classnames(suit$e({
descendantName: 'separator'
}), userCssClasses.separator),
submit: classnames(suit$e({
descendantName: 'submit'
}), userCssClasses.submit)
};
var specializedRenderer = renderer$b({
containerNode: containerNode,
cssClasses: cssClasses,
templates: templates,
renderState: {}
});
var makeWidget = connectRange(specializedRenderer);
return makeWidget({
attribute: attribute,
min: min,
max: max,
precision: precision
});
}
/* eslint max-len: 0 */
var defaultTemplates$9 = {
reset: "\n\n \n \n ",
submit: "\n\n \n \n ",
loadingIndicator: "\n\n \n \n \n \n \n \n \n \n \n "
};
var withUsage$x = createDocumentationMessageGenerator({
name: 'search-box'
});
var suit$f = component('SearchBox');
var renderer$c = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
placeholder = _ref.placeholder,
templates = _ref.templates,
autofocus = _ref.autofocus,
searchAsYouType = _ref.searchAsYouType,
showReset = _ref.showReset,
showSubmit = _ref.showSubmit,
showLoadingIndicator = _ref.showLoadingIndicator;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
clear = _ref2.clear,
query = _ref2.query,
onHistoryChange = _ref2.onHistoryChange,
isSearchStalled = _ref2.isSearchStalled;
if (isFirstRendering) {
var _input = document.createElement('input');
var wrappedInput = wrapInputFn(_input, cssClasses);
containerNode.appendChild(wrappedInput);
if (showSubmit) {
addSubmit(_input, cssClasses, templates);
}
if (showReset) {
addReset(_input, cssClasses, templates, clear);
}
if (showLoadingIndicator) {
addLoadingIndicator(_input, cssClasses, templates);
}
addDefaultAttributesToInput(placeholder, _input, query, cssClasses); // When the page is coming from BFCache
// (https://developer.mozilla.org/en-US/docs/Working_with_BFCache)
// then we force the input value to be the current query
// Otherwise, this happens:
// - autocomplete = off (default)
// - search $query
// - navigate away
// - use back button
// - input query is empty (because autocomplete = off)
window.addEventListener('pageshow', function () {
_input.value = query;
}); // Update value when query change outside of the input
onHistoryChange(function (fullState) {
_input.value = fullState.query || '';
});
if (autofocus === true) {
_input.focus();
_input.setSelectionRange(query.length, query.length);
}
var form = _input.parentElement;
if (searchAsYouType) {
_input.addEventListener('input', function (event) {
refine(event.currentTarget.value);
});
form.addEventListener('submit', function (event) {
event.preventDefault();
_input.blur();
});
} else {
_input.addEventListener('input', function (event) {
refine(event.currentTarget.value, false);
});
form.addEventListener('submit', function (event) {
refine(_input.value);
event.preventDefault();
_input.blur();
});
}
return;
}
var input = containerNode.querySelector('input');
var isFocused = document.activeElement === input;
if (!isFocused && query !== input.value) {
input.value = query;
}
if (showLoadingIndicator) {
var loadingIndicatorElement = containerNode.querySelector(".".concat(cssClasses.loadingIndicator));
if (loadingIndicatorElement) {
if (isSearchStalled) {
loadingIndicatorElement.removeAttribute('hidden');
} else {
loadingIndicatorElement.setAttribute('hidden', '');
}
}
}
if (showReset) {
var resetElement = containerNode.querySelector(".".concat(cssClasses.reset));
if (resetElement) {
var isUserTyping = Boolean(query && query.trim());
if (isUserTyping && !isSearchStalled) {
resetElement.removeAttribute('hidden');
} else {
resetElement.setAttribute('hidden', '');
}
}
}
};
};
var disposer = function disposer(containerNode) {
return function () {
var range = document.createRange(); // IE10+
range.selectNodeContents(containerNode);
range.deleteContents();
};
};
/**
* @typedef {Ojbect} SearchBoxTemplates
* @property {function|string} submit Template used for displaying the submit. Can accept a function or a Hogan string.
* @property {function|string} reset Template used for displaying the button. Can accept a function or a Hogan string.
* @property {function|string} loadingIndicator Template used for displaying the button. Can accept a function or a Hogan string.
*/
/**
* @typedef {Object} SearchBoxCSSClasses
* @property {string|string[]} [root] CSS class to add to the wrapping ``
* @property {string|string[]} [form] CSS class to add to the form
* @property {string|string[]} [input] CSS class to add to the input.
* @property {string|string[]} [submit] CSS classes added to the submit button.
* @property {string|string[]} [submitIcon] CSS classes added to the submit icon.
* @property {string|string[]} [reset] CSS classes added to the reset button.
* @property {string|string[]} [resetIcon] CSS classes added to the reset icon.
* @property {string|string[]} [loadingIndicator] CSS classes added to the loading indicator element.
* @property {string|string[]} [loadingIcon] CSS classes added to the loading indicator icon.
*/
/**
* @typedef {Object} SearchBoxWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget
* @property {string} [placeholder] The placeholder of the input
* @property {boolean} [autofocus=false] Whether the input should be autofocused
* @property {boolean} [searchAsYouType=true] If set, trigger the search
* once `
` is pressed only.
* @property {boolean} [showReset=true] Whether to show the reset button
* @property {boolean} [showSubmit=true] Whether to show the submit button
* @property {boolean} [showLoadingIndicator=true] Whether to show the loading indicator (replaces the submit if
* the search is stalled)
* @property {SearchBoxCSSClasses} [cssClasses] CSS classes to add
* @property {SearchBoxTemplates} [templates] Templates used for customizing the rendering of the searchbox
* @property {function} [queryHook] A function that is called every time a new search is done. You
* will get the query as the first parameter and a search (query) function to call as the second parameter.
* This `queryHook` can be used to debounce the number of searches done from the search box.
*/
/**
* The searchbox widget is used to let the user set a text based query.
*
* This is usually the main entry point to start the search in an instantsearch context. For that
* reason is usually placed on top, and not hidden so that the user can start searching right
* away.
*
* @type {WidgetFactory}
* @devNovel SearchBox
* @category basic
* @param {SearchBoxWidgetOptions} $0 Options used to configure a SearchBox widget.
* @return {Widget} Creates a new instance of the SearchBox widget.
* @example
* search.addWidget(
* instantsearch.widgets.searchBox({
* container: '#q',
* placeholder: 'Search for products',
* })
* );
*/
function searchBox() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
_ref3$placeholder = _ref3.placeholder,
placeholder = _ref3$placeholder === void 0 ? '' : _ref3$placeholder,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$autofocus = _ref3.autofocus,
autofocus = _ref3$autofocus === void 0 ? false : _ref3$autofocus,
_ref3$searchAsYouType = _ref3.searchAsYouType,
searchAsYouType = _ref3$searchAsYouType === void 0 ? true : _ref3$searchAsYouType,
_ref3$showReset = _ref3.showReset,
showReset = _ref3$showReset === void 0 ? true : _ref3$showReset,
_ref3$showSubmit = _ref3.showSubmit,
showSubmit = _ref3$showSubmit === void 0 ? true : _ref3$showSubmit,
_ref3$showLoadingIndi = _ref3.showLoadingIndicator,
showLoadingIndicator = _ref3$showLoadingIndi === void 0 ? true : _ref3$showLoadingIndi,
queryHook = _ref3.queryHook,
templates = _ref3.templates;
if (!container) {
throw new Error(withUsage$x('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
if (containerNode.tagName === 'INPUT') {
throw new Error("The `container` option doesn't accept `input` elements since InstantSearch.js 3.\n\nYou may want to migrate using `connectSearchBox`: ".concat(createDocumentationLink({
name: 'searchbox',
connector: true
}), "."));
}
_warning(typeof autofocus === 'boolean', 'The `autofocus` option only supports boolean values since InstantSearch.js 3.');
var cssClasses = {
root: classnames(suit$f(), userCssClasses.root),
form: classnames(suit$f({
descendantName: 'form'
}), userCssClasses.form),
input: classnames(suit$f({
descendantName: 'input'
}), userCssClasses.input),
submit: classnames(suit$f({
descendantName: 'submit'
}), userCssClasses.submit),
submitIcon: classnames(suit$f({
descendantName: 'submitIcon'
}), userCssClasses.submitIcon),
reset: classnames(suit$f({
descendantName: 'reset'
}), userCssClasses.reset),
resetIcon: classnames(suit$f({
descendantName: 'resetIcon'
}), userCssClasses.resetIcon),
loadingIndicator: classnames(suit$f({
descendantName: 'loadingIndicator'
}), userCssClasses.loadingIndicator),
loadingIcon: classnames(suit$f({
descendantName: 'loadingIcon'
}), userCssClasses.loadingIcon)
};
var specializedRenderer = renderer$c({
containerNode: containerNode,
cssClasses: cssClasses,
placeholder: placeholder,
templates: _objectSpread({}, defaultTemplates$9, templates),
autofocus: autofocus,
searchAsYouType: searchAsYouType,
showReset: showReset,
showSubmit: showSubmit,
showLoadingIndicator: showLoadingIndicator
});
var makeWidget = connectSearchBox(specializedRenderer, disposer(containerNode));
return makeWidget({
queryHook: queryHook
});
}
function addDefaultAttributesToInput(placeholder, input, query, cssClasses) {
var defaultAttributes = {
autocapitalize: 'off',
autocomplete: 'off',
autocorrect: 'off',
placeholder: placeholder,
role: 'textbox',
spellcheck: 'false',
type: 'text',
value: query
}; // Overrides attributes if not already set
forEach_1(defaultAttributes, function (value, key) {
if (input.hasAttribute(key)) {
return;
}
input.setAttribute(key, value);
}); // Add classes
input.className = cssClasses.input;
}
/**
* Adds a reset element in the searchbox widget. When this reset element is clicked on
* it should reset the query.
* @private
* @param {HTMLElement} input the DOM node of the input of the searchbox
* @param {object} cssClasses the object containing all the css classes
* @param {object} templates the templates object
* @param {function} clearFunction function called when the element is activated (clicked)
* @returns {undefined} Modifies the input
*/
function addReset(input, cssClasses, templates, clearFunction) {
var stringNode = renderTemplate({
templateKey: 'reset',
templates: templates,
data: {
cssClasses: cssClasses
}
});
var node = document.createElement('button');
node.className = cssClasses.reset;
node.setAttribute('hidden', '');
node.type = 'reset';
node.title = 'Clear the search query';
node.innerHTML = stringNode;
input.parentNode.appendChild(node);
node.addEventListener('click', function () {
input.focus();
clearFunction();
});
}
/**
* Adds a button with a magnifying glass in the searchbox widget
* @private
* @param {HTMLElement} input the DOM node of the input of the searchbox
* @param {object} cssClasses the user options (cssClasses and template)
* @param {object} templates the object containing all the templates
* @returns {undefined} Modifies the input
*/
function addSubmit(input, cssClasses, templates) {
var stringNode = renderTemplate({
templateKey: 'submit',
templates: templates,
data: {
cssClasses: cssClasses
}
});
var node = document.createElement('button');
node.className = cssClasses.submit;
node.type = 'submit';
node.title = 'Submit the search query';
node.innerHTML = stringNode;
input.parentNode.appendChild(node);
}
/**
* Adds a loading indicator (spinner) to the search box
* @param {DomElement} input DOM element where to add the loading indicator
* @param {Object} cssClasses css classes definition
* @param {Object} templates templates of the widget
* @returns {undefined} Modifies the input
*/
function addLoadingIndicator(input, cssClasses, templates) {
var stringNode = renderTemplate({
templateKey: 'loadingIndicator',
templates: templates,
data: {
cssClasses: cssClasses
}
});
var node = document.createElement('span');
node.setAttribute('hidden', '');
node.className = cssClasses.loadingIndicator;
node.innerHTML = stringNode;
input.parentNode.appendChild(node);
}
function wrapInputFn(input, cssClasses) {
var wrapper = document.createElement('div');
wrapper.className = cssClasses.root;
var form = document.createElement('form');
form.className = cssClasses.form;
form.noValidate = true;
form.action = ''; // show search button on iOS keyboard
form.appendChild(input);
wrapper.appendChild(form);
return wrapper;
}
var SliderConstants = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
var KEYS = exports.KEYS = {
DOWN: 40,
END: 35,
ESC: 27,
HOME: 36,
LEFT: 37,
PAGE_DOWN: 34,
PAGE_UP: 33,
RIGHT: 39,
UP: 38
};
var PERCENT_EMPTY = exports.PERCENT_EMPTY = 0;
var PERCENT_FULL = exports.PERCENT_FULL = 100;
});
unwrapExports(SliderConstants);
var SliderConstants_1 = SliderConstants.KEYS;
var SliderConstants_2 = SliderConstants.PERCENT_EMPTY;
var SliderConstants_3 = SliderConstants.PERCENT_FULL;
var linear = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = {
getPosition: function () {
function getPosition(value, min, max) {
return (value - min) / (max - min) * 100;
}
return getPosition;
}(),
getValue: function () {
function getValue(pos, min, max) {
var decimal = pos / 100;
if (pos === 0) {
return min;
} else if (pos === 100) {
return max;
}
return Math.round((max - min) * decimal + min);
}
return getValue;
}()
};
});
unwrapExports(linear);
var Slider = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || 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; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _preactCompat2 = _interopRequireDefault(index);
var _propTypes2 = _interopRequireDefault(propTypes);
var SliderConstants$$1 = _interopRequireWildcard(SliderConstants);
var _linear2 = _interopRequireDefault(linear);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* globals document */
/* eslint react/no-array-index-key: 1 */
function getClassName(props) {
var orientation = props.orientation === 'vertical' ? 'rheostat-vertical' : 'rheostat-horizontal';
return ['rheostat', orientation].concat(props.className.split(' ')).join(' ');
}
var has = Object.prototype.hasOwnProperty;
var PropTypeArrOfNumber = _propTypes2['default'].arrayOf(_propTypes2['default'].number);
var PropTypeReactComponent = _propTypes2['default'].oneOfType([_propTypes2['default'].func, _propTypes2['default'].string]);
function getHandleFor(ev) {
return Number(ev.currentTarget.getAttribute('data-handle-key'));
}
function killEvent(ev) {
ev.stopPropagation();
ev.preventDefault();
}
var Button = function (_React$Component) {
_inherits(Button, _React$Component);
function Button() {
_classCallCheck(this, Button);
return _possibleConstructorReturn(this, (Button.__proto__ || Object.getPrototypeOf(Button)).apply(this, arguments));
}
_createClass(Button, [{
key: 'render',
value: function () {
function render() {
return _preactCompat2['default'].createElement('button', _extends({}, this.props, { type: 'button' }));
}
return render;
}()
}]);
return Button;
}(_preactCompat2['default'].Component);
var propTypes$$1 = {
// the algorithm to use
algorithm: _propTypes2['default'].shape({
getValue: _propTypes2['default'].func,
getPosition: _propTypes2['default'].func
}),
// any children you pass in
children: _propTypes2['default'].node,
// standard class name you'd like to apply to the root element
className: _propTypes2['default'].string,
// prevent the slider from moving when clicked
disabled: _propTypes2['default'].bool,
// a custom handle you can pass in
handle: PropTypeReactComponent,
// the maximum possible value
max: _propTypes2['default'].number,
// the minimum possible value
min: _propTypes2['default'].number,
// called on click
onClick: _propTypes2['default'].func,
// called whenever the user is done changing values on the slider
onChange: _propTypes2['default'].func,
// called on key press
onKeyPress: _propTypes2['default'].func,
// called when you finish dragging a handle
onSliderDragEnd: _propTypes2['default'].func,
// called every time the slider is dragged and the value changes
onSliderDragMove: _propTypes2['default'].func,
// called when you start dragging a handle
onSliderDragStart: _propTypes2['default'].func,
// called whenever the user is actively changing the values on the slider
// (dragging, clicked, keypress)
onValuesUpdated: _propTypes2['default'].func,
// the orientation
orientation: _propTypes2['default'].oneOf(['horizontal', 'vertical']),
// a component for rendering the pits
pitComponent: PropTypeReactComponent,
// the points that pits are rendered on
pitPoints: PropTypeArrOfNumber,
// a custom progress bar you can pass in
progressBar: PropTypeReactComponent,
// should we snap?
snap: _propTypes2['default'].bool,
// the points we should snap to
snapPoints: PropTypeArrOfNumber,
// the values
values: PropTypeArrOfNumber
};
var defaultProps = {
algorithm: _linear2['default'],
className: '',
children: null,
disabled: false,
handle: Button,
max: SliderConstants$$1.PERCENT_FULL,
min: SliderConstants$$1.PERCENT_EMPTY,
onClick: null,
onChange: null,
onKeyPress: null,
onSliderDragEnd: null,
onSliderDragMove: null,
onSliderDragStart: null,
onValuesUpdated: null,
orientation: 'horizontal',
pitComponent: null,
pitPoints: [],
progressBar: 'div',
snap: false,
snapPoints: [],
values: [SliderConstants$$1.PERCENT_EMPTY]
};
var Rheostat = function (_React$Component2) {
_inherits(Rheostat, _React$Component2);
function Rheostat(props) {
_classCallCheck(this, Rheostat);
var _this2 = _possibleConstructorReturn(this, (Rheostat.__proto__ || Object.getPrototypeOf(Rheostat)).call(this, props));
var _this2$props = _this2.props,
algorithm = _this2$props.algorithm,
max = _this2$props.max,
min = _this2$props.min,
values = _this2$props.values;
_this2.state = {
className: getClassName(_this2.props),
handlePos: values.map(function (value) {
return algorithm.getPosition(value, min, max);
}),
handleDimensions: 0,
mousePos: null,
sliderBox: {},
slidingIndex: null,
values: values
};
_this2.getPublicState = _this2.getPublicState.bind(_this2);
_this2.getSliderBoundingBox = _this2.getSliderBoundingBox.bind(_this2);
_this2.getProgressStyle = _this2.getProgressStyle.bind(_this2);
_this2.getMinValue = _this2.getMinValue.bind(_this2);
_this2.getMaxValue = _this2.getMaxValue.bind(_this2);
_this2.getHandleDimensions = _this2.getHandleDimensions.bind(_this2);
_this2.getClosestSnapPoint = _this2.getClosestSnapPoint.bind(_this2);
_this2.getSnapPosition = _this2.getSnapPosition.bind(_this2);
_this2.getNextPositionForKey = _this2.getNextPositionForKey.bind(_this2);
_this2.getNextState = _this2.getNextState.bind(_this2);
_this2.handleClick = _this2.handleClick.bind(_this2);
_this2.getClosestHandle = _this2.getClosestHandle.bind(_this2);
_this2.setStartSlide = _this2.setStartSlide.bind(_this2);
_this2.startMouseSlide = _this2.startMouseSlide.bind(_this2);
_this2.startTouchSlide = _this2.startTouchSlide.bind(_this2);
_this2.handleMouseSlide = _this2.handleMouseSlide.bind(_this2);
_this2.handleTouchSlide = _this2.handleTouchSlide.bind(_this2);
_this2.handleSlide = _this2.handleSlide.bind(_this2);
_this2.endSlide = _this2.endSlide.bind(_this2);
_this2.handleKeydown = _this2.handleKeydown.bind(_this2);
_this2.validatePosition = _this2.validatePosition.bind(_this2);
_this2.validateValues = _this2.validateValues.bind(_this2);
_this2.canMove = _this2.canMove.bind(_this2);
_this2.fireChangeEvent = _this2.fireChangeEvent.bind(_this2);
_this2.slideTo = _this2.slideTo.bind(_this2);
_this2.updateNewValues = _this2.updateNewValues.bind(_this2);
return _this2;
}
_createClass(Rheostat, [{
key: 'componentWillReceiveProps',
value: function () {
function componentWillReceiveProps(nextProps) {
var _props = this.props,
className = _props.className,
disabled = _props.disabled,
min = _props.min,
max = _props.max,
orientation = _props.orientation;
var _state = this.state,
values = _state.values,
slidingIndex = _state.slidingIndex;
var minMaxChanged = nextProps.min !== min || nextProps.max !== max;
var valuesChanged = values.length !== nextProps.values.length || values.some(function (value, idx) {
return nextProps.values[idx] !== value;
});
var orientationChanged = nextProps.className !== className || nextProps.orientation !== orientation;
var willBeDisabled = nextProps.disabled && !disabled;
if (orientationChanged) {
this.setState({
className: getClassName(nextProps)
});
}
if (minMaxChanged || valuesChanged) this.updateNewValues(nextProps);
if (willBeDisabled && slidingIndex !== null) {
this.endSlide();
}
}
return componentWillReceiveProps;
}()
}, {
key: 'getPublicState',
value: function () {
function getPublicState() {
var _props2 = this.props,
min = _props2.min,
max = _props2.max;
var values = this.state.values;
return { max: max, min: min, values: values };
}
return getPublicState;
}()
// istanbul ignore next
}, {
key: 'getSliderBoundingBox',
value: function () {
function getSliderBoundingBox() {
var rheostat = this.refs.rheostat;
var node = rheostat.getDOMNode ? rheostat.getDOMNode() : rheostat;
var rect = node.getBoundingClientRect();
return {
height: rect.height || node.clientHeight,
left: rect.left,
top: rect.top,
width: rect.width || node.clientWidth
};
}
return getSliderBoundingBox;
}()
}, {
key: 'getProgressStyle',
value: function () {
function getProgressStyle(idx) {
var handlePos = this.state.handlePos;
var value = handlePos[idx];
if (idx === 0) {
return this.props.orientation === 'vertical' ? { height: String(value) + '%', top: 0 } : { left: 0, width: String(value) + '%' };
}
var prevValue = handlePos[idx - 1];
var diffValue = value - prevValue;
return this.props.orientation === 'vertical' ? { height: diffValue + '%', top: String(prevValue) + '%' } : { left: String(prevValue) + '%', width: diffValue + '%' };
}
return getProgressStyle;
}()
}, {
key: 'getMinValue',
value: function () {
function getMinValue(idx) {
return this.state.values[idx - 1] ? Math.max(this.props.min, this.state.values[idx - 1]) : this.props.min;
}
return getMinValue;
}()
}, {
key: 'getMaxValue',
value: function () {
function getMaxValue(idx) {
return this.state.values[idx + 1] ? Math.min(this.props.max, this.state.values[idx + 1]) : this.props.max;
}
return getMaxValue;
}()
// istanbul ignore next
}, {
key: 'getHandleDimensions',
value: function () {
function getHandleDimensions(ev, sliderBox) {
var handleNode = ev.currentTarget || null;
if (!handleNode) return 0;
return this.props.orientation === 'vertical' ? handleNode.clientHeight / sliderBox.height * SliderConstants$$1.PERCENT_FULL / 2 : handleNode.clientWidth / sliderBox.width * SliderConstants$$1.PERCENT_FULL / 2;
}
return getHandleDimensions;
}()
}, {
key: 'getClosestSnapPoint',
value: function () {
function getClosestSnapPoint(value) {
if (!this.props.snapPoints.length) return value;
return this.props.snapPoints.reduce(function (snapTo, snap) {
return Math.abs(snapTo - value) < Math.abs(snap - value) ? snapTo : snap;
});
}
return getClosestSnapPoint;
}()
}, {
key: 'getSnapPosition',
value: function () {
function getSnapPosition(positionPercent) {
if (!this.props.snap) return positionPercent;
var _props3 = this.props,
algorithm = _props3.algorithm,
max = _props3.max,
min = _props3.min;
var value = algorithm.getValue(positionPercent, min, max);
var snapValue = this.getClosestSnapPoint(value);
return algorithm.getPosition(snapValue, min, max);
}
return getSnapPosition;
}()
}, {
key: 'getNextPositionForKey',
value: function () {
function getNextPositionForKey(idx, keyCode) {
var _stepMultiplier;
var _state2 = this.state,
handlePos = _state2.handlePos,
values = _state2.values;
var _props4 = this.props,
algorithm = _props4.algorithm,
max = _props4.max,
min = _props4.min,
snapPoints = _props4.snapPoints;
var shouldSnap = this.props.snap;
var proposedValue = values[idx];
var proposedPercentage = handlePos[idx];
var originalPercentage = proposedPercentage;
var stepValue = 1;
if (max >= 100) {
proposedPercentage = Math.round(proposedPercentage);
} else {
stepValue = 100 / (max - min);
}
var currentIndex = null;
if (shouldSnap) {
currentIndex = snapPoints.indexOf(this.getClosestSnapPoint(values[idx]));
}
var stepMultiplier = (_stepMultiplier = {}, _defineProperty(_stepMultiplier, SliderConstants$$1.KEYS.LEFT, function (v) {
return v * -1;
}), _defineProperty(_stepMultiplier, SliderConstants$$1.KEYS.RIGHT, function (v) {
return v * 1;
}), _defineProperty(_stepMultiplier, SliderConstants$$1.KEYS.UP, function (v) {
return v * 1;
}), _defineProperty(_stepMultiplier, SliderConstants$$1.KEYS.DOWN, function (v) {
return v * -1;
}), _defineProperty(_stepMultiplier, SliderConstants$$1.KEYS.PAGE_DOWN, function (v) {
return v > 1 ? -v : v * -10;
}), _defineProperty(_stepMultiplier, SliderConstants$$1.KEYS.PAGE_UP, function (v) {
return v > 1 ? v : v * 10;
}), _stepMultiplier);
if (has.call(stepMultiplier, keyCode)) {
proposedPercentage += stepMultiplier[keyCode](stepValue);
if (shouldSnap) {
if (proposedPercentage > originalPercentage) {
// move cursor right unless overflow
if (currentIndex < snapPoints.length - 1) {
proposedValue = snapPoints[currentIndex + 1];
}
// move cursor left unless there is overflow
} else if (currentIndex > 0) {
proposedValue = snapPoints[currentIndex - 1];
}
}
} else if (keyCode === SliderConstants$$1.KEYS.HOME) {
proposedPercentage = SliderConstants$$1.PERCENT_EMPTY;
if (shouldSnap) {
proposedValue = snapPoints[0];
}
} else if (keyCode === SliderConstants$$1.KEYS.END) {
proposedPercentage = SliderConstants$$1.PERCENT_FULL;
if (shouldSnap) {
proposedValue = snapPoints[snapPoints.length - 1];
}
} else {
return null;
}
return shouldSnap ? algorithm.getPosition(proposedValue, min, max) : proposedPercentage;
}
return getNextPositionForKey;
}()
}, {
key: 'getNextState',
value: function () {
function getNextState(idx, proposedPosition) {
var _this3 = this;
var handlePos = this.state.handlePos;
var _props5 = this.props,
max = _props5.max,
min = _props5.min;
var actualPosition = this.validatePosition(idx, proposedPosition);
var nextHandlePos = handlePos.map(function (pos, index$$1) {
return index$$1 === idx ? actualPosition : pos;
});
return {
handlePos: nextHandlePos,
values: nextHandlePos.map(function (pos) {
return _this3.props.algorithm.getValue(pos, min, max);
})
};
}
return getNextState;
}()
}, {
key: 'getClosestHandle',
value: function () {
function getClosestHandle(positionPercent) {
var handlePos = this.state.handlePos;
return handlePos.reduce(function (closestIdx, node, idx) {
var challenger = Math.abs(handlePos[idx] - positionPercent);
var current = Math.abs(handlePos[closestIdx] - positionPercent);
return challenger < current ? idx : closestIdx;
}, 0);
}
return getClosestHandle;
}()
// istanbul ignore next
}, {
key: 'setStartSlide',
value: function () {
function setStartSlide(ev, x, y) {
var sliderBox = this.getSliderBoundingBox();
this.setState({
handleDimensions: this.getHandleDimensions(ev, sliderBox),
mousePos: { x: x, y: y },
sliderBox: sliderBox,
slidingIndex: getHandleFor(ev)
});
}
return setStartSlide;
}()
// istanbul ignore next
}, {
key: 'startMouseSlide',
value: function () {
function startMouseSlide(ev) {
this.setStartSlide(ev, ev.clientX, ev.clientY);
if (typeof document.addEventListener === 'function') {
document.addEventListener('mousemove', this.handleMouseSlide, false);
document.addEventListener('mouseup', this.endSlide, false);
} else {
document.attachEvent('onmousemove', this.handleMouseSlide);
document.attachEvent('onmouseup', this.endSlide);
}
killEvent(ev);
}
return startMouseSlide;
}()
// istanbul ignore next
}, {
key: 'startTouchSlide',
value: function () {
function startTouchSlide(ev) {
if (ev.changedTouches.length > 1) return;
var touch = ev.changedTouches[0];
this.setStartSlide(ev, touch.clientX, touch.clientY);
document.addEventListener('touchmove', this.handleTouchSlide, false);
document.addEventListener('touchend', this.endSlide, false);
if (this.props.onSliderDragStart) this.props.onSliderDragStart();
killEvent(ev);
}
return startTouchSlide;
}()
// istanbul ignore next
}, {
key: 'handleMouseSlide',
value: function () {
function handleMouseSlide(ev) {
if (this.state.slidingIndex === null) return;
this.handleSlide(ev.clientX, ev.clientY);
killEvent(ev);
}
return handleMouseSlide;
}()
// istanbul ignore next
}, {
key: 'handleTouchSlide',
value: function () {
function handleTouchSlide(ev) {
if (this.state.slidingIndex === null) return;
if (ev.changedTouches.length > 1) {
this.endSlide();
return;
}
var touch = ev.changedTouches[0];
this.handleSlide(touch.clientX, touch.clientY);
killEvent(ev);
}
return handleTouchSlide;
}()
// istanbul ignore next
}, {
key: 'handleSlide',
value: function () {
function handleSlide(x, y) {
var _state3 = this.state,
idx = _state3.slidingIndex,
sliderBox = _state3.sliderBox;
var positionPercent = this.props.orientation === 'vertical' ? (y - sliderBox.top) / sliderBox.height * SliderConstants$$1.PERCENT_FULL : (x - sliderBox.left) / sliderBox.width * SliderConstants$$1.PERCENT_FULL;
this.slideTo(idx, positionPercent);
if (this.canMove(idx, positionPercent)) {
// update mouse positions
this.setState({ x: x, y: y });
if (this.props.onSliderDragMove) this.props.onSliderDragMove();
}
}
return handleSlide;
}()
// istanbul ignore next
}, {
key: 'endSlide',
value: function () {
function endSlide() {
var _this4 = this;
var idx = this.state.slidingIndex;
this.setState({ slidingIndex: null });
if (typeof document.removeEventListener === 'function') {
document.removeEventListener('mouseup', this.endSlide, false);
document.removeEventListener('touchend', this.endSlide, false);
document.removeEventListener('touchmove', this.handleTouchSlide, false);
document.removeEventListener('mousemove', this.handleMouseSlide, false);
} else {
document.detachEvent('onmousemove', this.handleMouseSlide);
document.detachEvent('onmouseup', this.endSlide);
}
if (this.props.onSliderDragEnd) this.props.onSliderDragEnd();
if (this.props.snap) {
var positionPercent = this.getSnapPosition(this.state.handlePos[idx]);
this.slideTo(idx, positionPercent, function () {
return _this4.fireChangeEvent();
});
} else {
this.fireChangeEvent();
}
}
return endSlide;
}()
// istanbul ignore next
}, {
key: 'handleClick',
value: function () {
function handleClick(ev) {
var _this5 = this;
if (ev.target.getAttribute('data-handle-key')) {
return;
}
// Calculate the position of the slider on the page so we can determine
// the position where you click in relativity.
var sliderBox = this.getSliderBoundingBox();
var positionDecimal = this.props.orientation === 'vertical' ? (ev.clientY - sliderBox.top) / sliderBox.height : (ev.clientX - sliderBox.left) / sliderBox.width;
var positionPercent = positionDecimal * SliderConstants$$1.PERCENT_FULL;
var handleId = this.getClosestHandle(positionPercent);
var validPositionPercent = this.getSnapPosition(positionPercent);
// Move the handle there
this.slideTo(handleId, validPositionPercent, function () {
return _this5.fireChangeEvent();
});
if (this.props.onClick) this.props.onClick();
}
return handleClick;
}()
// istanbul ignore next
}, {
key: 'handleKeydown',
value: function () {
function handleKeydown(ev) {
var _this6 = this;
var idx = getHandleFor(ev);
if (ev.keyCode === SliderConstants$$1.KEYS.ESC) {
ev.currentTarget.blur();
return;
}
var proposedPercentage = this.getNextPositionForKey(idx, ev.keyCode);
if (proposedPercentage === null) return;
if (this.canMove(idx, proposedPercentage)) {
this.slideTo(idx, proposedPercentage, function () {
return _this6.fireChangeEvent();
});
if (this.props.onKeyPress) this.props.onKeyPress();
}
killEvent(ev);
}
return handleKeydown;
}()
// Make sure the proposed position respects the bounds and
// does not collide with other handles too much.
}, {
key: 'validatePosition',
value: function () {
function validatePosition(idx, proposedPosition) {
var _state4 = this.state,
handlePos = _state4.handlePos,
handleDimensions = _state4.handleDimensions;
return Math.max(Math.min(proposedPosition, handlePos[idx + 1] !== undefined ? handlePos[idx + 1] - handleDimensions : SliderConstants$$1.PERCENT_FULL // 100% is the highest value
), handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : SliderConstants$$1.PERCENT_EMPTY // 0% is the lowest value
);
}
return validatePosition;
}()
}, {
key: 'validateValues',
value: function () {
function validateValues(proposedValues, props) {
var _ref = props || this.props,
max = _ref.max,
min = _ref.min;
return proposedValues.map(function (value, idx, values) {
var realValue = Math.max(Math.min(value, max), min);
if (values.length && realValue < values[idx - 1]) {
return values[idx - 1];
}
return realValue;
});
}
return validateValues;
}()
// Can we move the slider to the given position?
}, {
key: 'canMove',
value: function () {
function canMove(idx, proposedPosition) {
var _state5 = this.state,
handlePos = _state5.handlePos,
handleDimensions = _state5.handleDimensions;
if (proposedPosition < SliderConstants$$1.PERCENT_EMPTY) return false;
if (proposedPosition > SliderConstants$$1.PERCENT_FULL) return false;
var nextHandlePosition = handlePos[idx + 1] !== undefined ? handlePos[idx + 1] - handleDimensions : Infinity;
if (proposedPosition > nextHandlePosition) return false;
var prevHandlePosition = handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : -Infinity;
if (proposedPosition < prevHandlePosition) return false;
return true;
}
return canMove;
}()
// istanbul ignore next
}, {
key: 'fireChangeEvent',
value: function () {
function fireChangeEvent() {
var onChange = this.props.onChange;
if (onChange) onChange(this.getPublicState());
}
return fireChangeEvent;
}()
// istanbul ignore next
}, {
key: 'slideTo',
value: function () {
function slideTo(idx, proposedPosition, onAfterSet) {
var _this7 = this;
var nextState = this.getNextState(idx, proposedPosition);
this.setState(nextState, function () {
var onValuesUpdated = _this7.props.onValuesUpdated;
if (onValuesUpdated) onValuesUpdated(_this7.getPublicState());
if (onAfterSet) onAfterSet();
});
}
return slideTo;
}()
// istanbul ignore next
}, {
key: 'updateNewValues',
value: function () {
function updateNewValues(nextProps) {
var _this8 = this;
var slidingIndex = this.state.slidingIndex;
// Don't update while the slider is sliding
if (slidingIndex !== null) {
return;
}
var max = nextProps.max,
min = nextProps.min,
values = nextProps.values;
var algorithm = this.props.algorithm;
var nextValues = this.validateValues(values, nextProps);
this.setState({
handlePos: nextValues.map(function (value) {
return algorithm.getPosition(value, min, max);
}),
values: nextValues
}, function () {
return _this8.fireChangeEvent();
});
}
return updateNewValues;
}()
}, {
key: 'render',
value: function () {
function render() {
var _this9 = this;
var _props6 = this.props,
algorithm = _props6.algorithm,
children = _props6.children,
disabled = _props6.disabled,
Handle = _props6.handle,
max = _props6.max,
min = _props6.min,
orientation = _props6.orientation,
PitComponent = _props6.pitComponent,
pitPoints = _props6.pitPoints,
ProgressBar = _props6.progressBar;
var _state6 = this.state,
className = _state6.className,
handlePos = _state6.handlePos,
values = _state6.values;
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
_preactCompat2['default'].createElement(
'div',
{
className: className,
ref: 'rheostat',
onClick: !disabled && this.handleClick,
style: { position: 'relative' }
},
_preactCompat2['default'].createElement('div', { className: 'rheostat-background' }),
handlePos.map(function (pos, idx) {
var handleStyle = orientation === 'vertical' ? { top: String(pos) + '%', position: 'absolute' } : { left: String(pos) + '%', position: 'absolute' };
return _preactCompat2['default'].createElement(Handle, {
'aria-valuemax': _this9.getMaxValue(idx),
'aria-valuemin': _this9.getMinValue(idx),
'aria-valuenow': values[idx],
'aria-disabled': disabled,
'data-handle-key': idx,
className: 'rheostat-handle',
key: 'handle-' + String(idx),
onClick: _this9.killEvent,
onKeyDown: !disabled && _this9.handleKeydown,
onMouseDown: !disabled && _this9.startMouseSlide,
onTouchStart: !disabled && _this9.startTouchSlide,
role: 'slider',
style: handleStyle,
tabIndex: 0
});
}),
handlePos.map(function (node, idx, arr) {
if (idx === 0 && arr.length > 1) {
return null;
}
return _preactCompat2['default'].createElement(ProgressBar, {
className: 'rheostat-progress',
key: 'progress-bar-' + String(idx),
style: _this9.getProgressStyle(idx)
});
}),
PitComponent && pitPoints.map(function (n) {
var pos = algorithm.getPosition(n, min, max);
var pitStyle = orientation === 'vertical' ? { top: String(pos) + '%', position: 'absolute' } : { left: String(pos) + '%', position: 'absolute' };
return _preactCompat2['default'].createElement(
PitComponent,
{ key: 'pit-' + String(n), style: pitStyle },
n
);
}),
children
)
);
}
return render;
}()
}]);
return Rheostat;
}(_preactCompat2['default'].Component);
Rheostat.propTypes = propTypes$$1;
Rheostat.defaultProps = defaultProps;
exports['default'] = Rheostat;
});
var Rheostat = unwrapExports(Slider);
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER$2 = 9007199254740991;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH$1 = 4294967295;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMin$3 = Math.min;
/**
* Invokes the iteratee `n` times, returning an array of the results of
* each invocation. The iteratee is invoked with one argument; (index).
*
* @static
* @since 0.1.0
* @memberOf _
* @category Util
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @returns {Array} Returns the array of results.
* @example
*
* _.times(3, String);
* // => ['0', '1', '2']
*
* _.times(4, _.constant(0));
* // => [0, 0, 0, 0]
*/
function times(n, iteratee) {
n = toInteger_1(n);
if (n < 1 || n > MAX_SAFE_INTEGER$2) {
return [];
}
var index = MAX_ARRAY_LENGTH$1,
length = nativeMin$3(n, MAX_ARRAY_LENGTH$1);
iteratee = _castFunction(iteratee);
n -= MAX_ARRAY_LENGTH$1;
var result = _baseTimes(length, iteratee);
while (++index < n) {
iteratee(index);
}
return result;
}
var times_1 = times;
/** Used for built-in method references. */
var objectProto$l = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$i = objectProto$l.hasOwnProperty;
/**
* The base implementation of `_.has` without support for deep paths.
*
* @private
* @param {Object} [object] The object to query.
* @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHas(object, key) {
return object != null && hasOwnProperty$i.call(object, key);
}
var _baseHas = baseHas;
/**
* Checks if `path` is a direct property of `object`.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `path` exists, else `false`.
* @example
*
* var object = { 'a': { 'b': 2 } };
* var other = _.create({ 'a': _.create({ 'b': 2 }) });
*
* _.has(object, 'a');
* // => true
*
* _.has(object, 'a.b');
* // => true
*
* _.has(object, ['a', 'b']);
* // => true
*
* _.has(other, 'a');
* // => false
*/
function has$4(object, path) {
return object != null && _hasPath(object, path, _baseHas);
}
var has_1 = has$4;
var Pit = function Pit(_ref) {
var style = _ref.style,
children = _ref.children;
// first, end & middle
var positionValue = Math.round(parseFloat(style.left));
var shouldDisplayValue = [0, 50, 100].includes(positionValue); // Children could be an array, unwrap the value if it's the case
// see: https://github.com/developit/preact-compat/issues/436
var value = Array.isArray(children) ? children[0] : children;
var pitValue = Math.round(parseFloat(value) * 100) / 100;
return index.createElement("div", {
style: _objectSpread({}, style, {
marginLeft: positionValue === 100 ? '-2px' : 0
}),
className: classnames('rheostat-marker', 'rheostat-marker-horizontal', {
'rheostat-marker-large': shouldDisplayValue
})
}, shouldDisplayValue && index.createElement("div", {
className: 'rheostat-value'
}, pitValue));
};
var Slider$1 =
/*#__PURE__*/
function (_Component) {
_inherits(Slider$$1, _Component);
function Slider$$1() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, Slider$$1);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Slider$$1)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleChange", function (_ref) {
var values = _ref.values;
if (!_this.isDisabled) {
_this.props.refine(values);
}
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "createHandleComponent", function (tooltips) {
return function (props) {
// display only two decimals after comma,
// and apply `tooltips.format()` if any`
var roundedValue = Math.round(parseFloat(props['aria-valuenow']) * 100) / 100;
var value = has_1(tooltips, 'format') ? tooltips.format(roundedValue) : roundedValue;
var className = classnames(props.className, {
'rheostat-handle-lower': props['data-handle-key'] === 0,
'rheostat-handle-upper': props['data-handle-key'] === 1
});
return index.createElement("div", _extends({}, props, {
className: className
}), tooltips && index.createElement("div", {
className: "rheostat-tooltip"
}, value));
};
});
return _this;
}
_createClass(Slider$$1, [{
key: "computeDefaultPitPoints",
// creates an array number where to display a pit point on the slider
value: function computeDefaultPitPoints(_ref2) {
var min = _ref2.min,
max = _ref2.max;
var totalLength = max - min;
var steps = 34;
var stepsLength = totalLength / steps;
var pitPoints = [min].concat(_toConsumableArray(times_1(steps - 1, function (step) {
return min + stepsLength * (step + 1);
})), [max]);
return pitPoints;
} // creates an array of values where the slider should snap to
}, {
key: "computeSnapPoints",
value: function computeSnapPoints(_ref3) {
var min = _ref3.min,
max = _ref3.max,
step = _ref3.step;
if (!step) return undefined;
return [].concat(_toConsumableArray(range_1(min, max, step)), [max]);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
tooltips = _this$props.tooltips,
step = _this$props.step,
pips = _this$props.pips,
values = _this$props.values,
cssClasses = _this$props.cssClasses;
var _ref4 = this.isDisabled ? {
min: this.props.min,
max: this.props.max + 0.001
} : this.props,
min = _ref4.min,
max = _ref4.max;
var snapPoints = this.computeSnapPoints({
min: min,
max: max,
step: step
});
var pitPoints = pips === false ? [] : this.computeDefaultPitPoints({
min: min,
max: max
});
return index.createElement("div", {
className: classnames(cssClasses.root, _defineProperty({}, cssClasses.disabledRoot, this.isDisabled))
}, index.createElement(Rheostat, {
handle: this.createHandleComponent(tooltips),
onChange: this.handleChange,
min: min,
max: max,
pitComponent: Pit,
pitPoints: pitPoints,
snap: true,
snapPoints: snapPoints,
values: this.isDisabled ? [min, max] : values,
disabled: this.isDisabled
}));
}
}, {
key: "isDisabled",
get: function get() {
return this.props.min >= this.props.max;
}
}]);
return Slider$$1;
}(Component$1);
var withUsage$y = createDocumentationMessageGenerator({
name: 'range-slider'
});
var suit$g = component('RangeSlider');
var renderer$d = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
pips = _ref.pips,
step = _ref.step,
tooltips = _ref.tooltips;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
range = _ref2.range,
start = _ref2.start;
if (isFirstRendering) {
// There's no information at this point, let's render nothing.
return;
}
var minRange = range.min,
maxRange = range.max;
var _start = _slicedToArray(start, 2),
minStart = _start[0],
maxStart = _start[1];
var minFinite = minStart === -Infinity ? minRange : minStart;
var maxFinite = maxStart === Infinity ? maxRange : maxStart; // Clamp values to the range for avoid extra rendering & refinement
// Should probably be done on the connector side, but we need to stay
// backward compatible so we still need to pass [-Infinity, Infinity]
var values = [minFinite > maxRange ? maxRange : minFinite, maxFinite < minRange ? minRange : maxFinite];
render$1(index.createElement(Slider$1, {
cssClasses: cssClasses,
refine: refine,
min: minRange,
max: maxRange,
values: values,
tooltips: tooltips,
step: step,
pips: pips
}), containerNode);
};
};
/**
* @typedef {Object} RangeSliderCssClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [disabledRoot] CSS class to add to the disabled root element.
*/
/**
* @typedef {Object} RangeSliderTooltipOptions
* @property {function(number):string} format The function takes the raw value as input, and should return
* a string for the label that should be used for this value.
* `format: function(rawValue) {return '$' + Math.round(rawValue).toLocaleString()}`
*/
/**
* @typedef {Object} RangeSliderWidgetOptions
* @property {string|HTMLElement} container CSS Selector or DOMElement to insert the widget.
* @property {string} attribute Name of the attribute for faceting.
* @property {boolean|RangeSliderTooltipOptions} [tooltips=true] Should we show tooltips or not.
* The default tooltip will show the raw value.
* You can also provide an object with a format function as an attribute.
* So that you can format the tooltip display value as you want
* @property {RangeSliderCssClasses} [cssClasses] CSS classes to add to the wrapping elements.
* @property {boolean} [pips=true] Show slider pips.
* @property {number} [precision = 0] Number of digits after decimal point to use.
* @property {number} [step] Every handle move will jump that number of steps.
* @property {number} [min] Minimal slider value, default to automatically computed from the result set.
* @property {number} [max] Maximal slider value, defaults to automatically computed from the result set.
*/
/**
* The range slider is a widget which provides a user-friendly way to filter the
* results based on a single numeric range.
*
* @requirements
* The attribute passed to `attribute` must be declared as an
* [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting)
* in your Algolia settings.
*
* The values inside this attribute must be JavaScript numbers (not strings).
*
* @type {WidgetFactory}
* @devNovel RangeSlider
* @category filter
* @param {RangeSliderWidgetOptions} $0 RangeSlider widget options.
* @return {Widget} A new RangeSlider widget instance.
* @example
* search.addWidget(
* instantsearch.widgets.rangeSlider({
* container: '#price',
* attribute: 'price',
* tooltips: {
* format: function(rawValue) {
* return '$' + Math.round(rawValue).toLocaleString();
* }
* }
* })
* );
*/
function rangeSlider() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attribute = _ref3.attribute,
min = _ref3.min,
max = _ref3.max,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
step = _ref3.step,
_ref3$pips = _ref3.pips,
pips = _ref3$pips === void 0 ? true : _ref3$pips,
_ref3$precision = _ref3.precision,
precision = _ref3$precision === void 0 ? 0 : _ref3$precision,
_ref3$tooltips = _ref3.tooltips,
tooltips = _ref3$tooltips === void 0 ? true : _ref3$tooltips;
if (!container) {
throw new Error(withUsage$y('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$g(), userCssClasses.root),
disabledRoot: classnames(suit$g({
modifierName: 'disabled'
}), userCssClasses.disabledRoot)
};
var specializedRenderer = renderer$d({
containerNode: containerNode,
step: step,
pips: pips,
tooltips: tooltips,
renderState: {},
cssClasses: cssClasses
});
var makeWidget = connectRange(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
attribute: attribute,
min: min,
max: max,
precision: precision
});
}
var withUsage$z = createDocumentationMessageGenerator({
name: 'sort-by'
});
var suit$h = component('SortBy');
var renderer$e = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses;
return function (_ref2, isFirstRendering) {
var currentRefinement = _ref2.currentRefinement,
options = _ref2.options,
refine = _ref2.refine;
if (isFirstRendering) {
return;
}
render$1(index.createElement("div", {
className: cssClasses.root
}, index.createElement(Selector, {
cssClasses: cssClasses,
currentValue: currentRefinement,
options: options,
setValue: refine
})), containerNode);
};
};
/**
* @typedef {Object} SortByWidgetCssClasses
* @property {string|string[]} [root] CSS classes added to the outer ``.
* @property {string|string[]} [select] CSS classes added to the parent `
`.
* @property {string|string[]} [option] CSS classes added to each ``.
*/
/**
* @typedef {Object} SortByIndexDefinition
* @property {string} value The name of the index to target.
* @property {string} label The label of the index to display.
*/
/**
* @typedef {Object} SortByWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {SortByIndexDefinition[]} items Array of objects defining the different indices to choose from.
* @property {SortByWidgetCssClasses} [cssClasses] CSS classes to be added.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* Sort by selector is a widget used for letting the user choose between different
* indices that contains the same data with a different order / ranking formula.
*
* For the users it is like they are selecting a new sort order.
* @type {WidgetFactory}
* @devNovel SortBy
* @category sort
* @param {SortByWidgetOptions} $0 Options for the SortBy widget
* @return {Widget} Creates a new instance of the SortBy widget.
* @example
* search.addWidget(
* instantsearch.widgets.sortBy({
* container: '#sort-by-container',
* items: [
* {value: 'instant_search', label: 'Most relevant'},
* {value: 'instant_search_price_asc', label: 'Lowest price'},
* {value: 'instant_search_price_desc', label: 'Highest price'}
* ]
* })
* );
*/
function sortBy() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
items = _ref3.items,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
transformItems = _ref3.transformItems;
if (!container) {
throw new Error(withUsage$z('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$h(), userCssClasses.root),
select: classnames(suit$h({
descendantName: 'select'
}), userCssClasses.select),
option: classnames(suit$h({
descendantName: 'option'
}), userCssClasses.option)
};
var specializedRenderer = renderer$e({
containerNode: containerNode,
cssClasses: cssClasses
});
var makeWidget = connectSortBy(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
items: items,
transformItems: transformItems
});
}
var defaultTemplates$a = {
item: "{{#count}}{{/count}}{{^count}}{{/count}}\n {{#stars}}\n {{#.}} {{/.}}{{^.}} {{/.}}\n {{/stars}}\n & Up \n {{#count}}{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}} {{/count}}\n{{#count}}{{/count}}{{^count}}
{{/count}}"
};
var withUsage$A = createDocumentationMessageGenerator({
name: 'rating-menu'
});
var suit$i = component('RatingMenu');
var _ref3$1 =
/*#__PURE__*/
index.createElement("path", {
d: "M12 .288l2.833 8.718h9.167l-7.417 5.389 2.833 8.718-7.416-5.388-7.417 5.388 2.833-8.718-7.416-5.389h9.167z"
});
var _ref4 =
/*#__PURE__*/
index.createElement("path", {
d: "M12 6.76l1.379 4.246h4.465l-3.612 2.625 1.379 4.246-3.611-2.625-3.612 2.625 1.379-4.246-3.612-2.625h4.465l1.38-4.246zm0-6.472l-2.833 8.718h-9.167l7.416 5.389-2.833 8.718 7.417-5.388 7.416 5.388-2.833-8.718 7.417-5.389h-9.167l-2.833-8.718z"
});
var renderer$f = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
templates = _ref.templates,
renderState = _ref.renderState;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
items = _ref2.items,
createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$a,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(RefinementList$1, {
createURL: createURL,
cssClasses: cssClasses,
facetValues: items,
templateProps: renderState.templateProps,
toggleRefinement: refine
}, index.createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
style: "display:none;"
}, index.createElement("symbol", {
id: suit$i({
descendantName: 'starSymbol'
}),
viewBox: "0 0 24 24"
}, _ref3$1), index.createElement("symbol", {
id: suit$i({
descendantName: 'starEmptySymbol'
}),
viewBox: "0 0 24 24"
}, _ref4))), containerNode);
};
};
/**
* @typedef {Object} RatingMenuWidgetTemplates
* @property {string|function} [item] Item template, provided with `name`, `count`, `isRefined`, `url` data properties.
*/
/**
* @typedef {Object} RatingMenuWidgetCssClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element when there's no refinements.
* @property {string|string[]} [list] CSS class to add to the list element.
* @property {string|string[]} [item] CSS class to add to each item element.
* @property {string|string[]} [selectedItem] CSS class to add the selected item element.
* @property {string|string[]} [disabledItem] CSS class to add a disabled item element.
* @property {string|string[]} [link] CSS class to add to each link element.
* @property {string|string[]} [starIcon] CSS class to add to each star element (when using the default template).
* @property {string|string[]} [fullStarIcon] CSS class to add to each full star element (when using the default template).
* @property {string|string[]} [emptyStarIcon] CSS class to add to each empty star element (when using the default template).
* @property {string|string[]} [label] CSS class to add to each label.
* @property {string|string[]} [count] CSS class to add to each counter.
*/
/**
* @typedef {Object} RatingMenuWidgetOptions
* @property {string|HTMLElement} container Place where to insert the widget in your webpage.
* @property {string} attribute Name of the attribute in your records that contains the ratings.
* @property {number} [max = 5] The maximum rating value.
* @property {RatingMenuWidgetTemplates} [templates] Templates to use for the widget.
* @property {RatingMenuWidgetCssClasses} [cssClasses] CSS classes to add.
*/
/**
* Rating menu is used for displaying grade like filters. The values are normalized within boundaries.
*
* The maximum value can be set (with `max`), the minimum is always 0.
*
* @requirements
* The attribute passed to `attribute` must be declared as an
* [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting)
* in your Algolia settings.
*
* The values inside this attribute must be JavaScript numbers (not strings).
*
* @type {WidgetFactory}
* @devNovel RatingMenu
* @category filter
* @param {RatingMenuWidgetOptions} $0 RatingMenu widget options.
* @return {Widget} A new RatingMenu widget instance.
* @example
* search.addWidget(
* instantsearch.widgets.ratingMenu({
* container: '#stars',
* attribute: 'rating',
* max: 5,
* })
* );
*/
function ratingMenu() {
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref5.container,
attribute = _ref5.attribute,
_ref5$max = _ref5.max,
max = _ref5$max === void 0 ? 5 : _ref5$max,
_ref5$cssClasses = _ref5.cssClasses,
userCssClasses = _ref5$cssClasses === void 0 ? {} : _ref5$cssClasses,
_ref5$templates = _ref5.templates,
templates = _ref5$templates === void 0 ? defaultTemplates$a : _ref5$templates;
if (!container) {
throw new Error(withUsage$A('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$i(), userCssClasses.root),
noRefinementRoot: classnames(suit$i({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$i({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$i({
descendantName: 'item'
}), userCssClasses.item),
selectedItem: classnames(suit$i({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
disabledItem: classnames(suit$i({
descendantName: 'item',
modifierName: 'disabled'
}), userCssClasses.disabledItem),
link: classnames(suit$i({
descendantName: 'link'
}), userCssClasses.link),
starIcon: classnames(suit$i({
descendantName: 'starIcon'
}), userCssClasses.starIcon),
fullStarIcon: classnames(suit$i({
descendantName: 'starIcon',
modifierName: 'full'
}), userCssClasses.fullStarIcon),
emptyStarIcon: classnames(suit$i({
descendantName: 'starIcon',
modifierName: 'empty'
}), userCssClasses.emptyStarIcon),
label: classnames(suit$i({
descendantName: 'label'
}), userCssClasses.label),
count: classnames(suit$i({
descendantName: 'count'
}), userCssClasses.count)
};
var specializedRenderer = renderer$f({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeWidget = connectRatingMenu(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
attribute: attribute,
max: max
});
}
var Stats = function Stats(_ref) {
var nbHits = _ref.nbHits,
hitsPerPage = _ref.hitsPerPage,
nbPages = _ref.nbPages,
page = _ref.page,
processingTimeMS = _ref.processingTimeMS,
query = _ref.query,
templateProps = _ref.templateProps,
cssClasses = _ref.cssClasses;
return index.createElement("div", {
className: cssClasses.root
}, index.createElement(Template, _extends({}, templateProps, {
templateKey: "text",
rootTagName: "span",
rootProps: {
className: cssClasses.text
},
data: {
hasManyResults: nbHits > 1,
hasNoResults: nbHits === 0,
hasOneResult: nbHits === 1,
hitsPerPage: hitsPerPage,
nbHits: nbHits,
nbPages: nbPages,
page: page,
processingTimeMS: processingTimeMS,
query: query,
cssClasses: cssClasses
}
})));
};
var defaultTemplates$b = {
text: "{{#hasNoResults}}No results{{/hasNoResults}}\n {{#hasOneResult}}1 result{{/hasOneResult}}\n {{#hasManyResults}}{{#helpers.formatNumber}}{{nbHits}}{{/helpers.formatNumber}} results{{/hasManyResults}} found in {{processingTimeMS}}ms"
};
var withUsage$B = createDocumentationMessageGenerator({
name: 'stats'
});
var suit$j = component('Stats');
var renderer$g = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var hitsPerPage = _ref2.hitsPerPage,
nbHits = _ref2.nbHits,
nbPages = _ref2.nbPages,
page = _ref2.page,
processingTimeMS = _ref2.processingTimeMS,
query = _ref2.query,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$b,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(Stats, {
cssClasses: cssClasses,
hitsPerPage: hitsPerPage,
nbHits: nbHits,
nbPages: nbPages,
page: page,
processingTimeMS: processingTimeMS,
query: query,
templateProps: renderState.templateProps
}), containerNode);
};
};
/**
* @typedef {Object} StatsWidgetTemplates
* @property {string|function} [text] Text template, provided with `hasManyResults`,
* `hasNoResults`, `hasOneResult`, `hitsPerPage`, `nbHits`, `nbPages`, `page`, `processingTimeMS`, `query`.
*/
/**
* @typedef {Object} StatsWidgetCssClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [text] CSS class to add to the text span element.
*/
/**
* @typedef {Object} StatsTextData
* @property {boolean} hasManyResults True if the result set has more than one result.
* @property {boolean} hasNoResults True if the result set has no result.
* @property {boolean} hasOneResult True if the result set has exactly one result.
* @property {number} hitsPerPage Number of hits per page.
* @property {number} nbHits Number of hit in the result set.
* @property {number} nbPages Number of pages in the result set with regard to the hitsPerPage and number of hits.
* @property {number} page Number of the current page. First page is 0.
* @property {number} processingTimeMS Time taken to compute the results inside the engine.
* @property {string} query Text query currently used.
*/
/**
* @typedef {Object} StatsWidgetOptions
* @property {string|HTMLElement} container Place where to insert the widget in your webpage.
* @property {StatsWidgetTemplates} [templates] Templates to use for the widget.
* @property {StatsWidgetCssClasses} [cssClasses] CSS classes to add.
*/
/**
* The `stats` widget is used to display useful insights about the current results.
*
* By default, it will display the **number of hits** and the time taken to compute the
* results inside the engine.
* @type {WidgetFactory}
* @devNovel Stats
* @category metadata
* @param {StatsWidgetOptions} $0 Stats widget options. Some keys are mandatory: `container`,
* @return {Widget} A new stats widget instance
* @example
* search.addWidget(
* instantsearch.widgets.stats({
* container: '#stats-container'
* })
* );
*/
function stats() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$b : _ref3$templates;
if (!container) {
throw new Error(withUsage$B('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$j(), userCssClasses.root),
text: classnames(suit$j({
descendantName: 'text'
}), userCssClasses.text)
};
var specializedRenderer = renderer$g({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeWidget = connectStats(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget();
}
var ToggleRefinement = function ToggleRefinement(_ref) {
var currentRefinement = _ref.currentRefinement,
refine = _ref.refine,
cssClasses = _ref.cssClasses,
templateProps = _ref.templateProps;
return index.createElement("div", {
className: cssClasses.root
}, index.createElement("label", {
className: cssClasses.label
}, index.createElement("input", {
className: cssClasses.checkbox,
type: "checkbox",
checked: currentRefinement.isRefined,
onChange: function onChange(event) {
return refine(!event.target.checked);
}
}), index.createElement(Template, _extends({}, templateProps, {
rootTagName: "span",
rootProps: {
className: cssClasses.labelText
},
templateKey: "labelText",
data: currentRefinement
}))));
};
var defaultTemplates$c = {
labelText: '{{name}}'
};
var withUsage$C = createDocumentationMessageGenerator({
name: 'toggle-refinement'
});
var suit$k = component('ToggleRefinement');
var renderer$h = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var value = _ref2.value,
createURL = _ref2.createURL,
_refine = _ref2.refine,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$c,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(ToggleRefinement, {
createURL: createURL,
cssClasses: cssClasses,
currentRefinement: value,
templateProps: renderState.templateProps,
refine: function refine(isRefined) {
return _refine({
isRefined: isRefined
});
}
}), containerNode);
};
};
/**
* @typedef {Object} ToggleWidgetCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [label] CSS class to add to the label wrapping element
* @property {string|string[]} [checkbox] CSS class to add to the checkbox
* @property {string|string[]} [labelText] CSS class to add to the label text.
*/
/**
* @typedef {Object} ToggleWidgetTemplates
* @property {string|function(object):string} labelText the text that describes the toggle action. This
* template receives some contextual information:
* - `isRefined` which is `true` if the checkbox is checked
* - `count` - the count of the values if the toggle in the next refinements
* - `onFacetValue`, `offFacetValue`: objects with `count` (useful to get the other value of `count`)
*/
/**
* @typedef {Object} ToggleWidgetOptions
* @property {string|HTMLElement} container Place where to insert the widget in your webpage.
* @property {string} attribute Name of the attribute for faceting (eg. "free_shipping").
* @property {string|number|boolean} on Value to filter on when checked.
* @property {string|number|boolean} off Value to filter on when unchecked.
* element (when using the default template). By default when switching to `off`, no refinement will be asked. So you
* will get both `true` and `false` results. If you set the off value to `false` then you will get only objects
* having `false` has a value for the selected attribute.
* @property {ToggleWidgetTemplates} [templates] Templates to use for the widget.
* @property {ToggleWidgetCSSClasses} [cssClasses] CSS classes to add.
*/
/**
* The toggleRefinement widget lets the user either:
* - switch between two values for a single facetted attribute (free_shipping / not_free_shipping)
* - toggleRefinement a faceted value on and off (only 'canon' for brands)
*
* This widget is particularly useful if you have a boolean value in the records.
*
* @requirements
* The attribute passed to `attribute` must be declared as an
* [attribute for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting)
* in your Algolia settings.
*
* @type {WidgetFactory}
* @devNovel ToggleRefinement
* @category filter
* @param {ToggleWidgetOptions} $0 Options for the ToggleRefinement widget.
* @return {Widget} A new instance of the ToggleRefinement widget
* @example
* search.addWidget(
* instantsearch.widgets.toggleRefinement({
* container: '#free-shipping',
* attribute: 'free_shipping',
* on: true,
* templates: {
* labelText: 'Free shipping'
* }
* })
* );
*/
function toggleRefinement() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attribute = _ref3.attribute,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$c : _ref3$templates,
_ref3$on = _ref3.on,
on = _ref3$on === void 0 ? true : _ref3$on,
off = _ref3.off;
if (!container) {
throw new Error(withUsage$C('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$k(), userCssClasses.root),
label: classnames(suit$k({
descendantName: 'label'
}), userCssClasses.label),
checkbox: classnames(suit$k({
descendantName: 'checkbox'
}), userCssClasses.checkbox),
labelText: classnames(suit$k({
descendantName: 'labelText'
}), userCssClasses.labelText)
};
var specializedRenderer = renderer$h({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeWidget = connectToggleRefinement(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
attribute: attribute,
on: on,
off: off
});
}
var withUsage$D = createDocumentationMessageGenerator({
name: 'analytics'
});
/**
* @typedef {Object} AnalyticsWidgetOptions
* @property {function(qs: string, state: SearchParameters, results: SearchResults)} pushFunction
* Function called when data are ready to be pushed. It should push the data to your analytics platform.
* The `qs` parameter contains the parameters serialized as a query string. The `state` contains the
* whole search state, and the `results` the last results received.
* @property {number} [delay=3000] Number of milliseconds between last search key stroke and calling pushFunction.
* @property {boolean} [triggerOnUIInteraction=false] Trigger pushFunction after click on page or redirecting the page
* @property {boolean} [pushInitialSearch=true] Trigger pushFunction after the initial search
* @property {boolean} [pushPagination=false] Trigger pushFunction on pagination
*/
/**
* The analytics widget pushes the current state of the search to the analytics platform of your
* choice. It requires the implementation of a function that will push the data.
*
* This is a headless widget, which means that it does not have a rendered output in the
* UI.
* @type {WidgetFactory}
* @devNovel Analytics
* @category analytics
* @param {AnalyticsWidgetOptions} $0 The Analytics widget options.
* @return {Widget} A new instance of the Analytics widget.
* @example
* search.addWidget(
* instantsearch.widgets.analytics({
* pushFunction: function(formattedParameters, state, results) {
* // Google Analytics
* // window.ga('set', 'page', window.location.pathname + window.location.search);
* // window.ga('send', 'pageView');
*
* // GTM
* // dataLayer.push({'event': 'search', 'Search Query': state.query, 'Facet Parameters': formattedParameters, 'Number of Hits': results.nbHits});
*
* // Segment.io
* // analytics.page( '[SEGMENT] instantsearch', { path: '/instantsearch/?query=' + state.query + '&' + formattedParameters });
*
* // Kissmetrics
* // var objParams = JSON.parse('{"' + decodeURI(formattedParameters.replace(/&/g, "\",\"").replace(/=/g,"\":\"")) + '"}');
* // var arrParams = $.map(objParams, function(value, index) {
* // return [value];
* // });
* //
* // _kmq.push(['record', '[KM] Viewed Result page', {
* // 'Query': state.query ,
* // 'Number of Hits': results.nbHits,
* // 'Search Params': arrParams
* // }]);
*
* // any other analytics service
* }
* })
* );
*/
function analytics() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
pushFunction = _ref.pushFunction,
_ref$delay = _ref.delay,
delay = _ref$delay === void 0 ? 3000 : _ref$delay,
_ref$triggerOnUIInter = _ref.triggerOnUIInteraction,
triggerOnUIInteraction = _ref$triggerOnUIInter === void 0 ? false : _ref$triggerOnUIInter,
_ref$pushInitialSearc = _ref.pushInitialSearch,
pushInitialSearch = _ref$pushInitialSearc === void 0 ? true : _ref$pushInitialSearc,
_ref$pushPagination = _ref.pushPagination,
pushPagination = _ref$pushPagination === void 0 ? false : _ref$pushPagination;
if (!pushFunction) {
throw new Error(withUsage$D('The `pushFunction` option is required.'));
}
var cachedState = null;
var serializeRefinements = function serializeRefinements(obj) {
var str = [];
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
var values = obj[p].join('+');
str.push("".concat(encodeURIComponent(p), "=").concat(encodeURIComponent(p), "_").concat(encodeURIComponent(values)));
}
}
return str.join('&');
};
var serializeNumericRefinements = function serializeNumericRefinements(numericRefinements) {
var numericStr = [];
for (var attr in numericRefinements) {
if (numericRefinements.hasOwnProperty(attr)) {
var filter = numericRefinements[attr];
if (filter.hasOwnProperty('>=') && filter.hasOwnProperty('<=')) {
if (filter['>='][0] === filter['<='][0]) {
numericStr.push("".concat(attr, "=").concat(attr, "_").concat(filter['>=']));
} else {
numericStr.push("".concat(attr, "=").concat(attr, "_").concat(filter['>='], "to").concat(filter['<=']));
}
} else if (filter.hasOwnProperty('>=')) {
numericStr.push("".concat(attr, "=").concat(attr, "_from").concat(filter['>=']));
} else if (filter.hasOwnProperty('<=')) {
numericStr.push("".concat(attr, "=").concat(attr, "_to").concat(filter['<=']));
} else if (filter.hasOwnProperty('=')) {
var equals = [];
for (var equal in filter['=']) {
// eslint-disable-next-line max-depth
if (filter['='].hasOwnProperty(equal)) {
equals.push(filter['='][equal]);
}
}
numericStr.push("".concat(attr, "=").concat(attr, "_").concat(equals.join('-')));
}
}
}
return numericStr.join('&');
};
var lastSentData = '';
var sendAnalytics = function sendAnalytics(state) {
if (state === null) {
return;
}
var formattedParams = [];
var serializedRefinements = serializeRefinements(_objectSpread({}, state.state.disjunctiveFacetsRefinements, state.state.facetsRefinements, state.state.hierarchicalFacetsRefinements));
var serializedNumericRefinements = serializeNumericRefinements(state.state.numericRefinements);
if (serializedRefinements !== '') {
formattedParams.push(serializedRefinements);
}
if (serializedNumericRefinements !== '') {
formattedParams.push(serializedNumericRefinements);
}
formattedParams = formattedParams.join('&');
var dataToSend = "Query: ".concat(state.state.query, ", ").concat(formattedParams);
if (pushPagination === true) {
dataToSend += ", Page: ".concat(state.state.page);
}
if (lastSentData !== dataToSend) {
pushFunction(formattedParams, state.state, state.results);
lastSentData = dataToSend;
}
};
var pushTimeout;
var isInitialSearch = true;
if (pushInitialSearch === true) {
isInitialSearch = false;
}
return {
init: function init() {
if (triggerOnUIInteraction === true) {
document.addEventListener('click', function () {
sendAnalytics(cachedState);
});
window.addEventListener('beforeunload', function () {
sendAnalytics(cachedState);
});
}
},
render: function render(_ref2) {
var results = _ref2.results,
state = _ref2.state;
if (isInitialSearch === true) {
isInitialSearch = false;
return;
}
cachedState = {
results: results,
state: state
};
if (pushTimeout) {
clearTimeout(pushTimeout);
}
pushTimeout = setTimeout(function () {
return sendAnalytics(cachedState);
}, delay);
}
};
}
var renderLink = function renderLink(_ref) {
var cssClasses = _ref.cssClasses,
createURL = _ref.createURL,
refine = _ref.refine,
templateProps = _ref.templateProps;
return function (item, idx, items) {
var isLast = idx === items.length - 1;
var link = isLast ? item.label : index.createElement("a", {
className: cssClasses.link,
href: createURL(item.value),
onClick: function onClick(event) {
event.preventDefault();
refine(item.value);
}
}, item.label);
return index.createElement("li", {
key: item.label + idx,
className: classnames(cssClasses.item, _defineProperty({}, cssClasses.selectedItem, isLast))
}, index.createElement(Template, _extends({}, templateProps, {
templateKey: "separator",
rootTagName: "span",
rootProps: {
className: cssClasses.separator,
'aria-hidden': true
}
})), link);
};
};
var Breadcrumb = function Breadcrumb(_ref2) {
var createURL = _ref2.createURL,
items = _ref2.items,
refine = _ref2.refine,
cssClasses = _ref2.cssClasses,
templateProps = _ref2.templateProps;
return index.createElement("div", {
className: classnames(cssClasses.root, _defineProperty({}, cssClasses.noRefinementRoot, items.length === 0))
}, index.createElement("ul", {
className: cssClasses.list
}, index.createElement("li", {
className: classnames(cssClasses.item, _defineProperty({}, cssClasses.selectedItem, items.length === 0))
}, index.createElement(Template, _extends({}, templateProps, {
templateKey: "home",
rootTagName: "a",
rootProps: {
className: cssClasses.link,
href: createURL(null),
onClick: function onClick(event) {
event.preventDefault();
refine(null);
}
}
}))), items.map(renderLink({
cssClasses: cssClasses,
createURL: createURL,
refine: refine,
templateProps: templateProps
}))));
};
var defaultTemplates$d = {
home: 'Home',
separator: '>'
};
var withUsage$E = createDocumentationMessageGenerator({
name: 'breadcrumb'
});
var suit$l = component('Breadcrumb');
var renderer$i = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var canRefine = _ref2.canRefine,
createURL = _ref2.createURL,
instantSearchInstance = _ref2.instantSearchInstance,
items = _ref2.items,
refine = _ref2.refine;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$d,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(Breadcrumb, {
canRefine: canRefine,
cssClasses: cssClasses,
createURL: createURL,
items: items,
refine: refine,
templateProps: renderState.templateProps
}), containerNode);
};
};
/**
* @typedef {Object} BreadcrumbCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element of the widget.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root element of the widget if there are no refinements.
* @property {string|string[]} [list] CSS class to add to the list element.
* @property {string|string[]} [item] CSS class to add to the items of the list. The items contains the link and the separator.
* @property {string|string[]} [selectedItem] CSS class to add to the selected item in the list: the last one or the home if there are no refinements.
* @property {string|string[]} [separator] CSS class to add to the separator.
* @property {string|string[]} [link] CSS class to add to the links in the items.
*/
/**
* @typedef {Object} BreadcrumbTemplates
* @property {string|function(object):string} [home = 'Home'] Label of the breadcrumb's first element.
* @property {string|function(object):string} [separator = '>'] Symbol used to separate the elements of the breadcrumb.
*/
/**
* @typedef {Object} BreadcrumbWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {string[]} attributes Array of attributes to use to generate the breadcrumb.
* @property {string} [separator = ' > '] The level separator used in the records.
* @property {string} [rootPath = null] Prefix path to use if the first level is not the root level.
* @property {BreadcrumbTemplates} [templates] Templates to use for the widget.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
* @property {BreadcrumbCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
*/
/**
* The breadcrumb widget is a secondary navigation scheme that allows the user to see where the current page is in relation to the facet's hierarchy.
*
* It reduces the number of actions a user needs to take in order to get to a higher-level page and improve the discoverability of the app or website's sections and pages.
* It is commonly used for websites with a large amount of data organized into categories with subcategories.
*
* All attributes (lvl0, lvl1 in this case) must be declared as [attributes for faceting](https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting) in your
* Algolia settings.
*
* @requirements
* Your objects must be formatted in a specific way to be
* able to display a breadcrumb. Here's an example:
*
* ```javascript
* {
* "objectID": "123",
* "name": "orange",
* "categories": {
* "lvl0": "fruits",
* "lvl1": "fruits > citrus"
* }
* }
* ```
*
* Each level must be specified entirely.
* It's also possible to have multiple values per level, for instance:
*
* ```javascript
* {
* "objectID": "123",
* "name": "orange",
* "categories": {
* "lvl0": ["fruits", "vitamins"],
* "lvl1": ["fruits > citrus", "vitamins > C"]
* }
* }
* ```
* @type {WidgetFactory}
* @devNovel Breadcrumb
* @category navigation
* @param {BreadcrumbWidgetOptions} $0 The Breadcrumb widget options.
* @return {Widget} A new Breadcrumb widget instance.
* @example
* search.addWidget(
* instantsearch.widgets.breadcrumb({
* container: '#breadcrumb',
* attributes: ['hierarchicalCategories.lvl0', 'hierarchicalCategories.lvl1', 'hierarchicalCategories.lvl2'],
* templates: { home: 'Home Page' },
* separator: ' / ',
* rootPath: 'Cameras & Camcorders > Digital Cameras',
* })
* );
*/
function breadcrumb() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
attributes = _ref3.attributes,
separator = _ref3.separator,
_ref3$rootPath = _ref3.rootPath,
rootPath = _ref3$rootPath === void 0 ? null : _ref3$rootPath,
transformItems = _ref3.transformItems,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$d : _ref3$templates,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
if (!container) {
throw new Error(withUsage$E('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$l(), userCssClasses.root),
noRefinementRoot: classnames(suit$l({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
list: classnames(suit$l({
descendantName: 'list'
}), userCssClasses.list),
item: classnames(suit$l({
descendantName: 'item'
}), userCssClasses.item),
selectedItem: classnames(suit$l({
descendantName: 'item',
modifierName: 'selected'
}), userCssClasses.selectedItem),
separator: classnames(suit$l({
descendantName: 'separator'
}), userCssClasses.separator),
link: classnames(suit$l({
descendantName: 'link'
}), userCssClasses.link)
};
var specializedRenderer = renderer$i({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeBreadcrumb = connectBreadcrumb(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeBreadcrumb({
attributes: attributes,
separator: separator,
rootPath: rootPath,
transformItems: transformItems
});
}
var MenuSelect =
/*#__PURE__*/
function (_Component) {
_inherits(MenuSelect, _Component);
function MenuSelect() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, MenuSelect);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MenuSelect)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleSelectChange", function (_ref) {
var value = _ref.target.value;
_this.props.refine(value);
});
return _this;
}
_createClass(MenuSelect, [{
key: "render",
value: function render() {
var _this$props = this.props,
cssClasses = _this$props.cssClasses,
templateProps = _this$props.templateProps,
items = _this$props.items;
var _ref2 = items.find(function (item) {
return item.isRefined;
}) || {
value: ''
},
selectedValue = _ref2.value;
var rootClassNames = classnames(cssClasses.root, _defineProperty({}, cssClasses.noRefinementRoot, items.length === 0));
return index.createElement("div", {
className: rootClassNames
}, index.createElement("select", {
className: cssClasses.select,
value: selectedValue,
onChange: this.handleSelectChange
}, index.createElement(Template, _extends({}, templateProps, {
templateKey: "defaultOption",
rootTagName: "option",
rootProps: {
value: '',
className: cssClasses.option
}
})), items.map(function (item) {
return index.createElement(Template, _extends({}, templateProps, {
templateKey: "item",
rootTagName: "option",
rootProps: {
value: item.value,
className: cssClasses.option
},
key: item.value,
data: item
}));
})));
}
}]);
return MenuSelect;
}(Component$1);
var defaultTemplates$e = {
item: '{{label}} ({{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}})',
defaultOption: 'See all'
};
var withUsage$F = createDocumentationMessageGenerator({
name: 'menu-select'
});
var suit$m = component('MenuSelect');
var renderer$j = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
renderState = _ref.renderState,
templates = _ref.templates;
return function (_ref2, isFirstRendering) {
var refine = _ref2.refine,
items = _ref2.items,
canRefine = _ref2.canRefine,
instantSearchInstance = _ref2.instantSearchInstance;
if (isFirstRendering) {
renderState.templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates$e,
templatesConfig: instantSearchInstance.templatesConfig,
templates: templates
});
return;
}
render$1(index.createElement(MenuSelect, {
cssClasses: cssClasses,
items: items,
refine: refine,
templateProps: renderState.templateProps,
canRefine: canRefine
}), containerNode);
};
};
/**
* @typedef {Object} MenuSelectCSSClasses
* @property {string|string[]} [root] CSS class to add to the root element.
* @property {string|string[]} [noRefinementRoot] CSS class to add to the root when there are no items to display
* @property {string|string[]} [select] CSS class to add to the select element.
* @property {string|string[]} [option] CSS class to add to the option element.
*
*/
/**
* @typedef {Object} MenuSelectTemplates
* @property {string|function(label: string, count: number, isRefined: boolean, value: string)} [item] Item template, provided with `label`, `count`, `isRefined` and `value` data properties.
* @property {string} [defaultOption = 'See all'] Label of the "see all" option in the select.
*/
/**
* @typedef {Object} MenuSelectWidgetOptions
* @property {string|HTMLElement} container CSS Selector or HTMLElement to insert the widget.
* @property {string} attribute Name of the attribute for faceting
* @property {string[]|function} [sortBy=['name:asc']] How to sort refinements. Possible values: `count|isRefined|name:asc|name:desc`.
*
* You can also use a sort function that behaves like the standard Javascript [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax).
* @property {MenuSelectTemplates} [templates] Customize the output through templating.
* @property {number} [limit=10] How many facets values to retrieve.
* @property {MenuSelectCSSClasses} [cssClasses] CSS classes to add to the wrapping elements.
* @property {function(object[]):object[]} [transformItems] Function to transform the items passed to the templates.
*/
/**
* Create a menu select out of a facet
* @type {WidgetFactory}
* @category filter
* @param {MenuSelectWidgetOptions} $0 The Menu select widget options.
* @return {Widget} Creates a new instance of the Menu select widget.
* @example
* search.addWidget(
* instantsearch.widgets.menuSelect({
* container: '#categories-menuSelect',
* attribute: 'hierarchicalCategories.lvl0',
* limit: 10,
* })
* );
*/
function menuSelect(_ref3) {
var container = _ref3.container,
attribute = _ref3.attribute,
_ref3$sortBy = _ref3.sortBy,
sortBy = _ref3$sortBy === void 0 ? ['name:asc'] : _ref3$sortBy,
_ref3$limit = _ref3.limit,
limit = _ref3$limit === void 0 ? 10 : _ref3$limit,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? defaultTemplates$e : _ref3$templates,
transformItems = _ref3.transformItems;
if (!container) {
throw new Error(withUsage$F('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$m(), userCssClasses.root),
noRefinementRoot: classnames(suit$m({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
select: classnames(suit$m({
descendantName: 'select'
}), userCssClasses.select),
option: classnames(suit$m({
descendantName: 'option'
}), userCssClasses.option)
};
var specializedRenderer = renderer$j({
containerNode: containerNode,
cssClasses: cssClasses,
renderState: {},
templates: templates
});
var makeWidget = connectMenu(specializedRenderer);
return makeWidget({
attribute: attribute,
limit: limit,
sortBy: sortBy,
transformItems: transformItems
});
}
var _ref2$1 =
/*#__PURE__*/
index.createElement("path", {
fill: "#5468FF",
d: "M78.99.94h16.6a2.97 2.97 0 0 1 2.96 2.96v16.6a2.97 2.97 0 0 1-2.97 2.96h-16.6a2.97 2.97 0 0 1-2.96-2.96V3.9A2.96 2.96 0 0 1 79 .94"
});
var _ref3$2 =
/*#__PURE__*/
index.createElement("path", {
fill: "#FFF",
d: "M89.63 5.97v-.78a.98.98 0 0 0-.98-.97h-2.28a.98.98 0 0 0-.97.97V6c0 .09.08.15.17.13a7.13 7.13 0 0 1 3.9-.02c.08.02.16-.04.16-.13m-6.25 1L83 6.6a.98.98 0 0 0-1.38 0l-.46.46a.97.97 0 0 0 0 1.38l.38.39c.06.06.15.04.2-.02a7.49 7.49 0 0 1 1.63-1.62c.07-.04.08-.14.02-.2m4.16 2.45v3.34c0 .1.1.17.2.12l2.97-1.54c.06-.03.08-.12.05-.18a3.7 3.7 0 0 0-3.08-1.87c-.07 0-.14.06-.14.13m0 8.05a4.49 4.49 0 1 1 0-8.98 4.49 4.49 0 0 1 0 8.98m0-10.85a6.37 6.37 0 1 0 0 12.74 6.37 6.37 0 0 0 0-12.74"
});
var PoweredBy = function PoweredBy(_ref) {
var url = _ref.url,
theme = _ref.theme,
cssClasses = _ref.cssClasses;
return index.createElement("div", {
className: cssClasses.root
}, index.createElement("a", {
href: url,
target: "_blank",
className: cssClasses.link,
"aria-label": "Search by Algolia",
rel: "noopener noreferrer"
}, index.createElement("svg", {
height: "1.2em",
className: cssClasses.logo,
viewBox: "0 0 168 24" // This style is necessary as long as it's not included in InstantSearch.css.
// For now, InstantSearch.css sets a maximum width of 70px.
,
style: {
width: 'auto'
}
}, index.createElement("path", {
fill: theme === 'dark' ? '#FFF' : '#5D6494',
d: "M6.97 6.68V8.3a4.47 4.47 0 0 0-2.42-.67 2.2 2.2 0 0 0-1.38.4c-.34.26-.5.6-.5 1.02 0 .43.16.77.49 1.03.33.25.83.53 1.51.83a7.04 7.04 0 0 1 1.9 1.08c.34.24.58.54.73.89.15.34.23.74.23 1.18 0 .95-.33 1.7-1 2.24a4 4 0 0 1-2.6.81 5.71 5.71 0 0 1-2.94-.68v-1.71c.84.63 1.81.94 2.92.94.58 0 1.05-.14 1.39-.4.34-.28.5-.65.5-1.13 0-.29-.1-.55-.3-.8a2.2 2.2 0 0 0-.65-.53 23.03 23.03 0 0 0-1.64-.78 13.67 13.67 0 0 1-1.11-.64c-.12-.1-.28-.22-.46-.4a1.72 1.72 0 0 1-.39-.5 4.46 4.46 0 0 1-.22-.6c-.07-.23-.1-.48-.1-.75 0-.91.33-1.63 1-2.17a4 4 0 0 1 2.57-.8c.97 0 1.8.18 2.47.52zm7.47 5.7v-.3a2.26 2.26 0 0 0-.5-1.44c-.3-.35-.74-.53-1.32-.53-.53 0-.99.2-1.37.58-.38.39-.62.95-.72 1.68h3.91zm1 2.79v1.4c-.6.34-1.38.51-2.36.51a4.02 4.02 0 0 1-3-1.13 4.04 4.04 0 0 1-1.11-2.97c0-1.3.34-2.32 1.02-3.06a3.38 3.38 0 0 1 2.6-1.1c1.03 0 1.85.32 2.46.96.6.64.9 1.57.9 2.78 0 .33-.03.68-.09 1.04h-5.31c.1.7.4 1.24.89 1.61.49.38 1.1.56 1.85.56.86 0 1.58-.2 2.15-.6zm6.61-1.78h-1.21c-.6 0-1.05.12-1.35.36-.3.23-.46.53-.46.89 0 .37.12.66.36.88.23.2.57.32 1.02.32.5 0 .9-.15 1.2-.43.3-.28.44-.65.44-1.1v-.92zm-4.07-2.55V9.33a4.96 4.96 0 0 1 2.5-.55c2.1 0 3.17 1.03 3.17 3.08V17H22.1v-.96c-.42.68-1.15 1.02-2.19 1.02-.76 0-1.38-.22-1.84-.66-.46-.44-.7-1-.7-1.68 0-.78.3-1.38.88-1.81.59-.43 1.4-.65 2.46-.65h1.34v-.46c0-.55-.13-.97-.4-1.25-.26-.29-.7-.43-1.32-.43-.86 0-1.65.24-2.35.72zm9.34-1.93v1.42c.39-1 1.1-1.5 2.12-1.5.15 0 .31.02.5.05v1.53c-.23-.1-.48-.14-.76-.14-.54 0-.99.24-1.34.71a2.8 2.8 0 0 0-.52 1.71V17h-1.57V8.91h1.57zm5 4.09a3 3 0 0 0 .76 2.01c.47.53 1.14.8 2 .8.64 0 1.24-.18 1.8-.53v1.4c-.53.32-1.2.48-2 .48a3.98 3.98 0 0 1-4.17-4.18c0-1.16.38-2.15 1.14-2.98a4 4 0 0 1 3.1-1.23c.7 0 1.34.15 1.92.44v1.44a3.24 3.24 0 0 0-1.77-.5A2.65 2.65 0 0 0 32.33 13zm7.92-7.28v4.58c.46-1 1.3-1.5 2.5-1.5.8 0 1.42.24 1.9.73.48.5.72 1.17.72 2.05V17H43.8v-5.1c0-.56-.14-.99-.43-1.29-.28-.3-.65-.45-1.1-.45-.54 0-1 .2-1.42.6-.4.4-.61 1.02-.61 1.85V17h-1.56V5.72h1.56zM55.2 15.74c.6 0 1.1-.25 1.5-.76.4-.5.6-1.16.6-1.95 0-.92-.2-1.62-.6-2.12-.4-.5-.92-.74-1.55-.74-.56 0-1.05.22-1.5.67-.44.45-.66 1.13-.66 2.06 0 .96.22 1.67.64 2.14.43.47.95.7 1.57.7zM53 5.72v4.42a2.74 2.74 0 0 1 2.43-1.34c1.03 0 1.86.38 2.51 1.15.65.76.97 1.78.97 3.05 0 1.13-.3 2.1-.92 2.9-.62.81-1.47 1.21-2.54 1.21s-1.9-.45-2.46-1.34V17h-1.58V5.72H53zm9.9 11.1l-3.22-7.9h1.74l1 2.62 1.26 3.42c.1-.32.48-1.46 1.15-3.42l.91-2.63h1.66l-2.92 7.87c-.78 2.07-1.96 3.1-3.56 3.1-.28 0-.53-.02-.73-.07v-1.34c.17.04.35.06.54.06 1.03 0 1.76-.57 2.17-1.7z"
}), _ref2$1, _ref3$2, index.createElement("path", {
fill: theme === 'dark' ? '#FFF' : '#5468FF',
d: "M120.92 18.8c-4.38.02-4.38-3.54-4.38-4.1V1.36l2.67-.42v13.25c0 .32 0 2.36 1.71 2.37v2.24zm-10.84-2.18c.82 0 1.43-.04 1.85-.12v-2.72a5.48 5.48 0 0 0-1.57-.2c-.3 0-.6.02-.9.07-.3.04-.57.12-.81.24-.24.11-.44.28-.58.49a.93.93 0 0 0-.22.65c0 .63.22 1 .61 1.23.4.24.94.36 1.62.36zm-.23-9.7c.88 0 1.62.11 2.23.33.6.22 1.09.53 1.44.92.36.4.61.92.76 1.48.16.56.23 1.17.23 1.85v6.87c-.4.1-1.03.2-1.86.32-.84.12-1.78.18-2.82.18-.69 0-1.32-.07-1.9-.2a4 4 0 0 1-1.46-.63c-.4-.3-.72-.67-.96-1.13a4.3 4.3 0 0 1-.34-1.8c0-.66.13-1.08.39-1.53.26-.45.6-.82 1.04-1.1.45-.3.95-.5 1.54-.62a8.8 8.8 0 0 1 3.79.05v-.44c0-.3-.04-.6-.11-.87a1.78 1.78 0 0 0-1.1-1.22c-.31-.12-.7-.2-1.15-.2a9.75 9.75 0 0 0-2.95.46l-.33-2.19c.34-.12.84-.23 1.48-.35.65-.12 1.34-.18 2.08-.18zm52.84 9.63c.82 0 1.43-.05 1.85-.13V13.7a5.42 5.42 0 0 0-1.57-.2c-.3 0-.6.02-.9.07-.3.04-.57.12-.81.24-.24.12-.44.28-.58.5a.93.93 0 0 0-.22.65c0 .63.22.99.61 1.23.4.24.94.36 1.62.36zm-.23-9.7c.88 0 1.63.11 2.23.33.6.22 1.1.53 1.45.92.35.39.6.92.76 1.48.15.56.23 1.18.23 1.85v6.88c-.41.08-1.03.19-1.87.31-.83.12-1.77.18-2.81.18-.7 0-1.33-.06-1.9-.2a4 4 0 0 1-1.47-.63c-.4-.3-.72-.67-.95-1.13a4.3 4.3 0 0 1-.34-1.8c0-.66.13-1.08.38-1.53.26-.45.61-.82 1.05-1.1.44-.3.95-.5 1.53-.62a8.8 8.8 0 0 1 3.8.05v-.43c0-.31-.04-.6-.12-.88-.07-.28-.2-.52-.38-.73a1.78 1.78 0 0 0-.73-.5c-.3-.1-.68-.2-1.14-.2a9.85 9.85 0 0 0-2.95.47l-.32-2.19a11.63 11.63 0 0 1 3.55-.53zm-8.03-1.27a1.62 1.62 0 0 0 0-3.24 1.62 1.62 0 1 0 0 3.24zm1.35 13.22h-2.7V7.27l2.7-.42V18.8zm-4.72 0c-4.38.02-4.38-3.54-4.38-4.1l-.01-13.34 2.67-.42v13.25c0 .32 0 2.36 1.72 2.37v2.24zm-8.7-5.9a4.7 4.7 0 0 0-.74-2.79 2.4 2.4 0 0 0-2.07-1 2.4 2.4 0 0 0-2.06 1 4.7 4.7 0 0 0-.74 2.8c0 1.16.25 1.94.74 2.62a2.4 2.4 0 0 0 2.07 1.02c.88 0 1.57-.34 2.07-1.02.49-.68.73-1.46.73-2.63zm2.74 0a6.46 6.46 0 0 1-1.52 4.23c-.49.53-1.07.94-1.76 1.22-.68.29-1.73.45-2.26.45-.53 0-1.58-.15-2.25-.45a5.1 5.1 0 0 1-2.88-3.13 7.3 7.3 0 0 1-.01-4.84 5.13 5.13 0 0 1 2.9-3.1 5.67 5.67 0 0 1 2.22-.42c.81 0 1.56.14 2.24.42.69.29 1.28.69 1.75 1.22.49.52.87 1.15 1.14 1.89a7 7 0 0 1 .43 2.5zm-20.14 0c0 1.11.25 2.36.74 2.88.5.52 1.13.78 1.91.78a4.07 4.07 0 0 0 2.12-.6V9.33c-.19-.04-.99-.2-1.76-.23a2.67 2.67 0 0 0-2.23 1 4.73 4.73 0 0 0-.78 2.8zm7.44 5.27c0 1.82-.46 3.16-1.4 4-.94.85-2.37 1.27-4.3 1.27-.7 0-2.17-.13-3.34-.4l.43-2.11c.98.2 2.27.26 2.95.26 1.08 0 1.84-.22 2.3-.66.46-.43.68-1.08.68-1.94v-.44a5.2 5.2 0 0 1-2.54.6 5.6 5.6 0 0 1-2.01-.36 4.2 4.2 0 0 1-2.58-2.71 9.88 9.88 0 0 1 .02-5.35 4.92 4.92 0 0 1 2.93-2.96 6.6 6.6 0 0 1 2.43-.46 19.64 19.64 0 0 1 4.43.66v10.6z"
}))));
};
var suit$n = component('PoweredBy');
var withUsage$G = createDocumentationMessageGenerator({
name: 'powered-by'
});
var renderer$k = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses;
return function (_ref2, isFirstRendering) {
var url = _ref2.url,
widgetParams = _ref2.widgetParams;
if (isFirstRendering) {
var theme = widgetParams.theme;
render$1(index.createElement(PoweredBy, {
cssClasses: cssClasses,
url: url,
theme: theme
}), containerNode);
return;
}
};
};
/**
* @typedef {Object} PoweredByWidgetCssClasses
* @property {string|string[]} [root] CSS classes added to the root element of the widget.
* @property {string|string[]} [link] CSS class to add to the link.
* @property {string|string[]} [logo] CSS class to add to the SVG logo.
*/
/**
* @typedef {Object} PoweredByWidgetOptions
* @property {string|HTMLElement} container Place where to insert the widget in your webpage.
* @property {string} [theme] The theme of the logo ("light" or "dark").
* @property {PoweredByWidgetCssClasses} [cssClasses] CSS classes to add.
*/
/**
* The `poweredBy` widget is used to display the logo to redirect to Algolia.
* @type {WidgetFactory}
* @devNovel PoweredBy
* @category metadata
* @param {PoweredByWidgetOptions} $0 PoweredBy widget options. Some keys are mandatory: `container`,
* @return {Widget} A new poweredBy widget instance
* @example
* search.addWidget(
* instantsearch.widgets.poweredBy({
* container: '#poweredBy-container',
* theme: 'dark',
* })
* );
*/
function poweredBy() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
container = _ref3.container,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
_ref3$theme = _ref3.theme,
theme = _ref3$theme === void 0 ? 'light' : _ref3$theme;
if (!container) {
throw new Error(withUsage$G('The `container` option is required.'));
}
var containerNode = getContainerNode(container);
var cssClasses = {
root: classnames(suit$n(), suit$n({
modifierName: theme === 'dark' ? 'dark' : 'light'
}), userCssClasses.root),
link: classnames(suit$n({
descendantName: 'link'
}), userCssClasses.link),
logo: classnames(suit$n({
descendantName: 'logo'
}), userCssClasses.logo)
};
var specializedRenderer = renderer$k({
containerNode: containerNode,
cssClasses: cssClasses
});
var makeWidget = connectPoweredBy(specializedRenderer, function () {
return unmountComponentAtNode(containerNode);
});
return makeWidget({
theme: theme
});
}
var Panel = function Panel(_ref) {
var cssClasses = _ref.cssClasses,
hidden = _ref.hidden,
templateProps = _ref.templateProps,
data = _ref.data,
onRef = _ref.onRef;
return index.createElement("div", {
className: classnames(cssClasses.root, _defineProperty({}, cssClasses.noRefinementRoot, hidden)),
hidden: hidden
}, templateProps.templates.header && index.createElement(Template, _extends({}, templateProps, {
templateKey: "header",
rootProps: {
className: cssClasses.header
},
data: data
})), index.createElement("div", {
className: cssClasses.body,
ref: onRef
}), templateProps.templates.footer && index.createElement(Template, _extends({}, templateProps, {
templateKey: "footer",
rootProps: {
className: cssClasses.footer
},
data: data
})));
};
var withUsage$H = createDocumentationMessageGenerator({
name: 'panel'
});
var suit$o = component('Panel');
var renderer$l = function renderer(_ref) {
var containerNode = _ref.containerNode,
cssClasses = _ref.cssClasses,
templateProps = _ref.templateProps;
return function (_ref2) {
var options = _ref2.options,
hidden = _ref2.hidden;
var bodyRef = null;
render$1(index.createElement(Panel, {
cssClasses: cssClasses,
hidden: hidden,
templateProps: templateProps,
data: options,
onRef: function onRef(ref) {
return bodyRef = ref;
}
}), containerNode);
return {
bodyRef: bodyRef
};
};
};
/**
* @typedef {Object} PanelWidgetCSSClasses
* @property {string|string[]} [root] CSS classes added to the root element of the widget.
* @property {string|string[]} [noRefinementRoot] CSS classes added to the root element of the widget when there's no refinements.
* @property {string|string[]} [header] CSS class to add to the header.
* @property {string|string[]} [footer] CSS class to add to the SVG footer.
*/
/**
* @typedef {Object} PanelTemplates
* @property {string|function} [header = ''] Template to use for the header.
* @property {string|function} [footer = ''] Template to use for the footer.
*/
/**
* @typedef {Object} PanelWidgetOptions
* @property {function} [hidden] This function is called on each render to determine from the render options if the panel have to be hidden or not. If the value is `true` the CSS class `noRefinementRoot` is applied and the wrapper is hidden.
* @property {PanelTemplates} [templates] Templates to use for the widgets.
* @property {PanelWidgetCSSClasses} [cssClasses] CSS classes to add.
*/
/**
* The panel widget wraps other widgets in a consistent panel design. It also reacts, indicates and sets CSS classes when widgets are no more relevant for refining.
*
* @type {WidgetFactory}
* @devNovel Panel
* @category metadata
* @param {PanelWidgetOptions} $0 Panel widget options.
* @return {function} A new panel widget instance
* @example
* const refinementListWithPanel = instantsearch.widgets.panel({
* templates: {
* header: 'Brand',
* },
* })(instantsearch.widgets.refinementList);
*
* search.addWidget(
* refinementListWithPanel({
* container: '#refinement-list',
* attribute: 'brand',
* })
* );
*/
function panel() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref3$templates = _ref3.templates,
templates = _ref3$templates === void 0 ? {} : _ref3$templates,
_ref3$hidden = _ref3.hidden,
hidden = _ref3$hidden === void 0 ? function () {
return false;
} : _ref3$hidden,
_ref3$cssClasses = _ref3.cssClasses,
userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
_warning(typeof hidden === 'function', "The `hidden` option in the \"panel\" widget expects a function returning a boolean (received \"".concat(_typeof(hidden), "\" type)."));
var cssClasses = {
root: classnames(suit$o(), userCssClasses.root),
noRefinementRoot: classnames(suit$o({
modifierName: 'noRefinement'
}), userCssClasses.noRefinementRoot),
body: classnames(suit$o({
descendantName: 'body'
}), userCssClasses.body),
header: classnames(suit$o({
descendantName: 'header'
}), userCssClasses.header),
footer: classnames(suit$o({
descendantName: 'footer'
}), userCssClasses.footer)
};
return function (widgetFactory) {
return function () {
var widgetOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var container = widgetOptions.container;
if (!container) {
throw new Error(withUsage$H("The `container` option is required in the widget within the panel."));
}
var defaultTemplates = {
header: '',
footer: ''
};
var templateProps = prepareTemplateProps({
defaultTemplates: defaultTemplates,
templates: templates
});
var renderPanel = renderer$l({
containerNode: getContainerNode(container),
cssClasses: cssClasses,
templateProps: templateProps
});
var _renderPanel = renderPanel({
options: {},
hidden: true
}),
bodyRef = _renderPanel.bodyRef;
var widget = widgetFactory(_objectSpread({}, widgetOptions, {
container: getContainerNode(bodyRef)
}));
return _objectSpread({}, widget, {
dispose: function dispose() {
unmountComponentAtNode(getContainerNode(container));
if (typeof widget.dispose === 'function') {
var _widget$dispose;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
(_widget$dispose = widget.dispose).call.apply(_widget$dispose, [this].concat(args));
}
},
render: function render() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
var options = args[0];
renderPanel({
options: options,
hidden: Boolean(hidden(options))
});
if (typeof widget.render === 'function') {
var _widget$render;
(_widget$render = widget.render).call.apply(_widget$render, [this].concat(args));
}
}
});
};
};
}
/** @module module:instantsearch.widgets */
var widgets = /*#__PURE__*/Object.freeze({
clearRefinements: clearRefinements$1,
configure: configure,
currentRefinements: currentRefinements,
geoSearch: geoSearch,
hierarchicalMenu: hierarchicalMenu,
hits: hits,
hitsPerPage: hitsPerPage,
infiniteHits: infiniteHits,
menu: menu,
refinementList: refinementList,
numericMenu: numericMenu,
pagination: pagination,
rangeInput: rangeInput,
searchBox: searchBox,
rangeSlider: rangeSlider,
sortBy: sortBy,
ratingMenu: ratingMenu,
stats: stats,
toggleRefinement: toggleRefinement,
analytics: analytics,
breadcrumb: breadcrumb,
menuSelect: menuSelect,
poweredBy: poweredBy,
panel: panel
});
var routers = /*#__PURE__*/Object.freeze({
history: historyRouter
});
var stateMappings = /*#__PURE__*/Object.freeze({
simple: simpleMapping
});
/** @module module:instantsearch */
/**
* @external SearchParameters
* @see https://www.algolia.com/doc/api-reference/search-api-parameters/
*/
/**
* @external InstantSearch
* @see /instantsearch.html
*/
/**
* @typedef {Object|boolean} RoutingOptions
* @property {Router} [router=HistoryRouter()] The router is the part that will save the UI State.
* By default, it uses an instance of the `HistoryRouter` with the default parameters.
* @property {StateMapping} [stateMapping=SimpleStateMapping()] This object transforms the UI state into
* the object that willl be saved by the router.
*/
/**
* The state mapping is a way to customize the structure before sending it to the router. It can transform
* and filter out the properties. To work correctly, for any state ui S, the following should be valid:
* `S = routeToState(stateToRoute(S))`.
* @typedef {Object} StateMapping
* @property {function} stateToRoute Transforms a UI state representation into a route object.
* It receives an object that contains the UI state of all the widgets in the page. It should
* return an object of any form as long as this form can be read by the `routeToState`.
* @property {function} routeToState Transforms route object into a UI state representation.
* It receives an object that contains the UI state stored by the router. The format is the output
* of `stateToRoute`.
*/
/**
* The router is the part that saves and reads the object from the storage (most of the time the URL).
* @typedef {Object} Router
* @property {function} onUpdate Sets an event listener that is triggered when the storage is updated.
* The function should accept a callback to trigger when the update happens. In the case of the history
* / URL in a browser, the callback will be called by `onPopState`.
* @property {function} read Reads the storage and gets a route object. It does not take parameters,
* and should return an object.
* @property {function} write Pushes a route object into a storage. Takes the UI state mapped by the state
* mapping configured in the mapping.
* @property {function} createURL Transforms a route object into a URL. It receives an object and should
* return a string. It may return an empty string.
* @property {function} dispose Cleans up any event listeners.
*/
/**
* @typedef {Object} SearchClient
* @property {function} search Performs the requests in the hits.
* @property {function} searchForFacetValues Performs the requests in the facet values.
*/
/**
* @typedef {Object} InstantSearchOptions
* @property {string} indexName The name of the main index
* @property {SearchClient} searchClient The search client to plug to InstantSearch.js
*
* Usage:
* ```javascript
* // Using the default Algolia search client
* instantsearch({
* indexName: 'indexName',
* searchClient: algoliasearch('appId', 'apiKey')
* });
*
* // Using a custom search client
* instantsearch({
* indexName: 'indexName',
* searchClient: {
* search(requests) {
* // fetch response based on requests
* return response;
* },
* searchForFacetValues(requests) {
* // fetch response based on requests
* return response;
* }
* }
* });
* ```
* @property {string} [numberLocale] The locale used to display numbers. This will be passed
* to [`Number.prototype.toLocaleString()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
* @property {function} [searchFunction] A hook that will be called each time a search needs to be done, with the
* helper as a parameter. It's your responsibility to call `helper.search()`. This option allows you to avoid doing
* searches at page load for example.
* @property {object} [searchParameters] Additional parameters to pass to
* the Algolia API ([see full documentation](https://community.algolia.com/algoliasearch-helper-js/reference.html#searchparameters)).
* @property {number} [stalledSearchDelay=200] Time before a search is considered stalled.
* @property {RoutingOptions} [routing] Router configuration used to save the UI State into the URL or
* any client side persistence.
*/
/**
* InstantSearch is the main component of InstantSearch.js. This object
* manages the widget and lets you add new ones.
*
* Two parameters are required to get you started with InstantSearch.js:
* - `indexName`: the main index that you will use for your new search UI
* - `searchClient`: the search client to plug to InstantSearch.js
*
* The [search client provided by Algolia](https://github.com/algolia/algoliasearch-client-javascript)
* needs an `appId` and an `apiKey`. Those parameters can be found in your
* [Algolia dashboard](https://www.algolia.com/api-keys).
*
* If you want to get up and running quickly with InstantSearch.js, have a
* look at the [getting started](getting-started.html).
* @function instantsearch
* @param {InstantSearchOptions} options The options
* @return {InstantSearch} the instantsearch instance
*/
var instantsearch = function instantsearch(options) {
return new InstantSearch(options);
};
instantsearch.routers = routers;
instantsearch.stateMappings = stateMappings;
instantsearch.connectors = connectors;
instantsearch.widgets = widgets;
instantsearch.version = version$1;
instantsearch.highlight = highlight;
instantsearch.snippet = snippet;
return instantsearch;
}));
//# sourceMappingURL=instantsearch.development.js.map