This repository has been archived by the owner on Feb 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
1 lines (1 loc) · 5 KB
/
index.js
1
(function () {var a={extends:"k-search",data:()=>({hasIndex:!0,isProcessing:!1}),computed:{rebuild(){let i=this.$t("search.index.missing");return this.isProcessing&&(i+="\u2026"),i}},methods:{async index(){this.isProcessing=!0;try{await this.$api.post("search"),this.$store.dispatch("notification/success",this.$t("search.index.built"))}catch(i){console.error(e)}finally{await this.search(this.q),this.isProcessing=!1,this.hasIndex=!0}},async search(i){this.isLoading=!0;try{if(""===i)throw new Error;const t=await this.$api.get("search",{q:i,select:["id","title","email","name","filename","parent","panelIcon","panelImage"]});this.items=t.data.map(i=>{let e={id:i.id,icon:{...i.panelIcon,back:"black",color:"#fff"},image:{...i.panelImage,back:"pattern",cover:!0}};return i.hasOwnProperty("email")?(e.title=i.name||i.email,e.link=this.$api.users.link(i.id),e.info=i.email,e.icon={back:"black",type:"user"}):i.hasOwnProperty("filename")?(e.title=i.filename,e.link=this.$api.files.link(this.$api.pages.url(i.parent.id),i.filename),e.info=i.id):(e.title=i.title,e.link=this.$api.pages.link(i.id),e.info=i.id),e})}catch(e){"error.notFound"===e.key&&(this.hasIndex=!1),this.items=[]}finally{this.selected=-1,this.isLoading=!1,this.hasResults=this.items.length>0}}}};if(typeof a==="function"){a=a.options}Object.assign(a,function(){var render=function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c("k-overlay",{ref:"overlay"},[_c("div",{staticClass:"k-search",attrs:{"role":"search"}},[_c("div",{staticClass:"k-search-input"},[_c("input",{directives:[{name:"model",rawName:"v-model",value:_vm.q,expression:"q"}],ref:"input",attrs:{"placeholder":_vm.$t("search")+" \u2026","aria-label":_vm.$t("search"),"autofocus":true,"type":"text"},domProps:{"value":_vm.q},on:{"input":[function($event){if($event.target.composing){return}_vm.q=$event.target.value},function($event){_vm.hasResults=true}],"keydown":[function($event){if(!$event.type.indexOf("key")&&_vm._k($event.keyCode,"down",40,$event.key,["Down","ArrowDown"])){return null}$event.preventDefault();return _vm.onDown($event)},function($event){if(!$event.type.indexOf("key")&&_vm._k($event.keyCode,"up",38,$event.key,["Up","ArrowUp"])){return null}$event.preventDefault();return _vm.onUp($event)},function($event){if(!$event.type.indexOf("key")&&_vm._k($event.keyCode,"tab",9,$event.key,"Tab")){return null}$event.preventDefault();return _vm.onTab($event)},function($event){if(!$event.type.indexOf("key")&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){return null}return _vm.onEnter($event)},function($event){if(!$event.type.indexOf("key")&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){return null}return _vm.close($event)}]}}),_vm._v(" "),_c("k-button",{staticClass:"k-search-close",attrs:{"tooltip":_vm.$t("close"),"icon":_vm.isLoading?"loader":"cancel"},on:{"click":_vm.close}})],1),_vm._v(" "),_vm.q&&(!_vm.hasResults||_vm.items.length)?_c("div",{staticClass:"k-search-results"},[_vm.items.length?_c("ul",{on:{"mouseout":function($event){_vm.selected=-1}}},_vm._l(_vm.items,function(item,itemIndex){return _c("li",{key:item.id,attrs:{"data-selected":_vm.selected===itemIndex},on:{"mouseover":function($event){_vm.selected=itemIndex}}},[_c("k-link",{attrs:{"to":item.link},on:{"click":_vm.close}},[_c("span",{staticClass:"k-search-item-image"},[_vm.imageOptions(item.image)?_c("k-image",_vm._b({},"k-image",_vm.imageOptions(item.image),false)):_c("k-icon",_vm._b({},"k-icon",item.icon,false))],1),_vm._v(" "),_c("span",{staticClass:"k-search-item-info"},[_c("strong",[_vm._v(_vm._s(item.title))]),_vm._v(" "),_c("small",[_vm._v(_vm._s(item.info))])])])],1)}),0):!_vm.hasIndex?_c("p",{staticClass:"k-search-empty k-search-index",on:{"click":_vm.index}},[_vm._v(" "+_vm._s(_vm.rebuild)+" ")]):!_vm.hasResults?_c("p",{staticClass:"k-search-empty"},[_vm._v(" "+_vm._s(_vm.$t("search.results.none"))+" ")]):_vm._e()]):_vm._e()])])};var staticRenderFns=[];return{render:render,staticRenderFns:staticRenderFns,_compiled:true,_scopeId:null,functional:undefined}}());var b={data:()=>({headline:"",isProcessing:!1}),computed:{text(){let s=this.$t("search.index.build");return this.isProcessing&&(s+="\u2026"),s}},async created(){const s=await this.load();this.headline=s.headline},methods:{async build(){this.isProcessing=!0;try{await this.$api.post("search"),this.$store.dispatch("notification/success",this.$t("search.index.built"))}catch(s){console.error(e)}finally{this.isProcessing=!1}}}};if(typeof b==="function"){b=b.options}Object.assign(b,function(){var render=function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c("div",[_c("div",{staticClass:"k-section-header"},[_c("k-headline",[_vm._v(_vm._s(_vm.headline))])],1),_vm._v(" "),_c("k-button",{attrs:{"icon":"refresh","disabled":_vm.isProcessing},on:{"click":_vm.build}},[_vm._v(" "+_vm._s(_vm.text)+" ")])],1)};var staticRenderFns=[];return{render:render,staticRenderFns:staticRenderFns,_compiled:true,_scopeId:null,functional:undefined}}());panel.plugin("distantnative/search-for-kirby",{sections:{search:b},components:{"k-search":a}});})();