@faasjs/ant-design 0.0.2-beta.442 → 0.0.2-beta.444

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
@@ -145,6 +145,7 @@ declare type ExtendDescriptionItemProps = BaseItemProps;
145
145
  declare type DescriptionItemProps<T = any> = {
146
146
  children?: JSX.Element;
147
147
  render?: (value: T, values: any) => ReactNode | JSX.Element;
148
+ if?: (values: Record<string, any>) => boolean;
148
149
  } & FaasItemProps & {
149
150
  object?: DescriptionItemProps[];
150
151
  };
@@ -252,6 +253,8 @@ declare type FormItemProps<T = any> = {
252
253
  extendTypes?: ExtendTypes;
253
254
  /** trigger when current item's value changed */
254
255
  onValueChange?: (value: T, values: any, form: FormInstance) => void;
256
+ /** trigger when any item's value changed */
257
+ if?: (values: Record<string, any>) => boolean;
255
258
  } & FormItemInputProps & FaasItemProps & Omit<FormItemProps$1<T>, 'children'>;
256
259
  /**
257
260
  * FormItem, can be used without Form.
@@ -268,7 +271,7 @@ declare type FormItemProps<T = any> = {
268
271
  */
269
272
  declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
270
273
 
271
- declare type FormProps<Values = any, ExtendItemProps = any> = {
274
+ declare type FormProps<Values extends Record<string, any> = any, ExtendItemProps = any> = {
272
275
  items?: (FormItemProps | ExtendItemProps)[];
273
276
  /** Default: { text: 'Submit' }, set false to disable it */
274
277
  submit?: false | {
@@ -398,6 +401,7 @@ declare type TableItemProps<T = any> = {
398
401
  optionsType?: 'auto';
399
402
  /** @deprecated use render */
400
403
  children?: JSX.Element | null;
404
+ object?: TableItemProps[];
401
405
  } & FaasItemProps & Omit<TableColumnProps<T>, 'children'>;
402
406
  declare type ExtendTableTypeProps = {
403
407
  children?: JSX.Element | null;
package/dist/index.js CHANGED
@@ -294,15 +294,17 @@ function Description(props) {
294
294
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Descriptions, {
295
295
  ...props,
296
296
  title: (0, import_lodash4.isFunction)(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
297
- children: props.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Descriptions.Item, {
298
- label: item.title || (0, import_lodash4.upperFirst)(item.id),
299
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DescriptionItemContent, {
300
- item,
301
- value: props.dataSource[item.id],
302
- values: props.dataSource,
303
- extendTypes: props.extendTypes
304
- })
305
- }, item.id))
297
+ children: props.items.map((item) => {
298
+ return !item.if || item.if(props.dataSource) ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Descriptions.Item, {
299
+ label: item.title || (0, import_lodash4.upperFirst)(item.id),
300
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DescriptionItemContent, {
301
+ item,
302
+ value: props.dataSource[item.id],
303
+ values: props.dataSource,
304
+ extendTypes: props.extendTypes
305
+ })
306
+ }, item.id) : null;
307
+ }).filter(Boolean)
306
308
  });
307
309
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.FaasDataWrapper, {
308
310
  fallback: props.faasData.fallback || /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Skeleton, {
@@ -312,15 +314,17 @@ function Description(props) {
312
314
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Descriptions, {
313
315
  ...props,
314
316
  title: (0, import_lodash4.isFunction)(props.renderTitle) ? props.renderTitle(data) : props.title,
315
- children: props.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Descriptions.Item, {
316
- label: item.title || (0, import_lodash4.upperFirst)(item.id),
317
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DescriptionItemContent, {
318
- item,
319
- value: data[item.id],
320
- values: data,
321
- extendTypes: props.extendTypes
322
- })
323
- }, item.id))
317
+ children: props.items.map((item) => {
318
+ return !item.if || item.if(data) ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd3.Descriptions.Item, {
319
+ label: item.title || (0, import_lodash4.upperFirst)(item.id),
320
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DescriptionItemContent, {
321
+ item,
322
+ value: data[item.id],
323
+ values: data,
324
+ extendTypes: props.extendTypes
325
+ })
326
+ }, item.id) : null;
327
+ }).filter(Boolean)
324
328
  });
325
329
  },
326
330
  ...props.faasData
@@ -752,12 +756,15 @@ function Form(props) {
752
756
  var _a2, _b2;
753
757
  const propsCopy = {
754
758
  ...props,
759
+ items: (props.items || []).filter((it) => {
760
+ return !it.if || it.if(props.initialValues || {});
761
+ }),
755
762
  form
756
763
  };
757
764
  if (propsCopy.initialValues)
758
765
  for (const key in propsCopy.initialValues)
759
766
  propsCopy.initialValues[key] = transferValue(
760
- (_a2 = propsCopy.items.find((i) => i.id === key)) == null ? void 0 : _a2.type,
767
+ (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
761
768
  propsCopy.initialValues[key]
762
769
  );
763
770
  if (propsCopy.onFinish) {
@@ -796,16 +803,37 @@ function Form(props) {
796
803
  propsCopy.onValuesChange = (changedValues, allValues) => {
797
804
  if (originValuesChange)
798
805
  originValuesChange(changedValues, allValues);
799
- if (!propsCopy.items)
806
+ if (!props.items)
800
807
  return;
801
808
  for (const key in changedValues) {
802
809
  const item = propsCopy.items.find((i) => i.id === key);
803
810
  if (item == null ? void 0 : item.onValueChange)
804
811
  item.onValueChange(changedValues[key], allValues, form);
805
812
  }
813
+ const filterItems = props.items.filter((it) => {
814
+ if (!it.if) {
815
+ return true;
816
+ }
817
+ const show = it.if(allValues);
818
+ if (show) {
819
+ propsCopy.form.setFields([
820
+ {
821
+ name: it.id,
822
+ errors: null
823
+ }
824
+ ]);
825
+ }
826
+ return show;
827
+ });
828
+ if (propsCopy.items.length !== filterItems.length || propsCopy.items.some((it, i) => it !== filterItems[i])) {
829
+ setComputedProps({
830
+ ...propsCopy,
831
+ items: filterItems
832
+ });
833
+ }
806
834
  };
807
835
  setComputedProps(propsCopy);
808
- }, []);
836
+ }, [props]);
809
837
  if (!computedProps)
810
838
  return null;
811
839
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_antd6.Form, {
@@ -1214,6 +1242,20 @@ function Table(props) {
1214
1242
  if (!item.sorter)
1215
1243
  item.sorter = (a, b) => (0, import_dayjs5.default)(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1216
1244
  break;
1245
+ case "object":
1246
+ if (!item.render)
1247
+ item.render = (value) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Description, {
1248
+ items: item.object,
1249
+ dataSource: value
1250
+ });
1251
+ break;
1252
+ case "object[]":
1253
+ if (!item.render)
1254
+ item.render = (value) => value.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Description, {
1255
+ items: item.object,
1256
+ dataSource: v
1257
+ }, i));
1258
+ break;
1217
1259
  default:
1218
1260
  if (!item.render)
1219
1261
  item.render = (value) => processValue(item, value);
package/dist/index.mjs CHANGED
@@ -255,15 +255,17 @@ function Description(props) {
255
255
  return /* @__PURE__ */ jsx3(Descriptions, {
256
256
  ...props,
257
257
  title: isFunction(props.renderTitle) ? props.renderTitle(props.dataSource) : props.title,
258
- children: props.items.map((item) => /* @__PURE__ */ jsx3(Descriptions.Item, {
259
- label: item.title || upperFirst2(item.id),
260
- children: /* @__PURE__ */ jsx3(DescriptionItemContent, {
261
- item,
262
- value: props.dataSource[item.id],
263
- values: props.dataSource,
264
- extendTypes: props.extendTypes
265
- })
266
- }, item.id))
258
+ children: props.items.map((item) => {
259
+ return !item.if || item.if(props.dataSource) ? /* @__PURE__ */ jsx3(Descriptions.Item, {
260
+ label: item.title || upperFirst2(item.id),
261
+ children: /* @__PURE__ */ jsx3(DescriptionItemContent, {
262
+ item,
263
+ value: props.dataSource[item.id],
264
+ values: props.dataSource,
265
+ extendTypes: props.extendTypes
266
+ })
267
+ }, item.id) : null;
268
+ }).filter(Boolean)
267
269
  });
268
270
  return /* @__PURE__ */ jsx3(FaasDataWrapper, {
269
271
  fallback: props.faasData.fallback || /* @__PURE__ */ jsx3(Skeleton, {
@@ -273,15 +275,17 @@ function Description(props) {
273
275
  return /* @__PURE__ */ jsx3(Descriptions, {
274
276
  ...props,
275
277
  title: isFunction(props.renderTitle) ? props.renderTitle(data) : props.title,
276
- children: props.items.map((item) => /* @__PURE__ */ jsx3(Descriptions.Item, {
277
- label: item.title || upperFirst2(item.id),
278
- children: /* @__PURE__ */ jsx3(DescriptionItemContent, {
279
- item,
280
- value: data[item.id],
281
- values: data,
282
- extendTypes: props.extendTypes
283
- })
284
- }, item.id))
278
+ children: props.items.map((item) => {
279
+ return !item.if || item.if(data) ? /* @__PURE__ */ jsx3(Descriptions.Item, {
280
+ label: item.title || upperFirst2(item.id),
281
+ children: /* @__PURE__ */ jsx3(DescriptionItemContent, {
282
+ item,
283
+ value: data[item.id],
284
+ values: data,
285
+ extendTypes: props.extendTypes
286
+ })
287
+ }, item.id) : null;
288
+ }).filter(Boolean)
285
289
  });
286
290
  },
287
291
  ...props.faasData
@@ -731,12 +735,15 @@ function Form(props) {
731
735
  var _a2, _b2;
732
736
  const propsCopy = {
733
737
  ...props,
738
+ items: (props.items || []).filter((it) => {
739
+ return !it.if || it.if(props.initialValues || {});
740
+ }),
734
741
  form
735
742
  };
736
743
  if (propsCopy.initialValues)
737
744
  for (const key in propsCopy.initialValues)
738
745
  propsCopy.initialValues[key] = transferValue(
739
- (_a2 = propsCopy.items.find((i) => i.id === key)) == null ? void 0 : _a2.type,
746
+ (_a2 = propsCopy.items.find((item) => item.id === key)) == null ? void 0 : _a2.type,
740
747
  propsCopy.initialValues[key]
741
748
  );
742
749
  if (propsCopy.onFinish) {
@@ -775,16 +782,37 @@ function Form(props) {
775
782
  propsCopy.onValuesChange = (changedValues, allValues) => {
776
783
  if (originValuesChange)
777
784
  originValuesChange(changedValues, allValues);
778
- if (!propsCopy.items)
785
+ if (!props.items)
779
786
  return;
780
787
  for (const key in changedValues) {
781
788
  const item = propsCopy.items.find((i) => i.id === key);
782
789
  if (item == null ? void 0 : item.onValueChange)
783
790
  item.onValueChange(changedValues[key], allValues, form);
784
791
  }
792
+ const filterItems = props.items.filter((it) => {
793
+ if (!it.if) {
794
+ return true;
795
+ }
796
+ const show = it.if(allValues);
797
+ if (show) {
798
+ propsCopy.form.setFields([
799
+ {
800
+ name: it.id,
801
+ errors: null
802
+ }
803
+ ]);
804
+ }
805
+ return show;
806
+ });
807
+ if (propsCopy.items.length !== filterItems.length || propsCopy.items.some((it, i) => it !== filterItems[i])) {
808
+ setComputedProps({
809
+ ...propsCopy,
810
+ items: filterItems
811
+ });
812
+ }
785
813
  };
786
814
  setComputedProps(propsCopy);
787
- }, []);
815
+ }, [props]);
788
816
  if (!computedProps)
789
817
  return null;
790
818
  return /* @__PURE__ */ jsxs2(AntdForm2, {
@@ -1211,6 +1239,20 @@ function Table(props) {
1211
1239
  if (!item.sorter)
1212
1240
  item.sorter = (a, b) => dayjs3(a[item.id]).isBefore(b[item.id]) ? -1 : 1;
1213
1241
  break;
1242
+ case "object":
1243
+ if (!item.render)
1244
+ item.render = (value) => /* @__PURE__ */ jsx11(Description, {
1245
+ items: item.object,
1246
+ dataSource: value
1247
+ });
1248
+ break;
1249
+ case "object[]":
1250
+ if (!item.render)
1251
+ item.render = (value) => value.map((v, i) => /* @__PURE__ */ jsx11(Description, {
1252
+ items: item.object,
1253
+ dataSource: v
1254
+ }, i));
1255
+ break;
1214
1256
  default:
1215
1257
  if (!item.render)
1216
1258
  item.render = (value) => processValue(item, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.442",
3
+ "version": "0.0.2-beta.444",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,7 +28,7 @@
28
28
  "lodash": "*",
29
29
  "react": "*",
30
30
  "react-dom": "*",
31
- "@faasjs/react": "^0.0.2-beta.442",
31
+ "@faasjs/react": "^0.0.2-beta.444",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },