isomorfeus-preact 23.8.0.rc2 → 23.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/delegate_native.rb +10 -0
- data/lib/browser/history.rb +6 -9
- data/lib/browser/location.rb +1 -11
- data/lib/browser_auto/browser/delegate_native.rb +94 -0
- data/lib/{browser → browser_auto/browser}/element.rb +0 -7
- data/lib/browser_auto/browser/file.rb +62 -0
- data/lib/browser_auto/browser/file_list.rb +47 -0
- data/lib/browser_auto/browser/file_reader.rb +18 -0
- data/lib/isomorfeus/preact/version.rb +1 -1
- data/lib/isomorfeus-preact.rb +8 -7
- metadata +23 -20
- data/lib/browser/file_list.rb +0 -127
- /data/lib/{browser → browser_auto/browser}/document.rb +0 -0
- /data/lib/{browser → browser_auto/browser}/element/canvas.rb +0 -0
- /data/lib/{browser → browser_auto/browser}/element/media.rb +0 -0
- /data/lib/{browser → browser_auto/browser}/event.rb +0 -0
- /data/lib/{browser → browser_auto/browser}/event_target.rb +0 -0
- /data/lib/{browser → browser_auto/browser}/window.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27a7d5a11be914eeb7d2492984130ce644c7e9544c28a51ca38de66062ed65e5
|
4
|
+
data.tar.gz: 0f8a66e40d5bc23cd54ecc624642d4dc02ce3b00e72746194dceb1f37e9f0c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91eda90d5fc66877f4c2c617d814b35bb11ac9040521802190b7462a4424ef0f88d793c09fbb95bc9a4fd43517dd1c4aead2bf9c4615347422d5a591417db051
|
7
|
+
data.tar.gz: c608d2b6c80195ff7d0d8831217600ec35ef9e8a3b7f253c8df214af66e5035f3e55430f0e0382bf71ac93b21dbc1fc87389081427f822d3bfc739ad73f85bcd
|
@@ -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
|
data/lib/browser/history.rb
CHANGED
@@ -3,14 +3,11 @@
|
|
3
3
|
module Browser
|
4
4
|
class History
|
5
5
|
if RUBY_ENGINE == 'opal'
|
6
|
-
include
|
6
|
+
include DelegateNative
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
data/lib/browser/location.rb
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
module Browser
|
2
2
|
class Location
|
3
3
|
if RUBY_ENGINE == 'opal'
|
4
|
-
include
|
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
|
data/lib/isomorfeus-preact.rb
CHANGED
@@ -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
|
-
|
25
|
-
|
26
|
-
|
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.
|
4
|
+
version: 23.9.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: 2023-
|
11
|
+
date: 2023-09-09 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.
|
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.
|
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.
|
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.
|
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.
|
81
|
+
version: 23.9.0.rc1
|
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.
|
88
|
+
version: 23.9.0.rc1
|
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.
|
95
|
+
version: 23.9.0.rc1
|
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.
|
102
|
+
version: 23.9.0.rc1
|
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.
|
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.
|
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/
|
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
|
data/lib/browser/file_list.rb
DELETED
@@ -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
|
File without changes
|
File without changes
|
File without changes
|