@fluentui-react-native/framework-base 0.2.1 → 0.3.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 (187) hide show
  1. package/CHANGELOG.json +1 -1
  2. package/CHANGELOG.md +35 -2
  3. package/README.md +18 -1
  4. package/babel.config.js +1 -1
  5. package/jsx-runtime.js +1 -0
  6. package/lib/component-patterns/directComponent.d.ts +7 -0
  7. package/lib/component-patterns/directComponent.d.ts.map +1 -0
  8. package/lib/component-patterns/directComponent.js +8 -0
  9. package/lib/component-patterns/directComponent.js.map +1 -0
  10. package/lib/component-patterns/extract.d.ts +22 -0
  11. package/lib/component-patterns/extract.d.ts.map +1 -0
  12. package/lib/component-patterns/extract.js +25 -0
  13. package/lib/component-patterns/extract.js.map +1 -0
  14. package/lib/component-patterns/phasedComponent.d.ts +18 -0
  15. package/lib/component-patterns/phasedComponent.d.ts.map +1 -0
  16. package/lib/component-patterns/phasedComponent.js +51 -0
  17. package/lib/component-patterns/phasedComponent.js.map +1 -0
  18. package/lib/component-patterns/render.d.ts +9 -3
  19. package/lib/component-patterns/render.d.ts.map +1 -1
  20. package/lib/component-patterns/render.js +39 -32
  21. package/lib/component-patterns/render.js.map +1 -1
  22. package/lib/component-patterns/render.types.d.ts +60 -34
  23. package/lib/component-patterns/render.types.d.ts.map +1 -1
  24. package/lib/component-patterns/render.types.js +1 -1
  25. package/lib/component-patterns/stagedComponent.d.ts +3 -8
  26. package/lib/component-patterns/stagedComponent.d.ts.map +1 -1
  27. package/lib/component-patterns/stagedComponent.js +10 -27
  28. package/lib/component-patterns/stagedComponent.js.map +1 -1
  29. package/lib/component-patterns/withSlots.d.ts +6 -2
  30. package/lib/component-patterns/withSlots.d.ts.map +1 -1
  31. package/lib/component-patterns/withSlots.js +3 -3
  32. package/lib/component-patterns/withSlots.js.map +1 -1
  33. package/lib/immutable-merge/Merge.d.ts +6 -3
  34. package/lib/immutable-merge/Merge.js +79 -83
  35. package/lib/immutable-merge/Merge.js.map +1 -1
  36. package/lib/immutable-merge/Merge.test.d.ts +1 -1
  37. package/lib/immutable-merge/Merge.test.js +231 -219
  38. package/lib/immutable-merge/Merge.test.js.map +1 -1
  39. package/lib/index.d.ts +33 -5
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +13 -4
  42. package/lib/index.js.map +1 -1
  43. package/lib/jsx-namespace.d.ts +65 -0
  44. package/lib/jsx-namespace.d.ts.map +1 -0
  45. package/lib/jsx-namespace.js +2 -0
  46. package/lib/jsx-namespace.js.map +1 -0
  47. package/lib/jsx-runtime.d.ts +6 -4
  48. package/lib/jsx-runtime.d.ts.map +1 -1
  49. package/lib/jsx-runtime.js +9 -7
  50. package/lib/jsx-runtime.js.map +1 -1
  51. package/lib/memo-cache/getCacheEntry.d.ts +13 -13
  52. package/lib/memo-cache/getCacheEntry.js +20 -22
  53. package/lib/memo-cache/getCacheEntry.js.map +1 -1
  54. package/lib/memo-cache/getCacheEntry.test.d.ts +1 -1
  55. package/lib/memo-cache/getCacheEntry.test.js +90 -90
  56. package/lib/memo-cache/getCacheEntry.test.js.map +1 -1
  57. package/lib/memo-cache/getMemoCache.d.ts +1 -1
  58. package/lib/memo-cache/getMemoCache.js +11 -11
  59. package/lib/memo-cache/getMemoCache.js.map +1 -1
  60. package/lib/memo-cache/getMemoCache.test.d.ts +1 -1
  61. package/lib/memo-cache/getMemoCache.test.js +73 -73
  62. package/lib/memo-cache/getMemoCache.test.js.map +1 -1
  63. package/lib/memo-cache/memoize.d.ts +1 -1
  64. package/lib/memo-cache/memoize.js +9 -9
  65. package/lib/memo-cache/memoize.js.map +1 -1
  66. package/lib/memo-cache/memoize.test.d.ts +1 -1
  67. package/lib/memo-cache/memoize.test.js +36 -38
  68. package/lib/memo-cache/memoize.test.js.map +1 -1
  69. package/lib/merge-props/index.d.ts +1 -1
  70. package/lib/merge-props/index.js +1 -1
  71. package/lib/merge-props/mergeProps.d.ts +1 -1
  72. package/lib/merge-props/mergeProps.js +4 -4
  73. package/lib/merge-props/mergeProps.js.map +1 -1
  74. package/lib/merge-props/mergeStyles.d.ts +33 -4
  75. package/lib/merge-props/mergeStyles.d.ts.map +1 -1
  76. package/lib/merge-props/mergeStyles.js +16 -17
  77. package/lib/merge-props/mergeStyles.js.map +1 -1
  78. package/lib/merge-props/mergeStyles.test.d.ts +1 -1
  79. package/lib/merge-props/mergeStyles.test.js +75 -75
  80. package/lib/merge-props/mergeStyles.test.js.map +1 -1
  81. package/lib/merge-props/mergeStyles.types.d.ts +4 -4
  82. package/lib/merge-props/mergeStyles.types.d.ts.map +1 -1
  83. package/lib/merge-props/mergeStyles.types.js +1 -1
  84. package/lib/utilities/filterProps.d.ts +3 -0
  85. package/lib/utilities/filterProps.d.ts.map +1 -0
  86. package/lib/utilities/filterProps.js +12 -0
  87. package/lib/utilities/filterProps.js.map +1 -0
  88. package/lib-commonjs/component-patterns/directComponent.d.ts +7 -0
  89. package/lib-commonjs/component-patterns/directComponent.d.ts.map +1 -0
  90. package/lib-commonjs/component-patterns/directComponent.js +11 -0
  91. package/lib-commonjs/component-patterns/directComponent.js.map +1 -0
  92. package/lib-commonjs/component-patterns/extract.d.ts +22 -0
  93. package/lib-commonjs/component-patterns/extract.d.ts.map +1 -0
  94. package/lib-commonjs/component-patterns/extract.js +30 -0
  95. package/lib-commonjs/component-patterns/extract.js.map +1 -0
  96. package/lib-commonjs/component-patterns/phasedComponent.d.ts +18 -0
  97. package/lib-commonjs/component-patterns/phasedComponent.d.ts.map +1 -0
  98. package/lib-commonjs/component-patterns/phasedComponent.js +60 -0
  99. package/lib-commonjs/component-patterns/phasedComponent.js.map +1 -0
  100. package/lib-commonjs/component-patterns/render.d.ts +9 -3
  101. package/lib-commonjs/component-patterns/render.d.ts.map +1 -1
  102. package/lib-commonjs/component-patterns/render.js +101 -64
  103. package/lib-commonjs/component-patterns/render.js.map +1 -1
  104. package/lib-commonjs/component-patterns/render.types.d.ts +60 -34
  105. package/lib-commonjs/component-patterns/render.types.d.ts.map +1 -1
  106. package/lib-commonjs/component-patterns/render.types.js +3 -3
  107. package/lib-commonjs/component-patterns/stagedComponent.d.ts +3 -8
  108. package/lib-commonjs/component-patterns/stagedComponent.d.ts.map +1 -1
  109. package/lib-commonjs/component-patterns/stagedComponent.js +64 -56
  110. package/lib-commonjs/component-patterns/stagedComponent.js.map +1 -1
  111. package/lib-commonjs/component-patterns/withSlots.d.ts +6 -2
  112. package/lib-commonjs/component-patterns/withSlots.d.ts.map +1 -1
  113. package/lib-commonjs/component-patterns/withSlots.js +7 -8
  114. package/lib-commonjs/component-patterns/withSlots.js.map +1 -1
  115. package/lib-commonjs/immutable-merge/Merge.d.ts +6 -3
  116. package/lib-commonjs/immutable-merge/Merge.js +85 -90
  117. package/lib-commonjs/immutable-merge/Merge.js.map +1 -1
  118. package/lib-commonjs/immutable-merge/Merge.test.d.ts +1 -1
  119. package/lib-commonjs/immutable-merge/Merge.test.js +234 -222
  120. package/lib-commonjs/immutable-merge/Merge.test.js.map +1 -1
  121. package/lib-commonjs/index.d.ts +33 -5
  122. package/lib-commonjs/index.d.ts.map +1 -1
  123. package/lib-commonjs/index.js +184 -31
  124. package/lib-commonjs/index.js.map +1 -1
  125. package/lib-commonjs/jsx-namespace.d.ts +65 -0
  126. package/lib-commonjs/jsx-namespace.d.ts.map +1 -0
  127. package/lib-commonjs/jsx-namespace.js +3 -0
  128. package/lib-commonjs/jsx-namespace.js.map +1 -0
  129. package/lib-commonjs/jsx-runtime.d.ts +6 -4
  130. package/lib-commonjs/jsx-runtime.d.ts.map +1 -1
  131. package/lib-commonjs/jsx-runtime.js +69 -34
  132. package/lib-commonjs/jsx-runtime.js.map +1 -1
  133. package/lib-commonjs/memo-cache/getCacheEntry.d.ts +13 -13
  134. package/lib-commonjs/memo-cache/getCacheEntry.js +23 -26
  135. package/lib-commonjs/memo-cache/getCacheEntry.js.map +1 -1
  136. package/lib-commonjs/memo-cache/getCacheEntry.test.d.ts +1 -1
  137. package/lib-commonjs/memo-cache/getCacheEntry.test.js +93 -93
  138. package/lib-commonjs/memo-cache/getCacheEntry.test.js.map +1 -1
  139. package/lib-commonjs/memo-cache/getMemoCache.d.ts +1 -1
  140. package/lib-commonjs/memo-cache/getMemoCache.js +16 -17
  141. package/lib-commonjs/memo-cache/getMemoCache.js.map +1 -1
  142. package/lib-commonjs/memo-cache/getMemoCache.test.d.ts +1 -1
  143. package/lib-commonjs/memo-cache/getMemoCache.test.js +76 -76
  144. package/lib-commonjs/memo-cache/getMemoCache.test.js.map +1 -1
  145. package/lib-commonjs/memo-cache/memoize.d.ts +1 -1
  146. package/lib-commonjs/memo-cache/memoize.js +13 -14
  147. package/lib-commonjs/memo-cache/memoize.js.map +1 -1
  148. package/lib-commonjs/memo-cache/memoize.test.d.ts +1 -1
  149. package/lib-commonjs/memo-cache/memoize.test.js +39 -41
  150. package/lib-commonjs/memo-cache/memoize.test.js.map +1 -1
  151. package/lib-commonjs/merge-props/index.d.ts +1 -1
  152. package/lib-commonjs/merge-props/index.js +17 -7
  153. package/lib-commonjs/merge-props/index.js.map +1 -1
  154. package/lib-commonjs/merge-props/mergeProps.d.ts +1 -1
  155. package/lib-commonjs/merge-props/mergeProps.js +9 -10
  156. package/lib-commonjs/merge-props/mergeProps.js.map +1 -1
  157. package/lib-commonjs/merge-props/mergeStyles.d.ts +33 -4
  158. package/lib-commonjs/merge-props/mergeStyles.d.ts.map +1 -1
  159. package/lib-commonjs/merge-props/mergeStyles.js +23 -25
  160. package/lib-commonjs/merge-props/mergeStyles.js.map +1 -1
  161. package/lib-commonjs/merge-props/mergeStyles.test.d.ts +1 -1
  162. package/lib-commonjs/merge-props/mergeStyles.test.js +78 -78
  163. package/lib-commonjs/merge-props/mergeStyles.test.js.map +1 -1
  164. package/lib-commonjs/merge-props/mergeStyles.types.d.ts +4 -4
  165. package/lib-commonjs/merge-props/mergeStyles.types.d.ts.map +1 -1
  166. package/lib-commonjs/merge-props/mergeStyles.types.js +3 -3
  167. package/lib-commonjs/utilities/filterProps.d.ts +3 -0
  168. package/lib-commonjs/utilities/filterProps.d.ts.map +1 -0
  169. package/lib-commonjs/utilities/filterProps.js +15 -0
  170. package/lib-commonjs/utilities/filterProps.js.map +1 -0
  171. package/package.json +48 -26
  172. package/src/component-patterns/README.md +53 -16
  173. package/src/component-patterns/directComponent.ts +9 -0
  174. package/src/component-patterns/extract.ts +32 -0
  175. package/src/component-patterns/phasedComponent.ts +54 -0
  176. package/src/component-patterns/render.ts +21 -13
  177. package/src/component-patterns/render.types.ts +55 -30
  178. package/src/component-patterns/stagedComponent.ts +24 -0
  179. package/src/immutable-merge/Merge.test.ts +5 -1
  180. package/src/index.ts +27 -7
  181. package/src/jsx-namespace.ts +83 -0
  182. package/src/jsx-runtime.ts +8 -4
  183. package/src/memo-cache/README.md +1 -1
  184. package/src/merge-props/mergeStyles.ts +52 -4
  185. package/src/merge-props/mergeStyles.types.ts +2 -2
  186. package/src/utilities/filterProps.ts +14 -0
  187. package/src/component-patterns/stagedComponent.tsx +0 -45
package/CHANGELOG.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@fluentui-react-native/framework-base",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 05 Aug 2025 18:46:08 GMT",
5
+ "date": "Tue, 05 Aug 2025 18:50:43 GMT",
6
6
  "version": "0.2.1",
7
7
  "tag": "@fluentui-react-native/framework-base_v0.2.1",
8
8
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,45 @@
1
1
  # Change Log - @fluentui-react-native/framework-base
2
2
 
3
- <!-- This log was last generated on Tue, 05 Aug 2025 18:46:08 GMT and should not be manually modified. -->
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d7adbdd: # Migration from Beachball to Changesets
8
+
9
+ This changeset represents the migration from Beachball to Changesets for version management and consolidates all changes from 440+ beachball change files that were in the `change/` directory.
10
+
11
+ All 75 affected packages receive a minor version bump to acknowledge the accumulated changes from the beachball era.
12
+
13
+ ## What Changed
14
+
15
+ Going forward, all version management uses Changesets via `yarn changeset`. The following beachball infrastructure has been removed:
16
+
17
+ - ❌ 440+ beachball change files from `change/` directory
18
+ - ❌ `beachball` package dependency
19
+ - ❌ Beachball scripts from `package.json`
20
+ - ❌ `beachball.config.js` configuration file
21
+ - ❌ Beachball publish steps from Azure Pipelines
22
+
23
+ ## New Workflow
24
+
25
+ ✅ **Create changes**: Run `yarn changeset` to document changes
26
+ ✅ **Version bump PRs**: Automatically created by GitHub Actions
27
+ ✅ **Publishing**: Handled by Azure Pipelines using `changeset publish`
28
+ ✅ **Validation**: CI validates changesets and blocks major version bumps
29
+
30
+ For details, see `CHANGESETS_SETUP.md` and `CONTRIBUTING.md`.
31
+
32
+ ### Patch Changes
33
+
34
+ - d1d8c26: We were pinning @types/react and react-native-macos via resolutions. This fixes that which uncovered a bunch of type inconsistencies that needed to be addressed.
35
+
36
+ <!-- This log was last generated on Tue, 05 Aug 2025 18:50:43 GMT and should not be manually modified. -->
4
37
 
5
38
  <!-- Start content -->
6
39
 
7
40
  ## 0.2.1
8
41
 
9
- Tue, 05 Aug 2025 18:46:08 GMT
42
+ Tue, 05 Aug 2025 18:50:43 GMT
10
43
 
11
44
  ### Patches
12
45
 
package/README.md CHANGED
@@ -16,4 +16,21 @@ The shared patterns for rendering components, as well as the JSX handlers have b
16
16
 
17
17
  ## Type Helpers
18
18
 
19
- - TODO: There are a number of issues with the way types are handled in the larger fluentui-react-native project, helpers and core types will be added here to help solve inference issues, avoid hard typecasts, and help the project eventually move to typescript 5.x.
19
+ This package provides several TypeScript utility types:
20
+
21
+ - `PropsOf<TComponent>` - Extract props from a React component type
22
+ - `FunctionComponent<TProps>` - A function component type without the children handling complications of React.FC
23
+ - `DirectComponent<TProps>` - A function component marked for direct rendering
24
+ - `PhasedComponent<TProps>` - A component with two-phase rendering support
25
+ - `SlotFn<TProps>` - Slot function type used in the composition framework
26
+ - `FinalRender<TProps>` - The final rendering signature for phased components
27
+
28
+ ## JSX Runtime
29
+
30
+ This package exports a custom JSX runtime at `@fluentui-react-native/framework-base/jsx-runtime`. Use it in your component files with:
31
+
32
+ ```tsx
33
+ /** @jsxImportSource @fluentui-react-native/framework-base */
34
+ ```
35
+
36
+ The custom runtime enables automatic element flattening for direct and phased components.
package/babel.config.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('@fluentui-react-native/babel-config/babel.react.config.js');
1
+ module.exports = require('@fluentui-react-native/react-configs/babel.react.config.js');
package/jsx-runtime.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib-commonjs/jsx-runtime.js');
@@ -0,0 +1,7 @@
1
+ import type { FunctionComponent } from './render.types';
2
+ /**
3
+ * @param component functional component, usually a closure, to make into a direct component
4
+ * @return the same component with the direct component flag set, return type is a pure function component
5
+ */
6
+ export declare function directComponent<TProps>(component: FunctionComponent<TProps>): FunctionComponent<TProps>;
7
+ //# sourceMappingURL=directComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/directComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAEvG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @param component functional component, usually a closure, to make into a direct component
3
+ * @return the same component with the direct component flag set, return type is a pure function component
4
+ */
5
+ export function directComponent(component) {
6
+ return Object.assign(component, { _callDirect: true });
7
+ }
8
+ //# sourceMappingURL=directComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directComponent.js","sourceRoot":"","sources":["../../src/component-patterns/directComponent.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAS,SAAoC,EAA6B;IACvG,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AAAA,CACxD"}
@@ -0,0 +1,22 @@
1
+ import type { ViewStyle, TextStyle, ImageStyle } from 'react-native';
2
+ type StyleTypes = ViewStyle | TextStyle | ImageStyle;
3
+ /**
4
+ * Extract the props from a React element. If the element is undefined, undefined will be returned.
5
+ * @param element The React element from which to extract the props.
6
+ * @returns The extracted props or undefined if the element is undefined.
7
+ */
8
+ export declare function extractProps<T extends object>(element?: React.ReactElement): T | undefined;
9
+ /**
10
+ * Extract the children from a React element. If the element is undefined, undefined will be returned.
11
+ * @param element The React element from which to extract the children.
12
+ * @returns The extracted children or undefined if the element is undefined.
13
+ */
14
+ export declare function extractChildren(element?: React.ReactElement): React.ReactNode | undefined;
15
+ /**
16
+ * Extract a style object from a React element. If the element is undefined or does not have a style prop, an empty object will be returned.
17
+ * @param element The React element from which to extract the style.
18
+ * @returns The extracted style object or an empty object if not available.
19
+ */
20
+ export declare function extractStyle<T extends StyleTypes = ViewStyle>(element?: React.ReactElement): T;
21
+ export {};
22
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/component-patterns/extract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAErE,KAAK,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAIrD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,CAAC,GAAG,SAAS,CAE1F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,SAAS,GAAG,SAAS,CAEzF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,CAAC,CAE9F"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Extract the props from a React element. If the element is undefined, undefined will be returned.
3
+ * @param element The React element from which to extract the props.
4
+ * @returns The extracted props or undefined if the element is undefined.
5
+ */
6
+ export function extractProps(element) {
7
+ return element ? element.props : undefined;
8
+ }
9
+ /**
10
+ * Extract the children from a React element. If the element is undefined, undefined will be returned.
11
+ * @param element The React element from which to extract the children.
12
+ * @returns The extracted children or undefined if the element is undefined.
13
+ */
14
+ export function extractChildren(element) {
15
+ return extractProps(element)?.children;
16
+ }
17
+ /**
18
+ * Extract a style object from a React element. If the element is undefined or does not have a style prop, an empty object will be returned.
19
+ * @param element The React element from which to extract the style.
20
+ * @returns The extracted style object or an empty object if not available.
21
+ */
22
+ export function extractStyle(element) {
23
+ return extractProps(element)?.style ?? {};
24
+ }
25
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/component-patterns/extract.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAmB,OAA4B,EAAiB;IAC1F,OAAO,OAAO,CAAC,CAAC,CAAE,OAAO,CAAC,KAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CACnD;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAA4B,EAA+B;IACzF,OAAO,YAAY,CAAoB,OAAO,CAAC,EAAE,QAAQ,CAAC;AAAA,CAC3D;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAmC,OAA4B,EAAK;IAC9F,OAAQ,YAAY,CAAiB,OAAO,CAAC,EAAE,KAAW,IAAK,EAAQ,CAAC;AAAA,CACzE"}
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { PhasedRender, FunctionComponent } from './render.types';
3
+ /**
4
+ * Extract the phased render function from a component, if it has one.
5
+ * Handles both the newer PhasedComponent pattern (_phasedRender) and the legacy
6
+ * ComposableFunction pattern (_staged) for backward compatibility.
7
+ *
8
+ * @param component - The component to extract the phased render from
9
+ * @returns The phased render function if present, undefined otherwise
10
+ */
11
+ export declare function getPhasedRender<TProps>(component: React.ComponentType<TProps>): PhasedRender<TProps> | undefined;
12
+ /**
13
+ * Take a phased render function and make a real component out of it, attaching the phased render function
14
+ * so it can be split if used in that manner.
15
+ * @param getInnerPhase - phased render function to wrap into a staged component
16
+ */
17
+ export declare function phasedComponent<TProps>(getInnerPhase: PhasedRender<TProps>): FunctionComponent<TProps>;
18
+ //# sourceMappingURL=phasedComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phasedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/phasedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAuC,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAI3G;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,SAAS,CAuBhH;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAUtG"}
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { renderForJsxRuntime } from './render';
3
+ /**
4
+ * Extract the phased render function from a component, if it has one.
5
+ * Handles both the newer PhasedComponent pattern (_phasedRender) and the legacy
6
+ * ComposableFunction pattern (_staged) for backward compatibility.
7
+ *
8
+ * @param component - The component to extract the phased render from
9
+ * @returns The phased render function if present, undefined otherwise
10
+ */
11
+ export function getPhasedRender(component) {
12
+ // only a function component can have a phased render
13
+ if (typeof component === 'function') {
14
+ // if this has a phased render function, return it
15
+ if (component._phasedRender) {
16
+ return component._phasedRender;
17
+ } else if (component._staged) {
18
+ // for backward compatibility check for staged render and return a wrapper that maps the signature
19
+ const staged = component._staged;
20
+ return (props) => {
21
+ const { children, ...rest } = props;
22
+ const inner = staged(rest, ...React.Children.toArray(children));
23
+ // staged render functions were not consistently marking contents as composable, though they were treated
24
+ // as such in useHook. To maintain compatibility we mark the returned function as composable here. This was
25
+ // dangerous, but this shim is necessary for backward compatibility. The newer pattern is explicit about this.
26
+ if (typeof inner === 'function' && !inner._canCompose) {
27
+ return Object.assign(inner, { _canCompose: true });
28
+ }
29
+ return inner;
30
+ };
31
+ }
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * Take a phased render function and make a real component out of it, attaching the phased render function
37
+ * so it can be split if used in that manner.
38
+ * @param getInnerPhase - phased render function to wrap into a staged component
39
+ */
40
+ export function phasedComponent(getInnerPhase) {
41
+ return Object.assign(
42
+ (props) => {
43
+ // pull out children from props
44
+ const { children, ...outerProps } = props;
45
+ const Inner = getInnerPhase(outerProps);
46
+ return renderForJsxRuntime(Inner, { children });
47
+ },
48
+ { _phasedRender: getInnerPhase },
49
+ );
50
+ }
51
+ //# sourceMappingURL=phasedComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phasedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/phasedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG/C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAS,SAAsC,EAAoC;IAChH,qDAAqD;IACrD,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;QACpC,kDAAkD;QAClD,IAAK,SAAqC,CAAC,aAAa,EAAE,CAAC;YACzD,OAAQ,SAAqC,CAAC,aAAa,CAAC;QAC9D,CAAC;aAAM,IAAK,SAAwC,CAAC,OAAO,EAAE,CAAC;YAC7D,kGAAkG;YAClG,MAAM,MAAM,GAAI,SAAwC,CAAC,OAAO,CAAC;YACjE,OAAO,CAAC,KAAa,EAAE,EAAE,CAAC;gBACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAwC,CAAC;gBACvE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAc,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAC1E,yGAAyG;gBACzG,2GAA2G;gBAC3G,8GAA8G;gBAC9G,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,CAAE,KAAuC,CAAC,WAAW,EAAE,CAAC;oBACzF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;gBACrD,CAAC;gBACD,OAAO,KAAK,CAAC;YAAA,CACd,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CAClB;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAS,aAAmC,EAA6B;IACtG,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,KAAsC,EAAE,EAAE,CAAC;QAC1C,+BAA+B;QAC/B,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC;QAC1C,MAAM,KAAK,GAAG,aAAa,CAAC,UAAoB,CAAC,CAAC;QAClD,OAAO,mBAAmB,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAAA,CACjD,EACD,EAAE,aAAa,EAAE,aAAa,EAAE,CACjC,CAAC;AAAA,CACH"}
@@ -1,8 +1,14 @@
1
1
  import React from 'react';
2
2
  import * as ReactJSX from 'react/jsx-runtime';
3
- import type { RenderType, RenderResult } from './render.types';
3
+ import type { RenderType, RenderResult, DirectComponent } from './render.types';
4
4
  export type CustomRender = () => RenderResult;
5
- export declare function renderForJsxRuntime<TProps>(type: React.ElementType, props: React.PropsWithChildren<TProps>, key?: React.Key, jsxFn?: typeof ReactJSX.jsx): RenderResult;
5
+ export declare function asDirectComponent<TProps>(type: RenderType): DirectComponent<TProps> | undefined;
6
+ export declare function renderForJsxRuntime<TProps>(
7
+ type: React.ElementType,
8
+ props: React.PropsWithChildren<TProps>,
9
+ key?: React.Key,
10
+ jsxFn?: typeof ReactJSX.jsx,
11
+ ): RenderResult;
6
12
  export declare function renderForClassicRuntime<TProps>(type: RenderType, props: TProps, ...children: React.ReactNode[]): RenderResult;
7
13
  export declare const renderSlot: typeof renderForClassicRuntime;
8
- //# sourceMappingURL=render.d.ts.map
14
+ //# sourceMappingURL=render.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/component-patterns/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAA0C,MAAM,gBAAgB,CAAC;AAEvG,MAAM,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC;AAgB9C,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,IAAI,EAAE,KAAK,CAAC,WAAW,EACvB,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,EACtC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,EACf,KAAK,GAAE,OAAO,QAAQ,CAAC,GAAkB,GACxC,YAAY,CAad;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,YAAY,CAW7H;AAED,eAAO,MAAM,UAAU,gCAA0B,CAAC"}
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/component-patterns/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAyB,MAAM,gBAAgB,CAAC;AAEvG,MAAM,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC;AAE9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,SAAS,CAK/F;AASD,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,IAAI,EAAE,KAAK,CAAC,WAAW,EACvB,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,EACtC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,EACf,KAAK,GAAE,OAAO,QAAQ,CAAC,GAAe,GACrC,YAAY,CA4Bd;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,YAAY,CAI7H;AAED,eAAO,MAAM,UAAU,gCAA0B,CAAC"}
@@ -1,42 +1,49 @@
1
1
  import React from 'react';
2
2
  import * as ReactJSX from 'react/jsx-runtime';
3
- function asDirectComponent(type) {
4
- if (typeof type === 'function' && type._callDirect) {
5
- return type;
6
- }
7
- return undefined;
3
+ export function asDirectComponent(type) {
4
+ if (typeof type === 'function' && type._callDirect) {
5
+ return type;
6
+ }
7
+ return undefined;
8
8
  }
9
9
  function asLegacyDirectComponent(type) {
10
- if (typeof type === 'function' && type._canCompose) {
11
- return type;
12
- }
13
- return undefined;
10
+ if (typeof type === 'function' && type._canCompose) {
11
+ return type;
12
+ }
13
+ return undefined;
14
14
  }
15
- export function renderForJsxRuntime(type, props, key, jsxFn = ReactJSX.jsx) {
16
- const legacyDirect = asLegacyDirectComponent(type);
17
- if (legacyDirect) {
18
- const { children, ...rest } = props;
19
- const newProps = { ...rest, key };
20
- return legacyDirect(newProps, ...React.Children.toArray(children));
21
- }
22
- const directComponent = asDirectComponent(type);
23
- if (directComponent) {
24
- const newProps = { ...props, key };
25
- return directComponent(newProps);
15
+ export function renderForJsxRuntime(type, props, key, jsxFn = undefined) {
16
+ const legacyDirect = asLegacyDirectComponent(type);
17
+ if (legacyDirect) {
18
+ const { children, ...rest } = props;
19
+ const newProps = { ...rest, key };
20
+ return legacyDirect(newProps, ...React.Children.toArray(children));
21
+ }
22
+ const directComponent = asDirectComponent(type);
23
+ if (directComponent) {
24
+ const newProps = { ...props, key };
25
+ return directComponent(newProps);
26
+ }
27
+ // auto-detect whether to use jsx or jsxs based on number of children, 0 or 1 = jsx, more than 1 = jsxs
28
+ if (!jsxFn) {
29
+ if (React.Children.count(props.children) > 1) {
30
+ jsxFn = ReactJSX.jsxs;
31
+ } else {
32
+ jsxFn = ReactJSX.jsx;
26
33
  }
27
- return jsxFn(type, props, key);
34
+ }
35
+ // Extract key from props to avoid React 19 warning about spreading key prop
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ const { key: propsKey, ...propsWithoutKey } = props;
38
+ // Use explicitly passed key, or fall back to key from props
39
+ const finalKey = key ?? propsKey;
40
+ // now call the appropriate jsx function to render the component
41
+ return jsxFn(type, propsWithoutKey, finalKey);
28
42
  }
29
43
  export function renderForClassicRuntime(type, props, ...children) {
30
- const legacyDirect = asLegacyDirectComponent(type);
31
- if (legacyDirect) {
32
- return legacyDirect(props, ...children);
33
- }
34
- const directComponent = asDirectComponent(type);
35
- if (directComponent) {
36
- const newProps = { ...props, children };
37
- return directComponent(newProps);
38
- }
39
- return React.createElement(type, props, ...children);
44
+ // if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
45
+ const propsWithChildren = { children, ...props };
46
+ return renderForJsxRuntime(type, propsWithChildren);
40
47
  }
41
48
  export const renderSlot = renderForClassicRuntime;
42
- //# sourceMappingURL=render.js.map
49
+ //# sourceMappingURL=render.js.map
@@ -1 +1 @@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C,CAAC;AAAA,CAC1E;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAC"}
@@ -1,15 +1,19 @@
1
1
  import type React from 'react';
2
- import type ReactJSX from 'react/jsx-runtime';
2
+ import type { FurnJSX } from '../jsx-namespace';
3
3
  /**
4
4
  * Base types for rendering components in a react application, extracted from react types
5
5
  */
6
- export type RenderResult = ReturnType<typeof ReactJSX.jsx>;
7
- export type RenderType = Parameters<typeof ReactJSX.jsx>[0] | string;
6
+ export type RenderResult = FurnJSX.Element;
7
+ export type RenderType = FurnJSX.ElementType;
8
8
  /**
9
9
  * The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
10
10
  * it is what react accepts for React.createElement
11
11
  */
12
12
  export type NativeReactType = RenderType;
13
+ /**
14
+ * Get the props from a react component type
15
+ */
16
+ export type PropsOf<TComponent> = TComponent extends React.JSXElementConstructor<infer P> ? P : never;
13
17
  /**
14
18
  * DIRECT RENDERING
15
19
  *
@@ -25,74 +29,96 @@ export type NativeReactType = RenderType;
25
29
  /**
26
30
  * type of the render function, not a FunctionComponent to help prevent hook usage
27
31
  */
28
- export type DirectComponentFunction<TProps> = (props: TProps) => RenderResult;
32
+ export type FunctionComponentCore<TProps> = (props: TProps) => RenderResult;
33
+ /**
34
+ * A function component that returns an element type. This allows for the empty call props usage for native
35
+ * components, as well as handles the returns of React components.
36
+ */
37
+ export type FunctionComponent<TProps> = FunctionComponentCore<TProps> & {
38
+ displayName?: string;
39
+ };
29
40
  /**
30
41
  * The full component definition that has the attached properties to allow the jsx handlers to render it directly.
31
42
  */
32
- export type DirectComponent<TProps> = DirectComponentFunction<TProps> & {
33
- displayName?: string;
34
- _callDirect?: boolean;
43
+ export type DirectComponent<TProps> = FunctionComponentCore<TProps> & {
44
+ displayName?: string;
45
+ _callDirect?: boolean;
35
46
  };
47
+ type LegacyComponentFunction<TProps> = (props: TProps, ...children: React.ReactNode[]) => RenderResult;
36
48
  /**
37
49
  * Legacy slot function type, this allows the rendering handlers to bypass the normal JSX rendering and call the function
38
50
  * directly. This expects the function to have children as the last argument of the call which isn't consistent with standard
39
51
  * react usage, where children are passed as a prop. If writing new components use the DirectComponent type instead.
40
52
  * @deprecated use DirectComponent instead
41
53
  */
42
- export type LegacyDirectComponent<TProps> = React.FunctionComponent<TProps> & {
43
- _canCompose?: boolean;
54
+ export type LegacyDirectComponent<TProps> = LegacyComponentFunction<TProps> & {
55
+ _canCompose?: boolean;
44
56
  };
45
57
  /**
46
- * Legacy type name used for consistency with old rendering patterns.
58
+ * Slot function type used in the composition framework. Slot functions return React elements (not arbitrary ReactNode values)
59
+ * since they always either call staged render functions or React.createElement.
47
60
  */
48
- export type SlotFn<TProps> = LegacyDirectComponent<TProps>;
61
+ export type SlotFn<TProps> = {
62
+ (props: TProps, ...children: React.ReactNode[]): React.ReactElement | null;
63
+ _canCompose?: boolean;
64
+ };
49
65
  /**
50
- * MULTI-STAGE RENDERING
66
+ * PHASED RENDERING (formerly called "staged" or "two-stage" rendering)
51
67
  *
52
- * The above direct rendering pattern is useful for simple components, but it does not allow for hooks or complex logic. The staged render pattern allows
53
- * for a component to be rendered in two stages, allowing for hooks to be used in the first stage and then the second stage to be a simple render function that can
68
+ * The above direct rendering pattern is useful for simple components, but it does not allow for hooks or complex logic. The phased render pattern allows
69
+ * for a component to be rendered in two phases, allowing for hooks to be used in the first phase and then the second phase to be a simple render function that can
54
70
  * be called directly.
55
71
  *
56
- * In code that respects the pattern the first stage will be called with props (though children will not be present) and will return a function that will be called
57
- * with additional props, this time with children present. This allows for the first stage to handle all the logic and hooks, while the second stage can be a simple render function
72
+ * In code that respects the pattern, the first phase will be called with props (though children will not be present) and will return a function that will be called
73
+ * with additional props, this time with children present. This allows for the first phase to handle all the logic and hooks, while the second phase can be a simple render function
58
74
  * that can leverage direct rendering if supported.
59
75
  *
60
- * The component itself will be a FunctionComponent, but it will have an attached property that is the staged render function. This allows the component to be used in two
76
+ * The component itself will be a FunctionComponent, but it will have an attached property that is the phased render function. This allows the component to be used in two
61
77
  * parts via the useSlot hook, or to be used directly in JSX/TSX as a normal component.
62
78
  */
63
79
  /**
64
- * This is an updated version of the staged render that handles children and types more consistently. Generally children
65
- * will be passed as part of the props for component rendering, it is inconsistent to have them as a variable argument.
80
+ * Phased render function signature. This is the recommended pattern for components that need hooks.
81
+ *
82
+ * Phase 1 receives props (without children) and can use hooks to compute derived state.
83
+ * Phase 2 returns a component that will be called with props including children.
66
84
  *
67
- * The `children` prop will be automatically inferred and typed correctly by the prop type. Hooks are still expected
85
+ * Children will be passed as part of the props for component rendering. The `children` prop will be
86
+ * automatically inferred and typed correctly by the prop type.
68
87
  */
69
- export type TwoStageRender<TProps> = (props: TProps) => React.ComponentType<React.PropsWithChildren<TProps>>;
88
+ export type PhasedRender<TProps> = (props: TProps) => React.ComponentType<React.PropsWithChildren<TProps>>;
70
89
  /**
71
- * Component type for a component that can be rendered in two stages, with the attached render function.
90
+ * Component type for a component that can be rendered in two phases, with the attached phased render function.
91
+ * Use phasedComponent() to create these.
72
92
  */
73
- export type StagedComponent<TProps> = React.FunctionComponent<TProps> & {
74
- _twoStageRender?: TwoStageRender<TProps>;
93
+ export type PhasedComponent<TProps> = FunctionComponent<TProps> & {
94
+ _phasedRender?: PhasedRender<TProps>;
75
95
  };
76
96
  /**
77
- * The final rendering of the props in a staged render. This is the function component signature that matches that of
97
+ * The final rendering of the props in a phased render. This is the function component signature that matches that of
78
98
  * React.createElement, children (if present) will be part of the variable args at the end.
79
99
  */
80
- export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
100
+ export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => FurnJSX.Element | null;
81
101
  /**
82
- * Signature for a staged render function.
83
- * @deprecated Use TwoStageRender instead
102
+ * Legacy staged render function signature.
103
+ * @deprecated Use PhasedRender instead. This older pattern splits children from props which is inconsistent with React conventions.
84
104
  */
85
105
  export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
86
106
  /**
87
- * Signature for a component that uses the staged render pattern.
88
- * @deprecated Use TwoStageRender instead
107
+ * Legacy component type that uses the staged render pattern.
108
+ * @deprecated Use PhasedComponent instead. Create with phasedComponent() rather than stagedComponent().
89
109
  */
90
- export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & {
91
- _staged?: StagedRender<TProps>;
110
+ export type ComposableFunction<TProps> = FunctionComponent<TProps> & {
111
+ _staged?: StagedRender<TProps>;
92
112
  };
93
113
  /**
94
114
  * A type aggregating all the custom types that can be used in the render process.
95
115
  * @internal only used in this package, should not be exported
96
116
  */
97
- export type AnyCustomType<TProps> = React.FunctionComponent<TProps> | DirectComponent<TProps> | StagedComponent<TProps> | ComposableFunction<TProps> | LegacyDirectComponent<TProps>;
98
- //# sourceMappingURL=render.types.d.ts.map
117
+ export type AnyCustomType<TProps> =
118
+ | React.FunctionComponent<TProps>
119
+ | DirectComponent<TProps>
120
+ | PhasedComponent<TProps>
121
+ | ComposableFunction<TProps>
122
+ | LegacyDirectComponent<TProps>;
123
+ export {};
124
+ //# sourceMappingURL=render.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.types.d.ts","sourceRoot":"","sources":["../../src/component-patterns/render.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC;AAEzC;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH,MAAM,MAAM,uBAAuB,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MA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AM,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAExG;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,IAC5B,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAC/B,eAAe,CAAC,MAAM,CAAC,GACvB,eAAe,CAAC,MAAM,CAAC,GACvB,kBAAkB,CAAC,MAAM,CAAC,GAC1B,qBAAqB,CAAC,MAAM,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=render.types.js.map
2
+ //# sourceMappingURL=render.types.js.map
@@ -1,15 +1,10 @@
1
- import type { StagedComponent, TwoStageRender, StagedRender, ComposableFunction } from './render.types';
1
+ import type { StagedRender, ComposableFunction } from './render.types';
2
2
  /**
3
3
  * Take a staged render function and make a real component out of it
4
4
  *
5
5
  * @param staged - staged render function to wrap into a staged component
6
6
  * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
7
+ * @deprecated Use phasedComponent from phasedComponent.ts instead
7
8
  */
8
9
  export declare function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps>;
9
- /**
10
- * Take a two stage render function and make a real component out of it, attaching the staged render function
11
- * so it can be split if used in that manner.
12
- * @param staged - two stage render function to wrap into a staged component
13
- */
14
- export declare function twoStageComponent<TProps>(staged: TwoStageRender<TProps>): StagedComponent<TProps>;
15
- //# sourceMappingURL=stagedComponent.d.ts.map
10
+ //# sourceMappingURL=stagedComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stagedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMxG;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAQhH;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAUjG"}
1
+ {"version":3,"file":"stagedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMvE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAQhH"}
@@ -1,38 +1,21 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx withSlots
4
- */
5
1
  import * as React from 'react';
6
- import { withSlots } from './withSlots';
7
2
  function asArray(val) {
8
- return Array.isArray(val) ? val : [val];
3
+ return Array.isArray(val) ? val : [val];
9
4
  }
10
5
  /**
11
6
  * Take a staged render function and make a real component out of it
12
7
  *
13
8
  * @param staged - staged render function to wrap into a staged component
14
9
  * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
10
+ * @deprecated Use phasedComponent from phasedComponent.ts instead
15
11
  */
16
12
  export function stagedComponent(staged, memo) {
17
- const component = (props) => {
18
- const { children, ...rest } = props;
19
- return staged(rest)({}, asArray(children));
20
- };
21
- const stagedComponent = memo ? React.memo(component) : component;
22
- Object.assign(stagedComponent, { _staged: staged });
23
- return stagedComponent;
24
- }
25
- /**
26
- * Take a two stage render function and make a real component out of it, attaching the staged render function
27
- * so it can be split if used in that manner.
28
- * @param staged - two stage render function to wrap into a staged component
29
- */
30
- export function twoStageComponent(staged) {
31
- return Object.assign((props) => {
32
- const { children, ...outerProps } = props;
33
- const innerProps = { children };
34
- const Inner = staged(outerProps);
35
- return withSlots(Inner, { ...innerProps });
36
- }, { _twoStageRender: staged });
13
+ const component = (props) => {
14
+ const { children, ...rest } = props;
15
+ return staged(rest)({}, asArray(children));
16
+ };
17
+ const stagedComponent = memo ? React.memo(component) : component;
18
+ Object.assign(stagedComponent, { _staged: staged });
19
+ return stagedComponent;
37
20
  }
38
- //# sourceMappingURL=stagedComponent.js.map
21
+ //# sourceMappingURL=stagedComponent.js.map