@gz-fronted/gz-pc 0.1.1-beta.3 → 0.1.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/README.md +551 -551
- package/dist/fetch/index.cjs +33 -28
- package/dist/fetch/index.d.cts +1 -0
- package/dist/fetch/index.d.ts +1 -0
- package/dist/fetch/index.js +36 -31
- package/package.json +99 -99
package/dist/fetch/index.cjs
CHANGED
|
@@ -325,51 +325,56 @@ var GzFetchUnauthorizedModal = () => {
|
|
|
325
325
|
const hostIdRef = react.useRef(void 0);
|
|
326
326
|
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
|
|
327
327
|
const hostId = hostIdRef.current;
|
|
328
|
-
const [messageApi, messageContextHolder] = ggUi.message.useMessage();
|
|
329
|
-
const showErrorMessage = react.useCallback(
|
|
330
|
-
(content) => {
|
|
331
|
-
void messageApi.error(content);
|
|
332
|
-
},
|
|
333
|
-
[messageApi]
|
|
334
|
-
);
|
|
335
328
|
const snapshot2 = react.useSyncExternalStore(
|
|
336
329
|
subscribeUnauthorized,
|
|
337
330
|
getUnauthorizedSnapshot,
|
|
338
331
|
getUnauthorizedServerSnapshot
|
|
339
332
|
);
|
|
340
333
|
react.useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
);
|
|
334
|
+
if (snapshot2.activeHostId !== hostId) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
345
337
|
const handleConfirm = () => {
|
|
346
338
|
const options = confirmUnauthorizedModal();
|
|
347
339
|
if (options) {
|
|
348
340
|
executeUnauthorizedAction(options);
|
|
349
341
|
}
|
|
350
342
|
};
|
|
351
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
)
|
|
367
|
-
] });
|
|
343
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
344
|
+
ggUi.Modal,
|
|
345
|
+
{
|
|
346
|
+
afterClose: completeUnauthorizedModal,
|
|
347
|
+
cancelText: "取消",
|
|
348
|
+
closable: true,
|
|
349
|
+
okText: "重新登录",
|
|
350
|
+
open: snapshot2.phase === "open",
|
|
351
|
+
title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
|
|
352
|
+
onCancel: cancelUnauthorizedModal,
|
|
353
|
+
onOk: handleConfirm,
|
|
354
|
+
children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
|
|
355
|
+
}
|
|
356
|
+
);
|
|
368
357
|
};
|
|
369
358
|
GzFetchUnauthorizedModal.displayName = "GzFetchUnauthorizedModal";
|
|
370
359
|
var GzFetchUnauthorizedModal_default = GzFetchUnauthorizedModal;
|
|
371
360
|
var GzFetchFeedbackProvider = ({ children }) => {
|
|
361
|
+
var _a;
|
|
362
|
+
const hostIdRef = react.useRef(void 0);
|
|
363
|
+
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-feedback-host");
|
|
364
|
+
const hostId = hostIdRef.current;
|
|
365
|
+
const [messageApi, messageContextHolder] = ggUi.message.useMessage();
|
|
366
|
+
const showErrorMessage = react.useCallback(
|
|
367
|
+
(content) => {
|
|
368
|
+
void messageApi.error(content);
|
|
369
|
+
},
|
|
370
|
+
[messageApi]
|
|
371
|
+
);
|
|
372
|
+
react.useEffect(
|
|
373
|
+
() => registerFeedbackHost(hostId, { showErrorMessage }),
|
|
374
|
+
[hostId, showErrorMessage]
|
|
375
|
+
);
|
|
372
376
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
377
|
+
messageContextHolder,
|
|
373
378
|
/* @__PURE__ */ jsxRuntime.jsx(GzFetchUnauthorizedModal_default, {}),
|
|
374
379
|
children
|
|
375
380
|
] });
|
package/dist/fetch/index.d.cts
CHANGED
|
@@ -88,6 +88,7 @@ declare function gzFetch<TResponse, TRequestParams = unknown>(config: GzRequestC
|
|
|
88
88
|
|
|
89
89
|
declare const GzFetchFeedbackProvider: FC<PropsWithChildren>;
|
|
90
90
|
|
|
91
|
+
/** @deprecated 请使用 GzFetchFeedbackProvider 统一接入请求反馈。 */
|
|
91
92
|
declare const GzFetchUnauthorizedModal: FC;
|
|
92
93
|
|
|
93
94
|
export { type CreateGzFetchOptions, type GzErrorContext, type GzFetch, type GzFetchAuthOptions, type GzFetchClient, GzFetchError, type GzFetchErrorOptions, type GzFetchErrorType, GzFetchFeedbackProvider, type GzFetchMiddleware, GzFetchUnauthorizedModal, type GzFetchUnauthorizedOptions, type GzInternalRequestConfig, type GzRequestConfig, type GzRequestHeaders, type GzRequestMethod, type GzRequestOptions, type GzRequestParams, type GzResponseContext, type GzResponseType, configureGzFetch, createGzFetch, getResponseMessage, gzFetch, toGzFetchError };
|
package/dist/fetch/index.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ declare function gzFetch<TResponse, TRequestParams = unknown>(config: GzRequestC
|
|
|
88
88
|
|
|
89
89
|
declare const GzFetchFeedbackProvider: FC<PropsWithChildren>;
|
|
90
90
|
|
|
91
|
+
/** @deprecated 请使用 GzFetchFeedbackProvider 统一接入请求反馈。 */
|
|
91
92
|
declare const GzFetchUnauthorizedModal: FC;
|
|
92
93
|
|
|
93
94
|
export { type CreateGzFetchOptions, type GzErrorContext, type GzFetch, type GzFetchAuthOptions, type GzFetchClient, GzFetchError, type GzFetchErrorOptions, type GzFetchErrorType, GzFetchFeedbackProvider, type GzFetchMiddleware, GzFetchUnauthorizedModal, type GzFetchUnauthorizedOptions, type GzInternalRequestConfig, type GzRequestConfig, type GzRequestHeaders, type GzRequestMethod, type GzRequestOptions, type GzRequestParams, type GzResponseContext, type GzResponseType, configureGzFetch, createGzFetch, getResponseMessage, gzFetch, toGzFetchError };
|
package/dist/fetch/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios, { AxiosError, AxiosHeaders } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
import { useRef,
|
|
4
|
-
import { jsxs, Fragment
|
|
2
|
+
import { Modal, message } from '@chenhui996/gg-ui';
|
|
3
|
+
import { useRef, useSyncExternalStore, useEffect, useCallback } from 'react';
|
|
4
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
// src/fetch/client.ts
|
|
7
7
|
var GzFetchError = class extends Error {
|
|
@@ -319,51 +319,56 @@ var GzFetchUnauthorizedModal = () => {
|
|
|
319
319
|
const hostIdRef = useRef(void 0);
|
|
320
320
|
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-unauthorized-modal-host");
|
|
321
321
|
const hostId = hostIdRef.current;
|
|
322
|
-
const [messageApi, messageContextHolder] = message.useMessage();
|
|
323
|
-
const showErrorMessage = useCallback(
|
|
324
|
-
(content) => {
|
|
325
|
-
void messageApi.error(content);
|
|
326
|
-
},
|
|
327
|
-
[messageApi]
|
|
328
|
-
);
|
|
329
322
|
const snapshot2 = useSyncExternalStore(
|
|
330
323
|
subscribeUnauthorized,
|
|
331
324
|
getUnauthorizedSnapshot,
|
|
332
325
|
getUnauthorizedServerSnapshot
|
|
333
326
|
);
|
|
334
327
|
useEffect(() => registerUnauthorizedModalHost(hostId), [hostId]);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
);
|
|
328
|
+
if (snapshot2.activeHostId !== hostId) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
339
331
|
const handleConfirm = () => {
|
|
340
332
|
const options = confirmUnauthorizedModal();
|
|
341
333
|
if (options) {
|
|
342
334
|
executeUnauthorizedAction(options);
|
|
343
335
|
}
|
|
344
336
|
};
|
|
345
|
-
return /* @__PURE__ */
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
)
|
|
361
|
-
] });
|
|
337
|
+
return /* @__PURE__ */ jsx(
|
|
338
|
+
Modal,
|
|
339
|
+
{
|
|
340
|
+
afterClose: completeUnauthorizedModal,
|
|
341
|
+
cancelText: "取消",
|
|
342
|
+
closable: true,
|
|
343
|
+
okText: "重新登录",
|
|
344
|
+
open: snapshot2.phase === "open",
|
|
345
|
+
title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
|
|
346
|
+
onCancel: cancelUnauthorizedModal,
|
|
347
|
+
onOk: handleConfirm,
|
|
348
|
+
children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
|
|
349
|
+
}
|
|
350
|
+
);
|
|
362
351
|
};
|
|
363
352
|
GzFetchUnauthorizedModal.displayName = "GzFetchUnauthorizedModal";
|
|
364
353
|
var GzFetchUnauthorizedModal_default = GzFetchUnauthorizedModal;
|
|
365
354
|
var GzFetchFeedbackProvider = ({ children }) => {
|
|
355
|
+
var _a;
|
|
356
|
+
const hostIdRef = useRef(void 0);
|
|
357
|
+
(_a = hostIdRef.current) != null ? _a : hostIdRef.current = /* @__PURE__ */ Symbol("gz-fetch-feedback-host");
|
|
358
|
+
const hostId = hostIdRef.current;
|
|
359
|
+
const [messageApi, messageContextHolder] = message.useMessage();
|
|
360
|
+
const showErrorMessage = useCallback(
|
|
361
|
+
(content) => {
|
|
362
|
+
void messageApi.error(content);
|
|
363
|
+
},
|
|
364
|
+
[messageApi]
|
|
365
|
+
);
|
|
366
|
+
useEffect(
|
|
367
|
+
() => registerFeedbackHost(hostId, { showErrorMessage }),
|
|
368
|
+
[hostId, showErrorMessage]
|
|
369
|
+
);
|
|
366
370
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
371
|
+
messageContextHolder,
|
|
367
372
|
/* @__PURE__ */ jsx(GzFetchUnauthorizedModal_default, {}),
|
|
368
373
|
children
|
|
369
374
|
] });
|
package/package.json
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@gz-fronted/gz-pc",
|
|
3
|
-
"version": "0.1.1
|
|
4
|
-
"description": "Shared fetch, hooks and utility primitives for GZ frontend applications.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"sideEffects": false,
|
|
8
|
-
"files": [
|
|
9
|
-
"dist",
|
|
10
|
-
"README.md"
|
|
11
|
-
],
|
|
12
|
-
"exports": {
|
|
13
|
-
"./fetch": {
|
|
14
|
-
"import": {
|
|
15
|
-
"types": "./dist/fetch/index.d.ts",
|
|
16
|
-
"default": "./dist/fetch/index.js"
|
|
17
|
-
},
|
|
18
|
-
"require": {
|
|
19
|
-
"types": "./dist/fetch/index.d.cts",
|
|
20
|
-
"default": "./dist/fetch/index.cjs"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"./hooks": {
|
|
24
|
-
"import": {
|
|
25
|
-
"types": "./dist/hooks/index.d.ts",
|
|
26
|
-
"default": "./dist/hooks/index.js"
|
|
27
|
-
},
|
|
28
|
-
"require": {
|
|
29
|
-
"types": "./dist/hooks/index.d.cts",
|
|
30
|
-
"default": "./dist/hooks/index.cjs"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"./utils": {
|
|
34
|
-
"import": {
|
|
35
|
-
"types": "./dist/utils/index.d.ts",
|
|
36
|
-
"default": "./dist/utils/index.js"
|
|
37
|
-
},
|
|
38
|
-
"require": {
|
|
39
|
-
"types": "./dist/utils/index.d.cts",
|
|
40
|
-
"default": "./dist/utils/index.cjs"
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"./package.json": "./package.json"
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "node scripts/build.mjs",
|
|
47
|
-
"lint": "eslint .",
|
|
48
|
-
"typecheck": "tsc --noEmit",
|
|
49
|
-
"test": "vitest run",
|
|
50
|
-
"test:watch": "vitest",
|
|
51
|
-
"verify:exports": "node tests/exports/smoke.mjs",
|
|
52
|
-
"prepublishOnly": "npm run build",
|
|
53
|
-
"prepare": "husky"
|
|
54
|
-
},
|
|
55
|
-
"dependencies": {
|
|
56
|
-
"ahooks": "^3.9.7",
|
|
57
|
-
"axios": "^1.13.6"
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"@chenhui996/gg-ui": "^0.1.1",
|
|
61
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
62
|
-
},
|
|
63
|
-
"devDependencies": {
|
|
64
|
-
"@chenhui996/gg-ui": "0.1.1",
|
|
65
|
-
"@commitlint/cli": "21.2.1",
|
|
66
|
-
"@commitlint/config-conventional": "21.2.0",
|
|
67
|
-
"@eslint/js": "9.39.4",
|
|
68
|
-
"@types/node": "24.10.0",
|
|
69
|
-
"@types/react": "19.2.14",
|
|
70
|
-
"@types/react-dom": "19.2.3",
|
|
71
|
-
"eslint": "9.39.4",
|
|
72
|
-
"globals": "16.5.0",
|
|
73
|
-
"husky": "9.1.7",
|
|
74
|
-
"lint-staged": "17.2.0",
|
|
75
|
-
"msw": "2.12.7",
|
|
76
|
-
"prettier": "3.9.6",
|
|
77
|
-
"react": "19.2.4",
|
|
78
|
-
"react-dom": "19.2.4",
|
|
79
|
-
"tsup": "8.5.1",
|
|
80
|
-
"typescript": "5.9.3",
|
|
81
|
-
"typescript-eslint": "8.56.1",
|
|
82
|
-
"vitest": "4.1.4"
|
|
83
|
-
},
|
|
84
|
-
"engines": {
|
|
85
|
-
"node": ">=20"
|
|
86
|
-
},
|
|
87
|
-
"publishConfig": {
|
|
88
|
-
"access": "public"
|
|
89
|
-
},
|
|
90
|
-
"lint-staged": {
|
|
91
|
-
"*.{js,jsx,ts,tsx}": [
|
|
92
|
-
"eslint --fix",
|
|
93
|
-
"prettier --write"
|
|
94
|
-
],
|
|
95
|
-
"*.{json,md,yml,yaml,css,less}": [
|
|
96
|
-
"prettier --write"
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@gz-fronted/gz-pc",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Shared fetch, hooks and utility primitives for GZ frontend applications.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./fetch": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/fetch/index.d.ts",
|
|
16
|
+
"default": "./dist/fetch/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/fetch/index.d.cts",
|
|
20
|
+
"default": "./dist/fetch/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"./hooks": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/hooks/index.d.ts",
|
|
26
|
+
"default": "./dist/hooks/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/hooks/index.d.cts",
|
|
30
|
+
"default": "./dist/hooks/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"./utils": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/utils/index.d.ts",
|
|
36
|
+
"default": "./dist/utils/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/utils/index.d.cts",
|
|
40
|
+
"default": "./dist/utils/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "node scripts/build.mjs",
|
|
47
|
+
"lint": "eslint .",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"verify:exports": "node tests/exports/smoke.mjs",
|
|
52
|
+
"prepublishOnly": "npm run build",
|
|
53
|
+
"prepare": "husky"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"ahooks": "^3.9.7",
|
|
57
|
+
"axios": "^1.13.6"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@chenhui996/gg-ui": "^0.1.1",
|
|
61
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@chenhui996/gg-ui": "0.1.1",
|
|
65
|
+
"@commitlint/cli": "21.2.1",
|
|
66
|
+
"@commitlint/config-conventional": "21.2.0",
|
|
67
|
+
"@eslint/js": "9.39.4",
|
|
68
|
+
"@types/node": "24.10.0",
|
|
69
|
+
"@types/react": "19.2.14",
|
|
70
|
+
"@types/react-dom": "19.2.3",
|
|
71
|
+
"eslint": "9.39.4",
|
|
72
|
+
"globals": "16.5.0",
|
|
73
|
+
"husky": "9.1.7",
|
|
74
|
+
"lint-staged": "17.2.0",
|
|
75
|
+
"msw": "2.12.7",
|
|
76
|
+
"prettier": "3.9.6",
|
|
77
|
+
"react": "19.2.4",
|
|
78
|
+
"react-dom": "19.2.4",
|
|
79
|
+
"tsup": "8.5.1",
|
|
80
|
+
"typescript": "5.9.3",
|
|
81
|
+
"typescript-eslint": "8.56.1",
|
|
82
|
+
"vitest": "4.1.4"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=20"
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public"
|
|
89
|
+
},
|
|
90
|
+
"lint-staged": {
|
|
91
|
+
"*.{js,jsx,ts,tsx}": [
|
|
92
|
+
"eslint --fix",
|
|
93
|
+
"prettier --write"
|
|
94
|
+
],
|
|
95
|
+
"*.{json,md,yml,yaml,css,less}": [
|
|
96
|
+
"prettier --write"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|