gridstack 12.3.3 → 12.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  2. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  3. package/dist/angular/esm2020/lib/gridstack.component.mjs +4 -2
  4. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  5. package/dist/angular/esm2020/lib/types.mjs +2 -2
  6. package/dist/angular/fesm2015/gridstack-angular.mjs +6 -4
  7. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  8. package/dist/angular/fesm2020/gridstack-angular.mjs +7 -5
  9. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  10. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  11. package/dist/angular/lib/gridstack.component.d.ts +4 -4
  12. package/dist/angular/lib/types.d.ts +1 -1
  13. package/dist/angular/package.json +1 -1
  14. package/dist/angular/projects/lib/src/index.d.ts +5 -0
  15. package/dist/angular/projects/lib/src/index.js +9 -0
  16. package/dist/angular/projects/lib/src/index.js.map +1 -0
  17. package/dist/angular/projects/lib/src/lib/base-widget.d.ts +56 -0
  18. package/dist/angular/projects/lib/src/lib/base-widget.js +94 -0
  19. package/dist/angular/projects/lib/src/lib/base-widget.js.map +1 -0
  20. package/dist/angular/projects/lib/src/lib/gridstack-item.component.d.ts +76 -0
  21. package/dist/angular/projects/lib/src/lib/gridstack-item.component.js +112 -0
  22. package/dist/angular/projects/lib/src/lib/gridstack-item.component.js.map +1 -0
  23. package/dist/angular/projects/lib/src/lib/gridstack.component.d.ts +233 -0
  24. package/dist/angular/projects/lib/src/lib/gridstack.component.js +457 -0
  25. package/dist/angular/projects/lib/src/lib/gridstack.component.js.map +1 -0
  26. package/dist/angular/projects/lib/src/lib/gridstack.module.d.ts +29 -0
  27. package/dist/angular/projects/lib/src/lib/gridstack.module.js +52 -0
  28. package/dist/angular/projects/lib/src/lib/gridstack.module.js.map +1 -0
  29. package/dist/angular/projects/lib/src/lib/types.d.ts +51 -0
  30. package/dist/angular/projects/lib/src/lib/types.js +6 -0
  31. package/dist/angular/projects/lib/src/lib/types.js.map +1 -0
  32. package/dist/angular/src/base-widget.ts +13 -13
  33. package/dist/angular/src/gridstack-item.component.ts +5 -5
  34. package/dist/angular/src/gridstack.component.ts +34 -32
  35. package/dist/angular/src/gridstack.module.ts +4 -4
  36. package/dist/angular/src/types.ts +3 -2
  37. package/dist/gridstack-all.js +1 -1
  38. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  39. package/dist/gridstack-all.js.map +1 -1
  40. package/dist/gridstack.css +1 -1
  41. package/dist/src/dd-base-impl.d.ts +1 -1
  42. package/dist/src/dd-base-impl.js +1 -1
  43. package/dist/src/dd-base-impl.js.map +1 -1
  44. package/dist/src/dd-draggable.d.ts +1 -1
  45. package/dist/src/dd-draggable.js +1 -1
  46. package/dist/src/dd-draggable.js.map +1 -1
  47. package/dist/src/dd-droppable.d.ts +1 -1
  48. package/dist/src/dd-droppable.js +7 -1
  49. package/dist/src/dd-droppable.js.map +1 -1
  50. package/dist/src/dd-element.d.ts +1 -1
  51. package/dist/src/dd-element.js +1 -1
  52. package/dist/src/dd-element.js.map +1 -1
  53. package/dist/src/dd-gridstack.d.ts +1 -1
  54. package/dist/src/dd-gridstack.js +1 -1
  55. package/dist/src/dd-gridstack.js.map +1 -1
  56. package/dist/src/dd-manager.d.ts +1 -1
  57. package/dist/src/dd-manager.js +1 -1
  58. package/dist/src/dd-manager.js.map +1 -1
  59. package/dist/src/dd-resizable-handle.d.ts +5 -4
  60. package/dist/src/dd-resizable-handle.js +23 -8
  61. package/dist/src/dd-resizable-handle.js.map +1 -1
  62. package/dist/src/dd-resizable.d.ts +3 -5
  63. package/dist/src/dd-resizable.js +5 -10
  64. package/dist/src/dd-resizable.js.map +1 -1
  65. package/dist/src/dd-touch.d.ts +1 -1
  66. package/dist/src/dd-touch.js +1 -1
  67. package/dist/src/dd-touch.js.map +1 -1
  68. package/dist/src/gridstack-engine.d.ts +1 -1
  69. package/dist/src/gridstack-engine.js +7 -1
  70. package/dist/src/gridstack-engine.js.map +1 -1
  71. package/dist/src/gridstack.d.ts +1 -2
  72. package/dist/src/gridstack.js +9 -18
  73. package/dist/src/gridstack.js.map +1 -1
  74. package/dist/src/gridstack.scss +1 -1
  75. package/dist/src/types.d.ts +11 -6
  76. package/dist/src/types.js +1 -1
  77. package/dist/src/types.js.map +1 -1
  78. package/dist/src/utils.d.ts +1 -270
  79. package/dist/src/utils.js +37 -31
  80. package/dist/src/utils.js.map +1 -1
  81. package/doc/API.md +166 -165
  82. package/package.json +5 -5
  83. package/dist/dd-base-impl.d.ts +0 -69
  84. package/dist/dd-base-impl.js +0 -70
  85. package/dist/dd-base-impl.js.map +0 -1
  86. package/dist/dd-draggable.d.ts +0 -20
  87. package/dist/dd-draggable.js +0 -364
  88. package/dist/dd-draggable.js.map +0 -1
  89. package/dist/dd-droppable.d.ts +0 -26
  90. package/dist/dd-droppable.js +0 -149
  91. package/dist/dd-droppable.js.map +0 -1
  92. package/dist/dd-element.d.ts +0 -27
  93. package/dist/dd-element.js +0 -91
  94. package/dist/dd-element.js.map +0 -1
  95. package/dist/dd-gridstack.d.ts +0 -82
  96. package/dist/dd-gridstack.js +0 -165
  97. package/dist/dd-gridstack.js.map +0 -1
  98. package/dist/dd-manager.d.ts +0 -43
  99. package/dist/dd-manager.js +0 -14
  100. package/dist/dd-manager.js.map +0 -1
  101. package/dist/dd-resizable-handle.d.ts +0 -18
  102. package/dist/dd-resizable-handle.js +0 -113
  103. package/dist/dd-resizable-handle.js.map +0 -1
  104. package/dist/dd-resizable.d.ts +0 -30
  105. package/dist/dd-resizable.js +0 -304
  106. package/dist/dd-resizable.js.map +0 -1
  107. package/dist/dd-touch.d.ts +0 -33
  108. package/dist/dd-touch.js +0 -145
  109. package/dist/dd-touch.js.map +0 -1
  110. package/dist/gridstack-engine.d.ts +0 -321
  111. package/dist/gridstack-engine.js +0 -1272
  112. package/dist/gridstack-engine.js.map +0 -1
  113. package/dist/gridstack.d.ts +0 -802
  114. package/dist/gridstack.js +0 -2872
  115. package/dist/gridstack.js.map +0 -1
  116. package/dist/spec/gridstack-engine-spec.d.ts +0 -1
  117. package/dist/spec/gridstack-engine-spec.js +0 -358
  118. package/dist/spec/gridstack-engine-spec.js.map +0 -1
  119. package/dist/spec/gridstack-spec.d.ts +0 -1
  120. package/dist/spec/gridstack-spec.js +0 -1780
  121. package/dist/spec/gridstack-spec.js.map +0 -1
  122. package/dist/spec/integration/gridstack-integration.spec.d.ts +0 -1
  123. package/dist/spec/integration/gridstack-integration.spec.js +0 -171
  124. package/dist/spec/integration/gridstack-integration.spec.js.map +0 -1
  125. package/dist/spec/regression-spec.d.ts +0 -1
  126. package/dist/spec/regression-spec.js +0 -100
  127. package/dist/spec/regression-spec.js.map +0 -1
  128. package/dist/spec/utils-spec.d.ts +0 -1
  129. package/dist/spec/utils-spec.js +0 -243
  130. package/dist/spec/utils-spec.js.map +0 -1
  131. package/dist/types.d.ts +0 -427
  132. package/dist/types.js +0 -38
  133. package/dist/types.js.map +0 -1
  134. package/dist/utils.d.ts +0 -283
  135. package/dist/utils.js +0 -787
  136. package/dist/utils.js.map +0 -1
  137. package/dist/vitest.config.d.ts +0 -2
  138. package/dist/vitest.config.js +0 -74
  139. package/dist/vitest.config.js.map +0 -1
  140. package/dist/vitest.setup.d.ts +0 -1
  141. package/dist/vitest.setup.js +0 -90
  142. package/dist/vitest.setup.js.map +0 -1
@@ -1,1780 +0,0 @@
1
- import { GridStack } from '../src/gridstack';
2
- import { Utils } from '../src/utils';
3
- describe('gridstack >', () => {
4
- 'use strict';
5
- let grid;
6
- let grids;
7
- let find = function (id) {
8
- return grid.engine.nodes.find(n => n.id === id);
9
- };
10
- let findEl = function (id) {
11
- return find(id).el;
12
- };
13
- // grid has 4x2 and 4x4 top-left aligned - used on most test cases
14
- let gridHTML = '<div class="grid-stack">' +
15
- ' <div class="grid-stack-item" gs-x="0" gs-y="0" gs-w="4" gs-h="2" gs-id="gsItem1" id="item1">' +
16
- ' <div class="grid-stack-item-content">item 1 text</div>' +
17
- ' </div>' +
18
- ' <div class="grid-stack-item" gs-x="4" gs-y="0" gs-w="4" gs-h="4" gs-id="gsItem2" id="item2">' +
19
- ' <div class="grid-stack-item-content">item 2 text</div>' +
20
- ' </div>' +
21
- '</div>';
22
- let gridstackHTML = '<div style="width: 800px; height: 600px" id="gs-cont">' + gridHTML + '</div>';
23
- let gridstackSmallHTML = '<div style="width: 400px; height: 600px" id="gs-cont">' + gridHTML + '</div>';
24
- // empty grid
25
- let gridstackEmptyHTML = '<div style="width: 800px; height: 600px" id="gs-cont">' +
26
- ' <div class="grid-stack">' +
27
- ' </div>' +
28
- '</div>';
29
- // nested empty grids
30
- let gridstackNestedHTML = '<div style="width: 800px; height: 600px" id="gs-cont">' +
31
- ' <div class="grid-stack">' +
32
- ' <div class="grid-stack-item">' +
33
- ' <div class="grid-stack-item-content">item 1</div>' +
34
- ' <div class="grid-stack-item-content">' +
35
- ' <div class="grid-stack sub1"></div>' +
36
- ' </div>' +
37
- ' </div>' +
38
- ' </div>' +
39
- '</div>';
40
- // generic widget with no param
41
- let widgetHTML = '<div id="item3"><div class="grid-stack-item-content"> hello </div></div>';
42
- describe('grid.init() / initAll() >', () => {
43
- beforeEach(() => {
44
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
45
- });
46
- afterEach(() => {
47
- document.body.removeChild(document.getElementById('gs-cont'));
48
- });
49
- it('use selector >', () => {
50
- grid = GridStack.init(undefined, '.grid-stack');
51
- expect(grid).not.toBe(null);
52
- });
53
- it('use selector no dot >', () => {
54
- grid = GridStack.init(null, 'grid-stack');
55
- expect(grid).not.toBe(null);
56
- });
57
- it('use wrong selector >', () => {
58
- grid = GridStack.init(null, 'BAD_SELECTOR_TEST');
59
- expect(grid).toEqual(null);
60
- });
61
- it('initAll use selector >', () => {
62
- grids = GridStack.initAll(undefined, '.grid-stack');
63
- expect(grids.length).toBe(1);
64
- });
65
- it('initAll use selector no dot >', () => {
66
- grids = GridStack.initAll(undefined, 'grid-stack');
67
- expect(grids.length).toBe(1);
68
- });
69
- });
70
- describe('grid.setAnimation >', () => {
71
- beforeEach(() => {
72
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
73
- });
74
- afterEach(() => {
75
- document.body.removeChild(document.getElementById('gs-cont'));
76
- });
77
- it('should add class grid-stack-animate to the container. >', () => {
78
- grid = GridStack.init({ animate: true });
79
- expect(grid.el.classList.contains('grid-stack-animate')).toBe(true);
80
- grid.el.classList.remove('grid-stack-animate');
81
- expect(grid.el.classList.contains('grid-stack-animate')).toBe(false);
82
- grid.setAnimation(true);
83
- expect(grid.el.classList.contains('grid-stack-animate')).toBe(true);
84
- });
85
- it('should remove class grid-stack-animate from the container. >', () => {
86
- grid = GridStack.init({ animate: true });
87
- grid.setAnimation(false);
88
- expect(grid.el.classList.contains('grid-stack-animate')).toBe(false);
89
- });
90
- });
91
- describe('grid._setStaticClass >', () => {
92
- beforeEach(() => {
93
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
94
- });
95
- afterEach(() => {
96
- document.body.removeChild(document.getElementById('gs-cont'));
97
- });
98
- it('should add class grid-stack-static to the container. >', () => {
99
- grid = GridStack.init({ staticGrid: true });
100
- expect(grid.el.classList.contains('grid-stack-static')).toBe(true);
101
- grid.setStatic(false);
102
- expect(grid.el.classList.contains('grid-stack-static')).toBe(false);
103
- grid.setStatic(true);
104
- expect(grid.el.classList.contains('grid-stack-static')).toBe(true);
105
- });
106
- it('should remove class grid-stack-static from the container. >', () => {
107
- grid = GridStack.init({ staticGrid: false });
108
- expect(grid.el.classList.contains('grid-stack-static')).toBe(false);
109
- grid.setStatic(true);
110
- expect(grid.el.classList.contains('grid-stack-static')).toBe(true);
111
- });
112
- });
113
- // Note: Pixel-accurate coordinate tests moved to E2E tests
114
- // where real browser layout engines can provide accurate getBoundingClientRect()
115
- // describe('grid.getCellFromPixel >', () => {});
116
- // Note: Exact pixel calculation tests moved to E2E tests
117
- // where real browser layout engines can provide accurate offsetWidth
118
- // describe('grid.cellWidth >', () => {});
119
- describe('grid.cellHeight >', () => {
120
- beforeEach(() => {
121
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
122
- });
123
- afterEach(() => {
124
- document.body.removeChild(document.getElementById('gs-cont'));
125
- });
126
- it('should set and get cellHeight correctly >', () => {
127
- let cellHeight = 80;
128
- let margin = 5;
129
- let options = {
130
- cellHeight,
131
- margin,
132
- column: 12
133
- };
134
- grid = GridStack.init(options);
135
- let rows = parseInt(grid.el.getAttribute('gs-current-row'));
136
- expect(grid.getRow()).toBe(rows);
137
- expect(grid.getCellHeight()).toBe(cellHeight);
138
- // Note: Exact pixel height calculation tests moved to E2E tests
139
- // where real browser layout engines can provide accurate getComputedStyle() values
140
- grid.cellHeight(grid.getCellHeight()); // should be no-op
141
- expect(grid.getCellHeight()).toBe(cellHeight);
142
- cellHeight = 120; // should change
143
- grid.cellHeight(cellHeight);
144
- expect(grid.getCellHeight()).toBe(cellHeight);
145
- cellHeight = 20; // should change
146
- grid.cellHeight(cellHeight);
147
- expect(grid.getCellHeight()).toBe(cellHeight);
148
- });
149
- it('should be square >', () => {
150
- grid = GridStack.init({ cellHeight: 'auto' });
151
- expect(grid.cellWidth()).toBe(grid.getCellHeight());
152
- });
153
- });
154
- describe('grid.column >', () => {
155
- beforeEach(() => {
156
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
157
- });
158
- afterEach(() => {
159
- document.body.removeChild(document.getElementById('gs-cont'));
160
- });
161
- it('should have no changes >', () => {
162
- grid = GridStack.init();
163
- expect(grid.getColumn()).toBe(12);
164
- grid.column(12);
165
- expect(grid.getColumn()).toBe(12);
166
- });
167
- it('should set construct CSS class >', () => {
168
- grid = GridStack.init({ column: 1 });
169
- expect(grid.el.classList.contains('gs-1')).toBe(true);
170
- grid.column(2);
171
- expect(grid.el.classList.contains('gs-1')).toBe(false);
172
- expect(grid.el.classList.contains('gs-2')).toBe(true);
173
- });
174
- it('should set CSS class >', () => {
175
- grid = GridStack.init();
176
- expect(grid.el.classList.contains('grid-stack')).toBe(true);
177
- grid.column(1);
178
- expect(grid.el.classList.contains('gs-1')).toBe(true);
179
- });
180
- it('should SMALL change column number, no relayout >', () => {
181
- let options = {
182
- column: 12
183
- };
184
- grid = GridStack.init(options);
185
- let items = Utils.getElements('.grid-stack-item');
186
- grid.column(9);
187
- expect(grid.getColumn()).toBe(9);
188
- items.forEach(el => expect(el.getAttribute('gs-y')).toBe(null));
189
- grid.column(12);
190
- expect(grid.getColumn()).toBe(12);
191
- items.forEach(el => expect(el.getAttribute('gs-y')).toBe(null));
192
- });
193
- it('no sizing, no moving >', () => {
194
- grid = GridStack.init({ column: 12 });
195
- let items = Utils.getElements('.grid-stack-item');
196
- grid.column(8, 'none');
197
- expect(grid.getColumn()).toBe(8);
198
- items.forEach(el => {
199
- expect(parseInt(el.getAttribute('gs-w'))).toBe(4);
200
- expect(el.getAttribute('gs-y')).toBe(null);
201
- });
202
- });
203
- it('no sizing, but moving down >', () => {
204
- grid = GridStack.init({ column: 12 });
205
- let items = Utils.getElements('.grid-stack-item');
206
- grid.column(7, 'move');
207
- expect(grid.getColumn()).toBe(7);
208
- items.forEach(el => expect(parseInt(el.getAttribute('gs-w'))).toBe(4));
209
- expect(items[0].getAttribute('gs-y')).toBe(null);
210
- expect(parseInt(items[1].getAttribute('gs-y'))).toBe(2);
211
- });
212
- it('should change column number and re-layout items >', () => {
213
- let options = {
214
- column: 12,
215
- float: true
216
- };
217
- grid = GridStack.init(options);
218
- let el1 = document.getElementById('item1');
219
- let el2 = document.getElementById('item2');
220
- // items start at 4x2 and 4x4
221
- expect(el1.getAttribute('gs-x')).toBe(null);
222
- expect(el1.getAttribute('gs-y')).toBe(null);
223
- expect(parseInt(el1.getAttribute('gs-w'))).toBe(4);
224
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
225
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(4);
226
- expect(el2.getAttribute('gs-y')).toBe(null);
227
- expect(parseInt(el2.getAttribute('gs-w'))).toBe(4);
228
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
229
- // 1 column will have item1, item2
230
- grid.column(1);
231
- expect(grid.getColumn()).toBe(1);
232
- expect(el1.getAttribute('gs-x')).toBe(null);
233
- expect(el1.getAttribute('gs-y')).toBe(null);
234
- expect(el1.getAttribute('gs-w')).toBe(null);
235
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
236
- expect(el2.getAttribute('gs-x')).toBe(null);
237
- expect(parseInt(el2.getAttribute('gs-y'))).toBe(2);
238
- expect(el2.getAttribute('gs-w')).toBe(null);
239
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
240
- // add default 1x1 item to the end (1 column)
241
- let el3 = grid.addWidget({ content: 'new' });
242
- expect(el3).not.toBe(null);
243
- expect(el3.getAttribute('gs-x')).toBe(null);
244
- expect(parseInt(el3.getAttribute('gs-y'))).toBe(6);
245
- expect(el3.getAttribute('gs-w')).toBe(null);
246
- expect(el3.getAttribute('gs-h')).toBe(null);
247
- // back to 12 column and initial layout (other than new item3)
248
- grid.column(12);
249
- expect(grid.getColumn()).toBe(12);
250
- expect(el1.getAttribute('gs-x')).toBe(null);
251
- expect(el1.getAttribute('gs-y')).toBe(null);
252
- expect(parseInt(el1.getAttribute('gs-w'))).toBe(4);
253
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
254
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(4);
255
- expect(el2.getAttribute('gs-y')).toBe(null);
256
- expect(parseInt(el2.getAttribute('gs-w'))).toBe(4);
257
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
258
- // TODO: we don't remembers autoPlacement (cleared multiple places)
259
- // expect(parseInt(el3.getAttribute('gs-x'))).toBe(8);
260
- // expect(el3.getAttribute('gs-y')).toBe(null);
261
- expect(el3.getAttribute('gs-x')).toBe(null);
262
- expect(parseInt(el3.getAttribute('gs-y'))).toBe(6);
263
- expect(el3.getAttribute('gs-w')).toBe(null);
264
- expect(el3.getAttribute('gs-h')).toBe(null);
265
- // back to 1 column
266
- grid.column(1);
267
- expect(grid.getColumn()).toBe(1);
268
- expect(el1.getAttribute('gs-x')).toBe(null);
269
- expect(el1.getAttribute('gs-y')).toBe(null);
270
- expect(el1.getAttribute('gs-w')).toBe(null);
271
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
272
- expect(el2.getAttribute('gs-x')).toBe(null);
273
- expect(parseInt(el2.getAttribute('gs-y'))).toBe(2);
274
- expect(el2.getAttribute('gs-w')).toBe(null);
275
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
276
- expect(el3.getAttribute('gs-x')).toBe(null);
277
- expect(parseInt(el3.getAttribute('gs-y'))).toBe(6);
278
- expect(el3.getAttribute('gs-w')).toBe(null);
279
- expect(el3.getAttribute('gs-h')).toBe(null);
280
- // move item2 to beginning to [3][1][2] vertically
281
- grid.update(el3, { x: 0, y: 0 });
282
- expect(el3.getAttribute('gs-x')).toBe(null);
283
- expect(el3.getAttribute('gs-y')).toBe(null);
284
- expect(el3.getAttribute('gs-w')).toBe(null);
285
- expect(el3.getAttribute('gs-h')).toBe(null);
286
- expect(el1.getAttribute('gs-x')).toBe(null);
287
- expect(parseInt(el1.getAttribute('gs-y'))).toBe(1);
288
- expect(el1.getAttribute('gs-w')).toBe(null);
289
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
290
- expect(el2.getAttribute('gs-x')).toBe(null);
291
- expect(parseInt(el2.getAttribute('gs-y'))).toBe(3);
292
- expect(el2.getAttribute('gs-w')).toBe(null);
293
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
294
- // back to 12 column, el3 to be beginning still, but [1][2] to be in 1 columns still but wide 4x2 and 4x still
295
- grid.column(12);
296
- expect(grid.getColumn()).toBe(12);
297
- expect(el3.getAttribute('gs-x')).toBe(null); // 8 TEST WHY
298
- expect(el3.getAttribute('gs-y')).toBe(null);
299
- expect(el3.getAttribute('gs-w')).toBe(null);
300
- expect(el3.getAttribute('gs-h')).toBe(null);
301
- expect(el1.getAttribute('gs-x')).toBe(null);
302
- expect(parseInt(el1.getAttribute('gs-y'))).toBe(1);
303
- expect(parseInt(el1.getAttribute('gs-w'))).toBe(4);
304
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
305
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(4);
306
- expect(parseInt(el2.getAttribute('gs-y'))).toBe(1);
307
- expect(parseInt(el2.getAttribute('gs-w'))).toBe(4);
308
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
309
- // 2 column will have item1, item2, item3 in 1 column still but half the width
310
- grid.column(1); // test convert from small, should use 12 layout still
311
- grid.column(2);
312
- expect(grid.getColumn()).toBe(2);
313
- expect(el3.getAttribute('gs-x')).toBe(null); // 1 TEST WHY
314
- expect(el3.getAttribute('gs-y')).toBe(null);
315
- expect(el3.getAttribute('gs-w')).toBe(null); // 1 as we scaled from 12 columns
316
- expect(el3.getAttribute('gs-h')).toBe(null);
317
- expect(el1.getAttribute('gs-x')).toBe(null);
318
- expect(parseInt(el1.getAttribute('gs-y'))).toBe(1);
319
- expect(el1.getAttribute('gs-w')).toBe(null);
320
- expect(parseInt(el1.getAttribute('gs-h'))).toBe(2);
321
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(1);
322
- expect(parseInt(el2.getAttribute('gs-y'))).toBe(1);
323
- expect(el2.getAttribute('gs-w')).toBe(null);
324
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(4);
325
- });
326
- });
327
- describe('grid.column larger layout >', () => {
328
- beforeEach(() => {
329
- document.body.insertAdjacentHTML('afterbegin', gridstackEmptyHTML);
330
- });
331
- afterEach(() => {
332
- document.body.removeChild(document.getElementById('gs-cont'));
333
- });
334
- it('24 layout in 12 column to 1 back 12 then 24 >', () => {
335
- const children = [{ x: 0, y: 0, w: 12, h: 1, id: 'left' }, { x: 12, y: 0, w: 12, h: 1, id: 'right' }];
336
- children.forEach(c => c.content = c.id);
337
- grid = GridStack.init({ children });
338
- const left = find('left');
339
- const right = find('right');
340
- // side-by-side components 12+12 = 24 columns but only have 12!
341
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 12 }));
342
- expect(right).toEqual(expect.objectContaining({ x: 0, y: 1, w: 12 }));
343
- // Resize to 1 column
344
- grid.column(1);
345
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 1 }));
346
- expect(right).toEqual(expect.objectContaining({ x: 0, y: 1, w: 1 }));
347
- // Resize back to 12 column
348
- grid.column(12);
349
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 12 }));
350
- expect(right).toEqual(expect.objectContaining({ x: 0, y: 1, w: 12 }));
351
- // Resize to 24 column
352
- grid.column(24);
353
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 12 }));
354
- expect(right).toEqual(expect.objectContaining({ x: 12, y: 0, w: 12 }));
355
- });
356
- it('24 column to 12, 1 back 12,24 >', () => {
357
- const children = [{ x: 0, y: 0, w: 12, h: 1, id: 'left' }, { x: 12, y: 0, w: 12, h: 1, id: 'right' }];
358
- children.forEach(c => c.content = c.id);
359
- grid = GridStack.init({ column: 24, children });
360
- const left = find('left');
361
- const right = find('right');
362
- // side-by-side components 12+12 = 24 columns
363
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 12 }));
364
- expect(right).toEqual(expect.objectContaining({ x: 12, y: 0, w: 12 }));
365
- // Resize to 12 column
366
- grid.column(12);
367
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 6 }));
368
- expect(right).toEqual(expect.objectContaining({ x: 6, y: 0, w: 6 }));
369
- // Resize to 1 column
370
- grid.column(1);
371
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 1 }));
372
- expect(right).toEqual(expect.objectContaining({ x: 0, y: 1, w: 1 }));
373
- // back to 12 column
374
- grid.column(12);
375
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 6 }));
376
- expect(right).toEqual(expect.objectContaining({ x: 6, y: 0, w: 6 }));
377
- // back to 24 column
378
- grid.column(24);
379
- expect(left).toEqual(expect.objectContaining({ x: 0, y: 0, w: 12 }));
380
- expect(right).toEqual(expect.objectContaining({ x: 12, y: 0, w: 12 }));
381
- });
382
- });
383
- // describe('oneColumnModeDomSort >', () => {
384
- // beforeEach(() => {
385
- // document.body.insertAdjacentHTML('afterbegin', gridstackEmptyHTML);
386
- // });
387
- // afterEach(() => {
388
- // document.body.removeChild(document.getElementById('gs-cont'));
389
- // });
390
- // it('should support default going to 1 column >', () => {
391
- // let options = {
392
- // column: 12,
393
- // float: true
394
- // };
395
- // grid = GridStack.init(options);
396
- // grid.batchUpdate();
397
- // grid.batchUpdate();
398
- // let el1 = grid.addWidget({w:1, h:1});
399
- // let el2 = grid.addWidget({x:2, y:0, w:2, h:1});
400
- // let el3 = grid.addWidget({x:1, y:0, w:1, h:2});
401
- // grid.batchUpdate(false);
402
- // grid.batchUpdate(false);
403
- // // items are item1[1x1], item3[1x1], item2[2x1]
404
- // expect(el1.getAttribute('gs-x')).toBe(null);
405
- // expect(el1.getAttribute('gs-y')).toBe(null);
406
- // expect(el1.getAttribute('gs-w')).toBe(null);
407
- // expect(el1.getAttribute('gs-h')).toBe(null);
408
- // expect(parseInt(el3.getAttribute('gs-x'))).toBe(1);
409
- // expect(el3.getAttribute('gs-y')).toBe(null);
410
- // expect(el3.getAttribute('gs-w')).toBe(null);
411
- // expect(parseInt(el3.getAttribute('gs-h'))).toBe(2);
412
- // expect(parseInt(el2.getAttribute('gs-x'))).toBe(2);
413
- // expect(el2.getAttribute('gs-y')).toBe(null);
414
- // expect(parseInt(el2.getAttribute('gs-w'))).toBe(2);
415
- // expect(el2.getAttribute('gs-h')).toBe(null);
416
- // // items are item1[1x1], item3[1x2], item2[1x1] in 1 column
417
- // grid.column(1);
418
- // expect(el1.getAttribute('gs-x')).toBe(null);
419
- // expect(el1.getAttribute('gs-y')).toBe(null);
420
- // expect(el1.getAttribute('gs-w')).toBe(null);
421
- // expect(el1.getAttribute('gs-h')).toBe(null);
422
- // expect(el3.getAttribute('gs-x')).toBe(null);
423
- // expect(parseInt(el3.getAttribute('gs-y'))).toBe(1);
424
- // expect(el3.getAttribute('gs-w')).toBe(null);
425
- // expect(parseInt(el3.getAttribute('gs-h'))).toBe(2);
426
- // expect(el2.getAttribute('gs-x')).toBe(null);
427
- // expect(parseInt(el2.getAttribute('gs-y'))).toBe(3);
428
- // expect(el2.getAttribute('gs-w')).toBe(null);
429
- // expect(el2.getAttribute('gs-h')).toBe(null);
430
- // });
431
- // it('should support oneColumnModeDomSort ON going to 1 column >', () => {
432
- // let options = {
433
- // column: 12,
434
- // oneColumnModeDomSort: true,
435
- // float: true
436
- // };
437
- // grid = GridStack.init(options);
438
- // let el1 = grid.addWidget({w:1, h:1});
439
- // let el2 = grid.addWidget({x:2, y:0, w:2, h:1});
440
- // let el3 = grid.addWidget({x:1, y:0, w:1, h:2});
441
- // // items are item1[1x1], item3[1x1], item2[2x1]
442
- // expect(el1.getAttribute('gs-x')).toBe(null);
443
- // expect(el1.getAttribute('gs-y')).toBe(null);
444
- // expect(el1.getAttribute('gs-w')).toBe(null);
445
- // expect(el1.getAttribute('gs-h')).toBe(null);
446
- // expect(parseInt(el3.getAttribute('gs-x'))).toBe(1);
447
- // expect(el3.getAttribute('gs-y')).toBe(null);
448
- // expect(el3.getAttribute('gs-w')).toBe(null);
449
- // expect(parseInt(el3.getAttribute('gs-h'))).toBe(2);
450
- // expect(parseInt(el2.getAttribute('gs-x'))).toBe(2);
451
- // expect(el2.getAttribute('gs-y')).toBe(null);
452
- // expect(parseInt(el2.getAttribute('gs-w'))).toBe(2);
453
- // expect(el2.getAttribute('gs-h')).toBe(null);
454
- // // items are item1[1x1], item2[1x1], item3[1x2] in 1 column dom ordered
455
- // grid.column(1);
456
- // expect(el1.getAttribute('gs-x')).toBe(null);
457
- // expect(el1.getAttribute('gs-y')).toBe(null);
458
- // expect(el1.getAttribute('gs-w')).toBe(null);
459
- // expect(el1.getAttribute('gs-h')).toBe(null);
460
- // expect(el2.getAttribute('gs-x')).toBe(null);
461
- // expect(parseInt(el2.getAttribute('gs-y'))).toBe(1);
462
- // expect(el2.getAttribute('gs-w')).toBe(null);
463
- // expect(el2.getAttribute('gs-h')).toBe(null);
464
- // expect(el3.getAttribute('gs-x')).toBe(null);
465
- // expect(parseInt(el3.getAttribute('gs-y'))).toBe(2);
466
- // expect(el3.getAttribute('gs-w')).toBe(null);
467
- // expect(parseInt(el3.getAttribute('gs-h'))).toBe(2);
468
- // });
469
- // });
470
- // describe('disableOneColumnMode >', () => {
471
- // beforeEach(() => {
472
- // document.body.insertAdjacentHTML('afterbegin', gridstackSmallHTML); // smaller default to 1 column
473
- // });
474
- // afterEach(() => {
475
- // document.body.removeChild(document.getElementById('gs-cont'));
476
- // });
477
- // it('should go to 1 column >', () => {
478
- // grid = GridStack.init();
479
- // expect(grid.getColumn()).toBe(1);
480
- // });
481
- // it('should go to 1 column with large minW >', () => {
482
- // grid = GridStack.init({oneColumnSize: 1000});
483
- // expect(grid.getColumn()).toBe(1);
484
- // });
485
- // it('should stay at 12 with minW >', () => {
486
- // grid = GridStack.init({oneColumnSize: 300});
487
- // expect(grid.getColumn()).toBe(12);
488
- // });
489
- // it('should stay at 12 column >', () => {
490
- // grid = GridStack.init({disableOneColumnMode: true});
491
- // expect(grid.getColumn()).toBe(12);
492
- // });
493
- // });
494
- describe('grid.minRow >', () => {
495
- beforeEach(() => {
496
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
497
- });
498
- afterEach(() => {
499
- document.body.removeChild(document.getElementById('gs-cont'));
500
- });
501
- it('should default to row 0 when empty >', () => {
502
- let options = {};
503
- grid = GridStack.init(options);
504
- expect(grid.getRow()).toBe(4);
505
- expect(grid.opts.minRow).toBe(0);
506
- expect(grid.opts.maxRow).toBe(0);
507
- grid.removeAll();
508
- expect(grid.getRow()).toBe(0);
509
- });
510
- it('should default to row 2 when empty >', () => {
511
- let options = { minRow: 2 };
512
- grid = GridStack.init(options);
513
- expect(grid.getRow()).toBe(4);
514
- expect(grid.opts.minRow).toBe(2);
515
- expect(grid.opts.maxRow).toBe(0);
516
- grid.removeAll();
517
- expect(grid.engine.getRow()).toBe(0);
518
- expect(grid.getRow()).toBe(2);
519
- });
520
- it('should set min = max = 3 rows >', () => {
521
- let options = { row: 3 };
522
- grid = GridStack.init(options);
523
- expect(grid.getRow()).toBe(3); // shrink elements to fit maxRow!
524
- expect(grid.opts.minRow).toBe(3);
525
- expect(grid.opts.maxRow).toBe(3);
526
- grid.removeAll();
527
- expect(grid.engine.getRow()).toBe(0);
528
- expect(grid.getRow()).toBe(3);
529
- });
530
- it('willItFit() >', () => {
531
- // default 4x2 and 4x4 so anything pushing more than 1 will fail
532
- grid = GridStack.init({ maxRow: 5 });
533
- expect(grid.willItFit({ x: 0, y: 0, w: 1, h: 1 })).toBe(true);
534
- expect(grid.willItFit({ x: 0, y: 0, w: 1, h: 3 })).toBe(true);
535
- expect(grid.willItFit({ x: 0, y: 0, w: 1, h: 4 })).toBe(false);
536
- expect(grid.willItFit({ x: 0, y: 0, w: 12, h: 1 })).toBe(true);
537
- expect(grid.willItFit({ x: 0, y: 0, w: 12, h: 2 })).toBe(false);
538
- });
539
- it('willItFit() not modifying node #1687 >', () => {
540
- // default 4x2 and 4x4 so anything pushing more than 1 will fail
541
- grid = GridStack.init({ maxRow: 5 });
542
- let node = { x: 0, y: 0, w: 1, h: 1, _id: 1, _temporaryRemoved: true };
543
- expect(grid.willItFit(node)).toBe(true);
544
- expect(node._temporaryRemoved).toBe(true);
545
- expect(node._id).toBe(1);
546
- });
547
- });
548
- describe('grid attributes >', () => {
549
- afterEach(() => {
550
- document.body.removeChild(document.getElementById('gs-cont'));
551
- });
552
- it('should have row attr >', () => {
553
- let HTML = '<div style="w: 800px; h: 600px" id="gs-cont">' +
554
- ' <div class="grid-stack" gs-row="4" gs-current-height="1"></div>' + // old attr current-height
555
- '</div>';
556
- document.body.insertAdjacentHTML('afterbegin', HTML);
557
- grid = GridStack.init();
558
- expect(grid.getRow()).toBe(4);
559
- expect(grid.opts.minRow).toBe(4);
560
- expect(grid.opts.maxRow).toBe(4);
561
- grid.addWidget({ h: 6 });
562
- expect(grid.engine.getRow()).toBe(4);
563
- expect(grid.getRow()).toBe(4);
564
- });
565
- });
566
- describe('grid.min/max width/height >', () => {
567
- beforeEach(() => {
568
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
569
- });
570
- afterEach(() => {
571
- document.body.removeChild(document.getElementById('gs-cont'));
572
- });
573
- it('should set gs-min-w to 2. >', () => {
574
- grid = GridStack.init();
575
- let items = Utils.getElements('.grid-stack-item');
576
- items.forEach(el => grid.update(el, { minW: 2, maxW: 3, minH: 4, maxH: 5 }));
577
- items.forEach(el => {
578
- expect(el.gridstackNode.minW).toBe(2);
579
- expect(el.gridstackNode.maxW).toBe(3);
580
- expect(el.gridstackNode.minH).toBe(4);
581
- expect(el.gridstackNode.maxH).toBe(5);
582
- expect(el.getAttribute('gs-min-w')).toBe(null);
583
- expect(el.getAttribute('gs-max-w')).toBe(null);
584
- expect(el.getAttribute('gs-min-h')).toBe(null);
585
- expect(el.getAttribute('gs-max-h')).toBe(null);
586
- });
587
- // remove all constrain
588
- grid.update('grid-stack-item', { minW: 0, maxW: null, minH: undefined, maxH: 0 });
589
- items.forEach(el => {
590
- expect(el.gridstackNode.minW).toBe(undefined);
591
- expect(el.gridstackNode.maxW).toBe(undefined);
592
- expect(el.gridstackNode.minH).toBe(undefined);
593
- expect(el.gridstackNode.maxH).toBe(undefined);
594
- expect(el.getAttribute('gs-min-w')).toBe(null);
595
- expect(el.getAttribute('gs-max-w')).toBe(null);
596
- expect(el.getAttribute('gs-min-h')).toBe(null);
597
- expect(el.getAttribute('gs-max-h')).toBe(null);
598
- });
599
- });
600
- });
601
- describe('grid.isAreaEmpty >', () => {
602
- beforeEach(() => {
603
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
604
- });
605
- afterEach(() => {
606
- document.body.removeChild(document.getElementById('gs-cont'));
607
- });
608
- it('should set return false. >', () => {
609
- let options = {
610
- cellHeight: 80,
611
- margin: 5
612
- };
613
- grid = GridStack.init(options);
614
- let shouldBeFalse = grid.isAreaEmpty(1, 1, 1, 1);
615
- expect(shouldBeFalse).toBe(false);
616
- });
617
- it('should set return true. >', () => {
618
- let options = {
619
- cellHeight: 80,
620
- margin: 5
621
- };
622
- grid = GridStack.init(options);
623
- let shouldBeTrue = grid.isAreaEmpty(5, 5, 1, 1);
624
- expect(shouldBeTrue).toBe(true);
625
- });
626
- });
627
- describe('grid.removeAll >', () => {
628
- beforeEach(() => {
629
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
630
- });
631
- afterEach(() => {
632
- document.body.removeChild(document.getElementById('gs-cont'));
633
- });
634
- it('should remove all children by default >', () => {
635
- grid = GridStack.init();
636
- grid.removeAll();
637
- expect(grid.engine.nodes).toEqual([]);
638
- expect(document.getElementById('item1')).toBe(null);
639
- });
640
- it('should remove all children >', () => {
641
- grid = GridStack.init();
642
- grid.removeAll(true);
643
- expect(grid.engine.nodes).toEqual([]);
644
- expect(document.getElementById('item1')).toBe(null);
645
- });
646
- it('should remove gridstack part, leave DOM behind >', () => {
647
- grid = GridStack.init();
648
- grid.removeAll(false);
649
- expect(grid.engine.nodes).toEqual([]);
650
- expect(document.getElementById('item1')).not.toBe(null);
651
- });
652
- });
653
- describe('grid.removeWidget >', () => {
654
- beforeEach(() => {
655
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
656
- });
657
- afterEach(() => {
658
- document.body.removeChild(document.getElementById('gs-cont'));
659
- });
660
- it('should remove first item (default), then second (false) >', () => {
661
- grid = GridStack.init();
662
- expect(grid.engine.nodes.length).toEqual(2);
663
- let el1 = document.getElementById('item1');
664
- expect(el1).not.toBe(null);
665
- grid.removeWidget(el1);
666
- expect(grid.engine.nodes.length).toEqual(1);
667
- expect(document.getElementById('item1')).toBe(null);
668
- expect(document.getElementById('item2')).not.toBe(null);
669
- let el2 = document.getElementById('item2');
670
- grid.removeWidget(el2, false);
671
- expect(grid.engine.nodes.length).toEqual(0);
672
- expect(document.getElementById('item2')).not.toBe(null);
673
- });
674
- });
675
- describe('grid method _packNodes with float >', () => {
676
- beforeEach(() => {
677
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
678
- });
679
- afterEach(() => {
680
- document.body.removeChild(document.getElementById('gs-cont'));
681
- });
682
- it('should allow same x, y coordinates for widgets. >', () => {
683
- let options = {
684
- cellHeight: 80,
685
- margin: 5,
686
- float: true
687
- };
688
- grid = GridStack.init(options);
689
- let items = Utils.getElements('.grid-stack-item');
690
- items.forEach(oldEl => {
691
- let el = grid.makeWidget(oldEl);
692
- expect(oldEl.getAttribute('gs-x')).toBe(el.getAttribute('gs-x'));
693
- expect(oldEl.getAttribute('gs-y')).toBe(el.getAttribute('gs-y'));
694
- });
695
- });
696
- it('should not allow same x, y coordinates for widgets. >', () => {
697
- let options = {
698
- cellHeight: 80,
699
- margin: 5
700
- };
701
- grid = GridStack.init(options);
702
- let items = Utils.getElements('.grid-stack-item');
703
- items.forEach(oldEl => {
704
- let el = oldEl.cloneNode(true);
705
- el = grid.makeWidget(el);
706
- expect(el.gridstackNode?.x).not.toBe(oldEl.gridstackNode?.x);
707
- });
708
- });
709
- });
710
- describe('grid method addWidget with all parameters >', () => {
711
- beforeEach(() => {
712
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
713
- });
714
- afterEach(() => {
715
- document.body.removeChild(document.getElementById('gs-cont'));
716
- });
717
- it('should keep all widget options the same (autoPosition off >', () => {
718
- grid = GridStack.init({ float: true });
719
- ;
720
- let w = grid.addWidget({ x: 6, y: 7, w: 2, h: 3, autoPosition: false,
721
- minW: 1, maxW: 4, minH: 2, maxH: 5, id: 'coolWidget' });
722
- expect(parseInt(w.getAttribute('gs-x'))).toBe(6);
723
- expect(parseInt(w.getAttribute('gs-y'))).toBe(7);
724
- expect(parseInt(w.getAttribute('gs-w'))).toBe(2);
725
- expect(parseInt(w.getAttribute('gs-h'))).toBe(3);
726
- expect(w.getAttribute('gs-auto-position')).toBe(null);
727
- expect(w.getAttribute('gs-id')).toBe('coolWidget');
728
- // should move widget to top with float=false
729
- expect(grid.getFloat()).toBe(true);
730
- grid.float(false);
731
- expect(grid.getFloat()).toBe(false);
732
- expect(parseInt(w.getAttribute('gs-x'))).toBe(6);
733
- expect(parseInt(w.getAttribute('gs-y'))).toBe(4); // <--- from 7 to 4 below second original widget
734
- expect(parseInt(w.getAttribute('gs-w'))).toBe(2);
735
- expect(parseInt(w.getAttribute('gs-h'))).toBe(3);
736
- expect(w.getAttribute('gs-auto-position')).toBe(null);
737
- expect(w.getAttribute('gs-id')).toBe('coolWidget');
738
- // should not move again (no-op)
739
- grid.float(true);
740
- expect(grid.getFloat()).toBe(true);
741
- expect(parseInt(w.getAttribute('gs-x'))).toBe(6);
742
- expect(parseInt(w.getAttribute('gs-y'))).toBe(4);
743
- expect(parseInt(w.getAttribute('gs-w'))).toBe(2);
744
- expect(parseInt(w.getAttribute('gs-h'))).toBe(3);
745
- expect(w.getAttribute('gs-auto-position')).toBe(null);
746
- expect(w.getAttribute('gs-id')).toBe('coolWidget');
747
- });
748
- });
749
- describe('grid method addWidget with autoPosition true >', () => {
750
- beforeEach(() => {
751
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
752
- });
753
- afterEach(() => {
754
- document.body.removeChild(document.getElementById('gs-cont'));
755
- });
756
- it('should change x, y coordinates for widgets. >', () => {
757
- grid = GridStack.init({ float: true });
758
- let w = grid.addWidget({ x: 9, y: 7, w: 2, h: 3, autoPosition: true });
759
- expect(parseInt(w.getAttribute('gs-x'), 10)).not.toBe(9);
760
- expect(parseInt(w.getAttribute('gs-y'), 10)).not.toBe(7);
761
- });
762
- });
763
- describe('grid method addWidget with widget options >', () => {
764
- beforeEach(() => {
765
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
766
- });
767
- afterEach(() => {
768
- document.body.removeChild(document.getElementById('gs-cont'));
769
- });
770
- it('should autoPosition (missing X,Y) >', () => {
771
- grid = GridStack.init();
772
- let w = grid.addWidget({ h: 2, id: 'optionWidget' });
773
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
774
- expect(w.getAttribute('gs-y')).toBe(null);
775
- expect(w.getAttribute('gs-w')).toBe(null);
776
- expect(parseInt(w.getAttribute('gs-h'))).toBe(2);
777
- // expect(w.getAttribute('gs-auto-position')).toBe('true');
778
- expect(w.getAttribute('gs-id')).toBe('optionWidget');
779
- });
780
- it('should autoPosition (missing X) >', () => {
781
- grid = GridStack.init();
782
- let w = grid.addWidget({ y: 9, h: 2, id: 'optionWidget' });
783
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
784
- expect(w.getAttribute('gs-y')).toBe(null);
785
- expect(w.getAttribute('gs-w')).toBe(null);
786
- expect(parseInt(w.getAttribute('gs-h'))).toBe(2);
787
- // expect(w.getAttribute('gs-auto-position')).toBe('true');
788
- expect(w.getAttribute('gs-id')).toBe('optionWidget');
789
- });
790
- it('should autoPosition (missing Y) >', () => {
791
- grid = GridStack.init();
792
- let w = grid.addWidget({ x: 9, h: 2, id: 'optionWidget' });
793
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
794
- expect(w.getAttribute('gs-y')).toBe(null);
795
- expect(w.getAttribute('gs-w')).toBe(null);
796
- expect(parseInt(w.getAttribute('gs-h'))).toBe(2);
797
- // expect(w.getAttribute('gs-auto-position')).toBe('true');
798
- expect(w.getAttribute('gs-id')).toBe('optionWidget');
799
- });
800
- it('should autoPosition (correct X, missing Y) >', () => {
801
- grid = GridStack.init();
802
- let w = grid.addWidget({ x: 8, h: 2, id: 'optionWidget' });
803
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
804
- expect(w.getAttribute('gs-y')).toBe(null);
805
- expect(w.getAttribute('gs-w')).toBe(null);
806
- expect(parseInt(w.getAttribute('gs-h'))).toBe(2);
807
- // expect(w.getAttribute('gs-auto-position')).toBe('true');
808
- expect(w.getAttribute('gs-id')).toBe('optionWidget');
809
- });
810
- it('should autoPosition (empty options) >', () => {
811
- grid = GridStack.init();
812
- let w = grid.addWidget({});
813
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
814
- expect(w.getAttribute('gs-y')).toBe(null);
815
- expect(w.getAttribute('gs-w')).toBe(null);
816
- expect(w.getAttribute('gs-h')).toBe(null);
817
- // expect(w.getAttribute('gs-auto-position')).toBe('true');
818
- });
819
- });
820
- describe('addWidget() >', () => {
821
- beforeEach(() => {
822
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
823
- });
824
- afterEach(() => {
825
- document.body.removeChild(document.getElementById('gs-cont'));
826
- });
827
- it('bad string options should use default >', () => {
828
- grid = GridStack.init();
829
- let w = grid.addWidget({ x: 'foo', y: null, w: 'bar', h: '' });
830
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
831
- expect(w.getAttribute('gs-y')).toBe(null);
832
- expect(w.getAttribute('gs-w')).toBe(null);
833
- expect(w.getAttribute('gs-h')).toBe(null);
834
- });
835
- it('makeWidget attr should be retained >', () => {
836
- grid = GridStack.init({ float: true });
837
- const d = document.createElement('div');
838
- d.innerHTML = '<div class="grid-stack-item" gs-w="3" gs-max-w="4" gs-id="gsfoo" id="foo"><div class="grid-stack-item-content">foo content</div></div>';
839
- grid.el.appendChild(d.firstChild);
840
- let w = grid.makeWidget('foo');
841
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
842
- expect(w.getAttribute('gs-y')).toBe(null);
843
- expect(parseInt(w.getAttribute('gs-w'))).toBe(3);
844
- expect(w.gridstackNode.maxW).toBe(4);
845
- expect(w.getAttribute('gs-h')).toBe(null);
846
- expect(w.getAttribute('gs-id')).toBe('gsfoo');
847
- });
848
- it('makeWidget width option override >', () => {
849
- grid = GridStack.init({ float: true });
850
- const d = document.createElement('div');
851
- d.innerHTML = '<div class="grid-stack-item" gs-w="3" gs-max-w="4" gs-id="gsfoo" id="foo"><div class="grid-stack-item-content">foo content</div></div>';
852
- grid.el.appendChild(d.firstChild);
853
- let w = grid.makeWidget('foo', { x: null, y: null, w: 2 });
854
- expect(parseInt(w.getAttribute('gs-x'))).toBe(8);
855
- expect(w.getAttribute('gs-y')).toBe(null);
856
- expect(parseInt(w.getAttribute('gs-w'))).toBe(2);
857
- expect(w.getAttribute('gs-h')).toBe(null);
858
- });
859
- });
860
- describe('makeWidget() >', () => {
861
- beforeEach(() => {
862
- document.body.insertAdjacentHTML('afterbegin', gridstackEmptyHTML);
863
- });
864
- afterEach(() => {
865
- document.body.removeChild(document.getElementById('gs-cont'));
866
- });
867
- it('passing element >', () => {
868
- grid = GridStack.init();
869
- let doc = document.implementation.createHTMLDocument();
870
- doc.body.innerHTML = '<div><div class="grid-stack-item-content"></div></div>';
871
- let el = doc.body.children[0];
872
- grid.el.appendChild(el);
873
- let w = grid.makeWidget(el);
874
- expect(w.getAttribute('gs-x')).toBe(null);
875
- });
876
- it('passing element float=true >', () => {
877
- grid = GridStack.init({ float: true });
878
- let doc = document.implementation.createHTMLDocument();
879
- doc.body.innerHTML = '<div><div class="grid-stack-item-content"></div></div>';
880
- let el = doc.body.children[0];
881
- grid.el.appendChild(el);
882
- let w = grid.makeWidget(el);
883
- expect(w.getAttribute('gs-x')).toBe(null);
884
- });
885
- it('passing class >', () => {
886
- grid = GridStack.init();
887
- let doc = document.implementation.createHTMLDocument();
888
- doc.body.innerHTML = '<div class="item"><div class="grid-stack-item-content"></div></div>';
889
- let el = doc.body.children[0];
890
- grid.el.appendChild(el);
891
- let w = grid.makeWidget('.item');
892
- expect(w.getAttribute('gs-x')).toBe(null);
893
- });
894
- it('passing class no dot >', () => {
895
- grid = GridStack.init();
896
- let doc = document.implementation.createHTMLDocument();
897
- doc.body.innerHTML = '<div class="item"><div class="grid-stack-item-content"></div></div>';
898
- let el = doc.body.children[0];
899
- grid.el.appendChild(el);
900
- let w = grid.makeWidget('item');
901
- expect(w.getAttribute('gs-x')).toBe(null);
902
- });
903
- it('passing id >', () => {
904
- grid = GridStack.init();
905
- let doc = document.implementation.createHTMLDocument();
906
- doc.body.innerHTML = '<div id="item"><div class="grid-stack-item-content"></div></div>';
907
- let el = doc.body.children[0];
908
- grid.el.appendChild(el);
909
- let w = grid.makeWidget('#item');
910
- expect(w.getAttribute('gs-x')).toBe(null);
911
- });
912
- it('passing id no # >', () => {
913
- grid = GridStack.init();
914
- let doc = document.implementation.createHTMLDocument();
915
- doc.body.innerHTML = '<div id="item"><div class="grid-stack-item-content"></div></div>';
916
- let el = doc.body.children[0];
917
- grid.el.appendChild(el);
918
- let w = grid.makeWidget('item');
919
- expect(w.getAttribute('gs-x')).toBe(null);
920
- });
921
- it('passing id as number >', () => {
922
- grid = GridStack.init();
923
- let doc = document.implementation.createHTMLDocument();
924
- doc.body.innerHTML = '<div id="1"><div class="grid-stack-item-content"></div></div>';
925
- let el = doc.body.children[0];
926
- grid.el.appendChild(el);
927
- let w = grid.makeWidget('1');
928
- expect(w.getAttribute('gs-x')).toBe(null);
929
- });
930
- });
931
- describe('method getFloat() >', () => {
932
- beforeEach(() => {
933
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
934
- });
935
- afterEach(() => {
936
- document.body.removeChild(document.getElementById('gs-cont'));
937
- });
938
- it('should match true/false only >', () => {
939
- grid = GridStack.init({ float: true });
940
- expect(grid.getFloat()).toBe(true);
941
- grid.float(0);
942
- expect(grid.getFloat()).toBe(false);
943
- grid.float(null);
944
- expect(grid.getFloat()).toBe(false);
945
- grid.float(undefined);
946
- expect(grid.getFloat()).toBe(false);
947
- grid.float(false);
948
- expect(grid.getFloat()).toBe(false);
949
- });
950
- });
951
- describe('grid.destroy >', () => {
952
- beforeEach(() => {
953
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
954
- });
955
- afterEach(() => {
956
- document.getElementById('gs-cont').remove();
957
- });
958
- it('should cleanup gridstack >', () => {
959
- let options = {
960
- cellHeight: 80,
961
- margin: 5
962
- };
963
- grid = GridStack.init(options);
964
- let gridEl = grid.el;
965
- grid.destroy();
966
- expect(gridEl.parentElement).toBe(null);
967
- expect(grid.el).toBe(undefined);
968
- expect(grid.engine).toBe(undefined);
969
- });
970
- it('should cleanup gridstack but leave elements >', () => {
971
- let options = {
972
- cellHeight: 80,
973
- margin: 5
974
- };
975
- grid = GridStack.init(options);
976
- let gridEl = grid.el;
977
- grid.destroy(false);
978
- expect(gridEl.parentElement).not.toBe(null);
979
- expect(Utils.getElements('.grid-stack-item').length).toBe(2);
980
- expect(grid.el).toBe(undefined);
981
- expect(grid.engine).toBe(undefined);
982
- grid.destroy(); // sanity check for call twice!
983
- });
984
- });
985
- describe('grid.resize >', () => {
986
- beforeEach(() => {
987
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
988
- });
989
- afterEach(() => {
990
- document.body.removeChild(document.getElementById('gs-cont'));
991
- });
992
- it('should resize widget >', () => {
993
- let options = {
994
- cellHeight: 80,
995
- margin: 5
996
- };
997
- grid = GridStack.init(options);
998
- let items = Utils.getElements('.grid-stack-item');
999
- grid.update(items[0], { w: 5, h: 5 });
1000
- expect(parseInt(items[0].getAttribute('gs-w'))).toBe(5);
1001
- expect(parseInt(items[0].getAttribute('gs-h'))).toBe(5);
1002
- });
1003
- });
1004
- describe('grid.move >', () => {
1005
- beforeEach(() => {
1006
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1007
- });
1008
- afterEach(() => {
1009
- document.body.removeChild(document.getElementById('gs-cont'));
1010
- });
1011
- it('should move widget >', () => {
1012
- let options = {
1013
- cellHeight: 80,
1014
- margin: 5,
1015
- float: true
1016
- };
1017
- grid = GridStack.init(options);
1018
- let items = Utils.getElements('.grid-stack-item');
1019
- grid.update(items[0], { x: 5, y: 5 });
1020
- expect(parseInt(items[0].getAttribute('gs-x'))).toBe(5);
1021
- expect(parseInt(items[0].getAttribute('gs-y'))).toBe(5);
1022
- });
1023
- });
1024
- describe('grid.update >', () => {
1025
- beforeEach(() => {
1026
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1027
- });
1028
- afterEach(() => {
1029
- document.body.removeChild(document.getElementById('gs-cont'));
1030
- });
1031
- it('should move and resize widget >', () => {
1032
- grid = GridStack.init({ float: true });
1033
- let el = Utils.getElements('.grid-stack-item')[1];
1034
- expect(parseInt(el.getAttribute('gs-w'))).toBe(4);
1035
- grid.update(el, { x: 5, y: 4, h: 2 });
1036
- expect(parseInt(el.getAttribute('gs-x'))).toBe(5);
1037
- expect(parseInt(el.getAttribute('gs-y'))).toBe(4);
1038
- expect(parseInt(el.getAttribute('gs-w'))).toBe(4);
1039
- expect(parseInt(el.getAttribute('gs-h'))).toBe(2);
1040
- });
1041
- it('should change noMove >', () => {
1042
- grid = GridStack.init({ float: true });
1043
- let items = Utils.getElements('.grid-stack-item');
1044
- let el = items[1];
1045
- let dd = GridStack.getDD();
1046
- grid.update(el, { noMove: true, noResize: false });
1047
- expect(el.getAttribute('gs-no-move')).toBe('true');
1048
- expect(el.getAttribute('gs-no-resize')).toBe(null); // false is no-op
1049
- expect(dd.isResizable(el)).toBe(true);
1050
- expect(dd.isDraggable(el)).toBe(false);
1051
- expect(dd.isResizable(items[0])).toBe(true);
1052
- expect(dd.isDraggable(items[0])).toBe(true);
1053
- expect(parseInt(el.getAttribute('gs-x'))).toBe(4);
1054
- expect(el.getAttribute('gs-y')).toBe(null);
1055
- expect(parseInt(el.getAttribute('gs-w'))).toBe(4);
1056
- expect(parseInt(el.getAttribute('gs-h'))).toBe(4);
1057
- });
1058
- it('should change content and id, and move >', () => {
1059
- grid = GridStack.init({ float: true });
1060
- let el = findEl('gsItem2');
1061
- let sub = el.querySelector('.grid-stack-item-content');
1062
- grid.update(el, { id: 'newID', y: 1, content: 'new content' });
1063
- expect(el.gridstackNode.id).toBe('newID');
1064
- expect(el.getAttribute('gs-id')).toBe('newID');
1065
- expect(sub.innerHTML).toBe('new content');
1066
- expect(parseInt(el.getAttribute('gs-x'))).toBe(4);
1067
- expect(parseInt(el.getAttribute('gs-y'))).toBe(1);
1068
- expect(parseInt(el.getAttribute('gs-w'))).toBe(4);
1069
- expect(parseInt(el.getAttribute('gs-h'))).toBe(4);
1070
- });
1071
- it('should change max and constrain a wanted resize >', () => {
1072
- grid = GridStack.init({ float: true });
1073
- let el = findEl('gsItem2');
1074
- expect(el.getAttribute('gs-max-w')).toBe(null);
1075
- grid.update(el, { maxW: 2, w: 5 });
1076
- expect(parseInt(el.getAttribute('gs-x'))).toBe(4);
1077
- expect(el.getAttribute('gs-y')).toBe(null);
1078
- expect(parseInt(el.getAttribute('gs-w'))).toBe(2);
1079
- expect(parseInt(el.getAttribute('gs-h'))).toBe(4);
1080
- expect(el.gridstackNode.maxW).toBe(2);
1081
- });
1082
- it('should change max and constrain existing >', () => {
1083
- grid = GridStack.init({ float: true });
1084
- let el = findEl('gsItem2');
1085
- expect(el.getAttribute('gs-max-w')).toBe(null);
1086
- grid.update(el, { maxW: 2 });
1087
- expect(parseInt(el.getAttribute('gs-x'))).toBe(4);
1088
- expect(el.getAttribute('gs-y')).toBe(null);
1089
- expect(parseInt(el.getAttribute('gs-w'))).toBe(2);
1090
- expect(parseInt(el.getAttribute('gs-h'))).toBe(4);
1091
- expect(el.gridstackNode.maxW).toBe(2);
1092
- });
1093
- it('should change all max and move, no inf loop! >', () => {
1094
- grid = GridStack.init({ float: true });
1095
- let items = Utils.getElements('.grid-stack-item');
1096
- items.forEach(item => {
1097
- expect(item.getAttribute('gs-max-w')).toBe(null);
1098
- expect(item.getAttribute('gs-max-h')).toBe(null);
1099
- });
1100
- grid.update('.grid-stack-item', { maxW: 2, maxH: 2 });
1101
- expect(items[0].getAttribute('gs-x')).toBe(null);
1102
- expect(parseInt(items[1].getAttribute('gs-x'))).toBe(4);
1103
- items.forEach((item) => {
1104
- expect(item.getAttribute('gs-y')).toBe(null);
1105
- expect(parseInt(item.getAttribute('gs-h'))).toBe(2);
1106
- expect(parseInt(item.getAttribute('gs-w'))).toBe(2);
1107
- expect(item.gridstackNode.maxW).toBe(2);
1108
- expect(item.gridstackNode.maxH).toBe(2);
1109
- });
1110
- });
1111
- });
1112
- describe('grid.margin >', () => {
1113
- beforeEach(() => {
1114
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1115
- });
1116
- afterEach(() => {
1117
- document.body.removeChild(document.getElementById('gs-cont'));
1118
- });
1119
- it('should return margin >', () => {
1120
- let options = {
1121
- cellHeight: 80,
1122
- margin: 12
1123
- };
1124
- grid = GridStack.init(options);
1125
- expect(grid.getMargin()).toBe(12);
1126
- });
1127
- it('should return update margin >', () => {
1128
- let options = {
1129
- cellHeight: 80,
1130
- margin: 5
1131
- };
1132
- grid = GridStack.init(options);
1133
- grid.margin('11rem');
1134
- expect(grid.getMargin()).toBe(11);
1135
- });
1136
- it('should change unit >', () => {
1137
- let options = {
1138
- cellHeight: 80,
1139
- margin: 10,
1140
- };
1141
- grid = GridStack.init(options);
1142
- expect(grid.getMargin()).toBe(10);
1143
- grid.margin('10rem');
1144
- expect(grid.getMargin()).toBe(10);
1145
- });
1146
- it('should not update css vars, with same value >', () => {
1147
- let options = {
1148
- cellHeight: 80,
1149
- margin: 5
1150
- };
1151
- let grid = GridStack.init(options);
1152
- expect(grid.getMargin()).toBe(5);
1153
- vi.spyOn(grid, '_initMargin');
1154
- grid.margin('5px');
1155
- expect(grid._initMargin).not.toHaveBeenCalled();
1156
- expect(grid.getMargin()).toBe(5);
1157
- });
1158
- it('should set top/bot/left value directly >', () => {
1159
- let options = {
1160
- cellHeight: 80,
1161
- marginTop: 5,
1162
- marginBottom: 0,
1163
- marginLeft: 1,
1164
- };
1165
- let grid = GridStack.init(options);
1166
- expect(grid.getMargin()).toBe(undefined);
1167
- expect(grid.opts.marginTop).toBe(5);
1168
- expect(grid.opts.marginBottom).toBe(0);
1169
- expect(grid.opts.marginLeft).toBe(1);
1170
- expect(grid.opts.marginRight).toBe(10); // default value
1171
- });
1172
- it('should set all 4 sides, and overall margin >', () => {
1173
- let options = {
1174
- cellHeight: 80,
1175
- marginTop: 5,
1176
- marginBottom: 5,
1177
- marginLeft: 5,
1178
- marginRight: 5,
1179
- };
1180
- let grid = GridStack.init(options);
1181
- expect(grid.getMargin()).toBe(5);
1182
- expect(grid.opts.marginTop).toBe(5);
1183
- expect(grid.opts.marginBottom).toBe(5);
1184
- expect(grid.opts.marginLeft).toBe(5);
1185
- expect(grid.opts.marginRight).toBe(5);
1186
- });
1187
- it('init 2 values >', () => {
1188
- let options = {
1189
- cellHeight: 80,
1190
- margin: '5px 10'
1191
- };
1192
- let grid = GridStack.init(options);
1193
- expect(grid.getMargin()).toBe(undefined);
1194
- expect(grid.opts.marginTop).toBe(5);
1195
- expect(grid.opts.marginBottom).toBe(5);
1196
- expect(grid.opts.marginLeft).toBe(10);
1197
- expect(grid.opts.marginRight).toBe(10);
1198
- });
1199
- it('init 4 values >', () => {
1200
- let options = {
1201
- cellHeight: 80,
1202
- margin: '1 2 0em 3'
1203
- };
1204
- let grid = GridStack.init(options);
1205
- expect(grid.getMargin()).toBe(undefined);
1206
- expect(grid.opts.marginTop).toBe(1);
1207
- expect(grid.opts.marginRight).toBe(2);
1208
- expect(grid.opts.marginBottom).toBe(0);
1209
- expect(grid.opts.marginLeft).toBe(3);
1210
- });
1211
- it('set 2 values, should update css vars >', () => {
1212
- let options = {
1213
- cellHeight: 80,
1214
- margin: 5
1215
- };
1216
- let grid = GridStack.init(options);
1217
- expect(grid.getMargin()).toBe(5);
1218
- grid.margin('1px 0');
1219
- expect(grid.getMargin()).toBe(undefined);
1220
- expect(grid.opts.marginTop).toBe(1);
1221
- expect(grid.opts.marginBottom).toBe(1);
1222
- expect(grid.opts.marginLeft).toBe(0);
1223
- expect(grid.opts.marginRight).toBe(0);
1224
- });
1225
- });
1226
- describe('grid.opts.rtl >', () => {
1227
- beforeEach(() => {
1228
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1229
- });
1230
- afterEach(() => {
1231
- document.body.removeChild(document.getElementById('gs-cont'));
1232
- });
1233
- it('should add grid-stack-rtl class >', () => {
1234
- let options = {
1235
- cellHeight: 80,
1236
- margin: 5,
1237
- rtl: true
1238
- };
1239
- grid = GridStack.init(options);
1240
- expect(grid.el.classList.contains('grid-stack-rtl')).toBe(true);
1241
- });
1242
- it('should not add grid-stack-rtl class >', () => {
1243
- let options = {
1244
- cellHeight: 80,
1245
- margin: 5
1246
- };
1247
- grid = GridStack.init(options);
1248
- expect(grid.el.classList.contains('grid-stack-rtl')).toBe(false);
1249
- });
1250
- });
1251
- describe('grid.enableMove', () => {
1252
- beforeEach(() => {
1253
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1254
- });
1255
- afterEach(() => {
1256
- document.body.removeChild(document.getElementById('gs-cont'));
1257
- });
1258
- it('should enable move for future also', () => {
1259
- let options = {
1260
- cellHeight: 80,
1261
- margin: 5,
1262
- disableDrag: true
1263
- };
1264
- grid = GridStack.init(options);
1265
- let items = Utils.getElements('.grid-stack-item');
1266
- items.forEach(el => expect(el.classList.contains('ui-draggable-disabled')).toBe(true));
1267
- expect(grid.opts.disableDrag).toBe(true);
1268
- grid.enableMove(true);
1269
- items.forEach(el => expect(el.classList.contains('ui-draggable-disabled')).toBe(false));
1270
- expect(grid.opts.disableDrag).not.toBe(true);
1271
- });
1272
- it('should disable move for existing only >', () => {
1273
- let options = {
1274
- cellHeight: 80,
1275
- margin: 5
1276
- };
1277
- grid = GridStack.init(options);
1278
- let items = Utils.getElements('.grid-stack-item');
1279
- items.forEach(el => expect(el.classList.contains('ui-draggable-disabled')).toBe(false));
1280
- expect(grid.opts.disableDrag).toBeFalsy();
1281
- grid.enableMove(false);
1282
- items.forEach(el => expect(el.classList.contains('ui-draggable-disabled')).toBe(true));
1283
- expect(grid.opts.disableDrag).toBe(true);
1284
- });
1285
- });
1286
- describe('grid.enableResize >', () => {
1287
- beforeEach(() => {
1288
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1289
- });
1290
- afterEach(() => {
1291
- document.body.removeChild(document.getElementById('gs-cont'));
1292
- });
1293
- it('should enable resize >', () => {
1294
- let options = {
1295
- cellHeight: 80,
1296
- margin: 5,
1297
- disableResize: true
1298
- };
1299
- grid = GridStack.init(options);
1300
- expect(grid.opts.disableResize).toBe(true);
1301
- let items = Utils.getElements('.grid-stack-item');
1302
- let dd = GridStack.getDD();
1303
- expect(dd).not.toBe(null); // sanity test to verify type
1304
- items.forEach(el => {
1305
- expect(dd.isResizable(el)).toBe(false);
1306
- expect(dd.isDraggable(el)).toBe(true);
1307
- });
1308
- grid.enableResize(true);
1309
- expect(grid.opts.disableResize).not.toBe(true);
1310
- items.forEach(el => {
1311
- expect(dd.isResizable(el)).toBe(true);
1312
- expect(dd.isDraggable(el)).toBe(true);
1313
- });
1314
- });
1315
- it('should disable resize >', () => {
1316
- let options = {
1317
- cellHeight: 80,
1318
- margin: 5
1319
- };
1320
- grid = GridStack.init(options);
1321
- expect(grid.opts.disableResize).toBeFalsy();
1322
- let items = Utils.getElements('.grid-stack-item');
1323
- let dd = GridStack.getDD();
1324
- items.forEach(el => expect(dd.isResizable(el)).toBe(true));
1325
- grid.enableResize(false);
1326
- expect(grid.opts.disableResize).toBe(true);
1327
- items.forEach(el => {
1328
- expect(dd.isResizable(el)).toBe(false);
1329
- expect(dd.isDraggable(el)).toBe(true);
1330
- });
1331
- });
1332
- });
1333
- describe('grid.enable >', () => {
1334
- beforeEach(() => {
1335
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1336
- });
1337
- afterEach(() => {
1338
- document.body.removeChild(document.getElementById('gs-cont'));
1339
- });
1340
- it('should enable movable and resizable >', () => {
1341
- let options = {
1342
- cellHeight: 80,
1343
- margin: 5
1344
- };
1345
- grid = GridStack.init(options);
1346
- let items = Utils.getElements('.grid-stack-item');
1347
- let dd = GridStack.getDD();
1348
- grid.enableResize(false);
1349
- grid.enableMove(false);
1350
- items.forEach(el => {
1351
- expect(el.classList.contains('ui-draggable-disabled')).toBe(true);
1352
- expect(dd.isResizable(el)).toBe(false);
1353
- expect(dd.isDraggable(el)).toBe(false);
1354
- });
1355
- grid.enable();
1356
- items.forEach(el => {
1357
- expect(el.classList.contains('ui-draggable-disabled')).toBe(false);
1358
- expect(dd.isResizable(el)).toBe(true);
1359
- expect(dd.isDraggable(el)).toBe(true);
1360
- });
1361
- });
1362
- });
1363
- describe('grid.enable >', () => {
1364
- beforeEach(() => {
1365
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1366
- });
1367
- afterEach(() => {
1368
- document.body.removeChild(document.getElementById('gs-cont'));
1369
- });
1370
- it('should lock widgets >', () => {
1371
- let options = {
1372
- cellHeight: 80,
1373
- margin: 5
1374
- };
1375
- grid = GridStack.init(options);
1376
- grid.update('.grid-stack-item', { locked: true });
1377
- Utils.getElements('.grid-stack-item').forEach(item => {
1378
- expect(item.getAttribute('gs-locked')).toBe('true');
1379
- });
1380
- });
1381
- it('should unlock widgets >', () => {
1382
- let options = {
1383
- cellHeight: 80,
1384
- margin: 5
1385
- };
1386
- grid = GridStack.init(options);
1387
- grid.update('.grid-stack-item', { locked: false });
1388
- Utils.getElements('.grid-stack-item').forEach(item => {
1389
- expect(item.getAttribute('gs-locked')).toBe(null);
1390
- });
1391
- });
1392
- });
1393
- describe('custom grid placement #1054 >', () => {
1394
- let HTML = '<div style="w: 800px; h: 600px" id="gs-cont">' +
1395
- ' <div class="grid-stack">' +
1396
- ' <div class="grid-stack-item" gs-x="0" gs-y="0" gs-w="12" gs-h="9">' +
1397
- ' <div class="grid-stack-item-content"></div>' +
1398
- ' </div>' +
1399
- ' <div class="grid-stack-item" gs-x="0" gs-y="9" gs-w="12" gs-h="5">' +
1400
- ' <div class="grid-stack-item-content"></div>' +
1401
- ' </div>' +
1402
- ' <div class="grid-stack-item" gs-x="0" gs-y="14" gs-w="7" gs-h="6">' +
1403
- ' <div class="grid-stack-item-content"></div>' +
1404
- ' </div>' +
1405
- ' <div class="grid-stack-item" gs-x="7" gs-y="14" gs-w="5" gs-h="6">' +
1406
- ' <div class="grid-stack-item-content"></div>' +
1407
- ' </div>' +
1408
- ' </div>' +
1409
- '</div>';
1410
- let pos = [{ x: 0, y: 0, w: 12, h: 9 }, { x: 0, y: 9, w: 12, h: 5 }, { x: 0, y: 14, w: 7, h: 6 }, { x: 7, y: 14, w: 5, h: 6 }];
1411
- beforeEach(() => {
1412
- document.body.insertAdjacentHTML('afterbegin', HTML);
1413
- });
1414
- afterEach(() => {
1415
- document.body.removeChild(document.getElementById('gs-cont'));
1416
- });
1417
- it('should have correct position >', () => {
1418
- let items = Utils.getElements('.grid-stack-item');
1419
- items.forEach((el, i) => {
1420
- expect(parseInt(el.getAttribute('gs-x'))).toBe(pos[i].x);
1421
- expect(parseInt(el.getAttribute('gs-y'))).toBe(pos[i].y);
1422
- expect(parseInt(el.getAttribute('gs-w'))).toBe(pos[i].w);
1423
- expect(parseInt(el.getAttribute('gs-h'))).toBe(pos[i].h);
1424
- });
1425
- });
1426
- });
1427
- describe('grid.compact >', () => {
1428
- beforeEach(() => {
1429
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1430
- });
1431
- afterEach(() => {
1432
- document.body.removeChild(document.getElementById('gs-cont'));
1433
- });
1434
- it('should move all 3 items to top-left with no space >', () => {
1435
- grid = GridStack.init({ float: true });
1436
- let el3 = grid.addWidget({ x: 3, y: 5 });
1437
- expect(parseInt(el3.getAttribute('gs-x'))).toBe(3);
1438
- expect(parseInt(el3.getAttribute('gs-y'))).toBe(5);
1439
- grid.compact();
1440
- expect(parseInt(el3.getAttribute('gs-x'))).toBe(8);
1441
- expect(el3.getAttribute('gs-y')).toBe(null);
1442
- });
1443
- it('not move locked item >', () => {
1444
- grid = GridStack.init({ float: true });
1445
- let el3 = grid.addWidget({ x: 3, y: 5, locked: true, noMove: true });
1446
- expect(parseInt(el3.getAttribute('gs-x'))).toBe(3);
1447
- expect(parseInt(el3.getAttribute('gs-y'))).toBe(5);
1448
- grid.compact();
1449
- expect(parseInt(el3.getAttribute('gs-x'))).toBe(3);
1450
- expect(parseInt(el3.getAttribute('gs-y'))).toBe(5);
1451
- });
1452
- });
1453
- describe('gridOption locked #1181 >', () => {
1454
- beforeEach(() => {
1455
- document.body.insertAdjacentHTML('afterbegin', gridstackEmptyHTML);
1456
- });
1457
- afterEach(() => {
1458
- document.body.removeChild(document.getElementById('gs-cont'));
1459
- });
1460
- it('not move locked item, size down added one >', () => {
1461
- grid = GridStack.init();
1462
- let el1 = grid.addWidget({ x: 0, y: 1, w: 12, locked: true });
1463
- expect(el1.getAttribute('gs-x')).toBe(null);
1464
- expect(parseInt(el1.getAttribute('gs-y'))).toBe(1);
1465
- let el2 = grid.addWidget({ x: 2, y: 0, h: 3 });
1466
- expect(el1.getAttribute('gs-x')).toBe(null);
1467
- expect(parseInt(el1.getAttribute('gs-y'))).toBe(1);
1468
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(2);
1469
- expect(parseInt(el2.getAttribute('gs-y'))).toBe(2);
1470
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(3);
1471
- });
1472
- });
1473
- describe('nested grids >', () => {
1474
- beforeEach(() => {
1475
- document.body.insertAdjacentHTML('afterbegin', gridstackNestedHTML);
1476
- });
1477
- afterEach(() => {
1478
- document.body.removeChild(document.getElementById('gs-cont'));
1479
- });
1480
- it('should both init, second with nested class >', () => {
1481
- grids = GridStack.initAll();
1482
- expect(grids.length).toBe(2);
1483
- expect(grids[0].el.classList.contains('grid-stack-nested')).toBe(false);
1484
- expect(grids[1].el.classList.contains('grid-stack-nested')).toBe(true);
1485
- });
1486
- });
1487
- describe('two grids >', () => {
1488
- beforeEach(() => {
1489
- document.body.insertAdjacentHTML('afterbegin', gridHTML);
1490
- document.body.insertAdjacentHTML('afterbegin', gridHTML);
1491
- });
1492
- afterEach(() => {
1493
- let els = document.body.querySelectorAll('.grid-stack');
1494
- expect(els.length).toBe(2);
1495
- els.forEach(g => g.remove());
1496
- });
1497
- it('should not remove incorrect child >', () => {
1498
- grids = GridStack.initAll();
1499
- expect(grids.length).toBe(2);
1500
- expect(grids[0].engine.nodes.length).toBe(2);
1501
- expect(grids[1].engine.nodes.length).toBe(2);
1502
- // should do nothing
1503
- grids[0].removeWidget(grids[1].engine.nodes[0].el);
1504
- expect(grids[0].engine.nodes.length).toBe(2);
1505
- expect(grids[0].el.children.length).toBe(2);
1506
- expect(grids[1].engine.nodes.length).toBe(2);
1507
- expect(grids[1].el.children.length).toBe(2);
1508
- // should empty with no errors
1509
- grids[1].removeAll();
1510
- expect(grids[0].engine.nodes.length).toBe(2);
1511
- expect(grids[0].el.children.length).toBe(2);
1512
- expect(grids[1].engine.nodes.length).toBe(0);
1513
- expect(grids[1].el.children.length).toBe(0);
1514
- });
1515
- it('should remove 1 child >', () => {
1516
- grids = GridStack.initAll();
1517
- grids[1].removeWidget(grids[1].engine.nodes[0].el);
1518
- expect(grids[0].engine.nodes.length).toBe(2);
1519
- expect(grids[0].el.children.length).toBe(2);
1520
- expect(grids[1].engine.nodes.length).toBe(1);
1521
- expect(grids[1].el.children.length).toBe(1);
1522
- });
1523
- });
1524
- describe('grid.on events >', () => {
1525
- beforeEach(() => {
1526
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1527
- });
1528
- afterEach(() => {
1529
- document.body.removeChild(document.getElementById('gs-cont'));
1530
- });
1531
- it('add 3 single events >', () => {
1532
- grid = GridStack.init();
1533
- let fcn = (event) => { };
1534
- grid.on('added', fcn).on('enable', fcn).on('dragstart', fcn);
1535
- expect(grid._gsEventHandler.enable).not.toBe(undefined);
1536
- grid.off('added').off('enable').off('dragstart');
1537
- expect(grid._gsEventHandler.enable).toBe(undefined);
1538
- });
1539
- it('add 3 events >', () => {
1540
- let grid = GridStack.init(); // prevent TS check for string combine...
1541
- let fcn = (event) => { };
1542
- grid.on('added enable dragstart', fcn);
1543
- expect(grid._gsEventHandler.enable).not.toBe(undefined);
1544
- grid.off('added enable dragstart');
1545
- expect(grid._gsEventHandler.enable).toBe(undefined);
1546
- });
1547
- });
1548
- describe('save & load >', () => {
1549
- beforeEach(() => {
1550
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1551
- });
1552
- afterEach(() => {
1553
- document.body.removeChild(document.getElementById('gs-cont'));
1554
- });
1555
- it('save layout >', () => {
1556
- grid = GridStack.init({ maxRow: 10 });
1557
- let layout = grid.save(false);
1558
- expect(layout).toEqual([{ x: 0, y: 0, w: 4, h: 2, id: 'gsItem1' }, { x: 4, y: 0, w: 4, h: 4, id: 'gsItem2' }]);
1559
- layout = grid.save();
1560
- expect(layout).toEqual([{ x: 0, y: 0, w: 4, h: 2, id: 'gsItem1', content: 'item 1 text' }, { x: 4, y: 0, w: 4, h: 4, id: 'gsItem2', content: 'item 2 text' }]);
1561
- layout = grid.save(true);
1562
- expect(layout).toEqual([{ x: 0, y: 0, w: 4, h: 2, id: 'gsItem1', content: 'item 1 text' }, { x: 4, y: 0, w: 4, h: 4, id: 'gsItem2', content: 'item 2 text' }]);
1563
- });
1564
- it('save layout full >', () => {
1565
- grid = GridStack.init({ maxRow: 10, _foo: 'bar' }); // using bogus 'internal' field (stripped)
1566
- let layout = grid.save(false, true);
1567
- expect(layout).toEqual({ maxRow: 10, children: [{ x: 0, y: 0, w: 4, h: 2, id: 'gsItem1' }, { x: 4, y: 0, w: 4, h: 4, id: 'gsItem2' }] });
1568
- layout = grid.save(true, true);
1569
- expect(layout).toEqual({ maxRow: 10, children: [{ x: 0, y: 0, w: 4, h: 2, id: 'gsItem1', content: 'item 1 text' }, { x: 4, y: 0, w: 4, h: 4, id: 'gsItem2', content: 'item 2 text' }] });
1570
- });
1571
- it('load move 1 item, delete others >', () => {
1572
- grid = GridStack.init();
1573
- grid.load([{ x: 2, h: 1, id: 'gsItem2' }]);
1574
- let layout = grid.save(false);
1575
- expect(layout).toEqual([{ x: 0, y: 0, id: 'gsItem2' }]);
1576
- });
1577
- it('load add new, delete others >', () => {
1578
- grid = GridStack.init();
1579
- grid.load([{ w: 2, y: 0, h: 1, id: 'gsItem3' }], true);
1580
- let layout = grid.save(false);
1581
- expect(layout).toEqual([{ x: 0, y: 0, w: 2, id: 'gsItem3' }]);
1582
- });
1583
- it('load 1 item only, no remove >', () => {
1584
- grid = GridStack.init();
1585
- grid.load([{ h: 3, id: 'gsItem1' }], false);
1586
- let layout = grid.save(false);
1587
- expect(layout).toEqual([{ x: 0, y: 0, h: 3, id: 'gsItem1' }, { x: 4, y: 0, w: 4, h: 4, id: 'gsItem2' }]);
1588
- });
1589
- it('load 1 item only with callback >', () => {
1590
- grid = GridStack.init();
1591
- grid.load([{ h: 3, id: 'gsItem1' }], () => null);
1592
- let layout = grid.save(false);
1593
- expect(layout).toEqual([{ x: 0, y: 0, h: 3, id: 'gsItem1' }]);
1594
- });
1595
- });
1596
- describe('load >', () => {
1597
- beforeEach(() => {
1598
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1599
- });
1600
- afterEach(() => {
1601
- document.body.removeChild(document.getElementById('gs-cont'));
1602
- });
1603
- it('after init #1693 >', () => {
1604
- grid = GridStack.init();
1605
- grid.load([{ id: 'gsItem1', x: 0, y: 0, w: 5, h: 1 }, { id: 'gsItem2', x: 6, y: 0, w: 2, h: 2 }]);
1606
- let el1 = document.getElementById('item1');
1607
- expect(el1.getAttribute('gs-x')).toBe(null);
1608
- expect(el1.getAttribute('gs-y')).toBe(null);
1609
- expect(parseInt(el1.getAttribute('gs-w'))).toBe(5);
1610
- expect(el1.getAttribute('gs-h')).toBe(null);
1611
- let el2 = document.getElementById('item2');
1612
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(6);
1613
- expect(el2.getAttribute('gs-y')).toBe(null);
1614
- expect(parseInt(el2.getAttribute('gs-w'))).toBe(2);
1615
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(2);
1616
- });
1617
- it('after init replace nodes >', () => {
1618
- grid = GridStack.init();
1619
- expect(document.getElementById('item1')).not.toBe(null);
1620
- expect(document.getElementById('item2')).not.toBe(null);
1621
- // this will replace with 2 new nodes
1622
- grid.load([{ id: 'new1', x: 0, y: 0, w: 5, h: 1 }, { id: 'new2', x: 6, y: 0, w: 2, h: 2 }]);
1623
- expect(grid.engine.nodes.length).toBe(2);
1624
- expect(document.getElementById('item1')).toBe(null);
1625
- let el1 = grid.engine.nodes.find(n => n.id === 'new1').el;
1626
- expect(el1.getAttribute('gs-x')).toBe(null);
1627
- expect(el1.getAttribute('gs-y')).toBe(null);
1628
- expect(parseInt(el1.getAttribute('gs-w'))).toBe(5);
1629
- expect(el1.getAttribute('gs-h')).toBe(null);
1630
- expect(document.getElementById('item2')).toBe(null);
1631
- let el2 = grid.engine.nodes.find(n => n.id === 'new2').el;
1632
- expect(parseInt(el2.getAttribute('gs-x'))).toBe(6);
1633
- expect(el2.getAttribute('gs-y')).toBe(null);
1634
- expect(parseInt(el2.getAttribute('gs-w'))).toBe(2);
1635
- expect(parseInt(el2.getAttribute('gs-h'))).toBe(2);
1636
- });
1637
- });
1638
- describe('load empty >', () => {
1639
- let items;
1640
- let grid;
1641
- const test = () => {
1642
- items.forEach(item => {
1643
- const n = grid.engine.nodes.find(n => n.id === item.id);
1644
- if (item.y)
1645
- expect(parseInt(n.el.getAttribute('gs-y'))).toBe(item.y);
1646
- else
1647
- expect(n.el.getAttribute('gs-y')).toBe(null);
1648
- });
1649
- };
1650
- beforeEach(() => {
1651
- document.body.insertAdjacentHTML('afterbegin', gridstackEmptyHTML);
1652
- items = [
1653
- { id: '0', x: 0, y: 0 },
1654
- { id: '1', x: 0, y: 1 },
1655
- { id: '2', x: 0, y: 2 },
1656
- { id: '3', x: 0, y: 3 },
1657
- ];
1658
- });
1659
- afterEach(() => {
1660
- document.body.removeChild(document.getElementById('gs-cont'));
1661
- });
1662
- it('update collision >', () => {
1663
- grid = GridStack.init({ children: items });
1664
- const n = grid.engine.nodes[0];
1665
- test();
1666
- grid.update(n.el, { h: 5 });
1667
- items[1].y = 5;
1668
- items[2].y = 6;
1669
- items[3].y = 7;
1670
- test();
1671
- grid.update(n.el, { h: 1 });
1672
- items[1].y = 1;
1673
- items[2].y = 2;
1674
- items[3].y = 3;
1675
- test();
1676
- });
1677
- it('load collision 2208 >', () => {
1678
- grid = GridStack.init({ children: items });
1679
- test();
1680
- items[0].h = 5;
1681
- grid.load(items);
1682
- items[1].y = 5;
1683
- items[2].y = 6;
1684
- items[3].y = 7;
1685
- test();
1686
- items[0].h = 1;
1687
- grid.load(items);
1688
- items[1].y = 1;
1689
- items[2].y = 2;
1690
- items[3].y = 3;
1691
- test();
1692
- });
1693
- it('load full collision 2208 >', () => {
1694
- grid = GridStack.init({ children: items });
1695
- test();
1696
- items[0].h = 5;
1697
- grid.load(grid.engine.nodes.map((n, index) => {
1698
- if (index === 0)
1699
- return { ...n, h: 5 };
1700
- return n;
1701
- }));
1702
- items[1].y = 5;
1703
- items[2].y = 6;
1704
- items[3].y = 7;
1705
- test();
1706
- items[0].h = 1;
1707
- grid.load(grid.engine.nodes.map((n, index) => {
1708
- if (index === 0)
1709
- return { ...n, h: 1 };
1710
- return n;
1711
- }));
1712
- items[1].y = 1;
1713
- items[2].y = 2;
1714
- items[3].y = 3;
1715
- test();
1716
- });
1717
- });
1718
- // ..and finally track log warnings at the end, instead of displaying them....
1719
- describe('obsolete warnings >', () => {
1720
- console.warn = vi.fn(); // track warnings instead of displaying them
1721
- beforeEach(() => {
1722
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1723
- });
1724
- afterEach(() => {
1725
- document.body.removeChild(document.getElementById('gs-cont'));
1726
- });
1727
- it('willItFit() legacy >', () => {
1728
- grid = GridStack.init({ maxRow: 5 });
1729
- expect(grid.willItFit(0, 0, 1, 3, false)).toBe(true);
1730
- expect(grid.willItFit(0, 0, 1, 4, false)).toBe(false);
1731
- });
1732
- it('warning if OLD commit() is called >', () => {
1733
- grid = GridStack.init();
1734
- grid.batchUpdate(true);
1735
- expect(grid.engine.batchMode).toBe(true);
1736
- grid.commit(); // old API
1737
- expect(grid.engine.batchMode).toBe(false);
1738
- // expect(console.warn).toHaveBeenCalledWith('gridstack.js: Function `setGridWidth` is deprecated in v0.5.3 and has been replaced with `column`. It will be **completely** removed in v1.0');
1739
- });
1740
- /* saving as example
1741
- it('warning if OLD setGridWidth is called >', () => {
1742
- let grid: any = GridStack.init();
1743
- grid.setGridWidth(11); // old 0.5.2 API
1744
- expect(grid.getColumn()).toBe(11);
1745
- expect(console.warn).toHaveBeenCalledWith('gridstack.js: Function `setGridWidth` is deprecated in v0.5.3 and has been replaced with `column`. It will be **completely** removed in v1.0');
1746
- });
1747
- */
1748
- });
1749
- // Note: Stylesheet tests moved to E2E tests
1750
- // where real browser CSS engines can provide accurate getComputedStyle() values
1751
- // describe('stylesheet', () => {});
1752
- describe('updateOptions()', () => {
1753
- let grid;
1754
- beforeEach(() => {
1755
- document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1756
- grid = GridStack.init({ cellHeight: 30 });
1757
- });
1758
- afterEach(() => {
1759
- document.body.removeChild(document.getElementById('gs-cont'));
1760
- });
1761
- it('update all values supported', () => {
1762
- grid.updateOptions({
1763
- cellHeight: '40px',
1764
- margin: 8,
1765
- column: 11,
1766
- float: true,
1767
- row: 10,
1768
- });
1769
- expect(grid.getCellHeight(true)).toBe(40);
1770
- expect(grid.getMargin()).toBe(8);
1771
- expect(grid.opts.marginTop).toBe(8);
1772
- expect(grid.getColumn()).toBe(11);
1773
- expect(grid.getFloat()).toBe(true);
1774
- expect(grid.opts.row).toBe(10);
1775
- expect(grid.opts.minRow).toBe(10);
1776
- expect(grid.opts.maxRow).toBe(10);
1777
- });
1778
- });
1779
- });
1780
- //# sourceMappingURL=gridstack-spec.js.map