@faasjs/ant-design 0.0.2-beta.345 → 0.0.2-beta.349
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 +32 -26
- package/dist/index.js +143 -79
- package/dist/index.mjs +100 -39
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DescriptionsProps, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, FormProps as FormProps$1, TableColumnProps, TableProps as TableProps$1 } from 'antd';
|
|
1
|
+
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
|
+
export { Drawer } from 'antd';
|
|
2
3
|
import * as antd_lib_form_Form from 'antd/lib/form/Form';
|
|
3
4
|
import { RuleObject } from 'rc-field-form/lib/interface';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
declare function Blank(options?: {
|
|
7
7
|
value?: any;
|
|
@@ -16,28 +16,33 @@ declare type FaasItemTypeValue = {
|
|
|
16
16
|
'number[]': number[];
|
|
17
17
|
boolean: boolean;
|
|
18
18
|
};
|
|
19
|
-
declare type
|
|
19
|
+
declare type BaseOption = string | number | {
|
|
20
|
+
label: string;
|
|
21
|
+
value?: string | number;
|
|
22
|
+
};
|
|
23
|
+
declare type BaseItemProps = {
|
|
20
24
|
id: string;
|
|
21
25
|
title?: string;
|
|
26
|
+
options?: BaseOption[];
|
|
22
27
|
};
|
|
23
|
-
declare type FaasItemProps =
|
|
28
|
+
declare type FaasItemProps = BaseItemProps & {
|
|
24
29
|
/**
|
|
25
30
|
* Support string, string[], number, number[], boolean
|
|
26
31
|
* @default 'string'
|
|
27
32
|
*/
|
|
28
33
|
type?: FaasItemType;
|
|
29
34
|
};
|
|
35
|
+
declare function transferOptions(options: BaseOption[]): {
|
|
36
|
+
label: string;
|
|
37
|
+
value?: string | number;
|
|
38
|
+
}[];
|
|
30
39
|
|
|
31
40
|
declare type ExtendDescriptionTypeProps = {
|
|
32
41
|
children?: JSX.Element | null;
|
|
33
42
|
render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
|
|
34
43
|
};
|
|
35
|
-
declare type ExtendDescriptionItemProps =
|
|
44
|
+
declare type ExtendDescriptionItemProps = BaseItemProps;
|
|
36
45
|
declare type DescriptionItemProps<T = any> = {
|
|
37
|
-
options?: {
|
|
38
|
-
label: string;
|
|
39
|
-
value?: T;
|
|
40
|
-
}[];
|
|
41
46
|
children?: JSX.Element;
|
|
42
47
|
render?: (value: T, values: any) => JSX.Element | string | number | boolean | null;
|
|
43
48
|
} & FaasItemProps;
|
|
@@ -54,6 +59,15 @@ declare type DescriptionProps<T = any, ExtendItemProps = any> = {
|
|
|
54
59
|
} & DescriptionsProps;
|
|
55
60
|
declare function Description(props: DescriptionProps): JSX.Element;
|
|
56
61
|
|
|
62
|
+
declare type DrawerProps = DrawerProps$1 & {
|
|
63
|
+
children?: JSX.Element | JSX.Element[];
|
|
64
|
+
};
|
|
65
|
+
declare function useDrawer(init?: DrawerProps): {
|
|
66
|
+
drawer: JSX.Element;
|
|
67
|
+
drawerProps: DrawerProps;
|
|
68
|
+
setDrawerProps(changes: Partial<DrawerProps>): void;
|
|
69
|
+
};
|
|
70
|
+
|
|
57
71
|
declare type StringProps = {
|
|
58
72
|
type?: 'string';
|
|
59
73
|
input?: InputProps;
|
|
@@ -76,24 +90,18 @@ declare type BooleanProps = {
|
|
|
76
90
|
type: 'boolean';
|
|
77
91
|
input?: SwitchProps;
|
|
78
92
|
};
|
|
79
|
-
declare type
|
|
80
|
-
|
|
81
|
-
value?: T;
|
|
82
|
-
disabled?: boolean;
|
|
83
|
-
children?: Omit<OptionType<T>, 'children'>[];
|
|
84
|
-
};
|
|
85
|
-
declare type OptionsProps<T = any> = {
|
|
86
|
-
options?: OptionType<T>[] | string[] | number[];
|
|
93
|
+
declare type OptionsProps = {
|
|
94
|
+
options: BaseOption[];
|
|
87
95
|
type?: 'string' | 'string[]' | 'number' | 'number[]';
|
|
88
96
|
input?: SelectProps<any>;
|
|
89
97
|
};
|
|
90
|
-
declare type FormItemInputProps<T = any> = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps
|
|
98
|
+
declare type FormItemInputProps<T = any> = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps;
|
|
91
99
|
declare type ExtendFormTypeProps = {
|
|
92
100
|
children?: JSX.Element | null;
|
|
93
101
|
};
|
|
94
|
-
declare type ExtendFormItemProps =
|
|
102
|
+
declare type ExtendFormItemProps = BaseItemProps & FormItemProps$1;
|
|
95
103
|
declare type FormItemProps<T = any> = {
|
|
96
|
-
children?: JSX.Element;
|
|
104
|
+
children?: JSX.Element | null;
|
|
97
105
|
rules?: RuleObject[];
|
|
98
106
|
label?: string | false;
|
|
99
107
|
extendTypes?: {
|
|
@@ -120,16 +128,14 @@ declare namespace Form {
|
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
declare type TableItemProps<T = any> = {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
value?: T;
|
|
126
|
-
}[];
|
|
131
|
+
/** @deprecated use render */
|
|
132
|
+
children?: JSX.Element | null;
|
|
127
133
|
} & FaasItemProps & TableColumnProps<T>;
|
|
128
134
|
declare type ExtendTableTypeProps = {
|
|
129
135
|
children?: JSX.Element | null;
|
|
130
136
|
render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
|
|
131
137
|
};
|
|
132
|
-
declare type ExtendTableItemProps<T = any> =
|
|
138
|
+
declare type ExtendTableItemProps<T = any> = BaseItemProps & TableColumnProps<T>;
|
|
133
139
|
declare type TableProps<T = any, ExtendTypes = any> = {
|
|
134
140
|
items: (TableItemProps | (ExtendTypes & ExtendTableItemProps))[];
|
|
135
141
|
extendTypes?: {
|
|
@@ -142,4 +148,4 @@ declare type TableProps<T = any, ExtendTypes = any> = {
|
|
|
142
148
|
} & TableProps$1<T>;
|
|
143
149
|
declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
|
|
144
150
|
|
|
145
|
-
export {
|
|
151
|
+
export { BaseItemProps, BaseOption, Blank, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps, transferOptions, useDrawer };
|
package/dist/index.js
CHANGED
|
@@ -48,9 +48,12 @@ var src_exports = {};
|
|
|
48
48
|
__export(src_exports, {
|
|
49
49
|
Blank: () => Blank,
|
|
50
50
|
Description: () => Description,
|
|
51
|
+
Drawer: () => import_antd3.Drawer,
|
|
51
52
|
Form: () => Form,
|
|
52
53
|
FormItem: () => FormItem,
|
|
53
|
-
Table: () => Table
|
|
54
|
+
Table: () => Table,
|
|
55
|
+
transferOptions: () => transferOptions,
|
|
56
|
+
useDrawer: () => useDrawer
|
|
54
57
|
});
|
|
55
58
|
|
|
56
59
|
// react-shim.js
|
|
@@ -67,10 +70,21 @@ function Blank(options) {
|
|
|
67
70
|
}, (options == null ? void 0 : options.text) || text) : options.value;
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
// src/data.ts
|
|
74
|
+
var import_lodash2 = require("lodash");
|
|
75
|
+
function transferOptions(options) {
|
|
76
|
+
if (!options)
|
|
77
|
+
return [];
|
|
78
|
+
return options.map((item) => typeof item === "object" ? item : {
|
|
79
|
+
label: (0, import_lodash2.upperFirst)(item.toString()),
|
|
80
|
+
value: item
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
70
84
|
// src/Description.tsx
|
|
71
85
|
var import_icons = require("@ant-design/icons");
|
|
72
86
|
var import_antd2 = require("antd");
|
|
73
|
-
var
|
|
87
|
+
var import_lodash3 = require("lodash");
|
|
74
88
|
var import_react4 = require("react");
|
|
75
89
|
|
|
76
90
|
// src/FaasWrapper.tsx
|
|
@@ -86,7 +100,7 @@ function FaasDataWrapper({
|
|
|
86
100
|
(0, import_react2.useEffect)(() => {
|
|
87
101
|
if (!faasData)
|
|
88
102
|
return;
|
|
89
|
-
(0, import_react3.getClient)().faas(faasData.action, faasData.
|
|
103
|
+
(0, import_react3.getClient)().faas(faasData.action, faasData.params).then((res) => setData(res.data));
|
|
90
104
|
}, [JSON.stringify(faasData)]);
|
|
91
105
|
if (dataSource)
|
|
92
106
|
return render({ data: dataSource });
|
|
@@ -99,20 +113,23 @@ function FaasDataWrapper({
|
|
|
99
113
|
function DescriptionItemContent(props) {
|
|
100
114
|
const [computedProps, setComputedProps] = (0, import_react4.useState)();
|
|
101
115
|
(0, import_react4.useEffect)(() => {
|
|
102
|
-
var _a2;
|
|
116
|
+
var _a2, _b;
|
|
103
117
|
const propsCopy = __spreadValues({}, props);
|
|
104
118
|
if (!propsCopy.item.title)
|
|
105
|
-
propsCopy.item.title = (0,
|
|
119
|
+
propsCopy.item.title = (0, import_lodash3.upperFirst)(propsCopy.item.id);
|
|
106
120
|
if (!propsCopy.item.type)
|
|
107
121
|
propsCopy.item.type = "string";
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
123
|
+
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
124
|
+
}
|
|
125
|
+
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
126
|
+
if (propsCopy.item.type.endsWith("[]"))
|
|
127
|
+
propsCopy.value = propsCopy.value.map((v) => {
|
|
111
128
|
var _a3;
|
|
112
|
-
return ((_a3 =
|
|
129
|
+
return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
|
|
113
130
|
});
|
|
114
131
|
else
|
|
115
|
-
propsCopy.value = ((
|
|
132
|
+
propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
|
|
116
133
|
}
|
|
117
134
|
setComputedProps(propsCopy);
|
|
118
135
|
}, [props]);
|
|
@@ -163,7 +180,7 @@ function Description(props) {
|
|
|
163
180
|
faasData: props.faasData,
|
|
164
181
|
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, {
|
|
165
182
|
key: item.id,
|
|
166
|
-
label: item.title || (0,
|
|
183
|
+
label: item.title || (0, import_lodash3.upperFirst)(item.id)
|
|
167
184
|
}, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
|
|
168
185
|
item,
|
|
169
186
|
value: data[item.id],
|
|
@@ -173,20 +190,40 @@ function Description(props) {
|
|
|
173
190
|
});
|
|
174
191
|
}
|
|
175
192
|
|
|
193
|
+
// src/Drawer.tsx
|
|
194
|
+
var import_antd3 = require("antd");
|
|
195
|
+
var import_react5 = require("react");
|
|
196
|
+
function useDrawer(init) {
|
|
197
|
+
const [props, setProps] = (0, import_react5.useState)(__spreadValues({
|
|
198
|
+
visible: false,
|
|
199
|
+
onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
200
|
+
visible: false
|
|
201
|
+
}))
|
|
202
|
+
}, init));
|
|
203
|
+
return {
|
|
204
|
+
drawer: /* @__PURE__ */ import_react.default.createElement(import_antd3.Drawer, __spreadValues({}, props)),
|
|
205
|
+
drawerProps: props,
|
|
206
|
+
setDrawerProps(changes) {
|
|
207
|
+
setProps((prev) => __spreadValues(__spreadValues({}, prev), changes));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
176
212
|
// src/Form.tsx
|
|
177
|
-
var
|
|
213
|
+
var import_antd5 = require("antd");
|
|
214
|
+
var import_react7 = require("react");
|
|
178
215
|
|
|
179
216
|
// src/FormItem.tsx
|
|
180
|
-
var
|
|
217
|
+
var import_antd4 = require("antd");
|
|
181
218
|
var import_icons2 = require("@ant-design/icons");
|
|
182
|
-
var
|
|
183
|
-
var
|
|
219
|
+
var import_react6 = require("react");
|
|
220
|
+
var import_lodash4 = require("lodash");
|
|
184
221
|
function FormItem(props) {
|
|
185
|
-
const [computedProps, setComputedProps] = (0,
|
|
186
|
-
(0,
|
|
222
|
+
const [computedProps, setComputedProps] = (0, import_react6.useState)();
|
|
223
|
+
(0, import_react6.useEffect)(() => {
|
|
187
224
|
const propsCopy = __spreadValues({}, props);
|
|
188
225
|
if (!propsCopy.title)
|
|
189
|
-
propsCopy.title = (0,
|
|
226
|
+
propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
|
|
190
227
|
if (!propsCopy.label && props.label !== false)
|
|
191
228
|
propsCopy.label = propsCopy.title;
|
|
192
229
|
if (!propsCopy.name)
|
|
@@ -212,20 +249,8 @@ function FormItem(props) {
|
|
|
212
249
|
}
|
|
213
250
|
if (!propsCopy.input)
|
|
214
251
|
propsCopy.input = {};
|
|
215
|
-
if (propsCopy.options)
|
|
216
|
-
|
|
217
|
-
if (propsCopy.options.length > 0)
|
|
218
|
-
for (const option of propsCopy.options) {
|
|
219
|
-
if (typeof option === "object")
|
|
220
|
-
options.push(option);
|
|
221
|
-
else
|
|
222
|
-
options.push({
|
|
223
|
-
label: (0, import_lodash3.upperFirst)(option.toString()),
|
|
224
|
-
value: option
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
propsCopy.input.options = options;
|
|
228
|
-
}
|
|
252
|
+
if (propsCopy.options)
|
|
253
|
+
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
229
254
|
switch (propsCopy.type) {
|
|
230
255
|
case "boolean":
|
|
231
256
|
propsCopy.valuePropName = "checked";
|
|
@@ -236,58 +261,58 @@ function FormItem(props) {
|
|
|
236
261
|
if (!computedProps)
|
|
237
262
|
return null;
|
|
238
263
|
if (computedProps.extendTypes && computedProps.extendTypes[computedProps.type])
|
|
239
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
264
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
|
|
240
265
|
if (computedProps.children)
|
|
241
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
266
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.children);
|
|
242
267
|
switch (computedProps.type) {
|
|
243
268
|
case "string":
|
|
244
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
269
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ import_react.default.createElement(import_antd4.Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ import_react.default.createElement(import_antd4.Input, __spreadValues({}, computedProps.input)));
|
|
245
270
|
case "string[]":
|
|
246
271
|
if (computedProps.options)
|
|
247
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
272
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd4.Select, __spreadValues({
|
|
248
273
|
mode: "multiple"
|
|
249
274
|
}, computedProps.input)));
|
|
250
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
275
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.List, {
|
|
251
276
|
name: computedProps.name,
|
|
252
277
|
rules: computedProps.rules
|
|
253
278
|
}, (fields, { add, remove }, { errors }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
254
279
|
className: "ant-form-item-label"
|
|
255
280
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
256
281
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
257
|
-
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ import_react.default.createElement(
|
|
282
|
+
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
258
283
|
key: field.key
|
|
259
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
284
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
260
285
|
gutter: 24
|
|
261
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
286
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
262
287
|
span: 23
|
|
263
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
288
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadProps(__spreadValues({}, field), {
|
|
264
289
|
noStyle: true
|
|
265
|
-
}), /* @__PURE__ */ import_react.default.createElement(
|
|
290
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.Input, __spreadValues({}, computedProps.input)))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
266
291
|
span: 1
|
|
267
|
-
}, (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(
|
|
292
|
+
}, (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
268
293
|
danger: true,
|
|
269
294
|
type: "link",
|
|
270
295
|
style: { float: "right" },
|
|
271
296
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons2.MinusCircleOutlined, null),
|
|
272
297
|
onClick: () => remove(field.name)
|
|
273
|
-
}))))), /* @__PURE__ */ import_react.default.createElement(
|
|
298
|
+
}))))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, null, (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
274
299
|
type: "dashed",
|
|
275
300
|
block: true,
|
|
276
301
|
onClick: () => add(),
|
|
277
302
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons2.PlusOutlined, null)
|
|
278
|
-
}), /* @__PURE__ */ import_react.default.createElement(
|
|
303
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.ErrorList, {
|
|
279
304
|
errors
|
|
280
305
|
}))));
|
|
281
306
|
case "number":
|
|
282
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
307
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ import_react.default.createElement(import_antd4.Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ import_react.default.createElement(import_antd4.InputNumber, __spreadValues({
|
|
283
308
|
style: { width: "100%" }
|
|
284
309
|
}, computedProps.input)));
|
|
285
310
|
case "number[]":
|
|
286
311
|
if (computedProps.options)
|
|
287
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
312
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd4.Select, __spreadValues({
|
|
288
313
|
mode: "multiple"
|
|
289
314
|
}, computedProps.input)));
|
|
290
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
315
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.List, {
|
|
291
316
|
name: computedProps.name,
|
|
292
317
|
rules: computedProps.rules
|
|
293
318
|
}, (fields, { add, remove }, { errors }) => {
|
|
@@ -296,35 +321,35 @@ function FormItem(props) {
|
|
|
296
321
|
className: "ant-form-item-label"
|
|
297
322
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
298
323
|
className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required"
|
|
299
|
-
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ import_react.default.createElement(
|
|
324
|
+
}, computedProps.label)), fields.map((field) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
300
325
|
key: field.key
|
|
301
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
326
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
302
327
|
gutter: 24
|
|
303
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
328
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
304
329
|
span: 23
|
|
305
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
330
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadProps(__spreadValues({}, field), {
|
|
306
331
|
noStyle: true
|
|
307
|
-
}), /* @__PURE__ */ import_react.default.createElement(
|
|
332
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.InputNumber, __spreadValues({
|
|
308
333
|
style: { width: "100%" }
|
|
309
|
-
}, computedProps.input)))), /* @__PURE__ */ import_react.default.createElement(
|
|
334
|
+
}, computedProps.input)))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
310
335
|
span: 1
|
|
311
|
-
}, (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(
|
|
336
|
+
}, (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
312
337
|
danger: true,
|
|
313
338
|
type: "link",
|
|
314
339
|
style: { float: "right" },
|
|
315
340
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons2.MinusCircleOutlined, null),
|
|
316
341
|
onClick: () => remove(field.name)
|
|
317
|
-
}))))), /* @__PURE__ */ import_react.default.createElement(
|
|
342
|
+
}))))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, null, (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
318
343
|
type: "dashed",
|
|
319
344
|
block: true,
|
|
320
345
|
onClick: () => add(),
|
|
321
346
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons2.PlusOutlined, null)
|
|
322
|
-
}), /* @__PURE__ */ import_react.default.createElement(
|
|
347
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.ErrorList, {
|
|
323
348
|
errors
|
|
324
349
|
})));
|
|
325
350
|
});
|
|
326
351
|
case "boolean":
|
|
327
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
352
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd4.Switch, __spreadValues({}, computedProps.input)));
|
|
328
353
|
default:
|
|
329
354
|
return null;
|
|
330
355
|
}
|
|
@@ -333,23 +358,41 @@ function FormItem(props) {
|
|
|
333
358
|
// src/Form.tsx
|
|
334
359
|
function Form(props) {
|
|
335
360
|
var _a2, _b;
|
|
336
|
-
|
|
361
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
362
|
+
const [computedProps, setComputedProps] = (0, import_react7.useState)();
|
|
363
|
+
(0, import_react7.useEffect)(() => {
|
|
364
|
+
const propsCopy = __spreadValues({}, props);
|
|
365
|
+
if (propsCopy.onFinish) {
|
|
366
|
+
propsCopy.onFinish = async (values) => {
|
|
367
|
+
setLoading(true);
|
|
368
|
+
try {
|
|
369
|
+
await propsCopy.onFinish(values);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
console.error(error);
|
|
372
|
+
}
|
|
373
|
+
setLoading(false);
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
setComputedProps(props);
|
|
377
|
+
}, []);
|
|
378
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd5.Form, __spreadValues({}, computedProps), (_a2 = props.items) == null ? void 0 : _a2.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({
|
|
337
379
|
key: item.id
|
|
338
380
|
}, item), {
|
|
339
381
|
extendTypes: props.extendTypes
|
|
340
|
-
}))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(
|
|
382
|
+
}))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd5.Button, {
|
|
341
383
|
htmlType: "submit",
|
|
342
|
-
type: "primary"
|
|
384
|
+
type: "primary",
|
|
385
|
+
loading
|
|
343
386
|
}, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
|
|
344
387
|
}
|
|
345
|
-
Form.useForm =
|
|
388
|
+
Form.useForm = import_antd5.Form.useForm;
|
|
346
389
|
Form.Item = FormItem;
|
|
347
390
|
|
|
348
391
|
// src/Table.tsx
|
|
349
|
-
var
|
|
350
|
-
var
|
|
392
|
+
var import_react8 = require("react");
|
|
393
|
+
var import_antd6 = require("antd");
|
|
351
394
|
var import_icons3 = require("@ant-design/icons");
|
|
352
|
-
var
|
|
395
|
+
var import_lodash5 = require("lodash");
|
|
353
396
|
function processValue(item, value) {
|
|
354
397
|
var _a2;
|
|
355
398
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
@@ -364,22 +407,32 @@ function processValue(item, value) {
|
|
|
364
407
|
return value;
|
|
365
408
|
}
|
|
366
409
|
function Table(props) {
|
|
367
|
-
const [columns, setColumns] = (0,
|
|
368
|
-
(0,
|
|
410
|
+
const [columns, setColumns] = (0, import_react8.useState)();
|
|
411
|
+
(0, import_react8.useEffect)(() => {
|
|
412
|
+
var _a2;
|
|
369
413
|
for (const item of props.items) {
|
|
370
414
|
if (!item.key)
|
|
371
415
|
item.key = item.id;
|
|
372
416
|
if (!item.dataIndex)
|
|
373
417
|
item.dataIndex = item.id;
|
|
374
418
|
if (!item.title)
|
|
375
|
-
item.title = (0,
|
|
419
|
+
item.title = (0, import_lodash5.upperFirst)(item.id);
|
|
376
420
|
if (!item.type)
|
|
377
421
|
item.type = "string";
|
|
422
|
+
if ((_a2 = item.options) == null ? void 0 : _a2.length) {
|
|
423
|
+
item.options = transferOptions(item.options);
|
|
424
|
+
item.filters = item.options.map((o) => ({
|
|
425
|
+
text: o.label,
|
|
426
|
+
value: o.value
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
378
429
|
if (item.render)
|
|
379
430
|
continue;
|
|
431
|
+
if (item.children)
|
|
432
|
+
delete item.children;
|
|
380
433
|
if (props.extendTypes && props.extendTypes[item.type]) {
|
|
381
434
|
if (props.extendTypes[item.type].children) {
|
|
382
|
-
item.render = (value, values) => (0,
|
|
435
|
+
item.render = (value, values) => (0, import_react8.cloneElement)(props.extendTypes[item.type].children, {
|
|
383
436
|
value,
|
|
384
437
|
values
|
|
385
438
|
});
|
|
@@ -392,14 +445,20 @@ function Table(props) {
|
|
|
392
445
|
switch (item.type) {
|
|
393
446
|
case "string[]":
|
|
394
447
|
item.render = (value) => processValue(item, value).join(", ");
|
|
448
|
+
if (!item.onFilter)
|
|
449
|
+
item.onFilter = (value, row) => row[item.id].includes(value);
|
|
395
450
|
break;
|
|
396
451
|
case "number":
|
|
397
452
|
item.render = (value) => processValue(item, value);
|
|
398
453
|
if (!item.sorter)
|
|
399
454
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
455
|
+
if (!item.onFilter)
|
|
456
|
+
item.onFilter = (value, row) => value === row[item.id];
|
|
400
457
|
break;
|
|
401
458
|
case "number[]":
|
|
402
459
|
item.render = (value) => processValue(item, value).join(", ");
|
|
460
|
+
if (!item.onFilter)
|
|
461
|
+
item.onFilter = (value, row) => row[item.id].includes(value);
|
|
403
462
|
break;
|
|
404
463
|
case "boolean":
|
|
405
464
|
item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ import_react.default.createElement(Blank, null) : value ? /* @__PURE__ */ import_react.default.createElement(import_icons3.CheckOutlined, {
|
|
@@ -419,8 +478,8 @@ function Table(props) {
|
|
|
419
478
|
selectedKeys,
|
|
420
479
|
confirm
|
|
421
480
|
}) => {
|
|
422
|
-
var
|
|
423
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
481
|
+
var _a3, _b;
|
|
482
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Group, {
|
|
424
483
|
style: { padding: 8 },
|
|
425
484
|
buttonStyle: "solid",
|
|
426
485
|
value: selectedKeys[0],
|
|
@@ -428,21 +487,21 @@ function Table(props) {
|
|
|
428
487
|
setSelectedKeys(e.target.value ? [e.target.value] : []);
|
|
429
488
|
confirm();
|
|
430
489
|
}
|
|
431
|
-
}, /* @__PURE__ */ import_react.default.createElement(
|
|
490
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, null, ((_a3 = navigator.language) == null ? void 0 : _a3.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, {
|
|
432
491
|
value: "true"
|
|
433
492
|
}, /* @__PURE__ */ import_react.default.createElement(import_icons3.CheckOutlined, {
|
|
434
493
|
style: {
|
|
435
494
|
color: "#52c41a",
|
|
436
495
|
verticalAlign: "middle"
|
|
437
496
|
}
|
|
438
|
-
})), /* @__PURE__ */ import_react.default.createElement(
|
|
497
|
+
})), /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, {
|
|
439
498
|
value: "false"
|
|
440
499
|
}, /* @__PURE__ */ import_react.default.createElement(import_icons3.CloseOutlined, {
|
|
441
500
|
style: {
|
|
442
501
|
verticalAlign: "middle",
|
|
443
502
|
color: "#ff4d4f"
|
|
444
503
|
}
|
|
445
|
-
})), /* @__PURE__ */ import_react.default.createElement(
|
|
504
|
+
})), /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, {
|
|
446
505
|
value: "empty"
|
|
447
506
|
}, ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u7A7A" : "Empty"));
|
|
448
507
|
};
|
|
@@ -450,11 +509,11 @@ function Table(props) {
|
|
|
450
509
|
item.onFilter = (value, row) => {
|
|
451
510
|
switch (value) {
|
|
452
511
|
case "true":
|
|
453
|
-
return !(0,
|
|
512
|
+
return !(0, import_lodash5.isNil)(row[item.id]) && !!row[item.id];
|
|
454
513
|
case "false":
|
|
455
|
-
return !(0,
|
|
514
|
+
return !(0, import_lodash5.isNil)(row[item.id]) && !row[item.id];
|
|
456
515
|
case "empty":
|
|
457
|
-
return (0,
|
|
516
|
+
return (0, import_lodash5.isNil)(row[item.id]);
|
|
458
517
|
default:
|
|
459
518
|
return true;
|
|
460
519
|
}
|
|
@@ -462,6 +521,8 @@ function Table(props) {
|
|
|
462
521
|
break;
|
|
463
522
|
default:
|
|
464
523
|
item.render = (value) => processValue(item, value);
|
|
524
|
+
if (!item.onFilter)
|
|
525
|
+
item.onFilter = (value, row) => value === row[item.id];
|
|
465
526
|
break;
|
|
466
527
|
}
|
|
467
528
|
}
|
|
@@ -472,7 +533,7 @@ function Table(props) {
|
|
|
472
533
|
return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, {
|
|
473
534
|
dataSource: props.dataSource,
|
|
474
535
|
faasData: props.faasData,
|
|
475
|
-
render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(
|
|
536
|
+
render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd6.Table, __spreadProps(__spreadValues({}, props), {
|
|
476
537
|
rowKey: props.rowKey || "id",
|
|
477
538
|
columns,
|
|
478
539
|
dataSource: data
|
|
@@ -484,7 +545,10 @@ module.exports = __toCommonJS(src_exports);
|
|
|
484
545
|
0 && (module.exports = {
|
|
485
546
|
Blank,
|
|
486
547
|
Description,
|
|
548
|
+
Drawer,
|
|
487
549
|
Form,
|
|
488
550
|
FormItem,
|
|
489
|
-
Table
|
|
551
|
+
Table,
|
|
552
|
+
transferOptions,
|
|
553
|
+
useDrawer
|
|
490
554
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -32,10 +32,21 @@ function Blank(options) {
|
|
|
32
32
|
}, (options == null ? void 0 : options.text) || text) : options.value;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// src/data.ts
|
|
36
|
+
import { upperFirst } from "lodash";
|
|
37
|
+
function transferOptions(options) {
|
|
38
|
+
if (!options)
|
|
39
|
+
return [];
|
|
40
|
+
return options.map((item) => typeof item === "object" ? item : {
|
|
41
|
+
label: upperFirst(item.toString()),
|
|
42
|
+
value: item
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
35
46
|
// src/Description.tsx
|
|
36
47
|
import { CheckOutlined, CloseOutlined } from "@ant-design/icons";
|
|
37
48
|
import { Descriptions } from "antd";
|
|
38
|
-
import { upperFirst } from "lodash";
|
|
49
|
+
import { upperFirst as upperFirst2 } from "lodash";
|
|
39
50
|
import {
|
|
40
51
|
cloneElement,
|
|
41
52
|
useEffect as useEffect2,
|
|
@@ -55,7 +66,7 @@ function FaasDataWrapper({
|
|
|
55
66
|
useEffect(() => {
|
|
56
67
|
if (!faasData)
|
|
57
68
|
return;
|
|
58
|
-
getClient().faas(faasData.action, faasData.
|
|
69
|
+
getClient().faas(faasData.action, faasData.params).then((res) => setData(res.data));
|
|
59
70
|
}, [JSON.stringify(faasData)]);
|
|
60
71
|
if (dataSource)
|
|
61
72
|
return render({ data: dataSource });
|
|
@@ -68,20 +79,23 @@ function FaasDataWrapper({
|
|
|
68
79
|
function DescriptionItemContent(props) {
|
|
69
80
|
const [computedProps, setComputedProps] = useState2();
|
|
70
81
|
useEffect2(() => {
|
|
71
|
-
var _a2;
|
|
82
|
+
var _a2, _b;
|
|
72
83
|
const propsCopy = __spreadValues({}, props);
|
|
73
84
|
if (!propsCopy.item.title)
|
|
74
|
-
propsCopy.item.title =
|
|
85
|
+
propsCopy.item.title = upperFirst2(propsCopy.item.id);
|
|
75
86
|
if (!propsCopy.item.type)
|
|
76
87
|
propsCopy.item.type = "string";
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
89
|
+
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
90
|
+
}
|
|
91
|
+
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
92
|
+
if (propsCopy.item.type.endsWith("[]"))
|
|
93
|
+
propsCopy.value = propsCopy.value.map((v) => {
|
|
80
94
|
var _a3;
|
|
81
|
-
return ((_a3 =
|
|
95
|
+
return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
|
|
82
96
|
});
|
|
83
97
|
else
|
|
84
|
-
propsCopy.value = ((
|
|
98
|
+
propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
|
|
85
99
|
}
|
|
86
100
|
setComputedProps(propsCopy);
|
|
87
101
|
}, [props]);
|
|
@@ -132,7 +146,7 @@ function Description(props) {
|
|
|
132
146
|
faasData: props.faasData,
|
|
133
147
|
render: ({ data }) => /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
|
|
134
148
|
key: item.id,
|
|
135
|
-
label: item.title ||
|
|
149
|
+
label: item.title || upperFirst2(item.id)
|
|
136
150
|
}, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
|
|
137
151
|
item,
|
|
138
152
|
value: data[item.id],
|
|
@@ -142,11 +156,31 @@ function Description(props) {
|
|
|
142
156
|
});
|
|
143
157
|
}
|
|
144
158
|
|
|
159
|
+
// src/Drawer.tsx
|
|
160
|
+
import { Drawer } from "antd";
|
|
161
|
+
import { useState as useState3 } from "react";
|
|
162
|
+
function useDrawer(init) {
|
|
163
|
+
const [props, setProps] = useState3(__spreadValues({
|
|
164
|
+
visible: false,
|
|
165
|
+
onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
166
|
+
visible: false
|
|
167
|
+
}))
|
|
168
|
+
}, init));
|
|
169
|
+
return {
|
|
170
|
+
drawer: /* @__PURE__ */ React.createElement(Drawer, __spreadValues({}, props)),
|
|
171
|
+
drawerProps: props,
|
|
172
|
+
setDrawerProps(changes) {
|
|
173
|
+
setProps((prev) => __spreadValues(__spreadValues({}, prev), changes));
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
145
178
|
// src/Form.tsx
|
|
146
179
|
import {
|
|
147
180
|
Button as Button2,
|
|
148
181
|
Form as AntdForm2
|
|
149
182
|
} from "antd";
|
|
183
|
+
import { useEffect as useEffect4, useState as useState5 } from "react";
|
|
150
184
|
|
|
151
185
|
// src/FormItem.tsx
|
|
152
186
|
import {
|
|
@@ -162,15 +196,15 @@ import {
|
|
|
162
196
|
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
|
163
197
|
import {
|
|
164
198
|
useEffect as useEffect3,
|
|
165
|
-
useState as
|
|
199
|
+
useState as useState4
|
|
166
200
|
} from "react";
|
|
167
|
-
import { upperFirst as
|
|
201
|
+
import { upperFirst as upperFirst3 } from "lodash";
|
|
168
202
|
function FormItem(props) {
|
|
169
|
-
const [computedProps, setComputedProps] =
|
|
203
|
+
const [computedProps, setComputedProps] = useState4();
|
|
170
204
|
useEffect3(() => {
|
|
171
205
|
const propsCopy = __spreadValues({}, props);
|
|
172
206
|
if (!propsCopy.title)
|
|
173
|
-
propsCopy.title =
|
|
207
|
+
propsCopy.title = upperFirst3(propsCopy.id);
|
|
174
208
|
if (!propsCopy.label && props.label !== false)
|
|
175
209
|
propsCopy.label = propsCopy.title;
|
|
176
210
|
if (!propsCopy.name)
|
|
@@ -196,20 +230,8 @@ function FormItem(props) {
|
|
|
196
230
|
}
|
|
197
231
|
if (!propsCopy.input)
|
|
198
232
|
propsCopy.input = {};
|
|
199
|
-
if (propsCopy.options)
|
|
200
|
-
|
|
201
|
-
if (propsCopy.options.length > 0)
|
|
202
|
-
for (const option of propsCopy.options) {
|
|
203
|
-
if (typeof option === "object")
|
|
204
|
-
options.push(option);
|
|
205
|
-
else
|
|
206
|
-
options.push({
|
|
207
|
-
label: upperFirst2(option.toString()),
|
|
208
|
-
value: option
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
propsCopy.input.options = options;
|
|
212
|
-
}
|
|
233
|
+
if (propsCopy.options)
|
|
234
|
+
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
213
235
|
switch (propsCopy.type) {
|
|
214
236
|
case "boolean":
|
|
215
237
|
propsCopy.valuePropName = "checked";
|
|
@@ -317,13 +339,31 @@ function FormItem(props) {
|
|
|
317
339
|
// src/Form.tsx
|
|
318
340
|
function Form(props) {
|
|
319
341
|
var _a2, _b;
|
|
320
|
-
|
|
342
|
+
const [loading, setLoading] = useState5(false);
|
|
343
|
+
const [computedProps, setComputedProps] = useState5();
|
|
344
|
+
useEffect4(() => {
|
|
345
|
+
const propsCopy = __spreadValues({}, props);
|
|
346
|
+
if (propsCopy.onFinish) {
|
|
347
|
+
propsCopy.onFinish = async (values) => {
|
|
348
|
+
setLoading(true);
|
|
349
|
+
try {
|
|
350
|
+
await propsCopy.onFinish(values);
|
|
351
|
+
} catch (error) {
|
|
352
|
+
console.error(error);
|
|
353
|
+
}
|
|
354
|
+
setLoading(false);
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
setComputedProps(props);
|
|
358
|
+
}, []);
|
|
359
|
+
return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, computedProps), (_a2 = props.items) == null ? void 0 : _a2.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
|
|
321
360
|
key: item.id
|
|
322
361
|
}, item), {
|
|
323
362
|
extendTypes: props.extendTypes
|
|
324
363
|
}))), props.children, props.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
|
|
325
364
|
htmlType: "submit",
|
|
326
|
-
type: "primary"
|
|
365
|
+
type: "primary",
|
|
366
|
+
loading
|
|
327
367
|
}, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
|
|
328
368
|
}
|
|
329
369
|
Form.useForm = AntdForm2.useForm;
|
|
@@ -331,8 +371,8 @@ Form.Item = FormItem;
|
|
|
331
371
|
|
|
332
372
|
// src/Table.tsx
|
|
333
373
|
import {
|
|
334
|
-
useState as
|
|
335
|
-
useEffect as
|
|
374
|
+
useState as useState6,
|
|
375
|
+
useEffect as useEffect5,
|
|
336
376
|
cloneElement as cloneElement2
|
|
337
377
|
} from "react";
|
|
338
378
|
import {
|
|
@@ -340,7 +380,7 @@ import {
|
|
|
340
380
|
Radio
|
|
341
381
|
} from "antd";
|
|
342
382
|
import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
|
|
343
|
-
import { isNil as isNil2, upperFirst as
|
|
383
|
+
import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
|
|
344
384
|
function processValue(item, value) {
|
|
345
385
|
var _a2;
|
|
346
386
|
if (item.options && typeof value !== "undefined" && value !== null) {
|
|
@@ -355,19 +395,29 @@ function processValue(item, value) {
|
|
|
355
395
|
return value;
|
|
356
396
|
}
|
|
357
397
|
function Table(props) {
|
|
358
|
-
const [columns, setColumns] =
|
|
359
|
-
|
|
398
|
+
const [columns, setColumns] = useState6();
|
|
399
|
+
useEffect5(() => {
|
|
400
|
+
var _a2;
|
|
360
401
|
for (const item of props.items) {
|
|
361
402
|
if (!item.key)
|
|
362
403
|
item.key = item.id;
|
|
363
404
|
if (!item.dataIndex)
|
|
364
405
|
item.dataIndex = item.id;
|
|
365
406
|
if (!item.title)
|
|
366
|
-
item.title =
|
|
407
|
+
item.title = upperFirst4(item.id);
|
|
367
408
|
if (!item.type)
|
|
368
409
|
item.type = "string";
|
|
410
|
+
if ((_a2 = item.options) == null ? void 0 : _a2.length) {
|
|
411
|
+
item.options = transferOptions(item.options);
|
|
412
|
+
item.filters = item.options.map((o) => ({
|
|
413
|
+
text: o.label,
|
|
414
|
+
value: o.value
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
369
417
|
if (item.render)
|
|
370
418
|
continue;
|
|
419
|
+
if (item.children)
|
|
420
|
+
delete item.children;
|
|
371
421
|
if (props.extendTypes && props.extendTypes[item.type]) {
|
|
372
422
|
if (props.extendTypes[item.type].children) {
|
|
373
423
|
item.render = (value, values) => cloneElement2(props.extendTypes[item.type].children, {
|
|
@@ -383,14 +433,20 @@ function Table(props) {
|
|
|
383
433
|
switch (item.type) {
|
|
384
434
|
case "string[]":
|
|
385
435
|
item.render = (value) => processValue(item, value).join(", ");
|
|
436
|
+
if (!item.onFilter)
|
|
437
|
+
item.onFilter = (value, row) => row[item.id].includes(value);
|
|
386
438
|
break;
|
|
387
439
|
case "number":
|
|
388
440
|
item.render = (value) => processValue(item, value);
|
|
389
441
|
if (!item.sorter)
|
|
390
442
|
item.sorter = (a, b) => a[item.id] - b[item.id];
|
|
443
|
+
if (!item.onFilter)
|
|
444
|
+
item.onFilter = (value, row) => value === row[item.id];
|
|
391
445
|
break;
|
|
392
446
|
case "number[]":
|
|
393
447
|
item.render = (value) => processValue(item, value).join(", ");
|
|
448
|
+
if (!item.onFilter)
|
|
449
|
+
item.onFilter = (value, row) => row[item.id].includes(value);
|
|
394
450
|
break;
|
|
395
451
|
case "boolean":
|
|
396
452
|
item.render = (value) => typeof value === "undefined" ? /* @__PURE__ */ React.createElement(Blank, null) : value ? /* @__PURE__ */ React.createElement(CheckOutlined2, {
|
|
@@ -410,7 +466,7 @@ function Table(props) {
|
|
|
410
466
|
selectedKeys,
|
|
411
467
|
confirm
|
|
412
468
|
}) => {
|
|
413
|
-
var
|
|
469
|
+
var _a3, _b;
|
|
414
470
|
return /* @__PURE__ */ React.createElement(Radio.Group, {
|
|
415
471
|
style: { padding: 8 },
|
|
416
472
|
buttonStyle: "solid",
|
|
@@ -419,7 +475,7 @@ function Table(props) {
|
|
|
419
475
|
setSelectedKeys(e.target.value ? [e.target.value] : []);
|
|
420
476
|
confirm();
|
|
421
477
|
}
|
|
422
|
-
}, /* @__PURE__ */ React.createElement(Radio.Button, null, ((
|
|
478
|
+
}, /* @__PURE__ */ React.createElement(Radio.Button, null, ((_a3 = navigator.language) == null ? void 0 : _a3.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ React.createElement(Radio.Button, {
|
|
423
479
|
value: "true"
|
|
424
480
|
}, /* @__PURE__ */ React.createElement(CheckOutlined2, {
|
|
425
481
|
style: {
|
|
@@ -453,6 +509,8 @@ function Table(props) {
|
|
|
453
509
|
break;
|
|
454
510
|
default:
|
|
455
511
|
item.render = (value) => processValue(item, value);
|
|
512
|
+
if (!item.onFilter)
|
|
513
|
+
item.onFilter = (value, row) => value === row[item.id];
|
|
456
514
|
break;
|
|
457
515
|
}
|
|
458
516
|
}
|
|
@@ -473,7 +531,10 @@ function Table(props) {
|
|
|
473
531
|
export {
|
|
474
532
|
Blank,
|
|
475
533
|
Description,
|
|
534
|
+
Drawer,
|
|
476
535
|
Form,
|
|
477
536
|
FormItem,
|
|
478
|
-
Table
|
|
537
|
+
Table,
|
|
538
|
+
transferOptions,
|
|
539
|
+
useDrawer
|
|
479
540
|
};
|
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.349",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"lodash": "*",
|
|
28
28
|
"react": "*",
|
|
29
29
|
"react-dom": "*",
|
|
30
|
-
"@faasjs/react": "^0.0.2-beta.
|
|
30
|
+
"@faasjs/react": "^0.0.2-beta.349"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/lodash": "*",
|