Skip to content

Commit b5e5697

Browse files
committed
placeholder implemented, moving items improvements,
1 parent 13261df commit b5e5697

File tree

10 files changed

+270
-163
lines changed

10 files changed

+270
-163
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ vue-grid-layout is a grid layout system, like [Gridster](http://gridster.net), f
1515
- [Features](#features)
1616
- [Installation](#installation)
1717
- [Usage](#usage)
18-
- [Providing Grid Width](#providing-grid-width)
19-
- [Grid Layout Props](#grid-layout-props)
20-
- [Grid Item Props](#grid-item-props)
2118
- [Contribute](#contribute)
2219
- [TODO List](#todo-list)
2320
@@ -28,7 +25,7 @@ vue-grid-layout is a grid layout system, like [Gridster](http://gridster.net), f
2825

2926
#### Projects based on vue-grid-layout
3027

31-
- [Draxed](https://www.draxed.com/)
28+
- [Draxed](https://www.draxed.com/?utm_source=github&utm_medium=web&utm_campaign=vue-grid-layout)
3229

3330
*Know of others? Create a PR to let me know!*
3431

@@ -130,5 +127,4 @@ If you have a feature request, please add it as an issue or make a pull request.
130127
- [x] Draggable grid items
131128
- [x] Resizable grid items
132129
- [ ] Static elements
133-
- [ ] Min/max w/h per item
134-
- [ ] Resizable handles on other corners
130+
- [x] Min/max w/h per item

dist/vue-grid-layout.js

Lines changed: 123 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-grid-layout.js.map

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

dist/vue-grid-layout.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ <h1>Vue Grid Layout</h1>
3333
:is-draggable="true"
3434
:is-resizable="true"
3535
:vertical-compact="true"
36-
:margin="[10, 10]"
36+
:margin="[5, 5]"
3737
:use-css-transforms="true"
3838
>
39-
4039
<grid-item v-for="item in layout"
4140
:x.sync="item.x"
4241
:y.sync="item.y"
4342
:w.sync="item.w"
4443
:h.sync="item.h"
44+
:min-w="2"
45+
:min-h="2"
4546
:i="item.i">
46-
{{item.i}}
47+
<test-element :text="item.i"></test-element>
4748
</grid-item>
4849
</grid-layout>
4950
</div>

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"main": "src/app.js",
1616
"scripts": {
1717
"dev": "webpack-dev-server --host 0.0.0.0 --inline --hot ",
18-
"build": "set NODE_ENV=production && webpack --progress --hide-modules",
19-
"dist": "set NODE_ENV=production && webpack --progress --hide-modules --config webpack.build.js && webpack --progress --hide-modules --config webpack.build.min.js"
18+
"build": "cross-env NODE_ENV=production && webpack --progress --hide-modules",
19+
"dist": "webpack --progress --hide-modules --config webpack.build.js && cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.build.min.js"
2020
},
2121
"repository": {
2222
"type": "git",
@@ -29,6 +29,7 @@
2929
"babel-runtime": "^6.0.0"
3030
},
3131
"devDependencies": {
32+
"cross-env": "^2.0.0",
3233
"babel-cli": "^6.5.1",
3334
"babel-core": "^6.x",
3435
"babel-eslint": "^4.1.8",

src/GridItem.vue

Lines changed: 77 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<template>
22
<div v-el:item
33
class="vue-grid-item"
4-
:class="{ 'vue-resizable' : isResizable, 'vue-draggable-dragging' : isDragging, 'cssTransforms' : useCssTransforms }"
4+
:class="{ 'vue-resizable' : isResizable, 'resizing' : isResizing, 'vue-draggable-dragging' : isDragging, 'cssTransforms' : useCssTransforms }"
55
:style="style"
66
>
77
<slot></slot>
8-
<!--span class="text">{{id}}</span-->
9-
<!--<span class="text">{{i}}</span>-->
10-
<!--<pre>
11-
x: {{ x | json}}
12-
y: {{ y | json}}
13-
w: {{ w | json}}
14-
h: {{ h | json}}
15-
</pre>-->
16-
<span v-if="isResizable" v-el:handle class="vue-resizable-handle"></span>
17-
</div>
8+
<!--<pre>
9+
x: {{ x | json}}
10+
y: {{ y | json}}
11+
w: {{ w | json}}
12+
h: {{ h | json}}
13+
</pre>-->
14+
<span v-if="isResizable" v-el:handle class="vue-resizable-handle"></span>
1815
</div>
1916
</template>
2017
<style>
@@ -26,7 +23,8 @@
2623
transition-property: transform;
2724
}
2825
.vue-grid-item.resizing {
29-
z-index: 1;
26+
opacity: 0.6;
27+
z-index: 3;
3028
}
3129
3230
.vue-grid-item.vue-draggable-dragging {
@@ -91,6 +89,24 @@
9189
type: Number,
9290
required: true
9391
},
92+
isDraggable: {
93+
type: Boolean,
94+
required: true
95+
},
96+
isResizable: {
97+
type: Boolean,
98+
required: true
99+
},
100+
useCssTransforms: {
101+
type: Boolean,
102+
required: true
103+
},
104+
static: {
105+
type: Boolean,
106+
required: false,
107+
default: false
108+
},
109+
*/
94110
minH: {
95111
type: Number,
96112
required: false,
@@ -111,23 +127,6 @@
111127
required: false,
112128
default: Infinity
113129
},
114-
isDraggable: {
115-
type: Boolean,
116-
required: true
117-
},
118-
isResizable: {
119-
type: Boolean,
120-
required: true
121-
},
122-
useCssTransforms: {
123-
type: Boolean,
124-
required: true
125-
},*/
126-
static: {
127-
type: Boolean,
128-
required: false,
129-
default: false
130-
},
131130
x: {
132131
type: Number,
133132
required: true
@@ -155,10 +154,6 @@
155154
rowHeight: 30,
156155
margin: [10, 10],
157156
maxRows: Infinity,
158-
minH: 1,
159-
minW: 1,
160-
maxH: Infinity,
161-
maxW: Infinity,
162157
isDraggable: true,
163158
isResizable: true,
164159
useCssTransforms: true,
@@ -171,19 +166,14 @@
171166
lastY: NaN,
172167
lastW: NaN,
173168
lastH: NaN,
174-
className: "",
175-
style: ""
169+
style: {}
176170
}
177171
},
178172
ready: function() {
179173
this.cols = this.$parent.colNum;
180174
this.rowHeight = this.$parent.rowHeight;
181175
this.margin = this.$parent.margin;
182176
this.maxRows = this.$parent.maxRows;
183-
this.minH = this.$parent.minH;
184-
this.minW = this.$parent.minW;
185-
this.maxH = this.$parent.maxH;
186-
this.maxW = this.$parent.maxW;
187177
this.isDraggable = this.$parent.isDraggable;
188178
this.isResizable = this.$parent.isResizable;
189179
this.useCssTransforms = this.$parent.useCssTransforms;
@@ -247,6 +237,15 @@
247237
// var pos = this.calcPosition(x, y, w, h);
248238
var pos = this.calcPosition(this.x, this.y, this.w, this.h);
249239
240+
if (this.isDragging) {
241+
pos.top = this.dragging.top;
242+
pos.left = this.dragging.left;
243+
}
244+
if (this.isResizing) {
245+
pos.width = this.resizing.width;
246+
pos.height = this.resizing.height;
247+
}
248+
250249
//const {usePercentages, containerWidth, useCssTransforms} = this.props;
251250
252251
let style;
@@ -258,8 +257,14 @@
258257
else {
259258
style = setTopLeft(pos.top, pos.left, pos.width, pos.height);
260259
}
260+
/*
261+
if (this.isDragging || this.isResizing) {
262+
style["z-index"] = 3;
263+
}
264+
*/
265+
// this.style = createMarkup(style);
266+
this.style = style;
261267
262-
this.style = createMarkup(style);
263268
},
264269
handleResize: function(event) {
265270
const position = getControlPosition(event);
@@ -276,15 +281,6 @@
276281
this.resizing = newSize;
277282
this.isResizing = true;
278283
break;
279-
case "resizeend":
280-
//console.log("### resize end => x=" +this.x + " y=" + this.y + " w=" + this.w + " h=" + this.h);
281-
var pos = this.calcPosition(this.x, this.y, this.w, this.h);
282-
newSize.width = pos.width;
283-
newSize.height = pos.height;
284-
// console.log("### resize end => " + JSON.stringify(newSize));
285-
this.resizing = null;
286-
this.isResizing = false;
287-
break;
288284
case "resizemove":
289285
// console.log("### resize => " + event.type + ", lastW=" + this.lastW + ", lastH=" + this.lastH);
290286
const coreEvent = createCoreData(this.lastW, this.lastH, x, y);
@@ -295,9 +291,32 @@
295291
///console.log("### resize => " + event.type + ", deltaX=" + coreEvent.deltaX + ", deltaY=" + coreEvent.deltaY);
296292
this.resizing = newSize;
297293
break;
294+
case "resizeend":
295+
//console.log("### resize end => x=" +this.x + " y=" + this.y + " w=" + this.w + " h=" + this.h);
296+
var pos = this.calcPosition(this.x, this.y, this.w, this.h);
297+
newSize.width = pos.width;
298+
newSize.height = pos.height;
299+
// console.log("### resize end => " + JSON.stringify(newSize));
300+
this.resizing = null;
301+
this.isResizing = false;
302+
break;
298303
}
304+
299305
// Get new WH
300306
var pos = this.calcWH(newSize.height, newSize.width);
307+
if (pos.w < this.minW) {
308+
pos.w = this.minW;
309+
}
310+
if (pos.w > this.maxW) {
311+
pos.w = this.maxW;
312+
}
313+
if (pos.h < this.minH) {
314+
pos.h = this.minH;
315+
}
316+
if (pos.h > this.maxH) {
317+
pos.h = this.maxH;
318+
}
319+
301320
if (pos.h >= 1) {
302321
this.h = pos.h;
303322
} else {
@@ -312,7 +331,7 @@
312331
this.lastW = x;
313332
this.lastH = y;
314333
315-
this.$dispatch("resizeEvent", event.type, this.i, this.h, this.w);
334+
this.$dispatch("resizeEvent", event.type, this.i, this.x, this.y, this.h, this.w);
316335
},
317336
handleDrag(event) {
318337
if (this.isResizing) return;
@@ -366,7 +385,7 @@
366385
this.lastX = x;
367386
this.lastY = y;
368387
369-
this.$dispatch("dragEvent", event.type, this.i, this.x, this.y);
388+
this.$dispatch("dragEvent", event.type, this.i, this.x, this.y, this.w, this.h);
370389
},
371390
calcPosition: function(x, y, w, h) {
372391
const colWidth = this.calcColWidth();
@@ -445,10 +464,13 @@
445464
},
446465
compact: function(layout) {
447466
var l = getLayoutItem(layout, this.i);
448-
this.x = l.x;
449-
this.y = l.y;
450-
this.h = l.h;
451-
this.w = l.w;
467+
if (l !== undefined && l !== null) {
468+
this.x = l.x;
469+
this.y = l.y;
470+
this.h = l.h;
471+
this.w = l.w;
472+
}
473+
this.createStyle();
452474
}
453475
}
454476
}

0 commit comments

Comments
 (0)