-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
1 lines (1 loc) · 5.66 KB
/
index.js
1
(function () {function b(t){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var a={data:function(){return{loading:!1,palette:[]}},props:{options:[Object,Array],display:String,size:String,unselect:Boolean,default:[String,Boolean],extractor:Boolean,limit:Number,uri:String,endpoints:Object,autotemplate:String,template:String,label:String,disabled:Boolean,help:String,parent:String,value:[String,Array],name:[String,Number],required:Boolean,type:String},computed:{selected:function(){return Array.isArray(this.value)?this.value[0]:this.value},extracted:function(){var t=Array.isArray(this.value)?this.value[1]:"";return this.palette.length?this.palette:t},emptyOptions:function(){return!(this.isObject(this.options)?Object.keys(this.options).length:this.options.length)&&!this.extractor},emptyOptionsPlaceholder:function(){return this.autotemplate?this.$t("palette.empty.template"):this.$t("palette.empty.options")},emptyPalette:function(){return this.extractor&&!this.extracted.length&&!this.loading},loadingPalette:function(){return this.extractor&&this.loading},colors:function(){return this.extractor?!!this.extracted.length&&this.extracted:this.isQueryOptions(this.options)?this.options.map(function(t){return t.value}):this.options}},created:function(){var t=this;!this.value&&this.default&&(Array.isArray(this.colors)&&this.colors.find(function(e){return e==t.default})?(this.value=this.default,this.input()):this.isObject(this.colors)&&Object.keys(this.colors).find(function(e){return e==t.default})&&(this.value=this.colors[this.default],this.input()))},methods:{isValue:function(t){return this.isObject(t)?this.selected==t||!!this.isObject(this.selected)&&this.isEquivalent(this.selected,t):this.selected==t},inlineStyle:function(t){return"duo"==this.display&&this.isObject(t)?"background: linear-gradient(to right, "+this.firstColor(t)+" 50%, "+this.secondColor(t)+" 50%);":"background:"+this.firstColor(t)},toTooltip:function(t){return!(!this.isObject(t)||!t.tooltip)&&t.tooltip},firstColor:function(t){return this.isString(t)?t:this.isObject(t)?t[Object.keys(t)[0]]:void 0},secondColor:function(t){return!!this.isObject(t)&&t[Object.keys(t)[1]]},isString:function(t){return"string"==typeof t},isObject:function(t){return null!=t&&"object"===b(t)},isQueryOptions:function(t){if(!t.length)return!1;var e=t[0];return this.isObject(e)&&2==Object.keys(e).length&&Object.keys(e).includes("text")&&Object.keys(e).includes("value")},isEquivalent:function(t,e){var i=Object.keys(t),n=Object.keys(e),r=i.indexOf("key");-1!==r&&i.splice(r,1);var o=n.indexOf("key");if(-1!==o&&n.splice(o,1),i.length!=n.length)return!1;for(var s=0;s<i.length;s++){var l=i[s];if(t[l]!==e[l])return!1}return!0},openSelector:function(){var t=this;this.$api.get("color-palette/get-files",{uri:this.uri,template:this.template}).then(function(e){t.$refs.selector.open(e,{max:!1,multiple:!1})}).catch(function(){t.$store.dispatch("notification/error","The files query does not seem to be correct")})},processImage:function(t){var e=this;this.loading=!0,this.$api.get("color-palette/extract-image-colors",{filename:t[0].filename,uri:this.uri,limit:this.limit}).then(function(t){e.palette=t.colors,e.value=["",e.palette],e.input(),e.loading=!1}).catch(function(t){e.palette=[],e.loading=!1})},input:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1?arguments[1]:void 0;t&&(this.unselect&&this.isValue(t)&&(t=""),this.value=this.extractor?[t,this.extracted]:t,this.isObject(this.value)&&(this.value.key=e)),this.$emit("input",this.value)}}};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-field",_vm._b({staticClass:"k-color-palette-field"},"k-field",_vm.$props,false),[_c("template",{slot:"options"},[_vm.extractor?_c("k-button",{ref:"extract",attrs:{"id":_vm._uid,"icon":"palette-pipette"},on:{"click":_vm.openSelector}},[_vm._v(" "+_vm._s(_vm.$t("palette.new.palette"))+" ")]):_vm._e(),_vm._v(" "),_c("k-files-dialog",{ref:"selector",on:{"submit":_vm.processImage}})],1),_vm._v(" "),_vm.emptyOptions?_c("k-box",{staticClass:"color-palette_empty-options",attrs:{"theme":"info"}},[_vm._v(" "+_vm._s(_vm.emptyOptionsPlaceholder)+" ")]):_vm.emptyPalette?_c("k-empty",{class:["color-palette_empty-palette",_vm.size],attrs:{"layout":"custom","icon":"image"},on:{"click":_vm.openSelector}},[_vm._v(" "+_vm._s(_vm.$t("palette.empty.palette"))+" ")]):_vm.loadingPalette?_c("div",{staticClass:"color-palette_empty-loading"},[_c("div",{staticClass:"loader-ctn",class:_vm.size},[_c("div",{staticClass:"loader"})])]):_c("div",{staticClass:"color-palette_input"},[_c("ul",{staticClass:"color-palette_input-list"},_vm._l(_vm.colors,function(color,index){return _c("li",{class:[_vm.size,{"active":_vm.isValue(color)},{"unselect":_vm.unselect}],on:{"click":function($event){return _vm.input(color,index)}}},[_c("div",{staticClass:"color-palette_input-color",style:_vm.inlineStyle(color),attrs:{"data-tooltip":_vm.toTooltip(color)}})])}),0)])],2)};var staticRenderFns=[];return{render:render,staticRenderFns:staticRenderFns,_compiled:true,_scopeId:null,functional:undefined}}());document.querySelector("svg defs").innerHTML+="\n <symbol id=\"icon-palette-pipette\" viewbox=\"0 0 36 35.99\">\n <path d=\"M35.41,5.25,30.74.58a2,2,0,0,0-2.83,0L21.66,6.83,17.83,3,15,5.82l2.84,2.84L0,26.49V36H9.5L27.34,18.15,30.17,21,33,18.16l-3.84-3.84,6.25-6.25A2,2,0,0,0,35.41,5.25ZM7.84,32,4,28.15,20.13,12,24,15.87Z\"/>\n </symbol>\n";panel.plugin("sylvainjule/color-palette",{fields:{"color-palette":a}});})();