react-native-molecules 0.5.0-beta.3 → 0.5.0-beta.4
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.
|
@@ -3,7 +3,7 @@ import React, {
|
|
|
3
3
|
memo,
|
|
4
4
|
type PropsWithoutRef,
|
|
5
5
|
type ReactNode,
|
|
6
|
-
type
|
|
6
|
+
type Ref,
|
|
7
7
|
useCallback,
|
|
8
8
|
useContext,
|
|
9
9
|
useEffect,
|
|
@@ -50,7 +50,7 @@ type Element = ReactNode | ((props: ElementProps) => ReactNode);
|
|
|
50
50
|
|
|
51
51
|
export type Props = Omit<TextInputProps, 'ref'> &
|
|
52
52
|
WithElements<Element> & {
|
|
53
|
-
ref?:
|
|
53
|
+
ref?: Ref<NativeTextInput | null>;
|
|
54
54
|
/**
|
|
55
55
|
* Variant of the TextInput.
|
|
56
56
|
* - `flat` - flat input with an underline.
|
|
@@ -30,27 +30,36 @@ const TooltipTrigger = memo(({ children }: { children: ReactElement }) => {
|
|
|
30
30
|
() => triggerRef?.current,
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
-
const onPress = useCallback(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const onPress = useCallback(
|
|
34
|
+
(e: unknown) => {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
children?.props?.onPress?.(e);
|
|
37
|
+
},
|
|
38
|
+
[children?.props],
|
|
39
|
+
);
|
|
37
40
|
|
|
38
|
-
const onLongPress = useCallback(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
const onLongPress = useCallback(
|
|
42
|
+
(e: unknown) => {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
children?.props?.onLongPress?.(e);
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
if (isWeb) return;
|
|
47
|
+
onOpen();
|
|
48
|
+
},
|
|
49
|
+
[children?.props, isWeb, onOpen],
|
|
50
|
+
);
|
|
45
51
|
|
|
46
|
-
const onPressOut = useCallback(
|
|
47
|
-
|
|
52
|
+
const onPressOut = useCallback(
|
|
53
|
+
(e: unknown) => {
|
|
54
|
+
// @ts-ignore
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
children?.props?.onPressOut?.(e);
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
if (isWeb) return;
|
|
59
|
+
onClose();
|
|
60
|
+
},
|
|
61
|
+
[children?.props, isWeb, onClose],
|
|
62
|
+
);
|
|
54
63
|
|
|
55
64
|
const onHoverIn = useCallback(() => {
|
|
56
65
|
// @ts-ignore
|
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.4",
|
|
4
4
|
"author": "Thet Aung <thetaung.dev@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -47,10 +47,6 @@
|
|
|
47
47
|
"color": "^4.2.3",
|
|
48
48
|
"date-fns": "^4.1.0",
|
|
49
49
|
"eventemitter2": "^6.4.9",
|
|
50
|
-
"lodash.get": "^4.4.2",
|
|
51
|
-
"lodash.keyby": "^4.6.0",
|
|
52
|
-
"lodash.memoize": "^4.1.2",
|
|
53
|
-
"lodash.omitby": "^4.6.0",
|
|
54
50
|
"use-sync-external-store": "^1.2.0"
|
|
55
51
|
},
|
|
56
52
|
"peerDependencies": {
|
|
@@ -64,11 +60,6 @@
|
|
|
64
60
|
"@react-native-documents/picker": "^10.1.2",
|
|
65
61
|
"@types/color": "^3.0.3",
|
|
66
62
|
"@types/jest": "^29.1.2",
|
|
67
|
-
"@types/lodash": "^4.17.13",
|
|
68
|
-
"@types/lodash.get": "^4.4.7",
|
|
69
|
-
"@types/lodash.keyby": "^4.6.7",
|
|
70
|
-
"@types/lodash.memoize": "^4.1.7",
|
|
71
|
-
"@types/lodash.omitby": "^4.6.7",
|
|
72
63
|
"@types/react": "~19.1.10",
|
|
73
64
|
"@types/use-sync-external-store": "^1.5.0",
|
|
74
65
|
"react": "19.1.0",
|
|
@@ -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/utils/lodash.ts
CHANGED
|
@@ -1,8 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
};
|
|
6
78
|
|
|
7
79
|
export const isNil = (value: unknown): value is null | undefined => value == null;
|
|
8
80
|
export const noop = () => {};
|