@faasjs/ant-design 0.0.2-beta.354 → 0.0.2-beta.358
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.d.ts +9 -19
- package/dist/index.js +103 -81
- package/dist/index.mjs +102 -83
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as react_use_lib_misc_hookState from 'react-use/lib/misc/hookState';
|
|
2
2
|
import { DescriptionsProps, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, FormProps as FormProps$1, TableColumnProps, TableProps as TableProps$1 } from 'antd';
|
|
3
3
|
export { Drawer } from 'antd';
|
|
4
|
-
import {
|
|
4
|
+
import { FaasDataWrapperProps } from '@faasjs/react';
|
|
5
5
|
import * as antd_lib_form_Form from 'antd/lib/form/Form';
|
|
6
6
|
import { RuleObject } from 'rc-field-form/lib/interface';
|
|
7
|
+
import { LazyExoticComponent, ComponentType } from 'react';
|
|
7
8
|
import { RouteProps } from 'react-router-dom';
|
|
8
9
|
|
|
9
10
|
declare type BlankProps = {
|
|
@@ -17,6 +18,7 @@ declare type FaasState = {
|
|
|
17
18
|
blank: string;
|
|
18
19
|
all: string;
|
|
19
20
|
submit: string;
|
|
21
|
+
pageNotFound: string;
|
|
20
22
|
};
|
|
21
23
|
Blank: {
|
|
22
24
|
text: string;
|
|
@@ -65,22 +67,6 @@ declare function transferOptions(options: BaseOption[]): {
|
|
|
65
67
|
value?: string | number;
|
|
66
68
|
}[];
|
|
67
69
|
|
|
68
|
-
declare type FaasDataProps<T = any> = {
|
|
69
|
-
action: string;
|
|
70
|
-
params?: Record<string, any>;
|
|
71
|
-
data?: T;
|
|
72
|
-
setData?: Dispatch<SetStateAction<T>>;
|
|
73
|
-
};
|
|
74
|
-
declare type FaasDataRender<T = any> = (args: {
|
|
75
|
-
data: T;
|
|
76
|
-
}) => JSX.Element;
|
|
77
|
-
declare type FaasDataWrapperProps<T = any> = {
|
|
78
|
-
dataSource?: T;
|
|
79
|
-
faasData?: FaasDataProps<T>;
|
|
80
|
-
render?: FaasDataRender<T>;
|
|
81
|
-
fallback?: JSX.Element;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
70
|
declare type ExtendDescriptionTypeProps = {
|
|
85
71
|
children?: JSX.Element | null;
|
|
86
72
|
render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
|
|
@@ -95,7 +81,9 @@ declare type DescriptionProps<T = any, ExtendItemProps = any> = {
|
|
|
95
81
|
extendTypes?: {
|
|
96
82
|
[key: string]: ExtendDescriptionTypeProps;
|
|
97
83
|
};
|
|
98
|
-
|
|
84
|
+
dataSource?: T;
|
|
85
|
+
faasData?: FaasDataWrapperProps<T>;
|
|
86
|
+
} & DescriptionsProps;
|
|
99
87
|
declare function Description<T = any>(props: DescriptionProps<T>): JSX.Element;
|
|
100
88
|
|
|
101
89
|
declare type DrawerProps = DrawerProps$1 & {
|
|
@@ -171,6 +159,7 @@ declare type RoutesProps = {
|
|
|
171
159
|
routes: (RouteProps & {
|
|
172
160
|
page?: LazyExoticComponent<ComponentType<any>>;
|
|
173
161
|
})[];
|
|
162
|
+
fallback?: JSX.Element;
|
|
174
163
|
notFound?: JSX.Element;
|
|
175
164
|
};
|
|
176
165
|
declare function Routes(props: RoutesProps): JSX.Element;
|
|
@@ -189,7 +178,8 @@ declare type TableProps<T = any, ExtendTypes = any> = {
|
|
|
189
178
|
extendTypes?: {
|
|
190
179
|
[key: string]: ExtendTableTypeProps;
|
|
191
180
|
};
|
|
192
|
-
|
|
181
|
+
faasData?: FaasDataWrapperProps<T>;
|
|
182
|
+
} & TableProps$1<T>;
|
|
193
183
|
declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
|
|
194
184
|
|
|
195
185
|
declare type TitleProps = {
|
package/dist/index.js
CHANGED
|
@@ -70,11 +70,17 @@ var import_lodash = require("lodash");
|
|
|
70
70
|
// src/Config.tsx
|
|
71
71
|
var import_react2 = require("react");
|
|
72
72
|
var import_react_use = require("react-use");
|
|
73
|
-
var
|
|
74
|
-
var common = {
|
|
75
|
-
blank:
|
|
76
|
-
all:
|
|
77
|
-
submit:
|
|
73
|
+
var isCN = /^zh/i.test(navigator.language);
|
|
74
|
+
var common = isCN ? {
|
|
75
|
+
blank: "\u7A7A",
|
|
76
|
+
all: "\u5168\u90E8",
|
|
77
|
+
submit: "\u63D0\u4EA4",
|
|
78
|
+
pageNotFound: "\u9875\u9762\u672A\u627E\u5230"
|
|
79
|
+
} : {
|
|
80
|
+
blank: "Empty",
|
|
81
|
+
all: "All",
|
|
82
|
+
submit: "Submit",
|
|
83
|
+
pageNotFound: "Page Not Found"
|
|
78
84
|
};
|
|
79
85
|
var useFaasState = (0, import_react_use.createGlobalState)({
|
|
80
86
|
common,
|
|
@@ -116,56 +122,28 @@ function transferOptions(options) {
|
|
|
116
122
|
var import_icons = require("@ant-design/icons");
|
|
117
123
|
var import_antd2 = require("antd");
|
|
118
124
|
var import_lodash3 = require("lodash");
|
|
119
|
-
var import_react5 = require("react");
|
|
120
|
-
|
|
121
|
-
// src/FaasDataWrapper.tsx
|
|
122
125
|
var import_react3 = require("react");
|
|
123
126
|
var import_react4 = require("@faasjs/react");
|
|
124
|
-
function FaasDataWrapper({
|
|
125
|
-
dataSource,
|
|
126
|
-
faasData,
|
|
127
|
-
render,
|
|
128
|
-
fallback
|
|
129
|
-
}) {
|
|
130
|
-
const [data, setData] = (0, import_react3.useState)();
|
|
131
|
-
(0, import_react3.useEffect)(() => {
|
|
132
|
-
if (!faasData)
|
|
133
|
-
return;
|
|
134
|
-
(0, import_react4.getClient)().faas(faasData.action, faasData.params).then((res) => {
|
|
135
|
-
if (faasData.setData)
|
|
136
|
-
faasData.setData(res.data);
|
|
137
|
-
else
|
|
138
|
-
setData(res.data);
|
|
139
|
-
});
|
|
140
|
-
}, [JSON.stringify([faasData == null ? void 0 : faasData.action, faasData == null ? void 0 : faasData.params])]);
|
|
141
|
-
if (dataSource)
|
|
142
|
-
return render({ data: dataSource });
|
|
143
|
-
if (!data && !faasData.data)
|
|
144
|
-
return fallback || null;
|
|
145
|
-
return render({ data: faasData.data || data });
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/Description.tsx
|
|
149
127
|
function DescriptionItemContent(props) {
|
|
150
|
-
const [computedProps, setComputedProps] = (0,
|
|
151
|
-
(0,
|
|
152
|
-
var
|
|
128
|
+
const [computedProps, setComputedProps] = (0, import_react3.useState)();
|
|
129
|
+
(0, import_react3.useEffect)(() => {
|
|
130
|
+
var _a, _b;
|
|
153
131
|
const propsCopy = __spreadValues({}, props);
|
|
154
132
|
if (!propsCopy.item.title)
|
|
155
133
|
propsCopy.item.title = (0, import_lodash3.upperFirst)(propsCopy.item.id);
|
|
156
134
|
if (!propsCopy.item.type)
|
|
157
135
|
propsCopy.item.type = "string";
|
|
158
|
-
if ((
|
|
136
|
+
if ((_a = propsCopy.item.options) == null ? void 0 : _a.length) {
|
|
159
137
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
160
138
|
}
|
|
161
139
|
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
162
140
|
if (propsCopy.item.type.endsWith("[]"))
|
|
163
141
|
propsCopy.value = propsCopy.value.map((v) => {
|
|
164
|
-
var
|
|
165
|
-
return ((
|
|
142
|
+
var _a2;
|
|
143
|
+
return ((_a2 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
166
144
|
});
|
|
167
145
|
else
|
|
168
|
-
propsCopy.value = ((
|
|
146
|
+
propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
|
|
169
147
|
}
|
|
170
148
|
setComputedProps(propsCopy);
|
|
171
149
|
}, [props]);
|
|
@@ -173,7 +151,7 @@ function DescriptionItemContent(props) {
|
|
|
173
151
|
return null;
|
|
174
152
|
if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
|
|
175
153
|
if (computedProps.extendTypes[computedProps.item.type].children)
|
|
176
|
-
return (0,
|
|
154
|
+
return (0, import_react3.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
|
|
177
155
|
value: computedProps.value,
|
|
178
156
|
values: computedProps.values
|
|
179
157
|
});
|
|
@@ -182,7 +160,7 @@ function DescriptionItemContent(props) {
|
|
|
182
160
|
else
|
|
183
161
|
throw Error(computedProps.item.type + " requires children or render");
|
|
184
162
|
if (computedProps.item.children)
|
|
185
|
-
return (0,
|
|
163
|
+
return (0, import_react3.cloneElement)(computedProps.item.children, { value: computedProps.value });
|
|
186
164
|
if (computedProps.item.render)
|
|
187
165
|
return computedProps.item.render(computedProps.value, computedProps.values);
|
|
188
166
|
if (typeof computedProps.value === "undefined" || computedProps.value === null)
|
|
@@ -211,7 +189,17 @@ function DescriptionItemContent(props) {
|
|
|
211
189
|
}
|
|
212
190
|
}
|
|
213
191
|
function Description(props) {
|
|
214
|
-
|
|
192
|
+
if (!props.faasData)
|
|
193
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions.Item, {
|
|
194
|
+
key: item.id,
|
|
195
|
+
label: item.title || (0, import_lodash3.upperFirst)(item.id)
|
|
196
|
+
}, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
|
|
197
|
+
item,
|
|
198
|
+
value: props.dataSource[item.id],
|
|
199
|
+
values: props.dataSource,
|
|
200
|
+
extendTypes: props.extendTypes
|
|
201
|
+
}))));
|
|
202
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react4.FaasDataWrapper, __spreadValues({
|
|
215
203
|
render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions.Item, {
|
|
216
204
|
key: item.id,
|
|
217
205
|
label: item.title || (0, import_lodash3.upperFirst)(item.id)
|
|
@@ -221,14 +209,14 @@ function Description(props) {
|
|
|
221
209
|
values: data,
|
|
222
210
|
extendTypes: props.extendTypes
|
|
223
211
|
}))))
|
|
224
|
-
}));
|
|
212
|
+
}, props.faasData));
|
|
225
213
|
}
|
|
226
214
|
|
|
227
215
|
// src/Drawer.tsx
|
|
228
216
|
var import_antd3 = require("antd");
|
|
229
|
-
var
|
|
217
|
+
var import_react5 = require("react");
|
|
230
218
|
function useDrawer(init) {
|
|
231
|
-
const [props, setProps] = (0,
|
|
219
|
+
const [props, setProps] = (0, import_react5.useState)(__spreadValues({
|
|
232
220
|
visible: false,
|
|
233
221
|
onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
234
222
|
visible: false
|
|
@@ -245,16 +233,16 @@ function useDrawer(init) {
|
|
|
245
233
|
|
|
246
234
|
// src/Form.tsx
|
|
247
235
|
var import_antd5 = require("antd");
|
|
248
|
-
var
|
|
236
|
+
var import_react7 = require("react");
|
|
249
237
|
|
|
250
238
|
// src/FormItem.tsx
|
|
251
239
|
var import_antd4 = require("antd");
|
|
252
240
|
var import_icons2 = require("@ant-design/icons");
|
|
253
|
-
var
|
|
241
|
+
var import_react6 = require("react");
|
|
254
242
|
var import_lodash4 = require("lodash");
|
|
255
243
|
function FormItem(props) {
|
|
256
|
-
const [computedProps, setComputedProps] = (0,
|
|
257
|
-
(0,
|
|
244
|
+
const [computedProps, setComputedProps] = (0, import_react6.useState)();
|
|
245
|
+
(0, import_react6.useEffect)(() => {
|
|
258
246
|
const propsCopy = __spreadValues({}, props);
|
|
259
247
|
if (!propsCopy.title)
|
|
260
248
|
propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
|
|
@@ -352,11 +340,11 @@ function FormItem(props) {
|
|
|
352
340
|
name: computedProps.name,
|
|
353
341
|
rules: computedProps.rules
|
|
354
342
|
}, (fields, { add, remove }, { errors }) => {
|
|
355
|
-
var
|
|
343
|
+
var _a;
|
|
356
344
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
357
345
|
className: "ant-form-item-label"
|
|
358
346
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
359
|
-
className: ((
|
|
347
|
+
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
|
360
348
|
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
361
349
|
key: field.key
|
|
362
350
|
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
@@ -393,11 +381,11 @@ function FormItem(props) {
|
|
|
393
381
|
|
|
394
382
|
// src/Form.tsx
|
|
395
383
|
function Form(props) {
|
|
396
|
-
var
|
|
397
|
-
const [loading, setLoading] = (0,
|
|
398
|
-
const [computedProps, setComputedProps] = (0,
|
|
384
|
+
var _a, _b;
|
|
385
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
386
|
+
const [computedProps, setComputedProps] = (0, import_react7.useState)();
|
|
399
387
|
const [config] = useFaasState();
|
|
400
|
-
(0,
|
|
388
|
+
(0, import_react7.useEffect)(() => {
|
|
401
389
|
const propsCopy = __spreadValues({}, props);
|
|
402
390
|
if (propsCopy.onFinish) {
|
|
403
391
|
propsCopy.onFinish = async (values) => {
|
|
@@ -414,7 +402,7 @@ function Form(props) {
|
|
|
414
402
|
}, []);
|
|
415
403
|
if (!computedProps)
|
|
416
404
|
return null;
|
|
417
|
-
return /* @__PURE__ */ import_react.default.createElement(import_antd5.Form, __spreadValues({}, computedProps), (
|
|
405
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd5.Form, __spreadValues({}, computedProps), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({
|
|
418
406
|
key: item.id
|
|
419
407
|
}, item), {
|
|
420
408
|
extendTypes: props.extendTypes
|
|
@@ -422,61 +410,63 @@ function Form(props) {
|
|
|
422
410
|
htmlType: "submit",
|
|
423
411
|
type: "primary",
|
|
424
412
|
loading
|
|
425
|
-
}, ((
|
|
413
|
+
}, ((_b = props.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
|
|
426
414
|
}
|
|
427
415
|
Form.useForm = import_antd5.Form.useForm;
|
|
428
416
|
Form.Item = FormItem;
|
|
429
417
|
|
|
430
418
|
// src/Routers.tsx
|
|
431
419
|
var import_antd6 = require("antd");
|
|
432
|
-
var
|
|
420
|
+
var import_react8 = require("react");
|
|
433
421
|
var import_react_router_dom = require("react-router-dom");
|
|
434
|
-
function
|
|
422
|
+
function NotFound() {
|
|
423
|
+
const [config] = useFaasState();
|
|
435
424
|
return /* @__PURE__ */ import_react.default.createElement(import_antd6.Result, {
|
|
436
425
|
status: "404",
|
|
437
|
-
title:
|
|
438
|
-
subTitle: "Page not found"
|
|
426
|
+
title: config.common.pageNotFound
|
|
439
427
|
});
|
|
440
428
|
}
|
|
441
429
|
function Routes(props) {
|
|
442
430
|
return /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Routes, null, props.routes.map((r) => /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, __spreadProps(__spreadValues({
|
|
443
431
|
key: r.path
|
|
444
432
|
}, r), {
|
|
445
|
-
element: r.element || /* @__PURE__ */ import_react.default.createElement(
|
|
446
|
-
fallback: /* @__PURE__ */ import_react.default.createElement(import_antd6.Skeleton, {
|
|
447
|
-
active: true
|
|
433
|
+
element: r.element || /* @__PURE__ */ import_react.default.createElement(import_react8.Suspense, {
|
|
434
|
+
fallback: props.fallback || /* @__PURE__ */ import_react.default.createElement(import_antd6.Skeleton, {
|
|
435
|
+
active: true,
|
|
436
|
+
style: { padding: "24px" }
|
|
448
437
|
})
|
|
449
438
|
}, /* @__PURE__ */ import_react.default.createElement(r.page, null))
|
|
450
439
|
}))), /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, {
|
|
451
440
|
key: "*",
|
|
452
441
|
path: "*",
|
|
453
|
-
element: props.notFound || /* @__PURE__ */ import_react.default.createElement(
|
|
442
|
+
element: props.notFound || /* @__PURE__ */ import_react.default.createElement(NotFound, null)
|
|
454
443
|
}));
|
|
455
444
|
}
|
|
456
445
|
|
|
457
446
|
// src/Table.tsx
|
|
458
|
-
var
|
|
447
|
+
var import_react9 = require("react");
|
|
459
448
|
var import_antd7 = require("antd");
|
|
460
449
|
var import_icons3 = require("@ant-design/icons");
|
|
461
450
|
var import_lodash5 = require("lodash");
|
|
451
|
+
var import_react10 = require("@faasjs/react");
|
|
462
452
|
function processValue(item, value) {
|
|
463
|
-
var
|
|
453
|
+
var _a;
|
|
464
454
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
465
455
|
if (item.type.endsWith("[]"))
|
|
466
456
|
return value.map((v) => {
|
|
467
|
-
var
|
|
468
|
-
return ((
|
|
457
|
+
var _a2;
|
|
458
|
+
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
469
459
|
});
|
|
470
460
|
else
|
|
471
|
-
return ((
|
|
461
|
+
return ((_a = item.options.find((option) => option.value === value)) == null ? void 0 : _a.label) || value;
|
|
472
462
|
}
|
|
473
463
|
return value;
|
|
474
464
|
}
|
|
475
465
|
function Table(props) {
|
|
476
|
-
const [columns, setColumns] = (0,
|
|
466
|
+
const [columns, setColumns] = (0, import_react9.useState)();
|
|
477
467
|
const [config] = useFaasState();
|
|
478
|
-
(0,
|
|
479
|
-
var
|
|
468
|
+
(0, import_react9.useEffect)(() => {
|
|
469
|
+
var _a;
|
|
480
470
|
for (const item of props.items) {
|
|
481
471
|
if (!item.key)
|
|
482
472
|
item.key = item.id;
|
|
@@ -486,7 +476,7 @@ function Table(props) {
|
|
|
486
476
|
item.title = (0, import_lodash5.upperFirst)(item.id);
|
|
487
477
|
if (!item.type)
|
|
488
478
|
item.type = "string";
|
|
489
|
-
if ((
|
|
479
|
+
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
490
480
|
item.options = transferOptions(item.options);
|
|
491
481
|
item.filters = item.options.map((o) => ({
|
|
492
482
|
text: o.label,
|
|
@@ -499,7 +489,7 @@ function Table(props) {
|
|
|
499
489
|
delete item.children;
|
|
500
490
|
if (props.extendTypes && props.extendTypes[item.type]) {
|
|
501
491
|
if (props.extendTypes[item.type].children) {
|
|
502
|
-
item.render = (value, values) => (0,
|
|
492
|
+
item.render = (value, values) => (0, import_react9.cloneElement)(props.extendTypes[item.type].children, {
|
|
503
493
|
value,
|
|
504
494
|
values
|
|
505
495
|
});
|
|
@@ -594,13 +584,45 @@ function Table(props) {
|
|
|
594
584
|
}, [props.items]);
|
|
595
585
|
if (!columns)
|
|
596
586
|
return null;
|
|
597
|
-
|
|
598
|
-
|
|
587
|
+
if (!props.faasData)
|
|
588
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
599
589
|
rowKey: props.rowKey || "id",
|
|
600
590
|
columns,
|
|
601
|
-
dataSource:
|
|
602
|
-
}))
|
|
603
|
-
|
|
591
|
+
dataSource: props.dataSource
|
|
592
|
+
}));
|
|
593
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react10.FaasDataWrapper, __spreadValues({
|
|
594
|
+
render: ({
|
|
595
|
+
data,
|
|
596
|
+
params,
|
|
597
|
+
reload
|
|
598
|
+
}) => {
|
|
599
|
+
if (!data)
|
|
600
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
601
|
+
rowKey: props.rowKey || "id",
|
|
602
|
+
columns,
|
|
603
|
+
dataSource: []
|
|
604
|
+
}));
|
|
605
|
+
if (Array.isArray(data))
|
|
606
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
607
|
+
rowKey: props.rowKey || "id",
|
|
608
|
+
columns,
|
|
609
|
+
dataSource: data
|
|
610
|
+
}));
|
|
611
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
612
|
+
rowKey: props.rowKey || "id",
|
|
613
|
+
columns,
|
|
614
|
+
dataSource: data.rows,
|
|
615
|
+
pagination: __spreadValues(__spreadValues({}, props.pagination), data.pagination),
|
|
616
|
+
onChange: (pagination, filters, sorter) => {
|
|
617
|
+
reload(__spreadProps(__spreadValues({}, params), {
|
|
618
|
+
pagination,
|
|
619
|
+
filters,
|
|
620
|
+
sorter
|
|
621
|
+
}));
|
|
622
|
+
}
|
|
623
|
+
}));
|
|
624
|
+
}
|
|
625
|
+
}, props.faasData));
|
|
604
626
|
}
|
|
605
627
|
|
|
606
628
|
// src/Title.tsx
|
package/dist/index.mjs
CHANGED
|
@@ -28,11 +28,17 @@ import { isNil } from "lodash";
|
|
|
28
28
|
// src/Config.tsx
|
|
29
29
|
import { useEffect } from "react";
|
|
30
30
|
import { createGlobalState } from "react-use";
|
|
31
|
-
var
|
|
32
|
-
var common = {
|
|
33
|
-
blank:
|
|
34
|
-
all:
|
|
35
|
-
submit:
|
|
31
|
+
var isCN = /^zh/i.test(navigator.language);
|
|
32
|
+
var common = isCN ? {
|
|
33
|
+
blank: "\u7A7A",
|
|
34
|
+
all: "\u5168\u90E8",
|
|
35
|
+
submit: "\u63D0\u4EA4",
|
|
36
|
+
pageNotFound: "\u9875\u9762\u672A\u627E\u5230"
|
|
37
|
+
} : {
|
|
38
|
+
blank: "Empty",
|
|
39
|
+
all: "All",
|
|
40
|
+
submit: "Submit",
|
|
41
|
+
pageNotFound: "Page Not Found"
|
|
36
42
|
};
|
|
37
43
|
var useFaasState = createGlobalState({
|
|
38
44
|
common,
|
|
@@ -76,61 +82,30 @@ import { Descriptions } from "antd";
|
|
|
76
82
|
import { upperFirst as upperFirst2 } from "lodash";
|
|
77
83
|
import {
|
|
78
84
|
cloneElement,
|
|
79
|
-
useEffect as useEffect3,
|
|
80
|
-
useState as useState2
|
|
81
|
-
} from "react";
|
|
82
|
-
|
|
83
|
-
// src/FaasDataWrapper.tsx
|
|
84
|
-
import {
|
|
85
85
|
useEffect as useEffect2,
|
|
86
86
|
useState
|
|
87
87
|
} from "react";
|
|
88
|
-
import {
|
|
89
|
-
function FaasDataWrapper({
|
|
90
|
-
dataSource,
|
|
91
|
-
faasData,
|
|
92
|
-
render,
|
|
93
|
-
fallback
|
|
94
|
-
}) {
|
|
95
|
-
const [data, setData] = useState();
|
|
96
|
-
useEffect2(() => {
|
|
97
|
-
if (!faasData)
|
|
98
|
-
return;
|
|
99
|
-
getClient().faas(faasData.action, faasData.params).then((res) => {
|
|
100
|
-
if (faasData.setData)
|
|
101
|
-
faasData.setData(res.data);
|
|
102
|
-
else
|
|
103
|
-
setData(res.data);
|
|
104
|
-
});
|
|
105
|
-
}, [JSON.stringify([faasData == null ? void 0 : faasData.action, faasData == null ? void 0 : faasData.params])]);
|
|
106
|
-
if (dataSource)
|
|
107
|
-
return render({ data: dataSource });
|
|
108
|
-
if (!data && !faasData.data)
|
|
109
|
-
return fallback || null;
|
|
110
|
-
return render({ data: faasData.data || data });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/Description.tsx
|
|
88
|
+
import { FaasDataWrapper } from "@faasjs/react";
|
|
114
89
|
function DescriptionItemContent(props) {
|
|
115
|
-
const [computedProps, setComputedProps] =
|
|
116
|
-
|
|
117
|
-
var
|
|
90
|
+
const [computedProps, setComputedProps] = useState();
|
|
91
|
+
useEffect2(() => {
|
|
92
|
+
var _a, _b;
|
|
118
93
|
const propsCopy = __spreadValues({}, props);
|
|
119
94
|
if (!propsCopy.item.title)
|
|
120
95
|
propsCopy.item.title = upperFirst2(propsCopy.item.id);
|
|
121
96
|
if (!propsCopy.item.type)
|
|
122
97
|
propsCopy.item.type = "string";
|
|
123
|
-
if ((
|
|
98
|
+
if ((_a = propsCopy.item.options) == null ? void 0 : _a.length) {
|
|
124
99
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
125
100
|
}
|
|
126
101
|
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
127
102
|
if (propsCopy.item.type.endsWith("[]"))
|
|
128
103
|
propsCopy.value = propsCopy.value.map((v) => {
|
|
129
|
-
var
|
|
130
|
-
return ((
|
|
104
|
+
var _a2;
|
|
105
|
+
return ((_a2 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
131
106
|
});
|
|
132
107
|
else
|
|
133
|
-
propsCopy.value = ((
|
|
108
|
+
propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
|
|
134
109
|
}
|
|
135
110
|
setComputedProps(propsCopy);
|
|
136
111
|
}, [props]);
|
|
@@ -176,7 +151,17 @@ function DescriptionItemContent(props) {
|
|
|
176
151
|
}
|
|
177
152
|
}
|
|
178
153
|
function Description(props) {
|
|
179
|
-
|
|
154
|
+
if (!props.faasData)
|
|
155
|
+
return /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
|
|
156
|
+
key: item.id,
|
|
157
|
+
label: item.title || upperFirst2(item.id)
|
|
158
|
+
}, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
|
|
159
|
+
item,
|
|
160
|
+
value: props.dataSource[item.id],
|
|
161
|
+
values: props.dataSource,
|
|
162
|
+
extendTypes: props.extendTypes
|
|
163
|
+
}))));
|
|
164
|
+
return /* @__PURE__ */ React.createElement(FaasDataWrapper, __spreadValues({
|
|
180
165
|
render: ({ data }) => /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
|
|
181
166
|
key: item.id,
|
|
182
167
|
label: item.title || upperFirst2(item.id)
|
|
@@ -186,14 +171,14 @@ function Description(props) {
|
|
|
186
171
|
values: data,
|
|
187
172
|
extendTypes: props.extendTypes
|
|
188
173
|
}))))
|
|
189
|
-
}));
|
|
174
|
+
}, props.faasData));
|
|
190
175
|
}
|
|
191
176
|
|
|
192
177
|
// src/Drawer.tsx
|
|
193
178
|
import { Drawer } from "antd";
|
|
194
|
-
import { useState as
|
|
179
|
+
import { useState as useState2 } from "react";
|
|
195
180
|
function useDrawer(init) {
|
|
196
|
-
const [props, setProps] =
|
|
181
|
+
const [props, setProps] = useState2(__spreadValues({
|
|
197
182
|
visible: false,
|
|
198
183
|
onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
199
184
|
visible: false
|
|
@@ -213,7 +198,7 @@ import {
|
|
|
213
198
|
Button as Button2,
|
|
214
199
|
Form as AntdForm2
|
|
215
200
|
} from "antd";
|
|
216
|
-
import { useEffect as
|
|
201
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
217
202
|
|
|
218
203
|
// src/FormItem.tsx
|
|
219
204
|
import {
|
|
@@ -227,11 +212,11 @@ import {
|
|
|
227
212
|
Select
|
|
228
213
|
} from "antd";
|
|
229
214
|
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
|
230
|
-
import { useEffect as
|
|
215
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
231
216
|
import { upperFirst as upperFirst3 } from "lodash";
|
|
232
217
|
function FormItem(props) {
|
|
233
|
-
const [computedProps, setComputedProps] =
|
|
234
|
-
|
|
218
|
+
const [computedProps, setComputedProps] = useState3();
|
|
219
|
+
useEffect3(() => {
|
|
235
220
|
const propsCopy = __spreadValues({}, props);
|
|
236
221
|
if (!propsCopy.title)
|
|
237
222
|
propsCopy.title = upperFirst3(propsCopy.id);
|
|
@@ -329,11 +314,11 @@ function FormItem(props) {
|
|
|
329
314
|
name: computedProps.name,
|
|
330
315
|
rules: computedProps.rules
|
|
331
316
|
}, (fields, { add, remove }, { errors }) => {
|
|
332
|
-
var
|
|
317
|
+
var _a;
|
|
333
318
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
334
319
|
className: "ant-form-item-label"
|
|
335
320
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
336
|
-
className: ((
|
|
321
|
+
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
|
337
322
|
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ React.createElement(AntdForm.Item, {
|
|
338
323
|
key: field.key
|
|
339
324
|
}, /* @__PURE__ */ React.createElement(Row, {
|
|
@@ -370,11 +355,11 @@ function FormItem(props) {
|
|
|
370
355
|
|
|
371
356
|
// src/Form.tsx
|
|
372
357
|
function Form(props) {
|
|
373
|
-
var
|
|
374
|
-
const [loading, setLoading] =
|
|
375
|
-
const [computedProps, setComputedProps] =
|
|
358
|
+
var _a, _b;
|
|
359
|
+
const [loading, setLoading] = useState4(false);
|
|
360
|
+
const [computedProps, setComputedProps] = useState4();
|
|
376
361
|
const [config] = useFaasState();
|
|
377
|
-
|
|
362
|
+
useEffect4(() => {
|
|
378
363
|
const propsCopy = __spreadValues({}, props);
|
|
379
364
|
if (propsCopy.onFinish) {
|
|
380
365
|
propsCopy.onFinish = async (values) => {
|
|
@@ -391,7 +376,7 @@ function Form(props) {
|
|
|
391
376
|
}, []);
|
|
392
377
|
if (!computedProps)
|
|
393
378
|
return null;
|
|
394
|
-
return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, computedProps), (
|
|
379
|
+
return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, computedProps), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
|
|
395
380
|
key: item.id
|
|
396
381
|
}, item), {
|
|
397
382
|
extendTypes: props.extendTypes
|
|
@@ -399,7 +384,7 @@ function Form(props) {
|
|
|
399
384
|
htmlType: "submit",
|
|
400
385
|
type: "primary",
|
|
401
386
|
loading
|
|
402
|
-
}, ((
|
|
387
|
+
}, ((_b = props.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
|
|
403
388
|
}
|
|
404
389
|
Form.useForm = AntdForm2.useForm;
|
|
405
390
|
Form.Item = FormItem;
|
|
@@ -413,11 +398,11 @@ import {
|
|
|
413
398
|
Routes as OriginRoutes,
|
|
414
399
|
Route
|
|
415
400
|
} from "react-router-dom";
|
|
416
|
-
function
|
|
401
|
+
function NotFound() {
|
|
402
|
+
const [config] = useFaasState();
|
|
417
403
|
return /* @__PURE__ */ React.createElement(Result, {
|
|
418
404
|
status: "404",
|
|
419
|
-
title:
|
|
420
|
-
subTitle: "Page not found"
|
|
405
|
+
title: config.common.pageNotFound
|
|
421
406
|
});
|
|
422
407
|
}
|
|
423
408
|
function Routes(props) {
|
|
@@ -425,21 +410,22 @@ function Routes(props) {
|
|
|
425
410
|
key: r.path
|
|
426
411
|
}, r), {
|
|
427
412
|
element: r.element || /* @__PURE__ */ React.createElement(Suspense, {
|
|
428
|
-
fallback: /* @__PURE__ */ React.createElement(Skeleton, {
|
|
429
|
-
active: true
|
|
413
|
+
fallback: props.fallback || /* @__PURE__ */ React.createElement(Skeleton, {
|
|
414
|
+
active: true,
|
|
415
|
+
style: { padding: "24px" }
|
|
430
416
|
})
|
|
431
417
|
}, /* @__PURE__ */ React.createElement(r.page, null))
|
|
432
418
|
}))), /* @__PURE__ */ React.createElement(Route, {
|
|
433
419
|
key: "*",
|
|
434
420
|
path: "*",
|
|
435
|
-
element: props.notFound || /* @__PURE__ */ React.createElement(
|
|
421
|
+
element: props.notFound || /* @__PURE__ */ React.createElement(NotFound, null)
|
|
436
422
|
}));
|
|
437
423
|
}
|
|
438
424
|
|
|
439
425
|
// src/Table.tsx
|
|
440
426
|
import {
|
|
441
|
-
useState as
|
|
442
|
-
useEffect as
|
|
427
|
+
useState as useState5,
|
|
428
|
+
useEffect as useEffect5,
|
|
443
429
|
cloneElement as cloneElement2
|
|
444
430
|
} from "react";
|
|
445
431
|
import {
|
|
@@ -448,24 +434,25 @@ import {
|
|
|
448
434
|
} from "antd";
|
|
449
435
|
import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
|
|
450
436
|
import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
|
|
437
|
+
import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
|
|
451
438
|
function processValue(item, value) {
|
|
452
|
-
var
|
|
439
|
+
var _a;
|
|
453
440
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
454
441
|
if (item.type.endsWith("[]"))
|
|
455
442
|
return value.map((v) => {
|
|
456
|
-
var
|
|
457
|
-
return ((
|
|
443
|
+
var _a2;
|
|
444
|
+
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
458
445
|
});
|
|
459
446
|
else
|
|
460
|
-
return ((
|
|
447
|
+
return ((_a = item.options.find((option) => option.value === value)) == null ? void 0 : _a.label) || value;
|
|
461
448
|
}
|
|
462
449
|
return value;
|
|
463
450
|
}
|
|
464
451
|
function Table(props) {
|
|
465
|
-
const [columns, setColumns] =
|
|
452
|
+
const [columns, setColumns] = useState5();
|
|
466
453
|
const [config] = useFaasState();
|
|
467
|
-
|
|
468
|
-
var
|
|
454
|
+
useEffect5(() => {
|
|
455
|
+
var _a;
|
|
469
456
|
for (const item of props.items) {
|
|
470
457
|
if (!item.key)
|
|
471
458
|
item.key = item.id;
|
|
@@ -475,7 +462,7 @@ function Table(props) {
|
|
|
475
462
|
item.title = upperFirst4(item.id);
|
|
476
463
|
if (!item.type)
|
|
477
464
|
item.type = "string";
|
|
478
|
-
if ((
|
|
465
|
+
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
479
466
|
item.options = transferOptions(item.options);
|
|
480
467
|
item.filters = item.options.map((o) => ({
|
|
481
468
|
text: o.label,
|
|
@@ -583,20 +570,52 @@ function Table(props) {
|
|
|
583
570
|
}, [props.items]);
|
|
584
571
|
if (!columns)
|
|
585
572
|
return null;
|
|
586
|
-
|
|
587
|
-
|
|
573
|
+
if (!props.faasData)
|
|
574
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
588
575
|
rowKey: props.rowKey || "id",
|
|
589
576
|
columns,
|
|
590
|
-
dataSource:
|
|
591
|
-
}))
|
|
592
|
-
|
|
577
|
+
dataSource: props.dataSource
|
|
578
|
+
}));
|
|
579
|
+
return /* @__PURE__ */ React.createElement(FaasDataWrapper2, __spreadValues({
|
|
580
|
+
render: ({
|
|
581
|
+
data,
|
|
582
|
+
params,
|
|
583
|
+
reload
|
|
584
|
+
}) => {
|
|
585
|
+
if (!data)
|
|
586
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
587
|
+
rowKey: props.rowKey || "id",
|
|
588
|
+
columns,
|
|
589
|
+
dataSource: []
|
|
590
|
+
}));
|
|
591
|
+
if (Array.isArray(data))
|
|
592
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
593
|
+
rowKey: props.rowKey || "id",
|
|
594
|
+
columns,
|
|
595
|
+
dataSource: data
|
|
596
|
+
}));
|
|
597
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
598
|
+
rowKey: props.rowKey || "id",
|
|
599
|
+
columns,
|
|
600
|
+
dataSource: data.rows,
|
|
601
|
+
pagination: __spreadValues(__spreadValues({}, props.pagination), data.pagination),
|
|
602
|
+
onChange: (pagination, filters, sorter) => {
|
|
603
|
+
reload(__spreadProps(__spreadValues({}, params), {
|
|
604
|
+
pagination,
|
|
605
|
+
filters,
|
|
606
|
+
sorter
|
|
607
|
+
}));
|
|
608
|
+
}
|
|
609
|
+
}));
|
|
610
|
+
}
|
|
611
|
+
}, props.faasData));
|
|
593
612
|
}
|
|
594
613
|
|
|
595
614
|
// src/Title.tsx
|
|
596
|
-
import { useEffect as
|
|
615
|
+
import { useEffect as useEffect6 } from "react";
|
|
597
616
|
function Title(props) {
|
|
598
617
|
const [config] = useFaasState();
|
|
599
|
-
|
|
618
|
+
useEffect6(() => {
|
|
600
619
|
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
601
620
|
document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
|
|
602
621
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.358",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"homepage": "https://faasjs.com/doc/ant-design.html",
|
|
8
9
|
"repository": {
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"lodash": "*",
|
|
28
29
|
"react": "*",
|
|
29
30
|
"react-dom": "*",
|
|
30
|
-
"@faasjs/react": "^0.0.2-beta.
|
|
31
|
+
"@faasjs/react": "^0.0.2-beta.358",
|
|
31
32
|
"react-use": "*",
|
|
32
33
|
"react-router-dom": "*"
|
|
33
34
|
},
|