@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.
@@ -197,7 +197,8 @@ function ShopRoutes (dbHelper, engine, app) {
197
197
  basket.items = JSON.parse(basket.items)
198
198
  }
199
199
  catch (error) {
200
- console.log('Unable to parse basket')
200
+ console.log(`Unable to parse basket items for ${req.session.user.id}`)
201
+ console.log(`Basket items has a type of ${typeof basket.items}`)
201
202
  console.log(basket.items)
202
203
  }
203
204
  }
@@ -6278,7 +6278,8 @@ class WebsyTable3 {
6278
6278
  disableInternalLoader: false,
6279
6279
  disableTouch: false,
6280
6280
  scrollWidth: 10,
6281
- touchScrollWidth: 30
6281
+ touchScrollWidth: 30,
6282
+ autoFitColumns: true
6282
6283
  }
6283
6284
  this.options = Object.assign({}, DEFAULTS, options)
6284
6285
  this.isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
@@ -6656,7 +6657,7 @@ class WebsyTable3 {
6656
6657
  maxWidth = this.options.maxColWidth
6657
6658
  }
6658
6659
  else if (this.options.maxColWidth.indexOf('%') !== -1) {
6659
- maxWidth = this.sizes.outer.width * (+(this.options.maxColWidth.replace('%', '')) / 100)
6660
+ maxWidth = this.sizes.table.width * (+(this.options.maxColWidth.replace('%', '')) / 100)
6660
6661
  }
6661
6662
  else if (this.options.maxColWidth.indexOf('px') !== -1) {
6662
6663
  maxWidth = +this.options.maxColWidth.replace('px', '')
@@ -6669,7 +6670,7 @@ class WebsyTable3 {
6669
6670
  this.sizes.total = footerEl.getBoundingClientRect()
6670
6671
  const rows = Array.from(tableEl.querySelectorAll('.websy-table-row'))
6671
6672
  let totalWidth = 0
6672
- this.sizes.scrollableWidth = this.sizes.outer.width
6673
+ this.sizes.scrollableWidth = this.sizes.table.width
6673
6674
  let firstNonPinnedColumnWidth = 0
6674
6675
  let columnsForSizing = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
6675
6676
  rows.forEach((row, rowIndex) => {
@@ -6678,8 +6679,10 @@ class WebsyTable3 {
6678
6679
  this.sizes.cellHeight = colSize.height
6679
6680
  if (columnsForSizing[colIndex]) {
6680
6681
  if (!columnsForSizing[colIndex].actualWidth) {
6682
+ columnsForSizing[colIndex].potentialWidth = 0
6681
6683
  columnsForSizing[colIndex].actualWidth = 0
6682
6684
  }
6685
+ columnsForSizing[colIndex].potentialWidth = Math.max(columnsForSizing[colIndex].potentialWidth, colSize.width)
6683
6686
  columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth)
6684
6687
  // if (columnsForSizing[colIndex].width) {
6685
6688
  // columnsForSizing[colIndex].actualWidth = columnsForSizing[colIndex].width
@@ -6699,19 +6702,53 @@ class WebsyTable3 {
6699
6702
  this.sizes.totalWidth = columnsForSizing.reduce((a, b) => a + (b.width || b.actualWidth), 0)
6700
6703
  this.sizes.totalNonPinnedWidth = columnsForSizing.filter((c, i) => i >= this.pinnedColumns).reduce((a, b) => a + (b.width || b.actualWidth), 0)
6701
6704
  this.sizes.pinnedWidth = this.sizes.totalWidth - this.sizes.totalNonPinnedWidth
6702
- // const outerSize = outerEl.getBoundingClientRect()
6703
- if (this.sizes.totalWidth < this.sizes.outer.width) {
6704
- let equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / columnsForSizing.length
6705
+ // const outerSize = outerEl.getBoundingClientRect()
6706
+ if (this.sizes.totalWidth < this.sizes.table.width) {
6707
+ let requiredSpace = 0
6708
+ let availableSpace = (this.sizes.table.width - this.sizes.totalWidth)
6709
+ columnsForSizing.forEach(c => {
6710
+ c.shouldGrow = true
6711
+ if (this.options.autoFitColumns === false) {
6712
+ c.shouldGrow = false
6713
+ if (c.potentialWidth > c.actualWidth) {
6714
+ c.shouldGrow = true
6715
+ c.growDiff = c.potentialWidth - c.actualWidth
6716
+ c.growDiffPerc = (c.potentialWidth - c.actualWidth) / availableSpace
6717
+ requiredSpace += c.growDiff
6718
+ }
6719
+ }
6720
+ })
6721
+ let equalWidth = (this.sizes.table.width - this.sizes.totalWidth) / columnsForSizing.filter(c => c.shouldGrow).length
6705
6722
  this.sizes.totalWidth = 0
6706
6723
  this.sizes.totalNonPinnedWidth = 0
6707
6724
  columnsForSizing.forEach((c, i) => {
6708
6725
  // if (!c.width) {
6709
6726
  // if (c.actualWidth < equalWidth) {
6710
6727
  // adjust the width
6711
- if (c.width) {
6712
- c.width += equalWidth
6728
+ if (this.options.autoFitColumns === true) {
6729
+ if (c.width) {
6730
+ c.width += equalWidth
6731
+ }
6732
+ c.actualWidth += equalWidth
6733
+ }
6734
+ else {
6735
+ if (requiredSpace > 0 && requiredSpace <= availableSpace) {
6736
+ if (c.shouldGrow) {
6737
+ if (c.width) {
6738
+ c.width += c.growDiff
6739
+ }
6740
+ c.actualWidth += c.growDiff
6741
+ }
6742
+ }
6743
+ else {
6744
+ if (c.shouldGrow) {
6745
+ if (c.width) {
6746
+ c.width += availableSpace * (c.growDiff / requiredSpace)
6747
+ }
6748
+ c.actualWidth += availableSpace * (c.growDiff / requiredSpace)
6749
+ }
6750
+ }
6713
6751
  }
6714
- c.actualWidth += equalWidth
6715
6752
  // }
6716
6753
  // }
6717
6754
  this.sizes.totalWidth += c.width || c.actualWidth
@@ -6722,9 +6759,9 @@ class WebsyTable3 {
6722
6759
  })
6723
6760
  }
6724
6761
  // check that we have enough from for all of the pinned columns plus 1 non pinned column
6725
- if (this.sizes.pinnedWidth > (this.sizes.outer.width - firstNonPinnedColumnWidth)) {
6762
+ if (this.sizes.pinnedWidth > (this.sizes.table.width - firstNonPinnedColumnWidth)) {
6726
6763
  this.sizes.totalWidth = 0
6727
- let diff = this.sizes.pinnedWidth - (this.sizes.outer.width - firstNonPinnedColumnWidth)
6764
+ let diff = this.sizes.pinnedWidth - (this.sizes.table.width - firstNonPinnedColumnWidth)
6728
6765
  let oldPinnedWidth = this.sizes.pinnedWidth
6729
6766
  this.sizes.pinnedWidth = 0
6730
6767
  // let colDiff = diff / this.pinnedColumns
@@ -6762,7 +6799,7 @@ class WebsyTable3 {
6762
6799
  else {
6763
6800
  this.vScrollRequired = false
6764
6801
  }
6765
- if (this.sizes.totalWidth > this.sizes.outer.width) {
6802
+ if (this.sizes.totalWidth.toFixed(3) > this.sizes.table.width.toFixed(3)) {
6766
6803
  this.hScrollRequired = true
6767
6804
  }
6768
6805
  else {
@@ -7127,7 +7164,6 @@ class WebsyTable3 {
7127
7164
  let vHandleEl = document.getElementById(`${this.elementId}_vScrollHandle`)
7128
7165
  if (this.vScrollRequired === true) {
7129
7166
  vScrollEl.style.top = `${this.sizes.header.height + this.sizes.total.height}px`
7130
- // vScrollEl.style.left = `${this.sizes.outer.width - (this.options.isTouchDevice ? this.options.touchScrollWidth : this.options.scrollWidth)}px`
7131
7167
  vScrollEl.style.height = `${this.sizes.bodyHeight}px`
7132
7168
  if (this.isTouchDevice === true) {
7133
7169
  vScrollEl.style.visibility = `unset`
@@ -7240,7 +7276,8 @@ class WebsyTable3 {
7240
7276
  }
7241
7277
  }
7242
7278
  }
7243
- cumulativeWidth = 0
7279
+ cumulativeWidth = 0
7280
+ let lastColWidth = 0
7244
7281
  for (let i = this.startCol; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
7245
7282
  if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
7246
7283
  cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
@@ -7255,9 +7292,22 @@ class WebsyTable3 {
7255
7292
  if (this.endCol === this.options.allColumns[this.options.allColumns.length - 1].length - 1 && cumulativeWidth > this.sizes.scrollableWidth && actualLeft > 0) {
7256
7293
  this.startCol += 1
7257
7294
  }
7258
- if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth) {
7259
- this.startCol += 1
7260
- this.endCol += 1
7295
+ if (
7296
+ scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >=
7297
+ scrollContainerEl.offsetWidth - lastColWidth
7298
+ ) {
7299
+ this.endCol = this.options.allColumns[this.options.allColumns.length - 1].length - 1
7300
+ this.startCol = this.endCol + 1
7301
+ // one last measurement
7302
+ let finalAcc = 0
7303
+ for (let i = this.endCol; i > -1; i--) {
7304
+ if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
7305
+ finalAcc += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
7306
+ if (finalAcc < this.sizes.scrollableWidth) {
7307
+ this.startCol--
7308
+ }
7309
+ }
7310
+ }
7261
7311
  }
7262
7312
  this.endCol = Math.max(this.startCol, this.endCol)
7263
7313
  this.options.onScroll('y', this.startRow, this.endRow, this.startCol - this.pinnedColumns, this.endCol - this.pinnedColumns)
@@ -5999,7 +5999,8 @@ var WebsyTable3 = /*#__PURE__*/function () {
5999
5999
  disableInternalLoader: false,
6000
6000
  disableTouch: false,
6001
6001
  scrollWidth: 10,
6002
- touchScrollWidth: 30
6002
+ touchScrollWidth: 30,
6003
+ autoFitColumns: true
6003
6004
  };
6004
6005
  this.options = _extends({}, DEFAULTS, options);
6005
6006
  this.isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
@@ -6313,7 +6314,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6313
6314
  if (typeof this.options.maxColWidth === 'number') {
6314
6315
  maxWidth = this.options.maxColWidth;
6315
6316
  } else if (this.options.maxColWidth.indexOf('%') !== -1) {
6316
- maxWidth = this.sizes.outer.width * (+this.options.maxColWidth.replace('%', '') / 100);
6317
+ maxWidth = this.sizes.table.width * (+this.options.maxColWidth.replace('%', '') / 100);
6317
6318
  } else if (this.options.maxColWidth.indexOf('px') !== -1) {
6318
6319
  maxWidth = +this.options.maxColWidth.replace('px', '');
6319
6320
  }
@@ -6325,7 +6326,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6325
6326
  this.sizes.total = footerEl.getBoundingClientRect();
6326
6327
  var rows = Array.from(tableEl.querySelectorAll('.websy-table-row'));
6327
6328
  var totalWidth = 0;
6328
- this.sizes.scrollableWidth = this.sizes.outer.width;
6329
+ this.sizes.scrollableWidth = this.sizes.table.width;
6329
6330
  var firstNonPinnedColumnWidth = 0;
6330
6331
  var columnsForSizing = this.options.columns[this.options.columns.length - 1].filter(function (c) {
6331
6332
  return c.show !== false;
@@ -6336,8 +6337,10 @@ var WebsyTable3 = /*#__PURE__*/function () {
6336
6337
  _this43.sizes.cellHeight = colSize.height;
6337
6338
  if (columnsForSizing[colIndex]) {
6338
6339
  if (!columnsForSizing[colIndex].actualWidth) {
6340
+ columnsForSizing[colIndex].potentialWidth = 0;
6339
6341
  columnsForSizing[colIndex].actualWidth = 0;
6340
6342
  }
6343
+ columnsForSizing[colIndex].potentialWidth = Math.max(columnsForSizing[colIndex].potentialWidth, colSize.width);
6341
6344
  columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth);
6342
6345
  // if (columnsForSizing[colIndex].width) {
6343
6346
  // columnsForSizing[colIndex].actualWidth = columnsForSizing[colIndex].width
@@ -6363,19 +6366,53 @@ var WebsyTable3 = /*#__PURE__*/function () {
6363
6366
  return a + (b.width || b.actualWidth);
6364
6367
  }, 0);
6365
6368
  this.sizes.pinnedWidth = this.sizes.totalWidth - this.sizes.totalNonPinnedWidth;
6366
- // const outerSize = outerEl.getBoundingClientRect()
6367
- if (this.sizes.totalWidth < this.sizes.outer.width) {
6368
- var equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / columnsForSizing.length;
6369
+ // const outerSize = outerEl.getBoundingClientRect()
6370
+ if (this.sizes.totalWidth < this.sizes.table.width) {
6371
+ var requiredSpace = 0;
6372
+ var availableSpace = this.sizes.table.width - this.sizes.totalWidth;
6373
+ columnsForSizing.forEach(function (c) {
6374
+ c.shouldGrow = true;
6375
+ if (_this43.options.autoFitColumns === false) {
6376
+ c.shouldGrow = false;
6377
+ if (c.potentialWidth > c.actualWidth) {
6378
+ c.shouldGrow = true;
6379
+ c.growDiff = c.potentialWidth - c.actualWidth;
6380
+ c.growDiffPerc = (c.potentialWidth - c.actualWidth) / availableSpace;
6381
+ requiredSpace += c.growDiff;
6382
+ }
6383
+ }
6384
+ });
6385
+ var equalWidth = (this.sizes.table.width - this.sizes.totalWidth) / columnsForSizing.filter(function (c) {
6386
+ return c.shouldGrow;
6387
+ }).length;
6369
6388
  this.sizes.totalWidth = 0;
6370
6389
  this.sizes.totalNonPinnedWidth = 0;
6371
6390
  columnsForSizing.forEach(function (c, i) {
6372
6391
  // if (!c.width) {
6373
6392
  // if (c.actualWidth < equalWidth) {
6374
6393
  // adjust the width
6375
- if (c.width) {
6376
- c.width += equalWidth;
6394
+ if (_this43.options.autoFitColumns === true) {
6395
+ if (c.width) {
6396
+ c.width += equalWidth;
6397
+ }
6398
+ c.actualWidth += equalWidth;
6399
+ } else {
6400
+ if (requiredSpace > 0 && requiredSpace <= availableSpace) {
6401
+ if (c.shouldGrow) {
6402
+ if (c.width) {
6403
+ c.width += c.growDiff;
6404
+ }
6405
+ c.actualWidth += c.growDiff;
6406
+ }
6407
+ } else {
6408
+ if (c.shouldGrow) {
6409
+ if (c.width) {
6410
+ c.width += availableSpace * (c.growDiff / requiredSpace);
6411
+ }
6412
+ c.actualWidth += availableSpace * (c.growDiff / requiredSpace);
6413
+ }
6414
+ }
6377
6415
  }
6378
- c.actualWidth += equalWidth;
6379
6416
  // }
6380
6417
  // }
6381
6418
  _this43.sizes.totalWidth += c.width || c.actualWidth;
@@ -6386,9 +6423,9 @@ var WebsyTable3 = /*#__PURE__*/function () {
6386
6423
  });
6387
6424
  }
6388
6425
  // check that we have enough from for all of the pinned columns plus 1 non pinned column
6389
- if (this.sizes.pinnedWidth > this.sizes.outer.width - firstNonPinnedColumnWidth) {
6426
+ if (this.sizes.pinnedWidth > this.sizes.table.width - firstNonPinnedColumnWidth) {
6390
6427
  this.sizes.totalWidth = 0;
6391
- var diff = this.sizes.pinnedWidth - (this.sizes.outer.width - firstNonPinnedColumnWidth);
6428
+ var diff = this.sizes.pinnedWidth - (this.sizes.table.width - firstNonPinnedColumnWidth);
6392
6429
  var oldPinnedWidth = this.sizes.pinnedWidth;
6393
6430
  this.sizes.pinnedWidth = 0;
6394
6431
  // let colDiff = diff / this.pinnedColumns
@@ -6425,7 +6462,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6425
6462
  } else {
6426
6463
  this.vScrollRequired = false;
6427
6464
  }
6428
- if (this.sizes.totalWidth > this.sizes.outer.width) {
6465
+ if (this.sizes.totalWidth.toFixed(3) > this.sizes.table.width.toFixed(3)) {
6429
6466
  this.hScrollRequired = true;
6430
6467
  } else {
6431
6468
  this.hScrollRequired = false;
@@ -6814,7 +6851,6 @@ var WebsyTable3 = /*#__PURE__*/function () {
6814
6851
  var vHandleEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
6815
6852
  if (this.vScrollRequired === true) {
6816
6853
  vScrollEl.style.top = "".concat(this.sizes.header.height + this.sizes.total.height, "px");
6817
- // vScrollEl.style.left = `${this.sizes.outer.width - (this.options.isTouchDevice ? this.options.touchScrollWidth : this.options.scrollWidth)}px`
6818
6854
  vScrollEl.style.height = "".concat(this.sizes.bodyHeight, "px");
6819
6855
  if (this.isTouchDevice === true) {
6820
6856
  vScrollEl.style.visibility = "unset";
@@ -6932,6 +6968,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
6932
6968
  }
6933
6969
  }
6934
6970
  cumulativeWidth = 0;
6971
+ var lastColWidth = 0;
6935
6972
  for (var _i10 = this.startCol; _i10 < this.options.allColumns[this.options.allColumns.length - 1].length; _i10++) {
6936
6973
  if (this.options.allColumns[this.options.allColumns.length - 1][_i10].show !== false) {
6937
6974
  cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][_i10].actualWidth;
@@ -6946,9 +6983,19 @@ var WebsyTable3 = /*#__PURE__*/function () {
6946
6983
  if (this.endCol === this.options.allColumns[this.options.allColumns.length - 1].length - 1 && cumulativeWidth > this.sizes.scrollableWidth && actualLeft > 0) {
6947
6984
  this.startCol += 1;
6948
6985
  }
6949
- if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth) {
6950
- this.startCol += 1;
6951
- this.endCol += 1;
6986
+ if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth - lastColWidth) {
6987
+ this.endCol = this.options.allColumns[this.options.allColumns.length - 1].length - 1;
6988
+ this.startCol = this.endCol + 1;
6989
+ // one last measurement
6990
+ var finalAcc = 0;
6991
+ for (var _i11 = this.endCol; _i11 > -1; _i11--) {
6992
+ if (this.options.allColumns[this.options.allColumns.length - 1][_i11].show !== false) {
6993
+ finalAcc += this.options.allColumns[this.options.allColumns.length - 1][_i11].actualWidth;
6994
+ if (finalAcc < this.sizes.scrollableWidth) {
6995
+ this.startCol--;
6996
+ }
6997
+ }
6998
+ }
6952
6999
  }
6953
7000
  this.endCol = Math.max(this.startCol, this.endCol);
6954
7001
  this.options.onScroll('y', this.startRow, this.endRow, this.startCol - this.pinnedColumns, this.endCol - this.pinnedColumns);