@websy/websy-designs 1.9.13 → 1.10.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.
@@ -60,6 +60,10 @@ class APIService {
60
60
  const url = this.buildUrl(entity, id)
61
61
  return this.run('DELETE', url)
62
62
  }
63
+ deleteMany (entity, query) {
64
+ const url = this.buildUrl(entity, null, query)
65
+ return this.run('DELETE', url)
66
+ }
63
67
  get (entity, id, query, offset, limit) {
64
68
  let url = this.buildUrl(entity, id, query)
65
69
  if (offset) {
@@ -70,12 +74,12 @@ class APIService {
70
74
  url += `?offset=${offset}`
71
75
  }
72
76
  }
73
- if (limit) {
77
+ if (limit || this.options.rowLimit) {
74
78
  if (url.indexOf('?') !== -1) {
75
- url += `&limit=${limit}`
79
+ url += `&limit=${limit || this.options.rowLimit}`
76
80
  }
77
81
  else {
78
- url += `?limit=${limit}`
82
+ url += `?limit=${limit || this.options.rowLimit}`
79
83
  }
80
84
  }
81
85
  return this.run('GET', url)
@@ -193,16 +197,51 @@ class ButtonGroup {
193
197
  this.render()
194
198
  }
195
199
  }
200
+ get value () {
201
+ if (this.options.activeItem > -1) {
202
+ return [this.options.items[this.options.activeItem]]
203
+ }
204
+ else if (this.options.multiSelect === true) {
205
+ return this.options.items.filter(d => d.selected)
206
+ }
207
+ return []
208
+ }
209
+ set value (value) {
210
+ let activeIndex = -1
211
+ if (this.options.multiSelect === true) {
212
+ if (Array.isArray(value)) {
213
+ this.options.items.forEach(d => {
214
+ if (value.indexOf(d.value) !== -1) {
215
+ d.selected = true
216
+ }
217
+ else {
218
+ d.selected = false
219
+ }
220
+ })
221
+ }
222
+ }
223
+ else {
224
+ for (let i = 0; i < this.options.items.length; i++) {
225
+ if ((this.options.items[i].value || this.options.items[i].label) === value) {
226
+ activeIndex = i
227
+ }
228
+ }
229
+ this.options.activeItem = activeIndex
230
+ }
231
+ this.render()
232
+ }
196
233
  handleClick (event) {
197
234
  if (event.target.classList.contains('websy-button-group-item')) {
198
235
  const index = +event.target.getAttribute('data-index')
199
236
  if (this.options.multiSelect === true) {
200
237
  if (event.target.classList.contains('active')) {
238
+ this.options.items[index].selected = false
201
239
  this.options.onDeactivate(this.options.items[index], index, event)
202
240
  event.target.classList.remove('active')
203
241
  event.target.classList.add('inactive')
204
242
  }
205
243
  else {
244
+ this.options.items[index].selected = true
206
245
  this.options.onActivate(this.options.items[index], index, event)
207
246
  event.target.classList.add('active')
208
247
  event.target.classList.remove('inactive')
@@ -253,7 +292,10 @@ class ButtonGroup {
253
292
  let activeClass = ''
254
293
  if (this.options.activeItem !== -1) {
255
294
  activeClass = i === this.options.activeItem ? 'active' : 'inactive'
256
- }
295
+ }
296
+ else if (this.options.multiSelect === true) {
297
+ activeClass = t.selected === true ? 'active' : 'inactive'
298
+ }
257
299
  return `
258
300
  <${this.options.tag} ${(t.attributes || []).join(' ')} data-id="${t.id || t.label}" data-index="${i}" class="websy-button-group-item ${(t.classes || []).join(' ')} ${this.options.style}-style ${activeClass}">${t.label}</${this.options.tag}>
259
301
  `
@@ -272,7 +314,12 @@ class WebsyCarousel {
272
314
  showFrameSelector: true,
273
315
  showPrevNext: true,
274
316
  autoPlay: true,
275
- frames: []
317
+ frames: [],
318
+ frameSelectorIcon: `
319
+ <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 512 512">
320
+ <circle cx="256" cy="256" r="192" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
321
+ </svg>
322
+ `
276
323
  }
277
324
  this.playTimeoutFn = null
278
325
  this.options = Object.assign({}, DEFAULTS, options)
@@ -383,10 +430,10 @@ class WebsyCarousel {
383
430
  html += `<div class="websy-btn-parent">`
384
431
  this.options.frames.forEach((frame, frameIndex) => {
385
432
  html += `
386
- <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 512 512" data-index="${frameIndex}" id="${this.elementId}_selector_${frameIndex}"
387
- class="websy-progress-btn ${this.options.currentFrame === frameIndex ? 'websy-progress-btn-active' : ''}">
388
- <title>Ellipse</title><circle cx="256" cy="256" r="192" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
389
- </svg>
433
+ <div data-index="${frameIndex}" id="${this.elementId}_selector_${frameIndex}"
434
+ class="websy-progress-btn ${this.options.currentFrame === frameIndex ? 'websy-progress-btn-active' : ''}">
435
+ ${this.options.frameSelectorIcon}
436
+ </div>
390
437
  `
391
438
  })
392
439
  html += `</div>`
@@ -1617,7 +1664,20 @@ class WebsyDropdown {
1617
1664
  const maskEl = document.getElementById(`${this.elementId}_mask`)
1618
1665
  const contentEl = document.getElementById(`${this.elementId}_content`)
1619
1666
  const scrollEl = document.getElementById(`${this.elementId}_itemsContainer`)
1620
- const actionEl = document.getElementById(`${this.elementId}_actionContainer`)
1667
+ const actionEl = document.getElementById(`${this.elementId}_actionContainer`)
1668
+ const headerEl = document.getElementById(`${this.elementId}_header`)
1669
+ const headerPos = WebsyUtils.getElementPos(headerEl)
1670
+ const contentPos = WebsyUtils.getElementPos(contentEl)
1671
+ if (this.options.style === 'plain' && headerPos.width > 0 && headerPos.height > 0) {
1672
+ contentEl.style.right = 'unset'
1673
+ if (headerPos.bottom + contentPos.height > window.innerHeight) {
1674
+ // contentEl.classList.add('on-top')
1675
+ contentEl.style.bottom = 'unset'
1676
+ }
1677
+ else {
1678
+ contentEl.style.top = 'unset'
1679
+ }
1680
+ }
1621
1681
  if (actionEl) {
1622
1682
  actionEl.classList.remove('active')
1623
1683
  }
@@ -1641,7 +1701,7 @@ class WebsyDropdown {
1641
1701
  return
1642
1702
  }
1643
1703
  if (event.target.classList.contains('websy-dropdown-header')) {
1644
- this.open()
1704
+ this.open(event)
1645
1705
  }
1646
1706
  else if (event.target.classList.contains('websy-dropdown-mask')) {
1647
1707
  this.close()
@@ -1756,17 +1816,29 @@ class WebsyDropdown {
1756
1816
  }
1757
1817
  }
1758
1818
  }
1759
- open (options, override = false) {
1819
+ open (event, override = false) {
1760
1820
  const maskEl = document.getElementById(`${this.elementId}_mask`)
1761
1821
  const contentEl = document.getElementById(`${this.elementId}_content`)
1762
- const el = document.getElementById(this.elementId)
1763
- if (el) {
1764
- el.style.zIndex = 999
1765
- }
1822
+ const headerEl = document.getElementById(`${this.elementId}_header`)
1766
1823
  maskEl.classList.add('active')
1767
1824
  contentEl.classList.add('active')
1768
- if (WebsyUtils.getElementPos(contentEl).bottom > window.innerHeight) {
1769
- contentEl.classList.add('on-top')
1825
+ const headerPos = WebsyUtils.getElementPos(headerEl)
1826
+ const contentPos = WebsyUtils.getElementPos(contentEl)
1827
+ if (this.options.style === 'plain' && headerPos.width > 0 && headerPos.height > 0) {
1828
+ contentEl.style.right = `calc(100vw - ${headerPos.right}px)`
1829
+ contentEl.style.width = `${headerEl.clientWidth}px`
1830
+ if (headerPos.bottom + contentPos.height > window.innerHeight) {
1831
+ // contentEl.classList.add('on-top')
1832
+ contentEl.style.bottom = `calc(100vh - ${headerPos.top}px)`
1833
+ }
1834
+ else {
1835
+ contentEl.style.top = headerPos.bottom + 'px'
1836
+ }
1837
+ }
1838
+ else if (this.options.style === 'plain' && headerPos.width === 0 && headerPos.height === 0) {
1839
+ const targetPos = WebsyUtils.getElementPos(event.target)
1840
+ contentEl.style.right = `calc(100vw - ${targetPos.right}px)`
1841
+ contentEl.style.width = `${targetPos.width}px`
1770
1842
  }
1771
1843
  if (this.options.disableSearch !== true) {
1772
1844
  const searchEl = document.getElementById(`${this.elementId}_search`)
@@ -1778,6 +1850,19 @@ class WebsyDropdown {
1778
1850
  this.options.onOpen(this.elementId)
1779
1851
  }
1780
1852
  }
1853
+ set items (items) {
1854
+ this.options.items = [...items]
1855
+ if (this.options.items.length > 0) {
1856
+ this.options.items = this.options.items.map((d, i) => {
1857
+ if (typeof d.index === 'undefined') {
1858
+ d.index = i
1859
+ }
1860
+ return d
1861
+ })
1862
+ }
1863
+ this._originalData = [...this.options.items]
1864
+ this.render()
1865
+ }
1781
1866
  render () {
1782
1867
  if (!this.elementId) {
1783
1868
  console.log('No element Id provided for Websy Dropdown')
@@ -2254,9 +2339,7 @@ class WebsyForm {
2254
2339
  }
2255
2340
  GlobalPubSub.subscribe('recaptchaready', this.recaptchaReady.bind(this))
2256
2341
  this.recaptchaResult = null
2257
- this.options = Object.assign(defaults, {}, {
2258
- // defaults go here
2259
- }, options)
2342
+ this.options = Object.assign({}, defaults, options)
2260
2343
  if (!elementId) {
2261
2344
  console.log('No element Id provided')
2262
2345
  return
@@ -2324,8 +2407,27 @@ class WebsyForm {
2324
2407
  const data = {}
2325
2408
  const temp = new FormData(formEl)
2326
2409
  temp.forEach((value, key) => {
2327
- data[key] = value
2410
+ if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2411
+ data[key] = true
2412
+ }
2413
+ if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2414
+ data[key] = this.fieldMap[key].instance.value
2415
+ }
2416
+ else {
2417
+ data[key] = value
2418
+ }
2328
2419
  })
2420
+ let keys = Object.keys(data)
2421
+ for (const key in this.fieldMap) {
2422
+ if (keys.indexOf(key) === -1) {
2423
+ if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2424
+ data[key] = false
2425
+ }
2426
+ else if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2427
+ data[key] = this.fieldMap[key].instance.value
2428
+ }
2429
+ }
2430
+ }
2329
2431
  return data
2330
2432
  }
2331
2433
  set data (d) {
@@ -2383,6 +2485,7 @@ class WebsyForm {
2383
2485
  handleClick (event) {
2384
2486
  if (event.target.classList.contains('submit')) {
2385
2487
  event.preventDefault()
2488
+ event.stopPropagation()
2386
2489
  this.submitForm()
2387
2490
  }
2388
2491
  else if (event.target.classList.contains('cancel')) {
@@ -2555,6 +2658,7 @@ class WebsyForm {
2555
2658
  `
2556
2659
  this.options.fields.forEach((f, i) => {
2557
2660
  this.fieldMap[f.field] = f
2661
+ f.owningElement = this.elementId
2558
2662
  if (f.component) {
2559
2663
  componentsToProcess.push(f)
2560
2664
  html += `
@@ -2641,6 +2745,10 @@ class WebsyForm {
2641
2745
  const el = document.getElementById(`${this.elementId}_input_${field}`)
2642
2746
  if (el) {
2643
2747
  el.value = value
2748
+ el.setAttribute('value', value)
2749
+ if (this.fieldMap[field].type === 'checkbox') {
2750
+ el.checked = value
2751
+ }
2644
2752
  }
2645
2753
  else {
2646
2754
  console.error(`Input for ${field} does not exist in form.`)
@@ -2798,6 +2906,10 @@ class MultiForm {
2798
2906
  }
2799
2907
  this.render()
2800
2908
  }
2909
+ addData (data) {
2910
+ this.formData = this.formData.concat(data)
2911
+ this.render()
2912
+ }
2801
2913
  addEntry () {
2802
2914
  const el = document.getElementById(`${this.elementId}_container`)
2803
2915
  let newId = WebsyDesigns.Utils.createIdentity()
@@ -2815,7 +2927,7 @@ class MultiForm {
2815
2927
  </button>
2816
2928
  `
2817
2929
  el.appendChild(newFormEl)
2818
- let formOptions = Object.assign({}, this.options)
2930
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
2819
2931
  this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${newId}_form`, formOptions))
2820
2932
  }
2821
2933
  clear () {
@@ -2829,14 +2941,20 @@ class MultiForm {
2829
2941
  }
2830
2942
  get data () {
2831
2943
  const d = this.forms.map(f => (f.data))
2832
- // we don't return the last form
2833
- d.pop()
2944
+ console.log('forms data', d)
2945
+ if (this.options.allowAdd !== false) {
2946
+ // we don't return the last form
2947
+ d.pop()
2948
+ }
2834
2949
  return d
2835
2950
  }
2836
2951
  set data (d) {
2837
2952
  this.formData = d
2838
2953
  this.render()
2839
2954
  }
2955
+ get deleted () {
2956
+ return this.formData.filter(d => this.recordsToDelete.includes(`${d.id}`))
2957
+ }
2840
2958
  handleClick (event) {
2841
2959
  if (event.target.classList.contains('websy-multi-form-add')) {
2842
2960
  let id = event.target.getAttribute('data-formid')
@@ -2916,15 +3034,17 @@ class MultiForm {
2916
3034
  `
2917
3035
  }
2918
3036
  el.innerHTML = html
2919
- this.formData.forEach(d => {
2920
- let formOptions = Object.assign({}, this.options)
3037
+ this.forms = new Array(this.formData.length)
3038
+ this.formData.forEach((d, i) => {
3039
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
2921
3040
  let formObject = new WebsyDesigns.Form(`${this.elementId}_${d.formId}_form`, formOptions)
2922
3041
  formObject.data = d
2923
- this.forms.push(formObject)
3042
+ this.forms[i] = formObject
2924
3043
  })
2925
3044
  if (this.options.allowAdd === true) {
2926
- let formOptions = Object.assign({}, this.options)
2927
- this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${id}_form`, formOptions))
3045
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
3046
+ let formObject = new WebsyDesigns.Form(`${this.elementId}_${id}_form`, formOptions)
3047
+ this.forms.push(formObject)
2928
3048
  }
2929
3049
  }
2930
3050
  }
@@ -3934,6 +4054,9 @@ class WebsyPubSub {
3934
4054
  }
3935
4055
  }
3936
4056
  subscribe (id, method, fn) {
4057
+ if (!this.subscriptions) {
4058
+ this.subscriptions = {}
4059
+ }
3937
4060
  if (arguments.length === 3) {
3938
4061
  if (!this.subscriptions[id]) {
3939
4062
  this.subscriptions[id] = {}
@@ -5490,7 +5613,52 @@ class WebsyTemplate {
5490
5613
  return html
5491
5614
  }
5492
5615
  handleClick (event) {
5493
- //
5616
+ if (event.target.classList.contains('clickable')) {
5617
+ this.handleEvent(event, 'clickable', 'click')
5618
+ }
5619
+ }
5620
+ handleEvent (event, eventType, action) {
5621
+ let l = event.target.getAttribute('data-event')
5622
+ if (l) {
5623
+ l = l.split('(')
5624
+ let params = []
5625
+ const id = event.target.getAttribute('data-id')
5626
+ // const locator = event.target.getAttribute('data-locator')
5627
+ // if (l[1]) {
5628
+ // l[1] = l[1].replace(')', '')
5629
+ // params = l[1].split(',')
5630
+ // }
5631
+ // l = l[0]
5632
+ let data = this.options.data
5633
+ // if (locator !== '') {
5634
+ // let locatorItems = locator.split(';')
5635
+ // locatorItems.forEach(loc => {
5636
+ // let locatorParts = loc.split(':')
5637
+ // if (data[locatorParts[0]]) {
5638
+ // data = data[locatorParts[0]]
5639
+ // let parts = locatorParts[1].split('.')
5640
+ // parts.forEach(p => {
5641
+ // data = data[p]
5642
+ // })
5643
+ // }
5644
+ // })
5645
+ // }
5646
+ // params = params.map(p => {
5647
+ // if (typeof p !== 'string' && typeof p !== 'number') {
5648
+ // if (data[+id]) {
5649
+ // p = data[+id][p]
5650
+ // }
5651
+ // }
5652
+ // else if (typeof p === 'string') {
5653
+ // p = p.replace(/"/g, '').replace(/'/g, '')
5654
+ // }
5655
+ // return p
5656
+ // })
5657
+ if (event.target.classList.contains(eventType) && this.options.listeners[action] && this.options.listeners[action][l]) {
5658
+ event.stopPropagation()
5659
+ this.options.listeners[action][l].call(this, event, data[+id], ...params)
5660
+ }
5661
+ }
5494
5662
  }
5495
5663
  render () {
5496
5664
  this.resize()
@@ -5523,7 +5691,9 @@ const WebsyUtils = {
5523
5691
  top: rect.top + scrollTop,
5524
5692
  left: rect.left + scrollLeft,
5525
5693
  bottom: rect.top + scrollTop + el.clientHeight,
5526
- right: rect.left + scrollLeft + el.clientWidth
5694
+ right: rect.left + scrollLeft + el.clientWidth,
5695
+ width: rect.width,
5696
+ height: rect.height
5527
5697
  }
5528
5698
  },
5529
5699
  getLightDark: (backgroundColor, darkColor = '#000000', lightColor = '#ffffff') => {
@@ -6844,7 +7014,7 @@ class WebsyTable3 {
6844
7014
  row.forEach((cell, cellIndex) => {
6845
7015
  let sizeIndex = cell.level || cellIndex
6846
7016
  let colIndex = cell.index || cellIndex
6847
- if (typeof sizingColumns[sizeIndex] === 'undefined' || sizingColumns[sizeIndex].show === false) {
7017
+ if (typeof sizingColumns[sizeIndex] === 'undefined' || this.options.columns[this.options.columns.length - 1][colIndex].show === false) {
6848
7018
  return // need to revisit this logic
6849
7019
  }
6850
7020
  let style = ''
@@ -9836,6 +10006,14 @@ symbols
9836
10006
  if (this.options.data[xAxis].scale === 'Time') {
9837
10007
  xPos = this[`${xAxis}Axis`](this.parseX(d.x.value))
9838
10008
  }
10009
+ else {
10010
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
10011
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
10012
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
10013
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
10014
+ }
10015
+ // return xPos
10016
+ }
9839
10017
  // return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
9840
10018
  return `translate(${xPos}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
9841
10019
  }
@@ -9862,6 +10040,14 @@ symbols.enter()
9862
10040
  if (this.options.data[xAxis].scale === 'Time') {
9863
10041
  xPos = this[`${xAxis}Axis`](this.parseX(d.x.value))
9864
10042
  }
10043
+ else {
10044
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
10045
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
10046
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
10047
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
10048
+ }
10049
+ // return xPos
10050
+ }
9865
10051
  // return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
9866
10052
  return `translate(${xPos}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
9867
10053
  }
@@ -10540,8 +10726,12 @@ class WebsyKPI {
10540
10726
  constructor (elementId, options) {
10541
10727
  const DEFAULTS = {
10542
10728
  tooltip: {},
10543
- label: {},
10544
- value: {}
10729
+ label: {
10730
+ value: ''
10731
+ },
10732
+ value: {
10733
+ value: ''
10734
+ }
10545
10735
  }
10546
10736
  this.elementId = elementId
10547
10737
  this.options = Object.assign({}, DEFAULTS, options)
@@ -10577,7 +10767,7 @@ class WebsyKPI {
10577
10767
  html += `
10578
10768
  <div class="websy-kpi-info">
10579
10769
  <div class="websy-kpi-label ${this.options.label.classes.join(' ') || ''}">
10580
- ${this.options.label.value || ''}
10770
+ ${(this.options.label || {}).value || ''}
10581
10771
  `
10582
10772
  if (this.options.tooltip && this.options.tooltip.value) {
10583
10773
  html += `