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,335 +0,0 @@
1
- import { diff, unmount, applyRef } from './index';
2
- import { createVNode, Fragment } from '../create-element';
3
- import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
4
- import { getDomSibling } from '../component';
5
-
6
- /**
7
- * Diff the children of a virtual node
8
- * @param {import('../internal').PreactElement} parentDom The DOM element whose
9
- * children are being diffed
10
- * @param {import('../internal').ComponentChildren[]} renderResult
11
- * @param {import('../internal').VNode} newParentVNode The new virtual
12
- * node whose children should be diff'ed against oldParentVNode
13
- * @param {import('../internal').VNode} oldParentVNode The old virtual
14
- * node whose children should be diff'ed against newParentVNode
15
- * @param {object} globalContext The current context object - modified by getChildContext
16
- * @param {boolean} isSvg Whether or not this DOM node is an SVG node
17
- * @param {Array<import('../internal').PreactElement>} excessDomChildren
18
- * @param {Array<import('../internal').Component>} commitQueue List of components
19
- * which have callbacks to invoke in commitRoot
20
- * @param {import('../internal').PreactElement} oldDom The current attached DOM
21
- * element any new dom elements should be placed around. Likely `null` on first
22
- * render (except when hydrating). Can be a sibling DOM element when diffing
23
- * Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
24
- * @param {boolean} isHydrating Whether or not we are in hydration
25
- */
26
- export function diffChildren(
27
- parentDom,
28
- renderResult,
29
- newParentVNode,
30
- oldParentVNode,
31
- globalContext,
32
- isSvg,
33
- excessDomChildren,
34
- commitQueue,
35
- oldDom,
36
- isHydrating
37
- ) {
38
- let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
39
-
40
- // This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
41
- // as EMPTY_OBJ._children should be `undefined`.
42
- let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;
43
-
44
- let oldChildrenLength = oldChildren.length;
45
-
46
- newParentVNode._children = [];
47
- for (i = 0; i < renderResult.length; i++) {
48
- childVNode = renderResult[i];
49
-
50
- if (childVNode == null || typeof childVNode == 'boolean') {
51
- childVNode = newParentVNode._children[i] = null;
52
- }
53
- // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
54
- // or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
55
- // it's own DOM & etc. pointers
56
- else if (
57
- typeof childVNode == 'string' ||
58
- typeof childVNode == 'number' ||
59
- // eslint-disable-next-line valid-typeof
60
- typeof childVNode == 'bigint'
61
- ) {
62
- childVNode = newParentVNode._children[i] = createVNode(
63
- null,
64
- childVNode,
65
- null,
66
- null,
67
- childVNode
68
- );
69
- } else if (Array.isArray(childVNode)) {
70
- childVNode = newParentVNode._children[i] = createVNode(
71
- Fragment,
72
- { children: childVNode },
73
- null,
74
- null,
75
- null
76
- );
77
- } else if (childVNode._depth > 0) {
78
- // VNode is already in use, clone it. This can happen in the following
79
- // scenario:
80
- // const reuse = <div />
81
- // <div>{reuse}<span />{reuse}</div>
82
- childVNode = newParentVNode._children[i] = createVNode(
83
- childVNode.type,
84
- childVNode.props,
85
- childVNode.key,
86
- null,
87
- childVNode._original
88
- );
89
- } else {
90
- childVNode = newParentVNode._children[i] = childVNode;
91
- }
92
-
93
- // Terser removes the `continue` here and wraps the loop body
94
- // in a `if (childVNode) { ... } condition
95
- if (childVNode == null) {
96
- continue;
97
- }
98
-
99
- childVNode._parent = newParentVNode;
100
- childVNode._depth = newParentVNode._depth + 1;
101
-
102
- // Check if we find a corresponding element in oldChildren.
103
- // If found, delete the array item by setting to `undefined`.
104
- // We use `undefined`, as `null` is reserved for empty placeholders
105
- // (holes).
106
- oldVNode = oldChildren[i];
107
-
108
- if (
109
- oldVNode === null ||
110
- (oldVNode &&
111
- childVNode.key == oldVNode.key &&
112
- childVNode.type === oldVNode.type)
113
- ) {
114
- oldChildren[i] = undefined;
115
- } else {
116
- // Either oldVNode === undefined or oldChildrenLength > 0,
117
- // so after this loop oldVNode == null or oldVNode is a valid value.
118
- for (j = 0; j < oldChildrenLength; j++) {
119
- oldVNode = oldChildren[j];
120
- // If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
121
- // We always match by type (in either case).
122
- if (
123
- oldVNode &&
124
- childVNode.key == oldVNode.key &&
125
- childVNode.type === oldVNode.type
126
- ) {
127
- oldChildren[j] = undefined;
128
- break;
129
- }
130
- oldVNode = null;
131
- }
132
- }
133
-
134
- oldVNode = oldVNode || EMPTY_OBJ;
135
-
136
- // Morph the old element into the new one, but don't append it to the dom yet
137
- diff(
138
- parentDom,
139
- childVNode,
140
- oldVNode,
141
- globalContext,
142
- isSvg,
143
- excessDomChildren,
144
- commitQueue,
145
- oldDom,
146
- isHydrating
147
- );
148
-
149
- newDom = childVNode._dom;
150
-
151
- if ((j = childVNode.ref) && oldVNode.ref != j) {
152
- if (!refs) refs = [];
153
- if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
154
- refs.push(j, childVNode._component || newDom, childVNode);
155
- }
156
-
157
- if (newDom != null) {
158
- if (firstChildDom == null) {
159
- firstChildDom = newDom;
160
- }
161
-
162
- if (
163
- typeof childVNode.type == 'function' &&
164
- childVNode._children === oldVNode._children
165
- ) {
166
- childVNode._nextDom = oldDom = reorderChildren(
167
- childVNode,
168
- oldDom,
169
- parentDom
170
- );
171
- } else {
172
- oldDom = placeChild(
173
- parentDom,
174
- childVNode,
175
- oldVNode,
176
- oldChildren,
177
- newDom,
178
- oldDom
179
- );
180
- }
181
-
182
- if (typeof newParentVNode.type == 'function') {
183
- // Because the newParentVNode is Fragment-like, we need to set it's
184
- // _nextDom property to the nextSibling of its last child DOM node.
185
- //
186
- // `oldDom` contains the correct value here because if the last child
187
- // is a Fragment-like, then oldDom has already been set to that child's _nextDom.
188
- // If the last child is a DOM VNode, then oldDom will be set to that DOM
189
- // node's nextSibling.
190
- newParentVNode._nextDom = oldDom;
191
- }
192
- } else if (
193
- oldDom &&
194
- oldVNode._dom == oldDom &&
195
- oldDom.parentNode != parentDom
196
- ) {
197
- // The above condition is to handle null placeholders. See test in placeholder.test.js:
198
- // `efficiently replace null placeholders in parent rerenders`
199
- oldDom = getDomSibling(oldVNode);
200
- }
201
- }
202
-
203
- newParentVNode._dom = firstChildDom;
204
-
205
- // Remove remaining oldChildren if there are any.
206
- for (i = oldChildrenLength; i--; ) {
207
- if (oldChildren[i] != null) {
208
- if (
209
- typeof newParentVNode.type == 'function' &&
210
- oldChildren[i]._dom != null &&
211
- oldChildren[i]._dom == newParentVNode._nextDom
212
- ) {
213
- // If the newParentVNode.__nextDom points to a dom node that is about to
214
- // be unmounted, then get the next sibling of that vnode and set
215
- // _nextDom to it
216
- newParentVNode._nextDom = getDomSibling(oldParentVNode, i + 1);
217
- }
218
-
219
- unmount(oldChildren[i], oldChildren[i]);
220
- }
221
- }
222
-
223
- // Set refs only after unmount
224
- if (refs) {
225
- for (i = 0; i < refs.length; i++) {
226
- applyRef(refs[i], refs[++i], refs[++i]);
227
- }
228
- }
229
- }
230
-
231
- function reorderChildren(childVNode, oldDom, parentDom) {
232
- // Note: VNodes in nested suspended trees may be missing _children.
233
- let c = childVNode._children;
234
- let tmp = 0;
235
- for (; c && tmp < c.length; tmp++) {
236
- let vnode = c[tmp];
237
- if (vnode) {
238
- // We typically enter this code path on sCU bailout, where we copy
239
- // oldVNode._children to newVNode._children. If that is the case, we need
240
- // to update the old children's _parent pointer to point to the newVNode
241
- // (childVNode here).
242
- vnode._parent = childVNode;
243
-
244
- if (typeof vnode.type == 'function') {
245
- oldDom = reorderChildren(vnode, oldDom, parentDom);
246
- } else {
247
- oldDom = placeChild(
248
- parentDom,
249
- vnode,
250
- vnode,
251
- c,
252
- vnode._dom,
253
- oldDom
254
- );
255
- }
256
- }
257
- }
258
-
259
- return oldDom;
260
- }
261
-
262
- /**
263
- * Flatten and loop through the children of a virtual node
264
- * @param {import('../index').ComponentChildren} children The unflattened
265
- * children of a virtual node
266
- * @returns {import('../internal').VNode[]}
267
- */
268
- export function toChildArray(children, out) {
269
- out = out || [];
270
- if (children == null || typeof children == 'boolean') {
271
- } else if (Array.isArray(children)) {
272
- children.some(child => {
273
- toChildArray(child, out);
274
- });
275
- } else {
276
- out.push(children);
277
- }
278
- return out;
279
- }
280
-
281
- function placeChild(
282
- parentDom,
283
- childVNode,
284
- oldVNode,
285
- oldChildren,
286
- newDom,
287
- oldDom
288
- ) {
289
- let nextDom;
290
- if (childVNode._nextDom !== undefined) {
291
- // Only Fragments or components that return Fragment like VNodes will
292
- // have a non-undefined _nextDom. Continue the diff from the sibling
293
- // of last DOM child of this child VNode
294
- nextDom = childVNode._nextDom;
295
-
296
- // Eagerly cleanup _nextDom. We don't need to persist the value because
297
- // it is only used by `diffChildren` to determine where to resume the diff after
298
- // diffing Components and Fragments. Once we store it the nextDOM local var, we
299
- // can clean up the property
300
- childVNode._nextDom = undefined;
301
- } else if (
302
- oldVNode == null ||
303
- newDom != oldDom ||
304
- newDom.parentNode == null
305
- ) {
306
- outer: if (oldDom == null || oldDom.parentNode !== parentDom) {
307
- parentDom.appendChild(newDom);
308
- nextDom = null;
309
- } else {
310
- // `j<oldChildrenLength; j+=2` is an alternative to `j++<oldChildrenLength/2`
311
- for (
312
- let sibDom = oldDom, j = 0;
313
- (sibDom = sibDom.nextSibling) && j < oldChildren.length;
314
- j += 2
315
- ) {
316
- if (sibDom == newDom) {
317
- break outer;
318
- }
319
- }
320
- parentDom.insertBefore(newDom, oldDom);
321
- nextDom = oldDom;
322
- }
323
- }
324
-
325
- // If we have pre-calculated the nextDOM node, use it. Else calculate it now
326
- // Strictly check for `undefined` here cuz `null` is a valid value of `nextDom`.
327
- // See more detail in create-element.js:createVNode
328
- if (nextDom !== undefined) {
329
- oldDom = nextDom;
330
- } else {
331
- oldDom = newDom.nextSibling;
332
- }
333
-
334
- return oldDom;
335
- }