react-native-molecules 0.5.0-beta.0
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 +89 -0
- package/components/Accordion/AccordionItem.tsx +94 -0
- package/components/Accordion/AccordionItemContent.tsx +17 -0
- package/components/Accordion/AccordionItemHeader.tsx +122 -0
- package/components/Accordion/index.tsx +36 -0
- package/components/Accordion/utils.ts +62 -0
- package/components/ActivityIndicator/ActivityIndicator.ios.tsx +1 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +200 -0
- package/components/ActivityIndicator/AnimatedSpinner.tsx +121 -0
- package/components/ActivityIndicator/index.tsx +17 -0
- package/components/Appbar/AppbarActions.tsx +13 -0
- package/components/Appbar/AppbarBase.tsx +60 -0
- package/components/Appbar/AppbarCenterAligned.tsx +13 -0
- package/components/Appbar/AppbarLarge.tsx +13 -0
- package/components/Appbar/AppbarLeft.tsx +26 -0
- package/components/Appbar/AppbarMedium.tsx +13 -0
- package/components/Appbar/AppbarRight.tsx +40 -0
- package/components/Appbar/AppbarSmall.tsx +13 -0
- package/components/Appbar/AppbarTitle.tsx +49 -0
- package/components/Appbar/index.tsx +46 -0
- package/components/Appbar/types.ts +19 -0
- package/components/Appbar/utils.ts +127 -0
- package/components/Avatar/Avatar.tsx +189 -0
- package/components/Avatar/index.tsx +11 -0
- package/components/Avatar/utils.ts +35 -0
- package/components/Backdrop/Backdrop.tsx +18 -0
- package/components/Backdrop/index.tsx +11 -0
- package/components/Backdrop/types.ts +3 -0
- package/components/Backdrop/utils.ts +21 -0
- package/components/Badge/Badge.tsx +29 -0
- package/components/Badge/index.tsx +11 -0
- package/components/Badge/utils.ts +38 -0
- package/components/Button/Button.tsx +349 -0
- package/components/Button/index.tsx +11 -0
- package/components/Button/types.ts +5 -0
- package/components/Button/utils.ts +416 -0
- package/components/Card/Card.tsx +160 -0
- package/components/Card/CardActions.tsx +18 -0
- package/components/Card/CardContent.tsx +29 -0
- package/components/Card/CardHeader.tsx +31 -0
- package/components/Card/CardHeadline.tsx +15 -0
- package/components/Card/CardMedia.tsx +36 -0
- package/components/Card/CardSubhead.tsx +15 -0
- package/components/Card/CardText.tsx +13 -0
- package/components/Card/CardTypography.tsx +113 -0
- package/components/Card/index.tsx +38 -0
- package/components/Card/types.ts +1 -0
- package/components/Card/utils.ts +23 -0
- package/components/Checkbox/Checkbox.tsx +123 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +86 -0
- package/components/Checkbox/CheckboxBase.tsx +216 -0
- package/components/Checkbox/index.tsx +11 -0
- package/components/Checkbox/types.ts +72 -0
- package/components/Checkbox/utils.ts +210 -0
- package/components/Chip/Chip.tsx +416 -0
- package/components/Chip/index.tsx +51 -0
- package/components/Chip/utils.ts +100 -0
- package/components/DatePickerDocked/DatePickerDocked.tsx +30 -0
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +129 -0
- package/components/DatePickerDocked/index.tsx +21 -0
- package/components/DatePickerDocked/types.ts +11 -0
- package/components/DatePickerDocked/utils.ts +155 -0
- package/components/DatePickerInline/AutoSizer.tsx +46 -0
- package/components/DatePickerInline/DatePickerContext.tsx +21 -0
- package/components/DatePickerInline/DatePickerInline.tsx +82 -0
- package/components/DatePickerInline/DatePickerInlineBase.tsx +181 -0
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +108 -0
- package/components/DatePickerInline/Day.tsx +88 -0
- package/components/DatePickerInline/DayName.tsx +17 -0
- package/components/DatePickerInline/DayNames.tsx +32 -0
- package/components/DatePickerInline/DayRange.tsx +48 -0
- package/components/DatePickerInline/HeaderItem.tsx +111 -0
- package/components/DatePickerInline/Month.tsx +233 -0
- package/components/DatePickerInline/MonthPicker.tsx +174 -0
- package/components/DatePickerInline/Swiper.native.tsx +172 -0
- package/components/DatePickerInline/Swiper.tsx +172 -0
- package/components/DatePickerInline/SwiperUtils.ts +40 -0
- package/components/DatePickerInline/Week.tsx +67 -0
- package/components/DatePickerInline/YearPicker.tsx +139 -0
- package/components/DatePickerInline/dateUtils.tsx +334 -0
- package/components/DatePickerInline/index.tsx +41 -0
- package/components/DatePickerInline/types.ts +104 -0
- package/components/DatePickerInline/utils.ts +367 -0
- package/components/DatePickerInput/DatePickerInput.tsx +139 -0
- package/components/DatePickerInput/DatePickerInputModal.tsx +48 -0
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +77 -0
- package/components/DatePickerInput/DateRangeInput.tsx +88 -0
- package/components/DatePickerInput/index.tsx +14 -0
- package/components/DatePickerInput/inputUtils.ts +138 -0
- package/components/DatePickerInput/types.ts +28 -0
- package/components/DatePickerInput/utils.ts +16 -0
- package/components/DatePickerModal/AnimatedCrossView.tsx +94 -0
- package/components/DatePickerModal/CalendarEdit.tsx +139 -0
- package/components/DatePickerModal/DatePickerModal.tsx +85 -0
- package/components/DatePickerModal/DatePickerModalContent.tsx +155 -0
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +213 -0
- package/components/DatePickerModal/DatePickerModalHeader.tsx +74 -0
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +13 -0
- package/components/DatePickerModal/index.tsx +20 -0
- package/components/DatePickerModal/types.ts +92 -0
- package/components/DatePickerModal/utils.ts +121 -0
- package/components/DateTimePicker/DateTimePicker.tsx +172 -0
- package/components/DateTimePicker/index.tsx +14 -0
- package/components/DateTimePicker/utils.ts +13 -0
- package/components/Dialog/Dialog.tsx +66 -0
- package/components/Dialog/DialogActions.tsx +89 -0
- package/components/Dialog/DialogContent.tsx +37 -0
- package/components/Dialog/DialogIcon.tsx +69 -0
- package/components/Dialog/DialogTitle.tsx +68 -0
- package/components/Dialog/index.tsx +37 -0
- package/components/Dialog/utils.ts +80 -0
- package/components/Drawer/Collapsible/DrawerCollapsible.tsx +22 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItem.tsx +38 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemContent.tsx +16 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemHeader.tsx +48 -0
- package/components/Drawer/Collapsible/index.tsx +23 -0
- package/components/Drawer/Collapsible/utils.ts +49 -0
- package/components/Drawer/Drawer.tsx +43 -0
- package/components/Drawer/DrawerContent.tsx +35 -0
- package/components/Drawer/DrawerFooter.tsx +27 -0
- package/components/Drawer/DrawerHeader.tsx +27 -0
- package/components/Drawer/DrawerItem.tsx +206 -0
- package/components/Drawer/DrawerItemGroup.tsx +82 -0
- package/components/Drawer/index.tsx +47 -0
- package/components/Drawer/types.ts +3 -0
- package/components/Drawer/utils.ts +8 -0
- package/components/ElementGroup/ElementGroup.tsx +139 -0
- package/components/ElementGroup/index.tsx +11 -0
- package/components/ElementGroup/utils.ts +25 -0
- package/components/FAB/FAB.tsx +176 -0
- package/components/FAB/index.tsx +12 -0
- package/components/FAB/types.ts +1 -0
- package/components/FAB/utils.ts +221 -0
- package/components/FilePicker/FilePicker.tsx +133 -0
- package/components/FilePicker/index.tsx +11 -0
- package/components/FilePicker/utils.ts +13 -0
- package/components/HelperText/HelperText.tsx +139 -0
- package/components/HelperText/index.tsx +11 -0
- package/components/HelperText/utils.ts +29 -0
- package/components/HorizontalDivider/HorizontalDivider.tsx +101 -0
- package/components/HorizontalDivider/index.tsx +13 -0
- package/components/Icon/CrossFadeIcon.tsx +116 -0
- package/components/Icon/Icon.tsx +41 -0
- package/components/Icon/iconFactory.tsx +23 -0
- package/components/Icon/index.tsx +11 -0
- package/components/Icon/types.ts +35 -0
- package/components/IconButton/IconButton.tsx +218 -0
- package/components/IconButton/index.tsx +11 -0
- package/components/IconButton/types.ts +1 -0
- package/components/IconButton/utils.ts +325 -0
- package/components/If/index.tsx +13 -0
- package/components/InputAddon/InputAddon.tsx +27 -0
- package/components/InputAddon/index.tsx +11 -0
- package/components/InputAddon/utils.ts +33 -0
- package/components/Link/Link.tsx +48 -0
- package/components/Link/index.tsx +11 -0
- package/components/Link/utils.ts +37 -0
- package/components/ListItem/ListItem.tsx +136 -0
- package/components/ListItem/ListItemDescription.tsx +25 -0
- package/components/ListItem/ListItemTitle.tsx +25 -0
- package/components/ListItem/index.tsx +18 -0
- package/components/ListItem/utils.ts +113 -0
- package/components/Menu/Menu.tsx +69 -0
- package/components/Menu/MenuDivider.tsx +13 -0
- package/components/Menu/MenuItem.tsx +128 -0
- package/components/Menu/index.tsx +19 -0
- package/components/Menu/utils.ts +92 -0
- package/components/Modal/Modal.tsx +261 -0
- package/components/Modal/index.tsx +11 -0
- package/components/Modal/utils.ts +45 -0
- package/components/NavigationRail/NavigationRail.tsx +32 -0
- package/components/NavigationRail/NavigationRailContent.tsx +25 -0
- package/components/NavigationRail/NavigationRailFooter.tsx +18 -0
- package/components/NavigationRail/NavigationRailHeader.tsx +18 -0
- package/components/NavigationRail/NavigationRailItem.tsx +226 -0
- package/components/NavigationRail/index.tsx +35 -0
- package/components/NavigationRail/utils.ts +170 -0
- package/components/NavigationStack/NavigationStack.tsx +85 -0
- package/components/NavigationStack/NavigationStackItem.tsx +60 -0
- package/components/NavigationStack/index.tsx +20 -0
- package/components/NavigationStack/utils.tsx +16 -0
- package/components/Popover/Popover.native.tsx +185 -0
- package/components/Popover/Popover.tsx +198 -0
- package/components/Popover/common.ts +459 -0
- package/components/Popover/index.ts +2 -0
- package/components/Portal/Portal.tsx +13 -0
- package/components/Portal/index.tsx +12 -0
- package/components/RadioButton/RadioButton.tsx +138 -0
- package/components/RadioButton/RadioButtonAndroid.tsx +188 -0
- package/components/RadioButton/RadioButtonGroup.tsx +98 -0
- package/components/RadioButton/RadioButtonIOS.tsx +106 -0
- package/components/RadioButton/RadioButtonItem.tsx +232 -0
- package/components/RadioButton/index.ts +27 -0
- package/components/RadioButton/utils.ts +164 -0
- package/components/Rating/Rating.tsx +149 -0
- package/components/Rating/RatingItem.tsx +125 -0
- package/components/Rating/index.tsx +13 -0
- package/components/Rating/utils.ts +38 -0
- package/components/Select/Select.tsx +1038 -0
- package/components/Select/index.ts +14 -0
- package/components/Select/types.ts +115 -0
- package/components/StateLayer/StateLayer.tsx +12 -0
- package/components/StateLayer/index.tsx +11 -0
- package/components/StateLayer/utils.ts +17 -0
- package/components/Surface/BackgroundContextWrapper.tsx +27 -0
- package/components/Surface/Surface.android.tsx +62 -0
- package/components/Surface/Surface.ios.tsx +123 -0
- package/components/Surface/Surface.tsx +48 -0
- package/components/Surface/index.tsx +12 -0
- package/components/Surface/utils.ts +106 -0
- package/components/Switch/Switch.ios.tsx +67 -0
- package/components/Switch/Switch.tsx +278 -0
- package/components/Switch/index.tsx +11 -0
- package/components/Switch/utils.ts +283 -0
- package/components/Tabs/TabItem.tsx +150 -0
- package/components/Tabs/TabLabel.tsx +84 -0
- package/components/Tabs/Tabs.tsx +398 -0
- package/components/Tabs/index.tsx +21 -0
- package/components/Tabs/utils.ts +126 -0
- package/components/Text/Text.tsx +23 -0
- package/components/Text/index.tsx +2 -0
- package/components/Text/textFactory.tsx +33 -0
- package/components/TextInput/InputLabel.tsx +181 -0
- package/components/TextInput/TextInput.tsx +693 -0
- package/components/TextInput/index.tsx +16 -0
- package/components/TextInput/types.ts +96 -0
- package/components/TextInput/utils.ts +544 -0
- package/components/TextInputWithMask/TextInputMask.tsx +57 -0
- package/components/TextInputWithMask/index.tsx +11 -0
- package/components/TextInputWithMask/utils.ts +56 -0
- package/components/TimePicker/AmPmSwitcher.tsx +99 -0
- package/components/TimePicker/AnalogClock.tsx +165 -0
- package/components/TimePicker/AnalogClockHours.tsx +163 -0
- package/components/TimePicker/AnalogClockMinutes.tsx +68 -0
- package/components/TimePicker/AnimatedClockSwitcher.tsx +72 -0
- package/components/TimePicker/DisplayModeContext.tsx +6 -0
- package/components/TimePicker/TimeInput.tsx +112 -0
- package/components/TimePicker/TimeInputs.tsx +148 -0
- package/components/TimePicker/TimePicker.tsx +130 -0
- package/components/TimePicker/index.tsx +19 -0
- package/components/TimePicker/timeUtils.ts +159 -0
- package/components/TimePicker/utils.ts +285 -0
- package/components/TimePickerField/TimePickerField.tsx +152 -0
- package/components/TimePickerField/index.tsx +14 -0
- package/components/TimePickerField/sanitizeTime.ts +85 -0
- package/components/TimePickerField/utils.ts +95 -0
- package/components/TimePickerModal/TimePickerModal.tsx +115 -0
- package/components/TimePickerModal/index.tsx +14 -0
- package/components/TimePickerModal/utils.ts +48 -0
- package/components/Tooltip/Tooltip.tsx +137 -0
- package/components/Tooltip/TooltipContent.tsx +12 -0
- package/components/Tooltip/TooltipTrigger.tsx +94 -0
- package/components/Tooltip/index.tsx +20 -0
- package/components/Tooltip/utils.ts +21 -0
- package/components/TouchableRipple/TouchableRipple.native.tsx +105 -0
- package/components/TouchableRipple/TouchableRipple.tsx +286 -0
- package/components/TouchableRipple/index.tsx +14 -0
- package/components/TouchableRipple/utils.ts +15 -0
- package/components/VerticalDivider/VerticalDivider.tsx +99 -0
- package/components/VerticalDivider/index.tsx +13 -0
- package/context-bridge/index.tsx +87 -0
- package/core/componentsRegistry.ts +164 -0
- package/core/index.tsx +2 -0
- package/fast-context/index.tsx +190 -0
- package/hocs/index.tsx +5 -0
- package/hocs/typedMemo.tsx +5 -0
- package/hocs/withKeyboardAccessibility.tsx +231 -0
- package/hocs/withPortal.tsx +16 -0
- package/hooks/createPsuedoHook.tsx +50 -0
- package/hooks/index.tsx +29 -0
- package/hooks/useActionState.native.tsx +22 -0
- package/hooks/useActionState.tsx +34 -0
- package/hooks/useActive.tsx +5 -0
- package/hooks/useBreakpoints.tsx +7 -0
- package/hooks/useColorMode.tsx +17 -0
- package/hooks/useContrastColor.ts +15 -0
- package/hooks/useControlledValue.tsx +68 -0
- package/hooks/useFilePicker.tsx +48 -0
- package/hooks/useFocus.tsx +5 -0
- package/hooks/useHandleNumberFormat.tsx +106 -0
- package/hooks/useHover.tsx +5 -0
- package/hooks/useKeyboardDismissable.ts +66 -0
- package/hooks/useLatest.tsx +9 -0
- package/hooks/useMediaQuery.tsx +64 -0
- package/hooks/useMergedRefs.ts +14 -0
- package/hooks/usePrevious.ts +13 -0
- package/hooks/useQueryFilter.tsx +35 -0
- package/hooks/useSearchable.tsx +74 -0
- package/hooks/useSubcomponents.tsx +59 -0
- package/hooks/useTheme.ts +3 -0
- package/hooks/useToggle.tsx +24 -0
- package/package.json +114 -0
- package/shortcuts-manager/EventsManager.tsx +121 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.native.tsx +9 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +58 -0
- package/shortcuts-manager/ShortcutsManager/index.tsx +2 -0
- package/shortcuts-manager/ShortcutsManager/utils.tsx +30 -0
- package/shortcuts-manager/index.tsx +6 -0
- package/shortcuts-manager/types.ts +24 -0
- package/shortcuts-manager/useIsKeyPressed/index.tsx +1 -0
- package/shortcuts-manager/useIsKeyPressed/useIsKeyPress.tsx +9 -0
- package/shortcuts-manager/useSetScopes/index.tsx +1 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.native.tsx +9 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +25 -0
- package/shortcuts-manager/useShortcut/index.tsx +2 -0
- package/shortcuts-manager/useShortcut/types.ts +3 -0
- package/shortcuts-manager/useShortcut/useShortcut.native.tsx +9 -0
- package/shortcuts-manager/useShortcut/useShortcut.tsx +61 -0
- package/shortcuts-manager/utils.ts +105 -0
- package/styles/index.ts +4 -0
- package/styles/overlay.ts +69 -0
- package/styles/shadow.ts +21 -0
- package/styles/themes/DarkTheme.tsx +98 -0
- package/styles/themes/LightTheme.tsx +212 -0
- package/styles/themes/tokens.ts +248 -0
- package/styles/utils.ts +11 -0
- package/types/index.ts +129 -0
- package/types/theme.ts +159 -0
- package/utils/DocumentPicker/documentPicker.native.ts +10 -0
- package/utils/DocumentPicker/documentPicker.ts +76 -0
- package/utils/DocumentPicker/index.ts +2 -0
- package/utils/DocumentPicker/types.ts +28 -0
- package/utils/addEventListener.tsx +51 -0
- package/utils/backgroundContext.ts +9 -0
- package/utils/color.ts +22 -0
- package/utils/compare/index.ts +54 -0
- package/utils/composeEventHandlers.ts +9 -0
- package/utils/createNumberMask/createNumberMask.ts +98 -0
- package/utils/createNumberMask/index.ts +5 -0
- package/utils/createSyntheticEvent.ts +31 -0
- package/utils/date-fns.ts +7 -0
- package/utils/dateTimePicker.ts +5 -0
- package/utils/escapeRegex.ts +9 -0
- package/utils/extractTextStyles.ts +52 -0
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +26 -0
- package/utils/formatNumberWithMask/formatWithMask.ts +119 -0
- package/utils/formatNumberWithMask/index.ts +6 -0
- package/utils/getCursorStyle/getCursorStyle.native.ts +1 -0
- package/utils/getCursorStyle/getCursorStyle.ts +1 -0
- package/utils/getCursorStyle/index.ts +1 -0
- package/utils/getOS/getOS.native.ts +7 -0
- package/utils/getOS/getOS.ts +24 -0
- package/utils/getOS/index.ts +1 -0
- package/utils/getyearRange.ts +5 -0
- package/utils/index.ts +20 -0
- package/utils/lodash.ts +50 -0
- package/utils/mergeRefs.ts +13 -0
- package/utils/normalizeBorderRadiuses.ts +24 -0
- package/utils/normalizeSpacings.ts +110 -0
- package/utils/normalizeToNumberString/index.ts +4 -0
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +48 -0
- package/utils/repository.ts +103 -0
- package/utils/resolveColorMode.ts +9 -0
- package/utils/resolveStateVariant.ts +26 -0
- package/utils/tokenStylesParser.ts +7 -0
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-molecules",
|
|
3
|
+
"version": "0.5.0-beta.0",
|
|
4
|
+
"author": "Thet Aung <thetaung.dev@gmail.com>",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"components",
|
|
9
|
+
"context-bridge",
|
|
10
|
+
"core",
|
|
11
|
+
"fast-context",
|
|
12
|
+
"hocs",
|
|
13
|
+
"hooks",
|
|
14
|
+
"shortcuts-manager",
|
|
15
|
+
"styles",
|
|
16
|
+
"types",
|
|
17
|
+
"utils",
|
|
18
|
+
"index.ts",
|
|
19
|
+
"!**/__tests__",
|
|
20
|
+
"!**/__fixtures__",
|
|
21
|
+
"!**/__mocks__"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"fix-typescript-output": "cd lib/typescript && mv src/* . && rm -rf src",
|
|
25
|
+
"example:expo": "pnpm --filter=expo-example run",
|
|
26
|
+
"start": "MOLECULES_ENV=storybook pnpm storybook",
|
|
27
|
+
"run:testcases": "pnpm workspace test-cases start",
|
|
28
|
+
"test": "MOLECULES_ENV=storybook jest && pnpm test-storybook",
|
|
29
|
+
"test-jest": "jest",
|
|
30
|
+
"bundle": "MOLECULES_ENV=release rm -rf dist && mkdir -p dist && npm pack --pack-destination=dist",
|
|
31
|
+
"do-release": "npm publish ./dist/react-native-molecules-$npm_package_version.tgz --access=public",
|
|
32
|
+
"release": "pnpm bundle && pnpm do-release",
|
|
33
|
+
"release:dev": "npm version prerelease --preid=dev && pnpm release --tag=dev",
|
|
34
|
+
"storybook": "MOLECULES_ENV=storybook storybook dev -p 6006",
|
|
35
|
+
"test-storybook": "test-storybook",
|
|
36
|
+
"coverage": "cp coverage/storybook/coverage-storybook.json coverage/coverage-storybook.json && npx nyc report --reporter=html -t coverage --report-dir coverage/lcov-report",
|
|
37
|
+
"test:coverage": "pnpm test-jest --coverage && pnpm test-storybook --coverage && pnpm coverage",
|
|
38
|
+
"build-storybook": "storybook build",
|
|
39
|
+
"chromatic:all": "MOLECULES_ENV=storybook npx chromatic --project-token=934368a7f6c9",
|
|
40
|
+
"chromatic": "MOLECULES_ENV=storybook pnpm chromatic:all --only-changed",
|
|
41
|
+
"perf": "npx reassure"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@gorhom/portal": "^1.0.14",
|
|
45
|
+
"@react-native-vector-icons/feather": "^12.4.0",
|
|
46
|
+
"@react-native-vector-icons/material-design-icons": "^12.4.0",
|
|
47
|
+
"color": "^4.2.3",
|
|
48
|
+
"date-fns": "^4.1.0",
|
|
49
|
+
"eventemitter2": "^6.4.9",
|
|
50
|
+
"lodash.debounce": "^4.0.8",
|
|
51
|
+
"lodash.get": "^4.4.2",
|
|
52
|
+
"lodash.keyby": "^4.6.0",
|
|
53
|
+
"lodash.memoize": "^4.1.2",
|
|
54
|
+
"lodash.omitby": "^4.6.0",
|
|
55
|
+
"use-sync-external-store": "^1.2.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@react-native-documents/picker": "^10.1.2",
|
|
59
|
+
"react": "19.1.0",
|
|
60
|
+
"react-native": "0.81.4",
|
|
61
|
+
"react-native-unistyles": "^3.0.15",
|
|
62
|
+
"react-native-web": "~0.21.1"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@react-native-documents/picker": "^10.1.2",
|
|
66
|
+
"@types/color": "^3.0.3",
|
|
67
|
+
"@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
|
+
"@types/react": "~19.1.10",
|
|
75
|
+
"@types/use-sync-external-store": "^1.5.0",
|
|
76
|
+
"react": "19.1.0",
|
|
77
|
+
"react-native": "0.81.4",
|
|
78
|
+
"react-native-builder-bob": "^0.17.1",
|
|
79
|
+
"react-native-unistyles": "^3.0.15",
|
|
80
|
+
"react-native-web": "~0.21.1"
|
|
81
|
+
},
|
|
82
|
+
"eslintIgnore": [
|
|
83
|
+
"node_modules/",
|
|
84
|
+
"lib/",
|
|
85
|
+
"test-cases/node_modules",
|
|
86
|
+
"dist",
|
|
87
|
+
"cache"
|
|
88
|
+
],
|
|
89
|
+
"react-native-builder-bob": {
|
|
90
|
+
"source": "src",
|
|
91
|
+
"output": "lib",
|
|
92
|
+
"targets": [
|
|
93
|
+
[
|
|
94
|
+
"commonjs",
|
|
95
|
+
{
|
|
96
|
+
"configFile": true
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"module",
|
|
101
|
+
{
|
|
102
|
+
"configFile": true
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"typescript",
|
|
107
|
+
{
|
|
108
|
+
"project": "tsconfig.build.json",
|
|
109
|
+
"rootDir": "src"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useShortcutsManagerContextValueSelector,
|
|
5
|
+
useShortcutsManagerStoreRef,
|
|
6
|
+
} from './ShortcutsManager/utils';
|
|
7
|
+
import type { ShortcutEventDetail } from './types';
|
|
8
|
+
import { calculateShortcutEventName, getPressedModifierKeys, normalizeKeys } from './utils';
|
|
9
|
+
|
|
10
|
+
const defaultMatcher = (_e: KeyboardEvent, key: string | string[], details: ShortcutEventDetail) =>
|
|
11
|
+
normalizeKeys(key) === details.normalizedKey;
|
|
12
|
+
|
|
13
|
+
const EventsManager = () => {
|
|
14
|
+
const { store, set: setShortcutsManagerStore } = useShortcutsManagerStoreRef();
|
|
15
|
+
|
|
16
|
+
const onKeyDown = useCallback(
|
|
17
|
+
(e: KeyboardEvent) => {
|
|
18
|
+
const modifierKeys = getPressedModifierKeys(e);
|
|
19
|
+
const normalizedKeys = normalizeKeys([e.key].concat(modifierKeys));
|
|
20
|
+
|
|
21
|
+
setShortcutsManagerStore(prev => ({
|
|
22
|
+
pressedKeys: [...prev.pressedKeys, e.key],
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
let shouldPrevent = false;
|
|
26
|
+
|
|
27
|
+
Object.values(store.current.shortcuts).forEach(shortcut => {
|
|
28
|
+
if (shortcut.scope) {
|
|
29
|
+
const shortcutScope = store.current.scopes[shortcut.scope];
|
|
30
|
+
|
|
31
|
+
if (!shortcutScope) return;
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
!(
|
|
35
|
+
shortcutScope?.node === document.activeElement ||
|
|
36
|
+
shortcutScope?.node?.contains(document.activeElement)
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const matcher = shortcut.matcher || defaultMatcher;
|
|
43
|
+
|
|
44
|
+
const foundMatchedKeys = shortcut.keys.find(keyGroup =>
|
|
45
|
+
matcher(e, keyGroup, {
|
|
46
|
+
pressedKeys: [e.key].concat(modifierKeys),
|
|
47
|
+
normalizedKey: normalizedKeys,
|
|
48
|
+
modifiers: modifierKeys,
|
|
49
|
+
key: e.key,
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
if (!foundMatchedKeys) return;
|
|
54
|
+
|
|
55
|
+
shouldPrevent = !!shortcut.preventDefault;
|
|
56
|
+
|
|
57
|
+
const event = new CustomEvent<ShortcutEventDetail>(
|
|
58
|
+
calculateShortcutEventName(shortcut.name),
|
|
59
|
+
{
|
|
60
|
+
detail: {
|
|
61
|
+
pressedKeys: [e.key].concat(modifierKeys),
|
|
62
|
+
normalizedKey: normalizedKeys,
|
|
63
|
+
modifiers: modifierKeys,
|
|
64
|
+
key: e.key,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
document.dispatchEvent(event);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (shouldPrevent) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
[setShortcutsManagerStore, store],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const onKeyUp = useCallback(
|
|
80
|
+
(e: KeyboardEvent) => {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
|
|
83
|
+
setShortcutsManagerStore(prev => ({
|
|
84
|
+
pressedKeys: prev.pressedKeys?.filter(key => key !== e.key),
|
|
85
|
+
}));
|
|
86
|
+
},
|
|
87
|
+
[setShortcutsManagerStore],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const onBlur = useCallback(() => {
|
|
91
|
+
setShortcutsManagerStore(() => ({
|
|
92
|
+
pressedKeys: [],
|
|
93
|
+
}));
|
|
94
|
+
}, [setShortcutsManagerStore]);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
document.addEventListener('keydown', onKeyDown);
|
|
98
|
+
document.addEventListener('keyup', onKeyUp);
|
|
99
|
+
document.addEventListener('blur', onBlur);
|
|
100
|
+
|
|
101
|
+
return () => {
|
|
102
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
103
|
+
document.removeEventListener('keyup', onKeyUp);
|
|
104
|
+
document.removeEventListener('blur', onBlur);
|
|
105
|
+
};
|
|
106
|
+
}, [onBlur, onKeyDown, onKeyUp]);
|
|
107
|
+
|
|
108
|
+
return null;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const EventManagerContainer = memo(() => {
|
|
112
|
+
const { isDisabled } = useShortcutsManagerContextValueSelector(state => ({
|
|
113
|
+
isDisabled: !!state.disabled,
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
if (isDisabled) return null;
|
|
117
|
+
|
|
118
|
+
return <EventsManager />;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
export default memo(EventManagerContainer);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { memo, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { keyBy } from '../../utils/lodash';
|
|
4
|
+
import EventsManager from '../EventsManager';
|
|
5
|
+
import type { Shortcut } from '../types';
|
|
6
|
+
import {
|
|
7
|
+
ShortcutsManagerContext,
|
|
8
|
+
ShortcutsManagerContextProvider,
|
|
9
|
+
type ShortcutsManagerContextType,
|
|
10
|
+
type ShortcutsManagerProps,
|
|
11
|
+
} from './utils';
|
|
12
|
+
|
|
13
|
+
const _ShortcutsManager = ({ shortcuts, scopes, children }: ShortcutsManagerProps) => {
|
|
14
|
+
const shortcutsRef = useRef<Shortcut[]>(shortcuts || []);
|
|
15
|
+
const scopesRef = useRef(scopes);
|
|
16
|
+
const parentContextRef = useContext(ShortcutsManagerContext);
|
|
17
|
+
|
|
18
|
+
const contextValue = useMemo(() => {
|
|
19
|
+
const currentValue = {
|
|
20
|
+
shortcuts: keyBy(shortcutsRef.current, 'name'),
|
|
21
|
+
scopes: keyBy(scopesRef.current, 'name'),
|
|
22
|
+
} as ShortcutsManagerContextType;
|
|
23
|
+
|
|
24
|
+
if (!parentContextRef) return currentValue;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
shortcuts: {
|
|
28
|
+
...currentValue.shortcuts,
|
|
29
|
+
...parentContextRef.store.current.shortcuts,
|
|
30
|
+
},
|
|
31
|
+
scopes: {
|
|
32
|
+
...currentValue.scopes,
|
|
33
|
+
...parentContextRef.store.current.scopes,
|
|
34
|
+
},
|
|
35
|
+
} as ShortcutsManagerContextType;
|
|
36
|
+
}, [parentContextRef]);
|
|
37
|
+
|
|
38
|
+
// disable the parent event listener, we only need 1 listener
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!parentContextRef) return;
|
|
41
|
+
|
|
42
|
+
parentContextRef.set(() => ({ disabled: true }));
|
|
43
|
+
|
|
44
|
+
// if unmounted re-enable parent event listener
|
|
45
|
+
return () => {
|
|
46
|
+
parentContextRef.set(() => ({ disabled: false }));
|
|
47
|
+
};
|
|
48
|
+
}, [parentContextRef]);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ShortcutsManagerContextProvider value={contextValue}>
|
|
52
|
+
<EventsManager />
|
|
53
|
+
{children}
|
|
54
|
+
</ShortcutsManagerContextProvider>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default memo(_ShortcutsManager);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Scope, Shortcut } from '../types';
|
|
2
|
+
import { createFastContext } from '../../fast-context';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export type ShortcutsManagerContextType = {
|
|
6
|
+
shortcuts: Record<string, Shortcut>;
|
|
7
|
+
scopes: Record<string, Scope>;
|
|
8
|
+
pressedKeys: string[];
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const defaultValue = {
|
|
13
|
+
shortcuts: [],
|
|
14
|
+
scopes: [],
|
|
15
|
+
pressedKeys: [],
|
|
16
|
+
} as unknown as ShortcutsManagerContextType;
|
|
17
|
+
|
|
18
|
+
export const {
|
|
19
|
+
Provider: ShortcutsManagerContextProvider,
|
|
20
|
+
useContext: useShortcutsManagerContextSelector,
|
|
21
|
+
useContextValue: useShortcutsManagerContextValueSelector,
|
|
22
|
+
useStoreRef: useShortcutsManagerStoreRef,
|
|
23
|
+
Context: ShortcutsManagerContext,
|
|
24
|
+
} = createFastContext<ShortcutsManagerContextType>(defaultValue);
|
|
25
|
+
|
|
26
|
+
export type ShortcutsManagerProps = {
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
shortcuts?: Shortcut[];
|
|
29
|
+
scopes?: Scope[];
|
|
30
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Shortcut = {
|
|
2
|
+
name: string;
|
|
3
|
+
keys: (string | string[])[];
|
|
4
|
+
scope?: string;
|
|
5
|
+
preventDefault?: boolean;
|
|
6
|
+
matcher?: (e: KeyboardEvent, key: string | string[], details: ShortcutEventDetail) => boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type Scope = {
|
|
10
|
+
name: string;
|
|
11
|
+
/*
|
|
12
|
+
* HTMLElement
|
|
13
|
+
* this is currently the only way for now to get focustrap feature.
|
|
14
|
+
* TODO - find a solution with ref
|
|
15
|
+
* */
|
|
16
|
+
node?: Element | null;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ShortcutEventDetail = {
|
|
20
|
+
pressedKeys: string[];
|
|
21
|
+
normalizedKey: string;
|
|
22
|
+
modifiers: string[];
|
|
23
|
+
key: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useIsKeyPress } from './useIsKeyPress';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useShortcutsManagerContextValueSelector } from '../ShortcutsManager';
|
|
2
|
+
|
|
3
|
+
const useIsKeyPress = (key: string) => {
|
|
4
|
+
return useShortcutsManagerContextValueSelector(
|
|
5
|
+
prev => !!prev.pressedKeys.find(pressedKey => pressedKey === key),
|
|
6
|
+
);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default useIsKeyPress;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useSetScopes } from './useSetScopes';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { keyBy } from '../../utils/lodash';
|
|
4
|
+
import { useShortcutsManagerStoreRef } from '../ShortcutsManager/utils';
|
|
5
|
+
import type { Scope } from '../types';
|
|
6
|
+
|
|
7
|
+
const useSetScopes = () => {
|
|
8
|
+
const { set: setStore } = useShortcutsManagerStoreRef();
|
|
9
|
+
|
|
10
|
+
return useCallback(
|
|
11
|
+
(newScopes: Scope[] | ((currentScopes: Scope[]) => Scope[])) => {
|
|
12
|
+
setStore(prev => ({
|
|
13
|
+
scopes: keyBy(
|
|
14
|
+
typeof newScopes === 'function'
|
|
15
|
+
? newScopes(Object.values(prev.scopes))
|
|
16
|
+
: newScopes,
|
|
17
|
+
'name',
|
|
18
|
+
),
|
|
19
|
+
}));
|
|
20
|
+
},
|
|
21
|
+
[setStore],
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default useSetScopes;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import useLatest from '../../hooks/useLatest';
|
|
3
|
+
|
|
4
|
+
import { useShortcutsManagerStoreRef } from '../ShortcutsManager';
|
|
5
|
+
import type { ShortcutEventDetail } from '../types';
|
|
6
|
+
import { calculateShortcutEventName } from '../utils';
|
|
7
|
+
import type { ShortcutCallbackArgs } from './types';
|
|
8
|
+
|
|
9
|
+
const useShortcut = (
|
|
10
|
+
name: string,
|
|
11
|
+
callback: (args: ShortcutCallbackArgs) => void,
|
|
12
|
+
disabled: boolean = false,
|
|
13
|
+
capture: boolean = false,
|
|
14
|
+
) => {
|
|
15
|
+
const { store } = useShortcutsManagerStoreRef();
|
|
16
|
+
|
|
17
|
+
const nameRef = useLatest(name);
|
|
18
|
+
const callbackRef = useLatest(callback);
|
|
19
|
+
|
|
20
|
+
const onCallback = useCallback(
|
|
21
|
+
(e: CustomEvent<ShortcutEventDetail>) => {
|
|
22
|
+
const shortcut = store.current.shortcuts[nameRef.current];
|
|
23
|
+
|
|
24
|
+
if (!shortcut) {
|
|
25
|
+
throw new Error(`Shortcut with name: ${nameRef.current} does not exist`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const scope = store.current.scopes[shortcut.scope || ''];
|
|
29
|
+
|
|
30
|
+
if (shortcut.scope && !scope) return;
|
|
31
|
+
|
|
32
|
+
// if there is node, we check if one of the elements instead it is focused
|
|
33
|
+
if (
|
|
34
|
+
scope?.node &&
|
|
35
|
+
!(
|
|
36
|
+
scope.node === document.activeElement ||
|
|
37
|
+
scope.node.contains(document.activeElement)
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
return;
|
|
41
|
+
|
|
42
|
+
callbackRef.current({ ...e.detail, shortcut: shortcut, event: e });
|
|
43
|
+
},
|
|
44
|
+
[callbackRef, nameRef, store],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (disabled) return;
|
|
49
|
+
|
|
50
|
+
const eventName = calculateShortcutEventName(nameRef.current);
|
|
51
|
+
|
|
52
|
+
document.addEventListener(eventName, onCallback as (e: Event) => void, capture);
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener(eventName, onCallback as (e: Event) => void, capture);
|
|
56
|
+
};
|
|
57
|
+
// eslint-disable-next-line
|
|
58
|
+
}, [onCallback, nameRef, disabled]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default useShortcut;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const MODIFIER_KEYS = ['meta', 'alt', 'shift', 'control'];
|
|
2
|
+
|
|
3
|
+
export const isModifierKey = (pressedKey: string) => {
|
|
4
|
+
return MODIFIER_KEYS.includes(pressedKey);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// This file handles key-name discrepancies between browsers.
|
|
8
|
+
// For the list of discrepancies, go to: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values.
|
|
9
|
+
const mappings = new Map([
|
|
10
|
+
[' ', 'space'], // custom mapping
|
|
11
|
+
['spacebar', 'space'],
|
|
12
|
+
['scroll', 'scrolllock'],
|
|
13
|
+
['del', 'delete'],
|
|
14
|
+
['esc', 'escape'],
|
|
15
|
+
['medianexttrack', 'mediatracknext'],
|
|
16
|
+
['mediaprevioustrack', 'mediatrackprevious'],
|
|
17
|
+
['volumeup', 'audiovolumeup'],
|
|
18
|
+
['volumedown', 'audiovolumedown'],
|
|
19
|
+
['volumemute', 'audiovolumemute'],
|
|
20
|
+
['multiply', '*'],
|
|
21
|
+
['add', '+'],
|
|
22
|
+
['divide', '/'],
|
|
23
|
+
['subtract', '-'],
|
|
24
|
+
['left', 'arrowleft'],
|
|
25
|
+
['right', 'arrowright'],
|
|
26
|
+
['up', 'arrowup'],
|
|
27
|
+
['down', 'arrowdown'],
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get a single, normalized string from the list of the `KeyboardEvent.key` properties.
|
|
32
|
+
*
|
|
33
|
+
* @param {Array<string>} keys The list of the `KeyboardEvent.key` properties
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export const normalizeKeys = (keys: string | string[]): string => {
|
|
37
|
+
if (typeof keys === 'string') return keys.toLowerCase();
|
|
38
|
+
|
|
39
|
+
return keys
|
|
40
|
+
.map(key => {
|
|
41
|
+
const lowercaseKey = key.toLowerCase();
|
|
42
|
+
|
|
43
|
+
if (mappings.has(lowercaseKey)) {
|
|
44
|
+
return mappings.get(lowercaseKey) as string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return lowercaseKey;
|
|
48
|
+
})
|
|
49
|
+
.sort()
|
|
50
|
+
.join('+');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get every pressed modifier key from the performed `KeyboardEvent`.
|
|
55
|
+
*
|
|
56
|
+
* @private
|
|
57
|
+
* @param {KeyboardEvent} event The event object.
|
|
58
|
+
* @param {boolean} [mergeMetaKeys=false] If `true,` the function will return the "control" and "meta"
|
|
59
|
+
* modifiers keys as the "control/meta" name. This allows creating
|
|
60
|
+
* keyboard shortcuts with modifier key that trigger the shortcut
|
|
61
|
+
* actions depend on the OS keyboard layout (the Meta key for macOS
|
|
62
|
+
* and Control for non macOS system).
|
|
63
|
+
* @returns {string[]}
|
|
64
|
+
*/
|
|
65
|
+
export const getPressedModifierKeys = (event: KeyboardEvent, mergeMetaKeys = false) => {
|
|
66
|
+
const pressedModifierKeys = [];
|
|
67
|
+
|
|
68
|
+
if (event.altKey) {
|
|
69
|
+
pressedModifierKeys.push('alt');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (mergeMetaKeys && (event.ctrlKey || event.metaKey)) {
|
|
73
|
+
pressedModifierKeys.push('control/meta');
|
|
74
|
+
} else {
|
|
75
|
+
if (event.ctrlKey) {
|
|
76
|
+
pressedModifierKeys.push('control');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (event.metaKey) {
|
|
80
|
+
pressedModifierKeys.push('meta');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (event.shiftKey) {
|
|
85
|
+
pressedModifierKeys.push('shift');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return pressedModifierKeys;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const isKey = (pressedKey: string, key: string) =>
|
|
92
|
+
mappings.get(pressedKey.toLowerCase()) === key;
|
|
93
|
+
|
|
94
|
+
export const isSpaceKey = (pressedKey: string) => isKey(pressedKey, 'space');
|
|
95
|
+
|
|
96
|
+
export const isEnterKey = (pressedKey: string) => isKey(pressedKey, 'enter');
|
|
97
|
+
|
|
98
|
+
export const isEscapeKey = (pressedKey: string) => isKey(pressedKey, 'escape');
|
|
99
|
+
|
|
100
|
+
export const isTabKey = (pressedKey: string) => isKey(pressedKey, 'tab');
|
|
101
|
+
|
|
102
|
+
export const shortcutEventPrefix = 'shortcut-event-';
|
|
103
|
+
|
|
104
|
+
export const calculateShortcutEventName = (shortcutName: string) =>
|
|
105
|
+
`${shortcutEventPrefix}-${shortcutName}`;
|
package/styles/index.ts
ADDED