Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit bdd3ca0

Browse files
author
bensladden
committed
only compact items that are added after loading
1 parent 04d90bc commit bdd3ca0

10 files changed

+500
-277
lines changed

dist/vue-responsive-dash.common.js

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

dist/vue-responsive-dash.common.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-responsive-dash.umd.js

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

dist/vue-responsive-dash.umd.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-responsive-dash.umd.min.js

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

dist/vue-responsive-dash.umd.min.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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-responsive-dash",
3-
"version": "0.3.29",
3+
"version": "0.3.30",
44
"keywords": [
55
"vuejs",
66
"vue",

src/App.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
:minRowHeight="minRowHeight"
1717
:compact="compact"
1818
:margin="margin"
19+
:debug="true"
1920
>
2021
<Dash-Item
2122
v-for="item in layout.items"
@@ -183,6 +184,17 @@ export default {
183184
],
184185
},
185186
],
187+
dlayouts: [
188+
{
189+
breakpoint: "xl",
190+
numberOfCols: 12,
191+
items: [
192+
{ id: "1", x: 6, y: 3, width: 6, height: 3 },
193+
{ id: "2", x: 9, y: 0, width: 3, height: 3 },
194+
{ id: "3", x: 0, y: 0, width: 8, height: 3 },
195+
],
196+
},
197+
],
186198
currentBreakpoint: "",
187199
origLayout: [],
188200
testHelper: false,

src/components/DashLayout.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
Layout Number of Cols: {{ numberOfCols }} <br />
2323
placeholder: {{ JSON.stringify(placeholder) }} <br />
2424
Items: {{ JSON.stringify(itemsFromLayout) }} <br />
25-
Height: {{ height }}
25+
Height: {{ height }} <br />
26+
Attrs: {{ $attrs }}
2627
</div>
2728
</div>
2829
</template>
@@ -154,7 +155,11 @@ export default {
154155
},
155156
},
156157
mounted() {
157-
this.l = new Layout(this.$props);
158+
let initialItems = [];
159+
if (this.$attrs?.items) {
160+
initialItems = this.$attrs.items;
161+
}
162+
this.l = new Layout({ ...this.$props, initialItems });
158163
//Check if dashboard exists and if not then start a watcher
159164
if (this.dashboard) {
160165
this.dashboard.addLayoutInstance(this.l);

src/components/Layout.model.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class Layout {
1919
private _useCssTransforms: boolean;
2020
private _itemBeingDragged: boolean = false;
2121
private _itemBeingResized: boolean = false;
22+
private _initalItemIds: Array<number | string> = [];
2223
private _dashItems: DashItem[] = [];
2324
private _dragStartListeners: Subscription[] = [];
2425
private _dragListeners: Subscription[] = [];
@@ -43,6 +44,7 @@ export class Layout {
4344
minColWidth,
4445
maxColWidth,
4546
compact,
47+
initialItems,
4648
}: {
4749
breakpoint: string;
4850
numberOfCols: number;
@@ -59,6 +61,7 @@ export class Layout {
5961
minColWidth?: number | boolean;
6062
maxColWidth?: number | boolean;
6163
compact?: boolean;
64+
initialItems?: Item[];
6265
}) {
6366
this._breakpoint = breakpoint;
6467
this._numberOfCols = numberOfCols;
@@ -137,6 +140,12 @@ export class Layout {
137140
} else {
138141
this._compact = Layout.defaults.compact;
139142
}
143+
144+
if (typeof initialItems !== "undefined") {
145+
this._initalItemIds = initialItems.map((item) => {
146+
return item.id;
147+
});
148+
}
140149
}
141150
get breakpoint() {
142151
return this._breakpoint;
@@ -361,8 +370,11 @@ export class Layout {
361370
});
362371

363372
//Check that the added item has not caused a collision and if so move the others.
364-
let items = this.compactLayout(this.items);
365-
this.syncItems(items);
373+
//Only do this on items added after initialisation
374+
if (!this._initalItemIds.includes(d.id)) {
375+
let items = this.compactLayout(this.items);
376+
this.syncItems(items);
377+
}
366378
}
367379
removeDashItem(d: DashItem) {
368380
let index = this._dashItems.findIndex((item) => {

0 commit comments

Comments
 (0)