coveo-search-ui
Version:
Coveo JavaScript Search Framework
1,075 lines (1,057 loc) • 274 kB
JavaScript
webpackJsonpCoveo__temporary([2,3,19],{
/***/ 118:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Component_1 = __webpack_require__(7);
var ResultList_1 = __webpack_require__(93);
var Dom_1 = __webpack_require__(1);
var underscore_1 = __webpack_require__(0);
var Logger_1 = __webpack_require__(9);
var ResultListUtils = /** @class */ (function () {
function ResultListUtils() {
}
ResultListUtils.hideIfInfiniteScrollEnabled = function (cmp) {
var infiniteScrollEnabled = ResultListUtils.isInfiniteScrollEnabled(cmp.searchInterface.element);
if (infiniteScrollEnabled) {
cmp.disable();
Dom_1.$$(cmp.element).hide();
ResultListUtils.warnIfComponentNotNeeded(cmp);
}
else {
cmp.enable();
Dom_1.$$(cmp.element).unhide();
}
};
ResultListUtils.isInfiniteScrollEnabled = function (root) {
var resultList = ResultListUtils.getMainResultList(root);
return resultList ? !!resultList.options.enableInfiniteScroll : false;
};
ResultListUtils.scrollToTop = function (root) {
var resultList = ResultListUtils.getMainResultList(root);
if (!resultList) {
new Logger_1.Logger(this).warn('No active ResultList, scrolling to the top of the Window');
return window.scrollTo(0, 0);
}
var searchInterfacePosition = resultList.searchInterface.element.getBoundingClientRect().top;
if (searchInterfacePosition > 0) {
return;
}
window.scrollTo(0, window.pageYOffset + searchInterfacePosition);
};
ResultListUtils.getMainResultList = function (root) {
var resultLists = ResultListUtils.getResultLists(root);
return underscore_1.find(resultLists, function (resultList) {
var isRecInterface = resultList.searchInterface.element.classList.contains('CoveoRecommendation');
return !resultList.disabled && !isRecInterface;
});
};
ResultListUtils.getResultLists = function (root) {
return Dom_1.$$(root)
.findAll("." + ResultListUtils.cssClass())
.map(function (el) { return Component_1.Component.get(el, ResultList_1.ResultList); });
};
ResultListUtils.cssClass = function () {
return Component_1.Component.computeCssClassName(ResultList_1.ResultList);
};
ResultListUtils.warnIfComponentNotNeeded = function (cmp) {
var root = cmp.searchInterface.root;
var allListsUseInfiniteScroll = ResultListUtils.allResultListsUseInfiniteScroll(root);
allListsUseInfiniteScroll && ResultListUtils.notNeededComponentWarning(cmp);
};
ResultListUtils.allResultListsUseInfiniteScroll = function (root) {
var listsWithInfiniteScrollDisabled = ResultListUtils.getResultLists(root).filter(function (resultList) { return !resultList.options.enableInfiniteScroll; });
return listsWithInfiniteScrollDisabled.length === 0;
};
ResultListUtils.notNeededComponentWarning = function (cmp) {
var cmpCssClass = Component_1.Component.computeCssClassNameForType(cmp.type);
var message = "The " + cmpCssClass + " component is not needed because all " + ResultListUtils.cssClass() + " components have enableInfiniteScroll set to 'true'.\n For the best performance, remove the " + cmpCssClass + " component from your search page.";
new Logger_1.Logger(cmp).warn(message);
};
return ResultListUtils;
}());
exports.ResultListUtils = ResultListUtils;
/***/ }),
/***/ 131:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ResponsiveDropdownContent_1 = __webpack_require__(94);
var ResponsiveComponentsUtils = /** @class */ (function () {
function ResponsiveComponentsUtils() {
}
ResponsiveComponentsUtils.shouldDrawFacetSlider = function (root, facetSliderElement) {
return ResponsiveDropdownContent_1.ResponsiveDropdownContent.isTargetInsideOpenedDropdown(facetSliderElement) || !this.isSmallFacetActivated(root);
};
ResponsiveComponentsUtils.isSmallTabsActivated = function (root) {
return root.hasClass(this.smallTabsClassName);
};
ResponsiveComponentsUtils.isSmallFacetActivated = function (root) {
return root.hasClass(this.smallFacetClassName);
};
ResponsiveComponentsUtils.isSmallRecommendationActivated = function (root) {
return root.hasClass(this.smallRecommendationClassName);
};
ResponsiveComponentsUtils.activateSmallTabs = function (root) {
root.addClass(this.smallTabsClassName);
};
ResponsiveComponentsUtils.deactivateSmallTabs = function (root) {
root.removeClass(this.smallTabsClassName);
};
ResponsiveComponentsUtils.activateSmallFacet = function (root) {
root.addClass(this.smallFacetClassName);
};
ResponsiveComponentsUtils.deactivateSmallFacet = function (root) {
root.removeClass(this.smallFacetClassName);
};
ResponsiveComponentsUtils.activateSmallRecommendation = function (root) {
root.addClass(this.smallRecommendationClassName);
};
ResponsiveComponentsUtils.deactivateSmallRecommendation = function (root) {
root.removeClass(this.smallRecommendationClassName);
};
ResponsiveComponentsUtils.smallTabsClassName = 'coveo-small-tabs';
ResponsiveComponentsUtils.smallFacetClassName = 'coveo-small-facets';
ResponsiveComponentsUtils.smallRecommendationClassName = 'coveo-small-recommendation';
return ResponsiveComponentsUtils;
}());
exports.ResponsiveComponentsUtils = ResponsiveComponentsUtils;
/***/ }),
/***/ 142:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || Object.assign || function(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;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (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 = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, 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 };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
__webpack_require__(224);
var underscore_1 = __webpack_require__(0);
var Dom_1 = __webpack_require__(1);
var GlobalExports_1 = __webpack_require__(3);
var Component_1 = __webpack_require__(7);
var ComponentOptions_1 = __webpack_require__(8);
var Initialization_1 = __webpack_require__(2);
var ResponsiveFacetOptions_1 = __webpack_require__(85);
var ResponsiveDynamicFacets_1 = __webpack_require__(581);
var DynamicFacetBreadcrumbs_1 = __webpack_require__(582);
var DynamicFacetHeader_1 = __webpack_require__(183);
var DynamicFacetValues_1 = __webpack_require__(517);
var QueryEvents_1 = __webpack_require__(11);
var QueryStateModel_1 = __webpack_require__(13);
var DynamicFacetQueryController_1 = __webpack_require__(518);
var Utils_1 = __webpack_require__(4);
var Model_1 = __webpack_require__(18);
var Assert_1 = __webpack_require__(5);
var FacetSortCriteria_1 = __webpack_require__(513);
var Strings_1 = __webpack_require__(6);
var DeviceUtils_1 = __webpack_require__(24);
var BreadcrumbEvents_1 = __webpack_require__(35);
var AnalyticsActionListMeta_1 = __webpack_require__(10);
var DynamicFacetSearch_1 = __webpack_require__(584);
var ResultListUtils_1 = __webpack_require__(118);
var FacetRequest_1 = __webpack_require__(184);
var DependsOnManager_1 = __webpack_require__(174);
var DynamicFacetValueCreator_1 = __webpack_require__(587);
var Logger_1 = __webpack_require__(9);
var FacetUtils_1 = __webpack_require__(40);
/**
* The `DynamicFacet` component displays a *facet* of the results for the current query. A facet is a list of values for a
* certain field occurring in the results, ordered using a configurable criteria (e.g., number of occurrences).
*
* The list of values is obtained using an array of [`FacetRequest`]{@link IFacetRequest} operations performed at the same time
* as the main query.
*
* The `DynamicFacet` component allows the end-user to drill down inside a result set by restricting the result to certain
* field values.
*
* This facet is more easy to use than the original [`Facet`]{@link Facet} component. It implements additional Coveo Machine Learning (Coveo ML) features
* such as dynamic navigation experience (DNE).
*
* @notSupportedIn salesforcefree
* @availablesince [May 2019 Release (v2.6063)](https://docs.coveo.com/en/2909/)
*/
var DynamicFacet = /** @class */ (function (_super) {
__extends(DynamicFacet, _super);
/**
* Creates a new `DynamicFacet` instance.
*
* @param element The element from which to instantiate the component.
* @param options The component options.
* @param bindings The component bindings. Automatically resolved by default.
*/
function DynamicFacet(element, options, bindings, classId) {
if (classId === void 0) { classId = DynamicFacet.ID; }
var _this = _super.call(this, element, classId, bindings) || this;
_this.element = element;
_this.listenToQueryStateChange = true;
_this.moreValuesAvailable = false;
_this.isDynamicFacet = true;
_this.isFieldValueCompatible = true;
_this.isFieldValueHierarchical = false;
_this.handleQueryStateChangedIncluded = function (querySelectedValues) {
var currentSelectedValues = _this.values.selectedValues;
var validQuerySelectedValues = querySelectedValues.filter(function (value) { return _this.values.get(value); });
var valuesToSelect = underscore_1.difference(validQuerySelectedValues, currentSelectedValues);
var valuesToDeselect = underscore_1.difference(currentSelectedValues, validQuerySelectedValues);
if (Utils_1.Utils.isNonEmptyArray(valuesToSelect)) {
_this.selectMultipleValues(valuesToSelect);
}
if (Utils_1.Utils.isNonEmptyArray(valuesToDeselect)) {
_this.deselectMultipleValues(valuesToDeselect);
}
};
_this.options = ComponentOptions_1.ComponentOptions.initComponentOptions(element, DynamicFacet, options);
_this.initDynamicFacetQueryController();
_this.initDependsOnManager();
_this.initQueryEvents();
_this.initQueryStateEvents();
_this.initBreadCrumbEvents();
_this.initComponentStateEvents();
_this.initValues();
_this.verifyCollapsingConfiguration();
_this.isCollapsed = _this.options.enableCollapse && _this.options.collapsedByDefault;
ResponsiveDynamicFacets_1.ResponsiveDynamicFacets.init(_this.root, _this, _this.options);
return _this;
}
Object.defineProperty(DynamicFacet.prototype, "fieldName", {
get: function () {
return this.options.field.slice(1);
},
enumerable: true,
configurable: true
});
Object.defineProperty(DynamicFacet.prototype, "facetType", {
get: function () {
return FacetRequest_1.FacetType.specific;
},
enumerable: true,
configurable: true
});
/**
* Selects a single value in this facet.
*
* Does **not** trigger a query automatically.
* Does **not** update the visual of the facet until a query is performed.
*
* @param value The name of the facet value to select.
*/
DynamicFacet.prototype.selectValue = function (value) {
Assert_1.Assert.exists(value);
this.selectMultipleValues([value]);
};
/**
* Selects multiple values in this facet.
*
* Does **not** trigger a query automatically.
* Does **not** update the visual of the facet until a query is performed.
*
* @param values The names of the facet values to select.
*/
DynamicFacet.prototype.selectMultipleValues = function (values) {
var _this = this;
Assert_1.Assert.exists(values);
this.ensureDom();
this.logger.info('Selecting facet value(s)', values);
values.forEach(function (value) {
_this.values.get(value).select();
});
this.updateQueryStateModel();
};
/**
* Deselects a single value in this facet.
*
* Does **not** trigger a query automatically.
* Does **not** update the visual of the facet until a query is performed.
*
* @param values The name of the facet value to deselect.
*/
DynamicFacet.prototype.deselectValue = function (value) {
Assert_1.Assert.exists(value);
this.deselectMultipleValues([value]);
};
/**
* Determines whether the specified value is selected in the facet.
* @param value The name of the facet value to verify.
*/
DynamicFacet.prototype.hasSelectedValue = function (value) {
return this.values.hasSelectedValue(value);
};
/**
* Deselects multiple values in this facet.
*
* Does **not** trigger a query automatically.
* Does **not** update the visual of the facet until a query is performed.
*
* @param values The names of the facet values to deselect.
*/
DynamicFacet.prototype.deselectMultipleValues = function (values) {
var _this = this;
Assert_1.Assert.exists(values);
this.ensureDom();
this.logger.info('Deselecting facet value(s)', values);
values.forEach(function (value) {
_this.values.get(value).deselect();
});
this.updateQueryStateModel();
};
/**
* Toggles the selection state of a single value in this facet.
*
* Does **not** trigger a query automatically.
*
* @param values The name of the facet value to toggle.
*/
DynamicFacet.prototype.toggleSelectValue = function (value) {
Assert_1.Assert.exists(value);
this.ensureDom();
var facetValue = this.values.get(value);
facetValue.toggleSelect();
this.logger.info('Toggle select facet value', facetValue);
this.updateQueryStateModel();
};
/**
* Keyboard focuses a value once it has been re-rendered.
*
* @param value The name of the facet value to focus
*/
DynamicFacet.prototype.focusValueAfterRerender = function (value) {
Assert_1.Assert.exists(value);
this.valueToFocusOnRender = value;
};
/**
* Returns the configured caption for a desired facet value.
*
* @param value The string facet value whose caption the method should return.
*/
DynamicFacet.prototype.getCaptionForStringValue = function (value) {
return FacetUtils_1.FacetUtils.getDisplayValueFromValueCaption(value, this.options.field, this.options.valueCaption);
};
/**
* Requests additional values.
*
* Automatically triggers an isolated query.
* @param additionalNumberOfValues The number of additional values to request. Minimum value is 1. Defaults to the [numberOfValues]{@link DynamicFacet.options.numberOfValues} option value.
*/
DynamicFacet.prototype.showMoreValues = function (additionalNumberOfValues) {
var _this = this;
if (additionalNumberOfValues === void 0) { additionalNumberOfValues = this.options.numberOfValues; }
this.ensureDom();
this.logger.info('Show more values');
this.dynamicFacetQueryController.increaseNumberOfValuesToRequest(additionalNumberOfValues);
this.triggerNewIsolatedQuery(function () { return _this.logAnalyticsFacetShowMoreLess(AnalyticsActionListMeta_1.analyticsActionCauseList.dynamicFacetShowMore); });
};
/**
* Reduces the number of displayed facet values down to [numberOfValues]{@link DynamicFacet.options.numberOfValues}.
*
* Automatically triggers an isolated query.
*/
DynamicFacet.prototype.showLessValues = function () {
var _this = this;
this.ensureDom();
this.logger.info('Show less values');
this.dynamicFacetQueryController.resetNumberOfValuesToRequest();
this.triggerNewIsolatedQuery(function () { return _this.logAnalyticsFacetShowMoreLess(AnalyticsActionListMeta_1.analyticsActionCauseList.dynamicFacetShowLess); });
};
/**
* Deselects all values in this facet.
*
* Does **not** trigger a query automatically.
* Updates the visual of the facet.
*
*/
DynamicFacet.prototype.reset = function () {
this.ensureDom();
if (!this.values.hasActiveValues) {
return;
}
this.logger.info('Deselect all values');
this.values.clearAll();
this.values.render();
this.enablePreventAutoSelectionFlag();
this.updateAppearance();
this.updateQueryStateModel();
};
/**
* Collapses or expands the facet depending on it's current state.
*/
DynamicFacet.prototype.toggleCollapse = function () {
this.isCollapsed ? this.expand() : this.collapse();
};
/**
* Expands the facet, displaying all of its currently fetched values.
*/
DynamicFacet.prototype.expand = function () {
if (!this.options.enableCollapse) {
return this.logger.warn("Calling expand() won't do anything on a facet that has the option \"enableCollapse\" set to \"false\"");
}
if (!this.isCollapsed) {
return;
}
this.ensureDom();
this.logger.info('Expand facet values');
this.isCollapsed = false;
this.updateAppearance();
};
/**
* Collapses the facet, displaying only its currently selected values.
*/
DynamicFacet.prototype.collapse = function () {
if (!this.options.enableCollapse) {
return this.logger.warn("Calling collapse() won't do anything on a facet that has the option \"enableCollapse\" set to \"false\"");
}
if (this.isCollapsed) {
return;
}
this.ensureDom();
this.logger.info('Collapse facet values');
this.isCollapsed = true;
this.updateAppearance();
};
/**
* Sets a flag indicating whether the facet values should be returned in their current order.
*
* Setting the flag to `true` helps ensuring that the values do not move around while the end-user is interacting with them.
*
* The flag is automatically set back to `false` after a query is built.
*/
DynamicFacet.prototype.enableFreezeCurrentValuesFlag = function () {
this.dynamicFacetQueryController.enableFreezeCurrentValuesFlag();
};
/**
* For this method to work, the component has to be the child of a [DynamicFacetManager]{@link DynamicFacetManager} component.
*
* Sets a flag indicating whether the facets should be returned in their current order.
*
* Setting the flag to `true` helps ensuring that the facets do not move around while the end-user is interacting with them.
*
* The flag is automatically set back to `false` after a query is built.
*/
DynamicFacet.prototype.enableFreezeFacetOrderFlag = function () {
this.dynamicFacetQueryController.enableFreezeFacetOrderFlag();
};
DynamicFacet.prototype.enablePreventAutoSelectionFlag = function () {
this.dynamicFacetQueryController.enablePreventAutoSelectionFlag();
};
DynamicFacet.prototype.scrollToTop = function () {
if (this.options.enableScrollToTop) {
ResultListUtils_1.ResultListUtils.scrollToTop(this.root);
}
};
Object.defineProperty(DynamicFacet.prototype, "analyticsFacetState", {
get: function () {
return this.values.activeValues.map(function (facetValue) { return facetValue.analyticsFacetState; });
},
enumerable: true,
configurable: true
});
Object.defineProperty(DynamicFacet.prototype, "basicAnalyticsFacetState", {
get: function () {
return {
field: this.options.field.toString(),
id: this.options.id,
title: this.options.title,
facetType: this.facetType,
facetPosition: this.position
};
},
enumerable: true,
configurable: true
});
Object.defineProperty(DynamicFacet.prototype, "basicAnalyticsFacetMeta", {
get: function () {
return {
facetField: this.options.field.toString(),
facetId: this.options.id,
facetTitle: this.options.title
};
},
enumerable: true,
configurable: true
});
DynamicFacet.prototype.logAnalyticsEvent = function (actionCause, facetMeta) {
this.usageAnalytics.logSearchEvent(actionCause, facetMeta);
};
DynamicFacet.prototype.putStateIntoQueryBuilder = function (queryBuilder) {
Assert_1.Assert.exists(queryBuilder);
this.dynamicFacetQueryController.putFacetIntoQueryBuilder(queryBuilder);
};
DynamicFacet.prototype.putStateIntoAnalytics = function () {
var pendingEvent = this.usageAnalytics.getPendingSearchEvent();
pendingEvent && pendingEvent.addFacetState(this.analyticsFacetState);
};
DynamicFacet.prototype.isCurrentlyDisplayed = function () {
return Dom_1.$$(this.element).isVisible();
};
Object.defineProperty(DynamicFacet.prototype, "hasActiveValues", {
get: function () {
return this.values.hasActiveValues;
},
enumerable: true,
configurable: true
});
DynamicFacet.prototype.initQueryEvents = function () {
var _this = this;
this.bind.onRootElement(QueryEvents_1.QueryEvents.duringQuery, function () { return _this.ensureDom(); });
this.bind.onRootElement(QueryEvents_1.QueryEvents.doneBuildingQuery, function (data) { return _this.handleDoneBuildingQuery(data); });
this.bind.onRootElement(QueryEvents_1.QueryEvents.deferredQuerySuccess, function (data) { return _this.handleQuerySuccess(data.results); });
this.bind.onRootElement(QueryEvents_1.QueryEvents.queryError, function () { return _this.onNoValues(); });
};
DynamicFacet.prototype.initQueryStateEvents = function () {
this.includedAttributeId = QueryStateModel_1.QueryStateModel.getFacetId(this.options.id);
this.queryStateModel.registerNewAttribute(this.includedAttributeId, []);
this.bind.onQueryState(Model_1.MODEL_EVENTS.CHANGE, undefined, this.handleQueryStateChanged);
};
DynamicFacet.prototype.initBreadCrumbEvents = function () {
var _this = this;
if (this.options.includeInBreadcrumb) {
this.bind.onRootElement(BreadcrumbEvents_1.BreadcrumbEvents.populateBreadcrumb, function (args) {
return _this.handlePopulateBreadcrumb(args);
});
this.bind.onRootElement(BreadcrumbEvents_1.BreadcrumbEvents.clearBreadcrumb, function () { return _this.reset(); });
}
};
DynamicFacet.prototype.initValues = function () {
this.values = new DynamicFacetValues_1.DynamicFacetValues(this, DynamicFacetValueCreator_1.DynamicFacetValueCreator);
};
DynamicFacet.prototype.initComponentStateEvents = function () {
var componentStateId = QueryStateModel_1.QueryStateModel.getFacetId(this.options.id);
this.componentStateModel.registerComponent(componentStateId, this);
};
DynamicFacet.prototype.initDynamicFacetQueryController = function () {
this.dynamicFacetQueryController = new DynamicFacetQueryController_1.DynamicFacetQueryController(this);
};
DynamicFacet.prototype.handleDoneBuildingQuery = function (data) {
// If there is a DynamicFacetManager, it will take care of adding the facet's state
if (this.dynamicFacetManager) {
return;
}
Assert_1.Assert.exists(data);
Assert_1.Assert.exists(data.queryBuilder);
this.putStateIntoQueryBuilder(data.queryBuilder);
this.putStateIntoAnalytics();
};
DynamicFacet.prototype.handleQuerySuccess = function (results) {
// If there is a DynamicFacetManager, it will take care of handling the results
if (this.dynamicFacetManager) {
return;
}
if (Utils_1.Utils.isNullOrUndefined(results.facets)) {
return this.notImplementedError();
}
this.handleQueryResults(results);
};
DynamicFacet.prototype.handleQueryResults = function (results) {
var _this = this;
var index = underscore_1.findIndex(results.facets, { facetId: this.options.id });
var facetResponse = index !== -1 ? results.facets[index] : null;
this.position = facetResponse ? index + 1 : undefined;
facetResponse ? this.onNewValues(facetResponse) : this.onNoValues();
this.header.hideLoading();
this.updateQueryStateModel();
this.values.render();
this.updateAppearance();
if (this.valueToFocusOnRender) {
var value_1 = this.valueToFocusOnRender;
this.valueToFocusOnRender = null;
underscore_1.defer(function () { return _this.values.focus(value_1); });
}
};
DynamicFacet.prototype.onNewValues = function (facetResponse) {
this.moreValuesAvailable = facetResponse.moreValuesAvailable;
this.values.createFromResponse(facetResponse);
if (this.options.customSort) {
this.values.reorderValues(this.options.customSort);
}
};
DynamicFacet.prototype.onNoValues = function () {
this.moreValuesAvailable = false;
this.values.resetValues();
};
DynamicFacet.prototype.handleQueryStateChanged = function (data) {
if (!this.listenToQueryStateChange) {
return;
}
var querySelectedValues = data.attributes[this.includedAttributeId];
if (!querySelectedValues) {
return;
}
this.handleQueryStateChangedIncluded(querySelectedValues);
};
DynamicFacet.prototype.handlePopulateBreadcrumb = function (args) {
Assert_1.Assert.exists(args);
if (!this.values.hasActiveValues) {
return;
}
var breadcrumbs = new DynamicFacetBreadcrumbs_1.DynamicFacetBreadcrumbs(this, { headingLevel: args.headingLevel });
args.breadcrumbs.push({ element: breadcrumbs.element });
};
DynamicFacet.prototype.initDependsOnManager = function () {
var _this = this;
var facetInfo = {
reset: function () { return _this.reset(); },
ref: this
};
this.dependsOnManager = new DependsOnManager_1.DependsOnManager(facetInfo);
};
DynamicFacet.prototype.createDom = function () {
this.createAndAppendContent();
this.updateAppearance();
};
DynamicFacet.prototype.createAndAppendContent = function () {
this.createAndAppendHeader();
this.createAndAppendSearch();
this.createAndAppendValues();
};
DynamicFacet.prototype.createAndAppendHeader = function () {
var _this = this;
this.header = new DynamicFacetHeader_1.DynamicFacetHeader({
id: this.options.id,
title: this.options.title,
enableCollapse: this.options.enableCollapse,
headingLevel: this.options.headingLevel,
clear: function () { return _this.clear(); },
toggleCollapse: function () { return _this.toggleCollapse(); },
collapse: function () { return _this.collapse(); },
expand: function () { return _this.expand(); }
});
this.element.appendChild(this.header.element);
};
DynamicFacet.prototype.createAndAppendSearch = function () {
if (this.options.enableFacetSearch === false) {
return;
}
this.search = new DynamicFacetSearch_1.DynamicFacetSearch(this);
this.element.appendChild(this.search.element);
};
DynamicFacet.prototype.createAndAppendValues = function () {
this.element.appendChild(this.values.render());
};
DynamicFacet.prototype.updateQueryStateModel = function () {
this.listenToQueryStateChange = false;
this.queryStateModel.set(this.includedAttributeId, this.values.selectedValues);
this.listenToQueryStateChange = true;
};
DynamicFacet.prototype.updateAppearance = function () {
this.header.toggleClear(this.values.hasSelectedValues);
this.header.toggleCollapse(this.isCollapsed);
this.toggleSearchDisplay();
Dom_1.$$(this.element).toggleClass('coveo-dynamic-facet-collapsed', this.isCollapsed);
Dom_1.$$(this.element).toggleClass('coveo-active', this.values.hasSelectedValues);
Dom_1.$$(this.element).toggleClass('coveo-hidden', !this.values.hasDisplayedValues);
};
DynamicFacet.prototype.toggleSearchDisplay = function () {
if (this.options.enableFacetSearch === false) {
return;
}
if (this.isCollapsed) {
return Dom_1.$$(this.search.element).toggleClass('coveo-hidden', true);
}
Dom_1.$$(this.search.element).toggleClass('coveo-hidden', !this.options.enableFacetSearch && !this.moreValuesAvailable);
};
DynamicFacet.prototype.triggerNewQuery = function (beforeExecuteQuery) {
this.beforeSendingQuery();
var options = beforeExecuteQuery ? { beforeExecuteQuery: beforeExecuteQuery } : { ignoreWarningSearchEvent: true };
this.queryController.executeQuery(options);
};
DynamicFacet.prototype.triggerNewIsolatedQuery = function (beforeExecuteQuery) {
return __awaiter(this, void 0, void 0, function () {
var results, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.beforeSendingQuery();
beforeExecuteQuery && beforeExecuteQuery();
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.dynamicFacetQueryController.getQueryResults()];
case 2:
results = _a.sent();
this.handleQueryResults(results);
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
this.header.hideLoading();
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
DynamicFacet.prototype.beforeSendingQuery = function () {
this.header.showLoading();
};
DynamicFacet.prototype.notImplementedError = function () {
this.logger.error('DynamicFacets are not supported by your current search endpoint. Disabling this component.');
this.disable();
this.updateAppearance();
};
DynamicFacet.prototype.verifyCollapsingConfiguration = function () {
if (this.options.collapsedByDefault && !this.options.enableCollapse) {
this.logger.warn('The "collapsedByDefault" option is "true" while the "enableCollapse" is "false"');
}
};
DynamicFacet.prototype.logAnalyticsFacetShowMoreLess = function (cause) {
this.usageAnalytics.logCustomEvent(cause, this.basicAnalyticsFacetMeta, this.element);
};
DynamicFacet.prototype.clear = function () {
var _this = this;
this.reset();
this.enableFreezeFacetOrderFlag();
this.scrollToTop();
this.triggerNewQuery(function () { return _this.logClearAllToAnalytics(); });
};
DynamicFacet.prototype.logClearAllToAnalytics = function () {
this.logAnalyticsEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.dynamicFacetClearAll, this.basicAnalyticsFacetMeta);
};
DynamicFacet.ID = 'DynamicFacet';
DynamicFacet.doExport = function () { return GlobalExports_1.exportGlobally({ DynamicFacet: DynamicFacet }); };
/**
* The options for the DynamicFacet
* @componentOptions
*/
DynamicFacet.options = __assign({}, ResponsiveFacetOptions_1.ResponsiveFacetOptions, {
/**
* The unique identifier for this facet.
*
* Among other things, this is used to record and read the facet
* state in the URL fragment identifier (see the
* [`enableHistory`]{@link SearchInterface.options.enableHistory} `SearchInterface`
* option).
*
* **Tip:** When several facets in a given search interface are based on
* the same field, ensure that each of those facets has a distinct `id`.
*
* If specified, must contain between 1 and 60 characters.
* Only alphanumeric (A-Za-z0-9), underscore (_), and hyphen (-) characters are kept; other characters are automatically removed.
*
* Defaults to the [`field`]{@link DynamicFacet.options.field} option value.
*
* @examples author-facet
*/
id: ComponentOptions_1.ComponentOptions.buildStringOption({
postProcessing: function (value, options) {
if (value === void 0) { value = ''; }
var maxCharLength = 60;
var sanitizedValue = value.replace(/[^A-Za-z0-9-_@]+/g, '');
if (Utils_1.Utils.isNonEmptyString(sanitizedValue)) {
return sanitizedValue.slice(0, maxCharLength - 1);
}
return options.field.slice(0, maxCharLength - 1);
},
section: 'CommonOptions'
}),
/**
* The title to display for this facet.
*
* Defaults to the localized string for `NoTitle`.
*
* @examples Author
*/
title: ComponentOptions_1.ComponentOptions.buildLocalizedStringOption({
localizedString: function () { return Strings_1.l('NoTitle'); },
section: 'CommonOptions',
priority: 10
}),
/**
* The name of the field on which to base this facet.
*
* The field must of the `string` type.
*
* Must be prefixed by `@`, and must reference an existing field whose
* **Facet** option is enabled.
*
* @externaldocs [Add or Edit Fields](https://docs.coveo.com/en/1982/)
* @examples @author
*/
field: ComponentOptions_1.ComponentOptions.buildFieldOption({ required: true, section: 'CommonOptions' }),
/**
* The sort criterion to use for this facet.
*
* See [`FacetSortCriteria`]{@link FacetSortCriteria} for the list and
* description of allowed values.
*
* By default, the following behavior applies:
*
* - If the requested [`numberOfValues`]{@link DynamicFacet.options.numberOfValues}
* is greater than or equal to the currently displayed number of values,
* the [`alphanumeric`]{@link FacetSortCriteria.alphanumeric} criterion is
* used.
* - If the requested `numberOfValues` is less than the currently displayed
* number of values and the facet is not currently expanded, the [`score`]{@link FacetSortCriteria.score}
* criterion is used.
* - Otherwise, the `alphanumeric` criterion is used.
*
* @examples score
*/
sortCriteria: ComponentOptions_1.ComponentOptions.buildStringOption({
postProcessing: function (value) {
if (!value) {
return undefined;
}
if (FacetSortCriteria_1.isFacetSortCriteria(value)) {
return value;
}
new Logger_1.Logger(value).warn('sortCriteria is not of the the allowed values: "score", "alphanumeric", "occurrences"');
return undefined;
},
section: 'Sorting'
}),
/**
* Specifies a custom order by which to sort the dynamic facet values.
*
* Custom-ordered values won't necessarily retrieve values from the index.
*
* **Example:**
*
* You could use this option to specify a logical order for support tickets, such as:
* ```html
* <div class="CoveoDynamicFacet" data-field="@ticketstatus" data-title="Ticket Status" data-tab="All" data-custom-sort="New,Opened,Feedback,Resolved"></div>
* ```
*
* **Note:**
* > The [`DynamicFacetRange`]{@link DynamicFacetRange} component does not support this option.
*/
customSort: ComponentOptions_1.ComponentOptions.buildListOption({ section: 'Sorting' }),
/**
* The number of values to request for this facet.
*
* Also determines the default maximum number of additional values to request each time this facet is expanded,
* and the maximum number of values to display when this facet is collapsed (see the [`enableCollapse`]{@link DynamicFacet.options.enableCollapse} option).
*/
numberOfValues: ComponentOptions_1.ComponentOptions.buildNumberOption({ min: 0, defaultValue: 8, section: 'CommonOptions' }),
/**
* Whether to allow the end-user to expand and collapse this facet.
*/
enableCollapse: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: true, section: 'CommonOptions' }),
/**
* Whether to scroll back to the top of the page whenever the end-user interacts with the facet.
*/
enableScrollToTop: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: true, section: 'CommonOptions' }),
/**
* Whether to enable the **Show more** and **Show less** buttons in the facet.
*
* **Note:** The [`DynamicFacetRange`]{@link DynamicFacetRange} component does not support this option.
*/
enableMoreLess: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: true, section: 'CommonOptions' }),
/**
* Whether to allow the end-user to search the facet values.
*
* **Note:** The [`DynamicFacetRange`]{@link DynamicFacetRange} component does not support this option.
*
* By default, the following behavior applies:
*
* - Enabled when more facet values are available.
* - Disabled when all available facet values are already displayed.
*/
enableFacetSearch: ComponentOptions_1.ComponentOptions.buildBooleanOption({ section: 'Filtering' }),
/**
* Whether to prepend facet search queries with a wildcard.
*
* **Note:** The [`DynamicFacetRange`]{@link DynamicFacetRange} component does not support this option.
*/
useLeadingWildcardInFacetSearch: ComponentOptions_1.ComponentOptions.buildBooleanOption({
defaultValue: true,
section: 'Filtering',
depend: 'enableFacetSearch'
}),
/**
* Whether this facet should be collapsed by default.
*/
collapsedByDefault: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: false, section: 'CommonOptions', depend: 'enableCollapse' }),
/**
* Whether to notify the [`Breadcrumb`]{@link Breadcrumb} component when toggling values in the facet.
*
* See also the [`numberOfValuesInBreadcrumb`]{@link DynamicFacet.options.numberOfValuesInBreadcrumb} option.
*/
includeInBreadcrumb: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: true, section: 'CommonOptions' }),
/**
* The maximum number of selected values the [`Breadcrumb`]{@link Breadcrumb} component can display before outputting a **N more...** link for the facet.
*/
numberOfValuesInBreadcrumb: ComponentOptions_1.ComponentOptions.buildNumberOption({
defaultFunction: function () { return (DeviceUtils_1.DeviceUtils.isMobileDevice() ? 3 : 5); },
min: 0,
depend: 'includeInBreadcrumb',
section: 'CommonOptions'
}),
/**
* A mapping of facet values to their desired captions.
*
* **Note:** The [`DynamicFacetRange`]{@link DynamicFacetRange} component does not support this option.
*
* @externaldocs [Normalizing Facet Value Captions](https://docs.coveo.com/368/).
* @examples { "smith_alice": "Alice Smith"\, "jones_bob_r": "Bob R. Jones" }
*/
valueCaption: ComponentOptions_1.ComponentOptions.buildJsonOption({ defaultValue: {} }),
/**
* The [`id`]{@link DynamicFacet.options.id} of another facet in which at least one value must be selected in order for the dependent facet to be visible.
*
* By default, the facet does not depend on any other facet to be displayed.
*
* @examples document-type-facet
*
* @availablesince [December 2019 Release (v2.7610)](https://docs.coveo.com/en/3142/)
*/
dependsOn: ComponentOptions_1.ComponentOptions.buildStringOption({ section: 'CommonOptions' }),
/**
* A function that verifies whether the current state of the `dependsOn` facet allows the dependent facet to be displayed.
*
* If specified, the function receives a reference to the resolved `dependsOn` facet component instance as an argument, and must return a boolean.
* The function's argument should typically be treated as read-only.
*
* By default, the dependent facet is displayed whenever one or more values are selected in its `dependsOn` facet.
*
* @externaldocs [Defining Dependent Facets](https://docs.coveo.com/3210/)
*
* @availablesince [April 2020 Release (v2.8864)](https://docs.coveo.com/en/3231/)
*/
dependsOnCondition: ComponentOptions_1.ComponentOptions.buildCustomOption(function () {
return null;
}, { depend: 'dependsOn', section: 'CommonOptions' }),
/**
* The number of items to scan for facet values.
*
* Setting this option to a higher value may enhance the accuracy of facet value counts at the cost of slower query performance.
*
* @availablesince [January 2020 Release (v2.7968)](https://docs.coveo.com/en/3163/)
*
* @examples 1500
*/
injectionDepth: ComponentOptions_1.ComponentOptions.buildNumberOption({ defaultValue: 1000, min: 1000 }),
/**
* Whether to exclude folded result parents when estimating result counts for facet values.
*
* **Note:** The target folding field must be a facet field with the **Use cache for nested queries** options enabled (see [Add or Edit a Field](https://docs.coveo.com/en/1982)).
*
* See also the [`Folding`]{@link Folding} and [`FoldingForThread`]{@link FoldingForThread} components.
*
* **Default:** `true`.
*
* @availablesince [March 2020 Release (v2.8521)](https://docs.coveo.com/en/3203/)
*/
filterFacetCount: ComponentOptions_1.ComponentOptions.buildBooleanOption({ section: 'Filtering' }),
/**
* The [heading level](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements) to use for the heading above the facet.
*
* A value of 0 will render a [`div`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) element instead.
*
* **Default:** `2`.
*/
headingLevel: ComponentOptions_1.ComponentOptions.buildNumberOption({ defaultValue: 2, min: 0, max: 6 }) });
return DynamicFacet;
}(Component_1.Component));
exports.DynamicFacet = DynamicFacet;
Initialization_1.Initialization.registerAutoCreateComponent(DynamicFacet);
DynamicFacet.doExport();
/***/ }),
/***/ 174:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var underscore_1 = __webpack_require__(0);
var Core_1 = __webpack_require__(20);
var ComponentsTypes_1 = __webpack_require__(47);
var Dom_1 = __webpack_require__(1);
var InitializationEvents_1 = __webpack_require__(17);
var DependsOnManager = /** @class */ (function () {
function DependsOnManager(facet) {
var _this = this;
this.facet = facet;
Dom_1.$$(this.facet.ref.searchInterface.element).on(Core_1.QueryEvents.buildingQuery, function () { return _this.handleBuildingQuery(); });
if (this.getDependsOn(this.facet.ref)) {
this.facet.ref.bind.onRootElement(InitializationEvents_1.InitializationEvents.afterComponentsInitialization, function () { return _this.setupDependentFacet(); });
}
}
DependsOnManager.prototype.setupDependentFacet = function () {
var _this = this;
Dom_1.$$(this.facet.ref.element).addClass('coveo-hidden-dependant-facet');
this.parentFacetRef = this.getParentFacet(this.facet.ref);
if (this.parentFacetRef) {
Dom_1.$$(this.facet.ref.root).on('state:change', function () { return _this.resetIfConditionUnfullfiled(); });
}
};
DependsOnManager.prototype.resetIfConditionUnfullfiled = function () {
var condition = this.getDependsOnCondition(this.facet.ref);
if (!condition(this.parentFacetRef)) {
this.facet.reset();
}
};
DependsOnManager.prototype.getId = function (component) {
var id = component.options.id;
return id ? "" + id : null;
};
DependsOnManager.prototype.getDependsOn = function (component) {
var dependsOn = component.options.dependsOn;
return dependsOn ? "" + dependsOn : null;
};
DependsOnManager.prototype.getDependsOnCondition = function (component) {
var _this = this;
var conditionOption = component.options.dependsOnCondition;
return conditionOption && underscore_1.isFunction(conditionOption)
? conditionOption
: function () { return _this.parentHasSelectedValues(component) && _this.parentIsEnabled(component); };
};
DependsOnManager.prototype.parentHasSelectedValues = function (component) {
var parent = this.getParentFacet(component);
return parent && this.valuesExistForFacetWithId(this.getId(parent));
};
DependsOnManager.prototype.parentIsEnabled = function (component) {
var parent = this.getParentFacet(component);
return parent && !parent.disabled;
};
DependsOnManager.prototype.valuesExistForFacetWithId = function (facetId) {
var values = this.facet.ref.queryStateModel.get(Core_1.QueryStateModel.getFacetId(facetId));
return !!values && !!values.length;
};
Object.defineProperty(DependsOnManager.prototype, "allFacetsInInterface", {
get: fu