@gz-fronted/gz-pc 0.1.3-beta.0 → 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/dist/fetch/index.cjs +500 -78
- package/dist/fetch/index.js +502 -80
- package/package.json +1 -1
package/dist/fetch/index.cjs
CHANGED
|
@@ -15,7 +15,8 @@ var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
|
15
15
|
var EMPTY_DEBUG_DRAWER_SNAPSHOT = {
|
|
16
16
|
activeHostId: void 0,
|
|
17
17
|
errors: [],
|
|
18
|
-
open: false
|
|
18
|
+
open: false,
|
|
19
|
+
selectedErrorId: void 0
|
|
19
20
|
};
|
|
20
21
|
var debugErrorSequence = 0;
|
|
21
22
|
var snapshot = EMPTY_DEBUG_DRAWER_SNAPSHOT;
|
|
@@ -81,16 +82,15 @@ var showFetchDebugError = (input) => {
|
|
|
81
82
|
return false;
|
|
82
83
|
}
|
|
83
84
|
debugErrorSequence += 1;
|
|
85
|
+
const error = {
|
|
86
|
+
...input,
|
|
87
|
+
id: `${Date.now()}-${debugErrorSequence}`
|
|
88
|
+
};
|
|
84
89
|
setSnapshot({
|
|
85
90
|
...snapshot,
|
|
86
|
-
errors: [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
...input,
|
|
90
|
-
id: `${Date.now()}-${debugErrorSequence}`
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
open: true
|
|
91
|
+
errors: [error, ...snapshot.errors],
|
|
92
|
+
open: true,
|
|
93
|
+
selectedErrorId: error.id
|
|
94
94
|
});
|
|
95
95
|
return true;
|
|
96
96
|
};
|
|
@@ -100,14 +100,28 @@ var closeDebugDrawer = () => {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
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;
|
|
103
110
|
setSnapshot({
|
|
104
111
|
...snapshot,
|
|
105
|
-
errors
|
|
112
|
+
errors,
|
|
113
|
+
selectedErrorId
|
|
106
114
|
});
|
|
107
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
|
+
};
|
|
108
122
|
var clearDebugErrors = () => {
|
|
109
123
|
if (snapshot.errors.length > 0) {
|
|
110
|
-
setSnapshot({ ...snapshot, errors: [] });
|
|
124
|
+
setSnapshot({ ...snapshot, errors: [], selectedErrorId: void 0 });
|
|
111
125
|
}
|
|
112
126
|
};
|
|
113
127
|
var GzFetchError = class extends Error {
|
|
@@ -193,6 +207,14 @@ var showFetchErrorMessage = (content) => {
|
|
|
193
207
|
}
|
|
194
208
|
ggUi.message.error(content);
|
|
195
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
|
+
};
|
|
196
218
|
|
|
197
219
|
// src/fetch/middleware.ts
|
|
198
220
|
async function runRequestMiddlewares(initialConfig, middlewares) {
|
|
@@ -390,6 +412,7 @@ function createGzFetch(options = {}) {
|
|
|
390
412
|
debug: debugInfo,
|
|
391
413
|
message: error.message,
|
|
392
414
|
method: currentConfig.method,
|
|
415
|
+
responseData: error.responseData,
|
|
393
416
|
url: currentConfig.url
|
|
394
417
|
});
|
|
395
418
|
if (!didShowDebugError) {
|
|
@@ -444,70 +467,400 @@ var formatDebugValue = (value) => {
|
|
|
444
467
|
return "(无法序列化)";
|
|
445
468
|
}
|
|
446
469
|
};
|
|
447
|
-
var
|
|
448
|
-
|
|
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",
|
|
449
504
|
borderRadius: 6,
|
|
450
|
-
|
|
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",
|
|
451
511
|
overflowWrap: "anywhere",
|
|
452
|
-
|
|
453
|
-
padding: 12,
|
|
512
|
+
padding: 16,
|
|
454
513
|
whiteSpace: "pre-wrap"
|
|
455
514
|
};
|
|
456
|
-
var
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
var
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
+
},
|
|
492
836
|
{
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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"
|
|
498
848
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
+
};
|
|
509
862
|
var GzFetchDebugDrawer = () => {
|
|
510
|
-
var _a;
|
|
863
|
+
var _a, _b;
|
|
511
864
|
const hostIdRef = react.useRef(void 0);
|
|
512
865
|
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-debug-drawer-host");
|
|
513
866
|
const hostId = hostIdRef.current;
|
|
@@ -520,25 +873,88 @@ var GzFetchDebugDrawer = () => {
|
|
|
520
873
|
if (snapshot3.activeHostId !== hostId) {
|
|
521
874
|
return null;
|
|
522
875
|
}
|
|
876
|
+
const selectedError = (_b = snapshot3.errors.find((error) => error.id === snapshot3.selectedErrorId)) != null ? _b : snapshot3.errors[0];
|
|
523
877
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
524
878
|
ggUi.Drawer,
|
|
525
879
|
{
|
|
880
|
+
open: snapshot3.open,
|
|
881
|
+
placement: "right",
|
|
882
|
+
styles: { body: { overflow: "hidden", padding: 0 } },
|
|
883
|
+
title: `Debug Error (${snapshot3.errors.length})`,
|
|
526
884
|
extra: /* @__PURE__ */ jsxRuntime.jsx(
|
|
527
885
|
ggUi.Button,
|
|
528
886
|
{
|
|
529
887
|
disabled: snapshot3.errors.length === 0,
|
|
530
|
-
size: "
|
|
888
|
+
size: "middle",
|
|
889
|
+
style: { paddingInline: 12 },
|
|
890
|
+
type: "default",
|
|
531
891
|
onClick: clearDebugErrors,
|
|
532
|
-
children: "
|
|
892
|
+
children: "清空记录"
|
|
533
893
|
}
|
|
534
894
|
),
|
|
535
|
-
|
|
536
|
-
placement: "right",
|
|
537
|
-
styles: { body: { overflowY: "auto" } },
|
|
538
|
-
title: `Debug Error (${snapshot3.errors.length})`,
|
|
539
|
-
width: "min(760px, 100vw)",
|
|
895
|
+
width: "min(calc(100vw - 32px), clamp(720px, 80vw, 1120px))",
|
|
540
896
|
onClose: closeDebugDrawer,
|
|
541
|
-
children: /* @__PURE__ */ jsxRuntime.
|
|
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
|
+
)
|
|
542
958
|
}
|
|
543
959
|
);
|
|
544
960
|
};
|
|
@@ -593,9 +1009,15 @@ var GzFetchFeedbackProvider = ({ children }) => {
|
|
|
593
1009
|
},
|
|
594
1010
|
[messageApi]
|
|
595
1011
|
);
|
|
1012
|
+
const showSuccessMessage = react.useCallback(
|
|
1013
|
+
(content) => {
|
|
1014
|
+
void messageApi.success(content);
|
|
1015
|
+
},
|
|
1016
|
+
[messageApi]
|
|
1017
|
+
);
|
|
596
1018
|
react.useEffect(
|
|
597
|
-
() => registerFeedbackHost(hostId, { showErrorMessage }),
|
|
598
|
-
[hostId, showErrorMessage]
|
|
1019
|
+
() => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
|
|
1020
|
+
[hostId, showErrorMessage, showSuccessMessage]
|
|
599
1021
|
);
|
|
600
1022
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
601
1023
|
messageContextHolder,
|
package/dist/fetch/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosError, AxiosHeaders } from 'axios';
|
|
2
|
-
import { Modal, message, Drawer, Button } 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
|
|
@@ -9,7 +9,8 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
9
9
|
var EMPTY_DEBUG_DRAWER_SNAPSHOT = {
|
|
10
10
|
activeHostId: void 0,
|
|
11
11
|
errors: [],
|
|
12
|
-
open: false
|
|
12
|
+
open: false,
|
|
13
|
+
selectedErrorId: void 0
|
|
13
14
|
};
|
|
14
15
|
var debugErrorSequence = 0;
|
|
15
16
|
var snapshot = EMPTY_DEBUG_DRAWER_SNAPSHOT;
|
|
@@ -75,16 +76,15 @@ var showFetchDebugError = (input) => {
|
|
|
75
76
|
return false;
|
|
76
77
|
}
|
|
77
78
|
debugErrorSequence += 1;
|
|
79
|
+
const error = {
|
|
80
|
+
...input,
|
|
81
|
+
id: `${Date.now()}-${debugErrorSequence}`
|
|
82
|
+
};
|
|
78
83
|
setSnapshot({
|
|
79
84
|
...snapshot,
|
|
80
|
-
errors: [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
...input,
|
|
84
|
-
id: `${Date.now()}-${debugErrorSequence}`
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
|
-
open: true
|
|
85
|
+
errors: [error, ...snapshot.errors],
|
|
86
|
+
open: true,
|
|
87
|
+
selectedErrorId: error.id
|
|
88
88
|
});
|
|
89
89
|
return true;
|
|
90
90
|
};
|
|
@@ -94,14 +94,28 @@ var closeDebugDrawer = () => {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
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;
|
|
97
104
|
setSnapshot({
|
|
98
105
|
...snapshot,
|
|
99
|
-
errors
|
|
106
|
+
errors,
|
|
107
|
+
selectedErrorId
|
|
100
108
|
});
|
|
101
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
|
+
};
|
|
102
116
|
var clearDebugErrors = () => {
|
|
103
117
|
if (snapshot.errors.length > 0) {
|
|
104
|
-
setSnapshot({ ...snapshot, errors: [] });
|
|
118
|
+
setSnapshot({ ...snapshot, errors: [], selectedErrorId: void 0 });
|
|
105
119
|
}
|
|
106
120
|
};
|
|
107
121
|
var GzFetchError = class extends Error {
|
|
@@ -187,6 +201,14 @@ var showFetchErrorMessage = (content) => {
|
|
|
187
201
|
}
|
|
188
202
|
message.error(content);
|
|
189
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
|
+
};
|
|
190
212
|
|
|
191
213
|
// src/fetch/middleware.ts
|
|
192
214
|
async function runRequestMiddlewares(initialConfig, middlewares) {
|
|
@@ -384,6 +406,7 @@ function createGzFetch(options = {}) {
|
|
|
384
406
|
debug: debugInfo,
|
|
385
407
|
message: error.message,
|
|
386
408
|
method: currentConfig.method,
|
|
409
|
+
responseData: error.responseData,
|
|
387
410
|
url: currentConfig.url
|
|
388
411
|
});
|
|
389
412
|
if (!didShowDebugError) {
|
|
@@ -438,70 +461,400 @@ var formatDebugValue = (value) => {
|
|
|
438
461
|
return "(无法序列化)";
|
|
439
462
|
}
|
|
440
463
|
};
|
|
441
|
-
var
|
|
442
|
-
|
|
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",
|
|
443
498
|
borderRadius: 6,
|
|
444
|
-
|
|
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",
|
|
445
505
|
overflowWrap: "anywhere",
|
|
446
|
-
|
|
447
|
-
padding: 12,
|
|
506
|
+
padding: 16,
|
|
448
507
|
whiteSpace: "pre-wrap"
|
|
449
508
|
};
|
|
450
|
-
var
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
var
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
+
},
|
|
486
830
|
{
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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"
|
|
492
842
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
+
};
|
|
503
856
|
var GzFetchDebugDrawer = () => {
|
|
504
|
-
var _a;
|
|
857
|
+
var _a, _b;
|
|
505
858
|
const hostIdRef = useRef(void 0);
|
|
506
859
|
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-debug-drawer-host");
|
|
507
860
|
const hostId = hostIdRef.current;
|
|
@@ -514,25 +867,88 @@ var GzFetchDebugDrawer = () => {
|
|
|
514
867
|
if (snapshot3.activeHostId !== hostId) {
|
|
515
868
|
return null;
|
|
516
869
|
}
|
|
870
|
+
const selectedError = (_b = snapshot3.errors.find((error) => error.id === snapshot3.selectedErrorId)) != null ? _b : snapshot3.errors[0];
|
|
517
871
|
return /* @__PURE__ */ jsx(
|
|
518
872
|
Drawer,
|
|
519
873
|
{
|
|
874
|
+
open: snapshot3.open,
|
|
875
|
+
placement: "right",
|
|
876
|
+
styles: { body: { overflow: "hidden", padding: 0 } },
|
|
877
|
+
title: `Debug Error (${snapshot3.errors.length})`,
|
|
520
878
|
extra: /* @__PURE__ */ jsx(
|
|
521
879
|
Button,
|
|
522
880
|
{
|
|
523
881
|
disabled: snapshot3.errors.length === 0,
|
|
524
|
-
size: "
|
|
882
|
+
size: "middle",
|
|
883
|
+
style: { paddingInline: 12 },
|
|
884
|
+
type: "default",
|
|
525
885
|
onClick: clearDebugErrors,
|
|
526
|
-
children: "
|
|
886
|
+
children: "清空记录"
|
|
527
887
|
}
|
|
528
888
|
),
|
|
529
|
-
|
|
530
|
-
placement: "right",
|
|
531
|
-
styles: { body: { overflowY: "auto" } },
|
|
532
|
-
title: `Debug Error (${snapshot3.errors.length})`,
|
|
533
|
-
width: "min(760px, 100vw)",
|
|
889
|
+
width: "min(calc(100vw - 32px), clamp(720px, 80vw, 1120px))",
|
|
534
890
|
onClose: closeDebugDrawer,
|
|
535
|
-
children: /* @__PURE__ */
|
|
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
|
+
)
|
|
536
952
|
}
|
|
537
953
|
);
|
|
538
954
|
};
|
|
@@ -587,9 +1003,15 @@ var GzFetchFeedbackProvider = ({ children }) => {
|
|
|
587
1003
|
},
|
|
588
1004
|
[messageApi]
|
|
589
1005
|
);
|
|
1006
|
+
const showSuccessMessage = useCallback(
|
|
1007
|
+
(content) => {
|
|
1008
|
+
void messageApi.success(content);
|
|
1009
|
+
},
|
|
1010
|
+
[messageApi]
|
|
1011
|
+
);
|
|
590
1012
|
useEffect(
|
|
591
|
-
() => registerFeedbackHost(hostId, { showErrorMessage }),
|
|
592
|
-
[hostId, showErrorMessage]
|
|
1013
|
+
() => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
|
|
1014
|
+
[hostId, showErrorMessage, showSuccessMessage]
|
|
593
1015
|
);
|
|
594
1016
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
595
1017
|
messageContextHolder,
|