@nosto/search-js 3.16.0 → 3.17.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-DtgDwaV9.cjs +1 -0
- package/dist/AutocompletePageProvider-FCFyqG35.js +35 -0
- package/dist/{CategoryPageProvider-CYRnaUx1.cjs → CategoryPageProvider-CJL0GSV1.cjs} +1 -1
- package/dist/{CategoryPageProvider-DcQlylFg.js → CategoryPageProvider-OYvvNZSr.js} +1 -1
- package/dist/{SerpPageProvider-s4dO49Fx.cjs → SerpPageProvider-CsLAvEUE.cjs} +1 -1
- package/dist/{SerpPageProvider-CsrFA6mA.js → SerpPageProvider-d781RZHT.js} +1 -1
- package/dist/baseConfig-Bm8iHF7S.cjs +1 -0
- package/dist/{baseConfig-BMc1698x.js → baseConfig-CFx9WXL8.js} +17 -8
- package/dist/eventBusDispatch-BKQcSHAB.cjs +1 -0
- package/dist/eventBusDispatch-DPR2Vwd4.js +20 -0
- 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/events/events.cjs.js +1 -1
- package/dist/preact/events/events.es.js +5 -20
- package/dist/preact/events/src/types.d.ts +1 -0
- package/dist/preact/hooks/hooks.cjs.js +1 -1
- package/dist/preact/hooks/hooks.es.js +119 -113
- package/dist/preact/hooks/src/useHistory.d.ts +1 -1
- package/dist/preact/inject/inject.cjs.js +1 -1
- package/dist/preact/inject/inject.es.js +3 -3
- package/dist/preact/serp/serp.cjs.js +1 -1
- package/dist/preact/serp/serp.es.js +1 -1
- package/dist/useHistory-D7detcsc.cjs +1 -0
- package/dist/useHistory-DtcY_Wkt.js +23 -0
- package/package.json +1 -1
- package/dist/AutocompletePageProvider-BJxsORbo.cjs +0 -1
- package/dist/AutocompletePageProvider-DI2PONk8.js +0 -37
- package/dist/baseConfig-gkfFlBOL.cjs +0 -1
- package/dist/useHistory-2uGnArVO.cjs +0 -1
- package/dist/useHistory-W6FQSk99.js +0 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-Drtoxcu4.cjs"),u=require("./baseConfig-Bm8iHF7S.cjs"),s=require("./useHistory-D7detcsc.cjs"),a=require("preact/hooks"),l={...u.defaultBaseConfig,memoryCache:!1,historyEnabled:!0,historySize:5,debounceDelay:500,minQueryLength:2};function n(e={}){return{pageType:"autocomplete",...l,...e}}function m({config:e,store:i,children:c}){const t=i??r.createStore();return u.useCheckClientScript(),a.useEffect(()=>{t.updateState({historyItems:s.getSaved()})},[t]),o.u(r.ConfigContext,{value:n(e),children:o.u(r.StoreContext,{value:t,children:[o.u(u.StoreActionsListener,{}),c]})})}exports.AutocompletePageProvider=m;exports.makeAutocompleteConfig=n;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { u as o } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
+
import { c as i, S as n, C as s } from "./useActions-MsVW37eV.js";
|
|
3
|
+
import { d as u, u as m, S as c } from "./baseConfig-CFx9WXL8.js";
|
|
4
|
+
import { g as f } from "./useHistory-DtcY_Wkt.js";
|
|
5
|
+
import { useEffect as l } from "preact/hooks";
|
|
6
|
+
const p = {
|
|
7
|
+
...u,
|
|
8
|
+
memoryCache: !1,
|
|
9
|
+
historyEnabled: !0,
|
|
10
|
+
historySize: 5,
|
|
11
|
+
debounceDelay: 500,
|
|
12
|
+
minQueryLength: 2
|
|
13
|
+
};
|
|
14
|
+
function d(e = {}) {
|
|
15
|
+
return {
|
|
16
|
+
pageType: "autocomplete",
|
|
17
|
+
...p,
|
|
18
|
+
...e
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function A({ config: e, store: r, children: a }) {
|
|
22
|
+
const t = r ?? i();
|
|
23
|
+
return m(), l(() => {
|
|
24
|
+
t.updateState({
|
|
25
|
+
historyItems: f()
|
|
26
|
+
});
|
|
27
|
+
}, [t]), /* @__PURE__ */ o(s, { value: d(e), children: /* @__PURE__ */ o(n, { value: t, children: [
|
|
28
|
+
/* @__PURE__ */ o(c, {}),
|
|
29
|
+
a
|
|
30
|
+
] }) });
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
A,
|
|
34
|
+
d as m
|
|
35
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-Drtoxcu4.cjs"),o=require("./baseConfig-
|
|
1
|
+
"use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-Drtoxcu4.cjs"),o=require("./baseConfig-Bm8iHF7S.cjs"),s={...o.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function n(e){return{pageType:"category",...s,...e}}function u({config:e,store:a,children:i}){const c=a??r.createStore();return o.useCheckClientScript(),t.u(r.ConfigContext,{value:n(e),children:t.u(r.StoreContext,{value:c,children:[t.u(o.StoreActionsListener,{}),i]})})}exports.CategoryPageProvider=u;exports.makeCategoryConfig=n;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
2
|
import { c as n, S as s, C as i } from "./useActions-MsVW37eV.js";
|
|
3
|
-
import { d as c, u as C, S as f } from "./baseConfig-
|
|
3
|
+
import { d as c, u as C, S as f } from "./baseConfig-CFx9WXL8.js";
|
|
4
4
|
const l = {
|
|
5
5
|
...c,
|
|
6
6
|
persistentSearchCache: !1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=require("./jsxRuntime.module-B3sGoTIU.cjs"),t=require("./useActions-Drtoxcu4.cjs"),n=require("./baseConfig-
|
|
1
|
+
"use strict";const r=require("./jsxRuntime.module-B3sGoTIU.cjs"),t=require("./useActions-Drtoxcu4.cjs"),n=require("./baseConfig-Bm8iHF7S.cjs"),s={...n.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function o(e={}){return{pageType:"search",...s,...e}}function u({config:e,store:i,children:a}){const c=i??t.createStore();return n.useCheckClientScript(),r.u(t.ConfigContext,{value:o(e),children:r.u(t.StoreContext,{value:c,children:[r.u(n.StoreActionsListener,{}),a]})})}exports.SearchPageProvider=u;exports.makeSerpConfig=o;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as r } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
2
|
import { c as n, S as s, C as c } from "./useActions-MsVW37eV.js";
|
|
3
|
-
import { d as i, u as f, S } from "./baseConfig-
|
|
3
|
+
import { d as i, u as f, S } from "./baseConfig-CFx9WXL8.js";
|
|
4
4
|
const l = {
|
|
5
5
|
...i,
|
|
6
6
|
persistentSearchCache: !1,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("./useActions-Drtoxcu4.cjs"),c=require("./eventBusSubscribe-oONOUGH8.cjs"),b=require("./index.es-Dp6Iaxz3.cjs"),f=require("./logger-Boh_C6Bz.cjs"),d=require("preact/hooks");function S(){const{pageType:e}=i.useConfig(),{newSearch:u,updateSearch:n,replaceFilter:o,toggleProductFilter:l}=i.useActions();return c.useEventBusSubscribe({event:"actions/newSearch",callback:({query:t,options:r,targetStore:s})=>{e===s&&u(t,r)}}),c.useEventBusSubscribe({event:"actions/updateSearch",callback:({query:t,options:r,targetStore:s})=>{e===s&&n(t,r)}}),c.useEventBusSubscribe({event:"actions/replaceFilter",callback:({field:t,value:r,targetStore:s})=>{e===s&&o(t,r)}}),c.useEventBusSubscribe({event:"actions/toggleProductFilter",callback:({field:t,value:r,active:s,targetStore:a})=>{e===a&&l(t,r,s)}}),c.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{n({products:{filter:[]}})}}),null}function v(){d.useEffect(()=>{const e=window.setTimeout(()=>{f.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);b.s(()=>{window.clearTimeout(e)})},[])}const g={defaultCurrency:"EUR",queryModifications:e=>e};exports.StoreActionsListener=S;exports.defaultBaseConfig=g;exports.useCheckClientScript=v;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { b as
|
|
1
|
+
import { b as u, h as f } from "./useActions-MsVW37eV.js";
|
|
2
2
|
import { u as c } from "./eventBusSubscribe-CzlS132j.js";
|
|
3
3
|
import { s as p } from "./index.es-XNBESE3P.js";
|
|
4
4
|
import { l as d } from "./logger-_fg_Za9y.js";
|
|
5
5
|
import { useEffect as m } from "preact/hooks";
|
|
6
6
|
function k() {
|
|
7
|
-
const { pageType: e } =
|
|
7
|
+
const { pageType: e } = u(), { newSearch: i, updateSearch: n, replaceFilter: a, toggleProductFilter: s } = f();
|
|
8
8
|
return c({
|
|
9
9
|
event: "actions/newSearch",
|
|
10
10
|
callback: ({ query: t, options: r, targetStore: o }) => {
|
|
11
|
-
e === o &&
|
|
11
|
+
e === o && i(t, r);
|
|
12
12
|
}
|
|
13
13
|
}), c({
|
|
14
14
|
event: "actions/updateSearch",
|
|
15
15
|
callback: ({ query: t, options: r, targetStore: o }) => {
|
|
16
|
-
e === o &&
|
|
16
|
+
e === o && n(t, r);
|
|
17
17
|
}
|
|
18
18
|
}), c({
|
|
19
19
|
event: "actions/replaceFilter",
|
|
@@ -22,12 +22,21 @@ function k() {
|
|
|
22
22
|
}
|
|
23
23
|
}), c({
|
|
24
24
|
event: "actions/toggleProductFilter",
|
|
25
|
-
callback: ({ field: t, value: r, active: o, targetStore:
|
|
26
|
-
e ===
|
|
25
|
+
callback: ({ field: t, value: r, active: o, targetStore: l }) => {
|
|
26
|
+
e === l && s(t, r, o);
|
|
27
|
+
}
|
|
28
|
+
}), c({
|
|
29
|
+
event: "events/removeAllFilters",
|
|
30
|
+
callback: () => {
|
|
31
|
+
n({
|
|
32
|
+
products: {
|
|
33
|
+
filter: []
|
|
34
|
+
}
|
|
35
|
+
});
|
|
27
36
|
}
|
|
28
37
|
}), null;
|
|
29
38
|
}
|
|
30
|
-
function
|
|
39
|
+
function w() {
|
|
31
40
|
m(() => {
|
|
32
41
|
const e = window.setTimeout(() => {
|
|
33
42
|
d.error("Nosto client script has not loaded after 3 seconds.");
|
|
@@ -44,5 +53,5 @@ const C = {
|
|
|
44
53
|
export {
|
|
45
54
|
k as S,
|
|
46
55
|
C as d,
|
|
47
|
-
|
|
56
|
+
w as u
|
|
48
57
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const n=require("preact/hooks");function e({event:t,params:s}){window.dispatchEvent(new CustomEvent(`@nosto/search-js/${t}`,{detail:s}))}function o({event:t}){return n.useCallback(s=>{e({event:t,params:s})},[t])}exports.dispatchNostoEvent=e;exports.useEventBusDispatch=o;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useCallback as n } from "preact/hooks";
|
|
2
|
+
function o({ event: t, params: s }) {
|
|
3
|
+
window.dispatchEvent(
|
|
4
|
+
new CustomEvent(`@nosto/search-js/${t}`, {
|
|
5
|
+
detail: s
|
|
6
|
+
})
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
function e({ event: t }) {
|
|
10
|
+
return n(
|
|
11
|
+
(s) => {
|
|
12
|
+
o({ event: t, params: s });
|
|
13
|
+
},
|
|
14
|
+
[t]
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
o as d,
|
|
19
|
+
e as u
|
|
20
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../AutocompletePageProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../AutocompletePageProvider-DtgDwaV9.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../../index.es-Dp6Iaxz3.cjs"),a=require("../../BaseElement-CIHACCWd.cjs"),m=require("preact/hooks"),p=require("../../cl-B00bZ7jc.cjs");function d({children:t,hit:e,as:o,componentProps:n}){const r=m.useCallback(()=>{e&&"productId"in e&&i.s(c=>c.recordSearchClick("autocomplete",e))},[e]);return u.u(a.BaseElement,{onClick:r,as:o,componentProps:n,className:"ns-autocomplete-element",children:t})}function P({children:t,class:e,onSubmit:o}){return u.u("div",{className:p.cl("ns-autocomplete-element",e),onClick:o,onKeyDown:n=>{n.key==="Enter"&&o()},children:t})}function f({as:t,componentProps:e,onSearchInput:o,children:n}){const r={...e,onInput:l=>{o(l.target)}},c=t??"input";return t||(r.type="search"),u.u(c,{...r,children:n})}exports.AutocompletePageProvider=s.AutocompletePageProvider;exports.AutocompleteElement=d;exports.HistoryElement=P;exports.SearchInput=f;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as g } from "../../AutocompletePageProvider-
|
|
1
|
+
import { A as g } from "../../AutocompletePageProvider-FCFyqG35.js";
|
|
2
2
|
import { u as m } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
3
|
import { s } from "../../index.es-XNBESE3P.js";
|
|
4
4
|
import { B as a } from "../../BaseElement-DD_4UwDm.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../CategoryPageProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../CategoryPageProvider-CJL0GSV1.cjs");exports.CategoryPageProvider=e.CategoryPageProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../eventBusDispatch-BKQcSHAB.cjs"),s=require("../../eventBusSubscribe-oONOUGH8.cjs");exports.dispatchNostoEvent=e.dispatchNostoEvent;exports.useEventBusDispatch=e.useEventBusDispatch;exports.subscribeToNostoEvent=s.subscribeToNostoEvent;exports.useEventBusSubscribe=s.useEventBusSubscribe;
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as a, u as
|
|
3
|
-
function e({ event: s, params: t }) {
|
|
4
|
-
window.dispatchEvent(
|
|
5
|
-
new CustomEvent(`@nosto/search-js/${s}`, {
|
|
6
|
-
detail: t
|
|
7
|
-
})
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
function u({ event: s }) {
|
|
11
|
-
return o(
|
|
12
|
-
(t) => {
|
|
13
|
-
e({ event: s, params: t });
|
|
14
|
-
},
|
|
15
|
-
[s]
|
|
16
|
-
);
|
|
17
|
-
}
|
|
1
|
+
import { d as t, u as o } from "../../eventBusDispatch-DPR2Vwd4.js";
|
|
2
|
+
import { s as a, u as r } from "../../eventBusSubscribe-CzlS132j.js";
|
|
18
3
|
export {
|
|
19
|
-
|
|
4
|
+
t as dispatchNostoEvent,
|
|
20
5
|
a as subscribeToNostoEvent,
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
o as useEventBusDispatch,
|
|
7
|
+
r as useEventBusSubscribe
|
|
23
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("../../useActions-Drtoxcu4.cjs"),P=require("../../logger-Boh_C6Bz.cjs"),h=require("../../useLoadMore-QOHOP_fr.cjs"),q=require("../../eventBusSubscribe-oONOUGH8.cjs"),l=require("preact/hooks"),L=require("../../useHistory-D7detcsc.cjs"),T=require("../../index.es-Dp6Iaxz3.cjs"),z=require("../../eventBusDispatch-BKQcSHAB.cjs"),A=require("../../parseNumber-FsZ8w61u.cjs");function X(e){const s=h.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&P.isPlainObject(e)?e:s}function O(e,s){const t=e.data?.filter(f=>f.selected).length??0,{active:r}={active:t>0,...s},[n,c]=l.useState(r),{toggleProductFilter:u}=F.useActions(),d=l.useCallback(()=>{c(!n)},[n]);return q.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{c(!1)}}),{active:n,selectedFiltersCount:t,toggleActive:d,toggleProductFilter:u}}function j(){const{loading:e,facets:s}=h.useNostoAppState(t=>({loading:t.loading,facets:t.response?.products?.facets??[]}));return{loading:e,facets:s}}function E(e,s){const t=s-e;return!isNaN(t)&&t>0?new Array(s-e).fill(void 0).map((r,n)=>n+e):[]}function D(e){const{query:s,products:t}=h.useNostoAppState(r=>({query:r.query,products:r.response.products}));return l.useMemo(()=>{if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const r=s.products?.from??0,n=e?.width??1/0,c=Math.max(Math.floor(n-1)/2,1),u=t.size>0?Math.floor(r/t.size)+1:1,d=t.size>0?Math.ceil(t.total/t.size):0,f=y=>y>=u-c&&y<=u+c,o=r+1,i=Math.min(r+t.total,t.total),a={from:r,page:u,current:!0},p=y=>({from:(y-1)*t.size,page:y,current:y===u}),S=u>1?p(u-1):void 0,m=u<d?p(u+1):void 0,g=u-c-1>1?p(1):void 0,v=u+c+1<d?p(d):void 0,b=E(1,d+1).filter(f).map(p);return!g&&b[0]?.page===2&&b.unshift(p(1)),!v&&b[b.length-1]?.page===d-1&&b.push(p(d)),{totalPages:d,resultsFrom:o,resultsTo:i,current:a,prev:S,next:m,first:g,last:v,pages:b}},[s,t,e?.width])}function B(){const[e,s]=l.useState([]),[t,r]=l.useState([]);return l.useEffect(()=>{T.s(async n=>{const{products:c,segments:u}=await n.getSearchSessionParams();s(u??[]),r(c?.personalizationBoost??[])})},[]),{segments:e,boost:t}}function V(){const{facets:e}=h.useNostoAppState(o=>({facets:o.response.products?.facets??[]})),{replaceFilter:s,toggleProductFilter:t}=F.useActions(),r=l.useCallback(o=>{const i=e?.find(a=>a.type==="stats"&&a.field===o);if(i&&"min"in i&&"max"in i)return i},[e]),n=l.useCallback(o=>e?.find(i=>i.field===o)?.name??o,[e]),c=l.useCallback(o=>"field"in o&&(o.value instanceof Array||o.range instanceof Array),[]),u=l.useCallback(o=>({...o,range:o.range?.map(i=>({gt:i.gt?Number(i.gt):i.gt,gte:i.gte?Number(i.gte):i.gte,lt:i.lt?Number(i.lt):i.lt,lte:i.lte?Number(i.lte):i.lte}))}),[]),d=l.useCallback(o=>(o.value??[]).map(a=>({value:a,field:o.field,name:n(o.field),filter:u(o),remove:()=>{t(o.field,a,!1)}})),[u,n,t]),f=l.useCallback(o=>(o.range??[]).map(a=>{const p=a.gte??a.gt??r(o.field)?.min,S=a.lte??a.lt??r(o.field)?.max;if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:o.field,name:n(o.field),filter:u(o),remove:()=>{s(o.field,void 0)}}}).filter(Boolean),[u,r,n,s]);return{selectFilters:c,toValueFilter:d,toRangeFilter:f}}function C(){const{filter:e}=h.useNostoAppState(u=>({filter:u.query.products?.filter??[]})),{selectFilters:s,toValueFilter:t,toRangeFilter:r}=V(),n=l.useMemo(()=>e?e.filter(s).flatMap(u=>"value"in u?t(u):"range"in u?r(u):[]).filter(Boolean):[],[e,s,r,t]),c=l.useCallback(()=>{z.dispatchNostoEvent({event:"events/removeAllFilters",params:null})},[]);return{filters:n,removeAll:c}}function R(e){const{replaceFilter:s}=F.useActions(),{query:t,products:r}=h.useNostoAppState(a=>({query:a.query,products:a.response.products})),n=r?.facets?.find(a=>a.id===e);if(!n)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const c=t.products?.filter?.find(a=>a.field===n.field),u=c?.range?c.range[0]:void 0,d=typeof u=="object"&&("gte"in u||"lte"in u)?[A.parseNumber(u.gte),A.parseNumber(u.lte)]:[void 0,void 0],f="min"in n?Math.floor(n.min):0,o="max"in n?Math.ceil(n.max):0,i=([a,p])=>{const S=a!==void 0?Math.floor(a):void 0,m=p!==void 0?Math.ceil(p):void 0,g=S!==void 0,v=m!==void 0;(f===S||!g)&&(o===m||!v)?s(n.field,void 0):(f===S||!g)&&v?s(n.field,{lte:m.toString()}):(o===m||!v)&&g?s(n.field,{gte:S.toString()}):g&&v&&s(n.field,{gte:S.toString(),lte:m.toString()})};return{min:f,max:o,range:[d[0]??f,d[1]??o],updateRange:i}}function $(e,s){const{min:t,max:r,range:n,updateRange:c}=R(e),{filters:u}=C(),d=l.useMemo(()=>{const a=u.find(g=>g?.filter?.range);let p=null;if(a){const g=a.filter.range?.[0];p=[A.parseNumber(g?.gte),A.parseNumber(g?.lte)]}const S=[];let m=Math.floor(t/s)*s;for(;m<r;){const g=m+s,v=p&&p[0]===m&&p[1]===g;S.push({min:m,max:g,selected:v}),m=g}return S},[u,t,r,s]),f=a=>{c([a,n[1]])},o=a=>{c([n[0],a])},i=t!==n[0]||r!==n[1];return{min:t,max:r,range:n,updateRange:c,ranges:d,handleMinChange:f,handleMaxChange:o,isSelected:i}}function _(){const{products:e,keywords:s}=h.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:s??{hits:[],total:0}}}function H(){const e=h.useNostoAppState(t=>t.query.products?.filter);return l.useMemo(()=>e?e.reduce((t,r)=>t+(Array.isArray(r.value)?r.value.length:1),0):0,[e])}const U=5*60*1e3,w=new Map;function I(e){const[s,t]=l.useState({product:null,loading:!0,error:null});return l.useEffect(()=>{if(!e){t({product:null,loading:!1,error:"Product handle is required"});return}t(n=>({...n,loading:!0,error:null}));const r=G(e);if(r){t({product:r,loading:!1,error:null});return}Z(e).then(n=>{J(e,n),t({product:n,loading:!1,error:null})}).catch(n=>{t({product:null,loading:!1,error:n.message||"Failed to fetch product"})})},[e]),s}async function Z(e){const s=await fetch(`/products/${e}.js`);if(!s.ok)throw new Error(`Failed to fetch product: ${s.status} ${s.statusText}`);return s.json()}function G(e){const s=w.get(e);return s?Date.now()-s.created>U?(w.delete(e),null):s.product:null}function J(e,s){w.set(e,{product:s,created:Date.now()})}function N(e){return e&&!Number.isNaN(e)?e:0}function K(e,s){const{from:t,size:r,total:n}=h.useNostoAppState(o=>({from:N(o.query.products?.from??0),size:N(o.response?.products?.size??s),total:N(o.response?.products?.total??0)})),{updateSearch:c}=F.useActions(),u=t+r,d=l.useMemo(()=>[...e].reverse().filter(o=>o<n),[e,n]),f=l.useCallback(o=>{c({products:{size:A.parseNumber(o)}})},[c]);return{from:t,to:u,total:n,size:r,sizeOptions:d,handleSizeChange:f}}function Q(e,s){return e.length!==s.length?!1:e.every(t=>s.find(r=>t.field===r.field&&t.order===r.order))}function W(e){const s=h.useNostoAppState(c=>c.query),{updateSearch:t}=F.useActions();return{activeSort:e.find(c=>Q(c.value.sort,s.products?.sort||[]))?.id??e[0]?.id,setSort:c=>{const u=e.find(d=>d.id===c);u&&t({products:{sort:u.value.sort}})}}}const M=window.SpeechRecognition||window.webkitSpeechRecognition,x=!!(M&&typeof M=="function");function Y(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function ee({language:e="en-US",interimResults:s=!1,onResult:t,onError:r}={}){const[n,c]=l.useState(!1),u=l.useRef(null),d=l.useCallback(()=>{const o=new M;o.lang=e,o.interimResults=s,o.onstart=()=>c(!0),t&&(o.onresult=i=>{const{transcript:a}=i.results?.[0]?.[0];t(a)}),r&&(o.onerror=i=>r(i.error)),o.onend=()=>c(!1),u.current=o,o.start()},[e,s,r,t]),f=l.useCallback(()=>{u.current?.stop()},[u]);return{listening:n,startListening:d,stopListening:f}}const te=x?ee:Y;function se(e,s){if(!e.length||!s.length)return[];const t=s.reduce((r,n)=>(r[n]={},r),{});return e.forEach(r=>{r.customFields?.forEach(({key:n,value:c})=>{const u=n.toLowerCase();s.includes(u)&&(t[u][c]=t[u][c]||[],t[u][c].push(r))})}),Object.entries(t).filter(r=>Object.keys(r[1]).length).map(([r,n])=>({field:r,options:Object.entries(n).map(([c,u])=>({value:c,skus:u,unavailable:!1,selected:!1}))}))}function ne(e,s){return e.length?e.map(({field:t,options:r})=>({field:t,options:r.map(n=>{const c=!n.skus?.some(d=>Object.entries(s).every(([f,o])=>f===t?!0:d.customFields?.find(a=>a.key.toLowerCase()===f)?.value===o)),u=s[t]===n.value;return{...n,unavailable:c,selected:u}})})):[]}const k=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function oe(e){if(k.includes(e))return 1e3+k.indexOf(e);const s=parseFloat(e);return isNaN(s)?e:s}function re(e,s){return[...s].sort((t,r)=>{const[n,c]=[t.value,r.value].map(oe);return n<c?-1:1})}function ue(e=[],s=[]){const[t,r]=l.useState({}),n=l.useMemo(()=>se(e,s).map(({field:o,options:i})=>({field:o,options:re(o,i)})),[e,s]),c=l.useMemo(()=>ne(n,t),[n,t]),u=l.useCallback((f,o)=>{r(i=>{const a={...i};return a[f]===o?delete a[f]:a[f]=o,a})},[]),d=l.useMemo(()=>Object.keys(t).filter(i=>t[i]).length===0?[]:c.filter(({field:i})=>t[i]).map(({field:i,options:a})=>{const p=t[i];return a.find(m=>m.value===p)?.skus??[]}).reduce((i,a)=>i.filter(p=>a.includes(p))),[c,t]);return{swatches:c,toggleOption:u,matchedSkus:d}}exports.useActions=F.useActions;exports.useLoadMore=h.useLoadMore;exports.useNostoAppState=h.useNostoAppState;exports.useHistory=L.useHistory;exports.speechToTextSupported=x;exports.useDecoratedSearchResults=X;exports.useFacet=O;exports.useFacets=j;exports.usePagination=D;exports.usePersonalization=B;exports.useProductFilters=C;exports.useRange=R;exports.useRangeSelector=$;exports.useResponse=_;exports.useSelectedFiltersCount=H;exports.useShopifyProduct=I;exports.useSizeOptions=K;exports.useSort=W;exports.useSpeechToText=te;exports.useSwatches=ue;
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import { u as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { h as R } from "../../useActions-MsVW37eV.js";
|
|
2
|
+
import { a as T } from "../../logger-_fg_Za9y.js";
|
|
3
|
+
import { a as v } from "../../useLoadMore-CYYoAHua.js";
|
|
4
|
+
import { u as Fe } from "../../useLoadMore-CYYoAHua.js";
|
|
5
|
+
import { u as X } from "../../eventBusSubscribe-CzlS132j.js";
|
|
6
|
+
import { useState as b, useCallback as h, useMemo as y, useEffect as N, useRef as z } from "preact/hooks";
|
|
7
|
+
import { u as be } from "../../useHistory-DtcY_Wkt.js";
|
|
8
|
+
import { s as k } from "../../index.es-XNBESE3P.js";
|
|
9
|
+
import { d as C } from "../../eventBusDispatch-DPR2Vwd4.js";
|
|
10
|
+
import { p as x } from "../../parseNumber-QA48nJLp.js";
|
|
11
|
+
function se(e) {
|
|
12
|
+
const n = v((t) => t.response);
|
|
13
|
+
return e && Array.isArray(e) || e && T(e) ? e : n;
|
|
12
14
|
}
|
|
13
|
-
function
|
|
15
|
+
function ie(e, n) {
|
|
14
16
|
const t = e.data?.filter((d) => d.selected).length ?? 0, { active: s } = {
|
|
15
17
|
active: t > 0,
|
|
16
18
|
...n
|
|
17
|
-
}, [r, c] =
|
|
19
|
+
}, [r, c] = b(s), { toggleProductFilter: i } = R(), l = h(() => {
|
|
18
20
|
c(!r);
|
|
19
21
|
}, [r]);
|
|
20
|
-
return {
|
|
22
|
+
return X({
|
|
23
|
+
event: "events/removeAllFilters",
|
|
24
|
+
callback: () => {
|
|
25
|
+
c(!1);
|
|
26
|
+
}
|
|
27
|
+
}), {
|
|
21
28
|
/** Active value */
|
|
22
29
|
active: r,
|
|
23
30
|
/** Selected filters count */
|
|
@@ -28,8 +35,8 @@ function ne(e, n) {
|
|
|
28
35
|
toggleProductFilter: i
|
|
29
36
|
};
|
|
30
37
|
}
|
|
31
|
-
function
|
|
32
|
-
const { loading: e, facets: n } =
|
|
38
|
+
function ce() {
|
|
39
|
+
const { loading: e, facets: n } = v((t) => ({
|
|
33
40
|
loading: t.loading,
|
|
34
41
|
facets: t.response?.products?.facets ?? []
|
|
35
42
|
}));
|
|
@@ -40,12 +47,12 @@ function re() {
|
|
|
40
47
|
facets: n
|
|
41
48
|
};
|
|
42
49
|
}
|
|
43
|
-
function
|
|
50
|
+
function O(e, n) {
|
|
44
51
|
const t = n - e;
|
|
45
52
|
return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((s, r) => r + e) : [];
|
|
46
53
|
}
|
|
47
|
-
function
|
|
48
|
-
const { query: n, products: t } =
|
|
54
|
+
function ue(e) {
|
|
55
|
+
const { query: n, products: t } = v((s) => ({
|
|
49
56
|
query: s.query,
|
|
50
57
|
products: s.response.products
|
|
51
58
|
}));
|
|
@@ -65,8 +72,8 @@ function oe(e) {
|
|
|
65
72
|
from: (w - 1) * t.size,
|
|
66
73
|
page: w,
|
|
67
74
|
current: w === i
|
|
68
|
-
}), m = i > 1 ? f(i - 1) : void 0, p = i < l ? f(i + 1) : void 0, g = i - c - 1 > 1 ? f(1) : void 0,
|
|
69
|
-
return !g && F[0]?.page === 2 && F.unshift(f(1)), !
|
|
75
|
+
}), m = i > 1 ? f(i - 1) : void 0, p = i < l ? f(i + 1) : void 0, g = i - c - 1 > 1 ? f(1) : void 0, S = i + c + 1 < l ? f(l) : void 0, F = O(1, l + 1).filter(d).map(f);
|
|
76
|
+
return !g && F[0]?.page === 2 && F.unshift(f(1)), !S && F[F.length - 1]?.page === l - 1 && F.push(f(l)), {
|
|
70
77
|
totalPages: l,
|
|
71
78
|
resultsFrom: o,
|
|
72
79
|
resultsTo: u,
|
|
@@ -74,15 +81,15 @@ function oe(e) {
|
|
|
74
81
|
prev: m,
|
|
75
82
|
next: p,
|
|
76
83
|
first: g,
|
|
77
|
-
last:
|
|
84
|
+
last: S,
|
|
78
85
|
pages: F
|
|
79
86
|
};
|
|
80
87
|
}, [n, t, e?.width]);
|
|
81
88
|
}
|
|
82
|
-
function
|
|
83
|
-
const [e, n] =
|
|
84
|
-
return
|
|
85
|
-
|
|
89
|
+
function ae() {
|
|
90
|
+
const [e, n] = b([]), [t, s] = b([]);
|
|
91
|
+
return N(() => {
|
|
92
|
+
k(async (r) => {
|
|
86
93
|
const { products: c, segments: i } = await r.getSearchSessionParams();
|
|
87
94
|
n(i ?? []), s(c?.personalizationBoost ?? []);
|
|
88
95
|
});
|
|
@@ -91,10 +98,10 @@ function se() {
|
|
|
91
98
|
boost: t
|
|
92
99
|
};
|
|
93
100
|
}
|
|
94
|
-
function
|
|
95
|
-
const { facets: e } =
|
|
101
|
+
function q() {
|
|
102
|
+
const { facets: e } = v((o) => ({
|
|
96
103
|
facets: o.response.products?.facets ?? []
|
|
97
|
-
})), { replaceFilter: n, toggleProductFilter: t } =
|
|
104
|
+
})), { replaceFilter: n, toggleProductFilter: t } = R(), s = h(
|
|
98
105
|
(o) => {
|
|
99
106
|
const u = e?.find((a) => a.type === "stats" && a.field === o);
|
|
100
107
|
if (u && "min" in u && "max" in u)
|
|
@@ -145,25 +152,24 @@ function O() {
|
|
|
145
152
|
toRangeFilter: d
|
|
146
153
|
};
|
|
147
154
|
}
|
|
148
|
-
function
|
|
149
|
-
const { filter: e } =
|
|
150
|
-
filter:
|
|
151
|
-
})), {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
155
|
+
function j() {
|
|
156
|
+
const { filter: e } = v((i) => ({
|
|
157
|
+
filter: i.query.products?.filter ?? []
|
|
158
|
+
})), { selectFilters: n, toValueFilter: t, toRangeFilter: s } = q(), r = y(() => e ? e.filter(n).flatMap((i) => "value" in i ? t(i) : "range" in i ? s(i) : []).filter(Boolean) : [], [e, n, s, t]), c = h(() => {
|
|
159
|
+
C({
|
|
160
|
+
event: "events/removeAllFilters",
|
|
161
|
+
params: null
|
|
156
162
|
});
|
|
157
|
-
}, [
|
|
163
|
+
}, []);
|
|
158
164
|
return {
|
|
159
165
|
/** Selected filters array. */
|
|
160
|
-
filters:
|
|
166
|
+
filters: r,
|
|
161
167
|
/** Should remove all selected filters. */
|
|
162
|
-
removeAll:
|
|
168
|
+
removeAll: c
|
|
163
169
|
};
|
|
164
170
|
}
|
|
165
|
-
function
|
|
166
|
-
const { replaceFilter: n } =
|
|
171
|
+
function E(e) {
|
|
172
|
+
const { replaceFilter: n } = R(), { query: t, products: s } = v((a) => ({
|
|
167
173
|
query: a.query,
|
|
168
174
|
products: a.response.products
|
|
169
175
|
})), r = s?.facets?.find((a) => a.id === e);
|
|
@@ -175,13 +181,13 @@ function q(e) {
|
|
|
175
181
|
updateRange: () => {
|
|
176
182
|
}
|
|
177
183
|
};
|
|
178
|
-
const c = t.products?.filter?.find((a) => a.field === r.field), i = c?.range ? c.range[0] : void 0, l = typeof i == "object" && ("gte" in i || "lte" in i) ? [
|
|
179
|
-
const m = a !== void 0 ? Math.floor(a) : void 0, p = f !== void 0 ? Math.ceil(f) : void 0, g = m !== void 0,
|
|
180
|
-
(d === m || !g) && (o === p || !
|
|
184
|
+
const c = t.products?.filter?.find((a) => a.field === r.field), i = c?.range ? c.range[0] : void 0, l = typeof i == "object" && ("gte" in i || "lte" in i) ? [x(i.gte), x(i.lte)] : [void 0, void 0], d = "min" in r ? Math.floor(r.min) : 0, o = "max" in r ? Math.ceil(r.max) : 0, u = ([a, f]) => {
|
|
185
|
+
const m = a !== void 0 ? Math.floor(a) : void 0, p = f !== void 0 ? Math.ceil(f) : void 0, g = m !== void 0, S = p !== void 0;
|
|
186
|
+
(d === m || !g) && (o === p || !S) ? n(r.field, void 0) : (d === m || !g) && S ? n(r.field, {
|
|
181
187
|
lte: p.toString()
|
|
182
|
-
}) : (o === p || !
|
|
188
|
+
}) : (o === p || !S) && g ? n(r.field, {
|
|
183
189
|
gte: m.toString()
|
|
184
|
-
}) : g &&
|
|
190
|
+
}) : g && S && n(r.field, {
|
|
185
191
|
gte: m.toString(),
|
|
186
192
|
lte: p.toString()
|
|
187
193
|
});
|
|
@@ -197,22 +203,22 @@ function q(e) {
|
|
|
197
203
|
updateRange: u
|
|
198
204
|
};
|
|
199
205
|
}
|
|
200
|
-
function
|
|
201
|
-
const { min: t, max: s, range: r, updateRange: c } =
|
|
206
|
+
function le(e, n) {
|
|
207
|
+
const { min: t, max: s, range: r, updateRange: c } = E(e), { filters: i } = j(), l = y(() => {
|
|
202
208
|
const a = i.find((g) => g?.filter?.range);
|
|
203
209
|
let f = null;
|
|
204
210
|
if (a) {
|
|
205
211
|
const g = a.filter.range?.[0];
|
|
206
|
-
f = [
|
|
212
|
+
f = [x(g?.gte), x(g?.lte)];
|
|
207
213
|
}
|
|
208
214
|
const m = [];
|
|
209
215
|
let p = Math.floor(t / n) * n;
|
|
210
216
|
for (; p < s; ) {
|
|
211
|
-
const g = p + n,
|
|
217
|
+
const g = p + n, S = f && f[0] === p && f[1] === g;
|
|
212
218
|
m.push({
|
|
213
219
|
min: p,
|
|
214
220
|
max: g,
|
|
215
|
-
selected:
|
|
221
|
+
selected: S
|
|
216
222
|
}), p = g;
|
|
217
223
|
}
|
|
218
224
|
return m;
|
|
@@ -240,8 +246,8 @@ function ie(e, n) {
|
|
|
240
246
|
isSelected: u
|
|
241
247
|
};
|
|
242
248
|
}
|
|
243
|
-
function
|
|
244
|
-
const { products: e, keywords: n } =
|
|
249
|
+
function de() {
|
|
250
|
+
const { products: e, keywords: n } = v((t) => t.response);
|
|
245
251
|
return {
|
|
246
252
|
/** Array of products */
|
|
247
253
|
products: e ?? { hits: [], total: 0 },
|
|
@@ -249,18 +255,18 @@ function ce() {
|
|
|
249
255
|
keywords: n ?? { hits: [], total: 0 }
|
|
250
256
|
};
|
|
251
257
|
}
|
|
252
|
-
function
|
|
253
|
-
const e =
|
|
258
|
+
function fe() {
|
|
259
|
+
const e = v((t) => t.query.products?.filter);
|
|
254
260
|
return y(() => e ? e.reduce((t, s) => t + (Array.isArray(s.value) ? s.value.length : 1), 0) : 0, [e]);
|
|
255
261
|
}
|
|
256
|
-
const
|
|
257
|
-
function
|
|
258
|
-
const [n, t] =
|
|
262
|
+
const D = 5 * 60 * 1e3, M = /* @__PURE__ */ new Map();
|
|
263
|
+
function ge(e) {
|
|
264
|
+
const [n, t] = b({
|
|
259
265
|
product: null,
|
|
260
266
|
loading: !0,
|
|
261
267
|
error: null
|
|
262
268
|
});
|
|
263
|
-
return
|
|
269
|
+
return N(() => {
|
|
264
270
|
if (!e) {
|
|
265
271
|
t({
|
|
266
272
|
product: null,
|
|
@@ -274,7 +280,7 @@ function ae(e) {
|
|
|
274
280
|
loading: !0,
|
|
275
281
|
error: null
|
|
276
282
|
}));
|
|
277
|
-
const s =
|
|
283
|
+
const s = $(e);
|
|
278
284
|
if (s) {
|
|
279
285
|
t({
|
|
280
286
|
product: s,
|
|
@@ -283,8 +289,8 @@ function ae(e) {
|
|
|
283
289
|
});
|
|
284
290
|
return;
|
|
285
291
|
}
|
|
286
|
-
|
|
287
|
-
|
|
292
|
+
V(e).then((r) => {
|
|
293
|
+
B(e, r), t({
|
|
288
294
|
product: r,
|
|
289
295
|
loading: !1,
|
|
290
296
|
error: null
|
|
@@ -298,17 +304,17 @@ function ae(e) {
|
|
|
298
304
|
});
|
|
299
305
|
}, [e]), n;
|
|
300
306
|
}
|
|
301
|
-
async function
|
|
307
|
+
async function V(e) {
|
|
302
308
|
const n = await fetch(`/products/${e}.js`);
|
|
303
309
|
if (!n.ok)
|
|
304
310
|
throw new Error(`Failed to fetch product: ${n.status} ${n.statusText}`);
|
|
305
311
|
return n.json();
|
|
306
312
|
}
|
|
307
|
-
function
|
|
313
|
+
function $(e) {
|
|
308
314
|
const n = M.get(e);
|
|
309
|
-
return n ? Date.now() - n.created >
|
|
315
|
+
return n ? Date.now() - n.created > D ? (M.delete(e), null) : n.product : null;
|
|
310
316
|
}
|
|
311
|
-
function
|
|
317
|
+
function B(e, n) {
|
|
312
318
|
M.set(e, {
|
|
313
319
|
product: n,
|
|
314
320
|
created: Date.now()
|
|
@@ -317,16 +323,16 @@ function V(e, n) {
|
|
|
317
323
|
function L(e) {
|
|
318
324
|
return e && !Number.isNaN(e) ? e : 0;
|
|
319
325
|
}
|
|
320
|
-
function
|
|
321
|
-
const { from: t, size: s, total: r } =
|
|
326
|
+
function pe(e, n) {
|
|
327
|
+
const { from: t, size: s, total: r } = v((o) => ({
|
|
322
328
|
from: L(o.query.products?.from ?? 0),
|
|
323
329
|
size: L(o.response?.products?.size ?? n),
|
|
324
330
|
total: L(o.response?.products?.total ?? 0)
|
|
325
|
-
})), { updateSearch: c } =
|
|
331
|
+
})), { updateSearch: c } = R(), i = t + s, l = y(() => [...e].reverse().filter((o) => o < r), [e, r]), d = h(
|
|
326
332
|
(o) => {
|
|
327
333
|
c({
|
|
328
334
|
products: {
|
|
329
|
-
size:
|
|
335
|
+
size: x(o)
|
|
330
336
|
}
|
|
331
337
|
});
|
|
332
338
|
},
|
|
@@ -347,14 +353,14 @@ function le(e, n) {
|
|
|
347
353
|
handleSizeChange: d
|
|
348
354
|
};
|
|
349
355
|
}
|
|
350
|
-
function
|
|
356
|
+
function U(e, n) {
|
|
351
357
|
return e.length !== n.length ? !1 : e.every((t) => n.find((s) => t.field === s.field && t.order === s.order));
|
|
352
358
|
}
|
|
353
|
-
function
|
|
354
|
-
const n =
|
|
359
|
+
function me(e) {
|
|
360
|
+
const n = v((c) => c.query), { updateSearch: t } = R();
|
|
355
361
|
return {
|
|
356
362
|
/** Active sort */
|
|
357
|
-
activeSort: e.find((c) =>
|
|
363
|
+
activeSort: e.find((c) => U(c.value.sort, n.products?.sort || []))?.id ?? e[0]?.id,
|
|
358
364
|
/** Set sort function */
|
|
359
365
|
setSort: (c) => {
|
|
360
366
|
const i = e.find((l) => l.id === c);
|
|
@@ -366,8 +372,8 @@ function de(e) {
|
|
|
366
372
|
}
|
|
367
373
|
};
|
|
368
374
|
}
|
|
369
|
-
const
|
|
370
|
-
function
|
|
375
|
+
const A = window.SpeechRecognition || window.webkitSpeechRecognition, _ = !!(A && typeof A == "function");
|
|
376
|
+
function I() {
|
|
371
377
|
return {
|
|
372
378
|
listening: !1,
|
|
373
379
|
startListening: () => {
|
|
@@ -376,14 +382,14 @@ function U() {
|
|
|
376
382
|
}
|
|
377
383
|
};
|
|
378
384
|
}
|
|
379
|
-
function
|
|
385
|
+
function H({
|
|
380
386
|
language: e = "en-US",
|
|
381
387
|
interimResults: n = !1,
|
|
382
388
|
onResult: t,
|
|
383
389
|
onError: s
|
|
384
390
|
} = {}) {
|
|
385
|
-
const [r, c] =
|
|
386
|
-
const o = new
|
|
391
|
+
const [r, c] = b(!1), i = z(null), l = h(() => {
|
|
392
|
+
const o = new A();
|
|
387
393
|
o.lang = e, o.interimResults = n, o.onstart = () => c(!0), t && (o.onresult = (u) => {
|
|
388
394
|
const { transcript: a } = u.results?.[0]?.[0];
|
|
389
395
|
t(a);
|
|
@@ -397,8 +403,8 @@ function _({
|
|
|
397
403
|
stopListening: d
|
|
398
404
|
};
|
|
399
405
|
}
|
|
400
|
-
const
|
|
401
|
-
function
|
|
406
|
+
const he = _ ? H : I;
|
|
407
|
+
function Z(e, n) {
|
|
402
408
|
if (!e.length || !n.length) return [];
|
|
403
409
|
const t = n.reduce((s, r) => (s[r] = {}, s), {});
|
|
404
410
|
return e.forEach((s) => {
|
|
@@ -416,7 +422,7 @@ function I(e, n) {
|
|
|
416
422
|
}))
|
|
417
423
|
}));
|
|
418
424
|
}
|
|
419
|
-
function
|
|
425
|
+
function G(e, n) {
|
|
420
426
|
return e.length ? e.map(({ field: t, options: s }) => ({
|
|
421
427
|
field: t,
|
|
422
428
|
options: s.map((r) => {
|
|
@@ -429,24 +435,24 @@ function H(e, n) {
|
|
|
429
435
|
})
|
|
430
436
|
})) : [];
|
|
431
437
|
}
|
|
432
|
-
const
|
|
433
|
-
function
|
|
434
|
-
if (
|
|
435
|
-
return 1e3 +
|
|
438
|
+
const P = ["4XS", "3XS", "2XS", "XXS", "XS", "S", "M", "L", "XL", "XXL", "2XL", "XXXL", "3XL", "4XL"];
|
|
439
|
+
function J(e) {
|
|
440
|
+
if (P.includes(e))
|
|
441
|
+
return 1e3 + P.indexOf(e);
|
|
436
442
|
const n = parseFloat(e);
|
|
437
443
|
return isNaN(n) ? e : n;
|
|
438
444
|
}
|
|
439
|
-
function
|
|
445
|
+
function K(e, n) {
|
|
440
446
|
return [...n].sort((t, s) => {
|
|
441
|
-
const [r, c] = [t.value, s.value].map(
|
|
447
|
+
const [r, c] = [t.value, s.value].map(J);
|
|
442
448
|
return r < c ? -1 : 1;
|
|
443
449
|
});
|
|
444
450
|
}
|
|
445
|
-
function
|
|
446
|
-
const [t, s] =
|
|
451
|
+
function ve(e = [], n = []) {
|
|
452
|
+
const [t, s] = b({}), r = y(() => Z(e, n).map(({ field: o, options: u }) => ({
|
|
447
453
|
field: o,
|
|
448
|
-
options:
|
|
449
|
-
})), [e, n]), c = y(() =>
|
|
454
|
+
options: K(o, u)
|
|
455
|
+
})), [e, n]), c = y(() => G(r, t), [r, t]), i = h((d, o) => {
|
|
450
456
|
s((u) => {
|
|
451
457
|
const a = { ...u };
|
|
452
458
|
return a[d] === o ? delete a[d] : a[d] = o, a;
|
|
@@ -458,24 +464,24 @@ function ge(e = [], n = []) {
|
|
|
458
464
|
return { swatches: c, toggleOption: i, matchedSkus: l };
|
|
459
465
|
}
|
|
460
466
|
export {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
467
|
+
_ as speechToTextSupported,
|
|
468
|
+
R as useActions,
|
|
469
|
+
se as useDecoratedSearchResults,
|
|
470
|
+
ie as useFacet,
|
|
471
|
+
ce as useFacets,
|
|
472
|
+
be as useHistory,
|
|
473
|
+
Fe as useLoadMore,
|
|
474
|
+
v as useNostoAppState,
|
|
475
|
+
ue as usePagination,
|
|
476
|
+
ae as usePersonalization,
|
|
477
|
+
j as useProductFilters,
|
|
478
|
+
E as useRange,
|
|
479
|
+
le as useRangeSelector,
|
|
480
|
+
de as useResponse,
|
|
481
|
+
fe as useSelectedFiltersCount,
|
|
482
|
+
ge as useShopifyProduct,
|
|
483
|
+
pe as useSizeOptions,
|
|
484
|
+
me as useSort,
|
|
485
|
+
he as useSpeechToText,
|
|
486
|
+
ve as useSwatches
|
|
481
487
|
};
|
|
@@ -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-DtgDwaV9.cjs"),T=require("../../CategoryPageProvider-CJL0GSV1.cjs"),h=require("../../useActions-Drtoxcu4.cjs"),I=require("../../SerpPageProvider-CsLAvEUE.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-
|
|
1
|
+
import { A as L, m as j } from "../../AutocompletePageProvider-FCFyqG35.js";
|
|
2
|
+
import { C as O, m as R } from "../../CategoryPageProvider-OYvvNZSr.js";
|
|
3
3
|
import { n as T, c as p } from "../../useActions-MsVW37eV.js";
|
|
4
|
-
import { S as $, m as F } from "../../SerpPageProvider-
|
|
4
|
+
import { S as $, m as F } from "../../SerpPageProvider-d781RZHT.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 a=require("../../jsxRuntime.module-B3sGoTIU.cjs"),l=require("../../index.es-Dp6Iaxz3.cjs"),u=require("../../BaseElement-CIHACCWd.cjs"),S=require("../../useActions-Drtoxcu4.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-
|
|
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-Drtoxcu4.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-CsLAvEUE.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;
|
|
@@ -3,7 +3,7 @@ import { s as l } from "../../index.es-XNBESE3P.js";
|
|
|
3
3
|
import { B as m } from "../../BaseElement-DD_4UwDm.js";
|
|
4
4
|
import { b as p } from "../../useActions-MsVW37eV.js";
|
|
5
5
|
import { useCallback as f } from "preact/hooks";
|
|
6
|
-
import { S as h } from "../../SerpPageProvider-
|
|
6
|
+
import { S as h } from "../../SerpPageProvider-d781RZHT.js";
|
|
7
7
|
const S = "nosto:search-js:scrollPos";
|
|
8
8
|
function g() {
|
|
9
9
|
window.sessionStorage.setItem(S, window.scrollY.toString());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const n=require("./useActions-Drtoxcu4.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;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { S as i, a as l } from "./useActions-MsVW37eV.js";
|
|
2
|
+
import { g as a, a as m } from "./search-mArZ2PXy.js";
|
|
3
|
+
import { useContext as u, useCallback as y } from "preact/hooks";
|
|
4
|
+
const o = "nosto:search-js:history";
|
|
5
|
+
function p() {
|
|
6
|
+
return (a(o) ?? []).slice().reverse().filter((t) => !!t);
|
|
7
|
+
}
|
|
8
|
+
function I() {
|
|
9
|
+
const { updateState: e } = u(i), { historySize: t } = l();
|
|
10
|
+
return {
|
|
11
|
+
addQuery: y(
|
|
12
|
+
(s) => {
|
|
13
|
+
const c = (a(o) ?? []).filter((n) => n !== s).concat(s), r = t ? c.slice(-t) : [];
|
|
14
|
+
m(o, r), e({ historyItems: r.reverse() });
|
|
15
|
+
},
|
|
16
|
+
[t, e]
|
|
17
|
+
)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
p as g,
|
|
22
|
+
I as u
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const o=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-Drtoxcu4.cjs"),u=require("./baseConfig-gkfFlBOL.cjs"),a=require("./useHistory-2uGnArVO.cjs"),l=require("preact/hooks"),m={...u.defaultBaseConfig,memoryCache:!1,historyEnabled:!0,historySize:5,debounceDelay:500,minQueryLength:2};function i(e={}){return{pageType:"autocomplete",...m,...e}}function f({config:e,store:s,children:c}){const t=s??r.createStore();u.useCheckClientScript();const{getSaved:n}=a.useHistory();return l.useEffect(()=>{t.updateState({historyItems:n()})},[t,n]),o.u(r.ConfigContext,{value:i(e),children:o.u(r.StoreContext,{value:t,children:[o.u(u.StoreActionsListener,{}),c]})})}exports.AutocompletePageProvider=f;exports.makeAutocompleteConfig=i;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { u as o } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as s, C as u } from "./useActions-MsVW37eV.js";
|
|
3
|
-
import { d as c, u as m, S as f } from "./baseConfig-BMc1698x.js";
|
|
4
|
-
import { u as l } from "./useHistory-W6FQSk99.js";
|
|
5
|
-
import { useEffect as p } from "preact/hooks";
|
|
6
|
-
const d = {
|
|
7
|
-
...c,
|
|
8
|
-
memoryCache: !1,
|
|
9
|
-
historyEnabled: !0,
|
|
10
|
-
historySize: 5,
|
|
11
|
-
debounceDelay: 500,
|
|
12
|
-
minQueryLength: 2
|
|
13
|
-
};
|
|
14
|
-
function C(e = {}) {
|
|
15
|
-
return {
|
|
16
|
-
pageType: "autocomplete",
|
|
17
|
-
...d,
|
|
18
|
-
...e
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function v({ config: e, store: a, children: i }) {
|
|
22
|
-
const t = a ?? n();
|
|
23
|
-
m();
|
|
24
|
-
const { getSaved: r } = l();
|
|
25
|
-
return p(() => {
|
|
26
|
-
t.updateState({
|
|
27
|
-
historyItems: r()
|
|
28
|
-
});
|
|
29
|
-
}, [t, r]), /* @__PURE__ */ o(u, { value: C(e), children: /* @__PURE__ */ o(s, { value: t, children: [
|
|
30
|
-
/* @__PURE__ */ o(f, {}),
|
|
31
|
-
i
|
|
32
|
-
] }) });
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
v as A,
|
|
36
|
-
C as m
|
|
37
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const c=require("./useActions-Drtoxcu4.cjs"),s=require("./eventBusSubscribe-oONOUGH8.cjs"),f=require("./index.es-Dp6Iaxz3.cjs"),b=require("./logger-Boh_C6Bz.cjs"),d=require("preact/hooks");function S(){const{pageType:e}=c.useConfig(),{newSearch:i,updateSearch:u,replaceFilter:o,toggleProductFilter:a}=c.useActions();return s.useEventBusSubscribe({event:"actions/newSearch",callback:({query:t,options:r,targetStore:n})=>{e===n&&i(t,r)}}),s.useEventBusSubscribe({event:"actions/updateSearch",callback:({query:t,options:r,targetStore:n})=>{e===n&&u(t,r)}}),s.useEventBusSubscribe({event:"actions/replaceFilter",callback:({field:t,value:r,targetStore:n})=>{e===n&&o(t,r)}}),s.useEventBusSubscribe({event:"actions/toggleProductFilter",callback:({field:t,value:r,active:n,targetStore:l})=>{e===l&&a(t,r,n)}}),null}function g(){d.useEffect(()=>{const e=window.setTimeout(()=>{b.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);f.s(()=>{window.clearTimeout(e)})},[])}const p={defaultCurrency:"EUR",queryModifications:e=>e};exports.StoreActionsListener=S;exports.defaultBaseConfig=p;exports.useCheckClientScript=g;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("./useActions-Drtoxcu4.cjs"),o=require("./search-RNs4Cunh.cjs"),s=require("preact/hooks"),r="nosto:search-js:history";function S(){const{updateState:c}=s.useContext(i.StoreContext),{historySize:e}=i.useAutocompleteConfig(),l=s.useCallback(t=>{const m=(o.getLocalStorageItem(r)??[]).filter(y=>y!==t).concat(t),a=e?m.slice(-e):[];o.setLocalStorageItem(r,a),c({historyItems:a.reverse()})},[e,c]),u=s.useCallback(()=>(o.getLocalStorageItem(r)??[]).slice().reverse().filter(n=>!!n),[]);return{addQuery:l,getSaved:u}}exports.useHistory=S;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { S, a as y } from "./useActions-MsVW37eV.js";
|
|
2
|
-
import { g as c, a as g } from "./search-mArZ2PXy.js";
|
|
3
|
-
import { useContext as f, useCallback as n } from "preact/hooks";
|
|
4
|
-
const o = "nosto:search-js:history";
|
|
5
|
-
function d() {
|
|
6
|
-
const { updateState: s } = f(S), { historySize: t } = y(), i = n(
|
|
7
|
-
(e) => {
|
|
8
|
-
const m = (c(o) ?? []).filter((u) => u !== e).concat(e), a = t ? m.slice(-t) : [];
|
|
9
|
-
g(o, a), s({ historyItems: a.reverse() });
|
|
10
|
-
},
|
|
11
|
-
[t, s]
|
|
12
|
-
), l = n(() => (c(o) ?? []).slice().reverse().filter((r) => !!r), []);
|
|
13
|
-
return {
|
|
14
|
-
addQuery: i,
|
|
15
|
-
getSaved: l
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
d as u
|
|
20
|
-
};
|