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