1import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{n as t,t as n}from"./jsx-runtime-D3F0h15I.js";import{a as r,c as i,n as a,s as o}from"./react-intl-D77hBoiN.js";import{L as s,f as c}from"./initial_state-Bq_NJi1A.js";import{o as l}from"./locales-CJrKkcVr.js";import{U as u}from"./chevron_right-N5umLIte.js";import{Zt as d}from"./detect-it.esm-C_e4o2yl.js";import{Fr as f,Ir as p,Nr as m}from"./time-DJAUxdvc.js";import{s as h}from"./react-router-D0L-bsDO.js";import{U as g}from"./accounts_typed-Cr4Ssacc.js";import{o as _,s as ee}from"./typed_functions-qbDu3xly.js";import{Jt as te,Nt as ne,Rt as re,on as v,rn as y}from"./poll-DVy9sBNj.js";import{t as b}from"./classnames-CfLRLWYq.js";import{t as x}from"./icon-BqRrl0RO.js";import{t as S}from"./search-ChptxC0m.js";import{y as C}from"./minBy-BCXYCyOs.js";var w=e(t()),T=e(b()),E=n(),D=o({placeholder:{id:`search.placeholder`,defaultMessage:`Search`},clearSearch:{id:`search.clear`,defaultMessage:`Clear search`},placeholderSignedIn:{id:`search.search_or_paste`,defaultMessage:`Search or paste URL`}}),O=e=>{switch(e.type){case`account`:return`@${e.q}`;case`hashtag`:return`#${e.q}`;default:return e.q}},k=({onClick:e,hasValue:t})=>{let n=i();return(0,E.jsxs)(`div`,{className:(0,T.default)(`search__icon-wrapper`,{"has-value":t}),children:[(0,E.jsx)(x,{id:`search`,icon:S,className:`search__icon`}),(0,E.jsx)(`button`,{type:`button`,onClick:e,className:`search__icon search__icon--clear-button`,tabIndex:t?void 0:-1,"aria-hidden":!t,children:(0,E.jsx)(x,{id:`times-circle`,icon:C,"aria-label":n.formatMessage(D.clearSearch)})})]})},A=({singleColumn:e,initialValue:t})=>{let n=i(),o=ee(e=>e.search.recent),{signedIn:b}=te(),S=_(),C=h(),A=(0,w.useRef)(null),[j,M]=(0,w.useState)(t??``),N=j.length>0,[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(-1),[R,z]=(0,w.useState)([]),[B,V]=(0,w.useState)(!1),H=v(y.SEARCH,()=>{V(!0)}),U=(0,w.useCallback)(()=>{document.querySelector(`.ui`)?.parentElement?.focus(),F(!1)},[]),W=(0,w.useCallback)(e=>{M(t=>t===``?e:t.endsWith(` `)?`${t}${e}`:`${t} ${e}`)},[]),G=(0,w.useMemo)(()=>s?[{key:`prompt-has`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`has:`}),` `,(0,E.jsx)(a,{type:`disjunction`,value:[`media`,`poll`,`embed`]})]}),action:e=>{e.preventDefault(),W(`has:`)}},{key:`prompt-is`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`is:`}),` `,(0,E.jsx)(a,{type:`disjunction`,value:[`reply`,`sensitive`]})]}),action:e=>{e.preventDefault(),W(`is:`)}},{key:`prompt-language`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`language:`}),` `,(0,E.jsx)(r,{id:`search_popout.language_code`,defaultMessage:`ISO language code`})]}),action:e=>{e.preventDefault(),W(`language:`)}},{key:`prompt-from`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`from:`}),` `,(0,E.jsx)(r,{id:`search_popout.user`,defaultMessage:`user`})]}),action:e=>{e.preventDefault(),W(`from:`)}},{key:`prompt-before`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`before:`}),` `,(0,E.jsx)(r,{id:`search_popout.specific_date`,defaultMessage:`specific date`})]}),action:e=>{e.preventDefault(),W(`before:`)}},{key:`prompt-during`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`during:`}),` `,(0,E.jsx)(r,{id:`search_popout.specific_date`,defaultMessage:`specific date`})]}),action:e=>{e.preventDefault(),W(`during:`)}},{key:`prompt-after`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`after:`}),` `,(0,E.jsx)(r,{id:`search_popout.specific_date`,defaultMessage:`specific date`})]}),action:e=>{e.preventDefault(),W(`after:`)}},{key:`prompt-in`,label:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`mark`,{children:`in:`}),` `,(0,E.jsx)(a,{type:`disjunction`,value:[`all`,`library`,`public`]})]}),action:e=>{e.preventDefault(),W(`in:`)}}]:[],[W]),K=(0,w.useMemo)(()=>o.map(e=>({key:`${e.type}/${e.q}`,label:O(e),action:()=>{if(M(e.q),e.type===`account`)C.push(`/@${e.q}`);else if(e.type===`hashtag`)C.push(`/tags/${e.q}`);else{let t=new URLSearchParams({q:e.q});e.type&&t.set(`type`,e.type),C.push({pathname:`/search`,search:t.toString()})}U()},forget:t=>{t.stopPropagation(),S(f(e))}})),[S,C,o,U]),q=(0,w.useMemo)(()=>N?R.concat(G):K.concat(R,G),[N,R,K,G]),J=(0,w.useCallback)((e,t)=>{S(m({q:e,type:t}));let n=new URLSearchParams({q:e});t&&n.set(`type`,t),C.push({pathname:`/search`,search:n.toString()}),U()},[S,C,U]),Y=(0,w.useCallback)(({target:{value:e}})=>{M(e),F(!0),L(-1);let t=e.trim(),n=[];t.length>0&&(t.startsWith(`https://`)&&!t.includes(` `)&&n.push({key:`open-url`,label:(0,E.jsx)(r,{id:`search.quick_action.open_url`,defaultMessage:`Open URL in Mastodon`}),action:async()=>{let e=await S(p({url:t}));d(e)&&(e.payload.accounts[0]?C.push(`/@${e.payload.accounts[0].acct}`):e.payload.statuses[0]?C.push(`/@${e.payload.statuses[0].account.acct}/${e.payload.statuses[0].id}`):e.payload.collections[0]&&C.push(re(e.payload.collections[0].id))),U()}}),(t.startsWith(`#`)&&t.length>1||t.match(g))&&n.push({key:`go-to-hashtag`,label:(0,E.jsx)(r,{id:`search.quick_action.go_to_hashtag`,defaultMessage:`Go to hashtag {x}`,values:{x:(0,E.jsxs)(`mark`,{children:[`#`,t.replace(/^#/,``)]})}}),action:()=>{let e=t.replace(/^#/,``);C.push(`/tags/${e}`),S(m({q:e,type:`hashtag`})),U()}}),/^@?[a-z0-9_-]+(@[^\s]+)?$/i.exec(t)&&n.push({key:`go-to-account`,label:(0,E.jsx)(r,{id:`search.quick_action.go_to_account`,defaultMessage:`Go to profile {x}`,values:{x:(0,E.jsxs)(`mark`,{children:[`@`,t.replace(/^@/,``)]})}}),action:()=>{let e=t.replace(/^@/,``);C.push(`/@${e}`),S(m({q:e,type:`account`})),U()}}),s&&b&&n.push({key:`status-search`,label:(0,E.jsx)(r,{id:`search.quick_action.status_search`,defaultMessage:`Posts matching {x}`,values:{x:(0,E.jsx)(`mark`,{children:t})}}),action:()=>{J(t,`statuses`)}}),n.push({key:`account-search`,label:(0,E.jsx)(r,{id:`search.quick_action.account_search`,defaultMessage:`Profiles matching {x}`,values:{x:(0,E.jsx)(`mark`,{children:t})}}),action:()=>{J(t,`accounts`)}})),z(n)},[b,S,U,C,J]),ie=(0,w.useCallback)(()=>{M(``),z([]),L(-1),U()},[U]),X=(0,w.useCallback)(e=>{switch(e.key){case`Escape`:e.preventDefault(),A.current?.focus(),F(!1);break;case`ArrowDown`:e.preventDefault(),P||F(!0),q.length>0&&L(Math.min(I+1,q.length-1));break;case`ArrowUp`:e.preventDefault(),q.length>0&&L(Math.max(I-1,-1));break;case`Enter`:e.preventDefault(),I===-1?J(j):q.length>0&&q[I]?.action(e);break;case`Delete`:if(I>-1&&q.length>0){let t=q[I];typeof t?.forget==`function`&&(e.preventDefault(),t.forget(e))}}},[P,q,I,J,j]),ae=(0,w.useCallback)(()=>
1{if(B&&(F(!0),L(-1)),A.current&&!e){let{left:e,right:t}=A.current.getBoundingClientRect();(e<0||t>(window.innerWidth||document.documentElement.clientWidth))&&A.current.scrollIntoView()}},[B,e]),oe=(0,w.useCallback)(()=>{L(-1)},[L]),Z=(0,w.useCallback)(e=>()=>{L(e)},[]),Q=(0,w.useRef)(null);(0,w.useEffect)(()=>{if(P){function e(e){let t=Q.current;(!t||t!==e.target&&!t.contains(e.target))&&F(!1)}return document.addEventListener(`focusin`,e),document.addEventListener(`click`,e),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`click`,e)}}return()=>null},[P]);let $=(0,w.useId)();return(0,E.jsxs)(`form`,{role:`search`,ref:Q,className:(0,T.default)(`search`,{active:P}),children:[(0,E.jsx)(`input`,{ref:ne(A,l()?H:null),className:`search__input`,type:`text`,inputMode:`search`,placeholder:n.formatMessage(b?D.placeholderSignedIn:D.placeholder),"aria-label":n.formatMessage(b?D.placeholderSignedIn:D.placeholder),value:j,onChange:Y,onKeyDown:X,onFocus:ae,onBlur:oe}),(0,E.jsx)(k,{hasValue:N,onClick:ie}),(0,E.jsxs)(`div`,{className:`search__popout`,role:`dialog`,tabIndex:-1,"aria-labelledby":$,onKeyDown:X,children:[!N&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`h4`,{children:(0,E.jsx)(r,{id:`search_popout.recent`,defaultMessage:`Recent searches`})}),(0,E.jsx)(`div`,{className:`search__popout__menu`,children:K.length>0?K.map(({label:e,key:t,action:n,forget:r},i)=>(0,E.jsxs)(`div`,{tabIndex:0,role:`button`,onMouseDown:n,onFocus:Z(i),className:(0,T.default)(`search__popout__menu__item search__popout__menu__item--flex`,{selected:I===i}),children:[(0,E.jsx)(`span`,{children:e}),(0,E.jsx)(`button`,{className:`icon-button`,onMouseDown:r,type:`button`,children:(0,E.jsx)(x,{id:`times`,icon:u})})]},t)):(0,E.jsx)(`div`,{className:`search__popout__menu__message`,children:(0,E.jsx)(r,{id:`search.no_recent_searches`,defaultMessage:`No recent searches`})})})]}),R.length>0&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`h4`,{children:(0,E.jsx)(r,{id:`search_popout.quick_actions`,defaultMessage:`Quick actions`})}),(0,E.jsx)(`div`,{className:`search__popout__menu`,children:R.map(({key:e,label:t,action:n},r)=>(0,E.jsx)(`button`,{onMouseDown:n,onFocus:Z(r),className:(0,T.default)(`search__popout__menu__item`,{selected:I===r}),type:`button`,children:t},e))})]}),(0,E.jsx)(`h4`,{id:$,children:(0,E.jsx)(r,{id:`search_popout.options`,defaultMessage:`Search options`})}),s&&b?(0,E.jsx)(`div`,{className:`search__popout__menu`,children:G.map(({key:e,label:t,action:n},r)=>{let i=(R.length||o.length)+r;return(0,E.jsx)(`button`,{onMouseDown:n,onFocus:Z(i),className:(0,T.default)(`search__popout__menu__item`,{selected:I===i}),type:`button`,children:t},e)})}):(0,E.jsx)(`div`,{className:`search__popout__menu__message`,children:s?(0,E.jsx)(r,{id:`search_popout.full_text_search_logged_out_message`,defaultMessage:`Only available when logged in.`}):(0,E.jsx)(r,{id:`search_popout.full_text_search_disabled_message`,defaultMessage:`Not available on {domain}.`,values:{domain:c}})})]})]})};export{A as t}; 2//# sourceMappingURL=search-nI-GeqGk.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.