isomorfeus-preact 22.9.0.rc9 → 22.10.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,6 +28,7 @@ if RUBY_ENGINE == 'opal'
28
28
  end
29
29
  else
30
30
  Isomorfeus.browser_history = Browser::History.new
31
+ require 'isomorfeus_preact_ext'
31
32
  end
32
33
 
33
34
  # allow mounting of components
@@ -49,7 +50,9 @@ require 'preact/component_resolution'
49
50
  require 'preact/module_component_resolution'
50
51
 
51
52
  # HTML Elements and Fragment support
52
- require 'preact/elements'
53
+ require 'preact/html_elements'
54
+ # require 'preact/svg_elements' # optional
55
+ # require 'preact/math_ml_elements' # optional
53
56
  # Component
54
57
  require 'preact/component'
55
58
  # Context
@@ -94,8 +97,8 @@ else
94
97
  end
95
98
 
96
99
  require 'iso_opal'
97
- Opal.append_path(__dir__.untaint) unless IsoOpal.paths.include?(__dir__.untaint)
98
- path = File.expand_path(File.join(__dir__.untaint, '..', 'opal'))
100
+ Opal.append_path(__dir__) unless IsoOpal.paths.include?(__dir__)
101
+ path = File.expand_path(File.join(__dir__, '..', 'opal'))
99
102
  Opal.append_path(path) unless IsoOpal.paths.include?(path)
100
103
 
101
104
  Isomorfeus.zeitwerk.push_dir(File.expand_path(File.join('app', 'components')))
data/lib/link.rb CHANGED
@@ -2,6 +2,8 @@ class Link < Preact::Component
2
2
  EVENT_PUSH_STATE = "pushState"
3
3
  EVENT_REPLACE_STATE = "replaceState"
4
4
 
5
+ self.context_type = RouterContext
6
+
5
7
  def initialize(props, context)
6
8
  super(props, context)
7
9
  if RUBY_ENGINE == 'opal'
@@ -49,4 +51,3 @@ class Link < Preact::Component
49
51
  Preact.clone_element(a, extra_props)
50
52
  end
51
53
  end
52
- Link.context_type = RouterContext
data/lib/lucid_app.rb CHANGED
@@ -33,7 +33,6 @@ class LucidApp < LucidComponent
33
33
  @theme_hash = theme_hash if theme_hash
34
34
  @theme_hash
35
35
  end
36
- alias_method :theme=, :theme
37
36
 
38
37
  if RUBY_ENGINE == 'opal'
39
38
  def css_theme
@@ -56,7 +55,7 @@ class LucidApp < LucidComponent
56
55
  i = NanoCSS.instance
57
56
  i.delete_from_sheet(rule_name)
58
57
  i.renderer[:hydrate_force_put] = true
59
- thread_css_theme = i.sheet(@theme_hash, rule_name)
58
+ self.thread_css_theme = i.sheet(@theme_hash, rule_name)
60
59
  end
61
60
 
62
61
  def thread_css_theme_key
@@ -114,4 +113,4 @@ class LucidApp < LucidComponent
114
113
  Isomorfeus.store.unsubscribe(@unsubscriber)
115
114
  end
116
115
  end
117
- end
116
+ end
@@ -29,14 +29,12 @@ class LucidComponent < Preact::Component
29
29
  @styles_hash = styles_hash if styles_hash
30
30
  @styles_hash
31
31
  end
32
- alias_method :styles=, :styles
33
32
 
34
33
  if RUBY_ENGINE == 'opal'
35
34
  def css_styles
36
35
  return {} unless @styles_hash
37
36
  return @css_styles if @css_styles
38
- component_name = self.to_s
39
- rule_name = component_name.gsub(':', '_')
37
+ rule_name = self.to_s.underscore
40
38
  i = NanoCSS.instance
41
39
  i.delete_from_sheet(rule_name)
42
40
  i.renderer[:hydrate_force_put] = true
@@ -47,12 +45,11 @@ class LucidComponent < Preact::Component
47
45
  return {} unless @styles_hash
48
46
  s = thread_css_styles
49
47
  return s if s
50
- component_name = self.to_s
51
- rule_name = component_name.gsub(':', '_')
48
+ rule_name = self.to_s.underscore
52
49
  i = NanoCSS.instance
53
50
  i.delete_from_sheet(rule_name)
54
51
  i.renderer[:hydrate_force_put] = true
55
- thread_css_styles = i.sheet(@styles_hash, rule_name)
52
+ self.thread_css_styles = i.sheet(@styles_hash, rule_name)
56
53
  end
57
54
 
58
55
  def thread_css_styles_key
@@ -151,4 +148,4 @@ class LucidComponent < Preact::Component
151
148
  def theme
152
149
  @context[:iso_theme]
153
150
  end
154
- end
151
+ end
data/lib/nano_css.rb CHANGED
@@ -41,11 +41,6 @@ class NanoCSS
41
41
 
42
42
  def initialize(config = nil, given_renderer: nil)
43
43
  config = {} unless config
44
- if RUBY_ENGINE == 'opal'
45
- @client = `typeof window === "object"`
46
- else
47
- @client = false
48
- end
49
44
 
50
45
  if given_renderer
51
46
  @renderer = given_renderer
@@ -56,7 +51,7 @@ class NanoCSS
56
51
 
57
52
  @hydrated = {}
58
53
 
59
- if @client
54
+ if RUBY_ENGINE == 'opal'
60
55
  unless @renderer.key?(:sh)
61
56
  e = `document.createElement('style')`
62
57
  @renderer[:sh] = e
@@ -76,10 +71,10 @@ class NanoCSS
76
71
  @@unitless_css_properties = {}
77
72
  UNITLESS_NUMBER_PROPS.each do |prop|
78
73
  @@unitless_css_properties[prop] = 1
79
- @@unitless_css_properties['-webkit-' + prop] = 1
80
- @@unitless_css_properties['-ms-' + prop] = 1
81
- @@unitless_css_properties['-moz-' + prop] = 1
82
- @@unitless_css_properties['-o-' + prop] = 1
74
+ @@unitless_css_properties["-webkit-#{prop}"] = 1
75
+ @@unitless_css_properties["-ms-#{prop}"] = 1
76
+ @@unitless_css_properties["-moz-#{prop}"] = 1
77
+ @@unitless_css_properties["-o-#{prop}"] = 1
83
78
  end
84
79
  end
85
80
 
@@ -110,7 +105,7 @@ class NanoCSS
110
105
  str.each_codepoint do |cp|
111
106
  h = (h * 33) ^ cp
112
107
  end
113
- '_' + h.abs.to_s(36)
108
+ "_#{h.abs.to_s(36)}"
114
109
  end
115
110
 
116
111
  def kebab(prop)
@@ -118,7 +113,7 @@ class NanoCSS
118
113
  end
119
114
 
120
115
  def put(css_selector, decls, atrule = nil)
121
- return if @client && !@renderer[:hydrate_force_put] && @hydrated.key?(css_selector)
116
+ return if RUBY_ENGINE == 'opal' && !@renderer[:hydrate_force_put] && @hydrated.key?(css_selector)
122
117
 
123
118
  str = ''
124
119
  postponed = []
@@ -132,8 +127,8 @@ class NanoCSS
132
127
  end
133
128
 
134
129
  unless str.empty?
135
- str = css_selector + '{' + str + '}'
136
- put_raw(atrule ? atrule + '{' + str + '}' : str)
130
+ str = "#{css_selector}{#{str}}"
131
+ put_raw(atrule ? "#{atrule}{#{str}}" : str)
137
132
  end
138
133
 
139
134
  postponed.each do |prop|
@@ -157,8 +152,8 @@ class NanoCSS
157
152
  end
158
153
 
159
154
  @renderer[:prefixes].each do |prefix|
160
- raw_key_frames = prelude.sub('@keyframes', "@#{prefix}keyframes") + "{#{str}}"
161
- if @client
155
+ raw_key_frames = "#{prelude.sub('@keyframes', "@#{prefix}keyframes")}{#{str}}"
156
+ if RUBY_ENGINE == 'opal'
162
157
  ksh = @renderer[:ksh]
163
158
  `ksh.appendChild(document.createTextNode(raw_key_frames))`
164
159
  else
@@ -171,20 +166,18 @@ class NanoCSS
171
166
  put(nil, keyframes, prelude)
172
167
  end
173
168
 
174
- def put_raw(raw_css_rule)
175
- @client ? put_raw_client(raw_css_rule) : put_raw_ssr(raw_css_rule)
176
- end
177
-
178
- def put_raw_ssr(raw_css_rule)
179
- @renderer[:raw] << raw_css_rule
180
- end
181
-
182
- def put_raw_client(raw_css_rule)
183
- # .insertRule() is faster than .appendChild(), that's why we use it in PROD.
184
- # But CSS injected using .insertRule() is not displayed in Chrome Devtools
185
- sheet = @renderer[:sh].JS[:sheet]
186
- # Unknown pseudo-selectors will throw, this try/catch swallows all errors.
187
- `sheet.insertRule(raw_css_rule, sheet.cssRules.length)` rescue nil
169
+ if RUBY_ENGINE == 'opal'
170
+ def put_raw(raw_css_rule)
171
+ # .insertRule() is faster than .appendChild(), that's why we use it in PROD.
172
+ # But CSS injected using .insertRule() is not displayed in Chrome Devtools
173
+ sheet = @renderer[:sh].JS[:sheet]
174
+ # Unknown pseudo-selectors will throw, this try/catch swallows all errors.
175
+ `sheet.insertRule(raw_css_rule, sheet.cssRules.length)` rescue nil
176
+ end
177
+ else
178
+ def put_raw(raw_css_rule)
179
+ @renderer[:raw] << raw_css_rule
180
+ end
188
181
  end
189
182
 
190
183
  # addons
@@ -193,16 +186,16 @@ class NanoCSS
193
186
 
194
187
  def rule(css, block = nil)
195
188
  block = block || hash(css)
196
- block = @renderer[:pfx] + block
197
- put('.' + block, css)
189
+ block = "#{@renderer[:pfx]}#{block}"
190
+ put(".#{block}", css)
198
191
 
199
- ' ' + block
192
+ " #{block}"
200
193
  end
201
194
 
202
195
  # sheet
203
196
 
204
197
  def delete_from_sheet(rule_name)
205
- selector_rule_name = "._" + rule_name + "-"
198
+ selector_rule_name = "._#{rule_name}-"
206
199
  if renderer[:sh] && renderer[:sh].JS[:sheet]
207
200
  sheet = renderer[:sh].JS[:sheet]
208
201
  css_rules = sheet.JS[:cssRules]
@@ -256,7 +249,7 @@ class NanoCSS
256
249
  result.push(sel)
257
250
  else
258
251
  parents.each do |parent|
259
- result.push(parent + ' ' + sel)
252
+ result.push("#{parent} #{sel}")
260
253
  end
261
254
  end
262
255
  end
@@ -1,7 +1,7 @@
1
1
  module Preact
2
2
  class Component
3
3
  extend Preact::PropDeclarationMixin
4
- include Preact::Elements
4
+ include Preact::HtmlElements
5
5
  include Preact::ComponentResolution
6
6
 
7
7
  class << self
@@ -115,16 +115,7 @@ module Preact
115
115
  attr_reader :props
116
116
  attr_reader :state
117
117
 
118
- if RUBY_ENGINE != 'opal'
119
- attr_accessor :__d
120
- attr_accessor :__s
121
- attr_accessor :__v
122
- attr_accessor :_dirty
123
- attr_accessor :_next_state
124
- end
125
-
126
118
  def initialize(props, context)
127
- @development = Isomorfeus.development?
128
119
  @self_class = self.class
129
120
 
130
121
  if RUBY_ENGINE == 'opal'
@@ -6,15 +6,20 @@ module Preact
6
6
  end
7
7
 
8
8
  class Provider < Preact::Component
9
+ class << self
10
+ attr_reader :root_context
11
+ end
12
+
9
13
  attr_reader :context_id
10
14
  attr_reader :subs
11
15
 
12
16
  def initialize(props, context)
17
+ @self_class_root = self.class.root_context
13
18
  unless props.key?(:value)
14
- props = props.merge({ value: get_default_value })
19
+ props = props.merge({ value: @self_class_root.value })
15
20
  end
16
21
  super(props, context)
17
- @context_id = get_context_id
22
+ @context_id = @self_class_root.context_id
18
23
  @child_context = { @context_id => self }
19
24
  @getChildContext = true
20
25
  @subs = []
@@ -51,18 +56,7 @@ module Preact
51
56
  @Provider = Class.new(Provider)
52
57
  @value = default_value
53
58
  @context_id = Preact._context_id
54
- ctx = self
55
- @Provider.define_method(:get_default_value) do
56
- ctx.value
57
- end
58
- @Provider.define_method(:get_context_id) do
59
- ctx.context_id
60
- end
61
- end
62
-
63
- def Consumer(&block)
64
- block_result = block.call(@value)
65
- Preact.render_buffer.last.push(block_result) if block_result
59
+ @Provider.instance_variable_set(:@root_context, self)
66
60
  end
67
61
  end
68
62
  end
@@ -0,0 +1,58 @@
1
+ module Preact::HtmlElements
2
+ # https://html.spec.whatwg.org/multipage/indices.html#elements-3
3
+ SUPPORTED_HTML_ELEMENTS = %w[
4
+ a abbr address area article aside audio
5
+ b base bdi bdo blockquote body br button
6
+ canvas caption cite code col colgroup
7
+ data datalist dd del details dfn dialog div dl dt
8
+ em embed
9
+ fieldset figcaption figure footer form
10
+ h1 h2 h3 h4 h5 h6 head header hgroup hr html
11
+ i iframe img input ins
12
+ kbd
13
+ label legend li link
14
+ main map mark math menu meta meter
15
+ nav noscript
16
+ object ol optgroup option output
17
+ p picture pre progress
18
+ q
19
+ rp rt ruby
20
+ s samp script section select slot small source span strong style sub summary sup svg
21
+ table tbody td template textarea tfoot th thead time title tr track
22
+ u ul
23
+ var video
24
+ wbr
25
+ ]
26
+
27
+ if RUBY_ENGINE == 'opal'
28
+ SUPPORTED_HTML_ELEMENTS.each do |element|
29
+ define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
30
+ %x{
31
+ const op = Opal.Preact;
32
+ const opr = op.render_buffer;
33
+ if (typeof block === 'function') op.$create_element.$$p = block.$to_proc();
34
+ opr[opr.length-1].push(op.$create_element(element, props, nil));
35
+ }
36
+ end
37
+ end
38
+ else
39
+ SUPPORTED_HTML_ELEMENTS.each do |element|
40
+ define_method(element.to_s.underscore.upcase.to_sym) do |props = nil, &block|
41
+ Preact._render_element(element, props, &block)
42
+ end
43
+ end
44
+ end
45
+
46
+ def GPE(arg, &block)
47
+ if block_given?
48
+ el = block.call
49
+ return el if el
50
+ end
51
+ Preact.render_buffer.last.pop
52
+ end
53
+
54
+ def RPE(el)
55
+ Preact.render_buffer.last.push(el)
56
+ nil
57
+ end
58
+ end
@@ -0,0 +1,53 @@
1
+ module Preact::MathMlElements
2
+ # https://www.w3.org/TR/MathML3/appendixi.html#index.elem
3
+ SUPPORTED_MATH_ML_ELEMENTS = %w[
4
+ abs and annotation apply approx arccos arccosh arccot arccoth arccsc arccsch
5
+ arcsec arcsech arcsin arcsinh arctan arctanh arg
6
+ bind bvar
7
+ card cartesianproduct cbytes ceiling cerror ci cn codomain complexes compose
8
+ condition conjugate cos cosh cot coth cs csc csch csymbol curl
9
+ declare degree determinant diff divergence divide domain domainofapplication
10
+ emptyset eq equivalent eulergamma exists exp exponentiale
11
+ factorial factorof false floor fn forall
12
+ gcd geq grad gt
13
+ ident image imaginary imaginaryi implies in infinity int integers intersect
14
+ interval inverse lambda laplacian lcm leq limit list ln log logbase
15
+ lowlimit lt
16
+ maction maligngroup malignmark matrix matrixrow max mean median
17
+ menclose merror mfenced mfrac mglyph mi min minus mlabeledtr mlongdiv
18
+ mmultiscripts mn mo mode moment momentabout mover mpadded mphantom
19
+ mprescripts mroot mrow ms mscarries mscarry msgroup msline mspace msqrt
20
+ msrow mstack mstyle msub msubsup msup mtable mtd mtext mtr munder
21
+ munderover
22
+ naturalnumbers neq none not notanumber notin notprsubset notsubset
23
+ or otherwise outerproduct
24
+ partialdiff pi piece piecewise plus power primes product prsubset
25
+ quotient
26
+ rationals real reals reln rem root
27
+ scalarproduct sdev sec sech selector semantics sep set setdiff share sin
28
+ sinh subset sum
29
+ tan tanh tendsto times transpose true
30
+ union uplimit
31
+ variance vector vectorproduct
32
+ xor
33
+ ]
34
+
35
+ if RUBY_ENGINE == 'opal'
36
+ SUPPORTED_MATH_ML_ELEMENTS.each do |element|
37
+ define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
38
+ %x{
39
+ const op = Opal.Preact;
40
+ const opr = op.render_buffer;
41
+ if (typeof block === 'function') op.$create_element.$$p = block.$to_proc();
42
+ opr[opr.length-1].push(op.$create_element(element, props, nil));
43
+ }
44
+ end
45
+ end
46
+ else
47
+ SUPPORTED_MATH_ML_ELEMENTS.each do |element|
48
+ define_method(element.to_s.underscore.upcase.to_sym) do |props = nil, &block|
49
+ Preact._render_element(element, props, &block)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,34 +1,33 @@
1
- module Preact::Elements
2
- # https://www.w3.org/TR/html52/fullindex.html#index-elements
3
- # https://www.w3.org/TR/SVG11/eltindex.html
4
- SUPPORTED_HTML_AND_SVG_ELEMENTS = %w[
1
+ module Preact::SvgElements
2
+ # https://www.w3.org/TR/SVG11/eltindex.html + https://www.w3.org/TR/SVG2/eltindex.htm
3
+ SUPPORTED_SVG_ELEMENTS = %w[
5
4
  a abbr address area article aside audio
6
5
  b base bdi bdo blockquote body br button
7
6
  canvas caption cite code col colgroup
8
7
  data datalist dd del details dfn dialog div dl dt
9
8
  em embed
10
9
  fieldset figcaption figure footer form
11
- h1 h2 h3 h4 h5 h6 head header hr html
10
+ h1 h2 h3 h4 h5 h6 head header hgroup hr html
12
11
  i iframe img input ins
13
12
  kbd
14
13
  label legend li link
15
- main map mark meta meter
14
+ main map mark math menu meta meter
16
15
  nav noscript
17
16
  object ol optgroup option output
18
- p param picture pre progress
17
+ p picture pre progress
19
18
  q
20
- rp rt rtc ruby
21
- s samp script section select small source span strong style sub summary sup
19
+ rp rt ruby
20
+ s samp script section select slot small source span strong style sub summary sup svg
22
21
  table tbody td template textarea tfoot th thead time title tr track
23
22
  u ul
24
23
  var video
25
24
  wbr
26
- altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform
25
+ altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform audio
27
26
  circle clipPath color-profile cursor
28
- defs desc
27
+ defs desc discard
29
28
  ellipse
30
29
  feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting
31
- feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
30
+ feDisplacementMap feDistantLight feDropShadow feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
32
31
  feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting
33
32
  feSpotLight feTile feTurbulence
34
33
  filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject
@@ -39,15 +38,15 @@ module Preact::Elements
39
38
  marker mask metadata missing-glyph mpath
40
39
  path pattern polygon polyline
41
40
  radialGradient rect
42
- script set stop style svg switch symbol
43
- text textPath tref tspan
44
- use
41
+ set stop switch symbol
42
+ text textPath tspan
43
+ unknown use
45
44
  view vkern
46
45
  ]
47
46
 
48
47
  if RUBY_ENGINE == 'opal'
49
- SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
50
- define_method(element.underscore.upcase) do |props = nil, &block|
48
+ SUPPORTED_SVG_ELEMENTS.each do |element|
49
+ define_method(element.underscore.JS.toUpperCase()) do |props = nil, &block|
51
50
  %x{
52
51
  const op = Opal.Preact;
53
52
  const opr = op.render_buffer;
@@ -57,23 +56,10 @@ module Preact::Elements
57
56
  end
58
57
  end
59
58
  else
60
- SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
59
+ SUPPORTED_SVG_ELEMENTS.each do |element|
61
60
  define_method(element.to_s.underscore.upcase.to_sym) do |props = nil, &block|
62
61
  Preact._render_element(element, props, &block)
63
62
  end
64
63
  end
65
64
  end
66
-
67
- def GPE(arg, &block)
68
- if block_given?
69
- el = block.call
70
- return el if el
71
- end
72
- Preact.render_buffer.last.pop
73
- end
74
-
75
- def RPE(el)
76
- Preact.render_buffer.last.push(el)
77
- nil
78
- end
79
65
  end