shadcn_phlexcomponents 0.1.17 → 0.1.18
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 +4 -4
- data/app/javascript/controllers/accordion_controller.js +90 -100
- data/app/javascript/controllers/alert_dialog_controller.js +4 -4
- data/app/javascript/controllers/avatar_controller.js +11 -11
- data/app/javascript/controllers/checkbox_controller.js +26 -25
- data/app/javascript/controllers/collapsible_controller.js +36 -34
- data/app/javascript/controllers/combobox_controller.js +231 -262
- data/app/javascript/controllers/command_controller.js +184 -204
- data/app/javascript/controllers/date_picker_controller.js +257 -240
- data/app/javascript/controllers/date_range_picker_controller.js +200 -188
- data/app/javascript/controllers/dialog_controller.js +78 -78
- data/app/javascript/controllers/dropdown_menu_controller.js +208 -228
- data/app/javascript/controllers/dropdown_menu_sub_controller.js +97 -110
- data/app/javascript/controllers/form_field_controller.js +16 -16
- data/app/javascript/controllers/hover_card_controller.js +71 -68
- data/app/javascript/controllers/loading_button_controller.js +10 -10
- data/app/javascript/controllers/popover_controller.js +78 -84
- data/app/javascript/controllers/progress_controller.js +11 -11
- data/app/javascript/controllers/radio_group_controller.js +74 -74
- data/app/javascript/controllers/select_controller.js +232 -246
- data/app/javascript/controllers/sidebar_controller.js +27 -26
- data/app/javascript/controllers/sidebar_trigger_controller.js +9 -12
- data/app/javascript/controllers/slider_controller.js +74 -73
- data/app/javascript/controllers/switch_controller.js +23 -22
- data/app/javascript/controllers/tabs_controller.js +61 -60
- data/app/javascript/controllers/theme_switcher_controller.js +27 -27
- data/app/javascript/controllers/toast_container_controller.js +31 -44
- data/app/javascript/controllers/toast_controller.js +18 -18
- data/app/javascript/controllers/toggle_controller.js +17 -16
- data/app/javascript/controllers/toggle_group_controller.js +17 -16
- data/app/javascript/controllers/tooltip_controller.js +77 -74
- data/app/javascript/shadcn_phlexcomponents.js +58 -58
- data/app/javascript/utils/command.js +334 -392
- data/app/javascript/utils/floating_ui.js +108 -147
- data/app/javascript/utils/index.js +190 -253
- data/app/stylesheets/date_picker.css +1 -1
- data/app/stylesheets/shadcn_phlexcomponents.css +173 -0
- data/app/typescript/controllers/combobox_controller.ts +0 -1
- data/app/typescript/controllers/date_picker_controller.ts +25 -7
- data/app/typescript/controllers/tooltip_controller.ts +1 -1
- data/app/typescript/utils/command.ts +0 -2
- data/app/typescript/utils/floating_ui.ts +11 -20
- data/app/typescript/utils/index.ts +0 -7
- data/lib/shadcn_phlexcomponents/components/accordion.rb +1 -1
- data/lib/shadcn_phlexcomponents/components/alert_dialog.rb +6 -6
- data/lib/shadcn_phlexcomponents/components/base.rb +2 -2
- data/lib/shadcn_phlexcomponents/components/combobox.rb +13 -13
- data/lib/shadcn_phlexcomponents/components/command.rb +13 -13
- data/lib/shadcn_phlexcomponents/components/date_picker.rb +18 -12
- data/lib/shadcn_phlexcomponents/components/date_range_picker.rb +7 -3
- data/lib/shadcn_phlexcomponents/components/dialog.rb +6 -6
- data/lib/shadcn_phlexcomponents/components/sheet.rb +7 -7
- data/lib/shadcn_phlexcomponents/components/toggle.rb +1 -1
- data/lib/shadcn_phlexcomponents/version.rb +1 -1
- metadata +2 -1
@@ -1,207 +1,187 @@
|
|
1
|
-
import hotkeys from
|
2
|
-
import { Controller } from
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
ON_OPEN_FOCUS_DELAY,
|
8
|
-
setGroupLabelsId,
|
9
|
-
} from "../utils";
|
10
|
-
import {
|
11
|
-
scrollToItem,
|
12
|
-
highlightItem,
|
13
|
-
highlightItemByIndex,
|
14
|
-
filteredItemsChanged,
|
15
|
-
setItemsGroupId,
|
16
|
-
search,
|
17
|
-
clearRemoteResults,
|
18
|
-
resetState,
|
19
|
-
hideError,
|
20
|
-
showList,
|
21
|
-
} from "../utils/command";
|
22
|
-
import { useDebounce, useClickOutside } from "stimulus-use";
|
23
|
-
import Fuse from "fuse.js";
|
1
|
+
import hotkeys from 'hotkeys-js';
|
2
|
+
import { Controller } from '@hotwired/stimulus';
|
3
|
+
import { showContent, hideContent, focusTrigger, ON_OPEN_FOCUS_DELAY, setGroupLabelsId, } from '../utils';
|
4
|
+
import { scrollToItem, highlightItem, highlightItemByIndex, filteredItemsChanged, setItemsGroupId, search, clearRemoteResults, resetState, hideError, showList, } from '../utils/command';
|
5
|
+
import { useDebounce, useClickOutside } from 'stimulus-use';
|
6
|
+
import Fuse from 'fuse.js';
|
24
7
|
const CommandController = class extends Controller {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
value
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
keybinds
|
165
|
-
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
this.abortController.abort();
|
204
|
-
}
|
205
|
-
}
|
8
|
+
// targets
|
9
|
+
static targets = [
|
10
|
+
'trigger',
|
11
|
+
'content',
|
12
|
+
'overlay',
|
13
|
+
'item',
|
14
|
+
'group',
|
15
|
+
'searchInput',
|
16
|
+
'list',
|
17
|
+
'listContainer',
|
18
|
+
'empty',
|
19
|
+
'modifierKey',
|
20
|
+
'loading',
|
21
|
+
'error',
|
22
|
+
];
|
23
|
+
// values
|
24
|
+
static values = {
|
25
|
+
isOpen: Boolean,
|
26
|
+
filteredItemIndexes: Array,
|
27
|
+
searchUrl: String,
|
28
|
+
};
|
29
|
+
static debounces = ['search'];
|
30
|
+
connect() {
|
31
|
+
this.orderedItems = [...this.itemTargets];
|
32
|
+
this.itemsInnerText = this.orderedItems.map((i) => i.innerText.trim());
|
33
|
+
this.fuse = new Fuse(this.itemsInnerText);
|
34
|
+
this.filteredItemIndexesValue = Array.from({ length: this.itemTargets.length }, (_, i) => i);
|
35
|
+
this.isLoading = false;
|
36
|
+
this.filteredItems = this.itemTargets;
|
37
|
+
this.isDirty = false;
|
38
|
+
this.searchPath = this.element.dataset.searchPath;
|
39
|
+
setGroupLabelsId(this);
|
40
|
+
setItemsGroupId(this);
|
41
|
+
useDebounce(this);
|
42
|
+
useClickOutside(this, { element: this.contentTarget, dispatchEvent: false });
|
43
|
+
this.hotkeyListener = this.onHotkeyPressed.bind(this);
|
44
|
+
this.DOMKeydownListener = this.onDOMKeydown.bind(this);
|
45
|
+
this.setupHotkeys();
|
46
|
+
this.replaceModifierKeyIcon();
|
47
|
+
}
|
48
|
+
open() {
|
49
|
+
this.isOpenValue = true;
|
50
|
+
this.highlightItemByIndex(0);
|
51
|
+
setTimeout(() => {
|
52
|
+
this.searchInputTarget.focus();
|
53
|
+
}, ON_OPEN_FOCUS_DELAY);
|
54
|
+
}
|
55
|
+
close() {
|
56
|
+
this.isOpenValue = false;
|
57
|
+
resetState(this);
|
58
|
+
}
|
59
|
+
scrollToItem(index) {
|
60
|
+
scrollToItem(this, index);
|
61
|
+
}
|
62
|
+
highlightItem(event = null, index = null) {
|
63
|
+
highlightItem(this, event, index);
|
64
|
+
}
|
65
|
+
highlightItemByIndex(index) {
|
66
|
+
highlightItemByIndex(this, index);
|
67
|
+
}
|
68
|
+
select(event) {
|
69
|
+
let value = null;
|
70
|
+
if (event instanceof KeyboardEvent) {
|
71
|
+
const item = this.filteredItems.find((i) => i.dataset.highlighted === 'true');
|
72
|
+
if (item) {
|
73
|
+
value = item.dataset.value;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
// mouse event
|
78
|
+
const item = event.currentTarget;
|
79
|
+
value = item.dataset.value;
|
80
|
+
}
|
81
|
+
if (value) {
|
82
|
+
window.Turbo.visit(value);
|
83
|
+
this.close();
|
84
|
+
}
|
85
|
+
}
|
86
|
+
inputKeydown(event) {
|
87
|
+
if (event.key === ' ' && this.searchInputTarget.value.length === 0) {
|
88
|
+
event.preventDefault();
|
89
|
+
}
|
90
|
+
hideError(this);
|
91
|
+
showList(this);
|
92
|
+
}
|
93
|
+
search(event) {
|
94
|
+
this.isDirty = true;
|
95
|
+
clearRemoteResults(this);
|
96
|
+
search(this, event);
|
97
|
+
}
|
98
|
+
clickOutside() {
|
99
|
+
this.close();
|
100
|
+
}
|
101
|
+
isOpenValueChanged(isOpen, previousIsOpen) {
|
102
|
+
if (isOpen) {
|
103
|
+
showContent({
|
104
|
+
trigger: this.triggerTarget,
|
105
|
+
content: this.contentTarget,
|
106
|
+
contentContainer: this.contentTarget,
|
107
|
+
overlay: this.overlayTarget,
|
108
|
+
});
|
109
|
+
this.setupEventListeners();
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
hideContent({
|
113
|
+
trigger: this.triggerTarget,
|
114
|
+
content: this.contentTarget,
|
115
|
+
contentContainer: this.contentTarget,
|
116
|
+
overlay: this.overlayTarget,
|
117
|
+
});
|
118
|
+
if (previousIsOpen) {
|
119
|
+
focusTrigger(this.triggerTarget);
|
120
|
+
}
|
121
|
+
this.cleanupEventListeners();
|
122
|
+
}
|
123
|
+
}
|
124
|
+
filteredItemIndexesValueChanged(filteredItemIndexes) {
|
125
|
+
filteredItemsChanged(this, filteredItemIndexes);
|
126
|
+
}
|
127
|
+
disconnect() {
|
128
|
+
this.cleanupEventListeners();
|
129
|
+
resetState(this);
|
130
|
+
if (this.keybinds) {
|
131
|
+
hotkeys.unbind(this.keybinds);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
setupHotkeys() {
|
135
|
+
const modifierKey = this.element.dataset.modifierKey;
|
136
|
+
const shortcutKey = this.element.dataset.shortcutKey;
|
137
|
+
let keybinds = '';
|
138
|
+
if (modifierKey && shortcutKey) {
|
139
|
+
keybinds = `${modifierKey}+${shortcutKey}`;
|
140
|
+
if (modifierKey === 'ctrl') {
|
141
|
+
keybinds += `,cmd-${shortcutKey}`;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
else if (shortcutKey) {
|
145
|
+
keybinds = shortcutKey;
|
146
|
+
}
|
147
|
+
this.keybinds = keybinds;
|
148
|
+
hotkeys(keybinds, this.hotkeyListener);
|
149
|
+
}
|
150
|
+
onHotkeyPressed(event) {
|
151
|
+
event.preventDefault();
|
152
|
+
this.open();
|
153
|
+
}
|
154
|
+
replaceModifierKeyIcon() {
|
155
|
+
if (this.hasModifierKeyTarget && this.isMac()) {
|
156
|
+
this.modifierKeyTarget.innerHTML = '⌘';
|
157
|
+
}
|
158
|
+
}
|
159
|
+
isMac() {
|
160
|
+
const navigator = window.navigator;
|
161
|
+
if (navigator.userAgentData) {
|
162
|
+
return navigator.userAgentData.platform === 'macOS';
|
163
|
+
}
|
164
|
+
// Fallback to traditional methods
|
165
|
+
return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
166
|
+
}
|
167
|
+
onDOMKeydown(event) {
|
168
|
+
if (!this.isOpenValue)
|
169
|
+
return;
|
170
|
+
const key = event.key;
|
171
|
+
if (['Tab', 'Enter'].includes(key))
|
172
|
+
event.preventDefault();
|
173
|
+
if (key === 'Escape') {
|
174
|
+
this.close();
|
175
|
+
}
|
176
|
+
}
|
177
|
+
setupEventListeners() {
|
178
|
+
document.addEventListener('keydown', this.DOMKeydownListener);
|
179
|
+
}
|
180
|
+
cleanupEventListeners() {
|
181
|
+
document.removeEventListener('keydown', this.DOMKeydownListener);
|
182
|
+
if (this.abortController) {
|
183
|
+
this.abortController.abort();
|
184
|
+
}
|
185
|
+
}
|
206
186
|
};
|
207
187
|
export { CommandController };
|