@websy/websy-designs 1.6.3 → 1.7.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.
@@ -120,8 +120,9 @@ class AuthHelper {
120
120
  }
121
121
  })
122
122
  }
123
- isLoggedIn (req, res, next) {
124
- if (req.session && req.session.user && !req.session.user.isAnonymous) {
123
+ isLoggedIn (req, res, next) {
124
+ console.log(req.session)
125
+ if (req.session && req.session.user && req.session.user.isAnonymous !== true) {
125
126
  console.log('in condition D')
126
127
  next()
127
128
  }
@@ -1864,7 +1864,13 @@ class WebsyDropdown {
1864
1864
  }
1865
1865
  this.updateHeader(item)
1866
1866
  }
1867
- setValue (value) {
1867
+ get value () {
1868
+ if (this.selectedItems && this.selectedItems.length > 0) {
1869
+ return this.selectedItems.map((d, i) => this.options.items[+d])
1870
+ }
1871
+ return []
1872
+ }
1873
+ set value (value) {
1868
1874
  this.selectedItems = []
1869
1875
  if (Array.isArray(value)) {
1870
1876
  this.options.items.forEach(d => {
@@ -1976,6 +1982,9 @@ class WebsyDropdown {
1976
1982
  if (item && this.options.onItemSelected) {
1977
1983
  this.options.onItemSelected(item, this.selectedItems, dataToUse, this.options)
1978
1984
  }
1985
+ if (this.options.onChange) {
1986
+ this.options.onChange(this)
1987
+ }
1979
1988
  if (this.options.closeAfterSelection === true) {
1980
1989
  this.close()
1981
1990
  }
@@ -2011,7 +2020,9 @@ class WebsyForm {
2011
2020
  // if (this.options.classes) {
2012
2021
  // this.options.classes.forEach(c => el.classList.add(c))
2013
2022
  // }
2023
+ el.addEventListener('change', this.handleChange.bind(this))
2014
2024
  el.addEventListener('click', this.handleClick.bind(this))
2025
+ el.addEventListener('focusout', this.handleFocusOut.bind(this))
2015
2026
  el.addEventListener('keyup', this.handleKeyUp.bind(this))
2016
2027
  el.addEventListener('keydown', this.handleKeyDown.bind(this))
2017
2028
  this.render()
@@ -2067,15 +2078,18 @@ class WebsyForm {
2067
2078
  this.options.fields = []
2068
2079
  }
2069
2080
  for (let key in d) {
2070
- this.options.fields.forEach(f => {
2081
+ this.options.fields.forEach(f => {
2071
2082
  if (f.field === key) {
2072
- f.value = d[key]
2073
- const el = document.getElementById(`${this.elementId}_input_${f.field}`)
2074
- el.value = f.value
2083
+ this.setValue(key, d[key])
2084
+ // f.value = d[key]
2085
+ // const el = document.getElementById(`${this.elementId}_input_${f.field}`)
2086
+ // if (el) {
2087
+ // el.value = f.value
2088
+ // }
2075
2089
  }
2076
2090
  })
2077
2091
  }
2078
- this.render()
2092
+ // this.render()
2079
2093
  }
2080
2094
  confirmValidation () {
2081
2095
  const el = document.getElementById(`${this.elementId}_validationFail`)
@@ -2089,6 +2103,20 @@ class WebsyForm {
2089
2103
  el.innerHTML = msg
2090
2104
  }
2091
2105
  }
2106
+ handleChange (event) {
2107
+ if (event.target.getAttribute('data-user-type') === 'expiry') {
2108
+ if (event.target.value.length === 7) {
2109
+ let value = event.target.value.split('/')
2110
+ event.target.value = `${value[0]}/${value[1].substring(2, 4)}`
2111
+ }
2112
+ }
2113
+ if (event.target.classList.contains('websy-input')) {
2114
+ let index = event.target.getAttribute('data-index')
2115
+ if (this.options.fields[index] && (this.options.fields[index].required || this.options.fields[index].validate)) {
2116
+ this.validateField(this.options.fields[index], event.target.value)
2117
+ }
2118
+ }
2119
+ }
2092
2120
  handleClick (event) {
2093
2121
  if (event.target.classList.contains('submit')) {
2094
2122
  event.preventDefault()
@@ -2099,13 +2127,68 @@ class WebsyForm {
2099
2127
  this.cancelForm()
2100
2128
  }
2101
2129
  }
2130
+ handleFocusOut (event) {
2131
+ if (event.target.classList.contains('websy-input')) {
2132
+ let index = event.target.getAttribute('data-index')
2133
+ if (this.options.fields[index] && (this.options.fields[index].required || this.options.fields[index].validate)) {
2134
+ this.validateField(this.options.fields[index], event.target.value)
2135
+ }
2136
+ }
2137
+ }
2102
2138
  handleKeyDown (event) {
2103
2139
  if (event.key === 'enter') {
2104
2140
  this.submitForm()
2105
2141
  }
2142
+ if (event.target.getAttribute('data-user-type') === 'expiry') {
2143
+ let isNumeric = !isNaN(event.key)
2144
+ let validKey = false
2145
+ if (!validKey) {
2146
+ validKey = ['ArrowLeft', 'ArrowRight', 'Backspace', 'Delete', 'Tab'].indexOf(event.key) !== -1
2147
+ }
2148
+ if ((event.target.value.length === 5 && !validKey) || (!validKey && !isNumeric)) {
2149
+ event.preventDefault()
2150
+ return false
2151
+ }
2152
+ if (event.key === 'Backspace') {
2153
+ if (event.target.value.indexOf('/') === event.target.selectionStart - 1) {
2154
+ let chars = event.target.value.split('')
2155
+ chars.pop()
2156
+ event.target.value = chars.join('')
2157
+ }
2158
+ }
2159
+ }
2160
+ if (event.target.getAttribute('data-user-type') === 'cvv') {
2161
+ let isNumeric = !isNaN(event.key)
2162
+ let validKey = false
2163
+ if (!validKey) {
2164
+ validKey = ['ArrowLeft', 'ArrowRight', 'Backspace', 'Delete', 'Tab'].indexOf(event.key) !== -1
2165
+ }
2166
+ if ((event.target.value.length === 3 && !validKey) || (!validKey && !isNumeric)) {
2167
+ event.preventDefault()
2168
+ return false
2169
+ }
2170
+ }
2106
2171
  }
2107
2172
  handleKeyUp (event) {
2108
-
2173
+ if (event.target.getAttribute('data-user-type') === 'expiry') {
2174
+ let chars = event.target.value.split('')
2175
+ let isNumeric = !isNaN(event.key)
2176
+ if (event.key === 'Backspace') {
2177
+ if (chars[chars.length - 1] === '/' && chars.length !== 3) {
2178
+ chars.pop()
2179
+ event.target.value = chars.join('')
2180
+ return
2181
+ }
2182
+ }
2183
+ if (event.target.selectionStart === 2) {
2184
+ if (chars[2] && ['ArrowLeft', 'ArrowRight', 'Backspace', 'Delete'].indexOf(event.key) === -1) {
2185
+ event.target.setSelectionRange(3, 3)
2186
+ }
2187
+ else if (isNumeric) {
2188
+ event.target.value += '/'
2189
+ }
2190
+ }
2191
+ }
2109
2192
  }
2110
2193
  processComponents (components, callbackFn) {
2111
2194
  if (components.length === 0) {
@@ -2114,6 +2197,13 @@ class WebsyForm {
2114
2197
  else {
2115
2198
  components.forEach(c => {
2116
2199
  if (typeof WebsyDesigns[c.component] !== 'undefined') {
2200
+ if (!c.options.onChange) {
2201
+ c.options.onChange = () => {
2202
+ if (c.required || c.validate) {
2203
+ this.validateField(c, c.instance.value)
2204
+ }
2205
+ }
2206
+ }
2117
2207
  c.instance = new WebsyDesigns[c.component](`${this.elementId}_input_${c.field}_component`, c.options)
2118
2208
  }
2119
2209
  else {
@@ -2145,35 +2235,41 @@ class WebsyForm {
2145
2235
  if (f.component) {
2146
2236
  componentsToProcess.push(f)
2147
2237
  html += `
2148
- ${i > 0 ? '-->' : ''}<div class='${f.classes || ''}'>
2149
- ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}
2238
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes || ''}'>
2239
+ ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2150
2240
  <div id='${this.elementId}_input_${f.field}_component' class='form-component'></div>
2241
+ <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
2151
2242
  </div><!--
2152
2243
  `
2153
2244
  }
2154
2245
  else if (f.type === 'longtext') {
2155
2246
  html += `
2156
- ${i > 0 ? '-->' : ''}<div class='${f.classes || ''}'>
2157
- ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}
2247
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes || ''}'>
2248
+ ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2158
2249
  <textarea
2159
2250
  id="${this.elementId}_input_${f.field}"
2160
2251
  ${f.required === true ? 'required' : ''}
2161
2252
  placeholder="${f.placeholder || ''}"
2253
+ data-user-type="${f.type}"
2254
+ data-index="${i}"
2162
2255
  name="${f.field}"
2163
2256
  ${(f.attributes || []).join(' ')}
2164
2257
  class="websy-input websy-textarea"
2165
2258
  ></textarea>
2259
+ <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
2166
2260
  </div><!--
2167
2261
  `
2168
2262
  }
2169
2263
  else {
2170
2264
  html += `
2171
- ${i > 0 ? '-->' : ''}<div class='${f.classes || ''}'>
2172
- ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}
2265
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes || ''}'>
2266
+ ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2173
2267
  <input
2174
2268
  id="${this.elementId}_input_${f.field}"
2175
2269
  ${f.required === true ? 'required' : ''}
2176
- type="${f.type || 'text'}"
2270
+ type="${(f.type === 'expiry' ? 'text' : f.type === 'cvv' ? 'number' : f.type) || 'text'}"
2271
+ data-user-type="${f.type}"
2272
+ data-index="${i}"
2177
2273
  class="websy-input"
2178
2274
  ${(f.attributes || []).join(' ')}
2179
2275
  name="${f.field}"
@@ -2182,6 +2278,7 @@ class WebsyForm {
2182
2278
  valueAsDate="${f.type === 'date' ? f.value : ''}"
2183
2279
  oninvalidx="this.setCustomValidity('${f.invalidMessage || 'Please fill in this field.'}')"
2184
2280
  />
2281
+ <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
2185
2282
  </div><!--
2186
2283
  `
2187
2284
  }
@@ -2215,7 +2312,7 @@ class WebsyForm {
2215
2312
  setValue (field, value) {
2216
2313
  if (this.fieldMap[field]) {
2217
2314
  if (this.fieldMap[field].instance) {
2218
- this.fieldMap[field].instance.setValue(value)
2315
+ this.fieldMap[field].instance.value = value
2219
2316
  }
2220
2317
  else {
2221
2318
  const el = document.getElementById(`${this.elementId}_input_${field}`)
@@ -2235,7 +2332,10 @@ class WebsyForm {
2235
2332
  const formEl = document.getElementById(`${this.elementId}Form`)
2236
2333
  const buttonEl = formEl.querySelector('button.websy-btn.submit')
2237
2334
  const recaptchErrEl = document.getElementById(`${this.elementId}_recaptchaError`)
2238
- if (formEl.reportValidity() === true) {
2335
+ if (this.options.preSubmitFn && this.options.preSubmitFn() === false) {
2336
+ return
2337
+ }
2338
+ if (this.validateForm() === true) {
2239
2339
  if (buttonEl) {
2240
2340
  buttonEl.setAttribute('disabled', true)
2241
2341
  }
@@ -2293,6 +2393,59 @@ class WebsyForm {
2293
2393
  })
2294
2394
  }
2295
2395
  }
2396
+ validateForm () {
2397
+ let valid = true
2398
+ let data = this.data
2399
+ for (let i = 0; i < this.options.fields.length; i++) {
2400
+ if (this.options.fields[i].required || this.options.fields[i].validate) {
2401
+ if (this.validateField(this.options.fields[i], data[this.options.fields[i].field]) === false) {
2402
+ valid = false
2403
+ }
2404
+ }
2405
+ }
2406
+ return valid
2407
+ }
2408
+ validateField (field, value) {
2409
+ const inputContainerEl = document.getElementById(`${this.elementId}_${field.field}_inputContainer`)
2410
+ const errorEl = document.getElementById(`${this.elementId}_${field.field}_error`)
2411
+ if (field.required) {
2412
+ let valid = true
2413
+ if (field.component && field.instance && field.instance.value) {
2414
+ valid = field.instance.value.length > 0
2415
+ }
2416
+ else {
2417
+ valid = !(typeof value === 'undefined' || value === '')
2418
+ }
2419
+ if (!valid) {
2420
+ if (errorEl) {
2421
+ errorEl.innerHTML = field.invalidMessage || 'A value is required'
2422
+ }
2423
+ if (inputContainerEl) {
2424
+ inputContainerEl.classList.add('websy-form-input-has-error')
2425
+ }
2426
+ return false
2427
+ }
2428
+ }
2429
+ if (field.validate) {
2430
+ let valid = field.validate(field, value)
2431
+ if (!valid) {
2432
+ if (errorEl) {
2433
+ errorEl.innerHTML = field.invalidMessage || 'A value is required'
2434
+ }
2435
+ if (inputContainerEl) {
2436
+ inputContainerEl.classList.add('websy-form-input-has-error')
2437
+ }
2438
+ return false
2439
+ }
2440
+ }
2441
+ if (errorEl) {
2442
+ errorEl.innerHTML = ''
2443
+ }
2444
+ if (inputContainerEl) {
2445
+ inputContainerEl.classList.remove('websy-form-input-has-error')
2446
+ }
2447
+ return true
2448
+ }
2296
2449
  validateRecaptcha (token) {
2297
2450
  this.recaptchaValue = token
2298
2451
  }
@@ -2485,24 +2638,26 @@ class WebsyLoadingDialog {
2485
2638
  return
2486
2639
  }
2487
2640
  const el = document.getElementById(this.elementId)
2488
- let html = `
2489
- <div class='websy-loading-container ${(this.options.classes || []).join(' ')}'>
2490
- <div class='websy-ripple'>
2491
- <div></div>
2492
- <div></div>
2493
- </div>
2494
- <h4>${this.options.title || 'Loading...'}</h4>
2495
- `
2496
- if (this.options.messages) {
2497
- for (let i = 0; i < this.options.messages.length; i++) {
2498
- html += `<p>${this.options.messages[i]}</p>`
2499
- }
2500
- }
2501
- html += `
2502
- </div>
2503
- `
2504
- el.classList.add('loading')
2505
- el.innerHTML = html
2641
+ if (el) {
2642
+ let html = `
2643
+ <div class='websy-loading-container ${(this.options.classes || []).join(' ')}'>
2644
+ <div class='websy-ripple'>
2645
+ <div></div>
2646
+ <div></div>
2647
+ </div>
2648
+ <h4>${this.options.title || 'Loading...'}</h4>
2649
+ `
2650
+ if (this.options.messages) {
2651
+ for (let i = 0; i < this.options.messages.length; i++) {
2652
+ html += `<p>${this.options.messages[i]}</p>`
2653
+ }
2654
+ }
2655
+ html += `
2656
+ </div>
2657
+ `
2658
+ el.classList.add('loading')
2659
+ el.innerHTML = html
2660
+ }
2506
2661
  }
2507
2662
  show (options, override = false) {
2508
2663
  if (options) {
@@ -3853,6 +4008,7 @@ class WebsyRouter {
3853
4008
  output.items = Object.assign({}, params)
3854
4009
  path = this.buildUrlPath(output.items)
3855
4010
  }
4011
+ output.path = path
3856
4012
  this.currentParams = output
3857
4013
  let inputPath = this.currentView
3858
4014
  if (this.options.urlPrefix) {
@@ -3865,13 +4021,13 @@ class WebsyRouter {
3865
4021
  // this.showView(this.currentView, this.currentParams, 'main')
3866
4022
  this.navigate(`${inputPath}?${path}`, 'main', null, noHistory)
3867
4023
  }
4024
+ else {
4025
+ this.updateHistory(inputPath, !noHistory, true)
4026
+ }
3868
4027
  }
3869
4028
  removeUrlParams (params = [], reloadView = false, noHistory = true) {
3870
4029
  this.previousParams = Object.assign({}, this.currentParams)
3871
- const output = {
3872
- path: '',
3873
- items: {}
3874
- }
4030
+
3875
4031
  let path = ''
3876
4032
  if (this.currentParams && this.currentParams.items) {
3877
4033
  params.forEach(p => {
@@ -3887,6 +4043,13 @@ class WebsyRouter {
3887
4043
  // this.showView(this.currentView, this.currentParams, 'main')
3888
4044
  this.navigate(`${inputPath}?${path}`, 'main', null, noHistory)
3889
4045
  }
4046
+ else if (noHistory === false) {
4047
+ this.currentParams = {
4048
+ items: this.currentParams.items,
4049
+ path
4050
+ }
4051
+ this.updateHistory(inputPath, !noHistory, true)
4052
+ }
3890
4053
  }
3891
4054
  removeAllUrlParams (reloadView = false, noHistory = true) {
3892
4055
  // const output = {
@@ -3901,14 +4064,12 @@ class WebsyRouter {
3901
4064
  this.currentParams = {
3902
4065
  path: '',
3903
4066
  items: {}
3904
- }
4067
+ }
3905
4068
  if (reloadView === true) {
3906
4069
  this.navigate(`${inputPath}`, 'main', null, noHistory)
3907
4070
  }
3908
4071
  else {
3909
- history.replaceState({
3910
- inputPath
3911
- }, 'unused', inputPath)
4072
+ this.updateHistory(inputPath, !noHistory, true)
3912
4073
  }
3913
4074
  }
3914
4075
  buildUrlPath (params) {
@@ -4310,28 +4471,7 @@ class WebsyRouter {
4310
4471
  }
4311
4472
  if ((this.currentPath !== inputPath || previousParamsPath !== this.currentParams.path) && group === this.options.defaultGroup) {
4312
4473
  let historyUrl = inputPath
4313
- if (this.options.urlPrefix) {
4314
- historyUrl = historyUrl === '/' ? '' : `/${historyUrl}`
4315
- inputPath = inputPath === '/' ? '' : `/${inputPath}`
4316
- historyUrl = (`/${this.options.urlPrefix}${historyUrl}`).replace(/\/\//g, '/')
4317
- inputPath = (`/${this.options.urlPrefix}${inputPath}`).replace(/\/\//g, '/')
4318
- }
4319
- if (this.currentParams && this.currentParams.path) {
4320
- historyUrl += `?${this.currentParams.path}`
4321
- }
4322
- else if (this.queryParams && this.options.persistentParameters === true) {
4323
- historyUrl += `?${this.queryParams}`
4324
- }
4325
- if (popped === false) {
4326
- history.pushState({
4327
- inputPath: historyUrl
4328
- }, 'unused', historyUrl)
4329
- }
4330
- else {
4331
- history.replaceState({
4332
- inputPath: historyUrl
4333
- }, 'unused', historyUrl)
4334
- }
4474
+ this.updateHistory(historyUrl, popped)
4335
4475
  }
4336
4476
  if (toggle === false) {
4337
4477
  this.showView(newPath.split('?')[0], this.currentParams, group)
@@ -4366,6 +4506,28 @@ class WebsyRouter {
4366
4506
  item.apply(null, params)
4367
4507
  })
4368
4508
  }
4509
+ updateHistory (historyUrl, replaceState = false, overridePersistent = false) {
4510
+ if (this.options.urlPrefix) {
4511
+ historyUrl = historyUrl === '/' ? '' : `/${historyUrl}`
4512
+ historyUrl = (`/${this.options.urlPrefix}${historyUrl}`).replace(/\/\//g, '/')
4513
+ }
4514
+ if ((this.currentParams && this.currentParams.path) || overridePersistent === true) {
4515
+ historyUrl += `?${this.currentParams.path}`
4516
+ }
4517
+ else if (this.queryParams && this.options.persistentParameters === true) {
4518
+ historyUrl += `?${this.queryParams}`
4519
+ }
4520
+ if (replaceState === false) {
4521
+ history.pushState({
4522
+ inputPath: historyUrl
4523
+ }, 'unused', historyUrl)
4524
+ }
4525
+ else {
4526
+ history.replaceState({
4527
+ inputPath: historyUrl
4528
+ }, 'unused', historyUrl)
4529
+ }
4530
+ }
4369
4531
  subscribe (event, fn) {
4370
4532
  this.options.subscribers[event].push(fn)
4371
4533
  }
@@ -5905,7 +6067,7 @@ class WebsyTable3 {
5905
6067
  return ''
5906
6068
  }
5907
6069
  let bodyHtml = ``
5908
- let sizingColumns = this.options.columns[this.options.columns.length - 1]
6070
+ let sizingColumns = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
5909
6071
  if (useWidths === true) {
5910
6072
  bodyHtml += '<colgroup>'
5911
6073
  bodyHtml += sizingColumns.map(c => `
@@ -5917,9 +6079,9 @@ class WebsyTable3 {
5917
6079
  }
5918
6080
  data.forEach((row, rowIndex) => {
5919
6081
  bodyHtml += `<tr class="websy-table-row">`
5920
- row.forEach((cell, cellIndex) => {
6082
+ row.forEach((cell, cellIndex) => {
5921
6083
  let sizeIndex = cell.level || cellIndex
5922
- if (typeof sizingColumns[sizeIndex] === 'undefined') {
6084
+ if (typeof sizingColumns[sizeIndex] === 'undefined' || sizingColumns[sizeIndex].show === false) {
5923
6085
  return // need to revisit this logic
5924
6086
  }
5925
6087
  let style = ''
@@ -6016,7 +6178,7 @@ class WebsyTable3 {
6016
6178
  return ''
6017
6179
  }
6018
6180
  let headerHtml = ''
6019
- let sizingColumns = this.options.columns[this.options.columns.length - 1]
6181
+ let sizingColumns = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
6020
6182
  if (useWidths === true) {
6021
6183
  headerHtml += '<colgroup>'
6022
6184
  headerHtml += sizingColumns.map(c => `
@@ -6032,7 +6194,10 @@ class WebsyTable3 {
6032
6194
  return
6033
6195
  }
6034
6196
  headerHtml += `<tr class="websy-table-row websy-table-header-row">`
6035
- row.forEach((col, colIndex) => {
6197
+ row.filter(c => c.show !== false).forEach((col, colIndex) => {
6198
+ if (typeof sizingColumns[colIndex] === 'undefined' || sizingColumns[colIndex].show === false) {
6199
+ return // need to revisit this logic
6200
+ }
6036
6201
  let style = `width: ${sizingColumns[colIndex].width || sizingColumns[colIndex].actualWidth}px!important; `
6037
6202
  let divStyle = style
6038
6203
  if (useWidths === true) {
@@ -6096,8 +6261,12 @@ class WebsyTable3 {
6096
6261
  if (!this.options.totals) {
6097
6262
  return ''
6098
6263
  }
6264
+ let sizingColumns = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
6099
6265
  let totalHtml = `<tr class="websy-table-row websy-table-total-row">`
6100
6266
  this.options.totals.forEach((col, colIndex) => {
6267
+ if (typeof sizingColumns[colIndex] === 'undefined' || sizingColumns[colIndex].show === false) {
6268
+ return // need to revisit this logic
6269
+ }
6101
6270
  totalHtml += `<td
6102
6271
  class='websy-table-cell ${(col.classes || []).join(' ')}'
6103
6272
  colspan='${col.colspan || 1}'
@@ -6153,36 +6322,37 @@ class WebsyTable3 {
6153
6322
  let totalWidth = 0
6154
6323
  this.sizes.scrollableWidth = this.sizes.outer.width
6155
6324
  let firstNonPinnedColumnWidth = 0
6325
+ let columnsForSizing = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
6156
6326
  rows.forEach((row, rowIndex) => {
6157
6327
  Array.from(row.children).forEach((col, colIndex) => {
6158
6328
  let colSize = col.getBoundingClientRect()
6159
6329
  this.sizes.cellHeight = colSize.height
6160
- if (this.options.columns[this.options.columns.length - 1][colIndex]) {
6161
- if (!this.options.columns[this.options.columns.length - 1][colIndex].actualWidth) {
6162
- this.options.columns[this.options.columns.length - 1][colIndex].actualWidth = 0
6330
+ if (columnsForSizing[colIndex]) {
6331
+ if (!columnsForSizing[colIndex].actualWidth) {
6332
+ columnsForSizing[colIndex].actualWidth = 0
6163
6333
  }
6164
- this.options.columns[this.options.columns.length - 1][colIndex].actualWidth = Math.min(Math.max(this.options.columns[this.options.columns.length - 1][colIndex].actualWidth, colSize.width), maxWidth)
6165
- this.options.columns[this.options.columns.length - 1][colIndex].cellHeight = colSize.height
6334
+ columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth)
6335
+ columnsForSizing[colIndex].cellHeight = colSize.height
6166
6336
  if (colIndex >= this.pinnedColumns) {
6167
- firstNonPinnedColumnWidth = this.options.columns[this.options.columns.length - 1][colIndex].actualWidth
6337
+ firstNonPinnedColumnWidth = columnsForSizing[colIndex].actualWidth
6168
6338
  }
6169
6339
  }
6170
6340
  })
6171
6341
  })
6172
- this.options.columns[this.options.columns.length - 1].forEach((col, colIndex) => {
6173
- if (colIndex < this.pinnedColumns) {
6174
- this.sizes.scrollableWidth -= col.actualWidth
6175
- }
6176
- })
6177
- this.sizes.totalWidth = this.options.columns[this.options.columns.length - 1].reduce((a, b) => a + (b.width || b.actualWidth), 0)
6178
- this.sizes.totalNonPinnedWidth = this.options.columns[this.options.columns.length - 1].filter((c, i) => i >= this.pinnedColumns).reduce((a, b) => a + (b.width || b.actualWidth), 0)
6342
+ // columnsForSizing.forEach((col, colIndex) => {
6343
+ // if (colIndex < this.pinnedColumns) {
6344
+ // this.sizes.scrollableWidth -= col.actualWidth
6345
+ // }
6346
+ // })
6347
+ this.sizes.totalWidth = columnsForSizing.reduce((a, b) => a + (b.width || b.actualWidth), 0)
6348
+ this.sizes.totalNonPinnedWidth = columnsForSizing.filter((c, i) => i >= this.pinnedColumns).reduce((a, b) => a + (b.width || b.actualWidth), 0)
6179
6349
  this.sizes.pinnedWidth = this.sizes.totalWidth - this.sizes.totalNonPinnedWidth
6180
6350
  // const outerSize = outerEl.getBoundingClientRect()
6181
6351
  if (this.sizes.totalWidth < this.sizes.outer.width) {
6182
- let equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / this.options.columns[this.options.columns.length - 1].length
6352
+ let equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / columnsForSizing.length
6183
6353
  this.sizes.totalWidth = 0
6184
6354
  this.sizes.totalNonPinnedWidth = 0
6185
- this.options.columns[this.options.columns.length - 1].forEach((c, i) => {
6355
+ columnsForSizing.forEach((c, i) => {
6186
6356
  // if (!c.width) {
6187
6357
  // if (c.actualWidth < equalWidth) {
6188
6358
  // adjust the width
@@ -6193,7 +6363,7 @@ class WebsyTable3 {
6193
6363
  // }
6194
6364
  // }
6195
6365
  this.sizes.totalWidth += c.width || c.actualWidth
6196
- if (i < this.pinnedColumns) {
6366
+ if (i > this.pinnedColumns) {
6197
6367
  this.sizes.totalNonPinnedWidth += c.width || c.actualWidth
6198
6368
  }
6199
6369
  // equalWidth = (outerSize.width - this.sizes.totalWidth) / (this.options.columns[this.options.columns.length - 1].length - (i + 1))
@@ -6203,17 +6373,21 @@ class WebsyTable3 {
6203
6373
  if (this.sizes.pinnedWidth > (this.sizes.outer.width - firstNonPinnedColumnWidth)) {
6204
6374
  this.sizes.totalWidth = 0
6205
6375
  let diff = this.sizes.pinnedWidth - (this.sizes.outer.width - firstNonPinnedColumnWidth)
6376
+ let oldPinnedWidth = this.sizes.pinnedWidth
6377
+ this.sizes.pinnedWidth = 0
6206
6378
  // let colDiff = diff / this.pinnedColumns
6207
- for (let i = 0; i < this.options.columns[this.options.columns.length - 1].length; i++) {
6379
+ for (let i = 0; i < columnsForSizing.length; i++) {
6208
6380
  if (i < this.pinnedColumns) {
6209
- let colDiff = (this.options.columns[this.options.columns.length - 1][i].actualWidth / this.sizes.pinnedWidth) * diff
6210
- this.options.columns[this.options.columns.length - 1][i].actualWidth -= colDiff
6381
+ let colDiff = (columnsForSizing[i].actualWidth / oldPinnedWidth) * diff
6382
+ columnsForSizing[i].actualWidth -= colDiff
6383
+ this.sizes.pinnedWidth += columnsForSizing[i].actualWidth
6211
6384
  }
6212
- this.sizes.totalWidth += this.options.columns[this.options.columns.length - 1][i].width || this.options.columns[this.options.columns.length - 1][i].actualWidth
6385
+ this.sizes.totalWidth += columnsForSizing[i].width || columnsForSizing[i].actualWidth
6213
6386
  }
6214
6387
  }
6215
6388
  // take the height of the last cell as the official height for data cells
6216
6389
  // this.sizes.dataCellHeight = this.options.columns[this.options.columns.length - 1].cellHeight
6390
+ this.sizes.scrollableWidth = this.sizes.table.width - this.sizes.pinnedWidth
6217
6391
  headEl.innerHTML = ''
6218
6392
  bodyEl.innerHTML = ''
6219
6393
  footerEl.innerHTML = ''
@@ -6523,18 +6697,21 @@ class WebsyTable3 {
6523
6697
  this.startCol = 0
6524
6698
  this.endCol = 0
6525
6699
  for (let i = this.pinnedColumns; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
6526
- cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
6527
- // console.log('actualLeft', actualLeft, this.sizes.totalWidth, cumulativeWidth, cumulativeWidth + this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth)
6528
- if (actualLeft < cumulativeWidth) {
6529
- this.startCol = i
6530
- break
6531
- }
6700
+ if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
6701
+ cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
6702
+ if (actualLeft < cumulativeWidth) {
6703
+ this.startCol = i
6704
+ break
6705
+ }
6706
+ }
6532
6707
  }
6533
6708
  cumulativeWidth = 0
6534
6709
  for (let i = this.startCol; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
6535
- cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
6536
- if (cumulativeWidth < this.sizes.scrollableWidth) {
6537
- this.endCol = i
6710
+ if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
6711
+ cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
6712
+ if (cumulativeWidth < this.sizes.scrollableWidth) {
6713
+ this.endCol = i
6714
+ }
6538
6715
  }
6539
6716
  }
6540
6717
  if (this.endCol < this.options.allColumns[this.options.allColumns.length - 1].length - 1) {