react-native-molecules 0.5.0-beta.3 → 0.5.0-beta.31
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 +2 -6
- package/components/Accordion/AccordionItem.tsx +16 -12
- package/components/Accordion/AccordionItemContent.tsx +6 -1
- package/components/Accordion/AccordionItemHeader.tsx +1 -1
- package/components/Accordion/utils.ts +6 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
- package/components/Appbar/AppbarBase.tsx +18 -13
- package/components/Button/Button.tsx +211 -264
- package/components/Button/index.tsx +9 -3
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +230 -208
- package/components/Card/Card.tsx +1 -1
- package/components/Checkbox/Checkbox.tsx +125 -88
- package/components/Checkbox/CheckboxBase.ios.tsx +14 -23
- package/components/Checkbox/CheckboxBase.tsx +21 -137
- package/components/Checkbox/context.tsx +14 -0
- package/components/Checkbox/index.tsx +11 -4
- package/components/Checkbox/types.ts +63 -29
- package/components/Checkbox/utils.ts +25 -108
- package/components/Chip/Chip.tsx +41 -52
- package/components/Chip/utils.ts +3 -7
- package/components/DateField/DateField.tsx +111 -0
- package/components/DateField/index.tsx +6 -0
- package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +19 -51
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +246 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +158 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +83 -0
- package/components/DatePicker/index.tsx +45 -0
- package/components/DatePicker/utils.ts +295 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +117 -0
- package/components/DatePickerInline/DatePickerInline.tsx +17 -16
- package/components/DatePickerInline/DatePickerInlineBase.tsx +11 -5
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +50 -20
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayNames.tsx +13 -10
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +44 -29
- package/components/DatePickerInline/Month.tsx +48 -67
- package/components/DatePickerInline/MonthPicker.tsx +80 -92
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +169 -14
- package/components/DatePickerInline/SwiperUtils.ts +1 -1
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +220 -78
- package/components/DatePickerInline/dateUtils.tsx +18 -13
- package/components/DatePickerInline/store.tsx +27 -0
- package/components/DatePickerInline/types.ts +6 -2
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/Divider/Divider.tsx +192 -0
- package/components/Divider/index.tsx +10 -0
- package/components/Drawer/Drawer.tsx +17 -6
- package/components/Drawer/DrawerItemGroup.tsx +3 -7
- package/components/ElementGroup/ElementGroup.tsx +1 -1
- package/components/FilePicker/FilePicker.tsx +48 -78
- package/components/FilePicker/index.tsx +2 -1
- package/components/FilePicker/utils.ts +9 -0
- package/components/HelperText/HelperText.tsx +0 -35
- package/components/Icon/iconFactory.tsx +5 -4
- package/components/Icon/index.tsx +1 -1
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +84 -84
- package/components/IconButton/index.tsx +1 -0
- package/components/IconButton/types.ts +10 -0
- package/components/IconButton/utils.ts +167 -33
- package/components/List/List.tsx +276 -0
- package/components/List/context.tsx +27 -0
- package/components/List/index.ts +8 -0
- package/components/List/types.ts +117 -0
- package/components/List/utils.ts +79 -0
- 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/Menu.tsx +162 -39
- package/components/Menu/index.tsx +10 -7
- package/components/Menu/utils.ts +21 -70
- package/components/NavigationRail/NavigationRail.tsx +15 -9
- package/components/Popover/Popover.tsx +119 -145
- package/components/Popover/PopoverRoot.tsx +60 -0
- package/components/Popover/common.ts +54 -34
- package/components/Popover/index.ts +12 -1
- package/components/Popover/usePlatformMeasure.native.ts +90 -0
- package/components/Popover/usePlatformMeasure.ts +120 -0
- package/components/Popover/utils.ts +34 -0
- package/components/Portal/Portal.tsx +1 -2
- package/components/Radio/Radio.tsx +188 -0
- package/components/Radio/RadioBase.ios.tsx +69 -0
- package/components/Radio/RadioBase.tsx +136 -0
- package/components/Radio/context.tsx +23 -0
- package/components/Radio/index.tsx +20 -0
- package/components/Radio/types.ts +101 -0
- package/components/Radio/utils.ts +115 -0
- package/components/Rating/Rating.tsx +1 -1
- package/components/Select/Select.tsx +521 -785
- package/components/Select/context.tsx +81 -0
- package/components/Select/index.ts +26 -14
- package/components/Select/types.ts +65 -58
- package/components/Select/utils.ts +126 -0
- package/components/Slot/Slot.tsx +224 -0
- package/components/Slot/compose-refs.tsx +62 -0
- package/components/Slot/index.tsx +8 -0
- package/components/Surface/Surface.android.tsx +32 -7
- package/components/Surface/Surface.ios.tsx +34 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/utils.ts +44 -6
- package/components/Switch/Switch.ios.tsx +1 -1
- package/components/Switch/Switch.tsx +10 -3
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +156 -150
- package/components/Tabs/utils.ts +15 -2
- package/components/Text/textFactory.tsx +17 -5
- package/components/TextInput/TextInput.tsx +663 -579
- package/components/TextInput/index.tsx +19 -3
- package/components/TextInput/types.ts +77 -28
- package/components/TextInput/utils.ts +235 -145
- package/components/TimeField/TimeField.tsx +75 -0
- package/components/TimeField/index.tsx +6 -0
- package/components/TimeField/useTimeFieldState.ts +70 -0
- package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
- package/components/TimePicker/AnalogClock.tsx +1 -1
- package/components/TimePicker/TimeInput.tsx +87 -42
- package/components/TimePicker/TimeInputs.tsx +138 -50
- package/components/TimePicker/TimePicker.tsx +74 -11
- package/components/TimePicker/TimePickerModal.tsx +186 -0
- package/components/TimePicker/context.tsx +17 -0
- package/components/TimePicker/index.tsx +15 -3
- package/components/TimePicker/utils.ts +93 -4
- package/components/Tooltip/Tooltip.tsx +42 -67
- package/components/Tooltip/TooltipContent.tsx +32 -5
- package/components/Tooltip/TooltipTrigger.tsx +21 -24
- package/components/Tooltip/index.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.native.tsx +83 -16
- package/components/TouchableRipple/TouchableRipple.tsx +150 -102
- package/components/TouchableRipple/rippleFromForegroundColor.ts +21 -0
- package/hocs/index.tsx +1 -1
- package/hocs/withKeyboardAccessibility.tsx +2 -3
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +2 -12
- package/hooks/useActionState.tsx +19 -8
- package/hooks/useContrastColor.ts +1 -2
- package/hooks/useFilePicker.tsx +7 -17
- package/hooks/useHandleNumberFormat.tsx +2 -2
- package/hooks/useMediaQuery.tsx +1 -2
- package/package.json +95 -111
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +6 -3
- 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/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/DocumentPicker/documentPicker.ts +78 -27
- package/utils/DocumentPicker/types.ts +0 -1
- package/utils/extractSubcomponents.ts +89 -0
- 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/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
- package/components/DatePickerDocked/index.tsx +0 -17
- package/components/DatePickerDocked/types.ts +0 -11
- package/components/DatePickerDocked/utils.ts +0 -157
- package/components/DatePickerInline/DatePickerContext.tsx +0 -21
- package/components/DatePickerInput/DatePickerInput.tsx +0 -139
- package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
- package/components/DatePickerInput/DateRangeInput.tsx +0 -88
- package/components/DatePickerInput/index.tsx +0 -10
- package/components/DatePickerInput/types.ts +0 -28
- package/components/DatePickerInput/utils.ts +0 -15
- package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
- package/components/DatePickerModal/CalendarEdit.tsx +0 -139
- package/components/DatePickerModal/DatePickerModal.tsx +0 -85
- package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
- package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
- package/components/DatePickerModal/index.tsx +0 -16
- package/components/DatePickerModal/types.ts +0 -92
- package/components/DatePickerModal/utils.ts +0 -122
- package/components/DateTimePicker/DateTimePicker.tsx +0 -172
- package/components/DateTimePicker/index.tsx +0 -10
- package/components/DateTimePicker/utils.ts +0 -12
- package/components/HorizontalDivider/HorizontalDivider.tsx +0 -103
- package/components/HorizontalDivider/index.tsx +0 -9
- package/components/ListItem/ListItem.tsx +0 -136
- package/components/ListItem/ListItemDescription.tsx +0 -25
- package/components/ListItem/ListItemTitle.tsx +0 -25
- package/components/ListItem/index.tsx +0 -14
- package/components/ListItem/utils.ts +0 -115
- package/components/Menu/MenuDivider.tsx +0 -13
- package/components/Menu/MenuItem.tsx +0 -128
- package/components/Popover/Popover.native.tsx +0 -185
- package/components/RadioButton/RadioButton.tsx +0 -138
- package/components/RadioButton/RadioButtonAndroid.tsx +0 -188
- package/components/RadioButton/RadioButtonGroup.tsx +0 -98
- package/components/RadioButton/RadioButtonIOS.tsx +0 -106
- package/components/RadioButton/RadioButtonItem.tsx +0 -232
- package/components/RadioButton/index.ts +0 -22
- package/components/RadioButton/utils.ts +0 -165
- package/components/TimePickerField/TimePickerField.tsx +0 -152
- package/components/TimePickerField/index.tsx +0 -10
- package/components/TimePickerField/utils.ts +0 -94
- package/components/TimePickerModal/TimePickerModal.tsx +0 -115
- package/components/TimePickerModal/index.tsx +0 -10
- package/components/TimePickerModal/utils.ts +0 -47
- package/components/VerticalDivider/VerticalDivider.tsx +0 -100
- package/components/VerticalDivider/index.tsx +0 -9
- 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 -68
- package/hooks/useLatest.tsx +0 -9
- package/hooks/useMergedRefs.ts +0 -14
- package/hooks/usePrevious.ts +0 -13
- package/hooks/useSearchable.tsx +0 -74
- package/hooks/useSubcomponents.tsx +0 -59
- package/hooks/useToggle.tsx +0 -24
- package/utils/color.ts +0 -22
- package/utils/compare/index.ts +0 -54
- package/utils/lodash.ts +0 -49
- package/utils/repository.ts +0 -53
package/hooks/useSearchable.tsx
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { type ReactElement, useCallback, useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import { IconButton } from '../components/IconButton';
|
|
4
|
-
import {
|
|
5
|
-
TextInput,
|
|
6
|
-
type TextInputElementProps,
|
|
7
|
-
type TextInputProps,
|
|
8
|
-
} from '../components/TextInput';
|
|
9
|
-
import useControlledValue from './useControlledValue';
|
|
10
|
-
|
|
11
|
-
export interface UseSearchableProps {
|
|
12
|
-
searchable?: boolean;
|
|
13
|
-
onQueryChange?: (search: string) => void;
|
|
14
|
-
query?: string;
|
|
15
|
-
searchInputProps?: Omit<TextInputProps, 'value' | 'onChangeText'>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const useSearchInputProps = (props?: Partial<TextInputProps>) => {
|
|
19
|
-
const onChange = props?.onChangeText;
|
|
20
|
-
const onPressClear = useCallback(() => {
|
|
21
|
-
onChange?.('');
|
|
22
|
-
}, [onChange]);
|
|
23
|
-
|
|
24
|
-
const right = useCallback(
|
|
25
|
-
({ color, forceFocus }: TextInputElementProps) => (
|
|
26
|
-
<IconButton
|
|
27
|
-
name={props?.value ? 'close-circle-outline' : 'magnify'}
|
|
28
|
-
onPress={props?.value ? onPressClear : forceFocus}
|
|
29
|
-
color={color}
|
|
30
|
-
/>
|
|
31
|
-
),
|
|
32
|
-
[onPressClear, props?.value],
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return useMemo(
|
|
36
|
-
() => (props?.right === undefined ? props : { right, ...props }),
|
|
37
|
-
[props, right],
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const useSearchable = ({
|
|
42
|
-
searchable,
|
|
43
|
-
onQueryChange,
|
|
44
|
-
query,
|
|
45
|
-
searchInputProps,
|
|
46
|
-
}: UseSearchableProps = {}): ReactElement<TextInputProps> | null => {
|
|
47
|
-
const [value, onValueChange] = useControlledValue({
|
|
48
|
-
value: query || '',
|
|
49
|
-
defaultValue: '', // to disable the useControlledValue inside TextInput
|
|
50
|
-
onChange: onQueryChange,
|
|
51
|
-
disabled: !searchable,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const props = useSearchInputProps(
|
|
55
|
-
useMemo(
|
|
56
|
-
() => ({
|
|
57
|
-
...searchInputProps,
|
|
58
|
-
value,
|
|
59
|
-
onChangeText: onValueChange,
|
|
60
|
-
}),
|
|
61
|
-
[onValueChange, searchInputProps, value],
|
|
62
|
-
),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return useMemo(() => {
|
|
66
|
-
if (!searchable || !onQueryChange) return null;
|
|
67
|
-
|
|
68
|
-
return <TextInput {...props} />;
|
|
69
|
-
}, [onQueryChange, props, searchable]);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export { useSearchInputProps };
|
|
73
|
-
|
|
74
|
-
export default useSearchable;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
2
|
-
import { Children, type FC, isValidElement, useMemo } from 'react';
|
|
3
|
-
|
|
4
|
-
export type UseSubcomponentsProps<T extends string> = {
|
|
5
|
-
children: ReactElement | ReactElement[];
|
|
6
|
-
/**
|
|
7
|
-
* array of displayName as string
|
|
8
|
-
* */
|
|
9
|
-
allowedChildren: T[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This will return an object with the displayNames as the property names
|
|
14
|
-
* eg. allowedChildren: ['Drawer_Header', 'Drawer_Content', 'Drawer_Footer', 'DrawerItem'];
|
|
15
|
-
*
|
|
16
|
-
* return value -> {
|
|
17
|
-
* Drawer_Header: [],
|
|
18
|
-
* Drawer_Content: [],
|
|
19
|
-
* Drawer_Footer: [],
|
|
20
|
-
* DrawerItem: [],
|
|
21
|
-
* }
|
|
22
|
-
* */
|
|
23
|
-
const useSubcomponents = <T extends string = string>({
|
|
24
|
-
children,
|
|
25
|
-
allowedChildren,
|
|
26
|
-
}: UseSubcomponentsProps<T>) => {
|
|
27
|
-
return useMemo(() => {
|
|
28
|
-
// this will create properties with default empty array values even if they don't exist in the children
|
|
29
|
-
const defaultContext = allowedChildren.reduce((context, childName) => {
|
|
30
|
-
return {
|
|
31
|
-
...context,
|
|
32
|
-
[childName]: [],
|
|
33
|
-
};
|
|
34
|
-
}, {}) as {
|
|
35
|
-
[key in T]: ReactElement[];
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return Children.map(children, child => child).reduce((context, child) => {
|
|
39
|
-
if (!isValidElement(child)) return context;
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
!allowedChildren.find(name => name === ((child.type as FC).displayName as string))
|
|
43
|
-
) {
|
|
44
|
-
return context;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const name = (child.type as FC).displayName as T;
|
|
48
|
-
|
|
49
|
-
if (!name) return context;
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
...context,
|
|
53
|
-
[name]: [...context[name], child],
|
|
54
|
-
};
|
|
55
|
-
}, defaultContext);
|
|
56
|
-
}, [allowedChildren, children]);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default useSubcomponents;
|
package/hooks/useToggle.tsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
const useToggle = (initialState = false) => {
|
|
4
|
-
const [state, setState] = useState<boolean>(initialState);
|
|
5
|
-
|
|
6
|
-
const toggle = useCallback(() => setState(prevState => !prevState), []);
|
|
7
|
-
|
|
8
|
-
const handleClose = useCallback(() => setState(false), [setState]);
|
|
9
|
-
|
|
10
|
-
const handleOpen = useCallback(() => setState(true), [setState]);
|
|
11
|
-
|
|
12
|
-
return useMemo(
|
|
13
|
-
() => ({
|
|
14
|
-
state,
|
|
15
|
-
onToggle: toggle,
|
|
16
|
-
setState,
|
|
17
|
-
handleOpen,
|
|
18
|
-
handleClose,
|
|
19
|
-
}),
|
|
20
|
-
[state, toggle, setState, handleOpen, handleClose],
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default useToggle;
|
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,49 +0,0 @@
|
|
|
1
|
-
import memoize from 'lodash.memoize';
|
|
2
|
-
export { default as get } from 'lodash.get';
|
|
3
|
-
export { default as keyBy } from 'lodash.keyby';
|
|
4
|
-
export { default as memoize } from 'lodash.memoize';
|
|
5
|
-
export { default as omitBy } from 'lodash.omitby';
|
|
6
|
-
|
|
7
|
-
export const isNil = (value: unknown): value is null | undefined => value == null;
|
|
8
|
-
export const noop = () => {};
|
|
9
|
-
|
|
10
|
-
const uniqueIdFactory = () => {
|
|
11
|
-
let number = Number.MAX_SAFE_INTEGER;
|
|
12
|
-
return () => number--;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const getUniqueId = uniqueIdFactory();
|
|
16
|
-
const weakMemoize = Object.assign(memoize.bind(null), { Cache: WeakMap });
|
|
17
|
-
const getObjectMemoryAddress = weakMemoize((x: unknown | null) => x && getUniqueId());
|
|
18
|
-
|
|
19
|
-
export const allArgumentResolver = (...args: unknown[]) =>
|
|
20
|
-
args
|
|
21
|
-
.map(x => {
|
|
22
|
-
const type = typeof x;
|
|
23
|
-
switch (type) {
|
|
24
|
-
case 'object':
|
|
25
|
-
case 'function':
|
|
26
|
-
return type.slice(0, 2)! + getObjectMemoryAddress(x);
|
|
27
|
-
default:
|
|
28
|
-
return type.slice(0, 2)! + String(x);
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
.join('_');
|
|
32
|
-
|
|
33
|
-
export const createMemoizedFunction = ({
|
|
34
|
-
resolver = allArgumentResolver,
|
|
35
|
-
Cache = Map,
|
|
36
|
-
}: {
|
|
37
|
-
resolver?: (...args: any[]) => any;
|
|
38
|
-
Cache?: typeof memoize.Cache;
|
|
39
|
-
} = {}) => {
|
|
40
|
-
const memo = Object.assign(memoize.bind(null), { Cache });
|
|
41
|
-
return Object.assign(
|
|
42
|
-
<T extends (...args: any[]) => any>(func: T, resolverOverwride?: (...args: any[]) => any) =>
|
|
43
|
-
memo(func, resolverOverwride ?? resolver),
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const weakMemoized = createMemoizedFunction({
|
|
48
|
-
Cache: WeakMap,
|
|
49
|
-
});
|
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
|
-
}
|