coveo-search-ui
Version:
Coveo JavaScript Search Framework
1,078 lines (1,052 loc) • 177 kB
JavaScript
webpackJsonpCoveo__temporary([0,42],{
/***/ 236:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
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 });
var RankingInfoTable_1 = __webpack_require__(817);
var MetaDataTable_1 = __webpack_require__(819);
var Dom_1 = __webpack_require__(1);
var ExternalModulesShim_1 = __webpack_require__(26);
var Core_1 = __webpack_require__(20);
var RelevanceInspectorTabs_1 = __webpack_require__(820);
__webpack_require__(821);
var ExecutionReport_1 = __webpack_require__(812);
var AvailableFieldsTable_1 = __webpack_require__(829);
var underscore_1 = __webpack_require__(0);
var InlineRankingInfo_1 = __webpack_require__(830);
var RelevanceInspector = /** @class */ (function () {
function RelevanceInspector(element, bindings) {
var _this = this;
this.element = element;
this.bindings = bindings;
this.opened = false;
this.modalBoxModule = ExternalModulesShim_1.ModalBox;
Dom_1.$$(this.element).text('Relevance Inspector');
Dom_1.$$(this.element).addClass('coveo-button coveo-relevance-inspector');
Dom_1.$$(this.bindings.root).on(this.bindings.queryStateModel.getEventName(Core_1.QueryStateModel.eventTypes.changeOne + Core_1.QueryStateModel.attributesEnum.debug), function (e, args) { return _this.toggleFromState(args.value); });
Dom_1.$$(this.element).on('click', function () { return _this.open(); });
Dom_1.$$(this.bindings.root).on(Core_1.ResultListEvents.newResultDisplayed, function (e, args) {
return _this.handleNewResultDisplayed(args);
});
this.bindings.queryStateModel.get(Core_1.QueryStateModel.attributesEnum.debug) ? this.show() : this.hide();
}
Object.defineProperty(RelevanceInspector.prototype, "modalBox", {
get: function () {
return this.modalBoxModule;
},
set: function (modalBoxModule) {
this.modalBoxModule = modalBoxModule;
},
enumerable: true,
configurable: true
});
RelevanceInspector.prototype.hide = function () {
Dom_1.$$(this.element).addClass('coveo-hidden');
};
RelevanceInspector.prototype.show = function () {
Dom_1.$$(this.element).removeClass('coveo-hidden');
};
RelevanceInspector.prototype.open = function () {
return __awaiter(this, void 0, void 0, function () {
var content, animation, rows;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this.opened) {
return [2 /*return*/];
}
this.opened = true;
content = Dom_1.$$('div');
animation = Core_1.DomUtils.getBasicLoadingAnimation();
content.append(animation);
this.modalBox.open(content.el, this.modalBoxOptions);
return [4 /*yield*/, this.buildTabs()];
case 1:
rows = _a.sent();
if (rows) {
animation.remove();
content.append(rows.el);
}
else {
this.modalBox.close();
}
return [2 /*return*/];
}
});
});
};
RelevanceInspector.prototype.handleNewResultDisplayed = function (args) {
if (this.bindings.queryStateModel.get(Core_1.QueryStateModel.attributesEnum.debug)) {
Dom_1.$$(args.item).addClass('coveo-with-inline-ranking-info');
if (Dom_1.$$(args.item).hasClass('coveo-table-layout')) {
Dom_1.$$(args.item).append(new InlineRankingInfo_1.InlineRankingInfo(args.result).build().el);
}
else {
Dom_1.$$(args.item).prepend(new InlineRankingInfo_1.InlineRankingInfo(args.result).build().el);
}
}
};
Object.defineProperty(RelevanceInspector.prototype, "modalBoxOptions", {
get: function () {
var _this = this;
return {
title: 'Relevance Inspector',
titleClose: false,
overlayClose: true,
sizeMod: 'big',
className: 'relevance-inspector-modal',
validation: function () {
_this.opened = false;
return true;
},
body: document.getElementsByClassName('CoveoSearchInterface')[0] // Will return undefined if no CoveoSearchInterface is present
};
},
enumerable: true,
configurable: true
});
RelevanceInspector.prototype.toggleFromState = function (stateValue) {
stateValue != 0 ? this.show() : this.hide();
this.modalBox.close();
};
RelevanceInspector.prototype.buildTabs = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var lastResults, container, rankingInfoTable, metadataTable, executionReport, availableFields, inspectorTabs, debouncedResize, _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
return __generator(this, function (_o) {
switch (_o.label) {
case 0:
lastResults = this.bindings.queryController.getLastResults().results;
if (!lastResults || lastResults.length == 0) {
new Core_1.Logger(this).error('Could not open Relevance Inspector because there is no results to display. Please execute a query beforehand', lastResults);
return [2 /*return*/];
}
if (!lastResults[0].rankingInfo) {
new Core_1.Logger(this).error('Could not open Relevance Inspector because there is no ranking info returned on the results. Please execute a query in debug mode beforehad', lastResults);
return [2 /*return*/];
}
container = Dom_1.$$('div');
rankingInfoTable = new RankingInfoTable_1.RankingInfoTable(lastResults, this.bindings);
metadataTable = new MetaDataTable_1.MetaDataTable(lastResults, this.bindings);
executionReport = new ExecutionReport_1.ExecutionReport(this.bindings.queryController.getLastResults(), this.bindings);
availableFields = new AvailableFieldsTable_1.AvailableFieldsTable(this.bindings);
this.tabs = {
relevanceInspectorRankingInfo: rankingInfoTable,
relevanceInspectorMetadata: metadataTable,
relevanceInspectorExecutionReport: executionReport,
relevanceInspectorAvailableFields: availableFields
};
inspectorTabs = new RelevanceInspectorTabs_1.RelevanceInspectorTabs(function (tabChangedTo) {
_this.activeTab = tabChangedTo;
_this.resize();
});
debouncedResize = underscore_1.debounce(function () { return _this.resize(); }, 100);
window.addEventListener('resize', debouncedResize);
_b = (_a = inspectorTabs).addSection;
_c = ['Ranking Information'];
return [4 /*yield*/, rankingInfoTable.build()];
case 1:
_b.apply(_a, _c.concat([_o.sent(), 'relevanceInspectorRankingInfo']));
_e = (_d = inspectorTabs).addSection;
_f = ['Metadata'];
return [4 /*yield*/, metadataTable.build()];
case 2:
_e.apply(_d, _f.concat([_o.sent(), 'relevanceInspectorMetadata']));
_h = (_g = inspectorTabs).addSection;
_j = ['Execution Report'];
return [4 /*yield*/, executionReport.build()];
case 3:
_h.apply(_g, _j.concat([_o.sent(), 'relevanceInspectorExecutionReport']));
_l = (_k = inspectorTabs).addSection;
_m = ['Available Fields'];
return [4 /*yield*/, availableFields.build()];
case 4:
_l.apply(_k, _m.concat([_o.sent(), 'relevanceInspectorAvailableFields']));
inspectorTabs.select('relevanceInspectorRankingInfo');
container.append(inspectorTabs.navigationSection.el);
container.append(inspectorTabs.tabContentSection.el);
return [2 /*return*/, container];
}
});
});
};
RelevanceInspector.prototype.resize = function () {
if (!this.activeTab) {
return;
}
if (!this.tabs[this.activeTab]) {
return;
}
this.tabs[this.activeTab].gridOptions.api.sizeColumnsToFit();
};
return RelevanceInspector;
}());
exports.RelevanceInspector = RelevanceInspector;
/***/ }),
/***/ 475:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var underscore_1 = __webpack_require__(0);
var Dom_1 = __webpack_require__(1);
function bindAnalyticsToLink(element, logAnalytics) {
var executeOnlyOnce = underscore_1.once(function () { return logAnalytics(); });
Dom_1.$$(element).on(['contextmenu', 'click', 'mousedown', 'mouseup'], executeOnlyOnce);
var longPressTimer;
Dom_1.$$(element).on('touchstart', function () {
longPressTimer = window.setTimeout(executeOnlyOnce, 1000);
});
Dom_1.$$(element).on('touchend', function () {
if (longPressTimer) {
clearTimeout(longPressTimer);
}
});
}
exports.bindAnalyticsToLink = bindAnalyticsToLink;
/***/ }),
/***/ 535:
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ 71:
/***/ (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Component_1 = __webpack_require__(7);
var ComponentOptions_1 = __webpack_require__(8);
var ComponentOptionsModel_1 = __webpack_require__(28);
var AnalyticsActionListMeta_1 = __webpack_require__(10);
var ResultListEvents_1 = __webpack_require__(29);
var HighlightUtils_1 = __webpack_require__(69);
var DeviceUtils_1 = __webpack_require__(24);
var OSUtils_1 = __webpack_require__(181);
var Initialization_1 = __webpack_require__(2);
var QueryUtils_1 = __webpack_require__(21);
var Assert_1 = __webpack_require__(5);
var Utils_1 = __webpack_require__(4);
var Defer_1 = __webpack_require__(31);
var Dom_1 = __webpack_require__(1);
var StreamHighlightUtils_1 = __webpack_require__(120);
var StringUtils_1 = __webpack_require__(22);
var underscore_1 = __webpack_require__(0);
var GlobalExports_1 = __webpack_require__(3);
__webpack_require__(535);
var AccessibleButton_1 = __webpack_require__(15);
var ResultLinkCommon_1 = __webpack_require__(475);
/**
* The `ResultLink` component automatically transform a search result title into a clickable link pointing to the
* original item.
*
* This component is a result template component (see [Result Templates](https://docs.coveo.com/en/413/)).
*/
var ResultLink = /** @class */ (function (_super) {
__extends(ResultLink, _super);
/**
* Creates a new `ResultLink` component.
* @param element The HTMLElement on which to instantiate the component.
* @param options The options for the `ResultLink` component.
* @param bindings The bindings that the component requires to function normally. If not set, these will be
* automatically resolved (with a slower execution time).
* @param result The result to associate the component with.
* @param os
*/
function ResultLink(element, options, bindings, result, os) {
var _this = _super.call(this, element, ResultLink.ID, bindings) || this;
_this.element = element;
_this.options = options;
_this.bindings = bindings;
_this.result = result;
_this.os = os;
_this.logAnalytics = underscore_1.debounce(function () {
_this.queryController.saveLastQuery();
var documentURL = Dom_1.$$(_this.element).getAttribute('href');
if (documentURL == undefined || documentURL == '') {
documentURL = _this.escapedClickUri;
}
if (_this.options.logAnalytics) {
_this.options.logAnalytics(documentURL);
}
else {
_this.logDocumentOpen(documentURL);
}
Defer_1.Defer.flush();
}, 1500, true);
var globalOptions = _this.searchInterface.options.originalOptionsObject[ResultLink.ID] || {};
var initialOptions = ComponentOptions_1.ComponentOptions.initComponentOptions(element, ResultLink, __assign({}, globalOptions, options));
var resultLinkOptions = _this.componentOptionsModel.get(ComponentOptionsModel_1.ComponentOptionsModel.attributesEnum.resultLink);
_this.options = underscore_1.extend({}, initialOptions, resultLinkOptions);
_this.result = result || _this.resolveResult();
if (_this.options.openQuickview == null) {
_this.options.openQuickview = result.raw['connectortype'] == 'ExchangeCrawler' && DeviceUtils_1.DeviceUtils.isMobileDevice();
}
if (!_this.element.hasAttribute('tabindex')) {
_this.element.setAttribute('tabindex', '0');
}
Assert_1.Assert.exists(_this.componentOptionsModel);
Assert_1.Assert.exists(_this.result);
if (!_this.quickviewShouldBeOpened()) {
// Bind on multiple "click" or "mouse" events.
// Create a function that will be executed only once, so as not to log multiple events
// Once a result link has been opened, and that we log at least one analytics event,
// it should not matter if the end user open the same link multiple times with different methods.
// It's still only one "click" event as far as UA is concerned.
// Also need to handle "longpress" on mobile (the contextual menu), which we assume to be 1 s long.
ResultLinkCommon_1.bindAnalyticsToLink(element, function () { return _this.logAnalytics(); });
}
_this.renderUri(element, result);
_this.bindEventToOpen();
return _this;
}
ResultLink.prototype.renderUri = function (element, result) {
if (/^\s*$/.test(this.element.innerHTML)) {
var title = this.getDisplayedTitle();
this.element.innerHTML = title;
var titleAsText = this.getDisplayedTitleAsText();
if (!this.element.hasAttribute('aria-label')) {
this.element.setAttribute('aria-label', titleAsText);
}
if (!this.element.title) {
this.element.title = titleAsText;
}
}
};
/**
* Opens the result in the same window, no matter how the actual component is configured for the end user.
* @param logAnalytics Specifies whether the method should log an analytics event.
*/
ResultLink.prototype.openLink = function (logAnalytics) {
if (logAnalytics === void 0) { logAnalytics = true; }
if (logAnalytics) {
this.logAnalytics();
}
window.location.href = this.getResultUri();
};
/**
* Opens the result in a new window, no matter how the actual component is configured for the end user.
* @param logAnalytics Specifies whether the method should log an analytics event.
*/
ResultLink.prototype.openLinkInNewWindow = function (logAnalytics) {
if (logAnalytics === void 0) { logAnalytics = true; }
if (logAnalytics) {
this.logAnalytics();
}
window.open(this.getResultUri(), '_blank');
};
/**
* Tries to open the result in Microsoft Outlook if the result has an `outlookformacuri` or `outlookuri` field.
*
* Normally, this implies the result should be a link to an email.
*
* If the needed fields are not present, this method does nothing.
* @param logAnalytics Specifies whether the method should log an analytics event.
*/
ResultLink.prototype.openLinkInOutlook = function (logAnalytics) {
if (logAnalytics === void 0) { logAnalytics = true; }
if (this.hasOutlookField()) {
if (logAnalytics) {
this.logAnalytics();
}
this.openLink();
}
};
/**
* Opens the link in the same manner the end user would.
*
* This essentially simulates a click on the result link.
*
* @param logAnalytics Specifies whether the method should log an analytics event.
*/
ResultLink.prototype.openLinkAsConfigured = function (logAnalytics) {
if (logAnalytics === void 0) { logAnalytics = true; }
if (this.toExecuteOnOpen) {
if (logAnalytics) {
this.logAnalytics();
}
this.toExecuteOnOpen();
}
};
ResultLink.prototype.bindEventToOpen = function () {
return (this.bindOnClickIfNotUndefined() ||
this.bindOpenQuickviewIfNotUndefined() ||
this.setHrefIfNotAlready() ||
this.openLinkThatIsNotAnAnchor());
};
ResultLink.prototype.getDisplayedTitle = function () {
if (!this.options.titleTemplate) {
return this.result.title
? HighlightUtils_1.HighlightUtils.highlightString(this.result.title, this.result.titleHighlights, null, 'coveo-highlight')
: this.escapedClickUri;
}
else {
var newTitle = StringUtils_1.StringUtils.buildStringTemplateFromResult(this.options.titleTemplate, this.result);
return newTitle
? StreamHighlightUtils_1.StreamHighlightUtils.highlightStreamText(newTitle, this.result.termsToHighlight, this.result.phrasesToHighlight)
: this.escapedClickUri;
}
};
ResultLink.prototype.getDisplayedTitleAsText = function () {
var container = Dom_1.$$('div');
container.setHtml(this.getDisplayedTitle());
return container.text();
};
Object.defineProperty(ResultLink.prototype, "escapedClickUri", {
get: function () {
return underscore_1.escape(this.result.clickUri);
},
enumerable: true,
configurable: true
});
ResultLink.prototype.bindOnClickIfNotUndefined = function () {
var _this = this;
if (this.options.onClick != undefined) {
this.toExecuteOnOpen = function (e) {
_this.options.onClick.call(_this, e, _this.result);
};
new AccessibleButton_1.AccessibleButton()
.withElement(this.element)
.withLabel(this.result.title)
.withSelectAction(function (e) { return _this.toExecuteOnOpen(e); })
.build();
return true;
}
else {
return false;
}
};
ResultLink.prototype.bindOpenQuickviewIfNotUndefined = function () {
var _this = this;
if (this.quickviewShouldBeOpened()) {
this.toExecuteOnOpen = function () {
Dom_1.$$(_this.bindings.resultElement).trigger(ResultListEvents_1.ResultListEvents.openQuickview);
};
Dom_1.$$(this.element).on('click', function (e) {
e.preventDefault();
_this.toExecuteOnOpen();
});
return true;
}
else {
return false;
}
};
ResultLink.prototype.openLinkThatIsNotAnAnchor = function () {
var _this = this;
if (!this.elementIsAnAnchor()) {
this.toExecuteOnOpen = function () {
if (_this.options.alwaysOpenInNewWindow) {
if (_this.options.openInOutlook) {
_this.openLinkInOutlook();
}
else {
_this.openLinkInNewWindow();
}
}
else {
_this.openLink();
}
};
Dom_1.$$(this.element).on('click', function () {
_this.toExecuteOnOpen();
});
return true;
}
return false;
};
ResultLink.prototype.setHrefIfNotAlready = function () {
// Do not erase any value put in href by the template, etc. Allows
// using custom click urls while still keeping analytics recording
// and other behavior brought by the component.
if (this.elementIsAnAnchor() && !Utils_1.Utils.isNonEmptyString(Dom_1.$$(this.element).getAttribute('href'))) {
Dom_1.$$(this.element).setAttribute('href', this.getResultUri());
if (this.options.alwaysOpenInNewWindow && !(this.options.openInOutlook && this.hasOutlookField())) {
Dom_1.$$(this.element).setAttribute('target', '_blank');
}
return true;
}
else {
return false;
}
};
ResultLink.prototype.logDocumentOpen = function (href) {
this.usageAnalytics.logClickEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.documentOpen, {
documentURL: href,
documentTitle: this.result.title,
author: Utils_1.Utils.getFieldValue(this.result, 'author')
}, this.result, this.root);
};
ResultLink.prototype.filterProtocol = function (uri) {
var isAbsolute = /^(https?|ftp|file|mailto|tel|sip):/i.test(uri);
var isRelative = /^(\/|\.\/|\.\.\/)/.test(uri);
return isAbsolute || isRelative ? uri : '';
};
ResultLink.prototype.getResultUri = function () {
if (this.options.hrefTemplate) {
var uri = StringUtils_1.StringUtils.buildStringTemplateFromResult(this.options.hrefTemplate, this.result);
return this.filterProtocol(uri);
}
if (this.options.field == undefined && this.options.openInOutlook) {
this.setField();
}
if (this.options.field != undefined) {
return this.filterProtocol(Utils_1.Utils.getFieldValue(this.result, this.options.field));
}
return this.filterProtocol(this.result.clickUri);
};
ResultLink.prototype.elementIsAnAnchor = function () {
return this.element.tagName == 'A';
};
ResultLink.prototype.setField = function () {
var os = Utils_1.Utils.exists(this.os) ? this.os : OSUtils_1.OSUtils.get();
if (os == OSUtils_1.OS_NAME.MACOSX && this.hasOutlookField()) {
this.options.field = '@outlookformacuri';
}
else if (os == OSUtils_1.OS_NAME.WINDOWS && this.hasOutlookField()) {
this.options.field = '@outlookuri';
}
};
ResultLink.prototype.hasOutlookField = function () {
var os = Utils_1.Utils.exists(this.os) ? this.os : OSUtils_1.OSUtils.get();
if (os == OSUtils_1.OS_NAME.MACOSX && this.result.raw['outlookformacuri'] != undefined) {
return true;
}
else if (os == OSUtils_1.OS_NAME.WINDOWS && this.result.raw['outlookuri'] != undefined) {
return true;
}
return false;
};
ResultLink.prototype.isUriThatMustBeOpenedInQuickview = function () {
return this.escapedClickUri.toLowerCase().indexOf('ldap://') == 0;
};
ResultLink.prototype.quickviewShouldBeOpened = function () {
return (this.options.openQuickview || this.isUriThatMustBeOpenedInQuickview()) && QueryUtils_1.QueryUtils.hasHTMLVersion(this.result);
};
ResultLink.ID = 'ResultLink';
ResultLink.doExport = function () {
GlobalExports_1.exportGlobally({
ResultLink: ResultLink
});
};
/**
* The options for the ResultLink
* @componentOptions
*/
ResultLink.options = {
/**
* Specifies the field to use to output the component `href` attribute value.
*
* **Tip:**
* > Instead of specifying a value for the `field` option, you can directly add an `href` attribute to the
* > `ResultLink` HTML element. Then, you can use a custom script to generate the `href` value.
*
* **Examples:**
* - With the following markup, the `ResultLink` outputs its `href` value using the `@uri` field (rather than the
* default field):
*
* ```html
* <a class="CoveoResultLink" data-field="@uri"></a>
* ```
*
* - In the following result template, the custom `getMyKBUri()` function provides the `href` value:
*
* ```html
* <script id="KnowledgeArticle" type="text/underscore" class="result-template">
* <div class='CoveoIcon>'></div>
* <a class="CoveoResultLink" href="<%= getMyKBUri(raw) %>"></a>
* <div class="CoveoExcerpt"></div>
* </script>
* ```
*
* See also [`hrefTemplate`]{@link ResultLink.options.hrefTemplate}, which can override this option.
*
* By default, the component uses the `@clickUri` field of the item to output the value of its `href` attribute.
*/
field: ComponentOptions_1.ComponentOptions.buildFieldOption(),
/**
* Specifies whether the component should try to open its link in Microsoft Outlook.
*
* Setting this option to `true` is normally useful for `ResultLink` instances related to Microsoft Exchange emails.
*
* If this option is `true`, clicking the `ResultLink` calls the
* [`openLinkInOutlook`]{@link ResultLink.openLinkInOutlook} method instead of the
* [`openLink`]{@link ResultLink.openLink} method.
*
* Default value is `false`.
*/
openInOutlook: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: false }),
/**
* Specifies whether the component should open its link in the [`Quickview`]{@link Quickview} component rather than
* loading through the original URL.
*
* Default value is `false`.
*/
openQuickview: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: false }),
/**
* Specifies whether the component should open its link in a new window instead of opening it in the current
* context.
*
* If this option is `true`, clicking the `ResultLink` calls the
* [`openLinkInNewWindow`]{@link ResultLink.openLinkInNewWindow} method instead of the
* [`openLink`]{@link ResultLink.openLink} method.
*
* **Note:**
* > If a search page contains a [`ResultPreferences`]{@link ResultsPreferences} component whose
* > [`enableOpenInNewWindow`]{@link ResultsPreferences.options.enableOpenInNewWindow} option is `true`, and the end
* > user checks the <b>Always open results in new window</b> box, `ResultLink` components in this page will always
* > open their links in a new window when the end user clicks them, no matter what the value of their
* > `alwaysOpenInNewWindow` option is.
*
* Default value is `false`.
*/
alwaysOpenInNewWindow: ComponentOptions_1.ComponentOptions.buildBooleanOption({ defaultValue: false }),
/**
* Specifies a template literal from which to generate the `ResultLink` `href` attribute value (see
* [Template literals](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals)).
*
* This option overrides the [`field`]{@link ResultLink.options.field} option value.
*
* The template literal can reference any number of fields from the parent result. It can also reference global
* scope properties.
*
* **Examples:**
*
* - The following markup generates an `href` value such as `http://uri.com?id=itemTitle`:
*
* ```html
* <a class='CoveoResultLink' data-href-template='${clickUri}?id=${raw.title}'></a>
* ```
*
* - The following markup generates an `href` value such as `localhost/fooBar`:
*
* ```html
* <a class='CoveoResultLink' data-href-template='${window.location.hostname}/{Foo.Bar}'></a>
* ```
*
* Default value is `undefined`.
*/
hrefTemplate: ComponentOptions_1.ComponentOptions.buildStringOption(),
/**
* Specifies a template literal from which to generate the `ResultLink` display title (see
* [Template literals](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals)).
*
* This option overrides the default `ResultLink` display title behavior.
*
* The template literal can reference any number of fields from the parent result. However, if the template literal
* references a key whose value is undefined in the parent result fields, the `ResultLink` title displays the
* name of this key instead.
*
* This option is ignored if the `ResultLink` innerHTML contains any value.
*
* **Examples:**
*
* - The following markup generates a `ResultLink` display title such as `Case number: 123456` if both the
* `raw.objecttype` and `raw.objectnumber` keys are defined in the parent result fields:
*
* ```html
* <a class="CoveoResultLink" data-title-template="${raw.objecttype} number: ${raw.objectnumber}"></a>
* ```
*
* - The following markup generates `${myField}` as a `ResultLink` display title if the `myField` key is undefined
* in the parent result fields:
*
* ```html
* <a class="CoveoResultLink" data-title-template="${myField}"></a>
* ```
*
* - The following markup generates `Foobar` as a `ResultLink` display title, because the `ResultLink` innterHTML is
* not empty:
*
* ```html
* <a class="CoveoResultLink" data-title-template="${will} ${be} ${ignored}">Foobar</a>
* ```
*
* Default value is `undefined`.
*
* @availablesince [January 2017 Release (v1.1865.9)](https://docs.coveo.com/en/396/#january-2017-release-v118659)
*/
titleTemplate: ComponentOptions_1.ComponentOptions.buildStringOption(),
/**
* Specifies an event handler function to execute when the user clicks the `ResultLink` component.
*
* The handler function takes a JavaScript [`Event`](https://developer.mozilla.org/en/docs/Web/API/Event) object and
* an [`IQueryResult`]{@link IQueryResult} as its parameters.
*
* Overriding the default behavior of the `onClick` event can allow you to execute specific code instead.
*
* **Note:**
* > You cannot set this option directly in the component markup as an HTML attribute. You must either set it in the
* > [`init`]{@link init} call of your search interface (see
* > [Passing Component Options in the init Call](https://docs.coveo.com/en/346/#passing-component-options-in-the-init-call)),
* > or before the `init` call, using the `options` top-level function (see
* > [Passing Component Options Before the init Call](https://docs.coveo.com/en/346/#passing-component-options-before-the-init-call)).
*
* **Example:**
* ```javascript
* // You can set the option in the 'init' call:
* Coveo.init(document.querySelector("#search"), {
* ResultLink : {
* onClick : function(e, result) {
* e.preventDefault();
* // Custom code to execute with the item URI and title.
* openUriInASpecialTab(result.clickUri, result.title);
* }
* }
* });
*
* // Or before the 'init' call, using the 'options' top-level function:
* // Coveo.options(document.querySelector('#search'), {
* // ResultLink : {
* // onClick : function(e, result) {
* // e.preventDefault();
* // // Custom code to execute with the item URI and title.
* // openUriInASpecialTab(result.clickUri, result.title);
* // }
* // }
* // });
* ```
*/
onClick: ComponentOptions_1.ComponentOptions.buildCustomOption(function () {
return null;
}),
/**
* Specify this option to log additional analytics when this result link is pressed.
*
* **Example:**
* ```javascript
* const resultLink = new Coveo.ResultLink(
* linkElement,
* {
* logAnalytics: (href) => Coveo.logCustomEvent(
* Coveo.analyticsActionCauseList.openSmartSnippetSource,
* {
* searchQueryUid: searchInterface.queryController.lastSearchUid,
* documentTitle: result.title,
* author: Utils.getFieldValue(result, 'author'),
* documentURL: href
* },
* element
* )
* },
* searchInterface.getBindings(),
* result
* )
* ```
*/
logAnalytics: ComponentOptions_1.ComponentOptions.buildCustomOption(function () { return null; })
};
return ResultLink;
}(Component_1.Component));
exports.ResultLink = ResultLink;
Initialization_1.Initialization.registerAutoCreateComponent(ResultLink);
/***/ }),
/***/ 811:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
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 });
var AgGrid_1 = __webpack_require__(818);
var underscore_1 = __webpack_require__(0);
var UtilsModules_1 = __webpack_require__(74);
var ResultLink_1 = __webpack_require__(71);
exports.defaultGridOptions = {
domLayout: 'autoHeight',
enableColResize: true,
rowHeight: 100,
enableRangeSelection: true,
suppressRowClickSelection: true,
suppressCellSelection: true,
defaultColDef: {
width: 100
},
enableSorting: true,
autoSizePadding: 10
};
var TableBuilder = /** @class */ (function () {
function TableBuilder() {
}
TableBuilder.prototype.build = function (sources, table, gridOptions) {
if (gridOptions === void 0) { gridOptions = exports.defaultGridOptions; }
return __awaiter(this, void 0, void 0, function () {
var firstData, mapToAgGridFormat, columnDefs, rowData, grid;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
firstData = underscore_1.first(sources) || {};
mapToAgGridFormat = function (value, key) {
if (value.children) {
return {
field: key,
headerName: key,
marryChildren: true,
children: underscore_1.flatten(value.children.map(function (child) {
return underscore_1.map(child, mapToAgGridFormat);
}))
};
}
else {
return __assign({ field: key, headerName: key }, value);
}
};
columnDefs = underscore_1.map(firstData, mapToAgGridFormat);
rowData = underscore_1.map(sources, function (source) {
var merged = {};
var extractContent = function (value, key) {
if (value.content) {
merged[key] = value.content;
}
else if (value.children) {
underscore_1.each(value.children, function (child) {
underscore_1.each(child, extractContent);
});
}
};
underscore_1.each(source, extractContent);
return merged;
});
this.gridOptions = __assign({}, exports.defaultGridOptions, { columnDefs: columnDefs,
rowData: rowData }, gridOptions);
return [4 /*yield*/, AgGrid_1.loadAgGridLibrary()];
case 1:
_a.sent();
grid = new agGrid.Grid(table.el, this.gridOptions);
return [2 /*return*/, { grid: grid, gridOptions: this.gridOptions }];
}
});
});
};
TableBuilder.thumbnailCell = function (result, bindings) {
return {
Document: {
content: { result: result, bindings: bindings },
cellRenderer: ThumbnailHtmlRenderer,
width: 550,
getQuickFilterText: function (params) {
return '';
}
}
};
};
return TableBuilder;
}());
exports.TableBuilder = TableBuilder;
var ThumbnailHtmlRenderer = /** @class */ (function () {
function ThumbnailHtmlRenderer() {
}
ThumbnailHtmlRenderer.prototype.init = function (params) {
if (params) {
this.element = params.value;
this.currentFilter = params.api.filterManager.quickFilter;
}
};
ThumbnailHtmlRenderer.prototype.getGui = function () {
var cell = UtilsModules_1.$$('div', { className: 'coveo-relevance-inspector-thumbnail-cell' });
if (this.element) {
var thumbnail = this.thumbnail(this.element.result, this.element.bindings);
cell.append(thumbnail.el);
}
else {
cell.append(UtilsModules_1.$$('p', undefined, '-- NULL --').el);
}
return cell.el;
};
ThumbnailHtmlRenderer.prototype.thumbnail = function (result, bindings) {
var dom;
if (bindings && result) {
var resultLists = bindings.searchInterface.getComponents('ResultList');
var firstActiveResultList = underscore_1.find(resultLists, function (resultList) { return !resultList.disabled; });
if (firstActiveResultList) {
dom = UtilsModules_1.$$('div', {
className: 'coveo-relevance-inspector-result-thumbnail'
});
firstActiveResultList.buildResult(result).then(function (builtResult) {
dom.append(builtResult);
});
}
else {
dom = UtilsModules_1.$$('a', {
className: 'CoveoResultLink'
});
new ResultLink_1.ResultLink(dom.el, { alwaysOpenInNewWindow: true }, bindings, result);
}
if (this.currentFilter) {
this.highlightSearch(dom.el, this.currentFilter);
}
}
else {
dom = UtilsModules_1.$$('div', undefined, '-- NULL --');
}
return dom;
};
ThumbnailHtmlRenderer.prototype.refresh = function (params) {
return true;
};
ThumbnailHtmlRenderer.prototype.highlightSearch = function (elementToSearch, search) {
var asHTMLElement = elementToSearch;
if (asHTMLElement != null && asHTMLElement.innerText != null) {
var match = asHTMLElement.innerText.split(new RegExp('(?=' + UtilsModules_1.StringUtils.regexEncode(search) + ')', 'gi'));
asHTMLElement.innerHTML = '';
match.forEach(function (value) {
var regex = new RegExp('(' + UtilsModules_1.StringUtils.regexEncode(search) + ')', 'i');
var group = value.match(regex);
var span;
if (group != null) {
span = UtilsModules_1.$$('span', {
className: 'coveo-relevance-inspector-highlight'
});
span.text(group[1]);
asHTMLElement.appendChild(span.el);
span = UtilsModules_1.$$('span');
span.text(value.substr(group[1].length));
asHTMLElement.appendChild(span.el);
}
else {
span = UtilsModules_1.$$('span');
span.text(value);
asHTMLElement.appendChild(span.el);
}
});
}
};
return ThumbnailHtmlRenderer;
}());
exports.ThumbnailHtmlRenderer = ThumbnailHtmlRenderer;
var GenericHtmlRenderer = /** @class */ (function () {
function GenericHtmlRenderer() {
}
GenericHtmlRenderer.prototype.init = function (params) {
if (params && params.api) {
this.element = params.value;
this.currentFilter = params.api.filterManager.quickFilter;
}
};
GenericHtmlRenderer.prototype.getGui = function () {
if (this.element && this.currentFilter) {
return UtilsModules_1.$$('div', undefined, UtilsModules_1.StreamHighlightUtils.highlightStreamHTML(this.element, { Precision: ['precision'] }, {})).el;
}
else if (this.element) {
return UtilsModules_1.$$('div', undefined, this.element).el;
}
else {
return UtilsModules_1.$$('div', undefined, '-- NULL --').el;
}
};
GenericHtmlRenderer.prototype.refresh = function (params) {
return true;
};
return GenericHtmlRenderer;
}());
exports.GenericHtmlRenderer = GenericHtmlRenderer;
/***/ }),
/***/ 812:
/***/ (function(module, exports, __webpack_require__) {
"use strict";
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) retu