react-native-molecules 0.5.0-beta.22 → 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/Button/Button.tsx +3 -1
- package/components/Checkbox/Checkbox.tsx +2 -1
- package/components/DateField/useDateFieldState.ts +2 -2
- package/components/DatePicker/DatePickerProvider.tsx +1 -1
- package/components/DatePicker/utils.ts +2 -0
- package/components/DatePickerInline/DatePickerInline.tsx +1 -1
- package/components/DatePickerInline/DatePickerInlineBase.tsx +1 -1
- package/components/DatePickerInline/Day.tsx +1 -1
- package/components/DatePickerInline/MonthPicker.tsx +24 -40
- package/components/DatePickerInline/Swiper.tsx +1 -1
- package/components/DatePickerInline/SwiperUtils.ts +1 -1
- package/components/DatePickerInline/YearPicker.tsx +44 -79
- 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 +156 -387
- package/components/List/context.tsx +4 -5
- package/components/List/index.ts +0 -1
- package/components/List/types.ts +77 -109
- package/components/List/utils.ts +4 -37
- package/components/Menu/Menu.tsx +13 -30
- package/components/Menu/index.tsx +0 -2
- package/components/Popover/Popover.tsx +7 -10
- package/components/Popover/PopoverRoot.tsx +6 -20
- package/components/Popover/common.ts +4 -0
- package/components/Popover/index.ts +2 -8
- package/components/Popover/usePlatformMeasure.ts +4 -2
- 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 +304 -71
- package/components/Select/context.tsx +30 -3
- package/components/Select/index.ts +20 -2
- package/components/Select/types.ts +43 -25
- package/components/Select/utils.ts +18 -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 +76 -152
- 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 +5 -28
- 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
package/utils/color.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import color from 'color';
|
|
2
|
-
|
|
3
|
-
import { weakMemoized } from './lodash';
|
|
4
|
-
|
|
5
|
-
export const resolveContrastColor = weakMemoized(
|
|
6
|
-
(
|
|
7
|
-
bgColor: string,
|
|
8
|
-
lightColor: string = '#fff',
|
|
9
|
-
darkColor: string = '#000',
|
|
10
|
-
isDarkMode?: boolean,
|
|
11
|
-
) => {
|
|
12
|
-
let isLightColor = !isDarkMode;
|
|
13
|
-
try {
|
|
14
|
-
// TODO: Account for transparency.
|
|
15
|
-
isLightColor = color(bgColor).isLight();
|
|
16
|
-
} finally {
|
|
17
|
-
return isLightColor ? darkColor : lightColor;
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export default color;
|
package/utils/compare/index.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
5
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
6
|
-
*/
|
|
7
|
-
function is(x: any, y: any) {
|
|
8
|
-
// SameValue algorithm
|
|
9
|
-
if (x === y) {
|
|
10
|
-
// Steps 1-5, 7-10
|
|
11
|
-
// Steps 6.b-6.e: +0 != -0
|
|
12
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
13
|
-
} else {
|
|
14
|
-
// Step 6.a: NaN == NaN
|
|
15
|
-
return x !== x && y !== y;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Performs equality by iterating through keys on an object and returning false
|
|
21
|
-
* when any key has values which are not strictly equal between the arguments.
|
|
22
|
-
* Returns true when the values of all keys are strictly equal.
|
|
23
|
-
*/
|
|
24
|
-
export function shallowCompare(objA?: unknown, objB?: unknown) {
|
|
25
|
-
if (is(objA, objB)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const keysA = Object.keys(objA);
|
|
34
|
-
const keysB = Object.keys(objB);
|
|
35
|
-
|
|
36
|
-
if (keysA.length !== keysB.length) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Test for A's keys different from B.
|
|
41
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
42
|
-
if (
|
|
43
|
-
!hasOwnProperty.call(objB, keysA[i]) ||
|
|
44
|
-
!is(
|
|
45
|
-
(objA as Record<string, unknown>)[keysA[i]],
|
|
46
|
-
(objB as Record<string, unknown>)[keysA[i]],
|
|
47
|
-
)
|
|
48
|
-
) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return true;
|
|
54
|
-
}
|
package/utils/lodash.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
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
|
-
};
|
|
78
|
-
|
|
79
|
-
export const isNil = (value: unknown): value is null | undefined => value == null;
|
|
80
|
-
export const noop = () => {};
|
|
81
|
-
|
|
82
|
-
const uniqueIdFactory = () => {
|
|
83
|
-
let number = Number.MAX_SAFE_INTEGER;
|
|
84
|
-
return () => number--;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const getUniqueId = uniqueIdFactory();
|
|
88
|
-
const weakMemoize = Object.assign(memoize.bind(null), { Cache: WeakMap });
|
|
89
|
-
const getObjectMemoryAddress = weakMemoize((x: unknown | null) => x && getUniqueId());
|
|
90
|
-
|
|
91
|
-
export const allArgumentResolver = (...args: unknown[]) =>
|
|
92
|
-
args
|
|
93
|
-
.map(x => {
|
|
94
|
-
const type = typeof x;
|
|
95
|
-
switch (type) {
|
|
96
|
-
case 'object':
|
|
97
|
-
case 'function':
|
|
98
|
-
return type.slice(0, 2)! + getObjectMemoryAddress(x);
|
|
99
|
-
default:
|
|
100
|
-
return type.slice(0, 2)! + String(x);
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
.join('_');
|
|
104
|
-
|
|
105
|
-
export const createMemoizedFunction = ({
|
|
106
|
-
resolver = allArgumentResolver,
|
|
107
|
-
Cache = Map,
|
|
108
|
-
}: {
|
|
109
|
-
resolver?: (...args: any[]) => any;
|
|
110
|
-
Cache?: typeof memoize.Cache;
|
|
111
|
-
} = {}) => {
|
|
112
|
-
const memo = Object.assign(memoize.bind(null), { Cache });
|
|
113
|
-
return Object.assign(
|
|
114
|
-
<T extends (...args: any[]) => any>(func: T, resolverOverwride?: (...args: any[]) => any) =>
|
|
115
|
-
memo(func, resolverOverwride ?? resolver),
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const weakMemoized = createMemoizedFunction({
|
|
120
|
-
Cache: WeakMap,
|
|
121
|
-
});
|
package/utils/repository.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
interface RepositoryConstructor<T> {
|
|
2
|
-
onRegister?: (arg: T, name: string, registery: Record<string, T>) => T;
|
|
3
|
-
name?: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
let id = Date.now();
|
|
7
|
-
|
|
8
|
-
export class Repository<T> {
|
|
9
|
-
private registry: Record<string, T> = {};
|
|
10
|
-
readonly #name!: string;
|
|
11
|
-
|
|
12
|
-
readonly #onRegister!: (arg: T, name: string, registery: Record<string, T>) => T;
|
|
13
|
-
|
|
14
|
-
get name() {
|
|
15
|
-
return this.#name;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static get uniqueId() {
|
|
19
|
-
return (id++).toString(36).substring(0, 15);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
constructor({
|
|
23
|
-
onRegister = arg => arg,
|
|
24
|
-
name = Repository.uniqueId,
|
|
25
|
-
}: RepositoryConstructor<T> = {}) {
|
|
26
|
-
this.#onRegister = onRegister;
|
|
27
|
-
this.#name = name;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
has = (itemName: string): boolean => {
|
|
31
|
-
return !!this.registry[itemName];
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Register a item with the src.
|
|
36
|
-
*/
|
|
37
|
-
register = <X extends T = T, ItemName extends string = ''>(itemName: ItemName, item: X) => {
|
|
38
|
-
let updatedItem = this.#onRegister?.(item, itemName, { ...this.registry });
|
|
39
|
-
if (!updatedItem) updatedItem = item;
|
|
40
|
-
|
|
41
|
-
this.registry = {
|
|
42
|
-
...this.registry,
|
|
43
|
-
[itemName]: updatedItem,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get all registered module from the registry.
|
|
49
|
-
*/
|
|
50
|
-
getAll = () => {
|
|
51
|
-
return this.registry;
|
|
52
|
-
};
|
|
53
|
-
}
|