lato 3.11.1 → 3.11.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aac7553d07bfc74cea7e43c829e5e68a99ef5c4c1ca84c0abafbe3ed9b28d4e2
4
- data.tar.gz: 946fa0334adad14cd55836470e5969a04be8d8533085811fd206cc21685bc333
3
+ metadata.gz: a5f0eb7f689dbdeaf6ed25131cbc8a6a4a3bdd3c0f402426373a29a9124d0506
4
+ data.tar.gz: ae388fcd54a59d7ac1f0b7ca3d3a342ac7839aaee1807697159b5c5fa7c67094
5
5
  SHA512:
6
- metadata.gz: fa351b5aaeb8c3610000eef54cfc6dc1fe000ede31e9a6963b5282c2f6591239a475da8285066f7c2e2483f5c8e1f2b7fbc109157cc6c035f4155c7ac66db3a0
7
- data.tar.gz: 0ec8ec42232d0ec5c0cd4411e6b5821348772cd451ea81c3698b2c852b20b96457e907a387f58634b2a711bf294140b55e55123503074f353d7bf828503eecaa
6
+ metadata.gz: 4c788d7f5b53aeb6f4bea7a4d5614f12697e5883ab99ca40b6752179b1f9dd9903334455153dcbe7f89473888a2a32908bfc1f8009f9043383d836367340d881
7
+ data.tar.gz: 4402d91bc41aa788e358f9aaea6592ae70630f6b9bbb375f15e51817fc3a01737d9d6b33c4c7679a1a30ae3c5e7f14c92792ee8e5eb058a0477be935d65ffb17
@@ -55,10 +55,5 @@ document.addEventListener('turbo:before-cache', (e) => {
55
55
  document.querySelector('.navbar-toggler').classList.add('collapsed')
56
56
  document.querySelector('.navbar-collapse').classList.remove('show')
57
57
 
58
- // remove all tooltips
59
- document.querySelectorAll('.tooltip').forEach((el) => {
60
- el.remove()
61
- })
62
-
63
58
  e.detail?.resume()
64
59
  })
@@ -10,84 +10,129 @@ export default class extends Controller {
10
10
  connect() {
11
11
  const localStorageStatus = localStorage.getItem('lato_guide')
12
12
  this.status = localStorageStatus ? JSON.parse(localStorageStatus) : {}
13
- this.items = null
14
- this.showing = false
15
-
16
13
  this.storeStatus()
17
- this.setupItems()
18
- this.showGuide()
14
+
15
+ this.connected = true
16
+ this.tooltip = null
17
+ this.run()
18
+
19
+ window.addEventListener('resize', this.onWindowResize.bind(this))
20
+ }
21
+
22
+ disconnect() {
23
+ this.storeStatus()
24
+
25
+ if (this.tooltip) {
26
+ this.tooltip.hide()
27
+ this.tooltip.dispose()
28
+ this.tooltip = null
29
+ }
30
+
31
+ this.connected = false
32
+
33
+ window.removeEventListener('resize', this.onWindowResize.bind(this))
19
34
  }
20
35
 
21
36
  itemTargetConnected(e) {
22
- this.setupItems()
23
- this.showGuide()
37
+ this.run()
24
38
  }
25
39
 
26
40
  itemTargetDisconnected(e) {
27
- this.setupItems()
41
+ if (this.tooltip && this.tooltip.itemKey === e.target.dataset.guideKey) {
42
+ this.tooltip.hide()
43
+ this.tooltip.dispose()
44
+ this.tooltip = null
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Exposed functions
50
+ */
51
+
52
+ rerun(e = null) {
53
+ if (e) e.preventDefault()
54
+ this.resetStatus()
55
+ this.run()
28
56
  }
29
57
 
30
- setupItems(e = null) {
58
+ run(e = null) {
31
59
  if (e) e.preventDefault()
60
+ if (!this.connected) return
32
61
 
33
- this.items = this.itemTargets.map(item => ({ element: item, key: item.dataset.guideKey, content: item.dataset.guideContent, index: parseInt(item.dataset.guideIndex) })).map(item => {
34
- item.index = isNaN(item.index) ? 999 : item.index
35
- return item
36
- }).sort((a, b) => a.index - b.index)
62
+ const items = this.getNotShowedItems()
63
+ if (items.length === 0) return
64
+
65
+ this.showItem(items[0])
37
66
  }
38
67
 
39
- async showGuide() {
40
- if (this.showing) return
41
- if (!this.status) return
42
- if (!this.items) return
68
+ /**
69
+ * Helpers
70
+ */
43
71
 
44
- for (const item of this.items) {
45
- if (this.status[item.key]) continue
46
- await this.showGuideItem(item)
47
- }
72
+ getNotShowedItems() {
73
+ const items = this.itemTargets.map(item => ({ element: item, key: item.dataset.guideKey, content: item.dataset.guideContent, index: parseInt(item.dataset.guideIndex) })).map(item => {
74
+ item.index = isNaN(item.index) ? 999 : item.index
75
+ return item
76
+ }).sort((a, b) => a.index - b.index).filter((item) => !this.status[item.key])
77
+
78
+ return items
48
79
  }
49
80
 
50
- async showGuideItem(item) {
51
- if (this.showing) return
81
+ showItem(item) {
52
82
  if (!this.status) return
53
83
  if (this.status[item.key]) return
84
+ if (this.tooltip) return
54
85
 
55
- this.showing = true
56
- return new Promise((resolve) => {
57
- const tooltipIsLast = this.items.filter(target => !this.status[target.key]).length === 1
58
- const tooltipCloseId = `lato-guide-close-${Math.random().toString(36).substring(7)}`
59
- const tooltipTitle = `
60
- <div class="px-2 py-2 d-flex align-items-center justify-content-between">
61
- <p class="me-2 mb-0 text-start">${item.content}</p>
62
- <a id="${tooltipCloseId}" class="btn btn-light btn-sm">${tooltipIsLast ? 'Close' : 'Next'}</a>
63
- </div>
64
- `
65
-
66
- const tooltip = new bootstrap.Tooltip(item.element, { title: tooltipTitle, trigger: 'manual', html: true, customClass: 'lato-guide-tooltip' })
67
- item.element.addEventListener('shown.bs.tooltip', () => {
68
- setTimeout(() => {
69
- document.getElementById(tooltipCloseId).addEventListener('click', () => {
70
- tooltip.hide()
71
- this.showing = false
72
- this.status[item.key] = true
73
- this.storeStatus()
74
- resolve()
75
- })
76
- }, 250)
77
- })
78
- tooltip.show()
86
+ // setup tooltip
87
+ const tooltipCloseId = `lato-guide-close-${Math.random().toString(36).substring(7)}`
88
+ const tooltipTitle = `
89
+ <div class="px-2 py-2 d-flex align-items-center justify-content-between">
90
+ <p class="me-2 mb-0 text-start">${item.content}</p>
91
+ <a id="${tooltipCloseId}" class="btn btn-light btn-sm">Next</a>
92
+ </div>
93
+ `
94
+ this.tooltip = new bootstrap.Tooltip(item.element, { title: tooltipTitle, trigger: 'manual', html: true, customClass: 'lato-guide-tooltip' })
95
+ this.tooltip.itemKey = item.key
96
+
97
+ // listen to tooltip close
98
+ item.element.addEventListener('shown.bs.tooltip', () => {
99
+ setTimeout(() => {
100
+ document.getElementById(tooltipCloseId).addEventListener('click', () => {
101
+ this.tooltip.hide()
102
+ this.tooltip.dispose()
103
+ this.tooltip = null
104
+ this.status[item.key] = true
105
+ this.storeStatus()
106
+ this.run()
107
+ })
108
+ }, 250)
79
109
  })
110
+ this.tooltip.show()
111
+
112
+ return true
80
113
  }
81
114
 
82
- storeStatus(e = null) {
83
- if (e) e.preventDefault()
115
+ storeStatus() {
84
116
  localStorage.setItem('lato_guide', JSON.stringify(this.status))
117
+
118
+ return true
85
119
  }
86
120
 
87
- resetStatus(e = null) {
88
- if (e) e.preventDefault()
121
+ resetStatus() {
89
122
  this.status = {}
90
123
  this.storeStatus()
91
- this.showGuide()
124
+
125
+ return true
126
+ }
127
+
128
+ /**
129
+ * Events
130
+ */
131
+
132
+ onWindowResize(e) { // on window resize, repostion tooltip
133
+ if (this.tooltip) {
134
+ this.tooltip.hide()
135
+ this.tooltip.show()
136
+ }
92
137
  }
93
138
  }
data/lib/lato/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lato
2
- VERSION = "3.11.1"
2
+ VERSION = "3.11.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.1
4
+ version: 3.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante