isomorfeus-preact 23.9.0.rc2 → 23.9.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b75453247bc0c884571e884c674717562fe5e27fadf2f1f27f5f62965e37580
4
- data.tar.gz: 6eaddb4ca8921da6d124b1eb983663fd8de05b3d25ad31c9975b35d77468cc6d
3
+ metadata.gz: b99c3271315df3f744c24558a5df45ad2f5386235ed91a6466c59ee8371ae948
4
+ data.tar.gz: 4e3c3ccf9dccfe9591bc3a3df4bd8c9a710f69c438939b9a241bf213fc008034
5
5
  SHA512:
6
- metadata.gz: 37662cbea0b4b59cd9ec04c632cb2ea2bf9e96fa2ffab3f6a40f9d7632be83b72d60189b8da2c60ba70af41c4f7de435a7410a40c66887699ab1ad9d6419c57d
7
- data.tar.gz: 4300537585ebb569255dddc9a34ea47ddc19d682ae0e1f995cf30f9b7cebe7a063512f9689a634bd9a9a113d80083bb684a0262db5c4d05d1aa18e008e1f90dd
6
+ metadata.gz: 8bf76f033520d26864e46bccc148ffd634dd28f816aecf6165bddbf443eb68cbcae41a4e05baeda7e2fc5c49ff35545d72997a43ac5175543e849ebe749dbe7c
7
+ data.tar.gz: 328e0c9f13fecd1c54bf0fe50d97603269be718d83d2bad098dd33182e36ea3b00259ac2fe9d79726bcb5ec58a6428f1294e4f6049243f485458db0e374f8286
@@ -223,11 +223,6 @@ void internal_render_to_string(VALUE vnode, VALUE context, VALUE is_svg_mode,
223
223
  return;
224
224
  rb_str_buf_append(rres, rb_funcall(self, id_encode_entities, 1, vnode));
225
225
  return;
226
- case T_BIGNUM:
227
- case T_FIXNUM:
228
- case T_FLOAT:
229
- rb_str_buf_append(rres, rb_funcall(vnode, id_to_s, 0));
230
- return;
231
226
  case T_ARRAY:
232
227
  len = RARRAY_LEN(vnode);
233
228
  for (i = 0; i < len; i++) {
@@ -0,0 +1,7 @@
1
+ # backtick_javascript: true
2
+
3
+ module Browser
4
+ class ArrayBuffer < `ArrayBuffer`
5
+ include Delegate
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # backtick_javascript: true
2
+
3
+ module Browser
4
+ class Blob < `Blob`
5
+ include Delegate
6
+ end
7
+ end
@@ -1,43 +1,28 @@
1
1
  # backtick_javascript: true
2
2
 
3
3
  module Browser
4
- module DelegateNative
5
- # Provides a default initializer. This should be overridden in all but the
6
- # simplest cases.
7
- def initialize native
8
- @native = native
9
- end
10
-
4
+ module Delegate
11
5
  def [](property)
12
6
  method_missing(property)
13
7
  end
14
8
 
15
- # Fall back to native properties. If the message sent to this element is not
16
- # recognized, it checks to see if it is a property of the native element. It
17
- # also checks for variations of the message name, such as:
18
- #
19
- # :supported? => [:supported, :isSupported]
20
- #
21
- # If a property with the specified message name is found and it is a
22
- # function, that function is invoked with `args`. Otherwise, the property
23
- # is returned as is.
24
9
  def method_missing message, *args, &block
25
10
  if message.end_with? '='
26
11
  message = message.chop
27
12
  property_name = property_for_message(message)
28
13
  arg = args[0]
29
14
  arg = arg.to_n if `arg && typeof arg.$to_n === 'function'`
30
- return `#@native[#{property_name}] = arg`
15
+ return `self[#{property_name}] = arg`
31
16
  else
32
17
  property_name = property_for_message(message)
33
18
  %x{
34
- let value = #@native[#{property_name}];
19
+ let value = self[#{property_name}];
35
20
  let type = typeof(value);
36
21
  if (type === 'undefined') { return #{super}; }
37
22
  try {
38
23
  if (type === 'function') {
39
24
  #{args.map! { |arg| `arg && typeof arg.$to_n === 'function'` ? arg.to_n : arg }}
40
- value = value.apply(#@native, args);
25
+ value = value.apply(self, args);
41
26
  }
42
27
  if (value instanceof HTMLCollection || value instanceof NodeList) {
43
28
  let a = [];
@@ -49,10 +34,6 @@ module Browser
49
34
  value = #{Browser::Element.new(`value`)};
50
35
  } else if (value instanceof Event) {
51
36
  value = #{Browser::Event.new(`value`)};
52
- } else if (value instanceof FileList) {
53
- value = #{Browser::FileList.new(`value`)};
54
- } else if (value instanceof File) {
55
- value = #{Browser::File.new(`value`)};
56
37
  } else if (value instanceof FileReader) {
57
38
  value = #{Browser::FileReader.new(`value`)}
58
39
  } else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
@@ -67,28 +48,24 @@ module Browser
67
48
  def respond_to_missing? message, include_all
68
49
  message = message.chop if message.end_with? '='
69
50
  property_name = property_for_message(message)
70
- return true if `#{property_name} in #@native`
51
+ return true if `#{property_name} in self`
71
52
  false
72
53
  end
73
54
 
74
55
  def property_for_message(message)
75
56
  %x{
76
57
  let camel_cased_message;
77
- if (typeof(#@native[message]) !== 'undefined') { camel_cased_message = message; }
58
+ if (typeof(self[message]) !== 'undefined') { camel_cased_message = message; }
78
59
  else { camel_cased_message = #{message.camelize(:lower)} }
79
60
 
80
61
  if (camel_cased_message.endsWith('?')) {
81
62
  camel_cased_message = camel_cased_message.substring(0, camel_cased_message.length - 2);
82
- if (typeof(#@native[camel_cased_message]) === 'undefined') {
63
+ if (typeof(self[camel_cased_message]) === 'undefined') {
83
64
  camel_cased_message = 'is' + camel_cased_message[0].toUpperCase() + camel_cased_message.substring(0, camel_cased_message.length - 1);
84
65
  }
85
66
  }
86
67
  return camel_cased_message
87
68
  }
88
69
  end
89
-
90
- def to_n
91
- @native
92
- end
93
70
  end
94
71
  end
@@ -49,10 +49,6 @@ module Browser
49
49
  value = #{Browser::Element.new(`value`)};
50
50
  } else if (value instanceof Event) {
51
51
  value = #{Browser::Event.new(`value`)};
52
- } else if (value instanceof FileList) {
53
- value = #{Browser::FileList.new(`value`)};
54
- } else if (value instanceof File) {
55
- value = #{Browser::File.new(`value`)};
56
52
  } else if (value instanceof FileReader) {
57
53
  value = #{Browser::FileReader.new(`value`)}
58
54
  } else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
@@ -0,0 +1,8 @@
1
+ # backtick_javascript: true
2
+
3
+ module Browser
4
+ # An individual item in a FileList
5
+ class File < `File`
6
+ include Delegate
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ # backtick_javascript: true
2
+
3
+ module Browser
4
+ class FileList < `FileList`
5
+ include Delegate
6
+ include Enumerable
7
+
8
+ def [](idx)
9
+ `self.item(idx)`
10
+ end
11
+
12
+ # @return [Integer] the number of files in this list
13
+ def size
14
+ `self.length`
15
+ end
16
+
17
+ # Call the given block for each file in the list
18
+ #
19
+ # @yieldparam file [Browser::FileList::File]
20
+ def each &block
21
+ %x{
22
+ let l = #@native.length, i;
23
+ for(i = 0; i < l; i++) {
24
+ #{block.call(File.new(`#@native.item(i)`))}
25
+ }
26
+ }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # backtick_javascript: true
2
+
3
+ module Browser
4
+ class ReadableStream < `ReadableStream`
5
+ include Delegate
6
+ end
7
+ end
@@ -109,15 +109,7 @@ module Browser
109
109
  #
110
110
  # @return [Browser::File] the file selected by the user
111
111
  def file
112
- files.first
113
- end
114
-
115
- # Get the currently selected files for this input. This is only useful for
116
- # file inputs with the `multiple` property set.
117
- #
118
- # @return [Browser::FileList] the currently selected files for this input
119
- def files
120
- FileList.new(`#@native.files`)
112
+ `#@native.files.item(0)`
121
113
  end
122
114
 
123
115
  # Determine whether this is the same element
@@ -1,18 +1,20 @@
1
+ # backtick_javascript: true
2
+
1
3
  module Browser
2
- # The object that reads the file from disk.
3
4
  class FileReader
5
+ include DelegateNative
4
6
  include EventTarget
5
7
 
6
- def initialize
7
- @native = `new FileReader()`
8
- end
8
+ EMPTY = 0
9
+ LOADING = 1
10
+ DONE = 2
9
11
 
10
- def result
11
- `#@native.result`
12
+ def initialize(native=nil)
13
+ @native = native || `new FileReader()`
12
14
  end
13
15
 
14
- def read_as_binary_string file
15
- `#@native.readAsBinaryString(#{file.to_n})`
16
+ def read_as_data_url file
17
+ `#@native.readAsDataURL(file)`
16
18
  end
17
19
  end
18
20
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Preact
3
- VERSION = '23.9.0.rc2'
3
+ VERSION = '23.9.0.rc4'
4
4
  end
5
5
  end
@@ -16,7 +16,9 @@ require 'isomorfeus-i18n'
16
16
  require 'isomorfeus/preact/config'
17
17
 
18
18
  if RUBY_ENGINE == 'opal'
19
+ require 'browser/delegate'
19
20
  require 'browser/delegate_native'
21
+ require 'browser/file'
20
22
  require_tree 'browser_auto', autoload: true
21
23
  end
22
24
 
data/lib/preact.rb CHANGED
@@ -34,6 +34,40 @@ module Preact
34
34
 
35
35
  if RUBY_ENGINE == 'opal'
36
36
  %x{
37
+ let vnodeId = 0;
38
+
39
+ function vnode_eql(me, other) {
40
+ for(let prop in me) {
41
+ if (prop === 'props' && !(vnode[prop]["$=="](other[prop]))) {
42
+ return false;
43
+ } else if (vnode[prop] != other[prop]) {
44
+ return false;
45
+ }
46
+ }
47
+ return true;
48
+ }
49
+
50
+ class VNode {
51
+ constructor(type, props, key, ref, original) {
52
+ this.type = type;
53
+ this.props = props;
54
+ this.key = key;
55
+ this.ref = ref;
56
+ this._children = null;
57
+ this._parent = null;
58
+ this._depth = 0;
59
+ this._dom = null;
60
+ this._nextDom = undefined;
61
+ this._component = null;
62
+ this._hydrating = null;
63
+ this._original = (original == null) ? ++vnodeId : original;
64
+ this.constructor = undefined;
65
+ }
66
+ "$=="(other) { return vnode_eql(this, other); }
67
+ "$eql?"(other) { return vnode_eql(this, other); }
68
+ "$is_a?"(t) { return t === Opal.VNode; }
69
+ }
70
+
37
71
  function _catchError(error, vnode, oldVNode) {
38
72
  let component, ctor, handled;
39
73
 
@@ -63,7 +97,7 @@ module Preact
63
97
  throw error;
64
98
  }
65
99
 
66
- const EMPTY_OBJ = Object.create(null);
100
+ const EMPTY_OBJ = new VNode();
67
101
  const EMPTY_ARR = [];
68
102
  const slice = EMPTY_ARR.slice;
69
103
 
@@ -279,17 +313,17 @@ module Preact
279
313
  // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
280
314
  // or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
281
315
  // it's own DOM & etc. pointers
282
- else if (typeof childVNode === 'string' || typeof childVNode === 'number' || typeof childVNode === 'bigint') {
283
- childVNode = newParentVNode._children[i] = self.createVNode(
316
+ else if (typeof childVNode === 'string') {
317
+ childVNode = newParentVNode._children[i] = new VNode(
284
318
  null,
285
319
  childVNode,
286
320
  null,
287
321
  null,
288
322
  childVNode
289
323
  );
290
- } else if (childVNode.$$is_string || childVNode.$$is_number) {
324
+ } else if (childVNode.$$is_string) {
291
325
  let str = childVNode.valueOf();
292
- childVNode = newParentVNode._children[i] = self.createVNode(
326
+ childVNode = newParentVNode._children[i] = new VNode(
293
327
  null,
294
328
  str,
295
329
  null,
@@ -297,7 +331,7 @@ module Preact
297
331
  str
298
332
  );
299
333
  } else if (childVNode.$$is_array) {
300
- childVNode = newParentVNode._children[i] = self.createVNode(
334
+ childVNode = newParentVNode._children[i] = new VNode(
301
335
  Opal.Fragment,
302
336
  #{{ children: `childVNode` }},
303
337
  null,
@@ -309,7 +343,7 @@ module Preact
309
343
  // scenario:
310
344
  // const reuse = <div />
311
345
  // <div>{reuse}<span />{reuse}</div>
312
- childVNode = newParentVNode._children[i] = self.createVNode(
346
+ childVNode = newParentVNode._children[i] = new VNode(
313
347
  childVNode.type,
314
348
  childVNode.props,
315
349
  childVNode.key,
@@ -387,7 +421,7 @@ module Preact
387
421
  }
388
422
 
389
423
  if (
390
- typeof childVNode.type == 'function' &&
424
+ typeof childVNode.type === 'function' &&
391
425
  childVNode._children === oldVNode._children
392
426
  ) {
393
427
  childVNode._nextDom = oldDom = reorderChildren(
@@ -433,7 +467,7 @@ module Preact
433
467
  for (i = oldChildrenLength; i--; ) {
434
468
  if (oldChildren[i] != null) {
435
469
  if (
436
- typeof newParentVNode.type == 'function' &&
470
+ typeof newParentVNode.type === 'function' &&
437
471
  oldChildren[i]._dom != null &&
438
472
  oldChildren[i]._dom == newParentVNode._nextDom
439
473
  ) {
@@ -834,7 +868,7 @@ module Preact
834
868
  validate_props(newType, newProps);
835
869
  newProps.$freeze();
836
870
  }
837
-
871
+
838
872
  if (c["$respond_to?"]("get_derived_state_from_props")) {
839
873
  if (c._nextState == c.state) {
840
874
  c._nextState = c._nextState.$dup();
@@ -987,34 +1021,12 @@ module Preact
987
1021
  });
988
1022
  }
989
1023
 
990
- let vnodeId = 0;
991
1024
 
992
- function is_a_vnode(type) { return type === Opal.VNode; }
993
1025
 
994
1026
  self.createVNode = function(type, props, key, ref, original) {
995
1027
  // V8 seems to be better at detecting type shapes if the object is allocated from the same call site
996
1028
  // Do not inline into createElement and coerceToVNode!
997
- return {
998
- type,
999
- props,
1000
- key,
1001
- ref,
1002
- _children: null,
1003
- _parent: null,
1004
- _depth: 0,
1005
- _dom: null,
1006
- // _nextDom must be initialized to undefined b/c it will eventually
1007
- // be set to dom.nextSibling which can return `null` and it is important
1008
- // to be able to distinguish between an uninitialized _nextDom and
1009
- // a _nextDom that has been set to `null`
1010
- _nextDom: undefined,
1011
- _component: null,
1012
- _hydrating: null,
1013
- constructor: undefined,
1014
- _original: (original == null) ? ++vnodeId : original,
1015
- "$is_a?": is_a_vnode,
1016
- "$$is_vnode": true
1017
- };
1029
+ return new VNode(type, props, key, ref, original);
1018
1030
  }
1019
1031
 
1020
1032
  self.render = function(vnode, parentDom, replaceNode) {
@@ -1083,7 +1095,7 @@ module Preact
1083
1095
 
1084
1096
  if (parentDom) {
1085
1097
  let commitQueue = [];
1086
- const oldVNode = assign({}, vnode);
1098
+ const oldVNode = assign(new VNode(), vnode);
1087
1099
  oldVNode._original = vnode._original + 1;
1088
1100
 
1089
1101
  diff(
@@ -1177,7 +1189,6 @@ module Preact
1177
1189
  end
1178
1190
 
1179
1191
  if RUBY_ENGINE == 'opal'
1180
- attr_accessor :_vnode_id
1181
1192
  attr_accessor :render_buffer
1182
1193
  attr_accessor :rerender_queue
1183
1194
 
@@ -1312,6 +1323,3 @@ module Preact
1312
1323
  end
1313
1324
  end
1314
1325
 
1315
- if RUBY_ENGINE == 'opal'
1316
- Preact._vnode_id = 0
1317
- end
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: 23.9.0.rc2
4
+ version: 23.9.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-10 00:00:00.000000000 Z
11
+ date: 2023-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -78,28 +78,28 @@ dependencies:
78
78
  requirements:
79
79
  - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: 23.9.0.rc2
81
+ version: 23.9.0.rc4
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '='
87
87
  - !ruby/object:Gem::Version
88
- version: 23.9.0.rc2
88
+ version: 23.9.0.rc4
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: isomorfeus-redux
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 23.9.0.rc2
95
+ version: 23.9.0.rc4
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
- version: 23.9.0.rc2
102
+ version: 23.9.0.rc4
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: benchmark-ips
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: 0.9.2
123
+ version: 0.9.3
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: 0.9.2
130
+ version: 0.9.3
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: rake
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -185,18 +185,21 @@ files:
185
185
  - ext/isomorfeus_preact_ext/preact.c
186
186
  - ext/isomorfeus_preact_ext/vnode.c
187
187
  - ext/isomorfeus_preact_ext/vnode.h
188
+ - lib/browser/array_buffer.rb
189
+ - lib/browser/blob.rb
190
+ - lib/browser/delegate.rb
188
191
  - lib/browser/delegate_native.rb
192
+ - lib/browser/file.rb
193
+ - lib/browser/file_list.rb
189
194
  - lib/browser/history.rb
190
195
  - lib/browser/location.rb
191
- - lib/browser_auto/browser/delegate_native.rb
196
+ - lib/browser/readable_stream.rb
192
197
  - lib/browser_auto/browser/document.rb
193
198
  - lib/browser_auto/browser/element.rb
194
199
  - lib/browser_auto/browser/element/canvas.rb
195
200
  - lib/browser_auto/browser/element/media.rb
196
201
  - lib/browser_auto/browser/event.rb
197
202
  - lib/browser_auto/browser/event_target.rb
198
- - lib/browser_auto/browser/file.rb
199
- - lib/browser_auto/browser/file_list.rb
200
203
  - lib/browser_auto/browser/file_reader.rb
201
204
  - lib/browser_auto/browser/window.rb
202
205
  - lib/data_uri.rb
@@ -1,62 +0,0 @@
1
- module Browser
2
- # An individual item in a FileList
3
- class File
4
- attr_reader :data
5
-
6
- # @param native [JS] the native File object to wrap
7
- def initialize native
8
- @native = native
9
- @data = nil
10
- end
11
-
12
- # @return [String] the filename
13
- def name
14
- `#@native.name`
15
- end
16
-
17
- # @return [Integer] the size of this file on disk
18
- def size
19
- `#@native.size`
20
- end
21
-
22
- # @return [String] the MIME type of the file, detected by the browser
23
- def type
24
- `#@native.type`
25
- end
26
-
27
- # @return [Time] the timestamp of the file
28
- def last_modified
29
- `#@native.lastModifiedDate`
30
- end
31
-
32
- # Read the file from disk into memory
33
- #
34
- # @return [Promise] a promise that resolves when finished loading and
35
- # rejects if an error occurs while loading.
36
- def read
37
- promise = Promise.new
38
- reader = FileReader.new
39
- reader.on :load do
40
- result = reader.result
41
-
42
- @data = result
43
- promise.resolve result
44
- end
45
-
46
- reader.on :error do
47
- promise.reject reader.result
48
- end
49
-
50
- reader.read_as_binary_string self
51
-
52
- promise
53
- end
54
-
55
- # Convert to the native object
56
- #
57
- # @return [JS.HTMLElement] the underlying native element
58
- def to_n
59
- @native
60
- end
61
- end
62
- end
@@ -1,47 +0,0 @@
1
- # backtick_javascript: true
2
-
3
- module Browser
4
- class FileList
5
- include Enumerable
6
-
7
- # @param native [JS] the native FileList object to wrap
8
- def initialize native
9
- @native = `#{native} || []`
10
- @files = length.times.each_with_object([]) { |index, array|
11
- array[index] = ::Browser::File.new(`#@native[index]`)
12
- }
13
- end
14
-
15
- # @param index [Integer] the index of the file in the list
16
- # @return [Browser::FileList::File] the file at the specified index
17
- def [] index
18
- @files[index]
19
- end
20
-
21
- # @return [Integer] the number of files in this list
22
- def length
23
- `#@native.length`
24
- end
25
- alias size length
26
-
27
- # Call the given block for each file in the list
28
- #
29
- # @yieldparam file [Browser::FileList::File]
30
- def each &block
31
- @files.each do |file|
32
- block.call file
33
- end
34
- end
35
-
36
- # Convert this FileList into an array
37
- def to_a
38
- @files.dup # Don't return a value that can mutate our internal state
39
- end
40
- alias to_ary to_a
41
-
42
- # @return [String] a string representation of this FileList
43
- def to_s
44
- @files.to_s
45
- end
46
- end
47
- end