@sentry/scraps 0.1.0 → 0.2.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.
Files changed (188) hide show
  1. package/README.md +13 -21
  2. package/dist/alert/alert.d.ts +25 -0
  3. package/dist/alert/alert.js +262 -0
  4. package/dist/alert/alertLink.d.ts +32 -0
  5. package/dist/alert/alertLink.js +94 -0
  6. package/dist/alert/index.d.ts +2 -0
  7. package/dist/alert/index.js +2 -0
  8. package/dist/backdrop/backdrop.d.ts +9 -0
  9. package/dist/backdrop/backdrop.js +28 -0
  10. package/dist/backdrop/index.d.ts +1 -0
  11. package/dist/backdrop/index.js +1 -0
  12. package/dist/badge/badge.d.ts +12 -0
  13. package/dist/badge/badge.js +80 -0
  14. package/dist/badge/featureBadge.d.ts +6 -0
  15. package/dist/badge/featureBadge.js +86 -0
  16. package/dist/badge/index.d.ts +3 -0
  17. package/dist/badge/index.js +3 -0
  18. package/dist/badge/tag.d.ts +15 -0
  19. package/dist/badge/tag.js +119 -0
  20. package/dist/boundaryContext.d.ts +2 -0
  21. package/dist/boundaryContext.js +5 -0
  22. package/dist/button/button.d.ts +3 -0
  23. package/dist/button/button.js +83 -0
  24. package/dist/button/buttonBar.d.ts +10 -0
  25. package/dist/button/buttonBar.js +135 -0
  26. package/dist/button/index.d.ts +5 -0
  27. package/dist/button/index.js +4 -0
  28. package/dist/button/linkButton.d.ts +3 -0
  29. package/dist/button/linkButton.js +110 -0
  30. package/dist/button/styles.d.ts +10 -0
  31. package/dist/button/styles.js +247 -0
  32. package/dist/button/types.d.ts +77 -0
  33. package/dist/button/types.js +0 -0
  34. package/dist/button/useButtonFunctionality.d.ts +5 -0
  35. package/dist/button/useButtonFunctionality.js +9 -0
  36. package/dist/checkbox/checkbox.d.ts +20 -0
  37. package/dist/checkbox/checkbox.js +193 -0
  38. package/dist/checkbox/index.d.ts +1 -0
  39. package/dist/checkbox/index.js +1 -0
  40. package/dist/chip/chip.d.ts +128 -0
  41. package/dist/chip/chip.js +364 -0
  42. package/dist/chip/index.d.ts +1 -0
  43. package/dist/chip/index.js +1 -0
  44. package/dist/code/inlineCode.d.ts +1 -0
  45. package/dist/datetime.d.ts +39 -0
  46. package/dist/datetime.js +20 -0
  47. package/dist/descriptionList/descriptionList.d.ts +69 -0
  48. package/dist/descriptionList/descriptionList.js +76 -0
  49. package/dist/descriptionList/index.d.ts +1 -0
  50. package/dist/descriptionList/index.js +1 -0
  51. package/dist/disclosure/disclosure.d.ts +37 -0
  52. package/dist/disclosure/disclosure.js +155 -0
  53. package/dist/disclosure/index.d.ts +1 -0
  54. package/dist/disclosure/index.js +1 -0
  55. package/dist/emptyState/emptyState.d.ts +10 -0
  56. package/dist/emptyState/emptyState.js +81 -0
  57. package/dist/emptyState/index.d.ts +1 -0
  58. package/dist/emptyState/index.js +1 -0
  59. package/dist/hotkey/hotkey.d.ts +22 -0
  60. package/dist/hotkey/hotkey.js +41 -0
  61. package/dist/hotkey/index.d.ts +4 -0
  62. package/dist/hotkey/index.js +3 -0
  63. package/dist/hotkey/kbd.d.ts +1 -0
  64. package/dist/hotkey/keyMappings.d.ts +23 -0
  65. package/dist/hotkey/keyMappings.js +223 -0
  66. package/dist/hotkey/useHotkeys.d.ts +47 -0
  67. package/dist/hotkey/useHotkeys.js +44 -0
  68. package/dist/image/image.d.ts +21 -0
  69. package/dist/image/image.js +20 -0
  70. package/dist/image/index.d.ts +1 -0
  71. package/dist/image/index.js +1 -0
  72. package/dist/info/index.d.ts +2 -0
  73. package/dist/info/index.js +2 -0
  74. package/dist/info/infoText.d.ts +15 -0
  75. package/dist/info/infoText.js +43 -0
  76. package/dist/info/infoTip.d.ts +10 -0
  77. package/dist/info/infoTip.js +54 -0
  78. package/dist/interactionStateLayer/index.d.ts +1 -0
  79. package/dist/interactionStateLayer/index.js +1 -0
  80. package/dist/interactionStateLayer/interactionStateLayer.d.ts +23 -0
  81. package/dist/interactionStateLayer/interactionStateLayer.js +67 -0
  82. package/dist/layout/flex.d.ts +1 -0
  83. package/dist/layout/grid.d.ts +1 -0
  84. package/dist/layout/index.d.ts +1 -1
  85. package/dist/layout/index.js +1 -1
  86. package/dist/layout/stack.d.ts +1 -0
  87. package/dist/layout/styles.d.ts +1 -1
  88. package/dist/layout/surface.d.ts +1 -0
  89. package/dist/link/index.d.ts +2 -0
  90. package/dist/link/index.js +2 -0
  91. package/dist/link/link.d.ts +43 -0
  92. package/dist/link/link.js +71 -0
  93. package/dist/link/linkBehaviorContext.d.ts +14 -0
  94. package/dist/link/linkBehaviorContext.js +31 -0
  95. package/dist/loader/indeterminateLoader.d.ts +1 -0
  96. package/dist/overlay.d.ts +59 -0
  97. package/dist/overlay.js +113 -0
  98. package/dist/overlayArrow.d.ts +9 -0
  99. package/dist/overlayArrow.js +55 -0
  100. package/dist/overlayPositioning.d.ts +61 -0
  101. package/dist/overlayPositioning.js +126 -0
  102. package/dist/panelProvider.d.ts +8 -0
  103. package/dist/panelProvider.js +20 -0
  104. package/dist/quote/quote.js +1 -1
  105. package/dist/radio/index.d.ts +1 -0
  106. package/dist/radio/index.js +1 -0
  107. package/dist/radio/radio.d.ts +9 -0
  108. package/dist/radio/radio.js +77 -0
  109. package/dist/renderToString.d.ts +2 -0
  110. package/dist/renderToString.js +25 -0
  111. package/dist/revealOnHover/index.d.ts +1 -0
  112. package/dist/revealOnHover/index.js +1 -0
  113. package/dist/revealOnHover/revealOnHover.d.ts +20 -0
  114. package/dist/revealOnHover/revealOnHover.js +62 -0
  115. package/dist/segmentedControl/index.d.ts +1 -0
  116. package/dist/segmentedControl/index.js +1 -0
  117. package/dist/segmentedControl/segmentedControl.d.ts +41 -0
  118. package/dist/segmentedControl/segmentedControl.js +217 -0
  119. package/dist/separator/separator.d.ts +4 -3
  120. package/dist/separator/separator.js +1 -1
  121. package/dist/sizeContext.d.ts +9 -0
  122. package/dist/sizeContext.js +13 -0
  123. package/dist/slider/index.d.ts +1 -0
  124. package/dist/slider/index.js +1 -0
  125. package/dist/slider/slider.d.ts +41 -0
  126. package/dist/slider/slider.js +386 -0
  127. package/dist/slot/index.d.ts +1 -0
  128. package/dist/slot/index.js +1 -0
  129. package/dist/slot/knownContexts.d.ts +1 -0
  130. package/dist/slot/knownContexts.js +7 -0
  131. package/dist/slot/slot.d.ts +26 -0
  132. package/dist/slot/slot.js +274 -0
  133. package/dist/statusIndicator/index.d.ts +1 -0
  134. package/dist/statusIndicator/index.js +1 -0
  135. package/dist/statusIndicator/statusIndicator.d.ts +24 -0
  136. package/dist/statusIndicator/statusIndicator.js +130 -0
  137. package/dist/switch/index.d.ts +1 -0
  138. package/dist/switch/index.js +1 -0
  139. package/dist/switch/switch.d.ts +6 -0
  140. package/dist/switch/switch.js +172 -0
  141. package/dist/text/heading.d.ts +1 -0
  142. package/dist/text/index.d.ts +1 -0
  143. package/dist/text/index.js +1 -0
  144. package/dist/text/prose.d.ts +8 -0
  145. package/dist/text/prose.js +45 -0
  146. package/dist/text/text.d.ts +1 -0
  147. package/dist/theme/dark.d.ts +129 -10
  148. package/dist/theme/dark.js +41 -13
  149. package/dist/theme/index.d.ts +3 -12
  150. package/dist/theme/index.js +2 -2
  151. package/dist/theme/light.d.ts +129 -10
  152. package/dist/theme/light.js +42 -14
  153. package/dist/theme/swatch.d.ts +27 -0
  154. package/dist/theme/swatch.js +37 -0
  155. package/dist/theme/theme.d.ts +648 -0
  156. package/dist/theme/theme.js +780 -0
  157. package/dist/theme/types.d.ts +1 -0
  158. package/dist/theme/useInvertedTheme.d.ts +1 -0
  159. package/dist/theme/useInvertedTheme.js +7 -0
  160. package/dist/tooltip/index.d.ts +2 -0
  161. package/dist/tooltip/index.js +2 -0
  162. package/dist/tooltip/tooltip.d.ts +166 -0
  163. package/dist/tooltip/tooltip.js +181 -0
  164. package/dist/tooltip/useDisabledTooltip.d.ts +22 -0
  165. package/dist/tooltip/useDisabledTooltip.js +24 -0
  166. package/dist/trackingContext.d.ts +34 -0
  167. package/dist/trackingContext.js +29 -0
  168. package/dist/translation/index.d.ts +4 -0
  169. package/dist/translation/index.js +4 -0
  170. package/dist/translation/translationContext.d.ts +6 -0
  171. package/dist/translation/translationContext.js +6 -0
  172. package/dist/translation/useTranslation.d.ts +1 -0
  173. package/dist/translation/useTranslation.js +6 -0
  174. package/dist/unreachable.d.ts +1 -0
  175. package/dist/unreachable.js +4 -0
  176. package/dist/useHoverOverlay.d.ts +113 -0
  177. package/dist/useHoverOverlay.js +370 -0
  178. package/dist/useIsInsideInteractiveElement.d.ts +6 -0
  179. package/dist/useIsInsideInteractiveElement.js +31 -0
  180. package/dist/useOverlay.d.ts +82 -0
  181. package/dist/useOverlay.js +216 -0
  182. package/dist/useScrollLock.d.ts +5 -0
  183. package/dist/useScrollLock.js +100 -0
  184. package/dist/useStableMergeRef.d.ts +9 -0
  185. package/dist/useStableMergeRef.js +18 -0
  186. package/package.json +193 -11
  187. package/dist/index.d.ts +0 -9
  188. package/dist/index.js +0 -9
@@ -0,0 +1,155 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { createContext, useContext, useRef } from "react";
3
+ import styled from "@emotion/styled";
4
+ import { useDisclosure } from "@react-aria/disclosure";
5
+ import { usePress } from "@react-aria/interactions";
6
+ import { useDisclosureState } from "@react-stately/disclosure";
7
+ import { IconChevron } from "@sentry/icons/chevron";
8
+ import { Button } from "../button/index.js";
9
+ import { Container, Flex, Stack } from "../layout/index.js";
10
+ const DisclosureContext = /*#__PURE__*/ createContext(null);
11
+ function useDisclosureContext() {
12
+ const context = useContext(DisclosureContext);
13
+ if (!context) throw new Error('useDisclosureContext must be used within a Disclosure component');
14
+ return context;
15
+ }
16
+ function DisclosureComponent({ children, size = 'md', variant = 'default', ref, onExpandedChange, ...props }) {
17
+ const panelRef = useRef(null);
18
+ const state = useDisclosureState({
19
+ ...props,
20
+ isExpanded: props.expanded,
21
+ onExpandedChange
22
+ });
23
+ const { buttonProps, panelProps } = useDisclosure({
24
+ ...props,
25
+ onExpandedChange,
26
+ isExpanded: props.expanded
27
+ }, state, panelRef);
28
+ return /*#__PURE__*/ jsx(DisclosureContext.Provider, {
29
+ value: {
30
+ buttonProps,
31
+ panelProps,
32
+ panelRef,
33
+ state,
34
+ context: {
35
+ size,
36
+ variant
37
+ }
38
+ },
39
+ children: /*#__PURE__*/ jsx(Stack, {
40
+ "data-disclosure": true,
41
+ align: "start",
42
+ ref: ref,
43
+ ...props,
44
+ children: children
45
+ })
46
+ });
47
+ }
48
+ function Title({ children, leadingItems, trailingItems, ...rest }) {
49
+ const { buttonProps, state, context } = useDisclosureContext();
50
+ const { isDisabled, ...restProps } = buttonProps;
51
+ const { pressProps } = usePress({
52
+ ...restProps
53
+ });
54
+ const chevron = /*#__PURE__*/ jsx(IconChevron, {
55
+ direction: state.isExpanded ? 'down' : 'right'
56
+ });
57
+ return /*#__PURE__*/ jsxs(TitleRow, {
58
+ justify: "start",
59
+ gap: context.size,
60
+ align: "center",
61
+ width: "100%",
62
+ paddingLeft: leadingItems ? 'xs' : void 0,
63
+ paddingRight: "xs",
64
+ radius: "md",
65
+ children: [
66
+ leadingItems ? /*#__PURE__*/ jsx(Flex, {
67
+ flexShrink: 0,
68
+ children: leadingItems
69
+ }) : null,
70
+ /*#__PURE__*/ jsx(StretchedButton, {
71
+ icon: leadingItems ? void 0 : chevron,
72
+ disabled: isDisabled,
73
+ size: context.size,
74
+ variant: "transparent",
75
+ ...pressProps,
76
+ ...rest,
77
+ children: leadingItems ? /*#__PURE__*/ jsxs(Flex, {
78
+ align: "center",
79
+ gap: "xs",
80
+ minWidth: 0,
81
+ children: [
82
+ children,
83
+ chevron
84
+ ]
85
+ }) : children
86
+ }),
87
+ trailingItems ? /*#__PURE__*/ jsx(Flex, {
88
+ flexShrink: 0,
89
+ children: trailingItems
90
+ }) : null
91
+ ]
92
+ });
93
+ }
94
+ const TitleRow = styled(Flex)`
95
+ &:hover {
96
+ background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.hover};
97
+ }
98
+
99
+ &:active {
100
+ background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.active};
101
+ }
102
+ `;
103
+ const StretchedButton = styled(Button)`
104
+ flex-grow: 1;
105
+ min-width: 0;
106
+ justify-content: flex-start;
107
+ padding-left: ${(p)=>p.theme.space.xs};
108
+
109
+ /* TitleRow owns the row's hover/active background; suppress the button's own
110
+ * states entirely so it never renders a second, nested background on top. */
111
+ &&:hover,
112
+ &&:active {
113
+ background-color: transparent;
114
+ }
115
+ `;
116
+ const OUTLINE_PADDING = {
117
+ xs: 'sm',
118
+ sm: 'md',
119
+ md: 'lg'
120
+ };
121
+ const OUTLINE_RADIUS = {
122
+ xs: 'md',
123
+ sm: 'lg',
124
+ md: 'xl'
125
+ };
126
+ function Content({ children, ...props }) {
127
+ const { panelProps, panelRef, context } = useDisclosureContext();
128
+ if ('outline' === context.variant) return /*#__PURE__*/ jsx(Container, {
129
+ ref: panelRef,
130
+ ...panelProps,
131
+ border: "primary",
132
+ radius: OUTLINE_RADIUS[context.size],
133
+ padding: OUTLINE_PADDING[context.size],
134
+ width: "100%",
135
+ ...props,
136
+ children: children
137
+ });
138
+ return /*#__PURE__*/ jsx(AlignedContainer, {
139
+ ref: panelRef,
140
+ ...panelProps,
141
+ padding: context.size,
142
+ size: context.size,
143
+ width: "100%",
144
+ ...props,
145
+ children: children
146
+ });
147
+ }
148
+ const AlignedContainer = styled(Container)`
149
+ padding-left: ${(p)=>'xs' === p.size ? '22px' : 'sm' === p.size ? '26px' : '26px'};
150
+ `;
151
+ const Disclosure = Object.assign(DisclosureComponent, {
152
+ Title: Title,
153
+ Content: Content
154
+ });
155
+ export { Disclosure };
@@ -0,0 +1 @@
1
+ export { Disclosure } from './disclosure.js';
@@ -0,0 +1 @@
1
+ export { Disclosure } from "./disclosure.js";
@@ -0,0 +1,10 @@
1
+ import type * as React from 'react';
2
+ import { type FlexProps } from '../layout/index.js';
3
+ interface EmptyStateProps extends Omit<FlexProps, 'title' | 'children' | 'containerType'> {
4
+ title: React.ReactNode;
5
+ action?: React.ReactNode;
6
+ description?: React.ReactNode;
7
+ illustration?: React.ReactNode;
8
+ }
9
+ export declare function EmptyState({ title, description, illustration, action, ...props }: EmptyStateProps): import("@emotion/react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,81 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Flex, Stack } from "../layout/index.js";
3
+ import { Heading } from "../text/heading.js";
4
+ import { Text } from "../text/text.js";
5
+ function EmptyState({ title, description, illustration, action, ...props }) {
6
+ const switchOn = 'md';
7
+ const textAlign = illustration ? {
8
+ zero: 'center',
9
+ [switchOn]: 'left'
10
+ } : 'center';
11
+ const actionJustify = illustration ? {
12
+ zero: 'center',
13
+ [switchOn]: 'start'
14
+ } : 'center';
15
+ return /*#__PURE__*/ jsx(Flex, {
16
+ containerType: "inline-size",
17
+ width: "100%",
18
+ flexGrow: 1,
19
+ minWidth: 0,
20
+ children: /*#__PURE__*/ jsxs(Flex, {
21
+ direction: {
22
+ zero: 'column',
23
+ [switchOn]: 'row'
24
+ },
25
+ flexGrow: 1,
26
+ align: "center",
27
+ gap: {
28
+ zero: 'xl',
29
+ [switchOn]: '2xl'
30
+ },
31
+ justify: {
32
+ zero: 'start',
33
+ [switchOn]: 'center'
34
+ },
35
+ "data-test-id": "empty-state",
36
+ ...props,
37
+ children: [
38
+ illustration && /*#__PURE__*/ jsx(Flex, {
39
+ justify: "center",
40
+ align: "center",
41
+ overflow: "hidden",
42
+ flexShrink: 0,
43
+ children: illustration
44
+ }),
45
+ /*#__PURE__*/ jsxs(Stack, {
46
+ gap: "xl",
47
+ children: [
48
+ /*#__PURE__*/ jsxs(Stack, {
49
+ gap: illustration ? 'md' : 'sm',
50
+ width: "100%",
51
+ maxWidth: "48ch",
52
+ children: [
53
+ /*#__PURE__*/ jsx(Heading, {
54
+ as: "h3",
55
+ size: "lg",
56
+ align: textAlign,
57
+ children: title
58
+ }),
59
+ description && /*#__PURE__*/ jsx(Text, {
60
+ as: "p",
61
+ size: "md",
62
+ variant: "muted",
63
+ align: textAlign,
64
+ textWrap: "balance",
65
+ children: description
66
+ })
67
+ ]
68
+ }),
69
+ action && /*#__PURE__*/ jsx(Flex, {
70
+ gap: "md",
71
+ justify: actionJustify,
72
+ wrap: "wrap",
73
+ children: action
74
+ })
75
+ ]
76
+ })
77
+ ]
78
+ })
79
+ });
80
+ }
81
+ export { EmptyState };
@@ -0,0 +1 @@
1
+ export { EmptyState } from './emptyState.js';
@@ -0,0 +1 @@
1
+ export { EmptyState } from "./emptyState.js";
@@ -0,0 +1,22 @@
1
+ interface HotkeyProps {
2
+ /**
3
+ * Key combination string(s) in the same format as `useHotkeys` match strings.
4
+ * Keys are separated by `+`. For example: `"command+k"`, `"shift+enter"`.
5
+ *
6
+ * Platform modifiers are mapped automatically:
7
+ * - `command` renders as `⌘` on Mac, `CTRL` on other platforms
8
+ * - `ctrl` renders as `⌃` on Mac, `CTRL` on other platforms
9
+ * - `alt`/`option` renders as `⌥` on Mac, `ALT` on other platforms
10
+ *
11
+ * Pass an array only when the actual keys differ across platforms
12
+ * (not just modifier names). The first compatible combo is used:
13
+ *
14
+ * ```tsx
15
+ * <Hotkey value={['command+backspace', 'delete']} />
16
+ * ```
17
+ */
18
+ value: string | string[];
19
+ variant?: 'embossed' | 'debossed';
20
+ }
21
+ export declare function Hotkey({ value, variant }: HotkeyProps): import("@emotion/react/jsx-runtime").JSX.Element | null;
22
+ export {};
@@ -0,0 +1,41 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import styled from "@emotion/styled";
3
+ import { Kbd } from "./kbd.js";
4
+ import { resolveKeyGlyph } from "./keyMappings.js";
5
+ function Hotkey({ value, variant }) {
6
+ const keySets = (Array.isArray(value) ? value : [
7
+ value
8
+ ]).map((v)=>v.trim().split('+'));
9
+ const resolved = keySets.map((keys)=>keys.map((key)=>resolveKeyGlyph(key)));
10
+ const finalKeys = resolved[0];
11
+ if (!finalKeys || 0 === finalKeys.length) return null;
12
+ return /*#__PURE__*/ jsx(WrapperKbd, {
13
+ variant: variant,
14
+ children: finalKeys.map((glyph, i)=>'icon' in glyph ? /*#__PURE__*/ jsx(StyledKbd, {
15
+ "aria-label": glyph.label,
16
+ children: glyph.icon
17
+ }, i) : /*#__PURE__*/ jsx(StyledKbd, {
18
+ children: glyph.label
19
+ }, i))
20
+ });
21
+ }
22
+ const WrapperKbd = styled(Kbd)`
23
+ padding: 0 ${(p)=>p.theme.space.xs};
24
+ gap: ${(p)=>p.theme.space['2xs']};
25
+ `;
26
+ const StyledKbd = styled('kbd')`
27
+ scale: 0.9;
28
+ color: inherit;
29
+ display: inline-flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+ margin: 0;
33
+ padding: 0;
34
+ font-family: inherit;
35
+ font-size: inherit;
36
+ background: none;
37
+ border: 0;
38
+ border-radius: 0;
39
+ box-shadow: none;
40
+ `;
41
+ export { Hotkey };
@@ -0,0 +1,4 @@
1
+ /** @public */
2
+ export { Kbd } from './kbd.js';
3
+ export { Hotkey } from './hotkey.js';
4
+ export { matchesHotkey, useHotkeys } from './useHotkeys.js';
@@ -0,0 +1,3 @@
1
+ export { Kbd } from "./kbd.js";
2
+ export { Hotkey } from "./hotkey.js";
3
+ export { matchesHotkey, useHotkeys } from "./useHotkeys.js";
@@ -1,3 +1,4 @@
1
+ import type * as React from 'react';
1
2
  import type { Theme } from '../theme/index.js';
2
3
  export declare const kbdStyles: (theme: Theme, variant?: KbdProps["variant"]) => import("@emotion/react").SerializedStyles;
3
4
  interface KbdProps extends React.HTMLAttributes<HTMLElement> {
@@ -0,0 +1,23 @@
1
+ import type * as React from 'react';
2
+ export declare function canonicalize(keyName: string): string;
3
+ export declare const MODIFIER_KEYS: readonly ["command", "shift", "control", "alt"];
4
+ /**
5
+ * Tests whether a single key name from a hotkey match string is currently
6
+ * pressed in the given keyboard event. Layout-aware: matches against
7
+ * `event.key` (so an AZERTY user pressing the K-labeled key fires `'k'`
8
+ * shortcuts) with `event.code` as a physical-position fallback (so
9
+ * `shift+1` works even though `event.key === '!'` on US QWERTY).
10
+ */
11
+ export declare function matchesKey(name: string, event: KeyboardEvent): boolean;
12
+ type KeyGlyph = {
13
+ icon: React.ReactNode;
14
+ label: string;
15
+ } | {
16
+ label: string;
17
+ };
18
+ /**
19
+ * Resolve a key name to its display glyph for the given platform.
20
+ * Non-special keys fall through to title-cased text (e.g. `'k'` → `'K'`).
21
+ */
22
+ export declare function resolveKeyGlyph(keyName: string): KeyGlyph;
23
+ export {};
@@ -0,0 +1,223 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { isMac } from "@react-aria/utils";
3
+ import { IconArrow } from "@sentry/icons/arrow";
4
+ import { IconCommand } from "@sentry/icons/command";
5
+ import { IconControl } from "@sentry/icons/control";
6
+ import { IconOption } from "@sentry/icons/option";
7
+ import { IconReturn } from "@sentry/icons/return";
8
+ import { IconShift } from "@sentry/icons/shift";
9
+ import * as __rspack_external__sentry_react_f0cda475 from "@sentry/react";
10
+ const aliases = {
11
+ cmd: 'command',
12
+ meta: 'command',
13
+ '\u2318': 'command',
14
+ ctrl: 'control',
15
+ '\u2303': 'control',
16
+ option: 'alt',
17
+ '\u2325': 'alt',
18
+ '\u21E7': 'shift',
19
+ return: 'enter',
20
+ esc: 'escape',
21
+ del: 'delete',
22
+ ins: 'insert',
23
+ '\u21EA': 'capslock'
24
+ };
25
+ function canonicalize(keyName) {
26
+ const lower = keyName.toLowerCase();
27
+ if ('mod' === lower) return isMac() ? 'command' : 'control';
28
+ return aliases[lower] ?? lower;
29
+ }
30
+ const namedKeyMap = {
31
+ backspace: 'Backspace',
32
+ tab: 'Tab',
33
+ clear: 'Clear',
34
+ enter: 'Enter',
35
+ escape: 'Escape',
36
+ space: ' ',
37
+ left: 'ArrowLeft',
38
+ up: 'ArrowUp',
39
+ right: 'ArrowRight',
40
+ down: 'ArrowDown',
41
+ delete: 'Delete',
42
+ insert: 'Insert',
43
+ home: 'Home',
44
+ end: 'End',
45
+ pageup: 'PageUp',
46
+ pagedown: 'PageDown',
47
+ capslock: 'CapsLock'
48
+ };
49
+ const punctuationCodeMap = {
50
+ ',': 'Comma',
51
+ '.': 'Period',
52
+ '/': 'Slash',
53
+ '`': 'Backquote',
54
+ '-': 'Minus',
55
+ '=': 'Equal',
56
+ ';': 'Semicolon',
57
+ "'": 'Quote',
58
+ '[': 'BracketLeft',
59
+ ']': 'BracketRight',
60
+ '\\': 'Backslash'
61
+ };
62
+ const modifierPredicates = {
63
+ command: (e)=>e.metaKey,
64
+ shift: (e)=>e.shiftKey,
65
+ control: (e)=>e.ctrlKey,
66
+ alt: (e)=>e.altKey
67
+ };
68
+ const MODIFIER_KEYS = [
69
+ 'command',
70
+ 'shift',
71
+ 'control',
72
+ 'alt'
73
+ ];
74
+ function codeForChar(ch) {
75
+ if (ch >= 'a' && ch <= 'z') return `Key${ch.toUpperCase()}`;
76
+ if (ch >= '0' && ch <= '9') return `Digit${ch}`;
77
+ return punctuationCodeMap[ch];
78
+ }
79
+ function matchesKey(name, event) {
80
+ const key = canonicalize(name);
81
+ const modifier = modifierPredicates[key];
82
+ if (modifier) return modifier(event);
83
+ const namedKey = namedKeyMap[key];
84
+ if (namedKey) return event.key === namedKey;
85
+ if (1 === key.length) {
86
+ if (event.key?.toLowerCase() === key) return true;
87
+ const code = codeForChar(key);
88
+ if (code && event.code === code) {
89
+ const eventKey = event.key;
90
+ if (eventKey?.length !== 1 || eventKey.charCodeAt(0) > 0x7f) return true;
91
+ if (event.shiftKey) return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
96
+ const sharedProps = {
97
+ size: 'xs'
98
+ };
99
+ const macGlyphs = {
100
+ command: {
101
+ icon: /*#__PURE__*/ jsx(IconCommand, {
102
+ ...sharedProps
103
+ }),
104
+ label: '\u2318'
105
+ },
106
+ control: {
107
+ icon: /*#__PURE__*/ jsx(IconControl, {
108
+ ...sharedProps
109
+ }),
110
+ label: '\u2303'
111
+ },
112
+ alt: {
113
+ icon: /*#__PURE__*/ jsx(IconOption, {
114
+ ...sharedProps
115
+ }),
116
+ label: '\u2325'
117
+ }
118
+ };
119
+ const otherGlyphs = {
120
+ command: {
121
+ label: 'Ctrl'
122
+ },
123
+ control: {
124
+ label: 'Ctrl'
125
+ },
126
+ alt: {
127
+ label: 'Alt'
128
+ }
129
+ };
130
+ const universalGlyphs = {
131
+ shift: {
132
+ icon: /*#__PURE__*/ jsx(IconShift, {
133
+ ...sharedProps
134
+ }),
135
+ label: '\u21E7'
136
+ },
137
+ enter: {
138
+ icon: /*#__PURE__*/ jsx(IconReturn, {
139
+ ...sharedProps
140
+ }),
141
+ label: '\u21B5'
142
+ },
143
+ left: {
144
+ icon: /*#__PURE__*/ jsx(IconArrow, {
145
+ ...sharedProps,
146
+ direction: "left"
147
+ }),
148
+ label: '\u2190'
149
+ },
150
+ right: {
151
+ icon: /*#__PURE__*/ jsx(IconArrow, {
152
+ ...sharedProps,
153
+ direction: "right"
154
+ }),
155
+ label: '\u2192'
156
+ },
157
+ up: {
158
+ icon: /*#__PURE__*/ jsx(IconArrow, {
159
+ ...sharedProps,
160
+ direction: "up"
161
+ }),
162
+ label: '\u2191'
163
+ },
164
+ down: {
165
+ icon: /*#__PURE__*/ jsx(IconArrow, {
166
+ ...sharedProps,
167
+ direction: "down"
168
+ }),
169
+ label: '\u2193'
170
+ },
171
+ backspace: {
172
+ label: '\u232B'
173
+ },
174
+ delete: {
175
+ label: 'Del'
176
+ },
177
+ tab: {
178
+ label: 'Tab'
179
+ },
180
+ escape: {
181
+ label: 'Esc'
182
+ },
183
+ space: {
184
+ label: 'Space'
185
+ },
186
+ home: {
187
+ label: 'Home'
188
+ },
189
+ end: {
190
+ label: 'End'
191
+ },
192
+ pageup: {
193
+ label: 'PageUp'
194
+ },
195
+ pagedown: {
196
+ label: 'PageDown'
197
+ },
198
+ insert: {
199
+ label: 'Insert'
200
+ },
201
+ clear: {
202
+ label: 'Clear'
203
+ },
204
+ capslock: {
205
+ label: 'CapsLock'
206
+ }
207
+ };
208
+ function resolveKeyGlyph(keyName) {
209
+ const key = canonicalize(keyName);
210
+ const platformGlyphs = isMac() ? macGlyphs : otherGlyphs;
211
+ const glyph = platformGlyphs[key] ?? universalGlyphs[key];
212
+ if (glyph) return glyph;
213
+ if (key.length > 1) {
214
+ if ('production' !== process.env.NODE_ENV) throw new Error(`Missing key glyph mapping for "${keyName}"`);
215
+ __rspack_external__sentry_react_f0cda475.logger.warn('Missing key glyph mapping', {
216
+ keyName
217
+ });
218
+ }
219
+ return {
220
+ label: keyName.replace(/\w\S*/g, (word)=>word.charAt(0).toUpperCase() + word.substring(1))
221
+ };
222
+ }
223
+ export { MODIFIER_KEYS, canonicalize, matchesKey, resolveKeyGlyph };
@@ -0,0 +1,47 @@
1
+ type Hotkey = {
2
+ /**
3
+ * The callback triggered when the matching key is pressed
4
+ */
5
+ callback: (e: KeyboardEvent) => void;
6
+ /**
7
+ * Defines the matching shortcuts.
8
+ *
9
+ * Multiple shortcuts may be passed as a list.
10
+ *
11
+ * The format for shorcuts is `<modifiers>+<key>` For example `shift+t` or
12
+ * `command+shift+t`.
13
+ */
14
+ match: string[] | string;
15
+ /**
16
+ * When `false`, the hotkey is skipped: the callback never fires and
17
+ * `preventDefault` is never called. Useful for gating a hotkey on state
18
+ * (e.g. only intercept `Escape` while a panel is open) without rebuilding
19
+ * the hotkey array. Defaults to `true`.
20
+ */
21
+ enabled?: boolean;
22
+ /**
23
+ * Allow shortcuts to be triggered while a text input is foccused
24
+ */
25
+ includeInputs?: boolean;
26
+ /**
27
+ * Do not call preventDefault on the keydown event
28
+ */
29
+ skipPreventDefault?: boolean;
30
+ };
31
+ /**
32
+ * Returns whether an event should trigger one of the supplied hotkey matches.
33
+ * Uses the same platform-aware modifier and keyboard-layout behavior as
34
+ * useHotkeys, and never matches while an IME is composing text.
35
+ */
36
+ export declare function matchesHotkey(match: string[] | string, event: KeyboardEvent): boolean;
37
+ /**
38
+ * Pass in the hotkey combinations under match and the corresponding callback
39
+ * function to be called. Separate key names with +. For example,
40
+ * 'command+alt+shift+x'
41
+ *
42
+ * Alternate matchings as an array: ['command+alt+backspace', 'ctrl+alt+delete']
43
+ *
44
+ * Note: you can only use one non-modifier (keys other than shift, ctrl, alt, command) key at a time.
45
+ */
46
+ export declare function useHotkeys(hotkeys: Hotkey[]): void;
47
+ export {};
@@ -0,0 +1,44 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { MODIFIER_KEYS, canonicalize, matchesKey } from "./keyMappings.js";
3
+ function shouldIgnoreHotkeyEvent(event) {
4
+ return event.isComposing;
5
+ }
6
+ function matchesHotkey(match, event) {
7
+ if (shouldIgnoreHotkeyEvent(event)) return false;
8
+ return (Array.isArray(match) ? match : [
9
+ match
10
+ ]).some((keyset)=>{
11
+ const keys = keyset.toLowerCase().split('+').map((key)=>canonicalize(key));
12
+ const unusedModifiers = MODIFIER_KEYS.filter((modifier)=>!keys.includes(modifier));
13
+ return keys.every((key)=>matchesKey(key, event)) && unusedModifiers.every((modifier)=>!matchesKey(modifier, event));
14
+ });
15
+ }
16
+ function useHotkeys(hotkeys) {
17
+ const hotkeysRef = useRef(hotkeys);
18
+ useEffect(()=>{
19
+ hotkeysRef.current = hotkeys;
20
+ });
21
+ useEffect(()=>{
22
+ const onKeyDown = (evt)=>{
23
+ if (shouldIgnoreHotkeyEvent(evt)) return;
24
+ for (const hotkey of hotkeysRef.current){
25
+ if (false === hotkey.enabled) continue;
26
+ const preventDefault = !hotkey.skipPreventDefault;
27
+ const inputHasFocus = !hotkey.includeInputs && evt.target instanceof HTMLElement ? evt.target.isContentEditable || [
28
+ 'textarea',
29
+ 'input'
30
+ ].includes(evt.target.tagName.toLowerCase()) : false;
31
+ if (matchesHotkey(hotkey.match, evt) && !inputHasFocus) {
32
+ if (preventDefault) evt.preventDefault();
33
+ hotkey.callback(evt);
34
+ return;
35
+ }
36
+ }
37
+ };
38
+ document.addEventListener('keydown', onKeyDown);
39
+ return ()=>{
40
+ document.removeEventListener('keydown', onKeyDown);
41
+ };
42
+ }, []);
43
+ }
44
+ export { matchesHotkey, useHotkeys };