diff --git a/index.js b/index.js index 5a653f9..a5e7d06 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -(()=>{(function(){"use strict";function p(n,c,d){var a,o;const r=n[c];return r?d>=((a=r.min)!=null?a:0)&&d<=((o=r.max)!=null?o:1/0):!0}panel.plugin("rasteiner/conditionalblocks",{use:[function(n){const c=n.component("k-layout-field").options,a=c.components["k-block-layouts"].components["k-layout"].components["k-layout-column"],o=n.component("k-block-selector").options,l=n.component("k-blocks").options;n.component("k-layout-field",{extends:c,provide(){return{constraints:this.requires}},props:{requires:{type:Object,required:!1}}}),a.provide=function(){const[t,s]=this.width.split("/");return{cwidth:parseInt(t)/parseInt(s)}},n.component("k-blocks",{extends:l,inject:["constraints","cwidth"],methods:{append(t,s){this.constraints&&this.cwidth&&Array.isArray(t)&&(t=t.filter(i=>p(this.constraints,i.type,this.cwidth))),l.methods.append.call(this,t,s)}},computed:{draggableOptions(){const t=l.computed.draggableOptions.call(this);return this.constraints&&this.cwidth&&(t.data.fieldsets=Object.fromEntries(Object.entries(t.data.fieldsets).filter(([s])=>p(this.constraints,s,this.cwidth)))),t}}}),o.inject=["constraints","cwidth"];const h=o.methods.open;o.methods.open=function(){if(h.call(this,...arguments),!this.constraints||!this.cwidth)return;const t=this.cwidth,s=Object.entries(this.constraints).filter(([i,e])=>e.min&&te.max).map(([i,e])=>i);this.disabled=[...this.disabled,...s]}}]})})();})(); +(()=>{(function(){"use strict";function p(n,c,d){var a,i;const r=n[c];return r?d>=((a=r.min)!=null?a:0)&&d<=((i=r.max)!=null?i:1/0):!0}panel.plugin("rasteiner/conditionalblocks",{use:[function(n){const c=n.component("k-layout-field").options,a=c.components["k-block-layouts"].components["k-layout"].components["k-layout-column"],i=n.component("k-block-selector").options,l=n.component("k-blocks").options;n.component("k-layout-field",{extends:c,provide(){return{constraints:this.requires&&!Array.isArray(this.requires)?this.requires:{}}},props:{requires:{type:Object|Array,required:!1}}}),a.provide=function(){const[t,s]=this.width.split("/");return{cwidth:parseInt(t)/parseInt(s)}},n.component("k-blocks",{extends:l,inject:["constraints","cwidth"],methods:{append(t,s){this.constraints&&this.cwidth&&Array.isArray(t)&&(t=t.filter(o=>p(this.constraints,o.type,this.cwidth))),l.methods.append.call(this,t,s)}},computed:{draggableOptions(){const t=l.computed.draggableOptions.call(this);return this.constraints&&this.cwidth&&(t.data.fieldsets=Object.fromEntries(Object.entries(t.data.fieldsets).filter(([s])=>p(this.constraints,s,this.cwidth)))),t}}}),i.inject=["constraints","cwidth"];const h=i.methods.open;i.methods.open=function(){if(h.call(this,...arguments),!this.constraints||!this.cwidth)return;const t=this.cwidth,s=Object.entries(this.constraints).filter(([o,e])=>e.min&&te.max).map(([o,e])=>o);this.disabled=[...this.disabled,...s]}}]})})();})(); diff --git a/src/index.js b/src/index.js index 3ca0f7f..5cb0991 100644 --- a/src/index.js +++ b/src/index.js @@ -21,12 +21,12 @@ panel.plugin("rasteiner/conditionalblocks", { provide() { return { - constraints: this.requires, + constraints: (this.requires && !Array.isArray(this.requires)) ? this.requires : {}, }; }, props: { requires: { - type: Object, + type: Object|Array, required: false, }, },