@nosto/search-js 3.17.2 → 3.18.1
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/core/core.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../useActions-CY9uts_o.cjs"),q=require("../../logger-Boh_C6Bz.cjs"),h=require("../../useLoadMore-CBshMpps.cjs"),C=require("../../eventBusSubscribe-oONOUGH8.cjs"),d=require("preact/hooks"),L=require("../../useHistory-CJSGam5n.cjs"),T=require("../../index.es-Dp6Iaxz3.cjs"),z=require("../../eventBusDispatch-BKQcSHAB.cjs"),A=require("../../parseNumber-FsZ8w61u.cjs");function O(e){const s=h.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&q.isPlainObject(e)?e:s}function X(e,s){const t=e.data?.filter(f=>f.selected).length??0,{active:o}={active:t>0,...s},[n,c]=d.useState(o),{toggleProductFilter:u}=v.useActions(),a=d.useCallback(()=>{c(!n)},[n]);return C.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{c(!1)}}),{active:n,selectedFiltersCount:t,toggleActive:a,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((o,n)=>n+e):[]}function B(e){const{query:s,products:t}=h.useNostoAppState(o=>({query:o.query,products:o.response.products}));return d.useMemo(()=>{if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=s.products?.from??0,n=e?.width??1/0,c=Math.max(Math.floor(n-1)/2,1),u=t.size>0?Math.floor(o/t.size)+1:1,a=t.size>0?Math.ceil(t.total/t.size):0,f=F=>F>=u-c&&F<=u+c,r=o+1,i=Math.min(o+t.total,t.total),l={from:o,page:u,current:!0},p=F=>({from:(F-1)*t.size,page:F,current:F===u}),S=u>1?p(u-1):void 0,g=u<a?p(u+1):void 0,m=u-c-1>1?p(1):void 0,b=u+c+1<a?p(a):void 0,y=E(1,a+1).filter(f).map(p);return!m&&y[0]?.page===2&&y.unshift(p(1)),!b&&y[y.length-1]?.page===a-1&&y.push(p(a)),{totalPages:a,resultsFrom:r,resultsTo:i,current:l,prev:S,next:g,first:m,last:b,pages:y}},[s,t,e?.width])}function D(){const[e,s]=d.useState([]),[t,o]=d.useState([]);return d.useEffect(()=>{T.s(async n=>{const{products:c,segments:u}=await n.getSearchSessionParams();s(u??[]),o(c?.personalizationBoost??[])})},[]),{segments:e,boost:t}}function V(){const{facets:e}=h.useNostoAppState(r=>({facets:r.response.products?.facets??[]})),{replaceFilter:s,toggleProductFilter:t}=v.useActions(),o=d.useCallback(r=>{const i=e?.find(l=>l.type==="stats"&&l.field===r);if(i&&"min"in i&&"max"in i)return i},[e]),n=d.useCallback(r=>e?.find(i=>i.field===r)?.name??r,[e]),c=d.useCallback(r=>"field"in r&&(r.value instanceof Array||r.range instanceof Array),[]),u=d.useCallback(r=>({...r,range:r.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}))}),[]),a=d.useCallback(r=>(r.value??[]).map(l=>({value:l,field:r.field,name:n(r.field),filter:u(r),remove:()=>{t(r.field,l,!1)}})),[u,n,t]),f=d.useCallback(r=>(r.range??[]).map(l=>{const p=l.gte??l.gt??o(r.field)?.min,S=l.lte??l.lt??o(r.field)?.max;if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:r.field,name:n(r.field),filter:u(r),remove:()=>{s(r.field,void 0)}}}).filter(Boolean),[u,o,n,s]);return{selectFilters:c,toValueFilter:a,toRangeFilter:f}}function R(){const{filter:e}=h.useNostoAppState(a=>({filter:a.query.products?.filter??[]})),{updateSearch:s}=v.useActions(),{selectFilters:t,toValueFilter:o,toRangeFilter:n}=V(),c=d.useMemo(()=>e?e.filter(t).flatMap(a=>"value"in a?o(a):"range"in a?n(a):[]).filter(Boolean):[],[e,t,n,o]),u=d.useCallback(()=>{s({products:{filter:[]}}),z.dispatchNostoEvent({event:"events/removeAllFilters",params:null})},[s]);return{filters:c,removeAll:u}}function x(e){const{replaceFilter:s}=v.useActions(),{query:t,products:o}=h.useNostoAppState(g=>({query:g.query,products:g.response.products})),n=o?.facets?.find(g=>g.id===e),c=t.products?.filter?.find(g=>g.field===n?.field),u=$(c),a=n&&"min"in n?Math.floor(n.min??0):0,f=n&&"max"in n?Math.ceil(n.max??0):0,r=u[0]!==void 0||u[1]!==void 0,[i,l]=d.useState(r),p=d.useCallback(()=>{l(g=>!g)},[]),S=d.useCallback(([g,m])=>{if(!n)return;const b=_(g,m,a,f);s(n.field,b)},[a,f,s,n]);return C.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{l(!1)}}),n?{min:a,max:f,range:[u[0]??a,u[1]??f],updateRange:S,active:i,toggleActive:p}:{min:0,max:0,range:[0,0],active:!1,toggleActive:()=>{},updateRange:()=>{}}}function $(e){const s=e?.range?.[0];return typeof s=="object"&&("gte"in s||"lte"in s)?[A.parseNumber(s.gte),A.parseNumber(s.lte)]:[void 0,void 0]}function _(e,s,t,o){const n=e!==void 0?Math.floor(e):void 0,c=s!==void 0?Math.ceil(s):void 0,u=n!==void 0,a=c!==void 0;if((t===n||!u)&&(o===c||!a))return;const f={};return u&&n!==t&&(f.gte=n.toString()),a&&c!==o&&(f.lte=c.toString()),Object.keys(f).length>0?f:void 0}function H(e,s){const{min:t,max:o,range:n,updateRange:c}=x(e),{filters:u}=R(),a=d.useMemo(()=>{const l=u.find(m=>m?.filter?.range);let p=null;if(l){const m=l.filter.range?.[0];p=[A.parseNumber(m?.gte),A.parseNumber(m?.lte)]}const S=[];let g=Math.floor(t/s)*s;for(;g<o;){const m=g+s,b=p&&p[0]===g&&p[1]===m;S.push({min:g,max:m,selected:b}),g=m}return S},[u,t,o,s]),f=l=>{c([l,n[1]])},r=l=>{c([n[0],l])},i=t!==n[0]||o!==n[1];return{min:t,max:o,range:n,updateRange:c,ranges:a,handleMinChange:f,handleMaxChange:r,isSelected:i}}function U(){const{products:e,keywords:s}=h.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:s??{hits:[],total:0}}}function I(){const e=h.useNostoAppState(t=>t.query.products?.filter);return d.useMemo(()=>e?e.reduce((t,o)=>t+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}const Z=5*60*1e3,w=new Map;function G(e){const[s,t]=d.useState({product:null,loading:!0,error:null});return d.useEffect(()=>{if(!e){t({product:null,loading:!1,error:"Product handle is required"});return}t(n=>({...n,loading:!0,error:null}));const o=K(e);if(o){t({product:o,loading:!1,error:null});return}J(e).then(n=>{Q(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 J(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 K(e){const s=w.get(e);return s?Date.now()-s.created>Z?(w.delete(e),null):s.product:null}function Q(e,s){w.set(e,{product:s,created:Date.now()})}function N(e){return e&&!Number.isNaN(e)?e:0}function W(e,s){const{from:t,size:o,total:n}=h.useNostoAppState(r=>({from:N(r.query.products?.from??0),size:N(r.response?.products?.size??s),total:N(r.response?.products?.total??0)})),{updateSearch:c}=v.useActions(),u=t+o,a=d.useMemo(()=>[...e].reverse().filter(r=>r<n),[e,n]),f=d.useCallback(r=>{c({products:{size:A.parseNumber(r)}})},[c]);return{from:t,to:u,total:n,size:o,sizeOptions:a,handleSizeChange:f}}function Y(e,s){return e.length!==s.length?!1:e.every(t=>s.find(o=>t.field===o.field&&t.order===o.order))}function ee(e){const s=h.useNostoAppState(c=>c.query),{updateSearch:t}=v.useActions();return{activeSort:e.find(c=>Y(c.value.sort,s.products?.sort||[]))?.id??e[0]?.id,setSort:c=>{const u=e.find(a=>a.id===c);u&&t({products:{sort:u.value.sort}})}}}const k=window.SpeechRecognition||window.webkitSpeechRecognition,P=!!(k&&typeof k=="function");function te(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function se({language:e="en-US",interimResults:s=!1,onResult:t,onError:o}={}){const[n,c]=d.useState(!1),u=d.useRef(null),a=d.useCallback(()=>{const r=new k;r.lang=e,r.interimResults=s,r.onstart=()=>c(!0),t&&(r.onresult=i=>{const{transcript:l}=i.results?.[0]?.[0];t(l)}),o&&(r.onerror=i=>o(i.error)),r.onend=()=>c(!1),u.current=r,r.start()},[e,s,o,t]),f=d.useCallback(()=>{u.current?.stop()},[u]);return{listening:n,startListening:a,stopListening:f}}const ne=P?se:te;function oe(e,s){if(!e.length||!s.length)return[];const t=s.reduce((o,n)=>(o[n]={},o),{});return e.forEach(o=>{o.customFields?.forEach(({key:n,value:c})=>{const u=n.toLowerCase();s.includes(u)&&(t[u][c]=t[u][c]||[],t[u][c].push(o))})}),Object.entries(t).filter(o=>Object.keys(o[1]).length).map(([o,n])=>({field:o,options:Object.entries(n).map(([c,u])=>({value:c,skus:u,unavailable:!1,selected:!1}))}))}function re(e,s){return e.length?e.map(({field:t,options:o})=>({field:t,options:o.map(n=>{const c=!n.skus?.some(a=>Object.entries(s).every(([f,r])=>f===t?!0:a.customFields?.find(l=>l.key.toLowerCase()===f)?.value===r)),u=s[t]===n.value;return{...n,unavailable:c,selected:u}})})):[]}const M=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function ue(e){if(M.includes(e))return 1e3+M.indexOf(e);const s=parseFloat(e);return isNaN(s)?e:s}function ce(e,s){return[...s].sort((t,o)=>{const[n,c]=[t.value,o.value].map(ue);return n<c?-1:1})}function ie(e=[],s=[]){const[t,o]=d.useState({}),n=d.useMemo(()=>oe(e,s).map(({field:r,options:i})=>({field:r,options:ce(r,i)})),[e,s]),c=d.useMemo(()=>re(n,t),[n,t]),u=d.useCallback((f,r)=>{o(i=>{const l={...i};return l[f]===r?delete l[f]:l[f]=r,l})},[]),a=d.useMemo(()=>Object.keys(t).filter(i=>t[i]).length===0?[]:c.filter(({field:i})=>t[i]).map(({field:i,options:l})=>{const p=t[i];return l.find(g=>g.value===p)?.skus??[]}).reduce((i,l)=>i.filter(p=>l.includes(p))),[c,t]);return{swatches:c,toggleOption:u,matchedSkus:a}}exports.useActions=v.useActions;exports.useLoadMore=h.useLoadMore;exports.useNostoAppState=h.useNostoAppState;exports.useHistory=L.useHistory;exports.speechToTextSupported=P;exports.useDecoratedSearchResults=O;exports.useFacet=X;exports.useFacets=j;exports.usePagination=B;exports.usePersonalization=D;exports.useProductFilters=R;exports.useRange=x;exports.useRangeSelector=H;exports.useResponse=U;exports.useSelectedFiltersCount=I;exports.useShopifyProduct=G;exports.useSizeOptions=W;exports.useSort=ee;exports.useSpeechToText=ne;exports.useSwatches=ie;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { h as x } from "../../useActions-CSNwQtT1.js";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as X } from "../../logger-_fg_Za9y.js";
|
|
3
3
|
import { a as v } from "../../useLoadMore-2OmOqicJ.js";
|
|
4
|
-
import { u as
|
|
5
|
-
import { u as
|
|
6
|
-
import { useState as
|
|
7
|
-
import { u as
|
|
8
|
-
import { s as
|
|
9
|
-
import { d as
|
|
10
|
-
import { p as
|
|
11
|
-
function
|
|
4
|
+
import { u as be } from "../../useLoadMore-2OmOqicJ.js";
|
|
5
|
+
import { u as N } from "../../eventBusSubscribe-CzlS132j.js";
|
|
6
|
+
import { useState as F, useCallback as p, useMemo as S, useEffect as T, useRef as k } from "preact/hooks";
|
|
7
|
+
import { u as Ae } from "../../useHistory-DeIqqw-P.js";
|
|
8
|
+
import { s as z } from "../../index.es-XNBESE3P.js";
|
|
9
|
+
import { d as O } from "../../eventBusDispatch-DPR2Vwd4.js";
|
|
10
|
+
import { p as A } from "../../parseNumber-QA48nJLp.js";
|
|
11
|
+
function ie(e) {
|
|
12
12
|
const n = v((t) => t.response);
|
|
13
|
-
return e && Array.isArray(e) || e &&
|
|
13
|
+
return e && Array.isArray(e) || e && X(e) ? e : n;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const t = e.data?.filter((d) => d.selected).length ?? 0, { active:
|
|
15
|
+
function ue(e, n) {
|
|
16
|
+
const t = e.data?.filter((d) => d.selected).length ?? 0, { active: o } = {
|
|
17
17
|
active: t > 0,
|
|
18
18
|
...n
|
|
19
|
-
}, [r,
|
|
20
|
-
|
|
19
|
+
}, [r, i] = F(o), { toggleProductFilter: c } = x(), a = p(() => {
|
|
20
|
+
i(!r);
|
|
21
21
|
}, [r]);
|
|
22
|
-
return
|
|
22
|
+
return N({
|
|
23
23
|
event: "events/removeAllFilters",
|
|
24
24
|
callback: () => {
|
|
25
|
-
|
|
25
|
+
i(!1);
|
|
26
26
|
}
|
|
27
27
|
}), {
|
|
28
28
|
/** Active value */
|
|
@@ -30,12 +30,12 @@ function ie(e, n) {
|
|
|
30
30
|
/** Selected filters count */
|
|
31
31
|
selectedFiltersCount: t,
|
|
32
32
|
/** Toggle active function */
|
|
33
|
-
toggleActive:
|
|
33
|
+
toggleActive: a,
|
|
34
34
|
/** Toggle product filter function */
|
|
35
|
-
toggleProductFilter:
|
|
35
|
+
toggleProductFilter: c
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function ae() {
|
|
39
39
|
const { loading: e, facets: n } = v((t) => ({
|
|
40
40
|
loading: t.loading,
|
|
41
41
|
facets: t.response?.products?.facets ?? []
|
|
@@ -47,16 +47,16 @@ function ce() {
|
|
|
47
47
|
facets: n
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function C(e, n) {
|
|
51
51
|
const t = n - e;
|
|
52
|
-
return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((
|
|
52
|
+
return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((o, r) => r + e) : [];
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
const { query: n, products: t } = v((
|
|
56
|
-
query:
|
|
57
|
-
products:
|
|
54
|
+
function le(e) {
|
|
55
|
+
const { query: n, products: t } = v((o) => ({
|
|
56
|
+
query: o.query,
|
|
57
|
+
products: o.response.products
|
|
58
58
|
}));
|
|
59
|
-
return
|
|
59
|
+
return S(() => {
|
|
60
60
|
if (!t)
|
|
61
61
|
return {
|
|
62
62
|
totalPages: 0,
|
|
@@ -64,193 +64,213 @@ function ue(e) {
|
|
|
64
64
|
resultsTo: 0,
|
|
65
65
|
pages: []
|
|
66
66
|
};
|
|
67
|
-
const
|
|
68
|
-
from:
|
|
69
|
-
page:
|
|
67
|
+
const o = n.products?.from ?? 0, r = e?.width ?? 1 / 0, i = Math.max(Math.floor(r - 1) / 2, 1), c = t.size > 0 ? Math.floor(o / t.size) + 1 : 1, a = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (b) => b >= c - i && b <= c + i, s = o + 1, u = Math.min(o + t.total, t.total), l = {
|
|
68
|
+
from: o,
|
|
69
|
+
page: c,
|
|
70
70
|
current: !0
|
|
71
|
-
}, f = (
|
|
72
|
-
from: (
|
|
73
|
-
page:
|
|
74
|
-
current:
|
|
75
|
-
}),
|
|
76
|
-
return !
|
|
77
|
-
totalPages:
|
|
78
|
-
resultsFrom:
|
|
71
|
+
}, f = (b) => ({
|
|
72
|
+
from: (b - 1) * t.size,
|
|
73
|
+
page: b,
|
|
74
|
+
current: b === c
|
|
75
|
+
}), h = c > 1 ? f(c - 1) : void 0, g = c < a ? f(c + 1) : void 0, m = c - i - 1 > 1 ? f(1) : void 0, y = c + i + 1 < a ? f(a) : void 0, w = C(1, a + 1).filter(d).map(f);
|
|
76
|
+
return !m && w[0]?.page === 2 && w.unshift(f(1)), !y && w[w.length - 1]?.page === a - 1 && w.push(f(a)), {
|
|
77
|
+
totalPages: a,
|
|
78
|
+
resultsFrom: s,
|
|
79
79
|
resultsTo: u,
|
|
80
|
-
current:
|
|
81
|
-
prev:
|
|
82
|
-
next:
|
|
83
|
-
first:
|
|
84
|
-
last:
|
|
85
|
-
pages:
|
|
80
|
+
current: l,
|
|
81
|
+
prev: h,
|
|
82
|
+
next: g,
|
|
83
|
+
first: m,
|
|
84
|
+
last: y,
|
|
85
|
+
pages: w
|
|
86
86
|
};
|
|
87
87
|
}, [n, t, e?.width]);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
const [e, n] =
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
const { products:
|
|
94
|
-
n(
|
|
89
|
+
function de() {
|
|
90
|
+
const [e, n] = F([]), [t, o] = F([]);
|
|
91
|
+
return T(() => {
|
|
92
|
+
z(async (r) => {
|
|
93
|
+
const { products: i, segments: c } = await r.getSearchSessionParams();
|
|
94
|
+
n(c ?? []), o(i?.personalizationBoost ?? []);
|
|
95
95
|
});
|
|
96
96
|
}, []), {
|
|
97
97
|
segments: e,
|
|
98
98
|
boost: t
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
const { facets: e } = v((
|
|
103
|
-
facets:
|
|
104
|
-
})), { replaceFilter: n, toggleProductFilter: t } = x(),
|
|
105
|
-
(
|
|
106
|
-
const u = e?.find((
|
|
101
|
+
function j() {
|
|
102
|
+
const { facets: e } = v((s) => ({
|
|
103
|
+
facets: s.response.products?.facets ?? []
|
|
104
|
+
})), { replaceFilter: n, toggleProductFilter: t } = x(), o = p(
|
|
105
|
+
(s) => {
|
|
106
|
+
const u = e?.find((l) => l.type === "stats" && l.field === s);
|
|
107
107
|
if (u && "min" in u && "max" in u)
|
|
108
108
|
return u;
|
|
109
109
|
},
|
|
110
110
|
[e]
|
|
111
|
-
), r =
|
|
112
|
-
(
|
|
111
|
+
), r = p(
|
|
112
|
+
(s) => e?.find((u) => u.field === s)?.name ?? s,
|
|
113
113
|
[e]
|
|
114
|
-
),
|
|
115
|
-
...
|
|
116
|
-
range:
|
|
114
|
+
), i = p((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), c = p((s) => ({
|
|
115
|
+
...s,
|
|
116
|
+
range: s.range?.map((u) => ({
|
|
117
117
|
gt: u.gt ? Number(u.gt) : u.gt,
|
|
118
118
|
gte: u.gte ? Number(u.gte) : u.gte,
|
|
119
119
|
lt: u.lt ? Number(u.lt) : u.lt,
|
|
120
120
|
lte: u.lte ? Number(u.lte) : u.lte
|
|
121
121
|
}))
|
|
122
|
-
}), []),
|
|
123
|
-
(
|
|
124
|
-
value:
|
|
125
|
-
field:
|
|
126
|
-
name: r(
|
|
127
|
-
filter:
|
|
122
|
+
}), []), a = p(
|
|
123
|
+
(s) => (s.value ?? []).map((l) => ({
|
|
124
|
+
value: l,
|
|
125
|
+
field: s.field,
|
|
126
|
+
name: r(s.field),
|
|
127
|
+
filter: c(s),
|
|
128
128
|
remove: () => {
|
|
129
|
-
t(
|
|
129
|
+
t(s.field, l, !1);
|
|
130
130
|
}
|
|
131
131
|
})),
|
|
132
|
-
[
|
|
133
|
-
), d =
|
|
134
|
-
(
|
|
135
|
-
const f =
|
|
136
|
-
if (f !== void 0 &&
|
|
132
|
+
[c, r, t]
|
|
133
|
+
), d = p(
|
|
134
|
+
(s) => (s.range ?? []).map((l) => {
|
|
135
|
+
const f = l.gte ?? l.gt ?? o(s.field)?.min, h = l.lte ?? l.lt ?? o(s.field)?.max;
|
|
136
|
+
if (f !== void 0 && h !== void 0)
|
|
137
137
|
return {
|
|
138
|
-
value: `${f} - ${
|
|
139
|
-
field:
|
|
140
|
-
name: r(
|
|
141
|
-
filter:
|
|
138
|
+
value: `${f} - ${h}`,
|
|
139
|
+
field: s.field,
|
|
140
|
+
name: r(s.field),
|
|
141
|
+
filter: c(s),
|
|
142
142
|
remove: () => {
|
|
143
|
-
n(
|
|
143
|
+
n(s.field, void 0);
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
}).filter(Boolean),
|
|
147
|
-
[
|
|
147
|
+
[c, o, r, n]
|
|
148
148
|
);
|
|
149
149
|
return {
|
|
150
|
-
selectFilters:
|
|
151
|
-
toValueFilter:
|
|
150
|
+
selectFilters: i,
|
|
151
|
+
toValueFilter: a,
|
|
152
152
|
toRangeFilter: d
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
const { filter: e } = v((
|
|
157
|
-
filter:
|
|
158
|
-
})), { updateSearch: n } = x(), { selectFilters: t, toValueFilter:
|
|
155
|
+
function q() {
|
|
156
|
+
const { filter: e } = v((a) => ({
|
|
157
|
+
filter: a.query.products?.filter ?? []
|
|
158
|
+
})), { updateSearch: n } = x(), { selectFilters: t, toValueFilter: o, toRangeFilter: r } = j(), i = S(() => e ? e.filter(t).flatMap((a) => "value" in a ? o(a) : "range" in a ? r(a) : []).filter(Boolean) : [], [e, t, r, o]), c = p(() => {
|
|
159
159
|
n({
|
|
160
160
|
products: {
|
|
161
161
|
filter: []
|
|
162
162
|
}
|
|
163
|
-
}),
|
|
163
|
+
}), O({
|
|
164
164
|
event: "events/removeAllFilters",
|
|
165
165
|
params: null
|
|
166
166
|
});
|
|
167
167
|
}, [n]);
|
|
168
168
|
return {
|
|
169
169
|
/** Selected filters array. */
|
|
170
|
-
filters:
|
|
170
|
+
filters: i,
|
|
171
171
|
/** Should remove all selected filters. */
|
|
172
|
-
removeAll:
|
|
172
|
+
removeAll: c
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
function E(e) {
|
|
176
|
-
const { replaceFilter: n } = x(), { query: t, products:
|
|
177
|
-
query:
|
|
178
|
-
products:
|
|
179
|
-
})), r =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
lte: p.toString()
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
return {
|
|
176
|
+
const { replaceFilter: n } = x(), { query: t, products: o } = v((g) => ({
|
|
177
|
+
query: g.query,
|
|
178
|
+
products: g.response.products
|
|
179
|
+
})), r = o?.facets?.find((g) => g.id === e), i = t.products?.filter?.find((g) => g.field === r?.field), c = V(i), a = r && "min" in r ? Math.floor(r.min ?? 0) : 0, d = r && "max" in r ? Math.ceil(r.max ?? 0) : 0, s = c[0] !== void 0 || c[1] !== void 0, [u, l] = F(s), f = p(() => {
|
|
180
|
+
l((g) => !g);
|
|
181
|
+
}, []), h = p(
|
|
182
|
+
([g, m]) => {
|
|
183
|
+
if (!r)
|
|
184
|
+
return;
|
|
185
|
+
const y = D(g, m, a, d);
|
|
186
|
+
n(r.field, y);
|
|
187
|
+
},
|
|
188
|
+
[a, d, n, r]
|
|
189
|
+
);
|
|
190
|
+
return N({
|
|
191
|
+
event: "events/removeAllFilters",
|
|
192
|
+
callback: () => {
|
|
193
|
+
l(!1);
|
|
194
|
+
}
|
|
195
|
+
}), r ? {
|
|
200
196
|
/** Min value */
|
|
201
|
-
min:
|
|
197
|
+
min: a,
|
|
202
198
|
/** Max value */
|
|
203
|
-
max:
|
|
199
|
+
max: d,
|
|
204
200
|
/** Range value */
|
|
205
|
-
range: [
|
|
201
|
+
range: [c[0] ?? a, c[1] ?? d],
|
|
206
202
|
/** Update range function */
|
|
207
|
-
updateRange:
|
|
203
|
+
updateRange: h,
|
|
204
|
+
/** Is the range filter active */
|
|
205
|
+
active: u,
|
|
206
|
+
/** Toggle active state function */
|
|
207
|
+
toggleActive: f
|
|
208
|
+
} : {
|
|
209
|
+
min: 0,
|
|
210
|
+
max: 0,
|
|
211
|
+
range: [0, 0],
|
|
212
|
+
active: !1,
|
|
213
|
+
toggleActive: () => {
|
|
214
|
+
},
|
|
215
|
+
updateRange: () => {
|
|
216
|
+
}
|
|
208
217
|
};
|
|
209
218
|
}
|
|
210
|
-
function
|
|
211
|
-
const
|
|
212
|
-
|
|
219
|
+
function V(e) {
|
|
220
|
+
const n = e?.range?.[0];
|
|
221
|
+
return typeof n == "object" && ("gte" in n || "lte" in n) ? [A(n.gte), A(n.lte)] : [void 0, void 0];
|
|
222
|
+
}
|
|
223
|
+
function D(e, n, t, o) {
|
|
224
|
+
const r = e !== void 0 ? Math.floor(e) : void 0, i = n !== void 0 ? Math.ceil(n) : void 0, c = r !== void 0, a = i !== void 0;
|
|
225
|
+
if ((t === r || !c) && (o === i || !a))
|
|
226
|
+
return;
|
|
227
|
+
const d = {};
|
|
228
|
+
return c && r !== t && (d.gte = r.toString()), a && i !== o && (d.lte = i.toString()), Object.keys(d).length > 0 ? d : void 0;
|
|
229
|
+
}
|
|
230
|
+
function fe(e, n) {
|
|
231
|
+
const { min: t, max: o, range: r, updateRange: i } = E(e), { filters: c } = q(), a = S(() => {
|
|
232
|
+
const l = c.find((m) => m?.filter?.range);
|
|
213
233
|
let f = null;
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
f = [
|
|
234
|
+
if (l) {
|
|
235
|
+
const m = l.filter.range?.[0];
|
|
236
|
+
f = [A(m?.gte), A(m?.lte)];
|
|
217
237
|
}
|
|
218
|
-
const
|
|
219
|
-
let
|
|
220
|
-
for (;
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
min:
|
|
224
|
-
max:
|
|
225
|
-
selected:
|
|
226
|
-
}),
|
|
238
|
+
const h = [];
|
|
239
|
+
let g = Math.floor(t / n) * n;
|
|
240
|
+
for (; g < o; ) {
|
|
241
|
+
const m = g + n, y = f && f[0] === g && f[1] === m;
|
|
242
|
+
h.push({
|
|
243
|
+
min: g,
|
|
244
|
+
max: m,
|
|
245
|
+
selected: y
|
|
246
|
+
}), g = m;
|
|
227
247
|
}
|
|
228
|
-
return
|
|
229
|
-
}, [
|
|
230
|
-
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
}, u = t !== r[0] ||
|
|
248
|
+
return h;
|
|
249
|
+
}, [c, t, o, n]), d = (l) => {
|
|
250
|
+
i([l, r[1]]);
|
|
251
|
+
}, s = (l) => {
|
|
252
|
+
i([r[0], l]);
|
|
253
|
+
}, u = t !== r[0] || o !== r[1];
|
|
234
254
|
return {
|
|
235
255
|
/** Minimum value */
|
|
236
256
|
min: t,
|
|
237
257
|
/** Maximum value */
|
|
238
|
-
max:
|
|
258
|
+
max: o,
|
|
239
259
|
/** Range value */
|
|
240
260
|
range: r,
|
|
241
261
|
/** Update range function */
|
|
242
|
-
updateRange:
|
|
262
|
+
updateRange: i,
|
|
243
263
|
/** Ranges */
|
|
244
|
-
ranges:
|
|
264
|
+
ranges: a,
|
|
245
265
|
/** Handle min change */
|
|
246
266
|
handleMinChange: d,
|
|
247
267
|
/** Handle max change */
|
|
248
|
-
handleMaxChange:
|
|
268
|
+
handleMaxChange: s,
|
|
249
269
|
/** Is selected */
|
|
250
270
|
isSelected: u
|
|
251
271
|
};
|
|
252
272
|
}
|
|
253
|
-
function
|
|
273
|
+
function ge() {
|
|
254
274
|
const { products: e, keywords: n } = v((t) => t.response);
|
|
255
275
|
return {
|
|
256
276
|
/** Array of products */
|
|
@@ -259,18 +279,18 @@ function de() {
|
|
|
259
279
|
keywords: n ?? { hits: [], total: 0 }
|
|
260
280
|
};
|
|
261
281
|
}
|
|
262
|
-
function
|
|
282
|
+
function pe() {
|
|
263
283
|
const e = v((t) => t.query.products?.filter);
|
|
264
|
-
return
|
|
284
|
+
return S(() => e ? e.reduce((t, o) => t + (Array.isArray(o.value) ? o.value.length : 1), 0) : 0, [e]);
|
|
265
285
|
}
|
|
266
|
-
const
|
|
267
|
-
function
|
|
268
|
-
const [n, t] =
|
|
286
|
+
const $ = 5 * 60 * 1e3, L = /* @__PURE__ */ new Map();
|
|
287
|
+
function me(e) {
|
|
288
|
+
const [n, t] = F({
|
|
269
289
|
product: null,
|
|
270
290
|
loading: !0,
|
|
271
291
|
error: null
|
|
272
292
|
});
|
|
273
|
-
return
|
|
293
|
+
return T(() => {
|
|
274
294
|
if (!e) {
|
|
275
295
|
t({
|
|
276
296
|
product: null,
|
|
@@ -284,17 +304,17 @@ function ge(e) {
|
|
|
284
304
|
loading: !0,
|
|
285
305
|
error: null
|
|
286
306
|
}));
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
307
|
+
const o = U(e);
|
|
308
|
+
if (o) {
|
|
289
309
|
t({
|
|
290
|
-
product:
|
|
310
|
+
product: o,
|
|
291
311
|
loading: !1,
|
|
292
312
|
error: null
|
|
293
313
|
});
|
|
294
314
|
return;
|
|
295
315
|
}
|
|
296
|
-
|
|
297
|
-
|
|
316
|
+
B(e).then((r) => {
|
|
317
|
+
_(e, r), t({
|
|
298
318
|
product: r,
|
|
299
319
|
loading: !1,
|
|
300
320
|
error: null
|
|
@@ -308,76 +328,76 @@ function ge(e) {
|
|
|
308
328
|
});
|
|
309
329
|
}, [e]), n;
|
|
310
330
|
}
|
|
311
|
-
async function
|
|
331
|
+
async function B(e) {
|
|
312
332
|
const n = await fetch(`/products/${e}.js`);
|
|
313
333
|
if (!n.ok)
|
|
314
334
|
throw new Error(`Failed to fetch product: ${n.status} ${n.statusText}`);
|
|
315
335
|
return n.json();
|
|
316
336
|
}
|
|
317
|
-
function
|
|
318
|
-
const n =
|
|
319
|
-
return n ? Date.now() - n.created >
|
|
337
|
+
function U(e) {
|
|
338
|
+
const n = L.get(e);
|
|
339
|
+
return n ? Date.now() - n.created > $ ? (L.delete(e), null) : n.product : null;
|
|
320
340
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
341
|
+
function _(e, n) {
|
|
342
|
+
L.set(e, {
|
|
323
343
|
product: n,
|
|
324
344
|
created: Date.now()
|
|
325
345
|
});
|
|
326
346
|
}
|
|
327
|
-
function
|
|
347
|
+
function R(e) {
|
|
328
348
|
return e && !Number.isNaN(e) ? e : 0;
|
|
329
349
|
}
|
|
330
|
-
function
|
|
331
|
-
const { from: t, size:
|
|
332
|
-
from:
|
|
333
|
-
size:
|
|
334
|
-
total:
|
|
335
|
-
})), { updateSearch:
|
|
336
|
-
(
|
|
337
|
-
|
|
350
|
+
function he(e, n) {
|
|
351
|
+
const { from: t, size: o, total: r } = v((s) => ({
|
|
352
|
+
from: R(s.query.products?.from ?? 0),
|
|
353
|
+
size: R(s.response?.products?.size ?? n),
|
|
354
|
+
total: R(s.response?.products?.total ?? 0)
|
|
355
|
+
})), { updateSearch: i } = x(), c = t + o, a = S(() => [...e].reverse().filter((s) => s < r), [e, r]), d = p(
|
|
356
|
+
(s) => {
|
|
357
|
+
i({
|
|
338
358
|
products: {
|
|
339
|
-
size:
|
|
359
|
+
size: A(s)
|
|
340
360
|
}
|
|
341
361
|
});
|
|
342
362
|
},
|
|
343
|
-
[
|
|
363
|
+
[i]
|
|
344
364
|
);
|
|
345
365
|
return {
|
|
346
366
|
/** from value */
|
|
347
367
|
from: t,
|
|
348
368
|
/** to value */
|
|
349
|
-
to:
|
|
369
|
+
to: c,
|
|
350
370
|
/** total value */
|
|
351
371
|
total: r,
|
|
352
372
|
/** size value */
|
|
353
|
-
size:
|
|
373
|
+
size: o,
|
|
354
374
|
/** Array of size options */
|
|
355
|
-
sizeOptions:
|
|
375
|
+
sizeOptions: a,
|
|
356
376
|
/** Should be called when size is changed */
|
|
357
377
|
handleSizeChange: d
|
|
358
378
|
};
|
|
359
379
|
}
|
|
360
|
-
function
|
|
361
|
-
return e.length !== n.length ? !1 : e.every((t) => n.find((
|
|
380
|
+
function I(e, n) {
|
|
381
|
+
return e.length !== n.length ? !1 : e.every((t) => n.find((o) => t.field === o.field && t.order === o.order));
|
|
362
382
|
}
|
|
363
|
-
function
|
|
364
|
-
const n = v((
|
|
383
|
+
function ve(e) {
|
|
384
|
+
const n = v((i) => i.query), { updateSearch: t } = x();
|
|
365
385
|
return {
|
|
366
386
|
/** Active sort */
|
|
367
|
-
activeSort: e.find((
|
|
387
|
+
activeSort: e.find((i) => I(i.value.sort, n.products?.sort || []))?.id ?? e[0]?.id,
|
|
368
388
|
/** Set sort function */
|
|
369
|
-
setSort: (
|
|
370
|
-
const
|
|
371
|
-
|
|
389
|
+
setSort: (i) => {
|
|
390
|
+
const c = e.find((a) => a.id === i);
|
|
391
|
+
c && t({
|
|
372
392
|
products: {
|
|
373
|
-
sort:
|
|
393
|
+
sort: c.value.sort
|
|
374
394
|
}
|
|
375
395
|
});
|
|
376
396
|
}
|
|
377
397
|
};
|
|
378
398
|
}
|
|
379
|
-
const
|
|
380
|
-
function
|
|
399
|
+
const M = window.SpeechRecognition || window.webkitSpeechRecognition, H = !!(M && typeof M == "function");
|
|
400
|
+
function Z() {
|
|
381
401
|
return {
|
|
382
402
|
listening: !1,
|
|
383
403
|
startListening: () => {
|
|
@@ -386,106 +406,106 @@ function I() {
|
|
|
386
406
|
}
|
|
387
407
|
};
|
|
388
408
|
}
|
|
389
|
-
function
|
|
409
|
+
function G({
|
|
390
410
|
language: e = "en-US",
|
|
391
411
|
interimResults: n = !1,
|
|
392
412
|
onResult: t,
|
|
393
|
-
onError:
|
|
413
|
+
onError: o
|
|
394
414
|
} = {}) {
|
|
395
|
-
const [r,
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
const { transcript:
|
|
399
|
-
t(
|
|
400
|
-
}),
|
|
401
|
-
}, [e, n,
|
|
402
|
-
|
|
403
|
-
}, [
|
|
415
|
+
const [r, i] = F(!1), c = k(null), a = p(() => {
|
|
416
|
+
const s = new M();
|
|
417
|
+
s.lang = e, s.interimResults = n, s.onstart = () => i(!0), t && (s.onresult = (u) => {
|
|
418
|
+
const { transcript: l } = u.results?.[0]?.[0];
|
|
419
|
+
t(l);
|
|
420
|
+
}), o && (s.onerror = (u) => o(u.error)), s.onend = () => i(!1), c.current = s, s.start();
|
|
421
|
+
}, [e, n, o, t]), d = p(() => {
|
|
422
|
+
c.current?.stop();
|
|
423
|
+
}, [c]);
|
|
404
424
|
return {
|
|
405
425
|
listening: r,
|
|
406
|
-
startListening:
|
|
426
|
+
startListening: a,
|
|
407
427
|
stopListening: d
|
|
408
428
|
};
|
|
409
429
|
}
|
|
410
|
-
const
|
|
411
|
-
function
|
|
430
|
+
const Se = H ? G : Z;
|
|
431
|
+
function J(e, n) {
|
|
412
432
|
if (!e.length || !n.length) return [];
|
|
413
|
-
const t = n.reduce((
|
|
414
|
-
return e.forEach((
|
|
415
|
-
|
|
416
|
-
const
|
|
417
|
-
n.includes(
|
|
433
|
+
const t = n.reduce((o, r) => (o[r] = {}, o), {});
|
|
434
|
+
return e.forEach((o) => {
|
|
435
|
+
o.customFields?.forEach(({ key: r, value: i }) => {
|
|
436
|
+
const c = r.toLowerCase();
|
|
437
|
+
n.includes(c) && (t[c][i] = t[c][i] || [], t[c][i].push(o));
|
|
418
438
|
});
|
|
419
|
-
}), Object.entries(t).filter((
|
|
420
|
-
field:
|
|
421
|
-
options: Object.entries(r).map(([
|
|
422
|
-
value:
|
|
423
|
-
skus:
|
|
439
|
+
}), Object.entries(t).filter((o) => Object.keys(o[1]).length).map(([o, r]) => ({
|
|
440
|
+
field: o,
|
|
441
|
+
options: Object.entries(r).map(([i, c]) => ({
|
|
442
|
+
value: i,
|
|
443
|
+
skus: c,
|
|
424
444
|
unavailable: !1,
|
|
425
445
|
selected: !1
|
|
426
446
|
}))
|
|
427
447
|
}));
|
|
428
448
|
}
|
|
429
|
-
function
|
|
430
|
-
return e.length ? e.map(({ field: t, options:
|
|
449
|
+
function K(e, n) {
|
|
450
|
+
return e.length ? e.map(({ field: t, options: o }) => ({
|
|
431
451
|
field: t,
|
|
432
|
-
options:
|
|
433
|
-
const
|
|
452
|
+
options: o.map((r) => {
|
|
453
|
+
const i = !r.skus?.some((a) => Object.entries(n).every(([d, s]) => d === t ? !0 : a.customFields?.find((l) => l.key.toLowerCase() === d)?.value === s)), c = n[t] === r.value;
|
|
434
454
|
return {
|
|
435
455
|
...r,
|
|
436
|
-
unavailable:
|
|
437
|
-
selected:
|
|
456
|
+
unavailable: i,
|
|
457
|
+
selected: c
|
|
438
458
|
};
|
|
439
459
|
})
|
|
440
460
|
})) : [];
|
|
441
461
|
}
|
|
442
462
|
const P = ["4XS", "3XS", "2XS", "XXS", "XS", "S", "M", "L", "XL", "XXL", "2XL", "XXXL", "3XL", "4XL"];
|
|
443
|
-
function
|
|
463
|
+
function Q(e) {
|
|
444
464
|
if (P.includes(e))
|
|
445
465
|
return 1e3 + P.indexOf(e);
|
|
446
466
|
const n = parseFloat(e);
|
|
447
467
|
return isNaN(n) ? e : n;
|
|
448
468
|
}
|
|
449
|
-
function
|
|
450
|
-
return [...n].sort((t,
|
|
451
|
-
const [r,
|
|
452
|
-
return r <
|
|
469
|
+
function W(e, n) {
|
|
470
|
+
return [...n].sort((t, o) => {
|
|
471
|
+
const [r, i] = [t.value, o.value].map(Q);
|
|
472
|
+
return r < i ? -1 : 1;
|
|
453
473
|
});
|
|
454
474
|
}
|
|
455
|
-
function
|
|
456
|
-
const [t,
|
|
457
|
-
field:
|
|
458
|
-
options:
|
|
459
|
-
})), [e, n]),
|
|
460
|
-
|
|
461
|
-
const
|
|
462
|
-
return
|
|
475
|
+
function Fe(e = [], n = []) {
|
|
476
|
+
const [t, o] = F({}), r = S(() => J(e, n).map(({ field: s, options: u }) => ({
|
|
477
|
+
field: s,
|
|
478
|
+
options: W(s, u)
|
|
479
|
+
})), [e, n]), i = S(() => K(r, t), [r, t]), c = p((d, s) => {
|
|
480
|
+
o((u) => {
|
|
481
|
+
const l = { ...u };
|
|
482
|
+
return l[d] === s ? delete l[d] : l[d] = s, l;
|
|
463
483
|
});
|
|
464
|
-
}, []),
|
|
484
|
+
}, []), a = S(() => Object.keys(t).filter((u) => t[u]).length === 0 ? [] : i.filter(({ field: u }) => t[u]).map(({ field: u, options: l }) => {
|
|
465
485
|
const f = t[u];
|
|
466
|
-
return
|
|
467
|
-
}).reduce((u,
|
|
468
|
-
return { swatches:
|
|
486
|
+
return l.find((g) => g.value === f)?.skus ?? [];
|
|
487
|
+
}).reduce((u, l) => u.filter((f) => l.includes(f))), [i, t]);
|
|
488
|
+
return { swatches: i, toggleOption: c, matchedSkus: a };
|
|
469
489
|
}
|
|
470
490
|
export {
|
|
471
|
-
|
|
491
|
+
H as speechToTextSupported,
|
|
472
492
|
x as useActions,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
493
|
+
ie as useDecoratedSearchResults,
|
|
494
|
+
ue as useFacet,
|
|
495
|
+
ae as useFacets,
|
|
496
|
+
Ae as useHistory,
|
|
497
|
+
be as useLoadMore,
|
|
478
498
|
v as useNostoAppState,
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
499
|
+
le as usePagination,
|
|
500
|
+
de as usePersonalization,
|
|
501
|
+
q as useProductFilters,
|
|
482
502
|
E as useRange,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
503
|
+
fe as useRangeSelector,
|
|
504
|
+
ge as useResponse,
|
|
505
|
+
pe as useSelectedFiltersCount,
|
|
506
|
+
me as useShopifyProduct,
|
|
507
|
+
he as useSizeOptions,
|
|
508
|
+
ve as useSort,
|
|
509
|
+
Se as useSpeechToText,
|
|
510
|
+
Fe as useSwatches
|
|
491
511
|
};
|
|
@@ -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 {};
|