@base-stone/hooks 0.8.7 → 0.8.8

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.
@@ -39,9 +39,9 @@ declare type ModalInstance<T = any> = {
39
39
  close: () => void;
40
40
  };
41
41
 
42
- export declare interface ModalProps {
42
+ export declare interface ModalProps<T = any> {
43
43
  width: number;
44
- title: string;
44
+ title: string | ((data: T) => string);
45
45
  maskClosable?: boolean;
46
46
  centered?: boolean;
47
47
  destroyOnHidden?: boolean;
@@ -1,15 +1,15 @@
1
- import { useState as E, useRef as I, useMemo as L, useCallback as S, useEffect as D, useId as W } from "react";
1
+ import { useState as y, useRef as I, useMemo as L, useCallback as S, useEffect as D, useId as W } from "react";
2
2
  import { Empty as O, App as X } from "antd";
3
3
  import { create as K } from "zustand";
4
- var P = { exports: {} }, y = {};
4
+ var P = { exports: {} }, b = {};
5
5
  var j;
6
6
  function ee() {
7
- if (j) return y;
7
+ if (j) return b;
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 f = null;
12
- if (s !== void 0 && (f = "" + s), o.key !== void 0 && (f = "" + o.key), "key" in o) {
11
+ var g = null;
12
+ if (s !== void 0 && (g = "" + s), o.key !== void 0 && (g = "" + o.key), "key" in o) {
13
13
  s = {};
14
14
  for (var i in o)
15
15
  i !== "key" && (s[i] = o[i]);
@@ -17,12 +17,12 @@ function ee() {
17
17
  return o = s.ref, {
18
18
  $$typeof: n,
19
19
  type: t,
20
- key: f,
20
+ key: g,
21
21
  ref: o !== void 0 ? o : null,
22
22
  props: s
23
23
  };
24
24
  }
25
- return y.Fragment = r, y.jsx = a, y.jsxs = a, y;
25
+ return b.Fragment = r, b.jsx = a, b.jsxs = a, b;
26
26
  }
27
27
  var q;
28
28
  function te() {
@@ -40,7 +40,7 @@ function ie(n) {
40
40
  });
41
41
  }
42
42
  function le(n, r = {}) {
43
- const { rowSelection: a, ...t } = r, o = C.pageSize, [s, f] = E({
43
+ const { rowSelection: a, ...t } = r, o = C.pageSize, [s, g] = y({
44
44
  pagination: {
45
45
  showSizeChanger: !0,
46
46
  showQuickJumper: !0,
@@ -54,23 +54,23 @@ function le(n, r = {}) {
54
54
  pageSize: o,
55
55
  ...t
56
56
  }
57
- }), { pagination: i, list: d, queryParams: e } = s, { pageNo: c, pageSize: p } = e, [g, m] = E(!0), b = I(e), [M, x] = E([]), h = L(() => {
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(() => {
58
58
  if (a)
59
59
  return {
60
60
  selectedRowKeys: M,
61
61
  onChange: (l) => x(l)
62
62
  };
63
63
  }, [a, M]), R = S(
64
- (l) => `共 ${l} 条记录 第 ${c}/${Math.ceil(l / p)} 页 `,
65
- [c, p]
66
- ), u = S(
64
+ (l) => `共 ${l} 条记录 第 ${c}/${Math.ceil(l / u)} 页 `,
65
+ [c, u]
66
+ ), p = S(
67
67
  async (l) => {
68
68
  const { pageNo: k } = l;
69
- m(!0);
70
- const v = { ...t, pageSize: p, ...l };
71
- l.pageNo === void 0 && (v.pageNo = 1), l.pageSize === void 0 && (v.pageSize = p);
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
72
  const { data: w } = await n(v), { list: T = [], totalCount: z = 0 } = w || {};
73
- a && x([]), f({
73
+ a && x([]), g({
74
74
  list: T,
75
75
  queryParams: v,
76
76
  pagination: {
@@ -79,24 +79,24 @@ function le(n, r = {}) {
79
79
  pageSize: v.pageSize,
80
80
  total: z
81
81
  }
82
- }), m(!1);
82
+ }), E(!1);
83
83
  },
84
- [e, t, a, p, n, i]
84
+ [e, t, a, u, n, i]
85
85
  ), N = S(
86
86
  (l) => {
87
- u({ ...e, ...l, pageNo: 1 });
87
+ p({ ...e, ...l, pageNo: 1 });
88
88
  },
89
- [u, e]
89
+ [p, e]
90
90
  ), J = S(
91
91
  (l) => {
92
- u({ ...e, ...l });
92
+ p({ ...e, ...l });
93
93
  },
94
- [u, e]
94
+ [p, e]
95
95
  ), F = S(
96
96
  (l) => {
97
- u({ ...l, pageSize: p, pageNo: 1 });
97
+ p({ ...l, pageSize: u, pageNo: 1 });
98
98
  },
99
- [u, p]
99
+ [p, u]
100
100
  ), _ = S(
101
101
  (l, k, v, w) => {
102
102
  const { action: T } = w;
@@ -108,25 +108,25 @@ function le(n, r = {}) {
108
108
  pageNo: z,
109
109
  pageSize: V
110
110
  };
111
- u(U);
111
+ p(U);
112
112
  }
113
113
  },
114
- [e, u]
114
+ [e, p]
115
115
  ), G = L(() => ({
116
116
  bordered: !0,
117
117
  size: "middle",
118
118
  sticky: !0,
119
119
  rowSelection: h,
120
120
  pagination: { ...i, showTotal: R },
121
- loading: g,
122
- dataSource: d,
121
+ loading: d,
122
+ dataSource: f,
123
123
  onChange: _,
124
124
  locale: {
125
- emptyText: g ? "" : /* @__PURE__ */ oe.jsx(O, { image: O.PRESENTED_IMAGE_SIMPLE })
125
+ emptyText: d ? "" : /* @__PURE__ */ oe.jsx(O, { image: O.PRESENTED_IMAGE_SIMPLE })
126
126
  }
127
- }), [h, i, R, g, d, _]);
127
+ }), [h, i, R, d, f, _]);
128
128
  return D(() => {
129
- N(b.current);
129
+ N(m.current);
130
130
  }, []), {
131
131
  queryParams: e,
132
132
  reload: N,
@@ -167,56 +167,56 @@ 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(), f = I([]), i = Object.keys(n);
171
- D(() => (f.current = i.map(
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(
172
172
  (e) => `${s}-${e}`
173
173
  ), () => {
174
- o(f.current);
174
+ o(g.current);
175
175
  }), []);
176
- const d = {};
176
+ const f = {};
177
177
  return i.forEach((e) => {
178
- const c = `${s}-${e}`, p = r[c] ?? { visible: !1, data: {} }, g = n[e];
179
- d[`${e}Modal`] = {
180
- visible: p.visible,
181
- data: p.data,
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;
179
+ f[`${e}Modal`] = {
180
+ visible: u.visible,
181
+ data: u.data,
182
182
  props: {
183
- width: g.width,
184
- title: g.title,
185
- open: p.visible,
186
- maskClosable: g.maskClosable ?? !1,
187
- centered: g.centered ?? !0,
188
- destroyOnHidden: g.destroyOnHidden ?? !0,
189
- onCancel: g.onCancel ?? t(c, !1)
183
+ width: d.width,
184
+ title: E,
185
+ 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))
190
190
  },
191
191
  toggle: (m) => a(c, m),
192
192
  open: (m) => t(c, !0, m),
193
193
  close: () => t(c, !1)
194
194
  };
195
- }), d.toggle = (e, c) => {
195
+ }), f.toggle = (e, c) => {
196
196
  a(`${s}-${e}`, c);
197
- }, d.open = (e, c) => {
197
+ }, f.open = (e, c) => {
198
198
  t(`${s}-${e}`, !0, c);
199
- }, d.close = (e) => {
199
+ }, f.close = (e) => {
200
200
  t(`${s}-${e}`, !1);
201
- }, d;
201
+ }, f;
202
202
  }
203
203
  const ae = (n, r = "value", a = "label") => new Map(n.map((t) => [t[r], t[a]]));
204
204
  function ue(n, r) {
205
- const [a, t] = E({
205
+ const [a, t] = y({
206
206
  options: [],
207
207
  mapData: /* @__PURE__ */ new Map()
208
- }), [o, s] = E(!0), { params: f, selectKey: i, fieldNames: d } = r, e = async () => {
208
+ }), [o, s] = y(!0), { params: g, selectKey: i, fieldNames: f } = r, e = async () => {
209
209
  s(!0);
210
- const { data: m } = await n(f), b = m || [];
211
- if (d) {
212
- const { label: M, value: x } = d, h = b.map((u) => ({
213
- data: u,
214
- label: u[M],
215
- value: u[x]
210
+ const { data: E } = await n(g), m = E || [];
211
+ if (f) {
212
+ const { label: M, value: x } = f, h = m.map((p) => ({
213
+ data: p,
214
+ label: p[M],
215
+ value: p[x]
216
216
  })), R = ae(h);
217
- t((u) => ({ ...u, options: h, mapData: R }));
217
+ t((p) => ({ ...p, options: h, mapData: R }));
218
218
  } else
219
- t((M) => ({ ...M, options: b }));
219
+ t((M) => ({ ...M, options: m }));
220
220
  s(!1);
221
221
  }, c = S(() => {
222
222
  e();
@@ -224,20 +224,20 @@ function ue(n, r) {
224
224
  D(() => {
225
225
  c();
226
226
  }, []);
227
- const { options: p, mapData: g } = a;
227
+ const { options: u, mapData: d } = a;
228
228
  return {
229
229
  loading: o,
230
230
  refresh: c,
231
- [`${i}Options`]: p,
232
- [`${i}Map`]: g
231
+ [`${i}Options`]: u,
232
+ [`${i}Map`]: d
233
233
  };
234
234
  }
235
235
  function de(n, r) {
236
- const [a, t] = E(!1), { message: o } = X.useApp(), s = S(async (f) => {
236
+ const [a, t] = y(!1), { message: o } = X.useApp(), s = S(async (g) => {
237
237
  try {
238
238
  t(!0);
239
- const i = await n(f), { status: d, info: e } = i;
240
- d == "success" && (r(i), o.success(e));
239
+ const i = await n(g), { status: f, info: e } = i;
240
+ f == "success" && (r(i), o.success(e));
241
241
  } catch {
242
242
  }
243
243
  t(!1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@base-stone/hooks",
3
3
  "license": "MIT",
4
- "version": "0.8.7",
4
+ "version": "0.8.8",
5
5
  "author": {
6
6
  "name": "leafront",
7
7
  "email": "leafront@126.com"