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

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
@@ -23,19 +23,25 @@ declare type FaasItemProps = BaseItemType & {
23
23
  type?: FaasItemType;
24
24
  };
25
25
 
26
- declare type ExtendDescriptionItemProps = {
27
- [type: string]: {
28
- children: JSX.Element | null;
29
- };
26
+ declare type ExtendDescriptionTypeProps = {
27
+ children?: JSX.Element | null;
28
+ render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
30
29
  };
30
+ declare type ExtendDescriptionItemProps = BaseItemType;
31
31
  declare type DescriptionItemProps<T = any> = {
32
32
  children?: JSX.Element;
33
- render?: (value: T, values: any) => JSX.Element | null;
33
+ render?: (value: T, values: any) => JSX.Element | string | number | boolean | null;
34
34
  } & FaasItemProps;
35
35
  declare type DescriptionProps<T = any, ExtendItemProps = any> = {
36
36
  items: (DescriptionItemProps | ExtendItemProps)[];
37
- dataSource: T;
38
- extendTypes?: ExtendDescriptionItemProps;
37
+ dataSource?: T;
38
+ faasData?: {
39
+ action: string;
40
+ params?: Record<string, any>;
41
+ };
42
+ extendTypes?: {
43
+ [key: string]: ExtendDescriptionTypeProps;
44
+ };
39
45
  } & DescriptionsProps;
40
46
  declare function Description(props: DescriptionProps): JSX.Element;
41
47
 
@@ -73,16 +79,17 @@ declare type OptionsProps<T = any> = {
73
79
  input?: SelectProps<any>;
74
80
  };
75
81
  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
- };
82
+ declare type ExtendFormTypeProps = {
83
+ children?: JSX.Element | null;
80
84
  };
85
+ declare type ExtendFormItemProps = BaseItemType & FormItemProps$1;
81
86
  declare type FormItemProps<T = any> = {
82
87
  children?: JSX.Element;
83
88
  rules?: RuleObject[];
84
89
  label?: string | false;
85
- extendTypes?: ExtendFormItemProps;
90
+ extendTypes?: {
91
+ [type: string]: ExtendFormTypeProps;
92
+ };
86
93
  } & FormItemInputProps<T> & FaasItemProps & FormItemProps$1<T>;
87
94
  declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
88
95
 
@@ -93,23 +100,32 @@ declare type FormProps<Values = any, ExtendItemProps = any> = {
93
100
  /** Default: Submit */
94
101
  text?: string;
95
102
  };
96
- extendTypes?: ExtendFormItemProps;
103
+ extendTypes?: {
104
+ [type: string]: ExtendFormTypeProps;
105
+ };
97
106
  } & FormProps$1<Values>;
98
107
  declare function Form<Values = any>(props: FormProps<Values>): JSX.Element;
99
108
  declare namespace Form {
100
109
  var useForm: typeof antd_lib_form_Form.useForm;
110
+ var Item: typeof FormItem;
101
111
  }
102
112
 
103
113
  declare type TableItemProps<T = any> = FaasItemProps & TableColumnProps<T>;
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;
114
+ declare type ExtendTableTypeProps = {
115
+ children?: JSX.Element | null;
116
+ render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
112
117
  };
118
+ declare type ExtendTableItemProps<T = any> = BaseItemType & TableColumnProps<T>;
119
+ declare type TableProps<T = any, ExtendTypes = any> = {
120
+ items: (TableItemProps | (ExtendTypes & BaseItemType))[];
121
+ extendTypes?: {
122
+ [key: string]: ExtendTableTypeProps;
123
+ };
124
+ faasData?: {
125
+ action: string;
126
+ params?: Record<string, any>;
127
+ };
128
+ } & TableProps$1<T>;
113
129
  declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
114
130
 
115
- export { BaseItemType, Description, DescriptionItemProps, DescriptionProps, ExtendDescriptionItemProps, ExtendFormItemProps, ExtendTableItemProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps };
131
+ 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
@@ -59,10 +59,34 @@ var import_react = __toESM(require("react"));
59
59
  var import_icons = require("@ant-design/icons");
60
60
  var import_antd = require("antd");
61
61
  var import_lodash = require("lodash");
62
+ var import_react4 = require("react");
63
+
64
+ // src/FaasWrapper.tsx
62
65
  var import_react2 = require("react");
63
- function DescriptionItemContent(props) {
64
- const [computedProps, setComputedProps] = (0, import_react2.useState)();
66
+ var import_react3 = require("@faasjs/react");
67
+ function FaasDataWrapper({
68
+ dataSource,
69
+ faasData,
70
+ render,
71
+ fallback
72
+ }) {
73
+ const [data, setData] = (0, import_react2.useState)();
65
74
  (0, import_react2.useEffect)(() => {
75
+ if (!faasData)
76
+ return;
77
+ (0, import_react3.getClient)().faas(faasData.action, faasData.action).then((res) => setData(res.data));
78
+ }, [JSON.stringify(faasData)]);
79
+ if (dataSource)
80
+ return render({ data: dataSource });
81
+ if (!data)
82
+ return fallback || null;
83
+ return render({ data });
84
+ }
85
+
86
+ // src/Description.tsx
87
+ function DescriptionItemContent(props) {
88
+ const [computedProps, setComputedProps] = (0, import_react4.useState)();
89
+ (0, import_react4.useEffect)(() => {
66
90
  const propsCopy = __spreadValues({}, props);
67
91
  if (!propsCopy.item.title)
68
92
  propsCopy.item.title = (0, import_lodash.upperFirst)(propsCopy.item.id);
@@ -70,17 +94,24 @@ function DescriptionItemContent(props) {
70
94
  propsCopy.item.type = "string";
71
95
  setComputedProps(propsCopy);
72
96
  }, [props]);
73
- if (!computedProps || typeof computedProps.value === "undefined" || computedProps.value === null)
97
+ if (!computedProps)
74
98
  return null;
75
99
  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
- });
100
+ if (computedProps.extendTypes[computedProps.item.type].children)
101
+ return (0, import_react4.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
102
+ value: computedProps.value,
103
+ values: computedProps.values
104
+ });
105
+ else if (computedProps.extendTypes[computedProps.item.type].render)
106
+ return computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values);
107
+ else
108
+ throw Error(computedProps.item.type + " requires children or render");
80
109
  if (computedProps.item.children)
81
- return (0, import_react2.cloneElement)(computedProps.item.children, { value: computedProps.value });
110
+ return (0, import_react4.cloneElement)(computedProps.item.children, { value: computedProps.value });
82
111
  if (computedProps.item.render)
83
112
  return computedProps.item.render(computedProps.value, computedProps.values);
113
+ if (typeof computedProps.value === "undefined" || computedProps.value === null)
114
+ return null;
84
115
  switch (computedProps.item.type) {
85
116
  case "string[]":
86
117
  return computedProps.value.join(", ");
@@ -99,15 +130,19 @@ function DescriptionItemContent(props) {
99
130
  }
100
131
  }
101
132
  function Description(props) {
102
- return /* @__PURE__ */ import_react.default.createElement(import_antd.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd.Descriptions.Item, {
103
- key: item.id,
104
- label: item.title || (0, import_lodash.upperFirst)(item.id)
105
- }, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
106
- item,
107
- value: props.dataSource[item.id],
108
- values: props.dataSource,
109
- extendTypes: props.extendTypes
110
- }))));
133
+ return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, {
134
+ dataSource: props.dataSource,
135
+ faasData: props.faasData,
136
+ render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd.Descriptions.Item, {
137
+ key: item.id,
138
+ label: item.title || (0, import_lodash.upperFirst)(item.id)
139
+ }, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
140
+ item,
141
+ value: data[item.id],
142
+ values: data,
143
+ extendTypes: props.extendTypes
144
+ }))))
145
+ });
111
146
  }
112
147
 
113
148
  // src/Form.tsx
@@ -116,11 +151,11 @@ var import_antd3 = require("antd");
116
151
  // src/FormItem.tsx
117
152
  var import_antd2 = require("antd");
118
153
  var import_icons2 = require("@ant-design/icons");
119
- var import_react3 = require("react");
154
+ var import_react5 = require("react");
120
155
  var import_lodash2 = require("lodash");
121
156
  function FormItem(props) {
122
- const [computedProps, setComputedProps] = (0, import_react3.useState)();
123
- (0, import_react3.useEffect)(() => {
157
+ const [computedProps, setComputedProps] = (0, import_react5.useState)();
158
+ (0, import_react5.useEffect)(() => {
124
159
  const propsCopy = __spreadValues({}, props);
125
160
  if (!propsCopy.title)
126
161
  propsCopy.title = (0, import_lodash2.upperFirst)(propsCopy.id);
@@ -280,15 +315,16 @@ function Form(props) {
280
315
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
281
316
  }
282
317
  Form.useForm = import_antd3.Form.useForm;
318
+ Form.Item = FormItem;
283
319
 
284
320
  // src/Table.tsx
285
- var import_react4 = require("react");
321
+ var import_react6 = require("react");
286
322
  var import_antd4 = require("antd");
287
323
  var import_icons3 = require("@ant-design/icons");
288
324
  var import_lodash3 = require("lodash");
289
325
  function Table(props) {
290
- const [columns, setColumns] = (0, import_react4.useState)();
291
- (0, import_react4.useEffect)(() => {
326
+ const [columns, setColumns] = (0, import_react6.useState)();
327
+ (0, import_react6.useEffect)(() => {
292
328
  for (const item of props.items) {
293
329
  if (!item.key)
294
330
  item.key = item.id;
@@ -301,10 +337,15 @@ function Table(props) {
301
337
  if (item.render)
302
338
  continue;
303
339
  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
- });
340
+ if (props.extendTypes[item.type].children) {
341
+ item.render = (value, values) => (0, import_react6.cloneElement)(props.extendTypes[item.type].children, {
342
+ value,
343
+ values
344
+ });
345
+ } else if (props.extendTypes[item.type].render)
346
+ item.render = props.extendTypes[item.type].render;
347
+ else
348
+ throw Error(item.type + " requires children or render");
308
349
  continue;
309
350
  }
310
351
  switch (item.type) {
@@ -327,10 +368,15 @@ function Table(props) {
327
368
  }, [props.items]);
328
369
  if (!columns)
329
370
  return null;
330
- return /* @__PURE__ */ import_react.default.createElement(import_antd4.Table, __spreadProps(__spreadValues({}, props), {
331
- rowKey: props.rowKey || "id",
332
- columns
333
- }));
371
+ return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, {
372
+ dataSource: props.dataSource,
373
+ faasData: props.faasData,
374
+ render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd4.Table, __spreadProps(__spreadValues({}, props), {
375
+ rowKey: props.rowKey || "id",
376
+ columns,
377
+ dataSource: data
378
+ }))
379
+ });
334
380
  }
335
381
  module.exports = __toCommonJS(src_exports);
336
382
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -27,12 +27,36 @@ import { Descriptions } from "antd";
27
27
  import { upperFirst } from "lodash";
28
28
  import {
29
29
  cloneElement,
30
- useEffect,
31
- useState
30
+ useEffect as useEffect2,
31
+ useState as useState2
32
32
  } from "react";
33
- function DescriptionItemContent(props) {
34
- const [computedProps, setComputedProps] = useState();
33
+
34
+ // src/FaasWrapper.tsx
35
+ import { useEffect, useState } from "react";
36
+ import { getClient } from "@faasjs/react";
37
+ function FaasDataWrapper({
38
+ dataSource,
39
+ faasData,
40
+ render,
41
+ fallback
42
+ }) {
43
+ const [data, setData] = useState();
35
44
  useEffect(() => {
45
+ if (!faasData)
46
+ return;
47
+ getClient().faas(faasData.action, faasData.action).then((res) => setData(res.data));
48
+ }, [JSON.stringify(faasData)]);
49
+ if (dataSource)
50
+ return render({ data: dataSource });
51
+ if (!data)
52
+ return fallback || null;
53
+ return render({ data });
54
+ }
55
+
56
+ // src/Description.tsx
57
+ function DescriptionItemContent(props) {
58
+ const [computedProps, setComputedProps] = useState2();
59
+ useEffect2(() => {
36
60
  const propsCopy = __spreadValues({}, props);
37
61
  if (!propsCopy.item.title)
38
62
  propsCopy.item.title = upperFirst(propsCopy.item.id);
@@ -40,17 +64,24 @@ function DescriptionItemContent(props) {
40
64
  propsCopy.item.type = "string";
41
65
  setComputedProps(propsCopy);
42
66
  }, [props]);
43
- if (!computedProps || typeof computedProps.value === "undefined" || computedProps.value === null)
67
+ if (!computedProps)
44
68
  return null;
45
69
  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
- });
70
+ if (computedProps.extendTypes[computedProps.item.type].children)
71
+ return cloneElement(computedProps.extendTypes[computedProps.item.type].children, {
72
+ value: computedProps.value,
73
+ values: computedProps.values
74
+ });
75
+ else if (computedProps.extendTypes[computedProps.item.type].render)
76
+ return computedProps.extendTypes[computedProps.item.type].render(computedProps.value, computedProps.values);
77
+ else
78
+ throw Error(computedProps.item.type + " requires children or render");
50
79
  if (computedProps.item.children)
51
80
  return cloneElement(computedProps.item.children, { value: computedProps.value });
52
81
  if (computedProps.item.render)
53
82
  return computedProps.item.render(computedProps.value, computedProps.values);
83
+ if (typeof computedProps.value === "undefined" || computedProps.value === null)
84
+ return null;
54
85
  switch (computedProps.item.type) {
55
86
  case "string[]":
56
87
  return computedProps.value.join(", ");
@@ -69,15 +100,19 @@ function DescriptionItemContent(props) {
69
100
  }
70
101
  }
71
102
  function Description(props) {
72
- return /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
73
- key: item.id,
74
- label: item.title || upperFirst(item.id)
75
- }, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
76
- item,
77
- value: props.dataSource[item.id],
78
- values: props.dataSource,
79
- extendTypes: props.extendTypes
80
- }))));
103
+ return /* @__PURE__ */ React.createElement(FaasDataWrapper, {
104
+ dataSource: props.dataSource,
105
+ faasData: props.faasData,
106
+ render: ({ data }) => /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
107
+ key: item.id,
108
+ label: item.title || upperFirst(item.id)
109
+ }, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
110
+ item,
111
+ value: data[item.id],
112
+ values: data,
113
+ extendTypes: props.extendTypes
114
+ }))))
115
+ });
81
116
  }
82
117
 
83
118
  // src/Form.tsx
@@ -99,13 +134,13 @@ import {
99
134
  } from "antd";
100
135
  import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
101
136
  import {
102
- useEffect as useEffect2,
103
- useState as useState2
137
+ useEffect as useEffect3,
138
+ useState as useState3
104
139
  } from "react";
105
140
  import { upperFirst as upperFirst2 } from "lodash";
106
141
  function FormItem(props) {
107
- const [computedProps, setComputedProps] = useState2();
108
- useEffect2(() => {
142
+ const [computedProps, setComputedProps] = useState3();
143
+ useEffect3(() => {
109
144
  const propsCopy = __spreadValues({}, props);
110
145
  if (!propsCopy.title)
111
146
  propsCopy.title = upperFirst2(propsCopy.id);
@@ -265,11 +300,12 @@ function Form(props) {
265
300
  }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
266
301
  }
267
302
  Form.useForm = AntdForm2.useForm;
303
+ Form.Item = FormItem;
268
304
 
269
305
  // src/Table.tsx
270
306
  import {
271
- useState as useState3,
272
- useEffect as useEffect3,
307
+ useState as useState4,
308
+ useEffect as useEffect4,
273
309
  cloneElement as cloneElement2
274
310
  } from "react";
275
311
  import {
@@ -278,8 +314,8 @@ import {
278
314
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
279
315
  import { upperFirst as upperFirst3 } from "lodash";
280
316
  function Table(props) {
281
- const [columns, setColumns] = useState3();
282
- useEffect3(() => {
317
+ const [columns, setColumns] = useState4();
318
+ useEffect4(() => {
283
319
  for (const item of props.items) {
284
320
  if (!item.key)
285
321
  item.key = item.id;
@@ -292,10 +328,15 @@ function Table(props) {
292
328
  if (item.render)
293
329
  continue;
294
330
  if (props.extendTypes && props.extendTypes[item.type]) {
295
- item.render = (value, values) => cloneElement2(props.extendTypes[item.type].children, {
296
- value,
297
- values
298
- });
331
+ if (props.extendTypes[item.type].children) {
332
+ item.render = (value, values) => cloneElement2(props.extendTypes[item.type].children, {
333
+ value,
334
+ values
335
+ });
336
+ } else if (props.extendTypes[item.type].render)
337
+ item.render = props.extendTypes[item.type].render;
338
+ else
339
+ throw Error(item.type + " requires children or render");
299
340
  continue;
300
341
  }
301
342
  switch (item.type) {
@@ -318,10 +359,15 @@ function Table(props) {
318
359
  }, [props.items]);
319
360
  if (!columns)
320
361
  return null;
321
- return /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
322
- rowKey: props.rowKey || "id",
323
- columns
324
- }));
362
+ return /* @__PURE__ */ React.createElement(FaasDataWrapper, {
363
+ dataSource: props.dataSource,
364
+ faasData: props.faasData,
365
+ render: ({ data }) => /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
366
+ rowKey: props.rowKey || "id",
367
+ columns,
368
+ dataSource: data
369
+ }))
370
+ });
325
371
  }
326
372
  export {
327
373
  Description,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.338",
3
+ "version": "0.0.2-beta.342",
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.338"
30
+ "@faasjs/react": "^0.0.2-beta.342"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/lodash": "*",