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,39 @@
1
+ module Browser
2
+ module EventTarget
3
+ # Add the block as a handler for the specified event name. Will use either
4
+ # `addEventListener` or `addListener` if they exist.
5
+ #
6
+ # @param event_name [String] the name of the event
7
+ # @return [Proc] the block to pass to `off` to remove this handler
8
+ # @yieldparam event [Browser::Event] the event object
9
+ def on event_name, &block
10
+ wrapper = proc { |event| block.call Event.new(event) }
11
+
12
+ if `#@native.addEventListener !== undefined`
13
+ `#@native.addEventListener(event_name, wrapper)`
14
+ elsif `#@native.addListener !== undefined`
15
+ `#@native.addListener(event_name, wrapper)`
16
+ else
17
+ warn "[Browser] Not entirely sure how to add an event listener to #{self}"
18
+ end
19
+
20
+ wrapper
21
+ end
22
+
23
+ # Remove an event handler
24
+ #
25
+ # @param event_name [String] the name of the event
26
+ # @block the handler to remove, as returned from `on`
27
+ def off event_name, &block
28
+ if `#@native.removeEventListener !== undefined`
29
+ `#@native.removeEventListener(event_name, block)`
30
+ elsif `#@native.removeListener !== undefined`
31
+ `#@native.removeListener(event_name, block)`
32
+ else
33
+ warn "[Browser] Not entirely sure how to remove an event listener from #{self}"
34
+ end
35
+
36
+ nil
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,125 @@
1
+ module Browser
2
+ class FileList
3
+ include Enumerable
4
+
5
+ # @param native [JS] the native FileList object to wrap
6
+ def initialize native
7
+ @native = `#{native} || []`
8
+ @files = length.times.each_with_object([]) { |index, array|
9
+ array[index] = File.new(`#@native[index]`)
10
+ }
11
+ end
12
+
13
+ # @param index [Integer] the index of the file in the list
14
+ # @return [Browser::FileList::File] the file at the specified index
15
+ def [] index
16
+ @files[index]
17
+ end
18
+
19
+ # @return [Integer] the number of files in this list
20
+ def length
21
+ `#@native.length`
22
+ end
23
+ alias size length
24
+
25
+ # Call the given block for each file in the list
26
+ #
27
+ # @yieldparam file [Browser::FileList::File]
28
+ def each &block
29
+ @files.each do |file|
30
+ block.call file
31
+ end
32
+ end
33
+
34
+ # Convert this FileList into an array
35
+ def to_a
36
+ @files.dup # Don't return a value that can mutate our internal state
37
+ end
38
+ alias to_ary to_a
39
+
40
+ # @return [String] a string representation of this FileList
41
+ def to_s
42
+ @files.to_s
43
+ end
44
+
45
+ # An individual item in a FileList
46
+ class File
47
+ attr_reader :data
48
+
49
+ # @param native [JS] the native File object to wrap
50
+ def initialize native
51
+ @native = native
52
+ @data = nil
53
+ end
54
+
55
+ # @return [String] the filename
56
+ def name
57
+ `#@native.name`
58
+ end
59
+
60
+ # @return [Integer] the size of this file on disk
61
+ def size
62
+ `#@native.size`
63
+ end
64
+
65
+ # @return [String] the MIME type of the file, detected by the browser
66
+ def type
67
+ `#@native.type`
68
+ end
69
+
70
+ # @return [Time] the timestamp of the file
71
+ def last_modified
72
+ `#@native.lastModifiedDate`
73
+ end
74
+
75
+ # Read the file from disk into memory
76
+ #
77
+ # @return [Promise] a promise that resolves when finished loading and
78
+ # rejects if an error occurs while loading.
79
+ def read
80
+ promise = Promise.new
81
+ reader = FileReader.new
82
+ reader.on :load do
83
+ result = reader.result
84
+
85
+ @data = result
86
+ promise.resolve result
87
+ end
88
+
89
+ reader.on :error do
90
+ promise.reject reader.result
91
+ end
92
+
93
+ reader.read_as_binary_string self
94
+
95
+ promise
96
+ end
97
+
98
+ # Convert to the native object
99
+ #
100
+ # @return [JS.HTMLElement] the underlying native element
101
+ def to_n
102
+ @native
103
+ end
104
+
105
+ # The object that reads the file from disk.
106
+ #
107
+ # @api private
108
+ class FileReader
109
+ include EventTarget
110
+
111
+ def initialize
112
+ @native = `new FileReader()`
113
+ end
114
+
115
+ def result
116
+ `#@native.result`
117
+ end
118
+
119
+ def read_as_binary_string file
120
+ `#@native.readAsBinaryString(#{file.to_n})`
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,15 @@
1
+ module Browser
2
+ class Iterable
3
+ include Enumerable
4
+
5
+ def initialize js_iterable
6
+ @js_iterable = js_iterable
7
+ end
8
+
9
+ def each
10
+ `#@js_iterable.length`.times do |i|
11
+ yield `#@js_iterable[i]`
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'isomorfeus-react'
2
+
3
+ # LucidMaterial::Component
4
+ require 'lucid_material/component/native_component_constructor'
5
+ require 'lucid_material/component/mixin'
6
+ require 'lucid_material/component/base'
7
+ # LucidMaterial::App
8
+ require 'lucid_material/app/native_component_constructor'
9
+ require 'lucid_material/app/mixin'
10
+ require 'lucid_material/app/base'
@@ -0,0 +1,145 @@
1
+ if RUBY_ENGINE == 'opal'
2
+ require 'opal'
3
+ require 'opal-autoloader'
4
+ require 'native'
5
+ require 'promise'
6
+ require 'active_support/core_ext/string'
7
+ require 'react/active_support_support'
8
+ require 'isomorfeus-redux'
9
+
10
+ if Isomorfeus.on_browser?
11
+ require 'browser/event'
12
+ require 'browser/event_target'
13
+ require 'browser/delegate_native'
14
+ require 'browser/element'
15
+ end
16
+
17
+ require 'isomorfeus/config'
18
+
19
+ # allow mounting of components
20
+ if Isomorfeus.on_browser?
21
+ require 'isomorfeus/top_level'
22
+ else
23
+ require 'isomorfeus/top_level_ssr'
24
+ end
25
+
26
+ # react
27
+ require 'react/version'
28
+ require 'react'
29
+ require 'react/synthetic_event'
30
+ require 'react/ref'
31
+ require 'react/children'
32
+ if Isomorfeus.on_browser?
33
+ require 'react_dom'
34
+ else
35
+ require 'react_dom_server'
36
+ end
37
+
38
+ # props
39
+ require 'isomorfeus/props/validate_hash_proxy'
40
+ require 'isomorfeus/props/validator'
41
+ require 'lucid_prop_declaration/mixin'
42
+ require 'react/component/props'
43
+
44
+ # HTML Elements support
45
+ require 'react/component/elements'
46
+
47
+ # React Features
48
+ require 'react/component/features'
49
+ require 'react/context_wrapper'
50
+ require 'react/native_constant_wrapper'
51
+
52
+ # Function Component
53
+ require 'react/function_component/resolution'
54
+ require 'react/function_component/api'
55
+ require 'react/function_component/event_handler'
56
+ require 'react/function_component/creator'
57
+ require 'react/function_component/mixin'
58
+ require 'react/function_component/base'
59
+ require 'react/memo_component/creator'
60
+ require 'react/memo_component/mixin'
61
+ require 'react/memo_component/base'
62
+
63
+ # React::Component
64
+ require 'react/component/api'
65
+ require 'react/component/callbacks'
66
+ # require 'react/component/unsafe_api'
67
+ require 'react/component/initializer'
68
+ require 'react/component/native_component_constructor'
69
+ require 'react/component/state'
70
+ require 'react/component/match'
71
+ require 'react/component/location'
72
+ require 'react/component/history'
73
+ require 'react/component/resolution'
74
+ require 'react/component/should_component_update'
75
+ require 'react/component/event_handler'
76
+ require 'react/component/styles'
77
+ require 'react/component/mixin'
78
+ require 'react/component/base'
79
+
80
+ # React::PureComponent
81
+ require 'react/pure_component/mixin'
82
+ require 'react/pure_component/base'
83
+
84
+ # init component reducers
85
+ require 'lucid_component/reducers'
86
+ LucidComponent::Reducers.add_component_reducers_to_store
87
+
88
+ # init LucidApplicationContext (Store Provider and Consumer)
89
+ require 'lucid_app/context'
90
+ LucidApp::Context.create_application_context
91
+
92
+ # LucidComponent
93
+ require 'lucid_component/styles_support'
94
+ require 'lucid_component/store_api'
95
+ require 'lucid_component/app_store_defaults'
96
+ require 'lucid_component/component_class_store_defaults'
97
+ require 'lucid_component/component_instance_store_defaults'
98
+ require 'lucid_component/app_store_proxy'
99
+ require 'lucid_component/class_store_proxy'
100
+ require 'lucid_component/instance_store_proxy'
101
+ require 'lucid_component/initializer'
102
+ require 'lucid_component/native_component_constructor'
103
+ require 'lucid_component/event_handler'
104
+ require 'lucid_component/mixin'
105
+ require 'lucid_component/base'
106
+
107
+ # LucidApp
108
+ require 'lucid_app/api'
109
+ require 'lucid_app/native_component_constructor'
110
+ require 'lucid_app/mixin'
111
+ require 'lucid_app/base'
112
+
113
+ Opal::Autoloader.add_load_path('components')
114
+ else
115
+ require 'oj'
116
+ require 'opal'
117
+ require 'opal-activesupport'
118
+ require 'opal-autoloader'
119
+ require 'isomorfeus-redux'
120
+ require 'isomorfeus-speednode'
121
+ require 'react/version'
122
+ require 'isomorfeus/config'
123
+
124
+ # props
125
+ require 'isomorfeus/props/validate_hash_proxy'
126
+ require 'isomorfeus/props/validator'
127
+ require 'lucid_prop_declaration/mixin'
128
+
129
+ Isomorfeus.env = ENV['RACK_ENV']
130
+
131
+ if Isomorfeus.production? || Isomorfeus.test?
132
+ Isomorfeus.server_side_rendering = true
133
+ else
134
+ Isomorfeus.server_side_rendering = false
135
+ end
136
+
137
+ require 'isomorfeus/execution_environment'
138
+ require 'isomorfeus/react_view_helper'
139
+
140
+ Opal.append_path(__dir__.untaint)
141
+
142
+ if Dir.exist?('isomorfeus')
143
+ Opal.append_path(File.expand_path('isomorfeus')) unless Opal.paths.include?(File.expand_path('isomorfeus'))
144
+ end
145
+ end
@@ -0,0 +1,130 @@
1
+ module Isomorfeus
2
+ if RUBY_ENGINE == 'opal'
3
+ class << self
4
+ attr_accessor :initial_state_fetched
5
+ attr_accessor :top_component
6
+ attr_accessor :ssr_response_status
7
+ attr_reader :initialized
8
+ attr_reader :env
9
+
10
+ def init
11
+ return if initialized
12
+ @initialized = true
13
+ Isomorfeus.init_store
14
+ execute_init_classes
15
+ end
16
+
17
+ def force_init!
18
+ unless Isomorfeus.initial_state_fetched
19
+ Isomorfeus.initial_state_fetched = true
20
+ Redux::Store.preloaded_state = Isomorfeus.store.get_state
21
+ end
22
+ Isomorfeus.force_init_store!
23
+ execute_init_classes
24
+ end
25
+
26
+ def add_client_init_class_name(init_class_name)
27
+ client_init_class_names << init_class_name
28
+ end
29
+
30
+ def add_client_option(key, value = nil)
31
+ self.class.attr_accessor(key)
32
+ self.send("#{key}=", value)
33
+ end
34
+
35
+ # only used for SSR
36
+ def cached_component_classes
37
+ @cached_component_classes ||= {}
38
+ end
39
+
40
+ # only used for SSR
41
+ def cached_component_class(class_name)
42
+ return cached_component_classes[class_name] if cached_component_classes.key?(class_name)
43
+ cached_component_classes[class_name] = "::#{class_name}".constantize
44
+ end
45
+
46
+ def execute_init_classes
47
+ client_init_class_names.each do |constant|
48
+ constant.constantize.send(:init)
49
+ end
50
+ end
51
+
52
+ def env=(env_string)
53
+ @env = env_string ? env_string.to_s : 'development'
54
+ @development = (@env == 'development') ? true : false
55
+ @production = (@env == 'production') ? true : false
56
+ @test = (@env == 'test') ? true : false
57
+ end
58
+
59
+ def development?
60
+ @development
61
+ end
62
+
63
+ def production?
64
+ @production
65
+ end
66
+
67
+ def test?
68
+ @test
69
+ end
70
+
71
+ def start_app!
72
+ Isomorfeus::TopLevel.mount!
73
+ end
74
+
75
+ def force_render
76
+ begin
77
+ if Isomorfeus.top_component
78
+ ReactDOM.find_dom_node(Isomorfeus.top_component) # if not mounted will raise
79
+ if `typeof Opal.global.deepForceUpdate === 'undefined'`
80
+ Isomorfeus.top_component.JS.forceUpdate()
81
+ else
82
+ `Opal.global.deepForceUpdate(#{Isomorfeus.top_component})`
83
+ end
84
+ end
85
+ rescue
86
+ `location.reload()` if on_browser?
87
+ end
88
+ nil
89
+ end
90
+ end
91
+
92
+ self.add_client_option(:client_init_class_names, [])
93
+ else
94
+ class << self
95
+ attr_accessor :server_side_rendering
96
+ attr_reader :env
97
+
98
+ def configuration(&block)
99
+ block.call(self)
100
+ end
101
+
102
+ def env=(env_string)
103
+ @env = env_string ? env_string.to_s : 'development'
104
+ @development = (@env == 'development') ? true : false
105
+ @production = (@env == 'production') ? true : false
106
+ @test = (@env == 'test') ? true : false
107
+ end
108
+
109
+ def development?
110
+ @development
111
+ end
112
+
113
+ def production?
114
+ @production
115
+ end
116
+
117
+ def test?
118
+ @test
119
+ end
120
+
121
+ def ssr_contexts
122
+ @ssr_contexts ||= {}
123
+ end
124
+
125
+ def version
126
+ Isomorfeus::VERSION
127
+ end
128
+ end
129
+ end
130
+ end