rails_admin_next 3.0.2 → 4.0.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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/README.md +25 -7
  4. data/app/assets/stylesheets/rails_admin/skin.css +240 -7
  5. data/app/assets/stylesheets/rails_admin/tokens.css +4 -0
  6. data/app/controllers/rails_admin_next/bulk_deletions_controller.rb +27 -0
  7. data/app/controllers/rails_admin_next/main_controller.rb +34 -5
  8. data/app/helpers/rails_admin_next/application_helper.rb +17 -2
  9. data/app/helpers/rails_admin_next/main_helper.rb +64 -0
  10. data/app/jobs/rails_admin_next/bulk_delete_job.rb +65 -0
  11. data/app/views/layouts/rails_admin_next/_head.html.erb +14 -6
  12. data/app/views/layouts/rails_admin_next/content.html.erb +1 -0
  13. data/app/views/rails_admin_next/bulk_deletions/_banner.html.erb +30 -0
  14. data/app/views/rails_admin_next/main/_batch.html.erb +9 -0
  15. data/app/views/rails_admin_next/main/_history_row.html.erb +32 -0
  16. data/app/views/rails_admin_next/main/_list_row.html.erb +19 -0
  17. data/app/views/rails_admin_next/main/_next_batch.html.erb +21 -0
  18. data/app/views/rails_admin_next/main/_selection_bar.html.erb +30 -0
  19. data/app/views/rails_admin_next/main/bulk_delete.html.erb +26 -6
  20. data/app/views/rails_admin_next/main/export.html.erb +1 -0
  21. data/app/views/rails_admin_next/main/history.html.erb +5 -36
  22. data/app/views/rails_admin_next/main/index.html.erb +28 -57
  23. data/config/importmap.rails_admin.rb +7 -2
  24. data/config/locales/rails_admin_next.en.yml +37 -4
  25. data/config/routes.rb +2 -0
  26. data/docs/UPGRADING.md +195 -2
  27. data/docs/security.md +18 -8
  28. data/docs/upstream-parity.md +1 -1
  29. data/lib/rails_admin_next/adapters/active_record.rb +7 -0
  30. data/lib/rails_admin_next/bulk_deletion/progress.rb +70 -0
  31. data/lib/rails_admin_next/bulk_deletion.rb +99 -0
  32. data/lib/rails_admin_next/config/actions/base.rb +7 -0
  33. data/lib/rails_admin_next/config/actions/bulk_delete.rb +94 -31
  34. data/lib/rails_admin_next/config/actions/export.rb +4 -0
  35. data/lib/rails_admin_next/config/actions/history_index.rb +1 -1
  36. data/lib/rails_admin_next/config/actions/history_show.rb +1 -1
  37. data/lib/rails_admin_next/config/actions/index.rb +6 -1
  38. data/lib/rails_admin_next/config/fields/types/action_text.rb +11 -0
  39. data/lib/rails_admin_next/config/sections/list.rb +1 -2
  40. data/lib/rails_admin_next/engine.rb +1 -0
  41. data/lib/rails_admin_next/extensions/paper_trail/auditing_adapter.rb +8 -3
  42. data/lib/rails_admin_next/support/action_text_editor.rb +36 -0
  43. data/lib/rails_admin_next/support/paginated_collection.rb +4 -5
  44. data/lib/rails_admin_next/version.rb +4 -5
  45. data/lib/rails_admin_next.rb +3 -0
  46. data/skills/rails-admin-next/SKILL.md +3 -3
  47. data/src/rails_admin/controllers/alert_controller.js +3 -1
  48. data/src/rails_admin/controllers/bulk_progress_controller.js +53 -0
  49. data/src/rails_admin/controllers/bulk_selection_controller.js +151 -0
  50. data/src/rails_admin/controllers/dropdown_controller.js +7 -5
  51. data/src/rails_admin/controllers/filtering_multiselect_controller.js +4 -0
  52. data/src/rails_admin/controllers/filtering_select_controller.js +4 -0
  53. data/src/rails_admin/controllers/index.js +6 -0
  54. data/src/rails_admin/controllers/infinite_scroll_controller.js +79 -0
  55. data/src/rails_admin/controllers/modal_controller.js +3 -1
  56. data/src/rails_admin/controllers/nested_form_controller.js +3 -2
  57. data/src/rails_admin/controllers/sidescroll_controller.js +41 -10
  58. data/src/rails_admin/interactions.js +4 -12
  59. metadata +24 -5
  60. data/app/views/rails_admin_next/main/_pagination.html.erb +0 -54
@@ -27,7 +27,7 @@ module RailsAdminNext
27
27
  @general = false
28
28
  @history = @auditing_adapter&.listing_for_object(@abstract_model, @object, params[:query], params[:sort], params[:sort_reverse], params[:all], params[:page]) || []
29
29
 
30
- render @action.template_name
30
+ render_history
31
31
  end
32
32
  end
33
33
 
@@ -38,7 +38,12 @@ module RailsAdminNext
38
38
 
39
39
  respond_to do |format|
40
40
  format.html do
41
- render @action.template_name, status: @status_code || :ok
41
+ # Rendering the batch without the layout keeps it independent of the host's parent controller.
42
+ if batch_request?(@objects)
43
+ render partial: "rails_admin_next/main/batch", layout: false
44
+ else
45
+ render @action.template_name, status: @status_code || :ok
46
+ end
42
47
  end
43
48
 
44
49
  format.json do
@@ -13,6 +13,17 @@ module RailsAdminNext
13
13
  register_instance_option :partial do
14
14
  :form_action_text
15
15
  end
16
+
17
+ # Action Text renders saved content inside a trix-content div whichever editor is in
18
+ # use, and Lexxy's content styles apply only under .lexxy-content. Only pages get the
19
+ # wrapper: the CSV export binds no view and takes the bare content.
20
+ register_instance_option :pretty_value do
21
+ if formatted_value.present? && bindings[:view] && RailsAdminNext::ActionTextEditor.current == :lexxy
22
+ bindings[:view].tag.div(formatted_value, class: "lexxy-content")
23
+ else
24
+ formatted_value.presence || " - "
25
+ end
26
+ end
16
27
  end
17
28
  end
18
29
  end
@@ -20,8 +20,7 @@ module RailsAdminNext
20
20
  RailsAdminNext::Config.default_items_per_page
21
21
  end
22
22
 
23
- # Positive value shows only prev, next links in pagination.
24
- # This is for avoiding count(*) query.
23
+ # Skips the COUNT query, so the list shows no record count.
25
24
  register_instance_option :limited_pagination do
26
25
  false
27
26
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_cable/engine"
4
+ require "active_job/railtie"
4
5
  require "geared_pagination"
5
6
  require "rails"
6
7
  require "rails_admin_next"
@@ -35,6 +35,10 @@ module RailsAdminNext
35
35
  def item
36
36
  @version.item_id
37
37
  end
38
+
39
+ def id
40
+ @version.id
41
+ end
38
42
  end
39
43
 
40
44
  module ControllerExtension
@@ -80,7 +84,8 @@ module RailsAdminNext
80
84
 
81
85
  def initialize(controller, user_class_name = nil, version_class_name = nil, &block)
82
86
  @controller = controller
83
- @controller&.send(:set_paper_trail_whodunnit)
87
+ # A background job builds the adapter without a controller; it sets whodunnit itself.
88
+ @controller.send(:set_paper_trail_whodunnit) if @controller.respond_to?(:set_paper_trail_whodunnit, true)
84
89
 
85
90
  user_class { user_class_name.to_s.constantize } if user_class_name
86
91
  version_class { version_class_name.to_s.constantize } if version_class_name
@@ -158,7 +163,7 @@ module RailsAdminNext
158
163
  else object.public_send(model.model.versions_association_name)
159
164
  end
160
165
  versions = versions.where("event LIKE ?", "%#{query}%") if query.present?
161
- versions = versions.reorder(sort)
166
+ versions = versions.reorder(sort).order(versions.primary_key => :desc)
162
167
 
163
168
  paginate_versions(versions, all, (page.presence || 1).to_i, per_page.to_i)
164
169
  end
@@ -175,7 +180,7 @@ module RailsAdminNext
175
180
  recordset = GearedPagination::Recordset.new(versions, per_page:)
176
181
  page = recordset.page(current_page)
177
182
  proxies = page.records.map { |version| VersionProxy.new(version, user_class) }
178
- RailsAdminNext::PaginatedCollection.new(proxies, current_page: page.number, per_page:, total_count: recordset.records_count)
183
+ RailsAdminNext::PaginatedCollection.new(proxies, current_page: page.number, per_page:, total_count: -> { recordset.records_count })
179
184
  end
180
185
 
181
186
  def versions_for_model(model, scope = nil)
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAdminNext
4
+ # Which Action Text editor the host's own rich_text_area renders, so the admin loads that
5
+ # editor's assets and no other. Asked on every request, never at boot: the engine is set up
6
+ # before the host's initializers, where the editor may be chosen.
7
+ module ActionTextEditor
8
+ Assets = Data.define(:stylesheet, :modules, :entry_point)
9
+
10
+ ASSETS = {
11
+ lexxy: Assets.new(stylesheet: "lexxy", modules: %w[lexxy], entry_point: "lexxy"),
12
+ trix: Assets.new(stylesheet: "trix", modules: %w[trix @rails/actiontext], entry_point: "trix")
13
+ }.freeze
14
+
15
+ def self.current
16
+ return unless defined?(::ActionText::Engine)
17
+
18
+ if ::ActionText::RichText.respond_to?(:editor)
19
+ ::ActionText::RichText.editor&.editor_name&.to_sym
20
+ else
21
+ rails_8_1_editor
22
+ end
23
+ end
24
+
25
+ def self.assets(editor)
26
+ ASSETS.fetch(editor) { raise ArgumentError, "rails_admin_next has no assets for the #{editor} Action Text editor" }
27
+ end
28
+
29
+ # Rails 8.1 has no editor setting. The lexxy gem replaces rich_text_area app-wide while its
30
+ # override flag is on, which is the default.
31
+ def self.rails_8_1_editor
32
+ (defined?(::Lexxy::Engine) && Rails.application.config.lexxy.override_action_text_defaults) ? :lexxy : :trix
33
+ end
34
+ private_class_method :rails_8_1_editor
35
+ end
36
+ end
@@ -6,9 +6,8 @@ module RailsAdminNext
6
6
  # Wraps either a GearedPagination::Page (ActiveRecord lists, via
7
7
  # .from_recordset) or a manually built Array (the PaperTrail audit log, whose
8
8
  # VersionProxy objects are not an ActiveRecord::Relation) and exposes only the
9
- # pagination contract the index/history views and the shared pager partial
10
- # consume. Counting is lazy so the count-free "limited" pager can render
11
- # prev/next without triggering a COUNT query.
9
+ # pagination contract the index and history views consume. Counting is lazy
10
+ # so a list can offer its next batch without triggering a COUNT query.
12
11
  class PaginatedCollection
13
12
  include Enumerable
14
13
 
@@ -24,7 +23,7 @@ module RailsAdminNext
24
23
 
25
24
  # total_count / total_pages may each be an Integer, nil, or a callable
26
25
  # returning one; callables are evaluated (and memoized) lazily on first read
27
- # so the count-free pager never triggers a COUNT query. total_pages defaults
26
+ # so a list that never shows a count never triggers a COUNT query. total_pages defaults
28
27
  # to a value derived from total_count (see #total_pages).
29
28
  def initialize(records, current_page:, per_page:, total_count:, total_pages: nil)
30
29
  @records = records.to_a
@@ -71,7 +70,7 @@ module RailsAdminNext
71
70
  end
72
71
 
73
72
  # This page holds a full slice, so (without a COUNT) more records may
74
- # follow — drives the count-free "limited" pager's next link.
73
+ # follow — decides whether a list offers its next batch.
75
74
  def full_page?
76
75
  size >= per_page
77
76
  end
@@ -2,12 +2,11 @@
2
2
 
3
3
  module RailsAdminNext
4
4
  class Version
5
- # Releases are cut by publishing a Release-Drafter draft: the gem-push workflow stamps
6
- # the tag's version over these constants at build time, so the in-repo values are only
7
- # the floor a local `gem build` produces.
8
- MAJOR = 3
5
+ # The release workflow stamps the tag's version over these constants before
6
+ # building (bin/stamp-version), so they are never bumped by hand.
7
+ MAJOR = 4
9
8
  MINOR = 0
10
- PATCH = 2
9
+ PATCH = 0
11
10
  PRE = nil
12
11
 
13
12
  class << self
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "rails_admin_next/engine"
4
4
  require "rails_admin_next/abstract_model"
5
+ require "rails_admin_next/bulk_deletion"
6
+ require "rails_admin_next/bulk_deletion/progress"
5
7
  require "rails_admin_next/config"
6
8
  require "rails_admin_next/config/const_load_suppressor"
7
9
  require "rails_admin_next/icons"
@@ -9,6 +11,7 @@ require "rails_admin_next/extension"
9
11
  require "rails_admin_next/extensions/pundit"
10
12
  require "rails_admin_next/extensions/action_policy"
11
13
  require "rails_admin_next/extensions/paper_trail"
14
+ require "rails_admin_next/support/action_text_editor"
12
15
  require "rails_admin_next/support/csv_converter"
13
16
  require "rails_admin_next/support/hash_helper"
14
17
  require "rails_admin_next/support/paginated_collection"
@@ -69,7 +69,7 @@ RailsAdminNext.config do |config|
69
69
  end
70
70
  ```
71
71
 
72
- A custom action subclasses `RailsAdminNext::Config::Actions::Base`, registers with `RailsAdminNext::Config::Actions.register(self)`, and then appears by name inside `config.actions`. Its options (`member`, `collection`, `http_methods`, `controller`, `link_icon`, `visible?`, `authorization_key`, `template_name` and the rest) are declared in `<gem>/lib/rails_admin_next/config/actions/base.rb`. `<gem>/lib/rails_admin_next/config/actions/show_in_app.rb` is a short example. The action renders the host view app/views/rails_admin_next/main/<template_name>.html.erb.
72
+ A custom action subclasses `RailsAdminNext::Config::Actions::Base`, registers with `RailsAdminNext::Config::Actions.register(self)`, and then appears by name inside `config.actions`. Its options (`member`, `collection`, `http_methods`, `controller`, `link_icon`, `visible?`, `authorization_key`, `template_name` and the rest) are declared in `<gem>/lib/rails_admin_next/config/actions/base.rb`. `<gem>/lib/rails_admin_next/config/actions/show_in_app.rb` is a short example. A bulk action (`bulkable?`) that sets `all_matching?` receives the whole filtered set when the reader picks "Select all N matching": no `bulk_ids`, and `list_entries` unpaginated, so it must check each record with `authorized?` itself. `bulk_delete` sends a set larger than its `background_threshold` (500) to `RailsAdminNext::BulkDeleteJob`, in `<gem>/app/jobs/rails_admin_next/bulk_delete_job.rb`. The action renders the host view app/views/rails_admin_next/main/<template_name>.html.erb.
73
73
 
74
74
  Icons take logical names, never Font Awesome classes: `link_icon :show_in_app` or `navigation_icon :list`. The list is in the "Icons" section of `<gem>/docs/UPGRADING.md`.
75
75
 
@@ -88,12 +88,12 @@ Icons take logical names, never Font Awesome classes: `link_icon :show_in_app` o
88
88
  - The engine runs its own Stimulus application, exposed as `window.RailsAdminNext.application`. Register custom controllers on that instance, not on the host's Stimulus app.
89
89
  - Add JavaScript to the admin through a host config/importmap.rails_admin.rb. The engine appends it after its own map, so it can add pins or override the entrypoint pin. The engine's pin names are in `<gem>/config/importmap.rails_admin.rb`.
90
90
  - There is no jQuery, jQuery UI, Bootstrap JS or `@rails/ujs`. Confirmations use Turbo's `data-turbo-confirm`.
91
- - Date and time fields are native HTML5 inputs, with no flatpickr. Rich text is ActionText/Trix. There are no CDN editors such as CKEditor, CodeMirror or froala.
91
+ - Date and time fields are native HTML5 inputs, with no flatpickr. Rich text is ActionText in the host's editor, Trix or Lexxy, which the engine loads itself with no host setup. There are no CDN editors such as CKEditor, CodeMirror or froala.
92
92
  - The admin supports only the latest Chrome and Safari, so modern CSS and DOM APIs are fair game.
93
93
 
94
94
  ## Theming
95
95
 
96
- Engine CSS sits in the cascade layers `ra.tokens`, `ra.framework` and `ra.skin`, so any unlayered host rule wins without specificity tricks. Rebrand by overriding `--ra-*` tokens, for example `:root { --ra-primary: #663399; }`. Upstream `--bs-*` variables do nothing here. The supported tokens and the `--bs-*` to `--ra-*` mapping are in the "Styling" section of `<gem>/docs/UPGRADING.md`. Dark mode follows the OS. `config.color_scheme = :light` (or `:dark`, or `:auto`) pins it.
96
+ Engine CSS sits in the cascade layers `ra.tokens`, `ra.framework` and `ra.skin`, so any unlayered host rule wins without specificity tricks. Rebrand by overriding `--ra-*` tokens, for example `:root { --ra-primary: #663399; }`. Upstream `--bs-*` variables do nothing here. The supported tokens and the `--bs-*` to `--ra-*` mapping are in the "Styling" section of `<gem>/docs/UPGRADING.md`. Dark mode follows the OS. `config.color_scheme = :light` (or `:dark`, or `:auto`) pins it. A Lexxy editor follows the scheme and the `--ra-*` tokens; override a `--lexxy-*` variable with an unlayered rule on `body.rails_admin`. Trix stays light.
97
97
 
98
98
  ## Security
99
99
 
@@ -16,7 +16,9 @@ export default class extends Controller {
16
16
 
17
17
  #focusReturnTarget() {
18
18
  const focusable = Array.from(document.querySelectorAll(FOCUSABLE)).filter(
19
- (el) => !this.element.contains(el) && el.offsetParent !== null
19
+ (el) =>
20
+ !this.element.contains(el) &&
21
+ el.checkVisibility({ visibilityProperty: true })
20
22
  );
21
23
  const preceding = focusable.filter(
22
24
  (el) =>
@@ -0,0 +1,53 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ // Reloads a running background delete's banner frame. The frame's new content brings its own
4
+ // controller while the delete runs and none once it has ended, so polling stops with the swap.
5
+ // A hidden tab polls nothing; it catches up with one poll as soon as it is shown again.
6
+ export default class extends Controller {
7
+ static values = { url: String, interval: Number };
8
+
9
+ connect() {
10
+ this.frame = this.element.closest("turbo-frame");
11
+ // A failed request leaves this content in place, so the next poll is scheduled again. An
12
+ // error page would otherwise replace the banner and end the polling with it.
13
+ this.retry = () => this.#schedule();
14
+ this.keepOnError = (event) => {
15
+ if (event.detail.fetchResponse.succeeded) return;
16
+ event.preventDefault();
17
+ this.#schedule();
18
+ };
19
+ this.visibilityChanged = () =>
20
+ document.hidden ? clearTimeout(this.timer) : this.#poll();
21
+ this.frame.addEventListener("turbo:fetch-request-error", this.retry);
22
+ this.frame.addEventListener(
23
+ "turbo:before-fetch-response",
24
+ this.keepOnError
25
+ );
26
+ document.addEventListener("visibilitychange", this.visibilityChanged);
27
+ this.#schedule();
28
+ }
29
+
30
+ disconnect() {
31
+ clearTimeout(this.timer);
32
+ this.frame.removeEventListener("turbo:fetch-request-error", this.retry);
33
+ this.frame.removeEventListener(
34
+ "turbo:before-fetch-response",
35
+ this.keepOnError
36
+ );
37
+ document.removeEventListener("visibilitychange", this.visibilityChanged);
38
+ }
39
+
40
+ #schedule() {
41
+ clearTimeout(this.timer);
42
+ if (document.hidden) return;
43
+ this.timer = setTimeout(() => this.#poll(), this.intervalValue);
44
+ }
45
+
46
+ #poll() {
47
+ if (this.frame.getAttribute("src")) {
48
+ this.frame.reload();
49
+ } else {
50
+ this.frame.src = this.urlValue;
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,151 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ // Lives on the bulk form and owns every tick on the list. The row checkboxes'
4
+ // checkedness is the explicit selection, and the all-matching fieldset's
5
+ // `disabled` flag says whether it extends to every record the filter matches;
6
+ // what the selection bar shows is derived from those two in skin.css. Both
7
+ // survive a Turbo snapshot and a back/forward-cache restore, so connect()
8
+ // rebuilds everything else from them.
9
+ export default class extends Controller {
10
+ static targets = [
11
+ "allMatching",
12
+ "allMatchingText",
13
+ "announcement",
14
+ "count",
15
+ "header",
16
+ "row",
17
+ ];
18
+ static values = {
19
+ allLoadedMessage: String,
20
+ clearedMessage: String,
21
+ loadedSelectedCount: String,
22
+ rowsSelectedMessage: String,
23
+ selectedCount: String,
24
+ };
25
+
26
+ #refreshQueued = false;
27
+ // Announcements mark a change of scope, not every tick, so the last
28
+ // announced scope is remembered. A restored page starts from its own scope.
29
+ #announcedScope = null;
30
+
31
+ connect() {
32
+ this.#refresh();
33
+ }
34
+
35
+ rowTargetConnected() {
36
+ this.#queueRefresh();
37
+ }
38
+
39
+ rowTargetDisconnected() {
40
+ this.#queueRefresh();
41
+ }
42
+
43
+ toggleAll() {
44
+ const checked = this.headerTarget.checked;
45
+ this.rowTargets.forEach((row) => (row.checked = checked));
46
+ if (!checked) this.allMatchingTarget.disabled = true;
47
+ this.#refresh();
48
+ }
49
+
50
+ rowChanged(event) {
51
+ if (!event.target.checked) this.allMatchingTarget.disabled = true;
52
+ this.#refresh();
53
+ }
54
+
55
+ selectAllMatching() {
56
+ this.allMatchingTarget.disabled = false;
57
+ this.#refresh();
58
+ // The offer hides once used; the menu is what the reader wants next.
59
+ document.getElementById("bulk_menu_toggle")?.focus();
60
+ }
61
+
62
+ // An all-matching submit names its records by the filter, and a deep
63
+ // selection's ids would overflow Rack's parameter limit.
64
+ dropIds(event) {
65
+ if (this.#allMatching) event.formData.delete("bulk_ids[]");
66
+ }
67
+
68
+ clear() {
69
+ this.rowTargets.forEach((row) => (row.checked = false));
70
+ this.allMatchingTarget.disabled = true;
71
+ this.#refresh();
72
+ // The button hides with the bar, so focus would otherwise drop to <body>.
73
+ this.headerTarget.focus({ preventScroll: true });
74
+ }
75
+
76
+ // A later batch can deliver a row already on screen when records were added
77
+ // meanwhile, and Turbo swaps in the new, unticked copy: carry the tick over.
78
+ // While the header is ticked, the rows of each new batch arrive ticked too.
79
+ carryTicks(event) {
80
+ const stream = event.target;
81
+ if (stream.action !== "append" || stream.target !== "list_rows") return;
82
+ const all = this.headerTarget.checked || this.#allMatching;
83
+ stream.templateElement.content
84
+ .querySelectorAll("tr[id] [name='bulk_ids[]']")
85
+ .forEach((checkbox) => {
86
+ const shown = document.querySelector(
87
+ `#${CSS.escape(checkbox.closest("tr").id)} [name='bulk_ids[]']`
88
+ );
89
+ if (all || shown?.checked) checkbox.setAttribute("checked", "");
90
+ });
91
+ }
92
+
93
+ // A batch connects its rows one by one; one refresh covers them all.
94
+ #queueRefresh() {
95
+ if (this.#refreshQueued) return;
96
+ this.#refreshQueued = true;
97
+ queueMicrotask(() => {
98
+ this.#refreshQueued = false;
99
+ if (this.element.isConnected) this.#refresh();
100
+ });
101
+ }
102
+
103
+ get #allMatching() {
104
+ return !this.allMatchingTarget.disabled;
105
+ }
106
+
107
+ // The same test skin.css uses to show the offer: a batch frame that has not
108
+ // loaded yet still holds its status line.
109
+ get #moreToLoad() {
110
+ return (
111
+ this.element.querySelector(".list-batch > .list-batch-status") !== null
112
+ );
113
+ }
114
+
115
+ #refresh() {
116
+ const rows = this.rowTargets;
117
+ const checked = rows.filter((row) => row.checked).length;
118
+ const all = rows.length > 0 && checked === rows.length;
119
+ const partial = all && this.#moreToLoad;
120
+ this.countTarget.textContent = this.#format(
121
+ partial ? this.loadedSelectedCountValue : this.selectedCountValue,
122
+ checked
123
+ );
124
+ this.headerTarget.checked = all;
125
+ this.headerTarget.indeterminate = checked > 0 && !all;
126
+ this.#announce(this.#scope(all, checked), checked);
127
+ }
128
+
129
+ #scope(all, checked) {
130
+ if (this.#allMatching) return "allMatching";
131
+ if (all) return "allLoaded";
132
+ return checked > 0 ? "rows" : "none";
133
+ }
134
+
135
+ #announce(scope, count) {
136
+ const previous = this.#announcedScope;
137
+ this.#announcedScope = scope;
138
+ if (previous === null || previous === scope) return;
139
+ const message = {
140
+ allLoaded: this.allLoadedMessageValue,
141
+ allMatching: this.allMatchingTextTarget.textContent,
142
+ none: this.clearedMessageValue,
143
+ rows: this.rowsSelectedMessageValue,
144
+ }[scope];
145
+ this.announcementTarget.textContent = this.#format(message, count);
146
+ }
147
+
148
+ #format(message, count) {
149
+ return message.replace("%{count}", count);
150
+ }
151
+ }
@@ -5,10 +5,8 @@ const ITEM = ".dropdown-item";
5
5
  // Menu button (WAI-ARIA APG) on a native popover. The toggle is a
6
6
  // <button popovertarget> and the menu carries popover="auto", so the platform
7
7
  // owns the top layer, click-to-toggle, and outside-click/Escape light
8
- // dismissal (do NOT reimplement those). The controller lives on the toggle;
9
- // its menu is the next sibling (`.dropdown-menu`), so the menu items stay out
10
- // of Stimulus's action-parsing scope — important because the bulk-action
11
- // items carry their own `data-action` attribute read by interactions.js.
8
+ // dismissal (do NOT reimplement those). The controller lives on the toggle
9
+ // and its menu is the next sibling (`.dropdown-menu`).
12
10
  //
13
11
  // What is left for JS:
14
12
  // - ArrowDown/ArrowUp on the closed toggle open the menu onto its
@@ -58,8 +56,12 @@ export default class extends Controller {
58
56
  return this.element.nextElementSibling;
59
57
  }
60
58
 
59
+ // Only items a reader can see: a menu can hide entries with CSS, and the
60
+ // arrow keys must never land on one.
61
61
  get #items() {
62
- return Array.from(this.#menu.querySelectorAll(ITEM));
62
+ return Array.from(this.#menu.querySelectorAll(ITEM)).filter((item) =>
63
+ item.checkVisibility({ visibilityProperty: true })
64
+ );
63
65
  }
64
66
 
65
67
  // Popover toggle events fire for every show/hide path — the toggle button,
@@ -33,9 +33,13 @@ export default class extends Controller {
33
33
  this.cache = {};
34
34
  this.searchTimer = null;
35
35
  this.requestId = 0;
36
+ // A form can focus its first field before this controller connects; hiding
37
+ // that <select> would otherwise drop focus to <body>.
38
+ const focused = document.activeElement === this.select;
36
39
  this.#build();
37
40
  this.#buildCache();
38
41
  this.#bind();
42
+ if (focused) this.search.focus();
39
43
  }
40
44
 
41
45
  disconnect() {
@@ -33,7 +33,11 @@ export default class extends Controller {
33
33
  this.activeIndex = -1;
34
34
  this.items = [];
35
35
  this.requestId = 0;
36
+ // A form can focus its first field before this controller connects; hiding
37
+ // that <select> would otherwise drop focus to <body>.
38
+ const focused = document.activeElement === this.select;
36
39
  this.#build();
40
+ if (focused) this.input.focus();
37
41
  }
38
42
 
39
43
  disconnect() {
@@ -1,12 +1,15 @@
1
1
  import { application } from "rails_admin/application";
2
2
 
3
3
  import AlertController from "rails_admin/controllers/alert_controller";
4
+ import BulkProgressController from "rails_admin/controllers/bulk_progress_controller";
5
+ import BulkSelectionController from "rails_admin/controllers/bulk_selection_controller";
4
6
  import CollapseController from "rails_admin/controllers/collapse_controller";
5
7
  import DropdownController from "rails_admin/controllers/dropdown_controller";
6
8
  import FeedbackController from "rails_admin/controllers/feedback_controller";
7
9
  import FilterBoxController from "rails_admin/controllers/filter_box_controller";
8
10
  import FilteringMultiselectController from "rails_admin/controllers/filtering_multiselect_controller";
9
11
  import FilteringSelectController from "rails_admin/controllers/filtering_select_controller";
12
+ import InfiniteScrollController from "rails_admin/controllers/infinite_scroll_controller";
10
13
  import ModalController from "rails_admin/controllers/modal_controller";
11
14
  import NestedFormController from "rails_admin/controllers/nested_form_controller";
12
15
  import PolymorphicController from "rails_admin/controllers/polymorphic_controller";
@@ -18,12 +21,15 @@ import SidescrollController from "rails_admin/controllers/sidescroll_controller"
18
21
  // known set of controllers and must stay self-contained — it can't scan the
19
22
  // host's controllers/ path under importmap+Propshaft.
20
23
  application.register("alert", AlertController);
24
+ application.register("bulk-progress", BulkProgressController);
25
+ application.register("bulk-selection", BulkSelectionController);
21
26
  application.register("collapse", CollapseController);
22
27
  application.register("dropdown", DropdownController);
23
28
  application.register("feedback", FeedbackController);
24
29
  application.register("filter-box", FilterBoxController);
25
30
  application.register("filtering-multiselect", FilteringMultiselectController);
26
31
  application.register("filtering-select", FilteringSelectController);
32
+ application.register("infinite-scroll", InfiniteScrollController);
27
33
  application.register("modal", ModalController);
28
34
  application.register("nested-form", NestedFormController);
29
35
  application.register("polymorphic", PolymorphicController);
@@ -0,0 +1,79 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ // Lives on a pending next-batch <turbo-frame>, which arrives without a src so
4
+ // that Turbo does not load it on its own: the frame lands where the previous
5
+ // one stood, a repaint before the rows above it, and Turbo's lazy loading
6
+ // would fetch it from there. This controller gives it its src one viewport
7
+ // before it scrolls into view, and turns a failed load into an error with a
8
+ // Retry link.
9
+ //
10
+ // State stays in attributes (`src`, Turbo's `busy`, `data-load-error`) and the
11
+ // strings arrive as values, because a restored page snapshot keeps attributes
12
+ // but not JS fields, and Stimulus connects before I18n is initialised.
13
+ export default class extends Controller {
14
+ static targets = ["error", "link"];
15
+ static values = { src: String, error: String, retryLabel: String };
16
+
17
+ #observer;
18
+ #pendingObserve;
19
+
20
+ // Observing waits a repaint, for the rows above the frame to land.
21
+ connect() {
22
+ if (this.element.src) return;
23
+ this.#pendingObserve = requestAnimationFrame(() => {
24
+ this.#observer = new IntersectionObserver(
25
+ (entries) => {
26
+ if (entries.some((entry) => entry.isIntersecting)) this.#loadNow();
27
+ },
28
+ { rootMargin: `0px 0px ${window.innerHeight}px 0px` }
29
+ );
30
+ this.#observer.observe(this.element);
31
+ });
32
+ }
33
+
34
+ disconnect() {
35
+ this.#stopObserving();
36
+ }
37
+
38
+ failed() {
39
+ this.#showError();
40
+ }
41
+
42
+ // A response without this frame (a server error page) would otherwise
43
+ // replace the frame with "Content missing" and throw. A redirected one is
44
+ // where the server sent the reader instead, such as the sign-in page once
45
+ // the session ended, so it is shown rather than retried.
46
+ missing(event) {
47
+ event.preventDefault();
48
+ const { response, visit } = event.detail;
49
+ if (response.redirected) return visit(response);
50
+ this.#showError();
51
+ }
52
+
53
+ // Following the link would dispatch turbo:click, which shows the global
54
+ // loading badge that only a full page render hides.
55
+ load(event) {
56
+ event.preventDefault();
57
+ if (!("loadError" in this.element.dataset)) return this.#loadNow();
58
+
59
+ delete this.element.dataset.loadError;
60
+ this.errorTarget.textContent = "";
61
+ this.element.reload();
62
+ }
63
+
64
+ #loadNow() {
65
+ this.#stopObserving();
66
+ this.element.src ||= this.srcValue;
67
+ }
68
+
69
+ #stopObserving() {
70
+ cancelAnimationFrame(this.#pendingObserve);
71
+ this.#observer?.disconnect();
72
+ }
73
+
74
+ #showError() {
75
+ this.element.dataset.loadError = "";
76
+ this.errorTarget.textContent = this.errorValue;
77
+ this.linkTarget.textContent = this.retryLabelValue;
78
+ }
79
+ }
@@ -126,7 +126,9 @@ export default class extends Controller {
126
126
 
127
127
  #focusable() {
128
128
  return Array.from(this.bodyTarget.querySelectorAll(FOCUSABLE)).filter(
129
- (el) => el.offsetParent !== null || el === document.activeElement
129
+ (el) =>
130
+ el.checkVisibility({ visibilityProperty: true }) ||
131
+ el === document.activeElement
130
132
  );
131
133
  }
132
134
 
@@ -106,8 +106,9 @@ export default class extends Controller {
106
106
  // querySelectorAll does not descend into a nested <template>'s inert
107
107
  // content, so deeply-nested blank fields are never matched here.
108
108
  const target =
109
- Array.from(fields).find((field) => field.offsetParent !== null) ||
110
- fields[0];
109
+ Array.from(fields).find((field) =>
110
+ field.checkVisibility({ visibilityProperty: true })
111
+ ) || fields[0];
111
112
  target?.focus();
112
113
  }
113
114