-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
1 lines (1 loc) · 5.89 KB
/
index.js
1
(function(){"use strict";var b=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-field",t._b({staticClass:"k-multilist-field"},"k-field",t.$props,!1),[e("template",{slot:"options"},[t.canAdd?e("k-button",{attrs:{id:t._uid,icon:"add"},on:{click:t.addItem}},[t._v(" "+t._s(t.$t("add"))+" ")]):t._e()],1),t.isEmpty?e("k-empty",{attrs:{icon:"list-bullet"},on:{click:t.addItem}},[t._v(" "+t._s(t.empty||t.$t("field.structure.empty"))+" ")]):e("div",{staticClass:"k-table k-multilist-table"},[e("table",{attrs:{"data-sortable":t.isSortable}},[e("thead",[e("tr",[e("th",{staticClass:"k-table-index-column",attrs:{"data-mobile":"true"}},[t._v("#")]),t._l(t.columns,function(a,l){return e("th",{key:t.index,staticClass:"k-table-column",style:"width:"+t.width(t.fields[l].width),attrs:{"data-mobile":a.mobile}},[t._v(" "+t._s(t.fields[l].label)),t.fields[l].required?e("span",[t._v("*")]):t._e()])}),e("th",{staticClass:"k-table-options-column",attrs:{"data-mobile":"true"}})],2)]),e("k-draggable",{staticClass:"k-multilist-list",attrs:{list:t.localValue,handle:!0,element:"tbody",options:t.dragOptions},on:{end:t.onInput}},t._l(t.localValue,function(a,l){return e("tr",{key:l,staticClass:"k-multilist-item"},[e("td",{class:["k-table-index-column",{disabled:t.isLast(l)}],attrs:{"data-sortable":t.isSortable&&!t.isLast(l),"data-mobile":"true"}},[e("div",{staticClass:"k-table-index"},[t._v(t._s(l+1))]),t.isSortable&&!t.isLast(l)?e("k-sort-handle"):t._e()],1),t._l(t.columns,function(d,i){return e("td",{key:i,staticClass:"k-table-column multilist-field",attrs:{"data-mobile":d.mobile}},[t.hasFieldType(t.fields[i].type)?e("k-"+t.fields[i].type+"-field",t._b({ref:"list-"+t.fields[i].name+"-"+l,refInFor:!0,tag:"component",attrs:{name:i,novalidate:t.novalidate,disabled:t.disabled},on:{keydown:function(n){return!n.type.indexOf("key")&&t._k(n.keyCode,"enter",13,n.key,"Enter")||!n.shiftKey?null:(n.preventDefault(),t.addItem.apply(null,arguments))},keyup:function(n){return t.onKeyup(l,i,t.fields[i],n)},input:function(n){return t.onColumnInput(l,i,n)}},model:{value:t.localValue[l][i],callback:function(n){t.$set(t.localValue[l],i,n)},expression:"localValue[index][columnName]"}},"component",t.fields[i],!1)):t._e()],1)}),e("td",{class:["k-table-options-column",{disabled:t.isLast(l)}],attrs:{"data-mobile":"true"}},[e("k-button",{staticClass:"k-table-options-button",attrs:{tooltip:t.$t("remove"),icon:"remove"},on:{click:function(d){return t.removeItem(l)}}})],1)],2)}),0)],1)])],2)},_=[],C="";function m(t,s,e,a,l,d,i,n){var r=typeof t=="function"?t.options:t;s&&(r.render=s,r.staticRenderFns=e,r._compiled=!0),a&&(r.functional=!0),d&&(r._scopeId="data-v-"+d);var o;if(i?(o=function(u){u=u||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!u&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(u=__VUE_SSR_CONTEXT__),l&&l.call(this,u),u&&u._registeredComponents&&u._registeredComponents.add(i)},r._ssrRegister=o):l&&(o=n?function(){l.call(this,(r.functional?this.parent:this).$root.$options.shadowRoot)}:l),o)if(r.functional){r._injectStyles=o;var c=r.render;r.render=function(V,p){return o.call(p),c(V,p)}}else{var f=r.beforeCreate;r.beforeCreate=f?[].concat(f,o):[o]}return{exports:t,options:r}}const y={props:{columns:Object,label:String,disabled:Boolean,help:String,parent:String,empty:String,name:[String,Number],required:Boolean,type:String,duplicate:{type:Boolean,default:!0},empty:String,fields:Object,limit:Number,max:Number,min:Number,prepend:{type:Boolean,default:!1},sortable:{type:Boolean,default:!0},sortBy:String,value:{type:Array,default(){return[]}}},data(){return{novalidate:!1,localValue:this.value}},watch:{value:function(t){this.localValue!==t&&(this.localValue=this.sort(t))}},computed:{isEmpty(){return!this.localValue||!this.localValue.length},canAdd(){return!this.limit||!this.localValue||!this.localValue.length||this.localValue.length<this.limit},isSortable(){return this.sortable&&this.localValue.length>1&&(!this.sortBy||!this.sortBy.length)},defaultItem(){let t={};return Object.keys(this.fields).forEach(s=>{const e=this.fields[s];e.default!==null&&e.default!==void 0?t[s]=this.$helper.clone(e.default):t[s]=null}),t},dragOptions(){return{disabled:!this.isSortable,fallbackClass:"k-table-row-fallback",ghostClass:"k-table-row-ghost"}},lastIndex(){return this.localValue.length-1}},methods:{addItem(t=!0){let s=this.defaultItem;this.prepend?this.localValue=[s].concat(this.localValue):this.localValue.push(s),this.onInput(),t&&this.$nextTick(()=>{this.setFocus()})},setFocus(){let t=this.prepend&&!this.autoAdd?0:this.lastIndex,s="list-"+Object.keys(this.columns)[0]+"-"+t,e=this.$refs[s];e&&e[0].focus()},removeItem(t){this.localValue.indexOf(t)&&this.localValue.splice(t,1),this.onInput()},onColumnInput(t,s,e){this.localValue[t][s]=e,this.onInput()},onInput(){this.$emit("input",this.localValue)},onKeyup(t,s,e,a){let l=!1;const d=["text","url","email","tel"].indexOf(e.type)>-1,i=["number","select","multiselect"].indexOf(e.type)>-1,n=["text","url","email","tel"].indexOf(e.type)>-1,r=a.target.selectionStart==0,o=a.target.selectionStart==a.target.value.length;if(d&&(a.key=="ArrowDown"||a.key=="ArrowUp")&&(t+=a.key=="ArrowDown"?1:-1,l=!0),a.key=="ArrowLeft"&&(i||n&&r)||a.key=="ArrowRight"&&(i||n&&o)){let c=Object.keys(this.fields);s=c[c.indexOf(s)+(a.key=="ArrowRight"?1:-1)],l=!0}if(l){let c="list-"+s+"-"+t,f=this.$refs[c];f&&f[0]&&f[0].focus()}},isLast(t){return this.localValue&&this.localValue.length>1&&t+1===this.localValue.length},hasFieldType(t){return this.$helper.isComponent("k-"+t+"-field")},sort(t){return this.sortBy?t.sortBy(this.sortBy):t},width(t){if(!t)return"auto";const s=t.toString().split("/");if(s.length!==2)return"auto";const e=Number(s[0]),a=Number(s[1]),l=parseFloat(100/a*e,2).toFixed(2)+"%";return l=="100.00%"?"auto":l}}},h={};var k=m(y,b,_,!1,g,null,null,null);function g(t){for(let s in h)this[s]=h[s]}var v=function(){return k.exports}();panel.plugin("sylvainjule/multilist",{fields:{multilist:v}})})();