kommandant 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/builds/kommandant.css +634 -0
- data/app/assets/stylesheets/kommandant/application.tailwind.css +3 -0
- data/app/controllers/concerns/kommandant/recent_commands.rb +21 -0
- data/app/controllers/kommandant/application_controller.rb +6 -1
- data/app/controllers/kommandant/commands/searches_controller.rb +40 -0
- data/app/controllers/kommandant/commands_controller.rb +17 -0
- data/app/controllers/kommandant/searches_controller.rb +14 -0
- data/app/models/kommandant/command.rb +88 -0
- data/app/models/kommandant/commands/search_result.rb +44 -0
- data/app/views/kommandant/commands/searches/show.html.erb +69 -0
- data/app/views/kommandant/commands/show.html.erb +20 -0
- data/app/views/kommandant/searches/index.html.erb +1 -0
- data/app/views/kommandant/searches/new.html.erb +1 -0
- data/app/views/kommandant/shared/_command_palette.html.erb +53 -0
- data/app/views/kommandant/shared/command_palette/_command.html.erb +14 -0
- data/app/views/kommandant/shared/command_palette/_default_state.html.erb +14 -0
- data/app/views/kommandant/shared/command_palette/_empty_state.html.erb +7 -0
- data/app/views/kommandant/shared/command_palette/_loading_message.html.erb +7 -0
- data/app/views/kommandant/shared/command_palette/_result.html.erb +6 -0
- data/app/views/kommandant/shared/icons/_chevron_right.html.erb +3 -0
- data/app/views/kommandant/shared/icons/_command.erb +7 -0
- data/app/views/kommandant/shared/icons/_search.erb +3 -0
- data/app/views/kommandant/shared/icons/_spinner.erb +4 -0
- data/config/locales/da.yml +19 -0
- data/config/locales/en.yml +19 -0
- data/config/routes.rb +4 -0
- data/lib/kommandant/engine.rb +7 -0
- data/lib/kommandant/version.rb +1 -1
- data/lib/kommandant.rb +21 -1
- data/vendor/assets/javascripts/command_palette.js +120 -0
- data/vendor/assets/javascripts/keyboard_navigation.js +72 -0
- data/vendor/assets/javascripts/kommandant.js +2 -0
- data/vendor/assets/javascripts/transition.js +57 -0
- metadata +93 -3
@@ -0,0 +1,72 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
static targets = ["focusable"]
|
5
|
+
static values = { activeOptionIndex: { type: Number, default: 0 } }
|
6
|
+
|
7
|
+
connect() {
|
8
|
+
if (this.activeOption) {
|
9
|
+
this.activateOption()
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
down(event) {
|
14
|
+
event.preventDefault()
|
15
|
+
|
16
|
+
if (this.activeOptionIndexValue < (this.focusableTargets.length - 1)) {
|
17
|
+
this.deactivateOption()
|
18
|
+
this.activeOptionIndexValue++
|
19
|
+
this.activateOption()
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
up(event) {
|
24
|
+
event.preventDefault()
|
25
|
+
|
26
|
+
if (this.activeOptionIndexValue > 0) {
|
27
|
+
this.deactivateOption()
|
28
|
+
this.activeOptionIndexValue--
|
29
|
+
this.activateOption()
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
focus(event) {
|
34
|
+
this.deactivateOption()
|
35
|
+
this.activeOptionIndexValue = this.focusableTargets.indexOf(event.currentTarget)
|
36
|
+
this.activateOption()
|
37
|
+
}
|
38
|
+
|
39
|
+
select(event) {
|
40
|
+
if (this.hasFocusableTarget && this.focusableTargetIsVisible) {
|
41
|
+
event.preventDefault()
|
42
|
+
|
43
|
+
this.activeOption.click()
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
// Private
|
48
|
+
|
49
|
+
deactivateOption() {
|
50
|
+
this.activeOption.dataset.active = false
|
51
|
+
}
|
52
|
+
|
53
|
+
activateOption() {
|
54
|
+
this.activeOption.dataset.active = true
|
55
|
+
}
|
56
|
+
|
57
|
+
focusableTargetDisconnected() {
|
58
|
+
this.activeOptionIndexValue = 0
|
59
|
+
}
|
60
|
+
|
61
|
+
focusableTargetConnected() {
|
62
|
+
this.activateOption()
|
63
|
+
}
|
64
|
+
|
65
|
+
get activeOption() {
|
66
|
+
return this.focusableTargets[this.activeOptionIndexValue]
|
67
|
+
}
|
68
|
+
|
69
|
+
get focusableTargetIsVisible() {
|
70
|
+
return this.focusableTarget.offsetParent !== null
|
71
|
+
}
|
72
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
// This was taken from https://github.com/mmccall10/el-transition but is included here to avoid the need for a separate package
|
2
|
+
|
3
|
+
export async function enter(element, transitionName = null) {
|
4
|
+
element.classList.remove('hidden')
|
5
|
+
await transition('enter', element, transitionName)
|
6
|
+
}
|
7
|
+
|
8
|
+
export async function leave(element, transitionName = null) {
|
9
|
+
await transition('leave', element, transitionName)
|
10
|
+
element.classList.add('hidden')
|
11
|
+
}
|
12
|
+
|
13
|
+
export async function toggle(element, transitionName = null) {
|
14
|
+
if (element.classList.contains('hidden')) {
|
15
|
+
await enter(element, transitionName)
|
16
|
+
} else {
|
17
|
+
await leave(element, transitionName)
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
async function transition(direction, element, animation) {
|
22
|
+
const dataset = element.dataset
|
23
|
+
const animationClass = animation ? `${animation}-${direction}` : direction
|
24
|
+
let transition = `transition${direction.charAt(0).toUpperCase() + direction.slice(1)}`
|
25
|
+
const genesis = dataset[transition] ? dataset[transition].split(" ") : [animationClass]
|
26
|
+
const start = dataset[`${transition}Start`] ? dataset[`${transition}Start`].split(" ") : [`${animationClass}-start`]
|
27
|
+
const end = dataset[`${transition}End`] ? dataset[`${transition}End`].split(" ") : [`${animationClass}-end`]
|
28
|
+
|
29
|
+
addClasses(element, genesis)
|
30
|
+
addClasses(element, start)
|
31
|
+
await nextFrame()
|
32
|
+
removeClasses(element, start)
|
33
|
+
addClasses(element, end);
|
34
|
+
await afterTransition(element)
|
35
|
+
removeClasses(element, end)
|
36
|
+
removeClasses(element, genesis)
|
37
|
+
}
|
38
|
+
|
39
|
+
function addClasses(element, classes) {
|
40
|
+
element.classList.add(...classes)
|
41
|
+
}
|
42
|
+
|
43
|
+
function removeClasses(element, classes) {
|
44
|
+
element.classList.remove(...classes)
|
45
|
+
}
|
46
|
+
|
47
|
+
function nextFrame() {
|
48
|
+
return new Promise(resolve => {
|
49
|
+
requestAnimationFrame(() => {
|
50
|
+
requestAnimationFrame(resolve)
|
51
|
+
});
|
52
|
+
});
|
53
|
+
}
|
54
|
+
|
55
|
+
function afterTransition(element) {
|
56
|
+
return Promise.all(element.getAnimations().map(animation => animation.finished));
|
57
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kommandant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolai Bach Woller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,68 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.0.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: meilisearch-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: turbo-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-configurable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.0.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.0.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: tailwindcss-rails
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.0.30
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.0.30
|
27
89
|
description: A command palette built with Hotwire and Meilisearch
|
28
90
|
email:
|
29
91
|
- woller@traels.it
|
@@ -34,19 +96,47 @@ files:
|
|
34
96
|
- MIT-LICENSE
|
35
97
|
- README.md
|
36
98
|
- Rakefile
|
99
|
+
- app/assets/builds/kommandant.css
|
37
100
|
- app/assets/config/kommandant_manifest.js
|
38
101
|
- app/assets/stylesheets/kommandant/application.css
|
102
|
+
- app/assets/stylesheets/kommandant/application.tailwind.css
|
103
|
+
- app/controllers/concerns/kommandant/recent_commands.rb
|
39
104
|
- app/controllers/kommandant/application_controller.rb
|
105
|
+
- app/controllers/kommandant/commands/searches_controller.rb
|
106
|
+
- app/controllers/kommandant/commands_controller.rb
|
107
|
+
- app/controllers/kommandant/searches_controller.rb
|
40
108
|
- app/helpers/kommandant/application_helper.rb
|
41
109
|
- app/jobs/kommandant/application_job.rb
|
42
110
|
- app/mailers/kommandant/application_mailer.rb
|
43
111
|
- app/models/kommandant/application_record.rb
|
112
|
+
- app/models/kommandant/command.rb
|
113
|
+
- app/models/kommandant/commands/search_result.rb
|
114
|
+
- app/views/kommandant/commands/searches/show.html.erb
|
115
|
+
- app/views/kommandant/commands/show.html.erb
|
116
|
+
- app/views/kommandant/searches/index.html.erb
|
117
|
+
- app/views/kommandant/searches/new.html.erb
|
118
|
+
- app/views/kommandant/shared/_command_palette.html.erb
|
119
|
+
- app/views/kommandant/shared/command_palette/_command.html.erb
|
120
|
+
- app/views/kommandant/shared/command_palette/_default_state.html.erb
|
121
|
+
- app/views/kommandant/shared/command_palette/_empty_state.html.erb
|
122
|
+
- app/views/kommandant/shared/command_palette/_loading_message.html.erb
|
123
|
+
- app/views/kommandant/shared/command_palette/_result.html.erb
|
124
|
+
- app/views/kommandant/shared/icons/_chevron_right.html.erb
|
125
|
+
- app/views/kommandant/shared/icons/_command.erb
|
126
|
+
- app/views/kommandant/shared/icons/_search.erb
|
127
|
+
- app/views/kommandant/shared/icons/_spinner.erb
|
44
128
|
- app/views/layouts/kommandant/application.html.erb
|
129
|
+
- config/locales/da.yml
|
130
|
+
- config/locales/en.yml
|
45
131
|
- config/routes.rb
|
46
132
|
- lib/kommandant.rb
|
47
133
|
- lib/kommandant/engine.rb
|
48
134
|
- lib/kommandant/version.rb
|
49
135
|
- lib/tasks/kommandant_tasks.rake
|
136
|
+
- vendor/assets/javascripts/command_palette.js
|
137
|
+
- vendor/assets/javascripts/keyboard_navigation.js
|
138
|
+
- vendor/assets/javascripts/kommandant.js
|
139
|
+
- vendor/assets/javascripts/transition.js
|
50
140
|
homepage: https://traels.it
|
51
141
|
licenses:
|
52
142
|
- MIT
|
@@ -68,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
158
|
- !ruby/object:Gem::Version
|
69
159
|
version: '0'
|
70
160
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
161
|
+
rubygems_version: 3.5.6
|
72
162
|
signing_key:
|
73
163
|
specification_version: 4
|
74
164
|
summary: A command palette for Rails
|