@faasjs/ant-design 0.0.3-beta.9 → 0.0.3-beta.90

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