isomorfeus-preact 10.6.46 → 10.6.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/history.rb +31 -0
- data/lib/isomorfeus/preact/config.rb +3 -2
- data/lib/isomorfeus/preact_view_helper.rb +19 -24
- data/lib/isomorfeus/ssr.rb +49 -30
- data/lib/isomorfeus/top_level.rb +8 -2
- data/lib/isomorfeus-preact.rb +4 -1
- data/lib/isomorfeus_preact/preact/function_component/api.rb +12 -7
- data/lib/preact/component/api.rb +12 -7
- data/lib/preact/component/callbacks.rb +32 -25
- data/lib/preact/version.rb +1 -1
- data/lib/preact.rb +3 -3
- data/node_modules/.package-lock.json +3 -3
- data/node_modules/preact-render-to-string/README.md +1 -1
- data/node_modules/preact-render-to-string/dist/commonjs.js +1 -1
- data/node_modules/preact-render-to-string/dist/commonjs.js.map +1 -1
- data/node_modules/preact-render-to-string/dist/index.js.map +1 -1
- data/node_modules/preact-render-to-string/dist/index.mjs +1 -1
- data/node_modules/preact-render-to-string/dist/index.module.js +1 -1
- data/node_modules/preact-render-to-string/dist/index.module.js.map +1 -1
- data/node_modules/preact-render-to-string/dist/jsx-entry.js +1 -1
- data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +1 -1
- data/node_modules/preact-render-to-string/dist/jsx.js.map +1 -1
- data/node_modules/preact-render-to-string/dist/jsx.mjs +1 -1
- data/node_modules/preact-render-to-string/dist/jsx.modern.js +1 -1
- data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +1 -1
- data/node_modules/preact-render-to-string/dist/jsx.module.js +1 -1
- data/node_modules/preact-render-to-string/dist/jsx.module.js.map +1 -1
- data/node_modules/preact-render-to-string/package.json +5 -2
- data/node_modules/preact-render-to-string/src/index.js +7 -5
- data/package.json +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac176b7d030eed4294beeb72b72652408b2270d22a0bb9a840b2e7e6e54a503e
|
4
|
+
data.tar.gz: 02d28d07b2ea5051493bd26a986299ddc26bce85dfbef06a2693a2b5680065e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f88f2d320dd5e3cb866607e91de65ddeb565df8aab74162d72d0c8b239c95548db9612df2c62948011646677469707682ebdfa71fc7d9c53775d1cd0083f70f
|
7
|
+
data.tar.gz: 691d9f6cd7e681cdbc402bcb16448f77c742ae0021bbb6f409d896042df6e3e3563d8c772bcbb6cac3ba82aa4f2bea88d8d6f0358dc8bd4dad29b03554317d1d
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Browser
|
2
|
+
class History
|
3
|
+
include Native::Wrapper
|
4
|
+
|
5
|
+
alias_native :back
|
6
|
+
alias_native :forward
|
7
|
+
alias_native :go
|
8
|
+
|
9
|
+
native_reader :length
|
10
|
+
|
11
|
+
def push_state(state, title = '', url = `null`)
|
12
|
+
`#@native.pushState(#{state.to_n}, #{title}, #{url})`
|
13
|
+
end
|
14
|
+
|
15
|
+
def replace_state(state, title = '', url = `null`)
|
16
|
+
`#@native.replaceState(#{state.to_n}, #{title}, #{url})`
|
17
|
+
end
|
18
|
+
|
19
|
+
def scroll_restoration
|
20
|
+
`#@native.scrollRestoration`
|
21
|
+
end
|
22
|
+
|
23
|
+
def scroll_restoration=(s)
|
24
|
+
`#@native.scrollRestoration = #{s}`
|
25
|
+
end
|
26
|
+
|
27
|
+
def state
|
28
|
+
::Hash.new(`#@native.state`)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
if RUBY_ENGINE == 'opal'
|
3
3
|
class << self
|
4
|
+
attr_accessor :browser_history
|
4
5
|
attr_accessor :current_user_sid
|
5
6
|
attr_accessor :initial_state_fetched
|
6
7
|
attr_accessor :top_component
|
@@ -42,8 +43,8 @@ module Isomorfeus
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def execute_init_after_store_classes
|
45
|
-
client_init_after_store_class_names.each do |
|
46
|
-
|
46
|
+
client_init_after_store_class_names.each do |constant_name|
|
47
|
+
constant_name.constantize.send(:init)
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -51,7 +51,7 @@ module Isomorfeus
|
|
51
51
|
# build javascript for rendering first pass
|
52
52
|
# it will initialize buffers to guard against leaks, maybe caused by previous exceptions
|
53
53
|
javascript = <<~JAVASCRIPT
|
54
|
-
return Opal.Isomorfeus.SSR.first_pass('#{Thread.current[:isomorfeus_session_id]}', '#{Isomorfeus.env}', '#{props[:locale]}', '#{props[:location]}', '#{
|
54
|
+
return Opal.Isomorfeus.SSR.first_pass('#{Thread.current[:isomorfeus_session_id]}', '#{Isomorfeus.env}', '#{props[:locale]}', '#{props[:location]}', '#{transport_ws_url}', '#{component_name}', #{Oj.dump(props, mode: :strict)})
|
55
55
|
JAVASCRIPT
|
56
56
|
|
57
57
|
finished = false
|
@@ -65,13 +65,14 @@ module Isomorfeus
|
|
65
65
|
end
|
66
66
|
|
67
67
|
if has_transport
|
68
|
+
sleep 0.001 # give node a chance connecting to ruby by allowing other threads to run
|
68
69
|
# wait for first pass to finish
|
69
70
|
first_pass_finished, need_further_pass, exception = ctx.eval_script(key: :first_pass_check)
|
70
71
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
71
72
|
unless first_pass_finished
|
72
73
|
start_time = Time.now
|
73
74
|
while !first_pass_finished
|
74
|
-
break if (Time.now - start_time) > 10
|
75
|
+
# break if (Time.now - start_time) > 10
|
75
76
|
sleep 0.005
|
76
77
|
first_pass_finished, need_further_pass, exception = ctx.eval_script(key: :first_pass_check)
|
77
78
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
@@ -79,13 +80,13 @@ module Isomorfeus
|
|
79
80
|
end
|
80
81
|
|
81
82
|
# wait for transport to settle
|
82
|
-
|
83
|
-
if
|
83
|
+
still_busy = ctx.eval_script(key: :still_busy)
|
84
|
+
if still_busy
|
84
85
|
start_time = Time.now
|
85
|
-
while
|
86
|
+
while still_busy
|
86
87
|
break if (Time.now - start_time) > 5
|
87
88
|
sleep 0.005
|
88
|
-
|
89
|
+
still_busy = ctx.eval_script(key: :still_busy)
|
89
90
|
end
|
90
91
|
end
|
91
92
|
end
|
@@ -95,26 +96,22 @@ module Isomorfeus
|
|
95
96
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
96
97
|
else
|
97
98
|
start_time = Time.now
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
:store_busy
|
102
|
-
end
|
99
|
+
javascript = <<~JAVASCRIPT
|
100
|
+
return Opal.Isomorfeus.SSR.further_pass('#{component_name}', #{Oj.dump(props, mode: :strict)})
|
101
|
+
JAVASCRIPT
|
103
102
|
while need_further_pass
|
104
103
|
# execute further render passes
|
105
|
-
javascript = <<~JAVASCRIPT
|
106
|
-
return Opal.Isomorfeus.SSR.further_pass('#{component_name}', #{Oj.dump(props, mode: :strict)})
|
107
|
-
JAVASCRIPT
|
108
104
|
pass += 1
|
109
105
|
rendered_tree, application_state, @ssr_styles, @ssr_response_status, need_further_pass, exception = ctx.exec(javascript)
|
110
106
|
Isomorfeus.raise_error(message: "Server Side Rendering: #{exception['message']}", stack: exception['stack']) if exception
|
111
|
-
if need_further_pass
|
112
|
-
|
113
|
-
|
107
|
+
if need_further_pass
|
108
|
+
sleep 0.001 # give other threads a chance
|
109
|
+
# break if (Time.now - start_time) > 5
|
110
|
+
still_busy = ctx.eval_script(key: :still_busy)
|
114
111
|
while still_busy
|
115
|
-
break if (Time.now - start_time) > 5
|
112
|
+
# break if (Time.now - start_time) > 5
|
116
113
|
sleep 0.005
|
117
|
-
still_busy = ctx.eval_script(key:
|
114
|
+
still_busy = ctx.eval_script(key: :still_busy)
|
118
115
|
end
|
119
116
|
break if pass >= max_passes
|
120
117
|
else
|
@@ -177,21 +174,19 @@ module Isomorfeus
|
|
177
174
|
ctx = Isomorfeus.ssr_contexts[thread_id_asset]
|
178
175
|
ctx.exec(top_level_mod)
|
179
176
|
ctx.exec(ssr_mod)
|
180
|
-
ctx.add_script(key: :first_pass_check, source: '
|
177
|
+
ctx.add_script(key: :first_pass_check, source: 'Opal.Isomorfeus.SSR.first_pass_check()')
|
181
178
|
ctx.add_script(key: :first_pass_result, source: 'Opal.Isomorfeus.SSR.first_pass_result()')
|
182
179
|
ctx.add_script(key: :still_busy, source: 'Opal.Isomorfeus.SSR.still_busy()')
|
183
|
-
ctx.add_script(key: :store_busy, source: 'Opal.Isomorfeus.SSR.store_busy()')
|
184
|
-
ctx.add_script(key: :transport_busy, source: 'global.Opal.Isomorfeus.Transport["$busy?"]()')
|
185
180
|
ctx.add_script(key: :transport_disconnect, source: 'global.Opal.Isomorfeus.SSR.$disconnect_transport()')
|
186
181
|
end
|
187
182
|
end
|
188
183
|
|
189
184
|
def ssr_mod
|
190
|
-
@_ssr_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'ssr.rb'))))
|
185
|
+
@_ssr_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'ssr.rb'))), { use_strict: true })
|
191
186
|
end
|
192
187
|
|
193
188
|
def top_level_mod
|
194
|
-
@_top_level_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'top_level_ssr.rb'))))
|
189
|
+
@_top_level_mod ||= Opal.compile(File.read(File.expand_path(File.join(File.dirname(__FILE__), 'top_level_ssr.rb'))), { use_strict: true })
|
195
190
|
end
|
196
191
|
end
|
197
192
|
end
|
data/lib/isomorfeus/ssr.rb
CHANGED
@@ -1,72 +1,91 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module SSR
|
3
3
|
%x{
|
4
|
-
self.first_pass = function(session_id, env, locale, location,
|
5
|
-
global.Opal.Preact
|
6
|
-
global.Opal.
|
7
|
-
|
4
|
+
self.first_pass = function(session_id, env, locale, location, transport_ws_url, component_name, props) {
|
5
|
+
const oper = global.Opal.Preact;
|
6
|
+
const opi = global.Opal.Isomorfeus;
|
7
|
+
oper.render_buffer = [];
|
8
|
+
oper.active_components = [];
|
9
|
+
oper.active_redux_components = [];
|
8
10
|
global.FirstPassFinished = false;
|
9
11
|
global.NeedFurtherPass = false;
|
10
12
|
global.RenderedTree = '';
|
11
13
|
global.Exception = false;
|
12
14
|
global.IsomorfeusSessionId = session_id;
|
13
|
-
global.HasTransport = (typeof
|
14
|
-
|
15
|
-
if (typeof
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
global.HasTransport = (typeof opi.Transport !== 'undefined');
|
16
|
+
opi['$env='](env);
|
17
|
+
if (typeof opi["$current_locale="] === 'function') { opi["$current_locale="](locale); }
|
18
|
+
opi['$force_init!']();
|
19
|
+
opi['$ssr_response_status='](200);
|
20
|
+
opi.TopLevel['$ssr_route_path='](location);
|
19
21
|
if (global.HasTransport) {
|
20
|
-
|
21
|
-
|
22
|
+
opi.TopLevel["$transport_ws_url="](transport_ws_url);
|
23
|
+
let $$1;
|
24
|
+
global.Opal.send(opi.Transport.$promise_connect(global.IsomorfeusSessionId), 'then', [], ($$1 = function(){
|
22
25
|
try {
|
23
|
-
global.RenderedTree =
|
26
|
+
global.RenderedTree = opi.TopLevel.$render_component_to_string(component_name, props);
|
24
27
|
global.NeedFurtherPass = self.still_busy();
|
25
28
|
global.FirstPassFinished = true;
|
26
29
|
} catch (e) {
|
27
30
|
global.Exception = e;
|
31
|
+
global.FirstPassFinished = true;
|
28
32
|
global.NeedFurtherPass = false;
|
29
33
|
}
|
30
34
|
}, $$1.$$s = this, $$1.$$arity = 0, $$1))
|
35
|
+
global.NeedFurtherPass = true;
|
31
36
|
} else {
|
32
37
|
try {
|
33
|
-
global.RenderedTree =
|
38
|
+
global.RenderedTree = opi.TopLevel.$render_component_to_string(component_name, props);
|
34
39
|
global.NeedFurtherPass = self.store_busy();
|
35
40
|
} catch (e) {
|
36
41
|
global.Exception = e;
|
42
|
+
global.FirstPassFinished = true;
|
37
43
|
global.NeedFurtherPass = false;
|
38
44
|
}
|
39
45
|
};
|
40
|
-
return [global.HasTransport, global.NeedFurtherPass,
|
46
|
+
return [global.HasTransport, global.NeedFurtherPass, self.get_exception()];
|
47
|
+
}
|
48
|
+
|
49
|
+
self.first_pass_check = function() {
|
50
|
+
return [global.FirstPassFinished, global.NeedFurtherPass, self.get_exception()];
|
41
51
|
}
|
42
52
|
|
43
53
|
self.first_pass_result = function() {
|
44
|
-
|
45
|
-
let application_state =
|
46
|
-
|
47
|
-
return [global.RenderedTree, application_state, ssr_styles,
|
54
|
+
const opi = global.Opal.Isomorfeus;
|
55
|
+
let application_state = opi.store.native.getState();
|
56
|
+
let ssr_styles = global?.NanoCSSInstance?.raw;
|
57
|
+
return [global.RenderedTree, application_state, ssr_styles, opi['$ssr_response_status'](), self.get_exception()];
|
48
58
|
}
|
49
59
|
|
50
60
|
self.further_pass = function(component_name, props) {
|
51
|
-
global.Opal.Preact
|
52
|
-
global.Opal.
|
53
|
-
|
61
|
+
const oper = global.Opal.Preact;
|
62
|
+
const opi = global.Opal.Isomorfeus;
|
63
|
+
oper.render_buffer = [];
|
64
|
+
oper.active_components = [];
|
65
|
+
oper.active_redux_components = [];
|
66
|
+
global.NeedFurtherPass = false;
|
54
67
|
global.Exception = false;
|
55
|
-
let
|
56
|
-
let
|
68
|
+
let application_state = null;
|
69
|
+
let rendered_tree = null;
|
70
|
+
let ssr_styles = null;
|
57
71
|
try {
|
58
|
-
rendered_tree =
|
72
|
+
rendered_tree = opi.TopLevel.$render_component_to_string(component_name, props);
|
73
|
+
application_state = opi.store.native.getState();
|
74
|
+
ssr_styles = global?.NanoCSSInstance?.raw;
|
75
|
+
global.NeedFurtherPass = self.still_busy();
|
59
76
|
} catch (e) {
|
60
77
|
global.Exception = e;
|
61
78
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
79
|
+
return [rendered_tree, application_state, ssr_styles, opi['$ssr_response_status'](), global.NeedFurtherPass, self.get_exception()];
|
80
|
+
}
|
81
|
+
|
82
|
+
self.get_exception = function() {
|
83
|
+
if (global.Exception) { return { message: global.Exception.message, stack: global.Exception.stack }; }
|
84
|
+
return false;
|
66
85
|
}
|
67
86
|
|
68
87
|
self.still_busy = function(){
|
69
|
-
if (global.Opal.Isomorfeus
|
88
|
+
if (global.Opal.Isomorfeus?.Transport?.["$busy?"]?.()) { return true; }
|
70
89
|
return self.store_busy();
|
71
90
|
}
|
72
91
|
|
data/lib/isomorfeus/top_level.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
class TopLevel
|
3
3
|
class << self
|
4
|
+
attr_accessor :hydrated
|
5
|
+
attr_accessor :first_pass
|
6
|
+
|
4
7
|
if on_browser?
|
5
8
|
def mount!
|
6
9
|
Isomorfeus.init
|
@@ -27,7 +30,7 @@ module Isomorfeus
|
|
27
30
|
props_json = root_element.JS.getAttribute('data-iso-props')
|
28
31
|
props = `Opal.Hash.$new(JSON.parse(props_json))`
|
29
32
|
raw_hydrated = root_element.JS.getAttribute('data-iso-hydrated')
|
30
|
-
hydrated = (raw_hydrated && raw_hydrated == "true")
|
33
|
+
self.hydrated = (raw_hydrated && raw_hydrated == "true")
|
31
34
|
%x{
|
32
35
|
if (global.ServerSideRenderingStateJSON) {
|
33
36
|
var state = global.ServerSideRenderingStateJSON;
|
@@ -41,10 +44,13 @@ module Isomorfeus
|
|
41
44
|
}
|
42
45
|
Isomorfeus.execute_init_after_store_classes
|
43
46
|
begin
|
44
|
-
|
47
|
+
self.first_pass = true
|
48
|
+
result = Isomorfeus::TopLevel.mount_component(component, props, root_element, self.hydrated)
|
49
|
+
self.first_pass = false
|
45
50
|
@tried_another_time = false
|
46
51
|
result
|
47
52
|
rescue Exception => e
|
53
|
+
self.first_pass = false
|
48
54
|
if !@tried_another_time
|
49
55
|
@tried_another_time = true
|
50
56
|
`console.warn("Deferring mount: " + #{e.message})`
|
data/lib/isomorfeus-preact.rb
CHANGED
@@ -8,10 +8,13 @@ if RUBY_ENGINE == 'opal'
|
|
8
8
|
require 'browser/event_target'
|
9
9
|
require 'browser/delegate_native'
|
10
10
|
require 'browser/element' # depends on 'preact'
|
11
|
+
require 'browser/history'
|
11
12
|
end
|
12
13
|
|
13
14
|
require 'isomorfeus/preact/config'
|
14
|
-
|
15
|
+
if on_browser? && `window?.history`
|
16
|
+
Isomorfeus.browser_history = Browser::History.new(`window.history`)
|
17
|
+
end
|
15
18
|
# allow mounting of components
|
16
19
|
require 'isomorfeus/top_level'
|
17
20
|
|
@@ -74,26 +74,31 @@ module Preact::FunctionComponent::Api
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def get_preact_element(arg, &block)
|
77
|
+
`let operabu = Opal.Preact.render_buffer`
|
77
78
|
if block_given?
|
78
79
|
# execute block, fetch last element from buffer
|
79
80
|
%x{
|
80
|
-
let last_buffer_length =
|
81
|
-
let last_buffer_element =
|
81
|
+
let last_buffer_length = operabu[operabu.length - 1].length;
|
82
|
+
let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
|
82
83
|
block.$call();
|
83
|
-
// console.log("get_preact_element popping",
|
84
|
-
let new_element =
|
84
|
+
// console.log("get_preact_element popping", operabu, operabu.toString())
|
85
|
+
let new_element = operabu[operabu.length - 1].pop();
|
85
86
|
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
|
86
87
|
return new_element;
|
87
88
|
}
|
88
89
|
else
|
89
90
|
# element was rendered before being passed as arg
|
90
91
|
# fetch last element from buffer
|
91
|
-
# `console.log("get_preact_element popping",
|
92
|
-
`
|
92
|
+
# `console.log("get_preact_element popping", operabu, operabu.toString())`
|
93
|
+
`operabu[operabu.length - 1].pop()`
|
93
94
|
end
|
94
95
|
end
|
95
96
|
alias gpe get_preact_element
|
96
97
|
|
98
|
+
def history
|
99
|
+
Isomorfeus.browser_history
|
100
|
+
end
|
101
|
+
|
97
102
|
def render_preact_element(el)
|
98
103
|
# push el to buffer
|
99
104
|
`Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
|
@@ -105,7 +110,7 @@ module Preact::FunctionComponent::Api
|
|
105
110
|
def method_ref(method_symbol, *args)
|
106
111
|
method_key = "#{method_symbol}#{args}"
|
107
112
|
%x{
|
108
|
-
if (#{self}.method_refs
|
113
|
+
if (#{self}.method_refs?.[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
|
109
114
|
if (!#{self}.method_refs) { #{self}.method_refs = {}; }
|
110
115
|
#{self}.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
|
111
116
|
return #{self}.method_refs[#{method_key}];
|
data/lib/preact/component/api.rb
CHANGED
@@ -66,30 +66,35 @@ module Preact::Component::Api
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def get_preact_element(arg, &block)
|
69
|
+
`const operabu = Opal.Preact.render_buffer`
|
69
70
|
if block_given?
|
70
71
|
# execute block, fetch last element from buffer
|
71
72
|
%x{
|
72
|
-
let last_buffer_length =
|
73
|
-
let last_buffer_element =
|
73
|
+
let last_buffer_length = operabu[operabu.length - 1].length;
|
74
|
+
let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
|
74
75
|
block.$call();
|
75
|
-
// console.log("get_preact_element popping",
|
76
|
-
let new_element =
|
76
|
+
// console.log("get_preact_element popping", operabu, operabu.toString())
|
77
|
+
let new_element = operabu[operabu.length - 1].pop();
|
77
78
|
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
|
78
79
|
return new_element;
|
79
80
|
}
|
80
81
|
else
|
81
82
|
# element was rendered before being passed as arg
|
82
83
|
# fetch last element from buffer
|
83
|
-
# `console.log("get_preact_element popping",
|
84
|
-
`
|
84
|
+
# `console.log("get_preact_element popping", operabu, operabu.toString())`
|
85
|
+
`operabu[operabu.length - 1].pop()`
|
85
86
|
end
|
86
87
|
end
|
87
88
|
alias gpe get_preact_element
|
88
89
|
|
90
|
+
def history
|
91
|
+
Isomorfeus.browser_history
|
92
|
+
end
|
93
|
+
|
89
94
|
def method_ref(method_symbol, *args)
|
90
95
|
method_key = "#{method_symbol}#{args}"
|
91
96
|
%x{
|
92
|
-
if (#@native.method_refs
|
97
|
+
if (#@native.method_refs?.[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
|
93
98
|
if (!#@native.method_refs) { #@native.method_refs = {}; }
|
94
99
|
#@native.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
|
95
100
|
return #@native.method_refs[#{method_key}];
|
@@ -5,11 +5,12 @@ module Preact::Component::Callbacks
|
|
5
5
|
# TODO convert error
|
6
6
|
%x{
|
7
7
|
var fun = function(error) {
|
8
|
-
Opal.Preact
|
8
|
+
const oper = Opal.Preact;
|
9
|
+
oper.register_active_component(this);
|
9
10
|
try {
|
10
11
|
#{`this.__ruby_instance`.instance_exec(`error`, &block)};
|
11
12
|
} catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
|
12
|
-
|
13
|
+
oper.unregister_active_component(this);
|
13
14
|
}
|
14
15
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
|
15
16
|
else { self.preact_component.prototype.componentDidCatch = fun; }
|
@@ -20,22 +21,24 @@ module Preact::Component::Callbacks
|
|
20
21
|
def component_did_mount(&block)
|
21
22
|
%x{
|
22
23
|
let fun = function() {
|
23
|
-
Opal.Preact
|
24
|
+
const oper = Opal.Preact;
|
25
|
+
oper.register_active_component(this);
|
24
26
|
try {
|
25
27
|
#{`this.__ruby_instance`.instance_exec(&block)};
|
26
28
|
} catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
|
27
|
-
|
29
|
+
oper.unregister_active_component(this);
|
28
30
|
}
|
29
31
|
if (self.lucid_preact_component) {
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
let proto = self.lucid_preact_component.prototype;
|
33
|
+
if (proto.componentDidMount) {
|
34
|
+
proto.componentDidMountTwo = proto.componentDidMount;
|
35
|
+
proto.componentDidMountOne = fun;
|
33
36
|
fun = function() {
|
34
|
-
|
35
|
-
|
37
|
+
this.componentDidMountOne();
|
38
|
+
this.componentDidMountTwo();
|
36
39
|
}
|
37
40
|
}
|
38
|
-
|
41
|
+
proto.componentDidMount = fun;
|
39
42
|
} else { self.preact_component.prototype.componentDidMount = fun; }
|
40
43
|
}
|
41
44
|
end
|
@@ -43,13 +46,14 @@ module Preact::Component::Callbacks
|
|
43
46
|
def component_did_update(&block)
|
44
47
|
%x{
|
45
48
|
var fun = function(prev_props, prev_state, snapshot) {
|
46
|
-
Opal.Preact
|
49
|
+
const oper = Opal.Preact;
|
50
|
+
oper.register_active_component(this);
|
47
51
|
try {
|
48
|
-
#{`this.__ruby_instance`.instance_exec(`
|
49
|
-
|
50
|
-
|
52
|
+
#{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: prev_props})`,
|
53
|
+
`oper.State.$new({state: prev_state})`,
|
54
|
+
`snapshot`, &block)};
|
51
55
|
} catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
|
52
|
-
|
56
|
+
oper.unregister_active_component(this);
|
53
57
|
}
|
54
58
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
|
55
59
|
else { self.preact_component.prototype.componentDidUpdate = fun; }
|
@@ -59,12 +63,13 @@ module Preact::Component::Callbacks
|
|
59
63
|
def component_will_unmount(&block)
|
60
64
|
%x{
|
61
65
|
var fun = function() {
|
66
|
+
const oper = Opal.Preact;
|
62
67
|
if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
|
63
|
-
|
68
|
+
oper.register_active_component(this);
|
64
69
|
try {
|
65
70
|
#{`this.__ruby_instance`.instance_exec(&block)};
|
66
71
|
} catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
|
67
|
-
|
72
|
+
oper.unregister_active_component(this);
|
68
73
|
}
|
69
74
|
if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
|
70
75
|
else { self.preact_component.prototype.componentWillUnmount = fun; }
|
@@ -75,12 +80,13 @@ module Preact::Component::Callbacks
|
|
75
80
|
def get_derived_state_from_props(&block)
|
76
81
|
%x{
|
77
82
|
var fun = function(props, state) {
|
78
|
-
Opal.Preact
|
83
|
+
const oper = Opal.Preact;
|
84
|
+
oper.register_active_component(this);
|
79
85
|
try {
|
80
|
-
var result = #{`this.__ruby_instance`.instance_exec(`
|
81
|
-
`
|
86
|
+
var result = #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: props})`,
|
87
|
+
`oper.State.$new({state: state})`, &block)};
|
82
88
|
} catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
|
83
|
-
|
89
|
+
oper.unregister_active_component(this);
|
84
90
|
if (typeof result.$to_n === 'function') { result = result.$to_n() }
|
85
91
|
if (result === nil) { return null; }
|
86
92
|
return result;
|
@@ -93,12 +99,13 @@ module Preact::Component::Callbacks
|
|
93
99
|
def get_snapshot_before_update(&block)
|
94
100
|
%x{
|
95
101
|
var fun = function(prev_props, prev_state) {
|
96
|
-
Opal.Preact
|
102
|
+
const oper = Opal.Preact;
|
103
|
+
oper.register_active_component(this);
|
97
104
|
try {
|
98
|
-
var result = #{`this.__ruby_instance`.instance_exec(`
|
99
|
-
`
|
105
|
+
var result = #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: prev_props})`,
|
106
|
+
`oper.State.$new({state: prev_state})`, &block)};
|
100
107
|
} catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
|
101
|
-
|
108
|
+
oper.unregister_active_component(this);
|
102
109
|
if (result === nil) { return null; }
|
103
110
|
return result;
|
104
111
|
}
|
data/lib/preact/version.rb
CHANGED
data/lib/preact.rb
CHANGED
@@ -145,12 +145,12 @@ module Preact
|
|
145
145
|
let method_name = '$' + value;
|
146
146
|
if (typeof active_component[method_name] === "function") {
|
147
147
|
// got a ruby instance
|
148
|
-
if (active_component.native
|
149
|
-
else if (active_component.method_refs
|
148
|
+
if (active_component.native?.method_refs?.[value]) { method_ref = active_component.native.method_refs[value]; } // ruby instance with native
|
149
|
+
else if (active_component.method_refs?.[value]) { method_ref = active_component.method_refs[value]; } // ruby function component
|
150
150
|
else { method_ref = active_component.$method_ref(value); } // create the ref
|
151
151
|
} else if (typeof active_component.__ruby_instance[method_name] === "function") {
|
152
152
|
// got a native instance
|
153
|
-
if (active_component.method_refs
|
153
|
+
if (active_component.method_refs?.[value]) { method_ref = active_component.method_refs[value]; }
|
154
154
|
else { method_ref = active_component.__ruby_instance.$method_ref(value); } // create ref for native
|
155
155
|
}
|
156
156
|
if (method_ref) {
|
@@ -13,9 +13,9 @@
|
|
13
13
|
}
|
14
14
|
},
|
15
15
|
"node_modules/preact-render-to-string": {
|
16
|
-
"version": "5.1.
|
17
|
-
"resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.1.
|
18
|
-
"integrity": "sha512-
|
16
|
+
"version": "5.1.20",
|
17
|
+
"resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.1.20.tgz",
|
18
|
+
"integrity": "sha512-ivh2oOGzth0o7XqbatWUQ81WQGoJwSqDKP5z917SoqTWYCAr7dlBzMv3SAMTAu3Gr5g47BJwrvyO44H2Y10ubg==",
|
19
19
|
"dependencies": {
|
20
20
|
"pretty-format": "^3.8.0"
|
21
21
|
},
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# preact-render-to-string
|
2
2
|
|
3
3
|
[![NPM](http://img.shields.io/npm/v/preact-render-to-string.svg)](https://www.npmjs.com/package/preact-render-to-string)
|
4
|
-
[![
|
4
|
+
[![Build status](https://github.com/preactjs/preact-render-to-string/actions/workflows/ci.yml/badge.svg)](https://github.com/preactjs/preact-render-to-string/actions/workflows/ci.yml)
|
5
5
|
|
6
6
|
Render JSX and [Preact] components to an HTML string.
|
7
7
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t((e||self).preactRenderToString={},e.preact)}(this,function(e,t){var n=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i,r=/[&<>"]/;function o(e){var t=String(e);return r.test(t)?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""):t}var i=function(e,t){return String(e).replace(/(\n+)/g,"$1"+(t||"\t"))},a=function(e,t,n){return String(e).length>(t||40)||!n&&-1!==String(e).indexOf("\n")||-1!==String(e).indexOf("<")},l={};function s(e){var t="";for(var r in e){var o=e[r];null!=o&&""!==o&&(t&&(t+=" "),t+="-"==r[0]?r:l[r]||(l[r]=r.replace(/([A-Z])/g,"-$1").toLowerCase()),t+=": ",t+=o,"number"==typeof o&&!1===n.test(r)&&(t+="px"),t+=";")}return t||void 0}function f(e,t){for(var n in t)e[n]=t[n];return e}function p(e,t){return Array.isArray(t)?t.reduce(p,e):null!=t&&!1!==t&&e.push(t),e}var u={shallow:!0},c=[],_=/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/,d=/[\s\n\\/='"\0<>]/,
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t((e||self).preactRenderToString={},e.preact)}(this,function(e,t){var n=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i,r=/[&<>"]/;function o(e){var t=String(e);return r.test(t)?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""):t}var i=function(e,t){return String(e).replace(/(\n+)/g,"$1"+(t||"\t"))},a=function(e,t,n){return String(e).length>(t||40)||!n&&-1!==String(e).indexOf("\n")||-1!==String(e).indexOf("<")},l={};function s(e){var t="";for(var r in e){var o=e[r];null!=o&&""!==o&&(t&&(t+=" "),t+="-"==r[0]?r:l[r]||(l[r]=r.replace(/([A-Z])/g,"-$1").toLowerCase()),t+=": ",t+=o,"number"==typeof o&&!1===n.test(r)&&(t+="px"),t+=";")}return t||void 0}function f(e,t){for(var n in t)e[n]=t[n];return e}function p(e,t){return Array.isArray(t)?t.reduce(p,e):null!=t&&!1!==t&&e.push(t),e}var u={shallow:!0},c=[],_=/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/,d=/[\s\n\\/='"\0<>]/,v=function(){};y.render=y;var g=function(e,t){return y(e,t,u)},h=[];function y(e,n,r){n=n||{},r=r||{};var o=t.options.__s;t.options.__s=!0;var i=m(e,n,r);return t.options.__c&&t.options.__c(e,h),h.length=0,t.options.__s=o,i}function m(e,n,r,l,u,g){if(null==e||"boolean"==typeof e)return"";if("object"!=typeof e)return o(e);var h=r.pretty,y=h&&"string"==typeof h?h:"\t";if(Array.isArray(e)){for(var x="",b=0;b<e.length;b++)h&&b>0&&(x+="\n"),x+=m(e[b],n,r,l,u,g);return x}var S,w=e.type,k=e.props,O=!1;if("function"==typeof w){if(O=!0,!r.shallow||!l&&!1!==r.renderRootComponent){if(w===t.Fragment){var T=[];return p(T,e.props.children),m(T,n,r,!1!==r.shallowHighOrder,u,g)}var C,A=e.__c={__v:e,context:n,props:e.props,setState:v,forceUpdate:v,__h:[]};if(t.options.__b&&t.options.__b(e),t.options.__r&&t.options.__r(e),w.prototype&&"function"==typeof w.prototype.render){var j=w.contextType,F=j&&n[j.__c],H=null!=j?F?F.props.value:j.__:n;(A=e.__c=new w(k,H)).__v=e,A._dirty=A.__d=!0,A.props=k,null==A.state&&(A.state={}),null==A._nextState&&null==A.__s&&(A._nextState=A.__s=A.state),A.context=H,w.getDerivedStateFromProps?A.state=f(f({},A.state),w.getDerivedStateFromProps(A.props,A.state)):A.componentWillMount&&(A.componentWillMount(),A.state=A._nextState!==A.state?A._nextState:A.__s!==A.state?A.__s:A.state),C=A.render(A.props,A.state,A.context)}else{var M=w.contextType,$=M&&n[M.__c];C=w.call(e.__c,k,null!=M?$?$.props.value:M.__:n)}return A.getChildContext&&(n=f(f({},n),A.getChildContext())),t.options.diffed&&t.options.diffed(e),m(C,n,r,!1!==r.shallowHighOrder,u,g)}w=(S=w).displayName||S!==Function&&S.name||function(e){var t=(Function.prototype.toString.call(e).match(/^\s*function\s+([^( ]+)/)||"")[1];if(!t){for(var n=-1,r=c.length;r--;)if(c[r]===e){n=r;break}n<0&&(n=c.push(e)-1),t="UnnamedComponent"+n}return t}(S)}var L,R,E="<"+w;if(k){var q=Object.keys(k);r&&!0===r.sortAttributes&&q.sort();for(var D=0;D<q.length;D++){var N=q[D],P=k[N];if("children"!==N){if(!d.test(N)&&(r&&r.allAttributes||"key"!==N&&"ref"!==N&&"__self"!==N&&"__source"!==N)){if("defaultValue"===N)N="value";else if("className"===N){if(void 0!==k.class)continue;N="class"}else u&&N.match(/^xlink:?./)&&(N=N.toLowerCase().replace(/^xlink:?/,"xlink:"));if("htmlFor"===N){if(k.for)continue;N="for"}"style"===N&&P&&"object"==typeof P&&(P=s(P)),"a"===N[0]&&"r"===N[1]&&"boolean"==typeof P&&(P=String(P));var U=r.attributeHook&&r.attributeHook(N,P,n,r,O);if(U||""===U)E+=U;else if("dangerouslySetInnerHTML"===N)R=P&&P.__html;else if("textarea"===w&&"value"===N)L=P;else if((P||0===P||""===P)&&"function"!=typeof P){if(!(!0!==P&&""!==P||(P=N,r&&r.xml))){E+=" "+N;continue}if("value"===N){if("select"===w){g=P;continue}"option"===w&&g==P&&(E+=" selected")}E+=" "+N+'="'+o(P)+'"'}}}else L=P}}if(h){var W=E.replace(/\n\s*/," ");W===E||~W.indexOf("\n")?h&&~E.indexOf("\n")&&(E+="\n"):E=W}if(E+=">",d.test(w))throw new Error(w+" is not a valid HTML tag name in "+E);var z,I=_.test(w)||r.voidElements&&r.voidElements.test(w),V=[];if(R)h&&a(R)&&(R="\n"+y+i(R,y)),E+=R;else if(null!=L&&p(z=[],L).length){for(var Z=h&&~E.indexOf("\n"),B=!1,G=0;G<z.length;G++){var J=z[G];if(null!=J&&!1!==J){var K=m(J,n,r,!0,"svg"===w||"foreignObject"!==w&&u,g);if(h&&!Z&&a(K)&&(Z=!0),K)if(h){var Q=K.length>0&&"<"!=K[0];B&&Q?V[V.length-1]+=K:V.push(K),B=Q}else V.push(K)}}if(h&&Z)for(var X=V.length;X--;)V[X]="\n"+y+i(V[X],y)}if(V.length||R)E+=V.join("");else if(r&&r.xml)return E.substring(0,E.length-1)+" />";return!I||z||R?(h&&~E.indexOf("\n")&&(E+="\n"),E+="</"+w+">"):E=E.replace(/>$/," />"),E}y.shallowRender=g,e.default=y,e.render=y,e.renderToStaticMarkup=y,e.renderToString=y,e.shallowRender=g});
|
2
2
|
//# sourceMappingURL=index.js.map
|