isomorfeus-react 16.8.9 → 16.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/browser/delegate_native.rb +70 -0
- data/lib/browser/element.rb +176 -0
- data/lib/browser/element/canvas.rb +17 -0
- data/lib/browser/element/media.rb +78 -0
- data/lib/browser/event.rb +92 -0
- data/lib/browser/event_target.rb +39 -0
- data/lib/browser/file_list.rb +125 -0
- data/lib/browser/iterable.rb +15 -0
- data/lib/isomorfeus-react-material-ui.rb +1 -31
- data/lib/isomorfeus-react.rb +112 -5
- data/lib/isomorfeus/execution_environment.rb +8 -2
- data/lib/isomorfeus/top_level_browser.rb +1 -1
- data/lib/lucid_app/mixin.rb +1 -1
- data/lib/lucid_component/app_store_defaults.rb +36 -0
- data/lib/lucid_component/app_store_proxy.rb +40 -0
- data/lib/lucid_component/class_store_proxy.rb +43 -0
- data/lib/lucid_component/component_class_store_defaults.rb +38 -0
- data/lib/lucid_component/component_instance_store_defaults.rb +35 -0
- data/lib/lucid_component/initializer.rb +3 -3
- data/lib/lucid_component/instance_store_proxy.rb +47 -0
- data/lib/lucid_component/mixin.rb +1 -1
- data/lib/lucid_component/reducers.rb +46 -0
- data/lib/lucid_component/store_api.rb +38 -0
- data/lib/lucid_material/app/mixin.rb +1 -1
- data/lib/lucid_material/component/mixin.rb +1 -1
- data/lib/react.rb +1 -2
- data/lib/react/component/api.rb +4 -0
- data/lib/react/component/features.rb +5 -1
- data/lib/react/component/mixin.rb +1 -1
- data/lib/react/component/props.rb +1 -1
- data/lib/react/function_component/api.rb +5 -25
- data/lib/react/pure_component/mixin.rb +1 -1
- data/lib/react/synthetic_event.rb +3 -3
- data/lib/react/version.rb +1 -1
- data/lib/react_dom.rb +1 -1
- metadata +22 -36
- data/lib/isomorfeus-react-base.rb +0 -57
- data/lib/isomorfeus-react-component.rb +0 -20
- data/lib/isomorfeus-react-lucid.rb +0 -39
- data/lib/isomorfeus-react-redux-component.rb +0 -25
- data/lib/react/redux_component/api.rb +0 -40
- data/lib/react/redux_component/app_store_defaults.rb +0 -38
- data/lib/react/redux_component/app_store_proxy.rb +0 -43
- data/lib/react/redux_component/base.rb +0 -9
- data/lib/react/redux_component/class_store_proxy.rb +0 -46
- data/lib/react/redux_component/component_class_store_defaults.rb +0 -40
- data/lib/react/redux_component/component_instance_store_defaults.rb +0 -37
- data/lib/react/redux_component/initializer.rb +0 -14
- data/lib/react/redux_component/instance_store_proxy.rb +0 -50
- data/lib/react/redux_component/mixin.rb +0 -19
- data/lib/react/redux_component/native_component_constructor.rb +0 -144
- data/lib/react/redux_component/reducers.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7055c4d0f51f9fe1035227468603837022020c562bab7b75c75dbfce892ccf3
|
4
|
+
data.tar.gz: a0fe000bd455105057f9b5136c446a705036240ef5ab322f86b4f5ae9529b1b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3c731f47da42dfcc9d072b9c7c7d9f676ce1ba33331c6b905d2ac9a66c0905058e693eb7b5426fbee13204786f10a94e6c8a5dba3a3a0a3abb8cbd99ff5e25
|
7
|
+
data.tar.gz: eed0e49409eb5bd1f3ce5a29cc2efbbebed244edbf2b978c7284b478e118c3fa5ae70fca87d02cc9d9aefae21cf52431044b542c1b13e3398c5d444a07d814e2
|
data/README.md
CHANGED
@@ -21,7 +21,6 @@ Component Types:
|
|
21
21
|
- [Class Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/class_component.md)
|
22
22
|
- [Pure Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/pure_component.md)
|
23
23
|
- [Function and Memo Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/function_component.md)
|
24
|
-
- [Redux Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/redux_component.md)
|
25
24
|
- [Lucid App, Lucid Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/lucid_component.md)
|
26
25
|
- [LucidMaterial App, LucidMaterial Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/lucid_material_component.md) - support for [MaterialUI](https://material-ui.com)
|
27
26
|
- [React Javascript Component](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/javascript_component.md)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Browser
|
2
|
+
module DelegateNative
|
3
|
+
# Provides a default initializer. This should be overridden in all but the
|
4
|
+
# simplest cases.
|
5
|
+
def initialize native
|
6
|
+
@native = native
|
7
|
+
end
|
8
|
+
|
9
|
+
# Fall back to native properties. If the message sent to this element is not
|
10
|
+
# recognized, it checks to see if it is a property of the native element. It
|
11
|
+
# also checks for variations of the message name, such as:
|
12
|
+
#
|
13
|
+
# :supported? => [:supported, :isSupported]
|
14
|
+
#
|
15
|
+
# If a property with the specified message name is found and it is a
|
16
|
+
# function, that function is invoked with `args`. Otherwise, the property
|
17
|
+
# is returned as is.
|
18
|
+
def method_missing message, *args, &block
|
19
|
+
property_name = property_for_message(message)
|
20
|
+
property = `#@native[#{property_name}]`
|
21
|
+
|
22
|
+
# translate setting a property
|
23
|
+
if message.end_with? '='
|
24
|
+
return `#@native[#{property_name}] = args[0]`
|
25
|
+
end
|
26
|
+
|
27
|
+
# If the native element doesn't have this property, bubble it up
|
28
|
+
super unless `#{property_name} in #@native`
|
29
|
+
|
30
|
+
if `property === false`
|
31
|
+
return false
|
32
|
+
elsif `typeof(property) === 'number' && isNaN(property)`
|
33
|
+
return nil
|
34
|
+
else
|
35
|
+
property = `property == null ? nil : property`
|
36
|
+
end
|
37
|
+
|
38
|
+
# If it's a method, call it. Otherwise, return it.
|
39
|
+
if `typeof(property) === 'function'`
|
40
|
+
`property.apply(#@native, args)`
|
41
|
+
else
|
42
|
+
property
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def respond_to_missing? message, include_all
|
47
|
+
return true if message.end_with? '='
|
48
|
+
return true if property_for_message(message)
|
49
|
+
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def property_for_message message
|
54
|
+
camel_cased_message = message
|
55
|
+
.gsub(/_\w/) { |match| `match[1]`.upcase }
|
56
|
+
.sub(/=$/, '')
|
57
|
+
|
58
|
+
# translate `supported?` to `supported` or `isSupported`
|
59
|
+
if message.end_with? '?'
|
60
|
+
camel_cased_message = camel_cased_message.chop
|
61
|
+
property_type = `typeof(#@native[camel_cased_message])`
|
62
|
+
if property_type == 'undefined'
|
63
|
+
camel_cased_message = "is#{camel_cased_message[0].upcase}#{camel_cased_message[1..-1]}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
camel_cased_message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
module Browser
|
2
|
+
autoload :FileList, 'browser/file_list'
|
3
|
+
autoload :Iterable, 'browser/iterable'
|
4
|
+
|
5
|
+
# Wrap a native DOM element
|
6
|
+
class Element
|
7
|
+
include EventTarget
|
8
|
+
include DelegateNative
|
9
|
+
|
10
|
+
@tags = Hash.new(self)
|
11
|
+
|
12
|
+
def self.element *tags, &block
|
13
|
+
tags.each do |tag|
|
14
|
+
@tags
|
15
|
+
.fetch(tag) { @tags[tag] = const_set(tag.capitalize, Class.new(self)) }
|
16
|
+
.class_exec(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.new(native)
|
21
|
+
element = @tags[`(#{native}.tagName || '')`.downcase].allocate
|
22
|
+
element.initialize native
|
23
|
+
element
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param native [JS] The native DOM element to wrap
|
27
|
+
def initialize native
|
28
|
+
@native = native
|
29
|
+
end
|
30
|
+
|
31
|
+
# Replace all child elements with the given element
|
32
|
+
#
|
33
|
+
# @param element [Browser::Element] The Browser element with which to replace
|
34
|
+
# this element's contents
|
35
|
+
def inner_dom= element
|
36
|
+
clear
|
37
|
+
append element
|
38
|
+
end
|
39
|
+
|
40
|
+
# The contents of this element as an HTML string
|
41
|
+
#
|
42
|
+
# @return [String] the HTML representation of this element's contents
|
43
|
+
def inner_html
|
44
|
+
`#@native.innerHTML`
|
45
|
+
end
|
46
|
+
|
47
|
+
# Use the supplied HTML string to replace this element's contents
|
48
|
+
#
|
49
|
+
# @param html [String] the HTML with which to replace this elements contents
|
50
|
+
def inner_html= html
|
51
|
+
`#@native.innerHTML = html`
|
52
|
+
end
|
53
|
+
|
54
|
+
# This element's direct child elements
|
55
|
+
#
|
56
|
+
# @return [Array<Browser::Element>] list of this element's children
|
57
|
+
def children
|
58
|
+
elements = []
|
59
|
+
|
60
|
+
%x{
|
61
|
+
var children = #@native.children;
|
62
|
+
for(var i = 0; i < children.length; i++) {
|
63
|
+
elements[i] = #{Element.new(`children[i]`)};
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
elements
|
68
|
+
end
|
69
|
+
|
70
|
+
# Determine whether this element has any contents
|
71
|
+
#
|
72
|
+
# @return [Boolean] true if the element has no children, false otherwise
|
73
|
+
def empty?
|
74
|
+
`#@native.children.length === 0`
|
75
|
+
end
|
76
|
+
|
77
|
+
# Remove all contents from this element. After this call, `empty?` will
|
78
|
+
# return `true`.
|
79
|
+
#
|
80
|
+
# @return [Browser::Element] self
|
81
|
+
def clear
|
82
|
+
if %w(input textarea).include? type
|
83
|
+
`#@native.value = null`
|
84
|
+
else
|
85
|
+
children.each do |child|
|
86
|
+
remove_child child
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
# Remove the specified child element
|
94
|
+
#
|
95
|
+
# @param child [Browser::Element] the child element to remove
|
96
|
+
def remove_child child
|
97
|
+
`#@native.removeChild(child['native'] ? child['native'] : child)`
|
98
|
+
end
|
99
|
+
|
100
|
+
# This element's type. For example: "div", "span", "p"
|
101
|
+
#
|
102
|
+
# @return [String] the HTML tag name for this element
|
103
|
+
def type
|
104
|
+
`#@native.nodeName`.downcase
|
105
|
+
end
|
106
|
+
|
107
|
+
# Append the specified element as a child element
|
108
|
+
#
|
109
|
+
# @param element [Browser::Element, JS] the element to insert
|
110
|
+
def append node
|
111
|
+
`#@native.appendChild(node['native'] ? node['native'] : node)`
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
# Methods for <input /> elements
|
116
|
+
|
117
|
+
# A checkbox's checked status
|
118
|
+
#
|
119
|
+
# @return [Boolean] true if the checkbox is checked, false otherwise
|
120
|
+
def checked?
|
121
|
+
`!!#@native.checked`
|
122
|
+
end
|
123
|
+
|
124
|
+
# Get the currently selected file for this input. This is only useful for
|
125
|
+
# file inputs without the `multiple` property set.
|
126
|
+
#
|
127
|
+
# @return [Browser::File] the file selected by the user
|
128
|
+
def file
|
129
|
+
files.first
|
130
|
+
end
|
131
|
+
|
132
|
+
# Get the currently selected files for this input. This is only useful for
|
133
|
+
# file inputs with the `multiple` property set.
|
134
|
+
#
|
135
|
+
# @return [Browser::FileList] the currently selected files for this input
|
136
|
+
def files
|
137
|
+
FileList.new(`#@native.files`)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Determine whether this is the same element
|
141
|
+
#
|
142
|
+
# @return [boolean] true if the element is the same, false otherwise
|
143
|
+
def ==(other)
|
144
|
+
`#@native === #{other.to_n}`
|
145
|
+
end
|
146
|
+
|
147
|
+
# Set the specified attribute to the specified value
|
148
|
+
def []= attribute, value
|
149
|
+
`#@native.setAttribute(#{attribute}, #{value})`
|
150
|
+
end
|
151
|
+
|
152
|
+
# Return the specified attribute
|
153
|
+
#
|
154
|
+
# @return [String] the value for the specified attribute
|
155
|
+
def [] attribute
|
156
|
+
`#@native.getAttribute(#{attribute})`
|
157
|
+
end
|
158
|
+
|
159
|
+
def query_selector selector
|
160
|
+
result = super
|
161
|
+
|
162
|
+
Element.new(result) if result
|
163
|
+
end
|
164
|
+
|
165
|
+
def query_selector_all selector
|
166
|
+
Iterable.new(super).map { |element| Element.new(element) }
|
167
|
+
end
|
168
|
+
|
169
|
+
# The native representation of this element.
|
170
|
+
#
|
171
|
+
# @return [JS] the native element wrapped by this object.
|
172
|
+
def to_n
|
173
|
+
@native
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Browser
|
2
|
+
class Element
|
3
|
+
element :canvas do
|
4
|
+
def context(type='2d')
|
5
|
+
Context.new(`#@native.getContext(#{type})`)
|
6
|
+
end
|
7
|
+
|
8
|
+
class Context
|
9
|
+
include DelegateNative
|
10
|
+
|
11
|
+
def initialize native
|
12
|
+
@native = native
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Browser
|
2
|
+
class Element
|
3
|
+
element :video, :audio do
|
4
|
+
def buffered
|
5
|
+
TimeRanges.new(`#@native.buffered`)
|
6
|
+
end
|
7
|
+
|
8
|
+
def played
|
9
|
+
TimeRanges.new(`#@native.played`)
|
10
|
+
end
|
11
|
+
|
12
|
+
def seekable
|
13
|
+
TimeRanges.new(`#@native.seekable`)
|
14
|
+
end
|
15
|
+
|
16
|
+
def network_state
|
17
|
+
case `#@native.networkState`
|
18
|
+
when `HTMLMediaElement.NETWORK_EMPTY` then :no_data
|
19
|
+
when `HTMLMediaElement.NETWORK_IDLE` then :idle
|
20
|
+
when `HTMLMediaElement.NETWORK_LOADING` then :loading
|
21
|
+
when `HTMLMediaElement.NETWORK_NO_SOURCE` then :no_source
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
element :video do
|
27
|
+
def fullscreen
|
28
|
+
fullscreen = %w(
|
29
|
+
requestFullScreen
|
30
|
+
requestFullscreen
|
31
|
+
webkitRequestFullScreen
|
32
|
+
webkitRequestFullscreen
|
33
|
+
mozRequestFullScreen
|
34
|
+
msRequestFullscreen
|
35
|
+
).find { |prop| `!!#@native[prop]` }
|
36
|
+
|
37
|
+
if fullscreen
|
38
|
+
`#@native[fullscreen]()`
|
39
|
+
else
|
40
|
+
warn "[#{self.class}] Cannot determine the method to full-screen a video"
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
alias request_fullscreen fullscreen
|
45
|
+
end
|
46
|
+
|
47
|
+
class TimeRanges
|
48
|
+
include Enumerable
|
49
|
+
|
50
|
+
def initialize native
|
51
|
+
@native = native
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_n
|
55
|
+
@native
|
56
|
+
end
|
57
|
+
|
58
|
+
def each
|
59
|
+
`#@native.length`.times do |i|
|
60
|
+
yield TimeRange.new(`#@native.start(i)`, `#@native.end(i)`)
|
61
|
+
end
|
62
|
+
|
63
|
+
self
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class TimeRange
|
68
|
+
attr_reader :start, :end
|
69
|
+
|
70
|
+
def initialize start, _end
|
71
|
+
@start = start
|
72
|
+
@end = _end
|
73
|
+
end
|
74
|
+
|
75
|
+
alias begin start
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Browser
|
2
|
+
# Wrapper for JS events
|
3
|
+
class Event
|
4
|
+
# @param [JS] the native event to wrap
|
5
|
+
def initialize native
|
6
|
+
@native = native
|
7
|
+
end
|
8
|
+
|
9
|
+
# Prevent the runtime from executing this event's default behavior. For
|
10
|
+
# example, prevent navigation after clicking a link.
|
11
|
+
#
|
12
|
+
# @return [Browser::Event] self
|
13
|
+
def prevent
|
14
|
+
`#@native.preventDefault()`
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
# Prevent the runtime from bubbling this event up the hierarchy. This is
|
19
|
+
# typically used to keep an event local to the element on which it was
|
20
|
+
# triggered, such as keeping a click event on a button from unintentionally
|
21
|
+
# triggering a handler on a parent element.
|
22
|
+
#
|
23
|
+
# @return self
|
24
|
+
def stop_propagation
|
25
|
+
`#@native.stopPropagation()`
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] true if `prevent` has been called on this event, false
|
30
|
+
# otherwise
|
31
|
+
def prevented?
|
32
|
+
`#@native.defaultPrevented`
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] true if the Meta/Command/Windows key was pressed when
|
36
|
+
# this event fired, false otherwise
|
37
|
+
def meta?
|
38
|
+
`#@native.metaKey`
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Boolean] true if the Shift key was pressed when this event fired,
|
42
|
+
# false otherwise
|
43
|
+
def shift?
|
44
|
+
`#@native.shiftKey`
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Boolean] true if the Ctrl key was pressed when this event fired,
|
48
|
+
# false otherwise
|
49
|
+
def ctrl?
|
50
|
+
`#@native.ctrlKey`
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Boolean] true if the Alt key was pressed when this event fired,
|
54
|
+
# false otherwise
|
55
|
+
def alt?
|
56
|
+
`#@native.altKey`
|
57
|
+
end
|
58
|
+
|
59
|
+
# The target for this event
|
60
|
+
#
|
61
|
+
# @return [Browser::Element] the element on which this event was triggered
|
62
|
+
# @todo Handle non-DOM events here
|
63
|
+
def target
|
64
|
+
Element.new(`#@native.target`)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Numeric] the key code associated with this event. Only useful for
|
68
|
+
# keyboard-based events.
|
69
|
+
def code
|
70
|
+
`#@native.keyCode`
|
71
|
+
end
|
72
|
+
|
73
|
+
# Return properties on the event not covered by Ruby methods.
|
74
|
+
def method_missing name, *args
|
75
|
+
property = name.gsub(/_[a-z]/) { |match| match[-1, 1].upcase }
|
76
|
+
value = `#@native[property]`
|
77
|
+
|
78
|
+
if `!!value && #{Proc === value}`
|
79
|
+
value.call(*args)
|
80
|
+
elsif `value == null`
|
81
|
+
nil
|
82
|
+
else
|
83
|
+
value
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [JS] the native event wrapped by this object.
|
88
|
+
def to_n
|
89
|
+
@native
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|