@tidbcloud/uikit 2.0.0-beta.3 → 2.0.0-beta.5
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/dist/biz/TimeRangePicker/AbsoluteTimeRangePicker.cjs +168 -0
- package/dist/biz/TimeRangePicker/AbsoluteTimeRangePicker.d.cts +13 -0
- package/dist/biz/TimeRangePicker/AbsoluteTimeRangePicker.d.ts +13 -0
- package/dist/biz/TimeRangePicker/AbsoluteTimeRangePicker.js +169 -0
- package/dist/biz/TimeRangePicker/helpers.cjs +68 -0
- package/dist/biz/TimeRangePicker/helpers.d.cts +27 -0
- package/dist/biz/TimeRangePicker/helpers.d.ts +27 -0
- package/dist/biz/TimeRangePicker/helpers.js +68 -0
- package/dist/biz/TimeRangePicker/index.cjs +153 -0
- package/dist/biz/TimeRangePicker/index.d.cts +14 -0
- package/dist/biz/TimeRangePicker/index.d.ts +14 -0
- package/dist/biz/TimeRangePicker/index.js +153 -0
- package/dist/biz/index.cjs +2 -0
- package/dist/biz/index.d.cts +1 -0
- package/dist/biz/index.d.ts +1 -0
- package/dist/biz/index.js +2 -0
- package/dist/hooks/useURLQueryState.cjs +5 -4
- package/dist/hooks/useURLQueryState.js +5 -4
- package/dist/node_modules/.pnpm/{@babel_runtime@7.21.5 → @babel_runtime@7.24.7}/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.cjs +3 -4
- package/dist/node_modules/.pnpm/{@babel_runtime@7.21.5 → @babel_runtime@7.24.7}/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js +3 -4
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/extends.cjs +12 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/extends.js +13 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/inheritsLoose.cjs +6 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +7 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.cjs +14 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +15 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.cjs +7 -0
- package/dist/node_modules/.pnpm/@babel_runtime@7.24.7/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +8 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-primitive@1.0.1_react-dom@18.2.0_react@18.2.0/node_modules/@radix-ui/react-primitive/dist/index.module.cjs +1 -1
- package/dist/node_modules/.pnpm/@radix-ui_react-primitive@1.0.1_react-dom@18.2.0_react@18.2.0/node_modules/@radix-ui/react-primitive/dist/index.module.js +1 -1
- package/dist/node_modules/.pnpm/@radix-ui_react-scroll-area@1.0.2_react-dom@18.2.0_react@18.2.0/node_modules/@radix-ui/react-scroll-area/dist/index.module.cjs +1 -1
- package/dist/node_modules/.pnpm/@radix-ui_react-scroll-area@1.0.2_react-dom@18.2.0_react@18.2.0/node_modules/@radix-ui/react-scroll-area/dist/index.module.js +1 -1
- package/dist/node_modules/.pnpm/@radix-ui_react-slot@1.0.1_react@18.2.0/node_modules/@radix-ui/react-slot/dist/index.module.cjs +1 -1
- package/dist/node_modules/.pnpm/@radix-ui_react-slot@1.0.1_react@18.2.0/node_modules/@radix-ui/react-slot/dist/index.module.js +1 -1
- package/dist/node_modules/.pnpm/react-textarea-autosize@8.3.4_@types_react@18.2.48_react@18.2.0/node_modules/react-textarea-autosize/dist/react-textarea-autosize.browser.esm.cjs +2 -2
- package/dist/node_modules/.pnpm/react-textarea-autosize@8.3.4_@types_react@18.2.48_react@18.2.0/node_modules/react-textarea-autosize/dist/react-textarea-autosize.browser.esm.js +2 -2
- package/dist/node_modules/.pnpm/react-transition-group@4.4.2_react-dom@18.2.0_react@18.2.0/node_modules/react-transition-group/esm/Transition.cjs +2 -2
- package/dist/node_modules/.pnpm/react-transition-group@4.4.2_react-dom@18.2.0_react@18.2.0/node_modules/react-transition-group/esm/Transition.js +2 -2
- package/dist/node_modules/.pnpm/react-transition-group@4.4.2_react-dom@18.2.0_react@18.2.0/node_modules/react-transition-group/esm/TransitionGroup.cjs +4 -4
- package/dist/node_modules/.pnpm/react-transition-group@4.4.2_react-dom@18.2.0_react@18.2.0/node_modules/react-transition-group/esm/TransitionGroup.js +4 -4
- package/package.json +5 -3
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/extends.cjs +0 -16
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/extends.js +0 -17
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/inheritsLoose.cjs +0 -8
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +0 -9
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.cjs +0 -16
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +0 -17
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.cjs +0 -9
- package/dist/node_modules/.pnpm/@babel_runtime@7.21.5/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @tidbcloud/uikit
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.5
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- add TimeRangePicker component
|
|
8
|
+
|
|
9
|
+
## 2.0.0-beta.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fix `useURLQueryState` bug
|
|
14
|
+
|
|
3
15
|
## 2.0.0-beta.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -24,6 +36,12 @@
|
|
|
24
36
|
|
|
25
37
|
- Upgrade react-hook-form to v7
|
|
26
38
|
|
|
39
|
+
## 1.18.0
|
|
40
|
+
|
|
41
|
+
### Minor Changes
|
|
42
|
+
|
|
43
|
+
- cd2433d: add icon: vector
|
|
44
|
+
|
|
27
45
|
## 1.17.1
|
|
28
46
|
|
|
29
47
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 by TiDB Cloud FE Team https://tiui.tidbcloud.com/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs");
|
|
3
|
+
const dayjs = require("dayjs");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const AlertCircle = require("../../icons/react/AlertCircle.cjs");
|
|
6
|
+
const ChevronLeft = require("../../icons/react/ChevronLeft.cjs");
|
|
7
|
+
const index = require("../../primitive/Typography/index.cjs");
|
|
8
|
+
const helpers = require("./helpers.cjs");
|
|
9
|
+
const DatePicker = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/DatePicker/DatePicker.cjs");
|
|
10
|
+
const TimeInput = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.cjs");
|
|
11
|
+
const RangeCalendar = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/RangeCalendar/RangeCalendar.cjs");
|
|
12
|
+
const Text = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Text/Text.cjs");
|
|
13
|
+
const MantineProvider = require("../../node_modules/.pnpm/@mantine_styles@5.10.4_@emotion_react@11.11.0_react-dom@18.2.0_react@18.2.0/node_modules/@mantine/styles/esm/theme/MantineProvider.cjs");
|
|
14
|
+
const Box = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Box/Box.cjs");
|
|
15
|
+
const Group = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Group/Group.cjs");
|
|
16
|
+
const Flex = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Flex/Flex.cjs");
|
|
17
|
+
const Alert = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Alert/Alert.cjs");
|
|
18
|
+
const Button = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Button/Button.cjs");
|
|
19
|
+
const AbsoluteTimeRangePicker = ({
|
|
20
|
+
value,
|
|
21
|
+
maxDateTime,
|
|
22
|
+
minDateTime,
|
|
23
|
+
maxDuration,
|
|
24
|
+
onChange,
|
|
25
|
+
onCancel,
|
|
26
|
+
onReturnClick
|
|
27
|
+
}) => {
|
|
28
|
+
const theme = MantineProvider.useMantineTheme();
|
|
29
|
+
const dayStyle = (_date, modifiers) => modifiers.weekend && !modifiers.disabled && !modifiers.selected && !modifiers.outside && !modifiers.selectedInRange ? { color: theme.colors.gray[7] } : null;
|
|
30
|
+
const [start, setStart] = React.useState(() => new Date(value[0] * 1e3));
|
|
31
|
+
const [end, setEnd] = React.useState(() => new Date(value[1] * 1e3));
|
|
32
|
+
const startAfterEnd = React.useMemo(() => {
|
|
33
|
+
return start.valueOf() > end.valueOf();
|
|
34
|
+
}, [start, end]);
|
|
35
|
+
const beyondMin = React.useMemo(() => {
|
|
36
|
+
return minDateTime && start.valueOf() < minDateTime.valueOf();
|
|
37
|
+
}, [minDateTime, start]);
|
|
38
|
+
const beyondMax = React.useMemo(() => {
|
|
39
|
+
return maxDateTime && end.valueOf() > maxDateTime.valueOf();
|
|
40
|
+
}, [maxDateTime, end]);
|
|
41
|
+
const beyondDuration = React.useMemo(() => {
|
|
42
|
+
if (maxDuration !== void 0) {
|
|
43
|
+
return end.valueOf() - start.valueOf() > maxDuration * 1e3;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}, [maxDuration, start, end]);
|
|
47
|
+
const updateDate = (dates) => {
|
|
48
|
+
const newStart = new Date(dates[0]);
|
|
49
|
+
newStart.setHours(start.getHours());
|
|
50
|
+
newStart.setMinutes(start.getMinutes());
|
|
51
|
+
newStart.setSeconds(start.getSeconds());
|
|
52
|
+
setStart(newStart);
|
|
53
|
+
let newEnd = new Date(dates[0]);
|
|
54
|
+
if (dates[1]) {
|
|
55
|
+
newEnd = new Date(dates[1]);
|
|
56
|
+
}
|
|
57
|
+
newEnd.setHours(end.getHours());
|
|
58
|
+
newEnd.setMinutes(end.getMinutes());
|
|
59
|
+
newEnd.setSeconds(end.getSeconds());
|
|
60
|
+
setEnd(newEnd);
|
|
61
|
+
};
|
|
62
|
+
const updateTime = (d, setter) => {
|
|
63
|
+
setter((old) => {
|
|
64
|
+
const newD = new Date(old);
|
|
65
|
+
newD.setHours(d.getHours());
|
|
66
|
+
newD.setMinutes(d.getMinutes());
|
|
67
|
+
newD.setSeconds(d.getSeconds());
|
|
68
|
+
return newD;
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const apply = () => onChange == null ? void 0 : onChange({ type: "absolute", value: [dayjs(start).unix(), dayjs(end).unix()] });
|
|
72
|
+
return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Box.Box, { p: 16, w: 280, m: -4, children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { onClick: onReturnClick, sx: { cursor: "pointer" }, children: [
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(ChevronLeft, { size: 16 }),
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "body-lg", children: "Back" })
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 0, pt: 8, position: "apart", children: [
|
|
78
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "label-sm", children: "Start" }),
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 8, children: [
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
81
|
+
DatePicker.DatePicker,
|
|
82
|
+
{
|
|
83
|
+
onClick: () => {
|
|
84
|
+
},
|
|
85
|
+
w: 116,
|
|
86
|
+
value: start,
|
|
87
|
+
inputFormat: "MMM D, YYYY",
|
|
88
|
+
clearable: false,
|
|
89
|
+
error: beyondMin || startAfterEnd || beyondDuration
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
93
|
+
TimeInput.TimeInput,
|
|
94
|
+
{
|
|
95
|
+
format: "24",
|
|
96
|
+
w: 90,
|
|
97
|
+
styles: { input: { paddingLeft: 4, paddingRight: 4 } },
|
|
98
|
+
withSeconds: true,
|
|
99
|
+
value: start,
|
|
100
|
+
onChange: (d) => updateTime(d, setStart),
|
|
101
|
+
error: beyondMin || startAfterEnd || beyondDuration
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
] })
|
|
105
|
+
] }),
|
|
106
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 0, pt: 8, position: "apart", children: [
|
|
107
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "label-sm", children: "End" }),
|
|
108
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 8, children: [
|
|
109
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
110
|
+
DatePicker.DatePicker,
|
|
111
|
+
{
|
|
112
|
+
onClick: () => {
|
|
113
|
+
},
|
|
114
|
+
w: 116,
|
|
115
|
+
value: end,
|
|
116
|
+
inputFormat: "MMM D, YYYY",
|
|
117
|
+
clearable: false,
|
|
118
|
+
error: beyondMax || startAfterEnd || beyondDuration
|
|
119
|
+
}
|
|
120
|
+
),
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
122
|
+
TimeInput.TimeInput,
|
|
123
|
+
{
|
|
124
|
+
format: "24",
|
|
125
|
+
w: 90,
|
|
126
|
+
styles: { input: { paddingLeft: 4, paddingRight: 4 } },
|
|
127
|
+
withSeconds: true,
|
|
128
|
+
value: end,
|
|
129
|
+
onChange: (d) => updateTime(d, setEnd),
|
|
130
|
+
error: beyondMax || startAfterEnd || beyondDuration
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
] })
|
|
134
|
+
] }),
|
|
135
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Flex.Flex, { justify: "center", pt: 8, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
136
|
+
RangeCalendar.RangeCalendar,
|
|
137
|
+
{
|
|
138
|
+
value: [start, end],
|
|
139
|
+
onChange: updateDate,
|
|
140
|
+
maxDate: maxDateTime,
|
|
141
|
+
minDate: minDateTime,
|
|
142
|
+
dayStyle
|
|
143
|
+
}
|
|
144
|
+
) }),
|
|
145
|
+
(startAfterEnd || beyondMin || beyondMax || beyondDuration) && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Alert.Alert, { icon: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(AlertCircle, { size: 16 }), color: "red", pt: 8, children: [
|
|
146
|
+
startAfterEnd && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Text.Text, { color: "red", children: "Please select an end time after the start time." }),
|
|
147
|
+
beyondMin && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { color: "red", children: [
|
|
148
|
+
"Please select a start time after ",
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(jsxRuntime.jsxRuntimeExports.Fragment, { children: helpers.timeFormatter(minDateTime, null, "MMM D, YYYY HH:mm:ss") })
|
|
150
|
+
] }),
|
|
151
|
+
beyondMax && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { color: "red", children: [
|
|
152
|
+
"Please select an end time before ",
|
|
153
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(jsxRuntime.jsxRuntimeExports.Fragment, { children: helpers.timeFormatter(maxDateTime, null, "MMM D, YYYY HH:mm:ss") })
|
|
154
|
+
] }),
|
|
155
|
+
beyondDuration && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { color: "red", children: [
|
|
156
|
+
"The selection exceeds the ",
|
|
157
|
+
helpers.formatDuration(maxDuration),
|
|
158
|
+
" limit, please select a shorter time range."
|
|
159
|
+
] })
|
|
160
|
+
] }),
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Flex.Flex, { pt: 8, gap: "xs", justify: "flex-end", align: "flex-start", direction: "row", wrap: "wrap", children: [
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Button.Button, { size: "xs", variant: "default", onClick: onCancel, children: "Cancel" }),
|
|
163
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Button.Button, { size: "xs", onClick: apply, disabled: startAfterEnd || beyondMin || beyondMax || beyondDuration, children: "Apply" })
|
|
164
|
+
] })
|
|
165
|
+
] });
|
|
166
|
+
};
|
|
167
|
+
const AbsoluteTimeRangePicker$1 = AbsoluteTimeRangePicker;
|
|
168
|
+
module.exports = AbsoluteTimeRangePicker$1;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { AbsoluteTimeRange, TimeRangeValue } from './helpers.js';
|
|
3
|
+
interface AbsoluteTimeRangePickerProps {
|
|
4
|
+
value: TimeRangeValue;
|
|
5
|
+
minDateTime?: Date;
|
|
6
|
+
maxDateTime?: Date;
|
|
7
|
+
maxDuration?: number;
|
|
8
|
+
onChange?: (v: AbsoluteTimeRange) => void;
|
|
9
|
+
onCancel?: () => void;
|
|
10
|
+
onReturnClick?: MouseEventHandler<HTMLElement>;
|
|
11
|
+
}
|
|
12
|
+
declare const AbsoluteTimeRangePicker: React.FC<React.PropsWithChildren<AbsoluteTimeRangePickerProps>>;
|
|
13
|
+
export default AbsoluteTimeRangePicker;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { AbsoluteTimeRange, TimeRangeValue } from './helpers.js';
|
|
3
|
+
interface AbsoluteTimeRangePickerProps {
|
|
4
|
+
value: TimeRangeValue;
|
|
5
|
+
minDateTime?: Date;
|
|
6
|
+
maxDateTime?: Date;
|
|
7
|
+
maxDuration?: number;
|
|
8
|
+
onChange?: (v: AbsoluteTimeRange) => void;
|
|
9
|
+
onCancel?: () => void;
|
|
10
|
+
onReturnClick?: MouseEventHandler<HTMLElement>;
|
|
11
|
+
}
|
|
12
|
+
declare const AbsoluteTimeRangePicker: React.FC<React.PropsWithChildren<AbsoluteTimeRangePickerProps>>;
|
|
13
|
+
export default AbsoluteTimeRangePicker;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import { useState, useMemo } from "react";
|
|
4
|
+
import IconAlertCircle from "../../icons/react/AlertCircle.js";
|
|
5
|
+
import IconChevronLeft from "../../icons/react/ChevronLeft.js";
|
|
6
|
+
import { Typography } from "../../primitive/Typography/index.js";
|
|
7
|
+
import { timeFormatter, formatDuration } from "./helpers.js";
|
|
8
|
+
import { DatePicker } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/DatePicker/DatePicker.js";
|
|
9
|
+
import { TimeInput } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.js";
|
|
10
|
+
import { RangeCalendar } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/RangeCalendar/RangeCalendar.js";
|
|
11
|
+
import { Text } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Text/Text.js";
|
|
12
|
+
import { useMantineTheme } from "../../node_modules/.pnpm/@mantine_styles@5.10.4_@emotion_react@11.11.0_react-dom@18.2.0_react@18.2.0/node_modules/@mantine/styles/esm/theme/MantineProvider.js";
|
|
13
|
+
import { Box } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Box/Box.js";
|
|
14
|
+
import { Group } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Group/Group.js";
|
|
15
|
+
import { Flex } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Flex/Flex.js";
|
|
16
|
+
import { Alert } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Alert/Alert.js";
|
|
17
|
+
import { Button } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Button/Button.js";
|
|
18
|
+
const AbsoluteTimeRangePicker = ({
|
|
19
|
+
value,
|
|
20
|
+
maxDateTime,
|
|
21
|
+
minDateTime,
|
|
22
|
+
maxDuration,
|
|
23
|
+
onChange,
|
|
24
|
+
onCancel,
|
|
25
|
+
onReturnClick
|
|
26
|
+
}) => {
|
|
27
|
+
const theme = useMantineTheme();
|
|
28
|
+
const dayStyle = (_date, modifiers) => modifiers.weekend && !modifiers.disabled && !modifiers.selected && !modifiers.outside && !modifiers.selectedInRange ? { color: theme.colors.gray[7] } : null;
|
|
29
|
+
const [start, setStart] = useState(() => new Date(value[0] * 1e3));
|
|
30
|
+
const [end, setEnd] = useState(() => new Date(value[1] * 1e3));
|
|
31
|
+
const startAfterEnd = useMemo(() => {
|
|
32
|
+
return start.valueOf() > end.valueOf();
|
|
33
|
+
}, [start, end]);
|
|
34
|
+
const beyondMin = useMemo(() => {
|
|
35
|
+
return minDateTime && start.valueOf() < minDateTime.valueOf();
|
|
36
|
+
}, [minDateTime, start]);
|
|
37
|
+
const beyondMax = useMemo(() => {
|
|
38
|
+
return maxDateTime && end.valueOf() > maxDateTime.valueOf();
|
|
39
|
+
}, [maxDateTime, end]);
|
|
40
|
+
const beyondDuration = useMemo(() => {
|
|
41
|
+
if (maxDuration !== void 0) {
|
|
42
|
+
return end.valueOf() - start.valueOf() > maxDuration * 1e3;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}, [maxDuration, start, end]);
|
|
46
|
+
const updateDate = (dates) => {
|
|
47
|
+
const newStart = new Date(dates[0]);
|
|
48
|
+
newStart.setHours(start.getHours());
|
|
49
|
+
newStart.setMinutes(start.getMinutes());
|
|
50
|
+
newStart.setSeconds(start.getSeconds());
|
|
51
|
+
setStart(newStart);
|
|
52
|
+
let newEnd = new Date(dates[0]);
|
|
53
|
+
if (dates[1]) {
|
|
54
|
+
newEnd = new Date(dates[1]);
|
|
55
|
+
}
|
|
56
|
+
newEnd.setHours(end.getHours());
|
|
57
|
+
newEnd.setMinutes(end.getMinutes());
|
|
58
|
+
newEnd.setSeconds(end.getSeconds());
|
|
59
|
+
setEnd(newEnd);
|
|
60
|
+
};
|
|
61
|
+
const updateTime = (d, setter) => {
|
|
62
|
+
setter((old) => {
|
|
63
|
+
const newD = new Date(old);
|
|
64
|
+
newD.setHours(d.getHours());
|
|
65
|
+
newD.setMinutes(d.getMinutes());
|
|
66
|
+
newD.setSeconds(d.getSeconds());
|
|
67
|
+
return newD;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const apply = () => onChange == null ? void 0 : onChange({ type: "absolute", value: [dayjs(start).unix(), dayjs(end).unix()] });
|
|
71
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { p: 16, w: 280, m: -4, children: [
|
|
72
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { onClick: onReturnClick, sx: { cursor: "pointer" }, children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronLeft, { size: 16 }),
|
|
74
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "body-lg", children: "Back" })
|
|
75
|
+
] }),
|
|
76
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 0, pt: 8, position: "apart", children: [
|
|
77
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "label-sm", children: "Start" }),
|
|
78
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 8, children: [
|
|
79
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
80
|
+
DatePicker,
|
|
81
|
+
{
|
|
82
|
+
onClick: () => {
|
|
83
|
+
},
|
|
84
|
+
w: 116,
|
|
85
|
+
value: start,
|
|
86
|
+
inputFormat: "MMM D, YYYY",
|
|
87
|
+
clearable: false,
|
|
88
|
+
error: beyondMin || startAfterEnd || beyondDuration
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
92
|
+
TimeInput,
|
|
93
|
+
{
|
|
94
|
+
format: "24",
|
|
95
|
+
w: 90,
|
|
96
|
+
styles: { input: { paddingLeft: 4, paddingRight: 4 } },
|
|
97
|
+
withSeconds: true,
|
|
98
|
+
value: start,
|
|
99
|
+
onChange: (d) => updateTime(d, setStart),
|
|
100
|
+
error: beyondMin || startAfterEnd || beyondDuration
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
] })
|
|
104
|
+
] }),
|
|
105
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 0, pt: 8, position: "apart", children: [
|
|
106
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "label-sm", children: "End" }),
|
|
107
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 8, children: [
|
|
108
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
109
|
+
DatePicker,
|
|
110
|
+
{
|
|
111
|
+
onClick: () => {
|
|
112
|
+
},
|
|
113
|
+
w: 116,
|
|
114
|
+
value: end,
|
|
115
|
+
inputFormat: "MMM D, YYYY",
|
|
116
|
+
clearable: false,
|
|
117
|
+
error: beyondMax || startAfterEnd || beyondDuration
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
121
|
+
TimeInput,
|
|
122
|
+
{
|
|
123
|
+
format: "24",
|
|
124
|
+
w: 90,
|
|
125
|
+
styles: { input: { paddingLeft: 4, paddingRight: 4 } },
|
|
126
|
+
withSeconds: true,
|
|
127
|
+
value: end,
|
|
128
|
+
onChange: (d) => updateTime(d, setEnd),
|
|
129
|
+
error: beyondMax || startAfterEnd || beyondDuration
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
] })
|
|
133
|
+
] }),
|
|
134
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { justify: "center", pt: 8, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
135
|
+
RangeCalendar,
|
|
136
|
+
{
|
|
137
|
+
value: [start, end],
|
|
138
|
+
onChange: updateDate,
|
|
139
|
+
maxDate: maxDateTime,
|
|
140
|
+
minDate: minDateTime,
|
|
141
|
+
dayStyle
|
|
142
|
+
}
|
|
143
|
+
) }),
|
|
144
|
+
(startAfterEnd || beyondMin || beyondMax || beyondDuration) && /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAlertCircle, { size: 16 }), color: "red", pt: 8, children: [
|
|
145
|
+
startAfterEnd && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "red", children: "Please select an end time after the start time." }),
|
|
146
|
+
beyondMin && /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "red", children: [
|
|
147
|
+
"Please select a start time after ",
|
|
148
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: timeFormatter(minDateTime, null, "MMM D, YYYY HH:mm:ss") })
|
|
149
|
+
] }),
|
|
150
|
+
beyondMax && /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "red", children: [
|
|
151
|
+
"Please select an end time before ",
|
|
152
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: timeFormatter(maxDateTime, null, "MMM D, YYYY HH:mm:ss") })
|
|
153
|
+
] }),
|
|
154
|
+
beyondDuration && /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "red", children: [
|
|
155
|
+
"The selection exceeds the ",
|
|
156
|
+
formatDuration(maxDuration),
|
|
157
|
+
" limit, please select a shorter time range."
|
|
158
|
+
] })
|
|
159
|
+
] }),
|
|
160
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { pt: 8, gap: "xs", justify: "flex-end", align: "flex-start", direction: "row", wrap: "wrap", children: [
|
|
161
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "xs", variant: "default", onClick: onCancel, children: "Cancel" }),
|
|
162
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "xs", onClick: apply, disabled: startAfterEnd || beyondMin || beyondMax || beyondDuration, children: "Apply" })
|
|
163
|
+
] })
|
|
164
|
+
] });
|
|
165
|
+
};
|
|
166
|
+
const AbsoluteTimeRangePicker$1 = AbsoluteTimeRangePicker;
|
|
167
|
+
export {
|
|
168
|
+
AbsoluteTimeRangePicker$1 as default
|
|
169
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const dayjs = require("dayjs");
|
|
4
|
+
const lodashEs = require("lodash-es");
|
|
5
|
+
const prettyMs = require("pretty-ms");
|
|
6
|
+
const DEFAULT_QUICK_RANGES = [
|
|
7
|
+
3 * 24 * 60 * 60,
|
|
8
|
+
2 * 24 * 60 * 60,
|
|
9
|
+
24 * 60 * 60,
|
|
10
|
+
12 * 60 * 60,
|
|
11
|
+
3 * 60 * 60,
|
|
12
|
+
60 * 60,
|
|
13
|
+
30 * 60,
|
|
14
|
+
15 * 60,
|
|
15
|
+
5 * 60
|
|
16
|
+
];
|
|
17
|
+
const formatDuration = (seconds, short = false) => {
|
|
18
|
+
if (short) {
|
|
19
|
+
return prettyMs(seconds * 1e3, { compact: true });
|
|
20
|
+
} else {
|
|
21
|
+
return prettyMs(seconds * 1e3, { verbose: true });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const toTimeRangeValue = (timeRange, offset = 0) => {
|
|
25
|
+
if (timeRange.type === "absolute") {
|
|
26
|
+
return timeRange.value.map((t) => t + offset);
|
|
27
|
+
} else {
|
|
28
|
+
const now = dayjs().unix();
|
|
29
|
+
return [now - timeRange.value + offset, now + offset];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
33
|
+
function addOffsetUTC(time, utcOffset) {
|
|
34
|
+
const targetTime = new Date(time);
|
|
35
|
+
const tzDifference = utcOffset * 60 + targetTime.getTimezoneOffset();
|
|
36
|
+
return new Date(targetTime.getTime() + tzDifference * 60 * 1e3);
|
|
37
|
+
}
|
|
38
|
+
const getUTCString = (offset) => {
|
|
39
|
+
const offsetStrs = offset.toString().split(".");
|
|
40
|
+
let mm = "00";
|
|
41
|
+
let hh = "";
|
|
42
|
+
const offsetH = Number.parseInt(offsetStrs[0] || "0");
|
|
43
|
+
const offsetM = Number.parseFloat(`0.${offsetStrs[1]}` || "0") * 60;
|
|
44
|
+
hh = Math.abs(offsetH).toString().padStart(2, "0");
|
|
45
|
+
mm = offsetM === 0 ? "00" : offsetM.toString();
|
|
46
|
+
if (offset > 0) {
|
|
47
|
+
return `UTC+${hh}:${mm}`;
|
|
48
|
+
}
|
|
49
|
+
if (offset < 0) {
|
|
50
|
+
return `UTC-${hh}:${mm}`;
|
|
51
|
+
}
|
|
52
|
+
return "UTC±00:00";
|
|
53
|
+
};
|
|
54
|
+
const timeFormatter = (timeValue, utcOffset, format = DEFAULT_TIME_FORMAT) => {
|
|
55
|
+
if (!timeValue)
|
|
56
|
+
return "-";
|
|
57
|
+
const time = timeValue instanceof Date || isNaN(Number(timeValue)) ? timeValue : Number(timeValue) * 1e3;
|
|
58
|
+
const currentTZOffsetInHours = utcOffset === void 0 || utcOffset === null ? -((/* @__PURE__ */ new Date()).getTimezoneOffset() / 60) : utcOffset;
|
|
59
|
+
const withUTC = format.indexOf("Z") >= 0;
|
|
60
|
+
return dayjs(addOffsetUTC(time, currentTZOffsetInHours)).format(withUTC ? lodashEs.trim(format, "Z") : format) + (withUTC ? getUTCString(currentTZOffsetInHours) : "");
|
|
61
|
+
};
|
|
62
|
+
exports.DEFAULT_QUICK_RANGES = DEFAULT_QUICK_RANGES;
|
|
63
|
+
exports.DEFAULT_TIME_FORMAT = DEFAULT_TIME_FORMAT;
|
|
64
|
+
exports.addOffsetUTC = addOffsetUTC;
|
|
65
|
+
exports.formatDuration = formatDuration;
|
|
66
|
+
exports.getUTCString = getUTCString;
|
|
67
|
+
exports.timeFormatter = timeFormatter;
|
|
68
|
+
exports.toTimeRangeValue = toTimeRangeValue;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type TimeRange = RelativeTimeRange | AbsoluteTimeRange;
|
|
2
|
+
export interface RelativeTimeRange {
|
|
3
|
+
type: 'relative';
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AbsoluteTimeRange {
|
|
7
|
+
type: 'absolute';
|
|
8
|
+
value: TimeRangeValue;
|
|
9
|
+
}
|
|
10
|
+
export type TimeRangeValue = [from: number, to: number];
|
|
11
|
+
export declare const DEFAULT_QUICK_RANGES: number[];
|
|
12
|
+
export declare const DEFAULT_TIME_RANGE: TimeRange;
|
|
13
|
+
export declare const formatDuration: (seconds: number, short?: boolean) => string;
|
|
14
|
+
export declare const toTimeRangeValue: (timeRange: TimeRange, offset?: number) => TimeRangeValue;
|
|
15
|
+
export declare function fromTimeRangeValue(v: TimeRangeValue): AbsoluteTimeRange;
|
|
16
|
+
export type URLTimeRange = {
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const toURLTimeRange: (timeRange: TimeRange) => URLTimeRange;
|
|
21
|
+
export declare const urlToTimeRange: (urlTimeRange: URLTimeRange) => TimeRange;
|
|
22
|
+
export declare const urlToTimeRangeValue: (urlTimeRange: URLTimeRange) => TimeRangeValue;
|
|
23
|
+
export declare const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
24
|
+
export declare const DEFAULT_TIME_FORMAT_WITH_TIMEZONE = "YYYY-MM-DD HH:mm:ss Z";
|
|
25
|
+
export declare function addOffsetUTC(time: string | number | Date, utcOffset: number): Date;
|
|
26
|
+
export declare const getUTCString: (offset: number) => string;
|
|
27
|
+
export declare const timeFormatter: (timeValue: number | string | Date, utcOffset?: number | null, format?: string) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type TimeRange = RelativeTimeRange | AbsoluteTimeRange;
|
|
2
|
+
export interface RelativeTimeRange {
|
|
3
|
+
type: 'relative';
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AbsoluteTimeRange {
|
|
7
|
+
type: 'absolute';
|
|
8
|
+
value: TimeRangeValue;
|
|
9
|
+
}
|
|
10
|
+
export type TimeRangeValue = [from: number, to: number];
|
|
11
|
+
export declare const DEFAULT_QUICK_RANGES: number[];
|
|
12
|
+
export declare const DEFAULT_TIME_RANGE: TimeRange;
|
|
13
|
+
export declare const formatDuration: (seconds: number, short?: boolean) => string;
|
|
14
|
+
export declare const toTimeRangeValue: (timeRange: TimeRange, offset?: number) => TimeRangeValue;
|
|
15
|
+
export declare function fromTimeRangeValue(v: TimeRangeValue): AbsoluteTimeRange;
|
|
16
|
+
export type URLTimeRange = {
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const toURLTimeRange: (timeRange: TimeRange) => URLTimeRange;
|
|
21
|
+
export declare const urlToTimeRange: (urlTimeRange: URLTimeRange) => TimeRange;
|
|
22
|
+
export declare const urlToTimeRangeValue: (urlTimeRange: URLTimeRange) => TimeRangeValue;
|
|
23
|
+
export declare const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
24
|
+
export declare const DEFAULT_TIME_FORMAT_WITH_TIMEZONE = "YYYY-MM-DD HH:mm:ss Z";
|
|
25
|
+
export declare function addOffsetUTC(time: string | number | Date, utcOffset: number): Date;
|
|
26
|
+
export declare const getUTCString: (offset: number) => string;
|
|
27
|
+
export declare const timeFormatter: (timeValue: number | string | Date, utcOffset?: number | null, format?: string) => string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { trim } from "lodash-es";
|
|
3
|
+
import prettyMs from "pretty-ms";
|
|
4
|
+
const DEFAULT_QUICK_RANGES = [
|
|
5
|
+
3 * 24 * 60 * 60,
|
|
6
|
+
2 * 24 * 60 * 60,
|
|
7
|
+
24 * 60 * 60,
|
|
8
|
+
12 * 60 * 60,
|
|
9
|
+
3 * 60 * 60,
|
|
10
|
+
60 * 60,
|
|
11
|
+
30 * 60,
|
|
12
|
+
15 * 60,
|
|
13
|
+
5 * 60
|
|
14
|
+
];
|
|
15
|
+
const formatDuration = (seconds, short = false) => {
|
|
16
|
+
if (short) {
|
|
17
|
+
return prettyMs(seconds * 1e3, { compact: true });
|
|
18
|
+
} else {
|
|
19
|
+
return prettyMs(seconds * 1e3, { verbose: true });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const toTimeRangeValue = (timeRange, offset = 0) => {
|
|
23
|
+
if (timeRange.type === "absolute") {
|
|
24
|
+
return timeRange.value.map((t) => t + offset);
|
|
25
|
+
} else {
|
|
26
|
+
const now = dayjs().unix();
|
|
27
|
+
return [now - timeRange.value + offset, now + offset];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
31
|
+
function addOffsetUTC(time, utcOffset) {
|
|
32
|
+
const targetTime = new Date(time);
|
|
33
|
+
const tzDifference = utcOffset * 60 + targetTime.getTimezoneOffset();
|
|
34
|
+
return new Date(targetTime.getTime() + tzDifference * 60 * 1e3);
|
|
35
|
+
}
|
|
36
|
+
const getUTCString = (offset) => {
|
|
37
|
+
const offsetStrs = offset.toString().split(".");
|
|
38
|
+
let mm = "00";
|
|
39
|
+
let hh = "";
|
|
40
|
+
const offsetH = Number.parseInt(offsetStrs[0] || "0");
|
|
41
|
+
const offsetM = Number.parseFloat(`0.${offsetStrs[1]}` || "0") * 60;
|
|
42
|
+
hh = Math.abs(offsetH).toString().padStart(2, "0");
|
|
43
|
+
mm = offsetM === 0 ? "00" : offsetM.toString();
|
|
44
|
+
if (offset > 0) {
|
|
45
|
+
return `UTC+${hh}:${mm}`;
|
|
46
|
+
}
|
|
47
|
+
if (offset < 0) {
|
|
48
|
+
return `UTC-${hh}:${mm}`;
|
|
49
|
+
}
|
|
50
|
+
return "UTC±00:00";
|
|
51
|
+
};
|
|
52
|
+
const timeFormatter = (timeValue, utcOffset, format = DEFAULT_TIME_FORMAT) => {
|
|
53
|
+
if (!timeValue)
|
|
54
|
+
return "-";
|
|
55
|
+
const time = timeValue instanceof Date || isNaN(Number(timeValue)) ? timeValue : Number(timeValue) * 1e3;
|
|
56
|
+
const currentTZOffsetInHours = utcOffset === void 0 || utcOffset === null ? -((/* @__PURE__ */ new Date()).getTimezoneOffset() / 60) : utcOffset;
|
|
57
|
+
const withUTC = format.indexOf("Z") >= 0;
|
|
58
|
+
return dayjs(addOffsetUTC(time, currentTZOffsetInHours)).format(withUTC ? trim(format, "Z") : format) + (withUTC ? getUTCString(currentTZOffsetInHours) : "");
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
DEFAULT_QUICK_RANGES,
|
|
62
|
+
DEFAULT_TIME_FORMAT,
|
|
63
|
+
addOffsetUTC,
|
|
64
|
+
formatDuration,
|
|
65
|
+
getUTCString,
|
|
66
|
+
timeFormatter,
|
|
67
|
+
toTimeRangeValue
|
|
68
|
+
};
|