diff --git a/index.js b/index.js index 21f6145..9b6dee0 100644 --- a/index.js +++ b/index.js @@ -1 +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");if(-1!==r&&i.splice(r,1),i.length!=n.length)return!1;for(var o=0;o0&&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 \n \n \n";panel.plugin("sylvainjule/color-palette",{fields:{"color-palette":a}});})(); \ No newline at end of file +(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;s0&&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 \n \n \n";panel.plugin("sylvainjule/color-palette",{fields:{"color-palette":a}});})(); \ No newline at end of file diff --git a/package.json b/package.json index a717a2e..3bec79e 100644 --- a/package.json +++ b/package.json @@ -13,13 +13,13 @@ "recognizeSelfClosing": true }, "devDependencies": { - "@vue/component-compiler-utils": "^3.0.0", + "@vue/component-compiler-utils": "^3.1.2", "cssnano": "^4.1.10", - "sass": "^1.21.0", - "vue-template-compiler": "^2.6.10" + "sass": "^1.26.3", + "vue-template-compiler": "^2.6.11" }, "dependencies": { - "vue": "^2.6.10", + "vue": "^2.6.11", "vue-hot-reload-api": "^2.3.4" } } diff --git a/src/components/field/ColorPalette.vue b/src/components/field/ColorPalette.vue index 288347e..4882582 100644 --- a/src/components/field/ColorPalette.vue +++ b/src/components/field/ColorPalette.vue @@ -152,9 +152,11 @@ export default { let aKeys = Object.keys(a); let bKeys = Object.keys(b); - // Make sure the selected option doesn't have its 'key' key - let keyIndex = aKeys.indexOf('key') - if(keyIndex !== -1) aKeys.splice(keyIndex, 1) + // Make sure to compare without the keys + let aKeyIndex = aKeys.indexOf('key') + if(aKeyIndex !== -1) aKeys.splice(aKeyIndex, 1) + let bKeyIndex = bKeys.indexOf('key') + if(bKeyIndex !== -1) bKeys.splice(bKeyIndex, 1) // Different keys? not equivalent if (aKeys.length != bKeys.length) {