phlex-cmdk 0.1.0 → 0.1.1

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: 64fd7358d8d5c71ef5038a191b08dd08f735ac5cd64319ba65617591b9fd5944
4
- data.tar.gz: 796d52044bd196d61bdab9da53752a3fd1b12eac2612656531449506d67cd348
3
+ metadata.gz: 9c7f8212512b7ffc57adcf7d2428fb10994947b10cc82e920ff8b08d034255eb
4
+ data.tar.gz: 2ec4b781453015d628ff1976b0047a85195980b3584c7eaddc9e2672051e3586
5
5
  SHA512:
6
- metadata.gz: 980b9a9b18c6965cf967a5f0fc1580294879f46f8a657dd3178bc7fd86f8f6dde2fefadb5b12604fefaa27cb188b9096fb44690419b1690b584e4c9feb666172
7
- data.tar.gz: 7cb81bd470337f4278bf1388b47c39dcf127b76fbe6cb44f84737335d43c9fa20ffad6e55fa7b2de2a1c8275915861beaa074e40a4f035ec677e876bf545b73f
6
+ metadata.gz: f2bba3534f26915215bb0fea83fc2e5c5126d4ad34510997d932125693921c2374749d921043a6a65de8f0a9d3ef6082d8053224ca2fc6fc090d71010bb92db6
7
+ data.tar.gz: 6e1623684909b42f34634bd5bc037aa14266544b88b2ede7733d4899e878e843b415a1dd1a1d31ffb407f43bd925787f77e5839cf12551ac71952823fbfe840f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1 — 2026-06-15
4
+
5
+ - docs: correct the Stimulus base controller import (the bare `cmdk`
6
+ specifier, not `./cmdk.js`); document `dialog_attributes:` and the
7
+ `cmdk-dialog-frame` theme class
8
+ - internal: idiomatic Phlex content-block forwarding; deterministic group
9
+ heading ids (monotonic, replacing a random suffix). No markup or API changes.
10
+
3
11
  ## 0.1.0 — 2026-06-15
4
12
 
5
13
  Initial release: a feature-parity Phlex port of the cmdk React command menu.
data/README.md CHANGED
@@ -147,6 +147,20 @@ Renders a native `<dialog cmdk-dialog>`: Escape and backdrop clicks close it, an
147
147
  `Cmdk.openDialog(el)` / `Cmdk.closeDialog(el)` toggle it programmatically. Style the
148
148
  backdrop with `dialog[cmdk-dialog]::backdrop` (replaces Radix's `[cmdk-overlay]`).
149
149
 
150
+ Extra attributes on `Cmdk::Dialog(...)` go to the inner `Cmdk::Root`; to set
151
+ attributes on the `<dialog>` element itself, pass `dialog_attributes:`. The
152
+ shipped themes style the dialog frame (transparent border, entry animation)
153
+ behind a `cmdk-dialog-frame` class, opt in the same way you opt into the menu
154
+ theme - by asking for the class:
155
+
156
+ ```ruby
157
+ Cmdk::Dialog(label: 'Command Menu', hotkey: 'k', class: 'cmdk',
158
+ dialog_attributes: { class: 'cmdk-dialog-frame' }) do
159
+ Cmdk::Input()
160
+ Cmdk::List() { ... }
161
+ end
162
+ ```
163
+
150
164
  By default the dialog renders as a top-third, horizontally centered palette; on
151
165
  viewports ≤640px it becomes a top-anchored, full-width sheet (the GitHub/Jira
152
166
  pattern - the software keyboard owns the bottom of the screen, so the input
@@ -280,7 +294,8 @@ The bubbling events work with plain action descriptors - no controller required:
280
294
 
281
295
  For more structure, the gem ships an optional base controller
282
296
  (`Cmdk.stimulus_controller_path`; serve it next to the runtime, it imports
283
- `./cmdk.js` and `@hotwired/stimulus`). Extend it and override the hooks:
297
+ the runtime as the bare specifier `cmdk` and `@hotwired/stimulus`). Extend it
298
+ and override the hooks:
284
299
 
285
300
  ```js
286
301
  import CmdkController from 'cmdk_controller' // pin to Cmdk.stimulus_controller_path
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Extend it and override the hooks you care about:
10
10
  *
11
- * import CmdkController from 'phlex-cmdk/controller' // or the copied file
11
+ * import CmdkController from 'cmdk_controller' // pin to Cmdk.stimulus_controller_path
12
12
  *
13
13
  * export default class extends CmdkController {
14
14
  * itemSelected({ detail: { value } }) { this.runCommand(value) }
data/lib/cmdk/base.rb CHANGED
@@ -10,6 +10,12 @@ module Cmdk
10
10
  # Merge user-supplied attributes into the component's defaults.
11
11
  # User values win, except `class` and `style` which are concatenated
12
12
  # and `data` hashes which are merged.
13
+ #
14
+ # Deliberately not Phlex's `mix`: `mix` treats *every* attribute as a
15
+ # token list (e.g. `mix({role: 'option'}, {role: 'button'})` yields
16
+ # `role: 'option button'`), which is wrong for scalar attributes like
17
+ # `role`/`type`/`tabindex`/`aria-selected` that should be replaced, not
18
+ # appended. Here only `class`/`style`/`data` combine; other scalars override.
13
19
  def merged(defaults, overrides)
14
20
  defaults.merge(overrides) do |key, default, override|
15
21
  case key
data/lib/cmdk/empty.rb CHANGED
@@ -9,7 +9,7 @@ module Cmdk
9
9
 
10
10
  def view_template(&block)
11
11
  defaults = { 'cmdk-empty' => '', role: 'presentation', style: 'display:none' }
12
- div(**merged(defaults, @attributes)) { block ? block.call : nil }
12
+ div(**merged(defaults, @attributes), &block)
13
13
  end
14
14
  end
15
15
  end
data/lib/cmdk/footer.rb CHANGED
@@ -19,11 +19,7 @@ module Cmdk
19
19
 
20
20
  def view_template(&block)
21
21
  div(**merged({ 'cmdk-footer' => '' }, @attributes)) do
22
- if block
23
- block.call
24
- else
25
- div('cmdk-footer-hint' => '')
26
- end
22
+ block ? block.call : div('cmdk-footer-hint' => '')
27
23
  end
28
24
  end
29
25
  end
data/lib/cmdk/group.rb CHANGED
@@ -1,10 +1,18 @@
1
- require 'securerandom'
2
-
3
1
  module Cmdk
4
2
  # Groups items together with an optional heading. Port of `<Command.Group>`.
5
3
  # Provide `value:` when there is no heading (it is used for sorting groups);
6
4
  # with a string heading the value is inferred from it, matching React cmdk.
7
5
  class Group < Base
6
+ # Monotonic id source for `aria-labelledby` (the analog of React's useId,
7
+ # which this port mirrors). Deterministic and collision-free, unlike a
8
+ # random suffix; the mutex keeps it correct under threaded servers.
9
+ @heading_seq = 0
10
+ @heading_mutex = Mutex.new
11
+
12
+ def self.next_heading_id
13
+ @heading_mutex.synchronize { "cmdk-heading-#{@heading_seq += 1}" }
14
+ end
15
+
8
16
  def initialize(heading: nil, value: nil, force_mount: false, scope: nil, scope_only: false,
9
17
  server_filtered: false, **attributes)
10
18
  @heading = heading
@@ -17,15 +25,13 @@ module Cmdk
17
25
  end
18
26
 
19
27
  def view_template(&block)
20
- heading_id = @heading ? "cmdk-heading-#{SecureRandom.hex(4)}" : nil
28
+ heading_id = @heading ? Group.next_heading_id : nil
21
29
 
22
30
  div(**merged(group_attributes, @attributes)) do
23
31
  if @heading
24
32
  div('cmdk-group-heading' => '', aria_hidden: 'true', id: heading_id) { @heading }
25
33
  end
26
- div('cmdk-group-items' => '', role: 'group', aria_labelledby: heading_id) do
27
- block ? block.call : nil
28
- end
34
+ div('cmdk-group-items' => '', role: 'group', aria_labelledby: heading_id, &block)
29
35
  end
30
36
  end
31
37
 
data/lib/cmdk/item.rb CHANGED
@@ -24,7 +24,7 @@ module Cmdk
24
24
  end
25
25
 
26
26
  def view_template(&block)
27
- div(**merged(item_attributes, @attributes)) { block ? block.call : nil }
27
+ div(**merged(item_attributes, @attributes), &block)
28
28
  end
29
29
 
30
30
  private
data/lib/cmdk/list.rb CHANGED
@@ -10,7 +10,7 @@ module Cmdk
10
10
 
11
11
  def view_template(&block)
12
12
  div(**merged({ 'cmdk-list' => '', role: 'listbox', tabindex: '-1', aria_label: @label }, @attributes)) do
13
- div('cmdk-list-sizer' => '') { block ? block.call : nil }
13
+ div('cmdk-list-sizer' => '', &block)
14
14
  end
15
15
  end
16
16
  end
data/lib/cmdk/loading.rb CHANGED
@@ -18,7 +18,7 @@ module Cmdk
18
18
  aria_label: @label
19
19
  }
20
20
  div(**merged(defaults, @attributes)) do
21
- div(aria_hidden: 'true') { block ? block.call : nil }
21
+ div(aria_hidden: 'true', &block)
22
22
  end
23
23
  end
24
24
  end
data/lib/cmdk/root.rb CHANGED
@@ -33,16 +33,12 @@ module Cmdk
33
33
  def view_template(&block)
34
34
  div(**merged(root_attributes, @attributes)) do
35
35
  label('cmdk-label' => '', style: SR_ONLY_STYLE) { @label }
36
- yield_content(&block)
36
+ block&.call
37
37
  end
38
38
  end
39
39
 
40
40
  private
41
41
 
42
- def yield_content(&block)
43
- block ? block.call : nil
44
- end
45
-
46
42
  def root_attributes
47
43
  data = {}
48
44
  data[:cmdk_should_filter] = 'false' unless @should_filter
data/lib/cmdk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cmdk
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-cmdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Gieser
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-06-15 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: phlex
@@ -67,6 +68,7 @@ metadata:
67
68
  source_code_uri: https://github.com/leongieser/phlex-cmdk
68
69
  changelog_uri: https://github.com/leongieser/phlex-cmdk/blob/main/CHANGELOG.md
69
70
  rubygems_mfa_required: 'true'
71
+ post_install_message:
70
72
  rdoc_options: []
71
73
  require_paths:
72
74
  - lib
@@ -81,7 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  requirements: []
84
- rubygems_version: 4.0.10
86
+ rubygems_version: 3.0.3.1
87
+ signing_key:
85
88
  specification_version: 4
86
89
  summary: 'Fast, composable command menu for Phlex: a port of cmdk (React).'
87
90
  test_files: []