@office-iss/react-native-win32 0.72.6 → 0.73.0-preview.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 (272) hide show
  1. package/.flowconfig +15 -4
  2. package/CHANGELOG.json +531 -87
  3. package/CHANGELOG.md +213 -48
  4. package/IntegrationTests/PromiseTest.js +1 -0
  5. package/IntegrationTests/websocket_integration_test_server.js +1 -1
  6. package/Libraries/Animated/Animated.js +1 -1
  7. package/Libraries/Animated/AnimatedImplementation.js +1 -1
  8. package/Libraries/Animated/NativeAnimatedHelper.js +14 -10
  9. package/Libraries/Animated/NativeAnimatedHelper.win32.js +16 -12
  10. package/Libraries/Animated/NativeAnimatedModule.js +6 -2
  11. package/Libraries/Animated/NativeAnimatedTurboModule.js +7 -4
  12. package/Libraries/Animated/animations/Animation.js +57 -3
  13. package/Libraries/Animated/animations/DecayAnimation.js +9 -0
  14. package/Libraries/Animated/animations/SpringAnimation.js +8 -0
  15. package/Libraries/Animated/animations/TimingAnimation.js +8 -0
  16. package/Libraries/Animated/components/AnimatedFlatList.js +2 -1
  17. package/Libraries/Animated/components/AnimatedScrollView.js +2 -0
  18. package/Libraries/Animated/components/AnimatedSectionList.js +2 -1
  19. package/Libraries/Animated/createAnimatedComponent.js +1 -0
  20. package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
  21. package/Libraries/Animated/nodes/AnimatedObject.js +146 -0
  22. package/Libraries/Animated/nodes/AnimatedProps.js +19 -7
  23. package/Libraries/Animated/nodes/AnimatedStyle.js +29 -55
  24. package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -17
  25. package/Libraries/Animated/shouldUseTurboAnimatedModule.js +17 -0
  26. package/Libraries/Animated/useAnimatedProps.js +9 -10
  27. package/Libraries/AppState/AppState.d.ts +1 -1
  28. package/Libraries/AppState/NativeAppState.js +8 -4
  29. package/Libraries/BatchedBridge/MessageQueue.js +45 -36
  30. package/Libraries/Blob/Blob.js +6 -2
  31. package/Libraries/Blob/BlobManager.js +9 -10
  32. package/Libraries/Blob/BlobRegistry.js +14 -9
  33. package/Libraries/Blob/File.js +1 -1
  34. package/Libraries/Blob/FileReader.js +1 -2
  35. package/Libraries/Components/Button/ButtonWin32.Props.d.ts +1 -1
  36. package/Libraries/Components/Button/ButtonWin32.Props.js.map +1 -1
  37. package/Libraries/Components/Button/ButtonWin32.d.ts +1 -1
  38. package/Libraries/Components/Button/ButtonWin32.js +1 -4
  39. package/Libraries/Components/Button/ButtonWin32.js.map +1 -1
  40. package/Libraries/Components/Clipboard/Clipboard.d.ts +4 -4
  41. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +3 -1
  42. package/Libraries/Components/EnterString.win32.d.ts +1 -1
  43. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +26 -6
  44. package/Libraries/Components/Pressable/Pressable.js +3 -2
  45. package/Libraries/Components/Pressable/Pressable.win32.js +4 -3
  46. package/Libraries/Components/Pressable/useAndroidRippleForView.js +1 -1
  47. package/Libraries/Components/SafeAreaView/SafeAreaView.js +7 -7
  48. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +7 -8
  49. package/Libraries/Components/ScrollView/ScrollView.js +3 -1
  50. package/Libraries/Components/ScrollView/ScrollView.win32.js +3 -1
  51. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +39 -46
  52. package/Libraries/Components/Switch/Switch.js +1 -0
  53. package/Libraries/Components/Text/TextWin32.d.ts +1 -1
  54. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  55. package/Libraries/Components/TextInput/TextInput.d.ts +49 -7
  56. package/Libraries/Components/TextInput/TextInput.flow.js +43 -10
  57. package/Libraries/Components/TextInput/TextInput.js +62 -10
  58. package/Libraries/Components/TextInput/TextInput.win32.js +953 -206
  59. package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +23 -0
  60. package/Libraries/Components/ToastAndroid/{ToastAndroid.ios.js → ToastAndroid.js} +9 -1
  61. package/Libraries/Components/ToastAndroid/ToastAndroid.win32.js +9 -1
  62. package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js +2 -2
  63. package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js.map +1 -1
  64. package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
  65. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  66. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
  67. package/Libraries/Components/Touchable/TouchableOpacity.js +4 -1
  68. package/Libraries/Components/Touchable/TouchableWin32.d.ts +1 -1
  69. package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
  70. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +1 -0
  71. package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js +16 -6
  72. package/Libraries/Components/View/ReactNativeStyleAttributes.js +9 -0
  73. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  74. package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +1 -0
  75. package/Libraries/Components/View/View.js +46 -32
  76. package/Libraries/Components/View/View.win32.js +37 -6
  77. package/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
  78. package/Libraries/Components/View/ViewNativeComponent.js +1 -0
  79. package/Libraries/Components/View/ViewPropTypes.js +18 -3
  80. package/Libraries/Components/View/ViewPropTypes.win32.js +30 -4
  81. package/Libraries/Components/View/ViewWin32.js +3 -2
  82. package/Libraries/Core/Devtools/loadBundleFromServer.js +152 -0
  83. package/Libraries/Core/Devtools/symbolicateStackTrace.js +2 -1
  84. package/Libraries/Core/ExceptionsManager.js +16 -7
  85. package/Libraries/Core/ExtendedError.js +12 -0
  86. package/Libraries/Core/ReactNativeVersion.js +3 -3
  87. package/Libraries/Core/ReactNativeVersionCheck.js +0 -2
  88. package/Libraries/Core/ReactNativeVersionCheck.win32.js +0 -2
  89. package/Libraries/Core/__mocks__/NativeExceptionsManager.js +20 -0
  90. package/Libraries/Core/setUpDeveloperTools.js +5 -1
  91. package/Libraries/Core/setUpIntersectionObserver.js +16 -0
  92. package/Libraries/{Components/ProgressBarAndroid/ProgressBarAndroid.ios.js → Core/setUpMutationObserver.js} +6 -2
  93. package/Libraries/Core/setUpPerformance.js +6 -13
  94. package/Libraries/Core/setUpPerformanceObserver.js +16 -0
  95. package/Libraries/Core/setUpRegeneratorRuntime.js +4 -2
  96. package/Libraries/DOM/Nodes/ReactNativeElement.js +135 -18
  97. package/Libraries/DOM/Nodes/ReadOnlyCharacterData.js +72 -0
  98. package/Libraries/DOM/Nodes/ReadOnlyElement.js +209 -21
  99. package/Libraries/DOM/Nodes/ReadOnlyNode.js +206 -17
  100. package/Libraries/DOM/Nodes/ReadOnlyText.js +30 -0
  101. package/Libraries/DOM/Nodes/Utilities/Traversal.js +54 -0
  102. package/Libraries/EventEmitter/NativeEventEmitter.d.ts +0 -6
  103. package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +15 -4
  104. package/Libraries/Image/Image.android.js +8 -2
  105. package/Libraries/Image/Image.d.ts +1 -1
  106. package/Libraries/Image/Image.ios.js +4 -1
  107. package/Libraries/Image/Image.win32.js +6 -3
  108. package/Libraries/Image/ImageBackground.js +3 -0
  109. package/Libraries/Image/resolveAssetSource.win32.js +1 -1
  110. package/Libraries/Inspector/DevtoolsOverlay.js +6 -3
  111. package/Libraries/Inspector/NetworkOverlay.js +2 -2
  112. package/Libraries/Interaction/JSEventLoopWatchdog.js +1 -5
  113. package/Libraries/Interaction/PanResponder.js +1 -4
  114. package/Libraries/IntersectionObserver/IntersectionObserver.js +252 -0
  115. package/Libraries/IntersectionObserver/IntersectionObserverEntry.js +140 -0
  116. package/Libraries/IntersectionObserver/IntersectionObserverManager.js +221 -0
  117. package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +41 -0
  118. package/Libraries/IntersectionObserver/__mocks__/NativeIntersectionObserver.js +162 -0
  119. package/Libraries/LayoutAnimation/LayoutAnimation.js +1 -1
  120. package/Libraries/Lists/FlatList.d.ts +2 -1
  121. package/Libraries/Lists/FlatList.js +15 -5
  122. package/Libraries/Lists/SectionList.js +4 -0
  123. package/Libraries/LogBox/Data/LogBoxLog.js +4 -1
  124. package/Libraries/LogBox/Data/LogBoxSymbolication.js +5 -2
  125. package/Libraries/LogBox/Data/parseLogBoxLog.js +57 -20
  126. package/Libraries/LogBox/UI/AnsiHighlight.js +1 -1
  127. package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +24 -31
  128. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +1 -1
  129. package/Libraries/LogBox/UI/LogBoxMessage.js +4 -7
  130. package/Libraries/MutationObserver/MutationObserver.js +184 -0
  131. package/Libraries/MutationObserver/MutationObserverManager.js +218 -0
  132. package/Libraries/MutationObserver/MutationRecord.js +82 -0
  133. package/Libraries/MutationObserver/NativeMutationObserver.js +58 -0
  134. package/Libraries/MutationObserver/__mocks__/NativeMutationObserver.js +327 -0
  135. package/Libraries/NativeComponent/BaseViewConfig.android.js +18 -3
  136. package/Libraries/NativeComponent/BaseViewConfig.ios.js +33 -0
  137. package/Libraries/NativeComponent/BaseViewConfig.win32.js +33 -0
  138. package/Libraries/NativeComponent/NativeComponentRegistry.js +3 -5
  139. package/Libraries/NativeModules/specs/NativeSourceCode.js +6 -6
  140. package/Libraries/Network/RCTNetworking.android.js +2 -1
  141. package/Libraries/Network/XMLHttpRequest.js +1 -1
  142. package/Libraries/NewAppScreen/components/DebugInstructions.js +4 -4
  143. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +9 -2
  144. package/Libraries/Performance/QuickPerformanceLogger.js +1 -1
  145. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +1 -0
  146. package/Libraries/PermissionsAndroid/PermissionsAndroid.d.ts +1 -0
  147. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +3 -1
  148. package/Libraries/Pressability/Pressability.js +28 -3
  149. package/Libraries/Pressability/Pressability.win32.js +30 -5
  150. package/Libraries/ReactNative/AppContainer.js +2 -3
  151. package/Libraries/ReactNative/AppRegistry.d.ts +0 -5
  152. package/Libraries/ReactNative/AppRegistry.js +66 -53
  153. package/Libraries/ReactNative/BridgelessUIManager.js +38 -9
  154. package/Libraries/ReactNative/FabricUIManager.js +143 -34
  155. package/Libraries/ReactNative/I18nManager.js +5 -11
  156. package/Libraries/ReactNative/NativeI18nManager.js +7 -5
  157. package/Libraries/ReactNative/PaperUIManager.win32.js +2 -2
  158. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +151 -0
  159. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +81 -0
  160. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload.js +492 -0
  161. package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +32 -0
  162. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +19 -3
  163. package/Libraries/ReactNative/UIManager.js +8 -0
  164. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +648 -0
  165. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +38 -2
  166. package/Libraries/Renderer/implementations/ReactFabric-dev.js +27 -27
  167. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3 -3
  168. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3 -3
  169. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +27 -27
  170. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3 -3
  171. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3 -3
  172. package/Libraries/Renderer/shims/ReactFabric.js +5 -6
  173. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -3
  174. package/Libraries/Renderer/shims/ReactNative.js +2 -3
  175. package/Libraries/Renderer/shims/ReactNativeTypes.js +35 -17
  176. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -3
  177. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -3
  178. package/Libraries/Settings/{Settings.android.js → Settings.js} +4 -4
  179. package/Libraries/Share/Share.d.ts +3 -9
  180. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +9 -4
  181. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +28 -13
  182. package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +14 -4
  183. package/Libraries/StyleSheet/PlatformColorValueTypesIOS.ios.js +1 -1
  184. package/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
  185. package/Libraries/StyleSheet/StyleSheet.d.ts +10 -1
  186. package/Libraries/StyleSheet/StyleSheet.js +3 -0
  187. package/Libraries/StyleSheet/StyleSheet.win32.js +3 -0
  188. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +31 -17
  189. package/Libraries/StyleSheet/StyleSheetTypes.js +90 -6
  190. package/Libraries/StyleSheet/flattenStyle.js +4 -0
  191. package/Libraries/StyleSheet/private/_TransformStyle.js +16 -2
  192. package/Libraries/StyleSheet/processColor.js +1 -2
  193. package/Libraries/StyleSheet/processTransformOrigin.js +136 -0
  194. package/Libraries/StyleSheet/splitLayoutProps.js +1 -0
  195. package/Libraries/Text/Text.d.ts +5 -5
  196. package/Libraries/Text/Text.js +17 -10
  197. package/Libraries/Text/Text.win32.js +354 -0
  198. package/Libraries/Text/TextProps.win32.js +281 -0
  199. package/Libraries/TurboModule/TurboModuleRegistry.js +47 -7
  200. package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +6 -0
  201. package/Libraries/Types/CoreEventTypes.d.ts +5 -2
  202. package/Libraries/Utilities/GlobalPerformanceLogger.js +2 -12
  203. package/Libraries/Utilities/NativeDeviceInfo.js +8 -9
  204. package/Libraries/Utilities/NativePlatformConstantsAndroid.js +23 -18
  205. package/Libraries/Utilities/NativePlatformConstantsIOS.js +16 -13
  206. package/Libraries/Utilities/NativePlatformConstantsWin.js +13 -10
  207. package/Libraries/Utilities/PerformanceLoggerContext.js +1 -1
  208. package/Libraries/Utilities/Platform.android.js +12 -8
  209. package/Libraries/Utilities/Platform.d.ts +1 -0
  210. package/Libraries/Utilities/Platform.flow.js +84 -0
  211. package/Libraries/Utilities/Platform.flow.win32.js +111 -0
  212. package/Libraries/Utilities/Platform.ios.js +12 -8
  213. package/Libraries/Utilities/Platform.win32.js +12 -8
  214. package/Libraries/Utilities/PolyfillFunctions.js +1 -1
  215. package/Libraries/Utilities/ReactNativeTestTools.js +1 -2
  216. package/Libraries/Utilities/SceneTracker.js +1 -1
  217. package/Libraries/Utilities/createPerformanceLogger.js +63 -32
  218. package/Libraries/Utilities/useColorScheme.js +7 -8
  219. package/Libraries/WebPerformance/MemoryInfo.js +1 -1
  220. package/Libraries/WebPerformance/NativePerformance.js +3 -8
  221. package/Libraries/WebPerformance/NativePerformanceObserver.js +4 -0
  222. package/Libraries/WebPerformance/Performance.js +42 -15
  223. package/Libraries/WebPerformance/PerformanceEntry.js +14 -6
  224. package/Libraries/WebPerformance/PerformanceEventTiming.js +18 -1
  225. package/Libraries/WebPerformance/ReactNativeStartupTiming.js +40 -14
  226. package/Libraries/WebPerformance/__mocks__/NativePerformance.js +4 -2
  227. package/Libraries/WebPerformance/__mocks__/NativePerformanceObserver.js +21 -3
  228. package/Libraries/promiseRejectionTrackingOptions.js +1 -3
  229. package/Libraries/vendor/emitter/EventEmitter.js +20 -18
  230. package/flow/global.js +1 -3
  231. package/flow/jest.js +5 -1
  232. package/{Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.ios.js → jest/ReactNativeInternalFeatureFlagsMock.js} +2 -1
  233. package/jest/__tests__/setup-test.js +18 -0
  234. package/jest/mockModal.js +6 -4
  235. package/jest/setup.js +61 -30
  236. package/jest.config.js +1 -1
  237. package/just-task.js +1 -0
  238. package/overrides.json +51 -46
  239. package/package.json +35 -33
  240. package/src/Libraries/Components/Button/ButtonWin32.Props.ts +1 -1
  241. package/src/Libraries/Components/Button/ButtonWin32.tsx +0 -2
  242. package/src/Libraries/Components/Touchable/Tests/TouchableWin32Test.tsx +2 -2
  243. package/src/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
  244. package/src/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
  245. package/src/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
  246. package/types/experimental.d.ts +44 -0
  247. package/types/index.d.ts +2 -1
  248. package/types/modules/Devtools.d.ts +1 -0
  249. package/types/modules/globals.d.ts +16 -1
  250. package/IntegrationTests/BUCK +0 -32
  251. package/IntegrationTests/PropertiesUpdateTest.js +0 -29
  252. package/IntegrationTests/RCTRootViewIntegrationTestApp.js +0 -86
  253. package/IntegrationTests/ReactContentSizeUpdateTest.js +0 -89
  254. package/IntegrationTests/SizeFlexibilityUpdateTest.js +0 -106
  255. package/Libraries/Components/TextInput/TextInput.Types.win32.d.ts +0 -51
  256. package/Libraries/Components/TextInput/TextInput.Types.win32.js +0 -3
  257. package/Libraries/Components/TextInput/TextInput.Types.win32.js.map +0 -1
  258. package/Libraries/Utilities/AcessibilityMapping.js +0 -154
  259. package/Libraries/Utilities/AcessibilityMapping.win32.js +0 -156
  260. package/Libraries/Utilities/NativeDevSplitBundleLoader.js +0 -19
  261. package/Libraries/Utilities/useColorScheme.win32.js +0 -26
  262. package/flow/use-sync-external-store.js +0 -20
  263. package/flow-typed/npm/base64-js_v1.x.x.js +0 -12
  264. package/flow-typed/npm/glob_v7.x.x.js +0 -79
  265. package/flow-typed/npm/pretty-format_v26.x.x.js +0 -49
  266. package/flow-typed/npm/promise_v8.x.x.js +0 -30
  267. package/flow-typed/npm/react-dom_v17.x.x.js +0 -139
  268. package/flow-typed/npm/react-test-renderer_v16.x.x.js +0 -79
  269. package/flow-typed/npm/stacktrace-parser_v0.1.x.js +0 -17
  270. package/flow-typed/npm/yargs_v17.x.x.js +0 -341
  271. package/src/Libraries/Components/TextInput/TextInput.Types.win32.ts +0 -68
  272. /package/Libraries/{Renderer/public → ReactNative/ReactFabricPublicInstance}/ReactFabricPublicInstanceUtils.js +0 -0
@@ -5,85 +5,273 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @format
8
- * @flow strict
8
+ * @flow strict-local
9
9
  */
10
10
 
11
11
  // flowlint unsafe-getters-setters:off
12
12
 
13
13
  import type HTMLCollection from '../OldStyleCollections/HTMLCollection';
14
14
 
15
- import ReadOnlyNode from './ReadOnlyNode';
15
+ import {getFabricUIManager} from '../../ReactNative/FabricUIManager';
16
+ import DOMRect from '../Geometry/DOMRect';
17
+ import {createHTMLCollection} from '../OldStyleCollections/HTMLCollection';
18
+ import ReadOnlyNode, {
19
+ getChildNodes,
20
+ getInstanceHandle,
21
+ getShadowNode,
22
+ } from './ReadOnlyNode';
23
+ import {getElementSibling} from './Utilities/Traversal';
24
+ import nullthrows from 'nullthrows';
16
25
 
17
26
  export default class ReadOnlyElement extends ReadOnlyNode {
18
27
  get childElementCount(): number {
19
- throw new TypeError('Unimplemented');
28
+ return getChildElements(this).length;
20
29
  }
21
30
 
22
31
  get children(): HTMLCollection<ReadOnlyElement> {
23
- throw new TypeError('Unimplemented');
32
+ return createHTMLCollection(getChildElements(this));
24
33
  }
25
34
 
26
35
  get clientHeight(): number {
27
- throw new TypeError('Unimplemented');
36
+ const node = getShadowNode(this);
37
+
38
+ if (node != null) {
39
+ const innerSize = nullthrows(getFabricUIManager()).getInnerSize(node);
40
+ if (innerSize != null) {
41
+ return innerSize[1];
42
+ }
43
+ }
44
+
45
+ return 0;
28
46
  }
29
47
 
30
48
  get clientLeft(): number {
31
- throw new TypeError('Unimplemented');
49
+ const node = getShadowNode(this);
50
+
51
+ if (node != null) {
52
+ const borderSize = nullthrows(getFabricUIManager()).getBorderSize(node);
53
+ if (borderSize != null) {
54
+ return borderSize[3];
55
+ }
56
+ }
57
+
58
+ return 0;
32
59
  }
33
60
 
34
61
  get clientTop(): number {
35
- throw new TypeError('Unimplemented');
62
+ const node = getShadowNode(this);
63
+
64
+ if (node != null) {
65
+ const borderSize = nullthrows(getFabricUIManager()).getBorderSize(node);
66
+ if (borderSize != null) {
67
+ return borderSize[0];
68
+ }
69
+ }
70
+
71
+ return 0;
36
72
  }
37
73
 
38
74
  get clientWidth(): number {
39
- throw new TypeError('Unimplemented');
75
+ const node = getShadowNode(this);
76
+
77
+ if (node != null) {
78
+ const innerSize = nullthrows(getFabricUIManager()).getInnerSize(node);
79
+ if (innerSize != null) {
80
+ return innerSize[0];
81
+ }
82
+ }
83
+
84
+ return 0;
40
85
  }
41
86
 
42
87
  get firstElementChild(): ReadOnlyElement | null {
43
- throw new TypeError('Unimplemented');
88
+ const childElements = getChildElements(this);
89
+
90
+ if (childElements.length === 0) {
91
+ return null;
92
+ }
93
+
94
+ return childElements[0];
44
95
  }
45
96
 
46
97
  get id(): string {
47
- throw new TypeError('Unimplemented');
98
+ const instanceHandle = getInstanceHandle(this);
99
+ // TODO: migrate off this private React API
100
+ // $FlowExpectedError[incompatible-use]
101
+ const props = instanceHandle?.stateNode?.canonical?.currentProps;
102
+ return props?.id ?? props?.nativeID ?? '';
48
103
  }
49
104
 
50
105
  get lastElementChild(): ReadOnlyElement | null {
51
- throw new TypeError('Unimplemented');
106
+ const childElements = getChildElements(this);
107
+
108
+ if (childElements.length === 0) {
109
+ return null;
110
+ }
111
+
112
+ return childElements[childElements.length - 1];
52
113
  }
53
114
 
54
115
  get nextElementSibling(): ReadOnlyElement | null {
55
- throw new TypeError('Unimplemented');
116
+ return getElementSibling(this, 'next');
56
117
  }
57
118
 
119
+ get nodeName(): string {
120
+ return this.tagName;
121
+ }
122
+
123
+ get nodeType(): number {
124
+ return ReadOnlyNode.ELEMENT_NODE;
125
+ }
126
+
127
+ get nodeValue(): string | null {
128
+ return null;
129
+ }
130
+
131
+ set nodeValue(value: string): void {}
132
+
58
133
  get previousElementSibling(): ReadOnlyElement | null {
59
- throw new TypeError('Unimplemented');
134
+ return getElementSibling(this, 'previous');
60
135
  }
61
136
 
62
137
  get scrollHeight(): number {
63
- throw new TypeError('Unimplemented');
138
+ const node = getShadowNode(this);
139
+
140
+ if (node != null) {
141
+ const scrollSize = nullthrows(getFabricUIManager()).getScrollSize(node);
142
+ if (scrollSize != null) {
143
+ return scrollSize[1];
144
+ }
145
+ }
146
+
147
+ return 0;
64
148
  }
65
149
 
66
150
  get scrollLeft(): number {
67
- throw new TypeError('Unimplemented');
151
+ const node = getShadowNode(this);
152
+
153
+ if (node != null) {
154
+ const scrollPosition = nullthrows(getFabricUIManager()).getScrollPosition(
155
+ node,
156
+ );
157
+ if (scrollPosition != null) {
158
+ return scrollPosition[0];
159
+ }
160
+ }
161
+
162
+ return 0;
68
163
  }
69
164
 
70
165
  get scrollTop(): number {
71
- throw new TypeError('Unimplemented');
166
+ const node = getShadowNode(this);
167
+
168
+ if (node != null) {
169
+ const scrollPosition = nullthrows(getFabricUIManager()).getScrollPosition(
170
+ node,
171
+ );
172
+ if (scrollPosition != null) {
173
+ return scrollPosition[1];
174
+ }
175
+ }
176
+
177
+ return 0;
72
178
  }
73
179
 
74
180
  get scrollWidth(): number {
75
- throw new TypeError('Unimplemented');
181
+ const node = getShadowNode(this);
182
+
183
+ if (node != null) {
184
+ const scrollSize = nullthrows(getFabricUIManager()).getScrollSize(node);
185
+ if (scrollSize != null) {
186
+ return scrollSize[0];
187
+ }
188
+ }
189
+
190
+ return 0;
76
191
  }
77
192
 
78
193
  get tagName(): string {
79
- throw new TypeError('Unimplemented');
194
+ const node = getShadowNode(this);
195
+
196
+ if (node != null) {
197
+ return nullthrows(getFabricUIManager()).getTagName(node);
198
+ }
199
+
200
+ return '';
201
+ }
202
+
203
+ get textContent(): string | null {
204
+ const shadowNode = getShadowNode(this);
205
+
206
+ if (shadowNode != null) {
207
+ return nullthrows(getFabricUIManager()).getTextContent(shadowNode);
208
+ }
209
+
210
+ return '';
80
211
  }
81
212
 
82
213
  getBoundingClientRect(): DOMRect {
83
- throw new TypeError('Unimplemented');
214
+ return getBoundingClientRect(this, {includeTransform: true});
84
215
  }
85
216
 
86
- getClientRects(): DOMRectList {
87
- throw new TypeError('Unimplemented');
217
+ /**
218
+ * Pointer Capture APIs
219
+ */
220
+ hasPointerCapture(pointerId: number): boolean {
221
+ const node = getShadowNode(this);
222
+ if (node != null) {
223
+ return nullthrows(getFabricUIManager()).hasPointerCapture(
224
+ node,
225
+ pointerId,
226
+ );
227
+ }
228
+ return false;
88
229
  }
230
+
231
+ setPointerCapture(pointerId: number): void {
232
+ const node = getShadowNode(this);
233
+ if (node != null) {
234
+ nullthrows(getFabricUIManager()).setPointerCapture(node, pointerId);
235
+ }
236
+ }
237
+
238
+ releasePointerCapture(pointerId: number): void {
239
+ const node = getShadowNode(this);
240
+ if (node != null) {
241
+ nullthrows(getFabricUIManager()).releasePointerCapture(node, pointerId);
242
+ }
243
+ }
244
+ }
245
+
246
+ function getChildElements(node: ReadOnlyNode): $ReadOnlyArray<ReadOnlyElement> {
247
+ // $FlowIssue[incompatible-call]
248
+ return getChildNodes(node).filter(
249
+ childNode => childNode instanceof ReadOnlyElement,
250
+ );
251
+ }
252
+
253
+ /**
254
+ * The public API for `getBoundingClientRect` always includes transform,
255
+ * so we use this internal version to get the data without transform to
256
+ * implement methods like `offsetWidth` and `offsetHeight`.
257
+ */
258
+ export function getBoundingClientRect(
259
+ node: ReadOnlyElement,
260
+ {includeTransform}: {includeTransform: boolean},
261
+ ): DOMRect {
262
+ const shadowNode = getShadowNode(node);
263
+
264
+ if (shadowNode != null) {
265
+ const rect = nullthrows(getFabricUIManager()).getBoundingClientRect(
266
+ shadowNode,
267
+ includeTransform,
268
+ );
269
+
270
+ if (rect) {
271
+ return new DOMRect(rect[0], rect[1], rect[2], rect[3]);
272
+ }
273
+ }
274
+
275
+ // Empty rect if any of the above failed
276
+ return new DOMRect(0, 0, 0, 0);
89
277
  }
@@ -5,77 +5,202 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @format
8
- * @flow strict
8
+ * @flow strict-local
9
9
  */
10
10
 
11
11
  // flowlint unsafe-getters-setters:off
12
12
 
13
+ import type {
14
+ InternalInstanceHandle,
15
+ Node as ShadowNode,
16
+ } from '../../Renderer/shims/ReactNativeTypes';
13
17
  import type NodeList from '../OldStyleCollections/NodeList';
14
18
  import type ReadOnlyElement from './ReadOnlyElement';
15
19
 
20
+ import {getFabricUIManager} from '../../ReactNative/FabricUIManager';
21
+ import ReactFabric from '../../Renderer/shims/ReactFabric';
22
+ import {createNodeList} from '../OldStyleCollections/NodeList';
23
+ import nullthrows from 'nullthrows';
24
+
25
+ // We initialize this lazily to avoid a require cycle
26
+ // (`ReadOnlyElement` also depends on `ReadOnlyNode`).
27
+ let ReadOnlyElementClass: Class<ReadOnlyElement>;
28
+
16
29
  export default class ReadOnlyNode {
30
+ constructor(internalInstanceHandle: InternalInstanceHandle) {
31
+ setInstanceHandle(this, internalInstanceHandle);
32
+ }
33
+
17
34
  get childNodes(): NodeList<ReadOnlyNode> {
18
- throw new TypeError('Unimplemented');
35
+ const childNodes = getChildNodes(this);
36
+ return createNodeList(childNodes);
19
37
  }
20
38
 
21
39
  get firstChild(): ReadOnlyNode | null {
22
- throw new TypeError('Unimplemented');
40
+ const childNodes = getChildNodes(this);
41
+
42
+ if (childNodes.length === 0) {
43
+ return null;
44
+ }
45
+
46
+ return childNodes[0];
23
47
  }
24
48
 
25
49
  get isConnected(): boolean {
26
- throw new TypeError('Unimplemented');
50
+ const shadowNode = getShadowNode(this);
51
+
52
+ if (shadowNode == null) {
53
+ return false;
54
+ }
55
+
56
+ return nullthrows(getFabricUIManager()).isConnected(shadowNode);
27
57
  }
28
58
 
29
59
  get lastChild(): ReadOnlyNode | null {
30
- throw new TypeError('Unimplemented');
60
+ const childNodes = getChildNodes(this);
61
+
62
+ if (childNodes.length === 0) {
63
+ return null;
64
+ }
65
+
66
+ return childNodes[childNodes.length - 1];
31
67
  }
32
68
 
33
69
  get nextSibling(): ReadOnlyNode | null {
34
- throw new TypeError('Unimplemented');
70
+ const [siblings, position] = getNodeSiblingsAndPosition(this);
71
+
72
+ if (position === siblings.length - 1) {
73
+ // this node is the last child of its parent, so there is no next sibling.
74
+ return null;
75
+ }
76
+
77
+ return siblings[position + 1];
35
78
  }
36
79
 
80
+ /**
81
+ * @abstract
82
+ */
37
83
  get nodeName(): string {
38
- throw new TypeError('Unimplemented');
84
+ throw new TypeError(
85
+ '`nodeName` is abstract and must be implemented in a subclass of `ReadOnlyNode`',
86
+ );
39
87
  }
40
88
 
89
+ /**
90
+ * @abstract
91
+ */
41
92
  get nodeType(): number {
42
- throw new TypeError('Unimplemented');
93
+ throw new TypeError(
94
+ '`nodeType` is abstract and must be implemented in a subclass of `ReadOnlyNode`',
95
+ );
43
96
  }
44
97
 
98
+ /**
99
+ * @abstract
100
+ */
45
101
  get nodeValue(): string | null {
46
- throw new TypeError('Unimplemented');
102
+ throw new TypeError(
103
+ '`nodeValue` is abstract and must be implemented in a subclass of `ReadOnlyNode`',
104
+ );
47
105
  }
48
106
 
49
107
  get parentElement(): ReadOnlyElement | null {
50
- throw new TypeError('Unimplemented');
108
+ const parentNode = this.parentNode;
109
+
110
+ if (ReadOnlyElementClass == null) {
111
+ // We initialize this lazily to avoid a require cycle.
112
+ ReadOnlyElementClass = require('./ReadOnlyElement').default;
113
+ }
114
+
115
+ if (parentNode instanceof ReadOnlyElementClass) {
116
+ return parentNode;
117
+ }
118
+
119
+ return null;
51
120
  }
52
121
 
53
122
  get parentNode(): ReadOnlyNode | null {
54
- throw new TypeError('Unimplemented');
123
+ const shadowNode = getShadowNode(this);
124
+
125
+ if (shadowNode == null) {
126
+ return null;
127
+ }
128
+
129
+ const parentInstanceHandle = nullthrows(getFabricUIManager()).getParentNode(
130
+ shadowNode,
131
+ );
132
+
133
+ if (parentInstanceHandle == null) {
134
+ return null;
135
+ }
136
+
137
+ return getPublicInstanceFromInternalInstanceHandle(parentInstanceHandle);
55
138
  }
56
139
 
57
140
  get previousSibling(): ReadOnlyNode | null {
58
- throw new TypeError('Unimplemented');
141
+ const [siblings, position] = getNodeSiblingsAndPosition(this);
142
+
143
+ if (position === 0) {
144
+ // this node is the first child of its parent, so there is no previous sibling.
145
+ return null;
146
+ }
147
+
148
+ return siblings[position - 1];
59
149
  }
60
150
 
151
+ /**
152
+ * @abstract
153
+ */
61
154
  get textContent(): string | null {
62
- throw new TypeError('Unimplemented');
155
+ throw new TypeError(
156
+ '`textContent` is abstract and must be implemented in a subclass of `ReadOnlyNode`',
157
+ );
63
158
  }
64
159
 
65
160
  compareDocumentPosition(otherNode: ReadOnlyNode): number {
66
- throw new TypeError('Unimplemented');
161
+ // Quick check to avoid having to call into Fabric if the nodes are the same.
162
+ if (otherNode === this) {
163
+ return 0;
164
+ }
165
+
166
+ const shadowNode = getShadowNode(this);
167
+ const otherShadowNode = getShadowNode(otherNode);
168
+
169
+ if (shadowNode == null || otherShadowNode == null) {
170
+ return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
171
+ }
172
+
173
+ return nullthrows(getFabricUIManager()).compareDocumentPosition(
174
+ shadowNode,
175
+ otherShadowNode,
176
+ );
67
177
  }
68
178
 
69
179
  contains(otherNode: ReadOnlyNode): boolean {
70
- throw new TypeError('Unimplemented');
180
+ if (otherNode === this) {
181
+ return true;
182
+ }
183
+
184
+ const position = this.compareDocumentPosition(otherNode);
185
+ // eslint-disable-next-line no-bitwise
186
+ return (position & ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY) !== 0;
71
187
  }
72
188
 
73
189
  getRootNode(): ReadOnlyNode {
74
- throw new TypeError('Unimplemented');
190
+ // eslint-disable-next-line consistent-this
191
+ let lastKnownParent: ReadOnlyNode = this;
192
+ let nextPossibleParent: ?ReadOnlyNode = this.parentNode;
193
+
194
+ while (nextPossibleParent != null) {
195
+ lastKnownParent = nextPossibleParent;
196
+ nextPossibleParent = nextPossibleParent.parentNode;
197
+ }
198
+
199
+ return lastKnownParent;
75
200
  }
76
201
 
77
202
  hasChildNodes(): boolean {
78
- throw new TypeError('Unimplemented');
203
+ return getChildNodes(this).length > 0;
79
204
  }
80
205
 
81
206
  /*
@@ -165,3 +290,67 @@ export default class ReadOnlyNode {
165
290
  */
166
291
  static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number = 32;
167
292
  }
293
+
294
+ const INSTANCE_HANDLE_KEY = Symbol('internalInstanceHandle');
295
+
296
+ export function getInstanceHandle(node: ReadOnlyNode): InternalInstanceHandle {
297
+ // $FlowExpectedError[prop-missing]
298
+ return node[INSTANCE_HANDLE_KEY];
299
+ }
300
+
301
+ function setInstanceHandle(
302
+ node: ReadOnlyNode,
303
+ instanceHandle: InternalInstanceHandle,
304
+ ): void {
305
+ // $FlowExpectedError[prop-missing]
306
+ node[INSTANCE_HANDLE_KEY] = instanceHandle;
307
+ }
308
+
309
+ export function getShadowNode(node: ReadOnlyNode): ?ShadowNode {
310
+ return ReactFabric.getNodeFromInternalInstanceHandle(getInstanceHandle(node));
311
+ }
312
+
313
+ export function getChildNodes(
314
+ node: ReadOnlyNode,
315
+ ): $ReadOnlyArray<ReadOnlyNode> {
316
+ const shadowNode = getShadowNode(node);
317
+
318
+ if (shadowNode == null) {
319
+ return [];
320
+ }
321
+
322
+ const childNodeInstanceHandles = nullthrows(
323
+ getFabricUIManager(),
324
+ ).getChildNodes(shadowNode);
325
+ return childNodeInstanceHandles.map(instanceHandle =>
326
+ getPublicInstanceFromInternalInstanceHandle(instanceHandle),
327
+ );
328
+ }
329
+
330
+ function getNodeSiblingsAndPosition(
331
+ node: ReadOnlyNode,
332
+ ): [$ReadOnlyArray<ReadOnlyNode>, number] {
333
+ const parent = node.parentNode;
334
+ if (parent == null) {
335
+ // This node is the root or it's disconnected.
336
+ return [[node], 0];
337
+ }
338
+
339
+ const siblings = getChildNodes(parent);
340
+ const position = siblings.indexOf(node);
341
+
342
+ if (position === -1) {
343
+ throw new TypeError("Missing node in parent's child node list");
344
+ }
345
+
346
+ return [siblings, position];
347
+ }
348
+
349
+ export function getPublicInstanceFromInternalInstanceHandle(
350
+ instanceHandle: InternalInstanceHandle,
351
+ ): ReadOnlyNode {
352
+ const mixedPublicInstance =
353
+ ReactFabric.getPublicInstanceFromInternalInstanceHandle(instanceHandle);
354
+ // $FlowExpectedError[incompatible-return] React defines public instances as "mixed" because it can't access the definition from React Native.
355
+ return mixedPublicInstance;
356
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ // flowlint unsafe-getters-setters:off
12
+
13
+ import ReadOnlyCharacterData from './ReadOnlyCharacterData';
14
+ import ReadOnlyNode from './ReadOnlyNode';
15
+
16
+ export default class ReadOnlyText extends ReadOnlyCharacterData {
17
+ /**
18
+ * @override
19
+ */
20
+ get nodeName(): string {
21
+ return '#text';
22
+ }
23
+
24
+ /**
25
+ * @override
26
+ */
27
+ get nodeType(): number {
28
+ return ReadOnlyNode.TEXT_NODE;
29
+ }
30
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import type ReadOnlyElement from '../ReadOnlyElement';
12
+ import type ReadOnlyNode from '../ReadOnlyNode';
13
+
14
+ import {getChildNodes} from '../ReadOnlyNode';
15
+
16
+ // We initialize this lazily to avoid a require cycle
17
+ // (`ReadOnlyElement` also depends on `Traversal`).
18
+ let ReadOnlyElementClass: Class<ReadOnlyElement>;
19
+
20
+ export function getElementSibling(
21
+ node: ReadOnlyNode,
22
+ direction: 'next' | 'previous',
23
+ ): ReadOnlyElement | null {
24
+ const parent = node.parentNode;
25
+ if (parent == null) {
26
+ // This node is the root or it's disconnected.
27
+ return null;
28
+ }
29
+
30
+ const childNodes = getChildNodes(parent);
31
+
32
+ const startPosition = childNodes.indexOf(node);
33
+ if (startPosition === -1) {
34
+ return null;
35
+ }
36
+
37
+ const increment = direction === 'next' ? 1 : -1;
38
+
39
+ let position = startPosition + increment;
40
+
41
+ if (ReadOnlyElementClass == null) {
42
+ // We initialize this lazily to avoid a require cycle.
43
+ ReadOnlyElementClass = require('../ReadOnlyElement').default;
44
+ }
45
+
46
+ while (
47
+ childNodes[position] != null &&
48
+ !(childNodes[position] instanceof ReadOnlyElementClass)
49
+ ) {
50
+ position = position + increment;
51
+ }
52
+
53
+ return childNodes[position] ?? null;
54
+ }
@@ -60,10 +60,4 @@ declare class NativeEventEmitter extends EventEmitter {
60
60
  * @param eventType name of the event whose registered listeners to remove
61
61
  */
62
62
  removeAllListeners(eventType: string): void;
63
-
64
- /**
65
- * Removes a subscription created by the addListener, the EventSubscription#remove()
66
- * function actually calls through to this.
67
- */
68
- removeSubscription(subscription: EmitterSubscription): void;
69
63
  }