@tanstack/redact 0.0.21 → 0.1.1

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 (254) hide show
  1. package/dist/core/attributes.js +2 -1
  2. package/dist/core/attributes.js.map +2 -2
  3. package/dist/core/browser.d.ts +9 -0
  4. package/dist/core/browser.js +35 -0
  5. package/dist/core/browser.js.map +7 -0
  6. package/dist/core/index.d.ts +2 -2
  7. package/dist/core/index.js +3 -3
  8. package/dist/core/internal.d.ts +31 -8
  9. package/dist/core/internal.js +3 -1
  10. package/dist/core/internal.js.map +2 -2
  11. package/dist/core/resource-hints.d.ts +7 -0
  12. package/dist/core/resource-hints.js +19 -0
  13. package/dist/core/resource-hints.js.map +7 -0
  14. package/dist/core/types.js +1 -1
  15. package/dist/dom/_all.d.ts +11 -16
  16. package/dist/dom/_all.js +9 -20
  17. package/dist/dom/_all.js.map +2 -2
  18. package/dist/dom/client.d.ts +4 -4
  19. package/dist/dom/client.js +4 -4
  20. package/dist/dom/commit.d.ts +23 -0
  21. package/dist/dom/commit.js +191 -0
  22. package/dist/dom/commit.js.map +7 -0
  23. package/dist/dom/dispatcher.d.ts +4 -22
  24. package/dist/dom/dispatcher.js +184 -126
  25. package/dist/dom/dispatcher.js.map +3 -3
  26. package/dist/dom/dom.d.ts +2 -0
  27. package/dist/dom/dom.js +72 -52
  28. package/dist/dom/dom.js.map +2 -2
  29. package/dist/dom/error-info.d.ts +2 -0
  30. package/dist/dom/error-info.js +16 -0
  31. package/dist/dom/error-info.js.map +7 -0
  32. package/dist/dom/event-replay.js +1 -1
  33. package/dist/dom/features/activity/full.d.ts +1 -0
  34. package/dist/dom/features/activity/full.js +162 -0
  35. package/dist/dom/features/activity/full.js.map +7 -0
  36. package/dist/dom/features/activity/index.d.ts +1 -0
  37. package/dist/dom/features/activity/index.js +3 -0
  38. package/dist/dom/features/activity/index.js.map +7 -0
  39. package/dist/dom/features/activity/stub.d.ts +1 -0
  40. package/dist/dom/features/activity/stub.js +12 -0
  41. package/dist/dom/features/activity/stub.js.map +7 -0
  42. package/dist/dom/features/class/full.js +87 -27
  43. package/dist/dom/features/class/full.js.map +2 -2
  44. package/dist/dom/features/class/index.d.ts +1 -1
  45. package/dist/dom/features/class/index.js +2 -2
  46. package/dist/dom/features/class/stub.js +3 -3
  47. package/dist/dom/features/context/full.d.ts +4 -1
  48. package/dist/dom/features/context/full.js +72 -15
  49. package/dist/dom/features/context/full.js.map +2 -2
  50. package/dist/dom/features/context/index.d.ts +1 -1
  51. package/dist/dom/features/context/index.js +2 -2
  52. package/dist/dom/features/context/stub.d.ts +4 -1
  53. package/dist/dom/features/context/stub.js +17 -8
  54. package/dist/dom/features/context/stub.js.map +2 -2
  55. package/dist/dom/features/forward-ref/full.js +12 -21
  56. package/dist/dom/features/forward-ref/full.js.map +2 -2
  57. package/dist/dom/features/forward-ref/index.d.ts +1 -1
  58. package/dist/dom/features/forward-ref/index.js +2 -2
  59. package/dist/dom/features/forward-ref/stub.js +4 -4
  60. package/dist/dom/features/fragment-refs/index.d.ts +1 -0
  61. package/dist/dom/features/fragment-refs/index.js +8 -0
  62. package/dist/dom/features/fragment-refs/index.js.map +7 -0
  63. package/dist/dom/features/fragment-refs/stub.d.ts +3 -0
  64. package/dist/dom/features/fragment-refs/stub.js +14 -0
  65. package/dist/dom/features/fragment-refs/stub.js.map +7 -0
  66. package/dist/dom/features/hydration/full.d.ts +11 -6
  67. package/dist/dom/features/hydration/full.js +76 -77
  68. package/dist/dom/features/hydration/full.js.map +2 -2
  69. package/dist/dom/features/hydration/index.d.ts +1 -1
  70. package/dist/dom/features/hydration/index.js +2 -2
  71. package/dist/dom/features/hydration/stub.d.ts +7 -2
  72. package/dist/dom/features/hydration/stub.js +1 -1
  73. package/dist/dom/features/hydration/stub.js.map +1 -1
  74. package/dist/dom/features/index.d.ts +8 -7
  75. package/dist/dom/features/index.js +9 -8
  76. package/dist/dom/features/index.js.map +2 -2
  77. package/dist/dom/features/lazy/full.js +4 -4
  78. package/dist/dom/features/lazy/index.d.ts +1 -1
  79. package/dist/dom/features/lazy/index.js +2 -2
  80. package/dist/dom/features/lazy/stub.js +4 -4
  81. package/dist/dom/features/memo/full.js +8 -6
  82. package/dist/dom/features/memo/full.js.map +2 -2
  83. package/dist/dom/features/memo/index.d.ts +1 -1
  84. package/dist/dom/features/memo/index.js +2 -2
  85. package/dist/dom/features/memo/stub.js +4 -4
  86. package/dist/dom/features/portal/full.js +4 -4
  87. package/dist/dom/features/portal/index.d.ts +1 -1
  88. package/dist/dom/features/portal/index.js +2 -2
  89. package/dist/dom/features/portal/stub.js +4 -4
  90. package/dist/dom/features/suspense/full.js +197 -52
  91. package/dist/dom/features/suspense/full.js.map +2 -2
  92. package/dist/dom/features/suspense/index.d.ts +1 -1
  93. package/dist/dom/features/suspense/index.js +2 -2
  94. package/dist/dom/features/suspense/stub.js +4 -4
  95. package/dist/dom/features/view-transition/full.d.ts +6 -0
  96. package/dist/dom/features/view-transition/full.js +280 -0
  97. package/dist/dom/features/view-transition/full.js.map +7 -0
  98. package/dist/dom/features/view-transition/index.d.ts +1 -0
  99. package/dist/dom/features/view-transition/index.js +3 -0
  100. package/dist/dom/features/view-transition/index.js.map +7 -0
  101. package/dist/dom/features/view-transition/resources.d.ts +11 -0
  102. package/dist/dom/features/view-transition/resources.js +108 -0
  103. package/dist/dom/features/view-transition/resources.js.map +7 -0
  104. package/dist/dom/features/view-transition/stub.d.ts +6 -0
  105. package/dist/dom/features/view-transition/stub.js +22 -0
  106. package/dist/dom/features/view-transition/stub.js.map +7 -0
  107. package/dist/dom/features/view-transition/visual.d.ts +14 -0
  108. package/dist/dom/features/view-transition/visual.js +356 -0
  109. package/dist/dom/features/view-transition/visual.js.map +7 -0
  110. package/dist/dom/fragment-instance.d.ts +40 -0
  111. package/dist/dom/fragment-instance.js +324 -0
  112. package/dist/dom/fragment-instance.js.map +7 -0
  113. package/dist/dom/index.d.ts +11 -11
  114. package/dist/dom/index.js +11 -18
  115. package/dist/dom/index.js.map +3 -3
  116. package/dist/dom/portal.d.ts +2 -2
  117. package/dist/dom/portal.js +2 -2
  118. package/dist/dom/portal.js.map +1 -1
  119. package/dist/dom/reconcile.d.ts +32 -3
  120. package/dist/dom/reconcile.js +689 -221
  121. package/dist/dom/reconcile.js.map +2 -2
  122. package/dist/dom/resource-hints.d.ts +6 -0
  123. package/dist/dom/resource-hints.js +115 -0
  124. package/dist/dom/resource-hints.js.map +7 -0
  125. package/dist/dom/resource-store.d.ts +13 -0
  126. package/dist/dom/resource-store.js +43 -0
  127. package/dist/dom/resource-store.js.map +7 -0
  128. package/dist/dom/resources.d.ts +1 -0
  129. package/dist/dom/resources.js +44 -0
  130. package/dist/dom/resources.js.map +7 -0
  131. package/dist/dom/retained-effects.d.ts +6 -0
  132. package/dist/dom/retained-effects.js +49 -0
  133. package/dist/dom/retained-effects.js.map +7 -0
  134. package/dist/dom/root-internal.d.ts +4 -4
  135. package/dist/dom/root-internal.js +2 -2
  136. package/dist/dom/root-internal.js.map +2 -2
  137. package/dist/dom/root.d.ts +5 -5
  138. package/dist/dom/root.js +11 -11
  139. package/dist/dom/root.js.map +2 -2
  140. package/dist/dom/test-utils.js +1 -1
  141. package/dist/react/activity.d.ts +7 -0
  142. package/dist/react/activity.js +8 -0
  143. package/dist/react/activity.js.map +7 -0
  144. package/dist/react/children.d.ts +1 -1
  145. package/dist/react/children.js +3 -3
  146. package/dist/react/children.js.map +1 -1
  147. package/dist/react/class.d.ts +1 -1
  148. package/dist/react/class.js +3 -3
  149. package/dist/react/class.js.map +1 -1
  150. package/dist/react/compiler-runtime.js +2 -2
  151. package/dist/react/context.d.ts +7 -2
  152. package/dist/react/context.js +3 -11
  153. package/dist/react/context.js.map +3 -3
  154. package/dist/react/element.d.ts +6 -3
  155. package/dist/react/element.js +7 -11
  156. package/dist/react/element.js.map +2 -2
  157. package/dist/react/hooks.d.ts +26 -7
  158. package/dist/react/hooks.js +13 -3
  159. package/dist/react/hooks.js.map +2 -2
  160. package/dist/react/index.d.ts +39 -24
  161. package/dist/react/index.js +39 -19
  162. package/dist/react/index.js.map +3 -3
  163. package/dist/react/jsx-runtime.d.ts +2 -2
  164. package/dist/react/jsx-runtime.js +3 -3
  165. package/dist/react/memo.d.ts +1 -1
  166. package/dist/react/memo.js +1 -1
  167. package/dist/react/portal.js +1 -1
  168. package/dist/react/shared-internals.d.ts +15 -5
  169. package/dist/react/shared-internals.js +2 -3
  170. package/dist/react/shared-internals.js.map +2 -2
  171. package/dist/react/suspense.js +1 -1
  172. package/dist/react/view-transition.d.ts +32 -0
  173. package/dist/react/view-transition.js +13 -0
  174. package/dist/react/view-transition.js.map +7 -0
  175. package/dist/scheduler/index.js +1 -1
  176. package/dist/server/bootstrap-script.d.ts +1 -23
  177. package/dist/server/bootstrap-script.js +7 -6
  178. package/dist/server/bootstrap-script.js.map +2 -2
  179. package/dist/server/dispatcher.d.ts +28 -6
  180. package/dist/server/dispatcher.js +33 -15
  181. package/dist/server/dispatcher.js.map +2 -2
  182. package/dist/server/escape.js +16 -15
  183. package/dist/server/escape.js.map +2 -2
  184. package/dist/server/index.d.ts +6 -6
  185. package/dist/server/index.js +7 -7
  186. package/dist/server/renderToString.d.ts +1 -1
  187. package/dist/server/renderToString.js +12 -8
  188. package/dist/server/renderToString.js.map +2 -2
  189. package/dist/server/resource-hints.d.ts +22 -0
  190. package/dist/server/resource-hints.js +148 -0
  191. package/dist/server/resource-hints.js.map +7 -0
  192. package/dist/server/stream.d.ts +15 -2
  193. package/dist/server/stream.js +155 -63
  194. package/dist/server/stream.js.map +2 -2
  195. package/dist/server/walk.d.ts +15 -2
  196. package/dist/server/walk.js +150 -110
  197. package/dist/server/walk.js.map +2 -2
  198. package/dist/vite/index.d.ts +6 -0
  199. package/dist/vite/index.js +22 -6
  200. package/dist/vite/index.js.map +2 -2
  201. package/package.json +1 -1
  202. package/src/core/attributes.ts +1 -0
  203. package/src/core/browser.ts +33 -0
  204. package/src/core/internal.ts +24 -6
  205. package/src/core/resource-hints.ts +36 -0
  206. package/src/dom/_all.ts +1 -7
  207. package/src/dom/commit.ts +186 -0
  208. package/src/dom/dispatcher.ts +190 -134
  209. package/src/dom/dom.ts +70 -54
  210. package/src/dom/error-info.ts +15 -0
  211. package/src/dom/features/activity/full.ts +166 -0
  212. package/src/dom/features/activity/index.ts +1 -0
  213. package/src/dom/features/activity/stub.ts +14 -0
  214. package/src/dom/features/class/full.ts +72 -28
  215. package/src/dom/features/context/full.ts +70 -13
  216. package/src/dom/features/context/stub.ts +10 -5
  217. package/src/dom/features/forward-ref/full.ts +9 -19
  218. package/src/dom/features/fragment-refs/index.ts +1 -0
  219. package/src/dom/features/fragment-refs/stub.ts +3 -0
  220. package/src/dom/features/hydration/full.ts +84 -85
  221. package/src/dom/features/hydration/stub.ts +1 -1
  222. package/src/dom/features/index.ts +1 -0
  223. package/src/dom/features/memo/full.ts +4 -3
  224. package/src/dom/features/suspense/full.ts +192 -55
  225. package/src/dom/features/view-transition/full.ts +288 -0
  226. package/src/dom/features/view-transition/index.ts +1 -0
  227. package/src/dom/features/view-transition/resources.ts +107 -0
  228. package/src/dom/features/view-transition/stub.ts +7 -0
  229. package/src/dom/features/view-transition/visual.ts +406 -0
  230. package/src/dom/fragment-instance.ts +337 -0
  231. package/src/dom/index.ts +6 -7
  232. package/src/dom/portal.ts +1 -1
  233. package/src/dom/reconcile.ts +695 -242
  234. package/src/dom/resource-hints.ts +115 -0
  235. package/src/dom/resource-store.ts +52 -0
  236. package/src/dom/resources.ts +39 -0
  237. package/src/dom/retained-effects.ts +38 -0
  238. package/src/dom/root-internal.ts +4 -4
  239. package/src/dom/root.ts +12 -14
  240. package/src/react/activity.ts +10 -0
  241. package/src/react/context.ts +4 -11
  242. package/src/react/element.ts +11 -12
  243. package/src/react/hooks.ts +12 -3
  244. package/src/react/index.ts +18 -0
  245. package/src/react/shared-internals.ts +3 -3
  246. package/src/react/view-transition.ts +41 -0
  247. package/src/server/bootstrap-script.ts +36 -5
  248. package/src/server/dispatcher.ts +35 -13
  249. package/src/server/escape.ts +15 -12
  250. package/src/server/renderToString.ts +7 -5
  251. package/src/server/resource-hints.ts +165 -0
  252. package/src/server/stream.ts +154 -62
  253. package/src/server/walk.ts +79 -26
  254. package/src/vite/index.ts +30 -13
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/dom/resource-store.ts"],
4
+ "sourcesContent": ["import type { ResourceHintOptions } from '../core/resource-hints'\n\ninterface Resources {\n // Connection and preload selectors are disjoint, so one map deduplicates both.\n preloads: Map<string, ResourceHintOptions>\n instances: Map<string, Element>\n}\n\nexport type ResourceRoot = Document | DocumentFragment\n\nconst roots = /*#__PURE__*/ new WeakMap<ResourceRoot, Resources>()\n// Existing document links can satisfy a shadow declaration. Links created by\n// the resource system belong to their original root instead.\nexport const createdStylesheets = /*#__PURE__*/ new WeakSet<Element>()\n\nexport function resourceAttribute(name: string, value: string): string {\n return `[${name}=\"${value.replace(/[\\n\"\\\\]/g, char => '\\\\' + char.charCodeAt(0).toString(16) + ' ')}\"]`\n}\n\nexport function resourceSelector(href: string, as: string): string {\n return as === 'style'\n ? 'link[rel=\"stylesheet\"]' + resourceAttribute('href', href)\n : 'script[async]' + resourceAttribute('src', href)\n}\n\nexport function getResources(root: ResourceRoot): Resources {\n let resources = roots.get(root)\n if (!resources) roots.set(root, resources = { preloads: new Map(), instances: new Map() })\n return resources\n}\n\nexport function adoptResourceProps(props: any, prior: ResourceHintOptions | undefined, script: boolean): void {\n if (prior) for (const name of ['crossOrigin', 'referrerPolicy', script ? 'integrity' : 'title']) {\n if (props[name] == null && prior[name] != null) props[name] = prior[name]\n }\n}\n\nexport function insertResource(node: Element, precedence?: string, root: ResourceRoot = node.ownerDocument): void {\n const container = root.nodeType === 9 ? (root as Document).head : root\n if (precedence != null) {\n if (node.localName === 'link') createdStylesheets.add(node)\n let previous: Element | undefined\n let matched = false\n for (const sibling of root.querySelectorAll('link[rel=\"stylesheet\"][data-precedence],style[data-precedence]')) {\n if (sibling.getAttribute('data-precedence') === precedence) matched = true\n else if (matched) break\n previous = sibling\n }\n if (previous) previous.parentNode!.insertBefore(node, previous.nextSibling)\n else container.insertBefore(node, container.firstChild)\n } else container.appendChild(node)\n}\n"],
5
+ "mappings": ";AAUA,IAAM,QAAsB,oBAAI,QAAiC;AAG1D,IAAM,qBAAmC,oBAAI,QAAiB;AAE9D,SAAS,kBAAkB,MAAc,OAAuB;AACrE,SAAO,IAAI,IAAI,KAAK,MAAM,QAAQ,YAAY,UAAQ,OAAO,KAAK,WAAW,CAAC,EAAE,SAAS,EAAE,IAAI,GAAG,CAAC;AACrG;AAEO,SAAS,iBAAiB,MAAc,IAAoB;AACjE,SAAO,OAAO,UACV,2BAA2B,kBAAkB,QAAQ,IAAI,IACzD,kBAAkB,kBAAkB,OAAO,IAAI;AACrD;AAEO,SAAS,aAAa,MAA+B;AAC1D,MAAI,YAAY,MAAM,IAAI,IAAI;AAC9B,MAAI,CAAC,UAAW,OAAM,IAAI,MAAM,YAAY,EAAE,UAAU,oBAAI,IAAI,GAAG,WAAW,oBAAI,IAAI,EAAE,CAAC;AACzF,SAAO;AACT;AAEO,SAAS,mBAAmB,OAAY,OAAwC,QAAuB;AAC5G,MAAI,MAAO,YAAW,QAAQ,CAAC,eAAe,kBAAkB,SAAS,cAAc,OAAO,GAAG;AAC/F,QAAI,MAAM,IAAI,KAAK,QAAQ,MAAM,IAAI,KAAK,KAAM,OAAM,IAAI,IAAI,MAAM,IAAI;AAAA,EAC1E;AACF;AAEO,SAAS,eAAe,MAAe,YAAqB,OAAqB,KAAK,eAAqB;AAChH,QAAM,YAAY,KAAK,aAAa,IAAK,KAAkB,OAAO;AAClE,MAAI,cAAc,MAAM;AACtB,QAAI,KAAK,cAAc,OAAQ,oBAAmB,IAAI,IAAI;AAC1D,QAAI;AACJ,QAAI,UAAU;AACd,eAAW,WAAW,KAAK,iBAAiB,gEAAgE,GAAG;AAC7G,UAAI,QAAQ,aAAa,iBAAiB,MAAM,WAAY,WAAU;AAAA,eAC7D,QAAS;AAClB,iBAAW;AAAA,IACb;AACA,QAAI,SAAU,UAAS,WAAY,aAAa,MAAM,SAAS,WAAW;AAAA,QACrE,WAAU,aAAa,MAAM,UAAU,UAAU;AAAA,EACxD,MAAO,WAAU,YAAY,IAAI;AACnC;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ export declare function acquireResource(type: string, props: any, container: Node): Element;
@@ -0,0 +1,44 @@
1
+ // src/dom/resources.ts
2
+ import { resourceURL } from "../core/resource-hints.js";
3
+ import { setProp } from "./dom.js";
4
+ import { adoptResourceProps, createdStylesheets, getResources, insertResource, resourceAttribute, resourceSelector } from "./resource-store.js";
5
+ function acquireResource(type, props, container) {
6
+ const script = type === "script";
7
+ const style = type === "style";
8
+ const ownerDocument = container.nodeType === 9 ? container : container.ownerDocument;
9
+ const tree = script ? ownerDocument : container.getRootNode();
10
+ const root = tree.nodeType === 9 || tree.nodeType === 11 ? tree : ownerDocument;
11
+ const href = script ? props.src : props.href;
12
+ const resources = getResources(root);
13
+ const key = resourceSelector(href, script ? "script" : "style");
14
+ let node = resources.instances.get(key);
15
+ if (node) return node;
16
+ const existing = !style && !script && root !== ownerDocument ? ownerDocument.querySelector(key) : null;
17
+ node = existing && !createdStylesheets.has(existing) && !existing._p ? existing : root.querySelector(style ? "style" + resourceAttribute("data-href~", href) : key) || void 0;
18
+ if (node) {
19
+ resources.instances.set(key, node);
20
+ return node;
21
+ }
22
+ const next = { ...props };
23
+ if (!script) {
24
+ next["data-precedence"] = props.precedence;
25
+ delete next.precedence;
26
+ if (style) {
27
+ next["data-href"] = props.href;
28
+ delete next.href;
29
+ }
30
+ }
31
+ if (!style) adoptResourceProps(next, getResources(ownerDocument).preloads.get(key), script);
32
+ node = ownerDocument.createElement(type);
33
+ for (const name in next) {
34
+ setProp(node, name, name === "href" || name === "src" ? resourceURL(next[name]) : next[name], void 0, false);
35
+ }
36
+ if (style && next.dangerouslySetInnerHTML == null && (typeof next.children === "string" || typeof next.children === "number" || typeof next.children === "bigint")) node.textContent = "" + next.children;
37
+ resources.instances.set(key, node);
38
+ insertResource(node, script ? void 0 : props.precedence, root);
39
+ return node;
40
+ }
41
+ export {
42
+ acquireResource
43
+ };
44
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/dom/resources.ts"],
4
+ "sourcesContent": ["import { resourceURL } from '../core/resource-hints'\nimport { setProp } from './dom'\nimport { adoptResourceProps, createdStylesheets, getResources, insertResource, resourceAttribute, resourceSelector, type ResourceRoot } from './resource-store'\n\n// Called only during commit. Resource nodes are shared by href and are not\n// owned by a component's placement or unmount operations.\n// The renderer has already checked this host's resource eligibility.\nexport function acquireResource(type: string, props: any, container: Node): Element {\n const script = type === 'script'\n const style = type === 'style'\n const ownerDocument = (container.nodeType === 9 ? container : container.ownerDocument) as Document\n const tree = script ? ownerDocument : container.getRootNode()\n const root = (tree.nodeType === 9 || tree.nodeType === 11 ? tree : ownerDocument) as ResourceRoot\n const href = script ? props.src : props.href\n const resources = getResources(root)\n const key = resourceSelector(href, script ? 'script' : 'style')\n let node = resources.instances.get(key)\n if (node) return node\n const existing = !style && !script && root !== ownerDocument ? ownerDocument.querySelector(key) : null\n node = existing && !createdStylesheets.has(existing) && !(existing as any)._p ? existing\n : root.querySelector(style ? 'style' + resourceAttribute('data-href~', href) : key) || undefined\n if (node) { resources.instances.set(key, node); return node }\n\n const next = { ...props }\n if (!script) {\n next['data-precedence'] = props.precedence\n delete next.precedence\n if (style) { next['data-href'] = props.href; delete next.href }\n }\n if (!style) adoptResourceProps(next, getResources(ownerDocument).preloads.get(key), script)\n node = ownerDocument.createElement(type)\n for (const name in next) {\n setProp(node, name, name === 'href' || name === 'src' ? resourceURL(next[name]) : next[name], undefined, false)\n }\n if (style && next.dangerouslySetInnerHTML == null && (typeof next.children === 'string' || typeof next.children === 'number' || typeof next.children === 'bigint')) node.textContent = '' + next.children\n resources.instances.set(key, node)\n insertResource(node, script ? undefined : props.precedence, root)\n return node\n}\n"],
5
+ "mappings": ";AAAA,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,oBAAoB,oBAAoB,cAAc,gBAAgB,mBAAmB,wBAA2C;AAKtI,SAAS,gBAAgB,MAAc,OAAY,WAA0B;AAClF,QAAM,SAAS,SAAS;AACxB,QAAM,QAAQ,SAAS;AACvB,QAAM,gBAAiB,UAAU,aAAa,IAAI,YAAY,UAAU;AACxE,QAAM,OAAO,SAAS,gBAAgB,UAAU,YAAY;AAC5D,QAAM,OAAQ,KAAK,aAAa,KAAK,KAAK,aAAa,KAAK,OAAO;AACnE,QAAM,OAAO,SAAS,MAAM,MAAM,MAAM;AACxC,QAAM,YAAY,aAAa,IAAI;AACnC,QAAM,MAAM,iBAAiB,MAAM,SAAS,WAAW,OAAO;AAC9D,MAAI,OAAO,UAAU,UAAU,IAAI,GAAG;AACtC,MAAI,KAAM,QAAO;AACjB,QAAM,WAAW,CAAC,SAAS,CAAC,UAAU,SAAS,gBAAgB,cAAc,cAAc,GAAG,IAAI;AAClG,SAAO,YAAY,CAAC,mBAAmB,IAAI,QAAQ,KAAK,CAAE,SAAiB,KAAK,WAC5E,KAAK,cAAc,QAAQ,UAAU,kBAAkB,cAAc,IAAI,IAAI,GAAG,KAAK;AACzF,MAAI,MAAM;AAAE,cAAU,UAAU,IAAI,KAAK,IAAI;AAAG,WAAO;AAAA,EAAK;AAE5D,QAAM,OAAO,EAAE,GAAG,MAAM;AACxB,MAAI,CAAC,QAAQ;AACX,SAAK,iBAAiB,IAAI,MAAM;AAChC,WAAO,KAAK;AACZ,QAAI,OAAO;AAAE,WAAK,WAAW,IAAI,MAAM;AAAM,aAAO,KAAK;AAAA,IAAK;AAAA,EAChE;AACA,MAAI,CAAC,MAAO,oBAAmB,MAAM,aAAa,aAAa,EAAE,SAAS,IAAI,GAAG,GAAG,MAAM;AAC1F,SAAO,cAAc,cAAc,IAAI;AACvC,aAAW,QAAQ,MAAM;AACvB,YAAQ,MAAM,MAAM,SAAS,UAAU,SAAS,QAAQ,YAAY,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG,QAAW,KAAK;AAAA,EAChH;AACA,MAAI,SAAS,KAAK,2BAA2B,SAAS,OAAO,KAAK,aAAa,YAAY,OAAO,KAAK,aAAa,YAAY,OAAO,KAAK,aAAa,UAAW,MAAK,cAAc,KAAK,KAAK;AACjM,YAAU,UAAU,IAAI,KAAK,IAAI;AACjC,iBAAe,MAAM,SAAS,SAAY,MAAM,YAAY,IAAI;AAChE,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import { type Fiber, type Hook, type Effect } from "../core/index.js";
2
+ export declare const retainedEffects: WeakMap<Fiber, Map<Hook, Effect>>;
3
+ export declare function rememberRetainedEffect(fiber: Fiber, hook: Hook, effect: Effect): void;
4
+ export declare function setLayoutDisconnected(fiber: Fiber, disconnected: boolean): boolean;
5
+ export declare function walkRetained(fiber: Fiber, visit: (fiber: Fiber) => void, postorder?: boolean): void;
6
+ export declare function inSuspensePrimary(fiber: Fiber): boolean;
@@ -0,0 +1,49 @@
1
+ // src/dom/retained-effects.ts
2
+ import { FiberTag } from "../core/index.js";
3
+ import { onCommitRollback } from "./commit.js";
4
+ var retainedEffects = /* @__PURE__ */ new WeakMap();
5
+ function rememberRetainedEffect(fiber, hook, effect) {
6
+ let entries = retainedEffects.get(fiber);
7
+ if (!entries) {
8
+ retainedEffects.set(fiber, entries = /* @__PURE__ */ new Map());
9
+ onCommitRollback(() => {
10
+ retainedEffects.delete(fiber);
11
+ });
12
+ }
13
+ const previous = entries.get(hook), target = entries;
14
+ onCommitRollback(() => {
15
+ if (previous) target.set(hook, previous);
16
+ else target.delete(hook);
17
+ });
18
+ entries.set(hook, effect);
19
+ }
20
+ function setLayoutDisconnected(fiber, disconnected) {
21
+ const previous = !!fiber.ld;
22
+ if (previous !== disconnected) {
23
+ onCommitRollback(() => {
24
+ fiber.ld = previous;
25
+ });
26
+ fiber.ld = disconnected;
27
+ }
28
+ return previous;
29
+ }
30
+ function walkRetained(fiber, visit, postorder = false) {
31
+ if (!postorder) visit(fiber);
32
+ for (let child = fiber.child; child; child = child.sibling) walkRetained(child, visit, postorder);
33
+ if (fiber.tag === FiberTag.Suspense && fiber.ms?.f) walkRetained(fiber.ms.f, visit, postorder);
34
+ if (postorder) visit(fiber);
35
+ }
36
+ function inSuspensePrimary(fiber) {
37
+ for (let child = fiber, parent = fiber.parent; parent; child = parent, parent = parent.parent) {
38
+ if (parent.tag === FiberTag.Suspense && parent.ms?.d && parent.ms.f !== child) return true;
39
+ }
40
+ return false;
41
+ }
42
+ export {
43
+ inSuspensePrimary,
44
+ rememberRetainedEffect,
45
+ retainedEffects,
46
+ setLayoutDisconnected,
47
+ walkRetained
48
+ };
49
+ //# sourceMappingURL=retained-effects.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/dom/retained-effects.ts"],
4
+ "sourcesContent": ["import { FiberTag, type Fiber, type Hook, type Effect } from '../core'\nimport { onCommitRollback } from './commit'\n\nexport const retainedEffects = new WeakMap<Fiber, Map<Hook, Effect>>()\n\nexport function rememberRetainedEffect(fiber: Fiber, hook: Hook, effect: Effect): void {\n let entries = retainedEffects.get(fiber)\n if (!entries) {\n retainedEffects.set(fiber, entries = new Map())\n onCommitRollback(() => { retainedEffects.delete(fiber) })\n }\n const previous = entries.get(hook), target = entries\n onCommitRollback(() => { if (previous) target.set(hook, previous); else target.delete(hook) })\n entries.set(hook, effect)\n}\n\nexport function setLayoutDisconnected(fiber: Fiber, disconnected: boolean): boolean {\n const previous = !!fiber.ld\n if (previous !== disconnected) {\n onCommitRollback(() => { fiber.ld = previous })\n fiber.ld = disconnected\n }\n return previous\n}\n\nexport function walkRetained(fiber: Fiber, visit: (fiber: Fiber) => void, postorder = false): void {\n if (!postorder) visit(fiber)\n for (let child = fiber.child; child; child = child.sibling) walkRetained(child, visit, postorder)\n if (fiber.tag === FiberTag.Suspense && fiber.ms?.f) walkRetained(fiber.ms.f, visit, postorder)\n if (postorder) visit(fiber)\n}\n\nexport function inSuspensePrimary(fiber: Fiber): boolean {\n for (let child = fiber, parent = fiber.parent; parent; child = parent, parent = parent.parent) {\n if (parent.tag === FiberTag.Suspense && parent.ms?.d && parent.ms.f !== child) return true\n }\n return false\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAoD;AAC7D,SAAS,wBAAwB;AAE1B,IAAM,kBAAkB,oBAAI,QAAkC;AAE9D,SAAS,uBAAuB,OAAc,MAAY,QAAsB;AACrF,MAAI,UAAU,gBAAgB,IAAI,KAAK;AACvC,MAAI,CAAC,SAAS;AACZ,oBAAgB,IAAI,OAAO,UAAU,oBAAI,IAAI,CAAC;AAC9C,qBAAiB,MAAM;AAAE,sBAAgB,OAAO,KAAK;AAAA,IAAE,CAAC;AAAA,EAC1D;AACA,QAAM,WAAW,QAAQ,IAAI,IAAI,GAAG,SAAS;AAC7C,mBAAiB,MAAM;AAAE,QAAI,SAAU,QAAO,IAAI,MAAM,QAAQ;AAAA,QAAQ,QAAO,OAAO,IAAI;AAAA,EAAE,CAAC;AAC7F,UAAQ,IAAI,MAAM,MAAM;AAC1B;AAEO,SAAS,sBAAsB,OAAc,cAAgC;AAClF,QAAM,WAAW,CAAC,CAAC,MAAM;AACzB,MAAI,aAAa,cAAc;AAC7B,qBAAiB,MAAM;AAAE,YAAM,KAAK;AAAA,IAAS,CAAC;AAC9C,UAAM,KAAK;AAAA,EACb;AACA,SAAO;AACT;AAEO,SAAS,aAAa,OAAc,OAA+B,YAAY,OAAa;AACjG,MAAI,CAAC,UAAW,OAAM,KAAK;AAC3B,WAAS,QAAQ,MAAM,OAAO,OAAO,QAAQ,MAAM,QAAS,cAAa,OAAO,OAAO,SAAS;AAChG,MAAI,MAAM,QAAQ,SAAS,YAAY,MAAM,IAAI,EAAG,cAAa,MAAM,GAAG,GAAG,OAAO,SAAS;AAC7F,MAAI,UAAW,OAAM,KAAK;AAC5B;AAEO,SAAS,kBAAkB,OAAuB;AACvD,WAAS,QAAQ,OAAO,SAAS,MAAM,QAAQ,QAAQ,QAAQ,QAAQ,SAAS,OAAO,QAAQ;AAC7F,QAAI,OAAO,QAAQ,SAAS,YAAY,OAAO,IAAI,KAAK,OAAO,GAAG,MAAM,MAAO,QAAO;AAAA,EACxF;AACA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,9 +1,9 @@
1
- import { type FiberRoot } from '../core';
1
+ import { type FiberRoot, type RecoverableErrorHandler } from "../core/index.js";
2
2
  export interface RootOptionsInternal {
3
3
  identifierPrefix?: string;
4
- onRecoverableError?: (error: unknown) => void;
5
- onCaughtError?: (error: unknown) => void;
6
- onUncaughtError?: (error: unknown) => void;
4
+ onRecoverableError?: RecoverableErrorHandler;
5
+ onCaughtError?: RecoverableErrorHandler;
6
+ onUncaughtError?: RecoverableErrorHandler;
7
7
  }
8
8
  export declare function createFiberRoot(container: Element | Document | DocumentFragment, options: RootOptionsInternal): FiberRoot;
9
9
  export declare function attachRootFiber(root: FiberRoot, container: Element | Document | DocumentFragment): void;
@@ -1,5 +1,5 @@
1
- // packages/redact/src/dom/root-internal.ts
2
- import { FiberTag, createFiber } from "../core";
1
+ // src/dom/root-internal.ts
2
+ import { FiberTag, createFiber } from "../core/index.js";
3
3
  function createFiberRoot(container, options) {
4
4
  const rootFiber = createFiber(FiberTag.Root, null, null);
5
5
  const root = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/root-internal.ts"],
4
- "sourcesContent": ["import { FiberTag, createFiber, type Fiber, type FiberRoot } from '../core'\n\nexport interface RootOptionsInternal {\n identifierPrefix?: string\n onRecoverableError?: (error: unknown) => void\n onCaughtError?: (error: unknown) => void\n onUncaughtError?: (error: unknown) => void\n}\n\nexport function createFiberRoot(\n container: Element | Document | DocumentFragment,\n options: RootOptionsInternal,\n): FiberRoot {\n const rootFiber = createFiber(FiberTag.Root, null, null)\n const root: FiberRoot = {\n c: container as any,\n r: rootFiber,\n p: new Set(),\n s: false,\n re: options.onRecoverableError,\n ce: options.onCaughtError,\n ue: options.onUncaughtError,\n i: options.identifierPrefix,\n ic: 0,\n h: false,\n }\n rootFiber.root = root\n rootFiber.sn = container\n return root\n}\n\nexport function attachRootFiber(\n root: FiberRoot,\n container: Element | Document | DocumentFragment,\n): void {\n const rootFiber = createFiber(FiberTag.Root, null, null)\n root.c = container as any\n root.ic = 0\n rootFiber.root = root\n rootFiber.sn = container\n root.r = rootFiber\n}\n"],
5
- "mappings": ";AAAA,SAAS,UAAU,mBAA+C;AAS3D,SAAS,gBACd,WACA,SACW;AACX,QAAM,YAAY,YAAY,SAAS,MAAM,MAAM,IAAI;AACvD,QAAM,OAAkB;AAAA,IACtB,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG,oBAAI,IAAI;AAAA,IACX,GAAG;AAAA,IACH,IAAI,QAAQ;AAAA,IACZ,IAAI,QAAQ;AAAA,IACZ,IAAI,QAAQ;AAAA,IACZ,GAAG,QAAQ;AAAA,IACX,IAAI;AAAA,IACJ,GAAG;AAAA,EACL;AACA,YAAU,OAAO;AACjB,YAAU,KAAK;AACf,SAAO;AACT;AAEO,SAAS,gBACd,MACA,WACM;AACN,QAAM,YAAY,YAAY,SAAS,MAAM,MAAM,IAAI;AACvD,OAAK,IAAI;AACT,OAAK,KAAK;AACV,YAAU,OAAO;AACjB,YAAU,KAAK;AACf,OAAK,IAAI;AACX;",
4
+ "sourcesContent": ["import { FiberTag, createFiber, type Fiber, type FiberRoot, type RecoverableErrorHandler } from '../core'\n\nexport interface RootOptionsInternal {\n identifierPrefix?: string\n onRecoverableError?: RecoverableErrorHandler\n onCaughtError?: RecoverableErrorHandler\n onUncaughtError?: RecoverableErrorHandler\n}\n\nexport function createFiberRoot(\n container: Element | Document | DocumentFragment,\n options: RootOptionsInternal,\n): FiberRoot {\n const rootFiber = createFiber(FiberTag.Root, null, null)\n const root: FiberRoot = {\n c: container as any,\n r: rootFiber,\n p: new Set(),\n s: false,\n re: options.onRecoverableError,\n ce: options.onCaughtError,\n ue: options.onUncaughtError,\n i: options.identifierPrefix,\n ic: 0,\n h: false,\n }\n rootFiber.root = root\n rootFiber.sn = container\n return root\n}\n\nexport function attachRootFiber(\n root: FiberRoot,\n container: Element | Document | DocumentFragment,\n): void {\n const rootFiber = createFiber(FiberTag.Root, null, null)\n root.c = container as any\n root.ic = 0\n rootFiber.root = root\n rootFiber.sn = container\n root.r = rootFiber\n}\n"],
5
+ "mappings": ";AAAA,SAAS,UAAU,mBAA6E;AASzF,SAAS,gBACd,WACA,SACW;AACX,QAAM,YAAY,YAAY,SAAS,MAAM,MAAM,IAAI;AACvD,QAAM,OAAkB;AAAA,IACtB,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG,oBAAI,IAAI;AAAA,IACX,GAAG;AAAA,IACH,IAAI,QAAQ;AAAA,IACZ,IAAI,QAAQ;AAAA,IACZ,IAAI,QAAQ;AAAA,IACZ,GAAG,QAAQ;AAAA,IACX,IAAI;AAAA,IACJ,GAAG;AAAA,EACL;AACA,YAAU,OAAO;AACjB,YAAU,KAAK;AACf,SAAO;AACT;AAEO,SAAS,gBACd,MACA,WACM;AACN,QAAM,YAAY,YAAY,SAAS,MAAM,MAAM,IAAI;AACvD,OAAK,IAAI;AACT,OAAK,KAAK;AACV,YAAU,OAAO;AACjB,YAAU,KAAK;AACf,OAAK,IAAI;AACX;",
6
6
  "names": []
7
7
  }
@@ -1,10 +1,10 @@
1
- import type { ReactNode } from '../core';
2
- import { flushSyncWork, batchedUpdates } from './reconcile';
1
+ import type { ReactNode, RecoverableErrorHandler } from "../core/index.js";
2
+ import { flushSyncWork, batchedUpdates } from "./reconcile.js";
3
3
  export interface RootOptions {
4
4
  identifierPrefix?: string;
5
- onRecoverableError?: (error: unknown) => void;
6
- onCaughtError?: (error: unknown) => void;
7
- onUncaughtError?: (error: unknown) => void;
5
+ onRecoverableError?: RecoverableErrorHandler;
6
+ onCaughtError?: RecoverableErrorHandler;
7
+ onUncaughtError?: RecoverableErrorHandler;
8
8
  }
9
9
  export interface Root {
10
10
  render(children: ReactNode): void;
package/dist/dom/root.js CHANGED
@@ -1,20 +1,20 @@
1
- // packages/redact/src/dom/root.ts
2
- import { renderRoot, flushSyncWork, batchedUpdates } from "./reconcile";
3
- import { hydrateRootImpl } from "./features/hydration";
4
- import { createFiberRoot } from "./root-internal";
1
+ // src/dom/root.ts
2
+ import { renderRoot, scheduleRootRender, flushSyncWork, batchedUpdates } from "./reconcile.js";
3
+ import { hydrateRootImpl } from "./features/hydration/index.js";
4
+ import { createFiberRoot } from "./root-internal.js";
5
+ import { queueMutation } from "./commit.js";
5
6
  function createRoot(container, options = {}) {
6
7
  const root = createFiberRoot(container, options);
7
8
  let firstRender = true;
8
9
  return {
9
10
  render(children) {
10
- if (firstRender) {
11
- firstRender = false;
12
- if (container.nodeType === 1) {
13
- ;
14
- container.textContent = "";
11
+ scheduleRootRender(root, () => {
12
+ if (firstRender) {
13
+ queueMutation(() => {
14
+ firstRender = false;
15
+ if (container.nodeType === 1) container.textContent = "";
16
+ });
15
17
  }
16
- }
17
- flushSyncWork(() => {
18
18
  renderRoot(root, children);
19
19
  });
20
20
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/root.ts"],
4
- "sourcesContent": ["import type { ReactNode } from '../core'\nimport { renderRoot, flushSyncWork, batchedUpdates } from './reconcile'\nimport { hydrateRootImpl } from './features/hydration'\nimport { createFiberRoot } from './root-internal'\n\nexport interface RootOptions {\n identifierPrefix?: string\n onRecoverableError?: (error: unknown) => void\n onCaughtError?: (error: unknown) => void\n onUncaughtError?: (error: unknown) => void\n}\n\nexport interface Root {\n render(children: ReactNode): void\n unmount(): void\n}\n\nexport function createRoot(container: Element | DocumentFragment, options: RootOptions = {}): Root {\n const root = createFiberRoot(container, options)\n\n let firstRender = true\n return {\n render(children) {\n if (firstRender) {\n firstRender = false\n // Match real React's `clearContainer` semantics: blow away any pre-render\n // markup (server-rendered placeholder, splash shells, etc.) on the\n // initial commit so it doesn't stack with the React tree.\n if ((container as Node).nodeType === 1 /* ELEMENT_NODE */) {\n ;(container as Element).textContent = ''\n }\n }\n flushSyncWork(() => {\n renderRoot(root, children)\n })\n },\n unmount() {\n flushSyncWork(() => {\n renderRoot(root, null)\n })\n },\n }\n}\n\nexport function hydrateRoot(\n container: Element | Document,\n initialChildren: ReactNode,\n options: RootOptions = {},\n): Root {\n return hydrateRootImpl(container, initialChildren, options)\n}\n\nexport { flushSyncWork as flushSync, batchedUpdates }\n"],
5
- "mappings": ";AACA,SAAS,YAAY,eAAe,sBAAsB;AAC1D,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAczB,SAAS,WAAW,WAAuC,UAAuB,CAAC,GAAS;AACjG,QAAM,OAAO,gBAAgB,WAAW,OAAO;AAE/C,MAAI,cAAc;AAClB,SAAO;AAAA,IACL,OAAO,UAAU;AACf,UAAI,aAAa;AACf,sBAAc;AAId,YAAK,UAAmB,aAAa,GAAsB;AACzD;AAAC,UAAC,UAAsB,cAAc;AAAA,QACxC;AAAA,MACF;AACA,oBAAc,MAAM;AAClB,mBAAW,MAAM,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,IACA,UAAU;AACR,oBAAc,MAAM;AAClB,mBAAW,MAAM,IAAI;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,YACd,WACA,iBACA,UAAuB,CAAC,GAClB;AACN,SAAO,gBAAgB,WAAW,iBAAiB,OAAO;AAC5D;",
4
+ "sourcesContent": ["import type { ReactNode, RecoverableErrorHandler } from '../core'\nimport { renderRoot, scheduleRootRender, flushSyncWork, batchedUpdates } from './reconcile'\nimport { hydrateRootImpl } from './features/hydration'\nimport { createFiberRoot } from './root-internal'\nimport { queueMutation } from './commit'\n\nexport interface RootOptions {\n identifierPrefix?: string\n onRecoverableError?: RecoverableErrorHandler\n onCaughtError?: RecoverableErrorHandler\n onUncaughtError?: RecoverableErrorHandler\n}\n\nexport interface Root {\n render(children: ReactNode): void\n unmount(): void\n}\n\nexport function createRoot(container: Element | DocumentFragment, options: RootOptions = {}): Root {\n const root = createFiberRoot(container, options)\n\n let firstRender = true\n return {\n render(children) {\n scheduleRootRender(root, () => {\n if (firstRender) {\n queueMutation(() => {\n firstRender = false\n if ((container as Node).nodeType === 1) container.textContent = ''\n })\n }\n renderRoot(root, children)\n })\n },\n unmount() {\n flushSyncWork(() => {\n renderRoot(root, null)\n })\n },\n }\n}\n\nexport function hydrateRoot(\n container: Element | Document,\n initialChildren: ReactNode,\n options: RootOptions = {},\n): Root {\n return hydrateRootImpl(container, initialChildren, options)\n}\n\nexport { flushSyncWork as flushSync, batchedUpdates }\n"],
5
+ "mappings": ";AACA,SAAS,YAAY,oBAAoB,eAAe,sBAAsB;AAC9E,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAcvB,SAAS,WAAW,WAAuC,UAAuB,CAAC,GAAS;AACjG,QAAM,OAAO,gBAAgB,WAAW,OAAO;AAE/C,MAAI,cAAc;AAClB,SAAO;AAAA,IACL,OAAO,UAAU;AACf,yBAAmB,MAAM,MAAM;AAC7B,YAAI,aAAa;AACf,wBAAc,MAAM;AAClB,0BAAc;AACd,gBAAK,UAAmB,aAAa,EAAG,WAAU,cAAc;AAAA,UAClE,CAAC;AAAA,QACH;AACA,mBAAW,MAAM,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,IACA,UAAU;AACR,oBAAc,MAAM;AAClB,mBAAW,MAAM,IAAI;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,YACd,WACA,iBACA,UAAuB,CAAC,GAClB;AACN,SAAO,gBAAgB,WAAW,iBAAiB,OAAO;AAC5D;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- // packages/redact/src/dom/test-utils.ts
1
+ // src/dom/test-utils.ts
2
2
  async function act(fn) {
3
3
  const r = fn();
4
4
  if (r && typeof r.then == "function") await r;
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from "../core/index.js";
2
+ export declare const REACT_ACTIVITY_TYPE: unique symbol;
3
+ export interface ActivityProps {
4
+ children?: ReactNode;
5
+ mode?: 'hidden' | 'visible';
6
+ }
7
+ export declare const Activity: (props: ActivityProps) => any;
@@ -0,0 +1,8 @@
1
+ // src/react/activity.ts
2
+ var REACT_ACTIVITY_TYPE = /* @__PURE__ */ Symbol.for("react.activity");
3
+ var Activity = REACT_ACTIVITY_TYPE;
4
+ export {
5
+ Activity,
6
+ REACT_ACTIVITY_TYPE
7
+ };
8
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/react/activity.ts"],
4
+ "sourcesContent": ["import type { ReactNode } from '../core'\n\nexport const REACT_ACTIVITY_TYPE = Symbol.for('react.activity')\n\nexport interface ActivityProps {\n children?: ReactNode\n mode?: 'hidden' | 'visible'\n}\n\nexport const Activity = REACT_ACTIVITY_TYPE as any as (props: ActivityProps) => any\n"],
5
+ "mappings": ";AAEO,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AAOvD,IAAM,WAAW;",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { ReactNode, ReactElement } from '../core';
1
+ import type { ReactNode, ReactElement } from "../core/index.js";
2
2
  export declare const Children: {
3
3
  map(children: ReactNode, fn: (child: ReactNode, index: number) => any): any[] | null;
4
4
  forEach(children: ReactNode, fn: (child: ReactNode, index: number) => void): void;
@@ -1,5 +1,5 @@
1
- // packages/redact/src/react/children.ts
2
- import { isValidElement, cloneElement } from "./element";
1
+ // src/react/children.ts
2
+ import { isValidElement, cloneElement } from "./element.js";
3
3
  function flatten(node, out, prefix) {
4
4
  if (node == null || typeof node === "boolean") return;
5
5
  if (Array.isArray(node)) {
@@ -64,7 +64,7 @@ var Children = {
64
64
  },
65
65
  only(children) {
66
66
  if (!isValidElement(children)) {
67
- if (true) {
67
+ if (process.env.NODE_ENV !== "production") {
68
68
  throw new Error("Children.only expected a single React element.");
69
69
  }
70
70
  throw new Error();
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/react/children.ts"],
4
4
  "sourcesContent": ["import { isValidElement, cloneElement } from './element'\nimport type { ReactNode, ReactElement } from '../core'\n\nfunction flatten(node: ReactNode, out: any[], prefix: string): void {\n if (node == null || typeof node === 'boolean') return\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) flatten(node[i], out, prefix + '.' + i)\n return\n }\n out.push(node)\n}\n\nfunction getKey(node: any, index: number, prefix: string): string {\n if (isValidElement(node) && node.key != null) return prefix + '$' + node.key\n return prefix + ':' + index\n}\n\nfunction mapChildren(\n children: ReactNode,\n fn: (child: ReactNode, index: number) => any,\n prefix = '',\n): any[] {\n const flat: any[] = []\n flatten(children, flat, prefix)\n const out: any[] = []\n for (let i = 0; i < flat.length; i++) {\n const child = flat[i]\n const mapped = fn(child, i)\n if (mapped == null) continue\n if (Array.isArray(mapped)) {\n for (let j = 0; j < mapped.length; j++) {\n const m = mapped[j]\n if (m == null) continue\n out.push(\n isValidElement(m) && m.key == null\n ? cloneElement(m as ReactElement, { key: getKey(child, i, prefix) + '/' + j })\n : m,\n )\n }\n } else {\n out.push(\n isValidElement(mapped) && mapped.key == null\n ? cloneElement(mapped as ReactElement, { key: getKey(child, i, prefix) })\n : mapped,\n )\n }\n }\n return out\n}\n\nexport const Children = {\n map(children: ReactNode, fn: (child: ReactNode, index: number) => any): any[] | null {\n if (children == null) return null\n return mapChildren(children, fn)\n },\n forEach(children: ReactNode, fn: (child: ReactNode, index: number) => void): void {\n if (children == null) return\n mapChildren(children, (c, i) => {\n fn(c, i)\n return null\n })\n },\n count(children: ReactNode): number {\n let n = 0\n const flat: any[] = []\n flatten(children, flat, '')\n for (let i = 0; i < flat.length; i++) n++\n return n\n },\n toArray(children: ReactNode): any[] {\n const flat: any[] = []\n flatten(children, flat, '')\n return flat.map((c, i) =>\n isValidElement(c) && c.key == null\n ? cloneElement(c as ReactElement, { key: '' + i })\n : c,\n )\n },\n only(children: ReactNode): ReactElement {\n if (!isValidElement(children)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Children.only expected a single React element.')\n }\n throw new Error()\n }\n return children\n },\n}\n"],
5
- "mappings": ";AAAA,SAAS,gBAAgB,oBAAoB;AAG7C,SAAS,QAAQ,MAAiB,KAAY,QAAsB;AAClE,MAAI,QAAQ,QAAQ,OAAO,SAAS,UAAW;AAC/C,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAK,SAAQ,KAAK,CAAC,GAAG,KAAK,SAAS,MAAM,CAAC;AAC5E;AAAA,EACF;AACA,MAAI,KAAK,IAAI;AACf;AAEA,SAAS,OAAO,MAAW,OAAe,QAAwB;AAChE,MAAI,eAAe,IAAI,KAAK,KAAK,OAAO,KAAM,QAAO,SAAS,MAAM,KAAK;AACzE,SAAO,SAAS,MAAM;AACxB;AAEA,SAAS,YACP,UACA,IACA,SAAS,IACF;AACP,QAAM,OAAc,CAAC;AACrB,UAAQ,UAAU,MAAM,MAAM;AAC9B,QAAM,MAAa,CAAC;AACpB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,QAAQ,KAAK,CAAC;AACpB,UAAM,SAAS,GAAG,OAAO,CAAC;AAC1B,QAAI,UAAU,KAAM;AACpB,QAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,eAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,cAAM,IAAI,OAAO,CAAC;AAClB,YAAI,KAAK,KAAM;AACf,YAAI;AAAA,UACF,eAAe,CAAC,KAAK,EAAE,OAAO,OAC1B,aAAa,GAAmB,EAAE,KAAK,OAAO,OAAO,GA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EACA,QAAQ,UAAqB,IAAqD;AAChF,QAAI,YAAY,KAAM;AACtB,gBAAY,UAAU,CAAC,GAAG,MAAM;AAC9B,SAAG,GAAG,CAAC;AACP,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA,EACA,MAAM,UAA6B;AACjC,QAAI,IAAI;AACR,UAAM,OAAc,CAAC;AACrB,YAAQ,UAAU,MAAM,EAAE;AAC1B,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAK;AACtC,WAAO;AAAA,EACT;AAAA,EACA,QAAQ,UAA4B;AAClC,UAAM,OAAc,CAAC;AACrB,YAAQ,UAAU,MAAM,EAAE;AAC1B,WAAO,KAAK;AAAA,MAAI,CAAC,GAAG,MAClB,eAAe,CAAC,KAAK,EAAE,OAAO,OAC1B,aAAa,GAAmB,EAAE,KAAK,KAAK,EAAE,CAAC,IAC/C;AAAA,IACN;AAAA,EACF;AAAA,EACA,KAAK,UAAmC;AACtC,QAAI,CAAC,eAAe,QAAQ,GAAG;AAC7B,UAAI,yBAAyB,cAAc;AACzC,cAAM,IAAI,MAAM,gDAAgD;AAAA,MAClE;AACA,YAAM,IAAI,MAAM;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from '../core';
1
+ import type { ReactNode } from "../core/index.js";
2
2
  type SetStateCallback<S, P> = Partial<S> | ((prev: S, props: P) => Partial<S> | null) | null;
3
3
  export declare class Component<P = {}, S = {}> {
4
4
  static contextType?: any;
@@ -1,4 +1,4 @@
1
- // packages/redact/src/react/class.ts
1
+ // src/react/class.ts
2
2
  var Component = class {
3
3
  static contextType;
4
4
  static defaultProps;
@@ -17,7 +17,7 @@ var Component = class {
17
17
  }
18
18
  setState(updater, callback) {
19
19
  if (!this._enqueueUpdate) {
20
- if (true) {
20
+ if (process.env.NODE_ENV !== "production") {
21
21
  throw new Error("Cannot call setState on an um component.");
22
22
  }
23
23
  throw new Error();
@@ -29,7 +29,7 @@ var Component = class {
29
29
  this._forceUpdate(callback);
30
30
  }
31
31
  render() {
32
- if (true) {
32
+ if (process.env.NODE_ENV !== "production") {
33
33
  throw new Error("Component subclass must implement render().");
34
34
  }
35
35
  throw new Error();
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/react/class.ts"],
4
4
  "sourcesContent": ["import type { ReactNode } from '../core'\n\ntype SetStateCallback<S, P> =\n | Partial<S>\n | ((prev: S, props: P) => Partial<S> | null)\n | null\n\nexport class Component<P = {}, S = {}> {\n static contextType?: any\n static getDerivedStateFromProps?(props: any, state: any): any\n static getDerivedStateFromError?(error: any): any\n static defaultProps?: any\n static displayName?: string\n\n props: P\n state: S = {} as S\n context: any\n refs: Record<string, any> = {}\n\n // Injected by reconciler\n _fiber: any = null\n _enqueueUpdate: ((updater: SetStateCallback<S, P>, cb?: () => void) => void) | null = null\n _forceUpdate: ((cb?: () => void) => void) | null = null\n\n constructor(props: P, context?: any) {\n this.props = props\n this.context = context\n }\n\n setState(updater: SetStateCallback<S, P>, callback?: () => void): void {\n if (!this._enqueueUpdate) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Cannot call setState on an um component.')\n }\n throw new Error()\n }\n this._enqueueUpdate(updater, callback)\n }\n\n forceUpdate(callback?: () => void): void {\n if (!this._forceUpdate) return\n this._forceUpdate(callback)\n }\n\n render(): ReactNode {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Component subclass must implement render().')\n }\n throw new Error()\n }\n\n componentDidMount?(): void\n componentDidUpdate?(prevProps: P, prevState: S, snapshot?: any): void\n componentWillUnmount?(): void\n shouldComponentUpdate?(nextProps: P, nextState: S, nextCtx: any): boolean\n getSnapshotBeforeUpdate?(prevProps: P, prevState: S): any\n componentDidCatch?(error: any, info: { componentStack: string }): void\n}\n;(Component.prototype as any).isReactComponent = {}\n\nexport class PureComponent<P = {}, S = {}> extends Component<P, S> {}\n;(PureComponent.prototype as any).isPureReactComponent = true\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Ac;AACzC,cAAM,IAAI,MAAM,0CAA0C;AAAA,MAC5D;AACA,YAAM,IAAI,MAAM;AAAA,IAClB;AACA,SAAK,eAAe,SAAS,QAAQ;AAAA,EACvC;AAAA,EAEA,YAAY,UAA6B;AACvC,QAAI,CAAC,KAAK,aAAc;AACxB,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA,EAEA,SAAoB;AAClB,QAAI,yBAAyB,cAAc;AACzC,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AAQF;AACE,UAAU,UAAkB,mBAAmB,CAAC;AAE3C,IAAM,gBAAN,cAA4C,UAAgB;AAAC;AAClE,cAAc,UAAkB,uBAAuB;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
- // packages/redact/src/react/compiler-runtime.ts
2
- import { useRef } from "./hooks";
1
+ // src/react/compiler-runtime.ts
2
+ import { useRef } from "./hooks.js";
3
3
  var MEMO_CACHE_SENTINEL = /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel");
4
4
  function c(size) {
5
5
  const ref = useRef(null);
@@ -1,9 +1,10 @@
1
- import type { ReactElement, ReactNode } from '../core';
1
+ import type { ReactElement, ReactNode } from "../core/index.js";
2
2
  export declare const REACT_CONTEXT_TYPE: unique symbol;
3
3
  export declare const REACT_PROVIDER_TYPE: unique symbol;
4
4
  export declare const REACT_CONSUMER_TYPE: unique symbol;
5
5
  export interface Context<T> {
6
6
  $$typeof: typeof REACT_CONTEXT_TYPE;
7
+ _context: Context<T>;
7
8
  _currentValue: T;
8
9
  Provider: ProviderExoticComponent<{
9
10
  value: T;
@@ -11,9 +12,13 @@ export interface Context<T> {
11
12
  }>;
12
13
  Consumer: ConsumerExoticComponent<T>;
13
14
  displayName?: string;
15
+ (props: {
16
+ value: T;
17
+ children?: ReactNode;
18
+ }): ReactElement;
14
19
  }
15
20
  export interface ProviderExoticComponent<P> {
16
- $$typeof: typeof REACT_PROVIDER_TYPE;
21
+ $$typeof: typeof REACT_CONTEXT_TYPE | typeof REACT_PROVIDER_TYPE;
17
22
  _context: Context<any>;
18
23
  (props: P): ReactElement;
19
24
  }
@@ -1,5 +1,5 @@
1
- // packages/redact/src/react/context.ts
2
- import { useContext } from "./hooks";
1
+ // src/react/context.ts
2
+ import { useContext } from "./hooks.js";
3
3
  var REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context");
4
4
  var REACT_PROVIDER_TYPE = /* @__PURE__ */ Symbol.for("react.provider");
5
5
  var REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer");
@@ -8,20 +8,12 @@ function createContext(defaultValue) {
8
8
  $$typeof: REACT_CONTEXT_TYPE,
9
9
  _currentValue: defaultValue
10
10
  };
11
- const Provider = function Provider2(_props) {
12
- if (true) {
13
- throw new Error("Provider components are handled by the renderer.");
14
- }
15
- throw new Error();
16
- };
17
- Provider.$$typeof = REACT_PROVIDER_TYPE;
18
- Provider._context = context;
19
11
  const Consumer = function Consumer2(props) {
20
12
  return props.children(useContext(context));
21
13
  };
22
14
  Consumer.$$typeof = REACT_CONSUMER_TYPE;
23
15
  Consumer._context = context;
24
- context.Provider = Provider;
16
+ context.Provider = context._context = context;
25
17
  context.Consumer = Consumer;
26
18
  return context;
27
19
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/react/context.ts"],
4
- "sourcesContent": ["import type { ReactElement, ReactNode } from '../core'\nimport { useContext } from './hooks'\n\nexport const REACT_CONTEXT_TYPE = Symbol.for('react.context')\nexport const REACT_PROVIDER_TYPE = Symbol.for('react.provider')\nexport const REACT_CONSUMER_TYPE = Symbol.for('react.consumer')\n\nexport interface Context<T> {\n $$typeof: typeof REACT_CONTEXT_TYPE\n _currentValue: T\n Provider: ProviderExoticComponent<{ value: T; children?: ReactNode }>\n Consumer: ConsumerExoticComponent<T>\n displayName?: string\n}\n\nexport interface ProviderExoticComponent<P> {\n $$typeof: typeof REACT_PROVIDER_TYPE\n _context: Context<any>\n (props: P): ReactElement\n}\n\nexport interface ConsumerExoticComponent<T> {\n $$typeof: typeof REACT_CONSUMER_TYPE\n _context: Context<T>\n (props: { children: (value: T) => ReactNode }): ReactElement\n}\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n const context: Context<T> = {\n $$typeof: REACT_CONTEXT_TYPE,\n _currentValue: defaultValue,\n } as Context<T>\n\n const Provider: any = function Provider(_props: any): any {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Provider components are handled by the renderer.')\n }\n throw new Error()\n }\n Provider.$$typeof = REACT_PROVIDER_TYPE\n Provider._context = context\n\n const Consumer: any = function Consumer(props: { children: (v: T) => any }): any {\n return props.children(useContext(context))\n }\n Consumer.$$typeof = REACT_CONSUMER_TYPE\n Consumer._context = context\n\n context.Provider = Provider\n context.Consumer = Consumer\n\n return context\n}\n"],
5
- "mappings": ";AACA,SAAS,kBAAkB;AAEpB,IAAM,qBAAqB,uBAAO,IAAI,eAAe;AACrD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AACvD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AAsBvD,SAAS,cAAiB,cAA6B;AAC5D,QAAM,UAAsB;AAAA,IAC1B,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAEA,QAAM,WAAgB,SAASA,UAAS,QAAkB;AACxD,QAAI,MAAuC;AACzC,YAAM,IAAI,MAAM,kDAAkD;AAAA,IACpE;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AACA,WAAS,WAAW;AACpB,WAAS,WAAW;AAEpB,QAAM,WAAgB,SAASC,UAAS,OAAyC;AAC/E,WAAO,MAAM,SAAS,WAAW,OAAO,CAAC;AAAA,EAC3C;AACA,WAAS,WAAW;AACpB,WAAS,WAAW;AAEpB,UAAQ,WAAW;AACnB,UAAQ,WAAW;AAEnB,SAAO;AACT;",
6
- "names": ["Provider", "Consumer"]
4
+ "sourcesContent": ["import type { ReactElement, ReactNode } from '../core'\nimport { useContext } from './hooks'\n\nexport const REACT_CONTEXT_TYPE = Symbol.for('react.context')\nexport const REACT_PROVIDER_TYPE = Symbol.for('react.provider')\nexport const REACT_CONSUMER_TYPE = Symbol.for('react.consumer')\n\nexport interface Context<T> {\n $$typeof: typeof REACT_CONTEXT_TYPE\n _context: Context<T>\n _currentValue: T\n Provider: ProviderExoticComponent<{ value: T; children?: ReactNode }>\n Consumer: ConsumerExoticComponent<T>\n displayName?: string\n (props: { value: T; children?: ReactNode }): ReactElement\n}\n\nexport interface ProviderExoticComponent<P> {\n $$typeof: typeof REACT_CONTEXT_TYPE | typeof REACT_PROVIDER_TYPE\n _context: Context<any>\n (props: P): ReactElement\n}\n\nexport interface ConsumerExoticComponent<T> {\n $$typeof: typeof REACT_CONSUMER_TYPE\n _context: Context<T>\n (props: { children: (value: T) => ReactNode }): ReactElement\n}\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n const context: Context<T> = {\n $$typeof: REACT_CONTEXT_TYPE,\n _currentValue: defaultValue,\n } as Context<T>\n\n const Consumer: any = function Consumer(props: { children: (v: T) => any }): any {\n return props.children(useContext(context))\n }\n Consumer.$$typeof = REACT_CONSUMER_TYPE\n Consumer._context = context\n\n context.Provider = context._context = context\n context.Consumer = Consumer\n\n return context\n}\n"],
5
+ "mappings": ";AACA,SAAS,kBAAkB;AAEpB,IAAM,qBAAqB,uBAAO,IAAI,eAAe;AACrD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AACvD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AAwBvD,SAAS,cAAiB,cAA6B;AAC5D,QAAM,UAAsB;AAAA,IAC1B,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAEA,QAAM,WAAgB,SAASA,UAAS,OAAyC;AAC/E,WAAO,MAAM,SAAS,WAAW,OAAO,CAAC;AAAA,EAC3C;AACA,WAAS,WAAW;AACpB,WAAS,WAAW;AAEpB,UAAQ,WAAW,QAAQ,WAAW;AACtC,UAAQ,WAAW;AAEnB,SAAO;AACT;",
6
+ "names": ["Consumer"]
7
7
  }
@@ -1,9 +1,12 @@
1
- import { type ReactElement, type ReactNode } from '../core';
1
+ import { type ReactElement, type ReactNode, type Ref } from "../core/index.js";
2
+ import type { FragmentInstance } from "../dom/fragment-instance.js";
2
3
  export declare const Fragment: (props: {
3
4
  children?: ReactNode;
5
+ key?: string | number;
6
+ ref?: Ref<FragmentInstance>;
4
7
  }) => ReactElement;
5
- export declare function createElement(type: any, config: Record<string, any> | null, ...children: ReactNode[]): ReactElement;
6
- export declare function cloneElement(element: ReactElement, config: Record<string, any> | null, ...children: ReactNode[]): ReactElement;
8
+ export declare function createElement(type: any, config?: Record<string, any> | null, ...children: ReactNode[]): ReactElement;
9
+ export declare function cloneElement(element: ReactElement, config?: Record<string, any> | null, ...children: ReactNode[]): ReactElement;
7
10
  export declare function isValidElement(obj: any): obj is ReactElement;
8
11
  export declare function createRef<T = any>(): {
9
12
  current: T | null;
@@ -1,20 +1,17 @@
1
- // packages/redact/src/react/element.ts
1
+ // src/react/element.ts
2
2
  import {
3
3
  REACT_ELEMENT_TYPE,
4
4
  REACT_LEGACY_ELEMENT_TYPE,
5
5
  REACT_FRAGMENT_TYPE
6
- } from "../core";
6
+ } from "../core/index.js";
7
7
  var Fragment = REACT_FRAGMENT_TYPE;
8
- var RESERVED_PROPS = { key: 1, ref: 1, __self: 1, __source: 1 };
9
8
  function createElement(type, config, ...children) {
10
9
  let key = null;
11
- let ref = null;
12
10
  const props = {};
13
11
  if (config != null) {
14
12
  if (config.key !== void 0 && config.key !== null) key = "" + config.key;
15
- if (config.ref !== void 0) ref = config.ref;
16
13
  for (const k in config) {
17
- if (!RESERVED_PROPS[k] && Object.prototype.hasOwnProperty.call(config, k)) {
14
+ if (k !== "key" && k !== "__self" && k !== "__source" && Object.prototype.hasOwnProperty.call(config, k)) {
18
15
  props[k] = config[k];
19
16
  }
20
17
  }
@@ -27,24 +24,23 @@ function createElement(type, config, ...children) {
27
24
  if (props[k] === void 0) props[k] = dp[k];
28
25
  }
29
26
  }
30
- return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref, props };
27
+ return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref: props.ref ?? null, props };
31
28
  }
32
29
  function cloneElement(element, config, ...children) {
33
30
  let key = element.key;
34
- let ref = element.ref;
35
31
  const props = { ...element.props };
36
32
  if (config != null) {
37
- if (config.ref !== void 0) ref = config.ref;
38
33
  if (config.key !== void 0) key = "" + config.key;
39
34
  const defaultProps = element.type?.defaultProps;
40
35
  for (const k in config) {
41
- if (RESERVED_PROPS[k] || !Object.prototype.hasOwnProperty.call(config, k)) continue;
36
+ if (k === "key" || k === "__self" || k === "__source" || !Object.prototype.hasOwnProperty.call(config, k)) continue;
37
+ if (k === "ref" && config.ref === void 0) continue;
42
38
  props[k] = config[k] === void 0 && defaultProps ? defaultProps[k] : config[k];
43
39
  }
44
40
  }
45
41
  if (children.length === 1) props.children = children[0];
46
42
  else if (children.length > 1) props.children = children;
47
- return { $$typeof: REACT_ELEMENT_TYPE, type: element.type, key, ref, props };
43
+ return { $$typeof: REACT_ELEMENT_TYPE, type: element.type, key, ref: props.ref === void 0 ? element.ref : props.ref, props };
48
44
  }
49
45
  function isValidElement(obj) {
50
46
  if (typeof obj !== "object" || obj === null) return false;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/react/element.ts"],
4
- "sourcesContent": ["import {\n REACT_ELEMENT_TYPE,\n REACT_LEGACY_ELEMENT_TYPE,\n REACT_FRAGMENT_TYPE,\n type ReactElement,\n type ReactNode,\n} from '../core'\n\nexport const Fragment = REACT_FRAGMENT_TYPE as unknown as (props: {\n children?: ReactNode\n}) => ReactElement\n\nconst RESERVED_PROPS: Record<string, 1> = { key: 1, ref: 1, __self: 1, __source: 1 }\n\nexport function createElement(\n type: any,\n config: Record<string, any> | null,\n ...children: ReactNode[]\n): ReactElement {\n let key: string | null = null\n let ref: any = null\n const props: Record<string, any> = {}\n\n if (config != null) {\n if (config.key !== undefined && config.key !== null) key = '' + config.key\n if (config.ref !== undefined) ref = config.ref\n for (const k in config) {\n if (!RESERVED_PROPS[k] && Object.prototype.hasOwnProperty.call(config, k)) {\n props[k] = config[k]\n }\n }\n }\n\n if (children.length === 1) props.children = children[0]\n else if (children.length > 1) props.children = children\n\n if (type && type.defaultProps) {\n const dp = type.defaultProps\n for (const k in dp) {\n if (props[k] === undefined) props[k] = dp[k]\n }\n }\n\n return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref, props }\n}\n\nexport function cloneElement(\n element: ReactElement,\n config: Record<string, any> | null,\n ...children: ReactNode[]\n): ReactElement {\n let key = element.key\n let ref = element.ref\n const props = { ...element.props }\n\n if (config != null) {\n if (config.ref !== undefined) ref = config.ref\n if (config.key !== undefined) key = '' + config.key\n const defaultProps = element.type?.defaultProps\n for (const k in config) {\n if (RESERVED_PROPS[k] || !Object.prototype.hasOwnProperty.call(config, k)) continue\n props[k] = config[k] === undefined && defaultProps ? defaultProps[k] : config[k]\n }\n }\n\n if (children.length === 1) props.children = children[0]\n else if (children.length > 1) props.children = children\n\n return { $$typeof: REACT_ELEMENT_TYPE, type: element.type, key, ref, props }\n}\n\nexport function isValidElement(obj: any): obj is ReactElement {\n if (typeof obj !== 'object' || obj === null) return false\n const t = obj.$$typeof\n return t === REACT_ELEMENT_TYPE || t === REACT_LEGACY_ELEMENT_TYPE\n}\n\nexport function createRef<T = any>() {\n return { current: null as T | null }\n}\n"],
5
- "mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAEA,IAAM,WAAW;AAIxB,IAAM,iBAAoC,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,UAAU,EAAE;AAE5E,SAAS,cACd,MACA,WACG,UACW;AACd,MAAI,MAAqB;AACzB,MAAI,MAAW;AACf,QAAM,QAA6B,CAAC;AAEpC,MAAI,UAAU,MAAM;AAClB,QAAI,OAAO,QAAQ,UAA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AAK,KAAK,MAAM;AAC7E;AAEO,SAAS,eAAe,KAA+B;AAC5D,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD,QAAM,IAAI,IAAI;AACd,SAAO,MAAM,sBAAsB,MAAM;AAC3C;AAEO,SAAS,YAAqB;AACnC,SAAO,EAAE,SAAS,KAAiB;AACrC;",
4
+ "sourcesContent": ["import {\n REACT_ELEMENT_TYPE,\n REACT_LEGACY_ELEMENT_TYPE,\n REACT_FRAGMENT_TYPE,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from '../core'\nimport type { FragmentInstance } from '../dom/fragment-instance'\n\nexport const Fragment = REACT_FRAGMENT_TYPE as unknown as (props: {\n children?: ReactNode\n key?: string | number\n ref?: Ref<FragmentInstance>\n}) => ReactElement\n\nexport function createElement(\n type: any,\n config?: Record<string, any> | null,\n ...children: ReactNode[]\n): ReactElement {\n let key: string | null = null\n const props: Record<string, any> = {}\n\n if (config != null) {\n if (config.key !== undefined && config.key !== null) key = '' + config.key\n for (const k in config) {\n if (k !== 'key' && k !== '__self' && k !== '__source' && Object.prototype.hasOwnProperty.call(config, k)) {\n props[k] = config[k]\n }\n }\n }\n\n if (children.length === 1) props.children = children[0]\n else if (children.length > 1) props.children = children\n\n if (type && type.defaultProps) {\n const dp = type.defaultProps\n for (const k in dp) {\n if (props[k] === undefined) props[k] = dp[k]\n }\n }\n\n return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref: props.ref ?? null, props }\n}\n\nexport function cloneElement(\n element: ReactElement,\n config?: Record<string, any> | null,\n ...children: ReactNode[]\n): ReactElement {\n let key = element.key\n const props = { ...element.props }\n\n if (config != null) {\n if (config.key !== undefined) key = '' + config.key\n const defaultProps = element.type?.defaultProps\n for (const k in config) {\n if (k === 'key' || k === '__self' || k === '__source' || !Object.prototype.hasOwnProperty.call(config, k)) continue\n if (k === 'ref' && config.ref === undefined) continue\n props[k] = config[k] === undefined && defaultProps ? defaultProps[k] : config[k]\n }\n }\n\n if (children.length === 1) props.children = children[0]\n else if (children.length > 1) props.children = children\n\n return { $$typeof: REACT_ELEMENT_TYPE, type: element.type, key, ref: props.ref === undefined ? element.ref : props.ref, props }\n}\n\nexport function isValidElement(obj: any): obj is ReactElement {\n if (typeof obj !== 'object' || obj === null) return false\n const t = obj.$$typeof\n return t === REACT_ELEMENT_TYPE || t === REACT_LEGACY_ELEMENT_TYPE\n}\n\nexport function createRef<T = any>() {\n return { current: null as T | null }\n}\n"],
5
+ "mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGA,IAAM,WAAW;AAMjB,SAAS,cACd,MACA,WACG,UACW;AACd,MAAI,MAAqB;AACzB,QAAM,QAA6B,CAAC;AAEpC,MAAI,UAAU,MAAM;AAClB,QAAI,OAAO,QAAQ,UAAa,OAAO,QAAQ,KAAM,OAAM,KAAK,OAAO;AACvE,eAAW,KAAK,QAAQ;AACtB,UAAI,MAAM,SAAS,MAAM,YAAY,MAAM,cAAc,OAAO,UAAU,eAAe,KAAK,QAAQ,CAAC,GAAG;AACxG,cAAM,CAAC,IAAI,OAAO,CAAC;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,SAAS,WAAW,EAAG,OAAM,WAAW,SAAS,CAAC;AAAA,WAC7C,SAAS,SAAS,EAAG,OAAM,WAAW;AAE/C,MAAI,QAAQ,KAAK,cAAc;AAC7B,UAAM,KAAK,KAAK;AAChB,eAAW,KAAK,IAAI;AAClB,UAAI,MAAM,CAAC,MAAM,OAAW,OAAM,CAAC,IAAI,GAAG,CAAC;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,oBAAoB,MAAM,KAAK,KAAK,MAAM,OAAO,MAAM,MAAM;AAClF;AAEO,SAAS,aACd,SACA,WACG,UACW;AACd,MAAI,MAAM,QAAQ;AAClB,QAAM,QAAQ,EAAE,GAAG,QAAQ,MAAM;AAEjC,MAAI,UAAU,MAAM;AAClB,QAAI,OAAO,QAAQ,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