atomic_view 0.1.15 → 0.1.16

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: bada6883ff0ebcfb57bb0cf9f153c8c978bd32601b3371d0a5db2db02a57fab3
4
- data.tar.gz: 59a99dd072921000d4dc906eafcc2d51b4638a7f78b625fd53e8c82dfe1017e6
3
+ metadata.gz: 815b41e5c66fe63cac96239f8d90cfdfa137da236e27f0d8577bdee068e35ce7
4
+ data.tar.gz: f4e735119fefc770222c595c49dd4031b43a64b2dcec004417bae2a610b9524e
5
5
  SHA512:
6
- metadata.gz: 2bd3d154f20a387d44c6fd2fbf30c6c00ca790ae8a4531d92c69291ed0a1f1c0cad1313a0807c9d576bec552e4faa297d3acab6be83feb7c14e4227440a228c6
7
- data.tar.gz: 77657284d3f55f498dda813f30542b65077c979804ef0d64fed520162ab0e154c6b58a7719ef345d516e4d58f66e013adc6b839ec5b180570a74b9c1658f1bfd
6
+ metadata.gz: d013eb53df0f79b51f6be0d0fcb167f52f2621a5dde41bad2385df742d426e44d68f7422bc4b697ff43db623797fe350c4cdf3f8549872492804c488c9cdcf3e
7
+ data.tar.gz: 0efc941867d3a932de3de2f98ef8318260a5c9df7b100406e5e4074dff38da2fe6cdbb55360a82b89b89ea350c205e52761bffd8f6483f280970a11c045491be
@@ -1,18 +1,24 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
- static targets = ["input", "row"]
4
+ static targets = ["input", "row", "section"]
5
5
 
6
6
  highlightedIndex = null
7
7
 
8
8
  connect() {
9
9
  document.addEventListener("keydown", this.onGlobalKeydown)
10
10
  this.element.addEventListener("close", this.onClose)
11
+ this.element.addEventListener("click", this.closeOnBackdrop)
11
12
  }
12
13
 
13
14
  disconnect() {
14
15
  document.removeEventListener("keydown", this.onGlobalKeydown)
15
16
  this.element.removeEventListener("close", this.onClose)
17
+ this.element.removeEventListener("click", this.closeOnBackdrop)
18
+ }
19
+
20
+ closeOnBackdrop = (event) => {
21
+ if (event.target === this.element) this.element.close()
16
22
  }
17
23
 
18
24
  onGlobalKeydown = (event) => {
@@ -25,6 +31,7 @@ export default class extends Controller {
25
31
  onClose = () => {
26
32
  this.inputTarget.value = ""
27
33
  this.rowTargets.forEach((row) => row.classList.remove("hidden"))
34
+ this.sectionTargets.forEach((section) => section.classList.remove("hidden"))
28
35
  this.clearHighlight()
29
36
  }
30
37
 
@@ -36,6 +43,14 @@ export default class extends Controller {
36
43
  row.classList.toggle("hidden", !matches)
37
44
  })
38
45
 
46
+ // Hide a section immediately once every one of its rows is filtered
47
+ // out, rather than leaving its (now empty) label dangling until the
48
+ // server-side Turbo Stream search catches up.
49
+ this.sectionTargets.forEach((section) => {
50
+ const hasVisibleRow = this.rowTargets.some((row) => section.contains(row) && !row.classList.contains("hidden"))
51
+ section.classList.toggle("hidden", !hasVisibleRow)
52
+ })
53
+
39
54
  this.clearHighlight()
40
55
  }
41
56
 
@@ -1,7 +1,7 @@
1
- <div role="group">
1
+ <%= tag.div(role: "group", data: data_attributes) do %>
2
2
  <p class="px-3 pb-1 pt-2 text-xs font-semibold uppercase text-muted-foreground select-none"><%= label %></p>
3
3
 
4
4
  <% rows.each do |row| %>
5
5
  <%= row %>
6
6
  <% end %>
7
- </div>
7
+ <% end %>
@@ -18,6 +18,10 @@ module AtomicView
18
18
  @options = options
19
19
  results.each { |result| with_row(**result) }
20
20
  end
21
+
22
+ def data_attributes
23
+ (@options[:data] || {}).merge("atomic-view--command-palette-target" => "section")
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtomicView
4
- VERSION = "0.1.15"
4
+ VERSION = "0.1.16"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Warrington