isomorfeus-preact 23.8.0.rc3 → 23.9.0.rc2

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: 2bd935d1edb5fe4edef829c7b47d8c61a3720af7575093324a68a0c385cfac14
4
- data.tar.gz: b3eef40865f6d0bb6a9ae2903478872baaf555c27051fa35e84e73f62156eccf
3
+ metadata.gz: 9b75453247bc0c884571e884c674717562fe5e27fadf2f1f27f5f62965e37580
4
+ data.tar.gz: 6eaddb4ca8921da6d124b1eb983663fd8de05b3d25ad31c9975b35d77468cc6d
5
5
  SHA512:
6
- metadata.gz: 8b43949427d9af4cf465cb7c65bc9fde35d78471e5f4f3c47b1d542addbbfc21b8b969d9bd67f97441b382735d5b5e2f271c2bd562fa3006181eeb1eac1647b6
7
- data.tar.gz: 38693a0bf2d26737985fa54782a783e75910d8f1e798c68f2f7f492a3ffa37222784b96d70ffe3f52eddec1b32c43133da9cf37c5a0d60bff1f14a6db8dc6694
6
+ metadata.gz: 37662cbea0b4b59cd9ec04c632cb2ea2bf9e96fa2ffab3f6a40f9d7632be83b72d60189b8da2c60ba70af41c4f7de435a7410a40c66887699ab1ad9d6419c57d
7
+ data.tar.gz: 4300537585ebb569255dddc9a34ea47ddc19d682ae0e1f995cf30f9b7cebe7a063512f9689a634bd9a9a113d80083bb684a0262db5c4d05d1aa18e008e1f90dd
@@ -49,6 +49,12 @@ 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
+ } else if (value instanceof FileReader) {
57
+ value = #{Browser::FileReader.new(`value`)}
52
58
  } else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
53
59
  value = nil;
54
60
  }
@@ -80,5 +86,9 @@ module Browser
80
86
  return camel_cased_message
81
87
  }
82
88
  end
89
+
90
+ def to_n
91
+ @native
92
+ end
83
93
  end
84
94
  end
@@ -3,14 +3,11 @@
3
3
  module Browser
4
4
  class History
5
5
  if RUBY_ENGINE == 'opal'
6
- include Native::Wrapper
6
+ include DelegateNative
7
7
 
8
- alias_native :back
9
- alias_native :forward
10
- alias_native :go
11
-
12
- native_reader :length
13
- alias :size :length
8
+ def size
9
+ length
10
+ end
14
11
 
15
12
  def push_state(state, title = '', url = `null`)
16
13
  `#@native.pushState(Object.fromEntries(#{state}), #{title}, #{url})`
@@ -29,7 +26,7 @@ module Browser
29
26
  end
30
27
 
31
28
  def state
32
- `Opal.hash(#@native.state)`
29
+ `(#@native.state) ? Opal.hash(#@native.state) : nil`
33
30
  end
34
31
  else
35
32
  def back; end
@@ -47,7 +44,7 @@ module Browser
47
44
  def scroll_restoration=(s); end
48
45
 
49
46
  def state
50
- {}
47
+ nil
51
48
  end
52
49
  end
53
50
  end
@@ -1,17 +1,7 @@
1
1
  module Browser
2
2
  class Location
3
3
  if RUBY_ENGINE == 'opal'
4
- include Native::Wrapper
5
-
6
- alias_native :hash
7
- alias_native :host
8
- alias_native :hostname
9
- alias_native :href
10
- alias_native :origin
11
- alias_native :pathname
12
- alias_native :port
13
- alias_native :protocol
14
- alias_native :search
4
+ include DelegateNative
15
5
  else
16
6
  def initialize(location_string)
17
7
  @location = URI(location_string)
@@ -0,0 +1,94 @@
1
+ # backtick_javascript: true
2
+
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
+
11
+ def [](property)
12
+ method_missing(property)
13
+ end
14
+
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
+ def method_missing message, *args, &block
25
+ if message.end_with? '='
26
+ message = message.chop
27
+ property_name = property_for_message(message)
28
+ arg = args[0]
29
+ arg = arg.to_n if `arg && typeof arg.$to_n === 'function'`
30
+ return `#@native[#{property_name}] = arg`
31
+ else
32
+ property_name = property_for_message(message)
33
+ %x{
34
+ let value = #@native[#{property_name}];
35
+ let type = typeof(value);
36
+ if (type === 'undefined') { return #{super}; }
37
+ try {
38
+ if (type === 'function') {
39
+ #{args.map! { |arg| `arg && typeof arg.$to_n === 'function'` ? arg.to_n : arg }}
40
+ value = value.apply(#@native, args);
41
+ }
42
+ if (value instanceof HTMLCollection || value instanceof NodeList) {
43
+ let a = [];
44
+ for(let i=0; i<value.length; i++) {
45
+ a[i] = #{Browser::Element.new(`value.item(i)`)};
46
+ }
47
+ value = a;
48
+ } else if (value instanceof HTMLElement || value instanceof SVGElement) {
49
+ value = #{Browser::Element.new(`value`)};
50
+ } else if (value instanceof Event) {
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
+ } else if (value instanceof FileReader) {
57
+ value = #{Browser::FileReader.new(`value`)}
58
+ } else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
59
+ value = nil;
60
+ }
61
+ return value;
62
+ } catch { return value; }
63
+ }
64
+ end
65
+ end
66
+
67
+ def respond_to_missing? message, include_all
68
+ message = message.chop if message.end_with? '='
69
+ property_name = property_for_message(message)
70
+ return true if `#{property_name} in #@native`
71
+ false
72
+ end
73
+
74
+ def property_for_message(message)
75
+ %x{
76
+ let camel_cased_message;
77
+ if (typeof(#@native[message]) !== 'undefined') { camel_cased_message = message; }
78
+ else { camel_cased_message = #{message.camelize(:lower)} }
79
+
80
+ if (camel_cased_message.endsWith('?')) {
81
+ camel_cased_message = camel_cased_message.substring(0, camel_cased_message.length - 2);
82
+ if (typeof(#@native[camel_cased_message]) === 'undefined') {
83
+ camel_cased_message = 'is' + camel_cased_message[0].toUpperCase() + camel_cased_message.substring(0, camel_cased_message.length - 1);
84
+ }
85
+ }
86
+ return camel_cased_message
87
+ }
88
+ end
89
+
90
+ def to_n
91
+ @native
92
+ end
93
+ end
94
+ end
@@ -1,8 +1,6 @@
1
1
  # backtick_javascript: true
2
2
 
3
3
  module Browser
4
- autoload :FileList, 'browser/file_list'
5
-
6
4
  # Wrap a native DOM element
7
5
  class Element
8
6
  include EventTarget
@@ -24,11 +22,6 @@ module Browser
24
22
  element
25
23
  end
26
24
 
27
- # @param native [JS] The native DOM element to wrap
28
- def initialize native
29
- @native = native
30
- end
31
-
32
25
  # Replace all child elements with the given element
33
26
  #
34
27
  # @param element [Browser::Element] The Browser element with which to replace
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,18 @@
1
+ module Browser
2
+ # The object that reads the file from disk.
3
+ class FileReader
4
+ include EventTarget
5
+
6
+ def initialize
7
+ @native = `new FileReader()`
8
+ end
9
+
10
+ def result
11
+ `#@native.result`
12
+ end
13
+
14
+ def read_as_binary_string file
15
+ `#@native.readAsBinaryString(#{file.to_n})`
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Preact
3
- VERSION = '23.8.0.rc3'
3
+ VERSION = '23.9.0.rc2'
4
4
  end
5
5
  end
@@ -14,17 +14,16 @@ require 'isomorfeus-transport'
14
14
  require 'isomorfeus-redux'
15
15
  require 'isomorfeus-i18n'
16
16
  require 'isomorfeus/preact/config'
17
- require 'browser/history'
18
- require 'browser/location'
19
17
 
20
18
  if RUBY_ENGINE == 'opal'
21
- require 'browser/event'
22
- require 'browser/event_target'
23
19
  require 'browser/delegate_native'
24
- require 'browser/element'
25
- require 'browser/document'
26
- require 'browser/window'
20
+ require_tree 'browser_auto', autoload: true
21
+ end
22
+
23
+ require 'browser/history'
24
+ require 'browser/location'
27
25
 
26
+ if RUBY_ENGINE == 'opal'
28
27
  if `window?.history`
29
28
  Isomorfeus.browser_history = Browser::History.new(`window.history`)
30
29
  Isomorfeus.browser_location = Browser::Location.new(`window.location`)
@@ -56,6 +55,7 @@ require 'preact/module_component_resolution'
56
55
  require 'preact/html_elements'
57
56
  # require 'preact/svg_elements' # optional
58
57
  # require 'preact/math_ml_elements' # optional
58
+
59
59
  # Component
60
60
  require 'preact/component'
61
61
  # Context
@@ -78,6 +78,7 @@ require 'lucid_app'
78
78
 
79
79
  if RUBY_ENGINE == 'opal'
80
80
  # init auto loader
81
+ Isomorfeus.zeitwerk.push_dir('browser_auto')
81
82
  Isomorfeus.zeitwerk.push_dir('components')
82
83
  else
83
84
  require 'isomorfeus/preact/version'
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.8.0.rc3
4
+ version: 23.9.0.rc2
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-08-26 00:00:00.000000000 Z
11
+ date: 2023-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 3.13.23
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 3.16.0
22
+ version: 3.17.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 3.13.23
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 3.16.0
32
+ version: 3.17.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: opal
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -64,42 +64,42 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.19.1
67
+ version: 0.19.3
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.19.1
74
+ version: 0.19.3
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: isomorfeus-i18n
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - '='
80
80
  - !ruby/object:Gem::Version
81
- version: 23.8.0.rc3
81
+ version: 23.9.0.rc2
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.8.0.rc3
88
+ version: 23.9.0.rc2
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.8.0.rc3
95
+ version: 23.9.0.rc2
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.8.0.rc3
102
+ version: 23.9.0.rc2
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.1
123
+ version: 0.9.2
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.1
130
+ version: 0.9.2
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: rake
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -186,16 +186,19 @@ files:
186
186
  - ext/isomorfeus_preact_ext/vnode.c
187
187
  - ext/isomorfeus_preact_ext/vnode.h
188
188
  - lib/browser/delegate_native.rb
189
- - lib/browser/document.rb
190
- - lib/browser/element.rb
191
- - lib/browser/element/canvas.rb
192
- - lib/browser/element/media.rb
193
- - lib/browser/event.rb
194
- - lib/browser/event_target.rb
195
- - lib/browser/file_list.rb
196
189
  - lib/browser/history.rb
197
190
  - lib/browser/location.rb
198
- - lib/browser/window.rb
191
+ - lib/browser_auto/browser/delegate_native.rb
192
+ - lib/browser_auto/browser/document.rb
193
+ - lib/browser_auto/browser/element.rb
194
+ - lib/browser_auto/browser/element/canvas.rb
195
+ - lib/browser_auto/browser/element/media.rb
196
+ - lib/browser_auto/browser/event.rb
197
+ - lib/browser_auto/browser/event_target.rb
198
+ - lib/browser_auto/browser/file.rb
199
+ - lib/browser_auto/browser/file_list.rb
200
+ - lib/browser_auto/browser/file_reader.rb
201
+ - lib/browser_auto/browser/window.rb
199
202
  - lib/data_uri.rb
200
203
  - lib/data_uri/open_uri.rb
201
204
  - lib/data_uri/uri.rb
@@ -1,127 +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] = 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
-
47
- # An individual item in a FileList
48
- class File
49
- attr_reader :data
50
-
51
- # @param native [JS] the native File object to wrap
52
- def initialize native
53
- @native = native
54
- @data = nil
55
- end
56
-
57
- # @return [String] the filename
58
- def name
59
- `#@native.name`
60
- end
61
-
62
- # @return [Integer] the size of this file on disk
63
- def size
64
- `#@native.size`
65
- end
66
-
67
- # @return [String] the MIME type of the file, detected by the browser
68
- def type
69
- `#@native.type`
70
- end
71
-
72
- # @return [Time] the timestamp of the file
73
- def last_modified
74
- `#@native.lastModifiedDate`
75
- end
76
-
77
- # Read the file from disk into memory
78
- #
79
- # @return [Promise] a promise that resolves when finished loading and
80
- # rejects if an error occurs while loading.
81
- def read
82
- promise = Promise.new
83
- reader = FileReader.new
84
- reader.on :load do
85
- result = reader.result
86
-
87
- @data = result
88
- promise.resolve result
89
- end
90
-
91
- reader.on :error do
92
- promise.reject reader.result
93
- end
94
-
95
- reader.read_as_binary_string self
96
-
97
- promise
98
- end
99
-
100
- # Convert to the native object
101
- #
102
- # @return [JS.HTMLElement] the underlying native element
103
- def to_n
104
- @native
105
- end
106
-
107
- # The object that reads the file from disk.
108
- #
109
- # @api private
110
- class FileReader
111
- include EventTarget
112
-
113
- def initialize
114
- @native = `new FileReader()`
115
- end
116
-
117
- def result
118
- `#@native.result`
119
- end
120
-
121
- def read_as_binary_string file
122
- `#@native.readAsBinaryString(#{file.to_n})`
123
- end
124
- end
125
- end
126
- end
127
- end
File without changes
File without changes
File without changes