nitro_kit 0.9.0 → 2.0.0.alpha.2
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/.agents/plugins/marketplace.json +20 -0
- data/CHANGELOG.md +172 -0
- data/LICENSE +28 -0
- data/README.md +22 -15
- data/STYLE_GUIDE.md +425 -0
- data/app/assets/stylesheets/nitro_kit-tailwind-v4.css +38 -0
- data/app/assets/stylesheets/nitro_kit.css +7239 -0
- data/app/components/nitro_kit/accordion.rb +125 -65
- data/app/components/nitro_kit/alert.rb +80 -43
- data/app/components/nitro_kit/app_navigation.rb +307 -0
- data/app/components/nitro_kit/app_shell.rb +227 -0
- data/app/components/nitro_kit/appearance_bootstrap.rb +146 -0
- data/app/components/nitro_kit/appearance_picker.rb +156 -0
- data/app/components/nitro_kit/auth_shell.rb +34 -0
- data/app/components/nitro_kit/avatar.rb +85 -29
- data/app/components/nitro_kit/avatar_stack.rb +155 -9
- data/app/components/nitro_kit/badge.rb +43 -81
- data/app/components/nitro_kit/button.rb +180 -103
- data/app/components/nitro_kit/button_group.rb +63 -11
- data/app/components/nitro_kit/button_to.rb +69 -0
- data/app/components/nitro_kit/card.rb +42 -45
- data/app/components/nitro_kit/checkbox.rb +115 -62
- data/app/components/nitro_kit/checkbox_group.rb +131 -22
- data/app/components/nitro_kit/choice.rb +55 -0
- data/app/components/nitro_kit/combobox.rb +292 -105
- data/app/components/nitro_kit/command_palette.rb +412 -0
- data/app/components/nitro_kit/component.rb +322 -46
- data/app/components/nitro_kit/container.rb +32 -0
- data/app/components/nitro_kit/control_group.rb +45 -0
- data/app/components/nitro_kit/danger_zone.rb +78 -0
- data/app/components/nitro_kit/data_section.rb +106 -0
- data/app/components/nitro_kit/details_table.rb +229 -0
- data/app/components/nitro_kit/dialog.rb +257 -83
- data/app/components/nitro_kit/dropdown.rb +335 -122
- data/app/components/nitro_kit/dropzone.rb +326 -0
- data/app/components/nitro_kit/empty_state.rb +99 -0
- data/app/components/nitro_kit/field.rb +461 -236
- data/app/components/nitro_kit/field_group.rb +15 -8
- data/app/components/nitro_kit/fieldset.rb +37 -39
- data/app/components/nitro_kit/flex.rb +49 -0
- data/app/components/nitro_kit/form_builder.rb +313 -72
- data/app/components/nitro_kit/form_section.rb +79 -0
- data/app/components/nitro_kit/grid.rb +34 -0
- data/app/components/nitro_kit/icon.rb +54 -25
- data/app/components/nitro_kit/input.rb +97 -10
- data/app/components/nitro_kit/label.rb +22 -6
- data/app/components/nitro_kit/layout_options.rb +7 -0
- data/app/components/nitro_kit/page_header.rb +76 -0
- data/app/components/nitro_kit/pagination.rb +355 -69
- data/app/components/nitro_kit/pagination_bar.rb +90 -0
- data/app/components/nitro_kit/progressive_image.rb +181 -0
- data/app/components/nitro_kit/radio_button.rb +77 -55
- data/app/components/nitro_kit/radio_button_group.rb +107 -36
- data/app/components/nitro_kit/responsive_value.rb +94 -0
- data/app/components/nitro_kit/rich_text_area.rb +31 -0
- data/app/components/nitro_kit/select.rb +129 -64
- data/app/components/nitro_kit/settings_layout.rb +152 -0
- data/app/components/nitro_kit/sheet.rb +202 -0
- data/app/components/nitro_kit/stat_grid.rb +75 -0
- data/app/components/nitro_kit/switch.rb +108 -51
- data/app/components/nitro_kit/table.rb +237 -45
- data/app/components/nitro_kit/tabs.rb +168 -63
- data/app/components/nitro_kit/textarea.rb +81 -10
- data/app/components/nitro_kit/toast.rb +211 -80
- data/app/components/nitro_kit/toolbar.rb +75 -0
- data/app/components/nitro_kit/tooltip.rb +235 -34
- data/app/components/nitro_kit/typeset.rb +28 -0
- data/app/javascript/controllers/nk/app_shell_controller.js +224 -0
- data/app/javascript/controllers/nk/appearance_controller.js +73 -0
- data/app/javascript/controllers/nk/avatar_controller.js +15 -0
- data/app/javascript/controllers/nk/button_controller.js +56 -0
- data/app/javascript/controllers/nk/checkable_controller.js +41 -0
- data/app/javascript/controllers/nk/combobox_controller.js +314 -82
- data/app/javascript/controllers/nk/command_palette_controller.js +249 -0
- data/app/javascript/controllers/nk/dialog_controller.js +14 -10
- data/app/javascript/controllers/nk/dropdown_controller.js +106 -58
- data/app/javascript/controllers/nk/dropzone/direct_upload.js +61 -0
- data/app/javascript/controllers/nk/dropzone/file_rules.js +77 -0
- data/app/javascript/controllers/nk/dropzone/form_submit_lock.js +30 -0
- data/app/javascript/controllers/nk/dropzone_controller.js +482 -0
- data/app/javascript/controllers/nk/overlay_position.js +37 -0
- data/app/javascript/controllers/nk/progressive_image_controller.js +116 -0
- data/app/javascript/controllers/nk/tabs_controller.js +135 -23
- data/app/javascript/controllers/nk/toast_controller.js +112 -45
- data/app/javascript/controllers/nk/tooltip_controller.js +12 -47
- data/config/importmap.rb +2 -0
- data/config/locales/en.yml +98 -0
- data/docs/agent_guide.md +139 -0
- data/docs/agent_native_spec.md +422 -0
- data/docs/component_contracts.md +263 -0
- data/docs/customization.md +595 -0
- data/docs/hotwire.md +94 -0
- data/docs/initialization_prompt.md +36 -0
- data/docs/migration_1_to_2.md +318 -0
- data/docs/new_app_strategy.md +22 -0
- data/docs/patterns/application_foundation.md +136 -0
- data/docs/patterns/crud_resource.md +144 -0
- data/docs/patterns/destructive_action.md +105 -0
- data/docs/patterns/flash_and_toast.md +57 -0
- data/docs/patterns/inline_edit.md +59 -0
- data/docs/patterns/queryable_collection.md +187 -0
- data/docs/patterns/resource_form.md +126 -0
- data/docs/rails_conventions.md +95 -0
- data/docs/rails_integration.md +514 -0
- data/lib/generators/nitro_kit/install_generator.rb +48 -0
- data/lib/generators/nitro_kit/upgrade_smoke_tests_generator.rb +67 -0
- data/lib/nitro_kit/engine.rb +20 -0
- data/lib/nitro_kit/installation.rb +671 -0
- data/lib/nitro_kit/migration_inventory.rb +345 -0
- data/lib/nitro_kit/upgrade_smoke_test.rb +403 -0
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/nitro_kit.rb +5 -42
- data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +42 -0
- data/lib/tasks/nitro_kit_tasks.rake +79 -4
- data/plugins/nitro-kit/.codex-plugin/plugin.json +28 -0
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +67 -0
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +4 -0
- data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +60 -0
- data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +4 -0
- data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +62 -0
- data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +4 -0
- data/src/stylesheets/nitro_kit/components/accordion.css +119 -0
- data/src/stylesheets/nitro_kit/components/alert.css +82 -0
- data/src/stylesheets/nitro_kit/components/app_navigation.css +156 -0
- data/src/stylesheets/nitro_kit/components/app_shell.css +605 -0
- data/src/stylesheets/nitro_kit/components/appearance_picker.css +117 -0
- data/src/stylesheets/nitro_kit/components/auth_shell.css +8 -0
- data/src/stylesheets/nitro_kit/components/avatar.css +81 -0
- data/src/stylesheets/nitro_kit/components/avatar_stack.css +80 -0
- data/src/stylesheets/nitro_kit/components/badge.css +76 -0
- data/src/stylesheets/nitro_kit/components/button.css +283 -0
- data/src/stylesheets/nitro_kit/components/button_group.css +53 -0
- data/src/stylesheets/nitro_kit/components/button_to.css +6 -0
- data/src/stylesheets/nitro_kit/components/card.css +70 -0
- data/src/stylesheets/nitro_kit/components/checkbox.css +160 -0
- data/src/stylesheets/nitro_kit/components/checkbox_group.css +61 -0
- data/src/stylesheets/nitro_kit/components/combobox.css +148 -0
- data/src/stylesheets/nitro_kit/components/command_palette.css +255 -0
- data/src/stylesheets/nitro_kit/components/container.css +25 -0
- data/src/stylesheets/nitro_kit/components/control_group.css +149 -0
- data/src/stylesheets/nitro_kit/components/danger_zone.css +54 -0
- data/src/stylesheets/nitro_kit/components/data_section.css +40 -0
- data/src/stylesheets/nitro_kit/components/details_table.css +53 -0
- data/src/stylesheets/nitro_kit/components/dialog.css +80 -0
- data/src/stylesheets/nitro_kit/components/dropdown.css +152 -0
- data/src/stylesheets/nitro_kit/components/dropzone.css +198 -0
- data/src/stylesheets/nitro_kit/components/empty_state.css +53 -0
- data/src/stylesheets/nitro_kit/components/field.css +79 -0
- data/src/stylesheets/nitro_kit/components/field_group.css +6 -0
- data/src/stylesheets/nitro_kit/components/fieldset.css +28 -0
- data/src/stylesheets/nitro_kit/components/flex.css +455 -0
- data/src/stylesheets/nitro_kit/components/form_section.css +71 -0
- data/src/stylesheets/nitro_kit/components/grid.css +308 -0
- data/src/stylesheets/nitro_kit/components/icon.css +26 -0
- data/src/stylesheets/nitro_kit/components/input.css +80 -0
- data/src/stylesheets/nitro_kit/components/label.css +9 -0
- data/src/stylesheets/nitro_kit/components/layout.css +440 -0
- data/src/stylesheets/nitro_kit/components/page_header.css +61 -0
- data/src/stylesheets/nitro_kit/components/pagination.css +119 -0
- data/src/stylesheets/nitro_kit/components/pagination_bar.css +41 -0
- data/src/stylesheets/nitro_kit/components/palette.css +113 -0
- data/src/stylesheets/nitro_kit/components/progressive_image.css +139 -0
- data/src/stylesheets/nitro_kit/components/radio_button.css +127 -0
- data/src/stylesheets/nitro_kit/components/radio_button_group.css +143 -0
- data/src/stylesheets/nitro_kit/components/rich_text_area.css +21 -0
- data/src/stylesheets/nitro_kit/components/select.css +70 -0
- data/src/stylesheets/nitro_kit/components/settings_layout.css +100 -0
- data/src/stylesheets/nitro_kit/components/sheet.css +100 -0
- data/src/stylesheets/nitro_kit/components/stat_grid.css +51 -0
- data/src/stylesheets/nitro_kit/components/switch.css +152 -0
- data/src/stylesheets/nitro_kit/components/table.css +116 -0
- data/src/stylesheets/nitro_kit/components/tabs.css +138 -0
- data/src/stylesheets/nitro_kit/components/textarea.css +39 -0
- data/src/stylesheets/nitro_kit/components/toast.css +131 -0
- data/src/stylesheets/nitro_kit/components/toolbar.css +78 -0
- data/src/stylesheets/nitro_kit/components/tooltip.css +124 -0
- data/src/stylesheets/nitro_kit/components/typeset.css +191 -0
- data/src/stylesheets/nitro_kit/layers.css +7 -0
- data/src/stylesheets/nitro_kit/reset.css +192 -0
- data/src/stylesheets/nitro_kit/tokens.css +198 -0
- metadata +182 -51
- data/Rakefile +0 -8
- data/app/assets/tailwind/application.css +0 -49
- data/app/components/nitro_kit/datepicker.rb +0 -9
- data/app/helpers/nitro_kit/accordion_helper.rb +0 -9
- data/app/helpers/nitro_kit/alert_helper.rb +0 -11
- data/app/helpers/nitro_kit/avatar_helper.rb +0 -13
- data/app/helpers/nitro_kit/badge_helper.rb +0 -13
- data/app/helpers/nitro_kit/button_group_helper.rb +0 -9
- data/app/helpers/nitro_kit/button_helper.rb +0 -49
- data/app/helpers/nitro_kit/card_helper.rb +0 -9
- data/app/helpers/nitro_kit/checkbox_helper.rb +0 -50
- data/app/helpers/nitro_kit/combobox_helper.rb +0 -9
- data/app/helpers/nitro_kit/datepicker_helper.rb +0 -9
- data/app/helpers/nitro_kit/dialog_helper.rb +0 -9
- data/app/helpers/nitro_kit/dropdown_helper.rb +0 -9
- data/app/helpers/nitro_kit/field_group_helper.rb +0 -9
- data/app/helpers/nitro_kit/field_helper.rb +0 -9
- data/app/helpers/nitro_kit/fieldset_helper.rb +0 -9
- data/app/helpers/nitro_kit/form_helper.rb +0 -13
- data/app/helpers/nitro_kit/icon_helper.rb +0 -9
- data/app/helpers/nitro_kit/input_helper.rb +0 -37
- data/app/helpers/nitro_kit/label_helper.rb +0 -19
- data/app/helpers/nitro_kit/pagination_helper.rb +0 -46
- data/app/helpers/nitro_kit/radio_button_helper.rb +0 -23
- data/app/helpers/nitro_kit/select_helper.rb +0 -24
- data/app/helpers/nitro_kit/switch_helper.rb +0 -9
- data/app/helpers/nitro_kit/table_helper.rb +0 -9
- data/app/helpers/nitro_kit/tabs_helper.rb +0 -9
- data/app/helpers/nitro_kit/textarea_helper.rb +0 -9
- data/app/helpers/nitro_kit/toast_helper.rb +0 -25
- data/app/helpers/nitro_kit/tooltip_helper.rb +0 -9
- data/app/javascript/controllers/nk/accordion_controller.js +0 -18
- data/app/javascript/controllers/nk/datepicker_controller.js +0 -5
- data/app/javascript/controllers/nk/switch_controller.js +0 -32
- data/lib/generators/nitro_kit/component_generator.rb +0 -84
- data/lib/nitro_kit/schema_builder.rb +0 -129
- data/lib/nitro_kit/variants.rb +0 -21
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NitroKit
|
|
4
|
+
class Typeset < Component
|
|
5
|
+
def initialize(
|
|
6
|
+
id: nil,
|
|
7
|
+
html: {},
|
|
8
|
+
aria: {},
|
|
9
|
+
data: {},
|
|
10
|
+
desperately_need_a_class: nil
|
|
11
|
+
)
|
|
12
|
+
super(
|
|
13
|
+
component: :typeset,
|
|
14
|
+
attributes: { id: }.compact,
|
|
15
|
+
html:,
|
|
16
|
+
aria:,
|
|
17
|
+
data:,
|
|
18
|
+
desperately_need_a_class:
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def view_template(&content)
|
|
23
|
+
raise ArgumentError, "Typeset requires a content block" unless content
|
|
24
|
+
|
|
25
|
+
div(**root_attributes, &content)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
const narrowViewport = "(max-width: 48rem)";
|
|
4
|
+
|
|
5
|
+
export default class extends Controller {
|
|
6
|
+
static targets = ["dialog", "navigation", "sidebar", "trigger"];
|
|
7
|
+
static values = { openLabel: String, closeLabel: String };
|
|
8
|
+
|
|
9
|
+
connect() {
|
|
10
|
+
this.onViewportChange = this.syncViewport.bind(this);
|
|
11
|
+
this.viewport = window.matchMedia(narrowViewport);
|
|
12
|
+
this.viewport.addEventListener("change", this.onViewportChange);
|
|
13
|
+
this.syncViewport();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
disconnect() {
|
|
17
|
+
this.viewport?.removeEventListener("change", this.onViewportChange);
|
|
18
|
+
this.restoreFocusAfterClose = false;
|
|
19
|
+
|
|
20
|
+
const dialog = this.element.querySelector(
|
|
21
|
+
'[data-nk--app-shell-target~="dialog"]',
|
|
22
|
+
);
|
|
23
|
+
const sidebar = this.element.querySelector(
|
|
24
|
+
'[data-nk--app-shell-target~="sidebar"]',
|
|
25
|
+
);
|
|
26
|
+
const navigation = this.element.querySelector(
|
|
27
|
+
'[data-nk--app-shell-target~="navigation"]',
|
|
28
|
+
);
|
|
29
|
+
const trigger = this.element.querySelector(
|
|
30
|
+
'[data-nk--app-shell-target~="trigger"]',
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (dialog?.open) dialog.close();
|
|
34
|
+
if (sidebar && navigation && navigation.parentElement !== sidebar) {
|
|
35
|
+
sidebar.append(navigation);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.element.dataset.state = "closed";
|
|
39
|
+
trigger?.setAttribute("aria-expanded", "false");
|
|
40
|
+
trigger?.setAttribute("aria-label", this.openLabelValue);
|
|
41
|
+
delete this.element.dataset.enhanced;
|
|
42
|
+
|
|
43
|
+
this.previouslyFocused = null;
|
|
44
|
+
this.viewport = null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toggle(event) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
this.dialogTarget.open ? this.closeDialog() : this.open();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
open() {
|
|
53
|
+
if (!this.isNarrow || this.dialogTarget.open) return;
|
|
54
|
+
|
|
55
|
+
this.previouslyFocused = document.activeElement;
|
|
56
|
+
this.restoreFocusAfterClose = true;
|
|
57
|
+
this.moveNavigationTo(this.dialogTarget);
|
|
58
|
+
this.dialogTarget.showModal();
|
|
59
|
+
this.setState(true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
close(event) {
|
|
63
|
+
event?.preventDefault();
|
|
64
|
+
this.closeDialog();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
closeFromBackdrop(event) {
|
|
68
|
+
if (event.target !== this.dialogTarget) return;
|
|
69
|
+
|
|
70
|
+
const bounds = this.dialogTarget.getBoundingClientRect();
|
|
71
|
+
const insideDialog =
|
|
72
|
+
event.clientX >= bounds.left &&
|
|
73
|
+
event.clientX <= bounds.right &&
|
|
74
|
+
event.clientY >= bounds.top &&
|
|
75
|
+
event.clientY <= bounds.bottom;
|
|
76
|
+
|
|
77
|
+
if (!insideDialog) this.close(event);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
closeForNavigation() {
|
|
81
|
+
this.closeDialog({ restoreFocus: false });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
dialogClosed() {
|
|
85
|
+
this.finishClosing();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
syncViewport() {
|
|
89
|
+
// A Turbo morph restores the server-rendered attributes without
|
|
90
|
+
// reconnecting the controller, so the enhancement marker is re-asserted
|
|
91
|
+
// every time the shell reconciles rather than only on connect.
|
|
92
|
+
this.element.dataset.enhanced = "";
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
!this.hasDialogTarget ||
|
|
96
|
+
!this.hasNavigationTarget ||
|
|
97
|
+
!this.hasSidebarTarget
|
|
98
|
+
) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const enteringNarrow = this.wasNarrow === false && this.isNarrow;
|
|
103
|
+
this.wasNarrow = this.isNarrow;
|
|
104
|
+
|
|
105
|
+
if (!this.isNarrow) {
|
|
106
|
+
this.closeDialog({ restoreFocus: false });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
enteringNarrow &&
|
|
112
|
+
this.element.dataset.state !== "open" &&
|
|
113
|
+
this.navigationTarget.contains(document.activeElement) &&
|
|
114
|
+
this.hasTriggerTarget
|
|
115
|
+
) {
|
|
116
|
+
this.triggerTarget.focus();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (this.element.dataset.state === "open") {
|
|
120
|
+
this.moveNavigationTo(this.dialogTarget);
|
|
121
|
+
this.ensureModalDialog();
|
|
122
|
+
this.setState(true);
|
|
123
|
+
} else {
|
|
124
|
+
this.closeDialog({ restoreFocus: false });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
dialogTargetConnected() {
|
|
129
|
+
if (this.viewport) this.syncViewport();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
dialogTargetDisconnected(dialog) {
|
|
133
|
+
if (dialog.open) dialog.close();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
navigationTargetConnected() {
|
|
137
|
+
if (this.viewport) this.syncViewport();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
sidebarTargetConnected() {
|
|
141
|
+
if (this.viewport) this.syncViewport();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
triggerTargetConnected(trigger) {
|
|
145
|
+
this.syncTrigger(trigger);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
openLabelValueChanged() {
|
|
149
|
+
if (this.hasTriggerTarget) this.syncTrigger(this.triggerTarget);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
closeLabelValueChanged() {
|
|
153
|
+
if (this.hasTriggerTarget) this.syncTrigger(this.triggerTarget);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
closeDialog({ restoreFocus = true } = {}) {
|
|
157
|
+
this.restoreFocusAfterClose = restoreFocus;
|
|
158
|
+
|
|
159
|
+
if (this.hasDialogTarget && this.dialogTarget.open) {
|
|
160
|
+
this.dialogTarget.close();
|
|
161
|
+
} else {
|
|
162
|
+
this.finishClosing();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
finishClosing() {
|
|
167
|
+
const shouldRestoreFocus = this.restoreFocusAfterClose ?? true;
|
|
168
|
+
const focusTarget = this.previouslyFocused?.isConnected
|
|
169
|
+
? this.previouslyFocused
|
|
170
|
+
: this.hasTriggerTarget
|
|
171
|
+
? this.triggerTarget
|
|
172
|
+
: null;
|
|
173
|
+
|
|
174
|
+
this.restoreNavigation();
|
|
175
|
+
this.setState(false);
|
|
176
|
+
this.previouslyFocused = null;
|
|
177
|
+
this.restoreFocusAfterClose = undefined;
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
shouldRestoreFocus &&
|
|
181
|
+
focusTarget?.isConnected &&
|
|
182
|
+
document.activeElement !== focusTarget
|
|
183
|
+
) {
|
|
184
|
+
focusTarget.focus();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
ensureModalDialog() {
|
|
189
|
+
if (this.dialogTarget.matches(":modal")) return;
|
|
190
|
+
|
|
191
|
+
if (this.dialogTarget.open) this.dialogTarget.close();
|
|
192
|
+
this.dialogTarget.showModal();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
restoreNavigation() {
|
|
196
|
+
if (!this.hasNavigationTarget || !this.hasSidebarTarget) return;
|
|
197
|
+
|
|
198
|
+
this.moveNavigationTo(this.sidebarTarget);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
moveNavigationTo(container) {
|
|
202
|
+
if (this.navigationTarget.parentElement !== container) {
|
|
203
|
+
container.append(this.navigationTarget);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
setState(open) {
|
|
208
|
+
this.element.dataset.state = open ? "open" : "closed";
|
|
209
|
+
if (this.hasTriggerTarget) this.syncTrigger(this.triggerTarget);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
syncTrigger(trigger) {
|
|
213
|
+
const open = this.element.dataset.state === "open";
|
|
214
|
+
trigger.setAttribute("aria-expanded", String(open));
|
|
215
|
+
trigger.setAttribute(
|
|
216
|
+
"aria-label",
|
|
217
|
+
open ? this.closeLabelValue : this.openLabelValue,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
get isNarrow() {
|
|
222
|
+
return this.viewport?.matches ?? false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
const preferences = ["light", "dark", "system"];
|
|
4
|
+
|
|
5
|
+
export default class extends Controller {
|
|
6
|
+
static targets = ["input", "trigger"];
|
|
7
|
+
|
|
8
|
+
connect() {
|
|
9
|
+
this.synchronize();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
inputTargetConnected() {
|
|
13
|
+
this.synchronize();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
triggerTargetConnected() {
|
|
17
|
+
this.synchronize();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
select(event) {
|
|
21
|
+
const input = this.inputTargets.find(
|
|
22
|
+
(target) => target === event.target || target === event.currentTarget,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (!input) return;
|
|
26
|
+
if (input.type === "radio" && !input.checked) return;
|
|
27
|
+
|
|
28
|
+
const preference = input.dataset.appearancePreference ?? input.value;
|
|
29
|
+
|
|
30
|
+
window.dispatchEvent(
|
|
31
|
+
new CustomEvent("nitro-kit:appearance-request", {
|
|
32
|
+
detail: { preference },
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
synchronize(event) {
|
|
38
|
+
const preference =
|
|
39
|
+
event?.detail?.preference ??
|
|
40
|
+
document.documentElement.dataset.themePreference ??
|
|
41
|
+
"system";
|
|
42
|
+
|
|
43
|
+
if (!preferences.includes(preference)) return;
|
|
44
|
+
|
|
45
|
+
this.element.dataset.state = preference;
|
|
46
|
+
this.inputTargets.forEach((input) => {
|
|
47
|
+
if (input.type === "radio") {
|
|
48
|
+
input.checked = input.value === preference;
|
|
49
|
+
} else if (input.localName === "select") {
|
|
50
|
+
input.value = preference;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.updateTriggerGlyph(preference);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The dropdown trigger renders the server-side preference glyph. Each menu
|
|
57
|
+
// item already carries the glyph for its own preference, so a client-side
|
|
58
|
+
// change swaps the trigger's drawing instructions instead of teaching this
|
|
59
|
+
// controller what any appearance looks like.
|
|
60
|
+
updateTriggerGlyph(preference) {
|
|
61
|
+
if (!this.hasTriggerTarget) return;
|
|
62
|
+
|
|
63
|
+
const glyph = this.triggerTarget.querySelector('[data-nk="icon"]');
|
|
64
|
+
const source = this.inputTargets.find(
|
|
65
|
+
(input) => input.dataset.appearancePreference === preference,
|
|
66
|
+
);
|
|
67
|
+
const replacement = source?.querySelector('[data-nk="icon"]');
|
|
68
|
+
|
|
69
|
+
if (!glyph || !replacement || glyph === replacement) return;
|
|
70
|
+
|
|
71
|
+
glyph.replaceChildren(...replacement.cloneNode(true).children);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["image", "fallback"];
|
|
5
|
+
|
|
6
|
+
imageTargetConnected(image) {
|
|
7
|
+
if (image.complete && image.naturalWidth === 0) this.failed();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
failed() {
|
|
11
|
+
this.element.dataset.state = "error";
|
|
12
|
+
if (this.hasFallbackTarget)
|
|
13
|
+
this.fallbackTarget.removeAttribute("aria-hidden");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
const submissionIndicatorDelay = 1000;
|
|
4
|
+
|
|
5
|
+
export default class extends Controller {
|
|
6
|
+
connect() {
|
|
7
|
+
this.form = this.element.form;
|
|
8
|
+
this.submissionText = this.element.getAttribute("data-turbo-submits-with");
|
|
9
|
+
this.initialAriaBusy = this.element.getAttribute("aria-busy");
|
|
10
|
+
this.element.removeAttribute("data-turbo-submits-with");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
disconnect() {
|
|
14
|
+
this.reset();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
submit(event) {
|
|
18
|
+
if (event.submitter !== this.element) return;
|
|
19
|
+
|
|
20
|
+
this.element.dataset.state = "submitting";
|
|
21
|
+
this.element.setAttribute("aria-busy", "true");
|
|
22
|
+
if (this.submissionSpinner) {
|
|
23
|
+
this.indicatorTimer = setTimeout(() => {
|
|
24
|
+
this.submissionSpinner.dataset.state = "visible";
|
|
25
|
+
}, submissionIndicatorDelay);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
reset(event) {
|
|
30
|
+
if (event?.type === "turbo:submit-end" && event.target !== this.form)
|
|
31
|
+
return;
|
|
32
|
+
|
|
33
|
+
delete this.element.dataset.state;
|
|
34
|
+
clearTimeout(this.indicatorTimer);
|
|
35
|
+
delete this.submissionSpinner?.dataset.state;
|
|
36
|
+
if (this.initialAriaBusy === null) {
|
|
37
|
+
this.element.removeAttribute("aria-busy");
|
|
38
|
+
} else {
|
|
39
|
+
this.element.setAttribute("aria-busy", this.initialAriaBusy);
|
|
40
|
+
}
|
|
41
|
+
if (event?.type === "turbo:before-cache") {
|
|
42
|
+
if (this.submissionText !== null) {
|
|
43
|
+
this.element.setAttribute(
|
|
44
|
+
"data-turbo-submits-with",
|
|
45
|
+
this.submissionText,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get submissionSpinner() {
|
|
52
|
+
return this.element.querySelector(
|
|
53
|
+
'[data-slot="button-submission-spinner"]',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
// Indeterminate is the only checkbox state HTML cannot express. Checked,
|
|
4
|
+
// unchecked, and radio selection stay native and are styled through :checked.
|
|
5
|
+
export default class extends Controller {
|
|
6
|
+
static targets = ["control"];
|
|
7
|
+
static values = { indeterminate: Boolean };
|
|
8
|
+
|
|
9
|
+
connect() {
|
|
10
|
+
this.apply();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
change() {
|
|
14
|
+
this.indeterminateValue = this.controlTarget.indeterminate;
|
|
15
|
+
this.synchronize();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
indeterminateValueChanged(indeterminate) {
|
|
19
|
+
if (!this.hasControlTarget) return;
|
|
20
|
+
|
|
21
|
+
this.controlTarget.indeterminate = indeterminate;
|
|
22
|
+
this.synchronize();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
controlTargetConnected() {
|
|
26
|
+
this.apply();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
apply() {
|
|
30
|
+
this.controlTarget.indeterminate = this.indeterminateValue;
|
|
31
|
+
this.synchronize();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
synchronize() {
|
|
35
|
+
if (this.controlTarget.indeterminate) {
|
|
36
|
+
this.element.dataset.state = "indeterminate";
|
|
37
|
+
} else {
|
|
38
|
+
delete this.element.dataset.state;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|