react-toolkits 2.8.3 → 2.9.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.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5cd1738: refactor: ContextProvider
8
+
3
9
  ## 2.8.3
4
10
 
5
11
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import * as react from 'react';
2
- import { ReactNode, FC, PropsWithChildren, Key, ReactElement, Ref } from 'react';
3
1
  import * as zustand from 'zustand';
2
+ import * as react from 'react';
3
+ import { FC, PropsWithChildren, Key, ReactNode, ReactElement, Ref } from 'react';
4
4
  import { ParagraphProps } from 'antd/es/typography/Paragraph';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { FormInstance, ButtonProps, ModalProps, FormProps } from 'antd';
@@ -13,6 +13,26 @@ import { AnyObject } from 'antd/es/_util/type';
13
13
  import * as swr from 'swr';
14
14
  import { MutatorCallback, MutatorOptions } from 'swr';
15
15
 
16
+ declare class RequestError extends Error {
17
+ status: number;
18
+ code?: number;
19
+ constructor(opts: {
20
+ message?: string;
21
+ status: number;
22
+ code?: number;
23
+ });
24
+ }
25
+ interface RequestOptions extends Omit<RequestInit, 'body'> {
26
+ body?: Record<string | number, any> | FormData | null;
27
+ params?: Record<string | number, any> | URLSearchParams | null;
28
+ responseType?: 'json' | 'blob' | 'text';
29
+ isGlobal?: boolean;
30
+ }
31
+ type RequestResponse<T> = Pick<Response, 'headers' | 'status' | 'statusText' | 'url'> & {
32
+ data: T;
33
+ };
34
+ declare function request<T = any, R = RequestResponse<T>>(url: string, opts?: RequestOptions): Promise<R>;
35
+
16
36
  type Locale = {
17
37
  global: {
18
38
  noEntitlement: string;
@@ -102,15 +122,22 @@ type Locale = {
102
122
  };
103
123
  };
104
124
 
105
- interface ContextState {
125
+ interface ContextProps {
126
+ locale: Locale;
106
127
  usePermissionApiV2: boolean;
107
- locale?: Locale;
108
- localeDropdownMenu?: ReactNode;
128
+ interceptor?: {
129
+ response?: (response: Response, opts: RequestOptions) => Promise<any>;
130
+ };
109
131
  }
110
-
111
- declare const contextStore: zustand.StoreApi<ContextState>;
112
- declare function useToolkitsContext(): ContextState;
113
- declare const ContextProvider: FC<PropsWithChildren<Partial<ContextState>>>;
132
+ interface ContextState extends ContextProps {
133
+ setContext: (props: Partial<ContextProps>) => void;
134
+ }
135
+ declare const createContextStore: (initProps?: Partial<ContextProps>) => zustand.StoreApi<ContextState>;
136
+ type ContextStore = ReturnType<typeof createContextStore>;
137
+ declare let contextStore: ContextStore;
138
+ declare function useToolkitsContext<T>(selector: (state: ContextState) => T): T;
139
+ type ContextProviderProps = PropsWithChildren<Partial<ContextProps>>;
140
+ declare const ContextProvider: FC<ContextProviderProps>;
114
141
 
115
142
  interface DynamicTagsProps {
116
143
  initialTags?: string[];
@@ -252,26 +279,6 @@ interface PermissionGuardProps {
252
279
  }
253
280
  declare const PermissionGuard: FC<PropsWithChildren<PermissionGuardProps>>;
254
281
 
255
- declare class RequestError extends Error {
256
- status: number;
257
- code?: number;
258
- constructor(opts: {
259
- message?: string;
260
- status: number;
261
- code?: number;
262
- });
263
- }
264
- interface RequestOptions extends Omit<RequestInit, 'body'> {
265
- body?: Record<string | number, any> | FormData | null;
266
- params?: Record<string | number, any> | URLSearchParams | null;
267
- responseType?: 'json' | 'blob' | 'text';
268
- isGlobal?: boolean;
269
- }
270
- type RequestResponse<T> = Pick<Response, 'headers' | 'status' | 'statusText' | 'url'> & {
271
- data: T;
272
- };
273
- declare function request<T = any>(url: string, opts?: RequestOptions): Promise<RequestResponse<T>>;
274
-
275
282
  interface ListResponse<T = any> {
276
283
  list: T[];
277
284
  total: number;
@@ -432,6 +439,7 @@ declare const PermissionRoutes: () => react_jsx_runtime.JSX.Element;
432
439
  interface SignInProps {
433
440
  title?: ReactNode;
434
441
  successRedirectUrl: string;
442
+ extra?: ReactNode;
435
443
  }
436
444
  declare const SignIn: FC<SignInProps>;
437
445