@react-fabric/core 1.0.0-beta.62 → 1.0.0-beta.63
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/css/components/_animations.css +7 -11
- package/css/components/_avatar.css +5 -5
- package/css/components/_badge.css +2 -1
- package/css/components/_breadcrumbs.css +5 -5
- package/css/components/_button.css +48 -14
- package/css/components/_card.css +9 -17
- package/css/components/_chip.css +0 -4
- package/css/components/_dropdown.css +1 -0
- package/css/components/_flyout.css +1 -1
- package/css/components/_media.css +2 -14
- package/css/components/_menu.css +1 -1
- package/css/components/_modal.css +1 -1
- package/css/components/_progress.css +1 -1
- package/css/components/_stepper.css +2 -1
- package/css/components/_tabPanel.css +4 -4
- package/css/core/_aside.css +3 -3
- package/css/core/_errorboundary.css +2 -10
- package/css/core/_page.css +1 -1
- package/css/core/_responsive.css +8 -0
- package/css/core/_viewport.css +1 -5
- package/css/reset/_reset.css +36 -41
- package/css/reset/_theme.css +214 -201
- package/css/styles.css +5 -0
- package/css/theme/_colors.css +14 -0
- package/css/theme/_utilities.css +103 -225
- package/css/theme/index.css +4 -6
- package/dist/cjs/components/actionLabel/ActionLabel.js +1 -1
- package/dist/cjs/components/animations/Animations.js +7 -7
- package/dist/cjs/components/avatar/Avatar.js +1 -1
- package/dist/cjs/components/avatar/AvatarGroup.js +1 -1
- package/dist/cjs/components/badge/Badge.js +5 -27
- package/dist/cjs/components/breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/cjs/components/button/Button.js +7 -5
- package/dist/cjs/components/button/ButtonGroup.js +1 -1
- package/dist/cjs/components/button/ConfirmButton.js +7 -6
- package/dist/cjs/components/button/ToggleButtonGroup.js +1 -1
- package/dist/cjs/components/callout/Callout.js +8 -7
- package/dist/cjs/components/card/Card.js +3 -3
- package/dist/cjs/components/card/CardCover.js +1 -1
- package/dist/cjs/components/card/FlipContent.js +2 -2
- package/dist/cjs/components/chip/Chip.js +8 -7
- package/dist/cjs/components/collapsable/Collapsable.js +4 -3
- package/dist/cjs/components/divider/Divider.js +2 -2
- package/dist/cjs/components/dropdown/Dropdown.js +18 -16
- package/dist/cjs/components/empty/EmptyContent.js +1 -1
- package/dist/cjs/components/icon/Icon.js +2 -16
- package/dist/cjs/components/media/Media.js +13 -13
- package/dist/cjs/components/menu/ContextMenu.js +23 -13
- package/dist/cjs/components/menu/Menu.js +16 -12
- package/dist/cjs/components/menu/MenuItem.js +4 -3
- package/dist/cjs/components/meter/Meter.js +1 -1
- package/dist/cjs/components/navigator/Navigator.js +5 -5
- package/dist/cjs/components/panel/Panel.js +6 -4
- package/dist/cjs/components/panel/PanelGroup.js +3 -3
- package/dist/cjs/components/panel/PanelStack.js +5 -5
- package/dist/cjs/components/progress/ProgressBar.js +2 -2
- package/dist/cjs/components/progress/ProgressCircle.js +2 -2
- package/dist/cjs/components/tabpanel/Tab.js +6 -4
- package/dist/cjs/components/tabpanel/TabPanel.js +4 -4
- package/dist/cjs/context/Global.js +2 -55
- package/dist/cjs/context/NotificationCenter.js +38 -39
- package/dist/cjs/context/context.js +59 -0
- package/dist/cjs/core/aside/Aside.js +9 -7
- package/dist/cjs/core/boundary/ErrorBoundary.js +2 -4
- package/dist/cjs/core/page/Page.js +4 -1
- package/dist/cjs/core/responsive/Responsive.js +3 -2
- package/dist/cjs/core/theme/ThemeProvider.js +2 -2
- package/dist/cjs/core/viewport/Viewport.js +1 -1
- package/dist/cjs/hooks/useContextMenu.js +103 -0
- package/dist/cjs/hooks/useIsDark.js +6 -4
- package/dist/cjs/hooks/useNavigator.js +2 -2
- package/dist/cjs/hooks/useOverlayService.js +10 -42
- package/dist/cjs/hooks/usePropToggle.js +2 -2
- package/dist/cjs/hooks/useResize.js +8 -6
- package/dist/cjs/hooks/useResizeObserver.js +5 -5
- package/dist/cjs/hooks/useStepper.js +2 -6
- package/dist/cjs/hotkeys/HotKey.js +2 -2
- package/dist/cjs/hotkeys/HotKeyWrapper.js +8 -13
- package/dist/cjs/hotkeys/commons.js +1 -1
- package/dist/cjs/hotkeys/context.js +36 -0
- package/dist/cjs/index.js +9 -5
- package/dist/cjs/overlays/alert/Alert.js +6 -5
- package/dist/cjs/overlays/flyout/Flyout.js +8 -6
- package/dist/cjs/overlays/message/Message.js +5 -5
- package/dist/cjs/overlays/modal/Modal.js +5 -3
- package/dist/cjs/overlays/toast/Toast.js +4 -4
- package/dist/cjs/overlays/tooltip/Tooltip.js +2 -16
- package/dist/cjs/typography/Abbr.js +4 -5
- package/dist/cjs/typography/Anchor.js +2 -2
- package/dist/cjs/typography/Copy.js +2 -2
- package/dist/cjs/typography/Mark.js +2 -4
- package/dist/cjs/typography/Text.js +4 -4
- package/dist/cjs/typography/Title.js +2 -2
- package/dist/cjs/utils/cloneElement.js +4 -4
- package/dist/cjs/utils/getBadgeProps.js +51 -0
- package/dist/cjs/utils/getIconProps.js +42 -0
- package/dist/cjs/utils/getTooltipProps.js +45 -0
- package/dist/esm/components/actionLabel/ActionLabel.js +1 -1
- package/dist/esm/components/animations/Animations.js +7 -7
- package/dist/esm/components/avatar/Avatar.js +1 -1
- package/dist/esm/components/avatar/AvatarGroup.js +1 -1
- package/dist/esm/components/badge/Badge.js +7 -28
- package/dist/esm/components/breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/esm/components/button/Button.js +8 -6
- package/dist/esm/components/button/ButtonGroup.js +3 -3
- package/dist/esm/components/button/ConfirmButton.js +8 -7
- package/dist/esm/components/button/ToggleButtonGroup.js +3 -3
- package/dist/esm/components/callout/Callout.js +8 -7
- package/dist/esm/components/card/Card.js +4 -4
- package/dist/esm/components/card/CardCover.js +1 -1
- package/dist/esm/components/card/FlipContent.js +2 -2
- package/dist/esm/components/chip/Chip.js +9 -8
- package/dist/esm/components/collapsable/Collapsable.js +4 -3
- package/dist/esm/components/divider/Divider.js +2 -2
- package/dist/esm/components/dropdown/Dropdown.js +19 -17
- package/dist/esm/components/empty/EmptyContent.js +1 -1
- package/dist/esm/components/icon/Icon.js +4 -17
- package/dist/esm/components/media/Media.js +13 -13
- package/dist/esm/components/menu/ContextMenu.js +24 -14
- package/dist/esm/components/menu/Menu.js +19 -15
- package/dist/esm/components/menu/MenuItem.js +5 -4
- package/dist/esm/components/meter/Meter.js +1 -1
- package/dist/esm/components/navigator/Navigator.js +6 -6
- package/dist/esm/components/panel/Panel.js +6 -4
- package/dist/esm/components/panel/PanelGroup.js +4 -4
- package/dist/esm/components/panel/PanelStack.js +6 -6
- package/dist/esm/components/progress/ProgressBar.js +2 -2
- package/dist/esm/components/progress/ProgressCircle.js +2 -2
- package/dist/esm/components/tabpanel/Tab.js +6 -4
- package/dist/esm/components/tabpanel/TabPanel.js +5 -5
- package/dist/esm/context/Global.js +3 -52
- package/dist/esm/context/NotificationCenter.js +38 -39
- package/dist/esm/context/context.js +56 -0
- package/dist/esm/core/aside/Aside.js +10 -8
- package/dist/esm/core/boundary/ErrorBoundary.js +1 -3
- package/dist/esm/core/page/Page.js +4 -1
- package/dist/esm/core/responsive/Responsive.js +3 -2
- package/dist/esm/core/theme/ThemeProvider.js +1 -1
- package/dist/esm/core/viewport/Viewport.js +1 -1
- package/dist/esm/hooks/useContextMenu.js +103 -0
- package/dist/esm/hooks/useIsDark.js +7 -5
- package/dist/esm/hooks/useNavigator.js +3 -3
- package/dist/esm/hooks/useOverlayService.js +8 -40
- package/dist/esm/hooks/usePropToggle.js +3 -3
- package/dist/esm/hooks/useResize.js +9 -7
- package/dist/esm/hooks/useResizeObserver.js +6 -6
- package/dist/esm/hooks/useStepper.js +2 -6
- package/dist/esm/hotkeys/HotKey.js +1 -1
- package/dist/esm/hotkeys/HotKeyWrapper.js +9 -12
- package/dist/esm/hotkeys/commons.js +1 -1
- package/dist/esm/hotkeys/context.js +35 -0
- package/dist/esm/index.js +7 -3
- package/dist/esm/overlays/alert/Alert.js +7 -6
- package/dist/esm/overlays/flyout/Flyout.js +9 -7
- package/dist/esm/overlays/message/Message.js +6 -6
- package/dist/esm/overlays/modal/Modal.js +6 -4
- package/dist/esm/overlays/toast/Toast.js +5 -5
- package/dist/esm/overlays/tooltip/Tooltip.js +4 -17
- package/dist/esm/typography/Abbr.js +4 -5
- package/dist/esm/typography/Anchor.js +2 -2
- package/dist/esm/typography/Copy.js +3 -3
- package/dist/esm/typography/Mark.js +2 -4
- package/dist/esm/typography/Text.js +5 -5
- package/dist/esm/typography/Title.js +2 -2
- package/dist/esm/utils/cloneElement.js +4 -4
- package/dist/esm/utils/getBadgeProps.js +51 -0
- package/dist/esm/utils/getIconProps.js +42 -0
- package/dist/esm/utils/getTooltipProps.js +45 -0
- package/dist/types/components/actionLabel/ActionLabel.d.ts +1 -1
- package/dist/types/components/animations/Animations.d.ts +6 -6
- package/dist/types/components/avatar/Avatar.d.ts +1 -1
- package/dist/types/components/avatar/AvatarGroup.d.ts +1 -1
- package/dist/types/components/badge/Badge.d.ts +2 -10
- package/dist/types/components/breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/dist/types/components/button/Button.d.ts +1 -1
- package/dist/types/components/button/ButtonGroup.d.ts +1 -1
- package/dist/types/components/button/ConfirmButton.d.ts +1 -1
- package/dist/types/components/button/ToggleButtonGroup.d.ts +1 -1
- package/dist/types/components/callout/Callout.d.ts +7 -3
- package/dist/types/components/card/Card.d.ts +2 -2
- package/dist/types/components/card/CardCover.d.ts +1 -1
- package/dist/types/components/card/FlipContent.d.ts +1 -1
- package/dist/types/components/chip/Chip.d.ts +1 -1
- package/dist/types/components/collapsable/Collapsable.d.ts +1 -1
- package/dist/types/components/divider/Divider.d.ts +1 -1
- package/dist/types/components/dropdown/Dropdown.d.ts +7 -3
- package/dist/types/components/dropdown/DropdownTool.d.ts +1 -1
- package/dist/types/components/empty/EmptyContent.d.ts +3 -3
- package/dist/types/components/icon/Icon.d.ts +3 -4
- package/dist/types/components/index.d.ts +2 -2
- package/dist/types/components/media/Media.d.ts +2 -2
- package/dist/types/components/menu/ContextMenu.d.ts +1 -1
- package/dist/types/components/menu/Menu.d.ts +1 -1
- package/dist/types/components/menu/types.d.ts +1 -1
- package/dist/types/components/meter/Meter.d.ts +1 -1
- package/dist/types/components/navigator/Navigator.d.ts +1 -1
- package/dist/types/components/panel/Panel.d.ts +2 -2
- package/dist/types/components/panel/PanelGroup.d.ts +1 -1
- package/dist/types/components/panel/PanelStack.d.ts +1 -1
- package/dist/types/components/progress/ProgressBar.d.ts +1 -1
- package/dist/types/components/progress/ProgressCircle.d.ts +1 -1
- package/dist/types/components/tabpanel/Tab.d.ts +1 -1
- package/dist/types/components/tabpanel/TabPanel.d.ts +1 -1
- package/dist/types/context/Global.d.ts +0 -82
- package/dist/types/context/context.d.ts +85 -0
- package/dist/types/core/aside/Aside.d.ts +2 -2
- package/dist/types/core/responsive/Responsive.d.ts +5 -1
- package/dist/types/hooks/useContextMenu.d.ts +10 -0
- package/dist/types/hotkeys/HotKeyWrapper.d.ts +0 -9
- package/dist/types/hotkeys/context.d.ts +9 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/overlays/alert/Alert.d.ts +2 -2
- package/dist/types/overlays/flyout/Flyout.d.ts +2 -2
- package/dist/types/overlays/message/Message.d.ts +2 -2
- package/dist/types/overlays/modal/Modal.d.ts +2 -2
- package/dist/types/overlays/toast/Toast.d.ts +2 -2
- package/dist/types/overlays/tooltip/Tooltip.d.ts +0 -3
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/typography/Abbr.d.ts +4 -8
- package/dist/types/typography/Anchor.d.ts +1 -1
- package/dist/types/typography/Copy.d.ts +1 -1
- package/dist/types/typography/Mark.d.ts +2 -2
- package/dist/types/typography/Text.d.ts +1 -1
- package/dist/types/typography/Title.d.ts +1 -1
- package/dist/types/utils/getBadgeProps.d.ts +9 -0
- package/dist/types/utils/getIconProps.d.ts +2 -0
- package/dist/types/utils/getTooltipProps.d.ts +4 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/package.json +14 -15
- package/src/components/actionLabel/ActionLabel.tsx +1 -1
- package/src/components/animations/Animations.tsx +6 -6
- package/src/components/avatar/Avatar.tsx +1 -1
- package/src/components/avatar/AvatarGroup.tsx +1 -1
- package/src/components/badge/Badge.tsx +8 -46
- package/src/components/breadcrumbs/Breadcrumbs.tsx +1 -1
- package/src/components/button/Button.tsx +24 -54
- package/src/components/button/ButtonGroup.tsx +1 -1
- package/src/components/button/ConfirmButton.tsx +23 -20
- package/src/components/button/ToggleButtonGroup.tsx +1 -1
- package/src/components/callout/Callout.tsx +14 -19
- package/src/components/card/Card.tsx +9 -11
- package/src/components/card/CardCover.tsx +1 -1
- package/src/components/card/FlipContent.tsx +2 -2
- package/src/components/chip/Chip.tsx +16 -33
- package/src/components/collapsable/Collapsable.tsx +2 -2
- package/src/components/divider/Divider.tsx +1 -1
- package/src/components/dropdown/Dropdown.tsx +42 -72
- package/src/components/dropdown/DropdownTool.tsx +1 -1
- package/src/components/empty/EmptyContent.tsx +3 -3
- package/src/components/icon/Icon.tsx +5 -32
- package/src/components/index.ts +2 -2
- package/src/components/media/Media.tsx +3 -3
- package/src/components/menu/ContextMenu.tsx +30 -30
- package/src/components/menu/Menu.tsx +32 -61
- package/src/components/menu/MenuItem.tsx +9 -28
- package/src/components/menu/types.ts +1 -1
- package/src/components/meter/Meter.tsx +1 -1
- package/src/components/navigator/Navigator.tsx +5 -10
- package/src/components/panel/Panel.tsx +13 -54
- package/src/components/panel/PanelGroup.tsx +3 -4
- package/src/components/panel/PanelStack.tsx +20 -25
- package/src/components/progress/ProgressBar.tsx +2 -2
- package/src/components/progress/ProgressCircle.tsx +2 -2
- package/src/components/tabpanel/Tab.tsx +9 -28
- package/src/components/tabpanel/TabPanel.tsx +11 -14
- package/src/context/Global.tsx +18 -125
- package/src/context/NotificationCenter.tsx +0 -1
- package/src/context/context.ts +100 -0
- package/src/core/aside/Aside.tsx +18 -55
- package/src/core/boundary/ErrorBoundary.tsx +8 -37
- package/src/core/page/Page.tsx +3 -5
- package/src/core/responsive/Responsive.tsx +10 -34
- package/src/core/theme/ThemeProvider.tsx +2 -7
- package/src/core/viewport/Viewport.tsx +1 -1
- package/src/hooks/useContextMenu.tsx +131 -0
- package/src/hooks/useIsDark.ts +7 -5
- package/src/hooks/useNavigator.tsx +12 -15
- package/src/hooks/useOverlayService.tsx +3 -11
- package/src/hooks/usePropToggle.ts +3 -3
- package/src/hooks/useResize.ts +14 -17
- package/src/hooks/useResizeObserver.ts +21 -21
- package/src/hooks/useStepper.tsx +1 -1
- package/src/hotkeys/HotKey.tsx +1 -1
- package/src/hotkeys/HotKeyWrapper.tsx +81 -105
- package/src/hotkeys/commons.ts +2 -0
- package/src/hotkeys/context.ts +32 -0
- package/src/index.ts +4 -7
- package/src/overlays/alert/Alert.tsx +12 -16
- package/src/overlays/flyout/Flyout.tsx +32 -69
- package/src/overlays/message/Message.tsx +11 -15
- package/src/overlays/modal/Modal.tsx +23 -57
- package/src/overlays/toast/Toast.tsx +16 -15
- package/src/overlays/tooltip/Tooltip.tsx +6 -29
- package/src/types/global.d.ts +12 -0
- package/src/types/index.ts +2 -2
- package/src/typography/Abbr.tsx +11 -39
- package/src/typography/Anchor.tsx +1 -1
- package/src/typography/Copy.tsx +4 -4
- package/src/typography/Mark.tsx +2 -3
- package/src/typography/Text.tsx +8 -6
- package/src/typography/Title.tsx +1 -1
- package/src/utils/getBadgeProps.ts +45 -0
- package/src/utils/getIconProps.ts +35 -0
- package/src/utils/getTooltipProps.ts +38 -0
- package/src/utils/index.ts +3 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2026 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
FloatingFocusManager,
|
|
26
|
+
FloatingOverlay,
|
|
27
|
+
FloatingPortal,
|
|
28
|
+
autoUpdate,
|
|
29
|
+
flip,
|
|
30
|
+
offset,
|
|
31
|
+
useClick,
|
|
32
|
+
useDismiss,
|
|
33
|
+
useFloating,
|
|
34
|
+
useFloatingNodeId,
|
|
35
|
+
useInteractions,
|
|
36
|
+
} from "@floating-ui/react";
|
|
37
|
+
import { cloneElement, useEffectEvent, useRef, useState } from "react";
|
|
38
|
+
import { type Menu } from "../components/menu/Menu";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A hook that provides a context menu that appears on right-click.
|
|
42
|
+
* It uses the Floating UI library to manage the positioning and interactions of the menu.
|
|
43
|
+
* This hook is useful for creating custom context menus that can be triggered by right-clicking on elements.
|
|
44
|
+
*
|
|
45
|
+
* @param {ContextMenuProps} props - The properties for the ContextMenu hook.
|
|
46
|
+
* @returns {[React.ReactElement | null, (e: MouseEvent) => void]} An array containing the rendered ContextMenu component (or null if not open) and the function to handle right-click events.
|
|
47
|
+
*/
|
|
48
|
+
export const useContextMenu = (
|
|
49
|
+
menu: React.ReactElement<typeof Menu>,
|
|
50
|
+
): [Overlay: React.ReactNode, onContentMenu: (e: React.MouseEvent) => void] => {
|
|
51
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
52
|
+
const nodeId = useFloatingNodeId();
|
|
53
|
+
|
|
54
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
55
|
+
open: isOpen,
|
|
56
|
+
nodeId,
|
|
57
|
+
onOpenChange: (open, evt, reason) => {
|
|
58
|
+
const target = evt?.target as HTMLElement;
|
|
59
|
+
if (!target?.closest(".menu-list")) setIsOpen(open);
|
|
60
|
+
},
|
|
61
|
+
strategy: "fixed",
|
|
62
|
+
placement: "bottom-start",
|
|
63
|
+
whileElementsMounted: autoUpdate,
|
|
64
|
+
middleware: [offset(8), flip()],
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const click = useClick(context, {
|
|
68
|
+
toggle: true,
|
|
69
|
+
ignoreMouse: true,
|
|
70
|
+
});
|
|
71
|
+
const dismiss = useDismiss(context, { bubbles: true });
|
|
72
|
+
|
|
73
|
+
const { getFloatingProps } = useInteractions([dismiss, click]);
|
|
74
|
+
|
|
75
|
+
const handleClick = useEffectEvent((e: React.MouseEvent) => {
|
|
76
|
+
const virtual = {
|
|
77
|
+
getBoundingClientRect() {
|
|
78
|
+
return {
|
|
79
|
+
width: 0,
|
|
80
|
+
height: 0,
|
|
81
|
+
x: e.clientX,
|
|
82
|
+
y: e.clientY,
|
|
83
|
+
top: e.clientY,
|
|
84
|
+
left: e.clientX,
|
|
85
|
+
right: e.clientX,
|
|
86
|
+
bottom: e.clientY,
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
refs.setReference(virtual);
|
|
91
|
+
setIsOpen(true);
|
|
92
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const tryClosing = useRef((e: React.MouseEvent) => {
|
|
98
|
+
if (!(e.target as HTMLElement)?.closest("[data-dropdown-dismiss='false']")) setTimeout(() => setIsOpen(false), 50);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return [
|
|
102
|
+
isOpen && (
|
|
103
|
+
<FloatingPortal root={refs.domReference.current?.closest<HTMLElement>(".theme-base") ?? undefined}>
|
|
104
|
+
<FloatingOverlay
|
|
105
|
+
lockScroll
|
|
106
|
+
style={{
|
|
107
|
+
zIndex: "var(--z-overlay-mask)",
|
|
108
|
+
position: "absolute",
|
|
109
|
+
overflow: "hidden",
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
<FloatingFocusManager context={context}>
|
|
113
|
+
{cloneElement(menu as AnyObject, {
|
|
114
|
+
...getFloatingProps(),
|
|
115
|
+
style: {
|
|
116
|
+
...floatingStyles,
|
|
117
|
+
borderRadius: "var(--rounding)",
|
|
118
|
+
zIndex: "var(--z-popover)",
|
|
119
|
+
fontSize: "0.875rem",
|
|
120
|
+
},
|
|
121
|
+
className: "bg-default outline rounded-capped shadow-lg",
|
|
122
|
+
ref: refs.setFloating,
|
|
123
|
+
onMouseUp: tryClosing.current,
|
|
124
|
+
})}
|
|
125
|
+
</FloatingFocusManager>
|
|
126
|
+
</FloatingOverlay>
|
|
127
|
+
</FloatingPortal>
|
|
128
|
+
),
|
|
129
|
+
handleClick,
|
|
130
|
+
];
|
|
131
|
+
};
|
package/src/hooks/useIsDark.ts
CHANGED
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { debounce } from "@react-fabric/utilities";
|
|
25
|
+
import { useEffectEvent, useState } from "react";
|
|
25
26
|
import { useLayoutEffectDebugger } from "./useEffectDebugger";
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -34,18 +35,19 @@ import { useLayoutEffectDebugger } from "./useEffectDebugger";
|
|
|
34
35
|
*/
|
|
35
36
|
export const useIsDark = () => {
|
|
36
37
|
const [isDark, setDark] = useState(false);
|
|
37
|
-
const checkTheme =
|
|
38
|
+
const checkTheme = useEffectEvent(() => {
|
|
38
39
|
const [r] = getComputedStyle(
|
|
39
40
|
document.documentElement,
|
|
40
41
|
).backgroundColor.match(/\d?\d?\d/g) as AnyObject;
|
|
41
42
|
setDark(+r < 50);
|
|
42
|
-
}
|
|
43
|
+
});
|
|
43
44
|
useLayoutEffectDebugger(
|
|
44
45
|
() => {
|
|
45
46
|
if (MutationObserver) {
|
|
46
|
-
const
|
|
47
|
+
const cb = debounce(checkTheme, 100);
|
|
48
|
+
const ob = new MutationObserver(cb);
|
|
47
49
|
ob.observe(document.documentElement, { attributes: true });
|
|
48
|
-
|
|
50
|
+
cb();
|
|
49
51
|
return () => {
|
|
50
52
|
ob.disconnect();
|
|
51
53
|
};
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { useEffectEvent, useMemo, useState } from "react";
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Custom hook to manage navigation through a list of items.
|
|
@@ -44,20 +44,17 @@ import { useCallback, useMemo, useState } from "react";
|
|
|
44
44
|
export const useNavigator = (totalCount = 0, defaultIndex = 0) => {
|
|
45
45
|
const [currentIndex, setCurrentIndex] = useState(defaultIndex);
|
|
46
46
|
|
|
47
|
-
const onNavigate =
|
|
48
|
-
(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
[totalCount],
|
|
60
|
-
);
|
|
47
|
+
const onNavigate = useEffectEvent((dir: 1 | -1) => {
|
|
48
|
+
setCurrentIndex((prevValue) => {
|
|
49
|
+
if (dir === -1) {
|
|
50
|
+
return prevValue > 0 ? prevValue - 1 : totalCount - 1;
|
|
51
|
+
}
|
|
52
|
+
if (dir === 1) {
|
|
53
|
+
return prevValue + 1 < totalCount ? prevValue + 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
return prevValue;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
61
58
|
const headLabel = useMemo(
|
|
62
59
|
() => (
|
|
63
60
|
<span className="text-muted leading-none select-none">
|
|
@@ -23,9 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { useRef, useState } from "react";
|
|
25
25
|
import { type ModalProps } from "../types";
|
|
26
|
-
|
|
27
|
-
// return the blank function since state functionality will execute if the value is function
|
|
28
|
-
const EMPTY_FC = () => () => null;
|
|
26
|
+
import { EMPTY_FC } from "@react-fabric/utilities";
|
|
29
27
|
|
|
30
28
|
/**
|
|
31
29
|
* Hook to manage overlay components like modals or flyouts.
|
|
@@ -59,8 +57,7 @@ export const useOverlayService = <T extends AnyObject = AnyObject>(
|
|
|
59
57
|
openOverlay: (props?: Partial<T>) => Promise<AnyObject>,
|
|
60
58
|
closeOverlay: ((args?: AnyObject) => void) | null,
|
|
61
59
|
] => {
|
|
62
|
-
const [Overlay, setOverlay] =
|
|
63
|
-
useState<React.FunctionComponent<Partial<T>>>(EMPTY_FC);
|
|
60
|
+
const [Overlay, setOverlay] = useState<React.FunctionComponent<Partial<T>>>(EMPTY_FC);
|
|
64
61
|
|
|
65
62
|
const existingOpenPromise = useRef<AnyObject | null>(null);
|
|
66
63
|
const openOverlay = async ({ onClose, ...outerProps }: AnyObject = {}) => {
|
|
@@ -74,13 +71,8 @@ export const useOverlayService = <T extends AnyObject = AnyObject>(
|
|
|
74
71
|
onClose?.(args);
|
|
75
72
|
existingOpenPromise.current = null;
|
|
76
73
|
};
|
|
77
|
-
// eslint-disable-next-line react/display-name
|
|
78
74
|
setOverlay(() => (overrideProps: Partial<T>) => (
|
|
79
|
-
<ModalOrFlyout
|
|
80
|
-
{...outerProps}
|
|
81
|
-
{...(overrideProps as any)}
|
|
82
|
-
onClose={existingOpenPromise.current}
|
|
83
|
-
/>
|
|
75
|
+
<ModalOrFlyout {...outerProps} {...(overrideProps as any)} onClose={existingOpenPromise.current} />
|
|
84
76
|
));
|
|
85
77
|
});
|
|
86
78
|
};
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { useEffectEvent, useRef, useState, type RefObject } from "react";
|
|
25
25
|
import { useLayoutEffectDebugger } from "./useEffectDebugger";
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -61,12 +61,12 @@ export const usePropToggle = (
|
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
/** ***************** toggle handler *******************/
|
|
64
|
-
const doToggle =
|
|
64
|
+
const doToggle = useEffectEvent(() => {
|
|
65
65
|
if (onToggle?.(!toggleOn, key) !== false) {
|
|
66
66
|
toggleRef.current = !toggleOn;
|
|
67
67
|
setToggleOn(!toggleOn);
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
});
|
|
70
70
|
|
|
71
71
|
return [toggleOn, doToggle, toggleRef];
|
|
72
72
|
};
|
package/src/hooks/useResize.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { useCallback, useRef, type RefObject } from "react";
|
|
24
|
+
import { useCallback, useEffectEvent, useRef, type RefObject } from "react";
|
|
25
25
|
import { useIsRtl } from "./useIsRtl";
|
|
26
26
|
|
|
27
27
|
interface Options {
|
|
@@ -74,14 +74,14 @@ export const useResize = <T extends HTMLElement = HTMLDivElement>(
|
|
|
74
74
|
/** ***************** check if reverse enabled of RTL *******************/
|
|
75
75
|
const reversed = ((isRtl ? 1 : 0) ^ (isReverse ? 1 : 0)) === 1;
|
|
76
76
|
const box = refEl.current?.getBoundingClientRect();
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const y = evt.clientY -
|
|
77
|
+
const diffX = ((box.left + box.right) / 2) * (reversed ? -1 : 1);
|
|
78
|
+
const diffY = (box.top + box.bottom) / 2;
|
|
79
|
+
const x = evt.clientX - diffX;
|
|
80
|
+
const y = evt.clientY - diffY;
|
|
81
81
|
onResize({ x, y });
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
|
-
[
|
|
84
|
+
[isRtl, isReverse, onResize],
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
/** ***************** dettach handlers on mouseup *******************/
|
|
@@ -90,19 +90,16 @@ export const useResize = <T extends HTMLElement = HTMLDivElement>(
|
|
|
90
90
|
document.removeEventListener("mousemove", onResizing);
|
|
91
91
|
document.removeEventListener("mouseup", onResizeEnd);
|
|
92
92
|
onEnd?.();
|
|
93
|
-
}, [
|
|
93
|
+
}, [onResizing, onEnd]);
|
|
94
94
|
|
|
95
95
|
/** ***************** attach handlers on mousedown *******************/
|
|
96
|
-
const onResizeStart =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
},
|
|
104
|
-
[onResizing, onResizeEnd, onStart],
|
|
105
|
-
);
|
|
96
|
+
const onResizeStart = useEffectEvent((e: React.MouseEvent) => {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
document.body.style.cursor = isVertical ? "row-resize" : "col-resize";
|
|
99
|
+
document.addEventListener("mousemove", onResizing);
|
|
100
|
+
document.addEventListener("mouseup", onResizeEnd);
|
|
101
|
+
onStart?.();
|
|
102
|
+
});
|
|
106
103
|
|
|
107
104
|
return { ref: refEl, onMouseDown: onResizeStart };
|
|
108
105
|
};
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { useEffectEvent, useRef, useTransition, type RefObject } from "react";
|
|
25
25
|
import ResizeObserver from "resize-observer-polyfill";
|
|
26
26
|
import { type SizeObject } from "../types";
|
|
27
|
-
import {
|
|
27
|
+
import { useEffectDebugger } from "./useEffectDebugger";
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Custom hook to observe size changes of an element using ResizeObserver.
|
|
@@ -51,28 +51,28 @@ export const useResizeObserver = <T extends HTMLElement = HTMLDivElement>(
|
|
|
51
51
|
const ref = useRef<T>(null);
|
|
52
52
|
const [, startTransition] = useTransition();
|
|
53
53
|
|
|
54
|
-
const callbackResize =
|
|
54
|
+
const callbackResize = useEffectEvent(() => {
|
|
55
|
+
startTransition(() => {
|
|
56
|
+
if (onResize && ref.current != null) {
|
|
57
|
+
const { offsetWidth: width, offsetHeight: height } = ref.current;
|
|
58
|
+
onResize?.({ width, height });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
useEffectDebugger(
|
|
55
64
|
() => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
if (ref.current != null) {
|
|
66
|
+
const ob = new ResizeObserver(callbackResize);
|
|
67
|
+
ob.observe(ref.current);
|
|
68
|
+
return () => {
|
|
69
|
+
ob.disconnect();
|
|
70
|
+
};
|
|
71
|
+
}
|
|
62
72
|
},
|
|
63
|
-
[
|
|
64
|
-
|
|
73
|
+
[],
|
|
74
|
+
"useResizeObserver",
|
|
65
75
|
);
|
|
66
76
|
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (ref.current != null) {
|
|
69
|
-
const ob = new ResizeObserver(callbackResize);
|
|
70
|
-
ob.observe(ref.current);
|
|
71
|
-
return () => {
|
|
72
|
-
ob.disconnect();
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}, [callbackResize, ref]);
|
|
76
|
-
|
|
77
77
|
return ref;
|
|
78
78
|
};
|
package/src/hooks/useStepper.tsx
CHANGED
|
@@ -36,7 +36,7 @@ export const useStepper = ({
|
|
|
36
36
|
|
|
37
37
|
const stepper = useMemo(() => {
|
|
38
38
|
return (
|
|
39
|
-
<div className="fabric-stepper bg-
|
|
39
|
+
<div className="fabric-stepper bg-default flex-1 flex justify-center py-1 px-2 overflow-x-auto">
|
|
40
40
|
{steps.map((child: any, index) => (
|
|
41
41
|
<div
|
|
42
42
|
className="fabric-stepper--pill"
|
package/src/hotkeys/HotKey.tsx
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { useEffectDebugger } from "../hooks/useEffectDebugger";
|
|
25
|
-
import { useHotKeys } from "./HotKeyWrapper";
|
|
26
25
|
import { type HotKeyProps } from "./commons";
|
|
26
|
+
import { useHotKeys } from "./context";
|
|
27
27
|
|
|
28
28
|
export const HotKey = ({ keyCombo, global, handler }: HotKeyProps) => {
|
|
29
29
|
const { addHotKey, removeHotKey } = useHotKeys();
|
|
@@ -21,119 +21,95 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
createContext,
|
|
26
|
-
memo,
|
|
27
|
-
useCallback,
|
|
28
|
-
useContext,
|
|
29
|
-
useRef,
|
|
30
|
-
type FC,
|
|
31
|
-
type PropsWithChildren,
|
|
32
|
-
} from "react";
|
|
24
|
+
import { memo, useCallback, useEffectEvent, useRef, type FC, type PropsWithChildren } from "react";
|
|
33
25
|
import { useEffectDebugger } from "../hooks/useEffectDebugger";
|
|
34
26
|
import { reduceHotKey } from "./commons";
|
|
27
|
+
import { HotKeysContext } from "./context";
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
removeHotKey: (key: string) => void;
|
|
40
|
-
}>({} as AnyObject);
|
|
29
|
+
export const HotKeyWrapper: FC<PropsWithChildren> = memo(({ children }: PropsWithChildren) => {
|
|
30
|
+
const refEl = useRef<HTMLDivElement>(null);
|
|
31
|
+
const keyList = useRef<KeyValue[]>([]);
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
const addHotKey = useEffectEvent(
|
|
34
|
+
(keyCombo: string, handler: () => void, global = false) =>
|
|
35
|
+
(keyList.current = [
|
|
36
|
+
...keyList.current.filter(({ _key }) => _key !== keyCombo),
|
|
37
|
+
reduceHotKey({ keyCombo, handler, global }),
|
|
38
|
+
]),
|
|
39
|
+
);
|
|
40
|
+
const removeHotKey = useEffectEvent(
|
|
41
|
+
(key: string) => (keyList.current = [...keyList.current.filter(({ _key }) => _key !== key)]),
|
|
42
|
+
);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
const handler = useEffectEvent((items: KeyValue[], event: KeyboardEvent) => {
|
|
45
|
+
if (items.length === 0) return;
|
|
46
|
+
const { key: keyCode, code, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
47
|
+
if (
|
|
48
|
+
keyCode !== "Enter" &&
|
|
49
|
+
keyCode !== "Esc" &&
|
|
50
|
+
["INPUT", "TEXTAREA", "SELECT"].includes((event.target as HTMLElement).tagName)
|
|
51
|
+
)
|
|
52
|
+
return;
|
|
53
|
+
const find = items.find(
|
|
54
|
+
({ key, alt, ctrl, meta, shift }: KeyValue) =>
|
|
55
|
+
(key.toLowerCase() === keyCode.toLowerCase() ||
|
|
56
|
+
key.toLowerCase() === code.toLowerCase() ||
|
|
57
|
+
// work around for macos alt+key issue
|
|
58
|
+
`key${key.toLowerCase()}` === code.toLowerCase()) &&
|
|
59
|
+
alt === altKey &&
|
|
60
|
+
ctrl === ctrlKey &&
|
|
61
|
+
meta === metaKey &&
|
|
62
|
+
shift === shiftKey,
|
|
63
63
|
);
|
|
64
|
+
if (find?.handler) {
|
|
65
|
+
find.handler();
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
event.stopImmediatePropagation();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
keyCode !== "Esc" &&
|
|
71
|
-
["INPUT", "TEXTAREA", "SELECT"].includes(
|
|
72
|
-
(event.target as HTMLElement).tagName,
|
|
73
|
-
)
|
|
74
|
-
)
|
|
75
|
-
return;
|
|
76
|
-
const find = items.find(
|
|
77
|
-
({ key, alt, ctrl, meta, shift }: KeyValue) =>
|
|
78
|
-
(key.toLowerCase() === keyCode.toLowerCase() ||
|
|
79
|
-
key.toLowerCase() === code.toLowerCase() ||
|
|
80
|
-
// work around for macos alt+key issue
|
|
81
|
-
`key${key.toLowerCase()}` === code.toLowerCase()) &&
|
|
82
|
-
alt === altKey &&
|
|
83
|
-
ctrl === ctrlKey &&
|
|
84
|
-
meta === metaKey &&
|
|
85
|
-
shift === shiftKey,
|
|
71
|
+
const handleGlobal = useCallback(
|
|
72
|
+
(event: KeyboardEvent) => {
|
|
73
|
+
handler(
|
|
74
|
+
keyList.current.filter((i) => i.global),
|
|
75
|
+
event,
|
|
86
76
|
);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
);
|
|
100
|
-
},
|
|
101
|
-
[handler],
|
|
102
|
-
);
|
|
103
|
-
const handleHotKey = useCallback(
|
|
104
|
-
(event: KeyboardEvent) => {
|
|
105
|
-
handler(
|
|
106
|
-
keyList.current.filter((i) => !i.global),
|
|
107
|
-
event,
|
|
108
|
-
);
|
|
109
|
-
},
|
|
110
|
-
[handler],
|
|
111
|
-
);
|
|
77
|
+
},
|
|
78
|
+
[handler],
|
|
79
|
+
);
|
|
80
|
+
const handleHotKey = useCallback(
|
|
81
|
+
(event: KeyboardEvent) => {
|
|
82
|
+
handler(
|
|
83
|
+
keyList.current.filter((i) => !i.global),
|
|
84
|
+
event,
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
[handler],
|
|
88
|
+
);
|
|
112
89
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
90
|
+
useEffectDebugger(
|
|
91
|
+
() => {
|
|
92
|
+
const el: HTMLElement | null | undefined = refEl.current?.parentElement;
|
|
93
|
+
if (el) {
|
|
94
|
+
el.tabIndex = 0;
|
|
95
|
+
el.addEventListener("keydown", handleHotKey);
|
|
96
|
+
document.addEventListener("keydown", handleGlobal);
|
|
97
|
+
return () => {
|
|
98
|
+
el.removeEventListener("keydown", handleHotKey);
|
|
99
|
+
document.removeEventListener("keydown", handleGlobal);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
[handleGlobal, handleHotKey],
|
|
104
|
+
"HotKeyWrapper attach handlers",
|
|
105
|
+
);
|
|
129
106
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
107
|
+
return (
|
|
108
|
+
<HotKeysContext.Provider value={{ addHotKey, removeHotKey }}>
|
|
109
|
+
<div ref={refEl} style={{ display: "contents" }}>
|
|
110
|
+
{children}
|
|
111
|
+
</div>
|
|
112
|
+
</HotKeysContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
});
|
|
139
115
|
HotKeyWrapper.displayName = "HotKeyProvider";
|
package/src/hotkeys/commons.ts
CHANGED
|
@@ -67,6 +67,8 @@ export const reduceHotKey = ({ keyCombo, global, handler }: HotKeyProps) => {
|
|
|
67
67
|
else if (e.trim().toLowerCase() === "down") item.key = "arrowdown";
|
|
68
68
|
else if (e.trim().toLowerCase().startsWith("del")) item.key = "delete";
|
|
69
69
|
else if (e.trim().toLowerCase().startsWith("esc")) item.key = "escape";
|
|
70
|
+
else if (e.trim().toLowerCase().startsWith("plus")) item.key = "+";
|
|
71
|
+
else if (e.trim().toLowerCase().startsWith("minus")) item.key = "-";
|
|
70
72
|
else item.key = e.trim().toLowerCase();
|
|
71
73
|
}
|
|
72
74
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2026 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { createContext, useContext } from "react";
|
|
25
|
+
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const HotKeysContext = createContext<{
|
|
28
|
+
addHotKey: (key: string, handler: () => void, global?: boolean) => void;
|
|
29
|
+
removeHotKey: (key: string) => void;
|
|
30
|
+
}>({} as AnyObject);
|
|
31
|
+
|
|
32
|
+
export const useHotKeys = () => useContext(HotKeysContext);
|