react-toolkits 2.31.10 → 2.32.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 752e915: refactor: replace PermissionMode with AuthMode across the toolkit
8
+
3
9
  ## 2.31.10
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -38,7 +38,7 @@ import 'react-toolkits/style.css'
38
38
  import { createRoot } from 'react-dom/client'
39
39
  import { RouterProvider } from 'react-router'
40
40
  import { ToolkitsProvider } from 'react-toolkits/components'
41
- import { PermissionMode } from 'react-toolkits/constants'
41
+ import { AuthMode } from 'react-toolkits/constants'
42
42
 
43
43
  import router from './router'
44
44
 
@@ -61,13 +61,7 @@ const root = createRoot(document.getElementById('root') as HTMLElement)
61
61
 
62
62
  root.render(
63
63
  <QueryClientProvider client={queryClient}>
64
- <ToolkitsProvider
65
- collapsible
66
- gameApiV2
67
- permissionMode={PermissionMode.GROUP_BASED}
68
- loginPath="/sign_in"
69
- mainPagePath="/"
70
- >
64
+ <ToolkitsProvider collapsible gameApiV2 auth={{ mode: AuthMode.GROUP_BASED }} loginPath="/sign_in" mainPagePath="/">
71
65
  <RouterProvider router={router} />
72
66
  </ToolkitsProvider>
73
67
  </QueryClientProvider>,
@@ -80,7 +74,7 @@ root.render(
80
74
 
81
75
  - **loginPath**: 登录页路径(未鉴权时会跳转)
82
76
  - **mainPagePath**: 登录后主页路径(鉴权通过时进入)
83
- - **permissionMode**: 权限版本,建议使用 `PermissionMode.GROUP_BASED`
77
+ - **auth.mode**: 认证模式,建议使用 `AuthMode.GROUP_BASED`
84
78
  - **collapsible**: 侧边栏是否可折叠
85
79
  - **gameApiV2**: 是否启用游戏相关 V2 接口适配(如不涉及可忽略)
86
80
  - 其余高级配置见类型定义 `react-toolkits/components` 内导出的 Provider Props
@@ -91,7 +85,7 @@ root.render(
91
85
  - `react-toolkits/hooks`:表单弹层 Hooks(如 `useFormDrawer`、`useFormModal`)
92
86
  - `react-toolkits/pages`:内置页面与路由片段(如 `permissionRoutes`、`menuRoutes`、`SignIn`)
93
87
  - `react-toolkits/services`:请求相关 Hooks(如 `useAuth`、`useMenuList`、`useGames`)
94
- - `react-toolkits/constants`:常量与枚举(如 `APP_ID_HEADER`、`PermissionMode`)
88
+ - `react-toolkits/constants`:常量与枚举(如 `APP_ID_HEADER`、`AuthMode`)
95
89
  - `react-toolkits/types`:公共类型
96
90
  - `react-toolkits/utils`:工具函数
97
91
  - `react-toolkits/locale` 与 `react-toolkits/locale/*`:国际化资源与工具
@@ -346,7 +340,7 @@ import { useAuth } from 'react-toolkits/services'
346
340
 
347
341
  ### 权限版本兼容
348
342
 
349
- - 历史上存在不同权限数据结构,`PermissionMode` 用于适配后端变体
343
+ - 历史上存在不同权限数据结构,`AuthMode` 用于适配后端变体
350
344
  - 新项目建议使用 `V3`;旧项目如为 `V2`,只需在 `ToolkitsProvider` 中切换版本
351
345
 
352
346
  ## 常见问题(FAQ)
package/lib/index.d.ts CHANGED
@@ -244,14 +244,30 @@ declare function useKeepAlive(): {
244
244
  };
245
245
  type UseKeepAliveReturn = ReturnType<typeof useKeepAlive>;
246
246
 
247
+ type Primitive = string | number | boolean | bigint | symbol | undefined | null;
248
+
249
+ type Builtin = Primitive | Function | Date | Error | RegExp;
250
+
247
251
  type Prettify<Type> = Type extends Function ? Type : Extract<{
248
252
  [Key in keyof Type]: Type[Key];
249
253
  }, Type>;
250
254
 
251
255
  type Merge<Object1, Object2> = Prettify<Omit<Object1, keyof Object2> & Object2>;
252
256
 
257
+ type IsAny<Type> = 0 extends 1 & Type ? true : false;
258
+
259
+ type IsUnknown<Type> = IsAny<Type> extends true ? false : unknown extends Type ? true : false;
260
+
253
261
  type MarkRequired<Type, Keys extends keyof Type> = Type extends Type ? Prettify<Type & Required<Omit<Type, Exclude<keyof Type, Keys>>>> : never;
254
262
 
263
+ type IsTuple<Type> = Type extends readonly any[] ? (any[] extends Type ? never : Type) : never;
264
+
265
+ type DeepPartial<Type> = Type extends Exclude<Builtin, Error> ? Type : Type extends Map<infer Keys, infer Values> ? Map<DeepPartial<Keys>, DeepPartial<Values>> : Type extends ReadonlyMap<infer Keys, infer Values> ? ReadonlyMap<DeepPartial<Keys>, DeepPartial<Values>> : Type extends WeakMap<infer Keys, infer Values> ? WeakMap<DeepPartial<Keys>, DeepPartial<Values>> : Type extends Set<infer Values> ? Set<DeepPartial<Values>> : Type extends ReadonlySet<infer Values> ? ReadonlySet<DeepPartial<Values>> : Type extends WeakSet<infer Values> ? WeakSet<DeepPartial<Values>> : Type extends ReadonlyArray<infer Values> ? Type extends IsTuple<Type> ? {
266
+ [Key in keyof Type]?: DeepPartial<Type[Key]>;
267
+ } : Type extends Array<Values> ? Array<DeepPartial<Values> | undefined> : ReadonlyArray<DeepPartial<Values> | undefined> : Type extends Promise<infer Value> ? Promise<DeepPartial<Value>> : Type extends {} ? {
268
+ [Key in keyof Type]?: DeepPartial<Type[Key]>;
269
+ } : IsUnknown<Type> extends true ? unknown : Partial<Type>;
270
+
255
271
  interface Game {
256
272
  game_id: string | number;
257
273
  [key: string]: any;
@@ -820,12 +836,12 @@ declare const SSO_URL = "https://idaas.ifunplus.cn/enduser/api/application/plugi
820
836
  declare const APP_ID_HEADER = "App-ID";
821
837
  declare const FRONTEND_ROUTE_PREFIX = "/console/";
822
838
  /**
823
- * 权限系统模式枚举
839
+ * 认证系统模式枚举
824
840
  * - GAME_SCOPED: 游戏范围权限(角色权限包含游戏信息)
825
841
  * - GROUP_BASED: 基于项目组的权限(需要先选择项目组才能选择游戏)
826
842
  * - DIRECT_GAME: 直接游戏权限(不需要项目组,直接选择游戏)
827
843
  */
828
- declare enum PermissionMode {
844
+ declare enum AuthMode {
829
845
  /** 游戏范围权限:角色权限包含游戏范围信息 */
830
846
  GAME_SCOPED = "game_scoped",
831
847
  /** 基于项目组的权限:权限依赖项目组,需要先选择项目组才能选择游戏 */
@@ -927,16 +943,26 @@ type Locale = {
927
943
  };
928
944
 
929
945
  interface ContextSlice {
930
- locale: Locale;
931
- permissionMode: PermissionMode;
946
+ /** 是否使用游戏 API V2 版本 */
932
947
  useGameApiV2: boolean;
933
- loginPath: string;
948
+ /** 为 true 时,APP-ID header 始终使用 'global',否则为当前游戏 id */
934
949
  isGlobalMode: boolean;
935
- gameScoped?: boolean;
950
+ /** 接口基础路径 */
951
+ apiBaseUrl?: string;
952
+ /** 登录页路径 */
953
+ loginPath: string;
954
+ /** 首页地址 */
955
+ homePath: string;
956
+ /** 侧边栏宽度 */
936
957
  sidebarWidth?: number;
958
+ /** 侧边栏是否可折叠 */
937
959
  sidebarCollapsible?: boolean;
938
- homePath: string;
939
- apiBaseUrl?: string;
960
+ /** 数据是否按游戏划分范围,默认为 false */
961
+ gameScoped?: boolean;
962
+ /** 本地化语言包 */
963
+ locale: Locale;
964
+ /** 认证模式 */
965
+ authMode: AuthMode;
940
966
  }
941
967
 
942
968
  interface GameSlice {
@@ -989,7 +1015,20 @@ type ToolkitsState = {
989
1015
 
990
1016
  declare function useToolkitsStore(): ToolkitsState;
991
1017
  declare function useToolkitsStore<T>(selector: (state: ToolkitsState) => T): T;
992
- type ToolkitsProviderProps = PropsWithChildren<Partial<ContextSlice>>;
1018
+ type ToolkitsProviderProps = PropsWithChildren<DeepPartial<ContextSlice>>;
1019
+ /**
1020
+ * ToolkitsProvider 组件
1021
+ *
1022
+ * 支持嵌套使用,子 Provider 会从最近的父 Provider 继承 context 配置。
1023
+ * 子 Provider 的 props 会覆盖父 Provider 的对应配置。
1024
+ *
1025
+ * 当父级 context 或当前 props 发生变化时,会重新创建 store 以确保配置同步。
1026
+ *
1027
+ * @example
1028
+ * 外层 Provider 和内层 Provider 嵌套使用示例:
1029
+ * - 外层:loginPath="/login" apiBaseUrl="https://api.example.com"
1030
+ * - 内层:apiBaseUrl="https://api-v2.example.com" (会覆盖外层的 apiBaseUrl)
1031
+ */
993
1032
  declare const ToolkitsProvider: FC<ToolkitsProviderProps>;
994
1033
 
995
1034
  declare const UserDropdown: FC;
@@ -1450,4 +1489,4 @@ declare function useAuth(code?: string | string[], config?: RequestOptions): {
1450
1489
  declare function useMenuList(): _tanstack_react_query.UseQueryResult<MenuListItem[], Error>;
1451
1490
  declare const useGames: () => _tanstack_react_query.UseQueryResult<Game[], Error>;
1452
1491
 
1453
- export { APP_ID_HEADER, AuthButton, type AuthButtonProps, 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, 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, KyClient, type KyClientOptions, Layout, type LayoutProps, Logo, type LogoProps, type MenuListItem, type NavItem, type NavMenuItemGroupType, type NavMenuItemType, type NavSubMenuType, type NavigationConfig, NotFound, OperationLogList, type PageParam, type Permission, PermissionMode, 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 UseKyOptions, 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, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitsStore };
1492
+ 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, 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, KyClient, type KyClientOptions, 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 UseKyOptions, 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, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitsStore };