@sentry/scraps 0.5.0 → 0.6.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 (103) hide show
  1. package/README.md +68 -3
  2. package/dist/badge/tag.js +4 -2
  3. package/dist/button/button.js +1 -0
  4. package/dist/button/linkButton.js +1 -0
  5. package/dist/button/styles.js +157 -152
  6. package/dist/codeBlock/codeBlock.js +1 -0
  7. package/dist/compactSelect/control.js +3 -2
  8. package/dist/compactSelect/utils.js +2 -6
  9. package/dist/dateTime/config.d.ts +23 -0
  10. package/dist/dateTime/config.js +50 -0
  11. package/dist/dateTime/context.d.ts +18 -0
  12. package/dist/dateTime/context.js +46 -0
  13. package/dist/dateTime/dateTime.d.ts +6 -0
  14. package/dist/dateTime/dateTime.js +30 -0
  15. package/dist/dateTime/format.d.ts +24 -0
  16. package/dist/dateTime/format.js +45 -0
  17. package/dist/dateTime/index.d.ts +6 -0
  18. package/dist/dateTime/index.js +6 -0
  19. package/dist/dateTime/intlFormatter.d.ts +9 -0
  20. package/dist/dateTime/intlFormatter.js +16 -0
  21. package/dist/dateTime/parseDate.d.ts +3 -0
  22. package/dist/dateTime/parseDate.js +12 -0
  23. package/dist/dropdownMenu/context.d.ts +28 -13
  24. package/dist/dropdownMenu/dropdownMenu.d.ts +2 -2
  25. package/dist/dropdownMenu/dropdownMenu.js +9 -3
  26. package/dist/dropdownMenu/item.d.ts +6 -2
  27. package/dist/dropdownMenu/item.js +31 -71
  28. package/dist/dropdownMenu/list.d.ts +31 -5
  29. package/dist/dropdownMenu/list.js +143 -124
  30. package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +5 -241
  31. package/dist/dropdownMenu/useDropdownMenuKeyboard.js +5 -29
  32. package/dist/dropdownMenu/useDropdownRootMenuState.d.ts +13 -0
  33. package/dist/dropdownMenu/useDropdownRootMenuState.js +30 -0
  34. package/dist/dropdownMenu/useDropdownSubmenuState.d.ts +19 -0
  35. package/dist/dropdownMenu/useDropdownSubmenuState.js +25 -0
  36. package/dist/dropdownMenu/utils.js +5 -7
  37. package/dist/duration/formatElapsedDuration.d.ts +4 -0
  38. package/dist/duration/formatElapsedDuration.js +10 -0
  39. package/dist/duration/getDuration.d.ts +68 -0
  40. package/dist/duration/getDuration.js +80 -0
  41. package/dist/duration/index.d.ts +2 -0
  42. package/dist/duration/index.js +2 -0
  43. package/dist/{compactSelect/fzf.d.ts → fzf.d.ts} +1 -0
  44. package/dist/{compactSelect/fzf.js → fzf.js} +5 -1
  45. package/dist/layout/container.d.ts +8 -2
  46. package/dist/layout/container.js +2 -2
  47. package/dist/layout/styles.d.ts +2 -1
  48. package/dist/layout/styles.js +11 -5
  49. package/dist/legacyDatetime.d.ts +21 -0
  50. package/dist/legacyDatetime.js +13 -0
  51. package/dist/link/index.d.ts +1 -1
  52. package/dist/link/index.js +1 -1
  53. package/dist/link/linkBehaviorContext.d.ts +9 -0
  54. package/dist/link/linkBehaviorContext.js +37 -7
  55. package/dist/menu/menu.d.ts +1 -3
  56. package/dist/menu/menu.js +4 -5
  57. package/dist/relativeTime/getRelativeDate.d.ts +14 -0
  58. package/dist/relativeTime/getRelativeDate.js +107 -0
  59. package/dist/relativeTime/index.d.ts +3 -0
  60. package/dist/relativeTime/index.js +3 -0
  61. package/dist/relativeTime/relativeTime.d.ts +55 -0
  62. package/dist/relativeTime/relativeTime.js +102 -0
  63. package/dist/relativeTime/useRelativeTimeFormatter.d.ts +2 -0
  64. package/dist/relativeTime/useRelativeTimeFormatter.js +10 -0
  65. package/dist/tabs/context.d.ts +9 -0
  66. package/dist/tabs/context.js +9 -0
  67. package/dist/tabs/index.d.ts +2 -4
  68. package/dist/tabs/index.js +1 -3
  69. package/dist/tabs/item.d.ts +16 -5
  70. package/dist/tabs/tab.js +6 -3
  71. package/dist/tabs/tabList.d.ts +5 -5
  72. package/dist/tabs/tabList.js +8 -6
  73. package/dist/tabs/tabPanels.d.ts +2 -3
  74. package/dist/tabs/tabPanels.js +1 -1
  75. package/dist/tabs/tabs.d.ts +46 -31
  76. package/dist/tabs/tabs.js +38 -35
  77. package/dist/text/prose.d.ts +2 -2
  78. package/dist/theme/theme.d.ts +34 -34
  79. package/dist/theme/theme.js +9 -0
  80. package/dist/theme/types.d.ts +20 -2
  81. package/dist/translation/index.d.ts +1 -0
  82. package/dist/translation/index.js +1 -0
  83. package/dist/translation/translate.d.ts +9 -0
  84. package/dist/translation/translate.js +5 -0
  85. package/dist/translation/translationContext.d.ts +2 -1
  86. package/dist/translation/translationContext.js +2 -1
  87. package/fonts/OFL.txt +94 -0
  88. package/fonts/roboto-mono-variable-cyrillic-ext.woff2 +0 -0
  89. package/fonts/roboto-mono-variable-cyrillic.woff2 +0 -0
  90. package/fonts/roboto-mono-variable-greek.woff2 +0 -0
  91. package/fonts/roboto-mono-variable-latin-ext.woff2 +0 -0
  92. package/fonts/roboto-mono-variable-vietnamese.woff2 +0 -0
  93. package/fonts/roboto-mono-variable.woff2 +0 -0
  94. package/fonts/rubik-variable-cyrillic-ext.woff2 +0 -0
  95. package/fonts/rubik-variable-cyrillic.woff2 +0 -0
  96. package/fonts/rubik-variable-latin-ext.woff2 +0 -0
  97. package/fonts/rubik-variable.woff2 +0 -0
  98. package/fonts.css +211 -0
  99. package/package.json +30 -12
  100. package/dist/datetime.d.ts +0 -39
  101. package/dist/datetime.js +0 -20
  102. package/dist/dropdownMenu/useSafetyTriangle.d.ts +0 -12
  103. package/dist/dropdownMenu/useSafetyTriangle.js +0 -119
@@ -0,0 +1,18 @@
1
+ import type * as React from 'react';
2
+ import { type DateTimePreferences } from './config.js';
3
+ import { type DateTimeInput, type DateTimeOptions } from './format.js';
4
+ /** Override only the specified preferences, inheriting the rest from the parent. */
5
+ export declare function DateTimeProvider({ value, children, }: {
6
+ children: React.ReactNode;
7
+ value: Partial<DateTimePreferences>;
8
+ }): import("@emotion/react/jsx-runtime").JSX.Element;
9
+ export declare function useFormattingSnapshot(): {
10
+ timezone: string;
11
+ clock: "12" | "24";
12
+ locale: string;
13
+ messages: import("../translation/index.js").Translation;
14
+ getTimezoneAbbreviation?: (epochMilliseconds: number, timezone: string, locale: string) => string | undefined;
15
+ };
16
+ export declare function useTimezone(): string;
17
+ export declare function useClock(): DateTimePreferences['clock'];
18
+ export declare function useDateTimeFormatter(): (date: DateTimeInput, options?: DateTimeOptions) => string;
@@ -0,0 +1,46 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { createContext, useCallback, useContext, useMemo } from "react";
3
+ import { useStore } from "zustand";
4
+ import { formattingStore } from "./config.js";
5
+ import { formatDateTimeWithSnapshot } from "./format.js";
6
+ const DateTimeContext = /*#__PURE__*/ createContext({});
7
+ function DateTimeProvider({ value, children }) {
8
+ const parent = useContext(DateTimeContext);
9
+ const preferences = useMemo(()=>({
10
+ timezone: value.timezone ?? parent.timezone,
11
+ clock: value.clock ?? parent.clock
12
+ }), [
13
+ parent,
14
+ value.timezone,
15
+ value.clock
16
+ ]);
17
+ return /*#__PURE__*/ jsx(DateTimeContext, {
18
+ value: preferences,
19
+ children: children
20
+ });
21
+ }
22
+ function useFormattingSnapshot() {
23
+ const overrides = useContext(DateTimeContext);
24
+ const snapshot = useStore(formattingStore);
25
+ return useMemo(()=>({
26
+ ...snapshot,
27
+ timezone: overrides.timezone ?? snapshot.timezone,
28
+ clock: overrides.clock ?? snapshot.clock
29
+ }), [
30
+ snapshot,
31
+ overrides
32
+ ]);
33
+ }
34
+ function useTimezone() {
35
+ return useFormattingSnapshot().timezone;
36
+ }
37
+ function useClock() {
38
+ return useFormattingSnapshot().clock;
39
+ }
40
+ function useDateTimeFormatter() {
41
+ const snapshot = useFormattingSnapshot();
42
+ return useCallback((date, options = {})=>formatDateTimeWithSnapshot(date, options, snapshot), [
43
+ snapshot
44
+ ]);
45
+ }
46
+ export { DateTimeProvider, useClock, useDateTimeFormatter, useFormattingSnapshot, useTimezone };
@@ -0,0 +1,6 @@
1
+ import type * as React from 'react';
2
+ import type { DateTimeInput, DateTimeOptions } from './format.js';
3
+ export type DateTimeProps = Omit<React.HTMLAttributes<HTMLTimeElement>, 'children'> & DateTimeOptions & {
4
+ date: DateTimeInput;
5
+ };
6
+ export declare function DateTime({ date, mode, year, precision, timezone, clock, showTimezone, ...props }: DateTimeProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { useDateTimeFormatter } from "./context.js";
3
+ function DateTime({ date, mode, year, precision, timezone, clock, showTimezone, ...props }) {
4
+ const format = useDateTimeFormatter();
5
+ const options = 'date' === mode ? {
6
+ mode,
7
+ year,
8
+ timezone,
9
+ clock,
10
+ showTimezone
11
+ } : 'time' === mode ? {
12
+ mode,
13
+ precision,
14
+ timezone,
15
+ clock,
16
+ showTimezone
17
+ } : {
18
+ mode,
19
+ year,
20
+ precision,
21
+ timezone,
22
+ clock,
23
+ showTimezone
24
+ };
25
+ return /*#__PURE__*/ jsx("time", {
26
+ ...props,
27
+ children: format(date, options)
28
+ });
29
+ }
30
+ export { DateTime };
@@ -0,0 +1,24 @@
1
+ import { type DateTimePreferences, type FormattingSnapshot } from './config.js';
2
+ /** Numbers are epoch milliseconds; strings must be ISO timestamps with an offset. */
3
+ export type DateTimeInput = Date | number | string;
4
+ export type TimePrecision = 'minute' | 'second' | 'millisecond';
5
+ export type YearDisplay = 'auto' | 'always' | 'never';
6
+ export type DateTimeOptions = Partial<DateTimePreferences> & {
7
+ /** Defaults to true only when the caller explicitly selects timezone "UTC". */
8
+ showTimezone?: boolean;
9
+ } & ({
10
+ mode?: 'dateTime';
11
+ precision?: TimePrecision;
12
+ year?: YearDisplay;
13
+ } | {
14
+ mode: 'date';
15
+ precision?: never;
16
+ year?: YearDisplay;
17
+ } | {
18
+ mode: 'time';
19
+ precision?: TimePrecision;
20
+ year?: never;
21
+ });
22
+ export declare function formatDateTime(date: DateTimeInput, options?: DateTimeOptions): string;
23
+ export declare function formatTimezone(epochMilliseconds: number, timezone: string, snapshot?: Readonly<FormattingSnapshot>): string;
24
+ export declare function formatDateTimeWithSnapshot(date: DateTimeInput, options: DateTimeOptions, snapshot: Readonly<FormattingSnapshot>): string;
@@ -0,0 +1,45 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { getSnapshot } from "./config.js";
3
+ import { getIntlFormatter } from "./intlFormatter.js";
4
+ import { parseDate } from "./parseDate.js";
5
+ function formatDateTime(date, options = {}) {
6
+ return formatDateTimeWithSnapshot(date, options, getSnapshot());
7
+ }
8
+ function formatTimezone(epochMilliseconds, timezone, snapshot = getSnapshot()) {
9
+ if ('UTC' === timezone) return 'UTC';
10
+ return snapshot.getTimezoneAbbreviation?.(epochMilliseconds, timezone, snapshot.locale) ?? getIntlFormatter(Intl.DateTimeFormat, snapshot.locale, {
11
+ timeZone: timezone,
12
+ timeZoneName: 'short'
13
+ }).formatToParts(epochMilliseconds).find((part)=>'timeZoneName' === part.type)?.value ?? '';
14
+ }
15
+ function formatDateTimeWithSnapshot(date, options, snapshot) {
16
+ const { mode = 'dateTime', clock = snapshot.clock, year = 'auto', precision = 'minute' } = options;
17
+ const timezone = options.timezone ?? snapshot.timezone;
18
+ const showTimezone = options.showTimezone ?? 'UTC' === options.timezone;
19
+ const value = parseDate(date, timezone);
20
+ if (!value) return 'Invalid date';
21
+ const currentYear = Temporal.Instant.fromEpochMilliseconds(Date.now()).toZonedDateTimeISO(timezone).year;
22
+ const showYear = 'always' === year || 'auto' === year && value.year !== currentYear;
23
+ const dateParts = getIntlFormatter(Intl.DateTimeFormat, snapshot.locale, {
24
+ calendar: 'gregory',
25
+ timeZone: timezone,
26
+ year: showYear ? 'numeric' : void 0,
27
+ month: 'short',
28
+ day: 'numeric'
29
+ }).formatToParts(value.epochMilliseconds);
30
+ const dateText = dateParts.map((part)=>'year' === part.type && value.year < 1000 ? getIntlFormatter(Intl.NumberFormat, snapshot.locale, {
31
+ minimumIntegerDigits: 4,
32
+ useGrouping: false
33
+ }).format(value.year) : part.value).join('');
34
+ const timeText = getIntlFormatter(Intl.DateTimeFormat, snapshot.locale, {
35
+ timeZone: timezone,
36
+ hour: '24' === clock ? '2-digit' : 'numeric',
37
+ minute: '2-digit',
38
+ second: 'minute' === precision ? void 0 : '2-digit',
39
+ fractionalSecondDigits: 'millisecond' === precision ? 3 : void 0,
40
+ hourCycle: '24' === clock ? 'h23' : 'h12'
41
+ }).format(value.epochMilliseconds).replaceAll('\u202F', ' ');
42
+ const text = 'date' === mode ? dateText : 'time' === mode ? timeText : `${dateText}${showYear ? ' ' : ', '}${timeText}`;
43
+ return showTimezone ? `${text} ${formatTimezone(value.epochMilliseconds, timezone, snapshot)}` : text;
44
+ }
45
+ export { formatDateTime, formatDateTimeWithSnapshot, formatTimezone };
@@ -0,0 +1,6 @@
1
+ export { DateTime, type DateTimeProps } from './dateTime.js';
2
+ export { DateTimeProvider, useTimezone, useClock, useDateTimeFormatter } from './context.js';
3
+ export { configureFormatting, type DateTimePreferences, type FormattingSource, type FormattingSnapshot, } from './config.js';
4
+ export { formatDateTime, formatTimezone, type DateTimeInput, type DateTimeOptions, type TimePrecision, type YearDisplay, } from './format.js';
5
+ export { getIntlFormatter } from './intlFormatter.js';
6
+ export { parseDate } from './parseDate.js';
@@ -0,0 +1,6 @@
1
+ export { DateTime } from "./dateTime.js";
2
+ export { DateTimeProvider, useClock, useDateTimeFormatter, useTimezone } from "./context.js";
3
+ export { configureFormatting } from "./config.js";
4
+ export { formatDateTime, formatTimezone } from "./format.js";
5
+ export { getIntlFormatter } from "./intlFormatter.js";
6
+ export { parseDate } from "./parseDate.js";
@@ -0,0 +1,9 @@
1
+ type IntlFormatterConstructor<Formatter, Options> = new (locale: string, options?: Options) => Formatter;
2
+ /**
3
+ * Constructing an Intl formatter costs far more than formatting with one, and
4
+ * dates render in large tables and on every relative-time tick. Formatters are
5
+ * reused per locale and options. The set stays small: a session uses few
6
+ * locales, timezones, and option shapes.
7
+ */
8
+ export declare function getIntlFormatter<Formatter, Options>(Constructor: IntlFormatterConstructor<Formatter, Options>, locale: string, options: NoInfer<Options>): Formatter;
9
+ export {};
@@ -0,0 +1,16 @@
1
+ const formattersByConstructor = new Map();
2
+ function getIntlFormatter(Constructor, locale, options) {
3
+ let formatters = formattersByConstructor.get(Constructor);
4
+ if (!formatters) {
5
+ formatters = new Map();
6
+ formattersByConstructor.set(Constructor, formatters);
7
+ }
8
+ const key = `${locale}|${JSON.stringify(options)}`;
9
+ let formatter = formatters.get(key);
10
+ if (!formatter) {
11
+ formatter = new Constructor(locale, options);
12
+ formatters.set(key, formatter);
13
+ }
14
+ return formatter;
15
+ }
16
+ export { getIntlFormatter };
@@ -0,0 +1,3 @@
1
+ import { Temporal } from '@js-temporal/polyfill';
2
+ import type { DateTimeInput } from './format.js';
3
+ export declare function parseDate(date: DateTimeInput, timezone: string): Temporal.ZonedDateTime | null;
@@ -0,0 +1,12 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ function parseDate(date, timezone) {
3
+ if ('string' != typeof date && 'number' != typeof date && !(date instanceof Date)) return null;
4
+ try {
5
+ const instant = 'string' == typeof date ? Temporal.Instant.from(date) : Temporal.Instant.fromEpochMilliseconds(Math.trunc(date instanceof Date ? date.getTime() : date));
6
+ return instant.toZonedDateTimeISO(timezone);
7
+ } catch (error) {
8
+ if (error instanceof RangeError || error instanceof TypeError) return null;
9
+ throw error;
10
+ }
11
+ }
12
+ export { parseDate };
@@ -1,24 +1,39 @@
1
- import type { TreeState } from '@react-stately/tree';
2
- import type { useOverlay } from '../useOverlay.js';
3
- import type { MenuItemProps } from './item.js';
4
- import type { useSafetyTriangle } from './useSafetyTriangle.js';
5
- export type OverlayState = ReturnType<typeof useOverlay>['state'];
1
+ import type * as React from 'react';
2
+ import type { RootMenuTriggerState } from '@react-stately/menu';
6
3
  interface DropdownMenuContextValue {
7
4
  /**
8
- * Menu state (from @react-aria's useTreeState) of the parent menu. To be used to
9
- * close the current submenu.
5
+ * `isDismissable` of the root menu. Dismissing a submenu closes the root menu,
6
+ * so submenus follow it.
10
7
  */
11
- parentMenuState?: TreeState<MenuItemProps>;
8
+ isDismissable?: boolean;
12
9
  /**
13
- * Overlay state manager (from useOverlay) for the root (top-most) menu. To be used to
14
- * close the entire menu system.
10
+ * Ref to the menu element (the `ul` with `role="menu"`) that renders the
11
+ * current items. Submenu triggers pass it to `useSubmenuTrigger` as their
12
+ * parent menu.
15
13
  */
16
- rootOverlayState?: OverlayState;
17
- safetyTriangle?: ReturnType<typeof useSafetyTriangle>;
14
+ parentMenuRef?: React.RefObject<HTMLElement | null>;
15
+ /**
16
+ * Element that submenus are portaled into. Submenus render outside their
17
+ * parent menu element, so focus moving into a submenu is not mistaken for
18
+ * focus moving to another item of the parent menu, but they stay inside the
19
+ * root overlay, so the root menu does not close on blur.
20
+ */
21
+ portalContainer?: HTMLElement | null;
22
+ /**
23
+ * Menu trigger state (from react-stately's `useMenuTriggerState` shape) for
24
+ * the root (top-most) menu. Tracks which submenus are open, and closes the
25
+ * entire menu system.
26
+ */
27
+ rootMenuState?: RootMenuTriggerState;
28
+ /**
29
+ * Level of the submenus opened from the current menu's items: 0 in the root
30
+ * menu, 1 in its submenus, and so on.
31
+ */
32
+ submenuLevel?: number;
18
33
  /**
19
34
  * `virtualizeThreshold` of the parent menu, inherited by its submenus.
20
35
  */
21
36
  virtualizeThreshold?: number;
22
37
  }
23
- export declare const DropdownMenuContext: import("react").Context<DropdownMenuContextValue>;
38
+ export declare const DropdownMenuContext: React.Context<DropdownMenuContextValue>;
24
39
  export {};
@@ -4,7 +4,7 @@ import type { UseOverlayProps } from '../useOverlay.js';
4
4
  import type { MenuItemProps } from './item.js';
5
5
  import type { DropdownMenuContentProps, DropdownMenuListProps } from './list.js';
6
6
  export type { MenuItemProps };
7
- interface BaseDropdownMenuProps extends Omit<DropdownMenuContentProps, 'overlayState' | 'overlayPositionProps' | 'items' | 'children' | 'menuTitle'>, Pick<UseOverlayProps, 'isOpen' | 'offset' | 'position' | 'isDismissable' | 'shouldCloseOnBlur' | 'shouldCloseOnInteractOutside' | 'onInteractOutside' | 'onOpenChange' | 'preventOverflowOptions' | 'flipOptions' | 'shouldApplyMinWidth' | 'strategy'> {
7
+ interface BaseDropdownMenuProps extends Omit<DropdownMenuContentProps, 'menuLevel' | 'overlayPositionProps' | 'items' | 'children' | 'menuTitle'>, Pick<UseOverlayProps, 'isOpen' | 'offset' | 'position' | 'isDismissable' | 'shouldCloseOnBlur' | 'shouldCloseOnInteractOutside' | 'onInteractOutside' | 'onOpenChange' | 'preventOverflowOptions' | 'flipOptions' | 'shouldApplyMinWidth' | 'strategy'> {
8
8
  /**
9
9
  * Items to display inside the dropdown menu. If the item has a `children`
10
10
  * prop, it will be rendered as a menu section. If it has a `children` prop
@@ -30,7 +30,7 @@ interface BaseDropdownMenuProps extends Omit<DropdownMenuContentProps, 'overlayS
30
30
  /**
31
31
  * Reference to the container element that the portal should be rendered into.
32
32
  */
33
- portalContainerRef?: React.RefObject<HTMLElement | null>;
33
+ portalContainerRef?: React.RefObject<Element | DocumentFragment | null>;
34
34
  /**
35
35
  * Tag name for the outer wrap, defaults to `div`
36
36
  */
@@ -8,14 +8,15 @@ import { ControlContext, DropdownButton } from "../menu/index.js";
8
8
  import { useOverlay } from "../useOverlay.js";
9
9
  import { DropdownMenuContent } from "./content.js";
10
10
  import { DropdownMenuContext } from "./context.js";
11
+ import { useDropdownRootMenuState } from "./useDropdownRootMenuState.js";
11
12
  function DropdownMenu({ items, disabledKeys, trigger, triggerLabel, isDisabled: disabledProp, isOpen: isOpenProp, renderWrapAs = 'div', size: explicitSize, className, usePortal = false, offset = 8, position = 'bottom-start', isDismissable = true, shouldCloseOnBlur = true, shouldCloseOnInteractOutside, onInteractOutside, onOpenChange, preventOverflowOptions, flipOptions, portalContainerRef, shouldApplyMinWidth, minMenuWidth, strategy, ...props }) {
12
13
  const size = explicitSize ?? 'md';
13
14
  const isDisabled = disabledProp ?? (!items || 0 === items.length);
14
- const { rootOverlayState } = useContext(DropdownMenuContext);
15
+ const { rootMenuState: parentRootMenuState } = useContext(DropdownMenuContext);
15
16
  const { isOpen, state: overlayState, triggerRef, triggerProps: overlayTriggerProps, overlayProps } = useOverlay({
16
17
  type: 'menu',
17
18
  isOpen: isOpenProp,
18
- onClose: rootOverlayState?.close,
19
+ onClose: parentRootMenuState?.close,
19
20
  offset,
20
21
  position,
21
22
  isDismissable,
@@ -29,6 +30,7 @@ function DropdownMenu({ items, disabledKeys, trigger, triggerLabel, isDisabled:
29
30
  shouldApplyMinWidth,
30
31
  strategy
31
32
  });
33
+ const rootMenuState = useDropdownRootMenuState(overlayState, parentRootMenuState);
32
34
  const { menuTriggerProps, menuProps } = useMenuTrigger({
33
35
  type: 'menu',
34
36
  isDisabled
@@ -58,7 +60,11 @@ function DropdownMenu({ items, disabledKeys, trigger, triggerLabel, isDisabled:
58
60
  minWidth: minMenuWidth ?? overlayProps.style?.minWidth
59
61
  }
60
62
  },
61
- overlayState: overlayState,
63
+ menuLevel: {
64
+ type: 'root',
65
+ state: rootMenuState
66
+ },
67
+ isDismissable: isDismissable,
62
68
  items: items
63
69
  });
64
70
  return usePortal ? /*#__PURE__*/ createPortal(menu, portalContainerRef?.current ?? document.body) : menu;
@@ -1,4 +1,5 @@
1
1
  import type * as React from 'react';
2
+ import type { SubmenuTriggerAria } from '@react-aria/menu';
2
3
  import type { TreeState } from '@react-stately/tree';
3
4
  import type { Node } from '@react-types/shared';
4
5
  import { type LinkProps } from '../link/index.js';
@@ -125,12 +126,15 @@ interface DropdownMenuItemProps<T extends React.ElementType = 'li'> {
125
126
  * wrappers use `display: contents` and have no height of their own.
126
127
  */
127
128
  rowProps?: VirtualRowProps;
128
- submenuRef?: React.RefObject<HTMLElement | null>;
129
+ /**
130
+ * Props from `useSubmenuTrigger`, set when this item opens a submenu.
131
+ */
132
+ submenuTriggerProps?: SubmenuTriggerAria<MenuItemProps>['submenuTriggerProps'];
129
133
  }
130
134
  /**
131
135
  * A menu item with a label, optional details, leading and trailing elements.
132
136
  * Can also be used as a trigger button for a submenu. See:
133
137
  * https://react-spectrum.adobe.com/react-aria/useMenu.html
134
138
  */
135
- export declare function DropdownMenuItem<T extends React.ElementType = 'li'>({ node, state, closeOnSelect, onClose, renderAs, ref, menuItemRef, submenuRef, isVirtualized, rowProps, ...props }: DropdownMenuItemProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
139
+ export declare function DropdownMenuItem<T extends React.ElementType = 'li'>({ node, state, closeOnSelect, onClose, renderAs, ref, menuItemRef, submenuTriggerProps, isVirtualized, rowProps, ...props }: DropdownMenuItemProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
136
140
  export {};
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { Fragment, useContext, useEffect, useRef } from "react";
3
- import { useHover, useKeyboard } from "@react-aria/interactions";
2
+ import { Fragment, useContext, useRef } from "react";
3
+ import { useKeyboard } from "@react-aria/interactions";
4
4
  import { useMenuItem } from "@react-aria/menu";
5
5
  import { mergeProps, mergeRefs } from "@react-aria/utils";
6
6
  import { IconCheckmark } from "@sentry/icons/checkmark";
@@ -17,53 +17,27 @@ function getSectionItemAttributes(node, state) {
17
17
  'data-first-in-section': isAfterFirstInSection(node, section) ? void 0 : true
18
18
  };
19
19
  }
20
- function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref, menuItemRef, submenuRef, isVirtualized, rowProps, ...props }) {
20
+ function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref, menuItemRef, submenuTriggerProps, isVirtualized, rowProps, ...props }) {
21
21
  const innerWrapRef = useRef(null);
22
22
  const trailingActionRef = useRef(null);
23
- const lastPointerPosition = useRef(null);
24
23
  const isDisabled = state.disabledKeys.has(node.key);
25
24
  const isFocused = state.selectionManager.focusedKey === node.key;
26
25
  const { key, onAction, to, label, isSelected, leadingItems, submenu, trailingItems, trailingAction, externalHref, closeOnSelect: itemCloseOnSelect, ref: itemRef, ...itemProps } = node.value ?? {};
27
26
  const isSubmenu = !!submenu;
28
27
  const { size } = node.props;
29
- const { rootOverlayState, safetyTriangle } = useContext(DropdownMenuContext);
28
+ const { rootMenuState } = useContext(DropdownMenuContext);
30
29
  const isLink = to || externalHref;
31
30
  const resolvedCloseOnSelect = itemCloseOnSelect ?? closeOnSelect;
32
31
  const actionHandler = ()=>{
33
32
  if (isLink) {
34
- if (resolvedCloseOnSelect) requestAnimationFrame(()=>rootOverlayState?.close());
33
+ if (resolvedCloseOnSelect) requestAnimationFrame(()=>rootMenuState?.close());
35
34
  onAction?.();
36
35
  return;
37
36
  }
38
- if (isSubmenu) return void state.selectionManager.toggleSelection(node.key);
39
37
  onAction?.();
40
38
  };
41
- const { hoverProps, isHovered } = useHover({});
42
- const previousInteraction = useRef({
43
- isHovered,
44
- isFocused
45
- });
46
- useEffect(()=>{
47
- const previous = previousInteraction.current;
48
- previousInteraction.current = {
49
- isHovered,
50
- isFocused
51
- };
52
- if (isHovered === previous.isHovered && isFocused === previous.isFocused) return;
53
- if (isHovered && isFocused) {
54
- if (isSubmenu) return void state.selectionManager.replaceSelection(node.key);
55
- state.selectionManager.clearSelection();
56
- }
57
- }, [
58
- isHovered,
59
- isFocused,
60
- isSubmenu,
61
- node.key,
62
- state.selectionManager
63
- ]);
64
39
  const { keyboardProps } = useKeyboard({
65
40
  onKeyDown: (e)=>{
66
- if ('ArrowRight' === e.key && isSubmenu) return void state.selectionManager.replaceSelection(node.key);
67
41
  if ('ArrowRight' === e.key && document.activeElement === innerWrapRef.current && trailingActionRef.current) {
68
42
  trailingActionRef.current.focus();
69
43
  if (document.activeElement === trailingActionRef.current) return void e.preventDefault();
@@ -71,12 +45,14 @@ function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref,
71
45
  e.continuePropagation();
72
46
  }
73
47
  });
48
+ const { isOpen: _isSubmenuOpen, ...submenuTriggerAriaProps } = submenuTriggerProps ?? {};
74
49
  const { menuItemProps, labelProps, descriptionProps } = useMenuItem({
50
+ ...submenuTriggerAriaProps,
75
51
  key: node.key,
76
52
  onAction: actionHandler,
77
53
  onClose: ()=>{
78
54
  onClose?.();
79
- rootOverlayState?.close();
55
+ rootMenuState?.close();
80
56
  },
81
57
  closeOnSelect: isLink ? false : resolvedCloseOnSelect,
82
58
  isDisabled,
@@ -99,12 +75,31 @@ function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref,
99
75
  }
100
76
  };
101
77
  };
102
- const mergedMenuItemContentProps = mergeProps(props, menuItemProps, hoverProps, keyboardProps, makeInnerWrapProps(), {
78
+ const mergedMenuItemContentProps = mergeProps(props, menuItemProps, keyboardProps, makeInnerWrapProps(), {
103
79
  ref: mergeRefs(menuItemRef, innerWrapRef),
104
80
  'data-test-id': key
105
81
  });
106
- const { onPointerEnter, onPointerMove, onPointerLeave } = mergedMenuItemContentProps;
82
+ const { onPointerEnter, onPointerMove, onPointerLeave, ...menuItemContentProps } = mergedMenuItemContentProps;
107
83
  const itemLabel = node.rendered ?? label;
84
+ const isFromRow = (event)=>event.target instanceof Node && event.currentTarget.contains(event.target);
85
+ const rowEventProps = {
86
+ onPointerEnter: (event)=>{
87
+ if (isFromRow(event)) onPointerEnter?.(event);
88
+ },
89
+ onPointerMove: (event)=>{
90
+ if (isFromRow(event)) onPointerMove?.(event);
91
+ },
92
+ onPointerLeave: (event)=>{
93
+ if (isFromRow(event)) onPointerLeave?.(event);
94
+ },
95
+ onKeyDown: (event)=>{
96
+ if ('ArrowLeft' === event.key && event.target === trailingActionRef.current) {
97
+ event.preventDefault();
98
+ event.stopPropagation();
99
+ innerWrapRef.current?.focus();
100
+ }
101
+ }
102
+ };
108
103
  return /*#__PURE__*/ jsx(ListItem, {
109
104
  ref: mergeRefs(ref, itemRef, rowProps?.ref),
110
105
  "data-index": rowProps?.['data-index'],
@@ -124,47 +119,11 @@ function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref,
124
119
  }),
125
120
  disabled: isDisabled,
126
121
  isFocused: isFocused,
127
- innerWrapProps: {
128
- ...mergedMenuItemContentProps,
129
- onPointerEnter: (event)=>{
130
- lastPointerPosition.current = {
131
- x: event.clientX,
132
- y: event.clientY
133
- };
134
- const savedEvent = {
135
- ...event,
136
- currentTarget: event.currentTarget
137
- };
138
- const enter = ()=>onPointerEnter?.(savedEvent);
139
- if (safetyTriangle) safetyTriangle.defer(event, enter);
140
- else enter();
141
- },
142
- onPointerMove: (event)=>{
143
- lastPointerPosition.current = {
144
- x: event.clientX,
145
- y: event.clientY
146
- };
147
- onPointerMove?.(event);
148
- },
149
- onPointerLeave: (event)=>{
150
- safetyTriangle?.leave(event.currentTarget);
151
- if ('mouse' === event.pointerType && submenuRef?.current && lastPointerPosition.current) safetyTriangle?.start(lastPointerPosition.current, submenuRef.current);
152
- onPointerLeave?.(event);
153
- }
154
- },
122
+ innerWrapProps: menuItemContentProps,
155
123
  labelProps: labelProps,
156
124
  detailsProps: descriptionProps,
157
125
  trailingAction: trailingAction,
158
126
  trailingActionRef: trailingActionRef,
159
- trailingActionWrapperProps: {
160
- onKeyDown: (event)=>{
161
- if ('ArrowLeft' === event.key) {
162
- event.preventDefault();
163
- event.stopPropagation();
164
- innerWrapRef.current?.focus();
165
- }
166
- }
167
- },
168
127
  trailingItems: isSubmenu ? /*#__PURE__*/ jsxs(Fragment, {
169
128
  children: [
170
129
  trailingItems,
@@ -176,6 +135,7 @@ function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref,
176
135
  ]
177
136
  }) : trailingItems,
178
137
  size: size,
138
+ ...rowEventProps,
179
139
  ...itemProps
180
140
  });
181
141
  }
@@ -1,14 +1,14 @@
1
1
  import type * as React from 'react';
2
2
  import type { AriaMenuOptions } from '@react-aria/menu';
3
+ import type { RootMenuTriggerState } from '@react-stately/menu';
3
4
  import type { TreeProps } from '@react-stately/tree';
4
- import type { OverlayState } from './context.js';
5
5
  import type { DropdownMenuContentSizeOptions, DropdownMenuSearchOptions, MenuItemProps } from './item.js';
6
6
  export interface DropdownMenuListProps extends Omit<AriaMenuOptions<MenuItemProps>, 'selectionMode' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'disallowEmptySelection'>, TreeProps<MenuItemProps>, DropdownMenuContentSizeOptions {
7
- overlayPositionProps: React.HTMLAttributes<HTMLDivElement>;
8
7
  /**
9
- * The open state of the current overlay that contains this menu
8
+ * Where this menu sits in the menu tree.
10
9
  */
11
- overlayState: OverlayState;
10
+ menuLevel: DropdownMenuLevel;
11
+ overlayPositionProps: React.HTMLAttributes<HTMLDivElement>;
12
12
  /**
13
13
  * Whether the menu should close when an item has been clicked/selected
14
14
  */
@@ -18,6 +18,11 @@ export interface DropdownMenuListProps extends Omit<AriaMenuOptions<MenuItemProp
18
18
  */
19
19
  disableTextSelection?: boolean;
20
20
  emptyMessage?: React.ReactNode;
21
+ /**
22
+ * Whether interacting outside the menu closes it. Submenus inherit the
23
+ * setting of their parent menu.
24
+ */
25
+ isDismissable?: boolean;
21
26
  /**
22
27
  * Whether only the items near the viewport are rendered. Computed by
23
28
  * `DropdownMenuContent` from `virtualizeThreshold`, so it is not part of the
@@ -52,8 +57,29 @@ export interface DropdownMenuListProps extends Omit<AriaMenuOptions<MenuItemProp
52
57
  */
53
58
  zIndex?: number;
54
59
  }
60
+ /**
61
+ * A root menu starts a menu tree, even when it renders inside another menu.
62
+ * A submenu belongs to the tree of the menu that contains its trigger, and
63
+ * reads the root menu state from context.
64
+ */
65
+ type DropdownMenuLevel = {
66
+ state: RootMenuTriggerState;
67
+ type: 'root';
68
+ } | {
69
+ /** Closes this submenu and returns focus to its trigger. */
70
+ close: () => void;
71
+ /**
72
+ * Index of this submenu in the root menu's `expandedKeysStack`: 0 for a
73
+ * submenu of the root menu, 1 for a submenu of that submenu, and so on.
74
+ */
75
+ level: number;
76
+ /** Ref for the menu element, so the trigger can move focus into it. */
77
+ ref: React.RefObject<HTMLUListElement | null>;
78
+ type: 'submenu';
79
+ };
55
80
  export type DropdownMenuContentProps = Omit<DropdownMenuListProps, 'searchState' | 'isVirtualized'> & {
56
81
  items: MenuItemProps[];
57
82
  search?: DropdownMenuSearchOptions;
58
83
  };
59
- export declare function DropdownMenuContent({ items, disabledKeys, size, search, virtualizeThreshold, ...props }: DropdownMenuContentProps): import("@emotion/react/jsx-runtime").JSX.Element;
84
+ export declare function DropdownMenuContent({ items, disabledKeys, size, search, isDismissable, virtualizeThreshold, ...props }: DropdownMenuContentProps): import("@emotion/react/jsx-runtime").JSX.Element;
85
+ export {};