@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.
- package/README.md +68 -3
- 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/control.js +3 -2
- 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/dropdownMenu/context.d.ts +28 -13
- package/dist/dropdownMenu/dropdownMenu.d.ts +2 -2
- package/dist/dropdownMenu/dropdownMenu.js +9 -3
- package/dist/dropdownMenu/item.d.ts +6 -2
- package/dist/dropdownMenu/item.js +31 -71
- package/dist/dropdownMenu/list.d.ts +31 -5
- package/dist/dropdownMenu/list.js +143 -124
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +5 -241
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +5 -29
- 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/{compactSelect/fzf.d.ts → fzf.d.ts} +1 -0
- package/dist/{compactSelect/fzf.js → fzf.js} +5 -1
- package/dist/layout/container.d.ts +8 -2
- package/dist/layout/container.js +2 -2
- package/dist/layout/styles.d.ts +2 -1
- package/dist/layout/styles.js +11 -5
- 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 +4 -5
- 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/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 +6 -3
- 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/theme.d.ts +34 -34
- package/dist/theme/theme.js +9 -0
- package/dist/theme/types.d.ts +20 -2
- 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/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 +30 -12
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
2
|
import type { useMenu } from '@react-aria/menu';
|
|
3
3
|
import type { TreeState } from '@react-stately/tree';
|
|
4
|
-
import type { Key
|
|
4
|
+
import type { Key } from '@react-types/shared';
|
|
5
5
|
import type { MenuItemProps } from './item.js';
|
|
6
6
|
interface UseDropdownMenuKeyboardOptions {
|
|
7
7
|
/** The keys keyboard focus can reach, in order. */
|
|
@@ -11,250 +11,14 @@ interface UseDropdownMenuKeyboardOptions {
|
|
|
11
11
|
menuRef: React.RefObject<HTMLUListElement | null>;
|
|
12
12
|
searchRef: React.RefObject<HTMLInputElement | null>;
|
|
13
13
|
state: TreeState<MenuItemProps>;
|
|
14
|
-
/** Top-level nodes of the menu, in order. */
|
|
15
|
-
stateCollection: Array<Node<MenuItemProps>>;
|
|
16
|
-
/** Menu state of the parent menu, if this menu is a submenu. */
|
|
17
|
-
parentMenuState?: TreeState<MenuItemProps>;
|
|
18
14
|
}
|
|
19
15
|
/**
|
|
20
16
|
* Keyboard navigation of a menu: moves focus between the search field and the
|
|
21
|
-
* items
|
|
22
|
-
*
|
|
17
|
+
* items. Opening and closing submenus with the arrow keys is handled by
|
|
18
|
+
* `useSubmenuTrigger`.
|
|
23
19
|
*/
|
|
24
|
-
export declare function useDropdownMenuKeyboard({ focusableKeys, menuProps, menuRef,
|
|
20
|
+
export declare function useDropdownMenuKeyboard({ focusableKeys, menuProps, menuRef, searchRef, state, }: UseDropdownMenuKeyboardOptions): {
|
|
25
21
|
focusItem: (key: Key | undefined) => void;
|
|
26
|
-
|
|
27
|
-
menuProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & {
|
|
28
|
-
onKeyUp?: React.KeyboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
29
|
-
onKeyDown?: React.KeyboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
30
|
-
id?: string | undefined;
|
|
31
|
-
role?: React.AriaRole | undefined;
|
|
32
|
-
tabIndex?: number | undefined;
|
|
33
|
-
style?: React.CSSProperties | undefined;
|
|
34
|
-
className?: string | undefined;
|
|
35
|
-
"aria-activedescendant"?: string | undefined;
|
|
36
|
-
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
37
|
-
"aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined;
|
|
38
|
-
"aria-braillelabel"?: string | undefined;
|
|
39
|
-
"aria-brailleroledescription"?: string | undefined;
|
|
40
|
-
"aria-busy"?: (boolean | "true" | "false") | undefined;
|
|
41
|
-
"aria-checked"?: boolean | "false" | "mixed" | "true" | undefined;
|
|
42
|
-
"aria-colcount"?: number | undefined;
|
|
43
|
-
"aria-colindex"?: number | undefined;
|
|
44
|
-
"aria-colindextext"?: string | undefined;
|
|
45
|
-
"aria-colspan"?: number | undefined;
|
|
46
|
-
"aria-controls"?: string | undefined;
|
|
47
|
-
"aria-current"?: boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time" | undefined;
|
|
48
|
-
"aria-describedby"?: string | undefined;
|
|
49
|
-
"aria-description"?: string | undefined;
|
|
50
|
-
"aria-details"?: string | undefined;
|
|
51
|
-
"aria-disabled"?: (boolean | "true" | "false") | undefined;
|
|
52
|
-
"aria-dropeffect"?: "none" | "copy" | "execute" | "link" | "move" | "popup" | undefined;
|
|
53
|
-
"aria-errormessage"?: string | undefined;
|
|
54
|
-
"aria-expanded"?: (boolean | "true" | "false") | undefined;
|
|
55
|
-
"aria-flowto"?: string | undefined;
|
|
56
|
-
"aria-grabbed"?: (boolean | "true" | "false") | undefined;
|
|
57
|
-
"aria-haspopup"?: boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined;
|
|
58
|
-
"aria-hidden"?: (boolean | "true" | "false") | undefined;
|
|
59
|
-
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling" | undefined;
|
|
60
|
-
"aria-keyshortcuts"?: string | undefined;
|
|
61
|
-
"aria-label"?: string | undefined;
|
|
62
|
-
"aria-labelledby"?: string | undefined;
|
|
63
|
-
"aria-level"?: number | undefined;
|
|
64
|
-
"aria-live"?: "off" | "assertive" | "polite" | undefined;
|
|
65
|
-
"aria-modal"?: (boolean | "true" | "false") | undefined;
|
|
66
|
-
"aria-multiline"?: (boolean | "true" | "false") | undefined;
|
|
67
|
-
"aria-multiselectable"?: (boolean | "true" | "false") | undefined;
|
|
68
|
-
"aria-orientation"?: "horizontal" | "vertical" | undefined;
|
|
69
|
-
"aria-owns"?: string | undefined;
|
|
70
|
-
"aria-placeholder"?: string | undefined;
|
|
71
|
-
"aria-posinset"?: number | undefined;
|
|
72
|
-
"aria-pressed"?: boolean | "false" | "mixed" | "true" | undefined;
|
|
73
|
-
"aria-readonly"?: (boolean | "true" | "false") | undefined;
|
|
74
|
-
"aria-relevant"?: "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text" | "text additions" | "text removals" | undefined;
|
|
75
|
-
"aria-required"?: (boolean | "true" | "false") | undefined;
|
|
76
|
-
"aria-roledescription"?: string | undefined;
|
|
77
|
-
"aria-rowcount"?: number | undefined;
|
|
78
|
-
"aria-rowindex"?: number | undefined;
|
|
79
|
-
"aria-rowindextext"?: string | undefined;
|
|
80
|
-
"aria-rowspan"?: number | undefined;
|
|
81
|
-
"aria-selected"?: (boolean | "true" | "false") | undefined;
|
|
82
|
-
"aria-setsize"?: number | undefined;
|
|
83
|
-
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined;
|
|
84
|
-
"aria-valuemax"?: number | undefined;
|
|
85
|
-
"aria-valuemin"?: number | undefined;
|
|
86
|
-
"aria-valuenow"?: number | undefined;
|
|
87
|
-
"aria-valuetext"?: string | undefined;
|
|
88
|
-
children?: React.ReactNode | undefined;
|
|
89
|
-
dangerouslySetInnerHTML?: {
|
|
90
|
-
__html: string | TrustedHTML;
|
|
91
|
-
} | undefined;
|
|
92
|
-
onCopy?: React.ClipboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
93
|
-
onCopyCapture?: React.ClipboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
94
|
-
onCut?: React.ClipboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
95
|
-
onCutCapture?: React.ClipboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
96
|
-
onPaste?: React.ClipboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
97
|
-
onPasteCapture?: React.ClipboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
98
|
-
onCompositionEnd?: React.CompositionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
99
|
-
onCompositionEndCapture?: React.CompositionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
100
|
-
onCompositionStart?: React.CompositionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
101
|
-
onCompositionStartCapture?: React.CompositionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
102
|
-
onCompositionUpdate?: React.CompositionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
103
|
-
onCompositionUpdateCapture?: React.CompositionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
104
|
-
onFocus?: React.FocusEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
105
|
-
onFocusCapture?: React.FocusEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
106
|
-
onBlur?: React.FocusEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
107
|
-
onBlurCapture?: React.FocusEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
108
|
-
onChange?: React.ChangeEventHandler<import("@react-types/shared").FocusableElement, Element> | undefined;
|
|
109
|
-
onChangeCapture?: React.ChangeEventHandler<import("@react-types/shared").FocusableElement, Element> | undefined;
|
|
110
|
-
onBeforeInput?: React.InputEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
111
|
-
onBeforeInputCapture?: React.InputEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
112
|
-
onInput?: React.InputEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
113
|
-
onInputCapture?: React.InputEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
114
|
-
onReset?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
115
|
-
onResetCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
116
|
-
onSubmit?: React.SubmitEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
117
|
-
onSubmitCapture?: React.SubmitEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
118
|
-
onInvalid?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
119
|
-
onInvalidCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
120
|
-
onLoad?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
121
|
-
onLoadCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
122
|
-
onError?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
123
|
-
onErrorCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
124
|
-
onKeyDownCapture?: React.KeyboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
125
|
-
onKeyPress?: React.KeyboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
126
|
-
onKeyPressCapture?: React.KeyboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
127
|
-
onKeyUpCapture?: React.KeyboardEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
128
|
-
onAbort?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
129
|
-
onAbortCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
130
|
-
onCanPlay?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
131
|
-
onCanPlayCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
132
|
-
onCanPlayThrough?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
133
|
-
onCanPlayThroughCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
134
|
-
onDurationChange?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
135
|
-
onDurationChangeCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
136
|
-
onEmptied?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
137
|
-
onEmptiedCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
138
|
-
onEncrypted?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
139
|
-
onEncryptedCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
140
|
-
onEnded?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
141
|
-
onEndedCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
142
|
-
onLoadedData?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
143
|
-
onLoadedDataCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
144
|
-
onLoadedMetadata?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
145
|
-
onLoadedMetadataCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
146
|
-
onLoadStart?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
147
|
-
onLoadStartCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
148
|
-
onPause?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
149
|
-
onPauseCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
150
|
-
onPlay?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
151
|
-
onPlayCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
152
|
-
onPlaying?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
153
|
-
onPlayingCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
154
|
-
onProgress?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
155
|
-
onProgressCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
156
|
-
onRateChange?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
157
|
-
onRateChangeCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
158
|
-
onSeeked?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
159
|
-
onSeekedCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
160
|
-
onSeeking?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
161
|
-
onSeekingCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
162
|
-
onStalled?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
163
|
-
onStalledCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
164
|
-
onSuspend?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
165
|
-
onSuspendCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
166
|
-
onTimeUpdate?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
167
|
-
onTimeUpdateCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
168
|
-
onVolumeChange?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
169
|
-
onVolumeChangeCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
170
|
-
onWaiting?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
171
|
-
onWaitingCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
172
|
-
onAuxClick?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
173
|
-
onAuxClickCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
174
|
-
onClick?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
175
|
-
onClickCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
176
|
-
onContextMenu?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
177
|
-
onContextMenuCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
178
|
-
onDoubleClick?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
179
|
-
onDoubleClickCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
180
|
-
onDrag?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
181
|
-
onDragCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
182
|
-
onDragEnd?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
183
|
-
onDragEndCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
184
|
-
onDragEnter?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
185
|
-
onDragEnterCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
186
|
-
onDragExit?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
187
|
-
onDragExitCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
188
|
-
onDragLeave?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
189
|
-
onDragLeaveCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
190
|
-
onDragOver?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
191
|
-
onDragOverCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
192
|
-
onDragStart?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
193
|
-
onDragStartCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
194
|
-
onDrop?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
195
|
-
onDropCapture?: React.DragEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
196
|
-
onMouseDown?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
197
|
-
onMouseDownCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
198
|
-
onMouseEnter?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
199
|
-
onMouseLeave?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
200
|
-
onMouseMove?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
201
|
-
onMouseMoveCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
202
|
-
onMouseOut?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
203
|
-
onMouseOutCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
204
|
-
onMouseOver?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
205
|
-
onMouseOverCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
206
|
-
onMouseUp?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
207
|
-
onMouseUpCapture?: React.MouseEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
208
|
-
onSelect?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
209
|
-
onSelectCapture?: React.ReactEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
210
|
-
onTouchCancel?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
211
|
-
onTouchCancelCapture?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
212
|
-
onTouchEnd?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
213
|
-
onTouchEndCapture?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
214
|
-
onTouchMove?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
215
|
-
onTouchMoveCapture?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
216
|
-
onTouchStart?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
217
|
-
onTouchStartCapture?: React.TouchEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
218
|
-
onPointerDown?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
219
|
-
onPointerDownCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
220
|
-
onPointerMove?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
221
|
-
onPointerMoveCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
222
|
-
onPointerUp?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
223
|
-
onPointerUpCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
224
|
-
onPointerCancel?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
225
|
-
onPointerCancelCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
226
|
-
onPointerEnter?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
227
|
-
onPointerLeave?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
228
|
-
onPointerOver?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
229
|
-
onPointerOverCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
230
|
-
onPointerOut?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
231
|
-
onPointerOutCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
232
|
-
onGotPointerCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
233
|
-
onGotPointerCaptureCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
234
|
-
onLostPointerCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
235
|
-
onLostPointerCaptureCapture?: React.PointerEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
236
|
-
onScroll?: React.UIEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
237
|
-
onScrollCapture?: React.UIEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
238
|
-
onScrollEnd?: React.UIEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
239
|
-
onScrollEndCapture?: React.UIEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
240
|
-
onWheel?: React.WheelEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
241
|
-
onWheelCapture?: React.WheelEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
242
|
-
onAnimationStart?: React.AnimationEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
243
|
-
onAnimationStartCapture?: React.AnimationEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
244
|
-
onAnimationEnd?: React.AnimationEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
245
|
-
onAnimationEndCapture?: React.AnimationEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
246
|
-
onAnimationIteration?: React.AnimationEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
247
|
-
onAnimationIterationCapture?: React.AnimationEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
248
|
-
onToggle?: React.ToggleEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
249
|
-
onBeforeToggle?: React.ToggleEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
250
|
-
onTransitionCancel?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
251
|
-
onTransitionCancelCapture?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
252
|
-
onTransitionEnd?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
253
|
-
onTransitionEndCapture?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
254
|
-
onTransitionRun?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
255
|
-
onTransitionRunCapture?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
256
|
-
onTransitionStart?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
257
|
-
onTransitionStartCapture?: React.TransitionEventHandler<import("@react-types/shared").FocusableElement> | undefined;
|
|
258
|
-
};
|
|
22
|
+
menuProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement>;
|
|
259
23
|
};
|
|
260
24
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
1
|
import { useKeyboard } from "@react-aria/interactions";
|
|
3
2
|
import { mergeProps } from "@react-aria/utils";
|
|
4
3
|
import { getMenuItemKey } from "./utils.js";
|
|
5
|
-
function useDropdownMenuKeyboard({ focusableKeys, menuProps, menuRef,
|
|
4
|
+
function useDropdownMenuKeyboard({ focusableKeys, menuProps, menuRef, searchRef, state }) {
|
|
6
5
|
const focusItem = (key)=>{
|
|
7
6
|
if (void 0 === key) return;
|
|
8
7
|
const element = menuRef.current?.querySelector(`[data-key="${CSS.escape(String(key))}"]`);
|
|
@@ -12,44 +11,21 @@ function useDropdownMenuKeyboard({ focusableKeys, menuProps, menuRef, parentMenu
|
|
|
12
11
|
};
|
|
13
12
|
const { keyboardProps } = useKeyboard({
|
|
14
13
|
onKeyDown: (e)=>{
|
|
14
|
+
if (!menuRef.current?.contains(e.target)) return void e.continuePropagation();
|
|
15
15
|
const targetKey = getMenuItemKey(e.target);
|
|
16
|
-
if ('ArrowDown' === e.key && searchRef.current &&
|
|
17
|
-
if ('ArrowUp' === e.key && searchRef.current &&
|
|
16
|
+
if ('ArrowDown' === e.key && searchRef.current && void 0 !== targetKey && targetKey === focusableKeys.at(-1)) menuRef.current.scrollTop = 0;
|
|
17
|
+
if ('ArrowUp' === e.key && searchRef.current && void 0 !== targetKey && targetKey === focusableKeys[0]) {
|
|
18
18
|
e.preventDefault();
|
|
19
19
|
menuRef.current.scrollTop = 0;
|
|
20
20
|
searchRef.current.focus();
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
if ('ArrowLeft' === e.key && parentMenuState) return void parentMenuState.selectionManager.clearSelection();
|
|
24
23
|
e.continuePropagation();
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
|
-
const hasFocus = useMemo(()=>{
|
|
28
|
-
const isLeafSubmenu = !stateCollection.some((node)=>{
|
|
29
|
-
const isSection = node.hasChildNodes && !node.value?.submenu;
|
|
30
|
-
return isSection ? [
|
|
31
|
-
...node.childNodes
|
|
32
|
-
].some((child)=>state.selectionManager.isSelected(`${child.key}`)) : state.selectionManager.isSelected(`${node.key}`);
|
|
33
|
-
});
|
|
34
|
-
return isLeafSubmenu;
|
|
35
|
-
}, [
|
|
36
|
-
stateCollection,
|
|
37
|
-
state.selectionManager
|
|
38
|
-
]);
|
|
39
|
-
const modifiedMenuProps = useMemo(()=>({
|
|
40
|
-
...menuProps,
|
|
41
|
-
...!hasFocus && {
|
|
42
|
-
onKeyUp: ()=>null,
|
|
43
|
-
onKeyDown: ()=>null
|
|
44
|
-
}
|
|
45
|
-
}), [
|
|
46
|
-
menuProps,
|
|
47
|
-
hasFocus
|
|
48
|
-
]);
|
|
49
26
|
return {
|
|
50
27
|
focusItem,
|
|
51
|
-
|
|
52
|
-
menuProps: mergeProps(modifiedMenuProps, keyboardProps)
|
|
28
|
+
menuProps: mergeProps(menuProps, keyboardProps)
|
|
53
29
|
};
|
|
54
30
|
}
|
|
55
31
|
export { useDropdownMenuKeyboard };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RootMenuTriggerState } from '@react-stately/menu';
|
|
2
|
+
import type { OverlayTriggerState } from '@react-stately/overlays';
|
|
3
|
+
/**
|
|
4
|
+
* State for the root menu, matching react-stately's `useMenuTriggerState`.
|
|
5
|
+
*
|
|
6
|
+
* `useOverlay` keeps owning the open state and positioning, so this wraps its
|
|
7
|
+
* overlay state instead of creating another one, and adds the stack of open
|
|
8
|
+
* submenus that `useSubmenuTrigger` reads.
|
|
9
|
+
*
|
|
10
|
+
* A root menu rendered inside another menu starts its own tree, but closing
|
|
11
|
+
* it, for example by selecting one of its items, also closes the outer menu.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useDropdownRootMenuState(overlayState: OverlayTriggerState, parentMenuState?: RootMenuTriggerState): RootMenuTriggerState;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
function useDropdownRootMenuState(overlayState, parentMenuState) {
|
|
3
|
+
const [expandedKeysStack, setExpandedKeysStack] = useState([]);
|
|
4
|
+
const [wasOpen, setWasOpen] = useState(overlayState.isOpen);
|
|
5
|
+
if (wasOpen !== overlayState.isOpen) {
|
|
6
|
+
setWasOpen(overlayState.isOpen);
|
|
7
|
+
if (!overlayState.isOpen) setExpandedKeysStack([]);
|
|
8
|
+
}
|
|
9
|
+
const { isOpen, setOpen, open, close, toggle } = overlayState;
|
|
10
|
+
const closeParentMenu = parentMenuState?.close;
|
|
11
|
+
return {
|
|
12
|
+
isOpen,
|
|
13
|
+
setOpen,
|
|
14
|
+
focusStrategy: 'first',
|
|
15
|
+
open: ()=>open(),
|
|
16
|
+
toggle: ()=>toggle(),
|
|
17
|
+
close: ()=>{
|
|
18
|
+
setExpandedKeysStack([]);
|
|
19
|
+
close();
|
|
20
|
+
closeParentMenu?.();
|
|
21
|
+
},
|
|
22
|
+
expandedKeysStack,
|
|
23
|
+
openSubmenu: (triggerKey, level)=>setExpandedKeysStack((stack)=>level > stack.length ? stack : [
|
|
24
|
+
...stack.slice(0, level),
|
|
25
|
+
triggerKey
|
|
26
|
+
]),
|
|
27
|
+
closeSubmenu: (triggerKey, level)=>setExpandedKeysStack((stack)=>stack[level] === triggerKey ? stack.slice(0, level) : stack)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { useDropdownRootMenuState };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RootMenuTriggerState, SubmenuTriggerState } from '@react-stately/menu';
|
|
2
|
+
import type { Key } from '@react-types/shared';
|
|
3
|
+
interface UseDropdownSubmenuStateOptions {
|
|
4
|
+
/** How deep the submenu sits in the menu tree, starting at 0. */
|
|
5
|
+
level: number;
|
|
6
|
+
rootMenuState: RootMenuTriggerState;
|
|
7
|
+
/** Key of the item that opens the submenu. */
|
|
8
|
+
triggerKey: Key;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* State for a submenu trigger, matching react-stately's `useSubmenuTriggerState`.
|
|
12
|
+
*
|
|
13
|
+
* react-stately takes the submenu level from the number of open submenus when
|
|
14
|
+
* the trigger mounts. A virtualized menu mounts triggers as they scroll into
|
|
15
|
+
* view, possibly while a sibling submenu is open, which would place the
|
|
16
|
+
* trigger one level too deep. The level comes from the menu tree instead.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useDropdownSubmenuState({ level, rootMenuState, triggerKey, }: UseDropdownSubmenuStateOptions): SubmenuTriggerState;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
function useDropdownSubmenuState({ level, rootMenuState, triggerKey }) {
|
|
3
|
+
const { expandedKeysStack, openSubmenu, closeSubmenu, close: closeAll } = rootMenuState;
|
|
4
|
+
const isOpen = expandedKeysStack[level] === triggerKey;
|
|
5
|
+
const [focusStrategy, setFocusStrategy] = useState(null);
|
|
6
|
+
const open = (strategy)=>{
|
|
7
|
+
setFocusStrategy(strategy ?? null);
|
|
8
|
+
openSubmenu(triggerKey, level);
|
|
9
|
+
};
|
|
10
|
+
const close = ()=>{
|
|
11
|
+
setFocusStrategy(null);
|
|
12
|
+
closeSubmenu(triggerKey, level);
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
focusStrategy,
|
|
16
|
+
isOpen,
|
|
17
|
+
open,
|
|
18
|
+
close,
|
|
19
|
+
closeAll,
|
|
20
|
+
submenuLevel: level,
|
|
21
|
+
setOpen: ()=>{},
|
|
22
|
+
toggle: (strategy)=>isOpen ? close() : open(strategy)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { useDropdownSubmenuState };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getSearchScore } from "../fzf.js";
|
|
1
2
|
function removeHiddenItemsAndSetHref(source, resolveHref) {
|
|
2
3
|
return source.filter((item)=>!item.hidden).map((item)=>{
|
|
3
4
|
const href = item.to ? resolveHref(item.to) : item.externalHref;
|
|
@@ -12,15 +13,11 @@ function removeHiddenItemsAndSetHref(source, resolveHref) {
|
|
|
12
13
|
};
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
function isMenuItemHidden(search, label, textValue) {
|
|
16
|
-
const text = textValue ?? ('string' == typeof label ? label : '');
|
|
17
|
-
return Boolean(search && !text.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()));
|
|
18
|
-
}
|
|
19
16
|
function isMenuSection(item) {
|
|
20
17
|
return Boolean(item.children && item.children.length > 0 && !item.submenu);
|
|
21
18
|
}
|
|
22
19
|
function filterMenuItems(items, search) {
|
|
23
|
-
const query = search.trim()
|
|
20
|
+
const query = search.trim();
|
|
24
21
|
if (!query) return items;
|
|
25
22
|
return items.flatMap((item)=>{
|
|
26
23
|
if (item.children && !item.submenu) {
|
|
@@ -32,9 +29,10 @@ function filterMenuItems(items, search) {
|
|
|
32
29
|
}
|
|
33
30
|
] : [];
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
const text = item.textValue ?? ('string' == typeof item.label ? item.label : '');
|
|
33
|
+
return getSearchScore(text, query) > 0 ? [
|
|
36
34
|
item
|
|
37
|
-
];
|
|
35
|
+
] : [];
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
38
|
function countMenuItems(items) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function formatElapsedDuration(ms) {
|
|
2
|
+
const tenths = Math.floor(ms / 100);
|
|
3
|
+
if (tenths < 600) return `${(tenths / 10).toFixed(1)}s`;
|
|
4
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
5
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
6
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
7
|
+
const seconds = totalSeconds % 60;
|
|
8
|
+
return hours > 0 ? `${hours}h ${minutes}m ${seconds}s` : `${minutes}m ${seconds}s`;
|
|
9
|
+
}
|
|
10
|
+
export { formatElapsedDuration };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Translation } from '../translation/translate.js';
|
|
2
|
+
export interface DurationOptions {
|
|
3
|
+
absolute?: boolean;
|
|
4
|
+
/** Smallest display unit. Defaults to milliseconds. */
|
|
5
|
+
minimumUnit?: DurationUnit;
|
|
6
|
+
precision?: number;
|
|
7
|
+
style?: 'long' | 'short' | 'narrow';
|
|
8
|
+
}
|
|
9
|
+
declare const units: readonly [{
|
|
10
|
+
readonly unit: "year";
|
|
11
|
+
readonly size: 31536000000;
|
|
12
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
13
|
+
readonly short: ({ t }: Translation) => string;
|
|
14
|
+
readonly narrow: ({ t }: Translation) => string;
|
|
15
|
+
}, {
|
|
16
|
+
readonly unit: "month";
|
|
17
|
+
readonly size: 2629800000;
|
|
18
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
19
|
+
readonly short: ({ t }: Translation) => string;
|
|
20
|
+
readonly narrow: ({ pgettext }: Translation) => string;
|
|
21
|
+
}, {
|
|
22
|
+
readonly unit: "week";
|
|
23
|
+
readonly size: 604800000;
|
|
24
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
25
|
+
readonly short: ({ t }: Translation) => string;
|
|
26
|
+
readonly narrow: ({ t }: Translation) => string;
|
|
27
|
+
}, {
|
|
28
|
+
readonly unit: "day";
|
|
29
|
+
readonly size: 86400000;
|
|
30
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
31
|
+
readonly short: ({ t }: Translation) => string;
|
|
32
|
+
readonly narrow: ({ t }: Translation) => string;
|
|
33
|
+
}, {
|
|
34
|
+
readonly unit: "hour";
|
|
35
|
+
readonly size: 3600000;
|
|
36
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
37
|
+
readonly short: ({ t }: Translation) => string;
|
|
38
|
+
readonly narrow: ({ t }: Translation) => string;
|
|
39
|
+
}, {
|
|
40
|
+
readonly unit: "minute";
|
|
41
|
+
readonly size: 60000;
|
|
42
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
43
|
+
readonly short: ({ t }: Translation) => string;
|
|
44
|
+
readonly narrow: ({ pgettext }: Translation) => string;
|
|
45
|
+
}, {
|
|
46
|
+
readonly unit: "second";
|
|
47
|
+
readonly size: 1000;
|
|
48
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
49
|
+
readonly short: ({ t }: Translation) => string;
|
|
50
|
+
readonly narrow: ({ t }: Translation) => string;
|
|
51
|
+
}, {
|
|
52
|
+
readonly unit: "millisecond";
|
|
53
|
+
readonly size: 1;
|
|
54
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
55
|
+
readonly short: ({ t }: Translation) => string;
|
|
56
|
+
readonly narrow: ({ t }: Translation) => string;
|
|
57
|
+
}, {
|
|
58
|
+
readonly unit: "microsecond";
|
|
59
|
+
readonly size: 0.001;
|
|
60
|
+
readonly long: (count: number, { tn }: Translation) => string;
|
|
61
|
+
readonly short: () => string;
|
|
62
|
+
readonly narrow: () => string;
|
|
63
|
+
}];
|
|
64
|
+
export type DurationUnit = (typeof units)[number]['unit'];
|
|
65
|
+
/** Format seconds using the shared application translations. */
|
|
66
|
+
export declare function getDuration(seconds: number, options?: DurationOptions): string;
|
|
67
|
+
export declare function getDurationWithMessages(seconds: number, { precision, style, absolute, minimumUnit, }: DurationOptions, messages: Translation): string;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getSnapshot } from "../dateTime/config.js";
|
|
2
|
+
const units = [
|
|
3
|
+
{
|
|
4
|
+
unit: 'year',
|
|
5
|
+
size: 31536000000,
|
|
6
|
+
long: (count, { tn })=>tn('year', 'years', count),
|
|
7
|
+
short: ({ t })=>t('yr'),
|
|
8
|
+
narrow: ({ t })=>t('y')
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
unit: 'month',
|
|
12
|
+
size: 2629800000,
|
|
13
|
+
long: (count, { tn })=>tn('month', 'months', count),
|
|
14
|
+
short: ({ t })=>t('mo'),
|
|
15
|
+
narrow: ({ pgettext })=>pgettext('abbreviated months', 'm')
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
unit: 'week',
|
|
19
|
+
size: 604800000,
|
|
20
|
+
long: (count, { tn })=>tn('week', 'weeks', count),
|
|
21
|
+
short: ({ t })=>t('wk'),
|
|
22
|
+
narrow: ({ t })=>t('w')
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
unit: 'day',
|
|
26
|
+
size: 86400000,
|
|
27
|
+
long: (count, { tn })=>tn('day', 'days', count),
|
|
28
|
+
short: ({ t })=>t('d'),
|
|
29
|
+
narrow: ({ t })=>t('d')
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
unit: 'hour',
|
|
33
|
+
size: 3600000,
|
|
34
|
+
long: (count, { tn })=>tn('hour', 'hours', count),
|
|
35
|
+
short: ({ t })=>t('hr'),
|
|
36
|
+
narrow: ({ t })=>t('h')
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
unit: 'minute',
|
|
40
|
+
size: 60000,
|
|
41
|
+
long: (count, { tn })=>tn('minute', 'minutes', count),
|
|
42
|
+
short: ({ t })=>t('min'),
|
|
43
|
+
narrow: ({ pgettext })=>pgettext('abbreviated minutes', 'm')
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
unit: 'second',
|
|
47
|
+
size: 1000,
|
|
48
|
+
long: (count, { tn })=>tn('second', 'seconds', count),
|
|
49
|
+
short: ({ t })=>t('s'),
|
|
50
|
+
narrow: ({ t })=>t('s')
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
unit: 'millisecond',
|
|
54
|
+
size: 1,
|
|
55
|
+
long: (count, { tn })=>tn('millisecond', 'milliseconds', count),
|
|
56
|
+
short: ({ t })=>t('ms'),
|
|
57
|
+
narrow: ({ t })=>t('ms')
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
unit: 'microsecond',
|
|
61
|
+
size: 0.001,
|
|
62
|
+
long: (count, { tn })=>tn('microsecond', 'microseconds', count),
|
|
63
|
+
short: ()=>'μs',
|
|
64
|
+
narrow: ()=>'μs'
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
function getDuration(seconds, options = {}) {
|
|
68
|
+
return getDurationWithMessages(seconds, options, getSnapshot().messages);
|
|
69
|
+
}
|
|
70
|
+
function getDurationWithMessages(seconds, { precision = 0, style = 'long', absolute = false, minimumUnit = 'millisecond' }, messages) {
|
|
71
|
+
const milliseconds = 1000 * seconds;
|
|
72
|
+
const magnitude = Math.abs(milliseconds);
|
|
73
|
+
const unit = units.find(({ size, unit })=>magnitude >= size || minimumUnit === unit) ?? units[8];
|
|
74
|
+
const value = (absolute ? magnitude : milliseconds) / unit.size;
|
|
75
|
+
const label = value.toFixed(precision);
|
|
76
|
+
if ('long' !== style) return `${label}${unit[style](messages)}`;
|
|
77
|
+
const count = precision <= 0 ? Math.round(value) : value;
|
|
78
|
+
return `${label} ${unit.long(count, messages)}`;
|
|
79
|
+
}
|
|
80
|
+
export { getDuration, getDurationWithMessages };
|