@faiwer/react 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +90 -0
  2. package/dist/core/actions/applyAction.d.ts +11 -0
  3. package/dist/core/actions/applyAction.d.ts.map +1 -0
  4. package/dist/core/actions/applyAction.js +35 -0
  5. package/dist/core/actions/applyAction.js.map +1 -0
  6. package/dist/core/actions/createComment.action.d.ts +7 -0
  7. package/dist/core/actions/createComment.action.d.ts.map +1 -0
  8. package/dist/core/actions/createComment.action.js +20 -0
  9. package/dist/core/actions/createComment.action.js.map +1 -0
  10. package/dist/core/actions/createTag.action.d.ts +10 -0
  11. package/dist/core/actions/createTag.action.d.ts.map +1 -0
  12. package/dist/core/actions/createTag.action.js +27 -0
  13. package/dist/core/actions/createTag.action.js.map +1 -0
  14. package/dist/core/actions/createText.action.d.ts +6 -0
  15. package/dist/core/actions/createText.action.d.ts.map +1 -0
  16. package/dist/core/actions/createText.action.js +16 -0
  17. package/dist/core/actions/createText.action.js.map +1 -0
  18. package/dist/core/actions/helpers.d.ts +43 -0
  19. package/dist/core/actions/helpers.d.ts.map +1 -0
  20. package/dist/core/actions/helpers.js +141 -0
  21. package/dist/core/actions/helpers.js.map +1 -0
  22. package/dist/core/actions/relayout.action.d.ts +20 -0
  23. package/dist/core/actions/relayout.action.d.ts.map +1 -0
  24. package/dist/core/actions/relayout.action.js +113 -0
  25. package/dist/core/actions/relayout.action.js.map +1 -0
  26. package/dist/core/actions/remove.action.d.ts +7 -0
  27. package/dist/core/actions/remove.action.d.ts.map +1 -0
  28. package/dist/core/actions/remove.action.js +64 -0
  29. package/dist/core/actions/remove.action.js.map +1 -0
  30. package/dist/core/actions/replace.action.d.ts +18 -0
  31. package/dist/core/actions/replace.action.d.ts.map +1 -0
  32. package/dist/core/actions/replace.action.js +57 -0
  33. package/dist/core/actions/replace.action.js.map +1 -0
  34. package/dist/core/actions/setAttr.action.d.ts +9 -0
  35. package/dist/core/actions/setAttr.action.d.ts.map +1 -0
  36. package/dist/core/actions/setAttr.action.js +62 -0
  37. package/dist/core/actions/setAttr.action.js.map +1 -0
  38. package/dist/core/actions/setProps.action.d.ts +8 -0
  39. package/dist/core/actions/setProps.action.d.ts.map +1 -0
  40. package/dist/core/actions/setProps.action.js +13 -0
  41. package/dist/core/actions/setProps.action.js.map +1 -0
  42. package/dist/core/actions/setRef.action.d.ts +11 -0
  43. package/dist/core/actions/setRef.action.d.ts.map +1 -0
  44. package/dist/core/actions/setRef.action.js +38 -0
  45. package/dist/core/actions/setRef.action.js.map +1 -0
  46. package/dist/core/actions/setText.action.d.ts +7 -0
  47. package/dist/core/actions/setText.action.d.ts.map +1 -0
  48. package/dist/core/actions/setText.action.js +12 -0
  49. package/dist/core/actions/setText.action.js.map +1 -0
  50. package/dist/core/compact.d.ts +38 -0
  51. package/dist/core/compact.d.ts.map +1 -0
  52. package/dist/core/compact.js +112 -0
  53. package/dist/core/compact.js.map +1 -0
  54. package/dist/core/components.d.ts +32 -0
  55. package/dist/core/components.d.ts.map +1 -0
  56. package/dist/core/components.js +57 -0
  57. package/dist/core/components.js.map +1 -0
  58. package/dist/core/createElement.d.ts +47 -0
  59. package/dist/core/createElement.d.ts.map +1 -0
  60. package/dist/core/createElement.js +73 -0
  61. package/dist/core/createElement.js.map +1 -0
  62. package/dist/core/createRoot.d.ts +13 -0
  63. package/dist/core/createRoot.d.ts.map +1 -0
  64. package/dist/core/createRoot.js +33 -0
  65. package/dist/core/createRoot.js.map +1 -0
  66. package/dist/core/reactNodeToFiberNode.d.ts +8 -0
  67. package/dist/core/reactNodeToFiberNode.d.ts.map +1 -0
  68. package/dist/core/reactNodeToFiberNode.js +132 -0
  69. package/dist/core/reactNodeToFiberNode.js.map +1 -0
  70. package/dist/core/reconciliation/app.d.ts +5 -0
  71. package/dist/core/reconciliation/app.d.ts.map +1 -0
  72. package/dist/core/reconciliation/app.js +20 -0
  73. package/dist/core/reconciliation/app.js.map +1 -0
  74. package/dist/core/reconciliation/applyActions.d.ts +8 -0
  75. package/dist/core/reconciliation/applyActions.d.ts.map +1 -0
  76. package/dist/core/reconciliation/applyActions.js +12 -0
  77. package/dist/core/reconciliation/applyActions.js.map +1 -0
  78. package/dist/core/reconciliation/collect/fromApp.d.ts +9 -0
  79. package/dist/core/reconciliation/collect/fromApp.d.ts.map +1 -0
  80. package/dist/core/reconciliation/collect/fromApp.js +39 -0
  81. package/dist/core/reconciliation/collect/fromApp.js.map +1 -0
  82. package/dist/core/reconciliation/collect/fromChildrenPair.d.ts +9 -0
  83. package/dist/core/reconciliation/collect/fromChildrenPair.d.ts.map +1 -0
  84. package/dist/core/reconciliation/collect/fromChildrenPair.js +127 -0
  85. package/dist/core/reconciliation/collect/fromChildrenPair.js.map +1 -0
  86. package/dist/core/reconciliation/collect/fromComponent.d.ts +10 -0
  87. package/dist/core/reconciliation/collect/fromComponent.d.ts.map +1 -0
  88. package/dist/core/reconciliation/collect/fromComponent.js +22 -0
  89. package/dist/core/reconciliation/collect/fromComponent.js.map +1 -0
  90. package/dist/core/reconciliation/collect/fromFiberPair.d.ts +9 -0
  91. package/dist/core/reconciliation/collect/fromFiberPair.d.ts.map +1 -0
  92. package/dist/core/reconciliation/collect/fromFiberPair.js +125 -0
  93. package/dist/core/reconciliation/collect/fromFiberPair.js.map +1 -0
  94. package/dist/core/reconciliation/collect/fromNewFiber.d.ts +7 -0
  95. package/dist/core/reconciliation/collect/fromNewFiber.d.ts.map +1 -0
  96. package/dist/core/reconciliation/collect/fromNewFiber.js +45 -0
  97. package/dist/core/reconciliation/collect/fromNewFiber.js.map +1 -0
  98. package/dist/core/reconciliation/comments.d.ts +3 -0
  99. package/dist/core/reconciliation/comments.d.ts.map +1 -0
  100. package/dist/core/reconciliation/comments.js +3 -0
  101. package/dist/core/reconciliation/comments.js.map +1 -0
  102. package/dist/core/reconciliation/compare/areFiberNodesEq.d.ts +7 -0
  103. package/dist/core/reconciliation/compare/areFiberNodesEq.d.ts.map +1 -0
  104. package/dist/core/reconciliation/compare/areFiberNodesEq.js +14 -0
  105. package/dist/core/reconciliation/compare/areFiberNodesEq.js.map +1 -0
  106. package/dist/core/reconciliation/compare/areFiberPropsEq.d.ts +7 -0
  107. package/dist/core/reconciliation/compare/areFiberPropsEq.d.ts.map +1 -0
  108. package/dist/core/reconciliation/compare/areFiberPropsEq.js +18 -0
  109. package/dist/core/reconciliation/compare/areFiberPropsEq.js.map +1 -0
  110. package/dist/core/reconciliation/effects.d.ts +14 -0
  111. package/dist/core/reconciliation/effects.d.ts.map +1 -0
  112. package/dist/core/reconciliation/effects.js +26 -0
  113. package/dist/core/reconciliation/effects.js.map +1 -0
  114. package/dist/core/reconciliation/fibers.d.ts +35 -0
  115. package/dist/core/reconciliation/fibers.d.ts.map +1 -0
  116. package/dist/core/reconciliation/fibers.js +51 -0
  117. package/dist/core/reconciliation/fibers.js.map +1 -0
  118. package/dist/core/reconciliation/invalidateFiber.d.ts +8 -0
  119. package/dist/core/reconciliation/invalidateFiber.d.ts.map +1 -0
  120. package/dist/core/reconciliation/invalidateFiber.js +28 -0
  121. package/dist/core/reconciliation/invalidateFiber.js.map +1 -0
  122. package/dist/core/reconciliation/mount.d.ts +7 -0
  123. package/dist/core/reconciliation/mount.d.ts.map +1 -0
  124. package/dist/core/reconciliation/mount.js +53 -0
  125. package/dist/core/reconciliation/mount.js.map +1 -0
  126. package/dist/core/reconciliation/postCommit.d.ts +11 -0
  127. package/dist/core/reconciliation/postCommit.d.ts.map +1 -0
  128. package/dist/core/reconciliation/postCommit.js +47 -0
  129. package/dist/core/reconciliation/postCommit.js.map +1 -0
  130. package/dist/core/reconciliation/render.d.ts +11 -0
  131. package/dist/core/reconciliation/render.d.ts.map +1 -0
  132. package/dist/core/reconciliation/render.js +35 -0
  133. package/dist/core/reconciliation/render.js.map +1 -0
  134. package/dist/core/reconciliation/runFiberComponents.d.ts +10 -0
  135. package/dist/core/reconciliation/runFiberComponents.d.ts.map +1 -0
  136. package/dist/core/reconciliation/runFiberComponents.js +37 -0
  137. package/dist/core/reconciliation/runFiberComponents.js.map +1 -0
  138. package/dist/core/reconciliation/typeGuards.d.ts +12 -0
  139. package/dist/core/reconciliation/typeGuards.d.ts.map +1 -0
  140. package/dist/core/reconciliation/typeGuards.js +32 -0
  141. package/dist/core/reconciliation/typeGuards.js.map +1 -0
  142. package/dist/core/reconciliation/validateTree.d.ts +6 -0
  143. package/dist/core/reconciliation/validateTree.d.ts.map +1 -0
  144. package/dist/core/reconciliation/validateTree.js +48 -0
  145. package/dist/core/reconciliation/validateTree.js.map +1 -0
  146. package/dist/hooks/helpers.d.ts +19 -0
  147. package/dist/hooks/helpers.d.ts.map +1 -0
  148. package/dist/hooks/helpers.js +40 -0
  149. package/dist/hooks/helpers.js.map +1 -0
  150. package/dist/hooks/index.d.ts +9 -0
  151. package/dist/hooks/index.d.ts.map +1 -0
  152. package/dist/hooks/index.js +9 -0
  153. package/dist/hooks/index.js.map +1 -0
  154. package/dist/hooks/useCallback.d.ts +2 -0
  155. package/dist/hooks/useCallback.d.ts.map +1 -0
  156. package/dist/hooks/useCallback.js +5 -0
  157. package/dist/hooks/useCallback.js.map +1 -0
  158. package/dist/hooks/useContext.d.ts +37 -0
  159. package/dist/hooks/useContext.d.ts.map +1 -0
  160. package/dist/hooks/useContext.js +101 -0
  161. package/dist/hooks/useContext.js.map +1 -0
  162. package/dist/hooks/useEffect.d.ts +48 -0
  163. package/dist/hooks/useEffect.d.ts.map +1 -0
  164. package/dist/hooks/useEffect.js +100 -0
  165. package/dist/hooks/useEffect.js.map +1 -0
  166. package/dist/hooks/useId.d.ts +2 -0
  167. package/dist/hooks/useId.d.ts.map +1 -0
  168. package/dist/hooks/useId.js +10 -0
  169. package/dist/hooks/useId.js.map +1 -0
  170. package/dist/hooks/useMemo.d.ts +20 -0
  171. package/dist/hooks/useMemo.d.ts.map +1 -0
  172. package/dist/hooks/useMemo.js +33 -0
  173. package/dist/hooks/useMemo.js.map +1 -0
  174. package/dist/hooks/useRef.d.ts +4 -0
  175. package/dist/hooks/useRef.d.ts.map +1 -0
  176. package/dist/hooks/useRef.js +9 -0
  177. package/dist/hooks/useRef.js.map +1 -0
  178. package/dist/hooks/useStableCallback.d.ts +45 -0
  179. package/dist/hooks/useStableCallback.d.ts.map +1 -0
  180. package/dist/hooks/useStableCallback.js +66 -0
  181. package/dist/hooks/useStableCallback.js.map +1 -0
  182. package/dist/hooks/useState.d.ts +15 -0
  183. package/dist/hooks/useState.d.ts.map +1 -0
  184. package/dist/hooks/useState.js +39 -0
  185. package/dist/hooks/useState.js.map +1 -0
  186. package/dist/index.d.ts +8 -0
  187. package/dist/index.d.ts.map +1 -0
  188. package/dist/index.js +13 -0
  189. package/dist/index.js.map +1 -0
  190. package/dist/jsx-dev-runtime.d.ts +6 -0
  191. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  192. package/dist/jsx-dev-runtime.js +7 -0
  193. package/dist/jsx-dev-runtime.js.map +1 -0
  194. package/dist/jsx-runtime.d.ts +31 -0
  195. package/dist/jsx-runtime.d.ts.map +1 -0
  196. package/dist/jsx-runtime.js +32 -0
  197. package/dist/jsx-runtime.js.map +1 -0
  198. package/dist/testing.d.ts +8 -0
  199. package/dist/testing.d.ts.map +1 -0
  200. package/dist/testing.js +10 -0
  201. package/dist/testing.js.map +1 -0
  202. package/dist/types/actions.d.ts +53 -0
  203. package/dist/types/actions.d.ts.map +1 -0
  204. package/dist/types/actions.js +2 -0
  205. package/dist/types/actions.js.map +1 -0
  206. package/dist/types/app.d.ts +74 -0
  207. package/dist/types/app.d.ts.map +1 -0
  208. package/dist/types/app.js +2 -0
  209. package/dist/types/app.js.map +1 -0
  210. package/dist/types/component.d.ts +11 -0
  211. package/dist/types/component.d.ts.map +1 -0
  212. package/dist/types/component.js +2 -0
  213. package/dist/types/component.js.map +1 -0
  214. package/dist/types/context.d.ts +28 -0
  215. package/dist/types/context.d.ts.map +1 -0
  216. package/dist/types/context.js +2 -0
  217. package/dist/types/context.js.map +1 -0
  218. package/dist/types/core.d.ts +51 -0
  219. package/dist/types/core.d.ts.map +1 -0
  220. package/dist/types/core.js +2 -0
  221. package/dist/types/core.js.map +1 -0
  222. package/dist/types/dom.d.ts +48 -0
  223. package/dist/types/dom.d.ts.map +1 -0
  224. package/dist/types/dom.js +2 -0
  225. package/dist/types/dom.js.map +1 -0
  226. package/dist/types/fiber.d.ts +169 -0
  227. package/dist/types/fiber.d.ts.map +1 -0
  228. package/dist/types/fiber.js +2 -0
  229. package/dist/types/fiber.js.map +1 -0
  230. package/dist/types/hooks.d.ts +47 -0
  231. package/dist/types/hooks.d.ts.map +1 -0
  232. package/dist/types/hooks.js +2 -0
  233. package/dist/types/hooks.js.map +1 -0
  234. package/dist/types/index.d.ts +9 -0
  235. package/dist/types/index.d.ts.map +1 -0
  236. package/dist/types/index.js +9 -0
  237. package/dist/types/index.js.map +1 -0
  238. package/dist/types/refs.d.ts +19 -0
  239. package/dist/types/refs.d.ts.map +1 -0
  240. package/dist/types/refs.js +2 -0
  241. package/dist/types/refs.js.map +1 -0
  242. package/dist/utils.d.ts +2 -0
  243. package/dist/utils.d.ts.map +1 -0
  244. package/dist/utils.js +7 -0
  245. package/dist/utils.js.map +1 -0
  246. package/package.json +67 -0
@@ -0,0 +1,47 @@
1
+ import type { ElementNode, ElementType, ReactContextProvider, ReactKey } from '../types';
2
+ /**
3
+ * This method is used as the JSX resolver. Every <tag/> or <Component/> is a
4
+ * call to this method.
5
+ *
6
+ * @example
7
+ * <div key="key" className="a" /> ===
8
+ * createElement('div', { className: 'a' }, 'key');
9
+ * <div>content</div> ===
10
+ * createElement('div', { children: 'content' });
11
+ * <div>{[1, 2]}</div> ===
12
+ * createElement('div', children: [1, 2]);
13
+ * <Message p1={1} p2={true} p3="p3" key="key">content</Message>
14
+ * createElement(
15
+ * Message,
16
+ * { p1: 1, p2: true, p3: 'p3', children: 'content' },
17
+ * key
18
+ * );
19
+ */
20
+ export declare function createElement(
21
+ /**
22
+ * What to render. Can be a tag (string), a component (function),
23
+ * or a portal target (HTMLElement).
24
+ */
25
+ type: ReactContextProvider | ElementType | HTMLElement, propsRaw: Record<PropertyKey, unknown>, key: ReactKey | null | undefined, _isStaticChildren?: boolean, _source?: Source, _self?: unknown): ElementNode;
26
+ type Source = {
27
+ fileName: string;
28
+ lineNumber: number;
29
+ columnNumber: number;
30
+ };
31
+ /**
32
+ * Renders content into an external HTML node. Unlike React, this version
33
+ * doesn't support interdimensional event bubbling.
34
+ *
35
+ * Following the React's approach, this library doesn't use <Portal target=?/>
36
+ * syntax. Thus, it's a simple wrapper around `createElement` with `type ===
37
+ * domNode`.
38
+ */
39
+ export declare function createPortal(
40
+ /** What to render. */
41
+ children: JSX.Element,
42
+ /** Where to render. */
43
+ domNode: HTMLElement,
44
+ /** Custom key if you need to conditionally recreate portals. */
45
+ key?: string): ElementNode;
46
+ export {};
47
+ //# sourceMappingURL=createElement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createElement.d.ts","sourceRoot":"","sources":["../../src/core/createElement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,QAAQ,EAET,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa;AAC3B;;;GAGG;AAEH,IAAI,EAEA,oBAAoB,GAEpB,WAAW,GAEX,WAAW,EACf,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EACtC,GAAG,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EAGhC,iBAAiB,CAAC,EAAE,OAAO,EAC3B,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,OAAO,GACd,WAAW,CAgCb;AAED,KAAK,MAAM,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAMF;;;;;;;GAOG;AACH,wBAAgB,YAAY;AAC1B,sBAAsB;AACtB,QAAQ,EAAE,GAAG,CAAC,OAAO;AACrB,uBAAuB;AACvB,OAAO,EAAE,WAAW;AACpB,gEAAgE;AAChE,GAAG,CAAC,EAAE,MAAM,eAGb"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * This method is used as the JSX resolver. Every <tag/> or <Component/> is a
3
+ * call to this method.
4
+ *
5
+ * @example
6
+ * <div key="key" className="a" /> ===
7
+ * createElement('div', { className: 'a' }, 'key');
8
+ * <div>content</div> ===
9
+ * createElement('div', { children: 'content' });
10
+ * <div>{[1, 2]}</div> ===
11
+ * createElement('div', children: [1, 2]);
12
+ * <Message p1={1} p2={true} p3="p3" key="key">content</Message>
13
+ * createElement(
14
+ * Message,
15
+ * { p1: 1, p2: true, p3: 'p3', children: 'content' },
16
+ * key
17
+ * );
18
+ */
19
+ export function createElement(
20
+ /**
21
+ * What to render. Can be a tag (string), a component (function),
22
+ * or a portal target (HTMLElement).
23
+ */
24
+ // prettier-ignore
25
+ type, propsRaw, key,
26
+ // The following arguments are provided only in the development mode.
27
+ // TODO: Support them to show more informative warnings and errors.
28
+ _isStaticChildren, _source, _self) {
29
+ key ??= null; // Narrow the type for simplicity.
30
+ if (typeof type === 'function') {
31
+ // Any component instance (<Message/>).
32
+ return {
33
+ type,
34
+ props: propsRaw,
35
+ key,
36
+ // ComponentFiber doesn't support direct children since we don't know
37
+ // what's inside until the component runs. Children are passed via `props`
38
+ // instead.
39
+ children: [],
40
+ };
41
+ }
42
+ // Any tag instance (<div/>).
43
+ let { children, ...propsWithoutChildren } = propsRaw;
44
+ if (!Array.isArray(children)) {
45
+ // - Case 1: <div>1</div> (the only child)
46
+ // - Case 2: <div/> | <div></div> (no children)
47
+ children = children === undefined ? [] : [children];
48
+ }
49
+ return {
50
+ type,
51
+ props: propsWithoutChildren,
52
+ key,
53
+ children,
54
+ };
55
+ }
56
+ /**
57
+ * Renders content into an external HTML node. Unlike React, this version
58
+ * doesn't support interdimensional event bubbling.
59
+ *
60
+ * Following the React's approach, this library doesn't use <Portal target=?/>
61
+ * syntax. Thus, it's a simple wrapper around `createElement` with `type ===
62
+ * domNode`.
63
+ */
64
+ export function createPortal(
65
+ /** What to render. */
66
+ children,
67
+ /** Where to render. */
68
+ domNode,
69
+ /** Custom key if you need to conditionally recreate portals. */
70
+ key) {
71
+ return createElement(domNode, { children }, key);
72
+ }
73
+ //# sourceMappingURL=createElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createElement.js","sourceRoot":"","sources":["../../src/core/createElement.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa;AAC3B;;;GAGG;AACH,kBAAkB;AAClB,IAMe,EACf,QAAsC,EACtC,GAAgC;AAChC,qEAAqE;AACrE,mEAAmE;AACnE,iBAA2B,EAC3B,OAAgB,EAChB,KAAe,EACF;IACb,GAAG,KAAK,IAAI,CAAC,CAAC,kCAAkC;IAEhD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,uCAAuC;QACvC,OAAO;YACL,IAAI;YACJ,KAAK,EAAE,QAAQ;YACf,GAAG;YACH,qEAAqE;YACrE,0EAA0E;YAC1E,WAAW;YACX,QAAQ,EAAE,EAAE;SACb,CAAC;IACJ,CAAC;IAED,6BAA6B;IAE7B,IAAI,EAAE,QAAQ,EAAE,GAAG,oBAAoB,EAAE,GAAG,QAAoB,CAAC;IAEjE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,0CAA0C;QAC1C,+CAA+C;QAC/C,QAAQ,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,oBAAoB;QAC3B,GAAG;QACH,QAAQ;KACT,CAAC;AAAA,CACH;AAYD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY;AAC1B,sBAAsB;AACtB,QAAqB;AACrB,uBAAuB;AACvB,OAAoB;AACpB,gEAAgE;AAChE,GAAY,EACZ;IACA,OAAO,aAAa,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC;AAAA,CAClD"}
@@ -0,0 +1,13 @@
1
+ import type { AppOptions, AppRoot } from '../types';
2
+ /**
3
+ * Creates a new React app. The signature is the same as in React 18+.
4
+ * @example
5
+ * const { unmount } = createRoot(
6
+ * document.getElementById('root'),
7
+ * <App/>
8
+ * );
9
+ * // ...
10
+ * unmount();
11
+ */
12
+ export declare function createRoot(root: HTMLElement, options?: AppOptions): AppRoot;
13
+ //# sourceMappingURL=createRoot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRoot.d.ts","sourceRoot":"","sources":["../../src/core/createRoot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG9D;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAoB3E"}
@@ -0,0 +1,33 @@
1
+ import { mount } from './reconciliation/mount';
2
+ /**
3
+ * Creates a new React app. The signature is the same as in React 18+.
4
+ * @example
5
+ * const { unmount } = createRoot(
6
+ * document.getElementById('root'),
7
+ * <App/>
8
+ * );
9
+ * // ...
10
+ * unmount();
11
+ */
12
+ export function createRoot(root, options) {
13
+ let created = false;
14
+ let unmount = null;
15
+ const api = {
16
+ render: (element) => {
17
+ if (created) {
18
+ api.unmount();
19
+ }
20
+ unmount = mount(root, element, options ?? DEFAULT_OPTIONS);
21
+ created = true;
22
+ },
23
+ unmount: () => {
24
+ unmount?.();
25
+ created = false;
26
+ },
27
+ };
28
+ return api;
29
+ }
30
+ const DEFAULT_OPTIONS = {
31
+ testMode: false,
32
+ };
33
+ //# sourceMappingURL=createRoot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRoot.js","sourceRoot":"","sources":["../../src/core/createRoot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,IAAiB,EAAE,OAAoB,EAAW;IAC3E,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,OAAO,GAAwB,IAAI,CAAC;IAExC,MAAM,GAAG,GAAY;QACnB,MAAM,EAAE,CAAC,OAAoB,EAAQ,EAAE,CAAC;YACtC,IAAI,OAAO,EAAE,CAAC;gBACZ,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,CAAC;YAED,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,IAAI,eAAe,CAAC,CAAC;YAC3D,OAAO,GAAG,IAAI,CAAC;QAAA,CAChB;QACD,OAAO,EAAE,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,EAAE,CAAC;YACZ,OAAO,GAAG,KAAK,CAAC;QAAA,CACjB;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AAAA,CACZ;AAED,MAAM,eAAe,GAAe;IAClC,QAAQ,EAAE,KAAK;CAChB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type FiberNode } from '../types';
2
+ /**
3
+ * Converts any possible JSX.Element to a FiberNode, that is used by the engine
4
+ * everywhere. We don't use JSX.Elements outside of this function.
5
+ * <div/> -> FiberNode.
6
+ */
7
+ export declare const jsxElementToFiberNode: (jsxElement: import("../index.js").JsxElement, parent: FiberNode, unwrapComponents: boolean) => FiberNode;
8
+ //# sourceMappingURL=reactNodeToFiberNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactNodeToFiberNode.d.ts","sourceRoot":"","sources":["../../src/core/reactNodeToFiberNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EASf,MAAM,UAAU,CAAC;AASlB;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,4GA+HjC,CAAC"}
@@ -0,0 +1,132 @@
1
+ import { runComponent } from './components';
2
+ import { createFiberNode, FRAGMENT_TAG, toFiberChildren, } from './reconciliation/fibers';
3
+ import { isContextProvider } from './reconciliation/typeGuards';
4
+ /**
5
+ * Converts any possible JSX.Element to a FiberNode, that is used by the engine
6
+ * everywhere. We don't use JSX.Elements outside of this function.
7
+ * <div/> -> FiberNode.
8
+ */
9
+ export const jsxElementToFiberNode = (jsxElement,
10
+ /** Every fiber node except the root must have a parent fiber node. */
11
+ parent,
12
+ /** Pass `true` on the 1st render for the given node to run internal
13
+ * components recursively. By default it doesn't run any components. */
14
+ unwrapComponents) => {
15
+ // []-based version of a fragment. Not a <Fragment/>.
16
+ if (Array.isArray(jsxElement)) {
17
+ jsxElement = {
18
+ type: FRAGMENT_TAG,
19
+ props: {},
20
+ key: null,
21
+ children: jsxElement,
22
+ };
23
+ }
24
+ // Any null-like value, i.e. it doesn't render a tag or a text node.
25
+ if (jsxElement === null || jsxElement === undefined || jsxElement === false) {
26
+ const nullFiber = {
27
+ ...createFiberNode(parent),
28
+ type: 'null',
29
+ parent,
30
+ props: null,
31
+ };
32
+ return nullFiber;
33
+ }
34
+ // A text node (string, number or boolean).
35
+ if (typeof jsxElement !== 'object') {
36
+ const textFiber = {
37
+ ...createFiberNode(parent),
38
+ type: 'text',
39
+ parent,
40
+ props: { text: String(jsxElement) },
41
+ };
42
+ return textFiber;
43
+ }
44
+ const { key = null } = jsxElement;
45
+ const { ref = null, ...props } = jsxElement.props;
46
+ // createPortal(JSX.Element, domNode, key)
47
+ if (jsxElement.type instanceof HTMLElement) {
48
+ const portalFiber = {
49
+ ...createFiberNode(parent),
50
+ type: 'tag',
51
+ tag: 'x-portal',
52
+ key,
53
+ role: 'portal',
54
+ data: jsxElement.type,
55
+ };
56
+ portalFiber.children = jsxElement.children.map((n) => jsxElementToFiberNode(n, portalFiber, unwrapComponents));
57
+ return portalFiber;
58
+ }
59
+ // <ctx.Provider value=?/>
60
+ if (isContextProvider(jsxElement.type)) {
61
+ validateContextProviderProps(props);
62
+ const contextFiber = {
63
+ ...createFiberNode(parent),
64
+ type: 'fragment',
65
+ key,
66
+ role: 'context',
67
+ props,
68
+ data: { ctx: jsxElement.type.__ctx, consumers: new Set() },
69
+ };
70
+ contextFiber.children = jsxElement.children.map((n) => jsxElementToFiberNode(n, contextFiber, unwrapComponents));
71
+ return contextFiber;
72
+ }
73
+ // [], </> or <Fragment/>.
74
+ if (jsxElement.type === FRAGMENT_TAG) {
75
+ const fragmentFiber = {
76
+ ...createFiberNode(parent),
77
+ type: 'fragment',
78
+ key,
79
+ };
80
+ fragmentFiber.children = jsxElement.children.map((n) => jsxElementToFiberNode(n, fragmentFiber, unwrapComponents));
81
+ return fragmentFiber;
82
+ }
83
+ // A component node (<Message/>):
84
+ if (typeof jsxElement.type === 'function') {
85
+ const fiber = {
86
+ ...createFiberNode(parent),
87
+ type: 'component',
88
+ component: jsxElement.type,
89
+ key,
90
+ props,
91
+ data: { hooks: null },
92
+ };
93
+ if (unwrapComponents) {
94
+ const content = runComponent(fiber, null);
95
+ const child = jsxElementToFiberNode(content, fiber, unwrapComponents);
96
+ fiber.children = toFiberChildren(child);
97
+ }
98
+ return fiber;
99
+ }
100
+ if (typeof jsxElement.type === 'string') {
101
+ validateRef(ref);
102
+ const tagFiber = {
103
+ ...createFiberNode(parent),
104
+ type: 'tag',
105
+ key,
106
+ props,
107
+ tag: jsxElement.type,
108
+ ref,
109
+ data: { events: {} },
110
+ };
111
+ tagFiber.children = jsxElement.children
112
+ .map((n) => jsxElementToFiberNode(n, tagFiber, unwrapComponents))
113
+ .flat();
114
+ return tagFiber;
115
+ }
116
+ throw new Error(`Unknown format of JSX.Element (${jsxElement.type})`);
117
+ };
118
+ function validateContextProviderProps(props) {
119
+ if (!('value' in props)) {
120
+ throw new Error(`Context provider value is not provided`);
121
+ }
122
+ }
123
+ function validateRef(src) {
124
+ if (src === null ||
125
+ // Unfortunately, there's no way to validate the function.
126
+ typeof src === 'function' ||
127
+ (!!src && typeof src === 'object' && 'current' in src)) {
128
+ return;
129
+ }
130
+ throw new Error(`Unsupported format of a ref or a ref handler`);
131
+ }
132
+ //# sourceMappingURL=reactNodeToFiberNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactNodeToFiberNode.js","sourceRoot":"","sources":["../../src/core/reactNodeToFiberNode.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,eAAe,EACf,YAAY,EACZ,eAAe,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,UAAuB;AACvB,sEAAsE;AACtE,MAAiB;AACjB;uEACuE;AACvE,gBAAyB,EACd,EAAE,CAAC;IACd,qDAAqD;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,UAAU,GAAG;YACX,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,EAAE;YACT,GAAG,EAAE,IAAI;YACT,QAAQ,EAAE,UAAU;SACrB,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;QAC5E,MAAM,SAAS,GAAkB;YAC/B,GAAG,eAAe,CAAC,MAAM,CAAC;YAC1B,IAAI,EAAE,MAAM;YACZ,MAAM;YACN,KAAK,EAAE,IAAI;SACZ,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,2CAA2C;IAC3C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,SAAS,GAAkB;YAC/B,GAAG,eAAe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AI,EAAE,KAAK;YACX,GAAG;YACH,KAAK;YACL,GAAG,EAAE,UAAU,CAAC,IAAI;YACpB,GAAG;YACH,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;SACrB,CAAC;QACF,QAAQ,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ;aACpC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;aAChE,IAAI,EAAE,CAAC;QACV,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,kCAAkC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;AAAA,CACvE,CAAC;AAEF,SAAS,4BAA4B,CACnC,KAAmB,EACkB;IACrC,IAAI,CAAC,CAAC,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;AAAA,CACF;AAED,SAAS,WAAW,CAClB,GAAY,EAC+C;IAC3D,IACE,GAAG,KAAK,IAAI;QACZ,0DAA0D;QAC1D,OAAO,GAAG,KAAK,UAAU;QACzB,CAAC,CAAC,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,SAAS,IAAI,GAAG,CAAC,EACtD,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;AAAA,CACjE"}
@@ -0,0 +1,5 @@
1
+ import type { App, FiberNode } from '../../types';
2
+ export declare const getAppByFiber: (fiber: FiberNode) => App;
3
+ export declare const registerApp: (fn: (id: number) => App) => App;
4
+ export declare const removeApp: (id: number) => void;
5
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/core/reconciliation/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKzD,eAAO,MAAM,aAAa,2BAEzB,CAAC;AAEF,eAAO,MAAM,WAAW,kCAGvB,CAAC;AAEF,eAAO,MAAM,SAAS,sBASrB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { nullthrows } from '../../utils';
2
+ const apps = [];
3
+ export const getAppByFiber = (fiber) => {
4
+ return nullthrows(apps[fiber.appId]);
5
+ };
6
+ export const registerApp = (fn) => {
7
+ apps.push(fn(apps.length));
8
+ return apps.at(-1);
9
+ };
10
+ export const removeApp = (id) => {
11
+ const app = apps[id];
12
+ if (app) {
13
+ apps[id] = null;
14
+ // Help with garbage collection.
15
+ app.root = app.tempContext = null;
16
+ app.effects = { normal: [] };
17
+ app.invalidatedComponents = { size: 0 };
18
+ }
19
+ };
20
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/core/reconciliation/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,MAAM,IAAI,GAAsB,EAAE,CAAC;AAEnC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAgB,EAAO,EAAE,CAAC;IACtD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAAA,CACtC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAuB,EAAO,EAAE,CAAC;IAC3D,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;AAAA,CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAQ,EAAE,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAA4B,CAAC;IAChD,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;QAChB,gCAAgC;QAChC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;QAClC,GAAG,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QAC7B,GAAG,CAAC,qBAAqB,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAC1C,CAAC;AAAA,CACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { App } from '../../types';
2
+ import type { Action } from '../../types/actions';
3
+ /**
4
+ * Moves the app into the "commit" state and applies the given actions one by
5
+ * one.
6
+ */
7
+ export declare const applyActions: (app: App, actions: Action[]) => void;
8
+ //# sourceMappingURL=applyActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyActions.d.ts","sourceRoot":"","sources":["../../../src/core/reconciliation/applyActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,YAAY,uCAKxB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { applyAction } from '../actions/applyAction';
2
+ /**
3
+ * Moves the app into the "commit" state and applies the given actions one by
4
+ * one.
5
+ */
6
+ export const applyActions = (app, actions) => {
7
+ app.state = 'commit';
8
+ for (const action of actions) {
9
+ applyAction(action);
10
+ }
11
+ };
12
+ //# sourceMappingURL=applyActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyActions.js","sourceRoot":"","sources":["../../../src/core/reconciliation/applyActions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAQ,EAAE,OAAiB,EAAQ,EAAE,CAAC;IACjE,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC;IACrB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,WAAW,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;AAAA,CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { App } from '../../../types';
2
+ import type { Action } from '../../../types/actions';
3
+ /**
4
+ * Goes through the list of invalidated components, runs them, finds the diff,
5
+ * and returns the list of actions to convert the previous fiber tree to the new
6
+ * one.
7
+ */
8
+ export declare const collectActionsFromApp: (app: App) => Action[];
9
+ //# sourceMappingURL=fromApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromApp.d.ts","sourceRoot":"","sources":["../../../../src/core/reconciliation/collect/fromApp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAIzD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,wBAoCjC,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { collectActionsFromComponent } from './fromComponent';
2
+ import { getFiberLevel } from '../fibers';
3
+ /**
4
+ * Goes through the list of invalidated components, runs them, finds the diff,
5
+ * and returns the list of actions to convert the previous fiber tree to the new
6
+ * one.
7
+ */
8
+ export const collectActionsFromApp = (app) => {
9
+ const actions = [];
10
+ // Sort invalidated components by their level in the fiber tree to run the
11
+ // parent components before their children components.
12
+ const sorted = [...app.invalidatedComponents]
13
+ .map((f) => ({ fiber: f, level: getFiberLevel(f) }))
14
+ .sort((a, b) => a.level - b.level);
15
+ for (const { fiber } of sorted) {
16
+ // Redo the check because some components can be indirectly removed in between.
17
+ if (app.invalidatedComponents.has(fiber)) {
18
+ actions.push(...collectActionsFromComponent(app, fiber, null));
19
+ }
20
+ }
21
+ if (app.invalidatedComponents.size > 0) {
22
+ // The only reason why a component might be kept in `invalidatedComponents`
23
+ // after the first run is that this component was "trapped" inside a
24
+ // non-invalidated component. We don't traverse through the whole fiber
25
+ // tree, so we need to run the rest of the queue again.
26
+ if (app.testMode) {
27
+ // A sanity check
28
+ for (const fiber of app.invalidatedComponents) {
29
+ if (fiber.type !== 'component' ||
30
+ !fiber.data.hooks?.some((h) => h.type === 'context')) {
31
+ throw new Error(`Fiber node is stuck`);
32
+ }
33
+ }
34
+ }
35
+ actions.push(...collectActionsFromApp(app));
36
+ }
37
+ return actions;
38
+ };
39
+ //# sourceMappingURL=fromApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromApp.js","sourceRoot":"","sources":["../../../../src/core/reconciliation/collect/fromApp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAQ,EAAY,EAAE,CAAC;IAC3D,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,0EAA0E;IAC1E,sDAAsD;IACtD,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,qBAAqB,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACnD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACrC,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,MAAM,EAAE,CAAC;QAC/B,+EAA+E;QAC/E,IAAI,GAAG,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC,GAAG,2BAA2B,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,IAAI,GAAG,CAAC,qBAAqB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QACvC,2EAA2E;QAC3E,oEAAoE;QACpE,uEAAuE;QACvE,uDAAuD;QACvD,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,iBAAiB;YACjB,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,qBAAqB,EAAE,CAAC;gBAC9C,IACE,KAAK,CAAC,IAAI,KAAK,WAAW;oBAC1B,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,EACpD,CAAC;oBACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;gBACzC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CAChB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { FiberNode } from '../../../types';
2
+ import type { Action } from '../../../types/actions';
3
+ /**
4
+ * Returns a list of actions needed to convert `before` to `after`, where
5
+ * `before` is a list of children from the last render, and `after` is the list
6
+ * of children of the same node from the current render.
7
+ */
8
+ export declare const collectActionsFromChildrenPair: (fiber: FiberNode, after: FiberNode[]) => Action[];
9
+ //# sourceMappingURL=fromChildrenPair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromChildrenPair.d.ts","sourceRoot":"","sources":["../../../../src/core/reconciliation/collect/fromChildrenPair.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,SAAS,EAGV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AASzD;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,oDA8D1C,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { getAppByFiber } from '../app';
2
+ import { collectActionsFromFiberPair } from './fromFiberPair';
3
+ import { runFiberComponents } from '../runFiberComponents';
4
+ import { collectActionsFromNewFiber } from '../../../core/reconciliation/collect/fromNewFiber';
5
+ import { createFiberNode, FAKE_CONTAINER_TAG } from '../fibers';
6
+ import { areFiberNodesEq } from '../compare/areFiberNodesEq';
7
+ import { isContainerFiber } from '../typeGuards';
8
+ /**
9
+ * Returns a list of actions needed to convert `before` to `after`, where
10
+ * `before` is a list of children from the last render, and `after` is the list
11
+ * of children of the same node from the current render.
12
+ */
13
+ export const collectActionsFromChildrenPair = (
14
+ /** The parent node for both `before` and `after`. */
15
+ fiber,
16
+ /** New children set (some component's direct or indirect update) */
17
+ after) => {
18
+ const app = getAppByFiber(fiber);
19
+ const left = getChildrenMap(fiber.children);
20
+ const right = getChildrenMap(after);
21
+ /** A flag indicating there was at least one change that requires calling the
22
+ * Relayout action. Such as removing, replacing, adding or repositioning a
23
+ * fiber node. */
24
+ let relayoutNeeded = false;
25
+ const actions = [];
26
+ // Search for nodes that were in the past render but don't exist in the
27
+ // current render. Then remove them.
28
+ for (const [key, l] of left.entries()) {
29
+ if (!right.has(key)) {
30
+ // Don't run components from the removing node even if they were invalidated
31
+ uninvalidateFiberSubTree(app, l.fiber);
32
+ actions.push({ type: 'Remove', fiber: l.fiber });
33
+ relayoutNeeded = true; // to handle the compact mode of the container.
34
+ }
35
+ }
36
+ for (const [key, r] of right.entries()) {
37
+ const l = left.get(key);
38
+ if (!l || !areFiberNodesEq(l.fiber, r.fiber)) {
39
+ // 1. There was no node with this key before. Create a new one.
40
+ // 2. There was one, but it was very different. Replace it.
41
+ relayoutNeeded = true;
42
+ actions.push(...createFiberActions(app, r.fiber));
43
+ if (l) {
44
+ // Don't run components from the removing node even if they were invalidated
45
+ uninvalidateFiberSubTree(app, l.fiber);
46
+ actions.push({ type: 'Replace', fiber: l.fiber, newFiber: r.fiber });
47
+ }
48
+ continue;
49
+ }
50
+ else {
51
+ // No need to recreate the existing node, but we might need to update it
52
+ // or one of its children.
53
+ actions.push(...collectActionsFromFiberPair(app, l.fiber, r.fiber));
54
+ }
55
+ // Handle the case when the node changed its position. It's possible for
56
+ // nodes with manual keys.
57
+ relayoutNeeded ||= l.order !== r.order;
58
+ }
59
+ if (relayoutNeeded) {
60
+ // It'll:
61
+ // - update node positions when needed
62
+ // - move new nodes from a temporary container to the existing l-container
63
+ // - wrap or unwrap !--brackets for the fiber's container
64
+ actions.push({ type: 'Relayout', fiber, before: left, after: right });
65
+ }
66
+ return actions;
67
+ };
68
+ /**
69
+ * Recursively search for components marked for invalidation. Then remove them
70
+ * from the updating queue (invalidatedComponents). Should be called on
71
+ * fiber-node deletion.
72
+ */
73
+ const uninvalidateFiberSubTree = (app, fiberNode) => {
74
+ if (fiberNode.type === 'component') {
75
+ app.invalidatedComponents.delete(fiberNode);
76
+ }
77
+ for (const f of fiberNode.children) {
78
+ uninvalidateFiberSubTree(app, f);
79
+ }
80
+ };
81
+ /**
82
+ * Returns a list of actions to create from scratch the DOM nodes of the given
83
+ * fiber node.
84
+ */
85
+ const createFiberActions = (app, fiber) => {
86
+ const fakeParent = createFakeFiberContainer(fiber.parent);
87
+ fakeParent.parent = fiber.parent;
88
+ // Wrap the given node with a fake <x-container/> node to force `applyActions`
89
+ // to create new DOM nodes in the fake DOM node, not in the mounted container.
90
+ // The Relayout action will move them into the real node and then reassign the
91
+ // parent.
92
+ fiber.parent = fakeParent;
93
+ if (isContainerFiber(fiber)) {
94
+ // Since all inner components are also new we need to run them.
95
+ runFiberComponents(app, fiber);
96
+ }
97
+ // Reuse the same tooling we use for mounting the app.
98
+ return collectActionsFromNewFiber(fiber);
99
+ };
100
+ /**
101
+ * Create an <x-container/> DOM node that is not mounted to the real DOM tree.
102
+ * It will be used to store new DOM nodes until the Relayout action repositions
103
+ * them into their real parent.
104
+ */
105
+ const createFakeFiberContainer = (fiber) => ({
106
+ ...createFiberNode(fiber),
107
+ type: 'tag',
108
+ element: document.createElement('x-container'),
109
+ tag: FAKE_CONTAINER_TAG,
110
+ data: { events: {} },
111
+ props: {},
112
+ });
113
+ /**
114
+ * Converts FiberNode[] to Map<key, { order, fiber }>.
115
+ */
116
+ const getChildrenMap = (fibers) => {
117
+ let unnamedPos = -1;
118
+ return new Map(fibers.map((fiber, idx) => {
119
+ if (fiber.key == null)
120
+ ++unnamedPos;
121
+ return [
122
+ fiber.key ?? `auto:${unnamedPos}`,
123
+ { order: idx, fiber },
124
+ ];
125
+ }));
126
+ };
127
+ //# sourceMappingURL=fromChildrenPair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromChildrenPair.js","sourceRoot":"","sources":["../../../../src/core/reconciliation/collect/fromChildrenPair.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uDAAuD,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG;AAC5C,qDAAqD;AACrD,KAAgB;AAChB,oEAAoE;AACpE,KAAkB,EACR,EAAE,CAAC;IACb,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACpC;;qBAEiB;IACjB,IAAI,cAAc,GAAG,KAAK,CAAC;I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5B,+DAA+D;QAC/D,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,sDAAsD;IACtD,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;AAAA,CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,wBAAwB,GAAG,CAAC,KAAgB,EAAgB,EAAE,CAAC,CAAC;IACpE,GAAG,eAAe,CAAC,KAAK,CAAC;IACzB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC;IAC9C,GAAG,EAAE,kBAAkB;IACvB,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IACpB,KAAK,EAAE,EAAE;CACV,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,MAAmB,EAAY,EAAE,CAAC;IACxD,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;IACpB,OAAO,IAAI,GAAG,CACZ,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAwB,EAAE,CAAC;QAC/C,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI;YAAE,EAAE,UAAU,CAAC;QACpC,OAAO;YACL,KAAK,CAAC,GAAG,IAAI,QAAQ,UAAU,EAAE;YACjC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE;SACb,CAAC;IAAA,CACZ,CAAC,CACH,CAAC;AAAA,CACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { App, FiberNode } from '../../../types';
2
+ import type { Action } from '../../../types/actions';
3
+ /**
4
+ * 1. Runs a component
5
+ * 2. Collects and returns a list of actions needed to actualize it
6
+ *
7
+ * Throws when the given component is not invalidated.
8
+ */
9
+ export declare const collectActionsFromComponent: (app: App, fiber: FiberNode, updated: FiberNode | null) => Action[];
10
+ //# sourceMappingURL=fromComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromComponent.d.ts","sourceRoot":"","sources":["../../../../src/core/reconciliation/collect/fromComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAMzD;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,qEAkBvC,CAAC"}