isomorfeus-preact 10.9.0 → 22.9.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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 -164
  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 -164
  109. data/node_modules/preact/compat/src/index.js +0 -223
  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 -1014
  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,225 +0,0 @@
1
- import { assign } from './util';
2
- import { diff, commitRoot } from './diff/index';
3
- import options from './options';
4
- import { Fragment } from './create-element';
5
-
6
- /**
7
- * Base Component class. Provides `setState()` and `forceUpdate()`, which
8
- * trigger rendering
9
- * @param {object} props The initial component props
10
- * @param {object} context The initial context from parent components'
11
- * getChildContext
12
- */
13
- export function Component(props, context) {
14
- this.props = props;
15
- this.context = context;
16
- }
17
-
18
- /**
19
- * Update component state and schedule a re-render.
20
- * @this {import('./internal').Component}
21
- * @param {object | ((s: object, p: object) => object)} update A hash of state
22
- * properties to update with new values or a function that given the current
23
- * state and props returns a new partial state
24
- * @param {() => void} [callback] A function to be called once component state is
25
- * updated
26
- */
27
- Component.prototype.setState = function(update, callback) {
28
- // only clone state when copying to nextState the first time.
29
- let s;
30
- if (this._nextState != null && this._nextState !== this.state) {
31
- s = this._nextState;
32
- } else {
33
- s = this._nextState = assign({}, this.state);
34
- }
35
-
36
- if (typeof update == 'function') {
37
- // Some libraries like `immer` mark the current state as readonly,
38
- // preventing us from mutating it, so we need to clone it. See #2716
39
- update = update(assign({}, s), this.props);
40
- }
41
-
42
- if (update) {
43
- assign(s, update);
44
- }
45
-
46
- // Skip update if updater function returned null
47
- if (update == null) return;
48
-
49
- if (this._vnode) {
50
- if (callback) this._renderCallbacks.push(callback);
51
- enqueueRender(this);
52
- }
53
- };
54
-
55
- /**
56
- * Immediately perform a synchronous re-render of the component
57
- * @this {import('./internal').Component}
58
- * @param {() => void} [callback] A function to be called after component is
59
- * re-rendered
60
- */
61
- Component.prototype.forceUpdate = function(callback) {
62
- if (this._vnode) {
63
- // Set render mode so that we can differentiate where the render request
64
- // is coming from. We need this because forceUpdate should never call
65
- // shouldComponentUpdate
66
- this._force = true;
67
- if (callback) this._renderCallbacks.push(callback);
68
- enqueueRender(this);
69
- }
70
- };
71
-
72
- /**
73
- * Accepts `props` and `state`, and returns a new Virtual DOM tree to build.
74
- * Virtual DOM is generally constructed via [JSX](http://jasonformat.com/wtf-is-jsx).
75
- * @param {object} props Props (eg: JSX attributes) received from parent
76
- * element/component
77
- * @param {object} state The component's current state
78
- * @param {object} context Context object, as returned by the nearest
79
- * ancestor's `getChildContext()`
80
- * @returns {import('./index').ComponentChildren | void}
81
- */
82
- Component.prototype.render = Fragment;
83
-
84
- /**
85
- * @param {import('./internal').VNode} vnode
86
- * @param {number | null} [childIndex]
87
- */
88
- export function getDomSibling(vnode, childIndex) {
89
- if (childIndex == null) {
90
- // Use childIndex==null as a signal to resume the search from the vnode's sibling
91
- return vnode._parent
92
- ? getDomSibling(vnode._parent, vnode._parent._children.indexOf(vnode) + 1)
93
- : null;
94
- }
95
-
96
- let sibling;
97
- for (; childIndex < vnode._children.length; childIndex++) {
98
- sibling = vnode._children[childIndex];
99
-
100
- if (sibling != null && sibling._dom != null) {
101
- // Since updateParentDomPointers keeps _dom pointer correct,
102
- // we can rely on _dom to tell us if this subtree contains a
103
- // rendered DOM node, and what the first rendered DOM node is
104
- return sibling._dom;
105
- }
106
- }
107
-
108
- // If we get here, we have not found a DOM node in this vnode's children.
109
- // We must resume from this vnode's sibling (in it's parent _children array)
110
- // Only climb up and search the parent if we aren't searching through a DOM
111
- // VNode (meaning we reached the DOM parent of the original vnode that began
112
- // the search)
113
- return typeof vnode.type == 'function' ? getDomSibling(vnode) : null;
114
- }
115
-
116
- /**
117
- * Trigger in-place re-rendering of a component.
118
- * @param {import('./internal').Component} component The component to rerender
119
- */
120
- function renderComponent(component) {
121
- let vnode = component._vnode,
122
- oldDom = vnode._dom,
123
- parentDom = component._parentDom;
124
-
125
- if (parentDom) {
126
- let commitQueue = [];
127
- const oldVNode = assign({}, vnode);
128
- oldVNode._original = vnode._original + 1;
129
-
130
- diff(
131
- parentDom,
132
- vnode,
133
- oldVNode,
134
- component._globalContext,
135
- parentDom.ownerSVGElement !== undefined,
136
- vnode._hydrating != null ? [oldDom] : null,
137
- commitQueue,
138
- oldDom == null ? getDomSibling(vnode) : oldDom,
139
- vnode._hydrating
140
- );
141
- commitRoot(commitQueue, vnode);
142
-
143
- if (vnode._dom != oldDom) {
144
- updateParentDomPointers(vnode);
145
- }
146
- }
147
- }
148
-
149
- /**
150
- * @param {import('./internal').VNode} vnode
151
- */
152
- function updateParentDomPointers(vnode) {
153
- if ((vnode = vnode._parent) != null && vnode._component != null) {
154
- vnode._dom = vnode._component.base = null;
155
- for (let i = 0; i < vnode._children.length; i++) {
156
- let child = vnode._children[i];
157
- if (child != null && child._dom != null) {
158
- vnode._dom = vnode._component.base = child._dom;
159
- break;
160
- }
161
- }
162
-
163
- return updateParentDomPointers(vnode);
164
- }
165
- }
166
-
167
- /**
168
- * The render queue
169
- * @type {Array<import('./internal').Component>}
170
- */
171
- let rerenderQueue = [];
172
-
173
- /**
174
- * Asynchronously schedule a callback
175
- * @type {(cb: () => void) => void}
176
- */
177
- /* istanbul ignore next */
178
- // Note the following line isn't tree-shaken by rollup cuz of rollup/rollup#2566
179
- const defer =
180
- typeof Promise == 'function'
181
- ? Promise.prototype.then.bind(Promise.resolve())
182
- : setTimeout;
183
-
184
- /*
185
- * The value of `Component.debounce` must asynchronously invoke the passed in callback. It is
186
- * important that contributors to Preact can consistently reason about what calls to `setState`, etc.
187
- * do, and when their effects will be applied. See the links below for some further reading on designing
188
- * asynchronous APIs.
189
- * * [Designing APIs for Asynchrony](https://blog.izs.me/2013/08/designing-apis-for-asynchrony)
190
- * * [Callbacks synchronous and asynchronous](https://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/)
191
- */
192
-
193
- let prevDebounce;
194
-
195
- /**
196
- * Enqueue a rerender of a component
197
- * @param {import('./internal').Component} c The component to rerender
198
- */
199
- export function enqueueRender(c) {
200
- if (
201
- (!c._dirty &&
202
- (c._dirty = true) &&
203
- rerenderQueue.push(c) &&
204
- !process._rerenderCount++) ||
205
- prevDebounce !== options.debounceRendering
206
- ) {
207
- prevDebounce = options.debounceRendering;
208
- (prevDebounce || defer)(process);
209
- }
210
- }
211
-
212
- /** Flush the render queue by rerendering all queued components */
213
- function process() {
214
- let queue;
215
- while ((process._rerenderCount = rerenderQueue.length)) {
216
- queue = rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
217
- rerenderQueue = [];
218
- // Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
219
- // process() calls from getting scheduled while `queue` is still being consumed.
220
- queue.some(c => {
221
- if (c._dirty) renderComponent(c);
222
- });
223
- }
224
- }
225
- process._rerenderCount = 0;
@@ -1,3 +0,0 @@
1
- export const EMPTY_OBJ = {};
2
- export const EMPTY_ARR = [];
3
- export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
@@ -1,68 +0,0 @@
1
- import { enqueueRender } from './component';
2
-
3
- export let i = 0;
4
-
5
- export function createContext(defaultValue, contextId) {
6
- contextId = '__cC' + i++;
7
-
8
- const context = {
9
- _id: contextId,
10
- _defaultValue: defaultValue,
11
- /** @type {import('./internal').FunctionComponent} */
12
- Consumer(props, contextValue) {
13
- // return props.children(
14
- // context[contextId] ? context[contextId].props.value : defaultValue
15
- // );
16
- return props.children(contextValue);
17
- },
18
- /** @type {import('./internal').FunctionComponent} */
19
- Provider(props) {
20
- if (!this.getChildContext) {
21
- let subs = [];
22
- let ctx = {};
23
- ctx[contextId] = this;
24
-
25
- this.getChildContext = () => ctx;
26
-
27
- this.shouldComponentUpdate = function(_props) {
28
- if (this.props.value !== _props.value) {
29
- // I think the forced value propagation here was only needed when `options.debounceRendering` was being bypassed:
30
- // https://github.com/preactjs/preact/commit/4d339fb803bea09e9f198abf38ca1bf8ea4b7771#diff-54682ce380935a717e41b8bfc54737f6R358
31
- // In those cases though, even with the value corrected, we're double-rendering all nodes.
32
- // It might be better to just tell folks not to use force-sync mode.
33
- // Currently, using `useContext()` in a class component will overwrite its `this.context` value.
34
- // subs.some(c => {
35
- // c.context = _props.value;
36
- // enqueueRender(c);
37
- // });
38
-
39
- // subs.some(c => {
40
- // c.context[contextId] = _props.value;
41
- // enqueueRender(c);
42
- // });
43
- subs.some(enqueueRender);
44
- }
45
- };
46
-
47
- this.sub = c => {
48
- subs.push(c);
49
- let old = c.componentWillUnmount;
50
- c.componentWillUnmount = () => {
51
- subs.splice(subs.indexOf(c), 1);
52
- if (old) old.call(c);
53
- };
54
- };
55
- }
56
-
57
- return props.children;
58
- }
59
- };
60
-
61
- // Devtools needs access to the context object when it
62
- // encounters a Provider. This is necessary to support
63
- // setting `displayName` on the context object instead
64
- // of on the component itself. See:
65
- // https://reactjs.org/docs/context.html#contextdisplayname
66
-
67
- return (context.Provider._contextRef = context.Consumer.contextType = context);
68
- }
@@ -1,98 +0,0 @@
1
- import { slice } from './util';
2
- import options from './options';
3
-
4
- let vnodeId = 0;
5
-
6
- /**
7
- * Create an virtual node (used for JSX)
8
- * @param {import('./internal').VNode["type"]} type The node name or Component
9
- * constructor for this virtual node
10
- * @param {object | null | undefined} [props] The properties of the virtual node
11
- * @param {Array<import('.').ComponentChildren>} [children] The children of the virtual node
12
- * @returns {import('./internal').VNode}
13
- */
14
- export function createElement(type, props, children) {
15
- let normalizedProps = {},
16
- key,
17
- ref,
18
- i;
19
- for (i in props) {
20
- if (i == 'key') key = props[i];
21
- else if (i == 'ref') ref = props[i];
22
- else normalizedProps[i] = props[i];
23
- }
24
-
25
- if (arguments.length > 2) {
26
- normalizedProps.children =
27
- arguments.length > 3 ? slice.call(arguments, 2) : children;
28
- }
29
-
30
- // If a Component VNode, check for and apply defaultProps
31
- // Note: type may be undefined in development, must never error here.
32
- if (typeof type == 'function' && type.defaultProps != null) {
33
- for (i in type.defaultProps) {
34
- if (normalizedProps[i] === undefined) {
35
- normalizedProps[i] = type.defaultProps[i];
36
- }
37
- }
38
- }
39
-
40
- return createVNode(type, normalizedProps, key, ref, null);
41
- }
42
-
43
- /**
44
- * Create a VNode (used internally by Preact)
45
- * @param {import('./internal').VNode["type"]} type The node name or Component
46
- * Constructor for this virtual node
47
- * @param {object | string | number | null} props The properties of this virtual node.
48
- * If this virtual node represents a text node, this is the text of the node (string or number).
49
- * @param {string | number | null} key The key for this virtual node, used when
50
- * diffing it against its children
51
- * @param {import('./internal').VNode["ref"]} ref The ref property that will
52
- * receive a reference to its created child
53
- * @returns {import('./internal').VNode}
54
- */
55
- export function createVNode(type, props, key, ref, original) {
56
- // V8 seems to be better at detecting type shapes if the object is allocated from the same call site
57
- // Do not inline into createElement and coerceToVNode!
58
- const vnode = {
59
- type,
60
- props,
61
- key,
62
- ref,
63
- _children: null,
64
- _parent: null,
65
- _depth: 0,
66
- _dom: null,
67
- // _nextDom must be initialized to undefined b/c it will eventually
68
- // be set to dom.nextSibling which can return `null` and it is important
69
- // to be able to distinguish between an uninitialized _nextDom and
70
- // a _nextDom that has been set to `null`
71
- _nextDom: undefined,
72
- _component: null,
73
- _hydrating: null,
74
- constructor: undefined,
75
- _original: original == null ? ++vnodeId : original
76
- };
77
-
78
- // Only invoke the vnode hook if this was *not* a direct copy:
79
- if (original == null && options.vnode != null) options.vnode(vnode);
80
-
81
- return vnode;
82
- }
83
-
84
- export function createRef() {
85
- return { current: null };
86
- }
87
-
88
- export function Fragment(props) {
89
- return props.children;
90
- }
91
-
92
- /**
93
- * Check if a the argument is a valid Preact VNode.
94
- * @param {*} vnode
95
- * @returns {vnode is import('./internal').VNode}
96
- */
97
- export const isValidElement = vnode =>
98
- vnode != null && vnode.constructor === undefined;
@@ -1,40 +0,0 @@
1
- /**
2
- * Find the closest error boundary to a thrown error and call it
3
- * @param {object} error The thrown value
4
- * @param {import('../internal').VNode} vnode The vnode that threw
5
- * the error that was caught (except for unmounting when this parameter
6
- * is the highest parent that was being unmounted)
7
- * @param {import('../internal').VNode} [oldVNode]
8
- * @param {import('../internal').ErrorInfo} [errorInfo]
9
- */
10
- export function _catchError(error, vnode, oldVNode, errorInfo) {
11
- /** @type {import('../internal').Component} */
12
- let component, ctor, handled;
13
-
14
- for (; (vnode = vnode._parent); ) {
15
- if ((component = vnode._component) && !component._processingException) {
16
- try {
17
- ctor = component.constructor;
18
-
19
- if (ctor && ctor.getDerivedStateFromError != null) {
20
- component.setState(ctor.getDerivedStateFromError(error));
21
- handled = component._dirty;
22
- }
23
-
24
- if (component.componentDidCatch != null) {
25
- component.componentDidCatch(error, errorInfo || {});
26
- handled = component._dirty;
27
- }
28
-
29
- // This is an error boundary. Mark it as having bailed out, and whether it was mid-hydration.
30
- if (handled) {
31
- return (component._pendingError = component);
32
- }
33
- } catch (e) {
34
- error = e;
35
- }
36
- }
37
- }
38
-
39
- throw error;
40
- }