lato 3.11.1 → 3.11.4

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: 0f74224daab88d3ccd9e30a552503efaa04503a4e4e1bf103bf0aefa43a1d743
4
+ data.tar.gz: 1995b2071e0ef30bfdcad2259dd90b7500af23506ac63fe77375ee8955b19920
5
5
  SHA512:
6
- metadata.gz: fa351b5aaeb8c3610000eef54cfc6dc1fe000ede31e9a6963b5282c2f6591239a475da8285066f7c2e2483f5c8e1f2b7fbc109157cc6c035f4155c7ac66db3a0
7
- data.tar.gz: 0ec8ec42232d0ec5c0cd4411e6b5821348772cd451ea81c3698b2c852b20b96457e907a387f58634b2a711bf294140b55e55123503074f353d7bf828503eecaa
6
+ metadata.gz: f22a9b7694ee48adbef3b63c1d02cf6ad00b4a719c71c2099576348c6726c5cf2edc7f9b6152d2213fc3dd7ffc9242ea29ac4fe96c3874a957a32e61707ed11b
7
+ data.tar.gz: e14da8bcb3bffadcc298a41ad48e47fcdfd631a7025574f7a19e4f1a4377e9f8c449ba82ca5005216ec1b5ef130ab1da4870edeaf217d1bf8b158a7650ea520c
@@ -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.onDomChange.bind(this))
20
+ document.addEventListener('turbo:load', this.onDomChange.bind(this))
21
+ document.addEventListener('turbo:frame-load', this.onDomChange.bind(this))
22
+ }
23
+
24
+ disconnect() {
25
+ this.storeStatus()
26
+
27
+ if (this.tooltip) {
28
+ this.tooltip.dispose()
29
+ this.tooltip = null
30
+ }
31
+
32
+ this.connected = false
33
+
34
+ window.removeEventListener('resize', this.onDomChange.bind(this))
35
+ window.removeEventListener('turbo:load', this.onDomChange.bind(this))
36
+ window.removeEventListener('turbo:frame-load', this.onDomChange.bind(this))
19
37
  }
20
38
 
21
39
  itemTargetConnected(e) {
22
- this.setupItems()
23
- this.showGuide()
40
+ this.run()
24
41
  }
25
42
 
26
43
  itemTargetDisconnected(e) {
27
- this.setupItems()
44
+ if (this.tooltip && this.tooltip.itemKey === e.target.dataset.guideKey) {
45
+ this.tooltip.dispose()
46
+ this.tooltip = null
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Exposed functions
52
+ */
53
+
54
+ rerun(e = null) {
55
+ if (e) e.preventDefault()
56
+ this.resetStatus()
57
+ this.run()
28
58
  }
29
59
 
30
- setupItems(e = null) {
60
+ run(e = null) {
31
61
  if (e) e.preventDefault()
62
+ if (!this.connected) return
32
63
 
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)
64
+ const items = this.getNotShowedItems()
65
+ if (items.length === 0) return
66
+
67
+ this.showItem(items[0])
37
68
  }
38
69
 
39
- async showGuide() {
40
- if (this.showing) return
41
- if (!this.status) return
42
- if (!this.items) return
70
+ /**
71
+ * Helpers
72
+ */
43
73
 
44
- for (const item of this.items) {
45
- if (this.status[item.key]) continue
46
- await this.showGuideItem(item)
47
- }
74
+ getNotShowedItems() {
75
+ const items = this.itemTargets.map(item => ({ element: item, key: item.dataset.guideKey, content: item.dataset.guideContent, index: parseInt(item.dataset.guideIndex) })).map(item => {
76
+ item.index = isNaN(item.index) ? 999 : item.index
77
+ return item
78
+ }).sort((a, b) => a.index - b.index).filter((item) => !this.status[item.key])
79
+
80
+ return items
48
81
  }
49
82
 
50
- async showGuideItem(item) {
51
- if (this.showing) return
83
+ showItem(item) {
52
84
  if (!this.status) return
53
85
  if (this.status[item.key]) return
86
+ if (this.tooltip) return
54
87
 
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()
88
+ // setup tooltip
89
+ const tooltipCloseId = `lato-guide-close-${Math.random().toString(36).substring(7)}`
90
+ const tooltipTitle = `
91
+ <div class="px-2 py-2 d-flex align-items-center justify-content-between">
92
+ <p class="me-2 mb-0 text-start">${item.content}</p>
93
+ <a id="${tooltipCloseId}" class="btn btn-light btn-sm">Next</a>
94
+ </div>
95
+ `
96
+ this.tooltip = new bootstrap.Tooltip(item.element, { title: tooltipTitle, trigger: 'manual', html: true, customClass: 'lato-guide-tooltip' })
97
+ this.tooltip.itemKey = item.key
98
+
99
+ // listen to tooltip close
100
+ item.element.addEventListener('shown.bs.tooltip', () => {
101
+ setTimeout(() => {
102
+ document.getElementById(tooltipCloseId).addEventListener('click', () => {
103
+ this.tooltip.dispose()
104
+ this.tooltip = null
105
+ this.status[item.key] = true
106
+ this.storeStatus()
107
+ this.run()
108
+ })
109
+ }, 250)
79
110
  })
111
+ this.tooltip.show()
112
+
113
+ return true
80
114
  }
81
115
 
82
- storeStatus(e = null) {
83
- if (e) e.preventDefault()
116
+ storeStatus() {
84
117
  localStorage.setItem('lato_guide', JSON.stringify(this.status))
118
+
119
+ return true
85
120
  }
86
121
 
87
- resetStatus(e = null) {
88
- if (e) e.preventDefault()
122
+ resetStatus() {
89
123
  this.status = {}
90
124
  this.storeStatus()
91
- this.showGuide()
125
+
126
+ return true
127
+ }
128
+
129
+ /**
130
+ * Events
131
+ */
132
+
133
+ onDomChange(e) { // when page size changes (change of length of the document), we need to reposition the tooltip
134
+ if (this.tooltip) {
135
+ this.tooltip.update()
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.4"
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante