@websy/websy-designs 1.9.12 → 1.9.13

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.
@@ -6694,7 +6694,8 @@ class WebsyTable3 {
6694
6694
  disableInternalLoader: false,
6695
6695
  disableTouch: false,
6696
6696
  scrollWidth: 10,
6697
- touchScrollWidth: 30
6697
+ touchScrollWidth: 30,
6698
+ autoFitColumns: true
6698
6699
  }
6699
6700
  this.options = Object.assign({}, DEFAULTS, options)
6700
6701
  this.isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
@@ -7072,7 +7073,7 @@ class WebsyTable3 {
7072
7073
  maxWidth = this.options.maxColWidth
7073
7074
  }
7074
7075
  else if (this.options.maxColWidth.indexOf('%') !== -1) {
7075
- maxWidth = this.sizes.outer.width * (+(this.options.maxColWidth.replace('%', '')) / 100)
7076
+ maxWidth = this.sizes.table.width * (+(this.options.maxColWidth.replace('%', '')) / 100)
7076
7077
  }
7077
7078
  else if (this.options.maxColWidth.indexOf('px') !== -1) {
7078
7079
  maxWidth = +this.options.maxColWidth.replace('px', '')
@@ -7085,7 +7086,7 @@ class WebsyTable3 {
7085
7086
  this.sizes.total = footerEl.getBoundingClientRect()
7086
7087
  const rows = Array.from(tableEl.querySelectorAll('.websy-table-row'))
7087
7088
  let totalWidth = 0
7088
- this.sizes.scrollableWidth = this.sizes.outer.width
7089
+ this.sizes.scrollableWidth = this.sizes.table.width
7089
7090
  let firstNonPinnedColumnWidth = 0
7090
7091
  let columnsForSizing = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
7091
7092
  rows.forEach((row, rowIndex) => {
@@ -7094,8 +7095,10 @@ class WebsyTable3 {
7094
7095
  this.sizes.cellHeight = colSize.height
7095
7096
  if (columnsForSizing[colIndex]) {
7096
7097
  if (!columnsForSizing[colIndex].actualWidth) {
7098
+ columnsForSizing[colIndex].potentialWidth = 0
7097
7099
  columnsForSizing[colIndex].actualWidth = 0
7098
7100
  }
7101
+ columnsForSizing[colIndex].potentialWidth = Math.max(columnsForSizing[colIndex].potentialWidth, colSize.width)
7099
7102
  columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth)
7100
7103
  // if (columnsForSizing[colIndex].width) {
7101
7104
  // columnsForSizing[colIndex].actualWidth = columnsForSizing[colIndex].width
@@ -7115,19 +7118,53 @@ class WebsyTable3 {
7115
7118
  this.sizes.totalWidth = columnsForSizing.reduce((a, b) => a + (b.width || b.actualWidth), 0)
7116
7119
  this.sizes.totalNonPinnedWidth = columnsForSizing.filter((c, i) => i >= this.pinnedColumns).reduce((a, b) => a + (b.width || b.actualWidth), 0)
7117
7120
  this.sizes.pinnedWidth = this.sizes.totalWidth - this.sizes.totalNonPinnedWidth
7118
- // const outerSize = outerEl.getBoundingClientRect()
7119
- if (this.sizes.totalWidth < this.sizes.outer.width) {
7120
- let equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / columnsForSizing.length
7121
+ // const outerSize = outerEl.getBoundingClientRect()
7122
+ if (this.sizes.totalWidth < this.sizes.table.width) {
7123
+ let requiredSpace = 0
7124
+ let availableSpace = (this.sizes.table.width - this.sizes.totalWidth)
7125
+ columnsForSizing.forEach(c => {
7126
+ c.shouldGrow = true
7127
+ if (this.options.autoFitColumns === false) {
7128
+ c.shouldGrow = false
7129
+ if (c.potentialWidth > c.actualWidth) {
7130
+ c.shouldGrow = true
7131
+ c.growDiff = c.potentialWidth - c.actualWidth
7132
+ c.growDiffPerc = (c.potentialWidth - c.actualWidth) / availableSpace
7133
+ requiredSpace += c.growDiff
7134
+ }
7135
+ }
7136
+ })
7137
+ let equalWidth = (this.sizes.table.width - this.sizes.totalWidth) / columnsForSizing.filter(c => c.shouldGrow).length
7121
7138
  this.sizes.totalWidth = 0
7122
7139
  this.sizes.totalNonPinnedWidth = 0
7123
7140
  columnsForSizing.forEach((c, i) => {
7124
7141
  // if (!c.width) {
7125
7142
  // if (c.actualWidth < equalWidth) {
7126
7143
  // adjust the width
7127
- if (c.width) {
7128
- c.width += equalWidth
7144
+ if (this.options.autoFitColumns === true) {
7145
+ if (c.width) {
7146
+ c.width += equalWidth
7147
+ }
7148
+ c.actualWidth += equalWidth
7149
+ }
7150
+ else {
7151
+ if (requiredSpace > 0 && requiredSpace <= availableSpace) {
7152
+ if (c.shouldGrow) {
7153
+ if (c.width) {
7154
+ c.width += c.growDiff
7155
+ }
7156
+ c.actualWidth += c.growDiff
7157
+ }
7158
+ }
7159
+ else {
7160
+ if (c.shouldGrow) {
7161
+ if (c.width) {
7162
+ c.width += availableSpace * (c.growDiff / requiredSpace)
7163
+ }
7164
+ c.actualWidth += availableSpace * (c.growDiff / requiredSpace)
7165
+ }
7166
+ }
7129
7167
  }
7130
- c.actualWidth += equalWidth
7131
7168
  // }
7132
7169
  // }
7133
7170
  this.sizes.totalWidth += c.width || c.actualWidth
@@ -7138,9 +7175,9 @@ class WebsyTable3 {
7138
7175
  })
7139
7176
  }
7140
7177
  // check that we have enough from for all of the pinned columns plus 1 non pinned column
7141
- if (this.sizes.pinnedWidth > (this.sizes.outer.width - firstNonPinnedColumnWidth)) {
7178
+ if (this.sizes.pinnedWidth > (this.sizes.table.width - firstNonPinnedColumnWidth)) {
7142
7179
  this.sizes.totalWidth = 0
7143
- let diff = this.sizes.pinnedWidth - (this.sizes.outer.width - firstNonPinnedColumnWidth)
7180
+ let diff = this.sizes.pinnedWidth - (this.sizes.table.width - firstNonPinnedColumnWidth)
7144
7181
  let oldPinnedWidth = this.sizes.pinnedWidth
7145
7182
  this.sizes.pinnedWidth = 0
7146
7183
  // let colDiff = diff / this.pinnedColumns
@@ -7178,7 +7215,7 @@ class WebsyTable3 {
7178
7215
  else {
7179
7216
  this.vScrollRequired = false
7180
7217
  }
7181
- if (this.sizes.totalWidth > this.sizes.outer.width) {
7218
+ if (this.sizes.totalWidth.toFixed(3) > this.sizes.table.width.toFixed(3)) {
7182
7219
  this.hScrollRequired = true
7183
7220
  }
7184
7221
  else {
@@ -7543,7 +7580,6 @@ class WebsyTable3 {
7543
7580
  let vHandleEl = document.getElementById(`${this.elementId}_vScrollHandle`)
7544
7581
  if (this.vScrollRequired === true) {
7545
7582
  vScrollEl.style.top = `${this.sizes.header.height + this.sizes.total.height}px`
7546
- // vScrollEl.style.left = `${this.sizes.outer.width - (this.options.isTouchDevice ? this.options.touchScrollWidth : this.options.scrollWidth)}px`
7547
7583
  vScrollEl.style.height = `${this.sizes.bodyHeight}px`
7548
7584
  if (this.isTouchDevice === true) {
7549
7585
  vScrollEl.style.visibility = `unset`
@@ -7656,7 +7692,8 @@ class WebsyTable3 {
7656
7692
  }
7657
7693
  }
7658
7694
  }
7659
- cumulativeWidth = 0
7695
+ cumulativeWidth = 0
7696
+ let lastColWidth = 0
7660
7697
  for (let i = this.startCol; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
7661
7698
  if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
7662
7699
  cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
@@ -7671,9 +7708,22 @@ class WebsyTable3 {
7671
7708
  if (this.endCol === this.options.allColumns[this.options.allColumns.length - 1].length - 1 && cumulativeWidth > this.sizes.scrollableWidth && actualLeft > 0) {
7672
7709
  this.startCol += 1
7673
7710
  }
7674
- if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth) {
7675
- this.startCol += 1
7676
- this.endCol += 1
7711
+ if (
7712
+ scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >=
7713
+ scrollContainerEl.offsetWidth - lastColWidth
7714
+ ) {
7715
+ this.endCol = this.options.allColumns[this.options.allColumns.length - 1].length - 1
7716
+ this.startCol = this.endCol + 1
7717
+ // one last measurement
7718
+ let finalAcc = 0
7719
+ for (let i = this.endCol; i > -1; i--) {
7720
+ if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
7721
+ finalAcc += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
7722
+ if (finalAcc < this.sizes.scrollableWidth) {
7723
+ this.startCol--
7724
+ }
7725
+ }
7726
+ }
7677
7727
  }
7678
7728
  this.endCol = Math.max(this.startCol, this.endCol)
7679
7729
  this.options.onScroll('y', this.startRow, this.endRow, this.startCol - this.pinnedColumns, this.endCol - this.pinnedColumns)
@@ -6392,7 +6392,8 @@ var WebsyTable3 = /*#__PURE__*/function () {
6392
6392
  disableInternalLoader: false,
6393
6393
  disableTouch: false,
6394
6394
  scrollWidth: 10,
6395
- touchScrollWidth: 30
6395
+ touchScrollWidth: 30,
6396
+ autoFitColumns: true
6396
6397
  };
6397
6398
  this.options = _extends({}, DEFAULTS, options);
6398
6399
  this.isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
@@ -6706,7 +6707,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6706
6707
  if (typeof this.options.maxColWidth === 'number') {
6707
6708
  maxWidth = this.options.maxColWidth;
6708
6709
  } else if (this.options.maxColWidth.indexOf('%') !== -1) {
6709
- maxWidth = this.sizes.outer.width * (+this.options.maxColWidth.replace('%', '') / 100);
6710
+ maxWidth = this.sizes.table.width * (+this.options.maxColWidth.replace('%', '') / 100);
6710
6711
  } else if (this.options.maxColWidth.indexOf('px') !== -1) {
6711
6712
  maxWidth = +this.options.maxColWidth.replace('px', '');
6712
6713
  }
@@ -6718,7 +6719,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6718
6719
  this.sizes.total = footerEl.getBoundingClientRect();
6719
6720
  var rows = Array.from(tableEl.querySelectorAll('.websy-table-row'));
6720
6721
  var totalWidth = 0;
6721
- this.sizes.scrollableWidth = this.sizes.outer.width;
6722
+ this.sizes.scrollableWidth = this.sizes.table.width;
6722
6723
  var firstNonPinnedColumnWidth = 0;
6723
6724
  var columnsForSizing = this.options.columns[this.options.columns.length - 1].filter(function (c) {
6724
6725
  return c.show !== false;
@@ -6729,8 +6730,10 @@ var WebsyTable3 = /*#__PURE__*/function () {
6729
6730
  _this46.sizes.cellHeight = colSize.height;
6730
6731
  if (columnsForSizing[colIndex]) {
6731
6732
  if (!columnsForSizing[colIndex].actualWidth) {
6733
+ columnsForSizing[colIndex].potentialWidth = 0;
6732
6734
  columnsForSizing[colIndex].actualWidth = 0;
6733
6735
  }
6736
+ columnsForSizing[colIndex].potentialWidth = Math.max(columnsForSizing[colIndex].potentialWidth, colSize.width);
6734
6737
  columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth);
6735
6738
  // if (columnsForSizing[colIndex].width) {
6736
6739
  // columnsForSizing[colIndex].actualWidth = columnsForSizing[colIndex].width
@@ -6756,19 +6759,53 @@ var WebsyTable3 = /*#__PURE__*/function () {
6756
6759
  return a + (b.width || b.actualWidth);
6757
6760
  }, 0);
6758
6761
  this.sizes.pinnedWidth = this.sizes.totalWidth - this.sizes.totalNonPinnedWidth;
6759
- // const outerSize = outerEl.getBoundingClientRect()
6760
- if (this.sizes.totalWidth < this.sizes.outer.width) {
6761
- var equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / columnsForSizing.length;
6762
+ // const outerSize = outerEl.getBoundingClientRect()
6763
+ if (this.sizes.totalWidth < this.sizes.table.width) {
6764
+ var requiredSpace = 0;
6765
+ var availableSpace = this.sizes.table.width - this.sizes.totalWidth;
6766
+ columnsForSizing.forEach(function (c) {
6767
+ c.shouldGrow = true;
6768
+ if (_this46.options.autoFitColumns === false) {
6769
+ c.shouldGrow = false;
6770
+ if (c.potentialWidth > c.actualWidth) {
6771
+ c.shouldGrow = true;
6772
+ c.growDiff = c.potentialWidth - c.actualWidth;
6773
+ c.growDiffPerc = (c.potentialWidth - c.actualWidth) / availableSpace;
6774
+ requiredSpace += c.growDiff;
6775
+ }
6776
+ }
6777
+ });
6778
+ var equalWidth = (this.sizes.table.width - this.sizes.totalWidth) / columnsForSizing.filter(function (c) {
6779
+ return c.shouldGrow;
6780
+ }).length;
6762
6781
  this.sizes.totalWidth = 0;
6763
6782
  this.sizes.totalNonPinnedWidth = 0;
6764
6783
  columnsForSizing.forEach(function (c, i) {
6765
6784
  // if (!c.width) {
6766
6785
  // if (c.actualWidth < equalWidth) {
6767
6786
  // adjust the width
6768
- if (c.width) {
6769
- c.width += equalWidth;
6787
+ if (_this46.options.autoFitColumns === true) {
6788
+ if (c.width) {
6789
+ c.width += equalWidth;
6790
+ }
6791
+ c.actualWidth += equalWidth;
6792
+ } else {
6793
+ if (requiredSpace > 0 && requiredSpace <= availableSpace) {
6794
+ if (c.shouldGrow) {
6795
+ if (c.width) {
6796
+ c.width += c.growDiff;
6797
+ }
6798
+ c.actualWidth += c.growDiff;
6799
+ }
6800
+ } else {
6801
+ if (c.shouldGrow) {
6802
+ if (c.width) {
6803
+ c.width += availableSpace * (c.growDiff / requiredSpace);
6804
+ }
6805
+ c.actualWidth += availableSpace * (c.growDiff / requiredSpace);
6806
+ }
6807
+ }
6770
6808
  }
6771
- c.actualWidth += equalWidth;
6772
6809
  // }
6773
6810
  // }
6774
6811
  _this46.sizes.totalWidth += c.width || c.actualWidth;
@@ -6779,9 +6816,9 @@ var WebsyTable3 = /*#__PURE__*/function () {
6779
6816
  });
6780
6817
  }
6781
6818
  // check that we have enough from for all of the pinned columns plus 1 non pinned column
6782
- if (this.sizes.pinnedWidth > this.sizes.outer.width - firstNonPinnedColumnWidth) {
6819
+ if (this.sizes.pinnedWidth > this.sizes.table.width - firstNonPinnedColumnWidth) {
6783
6820
  this.sizes.totalWidth = 0;
6784
- var diff = this.sizes.pinnedWidth - (this.sizes.outer.width - firstNonPinnedColumnWidth);
6821
+ var diff = this.sizes.pinnedWidth - (this.sizes.table.width - firstNonPinnedColumnWidth);
6785
6822
  var oldPinnedWidth = this.sizes.pinnedWidth;
6786
6823
  this.sizes.pinnedWidth = 0;
6787
6824
  // let colDiff = diff / this.pinnedColumns
@@ -6818,7 +6855,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6818
6855
  } else {
6819
6856
  this.vScrollRequired = false;
6820
6857
  }
6821
- if (this.sizes.totalWidth > this.sizes.outer.width) {
6858
+ if (this.sizes.totalWidth.toFixed(3) > this.sizes.table.width.toFixed(3)) {
6822
6859
  this.hScrollRequired = true;
6823
6860
  } else {
6824
6861
  this.hScrollRequired = false;
@@ -7207,7 +7244,6 @@ var WebsyTable3 = /*#__PURE__*/function () {
7207
7244
  var vHandleEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
7208
7245
  if (this.vScrollRequired === true) {
7209
7246
  vScrollEl.style.top = "".concat(this.sizes.header.height + this.sizes.total.height, "px");
7210
- // vScrollEl.style.left = `${this.sizes.outer.width - (this.options.isTouchDevice ? this.options.touchScrollWidth : this.options.scrollWidth)}px`
7211
7247
  vScrollEl.style.height = "".concat(this.sizes.bodyHeight, "px");
7212
7248
  if (this.isTouchDevice === true) {
7213
7249
  vScrollEl.style.visibility = "unset";
@@ -7325,6 +7361,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
7325
7361
  }
7326
7362
  }
7327
7363
  cumulativeWidth = 0;
7364
+ var lastColWidth = 0;
7328
7365
  for (var _i10 = this.startCol; _i10 < this.options.allColumns[this.options.allColumns.length - 1].length; _i10++) {
7329
7366
  if (this.options.allColumns[this.options.allColumns.length - 1][_i10].show !== false) {
7330
7367
  cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][_i10].actualWidth;
@@ -7339,9 +7376,19 @@ var WebsyTable3 = /*#__PURE__*/function () {
7339
7376
  if (this.endCol === this.options.allColumns[this.options.allColumns.length - 1].length - 1 && cumulativeWidth > this.sizes.scrollableWidth && actualLeft > 0) {
7340
7377
  this.startCol += 1;
7341
7378
  }
7342
- if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth) {
7343
- this.startCol += 1;
7344
- this.endCol += 1;
7379
+ if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth - lastColWidth) {
7380
+ this.endCol = this.options.allColumns[this.options.allColumns.length - 1].length - 1;
7381
+ this.startCol = this.endCol + 1;
7382
+ // one last measurement
7383
+ var finalAcc = 0;
7384
+ for (var _i11 = this.endCol; _i11 > -1; _i11--) {
7385
+ if (this.options.allColumns[this.options.allColumns.length - 1][_i11].show !== false) {
7386
+ finalAcc += this.options.allColumns[this.options.allColumns.length - 1][_i11].actualWidth;
7387
+ if (finalAcc < this.sizes.scrollableWidth) {
7388
+ this.startCol--;
7389
+ }
7390
+ }
7391
+ }
7345
7392
  }
7346
7393
  this.endCol = Math.max(this.startCol, this.endCol);
7347
7394
  this.options.onScroll('y', this.startRow, this.endRow, this.startCol - this.pinnedColumns, this.endCol - this.pinnedColumns);