@nosto/search-js 3.12.0 → 3.13.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/{AutocompletePageProvider-kQ8RqtRT.cjs → AutocompletePageProvider-99syi-nl.cjs} +1 -1
- package/dist/{AutocompletePageProvider-BoVX16FG.js → AutocompletePageProvider-HeGU8tjH.js} +2 -2
- package/dist/{CategoryPageProvider-DrDTw4gs.js → CategoryPageProvider-Bou8i9Tx.js} +2 -2
- package/dist/{CategoryPageProvider-DwqxtD8L.cjs → CategoryPageProvider-Clj40F3F.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-Da3akCS0.js → InfiniteScrollWithObserver-6A57AOKr.js} +1 -1
- package/dist/{InfiniteScrollWithObserver-BlsPDXH_.cjs → InfiniteScrollWithObserver-CoPOQr8Q.cjs} +1 -1
- package/dist/{SerpPageProvider-qRhpKBXS.js → SerpPageProvider-B-W6nCqu.js} +2 -2
- package/dist/{SerpPageProvider-NSsaKQ7f.cjs → SerpPageProvider-pR-E8S6m.cjs} +1 -1
- package/dist/{baseConfig-DKaOLPtn.cjs → baseConfig-CoxOyC7r.cjs} +1 -1
- package/dist/{baseConfig-DV2JVKBc.js → baseConfig-DzkbWglo.js} +3 -3
- 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.d.ts +1 -0
- package/dist/preact/common/common.es.js +26 -22
- package/dist/preact/hooks/hooks.cjs.js +1 -1
- package/dist/preact/hooks/hooks.es.js +3 -3
- 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 +3 -3
- package/dist/useActions-CJ71kc2N.cjs +1 -0
- package/dist/useActions-SEyBHGra.js +260 -0
- package/dist/{useLoadMore-PtSHiAZq.cjs → useLoadMore-B0JgcUfM.cjs} +1 -1
- package/dist/{useLoadMore-BZ5wWCPk.js → useLoadMore-hrNp8P0M.js} +3 -3
- package/package.json +5 -5
- package/dist/useActions-BFZx84-K.js +0 -239
- package/dist/useActions-DSWNCNrI.cjs +0 -1
package/dist/{AutocompletePageProvider-kQ8RqtRT.cjs → AutocompletePageProvider-99syi-nl.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),o=require("./useActions-
|
|
1
|
+
"use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),o=require("./useActions-CJ71kc2N.cjs"),n=require("./baseConfig-CoxOyC7r.cjs"),a={...n.defaultBaseConfig,memoryCache:!1,historyEnabled:!0,historySize:5,debounceDelay:500,minQueryLength:2};function r(e={}){return{pageType:"autocomplete",...a,...e}}function l({config:e,store:u,children:i}){const c=u??o.createStore();return n.useCheckClientScript(),t.u(o.ConfigContext,{value:r(e),children:t.u(o.StoreContext,{value:c,children:[t.u(n.StoreActionsListener,{}),i]})})}exports.AutocompletePageProvider=l;exports.makeAutocompleteConfig=r;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as i, C as u } from "./useActions-
|
|
3
|
-
import { d as c, u as s, S as l } from "./baseConfig-
|
|
2
|
+
import { c as n, S as i, C as u } from "./useActions-SEyBHGra.js";
|
|
3
|
+
import { d as c, u as s, S as l } from "./baseConfig-DzkbWglo.js";
|
|
4
4
|
const m = {
|
|
5
5
|
...c,
|
|
6
6
|
memoryCache: !1,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as s, C as i } from "./useActions-
|
|
3
|
-
import { d as c, u as C, S as f } from "./baseConfig-
|
|
2
|
+
import { c as n, S as s, C as i } from "./useActions-SEyBHGra.js";
|
|
3
|
+
import { d as c, u as C, S as f } from "./baseConfig-DzkbWglo.js";
|
|
4
4
|
const l = {
|
|
5
5
|
...c,
|
|
6
6
|
persistentSearchCache: !1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-
|
|
1
|
+
"use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-CJ71kc2N.cjs"),o=require("./baseConfig-CoxOyC7r.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;
|
package/dist/{InfiniteScrollWithObserver-Da3akCS0.js → InfiniteScrollWithObserver-6A57AOKr.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as y } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { a as x, u as U } from "./useLoadMore-
|
|
2
|
+
import { a as x, u as U } from "./useLoadMore-hrNp8P0M.js";
|
|
3
3
|
import { i as I } from "./logger-_fg_Za9y.js";
|
|
4
4
|
import { p as A } from "./pick-DReBictn.js";
|
|
5
5
|
import { Component as c, options as l, createElement as v, Fragment as d, toChildArray as h } from "preact";
|
package/dist/{InfiniteScrollWithObserver-BlsPDXH_.cjs → InfiniteScrollWithObserver-CoPOQr8Q.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const v=require("./jsxRuntime.module-B3sGoTIU.cjs"),d=require("./useLoadMore-
|
|
1
|
+
"use strict";const v=require("./jsxRuntime.module-B3sGoTIU.cjs"),d=require("./useLoadMore-B0JgcUfM.cjs"),N=require("./logger-Boh_C6Bz.cjs"),x=require("./pick-rYi1lc2m.cjs"),u=require("preact"),h=require("preact/hooks");function E(e,r){const t=r.products?.total??0,o=e.products?.from??0,n=e.products?.size??0;return t>0&&t>o+n}function A(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function M(e,r){for(var t in r)e[t]=r[t];return e}function f(e,r){for(var t in e)if(t!=="__source"&&!(t in r))return!0;for(var o in r)if(o!=="__source"&&e[o]!==r[o])return!0;return!1}function m(e,r){this.props=e,this.context=r}function U(e,r){function t(n){var s=this.props.ref,i=s==n.ref;return!i&&s&&(s.call?s(null):s.current=null),r?!r(this.props,n)||!i:f(this.props,n)}function o(n){return this.shouldComponentUpdate=t,u.createElement(e,n)}return o.displayName="Memo("+(e.displayName||e.name)+")",o.prototype.isReactComponent=!0,o.__f=!0,o}(m.prototype=new u.Component).isPureReactComponent=!0,m.prototype.shouldComponentUpdate=function(e,r){return f(this.props,e)||f(this.state,r)};var y=u.options.__b;u.options.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),y&&y(e)};var q=u.options.__e;u.options.__e=function(e,r,t,o){if(e.then){for(var n,s=r;s=s.__;)if((n=s.__c)&&n.__c)return r.__e==null&&(r.__e=t.__e,r.__k=t.__k),n.__c(e,r)}q(e,r,t,o)};var b=u.options.unmount;function P(e,r,t){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(o){typeof o.__c=="function"&&o.__c()}),e.__c.__H=null),(e=M({},e)).__c!=null&&(e.__c.__P===t&&(e.__c.__P=r),e.__c=null),e.__k=e.__k&&e.__k.map(function(o){return P(o,r,t)})),e}function R(e,r,t){return e&&t&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(o){return R(o,r,t)}),e.__c&&e.__c.__P===r&&(e.__e&&t.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=t)),e}function p(){this.__u=0,this.o=null,this.__b=null}function S(e){var r=e.__.__c;return r&&r.__a&&r.__a(e)}function c(){this.i=null,this.l=null}u.options.unmount=function(e){var r=e.__c;r&&r.__R&&r.__R(),r&&32&e.__u&&(e.type=null),b&&b(e)},(p.prototype=new u.Component).__c=function(e,r){var t=r.__c,o=this;o.o==null&&(o.o=[]),o.o.push(t);var n=S(o.__v),s=!1,i=function(){s||(s=!0,t.__R=null,n?n(_):_())};t.__R=i;var _=function(){if(!--o.__u){if(o.state.__a){var l=o.state.__a;o.__v.__k[0]=R(l,l.__c.__P,l.__c.__O)}var a;for(o.setState({__a:o.__b=null});a=o.o.pop();)a.forceUpdate()}};o.__u++||32&r.__u||o.setState({__a:o.__b=o.__v.__k[0]}),e.then(i,i)},p.prototype.componentWillUnmount=function(){this.o=[]},p.prototype.render=function(e,r){if(this.__b){if(this.__v.__k){var t=document.createElement("div"),o=this.__v.__k[0].__c;this.__v.__k[0]=P(this.__b,t,o.__O=o.__P)}this.__b=null}var n=r.__a&&u.createElement(u.Fragment,null,e.fallback);return n&&(n.__u&=-33),[u.createElement(u.Fragment,null,r.__a?null:e.children),n]};var g=function(e,r,t){if(++t[1]===t[0]&&e.l.delete(r),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(t=e.i;t;){for(;t.length>3;)t.pop()();if(t[1]<t[0])break;e.i=t=t[2]}};(c.prototype=new u.Component).__a=function(e){var r=this,t=S(r.__v),o=r.l.get(e);return o[0]++,function(n){var s=function(){r.props.revealOrder?(o.push(n),g(r,e,o)):n()};t?t(s):s()}},c.prototype.render=function(e){this.i=null,this.l=new Map;var r=u.toChildArray(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&r.reverse();for(var t=r.length;t--;)this.l.set(r[t],this.i=[1,0,this.i]);return e.children},c.prototype.componentDidUpdate=c.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(r,t){g(e,t,r)})};var I=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,W=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,V=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,j=/[A-Z0-9]/g,F=typeof document<"u",H=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};u.Component.prototype.isReactComponent={},["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(u.Component.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(r){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:r})}})});var k=u.options.event;function L(){}function z(){return this.cancelBubble}function B(){return this.defaultPrevented}u.options.event=function(e){return k&&(e=k(e)),e.persist=L,e.isPropagationStopped=z,e.isDefaultPrevented=B,e.nativeEvent=e};var D={enumerable:!1,configurable:!0,get:function(){return this.class}},O=u.options.vnode;u.options.vnode=function(e){typeof e.type=="string"&&function(r){var t=r.props,o=r.type,n={},s=o.indexOf("-")===-1;for(var i in t){var _=t[i];if(!(i==="value"&&"defaultValue"in t&&_==null||F&&i==="children"&&o==="noscript"||i==="class"||i==="className")){var l=i.toLowerCase();i==="defaultValue"&&"value"in t&&t.value==null?i="value":i==="download"&&_===!0?_="":l==="translate"&&_==="no"?_=!1:l[0]==="o"&&l[1]==="n"?l==="ondoubleclick"?i="ondblclick":l!=="onchange"||o!=="input"&&o!=="textarea"||H(t.type)?l==="onfocus"?i="onfocusin":l==="onblur"?i="onfocusout":V.test(i)&&(i=l):l=i="oninput":s&&W.test(i)?i=i.replace(j,"-$&").toLowerCase():_===null&&(_=void 0),l==="oninput"&&n[i=l]&&(i="oninputCapture"),n[i]=_}}o=="select"&&n.multiple&&Array.isArray(n.value)&&(n.value=u.toChildArray(t.children).forEach(function(a){a.props.selected=n.value.indexOf(a.props.value)!=-1})),o=="select"&&n.defaultValue!=null&&(n.value=u.toChildArray(t.children).forEach(function(a){a.props.selected=n.multiple?n.defaultValue.indexOf(a.props.value)!=-1:n.defaultValue==a.props.value})),t.class&&!t.className?(n.class=t.class,Object.defineProperty(n,"className",D)):(t.className&&!t.class||t.class&&t.className)&&(n.class=n.className=t.className),r.props=n}(e),e.$$typeof=I,O&&O(e)};var C=u.options.__r;u.options.__r=function(e){C&&C(e),e.__c};var w=u.options.diffed;u.options.diffed=function(e){w&&w(e);var r=e.props,t=e.__e;t!=null&&e.type==="textarea"&&"value"in r&&r.value!==t.value&&(t.value=r.value==null?"":r.value)};function T({children:e,pageSize:r,observerOptions:t}){const o=h.useRef(null),{query:n,response:s}=d.useNostoAppState(_=>x.pick(_,"query","response")),{loadMore:i}=d.useLoadMore(r);return h.useEffect(()=>{let _,l;return E(n,s)&&(_=o.current,l=new IntersectionObserver(a=>{a[0]?.isIntersecting&&i()},t),_&&l.observe(_)),()=>{_&&l.unobserve(_)}},[s]),v.u(u.Fragment,{children:[e,v.u("div",{ref:o,style:{height:"1px"}})]})}const $=U(T,N.isEqual);exports.InfiniteScrollWithObserver=$;exports.hasMoreResults=E;exports.intersectionObserverSupported=A;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as r } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as s, C as c } from "./useActions-
|
|
3
|
-
import { d as i, u as f, S } from "./baseConfig-
|
|
2
|
+
import { c as n, S as s, C as c } from "./useActions-SEyBHGra.js";
|
|
3
|
+
import { d as i, u as f, S } from "./baseConfig-DzkbWglo.js";
|
|
4
4
|
const l = {
|
|
5
5
|
...i,
|
|
6
6
|
persistentSearchCache: !1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=require("./jsxRuntime.module-B3sGoTIU.cjs"),t=require("./useActions-
|
|
1
|
+
"use strict";const r=require("./jsxRuntime.module-B3sGoTIU.cjs"),t=require("./useActions-CJ71kc2N.cjs"),n=require("./baseConfig-CoxOyC7r.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 +1 @@
|
|
|
1
|
-
"use strict";const i=require("./useActions-
|
|
1
|
+
"use strict";const i=require("./useActions-CJ71kc2N.cjs"),r=require("./eventBusSubscribe-oONOUGH8.cjs"),c=require("./index.es-Dp6Iaxz3.cjs"),o=require("./logger-Boh_C6Bz.cjs"),u=require("preact/hooks");function s(){const{pageType:t}=i.useConfig(),n=i.useActions();return r.useEventBusSubscribe({event:"actions/newSearch",callback:e=>{t===e.targetStore&&n.newSearch(e.query,e.options)}}),r.useEventBusSubscribe({event:"actions/updateSearch",callback:e=>{t===e.targetStore&&n.updateSearch(e.query,e.options)}}),r.useEventBusSubscribe({event:"actions/replaceFilter",callback:e=>{t===e.targetStore&&n.replaceFilter(e.field,e.value)}}),r.useEventBusSubscribe({event:"actions/toggleProductFilter",callback:e=>{t===e.targetStore&&n.toggleProductFilter(e.field,e.value,e.active)}}),null}function l(){u.useEffect(()=>{const t=window.setTimeout(()=>{o.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);c.s(()=>{window.clearTimeout(t)})},[])}const a={defaultCurrency:"EUR",queryModifications:t=>t};exports.StoreActionsListener=s;exports.defaultBaseConfig=a;exports.useCheckClientScript=l;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as i,
|
|
1
|
+
import { a as i, h as n } from "./useActions-SEyBHGra.js";
|
|
2
2
|
import { u as r } from "./eventBusSubscribe-CzlS132j.js";
|
|
3
3
|
import { s as c } from "./index.es-XNBESE3P.js";
|
|
4
4
|
import { l as u } from "./logger-_fg_Za9y.js";
|
|
@@ -37,12 +37,12 @@ function v() {
|
|
|
37
37
|
});
|
|
38
38
|
}, []);
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const h = {
|
|
41
41
|
defaultCurrency: "EUR",
|
|
42
42
|
queryModifications: (t) => t
|
|
43
43
|
};
|
|
44
44
|
export {
|
|
45
45
|
S,
|
|
46
|
-
|
|
46
|
+
h as d,
|
|
47
47
|
v as u
|
|
48
48
|
};
|
|
@@ -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-99syi-nl.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-HeGU8tjH.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-Clj40F3F.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 d=require("../../isBot-iyBlT_oq.cjs"),o=require("../../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../../useLoadMore-B0JgcUfM.cjs"),g=require("../../pick-rYi1lc2m.cjs"),n=require("../../InfiniteScrollWithObserver-CoPOQr8Q.cjs"),p=require("preact"),e=require("../../useActions-CJ71kc2N.cjs");function C({pageSize:r}){const{loadMore:t}=s.useLoadMore(r);return o.u("button",{onClick:t,children:"More results"})}function u({children:r,loadMoreComponent:t,pageSize:i}){const{loading:c,query:l,response:a}=s.useNostoAppState(S=>g.pick(S,"loading","query","response")),f=!c&&n.hasMoreResults(l,a);return o.u(p.Fragment,{children:[r,f&&(t?o.u(t,{pageSize:i}):o.u(C,{pageSize:i}))]})}const q=!d.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=e.StoreContext;exports.createExtendableStore=e.createExtendableStore;exports.createStore=e.createStore;exports.defaultState=e.defaultState;exports.useAutocompleteConfig=e.useAutocompleteConfig;exports.useCategoryConfig=e.useCategoryConfig;exports.useConfig=e.useConfig;exports.useSerpConfig=e.useSerpConfig;exports.InfiniteScroll=q;exports.InfiniteScrollWithLink=u;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @module preact/common */
|
|
2
2
|
export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
|
|
3
3
|
export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
|
|
4
|
+
export { useAutocompleteConfig, useCategoryConfig, useConfig, useSerpConfig } from './src/config/configContext';
|
|
4
5
|
export { createStore, defaultState, type State, type Store } from './src/store/store';
|
|
5
6
|
export { StoreContext } from './src/store/storeContext';
|
|
6
7
|
export { createExtendableStore, type ExtendedStore } from './src/store/storeExtensions';
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import { u as
|
|
3
|
-
import { u as
|
|
4
|
-
import { p
|
|
5
|
-
import { h as
|
|
6
|
-
import { Fragment as
|
|
7
|
-
import { S as O,
|
|
8
|
-
function
|
|
9
|
-
const { loadMore: o } =
|
|
10
|
-
return /* @__PURE__ */
|
|
1
|
+
import { i as c } from "../../isBot-Lnmft0Z0.js";
|
|
2
|
+
import { u as e } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
+
import { u as f, a as l } from "../../useLoadMore-hrNp8P0M.js";
|
|
4
|
+
import { p } from "../../pick-DReBictn.js";
|
|
5
|
+
import { h as m, i as d, I as S } from "../../InfiniteScrollWithObserver-6A57AOKr.js";
|
|
6
|
+
import { Fragment as g } from "preact";
|
|
7
|
+
import { S as A, g as O, c as W, f as B, b as E, d as F, a as N, e as R } from "../../useActions-SEyBHGra.js";
|
|
8
|
+
function C({ pageSize: r }) {
|
|
9
|
+
const { loadMore: o } = f(r);
|
|
10
|
+
return /* @__PURE__ */ e("button", { onClick: o, children: "More results" });
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const { loading:
|
|
14
|
-
return /* @__PURE__ */
|
|
15
|
-
|
|
16
|
-
a && (o ? /* @__PURE__ */
|
|
12
|
+
function h({ children: r, loadMoreComponent: o, pageSize: t }) {
|
|
13
|
+
const { loading: s, query: n, response: i } = l((u) => p(u, "loading", "query", "response")), a = !s && m(n, i);
|
|
14
|
+
return /* @__PURE__ */ e(g, { children: [
|
|
15
|
+
r,
|
|
16
|
+
a && (o ? /* @__PURE__ */ e(o, { pageSize: t }) : /* @__PURE__ */ e(C, { pageSize: t }))
|
|
17
17
|
] });
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const y = !c() && d() ? S : h;
|
|
20
20
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
B as defaultState
|
|
21
|
+
y as InfiniteScroll,
|
|
22
|
+
h as InfiniteScrollWithLink,
|
|
23
|
+
A as StoreContext,
|
|
24
|
+
O as createExtendableStore,
|
|
25
|
+
W as createStore,
|
|
26
|
+
B as defaultState,
|
|
27
|
+
E as useAutocompleteConfig,
|
|
28
|
+
F as useCategoryConfig,
|
|
29
|
+
N as useConfig,
|
|
30
|
+
R as useSerpConfig
|
|
27
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../useActions-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../useActions-CJ71kc2N.cjs"),x=require("../../logger-Boh_C6Bz.cjs"),h=require("../../useLoadMore-B0JgcUfM.cjs"),d=require("preact/hooks"),L=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../parseNumber-FsZ8w61u.cjs");function P(t){const n=h.useNostoAppState(e=>e.response);return t&&Array.isArray(t)||t&&x.isPlainObject(t)?t:n}function T(t,n){const e=t.data?.filter(f=>f.selected).length??0,{active:o}={active:e>0,...n},[r,c]=d.useState(o),{toggleProductFilter:u}=b.useActions(),l=d.useCallback(()=>{c(!r)},[r]);return{active:r,selectedFiltersCount:e,toggleActive:l,toggleProductFilter:u}}function q(){const{loading:t,facets:n}=h.useNostoAppState(e=>({loading:e.loading,facets:e.response?.products?.facets??[]}));return{loading:t,facets:n}}function z(t,n){const e=n-t;return!isNaN(e)&&e>0?new Array(n-t).fill(void 0).map((o,r)=>r+t):[]}function X(t){const{query:n,products:e}=h.useNostoAppState(o=>({query:o.query,products:o.response.products}));return d.useMemo(()=>{if(!e)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=n.products?.from??0,r=t?.width??1/0,c=Math.max(Math.floor(r-1)/2,1),u=e.size>0?Math.floor(o/e.size)+1:1,l=e.size>0?Math.ceil(e.total/e.size):0,f=A=>A>=u-c&&A<=u+c,s=o+1,i=Math.min(o+e.total,e.total),a={from:o,page:u,current:!0},p=A=>({from:(A-1)*e.size,page:A,current:A===u}),S=u>1?p(u-1):void 0,m=u<l?p(u+1):void 0,g=u-c-1>1?p(1):void 0,v=u+c+1<l?p(l):void 0,F=z(1,l+1).filter(f).map(p);return!g&&F[0]?.page===2&&F.unshift(p(1)),!v&&F[F.length-1]?.page===l-1&&F.push(p(l)),{totalPages:l,resultsFrom:s,resultsTo:i,current:a,prev:S,next:m,first:g,last:v,pages:F}},[n,e,t?.width])}function O(){const[t,n]=d.useState([]),[e,o]=d.useState([]);return d.useEffect(()=>{L.s(async r=>{const{products:c,segments:u}=await r.getSearchSessionParams();n(u??[]),o(c?.personalizationBoost??[])})},[]),{segments:t,boost:e}}function j(){const{facets:t}=h.useNostoAppState(s=>({facets:s.response.products?.facets??[]})),{replaceFilter:n,toggleProductFilter:e}=b.useActions(),o=d.useCallback(s=>{const i=t?.find(a=>a.type==="stats"&&a.field===s);if(i&&"min"in i&&"max"in i)return i},[t]),r=d.useCallback(s=>t?.find(i=>i.field===s)?.name??s,[t]),c=d.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),u=d.useCallback(s=>({...s,range:s.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}))}),[]),l=d.useCallback(s=>(s.value??[]).map(a=>({value:a,field:s.field,name:r(s.field),filter:u(s),remove:()=>{e(s.field,a,!1)}})),[u,r,e]),f=d.useCallback(s=>(s.range??[]).map(a=>{const p=a.gte??a.gt??o(s.field)?.min,S=a.lte??a.lt??o(s.field)?.max;if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:s.field,name:r(s.field),filter:u(s),remove:()=>{n(s.field,void 0)}}}).filter(Boolean),[u,o,r,n]);return{selectFilters:c,toValueFilter:l,toRangeFilter:f}}function R(){const{filter:t}=h.useNostoAppState(l=>({filter:l.query.products?.filter??[]})),{updateSearch:n}=b.useActions(),{selectFilters:e,toValueFilter:o,toRangeFilter:r}=j(),c=d.useMemo(()=>t?t.filter(e).flatMap(l=>"value"in l?o(l):"range"in l?r(l):[]).filter(Boolean):[],[t,e,r,o]),u=d.useCallback(()=>{n({products:{filter:[]}})},[n]);return{filters:c,removeAll:u}}function k(t){const{replaceFilter:n}=b.useActions(),{query:e,products:o}=h.useNostoAppState(a=>({query:a.query,products:a.response.products})),r=o?.facets?.find(a=>a.id===t);if(!r)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const c=e.products?.filter?.find(a=>a.field===r.field),u=c?.range?c.range[0]:void 0,l=typeof u=="object"&&("gte"in u||"lte"in u)?[y.parseNumber(u.gte),y.parseNumber(u.lte)]:[void 0,void 0],f="min"in r?Math.floor(r.min):0,s="max"in r?Math.ceil(r.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)&&(s===m||!v)?n(r.field,void 0):(f===S||!g)&&v?n(r.field,{lte:m.toString()}):(s===m||!v)&&g?n(r.field,{gte:S.toString()}):g&&v&&n(r.field,{gte:S.toString(),lte:m.toString()})};return{min:f,max:s,range:[l[0]??f,l[1]??s],updateRange:i}}function V(t,n){const{min:e,max:o,range:r,updateRange:c}=k(t),{filters:u}=R(),l=d.useMemo(()=>{const a=u.find(g=>g?.filter?.range);let p=null;if(a){const g=a.filter.range?.[0];p=[y.parseNumber(g?.gte),y.parseNumber(g?.lte)]}const S=[];let m=Math.floor(e/n)*n;for(;m<o;){const g=m+n,v=p&&p[0]===m&&p[1]===g;S.push({min:m,max:g,selected:v}),m=g}return S},[u,e,o,n]),f=a=>{c([a,r[1]])},s=a=>{c([r[0],a])},i=e!==r[0]||o!==r[1];return{min:e,max:o,range:r,updateRange:c,ranges:l,handleMinChange:f,handleMaxChange:s,isSelected:i}}function D(){const{products:t,keywords:n}=h.useNostoAppState(e=>e.response);return{products:t??{hits:[],total:0},keywords:n??{hits:[],total:0}}}function B(){const t=h.useNostoAppState(e=>e.query.products?.filter);return d.useMemo(()=>t?t.reduce((e,o)=>e+(Array.isArray(o.value)?o.value.length:1),0):0,[t])}function N(t){return t&&!Number.isNaN(t)?t:0}function _(t,n){const{from:e,size:o,total:r}=h.useNostoAppState(s=>({from:N(s.query.products?.from??0),size:N(s.response?.products?.size??n),total:N(s.response?.products?.total??0)})),{updateSearch:c}=b.useActions(),u=e+o,l=d.useMemo(()=>[...t].reverse().filter(s=>s<r),[t,r]),f=d.useCallback(s=>{c({products:{size:y.parseNumber(s)}})},[c]);return{from:e,to:u,total:r,size:o,sizeOptions:l,handleSizeChange:f}}function E(t,n){return t.length!==n.length?!1:t.every(e=>n.find(o=>e.field===o.field&&e.order===o.order))}function U(t){const n=h.useNostoAppState(c=>c.query),{updateSearch:e}=b.useActions();return{activeSort:t.find(c=>E(c.value.sort,n.products?.sort||[]))?.id??t[0]?.id,setSort:c=>{const u=t.find(l=>l.id===c);u&&e({products:{sort:u.value.sort}})}}}const M=window.SpeechRecognition||window.webkitSpeechRecognition,C=!!(M&&typeof M=="function");function $(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function I({language:t="en-US",interimResults:n=!1,onResult:e,onError:o}={}){const[r,c]=d.useState(!1),u=d.useRef(null),l=d.useCallback(()=>{const s=new M;s.lang=t,s.interimResults=n,s.onstart=()=>c(!0),e&&(s.onresult=i=>{const{transcript:a}=i.results?.[0]?.[0];e(a)}),o&&(s.onerror=i=>o(i.error)),s.onend=()=>c(!1),u.current=s,s.start()},[t,n,o,e]),f=d.useCallback(()=>{u.current?.stop()},[u]);return{listening:r,startListening:l,stopListening:f}}const Z=C?I:$;function G(t,n){if(!t.length||!n.length)return[];const e=n.reduce((o,r)=>(o[r]={},o),{});return t.forEach(o=>{o.customFields?.forEach(({key:r,value:c})=>{const u=r.toLowerCase();n.includes(u)&&(e[u][c]=e[u][c]||[],e[u][c].push(o))})}),Object.entries(e).filter(o=>Object.keys(o[1]).length).map(([o,r])=>({field:o,options:Object.entries(r).map(([c,u])=>({value:c,skus:u,unavailable:!1,selected:!1}))}))}function H(t,n){return t.length?t.map(({field:e,options:o})=>({field:e,options:o.map(r=>{const c=!r.skus?.some(l=>Object.entries(n).every(([f,s])=>f===e?!0:l.customFields?.find(a=>a.key.toLowerCase()===f)?.value===s)),u=n[e]===r.value;return{...r,unavailable:c,selected:u}})})):[]}const w=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function J(t){if(w.includes(t))return 1e3+w.indexOf(t);const n=parseFloat(t);return isNaN(n)?t:n}function K(t,n){return[...n].sort((e,o)=>{const[r,c]=[e.value,o.value].map(J);return r<c?-1:1})}function Q(t=[],n=[]){const[e,o]=d.useState({}),r=d.useMemo(()=>G(t,n).map(({field:s,options:i})=>({field:s,options:K(s,i)})),[t,n]),c=d.useMemo(()=>H(r,e),[r,e]),u=d.useCallback((f,s)=>{o(i=>{const a={...i};return a[f]===s?delete a[f]:a[f]=s,a})},[]),l=d.useMemo(()=>Object.keys(e).filter(i=>e[i]).length===0?[]:c.filter(({field:i})=>e[i]).map(({field:i,options:a})=>{const p=e[i];return a.find(m=>m.value===p)?.skus??[]}).reduce((i,a)=>i.filter(p=>a.includes(p))),[c,e]);return{swatches:c,toggleOption:u,matchedSkus:l}}exports.useActions=b.useActions;exports.useLoadMore=h.useLoadMore;exports.useNostoAppState=h.useNostoAppState;exports.speechToTextSupported=C;exports.useDecoratedSearchResults=P;exports.useFacet=T;exports.useFacets=q;exports.usePagination=X;exports.usePersonalization=O;exports.useProductFilters=R;exports.useRange=k;exports.useRangeSelector=V;exports.useResponse=D;exports.useSelectedFiltersCount=B;exports.useSizeOptions=_;exports.useSort=U;exports.useSpeechToText=Z;exports.useSwatches=Q;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as b } from "../../useActions-SEyBHGra.js";
|
|
2
2
|
import { a as z } from "../../logger-_fg_Za9y.js";
|
|
3
|
-
import { a as v } from "../../useLoadMore-
|
|
4
|
-
import { u as le } from "../../useLoadMore-
|
|
3
|
+
import { a as v } from "../../useLoadMore-hrNp8P0M.js";
|
|
4
|
+
import { u as le } from "../../useLoadMore-hrNp8P0M.js";
|
|
5
5
|
import { useState as R, useCallback as h, useMemo as y, useEffect as A, useRef as N } from "preact/hooks";
|
|
6
6
|
import { s as P } from "../../index.es-XNBESE3P.js";
|
|
7
7
|
import { p as x } from "../../parseNumber-QA48nJLp.js";
|
|
@@ -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-99syi-nl.cjs"),T=require("../../CategoryPageProvider-Clj40F3F.cjs"),m=require("../../useActions-CJ71kc2N.cjs"),x=require("../../SerpPageProvider-pR-E8S6m.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),E=require("../../bindInput-BnKvCky1.cjs"),P=require("../../unique-BXXNictB.cjs"),g=require("preact"),S=require("../../logger-Boh_C6Bz.cjs"),D=require("preact/hooks"),O=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../search-DTqo1D6Y.cjs");function B(e){let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function f({children:e}){const[t]=D.useErrorBoundary();return t&&S.logger.error("Error caught in ErrorBoundary",t),u.u(g.Fragment,{children:e})}function A(e){return Array.from(document.querySelectorAll(e))}function F(e){const t=[];let n=e.parentNode;for(;n&&n!==document&&n instanceof Element;)t.push(n),n=n.parentNode;return t}function q([e,t],n){const o=r=>{const i=r.target;i instanceof HTMLElement&&e&&i!==e&&i!==t&&!F(i).includes(e)&&n()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function I(e,t){e.tabIndex=0,e.addEventListener("blur",t)}function b(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function H({selector:e,timeout:t=500}){return new Promise(n=>{const o=A(e);if(o.length>0)return n(o);const r=new MutationObserver(()=>{const s=A(e);s.length>0&&(r.disconnect(),clearTimeout(i),n(s))}),i=setTimeout(()=>{r.disconnect(),S.logger.warn(`Timed out (${t}) while waiting for element ${e}`),n([])},t);r.observe(document.body,{childList:!0,subtree:!0})})}const N=g.createContext({reportProductClick:()=>{},reportKeywordClick:()=>{},handleSubmit:()=>{},highlightedElementIndex:-1});function $(e,t){const{dropdown:n,history:o,store:r,input:i,onNavigateToSearch:s}=e,l=(c,h)=>{n.hide(),o.hide(),c&&(o.add(c),r.updateState({historyItems:o.get()}),h&&O.s(a=>a.recordSearchSubmit(c)),i.value=c)};return{reportProductClick:c=>{l(c.name,!1)},reportKeywordClick:c=>{l(c.keyword,!0)},handleSubmit:c=>{l(c.query,!1),s?.(c)},highlightedElementIndex:t.highlightedIndex()}}function k(e,t,n){t.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=b(n),i=r&&document.querySelector(r.selector);if(i){const a=document.createElement("form");a.className="nosto-dropdown-form",a.appendChild(t),r.position==="first"?i.prepend(a):i.appendChild(a)}else o.appendChild(t);const s={index:-1,onChangeListeners:[]},l=(a,d)=>{const p=a.length;p===0&&(d=-1),s.index=d>=0?d%p:p-1,s.onChangeListeners.forEach(v=>v())},c=()=>{s.index=-1,s.onChangeListeners.forEach(a=>a())},h=()=>s.index;return{element:t,hide:()=>{t.style.display="none",c()},show:()=>{t.style.display="inherit"},isOpen:()=>t.style.display!=="none",goDown:()=>{const a=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();l(a,d+1)},goUp:()=>{const a=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();l(a,d-1)},highlight:l,highlightedIndex:h,submitHighlightedItem:a=>{Array.from(t.querySelectorAll(".ns-autocomplete-element"))[a]?.click()},onHighlightChange:a=>{s.onChangeListeners.push(a)}}}function K(e,t){const n=document.createElement("div");return n.className="nosto-autocomplete-dropdown",{...k(e,n,t),element:n}}const C="nosto:search-js:history";function Q(e,t,n){const o=document.createElement("div");return o.className="nosto-autocomplete-history",{...k(e,o,t),element:o,add:i=>{const l=(y.getLocalStorageItem(C)??[]).filter(c=>c!==i).slice(n?-n:0);l.push(i),y.setLocalStorageItem(C,l)},get:()=>(y.getLocalStorageItem(C)??[]).reverse().filter(s=>!!s)}}async function M(e,{config:t,dropdown:n,history:o,renderHistory:r,store:i}){const{historyEnabled:s,minQueryLength:l}=t;if(e.length<l&&s&&r&&!o.isOpen()){o.show();return}if(e.length<l)return;n.hide();const c=i.getState()?.query?.query;c&&c!==e&&await m.newSearch({config:t,store:i},{query:e}),n.show()}async function U(e,t){const{config:n,renderHistory:o,history:r}=t,{historyEnabled:i,minQueryLength:s}=n;if(!o||e.length>=s||!i||r.isOpen())return;const l=R(t,r);r.onHighlightChange(()=>{l(o,r.element)}),r.show();const c=P.measure("renderHistory");l(o,r.element),c()}async function _(e,{config:t,dropdown:n,history:o,store:r,debouncer:i}){const{minQueryLength:s,historyEnabled:l}=t;if(e.length<s&&!l){n.hide(),o.hide();return}if(e.length<s&&l){n.hide(),o.show();return}o.hide(),i(async()=>{m.newSearch({config:t,store:r},{query:e}),n.show()})}function z(e,t,n){const{config:o,debouncer:r}=n;if(r(()=>{}),e.length>=o.minQueryLength)return L(t,n.dropdown,n.history);if(o.historyEnabled)return L(t,n.history,n.dropdown)}function L(e,t,n){if(!t.isOpen()&&e==="ArrowDown"){t.show(),n.hide();return}if(e==="Escape"&&t.hide(),!!t.isOpen()){if(e==="ArrowDown")t.goDown();else if(e==="ArrowUp")t.goUp();else if(e==="Enter"){const o=t.highlightedIndex();return o>=0&&t.submitHighlightedItem(o),t.hide(),o>=0}}}function G(e,{config:t,dropdown:n,history:o,onNavigateToSearch:r,store:i}){n.hide(),o.hide(),!(e.length<t.minQueryLength)&&(o.add(e),i.updateState({historyItems:o.get()}),r?.({query:e}))}async function J(e,t){const{inputCssSelector:n,timeout:o}=e,r=b(n).selector,i=await H({selector:r,timeout:o});if(i.length===0)throw new Error(`No elements found for selector: ${r}`);i.forEach(s=>{V(s,e,t)})}async function V(e,t,n){const{config:o,dropdownCssSelector:r}=t,i=K(e,r),s=Q(e,r,o.historySize),l={...t,input:e,dropdown:i,history:s,store:n,debouncer:B(o.debounceDelay)};X(l),e.setAttribute("data-nosto-element","search-input"),n.updateState({historyItems:s.get()}),E.disableNativeAutocomplete(e),n.onInit(()=>{W(l)}),E.bindInput(e,{onInput:c=>_(c,l),onFocus:c=>U(c,l),onClick:c=>M(c,l),onSubmit:c=>G(c,l),onKeyDown:(c,h)=>z(c,h,l)}),I(s.element,s.hide),I(i.element,i.hide),q([s.element,e],s.hide),q([i.element,e],i.hide)}function W(e){const{dropdown:t,renderAutocomplete:n}=e;if(!n)return;const o=R(e,t);t.onHighlightChange(()=>{o(n,t.element)});const r=P.measure("renderAutocomplete");o(n,t.element),r()}async function X(e){const{input:t,renderSpeechToText:n,config:o,store:r}=e;if(!n)return;const i="ns-autocomplete-voice-position";if(!!t.parentElement?.querySelector(`.${i}`))return;const l=document.createElement("div");l.className=i,t.insertAdjacentElement("afterend",l);const c=await n();g.render(u.u(f,{children:u.u(w.AutocompletePageProvider,{config:o,store:r,children:c})}),l)}function R(e,t){const{config:n,store:o}=e,r=$(e,t);return t.onHighlightChange(()=>{r.highlightedElementIndex=t.highlightedIndex()}),(i,s)=>g.render(u.u(f,{children:u.u(w.AutocompletePageProvider,{config:n,store:o,children:u.u(N,{value:r,children:i()})})}),s)}async function j({cssSelector:e,timeout:t,renderComponent:n}){const o=b(e).selector,r=await H({selector:o,timeout:t??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&S.logger.warn(`Multiple (${r.length}) elements found for selector: ${o}`),g.render(n(),r[0])}async function Y(e,t){const{render:n}=e,o=await n();j({...e,renderComponent:()=>u.u(f,{children:u.u(T.CategoryPageProvider,{store:t,config:e.config,children:o})})})}async function Z(e,t){const{render:n}=e,o=await n();j({...e,renderComponent:()=>u.u(f,{children:u.u(x.SearchPageProvider,{store:t,config:e.config,children:o})})})}async function ee({autocomplete:e,category:t,serp:n}){const o={};if(e){const r=m.createStore({query:e.query});await J({...e,config:w.makeAutocompleteConfig(e.config)},r),o.autocomplete={store:r}}if(t){const r=m.createStore({query:t.query});await Y({...t,config:T.makeCategoryConfig(t.config)},r),o.category={store:r}}if(n){const r=m.createStore({query:n.query});await Z({...n,config:x.makeSerpConfig(n.config)},r),o.serp={store:r}}return o}exports.AutocompleteContext=N;exports.init=ee;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as L, m as D } from "../../AutocompletePageProvider-
|
|
2
|
-
import { C as R, m as B } from "../../CategoryPageProvider-
|
|
3
|
-
import { n as T, c as g } from "../../useActions-
|
|
4
|
-
import { S as F, m as O } from "../../SerpPageProvider-
|
|
1
|
+
import { A as L, m as D } from "../../AutocompletePageProvider-HeGU8tjH.js";
|
|
2
|
+
import { C as R, m as B } from "../../CategoryPageProvider-Bou8i9Tx.js";
|
|
3
|
+
import { n as T, c as g } from "../../useActions-SEyBHGra.js";
|
|
4
|
+
import { S as F, m as O } from "../../SerpPageProvider-B-W6nCqu.js";
|
|
5
5
|
import { u as d } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
6
6
|
import { d as $, b as j } from "../../bindInput-CCx0Fhsg.js";
|
|
7
7
|
import { a as x } from "../../unique-Cv2g464w.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-CJ71kc2N.cjs"),r=require("../../InfiniteScrollWithObserver-CoPOQr8Q.cjs"),t=require("../../useLoadMore-B0JgcUfM.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-SEyBHGra.js";
|
|
2
|
+
import { I as s, i } from "../../InfiniteScrollWithObserver-6A57AOKr.js";
|
|
3
|
+
import { g as p } from "../../useLoadMore-hrNp8P0M.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-CJ71kc2N.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-pR-E8S6m.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,10 +1,10 @@
|
|
|
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 { a as p } from "../../useActions-
|
|
4
|
+
import { a as p } from "../../useActions-SEyBHGra.js";
|
|
5
5
|
import { useCallback as f } from "preact/hooks";
|
|
6
|
-
import { S as x } from "../../SerpPageProvider-
|
|
7
|
-
const S = "nosto:search:scrollPos";
|
|
6
|
+
import { S as x } from "../../SerpPageProvider-B-W6nCqu.js";
|
|
7
|
+
const S = "nosto:search-js:scrollPos";
|
|
8
8
|
function g() {
|
|
9
9
|
window.sessionStorage.setItem(S, window.scrollY.toString());
|
|
10
10
|
}
|
|
@@ -0,0 +1 @@
|
|
|
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-DTqo1D6Y.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;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { createContext as S } from "preact";
|
|
2
|
+
import { useContext as k, useMemo as I, useCallback as d } from "preact/hooks";
|
|
3
|
+
import { b as w, u as M, a as f, d as h, m as E } from "./unique-Cv2g464w.js";
|
|
4
|
+
import { i as b, l as A } from "./logger-_fg_Za9y.js";
|
|
5
|
+
import { s as U } from "./search-sC5QgJmw.js";
|
|
6
|
+
const q = S(null);
|
|
7
|
+
function p() {
|
|
8
|
+
const e = k(q);
|
|
9
|
+
if (!e)
|
|
10
|
+
throw new Error("useConfig must be used within a ConfigProvider");
|
|
11
|
+
return e;
|
|
12
|
+
}
|
|
13
|
+
function R() {
|
|
14
|
+
const e = p();
|
|
15
|
+
if (e.pageType !== "search")
|
|
16
|
+
throw new Error("useSerpConfig must be used within a NostoSearchPageProvider");
|
|
17
|
+
return e;
|
|
18
|
+
}
|
|
19
|
+
function W() {
|
|
20
|
+
const e = p();
|
|
21
|
+
if (e.pageType !== "category")
|
|
22
|
+
throw new Error("useCategoryConfig must be used within a NostoCategoryPageProvider");
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
function X() {
|
|
26
|
+
const e = p();
|
|
27
|
+
if (e.pageType !== "autocomplete")
|
|
28
|
+
throw new Error("useAutocompleteConfig must be used within a NostoAutocompletePageProvider");
|
|
29
|
+
return e;
|
|
30
|
+
}
|
|
31
|
+
function Q(e, r = {}) {
|
|
32
|
+
const t = /* @__PURE__ */ new Map();
|
|
33
|
+
let s = w(e, r ?? {});
|
|
34
|
+
const i = w(e, r);
|
|
35
|
+
function c(g) {
|
|
36
|
+
s = g(s);
|
|
37
|
+
for (const u of t.values())
|
|
38
|
+
u(s);
|
|
39
|
+
}
|
|
40
|
+
function n(g) {
|
|
41
|
+
c((u) => ({ ...u, ...g }));
|
|
42
|
+
}
|
|
43
|
+
function a() {
|
|
44
|
+
return s;
|
|
45
|
+
}
|
|
46
|
+
function o() {
|
|
47
|
+
return structuredClone(i);
|
|
48
|
+
}
|
|
49
|
+
function l(g, u) {
|
|
50
|
+
let C;
|
|
51
|
+
t.set(u, (T) => {
|
|
52
|
+
const y = g(T);
|
|
53
|
+
b(y, C) || (C = y, u(y));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function P(g) {
|
|
57
|
+
l(
|
|
58
|
+
(u) => u.initialized,
|
|
59
|
+
(u) => {
|
|
60
|
+
u && g();
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function F(g) {
|
|
65
|
+
t.delete(g);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
updateState: n,
|
|
69
|
+
getState: a,
|
|
70
|
+
getInitialState: o,
|
|
71
|
+
onChange: l,
|
|
72
|
+
onInit: P,
|
|
73
|
+
clearOnChange: F
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const z = {
|
|
77
|
+
loading: !0,
|
|
78
|
+
query: {},
|
|
79
|
+
response: {},
|
|
80
|
+
initialized: !1
|
|
81
|
+
};
|
|
82
|
+
function K(e = {}) {
|
|
83
|
+
return Q(z, e);
|
|
84
|
+
}
|
|
85
|
+
const N = S(K());
|
|
86
|
+
function B(e, r) {
|
|
87
|
+
return {
|
|
88
|
+
...r,
|
|
89
|
+
products: {
|
|
90
|
+
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
91
|
+
fields: D,
|
|
92
|
+
...r.products
|
|
93
|
+
},
|
|
94
|
+
...r.keywords ? {
|
|
95
|
+
keywords: {
|
|
96
|
+
...r.keywords,
|
|
97
|
+
fields: M([...L, ...r.keywords.fields ?? []]),
|
|
98
|
+
highlight: r.keywords.highlight ?? {
|
|
99
|
+
preTag: "<strong>",
|
|
100
|
+
postTag: "</strong>"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} : {}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const D = [
|
|
107
|
+
"productId",
|
|
108
|
+
"url",
|
|
109
|
+
"name",
|
|
110
|
+
"imageUrl",
|
|
111
|
+
"imageHash",
|
|
112
|
+
"thumbUrl",
|
|
113
|
+
"description",
|
|
114
|
+
"brand",
|
|
115
|
+
"variantId",
|
|
116
|
+
"availability",
|
|
117
|
+
"price",
|
|
118
|
+
"priceText",
|
|
119
|
+
"categoryIds",
|
|
120
|
+
"categories",
|
|
121
|
+
"customFields.key",
|
|
122
|
+
"customFields.value",
|
|
123
|
+
"priceCurrencyCode",
|
|
124
|
+
"datePublished",
|
|
125
|
+
"listPrice",
|
|
126
|
+
"unitPricingBaseMeasure",
|
|
127
|
+
"unitPricingUnit",
|
|
128
|
+
"unitPricingMeasure",
|
|
129
|
+
"googleCategory",
|
|
130
|
+
"gtin",
|
|
131
|
+
"ageGroup",
|
|
132
|
+
"gender",
|
|
133
|
+
"condition",
|
|
134
|
+
"alternateImageUrls",
|
|
135
|
+
"ratingValue",
|
|
136
|
+
"reviewCount",
|
|
137
|
+
"inventoryLevel",
|
|
138
|
+
"skus.id",
|
|
139
|
+
"skus.name",
|
|
140
|
+
"skus.price",
|
|
141
|
+
"skus.listPrice",
|
|
142
|
+
"skus.priceText",
|
|
143
|
+
"skus.url",
|
|
144
|
+
"skus.imageUrl",
|
|
145
|
+
"skus.inventoryLevel",
|
|
146
|
+
"skus.customFields.key",
|
|
147
|
+
"skus.customFields.value",
|
|
148
|
+
"skus.availability",
|
|
149
|
+
"pid",
|
|
150
|
+
"onDiscount",
|
|
151
|
+
"extra.key",
|
|
152
|
+
"extra.value",
|
|
153
|
+
"saleable",
|
|
154
|
+
"available",
|
|
155
|
+
"tags1",
|
|
156
|
+
"tags2",
|
|
157
|
+
"tags3"
|
|
158
|
+
], L = ["keyword", "_redirect"];
|
|
159
|
+
async function v(e, r, t) {
|
|
160
|
+
const s = f("newSearch"), i = e.config.pageType, c = i === "search" ? "serp" : i, n = h(e.store.getInitialState().query, r), a = h(e.config.search, t, {
|
|
161
|
+
track: c,
|
|
162
|
+
redirect: i !== "autocomplete",
|
|
163
|
+
isKeyword: !!t?.isKeyword,
|
|
164
|
+
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache,
|
|
165
|
+
useMemoryCache: e.config.pageType === "autocomplete" && e.config.memoryCache
|
|
166
|
+
});
|
|
167
|
+
e.config.onBeforeSearch?.(e, a), e.store.updateState({
|
|
168
|
+
query: n,
|
|
169
|
+
loading: !0,
|
|
170
|
+
initialized: !0
|
|
171
|
+
});
|
|
172
|
+
const o = e.config.queryModifications(
|
|
173
|
+
{
|
|
174
|
+
...n,
|
|
175
|
+
products: {
|
|
176
|
+
...n.products,
|
|
177
|
+
// Apply filter merging to avoid overwriting base filters
|
|
178
|
+
filter: E(e.store.getInitialState().query?.products?.filter, r.products?.filter)
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
i
|
|
182
|
+
);
|
|
183
|
+
try {
|
|
184
|
+
const l = await U(B(e.config.pageType, o), a);
|
|
185
|
+
e.store.updateState({
|
|
186
|
+
response: l,
|
|
187
|
+
loading: !1
|
|
188
|
+
});
|
|
189
|
+
} catch (l) {
|
|
190
|
+
A.error("Search action failed", l), e.config.onSearchError?.(l, o, a, i);
|
|
191
|
+
}
|
|
192
|
+
s();
|
|
193
|
+
}
|
|
194
|
+
async function m(e, r, t) {
|
|
195
|
+
const s = f("updateSearch"), i = h(e.store.getState().query, { products: { from: 0 } }, r);
|
|
196
|
+
await v(e, i, t), s();
|
|
197
|
+
}
|
|
198
|
+
async function O(e, r, t) {
|
|
199
|
+
const s = f("replaceFilter"), i = e.store.getState().query.products?.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
200
|
+
await m(e, {
|
|
201
|
+
products: {
|
|
202
|
+
filter: [...i?.filter((n) => n.field !== r) ?? [], ...c]
|
|
203
|
+
}
|
|
204
|
+
}), s();
|
|
205
|
+
}
|
|
206
|
+
async function V(e, r, t, s) {
|
|
207
|
+
const i = f("toggleProductFilter"), c = e.store.getState().query.products?.filter, n = c?.find((o) => o.value instanceof Array && o.field === r), a = n?.value ? {
|
|
208
|
+
...n,
|
|
209
|
+
value: [...n.value.filter((o) => !b(o, t)), ...s ? [t] : []]
|
|
210
|
+
} : s ? {
|
|
211
|
+
field: r,
|
|
212
|
+
value: [t]
|
|
213
|
+
} : void 0;
|
|
214
|
+
await m(e, {
|
|
215
|
+
products: {
|
|
216
|
+
filter: [...c?.filter((o) => o !== n) ?? [], ...a?.value?.length ? [a] : []]
|
|
217
|
+
}
|
|
218
|
+
}), i();
|
|
219
|
+
}
|
|
220
|
+
function Y() {
|
|
221
|
+
const e = p(), r = k(N), t = I(
|
|
222
|
+
() => ({
|
|
223
|
+
config: e,
|
|
224
|
+
store: r
|
|
225
|
+
}),
|
|
226
|
+
[e, r]
|
|
227
|
+
), s = d(
|
|
228
|
+
(a, o) => v(t, a, o),
|
|
229
|
+
[t]
|
|
230
|
+
), i = d(
|
|
231
|
+
(a, o) => m(t, a, o),
|
|
232
|
+
[t]
|
|
233
|
+
), c = d(
|
|
234
|
+
(a, o, l) => V(t, a, o, l),
|
|
235
|
+
[t]
|
|
236
|
+
), n = d(
|
|
237
|
+
(a, o) => O(t, a, o),
|
|
238
|
+
[t]
|
|
239
|
+
);
|
|
240
|
+
return {
|
|
241
|
+
newSearch: s,
|
|
242
|
+
updateSearch: i,
|
|
243
|
+
toggleProductFilter: c,
|
|
244
|
+
replaceFilter: n
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
export {
|
|
248
|
+
q as C,
|
|
249
|
+
N as S,
|
|
250
|
+
p as a,
|
|
251
|
+
X as b,
|
|
252
|
+
K as c,
|
|
253
|
+
W as d,
|
|
254
|
+
R as e,
|
|
255
|
+
z as f,
|
|
256
|
+
Q as g,
|
|
257
|
+
Y as h,
|
|
258
|
+
v as n,
|
|
259
|
+
m as u
|
|
260
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("./useActions-
|
|
1
|
+
"use strict";const n=require("./useActions-CJ71kc2N.cjs"),r=require("preact/hooks"),i=require("./isBot-iyBlT_oq.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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as n,
|
|
1
|
+
import { S as n, h as u } from "./useActions-SEyBHGra.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-Lnmft0Z0.js";
|
|
4
4
|
function l(t = p) {
|
|
@@ -13,7 +13,7 @@ function d({ from: t, size: e, pageSize: o }) {
|
|
|
13
13
|
products: { size: e + o }
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function x(t = 24) {
|
|
17
17
|
const { from: e, size: o } = l((s) => ({
|
|
18
18
|
from: s.query.products?.from ?? 0,
|
|
19
19
|
size: s.query.products?.size ?? 0
|
|
@@ -27,5 +27,5 @@ function y(t = 24) {
|
|
|
27
27
|
export {
|
|
28
28
|
l as a,
|
|
29
29
|
d as g,
|
|
30
|
-
|
|
30
|
+
x as u
|
|
31
31
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -103,11 +103,11 @@
|
|
|
103
103
|
"@testing-library/dom": "^10.4.1",
|
|
104
104
|
"@types/dom-speech-recognition": "^0.0.6",
|
|
105
105
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
106
|
-
"@types/node": "^24.3.
|
|
106
|
+
"@types/node": "^24.3.1",
|
|
107
107
|
"@vitest/coverage-v8": "^3.2.4",
|
|
108
108
|
"concurrently": "^9.2.1",
|
|
109
109
|
"copyfiles": "^2.4.1",
|
|
110
|
-
"eslint": "^9.
|
|
110
|
+
"eslint": "^9.35.0",
|
|
111
111
|
"eslint-config-prettier": "^10.1.8",
|
|
112
112
|
"eslint-plugin-barrel-files": "^3.0.1",
|
|
113
113
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -121,8 +121,8 @@
|
|
|
121
121
|
"prettier": "^3.6.2",
|
|
122
122
|
"typedoc": "^0.28.12",
|
|
123
123
|
"typescript": "^5.9.2",
|
|
124
|
-
"typescript-eslint": "^8.
|
|
125
|
-
"vite": "^7.1.
|
|
124
|
+
"typescript-eslint": "^8.43.0",
|
|
125
|
+
"vite": "^7.1.5",
|
|
126
126
|
"vite-plugin-dts": "^4.5.4",
|
|
127
127
|
"vitest": "^3.1.3"
|
|
128
128
|
},
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { createContext as k } from "preact";
|
|
2
|
-
import { useContext as C, useMemo as T, useCallback as g } from "preact/hooks";
|
|
3
|
-
import { b as S, u as I, a as f, d as y, m as M } from "./unique-Cv2g464w.js";
|
|
4
|
-
import { i as w, l as U } from "./logger-_fg_Za9y.js";
|
|
5
|
-
import { s as q } from "./search-sC5QgJmw.js";
|
|
6
|
-
const E = k(null);
|
|
7
|
-
function Q() {
|
|
8
|
-
const e = C(E);
|
|
9
|
-
if (!e)
|
|
10
|
-
throw new Error("useConfig must be used within a ConfigProvider");
|
|
11
|
-
return e;
|
|
12
|
-
}
|
|
13
|
-
function z(e, r = {}) {
|
|
14
|
-
const t = /* @__PURE__ */ new Map();
|
|
15
|
-
let s = S(e, r ?? {});
|
|
16
|
-
const o = S(e, r);
|
|
17
|
-
function c(d) {
|
|
18
|
-
s = d(s);
|
|
19
|
-
for (const u of t.values())
|
|
20
|
-
u(s);
|
|
21
|
-
}
|
|
22
|
-
function n(d) {
|
|
23
|
-
c((u) => ({ ...u, ...d }));
|
|
24
|
-
}
|
|
25
|
-
function i() {
|
|
26
|
-
return s;
|
|
27
|
-
}
|
|
28
|
-
function a() {
|
|
29
|
-
return structuredClone(o);
|
|
30
|
-
}
|
|
31
|
-
function l(d, u) {
|
|
32
|
-
let m;
|
|
33
|
-
t.set(u, (P) => {
|
|
34
|
-
const p = d(P);
|
|
35
|
-
w(p, m) || (m = p, u(p));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function v(d) {
|
|
39
|
-
l(
|
|
40
|
-
(u) => u.initialized,
|
|
41
|
-
(u) => {
|
|
42
|
-
u && d();
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
function F(d) {
|
|
47
|
-
t.delete(d);
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
updateState: n,
|
|
51
|
-
getState: i,
|
|
52
|
-
getInitialState: a,
|
|
53
|
-
onChange: l,
|
|
54
|
-
onInit: v,
|
|
55
|
-
clearOnChange: F
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const A = {
|
|
59
|
-
loading: !0,
|
|
60
|
-
query: {},
|
|
61
|
-
response: {},
|
|
62
|
-
initialized: !1
|
|
63
|
-
};
|
|
64
|
-
function K(e = {}) {
|
|
65
|
-
return z(A, e);
|
|
66
|
-
}
|
|
67
|
-
const B = k(K());
|
|
68
|
-
function D(e, r) {
|
|
69
|
-
return {
|
|
70
|
-
...r,
|
|
71
|
-
products: {
|
|
72
|
-
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
73
|
-
fields: L,
|
|
74
|
-
...r.products
|
|
75
|
-
},
|
|
76
|
-
...r.keywords ? {
|
|
77
|
-
keywords: {
|
|
78
|
-
...r.keywords,
|
|
79
|
-
fields: I([...O, ...r.keywords.fields ?? []]),
|
|
80
|
-
highlight: r.keywords.highlight ?? {
|
|
81
|
-
preTag: "<strong>",
|
|
82
|
-
postTag: "</strong>"
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} : {}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const L = [
|
|
89
|
-
"productId",
|
|
90
|
-
"url",
|
|
91
|
-
"name",
|
|
92
|
-
"imageUrl",
|
|
93
|
-
"imageHash",
|
|
94
|
-
"thumbUrl",
|
|
95
|
-
"description",
|
|
96
|
-
"brand",
|
|
97
|
-
"variantId",
|
|
98
|
-
"availability",
|
|
99
|
-
"price",
|
|
100
|
-
"priceText",
|
|
101
|
-
"categoryIds",
|
|
102
|
-
"categories",
|
|
103
|
-
"customFields.key",
|
|
104
|
-
"customFields.value",
|
|
105
|
-
"priceCurrencyCode",
|
|
106
|
-
"datePublished",
|
|
107
|
-
"listPrice",
|
|
108
|
-
"unitPricingBaseMeasure",
|
|
109
|
-
"unitPricingUnit",
|
|
110
|
-
"unitPricingMeasure",
|
|
111
|
-
"googleCategory",
|
|
112
|
-
"gtin",
|
|
113
|
-
"ageGroup",
|
|
114
|
-
"gender",
|
|
115
|
-
"condition",
|
|
116
|
-
"alternateImageUrls",
|
|
117
|
-
"ratingValue",
|
|
118
|
-
"reviewCount",
|
|
119
|
-
"inventoryLevel",
|
|
120
|
-
"skus.id",
|
|
121
|
-
"skus.name",
|
|
122
|
-
"skus.price",
|
|
123
|
-
"skus.listPrice",
|
|
124
|
-
"skus.priceText",
|
|
125
|
-
"skus.url",
|
|
126
|
-
"skus.imageUrl",
|
|
127
|
-
"skus.inventoryLevel",
|
|
128
|
-
"skus.customFields.key",
|
|
129
|
-
"skus.customFields.value",
|
|
130
|
-
"skus.availability",
|
|
131
|
-
"pid",
|
|
132
|
-
"onDiscount",
|
|
133
|
-
"extra.key",
|
|
134
|
-
"extra.value",
|
|
135
|
-
"saleable",
|
|
136
|
-
"available",
|
|
137
|
-
"tags1",
|
|
138
|
-
"tags2",
|
|
139
|
-
"tags3"
|
|
140
|
-
], O = ["keyword", "_redirect"];
|
|
141
|
-
async function b(e, r, t) {
|
|
142
|
-
const s = f("newSearch"), o = e.config.pageType, c = o === "search" ? "serp" : o, n = y(e.store.getInitialState().query, r), i = y(e.config.search, t, {
|
|
143
|
-
track: c,
|
|
144
|
-
redirect: o !== "autocomplete",
|
|
145
|
-
isKeyword: !!t?.isKeyword,
|
|
146
|
-
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache,
|
|
147
|
-
useMemoryCache: e.config.pageType === "autocomplete" && e.config.memoryCache
|
|
148
|
-
});
|
|
149
|
-
e.config.onBeforeSearch?.(e, i), e.store.updateState({
|
|
150
|
-
query: n,
|
|
151
|
-
loading: !0,
|
|
152
|
-
initialized: !0
|
|
153
|
-
});
|
|
154
|
-
const a = e.config.queryModifications(
|
|
155
|
-
{
|
|
156
|
-
...n,
|
|
157
|
-
products: {
|
|
158
|
-
...n.products,
|
|
159
|
-
// Apply filter merging to avoid overwriting base filters
|
|
160
|
-
filter: M(e.store.getInitialState().query?.products?.filter, r.products?.filter)
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
o
|
|
164
|
-
);
|
|
165
|
-
try {
|
|
166
|
-
const l = await q(D(e.config.pageType, a), i);
|
|
167
|
-
e.store.updateState({
|
|
168
|
-
response: l,
|
|
169
|
-
loading: !1
|
|
170
|
-
});
|
|
171
|
-
} catch (l) {
|
|
172
|
-
U.error("Search action failed", l), e.config.onSearchError?.(l, a, i, o);
|
|
173
|
-
}
|
|
174
|
-
s();
|
|
175
|
-
}
|
|
176
|
-
async function h(e, r, t) {
|
|
177
|
-
const s = f("updateSearch"), o = y(e.store.getState().query, { products: { from: 0 } }, r);
|
|
178
|
-
await b(e, o, t), s();
|
|
179
|
-
}
|
|
180
|
-
async function V(e, r, t) {
|
|
181
|
-
const s = f("replaceFilter"), o = e.store.getState().query.products?.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
182
|
-
await h(e, {
|
|
183
|
-
products: {
|
|
184
|
-
filter: [...o?.filter((n) => n.field !== r) ?? [], ...c]
|
|
185
|
-
}
|
|
186
|
-
}), s();
|
|
187
|
-
}
|
|
188
|
-
async function j(e, r, t, s) {
|
|
189
|
-
const o = f("toggleProductFilter"), c = e.store.getState().query.products?.filter, n = c?.find((a) => a.value instanceof Array && a.field === r), i = n?.value ? {
|
|
190
|
-
...n,
|
|
191
|
-
value: [...n.value.filter((a) => !w(a, t)), ...s ? [t] : []]
|
|
192
|
-
} : s ? {
|
|
193
|
-
field: r,
|
|
194
|
-
value: [t]
|
|
195
|
-
} : void 0;
|
|
196
|
-
await h(e, {
|
|
197
|
-
products: {
|
|
198
|
-
filter: [...c?.filter((a) => a !== n) ?? [], ...i?.value?.length ? [i] : []]
|
|
199
|
-
}
|
|
200
|
-
}), o();
|
|
201
|
-
}
|
|
202
|
-
function R() {
|
|
203
|
-
const e = Q(), r = C(B), t = T(
|
|
204
|
-
() => ({
|
|
205
|
-
config: e,
|
|
206
|
-
store: r
|
|
207
|
-
}),
|
|
208
|
-
[e, r]
|
|
209
|
-
), s = g(
|
|
210
|
-
(i, a) => b(t, i, a),
|
|
211
|
-
[t]
|
|
212
|
-
), o = g(
|
|
213
|
-
(i, a) => h(t, i, a),
|
|
214
|
-
[t]
|
|
215
|
-
), c = g(
|
|
216
|
-
(i, a, l) => j(t, i, a, l),
|
|
217
|
-
[t]
|
|
218
|
-
), n = g(
|
|
219
|
-
(i, a) => V(t, i, a),
|
|
220
|
-
[t]
|
|
221
|
-
);
|
|
222
|
-
return {
|
|
223
|
-
newSearch: s,
|
|
224
|
-
updateSearch: o,
|
|
225
|
-
toggleProductFilter: c,
|
|
226
|
-
replaceFilter: n
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
export {
|
|
230
|
-
E as C,
|
|
231
|
-
B as S,
|
|
232
|
-
Q as a,
|
|
233
|
-
z as b,
|
|
234
|
-
K as c,
|
|
235
|
-
A as d,
|
|
236
|
-
R as e,
|
|
237
|
-
b as n,
|
|
238
|
-
h as u
|
|
239
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const k=require("preact"),f=require("preact/hooks"),c=require("./unique-BXXNictB.cjs"),y=require("./logger-Boh_C6Bz.cjs"),I=require("./search-DTqo1D6Y.cjs"),m=k.createContext(null);function w(){const e=f.useContext(m);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e}function b(e,r={}){const t=new Map;let n=c.deepMergePlain(e,r??{});const s=c.deepMergePlain(e,r);function u(g){n=g(n);for(const l of t.values())l(n)}function o(g){u(l=>({...l,...g}))}function i(){return n}function a(){return structuredClone(s)}function d(g,l){let S;t.set(l,T=>{const h=g(T);y.isEqual(h,S)||(S=h,l(h))})}function q(g){d(l=>l.initialized,l=>{l&&g()})}function M(g){t.delete(g)}return{updateState:o,getState:i,getInitialState:a,onChange:d,onInit:q,clearOnChange:M}}const v={loading:!0,query:{},response:{},initialized:!1};function F(e={}){return b(v,e)}const P=k.createContext(F());function E(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:U,...r.products},...r.keywords?{keywords:{...r.keywords,fields:c.unique([...A,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const U=["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"],A=["keyword","_redirect"];async function C(e,r,t){const n=c.measure("newSearch"),s=e.config.pageType,u=s==="search"?"serp":s,o=c.deepMerge(e.store.getInitialState().query,r),i=c.deepMerge(e.config.search,t,{track:u,redirect:s!=="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:o,loading:!0,initialized:!0});const a=e.config.queryModifications({...o,products:{...o.products,filter:c.mergeArrays(e.store.getInitialState().query?.products?.filter,r.products?.filter)}},s);try{const d=await I.search(E(e.config.pageType,a),i);e.store.updateState({response:d,loading:!1})}catch(d){y.logger.error("Search action failed",d),e.config.onSearchError?.(d,a,i,s)}n()}async function p(e,r,t){const n=c.measure("updateSearch"),s=c.deepMerge(e.store.getState().query,{products:{from:0}},r);await C(e,s,t),n()}async function Q(e,r,t){const n=c.measure("replaceFilter"),s=e.store.getState().query.products?.filter,u=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await p(e,{products:{filter:[...s?.filter(o=>o.field!==r)??[],...u]}}),n()}async function z(e,r,t,n){const s=c.measure("toggleProductFilter"),u=e.store.getState().query.products?.filter,o=u?.find(a=>a.value instanceof Array&&a.field===r),i=o?.value?{...o,value:[...o.value.filter(a=>!y.isEqual(a,t)),...n?[t]:[]]}:n?{field:r,value:[t]}:void 0;await p(e,{products:{filter:[...u?.filter(a=>a!==o)??[],...i?.value?.length?[i]:[]]}}),s()}function K(){const e=w(),r=f.useContext(P),t=f.useMemo(()=>({config:e,store:r}),[e,r]),n=f.useCallback((i,a)=>C(t,i,a),[t]),s=f.useCallback((i,a)=>p(t,i,a),[t]),u=f.useCallback((i,a,d)=>z(t,i,a,d),[t]),o=f.useCallback((i,a)=>Q(t,i,a),[t]);return{newSearch:n,updateSearch:s,toggleProductFilter:u,replaceFilter:o}}exports.ConfigContext=m;exports.StoreContext=P;exports.createExtendableStore=b;exports.createStore=F;exports.defaultState=v;exports.newSearch=C;exports.updateSearch=p;exports.useActions=K;exports.useConfig=w;
|