@faasjs/ant-design 0.0.2-beta.380 → 0.0.2-beta.383
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/dist/index.d.ts +25 -5
- package/dist/index.js +106 -48
- package/dist/index.mjs +106 -48
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,14 +31,10 @@ type FaasItemProps = {
|
|
|
31
31
|
|
|
32
32
|
Form are based on [Ant Design's Form component](https://ant.design/components/form/#Form).
|
|
33
33
|
|
|
34
|
-
<iframe src="https://codesandbox.io/embed/recursing-lumiere-8wn11" style="width:100%;height:500px;border:0;overflow:hidden;" title="faasjs-ant-design-form" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>
|
|
35
|
-
|
|
36
34
|
### FormItem
|
|
37
35
|
|
|
38
36
|
Form are based on [Ant Design's Form.Item component](https://ant.design/components/form/#Form.Item).
|
|
39
37
|
|
|
40
|
-
<iframe src="https://codesandbox.io/embed/faasjs-ant-design-formitem-olqg5" style="width:100%;height:500px;border:0;overflow:hidden;" title="faasjs-ant-design-formitem" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>
|
|
41
|
-
|
|
42
38
|
## Modules
|
|
43
39
|
|
|
44
40
|
### Namespaces
|
|
@@ -245,7 +241,7 @@ ___
|
|
|
245
241
|
|
|
246
242
|
### FaasItemType
|
|
247
243
|
|
|
248
|
-
Ƭ **FaasItemType**: ``"string"`` \| ``"string[]"`` \| ``"number"`` \| ``"number[]"`` \| ``"boolean"`` \| ``"date"`` \| ``"time"``
|
|
244
|
+
Ƭ **FaasItemType**: ``"string"`` \| ``"string[]"`` \| ``"number"`` \| ``"number[]"`` \| ``"boolean"`` \| ``"date"`` \| ``"time"`` \| ``"object"`` \| ``"object[]"``
|
|
249
245
|
|
|
250
246
|
___
|
|
251
247
|
|
|
@@ -261,6 +257,8 @@ ___
|
|
|
261
257
|
| `date` | `Dayjs` |
|
|
262
258
|
| `number` | `number` |
|
|
263
259
|
| `number[]` | `number`[] |
|
|
260
|
+
| `object` | `any` |
|
|
261
|
+
| `object[]` | `any`[] |
|
|
264
262
|
| `string` | `string` |
|
|
265
263
|
| `string[]` | `string`[] |
|
|
266
264
|
| `time` | `Dayjs` |
|
|
@@ -293,7 +291,7 @@ ___
|
|
|
293
291
|
|
|
294
292
|
### FormItemProps
|
|
295
293
|
|
|
296
|
-
Ƭ **FormItemProps**<`T`\>: { `children?`: `JSX.Element` \| ``null`` ; `extendTypes?`: { `[type: string]`: [`ExtendFormTypeProps`](#extendformtypeprops); } ; `label?`: `string` \| ``false`` ; `rules?`: `RuleObject`[] ; `render?`: () => `Element` } & `FormItemInputProps
|
|
294
|
+
Ƭ **FormItemProps**<`T`\>: { `children?`: `JSX.Element` \| ``null`` ; `extendTypes?`: { `[type: string]`: [`ExtendFormTypeProps`](#extendformtypeprops); } ; `label?`: `string` \| ``false`` ; `rules?`: `RuleObject`[] ; `render?`: () => `Element` } & `FormItemInputProps` & [`FaasItemProps`](#faasitemprops) & `AntdFormItemProps`<`T`\>
|
|
297
295
|
|
|
298
296
|
#### Type parameters
|
|
299
297
|
|
package/dist/index.d.ts
CHANGED
|
@@ -36,11 +36,15 @@ declare type CalendarProps = CalendarProps$1<Dayjs>;
|
|
|
36
36
|
declare const Calendar: (props: antd_es_calendar_generateCalendar_js.CalendarProps<Dayjs>) => JSX.Element;
|
|
37
37
|
|
|
38
38
|
declare type FaasState = {
|
|
39
|
+
lang: string;
|
|
39
40
|
common: {
|
|
40
41
|
blank: string;
|
|
41
42
|
all: string;
|
|
42
43
|
submit: string;
|
|
43
44
|
pageNotFound: string;
|
|
45
|
+
add: string;
|
|
46
|
+
delete: string;
|
|
47
|
+
required: string;
|
|
44
48
|
};
|
|
45
49
|
Blank: {
|
|
46
50
|
text: string;
|
|
@@ -74,15 +78,17 @@ declare function Config(props: {
|
|
|
74
78
|
config: Partial<FaasState>;
|
|
75
79
|
}): JSX.Element;
|
|
76
80
|
|
|
77
|
-
declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean' | 'date' | 'time';
|
|
81
|
+
declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean' | 'date' | 'time' | 'object' | 'object[]';
|
|
78
82
|
declare type FaasItemTypeValue = {
|
|
79
83
|
string: string;
|
|
80
84
|
'string[]': string[];
|
|
81
85
|
number: number;
|
|
82
86
|
'number[]': number[];
|
|
83
87
|
boolean: boolean;
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
date: Dayjs;
|
|
89
|
+
time: Dayjs;
|
|
90
|
+
object: any;
|
|
91
|
+
'object[]': any[];
|
|
86
92
|
};
|
|
87
93
|
declare type BaseOption = string | number | {
|
|
88
94
|
label: string;
|
|
@@ -191,12 +197,26 @@ declare type TimeProps = {
|
|
|
191
197
|
type: 'time';
|
|
192
198
|
input?: TimePickerProps$1;
|
|
193
199
|
};
|
|
200
|
+
declare type ObjectProps = {
|
|
201
|
+
type: 'object';
|
|
202
|
+
object: (FaasItemProps & (StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps | DateProps | TimeProps | ObjectProps))[];
|
|
203
|
+
disabled?: boolean;
|
|
204
|
+
};
|
|
205
|
+
declare type ObjectListProps = {
|
|
206
|
+
type: 'object[]';
|
|
207
|
+
object: (FaasItemProps & {
|
|
208
|
+
/** default is 6 */
|
|
209
|
+
col?: number;
|
|
210
|
+
} & (StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps | DateProps | TimeProps | ObjectProps))[];
|
|
211
|
+
maxCount?: number;
|
|
212
|
+
disabled?: boolean;
|
|
213
|
+
};
|
|
194
214
|
declare type OptionsProps = {
|
|
195
215
|
options?: BaseOption[];
|
|
196
216
|
type?: 'string' | 'string[]' | 'number' | 'number[]';
|
|
197
217
|
input?: SelectProps<any>;
|
|
198
218
|
};
|
|
199
|
-
declare type FormItemInputProps
|
|
219
|
+
declare type FormItemInputProps = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps | DateProps | TimeProps | ObjectProps | ObjectListProps;
|
|
200
220
|
declare type ExtendFormTypeProps = {
|
|
201
221
|
children?: JSX.Element | null;
|
|
202
222
|
};
|
|
@@ -209,7 +229,7 @@ declare type FormItemProps<T = any> = {
|
|
|
209
229
|
extendTypes?: {
|
|
210
230
|
[type: string]: ExtendFormTypeProps;
|
|
211
231
|
};
|
|
212
|
-
} & FormItemInputProps
|
|
232
|
+
} & FormItemInputProps & FaasItemProps & FormItemProps$1<T>;
|
|
213
233
|
/**
|
|
214
234
|
* FormItem, can be used without Form.
|
|
215
235
|
*
|
package/dist/index.js
CHANGED
|
@@ -75,19 +75,28 @@ var import_lodash = require("lodash");
|
|
|
75
75
|
// src/Config.tsx
|
|
76
76
|
var import_react2 = require("react");
|
|
77
77
|
var import_react_use = require("react-use");
|
|
78
|
-
var
|
|
79
|
-
var common =
|
|
78
|
+
var isZH = /^zh/i.test(navigator.language);
|
|
79
|
+
var common = isZH ? {
|
|
80
|
+
lang: "zh",
|
|
80
81
|
blank: "\u7A7A",
|
|
81
82
|
all: "\u5168\u90E8",
|
|
82
83
|
submit: "\u63D0\u4EA4",
|
|
83
|
-
pageNotFound: "\u9875\u9762\u672A\u627E\u5230"
|
|
84
|
+
pageNotFound: "\u9875\u9762\u672A\u627E\u5230",
|
|
85
|
+
add: "\u6DFB\u52A0",
|
|
86
|
+
delete: "\u5220\u9664",
|
|
87
|
+
required: "\u5FC5\u586B"
|
|
84
88
|
} : {
|
|
89
|
+
lang: "en",
|
|
85
90
|
blank: "Empty",
|
|
86
91
|
all: "All",
|
|
87
92
|
submit: "Submit",
|
|
88
|
-
pageNotFound: "Page Not Found"
|
|
93
|
+
pageNotFound: "Page Not Found",
|
|
94
|
+
add: "Add",
|
|
95
|
+
delete: "Delete",
|
|
96
|
+
required: "is required"
|
|
89
97
|
};
|
|
90
98
|
var useFaasState = (0, import_react_use.createGlobalState)({
|
|
99
|
+
lang: "en",
|
|
91
100
|
common,
|
|
92
101
|
Blank: { text: common.blank },
|
|
93
102
|
Form: { submit: { text: common.submit } },
|
|
@@ -283,45 +292,58 @@ var TimePicker = (0, import_react6.forwardRef)((props, ref) => {
|
|
|
283
292
|
TimePicker.displayName = "TimePicker";
|
|
284
293
|
|
|
285
294
|
// src/FormItem.tsx
|
|
295
|
+
function processProps(propsCopy, config) {
|
|
296
|
+
if (!propsCopy.title)
|
|
297
|
+
propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
|
|
298
|
+
if (!propsCopy.label && propsCopy.label !== false)
|
|
299
|
+
propsCopy.label = propsCopy.title;
|
|
300
|
+
if (!propsCopy.name)
|
|
301
|
+
propsCopy.name = propsCopy.id;
|
|
302
|
+
if (!propsCopy.type)
|
|
303
|
+
propsCopy.type = "string";
|
|
304
|
+
if (!propsCopy.rules)
|
|
305
|
+
propsCopy.rules = [];
|
|
306
|
+
if (propsCopy.required) {
|
|
307
|
+
if (propsCopy.type.endsWith("[]"))
|
|
308
|
+
propsCopy.rules.push({
|
|
309
|
+
required: true,
|
|
310
|
+
validator: async (_, values) => {
|
|
311
|
+
if (!values || values.length < 1)
|
|
312
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.common.required}`));
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
else
|
|
316
|
+
propsCopy.rules.push({
|
|
317
|
+
required: true,
|
|
318
|
+
message: `${propsCopy.label || propsCopy.title} ${config.common.required}`
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
if (!propsCopy.input)
|
|
322
|
+
propsCopy.input = {};
|
|
323
|
+
if (propsCopy.options)
|
|
324
|
+
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
325
|
+
switch (propsCopy.type) {
|
|
326
|
+
case "boolean":
|
|
327
|
+
propsCopy.valuePropName = "checked";
|
|
328
|
+
break;
|
|
329
|
+
case "object":
|
|
330
|
+
if (!Array.isArray(propsCopy.name))
|
|
331
|
+
propsCopy.name = [propsCopy.name];
|
|
332
|
+
for (const sub of propsCopy.object) {
|
|
333
|
+
if (!sub.name)
|
|
334
|
+
sub.name = propsCopy.name.concat(sub.id);
|
|
335
|
+
processProps(sub, config);
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
return propsCopy;
|
|
340
|
+
}
|
|
286
341
|
function FormItem(props) {
|
|
342
|
+
var _a;
|
|
287
343
|
const [computedProps, setComputedProps] = (0, import_react7.useState)();
|
|
344
|
+
const [config] = useFaasState();
|
|
288
345
|
(0, import_react7.useEffect)(() => {
|
|
289
|
-
|
|
290
|
-
if (!propsCopy.title)
|
|
291
|
-
propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
|
|
292
|
-
if (!propsCopy.label && props.label !== false)
|
|
293
|
-
propsCopy.label = propsCopy.title;
|
|
294
|
-
if (!propsCopy.name)
|
|
295
|
-
propsCopy.name = propsCopy.id;
|
|
296
|
-
if (!propsCopy.type)
|
|
297
|
-
propsCopy.type = "string";
|
|
298
|
-
if (!propsCopy.rules)
|
|
299
|
-
propsCopy.rules = [];
|
|
300
|
-
if (propsCopy.required) {
|
|
301
|
-
if (propsCopy.type.endsWith("[]"))
|
|
302
|
-
propsCopy.rules.push({
|
|
303
|
-
required: true,
|
|
304
|
-
validator: async (_, values) => {
|
|
305
|
-
if (!values || values.length < 1)
|
|
306
|
-
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} is required`));
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
else
|
|
310
|
-
propsCopy.rules.push({
|
|
311
|
-
required: true,
|
|
312
|
-
message: `${propsCopy.label || propsCopy.title} is required`
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
if (!propsCopy.input)
|
|
316
|
-
propsCopy.input = {};
|
|
317
|
-
if (propsCopy.options)
|
|
318
|
-
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
319
|
-
switch (propsCopy.type) {
|
|
320
|
-
case "boolean":
|
|
321
|
-
propsCopy.valuePropName = "checked";
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
setComputedProps(propsCopy);
|
|
346
|
+
setComputedProps(processProps(__spreadValues({}, props), config));
|
|
325
347
|
}, [props]);
|
|
326
348
|
if (!computedProps)
|
|
327
349
|
return null;
|
|
@@ -343,13 +365,13 @@ function FormItem(props) {
|
|
|
343
365
|
name: computedProps.name,
|
|
344
366
|
rules: computedProps.rules
|
|
345
367
|
}, (fields, { add, remove }, { errors }) => {
|
|
346
|
-
var
|
|
368
|
+
var _a2;
|
|
347
369
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
348
370
|
className: "ant-form-item-label"
|
|
349
371
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
350
372
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
351
373
|
}, computedProps.label)), fields.map((field) => {
|
|
352
|
-
var
|
|
374
|
+
var _a3;
|
|
353
375
|
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
354
376
|
key: field.key
|
|
355
377
|
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
@@ -361,14 +383,14 @@ function FormItem(props) {
|
|
|
361
383
|
noStyle: true
|
|
362
384
|
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.Input, __spreadValues({}, computedProps.input)))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
363
385
|
span: 1
|
|
364
|
-
}, !((
|
|
386
|
+
}, !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
365
387
|
danger: true,
|
|
366
388
|
type: "link",
|
|
367
389
|
style: { float: "right" },
|
|
368
390
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons2.MinusCircleOutlined, null),
|
|
369
391
|
onClick: () => remove(field.name)
|
|
370
392
|
}))));
|
|
371
|
-
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, null, !((
|
|
393
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, null, !((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
372
394
|
type: "dashed",
|
|
373
395
|
block: true,
|
|
374
396
|
onClick: () => add(),
|
|
@@ -390,13 +412,13 @@ function FormItem(props) {
|
|
|
390
412
|
name: computedProps.name,
|
|
391
413
|
rules: computedProps.rules
|
|
392
414
|
}, (fields, { add, remove }, { errors }) => {
|
|
393
|
-
var
|
|
415
|
+
var _a2, _b;
|
|
394
416
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
395
417
|
className: "ant-form-item-label"
|
|
396
418
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
397
|
-
className: ((
|
|
419
|
+
className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required"
|
|
398
420
|
}, computedProps.label)), fields.map((field) => {
|
|
399
|
-
var
|
|
421
|
+
var _a3;
|
|
400
422
|
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
401
423
|
key: field.key
|
|
402
424
|
}, /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
@@ -410,7 +432,7 @@ function FormItem(props) {
|
|
|
410
432
|
style: { width: "100%" }
|
|
411
433
|
}, computedProps.input)))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
412
434
|
span: 1
|
|
413
|
-
}, !((
|
|
435
|
+
}, !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
414
436
|
danger: true,
|
|
415
437
|
type: "link",
|
|
416
438
|
style: { float: "right" },
|
|
@@ -432,6 +454,42 @@ function FormItem(props) {
|
|
|
432
454
|
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(DatePicker, __spreadValues({}, computedProps.input)));
|
|
433
455
|
case "time":
|
|
434
456
|
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(TimePicker, __spreadValues({}, computedProps.input)));
|
|
457
|
+
case "object":
|
|
458
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
459
|
+
className: "ant-form-item-label"
|
|
460
|
+
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
461
|
+
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
|
462
|
+
}, computedProps.label)), computedProps.object.map((o) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadValues({
|
|
463
|
+
key: o.id
|
|
464
|
+
}, o))));
|
|
465
|
+
case "object[]":
|
|
466
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.List, {
|
|
467
|
+
name: computedProps.name,
|
|
468
|
+
rules: computedProps.rules
|
|
469
|
+
}, (fields, { add, remove }, { errors }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, fields.map((field) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, {
|
|
470
|
+
key: field.key,
|
|
471
|
+
style: { marginBottom: 0 }
|
|
472
|
+
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
473
|
+
className: "ant-form-item-label"
|
|
474
|
+
}, /* @__PURE__ */ import_react.default.createElement("label", null, computedProps.label, " ", field.name + 1, !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
475
|
+
danger: true,
|
|
476
|
+
type: "link",
|
|
477
|
+
onClick: () => remove(field.name)
|
|
478
|
+
}, config.common.delete))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Row, {
|
|
479
|
+
gutter: 24
|
|
480
|
+
}, computedProps.object.map((o) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Col, {
|
|
481
|
+
key: o.id,
|
|
482
|
+
span: o.col || 6
|
|
483
|
+
}, /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({}, o), {
|
|
484
|
+
name: [field.name, o.id]
|
|
485
|
+
}))))))), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, null, !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ import_react.default.createElement(import_antd4.Button, {
|
|
486
|
+
type: "dashed",
|
|
487
|
+
block: true,
|
|
488
|
+
onClick: () => add(),
|
|
489
|
+
icon: /* @__PURE__ */ import_react.default.createElement(import_icons2.PlusOutlined, null)
|
|
490
|
+
}, config.common.add, " ", computedProps.label), /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.ErrorList, {
|
|
491
|
+
errors
|
|
492
|
+
}))));
|
|
435
493
|
default:
|
|
436
494
|
return null;
|
|
437
495
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -28,19 +28,28 @@ 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 =
|
|
31
|
+
var isZH = /^zh/i.test(navigator.language);
|
|
32
|
+
var common = isZH ? {
|
|
33
|
+
lang: "zh",
|
|
33
34
|
blank: "\u7A7A",
|
|
34
35
|
all: "\u5168\u90E8",
|
|
35
36
|
submit: "\u63D0\u4EA4",
|
|
36
|
-
pageNotFound: "\u9875\u9762\u672A\u627E\u5230"
|
|
37
|
+
pageNotFound: "\u9875\u9762\u672A\u627E\u5230",
|
|
38
|
+
add: "\u6DFB\u52A0",
|
|
39
|
+
delete: "\u5220\u9664",
|
|
40
|
+
required: "\u5FC5\u586B"
|
|
37
41
|
} : {
|
|
42
|
+
lang: "en",
|
|
38
43
|
blank: "Empty",
|
|
39
44
|
all: "All",
|
|
40
45
|
submit: "Submit",
|
|
41
|
-
pageNotFound: "Page Not Found"
|
|
46
|
+
pageNotFound: "Page Not Found",
|
|
47
|
+
add: "Add",
|
|
48
|
+
delete: "Delete",
|
|
49
|
+
required: "is required"
|
|
42
50
|
};
|
|
43
51
|
var useFaasState = createGlobalState({
|
|
52
|
+
lang: "en",
|
|
44
53
|
common,
|
|
45
54
|
Blank: { text: common.blank },
|
|
46
55
|
Form: { submit: { text: common.submit } },
|
|
@@ -255,45 +264,58 @@ var TimePicker = forwardRef((props, ref) => {
|
|
|
255
264
|
TimePicker.displayName = "TimePicker";
|
|
256
265
|
|
|
257
266
|
// src/FormItem.tsx
|
|
267
|
+
function processProps(propsCopy, config) {
|
|
268
|
+
if (!propsCopy.title)
|
|
269
|
+
propsCopy.title = upperFirst3(propsCopy.id);
|
|
270
|
+
if (!propsCopy.label && propsCopy.label !== false)
|
|
271
|
+
propsCopy.label = propsCopy.title;
|
|
272
|
+
if (!propsCopy.name)
|
|
273
|
+
propsCopy.name = propsCopy.id;
|
|
274
|
+
if (!propsCopy.type)
|
|
275
|
+
propsCopy.type = "string";
|
|
276
|
+
if (!propsCopy.rules)
|
|
277
|
+
propsCopy.rules = [];
|
|
278
|
+
if (propsCopy.required) {
|
|
279
|
+
if (propsCopy.type.endsWith("[]"))
|
|
280
|
+
propsCopy.rules.push({
|
|
281
|
+
required: true,
|
|
282
|
+
validator: async (_, values) => {
|
|
283
|
+
if (!values || values.length < 1)
|
|
284
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} ${config.common.required}`));
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
else
|
|
288
|
+
propsCopy.rules.push({
|
|
289
|
+
required: true,
|
|
290
|
+
message: `${propsCopy.label || propsCopy.title} ${config.common.required}`
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (!propsCopy.input)
|
|
294
|
+
propsCopy.input = {};
|
|
295
|
+
if (propsCopy.options)
|
|
296
|
+
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
297
|
+
switch (propsCopy.type) {
|
|
298
|
+
case "boolean":
|
|
299
|
+
propsCopy.valuePropName = "checked";
|
|
300
|
+
break;
|
|
301
|
+
case "object":
|
|
302
|
+
if (!Array.isArray(propsCopy.name))
|
|
303
|
+
propsCopy.name = [propsCopy.name];
|
|
304
|
+
for (const sub of propsCopy.object) {
|
|
305
|
+
if (!sub.name)
|
|
306
|
+
sub.name = propsCopy.name.concat(sub.id);
|
|
307
|
+
processProps(sub, config);
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
return propsCopy;
|
|
312
|
+
}
|
|
258
313
|
function FormItem(props) {
|
|
314
|
+
var _a;
|
|
259
315
|
const [computedProps, setComputedProps] = useState3();
|
|
316
|
+
const [config] = useFaasState();
|
|
260
317
|
useEffect3(() => {
|
|
261
|
-
|
|
262
|
-
if (!propsCopy.title)
|
|
263
|
-
propsCopy.title = upperFirst3(propsCopy.id);
|
|
264
|
-
if (!propsCopy.label && props.label !== false)
|
|
265
|
-
propsCopy.label = propsCopy.title;
|
|
266
|
-
if (!propsCopy.name)
|
|
267
|
-
propsCopy.name = propsCopy.id;
|
|
268
|
-
if (!propsCopy.type)
|
|
269
|
-
propsCopy.type = "string";
|
|
270
|
-
if (!propsCopy.rules)
|
|
271
|
-
propsCopy.rules = [];
|
|
272
|
-
if (propsCopy.required) {
|
|
273
|
-
if (propsCopy.type.endsWith("[]"))
|
|
274
|
-
propsCopy.rules.push({
|
|
275
|
-
required: true,
|
|
276
|
-
validator: async (_, values) => {
|
|
277
|
-
if (!values || values.length < 1)
|
|
278
|
-
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} is required`));
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
else
|
|
282
|
-
propsCopy.rules.push({
|
|
283
|
-
required: true,
|
|
284
|
-
message: `${propsCopy.label || propsCopy.title} is required`
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
if (!propsCopy.input)
|
|
288
|
-
propsCopy.input = {};
|
|
289
|
-
if (propsCopy.options)
|
|
290
|
-
propsCopy.input.options = transferOptions(propsCopy.options);
|
|
291
|
-
switch (propsCopy.type) {
|
|
292
|
-
case "boolean":
|
|
293
|
-
propsCopy.valuePropName = "checked";
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
setComputedProps(propsCopy);
|
|
318
|
+
setComputedProps(processProps(__spreadValues({}, props), config));
|
|
297
319
|
}, [props]);
|
|
298
320
|
if (!computedProps)
|
|
299
321
|
return null;
|
|
@@ -315,13 +337,13 @@ function FormItem(props) {
|
|
|
315
337
|
name: computedProps.name,
|
|
316
338
|
rules: computedProps.rules
|
|
317
339
|
}, (fields, { add, remove }, { errors }) => {
|
|
318
|
-
var
|
|
340
|
+
var _a2;
|
|
319
341
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
320
342
|
className: "ant-form-item-label"
|
|
321
343
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
322
344
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
323
345
|
}, computedProps.label)), fields.map((field) => {
|
|
324
|
-
var
|
|
346
|
+
var _a3;
|
|
325
347
|
return /* @__PURE__ */ React.createElement(AntdForm.Item, {
|
|
326
348
|
key: field.key
|
|
327
349
|
}, /* @__PURE__ */ React.createElement(Row, {
|
|
@@ -333,14 +355,14 @@ function FormItem(props) {
|
|
|
333
355
|
noStyle: true
|
|
334
356
|
}), /* @__PURE__ */ React.createElement(Input, __spreadValues({}, computedProps.input)))), /* @__PURE__ */ React.createElement(Col, {
|
|
335
357
|
span: 1
|
|
336
|
-
}, !((
|
|
358
|
+
}, !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ React.createElement(Button, {
|
|
337
359
|
danger: true,
|
|
338
360
|
type: "link",
|
|
339
361
|
style: { float: "right" },
|
|
340
362
|
icon: /* @__PURE__ */ React.createElement(MinusCircleOutlined, null),
|
|
341
363
|
onClick: () => remove(field.name)
|
|
342
364
|
}))));
|
|
343
|
-
}), /* @__PURE__ */ React.createElement(AntdForm.Item, null, !((
|
|
365
|
+
}), /* @__PURE__ */ React.createElement(AntdForm.Item, null, !((_a2 = computedProps.input) == null ? void 0 : _a2.disabled) && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ React.createElement(Button, {
|
|
344
366
|
type: "dashed",
|
|
345
367
|
block: true,
|
|
346
368
|
onClick: () => add(),
|
|
@@ -362,13 +384,13 @@ function FormItem(props) {
|
|
|
362
384
|
name: computedProps.name,
|
|
363
385
|
rules: computedProps.rules
|
|
364
386
|
}, (fields, { add, remove }, { errors }) => {
|
|
365
|
-
var
|
|
387
|
+
var _a2, _b;
|
|
366
388
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
367
389
|
className: "ant-form-item-label"
|
|
368
390
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
369
|
-
className: ((
|
|
391
|
+
className: ((_a2 = computedProps.rules) == null ? void 0 : _a2.find((r) => r.required)) && "ant-form-item-required"
|
|
370
392
|
}, computedProps.label)), fields.map((field) => {
|
|
371
|
-
var
|
|
393
|
+
var _a3;
|
|
372
394
|
return /* @__PURE__ */ React.createElement(AntdForm.Item, {
|
|
373
395
|
key: field.key
|
|
374
396
|
}, /* @__PURE__ */ React.createElement(Row, {
|
|
@@ -382,7 +404,7 @@ function FormItem(props) {
|
|
|
382
404
|
style: { width: "100%" }
|
|
383
405
|
}, computedProps.input)))), /* @__PURE__ */ React.createElement(Col, {
|
|
384
406
|
span: 1
|
|
385
|
-
}, !((
|
|
407
|
+
}, !((_a3 = computedProps.input) == null ? void 0 : _a3.disabled) && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ React.createElement(Button, {
|
|
386
408
|
danger: true,
|
|
387
409
|
type: "link",
|
|
388
410
|
style: { float: "right" },
|
|
@@ -404,6 +426,42 @@ function FormItem(props) {
|
|
|
404
426
|
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), /* @__PURE__ */ React.createElement(DatePicker, __spreadValues({}, computedProps.input)));
|
|
405
427
|
case "time":
|
|
406
428
|
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), /* @__PURE__ */ React.createElement(TimePicker, __spreadValues({}, computedProps.input)));
|
|
429
|
+
case "object":
|
|
430
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
431
|
+
className: "ant-form-item-label"
|
|
432
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
433
|
+
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
|
434
|
+
}, computedProps.label)), computedProps.object.map((o) => /* @__PURE__ */ React.createElement(FormItem, __spreadValues({
|
|
435
|
+
key: o.id
|
|
436
|
+
}, o))));
|
|
437
|
+
case "object[]":
|
|
438
|
+
return /* @__PURE__ */ React.createElement(AntdForm.List, {
|
|
439
|
+
name: computedProps.name,
|
|
440
|
+
rules: computedProps.rules
|
|
441
|
+
}, (fields, { add, remove }, { errors }) => /* @__PURE__ */ React.createElement(React.Fragment, null, fields.map((field) => /* @__PURE__ */ React.createElement(AntdForm.Item, {
|
|
442
|
+
key: field.key,
|
|
443
|
+
style: { marginBottom: 0 }
|
|
444
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
445
|
+
className: "ant-form-item-label"
|
|
446
|
+
}, /* @__PURE__ */ React.createElement("label", null, computedProps.label, " ", field.name + 1, !computedProps.disabled && (!computedProps.rules.find((r) => r.required) || field.key > 0) && /* @__PURE__ */ React.createElement(Button, {
|
|
447
|
+
danger: true,
|
|
448
|
+
type: "link",
|
|
449
|
+
onClick: () => remove(field.name)
|
|
450
|
+
}, config.common.delete))), /* @__PURE__ */ React.createElement(Row, {
|
|
451
|
+
gutter: 24
|
|
452
|
+
}, computedProps.object.map((o) => /* @__PURE__ */ React.createElement(Col, {
|
|
453
|
+
key: o.id,
|
|
454
|
+
span: o.col || 6
|
|
455
|
+
}, /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({}, o), {
|
|
456
|
+
name: [field.name, o.id]
|
|
457
|
+
}))))))), /* @__PURE__ */ React.createElement(AntdForm.Item, null, !computedProps.disabled && (!computedProps.maxCount || computedProps.maxCount > fields.length) && /* @__PURE__ */ React.createElement(Button, {
|
|
458
|
+
type: "dashed",
|
|
459
|
+
block: true,
|
|
460
|
+
onClick: () => add(),
|
|
461
|
+
icon: /* @__PURE__ */ React.createElement(PlusOutlined, null)
|
|
462
|
+
}, config.common.add, " ", computedProps.label), /* @__PURE__ */ React.createElement(AntdForm.ErrorList, {
|
|
463
|
+
errors
|
|
464
|
+
}))));
|
|
407
465
|
default:
|
|
408
466
|
return null;
|
|
409
467
|
}
|
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.383",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lodash": "*",
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*",
|
|
31
|
-
"@faasjs/react": "^0.0.2-beta.
|
|
31
|
+
"@faasjs/react": "^0.0.2-beta.383",
|
|
32
32
|
"react-use": "*",
|
|
33
33
|
"react-router-dom": "*",
|
|
34
34
|
"dayjs": "*"
|