proscenium 0.18.0-arm64-darwin → 0.19.0-arm64-darwin

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -174
  3. data/lib/proscenium/builder.rb +36 -100
  4. data/lib/proscenium/bundled_gems.rb +37 -0
  5. data/lib/proscenium/css_module/path.rb +2 -1
  6. data/lib/proscenium/css_module/transformer.rb +1 -1
  7. data/lib/proscenium/css_module.rb +16 -9
  8. data/lib/proscenium/ensure_loaded.rb +14 -10
  9. data/lib/proscenium/ext/proscenium +0 -0
  10. data/lib/proscenium/ext/proscenium.h +9 -36
  11. data/lib/proscenium/helper.rb +4 -22
  12. data/lib/proscenium/importer.rb +39 -21
  13. data/lib/proscenium/log_subscriber.rb +11 -10
  14. data/lib/proscenium/middleware/base.rb +11 -6
  15. data/lib/proscenium/middleware/esbuild.rb +8 -9
  16. data/lib/proscenium/middleware/ruby_gems.rb +23 -0
  17. data/lib/proscenium/middleware.rb +26 -24
  18. data/lib/proscenium/monkey.rb +5 -14
  19. data/lib/proscenium/railtie.rb +11 -53
  20. data/lib/proscenium/{libs/react-manager → react-manager}/index.jsx +3 -22
  21. data/lib/proscenium/react_componentable.rb +2 -3
  22. data/lib/proscenium/resolver.rb +14 -23
  23. data/lib/proscenium/side_load.rb +41 -74
  24. data/lib/proscenium/utils.rb +33 -0
  25. data/lib/proscenium/version.rb +1 -1
  26. data/lib/proscenium.rb +2 -12
  27. metadata +11 -99
  28. data/lib/proscenium/core_ext/object/css_module_ivars.rb +0 -19
  29. data/lib/proscenium/css_module/rewriter.rb +0 -44
  30. data/lib/proscenium/libs/custom_element.js +0 -54
  31. data/lib/proscenium/libs/stimulus-loading.js +0 -65
  32. data/lib/proscenium/libs/test.js +0 -1
  33. data/lib/proscenium/libs/ujs/class.js +0 -15
  34. data/lib/proscenium/libs/ujs/data_confirm.js +0 -23
  35. data/lib/proscenium/libs/ujs/data_disable_with.js +0 -68
  36. data/lib/proscenium/libs/ujs/index.js +0 -9
  37. data/lib/proscenium/middleware/engines.rb +0 -45
  38. data/lib/proscenium/middleware/runtime.rb +0 -18
  39. data/lib/proscenium/phlex/asset_inclusions.rb +0 -17
  40. data/lib/proscenium/phlex/css_modules.rb +0 -79
  41. data/lib/proscenium/phlex/react_component.rb +0 -32
  42. data/lib/proscenium/phlex.rb +0 -42
  43. data/lib/proscenium/ui/breadcrumbs/component.module.css +0 -14
  44. data/lib/proscenium/ui/breadcrumbs/component.rb +0 -73
  45. data/lib/proscenium/ui/breadcrumbs/computed_element.rb +0 -69
  46. data/lib/proscenium/ui/breadcrumbs/control.rb +0 -95
  47. data/lib/proscenium/ui/breadcrumbs/mixins.css +0 -83
  48. data/lib/proscenium/ui/breadcrumbs.rb +0 -72
  49. data/lib/proscenium/ui/component.rb +0 -7
  50. data/lib/proscenium/ui/test.js +0 -1
  51. data/lib/proscenium/ui.rb +0 -8
  52. data/lib/proscenium/view_component/css_modules.rb +0 -11
  53. data/lib/proscenium/view_component/react_component.rb +0 -22
  54. data/lib/proscenium/view_component/sideload.rb +0 -4
  55. data/lib/proscenium/view_component.rb +0 -38
  56. /data/lib/proscenium/{libs/react-manager → react-manager}/react.js +0 -0
@@ -4,36 +4,27 @@ require 'active_support/current_attributes'
4
4
 
5
5
  module Proscenium
6
6
  class Resolver < ActiveSupport::CurrentAttributes
7
- # TODO: cache this across requests in production.
8
- attribute :resolved
7
+ attribute :resolved unless Rails.env.production?
8
+ mattr_accessor :resolved if Rails.env.production?
9
9
 
10
- # Resolve the given `path` to a URL path.
10
+ # Resolve the given `path` to a fully qualified URL path.
11
11
  #
12
- # @param path [String] Can be URL path, file system path, or bare specifier (ie. NPM package).
12
+ # @param path [String] URL path, file system path, or bare specifier (ie. NPM package).
13
13
  # @return [String] URL path.
14
- #
15
- # rubocop:disable Metrics/*
16
14
  def self.resolve(path)
17
15
  self.resolved ||= {}
18
16
 
19
- self.resolved[path] ||= begin
20
- if path.start_with?('./', '../')
21
- raise ArgumentError, 'path must be an absolute file system or URL path'
22
- end
23
-
24
- if path.start_with?('@proscenium/')
25
- "/#{path}"
26
- elsif path.start_with?(Proscenium.ui_path.to_s)
27
- path.delete_prefix Proscenium.root.join('lib').to_s
28
- elsif (engine = Proscenium.config.engines.find { |e| path.start_with? "#{e.root}/" })
29
- path.sub(/^#{engine.root}/, "/#{engine.engine_name}")
30
- elsif path.start_with?("#{Rails.root}/")
31
- path.delete_prefix Rails.root.to_s
32
- else
33
- Builder.resolve path
34
- end
17
+ if path.start_with?('./', '../')
18
+ raise ArgumentError, '`path` must be an absolute file system or URL path'
35
19
  end
20
+
21
+ self.resolved[path] ||= if (gem = BundledGems.paths.find { |_, v| path.start_with? "#{v}/" })
22
+ path.sub(/^#{gem.last}/, "/node_modules/@rubygems/#{gem.first}")
23
+ elsif path.start_with?("#{Rails.root}/")
24
+ path.delete_prefix Rails.root.to_s
25
+ else
26
+ Builder.resolve path
27
+ end
36
28
  end
37
- # rubocop:enable Metrics/*
38
29
  end
39
30
  end
@@ -4,7 +4,6 @@ module Proscenium
4
4
  class SideLoad
5
5
  JS_COMMENT = '<!-- [PROSCENIUM_JAVASCRIPTS] -->'
6
6
  CSS_COMMENT = '<!-- [PROSCENIUM_STYLESHEETS] -->'
7
- LAZY_COMMENT = '<!-- [PROSCENIUM_LAZY_SCRIPTS] -->'
8
7
 
9
8
  module Controller
10
9
  def self.included(child)
@@ -35,29 +34,16 @@ module Proscenium
35
34
 
36
35
  return if !fragments && !included_comment
37
36
 
38
- imports = Proscenium::Importer.imported.dup
39
- paths_to_build = []
40
- Proscenium::Importer.each_stylesheet(delete: true) do |x, _|
41
- paths_to_build << x.delete_prefix('/')
42
- end
43
-
44
- result = Proscenium::Builder.build_to_path(paths_to_build.join(';'),
45
- base_url: helpers.request.base_url)
46
-
47
37
  out = []
48
- result.split(';').each do |x|
49
- inpath, outpath = x.split('::')
50
- inpath.prepend '/'
51
- outpath.delete_prefix! 'public'
52
-
53
- next unless imports.key?(inpath)
54
-
55
- import = imports[inpath]
56
- opts = import[:css].is_a?(Hash) ? import[:css] : {}
38
+ Proscenium::Importer.each_stylesheet(delete: true) do |path, opts|
39
+ opts = opts[:css].is_a?(Hash) ? opts[:css] : {}
57
40
  opts[:preload_links_header] = false if fragments
58
41
  opts[:data] ||= {}
59
- opts[:data][:original_href] = inpath
60
- out << helpers.stylesheet_link_tag(outpath, extname: false, **opts)
42
+
43
+ if Proscenium.config.cache_query_string.present?
44
+ path += "?#{Proscenium.config.cache_query_string}"
45
+ end
46
+ out << helpers.stylesheet_link_tag(path, extname: false, **opts)
61
47
  end
62
48
 
63
49
  if fragments
@@ -71,73 +57,43 @@ module Proscenium
71
57
  return if response_body.nil?
72
58
  return if response_body.first.blank? || !Proscenium::Importer.js_imported?
73
59
 
74
- imports = Proscenium::Importer.imported.dup
75
- paths_to_build = []
76
- Proscenium::Importer.each_javascript(delete: true) do |x, _|
77
- paths_to_build << x.delete_prefix('/')
78
- end
79
-
80
- result = Proscenium::Builder.build_to_path(paths_to_build.join(';'),
81
- base_url: helpers.request.base_url)
82
-
83
- included_js_comment = response_body.first.include?(JS_COMMENT)
84
- included_lazy_comment = response_body.first.include?(LAZY_COMMENT)
60
+ included_comment = response_body.first.include?(JS_COMMENT)
85
61
  fragments = if (fragment_header = request.headers['X-Fragment'])
86
62
  fragment_header.split
87
63
  end
88
64
 
89
- if fragments || included_js_comment
90
- out = []
91
- scripts = {}
92
- result.split(';').each do |x|
93
- inpath, outpath = x.split('::')
94
- inpath.prepend '/'
95
- outpath.delete_prefix! 'public'
96
-
97
- next unless imports.key?(inpath)
98
-
99
- if (import = imports[inpath]).delete(:lazy)
100
- scripts[inpath] = import.merge(outpath:)
101
- else
102
- opts = import[:js].is_a?(Hash) ? import[:js] : {}
103
- opts[:preload_links_header] = false if fragments
104
- out << helpers.javascript_include_tag(outpath, extname: false, **opts)
105
- end
106
- end
65
+ return if !fragments && !included_comment
107
66
 
108
- if fragments
109
- response_body.first.prepend out.join.html_safe
110
- elsif included_js_comment
111
- response_body.first.gsub! JS_COMMENT, out.join.html_safe
112
- end
113
- end
67
+ out = []
68
+ Proscenium::Importer.each_javascript(delete: true) do |path, opts|
69
+ next if opts.delete(:lazy)
114
70
 
115
- return if !fragments && !included_lazy_comment
71
+ opts = opts[:js].is_a?(Hash) ? opts[:js] : {}
72
+ opts[:preload_links_header] = false if fragments
116
73
 
117
- lazy_script = ''
118
- if scripts.present?
119
- lazy_script = helpers.content_tag 'script', type: 'application/json',
120
- id: 'prosceniumLazyScripts' do
121
- scripts.to_json.html_safe
74
+ if Proscenium.config.cache_query_string.present?
75
+ path += "?#{Proscenium.config.cache_query_string}"
122
76
  end
77
+ out << helpers.javascript_include_tag(path, extname: false, **opts)
123
78
  end
124
79
 
125
80
  if fragments
126
- response_body.first.prepend lazy_script
127
- elsif included_lazy_comment
128
- response_body.first.gsub! LAZY_COMMENT, lazy_script
81
+ response_body.first.prepend out.join.html_safe
82
+ elsif included_comment
83
+ response_body.first.gsub! JS_COMMENT, out.join.html_safe
129
84
  end
130
85
  end
131
86
  end
132
87
 
133
88
  class << self
134
- # Side loads the class, and its super classes that respond to `.source_path`.
89
+ # Side loads assets for the class, and its super classes that respond to `.source_path`, which
90
+ # should return a Pathname of the class source file.
135
91
  #
136
92
  # Set the `abstract_class` class variable to true in any class, and it will not be side
137
93
  # loaded.
138
94
  #
139
- # If the class responds to `.sideload`, it will be called instead of the regular side loading.
140
- # You can use this to customise what is side loaded.
95
+ # If the class responds to `.sideload`, it will be called after the regular side loading. You
96
+ # can use this to customise what is side loaded.
141
97
  def sideload_inheritance_chain(obj, options)
142
98
  return unless Proscenium.config.side_load
143
99
 
@@ -160,23 +116,34 @@ module Proscenium
160
116
  css_imports = []
161
117
 
162
118
  klass = obj.class
163
- while klass.respond_to?(:source_path) && klass.source_path && !klass.abstract_class
164
- if klass.respond_to?(:sideload)
165
- klass.sideload options
166
- elsif options[:css] == false
119
+ while klass.respond_to?(:source_path) && klass.source_path &&
120
+ (klass.respond_to?(:abstract_class) ? !klass.abstract_class : true)
121
+ if options[:css] == false
167
122
  Importer.sideload klass.source_path, **options
168
123
  else
169
124
  Importer.sideload_js klass.source_path, **options
170
125
  css_imports << klass.source_path
171
126
  end
172
127
 
128
+ klass.sideload options if klass.respond_to?(:sideload)
129
+
173
130
  klass = klass.superclass
174
131
  end
175
132
 
133
+ # All regular CSS files (*.css) are ancestrally sideloaded. However, the first CSS module
134
+ # in the ancestry is also sideloaded in addition to the regular CSS files. This is because
135
+ # the CSS module digest will be different for each file, so we only sideload the first CSS
136
+ # module.
137
+ css_imports.each do |it| # rubocop:disable Style/ItAssignment
138
+ break if Importer.sideload_css_module(it, **options).present?
139
+ end
140
+
141
+ # Sideload regular CSS files in reverse order.
142
+ #
176
143
  # The reason why we sideload CSS after JS is because the order of CSS is important.
177
- # Basically, the layout should be loaded before the view so that CSS cascading works i9n the
144
+ # Basically, the layout should be loaded before the view so that CSS cascading works in the
178
145
  # right direction.
179
- css_imports.reverse_each do |it|
146
+ css_imports.reverse_each do |it| # rubocop:disable Style/ItAssignment
180
147
  Importer.sideload_css it, **options
181
148
  end
182
149
  end
@@ -9,5 +9,38 @@ module Proscenium
9
9
  def digest(value)
10
10
  Digest::SHA1.hexdigest(value.to_s)[..7]
11
11
  end
12
+
13
+ # Merges the given array of attribute `name`'s into the `kw_arguments`. A bang attribute is one
14
+ # that ends with an exclamation mark or - in Ruby parlance - a "bang", and has a boolean value.
15
+ # Modifies the given `kw_attributes`, and only attribute names in `allowed` will be merged.
16
+ #
17
+ # @param names [Array(Symbol)] of argument names
18
+ # @param kw_attributes [Hash] attributes to be merged with
19
+ # @param allowed [Array(Symbol)] attribute names allowed to be merged as bang attributes
20
+ #
21
+ # Example:
22
+ #
23
+ # def tab(name, *args, href:, **attributes)
24
+ # Hue::Utils.merge_bang_attributes!(args, attributes, [:current])
25
+ # end
26
+ #
27
+ # Allowing you to use either of the following API's:
28
+ #
29
+ # tab 'Tab 1', required: true
30
+ # tab 'Tab 1', :required!
31
+ #
32
+ def merge_bang_attributes!(names, kw_attributes, allowed)
33
+ allowed.each do |name|
34
+ sym_name = name.to_sym
35
+ bang_name = :"#{sym_name}!"
36
+
37
+ next unless names.include?(bang_name)
38
+
39
+ names.delete(bang_name)
40
+
41
+ # Keyword arguments should override the bang.
42
+ kw_attributes[sym_name] = true unless kw_attributes.key?(sym_name)
43
+ end
44
+ end
12
45
  end
13
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.18.0'
4
+ VERSION = '0.19.0'
5
5
  end
data/lib/proscenium.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/dependencies/autoload'
3
+ require 'active_support'
4
4
 
5
5
  module Proscenium
6
6
  extend ActiveSupport::Autoload
@@ -28,13 +28,11 @@ module Proscenium
28
28
  autoload :SideLoad
29
29
  autoload :CssModule
30
30
  autoload :ReactComponentable
31
- autoload :ViewComponent
32
- autoload :Phlex
33
31
  autoload :Helper
34
32
  autoload :Builder
35
33
  autoload :Importer
36
34
  autoload :Resolver
37
- autoload :UI
35
+ autoload :BundledGems
38
36
 
39
37
  class Deprecator
40
38
  def deprecation_warning(name, message, _caller_backtrace = nil)
@@ -60,14 +58,6 @@ module Proscenium
60
58
  @config ||= Railtie.config.proscenium
61
59
  end
62
60
 
63
- def cache
64
- @cache ||= config.cache || ActiveSupport::Cache::NullStore.new
65
- end
66
-
67
- def ui_path
68
- Railtie.root.join('lib', 'proscenium', 'ui')
69
- end
70
-
71
61
  def root
72
62
  Railtie.root
73
63
  end
metadata CHANGED
@@ -1,35 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proscenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-15 00:00:00.000000000 Z
11
+ date: 2025-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 7.1.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '8.0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 7.1.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '8.0'
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: ffi
35
15
  requirement: !ruby/object:Gem::Requirement
@@ -45,35 +25,7 @@ dependencies:
45
25
  - !ruby/object:Gem::Version
46
26
  version: 1.17.0
47
27
  - !ruby/object:Gem::Dependency
48
- name: literal
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.0'
61
- - !ruby/object:Gem::Dependency
62
- name: oj
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '3.13'
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '3.13'
75
- - !ruby/object:Gem::Dependency
76
- name: railties
28
+ name: rails
77
29
  requirement: !ruby/object:Gem::Requirement
78
30
  requirements:
79
31
  - - ">="
@@ -81,7 +33,7 @@ dependencies:
81
33
  version: 7.1.0
82
34
  - - "<"
83
35
  - !ruby/object:Gem::Version
84
- version: '8.0'
36
+ version: '9.0'
85
37
  type: :runtime
86
38
  prerelease: false
87
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,21 +43,7 @@ dependencies:
91
43
  version: 7.1.0
92
44
  - - "<"
93
45
  - !ruby/object:Gem::Version
94
- version: '8.0'
95
- - !ruby/object:Gem::Dependency
96
- name: ruby-next
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: 1.0.1
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: 1.0.1
46
+ version: '9.0'
109
47
  description:
110
48
  email:
111
49
  - joel@developwithstyle.com
@@ -118,57 +56,31 @@ files:
118
56
  - README.md
119
57
  - lib/proscenium.rb
120
58
  - lib/proscenium/builder.rb
121
- - lib/proscenium/core_ext/object/css_module_ivars.rb
59
+ - lib/proscenium/bundled_gems.rb
122
60
  - lib/proscenium/css_module.rb
123
61
  - lib/proscenium/css_module/path.rb
124
- - lib/proscenium/css_module/rewriter.rb
125
62
  - lib/proscenium/css_module/transformer.rb
126
63
  - lib/proscenium/ensure_loaded.rb
127
64
  - lib/proscenium/ext/proscenium
128
65
  - lib/proscenium/ext/proscenium.h
129
66
  - lib/proscenium/helper.rb
130
67
  - lib/proscenium/importer.rb
131
- - lib/proscenium/libs/custom_element.js
132
- - lib/proscenium/libs/react-manager/index.jsx
133
- - lib/proscenium/libs/react-manager/react.js
134
- - lib/proscenium/libs/stimulus-loading.js
135
- - lib/proscenium/libs/test.js
136
- - lib/proscenium/libs/ujs/class.js
137
- - lib/proscenium/libs/ujs/data_confirm.js
138
- - lib/proscenium/libs/ujs/data_disable_with.js
139
- - lib/proscenium/libs/ujs/index.js
140
68
  - lib/proscenium/log_subscriber.rb
141
69
  - lib/proscenium/middleware.rb
142
70
  - lib/proscenium/middleware/base.rb
143
- - lib/proscenium/middleware/engines.rb
144
71
  - lib/proscenium/middleware/esbuild.rb
145
- - lib/proscenium/middleware/runtime.rb
72
+ - lib/proscenium/middleware/ruby_gems.rb
146
73
  - lib/proscenium/monkey.rb
147
- - lib/proscenium/phlex.rb
148
- - lib/proscenium/phlex/asset_inclusions.rb
149
- - lib/proscenium/phlex/css_modules.rb
150
- - lib/proscenium/phlex/react_component.rb
151
74
  - lib/proscenium/railtie.rb
75
+ - lib/proscenium/react-manager/index.jsx
76
+ - lib/proscenium/react-manager/react.js
152
77
  - lib/proscenium/react_componentable.rb
153
78
  - lib/proscenium/resolver.rb
154
79
  - lib/proscenium/side_load.rb
155
80
  - lib/proscenium/source_path.rb
156
81
  - lib/proscenium/templates/rescues/build_error.html.erb
157
- - lib/proscenium/ui.rb
158
- - lib/proscenium/ui/breadcrumbs.rb
159
- - lib/proscenium/ui/breadcrumbs/component.module.css
160
- - lib/proscenium/ui/breadcrumbs/component.rb
161
- - lib/proscenium/ui/breadcrumbs/computed_element.rb
162
- - lib/proscenium/ui/breadcrumbs/control.rb
163
- - lib/proscenium/ui/breadcrumbs/mixins.css
164
- - lib/proscenium/ui/component.rb
165
- - lib/proscenium/ui/test.js
166
82
  - lib/proscenium/utils.rb
167
83
  - lib/proscenium/version.rb
168
- - lib/proscenium/view_component.rb
169
- - lib/proscenium/view_component/css_modules.rb
170
- - lib/proscenium/view_component/react_component.rb
171
- - lib/proscenium/view_component/sideload.rb
172
84
  homepage: https://github.com/joelmoss/proscenium
173
85
  licenses:
174
86
  - MIT
@@ -185,14 +97,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
97
  requirements:
186
98
  - - ">="
187
99
  - !ruby/object:Gem::Version
188
- version: 3.2.0
100
+ version: 3.3.0
189
101
  required_rubygems_version: !ruby/object:Gem::Requirement
190
102
  requirements:
191
103
  - - ">="
192
104
  - !ruby/object:Gem::Version
193
105
  version: '0'
194
106
  requirements: []
195
- rubygems_version: 3.5.21
107
+ rubygems_version: 3.5.22
196
108
  signing_key:
197
109
  specification_version: 4
198
110
  summary: The engine powering your Rails frontend
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Object
4
- def instance_variable_get(name)
5
- name.is_a?(::Proscenium::CssModule::Name) ? super(name.to_sym) : super
6
- end
7
-
8
- def instance_variable_set(name, obj)
9
- name.is_a?(::Proscenium::CssModule::Name) ? super(name.to_sym, obj) : super
10
- end
11
-
12
- def instance_variable_defined?(name)
13
- name.is_a?(::Proscenium::CssModule::Name) ? super(name.to_sym) : super
14
- end
15
-
16
- def remove_instance_variable(name)
17
- name.is_a?(::Proscenium::CssModule::Name) ? super(name.to_sym) : super
18
- end
19
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ruby-next/language'
4
- require 'proscenium/core_ext/object/css_module_ivars'
5
-
6
- module Proscenium
7
- module CssModule
8
- class Rewriter < RubyNext::Language::Rewriters::Text
9
- NAME = 'proscenium-css-module'
10
-
11
- def rewrite(source)
12
- source = source.gsub(/%i\[((@[\w@ ]+)|([\w@ ]+ @[\w@ ]+))\]/) do |_|
13
- arr = ::Regexp.last_match(1).split.map do |x|
14
- x.start_with?('@') ? css_module_string(x[1..]) : ":#{x}"
15
- end
16
- "[#{arr.join(',')}]"
17
- end
18
-
19
- source.gsub(/:@([\w]+)/) do |_|
20
- context.track!(self)
21
- css_module_string(::Regexp.last_match(1))
22
- end
23
- end
24
-
25
- private
26
-
27
- def css_module_string(name)
28
- if (path = Pathname.new(context.path).sub_ext('.module.css')).exist?
29
- tname = Transformer.new(path).class_name!(name, name.dup).first
30
- "Proscenium::CssModule::Name.new(:@#{name}, '#{tname}')"
31
- else
32
- "Proscenium::CssModule::Name.new(:@#{name}, css_module(:#{name}))"
33
- end
34
- end
35
- end
36
- end
37
- end
38
-
39
- RubyNext::Language.send :include_patterns=, []
40
- RubyNext::Language.include_patterns << "#{Rails.root.join('app', 'components')}/*.rb"
41
- RubyNext::Language.include_patterns << "#{Rails.root.join('app', 'views')}/*.rb"
42
- RubyNext::Language.rewriters = [Proscenium::CssModule::Rewriter]
43
-
44
- require 'ruby-next/language/runtime'
@@ -1,54 +0,0 @@
1
- /**
2
- * Base class for custom elements, providing support for event delegation, and idempotent
3
- * customElement registration.
4
- *
5
- * The `handleEvent` method is called any time an event defined in `delegatedEvents` is triggered.
6
- * It's a central handler to handle events for this custom element.
7
- *
8
- * @example
9
- * class MyComponent extends CustomElement {
10
- * static componentName = 'my-component'
11
- * static delegatedEvents = ['click']
12
- *
13
- * handleEvent(event) {
14
- * console.log('Hello, world!')
15
- * }
16
- * }
17
- * MyComponent.register()
18
- */
19
- export default class CustomElement extends HTMLElement {
20
- /**
21
- * Register the component as a custom element, inferring the component name from the kebab-cased
22
- * class name. You can override the component name by setting a static `componentName` property.
23
- *
24
- * This method is idempotent.
25
- */
26
- static register() {
27
- if (this.componentName === undefined) {
28
- this.componentName = this.name
29
- .replaceAll(/(.)([A-Z])/g, "$1-$2")
30
- .toLowerCase();
31
- }
32
-
33
- if (!customElements.get(this.componentName)) {
34
- customElements.define(this.componentName, this);
35
- }
36
- }
37
-
38
- /**
39
- * A list of event types to be delegated for the lifetime of the custom element.
40
- *
41
- * @type {Array}
42
- */
43
- static delegatedEvents = [];
44
-
45
- constructor() {
46
- super();
47
-
48
- if (typeof this.handleEvent !== "undefined") {
49
- this.constructor.delegatedEvents?.forEach((event) => {
50
- this.addEventListener(event, this);
51
- });
52
- }
53
- }
54
- }
@@ -1,65 +0,0 @@
1
- export function lazyLoadControllersFrom(under, app, element = document) {
2
- const { controllerAttribute } = app.schema;
3
-
4
- lazyLoadExistingControllers(element);
5
-
6
- // Lazy load new controllers.
7
- new MutationObserver((mutationsList) => {
8
- for (const { attributeName, target, type } of mutationsList) {
9
- switch (type) {
10
- case "attributes": {
11
- if (
12
- attributeName == controllerAttribute &&
13
- target.getAttribute(controllerAttribute)
14
- ) {
15
- extractControllerNamesFrom(target).forEach((controllerName) =>
16
- loadController(controllerName)
17
- );
18
- }
19
- }
20
-
21
- case "childList": {
22
- lazyLoadExistingControllers(target);
23
- }
24
- }
25
- }
26
- }).observe(element, {
27
- attributeFilter: [controllerAttribute],
28
- subtree: true,
29
- childList: true,
30
- });
31
-
32
- function lazyLoadExistingControllers(element) {
33
- Array.from(element.querySelectorAll(`[${controllerAttribute}]`))
34
- .map(extractControllerNamesFrom)
35
- .flat()
36
- .forEach(loadController);
37
- }
38
-
39
- function extractControllerNamesFrom(element) {
40
- return element
41
- .getAttribute(controllerAttribute)
42
- .split(/\s+/)
43
- .filter((content) => content.length);
44
- }
45
-
46
- function loadController(name) {
47
- if (canRegisterController(name)) {
48
- const fileToImport = `${under}/${name
49
- .replace(/--/g, "/")
50
- .replace(/-/g, "_")}_controller.js`;
51
-
52
- import(fileToImport)
53
- .then((module) => {
54
- canRegisterController(name) && app.register(name, module.default);
55
- })
56
- .catch((error) =>
57
- console.error(`Failed to autoload controller: ${name}`, error)
58
- );
59
- }
60
- }
61
-
62
- function canRegisterController(name) {
63
- return !app.router.modulesByIdentifier.has(name);
64
- }
65
- }
@@ -1 +0,0 @@
1
- console.log("/@proscenium/test.js");