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