@searchcraft/javascript-sdk 0.10.7 → 0.11.0
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.
- package/dist/components/defineCustomElements.js +4 -0
- package/dist/components/index.d.ts +530 -217
- package/dist/components/index.js +1655 -8
- package/dist/components/index.js.map +1 -1
- package/dist/components/{p-e99cd628.js → p-0c495408.js} +30 -20
- package/dist/components/p-0c495408.js.map +1 -0
- package/dist/components/{p-b4cac872.js → p-1d5c5536.js} +18 -8
- package/dist/components/p-1d5c5536.js.map +1 -0
- package/dist/components/{p-274c5cc8.js → p-3286bbb3.js} +22 -10
- package/dist/components/p-3286bbb3.js.map +1 -0
- package/dist/components/{p-ea48ccae.js → p-3e41546c.js} +17 -8
- package/dist/components/p-3e41546c.js.map +1 -0
- package/dist/components/{p-adc6236e.js → p-87435aac.js} +31 -20
- package/dist/components/p-87435aac.js.map +1 -0
- package/dist/components/p-919734fe.js +31 -0
- package/dist/components/p-919734fe.js.map +1 -0
- package/dist/components/{p-b01f8216.js → p-b13c7fbb.js} +48 -33
- package/dist/components/p-b13c7fbb.js.map +1 -0
- package/dist/components/{p-810a7850.js → p-b4b67072.js} +2 -2
- package/dist/components/p-b4b67072.js.map +1 -0
- package/dist/components/{p-acab4d41.js → p-b7e99386.js} +22 -22
- package/dist/components/p-b7e99386.js.map +1 -0
- package/dist/components/{p-4dd1995c.js → p-c9b65e8f.js} +4 -4
- package/dist/components/{p-4dd1995c.js.map → p-c9b65e8f.js.map} +1 -1
- package/dist/components/p-d54771ef.js.map +1 -1
- package/dist/components/{p-a64b4cba.js → p-e2a10337.js} +2 -2
- package/dist/components/{p-a64b4cba.js.map → p-e2a10337.js.map} +1 -1
- package/dist/components/p-e30203b1.js +62 -0
- package/dist/components/p-e30203b1.js.map +1 -0
- package/dist/components/{p-320e3895.js → p-fc8ccffa.js} +22 -11
- package/dist/components/p-fc8ccffa.js.map +1 -0
- package/dist/components/searchcraft-ad.js +1 -1
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-filter-panel.js +51 -23
- package/dist/components/searchcraft-filter-panel.js.map +1 -1
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-loading.d.ts +11 -0
- package/dist/components/searchcraft-loading.js +8 -0
- package/dist/components/searchcraft-loading.js.map +1 -0
- package/dist/components/searchcraft-pagination.js +13 -3
- package/dist/components/searchcraft-pagination.js.map +1 -1
- package/dist/components/searchcraft-popover-button.js +21 -9
- package/dist/components/searchcraft-popover-button.js.map +1 -1
- package/dist/components/searchcraft-popover-footer.js +1 -1
- package/dist/components/searchcraft-popover-form.js +32 -20
- package/dist/components/searchcraft-popover-form.js.map +1 -1
- package/dist/components/searchcraft-popover-list-item.js +1 -1
- package/dist/components/searchcraft-popover-list-view.js +1 -1
- package/dist/components/searchcraft-results-info.js +15 -7
- package/dist/components/searchcraft-results-info.js.map +1 -1
- package/dist/components/searchcraft-search-result.js +1 -1
- package/dist/components/searchcraft-search-results-per-page.js +14 -4
- package/dist/components/searchcraft-search-results-per-page.js.map +1 -1
- package/dist/components/searchcraft-search-results.js +50 -69
- package/dist/components/searchcraft-search-results.js.map +1 -1
- package/dist/components/searchcraft-slider.js +1 -1
- package/dist/components/searchcraft-summary-box.d.ts +11 -0
- package/dist/components/searchcraft-summary-box.js +2287 -0
- package/dist/components/searchcraft-summary-box.js.map +1 -0
- package/dist/components/searchcraft-theme.js +2 -2
- package/dist/components/searchcraft-theme.js.map +1 -1
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/hydrate/index.js +6072 -4862
- package/dist/hydrate/index.mjs +6072 -4862
- package/dist/themes/hologram.css +1 -1
- package/dist/themes/hologram.css.map +1 -1
- package/dist/types/classes/CoreInstanceRegistry.d.ts +38 -0
- package/dist/types/classes/Logger.d.ts +25 -0
- package/dist/types/classes/SearchcraftCore.d.ts +50 -0
- package/dist/types/classes/index.d.ts +3 -0
- package/dist/types/clients/MeasureClient.d.ts +27 -0
- package/dist/types/clients/SearchClient.d.ts +35 -0
- package/dist/types/clients/SummaryClient.d.ts +10 -0
- package/dist/types/clients/ad-clients/AdClient.d.ts +20 -0
- package/dist/types/clients/ad-clients/AdMarketplaceClient.d.ts +14 -0
- package/dist/types/clients/ad-clients/CustomAdClient.d.ts +6 -0
- package/dist/types/clients/ad-clients/NativoClient.d.ts +14 -0
- package/dist/types/clients/ad-clients/index.d.ts +5 -0
- package/dist/types/clients/index.d.ts +4 -0
- package/dist/types/components/searchcraft-ad/searchcraft-ad.d.ts +10 -3
- package/dist/types/components/searchcraft-facet-list/searchcraft-facet-list.d.ts +9 -2
- package/dist/types/components/searchcraft-filter-panel/searchcraft-filter-panel.d.ts +14 -3
- package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +9 -6
- package/dist/types/components/searchcraft-loading/searchcraft-loading.d.ts +10 -0
- package/dist/types/components/searchcraft-pagination/searchcraft-pagination.d.ts +8 -1
- package/dist/types/components/searchcraft-popover-button/searchcraft-popover-button.d.ts +10 -2
- package/dist/types/components/searchcraft-popover-footer/searchcraft-popover-footer.d.ts +8 -1
- package/dist/types/components/searchcraft-popover-form/searchcraft-popover-form.d.ts +11 -3
- package/dist/types/components/searchcraft-popover-list-item/searchcraft-popover-list-item.d.ts +9 -1
- package/dist/types/components/searchcraft-popover-list-view/searchcraft-popover-list-view.d.ts +11 -3
- package/dist/types/components/searchcraft-results-info/searchcraft-results-info.d.ts +8 -1
- package/dist/types/components/searchcraft-search-result/searchcraft-search-result.d.ts +10 -1
- package/dist/types/components/searchcraft-search-results/searchcraft-search-results.d.ts +11 -5
- package/dist/types/components/searchcraft-search-results-per-page/searchcraft-search-results-per-page.d.ts +8 -1
- package/dist/types/components/searchcraft-summary-box/searchcraft-summary-box.d.ts +49 -0
- package/dist/types/components/searchcraft-toggle-button/searchcraft-toggle-button.d.ts +8 -1
- package/dist/types/components.d.ts +256 -6
- package/dist/types/index.d.ts +4 -5
- package/dist/types/store/SearchcraftStore.types.d.ts +14 -15
- package/dist/types/store/SearchcraftStoreFactory.d.ts +13 -0
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/types/core-types/AdClientResponses.types.d.ts +24 -0
- package/dist/types/types/core-types/Facets.types.d.ts +39 -0
- package/dist/types/types/core-types/Measure.types.d.ts +52 -0
- package/dist/types/types/core-types/SearchClient.types.d.ts +67 -0
- package/dist/types/types/core-types/SearchClientResponses.types.d.ts +7 -0
- package/dist/types/types/core-types/SearchcraftAdConfig.types.d.ts +76 -0
- package/dist/types/types/core-types/SearchcraftConfig.types.d.ts +65 -0
- package/dist/types/types/core-types/SearchcraftResponse.types.d.ts +46 -0
- package/dist/types/types/core-types/SubscriptionEvents.types.d.ts +51 -0
- package/dist/types/types/core-types/index.d.ts +10 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/sdk-types/index.d.ts +4 -0
- package/dist/types/types/sdk-types/result-mappings.types.d.ts +58 -0
- package/dist/types/types/sdk-types/searchcraft-filter-panel.types.d.ts +44 -0
- package/dist/types/types/sdk-types/templates.types.d.ts +29 -0
- package/dist/types/utils/core-utils/index.d.ts +3 -0
- package/dist/types/utils/core-utils/sanitize.d.ts +2 -0
- package/dist/types/utils/core-utils/url.d.ts +2 -0
- package/dist/types/utils/facets.d.ts +1 -1
- package/dist/types/utils/html.d.ts +1 -1
- package/dist/types/utils/units.d.ts +1 -1
- package/package.json +5 -3
- package/dist/components/p-062d6b80.js +0 -1940
- package/dist/components/p-062d6b80.js.map +0 -1
- package/dist/components/p-274c5cc8.js.map +0 -1
- package/dist/components/p-320e3895.js.map +0 -1
- package/dist/components/p-810a7850.js.map +0 -1
- package/dist/components/p-acab4d41.js.map +0 -1
- package/dist/components/p-adc6236e.js.map +0 -1
- package/dist/components/p-b01f8216.js.map +0 -1
- package/dist/components/p-b4cac872.js.map +0 -1
- package/dist/components/p-e99cd628.js.map +0 -1
- package/dist/components/p-ea48ccae.js.map +0 -1
- package/dist/types/store/SearchcraftStore.d.ts +0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,+BAA+B,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAClG,SAAS,EACP,OAAO,IAAI,CAAC,QAAQ,KAAK,WAAW;kBAChC,IAAI,CAAC,QAAQ,CACX,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,EAC3C,EAAE,IAAI,EAAE,CACT;kBACD,SAAS,EAEf,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EACtC,IAAI,EAAC,QAAQ,IAEZ,OAAO,IAAI,CAAC,QAAQ,KAAK,WAAW;cACjC,SAAS;cACT,IAAI,CAAC,IAAI;kBACP,IAAI,CAAC,UAAU,EAAE;kBACjB,cAAc,CACb,EACT;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftPopoverButton"],"sources":["src/components/searchcraft-popover-button/searchcraft-popover-button.tsx"],"sourcesContent":["import { Component, h, Prop, State } from '@stencil/core';\n\nimport type { PopoverButtonTemplate } from '@searchcraft/core';\n\nimport { searchcraftStore } from '@store';\n\nimport { html } from '@utils';\n\n/**\n * Renders a button which, when clicked, turns on popover visibility.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftPopoverButton } from \"@searchcraft/react-sdk\";\n * ````\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftPopoverButton } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-button>\n * Open popover\n * </searchcraft-popover-button>\n * ```\n *\n * ```js\n * // index.js\n * const popoverButton = document.querySelector('searchcraft-popover-button');\n *\n * popoverButton.template = ({ isPopoverVisible }, { html }) => html`\n * <span>Click me</span>\n * `;\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftPopoverButton\n * template={({ isPopoverVisible }, { html }) => html`\n * <span>Click me</span>\n * `}\n * >\n * Open popover\n * </SearchcraftPopoverButton>\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftPopoverButton\n * :template={({ isPopoverVisible }, { html }) => html`\n * <span>Click me</span>\n * `}\n * >\n * Open popover\n * </SearchcraftPopoverButton>\n * ```\n */\n@Component({\n tag: 'searchcraft-popover-button',\n shadow: false,\n})\nexport class SearchcraftPopoverButton {\n /**\n * A callback function responsible for rendering the button contents.\n */\n @Prop() template?: PopoverButtonTemplate;\n /**\n * The type of popover button to render.\n */\n @Prop() type?: 'skeuomorphic';\n\n @State() hotkey;\n @State() hotkeyModifier;\n @State() hotkeyModifierSymbol;\n @State() isPopoverVisible;\n @State() userAgent;\n\n private unsubscribe: () => void = () => {};\n\n handleOnClick() {\n searchcraftStore.getState().setPopoverVisibility(true);\n }\n\n componentDidLoad() {\n const state = searchcraftStore.getState();\n this.hotkey = state.hotkey.toUpperCase();\n this.hotkeyModifier = state.hotkeyModifier;\n this.isPopoverVisible = state.isPopoverVisible;\n this.userAgent = this.setUserAgent();\n this.hotkeyModifierSymbol = this.setHotkeyModifierSymbol();\n\n this.unsubscribe = searchcraftStore.subscribe((state) => {\n this.hotkey = state.hotkey.toUpperCase();\n this.hotkeyModifier = state.hotkeyModifier;\n this.hotkeyModifierSymbol = this.setHotkeyModifierSymbol();\n });\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n }\n\n setUserAgent() {\n const userAgent = navigator.userAgent.toLowerCase();\n\n switch (true) {\n case userAgent.includes('windows'):\n return 'window';\n case userAgent.includes('mac'):\n return 'mac';\n default:\n return 'other';\n }\n }\n\n renderOptionSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Option key</title>\n <path\n d='M283,112c0-11.58,9.42-21,21-21h160c11.58,0,21,9.42,21,21s-9.42,21-21,21h-160c-11.58,0-21-9.42-21-21Z'\n fill='currentColor'\n />\n <path\n d='M485,400c0,11.58-9.42,21-21,21h-128c-8.29,0-15.82-4.9-19.19-12.47l-122.46-275.53H48c-11.58,0-21-9.42-21-21s9.42-21,21-21h160c8.29,0,15.82,4.9,19.19,12.47l122.46,275.53h114.35c11.58,0,21,9.42,21,21Z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n renderCtrlSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Ctrl key</title>\n <path\n d='M388.95,209.4c-.37,5.59-2.9,10.71-7.12,14.4-3.83,3.35-8.74,5.2-13.82,5.2-6.06,0-11.83-2.61-15.81-7.17l-96.2-109.94-96.2,109.94c-3.98,4.56-9.75,7.17-15.81,7.17-5.08,0-9.99-1.84-13.82-5.2-4.22-3.69-6.75-8.81-7.12-14.4-.38-5.6,1.45-11.01,5.15-15.23l112-128c3.98-4.56,9.74-7.17,15.8-7.17s11.82,2.61,15.8,7.17l112,128c3.7,4.22,5.53,9.63,5.15,15.23Z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n renderWindowsMetaSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Windows meta key</title>\n <path\n d='M206.115 255.957c-23.854-12.259-47.043-18.479-68.94-18.479-2.978 0-5.976 0.090-8.974 0.354-27.94 2.312-53.461 9.684-69.875 15.414-4.354 1.599-8.817 3.288-13.415 5.153l-44.911 155.697c30.851-11.416 58.146-16.969 83.135-16.969 40.423 0 69.764 15.104 93.996 30.652 11.481-38.959 39.022-133.045 47.241-161.162-5.975-3.642-12.038-7.285-18.257-10.66zM264.174 295.535l-45.223 157.074c13.416 7.686 58.549 32.025 93.106 32.025 27.896 0 59.126-7.148 95.417-21.896l43.178-150.988c-29.316 9.461-57.438 14.26-83.732 14.26-47.975 0-81.557-15.549-102.746-30.475zM146.411 184.395c38.559 0.399 67.076 15.104 90.708 30.251l46.376-158.672c-9.773-5.598-35.403-19.547-53.929-24.3-12.193-2.842-25.010-4.308-38.602-4.308-25.898 0.488-54.194 6.973-86.444 19.9l-44.22 155.298c32.404-12.218 60.322-18.17 86.043-18.17 0.023 0.001 0.068 0.001 0.068 0.001zM512 99.062c-29.407 11.416-58.104 17.233-85.514 17.233-45.843 0-79.646-15.901-101.547-31.183l-45.975 159.118c30.873 19.854 64.145 29.939 99.061 29.939 28.474 0 57.97-6.84 87.731-20.344l-0.091-1.111 1.867-0.443 44.468-153.209z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n renderMacMetaSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Mac meta key</title>\n <path\n d='M368,283h-43v-54h43c46.87,0,85-38.13,85-85s-38.13-85-85-85-85,38.13-85,85v43h-54v-43c0-46.87-38.13-85-85-85s-85,38.13-85,85,38.13,85,85,85h43v54h-43c-46.87,0-85,38.13-85,85s38.13,85,85,85,85-38.13,85-85v-43h54v43c0,46.87,38.13,85,85,85s85-38.13,85-85-38.13-85-85-85ZM325,144c0-23.71,19.29-43,43-43s43,19.29,43,43-19.29,43-43,43h-43v-43ZM144,187c-23.71,0-43-19.29-43-43s19.29-43,43-43,43,19.29,43,43v43h-43ZM187,368c0,23.71-19.29,43-43,43s-43-19.29-43-43,19.29-43,43-43h43v43ZM283,283h-54v-54h54v54ZM368,411c-23.71,0-43-19.29-43-43v-43h43c23.71,0,43,19.29,43,43s-19.29,43-43,43Z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n setHotkeyModifierSymbol() {\n switch (this.hotkeyModifier) {\n case 'ctrl':\n return this.userAgent === 'windows'\n ? this.renderCtrlSymbol()\n : this.renderMacMetaSymbol();\n case 'alt':\n case 'option':\n return this.renderOptionSymbol();\n default:\n return this.userAgent === 'windows'\n ? this.renderWindowsMetaSymbol()\n : this.renderMacMetaSymbol();\n }\n }\n\n renderSkeuomorphicSlot() {\n return (\n <div class='searchcraft-popover-button-wrapper'>\n <div class='searchcraft-popover-button-input'>\n <svg\n class='searchcraft-popover-button-input-search-icon'\n viewBox='0 0 20 20'\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n version='1.1'\n >\n <title>Search icon</title>\n <path\n d='M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z'\n stroke='currentColor'\n stroke-width='1.5'\n stroke-linecap='round'\n stroke-linejoin='round'\n />\n </svg>\n <span>Search</span>\n </div>\n <div class='searchcraft-popover-button-keycaps'>\n <div class='searchcraft-popover-button-keycaps-keycap searchcraft-popover-button-keycaps-keycap-modifier'>\n <span>{this.hotkeyModifierSymbol}</span>\n </div>\n <div class='searchcraft-popover-button-keycaps-keycap searchcraft-popover-button-keycaps-keycap-key'>\n <span>{this.hotkey}</span>\n </div>\n </div>\n </div>\n );\n }\n\n renderSlot() {\n switch (this.type) {\n case 'skeuomorphic':\n return this.renderSkeuomorphicSlot();\n default:\n return (\n <div>\n <slot />\n </div>\n );\n }\n }\n\n render() {\n return (\n <button\n class={`searchcraft-popover-button ${this.type ? ` searchcraft-popover-button-${this.type}` : ''}`}\n innerHTML={\n typeof this.template !== 'undefined'\n ? this.template(\n { isPopoverVisible: this.isPopoverVisible },\n { html },\n )\n : undefined\n }\n onClick={this.handleOnClick.bind(this)}\n type='button'\n >\n {typeof this.template !== 'undefined'\n ? undefined\n : this.type\n ? this.renderSlot()\n : 'Open Popover'}\n </button>\n );\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"searchcraft-popover-button.js","mappings":";;;;MAgEaA,0BAAwB;;;;;;;;IAI3B,QAAQ,CAAyB;;;;IAIjC,IAAI,CAAkB;;;;IAItB,aAAa,CAAU;IAEtB,MAAM,CAAC;IACP,cAAc,CAAC;IACf,oBAAoB,CAAC;IACrB,gBAAgB,CAAC;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ACE,QACE,eACE,eAAQ,CACJ,EACN;SACL;KACF;IAED,MAAM;QACJ,QACE,+DACE,KAAK,EAAE,8BAA8B,IAAI,CAAC,IAAI,GAAG,+BAA+B,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAClG,SAAS,EACP,OAAO,IAAI,CAAC,QAAQ,KAAK,WAAW;kBAChC,IAAI,CAAC,QAAQ,CACX,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,EAC3C,EAAE,IAAI,EAAE,CACT;kBACD,SAAS,EAEf,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EACtC,IAAI,EAAC,QAAQ,IAEZ,OAAO,IAAI,CAAC,QAAQ,KAAK,WAAW;cACjC,SAAS;cACT,IAAI,CAAC,IAAI;kBACP,IAAI,CAAC,UAAU,EAAE;kBACjB,cAAc,CACb,EACT;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftPopoverButton"],"sources":["src/components/searchcraft-popover-button/searchcraft-popover-button.tsx"],"sourcesContent":["import type { SearchcraftCore } from '@classes';\nimport { registry } from '@classes/CoreInstanceRegistry';\nimport { Component, h, Prop, State } from '@stencil/core';\n\nimport type { PopoverButtonTemplate } from '@types';\n\nimport { html } from '@utils';\n\n/**\n * Renders a button which, when clicked, turns on popover visibility.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftPopoverButton } from \"@searchcraft/react-sdk\";\n * ````\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftPopoverButton } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-button>\n * Open popover\n * </searchcraft-popover-button>\n * ```\n *\n * ```js\n * // index.js\n * const popoverButton = document.querySelector('searchcraft-popover-button');\n *\n * popoverButton.template = ({ isPopoverVisible }, { html }) => html`\n * <span>Click me</span>\n * `;\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftPopoverButton\n * template={({ isPopoverVisible }, { html }) => html`\n * <span>Click me</span>\n * `}\n * >\n * Open popover\n * </SearchcraftPopoverButton>\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftPopoverButton\n * :template={({ isPopoverVisible }, { html }) => html`\n * <span>Click me</span>\n * `}\n * >\n * Open popover\n * </SearchcraftPopoverButton>\n * ```\n */\n@Component({\n tag: 'searchcraft-popover-button',\n shadow: false,\n})\nexport class SearchcraftPopoverButton {\n /**\n * A callback function responsible for rendering the button contents.\n */\n @Prop() template?: PopoverButtonTemplate;\n /**\n * The type of popover button to render.\n */\n @Prop() type?: 'skeuomorphic';\n /**\n * The id of the Searchcraft instance that this component should use.\n */\n @Prop() searchcraftId?: string;\n\n @State() hotkey;\n @State() hotkeyModifier;\n @State() hotkeyModifierSymbol;\n @State() isPopoverVisible;\n @State() userAgent;\n\n private unsubscribe: () => void = () => {};\n private cleanupCore?: () => void;\n private core?: SearchcraftCore;\n\n onCoreAvailable(core: SearchcraftCore) {\n this.core = core;\n const state = core.store.getState();\n this.hotkey = state.hotkey.toUpperCase();\n this.hotkeyModifier = state.hotkeyModifier;\n this.isPopoverVisible = state.isPopoverVisible;\n this.userAgent = this.setUserAgent();\n this.hotkeyModifierSymbol = this.setHotkeyModifierSymbol();\n\n this.unsubscribe = core.store.subscribe((state) => {\n this.hotkey = state.hotkey.toUpperCase();\n this.hotkeyModifier = state.hotkeyModifier;\n this.hotkeyModifierSymbol = this.setHotkeyModifierSymbol();\n });\n }\n\n connectedCallback() {\n this.cleanupCore = registry.useCoreInstance(\n this.searchcraftId,\n this.onCoreAvailable.bind(this),\n );\n }\n\n handleOnClick() {\n this.core?.store.getState().setPopoverVisibility(true);\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n this.cleanupCore?.();\n }\n\n setUserAgent() {\n const userAgent = navigator.userAgent.toLowerCase();\n\n switch (true) {\n case userAgent.includes('windows'):\n return 'window';\n case userAgent.includes('mac'):\n return 'mac';\n default:\n return 'other';\n }\n }\n\n renderOptionSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Option key</title>\n <path\n d='M283,112c0-11.58,9.42-21,21-21h160c11.58,0,21,9.42,21,21s-9.42,21-21,21h-160c-11.58,0-21-9.42-21-21Z'\n fill='currentColor'\n />\n <path\n d='M485,400c0,11.58-9.42,21-21,21h-128c-8.29,0-15.82-4.9-19.19-12.47l-122.46-275.53H48c-11.58,0-21-9.42-21-21s9.42-21,21-21h160c8.29,0,15.82,4.9,19.19,12.47l122.46,275.53h114.35c11.58,0,21,9.42,21,21Z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n renderCtrlSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Ctrl key</title>\n <path\n d='M388.95,209.4c-.37,5.59-2.9,10.71-7.12,14.4-3.83,3.35-8.74,5.2-13.82,5.2-6.06,0-11.83-2.61-15.81-7.17l-96.2-109.94-96.2,109.94c-3.98,4.56-9.75,7.17-15.81,7.17-5.08,0-9.99-1.84-13.82-5.2-4.22-3.69-6.75-8.81-7.12-14.4-.38-5.6,1.45-11.01,5.15-15.23l112-128c3.98-4.56,9.74-7.17,15.8-7.17s11.82,2.61,15.8,7.17l112,128c3.7,4.22,5.53,9.63,5.15,15.23Z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n renderWindowsMetaSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Windows meta key</title>\n <path\n d='M206.115 255.957c-23.854-12.259-47.043-18.479-68.94-18.479-2.978 0-5.976 0.090-8.974 0.354-27.94 2.312-53.461 9.684-69.875 15.414-4.354 1.599-8.817 3.288-13.415 5.153l-44.911 155.697c30.851-11.416 58.146-16.969 83.135-16.969 40.423 0 69.764 15.104 93.996 30.652 11.481-38.959 39.022-133.045 47.241-161.162-5.975-3.642-12.038-7.285-18.257-10.66zM264.174 295.535l-45.223 157.074c13.416 7.686 58.549 32.025 93.106 32.025 27.896 0 59.126-7.148 95.417-21.896l43.178-150.988c-29.316 9.461-57.438 14.26-83.732 14.26-47.975 0-81.557-15.549-102.746-30.475zM146.411 184.395c38.559 0.399 67.076 15.104 90.708 30.251l46.376-158.672c-9.773-5.598-35.403-19.547-53.929-24.3-12.193-2.842-25.010-4.308-38.602-4.308-25.898 0.488-54.194 6.973-86.444 19.9l-44.22 155.298c32.404-12.218 60.322-18.17 86.043-18.17 0.023 0.001 0.068 0.001 0.068 0.001zM512 99.062c-29.407 11.416-58.104 17.233-85.514 17.233-45.843 0-79.646-15.901-101.547-31.183l-45.975 159.118c30.873 19.854 64.145 29.939 99.061 29.939 28.474 0 57.97-6.84 87.731-20.344l-0.091-1.111 1.867-0.443 44.468-153.209z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n renderMacMetaSymbol = () => {\n return (\n <svg\n version='1.1'\n xmlns='http://www.w3.org/2000/svg'\n width='20'\n height='20'\n viewBox='0 0 512 512'\n fill='none'\n >\n <title>Mac meta key</title>\n <path\n d='M368,283h-43v-54h43c46.87,0,85-38.13,85-85s-38.13-85-85-85-85,38.13-85,85v43h-54v-43c0-46.87-38.13-85-85-85s-85,38.13-85,85,38.13,85,85,85h43v54h-43c-46.87,0-85,38.13-85,85s38.13,85,85,85,85-38.13,85-85v-43h54v43c0,46.87,38.13,85,85,85s85-38.13,85-85-38.13-85-85-85ZM325,144c0-23.71,19.29-43,43-43s43,19.29,43,43-19.29,43-43,43h-43v-43ZM144,187c-23.71,0-43-19.29-43-43s19.29-43,43-43,43,19.29,43,43v43h-43ZM187,368c0,23.71-19.29,43-43,43s-43-19.29-43-43,19.29-43,43-43h43v43ZM283,283h-54v-54h54v54ZM368,411c-23.71,0-43-19.29-43-43v-43h43c23.71,0,43,19.29,43,43s-19.29,43-43,43Z'\n fill='currentColor'\n />\n </svg>\n );\n };\n\n setHotkeyModifierSymbol() {\n switch (this.hotkeyModifier) {\n case 'ctrl':\n return this.userAgent === 'windows'\n ? this.renderCtrlSymbol()\n : this.renderMacMetaSymbol();\n case 'alt':\n case 'option':\n return this.renderOptionSymbol();\n default:\n return this.userAgent === 'windows'\n ? this.renderWindowsMetaSymbol()\n : this.renderMacMetaSymbol();\n }\n }\n\n renderSkeuomorphicSlot() {\n return (\n <div class='searchcraft-popover-button-wrapper'>\n <div class='searchcraft-popover-button-input'>\n <svg\n class='searchcraft-popover-button-input-search-icon'\n viewBox='0 0 20 20'\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n version='1.1'\n >\n <title>Search icon</title>\n <path\n d='M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z'\n stroke='currentColor'\n stroke-width='1.5'\n stroke-linecap='round'\n stroke-linejoin='round'\n />\n </svg>\n <span>Search</span>\n </div>\n <div class='searchcraft-popover-button-keycaps'>\n <div class='searchcraft-popover-button-keycaps-keycap searchcraft-popover-button-keycaps-keycap-modifier'>\n <span>{this.hotkeyModifierSymbol}</span>\n </div>\n <div class='searchcraft-popover-button-keycaps-keycap searchcraft-popover-button-keycaps-keycap-key'>\n <span>{this.hotkey}</span>\n </div>\n </div>\n </div>\n );\n }\n\n renderSlot() {\n switch (this.type) {\n case 'skeuomorphic':\n return this.renderSkeuomorphicSlot();\n default:\n return (\n <div>\n <slot />\n </div>\n );\n }\n }\n\n render() {\n return (\n <button\n class={`searchcraft-popover-button ${this.type ? ` searchcraft-popover-button-${this.type}` : ''}`}\n innerHTML={\n typeof this.template !== 'undefined'\n ? this.template(\n { isPopoverVisible: this.isPopoverVisible },\n { html },\n )\n : undefined\n }\n onClick={this.handleOnClick.bind(this)}\n type='button'\n >\n {typeof this.template !== 'undefined'\n ? undefined\n : this.type\n ? this.renderSlot()\n : 'Open Popover'}\n </button>\n );\n }\n}\n"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftPopoverFooter$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftPopoverFooter$1, d as defineCustomElement$1 } from './p-1d5c5536.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftPopoverFooter = SearchcraftPopoverFooter$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, h } from './p-5365011f.js';
|
|
2
2
|
import { c as classNames } from './p-5cdc6210.js';
|
|
3
|
-
import {
|
|
4
|
-
import { d as defineCustomElement$9 } from './p-
|
|
3
|
+
import { r as registry } from './p-e30203b1.js';
|
|
4
|
+
import { d as defineCustomElement$9 } from './p-87435aac.js';
|
|
5
5
|
import { d as defineCustomElement$8 } from './p-acf23bab.js';
|
|
6
6
|
import { d as defineCustomElement$7 } from './p-f2585cdf.js';
|
|
7
|
-
import { d as defineCustomElement$6 } from './p-
|
|
7
|
+
import { d as defineCustomElement$6 } from './p-b7e99386.js';
|
|
8
8
|
import { d as defineCustomElement$5 } from './p-1adf78b9.js';
|
|
9
|
-
import { d as defineCustomElement$4 } from './p-
|
|
10
|
-
import { d as defineCustomElement$3 } from './p-
|
|
11
|
-
import { d as defineCustomElement$2 } from './p-
|
|
9
|
+
import { d as defineCustomElement$4 } from './p-1d5c5536.js';
|
|
10
|
+
import { d as defineCustomElement$3 } from './p-fc8ccffa.js';
|
|
11
|
+
import { d as defineCustomElement$2 } from './p-b13c7fbb.js';
|
|
12
12
|
|
|
13
13
|
const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftPopoverForm extends H {
|
|
14
14
|
constructor() {
|
|
@@ -34,8 +34,11 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
34
34
|
* The hotkey modifier that activates the popover. Used together with the `hotkey` prop.
|
|
35
35
|
*/
|
|
36
36
|
hotkeyModifier = 'meta';
|
|
37
|
+
/**
|
|
38
|
+
* The id of the Searchcraft instance that this component should use.
|
|
39
|
+
*/
|
|
40
|
+
searchcraftId;
|
|
37
41
|
isPopoverVisibleInState = false;
|
|
38
|
-
unsubscribe;
|
|
39
42
|
searchClientResponseItems = [];
|
|
40
43
|
adClientResponseItems = [];
|
|
41
44
|
searchTerm;
|
|
@@ -47,19 +50,23 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
47
50
|
searchResultsPerPage;
|
|
48
51
|
modalElement;
|
|
49
52
|
get hostElement() { return this; }
|
|
50
|
-
|
|
53
|
+
unsubscribe;
|
|
54
|
+
cleanupCore;
|
|
55
|
+
core;
|
|
56
|
+
onCoreAvailable(core) {
|
|
57
|
+
this.core = core;
|
|
51
58
|
// Loads the breakpoint values into state
|
|
52
59
|
const computedStyle = getComputedStyle(document.documentElement);
|
|
53
60
|
this.breakpointSm = Number.parseFloat(computedStyle.getPropertyValue('--sc-breakpoint-sm').trim());
|
|
54
61
|
this.breakpointMd = Number.parseFloat(computedStyle.getPropertyValue('--sc-breakpoint-md').trim());
|
|
55
62
|
this.breakpointLg = Number.parseFloat(computedStyle.getPropertyValue('--sc-breakpoint-lg').trim());
|
|
56
63
|
// Set popover visiblity in state
|
|
57
|
-
this.isPopoverVisibleInState =
|
|
64
|
+
this.isPopoverVisibleInState = core.store.getState().isPopoverVisible;
|
|
58
65
|
// Add event listeners
|
|
59
66
|
document.addEventListener('click', this.handleDocumentClick);
|
|
60
67
|
document.addEventListener('keydown', this.handleDocumentKeyDown);
|
|
61
68
|
// Subscribe to state events
|
|
62
|
-
this.unsubscribe =
|
|
69
|
+
this.unsubscribe = core.store.subscribe((state) => {
|
|
63
70
|
if (this.isPopoverVisibleInState !== state.isPopoverVisible) {
|
|
64
71
|
this.handlePopoverVisibilityChange(state.isPopoverVisible);
|
|
65
72
|
}
|
|
@@ -70,12 +77,16 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
70
77
|
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
71
78
|
});
|
|
72
79
|
// Set hotkey and hotkeyModifier in state.
|
|
73
|
-
|
|
80
|
+
core.store
|
|
74
81
|
.getState()
|
|
75
82
|
.setHotKeyAndHotKeyModifier(this.hotkey, this.hotkeyModifier);
|
|
76
83
|
}
|
|
84
|
+
connectedCallback() {
|
|
85
|
+
this.cleanupCore = registry.useCoreInstance(this.searchcraftId, this.onCoreAvailable.bind(this));
|
|
86
|
+
}
|
|
77
87
|
disconnectedCallback() {
|
|
78
88
|
this.unsubscribe?.();
|
|
89
|
+
this.cleanupCore?.();
|
|
79
90
|
document.removeEventListener('click', this.handleDocumentClick);
|
|
80
91
|
document.removeEventListener('keydown', this.handleDocumentKeyDown);
|
|
81
92
|
}
|
|
@@ -111,7 +122,7 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
111
122
|
this.focusOnNextListItem(event.key);
|
|
112
123
|
break;
|
|
113
124
|
case 'Escape':
|
|
114
|
-
|
|
125
|
+
this.core?.store.getState().setPopoverVisibility(false);
|
|
115
126
|
break;
|
|
116
127
|
default:
|
|
117
128
|
return;
|
|
@@ -130,18 +141,19 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
130
141
|
if (this.type === 'inline' &&
|
|
131
142
|
window.visualViewport &&
|
|
132
143
|
window.visualViewport.width < this.breakpointSm) {
|
|
133
|
-
|
|
144
|
+
this.core?.store.getState().setPopoverVisibility(true);
|
|
134
145
|
// Appends a popover form of type=`modal` to the body
|
|
135
146
|
if (!this.modalElement) {
|
|
136
147
|
this.modalElement = document.createElement('searchcraft-popover-form');
|
|
137
148
|
this.modalElement.popoverResultMappings = this.popoverResultMappings;
|
|
138
149
|
this.modalElement.setAttribute('type', 'fullscreen');
|
|
150
|
+
this.modalElement.setAttribute('searchcraft-id', this.searchcraftId);
|
|
139
151
|
document.body.appendChild(this.modalElement);
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
154
|
}
|
|
143
155
|
handleModalBackdropClick(_event) {
|
|
144
|
-
|
|
156
|
+
this.core?.store.getState().setPopoverVisibility(false);
|
|
145
157
|
}
|
|
146
158
|
/**
|
|
147
159
|
* When a hotkey is pressed, tests if the modifiers also match.
|
|
@@ -157,14 +169,14 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
157
169
|
hostElementInput?.focus();
|
|
158
170
|
}
|
|
159
171
|
else {
|
|
160
|
-
|
|
172
|
+
this.core?.store
|
|
161
173
|
.getState()
|
|
162
174
|
.setPopoverVisibility(!this.isPopoverVisibleInState);
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
177
|
}
|
|
166
178
|
handleCancelButtonClick() {
|
|
167
|
-
|
|
179
|
+
this.core?.store.getState().setPopoverVisibility(false);
|
|
168
180
|
}
|
|
169
181
|
/**
|
|
170
182
|
* Moves focus to the next/previous list item in the list view. If you are at the top
|
|
@@ -203,20 +215,20 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
203
215
|
const isListViewVisible = this.hasResultsToShow && this.isFocused;
|
|
204
216
|
return (h("div", { class: classNames('searchcraft-popover-form searchcraft-popover-form-inline', {
|
|
205
217
|
'searchcraft-popover-form-active': isListViewVisible,
|
|
206
|
-
}) }, h("div", { class: 'searchcraft-popover-form-input searchcraft-popover-form-inline-input' }, h("searchcraft-input-form", { onInputFocus: this.handleInputFocus.bind(this) })), isListViewVisible && (h("div", { class: 'searchcraft-popover-form-inline-wrapper' }, h("searchcraft-popover-list-view", { popoverResultMappings: this.popoverResultMappings, searchClientResponseItems: this.searchClientResponseItems, adClientResponseItems: this.adClientResponseItems, searchResultsPage: this.searchResultsPage, searchResultsPerPage: this.searchResultsPerPage }), h("searchcraft-popover-footer",
|
|
218
|
+
}) }, h("div", { class: 'searchcraft-popover-form-input searchcraft-popover-form-inline-input' }, h("searchcraft-input-form", { onInputFocus: this.handleInputFocus.bind(this), searchcraftId: this.searchcraftId })), isListViewVisible && (h("div", { class: 'searchcraft-popover-form-inline-wrapper' }, h("searchcraft-popover-list-view", { popoverResultMappings: this.popoverResultMappings, searchClientResponseItems: this.searchClientResponseItems, adClientResponseItems: this.adClientResponseItems, searchResultsPage: this.searchResultsPage, searchResultsPerPage: this.searchResultsPerPage, searchcraftId: this.searchcraftId }), h("searchcraft-popover-footer", { searchcraftId: this.searchcraftId })))));
|
|
207
219
|
}
|
|
208
220
|
renderModalPopover() {
|
|
209
221
|
if (this.isPopoverVisibleInState) {
|
|
210
222
|
return (h("div", { class: classNames('searchcraft-popover-form searchcraft-popover-form-modal', {
|
|
211
223
|
'searchcraft-popover-form-active': this.hasResultsToShow,
|
|
212
|
-
}) }, h("div", { class: 'searchcraft-popover-form-modal-backdrop', onClick: this.handleModalBackdropClick }), h("div", { class: 'searchcraft-popover-form-modal-wrapper' }, h("div", { class: 'searchcraft-popover-form-input searchcraft-popover-form-modal-input' }, h("searchcraft-input-form", { onInputFocus: this.handleInputFocus.bind(this), onInputInit: this.handleInputInit.bind(this) }), h("button", { type: 'button', class: 'searchcraft-popover-form-cancel-button searchcraft-popover-form-modal-cancel-button', onClick: this.handleCancelButtonClick.bind(this) }, "Cancel")), h("div", { class: 'searchcraft-popover-form-modal-popover-list-view' }, this.hasResultsToShow && (h("searchcraft-popover-list-view", { popoverResultMappings: this.popoverResultMappings, searchClientResponseItems: this.searchClientResponseItems, adClientResponseItems: this.adClientResponseItems, searchResultsPage: this.searchResultsPage, searchResultsPerPage: this.searchResultsPerPage }))), h("searchcraft-popover-footer",
|
|
224
|
+
}) }, h("div", { class: 'searchcraft-popover-form-modal-backdrop', onClick: this.handleModalBackdropClick }), h("div", { class: 'searchcraft-popover-form-modal-wrapper' }, h("div", { class: 'searchcraft-popover-form-input searchcraft-popover-form-modal-input' }, h("searchcraft-input-form", { onInputFocus: this.handleInputFocus.bind(this), onInputInit: this.handleInputInit.bind(this), searchcraftId: this.searchcraftId }), h("button", { type: 'button', class: 'searchcraft-popover-form-cancel-button searchcraft-popover-form-modal-cancel-button', onClick: this.handleCancelButtonClick.bind(this) }, "Cancel")), h("div", { class: 'searchcraft-popover-form-modal-popover-list-view' }, this.hasResultsToShow && (h("searchcraft-popover-list-view", { popoverResultMappings: this.popoverResultMappings, searchClientResponseItems: this.searchClientResponseItems, adClientResponseItems: this.adClientResponseItems, searchResultsPage: this.searchResultsPage, searchResultsPerPage: this.searchResultsPerPage, searchcraftId: this.searchcraftId }))), h("searchcraft-popover-footer", { searchcraftId: this.searchcraftId }))));
|
|
213
225
|
}
|
|
214
226
|
}
|
|
215
227
|
renderFullscreenPopover() {
|
|
216
228
|
if (this.isPopoverVisibleInState) {
|
|
217
229
|
return (h("div", { class: classNames('searchcraft-popover-form searchcraft-popover-form-fullscreen', {
|
|
218
230
|
'searchcraft-popover-form-active': this.hasResultsToShow,
|
|
219
|
-
}) }, h("div", { class: 'searchcraft-popover-form-input searchcraft-popover-form-fullscreen-input' }, h("searchcraft-input-form", { onInputFocus: this.handleInputFocus.bind(this), onInputInit: this.handleInputInit.bind(this) }), h("button", { type: 'button', class: 'searchcraft-popover-form-cancel-button searchcraft-popover-form-fullscreen-cancel-button', onClick: this.handleCancelButtonClick.bind(this) }, "Cancel")), h("div", { class: 'searchcraft-popover-form-fullscreen-popover-list-view' }, this.hasResultsToShow && (h("searchcraft-popover-list-view", { popoverResultMappings: this.popoverResultMappings, searchClientResponseItems: this.searchClientResponseItems, adClientResponseItems: this.adClientResponseItems, searchResultsPage: this.searchResultsPage, searchResultsPerPage: this.searchResultsPerPage }))), h("searchcraft-popover-footer",
|
|
231
|
+
}) }, h("div", { class: 'searchcraft-popover-form-input searchcraft-popover-form-fullscreen-input' }, h("searchcraft-input-form", { onInputFocus: this.handleInputFocus.bind(this), onInputInit: this.handleInputInit.bind(this), searchcraftId: this.searchcraftId }), h("button", { type: 'button', class: 'searchcraft-popover-form-cancel-button searchcraft-popover-form-fullscreen-cancel-button', onClick: this.handleCancelButtonClick.bind(this) }, "Cancel")), h("div", { class: 'searchcraft-popover-form-fullscreen-popover-list-view' }, this.hasResultsToShow && (h("searchcraft-popover-list-view", { popoverResultMappings: this.popoverResultMappings, searchClientResponseItems: this.searchClientResponseItems, adClientResponseItems: this.adClientResponseItems, searchResultsPage: this.searchResultsPage, searchResultsPerPage: this.searchResultsPerPage, searchcraftId: this.searchcraftId }))), h("searchcraft-popover-footer", { searchcraftId: this.searchcraftId })));
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
render() {
|
|
@@ -234,8 +246,8 @@ const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
234
246
|
"popoverResultMappings": [16],
|
|
235
247
|
"hotkey": [1],
|
|
236
248
|
"hotkeyModifier": [1, "hotkey-modifier"],
|
|
249
|
+
"searchcraftId": [1, "searchcraft-id"],
|
|
237
250
|
"isPopoverVisibleInState": [32],
|
|
238
|
-
"unsubscribe": [32],
|
|
239
251
|
"searchClientResponseItems": [32],
|
|
240
252
|
"adClientResponseItems": [32],
|
|
241
253
|
"searchTerm": [32],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"searchcraft-popover-form.js","mappings":";;;;;;;;;;;;MAmDaA,wBAAsB;;;;;;;;;;;IAOzB,IAAI,GAAuC,QAAQ,CAAC;;;;IAIpD,qBAAqB,CAAyB;;;;IAI9C,MAAM,GAAY,GAAG,CAAC;;;;IAItB,cAAc,GAAwC,MAAM,CAAC;IAE5D,uBAAuB,GAAG,KAAK,CAAC;IAChC,WAAW,CAA2B;IACtC,yBAAyB,GAA+B,EAAE,CAAC;IAC3D,qBAAqB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,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,aAGzC,CACL,EACN,WAAK,KAAK,EAAC,uDAAuD,IAC/D,IAAI,CAAC,gBAAgB,KACpB,qCACE,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,EACjD,yBAAyB,EAAE,IAAI,CAAC,yBAAyB,EACzD,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,EACjD,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EACzC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,GAC/C,CACH,CACG,EACN,qCAA8B,CAC1B,EACN;SACH;KACF;IAED,MAAM;QACJ,QAAQ,IAAI,CAAC,IAAI;YACf,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACnC,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,uBAAuB,EAAE,CAAC;SACzC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftPopoverForm"],"sources":["src/components/searchcraft-popover-form/searchcraft-popover-form.tsx"],"sourcesContent":["import { Component, Element, Prop, State, h } from '@stencil/core';\nimport classNames from 'classnames';\nimport type {\n SearchClientResponseItem,\n AdClientResponseItem,\n PopoverResultMappings,\n} from '@searchcraft/core';\n\nimport { searchcraftStore } from '@store';\n\n/**\n * This web component is designed to display search results in a popover container that dynamically appears when the user interacts with a search input field, or when a popover-button is pressed.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftPopoverForm } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftPopoverForm } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-form type=\"inline\" />\n * ```\n *\n * ```js\n * // index.js\n * const popoverForm = document.querySelector('searchcraft-popover-form');\n *\n * popoverForm.popoverResultMappings = {};\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftPopoverForm type=\"inline\" popoverResultMappings={[]} />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftPopoverForm type=\"inline\" :popoverResultMappings=\"[]\"\" />\n * ```\n *\n */\n@Component({\n tag: 'searchcraft-popover-form',\n shadow: false,\n})\nexport class SearchcraftPopoverForm {\n /**\n * The type of popover form to render.\n * - `inline` - Renders inline with the rest of the content on the page. The search results pop over the page content.\n * - `fullscreen` - Renders in fullscreen view. Used together with the `searchcraft-popover-button` component.\n * - `modal` - Renders in a modal view. Used together with the `searchcraft-popover-button` component.\n */\n @Prop() type?: 'inline' | 'fullscreen' | 'modal' = 'inline';\n /**\n * Formats the content rendered for each result.\n */\n @Prop() popoverResultMappings?: PopoverResultMappings;\n /**\n * The hotkey that activates the popover.\n */\n @Prop() hotkey?: string = 'k';\n /**\n * The hotkey modifier that activates the popover. Used together with the `hotkey` prop.\n */\n @Prop() hotkeyModifier?: 'ctrl' | 'meta' | 'alt' | 'option' = 'meta';\n\n @State() isPopoverVisibleInState = false;\n @State() unsubscribe: (() => void) | undefined;\n @State() searchClientResponseItems: SearchClientResponseItem[] = [];\n @State() adClientResponseItems: AdClientResponseItem[] = [];\n @State() searchTerm: string | undefined;\n @State() isFocused = false;\n @State() breakpointSm = 576;\n @State() breakpointMd = 768;\n @State() breakpointLg = 992;\n @State() searchResultsPage;\n @State() searchResultsPerPage;\n\n @State() modalElement;\n\n @Element() hostElement!: HTMLElement;\n\n componentDidLoad() {\n // Loads the breakpoint values into state\n const computedStyle = getComputedStyle(document.documentElement);\n this.breakpointSm = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-sm').trim(),\n );\n this.breakpointMd = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-md').trim(),\n );\n this.breakpointLg = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-lg').trim(),\n );\n // Set popover visiblity in state\n this.isPopoverVisibleInState = searchcraftStore.getState().isPopoverVisible;\n\n // Add event listeners\n document.addEventListener('click', this.handleDocumentClick);\n document.addEventListener('keydown', this.handleDocumentKeyDown);\n\n // Subscribe to state events\n this.unsubscribe = searchcraftStore.subscribe((state) => {\n if (this.isPopoverVisibleInState !== state.isPopoverVisible) {\n this.handlePopoverVisibilityChange(state.isPopoverVisible);\n }\n\n this.searchClientResponseItems = [...state.searchClientResponseItems];\n this.adClientResponseItems = [...state.adClientResponseItems];\n this.searchTerm = state.searchTerm;\n this.searchResultsPage = state.searchResultsPage;\n this.searchResultsPerPage = state.searchResultsPerPage;\n });\n\n // Set hotkey and hotkeyModifier in state.\n searchcraftStore\n .getState()\n .setHotKeyAndHotKeyModifier(this.hotkey, this.hotkeyModifier);\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n document.removeEventListener('click', this.handleDocumentClick);\n document.removeEventListener('keydown', this.handleDocumentKeyDown);\n }\n\n handleDocumentClick = (event: MouseEvent) => {\n if (!this.hostElement.contains(event.target as Node)) {\n this.isFocused = false;\n }\n };\n\n /**\n * Handles when popover visibility is changed in state\n */\n handlePopoverVisibilityChange(isVisible: boolean) {\n this.isPopoverVisibleInState = isVisible;\n document.body.style.overflow = isVisible ? 'hidden' : 'auto';\n }\n\n /**\n * Actions to perform when various keys are pressed within the popover form.\n */\n handleDocumentKeyDown = (event: KeyboardEvent) => {\n // Document-scoped actions\n if (event.key === this.hotkey) {\n this.handleHotkeyPressed(event);\n }\n\n // Document-scoped -> Popover-scoped keyboard event boundary\n if (!this.hostElement.contains(document.activeElement)) {\n return;\n }\n\n // Popover-scoped actions\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n this.focusOnNextListItem(event.key);\n break;\n case 'Escape':\n searchcraftStore.getState().setPopoverVisibility(false);\n break;\n default:\n return;\n }\n };\n\n handleInputInit = () => {\n const input = this.hostElement.querySelector(\n '.searchcraft-input-form-input',\n ) as HTMLInputElement | undefined;\n input?.focus();\n };\n\n /**\n * When popover is `inline` and the viewport is at the smallest breakpoint,\n * focusing on the input will open a modal version of the popover form.\n */\n handleInputFocus() {\n this.isFocused = true;\n\n if (\n this.type === 'inline' &&\n window.visualViewport &&\n window.visualViewport.width < this.breakpointSm\n ) {\n searchcraftStore.getState().setPopoverVisibility(true);\n\n // Appends a popover form of type=`modal` to the body\n if (!this.modalElement) {\n this.modalElement = document.createElement('searchcraft-popover-form');\n this.modalElement.popoverResultMappings = this.popoverResultMappings;\n this.modalElement.setAttribute('type', 'fullscreen');\n document.body.appendChild(this.modalElement);\n }\n }\n }\n\n handleModalBackdropClick(_event: MouseEvent) {\n searchcraftStore.getState().setPopoverVisibility(false);\n }\n\n /**\n * When a hotkey is pressed, tests if the modifiers also match.\n * If modifiers match, toggles visibility of the popover modal.\n */\n handleHotkeyPressed(event: KeyboardEvent) {\n if (\n (event.ctrlKey && this.hotkeyModifier === 'ctrl') ||\n (event.altKey && this.hotkeyModifier === 'alt') ||\n (event.metaKey && this.hotkeyModifier === 'meta')\n ) {\n event.preventDefault();\n if (this.type === 'inline' && !this.isPopoverVisibleInState) {\n const hostElementInput = this.hostElement.querySelector(\n '.searchcraft-input-form-input',\n ) as HTMLInputElement | undefined;\n hostElementInput?.focus();\n } else {\n searchcraftStore\n .getState()\n .setPopoverVisibility(!this.isPopoverVisibleInState);\n }\n }\n }\n\n handleCancelButtonClick() {\n searchcraftStore.getState().setPopoverVisibility(false);\n }\n\n /**\n * Moves focus to the next/previous list item in the list view. If you are at the top\n * of the list view, it moves focus back to the input.\n *\n * @param direction\n */\n focusOnNextListItem(direction: 'ArrowDown' | 'ArrowUp') {\n const listItems = Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n '.searchcraft-popover-list-item-link',\n ),\n ).filter((el) => !el.hasAttribute('disabled') && el.offsetParent !== null);\n\n const currentIndex = listItems.indexOf(\n document.activeElement as HTMLAnchorElement,\n );\n\n if (direction === 'ArrowDown') {\n listItems[(currentIndex + 1) % listItems.length]?.focus();\n } else if (direction === 'ArrowUp') {\n if (currentIndex >= 1) {\n listItems[currentIndex - 1]?.focus();\n } else {\n const input = document.querySelector('.searchcraft-input-form-input') as\n | HTMLInputElement\n | undefined;\n\n if (input) {\n input.focus();\n requestAnimationFrame(() => {\n input.selectionEnd = input.value.length;\n input.selectionStart = input.value.length;\n });\n }\n }\n }\n }\n\n get hasResultsToShow() {\n return (\n this.searchTerm &&\n this.searchTerm?.trim()?.length > 0 &&\n this.searchClientResponseItems.length > 0\n );\n }\n\n renderInlinePopover() {\n const isListViewVisible = this.hasResultsToShow && this.isFocused;\n\n return (\n <div\n class={classNames(\n 'searchcraft-popover-form searchcraft-popover-form-inline',\n {\n 'searchcraft-popover-form-active': isListViewVisible,\n },\n )}\n >\n <div class='searchcraft-popover-form-input searchcraft-popover-form-inline-input'>\n <searchcraft-input-form\n onInputFocus={this.handleInputFocus.bind(this)}\n />\n </div>\n {isListViewVisible && (\n <div class='searchcraft-popover-form-inline-wrapper'>\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n searchClientResponseItems={this.searchClientResponseItems}\n adClientResponseItems={this.adClientResponseItems}\n searchResultsPage={this.searchResultsPage}\n searchResultsPerPage={this.searchResultsPerPage}\n />\n <searchcraft-popover-footer />\n </div>\n )}\n </div>\n );\n }\n\n renderModalPopover() {\n if (this.isPopoverVisibleInState) {\n return (\n <div\n class={classNames(\n 'searchcraft-popover-form searchcraft-popover-form-modal',\n {\n 'searchcraft-popover-form-active': this.hasResultsToShow,\n },\n )}\n >\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: <explanation> */}\n <div\n class='searchcraft-popover-form-modal-backdrop'\n onClick={this.handleModalBackdropClick}\n />\n <div class='searchcraft-popover-form-modal-wrapper'>\n <div class='searchcraft-popover-form-input searchcraft-popover-form-modal-input'>\n <searchcraft-input-form\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button searchcraft-popover-form-modal-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n <div class='searchcraft-popover-form-modal-popover-list-view'>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n searchClientResponseItems={this.searchClientResponseItems}\n adClientResponseItems={this.adClientResponseItems}\n searchResultsPage={this.searchResultsPage}\n searchResultsPerPage={this.searchResultsPerPage}\n />\n )}\n </div>\n <searchcraft-popover-footer />\n </div>\n </div>\n );\n }\n }\n\n renderFullscreenPopover() {\n if (this.isPopoverVisibleInState) {\n return (\n <div\n class={classNames(\n 'searchcraft-popover-form searchcraft-popover-form-fullscreen',\n {\n 'searchcraft-popover-form-active': this.hasResultsToShow,\n },\n )}\n >\n <div class='searchcraft-popover-form-input searchcraft-popover-form-fullscreen-input'>\n <searchcraft-input-form\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button searchcraft-popover-form-fullscreen-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n <div class='searchcraft-popover-form-fullscreen-popover-list-view'>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n searchClientResponseItems={this.searchClientResponseItems}\n adClientResponseItems={this.adClientResponseItems}\n searchResultsPage={this.searchResultsPage}\n searchResultsPerPage={this.searchResultsPerPage}\n />\n )}\n </div>\n <searchcraft-popover-footer />\n </div>\n );\n }\n }\n\n render() {\n switch (this.type) {\n case 'inline':\n return this.renderInlinePopover();\n case 'modal':\n return this.renderModalPopover();\n case 'fullscreen':\n return this.renderFullscreenPopover();\n }\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"searchcraft-popover-form.js","mappings":";;;;;;;;;;;;MAmDaA,wBAAsB;;;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ACzD,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,EACjD,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EACzC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,EAC/C,aAAa,EAAE,IAAI,CAAC,aAAa,GACjC,CACH,CACG,EACN,kCAA4B,aAAa,EAAE,IAAI,CAAC,aAAa,GAAI,CAC7D,EACN;SACH;KACF;IAED,MAAM;QACJ,QAAQ,IAAI,CAAC,IAAI;YACf,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACnC,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,uBAAuB,EAAE,CAAC;SACzC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftPopoverForm"],"sources":["src/components/searchcraft-popover-form/searchcraft-popover-form.tsx"],"sourcesContent":["import { Component, Element, Prop, State, h } from '@stencil/core';\nimport classNames from 'classnames';\nimport type {\n SearchClientResponseItem,\n AdClientResponseItem,\n PopoverResultMappings,\n} from '@types';\nimport { registry } from '@classes/CoreInstanceRegistry';\nimport type { SearchcraftCore } from '@classes';\n\n/**\n * This web component is designed to display search results in a popover container that dynamically appears when the user interacts with a search input field, or when a popover-button is pressed.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftPopoverForm } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftPopoverForm } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-form type=\"inline\" />\n * ```\n *\n * ```js\n * // index.js\n * const popoverForm = document.querySelector('searchcraft-popover-form');\n *\n * popoverForm.popoverResultMappings = {};\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftPopoverForm type=\"inline\" popoverResultMappings={[]} />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftPopoverForm type=\"inline\" :popoverResultMappings=\"[]\"\" />\n * ```\n *\n */\n@Component({\n tag: 'searchcraft-popover-form',\n shadow: false,\n})\nexport class SearchcraftPopoverForm {\n /**\n * The type of popover form to render.\n * - `inline` - Renders inline with the rest of the content on the page. The search results pop over the page content.\n * - `fullscreen` - Renders in fullscreen view. Used together with the `searchcraft-popover-button` component.\n * - `modal` - Renders in a modal view. Used together with the `searchcraft-popover-button` component.\n */\n @Prop() type?: 'inline' | 'fullscreen' | 'modal' = 'inline';\n /**\n * Formats the content rendered for each result.\n */\n @Prop() popoverResultMappings?: PopoverResultMappings;\n /**\n * The hotkey that activates the popover.\n */\n @Prop() hotkey?: string = 'k';\n /**\n * The hotkey modifier that activates the popover. Used together with the `hotkey` prop.\n */\n @Prop() hotkeyModifier?: 'ctrl' | 'meta' | 'alt' | 'option' = 'meta';\n /**\n * The id of the Searchcraft instance that this component should use.\n */\n @Prop() searchcraftId?: string;\n\n @State() isPopoverVisibleInState = false;\n @State() searchClientResponseItems: SearchClientResponseItem[] = [];\n @State() adClientResponseItems: AdClientResponseItem[] = [];\n @State() searchTerm: string | undefined;\n @State() isFocused = false;\n @State() breakpointSm = 576;\n @State() breakpointMd = 768;\n @State() breakpointLg = 992;\n @State() searchResultsPage;\n @State() searchResultsPerPage;\n\n @State() modalElement;\n\n @Element() hostElement!: HTMLElement;\n\n private unsubscribe: (() => void) | undefined;\n private cleanupCore?: () => void;\n core?: SearchcraftCore;\n\n onCoreAvailable(core: SearchcraftCore) {\n this.core = core;\n // Loads the breakpoint values into state\n const computedStyle = getComputedStyle(document.documentElement);\n this.breakpointSm = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-sm').trim(),\n );\n this.breakpointMd = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-md').trim(),\n );\n this.breakpointLg = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-lg').trim(),\n );\n // Set popover visiblity in state\n this.isPopoverVisibleInState = core.store.getState().isPopoverVisible;\n\n // Add event listeners\n document.addEventListener('click', this.handleDocumentClick);\n document.addEventListener('keydown', this.handleDocumentKeyDown);\n\n // Subscribe to state events\n this.unsubscribe = core.store.subscribe((state) => {\n if (this.isPopoverVisibleInState !== state.isPopoverVisible) {\n this.handlePopoverVisibilityChange(state.isPopoverVisible);\n }\n\n this.searchClientResponseItems = [...state.searchClientResponseItems];\n this.adClientResponseItems = [...state.adClientResponseItems];\n this.searchTerm = state.searchTerm;\n this.searchResultsPage = state.searchResultsPage;\n this.searchResultsPerPage = state.searchResultsPerPage;\n });\n\n // Set hotkey and hotkeyModifier in state.\n core.store\n .getState()\n .setHotKeyAndHotKeyModifier(this.hotkey, this.hotkeyModifier);\n }\n\n connectedCallback() {\n this.cleanupCore = registry.useCoreInstance(\n this.searchcraftId,\n this.onCoreAvailable.bind(this),\n );\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n this.cleanupCore?.();\n document.removeEventListener('click', this.handleDocumentClick);\n document.removeEventListener('keydown', this.handleDocumentKeyDown);\n }\n\n handleDocumentClick = (event: MouseEvent) => {\n if (!this.hostElement.contains(event.target as Node)) {\n this.isFocused = false;\n }\n };\n\n /**\n * Handles when popover visibility is changed in state\n */\n handlePopoverVisibilityChange(isVisible: boolean) {\n this.isPopoverVisibleInState = isVisible;\n document.body.style.overflow = isVisible ? 'hidden' : 'auto';\n }\n\n /**\n * Actions to perform when various keys are pressed within the popover form.\n */\n handleDocumentKeyDown = (event: KeyboardEvent) => {\n // Document-scoped actions\n if (event.key === this.hotkey) {\n this.handleHotkeyPressed(event);\n }\n\n // Document-scoped -> Popover-scoped keyboard event boundary\n if (!this.hostElement.contains(document.activeElement)) {\n return;\n }\n\n // Popover-scoped actions\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n this.focusOnNextListItem(event.key);\n break;\n case 'Escape':\n this.core?.store.getState().setPopoverVisibility(false);\n break;\n default:\n return;\n }\n };\n\n handleInputInit = () => {\n const input = this.hostElement.querySelector(\n '.searchcraft-input-form-input',\n ) as HTMLInputElement | undefined;\n input?.focus();\n };\n\n /**\n * When popover is `inline` and the viewport is at the smallest breakpoint,\n * focusing on the input will open a modal version of the popover form.\n */\n handleInputFocus() {\n this.isFocused = true;\n\n if (\n this.type === 'inline' &&\n window.visualViewport &&\n window.visualViewport.width < this.breakpointSm\n ) {\n this.core?.store.getState().setPopoverVisibility(true);\n\n // Appends a popover form of type=`modal` to the body\n if (!this.modalElement) {\n this.modalElement = document.createElement('searchcraft-popover-form');\n this.modalElement.popoverResultMappings = this.popoverResultMappings;\n this.modalElement.setAttribute('type', 'fullscreen');\n this.modalElement.setAttribute('searchcraft-id', this.searchcraftId);\n document.body.appendChild(this.modalElement);\n }\n }\n }\n\n handleModalBackdropClick(_event: MouseEvent) {\n this.core?.store.getState().setPopoverVisibility(false);\n }\n\n /**\n * When a hotkey is pressed, tests if the modifiers also match.\n * If modifiers match, toggles visibility of the popover modal.\n */\n handleHotkeyPressed(event: KeyboardEvent) {\n if (\n (event.ctrlKey && this.hotkeyModifier === 'ctrl') ||\n (event.altKey && this.hotkeyModifier === 'alt') ||\n (event.metaKey && this.hotkeyModifier === 'meta')\n ) {\n event.preventDefault();\n if (this.type === 'inline' && !this.isPopoverVisibleInState) {\n const hostElementInput = this.hostElement.querySelector(\n '.searchcraft-input-form-input',\n ) as HTMLInputElement | undefined;\n hostElementInput?.focus();\n } else {\n this.core?.store\n .getState()\n .setPopoverVisibility(!this.isPopoverVisibleInState);\n }\n }\n }\n\n handleCancelButtonClick() {\n this.core?.store.getState().setPopoverVisibility(false);\n }\n\n /**\n * Moves focus to the next/previous list item in the list view. If you are at the top\n * of the list view, it moves focus back to the input.\n *\n * @param direction\n */\n focusOnNextListItem(direction: 'ArrowDown' | 'ArrowUp') {\n const listItems = Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n '.searchcraft-popover-list-item-link',\n ),\n ).filter((el) => !el.hasAttribute('disabled') && el.offsetParent !== null);\n\n const currentIndex = listItems.indexOf(\n document.activeElement as HTMLAnchorElement,\n );\n\n if (direction === 'ArrowDown') {\n listItems[(currentIndex + 1) % listItems.length]?.focus();\n } else if (direction === 'ArrowUp') {\n if (currentIndex >= 1) {\n listItems[currentIndex - 1]?.focus();\n } else {\n const input = document.querySelector('.searchcraft-input-form-input') as\n | HTMLInputElement\n | undefined;\n\n if (input) {\n input.focus();\n requestAnimationFrame(() => {\n input.selectionEnd = input.value.length;\n input.selectionStart = input.value.length;\n });\n }\n }\n }\n }\n\n get hasResultsToShow() {\n return (\n this.searchTerm &&\n this.searchTerm?.trim()?.length > 0 &&\n this.searchClientResponseItems.length > 0\n );\n }\n\n renderInlinePopover() {\n const isListViewVisible = this.hasResultsToShow && this.isFocused;\n\n return (\n <div\n class={classNames(\n 'searchcraft-popover-form searchcraft-popover-form-inline',\n {\n 'searchcraft-popover-form-active': isListViewVisible,\n },\n )}\n >\n <div class='searchcraft-popover-form-input searchcraft-popover-form-inline-input'>\n <searchcraft-input-form\n onInputFocus={this.handleInputFocus.bind(this)}\n searchcraftId={this.searchcraftId}\n />\n </div>\n {isListViewVisible && (\n <div class='searchcraft-popover-form-inline-wrapper'>\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n searchClientResponseItems={this.searchClientResponseItems}\n adClientResponseItems={this.adClientResponseItems}\n searchResultsPage={this.searchResultsPage}\n searchResultsPerPage={this.searchResultsPerPage}\n searchcraftId={this.searchcraftId}\n />\n <searchcraft-popover-footer searchcraftId={this.searchcraftId} />\n </div>\n )}\n </div>\n );\n }\n\n renderModalPopover() {\n if (this.isPopoverVisibleInState) {\n return (\n <div\n class={classNames(\n 'searchcraft-popover-form searchcraft-popover-form-modal',\n {\n 'searchcraft-popover-form-active': this.hasResultsToShow,\n },\n )}\n >\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: <explanation> */}\n <div\n class='searchcraft-popover-form-modal-backdrop'\n onClick={this.handleModalBackdropClick}\n />\n <div class='searchcraft-popover-form-modal-wrapper'>\n <div class='searchcraft-popover-form-input searchcraft-popover-form-modal-input'>\n <searchcraft-input-form\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n searchcraftId={this.searchcraftId}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button searchcraft-popover-form-modal-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n <div class='searchcraft-popover-form-modal-popover-list-view'>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n searchClientResponseItems={this.searchClientResponseItems}\n adClientResponseItems={this.adClientResponseItems}\n searchResultsPage={this.searchResultsPage}\n searchResultsPerPage={this.searchResultsPerPage}\n searchcraftId={this.searchcraftId}\n />\n )}\n </div>\n <searchcraft-popover-footer searchcraftId={this.searchcraftId} />\n </div>\n </div>\n );\n }\n }\n\n renderFullscreenPopover() {\n if (this.isPopoverVisibleInState) {\n return (\n <div\n class={classNames(\n 'searchcraft-popover-form searchcraft-popover-form-fullscreen',\n {\n 'searchcraft-popover-form-active': this.hasResultsToShow,\n },\n )}\n >\n <div class='searchcraft-popover-form-input searchcraft-popover-form-fullscreen-input'>\n <searchcraft-input-form\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n searchcraftId={this.searchcraftId}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button searchcraft-popover-form-fullscreen-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n <div class='searchcraft-popover-form-fullscreen-popover-list-view'>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n searchClientResponseItems={this.searchClientResponseItems}\n adClientResponseItems={this.adClientResponseItems}\n searchResultsPage={this.searchResultsPage}\n searchResultsPerPage={this.searchResultsPerPage}\n searchcraftId={this.searchcraftId}\n />\n )}\n </div>\n <searchcraft-popover-footer searchcraftId={this.searchcraftId} />\n </div>\n );\n }\n }\n\n render() {\n switch (this.type) {\n case 'inline':\n return this.renderInlinePopover();\n case 'modal':\n return this.renderModalPopover();\n case 'fullscreen':\n return this.renderFullscreenPopover();\n }\n }\n}\n"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftPopoverListItem$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftPopoverListItem$1, d as defineCustomElement$1 } from './p-fc8ccffa.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftPopoverListItem = SearchcraftPopoverListItem$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftPopoverListView$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftPopoverListView$1, d as defineCustomElement$1 } from './p-b13c7fbb.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftPopoverListView = SearchcraftPopoverListView$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, h } from './p-5365011f.js';
|
|
2
|
-
import {
|
|
2
|
+
import { r as registry } from './p-e30203b1.js';
|
|
3
3
|
import { f as formatNumberWithCommas } from './p-d54771ef.js';
|
|
4
|
-
import { h as html } from './p-
|
|
4
|
+
import { h as html } from './p-b4b67072.js';
|
|
5
5
|
|
|
6
6
|
const SearchcraftResultsInfo$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftResultsInfo extends H {
|
|
7
7
|
constructor() {
|
|
@@ -12,6 +12,10 @@ const SearchcraftResultsInfo$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
12
12
|
* A callback function responsible for rendering the results info.
|
|
13
13
|
*/
|
|
14
14
|
template;
|
|
15
|
+
/**
|
|
16
|
+
* The id of the Searchcraft instance that this component should use.
|
|
17
|
+
*/
|
|
18
|
+
searchcraftId;
|
|
15
19
|
// store vars
|
|
16
20
|
searchTerm;
|
|
17
21
|
searchResultsPage;
|
|
@@ -22,8 +26,9 @@ const SearchcraftResultsInfo$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
22
26
|
range = [0, 0];
|
|
23
27
|
responseTime = '0';
|
|
24
28
|
unsubscribe = () => { };
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
cleanupCore;
|
|
30
|
+
onCoreAvailable(core) {
|
|
31
|
+
this.unsubscribe = core.store.subscribe((state) => {
|
|
27
32
|
// store vars
|
|
28
33
|
this.searchTerm = state.searchTerm;
|
|
29
34
|
this.searchResultsPage = state.searchResultsPage;
|
|
@@ -43,10 +48,12 @@ const SearchcraftResultsInfo$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
43
48
|
this.responseTime = ((state.searchResponseTimeTaken || 0) * 1000).toFixed(2);
|
|
44
49
|
});
|
|
45
50
|
}
|
|
51
|
+
connectedCallback() {
|
|
52
|
+
this.cleanupCore = registry.useCoreInstance(this.searchcraftId, this.onCoreAvailable.bind(this));
|
|
53
|
+
}
|
|
46
54
|
disconnectedCallback() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
55
|
+
this.unsubscribe?.();
|
|
56
|
+
this.cleanupCore?.();
|
|
50
57
|
}
|
|
51
58
|
render() {
|
|
52
59
|
if (!this.searchTerm || this.searchResultsCount === 0) {
|
|
@@ -62,6 +69,7 @@ const SearchcraftResultsInfo$1 = /*@__PURE__*/ proxyCustomElement(class Searchcr
|
|
|
62
69
|
}
|
|
63
70
|
}, [0, "searchcraft-results-info", {
|
|
64
71
|
"template": [16],
|
|
72
|
+
"searchcraftId": [1, "searchcraft-id"],
|
|
65
73
|
"searchTerm": [32],
|
|
66
74
|
"searchResultsPage": [32],
|
|
67
75
|
"searchResultsPerPage": [32],
|
|
@@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I,CAAC,kBAAkB;sBACnC,IAAI,CAAC,kBAAkB;sBACvB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,IAAI,EAAE,OAAO,CACvE,CAAC,CACF,CAAC;SACH,CAAC,CAAC;KACJ;IAED,iBAAiB;QACf,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,eAAe,CACzC,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC,CAAC;KACH;IAED,oBAAoB;QAClB,IAAI,CAAC,WAAW,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,IAAI,CAAC;KACtB;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,kBAAkB,KAAK,CAAC,EAAE;YACrD,OAAO,IAAI,CAAC;SACb;QAED,QACE,SAAG,KAAK,EAAC,0BAA0B,IAChC,OAAO,IAAI,CAAC,QAAQ,KAAK,WAAW;cACjC,IAAI,CAAC,QAAQ,CACX;gBACE,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrD,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,YAAY,EAAE,IAAI,CAAC,YAAY;aAChC,EACD,EAAE,IAAI,EAAE,CACT;cACD,GAAG,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,IAAI,CAAC,YAAY,IAAI,CACjF,EACJ;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftResultsInfo"],"sources":["src/components/searchcraft-results-info/searchcraft-results-info.tsx"],"sourcesContent":["import type { SearchcraftCore } from '@classes';\nimport { registry } from '@classes/CoreInstanceRegistry';\nimport { Component, h, State, Prop } from '@stencil/core';\n\nimport type { ResultsInfoTemplate } from '@types';\n\nimport { formatNumberWithCommas, html } from '@utils';\n\n/**\n * This web component is designed to display the number of results returned from a search query.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftResultsInfo } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftResultsInfo } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-results-info />\n * ```\n *\n * ```js\n * // index.js\n * const resultsInfo = document.querySelector('searchcraft-results-info');\n *\n * resultsInfo.template = (info, { html }) => html`\n * ${info.range[0]}-${info.range[1]} of ${info.count} results in ${info.responseTime}ms\n * `;\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftResultsInfo\n * template={(info, { html }) => html`\n * ${info.range[0]}-${info.range[1]} of ${info.count} results in ${info.responseTime}ms\n * `}\n * />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftResultsInfo\n * :template={(info, { html }) => html`\n * ${info.range[0]}-${info.range[1]} of ${info.count} results in ${info.responseTime}ms\n * `}\n * />\n * ```\n */\n@Component({\n tag: 'searchcraft-results-info',\n shadow: false,\n})\nexport class SearchcraftResultsInfo {\n /**\n * A callback function responsible for rendering the results info.\n */\n @Prop() template?: ResultsInfoTemplate;\n /**\n * The id of the Searchcraft instance that this component should use.\n */\n @Prop() searchcraftId?: string;\n\n // store vars\n @State() searchTerm;\n @State() searchResultsPage;\n @State() searchResultsPerPage;\n @State() searchResultsCount;\n\n // local vars\n @State() count = 0;\n @State() range: number[] = [0, 0];\n @State() responseTime = '0';\n\n unsubscribe: () => void = () => {};\n private cleanupCore?: () => void;\n\n onCoreAvailable(core: SearchcraftCore) {\n this.unsubscribe = core.store.subscribe((state) => {\n // store vars\n this.searchTerm = state.searchTerm;\n this.searchResultsPage = state.searchResultsPage;\n this.searchResultsPerPage = state.searchResultsPerPage;\n this.searchResultsCount = state.searchResultsCount;\n\n // local vars\n this.count = this.searchResultsCount;\n this.range[0] =\n this.searchResultsPage <= 1\n ? 1\n : this.searchResultsPerPage * (this.searchResultsPage - 1);\n this.range[1] = this.searchResultsPerPage * this.searchResultsPage;\n this.range[1] =\n this.range[1] > this.searchResultsCount\n ? this.searchResultsCount\n : this.range[1];\n this.responseTime = ((state.searchResponseTimeTaken || 0) * 1000).toFixed(\n 2,\n );\n });\n }\n\n connectedCallback() {\n this.cleanupCore = registry.useCoreInstance(\n this.searchcraftId,\n this.onCoreAvailable.bind(this),\n );\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n this.cleanupCore?.();\n }\n\n render() {\n if (!this.searchTerm || this.searchResultsCount === 0) {\n return null;\n }\n\n return (\n <p class='searchcraft-results-info'>\n {typeof this.template !== 'undefined'\n ? this.template(\n {\n range: [Number(this.range[0]), Number(this.range[1])],\n count: this.count,\n responseTime: this.responseTime,\n },\n { html },\n )\n : `${formatNumberWithCommas(this.count)} results found in ${this.responseTime}ms`}\n </p>\n );\n }\n}\n"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftSearchResult$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftSearchResult$1, d as defineCustomElement$1 } from './p-3286bbb3.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftSearchResult = SearchcraftSearchResult$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, h } from './p-5365011f.js';
|
|
2
|
-
import {
|
|
2
|
+
import { r as registry } from './p-e30203b1.js';
|
|
3
3
|
import { d as defineCustomElement$2 } from './p-73db9122.js';
|
|
4
4
|
|
|
5
5
|
const SearchcraftSearchResultsPerPage$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftSearchResultsPerPage extends H {
|
|
@@ -12,6 +12,10 @@ const SearchcraftSearchResultsPerPage$1 = /*@__PURE__*/ proxyCustomElement(class
|
|
|
12
12
|
* The base value is defined by the `searchResultsPerPage` option in the configuration.
|
|
13
13
|
*/
|
|
14
14
|
increment = 20;
|
|
15
|
+
/**
|
|
16
|
+
* The id of the Searchcraft instance that this component should use.
|
|
17
|
+
*/
|
|
18
|
+
searchcraftId;
|
|
15
19
|
// store vars
|
|
16
20
|
searchTerm;
|
|
17
21
|
searchResultsPage;
|
|
@@ -24,8 +28,9 @@ const SearchcraftSearchResultsPerPage$1 = /*@__PURE__*/ proxyCustomElement(class
|
|
|
24
28
|
setSearchResultsPerPage = () => { };
|
|
25
29
|
setSearchResultsPage = () => { };
|
|
26
30
|
unsubscribe = () => { };
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
cleanupCore;
|
|
32
|
+
onCoreAvailable(core) {
|
|
33
|
+
this.unsubscribe = core.store.subscribe((state) => {
|
|
29
34
|
// store vars
|
|
30
35
|
this.searchTerm = state.searchTerm;
|
|
31
36
|
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
@@ -38,10 +43,14 @@ const SearchcraftSearchResultsPerPage$1 = /*@__PURE__*/ proxyCustomElement(class
|
|
|
38
43
|
this.setSearchResultsPerPage = state.setSearchResultsPerPage;
|
|
39
44
|
});
|
|
40
45
|
this.initialSearchResultsPerPage =
|
|
41
|
-
|
|
46
|
+
core.store.getState().searchResultsPerPage;
|
|
47
|
+
}
|
|
48
|
+
connectedCallback() {
|
|
49
|
+
this.cleanupCore = registry.useCoreInstance(this.searchcraftId, this.onCoreAvailable.bind(this));
|
|
42
50
|
}
|
|
43
51
|
disconnectedCallback() {
|
|
44
52
|
this.unsubscribe?.();
|
|
53
|
+
this.cleanupCore?.();
|
|
45
54
|
}
|
|
46
55
|
render() {
|
|
47
56
|
// early return if there isn't a searchTerm or there is 1 or fewer pages of results
|
|
@@ -62,6 +71,7 @@ const SearchcraftSearchResultsPerPage$1 = /*@__PURE__*/ proxyCustomElement(class
|
|
|
62
71
|
}
|
|
63
72
|
}, [0, "searchcraft-search-results-per-page", {
|
|
64
73
|
"increment": [8],
|
|
74
|
+
"searchcraftId": [1, "searchcraft-id"],
|
|
65
75
|
"searchTerm": [32],
|
|
66
76
|
"searchResultsPage": [32],
|
|
67
77
|
"searchResultsPerPage": [32],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"searchcraft-search-results-per-page.js","mappings":";;;;
|
|
1
|
+
{"file":"searchcraft-search-results-per-page.js","mappings":";;;;MAqCaA,iCAA+B;;;;;;;;;IAKlC,SAAS,GAAoB,EAAE,CAAC;;;;IAIhC,aAAa,CAAU;;IAGtB,UAAU,CAAC;IACX,iBAAiB,CAAC;IAClB,oBAAoB,CAAC;IACrB,kBAAkB,CAAC;IACnB,uBAAuB,CAAC;;IAGxB,2BAA2B,CAAC;;IAG5B,uBAAuB,GAA8B,SAAQ,CAAC;IAC9D,oBAAoB,GAA2B,SAAQ,CAAC;IAEzD,WAAW,GAAe,SAAQ,CAAC;IACnC,WAAW,CAAc;IAEjC,eAAe,CAAC,IAAqB;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK;;YAE5C,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;YACnC,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC,oBAAoB,CAAC;YACvD,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC;YACjD,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC;;YAGnD,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,IAAI,CACtC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,oBAAoB,CACpD,CAAC;;YAGF,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC,oBAAoB,CAAC;YACvD,IAAI,CAAC,uBAAuB,GAAG,KAAK,CAAC,uBAAuB,CAAC;SAC9D,CAAC,CAAC;QAEH,IAAI,CAAC,2BAA2B;YAC9B,IAAI,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-page/searchcraft-search-results-per-page.tsx"],"sourcesContent":["import type { SearchcraftCore } from '@classes';\nimport { registry } from '@classes/CoreInstanceRegistry';\nimport { Component, h, State, Prop } from '@stencil/core';\n\n/**\n * This web component is designed to choose the number of search results displayed.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftSearchResultsPerPage } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftSearchResultsPerPage } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-search-results-per-page increment=\"20\" />\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftSearchResultsPerPage increment={20} />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftSearchResultsPerPage increment=\"20\" />\n * ```\n */\n@Component({\n tag: 'searchcraft-search-results-per-page',\n shadow: false,\n})\nexport class SearchcraftSearchResultsPerPage {\n /**\n * The amount the options will increase (e.g. 20 = [20, 40, 60, 80, 100]).\n * The base value is defined by the `searchResultsPerPage` option in the configuration.\n */\n @Prop() increment: string | number = 20;\n /**\n * The id of the Searchcraft instance that this component should use.\n */\n @Prop() searchcraftId?: string;\n\n // store vars\n @State() searchTerm;\n @State() searchResultsPage;\n @State() searchResultsPerPage;\n @State() searchResultsCount;\n @State() searchResultsPagesCount;\n\n // local vars\n @State() initialSearchResultsPerPage;\n\n // store functions\n @State() setSearchResultsPerPage: (perPage: number) => void = () => {};\n @State() setSearchResultsPage: (page: number) => void = () => {};\n\n private unsubscribe: () => void = () => {};\n private cleanupCore?: () => void;\n\n onCoreAvailable(core: SearchcraftCore) {\n this.unsubscribe = core.store.subscribe((state) => {\n // store vars\n this.searchTerm = state.searchTerm;\n this.searchResultsPerPage = state.searchResultsPerPage;\n this.searchResultsPage = state.searchResultsPage;\n this.searchResultsCount = state.searchResultsCount;\n\n // local vars\n this.searchResultsPagesCount = Math.ceil(\n this.searchResultsCount / this.searchResultsPerPage,\n );\n\n // store functions\n this.setSearchResultsPage = state.setSearchResultsPage;\n this.setSearchResultsPerPage = state.setSearchResultsPerPage;\n });\n\n this.initialSearchResultsPerPage =\n core.store.getState().searchResultsPerPage;\n }\n\n connectedCallback() {\n this.cleanupCore = registry.useCoreInstance(\n this.searchcraftId,\n this.onCoreAvailable.bind(this),\n );\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n this.cleanupCore?.();\n }\n\n render() {\n // early return if there isn't a searchTerm or there is 1 or fewer pages of results\n if (!this.searchTerm || this.searchResultsPagesCount <= 1) {\n return;\n }\n\n return (\n <div class='searchcraft-search-results-per-page'>\n <div class='searchcraft-search-results-per-page-select'>\n <label\n class='searchcraft-search-results-per-page-select-label'\n htmlFor='searchcraft-search-results-per-page-select-input'\n >\n Results Per Page\n </label>\n <div class='searchcraft-search-results-per-page-select-input'>\n <searchcraft-select\n inputId='searchcraft-search-results-per-page-select-input'\n name='results-per-page'\n options={[...Array(5)].map((_, index) => {\n const value =\n this.initialSearchResultsPerPage +\n Number(this.increment) * index;\n return {\n label: `${value}`,\n value,\n };\n })}\n onSelectChange={(event) => {\n this.setSearchResultsPerPage(Number(event.detail));\n this.setSearchResultsPage(1);\n }}\n />\n </div>\n </div>\n </div>\n );\n }\n}\n"],"version":3}
|