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.
data/lib/preact.rb CHANGED
@@ -3,32 +3,6 @@ if RUBY_ENGINE == 'opal'
3
3
  # just a empty place holder to make is_a?(VNode) work
4
4
  # internally using the js implementation
5
5
  end
6
- else
7
- class VNode
8
- # full ruby implementation
9
- attr_accessor :__c
10
- attr_reader :_children
11
- attr_reader :_component
12
- attr_reader :_depth
13
- attr_reader :_dom
14
- attr_reader :_hydrating
15
- attr_reader :_nextDom
16
- attr_reader :_original
17
- attr_reader :constructor
18
- attr_reader :key
19
- attr_reader :props
20
- attr_reader :ref
21
- attr_reader :type
22
-
23
- def initialize(type, props, key, ref, original)
24
- @type = type
25
- @props = props
26
- @key = key
27
- @ref = ref
28
- @_depth = 0
29
- @_original = original.nil? ? Preact._vnode_id += 1 : original
30
- end
31
- end
32
6
  end
33
7
 
34
8
  class Fragment
@@ -496,11 +470,11 @@ module Preact
496
470
  dom.style.cssText = oldValue = '';
497
471
  }
498
472
 
499
- if (value && value !== nil && value["$is_a?"](Opal.Hash)) {
473
+ if (value && value !== nil && value.$$is_hash) {
500
474
  value = value.$to_n();
501
475
  }
502
476
 
503
- if (oldValue && oldValue !== nil && oldValue["$is_a?"](Opal.Hash)) {
477
+ if (oldValue && oldValue !== nil && oldValue.$$is_hash) {
504
478
  oldValue = oldValue.$to_n();
505
479
  }
506
480
 
@@ -1033,7 +1007,8 @@ module Preact
1033
1007
  return true;
1034
1008
  },
1035
1009
  "$eql?": eql,
1036
- "$nil?": is_nil
1010
+ "$nil?": is_nil,
1011
+ "$$is_vnode": true
1037
1012
  };
1038
1013
 
1039
1014
  return vnode;
@@ -1142,11 +1117,9 @@ module Preact
1142
1117
  self.process._rerenderCount = 0;
1143
1118
  }
1144
1119
  else
1145
- IGNORED_PROPS = %i[key ref __self __source].freeze
1146
1120
  IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i
1147
1121
  JS_TO_CSS = {}
1148
1122
  ENCODED_ENTITIES = /[&<>"]/
1149
- VOID_ELEMENTS = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/
1150
1123
  end
1151
1124
 
1152
1125
  class << self
@@ -1184,7 +1157,7 @@ module Preact
1184
1157
  if RUBY_ENGINE == 'opal'
1185
1158
  `self.createVNode(vnode.type, normalized_props, #{key || `vnode.key`}, #{ref || `vnode.ref`}, null)`
1186
1159
  else
1187
- _create_vnode(vnode.type, normalized_props, key || vnode.key, ref || vnode.ref, nil)
1160
+ VNode.new(vnode.type, normalized_props, key || vnode.key, ref || vnode.ref)
1188
1161
  end
1189
1162
  end
1190
1163
 
@@ -1199,20 +1172,20 @@ module Preact
1199
1172
  Isomorfeus.reset_something_loading
1200
1173
  end
1201
1174
 
1202
- def is_renderable?(block_result)
1203
- block_result &&
1204
- (block_result.is_a?(VNode) || block_result.is_a?(String) || block_result.is_a?(Numeric) ||
1205
- (block_result.is_a?(Array) && block_result.length > 0 && is_renderable?(block_result[0])))
1206
- end
1207
-
1208
1175
  if RUBY_ENGINE == 'opal'
1209
1176
  attr_accessor :_vnode_id
1210
1177
  attr_accessor :render_buffer
1211
1178
  attr_accessor :rerender_queue
1212
1179
 
1213
- def create_element(type, props = nil, children = nil, &block)
1180
+ def is_renderable?(block_result)
1181
+ block_result &&
1182
+ (block_result.JS['$$is_vnode'] || block_result.JS['$$is_string'] || block_result.is_a?(Numeric) ||
1183
+ (block_result.JS['$$is_array'] && `block_result.length > 0` && is_renderable?(block_result[0])))
1184
+ end
1185
+
1186
+ def create_element(type, props = nil, children = nil)
1214
1187
  if props
1215
- if props.is_a?(Hash)
1188
+ if props.JS['$$is_hash']
1216
1189
  normalized_props = props.dup
1217
1190
  key = normalized_props.delete(:key)
1218
1191
  ref = normalized_props.delete(:ref)
@@ -1229,17 +1202,18 @@ module Preact
1229
1202
  end
1230
1203
 
1231
1204
  if block_given?
1232
- pr = render_buffer
1205
+ pr = `self.render_buffer`
1233
1206
  pr.JS.push([])
1234
- block_result = block.call
1235
- children = pr.JS.pop()
1236
- if Preact.is_renderable?(block_result)
1237
- children.JS.push(block_result)
1238
- end
1207
+ block_result = yield
1208
+ c = pr.JS.pop()
1209
+ %x{
1210
+ if (self["$is_renderable?"](block_result)) { c.push(block_result); }
1211
+ if (c.length > 0) { children = c; }
1212
+ }
1239
1213
  end
1240
1214
 
1241
1215
  %x{
1242
- if (children !== nil && children !== null) { #{normalized_props[:children] = children} }
1216
+ if (children !== nil && children !== null) { normalized_props["$[]="]("children", children); }
1243
1217
  return self.createVNode(type, normalized_props, key, ref, null);
1244
1218
  }
1245
1219
  end
@@ -1253,7 +1227,7 @@ module Preact
1253
1227
  def _render_element(component, props, &block)
1254
1228
  %x{
1255
1229
  let opr = Opal.Preact.render_buffer;
1256
- opr[opr.length-1].push(#{self.create_element(component, props, nil, &block)});
1230
+ opr[opr.length-1].push(#{create_element(component, props, nil, &block)});
1257
1231
  }
1258
1232
  nil
1259
1233
  end
@@ -1290,14 +1264,6 @@ module Preact
1290
1264
  `self.render(null, element_or_query)`
1291
1265
  end
1292
1266
  else # RUBY_ENGINE
1293
- def _vnode_id
1294
- Thread.current[:@_isomorfeus_preact_vnode_id] ||= 0
1295
- end
1296
-
1297
- def _vnode_id=(i)
1298
- Thread.current[:@_isomorfeus_preact_vnode_id] = i
1299
- end
1300
-
1301
1267
  def render_buffer
1302
1268
  Thread.current[:@_isomorfeus_preact_render_buffer]
1303
1269
  end
@@ -1314,46 +1280,15 @@ module Preact
1314
1280
  Thread.current[:@_isomorfeus_preact_rerender_queue] = i
1315
1281
  end
1316
1282
 
1317
- def _create_vnode(type, props, key, ref, original)
1318
- VNode.new(type, props, key, ref, original)
1319
- end
1320
-
1321
- def create_element(type, props = nil, children = nil, &block)
1322
- if props
1323
- if props.is_a?(Hash)
1324
- normalized_props = props.dup
1325
- key = normalized_props.delete(:key)
1326
- ref = normalized_props.delete(:ref)
1327
- else
1328
- children = props
1329
- normalized_props = {}
1330
- key = nil
1331
- ref = nil
1332
- end
1333
- else
1334
- normalized_props = {}
1335
- key = nil
1336
- ref = nil
1337
- end
1338
-
1339
- if block_given?
1340
- pr = render_buffer
1341
- pr.push([])
1342
- block_result = block.call
1343
- children = pr.pop
1344
- if Preact.is_renderable?(block_result)
1345
- children.push(block_result)
1346
- end
1347
- end
1348
-
1349
- normalized_props[:children] = children unless children.nil?
1350
- _create_vnode(type, normalized_props, key, ref, nil)
1283
+ def is_renderable?(block_result)
1284
+ block_result &&
1285
+ (block_result.is_a?(VNode) || block_result.is_a?(String) || block_result.is_a?(Numeric) ||
1286
+ (block_result.is_a?(Array) && block_result.length > 0 && is_renderable?(block_result[0])))
1351
1287
  end
1352
1288
 
1353
1289
  def _encode_entities(input)
1354
1290
  s = input.to_s
1355
1291
  return s unless ENCODED_ENTITIES.match?(s)
1356
- s.gsub(/&/, '&amp;').gsub(/</, '&lt;').gsub(/>/, '&gt;').gsub(/"/, '&quot;')
1357
1292
  # TODO performance maybe, maybe similar to new js way, need to measure
1358
1293
  # for (; i<str.length; i++) {
1359
1294
  # switch (str.charCodeAt(i)) {
@@ -1367,15 +1302,7 @@ module Preact
1367
1302
  # out += ch;
1368
1303
  # start = i + 1;
1369
1304
  # }
1370
- end
1371
-
1372
- def _get_children(accumulator, children)
1373
- if children.is_a?(Array)
1374
- children.reduce(accumulator) { |accumulator, child| _get_children(accumulator, child) }
1375
- elsif children != nil && children != false
1376
- accumulator.push(children)
1377
- end
1378
- accumulator
1305
+ s.gsub(/&/, '&amp;').gsub(/</, '&lt;').gsub(/>/, '&gt;').gsub(/"/, '&quot;')
1379
1306
  end
1380
1307
 
1381
1308
  def _style_obj_to_css(v)
@@ -1400,218 +1327,15 @@ module Preact
1400
1327
  nil
1401
1328
  end
1402
1329
 
1403
- def _render_to_string(vnode, context, opts, inner = nil, is_svg_mode = false, select_value = nil)
1404
- return '' if !vnode || vnode == true
1405
-
1406
- if vnode.is_a?(String) # text nodes
1407
- return _encode_entities(vnode)
1408
- elsif vnode.is_a?(Numeric) # numeric nodes
1409
- return vnode.to_s
1410
- end
1411
-
1412
- if vnode.is_a?(Array) # array of nodes
1413
- rendered = ''
1414
- vnode.each_index do |i|
1415
- rendered << _render_to_string(vnode[i], context, opts, inner, is_svg_mode, select_value)
1416
- end
1417
- return rendered
1418
- end
1419
-
1420
- node_name = vnode.type
1421
- props = vnode.props
1422
- is_component = false
1423
- is_fragment = false
1424
-
1425
- # components
1426
- if !node_name.is_a?(String) && (node_name.ancestors.include?(Preact::Component) || is_fragment = node_name.ancestors.include?(Fragment))
1427
- is_component = true
1428
- if opts && opts[:shallow] && (inner || opts[:render_root_component] == false)
1429
- node_name = node_name.class.to_s
1430
- elsif is_fragment
1431
- children = []
1432
- _get_children(children, vnode.props[:children])
1433
- return _render_to_string(children, context, opts, opts&.fetch(:shallow_high_order) != false, is_svg_mode, select_value)
1434
- else
1435
- rendered = nil
1436
-
1437
- vnode.__c = {
1438
- __v: vnode,
1439
- context: context,
1440
- props: vnode.props,
1441
- __d: true
1442
- }
1443
-
1444
- c = vnode.__c
1445
- # silently drop state updates
1446
- mark_as_dirty = proc { c[:__d] = true }
1447
- c[:set_state] = mark_as_dirty,
1448
- c[:force_update] = mark_as_dirty,
1449
-
1450
- # class-based components
1451
- cx_type = node_name.context_type
1452
- provider = cx_type && context[cx_type.context_id]
1453
- cctx = cx_type ? (provider ? provider.props[:value] : cx_type.value) : context
1454
-
1455
- # validate props
1456
- declared_props = node_name.instance_variable_get(:@declared_props)
1457
- if declared_props
1458
- declared_props.each do |prop, value|
1459
- props[prop] = value[:default] if value.key?(:default) && !props.key?(prop)
1460
- end
1461
- node_name.validate_props(props) if Isomorfeus.development?
1462
- end
1463
-
1464
- c = vnode.__c = node_name.new(props, cctx)
1465
- c.__v = vnode
1466
- # turn off stateful re-rendering:
1467
- c._dirty = c.__d = true
1468
- c.instance_variable_set(:@props, props) if c.props.nil?
1469
- c.instance_variable_set(:@state, {}) if c.state.nil?
1470
-
1471
- c._next_state = c.__s = c.state if c._next_state == nil && c.__s == nil
1472
-
1473
- c.instance_variable_set(:@context, cctx)
1474
-
1475
- if c.respond_to?(:get_derived_state_from_props)
1476
- c.instance_variable_set(:@state, {}.merge!(c.state, c.get_derived_state_from_props(c.props, c.state)))
1477
- end
1478
-
1479
- rendered = c.render
1480
-
1481
- context = {}.merge!(context, c.get_child_context) if c.respond_to?(:get_child_context)
1482
-
1483
- return _render_to_string(rendered, context, opts, opts&.fetch(:shallow_high_order) != false, is_svg_mode, select_value)
1484
- end
1485
- end
1486
-
1487
- # render JSX to HTML
1488
- node_name_s = node_name.to_s
1489
- s = "<#{node_name_s}"
1490
- prop_children = nil
1491
- html = nil
1492
-
1493
- if props
1494
- attrs = props.keys
1495
-
1496
- # allow sorting lexicographically for more determinism (useful for tests, such as via preact-jsx-chai)
1497
- attrs.sort! if opts && opts[:sort_attributes] == true
1498
-
1499
- attrs.each do |name|
1500
- v = props[name]
1501
- if name == :children
1502
- prop_children = v
1503
- next
1504
- end
1505
-
1506
- next if UNSAFE_NAME.match?(name.to_s)
1507
- next if !(opts && opts[:all_attributes]) && IGNORED_PROPS.include?(name)
1508
-
1509
- if name == :default_value
1510
- name = :value
1511
- elsif name == :class_name
1512
- next if props[:class] != nil
1513
- name = :class
1514
- elsif is_svg_mode && name.to_s.match?(/^xlink:?./)
1515
- name = name.to_s.downcase.gsub(/^xlink:?/, 'xlink:')
1516
- end
1517
-
1518
- if name == :html_for
1519
- next if props.key?(:for)
1520
- name = :for
1521
- end
1522
-
1523
- v = _style_obj_to_css(v) if name == :style && v && v.is_a?(Hash)
1524
-
1525
- # always use string values instead of booleans for aria attributes
1526
- # also see https://github.com/preactjs/preact/pull/2347/files
1527
- v = v.to_s if name.to_s.start_with?('aria') && (v == true || v == false)
1528
-
1529
- if name == :dangerouslySetInnerHTML
1530
- html = v && v[:__html]
1531
- elsif node_name == :textarea && name == :value
1532
- # <textarea value="a&b"> --> <textarea>a&amp;b</textarea>
1533
- prop_children = v
1534
- elsif name.to_s.start_with?('on_')
1535
- next
1536
- elsif v || v == 0 || v == '' && !v.is_a?(Proc)
1537
- if v == true || v == ''
1538
- v = name
1539
- # in non-xml mode, allow boolean attributes
1540
- if !opts || !opts[:xml]
1541
- s << " #{name}"
1542
- next
1543
- end
1544
- end
1545
-
1546
- if name == :value
1547
- if node_name == :select
1548
- select_value = v
1549
- next
1550
- elsif (
1551
- # If we're looking at an <option> and it's the currently selected one
1552
- node_name == :option &&
1553
- select_value == v &&
1554
- # and the <option> doesn't already have a selected attribute on it
1555
- props[:selected] == nil
1556
- )
1557
- s << ' selected'
1558
- end
1559
- end
1560
- s << " #{name}=\"#{_encode_entities(v)}\""
1561
- end
1562
- end
1563
- end
1564
-
1565
- s << '>'
1566
-
1567
- raise "#{node_name_s} is not a valid HTML tag name in #{s}" if (UNSAFE_NAME.match?(node_name_s))
1568
-
1569
- is_void = VOID_ELEMENTS.match?(node_name_s)
1570
- pieces = []
1571
-
1572
- if html
1573
- s << html
1574
- elsif prop_children
1575
- children = []
1576
- if _get_children(children, prop_children).size > 0
1577
- last_was_text = false
1578
-
1579
- children.each do |child|
1580
- if child != nil && child != false
1581
- child_svg_mode = node_name == :svg ? true : ((node_name == :foreignObject) ? false : is_svg_mode)
1582
- ret = _render_to_string(child, context, opts, true, child_svg_mode, select_value)
1583
-
1584
- # Skip if we received an empty string
1585
- if ret
1586
- pieces.push(ret)
1587
- end
1588
- end
1589
- end
1590
- end
1591
- end
1592
-
1593
- if (pieces.length > 0) || html
1594
- s << pieces.join('')
1595
- elsif opts && opts[:xml]
1596
- return s.chop! << ' />'
1597
- end
1598
-
1599
- if is_void && !children && !html
1600
- s = s.sub(/>$/, ' />')
1601
- else
1602
- s << "</#{node_name}>"
1603
- end
1604
-
1605
- return s
1606
- end
1607
-
1608
- def render_to_string(vnode, context = nil, opts = nil)
1330
+ def render_to_string(vnode, context = nil)
1609
1331
  _init_render
1610
1332
  context = {} unless context
1611
- _render_to_string(vnode, context, opts)
1333
+ _render_to_string(vnode, context, false, nil)
1612
1334
  end
1613
1335
  end # RUBY_ENGINE
1614
1336
  end
1615
1337
  end
1616
1338
 
1617
- Preact._vnode_id = 0
1339
+ if RUBY_ENGINE == 'opal'
1340
+ Preact._vnode_id = 0
1341
+ end
data/lib/redirect.rb CHANGED
@@ -2,6 +2,8 @@ class Redirect < 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'
@@ -31,4 +33,3 @@ class Redirect < Preact::Component
31
33
  nil
32
34
  end
33
35
  end
34
- Redirect.context_type = RouterContext
data/lib/route.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  class Route < Preact::Component
2
+
3
+ self.context_type = RouterContext
4
+
2
5
  render do
3
6
  route_match = @context[:router][:matcher].call(props[:path], @context[:location])
4
7
  matches, params = props[:match] || route_match
@@ -14,4 +17,3 @@ class Route < Preact::Component
14
17
  end
15
18
  end
16
19
  end
17
- Route.context_type = RouterContext
data/lib/switch.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  class Switch < Preact::Component
2
+
3
+ self.context_type = RouterContext
4
+
2
5
  def initialize(props, context)
3
6
  super(props, context)
4
7
  if RUBY_ENGINE == 'opal'
@@ -76,4 +79,3 @@ class Switch < Preact::Component
76
79
  child
77
80
  end
78
81
  end
79
- Switch.context_type = RouterContext
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-preact
3
3
  version: !ruby/object:Gem::Version
4
- version: 22.9.0.rc9
4
+ version: 22.10.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 22.9.0.rc9
61
+ version: 22.10.0.rc1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 22.9.0.rc9
68
+ version: 22.10.0.rc1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: isomorfeus-redux
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 22.9.0.rc9
75
+ version: 22.10.0.rc1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 22.9.0.rc9
82
+ version: 22.10.0.rc1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: isomorfeus-puppetmaster
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake-compiler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -126,11 +140,18 @@ description: Write Preact Components in Ruby, including styles and reactive data
126
140
  email:
127
141
  - jan@kursator.com
128
142
  executables: []
129
- extensions: []
143
+ extensions:
144
+ - ext/isomorfeus_preact_ext/extconf.rb
130
145
  extra_rdoc_files: []
131
146
  files:
132
147
  - LICENSE
133
148
  - README.md
149
+ - ext/isomorfeus_preact_ext/extconf.rb
150
+ - ext/isomorfeus_preact_ext/fio-stl.h
151
+ - ext/isomorfeus_preact_ext/isomorfeus_preact_ext.c
152
+ - ext/isomorfeus_preact_ext/isomorfeus_preact_ext.h
153
+ - ext/isomorfeus_preact_ext/preact.c
154
+ - ext/isomorfeus_preact_ext/vnode.c
134
155
  - lib/browser/delegate_native.rb
135
156
  - lib/browser/document.rb
136
157
  - lib/browser/element.rb
@@ -163,9 +184,11 @@ files:
163
184
  - lib/preact/component.rb
164
185
  - lib/preact/component_resolution.rb
165
186
  - lib/preact/context.rb
166
- - lib/preact/elements.rb
187
+ - lib/preact/html_elements.rb
188
+ - lib/preact/math_ml_elements.rb
167
189
  - lib/preact/module_component_resolution.rb
168
190
  - lib/preact/prop_declaration_mixin.rb
191
+ - lib/preact/svg_elements.rb
169
192
  - lib/redirect.rb
170
193
  - lib/route.rb
171
194
  - lib/router.rb
@@ -187,14 +210,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
210
  requirements:
188
211
  - - ">="
189
212
  - !ruby/object:Gem::Version
190
- version: '0'
213
+ version: 3.0.0
191
214
  required_rubygems_version: !ruby/object:Gem::Requirement
192
215
  requirements:
193
216
  - - ">"
194
217
  - !ruby/object:Gem::Version
195
218
  version: 1.3.1
196
219
  requirements: []
197
- rubygems_version: 3.3.7
220
+ rubygems_version: 3.4.0.dev
198
221
  signing_key:
199
222
  specification_version: 4
200
223
  summary: Preact Components for Isomorfeus.