@gz-fronted/gz-pc 0.1.1-beta.3 → 0.1.1-beta.4

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.
@@ -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
- react.useEffect(
342
- () => registerFeedbackHost(hostId, { showErrorMessage }),
343
- [hostId, showErrorMessage]
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.jsxs(jsxRuntime.Fragment, { children: [
352
- messageContextHolder,
353
- snapshot2.activeHostId === hostId && /* @__PURE__ */ jsxRuntime.jsx(
354
- ggUi.Modal,
355
- {
356
- afterClose: completeUnauthorizedModal,
357
- cancelText: "取消",
358
- closable: true,
359
- okText: "重新登录",
360
- open: snapshot2.phase === "open",
361
- title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
362
- onCancel: cancelUnauthorizedModal,
363
- onOk: handleConfirm,
364
- children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
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
  ] });
@@ -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 };
@@ -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 };
@@ -1,7 +1,7 @@
1
1
  import axios, { AxiosError, AxiosHeaders } from 'axios';
2
- import { message, Modal } from '@chenhui996/gg-ui';
3
- import { useRef, useCallback, useSyncExternalStore, useEffect } from 'react';
4
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
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
- useEffect(
336
- () => registerFeedbackHost(hostId, { showErrorMessage }),
337
- [hostId, showErrorMessage]
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__ */ jsxs(Fragment, { children: [
346
- messageContextHolder,
347
- snapshot2.activeHostId === hostId && /* @__PURE__ */ jsx(
348
- Modal,
349
- {
350
- afterClose: completeUnauthorizedModal,
351
- cancelText: "取消",
352
- closable: true,
353
- okText: "重新登录",
354
- open: snapshot2.phase === "open",
355
- title: (_b = snapshot2.options) == null ? void 0 : _b.modalTitle,
356
- onCancel: cancelUnauthorizedModal,
357
- onOk: handleConfirm,
358
- children: (_c = snapshot2.options) == null ? void 0 : _c.modalMessage
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@gz-fronted/gz-pc",
3
- "version": "0.1.1-beta.3",
3
+ "version": "0.1.1-beta.4",
4
4
  "description": "Shared fetch, hooks and utility primitives for GZ frontend applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -42,16 +42,6 @@
42
42
  },
43
43
  "./package.json": "./package.json"
44
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
45
  "dependencies": {
56
46
  "ahooks": "^3.9.7",
57
47
  "axios": "^1.13.6"
@@ -95,5 +85,13 @@
95
85
  "*.{json,md,yml,yaml,css,less}": [
96
86
  "prettier --write"
97
87
  ]
88
+ },
89
+ "scripts": {
90
+ "build": "node scripts/build.mjs",
91
+ "lint": "eslint .",
92
+ "typecheck": "tsc --noEmit",
93
+ "test": "vitest run",
94
+ "test:watch": "vitest",
95
+ "verify:exports": "node tests/exports/smoke.mjs"
98
96
  }
99
- }
97
+ }