lato 3.8.1 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/lato/controllers/lato_input_autocomplete2_controller.js +115 -0
- data/app/assets/javascripts/lato/controllers/lato_input_autocomplete_controller.js +1 -1
- data/app/views/layouts/lato/application.html.erb +1 -1
- data/lib/lato/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c10619ad47c6b8d2300673db8875efccd74a6b31c0f831384590b137e679329
|
4
|
+
data.tar.gz: 99551763a78949b665938487a5be4ac0dec5c873b23788838574aa1a955affa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85e1478ee97be8b46f57dd8b771c549f87092856f5bce9aa72e71c41545e5c37cb1ae3d31ffa5c2478fcf8018c09ea69a5df7948ee9af6aa612a0a8e1110170f
|
7
|
+
data.tar.gz: 76b35dc8048537b9f37d792a0442b72b0989be7c3028d77f1c7b774c6af90434ea4b62a9f1ba09f9a5e3de05468d094e60f93712b47cd7e8e5e1d94a0aa3cf00
|
@@ -0,0 +1,115 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
import _ from 'lodash'
|
3
|
+
|
4
|
+
export default class extends Controller {
|
5
|
+
static values = {
|
6
|
+
path: String
|
7
|
+
}
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Stimulus
|
11
|
+
*/
|
12
|
+
|
13
|
+
connect() {
|
14
|
+
this.search = _.debounce(this.search, 500)
|
15
|
+
|
16
|
+
this.realInput = document.createElement('input')
|
17
|
+
this.realInput.type = 'hidden'
|
18
|
+
this.realInput.name = this.element.getAttribute('name')
|
19
|
+
this.realInput.value = this.element.value
|
20
|
+
this.element.insertAdjacentElement('afterend', this.realInput)
|
21
|
+
|
22
|
+
if (this.element.value) {
|
23
|
+
this.setDefaultElementValue()
|
24
|
+
}
|
25
|
+
|
26
|
+
this.element.addEventListener('keyup', (e) => {
|
27
|
+
this.search(e.target.value)
|
28
|
+
})
|
29
|
+
|
30
|
+
window.addEventListener('click', this.onWindowClick.bind(this))
|
31
|
+
window.addEventListener('scroll', this.onWindowScroll.bind(this))
|
32
|
+
window.addEventListener('resize', this.onWindowResize.bind(this))
|
33
|
+
}
|
34
|
+
|
35
|
+
disconnect() {
|
36
|
+
this.realInput.remove()
|
37
|
+
this.suggestHide()
|
38
|
+
|
39
|
+
window.removeEventListener('click', this.onWindowClick.bind(this))
|
40
|
+
window.removeEventListener('scroll', this.onWindowScroll.bind(this))
|
41
|
+
window.removeEventListener('resize', this.onWindowResize.bind(this))
|
42
|
+
}
|
43
|
+
|
44
|
+
async search(value) {
|
45
|
+
this.realInput.value = ''
|
46
|
+
if (!value || value.length < 3) return
|
47
|
+
|
48
|
+
try {
|
49
|
+
const response = await fetch(this.pathValue + '?q=' + value)
|
50
|
+
const data = await response.json()
|
51
|
+
this.suggestShow(data)
|
52
|
+
} catch (err) {
|
53
|
+
console.error(err)
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
suggestShow(data = []) {
|
58
|
+
if (this.optionsList) this.optionsList.remove()
|
59
|
+
this.optionsList = document.createElement('ul')
|
60
|
+
this.optionsList.classList.add('list-group')
|
61
|
+
this.optionsList.style.position = 'fixed'
|
62
|
+
this.optionsList.style.width = this.element.offsetWidth + 'px'
|
63
|
+
this.optionsList.style.maxHeight = '200px'
|
64
|
+
this.optionsList.style.overflowY = 'auto'
|
65
|
+
this.optionsList.style.zIndex = 9999
|
66
|
+
|
67
|
+
const elementRect = this.element.getBoundingClientRect()
|
68
|
+
this.optionsList.style.top = elementRect.bottom + 'px'
|
69
|
+
this.optionsList.style.left = elementRect.left + 'px'
|
70
|
+
|
71
|
+
data.forEach((option) => {
|
72
|
+
const li = document.createElement('li')
|
73
|
+
li.classList.add('list-group-item')
|
74
|
+
li.classList.add('list-group-item-action')
|
75
|
+
li.style.cursor = 'pointer'
|
76
|
+
li.innerText = typeof option == 'string' ? option : option.label
|
77
|
+
li.addEventListener('click', () => {
|
78
|
+
this.element.value = typeof option == 'string' ? option : option.label
|
79
|
+
this.realInput.value = typeof option == 'string' ? option : option.value
|
80
|
+
this.suggestHide()
|
81
|
+
})
|
82
|
+
this.optionsList.appendChild(li)
|
83
|
+
})
|
84
|
+
|
85
|
+
document.body.appendChild(this.optionsList)
|
86
|
+
}
|
87
|
+
|
88
|
+
suggestHide() {
|
89
|
+
if (this.optionsList) this.optionsList.remove()
|
90
|
+
}
|
91
|
+
|
92
|
+
async setDefaultElementValue() {
|
93
|
+
try {
|
94
|
+
const response = await fetch(this.pathValue + '?value=' + this.element.value)
|
95
|
+
const data = await response.json()
|
96
|
+
this.element.value = data?.label || this.element.value
|
97
|
+
} catch (err) {
|
98
|
+
console.error(err)
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
onWindowClick(event) {
|
103
|
+
if (!this.element.contains(event.target)) {
|
104
|
+
this.suggestHide()
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
onWindowScroll(event) {
|
109
|
+
this.suggestHide()
|
110
|
+
}
|
111
|
+
|
112
|
+
onWindowResize(event) {
|
113
|
+
this.suggestHide()
|
114
|
+
}
|
115
|
+
}
|
data/lib/lato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregorio Galante
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- app/assets/javascripts/lato/controllers/lato_feedback_controller.js
|
160
160
|
- app/assets/javascripts/lato/controllers/lato_form_controller.js
|
161
161
|
- app/assets/javascripts/lato/controllers/lato_hello_controller.js
|
162
|
+
- app/assets/javascripts/lato/controllers/lato_input_autocomplete2_controller.js
|
162
163
|
- app/assets/javascripts/lato/controllers/lato_input_autocomplete_controller.js
|
163
164
|
- app/assets/javascripts/lato/controllers/lato_network_controller.js
|
164
165
|
- app/assets/javascripts/lato/controllers/lato_operation_controller.js
|