diff --git a/src/DragGrid.vue b/src/DragGrid.vue index 4c0874a399045e63d69d630b4ca4b6255a59097f..dc69c5289116ebf3ebf996789453e73c1cd64449 100644 --- a/src/DragGrid.vue +++ b/src/DragGrid.vue @@ -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, + }; }, }, };