@nosto/search-js 3.17.1 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AutocompletePageProvider-CBobTZvT.cjs → AutocompletePageProvider-CjNvOYZz.cjs} +1 -1
- package/dist/{AutocompletePageProvider-Z4OvIKy-.js → AutocompletePageProvider-DMtA79nZ.js} +3 -3
- package/dist/{CategoryPageProvider-CYRnaUx1.cjs → CategoryPageProvider-2ZmajAxh.cjs} +1 -1
- package/dist/{CategoryPageProvider-DcQlylFg.js → CategoryPageProvider-DU3DjmnJ.js} +2 -2
- package/dist/{InfiniteScrollWithObserver-kW5lM7Jh.js → InfiniteScrollWithObserver-B0iiezKy.js} +1 -1
- package/dist/{InfiniteScrollWithObserver-CwWRBU3q.cjs → InfiniteScrollWithObserver-LxLj-_bT.cjs} +1 -1
- package/dist/{SerpPageProvider-s4dO49Fx.cjs → SerpPageProvider-Dn6PSZoF.cjs} +1 -1
- package/dist/{SerpPageProvider-CsrFA6mA.js → SerpPageProvider-DshgTNpM.js} +2 -2
- package/dist/{baseConfig-gkfFlBOL.cjs → baseConfig-CaRa_-zN.cjs} +1 -1
- package/dist/{baseConfig-BMc1698x.js → baseConfig-DeHr2N1l.js} +1 -1
- package/dist/preact/autocomplete/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete/autocomplete.es.js +1 -1
- package/dist/preact/category/category.cjs.js +1 -1
- package/dist/preact/category/category.es.js +1 -1
- package/dist/preact/common/common.cjs.js +1 -1
- package/dist/preact/common/common.es.js +3 -3
- package/dist/preact/hooks/hooks.cjs.js +1 -1
- package/dist/preact/hooks/hooks.es.js +269 -249
- package/dist/preact/hooks/src/useRange.d.ts +18 -5
- package/dist/preact/inject/inject.cjs.js +1 -1
- package/dist/preact/inject/inject.es.js +4 -4
- package/dist/preact/legacy/legacy.cjs.js +1 -1
- package/dist/preact/legacy/legacy.es.js +3 -3
- package/dist/preact/serp/serp.cjs.js +1 -1
- package/dist/preact/serp/serp.es.js +2 -2
- package/dist/{useActions-MsVW37eV.js → useActions-CSNwQtT1.js} +53 -53
- package/dist/useActions-CY9uts_o.cjs +1 -0
- package/dist/{useHistory-D7detcsc.cjs → useHistory-CJSGam5n.cjs} +1 -1
- package/dist/{useHistory-DtcY_Wkt.js → useHistory-DeIqqw-P.js} +1 -1
- package/dist/{useLoadMore-CYYoAHua.js → useLoadMore-2OmOqicJ.js} +1 -1
- package/dist/{useLoadMore-QOHOP_fr.cjs → useLoadMore-CBshMpps.cjs} +1 -1
- package/package.json +1 -1
- package/dist/useActions-Drtoxcu4.cjs +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
type RangeProps = [number | undefined, number | undefined];
|
|
1
2
|
/**
|
|
2
3
|
* A hook that returns range information and functions to update the range.
|
|
3
4
|
*
|
|
4
5
|
* @param id - The identifier for the specific range facet.
|
|
5
|
-
* @returns An object containing range information and functions to update the range.
|
|
6
|
+
* @returns An object containing range information, active state, and functions to update the range.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* General usage with `useRange`:
|
|
@@ -11,12 +12,19 @@
|
|
|
11
12
|
* import { useState } from "react";
|
|
12
13
|
*
|
|
13
14
|
* const Component = ({ facetId }) => {
|
|
14
|
-
* const { min, max, range, updateRange } = useRange(facetId);
|
|
15
|
+
* const { min, max, range, active, toggleActive, updateRange } = useRange(facetId);
|
|
15
16
|
*
|
|
16
17
|
* return (
|
|
17
18
|
* <div>
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* <button onClick={() => toggleActive()}>
|
|
20
|
+
* {active ? "Hide" : "Show"} Range Filter
|
|
21
|
+
* </button>
|
|
22
|
+
* {active && (
|
|
23
|
+
* <div>
|
|
24
|
+
* Current Range: {range[0]} to {range[1]}
|
|
25
|
+
* <button onClick={() => updateRange([min, max])}>Reset Range</button>
|
|
26
|
+
* </div>
|
|
27
|
+
* )}
|
|
20
28
|
* </div>
|
|
21
29
|
* );
|
|
22
30
|
* };
|
|
@@ -30,5 +38,10 @@ export declare function useRange(id: string): {
|
|
|
30
38
|
/** Range value */
|
|
31
39
|
range: number[];
|
|
32
40
|
/** Update range function */
|
|
33
|
-
updateRange: ([from, to]:
|
|
41
|
+
updateRange: ([from, to]: RangeProps) => void;
|
|
42
|
+
/** Is the range filter active */
|
|
43
|
+
active: boolean;
|
|
44
|
+
/** Toggle active state function */
|
|
45
|
+
toggleActive: () => void;
|
|
34
46
|
};
|
|
47
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-CjNvOYZz.cjs"),T=require("../../CategoryPageProvider-2ZmajAxh.cjs"),h=require("../../useActions-CY9uts_o.cjs"),I=require("../../SerpPageProvider-Dn6PSZoF.cjs"),d=require("../../jsxRuntime.module-B3sGoTIU.cjs"),g=require("../../ErrorBoundary-CKn3Ecpu.cjs"),b=require("../../disableNativeAutocomplete-DI6zaZII.cjs"),P=require("../../unique-BXXNictB.cjs"),C=require("preact"),N=require("../../logger-Boh_C6Bz.cjs"),p=require("../../search-RNs4Cunh.cjs");function O(e){let n;return t=>{n&&clearTimeout(n),n=setTimeout(t,e)}}function q(e){return Array.from(document.querySelectorAll(e))}function R(e){const n=[];let t=e.parentNode;for(;t&&t!==document&&t instanceof Element;)n.push(t),t=t.parentNode;return n}function E([e,n],t){const o=r=>{const s=r.target;s instanceof HTMLElement&&e&&s!==e&&s!==n&&!R(s).includes(e)&&t()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function A(e,n){e.tabIndex=0,e.addEventListener("blur",n)}function S(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function H({selector:e,timeout:n=500}){return new Promise(t=>{const o=q(e);if(o.length>0)return t(o);const r=new MutationObserver(()=>{const i=q(e);i.length>0&&(r.disconnect(),clearTimeout(s),t(i))}),s=setTimeout(()=>{r.disconnect(),N.logger.warn(`Timed out (${n}) while waiting for element ${e}`),t([])},n);r.observe(document.body,{childList:!0,subtree:!0})})}function x(e,n,t){n.style.display="none";const o=(()=>{if(e.parentElement&&e.parentElement.classList.contains("nosto-autocomplete-wrapper"))return e.parentElement;const a=document.createElement("div");return a.className="nosto-autocomplete-wrapper",e.parentNode?.insertBefore(a,e.nextSibling),a.appendChild(e),a})(),r=S(t),s=r&&document.querySelector(r.selector);if(s){const a=document.createElement("form");a.className="nosto-dropdown-form",a.appendChild(n),r.position==="first"?s.prepend(a):s.appendChild(a)}else o.appendChild(n);const i={index:-1,onChangeListeners:[]},c=(a,u)=>{const f=a.length;f===0&&(u=-1),i.index=u>=0?u%f:f-1,i.onChangeListeners.forEach(D=>D())},l=()=>{i.index=-1,i.onChangeListeners.forEach(a=>a())},m=()=>i.index;return{element:n,hide:()=>{n.style.display="none",l()},show:()=>{n.style.display="inherit"},isOpen:()=>n.style.display!=="none",goDown:()=>{const a=Array.from(n.getElementsByClassName("ns-autocomplete-element")),u=m();c(a,u+1)},goUp:()=>{const a=Array.from(n.getElementsByClassName("ns-autocomplete-element")),u=m();c(a,u-1)},highlight:c,highlightedIndex:m,submitHighlightedItem:a=>{Array.from(n.querySelectorAll(".ns-autocomplete-element"))[a]?.click()},onHighlightChange:a=>{i.onChangeListeners.push(a)}}}function $(e,n){const t=document.createElement("div");return t.className="nosto-autocomplete-dropdown",{...x(e,t,n),element:t}}const y="nosto:search-js:history";function v(e,n,t){const o=document.createElement("div");return o.className="nosto-autocomplete-history",{...x(e,o,n),element:o,add:s=>{const c=(p.getLocalStorageItem(y)??[]).filter(l=>l!==s).slice(t?-t:0);c.push(s),p.setLocalStorageItem(y,c)},get:()=>(p.getLocalStorageItem(y)??[]).reverse().filter(i=>!!i)}}async function F(e,{config:n,dropdown:t,history:o,renderHistory:r,store:s}){const{historyEnabled:i,minQueryLength:c}=n;if(e.length<c&&i&&r&&!o.isOpen()){o.show();return}if(e.length<c)return;t.hide();const l=s.getState()?.query?.query;l&&l!==e&&await h.newSearch({config:n,store:s},{query:e}),t.show()}async function k(e,n){const{config:t,renderHistory:o,history:r}=n,{historyEnabled:s,minQueryLength:i}=t;if(!o||e.length>=i||!s||r.isOpen())return;const c=j(n);r.onHighlightChange(()=>{c(o,r.element)}),r.show();const l=P.measure("renderHistory");c(o,r.element),l()}async function Q(e,{config:n,dropdown:t,history:o,store:r,debouncer:s}){const{minQueryLength:i,historyEnabled:c}=n;if(e.length<i&&!c){t.hide(),o.hide();return}if(e.length<i&&c){t.hide(),o.show();return}o.hide(),s(async()=>{h.newSearch({config:n,store:r},{query:e}),t.show()})}function M(e,n,t){const{config:o,debouncer:r}=t;if(r(()=>{}),e.length>=o.minQueryLength)return L(n,t.dropdown,t.history);if(o.historyEnabled)return L(n,t.history,t.dropdown)}function L(e,n,t){if(!n.isOpen()&&e==="ArrowDown"){n.show(),t.hide();return}if(e==="Escape"&&n.hide(),!!n.isOpen()){if(e==="ArrowDown")n.goDown();else if(e==="ArrowUp")n.goUp();else if(e==="Enter"){const o=n.highlightedIndex();return o>=0&&n.submitHighlightedItem(o),n.hide(),o>=0}}}function U(e,{config:n,dropdown:t,history:o,onNavigateToSearch:r,store:s}){t.hide(),o.hide(),!(e.length<n.minQueryLength)&&(o.add(e),s.updateState({historyItems:o.get()}),r?.({query:e}))}async function K(e,n){const{inputCssSelector:t,timeout:o}=e,r=S(t).selector,s=await H({selector:r,timeout:o});if(s.length===0)throw new Error(`No elements found for selector: ${r}`);s.forEach(i=>{_(i,e,n)})}async function _(e,n,t){const{config:o,dropdownCssSelector:r}=n,s=$(e,r),i=v(e,r,o.historySize),c={...n,input:e,dropdown:s,history:i,store:t,debouncer:O(o.debounceDelay)};G(c),e.setAttribute("data-nosto-element","search-input"),t.updateState({historyItems:i.get()}),b.disableNativeAutocomplete(e),t.onInit(()=>{z(c)}),b.bindInput(e,{onInput:l=>Q(l,c),onFocus:l=>k(l,c),onClick:l=>F(l,c),onSubmit:l=>U(l,c),onKeyDown:(l,m)=>M(l,m,c)}),A(i.element,i.hide),A(s.element,s.hide),E([i.element,e],i.hide),E([s.element,e],s.hide)}function z(e){const{dropdown:n,renderAutocomplete:t}=e;if(!t)return;const o=j(e);n.onHighlightChange(()=>{o(t,n.element)});const r=P.measure("renderAutocomplete");o(t,n.element),r()}async function G(e){const{input:n,renderSpeechToText:t,config:o,store:r}=e;if(!t)return;const s="ns-autocomplete-voice-position";if(!!n.parentElement?.querySelector(`.${s}`))return;const c=document.createElement("div");c.className=s,n.insertAdjacentElement("afterend",c);const l=await t();C.render(d.u(g.ErrorBoundary,{children:d.u(w.AutocompletePageProvider,{config:o,store:r,children:l})}),c)}function j(e){const{config:n,store:t}=e;return(o,r)=>C.render(d.u(g.ErrorBoundary,{children:d.u(w.AutocompletePageProvider,{config:n,store:t,children:o()})}),r)}async function B({cssSelector:e,timeout:n,renderComponent:t}){const o=S(e).selector,r=await H({selector:o,timeout:n??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&N.logger.warn(`Multiple (${r.length}) elements found for selector: ${o}`),C.render(t(),r[0])}async function J(e,n){const{render:t}=e,o=await t();B({...e,renderComponent:()=>d.u(g.ErrorBoundary,{children:d.u(T.CategoryPageProvider,{store:n,config:e.config,children:o})})})}async function V(e,n){const{render:t}=e,o=await t();B({...e,renderComponent:()=>d.u(g.ErrorBoundary,{children:d.u(I.SearchPageProvider,{store:n,config:e.config,children:o})})})}async function W({autocomplete:e,category:n,serp:t}){const o={};if(e){const r=h.createStore({query:e.query});await K({...e,config:w.makeAutocompleteConfig(e.config)},r),o.autocomplete={store:r}}if(n){const r=h.createStore({query:n.query});await J({...n,config:T.makeCategoryConfig(n.config)},r),o.category={store:r}}if(t){const r=h.createStore({query:t.query});await V({...t,config:I.makeSerpConfig(t.config)},r),o.serp={store:r}}return o}exports.init=W;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as L, m as j } from "../../AutocompletePageProvider-
|
|
2
|
-
import { C as O, m as R } from "../../CategoryPageProvider-
|
|
3
|
-
import { n as T, c as p } from "../../useActions-
|
|
4
|
-
import { S as $, m as F } from "../../SerpPageProvider-
|
|
1
|
+
import { A as L, m as j } from "../../AutocompletePageProvider-DMtA79nZ.js";
|
|
2
|
+
import { C as O, m as R } from "../../CategoryPageProvider-DU3DjmnJ.js";
|
|
3
|
+
import { n as T, c as p } from "../../useActions-CSNwQtT1.js";
|
|
4
|
+
import { S as $, m as F } from "../../SerpPageProvider-DshgTNpM.js";
|
|
5
5
|
import { u as d } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
6
6
|
import { E as h } from "../../ErrorBoundary-DTRm_60r.js";
|
|
7
7
|
import { d as k, b as B } from "../../disableNativeAutocomplete-Bkta_WR2.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../useActions-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../useActions-CY9uts_o.cjs"),r=require("../../InfiniteScrollWithObserver-LxLj-_bT.cjs"),t=require("../../useLoadMore-CBshMpps.cjs");exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;exports.getNextPageQuery=t.getNextPageQuery;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as t, u as a } from "../../useActions-
|
|
2
|
-
import { I as s, i } from "../../InfiniteScrollWithObserver-
|
|
3
|
-
import { g as p } from "../../useLoadMore-
|
|
1
|
+
import { n as t, u as a } from "../../useActions-CSNwQtT1.js";
|
|
2
|
+
import { I as s, i } from "../../InfiniteScrollWithObserver-B0iiezKy.js";
|
|
3
|
+
import { g as p } from "../../useLoadMore-2OmOqicJ.js";
|
|
4
4
|
export {
|
|
5
5
|
s as InfiniteScrollWithObserver,
|
|
6
6
|
p as getNextPageQuery,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../jsxRuntime.module-B3sGoTIU.cjs"),l=require("../../index.es-Dp6Iaxz3.cjs"),u=require("../../BaseElement-CIHACCWd.cjs"),S=require("../../useActions-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../jsxRuntime.module-B3sGoTIU.cjs"),l=require("../../index.es-Dp6Iaxz3.cjs"),u=require("../../BaseElement-CIHACCWd.cjs"),S=require("../../useActions-CY9uts_o.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-Dn6PSZoF.cjs"),P="nosto:search-js:scrollPos";function m(){window.sessionStorage.setItem(P,window.scrollY.toString())}function p({children:s,hit:e,componentProps:t,as:n}){const{pageType:o}=S.useConfig(),r=o==="autocomplete"?void 0:o==="search"?"serp":o,c=d.useCallback(()=>{e&&r&&l.s(i=>i.recordSearchClick(r,e)),m()},[e,r]);return a.u(u.BaseElement,{as:n,onClick:c,componentProps:t,children:s})}exports.SearchPageProvider=g.SearchPageProvider;exports.SerpElement=p;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { u as i } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
2
|
import { s as l } from "../../index.es-XNBESE3P.js";
|
|
3
3
|
import { B as m } from "../../BaseElement-DD_4UwDm.js";
|
|
4
|
-
import { b as p } from "../../useActions-
|
|
4
|
+
import { b as p } from "../../useActions-CSNwQtT1.js";
|
|
5
5
|
import { useCallback as f } from "preact/hooks";
|
|
6
|
-
import { S as h } from "../../SerpPageProvider-
|
|
6
|
+
import { S as h } from "../../SerpPageProvider-DshgTNpM.js";
|
|
7
7
|
const S = "nosto:search-js:scrollPos";
|
|
8
8
|
function g() {
|
|
9
9
|
window.sessionStorage.setItem(S, window.scrollY.toString());
|
|
@@ -30,45 +30,45 @@ function X() {
|
|
|
30
30
|
}
|
|
31
31
|
function Q(e, r = {}) {
|
|
32
32
|
const t = /* @__PURE__ */ new Map();
|
|
33
|
-
let
|
|
34
|
-
const
|
|
35
|
-
function c(
|
|
36
|
-
|
|
37
|
-
for (const
|
|
38
|
-
|
|
33
|
+
let a = w(e, r ?? {});
|
|
34
|
+
const s = w(e, r);
|
|
35
|
+
function c(u) {
|
|
36
|
+
a = u(a);
|
|
37
|
+
for (const l of t.values())
|
|
38
|
+
l(a);
|
|
39
39
|
}
|
|
40
|
-
function n(
|
|
41
|
-
c((
|
|
40
|
+
function n(u) {
|
|
41
|
+
c((l) => ({ ...l, ...u }));
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
return
|
|
43
|
+
function i() {
|
|
44
|
+
return a;
|
|
45
45
|
}
|
|
46
46
|
function o() {
|
|
47
|
-
return structuredClone(
|
|
47
|
+
return structuredClone(s);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
let C;
|
|
51
|
-
t.set(
|
|
52
|
-
const y =
|
|
53
|
-
b(y, C) || (C = y,
|
|
49
|
+
function g(u, l) {
|
|
50
|
+
let C = u(a);
|
|
51
|
+
t.set(l, (T) => {
|
|
52
|
+
const y = u(T);
|
|
53
|
+
b(y, C) || (C = y, l(y));
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
function P(
|
|
57
|
-
|
|
58
|
-
(
|
|
59
|
-
(
|
|
60
|
-
|
|
56
|
+
function P(u) {
|
|
57
|
+
g(
|
|
58
|
+
(l) => l.initialized,
|
|
59
|
+
(l) => {
|
|
60
|
+
l && u();
|
|
61
61
|
}
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
|
-
function F(
|
|
65
|
-
t.delete(
|
|
64
|
+
function F(u) {
|
|
65
|
+
t.delete(u);
|
|
66
66
|
}
|
|
67
67
|
return {
|
|
68
68
|
updateState: n,
|
|
69
|
-
getState:
|
|
69
|
+
getState: i,
|
|
70
70
|
getInitialState: o,
|
|
71
|
-
onChange:
|
|
71
|
+
onChange: g,
|
|
72
72
|
onInit: P,
|
|
73
73
|
clearOnChange: F
|
|
74
74
|
};
|
|
@@ -157,14 +157,14 @@ const D = [
|
|
|
157
157
|
"tags3"
|
|
158
158
|
], L = ["keyword", "_redirect"];
|
|
159
159
|
async function v(e, r, t) {
|
|
160
|
-
const
|
|
160
|
+
const a = f("newSearch"), s = e.config.pageType, c = s === "search" ? "serp" : s, n = h(e.store.getInitialState().query, r), i = h(e.config.search, t, {
|
|
161
161
|
track: c,
|
|
162
|
-
redirect:
|
|
162
|
+
redirect: s !== "autocomplete",
|
|
163
163
|
isKeyword: !!t?.isKeyword,
|
|
164
164
|
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache,
|
|
165
165
|
useMemoryCache: e.config.pageType === "autocomplete" && e.config.memoryCache
|
|
166
166
|
});
|
|
167
|
-
e.config.onBeforeSearch?.(e,
|
|
167
|
+
e.config.onBeforeSearch?.(e, i), e.store.updateState({
|
|
168
168
|
query: n,
|
|
169
169
|
loading: !0,
|
|
170
170
|
initialized: !0
|
|
@@ -178,44 +178,44 @@ async function v(e, r, t) {
|
|
|
178
178
|
filter: E(e.store.getInitialState().query?.products?.filter, r.products?.filter)
|
|
179
179
|
}
|
|
180
180
|
},
|
|
181
|
-
|
|
181
|
+
s
|
|
182
182
|
);
|
|
183
183
|
try {
|
|
184
|
-
const
|
|
184
|
+
const g = await U(B(e.config.pageType, o), i);
|
|
185
185
|
e.store.updateState({
|
|
186
|
-
response:
|
|
186
|
+
response: g,
|
|
187
187
|
loading: !1
|
|
188
188
|
});
|
|
189
|
-
} catch (
|
|
190
|
-
A.error("Search action failed",
|
|
189
|
+
} catch (g) {
|
|
190
|
+
A.error("Search action failed", g), e.config.onSearchError?.(g, o, i, s);
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
a();
|
|
193
193
|
}
|
|
194
194
|
async function m(e, r, t) {
|
|
195
|
-
const
|
|
196
|
-
await v(e,
|
|
195
|
+
const a = f("updateSearch"), s = h(e.store.getState().query, { products: { from: 0 } }, r);
|
|
196
|
+
await v(e, s, t), a();
|
|
197
197
|
}
|
|
198
198
|
async function O(e, r, t) {
|
|
199
|
-
const
|
|
199
|
+
const a = f("replaceFilter"), s = e.store.getState().query.products?.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
200
200
|
await m(e, {
|
|
201
201
|
products: {
|
|
202
|
-
filter: [...
|
|
202
|
+
filter: [...s?.filter((n) => n.field !== r) ?? [], ...c]
|
|
203
203
|
}
|
|
204
|
-
}),
|
|
204
|
+
}), a();
|
|
205
205
|
}
|
|
206
|
-
async function V(e, r, t,
|
|
207
|
-
const
|
|
206
|
+
async function V(e, r, t, a) {
|
|
207
|
+
const s = f("toggleProductFilter"), c = e.store.getState().query.products?.filter, n = c?.find((o) => o.value instanceof Array && o.field === r), i = n?.value ? {
|
|
208
208
|
...n,
|
|
209
|
-
value: [...n.value.filter((o) => !b(o, t)), ...
|
|
210
|
-
} :
|
|
209
|
+
value: [...n.value.filter((o) => !b(o, t)), ...a ? [t] : []]
|
|
210
|
+
} : a ? {
|
|
211
211
|
field: r,
|
|
212
212
|
value: [t]
|
|
213
213
|
} : void 0;
|
|
214
214
|
await m(e, {
|
|
215
215
|
products: {
|
|
216
|
-
filter: [...c?.filter((o) => o !== n) ?? [], ...
|
|
216
|
+
filter: [...c?.filter((o) => o !== n) ?? [], ...i?.value?.length ? [i] : []]
|
|
217
217
|
}
|
|
218
|
-
}),
|
|
218
|
+
}), s();
|
|
219
219
|
}
|
|
220
220
|
function Y() {
|
|
221
221
|
const e = p(), r = k(N), t = I(
|
|
@@ -224,22 +224,22 @@ function Y() {
|
|
|
224
224
|
store: r
|
|
225
225
|
}),
|
|
226
226
|
[e, r]
|
|
227
|
-
),
|
|
228
|
-
(
|
|
227
|
+
), a = d(
|
|
228
|
+
(i, o) => v(t, i, o),
|
|
229
229
|
[t]
|
|
230
|
-
),
|
|
231
|
-
(
|
|
230
|
+
), s = d(
|
|
231
|
+
(i, o) => m(t, i, o),
|
|
232
232
|
[t]
|
|
233
233
|
), c = d(
|
|
234
|
-
(
|
|
234
|
+
(i, o, g) => V(t, i, o, g),
|
|
235
235
|
[t]
|
|
236
236
|
), n = d(
|
|
237
|
-
(
|
|
237
|
+
(i, o) => O(t, i, o),
|
|
238
238
|
[t]
|
|
239
239
|
);
|
|
240
240
|
return {
|
|
241
|
-
newSearch:
|
|
242
|
-
updateSearch:
|
|
241
|
+
newSearch: a,
|
|
242
|
+
updateSearch: s,
|
|
243
243
|
toggleProductFilter: c,
|
|
244
244
|
replaceFilter: n
|
|
245
245
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const w=require("preact"),f=require("preact/hooks"),u=require("./unique-BXXNictB.cjs"),C=require("./logger-Boh_C6Bz.cjs"),E=require("./search-RNs4Cunh.cjs"),k=w.createContext(null);function p(){const e=f.useContext(k);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e}function A(){const e=p();if(e.pageType!=="search")throw new Error("useSerpConfig must be used within a NostoSearchPageProvider");return e}function I(){const e=p();if(e.pageType!=="category")throw new Error("useCategoryConfig must be used within a NostoCategoryPageProvider");return e}function U(){const e=p();if(e.pageType!=="autocomplete")throw new Error("useAutocompleteConfig must be used within a NostoAutocompletePageProvider");return e}function b(e,r={}){const t=new Map;let n=u.deepMergePlain(e,r??{});const a=u.deepMergePlain(e,r);function c(l){n=l(n);for(const g of t.values())g(n)}function s(l){c(g=>({...g,...l}))}function i(){return n}function o(){return structuredClone(a)}function d(l,g){let m=l(n);t.set(g,M=>{const y=l(M);C.isEqual(y,m)||(m=y,g(y))})}function T(l){d(g=>g.initialized,g=>{g&&l()})}function q(l){t.delete(l)}return{updateState:s,getState:i,getInitialState:o,onChange:d,onInit:T,clearOnChange:q}}const v={loading:!0,query:{},response:{},initialized:!1};function P(e={}){return b(v,e)}const F=w.createContext(P());function Q(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:z,...r.products},...r.keywords?{keywords:{...r.keywords,fields:u.unique([...K,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const z=["productId","url","name","imageUrl","imageHash","thumbUrl","description","brand","variantId","availability","price","priceText","categoryIds","categories","customFields.key","customFields.value","priceCurrencyCode","datePublished","listPrice","unitPricingBaseMeasure","unitPricingUnit","unitPricingMeasure","googleCategory","gtin","ageGroup","gender","condition","alternateImageUrls","ratingValue","reviewCount","inventoryLevel","skus.id","skus.name","skus.price","skus.listPrice","skus.priceText","skus.url","skus.imageUrl","skus.inventoryLevel","skus.customFields.key","skus.customFields.value","skus.availability","pid","onDiscount","extra.key","extra.value","saleable","available","tags1","tags2","tags3"],K=["keyword","_redirect"];async function S(e,r,t){const n=u.measure("newSearch"),a=e.config.pageType,c=a==="search"?"serp":a,s=u.deepMerge(e.store.getInitialState().query,r),i=u.deepMerge(e.config.search,t,{track:c,redirect:a!=="autocomplete",isKeyword:!!t?.isKeyword,usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache,useMemoryCache:e.config.pageType==="autocomplete"&&e.config.memoryCache});e.config.onBeforeSearch?.(e,i),e.store.updateState({query:s,loading:!0,initialized:!0});const o=e.config.queryModifications({...s,products:{...s.products,filter:u.mergeArrays(e.store.getInitialState().query?.products?.filter,r.products?.filter)}},a);try{const d=await E.search(Q(e.config.pageType,o),i);e.store.updateState({response:d,loading:!1})}catch(d){C.logger.error("Search action failed",d),e.config.onSearchError?.(d,o,i,a)}n()}async function h(e,r,t){const n=u.measure("updateSearch"),a=u.deepMerge(e.store.getState().query,{products:{from:0}},r);await S(e,a,t),n()}async function N(e,r,t){const n=u.measure("replaceFilter"),a=e.store.getState().query.products?.filter,c=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...a?.filter(s=>s.field!==r)??[],...c]}}),n()}async function x(e,r,t,n){const a=u.measure("toggleProductFilter"),c=e.store.getState().query.products?.filter,s=c?.find(o=>o.value instanceof Array&&o.field===r),i=s?.value?{...s,value:[...s.value.filter(o=>!C.isEqual(o,t)),...n?[t]:[]]}:n?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...c?.filter(o=>o!==s)??[],...i?.value?.length?[i]:[]]}}),a()}function B(){const e=p(),r=f.useContext(F),t=f.useMemo(()=>({config:e,store:r}),[e,r]),n=f.useCallback((i,o)=>S(t,i,o),[t]),a=f.useCallback((i,o)=>h(t,i,o),[t]),c=f.useCallback((i,o,d)=>x(t,i,o,d),[t]),s=f.useCallback((i,o)=>N(t,i,o),[t]);return{newSearch:n,updateSearch:a,toggleProductFilter:c,replaceFilter:s}}exports.ConfigContext=k;exports.StoreContext=F;exports.createExtendableStore=b;exports.createStore=P;exports.defaultState=v;exports.newSearch=S;exports.updateSearch=h;exports.useActions=B;exports.useAutocompleteConfig=U;exports.useCategoryConfig=I;exports.useConfig=p;exports.useSerpConfig=A;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("./useActions-
|
|
1
|
+
"use strict";const n=require("./useActions-CY9uts_o.cjs"),o=require("./search-RNs4Cunh.cjs"),a=require("preact/hooks"),s="nosto:search-js:history";function l(){return(o.getLocalStorageItem(s)??[]).slice().reverse().filter(e=>!!e)}function y(){const{updateState:t}=a.useContext(n.StoreContext),{historySize:e}=n.useAutocompleteConfig();return{addQuery:a.useCallback(r=>{const i=(o.getLocalStorageItem(s)??[]).filter(u=>u!==r).concat(r),c=e?i.slice(-e):[];o.setLocalStorageItem(s,c),t({historyItems:c.reverse()})},[e,t])}}exports.getSaved=l;exports.useHistory=y;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as i, a as l } from "./useActions-
|
|
1
|
+
import { S as i, a as l } from "./useActions-CSNwQtT1.js";
|
|
2
2
|
import { g as a, a as m } from "./search-mArZ2PXy.js";
|
|
3
3
|
import { useContext as u, useCallback as y } from "preact/hooks";
|
|
4
4
|
const o = "nosto:search-js:history";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as n, h as u } from "./useActions-
|
|
1
|
+
import { S as n, h as u } from "./useActions-CSNwQtT1.js";
|
|
2
2
|
import { useContext as a, useState as c, useEffect as i, useCallback as f } from "preact/hooks";
|
|
3
3
|
import { i as m } from "./isBot-Dt3hQTa6.js";
|
|
4
4
|
function l(t = p) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("./useActions-
|
|
1
|
+
"use strict";const n=require("./useActions-CY9uts_o.cjs"),r=require("preact/hooks"),i=require("./isBot-Bs99-Wlv.cjs");function c(e=f){const t=r.useContext(n.StoreContext),[o,s]=r.useState(e(t.getState()));return t.onChange(e,s),r.useEffect(()=>()=>t.clearOnChange(s),[t]),o}const f=e=>e;function a({from:e,size:t,pageSize:o}){return i.isBot()?{products:{from:e+o}}:{products:{size:t+o}}}function d(e=24){const{from:t,size:o}=c(u=>({from:u.query.products?.from??0,size:u.query.products?.size??0})),{updateSearch:s}=n.useActions();return{loadMore:r.useCallback(async()=>{await s(a({from:t,size:o,pageSize:e}))},[t,o,e,s])}}exports.getNextPageQuery=a;exports.useLoadMore=d;exports.useNostoAppState=c;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const w=require("preact"),f=require("preact/hooks"),c=require("./unique-BXXNictB.cjs"),C=require("./logger-Boh_C6Bz.cjs"),E=require("./search-RNs4Cunh.cjs"),k=w.createContext(null);function p(){const e=f.useContext(k);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e}function A(){const e=p();if(e.pageType!=="search")throw new Error("useSerpConfig must be used within a NostoSearchPageProvider");return e}function I(){const e=p();if(e.pageType!=="category")throw new Error("useCategoryConfig must be used within a NostoCategoryPageProvider");return e}function U(){const e=p();if(e.pageType!=="autocomplete")throw new Error("useAutocompleteConfig must be used within a NostoAutocompletePageProvider");return e}function b(e,r={}){const t=new Map;let i=c.deepMergePlain(e,r??{});const a=c.deepMergePlain(e,r);function u(d){i=d(i);for(const l of t.values())l(i)}function s(d){u(l=>({...l,...d}))}function n(){return i}function o(){return structuredClone(a)}function g(d,l){let m;t.set(l,M=>{const y=d(M);C.isEqual(y,m)||(m=y,l(y))})}function T(d){g(l=>l.initialized,l=>{l&&d()})}function q(d){t.delete(d)}return{updateState:s,getState:n,getInitialState:o,onChange:g,onInit:T,clearOnChange:q}}const v={loading:!0,query:{},response:{},initialized:!1};function P(e={}){return b(v,e)}const F=w.createContext(P());function Q(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:z,...r.products},...r.keywords?{keywords:{...r.keywords,fields:c.unique([...K,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const z=["productId","url","name","imageUrl","imageHash","thumbUrl","description","brand","variantId","availability","price","priceText","categoryIds","categories","customFields.key","customFields.value","priceCurrencyCode","datePublished","listPrice","unitPricingBaseMeasure","unitPricingUnit","unitPricingMeasure","googleCategory","gtin","ageGroup","gender","condition","alternateImageUrls","ratingValue","reviewCount","inventoryLevel","skus.id","skus.name","skus.price","skus.listPrice","skus.priceText","skus.url","skus.imageUrl","skus.inventoryLevel","skus.customFields.key","skus.customFields.value","skus.availability","pid","onDiscount","extra.key","extra.value","saleable","available","tags1","tags2","tags3"],K=["keyword","_redirect"];async function S(e,r,t){const i=c.measure("newSearch"),a=e.config.pageType,u=a==="search"?"serp":a,s=c.deepMerge(e.store.getInitialState().query,r),n=c.deepMerge(e.config.search,t,{track:u,redirect:a!=="autocomplete",isKeyword:!!t?.isKeyword,usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache,useMemoryCache:e.config.pageType==="autocomplete"&&e.config.memoryCache});e.config.onBeforeSearch?.(e,n),e.store.updateState({query:s,loading:!0,initialized:!0});const o=e.config.queryModifications({...s,products:{...s.products,filter:c.mergeArrays(e.store.getInitialState().query?.products?.filter,r.products?.filter)}},a);try{const g=await E.search(Q(e.config.pageType,o),n);e.store.updateState({response:g,loading:!1})}catch(g){C.logger.error("Search action failed",g),e.config.onSearchError?.(g,o,n,a)}i()}async function h(e,r,t){const i=c.measure("updateSearch"),a=c.deepMerge(e.store.getState().query,{products:{from:0}},r);await S(e,a,t),i()}async function N(e,r,t){const i=c.measure("replaceFilter"),a=e.store.getState().query.products?.filter,u=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...a?.filter(s=>s.field!==r)??[],...u]}}),i()}async function x(e,r,t,i){const a=c.measure("toggleProductFilter"),u=e.store.getState().query.products?.filter,s=u?.find(o=>o.value instanceof Array&&o.field===r),n=s?.value?{...s,value:[...s.value.filter(o=>!C.isEqual(o,t)),...i?[t]:[]]}:i?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...u?.filter(o=>o!==s)??[],...n?.value?.length?[n]:[]]}}),a()}function B(){const e=p(),r=f.useContext(F),t=f.useMemo(()=>({config:e,store:r}),[e,r]),i=f.useCallback((n,o)=>S(t,n,o),[t]),a=f.useCallback((n,o)=>h(t,n,o),[t]),u=f.useCallback((n,o,g)=>x(t,n,o,g),[t]),s=f.useCallback((n,o)=>N(t,n,o),[t]);return{newSearch:i,updateSearch:a,toggleProductFilter:u,replaceFilter:s}}exports.ConfigContext=k;exports.StoreContext=F;exports.createExtendableStore=b;exports.createStore=P;exports.defaultState=v;exports.newSearch=S;exports.updateSearch=h;exports.useActions=B;exports.useAutocompleteConfig=U;exports.useCategoryConfig=I;exports.useConfig=p;exports.useSerpConfig=A;
|