@coveo/atomic 3.33.8-pre.bfb642d322 → 3.33.8-pre.c44c9ff482

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/atomic/_atomic.esm.js +1 -1
  2. package/dist/atomic/components/_index.js +2 -1
  3. package/dist/atomic/components/analytics-config.js +1 -1
  4. package/dist/atomic/components/atomic-insight-search-box.js +3 -4
  5. package/dist/atomic/components/atomic-insight-search-box.js.map +1 -1
  6. package/dist/atomic/components/atomic-search-box-instant-results.js +2 -2
  7. package/dist/atomic/components/atomic-search-box-instant-results.js.map +1 -1
  8. package/dist/atomic/components/atomic-search-box-query-suggestions2.js +2 -2
  9. package/dist/atomic/components/atomic-search-box-query-suggestions2.js.map +1 -1
  10. package/dist/atomic/components/atomic-search-box-recent-queries2.js +2 -2
  11. package/dist/atomic/components/atomic-search-box-recent-queries2.js.map +1 -1
  12. package/dist/atomic/components/atomic-search-box.js +5 -6
  13. package/dist/atomic/components/atomic-search-box.js.map +1 -1
  14. package/dist/atomic/components/atomic-suggestion-renderer2.js +1 -1
  15. package/dist/atomic/components/atomic-suggestion-renderer2.js.map +1 -1
  16. package/dist/atomic/components/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.js +1 -1
  17. package/dist/atomic/components/components/commerce/atomic-commerce-search-box-instant-products/atomic-commerce-search-box-instant-products.js +1 -1
  18. package/dist/atomic/components/components/commerce/atomic-commerce-search-box-query-suggestions/atomic-commerce-search-box-query-suggestions.js +1 -1
  19. package/dist/atomic/components/components/commerce/atomic-commerce-search-box-recent-queries/atomic-commerce-search-box-recent-queries.js +1 -1
  20. package/dist/atomic/components/components/common/suggestions/suggestion-manager.js +1 -1
  21. package/dist/atomic/components/components/common/suggestions/{suggestions-common.js → suggestions-events.js} +16 -18
  22. package/dist/atomic/components/components/common/suggestions/suggestions-types.js +1 -0
  23. package/dist/atomic/components/components/common/suggestions/suggestions-utils.js +18 -0
  24. package/dist/atomic/components/global/environment.js +1 -1
  25. package/dist/atomic/components/index.js.map +1 -1
  26. package/dist/atomic/components/stencil-query-suggestions.js.map +1 -1
  27. package/dist/atomic/components/stencil-suggestion-manager.js +20 -2
  28. package/dist/atomic/components/stencil-suggestion-manager.js.map +1 -1
  29. package/dist/atomic/components/{suggestions-common.js → suggestions-events.js} +18 -20
  30. package/dist/atomic/components/suggestions-events.js.map +1 -0
  31. package/dist/atomic/index.esm.js +1 -1
  32. package/dist/atomic/index.esm.js.map +1 -1
  33. package/dist/atomic/p-0a051b8d.js +2 -0
  34. package/dist/atomic/p-0a051b8d.js.map +1 -0
  35. package/dist/atomic/p-16f4ce98.js +2 -0
  36. package/dist/atomic/p-16f4ce98.js.map +1 -0
  37. package/dist/atomic/{p-a09b4db4.entry.js → p-1bc8e637.entry.js} +2 -2
  38. package/dist/atomic/{p-8867af82.entry.js → p-26a51a77.entry.js} +2 -2
  39. package/dist/atomic/p-26a51a77.entry.js.map +1 -0
  40. package/dist/atomic/{p-c1bf43cf.entry.js → p-31f1e44e.entry.js} +2 -2
  41. package/dist/atomic/p-31f1e44e.entry.js.map +1 -0
  42. package/dist/atomic/{p-94b5f495.js → p-3eb7c413.js} +2 -2
  43. package/dist/atomic/p-4b7a19db.js +2 -0
  44. package/dist/atomic/p-4b7a19db.js.map +1 -0
  45. package/dist/atomic/{p-aa8e0616.entry.js → p-92ae95f6.entry.js} +2 -2
  46. package/dist/atomic/p-af93b44c.js.map +1 -1
  47. package/dist/atomic/{p-3d847e45.entry.js → p-c88a3d2d.entry.js} +2 -2
  48. package/dist/atomic/p-c88a3d2d.entry.js.map +1 -0
  49. package/dist/atomic/{p-83e20cc3.entry.js → p-cf741356.entry.js} +2 -2
  50. package/dist/atomic/{p-36e71b99.entry.js → p-d0f47b33.entry.js} +2 -2
  51. package/dist/atomic/p-d0f47b33.entry.js.map +1 -0
  52. package/dist/atomic/{p-aa4224ea.entry.js → p-fbfe913d.entry.js} +2 -2
  53. package/dist/atomic/p-fbfe913d.entry.js.map +1 -0
  54. package/dist/cjs/_index.cjs.js +5 -2
  55. package/dist/cjs/{analytics-config-b8fab215.js → analytics-config-b9ddf8f2.js} +2 -2
  56. package/dist/cjs/{analytics-config-b8fab215.js.map → analytics-config-b9ddf8f2.js.map} +1 -1
  57. package/dist/cjs/atomic-insight-interface.cjs.entry.js +1 -1
  58. package/dist/cjs/atomic-insight-search-box.cjs.entry.js +5 -5
  59. package/dist/cjs/atomic-insight-search-box.cjs.entry.js.map +1 -1
  60. package/dist/cjs/atomic-recs-interface.cjs.entry.js +1 -1
  61. package/dist/cjs/atomic-search-box-instant-results.cjs.entry.js +3 -3
  62. package/dist/cjs/atomic-search-box-instant-results.cjs.entry.js.map +1 -1
  63. package/dist/cjs/atomic-search-box-query-suggestions_2.cjs.entry.js +5 -5
  64. package/dist/cjs/atomic-search-box-query-suggestions_2.cjs.entry.js.map +1 -1
  65. package/dist/cjs/atomic-search-box.cjs.entry.js +7 -7
  66. package/dist/cjs/atomic-search-box.cjs.entry.js.map +1 -1
  67. package/dist/cjs/atomic-search-interface.cjs.entry.js +1 -1
  68. package/dist/cjs/atomic-suggestion-renderer.cjs.entry.js +1 -1
  69. package/dist/cjs/atomic-suggestion-renderer.cjs.entry.js.map +1 -1
  70. package/dist/cjs/index.cjs.js.map +1 -1
  71. package/dist/cjs/stencil-query-suggestions-03268ecc.js.map +1 -1
  72. package/dist/cjs/{stencil-suggestion-manager-c0878ef2.js → stencil-suggestion-manager-2cba6d69.js} +4 -4
  73. package/dist/cjs/{stencil-suggestion-manager-c0878ef2.js.map → stencil-suggestion-manager-2cba6d69.js.map} +1 -1
  74. package/dist/cjs/{suggestions-common-5097a362.js → suggestions-events-63dd0640.js} +17 -21
  75. package/dist/cjs/suggestions-events-63dd0640.js.map +1 -0
  76. package/dist/cjs/suggestions-utils-61000808.js +25 -0
  77. package/dist/cjs/suggestions-utils-61000808.js.map +1 -0
  78. package/dist/cjs/version.cjs.js +2 -2
  79. package/dist/esm/_index.js +2 -1
  80. package/dist/esm/{analytics-config-d0c5b639.js → analytics-config-f8efa4f7.js} +2 -2
  81. package/dist/esm/{analytics-config-d0c5b639.js.map → analytics-config-f8efa4f7.js.map} +1 -1
  82. package/dist/esm/atomic-insight-interface.entry.js +1 -1
  83. package/dist/esm/atomic-insight-search-box.entry.js +4 -4
  84. package/dist/esm/atomic-insight-search-box.entry.js.map +1 -1
  85. package/dist/esm/atomic-recs-interface.entry.js +1 -1
  86. package/dist/esm/atomic-search-box-instant-results.entry.js +2 -2
  87. package/dist/esm/atomic-search-box-instant-results.entry.js.map +1 -1
  88. package/dist/esm/atomic-search-box-query-suggestions_2.entry.js +3 -3
  89. package/dist/esm/atomic-search-box-query-suggestions_2.entry.js.map +1 -1
  90. package/dist/esm/atomic-search-box.entry.js +6 -6
  91. package/dist/esm/atomic-search-box.entry.js.map +1 -1
  92. package/dist/esm/atomic-search-interface.entry.js +1 -1
  93. package/dist/esm/atomic-suggestion-renderer.entry.js +1 -1
  94. package/dist/esm/atomic-suggestion-renderer.entry.js.map +1 -1
  95. package/dist/esm/index.js.map +1 -1
  96. package/dist/esm/stencil-query-suggestions-5d6a46d7.js.map +1 -1
  97. package/dist/esm/{stencil-suggestion-manager-486094dd.js → stencil-suggestion-manager-376f83e8.js} +2 -2
  98. package/dist/esm/{stencil-suggestion-manager-486094dd.js.map → stencil-suggestion-manager-376f83e8.js.map} +1 -1
  99. package/dist/esm/{suggestions-common-2b20db26.js → suggestions-events-b7a6f007.js} +18 -20
  100. package/dist/esm/suggestions-events-b7a6f007.js.map +1 -0
  101. package/dist/esm/suggestions-utils-591559a0.js +22 -0
  102. package/dist/esm/suggestions-utils-591559a0.js.map +1 -0
  103. package/dist/esm/version.js +2 -2
  104. package/dist/types/components/commerce/atomic-commerce-search-box-instant-products/atomic-commerce-search-box-instant-products.d.ts +1 -1
  105. package/dist/types/components/commerce/atomic-commerce-search-box-query-suggestions/atomic-commerce-search-box-query-suggestions.d.ts +1 -1
  106. package/dist/types/components/commerce/atomic-commerce-search-box-recent-queries/atomic-commerce-search-box-recent-queries.d.ts +1 -1
  107. package/dist/types/components/common/atomic-suggestion-renderer/atomic-suggestion-renderer.d.ts +1 -1
  108. package/dist/types/components/common/suggestions/instant-item.d.ts +1 -1
  109. package/dist/types/components/common/suggestions/query-suggestions.d.ts +1 -1
  110. package/dist/types/components/common/suggestions/recent-queries.d.ts +1 -1
  111. package/dist/types/components/common/suggestions/stencil-instant-item.d.ts +1 -1
  112. package/dist/types/components/common/suggestions/stencil-query-suggestions.d.ts +1 -1
  113. package/dist/types/components/common/suggestions/stencil-recent-queries.d.ts +1 -1
  114. package/dist/types/components/common/suggestions/stencil-suggestion-manager.d.ts +1 -1
  115. package/dist/types/components/common/suggestions/suggestion-manager.d.ts +1 -1
  116. package/dist/types/components/common/suggestions/suggestions-events.d.ts +14 -0
  117. package/dist/types/components/common/suggestions/{suggestions-common.d.ts → suggestions-types.d.ts} +6 -16
  118. package/dist/types/components/common/suggestions/suggestions-utils.d.ts +15 -0
  119. package/dist/types/components/search/atomic-search-box/atomic-search-box.d.ts +1 -1
  120. package/dist/types/components/search/search-box-suggestions/atomic-search-box-instant-results/atomic-search-box-instant-results.d.ts +1 -1
  121. package/dist/types/components.d.ts +2 -2
  122. package/dist/types/decorators/types.d.ts +1 -1
  123. package/dist/types/index.d.ts +3 -1
  124. package/docs/atomic-docs.json +3 -3
  125. package/package.json +4 -4
  126. package/dist/atomic/components/suggestions-common.js.map +0 -1
  127. package/dist/atomic/p-29fd6768.js +0 -2
  128. package/dist/atomic/p-29fd6768.js.map +0 -1
  129. package/dist/atomic/p-36e71b99.entry.js.map +0 -1
  130. package/dist/atomic/p-3d847e45.entry.js.map +0 -1
  131. package/dist/atomic/p-7601c3de.js +0 -2
  132. package/dist/atomic/p-7601c3de.js.map +0 -1
  133. package/dist/atomic/p-8867af82.entry.js.map +0 -1
  134. package/dist/atomic/p-aa4224ea.entry.js.map +0 -1
  135. package/dist/atomic/p-c1bf43cf.entry.js.map +0 -1
  136. package/dist/cjs/suggestions-common-5097a362.js.map +0 -1
  137. package/dist/esm/suggestions-common-2b20db26.js.map +0 -1
  138. /package/dist/atomic/{p-a09b4db4.entry.js.map → p-1bc8e637.entry.js.map} +0 -0
  139. /package/dist/atomic/{p-94b5f495.js.map → p-3eb7c413.js.map} +0 -0
  140. /package/dist/atomic/{p-aa8e0616.entry.js.map → p-92ae95f6.entry.js.map} +0 -0
  141. /package/dist/atomic/{p-83e20cc3.entry.js.map → p-cf741356.entry.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"names":["searchBoxElements","isLitElementLoosely","candidate","updateComplete","Promise","dispatchSearchBoxSuggestionsEventEventually","async","interfaceElement","element","event","customElements","whenDefined","nodeName","toLowerCase","componentOnReady","dispatchEvent","buildCustomEvent","dispatchSearchBoxSuggestionsEvent","allowedSearchBoxElements","closest","join","Error","elementHasNoQuery","el","query","trim","elementHasQuery"],"sources":["src/components/common/suggestions/suggestions-common.ts"],"sourcesContent":["import type {VNode} from '@stencil/core';\nimport type {HTMLStencilElement} from '@stencil/core/internal';\nimport type {LitElement} from 'lit';\nimport {closest} from '../../../utils/dom-utils';\nimport {buildCustomEvent} from '../../../utils/event-utils';\nimport type {AnyBindings} from '../interface/bindings';\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 * @remarks\n * The `VNode` type will be deprecated in v4 as we are detaching from Stencil.\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>;\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>;\n}\n\n/**\n * Event sent from the registered query suggestions to the parent search box.\n */\nexport type SearchBoxSuggestionsEvent<\n SearchBoxController,\n Bindings = AnyBindings,\n> = (\n /**\n * The bindings passed from the search box to the suggestions.\n */\n bindings: SearchBoxSuggestionsBindings<SearchBoxController, Bindings>\n) => SearchBoxSuggestions;\n\nconst searchBoxElements = [\n 'atomic-search-box',\n 'atomic-insight-search-box',\n 'atomic-commerce-search-box',\n] as const;\n\n/**\n * The bindings passed from the search box to the suggestions.\n */\nexport type SearchBoxSuggestionsBindings<\n SearchBoxController,\n Bindings = AnyBindings,\n> = 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.\n */\n searchBoxController: SearchBoxController;\n /**\n * The number of queries to display when the user interacts with the search box.\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\nconst isLitElementLoosely = (candidate: unknown): candidate is LitElement =>\n 'updateComplete' in (candidate as LitElement) &&\n (candidate as LitElement).updateComplete instanceof Promise;\n\nconst dispatchSearchBoxSuggestionsEventEventually = async <\n SearchBoxController,\n Bindings = AnyBindings,\n>(\n interfaceElement: Element,\n element: HTMLElement,\n event: SearchBoxSuggestionsEvent<SearchBoxController, Bindings>\n) => {\n await customElements.whenDefined(interfaceElement.nodeName.toLowerCase());\n if (isLitElementLoosely(interfaceElement)) {\n await interfaceElement.updateComplete;\n } else if ('componentOnReady' in interfaceElement) {\n await (interfaceElement as HTMLStencilElement).componentOnReady();\n }\n element.dispatchEvent(\n buildCustomEvent('atomic/searchBoxSuggestion/register', event)\n );\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 SearchBoxController,\n Bindings = AnyBindings,\n>(\n event: SearchBoxSuggestionsEvent<SearchBoxController, Bindings>,\n element: HTMLElement,\n allowedSearchBoxElements: readonly (typeof searchBoxElements)[number][] = searchBoxElements\n) => {\n const interfaceElement = closest(element, searchBoxElements.join(', '));\n if (!interfaceElement) {\n throw new Error(\n `The \"${element.nodeName.toLowerCase()}\" component was not handled, as it is not a child of the following elements: ${allowedSearchBoxElements.join(\n ', '\n )}`\n );\n }\n void dispatchSearchBoxSuggestionsEventEventually(\n interfaceElement,\n element,\n event\n );\n};\n\nexport function elementHasNoQuery(el: SearchBoxSuggestionElement) {\n return !el.query || el.query.trim() === '';\n}\n\nexport function elementHasQuery(el: SearchBoxSuggestionElement) {\n return !!el.query && el.query.trim() !== '';\n}\n"],"mappings":"wEA0FA,MAAMA,EAAoB,CACxB,oBACA,4BACA,8BAqDF,MAAMC,EAAuBC,GAC3B,mBAAqBA,GACpBA,EAAyBC,0BAA0BC,QAEtD,MAAMC,EAA8CC,MAIlDC,EACAC,EACAC,WAEMC,eAAeC,YAAYJ,EAAiBK,SAASC,eAC3D,GAAIZ,EAAoBM,GAAmB,OACnCA,EAAiBJ,c,MAClB,GAAI,qBAAsBI,EAAkB,OAC1CA,EAAwCO,kB,CAEjDN,EAAQO,cACNC,EAAiB,sCAAuCP,GACzD,E,MAQUQ,EAAoC,CAI/CR,EACAD,EACAU,EAA0ElB,KAE1E,MAAMO,EAAmBY,EAAQX,EAASR,EAAkBoB,KAAK,OACjE,IAAKb,EAAkB,CACrB,MAAM,IAAIc,MACR,QAAQb,EAAQI,SAASC,6FAA6FK,EAAyBE,KAC7I,Q,MAIDf,EACHE,EACAC,EACAC,EACD,E,SAGaa,EAAkBC,GAChC,OAAQA,EAAGC,OAASD,EAAGC,MAAMC,SAAW,EAC1C,C,SAEgBC,EAAgBH,GAC9B,QAASA,EAAGC,OAASD,EAAGC,MAAMC,SAAW,EAC3C,Q","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["atomicInsightSearchBoxCss","AtomicInsightSearchBoxStyle0","AtomicInsightSearchBox","this","isExpanded","disableSearch","numberOfSuggestions","initialize","id","randomID","searchBoxOptions","highlightOptions","notMatchDelimiters","open","close","correctionDelimiters","fetchQuerySuggestions","registerQuerySuggest","loadInsightSearchActions","bindings","engine","searchBox","buildInsightSearchBox","options","dispatch","count","suggestionManager","SuggestionManager","getNumberOfSuggestionsToDisplay","updateQuery","query","updateText","getSearchBoxValue","searchBoxState","value","getSuggestionTimeout","getSuggestionDelay","getHost","host","getLogger","logger","registerSuggestions","position","renderItems","state","suggestions","map","suggestion","renderSuggestionItem","onInput","panel","onSubmit","activeDescendantElement","clickOnActiveElement","submit","clearSuggestions","onKeyDown","e","key","preventDefault","focusNextValue","announceNewActiveSuggestionToScreenReader","focusPreviousValue","triggerTextAreaChange","textAreaRef","dispatchEvent","window","Event","renderSuggestion","item","index","lastIndex","isSelected","activeDescendant","suggestedQuery","hideIfLast","h","i18n","side","isDoubleList","onClick","onSuggestionClick","onMouseOver","onSuggestionMouseOver","hasQuery","partialItem","getPartialSearchBoxSuggestionElement","content","QuerySuggestionContainer","QuerySuggestionIcon","icon","SearchSlimIcon","hasSuggestion","length","QuerySuggestionText","onSelect","selectSuggestion","rawValue","renderPanel","elements","setRef","getRef","part","ref","class","onMouseDown","target","renderSuggestions","hasSuggestions","updateActiveDescendant","role","t","allSuggestionElements","el","leftPanel","getSearchInputLabel","isMacOS","hasKeyboard","onFocus","triggerSuggestions","announceNewSuggestionsToScreenReader","ariaLabel","suggestionsAriaMessage","numberOfSuggestionsToAnnounce","filter","elementHasQuery","searchBoxAriaMessage","render","SearchBoxWrapper","disabled","onFocusout","event","isFocusingOut","SearchTextArea","loading","isLoading","placeholder","onClear","clear","__decorate","InitializeBindings","BindStateToController","AriaLiveRegion"],"sources":["src/components/insight/atomic-insight-search-box/atomic-insight-search-box.pcss?tag=atomic-insight-search-box&encapsulation=shadow","src/components/insight/atomic-insight-search-box/atomic-insight-search-box.tsx"],"sourcesContent":["@import '../../../global/global.pcss';\n@import '../../common/search-box/search-box.pcss';\n\n[part='wrapper'] {\n @apply z-10;\n}\n\n:host {\n position: relative;\n}\n\n[part='input'] {\n padding-top: 0.675rem;\n padding-bottom: 0.675rem;\n}\n\n[part='submit-icon'] {\n @apply text-on-background;\n}\n\n[part='submit-button'] {\n @apply flex w-10 items-center justify-center;\n}\n\n.loading::after {\n content: '';\n @apply bg-background absolute h-5/6 w-5/6 rounded-full;\n}\n\n[part='clear-button-wrapper'] {\n @apply mr-2 py-0;\n}\n\n[part='clear-icon'] {\n @apply h-3 w-3;\n}\n\n[part='textarea-expander'] {\n &::after {\n @apply p-2 px-4;\n }\n}\n\n[part='textarea-expander'] {\n [part='textarea'] {\n @apply p-2 px-4;\n }\n}\n","import {loadInsightSearchActions} from '@coveo/headless/insight';\nimport {\n buildSearchBox as buildInsightSearchBox,\n SearchBox as InsightSearchBox,\n SearchBoxState as InsightSearchBoxState,\n Suggestion as InsightSuggestion,\n} from '@coveo/headless/insight';\nimport {Component, Element, h, Prop, State} from '@stencil/core';\nimport SearchSlimIcon from '../../../images/search-slim.svg';\nimport {hasKeyboard, isMacOS} from '../../../utils/device-utils';\nimport {\n BindStateToController,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {AriaLiveRegion} from '../../../utils/stencil-accessibility-utils';\nimport {isFocusingOut, randomID} from '../../../utils/utils';\nimport {SearchBoxWrapper} from '../../common/search-box/stencil-search-box-wrapper';\nimport {SearchTextArea} from '../../common/search-box/stencil-search-text-area';\nimport {\n getPartialSearchBoxSuggestionElement,\n QuerySuggestionContainer,\n QuerySuggestionIcon,\n QuerySuggestionText,\n} from '../../common/suggestions/stencil-query-suggestions';\nimport {SuggestionManager} from '../../common/suggestions/stencil-suggestion-manager';\nimport {\n elementHasQuery,\n SearchBoxSuggestionElement,\n} from '../../common/suggestions/suggestions-common';\nimport {InsightBindings} from '../atomic-insight-interface/atomic-insight-interface';\n\n/**\n * @internal\n */\n@Component({\n tag: 'atomic-insight-search-box',\n styleUrl: 'atomic-insight-search-box.pcss',\n shadow: true,\n})\nexport class AtomicInsightSearchBox {\n @InitializeBindings() public bindings!: InsightBindings;\n\n private searchBox!: InsightSearchBox;\n private id!: string;\n private textAreaRef!: HTMLTextAreaElement;\n private suggestionManager!: SuggestionManager<InsightSearchBox>;\n\n @Element() private host!: HTMLElement;\n\n @BindStateToController('searchBox')\n @State()\n private searchBoxState!: InsightSearchBoxState;\n @State() public error!: Error;\n @State() private isExpanded = false;\n\n /**\n * Whether to prevent the user from triggering a search from the component.\n * Perfect for use cases where you need to disable the search conditionally, like when the input is empty.\n */\n @Prop({reflect: true}) public disableSearch = false;\n /**\n * The number of query suggestions to display when interacting with the search box.\n */\n @Prop({reflect: true}) public numberOfSuggestions = 5;\n\n @AriaLiveRegion('search-box')\n protected searchBoxAriaMessage!: string;\n\n @AriaLiveRegion('search-suggestions', true)\n protected suggestionsAriaMessage!: string;\n\n public initialize() {\n this.id = randomID('atomic-search-box-');\n\n const searchBoxOptions = {\n id: this.id,\n numberOfSuggestions: 0,\n highlightOptions: {\n notMatchDelimiters: {\n open: '<span class=\"font-bold\">',\n close: '</span>',\n },\n correctionDelimiters: {\n open: '<span class=\"font-normal\">',\n close: '</span>',\n },\n },\n };\n\n const {fetchQuerySuggestions, registerQuerySuggest} =\n loadInsightSearchActions(this.bindings.engine);\n\n this.searchBox = buildInsightSearchBox(this.bindings.engine, {\n options: searchBoxOptions,\n });\n\n this.bindings.engine.dispatch(\n registerQuerySuggest({id: this.id, count: this.numberOfSuggestions})\n );\n\n this.suggestionManager = new SuggestionManager({\n getNumberOfSuggestionsToDisplay: () => this.numberOfSuggestions,\n updateQuery: (query) => this.searchBox.updateText(query),\n getSearchBoxValue: () => this.searchBoxState.value,\n getSuggestionTimeout: () => 500,\n getSuggestionDelay: () => 0,\n getHost: () => this.host,\n getLogger: () => this.bindings.engine.logger,\n });\n\n this.suggestionManager.registerSuggestions({\n position: 0,\n renderItems: () =>\n this.searchBox.state.suggestions.map((suggestion) =>\n this.renderSuggestionItem(suggestion)\n ),\n onInput: () => this.bindings.engine.dispatch(fetchQuerySuggestions({id: this.id})),\n panel: 'left',\n });\n }\n\n private onSubmit() {\n if (this.suggestionManager.activeDescendantElement) {\n this.suggestionManager.clickOnActiveElement();\n return;\n }\n\n this.searchBox.submit();\n this.suggestionManager.clearSuggestions();\n }\n\n private async onKeyDown(e: KeyboardEvent) {\n if (this.disableSearch) {\n return;\n }\n\n switch (e.key) {\n case 'Enter':\n this.onSubmit();\n break;\n case 'Escape':\n this.suggestionManager.clearSuggestions();\n break;\n case 'ArrowDown':\n e.preventDefault();\n await this.suggestionManager.focusNextValue();\n this.announceNewActiveSuggestionToScreenReader();\n break;\n case 'ArrowUp':\n e.preventDefault();\n await this.suggestionManager.focusPreviousValue();\n this.announceNewActiveSuggestionToScreenReader();\n break;\n case 'Tab':\n this.suggestionManager.clearSuggestions();\n break;\n }\n }\n\n private triggerTextAreaChange(value: string) {\n this.textAreaRef.value = value;\n this.textAreaRef.dispatchEvent(new window.Event('change'));\n }\n\n private renderSuggestion(\n item: SearchBoxSuggestionElement,\n index: number,\n lastIndex: number\n ) {\n const id = `${this.id}-suggestion-${item.key}`;\n\n const isSelected =\n id === this.suggestionManager.activeDescendant ||\n this.suggestionManager.suggestedQuery === item.query;\n\n if (index === lastIndex && item.hideIfLast) {\n return null;\n }\n\n return (\n <atomic-suggestion-renderer\n i18n={this.bindings.i18n}\n id={id}\n suggestion={item}\n isSelected={isSelected}\n side={'left'}\n index={index}\n lastIndex={lastIndex}\n isDoubleList={false}\n onClick={(e: Event) => {\n this.suggestionManager.onSuggestionClick(item, e);\n }}\n onMouseOver={() => {\n this.suggestionManager.onSuggestionMouseOver(item, 'left', id);\n }}\n ></atomic-suggestion-renderer>\n );\n }\n\n private renderSuggestionItem(\n suggestion: InsightSuggestion\n ): SearchBoxSuggestionElement {\n const hasQuery = this.searchBox.state.value !== '';\n const partialItem = getPartialSearchBoxSuggestionElement(\n suggestion,\n this.bindings.i18n\n );\n\n return {\n ...partialItem,\n content: (\n <QuerySuggestionContainer>\n <QuerySuggestionIcon\n icon={SearchSlimIcon}\n hasSuggestion={this.searchBoxState.suggestions.length > 1}\n />\n\n <QuerySuggestionText suggestion={suggestion} hasQuery={hasQuery} />\n </QuerySuggestionContainer>\n ),\n onSelect: () => {\n this.searchBox.selectSuggestion(suggestion.rawValue);\n },\n };\n }\n\n private renderPanel(\n elements: SearchBoxSuggestionElement[],\n setRef: (el: HTMLElement | undefined) => void,\n getRef: () => HTMLElement | undefined\n ) {\n if (!elements.length) {\n return null;\n }\n\n return (\n <div\n part={'suggestions'}\n ref={setRef}\n class=\"flex grow basis-1/2 flex-col\"\n onMouseDown={(e) => {\n if (e.target === getRef()) {\n e.preventDefault();\n }\n }}\n >\n {elements.map((suggestion, index) =>\n this.renderSuggestion(suggestion, index, elements.length - 1)\n )}\n </div>\n );\n }\n\n private renderSuggestions() {\n if (!this.suggestionManager.hasSuggestions) {\n this.suggestionManager.updateActiveDescendant();\n return null;\n }\n\n return (\n <div\n id={`${this.id}-popup`}\n part=\"suggestions-wrapper\"\n class={`bg-background border-neutral absolute top-full left-0 z-10 flex w-full rounded-md border ${\n this.suggestionManager.hasSuggestions && this.isExpanded\n ? ''\n : 'hidden'\n }`}\n role=\"application\"\n aria-label={this.bindings.i18n.t('search-suggestions-single-list')}\n {...(this.suggestionManager.activeDescendant && {\n 'aria-activedescendant': this.suggestionManager.activeDescendant,\n })}\n >\n {this.renderPanel(\n this.suggestionManager.allSuggestionElements,\n (el) => (this.suggestionManager.leftPanel = el),\n () => this.suggestionManager.leftPanel\n )}\n </div>\n );\n }\n\n private getSearchInputLabel() {\n if (isMacOS()) {\n return this.bindings.i18n.t('search-box-with-suggestions-macos');\n }\n if (!hasKeyboard()) {\n return this.bindings.i18n.t('search-box-with-suggestions-keyboardless');\n }\n return this.bindings.i18n.t('search-box-with-suggestions');\n }\n\n private async onFocus() {\n if (this.isExpanded) {\n return;\n }\n this.isExpanded = true;\n await this.suggestionManager.triggerSuggestions();\n this.announceNewSuggestionsToScreenReader();\n }\n\n private async onInput(value: string) {\n this.searchBox.updateText(value);\n this.isExpanded = true;\n await this.suggestionManager.triggerSuggestions();\n this.announceNewSuggestionsToScreenReader();\n }\n\n private announceNewActiveSuggestionToScreenReader() {\n const ariaLabel = this.suggestionManager.activeDescendantElement?.ariaLabel;\n if (isMacOS() && ariaLabel) {\n this.suggestionsAriaMessage = ariaLabel;\n }\n }\n\n private announceNewSuggestionsToScreenReader() {\n const numberOfSuggestionsToAnnounce =\n this.suggestionManager.allSuggestionElements.filter(\n elementHasQuery\n ).length;\n this.searchBoxAriaMessage = numberOfSuggestionsToAnnounce\n ? this.bindings.i18n.t(\n this.searchBoxState.value\n ? 'query-suggestions-available'\n : 'query-suggestions-available-no-query',\n {\n count: numberOfSuggestionsToAnnounce,\n query: this.searchBoxState.value,\n }\n )\n : this.bindings.i18n.t('query-suggestions-unavailable');\n }\n\n public render() {\n return (\n <SearchBoxWrapper\n disabled={this.disableSearch}\n onFocusout={(event) => {\n if (!isFocusingOut(event)) {\n return;\n }\n this.suggestionManager.clearSuggestions();\n this.isExpanded = false;\n }}\n >\n <atomic-icon\n part=\"submit-icon\"\n icon={SearchSlimIcon}\n class=\"my-auto mr-0 ml-4 h-4 w-4\"\n />\n <SearchTextArea\n textAreaRef={this.textAreaRef}\n loading={this.searchBoxState.isLoading}\n ref={(el) => el && (this.textAreaRef = el)}\n bindings={this.bindings}\n value={this.searchBoxState.value}\n ariaLabel={this.getSearchInputLabel()}\n placeholder={this.bindings.i18n.t('search-ellipsis')}\n onFocus={() => this.onFocus()}\n onKeyDown={(e) => this.onKeyDown(e)}\n onClear={() => {\n this.searchBox.clear();\n this.triggerTextAreaChange('');\n }}\n onInput={(e) => this.onInput((e.target as HTMLInputElement).value)}\n />\n {this.renderSuggestions()}\n </SearchBoxWrapper>\n );\n }\n}\n"],"mappings":"ysBAAA,MAAMA,EAA4B,smpEAClC,MAAAC,EAAeD,E,iXCsCFE,EAAsB,M,yBAchBC,KAAAC,WAAa,MAMAD,KAAAE,cAAgB,MAIhBF,KAAAG,oBAAsB,E,mEAVtB,M,mBAMgB,M,yBAIM,C,CAQ7C,UAAAC,GACLJ,KAAKK,GAAKC,EAAS,sBAEnB,MAAMC,EAAmB,CACvBF,GAAIL,KAAKK,GACTF,oBAAqB,EACr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le","itemUniqueId","ariaLabel","t","title","interpolation","escapeValue","key","encodeForDomAttribute","part","getPartialInstantItemShowAllElement","InstantItemShowAllButton","h","class","getClassNameForButtonStyle","AtomicSearchBoxInstantResults","this","results","display","templateHasError","maxResultsPerQuery","density","imageSize","setRenderFunction","resultRenderingFunction","itemRenderingFunction","componentWillLoad","dispatchSearchBoxSuggestionsEvent","bindings","initialize","host","error","getLink","el","atomicResult","tagName","querySelector","shadowRoot","handleLinkClick","hasModifier","setTarget","value","setAttribute","initialTarget","getAttribute","click","renderItems","suggestedQuery","store","isMobile","instantResults","state","length","elements","map","result","partialItem","ariaLabelGenerator","uniqueId","content","interactiveResult","buildInteractiveInstantResult","engine","options","itemTemplateProvider","getTemplateContent","stopPropagation","renderingFunction","onSelect","e","link","target","ctrlKey","metaKey","push","clearSuggestions","searchBoxController","updateText","q","submit","buildInstantResults","ItemTemplateProvider","includeDefaultTemplate","templateElements","Array","from","querySelectorAll","getResultTemplateRegistered","setResultTemplateRegistered","getTemplateHasError","setTemplateHasError","position","parentNode","children","indexOf","panel","onSuggestedQueryChange","updateQuery","getSuggestionElements","console","warn","Promise","resolve","unsubscribe","subscribe","isLoading","render","element"],"sources":["src/components/common/suggestions/stencil-instant-item.tsx","src/components/search/search-box-suggestions/atomic-search-box-instant-results/atomic-search-box-instant-results.tsx"],"sourcesContent":["import {FunctionalComponent, h} from '@stencil/core';\nimport {i18n} from 'i18next';\nimport {encodeForDomAttribute} from '../../../utils/string-utils';\nimport {getClassNameForButtonStyle} from '../stencil-button-style';\nimport {SearchBoxSuggestionElement} from './suggestions-common';\n\nexport const getPartialInstantItemElement = (\n i18n: i18n,\n itemTitle: string,\n itemUniqueId: string\n): Pick<SearchBoxSuggestionElement, 'ariaLabel' | 'key' | 'part'> => {\n return {\n ariaLabel: i18n.t('instant-results-suggestion-label', {\n title: itemTitle,\n interpolation: {escapeValue: false},\n }),\n key: `instant-result-${encodeForDomAttribute(itemUniqueId)}`,\n part: 'instant-results-item',\n };\n};\n\nexport const getPartialInstantItemShowAllElement = (\n i18n: i18n\n): Pick<SearchBoxSuggestionElement, 'key' | 'part' | 'ariaLabel'> => {\n return {\n key: 'instant-results-show-all-button',\n part: 'instant-results-show-all',\n ariaLabel: i18n.t('show-all-results'),\n };\n};\n\ninterface InstantItemShowAllButtonProps {\n i18n: i18n;\n}\nexport const InstantItemShowAllButton: FunctionalComponent<\n InstantItemShowAllButtonProps\n> = ({i18n}) => {\n return (\n <div\n part=\"instant-results-show-all-button\"\n class={getClassNameForButtonStyle('text-primary')}\n >\n {i18n.t('show-all-results')}\n </div>\n );\n};\n","import {\n buildInstantResults,\n buildInteractiveInstantResult,\n InstantResults,\n Result,\n SearchBox,\n} from '@coveo/headless';\nimport {Component, Element, State, h, Prop, Method} from '@stencil/core';\nimport {InitializableComponent} from '../../../../utils/initialization-utils';\nimport {encodeForDomAttribute} from '../../../../utils/string-utils';\nimport {ItemTemplateProvider} from '../../../common/item-list/item-template-provider';\nimport {ItemRenderingFunction} from '../../../common/item-list/stencil-item-list-common';\nimport {\n ItemDisplayDensity,\n ItemDisplayImageSize,\n ItemDisplayLayout,\n} from '../../../common/layout/display-options';\nimport {\n getPartialInstantItemElement,\n getPartialInstantItemShowAllElement,\n InstantItemShowAllButton,\n} from '../../../common/suggestions/stencil-instant-item';\nimport {\n dispatchSearchBoxSuggestionsEvent,\n SearchBoxSuggestionElement,\n SearchBoxSuggestions,\n SearchBoxSuggestionsBindings,\n} from '../../../common/suggestions/suggestions-common';\nimport {Bindings} from '../../atomic-search-interface/atomic-search-interface';\n\nexport type AriaLabelGenerator = (\n bindings: Bindings,\n result: Result\n) => string | undefined;\n\n/**\n * The `atomic-search-box-instant-results` component can be added as a child of an `atomic-search-box` component, allowing for the configuration of instant results behavior.\n *\n * This component does not support accessibility out-of-the-box. To do so, see [Instant Results Accessibility](https://docs.coveo.com/en/atomic/latest/usage/accessibility/#instant-results-accessibility).\n *\n * This component is not supported on mobile.\n *\n * @slot default - The default slot where the instant results are rendered.\n */\n@Component({\n tag: 'atomic-search-box-instant-results',\n shadow: true,\n})\nexport class AtomicSearchBoxInstantResults implements InitializableComponent {\n public bindings!: SearchBoxSuggestionsBindings<SearchBox, Bindings>;\n private itemRenderingFunction: ItemRenderingFunction;\n private results: Result[] = [];\n private itemTemplateProvider!: ItemTemplateProvider;\n private instantResults!: InstantResults;\n private display: ItemDisplayLayout = 'list';\n\n @Element() public host!: HTMLElement;\n\n @State() public error!: Error;\n @State() private templateHasError = false;\n\n /**\n * Sets a rendering function to bypass the standard HTML template mechanism for rendering results.\n * You can use this function while working with web frameworks that don't use plain HTML syntax, e.g., React, Angular or Vue.\n *\n * Do not use this method if you integrate Atomic in a plain HTML deployment.\n *\n * @param resultRenderingFunction\n */\n @Method() public async setRenderFunction(\n resultRenderingFunction: ItemRenderingFunction\n ) {\n this.itemRenderingFunction = resultRenderingFunction;\n }\n /**\n * The maximum number of results to show.\n */\n @Prop({reflect: true}) public maxResultsPerQuery = 4;\n /**\n * The spacing of various elements in the result list, including the gap between results, the gap between parts of a result, and the font sizes of different parts in a result.\n */\n @Prop({reflect: true}) public density: ItemDisplayDensity = 'normal';\n /**\n * The expected size of the image displayed in the results.\n */\n @Prop({reflect: true}) public imageSize: ItemDisplayImageSize = 'icon';\n /**\n * The callback to generate an [`aria-label`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label) for a given result so that accessibility tools can fully describe what's visually rendered by a result.\n *\n * By default, or if an empty string is returned, `result.title` is used.\n */\n @Prop() public ariaLabelGenerator?: AriaLabelGenerator;\n\n public componentWillLoad() {\n try {\n dispatchSearchBoxSuggestionsEvent<SearchBox, Bindings>(\n (bindings) => {\n this.bindings = bindings;\n return this.initialize();\n },\n this.host,\n ['atomic-search-box']\n );\n } catch (error) {\n this.error = error as Error;\n }\n }\n\n private getLink(el: HTMLElement): HTMLElement | null {\n const atomicResult =\n el.tagName === 'ATOMIC-RESULT' ? el : el?.querySelector('atomic-result');\n\n return (\n atomicResult?.shadowRoot?.querySelector(\n 'atomic-result-link a:not([slot])'\n ) || null\n );\n }\n\n private handleLinkClick(el: HTMLElement, hasModifier: boolean) {\n const setTarget = (value: string) => el.setAttribute('target', value);\n const initialTarget = el.getAttribute('target');\n\n hasModifier && setTarget('_blank');\n el.click();\n hasModifier && setTarget(initialTarget || '');\n\n return true;\n }\n\n private renderItems(): SearchBoxSuggestionElement[] {\n if (!this.bindings.suggestedQuery() || this.bindings.store.isMobile()) {\n return [];\n }\n const results = this.instantResults.state.results.length\n ? this.instantResults.state.results\n : this.results;\n\n const elements: SearchBoxSuggestionElement[] = results.map(\n (result: Result) => {\n const partialItem = getPartialInstantItemElement(\n this.bindings.i18n,\n this.ariaLabelGenerator?.(this.bindings, result) || result.title,\n result.uniqueId\n );\n return {\n ...partialItem,\n content: (\n <atomic-result\n key={`instant-result-${encodeForDomAttribute(result.uniqueId)}`}\n part=\"outline\"\n result={result}\n interactiveResult={buildInteractiveInstantResult(\n this.bindings.engine,\n {\n options: {result},\n }\n )}\n display={this.display}\n density={this.density}\n imageSize={this.imageSize}\n content={this.itemTemplateProvider.getTemplateContent(result)}\n stopPropagation={false}\n renderingFunction={this.itemRenderingFunction}\n ></atomic-result>\n ),\n onSelect: (e: MouseEvent) => {\n const link = this.getLink(e.target as HTMLElement);\n\n if (!link) {\n return;\n }\n this.handleLinkClick(link, e.ctrlKey || e.metaKey);\n },\n };\n }\n );\n if (elements.length) {\n const partialItem = getPartialInstantItemShowAllElement(\n this.bindings.i18n\n );\n elements.push({\n ...partialItem,\n content: <InstantItemShowAllButton i18n={this.bindings.i18n} />,\n onSelect: () => {\n this.bindings.clearSuggestions();\n this.bindings.searchBoxController.updateText(\n this.instantResults.state.q\n );\n this.bindings.searchBoxController.submit();\n },\n });\n }\n return elements;\n }\n\n public initialize(): SearchBoxSuggestions {\n this.instantResults = buildInstantResults(this.bindings.engine, {\n options: {\n maxResultsPerQuery: this.maxResultsPerQuery,\n },\n });\n\n this.itemTemplateProvider = new ItemTemplateProvider({\n includeDefaultTemplate: true,\n templateElements: Array.from(\n this.host.querySelectorAll('atomic-result-template')\n ),\n getResultTemplateRegistered: () => true,\n setResultTemplateRegistered: () => {},\n getTemplateHasError: () => this.templateHasError,\n setTemplateHasError: (value: boolean) => {\n this.templateHasError = value;\n },\n bindings: this.bindings,\n });\n\n return {\n position: Array.from(this.host.parentNode!.children).indexOf(this.host),\n panel: 'right',\n onSuggestedQueryChange: (q) => {\n this.instantResults.updateQuery(q);\n return this.onSuggestedQueryChange();\n },\n renderItems: () => this.renderItems(),\n };\n }\n\n private onSuggestedQueryChange() {\n if (\n !this.bindings.getSuggestionElements().length &&\n !this.bindings.searchBoxController.state.value\n ) {\n console.warn(\n \"There doesn't seem to be any query suggestions configured. Make sure to include either an atomic-search-box-query-suggestions or atomic-search-box-recent-queries in your search box in order to see some instant results.\"\n );\n }\n\n return new Promise<void>((resolve) => {\n const unsubscribe = this.instantResults.subscribe(() => {\n const state = this.instantResults.state;\n if (!state.isLoading) {\n if (state.results.length) {\n this.results = state.results;\n }\n unsubscribe();\n resolve();\n }\n });\n });\n }\n\n public render() {\n if (this.error) {\n return (\n <atomic-component-error\n element={this.host}\n error={this.error}\n ></atomic-component-error>\n );\n }\n }\n}\n"],"mappings":"sUAMO,MAAMA,EAA+B,CAC1CC,EACAC,EACAC,KAEO,CACLC,UAAWH,EAAKI,EAAE,mCAAoC,CACpDC,MAAOJ,EACPK,cAAe,CAACC,YAAa,SAE/BC,IAAK,kBAAkBC,EAAsBP,KAC7CQ,KAAM,yBAIH,MAAMC,EACXX,IAEO,CACLQ,IAAK,kCACLE,KAAM,2BACNP,UAAWH,EAAKI,EAAE,sBAOf,MAAMQ,EAET,EAAEZ,UAEFa,EAAA,OACEH,KAAK,kCACLI,MAAOC,EAA2B,iBAEjCf,EAAKI,EAAE,qB,MCMDY,EAA6B,M,yBAGhCC,KAAAC,QAAoB,GAGpBD,KAAAE,QAA6B,OAKpBF,KAAAG,iBAAmB,MA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MAAMV,MACzC,CACA0D,QAAQC,KACN,6N,CAIJ,OAAO,IAAIC,SAAeC,IACxB,MAAMC,EAAcvF,KAAKkC,eAAesD,WAAU,KAChD,MAAMrD,EAAQnC,KAAKkC,eAAeC,MAClC,IAAKA,EAAMsD,UAAW,CACpB,GAAItD,EAAMlC,QAAQmC,OAAQ,CACxBpC,KAAKC,QAAUkC,EAAMlC,O,CAEvBsF,IACAD,G,IAEF,G,CAIC,MAAAI,GACL,GAAI1F,KAAKe,MAAO,CACd,OACEnB,EAAA,0BAAAL,IAAA,2CACEoG,QAAS3F,KAAKc,KACdC,MAAOf,KAAKe,O","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["AtomicSearchBoxQuerySuggestions","componentWillLoad","dispatchSearchBoxSuggestionsEvent","bindings","this","initialize","host","error","engine","registerQuerySuggest","fetchQuerySuggestions","loadQuerySuggestActions","dispatch","id","count","numberOfQueries","position","Array","from","parentNode","children","indexOf","onInput","renderItems","hasQuery","searchBoxController","state","value","max","maxWithQuery","maxWithoutQuery","suggestions","slice","map","suggestion","renderItem","partialItem","getPartialSearchBoxSuggestionElement","i18n","content","h","QuerySuggestionContainer","QuerySuggestionIcon","icon","SearchIcon","hasSuggestion","getSuggestions","length","QuerySuggestionText","onSelect","selectSuggestion","rawValue","render","key","element","getPartialRecentQueryElement","part","query","encodeForDomAttribute","ariaLabel","t","interpolation","escapeValue","getPartialRecentQueryClearElement","hideIfLast","RecentQueriesContainer","_","class","RecentQueryIcon","RecentQueryText","innerHTML","HighlightUtils","highlightString","openingDelimiter","closingDelimiter","highlights","offset","RecentQueryClear","AtomicSearchBoxRecentQueries","warnUser","once","logger","warn","renderIcon","Clock","storage","SafeStorage","recentQueriesList","buildRecentQueriesList","initialState","queries","retrieveLocalStorage","options","maxLength","clearFilters","subscribe","updateLocalStorage","getParsedJSON","StorageItems","RECENT_QUERIES","analyticsEnabled","disableFeature","setJSON","removeItem","filteredQueries","filter","recentQuery","toLowerCase","startsWith","suggestionElements","unshift","renderClear","clear","triggerSuggestions","isStandalone","updateText","submit","executeRecentQuery"],"sources":["src/components/search/search-box-suggestions/atomic-search-box-query-suggestions/atomic-search-box-query-suggestions.tsx","src/components/common/suggestions/stencil-recent-queries.tsx","src/components/search/search-box-suggestions/atomic-search-box-recent-queries/atomic-search-box-recent-queries.tsx"],"sourcesContent":["import {\n loadQuerySuggestActions,\n SearchBox,\n SearchEngine,\n Suggestion,\n} from '@coveo/headless';\nimport {Component, Element, Prop, State, h} from '@stencil/core';\nimport SearchIcon from '../../../../images/search.svg';\nimport {\n getPartialSearchBoxSuggestionElement,\n QuerySuggestionContainer,\n QuerySuggestionIcon,\n QuerySuggestionText,\n} from '../../../common/suggestions/stencil-query-suggestions';\nimport {\n dispatchSearchBoxSuggestionsEvent,\n SearchBoxSuggestionElement,\n SearchBoxSuggestions,\n SearchBoxSuggestionsBindings,\n} from '../../../common/suggestions/suggestions-common';\n\n/**\n * The `atomic-search-box-query-suggestions` component can be added as a child of an `atomic-search-box` component, allowing for the configuration of query suggestion behavior.\n */\n@Component({\n tag: 'atomic-search-box-query-suggestions',\n shadow: true,\n})\nexport class AtomicSearchBoxQuerySuggestions {\n private bindings!: SearchBoxSuggestionsBindings<SearchBox>;\n @Element() private host!: HTMLElement;\n\n @State() public error!: Error;\n\n /**\n * The SVG icon to display.\n *\n * - Use a value that starts with `http://`, `https://`, `./`, or `../`, to fetch and display an icon from a given location.\n * - Use a value that starts with `assets://`, to display an icon from the Atomic package.\n * - Use a stringified SVG to display it directly.\n */\n @Prop() public icon?: string;\n\n /**\n * The maximum number of suggestions that will be displayed if the user has typed something into the input field.\n */\n @Prop({reflect: true}) public maxWithQuery?: number;\n /**\n * The maximum number of suggestions that will be displayed initially when the input field is empty.\n */\n @Prop({reflect: true}) public maxWithoutQuery?: number;\n\n componentWillLoad() {\n try {\n dispatchSearchBoxSuggestionsEvent<SearchBox>(\n (bindings) => {\n this.bindings = bindings;\n return this.initialize();\n },\n this.host,\n ['atomic-search-box']\n );\n } catch (error) {\n this.error = error as Error;\n }\n }\n\n private initialize(): SearchBoxSuggestions {\n const engine = this.bindings.engine as SearchEngine<{\n querySet: string;\n querySuggest: string;\n }>;\n const {registerQuerySuggest, fetchQuerySuggestions} =\n loadQuerySuggestActions(engine);\n\n engine.dispatch(\n registerQuerySuggest({\n id: this.bindings.id,\n count: this.bindings.numberOfQueries,\n })\n );\n\n return {\n position: Array.from(this.host.parentNode!.children).indexOf(this.host),\n onInput: () =>\n engine.dispatch(\n fetchQuerySuggestions({\n id: this.bindings.id,\n })\n ),\n renderItems: () => this.renderItems(),\n };\n }\n\n private renderItems(): SearchBoxSuggestionElement[] {\n const hasQuery = this.bindings.searchBoxController.state.value !== '';\n const max = hasQuery ? this.maxWithQuery : this.maxWithoutQuery;\n return this.bindings.searchBoxController.state.suggestions\n .slice(0, max)\n .map((suggestion) => this.renderItem(suggestion));\n }\n\n private renderItem(suggestion: Suggestion) {\n const hasQuery = this.bindings.searchBoxController.state.value !== '';\n const partialItem = getPartialSearchBoxSuggestionElement(\n suggestion,\n this.bindings.i18n\n );\n\n return {\n ...partialItem,\n content: (\n <QuerySuggestionContainer>\n <QuerySuggestionIcon\n icon={this.icon || SearchIcon}\n hasSuggestion={this.bindings.getSuggestions().length > 1}\n />\n\n <QuerySuggestionText suggestion={suggestion} hasQuery={hasQuery} />\n </QuerySuggestionContainer>\n ),\n onSelect: () => {\n this.bindings.searchBoxController.selectSuggestion(suggestion.rawValue);\n },\n };\n }\n\n public render() {\n if (this.error) {\n return (\n <atomic-component-error\n element={this.host}\n error={this.error}\n ></atomic-component-error>\n );\n }\n }\n}\n","import {HighlightUtils} from '@coveo/headless';\nimport {FunctionalComponent, h} from '@stencil/core';\nimport {i18n} from 'i18next';\nimport {encodeForDomAttribute} from '../../../utils/string-utils';\nimport {SearchBoxSuggestionElement} from './suggestions-common';\n\nexport const getPartialRecentQueryElement = (\n value: string,\n i18n: i18n\n): Pick<SearchBoxSuggestionElement, 'ariaLabel' | 'key' | 'query' | 'part'> => {\n return {\n part: 'recent-query-item',\n query: value,\n key: `recent-${encodeForDomAttribute(value)}`,\n ariaLabel: i18n.t('recent-query-suggestion-label', {\n query: value,\n interpolation: {escapeValue: false},\n }),\n };\n};\n\nexport const getPartialRecentQueryClearElement = (\n i18n: i18n\n): Pick<\n SearchBoxSuggestionElement,\n 'ariaLabel' | 'key' | 'part' | 'hideIfLast'\n> => {\n return {\n key: 'recent-query-clear',\n ariaLabel: i18n.t('clear-recent-searches', {\n interpolation: {escapeValue: false},\n }),\n part: 'recent-query-title-item suggestion-divider',\n hideIfLast: true,\n };\n};\n\nexport const RecentQueriesContainer: FunctionalComponent = (_, children) => {\n return (\n <div\n part=\"recent-query-content\"\n class=\"flex items-center text-left break-all\"\n >\n {children}\n </div>\n );\n};\n\ninterface RecentQueryIconProps {\n icon: string;\n}\n\nexport const RecentQueryIcon: FunctionalComponent<RecentQueryIconProps> = ({\n icon,\n}) => {\n return (\n <atomic-icon\n part=\"recent-query-icon\"\n icon={icon}\n class=\"mr-2 h-4 w-4 shrink-0\"\n ></atomic-icon>\n );\n};\n\ninterface RecentQueryTextProps {\n query: string;\n value: string;\n}\n\nexport const RecentQueryText: FunctionalComponent<RecentQueryTextProps> = ({\n query,\n value,\n}) => {\n if (query === '') {\n return (\n <span part=\"recent-query-text\" class=\"line-clamp-2 break-all\">\n {value}\n </span>\n );\n }\n return (\n <span\n part=\"recent-query-text\"\n class=\"line-clamp-2 break-all\"\n innerHTML={HighlightUtils.highlightString({\n content: value,\n openingDelimiter:\n '<span part=\"recent-query-text-highlight\" class=\"font-bold\">',\n closingDelimiter: '</span>',\n highlights: [\n {\n offset: query.length,\n length: value.length - query.length,\n },\n ],\n })}\n ></span>\n );\n};\n\ninterface RecentQueryClearProps {\n i18n: i18n;\n}\n\nexport const RecentQueryClear: FunctionalComponent<RecentQueryClearProps> = ({\n i18n,\n}) => {\n return (\n <div part=\"recent-query-title-content\" class=\"flex w-full justify-between\">\n <span class=\"font-bold\" part=\"recent-query-title\">\n {i18n.t('recent-searches')}\n </span>\n <span part=\"recent-query-clear\">{i18n.t('clear')}</span>\n </div>\n );\n};\n","import {\n buildRecentQueriesList,\n RecentQueriesList,\n SearchBox,\n} from '@coveo/headless';\nimport {Component, Element, Prop, State, h} from '@stencil/core';\nimport Clock from '../../../../images/clock.svg';\nimport {SafeStorage, StorageItems} from '../../../../utils/local-storage-utils';\nimport {once} from '../../../../utils/utils';\nimport {\n getPartialRecentQueryClearElement,\n getPartialRecentQueryElement,\n RecentQueriesContainer,\n RecentQueryClear,\n RecentQueryIcon,\n RecentQueryText,\n} from '../../../common/suggestions/stencil-recent-queries';\nimport {\n dispatchSearchBoxSuggestionsEvent,\n SearchBoxSuggestionElement,\n SearchBoxSuggestions,\n SearchBoxSuggestionsBindings,\n} from '../../../common/suggestions/suggestions-common';\nimport {Bindings} from '../../atomic-search-interface/atomic-search-interface';\n\n/**\n * The `atomic-search-box-recent-queries` component can be added as a child of an `atomic-search-box` component, allowing for the configuration of recent query suggestions.\n */\n@Component({\n tag: 'atomic-search-box-recent-queries',\n shadow: true,\n})\nexport class AtomicSearchBoxRecentQueries {\n private bindings!: SearchBoxSuggestionsBindings<SearchBox, Bindings>;\n private recentQueriesList!: RecentQueriesList;\n private storage!: SafeStorage;\n\n @Element() private host!: HTMLElement;\n\n @State() public error!: Error;\n\n /**\n * The SVG icon to display.\n *\n * - Use a value that starts with `http://`, `https://`, `./`, or `../`, to fetch and display an icon from a given location.\n * - Use a value that starts with `assets://`, to display an icon from the Atomic package.\n * - Use a stringified SVG to display it directly.\n */\n @Prop() public icon?: string;\n\n /**\n * The maximum number of suggestions that will be displayed if the user has typed something into the input field.\n */\n @Prop({reflect: true}) public maxWithQuery = 3;\n /**\n * The maximum number of suggestions that will be displayed initially when the input field is empty.\n */\n @Prop({reflect: true}) public maxWithoutQuery?: number;\n\n componentWillLoad() {\n try {\n dispatchSearchBoxSuggestionsEvent<SearchBox, Bindings>(\n (bindings) => {\n this.bindings = bindings;\n return this.initialize();\n },\n this.host,\n ['atomic-search-box']\n );\n } catch (error) {\n this.error = error as Error;\n }\n }\n\n private renderIcon() {\n return this.icon || Clock;\n }\n\n private initialize(): SearchBoxSuggestions {\n this.storage = new SafeStorage();\n this.recentQueriesList = buildRecentQueriesList(this.bindings.engine, {\n initialState: {queries: this.retrieveLocalStorage()},\n options: {maxLength: 1000, clearFilters: this.bindings.clearFilters},\n });\n\n this.recentQueriesList.subscribe(() => this.updateLocalStorage());\n\n return {\n position: Array.from(this.host.parentNode!.children).indexOf(this.host),\n renderItems: () => this.renderItems(),\n };\n }\n\n private retrieveLocalStorage() {\n return this.storage.getParsedJSON(StorageItems.RECENT_QUERIES, []);\n }\n\n private updateLocalStorage() {\n if (!this.recentQueriesList.state.analyticsEnabled) {\n return this.disableFeature();\n }\n\n return this.storage.setJSON(\n StorageItems.RECENT_QUERIES,\n this.recentQueriesList.state.queries\n );\n }\n\n private warnUser = once(() =>\n this.bindings.engine.logger.warn(\n 'Because analytics are disabled, the recent queries feature is deactivated.'\n )\n );\n\n private disableFeature() {\n this.warnUser();\n this.storage.removeItem(StorageItems.RECENT_QUERIES);\n }\n\n private renderItems(): SearchBoxSuggestionElement[] {\n if (!this.recentQueriesList.state.analyticsEnabled) {\n return [];\n }\n\n const query = this.bindings.searchBoxController.state.value;\n const hasQuery = query !== '';\n const max = hasQuery ? this.maxWithQuery : this.maxWithoutQuery;\n const filteredQueries = this.recentQueriesList.state.queries\n .filter((recentQuery) =>\n recentQuery.toLowerCase().startsWith(query.toLowerCase())\n )\n .slice(0, max);\n\n const suggestionElements: SearchBoxSuggestionElement[] =\n filteredQueries.map((value) => this.renderItem(value));\n if (suggestionElements.length) {\n suggestionElements.unshift(this.renderClear());\n }\n\n return suggestionElements;\n }\n\n private renderClear(): SearchBoxSuggestionElement {\n const partialItem = getPartialRecentQueryClearElement(this.bindings.i18n);\n\n return {\n ...partialItem,\n content: <RecentQueryClear i18n={this.bindings.i18n} />,\n onSelect: () => {\n this.recentQueriesList.clear();\n this.bindings.triggerSuggestions();\n },\n };\n }\n\n private renderItem(value: string): SearchBoxSuggestionElement {\n const query = this.bindings.searchBoxController.state.value;\n const partialItem = getPartialRecentQueryElement(value, this.bindings.i18n);\n return {\n ...partialItem,\n content: (\n <RecentQueriesContainer>\n <RecentQueryIcon icon={this.renderIcon()} />\n <RecentQueryText query={query} value={value} />\n </RecentQueriesContainer>\n ),\n\n onSelect: () => {\n if (this.bindings.isStandalone) {\n this.bindings.searchBoxController.updateText(value);\n this.bindings.searchBoxController.submit();\n return;\n }\n\n this.recentQueriesList.executeRecentQuery(\n this.recentQueriesList.state.queries.indexOf(value)\n );\n },\n };\n }\n\n public render() {\n if (this.error) {\n return (\n <atomic-component-error\n element={this.host}\n error={this.error}\n ></atomic-component-error>\n );\n }\n }\n}\n"],"mappings":"0hBA4BaA,EAA+B,M,6HAwB1C,iBAAAC,GACE,IACEC,GACGC,IACCC,KAAKD,SAAWA,EAChB,OAAOC,KAAKC,YAAY,GAE1BD,KAAKE,KACL,CAAC,qB,CAEH,MAAOC,GACPH,KAAKG,MAAQA,C,EAIT,UAAAF,GACN,MAAMG,EAASJ,KAAKD,SAASK,OAI7B,MAAMC,qBAACA,EAAoBC,sBAAEA,GAC3BC,EAAwBH,GAE1BA,EAAOI,SACLH,EAAqB,CACnBI,GAAIT,KAAKD,SAASU,GAClBC,MAAOV,KAAKD,SAASY,mBAIzB,MAAO,CACLC,SAAUC,MAAMC,KAAKd,KAAKE,KAAKa,WAAYC,UAAUC,QAAQjB,KAAKE,MAClEgB,QAAS,IACPd,EAAOI,SACLF,EAAsB,CACpBG,GAAIT,KAAKD,SAASU,MAGxBU,YAAa,IAAMnB,KAAKmB,c,CAIpB,WAAAA,GACN,MAAMC,EAAWpB,KAAKD,SAASsB,oBAAoBC,MAAMC,QAAU,GACnE,MAAMC,EAAMJ,EAAWpB,KAAKyB,aAAezB,KAAK0B,gBAChD,OAAO1B,KAAKD,SAAS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OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,gFAAgF,wBAAwB,CAAC,IAAI,CACjJ,IAAI,CACL,EAAE,CACJ,CAAC;KACH;IACD,KAAK,2CAA2C,CAC9C,gBAAgB,EAChB,OAAO,EACP,KAAK,CACN,CAAC;AACJ,EAAE;SAEc,iBAAiB,CAAC,EAA8B;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;SAEe,eAAe,CAAC,EAA8B;IAC5D,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC9C;;;;;;","names":["buildCustomEvent","closest"],"sources":["src/components/common/suggestions/suggestions-common.ts"],"sourcesContent":["import type {VNode} from '@stencil/core';\nimport type {HTMLStencilElement} from '@stencil/core/internal';\nimport type {LitElement} from 'lit';\nimport {closest} from '../../../utils/dom-utils';\nimport {buildCustomEvent} from '../../../utils/event-utils';\nimport type {AnyBindings} from '../interface/bindings';\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 * @remarks\n * The `VNode` type will be deprecated in v4 as we are detaching from Stencil.\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>;\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>;\n}\n\n/**\n * Event sent from the registered query suggestions to the parent search box.\n */\nexport type SearchBoxSuggestionsEvent<\n SearchBoxController,\n Bindings = AnyBindings,\n> = (\n /**\n * The bindings passed from the search box to the suggestions.\n */\n bindings: SearchBoxSuggestionsBindings<SearchBoxController, Bindings>\n) => SearchBoxSuggestions;\n\nconst searchBoxElements = [\n 'atomic-search-box',\n 'atomic-insight-search-box',\n 'atomic-commerce-search-box',\n] as const;\n\n/**\n * The bindings passed from the search box to the suggestions.\n */\nexport type SearchBoxSuggestionsBindings<\n SearchBoxController,\n Bindings = AnyBindings,\n> = 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.\n */\n searchBoxController: SearchBoxController;\n /**\n * The number of queries to display when the user interacts with the search box.\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\nconst isLitElementLoosely = (candidate: unknown): candidate is LitElement =>\n 'updateComplete' in (candidate as LitElement) &&\n (candidate as LitElement).updateComplete instanceof Promise;\n\nconst dispatchSearchBoxSuggestionsEventEventually = async <\n SearchBoxController,\n Bindings = AnyBindings,\n>(\n interfaceElement: Element,\n element: HTMLElement,\n event: SearchBoxSuggestionsEvent<SearchBoxController, Bindings>\n) => {\n await customElements.whenDefined(interfaceElement.nodeName.toLowerCase());\n if (isLitElementLoosely(interfaceElement)) {\n await interfaceElement.updateComplete;\n } else if ('componentOnReady' in interfaceElement) {\n await (interfaceElement as HTMLStencilElement).componentOnReady();\n }\n element.dispatchEvent(\n buildCustomEvent('atomic/searchBoxSuggestion/register', event)\n );\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 SearchBoxController,\n Bindings = AnyBindings,\n>(\n event: SearchBoxSuggestionsEvent<SearchBoxController, Bindings>,\n element: HTMLElement,\n allowedSearchBoxElements: readonly (typeof searchBoxElements)[number][] = searchBoxElements\n) => {\n const interfaceElement = closest(element, searchBoxElements.join(', '));\n if (!interfaceElement) {\n throw new Error(\n `The \"${element.nodeName.toLowerCase()}\" component was not handled, as it is not a child of the following elements: ${allowedSearchBoxElements.join(\n ', '\n )}`\n );\n }\n void dispatchSearchBoxSuggestionsEventEventually(\n interfaceElement,\n element,\n event\n );\n};\n\nexport function elementHasNoQuery(el: SearchBoxSuggestionElement) {\n return !el.query || el.query.trim() === '';\n}\n\nexport function elementHasQuery(el: SearchBoxSuggestionElement) {\n return !!el.query && el.query.trim() !== '';\n}\n"],"version":3}
@@ -1 +0,0 @@
1
- {"file":"suggestions-common-2b20db26.js","mappings":";;;AA0FA,MAAM,iBAAiB,GAAG;IACxB,mBAAmB;IACnB,2BAA2B;IAC3B,4BAA4B;CACpB,CAAC;AAoDX,MAAM,mBAAmB,GAAG,CAAC,SAAkB,KAC7C,gBAAgB,IAAK,SAAwB;IAC5C,SAAwB,CAAC,cAAc,YAAY,OAAO,CAAC;AAE9D,MAAM,2CAA2C,GAAG,OAIlD,gBAAyB,EACzB,OAAoB,EACpB,KAA+D;IAE/D,MAAM,cAAc,CAAC,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1E,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,EAAE;QACzC,MAAM,gBAAgB,CAAC,cAAc,CAAC;KACvC;SAAM,IAAI,kBAAkB,IAAI,gBAAgB,EAAE;QACjD,MAAO,gBAAuC,CAAC,gBAAgB,EAAE,CAAC;KACnE;IACD,OAAO,CAAC,aAAa,CACnB,gBAAgB,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAC/D,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;MAKa,iCAAiC,GAAG,CAI/C,KAA+D,EAC/D,OAAoB,EACpB,2BAA0E,iBAAiB;IAE3F,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACxE,IAAI,CAAC,gBAAgB,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,QAAQ,OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,gFAAgF,wBAAwB,CAAC,IAAI,CACjJ,IAAI,CACL,EAAE,CACJ,CAAC;KACH;IACD,KAAK,2CAA2C,CAC9C,gBAAgB,EAChB,OAAO,EACP,KAAK,CACN,CAAC;AACJ,EAAE;SAEc,iBAAiB,CAAC,EAA8B;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;SAEe,eAAe,CAAC,EAA8B;IAC5D,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC9C;;;;","names":[],"sources":["src/components/common/suggestions/suggestions-common.ts"],"sourcesContent":["import type {VNode} from '@stencil/core';\nimport type {HTMLStencilElement} from '@stencil/core/internal';\nimport type {LitElement} from 'lit';\nimport {closest} from '../../../utils/dom-utils';\nimport {buildCustomEvent} from '../../../utils/event-utils';\nimport type {AnyBindings} from '../interface/bindings';\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 * @remarks\n * The `VNode` type will be deprecated in v4 as we are detaching from Stencil.\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>;\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>;\n}\n\n/**\n * Event sent from the registered query suggestions to the parent search box.\n */\nexport type SearchBoxSuggestionsEvent<\n SearchBoxController,\n Bindings = AnyBindings,\n> = (\n /**\n * The bindings passed from the search box to the suggestions.\n */\n bindings: SearchBoxSuggestionsBindings<SearchBoxController, Bindings>\n) => SearchBoxSuggestions;\n\nconst searchBoxElements = [\n 'atomic-search-box',\n 'atomic-insight-search-box',\n 'atomic-commerce-search-box',\n] as const;\n\n/**\n * The bindings passed from the search box to the suggestions.\n */\nexport type SearchBoxSuggestionsBindings<\n SearchBoxController,\n Bindings = AnyBindings,\n> = 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.\n */\n searchBoxController: SearchBoxController;\n /**\n * The number of queries to display when the user interacts with the search box.\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\nconst isLitElementLoosely = (candidate: unknown): candidate is LitElement =>\n 'updateComplete' in (candidate as LitElement) &&\n (candidate as LitElement).updateComplete instanceof Promise;\n\nconst dispatchSearchBoxSuggestionsEventEventually = async <\n SearchBoxController,\n Bindings = AnyBindings,\n>(\n interfaceElement: Element,\n element: HTMLElement,\n event: SearchBoxSuggestionsEvent<SearchBoxController, Bindings>\n) => {\n await customElements.whenDefined(interfaceElement.nodeName.toLowerCase());\n if (isLitElementLoosely(interfaceElement)) {\n await interfaceElement.updateComplete;\n } else if ('componentOnReady' in interfaceElement) {\n await (interfaceElement as HTMLStencilElement).componentOnReady();\n }\n element.dispatchEvent(\n buildCustomEvent('atomic/searchBoxSuggestion/register', event)\n );\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 SearchBoxController,\n Bindings = AnyBindings,\n>(\n event: SearchBoxSuggestionsEvent<SearchBoxController, Bindings>,\n element: HTMLElement,\n allowedSearchBoxElements: readonly (typeof searchBoxElements)[number][] = searchBoxElements\n) => {\n const interfaceElement = closest(element, searchBoxElements.join(', '));\n if (!interfaceElement) {\n throw new Error(\n `The \"${element.nodeName.toLowerCase()}\" component was not handled, as it is not a child of the following elements: ${allowedSearchBoxElements.join(\n ', '\n )}`\n );\n }\n void dispatchSearchBoxSuggestionsEventEventually(\n interfaceElement,\n element,\n event\n );\n};\n\nexport function elementHasNoQuery(el: SearchBoxSuggestionElement) {\n return !el.query || el.query.trim() === '';\n}\n\nexport function elementHasQuery(el: SearchBoxSuggestionElement) {\n return !!el.query && el.query.trim() !== '';\n}\n"],"version":3}