{"version":3,"names":["searchBoxElements","dispatchSearchBoxSuggestionsEvent","event","element","dispatchEvent","buildCustomEvent","closest","join","Error","nodeName","toLowerCase","elementHasNoQuery","el","query","elementHasQuery"],"sources":["src/components/search/search-box-suggestions/suggestions-common.ts"],"sourcesContent":["import {SearchBox} from '@coveo/headless';\nimport {VNode} from '@stencil/core';\nimport {buildCustomEvent} from '../../../utils/event-utils';\nimport {closest} from '../../../utils/utils';\nimport {Bindings} from '../atomic-search-interface/atomic-search-interface';\n\n/**\n * Element which will be rendered in the list of suggestions.\n */\nexport interface SearchBoxSuggestionElement {\n  /**\n   * Stable identity which enables Stencil to reuse DOM elements for better performance.\n   * The best way to pick a key is to use a string that uniquely identifies that list item among its siblings (often your data will already have IDs).\n   */\n  key: string;\n  /**\n   * Rendered content of the element.\n   */\n  content: Element | VNode;\n  /**\n   * Hook called when the selection is selected.\n   * @param e DOM event.\n   */\n  onSelect?(e: Event): void;\n  /**\n   * The query associated with the suggestion which will replace the query in the search box if the suggestion is selected.\n   */\n  query?: string;\n  /**\n   * For improved accessibility, provide this property with additional information.\n   * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label\n   */\n  ariaLabel?: string;\n  /**\n   * Adds a specific shadow part attribute that can be selected with the CSS ::part pseudo-element.\n   * https://developer.mozilla.org/en-US/docs/Web/CSS/::part\n   */\n  part?: string;\n  /**\n   * Hide the suggestion if it's the last in the list.\n   */\n  hideIfLast?: boolean;\n}\n\n/**\n * List of suggestions that will be displayed along other lists (e.g recent queries) when the search box's input is selected.\n */\nexport interface SearchBoxSuggestions {\n  /**\n   * The search box will sort the position of suggestions using this value. The lowest value being first.\n   * By default, the DOM position will be used.\n   */\n  position: number;\n  /**\n   * Whether the suggestions should be listed in the right or left panel. By default, the suggestions are listed in the right panel.\n   */\n  panel?: 'left' | 'right';\n  /**\n   * Method that returns the list of elements which will be rendered in the list of suggestions.\n   */\n  renderItems(): SearchBoxSuggestionElement[];\n  /**\n   * Hook called when the user changes the search box's input value. This can lead to all the query suggestions being updated.\n   */\n  onInput?(): Promise<unknown> | void;\n  /**\n   * Hook called when the suggested query changes as a user traverses through the list of suggestions.\n   * This is used for instant results, which are rendered based on the current suggested query.\n   * @param q The new suggested query.\n   */\n  onSuggestedQueryChange?(q: string): Promise<unknown> | void;\n}\n\n/**\n * Event sent from the registered query suggestions to the parent search box.\n */\nexport type SearchBoxSuggestionsEvent = (\n  /**\n   * The bindings passed from the search box to the suggestions.\n   */\n  bindings: SearchBoxSuggestionsBindings\n) => SearchBoxSuggestions;\n\nconst searchBoxElements = ['atomic-search-box', 'atomic-insight-search-box'];\n\n/**\n * The bindings passed from the search box to the suggestions.\n */\nexport interface SearchBoxSuggestionsBindings extends Bindings {\n  /**\n   * The unique id of the search box.\n   */\n  id: string;\n  /**\n   * Whether the search box is [standalone](https://docs.coveo.com/en/atomic/latest/usage/ssb/).\n   */\n  isStandalone: boolean;\n  /**\n   * The [search box headless controller](https://docs.coveo.com/en/headless/latest/reference/search/controllers/search-box/).\n   */\n  searchBoxController: SearchBox;\n  /**\n   * The amount of queries displayed when the user interacts with the search box, property set on the [Atomic Search box](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-search-box/#properties).\n   */\n  numberOfQueries: number;\n  /**\n   * Whether to clear all active query filters when the end user submits a new query from the search box.\n   */\n  clearFilters: boolean;\n  /**\n   * Retrieves the suggested query, meaning the query that would be sent if the search is executed.\n   * The suggested query changes as a user traverses through the list of suggestions.\n   */\n  suggestedQuery(): string;\n  /**\n   * Removes the current suggestions.\n   */\n  clearSuggestions(): void;\n  /**\n   * Triggers update & retrieval of all suggestions.\n   */\n  triggerSuggestions(): void;\n  /**\n   * Retrieves the current suggestions.\n   */\n  getSuggestions(): SearchBoxSuggestions[];\n  /**\n   * Retrieves the current suggestions elements.\n   */\n  getSuggestionElements(): SearchBoxSuggestionElement[];\n}\n\n/**\n * Dispatches an event which retrieves the `SearchBoxSuggestionsBindings` on a configured parent search box.\n * @param event Event sent from the registered query suggestions to the parent search box.\n * @param element Element on which to dispatch the event, which must be the child of a configured search box.\n */\nexport const dispatchSearchBoxSuggestionsEvent = (\n  event: SearchBoxSuggestionsEvent,\n  element: HTMLElement\n) => {\n  element.dispatchEvent(\n    buildCustomEvent('atomic/searchBoxSuggestion/register', event)\n  );\n\n  if (!closest(element, searchBoxElements.join(', '))) {\n    throw new Error(\n      `The \"${element.nodeName.toLowerCase()}\" component was not handled, as it is not a child of the following elements: ${searchBoxElements.join(\n        ', '\n      )}`\n    );\n  }\n};\n\nexport function elementHasNoQuery(el: SearchBoxSuggestionElement) {\n  return !el.query;\n}\n\nexport function elementHasQuery(el: SearchBoxSuggestionElement) {\n  return !!el.query;\n}\n"],"mappings":"wEAmFA,MAAMA,EAAoB,CAAC,oBAAqB,6B,MAsDnCC,EAAoC,CAC/CC,EACAC,KAEAA,EAAQC,cACNC,EAAiB,sCAAuCH,IAG1D,IAAKI,EAAQH,EAASH,EAAkBO,KAAK,OAAQ,CACnD,MAAM,IAAIC,MACR,QAAQL,EAAQM,SAASC,6FAA6FV,EAAkBO,KACtI,Q,YAMQI,EAAkBC,GAChC,OAAQA,EAAGC,KACb,C,SAEgBC,EAAgBF,GAC9B,QAASA,EAAGC,KACd,Q"}