isomorfeus-preact 10.6.32 → 10.6.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus-preact.rb +15 -0
- data/lib/isomorfeus_preact/lucid_app/api.rb +30 -32
- data/lib/isomorfeus_preact/lucid_app/mixin.rb +12 -13
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +88 -90
- data/lib/isomorfeus_preact/lucid_component/api.rb +96 -98
- data/lib/isomorfeus_preact/lucid_component/initializer.rb +8 -10
- data/lib/isomorfeus_preact/lucid_component/mixin.rb +11 -12
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +77 -79
- data/lib/isomorfeus_preact/lucid_func/initializer.rb +7 -9
- data/lib/isomorfeus_preact/lucid_func/mixin.rb +8 -9
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +49 -51
- data/lib/isomorfeus_preact/preact/function_component/api.rb +102 -106
- data/lib/isomorfeus_preact/preact/function_component/base.rb +5 -7
- data/lib/isomorfeus_preact/preact/function_component/initializer.rb +4 -8
- data/lib/isomorfeus_preact/preact/function_component/mixin.rb +6 -10
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +41 -45
- data/lib/preact/component/api.rb +99 -103
- data/lib/preact/component/base.rb +5 -7
- data/lib/preact/component/callbacks.rb +99 -103
- data/lib/preact/component/initializer.rb +5 -9
- data/lib/preact/component/mixin.rb +9 -13
- data/lib/preact/component/native_component_constructor.rb +67 -71
- data/lib/preact/component_resolution.rb +78 -80
- data/lib/preact/elements.rb +55 -57
- data/lib/preact/version.rb +1 -1
- metadata +1 -1
@@ -1,81 +1,77 @@
|
|
1
|
-
module Preact
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
const oper = Opal.Preact;
|
25
|
-
element = oper.native_element_or_component_to_ruby(element);
|
26
|
-
oper.register_active_component(this);
|
27
|
-
try {
|
28
|
-
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
29
|
-
} catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
30
|
-
oper.unregister_active_component(this);
|
31
|
-
}
|
32
|
-
this[ref] = this[ref].bind(this);
|
33
|
-
} else {
|
34
|
-
this[ref] = Opal.global.Preact.createRef();
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
static get displayName() {
|
39
|
-
return #{component_name};
|
40
|
-
}
|
41
|
-
render(props, state) {
|
42
|
-
const oper = Opal.Preact;
|
43
|
-
oper.render_buffer.push([]);
|
44
|
-
oper.register_active_component(this);
|
45
|
-
try {
|
46
|
-
let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
47
|
-
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
48
|
-
} catch (e) {
|
49
|
-
if (oper.using_did_catch) { throw e; }
|
50
|
-
else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
51
|
-
}
|
52
|
-
oper.unregister_active_component(this);
|
53
|
-
let result = oper.render_buffer.pop();
|
54
|
-
return (result.length === 1) ? result[0] : result;
|
55
|
-
}
|
56
|
-
shouldComponentUpdate(next_props, next_state) {
|
57
|
-
const oper = Opal.Preact;
|
58
|
-
if (base.should_component_update_block) {
|
1
|
+
module Preact::Component::NativeComponentConstructor
|
2
|
+
# for should_component_update we apply ruby semantics for comparing props
|
3
|
+
# to do so, we convert the props to ruby hashes and then compare
|
4
|
+
# this makes sure, that for example rubys Nil object gets handled properly
|
5
|
+
def self.extended(base)
|
6
|
+
component_name = base.to_s
|
7
|
+
%x{
|
8
|
+
base.preact_component = class extends Opal.global.Preact.Component {
|
9
|
+
constructor(props) {
|
10
|
+
super(props);
|
11
|
+
if (base.$default_state_defined()) {
|
12
|
+
this.state = base.$state().$to_n();
|
13
|
+
} else {
|
14
|
+
this.state = {};
|
15
|
+
};
|
16
|
+
this.__ruby_instance = base.$new(this);
|
17
|
+
var defined_refs = #{base.defined_refs};
|
18
|
+
for (var ref in defined_refs) {
|
19
|
+
if (defined_refs[ref] != null) {
|
20
|
+
let r = ref; // to ensure closure for function below gets correct ref name
|
21
|
+
this[ref] = function(element) {
|
22
|
+
const oper = Opal.Preact;
|
23
|
+
element = oper.native_element_or_component_to_ruby(element);
|
59
24
|
oper.register_active_component(this);
|
60
|
-
let result;
|
61
25
|
try {
|
62
|
-
|
26
|
+
#{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[r]`)}
|
63
27
|
} catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
64
28
|
oper.unregister_active_component(this);
|
65
|
-
return result;
|
66
29
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
}
|
71
|
-
validateProp(props, propName, componentName) {
|
72
|
-
try { base.$validate_prop(propName, props[propName]) }
|
73
|
-
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
74
|
-
return null;
|
30
|
+
this[ref] = this[ref].bind(this);
|
31
|
+
} else {
|
32
|
+
this[ref] = Opal.global.Preact.createRef();
|
75
33
|
}
|
76
34
|
}
|
77
35
|
}
|
78
|
-
|
79
|
-
|
36
|
+
static get displayName() {
|
37
|
+
return #{component_name};
|
38
|
+
}
|
39
|
+
render(props, state) {
|
40
|
+
const oper = Opal.Preact;
|
41
|
+
oper.render_buffer.push([]);
|
42
|
+
oper.register_active_component(this);
|
43
|
+
try {
|
44
|
+
let block_result = #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
|
45
|
+
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
46
|
+
} catch (e) {
|
47
|
+
if (oper.using_did_catch) { throw e; }
|
48
|
+
else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
49
|
+
}
|
50
|
+
oper.unregister_active_component(this);
|
51
|
+
let result = oper.render_buffer.pop();
|
52
|
+
return (result.length === 1) ? result[0] : result;
|
53
|
+
}
|
54
|
+
shouldComponentUpdate(next_props, next_state) {
|
55
|
+
const oper = Opal.Preact;
|
56
|
+
if (base.should_component_update_block) {
|
57
|
+
oper.register_active_component(this);
|
58
|
+
let result;
|
59
|
+
try {
|
60
|
+
result = #{!!`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: next_props})`, `oper.State.$new({state: next_state })`, &`base.should_component_update_block`)};
|
61
|
+
} catch (e) { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
62
|
+
oper.unregister_active_component(this);
|
63
|
+
return result;
|
64
|
+
}
|
65
|
+
if (!oper.props_are_equal(this.props, next_props)) { return true; }
|
66
|
+
if (oper.state_is_not_equal(this.state, next_state)) { return true; }
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
validateProp(props, propName, componentName) {
|
70
|
+
try { base.$validate_prop(propName, props[propName]) }
|
71
|
+
catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
|
72
|
+
return null;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
80
76
|
end
|
81
77
|
end
|
@@ -1,94 +1,92 @@
|
|
1
|
-
module Preact
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module Preact::ComponentResolution
|
2
|
+
def self.included(base)
|
3
|
+
base.instance_exec do
|
4
|
+
unless method_defined?(:_preact_component_class_resolution_original_const_missing)
|
5
|
+
alias _preact_component_class_resolution_original_const_missing const_missing
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
8
|
+
def const_missing(const_name)
|
9
|
+
%x{
|
10
|
+
if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
|
11
|
+
var new_const = Opal.Preact.NativeConstantWrapper.$new(Opal.global[const_name], const_name);
|
12
|
+
new_const.preact_component = Opal.global[const_name];
|
13
|
+
Opal.Object.$const_set(const_name, new_const);
|
14
|
+
return new_const;
|
15
|
+
} else {
|
16
|
+
return #{_preact_component_class_resolution_original_const_missing(const_name)};
|
19
17
|
}
|
20
|
-
|
18
|
+
}
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
# this is required for autoloading support, as the component may not be loaded and so its method is not registered.
|
22
|
+
# must load it first, done by const_get, and next time the method will be there.
|
23
|
+
unless method_defined?(:_preact_component_class_resolution_original_method_missing)
|
24
|
+
alias _preact_component_class_resolution_original_method_missing method_missing
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
|
27
|
+
def method_missing(component_name, *args, &block)
|
28
|
+
# check for ruby component and render it
|
29
|
+
# otherwise pass on method missing
|
30
|
+
%x{
|
31
|
+
var constant = null;
|
32
|
+
if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
|
33
|
+
if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
|
34
|
+
constant = self.iso_preact_const_cache[component_name]
|
35
|
+
} else {
|
36
|
+
try {
|
37
|
+
constant = self.$const_get(component_name);
|
38
|
+
self.iso_preact_const_cache[component_name] = constant;
|
39
|
+
} catch(err) { }
|
40
|
+
}
|
41
|
+
if (constant && typeof constant.preact_component !== 'undefined') {
|
42
|
+
return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
|
46
43
|
}
|
47
|
-
|
44
|
+
return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
|
45
|
+
}
|
48
46
|
end
|
49
47
|
end
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
unless method_defined?(:_preact_component_resolution_original_method_missing)
|
51
|
+
alias _preact_component_resolution_original_method_missing method_missing
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
54
|
+
def method_missing(component_name, *args, &block)
|
55
|
+
# Further on it must check for modules, because $const_get does not take
|
56
|
+
# the full nesting into account, as usually its called via $$ with the
|
57
|
+
# nesting provided by the compiler.
|
58
|
+
%x{
|
59
|
+
var constant;
|
60
|
+
if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
|
61
|
+
if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
|
62
|
+
constant = self.iso_preact_const_cache[component_name]
|
63
|
+
} else if (typeof self.$$is_a_module !== 'undefined') {
|
64
|
+
try {
|
65
|
+
constant = self.$const_get(component_name);
|
66
|
+
self.iso_preact_const_cache[component_name] = constant;
|
67
|
+
} catch(err) { }
|
68
|
+
} else {
|
69
|
+
let sc = self.$class();
|
70
|
+
try {
|
71
|
+
constant = sc.$const_get(component_name);
|
72
|
+
self.iso_preact_const_cache[component_name] = constant;
|
73
|
+
} catch(err) {
|
74
|
+
var module_names = sc.$to_s().split("::");
|
75
|
+
var module_name;
|
76
|
+
for (var i = module_names.length - 1; i > 0; i--) {
|
77
|
+
module_name = module_names.slice(0, i).join('::');
|
78
|
+
try {
|
79
|
+
constant = sc.$const_get(module_name).$const_get(component_name, false);
|
80
|
+
self.iso_preact_const_cache[component_name] = constant;
|
81
|
+
break;
|
82
|
+
} catch(err) { }
|
85
83
|
}
|
86
84
|
}
|
87
|
-
if (constant && typeof constant.preact_component !== 'undefined') {
|
88
|
-
return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
|
89
|
-
}
|
90
|
-
return #{_preact_component_resolution_original_method_missing(component_name, *args, block)};
|
91
85
|
}
|
92
|
-
|
86
|
+
if (constant && typeof constant.preact_component !== 'undefined') {
|
87
|
+
return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
|
88
|
+
}
|
89
|
+
return #{_preact_component_resolution_original_method_missing(component_name, *args, block)};
|
90
|
+
}
|
93
91
|
end
|
94
92
|
end
|
data/lib/preact/elements.rb
CHANGED
@@ -1,62 +1,60 @@
|
|
1
|
-
module Preact
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
]
|
1
|
+
module Preact::Elements
|
2
|
+
# https://www.w3.org/TR/html52/fullindex.html#index-elements
|
3
|
+
# https://www.w3.org/TR/SVG11/eltindex.html
|
4
|
+
SUPPORTED_HTML_AND_SVG_ELEMENTS = %w[
|
5
|
+
a abbr address area article aside audio
|
6
|
+
b base bdi bdo blockquote body br button
|
7
|
+
canvas caption cite code col colgroup
|
8
|
+
data datalist dd del details dfn dialog div dl dt
|
9
|
+
em embed
|
10
|
+
fieldset figcaption figure footer form
|
11
|
+
h1 h2 h3 h4 h5 h6 head header hr html
|
12
|
+
i iframe img input ins
|
13
|
+
kbd
|
14
|
+
label legend li link
|
15
|
+
main map mark meta meter
|
16
|
+
nav noscript
|
17
|
+
object ol optgroup option output
|
18
|
+
p param picture pre progress
|
19
|
+
q
|
20
|
+
rp rt rtc ruby
|
21
|
+
s samp script section select small source span strong style sub summary sup
|
22
|
+
table tbody td template textarea tfoot th thead time title tr track
|
23
|
+
u ul
|
24
|
+
var video
|
25
|
+
wbr
|
26
|
+
altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform
|
27
|
+
circle clipPath color-profile cursor
|
28
|
+
defs desc
|
29
|
+
ellipse
|
30
|
+
feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting
|
31
|
+
feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur
|
32
|
+
feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting
|
33
|
+
feSpotLight feTile feTurbulence
|
34
|
+
filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject
|
35
|
+
g glyph glyphRef
|
36
|
+
hkern
|
37
|
+
image
|
38
|
+
line linearGradient
|
39
|
+
marker mask metadata missing-glyph mpath
|
40
|
+
path pattern polygon polyline
|
41
|
+
radialGradient rect
|
42
|
+
script set stop style svg switch symbol
|
43
|
+
text textPath tref tspan
|
44
|
+
use
|
45
|
+
view vkern
|
46
|
+
]
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
define_method(`element.toUpperCase()`) do |*args, &block|
|
54
|
-
`Opal.Preact.internal_prepare_args_and_render(element, args, block)`
|
55
|
-
end
|
48
|
+
SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
|
49
|
+
define_method(element) do |*args, &block|
|
50
|
+
`Opal.Preact.internal_prepare_args_and_render(element, args, block)`
|
56
51
|
end
|
57
|
-
|
58
|
-
|
59
|
-
`Opal.Preact.internal_prepare_args_and_render(Opal.global.Preact.Fragment, args, block)`
|
52
|
+
define_method(`element.toUpperCase()`) do |*args, &block|
|
53
|
+
`Opal.Preact.internal_prepare_args_and_render(element, args, block)`
|
60
54
|
end
|
61
55
|
end
|
56
|
+
|
57
|
+
def Fragment(*args, &block)
|
58
|
+
`Opal.Preact.internal_prepare_args_and_render(Opal.global.Preact.Fragment, args, block)`
|
59
|
+
end
|
62
60
|
end
|
data/lib/preact/version.rb
CHANGED