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