@faasjs/ant-design 0.0.2-beta.336 → 0.0.2-beta.340

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,22 +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 = FaasItemProps & {
25
- children?: JSX.Element;
26
+ declare type ExtendDescriptionTypeProps = {
27
+ children?: JSX.Element | null;
28
+ render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
26
29
  };
27
- declare type DescriptionProps<T = any> = {
28
- 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)[];
29
37
  dataSource: T;
38
+ extendTypes?: {
39
+ [key: string]: ExtendDescriptionTypeProps;
40
+ };
30
41
  } & DescriptionsProps;
31
42
  declare function Description(props: DescriptionProps): JSX.Element;
32
43
 
@@ -64,30 +75,49 @@ declare type OptionsProps<T = any> = {
64
75
  input?: SelectProps<any>;
65
76
  };
66
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;
67
82
  declare type FormItemProps<T = any> = {
68
83
  children?: JSX.Element;
69
84
  rules?: RuleObject[];
70
85
  label?: string | false;
86
+ extendTypes?: {
87
+ [type: string]: ExtendFormTypeProps;
88
+ };
71
89
  } & FormItemInputProps<T> & FaasItemProps & FormItemProps$1<T>;
72
90
  declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
73
91
 
74
- declare type FormProps<T = any> = {
75
- items?: FormItemProps[];
76
- /** Default: { text: 'Submit' } */
92
+ declare type FormProps<Values = any, ExtendItemProps = any> = {
93
+ items?: (FormItemProps | ExtendItemProps)[];
94
+ /** Default: { text: 'Submit' }, set false to disable it */
77
95
  submit?: false | {
78
96
  /** Default: Submit */
79
97
  text?: string;
80
98
  };
81
- } & FormProps$1<T>;
82
- 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;
83
104
  declare namespace Form {
84
105
  var useForm: typeof antd_lib_form_Form.useForm;
106
+ var Item: typeof FormItem;
85
107
  }
86
108
 
87
109
  declare type TableItemProps<T = any> = FaasItemProps & TableColumnProps<T>;
88
- declare type TableProps<T = any> = TableProps$1<T> & {
89
- items: TableItemProps[];
110
+ declare type ExtendTableTypeProps = {
111
+ children?: JSX.Element | null;
112
+ render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
90
113
  };
91
- 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;
92
122
 
93
- 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
@@ -72,9 +72,20 @@ function DescriptionItemContent(props) {
72
72
  }, [props]);
73
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
90
  case "string[]":
80
91
  return computedProps.value.join(", ");
@@ -98,7 +109,9 @@ function Description(props) {
98
109
  label: item.title || (0, import_lodash.upperFirst)(item.id)
99
110
  }, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
100
111
  item,
101
- value: props.dataSource[item.id]
112
+ value: props.dataSource[item.id],
113
+ values: props.dataSource,
114
+ extendTypes: props.extendTypes
102
115
  }))));
103
116
  }
104
117
 
@@ -164,6 +177,8 @@ function FormItem(props) {
164
177
  }, [props]);
165
178
  if (!computedProps)
166
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);
167
182
  if (computedProps.children)
168
183
  return /* @__PURE__ */ import_react.default.createElement(import_antd2.Form.Item, __spreadValues({}, computedProps), computedProps.children);
169
184
  switch (computedProps.type) {
@@ -260,14 +275,17 @@ function FormItem(props) {
260
275
  // src/Form.tsx
261
276
  function Form(props) {
262
277
  var _a, _b;
263
- 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({
264
279
  key: item.id
265
- }, 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, {
266
283
  htmlType: "submit",
267
284
  type: "primary"
268
285
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
269
286
  }
270
287
  Form.useForm = import_antd3.Form.useForm;
288
+ Form.Item = FormItem;
271
289
 
272
290
  // src/Table.tsx
273
291
  var import_react4 = require("react");
@@ -288,6 +306,18 @@ function Table(props) {
288
306
  item.type = "string";
289
307
  if (item.render)
290
308
  continue;
309
+ if (props.extendTypes && props.extendTypes[item.type]) {
310
+ if (props.extendTypes[item.type].children) {
311
+ item.render = (value, values) => (0, import_react4.cloneElement)(props.extendTypes[item.type].children, {
312
+ value,
313
+ values
314
+ });
315
+ } else if (props.extendTypes[item.type].render)
316
+ item.render = props.extendTypes[item.type].render;
317
+ else
318
+ throw Error(item.type + " requires children or render");
319
+ continue;
320
+ }
291
321
  switch (item.type) {
292
322
  case "string[]":
293
323
  item.render = (value) => value.join(", ");
package/dist/index.mjs CHANGED
@@ -42,9 +42,20 @@ function DescriptionItemContent(props) {
42
42
  }, [props]);
43
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
60
  case "string[]":
50
61
  return computedProps.value.join(", ");
@@ -68,7 +79,9 @@ function Description(props) {
68
79
  label: item.title || upperFirst(item.id)
69
80
  }, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
70
81
  item,
71
- value: props.dataSource[item.id]
82
+ value: props.dataSource[item.id],
83
+ values: props.dataSource,
84
+ extendTypes: props.extendTypes
72
85
  }))));
73
86
  }
74
87
 
@@ -149,6 +162,8 @@ function FormItem(props) {
149
162
  }, [props]);
150
163
  if (!computedProps)
151
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);
152
167
  if (computedProps.children)
153
168
  return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.children);
154
169
  switch (computedProps.type) {
@@ -245,17 +260,24 @@ function FormItem(props) {
245
260
  // src/Form.tsx
246
261
  function Form(props) {
247
262
  var _a, _b;
248
- 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({
249
264
  key: item.id
250
- }, 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, {
251
268
  htmlType: "submit",
252
269
  type: "primary"
253
270
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
254
271
  }
255
272
  Form.useForm = AntdForm2.useForm;
273
+ Form.Item = FormItem;
256
274
 
257
275
  // src/Table.tsx
258
- import { useState as useState3, useEffect as useEffect3 } from "react";
276
+ import {
277
+ useState as useState3,
278
+ useEffect as useEffect3,
279
+ cloneElement as cloneElement2
280
+ } from "react";
259
281
  import {
260
282
  Table as AntdTable
261
283
  } from "antd";
@@ -275,6 +297,18 @@ function Table(props) {
275
297
  item.type = "string";
276
298
  if (item.render)
277
299
  continue;
300
+ if (props.extendTypes && props.extendTypes[item.type]) {
301
+ if (props.extendTypes[item.type].children) {
302
+ item.render = (value, values) => cloneElement2(props.extendTypes[item.type].children, {
303
+ value,
304
+ values
305
+ });
306
+ } else if (props.extendTypes[item.type].render)
307
+ item.render = props.extendTypes[item.type].render;
308
+ else
309
+ throw Error(item.type + " requires children or render");
310
+ continue;
311
+ }
278
312
  switch (item.type) {
279
313
  case "string[]":
280
314
  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.336",
3
+ "version": "0.0.2-beta.340",
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.336"
30
+ "@faasjs/react": "^0.0.2-beta.340"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/lodash": "*",