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