react-toolkits 2.32.13 → 2.32.15
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/CHANGELOG.md +12 -0
- package/lib/index.d.ts +3 -8
- package/lib/index.js +15 -9
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# react-toolkits
|
|
2
2
|
|
|
3
|
+
## 2.32.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 512207b: refactor: update useKy hook to remove UseKyOptions interface and streamline options handling
|
|
8
|
+
|
|
9
|
+
## 2.32.14
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cf5be23: refactor: enhance GameSelect component to improve query invalidation logic
|
|
14
|
+
|
|
3
15
|
## 2.32.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ButtonProps, SelectProps, FormInstance, DrawerProps, Button, FormProps, ModalProps } from 'antd';
|
|
2
2
|
import { FC, PropsWithChildren, Key, ReactNode, ReactElement, CSSProperties, Ref, DetailedHTMLProps, ImgHTMLAttributes, ComponentProps } from 'react';
|
|
3
|
-
import { Options, KyInstance
|
|
3
|
+
import { Options, KyInstance } from 'ky';
|
|
4
4
|
import { ParagraphProps } from 'antd/es/typography/Paragraph';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { useLocation, PathPattern } from 'react-router';
|
|
@@ -41,11 +41,6 @@ interface KyMethods {
|
|
|
41
41
|
}) => Promise<T>;
|
|
42
42
|
instance: KyInstance;
|
|
43
43
|
}
|
|
44
|
-
/** useKy 配置选项 */
|
|
45
|
-
interface UseKyOptions {
|
|
46
|
-
/** 自定义 hooks(拦截器),在默认 hooks 之前执行 */
|
|
47
|
-
hooks?: Partial<Hooks>;
|
|
48
|
-
}
|
|
49
44
|
/**
|
|
50
45
|
* HTTP 客户端 Hook
|
|
51
46
|
*
|
|
@@ -70,7 +65,7 @@ interface UseKyOptions {
|
|
|
70
65
|
* })
|
|
71
66
|
* ```
|
|
72
67
|
*/
|
|
73
|
-
declare function useKy(options?:
|
|
68
|
+
declare function useKy(options?: Options): KyMethods;
|
|
74
69
|
|
|
75
70
|
interface AuthButtonProps extends ButtonProps {
|
|
76
71
|
/** 权限码,支持单个或多个 */
|
|
@@ -1497,4 +1492,4 @@ declare function useAuth(code?: string | string[], config?: RequestOptions): {
|
|
|
1497
1492
|
declare function useMenuList(): _tanstack_react_query.UseQueryResult<MenuListItem[], Error>;
|
|
1498
1493
|
declare const useGames: () => _tanstack_react_query.UseQueryResult<Game[], Error>;
|
|
1499
1494
|
|
|
1500
|
-
export { APP_ID_HEADER, AuthButton, type AuthButtonProps, AuthMode, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, type GameSelectConfig, type GameSelectProps, type HeaderExtra, type HeaderExtraConfig, Highlight, type HighlightProps, HttpResponseError, InfiniteList, type InfiniteListDataAdapter, type InfiniteListPayload, type InfiniteListProps, type InfiniteListRef, type InfiniteListRequestConfig, type InfiniteListRequestConfigType, type JsonResponse, KeepAlive, type KeepAliveCacheItem, KeepAliveOutlet, type KeepAliveOutletProps, type KeepAliveProps, KeepAliveProvider, type KeepAliveProviderProps, type KyMethods, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, type RecursivePartial, type RequestOptions, RequireAuth, type RequireAuthProps, RequireGame, type ResponseType, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitsProvider, type ToolkitsProviderProps, type UseDrawerOperation, type UseDrawerProps, type UseFormDrawerProps, type UseFormDrawerReturn, type UseFormModalProps, type UseFormModalReturn, type UseKeepAliveReturn, type
|
|
1495
|
+
export { APP_ID_HEADER, AuthButton, type AuthButtonProps, AuthMode, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, type GameSelectConfig, type GameSelectProps, type HeaderExtra, type HeaderExtraConfig, Highlight, type HighlightProps, HttpResponseError, InfiniteList, type InfiniteListDataAdapter, type InfiniteListPayload, type InfiniteListProps, type InfiniteListRef, type InfiniteListRequestConfig, type InfiniteListRequestConfigType, type JsonResponse, KeepAlive, type KeepAliveCacheItem, KeepAliveOutlet, type KeepAliveOutletProps, type KeepAliveProps, KeepAliveProvider, type KeepAliveProviderProps, type KyMethods, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, type RecursivePartial, type RequestOptions, RequireAuth, type RequireAuthProps, RequireGame, type ResponseType, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitsProvider, type ToolkitsProviderProps, type UseDrawerOperation, type UseDrawerProps, type UseFormDrawerProps, type UseFormDrawerReturn, type UseFormModalProps, type UseFormModalReturn, type UseKeepAliveReturn, type UseModalOperation, type UseModalProps, UserDropdown, type VisibilityState, WILDCARD, createVisibilityStoreConfig, generateId, _default$1 as menuRoutes, mixedStorage, _default as permissionRoutes, useAuth, useDrawer, useDrawerStore, useFormDrawer, useFormModal, useGames, useInfiniteListStore, useKeepAlive, useKeepAliveContext, useKy, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitsStore };
|
package/lib/index.js
CHANGED
|
@@ -587,7 +587,8 @@ function useKy(options) {
|
|
|
587
587
|
notification.error({ message: "Request failed", description: errorMessage });
|
|
588
588
|
throw new HttpResponseError(errorMessage, response, data);
|
|
589
589
|
};
|
|
590
|
-
const hooks =
|
|
590
|
+
const { hooks: customHooks, ...kyOptions } = options || {};
|
|
591
|
+
const hooks = mergeHooks(customHooks, {
|
|
591
592
|
beforeRequest: [beforeRequestHook],
|
|
592
593
|
beforeError: [beforeErrorHook],
|
|
593
594
|
afterResponse: [afterResponseHook]
|
|
@@ -596,17 +597,18 @@ function useKy(options) {
|
|
|
596
597
|
prefixUrl: apiBaseUrl,
|
|
597
598
|
retry: 0,
|
|
598
599
|
timeout: REQUEST_TIMEOUT,
|
|
600
|
+
...kyOptions,
|
|
599
601
|
hooks
|
|
600
602
|
});
|
|
601
603
|
const request = async (method, url, data, opts) => {
|
|
602
|
-
const { responseType = "json", isGlobalMode: reqGlobalMode, context, ...
|
|
604
|
+
const { responseType = "json", isGlobalMode: reqGlobalMode, context, ...reqOptions } = opts || {};
|
|
603
605
|
const finalContext = {
|
|
604
606
|
...context,
|
|
605
607
|
responseType,
|
|
606
608
|
...reqGlobalMode !== void 0 && { isGlobalMode: reqGlobalMode }
|
|
607
609
|
};
|
|
608
610
|
const finalOptions = {
|
|
609
|
-
...
|
|
611
|
+
...reqOptions,
|
|
610
612
|
context: finalContext
|
|
611
613
|
};
|
|
612
614
|
if (data !== void 0) {
|
|
@@ -4435,6 +4437,7 @@ var GameSelect = (props) => {
|
|
|
4435
4437
|
const { data, isLoading } = useGames();
|
|
4436
4438
|
const queryClient = useQueryClient();
|
|
4437
4439
|
const keepAlive = useKeepAlive();
|
|
4440
|
+
const pendingRefreshRef = useRef(false);
|
|
4438
4441
|
const selectOptions = useMemo(() => {
|
|
4439
4442
|
const filteredData = filter ? data?.filter((item) => filter(item)) : data;
|
|
4440
4443
|
if (options) return options(filteredData);
|
|
@@ -4443,20 +4446,23 @@ var GameSelect = (props) => {
|
|
|
4443
4446
|
value: String(useGameApiV2 ? item.game_id : item.id)
|
|
4444
4447
|
}));
|
|
4445
4448
|
}, [data, filter, options, useGameApiV2]);
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
+
useEffect(() => {
|
|
4450
|
+
if (!pendingRefreshRef.current) return;
|
|
4451
|
+
pendingRefreshRef.current = false;
|
|
4449
4452
|
queryClient.invalidateQueries({
|
|
4450
4453
|
predicate: (query) => !query.queryKey.includes("/api/game/list") && !query.queryKey.includes("/api/usystem/game/all")
|
|
4451
4454
|
});
|
|
4455
|
+
}, [appId, queryClient]);
|
|
4456
|
+
const handleChange = (value) => {
|
|
4457
|
+
pendingRefreshRef.current = true;
|
|
4458
|
+
keepAlive.clearCache();
|
|
4459
|
+
setAppId(value);
|
|
4452
4460
|
onChange?.(value);
|
|
4453
4461
|
};
|
|
4454
4462
|
useEffect(() => {
|
|
4455
4463
|
if (isLoading || !selectOptions) return;
|
|
4456
4464
|
const isValid = appId && selectOptions.some((item) => String(item.value) === String(appId));
|
|
4457
|
-
if (!isValid)
|
|
4458
|
-
setAppId(selectOptions[0]?.value);
|
|
4459
|
-
}
|
|
4465
|
+
if (!isValid) setAppId(selectOptions[0]?.value);
|
|
4460
4466
|
}, [selectOptions, isLoading, appId, setAppId]);
|
|
4461
4467
|
return /* @__PURE__ */ jsxs(Space, { children: [
|
|
4462
4468
|
/* @__PURE__ */ jsx(Typography.Text, { children: t("GameSelect.label") }),
|