@revolist/revogrid 3.6.0 → 3.6.2

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.
@@ -28,10 +28,7 @@ items, realCount, virtualSize, dimension) {
28
28
  toUpdate = recombineByOffset(Math.abs(changedOffsetStart), Object.assign(Object.assign({ positiveDirection: changedOffsetStart > -1 }, dimension), items));
29
29
  }
30
30
  }
31
- // virtual size can differ based on scroll position if some big items are present
32
- // scroll can be in the middle of item and virtual size will be larger
33
- // so we need to exclude this part from virtual size hence it's already passed
34
- const maxSizeVirtualSize = Math.min(virtualSize + (activeItem.end - activeItem.start), dimension.realSize);
31
+ const maxSizeVirtualSize = getMaxVirtualSize(virtualSize, dimension.realSize, activeItem);
35
32
  // if partial recombination add items if revo-viewport has some space left
36
33
  if (toUpdate) {
37
34
  const extra = addMissingItems(activeItem, realCount, maxSizeVirtualSize, toUpdate, dimension);
@@ -58,6 +55,12 @@ items, realCount, virtualSize, dimension) {
58
55
  }
59
56
  return toUpdate;
60
57
  }
58
+ // virtual size can differ based on scroll position if some big items are present
59
+ // scroll can be in the middle of item and virtual size will be larger
60
+ // so we need to exclude this part from virtual size hence it's already passed
61
+ function getMaxVirtualSize(virtualSize, realSize, activeItem) {
62
+ return Math.min(virtualSize + (activeItem.end - activeItem.start), realSize);
63
+ }
61
64
  function updateMissingAndRange(items, missing, range) {
62
65
  items.splice(range.end + 1, 0, ...missing);
63
66
  // update range if start larger after recombination
@@ -189,8 +192,24 @@ function getItemSize(index, sizes, origSize = 0) {
189
192
  }
190
193
  return origSize;
191
194
  }
192
- function isActiveRange(pos, item) {
193
- return item && pos >= item.start && pos <= item.end;
195
+ /**
196
+ * Verify if position is in range of the PositionItem, start and end are included
197
+ */
198
+ function isActiveRange(pos, realSize, first, last) {
199
+ if (!first || !last) {
200
+ return false;
201
+ }
202
+ // if position is in range of first item
203
+ // or position is after first item and last item is the last item in real size
204
+ return pos >= first.start && pos <= first.end ||
205
+ pos > first.end && last.end === realSize;
206
+ }
207
+ function isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem) {
208
+ // if no first item, means no items in viewport
209
+ if (!firstItem) {
210
+ return false;
211
+ }
212
+ return virtualSize + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end);
194
213
  }
195
214
  function getFirstItem(s) {
196
215
  return s.items[s.start];
@@ -267,29 +286,37 @@ class ViewportStore {
267
286
  return;
268
287
  }
269
288
  const frameOffset = dimension.frameOffset;
270
- const outsize = frameOffset * 2 * dimension.originItemSize;
289
+ const singleOffsetInPx = dimension.originItemSize * frameOffset;
290
+ // add offset to virtual size from both sides
291
+ const outsize = singleOffsetInPx * 2;
271
292
  virtualSize += outsize;
272
- let maxCoordinate = virtualSize;
293
+ // expected no scroll if real size less than virtual size, position is 0
294
+ let maxCoordinate = 0;
295
+ // if there is nodes outside of viewport, max coordinate has to be adjusted
273
296
  if (dimension.realSize > virtualSize) {
297
+ // max coordinate is real size minus virtual/rendered space
274
298
  maxCoordinate = dimension.realSize - virtualSize;
275
299
  }
276
300
  let toUpdate = {
277
301
  lastCoordinate: position,
278
302
  };
279
303
  let pos = position;
280
- pos -= frameOffset * dimension.originItemSize;
304
+ pos -= singleOffsetInPx;
281
305
  pos = pos < 0 ? 0 : pos < maxCoordinate ? pos : maxCoordinate;
282
- const firstItem = getFirstItem(this.getItems());
283
- const lastItem = getLastItem(this.getItems());
306
+ const allItems = this.getItems();
307
+ const firstItem = getFirstItem(allItems);
308
+ const lastItem = getLastItem(allItems);
284
309
  // left position changed
285
- if (!isActiveRange(pos, firstItem)) {
286
- toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, this.getItems(), this.store.get('realCount'), virtualSize, dimension));
310
+ // verify if new position is in range of previously rendered first item
311
+ if (!isActiveRange(pos, dimension.realSize, firstItem, lastItem)) {
312
+ toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, allItems, this.store.get('realCount'), virtualSize, dimension));
287
313
  this.setViewport(Object.assign({}, toUpdate));
288
314
  // right position changed
289
315
  }
290
- else if (firstItem && this.store.get('virtualSize') + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end)) {
316
+ else if (isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem)) {
291
317
  // check is any item missing for full fill content
292
- const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, this.getItems(), dimension);
318
+ const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, allItems, dimension);
319
+ // update missing items
293
320
  if (missing.length) {
294
321
  const items = [...this.store.get('items')];
295
322
  const range = {
@@ -4525,10 +4525,7 @@ items, realCount, virtualSize, dimension) {
4525
4525
  toUpdate = recombineByOffset(Math.abs(changedOffsetStart), Object.assign(Object.assign({ positiveDirection: changedOffsetStart > -1 }, dimension), items));
4526
4526
  }
4527
4527
  }
4528
- // virtual size can differ based on scroll position if some big items are present
4529
- // scroll can be in the middle of item and virtual size will be larger
4530
- // so we need to exclude this part from virtual size hence it's already passed
4531
- const maxSizeVirtualSize = Math.min(virtualSize + (activeItem.end - activeItem.start), dimension.realSize);
4528
+ const maxSizeVirtualSize = getMaxVirtualSize(virtualSize, dimension.realSize, activeItem);
4532
4529
  // if partial recombination add items if revo-viewport has some space left
4533
4530
  if (toUpdate) {
4534
4531
  const extra = addMissingItems(activeItem, realCount, maxSizeVirtualSize, toUpdate, dimension);
@@ -4555,6 +4552,12 @@ items, realCount, virtualSize, dimension) {
4555
4552
  }
4556
4553
  return toUpdate;
4557
4554
  }
4555
+ // virtual size can differ based on scroll position if some big items are present
4556
+ // scroll can be in the middle of item and virtual size will be larger
4557
+ // so we need to exclude this part from virtual size hence it's already passed
4558
+ function getMaxVirtualSize(virtualSize, realSize, activeItem) {
4559
+ return Math.min(virtualSize + (activeItem.end - activeItem.start), realSize);
4560
+ }
4558
4561
  function updateMissingAndRange(items, missing, range) {
4559
4562
  items.splice(range.end + 1, 0, ...missing);
4560
4563
  // update range if start larger after recombination
@@ -4686,8 +4689,24 @@ function getItemSize(index, sizes, origSize = 0) {
4686
4689
  }
4687
4690
  return origSize;
4688
4691
  }
4689
- function isActiveRange(pos, item) {
4690
- return item && pos >= item.start && pos <= item.end;
4692
+ /**
4693
+ * Verify if position is in range of the PositionItem, start and end are included
4694
+ */
4695
+ function isActiveRange(pos, realSize, first, last) {
4696
+ if (!first || !last) {
4697
+ return false;
4698
+ }
4699
+ // if position is in range of first item
4700
+ // or position is after first item and last item is the last item in real size
4701
+ return pos >= first.start && pos <= first.end ||
4702
+ pos > first.end && last.end === realSize;
4703
+ }
4704
+ function isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem) {
4705
+ // if no first item, means no items in viewport
4706
+ if (!firstItem) {
4707
+ return false;
4708
+ }
4709
+ return virtualSize + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end);
4691
4710
  }
4692
4711
  function getFirstItem(s) {
4693
4712
  return s.items[s.start];
@@ -4764,29 +4783,37 @@ class ViewportStore {
4764
4783
  return;
4765
4784
  }
4766
4785
  const frameOffset = dimension.frameOffset;
4767
- const outsize = frameOffset * 2 * dimension.originItemSize;
4786
+ const singleOffsetInPx = dimension.originItemSize * frameOffset;
4787
+ // add offset to virtual size from both sides
4788
+ const outsize = singleOffsetInPx * 2;
4768
4789
  virtualSize += outsize;
4769
- let maxCoordinate = virtualSize;
4790
+ // expected no scroll if real size less than virtual size, position is 0
4791
+ let maxCoordinate = 0;
4792
+ // if there is nodes outside of viewport, max coordinate has to be adjusted
4770
4793
  if (dimension.realSize > virtualSize) {
4794
+ // max coordinate is real size minus virtual/rendered space
4771
4795
  maxCoordinate = dimension.realSize - virtualSize;
4772
4796
  }
4773
4797
  let toUpdate = {
4774
4798
  lastCoordinate: position,
4775
4799
  };
4776
4800
  let pos = position;
4777
- pos -= frameOffset * dimension.originItemSize;
4801
+ pos -= singleOffsetInPx;
4778
4802
  pos = pos < 0 ? 0 : pos < maxCoordinate ? pos : maxCoordinate;
4779
- const firstItem = getFirstItem(this.getItems());
4780
- const lastItem = getLastItem(this.getItems());
4803
+ const allItems = this.getItems();
4804
+ const firstItem = getFirstItem(allItems);
4805
+ const lastItem = getLastItem(allItems);
4781
4806
  // left position changed
4782
- if (!isActiveRange(pos, firstItem)) {
4783
- toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, this.getItems(), this.store.get('realCount'), virtualSize, dimension));
4807
+ // verify if new position is in range of previously rendered first item
4808
+ if (!isActiveRange(pos, dimension.realSize, firstItem, lastItem)) {
4809
+ toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, allItems, this.store.get('realCount'), virtualSize, dimension));
4784
4810
  this.setViewport(Object.assign({}, toUpdate));
4785
4811
  // right position changed
4786
4812
  }
4787
- else if (firstItem && this.store.get('virtualSize') + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end)) {
4813
+ else if (isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem)) {
4788
4814
  // check is any item missing for full fill content
4789
- const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, this.getItems(), dimension);
4815
+ const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, allItems, dimension);
4816
+ // update missing items
4790
4817
  if (missing.length) {
4791
4818
  const items = [...this.store.get('items')];
4792
4819
  const range = {
@@ -21,10 +21,7 @@ items, realCount, virtualSize, dimension) {
21
21
  toUpdate = recombineByOffset(Math.abs(changedOffsetStart), Object.assign(Object.assign({ positiveDirection: changedOffsetStart > -1 }, dimension), items));
22
22
  }
23
23
  }
24
- // virtual size can differ based on scroll position if some big items are present
25
- // scroll can be in the middle of item and virtual size will be larger
26
- // so we need to exclude this part from virtual size hence it's already passed
27
- const maxSizeVirtualSize = Math.min(virtualSize + (activeItem.end - activeItem.start), dimension.realSize);
24
+ const maxSizeVirtualSize = getMaxVirtualSize(virtualSize, dimension.realSize, activeItem);
28
25
  // if partial recombination add items if revo-viewport has some space left
29
26
  if (toUpdate) {
30
27
  const extra = addMissingItems(activeItem, realCount, maxSizeVirtualSize, toUpdate, dimension);
@@ -51,6 +48,12 @@ items, realCount, virtualSize, dimension) {
51
48
  }
52
49
  return toUpdate;
53
50
  }
51
+ // virtual size can differ based on scroll position if some big items are present
52
+ // scroll can be in the middle of item and virtual size will be larger
53
+ // so we need to exclude this part from virtual size hence it's already passed
54
+ function getMaxVirtualSize(virtualSize, realSize, activeItem) {
55
+ return Math.min(virtualSize + (activeItem.end - activeItem.start), realSize);
56
+ }
54
57
  export function updateMissingAndRange(items, missing, range) {
55
58
  items.splice(range.end + 1, 0, ...missing);
56
59
  // update range if start larger after recombination
@@ -182,8 +185,24 @@ function getItemSize(index, sizes, origSize = 0) {
182
185
  }
183
186
  return origSize;
184
187
  }
185
- export function isActiveRange(pos, item) {
186
- return item && pos >= item.start && pos <= item.end;
188
+ /**
189
+ * Verify if position is in range of the PositionItem, start and end are included
190
+ */
191
+ export function isActiveRange(pos, realSize, first, last) {
192
+ if (!first || !last) {
193
+ return false;
194
+ }
195
+ // if position is in range of first item
196
+ // or position is after first item and last item is the last item in real size
197
+ return pos >= first.start && pos <= first.end ||
198
+ pos > first.end && last.end === realSize;
199
+ }
200
+ export function isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem) {
201
+ // if no first item, means no items in viewport
202
+ if (!firstItem) {
203
+ return false;
204
+ }
205
+ return virtualSize + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end);
187
206
  }
188
207
  export function getFirstItem(s) {
189
208
  return s.items[s.start];
@@ -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, setItemSizes, updateMissingAndRange } from './viewport.helpers';
10
+ import { addMissingItems, getFirstItem, getLastItem, getUpdatedItemsByPosition, isActiveRange, isActiveRangeOutsideLastItem, setItemSizes, updateMissingAndRange } from './viewport.helpers';
11
11
  import { setStore } from '../../utils/store.utils';
12
12
  function initialState() {
13
13
  return {
@@ -37,29 +37,37 @@ export default class ViewportStore {
37
37
  return;
38
38
  }
39
39
  const frameOffset = dimension.frameOffset;
40
- const outsize = frameOffset * 2 * dimension.originItemSize;
40
+ const singleOffsetInPx = dimension.originItemSize * frameOffset;
41
+ // add offset to virtual size from both sides
42
+ const outsize = singleOffsetInPx * 2;
41
43
  virtualSize += outsize;
42
- let maxCoordinate = virtualSize;
44
+ // expected no scroll if real size less than virtual size, position is 0
45
+ let maxCoordinate = 0;
46
+ // if there is nodes outside of viewport, max coordinate has to be adjusted
43
47
  if (dimension.realSize > virtualSize) {
48
+ // max coordinate is real size minus virtual/rendered space
44
49
  maxCoordinate = dimension.realSize - virtualSize;
45
50
  }
46
51
  let toUpdate = {
47
52
  lastCoordinate: position,
48
53
  };
49
54
  let pos = position;
50
- pos -= frameOffset * dimension.originItemSize;
55
+ pos -= singleOffsetInPx;
51
56
  pos = pos < 0 ? 0 : pos < maxCoordinate ? pos : maxCoordinate;
52
- const firstItem = getFirstItem(this.getItems());
53
- const lastItem = getLastItem(this.getItems());
57
+ const allItems = this.getItems();
58
+ const firstItem = getFirstItem(allItems);
59
+ const lastItem = getLastItem(allItems);
54
60
  // left position changed
55
- if (!isActiveRange(pos, firstItem)) {
56
- toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, this.getItems(), this.store.get('realCount'), virtualSize, dimension));
61
+ // verify if new position is in range of previously rendered first item
62
+ if (!isActiveRange(pos, dimension.realSize, firstItem, lastItem)) {
63
+ toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, allItems, this.store.get('realCount'), virtualSize, dimension));
57
64
  this.setViewport(Object.assign({}, toUpdate));
58
65
  // right position changed
59
66
  }
60
- else if (firstItem && this.store.get('virtualSize') + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end)) {
67
+ else if (isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem)) {
61
68
  // check is any item missing for full fill content
62
- const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, this.getItems(), dimension);
69
+ const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, allItems, dimension);
70
+ // update missing items
63
71
  if (missing.length) {
64
72
  const items = [...this.store.get('items')];
65
73
  const range = {
@@ -67,9 +67,15 @@ export function generateFakeDataObject(config = {}) {
67
67
  prop: rgCol,
68
68
  filter:"myFilterType",
69
69
  sortable: true,
70
- size: 200,
70
+ size: 140,
71
71
  cellCompare: (rgCol % 2) == 0 ? naturalSort : undefined
72
72
  };
73
+
74
+ if (rgCol == 0) {
75
+ columns[rgCol].size = 433;
76
+ } else if (rgCol == 10) {
77
+ columns[rgCol].size = 200;
78
+ }
73
79
 
74
80
  // apply config
75
81
  if (colPinStart.indexOf(j) > -1) {
@@ -4521,10 +4521,7 @@ items, realCount, virtualSize, dimension) {
4521
4521
  toUpdate = recombineByOffset(Math.abs(changedOffsetStart), Object.assign(Object.assign({ positiveDirection: changedOffsetStart > -1 }, dimension), items));
4522
4522
  }
4523
4523
  }
4524
- // virtual size can differ based on scroll position if some big items are present
4525
- // scroll can be in the middle of item and virtual size will be larger
4526
- // so we need to exclude this part from virtual size hence it's already passed
4527
- const maxSizeVirtualSize = Math.min(virtualSize + (activeItem.end - activeItem.start), dimension.realSize);
4524
+ const maxSizeVirtualSize = getMaxVirtualSize(virtualSize, dimension.realSize, activeItem);
4528
4525
  // if partial recombination add items if revo-viewport has some space left
4529
4526
  if (toUpdate) {
4530
4527
  const extra = addMissingItems(activeItem, realCount, maxSizeVirtualSize, toUpdate, dimension);
@@ -4551,6 +4548,12 @@ items, realCount, virtualSize, dimension) {
4551
4548
  }
4552
4549
  return toUpdate;
4553
4550
  }
4551
+ // virtual size can differ based on scroll position if some big items are present
4552
+ // scroll can be in the middle of item and virtual size will be larger
4553
+ // so we need to exclude this part from virtual size hence it's already passed
4554
+ function getMaxVirtualSize(virtualSize, realSize, activeItem) {
4555
+ return Math.min(virtualSize + (activeItem.end - activeItem.start), realSize);
4556
+ }
4554
4557
  function updateMissingAndRange(items, missing, range) {
4555
4558
  items.splice(range.end + 1, 0, ...missing);
4556
4559
  // update range if start larger after recombination
@@ -4682,8 +4685,24 @@ function getItemSize(index, sizes, origSize = 0) {
4682
4685
  }
4683
4686
  return origSize;
4684
4687
  }
4685
- function isActiveRange(pos, item) {
4686
- return item && pos >= item.start && pos <= item.end;
4688
+ /**
4689
+ * Verify if position is in range of the PositionItem, start and end are included
4690
+ */
4691
+ function isActiveRange(pos, realSize, first, last) {
4692
+ if (!first || !last) {
4693
+ return false;
4694
+ }
4695
+ // if position is in range of first item
4696
+ // or position is after first item and last item is the last item in real size
4697
+ return pos >= first.start && pos <= first.end ||
4698
+ pos > first.end && last.end === realSize;
4699
+ }
4700
+ function isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem) {
4701
+ // if no first item, means no items in viewport
4702
+ if (!firstItem) {
4703
+ return false;
4704
+ }
4705
+ return virtualSize + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end);
4687
4706
  }
4688
4707
  function getFirstItem(s) {
4689
4708
  return s.items[s.start];
@@ -4760,29 +4779,37 @@ class ViewportStore {
4760
4779
  return;
4761
4780
  }
4762
4781
  const frameOffset = dimension.frameOffset;
4763
- const outsize = frameOffset * 2 * dimension.originItemSize;
4782
+ const singleOffsetInPx = dimension.originItemSize * frameOffset;
4783
+ // add offset to virtual size from both sides
4784
+ const outsize = singleOffsetInPx * 2;
4764
4785
  virtualSize += outsize;
4765
- let maxCoordinate = virtualSize;
4786
+ // expected no scroll if real size less than virtual size, position is 0
4787
+ let maxCoordinate = 0;
4788
+ // if there is nodes outside of viewport, max coordinate has to be adjusted
4766
4789
  if (dimension.realSize > virtualSize) {
4790
+ // max coordinate is real size minus virtual/rendered space
4767
4791
  maxCoordinate = dimension.realSize - virtualSize;
4768
4792
  }
4769
4793
  let toUpdate = {
4770
4794
  lastCoordinate: position,
4771
4795
  };
4772
4796
  let pos = position;
4773
- pos -= frameOffset * dimension.originItemSize;
4797
+ pos -= singleOffsetInPx;
4774
4798
  pos = pos < 0 ? 0 : pos < maxCoordinate ? pos : maxCoordinate;
4775
- const firstItem = getFirstItem(this.getItems());
4776
- const lastItem = getLastItem(this.getItems());
4799
+ const allItems = this.getItems();
4800
+ const firstItem = getFirstItem(allItems);
4801
+ const lastItem = getLastItem(allItems);
4777
4802
  // left position changed
4778
- if (!isActiveRange(pos, firstItem)) {
4779
- toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, this.getItems(), this.store.get('realCount'), virtualSize, dimension));
4803
+ // verify if new position is in range of previously rendered first item
4804
+ if (!isActiveRange(pos, dimension.realSize, firstItem, lastItem)) {
4805
+ toUpdate = Object.assign(Object.assign({}, toUpdate), getUpdatedItemsByPosition(pos, allItems, this.store.get('realCount'), virtualSize, dimension));
4780
4806
  this.setViewport(Object.assign({}, toUpdate));
4781
4807
  // right position changed
4782
4808
  }
4783
- else if (firstItem && this.store.get('virtualSize') + pos > (lastItem === null || lastItem === void 0 ? void 0 : lastItem.end)) {
4809
+ else if (isActiveRangeOutsideLastItem(pos, virtualSize, firstItem, lastItem)) {
4784
4810
  // check is any item missing for full fill content
4785
- const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, this.getItems(), dimension);
4811
+ const missing = addMissingItems(firstItem, this.store.get('realCount'), virtualSize + pos - firstItem.start, allItems, dimension);
4812
+ // update missing items
4786
4813
  if (missing.length) {
4787
4814
  const items = [...this.store.get('items')];
4788
4815
  const range = {