@base-stone/hooks 1.0.3 → 1.0.5

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.
@@ -10,6 +10,8 @@ import { TableProps as TableProps_2 } from 'antd';
10
10
  */
11
11
  export declare function configureTableOption(config: GlobalTableConfig): void;
12
12
 
13
+ declare type DataType = 'Array' | 'Object';
14
+
13
15
  export declare interface DrawerProps {
14
16
  size: number | 'default' | 'large';
15
17
  title: string | ReactElement;
@@ -97,22 +99,24 @@ declare interface RequestFn {
97
99
  }>;
98
100
  }
99
101
 
100
- declare interface RequestQueryOptions<T, P = Record<string, any>> {
102
+ declare interface RequestQueryOptions<K extends string = string, T = Record<string, any> | Record<string, any>[]> {
101
103
  queryFn: (data: QueryParamsData_2) => Promise<QueryResponse_2<T>>;
102
- initialValue?: T;
103
- params?: P;
104
+ params?: Record<string, any>;
105
+ dataType: DataType;
106
+ dataKey: K;
104
107
  }
105
108
 
106
- declare interface RequestQueryResult<T> {
107
- data: T;
109
+ declare type RequestQueryResult<K extends string = string, T = Record<string, any>> = {
108
110
  loading: boolean;
109
111
  refresh: () => void;
110
- }
112
+ } & {
113
+ [P in K]?: T;
114
+ };
111
115
 
112
116
  declare interface SelectConfig<K extends string> {
113
117
  queryFn: (data: Record<string, any>) => Promise<QueryResponse>;
114
118
  params?: Record<string, any>;
115
- selectKey: K;
119
+ dataKey: K;
116
120
  fieldNames?: {
117
121
  label: string;
118
122
  value: string;
@@ -191,9 +195,9 @@ export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn
191
195
 
192
196
  export declare function useMemoizedFn<T extends noop>(fn: T): PickFunction<T>;
193
197
 
194
- export declare function useRequestQuery<T, P = Record<string, any>>({ queryFn, params, initialValue }: RequestQueryOptions<T, P>): RequestQueryResult<T>;
198
+ export declare function useRequestQuery<K extends string = string, T = Record<string, any> | Record<string, any>[]>({ queryFn, params, dataType, dataKey }: RequestQueryOptions<K, T>): RequestQueryResult<K, T>;
195
199
 
196
- export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>({ queryFn, params, selectKey, fieldNames }: SelectConfig<K>): SelectOptionsResult<K, T>;
200
+ export declare function useSelectOptions<T extends string | number = string | number, K extends string = string>({ queryFn, params, dataKey, fieldNames }: SelectConfig<K>): SelectOptionsResult<K, T>;
197
201
 
198
202
  export declare function useTableList<T extends Record<string, any> = Record<string, any>>({ queryFn, params: initParams, rowSelection }: TableOptions<T>): TableResult<T>;
199
203
 
@@ -1,37 +1,37 @@
1
- import { useRef as x, useMemo as F, useState as v, useEffect as D, useId as B, useCallback as U } from "react";
2
- import { Empty as N, App as W } from "antd";
1
+ import { useRef as x, useMemo as q, useState as v, useEffect as D, useId as B, useCallback as U } from "react";
2
+ import { Empty as A, App as W } from "antd";
3
3
  import { create as X } from "zustand";
4
4
  var P = { exports: {} }, y = {};
5
- var q;
5
+ var N;
6
6
  function K() {
7
- if (q) return y;
8
- q = 1;
7
+ if (N) return y;
8
+ N = 1;
9
9
  var a = /* @__PURE__ */ Symbol.for("react.transitional.element"), o = /* @__PURE__ */ Symbol.for("react.fragment");
10
- function t(e, n, s) {
10
+ function t(e, s, n) {
11
11
  var p = null;
12
- if (s !== void 0 && (p = "" + s), n.key !== void 0 && (p = "" + n.key), "key" in n) {
13
- s = {};
14
- for (var d in n)
15
- d !== "key" && (s[d] = n[d]);
16
- } else s = n;
17
- return n = s.ref, {
12
+ if (n !== void 0 && (p = "" + n), s.key !== void 0 && (p = "" + s.key), "key" in s) {
13
+ n = {};
14
+ for (var d in s)
15
+ d !== "key" && (n[d] = s[d]);
16
+ } else n = s;
17
+ return s = n.ref, {
18
18
  $$typeof: a,
19
19
  type: e,
20
20
  key: p,
21
- ref: n !== void 0 ? n : null,
22
- props: s
21
+ ref: s !== void 0 ? s : null,
22
+ props: n
23
23
  };
24
24
  }
25
25
  return y.Fragment = o, y.jsx = t, y.jsxs = t, y;
26
26
  }
27
- var A;
27
+ var j;
28
28
  function ee() {
29
- return A || (A = 1, P.exports = K()), P.exports;
29
+ return j || (j = 1, P.exports = K()), P.exports;
30
30
  }
31
31
  var te = ee();
32
32
  function M(a) {
33
33
  const o = x(a);
34
- o.current = F(() => a, [a]);
34
+ o.current = q(() => a, [a]);
35
35
  const t = x(void 0);
36
36
  return t.current || (t.current = function(...e) {
37
37
  return o.current.apply(this, e);
@@ -52,7 +52,7 @@ function ie({
52
52
  params: o,
53
53
  rowSelection: t
54
54
  }) {
55
- const e = R.pageSize, [n, s] = v({
55
+ const e = R.pageSize, [s, n] = v({
56
56
  pagination: {
57
57
  showSizeChanger: !0,
58
58
  showQuickJumper: !0,
@@ -66,7 +66,7 @@ function ie({
66
66
  pageSize: e,
67
67
  ...o
68
68
  }
69
- }), { pagination: p, list: d, queryParams: l } = n, { pageNo: r, pageSize: c } = l, [g, i] = v(!0), S = x(l), [f, b] = v([]), E = F(() => {
69
+ }), { pagination: p, list: d, queryParams: l } = s, { pageNo: r, pageSize: c } = l, [g, i] = v(!0), S = x(l), [f, b] = v([]), E = q(() => {
70
70
  if (t)
71
71
  return {
72
72
  selectedRowKeys: f,
@@ -80,7 +80,7 @@ function ie({
80
80
  const h = { ...o, pageSize: c, ...u };
81
81
  u.pageNo === void 0 && (h.pageNo = 1), u.pageSize === void 0 && (h.pageSize = c);
82
82
  const { data: $ } = await a(h), { list: T = [], totalCount: w = 0 } = $ || {};
83
- t && b([]), s({
83
+ t && b([]), n({
84
84
  list: T,
85
85
  queryParams: h,
86
86
  pagination: {
@@ -92,9 +92,9 @@ function ie({
92
92
  }), i(!1);
93
93
  }, k = (u) => {
94
94
  m({ ...l, ...u, pageNo: 1 });
95
- }, L = (u) => {
95
+ }, F = (u) => {
96
96
  m({ ...l, ...u });
97
- }, j = (u) => {
97
+ }, L = (u) => {
98
98
  m({ ...u, pageSize: c, pageNo: 1 });
99
99
  }, J = (u, O, h, $) => {
100
100
  const { action: T } = $;
@@ -114,8 +114,8 @@ function ie({
114
114
  }, []), {
115
115
  queryParams: l,
116
116
  search: M(k),
117
- refresh: M(L),
118
- reset: M(j),
117
+ refresh: M(F),
118
+ reset: M(L),
119
119
  selectedRowKeys: f,
120
120
  tableProps: {
121
121
  bordered: !0,
@@ -127,7 +127,7 @@ function ie({
127
127
  pagination: { ...p, showTotal: z },
128
128
  onChange: M(J),
129
129
  locale: {
130
- emptyText: g ? "" : /* @__PURE__ */ te.jsx(N, { image: N.PRESENTED_IMAGE_SIMPLE })
130
+ emptyText: g ? "" : /* @__PURE__ */ te.jsx(A, { image: A.PRESENTED_IMAGE_SIMPLE })
131
131
  }
132
132
  }
133
133
  };
@@ -135,20 +135,20 @@ function ie({
135
135
  const C = X((a) => ({
136
136
  modals: {},
137
137
  toggleModal: (o, t) => a((e) => {
138
- const s = e.modals[o]?.visible || !1;
138
+ const n = e.modals[o]?.visible || !1;
139
139
  return {
140
140
  modals: {
141
141
  ...e.modals,
142
142
  [o]: {
143
- visible: !s,
144
- data: s ? {} : t || {}
143
+ visible: !n,
144
+ data: n ? {} : t || {}
145
145
  }
146
146
  }
147
147
  };
148
148
  }),
149
- setModal: (o, t, e) => a((n) => ({
149
+ setModal: (o, t, e) => a((s) => ({
150
150
  modals: {
151
- ...n.modals,
151
+ ...s.modals,
152
152
  [o]: {
153
153
  visible: t,
154
154
  data: t ? e || {} : {}
@@ -157,21 +157,21 @@ const C = X((a) => ({
157
157
  })),
158
158
  clearModals: (o) => a((t) => {
159
159
  const e = { ...t.modals };
160
- return o.forEach((n) => {
161
- delete e[n];
160
+ return o.forEach((s) => {
161
+ delete e[s];
162
162
  }), { modals: e };
163
163
  })
164
164
  }));
165
165
  function le(a) {
166
- const o = C((r) => r.modals), t = C((r) => r.toggleModal), e = C((r) => r.setModal), n = C((r) => r.clearModals), s = B(), p = x([]), d = Object.keys(a);
166
+ const o = C((r) => r.modals), t = C((r) => r.toggleModal), e = C((r) => r.setModal), s = C((r) => r.clearModals), n = B(), p = x([]), d = Object.keys(a);
167
167
  D(() => (p.current = d.map(
168
- (r) => `${s}-${r}`
168
+ (r) => `${n}-${r}`
169
169
  ), () => {
170
- n(p.current);
170
+ s(p.current);
171
171
  }), []);
172
172
  const l = {};
173
173
  return d.forEach((r) => {
174
- const c = `${s}-${r}`, g = o[c] ?? { visible: !1, data: {} }, i = a[r], S = typeof i.title == "function" ? i.title(g.data) : i.title;
174
+ const c = `${n}-${r}`, g = o[c] ?? { visible: !1, data: {} }, i = a[r], S = typeof i.title == "function" ? i.title(g.data) : i.title;
175
175
  l[`${r}Modal`] = {
176
176
  visible: g.visible,
177
177
  data: g.data,
@@ -198,16 +198,16 @@ function le(a) {
198
198
  close: () => e(c, !1)
199
199
  };
200
200
  }), l.toggle = (r, c) => {
201
- t(`${s}-${r}`, c);
201
+ t(`${n}-${r}`, c);
202
202
  }, l.open = (r, c) => {
203
- e(`${s}-${r}`, !0, c);
203
+ e(`${n}-${r}`, !0, c);
204
204
  }, l.close = (r) => {
205
- e(`${s}-${r}`, !1);
205
+ e(`${n}-${r}`, !1);
206
206
  }, l;
207
207
  }
208
208
  const oe = (a, o = "value", t = "label") => new Map(a.map((e) => [e[o], e[t]]));
209
- function ce({ queryFn: a, params: o, selectKey: t, fieldNames: e }) {
210
- const [n, s] = v({
209
+ function ce({ queryFn: a, params: o, dataKey: t, fieldNames: e }) {
210
+ const [s, n] = v({
211
211
  list: [],
212
212
  mapData: /* @__PURE__ */ new Map()
213
213
  }), [p, d] = v(!0), l = async () => {
@@ -219,15 +219,15 @@ function ce({ queryFn: a, params: o, selectKey: t, fieldNames: e }) {
219
219
  label: m[f],
220
220
  value: m[b]
221
221
  })), z = oe(E);
222
- s((m) => ({ ...m, options: E, mapData: z }));
222
+ n((m) => ({ ...m, options: E, mapData: z }));
223
223
  } else
224
- s((f) => ({ ...f, options: S }));
224
+ n((f) => ({ ...f, options: S }));
225
225
  d(!1);
226
226
  }, r = M(void 0);
227
227
  D(() => {
228
228
  l();
229
229
  }, []);
230
- const { list: c, mapData: g } = n;
230
+ const { list: c, mapData: g } = s;
231
231
  return {
232
232
  loading: p,
233
233
  refresh: r,
@@ -236,29 +236,30 @@ function ce({ queryFn: a, params: o, selectKey: t, fieldNames: e }) {
236
236
  };
237
237
  }
238
238
  function ue(a, o) {
239
- const [t, e] = v(!1), { message: n } = W.useApp(), s = U(async (p) => {
239
+ const [t, e] = v(!1), { message: s } = W.useApp(), n = U(async (p) => {
240
240
  try {
241
241
  e(!0);
242
242
  const d = await a(p), { status: l, info: r } = d;
243
- l == "success" && (o(d), n.success(r));
243
+ l == "success" && (o(d), s.success(r));
244
244
  } catch {
245
245
  }
246
246
  e(!1);
247
- }, [a, o, n]);
247
+ }, [a, o, s]);
248
248
  return {
249
249
  loading: t,
250
- submit: s
250
+ submit: n
251
251
  };
252
252
  }
253
253
  function de({
254
254
  queryFn: a,
255
255
  params: o,
256
- initialValue: t
256
+ dataType: t,
257
+ dataKey: e
257
258
  }) {
258
- const [e, n] = v(t), [s, p] = v(!1);
259
+ const [s, n] = v(t === "Array" ? [] : /* @__PURE__ */ Object.create(null)), [p, d] = v(!1);
259
260
  return {
260
- data: e,
261
- loading: s,
261
+ [e]: s,
262
+ loading: p,
262
263
  refresh: M(void 0)
263
264
  };
264
265
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@base-stone/hooks",
3
3
  "license": "MIT",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "author": {
6
6
  "name": "leafront",
7
7
  "email": "leafront@126.com"