@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.
@@ -1,9 +1,123 @@
1
1
  import axios, { AxiosError, AxiosHeaders } from 'axios';
2
- import { Modal, message } from '@chenhui996/gg-ui';
3
- import { useRef, useSyncExternalStore, useEffect, useCallback } from 'react';
2
+ import { Modal, message, Drawer, Button, Tooltip, Tabs, Tag } from '@chenhui996/gg-ui';
3
+ import { useRef, useSyncExternalStore, useEffect, useCallback, useState } from 'react';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
6
6
  // 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
+ };
7
121
  var GzFetchError = class extends Error {
8
122
  constructor(message3, options) {
9
123
  super(message3);
@@ -87,6 +201,14 @@ var showFetchErrorMessage = (content) => {
87
201
  }
88
202
  message.error(content);
89
203
  };
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
+ };
90
212
 
91
213
  // src/fetch/middleware.ts
92
214
  async function runRequestMiddlewares(initialConfig, middlewares) {
@@ -119,17 +241,17 @@ var DEFAULT_UNAUTHORIZED_LOGIN_URL = "/login";
119
241
  var DEFAULT_UNAUTHORIZED_MODAL_TITLE = "登录失效";
120
242
  var DEFAULT_UNAUTHORIZED_MODAL_MESSAGE = "当前登录状态已失效,请重新登录。";
121
243
  var IDLE_SNAPSHOT = { phase: "idle" };
122
- var snapshot = IDLE_SNAPSHOT;
123
- var listeners = /* @__PURE__ */ new Set();
244
+ var snapshot2 = IDLE_SNAPSHOT;
245
+ var listeners2 = /* @__PURE__ */ new Set();
124
246
  var modalHosts = /* @__PURE__ */ new Set();
125
- var emitChange = () => {
126
- for (const listener of listeners) {
247
+ var emitChange2 = () => {
248
+ for (const listener of listeners2) {
127
249
  listener();
128
250
  }
129
251
  };
130
- var setSnapshot = (nextSnapshot) => {
131
- snapshot = nextSnapshot;
132
- emitChange();
252
+ var setSnapshot2 = (nextSnapshot) => {
253
+ snapshot2 = nextSnapshot;
254
+ emitChange2();
133
255
  };
134
256
  var resolveUnauthorizedOptions = (options) => {
135
257
  var _a, _b, _c, _d;
@@ -141,66 +263,66 @@ var resolveUnauthorizedOptions = (options) => {
141
263
  ...(options == null ? void 0 : options.onUnauthorized) === void 0 ? {} : { onUnauthorized: options.onUnauthorized }
142
264
  };
143
265
  };
144
- var getUnauthorizedSnapshot = () => snapshot;
266
+ var getUnauthorizedSnapshot = () => snapshot2;
145
267
  var getUnauthorizedServerSnapshot = () => IDLE_SNAPSHOT;
146
268
  var subscribeUnauthorized = (listener) => {
147
- listeners.add(listener);
148
- return () => listeners.delete(listener);
269
+ listeners2.add(listener);
270
+ return () => listeners2.delete(listener);
149
271
  };
150
272
  var registerUnauthorizedModalHost = (hostId) => {
151
273
  modalHosts.add(hostId);
152
- if (snapshot.activeHostId === void 0) {
153
- setSnapshot({ ...snapshot, activeHostId: hostId });
274
+ if (snapshot2.activeHostId === void 0) {
275
+ setSnapshot2({ ...snapshot2, activeHostId: hostId });
154
276
  }
155
277
  return () => {
156
278
  modalHosts.delete(hostId);
157
- if (snapshot.activeHostId !== hostId) {
279
+ if (snapshot2.activeHostId !== hostId) {
158
280
  return;
159
281
  }
160
282
  const nextHost = modalHosts.values().next();
161
283
  const nextHostId = nextHost.done ? void 0 : nextHost.value;
162
- if (snapshot.phase === "closing") {
163
- setSnapshot(
284
+ if (snapshot2.phase === "closing") {
285
+ setSnapshot2(
164
286
  nextHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: nextHostId, phase: "idle" }
165
287
  );
166
288
  return;
167
289
  }
168
290
  if (nextHostId === void 0) {
169
- setSnapshot(
170
- snapshot.options === void 0 ? { phase: snapshot.phase } : { options: snapshot.options, phase: snapshot.phase }
291
+ setSnapshot2(
292
+ snapshot2.options === void 0 ? { phase: snapshot2.phase } : { options: snapshot2.options, phase: snapshot2.phase }
171
293
  );
172
294
  return;
173
295
  }
174
- setSnapshot({ ...snapshot, activeHostId: nextHostId });
296
+ setSnapshot2({ ...snapshot2, activeHostId: nextHostId });
175
297
  };
176
298
  };
177
299
  var openUnauthorizedModal = (options) => {
178
- if (!options.enabled || snapshot.phase !== "idle") {
300
+ if (!options.enabled || snapshot2.phase !== "idle") {
179
301
  return false;
180
302
  }
181
- setSnapshot({
182
- ...snapshot.activeHostId === void 0 ? {} : { activeHostId: snapshot.activeHostId },
303
+ setSnapshot2({
304
+ ...snapshot2.activeHostId === void 0 ? {} : { activeHostId: snapshot2.activeHostId },
183
305
  options,
184
306
  phase: "open"
185
307
  });
186
308
  return true;
187
309
  };
188
310
  var beginCloseUnauthorizedModal = () => {
189
- if (snapshot.phase !== "open" || snapshot.options === void 0) {
311
+ if (snapshot2.phase !== "open" || snapshot2.options === void 0) {
190
312
  return void 0;
191
313
  }
192
- const { options } = snapshot;
193
- setSnapshot({ ...snapshot, phase: "closing" });
314
+ const { options } = snapshot2;
315
+ setSnapshot2({ ...snapshot2, phase: "closing" });
194
316
  return options;
195
317
  };
196
318
  var cancelUnauthorizedModal = () => beginCloseUnauthorizedModal() !== void 0;
197
319
  var confirmUnauthorizedModal = () => beginCloseUnauthorizedModal();
198
320
  var completeUnauthorizedModal = () => {
199
- if (snapshot.phase !== "closing") {
321
+ if (snapshot2.phase !== "closing") {
200
322
  return;
201
323
  }
202
- setSnapshot(
203
- snapshot.activeHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: snapshot.activeHostId, phase: "idle" }
324
+ setSnapshot2(
325
+ snapshot2.activeHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: snapshot2.activeHostId, phase: "idle" }
204
326
  );
205
327
  };
206
328
  var executeUnauthorizedAction = (options, navigate = (loginUrl) => window.location.assign(loginUrl)) => {
@@ -279,7 +401,17 @@ function createGzFetch(options = {}) {
279
401
  await runErrorMiddlewares(error, { config: currentConfig }, middlewares);
280
402
  const shouldShowError = (_a2 = currentConfig.showErrorMessage) != null ? _a2 : showInstanceErrorMessage;
281
403
  if (shouldShowError && error.type !== "CANCELED_ERROR" && !shouldHandleUnauthorized) {
282
- showFetchErrorMessage(error.message);
404
+ const debugInfo = error.type === "HTTP_ERROR" && error.status !== 401 && isDebugEnabled() ? getResponseDebugInfo(error.responseData) : void 0;
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
+ }
283
415
  }
284
416
  throw error;
285
417
  }
@@ -314,18 +446,526 @@ async function gzFetch(config) {
314
446
  }
315
447
  return defaultClient(config);
316
448
  }
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;
317
957
  var GzFetchUnauthorizedModal = () => {
318
958
  var _a, _b, _c;
319
959
  const hostIdRef = useRef(void 0);
320
960
  (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
321
961
  const hostId = hostIdRef.current;
322
- const snapshot2 = useSyncExternalStore(
962
+ const snapshot3 = useSyncExternalStore(
323
963
  subscribeUnauthorized,
324
964
  getUnauthorizedSnapshot,
325
965
  getUnauthorizedServerSnapshot
326
966
  );
327
967
  useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
328
- if (snapshot2.activeHostId !== hostId) {
968
+ if (snapshot3.activeHostId !== hostId) {
329
969
  return null;
330
970
  }
331
971
  const handleConfirm = () => {
@@ -341,11 +981,11 @@ var GzFetchUnauthorizedModal = () => {
341
981
  cancelText: "取消",
342
982
  closable: true,
343
983
  okText: "重新登录",
344
- open: snapshot2.phase === "open",
345
- title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
984
+ open: snapshot3.phase === "open",
985
+ title: (_b = snapshot3.options) == null ? void 0 : _b.modalTitle,
346
986
  onCancel: cancelUnauthorizedModal,
347
987
  onOk: handleConfirm,
348
- children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
988
+ children: (_c = snapshot3.options) == null ? void 0 : _c.modalMessage
349
989
  }
350
990
  );
351
991
  };
@@ -363,12 +1003,19 @@ var GzFetchFeedbackProvider = ({ children }) => {
363
1003
  },
364
1004
  [messageApi]
365
1005
  );
1006
+ const showSuccessMessage = useCallback(
1007
+ (content) => {
1008
+ void messageApi.success(content);
1009
+ },
1010
+ [messageApi]
1011
+ );
366
1012
  useEffect(
367
- () => registerFeedbackHost(hostId, { showErrorMessage }),
368
- [hostId, showErrorMessage]
1013
+ () => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
1014
+ [hostId, showErrorMessage, showSuccessMessage]
369
1015
  );
370
1016
  return /* @__PURE__ */ jsxs(Fragment, { children: [
371
1017
  messageContextHolder,
1018
+ /* @__PURE__ */ jsx(GzFetchDebugDrawer_default, {}),
372
1019
  /* @__PURE__ */ jsx(GzFetchUnauthorizedModal_default, {}),
373
1020
  children
374
1021
  ] });