@searchcraft/javascript-sdk 0.9.1 → 0.9.3
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.js
CHANGED
|
@@ -24,7 +24,7 @@ export { SearchcraftToggleButton, defineCustomElement as defineCustomElementSear
|
|
|
24
24
|
export { p as parseCustomStyles, s as serializeStyles } from './p-d9551738.js';
|
|
25
25
|
|
|
26
26
|
const name = "@searchcraft/javascript-sdk";
|
|
27
|
-
const version = "0.9.
|
|
27
|
+
const version = "0.9.3";
|
|
28
28
|
const description = "Searchcraft Javascript SDK";
|
|
29
29
|
const author = "Searchcraft";
|
|
30
30
|
const license = "Apache-2.0";
|
|
@@ -65,7 +65,7 @@ const dependencies = {
|
|
|
65
65
|
nanoid: "^5.0.9"
|
|
66
66
|
};
|
|
67
67
|
const devDependencies = {
|
|
68
|
-
"@searchcraft/core": "^0.9.
|
|
68
|
+
"@searchcraft/core": "^0.9.3",
|
|
69
69
|
"@stencil/core": "^4.7.0",
|
|
70
70
|
"@stencil/react-output-target": "^0.8.2",
|
|
71
71
|
"@stencil/sass": "^3.0.12",
|
|
@@ -86,7 +86,7 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
86
86
|
return (h("div", { class: 'searchcraft-search-results-container' }, h("div", { class: 'searchcraft-search-results-error-message-container' }, h("searchcraft-error-message", { "error-message": `No search results found for "${this.searchTerm}" query` }))));
|
|
87
87
|
}
|
|
88
88
|
renderWithADMAds() {
|
|
89
|
-
return (h("div", { class: 'searchcraft-search-results-container' }, this.adClientResponseItems?.map((item) => (h("searchcraft-ad", { adSource: 'adMarketplace', adClientResponseItem: item, key: item.id }))), 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 + index, searchResultMappings: this.searchResultMappings, item: item })))));
|
|
89
|
+
return (h("div", { class: 'searchcraft-search-results-container' }, this.adClientResponseItems?.map((item) => (h("searchcraft-ad", { adSource: 'adMarketplace', adClientResponseItem: item, key: item.id }))), 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 })))));
|
|
90
90
|
}
|
|
91
91
|
renderWithCustomAds() {
|
|
92
92
|
const itemsToRender = [];
|
|
@@ -109,7 +109,7 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
109
109
|
itemsToRender.push(h("searchcraft-ad", { adSource: 'Custom', key: `${item.id}-ad-${n}` }));
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
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 + index, searchResultMappings: this.searchResultMappings, item: item }));
|
|
112
|
+
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 }));
|
|
113
113
|
});
|
|
114
114
|
// Renders ads at end
|
|
115
115
|
for (let n = 0; n < adEndQuantity; n++) {
|
|
@@ -118,7 +118,7 @@ const SearchcraftBaseSearchResults$1 = /*@__PURE__*/ proxyCustomElement(class Se
|
|
|
118
118
|
return (h("div", { class: 'searchcraft-search-results-container' }, itemsToRender));
|
|
119
119
|
}
|
|
120
120
|
renderWithNoAds() {
|
|
121
|
-
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 + index, searchResultMappings: this.searchResultMappings, item: item })))));
|
|
121
|
+
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
122
|
}
|
|
123
123
|
render() {
|
|
124
124
|
if (this.searchTerm.trim() === '') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"searchcraft-base-search-results.js","mappings":";;;;;;;MAiDaA,8BAA4B;;;;;;;;IAI/B,sBAAsB,CAEa;;;;IAInC,oBAAoB,CAAwB;;;;IAI5C,oBAAoB,GAAqB,OAAO,CAAC;;;;IAIjD,WAAW,CAAU;;;;IAIrB,YAAY,GAA4C,QAAQ,CAAC;;;;IAIjE,SAAS,CAA0C;;;;IAInD,eAAe,GAA4C,QAAQ,CAAC;;;;IAIpE,YAAY,CAA0C;IAErD,UAAU,GAAG,EAAE,CAAC;IAChB,yBAAyB,GAA+B,EAAE,CAAC;IAC3D,qB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E,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 + 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 + 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 + 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 }\n}\n"],"version":3}
|
|
1
|
+
{"file":"searchcraft-base-search-results.js","mappings":";;;;;;;MAiDaA,8BAA4B;;;;;;;;IAI/B,sBAAsB,CAEa;;;;IAInC,oBAAoB,CAAwB;;;;IAI5C,oBAAoB,GAAqB,OAAO,CAAC;;;;IAIjD,WAAW,CAAU;;;;IAIrB,YAAY,GAA4C,QAAQ,CAAC;;;;IAIjE,SAAS,CAA0C;;;;IAInD,eAAe,GAA4C,QAAQ,CAAC;;;;IAIpE,YAAY,CAA0C;IAErD,UAAU,GAAG,EAAE,CAAC;IAChB,yBAAyB,GAA+B,EAAE,CAAC;IAC3D,qBAA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E,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 }\n}\n"],"version":3}
|
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.3",
|
|
5
5
|
"description": "Searchcraft Javascript SDK",
|
|
6
6
|
"author": "Searchcraft",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"nanoid": "^5.0.9"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@searchcraft/core": "^0.9.
|
|
46
|
+
"@searchcraft/core": "^0.9.3",
|
|
47
47
|
"@stencil/core": "^4.7.0",
|
|
48
48
|
"@stencil/react-output-target": "^0.8.2",
|
|
49
49
|
"@stencil/sass": "^3.0.12",
|
|
50
50
|
"@types/node": "^16.18.11",
|
|
51
51
|
"zustand": "^5.0.1"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "065d4f8272362e875356b921c32bba36af75637d"
|
|
54
54
|
}
|