@base-stone/hooks 1.2.5 → 1.2.7

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.
@@ -72,11 +72,11 @@ declare type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args
72
72
 
73
73
  declare type Placement = 'top' | 'bottom' | 'left' | 'right';
74
74
 
75
- declare interface QueryOptions<T = Record<string, any>> {
75
+ declare interface QueryOptions<K extends string, T = Record<string, any>> {
76
76
  queryFn: (data: QueryParamsData_2) => Promise<QueryResponse_2<T>>;
77
77
  params?: Record<string, any> | undefined;
78
78
  dataType: DataType;
79
- dataKey: string;
79
+ dataKey: K;
80
80
  transform?: (result: Record<string, any>) => Record<string, any>[];
81
81
  initialValue?: Record<string, any> | Record<string, any>[];
82
82
  }
@@ -101,11 +101,11 @@ declare interface QueryResponse_2<T> {
101
101
  data: T;
102
102
  }
103
103
 
104
- declare type QueryResult<T = Record<string, any>> = {
104
+ declare type QueryResult<K extends string, T = Record<string, any>> = {
105
105
  loading: boolean;
106
106
  refresh: (params?: Record<string, any> | undefined) => void;
107
107
  } & {
108
- [P in string]?: T;
108
+ [P in K]?: T;
109
109
  };
110
110
 
111
111
  declare interface RequestFn {
@@ -133,13 +133,13 @@ declare type SelectOption<K extends string | number = string | number> = {
133
133
  [key: string]: any;
134
134
  };
135
135
 
136
- declare type SelectOptionsResult<K extends string | number> = Readonly<{
136
+ declare type SelectOptionsResult<K extends string, V extends string | number = string | number> = Readonly<{
137
137
  loading: boolean;
138
138
  refresh: () => void;
139
139
  } & {
140
- [P in `${K}Options`]: (SelectOption<K> & Record<string, any>)[];
140
+ [P in `${K}Options`]: (SelectOption<V> & Record<string, any>)[];
141
141
  } & {
142
- [P in `${K}Map`]?: MapData<K>;
142
+ [P in `${K}Map`]?: MapData<V>;
143
143
  }>;
144
144
 
145
145
  declare interface SuccessFn {
@@ -200,9 +200,9 @@ export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn
200
200
 
201
201
  export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
202
202
 
203
- export declare function useRequestQuery<T = Record<string, any> | Record<string, any>[] | undefined>({ queryFn, params, dataType, dataKey, initialValue, transform }: QueryOptions<T>): QueryResult<T>;
203
+ export declare function useRequestQuery<T = Record<string, any> | Record<string, any>[] | undefined>({ queryFn, params, dataType, dataKey, initialValue, transform }: QueryOptions<typeof dataKey, T>): QueryResult<typeof dataKey, T>;
204
204
 
205
- export declare function useSelectOptions<K extends string | number = string | number>({ queryFn, params, dataKey, fieldNames, transform }: SelectConfig): SelectOptionsResult<K>;
205
+ export declare function useSelectOptions<V extends string | number = string | number>({ queryFn, params, dataKey, fieldNames, transform }: SelectConfig): SelectOptionsResult<typeof dataKey, V>;
206
206
 
207
207
  export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, params: initParams, transform, rowSelection }: TableOptions<T>): TableResult<T>;
208
208
 
@@ -1,4 +1,4 @@
1
- import { useRef as _, useMemo as I, useState as v, useEffectEvent as j, useEffect as P, useId as W, useCallback as X } from "react";
1
+ import { useRef as _, useMemo as I, useState as S, useEffectEvent as j, useEffect as P, useId as W, useCallback as X } from "react";
2
2
  import { Empty as q, App as K } from "antd";
3
3
  import { create as ee } from "zustand";
4
4
  var N = { exports: {} }, R = {};
@@ -53,7 +53,7 @@ function ce({
53
53
  transform: s,
54
54
  rowSelection: t
55
55
  }) {
56
- const o = T.pageSize, [n, u] = v({
56
+ const o = T.pageSize, [n, u] = S({
57
57
  pagination: {
58
58
  showSizeChanger: !0,
59
59
  showQuickJumper: !0,
@@ -67,7 +67,7 @@ function ce({
67
67
  pageSize: o,
68
68
  ...a
69
69
  }
70
- }), { pagination: c, list: f, queryParams: e } = n, { pageNo: l, pageSize: p } = e, [i, m] = v(!0), [g, y] = v([]), b = I(() => {
70
+ }), { pagination: c, list: f, queryParams: e } = n, { pageNo: l, pageSize: p } = e, [i, m] = S(!0), [g, y] = S([]), b = I(() => {
71
71
  if (t)
72
72
  return {
73
73
  selectedRowKeys: g,
@@ -75,7 +75,7 @@ function ce({
75
75
  };
76
76
  }, [t, g]), x = E(
77
77
  (d) => `共 ${d} 条记录 第 ${l}/${Math.ceil(d / p)} 页 `
78
- ), S = async (d) => {
78
+ ), h = async (d) => {
79
79
  const { pageNo: A } = d;
80
80
  m(!0);
81
81
  const M = { ...a, pageSize: p, ...d };
@@ -92,13 +92,13 @@ function ce({
92
92
  }
93
93
  }), m(!1);
94
94
  }, z = j(() => {
95
- S({ ...e, pageNo: 1 });
95
+ h({ ...e, pageNo: 1 });
96
96
  }), C = (d) => {
97
- S({ ...e, ...d, pageNo: 1 });
98
- }, h = (d) => {
99
- S({ ...e, ...d });
97
+ h({ ...e, ...d, pageNo: 1 });
98
+ }, v = (d) => {
99
+ h({ ...e, ...d });
100
100
  }, D = (d) => {
101
- S({ ...d, pageSize: p, pageNo: 1 });
101
+ h({ ...d, pageSize: p, pageNo: 1 });
102
102
  }, V = (d, A, M, $) => {
103
103
  const { action: k } = $;
104
104
  if (["paginate", "sort"].includes(k)) {
@@ -109,7 +109,7 @@ function ce({
109
109
  pageNo: O,
110
110
  pageSize: F
111
111
  };
112
- S(U);
112
+ h(U);
113
113
  }
114
114
  };
115
115
  return P(() => {
@@ -117,7 +117,7 @@ function ce({
117
117
  }, []), {
118
118
  queryParams: e,
119
119
  search: E(C),
120
- refresh: E(h),
120
+ refresh: E(v),
121
121
  reset: E(D),
122
122
  selectedRowKeys: g,
123
123
  tableProps: {
@@ -209,22 +209,22 @@ function le(r) {
209
209
  }, f;
210
210
  }
211
211
  function de({ queryFn: r, params: a, dataKey: s, fieldNames: t, transform: o }) {
212
- const [n, u] = v({
212
+ const [n, u] = S({
213
213
  list: [],
214
214
  mapData: /* @__PURE__ */ new Map()
215
- }), [c, f] = v(!0), e = async () => {
215
+ }), [c, f] = S(!0), e = async () => {
216
216
  f(!0);
217
- const { data: g } = await r(a), b = (o ? o(g) : g) || [], { label: x, value: S } = t, z = /* @__PURE__ */ new Map([]);
217
+ const { data: g } = await r(a), b = (o ? o(g) : g) || [], { label: x, value: h } = t, z = /* @__PURE__ */ new Map([]);
218
218
  if (t) {
219
- const C = b.map((h) => {
220
- const D = h[S];
221
- return z.set(D, x), {
222
- label: h[x],
219
+ const C = b.map((v) => {
220
+ const D = v[h];
221
+ return z.set(D, v[x]), {
222
+ label: v[x],
223
223
  value: D,
224
- data: h
224
+ data: v
225
225
  };
226
226
  });
227
- u((h) => ({ ...h, list: C, mapData: z }));
227
+ u((v) => ({ ...v, list: C, mapData: z }));
228
228
  } else
229
229
  u((C) => ({ ...C, list: b }));
230
230
  f(!1);
@@ -243,7 +243,7 @@ function de({ queryFn: r, params: a, dataKey: s, fieldNames: t, transform: o })
243
243
  };
244
244
  }
245
245
  function ue(r, a) {
246
- const [s, t] = v(!1), { message: o } = K.useApp(), n = X(async (u) => {
246
+ const [s, t] = S(!1), { message: o } = K.useApp(), n = X(async (u) => {
247
247
  try {
248
248
  t(!0);
249
249
  const c = await r(u), { status: f, info: e } = c;
@@ -265,7 +265,7 @@ function pe({
265
265
  initialValue: o,
266
266
  transform: n
267
267
  }) {
268
- const u = o || (s === "Array" ? [] : /* @__PURE__ */ Object.create({})), [c, f] = v(u), [e, l] = v(!1), p = async (g) => {
268
+ const u = o || (s === "Array" ? [] : /* @__PURE__ */ Object.create({})), [c, f] = S(u), [e, l] = S(!1), p = async (g) => {
269
269
  l(!0);
270
270
  const { data: y } = await r(g ?? a), b = n ? n(y) : y;
271
271
  f(b), l(!1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@base-stone/hooks",
3
3
  "license": "MIT",
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "author": {
6
6
  "name": "leafront",
7
7
  "email": "leafront@126.com"