@faasjs/ant-design 0.0.2-beta.345 → 0.0.2-beta.346

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
@@ -1,7 +1,6 @@
1
1
  import { DescriptionsProps, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, FormProps as FormProps$1, TableColumnProps, TableProps as TableProps$1 } from 'antd';
2
2
  import * as antd_lib_form_Form from 'antd/lib/form/Form';
3
3
  import { RuleObject } from 'rc-field-form/lib/interface';
4
- import { ReactNode } from 'react';
5
4
 
6
5
  declare function Blank(options?: {
7
6
  value?: any;
@@ -16,28 +15,33 @@ declare type FaasItemTypeValue = {
16
15
  'number[]': number[];
17
16
  boolean: boolean;
18
17
  };
19
- declare type BaseItemType = {
18
+ declare type BaseOption = string | number | {
19
+ label: string;
20
+ value?: string | number;
21
+ };
22
+ declare type BaseItemProps = {
20
23
  id: string;
21
24
  title?: string;
25
+ options?: BaseOption[];
22
26
  };
23
- declare type FaasItemProps = BaseItemType & {
27
+ declare type FaasItemProps = BaseItemProps & {
24
28
  /**
25
29
  * Support string, string[], number, number[], boolean
26
30
  * @default 'string'
27
31
  */
28
32
  type?: FaasItemType;
29
33
  };
34
+ declare function transferOptions(options: BaseOption[]): {
35
+ label: string;
36
+ value?: string | number;
37
+ }[];
30
38
 
31
39
  declare type ExtendDescriptionTypeProps = {
32
40
  children?: JSX.Element | null;
33
41
  render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
34
42
  };
35
- declare type ExtendDescriptionItemProps = BaseItemType;
43
+ declare type ExtendDescriptionItemProps = BaseItemProps;
36
44
  declare type DescriptionItemProps<T = any> = {
37
- options?: {
38
- label: string;
39
- value?: T;
40
- }[];
41
45
  children?: JSX.Element;
42
46
  render?: (value: T, values: any) => JSX.Element | string | number | boolean | null;
43
47
  } & FaasItemProps;
@@ -76,22 +80,16 @@ declare type BooleanProps = {
76
80
  type: 'boolean';
77
81
  input?: SwitchProps;
78
82
  };
79
- declare type OptionType<T = any> = {
80
- label: ReactNode;
81
- value?: T;
82
- disabled?: boolean;
83
- children?: Omit<OptionType<T>, 'children'>[];
84
- };
85
- declare type OptionsProps<T = any> = {
86
- options?: OptionType<T>[] | string[] | number[];
83
+ declare type OptionsProps = {
84
+ options: BaseOption[];
87
85
  type?: 'string' | 'string[]' | 'number' | 'number[]';
88
86
  input?: SelectProps<any>;
89
87
  };
90
- declare type FormItemInputProps<T = any> = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps<T>;
88
+ declare type FormItemInputProps<T = any> = StringProps | StringListProps | NumberProps | NumberListProps | BooleanProps | OptionsProps;
91
89
  declare type ExtendFormTypeProps = {
92
90
  children?: JSX.Element | null;
93
91
  };
94
- declare type ExtendFormItemProps = BaseItemType & FormItemProps$1;
92
+ declare type ExtendFormItemProps = BaseItemProps & FormItemProps$1;
95
93
  declare type FormItemProps<T = any> = {
96
94
  children?: JSX.Element;
97
95
  rules?: RuleObject[];
@@ -119,17 +117,12 @@ declare namespace Form {
119
117
  var Item: typeof FormItem;
120
118
  }
121
119
 
122
- declare type TableItemProps<T = any> = {
123
- options?: {
124
- label: string;
125
- value?: T;
126
- }[];
127
- } & FaasItemProps & TableColumnProps<T>;
120
+ declare type TableItemProps<T = any> = FaasItemProps & TableColumnProps<T>;
128
121
  declare type ExtendTableTypeProps = {
129
122
  children?: JSX.Element | null;
130
123
  render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
131
124
  };
132
- declare type ExtendTableItemProps<T = any> = BaseItemType & TableColumnProps<T>;
125
+ declare type ExtendTableItemProps<T = any> = BaseItemProps & TableColumnProps<T>;
133
126
  declare type TableProps<T = any, ExtendTypes = any> = {
134
127
  items: (TableItemProps | (ExtendTypes & ExtendTableItemProps))[];
135
128
  extendTypes?: {
@@ -142,4 +135,4 @@ declare type TableProps<T = any, ExtendTypes = any> = {
142
135
  } & TableProps$1<T>;
143
136
  declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
144
137
 
145
- export { BaseItemType, Blank, Description, DescriptionItemProps, DescriptionProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps };
138
+ export { BaseItemProps, BaseOption, Blank, Description, DescriptionItemProps, DescriptionProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps, transferOptions };
package/dist/index.js CHANGED
@@ -50,7 +50,8 @@ __export(src_exports, {
50
50
  Description: () => Description,
51
51
  Form: () => Form,
52
52
  FormItem: () => FormItem,
53
- Table: () => Table
53
+ Table: () => Table,
54
+ transferOptions: () => transferOptions
54
55
  });
55
56
 
56
57
  // react-shim.js
@@ -67,10 +68,21 @@ function Blank(options) {
67
68
  }, (options == null ? void 0 : options.text) || text) : options.value;
68
69
  }
69
70
 
71
+ // src/data.ts
72
+ var import_lodash2 = require("lodash");
73
+ function transferOptions(options) {
74
+ if (!options)
75
+ return [];
76
+ return options.map((item) => typeof item === "object" ? item : {
77
+ label: (0, import_lodash2.upperFirst)(item.toString()),
78
+ value: item
79
+ });
80
+ }
81
+
70
82
  // src/Description.tsx
71
83
  var import_icons = require("@ant-design/icons");
72
84
  var import_antd2 = require("antd");
73
- var import_lodash2 = require("lodash");
85
+ var import_lodash3 = require("lodash");
74
86
  var import_react4 = require("react");
75
87
 
76
88
  // src/FaasWrapper.tsx
@@ -99,20 +111,23 @@ function FaasDataWrapper({
99
111
  function DescriptionItemContent(props) {
100
112
  const [computedProps, setComputedProps] = (0, import_react4.useState)();
101
113
  (0, import_react4.useEffect)(() => {
102
- var _a2;
114
+ var _a2, _b;
103
115
  const propsCopy = __spreadValues({}, props);
104
116
  if (!propsCopy.item.title)
105
- propsCopy.item.title = (0, import_lodash2.upperFirst)(propsCopy.item.id);
117
+ propsCopy.item.title = (0, import_lodash3.upperFirst)(propsCopy.item.id);
106
118
  if (!propsCopy.item.type)
107
119
  propsCopy.item.type = "string";
108
- if (props.item.options && typeof props.value !== "undefined" && props.value !== null) {
109
- if (props.item.type.endsWith("[]"))
110
- propsCopy.value = props.value.map((v) => {
120
+ if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
121
+ propsCopy.item.options = transferOptions(propsCopy.item.options);
122
+ }
123
+ if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
124
+ if (propsCopy.item.type.endsWith("[]"))
125
+ propsCopy.value = propsCopy.value.map((v) => {
111
126
  var _a3;
112
- return ((_a3 = props.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
127
+ return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
113
128
  });
114
129
  else
115
- propsCopy.value = ((_a2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _a2.label) || props.value;
130
+ propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
116
131
  }
117
132
  setComputedProps(propsCopy);
118
133
  }, [props]);
@@ -163,7 +178,7 @@ function Description(props) {
163
178
  faasData: props.faasData,
164
179
  render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions.Item, {
165
180
  key: item.id,
166
- label: item.title || (0, import_lodash2.upperFirst)(item.id)
181
+ label: item.title || (0, import_lodash3.upperFirst)(item.id)
167
182
  }, /* @__PURE__ */ import_react.default.createElement(DescriptionItemContent, {
168
183
  item,
169
184
  value: data[item.id],
@@ -180,13 +195,13 @@ var import_antd4 = require("antd");
180
195
  var import_antd3 = require("antd");
181
196
  var import_icons2 = require("@ant-design/icons");
182
197
  var import_react5 = require("react");
183
- var import_lodash3 = require("lodash");
198
+ var import_lodash4 = require("lodash");
184
199
  function FormItem(props) {
185
200
  const [computedProps, setComputedProps] = (0, import_react5.useState)();
186
201
  (0, import_react5.useEffect)(() => {
187
202
  const propsCopy = __spreadValues({}, props);
188
203
  if (!propsCopy.title)
189
- propsCopy.title = (0, import_lodash3.upperFirst)(propsCopy.id);
204
+ propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
190
205
  if (!propsCopy.label && props.label !== false)
191
206
  propsCopy.label = propsCopy.title;
192
207
  if (!propsCopy.name)
@@ -212,20 +227,8 @@ function FormItem(props) {
212
227
  }
213
228
  if (!propsCopy.input)
214
229
  propsCopy.input = {};
215
- if (propsCopy.options) {
216
- const options = [];
217
- if (propsCopy.options.length > 0)
218
- for (const option of propsCopy.options) {
219
- if (typeof option === "object")
220
- options.push(option);
221
- else
222
- options.push({
223
- label: (0, import_lodash3.upperFirst)(option.toString()),
224
- value: option
225
- });
226
- }
227
- propsCopy.input.options = options;
228
- }
230
+ if (propsCopy.options)
231
+ propsCopy.input.options = transferOptions(propsCopy.options);
229
232
  switch (propsCopy.type) {
230
233
  case "boolean":
231
234
  propsCopy.valuePropName = "checked";
@@ -349,7 +352,7 @@ Form.Item = FormItem;
349
352
  var import_react6 = require("react");
350
353
  var import_antd5 = require("antd");
351
354
  var import_icons3 = require("@ant-design/icons");
352
- var import_lodash4 = require("lodash");
355
+ var import_lodash5 = require("lodash");
353
356
  function processValue(item, value) {
354
357
  var _a2;
355
358
  if (item.options && typeof value !== "undefined" && value !== null) {
@@ -366,15 +369,23 @@ function processValue(item, value) {
366
369
  function Table(props) {
367
370
  const [columns, setColumns] = (0, import_react6.useState)();
368
371
  (0, import_react6.useEffect)(() => {
372
+ var _a2;
369
373
  for (const item of props.items) {
370
374
  if (!item.key)
371
375
  item.key = item.id;
372
376
  if (!item.dataIndex)
373
377
  item.dataIndex = item.id;
374
378
  if (!item.title)
375
- item.title = (0, import_lodash4.upperFirst)(item.id);
379
+ item.title = (0, import_lodash5.upperFirst)(item.id);
376
380
  if (!item.type)
377
381
  item.type = "string";
382
+ if ((_a2 = item.options) == null ? void 0 : _a2.length) {
383
+ item.options = transferOptions(item.options);
384
+ item.filters = item.options.map((o) => ({
385
+ text: o.label,
386
+ value: o.value
387
+ }));
388
+ }
378
389
  if (item.render)
379
390
  continue;
380
391
  if (props.extendTypes && props.extendTypes[item.type]) {
@@ -419,7 +430,7 @@ function Table(props) {
419
430
  selectedKeys,
420
431
  confirm
421
432
  }) => {
422
- var _a2, _b;
433
+ var _a3, _b;
423
434
  return /* @__PURE__ */ import_react.default.createElement(import_antd5.Radio.Group, {
424
435
  style: { padding: 8 },
425
436
  buttonStyle: "solid",
@@ -428,7 +439,7 @@ function Table(props) {
428
439
  setSelectedKeys(e.target.value ? [e.target.value] : []);
429
440
  confirm();
430
441
  }
431
- }, /* @__PURE__ */ import_react.default.createElement(import_antd5.Radio.Button, null, ((_a2 = navigator.language) == null ? void 0 : _a2.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ import_react.default.createElement(import_antd5.Radio.Button, {
442
+ }, /* @__PURE__ */ import_react.default.createElement(import_antd5.Radio.Button, null, ((_a3 = navigator.language) == null ? void 0 : _a3.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ import_react.default.createElement(import_antd5.Radio.Button, {
432
443
  value: "true"
433
444
  }, /* @__PURE__ */ import_react.default.createElement(import_icons3.CheckOutlined, {
434
445
  style: {
@@ -450,11 +461,11 @@ function Table(props) {
450
461
  item.onFilter = (value, row) => {
451
462
  switch (value) {
452
463
  case "true":
453
- return !(0, import_lodash4.isNil)(row[item.id]) && !!row[item.id];
464
+ return !(0, import_lodash5.isNil)(row[item.id]) && !!row[item.id];
454
465
  case "false":
455
- return !(0, import_lodash4.isNil)(row[item.id]) && !row[item.id];
466
+ return !(0, import_lodash5.isNil)(row[item.id]) && !row[item.id];
456
467
  case "empty":
457
- return (0, import_lodash4.isNil)(row[item.id]);
468
+ return (0, import_lodash5.isNil)(row[item.id]);
458
469
  default:
459
470
  return true;
460
471
  }
@@ -486,5 +497,6 @@ module.exports = __toCommonJS(src_exports);
486
497
  Description,
487
498
  Form,
488
499
  FormItem,
489
- Table
500
+ Table,
501
+ transferOptions
490
502
  });
package/dist/index.mjs CHANGED
@@ -32,10 +32,21 @@ function Blank(options) {
32
32
  }, (options == null ? void 0 : options.text) || text) : options.value;
33
33
  }
34
34
 
35
+ // src/data.ts
36
+ import { upperFirst } from "lodash";
37
+ function transferOptions(options) {
38
+ if (!options)
39
+ return [];
40
+ return options.map((item) => typeof item === "object" ? item : {
41
+ label: upperFirst(item.toString()),
42
+ value: item
43
+ });
44
+ }
45
+
35
46
  // src/Description.tsx
36
47
  import { CheckOutlined, CloseOutlined } from "@ant-design/icons";
37
48
  import { Descriptions } from "antd";
38
- import { upperFirst } from "lodash";
49
+ import { upperFirst as upperFirst2 } from "lodash";
39
50
  import {
40
51
  cloneElement,
41
52
  useEffect as useEffect2,
@@ -68,20 +79,23 @@ function FaasDataWrapper({
68
79
  function DescriptionItemContent(props) {
69
80
  const [computedProps, setComputedProps] = useState2();
70
81
  useEffect2(() => {
71
- var _a2;
82
+ var _a2, _b;
72
83
  const propsCopy = __spreadValues({}, props);
73
84
  if (!propsCopy.item.title)
74
- propsCopy.item.title = upperFirst(propsCopy.item.id);
85
+ propsCopy.item.title = upperFirst2(propsCopy.item.id);
75
86
  if (!propsCopy.item.type)
76
87
  propsCopy.item.type = "string";
77
- if (props.item.options && typeof props.value !== "undefined" && props.value !== null) {
78
- if (props.item.type.endsWith("[]"))
79
- propsCopy.value = props.value.map((v) => {
88
+ if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
89
+ propsCopy.item.options = transferOptions(propsCopy.item.options);
90
+ }
91
+ if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
92
+ if (propsCopy.item.type.endsWith("[]"))
93
+ propsCopy.value = propsCopy.value.map((v) => {
80
94
  var _a3;
81
- return ((_a3 = props.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
95
+ return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
82
96
  });
83
97
  else
84
- propsCopy.value = ((_a2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _a2.label) || props.value;
98
+ propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
85
99
  }
86
100
  setComputedProps(propsCopy);
87
101
  }, [props]);
@@ -132,7 +146,7 @@ function Description(props) {
132
146
  faasData: props.faasData,
133
147
  render: ({ data }) => /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
134
148
  key: item.id,
135
- label: item.title || upperFirst(item.id)
149
+ label: item.title || upperFirst2(item.id)
136
150
  }, /* @__PURE__ */ React.createElement(DescriptionItemContent, {
137
151
  item,
138
152
  value: data[item.id],
@@ -164,13 +178,13 @@ import {
164
178
  useEffect as useEffect3,
165
179
  useState as useState3
166
180
  } from "react";
167
- import { upperFirst as upperFirst2 } from "lodash";
181
+ import { upperFirst as upperFirst3 } from "lodash";
168
182
  function FormItem(props) {
169
183
  const [computedProps, setComputedProps] = useState3();
170
184
  useEffect3(() => {
171
185
  const propsCopy = __spreadValues({}, props);
172
186
  if (!propsCopy.title)
173
- propsCopy.title = upperFirst2(propsCopy.id);
187
+ propsCopy.title = upperFirst3(propsCopy.id);
174
188
  if (!propsCopy.label && props.label !== false)
175
189
  propsCopy.label = propsCopy.title;
176
190
  if (!propsCopy.name)
@@ -196,20 +210,8 @@ function FormItem(props) {
196
210
  }
197
211
  if (!propsCopy.input)
198
212
  propsCopy.input = {};
199
- if (propsCopy.options) {
200
- const options = [];
201
- if (propsCopy.options.length > 0)
202
- for (const option of propsCopy.options) {
203
- if (typeof option === "object")
204
- options.push(option);
205
- else
206
- options.push({
207
- label: upperFirst2(option.toString()),
208
- value: option
209
- });
210
- }
211
- propsCopy.input.options = options;
212
- }
213
+ if (propsCopy.options)
214
+ propsCopy.input.options = transferOptions(propsCopy.options);
213
215
  switch (propsCopy.type) {
214
216
  case "boolean":
215
217
  propsCopy.valuePropName = "checked";
@@ -340,7 +342,7 @@ import {
340
342
  Radio
341
343
  } from "antd";
342
344
  import { CheckOutlined as CheckOutlined2, CloseOutlined as CloseOutlined2 } from "@ant-design/icons";
343
- import { isNil as isNil2, upperFirst as upperFirst3 } from "lodash";
345
+ import { isNil as isNil2, upperFirst as upperFirst4 } from "lodash";
344
346
  function processValue(item, value) {
345
347
  var _a2;
346
348
  if (item.options && typeof value !== "undefined" && value !== null) {
@@ -357,15 +359,23 @@ function processValue(item, value) {
357
359
  function Table(props) {
358
360
  const [columns, setColumns] = useState4();
359
361
  useEffect4(() => {
362
+ var _a2;
360
363
  for (const item of props.items) {
361
364
  if (!item.key)
362
365
  item.key = item.id;
363
366
  if (!item.dataIndex)
364
367
  item.dataIndex = item.id;
365
368
  if (!item.title)
366
- item.title = upperFirst3(item.id);
369
+ item.title = upperFirst4(item.id);
367
370
  if (!item.type)
368
371
  item.type = "string";
372
+ if ((_a2 = item.options) == null ? void 0 : _a2.length) {
373
+ item.options = transferOptions(item.options);
374
+ item.filters = item.options.map((o) => ({
375
+ text: o.label,
376
+ value: o.value
377
+ }));
378
+ }
369
379
  if (item.render)
370
380
  continue;
371
381
  if (props.extendTypes && props.extendTypes[item.type]) {
@@ -410,7 +420,7 @@ function Table(props) {
410
420
  selectedKeys,
411
421
  confirm
412
422
  }) => {
413
- var _a2, _b;
423
+ var _a3, _b;
414
424
  return /* @__PURE__ */ React.createElement(Radio.Group, {
415
425
  style: { padding: 8 },
416
426
  buttonStyle: "solid",
@@ -419,7 +429,7 @@ function Table(props) {
419
429
  setSelectedKeys(e.target.value ? [e.target.value] : []);
420
430
  confirm();
421
431
  }
422
- }, /* @__PURE__ */ React.createElement(Radio.Button, null, ((_a2 = navigator.language) == null ? void 0 : _a2.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ React.createElement(Radio.Button, {
432
+ }, /* @__PURE__ */ React.createElement(Radio.Button, null, ((_a3 = navigator.language) == null ? void 0 : _a3.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ React.createElement(Radio.Button, {
423
433
  value: "true"
424
434
  }, /* @__PURE__ */ React.createElement(CheckOutlined2, {
425
435
  style: {
@@ -475,5 +485,6 @@ export {
475
485
  Description,
476
486
  Form,
477
487
  FormItem,
478
- Table
488
+ Table,
489
+ transferOptions
479
490
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.345",
3
+ "version": "0.0.2-beta.346",
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.345"
30
+ "@faasjs/react": "^0.0.2-beta.346"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/lodash": "*",