PageSourceSearch

https://mastodon.roflcopter.fr/packs/search-D7KakQSY.js

js roflcopter.fr collected 2026-10-02 05:36:05 UTC 8,646 bytes, 2 lines download raw bytes

1import{j as e}from"./client-By3tlFYA.js";import{u as A,r as n,a as Q,ah as w,d as z,ai as E}from"./index-TEHZzOO_.js";import{c as b}from"./index-DkCxcZFY.js";import{a as K,h as T,u as X,cd as J,ce as $,a5 as I,S as Y,cf as Z,cg as V}from"./useSelectableClick-CnnB_wkC.js";import{ae as ee}from"./status_quoted-CQ4Yt3Mw.js";import{a as se,S as ae}from"./hashtags-CRafzBM6.js";import{c as te}from"./short_number-C9zm8Jg6.js";import{M as c}from"./message-CVkQtbZv.js";const v=Q({placeholder:{id:"search.placeholder",defaultMessage:"Search"},clearSearch:{id:"search.clear",defaultMessage:"Clear search"},placeholderSignedIn:{id:"search.search_or_paste",defaultMessage:"Search or paste URL"}}),ce=d=>{switch(d.type){case"account":return"@".concat(d.q);case"hashtag":return"#".concat(d.q);default:return d.q}},ne=({onClick:d,hasValue:r})=>{const y=A();return e.jsxs("div",{className:b("search__icon-wrapper",{"has-value":r}),children:[e.jsx(I,{id:"search",icon:ae,className:"search__icon"}),e.jsx("button",{type:"button",onClick:d,className:"search__icon search__icon--clear-button",tabIndex:r?void 0:-1,"aria-hidden":!r,children:e.jsx(I,{id:"times-circle",icon:ee,"aria-label":y.formatMessage(v.clearSearch)})})]})},ge=({singleColumn:d,initialValue:r})=>{const y=A(),L=K(s=>s.search.recent),{signedIn:_}=T(),m=X(),i=te(),S=n.useRef(null),[M,x]=n.useState(r!=null?r:""),F=M.length>0,[N,q]=n.useState(!1),[u,f]=n.useState(-1),[j,R]=n.useState([]);n.useEffect(()=>{x(r!=null?r:""),R([])},[r]);const D=[],l=n.useCallback(()=>{var s,a;(a=(s=document.querySelector(".ui"))==null?void 0:s.parentElement)==null||a.focus(),q(!1)},[]);w&&D.push({key:"prompt-has",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"has:"})," ",e.jsx(E,{type:"disjunction",value:["media","poll","embed"]})]}),action:s=>{s.preventDefault(),p("has:")}},{key:"prompt-is",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"is:"})," ",e.jsx(E,{type:"disjunction",value:["reply","sensitive"]})]}),action:s=>{s.preventDefault(),p("is:")}},{key:"prompt-language",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"language:"})," ",e.jsx(c,{id:"search_popout.language_code",defaultMessage:"ISO language code"})]}),action:s=>{s.preventDefault(),p("language:")}},{key:"prompt-from",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"from:"})," ",e.jsx(c,{id:"search_popout.user",defaultMessage:"user"})]}),action:s=>{s.preventDefault(),p("from:")}},{key:"prompt-before",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"before:"})," ",e.jsx(c,{id:"search_popout.specific_date",defaultMessage:"specific date"})]}),action:s=>{s.preventDefault(),p("before:")}},{key:"prompt-during",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"during:"})," ",e.jsx(c,{id:"search_popout.specific_date",defaultMessage:"specific date"})]}),action:s=>{s.preventDefault(),p("during:")}},{key:"prompt-after",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"after:"})," ",e.jsx(c,{id:"search_popout.specific_date",defaultMessage:"specific date"})]}),action:s=>{s.preventDefault(),p("after:")}},{key:"prompt-in",label:e.jsxs(e.Fragment,{children:[e.jsx("mark",{children:"in:"})," ",e.jsx(E,{type:"disjunction",value:["all","library","public"]})]}),action:s=>{s.preventDefault(),p("in:")}});const C=L.map(s=>({key:"".concat(s.type,"/").concat(s.q),label:ce(s),action:()=>{if(x(s.q),s.type==="account")i.push("/@".concat(s.q));else if(s.type==="hashtag")i.push("/tags/".concat(s.q));else{const a=new URLSearchParams({q:s.q});s.type&&a.set("type",s.type),i.push({pathname:"/search",search:a.toString()})}l()},forget:a=>{a.stopPropagation(),m(J(s))}})),h=F?j.concat(D):C.concat(j,D),p=s=>{x(a=>a===""?s:a.endsWith(" ")?"".concat(a).concat(s):"".concat(a," ").concat(s))},k=n.useCallback((s,a)=>{m($({q:s,type:a}));const t=new URLSearchParams({q:s});a&&t.set("type",a),i.push({pathname:"/search",search:t.toString()}),l()},[m,i,l]),O=n.useCallback(({target:{value:s}})=>{x(s);const a=s.trim(),t=[];a.length>0&&(a.startsWith("https://")&&!a.includes(" ")&&t.push({key:"open-url",label:e.jsx(c,{id:"search.quick_action.open_url",defaultMessage:"Open URL in Mastodon"}),action:async()=>{const o=await m(Z({url:a}));V(o)&&(o.payload.accounts[0]?i.push("/@".concat(o.payload.accounts[0].acct)):o.payload.statuses[0]&&i.push("/@".concat(o.payload.statuses[0].account.acct,"/").concat(o.payload.statuses[0].id))),l()}}),(a.startsWith("#")&&a.length>1||a.match(se))&&t.push({key:"go-to-hashtag",label:e.jsx(c,{id:"search.quick_action.go_to_hashtag",defaultMessage:"Go to hashtag {x}",values:{x:e.jsxs("mark",{children:["#",a.replace(/^#/,"")]})}}),action:()=>{const o=a.replace(/^#/,"");i.push("/tags/".concat(o)),m($({q:o,type:"hashtag"})),l()}}
1),/^@?[a-z0-9_-]+(@[^\s]+)?$/i.exec(a)&&t.push({key:"go-to-account",label:e.jsx(c,{id:"search.quick_action.go_to_account",defaultMessage:"Go to profile {x}",values:{x:e.jsxs("mark",{children:["@",a.replace(/^@/,"")]})}}),action:()=>{const o=a.replace(/^@/,"");i.push("/@".concat(o)),m($({q:o,type:"account"})),l()}}),w&&_&&t.push({key:"status-search",label:e.jsx(c,{id:"search.quick_action.status_search",defaultMessage:"Posts matching {x}",values:{x:e.jsx("mark",{children:a})}}),action:()=>{k(a,"statuses")}}),t.push({key:"account-search",label:e.jsx(c,{id:"search.quick_action.account_search",defaultMessage:"Profiles matching {x}",values:{x:e.jsx("mark",{children:a})}}),action:()=>{k(a,"accounts")}})),R(t)},[_,m,l,i,k]),P=n.useCallback(()=>{x(""),R([]),f(-1),l()},[l]),H=n.useCallback(s=>{var a;switch(s.key){case"Escape":s.preventDefault(),l();break;case"ArrowDown":s.preventDefault(),h.length>0&&f(Math.min(u+1,h.length-1));break;case"ArrowUp":s.preventDefault(),h.length>0&&f(Math.max(u-1,-1));break;case"Enter":s.preventDefault(),u===-1?k(M):h.length>0&&((a=h[u])==null||a.action(s));break;case"Delete":if(u>-1&&h.length>0){const t=h[u];typeof(t==null?void 0:t.forget)=="function"&&(s.preventDefault(),t.forget(s))}break}},[l,h,u,k,M]),W=n.useCallback(()=>{if(q(!0),f(-1),S.current&&!d){const{left:s,right:a}=S.current.getBoundingClientRect();(s<0||a>(window.innerWidth||document.documentElement.clientWidth))&&S.current.scrollIntoView()}},[q,f,d]),G=n.useCallback(()=>{f(-1)},[f]),B=n.useRef(null);return n.useEffect(()=>{if(N){let s=function(a){const t=B.current;t&&(t===a.target||t.contains(a.target))||q(!1)};return document.addEventListener("focusin",s),document.addEventListener("click",s),()=>{document.removeEventListener("focusin",s),document.removeEventListener("click",s)}}return()=>null},[N]),e.jsxs("form",{ref:B,className:b("search",{active:N}),children:[e.jsx("input",{ref:S,className:"search__input",type:"text",placeholder:y.formatMessage(_?v.placeholderSignedIn:v.placeholder),"aria-label":y.formatMessage(_?v.placeholderSignedIn:v.placeholder),value:M,onChange:O,onKeyDown:H,onFocus:W,onBlur:G}),e.jsx(ne,{hasValue:F,onClick:P}),e.jsxs("div",{className:"search__popout",tabIndex:-1,children:[!F&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:e.jsx(c,{id:"search_popout.recent",defaultMessage:"Recent searches"})}),e.jsx("div",{className:"search__popout__menu",children:C.length>0?C.map(({label:s,key:a,action:t,forget:g},U)=>e.jsxs("div",{tabIndex:0,role:"button",onMouseDown:t,className:b("search__popout__menu__item search__popout__menu__item--flex",{selected:u===U}),children:[e.jsx("span",{children:s}),e.jsx("button",{className:"icon-button",onMouseDown:g,children:e.jsx(I,{id:"times",icon:Y})})]},a)):e.jsx("div",{className:"search__popout__menu__message",children:e.jsx(c,{id:"search.no_recent_searches",defaultMessage:"No recent searches"})})})]}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:e.jsx(c,{id:"search_popout.quick_actions",defaultMessage:"Quick actions"})}),e.jsx("div",{className:"search__popout__menu",children:j.map(({key:s,label:a,action:t},g)=>e.jsx("button",{onMouseDown:t,className:b("search__popout__menu__item",{selected:u===g}),children:a},s))})]}),e.jsx("h4",{children:e.jsx(c,{id:"search_popout.options",defaultMessage:"Search options"})}),w&&_?e.jsx("div",{className:"search__popout__menu",children:D.map(({key:s,label:a,action:t},g)=>e.jsx("button",{onMouseDown:t,className:b("search__popout__menu__item",{selected:u===(j.length||L.length)+g}),children:a},s))}):e.jsx("div",{className:"search__popout__menu__message",children:w?e.jsx(c,{id:"search_popout.full_text_search_logged_out_message",defaultMessage:"Only available when logged in."}):e.jsx(c,{id:"search_popout.full_text_search_disabled_message",defaultMessage:"Not available on {domain}.",values:{domain:z}})})]})]})};export{ge as S};
2//# sourceMappingURL=search-D7KakQSY.js.map

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.