app/assets/SearchResult-CyPd9z6P.js

2 lines
5.7 KiB
JavaScript

import{u as U,f as se,g as te,h as Y,i as ae,P as le,t as re,j as ue,k as b,l as Q,m as ie,n as M,p as t,q as oe,R as T,s as ne,v as ce,x as ve,C as pe,y as de,z as ye,A as he,B as me,D as ge,E as fe,F as Ee,G as $,H as j,I as He,J as q,K as Re}from"./app-uE97kg21.js";const ke=["/","/foolsday.html","/deployment/","/deployment/config.html","/deployment/fandq.html","/deployment/install.html","/store/","/usage/","/usage/agreement.html","/usage/basic_command.html","/usage/extra_command.html","/usage/resource_pack.html","/404.html","/category/","/category/%E9%83%A8%E7%BD%B2/","/category/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/","/category/%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C/","/tag/","/tag/%E9%85%8D%E7%BD%AE/","/tag/%E9%83%A8%E7%BD%B2/","/tag/%E5%AE%89%E8%A3%85/","/article/","/star/","/timeline/"],De="SEARCH_PRO_QUERY_HISTORY",g=U(De,[]),Qe=()=>{const{queryHistoryCount:a}=q,l=a>0;return{enabled:l,queryHistory:g,addQueryHistory:r=>{l&&(g.value=Array.from(new Set([r,...g.value.slice(0,a-1)])))},removeQueryHistory:r=>{g.value=[...g.value.slice(0,r),...g.value.slice(r+1)]}}},F=a=>ke[a.id]+("anchor"in a?`#${a.anchor}`:""),qe="SEARCH_PRO_RESULT_HISTORY",{resultHistoryCount:I}=q,f=U(qe,[]),we=()=>{const a=I>0;return{enabled:a,resultHistory:f,addResultHistory:l=>{if(a){const r={link:F(l),display:l.display};"header"in l&&(r.header=l.header),f.value=[r,...f.value.slice(0,I-1)]}},removeResultHistory:l=>{f.value=[...f.value.slice(0,l),...f.value.slice(l+1)]}}},xe=a=>{const l=pe(),r=Y(),w=de(),i=b(0),R=Q(()=>i.value>0),y=ye([]);return he(()=>{const{search:h,terminate:x}=me(),E=He(c=>{const H=c.join(" "),{searchFilter:A=d=>d,splitWord:C,suggestionsFilter:_,...m}=l.value;H?(i.value+=1,h(c.join(" "),r.value,m).then(d=>A(d,H,r.value,w.value)).then(d=>{i.value-=1,y.value=d}).catch(d=>{console.warn(d),i.value-=1,i.value||(y.value=[])})):y.value=[]},q.searchDelay-q.suggestDelay);M([a,r],([c])=>E(c),{immediate:!0}),ge(()=>{x()})}),{isSearching:R,results:y}};var Ce=se({name:"SearchResult",props:{queries:{type:Array,required:!0},isFocusing:Boolean},emits:["close","updateQuery"],setup(a,{emit:l}){const r=te(),w=Y(),i=ae(le),{enabled:R,addQueryHistory:y,queryHistory:h,removeQueryHistory:x}=Qe(),{enabled:E,resultHistory:c,addResultHistory:H,removeResultHistory:A}=we(),C=R||E,_=re(a,"queries"),{results:m,isSearching:d}=xe(_),u=ue({isQuery:!0,index:0}),v=b(0),p=b(0),P=Q(()=>C&&(h.value.length>0||c.value.length>0)),S=Q(()=>m.value.length>0),B=Q(()=>m.value[v.value]||null),z=()=>{const{isQuery:e,index:s}=u;s===0?(u.isQuery=!e,u.index=e?c.value.length-1:h.value.length-1):u.index=s-1},G=()=>{const{isQuery:e,index:s}=u;s===(e?h.value.length-1:c.value.length-1)?(u.isQuery=!e,u.index=0):u.index=s+1},J=()=>{v.value=v.value>0?v.value-1:m.value.length-1,p.value=B.value.contents.length-1},K=()=>{v.value=v.value<m.value.length-1?v.value+1:0,p.value=0},V=()=>{p.value<B.value.contents.length-1?p.value+=1:K()},N=()=>{p.value>0?p.value-=1:J()},L=e=>e.map(s=>Re(s)?s:t(s[0],s[1])),W=e=>{if(e.type==="customField"){const s=fe[e.index]||"$content",[o,D=""]=Ee(s)?s[w.value].split("$content"):s.split("$content");return e.display.map(n=>t("div",L([o,...n,D])))}return e.display.map(s=>t("div",L(s)))},k=()=>{v.value=0,p.value=0,l("updateQuery",""),l("close")},X=()=>R?t("ul",{class:"search-pro-result-list"},t("li",{class:"search-pro-result-list-item"},[t("div",{class:"search-pro-result-title"},i.value.queryHistory),h.value.map((e,s)=>t("div",{class:["search-pro-result-item",{active:u.isQuery&&u.index===s}],onClick:()=>{l("updateQuery",e)}},[t($,{class:"search-pro-result-type"}),t("div",{class:"search-pro-result-content"},e),t("button",{class:"search-pro-remove-icon",innerHTML:j,onClick:o=>{o.preventDefault(),o.stopPropagation(),x(s)}})]))])):null,Z=()=>E?t("ul",{class:"search-pro-result-list"},t("li",{class:"search-pro-result-list-item"},[t("div",{class:"search-pro-result-title"},i.value.resultHistory),c.value.map((e,s)=>t(T,{to:e.link,class:["search-pro-result-item",{active:!u.isQuery&&u.index===s}],onClick:()=>{k()}},()=>[t($,{class:"search-pro-result-type"}),t("div",{class:"search-pro-result-content"},[e.header?t("div",{class:"content-header"},e.header):null,t("div",e.display.map(o=>L(o)).flat())]),t("button",{class:"search-pro-remove-icon",innerHTML:j,onClick:o=>{o.preventDefault(),o.stopPropagation(),A(s)}})]))])):null;return ie("keydown",e=>{if(a.isFocusing){if(S.value){if(e.key==="ArrowUp")N();else if(e.key==="ArrowDown")V();else if(e.key==="Enter"){const s=B.value.contents[p.value];y(a.queries.join(" ")),H(s),r.push(F(s)),k()}}else if(E){if(e.key==="ArrowUp")z();else if(e.key==="ArrowDown")G();else if(e.key==="Enter"){const{index:s}=u;u.isQuery?(l("updateQuery",h.value[s]),e.preventDefault()):(r.push(c.value[s].link),k())}}}}),M([v,p],()=>{var e;(e=document.querySelector(".search-pro-result-list-item.active .search-pro-result-item.active"))==null||e.scrollIntoView(!1)},{flush:"post"}),()=>t("div",{class:["search-pro-result-wrapper",{empty:a.queries.length?!S.value:!P.value}],id:"search-pro-results"},a.queries.length?d.value?t(oe,{hint:i.value.searching}):S.value?t("ul",{class:"search-pro-result-list"},m.value.map(({title:e,contents:s},o)=>{const D=v.value===o;return t("li",{class:["search-pro-result-list-item",{active:D}]},[t("div",{class:"search-pro-result-title"},e||i.value.defaultTitle),s.map((n,ee)=>{const O=D&&p.value===ee;return t(T,{to:F(n),class:["search-pro-result-item",{active:O,"aria-selected":O}],onClick:()=>{y(a.queries.join(" ")),H(n),k()}},()=>[n.type==="text"?null:t(n.type==="title"?ne:n.type==="heading"?ce:ve,{class:"search-pro-result-type"}),t("div",{class:"search-pro-result-content"},[n.type==="text"&&n.header?t("div",{class:"content-header"},n.header):null,t("div",W(n))])])})])})):i.value.emptyResult:C?P.value?[X(),Z()]:i.value.emptyHistory:i.value.emptyResult)}});export{Ce as default};