@sentry/scraps 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -3
- package/dist/alert/alert.js +10 -7
- package/dist/badge/tag.js +4 -2
- package/dist/button/button.js +1 -0
- package/dist/button/linkButton.js +1 -0
- package/dist/button/styles.js +157 -152
- package/dist/codeBlock/codeBlock.js +1 -0
- package/dist/compactSelect/compactSelect.d.ts +2 -2
- package/dist/compactSelect/compactSelect.js +37 -23
- package/dist/compactSelect/control.js +14 -10
- package/dist/compactSelect/gridList/index.js +35 -36
- package/dist/compactSelect/gridList/option.d.ts +4 -1
- package/dist/compactSelect/gridList/option.js +4 -3
- package/dist/compactSelect/gridList/section.d.ts +10 -3
- package/dist/compactSelect/gridList/section.js +16 -33
- package/dist/compactSelect/listBox/index.d.ts +1 -1
- package/dist/compactSelect/listBox/index.js +46 -58
- package/dist/compactSelect/listBox/section.d.ts +10 -8
- package/dist/compactSelect/listBox/section.js +11 -30
- package/dist/compactSelect/styles.d.ts +6 -7
- package/dist/compactSelect/styles.js +1 -23
- package/dist/compactSelect/utils.js +2 -6
- package/dist/dateTime/config.d.ts +23 -0
- package/dist/dateTime/config.js +50 -0
- package/dist/dateTime/context.d.ts +18 -0
- package/dist/dateTime/context.js +46 -0
- package/dist/dateTime/dateTime.d.ts +6 -0
- package/dist/dateTime/dateTime.js +30 -0
- package/dist/dateTime/format.d.ts +24 -0
- package/dist/dateTime/format.js +45 -0
- package/dist/dateTime/index.d.ts +6 -0
- package/dist/dateTime/index.js +6 -0
- package/dist/dateTime/intlFormatter.d.ts +9 -0
- package/dist/dateTime/intlFormatter.js +16 -0
- package/dist/dateTime/parseDate.d.ts +3 -0
- package/dist/dateTime/parseDate.js +12 -0
- package/dist/diagnostics/context.d.ts +12 -0
- package/dist/diagnostics/context.js +11 -0
- package/dist/diagnostics/index.d.ts +2 -0
- package/dist/diagnostics/index.js +1 -0
- package/dist/disclosure/disclosure.js +1 -1
- package/dist/dragHandle/dragHandle.js +3 -5
- package/dist/dropdownMenu/context.d.ts +36 -11
- package/dist/dropdownMenu/context.js +2 -1
- package/dist/dropdownMenu/dropdownMenu.d.ts +2 -2
- package/dist/dropdownMenu/dropdownMenu.js +9 -3
- package/dist/dropdownMenu/item.d.ts +7 -8
- package/dist/dropdownMenu/item.js +43 -77
- package/dist/dropdownMenu/list.d.ts +31 -5
- package/dist/dropdownMenu/list.js +154 -133
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +5 -241
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +5 -29
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +6 -14
- package/dist/dropdownMenu/useDropdownRootMenuState.d.ts +13 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.js +30 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.d.ts +19 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.js +25 -0
- package/dist/dropdownMenu/utils.js +5 -7
- package/dist/duration/formatElapsedDuration.d.ts +4 -0
- package/dist/duration/formatElapsedDuration.js +10 -0
- package/dist/duration/getDuration.d.ts +68 -0
- package/dist/duration/getDuration.js +80 -0
- package/dist/duration/index.d.ts +2 -0
- package/dist/duration/index.js +2 -0
- package/dist/form/field/radioGroupField.d.ts +7 -0
- package/dist/form/field/radioGroupField.js +14 -0
- package/dist/form/field/selectField.d.ts +3 -4
- package/dist/form/field/selectField.js +16 -24
- package/dist/{compactSelect/fzf.d.ts → fzf.d.ts} +1 -0
- package/dist/{compactSelect/fzf.js → fzf.js} +5 -1
- package/dist/layout/container.d.ts +24 -7
- package/dist/layout/container.js +9 -12
- package/dist/layout/flex.js +1 -1
- package/dist/layout/grid.js +2 -2
- package/dist/layout/index.d.ts +1 -1
- package/dist/layout/index.js +1 -1
- package/dist/layout/stack.js +1 -1
- package/dist/layout/styles.d.ts +28 -7
- package/dist/layout/styles.js +76 -16
- package/dist/layout/surface.d.ts +2 -2
- package/dist/layout/surface.js +6 -3
- package/dist/legacyDatetime.d.ts +21 -0
- package/dist/legacyDatetime.js +13 -0
- package/dist/link/index.d.ts +1 -1
- package/dist/link/index.js +1 -1
- package/dist/link/linkBehaviorContext.d.ts +9 -0
- package/dist/link/linkBehaviorContext.js +37 -7
- package/dist/menu/menu.d.ts +1 -3
- package/dist/menu/menu.js +5 -6
- package/dist/menu/selectValue.d.ts +2 -6
- package/dist/modal/components.js +2 -2
- package/dist/overlayArrow.js +2 -2
- package/dist/relativeTime/getRelativeDate.d.ts +14 -0
- package/dist/relativeTime/getRelativeDate.js +107 -0
- package/dist/relativeTime/index.d.ts +3 -0
- package/dist/relativeTime/index.js +3 -0
- package/dist/relativeTime/relativeTime.d.ts +55 -0
- package/dist/relativeTime/relativeTime.js +102 -0
- package/dist/relativeTime/useRelativeTimeFormatter.d.ts +2 -0
- package/dist/relativeTime/useRelativeTimeFormatter.js +10 -0
- package/dist/select/chips.d.ts +14 -0
- package/dist/select/chips.js +45 -0
- package/dist/select/filter.js +7 -11
- package/dist/select/index.d.ts +1 -1
- package/dist/select/indicators.d.ts +11 -0
- package/dist/select/indicators.js +61 -0
- package/dist/select/menu.d.ts +44 -0
- package/dist/select/menu.js +103 -0
- package/dist/select/option.d.ts +23 -15
- package/dist/select/option.js +66 -58
- package/dist/select/options.d.ts +31 -0
- package/dist/select/options.js +74 -0
- package/dist/select/select.d.ts +24 -11
- package/dist/select/select.js +527 -429
- package/dist/select/styles.d.ts +148 -2
- package/dist/select/styles.js +156 -1
- package/dist/select/types.d.ts +6 -7
- package/dist/select/types.js +4 -0
- package/dist/select/utils.d.ts +2 -0
- package/dist/select/utils.js +4 -0
- package/dist/separator/separator.d.ts +2 -2
- package/dist/separator/separator.js +4 -3
- package/dist/slot/slot.js +16 -12
- package/dist/tabs/context.d.ts +9 -0
- package/dist/tabs/context.js +9 -0
- package/dist/tabs/index.d.ts +2 -4
- package/dist/tabs/index.js +1 -3
- package/dist/tabs/item.d.ts +16 -5
- package/dist/tabs/tab.js +9 -4
- package/dist/tabs/tabList.d.ts +5 -5
- package/dist/tabs/tabList.js +8 -6
- package/dist/tabs/tabPanels.d.ts +2 -3
- package/dist/tabs/tabPanels.js +1 -1
- package/dist/tabs/tabs.d.ts +46 -31
- package/dist/tabs/tabs.js +38 -35
- package/dist/text/prose.d.ts +2 -2
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/theme.d.ts +34 -34
- package/dist/theme/theme.js +9 -0
- package/dist/theme/types.d.ts +21 -2
- package/dist/theme/useResolvedTheme.d.ts +12 -0
- package/dist/theme/useResolvedTheme.js +20 -0
- package/dist/theme/variables.css +1116 -0
- package/dist/theme/variables.d.ts +985 -0
- package/dist/theme/variables.js +455 -0
- package/dist/translation/index.d.ts +1 -0
- package/dist/translation/index.js +1 -0
- package/dist/translation/translate.d.ts +9 -0
- package/dist/translation/translate.js +5 -0
- package/dist/translation/translationContext.d.ts +2 -1
- package/dist/translation/translationContext.js +2 -1
- package/dist/useVirtualCollection.d.ts +14 -1
- package/dist/useVirtualCollection.js +59 -3
- package/fonts/OFL.txt +94 -0
- package/fonts/roboto-mono-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-cyrillic.woff2 +0 -0
- package/fonts/roboto-mono-variable-greek.woff2 +0 -0
- package/fonts/roboto-mono-variable-latin-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-vietnamese.woff2 +0 -0
- package/fonts/roboto-mono-variable.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic.woff2 +0 -0
- package/fonts/rubik-variable-latin-ext.woff2 +0 -0
- package/fonts/rubik-variable.woff2 +0 -0
- package/fonts.css +211 -0
- package/package.json +39 -15
- package/dist/compactSelect/useVirtualizedItems.d.ts +0 -52
- package/dist/compactSelect/useVirtualizedItems.js +0 -74
- package/dist/datetime.d.ts +0 -39
- package/dist/datetime.js +0 -20
- package/dist/dropdownMenu/useSafetyTriangle.d.ts +0 -12
- package/dist/dropdownMenu/useSafetyTriangle.js +0 -119
- package/dist/select/reactSelectWrapper.d.ts +0 -8
- package/dist/select/reactSelectWrapper.js +0 -25
- package/dist/select/virtualizedMenuList.d.ts +0 -24
- package/dist/select/virtualizedMenuList.js +0 -123
|
@@ -1,56 +1,37 @@
|
|
|
1
1
|
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { Fragment, useMemo } from "react";
|
|
3
2
|
import { useListBoxSection } from "@react-aria/listbox";
|
|
4
|
-
import { useSeparator } from "@react-aria/separator";
|
|
5
3
|
import { SectionSeparator } from "../styles.js";
|
|
6
4
|
import { SectionToggle } from "../utils.js";
|
|
7
5
|
import { SectionGroup, SectionHeader, SectionLabel, SectionList } from "../../menu/index.js";
|
|
8
|
-
|
|
9
|
-
function ListBoxSection({ item, listState, size, hiddenOptions, showSectionHeaders, showDetails = true, ref, 'data-index': dataIndex }) {
|
|
6
|
+
function ListBoxSection({ children, item, listState, showSectionHeaders, showSeparator, rowProps }) {
|
|
10
7
|
const { itemProps, headingProps, groupProps } = useListBoxSection({
|
|
11
8
|
heading: item.rendered,
|
|
12
9
|
'aria-label': item['aria-label']
|
|
13
10
|
});
|
|
14
|
-
const { separatorProps } = useSeparator({
|
|
15
|
-
elementType: 'li'
|
|
16
|
-
});
|
|
17
11
|
const showToggleAllButton = 'multiple' === listState.selectionManager.selectionMode && item.value?.showToggleAllButton;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
].filter((child)=>!hiddenOptions.has(child.key)), [
|
|
21
|
-
item.childNodes,
|
|
22
|
-
hiddenOptions
|
|
23
|
-
]);
|
|
24
|
-
return /*#__PURE__*/ jsxs(Fragment, {
|
|
12
|
+
return /*#__PURE__*/ jsxs(SectionGroup, {
|
|
13
|
+
...itemProps,
|
|
25
14
|
children: [
|
|
26
|
-
|
|
27
|
-
...
|
|
28
|
-
}),
|
|
29
|
-
/*#__PURE__*/ jsxs(SectionGroup, {
|
|
30
|
-
...itemProps,
|
|
31
|
-
"data-index": dataIndex,
|
|
32
|
-
ref: ref,
|
|
15
|
+
/*#__PURE__*/ jsxs("div", {
|
|
16
|
+
...rowProps,
|
|
33
17
|
children: [
|
|
18
|
+
showSectionHeaders && showSeparator && /*#__PURE__*/ jsx(SectionSeparator, {}),
|
|
34
19
|
(item.rendered || showToggleAllButton) && showSectionHeaders && /*#__PURE__*/ jsx(SectionHeader, {
|
|
35
20
|
trailingAction: showToggleAllButton ? /*#__PURE__*/ jsx(SectionToggle, {
|
|
36
21
|
item: item,
|
|
37
22
|
listState: listState
|
|
38
23
|
}) : null,
|
|
39
24
|
children: item.rendered && /*#__PURE__*/ jsx(SectionLabel, {
|
|
25
|
+
size: "md",
|
|
40
26
|
...headingProps,
|
|
41
27
|
children: item.rendered
|
|
42
28
|
})
|
|
43
|
-
}),
|
|
44
|
-
/*#__PURE__*/ jsx(SectionList, {
|
|
45
|
-
...groupProps,
|
|
46
|
-
children: childItems.map((child)=>/*#__PURE__*/ jsx(ListBoxOption, {
|
|
47
|
-
item: child,
|
|
48
|
-
listState: listState,
|
|
49
|
-
size: size,
|
|
50
|
-
showDetails: showDetails
|
|
51
|
-
}, child.key))
|
|
52
29
|
})
|
|
53
30
|
]
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ jsx(SectionList, {
|
|
33
|
+
...groupProps,
|
|
34
|
+
children: children
|
|
54
35
|
})
|
|
55
36
|
]
|
|
56
37
|
});
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import type * as React from 'react';
|
|
2
1
|
import { type FlexProps } from '../layout/index.js';
|
|
3
2
|
export declare const ListWrap: import("@emotion/styled").StyledComponent<{
|
|
4
3
|
theme?: import("@emotion/react").Theme;
|
|
5
4
|
as?: React.ElementType;
|
|
6
|
-
},
|
|
5
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, {}>;
|
|
7
6
|
export declare const ListLabel: import("@emotion/styled").StyledComponent<{
|
|
8
7
|
theme?: import("@emotion/react").Theme;
|
|
9
8
|
as?: React.ElementType;
|
|
10
|
-
},
|
|
9
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
|
11
10
|
export declare const ListSeparator: import("@emotion/styled").StyledComponent<{
|
|
12
11
|
theme?: import("@emotion/react").Theme;
|
|
13
12
|
as?: React.ElementType;
|
|
14
|
-
},
|
|
13
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
15
14
|
export declare const SectionToggleButton: import("@emotion/styled").StyledComponent<(import("../button/index.js").ButtonProps & {
|
|
16
15
|
theme?: import("@emotion/react").Theme;
|
|
17
16
|
}) & {
|
|
18
17
|
visible: boolean;
|
|
19
18
|
}, {}, {}>;
|
|
20
|
-
export declare function SectionSeparator(
|
|
19
|
+
export declare function SectionSeparator(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
21
20
|
/**
|
|
22
21
|
* Left inset for CompactSelect options. CompactSelect puts its check column 4px
|
|
23
22
|
* closer to the menu edge than dropdown menus, in line with the title. The shared
|
|
@@ -32,8 +31,8 @@ export declare function LeadWrap(props: FlexProps): import("@emotion/react/jsx-r
|
|
|
32
31
|
export declare const EmptyMessage: import("@emotion/styled").StyledComponent<{
|
|
33
32
|
theme?: import("@emotion/react").Theme;
|
|
34
33
|
as?: React.ElementType;
|
|
35
|
-
},
|
|
34
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>, {}>;
|
|
36
35
|
export declare const SizeLimitMessage: import("@emotion/styled").StyledComponent<{
|
|
37
36
|
theme?: import("@emotion/react").Theme;
|
|
38
37
|
as?: React.ElementType;
|
|
39
|
-
},
|
|
38
|
+
}, import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, {}>;
|
|
@@ -8,10 +8,6 @@ const ListWrap = styled('ul')`
|
|
|
8
8
|
margin: 0;
|
|
9
9
|
padding: ${(p)=>p.theme.space.xs} 0;
|
|
10
10
|
|
|
11
|
-
> [data-section-separator]:first-of-type {
|
|
12
|
-
display: none;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
11
|
/* Add 1px to top padding if preceded by menu header, to account for the header's
|
|
16
12
|
shadow border */
|
|
17
13
|
[data-menu-has-header='true'] > div > &:first-of-type {
|
|
@@ -24,13 +20,6 @@ const ListWrap = styled('ul')`
|
|
|
24
20
|
padding-bottom: calc(${(p)=>p.theme.space.xs} + 1px);
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
/* Remove top padding if preceded by search input, since search input already has
|
|
28
|
-
vertical padding. Account for InputGroup wrapper div. */
|
|
29
|
-
div:has(input) ~ &&:first-of-type,
|
|
30
|
-
div:has(input) ~ div > &&:first-of-type {
|
|
31
|
-
padding-top: 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
23
|
&:empty {
|
|
35
24
|
padding: 0;
|
|
36
25
|
}
|
|
@@ -44,14 +33,6 @@ const ListWrap = styled('ul')`
|
|
|
44
33
|
:focus-visible {
|
|
45
34
|
outline: none;
|
|
46
35
|
}
|
|
47
|
-
|
|
48
|
-
/* The first section follows a hidden separator in a headerless menu. */
|
|
49
|
-
[data-menu-has-header='false']
|
|
50
|
-
&:first-of-type
|
|
51
|
-
li[role='presentation']:nth-of-type(2)
|
|
52
|
-
> [data-section-header] {
|
|
53
|
-
padding-top: 0;
|
|
54
|
-
}
|
|
55
36
|
`;
|
|
56
37
|
const ListLabel = styled('span')`
|
|
57
38
|
display: inline-block;
|
|
@@ -102,14 +83,11 @@ const SectionToggleButton = styled(Button)`
|
|
|
102
83
|
pointer-events: all;
|
|
103
84
|
}
|
|
104
85
|
`;
|
|
105
|
-
function styles_SectionSeparator(
|
|
86
|
+
function styles_SectionSeparator() {
|
|
106
87
|
return /*#__PURE__*/ jsx(Stack, {
|
|
107
|
-
as: "li",
|
|
108
|
-
"data-section-separator": true,
|
|
109
88
|
justify: "center",
|
|
110
89
|
height: "8px",
|
|
111
90
|
padding: "0 lg 0 xl",
|
|
112
|
-
...props,
|
|
113
91
|
role: "presentation",
|
|
114
92
|
children: /*#__PURE__*/ jsx(SectionSeparator, {})
|
|
115
93
|
});
|
|
@@ -4,7 +4,7 @@ import { useFocus, usePress } from "@react-aria/interactions";
|
|
|
4
4
|
import { mergeProps } from "@react-aria/utils";
|
|
5
5
|
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
6
6
|
import { useTranslation } from "../translation/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getSearchScore } from "../fzf.js";
|
|
8
8
|
import { SectionToggleButton } from "./styles.js";
|
|
9
9
|
function hasVisibleLeadingItems(listItems, hiddenOptions) {
|
|
10
10
|
return listItems.flatMap((node)=>'section' === node.type ? [
|
|
@@ -68,12 +68,8 @@ function defaultSearchMatcher(option, search) {
|
|
|
68
68
|
if (!text) return {
|
|
69
69
|
score: 0
|
|
70
70
|
};
|
|
71
|
-
const result = fzf(text, search.toLowerCase(), false);
|
|
72
|
-
if (-1 === result.end) return {
|
|
73
|
-
score: 0
|
|
74
|
-
};
|
|
75
71
|
return {
|
|
76
|
-
score:
|
|
72
|
+
score: getSearchScore(text, search)
|
|
77
73
|
};
|
|
78
74
|
}
|
|
79
75
|
function getHiddenOptions(items, search, limit = 1 / 0, searchMatcher) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Translation } from '../translation/translate.js';
|
|
2
|
+
export interface DateTimePreferences {
|
|
3
|
+
clock: '12' | '24';
|
|
4
|
+
timezone: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FormattingSnapshot extends DateTimePreferences {
|
|
7
|
+
locale: string;
|
|
8
|
+
messages: Translation;
|
|
9
|
+
/** Optional application label source. Returning undefined falls back to Intl. */
|
|
10
|
+
getTimezoneAbbreviation?: (epochMilliseconds: number, timezone: string, locale: string) => string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface FormattingSource {
|
|
13
|
+
getSnapshot: () => Readonly<FormattingSnapshot>;
|
|
14
|
+
subscribe: (onChange: () => void) => () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const formattingStore: {
|
|
17
|
+
getState: () => Readonly<FormattingSnapshot>;
|
|
18
|
+
getInitialState: () => Readonly<FormattingSnapshot>;
|
|
19
|
+
subscribe: (listener: (state: Readonly<FormattingSnapshot>, prevState: Readonly<FormattingSnapshot>) => void) => () => void;
|
|
20
|
+
};
|
|
21
|
+
/** Connect application preferences and locale to the reactive formatting store. */
|
|
22
|
+
export declare function configureFormatting(source: FormattingSource): () => void;
|
|
23
|
+
export declare const getSnapshot: () => Readonly<FormattingSnapshot>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createStore } from "zustand/vanilla";
|
|
2
|
+
const defaults = {
|
|
3
|
+
timezone: 'UTC',
|
|
4
|
+
clock: '12',
|
|
5
|
+
locale: 'en',
|
|
6
|
+
messages: {
|
|
7
|
+
t: (message, ...args)=>message.replace(/%s/g, ()=>{
|
|
8
|
+
const value = args.shift();
|
|
9
|
+
return 'string' == typeof value || 'number' == typeof value ? `${value}` : '%s';
|
|
10
|
+
}),
|
|
11
|
+
tn: (singular, plural, count)=>1 === Math.abs(count) ? singular : plural,
|
|
12
|
+
pgettext: (_context, message)=>message
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const store = createStore(()=>defaults);
|
|
16
|
+
const formattingStore = {
|
|
17
|
+
getState: store.getState,
|
|
18
|
+
getInitialState: store.getState,
|
|
19
|
+
subscribe: store.subscribe
|
|
20
|
+
};
|
|
21
|
+
function toIntlLocale(locale) {
|
|
22
|
+
try {
|
|
23
|
+
return Intl.getCanonicalLocales(locale.replaceAll('_', '-'))[0] ?? defaults.locale;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (error instanceof RangeError) return defaults.locale;
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function configureFormatting(source) {
|
|
30
|
+
const previous = store.getState();
|
|
31
|
+
let lastSnapshot;
|
|
32
|
+
const update = ()=>{
|
|
33
|
+
const snapshot = source.getSnapshot();
|
|
34
|
+
if (snapshot === lastSnapshot) return;
|
|
35
|
+
lastSnapshot = snapshot;
|
|
36
|
+
const locale = toIntlLocale(snapshot.locale);
|
|
37
|
+
store.setState(locale === snapshot.locale ? snapshot : {
|
|
38
|
+
...snapshot,
|
|
39
|
+
locale
|
|
40
|
+
}, true);
|
|
41
|
+
};
|
|
42
|
+
const unsubscribe = source.subscribe(update);
|
|
43
|
+
update();
|
|
44
|
+
return ()=>{
|
|
45
|
+
unsubscribe();
|
|
46
|
+
store.setState(previous, true);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const getSnapshot = store.getState;
|
|
50
|
+
export { configureFormatting, formattingStore, getSnapshot };
|
|
@@ -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,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 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Diagnostics {
|
|
2
|
+
captureException: (error: Error, context?: {
|
|
3
|
+
fingerprint?: string[];
|
|
4
|
+
level?: 'fatal' | 'error' | 'warning' | 'log' | 'info' | 'debug';
|
|
5
|
+
tags?: Record<string, string>;
|
|
6
|
+
}) => void;
|
|
7
|
+
logger: {
|
|
8
|
+
error: (message: string, attributes?: Record<string, boolean | number | string>) => void;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const DiagnosticsContextProvider: import("react").Provider<Diagnostics>;
|
|
12
|
+
export declare const useDiagnostics: () => Diagnostics;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const defaultDiagnostics = {
|
|
3
|
+
captureException: ()=>{},
|
|
4
|
+
logger: {
|
|
5
|
+
error: ()=>{}
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
const DiagnosticsContext = createContext(defaultDiagnostics);
|
|
9
|
+
const DiagnosticsContextProvider = DiagnosticsContext.Provider;
|
|
10
|
+
const useDiagnostics = ()=>useContext(DiagnosticsContext);
|
|
11
|
+
export { DiagnosticsContextProvider, useDiagnostics };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DiagnosticsContextProvider } from "./context.js";
|
|
@@ -128,7 +128,7 @@ function Content({ children, ...props }) {
|
|
|
128
128
|
if ('outline' === context.variant) return /*#__PURE__*/ jsx(Container, {
|
|
129
129
|
ref: panelRef,
|
|
130
130
|
...panelProps,
|
|
131
|
-
|
|
131
|
+
borderColor: "primary",
|
|
132
132
|
radius: OUTLINE_RADIUS[context.size],
|
|
133
133
|
padding: OUTLINE_PADDING[context.size],
|
|
134
134
|
width: "100%",
|
|
@@ -39,13 +39,11 @@ const DragHandleLine = styled('div')`
|
|
|
39
39
|
touch-action: none;
|
|
40
40
|
pointer-events: none;
|
|
41
41
|
|
|
42
|
-
/*
|
|
43
|
-
One below the drawer z-index: above pane content, but below global drawers, which render
|
|
44
|
-
before the app in the DOM and so lose a z-index tie. */
|
|
42
|
+
/* Keep the hit area and highlight above pane content and below dropdowns and drawers. */
|
|
45
43
|
&::before {
|
|
46
44
|
content: '';
|
|
47
45
|
position: absolute;
|
|
48
|
-
z-index: ${(p)=>p.theme.zIndex.
|
|
46
|
+
z-index: ${(p)=>p.theme.zIndex.dropdown - 1};
|
|
49
47
|
pointer-events: auto;
|
|
50
48
|
cursor: ${(p)=>p.$cursor};
|
|
51
49
|
}
|
|
@@ -54,7 +52,7 @@ const DragHandleLine = styled('div')`
|
|
|
54
52
|
&::after {
|
|
55
53
|
content: '';
|
|
56
54
|
position: absolute;
|
|
57
|
-
z-index: ${(p)=>p.theme.zIndex.
|
|
55
|
+
z-index: ${(p)=>p.theme.zIndex.dropdown - 1};
|
|
58
56
|
opacity: 0.8;
|
|
59
57
|
background: transparent;
|
|
60
58
|
transition: background ${(p)=>p.theme.motion.smooth.slow};
|
|
@@ -1,24 +1,49 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { RootMenuTriggerState } from '@react-stately/menu';
|
|
1
3
|
import type { TreeState } from '@react-stately/tree';
|
|
2
|
-
import type { useOverlay } from '../useOverlay.js';
|
|
3
4
|
import type { MenuItemProps } from './item.js';
|
|
4
|
-
import type { useSafetyTriangle } from './useSafetyTriangle.js';
|
|
5
|
-
export type OverlayState = ReturnType<typeof useOverlay>['state'];
|
|
6
5
|
interface DropdownMenuContextValue {
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* `isDismissable` of the root menu. Dismissing a submenu closes the root menu,
|
|
8
|
+
* so submenus follow it.
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
isDismissable?: boolean;
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Ref to the menu element (the `ul` with `role="menu"`) that renders the
|
|
13
|
+
* current items. Submenu triggers pass it to `useSubmenuTrigger` as their
|
|
14
|
+
* parent menu.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
parentMenuRef?: React.RefObject<HTMLElement | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Element that submenus are portaled into. Submenus render outside their
|
|
19
|
+
* parent menu element, so focus moving into a submenu is not mistaken for
|
|
20
|
+
* focus moving to another item of the parent menu, but they stay inside the
|
|
21
|
+
* root overlay, so the root menu does not close on blur.
|
|
22
|
+
*/
|
|
23
|
+
portalContainer?: HTMLElement | null;
|
|
24
|
+
/**
|
|
25
|
+
* Menu trigger state (from react-stately's `useMenuTriggerState` shape) for
|
|
26
|
+
* the root (top-most) menu. Tracks which submenus are open, and closes the
|
|
27
|
+
* entire menu system.
|
|
28
|
+
*/
|
|
29
|
+
rootMenuState?: RootMenuTriggerState;
|
|
30
|
+
/**
|
|
31
|
+
* Level of the submenus opened from the current menu's items: 0 in the root
|
|
32
|
+
* menu, 1 in its submenus, and so on.
|
|
33
|
+
*/
|
|
34
|
+
submenuLevel?: number;
|
|
18
35
|
/**
|
|
19
36
|
* `virtualizeThreshold` of the parent menu, inherited by its submenus.
|
|
20
37
|
*/
|
|
21
38
|
virtualizeThreshold?: number;
|
|
22
39
|
}
|
|
23
|
-
export declare const DropdownMenuContext:
|
|
40
|
+
export declare const DropdownMenuContext: React.Context<DropdownMenuContextValue>;
|
|
41
|
+
/**
|
|
42
|
+
* Tree state of the menu that renders the current items. Items read it from
|
|
43
|
+
* context rather than props: React Aria returns a new state on every render,
|
|
44
|
+
* and as a prop it would re-render every component between the list and its
|
|
45
|
+
* items, including a submenu trigger's open submenu. Through context, only the
|
|
46
|
+
* items that read it re-render.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DropdownMenuTreeStateContext: React.Context<TreeState<MenuItemProps>>;
|
|
24
49
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { createContext } from "react";
|
|
2
2
|
const DropdownMenuContext = /*#__PURE__*/ createContext({});
|
|
3
|
-
|
|
3
|
+
const DropdownMenuTreeStateContext = /*#__PURE__*/ createContext(null);
|
|
4
|
+
export { DropdownMenuContext, DropdownMenuTreeStateContext };
|