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,142 +0,0 @@
1
- {
2
- "name": "preact-render-to-string",
3
- "amdName": "preactRenderToString",
4
- "version": "5.2.0",
5
- "description": "Render JSX to an HTML string, with support for Preact components.",
6
- "main": "dist/index.js",
7
- "umd:main": "dist/index.js",
8
- "module": "dist/index.module.js",
9
- "jsnext:main": "dist/index.module.js",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/index.mjs",
13
- "browser": "./dist/index.module.js",
14
- "require": "./dist/index.js"
15
- },
16
- "./jsx": {
17
- "import": "./dist/jsx.mjs",
18
- "browser": "./dist/jsx.module.js",
19
- "require": "./dist/jsx.js"
20
- },
21
- "./package.json": "./package.json",
22
- "./": "./"
23
- },
24
- "scripts": {
25
- "bench": "BABEL_ENV=test node -r @babel/register benchmarks index.js",
26
- "bench:v8": "BABEL_ENV=test microbundle benchmarks/index.js -f modern --alias benchmarkjs-pretty=benchmarks/lib/benchmark-lite.js --external none --target node --no-compress --no-sourcemap --raw -o benchmarks/.v8.js && v8 --module benchmarks/.v8.modern.js",
27
- "build": "npm run -s transpile && npm run -s transpile:jsx && npm run -s copy-typescript-definition",
28
- "postbuild": "node ./config/node-13-exports.js && node ./config/node-commonjs.js",
29
- "transpile": "microbundle src/index.js -f es,umd --target web --external preact",
30
- "transpile:jsx": "microbundle src/jsx.js -o dist/jsx.js --target web --external preact && microbundle dist/jsx.js -o dist/jsx.js -f cjs --external preact",
31
- "copy-typescript-definition": "copyfiles -f src/*.d.ts dist",
32
- "test": "eslint src test && tsc && npm run test:mocha && npm run bench",
33
- "test:mocha": "BABEL_ENV=test mocha -r @babel/register -r test/setup.js test/**/[!compat]*.test.js && npm run test:mocha:compat",
34
- "test:mocha:compat": "BABEL_ENV=test mocha -r @babel/register -r test/setup.js test/compat.test.js",
35
- "format": "prettier src/**/*.{d.ts,js} test/**/*.js --write",
36
- "prepublishOnly": "npm run build",
37
- "release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
38
- },
39
- "keywords": [
40
- "preact",
41
- "render",
42
- "universal",
43
- "isomorphic"
44
- ],
45
- "files": [
46
- "src",
47
- "dist",
48
- "jsx.js",
49
- "typings.json"
50
- ],
51
- "eslintConfig": {
52
- "extends": "developit",
53
- "rules": {
54
- "react/prefer-stateless-function": 0,
55
- "react/jsx-no-bind": 0,
56
- "react/no-danger": 0,
57
- "jest/valid-expect": 0,
58
- "new-cap": 0,
59
- "curly": "off",
60
- "brace-style": "off",
61
- "indent": "off"
62
- },
63
- "settings": {
64
- "react": {
65
- "version": "16.8"
66
- }
67
- }
68
- },
69
- "babel": {
70
- "env": {
71
- "test": {
72
- "presets": [
73
- [
74
- "@babel/preset-env",
75
- {
76
- "targets": {
77
- "node": true
78
- }
79
- }
80
- ]
81
- ],
82
- "plugins": [
83
- [
84
- "@babel/plugin-transform-react-jsx",
85
- {
86
- "pragma": "h"
87
- }
88
- ]
89
- ]
90
- }
91
- }
92
- },
93
- "author": "Jason Miller <jason@developit.ca>",
94
- "license": "MIT",
95
- "typings": "src/index.d.ts",
96
- "repository": "developit/preact-render-to-string",
97
- "bugs": "https://github.com/developit/preact-render-to-string/issues",
98
- "homepage": "https://github.com/developit/preact-render-to-string",
99
- "peerDependencies": {
100
- "preact": ">=10"
101
- },
102
- "devDependencies": {
103
- "@babel/plugin-transform-react-jsx": "^7.12.12",
104
- "@babel/preset-env": "^7.12.11",
105
- "@babel/register": "^7.12.10",
106
- "@changesets/cli": "^2.18.0",
107
- "@changesets/changelog-github": "^0.4.1",
108
- "benchmarkjs-pretty": "^2.0.1",
109
- "chai": "^4.2.0",
110
- "copyfiles": "^2.4.1",
111
- "eslint": "^7.16.0",
112
- "eslint-config-developit": "^1.2.0",
113
- "husky": "^4.3.6",
114
- "lint-staged": "^10.5.3",
115
- "microbundle": "^0.13.0",
116
- "mocha": "^8.2.1",
117
- "preact": "^10.5.7",
118
- "prettier": "^2.2.1",
119
- "sinon": "^9.2.2",
120
- "sinon-chai": "^3.5.0",
121
- "typescript": "^4.1.3"
122
- },
123
- "dependencies": {
124
- "pretty-format": "^3.8.0"
125
- },
126
- "prettier": {
127
- "singleQuote": true,
128
- "trailingComma": "none",
129
- "useTabs": true,
130
- "tabWidth": 2
131
- },
132
- "lint-staged": {
133
- "**/*.{js,jsx,ts,tsx,yml}": [
134
- "prettier --write"
135
- ]
136
- },
137
- "husky": {
138
- "hooks": {
139
- "pre-commit": "lint-staged"
140
- }
141
- }
142
- }
@@ -1,16 +0,0 @@
1
- import { VNode } from 'preact';
2
-
3
- interface Options {
4
- shallow?: boolean;
5
- xml?: boolean;
6
- pretty?: boolean | string;
7
- }
8
-
9
- export function render(vnode: VNode, context?: any, options?: Options): string;
10
- export function renderToString(
11
- vnode: VNode,
12
- context?: any,
13
- options?: Options
14
- ): string;
15
- export function shallowRender(vnode: VNode, context?: any): string;
16
- export default render;
@@ -1,462 +0,0 @@
1
- import {
2
- encodeEntities,
3
- indent,
4
- isLargeString,
5
- styleObjToCss,
6
- assign,
7
- getChildren
8
- } from './util';
9
- import { options, Fragment } from 'preact';
10
-
11
- /** @typedef {import('preact').VNode} VNode */
12
-
13
- const SHALLOW = { shallow: true };
14
-
15
- // components without names, kept as a hash for later comparison to return consistent UnnamedComponentXX names.
16
- const UNNAMED = [];
17
-
18
- const VOID_ELEMENTS = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
19
-
20
- const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
21
-
22
- function markAsDirty() {
23
- this.__d = true;
24
- }
25
-
26
- /** Render Preact JSX + Components to an HTML string.
27
- * @name render
28
- * @function
29
- * @param {VNode} vnode JSX VNode to render.
30
- * @param {Object} [context={}] Optionally pass an initial context object through the render path.
31
- * @param {Object} [options={}] Rendering options
32
- * @param {Boolean} [options.shallow=false] If `true`, renders nested Components as HTML elements (`<Foo a="b" />`).
33
- * @param {Boolean} [options.xml=false] If `true`, uses self-closing tags for elements without children.
34
- * @param {Boolean} [options.pretty=false] If `true`, adds whitespace for readability
35
- * @param {RegExp|undefined} [options.voidElements] RegeEx that matches elements that are considered void (self-closing)
36
- */
37
- renderToString.render = renderToString;
38
-
39
- /** Only render elements, leaving Components inline as `<ComponentName ... />`.
40
- * This method is just a convenience alias for `render(vnode, context, { shallow:true })`
41
- * @name shallow
42
- * @function
43
- * @param {VNode} vnode JSX VNode to render.
44
- * @param {Object} [context={}] Optionally pass an initial context object through the render path.
45
- */
46
- let shallowRender = (vnode, context) => renderToString(vnode, context, SHALLOW);
47
-
48
- const EMPTY_ARR = [];
49
- function renderToString(vnode, context, opts) {
50
- context = context || {};
51
- opts = opts || {};
52
-
53
- // Performance optimization: `renderToString` is synchronous and we
54
- // therefore don't execute any effects. To do that we pass an empty
55
- // array to `options._commit` (`__c`). But we can go one step further
56
- // and avoid a lot of dirty checks and allocations by setting
57
- // `options._skipEffects` (`__s`) too.
58
- const previousSkipEffects = options.__s;
59
- options.__s = true;
60
-
61
- const res = _renderToString(vnode, context, opts);
62
-
63
- // options._commit, we don't schedule any effects in this library right now,
64
- // so we can pass an empty queue to this hook.
65
- if (options.__c) options.__c(vnode, EMPTY_ARR);
66
- EMPTY_ARR.length = 0;
67
- options.__s = previousSkipEffects;
68
- return res;
69
- }
70
-
71
- /** The default export is an alias of `render()`. */
72
- function _renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
73
- if (vnode == null || typeof vnode === 'boolean') {
74
- return '';
75
- }
76
-
77
- // #text nodes
78
- if (typeof vnode !== 'object') {
79
- return encodeEntities(vnode);
80
- }
81
-
82
- let pretty = opts.pretty,
83
- indentChar = pretty && typeof pretty === 'string' ? pretty : '\t';
84
-
85
- if (Array.isArray(vnode)) {
86
- let rendered = '';
87
- for (let i = 0; i < vnode.length; i++) {
88
- if (pretty && i > 0) rendered += '\n';
89
- rendered += _renderToString(
90
- vnode[i],
91
- context,
92
- opts,
93
- inner,
94
- isSvgMode,
95
- selectValue
96
- );
97
- }
98
- return rendered;
99
- }
100
-
101
- let nodeName = vnode.type,
102
- props = vnode.props,
103
- isComponent = false;
104
-
105
- // components
106
- if (typeof nodeName === 'function') {
107
- isComponent = true;
108
- if (opts.shallow && (inner || opts.renderRootComponent === false)) {
109
- nodeName = getComponentName(nodeName);
110
- } else if (nodeName === Fragment) {
111
- const children = [];
112
- getChildren(children, vnode.props.children);
113
- return _renderToString(
114
- children,
115
- context,
116
- opts,
117
- opts.shallowHighOrder !== false,
118
- isSvgMode,
119
- selectValue
120
- );
121
- } else {
122
- let rendered;
123
-
124
- let c = (vnode.__c = {
125
- __v: vnode,
126
- context,
127
- props: vnode.props,
128
- // silently drop state updates
129
- setState: markAsDirty,
130
- forceUpdate: markAsDirty,
131
- __d: true,
132
- // hooks
133
- __h: []
134
- });
135
-
136
- // options._diff
137
- if (options.__b) options.__b(vnode);
138
-
139
- // options._render
140
- let renderHook = options.__r;
141
-
142
- if (
143
- !nodeName.prototype ||
144
- typeof nodeName.prototype.render !== 'function'
145
- ) {
146
- // Necessary for createContext api. Setting this property will pass
147
- // the context value as `this.context` just for this component.
148
- let cxType = nodeName.contextType;
149
- let provider = cxType && context[cxType.__c];
150
- let cctx =
151
- cxType != null
152
- ? provider
153
- ? provider.props.value
154
- : cxType.__
155
- : context;
156
-
157
- // If a hook invokes setState() to invalidate the component during rendering,
158
- // re-render it up to 25 times to allow "settling" of memoized states.
159
- // Note:
160
- // This will need to be updated for Preact 11 to use internal.flags rather than component._dirty:
161
- // https://github.com/preactjs/preact/blob/d4ca6fdb19bc715e49fd144e69f7296b2f4daa40/src/diff/component.js#L35-L44
162
- let count = 0;
163
- while (c.__d && count++ < 25) {
164
- c.__d = false;
165
-
166
- if (renderHook) renderHook(vnode);
167
-
168
- // stateless functional components
169
- rendered = nodeName.call(vnode.__c, props, cctx);
170
- }
171
- } else {
172
- // class-based components
173
- let cxType = nodeName.contextType;
174
- let provider = cxType && context[cxType.__c];
175
- let cctx =
176
- cxType != null
177
- ? provider
178
- ? provider.props.value
179
- : cxType.__
180
- : context;
181
-
182
- // c = new nodeName(props, context);
183
- c = vnode.__c = new nodeName(props, cctx);
184
- c.__v = vnode;
185
- // turn off stateful re-rendering:
186
- c._dirty = c.__d = true;
187
- c.props = props;
188
- if (c.state == null) c.state = {};
189
-
190
- if (c._nextState == null && c.__s == null) {
191
- c._nextState = c.__s = c.state;
192
- }
193
-
194
- c.context = cctx;
195
- if (nodeName.getDerivedStateFromProps)
196
- c.state = assign(
197
- assign({}, c.state),
198
- nodeName.getDerivedStateFromProps(c.props, c.state)
199
- );
200
- else if (c.componentWillMount) {
201
- c.componentWillMount();
202
-
203
- // If the user called setState in cWM we need to flush pending,
204
- // state updates. This is the same behaviour in React.
205
- c.state =
206
- c._nextState !== c.state
207
- ? c._nextState
208
- : c.__s !== c.state
209
- ? c.__s
210
- : c.state;
211
- }
212
-
213
- if (renderHook) renderHook(vnode);
214
-
215
- rendered = c.render(c.props, c.state, c.context);
216
- }
217
-
218
- if (c.getChildContext) {
219
- context = assign(assign({}, context), c.getChildContext());
220
- }
221
-
222
- if (options.diffed) options.diffed(vnode);
223
- return _renderToString(
224
- rendered,
225
- context,
226
- opts,
227
- opts.shallowHighOrder !== false,
228
- isSvgMode,
229
- selectValue
230
- );
231
- }
232
- }
233
-
234
- // render JSX to HTML
235
- let s = '<' + nodeName,
236
- propChildren,
237
- html;
238
-
239
- if (props) {
240
- let attrs = Object.keys(props);
241
-
242
- // allow sorting lexicographically for more determinism (useful for tests, such as via preact-jsx-chai)
243
- if (opts && opts.sortAttributes === true) attrs.sort();
244
-
245
- for (let i = 0; i < attrs.length; i++) {
246
- let name = attrs[i],
247
- v = props[name];
248
- if (name === 'children') {
249
- propChildren = v;
250
- continue;
251
- }
252
-
253
- if (UNSAFE_NAME.test(name)) continue;
254
-
255
- if (
256
- !(opts && opts.allAttributes) &&
257
- (name === 'key' ||
258
- name === 'ref' ||
259
- name === '__self' ||
260
- name === '__source')
261
- )
262
- continue;
263
-
264
- if (name === 'defaultValue') {
265
- name = 'value';
266
- } else if (name === 'className') {
267
- if (typeof props.class !== 'undefined') continue;
268
- name = 'class';
269
- } else if (isSvgMode && name.match(/^xlink:?./)) {
270
- name = name.toLowerCase().replace(/^xlink:?/, 'xlink:');
271
- }
272
-
273
- if (name === 'htmlFor') {
274
- if (props.for) continue;
275
- name = 'for';
276
- }
277
-
278
- if (name === 'style' && v && typeof v === 'object') {
279
- v = styleObjToCss(v);
280
- }
281
-
282
- // always use string values instead of booleans for aria attributes
283
- // also see https://github.com/preactjs/preact/pull/2347/files
284
- if (name[0] === 'a' && name['1'] === 'r' && typeof v === 'boolean') {
285
- v = String(v);
286
- }
287
-
288
- let hooked =
289
- opts.attributeHook &&
290
- opts.attributeHook(name, v, context, opts, isComponent);
291
- if (hooked || hooked === '') {
292
- s += hooked;
293
- continue;
294
- }
295
-
296
- if (name === 'dangerouslySetInnerHTML') {
297
- html = v && v.__html;
298
- } else if (nodeName === 'textarea' && name === 'value') {
299
- // <textarea value="a&b"> --> <textarea>a&amp;b</textarea>
300
- propChildren = v;
301
- } else if ((v || v === 0 || v === '') && typeof v !== 'function') {
302
- if (v === true || v === '') {
303
- v = name;
304
- // in non-xml mode, allow boolean attributes
305
- if (!opts || !opts.xml) {
306
- s += ' ' + name;
307
- continue;
308
- }
309
- }
310
-
311
- if (name === 'value') {
312
- if (nodeName === 'select') {
313
- selectValue = v;
314
- continue;
315
- } else if (
316
- // If we're looking at an <option> and it's the currently selected one
317
- nodeName === 'option' &&
318
- selectValue == v &&
319
- // and the <option> doesn't already have a selected attribute on it
320
- typeof props.selected === 'undefined'
321
- ) {
322
- s += ` selected`;
323
- }
324
- }
325
- s += ` ${name}="${encodeEntities(v)}"`;
326
- }
327
- }
328
- }
329
-
330
- // account for >1 multiline attribute
331
- if (pretty) {
332
- let sub = s.replace(/\n\s*/, ' ');
333
- if (sub !== s && !~sub.indexOf('\n')) s = sub;
334
- else if (pretty && ~s.indexOf('\n')) s += '\n';
335
- }
336
-
337
- s += '>';
338
-
339
- if (UNSAFE_NAME.test(nodeName))
340
- throw new Error(`${nodeName} is not a valid HTML tag name in ${s}`);
341
-
342
- let isVoid =
343
- VOID_ELEMENTS.test(nodeName) ||
344
- (opts.voidElements && opts.voidElements.test(nodeName));
345
- let pieces = [];
346
-
347
- let children;
348
- if (html) {
349
- // if multiline, indent.
350
- if (pretty && isLargeString(html)) {
351
- html = '\n' + indentChar + indent(html, indentChar);
352
- }
353
- s += html;
354
- } else if (
355
- propChildren != null &&
356
- getChildren((children = []), propChildren).length
357
- ) {
358
- let hasLarge = pretty && ~s.indexOf('\n');
359
- let lastWasText = false;
360
-
361
- for (let i = 0; i < children.length; i++) {
362
- let child = children[i];
363
-
364
- if (child != null && child !== false) {
365
- let childSvgMode =
366
- nodeName === 'svg'
367
- ? true
368
- : nodeName === 'foreignObject'
369
- ? false
370
- : isSvgMode,
371
- ret = _renderToString(
372
- child,
373
- context,
374
- opts,
375
- true,
376
- childSvgMode,
377
- selectValue
378
- );
379
-
380
- if (pretty && !hasLarge && isLargeString(ret)) hasLarge = true;
381
-
382
- // Skip if we received an empty string
383
- if (ret) {
384
- if (pretty) {
385
- let isText = ret.length > 0 && ret[0] != '<';
386
-
387
- // We merge adjacent text nodes, otherwise each piece would be printed
388
- // on a new line.
389
- if (lastWasText && isText) {
390
- pieces[pieces.length - 1] += ret;
391
- } else {
392
- pieces.push(ret);
393
- }
394
-
395
- lastWasText = isText;
396
- } else {
397
- pieces.push(ret);
398
- }
399
- }
400
- }
401
- }
402
- if (pretty && hasLarge) {
403
- for (let i = pieces.length; i--; ) {
404
- pieces[i] = '\n' + indentChar + indent(pieces[i], indentChar);
405
- }
406
- }
407
- }
408
-
409
- if (pieces.length || html) {
410
- s += pieces.join('');
411
- } else if (opts && opts.xml) {
412
- return s.substring(0, s.length - 1) + ' />';
413
- }
414
-
415
- if (isVoid && !children && !html) {
416
- s = s.replace(/>$/, ' />');
417
- } else {
418
- if (pretty && ~s.indexOf('\n')) s += '\n';
419
- s += `</${nodeName}>`;
420
- }
421
-
422
- return s;
423
- }
424
-
425
- function getComponentName(component) {
426
- return (
427
- component.displayName ||
428
- (component !== Function && component.name) ||
429
- getFallbackComponentName(component)
430
- );
431
- }
432
-
433
- function getFallbackComponentName(component) {
434
- let str = Function.prototype.toString.call(component),
435
- name = (str.match(/^\s*function\s+([^( ]+)/) || '')[1];
436
- if (!name) {
437
- // search for an existing indexed name for the given component:
438
- let index = -1;
439
- for (let i = UNNAMED.length; i--; ) {
440
- if (UNNAMED[i] === component) {
441
- index = i;
442
- break;
443
- }
444
- }
445
- // not found, create a new indexed name:
446
- if (index < 0) {
447
- index = UNNAMED.push(component) - 1;
448
- }
449
- name = `UnnamedComponent${index}`;
450
- }
451
- return name;
452
- }
453
- renderToString.shallowRender = shallowRender;
454
-
455
- export default renderToString;
456
-
457
- export {
458
- renderToString as render,
459
- renderToString as renderToStaticMarkup,
460
- renderToString,
461
- shallowRender
462
- };
@@ -1,13 +0,0 @@
1
- import { VNode } from 'preact';
2
-
3
- interface Options {
4
- jsx?: boolean;
5
- xml?: boolean;
6
- functions?: boolean;
7
- functionNames?: boolean;
8
- skipFalseAttributes?: boolean;
9
- pretty?: boolean | string;
10
- }
11
-
12
- export function render(vnode: VNode, context?: any, options?: Options): string;
13
- export default render;
@@ -1,76 +0,0 @@
1
- import './polyfills';
2
- import renderToString from './index';
3
- import { indent, encodeEntities, assign } from './util';
4
- import prettyFormat from 'pretty-format';
5
-
6
- // we have to patch in Array support, Possible issue in npm.im/pretty-format
7
- let preactPlugin = {
8
- test(object) {
9
- return (
10
- object &&
11
- typeof object === 'object' &&
12
- 'type' in object &&
13
- 'props' in object &&
14
- 'key' in object
15
- );
16
- },
17
- print(val, print, indent) {
18
- return renderToString(val, preactPlugin.context, preactPlugin.opts, true);
19
- }
20
- };
21
-
22
- let prettyFormatOpts = {
23
- plugins: [preactPlugin]
24
- };
25
-
26
- function attributeHook(name, value, context, opts, isComponent) {
27
- let type = typeof value;
28
-
29
- // Use render-to-string's built-in handling for these properties
30
- if (name === 'dangerouslySetInnerHTML') return false;
31
-
32
- // always skip null & undefined values, skip false DOM attributes, skip functions if told to
33
- if (value == null || (type === 'function' && !opts.functions)) return '';
34
-
35
- if (
36
- opts.skipFalseAttributes &&
37
- !isComponent &&
38
- (value === false ||
39
- ((name === 'class' || name === 'style') && value === ''))
40
- )
41
- return '';
42
-
43
- let indentChar = typeof opts.pretty === 'string' ? opts.pretty : '\t';
44
- if (type !== 'string') {
45
- if (type === 'function' && !opts.functionNames) {
46
- value = 'Function';
47
- } else {
48
- preactPlugin.context = context;
49
- preactPlugin.opts = opts;
50
- value = prettyFormat(value, prettyFormatOpts);
51
- if (~value.indexOf('\n')) {
52
- value = `${indent('\n' + value, indentChar)}\n`;
53
- }
54
- }
55
- return indent(`\n${name}={${value}}`, indentChar);
56
- }
57
- return `\n${indentChar}${name}="${encodeEntities(value)}"`;
58
- }
59
-
60
- let defaultOpts = {
61
- attributeHook,
62
- jsx: true,
63
- xml: false,
64
- functions: true,
65
- functionNames: true,
66
- skipFalseAttributes: true,
67
- pretty: ' '
68
- };
69
-
70
- function renderToJsxString(vnode, context, opts, inner) {
71
- opts = assign(assign({}, defaultOpts), opts || {});
72
- return renderToString(vnode, context, opts, inner);
73
- }
74
-
75
- export default renderToJsxString;
76
- export { renderToJsxString as render };