Skip to content

Commit fb73c93

Browse files
committed
fix #1
1 parent b57ee49 commit fb73c93

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
function fitsConstraint(constraints, type, width) {
2+
const constraint = constraints[type];
3+
if(constraint) {
4+
return width >= (constraint.min ?? 0) && width <= (constraint.max ?? Infinity)
5+
}
6+
return true;
7+
}
8+
19
panel.plugin("rasteiner/conditionalblocks", {
210
use: [
311
function (Vue) {
@@ -33,29 +41,31 @@ panel.plugin("rasteiner/conditionalblocks", {
3341
};
3442
};
3543

36-
const draggableOptions = Blocks.computed.draggableOptions;
37-
delete Blocks.computed.draggableOptions;
38-
3944
Vue.component("k-blocks", {
4045
extends: Blocks,
4146
inject: ["constraints", "cwidth"],
47+
methods: {
48+
append(what, index) {
49+
if(this.constraints && this.cwidth && Array.isArray(what)) {
50+
what = what.filter((block) => fitsConstraint(this.constraints, block.type, this.cwidth));
51+
}
52+
53+
Blocks.methods.append.call(this, what, index);
54+
}
55+
},
4256
computed: {
4357
draggableOptions() {
44-
const original = draggableOptions.call(this);
58+
const original = Blocks.computed.draggableOptions.call(this);
4559

4660
if (this.constraints && this.cwidth) {
4761
//remove fieldsets that are not allowed by constraints
4862
original.data.fieldsets = Object.fromEntries(
49-
Object.entries(original.data.fieldsets).filter(([type]) => {
50-
const constraint = this.constraints[type];
51-
return !(
52-
(constraint?.min && this.cwidth < constraint.min) ||
53-
(constraint?.max && this.cwidth > constraint.max)
54-
);
55-
})
63+
Object.entries(original.data.fieldsets).filter(([type]) => fitsConstraint(this.constraints, type, this.cwidth))
5664
);
65+
console.log(original.data.fieldsets);
5766
}
5867

68+
5969
return original;
6070
},
6171
},

0 commit comments

Comments
 (0)