react-native-molecules 0.5.0-beta.23 → 0.5.0-beta.24
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/components/Accordion/Accordion.tsx +1 -1
- package/components/Accordion/AccordionItem.tsx +1 -1
- package/components/Checkbox/Checkbox.tsx +2 -1
- package/components/DateField/useDateFieldState.ts +2 -2
- package/components/DatePicker/DatePickerProvider.tsx +1 -1
- package/components/DatePickerInline/DatePickerInline.tsx +1 -1
- package/components/DatePickerInline/DatePickerInlineBase.tsx +1 -1
- package/components/DatePickerInline/Day.tsx +1 -1
- package/components/DatePickerInline/Swiper.tsx +1 -1
- package/components/DatePickerInline/SwiperUtils.ts +1 -1
- package/components/DatePickerInline/dateUtils.tsx +1 -1
- package/components/DatePickerInline/store.tsx +2 -1
- package/components/Divider/index.tsx +2 -3
- package/components/ElementGroup/ElementGroup.tsx +1 -1
- package/components/FilePicker/FilePicker.tsx +1 -1
- package/components/Icon/iconFactory.tsx +2 -1
- package/components/IconButton/IconButton.tsx +39 -13
- package/components/IconButton/index.tsx +1 -0
- package/components/IconButton/types.ts +2 -0
- package/components/List/List.tsx +2 -1
- package/components/List/context.tsx +2 -1
- package/components/Portal/Portal.tsx +1 -2
- package/components/RadioButton/RadioButtonGroup.tsx +1 -2
- package/components/Rating/Rating.tsx +1 -1
- package/components/Select/Select.tsx +103 -34
- package/components/Select/context.tsx +3 -1
- package/components/Select/index.ts +20 -2
- package/components/Select/types.ts +2 -0
- package/components/Select/utils.ts +11 -4
- package/components/Switch/Switch.ios.tsx +1 -1
- package/components/Switch/Switch.tsx +2 -1
- package/components/Tabs/Tabs.tsx +2 -2
- package/components/TextInput/TextInput.tsx +4 -3
- package/components/TimePicker/AnalogClock.tsx +1 -1
- package/components/TimePicker/TimeInputs.tsx +1 -1
- package/components/TimePicker/TimePicker.tsx +1 -1
- package/components/TimePicker/TimePickerModal.tsx +1 -1
- package/components/Tooltip/Tooltip.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.tsx +1 -1
- package/hocs/index.tsx +1 -1
- package/hocs/withKeyboardAccessibility.tsx +2 -3
- package/hooks/index.tsx +2 -6
- package/hooks/useContrastColor.ts +1 -2
- package/hooks/useFilePicker.tsx +1 -1
- package/hooks/useHandleNumberFormat.tsx +2 -2
- package/hooks/useMediaQuery.tsx +1 -2
- package/package.json +3 -27
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +1 -1
- package/shortcuts-manager/ShortcutsManager/utils.tsx +1 -1
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +1 -1
- package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
- package/utils/extractTextStyles.ts +1 -2
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +2 -1
- package/utils/index.ts +0 -3
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +1 -1
- package/context-bridge/index.tsx +0 -87
- package/fast-context/index.tsx +0 -190
- package/hocs/typedMemo.tsx +0 -5
- package/hooks/useControlledValue.tsx +0 -84
- package/hooks/useLatest.tsx +0 -9
- package/hooks/useMergedRefs.ts +0 -14
- package/hooks/usePrevious.ts +0 -13
- package/hooks/useToggle.tsx +0 -24
- package/hooks/useWhatHasUpdated.tsx +0 -48
- package/utils/color.ts +0 -22
- package/utils/compare/index.ts +0 -54
- package/utils/lodash.ts +0 -121
- package/utils/repository.ts +0 -53
|
@@ -39,6 +39,13 @@ const triggerDefaultStyles = StyleSheet.create(theme => ({
|
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
|
+
triggerIcon: {
|
|
43
|
+
marginLeft: theme.spacings['2'],
|
|
44
|
+
color: theme.colors.onSurfaceVariant,
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
const outlineDefaultStyles = StyleSheet.create(theme => ({
|
|
42
49
|
outline: {
|
|
43
50
|
position: 'absolute',
|
|
44
51
|
top: 0,
|
|
@@ -85,10 +92,6 @@ const triggerDefaultStyles = StyleSheet.create(theme => ({
|
|
|
85
92
|
},
|
|
86
93
|
},
|
|
87
94
|
},
|
|
88
|
-
triggerIcon: {
|
|
89
|
-
marginLeft: theme.spacings['2'],
|
|
90
|
-
color: theme.colors.onSurfaceVariant,
|
|
91
|
-
},
|
|
92
95
|
}));
|
|
93
96
|
|
|
94
97
|
export const defaultStyles = StyleSheet.create(theme => ({
|
|
@@ -115,5 +118,9 @@ export const triggerStyles = getRegisteredComponentStylesWithFallback(
|
|
|
115
118
|
'Select_Trigger',
|
|
116
119
|
triggerDefaultStyles,
|
|
117
120
|
);
|
|
121
|
+
export const selectOutlineStyles = getRegisteredComponentStylesWithFallback(
|
|
122
|
+
'SelectOutline',
|
|
123
|
+
outlineDefaultStyles,
|
|
124
|
+
);
|
|
118
125
|
|
|
119
126
|
export const styles = getRegisteredComponentStylesWithFallback('Select', defaultStyles);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useControlledValue } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import { forwardRef, memo } from 'react';
|
|
2
3
|
import {
|
|
3
4
|
Switch as NativeSwitch,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
type ViewStyle,
|
|
7
8
|
} from 'react-native';
|
|
8
9
|
|
|
9
|
-
import { useControlledValue } from '../../hooks';
|
|
10
10
|
import type { IconType } from '../Icon';
|
|
11
11
|
|
|
12
12
|
export type Props = SwitchProps & {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useControlledValue, useLatest } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import { forwardRef, memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
3
|
import {
|
|
3
4
|
Animated,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
type ViewStyle,
|
|
10
11
|
} from 'react-native';
|
|
11
12
|
|
|
12
|
-
import { useActionState
|
|
13
|
+
import { useActionState } from '../../hooks';
|
|
13
14
|
import { resolveStateVariant } from '../../utils';
|
|
14
15
|
import { Icon, type IconType } from '../Icon';
|
|
15
16
|
import { switchStyles, useSwitchColors } from './utils';
|
package/components/Tabs/Tabs.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { noop } from '@react-native-molecules/utils/helpers/lodash';
|
|
2
|
+
import { useControlledValue } from '@react-native-molecules/utils/hooks';
|
|
1
3
|
import {
|
|
2
4
|
cloneElement,
|
|
3
5
|
type ComponentType,
|
|
@@ -22,9 +24,7 @@ import {
|
|
|
22
24
|
} from 'react-native';
|
|
23
25
|
|
|
24
26
|
import { typedMemo } from '../../hocs';
|
|
25
|
-
import { useControlledValue } from '../../hooks';
|
|
26
27
|
import { extractSubcomponents } from '../../utils/extractSubcomponents';
|
|
27
|
-
import { noop } from '../../utils/lodash';
|
|
28
28
|
import type { TabItemProps } from './TabItem';
|
|
29
29
|
import { tabsStyles } from './utils';
|
|
30
30
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useControlledValue, useLatest } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import React, {
|
|
2
3
|
memo,
|
|
3
4
|
type PropsWithoutRef,
|
|
@@ -31,9 +32,7 @@ import {
|
|
|
31
32
|
View,
|
|
32
33
|
} from 'react-native';
|
|
33
34
|
|
|
34
|
-
import { useActionState } from '../../hooks
|
|
35
|
-
import useControlledValue from '../../hooks/useControlledValue';
|
|
36
|
-
import useLatest from '../../hooks/useLatest';
|
|
35
|
+
import { useActionState } from '../../hooks';
|
|
37
36
|
import { createSyntheticEvent, resolveStateVariant } from '../../utils';
|
|
38
37
|
import { extractSubcomponents } from '../../utils/extractSubcomponents';
|
|
39
38
|
import { HelperText } from '../HelperText';
|
|
@@ -645,6 +644,7 @@ export const TextInputLeft = memo(
|
|
|
645
644
|
style={[textInputLeftStyles.leftElement, style]}
|
|
646
645
|
onLayout={handleLayout}
|
|
647
646
|
accessibilityRole="none"
|
|
647
|
+
tabIndex={-1}
|
|
648
648
|
{...rest}>
|
|
649
649
|
{children}
|
|
650
650
|
</Pressable>
|
|
@@ -683,6 +683,7 @@ export const TextInputRight = memo(
|
|
|
683
683
|
onPress={onPress}
|
|
684
684
|
style={[textInputRightStyles.rightElement, style]}
|
|
685
685
|
accessibilityRole="none"
|
|
686
|
+
tabIndex={-1}
|
|
686
687
|
{...rest}>
|
|
687
688
|
{children}
|
|
688
689
|
</Pressable>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useLatest } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import { memo, useCallback, useMemo, useRef } from 'react';
|
|
2
3
|
import {
|
|
3
4
|
type GestureResponderEvent,
|
|
@@ -7,7 +8,6 @@ import {
|
|
|
7
8
|
type ViewProps,
|
|
8
9
|
} from 'react-native';
|
|
9
10
|
|
|
10
|
-
import { useLatest } from '../../hooks';
|
|
11
11
|
import AnalogClockHours from './AnalogClockHours';
|
|
12
12
|
import AnalogClockMinutes from './AnalogClockMinutes';
|
|
13
13
|
import AnimatedClockSwitcher from './AnimatedClockSwitcher';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @typescript-eslint/no-unused-vars
|
|
2
2
|
// WORK IN PROGRESS
|
|
3
3
|
|
|
4
|
+
import { useLatest } from '@react-native-molecules/utils/hooks';
|
|
4
5
|
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
5
6
|
import { TextInput as TextInputNative, useWindowDimensions, View } from 'react-native';
|
|
6
7
|
|
|
7
|
-
import { useLatest } from '../../hooks';
|
|
8
8
|
import { resolveStateVariant } from '../../utils';
|
|
9
9
|
import { Text } from '../Text';
|
|
10
10
|
import AmPmSwitcher from './AmPmSwitcher';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { useControlledValue } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import { memo, useCallback, useMemo, useState } from 'react';
|
|
2
3
|
import { type StyleProp, View, type ViewStyle } from 'react-native';
|
|
3
4
|
|
|
4
5
|
import { getRegisteredComponentWithFallback } from '../../core';
|
|
5
|
-
import { useControlledValue } from '../../hooks';
|
|
6
6
|
import { format, parse } from '../../utils/date-fns';
|
|
7
7
|
import { useOptionalDatePickerContext } from '../DatePicker/context';
|
|
8
8
|
import AnalogClock from './AnalogClock';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { useControlledValue } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import type { ReactNode } from 'react';
|
|
2
3
|
import { memo, useMemo } from 'react';
|
|
3
4
|
import { KeyboardAvoidingView, Platform, View } from 'react-native';
|
|
4
5
|
|
|
5
6
|
import { getRegisteredComponentWithFallback } from '../../core';
|
|
6
|
-
import { useControlledValue } from '../../hooks';
|
|
7
7
|
import { DatePickerActions, DatePickerProvider } from '../DatePicker';
|
|
8
8
|
import type {
|
|
9
9
|
DatePickerContextType,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useToggle } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import {
|
|
2
3
|
createContext,
|
|
3
4
|
memo,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
useRef,
|
|
10
11
|
} from 'react';
|
|
11
12
|
|
|
12
|
-
import { useToggle } from '../../hooks';
|
|
13
13
|
import { extractSubcomponents } from '../../utils/extractSubcomponents';
|
|
14
14
|
|
|
15
15
|
export type Props = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { noop } from '@react-native-molecules/utils/helpers/lodash';
|
|
1
2
|
import { forwardRef, memo, type ReactNode, useCallback, useRef } from 'react';
|
|
2
3
|
import {
|
|
3
4
|
type GestureResponderEvent,
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
import { StyleSheet } from 'react-native-unistyles';
|
|
11
12
|
|
|
12
13
|
import { useTheme } from '../../hooks/useTheme';
|
|
13
|
-
import { noop } from '../../utils/lodash';
|
|
14
14
|
import { Slot } from '../Slot';
|
|
15
15
|
import { rippleColorFromBackground } from './rippleFromForegroundColor';
|
|
16
16
|
import { touchableRippleStyles } from './utils';
|
package/hocs/index.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createFastContext } from '@react-native-molecules/utils/fast-context';
|
|
2
|
+
import { useLatest } from '@react-native-molecules/utils/hooks';
|
|
1
3
|
import {
|
|
2
4
|
type ComponentType,
|
|
3
5
|
forwardRef,
|
|
@@ -15,9 +17,6 @@ import type { FlatList } from 'react-native';
|
|
|
15
17
|
import type { SectionList } from 'react-native';
|
|
16
18
|
import { Platform } from 'react-native';
|
|
17
19
|
|
|
18
|
-
import { createFastContext } from '../fast-context';
|
|
19
|
-
import useLatest from '../hooks/useLatest';
|
|
20
|
-
|
|
21
20
|
export type Store = {
|
|
22
21
|
currentIndex: number | null;
|
|
23
22
|
};
|
package/hooks/index.tsx
CHANGED
|
@@ -4,7 +4,6 @@ export * from './useActionState';
|
|
|
4
4
|
export * from './useActive';
|
|
5
5
|
export { default as useColorMode } from './useColorMode';
|
|
6
6
|
export { useContrastColor } from './useContrastColor';
|
|
7
|
-
export { default as useControlledValue } from './useControlledValue';
|
|
8
7
|
export * from './useFocus';
|
|
9
8
|
export {
|
|
10
9
|
type NumberMaskConfig,
|
|
@@ -13,10 +12,7 @@ export {
|
|
|
13
12
|
} from './useHandleNumberFormat';
|
|
14
13
|
export * from './useHover';
|
|
15
14
|
export * from './useKeyboardDismissable';
|
|
16
|
-
export
|
|
17
|
-
export { useMediaQuery } from './useMediaQuery';
|
|
18
|
-
export { useMergedRefs } from './useMergedRefs';
|
|
19
|
-
export { default as usePrevious } from './usePrevious';
|
|
15
|
+
export * from './useMediaQuery';
|
|
20
16
|
export * from './useQueryFilter';
|
|
21
17
|
export * from './useTheme';
|
|
22
|
-
export
|
|
18
|
+
export * from '@react-native-molecules/utils/hooks';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { resolveContrastColor } from '@react-native-molecules/utils/helpers/resolveContrastColor';
|
|
1
2
|
import { useMemo } from 'react';
|
|
2
3
|
import { useUnistyles } from 'react-native-unistyles';
|
|
3
4
|
|
|
4
|
-
import { resolveContrastColor } from '../utils/color';
|
|
5
|
-
|
|
6
5
|
export const useContrastColor = (bgColor: string, lightColor?: string, darkColor?: string) => {
|
|
7
6
|
const isDarkMode = useUnistyles().theme.dark;
|
|
8
7
|
|
package/hooks/useFilePicker.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNil, omitBy } from '@react-native-molecules/utils/helpers/lodash';
|
|
1
2
|
import { useCallback } from 'react';
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -5,7 +6,6 @@ import {
|
|
|
5
6
|
type DocumentPickerOptions,
|
|
6
7
|
type DocumentResult,
|
|
7
8
|
} from '../utils/DocumentPicker';
|
|
8
|
-
import { isNil, omitBy } from '../utils/lodash';
|
|
9
9
|
|
|
10
10
|
export const useFilePicker = (options: DocumentPickerOptions) => {
|
|
11
11
|
const openFilePicker = useCallback(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { isNil } from '@react-native-molecules/utils/helpers/lodash';
|
|
2
|
+
import { usePrevious } from '@react-native-molecules/utils/hooks';
|
|
1
3
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
4
|
import type { NativeSyntheticEvent, TextInputFocusEventData } from 'react-native';
|
|
3
5
|
|
|
4
6
|
import { formatNumberWithMask, normalizeToNumberString } from '../utils';
|
|
5
|
-
import { isNil } from '../utils/lodash';
|
|
6
|
-
import usePrevious from './usePrevious';
|
|
7
7
|
|
|
8
8
|
export type NumberMaskConfig = {
|
|
9
9
|
prefix?: string;
|
package/hooks/useMediaQuery.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { isNil } from '@react-native-molecules/utils/helpers/lodash';
|
|
1
2
|
import { useMemo } from 'react';
|
|
2
3
|
import { useWindowDimensions } from 'react-native';
|
|
3
4
|
|
|
4
|
-
import { isNil } from '../utils/lodash';
|
|
5
|
-
|
|
6
5
|
type Query = {
|
|
7
6
|
maxWidth?: number;
|
|
8
7
|
minWidth?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-molecules",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.24",
|
|
4
4
|
"author": "Thet Aung <thetaung.dev@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"perf": "npx reassure"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@react-native-molecules/utils": "workspace:^",
|
|
52
53
|
"@gorhom/portal": "^1.0.14",
|
|
53
54
|
"@radix-ui/react-compose-refs": "^1.1.2",
|
|
54
55
|
"@react-native-vector-icons/feather": "^12.4.0",
|
|
@@ -90,30 +91,5 @@
|
|
|
90
91
|
"test-cases/node_modules",
|
|
91
92
|
"dist",
|
|
92
93
|
"cache"
|
|
93
|
-
]
|
|
94
|
-
"react-native-builder-bob": {
|
|
95
|
-
"source": "src",
|
|
96
|
-
"output": "lib",
|
|
97
|
-
"targets": [
|
|
98
|
-
[
|
|
99
|
-
"commonjs",
|
|
100
|
-
{
|
|
101
|
-
"configFile": true
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
[
|
|
105
|
-
"module",
|
|
106
|
-
{
|
|
107
|
-
"configFile": true
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
[
|
|
111
|
-
"typescript",
|
|
112
|
-
{
|
|
113
|
-
"project": "tsconfig.build.json",
|
|
114
|
-
"rootDir": "src"
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
]
|
|
118
|
-
}
|
|
94
|
+
]
|
|
119
95
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { keyBy } from '@react-native-molecules/utils/helpers/lodash';
|
|
1
2
|
import { memo, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
3
|
|
|
3
|
-
import { keyBy } from '../../utils/lodash';
|
|
4
4
|
import EventsManager from '../EventsManager';
|
|
5
5
|
import type { Shortcut } from '../types';
|
|
6
6
|
import {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { createFastContext } from '@react-native-molecules/utils/fast-context';
|
|
1
2
|
import type { ReactNode } from 'react';
|
|
2
3
|
|
|
3
|
-
import { createFastContext } from '../../fast-context';
|
|
4
4
|
import type { Scope, Shortcut } from '../types';
|
|
5
5
|
|
|
6
6
|
export type ShortcutsManagerContextType = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { keyBy } from '@react-native-molecules/utils/helpers/lodash';
|
|
1
2
|
import { useCallback } from 'react';
|
|
2
3
|
|
|
3
|
-
import { keyBy } from '../../utils/lodash';
|
|
4
4
|
import { useShortcutsManagerStoreRef } from '../ShortcutsManager/utils';
|
|
5
5
|
import type { Scope } from '../types';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { useLatest } from '@react-native-molecules/utils/hooks';
|
|
1
2
|
import { useCallback, useEffect } from 'react';
|
|
2
3
|
|
|
3
|
-
import useLatest from '../../hooks/useLatest';
|
|
4
4
|
import { useShortcutsManagerStoreRef } from '../ShortcutsManager';
|
|
5
5
|
import type { ShortcutEventDetail } from '../types';
|
|
6
6
|
import { calculateShortcutEventName } from '../utils';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isNil } from '@react-native-molecules/utils/helpers/lodash';
|
|
2
|
+
|
|
1
3
|
import { createNumberMask, type CreateNumberMaskProps } from '../createNumberMask';
|
|
2
|
-
import { isNil } from '../lodash';
|
|
3
4
|
import { formatWithMask } from './formatWithMask';
|
|
4
5
|
|
|
5
6
|
export type FormatNumberWithMaskProps = CreateNumberMaskProps & {
|
package/utils/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { addEventListener, addListener } from './addEventListener';
|
|
2
2
|
export { BackgroundContext } from './backgroundContext';
|
|
3
|
-
export { default as color, resolveContrastColor } from './color';
|
|
4
|
-
export * from './compare';
|
|
5
3
|
export { default as composeEventHandlers } from './composeEventHandlers';
|
|
6
4
|
export { createNumberMask, type CreateNumberMaskProps } from './createNumberMask';
|
|
7
5
|
export * from './createSyntheticEvent';
|
|
@@ -16,5 +14,4 @@ export {
|
|
|
16
14
|
normalizeToNumberString,
|
|
17
15
|
type NormalizeToNumberStringProps,
|
|
18
16
|
} from './normalizeToNumberString';
|
|
19
|
-
export { Repository } from './repository';
|
|
20
17
|
export * from './resolveStateVariant';
|
package/context-bridge/index.tsx
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { ComponentType, Context as ContextType, PropsWithChildren } from 'react';
|
|
2
|
-
import { Fragment, useContext, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import typedMemo from '../hocs/typedMemo';
|
|
5
|
-
import { Repository } from '../utils/repository';
|
|
6
|
-
|
|
7
|
-
// https://github.com/pmndrs/its-fine/blob/main/src/index.tsx
|
|
8
|
-
// In development, React will warn about using contexts between renderers.
|
|
9
|
-
// Hide the warning because its-fine fixes this issue
|
|
10
|
-
// https://github.com/facebook/react/pull/12779
|
|
11
|
-
function wrapContext<T>(context: React.Context<T>): React.Context<T> {
|
|
12
|
-
try {
|
|
13
|
-
return Object.defineProperties(context, {
|
|
14
|
-
_currentRenderer: {
|
|
15
|
-
get() {
|
|
16
|
-
return null;
|
|
17
|
-
},
|
|
18
|
-
set() {},
|
|
19
|
-
},
|
|
20
|
-
_currentRenderer2: {
|
|
21
|
-
get() {
|
|
22
|
-
return null;
|
|
23
|
-
},
|
|
24
|
-
set() {},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
} catch (_) {
|
|
28
|
-
return context;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const createContextBridge = <T extends object>(
|
|
33
|
-
bridgeName: string,
|
|
34
|
-
Wrapper: ComponentType<T>,
|
|
35
|
-
contexts: ContextType<any>[] = [],
|
|
36
|
-
) => {
|
|
37
|
-
const respository = new Repository<ContextType<any>[]>({
|
|
38
|
-
name: bridgeName,
|
|
39
|
-
onRegister: (arg, name, registry) => {
|
|
40
|
-
return [registry[name] ?? [], arg].flat();
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
registerContextToBridge: (updatedContexts: ContextType<any> | ContextType<any>[]) => {
|
|
46
|
-
respository.register(
|
|
47
|
-
'contexts',
|
|
48
|
-
([] as ContextType<any>[])
|
|
49
|
-
.concat(updatedContexts)
|
|
50
|
-
.map(context => wrapContext(context)),
|
|
51
|
-
);
|
|
52
|
-
},
|
|
53
|
-
BridgedComponent: typedMemo((props: PropsWithChildren<T> & { name?: string }) => {
|
|
54
|
-
const { name, ...rest } = props;
|
|
55
|
-
const contextValuesRef = useRef<any[]>([]);
|
|
56
|
-
|
|
57
|
-
const id = useId();
|
|
58
|
-
|
|
59
|
-
const [allContexts] = useState(() =>
|
|
60
|
-
Array.from(new Set([...contexts, ...Object.values(respository.getAll()).flat()])),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
for (const i in allContexts) {
|
|
64
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
65
|
-
contextValuesRef.current[i] = useContext(allContexts[i]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const content = useMemo(() => {
|
|
69
|
-
return allContexts.reduce((acc, Context, currentIndex) => {
|
|
70
|
-
return (
|
|
71
|
-
<Context.Provider value={contextValuesRef.current[currentIndex]}>
|
|
72
|
-
{acc}
|
|
73
|
-
</Context.Provider>
|
|
74
|
-
);
|
|
75
|
-
}, <>{props.children}</>);
|
|
76
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
-
}, [...contextValuesRef.current, allContexts, props.children]);
|
|
78
|
-
|
|
79
|
-
const _key = name ? name + id : id;
|
|
80
|
-
return (
|
|
81
|
-
<Wrapper name={name} {...(rest as T)}>
|
|
82
|
-
<Fragment key={_key}>{content}</Fragment>
|
|
83
|
-
</Wrapper>
|
|
84
|
-
);
|
|
85
|
-
}),
|
|
86
|
-
};
|
|
87
|
-
};
|