isomorfeus-react 16.10.0 → 16.10.1

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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +64 -0
  3. data/lib/browser/delegate_native.rb +70 -0
  4. data/lib/browser/element.rb +176 -0
  5. data/lib/browser/element/canvas.rb +17 -0
  6. data/lib/browser/element/media.rb +78 -0
  7. data/lib/browser/event.rb +92 -0
  8. data/lib/browser/event_target.rb +39 -0
  9. data/lib/browser/file_list.rb +125 -0
  10. data/lib/browser/iterable.rb +15 -0
  11. data/lib/isomorfeus-react-material-ui.rb +10 -0
  12. data/lib/isomorfeus-react.rb +145 -0
  13. data/lib/isomorfeus/config.rb +130 -0
  14. data/lib/isomorfeus/props/validate_hash_proxy.rb +178 -0
  15. data/lib/isomorfeus/props/validator.rb +131 -0
  16. data/lib/isomorfeus/react_view_helper.rb +130 -0
  17. data/lib/isomorfeus/top_level.rb +86 -0
  18. data/lib/isomorfeus/top_level_ssr.rb +28 -0
  19. data/lib/lucid_app/api.rb +30 -0
  20. data/lib/lucid_app/base.rb +7 -0
  21. data/lib/lucid_app/context.rb +7 -0
  22. data/lib/lucid_app/mixin.rb +20 -0
  23. data/lib/lucid_app/native_component_constructor.rb +105 -0
  24. data/lib/lucid_component/app_store_defaults.rb +36 -0
  25. data/lib/lucid_component/app_store_proxy.rb +38 -0
  26. data/lib/lucid_component/base.rb +7 -0
  27. data/lib/lucid_component/class_store_proxy.rb +41 -0
  28. data/lib/lucid_component/component_class_store_defaults.rb +38 -0
  29. data/lib/lucid_component/component_instance_store_defaults.rb +35 -0
  30. data/lib/lucid_component/event_handler.rb +17 -0
  31. data/lib/lucid_component/initializer.rb +12 -0
  32. data/lib/lucid_component/instance_store_proxy.rb +45 -0
  33. data/lib/lucid_component/mixin.rb +18 -0
  34. data/lib/lucid_component/native_component_constructor.rb +116 -0
  35. data/lib/lucid_component/reducers.rb +48 -0
  36. data/lib/lucid_component/store_api.rb +38 -0
  37. data/lib/lucid_component/styles_support.rb +37 -0
  38. data/lib/lucid_material/app/base.rb +9 -0
  39. data/lib/lucid_material/app/mixin.rb +22 -0
  40. data/lib/lucid_material/app/native_component_constructor.rb +107 -0
  41. data/lib/lucid_material/component/base.rb +9 -0
  42. data/lib/lucid_material/component/mixin.rb +20 -0
  43. data/lib/lucid_material/component/native_component_constructor.rb +118 -0
  44. data/lib/lucid_prop_declaration/mixin.rb +91 -0
  45. data/lib/react.rb +195 -0
  46. data/lib/react/active_support_support.rb +13 -0
  47. data/lib/react/children.rb +35 -0
  48. data/lib/react/component/api.rb +80 -0
  49. data/lib/react/component/base.rb +9 -0
  50. data/lib/react/component/callbacks.rb +106 -0
  51. data/lib/react/component/elements.rb +60 -0
  52. data/lib/react/component/event_handler.rb +19 -0
  53. data/lib/react/component/features.rb +47 -0
  54. data/lib/react/component/history.rb +36 -0
  55. data/lib/react/component/initializer.rb +11 -0
  56. data/lib/react/component/location.rb +15 -0
  57. data/lib/react/component/match.rb +31 -0
  58. data/lib/react/component/mixin.rb +19 -0
  59. data/lib/react/component/native_component_constructor.rb +93 -0
  60. data/lib/react/component/props.rb +59 -0
  61. data/lib/react/component/resolution.rb +70 -0
  62. data/lib/react/component/should_component_update.rb +14 -0
  63. data/lib/react/component/state.rb +52 -0
  64. data/lib/react/component/styles.rb +27 -0
  65. data/lib/react/component/unsafe_api.rb +33 -0
  66. data/lib/react/context_wrapper.rb +46 -0
  67. data/lib/react/function_component/api.rb +63 -0
  68. data/lib/react/function_component/base.rb +9 -0
  69. data/lib/react/function_component/creator.rb +32 -0
  70. data/lib/react/function_component/event_handler.rb +13 -0
  71. data/lib/react/function_component/mixin.rb +14 -0
  72. data/lib/react/function_component/resolution.rb +62 -0
  73. data/lib/react/memo_component/base.rb +9 -0
  74. data/lib/react/memo_component/creator.rb +32 -0
  75. data/lib/react/memo_component/mixin.rb +14 -0
  76. data/lib/react/native_constant_wrapper.rb +26 -0
  77. data/lib/react/pure_component/base.rb +9 -0
  78. data/lib/react/pure_component/mixin.rb +18 -0
  79. data/lib/react/ref.rb +13 -0
  80. data/lib/react/synthetic_event.rb +53 -0
  81. data/lib/react/version.rb +3 -0
  82. data/lib/react_dom.rb +47 -0
  83. data/lib/react_dom_server.rb +19 -0
  84. metadata +84 -2
@@ -0,0 +1,14 @@
1
+ module React
2
+ module Component
3
+ module ShouldComponentUpdate
4
+ def self.extended(base)
5
+ base.define_singleton_method(:should_component_update?) do |&block|
6
+ `base.has_custom_should_component_update = true`
7
+ define_method(:should_component_update) do |next_props, next_state|
8
+ !!block.call(Hash.new(next_props), Hash.new(next_state))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ module React
2
+ module Component
3
+ class State
4
+ include ::Native::Wrapper
5
+
6
+ def method_missing(key, *args, &block)
7
+ if `args.length > 0`
8
+ new_state = `{}`
9
+ new_state.JS[(`key.endsWith('=')` ? key.chop : key)] = args[0]
10
+ if block_given?
11
+ @native.JS.setState(new_state, `function() { block.$call(); }`)
12
+ else
13
+ @native.JS.setState(new_state, `null`)
14
+ end
15
+ else
16
+ return nil if `typeof #@native.state[key] == "undefined"`
17
+ @native.JS[:state].JS[key]
18
+ end
19
+ end
20
+
21
+ def set_state(updater, &block)
22
+ new_state = `{}`
23
+ updater.keys.each do |key|
24
+ new_state.JS[key] = updater[key]
25
+ end
26
+ if block_given?
27
+ @native.JS.setState(new_state, `function() { block.$call(); }`)
28
+ else
29
+ @native.JS.setState(new_state, `null`)
30
+ end
31
+ end
32
+
33
+ def size
34
+ `Object.keys(#@native.state).length`;
35
+ end
36
+
37
+ def to_n
38
+ %x{
39
+ var new_native = {};
40
+ for (var key in #@native.state) {
41
+ if (typeof #@native.state[key].$to_n !== "undefined") {
42
+ new_native[key] = #@native.state[key].$to_n();
43
+ } else {
44
+ new_native[key] = #@native.state[key];
45
+ }
46
+ }
47
+ return new_native;
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ module React
2
+ module Component
3
+ class Styles
4
+ def initialize(native)
5
+ @native = native
6
+ end
7
+
8
+ def method_missing(prop, *args, &block)
9
+ %x{
10
+ if (!#@native || typeof #@native[prop] === 'undefined') { return #{nil}; }
11
+ let value = #@native[prop];
12
+ if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) { return value; }
13
+ if (typeof value === 'function') { return #{Proc.new { `value()` }} }
14
+ return Opal.React.Component.Styles.$new(value);
15
+ }
16
+ end
17
+
18
+ def to_h
19
+ `Opal.Hash.$new(#@native)`
20
+ end
21
+
22
+ def to_n
23
+ @native
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module React
2
+ module Component
3
+ module UnsafeAPI
4
+ def self.included(base)
5
+ base.instance_exec do
6
+ def unsafe_component_will_mount(&block)
7
+ %x{
8
+ self.react_component.prototype.UNSAFE_componentWillMount = function() {
9
+ return #{`this.__ruby_instance`.instance_exec(&block)};
10
+ }
11
+ }
12
+ end
13
+
14
+ def unsafe_component_will_receive_props(&block)
15
+ %x{
16
+ self.react_component.prototype.UNSAFE_componentWillReceiveProps = function(next_props) {
17
+ return #{`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), &block)};
18
+ }
19
+ }
20
+ end
21
+
22
+ def unsafe_component_will_update(&block)
23
+ %x{
24
+ self.react_component.prototype.UNSAFE_componentWillUpdate = function(next_props, next_state) {
25
+ return #{`this.__ruby_instance`.instance_exec(React::Component::Props.new(`{props: next_props}`), `Opal.Hash.$new(next_state)`, &block)};
26
+ }
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ module React
2
+ class ContextWrapper
3
+ include ::Native::Wrapper
4
+
5
+ def is_wrapped_context
6
+ true
7
+ end
8
+
9
+ def Consumer(*args, &block)
10
+ %x{
11
+ let children = null;
12
+ let props = null;
13
+
14
+ if (args.length > 0) { props = Opal.React.to_native_react_props(args[0]); }
15
+
16
+ let react_element = Opal.global.React.createElement(this.native.Consumer, props, function(value) {
17
+ if (block !== nil) {
18
+ Opal.React.render_buffer.push([]);
19
+ let block_result = block.$call();
20
+ let last_buffer_length = Opal.React.render_buffer[Opal.React.render_buffer.length - 1].length;
21
+ let last_buffer_element = Opal.React.render_buffer[Opal.React.render_buffer.length - 1][last_buffer_length - 1];
22
+ if (block_result && block_result !== last_buffer_element && (block_result !== nil && (typeof block_result === "string" || typeof block_result.$$typeof === "symbol" ||
23
+ (typeof block_result.constructor !== "undefined" && block_result.constructor === Array && block_result[0] && typeof block_result[0].$$typeof === "symbol")
24
+ ))) {
25
+ Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(block_result);
26
+ }
27
+ children = Opal.React.render_buffer.pop();
28
+ if (children.length == 1) { children = children[0]; }
29
+ else if (children.length == 0) { children = null; }
30
+ }
31
+ return Opal.React.render_buffer.pop();
32
+ });
33
+ Opal.React.render_buffer[Opal.React.render_buffer.length - 1].push(react_element);
34
+ return null;
35
+ }
36
+ end
37
+
38
+ def Provider(*args, &block)
39
+ %x{
40
+ var props = null;
41
+ if (args.length > 0) { props = Opal.React.to_native_react_props(args[0]); }
42
+ Opal.React.internal_render(this.native.Provider, props, null, block);
43
+ }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,63 @@
1
+ module React
2
+ module FunctionComponent
3
+ module API
4
+ attr_accessor :props
5
+
6
+ def initialize(props)
7
+ @props = ::React::Component::Props.new(`{props: props}`)
8
+ end
9
+
10
+ def use_callback(deps, &block)
11
+ `Opal.global.React.useCallback(function() { #{block.call} }, deps)`
12
+ end
13
+
14
+ def use_context(context)
15
+ `(typeof context.$is_wrapped_context !== 'undefined')` ? context.to_n : context
16
+ `Opal.global.React.useContext(native_context)`
17
+ end
18
+
19
+ def use_debug_value(value)
20
+ `Opal.global.React.useDebugValue(value)`
21
+ end
22
+
23
+ def use_effect(&block)
24
+ `Opal.global.React.useEffect(function() { #{block.call} })`
25
+ end
26
+
27
+ def use_imperative_handle(ref, *deps, &block)
28
+ native_ref = `(typeof ref.$is_wrapped_ref !== 'undefined')` ? ref.to_n : ref
29
+ `Opal.global.React.useImperativeHandle(native_ref, function() { #{block.call} }, deps)`
30
+ end
31
+
32
+ def use_layout_effect(&block)
33
+ `Opal.global.React.useLayoutEffect(function() { #{block.call} })`
34
+ end
35
+
36
+ def use_memo(*deps, &block)
37
+ `Opal.global.React.useMemo(function() { #{block.call} }, deps)`
38
+ end
39
+
40
+ def use_reducer(inital_state, &block)
41
+ state = nil
42
+ dispatcher = nil
43
+ %x{
44
+ [state, dispatcher] = Opal.global.React.useReducer(function(state, action) {
45
+ #{block.call(state, action)}
46
+ }, initial_state);
47
+ }
48
+ [state, proc { |arg| `dispatcher(arg)` }]
49
+ end
50
+
51
+ def use_ref(initial_value)
52
+ React::Ref.new(`Opal.global.React.useRef(initial_value)`)
53
+ end
54
+
55
+ def use_state(initial_value)
56
+ initial = nil
57
+ setter = nil
58
+ `[initial, setter] = Opal.global.React.useState(initial_value);`
59
+ [initial, proc { |arg| `setter(arg)` }]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ module React
2
+ module FunctionComponent
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::React::FunctionComponent::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ module React
2
+ module FunctionComponent
3
+ module Creator
4
+ def self.extended(base)
5
+ %x{
6
+ base.react_component = function(props) {
7
+ Opal.React.render_buffer.push([]);
8
+ Opal.React.active_components.push(base);
9
+ #{base.new(`props`).instance_exec(&`base.function_block`)};
10
+ Opal.React.active_components.pop();
11
+ return Opal.React.render_buffer.pop();
12
+ }
13
+ }
14
+
15
+ base_module = base.to_s.deconstantize
16
+ if base_module != ''
17
+ base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
18
+ `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
19
+ end
20
+ else
21
+ Object.define_method(base.to_s) do |*args, &block|
22
+ `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
23
+ end
24
+ end
25
+
26
+ def create_function(&block)
27
+ `base.function_block = #{block}`
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module React
2
+ module FunctionComponent
3
+ module EventHandler
4
+ def event_handler(name, &block)
5
+ define_method(name) do |event, info|
6
+ ruby_event = ::React::SyntheticEvent.new(event)
7
+ block.call(ruby_event, info)
8
+ end
9
+ `self[name] = self.prototype['$' + name]`
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module React
2
+ module FunctionComponent
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::React::Component::Elements)
6
+ base.include(::React::Component::Features)
7
+ base.include(::React::FunctionComponent::API)
8
+ base.include(::React::FunctionComponent::Resolution)
9
+ base.extend(::React::FunctionComponent::EventHandler)
10
+ base.extend(::React::FunctionComponent::Creator)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,62 @@
1
+ module React
2
+ module FunctionComponent
3
+ module Resolution
4
+ def self.included(base)
5
+ base.instance_exec do
6
+ alias _react_function_component_resolution_original_const_missing const_missing
7
+
8
+ def const_missing(const_name)
9
+ # language=JS
10
+ %x{
11
+ if (typeof Opal.global[const_name] === "object") {
12
+ var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
13
+ #{Object.const_set(const_name, `new_const`)};
14
+ return new_const;
15
+ } else {
16
+ return #{_react_function_component_resolution_original_const_missing(const_name)};
17
+ }
18
+ }
19
+ end
20
+ end
21
+ end
22
+
23
+ alias _react_function_component_resolution_original_method_missing method_missing
24
+
25
+ def method_missing(component_name, *args, &block)
26
+ # html tags are defined as methods, so they will not end up here.
27
+ # first check for native component and render it, we want to be fast for native components
28
+ # second check for ruby component and render it, they are a bit slower anyway
29
+ # third pass on method missing
30
+ # language=JS
31
+ %x{
32
+ var component = null;
33
+ var component_type = typeof Opal.global[component_name];
34
+ if (component_type === "function" || component_type === "object") {
35
+ component = Opal.global[component_name];
36
+ }
37
+ else {
38
+ try {
39
+ var constant = self.$class().$const_get(component_name, true);
40
+ if (typeof constant.react_component !== 'undefined') {
41
+ component = constant.react_component;
42
+ }
43
+ } catch(err) { component = null; }
44
+ }
45
+ if (!component) {
46
+ try {
47
+ constant = Opal.Object.$const_get(component_name);
48
+ if (typeof constant.react_component !== 'undefined') {
49
+ component = constant.react_component;
50
+ }
51
+ } catch(err) { component = null; }
52
+ }
53
+ if (component) {
54
+ return Opal.React.internal_prepare_args_and_render(component, args, block);
55
+ } else {
56
+ return #{_react_function_component_resolution_original_method_missing(component_name, *args, block)};
57
+ }
58
+ }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ module React
2
+ module MemoComponent
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::React::MemoComponent::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ module React
2
+ module MemoComponent
3
+ module Creator
4
+ def self.extended(base)
5
+ %x{
6
+ base.equality_checker = null;
7
+ base.react_component = Opal.global.React.memo(function(props) {
8
+ Opal.React.render_buffer.push([]);
9
+ Opal.React.active_components.push(base);
10
+ #{base.new(`props`).instance_exec(&`base.function_block`)};
11
+ Opal.React.active_components.pop();
12
+ return Opal.React.render_buffer.pop();
13
+ }, base.equality_checker);
14
+ }
15
+
16
+ def props_are_equal?(&block)
17
+ %x{
18
+ base.equality_checker = function (prev_props, next_props) {
19
+ var prev_ruby_props = Opal.React.Component.Props.$new({props: prev_props});
20
+ var next_ruby_props = Opal.React.Component.Props.$new({props: next_props});
21
+ return #{base.new(`{}`).instance_exec(`prev_ruby_props`, `next_ruby_props`, &block)};
22
+ }
23
+ }
24
+ end
25
+
26
+ def create_memo(&block)
27
+ `base.function_block = #{block}`
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module React
2
+ module MemoComponent
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::React::Component::Elements)
6
+ base.include(::React::Component::Features)
7
+ base.include(::React::FunctionComponent::API)
8
+ base.include(::React::FunctionComponent::Resolution)
9
+ base.extend(::React::FunctionComponent::EventHandler)
10
+ base.extend(::React::MemoComponent::Creator)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module React
2
+ class NativeConstantWrapper
3
+ include ::Native::Wrapper
4
+
5
+ def initialize(native, const_name)
6
+ @native = native
7
+ @const_name = const_name
8
+ end
9
+
10
+ def method_missing(name, *args, &block)
11
+ # language=JS
12
+ %x{
13
+ var component = null;
14
+ var component_type = typeof #@native[name];
15
+ if (component_type === "function" || component_type === "object") {
16
+ component = #@native[name];
17
+ }
18
+ if (component) {
19
+ return Opal.React.internal_prepare_args_and_render(component, args, block);
20
+ } else {
21
+ #{raise NameError, "No such native Component #@const_name.#{name}"};
22
+ }
23
+ }
24
+ end
25
+ end
26
+ end