voidable-hotwire 0.7.1 → 0.8.0

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 (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -4
  3. data/app/views/devise/confirmations/new.html.erb +16 -14
  4. data/app/views/devise/passwords/edit.html.erb +19 -17
  5. data/app/views/devise/passwords/new.html.erb +15 -13
  6. data/app/views/devise/registrations/edit.html.erb +35 -30
  7. data/app/views/devise/registrations/new.html.erb +21 -19
  8. data/app/views/devise/sessions/new.html.erb +25 -23
  9. data/app/views/devise/shared/_error_messages.html.erb +8 -6
  10. data/app/views/devise/unlocks/new.html.erb +16 -14
  11. data/config/importmap.rb +11 -2
  12. data/lib/generators/voidable/install/install_generator.rb +62 -18
  13. data/lib/generators/voidable/install/templates/_settings_menu.html.erb +31 -29
  14. data/lib/generators/voidable/install/templates/application_sidebar.html.erb.tt +12 -5
  15. data/lib/generators/voidable/install/templates/application_topbar.html.erb.tt +12 -5
  16. data/lib/generators/voidable/install/templates/sidebar.html.erb.tt +12 -5
  17. data/lib/generators/voidable/install/templates/topbar.html.erb.tt +12 -5
  18. data/lib/generators/voidable/install/templates/voidable-layout-sidebar.css +2 -11
  19. data/lib/generators/voidable/install/templates/voidable-layout-topbar.css +0 -5
  20. data/lib/generators/voidable/install/templates/voidable-layout.js +16 -10
  21. data/lib/templates/erb/scaffold/_form.html.erb.tt +13 -9
  22. data/lib/templates/erb/scaffold/index.html.erb.tt +45 -33
  23. data/lib/voidable/hotwire/cdn.rb +49 -0
  24. data/lib/voidable/hotwire/dev.rb +27 -0
  25. data/lib/voidable/hotwire/helpers.rb +40 -14
  26. data/lib/voidable/hotwire/version.rb +4 -1
  27. data/lib/voidable/hotwire.rb +2 -0
  28. metadata +3 -1
@@ -1,3 +1,5 @@
1
+ require "voidable/hotwire/cdn"
2
+
1
3
  module Voidable
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
@@ -6,6 +8,8 @@ module Voidable
6
8
 
7
9
  class_option :layout, type: :string, default: "topbar", enum: ["topbar", "sidebar", "switching"],
8
10
  desc: "Application layout style (topbar, sidebar, or switching)"
11
+ class_option :components, type: :string, default: "all", enum: ["all", "autoloader"],
12
+ desc: "How components load: all (one bundle, every component registered up front) or autoloader (each component loads when its tag first appears)"
9
13
  class_option :asset_pipeline, type: :string, default: "importmap", enum: ["importmap", "vite"],
10
14
  desc: "Asset pipeline (importmap or vite)"
11
15
 
@@ -18,13 +22,22 @@ module Voidable
18
22
  importmap = "config/importmap.rb"
19
23
  return unless File.exist?(importmap)
20
24
  return if File.read(importmap).include?("@voidable/ui")
21
- append_to_file importmap, <<~RUBY
22
-
23
- # Voidable UI
24
- pin "@voidable/ui", to: "https://cdn.jsdelivr.net/npm/@voidable/ui@0.5.3/+esm"
25
- pin "@voidable/ui-hotwire", to: "https://cdn.jsdelivr.net/npm/@voidable/ui-hotwire@0.3.1/dist/index.js"
26
- RUBY
27
- say "Pinned @voidable/ui and @voidable/ui-hotwire in importmap", :green
25
+ if autoloader?
26
+ pins = Voidable::Hotwire::CDN::AUTOLOADER_PINS.map { |name, url| %(pin "#{name}", to: "#{url}") }
27
+ pins << %(pin "@voidable/ui-hotwire", to: "#{Voidable::Hotwire::CDN::UI_HOTWIRE_URL}")
28
+ pins << dev_pin if dev_pin
29
+ append_to_file importmap, "\n# Voidable UI (autoloader: components load when their tag first appears)\n#{pins.join("\n")}\n"
30
+ say "Pinned @voidable/ui/autoloader, lit and @voidable/ui-hotwire in importmap", :green
31
+ else
32
+ append_to_file importmap, <<~RUBY
33
+
34
+ # Voidable UI
35
+ pin "@voidable/ui", to: "#{Voidable::Hotwire::CDN::UI_URL}"
36
+ pin "@voidable/ui-hotwire", to: "#{Voidable::Hotwire::CDN::UI_HOTWIRE_URL}"
37
+ #{dev_pin}
38
+ RUBY
39
+ say "Pinned @voidable/ui and @voidable/ui-hotwire in importmap (and @voidable/ui/dev in development)", :green
40
+ end
28
41
  end
29
42
 
30
43
  def create_layout
@@ -109,12 +122,21 @@ module Voidable
109
122
  return unless File.exist?(js_entrypoint)
110
123
  contents = File.read(js_entrypoint)
111
124
  unless contents.include?("@voidable/ui")
112
- header = if vite?
125
+ header = if autoloader?
126
+ <<~JS
127
+ // Components load when their tag first appears on the page.
128
+ // Switch to `import "@voidable/ui";` to register every component
129
+ // up front (see https://voidable.dev/getting-started/installation/).
130
+ import "@voidable/ui/autoloader";
131
+ import "@voidable/ui-hotwire";
132
+
133
+ JS
134
+ elsif vite?
113
135
  <<~JS
114
136
  // For smaller bundles, replace the bulk import below with
115
137
  // per-component imports for only the elements you use, e.g.:
116
- // import "@voidable/ui/button";
117
- // import "@voidable/ui/input";
138
+ // import "@voidable/ui/components/button";
139
+ // import "@voidable/ui/components/input";
118
140
  // See the available components under @voidable/ui's exports.
119
141
  import "@voidable/ui";
120
142
  import "@voidable/ui-hotwire";
@@ -127,6 +149,15 @@ module Voidable
127
149
 
128
150
  JS
129
151
  end
152
+ if vite?
153
+ header += <<~JS
154
+ // Console warnings for misused <void-*> markup (a wrong attribute, a value
155
+ // outside the allowed set, a child in the wrong parent). Development only:
156
+ // the production build drops this import.
157
+ if (import.meta.env.DEV) import("@voidable/ui/dev");
158
+
159
+ JS
160
+ end
130
161
  prepend_to_file js_entrypoint, header
131
162
  end
132
163
  if vite? && !contents.include?("voidable-layout.js")
@@ -145,12 +176,12 @@ module Voidable
145
176
  imports += "\nimport \"./voidable-layout.js\";"
146
177
  append_to_file js_entrypoint, "\n#{imports}\n"
147
178
  end
148
- if vite? && !contents.include?("VoidEventController")
179
+ if vite? && !contents.include?("VoidTurbo")
180
+ # Voidable events need no Stimulus controller: use
181
+ # data-action="void-click->controller#method" directly.
149
182
  append_to_file js_entrypoint, <<~JS
150
183
 
151
- import { VoidEventController, VoidTurbo } from "@voidable/ui-hotwire";
152
- const app = Application.start();
153
- app.register("void-event", VoidEventController);
184
+ import { VoidTurbo } from "@voidable/ui-hotwire";
154
185
  VoidTurbo.start();
155
186
  JS
156
187
  end
@@ -161,16 +192,15 @@ module Voidable
161
192
  return if vite?
162
193
  controllers_js = "app/javascript/controllers/application.js"
163
194
  return unless File.exist?(controllers_js)
164
- return if File.read(controllers_js).include?("VoidEventController")
195
+ return if File.read(controllers_js).include?("VoidTurbo")
165
196
  inject_into_file controllers_js, after: /window\.Stimulus\s*=\s*application\n/ do
166
197
  <<~JS
167
198
 
168
- import { VoidEventController, VoidTurbo } from "@voidable/ui-hotwire"
169
- application.register("void-event", VoidEventController)
199
+ import { VoidTurbo } from "@voidable/ui-hotwire"
170
200
  VoidTurbo.start()
171
201
  JS
172
202
  end
173
- say "Registered VoidEventController and started VoidTurbo in controllers/application.js", :green
203
+ say "Started VoidTurbo in controllers/application.js", :green
174
204
  end
175
205
 
176
206
  def create_vite_helper
@@ -181,6 +211,16 @@ module Voidable
181
211
 
182
212
  private
183
213
 
214
+ # The development warnings: pinned in development only; the layout's
215
+ # `voidable_dev_tags` imports it (Vite apps import it from application.js).
216
+ # None from an unreleased gem checkout, which has no published file to pin.
217
+ def dev_pin
218
+ url = Voidable::Hotwire::CDN::UI_DEV_URL
219
+ return unless url
220
+
221
+ %(pin "@voidable/ui/dev", to: "#{url}" if Rails.env.development? # console warnings for misused <void-*> markup)
222
+ end
223
+
184
224
  def app_name
185
225
  Rails.application.class.module_parent_name.underscore
186
226
  end
@@ -189,6 +229,10 @@ module Voidable
189
229
  options[:asset_pipeline] == "vite"
190
230
  end
191
231
 
232
+ def autoloader?
233
+ options[:components] == "autoloader"
234
+ end
235
+
192
236
  public
193
237
 
194
238
  def install_devise_views
@@ -1,31 +1,33 @@
1
- <void-popover position="<%= local_assigns[:popover_position] || 'top' %>" id="settings-popover">
2
- <button class="settings-btn" aria-label="View Settings" title="View Settings">
1
+ <void-popover side="<%= local_assigns[:popover_position] || 'top' %>" align="<%= local_assigns[:popover_align] || 'end' %>" id="settings-popover">
2
+ <void-popover-trigger><button class="settings-btn" aria-label="View Settings" title="View Settings">
3
3
  <i class="ti ti-settings"></i>
4
- </button>
5
- <div class="settings-menu">
6
- <% if defined?(Devise) && user_signed_in? %>
7
- <div class="settings-menu-item">
8
- <a href="<%= edit_user_registration_path %>" class="settings-menu-action">
9
- <i class="ti ti-user"></i>
10
- Profile
11
- </a>
12
- </div>
13
- <% end %>
14
- <label class="settings-menu-item">
15
- <i class="ti ti-moon"></i>
16
- <span>Dark mode</span>
17
- <void-switch id="theme-toggle" size="sm" aria-label="Toggle theme"></void-switch>
18
- </label>
19
- <% if local_assigns[:layout_toggle] %>
20
- <div class="settings-menu-item">
21
- <form action="/toggle_layout" method="post" class="settings-menu-form">
22
- <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
23
- <button type="submit" class="settings-menu-action">
24
- <i class="ti ti-<%= local_assigns[:layout_toggle_icon] %>"></i>
25
- <%= local_assigns[:layout_toggle_label] %>
26
- </button>
27
- </form>
28
- </div>
29
- <% end %>
30
- </div>
4
+ </button></void-popover-trigger>
5
+ <void-popover-content>
6
+ <div class="settings-menu">
7
+ <% if defined?(Devise) && user_signed_in? %>
8
+ <div class="settings-menu-item">
9
+ <a href="<%= edit_user_registration_path %>" class="settings-menu-action">
10
+ <i class="ti ti-user"></i>
11
+ Profile
12
+ </a>
13
+ </div>
14
+ <% end %>
15
+ <label class="settings-menu-item">
16
+ <i class="ti ti-moon"></i>
17
+ <span>Dark mode</span>
18
+ <void-switch id="theme-toggle" size="sm" aria-label="Toggle theme"></void-switch>
19
+ </label>
20
+ <% if local_assigns[:layout_toggle] %>
21
+ <div class="settings-menu-item">
22
+ <form action="/toggle_layout" method="post" class="settings-menu-form">
23
+ <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
24
+ <button type="submit" class="settings-menu-action">
25
+ <i class="ti ti-<%= local_assigns[:layout_toggle_icon] %>"></i>
26
+ <%= local_assigns[:layout_toggle_label] %>
27
+ </button>
28
+ </form>
29
+ </div>
30
+ <% end %>
31
+ </div>
32
+ </void-popover-content>
31
33
  </void-popover>
@@ -13,11 +13,12 @@
13
13
  <script type="module" src="<%%= vite_asset_path('application.js') %>" data-turbo-track="reload"></script>
14
14
  <% else %>
15
15
  <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
16
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@voidable/theme@0.6.0/src/index.css" data-turbo-track="reload">
16
+ <link rel="stylesheet" href="<%= Voidable::Hotwire::CDN::THEME_CSS_URL %>" data-turbo-track="reload">
17
17
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.44.0/dist/tabler-icons.min.css">
18
18
  <%%= stylesheet_link_tag "voidable-layout", "data-turbo-track": "reload" %>
19
19
  <%%= stylesheet_link_tag "voidable-devise", "data-turbo-track": "reload" %>
20
20
  <%%= javascript_importmap_tags %>
21
+ <%%= voidable_dev_tags %>
21
22
  <% end %>
22
23
  </head>
23
24
 
@@ -72,7 +73,7 @@
72
73
  </div>
73
74
  <div class="app-content-header-right">
74
75
  <%% unless defined?(Devise) && devise_controller? %>
75
- <void-action-input icon="search" placeholder="Search…" size="sm" tooltip-position="bottom" class="app-content-header-search"></void-action-input>
76
+ <void-action-input icon="search" placeholder="Search…" size="sm" tooltip-side="bottom" class="app-content-header-search"></void-action-input>
76
77
  <%% end %>
77
78
  <%%= content_for(:header_actions) %>
78
79
  </div>
@@ -83,12 +84,18 @@
83
84
  </main>
84
85
  </div>
85
86
 
86
- <void-toast-container position="bottom-right">
87
+ <void-toast-container placement="bottom-right">
87
88
  <%% if notice.present? %>
88
- <void-toast color="success" duration="20000" dismissable><%%= notice %></void-toast>
89
+ <void-toast color="success" duration="20000">
90
+ <void-toast-description><%%= notice %></void-toast-description>
91
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
92
+ </void-toast>
89
93
  <%% end %>
90
94
  <%% if alert.present? %>
91
- <void-toast color="caution" duration="20000" dismissable><%%= alert %></void-toast>
95
+ <void-toast color="caution" duration="20000">
96
+ <void-toast-description><%%= alert %></void-toast-description>
97
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
98
+ </void-toast>
92
99
  <%% end %>
93
100
  </void-toast-container>
94
101
 
@@ -13,11 +13,12 @@
13
13
  <script type="module" src="<%%= vite_asset_path('application.js') %>" data-turbo-track="reload"></script>
14
14
  <% else %>
15
15
  <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
16
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@voidable/theme@0.6.0/src/index.css" data-turbo-track="reload">
16
+ <link rel="stylesheet" href="<%= Voidable::Hotwire::CDN::THEME_CSS_URL %>" data-turbo-track="reload">
17
17
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.44.0/dist/tabler-icons.min.css">
18
18
  <%%= stylesheet_link_tag "voidable-layout", "data-turbo-track": "reload" %>
19
19
  <%%= stylesheet_link_tag "voidable-devise", "data-turbo-track": "reload" %>
20
20
  <%%= javascript_importmap_tags %>
21
+ <%%= voidable_dev_tags %>
21
22
  <% end %>
22
23
  </head>
23
24
 
@@ -49,7 +50,7 @@
49
50
  </div>
50
51
  <div class="app-content-header-right">
51
52
  <%% unless defined?(Devise) && devise_controller? %>
52
- <void-action-input icon="search" placeholder="Search..." size="sm" tooltip-position="bottom" class="app-content-header-search"></void-action-input>
53
+ <void-action-input icon="search" placeholder="Search..." size="sm" tooltip-side="bottom" class="app-content-header-search"></void-action-input>
53
54
  <%% end %>
54
55
  <%%= content_for(:header_actions) %>
55
56
  </div>
@@ -62,12 +63,18 @@
62
63
  </div>
63
64
  </main>
64
65
 
65
- <void-toast-container position="bottom-right">
66
+ <void-toast-container placement="bottom-right">
66
67
  <%% if notice.present? %>
67
- <void-toast color="success" duration="20000" dismissable><%%= notice %></void-toast>
68
+ <void-toast color="success" duration="20000">
69
+ <void-toast-description><%%= notice %></void-toast-description>
70
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
71
+ </void-toast>
68
72
  <%% end %>
69
73
  <%% if alert.present? %>
70
- <void-toast color="caution" duration="20000" dismissable><%%= alert %></void-toast>
74
+ <void-toast color="caution" duration="20000">
75
+ <void-toast-description><%%= alert %></void-toast-description>
76
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
77
+ </void-toast>
71
78
  <%% end %>
72
79
  </void-toast-container>
73
80
 
@@ -13,11 +13,12 @@
13
13
  <script type="module" src="<%%= vite_asset_path('application.js') %>" data-turbo-track="reload"></script>
14
14
  <% else %>
15
15
  <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
16
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@voidable/theme@0.6.0/src/index.css" data-turbo-track="reload">
16
+ <link rel="stylesheet" href="<%= Voidable::Hotwire::CDN::THEME_CSS_URL %>" data-turbo-track="reload">
17
17
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.44.0/dist/tabler-icons.min.css">
18
18
  <%%= stylesheet_link_tag "voidable-layout-sidebar", "data-turbo-track": "reload" %>
19
19
  <%%= stylesheet_link_tag "voidable-devise", "data-turbo-track": "reload" %>
20
20
  <%%= javascript_importmap_tags %>
21
+ <%%= voidable_dev_tags %>
21
22
  <% end %>
22
23
  </head>
23
24
 
@@ -72,7 +73,7 @@
72
73
  </div>
73
74
  <div class="app-content-header-right">
74
75
  <%% unless defined?(Devise) && devise_controller? %>
75
- <void-action-input icon="search" placeholder="Search..." size="sm" tooltip-position="bottom" class="app-content-header-search"></void-action-input>
76
+ <void-action-input icon="search" placeholder="Search..." size="sm" tooltip-side="bottom" class="app-content-header-search"></void-action-input>
76
77
  <%% end %>
77
78
  <%%= content_for(:header_actions) %>
78
79
  </div>
@@ -83,12 +84,18 @@
83
84
  </main>
84
85
  </div>
85
86
 
86
- <void-toast-container position="bottom-right">
87
+ <void-toast-container placement="bottom-right">
87
88
  <%% if notice.present? %>
88
- <void-toast color="success" duration="20000" dismissable><%%= notice %></void-toast>
89
+ <void-toast color="success" duration="20000">
90
+ <void-toast-description><%%= notice %></void-toast-description>
91
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
92
+ </void-toast>
89
93
  <%% end %>
90
94
  <%% if alert.present? %>
91
- <void-toast color="caution" duration="20000" dismissable><%%= alert %></void-toast>
95
+ <void-toast color="caution" duration="20000">
96
+ <void-toast-description><%%= alert %></void-toast-description>
97
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
98
+ </void-toast>
92
99
  <%% end %>
93
100
  </void-toast-container>
94
101
 
@@ -13,11 +13,12 @@
13
13
  <script type="module" src="<%%= vite_asset_path('application.js') %>" data-turbo-track="reload"></script>
14
14
  <% else %>
15
15
  <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
16
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@voidable/theme@0.6.0/src/index.css" data-turbo-track="reload">
16
+ <link rel="stylesheet" href="<%= Voidable::Hotwire::CDN::THEME_CSS_URL %>" data-turbo-track="reload">
17
17
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.44.0/dist/tabler-icons.min.css">
18
18
  <%%= stylesheet_link_tag "voidable-layout-topbar", "data-turbo-track": "reload" %>
19
19
  <%%= stylesheet_link_tag "voidable-devise", "data-turbo-track": "reload" %>
20
20
  <%%= javascript_importmap_tags %>
21
+ <%%= voidable_dev_tags %>
21
22
  <% end %>
22
23
  </head>
23
24
 
@@ -49,7 +50,7 @@
49
50
  </div>
50
51
  <div class="app-content-header-right">
51
52
  <%% unless defined?(Devise) && devise_controller? %>
52
- <void-action-input icon="search" placeholder="Search..." size="sm" tooltip-position="bottom" class="app-content-header-search"></void-action-input>
53
+ <void-action-input icon="search" placeholder="Search..." size="sm" tooltip-side="bottom" class="app-content-header-search"></void-action-input>
53
54
  <%% end %>
54
55
  <%%= content_for(:header_actions) %>
55
56
  </div>
@@ -62,12 +63,18 @@
62
63
  </div>
63
64
  </main>
64
65
 
65
- <void-toast-container position="bottom-right">
66
+ <void-toast-container placement="bottom-right">
66
67
  <%% if notice.present? %>
67
- <void-toast color="success" duration="20000" dismissable><%%= notice %></void-toast>
68
+ <void-toast color="success" duration="20000">
69
+ <void-toast-description><%%= notice %></void-toast-description>
70
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
71
+ </void-toast>
68
72
  <%% end %>
69
73
  <%% if alert.present? %>
70
- <void-toast color="caution" duration="20000" dismissable><%%= alert %></void-toast>
74
+ <void-toast color="caution" duration="20000">
75
+ <void-toast-description><%%= alert %></void-toast-description>
76
+ <void-toast-close><button type="button" aria-label="Dismiss">&times;</button></void-toast-close>
77
+ </void-toast>
71
78
  <%% end %>
72
79
  </void-toast-container>
73
80
 
@@ -226,17 +226,8 @@ a { color: inherit; text-decoration: none; }
226
226
  align-items: center;
227
227
  }
228
228
 
229
- .sidebar-footer void-popover[position="top"] .void-popover-body {
230
- left: auto;
231
- right: 0;
232
- }
233
-
234
- /* Signed-out row puts the gear on the LEFT — flip the popover so its menu
235
- extends rightward off the trigger instead of leftward off the page. */
236
- .sidebar-footer-row > void-popover:first-child[position="top"] .void-popover-body {
237
- left: 0;
238
- right: auto;
239
- }
229
+ /* The settings popover is aligned to the end of its trigger (align="end") and flips
230
+ to the other side by itself when the trigger sits at the left edge. */
240
231
 
241
232
  .settings-menu {
242
233
  display: flex;
@@ -113,11 +113,6 @@ a { color: inherit; text-decoration: none; }
113
113
  font-size: var(--void-text-base);
114
114
  }
115
115
 
116
- .app-nav-right void-popover[position="bottom"] .void-popover-body {
117
- left: auto;
118
- right: 0;
119
- }
120
-
121
116
  .settings-menu {
122
117
  display: flex;
123
118
  flex-direction: column;
@@ -58,18 +58,24 @@ document.addEventListener('click', (e) => {
58
58
  // Dialog close → if the user came from a row click, navigate back to
59
59
  // their saved index URL (Turbo restores the cached snapshot, preserving
60
60
  // pagination/scroll). On direct URL nav (no saved return), fall back to
61
- // the dialog's data-close-href.
61
+ // the dialog's data-close-href. void-close does not bubble, so listen in the
62
+ // capture phase; it fires before the dialog closes and can be cancelled, so
63
+ // navigate only once the dialog has really closed.
62
64
  document.addEventListener('void-close', (e) => {
63
- if (e.target.tagName !== 'VOID-DIALOG') return;
64
- const href = e.target.getAttribute('data-close-href');
65
+ const dialog = e.target;
66
+ if (dialog.tagName !== 'VOID-DIALOG') return;
67
+ const href = dialog.getAttribute('data-close-href');
65
68
  if (!href) return;
66
- const target = sessionStorage.getItem('voidable:return:' + window.location.pathname) || href;
67
- if (window.Turbo) {
68
- window.Turbo.visit(target);
69
- } else {
70
- window.location.href = target;
71
- }
72
- });
69
+ queueMicrotask(() => {
70
+ if (e.defaultPrevented || dialog.open) return;
71
+ const target = sessionStorage.getItem('voidable:return:' + window.location.pathname) || href;
72
+ if (window.Turbo) {
73
+ window.Turbo.visit(target);
74
+ } else {
75
+ window.location.href = target;
76
+ }
77
+ });
78
+ }, true);
73
79
 
74
80
  // Theme toggle
75
81
  (function() {
@@ -1,12 +1,14 @@
1
1
  <%%= form_with(model: <%= model_resource_name %>) do |form| %>
2
2
  <%% if <%= singular_table_name %>.errors.any? %>
3
3
  <void-alert color="error" class="form-errors">
4
- <strong><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</strong>
5
- <ul class="form-error-list">
6
- <%% <%= singular_table_name %>.errors.each do |error| %>
7
- <li><%%= error.full_message %></li>
8
- <%% end %>
9
- </ul>
4
+ <void-alert-title><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved</void-alert-title>
5
+ <void-alert-description>
6
+ <ul class="form-error-list">
7
+ <%% <%= singular_table_name %>.errors.each do |error| %>
8
+ <li><%%= error.full_message %></li>
9
+ <%% end %>
10
+ </ul>
11
+ </void-alert-description>
10
12
  </void-alert>
11
13
  <%% end %>
12
14
 
@@ -58,9 +60,11 @@
58
60
  </void-field>
59
61
  <% elsif attribute.reference? -%>
60
62
  <void-field label="<%= attribute.human_name %>">
61
- <void-select name="<%= singular_table_name %>[<%= attribute.column_name %>]">
62
- <option value="">Select...</option>
63
- <%%= options_from_collection_for_select(<%= attribute.column_name.chomp("_id").classify %>.all, :id, :name, <%= singular_table_name %>.<%= attribute.column_name %>) %>
63
+ <void-select>
64
+ <select name="<%= singular_table_name %>[<%= attribute.column_name %>]">
65
+ <option value="">Select...</option>
66
+ <%%= options_from_collection_for_select(<%= attribute.column_name.chomp("_id").classify %>.all, :id, :name, <%= singular_table_name %>.<%= attribute.column_name %>) %>
67
+ </select>
64
68
  </void-select>
65
69
  </void-field>
66
70
  <% else -%>
@@ -67,49 +67,61 @@
67
67
  <meta name="turbo-cache-control" content="no-cache">
68
68
  <%% end %>
69
69
  <%% if @new_mode %>
70
- <void-dialog id="resource-modal" open size="md" heading="New <%= human_name.downcase %>" data-close-href="<%%= <%= index_helper(type: :path) %> %>">
71
- <%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
70
+ <void-dialog id="resource-modal" open size="md" data-close-href="<%%= <%= index_helper(type: :path) %> %>">
71
+ <void-dialog-title>New <%= human_name.downcase %></void-dialog-title>
72
+ <void-dialog-body>
73
+ <%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
74
+ </void-dialog-body>
72
75
  </void-dialog>
73
76
  <%% elsif @edit_mode %>
74
- <void-dialog id="resource-modal" open size="md" heading="Edit <%= human_name.downcase %>" data-close-href="<%%= url_for(<%= model_resource_name(prefix: "@") %>) %>">
75
- <%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
77
+ <void-dialog id="resource-modal" open size="md" data-close-href="<%%= url_for(<%= model_resource_name(prefix: "@") %>) %>">
78
+ <void-dialog-title>Edit <%= human_name.downcase %></void-dialog-title>
79
+ <void-dialog-body>
80
+ <%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
81
+ </void-dialog-body>
76
82
  </void-dialog>
77
83
  <%% else %>
78
- <void-dialog id="resource-modal" open size="md" heading="<%%= @<%= singular_table_name %>.<%= display_column %>.to_s %>" data-close-href="<%%= <%= index_helper(type: :path) %> %>">
79
- <dl class="detail-grid">
80
- <% attributes.reject(&:password_digest?).each do |attribute| -%>
81
- <dt class="detail-label"><%= attribute.human_name %></dt>
82
- <% if attribute.type == :boolean -%>
83
- <dd class="detail-value">
84
- <void-badge color="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> ? 'success' : 'default' %>" variant="outline"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> ? 'Yes' : 'No' %></void-badge>
85
- </dd>
86
- <% elsif [:integer, :float, :decimal].include?(attribute.type) -%>
87
- <dd class="detail-value-mono"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></dd>
88
- <% elsif attribute.attachment? -%>
89
- <dd class="detail-value"><%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached? %></dd>
90
- <% elsif attribute.attachments? -%>
91
- <dd class="detail-value">
92
- <%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
93
- <div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
94
- <%% end %>
95
- </dd>
96
- <% else -%>
97
- <dd class="detail-value"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></dd>
98
- <% end -%>
99
- <% end -%>
100
- </dl>
101
- <div class="modal-actions">
84
+ <void-dialog id="resource-modal" open size="md" data-close-href="<%%= <%= index_helper(type: :path) %> %>">
85
+ <void-dialog-title><%%= @<%= singular_table_name %>.<%= display_column %>.to_s %></void-dialog-title>
86
+ <void-dialog-body>
87
+ <dl class="detail-grid">
88
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
89
+ <dt class="detail-label"><%= attribute.human_name %></dt>
90
+ <% if attribute.type == :boolean -%>
91
+ <dd class="detail-value">
92
+ <void-badge color="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> ? 'success' : 'default' %>" variant="outline"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> ? 'Yes' : 'No' %></void-badge>
93
+ </dd>
94
+ <% elsif [:integer, :float, :decimal].include?(attribute.type) -%>
95
+ <dd class="detail-value-mono"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></dd>
96
+ <% elsif attribute.attachment? -%>
97
+ <dd class="detail-value"><%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached? %></dd>
98
+ <% elsif attribute.attachments? -%>
99
+ <dd class="detail-value">
100
+ <%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
101
+ <div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
102
+ <%% end %>
103
+ </dd>
104
+ <% else -%>
105
+ <dd class="detail-value"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></dd>
106
+ <% end -%>
107
+ <% end -%>
108
+ </dl>
109
+ </void-dialog-body>
110
+ <void-dialog-actions>
102
111
  <void-button variant="outline" size="sm"><a href="<%%= <%= edit_helper(type: :path) %> %>">Edit</a></void-button>
103
112
  <void-button color="error" variant="outline" size="sm" data-open-dialog="resource-delete-dialog">Delete</void-button>
104
- </div>
113
+ </void-dialog-actions>
105
114
  </void-dialog>
106
115
 
107
- <void-dialog id="resource-delete-dialog" heading="Delete <%= human_name.downcase %>" size="sm">
108
- <p class="danger-zone-description">Are you sure you want to delete this <%= human_name.downcase %>? This action cannot be undone.</p>
109
- <div class="action-bar">
116
+ <void-dialog id="resource-delete-dialog" size="sm">
117
+ <void-dialog-title>Delete <%= human_name.downcase %></void-dialog-title>
118
+ <void-dialog-body>
119
+ <p class="danger-zone-description">Are you sure you want to delete this <%= human_name.downcase %>? This action cannot be undone.</p>
120
+ </void-dialog-body>
121
+ <void-dialog-actions>
110
122
  <void-button variant="ghost" size="sm" data-close-dialog="resource-delete-dialog">Cancel</void-button>
111
123
  <void-button color="error" size="sm"><a href="<%%= url_for(<%= model_resource_name(prefix: "@") %>) %>" data-turbo-method="delete">Delete</a></void-button>
112
- </div>
124
+ </void-dialog-actions>
113
125
  </void-dialog>
114
126
  <%% end %>
115
127
  <%% end %>