react-toolkits 2.13.10 → 2.13.12

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
+ ## 2.13.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 0b98376: fix: axios url not right
8
+
9
+ ## 2.13.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 23c7916: Release
14
+
3
15
  ## 2.13.10
4
16
 
5
17
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { FC, PropsWithChildren, Key, ReactNode, ReactElement, Ref, ComponentType
3
3
  import { ParagraphProps } from 'antd/es/typography/Paragraph';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import { FormInstance, MenuProps, ModalProps, FormProps, ButtonProps } from 'antd';
6
+ import { AnyObject } from 'antd/es/_util/type';
6
7
  import { TableProps } from 'antd/es/table';
7
8
  import { AxiosHeaderValue, AxiosRequestConfig, AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosInterceptorOptions } from 'axios';
8
9
  import * as swr from 'swr';
@@ -12,7 +13,6 @@ import { Merge } from 'ts-essentials';
12
13
  import * as zustand_middleware from 'zustand/middleware';
13
14
  import { StateStorage } from 'zustand/middleware';
14
15
  import * as zustand from 'zustand';
15
- import { AnyObject } from 'antd/es/_util/type';
16
16
 
17
17
  interface DynamicTagsProps {
18
18
  initialTags?: string[];
@@ -44,26 +44,31 @@ interface HighlightProps extends PropsWithChildren {
44
44
  }
45
45
  declare const Highlight: (props: HighlightProps) => react_jsx_runtime.JSX.Element;
46
46
 
47
- interface InfiniteListExtra<Values> {
48
- key: Key;
49
- children: ReactNode | ((form: FormInstance<Values>) => ReactNode);
47
+ interface InfiniteListRef<Item extends AnyObject = AnyObject, Values = AnyObject, Data = any> {
48
+ data: Data[] | undefined;
49
+ dataSource: Item[] | undefined;
50
+ form: FormInstance<Values>;
50
51
  }
51
- interface InfiniteListProps<Item, Values, Response> extends Pick<TableProps<Item>, 'columns' | 'rowKey' | 'tableLayout' | 'expandable' | 'rowSelection' | 'bordered'> {
52
+ interface InfiniteListProps<Item, Values, Data> extends Pick<TableProps<Item>, 'columns' | 'rowKey' | 'tableLayout' | 'expandable' | 'rowSelection' | 'bordered'>, Pick<FilterFormWrapperProps, 'buttonsAlign' | 'showReset'> {
52
53
  url: string;
53
- getRowKey: (response: Response) => any;
54
- getDataSource: (data: (Response | undefined)[] | undefined) => Item[];
54
+ getRowKey: (response: Data | undefined) => any;
55
+ getDataSource: (data: Data[] | undefined) => Item[];
56
+ form?: FormInstance<Values>;
55
57
  code?: string;
56
58
  headers?: {
57
59
  [key: string]: AxiosHeaderValue;
58
60
  } | ((form: FormInstance<Values>) => {
59
61
  [key: string]: AxiosHeaderValue;
60
62
  });
61
- renderForm?: (form: FormInstance<Values>) => ReactNode;
62
- transformArg: (values: Values, rowKey?: string) => Record<any, any>;
63
- hasMore?: (data: (Response | undefined)[] | undefined) => boolean;
64
- extras?: InfiniteListExtra<Values>[];
63
+ renderForm?: (form: FormInstance<Values>) => ReactElement;
64
+ params: (values: Values, rowKey?: string) => Record<any, any>;
65
+ getHasMore?: (data: Data | undefined) => boolean;
66
+ tableExtra?: ReactNode | ((form: FormInstance<Values>) => ReactNode);
67
+ footer?: (data: (Data | undefined)[] | undefined) => ReactNode;
65
68
  }
66
- declare const InfiniteList: <Item extends object, Values extends object | undefined = undefined, Response = any>(props: InfiniteListProps<Item, Values, Response>) => react_jsx_runtime.JSX.Element;
69
+ declare const InfiniteList: <Item extends AnyObject = AnyObject, Values extends object | undefined = undefined, Data = any>(props: InfiniteListProps<Item, Values, Data> & {
70
+ ref?: Ref<InfiniteListRef<Item, Data>>;
71
+ }) => ReactElement;
67
72
 
68
73
  type Area = 'all' | 'cn' | 'global';
69
74
  type ScreenOrientation = 0 | 1;
@@ -477,4 +482,4 @@ declare const SignIn: FC<SignInProps>;
477
482
 
478
483
  declare const mixedStorage: StateStorage;
479
484
 
480
- export { APP_ID_HEADER, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, Highlight, type HighlightProps, InfiniteList, type InfiniteListProps, type JsonData, Layout, type LayoutProps, type LayoutState, type MenuListItem, NavMenu, type NavMenuItem, NotFound, _default$1 as OperationLogList, type Permission, PermissionButton, type PermissionButtonProps, PermissionVersion, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, RequireGame, RequirePermission, type RequirePermissionProps, SSO_URL, SignIn, ToolkitsProvider, type ToolkitsProviderProps, type UseFormModalProps, UserWidget, WILDCARD, _default$2 as menuRoutes, mixedStorage, _default as permissionRoutes, useFindGame, useFormModal, useGames, useLayoutStore, useMenuList, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useToolkitsStore, withContext };
485
+ export { APP_ID_HEADER, DynamicTags, type DynamicTagsProps, ExpandableParagraph, type ExpandableParagraphProps, FRONTEND_ROUTE_PREFIX, FilterFormWrapper, type FilterFormWrapperProps, type Game, Highlight, type HighlightProps, InfiniteList, type InfiniteListProps, type InfiniteListRef, type JsonData, Layout, type LayoutProps, type LayoutState, type MenuListItem, NavMenu, type NavMenuItem, NotFound, _default$1 as OperationLogList, type Permission, PermissionButton, type PermissionButtonProps, PermissionVersion, QueryList, QueryListAction, type QueryListPayload, type QueryListProps, type QueryListRef, RequireGame, RequirePermission, type RequirePermissionProps, SSO_URL, SignIn, ToolkitsProvider, type ToolkitsProviderProps, type UseFormModalProps, UserWidget, WILDCARD, _default$2 as menuRoutes, mixedStorage, _default as permissionRoutes, useFindGame, useFormModal, useGames, useLayoutStore, useMenuList, useModal, useModalStore, usePermission, usePermissions, useQueryListStore, useToolkitsStore, withContext };
package/lib/index.js CHANGED
@@ -3,10 +3,10 @@ import { jwtDecode } from 'jwt-decode';
3
3
  import { useStore, create, createStore } from 'zustand';
4
4
  import { persist, createJSONStorage } from 'zustand/middleware';
5
5
  import * as Antd2 from 'antd';
6
- import { Modal, Form, Card, Input, Select, theme, Space, Tag, Typography, Spin, Result, Table, Button, Alert, Divider, Menu, App, Switch, InputNumber, Row, Col, Breadcrumb, Descriptions, Skeleton, Empty, Dropdown, Tooltip, Popconfirm, Collapse, Checkbox } from 'antd';
7
- import { lazy, useContext, useMemo, useState, useRef, useEffect, createContext, memo, useCallback, forwardRef, Fragment as Fragment$1, Suspense, useImperativeHandle, cloneElement } from 'react';
6
+ import { Modal, Form, Spin, Result, Table, Button, Card, Input, Select, theme, Space, Tag, Typography, Alert, Divider, Menu, App, Switch, InputNumber, Row, Col, Breadcrumb, Descriptions, Skeleton, Empty, Dropdown, Tooltip, Popconfirm, Collapse, Checkbox } from 'antd';
7
+ import { forwardRef, lazy, useContext, useMemo, useState, useEffect, useImperativeHandle, cloneElement, useRef, createContext, memo, useCallback, Fragment as Fragment$1, Suspense } from 'react';
8
8
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
- import { has, template, get, isEqual, last, first } from 'lodash-es';
9
+ import { last, has, template, get, isEqual, first } from 'lodash-es';
10
10
  import { flushSync } from 'react-dom';
11
11
  import { createRoot } from 'react-dom/client';
12
12
  import useSWR5, { mutate, unstable_serialize } from 'swr';
@@ -518,19 +518,16 @@ var init_highlight = __esm({
518
518
  }
519
519
  });
520
520
  function useMenuList() {
521
- const { signInPath, axios: axios2, token, gameId } = useToolkitsStore((s) => s);
521
+ const { signInPath, axios: axios2 } = useToolkitsStore((s) => s);
522
522
  return useSWR5(
523
- window.location.pathname !== signInPath ? ["/api/usystem/menu/navbar", gameId] : null,
524
- ([url4]) => axios2(url4, {
525
- headers: { Authorization: `Bearer ${token}`, [APP_ID_HEADER]: gameId }
526
- }).then((response) => response.data.data)
523
+ window.location.pathname !== signInPath ? "/api/usystem/menu/navbar" : null,
524
+ (url4) => axios2(url4).then((response) => response.data.data)
527
525
  );
528
526
  }
529
527
  var usePermissions, usePermission;
530
528
  var init_hooks2 = __esm({
531
529
  "src/hooks/index.ts"() {
532
530
  init_toolkitsProvider();
533
- init_constants();
534
531
  usePermissions = (codes = [], config) => {
535
532
  const { axios: axios2, permissionVersion } = useToolkitsStore((s) => s);
536
533
  const { data, ...rest } = useSWR5(
@@ -2684,7 +2681,9 @@ var init_userDetail = __esm({
2684
2681
  title: t("global.projectGroup"),
2685
2682
  dataIndex: "game_group",
2686
2683
  render(value) {
2687
- return value.map((item) => /* @__PURE__ */ jsx(Tag, { children: item }, item));
2684
+ return value.map((item) => {
2685
+ return /* @__PURE__ */ jsx(Tag, { children: item === WILDCARD ? "\u901A\u7528" : item }, item);
2686
+ });
2688
2687
  }
2689
2688
  },
2690
2689
  {
@@ -3159,27 +3158,43 @@ init_hooks2();
3159
3158
  init_filterFormWrapper();
3160
3159
  init_locale();
3161
3160
  init_toolkitsProvider();
3162
- var InfiniteList = (props) => {
3163
- const { code, url: url4, extras, headers, getRowKey, getDataSource, hasMore, renderForm, transformArg, ...tableProps } = props;
3161
+ var InternalInfiniteList = (props, ref) => {
3162
+ const {
3163
+ code,
3164
+ url: url4,
3165
+ tableExtra,
3166
+ headers,
3167
+ getRowKey,
3168
+ getDataSource,
3169
+ getHasMore,
3170
+ renderForm,
3171
+ params,
3172
+ footer,
3173
+ form,
3174
+ buttonsAlign,
3175
+ showReset,
3176
+ ...tableProps
3177
+ } = props;
3164
3178
  const { t } = useTranslation();
3165
- const [form] = Form.useForm();
3179
+ const [_form] = Form.useForm(form);
3166
3180
  const [isValid, setIsValid] = useState(false);
3167
3181
  const [formValues, setFormValues] = useState();
3168
3182
  const { axios: axios2 } = useToolkitsStore((s) => s);
3169
3183
  const getKey = (pageIndex, previousPageData) => {
3170
3184
  if (!isValid) return null;
3171
3185
  const rowKey = pageIndex !== 0 ? getRowKey(previousPageData) : void 0;
3172
- const args = transformArg(formValues, rowKey);
3186
+ const args = params(formValues, rowKey);
3173
3187
  const queryString = qs.stringify(args);
3174
3188
  return queryString ? `${url4}?${qs.stringify(args)}` : url4;
3175
3189
  };
3176
- const _headers = typeof headers === "function" ? headers(form) : headers;
3190
+ const _headers = typeof headers === "function" ? headers(_form) : headers;
3177
3191
  const { accessible, isLoading } = usePermission(code);
3178
3192
  const {
3179
3193
  data,
3180
3194
  size,
3181
3195
  setSize,
3182
- isValidating: isListValidating
3196
+ isValidating: isListValidating,
3197
+ mutate: mutate2
3183
3198
  } = useSWRInfinite(
3184
3199
  getKey,
3185
3200
  async (arg) => {
@@ -3194,15 +3209,16 @@ var InfiniteList = (props) => {
3194
3209
  );
3195
3210
  const dataSource = getDataSource(data);
3196
3211
  const isLoadingMore = isListValidating || size > 0 && data && typeof data[size - 1] === "undefined";
3197
- const isReachingEnd = typeof hasMore !== "undefined" ? !hasMore(data) : true;
3212
+ const isReachingEnd = typeof getHasMore !== "undefined" ? !getHasMore(last(data)) : true;
3198
3213
  const isEmpty = !dataSource || dataSource.length === 0;
3199
3214
  const onConfirm = async () => {
3200
- const values = await form.getFieldsValue();
3215
+ const values = await _form.getFieldsValue();
3201
3216
  setFormValues(values);
3202
3217
  try {
3203
- await form.validateFields();
3204
- setSize(1);
3218
+ await _form.validateFields();
3205
3219
  setIsValid(true);
3220
+ setSize(1);
3221
+ mutate2();
3206
3222
  } catch (_) {
3207
3223
  setSize(0);
3208
3224
  setIsValid(false);
@@ -3213,23 +3229,30 @@ var InfiniteList = (props) => {
3213
3229
  };
3214
3230
  const onReset = async () => {
3215
3231
  try {
3216
- form.resetFields();
3217
- await form.validateFields({ validateOnly: true });
3232
+ _form.resetFields();
3233
+ await _form.validateFields({ validateOnly: true });
3218
3234
  setSize(1);
3219
3235
  } catch (error) {
3220
3236
  setSize(0);
3221
3237
  }
3222
3238
  };
3223
3239
  useEffect(() => {
3224
- if (accessible) {
3225
- form.validateFields({ validateOnly: true }).then((values) => {
3226
- setFormValues(values);
3227
- setIsValid(true);
3228
- }).catch(() => {
3229
- setIsValid(false);
3230
- });
3231
- }
3240
+ setTimeout(() => {
3241
+ if (accessible) {
3242
+ _form.validateFields({ validateOnly: true }).then((values) => {
3243
+ setFormValues(values);
3244
+ setIsValid(true);
3245
+ }).catch(() => {
3246
+ setIsValid(false);
3247
+ });
3248
+ }
3249
+ }, 300);
3232
3250
  }, [accessible]);
3251
+ useImperativeHandle(ref, () => ({
3252
+ data,
3253
+ dataSource,
3254
+ form: _form
3255
+ }));
3233
3256
  if (isLoading) {
3234
3257
  return /* @__PURE__ */ jsx(
3235
3258
  Spin,
@@ -3246,20 +3269,31 @@ var InfiniteList = (props) => {
3246
3269
  if (!accessible) {
3247
3270
  return /* @__PURE__ */ jsx(Result, { status: 403, subTitle: t("global.noEntitlement") });
3248
3271
  }
3272
+ const renderFooter = footer && (() => footer(data));
3273
+ const formRenderer = typeof renderForm === "function" ? /* @__PURE__ */ jsx(
3274
+ FilterFormWrapper_default,
3275
+ {
3276
+ showReset,
3277
+ buttonsAlign,
3278
+ isConfirming: isListValidating,
3279
+ onReset,
3280
+ onConfirm,
3281
+ children: cloneElement(renderForm(_form), {
3282
+ onKeyUp: (e) => {
3283
+ if (e.key === "Enter") {
3284
+ onConfirm();
3285
+ }
3286
+ }
3287
+ })
3288
+ }
3289
+ ) : (
3290
+ // 屏蔽 Form 组件的警告(Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?)
3291
+ /* @__PURE__ */ jsx(Form, { form: _form })
3292
+ );
3249
3293
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3250
- renderForm ? /* @__PURE__ */ jsx(
3251
- FilterFormWrapper_default,
3252
- {
3253
- extras: extras?.map((extra) => ({
3254
- key: extra.key,
3255
- children: typeof extra.children === "function" ? extra.children(form) : extra.children
3256
- })),
3257
- onReset,
3258
- onConfirm,
3259
- children: renderForm(form)
3260
- }
3261
- ) : /* @__PURE__ */ jsx(Form, { form }),
3262
- /* @__PURE__ */ jsx(Table, { ...tableProps, dataSource, loading: isLoadingMore, pagination: false }),
3294
+ formRenderer,
3295
+ typeof tableExtra === "function" ? tableExtra(_form) : tableExtra,
3296
+ /* @__PURE__ */ jsx(Table, { ...tableProps, dataSource, loading: isLoadingMore, pagination: false, footer: renderFooter }),
3263
3297
  !isEmpty && /* @__PURE__ */ jsx(
3264
3298
  Button,
3265
3299
  {
@@ -3274,6 +3308,7 @@ var InfiniteList = (props) => {
3274
3308
  )
3275
3309
  ] });
3276
3310
  };
3311
+ var InfiniteList = forwardRef(InternalInfiniteList);
3277
3312
  var InfiniteList_default = InfiniteList;
3278
3313
 
3279
3314
  // src/index.ts