@faasjs/ant-design 0.0.2-beta.337 → 0.0.2-beta.341

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