@base-stone/hooks 0.9.1 → 0.9.3

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.
@@ -9,6 +9,16 @@ import { TableProps as TableProps_2 } from 'antd';
9
9
  */
10
10
  export declare function configureTableOption(config: GlobalTableConfig): void;
11
11
 
12
+ export declare interface DrawerProps {
13
+ size: number | string;
14
+ title: string;
15
+ open: boolean;
16
+ maskClosable: boolean;
17
+ destroyOnHidden: boolean;
18
+ placement: string;
19
+ onClose: () => void;
20
+ }
21
+
12
22
  declare interface FormSubmitResult {
13
23
  loading: boolean;
14
24
  submit: (number?: unknown) => void;
@@ -22,19 +32,22 @@ declare interface GlobalTableConfig {
22
32
 
23
33
  declare type MapData<T extends string | number = string | number> = Map<T, string | number | undefined>;
24
34
 
25
- declare interface ModalConfig<T = any> {
35
+ declare interface ModalConfig<T = Record<string, any>> {
26
36
  width: number;
27
37
  title: string | ((data: T) => string);
28
38
  maskClosable?: boolean;
29
39
  centered?: boolean;
30
40
  destroyOnHidden?: boolean;
41
+ placement?: 'top' | 'bottom' | 'left' | 'right';
42
+ onClose?: () => void;
31
43
  onCancel?: () => void;
32
44
  }
33
45
 
34
46
  declare type ModalInstance<T = any> = {
35
47
  visible: boolean;
36
48
  data: T;
37
- props: ModalProps;
49
+ modalProps: ModalProps;
50
+ drawerProps: DrawerProps;
38
51
  toggle: (data?: T) => void;
39
52
  open: (data?: T) => void;
40
53
  close: () => void;
@@ -1,46 +1,46 @@
1
- import { useState as y, useRef as I, useMemo as L, useCallback as S, useEffect as D, useId as W } from "react";
2
- import { Empty as O, App as X } from "antd";
1
+ import { useState as b, useRef as I, useMemo as A, useCallback as S, useEffect as k, useId as W } from "react";
2
+ import { Empty as L, App as X } from "antd";
3
3
  import { create as K } from "zustand";
4
- var P = { exports: {} }, b = {};
4
+ var T = { exports: {} }, E = {};
5
5
  var j;
6
6
  function ee() {
7
- if (j) return b;
7
+ if (j) return E;
8
8
  j = 1;
9
9
  var n = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
10
10
  function a(t, o, s) {
11
- var g = null;
12
- if (s !== void 0 && (g = "" + s), o.key !== void 0 && (g = "" + o.key), "key" in o) {
11
+ var m = null;
12
+ if (s !== void 0 && (m = "" + s), o.key !== void 0 && (m = "" + o.key), "key" in o) {
13
13
  s = {};
14
- for (var i in o)
15
- i !== "key" && (s[i] = o[i]);
14
+ for (var l in o)
15
+ l !== "key" && (s[l] = o[l]);
16
16
  } else s = o;
17
17
  return o = s.ref, {
18
18
  $$typeof: n,
19
19
  type: t,
20
- key: g,
20
+ key: m,
21
21
  ref: o !== void 0 ? o : null,
22
22
  props: s
23
23
  };
24
24
  }
25
- return b.Fragment = r, b.jsx = a, b.jsxs = a, b;
25
+ return E.Fragment = r, E.jsx = a, E.jsxs = a, E;
26
26
  }
27
27
  var q;
28
28
  function te() {
29
- return q || (q = 1, P.exports = ee()), P.exports;
29
+ return q || (q = 1, T.exports = ee()), T.exports;
30
30
  }
31
31
  var oe = te();
32
- const C = {
32
+ const R = {
33
33
  sortField: ["orderType", "orderField"],
34
34
  sortOrder: ["ASC", "DESC"],
35
35
  pageSize: 10
36
36
  };
37
37
  function ie(n) {
38
38
  Object.keys(n).forEach((r) => {
39
- C[r] = n[r];
39
+ R[r] = n[r];
40
40
  });
41
41
  }
42
42
  function le(n, r = {}) {
43
- const { rowSelection: a, ...t } = r, o = C.pageSize, [s, g] = y({
43
+ const { rowSelection: a, ...t } = r, o = R.pageSize, [s, m] = b({
44
44
  pagination: {
45
45
  showSizeChanger: !0,
46
46
  showQuickJumper: !0,
@@ -54,89 +54,89 @@ function le(n, r = {}) {
54
54
  pageSize: o,
55
55
  ...t
56
56
  }
57
- }), { pagination: i, list: f, queryParams: e } = s, { pageNo: c, pageSize: u } = e, [d, E] = y(!0), m = I(e), [M, x] = y([]), h = L(() => {
57
+ }), { pagination: l, list: f, queryParams: e } = s, { pageNo: d, pageSize: u } = e, [i, M] = b(!0), g = I(e), [v, C] = b([]), h = A(() => {
58
58
  if (a)
59
59
  return {
60
- selectedRowKeys: M,
61
- onChange: (l) => x(l)
60
+ selectedRowKeys: v,
61
+ onChange: (c) => C(c)
62
62
  };
63
- }, [a, M]), R = S(
64
- (l) => `共 ${l} 条记录 第 ${c}/${Math.ceil(l / u)} 页 `,
65
- [c, u]
63
+ }, [a, v]), x = S(
64
+ (c) => `共 ${c} 条记录 第 ${d}/${Math.ceil(c / u)} 页 `,
65
+ [d, u]
66
66
  ), p = S(
67
- async (l) => {
68
- const { pageNo: k } = l;
69
- E(!0);
70
- const v = { ...t, pageSize: u, ...l };
71
- l.pageNo === void 0 && (v.pageNo = 1), l.pageSize === void 0 && (v.pageSize = u);
72
- const { data: w } = await n(v), { list: T = [], totalCount: z = 0 } = w || {};
73
- a && x([]), g({
74
- list: T,
75
- queryParams: v,
67
+ async (c) => {
68
+ const { pageNo: O } = c;
69
+ M(!0);
70
+ const y = { ...t, pageSize: u, ...c };
71
+ c.pageNo === void 0 && (y.pageNo = 1), c.pageSize === void 0 && (y.pageSize = u);
72
+ const { data: $ } = await n(y), { list: z = [], totalCount: P = 0 } = $ || {};
73
+ a && C([]), m({
74
+ list: z,
75
+ queryParams: y,
76
76
  pagination: {
77
- ...i,
78
- current: k,
79
- pageSize: v.pageSize,
80
- total: z
77
+ ...l,
78
+ current: O,
79
+ pageSize: y.pageSize,
80
+ total: P
81
81
  }
82
- }), E(!1);
82
+ }), M(!1);
83
83
  },
84
- [e, t, a, u, n, i]
85
- ), N = S(
86
- (l) => {
87
- p({ ...e, ...l, pageNo: 1 });
84
+ [e, t, a, u, n, l]
85
+ ), D = S(
86
+ (c) => {
87
+ p({ ...e, ...c, pageNo: 1 });
88
88
  },
89
89
  [p, e]
90
90
  ), J = S(
91
- (l) => {
92
- p({ ...e, ...l });
91
+ (c) => {
92
+ p({ ...e, ...c });
93
93
  },
94
94
  [p, e]
95
95
  ), F = S(
96
- (l) => {
97
- p({ ...l, pageSize: u, pageNo: 1 });
96
+ (c) => {
97
+ p({ ...c, pageSize: u, pageNo: 1 });
98
98
  },
99
99
  [p, u]
100
- ), _ = S(
101
- (l, k, v, w) => {
102
- const { action: T } = w;
103
- if (["paginate", "sort"].includes(T)) {
104
- const { current: z, pageSize: V } = l, { field: H, order: A } = v, [Q, Y] = C.sortField, [Z, B] = C.sortOrder, U = {
100
+ ), N = S(
101
+ (c, O, y, $) => {
102
+ const { action: z } = $;
103
+ if (["paginate", "sort"].includes(z)) {
104
+ const { current: P, pageSize: G } = c, { field: V, order: _ } = y, [Q, Y] = R.sortField, [Z, B] = R.sortOrder, U = {
105
105
  ...e,
106
- [Q]: A ? A === "ascend" ? Z : B : void 0,
107
- [Y]: H,
108
- pageNo: z,
109
- pageSize: V
106
+ [Q]: _ ? _ === "ascend" ? Z : B : void 0,
107
+ [Y]: V,
108
+ pageNo: P,
109
+ pageSize: G
110
110
  };
111
111
  p(U);
112
112
  }
113
113
  },
114
114
  [e, p]
115
- ), G = L(() => ({
115
+ ), H = A(() => ({
116
116
  bordered: !0,
117
117
  size: "middle",
118
118
  sticky: !0,
119
119
  rowSelection: h,
120
- pagination: { ...i, showTotal: R },
121
- loading: d,
120
+ pagination: { ...l, showTotal: x },
121
+ loading: i,
122
122
  dataSource: f,
123
- onChange: _,
123
+ onChange: N,
124
124
  locale: {
125
- emptyText: d ? "" : /* @__PURE__ */ oe.jsx(O, { image: O.PRESENTED_IMAGE_SIMPLE })
125
+ emptyText: i ? "" : /* @__PURE__ */ oe.jsx(L, { image: L.PRESENTED_IMAGE_SIMPLE })
126
126
  }
127
- }), [h, i, R, d, f, _]);
128
- return D(() => {
129
- N(m.current);
127
+ }), [h, l, x, i, f, N]);
128
+ return k(() => {
129
+ D(g.current);
130
130
  }, []), {
131
131
  queryParams: e,
132
- reload: N,
132
+ reload: D,
133
133
  refresh: J,
134
134
  reset: F,
135
- selectedRowKeys: M,
136
- tableProps: G
135
+ selectedRowKeys: v,
136
+ tableProps: H
137
137
  };
138
138
  }
139
- const $ = K((n) => ({
139
+ const w = K((n) => ({
140
140
  modals: {},
141
141
  toggleModal: (r, a) => n((t) => {
142
142
  const s = t.modals[r]?.visible || !1;
@@ -167,77 +167,86 @@ const $ = K((n) => ({
167
167
  })
168
168
  }));
169
169
  function ce(n) {
170
- const r = $((e) => e.modals), a = $((e) => e.toggleModal), t = $((e) => e.setModal), o = $((e) => e.clearModals), s = W(), g = I([]), i = Object.keys(n);
171
- D(() => (g.current = i.map(
170
+ const r = w((e) => e.modals), a = w((e) => e.toggleModal), t = w((e) => e.setModal), o = w((e) => e.clearModals), s = W(), m = I([]), l = Object.keys(n);
171
+ k(() => (m.current = l.map(
172
172
  (e) => `${s}-${e}`
173
173
  ), () => {
174
- o(g.current);
174
+ o(m.current);
175
175
  }), []);
176
176
  const f = {};
177
- return i.forEach((e) => {
178
- const c = `${s}-${e}`, u = r[c] ?? { visible: !1, data: {} }, d = n[e], E = typeof d.title == "function" ? d.title(u.data) : d.title;
177
+ return l.forEach((e) => {
178
+ const d = `${s}-${e}`, u = r[d] ?? { visible: !1, data: {} }, i = n[e], M = typeof i.title == "function" ? i.title(u.data) : i.title;
179
179
  f[`${e}Modal`] = {
180
180
  visible: u.visible,
181
181
  data: u.data,
182
- props: {
183
- width: d.width,
184
- title: E,
182
+ modalProps: {
183
+ width: i.width,
184
+ title: M,
185
+ open: u.visible,
186
+ maskClosable: i.maskClosable ?? !1,
187
+ centered: i.centered ?? !0,
188
+ destroyOnHidden: i.destroyOnHidden ?? !0,
189
+ onCancel: i.onCancel ?? (() => t(d, !1))
190
+ },
191
+ drawerProps: {
192
+ size: i.width,
193
+ title: M,
185
194
  open: u.visible,
186
- maskClosable: d.maskClosable ?? !1,
187
- centered: d.centered ?? !0,
188
- destroyOnHidden: d.destroyOnHidden ?? !0,
189
- onCancel: d.onCancel ?? (() => t(c, !1))
195
+ maskClosable: i.maskClosable ?? !0,
196
+ destroyOnHidden: i.destroyOnHidden ?? !0,
197
+ placement: i.placement ?? "right",
198
+ onClose: i.onClose ?? (() => t(d, !1))
190
199
  },
191
- toggle: (m) => a(c, m),
192
- open: (m) => t(c, !0, m),
193
- close: () => t(c, !1)
200
+ toggle: (g) => a(d, g),
201
+ open: (g) => t(d, !0, g),
202
+ close: () => t(d, !1)
194
203
  };
195
- }), f.toggle = (e, c) => {
196
- a(`${s}-${e}`, c);
197
- }, f.open = (e, c) => {
198
- t(`${s}-${e}`, !0, c);
204
+ }), f.toggle = (e, d) => {
205
+ a(`${s}-${e}`, d);
206
+ }, f.open = (e, d) => {
207
+ t(`${s}-${e}`, !0, d);
199
208
  }, f.close = (e) => {
200
209
  t(`${s}-${e}`, !1);
201
210
  }, f;
202
211
  }
203
212
  const ae = (n, r = "value", a = "label") => new Map(n.map((t) => [t[r], t[a]]));
204
- function ue(n, r) {
205
- const [a, t] = y({
213
+ function de(n, r) {
214
+ const [a, t] = b({
206
215
  options: [],
207
216
  mapData: /* @__PURE__ */ new Map()
208
- }), [o, s] = y(!0), { params: g, selectKey: i, fieldNames: f } = r, e = async () => {
217
+ }), [o, s] = b(!0), { params: m, selectKey: l, fieldNames: f } = r, e = async () => {
209
218
  s(!0);
210
- const { data: E } = await n(g), m = E || [];
219
+ const { data: M } = await n(m), g = M || [];
211
220
  if (f) {
212
- const { label: M, value: x } = f, h = m.map((p) => ({
221
+ const { label: v, value: C } = f, h = g.map((p) => ({
213
222
  data: p,
214
- label: p[M],
215
- value: p[x]
216
- })), R = ae(h);
217
- t((p) => ({ ...p, options: h, mapData: R }));
223
+ label: p[v],
224
+ value: p[C]
225
+ })), x = ae(h);
226
+ t((p) => ({ ...p, options: h, mapData: x }));
218
227
  } else
219
- t((M) => ({ ...M, options: m }));
228
+ t((v) => ({ ...v, options: g }));
220
229
  s(!1);
221
- }, c = S(() => {
230
+ }, d = S(() => {
222
231
  e();
223
232
  }, [e]);
224
- D(() => {
225
- c();
233
+ k(() => {
234
+ d();
226
235
  }, []);
227
- const { options: u, mapData: d } = a;
236
+ const { options: u, mapData: i } = a;
228
237
  return {
229
238
  loading: o,
230
- refresh: c,
231
- [`${i}Options`]: u,
232
- [`${i}Map`]: d
239
+ refresh: d,
240
+ [`${l}Options`]: u,
241
+ [`${l}Map`]: i
233
242
  };
234
243
  }
235
- function de(n, r) {
236
- const [a, t] = y(!1), { message: o } = X.useApp(), s = S(async (g) => {
244
+ function ue(n, r) {
245
+ const [a, t] = b(!1), { message: o } = X.useApp(), s = S(async (m) => {
237
246
  try {
238
247
  t(!0);
239
- const i = await n(g), { status: f, info: e } = i;
240
- f == "success" && (r(i), o.success(e));
248
+ const l = await n(m), { status: f, info: e } = l;
249
+ f == "success" && (r(l), o.success(e));
241
250
  } catch {
242
251
  }
243
252
  t(!1);
@@ -250,7 +259,7 @@ function de(n, r) {
250
259
  export {
251
260
  ie as configureTableOption,
252
261
  ce as useCreateModal,
253
- de as useFormSubmit,
254
- ue as useSelectOptions,
262
+ ue as useFormSubmit,
263
+ de as useSelectOptions,
255
264
  le as useTableList
256
265
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@base-stone/hooks",
3
3
  "license": "MIT",
4
- "version": "0.9.1",
4
+ "version": "0.9.3",
5
5
  "author": {
6
6
  "name": "leafront",
7
7
  "email": "leafront@126.com"