isomorfeus-preact 10.8.2 → 22.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +14 -3
  3. data/README.md +23 -39
  4. data/lib/browser/delegate_native.rb +94 -72
  5. data/lib/browser/document.rb +38 -0
  6. data/lib/browser/element.rb +160 -176
  7. data/lib/browser/event.rb +99 -94
  8. data/lib/browser/history.rb +40 -20
  9. data/lib/browser/location.rb +59 -0
  10. data/lib/browser/window.rb +58 -0
  11. data/lib/data_uri/open_uri.rb +18 -0
  12. data/lib/data_uri/uri.rb +61 -0
  13. data/lib/data_uri.rb +4 -0
  14. data/lib/isomorfeus/preact/config.rb +42 -54
  15. data/lib/isomorfeus/preact/imports.rb +5 -20
  16. data/lib/isomorfeus/preact/ssr.rb +34 -0
  17. data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
  18. data/lib/isomorfeus/preact/version.rb +5 -0
  19. data/lib/isomorfeus/preact/view_helper.rb +72 -0
  20. data/lib/isomorfeus/props/validator.rb +19 -11
  21. data/lib/isomorfeus/top_level.rb +55 -33
  22. data/lib/isomorfeus-preact.rb +78 -103
  23. data/lib/link.rb +52 -0
  24. data/lib/lucid_app.rb +117 -0
  25. data/lib/lucid_component.rb +154 -0
  26. data/lib/nano_css.rb +282 -465
  27. data/lib/preact/component.rb +222 -0
  28. data/lib/preact/component_resolution.rb +49 -83
  29. data/lib/preact/context.rb +68 -0
  30. data/lib/preact/elements.rb +2 -9
  31. data/lib/preact/module_component_resolution.rb +50 -0
  32. data/lib/preact/prop_declaration_mixin.rb +73 -0
  33. data/lib/preact.rb +1548 -257
  34. data/lib/redirect.rb +34 -0
  35. data/lib/route.rb +15 -0
  36. data/lib/router.rb +145 -0
  37. data/lib/switch.rb +70 -0
  38. metadata +42 -309
  39. data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
  40. data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
  41. data/lib/isomorfeus/preact/ssr/history.rb +0 -23
  42. data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
  43. data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
  44. data/lib/isomorfeus/preact_view_helper.rb +0 -129
  45. data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
  46. data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
  47. data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
  48. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
  49. data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
  50. data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
  51. data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
  52. data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
  53. data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
  54. data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
  55. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
  56. data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
  57. data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
  58. data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
  59. data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
  60. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
  61. data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -140
  62. data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
  63. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
  64. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
  65. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
  66. data/lib/lucid_app/context.rb +0 -24
  67. data/lib/lucid_prop_declaration/mixin.rb +0 -126
  68. data/lib/preact/component/api.rb +0 -137
  69. data/lib/preact/component/base.rb +0 -7
  70. data/lib/preact/component/callbacks.rb +0 -111
  71. data/lib/preact/component/initializer.rb +0 -7
  72. data/lib/preact/component/mixin.rb +0 -11
  73. data/lib/preact/component/native_component_constructor.rb +0 -77
  74. data/lib/preact/context_wrapper.rb +0 -48
  75. data/lib/preact/native_constant_wrapper.rb +0 -29
  76. data/lib/preact/option_hooks.rb +0 -98
  77. data/lib/preact/params.rb +0 -16
  78. data/lib/preact/props.rb +0 -69
  79. data/lib/preact/ref.rb +0 -17
  80. data/lib/preact/state.rb +0 -87
  81. data/lib/preact/version.rb +0 -3
  82. data/node_modules/.package-lock.json +0 -38
  83. data/node_modules/preact/LICENSE +0 -21
  84. data/node_modules/preact/README.md +0 -188
  85. data/node_modules/preact/compat/LICENSE +0 -21
  86. data/node_modules/preact/compat/client.js +0 -19
  87. data/node_modules/preact/compat/client.mjs +0 -17
  88. data/node_modules/preact/compat/dist/compat.js +0 -2
  89. data/node_modules/preact/compat/dist/compat.js.map +0 -1
  90. data/node_modules/preact/compat/dist/compat.mjs +0 -2
  91. data/node_modules/preact/compat/dist/compat.module.js +0 -2
  92. data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
  93. data/node_modules/preact/compat/dist/compat.umd.js +0 -2
  94. data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
  95. data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
  96. data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
  97. data/node_modules/preact/compat/jsx-runtime.js +0 -3
  98. data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
  99. data/node_modules/preact/compat/package.json +0 -49
  100. data/node_modules/preact/compat/scheduler.js +0 -15
  101. data/node_modules/preact/compat/scheduler.mjs +0 -23
  102. data/node_modules/preact/compat/server.browser.js +0 -4
  103. data/node_modules/preact/compat/server.js +0 -15
  104. data/node_modules/preact/compat/server.mjs +0 -4
  105. data/node_modules/preact/compat/src/Children.js +0 -21
  106. data/node_modules/preact/compat/src/PureComponent.js +0 -15
  107. data/node_modules/preact/compat/src/forwardRef.js +0 -44
  108. data/node_modules/preact/compat/src/index.d.ts +0 -155
  109. data/node_modules/preact/compat/src/index.js +0 -187
  110. data/node_modules/preact/compat/src/internal.d.ts +0 -47
  111. data/node_modules/preact/compat/src/memo.js +0 -34
  112. data/node_modules/preact/compat/src/portals.js +0 -82
  113. data/node_modules/preact/compat/src/render.js +0 -238
  114. data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
  115. data/node_modules/preact/compat/src/suspense-list.js +0 -126
  116. data/node_modules/preact/compat/src/suspense.d.ts +0 -15
  117. data/node_modules/preact/compat/src/suspense.js +0 -270
  118. data/node_modules/preact/compat/src/util.js +0 -28
  119. data/node_modules/preact/compat/test-utils.js +0 -1
  120. data/node_modules/preact/debug/LICENSE +0 -21
  121. data/node_modules/preact/debug/dist/debug.js +0 -2
  122. data/node_modules/preact/debug/dist/debug.js.map +0 -1
  123. data/node_modules/preact/debug/dist/debug.mjs +0 -2
  124. data/node_modules/preact/debug/dist/debug.module.js +0 -2
  125. data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
  126. data/node_modules/preact/debug/dist/debug.umd.js +0 -2
  127. data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
  128. data/node_modules/preact/debug/package.json +0 -26
  129. data/node_modules/preact/debug/src/check-props.js +0 -54
  130. data/node_modules/preact/debug/src/component-stack.js +0 -146
  131. data/node_modules/preact/debug/src/constants.js +0 -3
  132. data/node_modules/preact/debug/src/debug.js +0 -437
  133. data/node_modules/preact/debug/src/index.js +0 -6
  134. data/node_modules/preact/debug/src/internal.d.ts +0 -82
  135. data/node_modules/preact/debug/src/util.js +0 -11
  136. data/node_modules/preact/devtools/LICENSE +0 -21
  137. data/node_modules/preact/devtools/dist/devtools.js +0 -2
  138. data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
  139. data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
  140. data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
  141. data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
  142. data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
  143. data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
  144. data/node_modules/preact/devtools/package.json +0 -25
  145. data/node_modules/preact/devtools/src/devtools.js +0 -10
  146. data/node_modules/preact/devtools/src/index.d.ts +0 -8
  147. data/node_modules/preact/devtools/src/index.js +0 -15
  148. data/node_modules/preact/dist/preact.js +0 -2
  149. data/node_modules/preact/dist/preact.js.map +0 -1
  150. data/node_modules/preact/dist/preact.min.js +0 -2
  151. data/node_modules/preact/dist/preact.min.js.map +0 -1
  152. data/node_modules/preact/dist/preact.mjs +0 -2
  153. data/node_modules/preact/dist/preact.module.js +0 -2
  154. data/node_modules/preact/dist/preact.module.js.map +0 -1
  155. data/node_modules/preact/dist/preact.umd.js +0 -2
  156. data/node_modules/preact/dist/preact.umd.js.map +0 -1
  157. data/node_modules/preact/hooks/LICENSE +0 -21
  158. data/node_modules/preact/hooks/dist/hooks.js +0 -2
  159. data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
  160. data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
  161. data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
  162. data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
  163. data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
  164. data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
  165. data/node_modules/preact/hooks/package.json +0 -35
  166. data/node_modules/preact/hooks/src/index.d.ts +0 -139
  167. data/node_modules/preact/hooks/src/index.js +0 -417
  168. data/node_modules/preact/hooks/src/internal.d.ts +0 -78
  169. data/node_modules/preact/jsx-runtime/LICENSE +0 -21
  170. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
  171. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
  172. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
  173. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
  174. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
  175. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
  176. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
  177. data/node_modules/preact/jsx-runtime/package.json +0 -28
  178. data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
  179. data/node_modules/preact/jsx-runtime/src/index.js +0 -77
  180. data/node_modules/preact/package.json +0 -304
  181. data/node_modules/preact/src/cjs.js +0 -3
  182. data/node_modules/preact/src/clone-element.js +0 -34
  183. data/node_modules/preact/src/component.js +0 -225
  184. data/node_modules/preact/src/constants.js +0 -3
  185. data/node_modules/preact/src/create-context.js +0 -68
  186. data/node_modules/preact/src/create-element.js +0 -98
  187. data/node_modules/preact/src/diff/catch-error.js +0 -40
  188. data/node_modules/preact/src/diff/children.js +0 -335
  189. data/node_modules/preact/src/diff/index.js +0 -533
  190. data/node_modules/preact/src/diff/props.js +0 -158
  191. data/node_modules/preact/src/index.d.ts +0 -317
  192. data/node_modules/preact/src/index.js +0 -13
  193. data/node_modules/preact/src/internal.d.ts +0 -155
  194. data/node_modules/preact/src/jsx.d.ts +0 -1013
  195. data/node_modules/preact/src/options.js +0 -16
  196. data/node_modules/preact/src/render.js +0 -75
  197. data/node_modules/preact/src/util.js +0 -27
  198. data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
  199. data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
  200. data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
  201. data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
  202. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
  203. data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
  204. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
  205. data/node_modules/preact/test-utils/package.json +0 -28
  206. data/node_modules/preact/test-utils/src/index.d.ts +0 -3
  207. data/node_modules/preact/test-utils/src/index.js +0 -118
  208. data/node_modules/preact-render-to-string/LICENSE +0 -21
  209. data/node_modules/preact-render-to-string/README.md +0 -102
  210. data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
  211. data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
  212. data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
  213. data/node_modules/preact-render-to-string/dist/index.js +0 -1
  214. data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
  215. data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
  216. data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
  217. data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
  218. data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
  219. data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
  220. data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
  221. data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
  222. data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
  223. data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
  224. data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
  225. data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
  226. data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
  227. data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
  228. data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
  229. data/node_modules/preact-render-to-string/jsx.js +0 -1
  230. data/node_modules/preact-render-to-string/package.json +0 -142
  231. data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
  232. data/node_modules/preact-render-to-string/src/index.js +0 -462
  233. data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
  234. data/node_modules/preact-render-to-string/src/jsx.js +0 -76
  235. data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
  236. data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
  237. data/node_modules/preact-render-to-string/src/util.js +0 -78
  238. data/node_modules/preact-render-to-string/typings.json +0 -5
  239. data/node_modules/pretty-format/.npmignore +0 -3
  240. data/node_modules/pretty-format/LICENSE.md +0 -15
  241. data/node_modules/pretty-format/README.md +0 -94
  242. data/node_modules/pretty-format/index.js +0 -343
  243. data/node_modules/pretty-format/package.json +0 -26
  244. data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
  245. data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
  246. data/node_modules/pretty-format/printString.js +0 -7
  247. data/node_modules/wouter-preact/cjs/index.js +0 -180
  248. data/node_modules/wouter-preact/cjs/matcher.js +0 -72
  249. data/node_modules/wouter-preact/cjs/package.json +0 -1
  250. data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
  251. data/node_modules/wouter-preact/cjs/static-location.js +0 -21
  252. data/node_modules/wouter-preact/cjs/use-location.js +0 -94
  253. data/node_modules/wouter-preact/index.d.ts +0 -110
  254. data/node_modules/wouter-preact/index.js +0 -178
  255. data/node_modules/wouter-preact/matcher.d.ts +0 -30
  256. data/node_modules/wouter-preact/matcher.js +0 -66
  257. data/node_modules/wouter-preact/package.json +0 -33
  258. data/node_modules/wouter-preact/react-deps.js +0 -15
  259. data/node_modules/wouter-preact/static-location.d.ts +0 -16
  260. data/node_modules/wouter-preact/static-location.js +0 -17
  261. data/node_modules/wouter-preact/use-location.d.ts +0 -43
  262. data/node_modules/wouter-preact/use-location.js +0 -86
  263. 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,140 +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_effect(*args, &block)
29
- `Opal.global.PreactHooks.useEffect(function() { #{block.call} }, args)`
30
- end
31
-
32
- def use_error_boundary(&block)
33
- error = nil
34
- reset_error = nil
35
- %x{
36
- let _error;
37
- let _reset_error;
38
- if (block) {
39
- [_error, reset_error] = Opal.global.PreactHooks.useErrorBoundary(function() { #{block.call(Error(_error))} });
40
- } else {
41
- [_error, reset_error] = Opal.global.PreactHooks.useErrorBoundary();
42
- }
43
- error = #{Error(e)};
44
- }
45
- [error, reset_error]
46
- end
47
-
48
- def use_imperative_handle(ruby_ref, *args, &block)
49
- ref = ruby_ref.to_n
50
- args = `null` if args.empty?
51
- `Opal.global.PreactHooks.useImperativeHandle(ref, function() { #{block.call} }, args)`
52
- end
53
-
54
- def use_layout_effect(&block)
55
- `Opal.global.PreactHooks.useLayoutEffect(function() { #{block.call} })`
56
- end
57
-
58
- def use_memo(*deps, &block)
59
- `Opal.global.PreactHooks.useMemo(function() { #{block.call} }, deps)`
60
- end
61
-
62
- def use_reducer(inital_state, &block)
63
- state = nil
64
- dispatcher = nil
65
- %x{
66
- [state, dispatcher] = Opal.global.PreactHooks.useReducer(function(state, action) {
67
- #{block.call(state, action)}
68
- }, initial_state);
69
- }
70
- [state, proc { |arg| `dispatcher(arg)` }]
71
- end
72
-
73
- def use_ref(native_ref)
74
- Preact::Ref.new(`Opal.global.PreactHooks.useRef(native_ref)`)
75
- end
76
-
77
- def use_state(initial_value)
78
- initial = nil
79
- setter = nil
80
- `[initial, setter] = Opal.global.PreactHooks.useState(initial_value);`
81
- [initial, proc { |arg| `setter(arg)` }]
82
- end
83
-
84
- def get_preact_element(arg, &block)
85
- `let operabu = Opal.Preact.render_buffer`
86
- if block_given?
87
- # execute block, fetch last element from buffer
88
- %x{
89
- let last_buffer_length = operabu[operabu.length - 1].length;
90
- let last_buffer_element = operabu[operabu.length - 1][last_buffer_length - 1];
91
- block.$call();
92
- // console.log("get_preact_element popping", operabu, operabu.toString())
93
- let new_element = operabu[operabu.length - 1].pop();
94
- if (last_buffer_element === new_element) { #{Isomorfeus.raise_error(message: "Block did not create any Preact element!")} }
95
- return new_element;
96
- }
97
- else
98
- # element was rendered before being passed as arg
99
- # fetch last element from buffer
100
- # `console.log("get_preact_element popping", operabu, operabu.toString())`
101
- `operabu[operabu.length - 1].pop()`
102
- end
103
- end
104
- alias gpe get_preact_element
105
-
106
- def history
107
- Isomorfeus.browser_history
108
- end
109
-
110
- def render_preact_element(el)
111
- # push el to buffer
112
- `Opal.Preact.render_buffer[Opal.Preact.render_buffer.length - 1].push(el)`
113
- # `console.log("render_preact_element pushed", Opal.Preact.render_buffer, Opal.Preact.render_buffer.toString())`
114
- nil
115
- end
116
- alias rpe render_preact_element
117
-
118
- def method_ref(method_symbol, *args)
119
- method_key = "#{method_symbol}#{args}"
120
- %x{
121
- if (#{self}.method_refs?.[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
122
- if (!#{self}.method_refs) { #{self}.method_refs = {}; }
123
- #{self}.method_refs[#{method_key}] = { m: null, a: args };
124
- let r = #{self}.method_refs[#{method_key}];
125
- let dev = #{Isomorfeus.development?};
126
- r.preact_event_handler_function = function(event, info) {
127
- let ruby_event = Opal.Preact.native_to_ruby_event(event);
128
- if (!r.m || dev) { r.m = #{method(method_symbol)} };
129
- if (r.a.length > 0) { r.m.$call.apply(r.m, [ruby_event, info].concat(r.a)); }
130
- else { r.m.$call(ruby_event, info); }
131
- };
132
- return #{self}.method_refs[#{method_key}];
133
- }
134
- end
135
- alias m_ref method_ref
136
-
137
- def to_n
138
- self
139
- end
140
- end
@@ -1,7 +0,0 @@
1
- module Preact::FunctionComponent
2
- class Base
3
- def self.inherited(base)
4
- base.include(::Preact::FunctionComponent::Mixin)
5
- end
6
- end
7
- end
@@ -1,6 +0,0 @@
1
- module Preact::FunctionComponent::Initializer
2
- def initialize
3
- self.JS[:native_props] = `{ props: null }`
4
- @native_props = `Opal.Preact.Props.$new(self)`
5
- end
6
- 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
@@ -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
@@ -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
@@ -1,7 +0,0 @@
1
- module Preact::Component
2
- class Base
3
- def self.inherited(base)
4
- base.include(::Preact::Component::Mixin)
5
- end
6
- end
7
- end
@@ -1,111 +0,0 @@
1
- module Preact::Component::Callbacks
2
- def self.included(base)
3
- base.instance_exec do
4
- def component_did_catch(&block)
5
- # TODO convert error
6
- %x{
7
- var fun = function(error, newVNode, oldVNode, errorInfo) {
8
- const oper = Opal.Preact;
9
- oper.register_active_component(this);
10
- try {
11
- #{`this.__ruby_instance`.instance_exec(`error`, `newVNode`, `oldVNode`, `errorInfo`, &block)};
12
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
13
- oper.unregister_active_component(this);
14
- }
15
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidCatch = fun; }
16
- else { self.preact_component.prototype.componentDidCatch = fun; }
17
- Opal.Preact.using_did_catch = true;
18
- }
19
- end
20
-
21
- def component_did_mount(&block)
22
- %x{
23
- let fun = function() {
24
- const oper = Opal.Preact;
25
- oper.register_active_component(this);
26
- try { #{`this.__ruby_instance`.instance_exec(&block)}; }
27
- catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
28
- if (self.preload_did_mount_proc) { #{`this.__ruby_instance`.instance_exec { self.class.JS[:preload_did_mount_proc].call } } }
29
- oper.unregister_active_component(this);
30
- }
31
- if (self.lucid_preact_component) {
32
- self.lucid_preact_component.prototype.componentDidMount = fun;
33
- } else {
34
- self.preact_component.prototype.componentDidMount = fun;
35
- }
36
- }
37
- end
38
-
39
- def component_did_update(&block)
40
- %x{
41
- var fun = function(prev_props, prev_state, snapshot) {
42
- const oper = Opal.Preact;
43
- oper.register_active_component(this);
44
- try {
45
- #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: prev_props})`,
46
- `oper.State.$new({state: prev_state})`,
47
- `snapshot`, &block)};
48
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
49
- oper.unregister_active_component(this);
50
- }
51
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentDidUpdate = fun; }
52
- else { self.preact_component.prototype.componentDidUpdate = fun; }
53
- }
54
- end
55
-
56
- def component_will_unmount(&block)
57
- %x{
58
- var fun = function() {
59
- const oper = Opal.Preact;
60
- if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
61
- oper.register_active_component(this);
62
- try {
63
- #{`this.__ruby_instance`.instance_exec(&block)};
64
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
65
- oper.unregister_active_component(this);
66
- }
67
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.componentWillUnmount = fun; }
68
- else { self.preact_component.prototype.componentWillUnmount = fun; }
69
- }
70
- end
71
-
72
-
73
- def get_derived_state_from_props(&block)
74
- %x{
75
- var fun = function(props, state) {
76
- const oper = Opal.Preact;
77
- oper.register_active_component(this);
78
- try {
79
- var result = #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: props})`,
80
- `oper.State.$new({state: state})`, &block)};
81
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
82
- oper.unregister_active_component(this);
83
- if (typeof result.$to_n === 'function') { result = result.$to_n() }
84
- if (result === nil) { return null; }
85
- return result;
86
- }
87
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getDerivedStateFromProps = fun; }
88
- else { self.preact_component.prototype.getDerivedStateFromProps = fun; }
89
- }
90
- end
91
-
92
- def get_snapshot_before_update(&block)
93
- %x{
94
- var fun = function(prev_props, prev_state) {
95
- const oper = Opal.Preact;
96
- oper.register_active_component(this);
97
- try {
98
- var result = #{`this.__ruby_instance`.instance_exec(`oper.Props.$new({props: prev_props})`,
99
- `oper.State.$new({state: prev_state})`, &block)};
100
- } catch (e) { console.error(e.message === Opal.nil ? 'error at' : e.message, e.stack); }
101
- oper.unregister_active_component(this);
102
- if (result === nil) { return null; }
103
- return result;
104
- }
105
- if (self.lucid_preact_component) { self.lucid_preact_component.prototype.getSnapshotBeforeUpdate = fun; }
106
- else { self.preact_component.prototype.getSnapshotBeforeUpdate = fun; }
107
- }
108
- end
109
- end
110
- end
111
- end
@@ -1,7 +0,0 @@
1
- module Preact::Component::Initializer
2
- def initialize(native_component)
3
- @native = native_component
4
- @props = `Opal.Preact.Props.$new(#@native)`
5
- @state = `Opal.Preact.State.$new(#@native)`
6
- end
7
- end