isomorfeus-preact 10.9.0 → 22.9.0.rc1
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
- metadata +42 -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
@@ -1,56 +0,0 @@
|
|
1
|
-
module LucidFunc::NativeComponentConstructor
|
2
|
-
def self.extended(base)
|
3
|
-
component_name = base.to_s
|
4
|
-
%x{
|
5
|
-
base.css_styles = null;
|
6
|
-
base.instance_init = function(initial) {
|
7
|
-
let ruby_state = { instance: #{base.new(`{}`)} };
|
8
|
-
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
9
|
-
ruby_state.instance.data_access = function() { return this.props.iso_store; }
|
10
|
-
ruby_state.instance.data_access.bind(ruby_state.instance);
|
11
|
-
return ruby_state;
|
12
|
-
}
|
13
|
-
base.instance_reducer = function(state, action) { return state; }
|
14
|
-
base.preact_component = function(props) {
|
15
|
-
const og = Opal.global;
|
16
|
-
const oper = Opal.Preact;
|
17
|
-
oper.render_buffer.push([]);
|
18
|
-
// console.log("function pushed", oper.render_buffer, oper.render_buffer.toString());
|
19
|
-
// Lucid functionality
|
20
|
-
let context = og.PreactHooks.useContext(og.LucidApplicationContext);
|
21
|
-
// prepare Ruby instance
|
22
|
-
const [__ruby_state, __ruby_dispatch] = og.PreactHooks.useReducer(base.instance_reducer, null, base.instance_init);
|
23
|
-
const __ruby_instance = __ruby_state.instance;
|
24
|
-
__ruby_instance.props = Object.assign({}, props, context);
|
25
|
-
oper.register_active_component(__ruby_instance);
|
26
|
-
try {
|
27
|
-
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
28
|
-
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
29
|
-
} catch (e) {
|
30
|
-
if (oper.using_did_catch) { throw e; }
|
31
|
-
else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
32
|
-
}
|
33
|
-
oper.unregister_active_component(__ruby_instance);
|
34
|
-
// console.log("function popping", oper.render_buffer, oper.render_buffer.toString());
|
35
|
-
let result = oper.render_buffer.pop();
|
36
|
-
return (result.length === 1) ? result[0] : result;
|
37
|
-
};
|
38
|
-
base.preact_component.displayName = #{component_name};
|
39
|
-
}
|
40
|
-
|
41
|
-
base_module = base.to_s.deconstantize
|
42
|
-
if base_module != ''
|
43
|
-
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
44
|
-
`Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
|
45
|
-
end
|
46
|
-
else
|
47
|
-
Object.define_method(base.to_s) do |*args, &block|
|
48
|
-
`Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def render(&block)
|
53
|
-
`base.render_block = #{block}`
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
module Preact::FunctionComponent::Api
|
2
|
-
def self.included(base)
|
3
|
-
base.instance_exec do
|
4
|
-
def to_js
|
5
|
-
self.JS[:preact_component]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def props
|
11
|
-
@native_props
|
12
|
-
end
|
13
|
-
|
14
|
-
def use_callback(*deps, &block)
|
15
|
-
`Opal.global.PreactHooks.useCallback(function() { #{block.call} }, deps)`
|
16
|
-
end
|
17
|
-
|
18
|
-
def use_context(context)
|
19
|
-
native_context = `(typeof context.$is_wrapped_context !== 'undefined')` ? context.to_n : context
|
20
|
-
`Opal.global.PreactHooks.useContext(native_context)`
|
21
|
-
end
|
22
|
-
|
23
|
-
def use_debug_value(value, formatter)
|
24
|
-
formatter = `null` unless formatter
|
25
|
-
`Opal.global.PreactHooks.useDebugValue(value, formatter)`
|
26
|
-
end
|
27
|
-
|
28
|
-
def use_deferred_value(value)
|
29
|
-
`Opal.global.PreactHooks.useDeferredValue(value)`
|
30
|
-
end
|
31
|
-
|
32
|
-
def use_effect(*args, &block)
|
33
|
-
`Opal.global.PreactHooks.useEffect(function() { #{block.call} }, args)`
|
34
|
-
end
|
35
|
-
|
36
|
-
def use_error_boundary(&block)
|
37
|
-
error = nil
|
38
|
-
reset_error = nil
|
39
|
-
%x{
|
40
|
-
let _error;
|
41
|
-
let _reset_error;
|
42
|
-
if (block) {
|
43
|
-
[_error, reset_error] = Opal.global.PreactHooks.useErrorBoundary(function() { #{block.call(Error(_error))} });
|
44
|
-
} else {
|
45
|
-
[_error, reset_error] = Opal.global.PreactHooks.useErrorBoundary();
|
46
|
-
}
|
47
|
-
error = #{Error(e)};
|
48
|
-
}
|
49
|
-
[error, reset_error]
|
50
|
-
end
|
51
|
-
|
52
|
-
def use_id
|
53
|
-
`Opal.global.PreactHooks.useId()`
|
54
|
-
end
|
55
|
-
|
56
|
-
def use_imperative_handle(ruby_ref, *args, &block)
|
57
|
-
ref = ruby_ref.to_n
|
58
|
-
args = `null` if args.empty?
|
59
|
-
`Opal.global.PreactHooks.useImperativeHandle(ref, function() { #{block.call} }, args)`
|
60
|
-
end
|
61
|
-
|
62
|
-
def use_insertion_effect
|
63
|
-
`Opal.global.PreactHooks.useInsertionEffect(function() { #{block.call} }, args)`
|
64
|
-
end
|
65
|
-
|
66
|
-
def use_layout_effect(&block)
|
67
|
-
`Opal.global.PreactHooks.useLayoutEffect(function() { #{block.call} })`
|
68
|
-
end
|
69
|
-
|
70
|
-
def use_memo(*deps, &block)
|
71
|
-
`Opal.global.PreactHooks.useMemo(function() { #{block.call} }, deps)`
|
72
|
-
end
|
73
|
-
|
74
|
-
def use_reducer(inital_state, &block)
|
75
|
-
state = nil
|
76
|
-
dispatcher = nil
|
77
|
-
%x{
|
78
|
-
[state, dispatcher] = Opal.global.PreactHooks.useReducer(function(state, action) {
|
79
|
-
#{block.call(state, action)}
|
80
|
-
}, initial_state);
|
81
|
-
}
|
82
|
-
[state, proc { |arg| `dispatcher(arg)` }]
|
83
|
-
end
|
84
|
-
|
85
|
-
def use_ref(native_ref)
|
86
|
-
Preact::Ref.new(`Opal.global.PreactHooks.useRef(native_ref)`)
|
87
|
-
end
|
88
|
-
|
89
|
-
def use_state(initial_value)
|
90
|
-
initial = nil
|
91
|
-
setter = nil
|
92
|
-
`[initial, setter] = Opal.global.PreactHooks.useState(initial_value);`
|
93
|
-
[initial, proc { |arg| `setter(arg)` }]
|
94
|
-
end
|
95
|
-
|
96
|
-
def use_sync_external_store(subscribe, get_snapshot, get_server_snapshot)
|
97
|
-
gss = get_server_snapshot.nil? ? `null` : `function() { return #{get_server_snapshot.call} }`
|
98
|
-
`Opal.global.PreactHooks.useSyncExternalStore(function() { #{subscribe.call} }, function() { return #{get_snapshot.call}}, gss)`
|
99
|
-
end
|
100
|
-
|
101
|
-
def use_transition
|
102
|
-
is_pending = nil
|
103
|
-
start_transition = nil
|
104
|
-
`[is_pending, start_transition] = Opal.global.PreactHooks.useTransition()`
|
105
|
-
[is_pending, proc { |arg| `start_transition(function(){#{arg&.call}})`}]
|
106
|
-
end
|
107
|
-
|
108
|
-
def get_preact_element(arg, &block)
|
109
|
-
`let operabu = Opal.Preact.render_buffer`
|
110
|
-
if block_given?
|
111
|
-
# execute block, fetch last element from buffer
|
112
|
-
%x{
|
113
|
-
let last_buffer_length = operabu[operabu.length - 1].length;
|
114
|
-
let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
|
115
|
-
block.$call();
|
116
|
-
// console.log("get_preact_element popping", operabu, operabu.toString())
|
117
|
-
let new_element = operabu[operabu.length - 1].pop();
|
118
|
-
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
|
119
|
-
return new_element;
|
120
|
-
}
|
121
|
-
else
|
122
|
-
# element was rendered before being passed as arg
|
123
|
-
# fetch last element from buffer
|
124
|
-
# `console.log("get_preact_element popping", operabu, operabu.toString())`
|
125
|
-
`operabu[operabu.length - 1].pop()`
|
126
|
-
end
|
127
|
-
end
|
128
|
-
alias gpe get_preact_element
|
129
|
-
|
130
|
-
def history
|
131
|
-
Isomorfeus.browser_history
|
132
|
-
end
|
133
|
-
|
134
|
-
def render_preact_element(el)
|
135
|
-
# push el to buffer
|
136
|
-
`Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
|
137
|
-
# `console.log("render_preact_element pushed", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
|
138
|
-
nil
|
139
|
-
end
|
140
|
-
alias rpe render_preact_element
|
141
|
-
|
142
|
-
def method_ref(method_symbol, *args)
|
143
|
-
method_key = "#{method_symbol}#{args}"
|
144
|
-
%x{
|
145
|
-
if (#{self}.method_refs?.[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
|
146
|
-
if (!#{self}.method_refs) { #{self}.method_refs = {}; }
|
147
|
-
#{self}.method_refs[#{method_key}] = { m: null, a: args };
|
148
|
-
let r = #{self}.method_refs[#{method_key}];
|
149
|
-
let dev = #{Isomorfeus.development?};
|
150
|
-
r.preact_event_handler_function = function(event, info) {
|
151
|
-
let ruby_event = Opal.Preact.native_to_ruby_event(event);
|
152
|
-
if (!r.m || dev) { r.m = #{method(method_symbol)} };
|
153
|
-
if (r.a.length > 0) { r.m.$call.apply(r.m, [ruby_event, info].concat(r.a)); }
|
154
|
-
else { r.m.$call(ruby_event, info); }
|
155
|
-
};
|
156
|
-
return #{self}.method_refs[#{method_key}];
|
157
|
-
}
|
158
|
-
end
|
159
|
-
alias m_ref method_ref
|
160
|
-
|
161
|
-
def to_n
|
162
|
-
self
|
163
|
-
end
|
164
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
module Preact::FunctionComponent::Mixin
|
2
|
-
def self.included(base)
|
3
|
-
base.include(::Preact::Elements)
|
4
|
-
base.include(::Preact::FunctionComponent::Initializer)
|
5
|
-
base.include(::Preact::FunctionComponent::Api)
|
6
|
-
base.extend(::Preact::FunctionComponent::NativeComponentConstructor)
|
7
|
-
end
|
8
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Preact::FunctionComponent::NativeComponentConstructor
|
2
|
-
def self.extended(base)
|
3
|
-
component_name = base.to_s
|
4
|
-
%x{
|
5
|
-
base.instance_init = function(initial) {
|
6
|
-
let ruby_state = { instance: #{base.new(`{}`)} };
|
7
|
-
ruby_state.instance.__ruby_instance = ruby_state.instance;
|
8
|
-
return ruby_state;
|
9
|
-
}
|
10
|
-
base.instance_reducer = function(state, action) { return state; }
|
11
|
-
base.preact_component = function(props) {
|
12
|
-
const oper = Opal.Preact;
|
13
|
-
oper.render_buffer.push([]);
|
14
|
-
const [__ruby_state, __ruby_dispatch] = Opal.global.PreactHooks.useReducer(base.instance_reducer, null, base.instance_init);
|
15
|
-
const __ruby_instance = __ruby_state.instance;
|
16
|
-
__ruby_instance.props = props;
|
17
|
-
oper.register_active_component(__ruby_instance);
|
18
|
-
try {
|
19
|
-
let block_result = #{`__ruby_instance`.instance_exec(&`base.render_block`)};
|
20
|
-
if (block_result && block_result !== nil) { oper.render_block_result(block_result); }
|
21
|
-
} catch (e) {
|
22
|
-
if (oper.using_did_catch) { throw e; }
|
23
|
-
else { console.error(e.message === nil ? 'error at' : e.message, e.stack); }
|
24
|
-
}
|
25
|
-
oper.unregister_active_component(__ruby_instance);
|
26
|
-
let result = oper.render_buffer.pop();
|
27
|
-
return (result.length === 1) ? result[0] : result;
|
28
|
-
}
|
29
|
-
base.preact_component.displayName = #{component_name};
|
30
|
-
}
|
31
|
-
|
32
|
-
base_module = base.to_s.deconstantize
|
33
|
-
if base_module != ''
|
34
|
-
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
35
|
-
`Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
|
36
|
-
end
|
37
|
-
else
|
38
|
-
Object.define_method(base.to_s) do |*args, &block|
|
39
|
-
`Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def render(&block)
|
44
|
-
`base.render_block = #{block}`
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/lucid_app/context.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module LucidApp
|
2
|
-
module Context
|
3
|
-
def self.create_application_context
|
4
|
-
nano_css = `null`
|
5
|
-
css_server = `null`
|
6
|
-
css_server = `document.getElementById('css-server-side')` unless on_ssr?
|
7
|
-
%x{
|
8
|
-
let n = Opal.NanoCSS;
|
9
|
-
nano_css = (css_server) ? n.create({ sh: css_server }) : n.create();
|
10
|
-
n.rule(nano_css);
|
11
|
-
n.sheet(nano_css);
|
12
|
-
n.nesting(nano_css);
|
13
|
-
n.hydrate(nano_css);
|
14
|
-
n.unitless(nano_css);
|
15
|
-
n.global(nano_css);
|
16
|
-
n.keyframes(nano_css);
|
17
|
-
n.fadeIn(nano_css);
|
18
|
-
n.fadeOut(nano_css);
|
19
|
-
Opal.global.NanoCSSInstance = nano_css;
|
20
|
-
}
|
21
|
-
Preact.create_context('LucidApplicationContext', { iso_store: Isomorfeus.store, nano_css: nano_css })
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
module LucidPropDeclaration
|
2
|
-
module Mixin
|
3
|
-
if RUBY_ENGINE == 'opal'
|
4
|
-
def self.extended(base)
|
5
|
-
def prop(prop_name, validate_hash = { required: true })
|
6
|
-
validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
|
7
|
-
if validate_hash.key?(:default)
|
8
|
-
%x{
|
9
|
-
if (base.lucid_preact_component) {
|
10
|
-
let preact_prop_name = Opal.Preact.lower_camelize(prop_name);
|
11
|
-
#{value = validate_hash[:default]}
|
12
|
-
if (!base.lucid_preact_component.defaultProps) { base.lucid_preact_component.defaultProps = {}; }
|
13
|
-
base.lucid_preact_component.defaultProps[preact_prop_name] = value;
|
14
|
-
if (!base.lucid_preact_component.propTypes) { base.lucid_preact_component.propTypes = {}; }
|
15
|
-
base.lucid_preact_component.propTypes[preact_prop_name] = base.lucid_preact_component.prototype.validateProp;
|
16
|
-
} else if (base.preact_component) {
|
17
|
-
let preact_prop_name = Opal.Preact.lower_camelize(prop_name);
|
18
|
-
#{value = validate_hash[:default]}
|
19
|
-
if (!base.preact_component.defaultProps) { base.preact_component.defaultProps = {}; }
|
20
|
-
base.preact_component.defaultProps[preact_prop_name] = value;
|
21
|
-
if (!base.preact_component.propTypes) { base.preact_component.propTypes = {}; }
|
22
|
-
base.preact_component.propTypes[preact_prop_name] = base.preact_component.prototype.validateProp;
|
23
|
-
}
|
24
|
-
}
|
25
|
-
end
|
26
|
-
declared_props[prop_name.to_sym] = validate_hash
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def validate_function
|
31
|
-
%x{
|
32
|
-
if (typeof self.validate_function === 'undefined') {
|
33
|
-
self.validate_function = function(props_object) {
|
34
|
-
try { self.$validate_props(Opal.Hash.$new(props_object)) }
|
35
|
-
catch (e) { return e.message; }
|
36
|
-
}
|
37
|
-
}
|
38
|
-
return self.validate_function;
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def validate_prop_function(prop)
|
43
|
-
function_name = "validate_#{prop}_function"
|
44
|
-
%x{
|
45
|
-
if (typeof self[function_name] === 'undefined') {
|
46
|
-
self[function_name] = function(value) {
|
47
|
-
try { self.$validate_prop(prop, value); }
|
48
|
-
catch (e) { return e.message; }
|
49
|
-
}
|
50
|
-
}
|
51
|
-
return self[function_name];
|
52
|
-
}
|
53
|
-
end
|
54
|
-
else
|
55
|
-
def prop(prop_name, validate_hash = { required: true })
|
56
|
-
validate_hash = validate_hash.to_h if validate_hash.class == Isomorfeus::Props::ValidateHashProxy
|
57
|
-
declared_props[prop_name.to_sym] = validate_hash
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def declared_props
|
62
|
-
@declared_props ||= {}
|
63
|
-
end
|
64
|
-
|
65
|
-
def valid_prop?(prop, value)
|
66
|
-
validate_prop(prop, value)
|
67
|
-
rescue
|
68
|
-
false
|
69
|
-
end
|
70
|
-
|
71
|
-
def valid_props?(props)
|
72
|
-
validate_props(props)
|
73
|
-
rescue
|
74
|
-
false
|
75
|
-
end
|
76
|
-
|
77
|
-
def validate
|
78
|
-
Isomorfeus::Props::ValidateHashProxy.new
|
79
|
-
end
|
80
|
-
|
81
|
-
def validate_prop(prop, value)
|
82
|
-
return false unless declared_props.key?(prop)
|
83
|
-
validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
|
84
|
-
validator.validate!
|
85
|
-
true
|
86
|
-
end
|
87
|
-
|
88
|
-
def validate_props(props)
|
89
|
-
props = {} unless props
|
90
|
-
declared_props.each_key do |prop|
|
91
|
-
if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
|
92
|
-
Isomorfeus.raise_error(message: "Required prop '#{prop}' not given!")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
result = true
|
96
|
-
props.each do |p, v|
|
97
|
-
r = validate_prop(p, v)
|
98
|
-
result = false unless r
|
99
|
-
end
|
100
|
-
result
|
101
|
-
end
|
102
|
-
|
103
|
-
def validated_prop(prop, value)
|
104
|
-
Isomorfeus.raise_error(message: "No such prop '#{prop}' declared!") unless declared_props.key?(prop)
|
105
|
-
validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
|
106
|
-
validator.validated_value
|
107
|
-
end
|
108
|
-
|
109
|
-
def validated_props(props)
|
110
|
-
props = {} unless props
|
111
|
-
|
112
|
-
declared_props.each_key do |prop|
|
113
|
-
if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
|
114
|
-
Isomorfeus.raise_error(message: "Required prop '#{prop}' not given!")
|
115
|
-
end
|
116
|
-
props[prop] = nil unless props.key?(prop) # let validator handle value
|
117
|
-
end
|
118
|
-
|
119
|
-
result = {}
|
120
|
-
props.each do |p, v|
|
121
|
-
result[p] = validated_prop(p, v)
|
122
|
-
end
|
123
|
-
result
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
data/lib/preact/component/api.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
module Preact::Component::Api
|
2
|
-
def self.included(base)
|
3
|
-
base.instance_exec do
|
4
|
-
base_module = base.to_s.deconstantize
|
5
|
-
if base_module != ''
|
6
|
-
base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
|
7
|
-
`Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
|
8
|
-
end
|
9
|
-
else
|
10
|
-
Object.define_method(base.to_s) do |*args, &block|
|
11
|
-
`Opal.Preact.internal_prepare_args_and_render(#{base}.preact_component, args, block)`
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_accessor :props
|
16
|
-
attr_accessor :state
|
17
|
-
|
18
|
-
def ref(ref_name, &block)
|
19
|
-
defined_refs.JS[ref_name] = block_given? ? block : `null`
|
20
|
-
end
|
21
|
-
|
22
|
-
def defined_refs
|
23
|
-
@defined_refs ||= `{}`
|
24
|
-
end
|
25
|
-
|
26
|
-
def default_state_defined
|
27
|
-
@default_state_defined
|
28
|
-
end
|
29
|
-
|
30
|
-
def state
|
31
|
-
return @default_state if @default_state
|
32
|
-
@default_state_defined = true
|
33
|
-
%x{
|
34
|
-
var native_state = {state: {}};
|
35
|
-
native_state.setState = function(new_state, callback) {
|
36
|
-
for (var key in new_state) {
|
37
|
-
this.state[key] = new_state[key];
|
38
|
-
}
|
39
|
-
if (callback) { callback.call(); }
|
40
|
-
}
|
41
|
-
}
|
42
|
-
@default_state = `Opal.Preact.State.$new(native_state)`
|
43
|
-
end
|
44
|
-
|
45
|
-
def render(&block)
|
46
|
-
`base.render_block = #{block}`
|
47
|
-
end
|
48
|
-
|
49
|
-
def should_component_update?(&block)
|
50
|
-
`base.should_component_update_block = block`
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_js
|
54
|
-
self.JS[:preact_component]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def display_name
|
60
|
-
@native.JS[:displayName]
|
61
|
-
end
|
62
|
-
|
63
|
-
def force_update(&block)
|
64
|
-
if block_given?
|
65
|
-
# this maybe needs instance_exec too
|
66
|
-
@native.JS.forceUpdate(`function() { block.$call(); }`)
|
67
|
-
else
|
68
|
-
@native.JS.forceUpdate
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_preact_element(arg, &block)
|
73
|
-
`const operabu = Opal.Preact.render_buffer`
|
74
|
-
if block_given?
|
75
|
-
# execute block, fetch last element from buffer
|
76
|
-
%x{
|
77
|
-
let last_buffer_length = operabu[operabu.length - 1].length;
|
78
|
-
let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
|
79
|
-
block.$call();
|
80
|
-
// console.log("get_preact_element popping", operabu, operabu.toString())
|
81
|
-
let new_element = operabu[operabu.length - 1].pop();
|
82
|
-
if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
|
83
|
-
return new_element;
|
84
|
-
}
|
85
|
-
else
|
86
|
-
# element was rendered before being passed as arg
|
87
|
-
# fetch last element from buffer
|
88
|
-
# `console.log("get_preact_element popping", operabu, operabu.toString())`
|
89
|
-
`operabu[operabu.length - 1].pop()`
|
90
|
-
end
|
91
|
-
end
|
92
|
-
alias gpe get_preact_element
|
93
|
-
|
94
|
-
def history
|
95
|
-
Isomorfeus.browser_history
|
96
|
-
end
|
97
|
-
|
98
|
-
def method_ref(method_symbol, *args)
|
99
|
-
method_key = "#{method_symbol}#{args}"
|
100
|
-
%x{
|
101
|
-
if (#@native.method_refs?.[#{method_key}]) { return #@native.method_refs[#{method_key}]; }
|
102
|
-
if (!#@native.method_refs) { #@native.method_refs = {}; }
|
103
|
-
#@native.method_refs[#{method_key}] = { m: null, a: args };
|
104
|
-
let r = #@native.method_refs[#{method_key}];
|
105
|
-
let dev = #{Isomorfeus.development?};
|
106
|
-
r.preact_event_handler_function = function(event, info) {
|
107
|
-
let ruby_event = Opal.Preact.native_to_ruby_event(event);
|
108
|
-
if (!r.m || dev) { r.m = #{method(method_symbol)} };
|
109
|
-
if (r.a.length > 0) { r.m.$call.apply(r.m, [ruby_event, info].concat(r.a)); }
|
110
|
-
else { r.m.$call(ruby_event, info); }
|
111
|
-
};
|
112
|
-
return #@native.method_refs[#{method_key}];
|
113
|
-
}
|
114
|
-
end
|
115
|
-
alias m_ref method_ref
|
116
|
-
|
117
|
-
def render_preact_element(el)
|
118
|
-
# push el to buffer
|
119
|
-
`Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
|
120
|
-
# `console.log("render_preact_element pushed", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
|
121
|
-
nil
|
122
|
-
end
|
123
|
-
alias rpe render_preact_element
|
124
|
-
|
125
|
-
def ref(name)
|
126
|
-
`#@native[name]`
|
127
|
-
end
|
128
|
-
|
129
|
-
def ruby_ref(name)
|
130
|
-
return `#@native[name]` if `(typeof #@native[name] === 'function')`
|
131
|
-
`Opal.Preact.Ref.$new(#@native[name])`
|
132
|
-
end
|
133
|
-
|
134
|
-
def set_state(updater, &callback)
|
135
|
-
@state.set_state(updater, &callback)
|
136
|
-
end
|
137
|
-
end
|