isomorfeus-preact 10.9.0 → 22.9.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +14 -3
- data/README.md +23 -39
- data/lib/browser/delegate_native.rb +94 -72
- data/lib/browser/document.rb +38 -0
- data/lib/browser/element.rb +160 -176
- data/lib/browser/event.rb +99 -94
- data/lib/browser/history.rb +40 -20
- data/lib/browser/location.rb +59 -0
- data/lib/browser/window.rb +58 -0
- data/lib/data_uri/open_uri.rb +18 -0
- data/lib/data_uri/uri.rb +61 -0
- data/lib/data_uri.rb +4 -0
- data/lib/isomorfeus/preact/config.rb +42 -54
- data/lib/isomorfeus/preact/imports.rb +5 -20
- data/lib/isomorfeus/preact/ssr.rb +34 -0
- data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
- data/lib/isomorfeus/preact/version.rb +5 -0
- data/lib/isomorfeus/preact/view_helper.rb +72 -0
- data/lib/isomorfeus/props/validator.rb +19 -11
- data/lib/isomorfeus/top_level.rb +55 -33
- data/lib/isomorfeus-preact.rb +78 -103
- data/lib/link.rb +52 -0
- data/lib/lucid_app.rb +117 -0
- data/lib/lucid_component.rb +154 -0
- data/lib/nano_css.rb +282 -465
- data/lib/preact/component.rb +222 -0
- data/lib/preact/component_resolution.rb +49 -83
- data/lib/preact/context.rb +68 -0
- data/lib/preact/elements.rb +2 -9
- data/lib/preact/module_component_resolution.rb +50 -0
- data/lib/preact/prop_declaration_mixin.rb +73 -0
- data/lib/preact.rb +1548 -257
- data/lib/redirect.rb +34 -0
- data/lib/route.rb +15 -0
- data/lib/router.rb +145 -0
- data/lib/switch.rb +70 -0
- data/opal/iso_uri.rb +29 -0
- data/opal/uri/common.rb +18 -0
- data/opal/uri/generic.rb +47 -0
- metadata +45 -309
- data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/ssr/history.rb +0 -23
- data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
- data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
- data/lib/isomorfeus/preact_view_helper.rb +0 -129
- data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
- data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
- data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
- data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
- data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
- data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
- data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
- data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
- data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
- data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
- data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -164
- data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
- data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
- data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
- data/lib/lucid_app/context.rb +0 -24
- data/lib/lucid_prop_declaration/mixin.rb +0 -126
- data/lib/preact/component/api.rb +0 -137
- data/lib/preact/component/base.rb +0 -7
- data/lib/preact/component/callbacks.rb +0 -111
- data/lib/preact/component/initializer.rb +0 -7
- data/lib/preact/component/mixin.rb +0 -11
- data/lib/preact/component/native_component_constructor.rb +0 -77
- data/lib/preact/context_wrapper.rb +0 -48
- data/lib/preact/native_constant_wrapper.rb +0 -29
- data/lib/preact/option_hooks.rb +0 -98
- data/lib/preact/params.rb +0 -16
- data/lib/preact/props.rb +0 -69
- data/lib/preact/ref.rb +0 -17
- data/lib/preact/state.rb +0 -87
- data/lib/preact/version.rb +0 -3
- data/node_modules/.package-lock.json +0 -38
- data/node_modules/preact/LICENSE +0 -21
- data/node_modules/preact/README.md +0 -188
- data/node_modules/preact/compat/LICENSE +0 -21
- data/node_modules/preact/compat/client.js +0 -19
- data/node_modules/preact/compat/client.mjs +0 -17
- data/node_modules/preact/compat/dist/compat.js +0 -2
- data/node_modules/preact/compat/dist/compat.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.mjs +0 -2
- data/node_modules/preact/compat/dist/compat.module.js +0 -2
- data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.umd.js +0 -2
- data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
- data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
- data/node_modules/preact/compat/jsx-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
- data/node_modules/preact/compat/package.json +0 -49
- data/node_modules/preact/compat/scheduler.js +0 -15
- data/node_modules/preact/compat/scheduler.mjs +0 -23
- data/node_modules/preact/compat/server.browser.js +0 -4
- data/node_modules/preact/compat/server.js +0 -15
- data/node_modules/preact/compat/server.mjs +0 -4
- data/node_modules/preact/compat/src/Children.js +0 -21
- data/node_modules/preact/compat/src/PureComponent.js +0 -15
- data/node_modules/preact/compat/src/forwardRef.js +0 -44
- data/node_modules/preact/compat/src/index.d.ts +0 -164
- data/node_modules/preact/compat/src/index.js +0 -223
- data/node_modules/preact/compat/src/internal.d.ts +0 -47
- data/node_modules/preact/compat/src/memo.js +0 -34
- data/node_modules/preact/compat/src/portals.js +0 -82
- data/node_modules/preact/compat/src/render.js +0 -238
- data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
- data/node_modules/preact/compat/src/suspense-list.js +0 -126
- data/node_modules/preact/compat/src/suspense.d.ts +0 -15
- data/node_modules/preact/compat/src/suspense.js +0 -270
- data/node_modules/preact/compat/src/util.js +0 -28
- data/node_modules/preact/compat/test-utils.js +0 -1
- data/node_modules/preact/debug/LICENSE +0 -21
- data/node_modules/preact/debug/dist/debug.js +0 -2
- data/node_modules/preact/debug/dist/debug.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.mjs +0 -2
- data/node_modules/preact/debug/dist/debug.module.js +0 -2
- data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.umd.js +0 -2
- data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
- data/node_modules/preact/debug/package.json +0 -26
- data/node_modules/preact/debug/src/check-props.js +0 -54
- data/node_modules/preact/debug/src/component-stack.js +0 -146
- data/node_modules/preact/debug/src/constants.js +0 -3
- data/node_modules/preact/debug/src/debug.js +0 -437
- data/node_modules/preact/debug/src/index.js +0 -6
- data/node_modules/preact/debug/src/internal.d.ts +0 -82
- data/node_modules/preact/debug/src/util.js +0 -11
- data/node_modules/preact/devtools/LICENSE +0 -21
- data/node_modules/preact/devtools/dist/devtools.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
- data/node_modules/preact/devtools/package.json +0 -25
- data/node_modules/preact/devtools/src/devtools.js +0 -10
- data/node_modules/preact/devtools/src/index.d.ts +0 -8
- data/node_modules/preact/devtools/src/index.js +0 -15
- data/node_modules/preact/dist/preact.js +0 -2
- data/node_modules/preact/dist/preact.js.map +0 -1
- data/node_modules/preact/dist/preact.min.js +0 -2
- data/node_modules/preact/dist/preact.min.js.map +0 -1
- data/node_modules/preact/dist/preact.mjs +0 -2
- data/node_modules/preact/dist/preact.module.js +0 -2
- data/node_modules/preact/dist/preact.module.js.map +0 -1
- data/node_modules/preact/dist/preact.umd.js +0 -2
- data/node_modules/preact/dist/preact.umd.js.map +0 -1
- data/node_modules/preact/hooks/LICENSE +0 -21
- data/node_modules/preact/hooks/dist/hooks.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
- data/node_modules/preact/hooks/package.json +0 -35
- data/node_modules/preact/hooks/src/index.d.ts +0 -139
- data/node_modules/preact/hooks/src/index.js +0 -417
- data/node_modules/preact/hooks/src/internal.d.ts +0 -78
- data/node_modules/preact/jsx-runtime/LICENSE +0 -21
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
- data/node_modules/preact/jsx-runtime/package.json +0 -28
- data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
- data/node_modules/preact/jsx-runtime/src/index.js +0 -77
- data/node_modules/preact/package.json +0 -304
- data/node_modules/preact/src/cjs.js +0 -3
- data/node_modules/preact/src/clone-element.js +0 -34
- data/node_modules/preact/src/component.js +0 -225
- data/node_modules/preact/src/constants.js +0 -3
- data/node_modules/preact/src/create-context.js +0 -68
- data/node_modules/preact/src/create-element.js +0 -98
- data/node_modules/preact/src/diff/catch-error.js +0 -40
- data/node_modules/preact/src/diff/children.js +0 -335
- data/node_modules/preact/src/diff/index.js +0 -533
- data/node_modules/preact/src/diff/props.js +0 -158
- data/node_modules/preact/src/index.d.ts +0 -317
- data/node_modules/preact/src/index.js +0 -13
- data/node_modules/preact/src/internal.d.ts +0 -155
- data/node_modules/preact/src/jsx.d.ts +0 -1014
- data/node_modules/preact/src/options.js +0 -16
- data/node_modules/preact/src/render.js +0 -75
- data/node_modules/preact/src/util.js +0 -27
- data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
- data/node_modules/preact/test-utils/package.json +0 -28
- data/node_modules/preact/test-utils/src/index.d.ts +0 -3
- data/node_modules/preact/test-utils/src/index.js +0 -118
- data/node_modules/preact-render-to-string/LICENSE +0 -21
- data/node_modules/preact-render-to-string/README.md +0 -102
- data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
- data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/dist/index.js +0 -1
- data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/jsx.js +0 -1
- data/node_modules/preact-render-to-string/package.json +0 -142
- data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/src/index.js +0 -462
- data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/src/jsx.js +0 -76
- data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
- data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/src/util.js +0 -78
- data/node_modules/preact-render-to-string/typings.json +0 -5
- data/node_modules/pretty-format/.npmignore +0 -3
- data/node_modules/pretty-format/LICENSE.md +0 -15
- data/node_modules/pretty-format/README.md +0 -94
- data/node_modules/pretty-format/index.js +0 -343
- data/node_modules/pretty-format/package.json +0 -26
- data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
- data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
- data/node_modules/pretty-format/printString.js +0 -7
- data/node_modules/wouter-preact/cjs/index.js +0 -180
- data/node_modules/wouter-preact/cjs/matcher.js +0 -72
- data/node_modules/wouter-preact/cjs/package.json +0 -1
- data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
- data/node_modules/wouter-preact/cjs/static-location.js +0 -21
- data/node_modules/wouter-preact/cjs/use-location.js +0 -94
- data/node_modules/wouter-preact/index.d.ts +0 -110
- data/node_modules/wouter-preact/index.js +0 -178
- data/node_modules/wouter-preact/matcher.d.ts +0 -30
- data/node_modules/wouter-preact/matcher.js +0 -66
- data/node_modules/wouter-preact/package.json +0 -33
- data/node_modules/wouter-preact/react-deps.js +0 -15
- data/node_modules/wouter-preact/static-location.d.ts +0 -16
- data/node_modules/wouter-preact/static-location.js +0 -17
- data/node_modules/wouter-preact/use-location.d.ts +0 -43
- data/node_modules/wouter-preact/use-location.js +0 -86
- data/package.json +0 -8
@@ -0,0 +1,222 @@
|
|
1
|
+
module Preact
|
2
|
+
class Component
|
3
|
+
extend Preact::PropDeclarationMixin
|
4
|
+
include Preact::Elements
|
5
|
+
include Preact::ComponentResolution
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def inherited(base)
|
9
|
+
base.instance_exec do
|
10
|
+
base_module = base.to_s.deconstantize
|
11
|
+
unless %w[LucidApp LucidComponent Preact::Component Preact::Context Fragment].include?(base_module)
|
12
|
+
if base_module != ''
|
13
|
+
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |props = nil, &block|
|
14
|
+
Preact._render_element(base, props, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :context_type
|
22
|
+
|
23
|
+
# lifecycle methods
|
24
|
+
|
25
|
+
def component_did_catch(&block)
|
26
|
+
define_method(:component_did_catch) do |error|
|
27
|
+
instance_exec(error, &block)
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def component_did_mount(&block)
|
33
|
+
define_method(:component_did_mount) do
|
34
|
+
instance_exec(&block)
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def component_did_update(&block)
|
40
|
+
define_method(:component_did_update) do |prev_props, prev_state, snapshot|
|
41
|
+
instance_exec(prev_props, prev_state, snapshot, &block)
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def component_will_unmount(&block)
|
47
|
+
define_method(:component_will_unmount) do
|
48
|
+
instance_exec do
|
49
|
+
@provider_subs.delete(self) if @provider_subs
|
50
|
+
end
|
51
|
+
instance_exec(&block)
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_derived_state_from_error(&block)
|
57
|
+
define_method(:get_derived_state_from_error) do |error|
|
58
|
+
instance_exec(error, &block)
|
59
|
+
new_state
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_derived_state_from_props(&block)
|
64
|
+
define_method(:get_derived_state_from_props) do |next_props, next_state|
|
65
|
+
instance_exec(next_props, next_state, &block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_snapshot_before_update(&block)
|
70
|
+
define_method(:get_snapshot_before_update) do |prev_props, prev_state|
|
71
|
+
instance_exec(prev_props, prev_state, &block)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def render(&block)
|
76
|
+
define_method(:render) do
|
77
|
+
pr = Preact.render_buffer
|
78
|
+
pr.push([])
|
79
|
+
block_result = instance_exec(&block)
|
80
|
+
if Preact.is_renderable?(block_result)
|
81
|
+
pr.pop.push(block_result)
|
82
|
+
else
|
83
|
+
pr.pop
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def should_component_update?(&block)
|
89
|
+
define_method(:should_component_update?) do |next_props, next_state, context|
|
90
|
+
instance_exec(next_props, next_state, context, &block)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# state
|
95
|
+
|
96
|
+
def state
|
97
|
+
@default_state ||= {}
|
98
|
+
end
|
99
|
+
|
100
|
+
def set_state(update)
|
101
|
+
state.merge!(update)
|
102
|
+
end
|
103
|
+
|
104
|
+
# refs
|
105
|
+
|
106
|
+
def ref(ref_name, &block)
|
107
|
+
@declared_refs = {} unless @declared_refs
|
108
|
+
@declared_refs[ref_name] = block
|
109
|
+
attr_reader ref_name
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
attr_accessor :provider_subs
|
114
|
+
attr_reader :context
|
115
|
+
attr_reader :props
|
116
|
+
attr_reader :state
|
117
|
+
|
118
|
+
if RUBY_ENGINE != 'opal'
|
119
|
+
attr_accessor :__d
|
120
|
+
attr_accessor :__s
|
121
|
+
attr_accessor :__v
|
122
|
+
attr_accessor :_dirty
|
123
|
+
attr_accessor :_next_state
|
124
|
+
end
|
125
|
+
|
126
|
+
def initialize(props, context)
|
127
|
+
@development = Isomorfeus.development?
|
128
|
+
@self_class = self.class
|
129
|
+
|
130
|
+
if RUBY_ENGINE == 'opal'
|
131
|
+
@state = `#@self_class.default_state`&.dup
|
132
|
+
declared_refs = `#@self_class.declared_refs`
|
133
|
+
else
|
134
|
+
@state = @self_class.instance_variable_get(:@default_state)&.dup
|
135
|
+
declared_refs = @self_class.instance_variable_get(:@declared_refs)
|
136
|
+
end
|
137
|
+
|
138
|
+
# props
|
139
|
+
@props = props
|
140
|
+
|
141
|
+
# state
|
142
|
+
@state = {} unless @state
|
143
|
+
|
144
|
+
# context
|
145
|
+
@context = context
|
146
|
+
@context_type = @self_class.context_type
|
147
|
+
|
148
|
+
# refs
|
149
|
+
declared_refs&.each do |ref_name, block|
|
150
|
+
if block
|
151
|
+
cmpnt = self
|
152
|
+
instance_variable_set("@#{ref_name}".to_sym, proc { |element| cmpnt.instance_exec(element, &block) })
|
153
|
+
else
|
154
|
+
instance_variable_set("@#{ref_name}".to_sym, { current: nil })
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
@method_cache = {}
|
159
|
+
end
|
160
|
+
|
161
|
+
def call(m)
|
162
|
+
return @method_cache[m] if @method_cache.key?(m)
|
163
|
+
@method_cache[m] = method(m)
|
164
|
+
end
|
165
|
+
|
166
|
+
def params
|
167
|
+
@props[:params] || {}
|
168
|
+
end
|
169
|
+
|
170
|
+
def component_will_unmount
|
171
|
+
@provider_subs.delete(self) if @provider_subs
|
172
|
+
end
|
173
|
+
|
174
|
+
def force_update(&block)
|
175
|
+
if @_vnode
|
176
|
+
# Set render mode so that we can differentiate where the render request
|
177
|
+
# is coming from. We need this because forceUpdate should never call
|
178
|
+
# should_component_update
|
179
|
+
@_force = true
|
180
|
+
@_renderCallbacks.push(block.to_n) if block_given?
|
181
|
+
Preact._enqueue_render(self)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def set_state(update, &block)
|
186
|
+
s = if @_nextState && @_nextState != @state
|
187
|
+
@_nextState
|
188
|
+
else
|
189
|
+
@_nextState = @state.dup
|
190
|
+
end
|
191
|
+
s = {} unless s
|
192
|
+
|
193
|
+
update = update.call(s, @props) if update.is_a?(Proc)
|
194
|
+
|
195
|
+
if update
|
196
|
+
s.merge!(update)
|
197
|
+
else
|
198
|
+
return
|
199
|
+
end
|
200
|
+
|
201
|
+
if @_vnode
|
202
|
+
@_renderCallbacks.push(block.to_n) if block_given?
|
203
|
+
Preact._enqueue_render(self)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def get_preact_element(arg, &block)
|
208
|
+
if block_given?
|
209
|
+
el = block.call
|
210
|
+
return el if el
|
211
|
+
end
|
212
|
+
Preact.render_buffer.last.pop
|
213
|
+
end
|
214
|
+
alias gpe get_preact_element
|
215
|
+
|
216
|
+
def render_preact_element(el)
|
217
|
+
Preact.render_buffer.last.push(el)
|
218
|
+
nil
|
219
|
+
end
|
220
|
+
alias rpe render_preact_element
|
221
|
+
end
|
222
|
+
end
|
@@ -1,100 +1,66 @@
|
|
1
1
|
module Preact::ComponentResolution
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
alias _preact_component_class_resolution_original_const_missing const_missing
|
6
|
-
end
|
7
|
-
|
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)};
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
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
|
26
|
-
|
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
|
-
try {
|
33
|
-
if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
|
34
|
-
} catch(err) {
|
35
|
-
return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
|
36
|
-
}
|
37
|
-
if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
|
38
|
-
constant = self.iso_preact_const_cache[component_name]
|
39
|
-
} else {
|
40
|
-
try {
|
41
|
-
constant = self.$const_get(component_name);
|
42
|
-
self.iso_preact_const_cache[component_name] = constant;
|
43
|
-
} catch(err) { }
|
44
|
-
}
|
45
|
-
if (constant && typeof constant.preact_component !== 'undefined') {
|
46
|
-
return Opal.Preact.internal_prepare_args_and_render(constant.preact_component, args, block);
|
47
|
-
}
|
48
|
-
return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
|
49
|
-
}
|
50
|
-
end
|
2
|
+
if RUBY_ENGINE == 'opal'
|
3
|
+
unless method_defined?(:_preact_component_resolution_original_method_missing)
|
4
|
+
alias _preact_component_resolution_original_method_missing method_missing
|
51
5
|
end
|
52
|
-
end
|
53
|
-
|
54
|
-
unless method_defined?(:_preact_component_resolution_original_method_missing)
|
55
|
-
alias _preact_component_resolution_original_method_missing method_missing
|
56
|
-
end
|
57
6
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
try {
|
65
|
-
if (typeof self.iso_preact_const_cache === 'undefined') { self.iso_preact_const_cache = {}; }
|
66
|
-
} catch(err) {
|
67
|
-
return #{_preact_component_resolution_original_method_missing(component_name, *args, block)};
|
68
|
-
}
|
69
|
-
if (typeof self.iso_preact_const_cache[component_name] !== 'undefined') {
|
70
|
-
constant = self.iso_preact_const_cache[component_name]
|
71
|
-
} else if (typeof self.$$is_a_module !== 'undefined') {
|
72
|
-
try {
|
73
|
-
constant = self.$const_get(component_name);
|
74
|
-
self.iso_preact_const_cache[component_name] = constant;
|
75
|
-
} catch(err) { }
|
76
|
-
} else {
|
7
|
+
def method_missing(component_name, *args, &block)
|
8
|
+
# Further on it must check for modules, because $const_get does not take
|
9
|
+
# the full nesting into account, as usually its called via $$ with the
|
10
|
+
# nesting provided by the compiler.
|
11
|
+
%x{
|
12
|
+
let constant;
|
77
13
|
let sc = self.$class();
|
78
14
|
try {
|
79
15
|
constant = sc.$const_get(component_name);
|
80
|
-
self.iso_preact_const_cache[component_name] = constant;
|
81
16
|
} catch(err) {
|
82
|
-
|
83
|
-
|
84
|
-
for (
|
17
|
+
let module_names = sc.$to_s().split("::");
|
18
|
+
let module_name;
|
19
|
+
for (let i = module_names.length - 1; i > 0; i--) {
|
85
20
|
module_name = module_names.slice(0, i).join('::');
|
86
21
|
try {
|
87
22
|
constant = sc.$const_get(module_name).$const_get(component_name, false);
|
88
|
-
self.iso_preact_const_cache[component_name] = constant;
|
89
23
|
break;
|
90
24
|
} catch(err) { }
|
91
25
|
}
|
92
26
|
}
|
27
|
+
if (constant) {
|
28
|
+
let last = args[args.length-1];
|
29
|
+
#{`Opal.Preact`._render_element(`constant`, `(last === undefined || last === null) ? nil : last`, &block)};
|
30
|
+
return nil;
|
31
|
+
}
|
32
|
+
return #{_preact_component_resolution_original_method_missing(component_name, *args, block)};
|
93
33
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
34
|
+
end
|
35
|
+
else
|
36
|
+
unless method_defined?(:_preact_component_resolution_original_method_missing)
|
37
|
+
alias _preact_component_resolution_original_method_missing method_missing
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_missing(component_name, *args, &block)
|
41
|
+
# Further on it must check for modules, because const_get does not take
|
42
|
+
# the full nesting into account
|
43
|
+
constant = nil
|
44
|
+
if self.is_a?(Module)
|
45
|
+
constant = const_get(component_name) rescue nil
|
46
|
+
else
|
47
|
+
begin
|
48
|
+
constant = self.class.const_get(component_name)
|
49
|
+
rescue
|
50
|
+
module_names = self.class.to_s.split('::')
|
51
|
+
module_names.each_index do |i|
|
52
|
+
module_name = module_names[0..i].join('::')
|
53
|
+
constant = self.class.const_get(module_name).const_get(component_name, false) rescue nil
|
54
|
+
break if constant
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
if constant
|
59
|
+
Preact._render_element(constant, args.last, &block)
|
60
|
+
nil
|
61
|
+
else
|
62
|
+
_preact_component_resolution_original_method_missing(component_name, *args, block)
|
63
|
+
end
|
64
|
+
end
|
99
65
|
end
|
100
66
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Preact
|
2
|
+
class Context
|
3
|
+
def self.create_application_contexts
|
4
|
+
Preact.create_context('LucidApplicationContext', { iso_location: "/", iso_store: {}, iso_theme: {} })
|
5
|
+
Preact.create_context('RouterContext', {})
|
6
|
+
end
|
7
|
+
|
8
|
+
class Provider < Preact::Component
|
9
|
+
attr_reader :context_id
|
10
|
+
attr_reader :subs
|
11
|
+
|
12
|
+
def initialize(props, context)
|
13
|
+
unless props.key?(:value)
|
14
|
+
props = props.merge({ value: get_default_value })
|
15
|
+
end
|
16
|
+
super(props, context)
|
17
|
+
@context_id = get_context_id
|
18
|
+
@child_context = { @context_id => self }
|
19
|
+
@getChildContext = true
|
20
|
+
@subs = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_child_context
|
24
|
+
@child_context
|
25
|
+
end
|
26
|
+
|
27
|
+
def render
|
28
|
+
@props[:children]
|
29
|
+
end
|
30
|
+
|
31
|
+
def should_component_update?(next_props, _next_state, _context)
|
32
|
+
if @props[:value] != next_props[:value]
|
33
|
+
@subs.each do |subc|
|
34
|
+
Preact._enqueue_render(subc)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def sub(component)
|
41
|
+
@subs.push(component)
|
42
|
+
component.provider_subs = @subs
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :context_id
|
47
|
+
attr_reader :Provider
|
48
|
+
attr_accessor :value
|
49
|
+
|
50
|
+
def initialize(default_value = nil)
|
51
|
+
@Provider = Class.new(Provider)
|
52
|
+
@value = default_value
|
53
|
+
@context_id = Preact._context_id
|
54
|
+
ctx = self
|
55
|
+
@Provider.define_method(:get_default_value) do
|
56
|
+
ctx.value
|
57
|
+
end
|
58
|
+
@Provider.define_method(:get_context_id) do
|
59
|
+
ctx.context_id
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def Consumer(&block)
|
64
|
+
block_result = block.call(@value)
|
65
|
+
Preact.render_buffer.last.push(block_result) if block_result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/preact/elements.rb
CHANGED
@@ -46,15 +46,8 @@ module Preact::Elements
|
|
46
46
|
]
|
47
47
|
|
48
48
|
SUPPORTED_HTML_AND_SVG_ELEMENTS.each do |element|
|
49
|
-
define_method(element) do
|
50
|
-
|
49
|
+
define_method(element.to_s.underscore.upcase.to_sym) do |props = nil, &block|
|
50
|
+
Preact._render_element(element, props, &block)
|
51
51
|
end
|
52
|
-
define_method(`element.toUpperCase()`) do |*args, &block|
|
53
|
-
`Opal.Preact.internal_prepare_args_and_render(element, args, block)`
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def Fragment(*args, &block)
|
58
|
-
`Opal.Preact.internal_prepare_args_and_render(Opal.global.Preact.Fragment, args, block)`
|
59
52
|
end
|
60
53
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Module
|
2
|
+
if RUBY_ENGINE == 'opal'
|
3
|
+
unless method_defined?(:_preact_component_class_resolution_original_method_missing)
|
4
|
+
alias _preact_component_class_resolution_original_method_missing method_missing
|
5
|
+
end
|
6
|
+
|
7
|
+
# this is required for autoloading support, as the component may not be loaded and so its method is not registered.
|
8
|
+
# must load it first, done by const_get, and next time the method will be there.
|
9
|
+
def method_missing(component_name, *args, &block)
|
10
|
+
# check for ruby component and render it
|
11
|
+
# otherwise pass on method missing
|
12
|
+
%x{
|
13
|
+
let constant = null;
|
14
|
+
let c = component_name[0];
|
15
|
+
if (c == c.toUpperCase()) {
|
16
|
+
try {
|
17
|
+
constant = self.$const_get(component_name);
|
18
|
+
} catch(err) { }
|
19
|
+
if (constant) {
|
20
|
+
let last = args[args.length-1];
|
21
|
+
#{`Opal.Preact`._render_element(`constant`, `(last === undefined || last === null) ? nil : last`, &block)};
|
22
|
+
return nil;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return #{_preact_component_class_resolution_original_method_missing(component_name, *args, block)};
|
26
|
+
}
|
27
|
+
end
|
28
|
+
else
|
29
|
+
unless method_defined?(:_preact_component_class_resolution_original_method_missing)
|
30
|
+
alias _preact_component_class_resolution_original_method_missing method_missing
|
31
|
+
end
|
32
|
+
|
33
|
+
# this is required for autoloading support, as the component may not be loaded and so its method is not registered.
|
34
|
+
# must load it first, done by const_get, and next time the method will be there.
|
35
|
+
def method_missing(component_name, *args, &block)
|
36
|
+
# check for ruby component and render it
|
37
|
+
# otherwise pass on method missing
|
38
|
+
component_name_s = component_name.to_s
|
39
|
+
c = component_name_s[0]
|
40
|
+
if c == c.upcase
|
41
|
+
constant = const_get(component_name) rescue nil
|
42
|
+
if constant && constant.ancestors.include?(Preact::Component)
|
43
|
+
Preact._render_element(constant, args.last, &block)
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
_preact_component_class_resolution_original_method_missing(component_name, *args, block)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Preact
|
2
|
+
module PropDeclarationMixin
|
3
|
+
def declared_props
|
4
|
+
@declared_props ||= {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def prop(prop_name, validate_hash = { required: true })
|
8
|
+
validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
|
9
|
+
declared_props[prop_name.to_sym] = validate_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid_prop?(prop, value)
|
13
|
+
validate_prop(prop, value)
|
14
|
+
rescue
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_props?(props)
|
19
|
+
validate_props(props)
|
20
|
+
rescue
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate
|
25
|
+
Isomorfeus::Props::ValidateHashProxy.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate_prop(prop, value)
|
29
|
+
return false unless declared_props.key?(prop)
|
30
|
+
validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
|
31
|
+
validator.validate!
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_props(props)
|
36
|
+
props = {} unless props
|
37
|
+
declared_props.each_key do |prop|
|
38
|
+
if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
|
39
|
+
Isomorfeus.raise_error(message: "Required prop '#{prop}' not given!")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
result = true
|
43
|
+
props.each do |p, v|
|
44
|
+
r = validate_prop(p, v)
|
45
|
+
result = false unless r
|
46
|
+
end
|
47
|
+
result
|
48
|
+
end
|
49
|
+
|
50
|
+
def validated_prop(prop, value)
|
51
|
+
Isomorfeus.raise_error(message: "No such prop '#{prop}' declared!") unless declared_props.key?(prop)
|
52
|
+
validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
|
53
|
+
validator.validated_value
|
54
|
+
end
|
55
|
+
|
56
|
+
def validated_props(props)
|
57
|
+
props = {} unless props
|
58
|
+
|
59
|
+
declared_props.each_key do |prop|
|
60
|
+
if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
|
61
|
+
Isomorfeus.raise_error(message: "Required prop '#{prop}' not given!")
|
62
|
+
end
|
63
|
+
props[prop] = nil unless props.key?(prop) # let validator handle value
|
64
|
+
end
|
65
|
+
|
66
|
+
result = {}
|
67
|
+
props.each do |p, v|
|
68
|
+
result[p] = validated_prop(p, v)
|
69
|
+
end
|
70
|
+
result
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|