@arcblock/ux 3.2.5 → 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.
@@ -6,34 +6,58 @@ export type PaperStyle = import('@mui/material').PaperProps & {
6
6
  minHeight?: number | string;
7
7
  };
8
8
  export type UxDialogProps = {
9
+ /**
10
+ * - The content of the dialog.
11
+ */
9
12
  /**
10
13
  * - The content of the dialog.
11
14
  */
12
15
  children: React.ReactNode;
16
+ /**
17
+ * - The title of the dialog.
18
+ */
13
19
  /**
14
20
  * - The title of the dialog.
15
21
  */
16
22
  title?: React.ReactNode;
23
+ /**
24
+ * - Content to be displayed before the dialog title.
25
+ */
17
26
  /**
18
27
  * - Content to be displayed before the dialog title.
19
28
  */
20
29
  prepend?: React.ReactNode;
30
+ /**
31
+ * - Content to be displayed in the top toolbar of the dialog.
32
+ */
21
33
  /**
22
34
  * - Content to be displayed in the top toolbar of the dialog.
23
35
  */
24
36
  toolbar?: React.ReactNode;
37
+ /**
38
+ * - Content to be displayed in the bottom actions toolbar of the dialog.
39
+ */
25
40
  /**
26
41
  * - Content to be displayed in the bottom actions toolbar of the dialog.
27
42
  */
28
43
  actions?: React.ReactNode;
44
+ /**
45
+ * - Whether or not to show the close button.
46
+ */
29
47
  /**
30
48
  * - Whether or not to show the close button.
31
49
  */
32
50
  showCloseButton?: boolean | undefined;
51
+ /**
52
+ * - The position of the actions toolbar.
53
+ */
33
54
  /**
34
55
  * - The position of the actions toolbar.
35
56
  */
36
57
  actionsPosition?: "left" | "right" | "center" | undefined;
58
+ /**
59
+ * - Props to be passed down to the dialog paper.
60
+ */
37
61
  /**
38
62
  * - Props to be passed down to the dialog paper.
39
63
  */
@@ -41,6 +65,9 @@ export type UxDialogProps = {
41
65
  slotProps?: {
42
66
  content: object;
43
67
  } | undefined;
68
+ /**
69
+ * - Callback function fired when the dialog is closed.
70
+ */
44
71
  /**
45
72
  * - Callback function fired when the dialog is closed.
46
73
  */
@@ -1,6 +1,9 @@
1
1
  import { default as PropTypes } from 'prop-types';
2
2
  export default Img;
3
3
  export type ImgExProps = {
4
+ /**
5
+ * - required
6
+ */
4
7
  /**
5
8
  * - required
6
9
  */
@@ -16,6 +19,9 @@ export type ImgExProps = {
16
19
  lazy?: boolean | undefined;
17
20
  placeholder?: string | undefined;
18
21
  fallback?: string | undefined;
22
+ /**
23
+ * - 是否使用代理 fallback, 用于解决 CSP 的问题
24
+ */
19
25
  /**
20
26
  * - 是否使用代理 fallback, 用于解决 CSP 的问题
21
27
  */
@@ -1,21 +1,21 @@
1
- import { jsxs as I, jsx as n, Fragment as F } from "react/jsx-runtime";
2
- import { Box as a, Tooltip as M } from "@mui/material";
3
- import { useEffect as R, useMemo as $ } from "react";
4
- import s from "dayjs";
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 k from "dayjs/plugin/utc";
7
- import B from "dayjs/plugin/timezone";
8
- import E from "dayjs/plugin/relativeTime";
9
- import H from "dayjs/plugin/updateLocale";
10
- import N from "dayjs/plugin/localizedFormat";
11
- import { create as Z } from "zustand";
12
- import { formatToDatetime as O, setDateTool as q } from "../Util/index.js";
13
- s.extend(N);
14
- s.extend(k);
15
- s.extend(B);
16
- s.extend(H);
17
- s.extend(E);
18
- s.updateLocale("zh-cn", {
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
- q(s);
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
- }, A = Z((t) => ({
50
+ }, w = H((i) => ({
51
51
  isUtc: !1,
52
- setIsUtc: (o) => t({ isUtc: o })
52
+ setIsUtc: (e) => i({ isUtc: e })
53
53
  }));
54
- function w({
55
- value: t,
56
- locale: o = "en",
57
- withoutSuffix: p = !1,
58
- from: d = "",
59
- to: x = "",
60
- type: i = "relative",
61
- tz: l,
62
- relativeRange: m,
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 C = (/* @__PURE__ */ new Date()).getTimezoneOffset(), T = C > 0 ? "-" : "+", v = Math.abs(C) / 60, L = C === 0, r = A((y) => y.isUtc), U = A((y) => y.setIsUtc);
66
- if (R(() => {
67
- U(L);
68
- }, [L]), !t)
69
- return { innerContent: "-", popContent: "-", isUtc: r, setIsUtc: U, sign: T, hoursOffset: v };
70
- const h = o === "zh" ? "zh-cn" : "en-us";
71
- let c = s(t).locale(h);
72
- i === "utc" && (c = s(t).utc().locale(h)), l && (c = c.tz(l));
73
- const f = O(t, { locale: h, tz: l, format: g });
74
- let e;
75
- if (d)
76
- e = c.from(d, p);
77
- else if (x)
78
- e = c.to(x, p);
79
- else if (m) {
80
- const y = c.diff(s());
81
- Math.abs(y) > m && (e = f);
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
- e || (e = c.fromNow(p));
84
- let u = e, b = f;
85
- return i === "absolute" && (u = f, b = e), i === "utc" && (r ? (u = O(t, { locale: h, tz: l, isUtc: !0, format: g }), b = O(t, { locale: h, tz: l, isUtc: !0, format: g })) : (u = f, b = e)), { innerContent: u, popContent: b, isUtc: r, setIsUtc: U, sign: T, hoursOffset: v, relativeString: e, absoluteString: f };
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 z({
88
- locale: t,
89
- isUtc: o = !1,
90
- setIsUtc: p,
91
- useShortTimezone: d = !0
91
+ function A({
92
+ locale: i,
93
+ isUtc: e = !1,
94
+ setIsUtc: d,
95
+ useShortTimezone: f = !0
92
96
  }) {
93
- const x = $(() => {
94
- const i = d ? "shortUTC" : "utc", l = d ? "shortLocal" : "local", m = j[t] || j.en;
95
- return o ? `${m[i]}` : `${m[l]}`;
96
- }, [t, d, o]);
97
- return /* @__PURE__ */ n(
98
- a,
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: () => p(!o),
111
- children: x
114
+ onClick: () => d(!e),
115
+ children: h
112
116
  }
113
117
  );
114
118
  }
115
- function et({
116
- value: t,
117
- locale: o = "en",
118
- withoutSuffix: p = !1,
119
- from: d = "",
120
- to: x = "",
121
- type: i = "relative",
122
- tz: l = void 0,
123
- relativeRange: m = void 0,
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: D = !1,
126
- disableTimezone: C = !1,
129
+ useShortTimezone: M = !1,
130
+ disableTimezone: x = !1,
127
131
  placement: T = "top-end",
128
- format: v = "lll",
129
- mode: L = "all",
130
- ...r
132
+ format: L = "lll",
133
+ mode: b = "all",
134
+ ...l
131
135
  }) {
132
- const { innerContent: U, popContent: h, isUtc: c, setIsUtc: f, relativeString: e } = w({
133
- value: t,
134
- locale: o,
135
- withoutSuffix: p,
136
- from: d,
137
- to: x,
138
- type: i === "all" ? "utc" : i,
139
- tz: l,
140
- relativeRange: m,
141
- format: v
142
- }), u = /* @__PURE__ */ I(
143
- a,
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
- ...r,
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(r.sx) ? r.sx : [r.sx]
156
+ ...Array.isArray(l.sx) ? l.sx : [l.sx]
153
157
  ],
154
158
  children: [
155
- /* @__PURE__ */ n(a, { component: "span", ...r, sx: {}, children: U }),
156
- /* @__PURE__ */ n(a, { component: "span", sx: { color: "inherit" }, children: "·" }),
157
- /* @__PURE__ */ n(a, { component: "span", sx: { color: "inherit" }, children: e }),
158
- !C && /* @__PURE__ */ I(F, { children: [
159
- /* @__PURE__ */ n(a, { component: "span", sx: { color: "inherit" }, children: "·" }),
160
- /* @__PURE__ */ n(z, { locale: o, isUtc: c, setIsUtc: f, useShortTimezone: D })
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 L === "daysLeft" ? /* @__PURE__ */ n(M, { title: u, placement: T, enterTouchDelay: 0, children: /* @__PURE__ */ n(a, { component: "span", children: e }) }) : i === "all" && L === "all" ? /* @__PURE__ */ n(M, { title: void 0, placement: T, enterTouchDelay: 0, children: u }) : /* @__PURE__ */ n(M, { title: g ? h : void 0, placement: T, enterTouchDelay: 0, children: /* @__PURE__ */ I(
166
- a,
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__ */ n(a, { component: "span", ...r, children: U }),
175
- i === "utc" && !C && /* @__PURE__ */ n(z, { locale: o, isUtc: c, setIsUtc: f, useShortTimezone: D })
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
- et as default
185
+ oe as default
182
186
  };
@@ -26,15 +26,7 @@ export declare const LOGIN_PROVIDER: {
26
26
  TWITTER: string;
27
27
  };
28
28
  export declare const LOGIN_PROVIDER_NAME: {
29
- [LOGIN_PROVIDER.EMAIL]: string;
30
- [LOGIN_PROVIDER.AUTH0]: string;
31
- [LOGIN_PROVIDER.APPLE]: string;
32
- [LOGIN_PROVIDER.GITHUB]: string;
33
- [LOGIN_PROVIDER.GOOGLE]: string;
34
- [LOGIN_PROVIDER.WALLET]: string;
35
- [LOGIN_PROVIDER.NFT]: string;
36
- [LOGIN_PROVIDER.PASSKEY]: string;
37
- [LOGIN_PROVIDER.TWITTER]: string;
29
+ [x: string]: string;
38
30
  };
39
31
  export declare const OAUTH_PROVIDER: {
40
32
  email: string;
@@ -1,4 +1,4 @@
1
- const e = "3.2.5", s = { "@blocklet/js-sdk": "1.17.1" }, n = {
1
+ const e = "3.2.7", s = { "@blocklet/js-sdk": "1.17.2" }, n = {
2
2
  version: e,
3
3
  dependencies: s
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "3.2.5",
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": "8fe09067fd88bc4fd7fe300c984b2b4775fcd128",
71
+ "gitHead": "756a9f08c4008f45690ef38e612e1c429855948d",
72
72
  "dependencies": {
73
- "@arcblock/bridge": "3.2.5",
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.5",
77
- "@arcblock/nft-display": "3.2.5",
78
- "@arcblock/react-hooks": "3.2.5",
79
- "@blocklet/js-sdk": "1.17.1",
80
- "@blocklet/theme": "3.2.5",
76
+ "@arcblock/icons": "3.2.7",
77
+ "@arcblock/nft-display": "3.2.7",
78
+ "@arcblock/react-hooks": "3.2.7",
79
+ "@blocklet/js-sdk": "1.17.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 localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
119
- let datetime = dayjs(value).locale(localeOption);
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 = dayjs(value).utc().locale(localeOption);
144
+ datetime = datetime.utc();
123
145
  }
124
146
 
125
147
  if (tz) {
126
148
  datetime = datetime.tz(tz);
127
149
  }
128
150
 
129
- const absoluteString = formatToDatetime(value, { locale: localeOption, tz, format });
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(value, { locale: localeOption, tz, isUtc: true, format });
159
- popContent = formatToDatetime(value, { locale: localeOption, tz, isUtc: true, format });
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;