{"version":3,"sources":["FieldSuggestions.min__d957946aa95219e5e0e2.js","./src/ui/FieldSuggestions/FieldSuggestions.ts","./src/ui/Misc/SuggestionForOmnibox.ts"],"names":["webpackJsonpCoveo__temporary","251","module","exports","__webpack_require__","__extends","this","extendStatics","Object","setPrototypeOf","__proto__","Array","d","b","p","hasOwnProperty","__","constructor","prototype","create","defineProperty","value","element","options","bindings","FieldSuggestions","ID","_","extend","ComponentOptions","initComponentOptions","Assert","check","Utils","isCoveoField","field","onSelect","onRowSelection","suggestionStructure","rowTemplate","toRender","rowElement","$$","className","el","innerHTML","outerHTML","headerTitle","row","header","template","headerElement","iconElement","captionElement","text","append","title","suggestionForOmnibox","SuggestionForOmnibox","args","call","onRowTab","bind","onRootElement","OmniboxEvents","populateOmnibox","handlePopulateOmnibox","_this","selectSuggestion","suggestion","currentlyDisplayedSuggestions","isNaN","trigger","currentlySuggested","findWhere","pos","exists","valueToSearch","completeQueryExpression","word","promise","Promise","resolve","queryController","getEndpoint","listFieldValues","buildListFieldValueRequest","then","results","buildOmniboxElement","map","findAll","selectable","i","zIndex","omniboxZIndex","undefined","catch","rows","push","deferred","closeOmnibox","queryStateModel","set","QueryStateModel","attributesEnum","q","usageAnalytics","logSearchEvent","analyticsActionCauseList","omniboxField","executeQuery","clear","logCustomEvent","ignoreAccents","sortCriteria","maximumNumberOfValues","numberOfSuggestions","patternType","pattern","queryOverride","doExport","exportGlobally","buildFieldOption","required","buildQueryExpressionOption","defaultValue","buildNumberOption","min","buildLocalizedStringOption","buildCustomOption","Component","Initialization","registerAutoCreateComponent","517","structure","onTabPress","length","buildElementHeader","appendChild","buildRowElements","each","ret","result","rawValue","data","DomUtils","highlightElement","on","518"],"mappings":"AAAAA,8BAA8B,KAExBC,IACA,SAAUC,EAAQC,EAASC,GAEjC,YAEA,IAAIC,GAAaC,MAAQA,KAAKD,WAAc,WACxC,GAAIE,GAAgBC,OAAOC,iBACpBC,uBAA2BC,QAAS,SAAUC,EAAGC,GAAKD,EAA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AAApF,wBFkVP2F,IACA,SAAUnJ,EAAQC","file":"FieldSuggestions.min__d957946aa95219e5e0e2.js","sourcesContent":["webpackJsonpCoveo__temporary([46],{\n\n/***/ 251:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\n__webpack_require__(518);\nvar _ = __webpack_require__(0);\nvar OmniboxEvents_1 = __webpack_require__(34);\nvar GlobalExports_1 = __webpack_require__(3);\nvar Assert_1 = __webpack_require__(5);\nvar QueryStateModel_1 = __webpack_require__(13);\nvar Dom_1 = __webpack_require__(1);\nvar Utils_1 = __webpack_require__(4);\nvar AnalyticsActionListMeta_1 = __webpack_require__(10);\nvar Component_1 = __webpack_require__(7);\nvar ComponentOptions_1 = __webpack_require__(8);\nvar Initialization_1 = __webpack_require__(2);\nvar SuggestionForOmnibox_1 = __webpack_require__(517);\n/**\n * The `FieldSuggestions` component provides query suggestions based on a particular facet field. For example, you could\n * use this component to provide auto-complete suggestions while the end user is typing the title of an item.\n *\n * The query suggestions provided by this component appear in the [`Omnibox`]{@link Omnibox} component.\n *\n * **Note:** Consider [providing Coveo ML query suggestions](https://docs.coveo.com/en/340/#providing-coveo-machine-learning-query-suggestions)\n * rather than field suggestions, as the former yields better performance and relevance.\n */\nvar FieldSuggestions = /** @class */ (function (_super) {\n __extends(FieldSuggestions, _super);\n /**\n * Creates a new `FieldSuggestions` component.\n * @param element The HTMLElement on which to instantiate the component.\n * @param options The options for the `FieldSuggestions` component.\n * @param bindings The bindings that the component requires to function normally. If not set, these will be\n * automatically resolved (with a slower execution time).\n */\n function FieldSuggestions(element, options, bindings) {\n var _this = _super.call(this, element, FieldSuggestions.ID, bindings) || this;\n _this.options = options;\n if (_this.options && 'omniboxSuggestionOptions' in _this.options) {\n _this.options = _.extend(_this.options, _this.options['omniboxSuggestionOptions']);\n }\n _this.options = ComponentOptions_1.ComponentOptions.initComponentOptions(element, FieldSuggestions, options);\n Assert_1.Assert.check(Utils_1.Utils.isCoveoField(_this.options.field), _this.options.field + ' is not a valid field');\n _this.options.onSelect = _this.options.onSelect || _this.onRowSelection;\n var rowTemplate = function (toRender) {\n var rowElement = Dom_1.$$('div', {\n className: 'magic-box-suggestion coveo-omnibox-selectable coveo-top-field-suggestion-row'\n });\n if (toRender['data']) {\n rowElement.el.innerHTML = toRender['data'];\n }\n return rowElement.el.outerHTML;\n };\n var suggestionStructure;\n if (_this.options.headerTitle == null) {\n suggestionStructure = {\n row: rowTemplate\n };\n }\n else {\n var headerTemplate = function () {\n var headerElement = Dom_1.$$('div', {\n className: 'coveo-top-field-suggestion-header'\n });\n var iconElement = Dom_1.$$('span', {\n className: 'coveo-icon-top-field'\n });\n var captionElement = Dom_1.$$('span', {\n className: 'coveo-caption'\n });\n if (_this.options.headerTitle) {\n captionElement.text(_this.options.headerTitle);\n }\n headerElement.append(iconElement.el);\n headerElement.append(captionElement.el);\n return headerElement.el.outerHTML;\n };\n suggestionStructure = {\n header: { template: headerTemplate, title: _this.options.headerTitle },\n row: rowTemplate\n };\n }\n _this.suggestionForOmnibox = new SuggestionForOmnibox_1.SuggestionForOmnibox(suggestionStructure, function (value, args) {\n _this.options.onSelect.call(_this, value, args);\n }, function (value, args) {\n _this.onRowTab(value, args);\n });\n _this.bind.onRootElement(OmniboxEvents_1.OmniboxEvents.populateOmnibox, function (args) { return _this.handlePopulateOmnibox(args); });\n return _this;\n }\n /**\n * Selects a currently displayed query suggestion. This implies that at least one suggestion must have been returned\n * at least once.\n * @param suggestion Either a number (0-based index position of the query suggestion to select) or a string that\n * matches the suggestion to select.\n */\n FieldSuggestions.prototype.selectSuggestion = function (suggestion) {\n if (this.currentlyDisplayedSuggestions) {\n if (isNaN(suggestion)) {\n if (this.currentlyDisplayedSuggestions[suggestion]) {\n Dom_1.$$(this.currentlyDisplayedSuggestions[suggestion].element).trigger('click');\n }\n }\n else {\n var currentlySuggested = _.findWhere(this.currentlyDisplayedSuggestions, {\n pos: suggestion\n });\n if (currentlySuggested) {\n Dom_1.$$(currentlySuggested.element).trigger('click');\n }\n }\n }\n };\n FieldSuggestions.prototype.handlePopulateOmnibox = function (args) {\n var _this = this;\n Assert_1.Assert.exists(args);\n var valueToSearch = args.completeQueryExpression.word;\n var promise = new Promise(function (resolve) {\n _this.queryController\n .getEndpoint()\n .listFieldValues(_this.buildListFieldValueRequest(valueToSearch))\n .then(function (results) {\n var element = _this.suggestionForOmnibox.buildOmniboxElement(results, args);\n _this.currentlyDisplayedSuggestions = {};\n if (element) {\n _.map(Dom_1.$$(element).findAll('.coveo-omnibox-selectable'), function (selectable, i) {\n _this.currentlyDisplayedSuggestions[Dom_1.$$(selectable).text()] = {\n element: selectable,\n pos: i\n };\n });\n resolve({\n element: element,\n zIndex: _this.options.omniboxZIndex\n });\n }\n else {\n resolve({\n element: undefined\n });\n }\n })\n .catch(function () {\n resolve({\n element: undefined\n });\n });\n });\n args.rows.push({\n deferred: promise\n });\n };\n FieldSuggestions.prototype.onRowSelection = function (value, args) {\n args.closeOmnibox();\n this.queryStateModel.set(QueryStateModel_1.QueryStateModel.attributesEnum.q, value);\n this.usageAnalytics.logSearchEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.omniboxField, {});\n this.queryController.executeQuery();\n };\n FieldSuggestions.prototype.onRowTab = function (value, args) {\n args.clear();\n args.closeOmnibox();\n this.queryStateModel.set(QueryStateModel_1.QueryStateModel.attributesEnum.q, \"\" + value);\n this.usageAnalytics.logCustomEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.omniboxField, {}, this.element);\n };\n FieldSuggestions.prototype.buildListFieldValueRequest = function (valueToSearch) {\n return {\n field: this.options.field,\n ignoreAccents: true,\n sortCriteria: 'occurrences',\n maximumNumberOfValues: this.options.numberOfSuggestions,\n patternType: 'Wildcards',\n pattern: '*' + valueToSearch + '*',\n queryOverride: this.options.queryOverride\n };\n };\n FieldSuggestions.ID = 'FieldSuggestions';\n FieldSuggestions.doExport = function () {\n GlobalExports_1.exportGlobally({\n FieldSuggestions: FieldSuggestions\n });\n };\n /**\n * @componentOptions\n */\n FieldSuggestions.options = {\n /**\n * Specifies the facet field from which to provide suggestions.\n *\n * Specifying a value for this option is required for the `FieldSuggestions` component to work.\n */\n field: ComponentOptions_1.ComponentOptions.buildFieldOption({ required: true }),\n /**\n * Specifies a query override to apply when retrieving suggestions. You can use any valid query expression (see\n * [Coveo Query Syntax Reference](https://docs.coveo.com/en/1552/searching-with-coveo/coveo-cloud-query-syntax)).\n *\n * Default value is the empty string, and the component applies no query override.\n */\n queryOverride: ComponentOptions_1.ComponentOptions.buildQueryExpressionOption({ defaultValue: '' }),\n /**\n * Specifies the z-index position at which the suggestions render themselves in the [`Omnibox`]{@link Omnibox}.\n *\n * When there are multiple suggestion providers, components with higher `omniboxZIndex` values render themselves\n * first.\n *\n * Default value is `51`. Minimum value is `0`.\n */\n omniboxZIndex: ComponentOptions_1.ComponentOptions.buildNumberOption({ defaultValue: 51, min: 0 }),\n /**\n * Specifies the title of the result suggestions group in the [`Omnibox`]{@link Omnibox} component.\n * If not provided, the component will simply not output any title.\n *\n * Default value is `null`.\n */\n headerTitle: ComponentOptions_1.ComponentOptions.buildLocalizedStringOption(),\n /**\n * Specifies the number of suggestions to render in the [`Omnibox`]{@link Omnibox}.\n *\n * Default value is `5`. Minimum value is `1`.\n */\n numberOfSuggestions: ComponentOptions_1.ComponentOptions.buildNumberOption({ defaultValue: 5, min: 1 }),\n /**\n * Specifies the event handler function to execute when the end user selects a suggested value in the\n * [`Omnibox`]{@link Omnibox}. By default, the query box text is replaced by what the end user selected and a new\n * query is executed. You can, however, replace this default behavior by providing a callback function to execute\n * when the value is selected.\n *\n * **Note:**\n * > You cannot set this option directly in the component markup as an HTML attribute. You must either set it in the\n * > [`init`]{@link init} call of your search interface (see\n * > [Passing Component Options in the init Call](https://docs.coveo.com/en/346/#passing-component-options-in-the-init-call)),\n * > or before the `init` call, using the `options` top-level function (see\n * > [Passing Component Options Before the init Call](https://docs.coveo.com/en/346/#passing-component-options-before-the-init-call)).\n *\n * **Example:**\n *\n * ```javascript\n *\n * var myOnSelectFunction = function(selectedValue, populateOmniboxEventArgs) {\n *\n * // Close the suggestion list when the user clicks a suggestion.\n * populateOmniboxEventArgs.closeOmnibox();\n *\n * // Search for matching title results in the default endpoint.\n * Coveo.SearchEndpoint.endpoints[\"default\"].search({\n * q: \"@title==\" + selectedValue\n * }).done(function(results) {\n *\n * // If more than one result is found, select a result that matches the selected title.\n * var foundResult = Coveo._.find(results.results, function(result) {\n * return selectedValue == result.raw.title;\n * });\n *\n * // Open the found result in the current window, or log an error.\n * if (foundResult) {\n * window.location = foundResult.clickUri;\n * }\n * else {\n * new Coveo.Logger.warn(\"Selected suggested result '\" + selectedValue + \"' not found.\");\n * }\n * });\n * };\n *\n * // You can set the option in the 'init' call:\n * Coveo.init(document.querySelector(\"#search\"), {\n * FieldSuggestions : {\n * onSelect : myOnSelectFunction\n * }\n * });\n *\n * // Or before the 'init' call, using the 'options' top-level function:\n * // Coveo.options(document.querySelector(\"#search\"), {\n * // FieldSuggestions : {\n * // onSelect : myOnSelectFunction\n * // }\n * // });\n * ```\n */\n onSelect: ComponentOptions_1.ComponentOptions.buildCustomOption(function () {\n return null;\n })\n };\n return FieldSuggestions;\n}(Component_1.Component));\nexports.FieldSuggestions = FieldSuggestions;\nInitialization_1.Initialization.registerAutoCreateComponent(FieldSuggestions);\n\n\n/***/ }),\n\n/***/ 517:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar DomUtils_1 = __webpack_require__(95);\nvar Dom_1 = __webpack_require__(1);\nvar _ = __webpack_require__(0);\nvar SuggestionForOmnibox = /** @class */ (function () {\n function SuggestionForOmnibox(structure, onSelect, onTabPress) {\n this.structure = structure;\n this.onSelect = onSelect;\n this.onTabPress = onTabPress;\n }\n SuggestionForOmnibox.prototype.buildOmniboxElement = function (results, args) {\n var element;\n if (results.length != 0) {\n element = Dom_1.$$('div').el;\n if (this.structure.header) {\n var header = this.buildElementHeader();\n element.appendChild(header);\n }\n var rows = this.buildRowElements(results, args);\n _.each(rows, function (row) {\n element.appendChild(row);\n });\n }\n return element;\n };\n SuggestionForOmnibox.prototype.buildElementHeader = function () {\n return Dom_1.$$('div', undefined, this.structure.header.template({\n headerTitle: this.structure.header.title\n })).el;\n };\n SuggestionForOmnibox.prototype.buildRowElements = function (results, args) {\n var _this = this;\n var ret = [];\n _.each(results, function (result) {\n var row = Dom_1.$$('div', undefined, _this.structure.row({\n rawValue: result.value,\n data: DomUtils_1.DomUtils.highlightElement(result.value, args.completeQueryExpression.word)\n })).el;\n Dom_1.$$(row).on('click', function () {\n _this.onSelect.call(_this, result.value, args);\n });\n Dom_1.$$(row).on('keyboardSelect', function () {\n _this.onSelect.call(_this, result.value, args);\n });\n Dom_1.$$(row).on('tabSelect', function () {\n _this.onTabPress.call(_this, result.value, args);\n });\n ret.push(row);\n });\n return ret;\n };\n return SuggestionForOmnibox;\n}());\nexports.SuggestionForOmnibox = SuggestionForOmnibox;\n\n\n/***/ }),\n\n/***/ 518:\n/***/ (function(module, exports) {\n\n// removed by extract-text-webpack-plugin\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// FieldSuggestions.min__d957946aa95219e5e0e2.js","import 'styling/_FieldSuggestions';\nimport * as _ from 'underscore';\nimport { IPopulateOmniboxEventArgs, OmniboxEvents } from '../../events/OmniboxEvents';\nimport { exportGlobally } from '../../GlobalExports';\nimport { Assert } from '../../misc/Assert';\nimport { QueryStateModel } from '../../models/QueryStateModel';\nimport { IIndexFieldValue } from '../../rest/FieldValue';\nimport { IStringMap } from '../../rest/GenericParam';\nimport { IListFieldValuesRequest } from '../../rest/ListFieldValuesRequest';\nimport { $$ } from '../../utils/Dom';\nimport { Utils } from '../../utils/Utils';\nimport { analyticsActionCauseList, IAnalyticsNoMeta } from '../Analytics/AnalyticsActionListMeta';\nimport { Component } from '../Base/Component';\nimport { IComponentBindings } from '../Base/ComponentBindings';\nimport { ComponentOptions } from '../Base/ComponentOptions';\nimport { IFieldOption, IQueryExpression } from '../Base/IComponentOptions';\nimport { Initialization } from '../Base/Initialization';\nimport {\n ISuggestionForOmniboxOptions,\n ISuggestionForOmniboxOptionsOnSelect,\n ISuggestionForOmniboxTemplate,\n SuggestionForOmnibox\n} from '../Misc/SuggestionForOmnibox';\n\nexport interface IFieldSuggestionsOptions extends ISuggestionForOmniboxOptions {\n field?: IFieldOption;\n queryOverride?: IQueryExpression;\n}\n\n/**\n * The `FieldSuggestions` component provides query suggestions based on a particular facet field. For example, you could\n * use this component to provide auto-complete suggestions while the end user is typing the title of an item.\n *\n * The query suggestions provided by this component appear in the [`Omnibox`]{@link Omnibox} component.\n *\n * **Note:** Consider [providing Coveo ML query suggestions](https://docs.coveo.com/en/340/#providing-coveo-machine-learning-query-suggestions)\n * rather than field suggestions, as the former yields better performance and relevance.\n */\nexport class FieldSuggestions extends Component {\n static ID = 'FieldSuggestions';\n\n static doExport = () => {\n exportGlobally({\n FieldSuggestions: FieldSuggestions\n });\n };\n\n /**\n * @componentOptions\n */\n static options: IFieldSuggestionsOptions = {\n /**\n * Specifies the facet field from which to provide suggestions.\n *\n * Specifying a value for this option is required for the `FieldSuggestions` component to work.\n */\n field: ComponentOptions.buildFieldOption({ required: true }),\n\n /**\n * Specifies a query override to apply when retrieving suggestions. You can use any valid query expression (see\n * [Coveo Query Syntax Reference](https://docs.coveo.com/en/1552/searching-with-coveo/coveo-cloud-query-syntax)).\n *\n * Default value is the empty string, and the component applies no query override.\n */\n queryOverride: ComponentOptions.buildQueryExpressionOption({ defaultValue: '' }),\n\n /**\n * Specifies the z-index position at which the suggestions render themselves in the [`Omnibox`]{@link Omnibox}.\n *\n * When there are multiple suggestion providers, components with higher `omniboxZIndex` values render themselves\n * first.\n *\n * Default value is `51`. Minimum value is `0`.\n */\n omniboxZIndex: ComponentOptions.buildNumberOption({ defaultValue: 51, min: 0 }),\n\n /**\n * Specifies the title of the result suggestions group in the [`Omnibox`]{@link Omnibox} component.\n * If not provided, the component will simply not output any title.\n *\n * Default value is `null`.\n */\n headerTitle: ComponentOptions.buildLocalizedStringOption(),\n\n /**\n * Specifies the number of suggestions to render in the [`Omnibox`]{@link Omnibox}.\n *\n * Default value is `5`. Minimum value is `1`.\n */\n numberOfSuggestions: ComponentOptions.buildNumberOption({ defaultValue: 5, min: 1 }),\n\n /**\n * Specifies the event handler function to execute when the end user selects a suggested value in the\n * [`Omnibox`]{@link Omnibox}. By default, the query box text is replaced by what the end user selected and a new\n * query is executed. You can, however, replace this default behavior by providing a callback function to execute\n * when the value is selected.\n *\n * **Note:**\n * > You cannot set this option directly in the component markup as an HTML attribute. You must either set it in the\n * > [`init`]{@link init} call of your search interface (see\n * > [Passing Component Options in the init Call](https://docs.coveo.com/en/346/#passing-component-options-in-the-init-call)),\n * > or before the `init` call, using the `options` top-level function (see\n * > [Passing Component Options Before the init Call](https://docs.coveo.com/en/346/#passing-component-options-before-the-init-call)).\n *\n * **Example:**\n *\n * ```javascript\n *\n * var myOnSelectFunction = function(selectedValue, populateOmniboxEventArgs) {\n *\n * // Close the suggestion list when the user clicks a suggestion.\n * populateOmniboxEventArgs.closeOmnibox();\n *\n * // Search for matching title results in the default endpoint.\n * Coveo.SearchEndpoint.endpoints[\"default\"].search({\n * q: \"@title==\" + selectedValue\n * }).done(function(results) {\n *\n * // If more than one result is found, select a result that matches the selected title.\n * var foundResult = Coveo._.find(results.results, function(result) {\n * return selectedValue == result.raw.title;\n * });\n *\n * // Open the found result in the current window, or log an error.\n * if (foundResult) {\n * window.location = foundResult.clickUri;\n * }\n * else {\n * new Coveo.Logger.warn(\"Selected suggested result '\" + selectedValue + \"' not found.\");\n * }\n * });\n * };\n *\n * // You can set the option in the 'init' call:\n * Coveo.init(document.querySelector(\"#search\"), {\n * FieldSuggestions : {\n * onSelect : myOnSelectFunction\n * }\n * });\n *\n * // Or before the 'init' call, using the 'options' top-level function:\n * // Coveo.options(document.querySelector(\"#search\"), {\n * // FieldSuggestions : {\n * // onSelect : myOnSelectFunction\n * // }\n * // });\n * ```\n */\n onSelect: ComponentOptions.buildCustomOption(() => {\n return null;\n })\n };\n\n private suggestionForOmnibox: SuggestionForOmnibox;\n private currentlyDisplayedSuggestions: { [suggestion: string]: { element: HTMLElement; pos: number } };\n\n /**\n * Creates a new `FieldSuggestions` component.\n * @param element The HTMLElement on which to instantiate the component.\n * @param options The options for the `FieldSuggestions` component.\n * @param bindings The bindings that the component requires to function normally. If not set, these will be\n * automatically resolved (with a slower execution time).\n */\n constructor(element: HTMLElement, public options: IFieldSuggestionsOptions, bindings?: IComponentBindings) {\n super(element, FieldSuggestions.ID, bindings);\n\n if (this.options && 'omniboxSuggestionOptions' in this.options) {\n this.options = _.extend(this.options, this.options['omniboxSuggestionOptions']);\n }\n\n this.options = ComponentOptions.initComponentOptions(element, FieldSuggestions, options);\n\n Assert.check(Utils.isCoveoField(this.options.field), this.options.field + ' is not a valid field');\n\n this.options.onSelect = this.options.onSelect || this.onRowSelection;\n\n let rowTemplate = (toRender: IStringMap) => {\n let rowElement = $$('div', {\n className: 'magic-box-suggestion coveo-omnibox-selectable coveo-top-field-suggestion-row'\n });\n if (toRender['data']) {\n rowElement.el.innerHTML = toRender['data'];\n }\n return rowElement.el.outerHTML;\n };\n\n let suggestionStructure: ISuggestionForOmniboxTemplate;\n if (this.options.headerTitle == null) {\n suggestionStructure = {\n row: rowTemplate\n };\n } else {\n let headerTemplate = () => {\n let headerElement = $$('div', {\n className: 'coveo-top-field-suggestion-header'\n });\n\n let iconElement = $$('span', {\n className: 'coveo-icon-top-field'\n });\n\n let captionElement = $$('span', {\n className: 'coveo-caption'\n });\n\n if (this.options.headerTitle) {\n captionElement.text(this.options.headerTitle);\n }\n\n headerElement.append(iconElement.el);\n headerElement.append(captionElement.el);\n\n return headerElement.el.outerHTML;\n };\n\n suggestionStructure = {\n header: { template: headerTemplate, title: this.options.headerTitle },\n row: rowTemplate\n };\n }\n\n this.suggestionForOmnibox = new SuggestionForOmnibox(\n suggestionStructure,\n (value: string, args: IPopulateOmniboxEventArgs) => {\n this.options.onSelect.call(this, value, args);\n },\n (value: string, args: IPopulateOmniboxEventArgs) => {\n this.onRowTab(value, args);\n }\n );\n this.bind.onRootElement(OmniboxEvents.populateOmnibox, (args: IPopulateOmniboxEventArgs) => this.handlePopulateOmnibox(args));\n }\n\n public selectSuggestion(suggestion: number);\n public selectSuggestion(suggestion: string);\n\n /**\n * Selects a currently displayed query suggestion. This implies that at least one suggestion must have been returned\n * at least once.\n * @param suggestion Either a number (0-based index position of the query suggestion to select) or a string that\n * matches the suggestion to select.\n */\n public selectSuggestion(suggestion: any) {\n if (this.currentlyDisplayedSuggestions) {\n if (isNaN(suggestion)) {\n if (this.currentlyDisplayedSuggestions[suggestion]) {\n $$(this.currentlyDisplayedSuggestions[suggestion].element).trigger('click');\n }\n } else {\n let currentlySuggested = <{ element: HTMLElement; pos: number }>_.findWhere(this.currentlyDisplayedSuggestions, {\n pos: suggestion\n });\n if (currentlySuggested) {\n $$(currentlySuggested.element).trigger('click');\n }\n }\n }\n }\n\n private handlePopulateOmnibox(args: IPopulateOmniboxEventArgs) {\n Assert.exists(args);\n\n let valueToSearch = args.completeQueryExpression.word;\n let promise = new Promise(resolve => {\n this.queryController\n .getEndpoint()\n .listFieldValues(this.buildListFieldValueRequest(valueToSearch))\n .then((results: IIndexFieldValue[]) => {\n let element = this.suggestionForOmnibox.buildOmniboxElement(results, args);\n this.currentlyDisplayedSuggestions = {};\n if (element) {\n _.map($$(element).findAll('.coveo-omnibox-selectable'), (selectable, i?) => {\n this.currentlyDisplayedSuggestions[$$(selectable).text()] = {\n element: selectable,\n pos: i\n };\n });\n resolve({\n element: element,\n zIndex: this.options.omniboxZIndex\n });\n } else {\n resolve({\n element: undefined\n });\n }\n })\n .catch(() => {\n resolve({\n element: undefined\n });\n });\n });\n args.rows.push({\n deferred: promise\n });\n }\n\n private onRowSelection(value: string, args: IPopulateOmniboxEventArgs) {\n args.closeOmnibox();\n this.queryStateModel.set(QueryStateModel.attributesEnum.q, value);\n this.usageAnalytics.logSearchEvent(analyticsActionCauseList.omniboxField, {});\n this.queryController.executeQuery();\n }\n\n private onRowTab(value: string, args: IPopulateOmniboxEventArgs) {\n args.clear();\n args.closeOmnibox();\n this.queryStateModel.set(QueryStateModel.attributesEnum.q, `${value}`);\n this.usageAnalytics.logCustomEvent(analyticsActionCauseList.omniboxField, {}, this.element);\n }\n\n private buildListFieldValueRequest(valueToSearch: string): IListFieldValuesRequest {\n return {\n field: this.options.field,\n ignoreAccents: true,\n sortCriteria: 'occurrences',\n maximumNumberOfValues: this.options.numberOfSuggestions,\n patternType: 'Wildcards',\n pattern: '*' + valueToSearch + '*',\n queryOverride: this.options.queryOverride\n };\n }\n}\n\nInitialization.registerAutoCreateComponent(FieldSuggestions);\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/FieldSuggestions/FieldSuggestions.ts","import { IPopulateOmniboxEventArgs } from '../../events/OmniboxEvents';\nimport { DomUtils } from '../../utils/DomUtils';\nimport { $$ } from '../../utils/Dom';\nimport * as _ from 'underscore';\n\nexport interface ISuggestionForOmniboxOptionsOnSelect {\n (value: string, args: IPopulateOmniboxEventArgs): void;\n}\n\nexport interface ISuggestionForOmniboxOptions {\n omniboxZIndex?: number;\n headerTitle?: string;\n onSelect?: ISuggestionForOmniboxOptionsOnSelect;\n numberOfSuggestions?: number;\n}\n\nexport interface ISuggestionForOmniboxTemplate {\n header?: {\n template: (...args: any[]) => string;\n title: string;\n };\n row: (...args: any[]) => string;\n}\n\nexport interface ISuggestionForOmniboxResult {\n value: string;\n}\n\nexport class SuggestionForOmnibox {\n constructor(\n public structure: ISuggestionForOmniboxTemplate,\n public onSelect: (value: string, args: IPopulateOmniboxEventArgs) => void,\n public onTabPress: (value: string, args: IPopulateOmniboxEventArgs) => void\n ) {}\n\n public buildOmniboxElement(results: ISuggestionForOmniboxResult[], args: IPopulateOmniboxEventArgs): HTMLElement {\n let element: HTMLElement;\n if (results.length != 0) {\n element = $$('div').el;\n if (this.structure.header) {\n let header = this.buildElementHeader();\n element.appendChild(header);\n }\n let rows = this.buildRowElements(results, args);\n _.each(rows, row => {\n element.appendChild(row);\n });\n }\n return element;\n }\n\n private buildElementHeader(): HTMLElement {\n return $$(\n 'div',\n undefined,\n this.structure.header.template({\n headerTitle: this.structure.header.title\n })\n ).el;\n }\n\n private buildRowElements(results: ISuggestionForOmniboxResult[], args: IPopulateOmniboxEventArgs): HTMLElement[] {\n let ret = [];\n _.each(results, result => {\n let row = $$(\n 'div',\n undefined,\n this.structure.row({\n rawValue: result.value,\n data: DomUtils.highlightElement(result.value, args.completeQueryExpression.word)\n })\n ).el;\n $$(row).on('click', () => {\n this.onSelect.call(this, result.value, args);\n });\n $$(row).on('keyboardSelect', () => {\n this.onSelect.call(this, result.value, args);\n });\n $$(row).on('tabSelect', () => {\n this.onTabPress.call(this, result.value, args);\n });\n ret.push(row);\n });\n return ret;\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/Misc/SuggestionForOmnibox.ts"],"sourceRoot":""}