-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
1 lines (1 loc) · 8.92 KB
/
index.js
1
(function(){"use strict";function o(t,e,n,i,r,d,h,R){var a=typeof t=="function"?t.options:t;e&&(a.render=e,a.staticRenderFns=n,a._compiled=!0),i&&(a.functional=!0),d&&(a._scopeId="data-v-"+d);var s;if(h?(s=function(l){l=l||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!l&&typeof __VUE_SSR_CONTEXT__<"u"&&(l=__VUE_SSR_CONTEXT__),r&&r.call(this,l),l&&l._registeredComponents&&l._registeredComponents.add(h)},a._ssrRegister=s):r&&(s=R?function(){r.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:r),s)if(a.functional){a._injectStyles=s;var S=a.render;a.render=function(D,u){return s.call(u),S(D,u)}}else{var c=a.beforeCreate;a.beforeCreate=c?[].concat(c,s):[s]}return{exports:t,options:a}}const g={data(){return{link:{href:null,title:null,target:!1,text:null,anchor:null}}},computed:{fields(){return{href:{label:this.$t("link"),type:"autosuggest",id:this.link.href},text:{label:this.$t("link.text"),type:"text",icon:"title"},title:{label:this.$t("title"),type:"text",counter:!1,icon:"title"},anchor:{label:this.$t("gearsdigital.enhanced-toolbar-link-dialog.anchor.title"),type:this.$t("gearsdigital.enhanced-toolbar-link-dialog.anchor-field")==="hidden"?"hidden":"text",disabled:this.$t("gearsdigital.enhanced-toolbar-link-dialog.anchor-field")==="disabled",counter:!1,before:"#",width:"1/2"},target:{label:this.$t("open.newWindow"),type:this.$t("gearsdigital.enhanced-toolbar-link-dialog.target-field")==="hidden"?"hidden":"toggle",disabled:this.$t("gearsdigital.enhanced-toolbar-link-dialog.target-field")==="disabled",text:[this.$t("no"),this.$t("yes")],width:"1/2"}}},kirbytext(){return this.$config.kirbytext}},methods:{open(t,e){this.link.text=e,this.$refs.dialog.open(),this.addListener()},close(){this.$emit("cancel"),this.removeListener(),this.link={href:null,title:null,target:!1,text:null,anchor:null}},submit(){this.$emit("submit",this.kirbytext?this.createKirbytext():this.createMarkdown()),this.link={href:null,title:null,target:!1,text:null,anchor:null},this.$refs.dialog.close()},createKirbytext(){const t=[];return t.push(`link: ${this.appendAnchor(this.link.href)}`),this.link.text&&this.link.text.length>0&&t.push(`text: ${this.link.text}`),this.link.title&&this.link.title.length>0&&t.push(`title: ${this.link.title}`),this.link.target&&t.push("target: _blank"),`(${t.join(" ")})`},createMarkdown(){return this.link.text.length>0?`[${this.link.text}](${this.link.href})`:`<${this.link.href}>`},appendAnchor(t){let e=this.$refs.dialog.model.anchor;return e?(t||(t=""),e.startsWith("#")?t+e:t+"#"+e):t},listener(t){t.detail.page!==null&&(this.link={...this.link,href:t.detail.page.link,title:t.detail.page.text})},addListener(){document.addEventListener("enhanced-toolbar-link-dialog/page",this.listener)},removeListener(){document.removeEventListener("enhanced-toolbar-link-dialog/page",this.listener)}}};var f=function(){var e=this,n=e._self._c;return n("k-form-dialog",{ref:"dialog",attrs:{fields:e.fields,"submit-button":e.$t("confirm"),size:"medium"},on:{close:e.close,submit:e.submit},model:{value:e.link,callback:function(i){e.link=i},expression:"link"}})},p=[],m=o(g,f,p,!1,null,null,null,null);const _=m.exports,F="",k={data(){return{link:{href:null,title:null,target:!1,anchor:null}}},computed:{fields(){return{href:{label:this.$t("link"),type:"autosuggest",id:this.link.href},title:{label:this.$t("title"),type:"text",counter:!1,icon:"title"},anchor:{label:this.$t("gearsdigital.enhanced-toolbar-link-dialog.anchor.title"),type:this.$t("gearsdigital.enhanced-toolbar-link-dialog.anchor-field")==="hidden"?"hidden":"text",disabled:this.$t("gearsdigital.enhanced-toolbar-link-dialog.anchor-field")==="disabled",counter:!1,before:"#",width:"1/2"},target:{label:this.$t("open.newWindow"),type:this.$t("gearsdigital.enhanced-toolbar-link-dialog.target-field")==="hidden"?"hidden":"toggle",disabled:this.$t("gearsdigital.enhanced-toolbar-link-dialog.target-field")==="disabled",text:[this.$t("no"),this.$t("yes")],width:"1/2"}}}},methods:{open(t){this.link={title:null,target:!1,anchor:null,...this.extendWithAnchor(t)},this.link.target=!!this.link.target,this.$refs.dialog.open(),this.addListener()},close(){this.$emit("close"),this.removeListener()},submit(){this.link.href=this.appendAnchor(this.link.href),this.$emit("submit",{...this.link,target:this.link.target?"_blank":null}),this.$refs.dialog.close()},extendWithAnchor(t){if(!t.href)return t;const e=t.href.split("#");return{...t,href:e[0]??null,anchor:e[1]??null}},appendAnchor(t){let e=this.$refs.dialog.model.anchor;return e?(t||(t=""),e.startsWith("#")?t+e:t+"#"+e):t},listener(t){t.detail.page===null?this.link={href:null,title:null,target:!1}:this.link={...this.link,href:t.detail.page.link,title:t.detail.page.text}},addListener(){document.addEventListener("enhanced-toolbar-link-dialog/page",this.listener)},removeListener(){document.removeEventListener("enhanced-toolbar-link-dialog/page",this.listener)}}};var b=function(){var e=this,n=e._self._c;return n("k-form-dialog",{ref:"dialog",attrs:{fields:e.fields,"submit-button":e.$t("confirm"),size:"medium"},on:{close:e.close,submit:e.submit},model:{value:e.link,callback:function(i){e.link=i},expression:"link"}})},$=[],v=o(k,b,$,!1,null,null,null,null);const y=v.exports,N="",x={name:"EnhancedToolbarDropdown",props:{pages:{type:Array},pagination:{type:{page:Number,total:Number,limit:Number}}},data(){return{open:!0,currentItem:-1}},watch:{currentItem(t){t===-1&&(t=0),this.focusItem(t)}},mounted(){window.addEventListener("keyup",this.keydownListener)},destroyed(){window.removeEventListener("keyup",this.keydownListener)},methods:{select(t){this.$emit("select",t),this.open=!1,this.currentItem=-1},focusItem(t){document.querySelector(`.enhanced-toolbar-dialog-element div[data-index="${t}"]`).focus()},keydownListener(t){const e=this.currentItem<this.pages.length-1,n=this.currentItem>0,i=t.code;i==="ArrowDown"&&e&&(this.currentItem===-1?this.currentItem=0:this.currentItem=this.currentItem+1),i==="ArrowUp"&&n&&(this.currentItem=this.currentItem-1),t.shiftKey&&i==="Tab"?this.currentItem=this.currentItem-1:i==="Tab"&&(this.currentItem===-1?this.currentItem=0:this.currentItem=this.currentItem+1),i==="Enter"&&this.currentItem!==-1&&(this.select(this.pages[this.currentItem]),t.stopPropagation(),t.preventDefault())}}};var w=function(){var e=this,n=e._self._c;return n("dialog",{staticClass:"enhanced-toolbar-dialog-element",attrs:{open:e.open}},[e._l(e.pages,function(i,r){return n("div",{key:i.id,attrs:{"data-index":r,tabindex:0}},[n("k-item",{attrs:{text:i.text,image:i.image,info:i.id},on:{click:function(d){return e.select(i)}}})],1)}),n("k-pagination",{attrs:{align:"center",details:!0,page:e.pagination.page,total:e.pagination.total,limit:e.pagination.limit},on:{paginate:function(i){return e.$emit("paginate",i)}}})],2)},T=[],E=o(x,w,T,!1,null,"afcf971a",null,null);const I=E.exports,K="",L={name:"EnhancedToolbarAutosuggest",components:{EnhancedToolbarDropdown:I},props:{id:String,label:String},data(){return{searchTerm:"",pagination:{},pages:[],selectedPage:[],url:""}},watch:{selectedPage(t){t.length||document.dispatchEvent(new CustomEvent("enhanced-toolbar-link-dialog/page",{detail:{page:null}}))}},async created(){this.updateSearch=this.$helper.debounce(this.updateSearch,200),this.id&&await this.$api.get("enhanced-toolbar-link-dialog/page",{id:this.id}).then(t=>{this.selectedPage=[t]}).catch(t=>{t.code===404&&(this.url=this.id)})},methods:{async fetch(t,e){const n=(e==null?void 0:e.page)||1;if(!this.searchTerm){this.pages=[];return}if(this.searchTerm.startsWith("http")||this.searchTerm.startsWith("/")){this.pages=[];return}const i=await this.$api.get("enhanced-toolbar-link-dialog/pages",{q:this.searchTerm,page:n});this.pages=i.data,this.pagination=i.pagination},updateSearch(t){this.searchTerm=t,this.fetch(),this.$emit("input",t)},selectPage(t){document.dispatchEvent(new CustomEvent("enhanced-toolbar-link-dialog/page",{detail:{page:t}})),this.selectedPage=[t],this.url=""}}};var C=function(){var e=this,n=e._self._c;return n("div",{staticClass:"enhanced-toolbar-autosuggest-field"},[e.selectedPage.length===0?n("k-text-field",{attrs:{counter:!1,icon:"file-document",label:e.label,placeholder:e.$t("gearsdigital.enhanced-toolbar-link-dialog.autosuggest.placeholder"),name:"autosuggesttext"},on:{input:e.updateSearch},model:{value:e.url,callback:function(i){e.url=i},expression:"url"}}):e._e(),e.selectedPage.length===1?n("k-tags-field",{attrs:{counter:!1,icon:"file-document",label:e.label,name:"tags",type:"tags",max:"1"},model:{value:e.selectedPage,callback:function(i){e.selectedPage=i},expression:"selectedPage"}}):e._e(),e.pages.length?n("enhanced-toolbar-dropdown",{attrs:{pages:e.pages,pagination:e.pagination},on:{select:e.selectPage,paginate:function(i){return e.fetch(e.searchTerm,i)}}}):e._e()],1)},A=[],P=o(L,C,A,!1,null,"f1fbdecd",null,null);const W=P.exports;panel.plugin("gearsdigital/enhanced-toolbar-link-dialog",{components:{"k-toolbar-link-dialog":{extends:_},"k-writer":{extends:"k-writer",components:{"k-writer-link-dialog":y}}},fields:{autosuggest:W}})})();