@websy/websy-designs 1.10.0 → 1.10.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.
@@ -1485,6 +1485,7 @@ class WebsyDropdown {
1485
1485
  closeAfterSelection: true,
1486
1486
  customActions: [],
1487
1487
  customButtons: [],
1488
+ minWidth: 220,
1488
1489
  searchIcon: `<svg width="20" height="20" viewBox="0 0 512 512"><path d="M221.09,64A157.09,157.09,0,1,0,378.18,221.09,157.1,157.1,0,0,0,221.09,64Z" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:32px"/><line x1="338.29" y1="338.29" x2="448" y2="448" style="fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px"/></svg>`,
1489
1490
  clearIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 512 512"><title>ionicons-v5-l</title><line x1="368" y1="368" x2="144" y2="144" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><line x1="368" y1="144" x2="144" y2="368" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/></svg>`,
1490
1491
  arrowIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M23.677 18.52c.914 1.523-.183 3.472-1.967 3.472h-19.414c-1.784 0-2.881-1.949-1.967-3.472l9.709-16.18c.891-1.483 3.041-1.48 3.93 0l9.709 16.18z"/></svg>`,
@@ -1511,7 +1512,7 @@ class WebsyDropdown {
1511
1512
  el.addEventListener('click', this.handleClick.bind(this))
1512
1513
  el.addEventListener('keyup', this.handleKeyUp.bind(this))
1513
1514
  el.addEventListener('mouseout', this.handleMouseOut.bind(this))
1514
- el.addEventListener('mousemove', this.handleMouseMove.bind(this))
1515
+ el.addEventListener('mousemove', this.handleMouseMove.bind(this))
1515
1516
  const headerLabel = this.selectedItems.map(s => this.options.items[s].label || this.options.items[s].value).join(this.options.multiValueDelimiter)
1516
1517
  const headerValue = this.selectedItems.map(s => this.options.items[s].value || this.options.items[s].label).join(this.options.multiValueDelimiter)
1517
1518
  let html = `
@@ -1596,6 +1597,15 @@ class WebsyDropdown {
1596
1597
  </div>
1597
1598
  `
1598
1599
  el.innerHTML = html
1600
+ const maskEl = document.getElementById(`${this.elementId}_mask`)
1601
+ if (maskEl) {
1602
+ maskEl.addEventListener('mousewheel', event => {
1603
+ if (event.target.classList.contains('websy-dropdown-mask')) {
1604
+ event.preventDefault()
1605
+ event.stopPropagation()
1606
+ }
1607
+ })
1608
+ }
1599
1609
  const scrollEl = document.getElementById(`${this.elementId}_itemsContainer`)
1600
1610
  if (scrollEl) {
1601
1611
  scrollEl.addEventListener('scroll', this.handleScroll.bind(this))
@@ -1826,7 +1836,7 @@ class WebsyDropdown {
1826
1836
  const contentPos = WebsyUtils.getElementPos(contentEl)
1827
1837
  if (this.options.style === 'plain' && headerPos.width > 0 && headerPos.height > 0) {
1828
1838
  contentEl.style.right = `calc(100vw - ${headerPos.right}px)`
1829
- contentEl.style.width = `${headerEl.clientWidth}px`
1839
+ contentEl.style.width = `${Math.max(this.options.minWidth, headerEl.clientWidth)}px`
1830
1840
  if (headerPos.bottom + contentPos.height > window.innerHeight) {
1831
1841
  // contentEl.classList.add('on-top')
1832
1842
  contentEl.style.bottom = `calc(100vh - ${headerPos.top}px)`
@@ -1838,7 +1848,7 @@ class WebsyDropdown {
1838
1848
  else if (this.options.style === 'plain' && headerPos.width === 0 && headerPos.height === 0) {
1839
1849
  const targetPos = WebsyUtils.getElementPos(event.target)
1840
1850
  contentEl.style.right = `calc(100vw - ${targetPos.right}px)`
1841
- contentEl.style.width = `${targetPos.width}px`
1851
+ contentEl.style.width = `${Math.max(this.options.minWidth, targetPos.width)}px`
1842
1852
  }
1843
1853
  if (this.options.disableSearch !== true) {
1844
1854
  const searchEl = document.getElementById(`${this.elementId}_search`)
@@ -3776,7 +3786,9 @@ class WebsyPDFButton {
3776
3786
  classes: [],
3777
3787
  wait: 0,
3778
3788
  buttonText: 'Download',
3779
- directDownload: false
3789
+ directDownload: false,
3790
+ preProcess: (callbackFn) => (callbackFn(true)),
3791
+ onError: () => {}
3780
3792
  }
3781
3793
  this.elementId = elementId
3782
3794
  this.options = Object.assign({}, DEFAULTS, options)
@@ -3834,87 +3846,95 @@ class WebsyPDFButton {
3834
3846
  handleClick (event) {
3835
3847
  if (event.target.classList.contains('websy-pdf-button')) {
3836
3848
  this.loader.show()
3837
- setTimeout(() => {
3838
- if (this.options.targetId) {
3839
- const el = document.getElementById(this.options.targetId)
3840
- if (el) {
3841
- const pdfData = { options: {} }
3842
- if (this.options.pdfOptions) {
3843
- pdfData.options = Object.assign({}, this.options.pdfOptions)
3844
- }
3845
- if (this.options.header) {
3846
- if (this.options.header.elementId) {
3847
- const headerEl = document.getElementById(this.options.header.elementId)
3848
- if (headerEl) {
3849
- pdfData.header = headerEl.outerHTML
3850
- if (this.options.header.css) {
3851
- pdfData.options.headerCSS = this.options.header.css
3852
- }
3849
+ this.options.preProcess((proceed) => {
3850
+ if (proceed === true) {
3851
+ setTimeout(() => {
3852
+ if (this.options.targetId) {
3853
+ const el = document.getElementById(this.options.targetId)
3854
+ if (el) {
3855
+ const pdfData = { options: {} }
3856
+ if (this.options.pdfOptions) {
3857
+ pdfData.options = Object.assign({}, this.options.pdfOptions)
3853
3858
  }
3854
- }
3855
- else if (this.options.header.html) {
3856
- pdfData.header = this.options.header.html
3857
- if (this.options.header.css) {
3858
- pdfData.options.headerCSS = this.options.header.css
3859
- }
3860
- }
3861
- else {
3862
- pdfData.header = this.options.header
3863
- }
3864
- }
3865
- if (this.options.footer) {
3866
- if (this.options.footer.elementId) {
3867
- const footerEl = document.getElementById(this.options.footer.elementId)
3868
- if (footerEl) {
3869
- pdfData.footer = footerEl.outerHTML
3870
- if (this.options.footer.css) {
3871
- pdfData.options.footerCSS = this.options.footer.css
3859
+ if (this.options.header) {
3860
+ if (this.options.header.elementId) {
3861
+ const headerEl = document.getElementById(this.options.header.elementId)
3862
+ if (headerEl) {
3863
+ pdfData.header = headerEl.outerHTML
3864
+ if (this.options.header.css) {
3865
+ pdfData.options.headerCSS = this.options.header.css
3866
+ }
3867
+ }
3868
+ }
3869
+ else if (this.options.header.html) {
3870
+ pdfData.header = this.options.header.html
3871
+ if (this.options.header.css) {
3872
+ pdfData.options.headerCSS = this.options.header.css
3873
+ }
3874
+ }
3875
+ else {
3876
+ pdfData.header = this.options.header
3872
3877
  }
3873
3878
  }
3874
- }
3875
- else {
3876
- pdfData.footer = this.options.footer
3877
- }
3878
- }
3879
- pdfData.html = el.outerHTML
3880
- // document.getElementById(`${this.elementId}_pdfHeader`).value = pdfData.header
3881
- // document.getElementById(`${this.elementId}_pdfHTML`).value = pdfData.html
3882
- // document.getElementById(`${this.elementId}_pdfFooter`).value = pdfData.footer
3883
- // document.getElementById(`${this.elementId}_form`).submit()
3884
- this.service.add('', pdfData, {responseType: 'blob'}).then(response => {
3885
- this.loader.hide()
3886
- const blob = new Blob([response], {type: 'application/pdf'})
3887
- let msg = `
3888
- <div class='text-center websy-pdf-download'>
3889
- <div>Your file is ready to download</div>
3890
- <a href='${URL.createObjectURL(blob)}' target='_blank'
3891
- `
3892
- if (this.options.directDownload === true) {
3893
- let fileName
3894
- if (typeof this.options.fileName === 'function') {
3895
- fileName = this.options.fileName() || 'Export'
3879
+ if (this.options.footer) {
3880
+ if (this.options.footer.elementId) {
3881
+ const footerEl = document.getElementById(this.options.footer.elementId)
3882
+ if (footerEl) {
3883
+ pdfData.footer = footerEl.outerHTML
3884
+ if (this.options.footer.css) {
3885
+ pdfData.options.footerCSS = this.options.footer.css
3886
+ }
3887
+ }
3888
+ }
3889
+ else {
3890
+ pdfData.footer = this.options.footer
3891
+ }
3896
3892
  }
3897
- else {
3898
- fileName = this.options.fileName || 'Export'
3899
- }
3900
- msg += `download='${fileName}.pdf'`
3893
+ pdfData.html = el.outerHTML
3894
+ // document.getElementById(`${this.elementId}_pdfHeader`).value = pdfData.header
3895
+ // document.getElementById(`${this.elementId}_pdfHTML`).value = pdfData.html
3896
+ // document.getElementById(`${this.elementId}_pdfFooter`).value = pdfData.footer
3897
+ // document.getElementById(`${this.elementId}_form`).submit()
3898
+ this.service.add('', pdfData, {responseType: 'blob'}).then(response => {
3899
+ this.loader.hide()
3900
+ const blob = new Blob([response], {type: 'application/pdf'})
3901
+ let msg = `
3902
+ <div class='text-center websy-pdf-download'>
3903
+ <div>Your file is ready to download</div>
3904
+ <a href='${URL.createObjectURL(blob)}' target='_blank'
3905
+ `
3906
+ if (this.options.directDownload === true) {
3907
+ let fileName
3908
+ if (typeof this.options.fileName === 'function') {
3909
+ fileName = this.options.fileName() || 'Export'
3910
+ }
3911
+ else {
3912
+ fileName = this.options.fileName || 'Export'
3913
+ }
3914
+ msg += `download='${fileName}.pdf'`
3915
+ }
3916
+ msg += `
3917
+ >
3918
+ <button class='websy-btn download-pdf'>${this.options.buttonText}</button>
3919
+ </a>
3920
+ </div>
3921
+ `
3922
+ this.popup.show({
3923
+ message: msg,
3924
+ mask: true
3925
+ })
3926
+ }, err => {
3927
+ console.error(err)
3928
+ })
3901
3929
  }
3902
- msg += `
3903
- >
3904
- <button class='websy-btn download-pdf'>${this.options.buttonText}</button>
3905
- </a>
3906
- </div>
3907
- `
3908
- this.popup.show({
3909
- message: msg,
3910
- mask: true
3911
- })
3912
- }, err => {
3913
- console.error(err)
3914
- })
3915
- }
3916
- }
3917
- }, this.options.wait)
3930
+ }
3931
+ }, this.options.wait)
3932
+ }
3933
+ else {
3934
+ this.loader.hide()
3935
+ this.options.onError()
3936
+ }
3937
+ })
3918
3938
  }
3919
3939
  else if (event.target.classList.contains('download-pdf')) {
3920
3940
  this.popup.hide()
@@ -5688,10 +5708,12 @@ const WebsyUtils = {
5688
5708
  const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft
5689
5709
  const scrollTop = window.pageYOffset || document.documentElement.scrollTop
5690
5710
  return {
5691
- top: rect.top + scrollTop,
5692
- left: rect.left + scrollLeft,
5693
- bottom: rect.top + scrollTop + el.clientHeight,
5694
- right: rect.left + scrollLeft + el.clientWidth,
5711
+ top: rect.top, // + scrollTop,
5712
+ left: rect.left, // + scrollLeft,
5713
+ // bottom: rect.top + scrollTop + el.clientHeight,
5714
+ bottom: rect.top + el.clientHeight,
5715
+ // right: rect.left + scrollLeft + el.clientWidth,
5716
+ right: rect.left + el.clientWidth,
5695
5717
  width: rect.width,
5696
5718
  height: rect.height
5697
5719
  }
@@ -5879,6 +5901,7 @@ class WebsyTable {
5879
5901
  this.busy = false
5880
5902
  this.tooltipTimeoutFn = null
5881
5903
  this.data = []
5904
+ this._isRendered = false
5882
5905
  const el = document.getElementById(this.elementId)
5883
5906
  if (el) {
5884
5907
  let html = `
@@ -5938,7 +5961,11 @@ class WebsyTable {
5938
5961
  console.error(`No element found with ID ${this.elementId}`)
5939
5962
  }
5940
5963
  }
5964
+ get isRendered () {
5965
+ return this._isRendered
5966
+ }
5941
5967
  appendRows (data) {
5968
+ this._isRendered = false
5942
5969
  this.hideError()
5943
5970
  let bodyHTML = ''
5944
5971
  if (data) {
@@ -6015,6 +6042,7 @@ class WebsyTable {
6015
6042
  }
6016
6043
  const bodyEl = document.getElementById(`${this.elementId}_body`)
6017
6044
  bodyEl.innerHTML += bodyHTML
6045
+ this._isRendered = true
6018
6046
  }
6019
6047
  buildSearchIcon (field) {
6020
6048
  return `
@@ -6154,6 +6182,7 @@ class WebsyTable {
6154
6182
  this.render(this.data)
6155
6183
  }
6156
6184
  render (data) {
6185
+ this._isRendered = false
6157
6186
  if (!this.options.columns) {
6158
6187
  return
6159
6188
  }
@@ -6868,6 +6897,7 @@ class WebsyTable3 {
6868
6897
  autoFitColumns: true
6869
6898
  }
6870
6899
  this.options = Object.assign({}, DEFAULTS, options)
6900
+ this._isRendered = false
6871
6901
  this.isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
6872
6902
  if (this.options.disableTouch === true) {
6873
6903
  this.isTouchDevice = false
@@ -6962,6 +6992,9 @@ class WebsyTable3 {
6962
6992
  console.error(`No element found with ID ${this.elementId}`)
6963
6993
  }
6964
6994
  }
6995
+ get isRendered () {
6996
+ return this._isRendered
6997
+ }
6965
6998
  set columns (columns) {
6966
6999
  this.options.columns = columns
6967
7000
  this.renderColumnHeaders()
@@ -6971,6 +7004,7 @@ class WebsyTable3 {
6971
7004
  this.renderTotals()
6972
7005
  }
6973
7006
  appendRows (data) {
7007
+ this._isRendered = false
6974
7008
  this.hideError()
6975
7009
  let bodyEl = document.getElementById(`${this.elementId}_tableBody`)
6976
7010
  if (bodyEl) {
@@ -6984,6 +7018,7 @@ class WebsyTable3 {
6984
7018
  }
6985
7019
  else {
6986
7020
  bodyEl.innerHTML += this.buildBodyHtml(data, true)
7021
+ this._isRendered = true
6987
7022
  }
6988
7023
  this.currentData = this.currentData.concat(data)
6989
7024
  }
@@ -7985,10 +8020,12 @@ class WebsyChart {
7985
8020
  maxBandWidth: 100,
7986
8021
  allowUnevenBands: true,
7987
8022
  allowBrushing: true,
7988
- balancedMinMax: false
8023
+ balancedMinMax: false,
8024
+ onRendered: () => {}
7989
8025
  }
7990
8026
  this.elementId = elementId
7991
8027
  this.options = Object.assign({}, DEFAULTS, options)
8028
+ this._isRendered = false
7992
8029
  this.leftAxis = null
7993
8030
  this.rightAxis = null
7994
8031
  this.topAxis = null
@@ -8027,21 +8064,6 @@ class WebsyChart {
8027
8064
  }
8028
8065
  }
8029
8066
  }
8030
- // }
8031
- // else {
8032
- // let domain = [...this[xAxis].domain()]
8033
- // if (this.options.orientation === 'horizontal') {
8034
- // domain = domain.reverse()
8035
- // }
8036
- // for (let j = 0; j < domain.length; j++) {
8037
- // let breakA = this[xAxis](domain[j]) - (width / 2)
8038
- // let breakB = breakA + width
8039
- // if (input > breakA && input <= breakB) {
8040
- // output = j
8041
- // break
8042
- // }
8043
- // }
8044
- // }
8045
8067
  return output
8046
8068
  }
8047
8069
  let that = this
@@ -8128,6 +8150,9 @@ class WebsyChart {
8128
8150
  this.options.data = d
8129
8151
  this.render()
8130
8152
  }
8153
+ get isRendered () {
8154
+ return this._isRendered
8155
+ }
8131
8156
  close () {
8132
8157
  this.leftAxisLayer && this.leftAxisLayer.selectAll('*').remove()
8133
8158
  this.rightAxisLayer && this.rightAxisLayer.selectAll('*').remove()
@@ -8438,6 +8463,7 @@ this.render()
8438
8463
  }
8439
8464
  render (options) {
8440
8465
  /* global d3 options WebsyUtils */
8466
+ this._isRendered = false
8441
8467
  if (typeof options !== 'undefined') {
8442
8468
  this.options = Object.assign({}, this.options, options)
8443
8469
  if (this.options.legendOptions) {
@@ -9304,6 +9330,7 @@ this.refLineLayer.selectAll('.reference-line-label').remove()
9304
9330
  if (this.options.refLines && this.options.refLines.length > 0) {
9305
9331
  this.options.refLines.forEach(l => this.renderRefLine(l))
9306
9332
  }
9333
+ this._isRendered = true
9307
9334
 
9308
9335
  }
9309
9336
  renderarea (series, index) {
@@ -10735,9 +10762,14 @@ class WebsyKPI {
10735
10762
  }
10736
10763
  this.elementId = elementId
10737
10764
  this.options = Object.assign({}, DEFAULTS, options)
10765
+ this._isRendered = false
10738
10766
  this.render()
10739
10767
  }
10768
+ get isRendered () {
10769
+ return this._isRendered
10770
+ }
10740
10771
  render (options) {
10772
+ this._isRendered = false
10741
10773
  this.options = Object.assign({}, this.options, options)
10742
10774
  if (!this.options.label.classes) {
10743
10775
  this.options.label.classes = []
@@ -10790,6 +10822,7 @@ class WebsyKPI {
10790
10822
  </div>
10791
10823
  `
10792
10824
  el.innerHTML = html
10825
+ this._isRendered = true
10793
10826
  }
10794
10827
  }
10795
10828
  }
@@ -10811,6 +10844,7 @@ class WebsyMap {
10811
10844
  }
10812
10845
  this.elementId = elementId
10813
10846
  this.options = Object.assign({}, DEFAULTS, options)
10847
+ this._isRendered = false
10814
10848
  if (!elementId) {
10815
10849
  console.log('No element Id provided for Websy Map')
10816
10850
  return
@@ -10842,6 +10876,9 @@ class WebsyMap {
10842
10876
  this.render()
10843
10877
  }
10844
10878
  }
10879
+ get isRendered () {
10880
+ return this._isRendered
10881
+ }
10845
10882
  handleClick (event) {
10846
10883
 
10847
10884
  }
@@ -10849,6 +10886,7 @@ class WebsyMap {
10849
10886
 
10850
10887
  }
10851
10888
  render () {
10889
+ this._isRendered = false
10852
10890
  const mapEl = document.getElementById(`${this.elementId}_map`)
10853
10891
  const legendEl = document.getElementById(`${this.elementId}_map`)
10854
10892
  if (this.options.showLegend === true && this.options.data.polygons) {
@@ -10980,6 +11018,7 @@ class WebsyMap {
10980
11018
  else if (this.options.center) {
10981
11019
  this.map.setView(this.options.center, this.options.zoom || null)
10982
11020
  }
11021
+ this._isRendered = true
10983
11022
  }
10984
11023
  }
10985
11024