react-native-molecules 0.5.0-beta.1 → 0.5.0-beta.10
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/index.tsx +1 -6
- package/components/Accordion/utils.ts +17 -14
- package/components/ActivityIndicator/ActivityIndicator.tsx +12 -20
- 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 +211 -264
- package/components/Button/index.tsx +9 -7
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +231 -210
- 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/Chip.tsx +40 -52
- package/components/Chip/index.tsx +1 -5
- package/components/Chip/utils.ts +5 -13
- 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 +1 -5
- package/components/DatePickerInput/utils.ts +5 -6
- package/components/DatePickerModal/DatePickerModalHeader.tsx +1 -1
- 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/ElementGroup.tsx +16 -14
- 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 +2 -6
- 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 +2 -4
- package/components/Icon/iconFactory.tsx +3 -3
- package/components/Icon/index.tsx +2 -6
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +45 -58
- package/components/IconButton/index.tsx +1 -5
- package/components/IconButton/utils.ts +15 -26
- 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 +2 -6
- package/components/ListItem/index.tsx +1 -5
- package/components/ListItem/utils.ts +13 -11
- package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
- package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
- package/components/LoadingIndicator/index.tsx +13 -0
- package/components/LoadingIndicator/utils.ts +117 -0
- 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/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 +1 -5
- package/components/RadioButton/utils.ts +9 -8
- package/components/Rating/index.tsx +1 -5
- package/components/Rating/utils.ts +6 -8
- package/components/Select/Select.tsx +360 -501
- package/components/Select/index.ts +7 -14
- package/components/Select/types.ts +2 -4
- package/components/Select/utils.ts +215 -0
- package/components/Slot/Slot.tsx +244 -0
- package/components/Slot/compose-refs.tsx +60 -0
- package/components/Slot/index.tsx +8 -0
- package/components/StateLayer/index.tsx +1 -5
- package/components/StateLayer/utils.ts +5 -6
- package/components/Surface/Surface.android.tsx +34 -8
- package/components/Surface/Surface.ios.tsx +36 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/index.tsx +1 -5
- package/components/Surface/utils.ts +49 -36
- package/components/Switch/Switch.tsx +8 -2
- package/components/Switch/index.tsx +1 -5
- package/components/Switch/utils.ts +2 -6
- 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 +5 -4
- 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/TimePickerModal.tsx +6 -2
- package/components/TimePickerModal/index.tsx +1 -5
- package/components/TimePickerModal/utils.ts +5 -6
- package/components/Tooltip/TooltipTrigger.tsx +25 -16
- package/components/Tooltip/index.tsx +1 -5
- package/components/Tooltip/utils.ts +5 -6
- package/components/TouchableRipple/TouchableRipple.native.tsx +49 -13
- package/components/TouchableRipple/TouchableRipple.tsx +136 -46
- 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/hocs/withPortal.tsx +1 -1
- package/hooks/useControlledValue.tsx +20 -4
- package/hooks/useSubcomponents.tsx +56 -22
- package/hooks/useWhatHasUpdated.tsx +48 -0
- package/package.json +10 -13
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
- package/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/extractPropertiesFromStyles.ts +25 -0
- package/utils/lodash.ts +77 -6
- package/utils/repository.ts +2 -52
|
@@ -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/hocs/withPortal.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
|
+
import useLatest from './useLatest';
|
|
4
|
+
|
|
3
5
|
type ReturnType<T> = [T, (value: T, ...args: any[]) => void];
|
|
4
6
|
|
|
5
7
|
type Args<T> = {
|
|
@@ -31,21 +33,35 @@ const useControlledValue = <T,>({
|
|
|
31
33
|
|
|
32
34
|
const isUncontrolled = useRef(valueProp).current === undefined;
|
|
33
35
|
const [uncontrolledValue, setValue] = useState(value);
|
|
36
|
+
const valuePropRef = useLatest(valueProp);
|
|
37
|
+
const onChangeRef = useLatest(onChange);
|
|
38
|
+
const manipulateValueRef = useLatest(manipulateValue);
|
|
39
|
+
const uncontrolledValueRef = useLatest(uncontrolledValue);
|
|
34
40
|
|
|
35
41
|
const updateValue = useCallback(
|
|
36
42
|
(val: T, ...rest: any[]) => {
|
|
37
43
|
if (disabled) return;
|
|
38
44
|
|
|
39
45
|
if (isUncontrolled) {
|
|
40
|
-
setValue(
|
|
46
|
+
setValue(manipulateValueRef.current(val, uncontrolledValueRef.current));
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
onChangeRef.current?.(
|
|
50
|
+
manipulateValueRef.current(
|
|
51
|
+
val,
|
|
52
|
+
isUncontrolled ? uncontrolledValueRef.current : valuePropRef.current,
|
|
53
|
+
),
|
|
45
54
|
...rest,
|
|
46
55
|
);
|
|
47
56
|
},
|
|
48
|
-
[
|
|
57
|
+
[
|
|
58
|
+
disabled,
|
|
59
|
+
isUncontrolled,
|
|
60
|
+
manipulateValueRef,
|
|
61
|
+
onChangeRef,
|
|
62
|
+
uncontrolledValueRef,
|
|
63
|
+
valuePropRef,
|
|
64
|
+
],
|
|
49
65
|
);
|
|
50
66
|
|
|
51
67
|
useEffect(() => {
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import { Children, type FC, isValidElement, useMemo } from 'react';
|
|
3
3
|
|
|
4
4
|
export type UseSubcomponentsProps<T extends string> = {
|
|
5
|
-
children:
|
|
5
|
+
children: ReactNode;
|
|
6
6
|
/**
|
|
7
7
|
* array of displayName as string
|
|
8
8
|
* */
|
|
9
9
|
allowedChildren: T[];
|
|
10
|
+
/**
|
|
11
|
+
* If true, also returns the remaining children that don't match any of the allowedChildren
|
|
12
|
+
* in a `rest` property
|
|
13
|
+
*/
|
|
14
|
+
includeRest?: boolean;
|
|
10
15
|
};
|
|
11
16
|
|
|
17
|
+
export type UseSubcomponentsResult<T extends string, IncludeRest extends boolean = false> = {
|
|
18
|
+
[key in T]: ReactElement[];
|
|
19
|
+
} & (IncludeRest extends true ? { rest: ReactNode[] } : {});
|
|
20
|
+
|
|
12
21
|
/**
|
|
13
22
|
* This will return an object with the displayNames as the property names
|
|
14
23
|
* eg. allowedChildren: ['Drawer_Header', 'Drawer_Content', 'Drawer_Footer', 'DrawerItem'];
|
|
@@ -19,41 +28,66 @@ export type UseSubcomponentsProps<T extends string> = {
|
|
|
19
28
|
* Drawer_Footer: [],
|
|
20
29
|
* DrawerItem: [],
|
|
21
30
|
* }
|
|
31
|
+
*
|
|
32
|
+
* If includeRest is true, also returns:
|
|
33
|
+
* {
|
|
34
|
+
* ...above,
|
|
35
|
+
* rest: [remaining children that don't match allowedChildren]
|
|
36
|
+
* }
|
|
22
37
|
* */
|
|
23
|
-
|
|
38
|
+
function useSubcomponents<T extends string = string, IncludeRest extends boolean = false>({
|
|
24
39
|
children,
|
|
25
40
|
allowedChildren,
|
|
26
|
-
|
|
41
|
+
includeRest,
|
|
42
|
+
}: UseSubcomponentsProps<T> & { includeRest?: IncludeRest }): UseSubcomponentsResult<
|
|
43
|
+
T,
|
|
44
|
+
IncludeRest
|
|
45
|
+
> {
|
|
27
46
|
return useMemo(() => {
|
|
28
47
|
// this will create properties with default empty array values even if they don't exist in the children
|
|
29
|
-
const defaultContext = allowedChildren.reduce(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
const defaultContext = allowedChildren.reduce(
|
|
49
|
+
(context, childName) => {
|
|
50
|
+
return {
|
|
51
|
+
...context,
|
|
52
|
+
[childName]: [],
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
includeRest ? { rest: [] as ReactNode[] } : {},
|
|
56
|
+
) as UseSubcomponentsResult<T, IncludeRest>;
|
|
37
57
|
|
|
38
|
-
|
|
39
|
-
if (!isValidElement(child)) return context;
|
|
58
|
+
const childArray = Children.toArray(children);
|
|
40
59
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
return childArray.reduce((context, child) => {
|
|
61
|
+
if (!isValidElement(child)) {
|
|
62
|
+
// Non-element children go to rest if includeRest is enabled
|
|
63
|
+
if (includeRest) {
|
|
64
|
+
return {
|
|
65
|
+
...context,
|
|
66
|
+
rest: [...(context as any).rest, child],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
44
69
|
return context;
|
|
45
70
|
}
|
|
46
71
|
|
|
47
|
-
const
|
|
72
|
+
const displayName = (child.type as FC)?.displayName as string | undefined;
|
|
48
73
|
|
|
49
|
-
if (!
|
|
74
|
+
if (!displayName || !allowedChildren.includes(displayName as T)) {
|
|
75
|
+
// Unmatched elements go to rest if includeRest is enabled
|
|
76
|
+
if (includeRest) {
|
|
77
|
+
return {
|
|
78
|
+
...context,
|
|
79
|
+
rest: [...(context as any).rest, child],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return context;
|
|
83
|
+
}
|
|
50
84
|
|
|
51
85
|
return {
|
|
52
86
|
...context,
|
|
53
|
-
[
|
|
87
|
+
[displayName]: [...(context as any)[displayName], child],
|
|
54
88
|
};
|
|
55
89
|
}, defaultContext);
|
|
56
|
-
}, [allowedChildren, children]);
|
|
57
|
-
}
|
|
90
|
+
}, [allowedChildren, children, includeRest]);
|
|
91
|
+
}
|
|
58
92
|
|
|
59
93
|
export default useSubcomponents;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import useLatest from './useLatest';
|
|
4
|
+
|
|
5
|
+
const map = new Map();
|
|
6
|
+
|
|
7
|
+
export const whatHasUpdatedFactory = <T extends Record<string, unknown>>(
|
|
8
|
+
name: string,
|
|
9
|
+
prevObject: T,
|
|
10
|
+
{ debug = false, useCached = false } = {},
|
|
11
|
+
) => {
|
|
12
|
+
const getPrev = () => {
|
|
13
|
+
if (!map.has(name)) map.set(name, prevObject);
|
|
14
|
+
return useCached ? map.get(name) : prevObject;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const setPrev = (value: T) => {
|
|
18
|
+
if (useCached) map.set(name, value);
|
|
19
|
+
else prevObject = value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (nextObject: T) => {
|
|
23
|
+
const old = getPrev();
|
|
24
|
+
const changes = Object.keys({ ...nextObject, ...old }).reduce((all, key) => {
|
|
25
|
+
const newValue = nextObject?.[key];
|
|
26
|
+
const oldValue = old[key];
|
|
27
|
+
if (oldValue === newValue) return all;
|
|
28
|
+
return { ...all, [key]: { newValue, oldValue } };
|
|
29
|
+
}, {});
|
|
30
|
+
|
|
31
|
+
setPrev(nextObject);
|
|
32
|
+
|
|
33
|
+
if (!debug && !Object.keys(changes).length) return;
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.log('🚨🕵️ UPDATED', name, changes);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const useWhatHasUpdated = (name: string, props: Record<string, any>) => {
|
|
40
|
+
const argRef = useLatest({ name, props });
|
|
41
|
+
const checkFunc = useMemo(
|
|
42
|
+
() => whatHasUpdatedFactory(argRef.current.name, argRef.current.props),
|
|
43
|
+
[argRef],
|
|
44
|
+
);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
checkFunc(props);
|
|
47
|
+
});
|
|
48
|
+
};
|
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.10",
|
|
4
4
|
"author": "Thet Aung <thetaung.dev@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -42,40 +42,37 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@gorhom/portal": "^1.0.14",
|
|
45
|
+
"@radix-ui/react-compose-refs": "^1.1.2",
|
|
45
46
|
"@react-native-vector-icons/feather": "^12.4.0",
|
|
46
47
|
"@react-native-vector-icons/material-design-icons": "^12.4.0",
|
|
47
48
|
"color": "^4.2.3",
|
|
48
49
|
"date-fns": "^4.1.0",
|
|
49
50
|
"eventemitter2": "^6.4.9",
|
|
50
|
-
"
|
|
51
|
-
"lodash.get": "^4.4.2",
|
|
52
|
-
"lodash.keyby": "^4.6.0",
|
|
53
|
-
"lodash.memoize": "^4.1.2",
|
|
54
|
-
"lodash.omitby": "^4.6.0",
|
|
51
|
+
"flubber": "^0.4.2",
|
|
55
52
|
"use-sync-external-store": "^1.2.0"
|
|
56
53
|
},
|
|
57
54
|
"peerDependencies": {
|
|
58
55
|
"@react-native-documents/picker": "^10.1.2",
|
|
59
56
|
"react": "19.1.0",
|
|
60
57
|
"react-native": "0.81.4",
|
|
58
|
+
"react-native-svg": ">=12.1.0",
|
|
61
59
|
"react-native-unistyles": "^3.0.15",
|
|
62
|
-
"react-native-web": "~0.21.1"
|
|
60
|
+
"react-native-web": "~0.21.1",
|
|
61
|
+
"react-native-reanimated": ">=4.0.0",
|
|
62
|
+
"react-native-redash": ">=18.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
+
"@types/flubber": "^0.4.0",
|
|
66
|
+
"react-native-svg": "^15.10.1",
|
|
65
67
|
"@react-native-documents/picker": "^10.1.2",
|
|
66
68
|
"@types/color": "^3.0.3",
|
|
67
69
|
"@types/jest": "^29.1.2",
|
|
68
|
-
"@types/lodash": "^4.17.13",
|
|
69
|
-
"@types/lodash.debounce": "^4.0.7",
|
|
70
|
-
"@types/lodash.get": "^4.4.7",
|
|
71
|
-
"@types/lodash.keyby": "^4.6.7",
|
|
72
|
-
"@types/lodash.memoize": "^4.1.7",
|
|
73
|
-
"@types/lodash.omitby": "^4.6.7",
|
|
74
70
|
"@types/react": "~19.1.10",
|
|
75
71
|
"@types/use-sync-external-store": "^1.5.0",
|
|
76
72
|
"react": "19.1.0",
|
|
77
73
|
"react-native": "0.81.4",
|
|
78
74
|
"react-native-builder-bob": "^0.17.1",
|
|
75
|
+
"react-native-reanimated": "~4.1.1",
|
|
79
76
|
"react-native-unistyles": "^3.0.15",
|
|
80
77
|
"react-native-web": "~0.21.1"
|
|
81
78
|
},
|
|
@@ -10,9 +10,12 @@ import {
|
|
|
10
10
|
type ShortcutsManagerProps,
|
|
11
11
|
} from './utils';
|
|
12
12
|
|
|
13
|
+
const defaultScopes: ShortcutsManagerProps['scopes'] = [];
|
|
14
|
+
const defaultShortcuts: Shortcut[] = [];
|
|
15
|
+
|
|
13
16
|
const _ShortcutsManager = ({ shortcuts, scopes, children }: ShortcutsManagerProps) => {
|
|
14
|
-
const shortcutsRef = useRef<Shortcut[]>(shortcuts ||
|
|
15
|
-
const scopesRef = useRef(scopes);
|
|
17
|
+
const shortcutsRef = useRef<Shortcut[]>(shortcuts || defaultShortcuts);
|
|
18
|
+
const scopesRef = useRef(scopes || defaultScopes);
|
|
16
19
|
const parentContextRef = useContext(ShortcutsManagerContext);
|
|
17
20
|
|
|
18
21
|
const contextValue = useMemo(() => {
|
package/styles/shadow.ts
CHANGED
|
@@ -8,7 +8,8 @@ export const inputRange: MD3Elevation[] = [0, 1, 2, 3, 4, 5];
|
|
|
8
8
|
export const shadowHeight = [0, 1, 2, 4, 6, 8];
|
|
9
9
|
export const shadowRadius = [0, 3, 6, 8, 10, 12];
|
|
10
10
|
|
|
11
|
-
export default function shadow(
|
|
11
|
+
export default function shadow(_elevation: number) {
|
|
12
|
+
const elevation = typeof _elevation === 'number' ? (_elevation > 5 ? 5 : _elevation) : 0;
|
|
12
13
|
return {
|
|
13
14
|
shadowColor: MD3_SHADOW_COLOR,
|
|
14
15
|
shadowOpacity: elevation ? MD3_SHADOW_OPACITY : 0,
|
|
@@ -25,7 +25,7 @@ export const generateLightThemeColors = (
|
|
|
25
25
|
error: palette.error40,
|
|
26
26
|
errorContainer: palette.error90,
|
|
27
27
|
onPrimary: palette.primary100,
|
|
28
|
-
onPrimaryContainer: palette.
|
|
28
|
+
onPrimaryContainer: palette.primary30,
|
|
29
29
|
onSecondary: palette.secondary100,
|
|
30
30
|
onSecondaryContainer: palette.secondary10,
|
|
31
31
|
onTertiary: palette.tertiary100,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
// TODO - abstract this
|
|
4
|
+
export function extractPropertiesFromStyles(
|
|
5
|
+
_objectsArray: Record<string, any>,
|
|
6
|
+
propertiesToExtract: string[],
|
|
7
|
+
) {
|
|
8
|
+
const extracted: Record<string, any> = {};
|
|
9
|
+
|
|
10
|
+
const objectsArray = StyleSheet.flatten(_objectsArray);
|
|
11
|
+
|
|
12
|
+
for (let i = objectsArray.length - 1; i >= 0; i--) {
|
|
13
|
+
const obj = objectsArray[i];
|
|
14
|
+
|
|
15
|
+
for (const prop of propertiesToExtract) {
|
|
16
|
+
if (!obj) continue;
|
|
17
|
+
if (prop in obj) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
extracted[prop] = obj[prop];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return extracted;
|
|
25
|
+
}
|
package/utils/lodash.ts
CHANGED
|
@@ -1,9 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
type MemoizeCache<K = any, V = any> = {
|
|
2
|
+
has(key: K): boolean;
|
|
3
|
+
get(key: K): V | undefined;
|
|
4
|
+
set(key: K, value: V): unknown;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type MemoizeFn = {
|
|
8
|
+
<T extends (...args: any[]) => any>(
|
|
9
|
+
func: T,
|
|
10
|
+
resolver?: (...args: Parameters<T>) => any,
|
|
11
|
+
): MemoizedFunction<T>;
|
|
12
|
+
Cache: { new (): MemoizeCache<any, any> };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface MemoizedFunction<T extends (...args: any[]) => any> {
|
|
16
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
17
|
+
cache: MemoizeCache<any, ReturnType<T>>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const memoize: MemoizeFn = ((
|
|
21
|
+
func: (...args: any[]) => any,
|
|
22
|
+
resolver?: (...args: any[]) => any,
|
|
23
|
+
) => {
|
|
24
|
+
if (typeof func !== 'function') {
|
|
25
|
+
throw new TypeError('Expected a function');
|
|
26
|
+
}
|
|
27
|
+
const memoized = function (this: unknown, ...args: any[]) {
|
|
28
|
+
const key = resolver ? resolver.apply(this, args) : args[0];
|
|
29
|
+
const { cache } = memoized as MemoizedFunction<typeof func>;
|
|
30
|
+
if (cache.has(key)) {
|
|
31
|
+
return cache.get(key);
|
|
32
|
+
}
|
|
33
|
+
const result = func.apply(this, args);
|
|
34
|
+
cache.set(key, result);
|
|
35
|
+
return result;
|
|
36
|
+
} as MemoizedFunction<typeof func>;
|
|
37
|
+
|
|
38
|
+
(memoized as MemoizedFunction<typeof func>).cache = new memoize.Cache();
|
|
39
|
+
return memoized;
|
|
40
|
+
}) as MemoizeFn;
|
|
41
|
+
|
|
42
|
+
memoize.Cache = Map;
|
|
43
|
+
|
|
44
|
+
type Iteratee<T> = ((item: T) => string | number | symbol) | keyof T;
|
|
45
|
+
|
|
46
|
+
export const keyBy = <T extends Record<string, any>>(
|
|
47
|
+
collection: T[],
|
|
48
|
+
iteratee: Iteratee<T>,
|
|
49
|
+
): Record<string, T> => {
|
|
50
|
+
const result: Record<string, T> = {};
|
|
51
|
+
if (!Array.isArray(collection)) return result;
|
|
52
|
+
|
|
53
|
+
const getter = typeof iteratee === 'function' ? iteratee : (item: T) => item[iteratee];
|
|
54
|
+
for (const item of collection) {
|
|
55
|
+
const key = getter(item);
|
|
56
|
+
if (key != null) {
|
|
57
|
+
result[String(key)] = item;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type Predicate = (value: any, key: string) => boolean;
|
|
64
|
+
|
|
65
|
+
export const omitBy = <T extends Record<string, any>>(
|
|
66
|
+
object: T,
|
|
67
|
+
predicate: Predicate,
|
|
68
|
+
): Partial<T> => {
|
|
69
|
+
if (object == null) return {};
|
|
70
|
+
const result: Partial<T> = {};
|
|
71
|
+
for (const [key, value] of Object.entries(object)) {
|
|
72
|
+
if (!predicate(value, key)) {
|
|
73
|
+
result[key as keyof T] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
7
78
|
|
|
8
79
|
export const isNil = (value: unknown): value is null | undefined => value == null;
|
|
9
80
|
export const noop = () => {};
|
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
|
}
|