Skip to content
Snippets Groups Projects
Commit 193777ff authored by Julian's avatar Julian
Browse files

Allow data to be a function

parent 998d06b6
No related branches found
No related tags found
1 merge request!2Resolve "Implement basic functionality"
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
v-for="item in value" v-for="item in value"
:key="item.key" :key="item.key"
:drag-i-d="item.key" :drag-i-d="item.key"
:x="get('x', item)" :x="getInt('x', item)"
:y="get('y', item)" :y="getInt('y', item)"
:w="get('w', item)" :w="getInt('w', item)"
:h="get('h', item)" :h="getInt('h', item)"
:data="item.data" :data="getObject('data', item)"
:context="context" :context="context"
:grid-id="gridId" :grid-id="gridId"
> >
<slot v-bind="item" name="item"> <slot v-bind="transformItem(item)" name="item">
<dl> <dl>
<dt>Key</dt> <dt>Key</dt>
<dd>{{ item.key }}</dd> <dd>{{ item.key }}</dd>
...@@ -88,8 +88,14 @@ export default { ...@@ -88,8 +88,14 @@ export default {
for (let item of this.value) { for (let item of this.value) {
if (key === item.key) continue; if (key === item.key) continue;
if (x >= item.x && x < item.x + item.w) { if (
if (y >= item.y && y < item.y + item.h) { x >= this.getInt("x", item) &&
x < this.getInt("x", item) + this.getInt("w", item)
) {
if (
y >= this.getInt("y", item) &&
y < this.getInt("y", item) + this.getInt("h", item)
) {
return false; return false;
} }
} }
...@@ -184,9 +190,30 @@ export default { ...@@ -184,9 +190,30 @@ export default {
y: Math.ceil(y / (this.$el.offsetHeight / this.rows)), y: Math.ceil(y / (this.$el.offsetHeight / this.rows)),
}; };
}, },
get(property, item) { getInt(property, item) {
let val = item[property] || 1; let val = item[property] || 1;
return val instanceof Function ? val(this) : parseInt(val); return val instanceof Function ? val(this.gridData) : parseInt(val);
},
getObject(property, item) {
let val = item[property] || {};
return val instanceof Function ? val(this.gridData) : val;
},
transformItem(item) {
let newItem = { key: item.key };
newItem.x = this.getInt("x", item);
newItem.y = this.getInt("y", item);
newItem.w = this.getInt("w", item);
newItem.h = this.getInt("h", item);
newItem.data = this.getObject("data", item);
return newItem;
},
},
computed: {
gridData() {
return {
gridId: this.gridId,
context: this.context,
};
}, },
}, },
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment