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 @@
v-for="item in value"
:key="item.key"
:drag-i-d="item.key"
:x="get('x', item)"
:y="get('y', item)"
:w="get('w', item)"
:h="get('h', item)"
:data="item.data"
:x="getInt('x', item)"
:y="getInt('y', item)"
:w="getInt('w', item)"
:h="getInt('h', item)"
:data="getObject('data', item)"
:context="context"
:grid-id="gridId"
>
<slot v-bind="item" name="item">
<slot v-bind="transformItem(item)" name="item">
<dl>
<dt>Key</dt>
<dd>{{ item.key }}</dd>
......@@ -88,8 +88,14 @@ export default {
for (let item of this.value) {
if (key === item.key) continue;
if (x >= item.x && x < item.x + item.w) {
if (y >= item.y && y < item.y + item.h) {
if (
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;
}
}
......@@ -184,9 +190,30 @@ export default {
y: Math.ceil(y / (this.$el.offsetHeight / this.rows)),
};
},
get(property, item) {
getInt(property, item) {
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