@searchcraft/javascript-sdk 0.9.4 → 0.9.6
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/bundled.types.d.ts +83 -10
- package/dist/components/index.js +5 -5
- package/dist/components/{p-7777d986.js → p-0bbc3aff.js} +2 -2
- package/dist/components/{p-7777d986.js.map → p-0bbc3aff.js.map} +1 -1
- package/dist/components/{p-05872320.js → p-10b0d0dc.js} +50 -23
- package/dist/components/p-10b0d0dc.js.map +1 -0
- package/dist/components/{p-6d8b0ead.js → p-2e293015.js} +539 -441
- package/dist/components/p-2e293015.js.map +1 -0
- package/dist/components/{p-3568414f.js → p-44e6ed36.js} +2 -2
- package/dist/components/{p-3568414f.js.map → p-44e6ed36.js.map} +1 -1
- package/dist/components/{p-b0bc5cee.js → p-94837dcb.js} +36 -4
- package/dist/components/p-94837dcb.js.map +1 -0
- package/dist/components/{p-cd9ba361.js → p-9bdcb929.js} +2 -2
- package/dist/components/{p-cd9ba361.js.map → p-9bdcb929.js.map} +1 -1
- package/dist/components/{p-11b05b94.js → p-bb9e9d7d.js} +2 -2
- package/dist/components/{p-11b05b94.js.map → p-bb9e9d7d.js.map} +1 -1
- package/dist/components/{p-5bd5c3cb.js → p-c1c14447.js} +7 -10
- package/dist/components/p-c1c14447.js.map +1 -0
- package/dist/components/searchcraft-ad.js +1 -1
- package/dist/components/searchcraft-base-search-result.js +1 -1
- package/dist/components/searchcraft-base-search-results.js +39 -6
- package/dist/components/searchcraft-base-search-results.js.map +1 -1
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-filter-panel.js +3 -3
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-pagination.js +1 -1
- package/dist/components/searchcraft-popover-button.js +1 -1
- package/dist/components/searchcraft-popover-form.js +5 -5
- 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 +1 -1
- package/dist/components/searchcraft-search-results-per-page.js +1 -1
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/types/components/searchcraft-ad/searchcraft-ad.d.ts +6 -2
- package/dist/types/components/searchcraft-base-search-results/searchcraft-base-search-results.d.ts +2 -1
- package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +1 -4
- package/dist/types/components/searchcraft-popover-list-view/searchcraft-popover-list-view.d.ts +1 -0
- package/dist/types/components.d.ts +0 -8
- package/package.json +3 -3
- package/dist/components/p-05872320.js.map +0 -1
- package/dist/components/p-5bd5c3cb.js.map +0 -1
- package/dist/components/p-6d8b0ead.js.map +0 -1
- package/dist/components/p-b0bc5cee.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"p-
|
|
1
|
+
{"file":"p-bb9e9d7d.js","mappings":";;;;MAmBa,uBAAuB;;;;;;;;;IAI1B,KAAK,GAAG,QAAQ,CAAC;;;;IAIjB,QAAQ,CAAqB;;;;IAK5B,aAAa,CAAyB;IAEtC,QAAQ,GAAG,KAAK,CAAC;IACjB,WAAW,CAA2B;IACtC,cAAc,CAAqB;IAEpC,YAAY,GAAG;QACrB,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACzC,CAAC;IAEF,iBAAiB;;QAEf,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,KAAK;YAClD,IACE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC,cAAc;gBACxC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EACpC;gBACA,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;aACvB;YACD,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,UAAU,CAAC;SACxC,CAAC,CAAC;KACJ;IAED,oBAAoB;QAClB,IAAI,CAAC,WAAW,IAAI,CAAC;KACtB;IAED,MAAM;QACJ,QACE,4DAAK,KAAK,EAAC,qCAAqC,IAC9C,8DACE,0DAAG,KAAK,EAAC,iCAAiC,IAAE,IAAI,CAAC,KAAK,CAAK,EAC1D,IAAI,CAAC,QAAQ,KACZ,0DAAG,KAAK,EAAC,qCAAqC,IAAE,IAAI,CAAC,QAAQ,CAAK,CACnE,CACG,EACN,+DACE,KAAK,EAAE,UAAU,CAAC,sCAAsC,EAAE;gBACxD,MAAM,EAAE,IAAI,CAAC,QAAQ;aACtB,CAAC,EACF,OAAO,EAAE,IAAI,CAAC,YAAY,EAC1B,IAAI,EAAC,QAAQ,IAEb,4DACE,KAAK,EAAE,UAAU,CAAC,kCAAkC,EAAE;gBACpD,MAAM,EAAE,IAAI,CAAC,QAAQ;aACtB,CAAC,GACF,CACK,CACL,EACN;KACH;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/searchcraft-toggle-button/searchcraft-toggle-button.tsx"],"sourcesContent":["import { searchcraftStore } from '@store';\nimport {\n Component,\n Event,\n h,\n Prop,\n State,\n type EventEmitter,\n} from '@stencil/core';\nimport classNames from 'classnames';\n\n/**\n * This web component simulates a light switch functionality, providing a simple and intuitive toggle between two states—on and off.\n * It is consumed within the `searchcraft-filter-panel` component.\n */\n@Component({\n tag: 'searchcraft-toggle-button',\n shadow: false,\n})\nexport class SearchcraftToggleButton {\n /**\n * The label.\n */\n @Prop() label = 'Toggle';\n /**\n * The secondary label displayed below the main label.\n */\n @Prop() subLabel: string | undefined;\n\n /**\n * When the toggle element is changed.\n */\n @Event() toggleUpdated?: EventEmitter<boolean>;\n\n @State() isActive = false;\n @State() unsubscribe: (() => void) | undefined;\n @State() lastSearchTerm: string | undefined;\n\n private handleToggle = async () => {\n this.isActive = !this.isActive;\n this.toggleUpdated?.emit(this.isActive);\n };\n\n connectedCallback() {\n /** When the query changes, sets toggle button state back to inactive. */\n this.unsubscribe = searchcraftStore.subscribe((state) => {\n if (\n state.searchTerm !== this.lastSearchTerm &&\n state.searchTerm.trim().length === 0\n ) {\n this.isActive = false;\n }\n this.lastSearchTerm = state.searchTerm;\n });\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n }\n\n render() {\n return (\n <div class='searchcraft-toggle-button-container'>\n <div>\n <p class='searchcraft-toggle-button-label'>{this.label}</p>\n {this.subLabel && (\n <p class='searchcraft-toggle-button-sub-label'>{this.subLabel}</p>\n )}\n </div>\n <button\n class={classNames('searchcraft-toggle-button-background', {\n active: this.isActive,\n })}\n onClick={this.handleToggle}\n type='button'\n >\n <div\n class={classNames('searchcraft-toggle-button-handle', {\n active: this.isActive,\n })}\n />\n </button>\n </div>\n );\n }\n}\n"],"version":3}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, c as createEvent, h } from './p-5365011f.js';
|
|
2
2
|
import { c as classNames } from './p-5cdc6210.js';
|
|
3
3
|
import { p as parseCustomStyles } from './p-d9551738.js';
|
|
4
|
-
import { s as searchcraftStore } from './p-
|
|
4
|
+
import { s as searchcraftStore } from './p-2e293015.js';
|
|
5
5
|
import { d as defineCustomElement$3 } from './p-71cc28c1.js';
|
|
6
6
|
import { d as defineCustomElement$2 } from './p-0e393fe1.js';
|
|
7
7
|
import { d as defineCustomElement$1 } from './p-e55a7970.js';
|
|
@@ -38,10 +38,6 @@ const SearchcraftInput = /*@__PURE__*/ proxyCustomElement(class SearchcraftInput
|
|
|
38
38
|
* The input element's placeholder value.
|
|
39
39
|
*/
|
|
40
40
|
placeholderValue = 'Enter Search';
|
|
41
|
-
/**
|
|
42
|
-
* The starting value of the input element.
|
|
43
|
-
*/
|
|
44
|
-
searchTerm = '';
|
|
45
41
|
/**
|
|
46
42
|
* When the input becomes focused.
|
|
47
43
|
*/
|
|
@@ -54,7 +50,8 @@ const SearchcraftInput = /*@__PURE__*/ proxyCustomElement(class SearchcraftInput
|
|
|
54
50
|
* Event emitted when input initializes.
|
|
55
51
|
*/
|
|
56
52
|
inputInit;
|
|
57
|
-
inputValue =
|
|
53
|
+
inputValue = '';
|
|
54
|
+
searchTerm = '';
|
|
58
55
|
error = false;
|
|
59
56
|
core;
|
|
60
57
|
searchStore = searchcraftStore.getState();
|
|
@@ -116,9 +113,9 @@ const SearchcraftInput = /*@__PURE__*/ proxyCustomElement(class SearchcraftInput
|
|
|
116
113
|
const inputGridStyles = {
|
|
117
114
|
gap: shouldHaveVerticalGap ? '4px 8px' : '0px 8px',
|
|
118
115
|
};
|
|
119
|
-
return (h("form", { key: '
|
|
116
|
+
return (h("form", { key: 'f08b30d8688e110230c99dbdc0b08aaa259680d1', class: 'searchcraft-input-form', onSubmit: this.handleFormSubmit }, h("div", { key: '32e8cbea58acd0d1e8b14a3ca7363f648df052f1', class: inputGridClassNames, style: inputGridStyles }, h("div", { key: '769484880d0228a5b865fad2c83e6537ae55686a', class: 'searchcraft-input-button-wrapper' }, h("searchcraft-button", { key: '75902602813c266d77c038d106f5a033ff64c477', onButtonClick: this.handleFormSubmit, label: this.buttonLabel })), this.inputLabel && (h("div", { key: '356356b1eac93b52f8622c9c2f414fe76b70e0fe', class: 'searchcraft-input-label-wrapper' }, h("searchcraft-input-label", { key: '4c5a680712b8d26a6326dde48223317b690e7a30', label: this.inputLabel }))), this.error && (h("div", { key: 'e2275fe0907d60e13ac3cb6b2a23e0872c475eb3', class: 'searchcraft-input-error-wrapper' }, h("searchcraft-error-message", { key: '26e7ffbe8fe43f3f5340176e68cf7763d71c4eab', errorMessage: 'Something went wrong.' }))), h("div", { key: 'cfc0d53d4ec644fd453fe39b3091986d9abf2b49', class: 'searchcraft-input-wrapper' }, h("input", { key: '44dcf30e32dcf4de2aeb5c64d445db468fde605b', autoComplete: 'off', class: 'searchcraft-input', onFocus: () => this.inputFocus?.emit(), onBlur: () => this.inputBlur?.emit(), onInput: (event) => {
|
|
120
117
|
this.handleOnInput(event);
|
|
121
|
-
}, placeholder: this.placeholderValue, style: validatedCustomStyles, type: 'text', value: this.inputValue }), h("div", { key: '
|
|
118
|
+
}, placeholder: this.placeholderValue, style: validatedCustomStyles, type: 'text', value: this.inputValue }), h("div", { key: 'a510ee45c5c1fcd8991220dcaed42bdbcef39b49', class: 'searchcraft-input-search-icon-wrapper' }, h("svg", { key: '5dc9bc129a7f550f400aa23b09b38df7aa412821', class: 'searchcraft-input-search-icon', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'searchcraft-title' }, h("title", { key: 'af9c2cb95db7d1f182d4312bccefa97ac95e06aa', id: 'searchcraft-title' }, "Searchcraft Search Icon Light"), h("path", { key: 'c2e8b250f1113670cb2435664a57725563d34efd', 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', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))), isShowingClearButton && (h("button", { key: '0630c1533ab1c9654e9e984a1194759dec2ab535', type: 'button', class: 'searchcraft-input-clear-button', onClick: this.handleClearInput }, h("svg", { key: '052abaa409746a98ee94e09e87e5345c05687dba', class: 'searchcraft-input-clear-icon', viewBox: '0 0 22 22', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'icon-title' }, h("title", { key: '795d7435b5cac2069063a6e6bf40868ddba76516', id: 'icon-title' }, "Searchcraft Clear Input Icon Light"), h("path", { key: '29be529ce60d62136bde73baa2600f3664479c7f', d: 'M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))))))));
|
|
122
119
|
}
|
|
123
120
|
static get watchers() { return {
|
|
124
121
|
"core": ["onCoreChange"]
|
|
@@ -130,9 +127,9 @@ const SearchcraftInput = /*@__PURE__*/ proxyCustomElement(class SearchcraftInput
|
|
|
130
127
|
"inputLabel": [1, "input-label"],
|
|
131
128
|
"customStyles": [1, "custom-styles"],
|
|
132
129
|
"placeholderValue": [1, "placeholder-value"],
|
|
133
|
-
"searchTerm": [1, "search-term"],
|
|
134
130
|
"core": [16],
|
|
135
131
|
"inputValue": [32],
|
|
132
|
+
"searchTerm": [32],
|
|
136
133
|
"error": [32]
|
|
137
134
|
}, undefined, {
|
|
138
135
|
"core": ["onCoreChange"]
|
|
@@ -168,4 +165,4 @@ function defineCustomElement() {
|
|
|
168
165
|
|
|
169
166
|
export { SearchcraftInput as S, defineCustomElement as d };
|
|
170
167
|
|
|
171
|
-
//# sourceMappingURL=p-
|
|
168
|
+
//# sourceMappingURL=p-c1c14447.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"p-c1c14447.js","mappings":";;;;;;;;MAoCa,gBAAgB;;;;;;;;;;;IAInB,UAAU,GAAG,IAAI,CAAC;;;;IAIlB,eAAe,GAA8B,MAAM,CAAC;;;;IAIpD,WAAW,CAAU;;;;IAIrB,UAAU,CAAU;;;;IAIpB,YAAY,GAAoC,EAAE,CAAC;;;;IAInD,gBAAgB,GAAG,cAAc,CAAC;;;;IAIjC,UAAU,CAAsB;;;;IAIhC,SAAS,CAAsB;;;;IAI/B,SAAS,CAAsB;IAE/B,UAAU,GAAG,EAAE,CAAC;IAChB,UAAU,GAAG,EAAE,CAAC;IAChB,KAAK,GAAG,KAAK,CAAC;IAEf,IAAI,CAAmB;IAEvB,WAAW,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;IAElD,IAAI;QACF,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,CAAC,SAAS,EAAE,IAAI,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M,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EACtC,MAAM,EAAE,MAAM,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,EACpC,OAAO,EAAE,CAAC,KAAK;gBACb,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;aAC3B,EACD,WAAW,EAAE,IAAI,CAAC,gBAAgB,EAClC,KAAK,EAAE,qBAAqB,EAC5B,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,IAAI,CAAC,UAAU,GACtB,EACF,4DAAK,KAAK,EAAC,uCAAuC,IAChD,4DACE,KAAK,EAAC,+BAA+B,EACrC,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,4BAA4B,qBAClB,mBAAmB,IAEnC,8DAAO,EAAE,EAAC,mBAAmB,oCAErB,EACR,6DACE,CAAC,EAAC,mNAAmN,EACrN,MAAM,EAAC,cAAc,kBACR,KAAK,oBACH,OAAO,qBACN,OAAO,GACvB,CACE,CACF,EACL,oBAAoB,KACnB,+DACE,IAAI,EAAC,QAAQ,EACb,KAAK,EAAC,gCAAgC,EACtC,OAAO,EAAE,IAAI,CAAC,gBAAgB,IAE9B,4DACE,KAAK,EAAC,8BAA8B,EACpC,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,4BAA4B,qBAClB,YAAY,IAE5B,8DAAO,EAAE,EAAC,YAAY,yCAEd,EACR,6DACE,CAAC,EAAC,uIAAuI,EACzI,MAAM,EAAC,cAAc,kBACR,KAAK,oBACH,OAAO,qBACN,OAAO,GACvB,CACE,CACC,CACV,CACG,CACF,CACD,EACP;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/searchcraft-input-form/searchcraft-input-form.tsx"],"sourcesContent":["import {\n Component,\n h,\n Prop,\n State,\n Event,\n type EventEmitter,\n Watch,\n} from '@stencil/core';\nimport classNames from 'classnames';\n\nimport type { SearchcraftCore } from '@searchcraft/core';\n\nimport { parseCustomStyles } from '@utils';\nimport { searchcraftStore } from '@store';\n\n/**\n * This web component provides a user-friendly interface for querying an indexed dataset, enabling users to easily search large collections of data.\n * It abstracts the complexities of index-based searching, making it accessible to users of all technical levels.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-input-form placeholder-value=\"Search here\" />\n * ```\n *\n * ```js\n * // index.js\n * const searchInputForm = document.querySelector('searchcraft-input-form');\n *\n * ```\n */\n@Component({\n tag: 'searchcraft-input-form',\n shadow: false,\n})\nexport class SearchcraftInput {\n /**\n * Whether or not to automatically submit the search term when the input changes.\n */\n @Prop() autoSearch = true;\n /**\n * Where to place the search button.\n */\n @Prop() buttonPlacement: 'left' | 'right' | 'none' = 'none';\n /**\n * The label for the submit button.\n */\n @Prop() buttonLabel?: string;\n /**\n * The label rendered above the input.\n */\n @Prop() inputLabel?: string;\n /**\n * A custom styles object to be applied to the input element.\n */\n @Prop() customStyles: string | Record<string, string> = {};\n /**\n * The input element's placeholder value.\n */\n @Prop() placeholderValue = 'Enter Search';\n /**\n * When the input becomes focused.\n */\n @Event() inputFocus?: EventEmitter<void>;\n /**\n * When the input becomes unfocused.\n */\n @Event() inputBlur?: EventEmitter<void>;\n /**\n * Event emitted when input initializes.\n */\n @Event() inputInit?: EventEmitter<void>;\n\n @State() inputValue = '';\n @State() searchTerm = '';\n @State() error = false;\n\n @Prop() core?: SearchcraftCore;\n\n private searchStore = searchcraftStore.getState();\n\n init() {\n if (this.core) {\n this.searchStore.initialize(this.core);\n this.inputInit?.emit();\n }\n }\n\n connectedCallback() {\n this.init();\n }\n\n @Watch('core')\n onCoreChange() {\n this.init();\n }\n\n handleOnInput = (event: Event) => {\n const input = event.target as HTMLInputElement;\n this.inputValue = input.value;\n\n if (!this.autoSearch) {\n return;\n }\n\n this.performSearch(input.value);\n };\n\n private performSearch = async (value: string) => {\n if (value === searchcraftStore.getState().searchTerm) {\n return;\n }\n\n this.searchTerm = value.trim();\n this.error = false;\n this.searchStore.setSearchTerm(this.searchTerm);\n\n try {\n await this.searchStore.search();\n } catch (error) {\n console.log(error);\n this.error = true;\n }\n };\n\n handleClearInput = () => {\n this.inputValue = '';\n this.searchTerm = '';\n this.searchStore.setSearchTerm('');\n this.searchStore.setSearchClientResponseItems([]);\n this.error = false;\n };\n\n handleFormSubmit = async (event: Event) => {\n event.preventDefault();\n await this.performSearch(this.searchTerm);\n };\n\n render() {\n const validatedCustomStyles = parseCustomStyles(this.customStyles);\n\n const isShowingClearButton = this.inputValue.length > 0;\n\n const inputGridClassNames = classNames('searchcraft-input-grid', {\n 'searchcraft-input-grid-buttonLeft': this.buttonPlacement === 'left',\n 'searchcraft-input-grid-buttonRight': this.buttonPlacement === 'right',\n 'searchcraft-input-grid-buttonNone': this.buttonPlacement === 'none',\n });\n\n const shouldHaveVerticalGap = this.inputLabel || this.error;\n const inputGridStyles = {\n gap: shouldHaveVerticalGap ? '4px 8px' : '0px 8px',\n };\n\n return (\n <form class='searchcraft-input-form' onSubmit={this.handleFormSubmit}>\n <div class={inputGridClassNames} style={inputGridStyles}>\n <div class='searchcraft-input-button-wrapper'>\n <searchcraft-button\n onButtonClick={this.handleFormSubmit}\n label={this.buttonLabel}\n />\n </div>\n {this.inputLabel && (\n <div class='searchcraft-input-label-wrapper'>\n <searchcraft-input-label label={this.inputLabel} />\n </div>\n )}\n {this.error && (\n <div class='searchcraft-input-error-wrapper'>\n <searchcraft-error-message errorMessage='Something went wrong.' />\n </div>\n )}\n <div class='searchcraft-input-wrapper'>\n <input\n autoComplete='off'\n class='searchcraft-input'\n onFocus={() => this.inputFocus?.emit()}\n onBlur={() => this.inputBlur?.emit()}\n onInput={(event) => {\n this.handleOnInput(event);\n }}\n placeholder={this.placeholderValue}\n style={validatedCustomStyles}\n type='text'\n value={this.inputValue}\n />\n <div class='searchcraft-input-search-icon-wrapper'>\n <svg\n class='searchcraft-input-search-icon'\n viewBox='0 0 20 20'\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n aria-labelledby='searchcraft-title'\n >\n <title id='searchcraft-title'>\n Searchcraft Search Icon Light\n </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 </div>\n {isShowingClearButton && (\n <button\n type='button'\n class='searchcraft-input-clear-button'\n onClick={this.handleClearInput}\n >\n <svg\n class='searchcraft-input-clear-icon'\n viewBox='0 0 22 22'\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n aria-labelledby='icon-title'\n >\n <title id='icon-title'>\n Searchcraft Clear Input Icon Light\n </title>\n <path\n d='M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z'\n stroke='currentColor'\n stroke-width='1.5'\n stroke-linecap='round'\n stroke-linejoin='round'\n />\n </svg>\n </button>\n )}\n </div>\n </div>\n </form>\n );\n }\n}\n"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftPopoverListItemAd, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftPopoverListItemAd, d as defineCustomElement$1 } from './p-10b0d0dc.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftAd = SearchcraftPopoverListItemAd;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftBaseSearchResult$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftBaseSearchResult$1, d as defineCustomElement$1 } from './p-9bdcb929.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftBaseSearchResult = SearchcraftBaseSearchResult$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,8 +1,8 @@
|
|
|
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-2e293015.js';
|
|
3
3
|
import { s as serializeStyles } from './p-d9551738.js';
|
|
4
|
-
import { d as defineCustomElement$4 } from './p-
|
|
5
|
-
import { d as defineCustomElement$3 } from './p-
|
|
4
|
+
import { d as defineCustomElement$4 } from './p-10b0d0dc.js';
|
|
5
|
+
import { d as defineCustomElement$3 } from './p-9bdcb929.js';
|
|
6
6
|
import { d as defineCustomElement$2 } from './p-0e393fe1.js';
|
|
7
7
|
|
|
8
8
|
const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftBaseSearchResults extends H {
|
|
@@ -43,11 +43,11 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
43
43
|
*/
|
|
44
44
|
containerRel;
|
|
45
45
|
searchTerm = '';
|
|
46
|
-
searchClientResponseItems
|
|
46
|
+
searchClientResponseItems;
|
|
47
47
|
adClientResponseItems = [];
|
|
48
48
|
searchResultsPerPage;
|
|
49
49
|
searchResultsPage;
|
|
50
|
-
isSearchInProgress =
|
|
50
|
+
isSearchInProgress = true;
|
|
51
51
|
config;
|
|
52
52
|
unsubscribe = () => { };
|
|
53
53
|
get serializedStyles() {
|
|
@@ -63,6 +63,7 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
63
63
|
componentDidLoad() {
|
|
64
64
|
this.unsubscribe = searchcraftStore.subscribe((state) => this.handleStateChange(state));
|
|
65
65
|
const currentState = searchcraftStore.getState();
|
|
66
|
+
this.handleStateChange(currentState);
|
|
66
67
|
this.searchClientResponseItems = currentState.searchClientResponseItems;
|
|
67
68
|
this.searchTerm = currentState.searchTerm;
|
|
68
69
|
this.config = currentState.core?.config;
|
|
@@ -117,6 +118,36 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
117
118
|
}
|
|
118
119
|
return (h("div", { class: 'searchcraft-search-results-container' }, itemsToRender));
|
|
119
120
|
}
|
|
121
|
+
renderWithNativoAds() {
|
|
122
|
+
const itemsToRender = [];
|
|
123
|
+
const interstitialStartIndex = this.config?.nativoAdInterstialStartIndex || 0;
|
|
124
|
+
const interstitialInterval = this.config?.nativoAdInterstitialInterval || 0;
|
|
125
|
+
const interstitialQuantity = this.config?.nativoAdInterstitialQuantity || 1;
|
|
126
|
+
const adStartQuantity = this.config?.nativoAdStartQuantity || 0;
|
|
127
|
+
const adEndQuantity = this.config?.nativoAdEndQuantity || 0;
|
|
128
|
+
const searchItems = this.searchClientResponseItems || [];
|
|
129
|
+
// Renders ads at beginning
|
|
130
|
+
for (let n = 0; n < adStartQuantity; n++) {
|
|
131
|
+
itemsToRender.push(h("searchcraft-ad", { adSource: 'Nativo', key: `${n}-ad` }));
|
|
132
|
+
}
|
|
133
|
+
// Renders search results + interstitial ads
|
|
134
|
+
searchItems.forEach((item, index) => {
|
|
135
|
+
if (interstitialInterval &&
|
|
136
|
+
(index + interstitialStartIndex) % interstitialInterval === 0 &&
|
|
137
|
+
index + interstitialInterval < searchItems.length &&
|
|
138
|
+
index >= interstitialInterval) {
|
|
139
|
+
for (let n = 0; n < interstitialQuantity; n++) {
|
|
140
|
+
itemsToRender.push(h("searchcraft-ad", { adSource: 'Nativo', key: `${item.id}-ad-${n}` }));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
itemsToRender.push(h("searchcraft-base-search-result", { key: item.id, "custom-styles": this.serializedStyles, "image-placement": this.resultImagePlacement, "container-rel": this.containerRel, "container-target": this.containerTarget, "button-label": this.buttonLabel || 'View more', "button-rel": this.buttonRel, "button-target": this.buttonTarget, "document-position": this.searchResultsPerPage * (this.searchResultsPage - 1) + index, searchResultMappings: this.searchResultMappings, item: item }));
|
|
144
|
+
});
|
|
145
|
+
// Renders ads at end
|
|
146
|
+
for (let n = 0; n < adEndQuantity; n++) {
|
|
147
|
+
itemsToRender.push(h("searchcraft-ad", { adSource: 'Nativo', key: `${n}-ad` }));
|
|
148
|
+
}
|
|
149
|
+
return (h("div", { class: 'searchcraft-search-results-container' }, itemsToRender));
|
|
150
|
+
}
|
|
120
151
|
renderWithNoAds() {
|
|
121
152
|
return (h("div", { class: 'searchcraft-search-results-container' }, this.searchClientResponseItems?.map((item, index) => (h("searchcraft-base-search-result", { key: item.id, "custom-styles": this.serializedStyles, "image-placement": this.resultImagePlacement, "container-rel": this.containerRel, "container-target": this.containerTarget, "button-label": this.buttonLabel || 'View more', "button-rel": this.buttonRel, "button-target": this.buttonTarget, "document-position": this.searchResultsPerPage * (this.searchResultsPage - 1) + index, searchResultMappings: this.searchResultMappings, item: item })))));
|
|
122
153
|
}
|
|
@@ -125,7 +156,7 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
125
156
|
return this.renderEmptyState();
|
|
126
157
|
}
|
|
127
158
|
if (this.searchTerm.length > 0 &&
|
|
128
|
-
this.searchClientResponseItems.length === 0 &&
|
|
159
|
+
(this.searchClientResponseItems || []).length === 0 &&
|
|
129
160
|
!this.isSearchInProgress) {
|
|
130
161
|
return this.renderNoResultsFoundState();
|
|
131
162
|
}
|
|
@@ -134,6 +165,8 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
134
165
|
return this.renderWithADMAds();
|
|
135
166
|
case 'Custom':
|
|
136
167
|
return this.renderWithCustomAds();
|
|
168
|
+
case 'Nativo':
|
|
169
|
+
return this.renderWithNativoAds();
|
|
137
170
|
default:
|
|
138
171
|
return this.renderWithNoAds();
|
|
139
172
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"searchcraft-base-search-results.js","mappings":";;;;;;;MA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H,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,IAAI,CAAC,yBAAyB,CAAC,MAAM,KAAK,CAAC;YAC3C,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;gBACE,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;SACjC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SearchcraftBaseSearchResults"],"sources":["src/components/searchcraft-base-search-results/searchcraft-base-search-results.tsx"],"sourcesContent":["import { Component, h, Prop, State, type JSX } from '@stencil/core';\n\nimport type {\n AdClientResponseItem,\n SearchClientResponseItem,\n SearchcraftConfig,\n} from '@searchcraft/core';\n\nimport { type SearchcraftState, searchcraftStore } from '@store';\n\nimport { serializeStyles } from '@utils';\nimport type { SearchResultMappings } from '@searchcraft/core';\n\n/**\n * This web component is responsible for displaying the results of a search query.\n * Once a query is submitted, the component formats and presents an ordered list of the results.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-base-search-results\n * ad-interval=\"4\"\n * place-ad-at-start=\"false\"\n * result-image-placement=\"right\"\n * />\n * ```\n *\n * ```js\n * // index.js\n * const baseSearchResults = document.querySelector('searchcraft-base-search-results');\n *\n * baseSearchResults.searchResultMappings = containerHref: {\n * fieldNames: [\n * {\n * fieldName: 'canonical_link',\n * dataType: 'text',\n * },\n * ],\n * };\n *\n * baseSearchResults.addEventListener('noResults', () => {\n * console.log('No search results found');\n * });\n * ```\n */\n@Component({\n tag: 'searchcraft-base-search-results',\n shadow: false,\n})\nexport class SearchcraftBaseSearchResults {\n /**\n * A custom styles object.\n */\n @Prop() customStylesForResults?:\n | string\n | Record<string, Record<string, string>>;\n /**\n * Formats the content rendered for each result.\n */\n @Prop() searchResultMappings?: SearchResultMappings;\n /**\n * The placement of the image for each result.\n */\n @Prop() resultImagePlacement: 'left' | 'right' = 'right';\n /**\n * The label for the button rendered when containerHref is not present for each result.\n */\n @Prop() buttonLabel?: string;\n /**\n * Where to open the link for the button rendered when containerHref is not present for each result.\n */\n @Prop() buttonTarget: '_blank' | '_self' | '_top' | '_parent' = '_blank';\n /**\n * The relationship between the current document and the link for the button rendered when containerHref is not present for each result.\n */\n @Prop() buttonRel?: 'noreferrer' | 'noopener' | 'nofollow';\n /**\n * Where to open the link for the containing element for each result.\n */\n @Prop() containerTarget: '_blank' | '_self' | '_top' | '_parent' = '_blank';\n /**\n * The relationship between the current document and the link for the containing element for each result.\n */\n @Prop() containerRel?: 'noreferrer' | 'noopener' | 'nofollow';\n\n @State() searchTerm = '';\n @State() searchClientResponseItems: SearchClientResponseItem[] = [];\n @State() adClientResponseItems: AdClientResponseItem[] = [];\n @State() searchResultsPerPage;\n @State() searchResultsPage;\n @State() isSearchInProgress = false;\n @State() config?: SearchcraftConfig;\n\n private unsubscribe: () => void = () => {};\n\n get serializedStyles(): string {\n let serializedStyles = '';\n if (this.customStylesForResults) {\n serializedStyles =\n typeof this.customStylesForResults === 'string'\n ? this.customStylesForResults\n : serializeStyles(this.customStylesForResults);\n }\n return serializedStyles;\n }\n\n componentDidLoad() {\n this.unsubscribe = searchcraftStore.subscribe((state) =>\n this.handleStateChange(state),\n );\n const currentState = searchcraftStore.getState();\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-container'>\n <slot name='empty-search' />\n </div>\n );\n }\n\n renderNoResultsFoundState() {\n return (\n <div class='searchcraft-search-results-container'>\n <div class='searchcraft-search-results-error-message-container'>\n <searchcraft-error-message\n error-message={`No search results found for \"${this.searchTerm}\" query`}\n />\n </div>\n </div>\n );\n }\n\n renderWithADMAds() {\n return (\n <div class='searchcraft-search-results-container'>\n {this.adClientResponseItems?.map((item) => (\n <searchcraft-ad\n adSource='adMarketplace'\n adClientResponseItem={item}\n key={item.id}\n />\n ))}\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\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(<searchcraft-ad adSource='Custom' key={`${n}-ad`} />);\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 adSource='Custom' key={`${item.id}-ad-${n}`} />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(<searchcraft-ad adSource='Custom' key={`${n}-ad`} />);\n }\n\n return (\n <div class='searchcraft-search-results-container'>{itemsToRender}</div>\n );\n }\n\n renderWithNoAds() {\n return (\n <div class='searchcraft-search-results-container'>\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\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 default:\n return this.renderWithNoAds();\n }\n }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,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":["SearchcraftBaseSearchResults"],"sources":["src/components/searchcraft-base-search-results/searchcraft-base-search-results.tsx"],"sourcesContent":["import { Component, h, Prop, State, type JSX } from '@stencil/core';\n\nimport type {\n AdClientResponseItem,\n SearchClientResponseItem,\n SearchcraftConfig,\n} from '@searchcraft/core';\n\nimport { type SearchcraftState, searchcraftStore } from '@store';\n\nimport { serializeStyles } from '@utils';\nimport type { SearchResultMappings } from '@searchcraft/core';\n\n/**\n * This web component is responsible for displaying the results of a search query.\n * Once a query is submitted, the component formats and presents an ordered list of the results.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-base-search-results\n * ad-interval=\"4\"\n * place-ad-at-start=\"false\"\n * result-image-placement=\"right\"\n * />\n * ```\n *\n * ```js\n * // index.js\n * const baseSearchResults = document.querySelector('searchcraft-base-search-results');\n *\n * baseSearchResults.searchResultMappings = containerHref: {\n * fieldNames: [\n * {\n * fieldName: 'canonical_link',\n * dataType: 'text',\n * },\n * ],\n * };\n *\n * baseSearchResults.addEventListener('noResults', () => {\n * console.log('No search results found');\n * });\n * ```\n */\n@Component({\n tag: 'searchcraft-base-search-results',\n shadow: false,\n})\nexport class SearchcraftBaseSearchResults {\n /**\n * A custom styles object.\n */\n @Prop() customStylesForResults?:\n | string\n | Record<string, Record<string, string>>;\n /**\n * Formats the content rendered for each result.\n */\n @Prop() searchResultMappings?: SearchResultMappings;\n /**\n * The placement of the image for each result.\n */\n @Prop() resultImagePlacement: 'left' | 'right' = 'right';\n /**\n * The label for the button rendered when containerHref is not present for each result.\n */\n @Prop() buttonLabel?: string;\n /**\n * Where to open the link for the button rendered when containerHref is not present for each result.\n */\n @Prop() buttonTarget: '_blank' | '_self' | '_top' | '_parent' = '_blank';\n /**\n * The relationship between the current document and the link for the button rendered when containerHref is not present for each result.\n */\n @Prop() buttonRel?: 'noreferrer' | 'noopener' | 'nofollow';\n /**\n * Where to open the link for the containing element for each result.\n */\n @Prop() containerTarget: '_blank' | '_self' | '_top' | '_parent' = '_blank';\n /**\n * The relationship between the current document and the link for the containing element for each result.\n */\n @Prop() containerRel?: 'noreferrer' | 'noopener' | 'nofollow';\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 get serializedStyles(): string {\n let serializedStyles = '';\n if (this.customStylesForResults) {\n serializedStyles =\n typeof this.customStylesForResults === 'string'\n ? this.customStylesForResults\n : serializeStyles(this.customStylesForResults);\n }\n return serializedStyles;\n }\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-container'>\n <slot name='empty-search' />\n </div>\n );\n }\n\n renderNoResultsFoundState() {\n return (\n <div class='searchcraft-search-results-container'>\n <div class='searchcraft-search-results-error-message-container'>\n <searchcraft-error-message\n error-message={`No search results found for \"${this.searchTerm}\" query`}\n />\n </div>\n </div>\n );\n }\n\n renderWithADMAds() {\n return (\n <div class='searchcraft-search-results-container'>\n {this.adClientResponseItems?.map((item) => (\n <searchcraft-ad\n adSource='adMarketplace'\n adClientResponseItem={item}\n key={item.id}\n />\n ))}\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\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(<searchcraft-ad adSource='Custom' key={`${n}-ad`} />);\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 adSource='Custom' key={`${item.id}-ad-${n}`} />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(<searchcraft-ad adSource='Custom' key={`${n}-ad`} />);\n }\n\n return (\n <div class='searchcraft-search-results-container'>{itemsToRender}</div>\n );\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(<searchcraft-ad adSource='Nativo' key={`${n}-ad`} />);\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 adSource='Nativo' key={`${item.id}-ad-${n}`} />,\n );\n }\n }\n itemsToRender.push(\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(<searchcraft-ad adSource='Nativo' key={`${n}-ad`} />);\n }\n\n return (\n <div class='searchcraft-search-results-container'>{itemsToRender}</div>\n );\n }\n\n renderWithNoAds() {\n return (\n <div class='searchcraft-search-results-container'>\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-base-search-result\n key={item.id}\n custom-styles={this.serializedStyles}\n image-placement={this.resultImagePlacement}\n container-rel={this.containerRel}\n container-target={this.containerTarget}\n button-label={this.buttonLabel || 'View more'}\n button-rel={this.buttonRel}\n button-target={this.buttonTarget}\n document-position={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n searchResultMappings={this.searchResultMappings}\n item={item}\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,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftFacetList$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftFacetList$1, d as defineCustomElement$1 } from './p-0bbc3aff.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftFacetList = SearchcraftFacetList$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -1,9 +1,9 @@
|
|
|
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-2e293015.js';
|
|
3
3
|
import { g as getMillis } from './p-6104fe5d.js';
|
|
4
|
-
import { d as defineCustomElement$4 } from './p-
|
|
4
|
+
import { d as defineCustomElement$4 } from './p-0bbc3aff.js';
|
|
5
5
|
import { d as defineCustomElement$3 } from './p-bb12ab5a.js';
|
|
6
|
-
import { d as defineCustomElement$2 } from './p-
|
|
6
|
+
import { d as defineCustomElement$2 } from './p-bb9e9d7d.js';
|
|
7
7
|
|
|
8
8
|
const SearchcraftFilterPanel$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftFilterPanel extends H {
|
|
9
9
|
constructor() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftInput, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftInput, d as defineCustomElement$1 } from './p-c1c14447.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftInputForm = SearchcraftInput;
|
|
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-2e293015.js';
|
|
3
3
|
import { c as classNames } from './p-5cdc6210.js';
|
|
4
4
|
import { p as parseCustomStyles } from './p-d9551738.js';
|
|
5
5
|
import { d as defineCustomElement$2 } from './p-71cc28c1.js';
|
|
@@ -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-2e293015.js';
|
|
3
3
|
|
|
4
4
|
const SearchcraftPopoverButton$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftPopoverButton extends H {
|
|
5
5
|
constructor() {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { p as proxyCustomElement, H, h } from './p-5365011f.js';
|
|
2
2
|
import { c as classNames } from './p-5cdc6210.js';
|
|
3
|
-
import { s as searchcraftStore } from './p-
|
|
4
|
-
import { d as defineCustomElement$8 } from './p-
|
|
3
|
+
import { s as searchcraftStore } from './p-2e293015.js';
|
|
4
|
+
import { d as defineCustomElement$8 } from './p-10b0d0dc.js';
|
|
5
5
|
import { d as defineCustomElement$7 } from './p-71cc28c1.js';
|
|
6
6
|
import { d as defineCustomElement$6 } from './p-0e393fe1.js';
|
|
7
|
-
import { d as defineCustomElement$5 } from './p-
|
|
7
|
+
import { d as defineCustomElement$5 } from './p-c1c14447.js';
|
|
8
8
|
import { d as defineCustomElement$4 } from './p-e55a7970.js';
|
|
9
|
-
import { d as defineCustomElement$3 } from './p-
|
|
10
|
-
import { d as defineCustomElement$2 } from './p-
|
|
9
|
+
import { d as defineCustomElement$3 } from './p-44e6ed36.js';
|
|
10
|
+
import { d as defineCustomElement$2 } from './p-94837dcb.js';
|
|
11
11
|
|
|
12
12
|
const SearchcraftPopoverForm$1 = /*@__PURE__*/ proxyCustomElement(class SearchcraftPopoverForm extends H {
|
|
13
13
|
constructor() {
|
|
@@ -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-44e6ed36.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-94837dcb.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
2
|
import { c as classNames } from './p-5cdc6210.js';
|
|
3
|
-
import { s as searchcraftStore } from './p-
|
|
3
|
+
import { s as searchcraftStore } from './p-2e293015.js';
|
|
4
4
|
import { f as formatNumberWithCommas } from './p-6104fe5d.js';
|
|
5
5
|
import { p as parseCustomStyles } from './p-d9551738.js';
|
|
6
6
|
|
|
@@ -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-2e293015.js';
|
|
3
3
|
import { c as classNames } from './p-5cdc6210.js';
|
|
4
4
|
import { p as parseCustomStyles } from './p-d9551738.js';
|
|
5
5
|
import { d as defineCustomElement$2 } from './p-bf6a086a.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SearchcraftToggleButton$1, d as defineCustomElement$1 } from './p-
|
|
1
|
+
import { S as SearchcraftToggleButton$1, d as defineCustomElement$1 } from './p-bb9e9d7d.js';
|
|
2
2
|
|
|
3
3
|
const SearchcraftToggleButton = SearchcraftToggleButton$1;
|
|
4
4
|
const defineCustomElement = defineCustomElement$1;
|
|
@@ -5,11 +5,15 @@ import type { AdClientResponseItem, SearchcraftAdSource } from '@searchcraft/cor
|
|
|
5
5
|
export declare class SearchcraftPopoverListItemAd {
|
|
6
6
|
adSource: SearchcraftAdSource;
|
|
7
7
|
adClientResponseItem?: AdClientResponseItem;
|
|
8
|
-
searchTerm
|
|
9
|
-
|
|
8
|
+
searchTerm?: string;
|
|
9
|
+
isSearchInProgress: boolean;
|
|
10
|
+
hostElement?: HTMLElement;
|
|
10
11
|
private core?;
|
|
11
12
|
private adContainerId;
|
|
13
|
+
private intersectionObserver?;
|
|
14
|
+
private storeUnsubscribe?;
|
|
12
15
|
connectedCallback(): void;
|
|
16
|
+
componentDidLoad(): void;
|
|
13
17
|
disconnectedCallback(): void;
|
|
14
18
|
renderADMAd(): any;
|
|
15
19
|
renderCustomAd(): any;
|
package/dist/types/components/searchcraft-base-search-results/searchcraft-base-search-results.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export declare class SearchcraftBaseSearchResults {
|
|
|
67
67
|
*/
|
|
68
68
|
containerRel?: 'noreferrer' | 'noopener' | 'nofollow';
|
|
69
69
|
searchTerm: string;
|
|
70
|
-
searchClientResponseItems
|
|
70
|
+
searchClientResponseItems?: SearchClientResponseItem[];
|
|
71
71
|
adClientResponseItems: AdClientResponseItem[];
|
|
72
72
|
searchResultsPerPage: any;
|
|
73
73
|
searchResultsPage: any;
|
|
@@ -82,6 +82,7 @@ export declare class SearchcraftBaseSearchResults {
|
|
|
82
82
|
renderNoResultsFoundState(): any;
|
|
83
83
|
renderWithADMAds(): any;
|
|
84
84
|
renderWithCustomAds(): any;
|
|
85
|
+
renderWithNativoAds(): any;
|
|
85
86
|
renderWithNoAds(): any;
|
|
86
87
|
render(): any;
|
|
87
88
|
}
|
|
@@ -41,10 +41,6 @@ export declare class SearchcraftInput {
|
|
|
41
41
|
* The input element's placeholder value.
|
|
42
42
|
*/
|
|
43
43
|
placeholderValue: string;
|
|
44
|
-
/**
|
|
45
|
-
* The starting value of the input element.
|
|
46
|
-
*/
|
|
47
|
-
searchTerm: string;
|
|
48
44
|
/**
|
|
49
45
|
* When the input becomes focused.
|
|
50
46
|
*/
|
|
@@ -58,6 +54,7 @@ export declare class SearchcraftInput {
|
|
|
58
54
|
*/
|
|
59
55
|
inputInit?: EventEmitter<void>;
|
|
60
56
|
inputValue: string;
|
|
57
|
+
searchTerm: string;
|
|
61
58
|
error: boolean;
|
|
62
59
|
core?: SearchcraftCore;
|
|
63
60
|
private searchStore;
|
|
@@ -241,10 +241,6 @@ export namespace Components {
|
|
|
241
241
|
* The input element's placeholder value.
|
|
242
242
|
*/
|
|
243
243
|
"placeholderValue": string;
|
|
244
|
-
/**
|
|
245
|
-
* The starting value of the input element.
|
|
246
|
-
*/
|
|
247
|
-
"searchTerm": string;
|
|
248
244
|
}
|
|
249
245
|
/**
|
|
250
246
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -1180,10 +1176,6 @@ declare namespace LocalJSX {
|
|
|
1180
1176
|
* The input element's placeholder value.
|
|
1181
1177
|
*/
|
|
1182
1178
|
"placeholderValue"?: string;
|
|
1183
|
-
/**
|
|
1184
|
-
* The starting value of the input element.
|
|
1185
|
-
*/
|
|
1186
|
-
"searchTerm"?: string;
|
|
1187
1179
|
}
|
|
1188
1180
|
/**
|
|
1189
1181
|
* This web component serves as the input label for the searchcraft-input-form component.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchcraft/javascript-sdk",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.6",
|
|
5
5
|
"description": "Searchcraft Javascript SDK",
|
|
6
6
|
"author": "Searchcraft",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"nanoid": "^5.0.9"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@searchcraft/core": "^0.9.
|
|
45
|
+
"@searchcraft/core": "^0.9.6",
|
|
46
46
|
"@stencil/core": "^4.7.0",
|
|
47
47
|
"@stencil/react-output-target": "^0.8.2",
|
|
48
48
|
"@stencil/sass": "^3.0.12",
|
|
49
49
|
"@types/node": "^16.18.11",
|
|
50
50
|
"zustand": "^5.0.1"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "4f86cf0a356f106eaafc88b457418567a5865518"
|
|
53
53
|
}
|