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.
Files changed (266) 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. data/opal/iso_uri.rb +29 -0
  39. data/opal/uri/common.rb +18 -0
  40. data/opal/uri/generic.rb +47 -0
  41. metadata +45 -309
  42. data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
  43. data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
  44. data/lib/isomorfeus/preact/ssr/history.rb +0 -23
  45. data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
  46. data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
  47. data/lib/isomorfeus/preact_view_helper.rb +0 -129
  48. data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
  49. data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
  50. data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
  51. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
  52. data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
  53. data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
  54. data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
  55. data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
  56. data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
  57. data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
  58. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
  59. data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
  60. data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
  61. data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
  62. data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
  63. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
  64. data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -164
  65. data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
  66. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
  67. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
  68. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
  69. data/lib/lucid_app/context.rb +0 -24
  70. data/lib/lucid_prop_declaration/mixin.rb +0 -126
  71. data/lib/preact/component/api.rb +0 -137
  72. data/lib/preact/component/base.rb +0 -7
  73. data/lib/preact/component/callbacks.rb +0 -111
  74. data/lib/preact/component/initializer.rb +0 -7
  75. data/lib/preact/component/mixin.rb +0 -11
  76. data/lib/preact/component/native_component_constructor.rb +0 -77
  77. data/lib/preact/context_wrapper.rb +0 -48
  78. data/lib/preact/native_constant_wrapper.rb +0 -29
  79. data/lib/preact/option_hooks.rb +0 -98
  80. data/lib/preact/params.rb +0 -16
  81. data/lib/preact/props.rb +0 -69
  82. data/lib/preact/ref.rb +0 -17
  83. data/lib/preact/state.rb +0 -87
  84. data/lib/preact/version.rb +0 -3
  85. data/node_modules/.package-lock.json +0 -38
  86. data/node_modules/preact/LICENSE +0 -21
  87. data/node_modules/preact/README.md +0 -188
  88. data/node_modules/preact/compat/LICENSE +0 -21
  89. data/node_modules/preact/compat/client.js +0 -19
  90. data/node_modules/preact/compat/client.mjs +0 -17
  91. data/node_modules/preact/compat/dist/compat.js +0 -2
  92. data/node_modules/preact/compat/dist/compat.js.map +0 -1
  93. data/node_modules/preact/compat/dist/compat.mjs +0 -2
  94. data/node_modules/preact/compat/dist/compat.module.js +0 -2
  95. data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
  96. data/node_modules/preact/compat/dist/compat.umd.js +0 -2
  97. data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
  98. data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
  99. data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
  100. data/node_modules/preact/compat/jsx-runtime.js +0 -3
  101. data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
  102. data/node_modules/preact/compat/package.json +0 -49
  103. data/node_modules/preact/compat/scheduler.js +0 -15
  104. data/node_modules/preact/compat/scheduler.mjs +0 -23
  105. data/node_modules/preact/compat/server.browser.js +0 -4
  106. data/node_modules/preact/compat/server.js +0 -15
  107. data/node_modules/preact/compat/server.mjs +0 -4
  108. data/node_modules/preact/compat/src/Children.js +0 -21
  109. data/node_modules/preact/compat/src/PureComponent.js +0 -15
  110. data/node_modules/preact/compat/src/forwardRef.js +0 -44
  111. data/node_modules/preact/compat/src/index.d.ts +0 -164
  112. data/node_modules/preact/compat/src/index.js +0 -223
  113. data/node_modules/preact/compat/src/internal.d.ts +0 -47
  114. data/node_modules/preact/compat/src/memo.js +0 -34
  115. data/node_modules/preact/compat/src/portals.js +0 -82
  116. data/node_modules/preact/compat/src/render.js +0 -238
  117. data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
  118. data/node_modules/preact/compat/src/suspense-list.js +0 -126
  119. data/node_modules/preact/compat/src/suspense.d.ts +0 -15
  120. data/node_modules/preact/compat/src/suspense.js +0 -270
  121. data/node_modules/preact/compat/src/util.js +0 -28
  122. data/node_modules/preact/compat/test-utils.js +0 -1
  123. data/node_modules/preact/debug/LICENSE +0 -21
  124. data/node_modules/preact/debug/dist/debug.js +0 -2
  125. data/node_modules/preact/debug/dist/debug.js.map +0 -1
  126. data/node_modules/preact/debug/dist/debug.mjs +0 -2
  127. data/node_modules/preact/debug/dist/debug.module.js +0 -2
  128. data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
  129. data/node_modules/preact/debug/dist/debug.umd.js +0 -2
  130. data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
  131. data/node_modules/preact/debug/package.json +0 -26
  132. data/node_modules/preact/debug/src/check-props.js +0 -54
  133. data/node_modules/preact/debug/src/component-stack.js +0 -146
  134. data/node_modules/preact/debug/src/constants.js +0 -3
  135. data/node_modules/preact/debug/src/debug.js +0 -437
  136. data/node_modules/preact/debug/src/index.js +0 -6
  137. data/node_modules/preact/debug/src/internal.d.ts +0 -82
  138. data/node_modules/preact/debug/src/util.js +0 -11
  139. data/node_modules/preact/devtools/LICENSE +0 -21
  140. data/node_modules/preact/devtools/dist/devtools.js +0 -2
  141. data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
  142. data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
  143. data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
  144. data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
  145. data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
  146. data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
  147. data/node_modules/preact/devtools/package.json +0 -25
  148. data/node_modules/preact/devtools/src/devtools.js +0 -10
  149. data/node_modules/preact/devtools/src/index.d.ts +0 -8
  150. data/node_modules/preact/devtools/src/index.js +0 -15
  151. data/node_modules/preact/dist/preact.js +0 -2
  152. data/node_modules/preact/dist/preact.js.map +0 -1
  153. data/node_modules/preact/dist/preact.min.js +0 -2
  154. data/node_modules/preact/dist/preact.min.js.map +0 -1
  155. data/node_modules/preact/dist/preact.mjs +0 -2
  156. data/node_modules/preact/dist/preact.module.js +0 -2
  157. data/node_modules/preact/dist/preact.module.js.map +0 -1
  158. data/node_modules/preact/dist/preact.umd.js +0 -2
  159. data/node_modules/preact/dist/preact.umd.js.map +0 -1
  160. data/node_modules/preact/hooks/LICENSE +0 -21
  161. data/node_modules/preact/hooks/dist/hooks.js +0 -2
  162. data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
  163. data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
  164. data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
  165. data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
  166. data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
  167. data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
  168. data/node_modules/preact/hooks/package.json +0 -35
  169. data/node_modules/preact/hooks/src/index.d.ts +0 -139
  170. data/node_modules/preact/hooks/src/index.js +0 -417
  171. data/node_modules/preact/hooks/src/internal.d.ts +0 -78
  172. data/node_modules/preact/jsx-runtime/LICENSE +0 -21
  173. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
  174. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
  175. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
  176. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
  177. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
  178. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
  179. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
  180. data/node_modules/preact/jsx-runtime/package.json +0 -28
  181. data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
  182. data/node_modules/preact/jsx-runtime/src/index.js +0 -77
  183. data/node_modules/preact/package.json +0 -304
  184. data/node_modules/preact/src/cjs.js +0 -3
  185. data/node_modules/preact/src/clone-element.js +0 -34
  186. data/node_modules/preact/src/component.js +0 -225
  187. data/node_modules/preact/src/constants.js +0 -3
  188. data/node_modules/preact/src/create-context.js +0 -68
  189. data/node_modules/preact/src/create-element.js +0 -98
  190. data/node_modules/preact/src/diff/catch-error.js +0 -40
  191. data/node_modules/preact/src/diff/children.js +0 -335
  192. data/node_modules/preact/src/diff/index.js +0 -533
  193. data/node_modules/preact/src/diff/props.js +0 -158
  194. data/node_modules/preact/src/index.d.ts +0 -317
  195. data/node_modules/preact/src/index.js +0 -13
  196. data/node_modules/preact/src/internal.d.ts +0 -155
  197. data/node_modules/preact/src/jsx.d.ts +0 -1014
  198. data/node_modules/preact/src/options.js +0 -16
  199. data/node_modules/preact/src/render.js +0 -75
  200. data/node_modules/preact/src/util.js +0 -27
  201. data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
  202. data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
  203. data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
  204. data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
  205. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
  206. data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
  207. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
  208. data/node_modules/preact/test-utils/package.json +0 -28
  209. data/node_modules/preact/test-utils/src/index.d.ts +0 -3
  210. data/node_modules/preact/test-utils/src/index.js +0 -118
  211. data/node_modules/preact-render-to-string/LICENSE +0 -21
  212. data/node_modules/preact-render-to-string/README.md +0 -102
  213. data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
  214. data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
  215. data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
  216. data/node_modules/preact-render-to-string/dist/index.js +0 -1
  217. data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
  218. data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
  219. data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
  220. data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
  221. data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
  222. data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
  223. data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
  224. data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
  225. data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
  226. data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
  227. data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
  228. data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
  229. data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
  230. data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
  231. data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
  232. data/node_modules/preact-render-to-string/jsx.js +0 -1
  233. data/node_modules/preact-render-to-string/package.json +0 -142
  234. data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
  235. data/node_modules/preact-render-to-string/src/index.js +0 -462
  236. data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
  237. data/node_modules/preact-render-to-string/src/jsx.js +0 -76
  238. data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
  239. data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
  240. data/node_modules/preact-render-to-string/src/util.js +0 -78
  241. data/node_modules/preact-render-to-string/typings.json +0 -5
  242. data/node_modules/pretty-format/.npmignore +0 -3
  243. data/node_modules/pretty-format/LICENSE.md +0 -15
  244. data/node_modules/pretty-format/README.md +0 -94
  245. data/node_modules/pretty-format/index.js +0 -343
  246. data/node_modules/pretty-format/package.json +0 -26
  247. data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
  248. data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
  249. data/node_modules/pretty-format/printString.js +0 -7
  250. data/node_modules/wouter-preact/cjs/index.js +0 -180
  251. data/node_modules/wouter-preact/cjs/matcher.js +0 -72
  252. data/node_modules/wouter-preact/cjs/package.json +0 -1
  253. data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
  254. data/node_modules/wouter-preact/cjs/static-location.js +0 -21
  255. data/node_modules/wouter-preact/cjs/use-location.js +0 -94
  256. data/node_modules/wouter-preact/index.d.ts +0 -110
  257. data/node_modules/wouter-preact/index.js +0 -178
  258. data/node_modules/wouter-preact/matcher.d.ts +0 -30
  259. data/node_modules/wouter-preact/matcher.js +0 -66
  260. data/node_modules/wouter-preact/package.json +0 -33
  261. data/node_modules/wouter-preact/react-deps.js +0 -15
  262. data/node_modules/wouter-preact/static-location.d.ts +0 -16
  263. data/node_modules/wouter-preact/static-location.js +0 -17
  264. data/node_modules/wouter-preact/use-location.d.ts +0 -43
  265. data/node_modules/wouter-preact/use-location.js +0 -86
  266. data/package.json +0 -8
@@ -1,102 +1,80 @@
1
+ require 'base64'
2
+ require 'stringio'
1
3
  if RUBY_ENGINE == 'opal'
2
- require 'isomorfeus-redux'
3
- require 'active_support/core_ext/string'
4
- require 'zeitwerk'
5
-
6
- if on_browser?
7
- require 'browser/event'
8
- require 'browser/event_target'
9
- require 'browser/delegate_native'
10
- require 'browser/element' # depends on 'preact'
11
- require 'browser/history'
12
- end
4
+ require 'iso_uri'
5
+ else
6
+ require 'uri'
7
+ require 'oj'
8
+ end
9
+ require 'data_uri'
10
+ require 'isomorfeus-transport'
11
+ require 'isomorfeus-redux'
12
+ require 'isomorfeus-i18n'
13
+ require 'isomorfeus/preact/config'
14
+ require 'browser/history'
15
+ require 'browser/location'
13
16
 
14
- require 'isomorfeus/preact/config'
15
- if on_browser? && `window?.history`
17
+ if RUBY_ENGINE == 'opal'
18
+ require 'browser/event'
19
+ require 'browser/event_target'
20
+ require 'browser/delegate_native'
21
+ require 'browser/element'
22
+ require 'browser/document'
23
+ require 'browser/window'
24
+
25
+ if `window?.history`
16
26
  Isomorfeus.browser_history = Browser::History.new(`window.history`)
27
+ Isomorfeus.browser_location = Browser::Location.new(`window.location`)
17
28
  end
18
- # allow mounting of components
19
- require 'isomorfeus/top_level'
20
-
21
- # nanocss
22
- require 'nano_css'
23
-
24
- # preact
25
- require 'preact/version'
26
- require 'preact'
27
- require 'preact/ref'
28
-
29
- # props
30
- require 'isomorfeus/props/validate_hash_proxy'
31
- require 'isomorfeus/props/validator'
32
- require 'lucid_prop_declaration/mixin'
33
- require 'preact/params'
34
- require 'preact/props'
35
-
36
- # HTML Elements and Fragment support
37
- require 'preact/elements'
38
-
39
- # Preact Wrappers
40
- require 'preact/context_wrapper'
41
- require 'preact/native_constant_wrapper'
42
-
43
- # Preact::Component
44
- # make modules available
45
- module Preact
46
- module Component
47
- end
48
- module FunctionComponent
49
- end
50
- end
29
+ else
30
+ Isomorfeus.browser_history = Browser::History.new
31
+ end
51
32
 
52
- require 'preact/component/api'
53
- require 'preact/component/callbacks'
54
- require 'preact/component/initializer'
55
- require 'preact/component/native_component_constructor'
56
- require 'preact/state'
57
- require 'preact/component/mixin'
58
- require 'preact/component/base'
59
-
60
- # component resolution
61
- require 'preact/component_resolution'
62
- class Object
63
- include Preact::ComponentResolution
64
- end
33
+ # allow mounting of components
34
+ require 'isomorfeus/top_level'
65
35
 
66
- # make modules available
67
- module LucidApp
68
- end
69
- module LucidComponent
70
- end
71
- module LucidFunc
72
- end
73
- # init LucidApplicationContext (Store Provider and Consumer)
74
- require 'lucid_app/context'
75
- LucidApp::Context.create_application_context
36
+ # nanocss
37
+ require 'nano_css'
76
38
 
77
- # init auto loader
78
- Isomorfeus.zeitwerk = Zeitwerk::Loader.new
79
- Isomorfeus.zeitwerk.push_dir('isomorfeus_preact')
80
- require_tree 'isomorfeus_preact', autoload: true
39
+ # preact
40
+ require 'preact'
81
41
 
42
+ # props
43
+ require 'isomorfeus/props/validate_hash_proxy'
44
+ require 'isomorfeus/props/validator'
45
+ require 'preact/prop_declaration_mixin'
46
+
47
+ # component resolution
48
+ require 'preact/component_resolution'
49
+ require 'preact/module_component_resolution'
50
+
51
+ # HTML Elements and Fragment support
52
+ require 'preact/elements'
53
+ # Component
54
+ require 'preact/component'
55
+ # Context
56
+ require 'preact/context'
57
+
58
+ Preact::Context.create_application_contexts
59
+
60
+ # Router Components
61
+ require 'link'
62
+ require 'redirect'
63
+ require 'route'
64
+ require 'router'
65
+ require 'switch'
66
+
67
+ # LucidComponent
68
+ require 'lucid_component'
69
+
70
+ # LucidApp
71
+ require 'lucid_app'
72
+
73
+ if RUBY_ENGINE == 'opal'
74
+ # init auto loader
82
75
  Isomorfeus.zeitwerk.push_dir('components')
83
76
  else
84
- require 'uri'
85
- require 'oj'
86
- require 'opal'
87
- require 'opal/compiler'
88
- require 'opal-activesupport'
89
- require 'opal-zeitwerk'
90
- require 'isomorfeus-speednode'
91
- require 'isomorfeus-asset-manager'
92
- require 'isomorfeus-redux'
93
- require 'preact/version'
94
- require 'isomorfeus/preact/config'
95
-
96
- # props
97
- require 'isomorfeus/props/validate_hash_proxy'
98
- require 'isomorfeus/props/validator'
99
- require 'lucid_prop_declaration/mixin'
77
+ require 'isomorfeus/preact/version'
100
78
 
101
79
  if Isomorfeus.development?
102
80
  require 'net/http'
@@ -104,28 +82,25 @@ else
104
82
  end
105
83
 
106
84
  Isomorfeus.server_side_rendering = true
85
+ NanoCSS.instance = NanoCSS.new(nil)
107
86
 
108
- # caches
87
+ # cache
109
88
  require 'isomorfeus/preact/thread_local_component_cache'
110
- # require 'isomorfeus/preact/memcached_component_cache'
111
- # require 'isomorfeus/preact/redis_component_cache'
112
- require 'isomorfeus/preact_view_helper'
89
+
90
+ require 'isomorfeus/preact/ssr'
91
+ require 'isomorfeus/preact/view_helper'
113
92
 
114
93
  Isomorfeus.component_cache_init do
115
94
  Isomorfeus::ThreadLocalComponentCache.new
116
95
  end
117
96
 
118
- Opal.append_path(__dir__.untaint)
119
-
120
- require 'concurrent/atomic/atomic_fixnum'
121
- require 'concurrent/atomic/reentrant_read_write_lock'
122
- require 'zeitwerk'
97
+ require 'iso_opal'
98
+ Opal.append_path(__dir__.untaint) unless IsoOpal.paths.include?(__dir__.untaint)
99
+ path = File.expand_path(File.join(__dir__.untaint, '..', 'opal'))
100
+ Opal.append_path(path) unless IsoOpal.paths.include?(path)
123
101
 
124
- Isomorfeus.zeitwerk = Zeitwerk::Loader.new
125
- Isomorfeus.zeitwerk_lock = Concurrent::ReentrantReadWriteLock.new if Isomorfeus.development?
126
- # nothing to push_dir to zeitwerk here, as components are available only within browser/SSR
102
+ Isomorfeus.zeitwerk.push_dir(File.expand_path(File.join('app', 'components')))
127
103
 
128
104
  require 'isomorfeus/preact/imports'
129
- Isomorfeus.node_paths << File.expand_path(File.join(File.dirname(__FILE__), '..', 'node_modules'))
130
- Isomorfeus::Preact::Imports.add
105
+ Isomorfeus::PreactImports.add
131
106
  end
data/lib/link.rb ADDED
@@ -0,0 +1,52 @@
1
+ class Link < Preact::Component
2
+ EVENT_PUSH_STATE = "pushState"
3
+ EVENT_REPLACE_STATE = "replaceState"
4
+
5
+ def initialize(props, context)
6
+ super(props, context)
7
+ if RUBY_ENGINE == 'opal'
8
+ if `typeof window !== "undefined"`
9
+ @history = `window.history`
10
+ else
11
+ @history = `{ length: 1, state: null, scrollRestoration: "auto", pushState: function(e,t,n){}, replaceState: function(e,t,n){} }`
12
+ end
13
+ end
14
+ @rbase = nil
15
+ end
16
+
17
+ def navigate
18
+ rto = props[:to] || props[:href]
19
+ m = props[:replace] ? EVENT_REPLACE_STATE : EVENT_PUSH_STATE
20
+ `#@history[m](null, "", rto[0] === "~" ? rto.slice(1) : #@rbase + rto)`
21
+ @context[:router][:callback]&.call
22
+ end
23
+
24
+ def handle_click(event)
25
+ # ignores the navigation when clicked using right mouse button or
26
+ # by holding a special modifier key: ctrl, command, win, alt, shift
27
+ if event.ctrl? || event.meta? || event.alt? || event.shift? || event.button > 0
28
+ event.prevent
29
+ return
30
+ end
31
+ props[:on_click]&.call(event)
32
+ event.prevent unless event.prevented?
33
+ navigate
34
+ end
35
+
36
+ render do
37
+ to = props[:to]
38
+ href = props[:href] || to
39
+ children = props[:children]
40
+ @rbase = @context[:router][:base]
41
+ extra_props = {
42
+ # handle nested routers and absolute paths
43
+ href: href[0] === "~" ? href.slice(1) : @rbase + href,
44
+ on_click: call(:handle_click),
45
+ to: nil
46
+ }
47
+ # wraps children in `a` if needed
48
+ a = children.is_a?(VNode) ? children : Preact.create_element("a", props)
49
+ Preact.clone_element(a, extra_props)
50
+ end
51
+ end
52
+ Link.context_type = RouterContext
data/lib/lucid_app.rb ADDED
@@ -0,0 +1,117 @@
1
+ class LucidApp < LucidComponent
2
+ class << self
3
+ def inherited(base)
4
+ base.context_type = nil
5
+ end
6
+
7
+ def render(&block)
8
+ define_method(:render) do
9
+ pr = Preact.render_buffer
10
+ block_result = _internal_render(pr, &block)
11
+ children = pr.pop
12
+ if Preact.is_renderable?(block_result)
13
+ children.push(block_result)
14
+ end
15
+ Preact.create_element(LucidApplicationContext.Provider, state[:_app_ctx], children)
16
+ end
17
+ end
18
+
19
+ def component_will_unmount(&block)
20
+ define_method(:component_will_unmount) do
21
+ instance_exec do
22
+ Isomorfeus.store.unsubscribe(@unsubscriber)
23
+ end
24
+ instance_exec(&block)
25
+ nil
26
+ end
27
+ end
28
+
29
+ # theme
30
+
31
+ def theme(theme_hash = nil, &block)
32
+ theme_hash = block.call if block_given?
33
+ @theme_hash = theme_hash if theme_hash
34
+ @theme_hash
35
+ end
36
+ alias_method :theme=, :theme
37
+
38
+ if RUBY_ENGINE == 'opal'
39
+ def css_theme
40
+ return {} unless @theme_hash
41
+ return @css_theme if @css_theme
42
+ component_name = self.to_s
43
+ rule_name = component_name.gsub(':', '_')
44
+ i = NanoCSS.instance
45
+ i.delete_from_sheet(rule_name)
46
+ i.renderer[:hydrate_force_put] = true
47
+ @css_theme = i.sheet(@theme_hash, rule_name)
48
+ end
49
+ else
50
+ def css_theme
51
+ return {} unless @theme_hash
52
+ t = thread_css_theme
53
+ return t if t
54
+ component_name = self.to_s
55
+ rule_name = component_name.gsub(':', '_')
56
+ i = NanoCSS.instance
57
+ i.delete_from_sheet(rule_name)
58
+ i.renderer[:hydrate_force_put] = true
59
+ thread_css_theme = i.sheet(@theme_hash, rule_name)
60
+ end
61
+
62
+ def thread_css_theme_key
63
+ @thread_css_theme_key ||= "#{self.to_s.underscore}_css_theme".to_sym
64
+ end
65
+
66
+ def thread_css_theme
67
+ Thread.current[thread_css_theme_key]
68
+ end
69
+
70
+ def thread_css_theme=(s)
71
+ Thread.current[thread_css_theme_key] = s
72
+ end
73
+ end
74
+ end
75
+
76
+ attr_reader :theme
77
+
78
+ def initialize(props, context)
79
+ super(props, context)
80
+
81
+ # theme
82
+ @class_name_sym = @class_name.to_sym
83
+ @theme = @self_class.css_theme
84
+
85
+ store_state = Isomorfeus.store.get_state
86
+ unless store_state[:class_state].key?(@class_name_sym)
87
+ store_state[:class_state][@class_name_sym] = {}
88
+ end
89
+ @state.merge!({ _app_ctx: { value: { iso_location: props[:location],
90
+ iso_store: store_state,
91
+ iso_theme: @theme }}})
92
+
93
+ lai = self
94
+ if RUBY_ENGINE == 'opal'
95
+ @unsubscriber = Isomorfeus.store.subscribe do
96
+ store_state = Isomorfeus.store.get_state
97
+ unless store_state[:class_state].key?(@class_name_sym)
98
+ store_state[:class_state][@class_name_sym] = {}
99
+ end
100
+ lai.set_state({ _app_ctx: { value: { iso_location: lai.props[:location],
101
+ iso_store: store_state,
102
+ iso_theme: lai.theme }}})
103
+ end
104
+ end
105
+ end
106
+
107
+ def should_component_update?(next_props, next_state, _next_context)
108
+ return true if @props != next_props || @state != next_state
109
+ false
110
+ end
111
+
112
+ if RUBY_ENGINE == 'opal'
113
+ def component_will_unmount
114
+ Isomorfeus.store.unsubscribe(@unsubscriber)
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,154 @@
1
+ class LucidComponent < Preact::Component
2
+ include LucidI18nMixin
3
+
4
+ class << self
5
+ def inherited(base)
6
+ base.context_type = LucidApplicationContext
7
+ end
8
+
9
+ def render(&block)
10
+ define_method(:render) do
11
+ pr = Preact.render_buffer
12
+ block_result = _internal_render(pr, &block)
13
+ if Preact.is_renderable?(block_result)
14
+ pr.pop.push(block_result)
15
+ else
16
+ pr.pop
17
+ end
18
+ end
19
+ end
20
+
21
+ def while_loading(&block)
22
+ @while_loading_block = block
23
+ end
24
+
25
+ # styles
26
+
27
+ def styles(styles_hash = nil, &block)
28
+ styles_hash = block.call if block_given?
29
+ @styles_hash = styles_hash if styles_hash
30
+ @styles_hash
31
+ end
32
+ alias_method :styles=, :styles
33
+
34
+ if RUBY_ENGINE == 'opal'
35
+ def css_styles
36
+ return {} unless @styles_hash
37
+ return @css_styles if @css_styles
38
+ component_name = self.to_s
39
+ rule_name = component_name.gsub(':', '_')
40
+ i = NanoCSS.instance
41
+ i.delete_from_sheet(rule_name)
42
+ i.renderer[:hydrate_force_put] = true
43
+ @css_styles = i.sheet(@styles_hash, rule_name)
44
+ end
45
+ else
46
+ def css_styles
47
+ return {} unless @styles_hash
48
+ s = thread_css_styles
49
+ return s if s
50
+ component_name = self.to_s
51
+ rule_name = component_name.gsub(':', '_')
52
+ i = NanoCSS.instance
53
+ i.delete_from_sheet(rule_name)
54
+ i.renderer[:hydrate_force_put] = true
55
+ thread_css_styles = i.sheet(@styles_hash, rule_name)
56
+ end
57
+
58
+ def thread_css_styles_key
59
+ @thread_css_styles_key ||= "#{self.to_s.underscore}_css_styles".to_sym
60
+ end
61
+
62
+ def thread_css_styles
63
+ Thread.current[thread_css_styles_key]
64
+ end
65
+
66
+ def thread_css_styles=(s)
67
+ Thread.current[thread_css_styles_key] = s
68
+ end
69
+ end
70
+ end
71
+
72
+ attr_reader :styles
73
+
74
+ def initialize(props, context)
75
+ super(props, context)
76
+ @class_name = @self_class.to_s
77
+ if RUBY_ENGINE == 'opal'
78
+ @while_loading_block = `#@self_class.while_loading_block`
79
+ else
80
+ @while_loading_block = @self_class.instance_variable_get(:@while_loading_block)
81
+ end
82
+ # styles
83
+ @styles = @self_class.css_styles
84
+ end
85
+
86
+ def _internal_render(pr, &block)
87
+ pr.push([])
88
+ outer_loading = Isomorfeus.something_loading?
89
+ ex = nil
90
+ begin
91
+ block_result = instance_exec(&block)
92
+ rescue => e
93
+ ex = e
94
+ end
95
+ if Isomorfeus.something_loading?
96
+ STDERR.puts "#{@class_name} component still loading ...\n#{ex.message}\n#{ex.backtrace&.join("\n")}" if ex && Isomorfeus.development?
97
+ pr[pr.length-1].clear
98
+ block_result = @while_loading_block ? instance_exec(&@while_loading_block) : Preact.create_element('div')
99
+ elsif ex
100
+ raise ex
101
+ end
102
+ Isomorfeus.something_loading! if outer_loading
103
+ block_result
104
+ end
105
+
106
+ def should_component_update?(next_props, next_state, next_context)
107
+ return true if @props != next_props || @state != next_state || @context != next_context
108
+ false
109
+ end
110
+
111
+ def current_user
112
+ Isomorfeus.current_user
113
+ end
114
+
115
+ def history
116
+ Isomorfeus.browser_history
117
+ end
118
+
119
+ def location
120
+ Isomorfeus.browser_location
121
+ end
122
+
123
+ def app_state
124
+ @context.dig(:iso_store, :application_state)
125
+ end
126
+
127
+ def set_app_state(update)
128
+ action = { type: 'APPLICATION_STATE', state: update }
129
+ Isomorfeus.store.deferred_dispatch(action)
130
+ end
131
+
132
+ def class_state
133
+ res = @context.dig(:iso_store, :class_state, @class_name)
134
+ return res if res
135
+ {}
136
+ end
137
+
138
+ def set_class_state(update)
139
+ action = { type: 'CLASS_STATE', class: @class_name, state: update }
140
+ Isomorfeus.store.deferred_dispatch(action)
141
+ end
142
+
143
+ def local_store
144
+ LocalStore
145
+ end
146
+
147
+ def session_store
148
+ SessionStore
149
+ end
150
+
151
+ def theme
152
+ @context[:iso_theme]
153
+ end
154
+ end