@faasjs/ant-design 8.0.0-beta.14 → 8.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -40
- package/dist/index.cjs +75 -41
- package/dist/index.d.ts +82 -82
- package/dist/index.mjs +76 -43
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
1
|
# @faasjs/ant-design
|
|
2
2
|
|
|
3
|
-
UI components based on [FaasJS](https://faasjs.com), [Ant Design](https://ant.design) and [React Router](https://reactrouter.com).
|
|
4
|
-
|
|
5
|
-
[](https://github.com/faasjs/faasjs/blob/main/packages/ant-design/LICENSE)
|
|
6
|
-
[](https://www.npmjs.com/package/@faasjs/ant-design)
|
|
7
|
-
|
|
8
|
-
## Features
|
|
9
|
-
|
|
10
|
-
- [App](https://faasjs.com/doc/ant-design/functions/App.html) component with Ant Design & FaasJS.
|
|
11
|
-
- [UnionFaasItemElement](https://faasjs.com/doc/ant-design/type-aliases/UnionFaasItemElement.html) and [UnionFaasItemRender](https://faasjs.com/doc/ant-design/type-aliases/UnionFaasItemRender.html) for custom union rendering.
|
|
12
|
-
|
|
13
|
-
## Install
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
npm install @faasjs/ant-design
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
In `@faasjs/ant-design`, we use `FaasItemProps` to provide data structures for components.
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
type FaasItemType =
|
|
25
|
-
| 'string'
|
|
26
|
-
| 'string[]'
|
|
27
|
-
| 'number'
|
|
28
|
-
| 'number[]'
|
|
29
|
-
| 'boolean'
|
|
30
|
-
| 'date'
|
|
31
|
-
| 'time'
|
|
32
|
-
| 'object'
|
|
33
|
-
| 'object[]'
|
|
34
|
-
|
|
35
|
-
type FaasItemProps = {
|
|
36
|
-
type: FaasItemTypes
|
|
37
|
-
id: string
|
|
38
|
-
title?: string
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
3
|
## Functions
|
|
43
4
|
|
|
44
5
|
- [App](functions/App.md)
|
|
@@ -62,6 +23,7 @@ type FaasItemProps = {
|
|
|
62
23
|
- [Title](functions/Title.md)
|
|
63
24
|
- [transferOptions](functions/transferOptions.md)
|
|
64
25
|
- [transferValue](functions/transferValue.md)
|
|
26
|
+
- [useApp](functions/useApp.md)
|
|
65
27
|
- [useConfigContext](functions/useConfigContext.md)
|
|
66
28
|
- [useDrawer](functions/useDrawer.md)
|
|
67
29
|
- [useFaas](functions/useFaas.md)
|
|
@@ -124,5 +86,5 @@ type FaasItemProps = {
|
|
|
124
86
|
|
|
125
87
|
## Variables
|
|
126
88
|
|
|
89
|
+
- [AppContext](variables/AppContext.md)
|
|
127
90
|
- [ConfigContext](variables/ConfigContext.md)
|
|
128
|
-
- [useApp](variables/useApp.md)
|
package/dist/index.cjs
CHANGED
|
@@ -47,7 +47,7 @@ function Loading(props) {
|
|
|
47
47
|
if (props.loading === false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: props.children });
|
|
48
48
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
49
49
|
style: {
|
|
50
|
-
...props.style
|
|
50
|
+
...props.style,
|
|
51
51
|
...!props.size || props.size === "large" ? {
|
|
52
52
|
margin: "20vh auto",
|
|
53
53
|
textAlign: "center"
|
|
@@ -272,7 +272,7 @@ function useModal(init) {
|
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
274
|
//#endregion
|
|
275
|
-
//#region src/
|
|
275
|
+
//#region src/useApp.ts
|
|
276
276
|
const AppContext = (0, _faasjs_react.createSplittingContext)([
|
|
277
277
|
"message",
|
|
278
278
|
"notification",
|
|
@@ -281,6 +281,20 @@ const AppContext = (0, _faasjs_react.createSplittingContext)([
|
|
|
281
281
|
"drawerProps",
|
|
282
282
|
"setDrawerProps"
|
|
283
283
|
]);
|
|
284
|
+
/**
|
|
285
|
+
* Get app context.
|
|
286
|
+
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* import { useApp } from '@faasjs/ant-design'
|
|
289
|
+
*
|
|
290
|
+
* const { message, notification, setModalProps, setDrawerProps } = useApp()
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
function useApp() {
|
|
294
|
+
return AppContext.use();
|
|
295
|
+
}
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/App.tsx
|
|
284
298
|
function RoutesApp(props) {
|
|
285
299
|
const location = (0, react_router_dom.useLocation)();
|
|
286
300
|
const { drawerProps, setDrawerProps, modalProps, setModalProps } = useApp();
|
|
@@ -365,17 +379,6 @@ function App(props) {
|
|
|
365
379
|
})
|
|
366
380
|
});
|
|
367
381
|
}
|
|
368
|
-
/**
|
|
369
|
-
* Get app context.
|
|
370
|
-
*
|
|
371
|
-
* ```ts
|
|
372
|
-
* import { useApp } from '@faasjs/ant-design'
|
|
373
|
-
*
|
|
374
|
-
* const { message, notification, setModalProps, setDrawerProps } = useApp()
|
|
375
|
-
* ```
|
|
376
|
-
*/
|
|
377
|
-
const useApp = AppContext.use;
|
|
378
|
-
App.useApp = useApp;
|
|
379
382
|
//#endregion
|
|
380
383
|
//#region src/Blank.tsx
|
|
381
384
|
/**
|
|
@@ -470,7 +473,7 @@ function cloneUnionFaasItemElement(element, props) {
|
|
|
470
473
|
//#region src/Description.tsx
|
|
471
474
|
function DescriptionItemContent(props) {
|
|
472
475
|
const [computedProps, setComputedProps] = (0, react.useState)();
|
|
473
|
-
(0,
|
|
476
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
474
477
|
const propsCopy = { ...props };
|
|
475
478
|
propsCopy.item.title = propsCopy.item.title ?? idToTitle(propsCopy.item.id);
|
|
476
479
|
if (!propsCopy.item.type) propsCopy.item.type = "string";
|
|
@@ -651,7 +654,7 @@ function FormItem(props) {
|
|
|
651
654
|
const [extendTypes, setExtendTypes] = (0, react.useState)();
|
|
652
655
|
const { theme } = useConfigContext();
|
|
653
656
|
const [hidden, setHidden] = (0, react.useState)(props.hidden || false);
|
|
654
|
-
(0,
|
|
657
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
655
658
|
const { extendTypes, ...propsCopy } = { ...props };
|
|
656
659
|
if (extendTypes) setExtendTypes(extendTypes);
|
|
657
660
|
if (propsCopy.if) {
|
|
@@ -668,7 +671,11 @@ function FormItem(props) {
|
|
|
668
671
|
delete propsCopy.hidden;
|
|
669
672
|
}
|
|
670
673
|
setComputedProps(processProps(propsCopy, theme.common));
|
|
671
|
-
}, [
|
|
674
|
+
}, [
|
|
675
|
+
hidden,
|
|
676
|
+
props,
|
|
677
|
+
theme.common
|
|
678
|
+
]);
|
|
672
679
|
if (!computedProps) return null;
|
|
673
680
|
const itemType = computedProps.type ?? "string";
|
|
674
681
|
if (hidden) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Form.Item, {
|
|
@@ -900,19 +907,21 @@ function Form(props) {
|
|
|
900
907
|
const [extendTypes, setExtendTypes] = (0, react.useState)();
|
|
901
908
|
const [form] = antd.Form.useForm(props.form);
|
|
902
909
|
const [initialValues, setInitialValues] = (0, react.useState)(props.initialValues || Object.create(null));
|
|
903
|
-
(0,
|
|
910
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
904
911
|
const { submit, ...propsCopy } = {
|
|
905
912
|
...props,
|
|
906
913
|
form
|
|
907
914
|
};
|
|
915
|
+
let nextInitialValues = propsCopy.initialValues;
|
|
908
916
|
if (typeof submit !== "undefined") setSubmit(submit);
|
|
909
917
|
if (propsCopy.initialValues && propsCopy.items?.length) {
|
|
910
918
|
for (const key in propsCopy.initialValues) propsCopy.initialValues[key] = transferValue(propsCopy.items.find((item) => isFormItemProps(item) && item.id === key)?.type, propsCopy.initialValues[key]);
|
|
919
|
+
nextInitialValues = propsCopy.initialValues;
|
|
911
920
|
setInitialValues(propsCopy.initialValues);
|
|
912
921
|
delete propsCopy.initialValues;
|
|
913
922
|
}
|
|
914
923
|
if (propsCopy.items?.length) {
|
|
915
|
-
for (const item of propsCopy.items) if (isFormItemProps(item) && item.if) item.hidden = !item.if(
|
|
924
|
+
for (const item of propsCopy.items) if (isFormItemProps(item) && item.if) item.hidden = !item.if(nextInitialValues || Object.create(null));
|
|
916
925
|
}
|
|
917
926
|
const submitTo = typeof submit === "object" ? submit.to : void 0;
|
|
918
927
|
if (propsCopy.onFinish) {
|
|
@@ -951,7 +960,7 @@ function Form(props) {
|
|
|
951
960
|
delete propsCopy.extendTypes;
|
|
952
961
|
}
|
|
953
962
|
setComputedProps(propsCopy);
|
|
954
|
-
}, [props]);
|
|
963
|
+
}, [form, props]);
|
|
955
964
|
const onValuesChange = (0, _faasjs_react.useEqualCallback)((changedValues, allValues) => {
|
|
956
965
|
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
957
966
|
if (props.onValuesChange) props.onValuesChange(changedValues, allValues);
|
|
@@ -961,12 +970,12 @@ function Form(props) {
|
|
|
961
970
|
if (item?.onValueChange) item.onValueChange(changedValues[key], allValues, form);
|
|
962
971
|
}
|
|
963
972
|
}, [computedProps]);
|
|
964
|
-
(0,
|
|
973
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
965
974
|
if (!initialValues) return;
|
|
966
975
|
console.debug("Form:initialValues", initialValues);
|
|
967
976
|
form.setFieldsValue(initialValues);
|
|
968
977
|
setInitialValues(null);
|
|
969
|
-
}, [
|
|
978
|
+
}, [form, initialValues]);
|
|
970
979
|
if (!computedProps) return null;
|
|
971
980
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Form, {
|
|
972
981
|
...computedProps,
|
|
@@ -1017,7 +1026,7 @@ function Link(props) {
|
|
|
1017
1026
|
const navigate = (0, react_router_dom.useNavigate)();
|
|
1018
1027
|
const target = props.target || theme.Link?.target || (props.href.startsWith("http") ? "_blank" : void 0);
|
|
1019
1028
|
let computedStyle = {
|
|
1020
|
-
...theme.Link.style
|
|
1029
|
+
...theme.Link.style,
|
|
1021
1030
|
cursor: "pointer",
|
|
1022
1031
|
...props.style
|
|
1023
1032
|
};
|
|
@@ -1031,8 +1040,16 @@ function Link(props) {
|
|
|
1031
1040
|
...buttonProps,
|
|
1032
1041
|
style: computedStyle,
|
|
1033
1042
|
onClick: (e) => {
|
|
1034
|
-
props.onClick ? props.onClick(e) : target === "_blank" ? window.open(props.href) : navigate(props.href);
|
|
1035
1043
|
e.preventDefault();
|
|
1044
|
+
if (props.onClick) {
|
|
1045
|
+
props.onClick(e);
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
if (target === "_blank") {
|
|
1049
|
+
window.open(props.href);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
navigate(props.href);
|
|
1036
1053
|
},
|
|
1037
1054
|
children: props.children ?? props.text
|
|
1038
1055
|
});
|
|
@@ -1132,7 +1149,8 @@ function processValue(item, value) {
|
|
|
1132
1149
|
function Table(props) {
|
|
1133
1150
|
const [columns, setColumns] = (0, react.useState)();
|
|
1134
1151
|
const { theme } = useConfigContext();
|
|
1135
|
-
const
|
|
1152
|
+
const { all, blank, search } = theme.common;
|
|
1153
|
+
const generateFilterDropdown = (0, react.useCallback)((item) => {
|
|
1136
1154
|
if (item.filterDropdown && item.filterDropdown !== true) return;
|
|
1137
1155
|
if (!item.options?.length) return;
|
|
1138
1156
|
if (item.options.length < 11) {
|
|
@@ -1153,7 +1171,7 @@ function Table(props) {
|
|
|
1153
1171
|
allowClear: true,
|
|
1154
1172
|
showSearch: true,
|
|
1155
1173
|
style: { width: "100%" },
|
|
1156
|
-
placeholder: `${
|
|
1174
|
+
placeholder: `${search} ${item.title}`,
|
|
1157
1175
|
value: selectedKeys,
|
|
1158
1176
|
onChange: (v) => {
|
|
1159
1177
|
setSelectedKeys(v?.length ? v : []);
|
|
@@ -1161,18 +1179,19 @@ function Table(props) {
|
|
|
1161
1179
|
},
|
|
1162
1180
|
mode: "multiple",
|
|
1163
1181
|
filterOption: (input, option) => {
|
|
1164
|
-
if (!input || !option
|
|
1182
|
+
if (!input || !option) return true;
|
|
1183
|
+
if (typeof option.label !== "string") return option.value === input;
|
|
1165
1184
|
input = input.trim();
|
|
1166
|
-
return option.value === input || option.label.
|
|
1185
|
+
return option.value === input || option.label.toLowerCase().includes(input.toLowerCase());
|
|
1167
1186
|
}
|
|
1168
1187
|
})
|
|
1169
1188
|
});
|
|
1170
1189
|
return item;
|
|
1171
|
-
};
|
|
1172
|
-
(0,
|
|
1190
|
+
}, [search]);
|
|
1191
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
1173
1192
|
const items = (0, lodash_es.cloneDeep)(props.items).filter((item) => !(item.tableChildren === null || item.children === null || item.tableRender === null || item.render === null));
|
|
1174
1193
|
const createTextSearchFilterDropdown = (item, transformValue) => ({ setSelectedKeys, confirm, clearFilters }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Input.Search, {
|
|
1175
|
-
placeholder: `${
|
|
1194
|
+
placeholder: `${search} ${item.title}`,
|
|
1176
1195
|
allowClear: true,
|
|
1177
1196
|
onSearch: (v) => {
|
|
1178
1197
|
if (v) setSelectedKeys(transformValue ? [transformValue(v)] : [v]);
|
|
@@ -1270,7 +1289,7 @@ function Table(props) {
|
|
|
1270
1289
|
}
|
|
1271
1290
|
break;
|
|
1272
1291
|
case "number[]":
|
|
1273
|
-
if (!item.render) item.render = (value) => processValue(item, value)
|
|
1292
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1274
1293
|
if (item.filterDropdown !== false) {
|
|
1275
1294
|
if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
|
|
1276
1295
|
if (value === null && (!row[item.id] || !row[item.id].length)) return true;
|
|
@@ -1289,7 +1308,7 @@ function Table(props) {
|
|
|
1289
1308
|
color: "#ff4d4f"
|
|
1290
1309
|
} });
|
|
1291
1310
|
if (item.filterDropdown !== false) {
|
|
1292
|
-
if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Radio.Group, {
|
|
1311
|
+
if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm: confirmFilter }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(antd.Radio.Group, {
|
|
1293
1312
|
style: { padding: 8 },
|
|
1294
1313
|
buttonStyle: "solid",
|
|
1295
1314
|
value: JSON.stringify(selectedKeys[0]),
|
|
@@ -1299,10 +1318,10 @@ function Table(props) {
|
|
|
1299
1318
|
false: false,
|
|
1300
1319
|
null: null
|
|
1301
1320
|
}[e.target.value]] : []);
|
|
1302
|
-
|
|
1321
|
+
confirmFilter();
|
|
1303
1322
|
},
|
|
1304
1323
|
children: [
|
|
1305
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, { children:
|
|
1324
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, { children: all }),
|
|
1306
1325
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, {
|
|
1307
1326
|
value: "true",
|
|
1308
1327
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_ant_design_icons.CheckOutlined, { style: {
|
|
@@ -1319,7 +1338,7 @@ function Table(props) {
|
|
|
1319
1338
|
}),
|
|
1320
1339
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Radio.Button, {
|
|
1321
1340
|
value: "null",
|
|
1322
|
-
children:
|
|
1341
|
+
children: blank
|
|
1323
1342
|
})
|
|
1324
1343
|
]
|
|
1325
1344
|
});
|
|
@@ -1343,7 +1362,9 @@ function Table(props) {
|
|
|
1343
1362
|
};
|
|
1344
1363
|
if (item.filterDropdown !== false) {
|
|
1345
1364
|
if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.DatePicker.RangePicker, { onChange: (dates) => {
|
|
1346
|
-
|
|
1365
|
+
const start = dates?.[0];
|
|
1366
|
+
const end = dates?.[1];
|
|
1367
|
+
setSelectedKeys(start && end ? [[start.startOf("day").toISOString(), end.endOf("day").toISOString()]] : []);
|
|
1347
1368
|
confirm();
|
|
1348
1369
|
} });
|
|
1349
1370
|
if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
|
|
@@ -1377,8 +1398,16 @@ function Table(props) {
|
|
|
1377
1398
|
}
|
|
1378
1399
|
}
|
|
1379
1400
|
setColumns(items);
|
|
1380
|
-
}, [
|
|
1381
|
-
|
|
1401
|
+
}, [
|
|
1402
|
+
all,
|
|
1403
|
+
blank,
|
|
1404
|
+
generateFilterDropdown,
|
|
1405
|
+
props.extendTypes,
|
|
1406
|
+
props.faasData,
|
|
1407
|
+
props.items,
|
|
1408
|
+
search
|
|
1409
|
+
]);
|
|
1410
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
1382
1411
|
if (!props.dataSource || !columns) return;
|
|
1383
1412
|
for (const column of columns) if (column.optionsType === "auto" && !column.options && !column.filters) {
|
|
1384
1413
|
const options = (0, lodash_es.uniqBy)(props.dataSource, column.id).map((v) => ({
|
|
@@ -1394,7 +1423,11 @@ function Table(props) {
|
|
|
1394
1423
|
return newColumns;
|
|
1395
1424
|
});
|
|
1396
1425
|
}
|
|
1397
|
-
}, [
|
|
1426
|
+
}, [
|
|
1427
|
+
props.dataSource,
|
|
1428
|
+
columns,
|
|
1429
|
+
generateFilterDropdown
|
|
1430
|
+
]);
|
|
1398
1431
|
if (!columns) return null;
|
|
1399
1432
|
if (props.dataSource) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(antd.Table, {
|
|
1400
1433
|
...props,
|
|
@@ -1416,7 +1449,7 @@ function Table(props) {
|
|
|
1416
1449
|
}
|
|
1417
1450
|
function FaasDataTable({ props, columns, data, params, reload, loading }) {
|
|
1418
1451
|
const [currentColumns, setCurrentColumns] = (0, react.useState)(columns);
|
|
1419
|
-
(0,
|
|
1452
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
1420
1453
|
if (!data || Array.isArray(data)) return;
|
|
1421
1454
|
setCurrentColumns((prev) => {
|
|
1422
1455
|
const newColumns = [...prev];
|
|
@@ -1553,7 +1586,7 @@ function Tabs(props) {
|
|
|
1553
1586
|
*/
|
|
1554
1587
|
function Title(props) {
|
|
1555
1588
|
const { theme } = useConfigContext();
|
|
1556
|
-
(0,
|
|
1589
|
+
(0, _faasjs_react.useEqualEffect)(() => {
|
|
1557
1590
|
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
1558
1591
|
document.title = title.concat(props.suffix || theme.Title.suffix).filter((t) => !!t).join(props.separator || theme.Title.separator);
|
|
1559
1592
|
}, [props, theme.Title]);
|
|
@@ -1584,6 +1617,7 @@ function useThemeToken() {
|
|
|
1584
1617
|
}
|
|
1585
1618
|
//#endregion
|
|
1586
1619
|
exports.App = App;
|
|
1620
|
+
exports.AppContext = AppContext;
|
|
1587
1621
|
exports.Blank = Blank;
|
|
1588
1622
|
exports.ConfigContext = ConfigContext;
|
|
1589
1623
|
exports.ConfigProvider = ConfigProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
2
|
import { ButtonProps, ConfigProviderProps as ConfigProviderProps$1, DatePickerProps, DescriptionsProps, Drawer, DrawerProps as DrawerProps$1, FormInstance, FormItemProps as FormItemProps$1, FormProps as FormProps$1, GlobalToken, InputNumberProps, InputProps, Modal, ModalProps as ModalProps$1, RadioProps, SelectProps, SwitchProps, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1, TabsProps as TabsProps$1 } from "antd";
|
|
3
3
|
import { BrowserRouterProps, RouteProps } from "react-router-dom";
|
|
4
4
|
import * as react from "react";
|
|
5
5
|
import { CSSProperties, ComponentType, Dispatch, FC, JSX, LazyExoticComponent, ReactElement, ReactNode, SetStateAction, lazy } from "react";
|
|
6
|
-
import
|
|
6
|
+
import { ErrorBoundaryProps, FaasDataInjection as FaasDataInjection$1, FaasDataWrapperProps as FaasDataWrapperProps$1, FaasDataWrapperRef, FaasReactClient, FaasReactClientOptions, faas, useFaas } from "@faasjs/react";
|
|
7
7
|
import { Dayjs } from "dayjs";
|
|
8
|
-
import { MessageInstance } from "antd/es/message/interface";
|
|
9
|
-
import { NotificationInstance } from "antd/es/notification/interface";
|
|
10
8
|
import * as antd_es_form_FormItem0 from "antd/es/form/FormItem";
|
|
11
9
|
import * as antd_es_form0 from "antd/es/form";
|
|
12
10
|
import { RuleObject } from "antd/es/form";
|
|
@@ -16,6 +14,8 @@ import * as antd_es_form_hooks_useFormInstance0 from "antd/es/form/hooks/useForm
|
|
|
16
14
|
import * as _rc_component_form0 from "@rc-component/form";
|
|
17
15
|
import * as antd_es_form_context0 from "antd/es/form/context";
|
|
18
16
|
import { Tab } from "@rc-component/tabs/lib/interface";
|
|
17
|
+
import { MessageInstance } from "antd/es/message/interface";
|
|
18
|
+
import { NotificationInstance } from "antd/es/notification/interface";
|
|
19
19
|
|
|
20
20
|
//#region ../types/src/index.d.ts
|
|
21
21
|
/**
|
|
@@ -53,7 +53,7 @@ type FaasActionPaths = Exclude<Extract<keyof FaasActions, string>, 'faasjsAction
|
|
|
53
53
|
/**
|
|
54
54
|
* Union type accepted by action helpers.
|
|
55
55
|
*/
|
|
56
|
-
type FaasActionUnionType =
|
|
56
|
+
type FaasActionUnionType = Record<string, any> | string;
|
|
57
57
|
/**
|
|
58
58
|
* Infer the action path type.
|
|
59
59
|
*
|
|
@@ -206,64 +206,12 @@ declare const ConfigContext: react.Context<ConfigContextValue>;
|
|
|
206
206
|
declare function ConfigProvider(props: ConfigProviderProps): react_jsx_runtime0.JSX.Element | null;
|
|
207
207
|
declare function useConfigContext(): ConfigContextValue;
|
|
208
208
|
//#endregion
|
|
209
|
-
//#region src/Drawer.d.ts
|
|
210
|
-
interface DrawerProps extends DrawerProps$1 {
|
|
211
|
-
children?: JSX.Element | JSX.Element[];
|
|
212
|
-
}
|
|
213
|
-
type setDrawerProps = Dispatch<SetStateAction<DrawerProps>>;
|
|
214
|
-
/**
|
|
215
|
-
* Hook style drawer
|
|
216
|
-
*
|
|
217
|
-
* ```tsx
|
|
218
|
-
* function Example() {
|
|
219
|
-
* const { drawer, setDrawerProps } = useDrawer()
|
|
220
|
-
*
|
|
221
|
-
* return <>
|
|
222
|
-
* <Button onClick={ () => setDrawerProps(prev => ({ open: !prev.open})) }>
|
|
223
|
-
* Toggle
|
|
224
|
-
* </Button>
|
|
225
|
-
* {drawer}
|
|
226
|
-
* </>
|
|
227
|
-
* }
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
declare function useDrawer(init?: DrawerProps): {
|
|
231
|
-
drawer: react_jsx_runtime0.JSX.Element;
|
|
232
|
-
drawerProps: DrawerProps;
|
|
233
|
-
setDrawerProps: setDrawerProps;
|
|
234
|
-
};
|
|
235
|
-
//#endregion
|
|
236
209
|
//#region src/ErrorBoundary.d.ts
|
|
237
210
|
/**
|
|
238
211
|
* Styled error boundary.
|
|
239
212
|
*/
|
|
240
213
|
declare function ErrorBoundary(props: ErrorBoundaryProps): react_jsx_runtime0.JSX.Element;
|
|
241
214
|
//#endregion
|
|
242
|
-
//#region src/Modal.d.ts
|
|
243
|
-
interface ModalProps extends ModalProps$1 {
|
|
244
|
-
children?: JSX.Element | JSX.Element[] | string;
|
|
245
|
-
}
|
|
246
|
-
type setModalProps = Dispatch<SetStateAction<ModalProps>>;
|
|
247
|
-
/**
|
|
248
|
-
* Hook style modal
|
|
249
|
-
*
|
|
250
|
-
* ```tsx
|
|
251
|
-
* function Example() {
|
|
252
|
-
* const { modal, setModalProps } = useModal()
|
|
253
|
-
*
|
|
254
|
-
* return <>
|
|
255
|
-
* <Button onClick={() => setModalProps({ open: true })}>Open Modal</Button>
|
|
256
|
-
* {modal}
|
|
257
|
-
* </>
|
|
258
|
-
* }
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
declare function useModal(init?: ModalProps): {
|
|
262
|
-
modal: react_jsx_runtime0.JSX.Element;
|
|
263
|
-
modalProps: ModalProps;
|
|
264
|
-
setModalProps: setModalProps;
|
|
265
|
-
};
|
|
266
|
-
//#endregion
|
|
267
215
|
//#region src/App.d.ts
|
|
268
216
|
interface AppProps {
|
|
269
217
|
children: React.ReactNode;
|
|
@@ -282,14 +230,6 @@ interface AppProps {
|
|
|
282
230
|
/** @see https://faasjs.com/doc/ant-design/#configprovider */
|
|
283
231
|
faasConfigProviderProps?: Omit<ConfigProviderProps, 'children'> | false;
|
|
284
232
|
}
|
|
285
|
-
interface useAppProps {
|
|
286
|
-
message: MessageInstance;
|
|
287
|
-
notification: NotificationInstance;
|
|
288
|
-
modalProps: ModalProps;
|
|
289
|
-
setModalProps: setModalProps;
|
|
290
|
-
drawerProps: DrawerProps;
|
|
291
|
-
setDrawerProps: setDrawerProps;
|
|
292
|
-
}
|
|
293
233
|
/**
|
|
294
234
|
* App component with Ant Design & FaasJS
|
|
295
235
|
*
|
|
@@ -318,19 +258,6 @@ interface useAppProps {
|
|
|
318
258
|
* ```
|
|
319
259
|
*/
|
|
320
260
|
declare function App(props: AppProps): react_jsx_runtime0.JSX.Element;
|
|
321
|
-
declare namespace App {
|
|
322
|
-
var useApp: <NewT extends useAppProps = useAppProps>() => Readonly<NewT>;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Get app context.
|
|
326
|
-
*
|
|
327
|
-
* ```ts
|
|
328
|
-
* import { useApp } from '@faasjs/ant-design'
|
|
329
|
-
*
|
|
330
|
-
* const { message, notification, setModalProps, setDrawerProps } = useApp()
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
declare const useApp: <NewT extends useAppProps = useAppProps>() => Readonly<NewT>;
|
|
334
261
|
//#endregion
|
|
335
262
|
//#region src/Blank.d.ts
|
|
336
263
|
interface BlankProps {
|
|
@@ -576,7 +503,7 @@ type UnionFaasItemInjection<Value = any, Values = any> = {
|
|
|
576
503
|
* @param value - The value of the current item.
|
|
577
504
|
* @param values - The entire list of values.
|
|
578
505
|
* @param index - The index of the current item in the list.
|
|
579
|
-
* @param scene
|
|
506
|
+
* @param scene - The scene in which the rendering is taking place. See {@link UnionScene}.
|
|
580
507
|
*
|
|
581
508
|
* @example
|
|
582
509
|
* ```tsx
|
|
@@ -747,7 +674,7 @@ interface DescriptionItemProps<T = any> extends FaasItemProps {
|
|
|
747
674
|
object?: DescriptionItemProps<T>[];
|
|
748
675
|
}
|
|
749
676
|
interface DescriptionProps<T = any, ExtendItemProps = any> extends Omit<DescriptionsProps, 'items'> {
|
|
750
|
-
renderTitle?(values: T): ReactNode;
|
|
677
|
+
renderTitle?(this: void, values: T): ReactNode;
|
|
751
678
|
items: (DescriptionItemProps | ExtendItemProps)[];
|
|
752
679
|
extendTypes?: {
|
|
753
680
|
[key: string]: ExtendDescriptionTypeProps;
|
|
@@ -796,6 +723,33 @@ declare namespace Description {
|
|
|
796
723
|
var displayName: string;
|
|
797
724
|
}
|
|
798
725
|
//#endregion
|
|
726
|
+
//#region src/Drawer.d.ts
|
|
727
|
+
interface DrawerProps extends DrawerProps$1 {
|
|
728
|
+
children?: JSX.Element | JSX.Element[];
|
|
729
|
+
}
|
|
730
|
+
type setDrawerProps = Dispatch<SetStateAction<DrawerProps>>;
|
|
731
|
+
/**
|
|
732
|
+
* Hook style drawer
|
|
733
|
+
*
|
|
734
|
+
* ```tsx
|
|
735
|
+
* function Example() {
|
|
736
|
+
* const { drawer, setDrawerProps } = useDrawer()
|
|
737
|
+
*
|
|
738
|
+
* return <>
|
|
739
|
+
* <Button onClick={ () => setDrawerProps(prev => ({ open: !prev.open})) }>
|
|
740
|
+
* Toggle
|
|
741
|
+
* </Button>
|
|
742
|
+
* {drawer}
|
|
743
|
+
* </>
|
|
744
|
+
* }
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
declare function useDrawer(init?: DrawerProps): {
|
|
748
|
+
drawer: react_jsx_runtime0.JSX.Element;
|
|
749
|
+
drawerProps: DrawerProps;
|
|
750
|
+
setDrawerProps: setDrawerProps;
|
|
751
|
+
};
|
|
752
|
+
//#endregion
|
|
799
753
|
//#region src/Form.d.ts
|
|
800
754
|
type FormSubmitProps = {
|
|
801
755
|
/** Default: Submit */text?: string;
|
|
@@ -825,7 +779,7 @@ type FormSubmitProps = {
|
|
|
825
779
|
* ```
|
|
826
780
|
*/
|
|
827
781
|
to?: {
|
|
828
|
-
action: FaasAction
|
|
782
|
+
action: FaasAction; /** params will overwrite form values before submit */
|
|
829
783
|
params?: Record<string, any>;
|
|
830
784
|
then?: (result: any) => void;
|
|
831
785
|
catch?: (error: any) => void;
|
|
@@ -886,6 +840,31 @@ interface LinkProps {
|
|
|
886
840
|
*/
|
|
887
841
|
declare function Link(props: LinkProps): react_jsx_runtime0.JSX.Element;
|
|
888
842
|
//#endregion
|
|
843
|
+
//#region src/Modal.d.ts
|
|
844
|
+
interface ModalProps extends ModalProps$1 {
|
|
845
|
+
children?: JSX.Element | JSX.Element[] | string;
|
|
846
|
+
}
|
|
847
|
+
type setModalProps = Dispatch<SetStateAction<ModalProps>>;
|
|
848
|
+
/**
|
|
849
|
+
* Hook style modal
|
|
850
|
+
*
|
|
851
|
+
* ```tsx
|
|
852
|
+
* function Example() {
|
|
853
|
+
* const { modal, setModalProps } = useModal()
|
|
854
|
+
*
|
|
855
|
+
* return <>
|
|
856
|
+
* <Button onClick={() => setModalProps({ open: true })}>Open Modal</Button>
|
|
857
|
+
* {modal}
|
|
858
|
+
* </>
|
|
859
|
+
* }
|
|
860
|
+
* ```
|
|
861
|
+
*/
|
|
862
|
+
declare function useModal(init?: ModalProps): {
|
|
863
|
+
modal: react_jsx_runtime0.JSX.Element;
|
|
864
|
+
modalProps: ModalProps;
|
|
865
|
+
setModalProps: setModalProps;
|
|
866
|
+
};
|
|
867
|
+
//#endregion
|
|
889
868
|
//#region src/Routers.d.ts
|
|
890
869
|
declare function PageNotFound(): react_jsx_runtime0.JSX.Element;
|
|
891
870
|
interface RoutesProps {
|
|
@@ -990,6 +969,27 @@ interface TitleProps {
|
|
|
990
969
|
*/
|
|
991
970
|
declare function Title(props: TitleProps): JSX.Element | null;
|
|
992
971
|
//#endregion
|
|
972
|
+
//#region src/useApp.d.ts
|
|
973
|
+
interface useAppProps {
|
|
974
|
+
message: MessageInstance;
|
|
975
|
+
notification: NotificationInstance;
|
|
976
|
+
modalProps: ModalProps;
|
|
977
|
+
setModalProps: setModalProps;
|
|
978
|
+
drawerProps: DrawerProps;
|
|
979
|
+
setDrawerProps: setDrawerProps;
|
|
980
|
+
}
|
|
981
|
+
declare const AppContext: any;
|
|
982
|
+
/**
|
|
983
|
+
* Get app context.
|
|
984
|
+
*
|
|
985
|
+
* ```ts
|
|
986
|
+
* import { useApp } from '@faasjs/ant-design'
|
|
987
|
+
*
|
|
988
|
+
* const { message, notification, setModalProps, setDrawerProps } = useApp()
|
|
989
|
+
* ```
|
|
990
|
+
*/
|
|
991
|
+
declare function useApp<NewT extends useAppProps = useAppProps>(this: void): Readonly<NewT>;
|
|
992
|
+
//#endregion
|
|
993
993
|
//#region src/useThemeToken.d.ts
|
|
994
994
|
/**
|
|
995
995
|
* Hook to retrieve the theme token from the Ant Design theme configuration.
|
|
@@ -1001,4 +1001,4 @@ declare function Title(props: TitleProps): JSX.Element | null;
|
|
|
1001
1001
|
*/
|
|
1002
1002
|
declare function useThemeToken(): GlobalToken;
|
|
1003
1003
|
//#endregion
|
|
1004
|
-
export { App, AppProps, BaseItemProps, BaseOption, Blank, BlankProps, ConfigContext, ConfigProvider, ConfigProviderProps, Description, DescriptionItemContentProps, DescriptionItemProps, DescriptionProps, Drawer, DrawerProps, ErrorBoundary, type ErrorBoundaryProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, type FaasDataWrapperRef, FaasItemProps, FaasItemType, FaasItemTypeValue, FaasReactClient, type FaasReactClientOptions, Form, FormItem, FormItemProps, FormProps, FormSubmitProps, Link, LinkProps, Loading, LoadingProps, Modal, ModalProps, PageNotFound, ResolvedTheme, Routes, RoutesProps, TabProps, Table, TableFaasDataParams, TableFaasDataResponse, TableItemProps, TableProps, Tabs, TabsProps, Title, TitleProps, UnionFaasItemElement, UnionFaasItemInjection, UnionFaasItemProps, UnionFaasItemRender, UnionScene, cloneUnionFaasItemElement, faas, idToTitle, lazy, setDrawerProps, setModalProps, transferOptions, transferValue, useApp, useAppProps, useConfigContext, useDrawer, useFaas, useModal, useThemeToken, withFaasData };
|
|
1004
|
+
export { App, AppContext, AppProps, BaseItemProps, BaseOption, Blank, BlankProps, ConfigContext, ConfigProvider, ConfigProviderProps, Description, DescriptionItemContentProps, DescriptionItemProps, DescriptionProps, Drawer, DrawerProps, ErrorBoundary, type ErrorBoundaryProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, type FaasDataWrapperRef, FaasItemProps, FaasItemType, FaasItemTypeValue, FaasReactClient, type FaasReactClientOptions, Form, FormItem, FormItemProps, FormProps, FormSubmitProps, Link, LinkProps, Loading, LoadingProps, Modal, ModalProps, PageNotFound, ResolvedTheme, Routes, RoutesProps, TabProps, Table, TableFaasDataParams, TableFaasDataResponse, TableItemProps, TableProps, Tabs, TabsProps, Title, TitleProps, UnionFaasItemElement, UnionFaasItemInjection, UnionFaasItemProps, UnionFaasItemRender, UnionScene, cloneUnionFaasItemElement, faas, idToTitle, lazy, setDrawerProps, setModalProps, transferOptions, transferValue, useApp, useAppProps, useConfigContext, useDrawer, useFaas, useModal, useThemeToken, withFaasData };
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { ErrorBoundary as ErrorBoundary$1, FaasDataWrapper as FaasDataWrapper$1,
|
|
|
2
2
|
import { Alert, Button, Col, ConfigProvider as ConfigProvider$1, DatePicker, Descriptions, Drawer, Form as Form$1, Input, InputNumber, Modal, Radio, Result, Row, Select, Skeleton, Space, Spin, Switch, Table as Table$1, Tabs as Tabs$1, Typography, message, notification, theme } from "antd";
|
|
3
3
|
import { BrowserRouter, Route, Routes as Routes$1, useLocation, useNavigate } from "react-router-dom";
|
|
4
4
|
import { cloneDeep, defaultsDeep, isNil, uniqBy } from "lodash-es";
|
|
5
|
-
import { Suspense, cloneElement, createContext, createElement, isValidElement, lazy,
|
|
5
|
+
import { Suspense, cloneElement, createContext, createElement, isValidElement, lazy, useCallback, useContext, useState } from "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { CheckOutlined, CloseOutlined, MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
|
8
8
|
import dayjs from "dayjs";
|
|
@@ -23,7 +23,7 @@ function Loading(props) {
|
|
|
23
23
|
if (props.loading === false) return /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
24
24
|
return /* @__PURE__ */ jsx("div", {
|
|
25
25
|
style: {
|
|
26
|
-
...props.style
|
|
26
|
+
...props.style,
|
|
27
27
|
...!props.size || props.size === "large" ? {
|
|
28
28
|
margin: "20vh auto",
|
|
29
29
|
textAlign: "center"
|
|
@@ -248,7 +248,7 @@ function useModal(init) {
|
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
250
|
//#endregion
|
|
251
|
-
//#region src/
|
|
251
|
+
//#region src/useApp.ts
|
|
252
252
|
const AppContext = createSplittingContext([
|
|
253
253
|
"message",
|
|
254
254
|
"notification",
|
|
@@ -257,6 +257,20 @@ const AppContext = createSplittingContext([
|
|
|
257
257
|
"drawerProps",
|
|
258
258
|
"setDrawerProps"
|
|
259
259
|
]);
|
|
260
|
+
/**
|
|
261
|
+
* Get app context.
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* import { useApp } from '@faasjs/ant-design'
|
|
265
|
+
*
|
|
266
|
+
* const { message, notification, setModalProps, setDrawerProps } = useApp()
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
function useApp() {
|
|
270
|
+
return AppContext.use();
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/App.tsx
|
|
260
274
|
function RoutesApp(props) {
|
|
261
275
|
const location = useLocation();
|
|
262
276
|
const { drawerProps, setDrawerProps, modalProps, setModalProps } = useApp();
|
|
@@ -341,17 +355,6 @@ function App(props) {
|
|
|
341
355
|
})
|
|
342
356
|
});
|
|
343
357
|
}
|
|
344
|
-
/**
|
|
345
|
-
* Get app context.
|
|
346
|
-
*
|
|
347
|
-
* ```ts
|
|
348
|
-
* import { useApp } from '@faasjs/ant-design'
|
|
349
|
-
*
|
|
350
|
-
* const { message, notification, setModalProps, setDrawerProps } = useApp()
|
|
351
|
-
* ```
|
|
352
|
-
*/
|
|
353
|
-
const useApp = AppContext.use;
|
|
354
|
-
App.useApp = useApp;
|
|
355
358
|
//#endregion
|
|
356
359
|
//#region src/Blank.tsx
|
|
357
360
|
/**
|
|
@@ -446,7 +449,7 @@ function cloneUnionFaasItemElement(element, props) {
|
|
|
446
449
|
//#region src/Description.tsx
|
|
447
450
|
function DescriptionItemContent(props) {
|
|
448
451
|
const [computedProps, setComputedProps] = useState();
|
|
449
|
-
|
|
452
|
+
useEqualEffect(() => {
|
|
450
453
|
const propsCopy = { ...props };
|
|
451
454
|
propsCopy.item.title = propsCopy.item.title ?? idToTitle(propsCopy.item.id);
|
|
452
455
|
if (!propsCopy.item.type) propsCopy.item.type = "string";
|
|
@@ -627,7 +630,7 @@ function FormItem(props) {
|
|
|
627
630
|
const [extendTypes, setExtendTypes] = useState();
|
|
628
631
|
const { theme } = useConfigContext();
|
|
629
632
|
const [hidden, setHidden] = useState(props.hidden || false);
|
|
630
|
-
|
|
633
|
+
useEqualEffect(() => {
|
|
631
634
|
const { extendTypes, ...propsCopy } = { ...props };
|
|
632
635
|
if (extendTypes) setExtendTypes(extendTypes);
|
|
633
636
|
if (propsCopy.if) {
|
|
@@ -644,7 +647,11 @@ function FormItem(props) {
|
|
|
644
647
|
delete propsCopy.hidden;
|
|
645
648
|
}
|
|
646
649
|
setComputedProps(processProps(propsCopy, theme.common));
|
|
647
|
-
}, [
|
|
650
|
+
}, [
|
|
651
|
+
hidden,
|
|
652
|
+
props,
|
|
653
|
+
theme.common
|
|
654
|
+
]);
|
|
648
655
|
if (!computedProps) return null;
|
|
649
656
|
const itemType = computedProps.type ?? "string";
|
|
650
657
|
if (hidden) return /* @__PURE__ */ jsx(Form$1.Item, {
|
|
@@ -876,19 +883,21 @@ function Form(props) {
|
|
|
876
883
|
const [extendTypes, setExtendTypes] = useState();
|
|
877
884
|
const [form] = Form$1.useForm(props.form);
|
|
878
885
|
const [initialValues, setInitialValues] = useState(props.initialValues || Object.create(null));
|
|
879
|
-
|
|
886
|
+
useEqualEffect(() => {
|
|
880
887
|
const { submit, ...propsCopy } = {
|
|
881
888
|
...props,
|
|
882
889
|
form
|
|
883
890
|
};
|
|
891
|
+
let nextInitialValues = propsCopy.initialValues;
|
|
884
892
|
if (typeof submit !== "undefined") setSubmit(submit);
|
|
885
893
|
if (propsCopy.initialValues && propsCopy.items?.length) {
|
|
886
894
|
for (const key in propsCopy.initialValues) propsCopy.initialValues[key] = transferValue(propsCopy.items.find((item) => isFormItemProps(item) && item.id === key)?.type, propsCopy.initialValues[key]);
|
|
895
|
+
nextInitialValues = propsCopy.initialValues;
|
|
887
896
|
setInitialValues(propsCopy.initialValues);
|
|
888
897
|
delete propsCopy.initialValues;
|
|
889
898
|
}
|
|
890
899
|
if (propsCopy.items?.length) {
|
|
891
|
-
for (const item of propsCopy.items) if (isFormItemProps(item) && item.if) item.hidden = !item.if(
|
|
900
|
+
for (const item of propsCopy.items) if (isFormItemProps(item) && item.if) item.hidden = !item.if(nextInitialValues || Object.create(null));
|
|
892
901
|
}
|
|
893
902
|
const submitTo = typeof submit === "object" ? submit.to : void 0;
|
|
894
903
|
if (propsCopy.onFinish) {
|
|
@@ -927,7 +936,7 @@ function Form(props) {
|
|
|
927
936
|
delete propsCopy.extendTypes;
|
|
928
937
|
}
|
|
929
938
|
setComputedProps(propsCopy);
|
|
930
|
-
}, [props]);
|
|
939
|
+
}, [form, props]);
|
|
931
940
|
const onValuesChange = useEqualCallback((changedValues, allValues) => {
|
|
932
941
|
console.debug("Form:onValuesChange", changedValues, allValues);
|
|
933
942
|
if (props.onValuesChange) props.onValuesChange(changedValues, allValues);
|
|
@@ -937,12 +946,12 @@ function Form(props) {
|
|
|
937
946
|
if (item?.onValueChange) item.onValueChange(changedValues[key], allValues, form);
|
|
938
947
|
}
|
|
939
948
|
}, [computedProps]);
|
|
940
|
-
|
|
949
|
+
useEqualEffect(() => {
|
|
941
950
|
if (!initialValues) return;
|
|
942
951
|
console.debug("Form:initialValues", initialValues);
|
|
943
952
|
form.setFieldsValue(initialValues);
|
|
944
953
|
setInitialValues(null);
|
|
945
|
-
}, [
|
|
954
|
+
}, [form, initialValues]);
|
|
946
955
|
if (!computedProps) return null;
|
|
947
956
|
return /* @__PURE__ */ jsxs(Form$1, {
|
|
948
957
|
...computedProps,
|
|
@@ -993,7 +1002,7 @@ function Link(props) {
|
|
|
993
1002
|
const navigate = useNavigate();
|
|
994
1003
|
const target = props.target || theme.Link?.target || (props.href.startsWith("http") ? "_blank" : void 0);
|
|
995
1004
|
let computedStyle = {
|
|
996
|
-
...theme.Link.style
|
|
1005
|
+
...theme.Link.style,
|
|
997
1006
|
cursor: "pointer",
|
|
998
1007
|
...props.style
|
|
999
1008
|
};
|
|
@@ -1007,8 +1016,16 @@ function Link(props) {
|
|
|
1007
1016
|
...buttonProps,
|
|
1008
1017
|
style: computedStyle,
|
|
1009
1018
|
onClick: (e) => {
|
|
1010
|
-
props.onClick ? props.onClick(e) : target === "_blank" ? window.open(props.href) : navigate(props.href);
|
|
1011
1019
|
e.preventDefault();
|
|
1020
|
+
if (props.onClick) {
|
|
1021
|
+
props.onClick(e);
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
if (target === "_blank") {
|
|
1025
|
+
window.open(props.href);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
navigate(props.href);
|
|
1012
1029
|
},
|
|
1013
1030
|
children: props.children ?? props.text
|
|
1014
1031
|
});
|
|
@@ -1108,7 +1125,8 @@ function processValue(item, value) {
|
|
|
1108
1125
|
function Table(props) {
|
|
1109
1126
|
const [columns, setColumns] = useState();
|
|
1110
1127
|
const { theme } = useConfigContext();
|
|
1111
|
-
const
|
|
1128
|
+
const { all, blank, search } = theme.common;
|
|
1129
|
+
const generateFilterDropdown = useCallback((item) => {
|
|
1112
1130
|
if (item.filterDropdown && item.filterDropdown !== true) return;
|
|
1113
1131
|
if (!item.options?.length) return;
|
|
1114
1132
|
if (item.options.length < 11) {
|
|
@@ -1129,7 +1147,7 @@ function Table(props) {
|
|
|
1129
1147
|
allowClear: true,
|
|
1130
1148
|
showSearch: true,
|
|
1131
1149
|
style: { width: "100%" },
|
|
1132
|
-
placeholder: `${
|
|
1150
|
+
placeholder: `${search} ${item.title}`,
|
|
1133
1151
|
value: selectedKeys,
|
|
1134
1152
|
onChange: (v) => {
|
|
1135
1153
|
setSelectedKeys(v?.length ? v : []);
|
|
@@ -1137,18 +1155,19 @@ function Table(props) {
|
|
|
1137
1155
|
},
|
|
1138
1156
|
mode: "multiple",
|
|
1139
1157
|
filterOption: (input, option) => {
|
|
1140
|
-
if (!input || !option
|
|
1158
|
+
if (!input || !option) return true;
|
|
1159
|
+
if (typeof option.label !== "string") return option.value === input;
|
|
1141
1160
|
input = input.trim();
|
|
1142
|
-
return option.value === input || option.label.
|
|
1161
|
+
return option.value === input || option.label.toLowerCase().includes(input.toLowerCase());
|
|
1143
1162
|
}
|
|
1144
1163
|
})
|
|
1145
1164
|
});
|
|
1146
1165
|
return item;
|
|
1147
|
-
};
|
|
1148
|
-
|
|
1166
|
+
}, [search]);
|
|
1167
|
+
useEqualEffect(() => {
|
|
1149
1168
|
const items = cloneDeep(props.items).filter((item) => !(item.tableChildren === null || item.children === null || item.tableRender === null || item.render === null));
|
|
1150
1169
|
const createTextSearchFilterDropdown = (item, transformValue) => ({ setSelectedKeys, confirm, clearFilters }) => /* @__PURE__ */ jsx(Input.Search, {
|
|
1151
|
-
placeholder: `${
|
|
1170
|
+
placeholder: `${search} ${item.title}`,
|
|
1152
1171
|
allowClear: true,
|
|
1153
1172
|
onSearch: (v) => {
|
|
1154
1173
|
if (v) setSelectedKeys(transformValue ? [transformValue(v)] : [v]);
|
|
@@ -1246,7 +1265,7 @@ function Table(props) {
|
|
|
1246
1265
|
}
|
|
1247
1266
|
break;
|
|
1248
1267
|
case "number[]":
|
|
1249
|
-
if (!item.render) item.render = (value) => processValue(item, value)
|
|
1268
|
+
if (!item.render) item.render = (value) => processValue(item, value);
|
|
1250
1269
|
if (item.filterDropdown !== false) {
|
|
1251
1270
|
if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
|
|
1252
1271
|
if (value === null && (!row[item.id] || !row[item.id].length)) return true;
|
|
@@ -1265,7 +1284,7 @@ function Table(props) {
|
|
|
1265
1284
|
color: "#ff4d4f"
|
|
1266
1285
|
} });
|
|
1267
1286
|
if (item.filterDropdown !== false) {
|
|
1268
|
-
if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm }) => /* @__PURE__ */ jsxs(Radio.Group, {
|
|
1287
|
+
if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, selectedKeys, confirm: confirmFilter }) => /* @__PURE__ */ jsxs(Radio.Group, {
|
|
1269
1288
|
style: { padding: 8 },
|
|
1270
1289
|
buttonStyle: "solid",
|
|
1271
1290
|
value: JSON.stringify(selectedKeys[0]),
|
|
@@ -1275,10 +1294,10 @@ function Table(props) {
|
|
|
1275
1294
|
false: false,
|
|
1276
1295
|
null: null
|
|
1277
1296
|
}[e.target.value]] : []);
|
|
1278
|
-
|
|
1297
|
+
confirmFilter();
|
|
1279
1298
|
},
|
|
1280
1299
|
children: [
|
|
1281
|
-
/* @__PURE__ */ jsx(Radio.Button, { children:
|
|
1300
|
+
/* @__PURE__ */ jsx(Radio.Button, { children: all }),
|
|
1282
1301
|
/* @__PURE__ */ jsx(Radio.Button, {
|
|
1283
1302
|
value: "true",
|
|
1284
1303
|
children: /* @__PURE__ */ jsx(CheckOutlined, { style: {
|
|
@@ -1295,7 +1314,7 @@ function Table(props) {
|
|
|
1295
1314
|
}),
|
|
1296
1315
|
/* @__PURE__ */ jsx(Radio.Button, {
|
|
1297
1316
|
value: "null",
|
|
1298
|
-
children:
|
|
1317
|
+
children: blank
|
|
1299
1318
|
})
|
|
1300
1319
|
]
|
|
1301
1320
|
});
|
|
@@ -1319,7 +1338,9 @@ function Table(props) {
|
|
|
1319
1338
|
};
|
|
1320
1339
|
if (item.filterDropdown !== false) {
|
|
1321
1340
|
if (typeof item.filterDropdown === "undefined") item.filterDropdown = ({ setSelectedKeys, confirm }) => /* @__PURE__ */ jsx(DatePicker.RangePicker, { onChange: (dates) => {
|
|
1322
|
-
|
|
1341
|
+
const start = dates?.[0];
|
|
1342
|
+
const end = dates?.[1];
|
|
1343
|
+
setSelectedKeys(start && end ? [[start.startOf("day").toISOString(), end.endOf("day").toISOString()]] : []);
|
|
1323
1344
|
confirm();
|
|
1324
1345
|
} });
|
|
1325
1346
|
if (!item.onFilter && !props.faasData) item.onFilter = (value, row) => {
|
|
@@ -1353,8 +1374,16 @@ function Table(props) {
|
|
|
1353
1374
|
}
|
|
1354
1375
|
}
|
|
1355
1376
|
setColumns(items);
|
|
1356
|
-
}, [
|
|
1357
|
-
|
|
1377
|
+
}, [
|
|
1378
|
+
all,
|
|
1379
|
+
blank,
|
|
1380
|
+
generateFilterDropdown,
|
|
1381
|
+
props.extendTypes,
|
|
1382
|
+
props.faasData,
|
|
1383
|
+
props.items,
|
|
1384
|
+
search
|
|
1385
|
+
]);
|
|
1386
|
+
useEqualEffect(() => {
|
|
1358
1387
|
if (!props.dataSource || !columns) return;
|
|
1359
1388
|
for (const column of columns) if (column.optionsType === "auto" && !column.options && !column.filters) {
|
|
1360
1389
|
const options = uniqBy(props.dataSource, column.id).map((v) => ({
|
|
@@ -1370,7 +1399,11 @@ function Table(props) {
|
|
|
1370
1399
|
return newColumns;
|
|
1371
1400
|
});
|
|
1372
1401
|
}
|
|
1373
|
-
}, [
|
|
1402
|
+
}, [
|
|
1403
|
+
props.dataSource,
|
|
1404
|
+
columns,
|
|
1405
|
+
generateFilterDropdown
|
|
1406
|
+
]);
|
|
1374
1407
|
if (!columns) return null;
|
|
1375
1408
|
if (props.dataSource) return /* @__PURE__ */ jsx(Table$1, {
|
|
1376
1409
|
...props,
|
|
@@ -1392,7 +1425,7 @@ function Table(props) {
|
|
|
1392
1425
|
}
|
|
1393
1426
|
function FaasDataTable({ props, columns, data, params, reload, loading }) {
|
|
1394
1427
|
const [currentColumns, setCurrentColumns] = useState(columns);
|
|
1395
|
-
|
|
1428
|
+
useEqualEffect(() => {
|
|
1396
1429
|
if (!data || Array.isArray(data)) return;
|
|
1397
1430
|
setCurrentColumns((prev) => {
|
|
1398
1431
|
const newColumns = [...prev];
|
|
@@ -1529,7 +1562,7 @@ function Tabs(props) {
|
|
|
1529
1562
|
*/
|
|
1530
1563
|
function Title(props) {
|
|
1531
1564
|
const { theme } = useConfigContext();
|
|
1532
|
-
|
|
1565
|
+
useEqualEffect(() => {
|
|
1533
1566
|
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
1534
1567
|
document.title = title.concat(props.suffix || theme.Title.suffix).filter((t) => !!t).join(props.separator || theme.Title.separator);
|
|
1535
1568
|
}, [props, theme.Title]);
|
|
@@ -1559,4 +1592,4 @@ function useThemeToken() {
|
|
|
1559
1592
|
return theme.useToken().token;
|
|
1560
1593
|
}
|
|
1561
1594
|
//#endregion
|
|
1562
|
-
export { App, Blank, ConfigContext, ConfigProvider, Description, Drawer, ErrorBoundary, FaasDataWrapper, FaasReactClient, Form, FormItem, Link, Loading, Modal, PageNotFound, Routes, Table, Tabs, Title, cloneUnionFaasItemElement, faas, idToTitle, lazy, transferOptions, transferValue, useApp, useConfigContext, useDrawer, useFaas, useModal, useThemeToken, withFaasData };
|
|
1595
|
+
export { App, AppContext, Blank, ConfigContext, ConfigProvider, Description, Drawer, ErrorBoundary, FaasDataWrapper, FaasReactClient, Form, FormItem, Link, Loading, Modal, PageNotFound, Routes, Table, Tabs, Title, cloneUnionFaasItemElement, faas, idToTitle, lazy, transferOptions, transferValue, useApp, useConfigContext, useDrawer, useFaas, useModal, useThemeToken, withFaasData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.16",
|
|
4
4
|
"homepage": "https://faasjs.com/doc/ant-design",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/faasjs/faasjs/issues"
|
|
@@ -26,12 +26,9 @@
|
|
|
26
26
|
"require": "./dist/index.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"build": "tsdown src/index.ts --config ../../tsdown.config.ts --dts.eager --no-sourcemap --no-dts.sourcemap"
|
|
31
|
-
},
|
|
32
29
|
"devDependencies": {
|
|
33
30
|
"@ant-design/icons": "*",
|
|
34
|
-
"@faasjs/react": ">=8.0.0-beta.
|
|
31
|
+
"@faasjs/react": ">=8.0.0-beta.16",
|
|
35
32
|
"@types/lodash-es": "*",
|
|
36
33
|
"@types/react": "^19.0.0",
|
|
37
34
|
"@types/react-dom": "^19.0.0",
|
|
@@ -43,7 +40,7 @@
|
|
|
43
40
|
},
|
|
44
41
|
"peerDependencies": {
|
|
45
42
|
"@ant-design/icons": "*",
|
|
46
|
-
"@faasjs/react": ">=8.0.0-beta.
|
|
43
|
+
"@faasjs/react": ">=8.0.0-beta.16",
|
|
47
44
|
"antd": "^6.0.0",
|
|
48
45
|
"lodash-es": "*",
|
|
49
46
|
"react": "^19.0.0",
|