@faasjs/ant-design 0.0.2-beta.352 → 0.0.2-beta.356
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 +53 -20
- package/dist/index.js +170 -83
- package/dist/index.mjs +170 -85
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
|
+
import * as react_use_lib_misc_hookState from 'react-use/lib/misc/hookState';
|
|
1
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';
|
|
2
3
|
export { Drawer } from 'antd';
|
|
3
|
-
import {
|
|
4
|
+
import { FaasDataWrapperProps } from '@faasjs/react';
|
|
4
5
|
import * as antd_lib_form_Form from 'antd/lib/form/Form';
|
|
5
6
|
import { RuleObject } from 'rc-field-form/lib/interface';
|
|
7
|
+
import { LazyExoticComponent, ComponentType } from 'react';
|
|
8
|
+
import { RouteProps } from 'react-router-dom';
|
|
6
9
|
|
|
7
|
-
declare
|
|
10
|
+
declare type BlankProps = {
|
|
8
11
|
value?: any;
|
|
9
12
|
text?: string;
|
|
10
|
-
}
|
|
13
|
+
};
|
|
14
|
+
declare function Blank(options?: BlankProps): any;
|
|
15
|
+
|
|
16
|
+
declare type FaasState = {
|
|
17
|
+
common: {
|
|
18
|
+
blank: string;
|
|
19
|
+
all: string;
|
|
20
|
+
submit: string;
|
|
21
|
+
};
|
|
22
|
+
Blank: {
|
|
23
|
+
text: string;
|
|
24
|
+
};
|
|
25
|
+
Form: {
|
|
26
|
+
submit: {
|
|
27
|
+
text: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
Title: {
|
|
31
|
+
separator: string;
|
|
32
|
+
suffix: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
declare const useFaasState: () => [FaasState, (state: react_use_lib_misc_hookState.IHookStateSetAction<FaasState>) => void];
|
|
36
|
+
declare function Config(props: {
|
|
37
|
+
config: Partial<FaasState>;
|
|
38
|
+
}): JSX.Element;
|
|
11
39
|
|
|
12
40
|
declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean';
|
|
13
41
|
declare type FaasItemTypeValue = {
|
|
@@ -38,20 +66,6 @@ declare function transferOptions(options: BaseOption[]): {
|
|
|
38
66
|
value?: string | number;
|
|
39
67
|
}[];
|
|
40
68
|
|
|
41
|
-
declare type FaasDataWrapperProps<T = any> = {
|
|
42
|
-
dataSource?: T;
|
|
43
|
-
faasData?: {
|
|
44
|
-
action: string;
|
|
45
|
-
params?: Record<string, any>;
|
|
46
|
-
data?: T;
|
|
47
|
-
setData?: Dispatch<SetStateAction<T>>;
|
|
48
|
-
};
|
|
49
|
-
render?: (args: {
|
|
50
|
-
data: T;
|
|
51
|
-
}) => JSX.Element;
|
|
52
|
-
fallback?: JSX.Element;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
69
|
declare type ExtendDescriptionTypeProps = {
|
|
56
70
|
children?: JSX.Element | null;
|
|
57
71
|
render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
|
|
@@ -66,7 +80,9 @@ declare type DescriptionProps<T = any, ExtendItemProps = any> = {
|
|
|
66
80
|
extendTypes?: {
|
|
67
81
|
[key: string]: ExtendDescriptionTypeProps;
|
|
68
82
|
};
|
|
69
|
-
|
|
83
|
+
dataSource?: T;
|
|
84
|
+
faasData?: FaasDataWrapperProps<T>;
|
|
85
|
+
} & DescriptionsProps;
|
|
70
86
|
declare function Description<T = any>(props: DescriptionProps<T>): JSX.Element;
|
|
71
87
|
|
|
72
88
|
declare type DrawerProps = DrawerProps$1 & {
|
|
@@ -138,6 +154,14 @@ declare namespace Form {
|
|
|
138
154
|
var Item: typeof FormItem;
|
|
139
155
|
}
|
|
140
156
|
|
|
157
|
+
declare type RoutesProps = {
|
|
158
|
+
routes: (RouteProps & {
|
|
159
|
+
page?: LazyExoticComponent<ComponentType<any>>;
|
|
160
|
+
})[];
|
|
161
|
+
notFound?: JSX.Element;
|
|
162
|
+
};
|
|
163
|
+
declare function Routes(props: RoutesProps): JSX.Element;
|
|
164
|
+
|
|
141
165
|
declare type TableItemProps<T = any> = {
|
|
142
166
|
/** @deprecated use render */
|
|
143
167
|
children?: JSX.Element | null;
|
|
@@ -152,7 +176,16 @@ declare type TableProps<T = any, ExtendTypes = any> = {
|
|
|
152
176
|
extendTypes?: {
|
|
153
177
|
[key: string]: ExtendTableTypeProps;
|
|
154
178
|
};
|
|
155
|
-
|
|
179
|
+
faasData?: FaasDataWrapperProps<T>;
|
|
180
|
+
} & TableProps$1<T>;
|
|
156
181
|
declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
|
|
157
182
|
|
|
158
|
-
|
|
183
|
+
declare type TitleProps = {
|
|
184
|
+
title: string | string[];
|
|
185
|
+
/** ` - ` as default */
|
|
186
|
+
separator?: string;
|
|
187
|
+
suffix?: string;
|
|
188
|
+
};
|
|
189
|
+
declare function Title(props: TitleProps): JSX.Element;
|
|
190
|
+
|
|
191
|
+
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
|
@@ -47,13 +47,17 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
|
47
47
|
var src_exports = {};
|
|
48
48
|
__export(src_exports, {
|
|
49
49
|
Blank: () => Blank,
|
|
50
|
+
Config: () => Config,
|
|
50
51
|
Description: () => Description,
|
|
51
52
|
Drawer: () => import_antd3.Drawer,
|
|
52
53
|
Form: () => Form,
|
|
53
54
|
FormItem: () => FormItem,
|
|
55
|
+
Routes: () => Routes,
|
|
54
56
|
Table: () => Table,
|
|
57
|
+
Title: () => Title,
|
|
55
58
|
transferOptions: () => transferOptions,
|
|
56
|
-
useDrawer: () => useDrawer
|
|
59
|
+
useDrawer: () => useDrawer,
|
|
60
|
+
useFaasState: () => useFaasState
|
|
57
61
|
});
|
|
58
62
|
|
|
59
63
|
// react-shim.js
|
|
@@ -62,12 +66,39 @@ var import_react = __toESM(require("react"));
|
|
|
62
66
|
// src/Blank.tsx
|
|
63
67
|
var import_antd = require("antd");
|
|
64
68
|
var import_lodash = require("lodash");
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
|
|
70
|
+
// src/Config.tsx
|
|
71
|
+
var import_react2 = require("react");
|
|
72
|
+
var import_react_use = require("react-use");
|
|
73
|
+
var _a, _b, _c;
|
|
74
|
+
var common = {
|
|
75
|
+
blank: ((_a = navigator.language) == null ? void 0 : _a.includes("CN")) ? "\u7A7A" : "Empty",
|
|
76
|
+
all: ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u5168\u90E8" : "All",
|
|
77
|
+
submit: ((_c = navigator.language) == null ? void 0 : _c.includes("CN")) ? "\u63D0\u4EA4" : "Submit"
|
|
78
|
+
};
|
|
79
|
+
var useFaasState = (0, import_react_use.createGlobalState)({
|
|
80
|
+
common,
|
|
81
|
+
Blank: { text: common.blank },
|
|
82
|
+
Form: { submit: { text: common.submit } },
|
|
83
|
+
Title: {
|
|
84
|
+
separator: " - ",
|
|
85
|
+
suffix: ""
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
function Config(props) {
|
|
89
|
+
const [_, setState] = useFaasState();
|
|
90
|
+
(0, import_react2.useEffect)(() => {
|
|
91
|
+
setState((prev) => __spreadValues(__spreadValues({}, prev), props.config));
|
|
92
|
+
}, []);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/Blank.tsx
|
|
67
97
|
function Blank(options) {
|
|
98
|
+
const [config] = useFaasState();
|
|
68
99
|
return !options || (0, import_lodash.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ import_react.default.createElement(import_antd.Typography.Text, {
|
|
69
100
|
disabled: true
|
|
70
|
-
}, (options == null ? void 0 : options.text) || text) : options.value;
|
|
101
|
+
}, (options == null ? void 0 : options.text) || config.Blank.text) : options.value;
|
|
71
102
|
}
|
|
72
103
|
|
|
73
104
|
// src/data.ts
|
|
@@ -85,40 +116,12 @@ function transferOptions(options) {
|
|
|
85
116
|
var import_icons = require("@ant-design/icons");
|
|
86
117
|
var import_antd2 = require("antd");
|
|
87
118
|
var import_lodash3 = require("lodash");
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
// src/FaasDataWrapper.tsx
|
|
91
|
-
var import_react2 = require("react");
|
|
92
|
-
var import_react3 = require("@faasjs/react");
|
|
93
|
-
function FaasDataWrapper({
|
|
94
|
-
dataSource,
|
|
95
|
-
faasData,
|
|
96
|
-
render,
|
|
97
|
-
fallback
|
|
98
|
-
}) {
|
|
99
|
-
const [data, setData] = (0, import_react2.useState)();
|
|
100
|
-
(0, import_react2.useEffect)(() => {
|
|
101
|
-
if (!faasData)
|
|
102
|
-
return;
|
|
103
|
-
(0, import_react3.getClient)().faas(faasData.action, faasData.params).then((res) => {
|
|
104
|
-
if (faasData.setData)
|
|
105
|
-
faasData.setData(res.data);
|
|
106
|
-
else
|
|
107
|
-
setData(res.data);
|
|
108
|
-
});
|
|
109
|
-
}, [JSON.stringify([faasData == null ? void 0 : faasData.action, faasData == null ? void 0 : faasData.params])]);
|
|
110
|
-
if (dataSource)
|
|
111
|
-
return render({ data: dataSource });
|
|
112
|
-
if (!data && !faasData.data)
|
|
113
|
-
return fallback || null;
|
|
114
|
-
return render({ data: faasData.data || data });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// src/Description.tsx
|
|
119
|
+
var import_react3 = require("react");
|
|
120
|
+
var import_react4 = require("@faasjs/react");
|
|
118
121
|
function DescriptionItemContent(props) {
|
|
119
|
-
const [computedProps, setComputedProps] = (0,
|
|
120
|
-
(0,
|
|
121
|
-
var _a2,
|
|
122
|
+
const [computedProps, setComputedProps] = (0, import_react3.useState)();
|
|
123
|
+
(0, import_react3.useEffect)(() => {
|
|
124
|
+
var _a2, _b2;
|
|
122
125
|
const propsCopy = __spreadValues({}, props);
|
|
123
126
|
if (!propsCopy.item.title)
|
|
124
127
|
propsCopy.item.title = (0, import_lodash3.upperFirst)(propsCopy.item.id);
|
|
@@ -134,7 +137,7 @@ function DescriptionItemContent(props) {
|
|
|
134
137
|
return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
|
|
135
138
|
});
|
|
136
139
|
else
|
|
137
|
-
propsCopy.value = ((
|
|
140
|
+
propsCopy.value = ((_b2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b2.label) || props.value;
|
|
138
141
|
}
|
|
139
142
|
setComputedProps(propsCopy);
|
|
140
143
|
}, [props]);
|
|
@@ -142,7 +145,7 @@ function DescriptionItemContent(props) {
|
|
|
142
145
|
return null;
|
|
143
146
|
if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
|
|
144
147
|
if (computedProps.extendTypes[computedProps.item.type].children)
|
|
145
|
-
return (0,
|
|
148
|
+
return (0, import_react3.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
|
|
146
149
|
value: computedProps.value,
|
|
147
150
|
values: computedProps.values
|
|
148
151
|
});
|
|
@@ -151,7 +154,7 @@ function DescriptionItemContent(props) {
|
|
|
151
154
|
else
|
|
152
155
|
throw Error(computedProps.item.type + " requires children or render");
|
|
153
156
|
if (computedProps.item.children)
|
|
154
|
-
return (0,
|
|
157
|
+
return (0, import_react3.cloneElement)(computedProps.item.children, { value: computedProps.value });
|
|
155
158
|
if (computedProps.item.render)
|
|
156
159
|
return computedProps.item.render(computedProps.value, computedProps.values);
|
|
157
160
|
if (typeof computedProps.value === "undefined" || computedProps.value === null)
|
|
@@ -180,7 +183,17 @@ function DescriptionItemContent(props) {
|
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
185
|
function Description(props) {
|
|
183
|
-
|
|
186
|
+
if (!props.faasData)
|
|
187
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions.Item, {
|
|
188
|
+
key: item.id,
|
|
189
|
+
label: item.title || (0, import_lodash3.upperFirst)(item.id)
|
|
190
|
+
}, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
|
|
191
|
+
item,
|
|
192
|
+
value: props.dataSource[item.id],
|
|
193
|
+
values: props.dataSource,
|
|
194
|
+
extendTypes: props.extendTypes
|
|
195
|
+
}))));
|
|
196
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react4.FaasDataWrapper, __spreadValues({
|
|
184
197
|
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, {
|
|
185
198
|
key: item.id,
|
|
186
199
|
label: item.title || (0, import_lodash3.upperFirst)(item.id)
|
|
@@ -190,7 +203,7 @@ function Description(props) {
|
|
|
190
203
|
values: data,
|
|
191
204
|
extendTypes: props.extendTypes
|
|
192
205
|
}))))
|
|
193
|
-
}));
|
|
206
|
+
}, props.faasData));
|
|
194
207
|
}
|
|
195
208
|
|
|
196
209
|
// src/Drawer.tsx
|
|
@@ -362,9 +375,10 @@ function FormItem(props) {
|
|
|
362
375
|
|
|
363
376
|
// src/Form.tsx
|
|
364
377
|
function Form(props) {
|
|
365
|
-
var _a2,
|
|
378
|
+
var _a2, _b2;
|
|
366
379
|
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
367
380
|
const [computedProps, setComputedProps] = (0, import_react7.useState)();
|
|
381
|
+
const [config] = useFaasState();
|
|
368
382
|
(0, import_react7.useEffect)(() => {
|
|
369
383
|
const propsCopy = __spreadValues({}, props);
|
|
370
384
|
if (propsCopy.onFinish) {
|
|
@@ -390,16 +404,44 @@ function Form(props) {
|
|
|
390
404
|
htmlType: "submit",
|
|
391
405
|
type: "primary",
|
|
392
406
|
loading
|
|
393
|
-
}, ((
|
|
407
|
+
}, ((_b2 = props.submit) == null ? void 0 : _b2.text) || config.Form.submit.text));
|
|
394
408
|
}
|
|
395
409
|
Form.useForm = import_antd5.Form.useForm;
|
|
396
410
|
Form.Item = FormItem;
|
|
397
411
|
|
|
398
|
-
// src/
|
|
399
|
-
var import_react8 = require("react");
|
|
412
|
+
// src/Routers.tsx
|
|
400
413
|
var import_antd6 = require("antd");
|
|
414
|
+
var import_react8 = require("react");
|
|
415
|
+
var import_react_router_dom = require("react-router-dom");
|
|
416
|
+
function NoMatch() {
|
|
417
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd6.Result, {
|
|
418
|
+
status: "404",
|
|
419
|
+
title: "404",
|
|
420
|
+
subTitle: "Page not found"
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
function Routes(props) {
|
|
424
|
+
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({
|
|
425
|
+
key: r.path
|
|
426
|
+
}, r), {
|
|
427
|
+
element: r.element || /* @__PURE__ */ import_react.default.createElement(import_react8.Suspense, {
|
|
428
|
+
fallback: /* @__PURE__ */ import_react.default.createElement(import_antd6.Skeleton, {
|
|
429
|
+
active: true
|
|
430
|
+
})
|
|
431
|
+
}, /* @__PURE__ */ import_react.default.createElement(r.page, null))
|
|
432
|
+
}))), /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, {
|
|
433
|
+
key: "*",
|
|
434
|
+
path: "*",
|
|
435
|
+
element: props.notFound || /* @__PURE__ */ import_react.default.createElement(NoMatch, null)
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/Table.tsx
|
|
440
|
+
var import_react9 = require("react");
|
|
441
|
+
var import_antd7 = require("antd");
|
|
401
442
|
var import_icons3 = require("@ant-design/icons");
|
|
402
443
|
var import_lodash5 = require("lodash");
|
|
444
|
+
var import_react10 = require("@faasjs/react");
|
|
403
445
|
function processValue(item, value) {
|
|
404
446
|
var _a2;
|
|
405
447
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
@@ -414,8 +456,9 @@ function processValue(item, value) {
|
|
|
414
456
|
return value;
|
|
415
457
|
}
|
|
416
458
|
function Table(props) {
|
|
417
|
-
const [columns, setColumns] = (0,
|
|
418
|
-
|
|
459
|
+
const [columns, setColumns] = (0, import_react9.useState)();
|
|
460
|
+
const [config] = useFaasState();
|
|
461
|
+
(0, import_react9.useEffect)(() => {
|
|
419
462
|
var _a2;
|
|
420
463
|
for (const item of props.items) {
|
|
421
464
|
if (!item.key)
|
|
@@ -439,7 +482,7 @@ function Table(props) {
|
|
|
439
482
|
delete item.children;
|
|
440
483
|
if (props.extendTypes && props.extendTypes[item.type]) {
|
|
441
484
|
if (props.extendTypes[item.type].children) {
|
|
442
|
-
item.render = (value, values) => (0,
|
|
485
|
+
item.render = (value, values) => (0, import_react9.cloneElement)(props.extendTypes[item.type].children, {
|
|
443
486
|
value,
|
|
444
487
|
values
|
|
445
488
|
});
|
|
@@ -484,34 +527,31 @@ function Table(props) {
|
|
|
484
527
|
setSelectedKeys,
|
|
485
528
|
selectedKeys,
|
|
486
529
|
confirm
|
|
487
|
-
}) => {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
value:
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
value: "empty"
|
|
513
|
-
}, ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u7A7A" : "Empty"));
|
|
514
|
-
};
|
|
530
|
+
}) => /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Group, {
|
|
531
|
+
style: { padding: 8 },
|
|
532
|
+
buttonStyle: "solid",
|
|
533
|
+
value: selectedKeys[0],
|
|
534
|
+
onChange: (e) => {
|
|
535
|
+
setSelectedKeys(e.target.value ? [e.target.value] : []);
|
|
536
|
+
confirm();
|
|
537
|
+
}
|
|
538
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, null, config.common.all), /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, {
|
|
539
|
+
value: "true"
|
|
540
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_icons3.CheckOutlined, {
|
|
541
|
+
style: {
|
|
542
|
+
color: "#52c41a",
|
|
543
|
+
verticalAlign: "middle"
|
|
544
|
+
}
|
|
545
|
+
})), /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, {
|
|
546
|
+
value: "false"
|
|
547
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_icons3.CloseOutlined, {
|
|
548
|
+
style: {
|
|
549
|
+
verticalAlign: "middle",
|
|
550
|
+
color: "#ff4d4f"
|
|
551
|
+
}
|
|
552
|
+
})), /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, {
|
|
553
|
+
value: "empty"
|
|
554
|
+
}, config.common.blank));
|
|
515
555
|
if (!item.onFilter)
|
|
516
556
|
item.onFilter = (value, row) => {
|
|
517
557
|
switch (value) {
|
|
@@ -537,23 +577,70 @@ function Table(props) {
|
|
|
537
577
|
}, [props.items]);
|
|
538
578
|
if (!columns)
|
|
539
579
|
return null;
|
|
540
|
-
|
|
541
|
-
|
|
580
|
+
if (!props.faasData)
|
|
581
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
542
582
|
rowKey: props.rowKey || "id",
|
|
543
583
|
columns,
|
|
544
|
-
dataSource:
|
|
545
|
-
}))
|
|
546
|
-
|
|
584
|
+
dataSource: props.dataSource
|
|
585
|
+
}));
|
|
586
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react10.FaasDataWrapper, __spreadValues({
|
|
587
|
+
render: ({
|
|
588
|
+
data,
|
|
589
|
+
params,
|
|
590
|
+
reload
|
|
591
|
+
}) => {
|
|
592
|
+
if (!data)
|
|
593
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
594
|
+
rowKey: props.rowKey || "id",
|
|
595
|
+
columns,
|
|
596
|
+
dataSource: []
|
|
597
|
+
}));
|
|
598
|
+
if (Array.isArray(data))
|
|
599
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
600
|
+
rowKey: props.rowKey || "id",
|
|
601
|
+
columns,
|
|
602
|
+
dataSource: data
|
|
603
|
+
}));
|
|
604
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
|
|
605
|
+
rowKey: props.rowKey || "id",
|
|
606
|
+
columns,
|
|
607
|
+
dataSource: data.rows,
|
|
608
|
+
pagination: data.pagination,
|
|
609
|
+
onChange: (pagination, filters, sorter) => {
|
|
610
|
+
reload(__spreadProps(__spreadValues({}, params), {
|
|
611
|
+
pagination,
|
|
612
|
+
filters,
|
|
613
|
+
sorter
|
|
614
|
+
}));
|
|
615
|
+
}
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
618
|
+
}, props.faasData));
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/Title.tsx
|
|
622
|
+
var import_react11 = require("react");
|
|
623
|
+
function Title(props) {
|
|
624
|
+
const [config] = useFaasState();
|
|
625
|
+
(0, import_react11.useEffect)(() => {
|
|
626
|
+
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
627
|
+
document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
|
|
628
|
+
}, []);
|
|
629
|
+
return null;
|
|
547
630
|
}
|
|
548
631
|
module.exports = __toCommonJS(src_exports);
|
|
549
632
|
// Annotate the CommonJS export names for ESM import in node:
|
|
550
633
|
0 && (module.exports = {
|
|
551
634
|
Blank,
|
|
635
|
+
Config,
|
|
552
636
|
Description,
|
|
553
637
|
Drawer,
|
|
554
638
|
Form,
|
|
555
639
|
FormItem,
|
|
640
|
+
Routes,
|
|
556
641
|
Table,
|
|
642
|
+
Title,
|
|
557
643
|
transferOptions,
|
|
558
|
-
useDrawer
|
|
644
|
+
useDrawer,
|
|
645
|
+
useFaasState
|
|
559
646
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -24,12 +24,39 @@ import React from "react";
|
|
|
24
24
|
// src/Blank.tsx
|
|
25
25
|
import { Typography } from "antd";
|
|
26
26
|
import { isNil } from "lodash";
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
// src/Config.tsx
|
|
29
|
+
import { useEffect } from "react";
|
|
30
|
+
import { createGlobalState } from "react-use";
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
var common = {
|
|
33
|
+
blank: ((_a = navigator.language) == null ? void 0 : _a.includes("CN")) ? "\u7A7A" : "Empty",
|
|
34
|
+
all: ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u5168\u90E8" : "All",
|
|
35
|
+
submit: ((_c = navigator.language) == null ? void 0 : _c.includes("CN")) ? "\u63D0\u4EA4" : "Submit"
|
|
36
|
+
};
|
|
37
|
+
var useFaasState = createGlobalState({
|
|
38
|
+
common,
|
|
39
|
+
Blank: { text: common.blank },
|
|
40
|
+
Form: { submit: { text: common.submit } },
|
|
41
|
+
Title: {
|
|
42
|
+
separator: " - ",
|
|
43
|
+
suffix: ""
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
function Config(props) {
|
|
47
|
+
const [_, setState] = useFaasState();
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
setState((prev) => __spreadValues(__spreadValues({}, prev), props.config));
|
|
50
|
+
}, []);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/Blank.tsx
|
|
29
55
|
function Blank(options) {
|
|
56
|
+
const [config] = useFaasState();
|
|
30
57
|
return !options || isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ React.createElement(Typography.Text, {
|
|
31
58
|
disabled: true
|
|
32
|
-
}, (options == null ? void 0 : options.text) || text) : options.value;
|
|
59
|
+
}, (options == null ? void 0 : options.text) || config.Blank.text) : options.value;
|
|
33
60
|
}
|
|
34
61
|
|
|
35
62
|
// src/data.ts
|
|
@@ -50,44 +77,13 @@ import { upperFirst as upperFirst2 } from "lodash";
|
|
|
50
77
|
import {
|
|
51
78
|
cloneElement,
|
|
52
79
|
useEffect as useEffect2,
|
|
53
|
-
useState as useState2
|
|
54
|
-
} from "react";
|
|
55
|
-
|
|
56
|
-
// src/FaasDataWrapper.tsx
|
|
57
|
-
import {
|
|
58
|
-
useEffect,
|
|
59
80
|
useState
|
|
60
81
|
} from "react";
|
|
61
|
-
import {
|
|
62
|
-
function FaasDataWrapper({
|
|
63
|
-
dataSource,
|
|
64
|
-
faasData,
|
|
65
|
-
render,
|
|
66
|
-
fallback
|
|
67
|
-
}) {
|
|
68
|
-
const [data, setData] = useState();
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (!faasData)
|
|
71
|
-
return;
|
|
72
|
-
getClient().faas(faasData.action, faasData.params).then((res) => {
|
|
73
|
-
if (faasData.setData)
|
|
74
|
-
faasData.setData(res.data);
|
|
75
|
-
else
|
|
76
|
-
setData(res.data);
|
|
77
|
-
});
|
|
78
|
-
}, [JSON.stringify([faasData == null ? void 0 : faasData.action, faasData == null ? void 0 : faasData.params])]);
|
|
79
|
-
if (dataSource)
|
|
80
|
-
return render({ data: dataSource });
|
|
81
|
-
if (!data && !faasData.data)
|
|
82
|
-
return fallback || null;
|
|
83
|
-
return render({ data: faasData.data || data });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/Description.tsx
|
|
82
|
+
import { FaasDataWrapper } from "@faasjs/react";
|
|
87
83
|
function DescriptionItemContent(props) {
|
|
88
|
-
const [computedProps, setComputedProps] =
|
|
84
|
+
const [computedProps, setComputedProps] = useState();
|
|
89
85
|
useEffect2(() => {
|
|
90
|
-
var _a2,
|
|
86
|
+
var _a2, _b2;
|
|
91
87
|
const propsCopy = __spreadValues({}, props);
|
|
92
88
|
if (!propsCopy.item.title)
|
|
93
89
|
propsCopy.item.title = upperFirst2(propsCopy.item.id);
|
|
@@ -103,7 +99,7 @@ function DescriptionItemContent(props) {
|
|
|
103
99
|
return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
|
|
104
100
|
});
|
|
105
101
|
else
|
|
106
|
-
propsCopy.value = ((
|
|
102
|
+
propsCopy.value = ((_b2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b2.label) || props.value;
|
|
107
103
|
}
|
|
108
104
|
setComputedProps(propsCopy);
|
|
109
105
|
}, [props]);
|
|
@@ -149,7 +145,17 @@ function DescriptionItemContent(props) {
|
|
|
149
145
|
}
|
|
150
146
|
}
|
|
151
147
|
function Description(props) {
|
|
152
|
-
|
|
148
|
+
if (!props.faasData)
|
|
149
|
+
return /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
|
|
150
|
+
key: item.id,
|
|
151
|
+
label: item.title || upperFirst2(item.id)
|
|
152
|
+
}, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
|
|
153
|
+
item,
|
|
154
|
+
value: props.dataSource[item.id],
|
|
155
|
+
values: props.dataSource,
|
|
156
|
+
extendTypes: props.extendTypes
|
|
157
|
+
}))));
|
|
158
|
+
return /* @__PURE__ */ React.createElement(FaasDataWrapper, __spreadValues({
|
|
153
159
|
render: ({ data }) => /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
|
|
154
160
|
key: item.id,
|
|
155
161
|
label: item.title || upperFirst2(item.id)
|
|
@@ -159,14 +165,14 @@ function Description(props) {
|
|
|
159
165
|
values: data,
|
|
160
166
|
extendTypes: props.extendTypes
|
|
161
167
|
}))))
|
|
162
|
-
}));
|
|
168
|
+
}, props.faasData));
|
|
163
169
|
}
|
|
164
170
|
|
|
165
171
|
// src/Drawer.tsx
|
|
166
172
|
import { Drawer } from "antd";
|
|
167
|
-
import { useState as
|
|
173
|
+
import { useState as useState2 } from "react";
|
|
168
174
|
function useDrawer(init) {
|
|
169
|
-
const [props, setProps] =
|
|
175
|
+
const [props, setProps] = useState2(__spreadValues({
|
|
170
176
|
visible: false,
|
|
171
177
|
onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
172
178
|
visible: false
|
|
@@ -186,7 +192,7 @@ import {
|
|
|
186
192
|
Button as Button2,
|
|
187
193
|
Form as AntdForm2
|
|
188
194
|
} from "antd";
|
|
189
|
-
import { useEffect as useEffect4, useState as
|
|
195
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
190
196
|
|
|
191
197
|
// src/FormItem.tsx
|
|
192
198
|
import {
|
|
@@ -200,10 +206,10 @@ import {
|
|
|
200
206
|
Select
|
|
201
207
|
} from "antd";
|
|
202
208
|
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
|
203
|
-
import { useEffect as useEffect3, useState as
|
|
209
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
204
210
|
import { upperFirst as upperFirst3 } from "lodash";
|
|
205
211
|
function FormItem(props) {
|
|
206
|
-
const [computedProps, setComputedProps] =
|
|
212
|
+
const [computedProps, setComputedProps] = useState3();
|
|
207
213
|
useEffect3(() => {
|
|
208
214
|
const propsCopy = __spreadValues({}, props);
|
|
209
215
|
if (!propsCopy.title)
|
|
@@ -343,9 +349,10 @@ function FormItem(props) {
|
|
|
343
349
|
|
|
344
350
|
// src/Form.tsx
|
|
345
351
|
function Form(props) {
|
|
346
|
-
var _a2,
|
|
347
|
-
const [loading, setLoading] =
|
|
348
|
-
const [computedProps, setComputedProps] =
|
|
352
|
+
var _a2, _b2;
|
|
353
|
+
const [loading, setLoading] = useState4(false);
|
|
354
|
+
const [computedProps, setComputedProps] = useState4();
|
|
355
|
+
const [config] = useFaasState();
|
|
349
356
|
useEffect4(() => {
|
|
350
357
|
const propsCopy = __spreadValues({}, props);
|
|
351
358
|
if (propsCopy.onFinish) {
|
|
@@ -371,14 +378,46 @@ function Form(props) {
|
|
|
371
378
|
htmlType: "submit",
|
|
372
379
|
type: "primary",
|
|
373
380
|
loading
|
|
374
|
-
}, ((
|
|
381
|
+
}, ((_b2 = props.submit) == null ? void 0 : _b2.text) || config.Form.submit.text));
|
|
375
382
|
}
|
|
376
383
|
Form.useForm = AntdForm2.useForm;
|
|
377
384
|
Form.Item = FormItem;
|
|
378
385
|
|
|
386
|
+
// src/Routers.tsx
|
|
387
|
+
import { Result, Skeleton } from "antd";
|
|
388
|
+
import {
|
|
389
|
+
Suspense
|
|
390
|
+
} from "react";
|
|
391
|
+
import {
|
|
392
|
+
Routes as OriginRoutes,
|
|
393
|
+
Route
|
|
394
|
+
} from "react-router-dom";
|
|
395
|
+
function NoMatch() {
|
|
396
|
+
return /* @__PURE__ */ React.createElement(Result, {
|
|
397
|
+
status: "404",
|
|
398
|
+
title: "404",
|
|
399
|
+
subTitle: "Page not found"
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function Routes(props) {
|
|
403
|
+
return /* @__PURE__ */ React.createElement(OriginRoutes, null, props.routes.map((r) => /* @__PURE__ */ React.createElement(Route, __spreadProps(__spreadValues({
|
|
404
|
+
key: r.path
|
|
405
|
+
}, r), {
|
|
406
|
+
element: r.element || /* @__PURE__ */ React.createElement(Suspense, {
|
|
407
|
+
fallback: /* @__PURE__ */ React.createElement(Skeleton, {
|
|
408
|
+
active: true
|
|
409
|
+
})
|
|
410
|
+
}, /* @__PURE__ */ React.createElement(r.page, null))
|
|
411
|
+
}))), /* @__PURE__ */ React.createElement(Route, {
|
|
412
|
+
key: "*",
|
|
413
|
+
path: "*",
|
|
414
|
+
element: props.notFound || /* @__PURE__ */ React.createElement(NoMatch, null)
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
|
|
379
418
|
// src/Table.tsx
|
|
380
419
|
import {
|
|
381
|
-
useState as
|
|
420
|
+
useState as useState5,
|
|
382
421
|
useEffect as useEffect5,
|
|
383
422
|
cloneElement as cloneElement2
|
|
384
423
|
} from "react";
|
|
@@ -388,6 +427,7 @@ import {
|
|
|
388
427
|
} from "antd";
|
|
389
428
|
import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
|
|
390
429
|
import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
|
|
430
|
+
import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
|
|
391
431
|
function processValue(item, value) {
|
|
392
432
|
var _a2;
|
|
393
433
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
@@ -402,7 +442,8 @@ function processValue(item, value) {
|
|
|
402
442
|
return value;
|
|
403
443
|
}
|
|
404
444
|
function Table(props) {
|
|
405
|
-
const [columns, setColumns] =
|
|
445
|
+
const [columns, setColumns] = useState5();
|
|
446
|
+
const [config] = useFaasState();
|
|
406
447
|
useEffect5(() => {
|
|
407
448
|
var _a2;
|
|
408
449
|
for (const item of props.items) {
|
|
@@ -472,34 +513,31 @@ function Table(props) {
|
|
|
472
513
|
setSelectedKeys,
|
|
473
514
|
selectedKeys,
|
|
474
515
|
confirm
|
|
475
|
-
}) => {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
value:
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
value: "empty"
|
|
501
|
-
}, ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u7A7A" : "Empty"));
|
|
502
|
-
};
|
|
516
|
+
}) => /* @__PURE__ */ React.createElement(Radio.Group, {
|
|
517
|
+
style: { padding: 8 },
|
|
518
|
+
buttonStyle: "solid",
|
|
519
|
+
value: selectedKeys[0],
|
|
520
|
+
onChange: (e) => {
|
|
521
|
+
setSelectedKeys(e.target.value ? [e.target.value] : []);
|
|
522
|
+
confirm();
|
|
523
|
+
}
|
|
524
|
+
}, /* @__PURE__ */ React.createElement(Radio.Button, null, config.common.all), /* @__PURE__ */ React.createElement(Radio.Button, {
|
|
525
|
+
value: "true"
|
|
526
|
+
}, /* @__PURE__ */ React.createElement(CheckOutlined2, {
|
|
527
|
+
style: {
|
|
528
|
+
color: "#52c41a",
|
|
529
|
+
verticalAlign: "middle"
|
|
530
|
+
}
|
|
531
|
+
})), /* @__PURE__ */ React.createElement(Radio.Button, {
|
|
532
|
+
value: "false"
|
|
533
|
+
}, /* @__PURE__ */ React.createElement(CloseOutlined2, {
|
|
534
|
+
style: {
|
|
535
|
+
verticalAlign: "middle",
|
|
536
|
+
color: "#ff4d4f"
|
|
537
|
+
}
|
|
538
|
+
})), /* @__PURE__ */ React.createElement(Radio.Button, {
|
|
539
|
+
value: "empty"
|
|
540
|
+
}, config.common.blank));
|
|
503
541
|
if (!item.onFilter)
|
|
504
542
|
item.onFilter = (value, row) => {
|
|
505
543
|
switch (value) {
|
|
@@ -525,21 +563,68 @@ function Table(props) {
|
|
|
525
563
|
}, [props.items]);
|
|
526
564
|
if (!columns)
|
|
527
565
|
return null;
|
|
528
|
-
|
|
529
|
-
|
|
566
|
+
if (!props.faasData)
|
|
567
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
530
568
|
rowKey: props.rowKey || "id",
|
|
531
569
|
columns,
|
|
532
|
-
dataSource:
|
|
533
|
-
}))
|
|
534
|
-
|
|
570
|
+
dataSource: props.dataSource
|
|
571
|
+
}));
|
|
572
|
+
return /* @__PURE__ */ React.createElement(FaasDataWrapper2, __spreadValues({
|
|
573
|
+
render: ({
|
|
574
|
+
data,
|
|
575
|
+
params,
|
|
576
|
+
reload
|
|
577
|
+
}) => {
|
|
578
|
+
if (!data)
|
|
579
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
580
|
+
rowKey: props.rowKey || "id",
|
|
581
|
+
columns,
|
|
582
|
+
dataSource: []
|
|
583
|
+
}));
|
|
584
|
+
if (Array.isArray(data))
|
|
585
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
586
|
+
rowKey: props.rowKey || "id",
|
|
587
|
+
columns,
|
|
588
|
+
dataSource: data
|
|
589
|
+
}));
|
|
590
|
+
return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
|
|
591
|
+
rowKey: props.rowKey || "id",
|
|
592
|
+
columns,
|
|
593
|
+
dataSource: data.rows,
|
|
594
|
+
pagination: data.pagination,
|
|
595
|
+
onChange: (pagination, filters, sorter) => {
|
|
596
|
+
reload(__spreadProps(__spreadValues({}, params), {
|
|
597
|
+
pagination,
|
|
598
|
+
filters,
|
|
599
|
+
sorter
|
|
600
|
+
}));
|
|
601
|
+
}
|
|
602
|
+
}));
|
|
603
|
+
}
|
|
604
|
+
}, props.faasData));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// src/Title.tsx
|
|
608
|
+
import { useEffect as useEffect6 } from "react";
|
|
609
|
+
function Title(props) {
|
|
610
|
+
const [config] = useFaasState();
|
|
611
|
+
useEffect6(() => {
|
|
612
|
+
const title = Array.isArray(props.title) ? props.title : [props.title];
|
|
613
|
+
document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
|
|
614
|
+
}, []);
|
|
615
|
+
return null;
|
|
535
616
|
}
|
|
536
617
|
export {
|
|
537
618
|
Blank,
|
|
619
|
+
Config,
|
|
538
620
|
Description,
|
|
539
621
|
Drawer,
|
|
540
622
|
Form,
|
|
541
623
|
FormItem,
|
|
624
|
+
Routes,
|
|
542
625
|
Table,
|
|
626
|
+
Title,
|
|
543
627
|
transferOptions,
|
|
544
|
-
useDrawer
|
|
628
|
+
useDrawer,
|
|
629
|
+
useFaasState
|
|
545
630
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.356",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"lodash": "*",
|
|
28
28
|
"react": "*",
|
|
29
29
|
"react-dom": "*",
|
|
30
|
-
"@faasjs/react": "^0.0.2-beta.
|
|
30
|
+
"@faasjs/react": "^0.0.2-beta.356",
|
|
31
|
+
"react-use": "*",
|
|
32
|
+
"react-router-dom": "*"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@types/lodash": "*",
|