@nosto/search-js 3.13.1 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ErrorBoundary-CKn3Ecpu.cjs +1 -0
- package/dist/ErrorBoundary-DTRm_60r.js +11 -0
- 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 +17 -15
- package/dist/preact/{inject → common}/src/components/ErrorBoundary.d.ts +1 -1
- package/dist/preact/inject/inject.cjs.js +1 -1
- package/dist/preact/inject/inject.es.js +86 -90
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./jsxRuntime.module-B3sGoTIU.cjs"),u=require("./logger-Boh_C6Bz.cjs"),n=require("preact"),t=require("preact/hooks");function s({children:o}){const[r]=t.useErrorBoundary();return r&&u.logger.error("Error caught in ErrorBoundary",r),e.u(n.Fragment,{children:o})}exports.ErrorBoundary=s;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
+
import { l as m } from "./logger-_fg_Za9y.js";
|
|
3
|
+
import { Fragment as n } from "preact";
|
|
4
|
+
import { useErrorBoundary as u } from "preact/hooks";
|
|
5
|
+
function p({ children: o }) {
|
|
6
|
+
const [r] = u();
|
|
7
|
+
return r && m.error("Error caught in ErrorBoundary", r), /* @__PURE__ */ t(n, { children: o });
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
p as E
|
|
11
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../../ErrorBoundary-CKn3Ecpu.cjs"),g=require("../../isBot-iyBlT_oq.cjs"),o=require("../../jsxRuntime.module-B3sGoTIU.cjs"),u=require("../../useLoadMore-B0JgcUfM.cjs"),p=require("../../pick-rYi1lc2m.cjs"),n=require("../../InfiniteScrollWithObserver-CoPOQr8Q.cjs"),C=require("preact"),e=require("../../useActions-CJ71kc2N.cjs");function q({pageSize:t}){const{loadMore:r}=u.useLoadMore(t);return o.u("button",{onClick:r,children:"More results"})}function s({children:t,loadMoreComponent:r,pageSize:i}){const{loading:c,query:l,response:a}=u.useNostoAppState(f=>p.pick(f,"loading","query","response")),d=!c&&n.hasMoreResults(l,a);return o.u(C.Fragment,{children:[t,d&&(r?o.u(r,{pageSize:i}):o.u(q,{pageSize:i}))]})}const y=!g.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:s;exports.ErrorBoundary=S.ErrorBoundary;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=y;exports.InfiniteScrollWithLink=s;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @module preact/common */
|
|
2
|
+
export { ErrorBoundary } from './src/components/ErrorBoundary';
|
|
2
3
|
export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
|
|
3
4
|
export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
|
|
4
5
|
export { useAutocompleteConfig, useCategoryConfig, useConfig, useSerpConfig } from './src/config/configContext';
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as v } from "../../ErrorBoundary-DTRm_60r.js";
|
|
2
|
+
import { i as f } from "../../isBot-Lnmft0Z0.js";
|
|
2
3
|
import { u as e } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
-
import { u as
|
|
4
|
-
import { p } from "../../pick-DReBictn.js";
|
|
4
|
+
import { u as p, a as c } from "../../useLoadMore-hrNp8P0M.js";
|
|
5
|
+
import { p as l } from "../../pick-DReBictn.js";
|
|
5
6
|
import { h as m, i as d, I as S } from "../../InfiniteScrollWithObserver-6A57AOKr.js";
|
|
6
7
|
import { Fragment as g } from "preact";
|
|
7
|
-
import { S as
|
|
8
|
+
import { S as B, g as O, c as W, f as F, b as N, d as R, a as j, e as w } from "../../useActions-SEyBHGra.js";
|
|
8
9
|
function C({ pageSize: r }) {
|
|
9
|
-
const { loadMore: o } =
|
|
10
|
+
const { loadMore: o } = p(r);
|
|
10
11
|
return /* @__PURE__ */ e("button", { onClick: o, children: "More results" });
|
|
11
12
|
}
|
|
12
13
|
function h({ children: r, loadMoreComponent: o, pageSize: t }) {
|
|
13
|
-
const { loading: s, query: n, response:
|
|
14
|
+
const { loading: s, query: n, response: a } = c((u) => l(u, "loading", "query", "response")), i = !s && m(n, a);
|
|
14
15
|
return /* @__PURE__ */ e(g, { children: [
|
|
15
16
|
r,
|
|
16
|
-
|
|
17
|
+
i && (o ? /* @__PURE__ */ e(o, { pageSize: t }) : /* @__PURE__ */ e(C, { pageSize: t }))
|
|
17
18
|
] });
|
|
18
19
|
}
|
|
19
|
-
const
|
|
20
|
+
const L = !f() && d() ? S : h;
|
|
20
21
|
export {
|
|
21
|
-
|
|
22
|
+
v as ErrorBoundary,
|
|
23
|
+
L as InfiniteScroll,
|
|
22
24
|
h as InfiniteScrollWithLink,
|
|
23
|
-
|
|
25
|
+
B as StoreContext,
|
|
24
26
|
O as createExtendableStore,
|
|
25
27
|
W as createStore,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
F as defaultState,
|
|
29
|
+
N as useAutocompleteConfig,
|
|
30
|
+
R as useCategoryConfig,
|
|
31
|
+
j as useConfig,
|
|
32
|
+
w as useSerpConfig
|
|
31
33
|
};
|
|
@@ -3,6 +3,6 @@ import { ComponentChildren } from 'preact';
|
|
|
3
3
|
* Error boundary component to log UI level errors
|
|
4
4
|
* @group Components
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export declare function ErrorBoundary({ children }: {
|
|
7
7
|
children: ComponentChildren;
|
|
8
8
|
}): import("preact").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-99syi-nl.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-99syi-nl.cjs"),L=require("../../CategoryPageProvider-Clj40F3F.cjs"),m=require("../../useActions-CJ71kc2N.cjs"),T=require("../../SerpPageProvider-pR-E8S6m.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),g=require("../../ErrorBoundary-CKn3Ecpu.cjs"),b=require("../../bindInput-BnKvCky1.cjs"),x=require("../../unique-BXXNictB.cjs"),f=require("preact"),P=require("../../logger-Boh_C6Bz.cjs"),v=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../search-DTqo1D6Y.cjs");function D(e){let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function E(e){return Array.from(document.querySelectorAll(e))}function O(e){const t=[];let n=e.parentNode;for(;n&&n!==document&&n instanceof Element;)t.push(n),n=n.parentNode;return t}function A([e,t],n){const o=r=>{const i=r.target;i instanceof HTMLElement&&e&&i!==e&&i!==t&&!O(i).includes(e)&&n()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function q(e,t){e.tabIndex=0,e.addEventListener("blur",t)}function S(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=E(e);if(o.length>0)return n(o);const r=new MutationObserver(()=>{const s=E(e);s.length>0&&(r.disconnect(),clearTimeout(i),n(s))}),i=setTimeout(()=>{r.disconnect(),P.logger.warn(`Timed out (${t}) while waiting for element ${e}`),n([])},t);r.observe(document.body,{childList:!0,subtree:!0})})}const N=f.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&&v.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=S(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(j=>j())},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 F(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 K(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 Q(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 M(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=B(t,r);r.onHighlightChange(()=>{l(o,r.element)}),r.show();const c=x.measure("renderHistory");l(o,r.element),c()}async function U(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 _(e,t,n){const{config:o,debouncer:r}=n;if(r(()=>{}),e.length>=o.minQueryLength)return I(t,n.dropdown,n.history);if(o.historyEnabled)return I(t,n.history,n.dropdown)}function I(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 z(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 G(e,t){const{inputCssSelector:n,timeout:o}=e,r=S(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=>{J(s,e,t)})}async function J(e,t,n){const{config:o,dropdownCssSelector:r}=t,i=F(e,r),s=K(e,r,o.historySize),l={...t,input:e,dropdown:i,history:s,store:n,debouncer:D(o.debounceDelay)};W(l),e.setAttribute("data-nosto-element","search-input"),n.updateState({historyItems:s.get()}),b.disableNativeAutocomplete(e),n.onInit(()=>{V(l)}),b.bindInput(e,{onInput:c=>U(c,l),onFocus:c=>M(c,l),onClick:c=>Q(c,l),onSubmit:c=>z(c,l),onKeyDown:(c,h)=>_(c,h,l)}),q(s.element,s.hide),q(i.element,i.hide),A([s.element,e],s.hide),A([i.element,e],i.hide)}function V(e){const{dropdown:t,renderAutocomplete:n}=e;if(!n)return;const o=B(e,t);t.onHighlightChange(()=>{o(n,t.element)});const r=x.measure("renderAutocomplete");o(n,t.element),r()}async function W(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();f.render(u.u(g.ErrorBoundary,{children:u.u(w.AutocompletePageProvider,{config:o,store:r,children:c})}),l)}function B(e,t){const{config:n,store:o}=e,r=$(e,t);return t.onHighlightChange(()=>{r.highlightedElementIndex=t.highlightedIndex()}),(i,s)=>f.render(u.u(g.ErrorBoundary,{children:u.u(w.AutocompletePageProvider,{config:n,store:o,children:u.u(N,{value:r,children:i()})})}),s)}async function R({cssSelector:e,timeout:t,renderComponent:n}){const o=S(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&&P.logger.warn(`Multiple (${r.length}) elements found for selector: ${o}`),f.render(n(),r[0])}async function X(e,t){const{render:n}=e,o=await n();R({...e,renderComponent:()=>u.u(g.ErrorBoundary,{children:u.u(L.CategoryPageProvider,{store:t,config:e.config,children:o})})})}async function Y(e,t){const{render:n}=e,o=await n();R({...e,renderComponent:()=>u.u(g.ErrorBoundary,{children:u.u(T.SearchPageProvider,{store:t,config:e.config,children:o})})})}async function Z({autocomplete:e,category:t,serp:n}){const o={};if(e){const r=m.createStore({query:e.query});await G({...e,config:w.makeAutocompleteConfig(e.config)},r),o.autocomplete={store:r}}if(t){const r=m.createStore({query:t.query});await X({...t,config:L.makeCategoryConfig(t.config)},r),o.category={store:r}}if(n){const r=m.createStore({query:n.query});await Y({...n,config:T.makeSerpConfig(n.config)},r),o.serp={store:r}}return o}exports.AutocompleteContext=N;exports.init=Z;
|
|
@@ -1,39 +1,35 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { C as R, m as
|
|
3
|
-
import { n as
|
|
4
|
-
import { S as
|
|
1
|
+
import { A as I, m as D } from "../../AutocompletePageProvider-HeGU8tjH.js";
|
|
2
|
+
import { C as R, m as O } from "../../CategoryPageProvider-Bou8i9Tx.js";
|
|
3
|
+
import { n as L, c as p } from "../../useActions-SEyBHGra.js";
|
|
4
|
+
import { S as $, m as j } from "../../SerpPageProvider-B-W6nCqu.js";
|
|
5
5
|
import { u as d } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { s as
|
|
12
|
-
import { g as
|
|
13
|
-
function
|
|
6
|
+
import { E as u } from "../../ErrorBoundary-DTRm_60r.js";
|
|
7
|
+
import { d as F, b as B } from "../../bindInput-CCx0Fhsg.js";
|
|
8
|
+
import { a as T } from "../../unique-Cv2g464w.js";
|
|
9
|
+
import { createContext as K, render as y } from "preact";
|
|
10
|
+
import { l as x } from "../../logger-_fg_Za9y.js";
|
|
11
|
+
import { s as Q } from "../../index.es-XNBESE3P.js";
|
|
12
|
+
import { g as w, a as U } from "../../search-sC5QgJmw.js";
|
|
13
|
+
function v(e) {
|
|
14
14
|
let t;
|
|
15
15
|
return (n) => {
|
|
16
16
|
t && clearTimeout(t), t = setTimeout(n, e);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const [t] = U();
|
|
21
|
-
return t && C.error("Error caught in ErrorBoundary", t), /* @__PURE__ */ d(K, { children: e });
|
|
22
|
-
}
|
|
23
|
-
function b(e) {
|
|
19
|
+
function S(e) {
|
|
24
20
|
return Array.from(document.querySelectorAll(e));
|
|
25
21
|
}
|
|
26
|
-
function
|
|
22
|
+
function M(e) {
|
|
27
23
|
const t = [];
|
|
28
24
|
let n = e.parentNode;
|
|
29
25
|
for (; n && n !== document && n instanceof Element; )
|
|
30
26
|
t.push(n), n = n.parentNode;
|
|
31
27
|
return t;
|
|
32
28
|
}
|
|
33
|
-
function
|
|
29
|
+
function b([e, t], n) {
|
|
34
30
|
const o = (r) => {
|
|
35
31
|
const i = r.target;
|
|
36
|
-
i instanceof HTMLElement && e && i !== e && i !== t && !
|
|
32
|
+
i instanceof HTMLElement && e && i !== e && i !== t && !M(i).includes(e) && n();
|
|
37
33
|
};
|
|
38
34
|
return document.addEventListener("click", o), {
|
|
39
35
|
destroy: () => {
|
|
@@ -41,10 +37,10 @@ function E([e, t], n) {
|
|
|
41
37
|
}
|
|
42
38
|
};
|
|
43
39
|
}
|
|
44
|
-
function
|
|
40
|
+
function E(e, t) {
|
|
45
41
|
e.tabIndex = 0, e.addEventListener("blur", t);
|
|
46
42
|
}
|
|
47
|
-
function
|
|
43
|
+
function C(e) {
|
|
48
44
|
return typeof e == "string" ? {
|
|
49
45
|
selector: e,
|
|
50
46
|
position: "last"
|
|
@@ -55,14 +51,14 @@ function w(e) {
|
|
|
55
51
|
}
|
|
56
52
|
function H({ selector: e, timeout: t = 500 }) {
|
|
57
53
|
return new Promise((n) => {
|
|
58
|
-
const o =
|
|
54
|
+
const o = S(e);
|
|
59
55
|
if (o.length > 0)
|
|
60
56
|
return n(o);
|
|
61
57
|
const r = new MutationObserver(() => {
|
|
62
|
-
const s =
|
|
58
|
+
const s = S(e);
|
|
63
59
|
s.length > 0 && (r.disconnect(), clearTimeout(i), n(s));
|
|
64
60
|
}), i = setTimeout(() => {
|
|
65
|
-
r.disconnect(),
|
|
61
|
+
r.disconnect(), x.warn(`Timed out (${t}) while waiting for element ${e}`), n([]);
|
|
66
62
|
}, t);
|
|
67
63
|
r.observe(document.body, {
|
|
68
64
|
childList: !0,
|
|
@@ -70,7 +66,7 @@ function H({ selector: e, timeout: t = 500 }) {
|
|
|
70
66
|
});
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
|
-
const
|
|
69
|
+
const z = K({
|
|
74
70
|
reportProductClick: () => {
|
|
75
71
|
},
|
|
76
72
|
reportKeywordClick: () => {
|
|
@@ -79,11 +75,11 @@ const J = Q({
|
|
|
79
75
|
},
|
|
80
76
|
highlightedElementIndex: -1
|
|
81
77
|
});
|
|
82
|
-
function
|
|
83
|
-
const { dropdown: n, history: o, store: r, input: i, onNavigateToSearch: s } = e, a = (c,
|
|
78
|
+
function G(e, t) {
|
|
79
|
+
const { dropdown: n, history: o, store: r, input: i, onNavigateToSearch: s } = e, a = (c, h) => {
|
|
84
80
|
n.hide(), o.hide(), c && (o.add(c), r.updateState({
|
|
85
81
|
historyItems: o.get()
|
|
86
|
-
}),
|
|
82
|
+
}), h && Q((l) => l.recordSearchSubmit(c)), i.value = c);
|
|
87
83
|
};
|
|
88
84
|
return {
|
|
89
85
|
reportProductClick: (c) => {
|
|
@@ -105,7 +101,7 @@ function N(e, t, n) {
|
|
|
105
101
|
return e.parentElement;
|
|
106
102
|
const l = document.createElement("div");
|
|
107
103
|
return l.className = "nosto-autocomplete-wrapper", e.parentNode?.insertBefore(l, e.nextSibling), l.appendChild(e), l;
|
|
108
|
-
})(), r =
|
|
104
|
+
})(), r = C(n), i = r && document.querySelector(r.selector);
|
|
109
105
|
if (i) {
|
|
110
106
|
const l = document.createElement("form");
|
|
111
107
|
l.className = "nosto-dropdown-form", l.appendChild(t), r.position === "first" ? i.prepend(l) : i.appendChild(l);
|
|
@@ -119,7 +115,7 @@ function N(e, t, n) {
|
|
|
119
115
|
f === 0 && (m = -1), s.index = m >= 0 ? m % f : f - 1, s.onChangeListeners.forEach((P) => P());
|
|
120
116
|
}, c = () => {
|
|
121
117
|
s.index = -1, s.onChangeListeners.forEach((l) => l());
|
|
122
|
-
},
|
|
118
|
+
}, h = () => s.index;
|
|
123
119
|
return {
|
|
124
120
|
element: t,
|
|
125
121
|
hide: () => {
|
|
@@ -130,15 +126,15 @@ function N(e, t, n) {
|
|
|
130
126
|
},
|
|
131
127
|
isOpen: () => t.style.display !== "none",
|
|
132
128
|
goDown: () => {
|
|
133
|
-
const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m =
|
|
129
|
+
const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
|
|
134
130
|
a(l, m + 1);
|
|
135
131
|
},
|
|
136
132
|
goUp: () => {
|
|
137
|
-
const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m =
|
|
133
|
+
const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
|
|
138
134
|
a(l, m - 1);
|
|
139
135
|
},
|
|
140
136
|
highlight: a,
|
|
141
|
-
highlightedIndex:
|
|
137
|
+
highlightedIndex: h,
|
|
142
138
|
submitHighlightedItem: (l) => {
|
|
143
139
|
Array.from(t.querySelectorAll(".ns-autocomplete-element"))[l]?.click();
|
|
144
140
|
},
|
|
@@ -147,27 +143,27 @@ function N(e, t, n) {
|
|
|
147
143
|
}
|
|
148
144
|
};
|
|
149
145
|
}
|
|
150
|
-
function
|
|
146
|
+
function J(e, t) {
|
|
151
147
|
const n = document.createElement("div");
|
|
152
148
|
return n.className = "nosto-autocomplete-dropdown", {
|
|
153
149
|
...N(e, n, t),
|
|
154
150
|
element: n
|
|
155
151
|
};
|
|
156
152
|
}
|
|
157
|
-
const
|
|
158
|
-
function
|
|
153
|
+
const g = "nosto:search-js:history";
|
|
154
|
+
function V(e, t, n) {
|
|
159
155
|
const o = document.createElement("div");
|
|
160
156
|
return o.className = "nosto-autocomplete-history", {
|
|
161
157
|
...N(e, o, t),
|
|
162
158
|
element: o,
|
|
163
159
|
add: (i) => {
|
|
164
|
-
const a = (
|
|
165
|
-
a.push(i),
|
|
160
|
+
const a = (w(g) ?? []).filter((c) => c !== i).slice(n ? -n : 0);
|
|
161
|
+
a.push(i), U(g, a);
|
|
166
162
|
},
|
|
167
|
-
get: () => (
|
|
163
|
+
get: () => (w(g) ?? []).reverse().filter((s) => !!s)
|
|
168
164
|
};
|
|
169
165
|
}
|
|
170
|
-
async function
|
|
166
|
+
async function W(e, { config: t, dropdown: n, history: o, renderHistory: r, store: i }) {
|
|
171
167
|
const { historyEnabled: s, minQueryLength: a } = t;
|
|
172
168
|
if (e.length < a && s && r && !o.isOpen()) {
|
|
173
169
|
o.show();
|
|
@@ -177,9 +173,9 @@ async function Y(e, { config: t, dropdown: n, history: o, renderHistory: r, stor
|
|
|
177
173
|
return;
|
|
178
174
|
n.hide();
|
|
179
175
|
const c = i.getState()?.query?.query;
|
|
180
|
-
c && c !== e && await
|
|
176
|
+
c && c !== e && await L({ config: t, store: i }, { query: e }), n.show();
|
|
181
177
|
}
|
|
182
|
-
async function
|
|
178
|
+
async function X(e, t) {
|
|
183
179
|
const { config: n, renderHistory: o, history: r } = t, { historyEnabled: i, minQueryLength: s } = n;
|
|
184
180
|
if (!o || e.length >= s || !i || r.isOpen())
|
|
185
181
|
return;
|
|
@@ -187,10 +183,10 @@ async function Z(e, t) {
|
|
|
187
183
|
r.onHighlightChange(() => {
|
|
188
184
|
a(o, r.element);
|
|
189
185
|
}), r.show();
|
|
190
|
-
const c =
|
|
186
|
+
const c = T("renderHistory");
|
|
191
187
|
a(o, r.element), c();
|
|
192
188
|
}
|
|
193
|
-
async function
|
|
189
|
+
async function Y(e, { config: t, dropdown: n, history: o, store: r, debouncer: i }) {
|
|
194
190
|
const { minQueryLength: s, historyEnabled: a } = t;
|
|
195
191
|
if (e.length < s && !a) {
|
|
196
192
|
n.hide(), o.hide();
|
|
@@ -201,18 +197,18 @@ async function _(e, { config: t, dropdown: n, history: o, store: r, debouncer: i
|
|
|
201
197
|
return;
|
|
202
198
|
}
|
|
203
199
|
o.hide(), i(async () => {
|
|
204
|
-
|
|
200
|
+
L({ config: t, store: r }, { query: e }), n.show();
|
|
205
201
|
});
|
|
206
202
|
}
|
|
207
|
-
function
|
|
203
|
+
function Z(e, t, n) {
|
|
208
204
|
const { config: o, debouncer: r } = n;
|
|
209
205
|
if (r(() => {
|
|
210
206
|
}), e.length >= o.minQueryLength)
|
|
211
|
-
return
|
|
207
|
+
return A(t, n.dropdown, n.history);
|
|
212
208
|
if (o.historyEnabled)
|
|
213
|
-
return
|
|
209
|
+
return A(t, n.history, n.dropdown);
|
|
214
210
|
}
|
|
215
|
-
function
|
|
211
|
+
function A(e, t, n) {
|
|
216
212
|
if (!t.isOpen() && e === "ArrowDown") {
|
|
217
213
|
t.show(), n.hide();
|
|
218
214
|
return;
|
|
@@ -228,46 +224,46 @@ function I(e, t, n) {
|
|
|
228
224
|
}
|
|
229
225
|
}
|
|
230
226
|
}
|
|
231
|
-
function
|
|
227
|
+
function _(e, { config: t, dropdown: n, history: o, onNavigateToSearch: r, store: i }) {
|
|
232
228
|
n.hide(), o.hide(), !(e.length < t.minQueryLength) && (o.add(e), i.updateState({
|
|
233
229
|
historyItems: o.get()
|
|
234
230
|
}), r?.({
|
|
235
231
|
query: e
|
|
236
232
|
}));
|
|
237
233
|
}
|
|
238
|
-
async function
|
|
239
|
-
const { inputCssSelector: n, timeout: o } = e, r =
|
|
234
|
+
async function ee(e, t) {
|
|
235
|
+
const { inputCssSelector: n, timeout: o } = e, r = C(n).selector, i = await H({
|
|
240
236
|
selector: r,
|
|
241
237
|
timeout: o
|
|
242
238
|
});
|
|
243
239
|
if (i.length === 0)
|
|
244
240
|
throw new Error(`No elements found for selector: ${r}`);
|
|
245
241
|
i.forEach((s) => {
|
|
246
|
-
|
|
242
|
+
te(s, e, t);
|
|
247
243
|
});
|
|
248
244
|
}
|
|
249
|
-
async function
|
|
250
|
-
const { config: o, dropdownCssSelector: r } = t, i =
|
|
245
|
+
async function te(e, t, n) {
|
|
246
|
+
const { config: o, dropdownCssSelector: r } = t, i = J(e, r), s = V(e, r, o.historySize), a = {
|
|
251
247
|
...t,
|
|
252
248
|
input: e,
|
|
253
249
|
dropdown: i,
|
|
254
250
|
history: s,
|
|
255
251
|
store: n,
|
|
256
|
-
debouncer:
|
|
252
|
+
debouncer: v(o.debounceDelay)
|
|
257
253
|
};
|
|
258
|
-
|
|
254
|
+
oe(a), e.setAttribute("data-nosto-element", "search-input"), n.updateState({
|
|
259
255
|
historyItems: s.get()
|
|
260
|
-
}),
|
|
261
|
-
|
|
262
|
-
}),
|
|
263
|
-
onInput: (c) =>
|
|
264
|
-
onFocus: (c) =>
|
|
265
|
-
onClick: (c) =>
|
|
266
|
-
onSubmit: (c) =>
|
|
267
|
-
onKeyDown: (c,
|
|
268
|
-
}),
|
|
256
|
+
}), F(e), n.onInit(() => {
|
|
257
|
+
ne(a);
|
|
258
|
+
}), B(e, {
|
|
259
|
+
onInput: (c) => Y(c, a),
|
|
260
|
+
onFocus: (c) => X(c, a),
|
|
261
|
+
onClick: (c) => W(c, a),
|
|
262
|
+
onSubmit: (c) => _(c, a),
|
|
263
|
+
onKeyDown: (c, h) => Z(c, h, a)
|
|
264
|
+
}), E(s.element, s.hide), E(i.element, i.hide), b([s.element, e], s.hide), b([i.element, e], i.hide);
|
|
269
265
|
}
|
|
270
|
-
function
|
|
266
|
+
function ne(e) {
|
|
271
267
|
const { dropdown: t, renderAutocomplete: n } = e;
|
|
272
268
|
if (!n)
|
|
273
269
|
return;
|
|
@@ -275,10 +271,10 @@ function re(e) {
|
|
|
275
271
|
t.onHighlightChange(() => {
|
|
276
272
|
o(n, t.element);
|
|
277
273
|
});
|
|
278
|
-
const r =
|
|
274
|
+
const r = T("renderAutocomplete");
|
|
279
275
|
o(n, t.element), r();
|
|
280
276
|
}
|
|
281
|
-
async function
|
|
277
|
+
async function oe(e) {
|
|
282
278
|
const { input: t, renderSpeechToText: n, config: o, store: r } = e;
|
|
283
279
|
if (!n) return;
|
|
284
280
|
const i = "ns-autocomplete-voice-position";
|
|
@@ -287,47 +283,47 @@ async function ie(e) {
|
|
|
287
283
|
a.className = i, t.insertAdjacentElement("afterend", a);
|
|
288
284
|
const c = await n();
|
|
289
285
|
y(
|
|
290
|
-
/* @__PURE__ */ d(
|
|
286
|
+
/* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(I, { config: o, store: r, children: c }) }),
|
|
291
287
|
a
|
|
292
288
|
);
|
|
293
289
|
}
|
|
294
290
|
function q(e, t) {
|
|
295
|
-
const { config: n, store: o } = e, r =
|
|
291
|
+
const { config: n, store: o } = e, r = G(e, t);
|
|
296
292
|
return t.onHighlightChange(() => {
|
|
297
293
|
r.highlightedElementIndex = t.highlightedIndex();
|
|
298
294
|
}), (i, s) => y(
|
|
299
|
-
/* @__PURE__ */ d(
|
|
295
|
+
/* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(I, { config: n, store: o, children: /* @__PURE__ */ d(z, { value: r, children: i() }) }) }),
|
|
300
296
|
s
|
|
301
297
|
);
|
|
302
298
|
}
|
|
303
299
|
async function k({ cssSelector: e, timeout: t, renderComponent: n }) {
|
|
304
|
-
const o =
|
|
300
|
+
const o = C(e).selector, r = await H({
|
|
305
301
|
selector: o,
|
|
306
302
|
timeout: t ?? 100
|
|
307
303
|
});
|
|
308
304
|
if (r.length === 0)
|
|
309
305
|
throw new Error(`No elements found for selector: ${o}`);
|
|
310
|
-
r.length > 1 &&
|
|
306
|
+
r.length > 1 && x.warn(`Multiple (${r.length}) elements found for selector: ${o}`), y(n(), r[0]);
|
|
311
307
|
}
|
|
312
|
-
async function
|
|
308
|
+
async function re(e, t) {
|
|
313
309
|
const { render: n } = e, o = await n();
|
|
314
310
|
k({
|
|
315
311
|
...e,
|
|
316
|
-
renderComponent: () => /* @__PURE__ */ d(
|
|
312
|
+
renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(R, { store: t, config: e.config, children: o }) })
|
|
317
313
|
});
|
|
318
314
|
}
|
|
319
|
-
async function
|
|
315
|
+
async function ie(e, t) {
|
|
320
316
|
const { render: n } = e, o = await n();
|
|
321
317
|
k({
|
|
322
318
|
...e,
|
|
323
|
-
renderComponent: () => /* @__PURE__ */ d(
|
|
319
|
+
renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d($, { store: t, config: e.config, children: o }) })
|
|
324
320
|
});
|
|
325
321
|
}
|
|
326
|
-
async function
|
|
322
|
+
async function Ce({ autocomplete: e, category: t, serp: n }) {
|
|
327
323
|
const o = {};
|
|
328
324
|
if (e) {
|
|
329
|
-
const r =
|
|
330
|
-
await
|
|
325
|
+
const r = p({ query: e.query });
|
|
326
|
+
await ee(
|
|
331
327
|
{
|
|
332
328
|
...e,
|
|
333
329
|
config: D(e.config)
|
|
@@ -336,21 +332,21 @@ async function Se({ autocomplete: e, category: t, serp: n }) {
|
|
|
336
332
|
), o.autocomplete = { store: r };
|
|
337
333
|
}
|
|
338
334
|
if (t) {
|
|
339
|
-
const r =
|
|
340
|
-
await
|
|
335
|
+
const r = p({ query: t.query });
|
|
336
|
+
await re(
|
|
341
337
|
{
|
|
342
338
|
...t,
|
|
343
|
-
config:
|
|
339
|
+
config: O(t.config)
|
|
344
340
|
},
|
|
345
341
|
r
|
|
346
342
|
), o.category = { store: r };
|
|
347
343
|
}
|
|
348
344
|
if (n) {
|
|
349
|
-
const r =
|
|
350
|
-
await
|
|
345
|
+
const r = p({ query: n.query });
|
|
346
|
+
await ie(
|
|
351
347
|
{
|
|
352
348
|
...n,
|
|
353
|
-
config:
|
|
349
|
+
config: j(n.config)
|
|
354
350
|
},
|
|
355
351
|
r
|
|
356
352
|
), o.serp = { store: r };
|
|
@@ -358,6 +354,6 @@ async function Se({ autocomplete: e, category: t, serp: n }) {
|
|
|
358
354
|
return o;
|
|
359
355
|
}
|
|
360
356
|
export {
|
|
361
|
-
|
|
362
|
-
|
|
357
|
+
z as AutocompleteContext,
|
|
358
|
+
Ce as init
|
|
363
359
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -103,7 +103,7 @@
|
|
|
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.
|
|
106
|
+
"@types/node": "^24.4.0",
|
|
107
107
|
"@vitest/coverage-v8": "^3.2.4",
|
|
108
108
|
"concurrently": "^9.2.1",
|
|
109
109
|
"copyfiles": "^2.4.1",
|
|
@@ -117,9 +117,9 @@
|
|
|
117
117
|
"eslint-plugin-unused-imports": "^4.2.0",
|
|
118
118
|
"husky": "^9.1.7",
|
|
119
119
|
"isbot": "^5.1.30",
|
|
120
|
-
"jsdom": "^
|
|
120
|
+
"jsdom": "^27.0.0",
|
|
121
121
|
"prettier": "^3.6.2",
|
|
122
|
-
"typedoc": "^0.28.
|
|
122
|
+
"typedoc": "^0.28.13",
|
|
123
123
|
"typescript": "^5.9.2",
|
|
124
124
|
"typescript-eslint": "^8.43.0",
|
|
125
125
|
"vite": "^7.1.5",
|