@arcblock/ux 3.2.6 → 3.2.7
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/lib/RelativeTime/index.js +105 -101
- package/lib/package.json.js +1 -1
- package/package.json +7 -7
- package/src/RelativeTime/index.tsx +30 -6
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { jsxs as I, jsx as
|
|
2
|
-
import { Box as
|
|
3
|
-
import { useEffect as
|
|
4
|
-
import
|
|
1
|
+
import { jsxs as I, jsx as o, Fragment as $ } from "react/jsx-runtime";
|
|
2
|
+
import { Box as c, Tooltip as z } from "@mui/material";
|
|
3
|
+
import { useEffect as F, useMemo as N } from "react";
|
|
4
|
+
import a from "dayjs";
|
|
5
5
|
import "dayjs/locale/zh-cn";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { create as
|
|
12
|
-
import { formatToDatetime as O, setDateTool as
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
import R from "dayjs/plugin/utc";
|
|
7
|
+
import V from "dayjs/plugin/timezone";
|
|
8
|
+
import k from "dayjs/plugin/relativeTime";
|
|
9
|
+
import B from "dayjs/plugin/updateLocale";
|
|
10
|
+
import E from "dayjs/plugin/localizedFormat";
|
|
11
|
+
import { create as H } from "zustand";
|
|
12
|
+
import { formatToDatetime as O, setDateTool as Z } from "../Util/index.js";
|
|
13
|
+
a.extend(E);
|
|
14
|
+
a.extend(R);
|
|
15
|
+
a.extend(V);
|
|
16
|
+
a.extend(B);
|
|
17
|
+
a.extend(k);
|
|
18
|
+
a.updateLocale("zh-cn", {
|
|
19
19
|
// copy with https://github.com/iamkun/dayjs/blob/dev/src/locale/zh-cn.js
|
|
20
20
|
relativeTime: {
|
|
21
21
|
future: "%s后",
|
|
@@ -33,7 +33,7 @@ s.updateLocale("zh-cn", {
|
|
|
33
33
|
yy: "%d 年"
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
Z(a);
|
|
37
37
|
const j = {
|
|
38
38
|
en: {
|
|
39
39
|
utc: "UTC Timezone",
|
|
@@ -47,55 +47,59 @@ const j = {
|
|
|
47
47
|
shortUTC: "UTC",
|
|
48
48
|
shortLocal: "当前时区"
|
|
49
49
|
}
|
|
50
|
-
},
|
|
50
|
+
}, w = H((i) => ({
|
|
51
51
|
isUtc: !1,
|
|
52
|
-
setIsUtc: (
|
|
52
|
+
setIsUtc: (e) => i({ isUtc: e })
|
|
53
53
|
}));
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
function q(i) {
|
|
55
|
+
let e = i;
|
|
56
|
+
return typeof e == "string" && /^\d+$/.test(e) && (e = Number(e)), typeof e == "number" ? Math.abs(Math.trunc(e)) < 1e11 ? new Date(e * 1e3).getTime() : new Date(e).getTime() : new Date(e).getTime();
|
|
57
|
+
}
|
|
58
|
+
function G({
|
|
59
|
+
value: i,
|
|
60
|
+
locale: e = "en",
|
|
61
|
+
withoutSuffix: d = !1,
|
|
62
|
+
from: f = "",
|
|
63
|
+
to: h = "",
|
|
64
|
+
type: r = "relative",
|
|
65
|
+
tz: s,
|
|
66
|
+
relativeRange: p,
|
|
63
67
|
format: g
|
|
64
68
|
}) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
}, [
|
|
69
|
-
return { innerContent: "-", popContent: "-", isUtc:
|
|
70
|
-
const
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
let
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
else if (
|
|
78
|
-
|
|
79
|
-
else if (
|
|
80
|
-
const
|
|
81
|
-
Math.abs(
|
|
69
|
+
const x = (/* @__PURE__ */ new Date()).getTimezoneOffset(), T = x > 0 ? "-" : "+", L = Math.abs(x) / 60, b = x === 0, l = w((v) => v.isUtc), C = w((v) => v.setIsUtc);
|
|
70
|
+
if (F(() => {
|
|
71
|
+
C(b);
|
|
72
|
+
}, [b]), !i)
|
|
73
|
+
return { innerContent: "-", popContent: "-", isUtc: l, setIsUtc: C, sign: T, hoursOffset: L };
|
|
74
|
+
const U = q(i), u = e === "zh" ? "zh-cn" : "en";
|
|
75
|
+
let t = a(U);
|
|
76
|
+
r === "utc" && (t = t.utc()), s && (t = t.tz(s)), t = t.locale(u);
|
|
77
|
+
const m = O(U, { locale: u, tz: s, format: g });
|
|
78
|
+
let n;
|
|
79
|
+
if (f)
|
|
80
|
+
n = t.from(f, d);
|
|
81
|
+
else if (h)
|
|
82
|
+
n = t.to(h, d);
|
|
83
|
+
else if (p) {
|
|
84
|
+
const v = t.diff(a());
|
|
85
|
+
Math.abs(v) > p && (n = m);
|
|
82
86
|
}
|
|
83
|
-
|
|
84
|
-
let
|
|
85
|
-
return
|
|
87
|
+
n || (n = t.fromNow(d));
|
|
88
|
+
let y = n, D = m;
|
|
89
|
+
return r === "absolute" && (y = m, D = n), r === "utc" && (l ? (y = O(U, { locale: u, tz: s, isUtc: !0, format: g }), D = O(U, { locale: u, tz: s, isUtc: !0, format: g })) : (y = m, D = n)), { innerContent: y, popContent: D, isUtc: l, setIsUtc: C, sign: T, hoursOffset: L, relativeString: n, absoluteString: m };
|
|
86
90
|
}
|
|
87
|
-
function
|
|
88
|
-
locale:
|
|
89
|
-
isUtc:
|
|
90
|
-
setIsUtc:
|
|
91
|
-
useShortTimezone:
|
|
91
|
+
function A({
|
|
92
|
+
locale: i,
|
|
93
|
+
isUtc: e = !1,
|
|
94
|
+
setIsUtc: d,
|
|
95
|
+
useShortTimezone: f = !0
|
|
92
96
|
}) {
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
return
|
|
96
|
-
}, [
|
|
97
|
-
return /* @__PURE__ */
|
|
98
|
-
|
|
97
|
+
const h = N(() => {
|
|
98
|
+
const r = f ? "shortUTC" : "utc", s = f ? "shortLocal" : "local", p = j[i] || j.en;
|
|
99
|
+
return e ? `${p[r]}` : `${p[s]}`;
|
|
100
|
+
}, [i, f, e]);
|
|
101
|
+
return /* @__PURE__ */ o(
|
|
102
|
+
c,
|
|
99
103
|
{
|
|
100
104
|
component: "span",
|
|
101
105
|
sx: {
|
|
@@ -107,63 +111,63 @@ function z({
|
|
|
107
111
|
padding: "4px 8px",
|
|
108
112
|
lineHeight: 1
|
|
109
113
|
},
|
|
110
|
-
onClick: () =>
|
|
111
|
-
children:
|
|
114
|
+
onClick: () => d(!e),
|
|
115
|
+
children: h
|
|
112
116
|
}
|
|
113
117
|
);
|
|
114
118
|
}
|
|
115
|
-
function
|
|
116
|
-
value:
|
|
117
|
-
locale:
|
|
118
|
-
withoutSuffix:
|
|
119
|
-
from:
|
|
120
|
-
to:
|
|
121
|
-
type:
|
|
122
|
-
tz:
|
|
123
|
-
relativeRange:
|
|
119
|
+
function oe({
|
|
120
|
+
value: i,
|
|
121
|
+
locale: e = "en",
|
|
122
|
+
withoutSuffix: d = !1,
|
|
123
|
+
from: f = "",
|
|
124
|
+
to: h = "",
|
|
125
|
+
type: r = "relative",
|
|
126
|
+
tz: s = void 0,
|
|
127
|
+
relativeRange: p = void 0,
|
|
124
128
|
enableTooltip: g = !0,
|
|
125
|
-
useShortTimezone:
|
|
126
|
-
disableTimezone:
|
|
129
|
+
useShortTimezone: M = !1,
|
|
130
|
+
disableTimezone: x = !1,
|
|
127
131
|
placement: T = "top-end",
|
|
128
|
-
format:
|
|
129
|
-
mode:
|
|
130
|
-
...
|
|
132
|
+
format: L = "lll",
|
|
133
|
+
mode: b = "all",
|
|
134
|
+
...l
|
|
131
135
|
}) {
|
|
132
|
-
const { innerContent:
|
|
133
|
-
value:
|
|
134
|
-
locale:
|
|
135
|
-
withoutSuffix:
|
|
136
|
-
from:
|
|
137
|
-
to:
|
|
138
|
-
type:
|
|
139
|
-
tz:
|
|
140
|
-
relativeRange:
|
|
141
|
-
format:
|
|
142
|
-
}),
|
|
143
|
-
|
|
136
|
+
const { innerContent: C, popContent: U, isUtc: u, setIsUtc: t, relativeString: m } = G({
|
|
137
|
+
value: i,
|
|
138
|
+
locale: e,
|
|
139
|
+
withoutSuffix: d,
|
|
140
|
+
from: f,
|
|
141
|
+
to: h,
|
|
142
|
+
type: r === "all" ? "utc" : r,
|
|
143
|
+
tz: s,
|
|
144
|
+
relativeRange: p,
|
|
145
|
+
format: L
|
|
146
|
+
}), n = /* @__PURE__ */ I(
|
|
147
|
+
c,
|
|
144
148
|
{
|
|
145
|
-
...
|
|
149
|
+
...l,
|
|
146
150
|
sx: [
|
|
147
151
|
{
|
|
148
152
|
display: "inline-flex",
|
|
149
153
|
alignItems: "center",
|
|
150
154
|
gap: 0.5
|
|
151
155
|
},
|
|
152
|
-
...Array.isArray(
|
|
156
|
+
...Array.isArray(l.sx) ? l.sx : [l.sx]
|
|
153
157
|
],
|
|
154
158
|
children: [
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
/* @__PURE__ */
|
|
157
|
-
/* @__PURE__ */
|
|
158
|
-
!
|
|
159
|
-
/* @__PURE__ */
|
|
160
|
-
/* @__PURE__ */
|
|
159
|
+
/* @__PURE__ */ o(c, { component: "span", ...l, sx: {}, children: C }),
|
|
160
|
+
/* @__PURE__ */ o(c, { component: "span", sx: { color: "inherit" }, children: "·" }),
|
|
161
|
+
/* @__PURE__ */ o(c, { component: "span", sx: { color: "inherit" }, children: m }),
|
|
162
|
+
!x && /* @__PURE__ */ I($, { children: [
|
|
163
|
+
/* @__PURE__ */ o(c, { component: "span", sx: { color: "inherit" }, children: "·" }),
|
|
164
|
+
/* @__PURE__ */ o(A, { locale: e, isUtc: u, setIsUtc: t, useShortTimezone: M })
|
|
161
165
|
] })
|
|
162
166
|
]
|
|
163
167
|
}
|
|
164
168
|
);
|
|
165
|
-
return
|
|
166
|
-
|
|
169
|
+
return b === "daysLeft" ? /* @__PURE__ */ o(z, { title: n, placement: T, enterTouchDelay: 0, children: /* @__PURE__ */ o(c, { component: "span", children: m }) }) : r === "all" && b === "all" ? /* @__PURE__ */ o(z, { title: void 0, placement: T, enterTouchDelay: 0, children: n }) : /* @__PURE__ */ o(z, { title: g ? U : void 0, placement: T, enterTouchDelay: 0, children: /* @__PURE__ */ I(
|
|
170
|
+
c,
|
|
167
171
|
{
|
|
168
172
|
sx: {
|
|
169
173
|
display: "inline-flex",
|
|
@@ -171,12 +175,12 @@ function et({
|
|
|
171
175
|
gap: 1
|
|
172
176
|
},
|
|
173
177
|
children: [
|
|
174
|
-
/* @__PURE__ */
|
|
175
|
-
|
|
178
|
+
/* @__PURE__ */ o(c, { component: "span", ...l, children: C }),
|
|
179
|
+
r === "utc" && !x && /* @__PURE__ */ o(A, { locale: e, isUtc: u, setIsUtc: t, useShortTimezone: M })
|
|
176
180
|
]
|
|
177
181
|
}
|
|
178
182
|
) });
|
|
179
183
|
}
|
|
180
184
|
export {
|
|
181
|
-
|
|
185
|
+
oe as default
|
|
182
186
|
};
|
package/lib/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.7",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -68,16 +68,16 @@
|
|
|
68
68
|
"react": "^19.0.0",
|
|
69
69
|
"react-router-dom": "^6.22.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "756a9f08c4008f45690ef38e612e1c429855948d",
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@arcblock/bridge": "3.2.
|
|
73
|
+
"@arcblock/bridge": "3.2.7",
|
|
74
74
|
"@arcblock/did": "^1.27.6",
|
|
75
75
|
"@arcblock/did-motif": "^1.1.14",
|
|
76
|
-
"@arcblock/icons": "3.2.
|
|
77
|
-
"@arcblock/nft-display": "3.2.
|
|
78
|
-
"@arcblock/react-hooks": "3.2.
|
|
76
|
+
"@arcblock/icons": "3.2.7",
|
|
77
|
+
"@arcblock/nft-display": "3.2.7",
|
|
78
|
+
"@arcblock/react-hooks": "3.2.7",
|
|
79
79
|
"@blocklet/js-sdk": "1.17.2",
|
|
80
|
-
"@blocklet/theme": "3.2.
|
|
80
|
+
"@blocklet/theme": "3.2.7",
|
|
81
81
|
"@fontsource/roboto": "~5.1.1",
|
|
82
82
|
"@fontsource/ubuntu-mono": "^5.2.6",
|
|
83
83
|
"@iconify-icons/logos": "^1.2.36",
|
|
@@ -76,6 +76,27 @@ export interface RelativeTimeProps {
|
|
|
76
76
|
mode?: 'all' | 'daysLeft'; // all: 显示所有内容,daysLeft: 只显示剩余天数
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
function normalizeTimestamp(value: string | number) {
|
|
80
|
+
let normalizedValue = value;
|
|
81
|
+
if (typeof normalizedValue === 'string' && /^\d+$/.test(normalizedValue)) {
|
|
82
|
+
normalizedValue = Number(normalizedValue);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (typeof normalizedValue === 'number') {
|
|
86
|
+
// 10 位左右:很可能是秒(例如 1699411200)
|
|
87
|
+
// 13 位左右:很可能是毫秒(例如 1699411200000)
|
|
88
|
+
const abs = Math.abs(Math.trunc(normalizedValue));
|
|
89
|
+
// < 100,000,000,000 -> treat as seconds (safe threshold for seconds)
|
|
90
|
+
if (abs < 1e11) {
|
|
91
|
+
return new Date(normalizedValue * 1000).getTime();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new Date(normalizedValue).getTime();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return new Date(normalizedValue).getTime();
|
|
98
|
+
}
|
|
99
|
+
|
|
79
100
|
function useRelativeTime({
|
|
80
101
|
value,
|
|
81
102
|
locale = 'en',
|
|
@@ -115,18 +136,21 @@ function useRelativeTime({
|
|
|
115
136
|
return { innerContent: '-', popContent: '-', isUtc, setIsUtc, sign, hoursOffset };
|
|
116
137
|
}
|
|
117
138
|
|
|
118
|
-
const
|
|
119
|
-
|
|
139
|
+
const normalizedValue = normalizeTimestamp(value);
|
|
140
|
+
const localeOption = locale === 'zh' ? 'zh-cn' : 'en';
|
|
141
|
+
let datetime = dayjs(normalizedValue);
|
|
120
142
|
|
|
121
143
|
if (type === 'utc') {
|
|
122
|
-
datetime =
|
|
144
|
+
datetime = datetime.utc();
|
|
123
145
|
}
|
|
124
146
|
|
|
125
147
|
if (tz) {
|
|
126
148
|
datetime = datetime.tz(tz);
|
|
127
149
|
}
|
|
128
150
|
|
|
129
|
-
|
|
151
|
+
datetime = datetime.locale(localeOption);
|
|
152
|
+
|
|
153
|
+
const absoluteString = formatToDatetime(normalizedValue, { locale: localeOption, tz, format });
|
|
130
154
|
|
|
131
155
|
let relativeString;
|
|
132
156
|
|
|
@@ -155,8 +179,8 @@ function useRelativeTime({
|
|
|
155
179
|
|
|
156
180
|
if (type === 'utc') {
|
|
157
181
|
if (isUtc) {
|
|
158
|
-
innerContent = formatToDatetime(
|
|
159
|
-
popContent = formatToDatetime(
|
|
182
|
+
innerContent = formatToDatetime(normalizedValue, { locale: localeOption, tz, isUtc: true, format });
|
|
183
|
+
popContent = formatToDatetime(normalizedValue, { locale: localeOption, tz, isUtc: true, format });
|
|
160
184
|
} else {
|
|
161
185
|
innerContent = absoluteString;
|
|
162
186
|
popContent = relativeString;
|