@faasjs/ant-design 0.0.2-beta.355 → 0.0.2-beta.359
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 +10 -21
- package/dist/index.js +106 -83
- package/dist/index.mjs +105 -84
- 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,23 +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
|
-
declare function FaasDataWrapper<T = any>({ dataSource, faasData, render, fallback, }: FaasDataWrapperProps<T>): JSX.Element;
|
|
84
|
-
|
|
85
70
|
declare type ExtendDescriptionTypeProps = {
|
|
86
71
|
children?: JSX.Element | null;
|
|
87
72
|
render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
|
|
@@ -96,7 +81,9 @@ declare type DescriptionProps<T = any, ExtendItemProps = any> = {
|
|
|
96
81
|
extendTypes?: {
|
|
97
82
|
[key: string]: ExtendDescriptionTypeProps;
|
|
98
83
|
};
|
|
99
|
-
|
|
84
|
+
dataSource?: T;
|
|
85
|
+
faasData?: FaasDataWrapperProps<T>;
|
|
86
|
+
} & DescriptionsProps;
|
|
100
87
|
declare function Description<T = any>(props: DescriptionProps<T>): JSX.Element;
|
|
101
88
|
|
|
102
89
|
declare type DrawerProps = DrawerProps$1 & {
|
|
@@ -172,6 +159,7 @@ declare type RoutesProps = {
|
|
|
172
159
|
routes: (RouteProps & {
|
|
173
160
|
page?: LazyExoticComponent<ComponentType<any>>;
|
|
174
161
|
})[];
|
|
162
|
+
fallback?: JSX.Element;
|
|
175
163
|
notFound?: JSX.Element;
|
|
176
164
|
};
|
|
177
165
|
declare function Routes(props: RoutesProps): JSX.Element;
|
|
@@ -190,7 +178,8 @@ declare type TableProps<T = any, ExtendTypes = any> = {
|
|
|
190
178
|
extendTypes?: {
|
|
191
179
|
[key: string]: ExtendTableTypeProps;
|
|
192
180
|
};
|
|
193
|
-
|
|
181
|
+
faasData?: FaasDataWrapperProps<T>;
|
|
182
|
+
} & TableProps$1<T>;
|
|
194
183
|
declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
|
|
195
184
|
|
|
196
185
|
declare type TitleProps = {
|
|
@@ -201,4 +190,4 @@ declare type TitleProps = {
|
|
|
201
190
|
};
|
|
202
191
|
declare function Title(props: TitleProps): JSX.Element;
|
|
203
192
|
|
|
204
|
-
export { BaseItemProps, BaseOption, Blank, BlankProps, Config, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps,
|
|
193
|
+
export { BaseItemProps, BaseOption, Blank, BlankProps, Config, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, FaasState, Form, FormItem, FormItemProps, FormProps, Routes, RoutesProps, Table, TableItemProps, TableProps, Title, TitleProps, transferOptions, useDrawer, useFaasState };
|
package/dist/index.js
CHANGED
|
@@ -50,7 +50,6 @@ __export(src_exports, {
|
|
|
50
50
|
Config: () => Config,
|
|
51
51
|
Description: () => Description,
|
|
52
52
|
Drawer: () => import_antd3.Drawer,
|
|
53
|
-
FaasDataWrapper: () => FaasDataWrapper,
|
|
54
53
|
Form: () => Form,
|
|
55
54
|
FormItem: () => FormItem,
|
|
56
55
|
Routes: () => Routes,
|
|
@@ -71,11 +70,17 @@ var import_lodash = require("lodash");
|
|
|
71
70
|
// src/Config.tsx
|
|
72
71
|
var import_react2 = require("react");
|
|
73
72
|
var import_react_use = require("react-use");
|
|
74
|
-
var
|
|
75
|
-
var common = {
|
|
76
|
-
blank:
|
|
77
|
-
all:
|
|
78
|
-
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"
|
|
79
84
|
};
|
|
80
85
|
var useFaasState = (0, import_react_use.createGlobalState)({
|
|
81
86
|
common,
|
|
@@ -117,56 +122,28 @@ function transferOptions(options) {
|
|
|
117
122
|
var import_icons = require("@ant-design/icons");
|
|
118
123
|
var import_antd2 = require("antd");
|
|
119
124
|
var import_lodash3 = require("lodash");
|
|
120
|
-
var import_react5 = require("react");
|
|
121
|
-
|
|
122
|
-
// src/FaasDataWrapper.tsx
|
|
123
125
|
var import_react3 = require("react");
|
|
124
126
|
var import_react4 = require("@faasjs/react");
|
|
125
|
-
function FaasDataWrapper({
|
|
126
|
-
dataSource,
|
|
127
|
-
faasData,
|
|
128
|
-
render,
|
|
129
|
-
fallback
|
|
130
|
-
}) {
|
|
131
|
-
const [data, setData] = (0, import_react3.useState)();
|
|
132
|
-
(0, import_react3.useEffect)(() => {
|
|
133
|
-
if (!faasData)
|
|
134
|
-
return;
|
|
135
|
-
(0, import_react4.getClient)().faas(faasData.action, faasData.params).then((res) => {
|
|
136
|
-
if (faasData.setData)
|
|
137
|
-
faasData.setData(res.data);
|
|
138
|
-
else
|
|
139
|
-
setData(res.data);
|
|
140
|
-
});
|
|
141
|
-
}, [JSON.stringify([faasData == null ? void 0 : faasData.action, faasData == null ? void 0 : faasData.params])]);
|
|
142
|
-
if (dataSource)
|
|
143
|
-
return render({ data: dataSource });
|
|
144
|
-
if (!data && !faasData.data)
|
|
145
|
-
return fallback || null;
|
|
146
|
-
return render({ data: faasData.data || data });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// src/Description.tsx
|
|
150
127
|
function DescriptionItemContent(props) {
|
|
151
|
-
const [computedProps, setComputedProps] = (0,
|
|
152
|
-
(0,
|
|
153
|
-
var
|
|
128
|
+
const [computedProps, setComputedProps] = (0, import_react3.useState)();
|
|
129
|
+
(0, import_react3.useEffect)(() => {
|
|
130
|
+
var _a, _b;
|
|
154
131
|
const propsCopy = __spreadValues({}, props);
|
|
155
132
|
if (!propsCopy.item.title)
|
|
156
133
|
propsCopy.item.title = (0, import_lodash3.upperFirst)(propsCopy.item.id);
|
|
157
134
|
if (!propsCopy.item.type)
|
|
158
135
|
propsCopy.item.type = "string";
|
|
159
|
-
if ((
|
|
136
|
+
if ((_a = propsCopy.item.options) == null ? void 0 : _a.length) {
|
|
160
137
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
161
138
|
}
|
|
162
139
|
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
163
140
|
if (propsCopy.item.type.endsWith("[]"))
|
|
164
141
|
propsCopy.value = propsCopy.value.map((v) => {
|
|
165
|
-
var
|
|
166
|
-
return ((
|
|
142
|
+
var _a2;
|
|
143
|
+
return ((_a2 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
167
144
|
});
|
|
168
145
|
else
|
|
169
|
-
propsCopy.value = ((
|
|
146
|
+
propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
|
|
170
147
|
}
|
|
171
148
|
setComputedProps(propsCopy);
|
|
172
149
|
}, [props]);
|
|
@@ -174,7 +151,7 @@ function DescriptionItemContent(props) {
|
|
|
174
151
|
return null;
|
|
175
152
|
if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
|
|
176
153
|
if (computedProps.extendTypes[computedProps.item.type].children)
|
|
177
|
-
return (0,
|
|
154
|
+
return (0, import_react3.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
|
|
178
155
|
value: computedProps.value,
|
|
179
156
|
values: computedProps.values
|
|
180
157
|
});
|
|
@@ -183,7 +160,7 @@ function DescriptionItemContent(props) {
|
|
|
183
160
|
else
|
|
184
161
|
throw Error(computedProps.item.type + " requires children or render");
|
|
185
162
|
if (computedProps.item.children)
|
|
186
|
-
return (0,
|
|
163
|
+
return (0, import_react3.cloneElement)(computedProps.item.children, { value: computedProps.value });
|
|
187
164
|
if (computedProps.item.render)
|
|
188
165
|
return computedProps.item.render(computedProps.value, computedProps.values);
|
|
189
166
|
if (typeof computedProps.value === "undefined" || computedProps.value === null)
|
|
@@ -212,7 +189,17 @@ function DescriptionItemContent(props) {
|
|
|
212
189
|
}
|
|
213
190
|
}
|
|
214
191
|
function Description(props) {
|
|
215
|
-
|
|
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({
|
|
216
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, {
|
|
217
204
|
key: item.id,
|
|
218
205
|
label: item.title || (0, import_lodash3.upperFirst)(item.id)
|
|
@@ -222,14 +209,14 @@ function Description(props) {
|
|
|
222
209
|
values: data,
|
|
223
210
|
extendTypes: props.extendTypes
|
|
224
211
|
}))))
|
|
225
|
-
}));
|
|
212
|
+
}, props.faasData));
|
|
226
213
|
}
|
|
227
214
|
|
|
228
215
|
// src/Drawer.tsx
|
|
229
216
|
var import_antd3 = require("antd");
|
|
230
|
-
var
|
|
217
|
+
var import_react5 = require("react");
|
|
231
218
|
function useDrawer(init) {
|
|
232
|
-
const [props, setProps] = (0,
|
|
219
|
+
const [props, setProps] = (0, import_react5.useState)(__spreadValues({
|
|
233
220
|
visible: false,
|
|
234
221
|
onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
235
222
|
visible: false
|
|
@@ -246,16 +233,16 @@ function useDrawer(init) {
|
|
|
246
233
|
|
|
247
234
|
// src/Form.tsx
|
|
248
235
|
var import_antd5 = require("antd");
|
|
249
|
-
var
|
|
236
|
+
var import_react7 = require("react");
|
|
250
237
|
|
|
251
238
|
// src/FormItem.tsx
|
|
252
239
|
var import_antd4 = require("antd");
|
|
253
240
|
var import_icons2 = require("@ant-design/icons");
|
|
254
|
-
var
|
|
241
|
+
var import_react6 = require("react");
|
|
255
242
|
var import_lodash4 = require("lodash");
|
|
256
243
|
function FormItem(props) {
|
|
257
|
-
const [computedProps, setComputedProps] = (0,
|
|
258
|
-
(0,
|
|
244
|
+
const [computedProps, setComputedProps] = (0, import_react6.useState)();
|
|
245
|
+
(0, import_react6.useEffect)(() => {
|
|
259
246
|
const propsCopy = __spreadValues({}, props);
|
|
260
247
|
if (!propsCopy.title)
|
|
261
248
|
propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
|
|
@@ -353,11 +340,11 @@ function FormItem(props) {
|
|
|
353
340
|
name: computedProps.name,
|
|
354
341
|
rules: computedProps.rules
|
|
355
342
|
}, (fields, { add, remove }, { errors }) => {
|
|
356
|
-
var
|
|
343
|
+
var _a;
|
|
357
344
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
358
345
|
className: "ant-form-item-label"
|
|
359
346
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
360
|
-
className: ((
|
|
347
|
+
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
|
361
348
|
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
362
349
|
key: field.key
|
|
363
350
|
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
@@ -394,11 +381,11 @@ function FormItem(props) {
|
|
|
394
381
|
|
|
395
382
|
// src/Form.tsx
|
|
396
383
|
function Form(props) {
|
|
397
|
-
var
|
|
398
|
-
const [loading, setLoading] = (0,
|
|
399
|
-
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)();
|
|
400
387
|
const [config] = useFaasState();
|
|
401
|
-
(0,
|
|
388
|
+
(0, import_react7.useEffect)(() => {
|
|
402
389
|
const propsCopy = __spreadValues({}, props);
|
|
403
390
|
if (propsCopy.onFinish) {
|
|
404
391
|
propsCopy.onFinish = async (values) => {
|
|
@@ -415,7 +402,7 @@ function Form(props) {
|
|
|
415
402
|
}, []);
|
|
416
403
|
if (!computedProps)
|
|
417
404
|
return null;
|
|
418
|
-
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({
|
|
419
406
|
key: item.id
|
|
420
407
|
}, item), {
|
|
421
408
|
extendTypes: props.extendTypes
|
|
@@ -423,61 +410,64 @@ function Form(props) {
|
|
|
423
410
|
htmlType: "submit",
|
|
424
411
|
type: "primary",
|
|
425
412
|
loading
|
|
426
|
-
}, ((
|
|
413
|
+
}, ((_b = props.submit) == null ? void 0 : _b.text) || config.Form.submit.text));
|
|
427
414
|
}
|
|
428
415
|
Form.useForm = import_antd5.Form.useForm;
|
|
429
416
|
Form.Item = FormItem;
|
|
430
417
|
|
|
431
418
|
// src/Routers.tsx
|
|
432
419
|
var import_antd6 = require("antd");
|
|
433
|
-
var
|
|
420
|
+
var import_react8 = require("react");
|
|
434
421
|
var import_react_router_dom = require("react-router-dom");
|
|
435
|
-
function
|
|
422
|
+
function NotFound() {
|
|
423
|
+
const [config] = useFaasState();
|
|
436
424
|
return /* @__PURE__ */ import_react.default.createElement(import_antd6.Result, {
|
|
437
425
|
status: "404",
|
|
438
|
-
title:
|
|
439
|
-
subTitle: "Page not found"
|
|
426
|
+
title: config.common.pageNotFound
|
|
440
427
|
});
|
|
441
428
|
}
|
|
442
429
|
function Routes(props) {
|
|
443
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({
|
|
444
431
|
key: r.path
|
|
445
432
|
}, r), {
|
|
446
|
-
element: r.element || /* @__PURE__ */ import_react.default.createElement(
|
|
447
|
-
fallback: /* @__PURE__ */ import_react.default.createElement(
|
|
433
|
+
element: r.element || /* @__PURE__ */ import_react.default.createElement(import_react8.Suspense, {
|
|
434
|
+
fallback: props.fallback || /* @__PURE__ */ import_react.default.createElement("div", {
|
|
435
|
+
style: { padding: "24px" }
|
|
436
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd6.Skeleton, {
|
|
448
437
|
active: true
|
|
449
|
-
})
|
|
438
|
+
}))
|
|
450
439
|
}, /* @__PURE__ */ import_react.default.createElement(r.page, null))
|
|
451
440
|
}))), /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, {
|
|
452
441
|
key: "*",
|
|
453
442
|
path: "*",
|
|
454
|
-
element: props.notFound || /* @__PURE__ */ import_react.default.createElement(
|
|
443
|
+
element: props.notFound || /* @__PURE__ */ import_react.default.createElement(NotFound, null)
|
|
455
444
|
}));
|
|
456
445
|
}
|
|
457
446
|
|
|
458
447
|
// src/Table.tsx
|
|
459
|
-
var
|
|
448
|
+
var import_react9 = require("react");
|
|
460
449
|
var import_antd7 = require("antd");
|
|
461
450
|
var import_icons3 = require("@ant-design/icons");
|
|
462
451
|
var import_lodash5 = require("lodash");
|
|
452
|
+
var import_react10 = require("@faasjs/react");
|
|
463
453
|
function processValue(item, value) {
|
|
464
|
-
var
|
|
454
|
+
var _a;
|
|
465
455
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
466
456
|
if (item.type.endsWith("[]"))
|
|
467
457
|
return value.map((v) => {
|
|
468
|
-
var
|
|
469
|
-
return ((
|
|
458
|
+
var _a2;
|
|
459
|
+
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
470
460
|
});
|
|
471
461
|
else
|
|
472
|
-
return ((
|
|
462
|
+
return ((_a = item.options.find((option) => option.value === value)) == null ? void 0 : _a.label) || value;
|
|
473
463
|
}
|
|
474
464
|
return value;
|
|
475
465
|
}
|
|
476
466
|
function Table(props) {
|
|
477
|
-
const [columns, setColumns] = (0,
|
|
467
|
+
const [columns, setColumns] = (0, import_react9.useState)();
|
|
478
468
|
const [config] = useFaasState();
|
|
479
|
-
(0,
|
|
480
|
-
var
|
|
469
|
+
(0, import_react9.useEffect)(() => {
|
|
470
|
+
var _a;
|
|
481
471
|
for (const item of props.items) {
|
|
482
472
|
if (!item.key)
|
|
483
473
|
item.key = item.id;
|
|
@@ -487,7 +477,7 @@ function Table(props) {
|
|
|
487
477
|
item.title = (0, import_lodash5.upperFirst)(item.id);
|
|
488
478
|
if (!item.type)
|
|
489
479
|
item.type = "string";
|
|
490
|
-
if ((
|
|
480
|
+
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
491
481
|
item.options = transferOptions(item.options);
|
|
492
482
|
item.filters = item.options.map((o) => ({
|
|
493
483
|
text: o.label,
|
|
@@ -500,7 +490,7 @@ function Table(props) {
|
|
|
500
490
|
delete item.children;
|
|
501
491
|
if (props.extendTypes && props.extendTypes[item.type]) {
|
|
502
492
|
if (props.extendTypes[item.type].children) {
|
|
503
|
-
item.render = (value, values) => (0,
|
|
493
|
+
item.render = (value, values) => (0, import_react9.cloneElement)(props.extendTypes[item.type].children, {
|
|
504
494
|
value,
|
|
505
495
|
values
|
|
506
496
|
});
|
|
@@ -595,13 +585,47 @@ function Table(props) {
|
|
|
595
585
|
}, [props.items]);
|
|
596
586
|
if (!columns)
|
|
597
587
|
return null;
|
|
598
|
-
|
|
599
|
-
|
|
588
|
+
if (!props.faasData)
|
|
589
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
600
590
|
rowKey: props.rowKey || "id",
|
|
601
591
|
columns,
|
|
602
|
-
dataSource:
|
|
603
|
-
}))
|
|
604
|
-
|
|
592
|
+
dataSource: props.dataSource
|
|
593
|
+
}));
|
|
594
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react10.FaasDataWrapper, __spreadValues({
|
|
595
|
+
render: ({
|
|
596
|
+
data,
|
|
597
|
+
params,
|
|
598
|
+
reload
|
|
599
|
+
}) => {
|
|
600
|
+
if (!data)
|
|
601
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
602
|
+
rowKey: props.rowKey || "id",
|
|
603
|
+
columns,
|
|
604
|
+
dataSource: []
|
|
605
|
+
}));
|
|
606
|
+
if (Array.isArray(data))
|
|
607
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
608
|
+
rowKey: props.rowKey || "id",
|
|
609
|
+
columns,
|
|
610
|
+
dataSource: data
|
|
611
|
+
}));
|
|
612
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
613
|
+
rowKey: props.rowKey || "id",
|
|
614
|
+
columns,
|
|
615
|
+
dataSource: data.rows,
|
|
616
|
+
pagination: __spreadValues(__spreadValues({}, props.pagination), data.pagination),
|
|
617
|
+
onChange: (pagination, filters, sorter, extra) => {
|
|
618
|
+
if (props.onChange)
|
|
619
|
+
props.onChange(pagination, filters, sorter, extra);
|
|
620
|
+
reload(__spreadProps(__spreadValues({}, params), {
|
|
621
|
+
pagination,
|
|
622
|
+
filters,
|
|
623
|
+
sorter
|
|
624
|
+
}));
|
|
625
|
+
}
|
|
626
|
+
}));
|
|
627
|
+
}
|
|
628
|
+
}, props.faasData));
|
|
605
629
|
}
|
|
606
630
|
|
|
607
631
|
// src/Title.tsx
|
|
@@ -621,7 +645,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
621
645
|
Config,
|
|
622
646
|
Description,
|
|
623
647
|
Drawer,
|
|
624
|
-
FaasDataWrapper,
|
|
625
648
|
Form,
|
|
626
649
|
FormItem,
|
|
627
650
|
Routes,
|
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,23 @@ 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(
|
|
413
|
+
fallback: props.fallback || /* @__PURE__ */ React.createElement("div", {
|
|
414
|
+
style: { padding: "24px" }
|
|
415
|
+
}, /* @__PURE__ */ React.createElement(Skeleton, {
|
|
429
416
|
active: true
|
|
430
|
-
})
|
|
417
|
+
}))
|
|
431
418
|
}, /* @__PURE__ */ React.createElement(r.page, null))
|
|
432
419
|
}))), /* @__PURE__ */ React.createElement(Route, {
|
|
433
420
|
key: "*",
|
|
434
421
|
path: "*",
|
|
435
|
-
element: props.notFound || /* @__PURE__ */ React.createElement(
|
|
422
|
+
element: props.notFound || /* @__PURE__ */ React.createElement(NotFound, null)
|
|
436
423
|
}));
|
|
437
424
|
}
|
|
438
425
|
|
|
439
426
|
// src/Table.tsx
|
|
440
427
|
import {
|
|
441
|
-
useState as
|
|
442
|
-
useEffect as
|
|
428
|
+
useState as useState5,
|
|
429
|
+
useEffect as useEffect5,
|
|
443
430
|
cloneElement as cloneElement2
|
|
444
431
|
} from "react";
|
|
445
432
|
import {
|
|
@@ -448,24 +435,25 @@ import {
|
|
|
448
435
|
} from "antd";
|
|
449
436
|
import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
|
|
450
437
|
import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
|
|
438
|
+
import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
|
|
451
439
|
function processValue(item, value) {
|
|
452
|
-
var
|
|
440
|
+
var _a;
|
|
453
441
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
454
442
|
if (item.type.endsWith("[]"))
|
|
455
443
|
return value.map((v) => {
|
|
456
|
-
var
|
|
457
|
-
return ((
|
|
444
|
+
var _a2;
|
|
445
|
+
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
458
446
|
});
|
|
459
447
|
else
|
|
460
|
-
return ((
|
|
448
|
+
return ((_a = item.options.find((option) => option.value === value)) == null ? void 0 : _a.label) || value;
|
|
461
449
|
}
|
|
462
450
|
return value;
|
|
463
451
|
}
|
|
464
452
|
function Table(props) {
|
|
465
|
-
const [columns, setColumns] =
|
|
453
|
+
const [columns, setColumns] = useState5();
|
|
466
454
|
const [config] = useFaasState();
|
|
467
|
-
|
|
468
|
-
var
|
|
455
|
+
useEffect5(() => {
|
|
456
|
+
var _a;
|
|
469
457
|
for (const item of props.items) {
|
|
470
458
|
if (!item.key)
|
|
471
459
|
item.key = item.id;
|
|
@@ -475,7 +463,7 @@ function Table(props) {
|
|
|
475
463
|
item.title = upperFirst4(item.id);
|
|
476
464
|
if (!item.type)
|
|
477
465
|
item.type = "string";
|
|
478
|
-
if ((
|
|
466
|
+
if ((_a = item.options) == null ? void 0 : _a.length) {
|
|
479
467
|
item.options = transferOptions(item.options);
|
|
480
468
|
item.filters = item.options.map((o) => ({
|
|
481
469
|
text: o.label,
|
|
@@ -583,20 +571,54 @@ function Table(props) {
|
|
|
583
571
|
}, [props.items]);
|
|
584
572
|
if (!columns)
|
|
585
573
|
return null;
|
|
586
|
-
|
|
587
|
-
|
|
574
|
+
if (!props.faasData)
|
|
575
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
588
576
|
rowKey: props.rowKey || "id",
|
|
589
577
|
columns,
|
|
590
|
-
dataSource:
|
|
591
|
-
}))
|
|
592
|
-
|
|
578
|
+
dataSource: props.dataSource
|
|
579
|
+
}));
|
|
580
|
+
return /* @__PURE__ */ React.createElement(FaasDataWrapper2, __spreadValues({
|
|
581
|
+
render: ({
|
|
582
|
+
data,
|
|
583
|
+
params,
|
|
584
|
+
reload
|
|
585
|
+
}) => {
|
|
586
|
+
if (!data)
|
|
587
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
588
|
+
rowKey: props.rowKey || "id",
|
|
589
|
+
columns,
|
|
590
|
+
dataSource: []
|
|
591
|
+
}));
|
|
592
|
+
if (Array.isArray(data))
|
|
593
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
594
|
+
rowKey: props.rowKey || "id",
|
|
595
|
+
columns,
|
|
596
|
+
dataSource: data
|
|
597
|
+
}));
|
|
598
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
599
|
+
rowKey: props.rowKey || "id",
|
|
600
|
+
columns,
|
|
601
|
+
dataSource: data.rows,
|
|
602
|
+
pagination: __spreadValues(__spreadValues({}, props.pagination), data.pagination),
|
|
603
|
+
onChange: (pagination, filters, sorter, extra) => {
|
|
604
|
+
if (props.onChange)
|
|
605
|
+
props.onChange(pagination, filters, sorter, extra);
|
|
606
|
+
reload(__spreadProps(__spreadValues({}, params), {
|
|
607
|
+
pagination,
|
|
608
|
+
filters,
|
|
609
|
+
sorter
|
|
610
|
+
}));
|
|
611
|
+
}
|
|
612
|
+
}));
|
|
613
|
+
}
|
|
614
|
+
}, props.faasData));
|
|
593
615
|
}
|
|
594
616
|
|
|
595
617
|
// src/Title.tsx
|
|
596
|
-
import { useEffect as
|
|
618
|
+
import { useEffect as useEffect6 } from "react";
|
|
597
619
|
function Title(props) {
|
|
598
620
|
const [config] = useFaasState();
|
|
599
|
-
|
|
621
|
+
useEffect6(() => {
|
|
600
622
|
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
601
623
|
document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
|
|
602
624
|
}, []);
|
|
@@ -607,7 +629,6 @@ export {
|
|
|
607
629
|
Config,
|
|
608
630
|
Description,
|
|
609
631
|
Drawer,
|
|
610
|
-
FaasDataWrapper,
|
|
611
632
|
Form,
|
|
612
633
|
FormItem,
|
|
613
634
|
Routes,
|
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.359",
|
|
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.359",
|
|
31
32
|
"react-use": "*",
|
|
32
33
|
"react-router-dom": "*"
|
|
33
34
|
},
|