angular-instantsearch
Version:
Lightning-fast search for Angular apps, by Algolia.
1,052 lines (1,027 loc) • 145 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('instantsearch.js/es/connectors'), require('algoliasearch/lite'), require('instantsearch.js/es'), require('instantsearch.js/es/widgets/index/index'), require('instantsearch.js/es/helpers'), require('instantsearch.js/es/lib/utils'), require('nouislider'), require('querystring-es3/encode')) :
typeof define === 'function' && define.amd ? define('angular-instantsearch', ['exports', '@angular/core', '@angular/common', 'instantsearch.js/es/connectors', 'algoliasearch/lite', 'instantsearch.js/es', 'instantsearch.js/es/widgets/index/index', 'instantsearch.js/es/helpers', 'instantsearch.js/es/lib/utils', 'nouislider', 'querystring-es3/encode'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['angular-instantsearch'] = {}, global.ng.core, global.ng.common, global.instantsearch.connectors, global.algoliasearch, global.instantsearch, global.instantsearch.widgets.index, global.instantsearch.helpers, global.instantsearch.lib.utils, global.noUiSlider, global.qs.encode));
}(this, (function (exports, core, common, connectors, algoliasearchProxy, instantsearch, indexWidget, helpers, utils, noUiSlider, encodeProxy) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var algoliasearchProxy__namespace = /*#__PURE__*/_interopNamespace(algoliasearchProxy);
var instantsearch__default = /*#__PURE__*/_interopDefaultLegacy(instantsearch);
var indexWidget__default = /*#__PURE__*/_interopDefaultLegacy(indexWidget);
var noUiSlider__namespace = /*#__PURE__*/_interopNamespace(noUiSlider);
var encodeProxy__namespace = /*#__PURE__*/_interopNamespace(encodeProxy);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
function bem(widgetName) {
var cx = function (element, subElement) {
var cssClass = "ais-" + widgetName;
if (element) {
cssClass += "-" + element;
}
if (subElement) {
cssClass += "--" + subElement;
}
return cssClass;
};
return cx;
}
function parseNumberInput(input) {
return typeof input === 'string' ? parseInt(input, 10) : input;
}
function noop() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
}
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}
// See https://github.com/algolia/instantsearch.js/blob/9296022fecadfbf82f15e837c215a1356eac4bc5/src/lib/utils/range.ts
function range(_a) {
var _b = _a.start, start = _b === void 0 ? 0 : _b, end = _a.end, _c = _a.step, step = _c === void 0 ? 1 : _c;
// We can't divide by 0 so we re-assign the step to 1 if it happens.
var limitStep = step === 0 ? 1 : step;
// In some cases the array to create has a decimal length.
// We therefore need to round the value.
// Example:
// { start: 1, end: 5000, step: 500 }
// => Array length = (5000 - 1) / 500 = 9.998
var arrayLength = Math.round((end - start) / limitStep);
return __spreadArray([], __read(Array(arrayLength))).map(function (_, current) { return start + current * limitStep; });
}
// See https://github.com/algolia/react-instantsearch/blob/86dfe8674d566124af55a8f044051d0062786c1a/packages/react-instantsearch-core/src/core/utils.ts#L138-L142
function getPropertyByPath(object, path) {
return path
.replace(/\[(\d+)]/g, '.$1')
.split('.')
.reduce(function (current, key) { return (current ? current[key] : undefined); }, object);
}
var TypedBaseWidget = /** @class */ (function () {
function TypedBaseWidget(widgetName) {
var _this = this;
this.updateState = function (state, isFirstRendering) {
if (isFirstRendering) {
Promise.resolve().then(function () {
_this.state = state;
});
}
else {
_this.state = state;
}
};
this.cx = bem(widgetName);
}
Object.defineProperty(TypedBaseWidget.prototype, "parent", {
get: function () {
if (this.parentIndex) {
return this.parentIndex;
}
return this.instantSearchInstance;
},
enumerable: false,
configurable: true
});
TypedBaseWidget.prototype.createWidget = function (connector, options, additionalWidgetProperties) {
if (additionalWidgetProperties === void 0) { additionalWidgetProperties = {}; }
this.widget = Object.assign(Object.assign({}, connector(this.updateState, noop)(options)), additionalWidgetProperties);
};
TypedBaseWidget.prototype.ngOnInit = function () {
this.parent.addWidgets([this.widget]);
};
TypedBaseWidget.prototype.ngOnDestroy = function () {
if (common.isPlatformBrowser(this.instantSearchInstance.platformId)) {
this.parent.removeWidgets([this.widget]);
}
};
/**
* Helper to generate class names for an item
* @param item element to generate a class name for
*/
TypedBaseWidget.prototype.getItemClass = function (item) {
var className = this.cx('item');
if (item.isRefined) {
return className + " " + this.cx('item', 'selected');
}
return className;
};
return TypedBaseWidget;
}());
TypedBaseWidget.propDecorators = {
autoHideContainer: [{ type: core.Input }]
};
var VERSION = '4.4.3';
// this is needed for different webpack/typescript configurations
var algoliasearch$1 = algoliasearchProxy__namespace.default || algoliasearchProxy__namespace;
var NgAisInstantSearch = /** @class */ (function () {
function NgAisInstantSearch(platformId) {
var _this = this;
this.platformId = platformId;
this.instanceName = 'default';
this.change = new core.EventEmitter();
this.onRender = function () {
_this.change.emit({
results: _this.instantSearchInstance.helper.lastResults,
state: _this.instantSearchInstance.helper.state,
});
};
}
NgAisInstantSearch.prototype.ngOnInit = function () {
if (core.isDevMode()) {
console.warn("We are deprecating Angular InstantSearch.\nFor more information and alternative solutions, go to https://alg.li/angular-deprecation.");
}
if (typeof this.config.searchClient.addAlgoliaAgent === 'function') {
this.config.searchClient.addAlgoliaAgent("angular (" + core.VERSION.full + ")");
this.config.searchClient.addAlgoliaAgent("angular-instantsearch (" + VERSION + ")");
}
this.instantSearchInstance = instantsearch__default['default'](this.config);
this.instantSearchInstance.on('render', this.onRender);
};
NgAisInstantSearch.prototype.ngAfterViewInit = function () {
this.instantSearchInstance.start();
};
NgAisInstantSearch.prototype.ngOnDestroy = function () {
if (this.instantSearchInstance) {
this.instantSearchInstance.removeListener('render', this.onRender);
this.instantSearchInstance.dispose();
}
};
NgAisInstantSearch.prototype.addWidgets = function (widgets) {
this.instantSearchInstance.addWidgets(widgets);
};
NgAisInstantSearch.prototype.removeWidgets = function (widgets) {
this.instantSearchInstance.removeWidgets(widgets);
};
NgAisInstantSearch.prototype.refresh = function () {
this.instantSearchInstance.refresh();
};
return NgAisInstantSearch;
}());
NgAisInstantSearch.decorators = [
{ type: core.Component, args: [{
selector: 'ais-instantsearch',
template: '<ng-content></ng-content>'
},] }
];
NgAisInstantSearch.ctorParameters = function () { return [
{ type: Object, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] }
]; };
NgAisInstantSearch.propDecorators = {
config: [{ type: core.Input }],
instanceName: [{ type: core.Input }],
change: [{ type: core.Output }]
};
var NgAisIndex = /** @class */ (function () {
function NgAisIndex(
// public API does not include SkipSelf, but the index widget should accept parents, avoiding itself.
parentIndex, instantSearchInstance) {
this.parentIndex = parentIndex;
this.instantSearchInstance = instantSearchInstance;
}
Object.defineProperty(NgAisIndex.prototype, "parent", {
get: function () {
if (this.parentIndex) {
return this.parentIndex;
}
return this.instantSearchInstance;
},
enumerable: false,
configurable: true
});
NgAisIndex.prototype.createWidget = function () {
this.widget = Object.assign(Object.assign({}, indexWidget__default['default']({
indexName: this.indexName,
indexId: this.indexId,
})), { $$widgetType: 'ais.index' });
};
NgAisIndex.prototype.addWidgets = function (widgets) {
this.widget.addWidgets(widgets);
};
NgAisIndex.prototype.removeWidgets = function (widgets) {
this.widget.removeWidgets(widgets);
};
NgAisIndex.prototype.ngOnInit = function () {
this.createWidget();
this.parent.addWidgets([this.widget]);
};
NgAisIndex.prototype.ngOnDestroy = function () {
if (common.isPlatformBrowser(this.instantSearchInstance.platformId)) {
this.parent.removeWidgets([this.widget]);
}
};
return NgAisIndex;
}());
NgAisIndex.decorators = [
{ type: core.Component, args: [{
selector: 'ais-index',
template: "<ng-content></ng-content>"
},] }
];
NgAisIndex.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.SkipSelf }, { type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisIndex.propDecorators = {
indexName: [{ type: core.Input }],
indexId: [{ type: core.Input }]
};
var NgAisBreadcrumb = /** @class */ (function (_super) {
__extends(NgAisBreadcrumb, _super);
function NgAisBreadcrumb(parentIndex, instantSearchInstance) {
var _this = _super.call(this, 'Breadcrumb') || this;
_this.parentIndex = parentIndex;
_this.instantSearchInstance = instantSearchInstance;
_this.state = {
createURL: function () { return '#'; },
items: [],
refine: noop,
canRefine: false,
};
return _this;
}
Object.defineProperty(NgAisBreadcrumb.prototype, "isHidden", {
get: function () {
return this.state.items.length === 0 && this.autoHideContainer;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgAisBreadcrumb.prototype, "items", {
get: function () {
var _this = this;
return this.state.items.map(function (item, idx) { return (Object.assign(Object.assign({}, item), { separator: idx !== 0, isLast: idx === _this.state.items.length - 1 })); });
},
enumerable: false,
configurable: true
});
NgAisBreadcrumb.prototype.ngOnInit = function () {
this.createWidget(connectors.connectBreadcrumb, {
attributes: this.attributes,
rootPath: this.rootPath,
separator: this.separator,
transformItems: this.transformItems,
}, {
$$widgetType: 'ais.breadcrumb',
});
_super.prototype.ngOnInit.call(this);
};
NgAisBreadcrumb.prototype.handleClick = function (event, item) {
event.preventDefault();
event.stopPropagation();
if (item.value) {
this.state.refine(item.value);
}
};
return NgAisBreadcrumb;
}(TypedBaseWidget));
NgAisBreadcrumb.decorators = [
{ type: core.Component, args: [{
selector: 'ais-breadcrumb',
template: "\n <div\n [class]=\"cx()\"\n *ngIf=\"!isHidden\"\n >\n <ul [class]=\"cx('list')\">\n <li\n *ngFor=\"let item of items\"\n [ngClass]=\"[cx('item'), item.isLast ? cx('item', 'selected') : '']\"\n (click)=\"handleClick($event, item)\"\n >\n <span\n *ngIf=\"item.separator\"\n [class]=\"cx('separator')\"\n aria-hidden=\"true\"\n >\n >\n </span>\n <a\n [class]=\"cx('link')\"\n href=\"{{state.createURL(item.value)}}\"\n *ngIf=\"!item.isLast\"\n (click)=\"handleClick($event, item)\"\n >\n {{item.label}}\n </a>\n\n <span *ngIf=\"item.isLast\">\n {{item.label}}\n </span>\n </li>\n </ul>\n </div>\n "
},] }
];
NgAisBreadcrumb.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisBreadcrumb.propDecorators = {
attributes: [{ type: core.Input }],
rootPath: [{ type: core.Input }],
separator: [{ type: core.Input }],
transformItems: [{ type: core.Input }]
};
var NgAisBreadcrumbModule = /** @class */ (function () {
function NgAisBreadcrumbModule() {
}
return NgAisBreadcrumbModule;
}());
NgAisBreadcrumbModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgAisBreadcrumb],
entryComponents: [NgAisBreadcrumb],
exports: [NgAisBreadcrumb],
imports: [common.CommonModule],
},] }
];
var NgAisClearRefinements = /** @class */ (function (_super) {
__extends(NgAisClearRefinements, _super);
function NgAisClearRefinements(parentIndex, instantSearchInstance) {
var _this = _super.call(this, 'ClearRefinements') || this;
_this.parentIndex = parentIndex;
_this.instantSearchInstance = instantSearchInstance;
// rendering options
_this.resetLabel = 'Clear refinements';
_this.state = {
hasRefinements: false,
canRefine: false,
refine: noop,
createURL: function () { return '#'; },
};
return _this;
}
Object.defineProperty(NgAisClearRefinements.prototype, "isHidden", {
get: function () {
return !this.state.hasRefinements && this.autoHideContainer;
},
enumerable: false,
configurable: true
});
NgAisClearRefinements.prototype.ngOnInit = function () {
this.createWidget(connectors.connectClearRefinements, {
includedAttributes: this.includedAttributes,
excludedAttributes: this.excludedAttributes,
transformItems: this.transformItems,
}, {
$$widgetType: 'ais.clearRefinements',
});
_super.prototype.ngOnInit.call(this);
};
NgAisClearRefinements.prototype.handleClick = function (event) {
event.preventDefault();
if (this.state.hasRefinements) {
this.state.refine();
}
};
return NgAisClearRefinements;
}(TypedBaseWidget));
NgAisClearRefinements.decorators = [
{ type: core.Component, args: [{
selector: 'ais-clear-refinements',
template: "\n <div\n [class]=\"cx()\"\n *ngIf=\"!isHidden\"\n >\n <button\n [class]=\"cx('button') + (!state.hasRefinements ? (' ' + cx('button', 'disabled')) : '')\"\n (click)=\"handleClick($event)\"\n [disabled]=\"!state.hasRefinements\"\n >\n {{resetLabel}}\n </button>\n </div>\n "
},] }
];
NgAisClearRefinements.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisClearRefinements.propDecorators = {
resetLabel: [{ type: core.Input }],
includedAttributes: [{ type: core.Input }],
excludedAttributes: [{ type: core.Input }],
transformItems: [{ type: core.Input }]
};
var NgAisClearRefinementsModule = /** @class */ (function () {
function NgAisClearRefinementsModule() {
}
return NgAisClearRefinementsModule;
}());
NgAisClearRefinementsModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgAisClearRefinements],
entryComponents: [NgAisClearRefinements],
exports: [NgAisClearRefinements],
imports: [common.CommonModule],
},] }
];
var NgAisCurrentRefinements = /** @class */ (function (_super) {
__extends(NgAisCurrentRefinements, _super);
function NgAisCurrentRefinements(parentIndex, instantSearchInstance) {
var _this = _super.call(this, 'CurrentRefinements') || this;
_this.parentIndex = parentIndex;
_this.instantSearchInstance = instantSearchInstance;
_this.state = {
createURL: function () { return '#'; },
refine: noop,
items: [],
canRefine: false,
};
return _this;
}
Object.defineProperty(NgAisCurrentRefinements.prototype, "isHidden", {
get: function () {
return this.state.items.length === 0 && this.autoHideContainer;
},
enumerable: false,
configurable: true
});
NgAisCurrentRefinements.prototype.ngOnInit = function () {
this.createWidget(connectors.connectCurrentRefinements, {
includedAttributes: this.includedAttributes,
excludedAttributes: this.excludedAttributes,
transformItems: this.transformItems,
}, {
$$widgetType: 'ais.currentRefinements',
});
_super.prototype.ngOnInit.call(this);
};
NgAisCurrentRefinements.prototype.handleClick = function (event, refinement) {
event.preventDefault();
this.state.refine(refinement);
};
return NgAisCurrentRefinements;
}(TypedBaseWidget));
NgAisCurrentRefinements.decorators = [
{ type: core.Component, args: [{
selector: 'ais-current-refinements',
template: "\n <div\n [class]=\"cx()\"\n *ngIf=\"!isHidden\"\n >\n <ul\n [class]=\"cx('list')\"\n *ngFor=\"let item of state.items\"\n >\n <li [class]=\"cx('item')\">\n <span [class]=\"cx('label')\">{{item.label | titlecase}}:</span>\n\n <span\n [class]=\"cx('category')\"\n *ngFor=\"let refinement of item.refinements\"\n >\n <span [class]=\"cx('categoryLabel')\">{{refinement.label}}</span>\n <button [class]=\"cx('delete')\" (click)=\"handleClick($event, refinement)\">\u2715</button>\n </span>\n </li>\n </ul>\n </div>\n "
},] }
];
NgAisCurrentRefinements.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisCurrentRefinements.propDecorators = {
includedAttributes: [{ type: core.Input }],
excludedAttributes: [{ type: core.Input }],
transformItems: [{ type: core.Input }]
};
var NgAisCurrentRefinementsModule = /** @class */ (function () {
function NgAisCurrentRefinementsModule() {
}
return NgAisCurrentRefinementsModule;
}());
NgAisCurrentRefinementsModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgAisCurrentRefinements],
entryComponents: [NgAisCurrentRefinements],
exports: [NgAisCurrentRefinements],
imports: [common.CommonModule],
},] }
];
var NgAisHierarchicalMenu = /** @class */ (function (_super) {
__extends(NgAisHierarchicalMenu, _super);
function NgAisHierarchicalMenu(parentIndex, instantSearchInstance) {
var _this = _super.call(this, 'HierarchicalMenu') || this;
_this.parentIndex = parentIndex;
_this.instantSearchInstance = instantSearchInstance;
_this.state = {
createURL: function () { return '#'; },
items: [],
refine: noop,
canRefine: false,
isShowingMore: false,
toggleShowMore: noop,
canToggleShowMore: false,
sendEvent: noop,
};
return _this;
}
Object.defineProperty(NgAisHierarchicalMenu.prototype, "isHidden", {
get: function () {
return this.state.items.length === 0 && this.autoHideContainer;
},
enumerable: false,
configurable: true
});
NgAisHierarchicalMenu.prototype.ngOnInit = function () {
this.createWidget(connectors.connectHierarchicalMenu, {
limit: parseNumberInput(this.limit),
attributes: this.attributes,
rootPath: this.rootPath,
separator: this.separator,
showParentLevel: this.showParentLevel,
sortBy: this.sortBy,
transformItems: this.transformItems,
}, {
$$widgetType: 'ais.hierarchicalMenu',
});
_super.prototype.ngOnInit.call(this);
};
return NgAisHierarchicalMenu;
}(TypedBaseWidget));
NgAisHierarchicalMenu.decorators = [
{ type: core.Component, args: [{
selector: 'ais-hierarchical-menu',
template: "\n <div\n [class]=\"cx()\"\n *ngIf=\"!isHidden\"\n >\n <ul [class]=\"cx('list') + ' ' + cx('list', 'lvl0')\">\n <ais-hierarchical-menu-item\n *ngFor=\"let item of state.items\"\n [item]=\"item\"\n [createURL]=\"state.createURL\"\n [refine]=\"state.refine\"\n >\n </ais-hierarchical-menu-item>\n </ul>\n </div>\n "
},] }
];
NgAisHierarchicalMenu.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisHierarchicalMenu.propDecorators = {
attributes: [{ type: core.Input }],
separator: [{ type: core.Input }],
rootPath: [{ type: core.Input }],
showParentLevel: [{ type: core.Input }],
limit: [{ type: core.Input }],
sortBy: [{ type: core.Input }],
transformItems: [{ type: core.Input }]
};
var NgAisHierarchicalMenuItem = /** @class */ (function () {
function NgAisHierarchicalMenuItem() {
this.lvl = 1;
this.cx = bem('HierarchicalMenu');
}
NgAisHierarchicalMenuItem.prototype.getItemClass = function (item) {
var className = this.cx('item');
if (item.isRefined) {
className = className + " " + this.cx('item', 'selected');
}
if (this.isArray(item.data) && item.data.length > 0) {
className = className + " " + this.cx('item', 'parent');
}
return className;
};
NgAisHierarchicalMenuItem.prototype.getListClass = function () {
return this.cx('list') + " " + this.cx('list', 'child') + " " + this.cx('list', "lvl" + this.lvl);
};
NgAisHierarchicalMenuItem.prototype.isArray = function (potentialArray) {
return Array.isArray(potentialArray);
};
NgAisHierarchicalMenuItem.prototype.handleClick = function (event, item) {
event.preventDefault();
event.stopPropagation();
this.refine(item.value);
};
return NgAisHierarchicalMenuItem;
}());
NgAisHierarchicalMenuItem.decorators = [
{ type: core.Component, args: [{
selector: 'ais-hierarchical-menu-item',
template: "\n <li\n [class]=\"getItemClass(item)\"\n (click)=\"handleClick($event, item)\"\n >\n <a\n [class]=\"cx('link')\"\n href=\"{{createURL(item.value)}}\"\n (click)=\"handleClick($event, item)\"\n >\n <span [class]=\"cx('label')\">{{item.label}}</span>\n <span [class]=\"cx('count')\">{{item.count}}</span>\n </a>\n\n <ul\n [class]=\"getListClass()\"\n *ngIf=\"item.isRefined && isArray(item.data) && item.data.length > 0\"\n >\n <ais-hierarchical-menu-item\n *ngFor=\"let child of item.data\"\n [item]=\"child\"\n [createURL]=\"createURL\"\n [refine]=\"refine\"\n [lvl]=\"lvl + 1\"\n >\n </ais-hierarchical-menu-item>\n </ul>\n </li>\n "
},] }
];
NgAisHierarchicalMenuItem.propDecorators = {
lvl: [{ type: core.Input }],
refine: [{ type: core.Input }],
createURL: [{ type: core.Input }],
item: [{ type: core.Input }]
};
var NgAisHierarchicalMenuModule = /** @class */ (function () {
function NgAisHierarchicalMenuModule() {
}
return NgAisHierarchicalMenuModule;
}());
NgAisHierarchicalMenuModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgAisHierarchicalMenu, NgAisHierarchicalMenuItem],
entryComponents: [NgAisHierarchicalMenu],
exports: [NgAisHierarchicalMenu],
imports: [common.CommonModule],
},] }
];
var NgAisHitsPerPage = /** @class */ (function (_super) {
__extends(NgAisHitsPerPage, _super);
function NgAisHitsPerPage(parentIndex, instantSearchInstance) {
var _this = _super.call(this, 'HitsPerPage') || this;
_this.parentIndex = parentIndex;
_this.instantSearchInstance = instantSearchInstance;
_this.state = {
items: [],
refine: noop,
hasNoResults: true,
canRefine: false,
};
return _this;
}
Object.defineProperty(NgAisHitsPerPage.prototype, "isHidden", {
get: function () {
return this.state.items.length === 0 && this.autoHideContainer;
},
enumerable: false,
configurable: true
});
NgAisHitsPerPage.prototype.ngOnInit = function () {
this.createWidget(connectors.connectHitsPerPage, {
items: this.items,
transformItems: this.transformItems,
}, {
$$widgetType: 'ais.hitsPerPage',
});
_super.prototype.ngOnInit.call(this);
};
return NgAisHitsPerPage;
}(TypedBaseWidget));
NgAisHitsPerPage.decorators = [
{ type: core.Component, args: [{
selector: 'ais-hits-per-page',
template: "\n <div\n [class]=\"cx()\"\n *ngIf=\"!isHidden\"\n >\n <select\n [class]=\"cx('select')\"\n (change)=\"state.refine($event.target.value)\"\n >\n <option\n [class]=\"cx('option')\"\n *ngFor=\"let item of state.items\"\n [value]=\"item.value\"\n [selected]=\"item.isRefined\"\n >\n {{item.label}}\n </option>\n </select>\n </div>\n "
},] }
];
NgAisHitsPerPage.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisHitsPerPage.propDecorators = {
items: [{ type: core.Input }],
transformItems: [{ type: core.Input }]
};
var NgAisHitsPerPageModule = /** @class */ (function () {
function NgAisHitsPerPageModule() {
}
return NgAisHitsPerPageModule;
}());
NgAisHitsPerPageModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgAisHitsPerPage],
entryComponents: [NgAisHitsPerPage],
exports: [NgAisHitsPerPage],
imports: [common.CommonModule],
},] }
];
var NgAisHighlight = /** @class */ (function () {
function NgAisHighlight() {
this.tagName = 'mark';
}
Object.defineProperty(NgAisHighlight.prototype, "content", {
get: function () {
var highlightAttributeResult = utils.getPropertyByPath(this.hit._highlightResult, this.attribute);
var fallback = utils.getPropertyByPath(this.hit, this.attribute);
// @MAJOR drop this custom fallback once it is implemented directly in instantsearch.js v5
if (!highlightAttributeResult && fallback) {
return fallback;
}
return helpers.highlight({
attribute: this.attribute,
highlightedTagName: this.tagName,
hit: this.hit,
});
},
enumerable: false,
configurable: true
});
return NgAisHighlight;
}());
NgAisHighlight.decorators = [
{ type: core.Component, args: [{
selector: 'ais-highlight',
changeDetection: core.ChangeDetectionStrategy.OnPush,
template: "<span class=\"ais-Highlight\" [innerHtml]=\"content\"></span>"
},] }
];
NgAisHighlight.propDecorators = {
attribute: [{ type: core.Input }],
hit: [{ type: core.Input }],
tagName: [{ type: core.Input }]
};
var NgAisHighlightModule = /** @class */ (function () {
function NgAisHighlightModule() {
}
return NgAisHighlightModule;
}());
NgAisHighlightModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [NgAisHighlight],
entryComponents: [NgAisHighlight],
exports: [NgAisHighlight],
imports: [common.CommonModule],
},] }
];
var NgAisHits = /** @class */ (function (_super) {
__extends(NgAisHits, _super);
function NgAisHits(parentIndex, instantSearchInstance) {
var _this = _super.call(this, 'Hits') || this;
_this.parentIndex = parentIndex;
_this.instantSearchInstance = instantSearchInstance;
_this.state = {
hits: [],
results: undefined,
bindEvent: undefined,
sendEvent: undefined,
};
_this.updateState = function (state, isFirstRendering) {
if (isFirstRendering)
return;
_this.state = state;
};
return _this;
}
NgAisHits.prototype.ngOnInit = function () {
this.createWidget(connectors.connectHitsWithInsights, {
escapeHTML: this.escapeHTML,
transformItems: this.transformItems,
}, {
$$widgetType: 'ais.hits',
});
_super.prototype.ngOnInit.call(this);
};
return NgAisHits;
}(TypedBaseWidget));
NgAisHits.decorators = [
{ type: core.Component, args: [{
selector: 'ais-hits',
template: "\n <div [class]=\"cx()\">\n <ng-container *ngTemplateOutlet=\"template; context: state\"></ng-container>\n\n <!-- default rendering if no template specified -->\n <div *ngIf=\"!template\">\n <ul [class]=\"cx('list')\">\n <li\n [class]=\"cx('item')\"\n *ngFor=\"let hit of state.hits\"\n >\n <ais-highlight attribute=\"name\" [hit]=\"hit\">\n </ais-highlight>\n </li>\n </ul>\n </div>\n </div>\n "
},] }
];
NgAisHits.ctorParameters = function () { return [
{ type: NgAisIndex, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisIndex; }),] }, { type: core.Optional }] },
{ type: NgAisInstantSearch, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return NgAisInstantSearch; }),] }] }
]; };
NgAisHits.propDecorators = {
template: