@gz-fronted/gz-pc 0.1.2 → 0.1.3-beta.1
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 +27 -10
- package/dist/fetch/index.cjs +682 -35
- package/dist/fetch/index.js +684 -37
- package/package.json +99 -99
package/dist/fetch/index.cjs
CHANGED
|
@@ -10,6 +10,120 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
10
10
|
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
11
11
|
|
|
12
12
|
// src/fetch/client.ts
|
|
13
|
+
|
|
14
|
+
// src/fetch/debug.ts
|
|
15
|
+
var EMPTY_DEBUG_DRAWER_SNAPSHOT = {
|
|
16
|
+
activeHostId: void 0,
|
|
17
|
+
errors: [],
|
|
18
|
+
open: false,
|
|
19
|
+
selectedErrorId: void 0
|
|
20
|
+
};
|
|
21
|
+
var debugErrorSequence = 0;
|
|
22
|
+
var snapshot = EMPTY_DEBUG_DRAWER_SNAPSHOT;
|
|
23
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
24
|
+
var drawerHosts = /* @__PURE__ */ new Set();
|
|
25
|
+
var emitChange = () => {
|
|
26
|
+
for (const listener of listeners) {
|
|
27
|
+
listener();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var setSnapshot = (nextSnapshot) => {
|
|
31
|
+
snapshot = nextSnapshot;
|
|
32
|
+
emitChange();
|
|
33
|
+
};
|
|
34
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35
|
+
var getResponseDebugInfo = (responseData) => {
|
|
36
|
+
if (!isRecord(responseData) || !isRecord(responseData.debug)) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
return responseData.debug;
|
|
40
|
+
};
|
|
41
|
+
var isDebugEnabled = () => {
|
|
42
|
+
if (typeof window === "undefined") {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
if (new URLSearchParams(window.location.search).get("showDebug") === "1") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return window.localStorage.getItem("showDebug") === "1";
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var subscribeDebugDrawer = (listener) => {
|
|
58
|
+
listeners.add(listener);
|
|
59
|
+
return () => listeners.delete(listener);
|
|
60
|
+
};
|
|
61
|
+
var getDebugDrawerSnapshot = () => snapshot;
|
|
62
|
+
var getDebugDrawerServerSnapshot = () => EMPTY_DEBUG_DRAWER_SNAPSHOT;
|
|
63
|
+
var registerDebugDrawerHost = (hostId) => {
|
|
64
|
+
drawerHosts.add(hostId);
|
|
65
|
+
if (snapshot.activeHostId === void 0) {
|
|
66
|
+
setSnapshot({ ...snapshot, activeHostId: hostId });
|
|
67
|
+
}
|
|
68
|
+
return () => {
|
|
69
|
+
drawerHosts.delete(hostId);
|
|
70
|
+
if (snapshot.activeHostId !== hostId) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const nextHost = drawerHosts.values().next();
|
|
74
|
+
setSnapshot({
|
|
75
|
+
...snapshot,
|
|
76
|
+
activeHostId: nextHost.done ? void 0 : nextHost.value
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
var showFetchDebugError = (input) => {
|
|
81
|
+
if (snapshot.activeHostId === void 0) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
debugErrorSequence += 1;
|
|
85
|
+
const error = {
|
|
86
|
+
...input,
|
|
87
|
+
id: `${Date.now()}-${debugErrorSequence}`
|
|
88
|
+
};
|
|
89
|
+
setSnapshot({
|
|
90
|
+
...snapshot,
|
|
91
|
+
errors: [error, ...snapshot.errors],
|
|
92
|
+
open: true,
|
|
93
|
+
selectedErrorId: error.id
|
|
94
|
+
});
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
var closeDebugDrawer = () => {
|
|
98
|
+
if (snapshot.open) {
|
|
99
|
+
setSnapshot({ ...snapshot, open: false });
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var removeDebugError = (id) => {
|
|
103
|
+
var _a, _b, _c, _d;
|
|
104
|
+
const removedIndex = snapshot.errors.findIndex((error) => error.id === id);
|
|
105
|
+
if (removedIndex === -1) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const errors = snapshot.errors.filter((error) => error.id !== id);
|
|
109
|
+
const selectedErrorId = snapshot.selectedErrorId === id ? (_c = (_a = errors[removedIndex]) == null ? void 0 : _a.id) != null ? _c : (_b = errors[removedIndex - 1]) == null ? void 0 : _b.id : snapshot.selectedErrorId && errors.some((error) => error.id === snapshot.selectedErrorId) ? snapshot.selectedErrorId : (_d = errors[0]) == null ? void 0 : _d.id;
|
|
110
|
+
setSnapshot({
|
|
111
|
+
...snapshot,
|
|
112
|
+
errors,
|
|
113
|
+
selectedErrorId
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
var selectDebugError = (id) => {
|
|
117
|
+
if (snapshot.selectedErrorId === id || !snapshot.errors.some((error) => error.id === id)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
setSnapshot({ ...snapshot, selectedErrorId: id });
|
|
121
|
+
};
|
|
122
|
+
var clearDebugErrors = () => {
|
|
123
|
+
if (snapshot.errors.length > 0) {
|
|
124
|
+
setSnapshot({ ...snapshot, errors: [], selectedErrorId: void 0 });
|
|
125
|
+
}
|
|
126
|
+
};
|
|
13
127
|
var GzFetchError = class extends Error {
|
|
14
128
|
constructor(message3, options) {
|
|
15
129
|
super(message3);
|
|
@@ -93,6 +207,14 @@ var showFetchErrorMessage = (content) => {
|
|
|
93
207
|
}
|
|
94
208
|
ggUi.message.error(content);
|
|
95
209
|
};
|
|
210
|
+
var showFetchSuccessMessage = (content) => {
|
|
211
|
+
const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
|
|
212
|
+
if (activeHost == null ? void 0 : activeHost.showSuccessMessage) {
|
|
213
|
+
activeHost.showSuccessMessage(content);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
ggUi.message.success(content);
|
|
217
|
+
};
|
|
96
218
|
|
|
97
219
|
// src/fetch/middleware.ts
|
|
98
220
|
async function runRequestMiddlewares(initialConfig, middlewares) {
|
|
@@ -125,17 +247,17 @@ var DEFAULT_UNAUTHORIZED_LOGIN_URL = "/login";
|
|
|
125
247
|
var DEFAULT_UNAUTHORIZED_MODAL_TITLE = "登录失效";
|
|
126
248
|
var DEFAULT_UNAUTHORIZED_MODAL_MESSAGE = "当前登录状态已失效,请重新登录。";
|
|
127
249
|
var IDLE_SNAPSHOT = { phase: "idle" };
|
|
128
|
-
var
|
|
129
|
-
var
|
|
250
|
+
var snapshot2 = IDLE_SNAPSHOT;
|
|
251
|
+
var listeners2 = /* @__PURE__ */ new Set();
|
|
130
252
|
var modalHosts = /* @__PURE__ */ new Set();
|
|
131
|
-
var
|
|
132
|
-
for (const listener of
|
|
253
|
+
var emitChange2 = () => {
|
|
254
|
+
for (const listener of listeners2) {
|
|
133
255
|
listener();
|
|
134
256
|
}
|
|
135
257
|
};
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
258
|
+
var setSnapshot2 = (nextSnapshot) => {
|
|
259
|
+
snapshot2 = nextSnapshot;
|
|
260
|
+
emitChange2();
|
|
139
261
|
};
|
|
140
262
|
var resolveUnauthorizedOptions = (options) => {
|
|
141
263
|
var _a, _b, _c, _d;
|
|
@@ -147,66 +269,66 @@ var resolveUnauthorizedOptions = (options) => {
|
|
|
147
269
|
...(options == null ? void 0 : options.onUnauthorized) === void 0 ? {} : { onUnauthorized: options.onUnauthorized }
|
|
148
270
|
};
|
|
149
271
|
};
|
|
150
|
-
var getUnauthorizedSnapshot = () =>
|
|
272
|
+
var getUnauthorizedSnapshot = () => snapshot2;
|
|
151
273
|
var getUnauthorizedServerSnapshot = () => IDLE_SNAPSHOT;
|
|
152
274
|
var subscribeUnauthorized = (listener) => {
|
|
153
|
-
|
|
154
|
-
return () =>
|
|
275
|
+
listeners2.add(listener);
|
|
276
|
+
return () => listeners2.delete(listener);
|
|
155
277
|
};
|
|
156
278
|
var registerUnauthorizedModalHost = (hostId) => {
|
|
157
279
|
modalHosts.add(hostId);
|
|
158
|
-
if (
|
|
159
|
-
|
|
280
|
+
if (snapshot2.activeHostId === void 0) {
|
|
281
|
+
setSnapshot2({ ...snapshot2, activeHostId: hostId });
|
|
160
282
|
}
|
|
161
283
|
return () => {
|
|
162
284
|
modalHosts.delete(hostId);
|
|
163
|
-
if (
|
|
285
|
+
if (snapshot2.activeHostId !== hostId) {
|
|
164
286
|
return;
|
|
165
287
|
}
|
|
166
288
|
const nextHost = modalHosts.values().next();
|
|
167
289
|
const nextHostId = nextHost.done ? void 0 : nextHost.value;
|
|
168
|
-
if (
|
|
169
|
-
|
|
290
|
+
if (snapshot2.phase === "closing") {
|
|
291
|
+
setSnapshot2(
|
|
170
292
|
nextHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: nextHostId, phase: "idle" }
|
|
171
293
|
);
|
|
172
294
|
return;
|
|
173
295
|
}
|
|
174
296
|
if (nextHostId === void 0) {
|
|
175
|
-
|
|
176
|
-
|
|
297
|
+
setSnapshot2(
|
|
298
|
+
snapshot2.options === void 0 ? { phase: snapshot2.phase } : { options: snapshot2.options, phase: snapshot2.phase }
|
|
177
299
|
);
|
|
178
300
|
return;
|
|
179
301
|
}
|
|
180
|
-
|
|
302
|
+
setSnapshot2({ ...snapshot2, activeHostId: nextHostId });
|
|
181
303
|
};
|
|
182
304
|
};
|
|
183
305
|
var openUnauthorizedModal = (options) => {
|
|
184
|
-
if (!options.enabled ||
|
|
306
|
+
if (!options.enabled || snapshot2.phase !== "idle") {
|
|
185
307
|
return false;
|
|
186
308
|
}
|
|
187
|
-
|
|
188
|
-
...
|
|
309
|
+
setSnapshot2({
|
|
310
|
+
...snapshot2.activeHostId === void 0 ? {} : { activeHostId: snapshot2.activeHostId },
|
|
189
311
|
options,
|
|
190
312
|
phase: "open"
|
|
191
313
|
});
|
|
192
314
|
return true;
|
|
193
315
|
};
|
|
194
316
|
var beginCloseUnauthorizedModal = () => {
|
|
195
|
-
if (
|
|
317
|
+
if (snapshot2.phase !== "open" || snapshot2.options === void 0) {
|
|
196
318
|
return void 0;
|
|
197
319
|
}
|
|
198
|
-
const { options } =
|
|
199
|
-
|
|
320
|
+
const { options } = snapshot2;
|
|
321
|
+
setSnapshot2({ ...snapshot2, phase: "closing" });
|
|
200
322
|
return options;
|
|
201
323
|
};
|
|
202
324
|
var cancelUnauthorizedModal = () => beginCloseUnauthorizedModal() !== void 0;
|
|
203
325
|
var confirmUnauthorizedModal = () => beginCloseUnauthorizedModal();
|
|
204
326
|
var completeUnauthorizedModal = () => {
|
|
205
|
-
if (
|
|
327
|
+
if (snapshot2.phase !== "closing") {
|
|
206
328
|
return;
|
|
207
329
|
}
|
|
208
|
-
|
|
209
|
-
|
|
330
|
+
setSnapshot2(
|
|
331
|
+
snapshot2.activeHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: snapshot2.activeHostId, phase: "idle" }
|
|
210
332
|
);
|
|
211
333
|
};
|
|
212
334
|
var executeUnauthorizedAction = (options, navigate = (loginUrl) => window.location.assign(loginUrl)) => {
|
|
@@ -285,7 +407,17 @@ function createGzFetch(options = {}) {
|
|
|
285
407
|
await runErrorMiddlewares(error, { config: currentConfig }, middlewares);
|
|
286
408
|
const shouldShowError = (_a2 = currentConfig.showErrorMessage) != null ? _a2 : showInstanceErrorMessage;
|
|
287
409
|
if (shouldShowError && error.type !== "CANCELED_ERROR" && !shouldHandleUnauthorized) {
|
|
288
|
-
|
|
410
|
+
const debugInfo = error.type === "HTTP_ERROR" && error.status !== 401 && isDebugEnabled() ? getResponseDebugInfo(error.responseData) : void 0;
|
|
411
|
+
const didShowDebugError = debugInfo === void 0 ? false : showFetchDebugError({
|
|
412
|
+
debug: debugInfo,
|
|
413
|
+
message: error.message,
|
|
414
|
+
method: currentConfig.method,
|
|
415
|
+
responseData: error.responseData,
|
|
416
|
+
url: currentConfig.url
|
|
417
|
+
});
|
|
418
|
+
if (!didShowDebugError) {
|
|
419
|
+
showFetchErrorMessage(error.message);
|
|
420
|
+
}
|
|
289
421
|
}
|
|
290
422
|
throw error;
|
|
291
423
|
}
|
|
@@ -320,18 +452,526 @@ async function gzFetch(config) {
|
|
|
320
452
|
}
|
|
321
453
|
return defaultClient(config);
|
|
322
454
|
}
|
|
455
|
+
var EMPTY_DEBUG_VALUE = "(无)";
|
|
456
|
+
var formatDebugValue = (value) => {
|
|
457
|
+
if (typeof value === "string") {
|
|
458
|
+
return value;
|
|
459
|
+
}
|
|
460
|
+
if (value === void 0 || value === null) {
|
|
461
|
+
return EMPTY_DEBUG_VALUE;
|
|
462
|
+
}
|
|
463
|
+
try {
|
|
464
|
+
const serialized = JSON.stringify(value, null, 2);
|
|
465
|
+
return serialized != null ? serialized : "(无法序列化)";
|
|
466
|
+
} catch (e) {
|
|
467
|
+
return "(无法序列化)";
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
var formatCompleteDebugResponse = (error) => formatDebugValue(error.responseData);
|
|
471
|
+
var copyDebugText = async (text) => {
|
|
472
|
+
var _a;
|
|
473
|
+
try {
|
|
474
|
+
if (typeof navigator !== "undefined" && ((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
|
|
475
|
+
await navigator.clipboard.writeText(text);
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
} catch (e) {
|
|
479
|
+
}
|
|
480
|
+
if (typeof document === "undefined" || !document.body || typeof document.execCommand !== "function") {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const textarea = document.createElement("textarea");
|
|
484
|
+
textarea.value = text;
|
|
485
|
+
textarea.setAttribute("readonly", "");
|
|
486
|
+
textarea.style.position = "fixed";
|
|
487
|
+
textarea.style.opacity = "0";
|
|
488
|
+
document.body.appendChild(textarea);
|
|
489
|
+
let copied = false;
|
|
490
|
+
try {
|
|
491
|
+
textarea.focus();
|
|
492
|
+
textarea.select();
|
|
493
|
+
copied = document.execCommand("copy");
|
|
494
|
+
} catch (e) {
|
|
495
|
+
copied = false;
|
|
496
|
+
} finally {
|
|
497
|
+
document.body.removeChild(textarea);
|
|
498
|
+
}
|
|
499
|
+
return copied;
|
|
500
|
+
};
|
|
501
|
+
var codeBlockStyle = {
|
|
502
|
+
background: "var(--gz-color-bg-field, rgba(127, 127, 127, 0.08))",
|
|
503
|
+
border: "0",
|
|
504
|
+
borderRadius: 6,
|
|
505
|
+
boxSizing: "border-box",
|
|
506
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
|
|
507
|
+
lineHeight: 1.5,
|
|
508
|
+
margin: 0,
|
|
509
|
+
minHeight: 0,
|
|
510
|
+
overflow: "auto",
|
|
511
|
+
overflowWrap: "anywhere",
|
|
512
|
+
padding: 16,
|
|
513
|
+
whiteSpace: "pre-wrap"
|
|
514
|
+
};
|
|
515
|
+
var methodTagColors = {
|
|
516
|
+
DELETE: "red",
|
|
517
|
+
GET: "green",
|
|
518
|
+
PATCH: "purple",
|
|
519
|
+
POST: "gold",
|
|
520
|
+
PUT: "blue"
|
|
521
|
+
};
|
|
522
|
+
var getHttpMethodTagColor = (method) => {
|
|
523
|
+
const normalizedMethod = method == null ? void 0 : method.toUpperCase();
|
|
524
|
+
return normalizedMethod === void 0 ? void 0 : methodTagColors[normalizedMethod];
|
|
525
|
+
};
|
|
526
|
+
var HttpMethodTag = ({ method }) => {
|
|
527
|
+
var _a;
|
|
528
|
+
const normalizedMethod = (_a = method == null ? void 0 : method.toUpperCase()) != null ? _a : "--";
|
|
529
|
+
const color = getHttpMethodTagColor(method);
|
|
530
|
+
return color ? /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tag, { color, children: normalizedMethod }) : /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tag, { children: normalizedMethod });
|
|
531
|
+
};
|
|
532
|
+
var DebugCodeBlock = ({ onCopy, value }) => {
|
|
533
|
+
const canCopy = value !== void 0 && value !== null;
|
|
534
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
535
|
+
"div",
|
|
536
|
+
{
|
|
537
|
+
style: {
|
|
538
|
+
height: "100%",
|
|
539
|
+
minHeight: 0,
|
|
540
|
+
overflow: "auto",
|
|
541
|
+
position: "relative"
|
|
542
|
+
},
|
|
543
|
+
children: [
|
|
544
|
+
canCopy ? /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: "复制", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
545
|
+
ggUi.Button,
|
|
546
|
+
{
|
|
547
|
+
"aria-label": "复制",
|
|
548
|
+
size: "middle",
|
|
549
|
+
style: {
|
|
550
|
+
paddingInline: 12,
|
|
551
|
+
position: "absolute",
|
|
552
|
+
right: 8,
|
|
553
|
+
top: 8,
|
|
554
|
+
zIndex: 1
|
|
555
|
+
},
|
|
556
|
+
type: "primary",
|
|
557
|
+
onClick: onCopy,
|
|
558
|
+
children: "复制"
|
|
559
|
+
}
|
|
560
|
+
) }) : null,
|
|
561
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
562
|
+
"pre",
|
|
563
|
+
{
|
|
564
|
+
style: {
|
|
565
|
+
...codeBlockStyle,
|
|
566
|
+
paddingRight: canCopy ? 88 : codeBlockStyle.padding
|
|
567
|
+
},
|
|
568
|
+
children: formatDebugValue(value)
|
|
569
|
+
}
|
|
570
|
+
)
|
|
571
|
+
]
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
};
|
|
575
|
+
var DebugErrorListItem = ({ error, index, selected, total }) => {
|
|
576
|
+
var _a, _b;
|
|
577
|
+
const handleRemove = (event) => {
|
|
578
|
+
event.stopPropagation();
|
|
579
|
+
removeDebugError(error.id);
|
|
580
|
+
};
|
|
581
|
+
const handleKeyDown = (event) => {
|
|
582
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
583
|
+
event.preventDefault();
|
|
584
|
+
selectDebugError(error.id);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
588
|
+
"div",
|
|
589
|
+
{
|
|
590
|
+
"aria-selected": selected,
|
|
591
|
+
role: "button",
|
|
592
|
+
tabIndex: 0,
|
|
593
|
+
title: error.url,
|
|
594
|
+
onClick: () => selectDebugError(error.id),
|
|
595
|
+
onKeyDown: handleKeyDown,
|
|
596
|
+
style: {
|
|
597
|
+
background: selected ? "var(--gz-color-bg-field, rgba(127, 127, 127, 0.12))" : "transparent",
|
|
598
|
+
borderRadius: 6,
|
|
599
|
+
cursor: "pointer",
|
|
600
|
+
display: "flex",
|
|
601
|
+
flexDirection: "column",
|
|
602
|
+
gap: 6,
|
|
603
|
+
margin: "0 8px",
|
|
604
|
+
minWidth: 0,
|
|
605
|
+
padding: "10px 8px",
|
|
606
|
+
position: "relative"
|
|
607
|
+
},
|
|
608
|
+
children: [
|
|
609
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
610
|
+
"span",
|
|
611
|
+
{
|
|
612
|
+
"aria-hidden": "true",
|
|
613
|
+
style: {
|
|
614
|
+
background: selected ? "var(--gz-color-primary, var(--gz-color-primary-border, rgba(127, 127, 127, 0.24)))" : "transparent",
|
|
615
|
+
borderRadius: 2,
|
|
616
|
+
bottom: 8,
|
|
617
|
+
left: 0,
|
|
618
|
+
pointerEvents: "none",
|
|
619
|
+
position: "absolute",
|
|
620
|
+
top: 8,
|
|
621
|
+
width: 3
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
),
|
|
625
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
626
|
+
"div",
|
|
627
|
+
{
|
|
628
|
+
style: {
|
|
629
|
+
alignItems: "center",
|
|
630
|
+
display: "flex",
|
|
631
|
+
gap: 8,
|
|
632
|
+
minWidth: 0
|
|
633
|
+
},
|
|
634
|
+
children: [
|
|
635
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "var(--gz-color-text-secondary)", flex: "0 0 auto" }, children: [
|
|
636
|
+
"#",
|
|
637
|
+
total - index
|
|
638
|
+
] }),
|
|
639
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { flex: "0 0 58px", minWidth: 58 }, children: /* @__PURE__ */ jsxRuntime.jsx(HttpMethodTag, { method: error.method }) }),
|
|
640
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
641
|
+
"span",
|
|
642
|
+
{
|
|
643
|
+
style: {
|
|
644
|
+
display: "block",
|
|
645
|
+
flex: "1 1 auto",
|
|
646
|
+
minWidth: 0,
|
|
647
|
+
overflow: "hidden"
|
|
648
|
+
},
|
|
649
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: (_a = error.url) != null ? _a : "--", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
650
|
+
"code",
|
|
651
|
+
{
|
|
652
|
+
style: {
|
|
653
|
+
color: "var(--gz-color-text-secondary)",
|
|
654
|
+
direction: "rtl",
|
|
655
|
+
display: "block",
|
|
656
|
+
minWidth: 0,
|
|
657
|
+
overflow: "hidden",
|
|
658
|
+
textAlign: "left",
|
|
659
|
+
textOverflow: "ellipsis",
|
|
660
|
+
whiteSpace: "nowrap"
|
|
661
|
+
},
|
|
662
|
+
children: (_b = error.url) != null ? _b : "--"
|
|
663
|
+
}
|
|
664
|
+
) })
|
|
665
|
+
}
|
|
666
|
+
),
|
|
667
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { flex: "0 0 24px", width: 24 }, children: /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: "关闭此条", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
668
|
+
ggUi.Button,
|
|
669
|
+
{
|
|
670
|
+
"aria-label": "关闭此条",
|
|
671
|
+
size: "small",
|
|
672
|
+
style: { padding: 0, width: 24 },
|
|
673
|
+
type: "text",
|
|
674
|
+
onClick: handleRemove,
|
|
675
|
+
children: "×"
|
|
676
|
+
}
|
|
677
|
+
) }) })
|
|
678
|
+
]
|
|
679
|
+
}
|
|
680
|
+
),
|
|
681
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
682
|
+
"div",
|
|
683
|
+
{
|
|
684
|
+
style: {
|
|
685
|
+
display: "-webkit-box",
|
|
686
|
+
overflow: "hidden",
|
|
687
|
+
overflowWrap: "anywhere",
|
|
688
|
+
WebkitBoxOrient: "vertical",
|
|
689
|
+
WebkitLineClamp: 2
|
|
690
|
+
},
|
|
691
|
+
children: error.message
|
|
692
|
+
}
|
|
693
|
+
)
|
|
694
|
+
]
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
};
|
|
698
|
+
var debugTabKeys = ["request", "stackTrace", "mdc"];
|
|
699
|
+
var isDebugTabKey = (value) => debugTabKeys.includes(value);
|
|
700
|
+
var DebugErrorDetails = ({ error }) => {
|
|
701
|
+
var _a, _b;
|
|
702
|
+
const [activeTab, setActiveTab] = react.useState("request");
|
|
703
|
+
const canCopyCompleteResponse = error.responseData !== void 0 && error.responseData !== null;
|
|
704
|
+
const values = {
|
|
705
|
+
mdc: error.debug.mdc,
|
|
706
|
+
request: error.debug.request,
|
|
707
|
+
stackTrace: error.debug.stackTrace
|
|
708
|
+
};
|
|
709
|
+
const handleCopy = async (value) => {
|
|
710
|
+
if (value === void 0 || value === null) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const copied = await copyDebugText(formatDebugValue(value));
|
|
714
|
+
if (copied) {
|
|
715
|
+
showFetchSuccessMessage("已复制");
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
showFetchErrorMessage("复制失败");
|
|
719
|
+
};
|
|
720
|
+
const handleCopyCompleteResponse = async () => {
|
|
721
|
+
const copied = await copyDebugText(formatCompleteDebugResponse(error));
|
|
722
|
+
if (copied) {
|
|
723
|
+
showFetchSuccessMessage("完整响应信息已复制");
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
showFetchErrorMessage("复制失败");
|
|
727
|
+
};
|
|
728
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
729
|
+
"div",
|
|
730
|
+
{
|
|
731
|
+
style: {
|
|
732
|
+
display: "flex",
|
|
733
|
+
flexDirection: "column",
|
|
734
|
+
height: "100%",
|
|
735
|
+
minHeight: 0,
|
|
736
|
+
minWidth: 0
|
|
737
|
+
},
|
|
738
|
+
children: [
|
|
739
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: "0 0 auto", marginBottom: 16, minWidth: 0 }, children: [
|
|
740
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
741
|
+
"div",
|
|
742
|
+
{
|
|
743
|
+
style: { alignItems: "flex-start", display: "flex", gap: 8, minWidth: 0 },
|
|
744
|
+
children: [
|
|
745
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
746
|
+
"strong",
|
|
747
|
+
{
|
|
748
|
+
style: {
|
|
749
|
+
display: "block",
|
|
750
|
+
flex: "1 1 auto",
|
|
751
|
+
fontSize: 16,
|
|
752
|
+
minWidth: 0,
|
|
753
|
+
overflowWrap: "anywhere"
|
|
754
|
+
},
|
|
755
|
+
children: error.message
|
|
756
|
+
}
|
|
757
|
+
),
|
|
758
|
+
canCopyCompleteResponse ? /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: "复制完整响应信息", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
759
|
+
ggUi.Button,
|
|
760
|
+
{
|
|
761
|
+
"aria-label": "复制完整响应信息",
|
|
762
|
+
size: "middle",
|
|
763
|
+
style: { flex: "0 0 auto", paddingInline: 12 },
|
|
764
|
+
type: "primary",
|
|
765
|
+
onClick: () => {
|
|
766
|
+
void handleCopyCompleteResponse();
|
|
767
|
+
},
|
|
768
|
+
children: "复制完整响应"
|
|
769
|
+
}
|
|
770
|
+
) }) : null
|
|
771
|
+
]
|
|
772
|
+
}
|
|
773
|
+
),
|
|
774
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
775
|
+
"div",
|
|
776
|
+
{
|
|
777
|
+
style: {
|
|
778
|
+
alignItems: "center",
|
|
779
|
+
display: "flex",
|
|
780
|
+
gap: 8,
|
|
781
|
+
marginTop: 8,
|
|
782
|
+
minWidth: 0
|
|
783
|
+
},
|
|
784
|
+
children: [
|
|
785
|
+
/* @__PURE__ */ jsxRuntime.jsx(HttpMethodTag, { method: error.method }),
|
|
786
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
787
|
+
"code",
|
|
788
|
+
{
|
|
789
|
+
style: {
|
|
790
|
+
color: "var(--gz-color-text-secondary)",
|
|
791
|
+
display: "block",
|
|
792
|
+
minWidth: 0,
|
|
793
|
+
overflow: "hidden",
|
|
794
|
+
textOverflow: "ellipsis",
|
|
795
|
+
whiteSpace: "nowrap"
|
|
796
|
+
},
|
|
797
|
+
title: (_a = error.url) != null ? _a : "--",
|
|
798
|
+
children: (_b = error.url) != null ? _b : "--"
|
|
799
|
+
}
|
|
800
|
+
)
|
|
801
|
+
]
|
|
802
|
+
}
|
|
803
|
+
)
|
|
804
|
+
] }),
|
|
805
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
806
|
+
ggUi.Tabs,
|
|
807
|
+
{
|
|
808
|
+
activeKey: activeTab,
|
|
809
|
+
items: [
|
|
810
|
+
{
|
|
811
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
812
|
+
DebugCodeBlock,
|
|
813
|
+
{
|
|
814
|
+
onCopy: () => {
|
|
815
|
+
void handleCopy(values.request);
|
|
816
|
+
},
|
|
817
|
+
value: values.request
|
|
818
|
+
}
|
|
819
|
+
),
|
|
820
|
+
key: "request",
|
|
821
|
+
label: "Request"
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
825
|
+
DebugCodeBlock,
|
|
826
|
+
{
|
|
827
|
+
onCopy: () => {
|
|
828
|
+
void handleCopy(values.stackTrace);
|
|
829
|
+
},
|
|
830
|
+
value: values.stackTrace
|
|
831
|
+
}
|
|
832
|
+
),
|
|
833
|
+
key: "stackTrace",
|
|
834
|
+
label: "Stack Trace"
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
838
|
+
DebugCodeBlock,
|
|
839
|
+
{
|
|
840
|
+
onCopy: () => {
|
|
841
|
+
void handleCopy(values.mdc);
|
|
842
|
+
},
|
|
843
|
+
value: values.mdc
|
|
844
|
+
}
|
|
845
|
+
),
|
|
846
|
+
key: "mdc",
|
|
847
|
+
label: "MDC"
|
|
848
|
+
}
|
|
849
|
+
],
|
|
850
|
+
style: { display: "flex", flexDirection: "column", height: "100%", minHeight: 0 },
|
|
851
|
+
onChange: (key) => {
|
|
852
|
+
if (isDebugTabKey(key)) {
|
|
853
|
+
setActiveTab(key);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
)
|
|
858
|
+
]
|
|
859
|
+
}
|
|
860
|
+
);
|
|
861
|
+
};
|
|
862
|
+
var GzFetchDebugDrawer = () => {
|
|
863
|
+
var _a, _b;
|
|
864
|
+
const hostIdRef = react.useRef(void 0);
|
|
865
|
+
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-debug-drawer-host");
|
|
866
|
+
const hostId = hostIdRef.current;
|
|
867
|
+
const snapshot3 = react.useSyncExternalStore(
|
|
868
|
+
subscribeDebugDrawer,
|
|
869
|
+
getDebugDrawerSnapshot,
|
|
870
|
+
getDebugDrawerServerSnapshot
|
|
871
|
+
);
|
|
872
|
+
react.useEffect(() => registerDebugDrawerHost(hostId), [hostId]);
|
|
873
|
+
if (snapshot3.activeHostId !== hostId) {
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
const selectedError = (_b = snapshot3.errors.find((error) => error.id === snapshot3.selectedErrorId)) != null ? _b : snapshot3.errors[0];
|
|
877
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
878
|
+
ggUi.Drawer,
|
|
879
|
+
{
|
|
880
|
+
open: snapshot3.open,
|
|
881
|
+
placement: "right",
|
|
882
|
+
styles: { body: { overflow: "hidden", padding: 0 } },
|
|
883
|
+
title: `Debug Error (${snapshot3.errors.length})`,
|
|
884
|
+
extra: /* @__PURE__ */ jsxRuntime.jsx(
|
|
885
|
+
ggUi.Button,
|
|
886
|
+
{
|
|
887
|
+
disabled: snapshot3.errors.length === 0,
|
|
888
|
+
size: "middle",
|
|
889
|
+
style: { paddingInline: 12 },
|
|
890
|
+
type: "default",
|
|
891
|
+
onClick: clearDebugErrors,
|
|
892
|
+
children: "清空记录"
|
|
893
|
+
}
|
|
894
|
+
),
|
|
895
|
+
width: "min(calc(100vw - 32px), clamp(720px, 80vw, 1120px))",
|
|
896
|
+
onClose: closeDebugDrawer,
|
|
897
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
898
|
+
"div",
|
|
899
|
+
{
|
|
900
|
+
style: {
|
|
901
|
+
display: "flex",
|
|
902
|
+
height: "100%",
|
|
903
|
+
minHeight: 0,
|
|
904
|
+
minWidth: 0
|
|
905
|
+
},
|
|
906
|
+
children: [
|
|
907
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
908
|
+
"aside",
|
|
909
|
+
{
|
|
910
|
+
"aria-label": "Debug Error 列表",
|
|
911
|
+
style: {
|
|
912
|
+
borderRight: "1px solid var(--gz-color-border, rgba(127, 127, 127, 0.24))",
|
|
913
|
+
flex: "0 1 clamp(220px, 24vw, 320px)",
|
|
914
|
+
minHeight: 0,
|
|
915
|
+
overflowY: "auto",
|
|
916
|
+
padding: "6px 0",
|
|
917
|
+
width: "clamp(220px, 24vw, 320px)"
|
|
918
|
+
},
|
|
919
|
+
children: snapshot3.errors.length > 0 ? snapshot3.errors.map((error, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
920
|
+
DebugErrorListItem,
|
|
921
|
+
{
|
|
922
|
+
error,
|
|
923
|
+
index,
|
|
924
|
+
selected: error.id === (selectedError == null ? void 0 : selectedError.id),
|
|
925
|
+
total: snapshot3.errors.length
|
|
926
|
+
},
|
|
927
|
+
error.id
|
|
928
|
+
)) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
929
|
+
"div",
|
|
930
|
+
{
|
|
931
|
+
style: {
|
|
932
|
+
color: "var(--gz-color-text-secondary)",
|
|
933
|
+
padding: 16,
|
|
934
|
+
textAlign: "center"
|
|
935
|
+
},
|
|
936
|
+
children: "暂无 Debug Error"
|
|
937
|
+
}
|
|
938
|
+
)
|
|
939
|
+
}
|
|
940
|
+
),
|
|
941
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
942
|
+
"main",
|
|
943
|
+
{
|
|
944
|
+
"aria-label": "Debug Error 详情",
|
|
945
|
+
style: {
|
|
946
|
+
flex: "1 1 auto",
|
|
947
|
+
minHeight: 0,
|
|
948
|
+
minWidth: 0,
|
|
949
|
+
overflow: "hidden",
|
|
950
|
+
padding: 20
|
|
951
|
+
},
|
|
952
|
+
children: selectedError ? /* @__PURE__ */ jsxRuntime.jsx(DebugErrorDetails, { error: selectedError }, selectedError.id) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "var(--gz-color-text-secondary)" }, children: "暂无 Debug Error" })
|
|
953
|
+
}
|
|
954
|
+
)
|
|
955
|
+
]
|
|
956
|
+
}
|
|
957
|
+
)
|
|
958
|
+
}
|
|
959
|
+
);
|
|
960
|
+
};
|
|
961
|
+
GzFetchDebugDrawer.displayName = "GzFetchDebugDrawer";
|
|
962
|
+
var GzFetchDebugDrawer_default = GzFetchDebugDrawer;
|
|
323
963
|
var GzFetchUnauthorizedModal = () => {
|
|
324
964
|
var _a, _b, _c;
|
|
325
965
|
const hostIdRef = react.useRef(void 0);
|
|
326
966
|
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
|
|
327
967
|
const hostId = hostIdRef.current;
|
|
328
|
-
const
|
|
968
|
+
const snapshot3 = react.useSyncExternalStore(
|
|
329
969
|
subscribeUnauthorized,
|
|
330
970
|
getUnauthorizedSnapshot,
|
|
331
971
|
getUnauthorizedServerSnapshot
|
|
332
972
|
);
|
|
333
973
|
react.useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
|
|
334
|
-
if (
|
|
974
|
+
if (snapshot3.activeHostId !== hostId) {
|
|
335
975
|
return null;
|
|
336
976
|
}
|
|
337
977
|
const handleConfirm = () => {
|
|
@@ -347,11 +987,11 @@ var GzFetchUnauthorizedModal = () => {
|
|
|
347
987
|
cancelText: "取消",
|
|
348
988
|
closable: true,
|
|
349
989
|
okText: "重新登录",
|
|
350
|
-
open:
|
|
351
|
-
title: (_b =
|
|
990
|
+
open: snapshot3.phase === "open",
|
|
991
|
+
title: (_b = snapshot3.options) == null ? void 0 : _b.modalTitle,
|
|
352
992
|
onCancel: cancelUnauthorizedModal,
|
|
353
993
|
onOk: handleConfirm,
|
|
354
|
-
children: (_c =
|
|
994
|
+
children: (_c = snapshot3.options) == null ? void 0 : _c.modalMessage
|
|
355
995
|
}
|
|
356
996
|
);
|
|
357
997
|
};
|
|
@@ -369,12 +1009,19 @@ var GzFetchFeedbackProvider = ({ children }) => {
|
|
|
369
1009
|
},
|
|
370
1010
|
[messageApi]
|
|
371
1011
|
);
|
|
1012
|
+
const showSuccessMessage = react.useCallback(
|
|
1013
|
+
(content) => {
|
|
1014
|
+
void messageApi.success(content);
|
|
1015
|
+
},
|
|
1016
|
+
[messageApi]
|
|
1017
|
+
);
|
|
372
1018
|
react.useEffect(
|
|
373
|
-
() => registerFeedbackHost(hostId, { showErrorMessage }),
|
|
374
|
-
[hostId, showErrorMessage]
|
|
1019
|
+
() => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
|
|
1020
|
+
[hostId, showErrorMessage, showSuccessMessage]
|
|
375
1021
|
);
|
|
376
1022
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
377
1023
|
messageContextHolder,
|
|
1024
|
+
/* @__PURE__ */ jsxRuntime.jsx(GzFetchDebugDrawer_default, {}),
|
|
378
1025
|
/* @__PURE__ */ jsxRuntime.jsx(GzFetchUnauthorizedModal_default, {}),
|
|
379
1026
|
children
|
|
380
1027
|
] });
|