@faasjs/ant-design 0.0.3-beta.1 → 0.0.3-beta.100

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/dist/index.js CHANGED
@@ -1,64 +1,116 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
25
2
 
26
- // src/index.ts
27
- var src_exports = {};
28
- __export(src_exports, {
29
- Blank: () => Blank,
30
- ConfigContext: () => ConfigContext,
31
- ConfigProvider: () => ConfigProvider,
32
- Description: () => Description,
33
- Drawer: () => import_antd4.Drawer,
34
- Form: () => Form,
35
- FormItem: () => FormItem,
36
- Link: () => Link,
37
- Modal: () => import_antd8.Modal,
38
- PageNotFound: () => PageNotFound,
39
- Routes: () => Routes,
40
- Table: () => Table,
41
- Title: () => Title,
42
- transferOptions: () => transferOptions,
43
- transferValue: () => transferValue,
44
- useConfigContext: () => useConfigContext,
45
- useDrawer: () => useDrawer,
46
- useModal: () => useModal
47
- });
48
- module.exports = __toCommonJS(src_exports);
3
+ var react = require('@faasjs/react');
4
+ var antd = require('antd');
5
+ var cssinjs = require('@ant-design/cssinjs');
6
+ var react$1 = require('react');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+ var reactRouterDom = require('react-router-dom');
9
+ var lodashEs = require('lodash-es');
10
+ var dayjs2 = require('dayjs');
11
+ var icons = require('@ant-design/icons');
49
12
 
50
- // react-shim.js
51
- var import_react = __toESM(require("react"));
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
52
14
 
53
- // src/Blank.tsx
54
- var import_antd2 = require("antd");
55
- var import_lodash2 = require("lodash");
15
+ var dayjs2__default = /*#__PURE__*/_interopDefault(dayjs2);
56
16
 
57
- // src/Config.tsx
58
- var import_react2 = require("react");
59
- var import_antd = require("antd");
60
- var import_lodash = require("lodash");
61
- var import_jsx_runtime = require("react/jsx-runtime");
17
+ // src/index.ts
18
+ function useModal(init) {
19
+ const [props, setProps] = react$1.useState({
20
+ open: false,
21
+ onCancel: () => setProps((prev) => ({
22
+ ...prev,
23
+ open: false
24
+ })),
25
+ ...init
26
+ });
27
+ return {
28
+ modal: /* @__PURE__ */ jsxRuntime.jsx(antd.Modal, { ...props }),
29
+ modalProps: props,
30
+ setModalProps(changes) {
31
+ setProps((prev) => ({
32
+ ...prev,
33
+ ...changes
34
+ }));
35
+ }
36
+ };
37
+ }
38
+ function useDrawer(init) {
39
+ const [props, setProps] = react$1.useState({
40
+ open: false,
41
+ onClose: () => setProps((prev) => ({
42
+ ...prev,
43
+ open: false
44
+ })),
45
+ ...init
46
+ });
47
+ return {
48
+ drawer: /* @__PURE__ */ jsxRuntime.jsx(antd.Drawer, { ...props }),
49
+ drawerProps: props,
50
+ setDrawerProps(changes) {
51
+ setProps((prev) => ({
52
+ ...prev,
53
+ ...changes
54
+ }));
55
+ }
56
+ };
57
+ }
58
+ var AppContext = react$1.createContext({
59
+ message: {},
60
+ notification: {},
61
+ setModalProps: () => void 0,
62
+ setDrawerProps: () => void 0
63
+ });
64
+ function RoutesApp(props) {
65
+ const location = reactRouterDom.useLocation();
66
+ const { setDrawerProps, setModalProps } = useApp();
67
+ react$1.useEffect(() => {
68
+ console.debug("location", location);
69
+ setDrawerProps({ open: false });
70
+ setModalProps({ open: false });
71
+ }, [location]);
72
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
73
+ }
74
+ function App(props) {
75
+ const [messageApi, messageContextHolder] = antd.message.useMessage();
76
+ const [notificationApi, notificationContextHolder] = antd.notification.useNotification();
77
+ const { modal, setModalProps } = useModal();
78
+ const { drawer, setDrawerProps } = useDrawer();
79
+ const memoizedContextValue = react$1.useMemo(
80
+ () => ({
81
+ message: messageApi,
82
+ notification: notificationApi,
83
+ setModalProps,
84
+ setDrawerProps
85
+ }),
86
+ [
87
+ messageApi,
88
+ notificationApi,
89
+ setModalProps,
90
+ setDrawerProps
91
+ ]
92
+ );
93
+ return /* @__PURE__ */ jsxRuntime.jsx(
94
+ cssinjs.StyleProvider,
95
+ {
96
+ ...Object.assign(props.styleProviderProps || {}, {
97
+ hashPriority: "high",
98
+ transformers: [cssinjs.legacyLogicalPropertiesTransformer]
99
+ }),
100
+ children: /* @__PURE__ */ jsxRuntime.jsx(antd.ConfigProvider, { ...props.configProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(AppContext.Provider, { value: memoizedContextValue, children: /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.BrowserRouter, { ...props.browserRouterProps, children: [
101
+ messageContextHolder,
102
+ notificationContextHolder,
103
+ modal,
104
+ drawer,
105
+ /* @__PURE__ */ jsxRuntime.jsx(RoutesApp, { children: props.children })
106
+ ] }) }) })
107
+ }
108
+ );
109
+ }
110
+ function useApp() {
111
+ return react$1.useContext(AppContext);
112
+ }
113
+ App.useApp = useApp;
62
114
  var isZH = /^zh/i.test(navigator.language);
63
115
  var zh = {
64
116
  lang: "zh",
@@ -97,53 +149,37 @@ var baseConfig = {
97
149
  },
98
150
  Link: { style: {} }
99
151
  };
100
- var ConfigContext = (0, import_react2.createContext)(baseConfig);
101
- function ConfigProvider({
152
+ var ConfigContext = react$1.createContext(baseConfig);
153
+ function ConfigProvider2({
102
154
  config,
103
155
  children
104
156
  }) {
105
- const [values, setValues] = (0, import_react2.useState)(baseConfig);
106
- (0, import_react2.useEffect)(() => {
157
+ const [values, setValues] = react$1.useState(baseConfig);
158
+ react$1.useEffect(() => {
107
159
  if (config.lang === "zh") {
108
- setValues((0, import_lodash.defaultsDeep)(config, {
160
+ setValues(lodashEs.defaultsDeep(config, {
109
161
  lang: "zh",
110
162
  common: zh,
111
163
  Blank: { text: zh.blank },
112
164
  Form: { submit: { text: zh.submit } }
113
165
  }, baseConfig));
114
166
  } else
115
- setValues(values);
167
+ setValues(lodashEs.defaultsDeep(config, values));
116
168
  }, []);
117
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigContext.Provider, {
118
- value: values,
119
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.ConfigProvider, {
120
- ...config.antd,
121
- children
122
- })
123
- });
169
+ return /* @__PURE__ */ jsxRuntime.jsx(ConfigContext.Provider, { value: values, children });
124
170
  }
125
171
  function useConfigContext() {
126
- return (0, import_react2.useContext)(ConfigContext);
172
+ return react$1.useContext(ConfigContext);
127
173
  }
128
-
129
- // src/Blank.tsx
130
- var import_jsx_runtime = require("react/jsx-runtime");
131
174
  function Blank(options) {
132
175
  const { Blank: Blank2 } = useConfigContext();
133
- return !options || (0, import_lodash2.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd2.Typography.Text, {
134
- disabled: true,
135
- children: (options == null ? void 0 : options.text) || Blank2.text
136
- }) : options.value;
176
+ return !options || lodashEs.isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ jsxRuntime.jsx(antd.Typography.Text, { disabled: true, children: (options == null ? void 0 : options.text) || Blank2.text }) : options.value;
137
177
  }
138
-
139
- // src/data.ts
140
- var import_lodash3 = require("lodash");
141
- var import_dayjs = __toESM(require("dayjs"));
142
178
  function transferOptions(options) {
143
179
  if (!options)
144
180
  return [];
145
181
  return options.map((item) => typeof item === "object" ? item : {
146
- label: (0, import_lodash3.upperFirst)(item.toString()),
182
+ label: lodashEs.upperFirst(item.toString()),
147
183
  value: item
148
184
  });
149
185
  }
@@ -157,27 +193,39 @@ function transferValue(type, value) {
157
193
  if (["date", "time"].includes(type)) {
158
194
  if (typeof value === "number" && value.toString().length === 10)
159
195
  value = value * 1e3;
160
- if (!import_dayjs.default.isDayjs(value))
161
- value = (0, import_dayjs.default)(value);
196
+ if (!dayjs2__default.default.isDayjs(value))
197
+ value = dayjs2__default.default(value);
162
198
  }
163
199
  return value;
164
200
  }
165
-
166
- // src/Description.tsx
167
- var import_icons = require("@ant-design/icons");
168
- var import_antd3 = require("antd");
169
- var import_lodash4 = require("lodash");
170
- var import_react3 = require("react");
171
- var import_react4 = require("@faasjs/react");
172
- var import_jsx_runtime = require("react/jsx-runtime");
201
+ function Loading(props) {
202
+ if (props.loading === false)
203
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
204
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
205
+ ...props.style || {},
206
+ ...!props.size || props.size === "large" ? {
207
+ margin: "20vh auto",
208
+ textAlign: "center"
209
+ } : {}
210
+ }, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { size: props.size || "large" }) });
211
+ }
212
+ function FaasDataWrapper(props) {
213
+ return /* @__PURE__ */ jsxRuntime.jsx(
214
+ react.FaasDataWrapper,
215
+ {
216
+ fallback: props.loading || /* @__PURE__ */ jsxRuntime.jsx(Loading, { ...props.loadingProps }),
217
+ ...props
218
+ }
219
+ );
220
+ }
173
221
  function DescriptionItemContent(props) {
174
222
  var _a;
175
- const [computedProps, setComputedProps] = (0, import_react3.useState)();
176
- (0, import_react3.useEffect)(() => {
223
+ const [computedProps, setComputedProps] = react$1.useState();
224
+ react$1.useEffect(() => {
177
225
  var _a2, _b;
178
226
  const propsCopy = { ...props };
179
227
  if (!propsCopy.item.title)
180
- propsCopy.item.title = (0, import_lodash4.upperFirst)(propsCopy.item.id);
228
+ propsCopy.item.title = lodashEs.upperFirst(propsCopy.item.id);
181
229
  if (!propsCopy.item.type)
182
230
  propsCopy.item.type = "string";
183
231
  if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
@@ -203,164 +251,148 @@ function DescriptionItemContent(props) {
203
251
  return null;
204
252
  if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
205
253
  if (computedProps.extendTypes[computedProps.item.type].children)
206
- return (0, import_react3.cloneElement)(
254
+ return react$1.cloneElement(
207
255
  computedProps.extendTypes[computedProps.item.type].children,
208
256
  {
257
+ scene: "description",
209
258
  value: computedProps.value,
210
259
  values: computedProps.values
211
260
  }
212
261
  );
213
262
  else if (computedProps.extendTypes[computedProps.item.type].render)
214
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
215
- children: computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values)
216
- });
263
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values, 0, "description") });
217
264
  else
218
265
  throw Error(computedProps.item.type + " requires children or render");
266
+ if (computedProps.item.descriptionChildren === null)
267
+ return null;
268
+ if (computedProps.item.descriptionChildren)
269
+ return react$1.cloneElement(computedProps.item.descriptionChildren, {
270
+ scene: "description",
271
+ value: computedProps.value,
272
+ values: computedProps.values
273
+ });
274
+ if (computedProps.item.children === null)
275
+ return null;
219
276
  if (computedProps.item.children)
220
- return (0, import_react3.cloneElement)(computedProps.item.children, { value: computedProps.value });
221
- if (computedProps.item.render)
222
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
223
- children: computedProps.item.render(computedProps.value, computedProps.values)
277
+ return react$1.cloneElement(computedProps.item.children, {
278
+ scene: "description",
279
+ value: computedProps.value,
280
+ values: computedProps.values
224
281
  });
282
+ if (computedProps.item.descriptionRender)
283
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.item.descriptionRender(computedProps.value, computedProps.values, 0, "description") });
284
+ if (computedProps.item.render)
285
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.item.render(computedProps.value, computedProps.values, 0, "description") });
225
286
  if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length)
226
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
287
+ return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
227
288
  switch (computedProps.item.type) {
228
289
  case "string[]":
229
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
230
- children: computedProps.value.join(", ")
231
- });
290
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.join(", ") });
232
291
  case "number":
233
292
  return computedProps.value || null;
234
293
  case "number[]":
235
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
236
- children: computedProps.value.join(", ")
237
- });
294
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.join(", ") });
238
295
  case "boolean":
239
- return computedProps.value ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CheckOutlined, {
240
- style: {
241
- marginTop: "4px",
242
- color: "#52c41a"
243
- }
244
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CloseOutlined, {
245
- style: {
246
- marginTop: "4px",
247
- color: "#ff4d4f"
248
- }
249
- });
296
+ return computedProps.value ? /* @__PURE__ */ jsxRuntime.jsx(icons.CheckOutlined, { style: {
297
+ marginTop: "4px",
298
+ color: "#52c41a"
299
+ } }) : /* @__PURE__ */ jsxRuntime.jsx(icons.CloseOutlined, { style: {
300
+ marginTop: "4px",
301
+ color: "#ff4d4f"
302
+ } });
250
303
  case "time":
251
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
252
- children: computedProps.value.format("YYYY-MM-DD HH:mm:ss")
253
- });
304
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.format("YYYY-MM-DD HH:mm:ss") });
254
305
  case "date":
255
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
256
- children: computedProps.value.format("YYYY-MM-DD")
257
- });
306
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.value.format("YYYY-MM-DD") });
258
307
  case "object":
259
308
  if (!computedProps.value)
260
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
261
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
262
- items: computedProps.item.object,
263
- dataSource: computedProps.value,
264
- column: 1
265
- });
309
+ return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
310
+ return /* @__PURE__ */ jsxRuntime.jsx(
311
+ Description,
312
+ {
313
+ items: computedProps.item.object,
314
+ dataSource: computedProps.value,
315
+ column: 1
316
+ }
317
+ );
266
318
  case "object[]":
267
319
  if (!((_a = computedProps.value) == null ? void 0 : _a.length))
268
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
269
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Space, {
270
- direction: "vertical",
271
- children: computedProps.value.map((value, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
320
+ return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
321
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Space, { direction: "vertical", children: computedProps.value.map((value, index) => /* @__PURE__ */ jsxRuntime.jsx(
322
+ Description,
323
+ {
272
324
  items: computedProps.item.object,
273
325
  dataSource: value,
274
326
  column: 1
275
- }, index))
276
- });
327
+ },
328
+ index
329
+ )) });
277
330
  default:
278
331
  return computedProps.value || null;
279
332
  }
280
333
  }
281
334
  function Description(props) {
282
- if (!props.faasData)
283
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
335
+ if (props.faasData && !props.dataSource)
336
+ return /* @__PURE__ */ jsxRuntime.jsx(
337
+ FaasDataWrapper,
338
+ {
339
+ render: ({ data }) => /* @__PURE__ */ jsxRuntime.jsx(
340
+ Description,
341
+ {
342
+ ...props,
343
+ dataSource: data
344
+ }
345
+ ),
346
+ ...props.faasData
347
+ }
348
+ );
349
+ return /* @__PURE__ */ jsxRuntime.jsx(
350
+ antd.Descriptions,
351
+ {
284
352
  ...props,
285
- title: (0, import_lodash4.isFunction)(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
286
- children: props.items.map((item) => {
287
- return !item.if || item.if(props.dataSource) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
288
- label: item.title || (0, import_lodash4.upperFirst)(item.id),
289
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
353
+ title: lodashEs.isFunction(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
354
+ items: props.items.filter((item) => item && (!item.if || item.if(props.dataSource))).map((item) => ({
355
+ ...item,
356
+ key: item.id,
357
+ label: item.title || lodashEs.upperFirst(item.id),
358
+ children: /* @__PURE__ */ jsxRuntime.jsx(
359
+ DescriptionItemContent,
360
+ {
290
361
  item,
291
- value: props.dataSource[item.id],
362
+ value: props.dataSource ? props.dataSource[item.id] : null,
292
363
  values: props.dataSource,
293
364
  extendTypes: props.extendTypes
294
- })
295
- }, item.id) : null;
296
- }).filter(Boolean)
297
- });
298
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react4.FaasDataWrapper, {
299
- fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Skeleton, {
300
- active: true
301
- }),
302
- render: ({ data }) => {
303
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions, {
304
- ...props,
305
- title: (0, import_lodash4.isFunction)(props.renderTitle) ? props.renderTitle(data) : props.title,
306
- children: props.items.map((item) => {
307
- return !item.if || item.if(data) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd3.Descriptions.Item, {
308
- label: item.title || (0, import_lodash4.upperFirst)(item.id),
309
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionItemContent, {
310
- item,
311
- value: data[item.id],
312
- values: data,
313
- extendTypes: props.extendTypes
314
- })
315
- }, item.id) : null;
316
- }).filter(Boolean)
317
- });
318
- },
319
- ...props.faasData
320
- });
365
+ }
366
+ )
367
+ }))
368
+ }
369
+ );
321
370
  }
322
-
323
- // src/Drawer.tsx
324
- var import_antd4 = require("antd");
325
- var import_react5 = require("react");
326
- var import_jsx_runtime = require("react/jsx-runtime");
327
- function useDrawer(init) {
328
- const [props, setProps] = (0, import_react5.useState)({
329
- open: false,
330
- onClose: () => setProps((prev) => ({
331
- ...prev,
332
- open: false
333
- })),
334
- ...init
335
- });
336
- return {
337
- drawer: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd4.Drawer, {
371
+ function ErrorChildren(props) {
372
+ return /* @__PURE__ */ jsxRuntime.jsx(
373
+ antd.Alert,
374
+ {
375
+ type: "error",
376
+ message: props.errorMessage,
377
+ description: /* @__PURE__ */ jsxRuntime.jsx("pre", { style: {
378
+ fontSize: "0.9em",
379
+ overflowX: "auto"
380
+ }, children: props.errorDescription })
381
+ }
382
+ );
383
+ }
384
+ function ErrorBoundary(props) {
385
+ return /* @__PURE__ */ jsxRuntime.jsx(
386
+ react.ErrorBoundary,
387
+ {
388
+ errorChildren: /* @__PURE__ */ jsxRuntime.jsx(ErrorChildren, {}),
338
389
  ...props
339
- }),
340
- drawerProps: props,
341
- setDrawerProps(changes) {
342
- setProps((prev) => ({
343
- ...prev,
344
- ...changes
345
- }));
346
390
  }
347
- };
391
+ );
348
392
  }
349
-
350
- // src/Form.tsx
351
- var import_react7 = require("@faasjs/react");
352
- var import_antd6 = require("antd");
353
- var import_react8 = require("react");
354
-
355
- // src/FormItem.tsx
356
- var import_antd5 = require("antd");
357
- var import_icons2 = require("@ant-design/icons");
358
- var import_react6 = require("react");
359
- var import_lodash5 = require("lodash");
360
- var import_jsx_runtime = require("react/jsx-runtime");
361
393
  function processProps(propsCopy, config) {
362
394
  if (!propsCopy.title)
363
- propsCopy.title = (0, import_lodash5.upperFirst)(propsCopy.id);
395
+ propsCopy.title = lodashEs.upperFirst(propsCopy.id);
364
396
  if (!propsCopy.label && propsCopy.label !== false)
365
397
  propsCopy.label = propsCopy.title;
366
398
  if (!propsCopy.name)
@@ -375,13 +407,13 @@ function processProps(propsCopy, config) {
375
407
  required: true,
376
408
  validator: async (_, values) => {
377
409
  if (!values || values.length < 1)
378
- return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.common.required}`));
410
+ return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.required}`));
379
411
  }
380
412
  });
381
413
  else
382
414
  propsCopy.rules.push({
383
415
  required: true,
384
- message: `${propsCopy.label || propsCopy.title} ${config.common.required}`
416
+ message: `${propsCopy.label || propsCopy.title} ${config.required}`
385
417
  });
386
418
  }
387
419
  if (!propsCopy.input)
@@ -406,11 +438,11 @@ function processProps(propsCopy, config) {
406
438
  }
407
439
  function FormItem(props) {
408
440
  var _a;
409
- const [computedProps, setComputedProps] = (0, import_react6.useState)();
410
- const [extendTypes, setExtendTypes] = (0, import_react6.useState)();
411
- const config = useConfigContext();
412
- const [hidden, setHidden] = (0, import_react6.useState)(false);
413
- (0, import_react6.useEffect)(() => {
441
+ const [computedProps, setComputedProps] = react$1.useState();
442
+ const [extendTypes, setExtendTypes] = react$1.useState();
443
+ const { common: common2 } = useConfigContext();
444
+ const [hidden, setHidden] = react$1.useState(props.hidden || false);
445
+ react$1.useEffect(() => {
414
446
  const propsCopy = { ...props };
415
447
  if (propsCopy.extendTypes) {
416
448
  setExtendTypes(propsCopy.extendTypes);
@@ -418,325 +450,311 @@ function FormItem(props) {
418
450
  }
419
451
  if (propsCopy.if) {
420
452
  const condition = propsCopy.if;
421
- propsCopy.shouldUpdate = (_, cur) => {
453
+ const originShouldUpdate = propsCopy.shouldUpdate;
454
+ propsCopy.shouldUpdate = (prev, cur) => {
422
455
  const show = condition(cur);
456
+ const shouldUpdate = hidden !== show;
423
457
  setHidden(!show);
424
- return show;
458
+ const origin = originShouldUpdate ? typeof originShouldUpdate === "boolean" ? originShouldUpdate : originShouldUpdate(prev, cur, {}) : true;
459
+ return shouldUpdate || origin;
425
460
  };
426
461
  delete propsCopy.if;
462
+ delete propsCopy.hidden;
427
463
  }
428
- setComputedProps(processProps(propsCopy, config));
464
+ setComputedProps(processProps(propsCopy, common2));
429
465
  }, [props]);
430
466
  if (!computedProps)
431
467
  return null;
432
468
  if (hidden)
433
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
434
- ...computedProps,
435
- noStyle: true,
436
- rules: [],
437
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
438
- hidden: true
439
- })
440
- });
469
+ return /* @__PURE__ */ jsxRuntime.jsx(
470
+ antd.Form.Item,
471
+ {
472
+ ...computedProps,
473
+ noStyle: true,
474
+ rules: [],
475
+ children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { hidden: true })
476
+ }
477
+ );
441
478
  if (extendTypes && extendTypes[computedProps.type])
442
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
443
- ...computedProps,
444
- children: extendTypes[computedProps.type].children
445
- });
479
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: extendTypes[computedProps.type].children });
480
+ if (computedProps.formChildren === null)
481
+ return null;
482
+ if (computedProps.formChildren)
483
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: react$1.cloneElement(computedProps.formChildren, { scene: "form" }) });
484
+ if (computedProps.children === null)
485
+ return null;
446
486
  if (computedProps.children)
447
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
448
- ...computedProps,
449
- children: computedProps.children
450
- });
487
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: react$1.cloneElement(computedProps.children, { scene: "form" }) });
488
+ if (computedProps.formRender)
489
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.formRender(null, null, 0, "form") });
451
490
  if (computedProps.render)
452
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
453
- ...computedProps,
454
- children: computedProps.render()
455
- });
491
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.render(null, null, 0, "form") });
456
492
  switch (computedProps.type) {
457
493
  case "string":
458
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
459
- ...computedProps,
460
- children: computedProps.options ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
461
- ...computedProps.input
462
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
463
- ...computedProps.input
464
- })
465
- });
494
+ if (computedProps.options)
495
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.options.length > 10 ? /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Group, { ...computedProps.input }) });
496
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { ...computedProps.input }) });
466
497
  case "string[]":
467
498
  if (computedProps.options)
468
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
469
- ...computedProps,
470
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
499
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(
500
+ antd.Select,
501
+ {
471
502
  mode: "multiple",
472
503
  ...computedProps.input
473
- })
474
- });
475
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
476
- name: computedProps.name,
477
- rules: computedProps.rules,
478
- children: (fields, { add, remove }, { errors }) => {
479
- var _a2;
480
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
481
- children: [
482
- computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
483
- className: "ant-form-item-label",
484
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
485
- className: computedProps.rules.find((r) => r.required) && "ant-form-item-required",
486
- children: computedProps.label
487
- })
488
- }),
504
+ }
505
+ ) });
506
+ return /* @__PURE__ */ jsxRuntime.jsx(
507
+ antd.Form.List,
508
+ {
509
+ name: computedProps.name,
510
+ rules: computedProps.rules,
511
+ children: (fields, { add, remove }, { errors }) => {
512
+ var _a2;
513
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
514
+ computedProps.label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsx("label", { className: computedProps.rules.find((r) => r.required) && "ant-form-item-required", children: computedProps.label }) }),
489
515
  fields.map((field) => {
490
516
  var _a3;
491
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
492
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Row, {
517
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs(
518
+ antd.Row,
519
+ {
493
520
  gutter: 24,
494
521
  style: { flexFlow: "row nowrap" },
495
522
  children: [
496
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
497
- span: 23,
498
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
523
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 23, children: /* @__PURE__ */ jsxRuntime.jsx(
524
+ antd.Form.Item,
525
+ {
499
526
  ...field,
500
527
  noStyle: true,
501
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Input, {
502
- ...computedProps.input
503
- })
504
- })
505
- }),
506
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
507
- span: 1,
508
- children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
528
+ children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { ...computedProps.input })
529
+ }
530
+ ) }),
531
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 1, children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsxRuntime.jsx(
532
+ antd.Button,
533
+ {
509
534
  danger: true,
510
535
  type: "link",
511
536
  style: { float: "right" },
512
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.MinusCircleOutlined, {}),
537
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusCircleOutlined, {}),
513
538
  onClick: () => remove(field.name)
514
- })
515
- })
539
+ }
540
+ ) })
516
541
  ]
517
- })
518
- }, field.key);
542
+ }
543
+ ) }, field.key);
519
544
  }),
520
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
521
- children: [
522
- !((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
545
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Form.Item, { children: [
546
+ !((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxRuntime.jsx(
547
+ antd.Button,
548
+ {
523
549
  type: "dashed",
524
550
  block: true,
525
551
  onClick: () => add(),
526
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {})
527
- }),
528
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
529
- errors
530
- })
531
- ]
532
- })
533
- ]
534
- });
552
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {})
553
+ }
554
+ ),
555
+ computedProps.extra && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
556
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Form.ErrorList, { errors })
557
+ ] })
558
+ ] });
559
+ }
535
560
  }
536
- });
561
+ );
537
562
  case "number":
538
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
539
- ...computedProps,
540
- children: computedProps.options ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
541
- ...computedProps.input
542
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.InputNumber, {
563
+ if (computedProps.options)
564
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.options.length > 10 ? /* @__PURE__ */ jsxRuntime.jsx(antd.Select, { ...computedProps.input }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Group, { ...computedProps.input }) });
565
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(
566
+ antd.InputNumber,
567
+ {
543
568
  style: { width: "100%" },
544
569
  ...computedProps.input
545
- })
546
- });
570
+ }
571
+ ) });
547
572
  case "number[]":
548
573
  if (computedProps.options)
549
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
550
- ...computedProps,
551
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Select, {
574
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(
575
+ antd.Select,
576
+ {
552
577
  mode: "multiple",
553
578
  ...computedProps.input
554
- })
555
- });
556
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
557
- name: computedProps.name,
558
- rules: computedProps.rules,
559
- children: (fields, { add, remove }, { errors }) => {
560
- var _a2, _b;
561
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
562
- children: [
563
- computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
564
- className: "ant-form-item-label",
565
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
566
- className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required",
567
- children: computedProps.label
568
- })
569
- }),
579
+ }
580
+ ) });
581
+ return /* @__PURE__ */ jsxRuntime.jsx(
582
+ antd.Form.List,
583
+ {
584
+ name: computedProps.name,
585
+ rules: computedProps.rules,
586
+ children: (fields, { add, remove }, { errors }) => {
587
+ var _a2, _b;
588
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
589
+ computedProps.label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsx("label", { className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required", children: computedProps.label }) }),
570
590
  fields.map((field) => {
571
591
  var _a3;
572
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
573
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Row, {
592
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs(
593
+ antd.Row,
594
+ {
574
595
  gutter: 24,
575
596
  style: { flexFlow: "row nowrap" },
576
597
  children: [
577
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
578
- span: 23,
579
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
598
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 23, children: /* @__PURE__ */ jsxRuntime.jsx(
599
+ antd.Form.Item,
600
+ {
580
601
  ...field,
581
602
  noStyle: true,
582
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.InputNumber, {
583
- style: { width: "100%" },
584
- ...computedProps.input
585
- })
586
- })
587
- }),
588
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
589
- span: 1,
590
- children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
603
+ children: /* @__PURE__ */ jsxRuntime.jsx(
604
+ antd.InputNumber,
605
+ {
606
+ style: { width: "100%" },
607
+ ...computedProps.input
608
+ }
609
+ )
610
+ }
611
+ ) }),
612
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Col, { span: 1, children: !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsxRuntime.jsx(
613
+ antd.Button,
614
+ {
591
615
  danger: true,
592
616
  type: "link",
593
617
  style: { float: "right" },
594
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.MinusCircleOutlined, {}),
618
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.MinusCircleOutlined, {}),
595
619
  onClick: () => remove(field.name)
596
- })
597
- })
620
+ }
621
+ ) })
598
622
  ]
599
- })
600
- }, field.key);
623
+ }
624
+ ) }, field.key);
601
625
  }),
602
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
603
- children: [
604
- !((_b = computedProps.input) == null ? void 0 : _b.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
626
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Form.Item, { children: [
627
+ !((_b = computedProps.input) == null ? void 0 : _b.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxRuntime.jsx(
628
+ antd.Button,
629
+ {
605
630
  type: "dashed",
606
631
  block: true,
607
632
  onClick: () => add(),
608
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {})
609
- }),
610
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
611
- errors
612
- })
613
- ]
614
- })
615
- ]
616
- });
633
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {})
634
+ }
635
+ ),
636
+ computedProps.extra && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
637
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Form.ErrorList, { errors })
638
+ ] })
639
+ ] });
640
+ }
617
641
  }
618
- });
642
+ );
619
643
  case "boolean":
620
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
621
- ...computedProps,
622
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Switch, {
623
- ...computedProps.input
624
- })
625
- });
644
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Switch, { ...computedProps.input }) });
626
645
  case "date":
627
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
628
- ...computedProps,
629
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.DatePicker, {
630
- ...computedProps.input
631
- })
632
- });
646
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.DatePicker, { ...computedProps.input }) });
633
647
  case "time":
634
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.Item, {
635
- ...computedProps,
636
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.TimePicker, {
637
- ...computedProps.input
638
- })
639
- });
648
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: /* @__PURE__ */ jsxRuntime.jsx(antd.TimePicker, { ...computedProps.input }) });
640
649
  case "object":
641
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
642
- children: [
643
- computedProps.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
644
- className: "ant-form-item-label",
645
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
646
- className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required",
647
- children: computedProps.label
648
- })
649
- }),
650
- computedProps.object.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
650
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
651
+ computedProps.label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsx("label", { className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required", children: computedProps.label }) }),
652
+ computedProps.object.map((o) => /* @__PURE__ */ jsxRuntime.jsx(
653
+ FormItem,
654
+ {
651
655
  ...o
652
- }, o.id))
653
- ]
654
- });
656
+ },
657
+ o.id
658
+ ))
659
+ ] });
655
660
  case "object[]":
656
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.List, {
657
- name: computedProps.name,
658
- rules: computedProps.rules,
659
- children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
660
- children: [
661
- fields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
662
- style: { marginBottom: 0 },
663
- children: [
664
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
665
- className: "ant-form-item-label",
666
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
667
- children: [
668
- computedProps.label,
669
- " ",
670
- field.name + 1,
671
- !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Button, {
661
+ return /* @__PURE__ */ jsxRuntime.jsx(
662
+ antd.Form.List,
663
+ {
664
+ name: computedProps.name,
665
+ rules: computedProps.rules,
666
+ children: (fields, { add, remove }, { errors }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
667
+ fields.map((field) => /* @__PURE__ */ jsxRuntime.jsxs(
668
+ antd.Form.Item,
669
+ {
670
+ style: { marginBottom: 0 },
671
+ children: [
672
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-label", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
673
+ computedProps.label,
674
+ " ",
675
+ field.name + 1,
676
+ !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ jsxRuntime.jsx(
677
+ antd.Button,
678
+ {
672
679
  danger: true,
673
680
  type: "link",
674
681
  onClick: () => remove(field.name),
675
- children: config.common.delete
676
- })
677
- ]
678
- })
679
- }),
680
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Row, {
681
- gutter: 24,
682
- children: computedProps.object.map((o) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Col, {
683
- span: o.col || 24,
684
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
685
- ...o,
686
- name: [field.name, o.id]
687
- })
688
- }, o.id))
689
- })
690
- ]
691
- }, field.key)),
692
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Form.Item, {
693
- children: [
694
- !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd5.Button, {
682
+ children: common2.delete
683
+ }
684
+ )
685
+ ] }) }),
686
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Row, { gutter: 24, children: computedProps.object.map((o) => /* @__PURE__ */ jsxRuntime.jsx(
687
+ antd.Col,
688
+ {
689
+ span: o.col || 24,
690
+ children: /* @__PURE__ */ jsxRuntime.jsx(
691
+ FormItem,
692
+ {
693
+ ...o,
694
+ name: [field.name, o.id]
695
+ }
696
+ )
697
+ },
698
+ o.id
699
+ )) })
700
+ ]
701
+ },
702
+ field.key
703
+ )),
704
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Form.Item, { children: [
705
+ !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ jsxRuntime.jsxs(
706
+ antd.Button,
707
+ {
695
708
  type: "dashed",
696
709
  block: true,
697
710
  onClick: () => add(),
698
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.PlusOutlined, {}),
711
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
699
712
  children: [
700
- config.common.add,
713
+ common2.add,
701
714
  " ",
702
715
  computedProps.label
703
716
  ]
704
- }),
705
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd5.Form.ErrorList, {
706
- errors
707
- })
708
- ]
709
- })
710
- ]
711
- })
712
- });
717
+ }
718
+ ),
719
+ computedProps.extra && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ant-form-item-extra", children: computedProps.extra }),
720
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Form.ErrorList, { errors })
721
+ ] })
722
+ ] })
723
+ }
724
+ );
713
725
  default:
714
726
  return null;
715
727
  }
716
728
  }
717
-
718
- // src/Form.tsx
719
- var import_jsx_runtime = require("react/jsx-runtime");
729
+ FormItem.useStatus = antd.Form.Item.useStatus;
720
730
  function Form(props) {
721
731
  var _a, _b;
722
- const [loading, setLoading] = (0, import_react8.useState)(false);
723
- const [computedProps, setComputedProps] = (0, import_react8.useState)();
732
+ const [loading, setLoading] = react$1.useState(false);
733
+ const [computedProps, setComputedProps] = react$1.useState();
724
734
  const config = useConfigContext();
725
- const [extendTypes, setExtendTypes] = (0, import_react8.useState)();
726
- const [form] = import_antd6.Form.useForm(props.form);
727
- const [initialValues, setInitialValues] = (0, import_react8.useState)(props.initialValues);
728
- (0, import_react8.useEffect)(() => {
729
- var _a2, _b2;
735
+ const [extendTypes, setExtendTypes] = react$1.useState();
736
+ const [form] = antd.Form.useForm(props.form);
737
+ const [initialValues, setInitialValues] = react$1.useState(props.initialValues);
738
+ react$1.useEffect(() => {
739
+ var _a2, _b2, _c;
730
740
  const propsCopy = {
731
741
  ...props,
732
742
  form
733
743
  };
734
- if (propsCopy.initialValues) {
735
- for (const key in propsCopy.initialValues)
744
+ if (propsCopy.initialValues && ((_a2 = propsCopy.items) == null ? void 0 : _a2.length)) {
745
+ for (const key in propsCopy.initialValues) {
736
746
  propsCopy.initialValues[key] = transferValue(
737
- (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
747
+ (_b2 = propsCopy.items.find((item2) => item2.id === key)) == null ? void 0 : _b2.type,
738
748
  propsCopy.initialValues[key]
739
749
  );
750
+ const item = propsCopy.items.find((item2) => item2.id === key);
751
+ if (item == null ? void 0 : item.if)
752
+ item.hidden = !item.if(propsCopy.initialValues);
753
+ }
754
+ for (const item of propsCopy.items) {
755
+ if (item.if)
756
+ item.hidden = !item.if(propsCopy.initialValues);
757
+ }
740
758
  setInitialValues(propsCopy.initialValues);
741
759
  delete propsCopy.initialValues;
742
760
  }
@@ -746,7 +764,7 @@ function Form(props) {
746
764
  setLoading(true);
747
765
  try {
748
766
  if (propsCopy.submit && ((_a3 = propsCopy.submit.to) == null ? void 0 : _a3.action)) {
749
- await props.onFinish(values, async (values2) => (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
767
+ await props.onFinish(values, async (values2) => react.faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
750
768
  ...values2,
751
769
  ...propsCopy.submit.to.params
752
770
  } : values2));
@@ -757,13 +775,25 @@ function Form(props) {
757
775
  }
758
776
  setLoading(false);
759
777
  };
760
- } else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
778
+ } else if (propsCopy.submit && ((_c = propsCopy.submit.to) == null ? void 0 : _c.action)) {
761
779
  propsCopy.onFinish = async (values) => {
762
780
  setLoading(true);
763
- return (0, import_react7.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
781
+ return react.faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
764
782
  ...values,
765
783
  ...propsCopy.submit.to.params
766
- } : values).finally(() => setLoading(false));
784
+ } : values).then((result) => {
785
+ if (propsCopy.submit.to.then)
786
+ propsCopy.submit.to.then(result);
787
+ return result;
788
+ }).catch((error) => {
789
+ if (propsCopy.submit.to.catch)
790
+ propsCopy.submit.to.catch(error);
791
+ return Promise.reject(error);
792
+ }).finally(() => {
793
+ if (propsCopy.submit.to.finally)
794
+ propsCopy.submit.to.finally();
795
+ setLoading(false);
796
+ });
767
797
  };
768
798
  }
769
799
  if (propsCopy.extendTypes) {
@@ -772,7 +802,8 @@ function Form(props) {
772
802
  }
773
803
  setComputedProps(propsCopy);
774
804
  }, [props]);
775
- const onValuesChange = (0, import_react8.useCallback)((changedValues, allValues) => {
805
+ const onValuesChange = react$1.useCallback((changedValues, allValues) => {
806
+ console.debug("Form:onValuesChange", changedValues, allValues);
776
807
  if (props.onValuesChange) {
777
808
  props.onValuesChange(changedValues, allValues);
778
809
  }
@@ -784,173 +815,172 @@ function Form(props) {
784
815
  item.onValueChange(changedValues[key], allValues, form);
785
816
  }
786
817
  }, [computedProps]);
787
- (0, import_react8.useEffect)(() => {
818
+ react$1.useEffect(() => {
788
819
  if (!initialValues)
789
820
  return;
821
+ console.debug("Form:initialValues", initialValues);
790
822
  form.setFieldsValue(initialValues);
791
823
  setInitialValues(null);
792
824
  }, [computedProps]);
793
825
  if (!computedProps)
794
826
  return null;
795
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd6.Form, {
796
- ...computedProps,
797
- onValuesChange,
798
- children: [
799
- computedProps.beforeItems,
800
- (_a = computedProps.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormItem, {
801
- ...item,
802
- extendTypes
803
- }, item.id)),
804
- computedProps.children,
805
- computedProps.submit !== false && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd6.Button, {
806
- htmlType: "submit",
807
- type: "primary",
808
- loading,
809
- children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text
810
- }),
811
- computedProps.footer
812
- ]
813
- });
814
- }
815
- Form.useForm = import_antd6.Form.useForm;
816
-
817
- // src/Link.tsx
818
- var import_react_router_dom = require("react-router-dom");
819
- var import_antd7 = require("antd");
820
- var import_jsx_runtime = require("react/jsx-runtime");
821
- function Link({
822
- href,
823
- target,
824
- text,
825
- children,
826
- style,
827
- button
828
- }) {
829
- const { Link: Link2 } = useConfigContext();
830
- style = Object.assign({ cursor: "pointer" }, style);
831
- if (href.startsWith("http")) {
832
- if (button)
833
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
834
- ...button,
835
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
836
- href,
837
- target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
838
- style: {
839
- ...Link2.style,
840
- ...style || {}
827
+ return /* @__PURE__ */ jsxRuntime.jsxs(
828
+ antd.Form,
829
+ {
830
+ ...computedProps,
831
+ onValuesChange,
832
+ children: [
833
+ computedProps.beforeItems,
834
+ (_a = computedProps.items) == null ? void 0 : _a.map((item) => react$1.isValidElement(item) ? item : /* @__PURE__ */ jsxRuntime.jsx(
835
+ FormItem,
836
+ {
837
+ ...item,
838
+ extendTypes
841
839
  },
842
- children: text || children
843
- })
844
- });
845
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
846
- href,
847
- target: target || (Link2 == null ? void 0 : Link2.target) || "_blank",
848
- style: {
849
- ...Link2.style,
850
- ...style || {}
851
- },
852
- children: text || children
853
- });
854
- }
855
- if (button)
856
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd7.Button, {
857
- ...button,
858
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
859
- to: href,
860
- target: target || (Link2 == null ? void 0 : Link2.target),
861
- style: {
862
- ...Link2.style,
863
- ...style || {}
864
- },
865
- children: text || children
866
- })
867
- });
868
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Link, {
869
- to: href,
870
- target: target || (Link2 == null ? void 0 : Link2.target),
871
- style: {
872
- ...Link2.style,
873
- ...style || {}
874
- },
875
- children: text || children
876
- });
877
- }
878
-
879
- // src/Modal.tsx
880
- var import_antd8 = require("antd");
881
- var import_react9 = require("react");
882
- var import_jsx_runtime = require("react/jsx-runtime");
883
- function useModal(init) {
884
- const [props, setProps] = (0, import_react9.useState)({
885
- open: false,
886
- onCancel: () => setProps((prev) => ({
887
- ...prev,
888
- open: false
889
- })),
890
- ...init
891
- });
892
- return {
893
- modal: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd8.Modal, {
894
- ...props
895
- }),
896
- modalProps: props,
897
- setModalProps(changes) {
898
- setProps((prev) => ({
899
- ...prev,
900
- ...changes
901
- }));
840
+ item.id
841
+ )),
842
+ computedProps.children,
843
+ computedProps.submit !== false && /* @__PURE__ */ jsxRuntime.jsx(
844
+ antd.Button,
845
+ {
846
+ htmlType: "submit",
847
+ type: "primary",
848
+ loading,
849
+ children: ((_b = computedProps.submit) == null ? void 0 : _b.text) || config.Form.submit.text
850
+ }
851
+ ),
852
+ computedProps.footer
853
+ ]
902
854
  }
855
+ );
856
+ }
857
+ Form.useForm = antd.Form.useForm;
858
+ Form.useFormInstance = antd.Form.useFormInstance;
859
+ Form.useWatch = antd.Form.useWatch;
860
+ Form.Item = FormItem;
861
+ Form.List = antd.Form.List;
862
+ Form.ErrorList = antd.Form.ErrorList;
863
+ Form.Provider = antd.Form.Provider;
864
+ function Link(props) {
865
+ var _a, _b;
866
+ const { Link: Config } = useConfigContext();
867
+ const navigate = reactRouterDom.useNavigate();
868
+ let style = {
869
+ ...Config.style || {},
870
+ cursor: "pointer",
871
+ ...props.style
903
872
  };
873
+ if (props.block)
874
+ style = Object.assign({
875
+ display: "block",
876
+ width: "100%"
877
+ }, style);
878
+ if (props.href.startsWith("http")) {
879
+ if (props.button)
880
+ return /* @__PURE__ */ jsxRuntime.jsx(
881
+ antd.Button,
882
+ {
883
+ ...props.button,
884
+ target: props.target || (Config == null ? void 0 : Config.target) || "_blank",
885
+ style,
886
+ href: props.href,
887
+ children: (_a = props.text) != null ? _a : props.children
888
+ }
889
+ );
890
+ if (props.children)
891
+ return /* @__PURE__ */ jsxRuntime.jsx(
892
+ "a",
893
+ {
894
+ href: props.href,
895
+ target: props.target || (Config == null ? void 0 : Config.target),
896
+ style,
897
+ children: props.children
898
+ }
899
+ );
900
+ return /* @__PURE__ */ jsxRuntime.jsx(
901
+ antd.Typography.Link,
902
+ {
903
+ href: props.href,
904
+ target: props.target || (Config == null ? void 0 : Config.target) || "_blank",
905
+ style,
906
+ copyable: props.copyable,
907
+ children: props.text
908
+ }
909
+ );
910
+ }
911
+ if (props.button)
912
+ return /* @__PURE__ */ jsxRuntime.jsx(
913
+ antd.Button,
914
+ {
915
+ ...props.button,
916
+ style,
917
+ onClick: () => (props.target || (Config == null ? void 0 : Config.target)) === "_blank" ? window.open(props.href) : navigate(props.href),
918
+ children: (_b = props.text) != null ? _b : props.children
919
+ }
920
+ );
921
+ if (props.children)
922
+ return /* @__PURE__ */ jsxRuntime.jsx(
923
+ reactRouterDom.Link,
924
+ {
925
+ to: props.href,
926
+ target: props.target || (Config == null ? void 0 : Config.target),
927
+ style,
928
+ children: props.children
929
+ }
930
+ );
931
+ return /* @__PURE__ */ jsxRuntime.jsx(
932
+ antd.Typography.Link,
933
+ {
934
+ href: props.href,
935
+ target: props.target || (Config == null ? void 0 : Config.target),
936
+ style,
937
+ copyable: props.copyable,
938
+ onClick: (e) => {
939
+ e.preventDefault();
940
+ if ((props.target || (Config == null ? void 0 : Config.target)) === "_blank")
941
+ window.open(props.href);
942
+ else
943
+ navigate(props.href);
944
+ },
945
+ children: props.text
946
+ }
947
+ );
904
948
  }
905
-
906
- // src/Routers.tsx
907
- var import_antd9 = require("antd");
908
- var import_react10 = require("react");
909
- var import_react_router_dom2 = require("react-router-dom");
910
- var import_jsx_runtime = require("react/jsx-runtime");
911
949
  function PageNotFound() {
912
950
  const config = useConfigContext();
913
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd9.Result, {
914
- status: "404",
915
- title: config.common.pageNotFound
916
- });
951
+ return /* @__PURE__ */ jsxRuntime.jsx(
952
+ antd.Result,
953
+ {
954
+ status: "404",
955
+ title: config.common.pageNotFound
956
+ }
957
+ );
917
958
  }
918
959
  function Routes(props) {
919
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_router_dom2.Routes, {
920
- children: [
921
- props.routes.map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom2.Route, {
960
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [
961
+ props.routes.map((r) => /* @__PURE__ */ jsxRuntime.jsx(
962
+ reactRouterDom.Route,
963
+ {
922
964
  ...r,
923
- element: r.element || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react10.Suspense, {
924
- fallback: props.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
925
- style: { padding: "24px" },
926
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd9.Skeleton, {
927
- active: true
928
- })
929
- }),
930
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(r.page, {})
931
- })
932
- }, r.path)),
933
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom2.Route, {
965
+ element: r.element || /* @__PURE__ */ jsxRuntime.jsx(react$1.Suspense, { fallback: props.fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "24px" }, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Skeleton, { active: true }) }), children: /* @__PURE__ */ jsxRuntime.jsx(r.page, {}) })
966
+ },
967
+ r.path
968
+ )),
969
+ /* @__PURE__ */ jsxRuntime.jsx(
970
+ reactRouterDom.Route,
971
+ {
934
972
  path: "*",
935
- element: props.notFound || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageNotFound, {})
936
- }, "*")
937
- ]
938
- });
973
+ element: props.notFound || /* @__PURE__ */ jsxRuntime.jsx(PageNotFound, {})
974
+ },
975
+ "*"
976
+ )
977
+ ] });
939
978
  }
940
-
941
- // src/Table.tsx
942
- var import_react11 = require("react");
943
- var import_antd10 = require("antd");
944
- var import_dayjs2 = __toESM(require("dayjs"));
945
- var import_icons3 = require("@ant-design/icons");
946
- var import_lodash6 = require("lodash");
947
- var import_react12 = require("@faasjs/react");
948
- var import_jsx_runtime = require("react/jsx-runtime");
949
979
  function processValue(item, value) {
950
980
  var _a;
951
981
  const transferred = transferValue(item.type, value);
952
982
  if (transferred === null || Array.isArray(transferred) && transferred.length === 0)
953
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {});
983
+ return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
954
984
  if (item.options) {
955
985
  if (item.type.endsWith("[]"))
956
986
  return transferred.map((v) => {
@@ -971,9 +1001,58 @@ function processValue(item, value) {
971
1001
  return value;
972
1002
  }
973
1003
  function Table(props) {
974
- const [columns, setColumns] = (0, import_react11.useState)();
1004
+ const [columns, setColumns] = react$1.useState();
975
1005
  const { common: common2 } = useConfigContext();
976
- (0, import_react11.useEffect)(() => {
1006
+ const generateFilterDropdown = (item) => {
1007
+ if (typeof item.filterDropdown !== "undefined")
1008
+ return;
1009
+ if (item.options.length < 11) {
1010
+ if (!item.filters)
1011
+ item.filters = item.options.map((o) => ({
1012
+ text: o.label,
1013
+ value: o.value
1014
+ }));
1015
+ return;
1016
+ }
1017
+ item.filterDropdown = ({
1018
+ setSelectedKeys,
1019
+ selectedKeys,
1020
+ confirm
1021
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1022
+ "div",
1023
+ {
1024
+ style: {
1025
+ padding: 8,
1026
+ width: "200px"
1027
+ },
1028
+ onKeyDown: (e) => e.stopPropagation(),
1029
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1030
+ antd.Select,
1031
+ {
1032
+ options: item.options,
1033
+ allowClear: true,
1034
+ showSearch: true,
1035
+ style: { width: "100%" },
1036
+ placeholder: `${common2.search} ${item.title}`,
1037
+ value: selectedKeys,
1038
+ onChange: (v) => {
1039
+ setSelectedKeys((v == null ? void 0 : v.length) ? v : []);
1040
+ confirm();
1041
+ },
1042
+ mode: "multiple",
1043
+ filterOption: (input, option) => {
1044
+ if (!input || !option || !option.label)
1045
+ return true;
1046
+ input = input.trim();
1047
+ return option.value === input || option.label.toString().toLowerCase().includes(input.toLowerCase());
1048
+ }
1049
+ }
1050
+ )
1051
+ }
1052
+ );
1053
+ return item;
1054
+ };
1055
+ react$1.useEffect(() => {
977
1056
  var _a;
978
1057
  for (const item of props.items) {
979
1058
  if (!item.key)
@@ -981,7 +1060,7 @@ function Table(props) {
981
1060
  if (!item.dataIndex)
982
1061
  item.dataIndex = item.id;
983
1062
  if (!item.title)
984
- item.title = (0, import_lodash6.upperFirst)(item.id);
1063
+ item.title = lodashEs.upperFirst(item.id);
985
1064
  if (!item.type)
986
1065
  item.type = "string";
987
1066
  if ((_a = item.options) == null ? void 0 : _a.length) {
@@ -989,15 +1068,40 @@ function Table(props) {
989
1068
  item.filters = item.options.map((o) => ({
990
1069
  text: o.label,
991
1070
  value: o.value
992
- }));
1071
+ })).concat({
1072
+ text: /* @__PURE__ */ jsxRuntime.jsx(Blank, {}),
1073
+ value: null
1074
+ });
1075
+ generateFilterDropdown(item);
993
1076
  }
994
- if (item.children)
995
- delete item.children;
1077
+ if (item.tableChildren === null)
1078
+ item.render = () => null;
1079
+ else if (item.tableChildren)
1080
+ item.render = (value, values) => react$1.cloneElement(
1081
+ item.tableChildren,
1082
+ {
1083
+ scene: "table",
1084
+ value,
1085
+ values
1086
+ }
1087
+ );
1088
+ else if (item.children === null)
1089
+ item.render = () => null;
1090
+ else if (item.children)
1091
+ item.render = (value, values) => react$1.cloneElement(
1092
+ item.children,
1093
+ {
1094
+ scene: "table",
1095
+ value,
1096
+ values
1097
+ }
1098
+ );
996
1099
  if (props.extendTypes && props.extendTypes[item.type]) {
997
1100
  if (props.extendTypes[item.type].children)
998
- item.render = (value, values) => (0, import_react11.cloneElement)(
1101
+ item.render = (value, values) => react$1.cloneElement(
999
1102
  props.extendTypes[item.type].children,
1000
1103
  {
1104
+ scene: "table",
1001
1105
  value,
1002
1106
  values
1003
1107
  }
@@ -1014,56 +1118,70 @@ function Table(props) {
1014
1118
  item.render = (value) => processValue(item, value);
1015
1119
  if (!item.onFilter)
1016
1120
  item.onFilter = (value, row) => {
1017
- if (!row[item.id])
1121
+ if (!value || lodashEs.isNil(value))
1122
+ return true;
1123
+ if (lodashEs.isNil(row[item.id]))
1018
1124
  return false;
1019
- return row[item.id].toLowerCase().includes(value.toLowerCase());
1125
+ return row[item.id].trim().toLowerCase().includes(value.trim().toLowerCase());
1020
1126
  };
1021
- if (!item.filters && item.filterDropdown !== false && item.optionsType !== "auto")
1127
+ if (item.filterDropdown === false || item.filterDropdown)
1128
+ break;
1129
+ if (!item.filters && item.optionsType !== "auto")
1022
1130
  item.filterDropdown = ({
1023
1131
  setSelectedKeys,
1024
1132
  confirm,
1025
1133
  clearFilters
1026
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1027
- placeholder: `${common2.search} ${item.title}`,
1028
- allowClear: true,
1029
- onSearch: (v) => {
1030
- if (v) {
1031
- setSelectedKeys([v]);
1032
- } else {
1033
- setSelectedKeys([]);
1034
- clearFilters();
1134
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1135
+ antd.Input.Search,
1136
+ {
1137
+ placeholder: `${common2.search} ${item.title}`,
1138
+ allowClear: true,
1139
+ onSearch: (v) => {
1140
+ if (v) {
1141
+ setSelectedKeys([v]);
1142
+ } else {
1143
+ setSelectedKeys([]);
1144
+ clearFilters();
1145
+ }
1146
+ confirm();
1035
1147
  }
1036
- confirm();
1037
1148
  }
1038
- });
1149
+ );
1039
1150
  break;
1040
1151
  case "string[]":
1041
1152
  if (!item.render)
1042
1153
  item.render = (value) => processValue(item, value);
1043
1154
  if (!item.onFilter)
1044
1155
  item.onFilter = (value, row) => {
1045
- if (!row[item.id] || !row[item.id].length)
1156
+ if (value === null && (!row[item.id] || !row[item.id].length))
1157
+ return true;
1158
+ if (!row[item.id] || !row[item.id].length || !value)
1046
1159
  return false;
1047
- return row[item.id].some((v) => v.toLowerCase().includes(value.toLowerCase()));
1160
+ return row[item.id].some((v) => v.trim().toLowerCase().includes(value.trim().toLowerCase()));
1048
1161
  };
1049
- if (!item.filters && item.filterDropdown !== false)
1162
+ if (item.filterDropdown === false || item.filterDropdown)
1163
+ break;
1164
+ if (!item.filters && item.optionsType !== "auto")
1050
1165
  item.filterDropdown = ({
1051
1166
  setSelectedKeys,
1052
1167
  confirm,
1053
1168
  clearFilters
1054
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1055
- placeholder: `${common2.search} ${item.title}`,
1056
- allowClear: true,
1057
- onSearch: (v) => {
1058
- if (v) {
1059
- setSelectedKeys([v]);
1060
- } else {
1061
- setSelectedKeys([]);
1062
- clearFilters();
1169
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1170
+ antd.Input.Search,
1171
+ {
1172
+ placeholder: `${common2.search} ${item.title}`,
1173
+ allowClear: true,
1174
+ onSearch: (v) => {
1175
+ if (v) {
1176
+ setSelectedKeys([v]);
1177
+ } else {
1178
+ setSelectedKeys([]);
1179
+ clearFilters();
1180
+ }
1181
+ confirm();
1063
1182
  }
1064
- confirm();
1065
1183
  }
1066
- });
1184
+ );
1067
1185
  break;
1068
1186
  case "number":
1069
1187
  if (!item.render)
@@ -1071,288 +1189,452 @@ function Table(props) {
1071
1189
  if (!item.sorter)
1072
1190
  item.sorter = (a, b) => a[item.id] - b[item.id];
1073
1191
  if (!item.onFilter)
1074
- item.onFilter = (value, row) => value === row[item.id];
1075
- if (!item.filters && item.filterDropdown !== false)
1192
+ item.onFilter = (value, row) => {
1193
+ if (value === null)
1194
+ return true;
1195
+ if (lodashEs.isNil(row[item.id]))
1196
+ return false;
1197
+ return value == row[item.id];
1198
+ };
1199
+ if (item.filterDropdown === false || item.filterDropdown)
1200
+ break;
1201
+ if (!item.filters)
1076
1202
  item.filterDropdown = ({
1077
1203
  setSelectedKeys,
1078
1204
  confirm,
1079
1205
  clearFilters
1080
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1081
- placeholder: `${common2.search} ${item.title}`,
1082
- allowClear: true,
1083
- onSearch: (v) => {
1084
- if (v) {
1085
- setSelectedKeys([Number(v)]);
1086
- } else {
1087
- setSelectedKeys([]);
1088
- clearFilters();
1206
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1207
+ antd.Input.Search,
1208
+ {
1209
+ placeholder: `${common2.search} ${item.title}`,
1210
+ allowClear: true,
1211
+ onSearch: (v) => {
1212
+ if (v) {
1213
+ setSelectedKeys([Number(v)]);
1214
+ } else {
1215
+ setSelectedKeys([]);
1216
+ clearFilters();
1217
+ }
1218
+ confirm();
1089
1219
  }
1090
- confirm();
1091
1220
  }
1092
- });
1221
+ );
1093
1222
  break;
1094
1223
  case "number[]":
1095
1224
  if (!item.render)
1096
1225
  item.render = (value) => processValue(item, value).join(", ");
1097
1226
  if (!item.onFilter)
1098
- item.onFilter = (value, row) => row[item.id].includes(value);
1099
- if (!item.filters && item.filterDropdown !== false)
1227
+ item.onFilter = (value, row) => {
1228
+ if (value === null && (!row[item.id] || !row[item.id].length))
1229
+ return true;
1230
+ if (!row[item.id] || !row[item.id].length)
1231
+ return false;
1232
+ return row[item.id].includes(Number(value));
1233
+ };
1234
+ if (item.filterDropdown === false || item.filterDropdown)
1235
+ break;
1236
+ if (!item.filters)
1100
1237
  item.filterDropdown = ({
1101
1238
  setSelectedKeys,
1102
1239
  confirm,
1103
1240
  clearFilters
1104
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Input.Search, {
1105
- placeholder: `${common2.search} ${item.title}`,
1106
- allowClear: true,
1107
- onSearch: (v) => {
1108
- if (v) {
1109
- setSelectedKeys([Number(v)]);
1110
- } else {
1111
- setSelectedKeys([]);
1112
- clearFilters();
1241
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1242
+ antd.Input.Search,
1243
+ {
1244
+ placeholder: `${common2.search} ${item.title}`,
1245
+ allowClear: true,
1246
+ onSearch: (v) => {
1247
+ if (v) {
1248
+ setSelectedKeys([Number(v)]);
1249
+ } else {
1250
+ setSelectedKeys([]);
1251
+ clearFilters();
1252
+ }
1253
+ confirm();
1113
1254
  }
1114
- confirm();
1115
1255
  }
1116
- });
1256
+ );
1117
1257
  break;
1118
1258
  case "boolean":
1119
1259
  if (!item.render)
1120
- item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Blank, {}) : value ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CheckOutlined, {
1121
- style: {
1122
- marginTop: "4px",
1123
- color: "#52c41a"
1124
- }
1125
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CloseOutlined, {
1126
- style: {
1127
- marginTop: "4px",
1128
- color: "#ff4d4f"
1129
- }
1130
- });
1260
+ item.render = (value) => lodashEs.isNil(value) ? /* @__PURE__ */ jsxRuntime.jsx(Blank, {}) : value ? /* @__PURE__ */ jsxRuntime.jsx(icons.CheckOutlined, { style: {
1261
+ marginTop: "4px",
1262
+ color: "#52c41a"
1263
+ } }) : /* @__PURE__ */ jsxRuntime.jsx(icons.CloseOutlined, { style: {
1264
+ marginTop: "4px",
1265
+ color: "#ff4d4f"
1266
+ } });
1131
1267
  if (item.filterDropdown !== false)
1132
1268
  item.filterDropdown = ({
1133
1269
  setSelectedKeys,
1134
1270
  selectedKeys,
1135
1271
  confirm
1136
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd10.Radio.Group, {
1137
- style: { padding: 8 },
1138
- buttonStyle: "solid",
1139
- value: selectedKeys[0],
1140
- onChange: (e) => {
1141
- setSelectedKeys(e.target.value ? [e.target.value] : []);
1142
- confirm();
1143
- },
1144
- children: [
1145
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1146
- children: common2.all
1147
- }),
1148
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1149
- value: "true",
1150
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CheckOutlined, {
1151
- style: {
1152
- color: "#52c41a",
1153
- verticalAlign: "middle"
1154
- }
1155
- })
1156
- }),
1157
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1158
- value: "false",
1159
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons3.CloseOutlined, {
1160
- style: {
1161
- verticalAlign: "middle",
1162
- color: "#ff4d4f"
1163
- }
1164
- })
1165
- }),
1166
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Radio.Button, {
1167
- value: "empty",
1168
- children: common2.blank
1169
- })
1170
- ]
1171
- });
1272
+ }) => /* @__PURE__ */ jsxRuntime.jsxs(
1273
+ antd.Radio.Group,
1274
+ {
1275
+ style: { padding: 8 },
1276
+ buttonStyle: "solid",
1277
+ value: JSON.stringify(selectedKeys[0]),
1278
+ onChange: (e) => {
1279
+ const Values = {
1280
+ true: true,
1281
+ false: false,
1282
+ null: null
1283
+ };
1284
+ setSelectedKeys(e.target.value ? [Values[e.target.value]] : []);
1285
+ confirm();
1286
+ },
1287
+ children: [
1288
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { children: common2.all }),
1289
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { value: "true", children: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckOutlined, { style: {
1290
+ color: "#52c41a",
1291
+ verticalAlign: "middle"
1292
+ } }) }),
1293
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { value: "false", children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseOutlined, { style: {
1294
+ verticalAlign: "middle",
1295
+ color: "#ff4d4f"
1296
+ } }) }),
1297
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Radio.Button, { value: "null", children: common2.blank })
1298
+ ]
1299
+ }
1300
+ );
1172
1301
  if (!item.onFilter)
1173
1302
  item.onFilter = (value, row) => {
1174
1303
  switch (value) {
1175
- case "true":
1176
- return !(0, import_lodash6.isNil)(row[item.id]) && !!row[item.id];
1177
- case "false":
1178
- return !(0, import_lodash6.isNil)(row[item.id]) && !row[item.id];
1179
- case "empty":
1180
- return (0, import_lodash6.isNil)(row[item.id]);
1304
+ case true:
1305
+ return !lodashEs.isNil(row[item.id]) && row[item.id] !== false;
1306
+ case false:
1307
+ return !lodashEs.isNil(row[item.id]) && !row[item.id];
1181
1308
  default:
1182
- return true;
1309
+ return lodashEs.isNil(row[item.id]);
1183
1310
  }
1184
1311
  };
1185
1312
  break;
1186
1313
  case "date":
1187
1314
  if (!item.render)
1188
1315
  item.render = (value) => processValue(item, value);
1189
- if (!item.onFilter)
1190
- item.onFilter = (value, row) => (0, import_dayjs2.default)(row[item.id]).isSame((0, import_dayjs2.default)(value));
1191
1316
  if (!item.sorter)
1192
- item.sorter = (a, b) => (0, import_dayjs2.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1317
+ item.sorter = (a, b, order) => {
1318
+ if (lodashEs.isNil(a[item.id]))
1319
+ return order === "ascend" ? 1 : -1;
1320
+ if (lodashEs.isNil(b[item.id]))
1321
+ return order === "ascend" ? -1 : 1;
1322
+ return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
1323
+ };
1324
+ if (!item.filterDropdown)
1325
+ item.filterDropdown = ({
1326
+ setSelectedKeys,
1327
+ confirm
1328
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1329
+ antd.DatePicker.RangePicker,
1330
+ {
1331
+ onChange: (dates) => {
1332
+ setSelectedKeys(dates && dates[0] && dates[1] ? [[dates[0].startOf("day").toISOString(), dates[1].endOf("day").toISOString()]] : []);
1333
+ confirm();
1334
+ }
1335
+ }
1336
+ );
1337
+ if (!item.onFilter)
1338
+ item.onFilter = (value, row) => {
1339
+ if (lodashEs.isNil(value[0]))
1340
+ return true;
1341
+ if (lodashEs.isNil(row[item.id]))
1342
+ return false;
1343
+ return dayjs2__default.default(row[item.id]) >= dayjs2__default.default(value[0]) && dayjs2__default.default(row[item.id]) <= dayjs2__default.default(value[1]);
1344
+ };
1193
1345
  break;
1194
1346
  case "time":
1195
1347
  if (!item.render)
1196
1348
  item.render = (value) => processValue(item, value);
1197
- if (!item.onFilter)
1198
- item.onFilter = (value, row) => (0, import_dayjs2.default)(row[item.id]).isSame((0, import_dayjs2.default)(value));
1199
1349
  if (!item.sorter)
1200
- item.sorter = (a, b) => (0, import_dayjs2.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1350
+ item.sorter = (a, b, order) => {
1351
+ if (lodashEs.isNil(a[item.id]))
1352
+ return order === "ascend" ? 1 : -1;
1353
+ if (lodashEs.isNil(b[item.id]))
1354
+ return order === "ascend" ? -1 : 1;
1355
+ return new Date(a[item.id]).getTime() < new Date(b[item.id]).getTime() ? -1 : 1;
1356
+ };
1357
+ if (!item.filterDropdown)
1358
+ item.filterDropdown = ({
1359
+ setSelectedKeys,
1360
+ confirm
1361
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
1362
+ antd.DatePicker.RangePicker,
1363
+ {
1364
+ onChange: (dates) => {
1365
+ setSelectedKeys(dates && dates[0] && dates[1] ? [[dates[0].startOf("day").toISOString(), dates[1].endOf("day").toISOString()]] : []);
1366
+ confirm();
1367
+ }
1368
+ }
1369
+ );
1370
+ if (!item.onFilter)
1371
+ item.onFilter = (value, row) => {
1372
+ if (lodashEs.isNil(value[0]))
1373
+ return true;
1374
+ if (lodashEs.isNil(row[item.id]))
1375
+ return false;
1376
+ return dayjs2__default.default(row[item.id]) >= dayjs2__default.default(value[0]) && dayjs2__default.default(row[item.id]) <= dayjs2__default.default(value[1]);
1377
+ };
1201
1378
  break;
1202
1379
  case "object":
1203
1380
  if (!item.render)
1204
- item.render = (value) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
1205
- items: item.object,
1206
- dataSource: value || {},
1207
- column: 1
1208
- });
1381
+ item.render = (value) => /* @__PURE__ */ jsxRuntime.jsx(
1382
+ Description,
1383
+ {
1384
+ items: item.object,
1385
+ dataSource: value || {},
1386
+ column: 1
1387
+ }
1388
+ );
1209
1389
  break;
1210
1390
  case "object[]":
1211
1391
  if (!item.render)
1212
- item.render = (value) => value.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, {
1213
- items: item.object,
1214
- dataSource: v || [],
1215
- column: 1
1216
- }, i));
1392
+ item.render = (value) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value.map((v, i) => /* @__PURE__ */ jsxRuntime.jsx(
1393
+ Description,
1394
+ {
1395
+ items: item.object,
1396
+ dataSource: v || [],
1397
+ column: 1
1398
+ },
1399
+ i
1400
+ )) });
1217
1401
  break;
1218
1402
  default:
1219
1403
  if (!item.render)
1220
1404
  item.render = (value) => processValue(item, value);
1221
1405
  if (!item.onFilter)
1222
- item.onFilter = (value, row) => value === row[item.id];
1406
+ item.onFilter = (value, row) => {
1407
+ if (value === null && lodashEs.isNil(row[item.id]))
1408
+ return true;
1409
+ return value === row[item.id];
1410
+ };
1223
1411
  break;
1224
1412
  }
1225
1413
  }
1226
1414
  setColumns(props.items);
1227
- }, [props.items]);
1228
- (0, import_react11.useEffect)(() => {
1415
+ }, [JSON.stringify(props.items)]);
1416
+ react$1.useEffect(() => {
1229
1417
  if (!props.dataSource || !columns)
1230
1418
  return;
1231
1419
  for (const column of columns) {
1232
1420
  if (column.optionsType === "auto" && !column.options && !column.filters) {
1233
- setColumns((prev) => {
1234
- const newColumns = [...prev];
1235
- const index = newColumns.findIndex((item) => item.id === column.id);
1236
- newColumns[index].filters = (0, import_lodash6.uniqBy)(props.dataSource, column.id).map((v) => ({
1237
- text: v[column.id],
1238
- value: v[column.id]
1239
- }));
1240
- return newColumns;
1241
- });
1421
+ const options = lodashEs.uniqBy(props.dataSource, column.id).map((v) => ({
1422
+ label: v[column.id],
1423
+ value: v[column.id]
1424
+ }));
1425
+ if (options.length)
1426
+ setColumns((prev) => {
1427
+ const newColumns = [...prev];
1428
+ const index = newColumns.findIndex((item) => item.id === column.id);
1429
+ newColumns[index].options = options;
1430
+ generateFilterDropdown(newColumns[index]);
1431
+ return newColumns;
1432
+ });
1242
1433
  }
1243
1434
  }
1244
1435
  }, [props.dataSource, columns]);
1245
1436
  if (!columns)
1246
1437
  return null;
1247
- if (!props.faasData)
1248
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1249
- ...props,
1250
- rowKey: props.rowKey || "id",
1251
- columns,
1252
- dataSource: props.dataSource
1253
- });
1254
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react12.FaasDataWrapper, {
1255
- fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Skeleton, {
1256
- active: true
1257
- }),
1258
- render: ({
1259
- data,
1260
- params,
1261
- reload
1262
- }) => {
1263
- if (!data)
1264
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1265
- ...props,
1266
- rowKey: props.rowKey || "id",
1267
- columns,
1268
- dataSource: []
1269
- });
1270
- if (Array.isArray(data))
1271
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1272
- ...props,
1273
- rowKey: props.rowKey || "id",
1274
- columns,
1275
- dataSource: data
1276
- });
1277
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd10.Table, {
1438
+ if (props.dataSource)
1439
+ return /* @__PURE__ */ jsxRuntime.jsx(
1440
+ antd.Table,
1441
+ {
1278
1442
  ...props,
1279
1443
  rowKey: props.rowKey || "id",
1280
1444
  columns,
1281
- dataSource: data.rows,
1282
- pagination: {
1283
- ...props.pagination,
1284
- ...data.pagination
1285
- },
1286
- onChange: (pagination, filters, sorter, extra) => {
1287
- if (props.onChange) {
1288
- const processed = props.onChange(pagination, filters, sorter, extra);
1289
- reload({
1290
- ...params,
1291
- pagination: processed.pagination,
1292
- filters: processed.filters,
1293
- sorter: processed.sorter
1445
+ dataSource: props.dataSource
1446
+ }
1447
+ );
1448
+ return /* @__PURE__ */ jsxRuntime.jsx(
1449
+ FaasDataWrapper,
1450
+ {
1451
+ ...props.faasData,
1452
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1453
+ FaasDataTable,
1454
+ {
1455
+ props,
1456
+ columns
1457
+ }
1458
+ )
1459
+ }
1460
+ );
1461
+ }
1462
+ function FaasDataTable({
1463
+ props,
1464
+ columns,
1465
+ data,
1466
+ params,
1467
+ reload
1468
+ }) {
1469
+ const [currentColumns, setCurrentColumns] = react$1.useState(columns);
1470
+ react$1.useEffect(() => {
1471
+ if (!data || Array.isArray(data))
1472
+ return;
1473
+ setCurrentColumns((prev) => {
1474
+ const newColumns = [...prev];
1475
+ for (const column of newColumns) {
1476
+ if (data["options"] && data.options[column.id]) {
1477
+ column.options = data["options"][column.id];
1478
+ column.filters = data["options"][column.id].map((v) => ({
1479
+ text: v.label,
1480
+ value: v.value
1481
+ })).concat({
1482
+ text: /* @__PURE__ */ jsxRuntime.jsx(Blank, {}),
1483
+ value: null
1484
+ });
1485
+ column.render = (value) => processValue(column, value);
1486
+ if (column.filterDropdown)
1487
+ delete column.filterDropdown;
1488
+ continue;
1489
+ }
1490
+ if (column.optionsType === "auto" && !column.options && !column.filters) {
1491
+ const filters = lodashEs.uniqBy(props.dataSource, column.id).map((v) => ({
1492
+ text: v[column.id],
1493
+ value: v[column.id]
1494
+ }));
1495
+ if (filters.length)
1496
+ column.filters = filters.concat({
1497
+ text: /* @__PURE__ */ jsxRuntime.jsx(Blank, {}),
1498
+ value: null
1294
1499
  });
1295
- return;
1296
- }
1500
+ }
1501
+ }
1502
+ return newColumns;
1503
+ });
1504
+ }, [columns, data]);
1505
+ if (!data)
1506
+ return /* @__PURE__ */ jsxRuntime.jsx(
1507
+ antd.Table,
1508
+ {
1509
+ ...props,
1510
+ loading: props.loading,
1511
+ rowKey: props.rowKey || "id",
1512
+ columns: currentColumns,
1513
+ dataSource: []
1514
+ }
1515
+ );
1516
+ if (Array.isArray(data))
1517
+ return /* @__PURE__ */ jsxRuntime.jsx(
1518
+ antd.Table,
1519
+ {
1520
+ ...props,
1521
+ loading: props.loading,
1522
+ rowKey: props.rowKey || "id",
1523
+ columns: currentColumns,
1524
+ dataSource: data
1525
+ }
1526
+ );
1527
+ return /* @__PURE__ */ jsxRuntime.jsx(
1528
+ antd.Table,
1529
+ {
1530
+ ...props,
1531
+ loading: props.loading,
1532
+ rowKey: props.rowKey || "id",
1533
+ columns: currentColumns,
1534
+ dataSource: data.rows,
1535
+ pagination: {
1536
+ ...props.pagination,
1537
+ ...data.pagination
1538
+ },
1539
+ onChange: (pagination, filters, sorter, extra) => {
1540
+ if (props.onChange) {
1541
+ const processed = props.onChange(pagination, filters, sorter, extra);
1297
1542
  reload({
1298
1543
  ...params,
1299
- pagination,
1300
- filters,
1301
- sorter
1544
+ pagination: processed.pagination,
1545
+ filters: processed.filters,
1546
+ sorter: processed.sorter,
1547
+ extra: processed.extra
1302
1548
  });
1549
+ return;
1303
1550
  }
1304
- });
1305
- },
1306
- ...props.faasData
1307
- });
1551
+ reload({
1552
+ ...params,
1553
+ pagination,
1554
+ filters,
1555
+ sorter
1556
+ });
1557
+ }
1558
+ }
1559
+ );
1560
+ }
1561
+ function Tabs(props) {
1562
+ return /* @__PURE__ */ jsxRuntime.jsx(
1563
+ antd.Tabs,
1564
+ {
1565
+ ...props,
1566
+ items: props.items.filter(Boolean).map((i) => ({
1567
+ ...i,
1568
+ key: i.key || i.id,
1569
+ label: i.label || i.title || i.id
1570
+ }))
1571
+ }
1572
+ );
1308
1573
  }
1309
-
1310
- // src/Title.tsx
1311
- var import_react13 = require("react");
1312
- var import_jsx_runtime = require("react/jsx-runtime");
1313
1574
  function Title(props) {
1314
1575
  const { Title: Title2 } = useConfigContext();
1315
- (0, import_react13.useEffect)(() => {
1576
+ react$1.useEffect(() => {
1316
1577
  const title = Array.isArray(props.title) ? props.title : [props.title];
1317
1578
  document.title = title.concat(props.suffix || Title2.suffix).filter((t) => !!t).join(props.separator || Title2.separator);
1318
1579
  }, [props]);
1319
1580
  if (props.h1) {
1320
1581
  if (typeof props.h1 === "boolean")
1321
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
1582
+ return /* @__PURE__ */ jsxRuntime.jsx("h1", { children: Array.isArray(props.title) ? props.title[0] : props.title });
1583
+ return /* @__PURE__ */ jsxRuntime.jsx(
1584
+ "h1",
1585
+ {
1586
+ className: props.h1.className,
1587
+ style: props.h1.style,
1322
1588
  children: Array.isArray(props.title) ? props.title[0] : props.title
1323
- });
1324
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
1325
- className: props.h1.className,
1326
- style: props.h1.style,
1327
- children: Array.isArray(props.title) ? props.title[0] : props.title
1328
- });
1589
+ }
1590
+ );
1329
1591
  }
1330
1592
  if (props.plain)
1331
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
1332
- children: Array.isArray(props.title) ? props.title[0] : props.title
1333
- });
1593
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: Array.isArray(props.title) ? props.title[0] : props.title });
1334
1594
  if (props.children)
1335
- return (0, import_react13.cloneElement)(props.children, { title: props.title });
1595
+ return react$1.cloneElement(props.children, { title: props.title });
1336
1596
  return null;
1337
1597
  }
1338
- // Annotate the CommonJS export names for ESM import in node:
1339
- 0 && (module.exports = {
1340
- Blank,
1341
- ConfigContext,
1342
- ConfigProvider,
1343
- Description,
1344
- Drawer,
1345
- Form,
1346
- FormItem,
1347
- Link,
1348
- Modal,
1349
- PageNotFound,
1350
- Routes,
1351
- Table,
1352
- Title,
1353
- transferOptions,
1354
- transferValue,
1355
- useConfigContext,
1356
- useDrawer,
1357
- useModal
1598
+
1599
+ Object.defineProperty(exports, 'faas', {
1600
+ enumerable: true,
1601
+ get: function () { return react.faas; }
1602
+ });
1603
+ Object.defineProperty(exports, 'useFaas', {
1604
+ enumerable: true,
1605
+ get: function () { return react.useFaas; }
1606
+ });
1607
+ Object.defineProperty(exports, 'Drawer', {
1608
+ enumerable: true,
1609
+ get: function () { return antd.Drawer; }
1610
+ });
1611
+ Object.defineProperty(exports, 'Modal', {
1612
+ enumerable: true,
1613
+ get: function () { return antd.Modal; }
1614
+ });
1615
+ Object.defineProperty(exports, 'lazy', {
1616
+ enumerable: true,
1617
+ get: function () { return react$1.lazy; }
1358
1618
  });
1619
+ exports.App = App;
1620
+ exports.Blank = Blank;
1621
+ exports.ConfigContext = ConfigContext;
1622
+ exports.ConfigProvider = ConfigProvider2;
1623
+ exports.Description = Description;
1624
+ exports.ErrorBoundary = ErrorBoundary;
1625
+ exports.FaasDataWrapper = FaasDataWrapper;
1626
+ exports.Form = Form;
1627
+ exports.FormItem = FormItem;
1628
+ exports.Link = Link;
1629
+ exports.Loading = Loading;
1630
+ exports.PageNotFound = PageNotFound;
1631
+ exports.Routes = Routes;
1632
+ exports.Table = Table;
1633
+ exports.Tabs = Tabs;
1634
+ exports.Title = Title;
1635
+ exports.transferOptions = transferOptions;
1636
+ exports.transferValue = transferValue;
1637
+ exports.useApp = useApp;
1638
+ exports.useConfigContext = useConfigContext;
1639
+ exports.useDrawer = useDrawer;
1640
+ exports.useModal = useModal;