lato 0.1.47 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd2a16b3cd379e5f7c8fc085e35c16a1111ecfd1e2284ce8c055d8a42f52b242
4
- data.tar.gz: 1c05f2dd442acb6a2d5139474634c2cd79e97a3c716e13fb95428b5ae5af52de
3
+ metadata.gz: 1b950d52eacb976f1c5c268d08e601c3a4c5cd3b3c92b5bdedc56ef5ba0daeb8
4
+ data.tar.gz: 99410bc99efc35de36892b57d19d768d94cf7489867b5d0fef82f7d8ca604b5d
5
5
  SHA512:
6
- metadata.gz: ef997bd4a6a83abed77335af0a80e3466e3457864b8c35b203a36814ca6bde3054fded2471164518fd8ddbc2b9b95919bb4d11a98e965ecde84f59b0a5a66d1b
7
- data.tar.gz: 5925fa2fd8c4e077ce9d8d3281e48eade697567d5ac4ea1788e65b6e917bdbea13f41e4f3523e67df7472b9c63890e9dea8b03ec940d14061890b01bae31f94e
6
+ metadata.gz: 3b232a44f90d3f38f7d0e8321d2085a9d7d7bf7a4aae52ed0160d2cb8d2b654f2e549164eb3e0c15c8623e9f30b097f736d5e96838fb61109a25fceeece75536
7
+ data.tar.gz: '0588148e4e64b91b9b92ab609ab95439ab3a08e1e5bfd1d661166f4654cbebdf913dc69b035a0b00027907870e8d5b5214c38a8f1b3ceb8e48c994783224ecdb'
@@ -0,0 +1,51 @@
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
+ this.datalist = document.createElement('datalist')
16
+ this.datalist.id = Math.random().toString(36)
17
+ this.element.setAttribute('list', this.datalist.id)
18
+ this.element.parentNode.appendChild(this.datalist)
19
+
20
+ this.element.addEventListener('keyup', (e) => {
21
+ this.search(e.target.value)
22
+ })
23
+ }
24
+
25
+ async search(value) {
26
+ if (!value || value.length < 3) return this.clear()
27
+
28
+ try {
29
+ const response = await fetch(this.pathValue + '?q=' + value)
30
+ const data = await response.json()
31
+ this.suggest(data)
32
+ } catch (err) {
33
+ console.error(err)
34
+ this.clear()
35
+ }
36
+ }
37
+
38
+ suggest(data = []) {
39
+ this.clear()
40
+
41
+ data.forEach((item) => {
42
+ const option = document.createElement('option')
43
+ option.value = item
44
+ this.datalist.appendChild(option)
45
+ })
46
+ }
47
+
48
+ clear() {
49
+ this.datalist.innerHTML = ''
50
+ }
51
+ }
data/config/importmap.rb CHANGED
@@ -3,3 +3,4 @@ pin_all_from Lato::Engine.root.join("app/assets/javascripts/lato/controllers"),
3
3
 
4
4
  pin "bootstrap", to: "bootstrap.js", preload: true
5
5
  # pin "@popperjs/core", to: "popper.js", preload: true
6
+ pin "lodash", to: "https://ga.jspm.io/npm:lodash@4.17.21/lodash.js"
data/lib/lato/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lato
2
- VERSION = "0.1.47"
2
+ VERSION = "0.1.48"
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: 0.1.47
4
+ version: 0.1.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
@@ -117,6 +117,7 @@ files:
117
117
  - app/assets/javascripts/lato/controllers/lato_feedback_controller.js
118
118
  - app/assets/javascripts/lato/controllers/lato_form_controller.js
119
119
  - app/assets/javascripts/lato/controllers/lato_hello_controller.js
120
+ - app/assets/javascripts/lato/controllers/lato_input_autocomplete_controller.js
120
121
  - app/assets/javascripts/lato/controllers/lato_operation_controller.js
121
122
  - app/assets/stylesheets/lato/application.scss
122
123
  - app/controllers/concerns/lato/componentable.rb