PageSourceSearch

https://www.frandroid.com/wp-content/mu-plugins/optimus/build/js/chunks/SearchField-aO3WjFcp.js

js frandroid.com collected 2026-09-24 08:28:00 UTC 15,372 bytes, 1 lines download raw bytes

1import{r as s,j as t}from"./react-Bs4hDxVO.js";import{T as X}from"./TextInput-CLPnbPML.js";import{N as Y,P as D,B as Z,v as ee,w as te}from"./hydrateServerComponents-CgeGZCoY.js";const ne="dropdown___fiJm8",se="loadingBar___bQPi-",re="skeletonPulse___K1Cpu",ae="section___p8004",oe="item___gxmQB",le="active___xn4mi",ie="contentEnter___okDxm",N={dropdown:ne,loadingBar:se,skeletonPulse:re,section:ae,item:oe,active:le,contentEnter:ie},W=s.createContext(null);function T(){const n=s.useContext(W);if(!n)throw new Error("Combobox compound components must be used within <Combobox>");return n}function ce({open:n,onOpenChange:l,onSelect:u,inputValue:o="",inputSelector:h=".js-search-input",listboxLabel:x="Suggestions",children:R}){const[i,f]=s.useState(null),v=s.useId(),w=s.useRef(null),j=s.useRef(null),g=s.useRef([]),C=s.useRef(0),I=s.useRef(n);I.current=n;const S=s.useRef(i);S.current=i;const _=s.useRef(n);n&&!_.current&&f(null),_.current=n,s.useEffect(()=>{const r=document.querySelector(h);if(!r)return;j.current=r,r.setAttribute("role","combobox"),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-autocomplete","list"),r.setAttribute("aria-controls",v);const y=k=>{const m=k;if(!I.current)return;const A=g.current.length;if(!(A===0&&m.key!=="Escape"&&m.key!=="Tab"))switch(m.key){case"ArrowDown":m.preventDefault(),m.stopPropagation(),f(b=>b===null||b>=A-1?0:b+1);break;case"ArrowUp":m.preventDefault(),m.stopPropagation(),f(b=>b===null||b<=0?A-1:b-1);break;case"Enter":if(S.current!==null){m.preventDefault(),m.stopPropagation();const b=g.current[S.current],e=b==null?void 0:b.getAttribute("data-value");e&&(u==null||u(e))}break;case"Escape":l(!1),f(null);break;case"Home":m.preventDefault(),m.stopPropagation(),f(0);break;case"End":m.preventDefault(),m.stopPropagation(),f(A-1);break;case"Tab":l(!1),f(null);break}},a=k=>{if(!I.current)return;const m=k.target;w.current&&!w.current.contains(m)&&r&&!r.contains(m)&&(l(!1),f(null))};return r.addEventListener("keydown",y),document.addEventListener("click",a),()=>{r.removeEventListener("keydown",y),document.removeEventListener("click",a),r.removeAttribute("role"),r.removeAttribute("aria-haspopup"),r.removeAttribute("aria-autocomplete"),r.removeAttribute("aria-controls"),r.removeAttribute("aria-expanded"),r.removeAttribute("aria-activedescendant")}},[h,v,l,u]),s.useEffect(()=>{const r=j.current;r&&(r.setAttribute("aria-expanded",String(n)),n&&i!==null?r.setAttribute("aria-activedescendant",`${v}-item-${i}`):r.removeAttribute("aria-activedescendant"))},[n,i,v]),s.useEffect(()=>{var r;i!==null&&((r=g.current[i])==null||r.scrollIntoView({block:"nearest"}))},[i]),C.current=0,g.current=[];const E=()=>
1C.current++,P=(r,y)=>{g.current[r]=y};return n?t.jsx(W.Provider,{value:{open:n,activeIndex:i,listboxId:v,listboxLabel:x,inputValue:o,onSelect:u,dropdownRef:w,claimIndex:E,setItemRef:P},children:R}):null}function ue({loading:n=!1,className:l,children:u}){const{listboxId:o,listboxLabel:h,dropdownRef:x}=T();return t.jsxs("div",{id:o,ref:x,className:[N.dropdown,l].filter(Boolean).join(" "),role:"listbox","aria-label":h,"aria-busy":n,children:[t.jsx("div",{className:N.loadingBar,role:"progressbar","aria-label":"Chargement","aria-hidden":!n,style:{opacity:n?1:0}}),u]})}function V({label:n,className:l,children:u}){return t.jsxs("div",{className:[`py-100 ${N.section} ${N.contentEnter}`,l].filter(Boolean).join(" "),children:[t.jsx("div",{className:"text-font-item text-[0.65rem] font-bold tracking-[0.08em] px-300 pt-200 pb-100 uppercase",children:n}),t.jsx("ul",{className:"list-none m-0 p-0",role:"group","aria-label":n,children:u})]})}function F({value:n,className:l,children:u}){const{activeIndex:o,listboxId:h,onSelect:x,claimIndex:R,setItemRef:i}=T(),f=R(),v=o===f,w=typeof u=="function",j=()=>{x==null||x(n)},g={id:`${h}-item-${f}`,role:"option","aria-selected":v};return t.jsx("li",{ref:C=>i(f,C),"data-value":n,className:[`flex items-center ${N.item}`,v?N.active:"",l].filter(Boolean).join(" "),...w?{}:g,onClick:j,children:w?u(g):u})}function de({className:n,children:l}){return t.jsx("div",{className:[`py-600 px-300 text-center text-font-item ${N.contentEnter}`,n].filter(Boolean).join(" "),children:l})}function fe({className:n,children:l}){return l?t.jsx("div",{className:[N.contentEnter,n].filter(Boolean).join(" "),children:l}):t.jsx("div",{className:[N.contentEnter,n].filter(Boolean).join(" "),children:[...Array(3)].map((u,o)=>t.jsxs("div",{className:"flex items-center gap-300 p-300",children:[t.jsx("div",{className:`w-10 h-10 rounded-default ${N.skeletonPulse}`}),t.jsx("div",{className:"flex-1",children:t.jsx("div",{className:`h-3 rounded-default ${N.skeletonPulse}`,style:{width:`${70-o*15}%`}})})]},o))})}function me(n){return new DOMParser().parseFromString(n,"text/html").body.textContent??n}function G({text:n,keyword:l,disabled:u=!1,className:o}){const{inputValue:h}=T(),x=l??h,R=me(n);if(u||!x)return t.jsx("span",{className:o,children:R});const i=x.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=R.split(new RegExp(`(${i})`,"gi"));return t.jsx("span",{className:o,children:f.map((v,w)=>w%2===1?t.jsx("mark",{children:v},w):v)})}function pe(n){return typeof document>"u"?!1:document.querySelector(n)!==null}const he="[data-search-suggest]";function xe(){return pe(he)}const ge="title___OebYx",be="notationCompact___KcQpI",ve="priceTag___6HUx2",ye="footer___WLk3T",we="seeAll___6HRbp",B={title:ge,notationCompact:be,priceTag:ve,footer:ye,seeAll:we},je=200,q=4,H=4,ke=3,Re=5,_e="/wp-json/humanoid/v1/public/es/suggest",K="datalayerSearchClickResultsAttributes",M={test:{label:"Test",variant:"secondary"},guide:{label:"Guide",variant:"primary"},"how-to":{label:"Tuto",variant:"primary"},avis:{label:"Avis",variant:"default"}};function z(n){return n.trim().split(/\s+/).filter(Boolean).length}function J({inputSelector:n=".js-search-input"}={}){const[l,u]=s.useState(null),[o,h]=s.useState(!1),[x,R]=s.useState(!1),[i,f]=s.useState(""),[v,w]=s.useState(!1),j=s.useRef(null),g=s.useRef(null),C=s.useRef(new Map),I=s.useCallback(async e=>{var p;(p=j.current)==null||p.abort();const c=new AbortController;j.current=c,h(!0);try{const d=`${_e}?keyword=${encodeURIComponent(e)}`,L=await fetch(d,{signal:c.signal});if(!L.ok)return;const U=await L.json(),$=U.data??U;if(!($!=null&&$.posts)||!($!=null&&$.products))return;u($),R(!0)}catch(d){if(d instanceof DOMException&&d.name==="AbortError")return;console.error("[SearchSuggest] Fetch error:",d)}finally{h(!1)}},[]),S=s.useCallback(e=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>I(e),je)},[I]),_=s.useRef(null),E=s.useCallback(e=>{var c,p;R(e),_.current||(_.current=document.querySelector("#search-wrapper")),e?(c=_.current)==null||c.classList.add("suggest-open"):(p=_.current)==null||p.classList.remove("suggest-open")},[]);s.useEffect(()=>{if(!xe())return;w(!0);const e=document.querySelector(n);if(!e)return;const c=()=>{const d=e.value;if(d.length===0){E(!1),u(null),f("");return}if(d.length<q||z(d)>=H){E(!1);return}f(d),E(!0),S(d)},p=()=>{const d=e.value;d.length>=q&&z(d)<H&&(f(d),h(!0),E(!0),S(d))};return e.addEventListener("input",c),e.addEventListener("focus",p),()=>{var d;e.removeEventListener("input",c),e.removeEventListener("focus",p),(d=j.current)==null||d.abort(),g.current&&clearTimeout(g.current)}},[S,E]);const P=s.useCallback(e=>{const c=C.current.get(e);c&&sessionStorage.setItem(K,JSON.stringify(c)),window.location.href=e},[]),r=e=>{const c=e.currentTarget.getAttribute("data-gtm-search");c&&sessionStorage.setItem(K,c)};if(!v)return null;const{products:y=[],posts:a=[]}=l??{},k=y.length>0||a.length>0,m=o&&!l,A=!!l&&!k;
1C.current.clear(),y.forEach((e,c)=>{const p={event:"search-click-results","search-mode":"suggest","search-query":i,"result-type":"product",position:c+1};C.current.set(e.url,{...p,"card-link-type":"fiche-produit-titre"})}),a.forEach((e,c)=>{C.current.set(e.url,{event:"search-click-results","search-mode":"suggest","search-query":i,"result-type":"post",position:c+1,"card-link-type":"article-titre"})});const b=(()=>{if(o)return"Chargement des suggestions…";if(A)return`Aucun résultat pour ${i}`;if(k){const e=[];return y.length&&e.push(`${y.length} produit${y.length>1?"s":""}`),a.length&&e.push(`${a.length} article${a.length>1?"s":""}`),`${e.join(" et ")} trouvé${y.length+a.length>1?"s":""}`}return""})();return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true",children:b}),t.jsx(ce,{open:x,onOpenChange:E,onSelect:P,inputValue:i,inputSelector:n,listboxLabel:"Suggestions de recherche",children:t.jsxs(ue,{loading:o,children:[m&&t.jsx(fe,{}),A&&t.jsxs(de,{children:[t.jsxs("div",{className:"text-2xs font-semibold font-fontFamilySecondary",children:["Aucun résultat pour « ",i," »"]}),t.jsx("div",{className:"text-[0.7rem] mt-100",children:"Essayez avec d'autres termes"})]}),y.length>0&&t.jsx(V,{label:"Produits",children:y.slice(0,ke).map((e,c)=>{const p={event:"search-click-results","search-mode":"suggest","search-query":i,"result-type":"product",position:c+1},d=[e.title,e.testRating!=null?`${e.testRating}/10`:null,e.price!=null?`${e.price} €`:null].filter(Boolean).join(" — ");return t.jsx(F,{value:e.url,children:L=>t.jsxs(t.Fragment,{children:[t.jsxs("a",{...L,href:e.url,className:"flex items-center flex-1 gap-300 min-w-0 py-300 pl-300 pr-200 no-underline text-font-body outline-none","data-gtm-search":JSON.stringify({...p,"card-link-type":"fiche-produit-titre"}),onClick:r,tabIndex:-1,"aria-label":d,children:[e.thumbnail&&t.jsx("img",{className:"bg-background-accent rounded-default shrink-0 h-10 w-10 object-contain p-50",src:e.thumbnail,alt:"",width:40,height:40,loading:"lazy"}),t.jsx(G,{text:e.title,className:`flex-1 text-2xs leading-[1.35] min-w-0 overflow-hidden text-ellipsis whitespace-nowrap ${B.title}`})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-100 pr-300",children:[e.testUrl&&e.testRating!=null&&t.jsx(Y,{score:e.testRating,href:e.testUrl,label:"Voir le test",className:B.notationCompact,"data-gtm-search":JSON.stringify({...p,"card-link-type":"test-bouton","with-test":`${e.testRating}/10`}),onClick:r,tabIndex:-1}),e.price!=null&&e.buyUrl&&t.jsxs("a",{href:e.buyUrl,target:"_blank",rel:"nofollow noreferrer",className:`inline-flex items-center py-100 px-200 text-[0.7rem] font-bold font-fontFamilySecondary leading-none whitespace-nowrap no-underline text-white bg-tertiary rounded-default ${B.priceTag}`,"data-gtm-search":JSON.stringify({...p,"card-link-type":"bouton-prix","with-price":e.price}),onClick:r,tabIndex:-1,children:[e.price," €"]}),e.price!=null&&!e.buyUrl&&t.jsxs("span",{className:"text-tertiary shrink-0 text-2xs font-bold",children:[e.price," €"]})]})]})},e.url)})}),a.length>0&&t.jsx(V,{label:"Articles",children:a.slice(0,Re).map((e,c)=>{const p=JSON.stringify({event:"search-click-results","search-mode":"suggest","search-query":i,"result-type":"post",position:c+1,"card-link-type":"article-titre"});return t.jsx(F,{value:e.url,children:d=>t.jsxs("a",{...d,href:e.url,className:"flex items-center flex-1 gap-300 min-w-0 py-200 px-300 no-underline text-font-body","data-gtm-search":p,onClick:r,tabIndex:-1,children:[e.format==="good-deal"&&t.jsx(D,{name:"fire",size:16,weight:"duotone",color:"var(--hds-color-tertiary)"}),e.format&&e.format!=="good-deal"&&M[e.format]&&t.jsx(Z,{variant:M[e.format].variant,size:"sm",children:M[e.format].label}),t.jsx(G,{text:e.title,className:`flex-1 text-2xs leading-[1.35] min-w-0 overflow-hidden text-ellipsis whitespace-nowrap ${B.title}`}),e.category&&t.jsx("span",{className:"text-font-item shrink-0 text-[0.7rem] ml-auto",children:e.category})]})},e.url)})}),i&&(k||A)&&t.jsx("div",{className:`border-t border-background-separator py-200 px-300 text-center ${B.footer}`,children:t.jsxs("a",{href:`/?s=${encodeURIComponent(i)}`,className:`text-primary text-[0.8rem] font-semibold font-fontFamilySecondary no-u
1nderline ${B.seeAll}`,children:["Voir tous les résultats pour « ",i," » →"]})})]})})]})}const Ee="wrapper___Wj4gt",Ce="pill___H0O21",Se="glassShell___G9Rv-",Ae="clear___06fCs",O={wrapper:Ee,pill:Ce,glassShell:Se,clear:Ae},Ne=ee["search-ai"],Ie="Rechercher un produit, un article...",$e={...te("regular","high"),"--glass-alpha":.8,width:"100%",maxWidth:"48rem"};function Le(n,l,u,o){const h=[`${l}=${encodeURIComponent(u)}`];return o!=null&&o.postType&&h.push(`post_type=${encodeURIComponent(o.postType)}`),o!=null&&o.taxonomy&&h.push(`${encodeURIComponent(o.taxonomy)}=${encodeURIComponent(o.term??"")}`),`${n}?${h.join("&")}`}function Ue({onSubmit:n,clearable:l=!1,autoFocus:u=!1,shape:o="default",glyph:h="search",queryParam:x="s",action:R="/",initialValue:i,placeholder:f=Ie,disabled:v=!1,restrictTo:w}={}){const j=s.useRef(null),[g,C]=s.useState(!1),[I,S]=s.useState(!1),_=s.useId().replace(/:/g,"_")+"_search",E=s.useRef(n);E.current=n;const P=s.useRef({action:R,queryParam:x,restrictTo:w});P.current={action:R,queryParam:x,restrictTo:w};const[r]=s.useState(()=>i??new URLSearchParams(window.location.search).get(x)??"");s.useEffect(()=>{var A;const a=(A=j.current)==null?void 0:A.querySelector("input");if(!a)return;a.id=_,a.classList.add("js-search-input","gtm-search"),a.setAttribute("autocomplete","off"),a.setAttribute("autocorrect","off"),S(a.value.trim().length>0);const k=b=>{var e;if(b.key==="Enter"){const c=a.getAttribute("aria-controls"),p=c?document.getElementById(c):null;if(!(p==null?void 0:p.querySelector('[role="option"][aria-selected="true"]'))){const L=(e=a.value)==null?void 0:e.trim();if(L)if(b.preventDefault(),b.stopPropagation(),E.current)E.current(L),window.matchMedia("(pointer: coarse)").matches&&a.blur();else{const{action:U,queryParam:$,restrictTo:Q}=P.current;window.location.href=Le(U,$,L,Q)}}}},m=()=>S(a.value.trim().length>0);return a.addEventListener("keydown",k),a.addEventListener("input",m),C(!0),()=>{a.removeEventListener("keydown",k),a.removeEventListener("input",m)}},[_]);const y=s.useCallback(()=>{var k;const a=(k=j.current)==null?void 0:k.querySelector("input");a&&(a.value="",a.dispatchEvent(new Event("input",{bubbles:!0})),S(!1),a.focus())},[]);return o==="glass"?t.jsxs("div",{ref:j,className:O.wrapper,children:[t.jsx("div",{className:`bn-pill has-default-theme--inverted ${O.glassShell}`,style:$e,children:t.jsxs("div",{className:"bn-search-pill",children:[t.jsx("span",{className:"bn-search-icon","aria-hidden":"true",children:h==="ai"?t.jsx(Ne,{width:24,height:24}):t.jsx(D,{name:"magnifying-glass",size:24,color:"inherit"})}),t.jsx("input",{type:"search",name:x,className:"bn-search-input",placeholder:f,"aria-label":"Rechercher un produit, un article",autoFocus:u,disabled:v,defaultValue:r}),l&&I&&t.jsx("button",{type:"button",className:"bn-search-clear","aria-label":"Effacer la recherche",onClick:y,children:t.jsx(D,{name:"x",size:12,weight:"bold",color:"inherit"})})]})}),g&&t.jsx(J,{inputSelector:`#${_}`})]}):t.jsxs("div",{ref:j,className:O.wrapper,children:[t.jsx(X,{name:x,placeholder:f,iconLeft:"magnifying-glass","aria-label":"Rechercher un produit, un article",autoFocus:u,disabled:v,defaultValue:r,className:o==="pill"?O.pill:void 0}),l&&I&&t.jsx("button",{type:"button",className:O.clear,"aria-label":"Effacer la recherche",onClick:y,children:t.jsx(D,{name:"x-circle",size:24,weight:"fill",color:"inherit"})}),g&&t.jsx(J,{inputSelector:`#${_}`})]})}export{Ue as S,J as a,pe as s};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.