whose-components 0.3.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 (104) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +231 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/fonts/whose_components/OFL.txt +93 -0
  6. data/app/assets/fonts/whose_components/leaguespartan-bold.woff2 +0 -0
  7. data/app/assets/tailwind/whose_components/engine.css +139 -0
  8. data/app/components/whose/badge_component/badge_component.html.haml +1 -0
  9. data/app/components/whose/badge_component.rb +23 -0
  10. data/app/components/whose/button_component/button_component.html.haml +6 -0
  11. data/app/components/whose/button_component.rb +40 -0
  12. data/app/components/whose/card_component/card_component.html.haml +6 -0
  13. data/app/components/whose/card_component.rb +24 -0
  14. data/app/components/whose/dialog.rb +21 -0
  15. data/app/components/whose/dialog_header_component/dialog_header_component.en.yml +2 -0
  16. data/app/components/whose/dialog_header_component/dialog_header_component.html.haml +3 -0
  17. data/app/components/whose/dialog_header_component.rb +8 -0
  18. data/app/components/whose/flash_component/flash_component.en.yml +2 -0
  19. data/app/components/whose/flash_component/flash_component.html.haml +14 -0
  20. data/app/components/whose/flash_component.rb +35 -0
  21. data/app/components/whose/form/field_component/field_component.html.haml +16 -0
  22. data/app/components/whose/form/field_component.rb +90 -0
  23. data/app/components/whose/link_component/link_component.html.haml +1 -0
  24. data/app/components/whose/link_component.rb +22 -0
  25. data/app/components/whose/list_component/list_component.html.haml +3 -0
  26. data/app/components/whose/list_component.rb +15 -0
  27. data/app/components/whose/list_row_component/list_row_component.html.haml +12 -0
  28. data/app/components/whose/list_row_component.rb +19 -0
  29. data/app/components/whose/modal_component/modal_component.html.haml +10 -0
  30. data/app/components/whose/modal_component.rb +12 -0
  31. data/app/components/whose/nav/item_component/item_component.html.haml +5 -0
  32. data/app/components/whose/nav/item_component.rb +21 -0
  33. data/app/components/whose/nav_component/nav_component.en.yml +4 -0
  34. data/app/components/whose/nav_component/nav_component.html.haml +22 -0
  35. data/app/components/whose/nav_component.rb +55 -0
  36. data/app/components/whose/offcanvas_component/offcanvas_component.html.haml +8 -0
  37. data/app/components/whose/offcanvas_component.rb +21 -0
  38. data/app/components/whose/page_header_component/page_header_component.html.haml +7 -0
  39. data/app/components/whose/page_header_component.rb +17 -0
  40. data/app/components/whose/pagination_component/pagination_component.html.haml +2 -0
  41. data/app/components/whose/pagination_component.rb +12 -0
  42. data/app/components/whose/tooltip_component/tooltip_component.html.haml +3 -0
  43. data/app/components/whose/tooltip_component.rb +26 -0
  44. data/app/controllers/concerns/whose/authentication.rb +77 -0
  45. data/app/controllers/whose/confirmations_controller.rb +29 -0
  46. data/app/controllers/whose/passwords_controller.rb +38 -0
  47. data/app/controllers/whose/registrations_controller.rb +29 -0
  48. data/app/controllers/whose/sessions_controller.rb +31 -0
  49. data/app/helpers/whose/component_helper.rb +18 -0
  50. data/app/helpers/whose/form_helper.rb +16 -0
  51. data/app/javascript/whose/controllers/whose_dialog_controller.js +3 -0
  52. data/app/javascript/whose/controllers/whose_notification_controller.js +8 -0
  53. data/app/javascript/whose/controllers/whose_password_visibility_controller.js +3 -0
  54. data/app/jobs/.keep +0 -0
  55. data/app/mailers/whose/auth_mailer.rb +17 -0
  56. data/app/models/concerns/whose/authenticatable.rb +31 -0
  57. data/app/models/whose/current.rb +6 -0
  58. data/app/models/whose/session.rb +7 -0
  59. data/app/views/whose/auth_mailer/account_exists.html.haml +6 -0
  60. data/app/views/whose/auth_mailer/account_exists.text.haml +9 -0
  61. data/app/views/whose/auth_mailer/confirmation.html.haml +3 -0
  62. data/app/views/whose/auth_mailer/confirmation.text.haml +5 -0
  63. data/app/views/whose/auth_mailer/password_reset.html.haml +3 -0
  64. data/app/views/whose/auth_mailer/password_reset.text.haml +5 -0
  65. data/app/views/whose/confirmations/new.html.haml +11 -0
  66. data/app/views/whose/confirmations/show.html.haml +6 -0
  67. data/app/views/whose/passwords/edit.html.haml +11 -0
  68. data/app/views/whose/passwords/new.html.haml +11 -0
  69. data/app/views/whose/registrations/new.html.haml +16 -0
  70. data/app/views/whose/sessions/new.html.haml +15 -0
  71. data/config/importmap.rb +7 -0
  72. data/config/locales/whose/auth.en.yml +71 -0
  73. data/config/locales/whose/errors.en.yml +17 -0
  74. data/config/locales/whose/form.en.yml +5 -0
  75. data/config/locales/whose/nav.en.yml +4 -0
  76. data/lib/generators/whose/components/install/install_generator.rb +56 -0
  77. data/lib/generators/whose/components/install/templates/application.html.haml +24 -0
  78. data/lib/generators/whose/components/install/templates/create_users.rb.tt +17 -0
  79. data/lib/generators/whose/components/install/templates/create_whose_sessions.rb.tt +13 -0
  80. data/lib/generators/whose/components/install/templates/user.rb.tt +7 -0
  81. data/lib/generators/whose/components/install/templates/users.rb.tt +15 -0
  82. data/lib/generators/whose/components/views/USAGE +12 -0
  83. data/lib/generators/whose/components/views/views_generator.rb +19 -0
  84. data/lib/templates/app/.claude/skills/asd-ste100/LICENSE +21 -0
  85. data/lib/templates/app/.claude/skills/asd-ste100/README.md +102 -0
  86. data/lib/templates/app/.claude/skills/asd-ste100/SKILL.md +139 -0
  87. data/lib/templates/app/.claude/skills/asd-ste100/examples/before-after.md +92 -0
  88. data/lib/templates/app/.claude/skills/asd-ste100/examples/linter-edge-cases.md +14 -0
  89. data/lib/templates/app/.claude/skills/asd-ste100/references/writing-rules.md +59 -0
  90. data/lib/templates/app/.claude/skills/asd-ste100/scripts/ste-lint.py +486 -0
  91. data/lib/templates/app/CLAUDE.md.tt +181 -0
  92. data/lib/templates/whose_app_template.rb +144 -0
  93. data/lib/whose/components/engine.rb +33 -0
  94. data/lib/whose/components/form_builder.rb +158 -0
  95. data/lib/whose/components/routes.rb +16 -0
  96. data/lib/whose/components/version.rb +7 -0
  97. data/lib/whose/components.rb +16 -0
  98. data/lib/whose/merge_classes.rb +17 -0
  99. data/vendor/javascript/@stimulus-components--dialog.js +4 -0
  100. data/vendor/javascript/@stimulus-components--notification.js +4 -0
  101. data/vendor/javascript/@stimulus-components--password-visibility.js +4 -0
  102. data/vendor/javascript/LICENSES +30 -0
  103. data/vendor/javascript/stimulus-use.js +4 -0
  104. metadata +272 -0
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require "tmpdir"
5
+
6
+ def whose_template_ref(url)
7
+ url[%r{waywho/whose-components/(?:refs/(?:heads|tags)/)?([^/]+)/lib/templates/}, 1]
8
+ end
9
+
10
+ # rails new keeps flags it does not know in ARGV and leaves them out of options.
11
+ def whose_flag_value(args, name)
12
+ args.each_cons(2).find { |flag, _| flag == "--#{name}" }&.last ||
13
+ args.find { it.start_with?("--#{name}=") }&.delete_prefix("--#{name}=")
14
+ end
15
+
16
+ def whose_root_option(args)
17
+ value = whose_flag_value(args, "root")
18
+ return unless value
19
+ raise Thor::Error, "Use --root controller#action, for example --root pages#home." unless value.match?(/\A[a-z_]+#[a-z_]+\z/)
20
+
21
+ value
22
+ end
23
+
24
+ template_ref = whose_template_ref(__FILE__)
25
+ root_page = whose_root_option(ARGV)
26
+ gem_path = whose_flag_value(ARGV, "component-gem-path")
27
+
28
+ if __FILE__.match?(%r{\Ahttps?://})
29
+ gem_checkout = Dir.mktmpdir("whose-components-")
30
+ at_exit { FileUtils.remove_entry(gem_checkout) }
31
+ git clone: [ "--quiet", "--depth=1", *("--branch=#{template_ref}" if template_ref), "https://github.com/waywho/whose-components.git", gem_checkout ].shelljoin
32
+ source_paths.unshift(File.join(gem_checkout, "lib/templates/app"))
33
+ else
34
+ source_paths.unshift(File.join(__dir__, "app"))
35
+ end
36
+
37
+ auth = ARGV.include?("--auth") || (!ARGV.include?("--no-auth") && yes?("Add sign-in? (y/n)"))
38
+
39
+ gem "haml-rails"
40
+ gem "view_component"
41
+ gem "pagy", "~> 43"
42
+ if gem_path
43
+ gem "whose-components", path: gem_path
44
+ elsif template_ref
45
+ gem "whose-components", github: "waywho/whose-components", ref: template_ref
46
+ else
47
+ gem "whose-components"
48
+ end
49
+
50
+ gem_group :development, :test do
51
+ gem "factory_bot_rails"
52
+ gem "faker"
53
+ end
54
+
55
+ gem_group :development do
56
+ gem "lookbook"
57
+ gem "letter_opener"
58
+ end
59
+
60
+ environment <<~RUBY
61
+ config.generators do |g|
62
+ g.template_engine :haml
63
+ g.helper false
64
+ g.jbuilder false
65
+ g.system_tests nil
66
+ g.fixture_replacement :factory_bot, dir: "test/factories"
67
+ end
68
+
69
+ RUBY
70
+
71
+ append_to_file ".rubocop.yml", <<~YAML
72
+
73
+ Style/FrozenStringLiteralComment:
74
+ Enabled: true
75
+ EnforcedStyle: always
76
+ YAML
77
+
78
+ uncomment_lines "config/environments/development.rb", /config\.generators\.apply_rubocop_autocorrect_after_generate!/
79
+ environment "config.action_mailer.delivery_method = :letter_opener", env: "development"
80
+
81
+ remove_dir "app/assets/stylesheets"
82
+
83
+ gsub_file "test/test_helper.rb", /^ *# Setup all fixtures.*\n *fixtures :all\n/, " include FactoryBot::Syntax::Methods\n"
84
+
85
+ template "CLAUDE.md.tt", "CLAUDE.md"
86
+ directory ".claude", ".claude"
87
+
88
+ route %(mount Lookbook::Engine, at: "/lookbook" if Rails.env.development?)
89
+
90
+ if root_page
91
+ controller, action = root_page.split("#")
92
+ route %(root "#{root_page}")
93
+ create_file "app/controllers/#{controller}_controller.rb", <<~RUBY
94
+ # frozen_string_literal: true
95
+
96
+ class #{controller.camelize}Controller < ApplicationController
97
+ def #{action}; end
98
+ end
99
+ RUBY
100
+ create_file "app/views/#{controller}/#{action}.html.haml", %(= page_header_component(title: "#{action.humanize}")\n)
101
+ create_file "test/controllers/#{controller}_controller_test.rb", <<~RUBY
102
+ # frozen_string_literal: true
103
+
104
+ require "test_helper"
105
+
106
+ class #{controller.camelize}ControllerTest < ActionDispatch::IntegrationTest
107
+ #{auth ? %(test "#{action} asks a signed-out visitor to sign in" do) : %(test "#{action} renders" do)}
108
+ get root_url
109
+
110
+ #{auth ? "assert_redirected_to new_session_url" : "assert_response :success"}
111
+ end
112
+ end
113
+ RUBY
114
+ end
115
+
116
+ github_steps = <<~TEXT
117
+ To put the app on GitHub:
118
+ 1. Make an empty repository at https://github.com/new.
119
+ 2. Run: git remote add origin git@github.com:<your-account>/#{app_name}.git
120
+ 3. Run: git push -u origin main
121
+ TEXT
122
+
123
+ after_bundle do
124
+ if options[:skip_bundle]
125
+ say "Bundling was skipped. Run these commands in the app: bundle install, " \
126
+ "bin/rails generate whose:components:install#{" --auth" if auth}, bin/rubocop -A, " \
127
+ 'bin/rails db:create db:migrate, git init, git add . and git commit -m "Initial commit".'
128
+ say github_steps
129
+ next
130
+ end
131
+
132
+ generate "whose:components:install", *("--auth" if auth)
133
+ run "bin/rubocop -A"
134
+ rails_command "db:create"
135
+ rails_command "db:migrate"
136
+ if options[:skip_git]
137
+ say "Git was skipped, so the template made no commit."
138
+ next
139
+ end
140
+
141
+ git add: "."
142
+ git commit: %(-m "Initial commit")
143
+ say github_steps
144
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whose
4
+ module Components
5
+ class Engine < ::Rails::Engine
6
+ engine_name "whose_components"
7
+ config.generators.template_engine :haml
8
+
9
+ initializer "whose_components.importmap", before: "importmap" do |app|
10
+ app.config.importmap.paths << root.join("config/importmap.rb")
11
+ app.config.importmap.cache_sweepers << root.join("app/javascript")
12
+ end
13
+
14
+ config.to_prepare do
15
+ ActionController::Base.helper Whose::FormHelper
16
+ ActionController::Base.helper Whose::ComponentHelper
17
+ end
18
+
19
+ initializer "whose_components.assets" do |app|
20
+ app.config.assets.paths << root.join("app/javascript")
21
+ app.config.assets.paths << root.join("vendor/javascript")
22
+ end
23
+
24
+ # engine.css is a Tailwind source, not an asset that the pipeline serves.
25
+ # Propshaft would compile it and warn about its font URL, which resolves
26
+ # against the built tailwind.css instead. tailwindcss-rails excludes the
27
+ # app's own Tailwind source the same way.
28
+ initializer "whose_components.exclude_tailwind_source", before: "propshaft.append_assets_path" do |app|
29
+ app.config.assets.excluded_paths&.push(root.join("app/assets/tailwind"))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view"
4
+
5
+ module Whose
6
+ module Components
7
+ class FormBuilder < ActionView::Helpers::FormBuilder
8
+ delegate :render, :tag, :content_tag, :safe_join, :t, to: :@template
9
+
10
+ %i[text_field email_field number_field telephone_field phone_field url_field date_field search_field
11
+ datetime_field datetime_local_field time_field month_field week_field].each do |type|
12
+ define_method(type) do |method, label: nil, hint: nil, **options|
13
+ field(method, label:, hint:, placeholder: true) { |component| super(method, **input_options(component, options)) }
14
+ end
15
+ end
16
+
17
+ def color_field(method, label: nil, hint: nil, **options)
18
+ field(method, label:, hint:) { |component| super(method, **input_options(component, options, field_classes[:color])) }
19
+ end
20
+
21
+ def range_field(method, label: nil, hint: nil, **options)
22
+ field(method, label:, hint:) { |component| super(method, **input_options(component, options)) }
23
+ end
24
+
25
+ def password_field(method, label: nil, hint: nil, **options)
26
+ field(method, label:, hint:, placeholder: true) do |component|
27
+ options[:data] = { whose_password_visibility_target: "input" }.merge(options[:data] || {})
28
+ input = super(method, **input_options(component, options, field_classes[:password_input]))
29
+ content_tag(:div, class: field_classes[:password_wrapper], data: { controller: "whose-password-visibility" }) do
30
+ safe_join([ input, password_button ])
31
+ end
32
+ end
33
+ end
34
+
35
+ def textarea(method, label: nil, hint: nil, **options)
36
+ field(method, label:, hint:, placeholder: true) do |component|
37
+ super(method, **input_options(component, options, field_classes[:textarea]))
38
+ end
39
+ end
40
+ alias_method :text_area, :textarea
41
+
42
+ def file_field(method, label: nil, hint: nil, **options)
43
+ field(method, label:, hint:) do |component|
44
+ super(method, **input_options(component, options, field_classes[:file]))
45
+ end
46
+ end
47
+
48
+ def select(method, choices = nil, options = {}, html_options = {}, &block)
49
+ label, hint = options.values_at(:label, :hint)
50
+ field(method, label:, hint:) do |component|
51
+ with_caret do
52
+ super(method, choices, options.except(:label, :hint),
53
+ input_options(component, html_options, field_classes[:select]), &block)
54
+ end
55
+ end
56
+ end
57
+
58
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
59
+ label, hint = options.values_at(:label, :hint)
60
+ field(method, label:, hint:) do |component|
61
+ with_caret do
62
+ super(method, collection, value_method, text_method, options.except(:label, :hint),
63
+ input_options(component, html_options, field_classes[:select]))
64
+ end
65
+ end
66
+ end
67
+
68
+ def radio_button(method, tag_value, options = {})
69
+ super(method, tag_value, options.merge(class: Whose.merge_classes(field_classes[:radio], options[:class])))
70
+ end
71
+
72
+ def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {})
73
+ label, hint = options.values_at(:label, :hint)
74
+ field(method, label:, hint:, group: true) do |component|
75
+ radio_options = html_options.merge(class: Whose.merge_classes(field_classes[:radio], html_options[:class]),
76
+ aria: component.aria(html_options[:aria] || {}))
77
+ super(method, collection, value_method, text_method, options.except(:label, :hint)) do |radio|
78
+ tag.div(radio.radio_button(radio_options) + radio.label(class: "text-sm text-fg"), class: "flex items-center gap-2")
79
+ end
80
+ end
81
+ end
82
+
83
+ def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0")
84
+ styled_checkbox(method, options, checked_value, unchecked_value, field_classes[:check])
85
+ end
86
+ alias_method :check_box, :checkbox
87
+
88
+ def toggle(method, **options)
89
+ styled_checkbox(method, options.merge(role: "switch"), "1", "0", field_classes[:toggle])
90
+ end
91
+
92
+ def submit(value = nil, **options)
93
+ button = render(Whose::ButtonComponent.new(type: "submit", **options)) { value || submit_default_value }
94
+ return button unless layout == :inline && labels == :visible
95
+
96
+ tag.div(label_spacer + button, class: "flex flex-col gap-1")
97
+ end
98
+
99
+ private
100
+
101
+ def label_spacer
102
+ tag.span("&nbsp;".html_safe, class: "hidden text-sm font-medium sm:block", aria: { hidden: true })
103
+ end
104
+
105
+ def field_classes
106
+ Whose::Form::FieldComponent::CLASSES
107
+ end
108
+
109
+ def layout
110
+ @options[:layout] || :vertical
111
+ end
112
+
113
+ def labels
114
+ @options[:labels] || :visible
115
+ end
116
+
117
+ def field(method, label:, hint:, inline: false, placeholder: false, group: false, &block)
118
+ component = Whose::Form::FieldComponent.new(form: self, method:, label:, hint:, layout:, inline:, group:,
119
+ placeholder_label: placeholder && labels == :placeholder)
120
+ render(component) { block.call(component) }
121
+ end
122
+
123
+ def input_options(component, options, extra_class = nil)
124
+ placeholder = component.placeholder_label? ? { placeholder: component.label_text } : {}
125
+ placeholder.merge(options).merge(class: Whose.merge_classes(field_classes[:input], extra_class, options[:class]),
126
+ aria: component.aria(options[:aria] || {}))
127
+ end
128
+
129
+ def styled_checkbox(attribute, options, checked_value, unchecked_value, css_class)
130
+ label, hint = options.values_at(:label, :hint)
131
+ field(attribute, label:, hint:, inline: true) do |component|
132
+ checkbox_options = options.except(:label, :hint).merge(class: Whose.merge_classes(css_class, options[:class]),
133
+ aria: component.aria(options[:aria] || {}))
134
+ ActionView::Helpers::FormBuilder.instance_method(:checkbox)
135
+ .bind_call(self, attribute, checkbox_options, checked_value, unchecked_value)
136
+ end
137
+ end
138
+
139
+ def with_caret
140
+ caret = tag.svg(tag.path(d: "m6 8 4 4 4-4"), viewBox: "0 0 20 20", fill: "none", stroke: "currentColor",
141
+ "stroke-width": 1.5, class: field_classes[:select_caret],
142
+ aria: { hidden: true })
143
+ content_tag(:div, yield + caret, class: field_classes[:select_wrapper])
144
+ end
145
+
146
+ def password_button
147
+ content_tag(:button, type: "button", class: field_classes[:password_button],
148
+ data: { action: "whose-password-visibility#toggle" }) do
149
+ safe_join([
150
+ content_tag(:span, t("whose.form.show"), data: { whose_password_visibility_target: "icon" }),
151
+ content_tag(:span, t("whose.form.hide"), class: field_classes[:password_hidden],
152
+ data: { whose_password_visibility_target: "icon" })
153
+ ])
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whose
4
+ module Components
5
+ module Routes
6
+ def whose_authentication
7
+ resource :session, only: %i[new create destroy], controller: "whose/sessions"
8
+ resource :registration, only: %i[new create], controller: "whose/registrations"
9
+ resources :confirmations, only: %i[new create show update], param: :token, controller: "whose/confirmations"
10
+ resources :passwords, only: %i[new create edit update], param: :token, controller: "whose/passwords"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ ActionDispatch::Routing::Mapper.include(Whose::Components::Routes)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whose
4
+ module Components
5
+ VERSION = "0.3.0"
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "view_component"
5
+ require "haml-rails"
6
+ require "tailwindcss-rails"
7
+ require "importmap-rails"
8
+ require "stimulus-rails"
9
+ require "turbo-rails"
10
+ require "bcrypt"
11
+
12
+ require "whose/components/version"
13
+ require "whose/components/engine"
14
+ require "whose/merge_classes"
15
+ require "whose/components/form_builder"
16
+ require "whose/components/routes"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tailwind_merge"
4
+
5
+ module Whose
6
+ MERGER = TailwindMerge::Merger.new(config: {
7
+ theme: {
8
+ "color" => %w[accent accent-soft accent-text backdrop border canvas fg muted negative negative-soft
9
+ on-accent positive positive-soft subtle surface warning warning-soft],
10
+ "radius" => [ "box" ]
11
+ }
12
+ })
13
+
14
+ def self.merge_classes(*classes)
15
+ MERGER.merge(classes.flatten.compact.join(" "))
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ // @stimulus-components/dialog@1.0.1 downloaded from https://ga.jspm.io/npm:@stimulus-components/dialog@1.0.1/dist/stimulus-dialog.mjs
2
+
3
+ import{Controller as e}from"@hotwired/stimulus";const t=class _Dialog extends e{initialize(){this.forceClose=this.forceClose.bind(this)}connect(){this.openValue&&this.open(),document.addEventListener("turbo:before-render",this.forceClose)}disconnect(){document.removeEventListener("turbo:before-render",this.forceClose)}open(){this.dialogTarget.showModal()}close(){this.dialogTarget.setAttribute("closing",""),Promise.all(this.dialogTarget.getAnimations().map((e=>e.finished))).then((()=>{this.dialogTarget.removeAttribute("closing"),this.dialogTarget.close()}))}backdropClose(e){e.target===this.dialogTarget&&this.close()}forceClose(){this.dialogTarget.close()}};t.targets=["dialog"],t.values={open:{type:Boolean,default:!1}};let o=t;export{o as default};
4
+
@@ -0,0 +1,4 @@
1
+ // @stimulus-components/notification@3.0.0 downloaded from https://ga.jspm.io/npm:@stimulus-components/notification@3.0.0/dist/stimulus-notification.mjs
2
+
3
+ import{Controller as t}from"@hotwired/stimulus";import{useTransition as e}from"stimulus-use";const i=class _Notification extends t{initialize(){this.hide=this.hide.bind(this)}connect(){e(this),this.hiddenValue===!1&&this.show()}show(){this.enter(),this.timeout=setTimeout(this.hide,this.delayValue)}async hide(){this.timeout&&clearTimeout(this.timeout),await this.leave(),this.element.remove()}};i.values={delay:{type:Number,default:3e3},hidden:{type:Boolean,default:!1}};let s=i;export{s as default};
4
+
@@ -0,0 +1,4 @@
1
+ // @stimulus-components/password-visibility@3.0.0 downloaded from https://ga.jspm.io/npm:@stimulus-components/password-visibility@3.0.0/dist/stimulus-password-visibility.mjs
2
+
3
+ import{Controller as s}from"@hotwired/stimulus";const t=class _PasswordVisibility extends s{connect(){this.hidden=this.inputTarget.type==="password",this.class=this.hasHiddenClass?this.hiddenClass:"hidden"}toggle(s){s.preventDefault(),this.inputTarget.type=this.hidden?"text":"password",this.hidden=!this.hidden,this.iconTargets.forEach((s=>s.classList.toggle(this.class)))}};t.targets=["input","icon"],t.classes=["hidden"];let i=t;export{i as default};
4
+
@@ -0,0 +1,30 @@
1
+ The files in this folder are third-party packages, vendored with importmap.
2
+ Each package uses the MIT license.
3
+
4
+ @stimulus-components/dialog
5
+ @stimulus-components/notification
6
+ @stimulus-components/password-visibility
7
+ Copyright (c) Guillaume Briday
8
+
9
+ stimulus-use
10
+ Copyright (c) 2020 Adrien POLY
11
+
12
+ MIT License
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ // stimulus-use@0.52.3 downloaded from https://ga.jspm.io/npm:stimulus-use@0.52.3/dist/index.js
2
+
3
+ import{Controller as e}from"@hotwired/stimulus";const method=(e,t)=>{const s=e[t];return typeof s=="function"?s:(...e)=>{}};const composeEventName=(e,t,s)=>{let n=e;s===true?n=`${t.identifier}:${e}`:typeof s==="string"&&(n=`${s}:${e}`);return n};const extendedEvent=(e,t,s)=>{const{bubbles:n,cancelable:o,composed:i}=t||{bubbles:true,cancelable:true,composed:true};t&&Object.assign(s,{originalEvent:t});const r=new CustomEvent(e,{bubbles:n,cancelable:o,composed:i,detail:s});return r};function isElementInViewport(e){const t=e.getBoundingClientRect();const s=window.innerHeight||document.documentElement.clientHeight;const n=window.innerWidth||document.documentElement.clientWidth;const o=t.top<=s&&t.top+t.height>0;const i=t.left<=n&&t.left+t.width>0;return o&&i}function camelize(e){return e.replace(/(?:[_-])([a-z0-9])/g,((e,t)=>t.toUpperCase()))}function __rest(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols==="function"){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}const t={debug:false,logger:console,dispatchEvent:true,eventPrefix:true};class StimulusUse{constructor(e,s={}){var n,o,i;this.log=(e,t)=>{if(this.debug){this.logger.groupCollapsed(`%c${this.controller.identifier} %c#${e}`,"color: #3B82F6","color: unset");this.logger.log(Object.assign({controllerId:this.controllerId},t));this.logger.groupEnd()}};this.warn=e=>{this.logger.warn(`%c${this.controller.identifier} %c${e}`,"color: #3B82F6; font-weight: bold","color: unset")};this.dispatch=(e,t={})=>{if(this.dispatchEvent){const{event:s}=t,n=__rest(t,["event"]);const o=this.extendedEvent(e,s||null,n);this.targetElement.dispatchEvent(o);this.log("dispatchEvent",Object.assign({eventName:o.type},n))}};this.call=(e,t={})=>{const s=this.controller[e];if(typeof s=="function")return s.call(this.controller,t)};this.extendedEvent=(e,t,s)=>{const{bubbles:n,cancelable:o,composed:i}=t||{bubbles:true,cancelable:true,composed:true};t&&Object.assign(s,{originalEvent:t});const r=new CustomEvent(this.composeEventName(e),{bubbles:n,cancelable:o,composed:i,detail:s});return r};this.composeEventName=e=>{let t=e;this.eventPrefix===true?t=`${this.controller.identifier}:${e}`:typeof this.eventPrefix==="string"&&(t=`${this.eventPrefix}:${e}`);return t};this.debug=(o=(n=s===null||s===void 0?void 0:s.debug)!==null&&n!==void 0?n:e.application.stimulusUseDebug)!==null&&o!==void 0?o:t.debug;this.logger=(i=s===null||s===void 0?void 0:s.logger)!==null&&i!==void 0?i:t.logger;this.controller=e;this.controllerId=e.element.id||e.element.dataset.id;this.targetElement=(s===null||s===void 0?void 0:s.element)||e.element;const{dispatchEvent:r,eventPrefix:l}=Object.assign({},t,s);Object.assign(this,{dispatchEvent:r,eventPrefix:l});this.controllerInitialize=e.initialize.bind(e);this.controllerConnect=e.connect.bind(e);this.controllerDisconnect=e.disconnect.bind(e)}}const s={eventPrefix:true,bubbles:true,cancelable:true};class UseDispatch extends StimulusUse{constructor(e,t={}){var n,o,i,r;super(e,t);this.dispatch=(e,t={})=>{const{controller:s,targetElement:n,eventPrefix:o,bubbles:i,cancelable:r,log:l,warn:c}=this;Object.assign(t,{controller:s});const a=composeEventName(e,this.controller,o);const u=new CustomEvent(a,{detail:t,bubbles:i,cancelable:r});n.dispatchEvent(u);c("`useDispatch()` is deprecated. Please use the built-in `this.dispatch()` function from Stimulus. You can find more information on how to upgrade at: https://stimulus-use.github.io/stimulus-use/#/use-dispatch");l("dispatch",{eventName:a,detail:t,bubbles:i,cancelable:r});return u};this.targetElement=(n=t.element)!==null&&n!==void 0?n:e.element;this.eventPrefix=(o=t.eventPrefix)!==null&&o!==void 0?o:s.eventPrefix;this.bubbles=(i=t.bubbles)!==null&&i!==void 0?i:s.bubbles;this.cancelable=(r=t.cancelable)!==null&&r!==void 0?r:s.cancelable;this.enhanceController()}enhanceController(){Object.assign(this.controller,{dispatch:this.dispatch})}}const useDispatch=(e,t={})=>new UseDispatch(e,t);const n={overwriteDispatch:true};const useApplication=(e,t={})=>{const{overwriteDispatch:s}=Object.assign({},n,t);Object.defineProperty(e,"isPreview",{get(){return document.documentElement.hasAttribute("data-turbolinks-preview")||document.documentElement.hasAttribute("data-turbo-preview")}});Object.defineProperty(e,"isConnected",{get(){return!!Array.from(this.context.module.connectedContexts).find((e=>e===this.context))}});Object.defineProperty(e,"csrfToken",{get(){return this.metaValue("csrf-token")}});s&&useDispatch(e,t);Object.assign(e,{metaValue(e){const t=document.head.querySelector(`meta[name="${e}"]`);return t&&t.getAttribute("content")}})};class ApplicationController extends e{constructor(e){super(e);this.isPreview=false;this.isConnected=false;this.csrfToken="";useApplication(this,this.options)}}const o={events:["click","touchend"],onlyVisible:true,dispatchEvent:true,eventPrefix:true};const useClickOutside=(e,t={})=>{const s=e;const{onlyVisible:n,dispatchEvent:i,events:r,eventPrefix:l}=Object.assign({},o,t);const onEvent=e=>{const o=(t===null||t===void 0?void 0:t.element)||s.element;if(!(o.contains(e.target)||!isElementInViewport(o)&&n)){s.clickOutside&&s.clickOutside(e);if(i){const t=composeEventName("click:outside",s,l);const n=extendedEvent(t,e,{controller:s});o.dispatchEvent(n)}}};const observe=()=>{r===null||r===void 0?void 0:r.forEach((e=>{window.addEventListener(e,onEvent,true)}))};const unobserve=()=>{r===null||r===void 0?void 0:r.forEach((e=>{window.removeEventListener(e,onEvent,true)}))};const c=s.disconnect.bind(s);Object.assign(s,{disconnect(){unobserve();c()}});observe();return[observe,unobserve]};class ClickOutsideComposableController extends e{}class ClickOutsideController extends ClickOutsideComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useClickOutside(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}class DebounceController extends e{}DebounceController.debounces=[];const i=200;const debounce=(e,t=i)=>{let s=null;return function(){const n=Array.from(arguments);const o=this;const i=n.map((e=>e.params));const callback=()=>{n.forEach(((e,t)=>e.params=i[t]));return e.apply(o,n)};s&&clearTimeout(s);s=setTimeout(callback,t)}};const useDebounce=(e,t)=>{const s=e;const n=s.constructor;n.debounces.forEach((e=>{typeof e==="string"&&(s[e]=debounce(s[e],t===null||t===void 0?void 0:t.wait));if(typeof e==="object"){const{name:n,wait:o}=e;if(!n)return;s[n]=debounce(s[n],o||(t===null||t===void 0?void 0:t.wait))}}))};class UseHover extends StimulusUse{constructor(e,t={}){super(e,t);this.observe=()=>{this.targetElement.addEventListener("mouseenter",this.onEnter);this.targetElement.addEventListener("mouseleave",this.onLeave)};this.unobserve=()=>{this.targetElement.removeEventListener("mouseenter",this.onEnter);this.targetElement.removeEventListener("mouseleave",this.onLeave)};this.onEnter=e=>{this.call("mouseEnter",e);this.log("mouseEnter",{hover:true});this.dispatch("mouseEnter",{hover:false})};this.onLeave=e=>{this.call("mouseLeave",e);this.log("mouseLeave",{hover:false});this.dispatch("mouseLeave",{hover:false})};this.controller=e;this.enhanceController();this.observe()}enhanceController(){const e=this.controller.disconnect.bind(this.controller);const disconnect=()=>{this.unobserve();e()};Object.assign(this.controller,{disconnect:disconnect})}}const useHover=(e,t={})=>{const s=e;const n=new UseHover(s,t);return[n.observe,n.unobserve]};class HoverComposableController extends e{}class HoverController extends HoverComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useHover(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}const r=["mousemove","mousedown","resize","keydown","touchstart","wheel"];const l=6e4;const c={ms:l,initialState:false,events:r,dispatchEvent:true,eventPrefix:true};const useIdle=(e,t={})=>{const s=e;const{ms:n,initialState:o,events:i,dispatchEvent:r,eventPrefix:l}=Object.assign({},c,t);let a=o;let u=setTimeout((()=>{a=true;dispatchAway()}),n);const dispatchAway=e=>{const t=composeEventName("away",s,l);s.isIdle=true;method(s,"away").call(s,e);if(r){const n=extendedEvent(t,e||null,{controller:s});s.element.dispatchEvent(n)}};const dispatchBack=e=>{const t=composeEventName("back",s,l);s.isIdle=false;method(s,"back").call(s,e);if(r){const n=extendedEvent(t,e||null,{controller:s});s.element.dispatchEvent(n)}};const onEvent=e=>{a&&dispatchBack(e);a=false;clearTimeout(u);u=setTimeout((()=>{a=true;dispatchAway(e)}),n)};const onVisibility=e=>{document.hidden||onEvent(e)};a?dispatchAway():dispatchBack();const h=s.disconnect.bind(s);const observe=()=>{i.forEach((e=>{window.addEventListener(e,onEvent)}));document.addEventListener("visibilitychange",onVisibility)};const unobserve=()=>{clearTimeout(u);i.forEach((e=>{window.removeEventListener(e,onEvent)}));document.removeEventListener("visibilitychange",onVisibility)};Object.assign(s,{disconnect(){unobserve();h()}});observe();return[observe,unobserve]};class IdleComposableController extends e{constructor(){super(...arguments);this.isIdle=false}}class IdleController extends IdleComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useIdle(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}const a={dispatchEvent:true,eventPrefix:true,visibleAttribute:"isVisible"};const useIntersection=(e,t={})=>{const s=e;const{dispatchEvent:n,eventPrefix:o,visibleAttribute:i}=Object.assign({},a,t);const r=(t===null||t===void 0?void 0:t.element)||s.element;s.intersectionElements||(s.intersectionElements=[]);s.intersectionElements.push(r);const callback=e=>{const[t]=e;t.isIntersecting?dispatchAppear(t):r.hasAttribute(i)&&dispatchDisappear(t)};const l=new IntersectionObserver(callback,t);const dispatchAppear=e=>{r.setAttribute(i,"true");method(s,"appear").call(s,e,l);if(n){const t=composeEventName("appear",s,o);const n=extendedEvent(t,null,{controller:s,entry:e,observer:l});r.dispatchEvent(n)}};const dispatchDisappear=e=>{r.removeAttribute(i);method(s,"disappear").call(s,e,l);if(n){const t=composeEventName("disappear",s,o);const n=extendedEvent(t,null,{controller:s,entry:e,observer:l});r.dispatchEvent(n)}};const c=s.disconnect.bind(s);const disconnect=()=>{unobserve();c()};const observe=()=>{l.observe(r)};const unobserve=()=>{l.unobserve(r)};const noneVisible=()=>s.intersectionElements.filter((e=>e.hasAttribute(i))).length===0;const oneVisible=()=>s.intersectionElements.filter((e=>e.hasAttribute(i))).length===1;const atLeastOneVisible=()=>s.intersectionElements.some((e=>e.hasAttribute(i)));const allVisible=()=>s.intersectionElements.every((e=>e.hasAttribute(i)));const u=allVisible;Object.assign(s,{isVisible:u,noneVisible:noneVisible,oneVisible:oneVisible,atLeastOneVisible:atLeastOneVisible,allVisible:allVisible,disconnect:disconnect});observe();return[observe,unobserve]};class IntersectionComposableController extends e{}class IntersectionController extends IntersectionComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useIntersection(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}const useLazyLoad=(e,t)=>{const callback=t=>{const[s]=t;s.isIntersecting&&!e.isLoaded&&handleAppear()};const handleAppear=t=>{const s=e.data.get("src");if(!s)return;const n=e.element;e.isLoading=true;method(e,"loading").call(e,s);n.onload=()=>{handleLoaded(s)};n.src=s};const handleLoaded=t=>{e.isLoading=false;e.isLoaded=true;method(e,"loaded").call(e,t)};const s=e.disconnect.bind(e);const n=new IntersectionObserver(callback,t);const observe=()=>{n.observe(e.element)};const unobserve=()=>{n.unobserve(e.element)};Object.assign(e,{isVisible:false,disconnect(){unobserve();s()}});observe();return[observe,unobserve]};class LazyLoadComposableController extends e{constructor(){super(...arguments);this.isLoading=false;this.isLoaded=false}}class LazyLoadController extends LazyLoadComposableController{constructor(e){super(e);this.options={rootMargin:"10%"};requestAnimationFrame((()=>{const[e,t]=useLazyLoad(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}const u={mediaQueries:{},dispatchEvent:true,eventPrefix:true,debug:false};class UseMatchMedia extends StimulusUse{constructor(e,t={}){var s,n,o,i;super(e,t);this.matches=[];this.callback=e=>{const t=Object.keys(this.mediaQueries).find((t=>this.mediaQueries[t]===e.media));if(!t)return;const{media:s,matches:n}=e;this.changed({name:t,media:s,matches:n,event:e})};this.changed=e=>{const{name:t}=e;if(e.event){this.call(camelize(`${t}_changed`),e);this.dispatch(`${t}:changed`,e);this.log(`media query "${t}" changed`,e)}if(e.matches){this.call(camelize(`is_${t}`),e);this.dispatch(`is:${t}`,e)}else{this.call(camelize(`not_${t}`),e);this.dispatch(`not:${t}`,e)}};this.observe=()=>{Object.keys(this.mediaQueries).forEach((e=>{const t=this.mediaQueries[e];const s=window.matchMedia(t);s.addListener(this.callback);this.matches.push(s);this.changed({name:e,media:t,matches:s.matches})}))};this.unobserve=()=>{this.matches.forEach((e=>e.removeListener(this.callback)))};this.controller=e;this.mediaQueries=(s=t.mediaQueries)!==null&&s!==void 0?s:u.mediaQueries;this.dispatchEvent=(n=t.dispatchEvent)!==null&&n!==void 0?n:u.dispatchEvent;this.eventPrefix=(o=t.eventPrefix)!==null&&o!==void 0?o:u.eventPrefix;this.debug=(i=t.debug)!==null&&i!==void 0?i:u.debug;if(window.matchMedia){this.enhanceController();this.observe()}else console.error("window.matchMedia() is not available")}enhanceController(){const e=this.controller.disconnect.bind(this.controller);const disconnect=()=>{this.unobserve();e()};Object.assign(this.controller,{disconnect:disconnect})}}const useMatchMedia=(e,t={})=>{const s=new UseMatchMedia(e,t);return[s.observe,s.unobserve]};const memoize=(e,t,s)=>{Object.defineProperty(e,t,{value:s});return s};const useMemo=e=>{var t;(t=e.constructor.memos)===null||t===void 0?void 0:t.forEach((t=>{memoize(e,t,e[t])}))};const defineMetaGetter=(e,t,s)=>{const n=s?`${camelize(t)}Meta`:camelize(t);Object.defineProperty(e,n,{get(){return typeCast(metaValue(t))}})};function metaValue(e){const t=document.head.querySelector(`meta[name="${e}"]`);return t&&t.getAttribute("content")}function typeCast(e){try{return JSON.parse(e)}catch(t){return e}}const useMeta=(e,t={suffix:true})=>{const s=e.constructor.metaNames;const n=t.suffix;s===null||s===void 0?void 0:s.forEach((t=>{defineMetaGetter(e,t,n)}));Object.defineProperty(e,"metas",{get(){const e={};s===null||s===void 0?void 0:s.forEach((t=>{const s=typeCast(metaValue(t));s!==void 0&&s!==null&&(e[camelize(t)]=s)}));return e}})};class UseMutation extends StimulusUse{constructor(e,t={}){super(e,t);this.observe=()=>{try{this.observer.observe(this.targetElement,this.options)}catch(e){this.controller.application.handleError(e,"At a minimum, one of childList, attributes, and/or characterData must be true",{})}};this.unobserve=()=>{this.observer.disconnect()};this.mutation=e=>{this.call("mutate",e);this.log("mutate",{entries:e});this.dispatch("mutate",{entries:e})};this.targetElement=(t===null||t===void 0?void 0:t.element)||e.element;this.controller=e;this.options=t;this.observer=new MutationObserver(this.mutation);this.enhanceController();this.observe()}enhanceController(){const e=this.controller.disconnect.bind(this.controller);const disconnect=()=>{this.unobserve();e()};Object.assign(this.controller,{disconnect:disconnect})}}const useMutation=(e,t={})=>{const s=new UseMutation(e,t);return[s.observe,s.unobserve]};class MutationComposableController extends e{}class MutationController extends MutationComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useMutation(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}const h={dispatchEvent:true,eventPrefix:true};const useResize=(e,t={})=>{const s=e;const{dispatchEvent:n,eventPrefix:o}=Object.assign({},h,t);const i=(t===null||t===void 0?void 0:t.element)||s.element;const callback=e=>{const[t]=e;method(s,"resize").call(s,t.contentRect);if(n){const e=composeEventName("resize",s,o);const n=extendedEvent(e,null,{controller:s,entry:t});i.dispatchEvent(n)}};const r=s.disconnect.bind(s);const l=new ResizeObserver(callback);const observe=()=>{l.observe(i)};const unobserve=()=>{l.unobserve(i)};Object.assign(s,{disconnect(){unobserve();r()}});observe();return[observe,unobserve]};class ResizeComposableController extends e{}class ResizeController extends ResizeComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useResize(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}class UseTargetMutation extends StimulusUse{constructor(e,t={}){super(e,t);this.observe=()=>{this.observer.observe(this.targetElement,{subtree:true,characterData:true,childList:true,attributes:true,attributeOldValue:true,attributeFilter:[this.targetSelector,this.scopedTargetSelector]})};this.unobserve=()=>{this.observer.disconnect()};this.mutation=e=>{for(const t of e)switch(t.type){case"attributes":let e=t.target.getAttribute(t.attributeName);let s=t.oldValue;if(t.attributeName===this.targetSelector||t.attributeName===this.scopedTargetSelector){let n=this.targetsUsedByThisController(s);let o=this.targetsUsedByThisController(e);let i=n.filter((e=>!o.includes(e)));let r=o.filter((e=>!n.includes(e)));i.forEach((e=>this.targetRemoved(this.stripIdentifierPrefix(e),t.target,"attributeChange")));r.forEach((e=>this.targetAdded(this.stripIdentifierPrefix(e),t.target,"attributeChange")))}break;case"characterData":let n=this.findTargetInAncestry(t.target);if(n==null)return;{let e=this.targetsUsedByThisControllerFromNode(n);e.forEach((e=>{this.targetChanged(this.stripIdentifierPrefix(e),n,"domMutation")}))}break;case"childList":let{addedNodes:o,removedNodes:i}=t;o.forEach((e=>this.processNodeDOMMutation(e,this.targetAdded)));i.forEach((e=>this.processNodeDOMMutation(e,this.targetRemoved)));break}};this.controller=e;this.options=t;this.targetElement=e.element;this.identifier=e.scope.identifier;this.identifierPrefix=`${this.identifier}.`;this.targetSelector=e.scope.schema.targetAttribute;this.scopedTargetSelector=`data-${this.identifier}-target`;this.targets=t.targets||e.constructor.targets;this.prefixedTargets=this.targets.map((e=>`${this.identifierPrefix}${e}`));this.observer=new MutationObserver(this.mutation);this.enhanceController();this.observe()}processNodeDOMMutation(e,t){let s=e;let n=t;let o=[];if(s.nodeName=="#text"||this.targetsUsedByThisControllerFromNode(s).length==0){n=this.targetChanged;s=this.findTargetInAncestry(e)}else o=this.targetsUsedByThisControllerFromNode(s);if(s!=null){o.length==0&&(o=this.targetsUsedByThisControllerFromNode(s));o.forEach((e=>{n.call(this,this.stripIdentifierPrefix(e),s,"domMutation")}))}}findTargetInAncestry(e){let t=e;let s=[];t.nodeName!="#text"&&(s=this.targetsUsedByThisControllerFromNode(t));while(t.parentNode!==null&&t.parentNode!=this.targetElement&&s.length==0){t=t.parentNode;if(t.nodeName!=="#text"){let e=this.targetsUsedByThisControllerFromNode(t);if(e.length>0)return t}}return t.nodeName=="#text"||t.parentNode==null?null:t.parentNode==this.targetElement&&this.targetsUsedByThisControllerFromNode(t).length>0?t:null}targetAdded(e,t,s){let n=`${e}TargetAdded`;this.controller[n]&&method(this.controller,n).call(this.controller,t);this.warn("`[target]TargetAdded` is deprecated. Please use the built-in `[target]TargetConnected()` function from Stimulus.");this.log("targetAdded",{target:e,node:t,trigger:s})}targetRemoved(e,t,s){let n=`${e}TargetRemoved`;this.controller[n]&&method(this.controller,n).call(this.controller,t);this.warn("`[target]TargetRemoved` is deprecated. Please use the built-in `[target]TargetDisconnected()` function from Stimulus.");this.log("targetRemoved",{target:e,node:t,trigger:s})}targetChanged(e,t,s){let n=`${e}TargetChanged`;this.controller[n]&&method(this.controller,n).call(this.controller,t);this.log("targetChanged",{target:e,node:t,trigger:s})}targetsUsedByThisControllerFromNode(e){if(e.nodeName=="#text"||e.nodeName=="#comment")return[];let t=e;return this.targetsUsedByThisController(t.getAttribute(this.scopedTargetSelector)||t.getAttribute(this.targetSelector))}targetsUsedByThisController(e){e=e||"";let t=this.stripIdentifierPrefix(e).split(" ");return this.targets.filter((e=>t.indexOf(e)!==-1))}stripIdentifierPrefix(e){return e.replace(new RegExp(this.identifierPrefix,"g"),"")}enhanceController(){const e=this.controller.disconnect.bind(this.controller);const disconnect=()=>{this.unobserve();e()};Object.assign(this.controller,{disconnect:disconnect})}}const useTargetMutation=(e,t={})=>{const s=e;const n=new UseTargetMutation(s,t);n.warn("`[target]TargetAdded` and `[target]TargetRemoved` are deprecated. Please use the built-in `[target]TargetConnected()` and `[target]TargetDisconnected()` functions from Stimulus.");return[n.observe,n.unobserve]};class TargetMutationComposableController extends e{}class TargetMutationController extends TargetMutationComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useTargetMutation(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}class ThrottleController extends e{}ThrottleController.throttles=[];const d=200;function throttle(e,t=d){let s;return function(){const n=arguments;const o=this;if(!s){s=true;e.apply(o,n);setTimeout((()=>s=false),t)}}}const useThrottle=(e,t={})=>{var s;const n=e;const o=n.constructor;(s=o.throttles)===null||s===void 0?void 0:s.forEach((e=>{typeof e==="string"&&(n[e]=throttle(n[e],t===null||t===void 0?void 0:t.wait));if(typeof e==="object"){const{name:s,wait:o}=e;if(!s)return;n[s]=throttle(n[s],o||(t===null||t===void 0?void 0:t.wait))}}))};const b={enterFromClass:"enter",enterActiveClass:"enterStart",enterToClass:"enterEnd",leaveFromClass:"leave",leaveActiveClass:"leaveStart",leaveToClass:"leaveEnd"};const m={transitioned:false,hiddenClass:"hidden",preserveOriginalClass:true,removeToClasses:true};const useTransition=(e,t={})=>{var s,n,o;const i=e;const r=i.element.dataset.transitionTarget;let l;r&&(l=i[`${r}Target`]);const c=(t===null||t===void 0?void 0:t.element)||l||i.element;if(!(c instanceof HTMLElement||c instanceof SVGElement))return;const a=c.dataset;const u=parseInt(a.leaveAfter||"")||t.leaveAfter||0;const{transitioned:h,hiddenClass:d,preserveOriginalClass:b,removeToClasses:v}=Object.assign({},m,t);const g=(s=i.enter)===null||s===void 0?void 0:s.bind(i);const p=(n=i.leave)===null||n===void 0?void 0:n.bind(i);const f=(o=i.toggleTransition)===null||o===void 0?void 0:o.bind(i);async function enter(e){if(i.transitioned)return;i.transitioned=true;g&&g(e);const s=getAttribute("enterFrom",t,a);const n=getAttribute("enterActive",t,a);const o=getAttribute("enterTo",t,a);const r=getAttribute("leaveTo",t,a);!d||c.classList.remove(d);v||removeClasses(c,r);await transition(c,s,n,o,d,b,v);u>0&&setTimeout((()=>{leave(e)}),u)}async function leave(e){if(!i.transitioned)return;i.transitioned=false;p&&p(e);const s=getAttribute("leaveFrom",t,a);const n=getAttribute("leaveActive",t,a);const o=getAttribute("leaveTo",t,a);const r=getAttribute("enterTo",t,a);v||removeClasses(c,r);await transition(c,s,n,o,d,b,v);!d||c.classList.add(d)}function toggleTransition(e){f&&f(e);i.transitioned?leave():enter()}async function transition(e,t,s,n,o,i,r){const l=[];if(i){t.forEach((t=>e.classList.contains(t)&&t!==o&&l.push(t)));s.forEach((t=>e.classList.contains(t)&&t!==o&&l.push(t)));n.forEach((t=>e.classList.contains(t)&&t!==o&&l.push(t)))}addClasses(e,t);removeClasses(e,l);addClasses(e,s);await nextAnimationFrame();removeClasses(e,t);addClasses(e,n);await afterTransition(e);removeClasses(e,s);r&&removeClasses(e,n);addClasses(e,l)}function initialState(){i.transitioned=h;if(h){!d||c.classList.remove(d);enter()}else{!d||c.classList.add(d);leave()}}function addClasses(e,t){t.length>0&&e.classList.add(...t)}function removeClasses(e,t){t.length>0&&e.classList.remove(...t)}initialState();Object.assign(i,{enter:enter,leave:leave,toggleTransition:toggleTransition});return[enter,leave,toggleTransition]};function getAttribute(e,t,s){const n=`transition${e[0].toUpperCase()}${e.substr(1)}`;const o=b[e];const i=t[e]||s[n]||s[o]||" ";return isEmpty(i)?[]:i.split(" ")}async function afterTransition(e){return new Promise((t=>{const s=Number(getComputedStyle(e).transitionDuration.split(",")[0].replace("s",""))*1e3;setTimeout((()=>{t(s)}),s)}))}async function nextAnimationFrame(){return new Promise((e=>{requestAnimationFrame((()=>{requestAnimationFrame(e)}))}))}function isEmpty(e){return e.length===0||!e.trim()}class TransitionComposableController extends e{constructor(){super(...arguments);this.transitioned=false}}class TransitionController extends TransitionComposableController{constructor(e){super(e);requestAnimationFrame((()=>{useTransition(this,this.options)}))}}class UseVisibility extends StimulusUse{constructor(e,t={}){super(e,t);this.observe=()=>{this.controller.isVisible=!document.hidden;document.addEventListener("visibilitychange",this.handleVisibilityChange);this.handleVisibilityChange()};this.unobserve=()=>{document.removeEventListener("visibilitychange",this.handleVisibilityChange)};this.becomesInvisible=e=>{this.controller.isVisible=false;this.call("invisible",e);this.log("invisible",{isVisible:false});this.dispatch("invisible",{event:e,isVisible:false})};this.becomesVisible=e=>{this.controller.isVisible=true;this.call("visible",e);this.log("visible",{isVisible:true});this.dispatch("visible",{event:e,isVisible:true})};this.handleVisibilityChange=e=>{document.hidden?this.becomesInvisible(e):this.becomesVisible(e)};this.controller=e;this.enhanceController();this.observe()}enhanceController(){const e=this.controllerDisconnect;const disconnect=()=>{this.unobserve();e()};Object.assign(this.controller,{disconnect:disconnect})}}const useVisibility=(e,t={})=>{const s=e;const n=new UseVisibility(s,t);return[n.observe,n.unobserve]};class VisibilityComposableController extends e{constructor(){super(...arguments);this.isVisible=false}}class VisibilityController extends VisibilityComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useVisibility(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}class UseWindowFocus extends StimulusUse{constructor(e,t={}){super(e,t);this.observe=()=>{document.hasFocus()?this.becomesFocused():this.becomesUnfocused();this.interval=setInterval((()=>{this.handleWindowFocusChange()}),this.intervalDuration)};this.unobserve=()=>{clearInterval(this.interval)};this.becomesUnfocused=e=>{this.controller.hasFocus=false;this.call("unfocus",e);this.log("unfocus",{hasFocus:false});this.dispatch("unfocus",{event:e,hasFocus:false})};this.becomesFocused=e=>{this.controller.hasFocus=true;this.call("focus",e);this.log("focus",{hasFocus:true});this.dispatch("focus",{event:e,hasFocus:true})};this.handleWindowFocusChange=e=>{document.hasFocus()&&!this.controller.hasFocus?this.becomesFocused(e):!document.hasFocus()&&this.controller.hasFocus&&this.becomesUnfocused(e)};this.controller=e;this.intervalDuration=t.interval||200;this.enhanceController();this.observe()}enhanceController(){const e=this.controllerDisconnect;const disconnect=()=>{this.unobserve();e()};Object.assign(this.controller,{disconnect:disconnect})}}const useWindowFocus=(e,t={})=>{const s=e;const n=new UseWindowFocus(s,t);return[n.observe,n.unobserve]};class WindowFocusComposableController extends e{constructor(){super(...arguments);this.hasFocus=false}}class WindowFocusController extends WindowFocusComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useWindowFocus(this,this.options);Object.assign(this,{observe:e,unobserve:t})}))}}const useWindowResize=e=>{const t=e;const callback=e=>{const{innerWidth:s,innerHeight:n}=window;const o={height:n||Infinity,width:s||Infinity,event:e};method(t,"windowResize").call(t,o)};const s=t.disconnect.bind(t);const observe=()=>{window.addEventListener("resize",callback);callback()};const unobserve=()=>{window.removeEventListener("resize",callback)};Object.assign(t,{disconnect(){unobserve();s()}});observe();return[observe,unobserve]};class WindowResizeComposableController extends e{}class WindowResizeController extends WindowResizeComposableController{constructor(e){super(e);requestAnimationFrame((()=>{const[e,t]=useWindowResize(this);Object.assign(this,{observe:e,unobserve:t})}))}}function useHotkeys(){throw"[stimulus-use] Notice: The import for `useHotkeys()` has been moved from `stimulus-use` to `stimulus-use/hotkeys`. \nPlease change the import accordingly and add `hotkey-js` as a dependency to your project. \n\nFor more information see: https://stimulus-use.github.io/stimulus-use/#/use-hotkeys?id=importing-the-behavior"}export{ApplicationController,ClickOutsideController,HoverController,IdleController,IntersectionController,LazyLoadController,MutationController,ResizeController,TargetMutationController,TransitionController,UseHover,UseMutation,UseTargetMutation,UseVisibility,UseWindowFocus,VisibilityController,WindowFocusController,WindowResizeController,debounce,useApplication,useClickOutside,useDebounce,useDispatch,useHotkeys,useHover,useIdle,useIntersection,useLazyLoad,useMatchMedia,useMemo,useMeta,useMutation,useResize,useTargetMutation,useThrottle,useTransition,useVisibility,useWindowFocus,useWindowResize};
4
+