@flow97/react-toolkit 0.0.4 → 0.0.6

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,17 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 0.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 5fc6012: refactor: integrate AuthConfig for improved authentication handling
8
+
9
+ ## 0.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 48a1c84: refactor: update KeepAlive components to improve caching behavior and context handling
14
+
3
15
  ## 0.0.4
4
16
 
5
17
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -87,6 +87,11 @@ interface KeepAliveProps {
87
87
  * 使用 React 19 Activity API 实现组件状态缓存,避免路由切换时重新挂载
88
88
  * 支持路由级别的自动缓存:如果不提供 cacheKey,会自动使用当前路由路径作为缓存 key
89
89
  *
90
+ * **重要说明:**
91
+ * - React Activity 会保留组件的状态(state),组件不会被卸载和重新挂载
92
+ * - 但是当 Activity 从 hidden 切换到 visible 时,会重新执行副作用(useEffect)
93
+ * - 这意味着组件的状态会保留,但 useEffect 会重新运行,需要根据业务需求处理副作用
94
+ *
90
95
  * @example
91
96
  * ```tsx
92
97
  * // 手动指定缓存 key
@@ -125,8 +130,6 @@ interface KeepAliveCacheItem {
125
130
  element: ReactNode;
126
131
  /** 是否激活 */
127
132
  active: boolean;
128
- /** 缓存时间戳 */
129
- timestamp: number;
130
133
  }
131
134
  /**
132
135
  * KeepAlive 上下文类型
@@ -172,12 +175,15 @@ declare function useKeepAliveContext(): KeepAliveContextType;
172
175
  * useKeepAlive Hook
173
176
  * 用于控制 KeepAlive 缓存
174
177
  *
178
+ * 如果 KeepAliveProvider 不存在,返回 no-op 实现,不会报错
179
+ * 这样可以在未启用 KeepAlive 的项目中正常使用
180
+ *
175
181
  * @example
176
182
  * ```tsx
177
183
  * const { clearCache, removeCache, getCacheKeys } = useKeepAlive()
178
184
  *
179
185
  * const handleClearAll = () => {
180
- * clearCache() // 清除所有缓存
186
+ * clearCache() // 清除所有缓存(如果 KeepAliveProvider 不存在,则无操作)
181
187
  * }
182
188
  *
183
189
  * const handleClearSpecific = () => {
@@ -186,6 +192,17 @@ declare function useKeepAliveContext(): KeepAliveContextType;
186
192
  * ```
187
193
  */
188
194
  declare function useKeepAlive(): {
195
+ cache: any;
196
+ removeCache: () => void;
197
+ clearCache: () => void;
198
+ clearCacheByPath: () => void;
199
+ clearCurrentCache: () => void;
200
+ getCacheKeys: () => never[];
201
+ getAllCache: () => never[];
202
+ getCache: () => undefined;
203
+ activateCache: () => void;
204
+ deactivateCache: () => void;
205
+ } | {
189
206
  cache: Map<string, KeepAliveCacheItem>;
190
207
  removeCache: (key: string) => void;
191
208
  clearCache: () => void;
@@ -794,18 +811,24 @@ declare const SSO_URL = "https://idaas.ifunplus.cn/enduser/api/application/plugi
794
811
  declare const APP_ID_HEADER = "App-ID";
795
812
  declare const FRONTEND_ROUTE_PREFIX = "/console/";
796
813
  /**
797
- * 认证系统模式枚举
798
- * - GAME_SCOPED: 游戏范围权限(角色权限包含游戏信息)
799
- * - GROUP_BASED: 基于项目组的权限(需要先选择项目组才能选择游戏)
800
- * - DIRECT_GAME: 直接游戏权限(不需要项目组,直接选择游戏)
814
+ * 认证模式枚举:合并了用户配置和角色配置的所有有效组合
801
815
  */
802
816
  declare enum AuthMode {
803
- /** 游戏范围权限:角色权限包含游戏范围信息 */
817
+ /** 直接角色模式(不带游戏):直接将角色分配给用户,角色权限不包含游戏信息 */
818
+ DIRECT_ROLE = "direct_role",
819
+ /** 直接角色模式(带游戏):直接将角色分配给用户,角色权限包含游戏信息 */
820
+ DIRECT_ROLE_WITH_GAME = "direct_role_with_game",
821
+ /** 游戏范围模式:按游戏分配角色,角色权限不包含游戏信息 */
804
822
  GAME_SCOPED = "game_scoped",
805
- /** 基于项目组的权限:权限依赖项目组,需要先选择项目组才能选择游戏 */
806
- GROUP_BASED = "group_based",
807
- /** 直接游戏权限:权限直接选择游戏,不需要项目组作为中间层 */
808
- DIRECT_GAME = "direct_game"
823
+ /** 项目组模式:按项目组-游戏-角色分配,角色权限不包含游戏信息 */
824
+ GROUP_BASED = "group_based"
825
+ }
826
+ /**
827
+ * 认证配置:直接使用 AuthMode
828
+ */
829
+ interface AuthConfig {
830
+ /** 认证模式 */
831
+ mode: AuthMode;
809
832
  }
810
833
  declare const WILDCARD = "*";
811
834
 
@@ -900,16 +923,6 @@ type Locale = {
900
923
  };
901
924
  };
902
925
 
903
- /**
904
- * JWT Token 解密后的用户信息
905
- */
906
- interface UserInfo {
907
- authorityId: string;
908
- exp: number;
909
- }
910
- /**
911
- * Context 配置接口
912
- */
913
926
  interface ContextSlice {
914
927
  /** 是否使用游戏 API V2 版本 */
915
928
  useGameApiV2: boolean;
@@ -927,9 +940,18 @@ interface ContextSlice {
927
940
  gameScoped?: boolean;
928
941
  /** 本地化语言包 */
929
942
  locale: Locale;
930
- /** 认证模式 */
931
- authMode: AuthMode;
943
+ /** 认证配置 */
944
+ authConfig: AuthConfig;
932
945
  }
946
+
947
+ /**
948
+ * JWT Token 解密后的用户信息
949
+ */
950
+ interface UserInfo {
951
+ authorityId: string;
952
+ exp: number;
953
+ }
954
+
933
955
  /**
934
956
  * Token 状态接口
935
957
  */
@@ -1210,6 +1232,31 @@ declare function useFormModal<Values extends AnyObject = AnyObject, ExtraValues
1210
1232
  */
1211
1233
  declare function useModalStore(): VisibilityState;
1212
1234
 
1235
+ /**
1236
+ * 获取当前有效的认证配置
1237
+ */
1238
+ declare function useAuthConfig(): AuthConfig;
1239
+ /**
1240
+ * 获取当前认证模式
1241
+ */
1242
+ declare function useAuthMode(): AuthMode;
1243
+ /**
1244
+ * 判断是否为直接角色模式
1245
+ */
1246
+ declare function useIsDirectRole(): boolean;
1247
+ /**
1248
+ * 判断是否为游戏范围模式
1249
+ */
1250
+ declare function useIsGameScoped(): boolean;
1251
+ /**
1252
+ * 判断是否为项目组模式
1253
+ */
1254
+ declare function useIsGroupBased(): boolean;
1255
+ /**
1256
+ * 判断角色是否包含游戏信息
1257
+ */
1258
+ declare function useIsRoleWithGame(): boolean;
1259
+
1213
1260
  interface NotFoundProps {
1214
1261
  redirectUrl?: string;
1215
1262
  }
@@ -1450,4 +1497,4 @@ declare function useAuth(code?: string | string[], config?: RequestOptions): {
1450
1497
  declare function useMenuList(): _tanstack_react_query.UseQueryResult<MenuListItem[], Error>;
1451
1498
  declare const useGames: () => _tanstack_react_query.UseQueryResult<Game[], Error>;
1452
1499
 
1453
- 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, 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, RequireAuth, type RequireAuthProps, RequireGame, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitProvider, type ToolkitProviderProps, 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, toolkitStore, useAuth, useDrawer, useDrawerStore, useFormDrawer, useFormModal, useGames, useInfiniteListStore, useKeepAlive, useKeepAliveContext, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitStore };
1500
+ export { APP_ID_HEADER, AuthButton, type AuthButtonProps, type AuthConfig, 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, 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, RequireAuth, type RequireAuthProps, RequireGame, type RouteMatchRule, SSO_URL, SelectAll, type SelectAllProps, type ShowFormOptions$1 as ShowFormDrawerOptions, type ShowFormOptions as ShowFormModalOptions, SignIn, ToolkitProvider, type ToolkitProviderProps, 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, toolkitStore, useAuth, useAuthConfig, useAuthMode, useDrawer, useDrawerStore, useFormDrawer, useFormModal, useGames, useInfiniteListStore, useIsDirectRole, useIsGameScoped, useIsGroupBased, useIsRoleWithGame, useKeepAlive, useKeepAliveContext, useMenuList, useModal, useModalStore, useQueryListStore, useToolkitStore };