@faasjs/ant-design 0.0.2-beta.335 → 0.0.2-beta.339

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 CHANGED
@@ -4,22 +4,39 @@ import { RuleObject } from 'rc-field-form/lib/interface';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean';
7
- declare type FaasItemProps = {
7
+ declare type FaasItemTypeValue = {
8
+ string: string;
9
+ 'string[]': string[];
10
+ number: number;
11
+ 'number[]': number[];
12
+ boolean: boolean;
13
+ };
14
+ declare type BaseItemType = {
15
+ id: string;
16
+ title?: string;
17
+ };
18
+ declare type FaasItemProps = BaseItemType & {
8
19
  /**
9
20
  * Support string, string[], number, number[], boolean
10
21
  * @default 'string'
11
22
  */
12
23
  type?: FaasItemType;
13
- id: string;
14
- title?: string;
15
24
  };
16
25
 
17
- declare type DescriptionItemProps = FaasItemProps & {
18
- children?: JSX.Element;
26
+ declare type ExtendDescriptionItemProps = {
27
+ [type: string]: {
28
+ children?: JSX.Element | null;
29
+ render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
30
+ };
19
31
  };
20
- declare type DescriptionProps<T = any> = {
21
- items: DescriptionItemProps[];
32
+ declare type DescriptionItemProps<T = any> = {
33
+ children?: JSX.Element;
34
+ render?: (value: T, values: any) => JSX.Element | string | number | boolean | null;
35
+ } & FaasItemProps;
36
+ declare type DescriptionProps<T = any, ExtendItemProps = any> = {
37
+ items: (DescriptionItemProps | ExtendItemProps)[];
22
38
  dataSource: T;
39
+ extendTypes?: ExtendDescriptionItemProps;
23
40
  } & DescriptionsProps;
24
41
  declare function Description(props: DescriptionProps): JSX.Element;
25
42
 
@@ -57,30 +74,44 @@ declare type OptionsProps<T = any> = {
57
74
  input?: SelectProps<any>;
58
75
  };
59
76
  declare type FormItemInputProps<T = any> = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps<T>;
77
+ declare type ExtendFormItemProps = {
78
+ [type: string]: {
79
+ children?: JSX.Element | null;
80
+ };
81
+ };
60
82
  declare type FormItemProps<T = any> = {
61
83
  children?: JSX.Element;
62
84
  rules?: RuleObject[];
63
85
  label?: string | false;
86
+ extendTypes?: ExtendFormItemProps;
64
87
  } & FormItemInputProps<T> & FaasItemProps & FormItemProps$1<T>;
65
88
  declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
66
89
 
67
- declare type FormProps<T = any> = {
68
- items?: FormItemProps[];
69
- /** Default: { text: 'Submit' } */
90
+ declare type FormProps<Values = any, ExtendItemProps = any> = {
91
+ items?: (FormItemProps | ExtendItemProps)[];
92
+ /** Default: { text: 'Submit' }, set false to disable it */
70
93
  submit?: false | {
71
94
  /** Default: Submit */
72
95
  text?: string;
73
96
  };
74
- } & FormProps$1<T>;
75
- declare function Form<T = any>(props: FormProps<T>): JSX.Element;
97
+ extendTypes?: ExtendFormItemProps;
98
+ } & FormProps$1<Values>;
99
+ declare function Form<Values = any>(props: FormProps<Values>): JSX.Element;
76
100
  declare namespace Form {
77
101
  var useForm: typeof antd_lib_form_Form.useForm;
78
102
  }
79
103
 
80
104
  declare type TableItemProps<T = any> = FaasItemProps & TableColumnProps<T>;
81
- declare type TableProps<T = any> = TableProps$1<T> & {
82
- items: TableItemProps[];
105
+ declare type ExtendTableItemProps = {
106
+ [type: string]: {
107
+ children?: JSX.Element | null;
108
+ render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
109
+ };
110
+ };
111
+ declare type TableProps<T = any, ExtendTypes = any> = TableProps$1<T> & {
112
+ items: (TableItemProps | ExtendTypes)[];
113
+ extendTypes?: ExtendTableItemProps;
83
114
  };
84
- declare function Table(props: TableProps): JSX.Element;
115
+ declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
85
116
 
86
- export { Description, DescriptionItemProps, DescriptionProps, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps };
117
+ export { BaseItemType, Description, DescriptionItemProps, DescriptionProps, ExtendDescriptionItemProps, ExtendFormItemProps, ExtendTableItemProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps };
package/dist/index.js CHANGED
@@ -70,14 +70,23 @@ function DescriptionItemContent(props) {
70
70
  propsCopy.item.type = "string";
71
71
  setComputedProps(propsCopy);
72
72
  }, [props]);
73
- if (typeof computedProps.value === "undefined" || computedProps.value === null)
73
+ if (!computedProps || typeof computedProps.value === "undefined" || computedProps.value === null)
74
74
  return null;
75
- if (computedProps.item.children) {
75
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
76
+ if (computedProps.extendTypes[computedProps.item.type].children)
77
+ return (0, import_react2.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
78
+ value: computedProps.value,
79
+ values: computedProps.values
80
+ });
81
+ else if (computedProps.extendTypes[computedProps.item.type].render)
82
+ return computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values);
83
+ else
84
+ throw Error(computedProps.item.type + " requires children or render");
85
+ if (computedProps.item.children)
76
86
  return (0, import_react2.cloneElement)(computedProps.item.children, { value: computedProps.value });
77
- }
87
+ if (computedProps.item.render)
88
+ return computedProps.item.render(computedProps.value, computedProps.values);
78
89
  switch (computedProps.item.type) {
79
- case "string":
80
- return computedProps.value;
81
90
  case "string[]":
82
91
  return computedProps.value.join(", ");
83
92
  case "number":
@@ -91,7 +100,7 @@ function DescriptionItemContent(props) {
91
100
  style: { marginTop: "4px" }
92
101
  });
93
102
  default:
94
- return null;
103
+ return computedProps.value;
95
104
  }
96
105
  }
97
106
  function Description(props) {
@@ -100,7 +109,9 @@ function Description(props) {
100
109
  label: item.title || (0, import_lodash.upperFirst)(item.id)
101
110
  }, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
102
111
  item,
103
- value: props.dataSource[item.id]
112
+ value: props.dataSource[item.id],
113
+ values: props.dataSource,
114
+ extendTypes: props.extendTypes
104
115
  }))));
105
116
  }
106
117
 
@@ -166,6 +177,8 @@ function FormItem(props) {
166
177
  }, [props]);
167
178
  if (!computedProps)
168
179
  return null;
180
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.type])
181
+ return /* @__PURE__ */ import_react.default.createElement(import_antd2.Form.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
169
182
  if (computedProps.children)
170
183
  return /* @__PURE__ */ import_react.default.createElement(import_antd2.Form.Item, __spreadValues({}, computedProps), computedProps.children);
171
184
  switch (computedProps.type) {
@@ -262,9 +275,11 @@ function FormItem(props) {
262
275
  // src/Form.tsx
263
276
  function Form(props) {
264
277
  var _a, _b;
265
- return /* @__PURE__ */ import_react.default.createElement(import_antd3.Form, __spreadValues({}, props), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadValues({
278
+ return /* @__PURE__ */ import_react.default.createElement(import_antd3.Form, __spreadValues({}, props), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({
266
279
  key: item.id
267
- }, item))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd3.Button, {
280
+ }, item), {
281
+ extendTypes: props.extendTypes
282
+ }))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd3.Button, {
268
283
  htmlType: "submit",
269
284
  type: "primary"
270
285
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
@@ -290,6 +305,18 @@ function Table(props) {
290
305
  item.type = "string";
291
306
  if (item.render)
292
307
  continue;
308
+ if (props.extendTypes && props.extendTypes[item.type]) {
309
+ if (props.extendTypes[item.type].children) {
310
+ item.render = (value, values) => (0, import_react4.cloneElement)(props.extendTypes[item.type].children, {
311
+ value,
312
+ values
313
+ });
314
+ } else if (props.extendTypes[item.type].render)
315
+ item.render = props.extendTypes[item.type].render;
316
+ else
317
+ throw Error(item.type + " requires children or render");
318
+ continue;
319
+ }
293
320
  switch (item.type) {
294
321
  case "string[]":
295
322
  item.render = (value) => value.join(", ");
package/dist/index.mjs CHANGED
@@ -40,14 +40,23 @@ function DescriptionItemContent(props) {
40
40
  propsCopy.item.type = "string";
41
41
  setComputedProps(propsCopy);
42
42
  }, [props]);
43
- if (typeof computedProps.value === "undefined" || computedProps.value === null)
43
+ if (!computedProps || typeof computedProps.value === "undefined" || computedProps.value === null)
44
44
  return null;
45
- if (computedProps.item.children) {
45
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
46
+ if (computedProps.extendTypes[computedProps.item.type].children)
47
+ return cloneElement(computedProps.extendTypes[computedProps.item.type].children, {
48
+ value: computedProps.value,
49
+ values: computedProps.values
50
+ });
51
+ else if (computedProps.extendTypes[computedProps.item.type].render)
52
+ return computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values);
53
+ else
54
+ throw Error(computedProps.item.type + " requires children or render");
55
+ if (computedProps.item.children)
46
56
  return cloneElement(computedProps.item.children, { value: computedProps.value });
47
- }
57
+ if (computedProps.item.render)
58
+ return computedProps.item.render(computedProps.value, computedProps.values);
48
59
  switch (computedProps.item.type) {
49
- case "string":
50
- return computedProps.value;
51
60
  case "string[]":
52
61
  return computedProps.value.join(", ");
53
62
  case "number":
@@ -61,7 +70,7 @@ function DescriptionItemContent(props) {
61
70
  style: { marginTop: "4px" }
62
71
  });
63
72
  default:
64
- return null;
73
+ return computedProps.value;
65
74
  }
66
75
  }
67
76
  function Description(props) {
@@ -70,7 +79,9 @@ function Description(props) {
70
79
  label: item.title || upperFirst(item.id)
71
80
  }, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
72
81
  item,
73
- value: props.dataSource[item.id]
82
+ value: props.dataSource[item.id],
83
+ values: props.dataSource,
84
+ extendTypes: props.extendTypes
74
85
  }))));
75
86
  }
76
87
 
@@ -151,6 +162,8 @@ function FormItem(props) {
151
162
  }, [props]);
152
163
  if (!computedProps)
153
164
  return null;
165
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.type])
166
+ return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
154
167
  if (computedProps.children)
155
168
  return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.children);
156
169
  switch (computedProps.type) {
@@ -247,9 +260,11 @@ function FormItem(props) {
247
260
  // src/Form.tsx
248
261
  function Form(props) {
249
262
  var _a, _b;
250
- return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, props), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadValues({
263
+ return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, props), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
251
264
  key: item.id
252
- }, item))), props.children, props.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
265
+ }, item), {
266
+ extendTypes: props.extendTypes
267
+ }))), props.children, props.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
253
268
  htmlType: "submit",
254
269
  type: "primary"
255
270
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
@@ -257,7 +272,11 @@ function Form(props) {
257
272
  Form.useForm = AntdForm2.useForm;
258
273
 
259
274
  // src/Table.tsx
260
- import { useState as useState3, useEffect as useEffect3 } from "react";
275
+ import {
276
+ useState as useState3,
277
+ useEffect as useEffect3,
278
+ cloneElement as cloneElement2
279
+ } from "react";
261
280
  import {
262
281
  Table as AntdTable
263
282
  } from "antd";
@@ -277,6 +296,18 @@ function Table(props) {
277
296
  item.type = "string";
278
297
  if (item.render)
279
298
  continue;
299
+ if (props.extendTypes && props.extendTypes[item.type]) {
300
+ if (props.extendTypes[item.type].children) {
301
+ item.render = (value, values) => cloneElement2(props.extendTypes[item.type].children, {
302
+ value,
303
+ values
304
+ });
305
+ } else if (props.extendTypes[item.type].render)
306
+ item.render = props.extendTypes[item.type].render;
307
+ else
308
+ throw Error(item.type + " requires children or render");
309
+ continue;
310
+ }
280
311
  switch (item.type) {
281
312
  case "string[]":
282
313
  item.render = (value) => value.join(", ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.335",
3
+ "version": "0.0.2-beta.339",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,7 +26,8 @@
26
26
  "antd": "*",
27
27
  "lodash": "*",
28
28
  "react": "*",
29
- "react-dom": "*"
29
+ "react-dom": "*",
30
+ "@faasjs/react": "^0.0.2-beta.339"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@types/lodash": "*",