react-native-molecules 0.5.0-beta.0 → 0.5.0-beta.2
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/README.md +87 -0
- package/components/Accordion/AccordionItem.tsx +3 -2
- package/components/Accordion/AccordionItemContent.tsx +1 -0
- package/components/Accordion/AccordionItemHeader.tsx +6 -5
- package/components/Accordion/index.tsx +8 -14
- package/components/Accordion/utils.ts +17 -14
- package/components/ActivityIndicator/ActivityIndicator.tsx +6 -5
- package/components/ActivityIndicator/index.tsx +1 -5
- package/components/Appbar/index.tsx +1 -4
- package/components/Appbar/utils.ts +33 -21
- package/components/Avatar/index.tsx +1 -5
- package/components/Avatar/utils.ts +2 -6
- package/components/Backdrop/Backdrop.tsx +2 -2
- package/components/Backdrop/index.tsx +1 -5
- package/components/Backdrop/utils.ts +5 -6
- package/components/Badge/index.tsx +1 -5
- package/components/Badge/utils.ts +2 -6
- package/components/Button/Button.tsx +3 -1
- package/components/Button/index.tsx +1 -5
- package/components/Button/utils.ts +5 -8
- package/components/Card/Card.tsx +8 -4
- package/components/Card/CardContent.tsx +5 -4
- package/components/Card/CardHeader.tsx +5 -3
- package/components/Card/CardMedia.tsx +5 -3
- package/components/Card/CardTypography.tsx +5 -3
- package/components/Card/index.tsx +1 -5
- package/components/Card/utils.ts +5 -6
- package/components/Checkbox/Checkbox.tsx +1 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +1 -0
- package/components/Checkbox/CheckboxBase.tsx +1 -0
- package/components/Checkbox/index.tsx +1 -5
- package/components/Checkbox/utils.ts +6 -6
- package/components/Chip/index.tsx +1 -5
- package/components/Chip/utils.ts +2 -6
- package/components/DatePickerDocked/index.tsx +1 -5
- package/components/DatePickerDocked/utils.ts +21 -19
- package/components/DatePickerInline/index.tsx +1 -5
- package/components/DatePickerInline/utils.ts +41 -28
- package/components/DatePickerInput/index.tsx +2 -6
- package/components/DatePickerInput/utils.ts +5 -6
- package/components/DatePickerModal/index.tsx +1 -5
- package/components/DatePickerModal/utils.ts +17 -16
- package/components/DateTimePicker/index.tsx +1 -5
- package/components/DateTimePicker/utils.ts +5 -6
- package/components/Dialog/index.tsx +1 -5
- package/components/Dialog/utils.ts +22 -16
- package/components/Drawer/Collapsible/utils.ts +13 -13
- package/components/Drawer/Drawer.tsx +2 -3
- package/components/Drawer/DrawerContent.tsx +5 -3
- package/components/Drawer/DrawerFooter.tsx +5 -4
- package/components/Drawer/DrawerHeader.tsx +5 -4
- package/components/Drawer/DrawerItem.tsx +5 -3
- package/components/Drawer/DrawerItemGroup.tsx +5 -4
- package/components/Drawer/index.tsx +1 -5
- package/components/Drawer/utils.ts +7 -7
- package/components/ElementGroup/index.tsx +1 -5
- package/components/ElementGroup/utils.ts +5 -6
- package/components/FAB/index.tsx +1 -5
- package/components/FAB/utils.ts +3 -7
- package/components/FilePicker/index.tsx +1 -5
- package/components/FilePicker/utils.ts +5 -6
- package/components/HelperText/index.tsx +1 -5
- package/components/HelperText/utils.ts +5 -7
- package/components/HorizontalDivider/HorizontalDivider.tsx +5 -3
- package/components/HorizontalDivider/index.tsx +1 -5
- package/components/Icon/CrossFadeIcon.tsx +3 -5
- package/components/Icon/Icon.tsx +3 -14
- package/components/Icon/index.tsx +1 -5
- package/components/IconButton/IconButton.tsx +3 -1
- package/components/IconButton/index.tsx +1 -5
- package/components/IconButton/utils.ts +11 -16
- package/components/If/index.tsx +1 -5
- package/components/InputAddon/index.tsx +1 -5
- package/components/InputAddon/utils.ts +5 -6
- package/components/Link/index.tsx +1 -5
- package/components/Link/utils.ts +7 -9
- package/components/ListItem/index.tsx +1 -5
- package/components/ListItem/utils.ts +13 -11
- package/components/Menu/index.tsx +1 -5
- package/components/Menu/utils.ts +6 -8
- package/components/Modal/index.tsx +1 -5
- package/components/Modal/utils.ts +2 -6
- package/components/NavigationRail/NavigationRailHeader.tsx +1 -1
- package/components/NavigationRail/NavigationRailItem.tsx +2 -1
- package/components/NavigationRail/index.tsx +1 -5
- package/components/NavigationRail/utils.ts +21 -17
- package/components/NavigationStack/index.tsx +1 -5
- package/components/NavigationStack/utils.tsx +7 -1
- package/components/Portal/index.tsx +1 -5
- package/components/RadioButton/index.ts +5 -10
- package/components/RadioButton/utils.ts +9 -8
- package/components/Rating/RatingItem.tsx +2 -1
- package/components/Rating/index.tsx +1 -5
- package/components/Rating/utils.ts +6 -8
- package/components/StateLayer/index.tsx +1 -5
- package/components/StateLayer/utils.ts +5 -6
- package/components/Surface/index.tsx +1 -5
- package/components/Surface/utils.ts +5 -6
- package/components/Switch/index.tsx +1 -5
- package/components/Switch/utils.ts +2 -6
- package/components/Tabs/Tabs.tsx +14 -13
- package/components/Tabs/index.tsx +1 -5
- package/components/Tabs/utils.ts +10 -10
- package/components/Text/Text.tsx +2 -8
- package/components/TextInput/TextInput.tsx +1 -0
- package/components/TextInput/index.tsx +1 -5
- package/components/TextInput/utils.ts +8 -15
- package/components/TextInputWithMask/index.tsx +1 -5
- package/components/TimePicker/AmPmSwitcher.tsx +1 -1
- package/components/TimePicker/index.tsx +1 -5
- package/components/TimePicker/utils.ts +29 -21
- package/components/TimePickerField/index.tsx +1 -5
- package/components/TimePickerField/utils.ts +5 -6
- package/components/TimePickerModal/index.tsx +1 -5
- package/components/TimePickerModal/utils.ts +5 -6
- package/components/Tooltip/index.tsx +5 -9
- package/components/Tooltip/utils.ts +5 -6
- package/components/TouchableRipple/index.tsx +1 -5
- package/components/TouchableRipple/utils.ts +5 -6
- package/components/VerticalDivider/VerticalDivider.tsx +9 -8
- package/components/VerticalDivider/index.tsx +1 -5
- package/core/componentsRegistry.ts +31 -19
- package/hooks/index.tsx +0 -1
- package/package.json +1 -3
- package/shortcuts-manager/ShortcutsManager/utils.tsx +3 -2
- package/shortcuts-manager/useShortcut/index.tsx +1 -1
- package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
- package/utils/lodash.ts +0 -1
- package/utils/repository.ts +2 -52
- package/utils/tokenStylesParser.ts +3 -1
- package/hooks/useBreakpoints.tsx +0 -7
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
2
|
import TimePickerFieldDefault from './TimePickerField';
|
|
3
3
|
|
|
4
|
-
registerMoleculesComponents({
|
|
5
|
-
TimePickerField: TimePickerFieldDefault,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
4
|
export const TimePickerField = getRegisteredComponentWithFallback(
|
|
9
5
|
'TimePickerField',
|
|
10
6
|
TimePickerFieldDefault,
|
|
@@ -5,17 +5,16 @@ export declare type MaskItem = string | RegExp | [RegExp];
|
|
|
5
5
|
export declare type MaskArray = Array<MaskItem>;
|
|
6
6
|
export declare type Mask = MaskArray | ((value?: string) => MaskArray);
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
9
9
|
|
|
10
10
|
const timepickerFieldStylesDefault = StyleSheet.create({
|
|
11
11
|
root: {},
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
TimePickerField
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export const styles = getRegisteredMoleculesComponentStyles('TimePickerField');
|
|
14
|
+
export const styles = getRegisteredComponentStylesWithFallback(
|
|
15
|
+
'TimePickerField',
|
|
16
|
+
timepickerFieldStylesDefault,
|
|
17
|
+
);
|
|
19
18
|
|
|
20
19
|
export const timeMask24Hour: Mask = (text: string = '') => {
|
|
21
20
|
const cleanTime = text.replace(/\D+/g, '');
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
2
|
import TimePickerModalDefault from './TimePickerModal';
|
|
3
3
|
|
|
4
|
-
registerMoleculesComponents({
|
|
5
|
-
TimePickerModal: TimePickerModalDefault,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
4
|
export const TimePickerModal = getRegisteredComponentWithFallback(
|
|
9
5
|
'TimePickerModal',
|
|
10
6
|
TimePickerModalDefault,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native-unistyles';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
4
|
|
|
5
5
|
const timepickerModalStylesDefault = StyleSheet.create(theme => ({
|
|
6
6
|
keyboardView: {
|
|
@@ -41,8 +41,7 @@ const timepickerModalStylesDefault = StyleSheet.create(theme => ({
|
|
|
41
41
|
fill: { flex: 1 },
|
|
42
42
|
}));
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
TimePickerModal
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export const styles = getRegisteredMoleculesComponentStyles('TimePickerModal');
|
|
44
|
+
export const styles = getRegisteredComponentStylesWithFallback(
|
|
45
|
+
'TimePickerModal',
|
|
46
|
+
timepickerModalStylesDefault,
|
|
47
|
+
);
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
2
|
import TooltipComponent from './Tooltip';
|
|
3
|
-
import TooltipTrigger from './TooltipTrigger';
|
|
4
3
|
import TooltipContent from './TooltipContent';
|
|
4
|
+
import TooltipTrigger from './TooltipTrigger';
|
|
5
5
|
|
|
6
6
|
export const TooltipDefault = Object.assign(TooltipComponent, {
|
|
7
7
|
Trigger: TooltipTrigger,
|
|
8
8
|
Content: TooltipContent,
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
registerMoleculesComponents({
|
|
12
|
-
Tooltip: TooltipDefault,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
11
|
export const Tooltip = getRegisteredComponentWithFallback('Tooltip', TooltipDefault);
|
|
16
12
|
|
|
17
|
-
export { Props as TooltipProps } from './Tooltip';
|
|
18
|
-
export { Props as
|
|
19
|
-
export { Props as
|
|
13
|
+
export type { Props as TooltipProps } from './Tooltip';
|
|
14
|
+
export type { Props as TooltipContentProps } from './TooltipContent';
|
|
15
|
+
export type { Props as TooltipTriggerProps } from './TooltipTrigger';
|
|
20
16
|
export { tooltipStyles } from './utils';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native-unistyles';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
4
|
|
|
5
5
|
const tooltipStylesDefault = StyleSheet.create(theme => ({
|
|
6
6
|
content: {
|
|
@@ -14,8 +14,7 @@ const tooltipStylesDefault = StyleSheet.create(theme => ({
|
|
|
14
14
|
},
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
Tooltip
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export const tooltipStyles = getRegisteredMoleculesComponentStyles('Tooltip');
|
|
17
|
+
export const tooltipStyles = getRegisteredComponentStylesWithFallback(
|
|
18
|
+
'Tooltip',
|
|
19
|
+
tooltipStylesDefault,
|
|
20
|
+
);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
2
|
import TouchableRippleDefault from './TouchableRipple';
|
|
3
3
|
|
|
4
|
-
registerMoleculesComponents({
|
|
5
|
-
TouchableRipple: TouchableRippleDefault,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
4
|
export const TouchableRipple = getRegisteredComponentWithFallback(
|
|
9
5
|
'TouchableRipple',
|
|
10
6
|
TouchableRippleDefault,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native-unistyles';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
4
|
|
|
5
5
|
const touchableRippleStylesDefault = StyleSheet.create(theme => ({
|
|
6
6
|
root: {
|
|
@@ -8,8 +8,7 @@ const touchableRippleStylesDefault = StyleSheet.create(theme => ({
|
|
|
8
8
|
} as any,
|
|
9
9
|
}));
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
TouchableRipple
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const touchableRippleStyles = getRegisteredMoleculesComponentStyles('TouchableRipple');
|
|
11
|
+
export const touchableRippleStyles = getRegisteredComponentStylesWithFallback(
|
|
12
|
+
'TouchableRipple',
|
|
13
|
+
touchableRippleStylesDefault,
|
|
14
|
+
);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { memo } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
3
|
import { StyleSheet } from 'react-native-unistyles';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
6
6
|
|
|
7
7
|
export type Props = Omit<ViewProps, 'children'> & {
|
|
8
8
|
/**
|
|
@@ -21,7 +21,6 @@ export type Props = Omit<ViewProps, 'children'> & {
|
|
|
21
21
|
* Horizontal spacing of the Divider
|
|
22
22
|
*/
|
|
23
23
|
spacing?: number;
|
|
24
|
-
style?: StyleProp<ViewStyle>;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
/**
|
|
@@ -70,9 +69,9 @@ const VerticalDivider = ({
|
|
|
70
69
|
style={[
|
|
71
70
|
verticalDividerStyles.root,
|
|
72
71
|
style,
|
|
73
|
-
topInset
|
|
74
|
-
bottomInset
|
|
75
|
-
spacing
|
|
72
|
+
topInset ? { marginTop: topInset } : undefined,
|
|
73
|
+
bottomInset ? { marginBottom: bottomInset } : undefined,
|
|
74
|
+
spacing ? { marginHorizontal: spacing } : undefined,
|
|
76
75
|
]}
|
|
77
76
|
/>
|
|
78
77
|
);
|
|
@@ -93,7 +92,9 @@ export const verticalDividerStylesDefault = StyleSheet.create(theme => ({
|
|
|
93
92
|
},
|
|
94
93
|
}));
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
export const verticalDividerStyles = getRegisteredComponentStylesWithFallback(
|
|
96
|
+
'VerticalDivider',
|
|
97
|
+
verticalDividerStylesDefault,
|
|
98
|
+
);
|
|
98
99
|
|
|
99
100
|
export default memo(VerticalDivider);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
2
|
import VerticalDividerDefault from './VerticalDivider';
|
|
3
3
|
|
|
4
|
-
registerMoleculesComponents({
|
|
5
|
-
VerticalDivider: VerticalDividerDefault,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
4
|
export const VerticalDivider = getRegisteredComponentWithFallback(
|
|
9
5
|
'VerticalDivider',
|
|
10
6
|
VerticalDividerDefault,
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import EventEmitter, {
|
|
2
|
-
type ConstructorOptions,
|
|
3
|
-
type event as Event,
|
|
4
|
-
type eventNS,
|
|
5
|
-
} from 'eventemitter2';
|
|
6
1
|
import type { ComponentType } from 'react';
|
|
7
2
|
|
|
8
|
-
interface RepositoryConstructor<T>
|
|
3
|
+
interface RepositoryConstructor<T> {
|
|
9
4
|
onRegister?: (arg: T, name: string, registery: Record<string, T>) => T;
|
|
10
5
|
name?: string;
|
|
11
6
|
}
|
|
12
7
|
|
|
13
8
|
let id = Date.now();
|
|
14
9
|
|
|
15
|
-
export class Repository<T>
|
|
10
|
+
export class Repository<T> {
|
|
16
11
|
private registry: Record<string, T> = {};
|
|
17
12
|
readonly #name!: string;
|
|
18
13
|
|
|
@@ -29,9 +24,7 @@ export class Repository<T> extends EventEmitter {
|
|
|
29
24
|
constructor({
|
|
30
25
|
onRegister = arg => arg,
|
|
31
26
|
name = Repository.uniqueId,
|
|
32
|
-
...options
|
|
33
27
|
}: RepositoryConstructor<T> = {}) {
|
|
34
|
-
super(options);
|
|
35
28
|
this.#onRegister = onRegister;
|
|
36
29
|
this.#name = name;
|
|
37
30
|
}
|
|
@@ -40,11 +33,6 @@ export class Repository<T> extends EventEmitter {
|
|
|
40
33
|
return !!this.registry[itemName];
|
|
41
34
|
};
|
|
42
35
|
|
|
43
|
-
emit(event: eventNS | Event, ...values: any[]) {
|
|
44
|
-
event = typeof event === 'string' ? `${this.#name}::event` : event;
|
|
45
|
-
return super.emit(event, ...values);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
36
|
/**
|
|
49
37
|
* Register a item with the src.
|
|
50
38
|
*/
|
|
@@ -58,8 +46,6 @@ export class Repository<T> extends EventEmitter {
|
|
|
58
46
|
...this.registry,
|
|
59
47
|
[itemName]: updatedItem,
|
|
60
48
|
};
|
|
61
|
-
|
|
62
|
-
this.emit('item_registered', itemName);
|
|
63
49
|
};
|
|
64
50
|
|
|
65
51
|
/**
|
|
@@ -92,17 +78,14 @@ export class Repository<T> extends EventEmitter {
|
|
|
92
78
|
|
|
93
79
|
export const componentsRepository = new Repository<Record<string, any>>({
|
|
94
80
|
name: 'Components_Repository',
|
|
95
|
-
maxListeners: 0,
|
|
96
81
|
});
|
|
97
82
|
|
|
98
83
|
export const componentsStylesRepository = new Repository<Record<string, any>>({
|
|
99
84
|
name: 'Components_Styles_Repository',
|
|
100
|
-
maxListeners: 0,
|
|
101
85
|
});
|
|
102
86
|
|
|
103
87
|
export const componentsUtilsRepository = new Repository<Record<string, any>>({
|
|
104
88
|
name: 'Components_Utils_Repository',
|
|
105
|
-
maxListeners: 0,
|
|
106
89
|
});
|
|
107
90
|
|
|
108
91
|
export const registerMoleculesComponent = componentsRepository.registerOne;
|
|
@@ -162,3 +145,32 @@ export function getRegisteredComponentWithFallback<T extends ComponentType<any>>
|
|
|
162
145
|
): T {
|
|
163
146
|
return (getRegisteredMoleculesComponent(name) ?? defaultComponent) as T;
|
|
164
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gets a registered component with a fallback to the default component
|
|
151
|
+
* @param name The name of the component to retrieve
|
|
152
|
+
* @param defaultStyles The default styles to use as fallback
|
|
153
|
+
* @returns The registered styles or the default styles
|
|
154
|
+
*/
|
|
155
|
+
export function getRegisteredComponentStylesWithFallback<T extends unknown>(
|
|
156
|
+
name: string,
|
|
157
|
+
defaultStyles: T,
|
|
158
|
+
): T {
|
|
159
|
+
return (getRegisteredMoleculesComponentStyles(name) ?? defaultStyles) as T;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Gets a registered component with a fallback to the default component
|
|
164
|
+
* @param name The name of the component to retrieve
|
|
165
|
+
* @param defaultUtils The default utils to use as fallback
|
|
166
|
+
* @returns The registered utils or the default utils
|
|
167
|
+
*/
|
|
168
|
+
export function getRegisteredComponentUtilsWithFallback<T extends unknown>(
|
|
169
|
+
name: string,
|
|
170
|
+
defaultUtils: T,
|
|
171
|
+
key?: string,
|
|
172
|
+
): T {
|
|
173
|
+
return key
|
|
174
|
+
? (((getRegisteredComponentUtils(name) as Record<string, any>)?.[key] ?? defaultUtils) as T)
|
|
175
|
+
: ((getRegisteredComponentUtils(name) ?? defaultUtils) as T);
|
|
176
|
+
}
|
package/hooks/index.tsx
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
export * from './useActionState';
|
|
4
4
|
export * from './useActive';
|
|
5
|
-
export { default as useBreakpoints } from './useBreakpoints';
|
|
6
5
|
export { default as useColorMode } from './useColorMode';
|
|
7
6
|
export { useContrastColor } from './useContrastColor';
|
|
8
7
|
export { default as useControlledValue } from './useControlledValue';
|
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.2",
|
|
4
4
|
"author": "Thet Aung <thetaung.dev@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"color": "^4.2.3",
|
|
48
48
|
"date-fns": "^4.1.0",
|
|
49
49
|
"eventemitter2": "^6.4.9",
|
|
50
|
-
"lodash.debounce": "^4.0.8",
|
|
51
50
|
"lodash.get": "^4.4.2",
|
|
52
51
|
"lodash.keyby": "^4.6.0",
|
|
53
52
|
"lodash.memoize": "^4.1.2",
|
|
@@ -66,7 +65,6 @@
|
|
|
66
65
|
"@types/color": "^3.0.3",
|
|
67
66
|
"@types/jest": "^29.1.2",
|
|
68
67
|
"@types/lodash": "^4.17.13",
|
|
69
|
-
"@types/lodash.debounce": "^4.0.7",
|
|
70
68
|
"@types/lodash.get": "^4.4.7",
|
|
71
69
|
"@types/lodash.keyby": "^4.6.7",
|
|
72
70
|
"@types/lodash.memoize": "^4.1.7",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Scope, Shortcut } from '../types';
|
|
2
|
-
import { createFastContext } from '../../fast-context';
|
|
3
1
|
import type { ReactNode } from 'react';
|
|
4
2
|
|
|
3
|
+
import { createFastContext } from '../../fast-context';
|
|
4
|
+
import type { Scope, Shortcut } from '../types';
|
|
5
|
+
|
|
5
6
|
export type ShortcutsManagerContextType = {
|
|
6
7
|
shortcuts: Record<string, Shortcut>;
|
|
7
8
|
scopes: Record<string, Scope>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect } from 'react';
|
|
2
|
-
import useLatest from '../../hooks/useLatest';
|
|
3
2
|
|
|
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';
|
package/utils/lodash.ts
CHANGED
package/utils/repository.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
type ConstructorOptions,
|
|
3
|
-
type event as Event,
|
|
4
|
-
type eventNS,
|
|
5
|
-
} from 'eventemitter2';
|
|
6
|
-
|
|
7
|
-
import { debounce } from './lodash';
|
|
8
|
-
|
|
9
|
-
interface RepositoryConstructor<T> extends ConstructorOptions {
|
|
1
|
+
interface RepositoryConstructor<T> {
|
|
10
2
|
onRegister?: (arg: T, name: string, registery: Record<string, T>) => T;
|
|
11
3
|
name?: string;
|
|
12
4
|
}
|
|
13
5
|
|
|
14
6
|
let id = Date.now();
|
|
15
7
|
|
|
16
|
-
export class Repository<T>
|
|
8
|
+
export class Repository<T> {
|
|
17
9
|
private registry: Record<string, T> = {};
|
|
18
10
|
readonly #name!: string;
|
|
19
11
|
|
|
@@ -30,9 +22,7 @@ export class Repository<T> extends EventEmitter {
|
|
|
30
22
|
constructor({
|
|
31
23
|
onRegister = arg => arg,
|
|
32
24
|
name = Repository.uniqueId,
|
|
33
|
-
...options
|
|
34
25
|
}: RepositoryConstructor<T> = {}) {
|
|
35
|
-
super(options);
|
|
36
26
|
this.#onRegister = onRegister;
|
|
37
27
|
this.#name = name;
|
|
38
28
|
}
|
|
@@ -41,11 +31,6 @@ export class Repository<T> extends EventEmitter {
|
|
|
41
31
|
return !!this.registry[itemName];
|
|
42
32
|
};
|
|
43
33
|
|
|
44
|
-
emit(event: eventNS | Event, ...values: any[]) {
|
|
45
|
-
event = typeof event === 'string' ? `${this.#name}::event` : event;
|
|
46
|
-
return super.emit(event, ...values);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
34
|
/**
|
|
50
35
|
* Register a item with the src.
|
|
51
36
|
*/
|
|
@@ -57,8 +42,6 @@ export class Repository<T> extends EventEmitter {
|
|
|
57
42
|
...this.registry,
|
|
58
43
|
[itemName]: updatedItem,
|
|
59
44
|
};
|
|
60
|
-
|
|
61
|
-
this.emit('item_registered', itemName);
|
|
62
45
|
};
|
|
63
46
|
|
|
64
47
|
/**
|
|
@@ -67,37 +50,4 @@ export class Repository<T> extends EventEmitter {
|
|
|
67
50
|
getAll = () => {
|
|
68
51
|
return this.registry;
|
|
69
52
|
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Register a listener to the module registry.
|
|
73
|
-
* Return value returns a function that removes the listener.
|
|
74
|
-
*/
|
|
75
|
-
listen = (
|
|
76
|
-
callback: (events: string[]) => void,
|
|
77
|
-
{ throttle = 100 }: { throttle?: number } = {},
|
|
78
|
-
) => {
|
|
79
|
-
let cached: string[] = [];
|
|
80
|
-
|
|
81
|
-
const wrappedCallback = () => {
|
|
82
|
-
callback(cached);
|
|
83
|
-
cached = [];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const debouncedCallback = !throttle
|
|
87
|
-
? wrappedCallback
|
|
88
|
-
: debounce(wrappedCallback, Math.abs(throttle), {
|
|
89
|
-
trailing: true,
|
|
90
|
-
leading: false,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const handledCallback = (itemName: string) => {
|
|
94
|
-
cached.push(itemName);
|
|
95
|
-
debouncedCallback();
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
this.on('item_registered', handledCallback);
|
|
99
|
-
return () => {
|
|
100
|
-
this.off('item_registered', handledCallback);
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
53
|
}
|
|
@@ -2,6 +2,8 @@ import { StyleSheet } from 'react-native-unistyles';
|
|
|
2
2
|
|
|
3
3
|
export const tokenStylesParser = StyleSheet.create(theme => ({
|
|
4
4
|
getColor: (color: string | undefined, propertyName: string = 'color') => ({
|
|
5
|
-
...(color
|
|
5
|
+
...(color
|
|
6
|
+
? { [propertyName]: theme.colors[color as keyof typeof theme.colors] ?? color }
|
|
7
|
+
: {}),
|
|
6
8
|
}),
|
|
7
9
|
}));
|