@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.
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var axios = require('axios');
4
- var ggUi = require('@chenhui996/gg-ui');
4
+ var gzUiWeb = require('gz-ui-web');
5
+ var losslessJson = require('lossless-json');
5
6
  var react = require('react');
6
7
  var jsxRuntime = require('react/jsx-runtime');
7
8
 
@@ -10,120 +11,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
11
  var axios__default = /*#__PURE__*/_interopDefault(axios);
11
12
 
12
13
  // 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
- };
127
14
  var GzFetchError = class extends Error {
128
15
  constructor(message3, options) {
129
16
  super(message3);
@@ -205,15 +92,7 @@ var showFetchErrorMessage = (content) => {
205
92
  activeHost.showErrorMessage(content);
206
93
  return;
207
94
  }
208
- ggUi.message.error(content);
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);
95
+ gzUiWeb.message.error(content);
217
96
  };
218
97
 
219
98
  // src/fetch/middleware.ts
@@ -241,23 +120,64 @@ async function runErrorMiddlewares(error, context, middlewares) {
241
120
  await ((_a = middleware.onError) == null ? void 0 : _a.call(middleware, error, context));
242
121
  }
243
122
  }
123
+ var JSON_TOKENS = /"(?:\\[\s\S]|[^"\\])*"|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/g;
124
+ function parseNumber(value) {
125
+ const number = Number(value);
126
+ return losslessJson.isSafeNumber(value) && (!Number.isInteger(number) || Number.isSafeInteger(number)) ? number : value;
127
+ }
128
+ var transformResponsePreservingNumbers = function(data, headers, status) {
129
+ if (typeof data !== "string" || data.length === 0 || this.responseType !== void 0 && this.responseType !== "json") {
130
+ return data;
131
+ }
132
+ try {
133
+ const preservedNumbers = /* @__PURE__ */ new Set();
134
+ losslessJson.parse(data, void 0, {
135
+ parseNumber(value) {
136
+ const parsed = parseNumber(value);
137
+ if (typeof parsed === "string") {
138
+ preservedNumbers.add(value);
139
+ }
140
+ return parsed;
141
+ },
142
+ onDuplicateKey: ({ newValue }) => newValue
143
+ });
144
+ const protectedJson = data.replace(
145
+ JSON_TOKENS,
146
+ (token) => preservedNumbers.has(token) ? JSON.stringify(token) : token
147
+ );
148
+ return JSON.parse(protectedJson);
149
+ } catch (error) {
150
+ if (!(error instanceof SyntaxError)) {
151
+ throw error;
152
+ }
153
+ }
154
+ const defaults = axios__default.default.defaults.transformResponse;
155
+ const transformers = Array.isArray(defaults) ? defaults : [defaults];
156
+ let result = data;
157
+ for (const transform of transformers) {
158
+ if (transform) {
159
+ result = transform.call(this, result, headers, status);
160
+ }
161
+ }
162
+ return result;
163
+ };
244
164
 
245
165
  // src/fetch/unauthorized.ts
246
166
  var DEFAULT_UNAUTHORIZED_LOGIN_URL = "/login";
247
167
  var DEFAULT_UNAUTHORIZED_MODAL_TITLE = "登录失效";
248
168
  var DEFAULT_UNAUTHORIZED_MODAL_MESSAGE = "当前登录状态已失效,请重新登录。";
249
169
  var IDLE_SNAPSHOT = { phase: "idle" };
250
- var snapshot2 = IDLE_SNAPSHOT;
251
- var listeners2 = /* @__PURE__ */ new Set();
170
+ var snapshot = IDLE_SNAPSHOT;
171
+ var listeners = /* @__PURE__ */ new Set();
252
172
  var modalHosts = /* @__PURE__ */ new Set();
253
- var emitChange2 = () => {
254
- for (const listener of listeners2) {
173
+ var emitChange = () => {
174
+ for (const listener of listeners) {
255
175
  listener();
256
176
  }
257
177
  };
258
- var setSnapshot2 = (nextSnapshot) => {
259
- snapshot2 = nextSnapshot;
260
- emitChange2();
178
+ var setSnapshot = (nextSnapshot) => {
179
+ snapshot = nextSnapshot;
180
+ emitChange();
261
181
  };
262
182
  var resolveUnauthorizedOptions = (options) => {
263
183
  var _a, _b, _c, _d;
@@ -269,66 +189,66 @@ var resolveUnauthorizedOptions = (options) => {
269
189
  ...(options == null ? void 0 : options.onUnauthorized) === void 0 ? {} : { onUnauthorized: options.onUnauthorized }
270
190
  };
271
191
  };
272
- var getUnauthorizedSnapshot = () => snapshot2;
192
+ var getUnauthorizedSnapshot = () => snapshot;
273
193
  var getUnauthorizedServerSnapshot = () => IDLE_SNAPSHOT;
274
194
  var subscribeUnauthorized = (listener) => {
275
- listeners2.add(listener);
276
- return () => listeners2.delete(listener);
195
+ listeners.add(listener);
196
+ return () => listeners.delete(listener);
277
197
  };
278
198
  var registerUnauthorizedModalHost = (hostId) => {
279
199
  modalHosts.add(hostId);
280
- if (snapshot2.activeHostId === void 0) {
281
- setSnapshot2({ ...snapshot2, activeHostId: hostId });
200
+ if (snapshot.activeHostId === void 0) {
201
+ setSnapshot({ ...snapshot, activeHostId: hostId });
282
202
  }
283
203
  return () => {
284
204
  modalHosts.delete(hostId);
285
- if (snapshot2.activeHostId !== hostId) {
205
+ if (snapshot.activeHostId !== hostId) {
286
206
  return;
287
207
  }
288
208
  const nextHost = modalHosts.values().next();
289
209
  const nextHostId = nextHost.done ? void 0 : nextHost.value;
290
- if (snapshot2.phase === "closing") {
291
- setSnapshot2(
210
+ if (snapshot.phase === "closing") {
211
+ setSnapshot(
292
212
  nextHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: nextHostId, phase: "idle" }
293
213
  );
294
214
  return;
295
215
  }
296
216
  if (nextHostId === void 0) {
297
- setSnapshot2(
298
- snapshot2.options === void 0 ? { phase: snapshot2.phase } : { options: snapshot2.options, phase: snapshot2.phase }
217
+ setSnapshot(
218
+ snapshot.options === void 0 ? { phase: snapshot.phase } : { options: snapshot.options, phase: snapshot.phase }
299
219
  );
300
220
  return;
301
221
  }
302
- setSnapshot2({ ...snapshot2, activeHostId: nextHostId });
222
+ setSnapshot({ ...snapshot, activeHostId: nextHostId });
303
223
  };
304
224
  };
305
225
  var openUnauthorizedModal = (options) => {
306
- if (!options.enabled || snapshot2.phase !== "idle") {
226
+ if (!options.enabled || snapshot.phase !== "idle") {
307
227
  return false;
308
228
  }
309
- setSnapshot2({
310
- ...snapshot2.activeHostId === void 0 ? {} : { activeHostId: snapshot2.activeHostId },
229
+ setSnapshot({
230
+ ...snapshot.activeHostId === void 0 ? {} : { activeHostId: snapshot.activeHostId },
311
231
  options,
312
232
  phase: "open"
313
233
  });
314
234
  return true;
315
235
  };
316
236
  var beginCloseUnauthorizedModal = () => {
317
- if (snapshot2.phase !== "open" || snapshot2.options === void 0) {
237
+ if (snapshot.phase !== "open" || snapshot.options === void 0) {
318
238
  return void 0;
319
239
  }
320
- const { options } = snapshot2;
321
- setSnapshot2({ ...snapshot2, phase: "closing" });
240
+ const { options } = snapshot;
241
+ setSnapshot({ ...snapshot, phase: "closing" });
322
242
  return options;
323
243
  };
324
244
  var cancelUnauthorizedModal = () => beginCloseUnauthorizedModal() !== void 0;
325
245
  var confirmUnauthorizedModal = () => beginCloseUnauthorizedModal();
326
246
  var completeUnauthorizedModal = () => {
327
- if (snapshot2.phase !== "closing") {
247
+ if (snapshot.phase !== "closing") {
328
248
  return;
329
249
  }
330
- setSnapshot2(
331
- snapshot2.activeHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: snapshot2.activeHostId, phase: "idle" }
250
+ setSnapshot(
251
+ snapshot.activeHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: snapshot.activeHostId, phase: "idle" }
332
252
  );
333
253
  };
334
254
  var executeUnauthorizedAction = (options, navigate = (loginUrl) => window.location.assign(loginUrl)) => {
@@ -362,7 +282,8 @@ function createGzFetch(options = {}) {
362
282
  const instance = axios__default.default.create({
363
283
  ...options.baseURL === void 0 ? {} : { baseURL: options.baseURL },
364
284
  timeout: (_g = options.timeout) != null ? _g : DEFAULT_TIMEOUT,
365
- validateStatus: (_h = options.validateStatus) != null ? _h : DEFAULT_VALIDATE_STATUS
285
+ validateStatus: (_h = options.validateStatus) != null ? _h : DEFAULT_VALIDATE_STATUS,
286
+ ...options.preserveNumberPrecision ? { transformResponse: [transformResponsePreservingNumbers] } : {}
366
287
  });
367
288
  async function request(initialConfig) {
368
289
  var _a2;
@@ -407,17 +328,7 @@ function createGzFetch(options = {}) {
407
328
  await runErrorMiddlewares(error, { config: currentConfig }, middlewares);
408
329
  const shouldShowError = (_a2 = currentConfig.showErrorMessage) != null ? _a2 : showInstanceErrorMessage;
409
330
  if (shouldShowError && error.type !== "CANCELED_ERROR" && !shouldHandleUnauthorized) {
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
- }
331
+ showFetchErrorMessage(error.message);
421
332
  }
422
333
  throw error;
423
334
  }
@@ -452,526 +363,18 @@ async function gzFetch(config) {
452
363
  }
453
364
  return defaultClient(config);
454
365
  }
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;
963
366
  var GzFetchUnauthorizedModal = () => {
964
367
  var _a, _b, _c;
965
368
  const hostIdRef = react.useRef(void 0);
966
369
  (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
967
370
  const hostId = hostIdRef.current;
968
- const snapshot3 = react.useSyncExternalStore(
371
+ const snapshot2 = react.useSyncExternalStore(
969
372
  subscribeUnauthorized,
970
373
  getUnauthorizedSnapshot,
971
374
  getUnauthorizedServerSnapshot
972
375
  );
973
376
  react.useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
974
- if (snapshot3.activeHostId !== hostId) {
377
+ if (snapshot2.activeHostId !== hostId) {
975
378
  return null;
976
379
  }
977
380
  const handleConfirm = () => {
@@ -981,17 +384,17 @@ var GzFetchUnauthorizedModal = () => {
981
384
  }
982
385
  };
983
386
  return /* @__PURE__ */ jsxRuntime.jsx(
984
- ggUi.Modal,
387
+ gzUiWeb.Modal,
985
388
  {
986
389
  afterClose: completeUnauthorizedModal,
987
390
  cancelText: "取消",
988
391
  closable: true,
989
392
  okText: "重新登录",
990
- open: snapshot3.phase === "open",
991
- title: (_b = snapshot3.options) == null ? void 0 : _b.modalTitle,
393
+ open: snapshot2.phase === "open",
394
+ title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
992
395
  onCancel: cancelUnauthorizedModal,
993
396
  onOk: handleConfirm,
994
- children: (_c = snapshot3.options) == null ? void 0 : _c.modalMessage
397
+ children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
995
398
  }
996
399
  );
997
400
  };
@@ -1002,26 +405,19 @@ var GzFetchFeedbackProvider = ({ children }) => {
1002
405
  const hostIdRef = react.useRef(void 0);
1003
406
  (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-feedback-host");
1004
407
  const hostId = hostIdRef.current;
1005
- const [messageApi, messageContextHolder] = ggUi.message.useMessage();
408
+ const [messageApi, messageContextHolder] = gzUiWeb.message.useMessage();
1006
409
  const showErrorMessage = react.useCallback(
1007
410
  (content) => {
1008
411
  void messageApi.error(content);
1009
412
  },
1010
413
  [messageApi]
1011
414
  );
1012
- const showSuccessMessage = react.useCallback(
1013
- (content) => {
1014
- void messageApi.success(content);
1015
- },
1016
- [messageApi]
1017
- );
1018
415
  react.useEffect(
1019
- () => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
1020
- [hostId, showErrorMessage, showSuccessMessage]
416
+ () => registerFeedbackHost(hostId, { showErrorMessage }),
417
+ [hostId, showErrorMessage]
1021
418
  );
1022
419
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1023
420
  messageContextHolder,
1024
- /* @__PURE__ */ jsxRuntime.jsx(GzFetchDebugDrawer_default, {}),
1025
421
  /* @__PURE__ */ jsxRuntime.jsx(GzFetchUnauthorizedModal_default, {}),
1026
422
  children
1027
423
  ] });