nitro_kit 2.0.0.beta.2 → 2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +79 -1
- data/LICENSE +21 -28
- data/README.md +10 -9
- data/STYLE_GUIDE.md +1 -1
- data/app/assets/stylesheets/nitro_kit.css +1706 -1400
- data/app/assets/tailwind/nitro_kit/engine.css +15 -0
- data/app/components/nitro_kit/accordion.rb +1 -13
- data/app/components/nitro_kit/app_navigation.rb +0 -12
- data/app/components/nitro_kit/app_shell.rb +5 -11
- data/app/components/nitro_kit/appearance_picker.rb +1 -7
- data/app/components/nitro_kit/combobox.rb +366 -21
- data/app/components/nitro_kit/command_palette.rb +7 -20
- data/app/components/nitro_kit/details_table.rb +5 -11
- data/app/components/nitro_kit/dropzone.rb +3 -15
- data/app/components/nitro_kit/field.rb +20 -2
- data/app/components/nitro_kit/pagination.rb +2 -8
- data/app/components/nitro_kit/settings_layout.rb +3 -9
- data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
- data/app/javascript/controllers/nk/combobox_controller.js +308 -22
- data/app/javascript/controllers/nk/combobox_remote.js +70 -0
- data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
- data/app/javascript/controllers/nk/tabs_controller.js +2 -2
- data/config/locales/en.yml +3 -0
- data/docs/agent_guide.md +43 -13
- data/docs/browser_support.md +7 -1
- data/docs/component_contracts.md +90 -61
- data/docs/customization.md +205 -47
- data/docs/initialization_prompt.md +4 -5
- data/docs/migration_1_to_2.md +10 -8
- data/docs/patterns/application_foundation.md +5 -0
- data/docs/patterns/composition.md +61 -0
- data/docs/patterns/crud_resource.md +5 -0
- data/docs/patterns/inset_workspace.md +21 -22
- data/docs/patterns/resource_form.md +65 -0
- data/docs/rails_integration.md +217 -3
- data/lib/generators/nitro_kit/install_generator.rb +5 -4
- data/lib/nitro_kit/engine.rb +13 -0
- data/lib/nitro_kit/installation.rb +353 -72
- data/lib/nitro_kit/migration_inventory.rb +18 -3
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
- data/lib/tasks/nitro_kit_tasks.rake +1 -1
- data/patterns/README.md +21 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
- data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
- data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
- data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
- data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
- data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
- data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
- data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
- data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
- data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
- data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
- data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
- data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
- data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
- data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
- data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
- data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
- data/patterns/account-settings/item.yml +4 -0
- data/patterns/account-settings/pattern.md +44 -0
- data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
- data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
- data/patterns/application-shell/item.yml +4 -0
- data/patterns/application-shell/pattern.md +110 -0
- data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
- data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
- data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
- data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
- data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
- data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
- data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
- data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
- data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
- data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
- data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
- data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
- data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
- data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
- data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
- data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
- data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
- data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
- data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
- data/patterns/authentication/files/app/models/session.rb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
- data/patterns/authentication/files/config/routes/authentication.rb +11 -0
- data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
- data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
- data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
- data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
- data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
- data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
- data/patterns/authentication/item.yml +12 -0
- data/patterns/authentication/pattern.md +54 -0
- data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
- data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
- data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
- data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
- data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
- data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
- data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
- data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
- data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
- data/patterns/crud-resource/files/app/models/project.rb +41 -0
- data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
- data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
- data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
- data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
- data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
- data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
- data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
- data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
- data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
- data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
- data/patterns/crud-resource/item.yml +6 -0
- data/patterns/crud-resource/pattern.md +48 -0
- data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
- data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
- data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
- data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
- data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
- data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
- data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
- data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
- data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
- data/patterns/file-uploads/files/app/models/upload.rb +295 -0
- data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
- data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
- data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
- data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
- data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
- data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
- data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
- data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
- data/patterns/file-uploads/item.yml +4 -0
- data/patterns/file-uploads/pattern.md +71 -0
- data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
- data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
- data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
- data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
- data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
- data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
- data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
- data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
- data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
- data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
- data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
- data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
- data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
- data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
- data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
- data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
- data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
- data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
- data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
- data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
- data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
- data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
- data/patterns/onboarding/item.yml +4 -0
- data/patterns/onboarding/pattern.md +53 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
- data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
- data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
- data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
- data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
- data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
- data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
- data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
- data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
- data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
- data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
- data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
- data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
- data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
- data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
- data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
- data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
- data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
- data/patterns/subscription-billing/item.yml +4 -0
- data/patterns/subscription-billing/pattern.md +59 -0
- data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
- data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
- data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
- data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
- data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
- data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
- data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
- data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
- data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
- data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
- data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
- data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
- data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
- data/patterns/team-management/files/app/models/invitation.rb +41 -0
- data/patterns/team-management/files/app/models/membership.rb +45 -0
- data/patterns/team-management/files/app/models/team.rb +25 -0
- data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
- data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
- data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
- data/patterns/team-management/files/config/routes/team_management.rb +11 -0
- data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
- data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
- data/patterns/team-management/files/test/models/membership_test.rb +29 -0
- data/patterns/team-management/files/test/models/team_test.rb +31 -0
- data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
- data/patterns/team-management/item.yml +4 -0
- data/patterns/team-management/pattern.md +47 -0
- data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
- data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
- data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
- data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
- data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
- data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
- data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
- data/patterns/webhook-deliveries/item.yml +4 -0
- data/patterns/webhook-deliveries/pattern.md +120 -0
- data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
- data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
- data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
- data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
- data/src/stylesheets/nitro_kit/components/alert.css +7 -6
- data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
- data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
- data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
- data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
- data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
- data/src/stylesheets/nitro_kit/components/badge.css +5 -2
- data/src/stylesheets/nitro_kit/components/button.css +57 -49
- data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
- data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
- data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
- data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
- data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
- data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
- data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
- data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
- data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
- data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
- data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
- data/src/stylesheets/nitro_kit/components/field.css +26 -30
- data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
- data/src/stylesheets/nitro_kit/components/input.css +6 -14
- data/src/stylesheets/nitro_kit/components/layout.css +165 -165
- data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
- data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
- data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
- data/src/stylesheets/nitro_kit/components/palette.css +24 -22
- data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
- data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
- data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
- data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
- data/src/stylesheets/nitro_kit/components/select.css +2 -2
- data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
- data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
- data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
- data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
- data/src/stylesheets/nitro_kit/components/switch.css +23 -23
- data/src/stylesheets/nitro_kit/components/table.css +27 -27
- data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
- data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
- data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
- data/src/stylesheets/nitro_kit/layers.css +10 -1
- data/src/stylesheets/nitro_kit/reset.css +10 -10
- data/{app/assets/stylesheets/nitro_kit-tailwind-v4.css → src/stylesheets/nitro_kit/tailwind.css} +10 -7
- data/src/stylesheets/nitro_kit/tokens.css +18 -9
- metadata +240 -3
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
observeOverlayPosition,
|
|
4
4
|
positionOverlay,
|
|
5
5
|
} from "controllers/nk/overlay_position";
|
|
6
|
+
import { fetchResults, LatestRequest } from "controllers/nk/combobox_remote";
|
|
6
7
|
|
|
7
8
|
// The Combobox component translates these and passes them in as Stimulus
|
|
8
9
|
// values. They remain here as the shipped English fallbacks.
|
|
@@ -10,8 +11,12 @@ const INVALID_SELECTION_MESSAGE = "Choose an option.";
|
|
|
10
11
|
const NO_RESULTS_MESSAGE = "No options found.";
|
|
11
12
|
const RESULTS_ONE_MESSAGE = "%{count} option available.";
|
|
12
13
|
const RESULTS_OTHER_MESSAGE = "%{count} options available.";
|
|
14
|
+
const LOADING_MESSAGE = "Searching…";
|
|
15
|
+
const ERROR_MESSAGE = "Results could not be loaded. Try again.";
|
|
16
|
+
const REMOVE_MESSAGE = "Remove %{label}";
|
|
13
17
|
|
|
14
18
|
const OPTION_LABEL_SELECTOR = '[data-slot="combobox-option-label"]';
|
|
19
|
+
const SEARCH_DELAY = 150;
|
|
15
20
|
|
|
16
21
|
export default class extends Controller {
|
|
17
22
|
static targets = [
|
|
@@ -22,6 +27,10 @@ export default class extends Controller {
|
|
|
22
27
|
"listbox",
|
|
23
28
|
"option",
|
|
24
29
|
"status",
|
|
30
|
+
"message",
|
|
31
|
+
"selections",
|
|
32
|
+
"selection",
|
|
33
|
+
"selectionTemplate",
|
|
25
34
|
];
|
|
26
35
|
static values = {
|
|
27
36
|
open: Boolean,
|
|
@@ -30,6 +39,11 @@ export default class extends Controller {
|
|
|
30
39
|
noResults: String,
|
|
31
40
|
resultsOne: String,
|
|
32
41
|
resultsOther: String,
|
|
42
|
+
src: String,
|
|
43
|
+
multiple: Boolean,
|
|
44
|
+
loading: String,
|
|
45
|
+
error: String,
|
|
46
|
+
remove: String,
|
|
33
47
|
};
|
|
34
48
|
|
|
35
49
|
get invalidSelectionMessage() {
|
|
@@ -40,6 +54,14 @@ export default class extends Controller {
|
|
|
40
54
|
return this.noResultsValue || NO_RESULTS_MESSAGE;
|
|
41
55
|
}
|
|
42
56
|
|
|
57
|
+
get loadingMessage() {
|
|
58
|
+
return this.loadingValue || LOADING_MESSAGE;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get errorMessage() {
|
|
62
|
+
return this.errorValue || ERROR_MESSAGE;
|
|
63
|
+
}
|
|
64
|
+
|
|
43
65
|
resultsMessage(count) {
|
|
44
66
|
const template =
|
|
45
67
|
count === 1
|
|
@@ -49,15 +71,27 @@ export default class extends Controller {
|
|
|
49
71
|
return template.replace("%{count}", String(count));
|
|
50
72
|
}
|
|
51
73
|
|
|
74
|
+
removeMessage(label) {
|
|
75
|
+
return (this.removeValue || REMOVE_MESSAGE).replace("%{label}", label);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get remote() {
|
|
79
|
+
return this.srcValue !== "";
|
|
80
|
+
}
|
|
81
|
+
|
|
52
82
|
connect() {
|
|
53
83
|
this.outsidePointerDown = this.outsidePointerDown.bind(this);
|
|
54
84
|
this.activeOption = null;
|
|
55
85
|
this.enhanced = true;
|
|
86
|
+
this.searches = new LatestRequest();
|
|
87
|
+
this.loadedQuery = null;
|
|
56
88
|
this.nativeRequired = this.requiredValue;
|
|
57
89
|
this.element.dataset.enhanced = "true";
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
90
|
+
if (this.hasNativeTarget) {
|
|
91
|
+
this.controlTarget.hidden = false;
|
|
92
|
+
this.nativeTarget.hidden = true;
|
|
93
|
+
this.valueTarget.required = false;
|
|
94
|
+
}
|
|
61
95
|
this.syncSelection();
|
|
62
96
|
this.syncValidity();
|
|
63
97
|
this.reflectOpenState();
|
|
@@ -66,14 +100,20 @@ export default class extends Controller {
|
|
|
66
100
|
disconnect() {
|
|
67
101
|
this.stopPositioning?.();
|
|
68
102
|
this.stopOutsideDismissal();
|
|
103
|
+
clearTimeout(this.searchTimer);
|
|
104
|
+
this.searches?.cancel();
|
|
69
105
|
this.enhanced = false;
|
|
70
|
-
const
|
|
106
|
+
const controlSlot = this.element.querySelector(
|
|
71
107
|
':scope > [data-slot="combobox-control"]',
|
|
72
108
|
);
|
|
73
|
-
const input =
|
|
109
|
+
const input = controlSlot?.querySelector(
|
|
110
|
+
'[data-nk--combobox-target~="input"]',
|
|
111
|
+
);
|
|
74
112
|
const native = this.element.querySelector(
|
|
75
113
|
':scope > [data-slot="combobox-native"]',
|
|
76
114
|
);
|
|
115
|
+
// A remote combobox has no native fallback, so its control stays visible.
|
|
116
|
+
const control = native ? controlSlot : null;
|
|
77
117
|
const value = native?.querySelector('[data-nk--combobox-target~="value"]');
|
|
78
118
|
const listbox = this.element.querySelector(
|
|
79
119
|
':scope > [data-slot="combobox-listbox"]',
|
|
@@ -87,6 +127,7 @@ export default class extends Controller {
|
|
|
87
127
|
if (listbox) {
|
|
88
128
|
listbox.dataset.state = "closed";
|
|
89
129
|
listbox.hidden = true;
|
|
130
|
+
listbox.removeAttribute("aria-busy");
|
|
90
131
|
}
|
|
91
132
|
if (input) {
|
|
92
133
|
input.setAttribute("aria-expanded", "false");
|
|
@@ -122,7 +163,7 @@ export default class extends Controller {
|
|
|
122
163
|
inputTargetConnected() {
|
|
123
164
|
if (!this.enhanced) return;
|
|
124
165
|
|
|
125
|
-
if (this.hasValueTarget) this.syncValidity();
|
|
166
|
+
if (this.hasValueTarget || this.multipleValue) this.syncValidity();
|
|
126
167
|
this.reflectOpenState();
|
|
127
168
|
}
|
|
128
169
|
|
|
@@ -134,8 +175,8 @@ export default class extends Controller {
|
|
|
134
175
|
if (this.enhanced) this.reflectOpenState();
|
|
135
176
|
}
|
|
136
177
|
|
|
137
|
-
optionTargetConnected() {
|
|
138
|
-
if (this.enhanced
|
|
178
|
+
optionTargetConnected(option) {
|
|
179
|
+
if (this.enhanced) this.syncOption(option, this.selectedValues);
|
|
139
180
|
}
|
|
140
181
|
|
|
141
182
|
optionTargetDisconnected(option) {
|
|
@@ -145,9 +186,13 @@ export default class extends Controller {
|
|
|
145
186
|
open() {
|
|
146
187
|
if (this.inputTarget.disabled) return;
|
|
147
188
|
|
|
148
|
-
// A committed selection is replaced, not appended to: opening
|
|
149
|
-
// visible text so the first keystroke starts a fresh filter.
|
|
150
|
-
if (
|
|
189
|
+
// A committed single selection is replaced, not appended to: opening
|
|
190
|
+
// selects the visible text so the first keystroke starts a fresh filter.
|
|
191
|
+
if (
|
|
192
|
+
!this.openValue &&
|
|
193
|
+
!this.multipleValue &&
|
|
194
|
+
this.inputTarget.value !== ""
|
|
195
|
+
) {
|
|
151
196
|
this.inputTarget.select();
|
|
152
197
|
this.inputTarget.addEventListener(
|
|
153
198
|
"mouseup",
|
|
@@ -157,6 +202,7 @@ export default class extends Controller {
|
|
|
157
202
|
}
|
|
158
203
|
|
|
159
204
|
this.openValue = true;
|
|
205
|
+
if (this.remote && this.loadedQuery !== this.query) this.search();
|
|
160
206
|
}
|
|
161
207
|
|
|
162
208
|
close() {
|
|
@@ -189,6 +235,11 @@ export default class extends Controller {
|
|
|
189
235
|
}
|
|
190
236
|
|
|
191
237
|
filter() {
|
|
238
|
+
if (this.remote) {
|
|
239
|
+
this.filterRemote();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
192
243
|
const query = this.inputTarget.value.trim().toLocaleLowerCase();
|
|
193
244
|
let exactMatch = null;
|
|
194
245
|
|
|
@@ -212,6 +263,82 @@ export default class extends Controller {
|
|
|
212
263
|
this.open();
|
|
213
264
|
}
|
|
214
265
|
|
|
266
|
+
// Remote results come from the application's search endpoint. Typing
|
|
267
|
+
// replaces a committed single selection; in multiple mode the text is only
|
|
268
|
+
// a query and the chips keep their values.
|
|
269
|
+
filterRemote() {
|
|
270
|
+
if (!this.multipleValue) this.setSubmittedValue("");
|
|
271
|
+
this.syncSelection();
|
|
272
|
+
this.setActive(null);
|
|
273
|
+
this.syncValidity();
|
|
274
|
+
this.openValue = true;
|
|
275
|
+
this.listboxTarget.setAttribute("aria-busy", "true");
|
|
276
|
+
clearTimeout(this.searchTimer);
|
|
277
|
+
this.searchTimer = setTimeout(() => this.search(), SEARCH_DELAY);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
get query() {
|
|
281
|
+
if (!this.multipleValue && this.hasValueTarget && this.valueTarget.value)
|
|
282
|
+
return "";
|
|
283
|
+
|
|
284
|
+
return this.inputTarget.value.trim();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async search(query = this.query) {
|
|
288
|
+
clearTimeout(this.searchTimer);
|
|
289
|
+
const url = new URL(this.srcValue, document.baseURI);
|
|
290
|
+
url.searchParams.set("query", query);
|
|
291
|
+
this.listboxTarget.setAttribute("aria-busy", "true");
|
|
292
|
+
if (this.resultOptions.length === 0) this.showMessage("loading");
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
const items = await this.searches.run((signal) =>
|
|
296
|
+
fetchResults(url, { signal }),
|
|
297
|
+
);
|
|
298
|
+
// A newer search, a creation, or a disconnect superseded this one.
|
|
299
|
+
if (!items || !this.enhanced) return;
|
|
300
|
+
|
|
301
|
+
this.loadedQuery = query;
|
|
302
|
+
this.replaceResults(items);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (!this.enhanced || this.searches.isStale(error)) return;
|
|
305
|
+
|
|
306
|
+
this.showError();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
replaceResults(items) {
|
|
311
|
+
this.setActive(null);
|
|
312
|
+
this.resultOptions.forEach((option) => option.remove());
|
|
313
|
+
this.messageTarget.before(...items);
|
|
314
|
+
this.listboxTarget.removeAttribute("aria-busy");
|
|
315
|
+
this.syncSelection();
|
|
316
|
+
this.announceResults();
|
|
317
|
+
this.updatePosition?.();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
showError() {
|
|
321
|
+
this.loadedQuery = null;
|
|
322
|
+
this.setActive(null);
|
|
323
|
+
this.resultOptions.forEach((option) => option.remove());
|
|
324
|
+
this.listboxTarget.removeAttribute("aria-busy");
|
|
325
|
+
this.showMessage("error");
|
|
326
|
+
this.statusTarget.textContent = this.errorMessage;
|
|
327
|
+
this.updatePosition?.();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
showMessage(state) {
|
|
331
|
+
const messages = {
|
|
332
|
+
loading: this.loadingMessage,
|
|
333
|
+
error: this.errorMessage,
|
|
334
|
+
empty: this.noResultsMessage,
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
this.messageTarget.dataset.state = state;
|
|
338
|
+
this.messageTarget.textContent = messages[state] ?? "";
|
|
339
|
+
this.messageTarget.hidden = !(state in messages);
|
|
340
|
+
}
|
|
341
|
+
|
|
215
342
|
select(event) {
|
|
216
343
|
this.commit(event.currentTarget);
|
|
217
344
|
}
|
|
@@ -247,7 +374,11 @@ export default class extends Controller {
|
|
|
247
374
|
nextIndex = options.length - 1;
|
|
248
375
|
break;
|
|
249
376
|
case "Enter":
|
|
250
|
-
if (!this.openValue
|
|
377
|
+
if (!this.openValue) return;
|
|
378
|
+
// An open remote search never submits the surrounding form: Enter
|
|
379
|
+
// belongs to the results, even while they are still loading.
|
|
380
|
+
if (this.remote) event.preventDefault();
|
|
381
|
+
if (!this.activeOption) return;
|
|
251
382
|
event.preventDefault();
|
|
252
383
|
this.commit(this.activeOption);
|
|
253
384
|
return;
|
|
@@ -256,6 +387,16 @@ export default class extends Controller {
|
|
|
256
387
|
event.preventDefault();
|
|
257
388
|
this.close();
|
|
258
389
|
return;
|
|
390
|
+
case "Backspace":
|
|
391
|
+
if (
|
|
392
|
+
!this.multipleValue ||
|
|
393
|
+
this.inputTarget.value !== "" ||
|
|
394
|
+
this.selectionTargets.length === 0
|
|
395
|
+
)
|
|
396
|
+
return;
|
|
397
|
+
event.preventDefault();
|
|
398
|
+
this.removeSelection(this.selectionTargets.at(-1));
|
|
399
|
+
return;
|
|
259
400
|
case "Tab":
|
|
260
401
|
this.close();
|
|
261
402
|
this.syncValidity();
|
|
@@ -305,6 +446,7 @@ export default class extends Controller {
|
|
|
305
446
|
} else {
|
|
306
447
|
this.stopPositioning?.();
|
|
307
448
|
this.stopPositioning = null;
|
|
449
|
+
this.updatePosition = null;
|
|
308
450
|
this.stopOutsideDismissal();
|
|
309
451
|
}
|
|
310
452
|
}
|
|
@@ -319,12 +461,23 @@ export default class extends Controller {
|
|
|
319
461
|
);
|
|
320
462
|
|
|
321
463
|
update();
|
|
464
|
+
this.updatePosition = update;
|
|
322
465
|
this.stopPositioning = observeOverlayPosition(update);
|
|
323
466
|
}
|
|
324
467
|
|
|
325
468
|
commit(option) {
|
|
326
469
|
if (!option || option.getAttribute("aria-disabled") === "true") return;
|
|
327
470
|
|
|
471
|
+
if (option.dataset.requestUrl) {
|
|
472
|
+
this.runAction(option);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (this.multipleValue) {
|
|
477
|
+
this.toggleSelection(option);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
328
481
|
this.inputTarget.value = this.optionLabel(option);
|
|
329
482
|
this.setSubmittedValue(option.dataset.value);
|
|
330
483
|
this.syncSelection();
|
|
@@ -333,6 +486,104 @@ export default class extends Controller {
|
|
|
333
486
|
this.inputTarget.focus();
|
|
334
487
|
}
|
|
335
488
|
|
|
489
|
+
// A result action (such as "Create …") posts to the application, which
|
|
490
|
+
// persists the record and answers with Combobox::Results holding it. The
|
|
491
|
+
// first returned option becomes a selection exactly as if it were chosen.
|
|
492
|
+
async runAction(option) {
|
|
493
|
+
if (this.actionPending) return;
|
|
494
|
+
|
|
495
|
+
this.actionPending = true;
|
|
496
|
+
clearTimeout(this.searchTimer);
|
|
497
|
+
this.searches.cancel();
|
|
498
|
+
option.setAttribute("aria-busy", "true");
|
|
499
|
+
this.listboxTarget.setAttribute("aria-busy", "true");
|
|
500
|
+
|
|
501
|
+
try {
|
|
502
|
+
const items = await fetchResults(option.dataset.requestUrl, {
|
|
503
|
+
method: option.dataset.requestMethod,
|
|
504
|
+
params: JSON.parse(option.dataset.requestParams || "{}"),
|
|
505
|
+
});
|
|
506
|
+
if (!this.enhanced) return;
|
|
507
|
+
|
|
508
|
+
const created = items.find((item) => item.dataset.value !== undefined);
|
|
509
|
+
if (!created) throw new Error("Combobox action returned no option");
|
|
510
|
+
|
|
511
|
+
this.listboxTarget.removeAttribute("aria-busy");
|
|
512
|
+
this.loadedQuery = null;
|
|
513
|
+
this.commit(created);
|
|
514
|
+
if (this.multipleValue && this.openValue) this.search();
|
|
515
|
+
} catch (error) {
|
|
516
|
+
if (this.enhanced) this.showError();
|
|
517
|
+
} finally {
|
|
518
|
+
this.actionPending = false;
|
|
519
|
+
option.removeAttribute("aria-busy");
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
toggleSelection(option) {
|
|
524
|
+
const existing = this.selectionTargets.find(
|
|
525
|
+
(selection) => selection.dataset.value === option.dataset.value,
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
if (existing) {
|
|
529
|
+
existing.remove();
|
|
530
|
+
} else {
|
|
531
|
+
this.selectionsTarget.append(
|
|
532
|
+
this.buildSelection(this.optionLabel(option), option.dataset.value),
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
this.selectionsChanged();
|
|
537
|
+
this.inputTarget.focus();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
buildSelection(label, value) {
|
|
541
|
+
const selection =
|
|
542
|
+
this.selectionTemplateTarget.content.firstElementChild.cloneNode(true);
|
|
543
|
+
|
|
544
|
+
selection.dataset.value = value;
|
|
545
|
+
selection.querySelector(
|
|
546
|
+
'[data-slot="combobox-selection-label"]',
|
|
547
|
+
).textContent = label;
|
|
548
|
+
selection
|
|
549
|
+
.querySelector('[data-slot="combobox-remove"]')
|
|
550
|
+
.setAttribute("aria-label", this.removeMessage(label));
|
|
551
|
+
selection.querySelector('[data-slot="combobox-selection-value"]').value =
|
|
552
|
+
value;
|
|
553
|
+
|
|
554
|
+
return selection;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
remove(event) {
|
|
558
|
+
const selection = event.currentTarget.closest(
|
|
559
|
+
'[data-slot="combobox-selection"]',
|
|
560
|
+
);
|
|
561
|
+
const selections = this.selectionTargets;
|
|
562
|
+
const index = selections.indexOf(selection);
|
|
563
|
+
const neighbour = selections[index + 1] ?? selections[index - 1];
|
|
564
|
+
|
|
565
|
+
this.removeSelection(selection);
|
|
566
|
+
(
|
|
567
|
+
neighbour?.querySelector('[data-slot="combobox-remove"]') ??
|
|
568
|
+
this.inputTarget
|
|
569
|
+
).focus();
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
removeSelection(selection) {
|
|
573
|
+
if (!selection || this.inputTarget.disabled) return;
|
|
574
|
+
|
|
575
|
+
selection.remove();
|
|
576
|
+
this.selectionsChanged();
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Chips hold their own hidden `name[]` fields, so removing a chip removes
|
|
580
|
+
// its submitted value. The list itself carries the one bubbling change.
|
|
581
|
+
selectionsChanged() {
|
|
582
|
+
this.syncSelection();
|
|
583
|
+
this.syncValidity();
|
|
584
|
+
this.selectionsTarget.dispatchEvent(new Event("change", { bubbles: true }));
|
|
585
|
+
}
|
|
586
|
+
|
|
336
587
|
setSubmittedValue(value) {
|
|
337
588
|
if (this.valueTarget.value === value) return;
|
|
338
589
|
|
|
@@ -340,20 +591,42 @@ export default class extends Controller {
|
|
|
340
591
|
this.valueTarget.dispatchEvent(new Event("change", { bubbles: true }));
|
|
341
592
|
}
|
|
342
593
|
|
|
594
|
+
get selectedValues() {
|
|
595
|
+
if (this.multipleValue)
|
|
596
|
+
return new Set(
|
|
597
|
+
this.selectionTargets.map((selection) => selection.dataset.value),
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
return new Set(this.hasValueTarget ? [this.valueTarget.value] : []);
|
|
601
|
+
}
|
|
602
|
+
|
|
343
603
|
syncSelection() {
|
|
344
|
-
this.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
604
|
+
const values = this.selectedValues;
|
|
605
|
+
this.optionTargets.forEach((option) => this.syncOption(option, values));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
syncOption(option, values) {
|
|
609
|
+
if (option.dataset.requestUrl) return;
|
|
610
|
+
|
|
611
|
+
const selected = values.has(option.dataset.value);
|
|
612
|
+
option.setAttribute("aria-selected", String(selected));
|
|
613
|
+
option.dataset.state = selected ? "selected" : "unselected";
|
|
349
614
|
}
|
|
350
615
|
|
|
351
616
|
syncValidity() {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
617
|
+
if (!this.hasInputTarget) return;
|
|
618
|
+
|
|
619
|
+
let invalid;
|
|
620
|
+
if (this.multipleValue) {
|
|
621
|
+
invalid = this.requiredValue && this.selectionTargets.length === 0;
|
|
622
|
+
} else {
|
|
623
|
+
const hasVisibleValue = this.inputTarget.value.trim() !== "";
|
|
624
|
+
const hasSubmittedValue = this.valueTarget.value !== "";
|
|
625
|
+
invalid =
|
|
626
|
+
(this.requiredValue && !hasSubmittedValue) ||
|
|
627
|
+
(hasVisibleValue && !hasSubmittedValue);
|
|
628
|
+
}
|
|
629
|
+
|
|
357
630
|
this.inputTarget.setCustomValidity(
|
|
358
631
|
invalid ? this.invalidSelectionMessage : "",
|
|
359
632
|
);
|
|
@@ -390,6 +663,11 @@ export default class extends Controller {
|
|
|
390
663
|
}
|
|
391
664
|
|
|
392
665
|
toggleEmptyState(empty) {
|
|
666
|
+
if (this.hasMessageTarget) {
|
|
667
|
+
this.showMessage(empty ? "empty" : "idle");
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
|
|
393
671
|
if (empty && !this.emptyElement) {
|
|
394
672
|
const item = document.createElement("li");
|
|
395
673
|
item.setAttribute("role", "presentation");
|
|
@@ -403,6 +681,14 @@ export default class extends Controller {
|
|
|
403
681
|
}
|
|
404
682
|
}
|
|
405
683
|
|
|
684
|
+
// Remote result items are every listbox child the server rendered: options
|
|
685
|
+
// and actions, but never the controller-owned message.
|
|
686
|
+
get resultOptions() {
|
|
687
|
+
return Array.from(this.listboxTarget.children).filter(
|
|
688
|
+
(child) => !this.messageTarget.contains(child),
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
|
|
406
692
|
get visibleOptions() {
|
|
407
693
|
return this.optionTargets.filter(
|
|
408
694
|
(option) =>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Remote Combobox transport. The application renders Combobox::Results as
|
|
2
|
+
// HTML; these helpers fetch it and keep only the newest search alive.
|
|
3
|
+
|
|
4
|
+
const RESULTS_SELECTOR = '[data-nk="combobox-results"]';
|
|
5
|
+
|
|
6
|
+
export async function fetchResults(
|
|
7
|
+
url,
|
|
8
|
+
{ signal, method = "get", params = {} } = {},
|
|
9
|
+
) {
|
|
10
|
+
const headers = { Accept: "text/html, application/xhtml+xml" };
|
|
11
|
+
const options = { headers, signal, credentials: "same-origin" };
|
|
12
|
+
|
|
13
|
+
if (method !== "get") {
|
|
14
|
+
const body = new FormData();
|
|
15
|
+
Object.entries(params).forEach(([key, value]) => body.append(key, value));
|
|
16
|
+
// Rails reads the override from POST bodies for PATCH and PUT.
|
|
17
|
+
if (method !== "post") body.append("_method", method);
|
|
18
|
+
const token = document.querySelector('meta[name="csrf-token"]')?.content;
|
|
19
|
+
if (token) headers["X-CSRF-Token"] = token;
|
|
20
|
+
Object.assign(options, { method: "POST", body });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const response = await fetch(url, options);
|
|
24
|
+
const html = await response.text();
|
|
25
|
+
if (!response.ok)
|
|
26
|
+
throw new Error(`Combobox results failed: ${response.status}`);
|
|
27
|
+
|
|
28
|
+
const results = new DOMParser()
|
|
29
|
+
.parseFromString(html, "text/html")
|
|
30
|
+
.querySelector(RESULTS_SELECTOR);
|
|
31
|
+
if (!results) throw new Error("Combobox response has no Combobox::Results");
|
|
32
|
+
|
|
33
|
+
// Copy the collection first: adopting a node removes it from the live list.
|
|
34
|
+
return Array.from(results.children).map((item) => document.adoptNode(item));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Starting a request aborts its predecessor, and a sequence number discards
|
|
38
|
+
// any predecessor response that still resolves, so an older search can never
|
|
39
|
+
// overwrite newer results.
|
|
40
|
+
export class LatestRequest {
|
|
41
|
+
sequence = 0;
|
|
42
|
+
controller = null;
|
|
43
|
+
|
|
44
|
+
async run(request) {
|
|
45
|
+
this.cancel();
|
|
46
|
+
const sequence = this.sequence;
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
this.controller = controller;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const result = await request(controller.signal);
|
|
52
|
+
return sequence === this.sequence ? result : null;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (sequence !== this.sequence) return null;
|
|
55
|
+
throw error;
|
|
56
|
+
} finally {
|
|
57
|
+
if (this.controller === controller) this.controller = null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
cancel() {
|
|
62
|
+
this.sequence += 1;
|
|
63
|
+
this.controller?.abort();
|
|
64
|
+
this.controller = null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
isStale(error) {
|
|
68
|
+
return error?.name === "AbortError";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -56,8 +56,8 @@ export default class extends Controller {
|
|
|
56
56
|
this.orientationValue === "vertical"
|
|
57
57
|
? ["ArrowUp", "ArrowDown"]
|
|
58
58
|
: rightToLeft
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
? ["ArrowRight", "ArrowLeft"]
|
|
60
|
+
: ["ArrowLeft", "ArrowRight"];
|
|
61
61
|
|
|
62
62
|
if (![...directionKeys, "Home", "End"].includes(event.key)) return;
|
|
63
63
|
|
data/config/locales/en.yml
CHANGED
|
@@ -19,6 +19,9 @@ en:
|
|
|
19
19
|
combobox:
|
|
20
20
|
invalid_selection: "Choose an option."
|
|
21
21
|
no_results: "No options found."
|
|
22
|
+
loading: "Searching…"
|
|
23
|
+
error: "Results could not be loaded. Try again."
|
|
24
|
+
remove: "Remove %{label}"
|
|
22
25
|
results:
|
|
23
26
|
one: "%{count} option available."
|
|
24
27
|
other: "%{count} options available."
|