@searchcraft/javascript-sdk 0.10.1 → 0.10.2
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/index.d.ts +123 -80
- package/dist/components/index.js +7 -33
- package/dist/components/index.js.map +1 -1
- package/dist/components/{p-84e2cbd6.js → p-01589c0b.js} +3 -3
- package/dist/components/{p-84e2cbd6.js.map → p-01589c0b.js.map} +1 -1
- package/dist/components/{p-5d17ace0.js → p-0f5b47be.js} +7 -7
- package/dist/components/{p-5d17ace0.js.map → p-0f5b47be.js.map} +1 -1
- package/dist/components/{p-0077f677.js → p-2999498a.js} +34 -22
- package/dist/components/p-2999498a.js.map +1 -0
- package/dist/components/{p-17c646e2.js → p-3465cbc7.js} +548 -474
- package/dist/components/p-3465cbc7.js.map +1 -0
- package/dist/components/{p-13e81b5d.js → p-435bec83.js} +2 -2
- package/dist/components/{p-13e81b5d.js.map → p-435bec83.js.map} +1 -1
- package/dist/components/{p-172a848d.js → p-48fa555e.js} +7 -7
- package/dist/components/{p-172a848d.js.map → p-48fa555e.js.map} +1 -1
- package/dist/components/p-4d37616e.js +105 -0
- package/dist/components/p-4d37616e.js.map +1 -0
- package/dist/components/{p-3e65aa91.js → p-66109c31.js} +3 -8
- package/dist/components/p-66109c31.js.map +1 -0
- package/dist/components/{p-2be1a382.js → p-760c6845.js} +2 -2
- package/dist/components/{p-2be1a382.js.map → p-760c6845.js.map} +1 -1
- package/dist/components/{p-868803f9.js → p-7c650118.js} +2 -2
- package/dist/components/{p-868803f9.js.map → p-7c650118.js.map} +1 -1
- package/dist/components/{p-a62a2e74.js → p-c1f43fe1.js} +4 -4
- package/dist/components/{p-a62a2e74.js.map → p-c1f43fe1.js.map} +1 -1
- package/dist/components/searchcraft-ad.js +1 -1
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-filter-panel.js +5 -5
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-pagination.js +1 -1
- package/dist/components/searchcraft-popover-button.js +5 -3
- 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 +8 -8
- 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 +2 -2
- package/dist/components/searchcraft-search-result.js +1 -1
- package/dist/components/searchcraft-search-results-per-page.js +1 -1
- package/dist/components/searchcraft-search-results.js +69 -32
- package/dist/components/searchcraft-search-results.js.map +1 -1
- package/dist/components/searchcraft-slider.js +1 -1
- package/dist/components/searchcraft-theme.js +1 -1
- package/dist/components/searchcraft-theme.js.map +1 -1
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/hydrate/index.js +484 -388
- package/dist/hydrate/index.mjs +484 -388
- package/dist/themes/hologram.css +1 -1
- package/dist/themes/hologram.css.map +1 -1
- package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +7 -3
- package/dist/types/components/searchcraft-popover-button/searchcraft-popover-button.d.ts +3 -3
- package/dist/types/components/searchcraft-search-results/searchcraft-search-results.d.ts +10 -5
- package/dist/types/components.d.ts +20 -12
- package/dist/types/index.d.ts +0 -1
- package/dist/types/store/SearchcraftStore.types.d.ts +15 -6
- package/dist/types/utils/index.d.ts +0 -1
- package/dist/types/utils/units.d.ts +19 -6
- package/package.json +4 -7
- package/dist/components/p-0077f677.js.map +0 -1
- package/dist/components/p-17c646e2.js.map +0 -1
- package/dist/components/p-3e65aa91.js.map +0 -1
- package/dist/components/p-6104fe5d.js +0 -84
- package/dist/components/p-6104fe5d.js.map +0 -1
- package/dist/types/utils/styles.d.ts +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"searchcraft-popover-form.js","mappings":";;;;;;;;;;;;MAmDaA,wBAAsB;;;;;;;;;;;IAOzB,IAAI,GAAuC,QAAQ,CAA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I,CAAC,EAC9C,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,GAC5C,EACF,cACE,IAAI,EAAC,QAAQ,EACb,KAAK,EAAC,sGAAsG,EAC5G,OAAO,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,aAGzC,CACL,EACL,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,EACD,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-input-cancel-button searchcraft-popover-form-modal-input-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\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 <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-input-cancel-button searchcraft-popover-form-fullscreen-input-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\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 <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":"searchcra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IAAI,CAAC,gBAAgB;iBACzD,CACF,IAED,WAAK,KAAK,EAAC,0EAA0E,IACnF,8BACE,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAC9C,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,GAC5C,EACF,cACE,IAAI,EAAC,QAAQ,EACb,KAAK,EAAC,0FAA0F,EAChG,OAAO,EAAE,IAAI,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,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-0f5b47be.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-c1f43fe1.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftPopoverListView = SearchcraftPopoverListView$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, h } from './p-5365011f.js';
|
|
2
|
-
import { s as searchcraftStore } from './p-
|
|
3
|
-
import { f as formatNumberWithCommas } from './p-
|
|
2
|
+
import { s as searchcraftStore } from './p-3465cbc7.js';
|
|
3
|
+
import { f as formatNumberWithCommas } from './p-4d37616e.js';
|
|
4
4
|
import { h as html } from './p-810a7850.js';
|
|
5
5
|
|
|
6
6
|
const SearchcraftResultsInfo$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftResultsInfo extends H {
|
|
@@ -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-48fa555e.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 { s as searchcraftStore } from './p-
|
|
2
|
+
import { s as searchcraftStore } from './p-3465cbc7.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 {
|
|
@@ -1,45 +1,58 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, h } from './p-5365011f.js';
|
|
2
|
-
import { n as nanoid, d as defineCustomElement$4 } from './p-
|
|
3
|
-
import { s as searchcraftStore } from './p-
|
|
2
|
+
import { n as nanoid, d as defineCustomElement$4 } from './p-435bec83.js';
|
|
3
|
+
import { s as searchcraftStore } from './p-3465cbc7.js';
|
|
4
4
|
import { d as defineCustomElement$3 } from './p-f2585cdf.js';
|
|
5
|
-
import { d as defineCustomElement$2 } from './p-
|
|
5
|
+
import { d as defineCustomElement$2 } from './p-48fa555e.js';
|
|
6
6
|
|
|
7
7
|
const SearchcraftSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftSearchResults extends H {
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
10
|
this.__registerHost();
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A query that will appears when the component initializes or the search term is ''..
|
|
14
|
+
*/
|
|
15
|
+
initialQuery;
|
|
12
16
|
/**
|
|
13
17
|
* A callback function responsible for rendering a result. Passed to `searchcraft-search-result`.
|
|
14
18
|
*/
|
|
15
19
|
template;
|
|
16
|
-
searchTerm = '';
|
|
17
|
-
searchClientResponseItems;
|
|
18
20
|
adClientResponseItems = [];
|
|
19
|
-
searchResultsPerPage;
|
|
20
|
-
searchResultsPage;
|
|
21
|
-
isSearchInProgress = true;
|
|
22
21
|
config;
|
|
22
|
+
initialSearchClientResponseItems;
|
|
23
|
+
isSearchInProgress = true;
|
|
24
|
+
searchClientResponseItems;
|
|
25
|
+
searchResultsPage;
|
|
26
|
+
searchResultsPerPage;
|
|
27
|
+
searchTerm = '';
|
|
23
28
|
unsubscribe = () => { };
|
|
24
29
|
componentDidLoad() {
|
|
30
|
+
const state = searchcraftStore.getState();
|
|
31
|
+
this.handleStateChange(state);
|
|
32
|
+
this.searchClientResponseItems = state.searchClientResponseItems;
|
|
33
|
+
this.searchTerm = state.searchTerm;
|
|
34
|
+
this.config = state.core?.config;
|
|
35
|
+
state.afterInit = (state) => {
|
|
36
|
+
if (this.initialQuery) {
|
|
37
|
+
state.setInitialQuery(this.initialQuery);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
25
40
|
this.unsubscribe = searchcraftStore.subscribe((state) => this.handleStateChange(state));
|
|
26
|
-
const currentState = searchcraftStore.getState();
|
|
27
|
-
this.handleStateChange(currentState);
|
|
28
|
-
this.searchClientResponseItems = currentState.searchClientResponseItems;
|
|
29
|
-
this.searchTerm = currentState.searchTerm;
|
|
30
|
-
this.config = currentState.core?.config;
|
|
31
41
|
}
|
|
32
42
|
disconnectedCallback() {
|
|
33
43
|
this.unsubscribe?.();
|
|
34
44
|
}
|
|
35
45
|
handleStateChange(state) {
|
|
36
|
-
this.searchClientResponseItems = [...state.searchClientResponseItems];
|
|
37
46
|
this.adClientResponseItems = [...state.adClientResponseItems];
|
|
38
|
-
this.searchTerm = state.searchTerm;
|
|
39
|
-
this.searchResultsPage = state.searchResultsPage;
|
|
40
|
-
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
41
47
|
this.config = state.core?.config;
|
|
48
|
+
this.initialSearchClientResponseItems = [
|
|
49
|
+
...state.initialSearchClientResponseItems,
|
|
50
|
+
];
|
|
42
51
|
this.isSearchInProgress = state.isSearchInProgress;
|
|
52
|
+
this.searchClientResponseItems = [...state.searchClientResponseItems];
|
|
53
|
+
this.searchResultsPage = state.searchResultsPage;
|
|
54
|
+
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
55
|
+
this.searchTerm = state.searchTerm;
|
|
43
56
|
}
|
|
44
57
|
renderEmptyState() {
|
|
45
58
|
return (h("div", { class: 'searchcraft-search-results-empty-state' }, h("slot", { name: 'empty-search' })));
|
|
@@ -48,7 +61,12 @@ const SearchcraftSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Search
|
|
|
48
61
|
return (h("div", { class: 'searchcraft-search-results' }, h("div", { class: 'searchcraft-search-results-error-message' }, h("searchcraft-error-message", null, "No search results found for \"", this.searchTerm, "\" query."))));
|
|
49
62
|
}
|
|
50
63
|
renderWithADMAds() {
|
|
51
|
-
|
|
64
|
+
const items = this.searchClientResponseItems?.length
|
|
65
|
+
? this.searchClientResponseItems
|
|
66
|
+
: this.initialSearchClientResponseItems?.length
|
|
67
|
+
? this.initialSearchClientResponseItems
|
|
68
|
+
: [];
|
|
69
|
+
return (h("div", { class: 'searchcraft-search-results' }, this.adClientResponseItems?.map((item) => (h("searchcraft-ad", { adSource: 'adMarketplace', adClientResponseItem: item, adContainerId: nanoid(), key: item.id }))), items.map((item, index) => (h("searchcraft-search-result", { key: item.id, "document-position": this.searchResultsPerPage * (this.searchResultsPage - 1) + index, index: index, item: item, template: this.template })))));
|
|
52
70
|
}
|
|
53
71
|
renderWithCustomAds() {
|
|
54
72
|
const itemsToRender = [];
|
|
@@ -56,16 +74,20 @@ const SearchcraftSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Search
|
|
|
56
74
|
const interstitialQuantity = this.config?.customAdInterstitialQuantity || 1;
|
|
57
75
|
const adStartQuantity = this.config?.customAdStartQuantity || 0;
|
|
58
76
|
const adEndQuantity = this.config?.customAdEndQuantity || 0;
|
|
59
|
-
const
|
|
77
|
+
const items = this.searchClientResponseItems?.length
|
|
78
|
+
? this.searchClientResponseItems
|
|
79
|
+
: this.initialSearchClientResponseItems?.length
|
|
80
|
+
? this.initialSearchClientResponseItems
|
|
81
|
+
: [];
|
|
60
82
|
// Renders ads at beginning
|
|
61
83
|
for (let n = 0; n < adStartQuantity; n++) {
|
|
62
84
|
itemsToRender.push(h("searchcraft-ad", { adSource: 'Custom', adContainerId: nanoid(), key: `${n}-ad` }));
|
|
63
85
|
}
|
|
64
86
|
// Renders search results + interstitial ads
|
|
65
|
-
|
|
87
|
+
items.forEach((item, index) => {
|
|
66
88
|
if (interstitialInterval &&
|
|
67
89
|
index % interstitialInterval === 0 &&
|
|
68
|
-
index + interstitialInterval <
|
|
90
|
+
index + interstitialInterval < items.length &&
|
|
69
91
|
index >= interstitialInterval) {
|
|
70
92
|
for (let n = 0; n < interstitialQuantity; n++) {
|
|
71
93
|
itemsToRender.push(h("searchcraft-ad", { adSource: 'Custom', adContainerId: nanoid(), key: `${item.id}-ad-${n}` }));
|
|
@@ -86,16 +108,20 @@ const SearchcraftSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Search
|
|
|
86
108
|
const interstitialQuantity = this.config?.nativoAdInterstitialQuantity || 1;
|
|
87
109
|
const adStartQuantity = this.config?.nativoAdStartQuantity || 0;
|
|
88
110
|
const adEndQuantity = this.config?.nativoAdEndQuantity || 0;
|
|
89
|
-
const
|
|
111
|
+
const items = this.searchClientResponseItems?.length
|
|
112
|
+
? this.searchClientResponseItems
|
|
113
|
+
: this.initialSearchClientResponseItems?.length
|
|
114
|
+
? this.initialSearchClientResponseItems
|
|
115
|
+
: [];
|
|
90
116
|
// Renders ads at beginning
|
|
91
117
|
for (let n = 0; n < adStartQuantity; n++) {
|
|
92
118
|
itemsToRender.push(h("searchcraft-ad", { adSource: 'Nativo', adContainerId: nanoid(), key: `${n}-ad` }));
|
|
93
119
|
}
|
|
94
120
|
// Renders search results + interstitial ads
|
|
95
|
-
|
|
121
|
+
items.forEach((item, index) => {
|
|
96
122
|
if (interstitialInterval &&
|
|
97
123
|
(index + interstitialStartIndex) % interstitialInterval === 0 &&
|
|
98
|
-
index + interstitialInterval <
|
|
124
|
+
index + interstitialInterval < items.length &&
|
|
99
125
|
index >= interstitialInterval) {
|
|
100
126
|
for (let n = 0; n < interstitialQuantity; n++) {
|
|
101
127
|
itemsToRender.push(h("searchcraft-ad", { adSource: 'Nativo', adContainerId: nanoid(), key: `${item.id}-ad-${n}` }));
|
|
@@ -110,14 +136,23 @@ const SearchcraftSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Search
|
|
|
110
136
|
return h("div", { class: 'searchcraft-search-results' }, itemsToRender);
|
|
111
137
|
}
|
|
112
138
|
renderWithNoAds() {
|
|
113
|
-
|
|
139
|
+
const items = this.searchClientResponseItems?.length
|
|
140
|
+
? this.searchClientResponseItems
|
|
141
|
+
: this.initialSearchClientResponseItems?.length
|
|
142
|
+
? this.initialSearchClientResponseItems
|
|
143
|
+
: [];
|
|
144
|
+
return (h("div", { class: 'searchcraft-search-results' }, items.map((item, index) => (h("searchcraft-search-result", { key: item.id, "document-position": this.searchResultsPerPage * (this.searchResultsPage - 1) + index, index: index, item: item, template: this.template })))));
|
|
114
145
|
}
|
|
115
146
|
render() {
|
|
116
|
-
|
|
147
|
+
const searchClientResponseItems = this.searchClientResponseItems || [];
|
|
148
|
+
const initialSearchClientResponseItems = this.initialSearchClientResponseItems || [];
|
|
149
|
+
if (this.searchTerm === '' &&
|
|
150
|
+
initialSearchClientResponseItems.length === 0 &&
|
|
151
|
+
!this.isSearchInProgress) {
|
|
117
152
|
return this.renderEmptyState();
|
|
118
153
|
}
|
|
119
154
|
if (this.searchTerm.length > 0 &&
|
|
120
|
-
|
|
155
|
+
searchClientResponseItems.length === 0 &&
|
|
121
156
|
!this.isSearchInProgress) {
|
|
122
157
|
return this.renderNoResultsFoundState();
|
|
123
158
|
}
|
|
@@ -133,14 +168,16 @@ const SearchcraftSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Search
|
|
|
133
168
|
}
|
|
134
169
|
}
|
|
135
170
|
}, [4, "searchcraft-search-results", {
|
|
171
|
+
"initialQuery": [1, "initial-query"],
|
|
136
172
|
"template": [16],
|
|
137
|
-
"searchTerm": [32],
|
|
138
|
-
"searchClientResponseItems": [32],
|
|
139
173
|
"adClientResponseItems": [32],
|
|
140
|
-
"
|
|
141
|
-
"
|
|
174
|
+
"config": [32],
|
|
175
|
+
"initialSearchClientResponseItems": [32],
|
|
142
176
|
"isSearchInProgress": [32],
|
|
143
|
-
"
|
|
177
|
+
"searchClientResponseItems": [32],
|
|
178
|
+
"searchResultsPage": [32],
|
|
179
|
+
"searchResultsPerPage": [32],
|
|
180
|
+
"searchTerm": [32]
|
|
144
181
|
}]);
|
|
145
182
|
function defineCustomElement$1() {
|
|
146
183
|
if (typeof customElements === "undefined") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"searchcraft-search-results.js","mappings":";;;;;;MAsEaA,0BAAwB;;;;;;;;IAI3B,QAAQ,CAAkD;IAEzD,UAAU,GAAG,EAAE,CAAC;IAChB,yBAAyB,CAA8B;IACvD,qBAAqB,GAA2B,EAAE,CAAC;IACnD,oBAAoB,CAAC;IACrB,iBAAiB,CAAC;IAClB,kBAAkB,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAqB;IAE5B,WAAW,GAAe,SAAQ,CAAC;IAE3C,gBAAgB;QACd,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,KAAK,KAClD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAC9B,CAAC;QACF,MAAM,YAAY,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QACjD,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QACrC,IAAI,CAAC,yBAAyB,GAAG,YAAY,CAAC,yBAAyB,CAAC;QACxE,IAAI,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC;KACzC;IAED,oBAAoB;QAClB,IAAI,CAAC,W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BAEV,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,KAAK,EAElE,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,IAAI,CAAC,QAAQ,GACvB,CACH,CAAC,CACE,EACN;KACH;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACjC,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;SAChC;QAED,IACE,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YAC1B,CAAC,IAAI,CAAC,yBAAyB,IAAI,EAAE,EAAE,MAAM,KAAK,CAAC;YACnD,CAAC,IAAI,CAAC,kBAAkB,EACxB;YACA,OAAO,IAAI,CAAC,yBAAyB,EAAE,CAAC;SACzC;QAED,QAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM;YACrC,KAAK,eAAe;gBAClB,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC;gBACE,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;SACjC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftSearchResults"],"sources":["src/components/searchcraft-search-results/searchcraft-search-results.tsx"],"sourcesContent":["import { Component, h, Prop, State, type JSX } from '@stencil/core';\nimport { nanoid } from 'nanoid';\n\nimport type {\n AdClientResponseItem,\n SearchClientResponseItem,\n SearchcraftConfig,\n SearchResultTemplate,\n SearchResultTemplateData,\n} from '@searchcraft/core';\n\nimport { type SearchcraftState, searchcraftStore } from '@store';\n\n/**\n * This web component is responsible for displaying the results of a search query. Once a query is submitted, the component formats and presents an ordered list of the results.\n *\n *\n * @react-import\n * ```jsx\n * import { SearchcraftSearchResults } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftSearchResults } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-search-results\n * ad-interval=\"4\"\n * place-ad-at-start=\"true\"\n * />\n * ```\n *\n * ```js\n * // index.js\n * const searchResults = document.querySelector('searchcraft-search-results');\n *\n * searchResults.template = (item, index, { html }) => html`\n * <h2>${item.title}</h2>\n * `;\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftSearchResults\n * adInterval={4}\n * placeAdAtState={true}\n * template={(item, index, { html }) => html`\n * <h2>${item.title}</h2>\n * `}\n * />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftSearchResults\n * adInterval={4}\n * placeAdAtState={true}\n * :template={(item, index, { html }) => html`\n * <h2>${item.title}</h2>\n * `}\n * />\n * ```\n */\n@Component({\n tag: 'searchcraft-search-results',\n})\nexport class SearchcraftSearchResults {\n /**\n * A callback function responsible for rendering a result. Passed to `searchcraft-search-result`.\n */\n @Prop() template?: SearchResultTemplate<SearchResultTemplateData>;\n\n @State() searchTerm = '';\n @State() searchClientResponseItems?: SearchClientResponseItem[];\n @State() adClientResponseItems: AdClientResponseItem[] = [];\n @State() searchResultsPerPage;\n @State() searchResultsPage;\n @State() isSearchInProgress = true;\n @State() config?: SearchcraftConfig;\n\n private unsubscribe: () => void = () => {};\n\n componentDidLoad() {\n this.unsubscribe = searchcraftStore.subscribe((state) =>\n this.handleStateChange(state),\n );\n const currentState = searchcraftStore.getState();\n this.handleStateChange(currentState);\n this.searchClientResponseItems = currentState.searchClientResponseItems;\n this.searchTerm = currentState.searchTerm;\n this.config = currentState.core?.config;\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n }\n\n handleStateChange(state: SearchcraftState) {\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 this.config = state.core?.config;\n this.isSearchInProgress = state.isSearchInProgress;\n }\n\n renderEmptyState() {\n return (\n <div class='searchcraft-search-results-empty-state'>\n <slot name='empty-search' />\n </div>\n );\n }\n\n renderNoResultsFoundState() {\n return (\n <div class='searchcraft-search-results'>\n <div class='searchcraft-search-results-error-message'>\n <searchcraft-error-message>\n No search results found for \"{this.searchTerm}\" query.\n </searchcraft-error-message>\n </div>\n </div>\n );\n }\n\n renderWithADMAds() {\n return (\n <div class='searchcraft-search-results'>\n {this.adClientResponseItems?.map((item) => (\n <searchcraft-ad\n adSource='adMarketplace'\n adClientResponseItem={item}\n adContainerId={nanoid()}\n key={item.id}\n />\n ))}\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />\n ))}\n </div>\n );\n }\n\n renderWithCustomAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialInterval = this.config?.customAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.customAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.customAdStartQuantity || 0;\n const adEndQuantity = this.config?.customAdEndQuantity || 0;\n const searchItems = this.searchClientResponseItems || [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n searchItems.forEach((item, index) => {\n if (\n interstitialInterval &&\n index % interstitialInterval === 0 &&\n index + interstitialInterval < searchItems.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-search-results'>{itemsToRender}</div>;\n }\n\n renderWithNativoAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialStartIndex =\n this.config?.nativoAdInterstialStartIndex || 0;\n const interstitialInterval = this.config?.nativoAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.nativoAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.nativoAdStartQuantity || 0;\n const adEndQuantity = this.config?.nativoAdEndQuantity || 0;\n const searchItems = this.searchClientResponseItems || [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n searchItems.forEach((item, index) => {\n if (\n interstitialInterval &&\n (index + interstitialStartIndex) % interstitialInterval === 0 &&\n index + interstitialInterval < searchItems.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-search-results'>{itemsToRender}</div>;\n }\n\n renderWithNoAds() {\n return (\n <div class='searchcraft-search-results'>\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />\n ))}\n </div>\n );\n }\n\n render() {\n if (this.searchTerm.trim() === '') {\n return this.renderEmptyState();\n }\n\n if (\n this.searchTerm.length > 0 &&\n (this.searchClientResponseItems || []).length === 0 &&\n !this.isSearchInProgress\n ) {\n return this.renderNoResultsFoundState();\n }\n\n switch (this.config?.adSource || 'None') {\n case 'adMarketplace':\n return this.renderWithADMAds();\n case 'Custom':\n return this.renderWithCustomAds();\n case 'Nativo':\n return this.renderWithNativoAds();\n default:\n return this.renderWithNoAds();\n }\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"searchcraft-search-results.js","mappings":";;;;;;MAsEaA,0BAAwB;;;;;;;;IAI3B,YAAY,CAAU;;;;IAKtB,QAAQ,CAAkD;IAEzD,qBAAqB,GAA2B,EAAE,CAAC;IACnD,MAAM,CAAqB;IAC3B,gCAAgC,CAA8B;IAC9D,kBAAkB,GAAG,IAAI,CAAC;IAC1B,yBAAyB,CAA8B;IACvD,iBAAiB,CAAC;IAClB,oBAAoB,CAAC;IACrB,UAAU,GAAG,EAAE,CAAC;IAEjB,WAAW,GAAe,SAAQ,CAAC;IAE3C,gBAAgB;QACd,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC1C,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,CAAC,yBAAyB,GAAG,KAAK,CAAC,yBAAyB,CAAC;QACjE,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;QAEjC,KAAK,CAAC,SAAS,GAAG,CAAC,KAAK;YACtB,IAAI,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AAU,KAAK,EAAE;YACtB,gCAAgC,CAAC,MAAM,KAAK,CAAC;YAC7C,CAAC,IAAI,CAAC,kBAAkB,EACxB;YACA,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;SAChC;QAED,IACE,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YAC1B,yBAAyB,CAAC,MAAM,KAAK,CAAC;YACtC,CAAC,IAAI,CAAC,kBAAkB,EACxB;YACA,OAAO,IAAI,CAAC,yBAAyB,EAAE,CAAC;SACzC;QAED,QAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM;YACrC,KAAK,eAAe;gBAClB,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC;gBACE,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;SACjC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftSearchResults"],"sources":["src/components/searchcraft-search-results/searchcraft-search-results.tsx"],"sourcesContent":["import { Component, h, Prop, State, type JSX } from '@stencil/core';\nimport { nanoid } from 'nanoid';\n\nimport type {\n AdClientResponseItem,\n SearchClientResponseItem,\n SearchcraftConfig,\n SearchResultTemplate,\n SearchResultTemplateData,\n} from '@searchcraft/core';\n\nimport { type SearchcraftState, searchcraftStore } from '@store';\n\n/**\n * This web component is responsible for displaying the results of a search query. Once a query is submitted, the component formats and presents an ordered list of the results.\n *\n *\n * @react-import\n * ```jsx\n * import { SearchcraftSearchResults } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftSearchResults } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <!-- index.html -->\n * <searchcraft-search-results\n * ad-interval=\"4\"\n * place-ad-at-start=\"true\"\n * />\n * ```\n *\n * ```js\n * // index.js\n * const searchResults = document.querySelector('searchcraft-search-results');\n *\n * searchResults.template = (item, index, { html }) => html`\n * <h2>${item.title}</h2>\n * `;\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftSearchResults\n * adInterval={4}\n * placeAdAtState={true}\n * template={(item, index, { html }) => html`\n * <h2>${item.title}</h2>\n * `}\n * />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftSearchResults\n * adInterval={4}\n * placeAdAtState={true}\n * :template={(item, index, { html }) => html`\n * <h2>${item.title}</h2>\n * `}\n * />\n * ```\n */\n@Component({\n tag: 'searchcraft-search-results',\n})\nexport class SearchcraftSearchResults {\n /**\n * A query that will appears when the component initializes or the search term is ''..\n */\n @Prop() initialQuery?: string;\n\n /**\n * A callback function responsible for rendering a result. Passed to `searchcraft-search-result`.\n */\n @Prop() template?: SearchResultTemplate<SearchResultTemplateData>;\n\n @State() adClientResponseItems: AdClientResponseItem[] = [];\n @State() config?: SearchcraftConfig;\n @State() initialSearchClientResponseItems?: SearchClientResponseItem[];\n @State() isSearchInProgress = true;\n @State() searchClientResponseItems?: SearchClientResponseItem[];\n @State() searchResultsPage;\n @State() searchResultsPerPage;\n @State() searchTerm = '';\n\n private unsubscribe: () => void = () => {};\n\n componentDidLoad() {\n const state = searchcraftStore.getState();\n this.handleStateChange(state);\n this.searchClientResponseItems = state.searchClientResponseItems;\n this.searchTerm = state.searchTerm;\n this.config = state.core?.config;\n\n state.afterInit = (state) => {\n if (this.initialQuery) {\n state.setInitialQuery(this.initialQuery);\n }\n };\n\n this.unsubscribe = searchcraftStore.subscribe((state) =>\n this.handleStateChange(state),\n );\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n }\n\n handleStateChange(state: SearchcraftState) {\n this.adClientResponseItems = [...state.adClientResponseItems];\n this.config = state.core?.config;\n this.initialSearchClientResponseItems = [\n ...state.initialSearchClientResponseItems,\n ];\n this.isSearchInProgress = state.isSearchInProgress;\n this.searchClientResponseItems = [...state.searchClientResponseItems];\n this.searchResultsPage = state.searchResultsPage;\n this.searchResultsPerPage = state.searchResultsPerPage;\n this.searchTerm = state.searchTerm;\n }\n\n renderEmptyState() {\n return (\n <div class='searchcraft-search-results-empty-state'>\n <slot name='empty-search' />\n </div>\n );\n }\n\n renderNoResultsFoundState() {\n return (\n <div class='searchcraft-search-results'>\n <div class='searchcraft-search-results-error-message'>\n <searchcraft-error-message>\n No search results found for \"{this.searchTerm}\" query.\n </searchcraft-error-message>\n </div>\n </div>\n );\n }\n\n renderWithADMAds() {\n const items = this.searchClientResponseItems?.length\n ? this.searchClientResponseItems\n : this.initialSearchClientResponseItems?.length\n ? this.initialSearchClientResponseItems\n : [];\n\n return (\n <div class='searchcraft-search-results'>\n {this.adClientResponseItems?.map((item) => (\n <searchcraft-ad\n adSource='adMarketplace'\n adClientResponseItem={item}\n adContainerId={nanoid()}\n key={item.id}\n />\n ))}\n {items.map((item, index) => (\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />\n ))}\n </div>\n );\n }\n\n renderWithCustomAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialInterval = this.config?.customAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.customAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.customAdStartQuantity || 0;\n const adEndQuantity = this.config?.customAdEndQuantity || 0;\n const items = this.searchClientResponseItems?.length\n ? this.searchClientResponseItems\n : this.initialSearchClientResponseItems?.length\n ? this.initialSearchClientResponseItems\n : [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n items.forEach((item, index) => {\n if (\n interstitialInterval &&\n index % interstitialInterval === 0 &&\n index + interstitialInterval < items.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-search-results'>{itemsToRender}</div>;\n }\n\n renderWithNativoAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialStartIndex =\n this.config?.nativoAdInterstialStartIndex || 0;\n const interstitialInterval = this.config?.nativoAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.nativoAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.nativoAdStartQuantity || 0;\n const adEndQuantity = this.config?.nativoAdEndQuantity || 0;\n const items = this.searchClientResponseItems?.length\n ? this.searchClientResponseItems\n : this.initialSearchClientResponseItems?.length\n ? this.initialSearchClientResponseItems\n : [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n items.forEach((item, index) => {\n if (\n interstitialInterval &&\n (index + interstitialStartIndex) % interstitialInterval === 0 &&\n index + interstitialInterval < items.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-search-results'>{itemsToRender}</div>;\n }\n\n renderWithNoAds() {\n const items = this.searchClientResponseItems?.length\n ? this.searchClientResponseItems\n : this.initialSearchClientResponseItems?.length\n ? this.initialSearchClientResponseItems\n : [];\n\n return (\n <div class='searchcraft-search-results'>\n {items.map((item, index) => (\n <searchcraft-search-result\n key={item.id}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n index={index}\n item={item}\n template={this.template}\n />\n ))}\n </div>\n );\n }\n\n render() {\n const searchClientResponseItems = this.searchClientResponseItems || [];\n const initialSearchClientResponseItems =\n this.initialSearchClientResponseItems || [];\n\n if (\n this.searchTerm === '' &&\n initialSearchClientResponseItems.length === 0 &&\n !this.isSearchInProgress\n ) {\n return this.renderEmptyState();\n }\n\n if (\n this.searchTerm.length > 0 &&\n searchClientResponseItems.length === 0 &&\n !this.isSearchInProgress\n ) {\n return this.renderNoResultsFoundState();\n }\n\n switch (this.config?.adSource || 'None') {\n case 'adMarketplace':\n return this.renderWithADMAds();\n case 'Custom':\n return this.renderWithCustomAds();\n case 'Nativo':\n return this.renderWithNativoAds();\n default:\n return this.renderWithNoAds();\n }\n }\n}\n"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftSlider$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftSlider$1, d as defineCustomElement$1 } from './p-7c650118.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftSlider = SearchcraftSlider$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|