@faasjs/ant-design 0.0.2-beta.443 → 0.0.2-beta.445

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.
@@ -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
@@ -750,10 +754,11 @@ function Form(props) {
750
754
  const [form] = import_antd6.Form.useForm(props.form);
751
755
  (0, import_react9.useEffect)(() => {
752
756
  var _a2, _b2;
753
- if (!props.items)
754
- return;
755
757
  const propsCopy = {
756
758
  ...props,
759
+ items: (props.items || []).filter((it) => {
760
+ return !it.if || it.if(props.initialValues || {});
761
+ }),
757
762
  form
758
763
  };
759
764
  if (propsCopy.initialValues)
@@ -798,11 +803,34 @@ function Form(props) {
798
803
  propsCopy.onValuesChange = (changedValues, allValues) => {
799
804
  if (originValuesChange)
800
805
  originValuesChange(changedValues, allValues);
806
+ if (!props.items)
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]);
@@ -1214,6 +1242,22 @@ 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
+ column: 1
1251
+ });
1252
+ break;
1253
+ case "object[]":
1254
+ if (!item.render)
1255
+ item.render = (value) => value.map((v, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Description, {
1256
+ items: item.object,
1257
+ dataSource: v,
1258
+ column: 1
1259
+ }, i));
1260
+ break;
1217
1261
  default:
1218
1262
  if (!item.render)
1219
1263
  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
@@ -729,10 +733,11 @@ function Form(props) {
729
733
  const [form] = AntdForm2.useForm(props.form);
730
734
  useEffect4(() => {
731
735
  var _a2, _b2;
732
- if (!props.items)
733
- return;
734
736
  const propsCopy = {
735
737
  ...props,
738
+ items: (props.items || []).filter((it) => {
739
+ return !it.if || it.if(props.initialValues || {});
740
+ }),
736
741
  form
737
742
  };
738
743
  if (propsCopy.initialValues)
@@ -777,11 +782,34 @@ function Form(props) {
777
782
  propsCopy.onValuesChange = (changedValues, allValues) => {
778
783
  if (originValuesChange)
779
784
  originValuesChange(changedValues, allValues);
785
+ if (!props.items)
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]);
@@ -1211,6 +1239,22 @@ 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
+ column: 1
1248
+ });
1249
+ break;
1250
+ case "object[]":
1251
+ if (!item.render)
1252
+ item.render = (value) => value.map((v, i) => /* @__PURE__ */ jsx11(Description, {
1253
+ items: item.object,
1254
+ dataSource: v,
1255
+ column: 1
1256
+ }, i));
1257
+ break;
1214
1258
  default:
1215
1259
  if (!item.render)
1216
1260
  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.443",
3
+ "version": "0.0.2-beta.445",
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.443",
31
+ "@faasjs/react": "^0.0.2-beta.445",
32
32
  "react-router-dom": "*",
33
33
  "dayjs": "*"
34
34
  },