@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.
- package/.flowconfig +15 -4
- package/CHANGELOG.json +531 -87
- package/CHANGELOG.md +213 -48
- package/IntegrationTests/PromiseTest.js +1 -0
- package/IntegrationTests/websocket_integration_test_server.js +1 -1
- package/Libraries/Animated/Animated.js +1 -1
- package/Libraries/Animated/AnimatedImplementation.js +1 -1
- package/Libraries/Animated/NativeAnimatedHelper.js +14 -10
- package/Libraries/Animated/NativeAnimatedHelper.win32.js +16 -12
- package/Libraries/Animated/NativeAnimatedModule.js +6 -2
- package/Libraries/Animated/NativeAnimatedTurboModule.js +7 -4
- package/Libraries/Animated/animations/Animation.js +57 -3
- package/Libraries/Animated/animations/DecayAnimation.js +9 -0
- package/Libraries/Animated/animations/SpringAnimation.js +8 -0
- package/Libraries/Animated/animations/TimingAnimation.js +8 -0
- package/Libraries/Animated/components/AnimatedFlatList.js +2 -1
- package/Libraries/Animated/components/AnimatedScrollView.js +2 -0
- package/Libraries/Animated/components/AnimatedSectionList.js +2 -1
- package/Libraries/Animated/createAnimatedComponent.js +1 -0
- package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
- package/Libraries/Animated/nodes/AnimatedObject.js +146 -0
- package/Libraries/Animated/nodes/AnimatedProps.js +19 -7
- package/Libraries/Animated/nodes/AnimatedStyle.js +29 -55
- package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -17
- package/Libraries/Animated/shouldUseTurboAnimatedModule.js +17 -0
- package/Libraries/Animated/useAnimatedProps.js +9 -10
- package/Libraries/AppState/AppState.d.ts +1 -1
- package/Libraries/AppState/NativeAppState.js +8 -4
- package/Libraries/BatchedBridge/MessageQueue.js +45 -36
- package/Libraries/Blob/Blob.js +6 -2
- package/Libraries/Blob/BlobManager.js +9 -10
- package/Libraries/Blob/BlobRegistry.js +14 -9
- package/Libraries/Blob/File.js +1 -1
- package/Libraries/Blob/FileReader.js +1 -2
- package/Libraries/Components/Button/ButtonWin32.Props.d.ts +1 -1
- package/Libraries/Components/Button/ButtonWin32.Props.js.map +1 -1
- package/Libraries/Components/Button/ButtonWin32.d.ts +1 -1
- package/Libraries/Components/Button/ButtonWin32.js +1 -4
- package/Libraries/Components/Button/ButtonWin32.js.map +1 -1
- package/Libraries/Components/Clipboard/Clipboard.d.ts +4 -4
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +3 -1
- package/Libraries/Components/EnterString.win32.d.ts +1 -1
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +26 -6
- package/Libraries/Components/Pressable/Pressable.js +3 -2
- package/Libraries/Components/Pressable/Pressable.win32.js +4 -3
- package/Libraries/Components/Pressable/useAndroidRippleForView.js +1 -1
- package/Libraries/Components/SafeAreaView/SafeAreaView.js +7 -7
- package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +7 -8
- package/Libraries/Components/ScrollView/ScrollView.js +3 -1
- package/Libraries/Components/ScrollView/ScrollView.win32.js +3 -1
- package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +39 -46
- package/Libraries/Components/Switch/Switch.js +1 -0
- package/Libraries/Components/Text/TextWin32.d.ts +1 -1
- package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
- package/Libraries/Components/TextInput/TextInput.d.ts +49 -7
- package/Libraries/Components/TextInput/TextInput.flow.js +43 -10
- package/Libraries/Components/TextInput/TextInput.js +62 -10
- package/Libraries/Components/TextInput/TextInput.win32.js +953 -206
- package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +23 -0
- package/Libraries/Components/ToastAndroid/{ToastAndroid.ios.js → ToastAndroid.js} +9 -1
- package/Libraries/Components/ToastAndroid/ToastAndroid.win32.js +9 -1
- package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js +2 -2
- package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js.map +1 -1
- package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
- package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
- package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
- package/Libraries/Components/Touchable/TouchableOpacity.js +4 -1
- package/Libraries/Components/Touchable/TouchableWin32.d.ts +1 -1
- package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +1 -0
- package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js +16 -6
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +9 -0
- package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
- package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +1 -0
- package/Libraries/Components/View/View.js +46 -32
- package/Libraries/Components/View/View.win32.js +37 -6
- package/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
- package/Libraries/Components/View/ViewNativeComponent.js +1 -0
- package/Libraries/Components/View/ViewPropTypes.js +18 -3
- package/Libraries/Components/View/ViewPropTypes.win32.js +30 -4
- package/Libraries/Components/View/ViewWin32.js +3 -2
- package/Libraries/Core/Devtools/loadBundleFromServer.js +152 -0
- package/Libraries/Core/Devtools/symbolicateStackTrace.js +2 -1
- package/Libraries/Core/ExceptionsManager.js +16 -7
- package/Libraries/Core/ExtendedError.js +12 -0
- package/Libraries/Core/ReactNativeVersion.js +3 -3
- package/Libraries/Core/ReactNativeVersionCheck.js +0 -2
- package/Libraries/Core/ReactNativeVersionCheck.win32.js +0 -2
- package/Libraries/Core/__mocks__/NativeExceptionsManager.js +20 -0
- package/Libraries/Core/setUpDeveloperTools.js +5 -1
- package/Libraries/Core/setUpIntersectionObserver.js +16 -0
- package/Libraries/{Components/ProgressBarAndroid/ProgressBarAndroid.ios.js → Core/setUpMutationObserver.js} +6 -2
- package/Libraries/Core/setUpPerformance.js +6 -13
- package/Libraries/Core/setUpPerformanceObserver.js +16 -0
- package/Libraries/Core/setUpRegeneratorRuntime.js +4 -2
- package/Libraries/DOM/Nodes/ReactNativeElement.js +135 -18
- package/Libraries/DOM/Nodes/ReadOnlyCharacterData.js +72 -0
- package/Libraries/DOM/Nodes/ReadOnlyElement.js +209 -21
- package/Libraries/DOM/Nodes/ReadOnlyNode.js +206 -17
- package/Libraries/DOM/Nodes/ReadOnlyText.js +30 -0
- package/Libraries/DOM/Nodes/Utilities/Traversal.js +54 -0
- package/Libraries/EventEmitter/NativeEventEmitter.d.ts +0 -6
- package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +15 -4
- package/Libraries/Image/Image.android.js +8 -2
- package/Libraries/Image/Image.d.ts +1 -1
- package/Libraries/Image/Image.ios.js +4 -1
- package/Libraries/Image/Image.win32.js +6 -3
- package/Libraries/Image/ImageBackground.js +3 -0
- package/Libraries/Image/resolveAssetSource.win32.js +1 -1
- package/Libraries/Inspector/DevtoolsOverlay.js +6 -3
- package/Libraries/Inspector/NetworkOverlay.js +2 -2
- package/Libraries/Interaction/JSEventLoopWatchdog.js +1 -5
- package/Libraries/Interaction/PanResponder.js +1 -4
- package/Libraries/IntersectionObserver/IntersectionObserver.js +252 -0
- package/Libraries/IntersectionObserver/IntersectionObserverEntry.js +140 -0
- package/Libraries/IntersectionObserver/IntersectionObserverManager.js +221 -0
- package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +41 -0
- package/Libraries/IntersectionObserver/__mocks__/NativeIntersectionObserver.js +162 -0
- package/Libraries/LayoutAnimation/LayoutAnimation.js +1 -1
- package/Libraries/Lists/FlatList.d.ts +2 -1
- package/Libraries/Lists/FlatList.js +15 -5
- package/Libraries/Lists/SectionList.js +4 -0
- package/Libraries/LogBox/Data/LogBoxLog.js +4 -1
- package/Libraries/LogBox/Data/LogBoxSymbolication.js +5 -2
- package/Libraries/LogBox/Data/parseLogBoxLog.js +57 -20
- package/Libraries/LogBox/UI/AnsiHighlight.js +1 -1
- package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +24 -31
- package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +1 -1
- package/Libraries/LogBox/UI/LogBoxMessage.js +4 -7
- package/Libraries/MutationObserver/MutationObserver.js +184 -0
- package/Libraries/MutationObserver/MutationObserverManager.js +218 -0
- package/Libraries/MutationObserver/MutationRecord.js +82 -0
- package/Libraries/MutationObserver/NativeMutationObserver.js +58 -0
- package/Libraries/MutationObserver/__mocks__/NativeMutationObserver.js +327 -0
- package/Libraries/NativeComponent/BaseViewConfig.android.js +18 -3
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +33 -0
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +33 -0
- package/Libraries/NativeComponent/NativeComponentRegistry.js +3 -5
- package/Libraries/NativeModules/specs/NativeSourceCode.js +6 -6
- package/Libraries/Network/RCTNetworking.android.js +2 -1
- package/Libraries/Network/XMLHttpRequest.js +1 -1
- package/Libraries/NewAppScreen/components/DebugInstructions.js +4 -4
- package/Libraries/NewAppScreen/components/LearnMoreLinks.js +9 -2
- package/Libraries/Performance/QuickPerformanceLogger.js +1 -1
- package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +1 -0
- package/Libraries/PermissionsAndroid/PermissionsAndroid.d.ts +1 -0
- package/Libraries/PermissionsAndroid/PermissionsAndroid.js +3 -1
- package/Libraries/Pressability/Pressability.js +28 -3
- package/Libraries/Pressability/Pressability.win32.js +30 -5
- package/Libraries/ReactNative/AppContainer.js +2 -3
- package/Libraries/ReactNative/AppRegistry.d.ts +0 -5
- package/Libraries/ReactNative/AppRegistry.js +66 -53
- package/Libraries/ReactNative/BridgelessUIManager.js +38 -9
- package/Libraries/ReactNative/FabricUIManager.js +143 -34
- package/Libraries/ReactNative/I18nManager.js +5 -11
- package/Libraries/ReactNative/NativeI18nManager.js +7 -5
- package/Libraries/ReactNative/PaperUIManager.win32.js +2 -2
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +151 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +81 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload.js +492 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +32 -0
- package/Libraries/ReactNative/ReactNativeFeatureFlags.js +19 -3
- package/Libraries/ReactNative/UIManager.js +8 -0
- package/Libraries/ReactNative/__mocks__/FabricUIManager.js +648 -0
- package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +38 -2
- package/Libraries/Renderer/implementations/ReactFabric-dev.js +27 -27
- package/Libraries/Renderer/implementations/ReactFabric-prod.js +3 -3
- package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3 -3
- package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +27 -27
- package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3 -3
- package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3 -3
- package/Libraries/Renderer/shims/ReactFabric.js +5 -6
- package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -3
- package/Libraries/Renderer/shims/ReactNative.js +2 -3
- package/Libraries/Renderer/shims/ReactNativeTypes.js +35 -17
- package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -3
- package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -3
- package/Libraries/Settings/{Settings.android.js → Settings.js} +4 -4
- package/Libraries/Share/Share.d.ts +3 -9
- package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +9 -4
- package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +28 -13
- package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +14 -4
- package/Libraries/StyleSheet/PlatformColorValueTypesIOS.ios.js +1 -1
- package/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
- package/Libraries/StyleSheet/StyleSheet.d.ts +10 -1
- package/Libraries/StyleSheet/StyleSheet.js +3 -0
- package/Libraries/StyleSheet/StyleSheet.win32.js +3 -0
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +31 -17
- package/Libraries/StyleSheet/StyleSheetTypes.js +90 -6
- package/Libraries/StyleSheet/flattenStyle.js +4 -0
- package/Libraries/StyleSheet/private/_TransformStyle.js +16 -2
- package/Libraries/StyleSheet/processColor.js +1 -2
- package/Libraries/StyleSheet/processTransformOrigin.js +136 -0
- package/Libraries/StyleSheet/splitLayoutProps.js +1 -0
- package/Libraries/Text/Text.d.ts +5 -5
- package/Libraries/Text/Text.js +17 -10
- package/Libraries/Text/Text.win32.js +354 -0
- package/Libraries/Text/TextProps.win32.js +281 -0
- package/Libraries/TurboModule/TurboModuleRegistry.js +47 -7
- package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +6 -0
- package/Libraries/Types/CoreEventTypes.d.ts +5 -2
- package/Libraries/Utilities/GlobalPerformanceLogger.js +2 -12
- package/Libraries/Utilities/NativeDeviceInfo.js +8 -9
- package/Libraries/Utilities/NativePlatformConstantsAndroid.js +23 -18
- package/Libraries/Utilities/NativePlatformConstantsIOS.js +16 -13
- package/Libraries/Utilities/NativePlatformConstantsWin.js +13 -10
- package/Libraries/Utilities/PerformanceLoggerContext.js +1 -1
- package/Libraries/Utilities/Platform.android.js +12 -8
- package/Libraries/Utilities/Platform.d.ts +1 -0
- package/Libraries/Utilities/Platform.flow.js +84 -0
- package/Libraries/Utilities/Platform.flow.win32.js +111 -0
- package/Libraries/Utilities/Platform.ios.js +12 -8
- package/Libraries/Utilities/Platform.win32.js +12 -8
- package/Libraries/Utilities/PolyfillFunctions.js +1 -1
- package/Libraries/Utilities/ReactNativeTestTools.js +1 -2
- package/Libraries/Utilities/SceneTracker.js +1 -1
- package/Libraries/Utilities/createPerformanceLogger.js +63 -32
- package/Libraries/Utilities/useColorScheme.js +7 -8
- package/Libraries/WebPerformance/MemoryInfo.js +1 -1
- package/Libraries/WebPerformance/NativePerformance.js +3 -8
- package/Libraries/WebPerformance/NativePerformanceObserver.js +4 -0
- package/Libraries/WebPerformance/Performance.js +42 -15
- package/Libraries/WebPerformance/PerformanceEntry.js +14 -6
- package/Libraries/WebPerformance/PerformanceEventTiming.js +18 -1
- package/Libraries/WebPerformance/ReactNativeStartupTiming.js +40 -14
- package/Libraries/WebPerformance/__mocks__/NativePerformance.js +4 -2
- package/Libraries/WebPerformance/__mocks__/NativePerformanceObserver.js +21 -3
- package/Libraries/promiseRejectionTrackingOptions.js +1 -3
- package/Libraries/vendor/emitter/EventEmitter.js +20 -18
- package/flow/global.js +1 -3
- package/flow/jest.js +5 -1
- package/{Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.ios.js → jest/ReactNativeInternalFeatureFlagsMock.js} +2 -1
- package/jest/__tests__/setup-test.js +18 -0
- package/jest/mockModal.js +6 -4
- package/jest/setup.js +61 -30
- package/jest.config.js +1 -1
- package/just-task.js +1 -0
- package/overrides.json +51 -46
- package/package.json +35 -33
- package/src/Libraries/Components/Button/ButtonWin32.Props.ts +1 -1
- package/src/Libraries/Components/Button/ButtonWin32.tsx +0 -2
- package/src/Libraries/Components/Touchable/Tests/TouchableWin32Test.tsx +2 -2
- package/src/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
- package/src/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
- package/src/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
- package/types/experimental.d.ts +44 -0
- package/types/index.d.ts +2 -1
- package/types/modules/Devtools.d.ts +1 -0
- package/types/modules/globals.d.ts +16 -1
- package/IntegrationTests/BUCK +0 -32
- package/IntegrationTests/PropertiesUpdateTest.js +0 -29
- package/IntegrationTests/RCTRootViewIntegrationTestApp.js +0 -86
- package/IntegrationTests/ReactContentSizeUpdateTest.js +0 -89
- package/IntegrationTests/SizeFlexibilityUpdateTest.js +0 -106
- package/Libraries/Components/TextInput/TextInput.Types.win32.d.ts +0 -51
- package/Libraries/Components/TextInput/TextInput.Types.win32.js +0 -3
- package/Libraries/Components/TextInput/TextInput.Types.win32.js.map +0 -1
- package/Libraries/Utilities/AcessibilityMapping.js +0 -154
- package/Libraries/Utilities/AcessibilityMapping.win32.js +0 -156
- package/Libraries/Utilities/NativeDevSplitBundleLoader.js +0 -19
- package/Libraries/Utilities/useColorScheme.win32.js +0 -26
- package/flow/use-sync-external-store.js +0 -20
- package/flow-typed/npm/base64-js_v1.x.x.js +0 -12
- package/flow-typed/npm/glob_v7.x.x.js +0 -79
- package/flow-typed/npm/pretty-format_v26.x.x.js +0 -49
- package/flow-typed/npm/promise_v8.x.x.js +0 -30
- package/flow-typed/npm/react-dom_v17.x.x.js +0 -139
- package/flow-typed/npm/react-test-renderer_v16.x.x.js +0 -79
- package/flow-typed/npm/stacktrace-parser_v0.1.x.js +0 -17
- package/flow-typed/npm/yargs_v17.x.x.js +0 -341
- package/src/Libraries/Components/TextInput/TextInput.Types.win32.ts +0 -68
- /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
|
|
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
|
-
|
|
28
|
+
return getChildElements(this).length;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
get children(): HTMLCollection<ReadOnlyElement> {
|
|
23
|
-
|
|
32
|
+
return createHTMLCollection(getChildElements(this));
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
get clientHeight(): number {
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
+
return getElementSibling(this, 'previous');
|
|
60
135
|
}
|
|
61
136
|
|
|
62
137
|
get scrollHeight(): number {
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
214
|
+
return getBoundingClientRect(this, {includeTransform: true});
|
|
84
215
|
}
|
|
85
216
|
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
35
|
+
const childNodes = getChildNodes(this);
|
|
36
|
+
return createNodeList(childNodes);
|
|
19
37
|
}
|
|
20
38
|
|
|
21
39
|
get firstChild(): ReadOnlyNode | null {
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|