@gz-fronted/gz-pc 0.1.3-beta.2 → 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,714 +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/feedback/debug-store.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 subscribeDebugDrawer = (listener) => {
35
- listeners.add(listener);
36
- return () => listeners.delete(listener);
37
- };
38
- var getDebugDrawerSnapshot = () => snapshot;
39
- var getDebugDrawerServerSnapshot = () => EMPTY_DEBUG_DRAWER_SNAPSHOT;
40
- var registerDebugDrawerHost = (hostId) => {
41
- drawerHosts.add(hostId);
42
- if (snapshot.activeHostId === void 0) {
43
- setSnapshot({ ...snapshot, activeHostId: hostId });
44
- }
45
- return () => {
46
- drawerHosts.delete(hostId);
47
- if (snapshot.activeHostId !== hostId) {
48
- return;
49
- }
50
- const nextHost = drawerHosts.values().next();
51
- setSnapshot({
52
- ...snapshot,
53
- activeHostId: nextHost.done ? void 0 : nextHost.value
54
- });
55
- };
56
- };
57
- var appendDebugError = (input) => {
58
- if (snapshot.activeHostId === void 0) {
59
- return false;
60
- }
61
- debugErrorSequence += 1;
62
- const error = {
63
- ...input,
64
- id: `${Date.now()}-${debugErrorSequence}`
65
- };
66
- setSnapshot({
67
- ...snapshot,
68
- errors: [error, ...snapshot.errors],
69
- open: true,
70
- selectedErrorId: error.id
71
- });
72
- return true;
73
- };
74
- var closeDebugDrawer = () => {
75
- if (snapshot.open) {
76
- setSnapshot({ ...snapshot, open: false });
77
- }
78
- };
79
- var removeDebugError = (id) => {
80
- var _a, _b, _c, _d;
81
- const removedIndex = snapshot.errors.findIndex((error) => error.id === id);
82
- if (removedIndex === -1) {
83
- return;
84
- }
85
- const errors = snapshot.errors.filter((error) => error.id !== id);
86
- 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;
87
- setSnapshot({
88
- ...snapshot,
89
- errors,
90
- selectedErrorId
91
- });
92
- };
93
- var selectDebugError = (id) => {
94
- if (snapshot.selectedErrorId === id || !snapshot.errors.some((error) => error.id === id)) {
95
- return;
96
- }
97
- setSnapshot({ ...snapshot, selectedErrorId: id });
98
- };
99
- var clearDebugErrors = () => {
100
- if (snapshot.errors.length > 0) {
101
- setSnapshot({ ...snapshot, errors: [], selectedErrorId: void 0 });
102
- }
103
- };
104
- var feedbackHosts = /* @__PURE__ */ new Map();
105
- var activeHostId;
106
- var registerFeedbackHost = (hostId, host) => {
107
- feedbackHosts.set(hostId, host);
108
- activeHostId != null ? activeHostId : activeHostId = hostId;
109
- return () => {
110
- feedbackHosts.delete(hostId);
111
- if (activeHostId !== hostId) {
112
- return;
113
- }
114
- const nextHost = feedbackHosts.keys().next();
115
- activeHostId = nextHost.done ? void 0 : nextHost.value;
116
- };
117
- };
118
- var showFeedbackErrorMessage = (content) => {
119
- const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
120
- if (activeHost) {
121
- activeHost.showErrorMessage(content);
122
- return;
123
- }
124
- ggUi.message.error(content);
125
- };
126
- var showFeedbackSuccessMessage = (content) => {
127
- const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
128
- if (activeHost == null ? void 0 : activeHost.showSuccessMessage) {
129
- activeHost.showSuccessMessage(content);
130
- return;
131
- }
132
- ggUi.message.success(content);
133
- };
134
- var EMPTY_DEBUG_VALUE = "(无)";
135
- var formatDebugValue = (value) => {
136
- if (typeof value === "string") {
137
- return value;
138
- }
139
- if (value === void 0 || value === null) {
140
- return EMPTY_DEBUG_VALUE;
141
- }
142
- try {
143
- const serialized = JSON.stringify(value, null, 2);
144
- return serialized != null ? serialized : "(无法序列化)";
145
- } catch (e) {
146
- return "(无法序列化)";
147
- }
148
- };
149
- var formatCompleteDebugResponse = (error) => error.responseData === void 0 ? void 0 : formatDebugValue(error.responseData);
150
- var copyDebugText = async (text) => {
151
- var _a;
152
- try {
153
- if (typeof navigator !== "undefined" && ((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
154
- await navigator.clipboard.writeText(text);
155
- return true;
156
- }
157
- } catch (e) {
158
- }
159
- if (typeof document === "undefined" || !document.body || typeof document.execCommand !== "function") {
160
- return false;
161
- }
162
- const textarea = document.createElement("textarea");
163
- textarea.value = text;
164
- textarea.setAttribute("readonly", "");
165
- textarea.style.position = "fixed";
166
- textarea.style.opacity = "0";
167
- document.body.appendChild(textarea);
168
- let copied = false;
169
- try {
170
- textarea.focus();
171
- textarea.select();
172
- copied = document.execCommand("copy");
173
- } catch (e) {
174
- copied = false;
175
- } finally {
176
- document.body.removeChild(textarea);
177
- }
178
- return copied;
179
- };
180
- var codeBlockStyle = {
181
- background: "var(--gz-color-bg-field, rgba(127, 127, 127, 0.08))",
182
- border: "0",
183
- borderRadius: 6,
184
- boxSizing: "border-box",
185
- fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
186
- lineHeight: 1.5,
187
- margin: 0,
188
- minHeight: 0,
189
- overflow: "auto",
190
- overflowWrap: "anywhere",
191
- padding: 16,
192
- whiteSpace: "pre-wrap"
193
- };
194
- var methodTagColors = {
195
- DELETE: "red",
196
- GET: "green",
197
- PATCH: "purple",
198
- POST: "gold",
199
- PUT: "blue"
200
- };
201
- var getHttpMethodTagColor = (method) => {
202
- const normalizedMethod = method == null ? void 0 : method.toUpperCase();
203
- return normalizedMethod === void 0 ? void 0 : methodTagColors[normalizedMethod];
204
- };
205
- var HttpMethodTag = ({ method }) => {
206
- var _a;
207
- const normalizedMethod = (_a = method == null ? void 0 : method.toUpperCase()) != null ? _a : "--";
208
- const color = getHttpMethodTagColor(method);
209
- return color ? /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tag, { color, children: normalizedMethod }) : /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tag, { children: normalizedMethod });
210
- };
211
- var DebugCodeBlock = ({ onCopy, value }) => {
212
- const canCopy = value !== void 0 && value !== null;
213
- return /* @__PURE__ */ jsxRuntime.jsxs(
214
- "div",
215
- {
216
- style: {
217
- height: "100%",
218
- minHeight: 0,
219
- overflow: "auto",
220
- position: "relative"
221
- },
222
- children: [
223
- canCopy ? /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: "复制", children: /* @__PURE__ */ jsxRuntime.jsx(
224
- ggUi.Button,
225
- {
226
- "aria-label": "复制",
227
- size: "middle",
228
- style: {
229
- paddingInline: 12,
230
- position: "absolute",
231
- right: 8,
232
- top: 8,
233
- zIndex: 1
234
- },
235
- type: "primary",
236
- onClick: onCopy,
237
- children: "复制"
238
- }
239
- ) }) : null,
240
- /* @__PURE__ */ jsxRuntime.jsx(
241
- "pre",
242
- {
243
- style: {
244
- ...codeBlockStyle,
245
- paddingRight: canCopy ? 88 : codeBlockStyle.padding
246
- },
247
- children: formatDebugValue(value)
248
- }
249
- )
250
- ]
251
- }
252
- );
253
- };
254
- var DebugErrorListItem = ({ error, index, selected, total }) => {
255
- var _a, _b;
256
- const handleRemove = (event) => {
257
- event.stopPropagation();
258
- removeDebugError(error.id);
259
- };
260
- const handleKeyDown = (event) => {
261
- if (event.key === "Enter" || event.key === " ") {
262
- event.preventDefault();
263
- selectDebugError(error.id);
264
- }
265
- };
266
- return /* @__PURE__ */ jsxRuntime.jsxs(
267
- "div",
268
- {
269
- "aria-selected": selected,
270
- role: "button",
271
- tabIndex: 0,
272
- title: error.url,
273
- onClick: () => selectDebugError(error.id),
274
- onKeyDown: handleKeyDown,
275
- style: {
276
- background: selected ? "var(--gz-color-bg-field, rgba(127, 127, 127, 0.12))" : "transparent",
277
- borderRadius: 6,
278
- cursor: "pointer",
279
- display: "flex",
280
- flexDirection: "column",
281
- gap: 6,
282
- margin: "0 8px",
283
- minWidth: 0,
284
- padding: "10px 8px",
285
- position: "relative"
286
- },
287
- children: [
288
- /* @__PURE__ */ jsxRuntime.jsx(
289
- "span",
290
- {
291
- "aria-hidden": "true",
292
- style: {
293
- background: selected ? "var(--gz-color-primary, var(--gz-color-primary-border, rgba(127, 127, 127, 0.24)))" : "transparent",
294
- borderRadius: 2,
295
- bottom: 8,
296
- left: 0,
297
- pointerEvents: "none",
298
- position: "absolute",
299
- top: 8,
300
- width: 3
301
- }
302
- }
303
- ),
304
- /* @__PURE__ */ jsxRuntime.jsxs(
305
- "div",
306
- {
307
- style: {
308
- alignItems: "center",
309
- display: "flex",
310
- gap: 8,
311
- minWidth: 0
312
- },
313
- children: [
314
- /* @__PURE__ */ jsxRuntime.jsxs(
315
- "span",
316
- {
317
- style: { color: "var(--gz-color-text-secondary)", flex: "0 0 auto" },
318
- children: [
319
- "#",
320
- total - index
321
- ]
322
- }
323
- ),
324
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { flex: "0 0 58px", minWidth: 58 }, children: /* @__PURE__ */ jsxRuntime.jsx(HttpMethodTag, { method: error.method }) }),
325
- /* @__PURE__ */ jsxRuntime.jsx(
326
- "span",
327
- {
328
- style: {
329
- display: "block",
330
- flex: "1 1 auto",
331
- minWidth: 0,
332
- overflow: "hidden"
333
- },
334
- children: /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: (_a = error.url) != null ? _a : "--", children: /* @__PURE__ */ jsxRuntime.jsx(
335
- "code",
336
- {
337
- style: {
338
- color: "var(--gz-color-text-secondary)",
339
- direction: "rtl",
340
- display: "block",
341
- minWidth: 0,
342
- overflow: "hidden",
343
- textAlign: "left",
344
- textOverflow: "ellipsis",
345
- whiteSpace: "nowrap"
346
- },
347
- children: (_b = error.url) != null ? _b : "--"
348
- }
349
- ) })
350
- }
351
- ),
352
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { flex: "0 0 24px", width: 24 }, children: /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: "关闭此条", children: /* @__PURE__ */ jsxRuntime.jsx(
353
- ggUi.Button,
354
- {
355
- "aria-label": "关闭此条",
356
- size: "small",
357
- style: { padding: 0, width: 24 },
358
- type: "text",
359
- onClick: handleRemove,
360
- children: "×"
361
- }
362
- ) }) })
363
- ]
364
- }
365
- ),
366
- /* @__PURE__ */ jsxRuntime.jsx(
367
- "div",
368
- {
369
- style: {
370
- display: "-webkit-box",
371
- overflow: "hidden",
372
- overflowWrap: "anywhere",
373
- WebkitBoxOrient: "vertical",
374
- WebkitLineClamp: 2
375
- },
376
- children: error.message
377
- }
378
- )
379
- ]
380
- }
381
- );
382
- };
383
- var debugTabKeys = ["request", "stackTrace", "mdc"];
384
- var isDebugTabKey = (value) => debugTabKeys.includes(value);
385
- var DebugErrorDetails = ({
386
- error
387
- }) => {
388
- var _a, _b;
389
- const [activeTab, setActiveTab] = react.useState("request");
390
- const values = {
391
- mdc: error.debug.mdc,
392
- request: error.debug.request,
393
- stackTrace: error.debug.stackTrace
394
- };
395
- const handleCopy = async (value) => {
396
- if (value === void 0 || value === null) {
397
- return;
398
- }
399
- const copied = await copyDebugText(formatDebugValue(value));
400
- if (copied) {
401
- showFeedbackSuccessMessage("已复制");
402
- return;
403
- }
404
- showFeedbackErrorMessage("复制失败");
405
- };
406
- const handleCopyCompleteResponse = async () => {
407
- const responseText = formatCompleteDebugResponse(error);
408
- if (responseText === void 0) {
409
- return;
410
- }
411
- const copied = await copyDebugText(responseText);
412
- if (copied) {
413
- showFeedbackSuccessMessage("完整响应信息已复制");
414
- return;
415
- }
416
- showFeedbackErrorMessage("复制失败");
417
- };
418
- return /* @__PURE__ */ jsxRuntime.jsxs(
419
- "div",
420
- {
421
- style: {
422
- display: "flex",
423
- flexDirection: "column",
424
- height: "100%",
425
- minHeight: 0,
426
- minWidth: 0
427
- },
428
- children: [
429
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: "0 0 auto", marginBottom: 16, minWidth: 0 }, children: [
430
- /* @__PURE__ */ jsxRuntime.jsxs(
431
- "div",
432
- {
433
- style: {
434
- alignItems: "flex-start",
435
- display: "flex",
436
- gap: 8,
437
- minWidth: 0
438
- },
439
- children: [
440
- /* @__PURE__ */ jsxRuntime.jsx(
441
- "strong",
442
- {
443
- style: {
444
- display: "block",
445
- flex: "1 1 auto",
446
- fontSize: 16,
447
- minWidth: 0,
448
- overflowWrap: "anywhere"
449
- },
450
- children: error.message
451
- }
452
- ),
453
- error.responseData === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx(ggUi.Tooltip, { title: "复制完整响应信息", children: /* @__PURE__ */ jsxRuntime.jsx(
454
- ggUi.Button,
455
- {
456
- "aria-label": "复制完整响应信息",
457
- size: "middle",
458
- style: { flex: "0 0 auto", paddingInline: 12 },
459
- type: "primary",
460
- onClick: () => {
461
- void handleCopyCompleteResponse();
462
- },
463
- children: "复制完整响应"
464
- }
465
- ) })
466
- ]
467
- }
468
- ),
469
- /* @__PURE__ */ jsxRuntime.jsxs(
470
- "div",
471
- {
472
- style: {
473
- alignItems: "center",
474
- display: "flex",
475
- gap: 8,
476
- marginTop: 8,
477
- minWidth: 0
478
- },
479
- children: [
480
- /* @__PURE__ */ jsxRuntime.jsx(HttpMethodTag, { method: error.method }),
481
- /* @__PURE__ */ jsxRuntime.jsx(
482
- "code",
483
- {
484
- style: {
485
- color: "var(--gz-color-text-secondary)",
486
- display: "block",
487
- minWidth: 0,
488
- overflow: "hidden",
489
- textOverflow: "ellipsis",
490
- whiteSpace: "nowrap"
491
- },
492
- title: (_a = error.url) != null ? _a : "--",
493
- children: (_b = error.url) != null ? _b : "--"
494
- }
495
- )
496
- ]
497
- }
498
- )
499
- ] }),
500
- /* @__PURE__ */ jsxRuntime.jsx(
501
- ggUi.Tabs,
502
- {
503
- activeKey: activeTab,
504
- items: [
505
- {
506
- children: /* @__PURE__ */ jsxRuntime.jsx(
507
- DebugCodeBlock,
508
- {
509
- onCopy: () => {
510
- void handleCopy(values.request);
511
- },
512
- value: values.request
513
- }
514
- ),
515
- key: "request",
516
- label: "Request"
517
- },
518
- {
519
- children: /* @__PURE__ */ jsxRuntime.jsx(
520
- DebugCodeBlock,
521
- {
522
- onCopy: () => {
523
- void handleCopy(values.stackTrace);
524
- },
525
- value: values.stackTrace
526
- }
527
- ),
528
- key: "stackTrace",
529
- label: "Stack Trace"
530
- },
531
- {
532
- children: /* @__PURE__ */ jsxRuntime.jsx(
533
- DebugCodeBlock,
534
- {
535
- onCopy: () => {
536
- void handleCopy(values.mdc);
537
- },
538
- value: values.mdc
539
- }
540
- ),
541
- key: "mdc",
542
- label: "MDC"
543
- }
544
- ],
545
- style: {
546
- display: "flex",
547
- flexDirection: "column",
548
- height: "100%",
549
- minHeight: 0
550
- },
551
- onChange: (key) => {
552
- if (isDebugTabKey(key)) {
553
- setActiveTab(key);
554
- }
555
- }
556
- }
557
- )
558
- ]
559
- }
560
- );
561
- };
562
- var DebugErrorDrawer = () => {
563
- var _a, _b;
564
- const hostIdRef = react.useRef(void 0);
565
- (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-debug-feedback-drawer-host");
566
- const hostId = hostIdRef.current;
567
- const snapshot3 = react.useSyncExternalStore(
568
- subscribeDebugDrawer,
569
- getDebugDrawerSnapshot,
570
- getDebugDrawerServerSnapshot
571
- );
572
- react.useEffect(() => registerDebugDrawerHost(hostId), [hostId]);
573
- if (snapshot3.activeHostId !== hostId) {
574
- return null;
575
- }
576
- const selectedError = (_b = snapshot3.errors.find((error) => error.id === snapshot3.selectedErrorId)) != null ? _b : snapshot3.errors[0];
577
- return /* @__PURE__ */ jsxRuntime.jsx(
578
- ggUi.Drawer,
579
- {
580
- open: snapshot3.open,
581
- placement: "right",
582
- styles: { body: { overflow: "hidden", padding: 0 } },
583
- title: `Debug Error (${snapshot3.errors.length})`,
584
- extra: /* @__PURE__ */ jsxRuntime.jsx(
585
- ggUi.Button,
586
- {
587
- disabled: snapshot3.errors.length === 0,
588
- size: "middle",
589
- style: { paddingInline: 12 },
590
- type: "default",
591
- onClick: clearDebugErrors,
592
- children: "清空记录"
593
- }
594
- ),
595
- width: "min(calc(100vw - 32px), clamp(720px, 80vw, 1120px))",
596
- onClose: closeDebugDrawer,
597
- children: /* @__PURE__ */ jsxRuntime.jsxs(
598
- "div",
599
- {
600
- style: {
601
- display: "flex",
602
- height: "100%",
603
- minHeight: 0,
604
- minWidth: 0
605
- },
606
- children: [
607
- /* @__PURE__ */ jsxRuntime.jsx(
608
- "aside",
609
- {
610
- "aria-label": "Debug Error 列表",
611
- style: {
612
- borderRight: "1px solid var(--gz-color-border, rgba(127, 127, 127, 0.24))",
613
- flex: "0 1 clamp(220px, 24vw, 320px)",
614
- minHeight: 0,
615
- overflowY: "auto",
616
- padding: "6px 0",
617
- width: "clamp(220px, 24vw, 320px)"
618
- },
619
- children: snapshot3.errors.length > 0 ? snapshot3.errors.map((error, index) => /* @__PURE__ */ jsxRuntime.jsx(
620
- DebugErrorListItem,
621
- {
622
- error,
623
- index,
624
- selected: error.id === (selectedError == null ? void 0 : selectedError.id),
625
- total: snapshot3.errors.length
626
- },
627
- error.id
628
- )) : /* @__PURE__ */ jsxRuntime.jsx(
629
- "div",
630
- {
631
- style: {
632
- color: "var(--gz-color-text-secondary)",
633
- padding: 16,
634
- textAlign: "center"
635
- },
636
- children: "暂无 Debug Error"
637
- }
638
- )
639
- }
640
- ),
641
- /* @__PURE__ */ jsxRuntime.jsx(
642
- "main",
643
- {
644
- "aria-label": "Debug Error 详情",
645
- style: {
646
- flex: "1 1 auto",
647
- minHeight: 0,
648
- minWidth: 0,
649
- overflow: "hidden",
650
- padding: 20
651
- },
652
- children: selectedError ? /* @__PURE__ */ jsxRuntime.jsx(DebugErrorDetails, { error: selectedError }, selectedError.id) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "var(--gz-color-text-secondary)" }, children: "暂无 Debug Error" })
653
- }
654
- )
655
- ]
656
- }
657
- )
658
- }
659
- );
660
- };
661
- DebugErrorDrawer.displayName = "DebugErrorDrawer";
662
- var DebugErrorDrawer_default = DebugErrorDrawer;
663
- var GzDebugFeedbackProvider = ({ children }) => {
664
- var _a;
665
- const hostIdRef = react.useRef(void 0);
666
- (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-debug-feedback-host");
667
- const hostId = hostIdRef.current;
668
- const [messageApi, messageContextHolder] = ggUi.message.useMessage();
669
- const showErrorMessage = react.useCallback(
670
- (content) => {
671
- void messageApi.error(content);
672
- },
673
- [messageApi]
674
- );
675
- const showSuccessMessage = react.useCallback(
676
- (content) => {
677
- void messageApi.success(content);
678
- },
679
- [messageApi]
680
- );
681
- react.useEffect(
682
- () => registerFeedbackHost(hostId, { showErrorMessage, showSuccessMessage }),
683
- [hostId, showErrorMessage, showSuccessMessage]
684
- );
685
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
686
- messageContextHolder,
687
- /* @__PURE__ */ jsxRuntime.jsx(DebugErrorDrawer_default, {}),
688
- children
689
- ] });
690
- };
691
- GzDebugFeedbackProvider.displayName = "GzDebugFeedbackProvider";
692
- var GzDebugFeedbackProvider_default = GzDebugFeedbackProvider;
693
-
694
- // src/fetch/feedback/report-debug-error.ts
695
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
696
- var getDebugInfo = (value) => isRecord(value) ? value : void 0;
697
- var getResponseDebugInfo = (responseData) => isRecord(responseData) ? getDebugInfo(responseData.debug) : void 0;
698
- var isDebugEnabled = () => {
699
- if (typeof window === "undefined") {
700
- return false;
701
- }
702
- try {
703
- if (new URLSearchParams(window.location.search).get("showDebug") === "1") {
704
- return true;
705
- }
706
- } catch (e) {
707
- }
708
- try {
709
- return window.localStorage.getItem("showDebug") === "1";
710
- } catch (e) {
711
- return false;
712
- }
713
- };
714
- var reportDebugError = (input) => {
715
- const debug = getDebugInfo(input.debug);
716
- if (debug === void 0 || !isDebugEnabled()) {
717
- return false;
718
- }
719
- return appendDebugError({ ...input, debug });
720
- };
721
14
  var GzFetchError = class extends Error {
722
15
  constructor(message3, options) {
723
16
  super(message3);
@@ -779,6 +72,28 @@ function toGzFetchError(error) {
779
72
  originalError: error
780
73
  });
781
74
  }
75
+ var feedbackHosts = /* @__PURE__ */ new Map();
76
+ var activeHostId;
77
+ var registerFeedbackHost = (hostId, host) => {
78
+ feedbackHosts.set(hostId, host);
79
+ activeHostId != null ? activeHostId : activeHostId = hostId;
80
+ return () => {
81
+ feedbackHosts.delete(hostId);
82
+ if (activeHostId !== hostId) {
83
+ return;
84
+ }
85
+ const nextHost = feedbackHosts.keys().next();
86
+ activeHostId = nextHost.done ? void 0 : nextHost.value;
87
+ };
88
+ };
89
+ var showFetchErrorMessage = (content) => {
90
+ const activeHost = activeHostId === void 0 ? void 0 : feedbackHosts.get(activeHostId);
91
+ if (activeHost) {
92
+ activeHost.showErrorMessage(content);
93
+ return;
94
+ }
95
+ gzUiWeb.message.error(content);
96
+ };
782
97
 
783
98
  // src/fetch/middleware.ts
784
99
  async function runRequestMiddlewares(initialConfig, middlewares) {
@@ -805,23 +120,64 @@ async function runErrorMiddlewares(error, context, middlewares) {
805
120
  await ((_a = middleware.onError) == null ? void 0 : _a.call(middleware, error, context));
806
121
  }
807
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
+ };
808
164
 
809
165
  // src/fetch/unauthorized.ts
810
166
  var DEFAULT_UNAUTHORIZED_LOGIN_URL = "/login";
811
167
  var DEFAULT_UNAUTHORIZED_MODAL_TITLE = "登录失效";
812
168
  var DEFAULT_UNAUTHORIZED_MODAL_MESSAGE = "当前登录状态已失效,请重新登录。";
813
169
  var IDLE_SNAPSHOT = { phase: "idle" };
814
- var snapshot2 = IDLE_SNAPSHOT;
815
- var listeners2 = /* @__PURE__ */ new Set();
170
+ var snapshot = IDLE_SNAPSHOT;
171
+ var listeners = /* @__PURE__ */ new Set();
816
172
  var modalHosts = /* @__PURE__ */ new Set();
817
- var emitChange2 = () => {
818
- for (const listener of listeners2) {
173
+ var emitChange = () => {
174
+ for (const listener of listeners) {
819
175
  listener();
820
176
  }
821
177
  };
822
- var setSnapshot2 = (nextSnapshot) => {
823
- snapshot2 = nextSnapshot;
824
- emitChange2();
178
+ var setSnapshot = (nextSnapshot) => {
179
+ snapshot = nextSnapshot;
180
+ emitChange();
825
181
  };
826
182
  var resolveUnauthorizedOptions = (options) => {
827
183
  var _a, _b, _c, _d;
@@ -833,66 +189,66 @@ var resolveUnauthorizedOptions = (options) => {
833
189
  ...(options == null ? void 0 : options.onUnauthorized) === void 0 ? {} : { onUnauthorized: options.onUnauthorized }
834
190
  };
835
191
  };
836
- var getUnauthorizedSnapshot = () => snapshot2;
192
+ var getUnauthorizedSnapshot = () => snapshot;
837
193
  var getUnauthorizedServerSnapshot = () => IDLE_SNAPSHOT;
838
194
  var subscribeUnauthorized = (listener) => {
839
- listeners2.add(listener);
840
- return () => listeners2.delete(listener);
195
+ listeners.add(listener);
196
+ return () => listeners.delete(listener);
841
197
  };
842
198
  var registerUnauthorizedModalHost = (hostId) => {
843
199
  modalHosts.add(hostId);
844
- if (snapshot2.activeHostId === void 0) {
845
- setSnapshot2({ ...snapshot2, activeHostId: hostId });
200
+ if (snapshot.activeHostId === void 0) {
201
+ setSnapshot({ ...snapshot, activeHostId: hostId });
846
202
  }
847
203
  return () => {
848
204
  modalHosts.delete(hostId);
849
- if (snapshot2.activeHostId !== hostId) {
205
+ if (snapshot.activeHostId !== hostId) {
850
206
  return;
851
207
  }
852
208
  const nextHost = modalHosts.values().next();
853
209
  const nextHostId = nextHost.done ? void 0 : nextHost.value;
854
- if (snapshot2.phase === "closing") {
855
- setSnapshot2(
210
+ if (snapshot.phase === "closing") {
211
+ setSnapshot(
856
212
  nextHostId === void 0 ? IDLE_SNAPSHOT : { activeHostId: nextHostId, phase: "idle" }
857
213
  );
858
214
  return;
859
215
  }
860
216
  if (nextHostId === void 0) {
861
- setSnapshot2(
862
- 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 }
863
219
  );
864
220
  return;
865
221
  }
866
- setSnapshot2({ ...snapshot2, activeHostId: nextHostId });
222
+ setSnapshot({ ...snapshot, activeHostId: nextHostId });
867
223
  };
868
224
  };
869
225
  var openUnauthorizedModal = (options) => {
870
- if (!options.enabled || snapshot2.phase !== "idle") {
226
+ if (!options.enabled || snapshot.phase !== "idle") {
871
227
  return false;
872
228
  }
873
- setSnapshot2({
874
- ...snapshot2.activeHostId === void 0 ? {} : { activeHostId: snapshot2.activeHostId },
229
+ setSnapshot({
230
+ ...snapshot.activeHostId === void 0 ? {} : { activeHostId: snapshot.activeHostId },
875
231
  options,
876
232
  phase: "open"
877
233
  });
878
234
  return true;
879
235
  };
880
236
  var beginCloseUnauthorizedModal = () => {
881
- if (snapshot2.phase !== "open" || snapshot2.options === void 0) {
237
+ if (snapshot.phase !== "open" || snapshot.options === void 0) {
882
238
  return void 0;
883
239
  }
884
- const { options } = snapshot2;
885
- setSnapshot2({ ...snapshot2, phase: "closing" });
240
+ const { options } = snapshot;
241
+ setSnapshot({ ...snapshot, phase: "closing" });
886
242
  return options;
887
243
  };
888
244
  var cancelUnauthorizedModal = () => beginCloseUnauthorizedModal() !== void 0;
889
245
  var confirmUnauthorizedModal = () => beginCloseUnauthorizedModal();
890
246
  var completeUnauthorizedModal = () => {
891
- if (snapshot2.phase !== "closing") {
247
+ if (snapshot.phase !== "closing") {
892
248
  return;
893
249
  }
894
- setSnapshot2(
895
- 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" }
896
252
  );
897
253
  };
898
254
  var executeUnauthorizedAction = (options, navigate = (loginUrl) => window.location.assign(loginUrl)) => {
@@ -926,7 +282,8 @@ function createGzFetch(options = {}) {
926
282
  const instance = axios__default.default.create({
927
283
  ...options.baseURL === void 0 ? {} : { baseURL: options.baseURL },
928
284
  timeout: (_g = options.timeout) != null ? _g : DEFAULT_TIMEOUT,
929
- validateStatus: (_h = options.validateStatus) != null ? _h : DEFAULT_VALIDATE_STATUS
285
+ validateStatus: (_h = options.validateStatus) != null ? _h : DEFAULT_VALIDATE_STATUS,
286
+ ...options.preserveNumberPrecision ? { transformResponse: [transformResponsePreservingNumbers] } : {}
930
287
  });
931
288
  async function request(initialConfig) {
932
289
  var _a2;
@@ -971,16 +328,7 @@ function createGzFetch(options = {}) {
971
328
  await runErrorMiddlewares(error, { config: currentConfig }, middlewares);
972
329
  const shouldShowError = (_a2 = currentConfig.showErrorMessage) != null ? _a2 : showInstanceErrorMessage;
973
330
  if (shouldShowError && error.type !== "CANCELED_ERROR" && !shouldHandleUnauthorized) {
974
- const didShowDebugError = error.type === "HTTP_ERROR" && error.status !== 401 ? reportDebugError({
975
- debug: getResponseDebugInfo(error.responseData),
976
- message: error.message,
977
- method: currentConfig.method,
978
- responseData: error.responseData,
979
- url: currentConfig.url
980
- }) : false;
981
- if (!didShowDebugError) {
982
- showFeedbackErrorMessage(error.message);
983
- }
331
+ showFetchErrorMessage(error.message);
984
332
  }
985
333
  throw error;
986
334
  }
@@ -1015,18 +363,18 @@ async function gzFetch(config) {
1015
363
  }
1016
364
  return defaultClient(config);
1017
365
  }
1018
- var GzFetchUnauthorizedModalContent = () => {
366
+ var GzFetchUnauthorizedModal = () => {
1019
367
  var _a, _b, _c;
1020
368
  const hostIdRef = react.useRef(void 0);
1021
369
  (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
1022
370
  const hostId = hostIdRef.current;
1023
- const snapshot3 = react.useSyncExternalStore(
371
+ const snapshot2 = react.useSyncExternalStore(
1024
372
  subscribeUnauthorized,
1025
373
  getUnauthorizedSnapshot,
1026
374
  getUnauthorizedServerSnapshot
1027
375
  );
1028
376
  react.useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
1029
- if (snapshot3.activeHostId !== hostId) {
377
+ if (snapshot2.activeHostId !== hostId) {
1030
378
  return null;
1031
379
  }
1032
380
  const handleConfirm = () => {
@@ -1036,33 +384,47 @@ var GzFetchUnauthorizedModalContent = () => {
1036
384
  }
1037
385
  };
1038
386
  return /* @__PURE__ */ jsxRuntime.jsx(
1039
- ggUi.Modal,
387
+ gzUiWeb.Modal,
1040
388
  {
1041
389
  afterClose: completeUnauthorizedModal,
1042
390
  cancelText: "取消",
1043
391
  closable: true,
1044
392
  okText: "重新登录",
1045
- open: snapshot3.phase === "open",
1046
- title: (_b = snapshot3.options) == null ? void 0 : _b.modalTitle,
393
+ open: snapshot2.phase === "open",
394
+ title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
1047
395
  onCancel: cancelUnauthorizedModal,
1048
396
  onOk: handleConfirm,
1049
- children: (_c = snapshot3.options) == null ? void 0 : _c.modalMessage
397
+ children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
1050
398
  }
1051
399
  );
1052
400
  };
1053
- GzFetchUnauthorizedModalContent.displayName = "GzFetchUnauthorizedModalContent";
1054
- var GzFetchUnauthorizedModalContent_default = GzFetchUnauthorizedModalContent;
1055
- var GzFetchFeedbackProvider = ({ children }) => /* @__PURE__ */ jsxRuntime.jsxs(GzDebugFeedbackProvider_default, { children: [
1056
- /* @__PURE__ */ jsxRuntime.jsx(GzFetchUnauthorizedModalContent_default, {}),
1057
- children
1058
- ] });
1059
- GzFetchFeedbackProvider.displayName = "GzFetchFeedbackProvider";
1060
- var GzFetchFeedbackProvider_default = GzFetchFeedbackProvider;
1061
- var GzFetchUnauthorizedModal = () => /* @__PURE__ */ jsxRuntime.jsx(GzFetchUnauthorizedModalContent_default, {});
1062
401
  GzFetchUnauthorizedModal.displayName = "GzFetchUnauthorizedModal";
1063
402
  var GzFetchUnauthorizedModal_default = GzFetchUnauthorizedModal;
403
+ var GzFetchFeedbackProvider = ({ children }) => {
404
+ var _a;
405
+ const hostIdRef = react.useRef(void 0);
406
+ (_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-feedback-host");
407
+ const hostId = hostIdRef.current;
408
+ const [messageApi, messageContextHolder] = gzUiWeb.message.useMessage();
409
+ const showErrorMessage = react.useCallback(
410
+ (content) => {
411
+ void messageApi.error(content);
412
+ },
413
+ [messageApi]
414
+ );
415
+ react.useEffect(
416
+ () => registerFeedbackHost(hostId, { showErrorMessage }),
417
+ [hostId, showErrorMessage]
418
+ );
419
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
420
+ messageContextHolder,
421
+ /* @__PURE__ */ jsxRuntime.jsx(GzFetchUnauthorizedModal_default, {}),
422
+ children
423
+ ] });
424
+ };
425
+ GzFetchFeedbackProvider.displayName = "GzFetchFeedbackProvider";
426
+ var GzFetchFeedbackProvider_default = GzFetchFeedbackProvider;
1064
427
 
1065
- exports.GzDebugFeedbackProvider = GzDebugFeedbackProvider_default;
1066
428
  exports.GzFetchError = GzFetchError;
1067
429
  exports.GzFetchFeedbackProvider = GzFetchFeedbackProvider_default;
1068
430
  exports.GzFetchUnauthorizedModal = GzFetchUnauthorizedModal_default;
@@ -1070,5 +432,4 @@ exports.configureGzFetch = configureGzFetch;
1070
432
  exports.createGzFetch = createGzFetch;
1071
433
  exports.getResponseMessage = getResponseMessage;
1072
434
  exports.gzFetch = gzFetch;
1073
- exports.reportDebugError = reportDebugError;
1074
435
  exports.toGzFetchError = toGzFetchError;