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

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,31 @@ 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 & {
26
+ declare type ExtendDescriptionItemProps = {
27
+ [type: string]: {
28
+ children: JSX.Element | null;
29
+ };
30
+ };
31
+ declare type DescriptionItemProps<T = any> = {
25
32
  children?: JSX.Element;
26
33
  render?: (value: T, values: any) => JSX.Element | null;
27
- };
28
- declare type DescriptionProps<T = any> = {
29
- items: DescriptionItemProps[];
34
+ } & FaasItemProps;
35
+ declare type DescriptionProps<T = any, ExtendItemProps = any> = {
36
+ items: (DescriptionItemProps | ExtendItemProps)[];
30
37
  dataSource: T;
38
+ extendTypes?: ExtendDescriptionItemProps;
31
39
  } & DescriptionsProps;
32
40
  declare function Description(props: DescriptionProps): JSX.Element;
33
41
 
@@ -65,30 +73,43 @@ declare type OptionsProps<T = any> = {
65
73
  input?: SelectProps<any>;
66
74
  };
67
75
  declare type FormItemInputProps<T = any> = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps<T>;
76
+ declare type ExtendFormItemProps = {
77
+ [type: string]: {
78
+ children: JSX.Element | null;
79
+ };
80
+ };
68
81
  declare type FormItemProps<T = any> = {
69
82
  children?: JSX.Element;
70
83
  rules?: RuleObject[];
71
84
  label?: string | false;
85
+ extendTypes?: ExtendFormItemProps;
72
86
  } & FormItemInputProps<T> & FaasItemProps & FormItemProps$1<T>;
73
87
  declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
74
88
 
75
- declare type FormProps<T = any> = {
76
- items?: FormItemProps[];
77
- /** Default: { text: 'Submit' } */
89
+ declare type FormProps<Values = any, ExtendItemProps = any> = {
90
+ items?: (FormItemProps | ExtendItemProps)[];
91
+ /** Default: { text: 'Submit' }, set false to disable it */
78
92
  submit?: false | {
79
93
  /** Default: Submit */
80
94
  text?: string;
81
95
  };
82
- } & FormProps$1<T>;
83
- declare function Form<T = any>(props: FormProps<T>): JSX.Element;
96
+ extendTypes?: ExtendFormItemProps;
97
+ } & FormProps$1<Values>;
98
+ declare function Form<Values = any>(props: FormProps<Values>): JSX.Element;
84
99
  declare namespace Form {
85
100
  var useForm: typeof antd_lib_form_Form.useForm;
86
101
  }
87
102
 
88
103
  declare type TableItemProps<T = any> = FaasItemProps & TableColumnProps<T>;
89
- declare type TableProps<T = any> = TableProps$1<T> & {
90
- items: TableItemProps[];
104
+ declare type ExtendTableItemProps = {
105
+ [type: string]: {
106
+ children: JSX.Element | null;
107
+ };
108
+ };
109
+ declare type TableProps<T = any, ExtendTypes = any> = TableProps$1<T> & {
110
+ items: (TableItemProps | ExtendTypes)[];
111
+ extendTypes?: ExtendTableItemProps;
91
112
  };
92
- declare function Table(props: TableProps): JSX.Element;
113
+ declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
93
114
 
94
- export { Description, DescriptionItemProps, DescriptionProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps };
115
+ export { BaseItemType, Description, DescriptionItemProps, DescriptionProps, ExtendDescriptionItemProps, ExtendFormItemProps, ExtendTableItemProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps };
package/dist/index.js CHANGED
@@ -72,6 +72,11 @@ function DescriptionItemContent(props) {
72
72
  }, [props]);
73
73
  if (!computedProps || typeof computedProps.value === "undefined" || computedProps.value === null)
74
74
  return null;
75
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
76
+ return (0, import_react2.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
77
+ value: computedProps.value,
78
+ values: computedProps.values
79
+ });
75
80
  if (computedProps.item.children)
76
81
  return (0, import_react2.cloneElement)(computedProps.item.children, { value: computedProps.value });
77
82
  if (computedProps.item.render)
@@ -100,7 +105,8 @@ function Description(props) {
100
105
  }, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
101
106
  item,
102
107
  value: props.dataSource[item.id],
103
- values: props.dataSource
108
+ values: props.dataSource,
109
+ extendTypes: props.extendTypes
104
110
  }))));
105
111
  }
106
112
 
@@ -166,6 +172,8 @@ function FormItem(props) {
166
172
  }, [props]);
167
173
  if (!computedProps)
168
174
  return null;
175
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.type])
176
+ return /* @__PURE__ */ import_react.default.createElement(import_antd2.Form.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
169
177
  if (computedProps.children)
170
178
  return /* @__PURE__ */ import_react.default.createElement(import_antd2.Form.Item, __spreadValues({}, computedProps), computedProps.children);
171
179
  switch (computedProps.type) {
@@ -262,9 +270,11 @@ function FormItem(props) {
262
270
  // src/Form.tsx
263
271
  function Form(props) {
264
272
  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({
273
+ 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
274
  key: item.id
267
- }, item))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd3.Button, {
275
+ }, item), {
276
+ extendTypes: props.extendTypes
277
+ }))), props.children, props.submit !== false && /* @__PURE__ */ import_react.default.createElement(import_antd3.Button, {
268
278
  htmlType: "submit",
269
279
  type: "primary"
270
280
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
@@ -290,6 +300,13 @@ function Table(props) {
290
300
  item.type = "string";
291
301
  if (item.render)
292
302
  continue;
303
+ if (props.extendTypes && props.extendTypes[item.type]) {
304
+ item.render = (value, values) => (0, import_react4.cloneElement)(props.extendTypes[item.type].children, {
305
+ value,
306
+ values
307
+ });
308
+ continue;
309
+ }
293
310
  switch (item.type) {
294
311
  case "string[]":
295
312
  item.render = (value) => value.join(", ");
package/dist/index.mjs CHANGED
@@ -42,6 +42,11 @@ function DescriptionItemContent(props) {
42
42
  }, [props]);
43
43
  if (!computedProps || typeof computedProps.value === "undefined" || computedProps.value === null)
44
44
  return null;
45
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
46
+ return cloneElement(computedProps.extendTypes[computedProps.item.type].children, {
47
+ value: computedProps.value,
48
+ values: computedProps.values
49
+ });
45
50
  if (computedProps.item.children)
46
51
  return cloneElement(computedProps.item.children, { value: computedProps.value });
47
52
  if (computedProps.item.render)
@@ -70,7 +75,8 @@ function Description(props) {
70
75
  }, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
71
76
  item,
72
77
  value: props.dataSource[item.id],
73
- values: props.dataSource
78
+ values: props.dataSource,
79
+ extendTypes: props.extendTypes
74
80
  }))));
75
81
  }
76
82
 
@@ -151,6 +157,8 @@ function FormItem(props) {
151
157
  }, [props]);
152
158
  if (!computedProps)
153
159
  return null;
160
+ if (computedProps.extendTypes && computedProps.extendTypes[computedProps.type])
161
+ return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
154
162
  if (computedProps.children)
155
163
  return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.children);
156
164
  switch (computedProps.type) {
@@ -247,9 +255,11 @@ function FormItem(props) {
247
255
  // src/Form.tsx
248
256
  function Form(props) {
249
257
  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({
258
+ return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, props), (_a = props.items) == null ? void 0 : _a.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
251
259
  key: item.id
252
- }, item))), props.children, props.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
260
+ }, item), {
261
+ extendTypes: props.extendTypes
262
+ }))), props.children, props.submit !== false && /* @__PURE__ */ React.createElement(Button2, {
253
263
  htmlType: "submit",
254
264
  type: "primary"
255
265
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
@@ -257,7 +267,11 @@ function Form(props) {
257
267
  Form.useForm = AntdForm2.useForm;
258
268
 
259
269
  // src/Table.tsx
260
- import { useState as useState3, useEffect as useEffect3 } from "react";
270
+ import {
271
+ useState as useState3,
272
+ useEffect as useEffect3,
273
+ cloneElement as cloneElement2
274
+ } from "react";
261
275
  import {
262
276
  Table as AntdTable
263
277
  } from "antd";
@@ -277,6 +291,13 @@ function Table(props) {
277
291
  item.type = "string";
278
292
  if (item.render)
279
293
  continue;
294
+ if (props.extendTypes && props.extendTypes[item.type]) {
295
+ item.render = (value, values) => cloneElement2(props.extendTypes[item.type].children, {
296
+ value,
297
+ values
298
+ });
299
+ continue;
300
+ }
280
301
  switch (item.type) {
281
302
  case "string[]":
282
303
  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.338",
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.338"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/lodash": "*",