@base-stone/hooks 0.8.0 → 0.8.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.
package/README.md CHANGED
@@ -1,11 +1,52 @@
1
1
  # design-hooks
2
2
 
3
3
 
4
- ## 安装
4
+ ### 安装
5
5
 
6
6
  ```
7
7
 
8
- pnpm add @base-stone/design-hooks
8
+ pnpm add @base-stone/hooks
9
9
 
10
10
  ```
11
11
 
12
+
13
+ ### useTableList 使用
14
+
15
+
16
+ ```
17
+
18
+ const { tableProps, reload } = useTableList<ListItemData>(getCooperateList, {
19
+ orderField: 'createDate',
20
+ orderType: 'DESC',
21
+ taskStatuses: taskStatusesArr,
22
+ scope: scopeType
23
+ })
24
+
25
+ <Table rowKey="id" scroll={{ x: 'max-content' }} columns={columns} {...tableProps} />
26
+
27
+ ```
28
+
29
+ ### useCreateModal 使用
30
+
31
+
32
+ ```
33
+
34
+ const { editModal, infoModal, memberModal, toggle } = useCreateModal(['edit', 'member', 'info'])
35
+
36
+ const onSetModalData = (type: string, data?: any) => {
37
+ toggle(type, data)
38
+ }
39
+
40
+ ```
41
+
42
+
43
+ ### useSelectOptions 使用
44
+
45
+
46
+ ```
47
+ const { sceneOptions, sceneMap } = useSelectOptions<string>(getRecruitSceneList, {
48
+ selectKey: 'scene',
49
+ fieldNames: { label: 'recruitTypeName', value: 'recruitEncrypt' }
50
+ })
51
+
52
+ ```
@@ -22,9 +22,26 @@ declare interface GlobalTableConfig {
22
22
 
23
23
  declare type MapData<T extends string | number = string | number> = Map<T, string | number | undefined>;
24
24
 
25
+ declare interface ModalConfig {
26
+ width: number;
27
+ title: string;
28
+ maskClosable?: boolean;
29
+ centered?: boolean;
30
+ destroyOnHidden?: boolean;
31
+ }
32
+
25
33
  declare type ModalInstance<T = any> = {
26
34
  visible: boolean;
27
35
  data: T;
36
+ props: {
37
+ width: number;
38
+ title: string;
39
+ open: boolean;
40
+ maskClosable: boolean;
41
+ centered: boolean;
42
+ destroyOnHidden: boolean;
43
+ onCancel: () => void;
44
+ };
28
45
  toggle: (data?: T) => void;
29
46
  open: (data?: T) => void;
30
47
  close: () => void;
@@ -45,14 +62,14 @@ declare interface RequestFn {
45
62
  }>;
46
63
  }
47
64
 
48
- declare interface SelectConfig<K> {
65
+ declare type SelectConfig<K extends string> = Readonly<{
49
66
  params?: Record<string, any>;
50
67
  selectKey: K;
51
68
  fieldNames?: {
52
69
  label: string;
53
70
  value: string;
54
71
  };
55
- }
72
+ }>;
56
73
 
57
74
  declare type SelectOption<T extends string | number = string | number> = {
58
75
  label: string;
@@ -66,7 +83,7 @@ declare type SelectOptionsResult<K extends string, T extends string | number> =
66
83
  } & {
67
84
  [P in `${K}Options`]: (SelectOption<T> & Record<string, any>)[];
68
85
  } & {
69
- [P in `${K}Map`]: MapData<T>;
86
+ [P in `${K}Map`]?: MapData<T>;
70
87
  }>;
71
88
 
72
89
  declare interface SuccessFn {
@@ -108,15 +125,12 @@ declare interface TableResponse<T> {
108
125
  };
109
126
  }
110
127
 
111
- /**
112
- * 批量创建多个模态框 hook
113
- * @param suffixes 模态框后缀数组
114
- * @returns 包含所有模态框实例的对象,以及统一的 toggle/open/close 函数
115
- */
116
- export declare function useCreateModal<const T extends readonly string[] = readonly string[]>(suffixes: T): Record<`${T[number]}Modal`, ModalInstance> & {
117
- toggle: (type: string, data?: any) => void;
118
- open: (type: string, data?: any) => void;
119
- close: (type: string) => void;
128
+ export declare function useCreateModal<const T extends Record<string, ModalConfig>>(configs: T): {
129
+ [K in keyof T as `${string & K}Modal`]: ModalInstance;
130
+ } & {
131
+ open: (type: keyof T, data?: any) => void;
132
+ close: (type: keyof T) => void;
133
+ toggle: (type: keyof T, data?: any) => void;
120
134
  };
121
135
 
122
136
  export declare function useFormSubmit(requestFn: RequestFn, successFn: SuccessFn): FormSubmitResult;
@@ -1,239 +1,250 @@
1
- import { useState as M, useRef as J, useMemo as j, useCallback as m, useEffect as L, useId as W } from "react";
2
- import { Empty as q, App as X } from "antd";
1
+ import { useState as E, 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";
3
3
  import { create as K } from "zustand";
4
- var P = { exports: {} }, x = {};
5
- var D;
4
+ var P = { exports: {} }, y = {};
5
+ var j;
6
6
  function ee() {
7
- if (D) return x;
8
- D = 1;
9
- var i = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
10
- function r(e, s, n) {
11
- var d = null;
12
- if (n !== void 0 && (d = "" + n), s.key !== void 0 && (d = "" + s.key), "key" in s) {
13
- n = {};
14
- for (var l in s)
15
- l !== "key" && (n[l] = s[l]);
16
- } else n = s;
17
- return s = n.ref, {
18
- $$typeof: i,
19
- type: e,
20
- key: d,
21
- ref: s !== void 0 ? s : null,
22
- props: n
7
+ if (j) return y;
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 f = null;
12
+ if (s !== void 0 && (f = "" + s), o.key !== void 0 && (f = "" + o.key), "key" in o) {
13
+ s = {};
14
+ for (var i in o)
15
+ i !== "key" && (s[i] = o[i]);
16
+ } else s = o;
17
+ return o = s.ref, {
18
+ $$typeof: n,
19
+ type: t,
20
+ key: f,
21
+ ref: o !== void 0 ? o : null,
22
+ props: s
23
23
  };
24
24
  }
25
- return x.Fragment = a, x.jsx = r, x.jsxs = r, x;
25
+ return y.Fragment = r, y.jsx = a, y.jsxs = a, y;
26
26
  }
27
- var I;
27
+ var q;
28
28
  function te() {
29
- return I || (I = 1, P.exports = ee()), P.exports;
29
+ return q || (q = 1, P.exports = ee()), P.exports;
30
30
  }
31
31
  var oe = te();
32
- const b = {
32
+ const w = {
33
33
  sortField: ["orderType", "orderField"],
34
34
  sortOrder: ["ASC", "DESC"],
35
35
  pageSize: 10
36
36
  };
37
- function ie(i) {
38
- Object.keys(i).forEach((a) => {
39
- b[a] = i[a];
37
+ function ie(n) {
38
+ Object.keys(n).forEach((r) => {
39
+ w[r] = n[r];
40
40
  });
41
41
  }
42
- function le(i, a = {}) {
43
- const { rowSelection: r, ...e } = a, s = b.pageSize, [n, d] = M({
42
+ function le(n, r = {}) {
43
+ const { rowSelection: a, ...t } = r, o = w.pageSize, [s, f] = E({
44
44
  pagination: {
45
45
  showSizeChanger: !0,
46
46
  showQuickJumper: !0,
47
47
  total: 0,
48
- pageSize: s,
48
+ pageSize: o,
49
49
  current: 1
50
50
  },
51
51
  list: [],
52
52
  queryParams: {
53
53
  pageNo: 1,
54
- pageSize: s,
55
- ...e
54
+ pageSize: o,
55
+ ...t
56
56
  }
57
- }), { pagination: l, list: o, queryParams: t } = n, { pageNo: p, pageSize: u } = t, [f, R] = M(!0), $ = J(t), [y, h] = M([]), E = j(() => {
58
- if (r)
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(() => {
58
+ if (a)
59
59
  return {
60
- selectedRowKeys: y,
61
- onChange: (c) => h(c)
60
+ selectedRowKeys: M,
61
+ onChange: (l) => x(l)
62
62
  };
63
- }, [r, y]), v = m(
64
- (c) => `共 ${c} 条记录 第 ${p}/${Math.ceil(c / u)} 页 `,
65
- [p, u]
66
- ), g = m(
67
- async (c) => {
68
- const { pageNo: _ } = c;
69
- R(!0);
70
- const S = { ...e, pageSize: u, ...c };
71
- c.pageNo === void 0 && (S.pageNo = 1), c.pageSize === void 0 && (S.pageSize = u);
72
- const { data: z } = await i(S), { list: k = [], totalCount: w = 0 } = z || {};
73
- r && h([]), d({
74
- list: k,
75
- queryParams: S,
63
+ }, [a, M]), R = S(
64
+ (l) => `共 ${l} 条记录 第 ${c}/${Math.ceil(l / p)} 页 `,
65
+ [c, p]
66
+ ), u = S(
67
+ async (l) => {
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);
72
+ const { data: C } = await n(v), { list: T = [], totalCount: z = 0 } = C || {};
73
+ a && x([]), f({
74
+ list: T,
75
+ queryParams: v,
76
76
  pagination: {
77
- ...l,
78
- current: _,
79
- pageSize: S.pageSize,
80
- total: w
77
+ ...i,
78
+ current: k,
79
+ pageSize: v.pageSize,
80
+ total: z
81
81
  }
82
- }), R(!1);
82
+ }), m(!1);
83
83
  },
84
- [t, e, r, u, i, l]
85
- ), C = m(
86
- (c) => {
87
- g({ ...t, ...c, pageNo: 1 });
84
+ [e, t, a, p, n, i]
85
+ ), N = S(
86
+ (l) => {
87
+ u({ ...e, ...l, pageNo: 1 });
88
88
  },
89
- [g, t]
90
- ), O = m(
91
- (c) => {
92
- g({ ...t, ...c });
89
+ [u, e]
90
+ ), J = S(
91
+ (l) => {
92
+ u({ ...e, ...l });
93
93
  },
94
- [g, t]
95
- ), F = m(
96
- (c) => {
97
- g({ ...c, pageSize: u, pageNo: 1 });
94
+ [u, e]
95
+ ), F = S(
96
+ (l) => {
97
+ u({ ...l, pageSize: p, pageNo: 1 });
98
98
  },
99
- [g, u]
100
- ), N = m(
101
- (c, _, S, z) => {
102
- const { action: k } = z;
103
- if (["paginate", "sort"].includes(k)) {
104
- const { current: w, pageSize: V } = c, { field: Q, order: A } = S, [Y, Z] = b.sortField, [B, H] = b.sortOrder, U = {
105
- ...t,
106
- [Y]: A ? A === "ascend" ? B : H : void 0,
107
- [Z]: Q,
108
- pageNo: w,
99
+ [u, p]
100
+ ), _ = S(
101
+ (l, k, v, C) => {
102
+ const { action: T } = C;
103
+ if (["paginate", "sort"].includes(T)) {
104
+ const { current: z, pageSize: V } = l, { field: H, order: A } = v, [Q, Y] = w.sortField, [Z, B] = w.sortOrder, U = {
105
+ ...e,
106
+ [Q]: A ? A === "ascend" ? Z : B : void 0,
107
+ [Y]: H,
108
+ pageNo: z,
109
109
  pageSize: V
110
110
  };
111
- g(U);
111
+ u(U);
112
112
  }
113
113
  },
114
- [t, g]
115
- ), G = j(() => ({
114
+ [e, u]
115
+ ), G = L(() => ({
116
116
  bordered: !0,
117
117
  size: "middle",
118
118
  sticky: !0,
119
- rowSelection: E,
120
- pagination: { ...l, showTotal: v },
121
- loading: f,
122
- dataSource: o,
123
- onChange: N,
119
+ rowSelection: h,
120
+ pagination: { ...i, showTotal: R },
121
+ loading: g,
122
+ dataSource: d,
123
+ onChange: _,
124
124
  locale: {
125
- emptyText: f ? "" : /* @__PURE__ */ oe.jsx(q, { image: q.PRESENTED_IMAGE_SIMPLE })
125
+ emptyText: g ? "" : /* @__PURE__ */ oe.jsx(O, { image: O.PRESENTED_IMAGE_SIMPLE })
126
126
  }
127
- }), [E, l, v, f, o, N]);
128
- return L(() => {
129
- C($.current);
127
+ }), [h, i, R, g, d, _]);
128
+ return D(() => {
129
+ N(b.current);
130
130
  }, []), {
131
- queryParams: t,
132
- reload: C,
133
- refresh: O,
131
+ queryParams: e,
132
+ reload: N,
133
+ refresh: J,
134
134
  reset: F,
135
- selectedRowKeys: y,
135
+ selectedRowKeys: M,
136
136
  tableProps: G
137
137
  };
138
138
  }
139
- const T = K((i) => ({
139
+ const $ = K((n) => ({
140
140
  modals: {},
141
- toggleModal: (a, r) => i((e) => {
142
- const n = e.modals[a]?.visible || !1;
141
+ toggleModal: (r, a) => n((t) => {
142
+ const s = t.modals[r]?.visible || !1;
143
143
  return {
144
144
  modals: {
145
- ...e.modals,
146
- [a]: {
147
- visible: !n,
148
- data: n ? {} : r || {}
145
+ ...t.modals,
146
+ [r]: {
147
+ visible: !s,
148
+ data: s ? {} : a || {}
149
149
  }
150
150
  }
151
151
  };
152
152
  }),
153
- setModal: (a, r, e) => i((s) => ({
153
+ setModal: (r, a, t) => n((o) => ({
154
154
  modals: {
155
- ...s.modals,
156
- [a]: {
157
- visible: r,
158
- data: r ? e || {} : {}
155
+ ...o.modals,
156
+ [r]: {
157
+ visible: a,
158
+ data: a ? t || {} : {}
159
159
  }
160
160
  }
161
161
  })),
162
- clearModals: (a) => i((r) => {
163
- const e = { ...r.modals };
164
- return a.forEach((s) => {
165
- delete e[s];
166
- }), { modals: e };
162
+ clearModals: (r) => n((a) => {
163
+ const t = { ...a.modals };
164
+ return r.forEach((o) => {
165
+ delete t[o];
166
+ }), { modals: t };
167
167
  })
168
168
  }));
169
- function ce(i) {
170
- const a = T((o) => o.modals), r = T((o) => o.toggleModal), e = T((o) => o.setModal), s = T((o) => o.clearModals), n = W(), d = J(i.map((o) => `${n}-${o}`));
171
- L(() => () => {
172
- s(d.current);
173
- }, []);
174
- const l = {};
175
- for (const o of i) {
176
- const t = `${n}-${o}`, u = a[t] ?? { visible: !1, data: {} };
177
- l[`${o}Modal`] = {
178
- visible: u.visible,
179
- data: u.data,
180
- toggle: (f) => r(t, f),
181
- open: (f) => e(t, !0, f),
182
- close: () => e(t, !1)
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(
172
+ (e) => `${s}-${e}`
173
+ ), () => {
174
+ o(f.current);
175
+ }), []);
176
+ const d = {};
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,
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: t(c, !1)
190
+ },
191
+ toggle: (m) => a(c, m),
192
+ open: (m) => t(c, !0, m),
193
+ close: () => t(c, !1)
183
194
  };
184
- }
185
- return l.toggle = (o, t) => {
186
- const p = `${n}-${o}`;
187
- r(p, t);
188
- }, l.open = (o, t) => {
189
- const p = `${n}-${o}`;
190
- e(p, !0, t);
191
- }, l.close = (o) => {
192
- const t = `${n}-${o}`;
193
- e(t, !1);
194
- }, l;
195
+ }), d.toggle = (e, c) => {
196
+ a(`${s}-${e}`, c);
197
+ }, d.open = (e, c) => {
198
+ t(`${s}-${e}`, !0, c);
199
+ }, d.close = (e) => {
200
+ t(`${s}-${e}`, !1);
201
+ }, d;
195
202
  }
196
- const se = (i, a = "value", r = "label") => new Map(i.map((e) => [e[a], e[r]]));
197
- function ue(i, a) {
198
- const [r, e] = M([]), [s, n] = M(/* @__PURE__ */ new Map()), [d, l] = M(!0), { params: o, fieldNames: t } = a, p = a.selectKey, u = async () => {
199
- l(!0);
200
- const { data: R } = await i(o), $ = R || [];
201
- if (t) {
202
- const { label: y, value: h } = t, E = $.map((v) => ({
203
- data: v,
204
- label: v[y],
205
- value: v[h]
206
- }));
207
- e(E), n(se(E));
203
+ 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] = E({
206
+ options: [],
207
+ mapData: /* @__PURE__ */ new Map()
208
+ }), [o, s] = E(!0), { params: f, selectKey: i, fieldNames: d } = r, e = async () => {
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]
216
+ })), R = ae(h);
217
+ t((u) => ({ ...u, options: h, mapData: R }));
208
218
  } else
209
- e($);
210
- l(!1);
211
- }, f = m(() => {
212
- u();
213
- }, [u]);
214
- return L(() => {
215
- f();
216
- }, []), {
217
- loading: d,
218
- refresh: f,
219
- [`${p}Options`]: r,
220
- [`${p}Map`]: s
219
+ t((M) => ({ ...M, options: b }));
220
+ s(!1);
221
+ }, c = S(() => {
222
+ e();
223
+ }, [e]);
224
+ D(() => {
225
+ c();
226
+ }, []);
227
+ const { options: p, mapData: g } = a;
228
+ return {
229
+ loading: o,
230
+ refresh: c,
231
+ [`${i}Options`]: p,
232
+ [`${i}Map`]: g
221
233
  };
222
234
  }
223
- function de(i, a) {
224
- const [r, e] = M(!1), { message: s } = X.useApp(), n = m(async (d) => {
235
+ function de(n, r) {
236
+ const [a, t] = E(!1), { message: o } = X.useApp(), s = S(async (f) => {
225
237
  try {
226
- const l = await i(d);
227
- e(!0);
228
- const { status: o, info: t } = l;
229
- o == "success" && (a(l), s.success(t));
238
+ t(!0);
239
+ const i = await n(f), { status: d, info: e } = i;
240
+ d == "success" && (r(i), o.success(e));
230
241
  } catch {
231
242
  }
232
- e(!1);
233
- }, [i, a, s]);
243
+ t(!1);
244
+ }, [n, r, o]);
234
245
  return {
235
- loading: r,
236
- submit: n
246
+ loading: a,
247
+ submit: s
237
248
  };
238
249
  }
239
250
  export {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@base-stone/hooks",
3
3
  "license": "MIT",
4
- "version": "0.8.0",
4
+ "version": "0.8.5",
5
5
  "author": {
6
- "name": "yeliang",
6
+ "name": "leafront",
7
7
  "email": "leafront@126.com"
8
8
  },
9
9
  "publishConfig": {
@@ -1 +0,0 @@
1
- (function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("antd"),require("zustand")):typeof define=="function"&&define.amd?define(["exports","react","antd","zustand"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d.DesignReact={},d.React,d.antd,d.zustand))})(this,(function(d,e,z,O){"use strict";var $={exports:{}},b={};var L;function D(){if(L)return b;L=1;var l=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function r(t,a,i){var f=null;if(i!==void 0&&(f=""+i),a.key!==void 0&&(f=""+a.key),"key"in a){i={};for(var u in a)u!=="key"&&(i[u]=a[u])}else i=a;return a=i.ref,{$$typeof:l,type:t,key:f,ref:a!==void 0?a:null,props:i}}return b.Fragment=n,b.jsx=r,b.jsxs=r,b}var N;function F(){return N||(N=1,$.exports=D()),$.exports}var I=F();const k={sortField:["orderType","orderField"],sortOrder:["ASC","DESC"],pageSize:10};function J(l){Object.keys(l).forEach(n=>{k[n]=l[n]})}function G(l,n={}){const{rowSelection:r,...t}=n,a=k.pageSize,[i,f]=e.useState({pagination:{showSizeChanger:!0,showQuickJumper:!0,total:0,pageSize:a,current:1},list:[],queryParams:{pageNo:1,pageSize:a,...t}}),{pagination:u,list:o,queryParams:s}=i,{pageNo:g,pageSize:p}=s,[S,T]=e.useState(!0),h=e.useRef(s),[E,C]=e.useState([]),v=e.useMemo(()=>{if(r)return{selectedRowKeys:E,onChange:c=>C(c)}},[r,E]),y=e.useCallback(c=>`共 ${c} 条记录 第 ${g}/${Math.ceil(c/p)} 页 `,[g,p]),m=e.useCallback(async c=>{const{pageNo:q}=c;T(!0);const M={...t,pageSize:p,...c};c.pageNo===void 0&&(M.pageNo=1),c.pageSize===void 0&&(M.pageSize=p);const{data:x}=await l(M),{list:P=[],totalCount:w=0}=x||{};r&&C([]),f({list:P,queryParams:M,pagination:{...u,current:q,pageSize:M.pageSize,total:w}}),T(!1)},[s,t,r,p,l,u]),_=e.useCallback(c=>{m({...s,...c,pageNo:1})},[m,s]),B=e.useCallback(c=>{m({...s,...c})},[m,s]),H=e.useCallback(c=>{m({...c,pageSize:p,pageNo:1})},[m,p]),j=e.useCallback((c,q,M,x)=>{const{action:P}=x;if(["paginate","sort"].includes(P)){const{current:w,pageSize:W}=c,{field:X,order:A}=M,[K,ee]=k.sortField,[te,se]=k.sortOrder,oe={...s,[K]:A?A==="ascend"?te:se:void 0,[ee]:X,pageNo:w,pageSize:W};m(oe)}},[s,m]),U=e.useMemo(()=>({bordered:!0,size:"middle",sticky:!0,rowSelection:v,pagination:{...u,showTotal:y},loading:S,dataSource:o,onChange:j,locale:{emptyText:S?"":I.jsx(z.Empty,{image:z.Empty.PRESENTED_IMAGE_SIMPLE})}}),[v,u,y,S,o,j]);return e.useEffect(()=>{_(h.current)},[]),{queryParams:s,reload:_,refresh:B,reset:H,selectedRowKeys:E,tableProps:U}}const R=O.create(l=>({modals:{},toggleModal:(n,r)=>l(t=>{const i=t.modals[n]?.visible||!1;return{modals:{...t.modals,[n]:{visible:!i,data:i?{}:r||{}}}}}),setModal:(n,r,t)=>l(a=>({modals:{...a.modals,[n]:{visible:r,data:r?t||{}:{}}}})),clearModals:n=>l(r=>{const t={...r.modals};return n.forEach(a=>{delete t[a]}),{modals:t}})}));function V(l){const n=R(o=>o.modals),r=R(o=>o.toggleModal),t=R(o=>o.setModal),a=R(o=>o.clearModals),i=e.useId(),f=e.useRef(l.map(o=>`${i}-${o}`));e.useEffect(()=>()=>{a(f.current)},[]);const u={};for(const o of l){const s=`${i}-${o}`,p=n[s]??{visible:!1,data:{}};u[`${o}Modal`]={visible:p.visible,data:p.data,toggle:S=>r(s,S),open:S=>t(s,!0,S),close:()=>t(s,!1)}}return u.toggle=(o,s)=>{const g=`${i}-${o}`;r(g,s)},u.open=(o,s)=>{const g=`${i}-${o}`;t(g,!0,s)},u.close=o=>{const s=`${i}-${o}`;t(s,!1)},u}const Q=(l,n="value",r="label")=>new Map(l.map(t=>[t[n],t[r]]));function Y(l,n){const[r,t]=e.useState([]),[a,i]=e.useState(new Map),[f,u]=e.useState(!0),{params:o,fieldNames:s}=n,g=n.selectKey,p=async()=>{u(!0);const{data:T}=await l(o),h=T||[];if(s){const{label:E,value:C}=s,v=h.map(y=>({data:y,label:y[E],value:y[C]}));t(v),i(Q(v))}else t(h);u(!1)},S=e.useCallback(()=>{p()},[p]);return e.useEffect(()=>{S()},[]),{loading:f,refresh:S,[`${g}Options`]:r,[`${g}Map`]:a}}function Z(l,n){const[r,t]=e.useState(!1),{message:a}=z.App.useApp(),i=e.useCallback(async f=>{try{const u=await l(f);t(!0);const{status:o,info:s}=u;o=="success"&&(n(u),a.success(s))}catch{}t(!1)},[l,n,a]);return{loading:r,submit:i}}d.configureTableOption=J,d.useCreateModal=V,d.useFormSubmit=Z,d.useSelectOptions=Y,d.useTableList=G,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));