@revolist/revogrid 3.3.2 → 3.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.
@@ -582,6 +582,21 @@ class DimensionProvider {
582
582
  this.viewports.stores[type].setViewport({ realCount });
583
583
  this.stores[type].setRealSize(realCount);
584
584
  }
585
+ /**
586
+ * Apply new custom sizes to dimension and view port
587
+ * @param type - dimension type
588
+ * @param sizes - new custom sizes
589
+ * @param keepOld - keep old sizes merge new with old
590
+ */
591
+ setCustomSizes(type, sizes, keepOld = false) {
592
+ let newSizes = sizes;
593
+ if (keepOld) {
594
+ const oldSizes = this.stores[type].store.get('sizes');
595
+ newSizes = Object.assign(Object.assign({}, oldSizes), sizes);
596
+ }
597
+ this.stores[type].setDimensionSize(newSizes);
598
+ this.viewports.stores[type].setViewPortDimension(newSizes, !keepOld ? this.stores[type].store.get('originItemSize') : undefined);
599
+ }
585
600
  /**
586
601
  * Sets dimension data and view port coordinate
587
602
  * @param items - data/column items
@@ -606,8 +621,9 @@ class DimensionProvider {
606
621
  this.stores[type].drop();
607
622
  }
608
623
  }
609
- setColumns(type, sizes, noVirtual = false) {
610
- this.stores[type].setDimensionSize(sizes);
624
+ setColumns(type, newLength, sizes, noVirtual = false) {
625
+ this.setRealSize(newLength, type);
626
+ this.setCustomSizes(type, sizes);
611
627
  if (noVirtual) {
612
628
  this.setNoVirtual(type);
613
629
  }
@@ -3336,8 +3352,7 @@ const RevoGridComponent = /*@__PURE__*/ proxyCustomElement(class extends HTMLEle
3336
3352
  this.beforecolumnsset.emit(columnGather);
3337
3353
  for (let type of columnTypes) {
3338
3354
  const items = columnGather.columns[type];
3339
- this.dimensionProvider.setRealSize(items.length, type);
3340
- this.dimensionProvider.setColumns(type, ColumnDataProvider.getSizes(items), type !== 'rgCol');
3355
+ this.dimensionProvider.setColumns(type, items.length, ColumnDataProvider.getSizes(items), type !== 'rgCol');
3341
3356
  }
3342
3357
  this.beforecolumnapplied.emit(columnGather);
3343
3358
  const columns = this.columnProvider.setColumns(columnGather);
@@ -188,6 +188,41 @@ function getFirstItem(s) {
188
188
  function getLastItem(s) {
189
189
  return s.items[s.end];
190
190
  }
191
+ /**
192
+ * Set items sizes from start index to end
193
+ * @param vpItems
194
+ * @param start
195
+ * @param size
196
+ * @param lastCoordinate
197
+ * @returns
198
+ */
199
+ function setItemSizes(vpItems, initialIndex, size, lastCoordinate) {
200
+ const items = [...vpItems];
201
+ const count = items.length;
202
+ let pos = lastCoordinate;
203
+ let i = 0;
204
+ let start = initialIndex;
205
+ // viewport not inited
206
+ if (!count) {
207
+ return [];
208
+ }
209
+ // loop through array from initial item after recombination
210
+ while (i < count) {
211
+ const item = items[start];
212
+ item.start = pos;
213
+ item.size = size;
214
+ item.end = item.start + size;
215
+ pos = item.end;
216
+ // loop by start index
217
+ start++;
218
+ i++;
219
+ // if start index out of array, reset it
220
+ if (start === count) {
221
+ start = 0;
222
+ }
223
+ }
224
+ return items;
225
+ }
191
226
 
192
227
  /**
193
228
  * Store is responsible for visible
@@ -258,8 +293,8 @@ class ViewportStore {
258
293
  }
259
294
  }
260
295
  /** Update viewport sizes */
261
- setViewPortDimension(sizes) {
262
- const items = this.store.get('items');
296
+ setViewPortDimension(sizes, dropToOriginalSize) {
297
+ let items = this.store.get('items');
263
298
  const count = items.length;
264
299
  // viewport not inited
265
300
  if (!count) {
@@ -268,6 +303,10 @@ class ViewportStore {
268
303
  let changedCoordinate = 0;
269
304
  let i = 0;
270
305
  let start = this.store.get('start');
306
+ // drop to original size if requested
307
+ if (dropToOriginalSize) {
308
+ items = setItemSizes(items, start, dropToOriginalSize, this.store.get('lastCoordinate'));
309
+ }
271
310
  // loop through array from initial item after recombination
272
311
  while (i < count) {
273
312
  const item = items[start];
@@ -4430,6 +4430,21 @@ class DimensionProvider {
4430
4430
  this.viewports.stores[type].setViewport({ realCount });
4431
4431
  this.stores[type].setRealSize(realCount);
4432
4432
  }
4433
+ /**
4434
+ * Apply new custom sizes to dimension and view port
4435
+ * @param type - dimension type
4436
+ * @param sizes - new custom sizes
4437
+ * @param keepOld - keep old sizes merge new with old
4438
+ */
4439
+ setCustomSizes(type, sizes, keepOld = false) {
4440
+ let newSizes = sizes;
4441
+ if (keepOld) {
4442
+ const oldSizes = this.stores[type].store.get('sizes');
4443
+ newSizes = Object.assign(Object.assign({}, oldSizes), sizes);
4444
+ }
4445
+ this.stores[type].setDimensionSize(newSizes);
4446
+ this.viewports.stores[type].setViewPortDimension(newSizes, !keepOld ? this.stores[type].store.get('originItemSize') : undefined);
4447
+ }
4433
4448
  /**
4434
4449
  * Sets dimension data and view port coordinate
4435
4450
  * @param items - data/column items
@@ -4454,8 +4469,9 @@ class DimensionProvider {
4454
4469
  this.stores[type].drop();
4455
4470
  }
4456
4471
  }
4457
- setColumns(type, sizes, noVirtual = false) {
4458
- this.stores[type].setDimensionSize(sizes);
4472
+ setColumns(type, newLength, sizes, noVirtual = false) {
4473
+ this.setRealSize(newLength, type);
4474
+ this.setCustomSizes(type, sizes);
4459
4475
  if (noVirtual) {
4460
4476
  this.setNoVirtual(type);
4461
4477
  }
@@ -4668,6 +4684,41 @@ function getFirstItem(s) {
4668
4684
  function getLastItem(s) {
4669
4685
  return s.items[s.end];
4670
4686
  }
4687
+ /**
4688
+ * Set items sizes from start index to end
4689
+ * @param vpItems
4690
+ * @param start
4691
+ * @param size
4692
+ * @param lastCoordinate
4693
+ * @returns
4694
+ */
4695
+ function setItemSizes(vpItems, initialIndex, size, lastCoordinate) {
4696
+ const items = [...vpItems];
4697
+ const count = items.length;
4698
+ let pos = lastCoordinate;
4699
+ let i = 0;
4700
+ let start = initialIndex;
4701
+ // viewport not inited
4702
+ if (!count) {
4703
+ return [];
4704
+ }
4705
+ // loop through array from initial item after recombination
4706
+ while (i < count) {
4707
+ const item = items[start];
4708
+ item.start = pos;
4709
+ item.size = size;
4710
+ item.end = item.start + size;
4711
+ pos = item.end;
4712
+ // loop by start index
4713
+ start++;
4714
+ i++;
4715
+ // if start index out of array, reset it
4716
+ if (start === count) {
4717
+ start = 0;
4718
+ }
4719
+ }
4720
+ return items;
4721
+ }
4671
4722
 
4672
4723
  /**
4673
4724
  * Store is responsible for visible
@@ -4738,8 +4789,8 @@ class ViewportStore {
4738
4789
  }
4739
4790
  }
4740
4791
  /** Update viewport sizes */
4741
- setViewPortDimension(sizes) {
4742
- const items = this.store.get('items');
4792
+ setViewPortDimension(sizes, dropToOriginalSize) {
4793
+ let items = this.store.get('items');
4743
4794
  const count = items.length;
4744
4795
  // viewport not inited
4745
4796
  if (!count) {
@@ -4748,6 +4799,10 @@ class ViewportStore {
4748
4799
  let changedCoordinate = 0;
4749
4800
  let i = 0;
4750
4801
  let start = this.store.get('start');
4802
+ // drop to original size if requested
4803
+ if (dropToOriginalSize) {
4804
+ items = setItemSizes(items, start, dropToOriginalSize, this.store.get('lastCoordinate'));
4805
+ }
4751
4806
  // loop through array from initial item after recombination
4752
4807
  while (i < count) {
4753
4808
  const item = items[start];
@@ -25205,8 +25260,7 @@ const RevoGridComponent = class {
25205
25260
  this.beforecolumnsset.emit(columnGather);
25206
25261
  for (let type of columnTypes) {
25207
25262
  const items = columnGather.columns[type];
25208
- this.dimensionProvider.setRealSize(items.length, type);
25209
- this.dimensionProvider.setColumns(type, ColumnDataProvider.getSizes(items), type !== 'rgCol');
25263
+ this.dimensionProvider.setColumns(type, items.length, ColumnDataProvider.getSizes(items), type !== 'rgCol');
25210
25264
  }
25211
25265
  this.beforecolumnapplied.emit(columnGather);
25212
25266
  const columns = this.columnProvider.setColumns(columnGather);
@@ -392,8 +392,7 @@ export class RevoGridComponent {
392
392
  this.beforecolumnsset.emit(columnGather);
393
393
  for (let type of columnTypes) {
394
394
  const items = columnGather.columns[type];
395
- this.dimensionProvider.setRealSize(items.length, type);
396
- this.dimensionProvider.setColumns(type, ColumnDataProvider.getSizes(items), type !== 'rgCol');
395
+ this.dimensionProvider.setColumns(type, items.length, ColumnDataProvider.getSizes(items), type !== 'rgCol');
397
396
  }
398
397
  this.beforecolumnapplied.emit(columnGather);
399
398
  const columns = this.columnProvider.setColumns(columnGather);
@@ -21,6 +21,21 @@ export default class DimensionProvider {
21
21
  this.viewports.stores[type].setViewport({ realCount });
22
22
  this.stores[type].setRealSize(realCount);
23
23
  }
24
+ /**
25
+ * Apply new custom sizes to dimension and view port
26
+ * @param type - dimension type
27
+ * @param sizes - new custom sizes
28
+ * @param keepOld - keep old sizes merge new with old
29
+ */
30
+ setCustomSizes(type, sizes, keepOld = false) {
31
+ let newSizes = sizes;
32
+ if (keepOld) {
33
+ const oldSizes = this.stores[type].store.get('sizes');
34
+ newSizes = Object.assign(Object.assign({}, oldSizes), sizes);
35
+ }
36
+ this.stores[type].setDimensionSize(newSizes);
37
+ this.viewports.stores[type].setViewPortDimension(newSizes, !keepOld ? this.stores[type].store.get('originItemSize') : undefined);
38
+ }
24
39
  /**
25
40
  * Sets dimension data and view port coordinate
26
41
  * @param items - data/column items
@@ -45,8 +60,9 @@ export default class DimensionProvider {
45
60
  this.stores[type].drop();
46
61
  }
47
62
  }
48
- setColumns(type, sizes, noVirtual = false) {
49
- this.stores[type].setDimensionSize(sizes);
63
+ setColumns(type, newLength, sizes, noVirtual = false) {
64
+ this.setRealSize(newLength, type);
65
+ this.setCustomSizes(type, sizes);
50
66
  if (noVirtual) {
51
67
  this.setNoVirtual(type);
52
68
  }
@@ -181,3 +181,38 @@ export function getFirstItem(s) {
181
181
  export function getLastItem(s) {
182
182
  return s.items[s.end];
183
183
  }
184
+ /**
185
+ * Set items sizes from start index to end
186
+ * @param vpItems
187
+ * @param start
188
+ * @param size
189
+ * @param lastCoordinate
190
+ * @returns
191
+ */
192
+ export function setItemSizes(vpItems, initialIndex, size, lastCoordinate) {
193
+ const items = [...vpItems];
194
+ const count = items.length;
195
+ let pos = lastCoordinate;
196
+ let i = 0;
197
+ let start = initialIndex;
198
+ // viewport not inited
199
+ if (!count) {
200
+ return [];
201
+ }
202
+ // loop through array from initial item after recombination
203
+ while (i < count) {
204
+ const item = items[start];
205
+ item.start = pos;
206
+ item.size = size;
207
+ item.end = item.start + size;
208
+ pos = item.end;
209
+ // loop by start index
210
+ start++;
211
+ i++;
212
+ // if start index out of array, reset it
213
+ if (start === count) {
214
+ start = 0;
215
+ }
216
+ }
217
+ return items;
218
+ }
@@ -7,7 +7,7 @@
7
7
  * Redraw items during scrolling
8
8
  */
9
9
  import { createStore } from '@stencil/store';
10
- import { addMissingItems, getFirstItem, getLastItem, getUpdatedItemsByPosition, isActiveRange, updateMissingAndRange } from './viewport.helpers';
10
+ import { addMissingItems, getFirstItem, getLastItem, getUpdatedItemsByPosition, isActiveRange, setItemSizes, updateMissingAndRange } from './viewport.helpers';
11
11
  import { setStore } from '../../utils/store.utils';
12
12
  function initialState() {
13
13
  return {
@@ -73,8 +73,8 @@ export default class ViewportStore {
73
73
  }
74
74
  }
75
75
  /** Update viewport sizes */
76
- setViewPortDimension(sizes) {
77
- const items = this.store.get('items');
76
+ setViewPortDimension(sizes, dropToOriginalSize) {
77
+ let items = this.store.get('items');
78
78
  const count = items.length;
79
79
  // viewport not inited
80
80
  if (!count) {
@@ -83,6 +83,10 @@ export default class ViewportStore {
83
83
  let changedCoordinate = 0;
84
84
  let i = 0;
85
85
  let start = this.store.get('start');
86
+ // drop to original size if requested
87
+ if (dropToOriginalSize) {
88
+ items = setItemSizes(items, start, dropToOriginalSize, this.store.get('lastCoordinate'));
89
+ }
86
90
  // loop through array from initial item after recombination
87
91
  while (i < count) {
88
92
  const item = items[start];
@@ -4426,6 +4426,21 @@ class DimensionProvider {
4426
4426
  this.viewports.stores[type].setViewport({ realCount });
4427
4427
  this.stores[type].setRealSize(realCount);
4428
4428
  }
4429
+ /**
4430
+ * Apply new custom sizes to dimension and view port
4431
+ * @param type - dimension type
4432
+ * @param sizes - new custom sizes
4433
+ * @param keepOld - keep old sizes merge new with old
4434
+ */
4435
+ setCustomSizes(type, sizes, keepOld = false) {
4436
+ let newSizes = sizes;
4437
+ if (keepOld) {
4438
+ const oldSizes = this.stores[type].store.get('sizes');
4439
+ newSizes = Object.assign(Object.assign({}, oldSizes), sizes);
4440
+ }
4441
+ this.stores[type].setDimensionSize(newSizes);
4442
+ this.viewports.stores[type].setViewPortDimension(newSizes, !keepOld ? this.stores[type].store.get('originItemSize') : undefined);
4443
+ }
4429
4444
  /**
4430
4445
  * Sets dimension data and view port coordinate
4431
4446
  * @param items - data/column items
@@ -4450,8 +4465,9 @@ class DimensionProvider {
4450
4465
  this.stores[type].drop();
4451
4466
  }
4452
4467
  }
4453
- setColumns(type, sizes, noVirtual = false) {
4454
- this.stores[type].setDimensionSize(sizes);
4468
+ setColumns(type, newLength, sizes, noVirtual = false) {
4469
+ this.setRealSize(newLength, type);
4470
+ this.setCustomSizes(type, sizes);
4455
4471
  if (noVirtual) {
4456
4472
  this.setNoVirtual(type);
4457
4473
  }
@@ -4664,6 +4680,41 @@ function getFirstItem(s) {
4664
4680
  function getLastItem(s) {
4665
4681
  return s.items[s.end];
4666
4682
  }
4683
+ /**
4684
+ * Set items sizes from start index to end
4685
+ * @param vpItems
4686
+ * @param start
4687
+ * @param size
4688
+ * @param lastCoordinate
4689
+ * @returns
4690
+ */
4691
+ function setItemSizes(vpItems, initialIndex, size, lastCoordinate) {
4692
+ const items = [...vpItems];
4693
+ const count = items.length;
4694
+ let pos = lastCoordinate;
4695
+ let i = 0;
4696
+ let start = initialIndex;
4697
+ // viewport not inited
4698
+ if (!count) {
4699
+ return [];
4700
+ }
4701
+ // loop through array from initial item after recombination
4702
+ while (i < count) {
4703
+ const item = items[start];
4704
+ item.start = pos;
4705
+ item.size = size;
4706
+ item.end = item.start + size;
4707
+ pos = item.end;
4708
+ // loop by start index
4709
+ start++;
4710
+ i++;
4711
+ // if start index out of array, reset it
4712
+ if (start === count) {
4713
+ start = 0;
4714
+ }
4715
+ }
4716
+ return items;
4717
+ }
4667
4718
 
4668
4719
  /**
4669
4720
  * Store is responsible for visible
@@ -4734,8 +4785,8 @@ class ViewportStore {
4734
4785
  }
4735
4786
  }
4736
4787
  /** Update viewport sizes */
4737
- setViewPortDimension(sizes) {
4738
- const items = this.store.get('items');
4788
+ setViewPortDimension(sizes, dropToOriginalSize) {
4789
+ let items = this.store.get('items');
4739
4790
  const count = items.length;
4740
4791
  // viewport not inited
4741
4792
  if (!count) {
@@ -4744,6 +4795,10 @@ class ViewportStore {
4744
4795
  let changedCoordinate = 0;
4745
4796
  let i = 0;
4746
4797
  let start = this.store.get('start');
4798
+ // drop to original size if requested
4799
+ if (dropToOriginalSize) {
4800
+ items = setItemSizes(items, start, dropToOriginalSize, this.store.get('lastCoordinate'));
4801
+ }
4747
4802
  // loop through array from initial item after recombination
4748
4803
  while (i < count) {
4749
4804
  const item = items[start];
@@ -25201,8 +25256,7 @@ const RevoGridComponent = class {
25201
25256
  this.beforecolumnsset.emit(columnGather);
25202
25257
  for (let type of columnTypes) {
25203
25258
  const items = columnGather.columns[type];
25204
- this.dimensionProvider.setRealSize(items.length, type);
25205
- this.dimensionProvider.setColumns(type, ColumnDataProvider.getSizes(items), type !== 'rgCol');
25259
+ this.dimensionProvider.setColumns(type, items.length, ColumnDataProvider.getSizes(items), type !== 'rgCol');
25206
25260
  }
25207
25261
  this.beforecolumnapplied.emit(columnGather);
25208
25262
  const columns = this.columnProvider.setColumns(columnGather);