@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
@@ -4,5 +4,6 @@ interface Result {
4
4
  readonly score: number;
5
5
  readonly start: number;
6
6
  }
7
+ export declare function getSearchScore(text: string, search: string): number;
7
8
  export declare function fzf(text: string, pattern: string, caseSensitive: boolean): Result;
8
9
  export {};
@@ -1,3 +1,7 @@
1
+ function getSearchScore(text, search) {
2
+ const { end, score } = fzf(text, search.toLowerCase(), false);
3
+ return -1 === end ? 0 : Math.max(1, score);
4
+ }
1
5
  const scoreMatch = 16;
2
6
  const scoreGapStart = -3;
3
7
  const scoreGapExtention = -1;
@@ -148,4 +152,4 @@ function calculateScore(text, pattern, sidx, eidx, caseSensitive) {
148
152
  matches
149
153
  ];
150
154
  }
151
- export { fzf };
155
+ export { fzf, getSearchScore };
@@ -1,10 +1,13 @@
1
1
  import React from 'react';
2
2
  import type { CSS } from '../cssTypes.js';
3
- import type { BorderVariant, RadiusSize, SpaceSize, SurfaceVariant } from '../theme/index.js';
3
+ import type { BackgroundToken, BorderVariant, RadiusSize, SpaceSize } from '../theme/index.js';
4
4
  import { type Responsive, type Shorthand } from './styles.js';
5
5
  type Margin = SpaceSize | 'auto' | '0';
6
6
  interface ContainerLayoutProps {
7
- background?: Responsive<Exclude<SurfaceVariant, 'overlay'>>;
7
+ /**
8
+ * Background color, as a path into `tokens.background`.
9
+ */
10
+ background?: Responsive<BackgroundToken>;
8
11
  display?: Responsive<CSS['display']>;
9
12
  padding?: Responsive<Shorthand<SpaceSize, 4>>;
10
13
  paddingTop?: Responsive<SpaceSize>;
@@ -45,6 +48,9 @@ interface ContainerLayoutProps {
45
48
  height?: Responsive<CSS['height']>;
46
49
  minHeight?: Responsive<CSS['minHeight']>;
47
50
  maxHeight?: Responsive<CSS['maxHeight']>;
51
+ /**
52
+ * Border color on all sides. Renders a 1px solid border.
53
+ */
48
54
  border?: Responsive<BorderVariant>;
49
55
  borderTop?: Responsive<BorderVariant>;
50
56
  borderBottom?: Responsive<BorderVariant>;
@@ -3,7 +3,7 @@ import { useMemo, useRef } from "react";
3
3
  import is_prop_valid from "@emotion/is-prop-valid";
4
4
  import styled from "@emotion/styled";
5
5
  import { mergeRefs } from "@react-aria/utils";
6
- import { ContainerQueryProvider, getBorder, getMargin, getRadius, getSpacing, rc } from "./styles.js";
6
+ import { ContainerQueryProvider, getBackground, getBorder, getMargin, getRadius, getSpacing, rc } from "./styles.js";
7
7
  const omitContainerProps = new Set([
8
8
  'alignSelf',
9
9
  'area',
@@ -118,7 +118,7 @@ const Container = styled((props)=>{
118
118
  ${(p)=>rc('margin-left', p.marginLeft, p.theme, getMargin)};
119
119
  ${(p)=>rc('margin-right', p.marginRight, p.theme, getMargin)};
120
120
 
121
- ${(p)=>rc('background', p.background, p.theme, (v)=>v ? p.theme.tokens.background[v] : void 0)};
121
+ ${(p)=>rc('background', p.background, p.theme, getBackground)};
122
122
 
123
123
  ${(p)=>rc('border-radius', p.radius, p.theme, getRadius)};
124
124
 
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode, RefObject } from 'react';
2
- import type { BorderVariant, BreakpointSize, ContainerBreakpointSize, RadiusSize, SpaceSize, Theme } from '../theme/index.js';
2
+ import type { BackgroundToken, BorderVariant, BreakpointSize, ContainerBreakpointSize, RadiusSize, SpaceSize, Theme } from '../theme/index.js';
3
3
  type ResponsiveBreakpoint = BreakpointSize | ContainerBreakpointSize;
4
4
  export declare function rc<T>(property: string, value: Responsive<T> | undefined, theme: Theme, resolver?: (value: T | undefined, breakpoint: ResponsiveBreakpoint | undefined, theme: Theme) => string | undefined): string | undefined;
5
5
  type Margin = SpaceSize | 'auto' | '0';
@@ -38,6 +38,7 @@ export type Shorthand<T extends string, N extends 4 | 2> = N extends 4 ? `${T} $
38
38
  type ScreenBreakpoint = `screen:${BreakpointSize}`;
39
39
  export type ResponsiveKey = ContainerBreakpointSize | ScreenBreakpoint;
40
40
  export type Responsive<T> = T | Partial<Record<ResponsiveKey, T>>;
41
+ export declare function getBackground(background: BackgroundToken | undefined, _breakpoint: ResponsiveBreakpoint | undefined, theme: Theme): string | undefined;
41
42
  export declare function getBorder(border: BorderVariant | undefined, _breakpoint: ResponsiveBreakpoint | undefined, theme: Theme): string | undefined;
42
43
  export declare function getRadius(radius: Shorthand<RadiusSize, 4> | undefined, _breakpoint: ResponsiveBreakpoint | undefined, theme: Theme): string | undefined;
43
44
  export declare function getSpacing(spacing: Shorthand<SpaceSize, 4> | undefined, _breakpoint: ResponsiveBreakpoint | undefined, theme: Theme): string | undefined;
@@ -95,10 +95,16 @@ function resolveMargin(sizeComponent, theme) {
95
95
  if ('0' === sizeComponent) return '0';
96
96
  return theme.space[sizeComponent] ?? theme.space['0'];
97
97
  }
98
- function borderValue(key, theme) {
99
- if ('primary' === key) return theme.tokens.border[key];
100
- if ('muted' === key || 'secondary' === key) return theme.tokens.border.secondary;
101
- return theme.tokens.border[key].vibrant;
98
+ function getBackground(background, _breakpoint, theme) {
99
+ if (void 0 === background) return;
100
+ let node = theme.tokens.background;
101
+ for (const segment of background.split('.'))node = node[segment];
102
+ return node;
103
+ }
104
+ function borderValue(path, theme) {
105
+ let node = theme.tokens.border;
106
+ for (const segment of path.split('.'))node = node[segment];
107
+ return node;
102
108
  }
103
109
  function getBorder(border, _breakpoint, theme) {
104
110
  if (void 0 === border) return;
@@ -234,4 +240,4 @@ function ContainerQueryProvider({ elementRef, children }) {
234
240
  children: children
235
241
  });
236
242
  }
237
- export { ContainerQueryContext, ContainerQueryProvider, FLEX_JUSTIFY_CONTENT, getBorder, getMargin, getRadius, getSpacing, rc, useActiveBreakpoint, useContainerBreakpoint, useHasContainerQuery, useResponsivePropResolver, useResponsivePropValue };
243
+ export { ContainerQueryContext, ContainerQueryProvider, FLEX_JUSTIFY_CONTENT, getBackground, getBorder, getMargin, getRadius, getSpacing, rc, useActiveBreakpoint, useContainerBreakpoint, useHasContainerQuery, useResponsivePropResolver, useResponsivePropValue };
@@ -0,0 +1,21 @@
1
+ import type * as React from 'react';
2
+ import { useClock, useTimezone } from './dateTime/index.js';
3
+ /**
4
+ * Published 0.4.0 and 0.5.0 exported this API from `@sentry/scraps/datetime`.
5
+ * It now lives in `@sentry/scraps/dateTime`; these aliases keep existing imports
6
+ * working for one release.
7
+ */
8
+ /** @deprecated Use `DateTimePreferences` from `@sentry/scraps/dateTime`. */
9
+ export interface DateTimeContextValue {
10
+ clockDisplay: '12' | '24';
11
+ timezone: string;
12
+ }
13
+ /** @deprecated Use `DateTimeProvider` from `@sentry/scraps/dateTime`. */
14
+ export declare function DateTimeProvider({ value, children, }: {
15
+ children: React.ReactNode;
16
+ value: DateTimeContextValue;
17
+ }): import("@emotion/react/jsx-runtime").JSX.Element;
18
+ /** @deprecated Use `useTimezone` from `@sentry/scraps/dateTime`. */
19
+ export { useTimezone };
20
+ /** @deprecated Use `useClock` from `@sentry/scraps/dateTime`. */
21
+ export declare const useClockDisplay: typeof useClock;
@@ -0,0 +1,13 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { DateTimeProvider, useClock, useTimezone } from "./dateTime/index.js";
3
+ function legacyDatetime_DateTimeProvider({ value, children }) {
4
+ return /*#__PURE__*/ jsx(DateTimeProvider, {
5
+ value: {
6
+ timezone: value.timezone,
7
+ clock: value.clockDisplay
8
+ },
9
+ children: children
10
+ });
11
+ }
12
+ const useClockDisplay = useClock;
13
+ export { legacyDatetime_DateTimeProvider as DateTimeProvider, useClockDisplay, useTimezone };
@@ -1,2 +1,2 @@
1
1
  export { Link, type LinkDestination, type LinkProps, ExternalLink } from './link.js';
2
- export { LinkBehaviorContextProvider } from './linkBehaviorContext.js';
2
+ export { LinkBehaviorContextProvider, useLinkQueryString, useResolveLinkHref, } from './linkBehaviorContext.js';
@@ -1,2 +1,2 @@
1
1
  export { ExternalLink, Link } from "./link.js";
2
- export { LinkBehaviorContextProvider } from "./linkBehaviorContext.js";
2
+ export { LinkBehaviorContextProvider, useLinkQueryString, useResolveLinkHref } from "./linkBehaviorContext.js";
@@ -1,9 +1,16 @@
1
1
  import type * as React from 'react';
2
2
  import { type FunctionComponent } from 'react';
3
3
  import type { LinkProps } from './link.js';
4
+ type QueryString = {
5
+ parse: (search: string) => Record<string, string | string[] | null>;
6
+ stringify: (query: Record<string, unknown>) => string;
7
+ };
4
8
  type LinkBehavior<T extends LinkProps> = {
5
9
  behavior: (props: T) => T;
6
10
  component: FunctionComponent<T>;
11
+ /** Query string helpers default to URLSearchParams behavior. */
12
+ parse?: QueryString['parse'];
13
+ stringify?: QueryString['stringify'];
7
14
  };
8
15
  declare function AnchorLink({ to, replace: _replace, preventScrollReset: _preventScrollReset, reloadDocument: _reloadDocument, state: _state, ...props }: LinkProps): import("@emotion/react/jsx-runtime").JSX.Element;
9
16
  export declare const LinkBehaviorContextProvider: React.Provider<LinkBehavior<LinkProps> | null>;
@@ -11,6 +18,8 @@ export declare const useLinkBehavior: <T extends LinkProps>(props: T) => {
11
18
  Component: typeof AnchorLink | React.FunctionComponent<T>;
12
19
  behavior: () => T;
13
20
  };
21
+ /** Use the provider's query helpers, or the native defaults outside a provider. */
22
+ export declare function useLinkQueryString(): QueryString;
14
23
  /** Resolve collection hrefs through the same application behavior as Link. */
15
24
  export declare function useResolveLinkHref(): (to: LinkProps["to"]) => string;
16
25
  export {};
@@ -1,11 +1,11 @@
1
1
  import { jsx } from "@emotion/react/jsx-runtime";
2
2
  import { createContext, useCallback, useContext } from "react";
3
- import * as __rspack_external_query_string_78b5d812 from "query-string";
4
3
  const LinkBehaviorContext = /*#__PURE__*/ createContext(null);
5
4
  function AnchorLink({ to, replace: _replace, preventScrollReset: _preventScrollReset, reloadDocument: _reloadDocument, state: _state, ...props }) {
5
+ const { stringify } = useLinkQueryString();
6
6
  return /*#__PURE__*/ jsx("a", {
7
7
  ...props,
8
- href: destinationToHref(to)
8
+ href: destinationToHref(to, stringify)
9
9
  });
10
10
  }
11
11
  const defaultLinkBehavior = ()=>({
@@ -21,18 +21,48 @@ const useLinkBehavior = (props)=>{
21
21
  behavior: ()=>behavior(props)
22
22
  };
23
23
  };
24
- function destinationToHref(to) {
24
+ function parseQuery(search) {
25
+ const query = Object.create(null);
26
+ for (const [key, value] of new URLSearchParams(search)){
27
+ const existing = query[key];
28
+ if (void 0 === existing) query[key] = value;
29
+ else query[key] = [
30
+ ...Array.isArray(existing) ? existing : [
31
+ existing
32
+ ],
33
+ value
34
+ ];
35
+ }
36
+ return query;
37
+ }
38
+ function stringifyQuery(query) {
39
+ const params = new URLSearchParams();
40
+ for (const [key, value] of Object.entries(query))for (const item of Array.isArray(value) ? value : [
41
+ value
42
+ ])if (void 0 !== item) params.append(key, String(item));
43
+ return params.toString();
44
+ }
45
+ function useLinkQueryString() {
46
+ const linkBehavior = useContext(LinkBehaviorContext);
47
+ return {
48
+ parse: linkBehavior?.parse ?? parseQuery,
49
+ stringify: linkBehavior?.stringify ?? stringifyQuery
50
+ };
51
+ }
52
+ function destinationToHref(to, stringify) {
25
53
  if ('string' == typeof to) return to;
26
54
  const { pathname = '', hash = '', search = '', query } = to;
27
- const querySearch = query ? __rspack_external_query_string_78b5d812.stringify(query) : search;
55
+ const querySearch = query ? stringify(query) : search;
28
56
  return `${pathname}${querySearch && !querySearch.startsWith('?') ? '?' : ''}${querySearch}${hash && !hash.startsWith('#') ? '#' : ''}${hash}`;
29
57
  }
30
58
  function useResolveLinkHref() {
31
59
  const linkBehavior = useContext(LinkBehaviorContext);
60
+ const { stringify } = useLinkQueryString();
32
61
  return useCallback((to)=>destinationToHref(linkBehavior ? linkBehavior.behavior({
33
62
  to
34
- }).to : to), [
35
- linkBehavior
63
+ }).to : to, stringify), [
64
+ linkBehavior,
65
+ stringify
36
66
  ]);
37
67
  }
38
- export { LinkBehaviorContextProvider, useLinkBehavior, useResolveLinkHref };
68
+ export { LinkBehaviorContextProvider, useLinkBehavior, useLinkQueryString, useResolveLinkHref };
@@ -154,14 +154,12 @@ interface OtherProps<T extends React.ElementType> {
154
154
  trailingAction?: MenuItemTrailingAction;
155
155
  /** Ref to the trailing action's button. */
156
156
  trailingActionRef?: React.Ref<HTMLButtonElement>;
157
- /** Props for the wrapper around the trailing action. */
158
- trailingActionWrapperProps?: React.ComponentPropsWithRef<'div'>;
159
157
  }
160
158
  interface MenuListItemProps<T extends React.ElementType = 'li'> extends ListItemProps, OtherProps<T> {
161
159
  ref?: React.ComponentPropsWithRef<NoInfer<T>>['ref'];
162
160
  }
163
161
  /** Renders the shared visual shell for menu and select items. */
164
- export declare function MenuListItem<T extends React.ElementType = 'li'>({ label, details, as, priority, size, disabled, leadingItems, trailingItems, trailingAction, isFocused, isSelected, isPressed, innerWrapProps, labelProps, detailsProps, showDetailsInOverlay, onDetailsHoverChange, tooltip, tooltipOptions, ref, trailingActionRef, trailingActionWrapperProps, ...props }: MenuListItemProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
162
+ export declare function MenuListItem<T extends React.ElementType = 'li'>({ label, details, as, priority, size, disabled, leadingItems, trailingItems, trailingAction, isFocused, isSelected, isPressed, innerWrapProps, labelProps, detailsProps, showDetailsInOverlay, onDetailsHoverChange, tooltip, tooltipOptions, ref, trailingActionRef, ...props }: MenuListItemProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
165
163
  /** Moves focus into a menu item's overlay details, returning whether it could. */
166
164
  export declare function focusMenuItemDetails(item: Element | null): boolean;
167
165
  export {};
package/dist/menu/menu.js CHANGED
@@ -27,7 +27,7 @@ function calculateMenuMinHeight(first, second) {
27
27
  }
28
28
  function MenuHeaderLayout(props) {
29
29
  return /*#__PURE__*/ jsx(Stack, {
30
- borderBottom: "muted",
30
+ borderBottom: "secondary",
31
31
  gap: "0",
32
32
  ...props
33
33
  });
@@ -76,7 +76,7 @@ function MenuSectionHeader({ children, trailingAction, ...props }) {
76
76
  function MenuSectionSeparator() {
77
77
  return /*#__PURE__*/ jsx(Separator, {
78
78
  orientation: "horizontal",
79
- border: "muted"
79
+ border: "secondary"
80
80
  });
81
81
  }
82
82
  function MenuSectionGroup(props) {
@@ -97,7 +97,7 @@ function MenuSectionList(props) {
97
97
  }
98
98
  function MenuFooterLayout(props) {
99
99
  return /*#__PURE__*/ jsx(Flex, {
100
- borderTop: "muted",
100
+ borderTop: "secondary",
101
101
  align: "center",
102
102
  padding: "md lg",
103
103
  ...props
@@ -254,7 +254,7 @@ const StyledDetails = styled('div')`
254
254
  color: ${getTextColor(p)};
255
255
  `}
256
256
  `;
257
- function MenuListItem({ label, details, as, priority = 'default', size, disabled = false, leadingItems = false, trailingItems = false, trailingAction, isFocused = false, isSelected = false, isPressed, innerWrapProps = {}, labelProps = {}, detailsProps = {}, showDetailsInOverlay = false, onDetailsHoverChange, tooltip, tooltipOptions, ref, trailingActionRef, trailingActionWrapperProps, ...props }) {
257
+ function MenuListItem({ label, details, as, priority = 'default', size, disabled = false, leadingItems = false, trailingItems = false, trailingAction, isFocused = false, isSelected = false, isPressed, innerWrapProps = {}, labelProps = {}, detailsProps = {}, showDetailsInOverlay = false, onDetailsHoverChange, tooltip, tooltipOptions, ref, trailingActionRef, ...props }) {
258
258
  const [itemElement, setItemElement] = useState(null);
259
259
  const [returnFocusTarget, setReturnFocusTarget] = useState(null);
260
260
  const theme = useTheme();
@@ -394,7 +394,6 @@ function MenuListItem({ label, details, as, priority = 'default', size, disabled
394
394
  top: "0",
395
395
  height: "100%",
396
396
  align: "center",
397
- ...trailingActionWrapperProps,
398
397
  children: /*#__PURE__*/ jsx(Button, {
399
398
  ref: trailingActionRef,
400
399
  size: "zero",
@@ -0,0 +1,14 @@
1
+ import type { DateTimeInput } from '../dateTime/index.js';
2
+ import { type FormattingSnapshot } from '../dateTime/config.js';
3
+ export type RelaxedDateType = DateTimeInput;
4
+ export interface RelativeTimeOptions {
5
+ prefix?: string;
6
+ /** Fuzzy preserves thresholds; English keeps articles, other locales use numeric counts. */
7
+ rounding?: 'fuzzy' | 'unit';
8
+ /** Unit width when rounding is "unit". */
9
+ style?: 'long' | 'short' | 'narrow';
10
+ suffix?: string;
11
+ }
12
+ export declare function getDateObj(date: RelaxedDateType): Date;
13
+ export declare function formatRelativeDate(date: DateTimeInput, { suffix, prefix, style, rounding }: RelativeTimeOptions, snapshot: Readonly<FormattingSnapshot>): string;
14
+ export declare function getRelativeDate(date: DateTimeInput, options?: RelativeTimeOptions): string;
@@ -0,0 +1,107 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { getSnapshot } from "../dateTime/config.js";
3
+ import { getIntlFormatter } from "../dateTime/intlFormatter.js";
4
+ import { parseDate } from "../dateTime/parseDate.js";
5
+ import { getDurationWithMessages } from "../duration/getDuration.js";
6
+ function getDateObj(date) {
7
+ return 'string' == typeof date || 'number' == typeof date ? new Date(date) : date;
8
+ }
9
+ function getFuzzyDuration(value, now) {
10
+ const milliseconds = Math.abs(value.epochMilliseconds - now.epochMilliseconds);
11
+ const seconds = Math.round(milliseconds / 1000);
12
+ if (seconds <= 44) return {
13
+ unit: 'second',
14
+ count: seconds
15
+ };
16
+ for (const { unit, size, limit } of [
17
+ {
18
+ unit: 'minute',
19
+ size: 60000,
20
+ limit: 45
21
+ },
22
+ {
23
+ unit: 'hour',
24
+ size: 3600000,
25
+ limit: 22
26
+ },
27
+ {
28
+ unit: 'day',
29
+ size: 86400000,
30
+ limit: 26
31
+ }
32
+ ]){
33
+ const count = Math.round(milliseconds / size);
34
+ if (count <= 1) return {
35
+ unit,
36
+ count: 1
37
+ };
38
+ if (count < limit) return {
39
+ unit,
40
+ count
41
+ };
42
+ }
43
+ const earlier = value.epochNanoseconds < now.epochNanoseconds ? value : now;
44
+ const later = earlier === value ? now : value;
45
+ let wholeMonths = (later.year - earlier.year) * 12 + later.month - earlier.month;
46
+ let anchor;
47
+ try {
48
+ anchor = earlier.add({
49
+ months: wholeMonths
50
+ });
51
+ } catch (error) {
52
+ if (!(error instanceof RangeError)) throw error;
53
+ anchor = earlier.add({
54
+ months: --wholeMonths
55
+ });
56
+ }
57
+ if (anchor.epochNanoseconds > later.epochNanoseconds) anchor = earlier.add({
58
+ months: --wholeMonths
59
+ });
60
+ const remainder = later.epochMilliseconds - anchor.epochMilliseconds;
61
+ const months = wholeMonths + remainder / 86400000 * (4800 / 146097);
62
+ const roundedMonths = Math.round(months);
63
+ return roundedMonths < 11 ? {
64
+ unit: 'month',
65
+ count: Math.max(1, roundedMonths)
66
+ } : {
67
+ unit: 'year',
68
+ count: Math.max(1, Math.round(months / 12))
69
+ };
70
+ }
71
+ function englishFuzzyDuration(unit, count) {
72
+ if ('second' === unit) return 'a few seconds';
73
+ if (1 === count) return 'hour' === unit ? 'an hour' : `a ${unit}`;
74
+ return `${count} ${unit}s`;
75
+ }
76
+ function formatRelativeDate(date, { suffix, prefix, style = 'long', rounding = 'fuzzy' }, snapshot) {
77
+ const value = parseDate(date, snapshot.timezone);
78
+ if (!value) return 'Invalid date';
79
+ const now = Temporal.Instant.fromEpochMilliseconds(Date.now()).toZonedDateTimeISO(snapshot.timezone);
80
+ const isFuture = value.epochNanoseconds > now.epochNanoseconds;
81
+ let duration;
82
+ if ('fuzzy' === rounding) {
83
+ const { unit, count } = getFuzzyDuration(value, now);
84
+ const isEnglish = 'en' === snapshot.locale.toLowerCase().split('-')[0];
85
+ if (!isEnglish && (isFuture ? prefix : suffix) === void 0) return getIntlFormatter(Intl.RelativeTimeFormat, snapshot.locale, {
86
+ numeric: 'always'
87
+ }).format(isFuture ? count : -count, unit);
88
+ duration = isEnglish ? englishFuzzyDuration(unit, count) : getIntlFormatter(Intl.NumberFormat, snapshot.locale, {
89
+ style: 'unit',
90
+ unit,
91
+ unitDisplay: 'long'
92
+ }).format(count);
93
+ } else duration = getDurationWithMessages(Math.trunc((now.epochMilliseconds - value.epochMilliseconds) / 1000), {
94
+ style,
95
+ absolute: isFuture
96
+ }, snapshot.messages);
97
+ if (isFuture) {
98
+ if (void 0 === prefix) return `${snapshot.messages.t('in')} ${duration}`;
99
+ return prefix ? `${prefix} ${duration}` : duration;
100
+ }
101
+ if (void 0 === suffix) return snapshot.messages.t('%s ago', duration);
102
+ return suffix ? `${duration} ${suffix}` : duration;
103
+ }
104
+ function getRelativeDate(date, options = {}) {
105
+ return formatRelativeDate(date, options, getSnapshot());
106
+ }
107
+ export { formatRelativeDate, getDateObj, getRelativeDate };
@@ -0,0 +1,3 @@
1
+ export { RelativeTime, RELATIVE_TIME_MAX_WIDTH, type RelativeTimeProps, } from './relativeTime.js';
2
+ export { getDateObj, getRelativeDate, type RelaxedDateType, type RelativeTimeOptions, } from './getRelativeDate.js';
3
+ export { useRelativeTimeFormatter } from './useRelativeTimeFormatter.js';
@@ -0,0 +1,3 @@
1
+ export { RELATIVE_TIME_MAX_WIDTH, RelativeTime } from "./relativeTime.js";
2
+ export { getDateObj, getRelativeDate } from "./getRelativeDate.js";
3
+ export { useRelativeTimeFormatter } from "./useRelativeTimeFormatter.js";
@@ -0,0 +1,55 @@
1
+ import type * as React from 'react';
2
+ import { type RelaxedDateType, type RelativeTimeOptions } from './getRelativeDate.js';
3
+ /** Allow room for offset labels such as GMT+5:45 without wrapping timestamp rows. */
4
+ export declare const RELATIVE_TIME_MAX_WIDTH = 280;
5
+ export interface RelativeTimeProps extends RelativeTimeOptions {
6
+ /**
7
+ * The date value, can be string, number (e.g. timestamp), or instance of Date
8
+ */
9
+ date: RelaxedDateType;
10
+ /**
11
+ * What the timestamp refers to, e.g. "Last Seen". Rendered in a header
12
+ * alongside the relative time.
13
+ *
14
+ * Optional because most timestamps in the app are already labelled by what
15
+ * they sit next to. Without one there is no header, and the card is the two
16
+ * timezone rows on their own.
17
+ */
18
+ label?: React.ReactNode;
19
+ /**
20
+ * Prefix before upcoming time (when the date is in the future)
21
+ *
22
+ * @default "in"
23
+ */
24
+ prefix?: string;
25
+ /**
26
+ * Show seconds on the absolute times. For timestamps precise enough that the
27
+ * minute alone does not identify them, e.g. spans in a trace.
28
+ */
29
+ showSeconds?: boolean;
30
+ /**
31
+ * Suffix after elapsed time e.g. "ago" in "5 minutes ago"
32
+ *
33
+ * @default "ago"
34
+ */
35
+ suffix?: string;
36
+ }
37
+ /**
38
+ * A detail card for a single timestamp, showing the relative time alongside the
39
+ * absolute time in both the viewer's timezone and UTC.
40
+ *
41
+ * This is tooltip content rather than a standalone element. `TimeSince` renders
42
+ * it for you; reach for it directly only when you are building the tooltip
43
+ * yourself. The overlay drops its own padding on seeing the sections this
44
+ * composes, so there is nothing to pass but the card's width:
45
+ *
46
+ * ```tsx
47
+ * <Tooltip
48
+ * maxWidth={RELATIVE_TIME_MAX_WIDTH}
49
+ * title={<RelativeTime date={date} label={t('Last Seen')} />}
50
+ * >
51
+ * {trigger}
52
+ * </Tooltip>
53
+ * ```
54
+ */
55
+ export declare function RelativeTime({ date, label, prefix, suffix, rounding, style, showSeconds, }: RelativeTimeProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,102 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Fragment } from "react";
3
+ import styled from "@emotion/styled";
4
+ import { Tag } from "../badge/index.js";
5
+ import { DateTime } from "../dateTime/index.js";
6
+ import { DescriptionList } from "../descriptionList/index.js";
7
+ import { Text } from "../text/index.js";
8
+ import { Tooltip } from "../tooltip/index.js";
9
+ import { useFormattingSnapshot } from "../dateTime/context.js";
10
+ import { formatTimezone } from "../dateTime/format.js";
11
+ import { parseDate } from "../dateTime/parseDate.js";
12
+ import { formatRelativeDate } from "./getRelativeDate.js";
13
+ const RELATIVE_TIME_MAX_WIDTH = 280;
14
+ const UTC = 'UTC';
15
+ function RelativeTime({ date, label, prefix, suffix, rounding, style, showSeconds }) {
16
+ const snapshot = useFormattingSnapshot();
17
+ const value = parseDate(date, snapshot.timezone);
18
+ const abbreviation = value ? formatTimezone(value.epochMilliseconds, snapshot.timezone, snapshot) : 'Invalid date';
19
+ const isViewerUtc = abbreviation === UTC;
20
+ return /*#__PURE__*/ jsxs(Fragment, {
21
+ children: [
22
+ null != label && /*#__PURE__*/ jsx(Tooltip.Header, {
23
+ trailingItems: formatRelativeDate(date, {
24
+ suffix,
25
+ prefix,
26
+ rounding,
27
+ style
28
+ }, snapshot),
29
+ children: label
30
+ }),
31
+ /*#__PURE__*/ jsx(Tooltip.Grid, {
32
+ children: /*#__PURE__*/ jsxs(DescriptionList, {
33
+ columns: "max-content 1fr max-content",
34
+ gap: "2xs sm",
35
+ align: "center",
36
+ children: [
37
+ !isViewerUtc && /*#__PURE__*/ jsx(TimestampRow, {
38
+ date: date,
39
+ abbreviation: abbreviation,
40
+ variant: "info",
41
+ showSeconds: showSeconds
42
+ }),
43
+ /*#__PURE__*/ jsx(TimestampRow, {
44
+ date: date,
45
+ abbreviation: UTC,
46
+ variant: "muted",
47
+ showSeconds: showSeconds,
48
+ utc: true
49
+ })
50
+ ]
51
+ })
52
+ })
53
+ ]
54
+ });
55
+ }
56
+ function TimestampRow({ date, abbreviation, variant, showSeconds, utc }) {
57
+ return /*#__PURE__*/ jsxs(Fragment, {
58
+ children: [
59
+ /*#__PURE__*/ jsx(DescriptionList.Term, {
60
+ children: /*#__PURE__*/ jsx(TimezoneTag, {
61
+ variant: variant,
62
+ children: abbreviation
63
+ })
64
+ }),
65
+ /*#__PURE__*/ jsx(DescriptionList.Details, {
66
+ children: /*#__PURE__*/ jsx(Text, {
67
+ tabular: true,
68
+ wrap: "nowrap",
69
+ children: /*#__PURE__*/ jsx(DateTime, {
70
+ date: date,
71
+ mode: "date",
72
+ year: "always",
73
+ timezone: utc ? 'UTC' : void 0,
74
+ showTimezone: false
75
+ })
76
+ })
77
+ }),
78
+ /*#__PURE__*/ jsx(DescriptionList.Details, {
79
+ children: /*#__PURE__*/ jsx(Text, {
80
+ align: "right",
81
+ tabular: true,
82
+ wrap: "nowrap",
83
+ children: /*#__PURE__*/ jsx(DateTime, {
84
+ date: date,
85
+ mode: "time",
86
+ precision: showSeconds ? 'second' : 'minute',
87
+ timezone: utc ? 'UTC' : void 0,
88
+ showTimezone: false
89
+ })
90
+ })
91
+ })
92
+ ]
93
+ });
94
+ }
95
+ const TimezoneTag = styled(Tag)`
96
+ height: 17px;
97
+ min-width: 20px;
98
+ justify-content: center;
99
+ padding: 0 ${(p)=>p.theme.space.xs};
100
+ border-radius: ${(p)=>p.theme.radius['2xs']};
101
+ `;
102
+ export { RELATIVE_TIME_MAX_WIDTH, RelativeTime };
@@ -0,0 +1,2 @@
1
+ import { type getRelativeDate } from './getRelativeDate.js';
2
+ export declare function useRelativeTimeFormatter(): typeof getRelativeDate;
@@ -0,0 +1,10 @@
1
+ import { useCallback } from "react";
2
+ import { useFormattingSnapshot } from "../dateTime/context.js";
3
+ import { formatRelativeDate } from "./getRelativeDate.js";
4
+ function useRelativeTimeFormatter() {
5
+ const snapshot = useFormattingSnapshot();
6
+ return useCallback((date, options = {})=>formatRelativeDate(date, options, snapshot), [
7
+ snapshot
8
+ ]);
9
+ }
10
+ export { useRelativeTimeFormatter };
@@ -0,0 +1,9 @@
1
+ import type { TabListState } from '@react-stately/tabs';
2
+ import type { InternalTabsProps } from './tabs.js';
3
+ interface TabContext {
4
+ rootProps: Omit<InternalTabsProps, 'children'> & Required<Pick<InternalTabsProps, 'orientation' | 'size'>>;
5
+ setTabListState: (state: TabListState<any>) => void;
6
+ tabListState?: TabListState<any>;
7
+ }
8
+ export declare const TabsContext: import("react").Context<TabContext>;
9
+ export {};
@@ -0,0 +1,9 @@
1
+ import { createContext } from "react";
2
+ const TabsContext = /*#__PURE__*/ createContext({
3
+ rootProps: {
4
+ orientation: 'horizontal',
5
+ size: 'md'
6
+ },
7
+ setTabListState: ()=>{}
8
+ });
9
+ export { TabsContext };
@@ -1,4 +1,2 @@
1
- export { Tabs, TabStateProvider } from './tabs.js';
2
- export { TabList } from './tabList.js';
3
- export { type TabListItemProps } from './item.js';
4
- export { TabPanels } from './tabPanels.js';
1
+ export { Tabs, LinkTabs, type TabKey, type TabsComponents, type TabsProps, type LinkTabsComponents, type LinkTabsProps, } from './tabs.js';
2
+ export type { TabListItemProps, LinkTabListItemProps, TabPanelItemProps } from './item.js';