@faasjs/ant-design 6.3.2 → 6.4.1

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/README.md CHANGED
@@ -5,6 +5,11 @@ UI components based on [FaasJS](https://faasjs.com), [Ant Design](https://ant.de
5
5
  [![License: MIT](https://img.shields.io/npm/l/@faasjs/ant-design.svg)](https://github.com/faasjs/faasjs/blob/main/packages/ant-design/LICENSE)
6
6
  [![NPM Version](https://img.shields.io/npm/v/@faasjs/ant-design.svg)](https://www.npmjs.com/package/@faasjs/ant-design)
7
7
 
8
+ ## Features
9
+
10
+ - [App](https://faasjs.com/doc/ant-design/functions/App.html) component with Ant Design & FaasJS.
11
+ - [UnionFaasItemElement](https://faasjs.com/doc/ant-design/type-aliases/UnionFaasItemElement.html) and [UnionFaasItemRender](https://faasjs.com/doc/ant-design/type-aliases/UnionFaasItemRender.html) for custom union rendering.
12
+
8
13
  ## Install
9
14
 
10
15
  ```sh
@@ -34,6 +39,7 @@ type FaasItemProps = {
34
39
 
35
40
  - [App](functions/App.md)
36
41
  - [Blank](functions/Blank.md)
42
+ - [cloneUnionFaasItemElement](functions/cloneUnionFaasItemElement.md)
37
43
  - [ConfigContext](functions/ConfigContext.md)
38
44
  - [ConfigProvider](functions/ConfigProvider.md)
39
45
  - [Description](functions/Description.md)
package/dist/index.cjs CHANGED
@@ -281,6 +281,12 @@ function transferValue(type, value) {
281
281
  }
282
282
  return value;
283
283
  }
284
+ function cloneUnionFaasItemElement(element, props) {
285
+ return react$1.cloneElement(
286
+ react$1.isValidElement(element) ? element : react$1.createElement(element),
287
+ props
288
+ );
289
+ }
284
290
  function Loading(props) {
285
291
  if (props.loading === false) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
286
292
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -336,9 +342,22 @@ function DescriptionItemContent(props) {
336
342
  setComputedProps(propsCopy);
337
343
  }, [props]);
338
344
  if (!computedProps) return null;
345
+ if (computedProps.item.descriptionChildren === null || computedProps.item.children === null)
346
+ return null;
347
+ const children = computedProps.item.descriptionChildren || computedProps.item.children;
348
+ if (children)
349
+ return cloneUnionFaasItemElement(children, {
350
+ scene: "description",
351
+ value: computedProps.value,
352
+ values: computedProps.values,
353
+ index: 0
354
+ });
355
+ const render = computedProps.item.descriptionRender || computedProps.item.render;
356
+ if (render)
357
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(computedProps.value, computedProps.values, 0, "description") });
339
358
  if (computedProps.extendTypes?.[computedProps.item.type]) {
340
359
  if (computedProps.extendTypes[computedProps.item.type].children)
341
- return react$1.cloneElement(
360
+ return cloneUnionFaasItemElement(
342
361
  computedProps.extendTypes[computedProps.item.type].children,
343
362
  {
344
363
  scene: "description",
@@ -355,34 +374,6 @@ function DescriptionItemContent(props) {
355
374
  ) });
356
375
  throw Error(`${computedProps.item.type} requires children or render`);
357
376
  }
358
- if (computedProps.item.descriptionChildren === null) return null;
359
- if (computedProps.item.descriptionChildren)
360
- return react$1.cloneElement(computedProps.item.descriptionChildren, {
361
- scene: "description",
362
- value: computedProps.value,
363
- values: computedProps.values
364
- });
365
- if (computedProps.item.children === null) return null;
366
- if (computedProps.item.children)
367
- return react$1.cloneElement(computedProps.item.children, {
368
- scene: "description",
369
- value: computedProps.value,
370
- values: computedProps.values
371
- });
372
- if (computedProps.item.descriptionRender)
373
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.item.descriptionRender(
374
- computedProps.value,
375
- computedProps.values,
376
- 0,
377
- "description"
378
- ) });
379
- if (computedProps.item.render)
380
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: computedProps.item.render(
381
- computedProps.value,
382
- computedProps.values,
383
- 0,
384
- "description"
385
- ) });
386
377
  if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length)
387
378
  return /* @__PURE__ */ jsxRuntime.jsx(Blank, {});
388
379
  switch (computedProps.item.type) {
@@ -563,18 +554,18 @@ function FormItem(props) {
563
554
  if (!computedProps) return null;
564
555
  if (hidden)
565
556
  return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, noStyle: true, rules: [], children: /* @__PURE__ */ jsxRuntime.jsx(antd.Input, { type: "hidden", hidden: true }) });
557
+ if (computedProps.formChildren === null || computedProps.children === null)
558
+ return null;
559
+ const children = computedProps.formChildren || computedProps.children;
560
+ if (children)
561
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: cloneUnionFaasItemElement(children, { scene: "form" }) });
562
+ const render = computedProps.formRender || computedProps.render;
563
+ if (render)
564
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: render(null, null, 0, "form") });
566
565
  if (extendTypes?.[computedProps.type])
567
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: extendTypes[computedProps.type].children });
568
- if (computedProps.formChildren === null) return null;
569
- if (computedProps.formChildren)
570
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: react$1.cloneElement(computedProps.formChildren, { scene: "form" }) });
571
- if (computedProps.children === null) return null;
572
- if (computedProps.children)
573
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: react$1.cloneElement(computedProps.children, { scene: "form" }) });
574
- if (computedProps.formRender)
575
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.formRender(null, null, 0, "form") });
576
- if (computedProps.render)
577
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: computedProps.render(null, null, 0, "form") });
566
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Form.Item, { ...computedProps, children: cloneUnionFaasItemElement(extendTypes[computedProps.type].children, {
567
+ scene: "form"
568
+ }) });
578
569
  switch (computedProps.type) {
579
570
  case "string":
580
571
  if (isOptionsProps(computedProps))
@@ -1051,29 +1042,39 @@ function Table(props) {
1051
1042
  });
1052
1043
  generateFilterDropdown(item);
1053
1044
  }
1054
- if (item.tableChildren === null) item.render = () => null;
1055
- else if (item.tableChildren)
1056
- item.render = (value, values) => react$1.cloneElement(item.tableChildren, {
1057
- scene: "table",
1058
- value,
1059
- values
1060
- });
1061
- else if (item.children === null) item.render = () => null;
1062
- else if (item.children)
1063
- item.render = (value, values) => react$1.cloneElement(item.children, {
1045
+ const isNull = item.tableChildren === null || item.children === null;
1046
+ if (isNull) {
1047
+ item.render = () => null;
1048
+ continue;
1049
+ }
1050
+ const children = item.tableChildren || item.children;
1051
+ if (children) {
1052
+ item.render = (value, values) => cloneUnionFaasItemElement(children, {
1064
1053
  scene: "table",
1065
1054
  value,
1066
- values
1055
+ values,
1056
+ index: 0
1067
1057
  });
1058
+ delete item.children;
1059
+ delete item.tableChildren;
1060
+ continue;
1061
+ }
1062
+ const render = item.tableRender || item.render;
1063
+ if (render) {
1064
+ item.render = (value, values) => render(value, values, 0, "table");
1065
+ delete item.tableRender;
1066
+ continue;
1067
+ }
1068
1068
  if (props.extendTypes?.[item.type]) {
1069
- if (props.extendTypes[item.type].children)
1070
- item.render = (value, values) => react$1.cloneElement(props.extendTypes[item.type].children, {
1069
+ if (props.extendTypes[item.type].children) {
1070
+ item.render = (value, values) => cloneUnionFaasItemElement(props.extendTypes[item.type].children, {
1071
1071
  scene: "table",
1072
1072
  value,
1073
- values
1073
+ values,
1074
+ index: 0
1074
1075
  });
1075
- else if (props.extendTypes[item.type].render)
1076
- item.render = props.extendTypes[item.type].render;
1076
+ } else if (props.extendTypes[item.type].render)
1077
+ item.render = (value, values) => props.extendTypes[item.type].render(value, values, 0, "table");
1077
1078
  else throw Error(`${item.type} requires children or render`);
1078
1079
  continue;
1079
1080
  }
@@ -1501,15 +1502,15 @@ function FaasDataTable({
1501
1502
  rowKey: props.rowKey || "id",
1502
1503
  columns: currentColumns,
1503
1504
  dataSource: data.rows,
1504
- pagination: {
1505
- ...props.pagination,
1506
- ...data.pagination
1505
+ pagination: props.pagination === false ? false : {
1506
+ ...props.pagination || /* @__PURE__ */ Object.create(null),
1507
+ ...data.pagination || /* @__PURE__ */ Object.create(null)
1507
1508
  },
1508
1509
  onChange: (pagination, filters, sorter, extra) => {
1509
1510
  if (props.onChange) {
1510
1511
  const processed = props.onChange(pagination, filters, sorter, extra);
1511
1512
  reload({
1512
- ...params,
1513
+ ...params || /* @__PURE__ */ Object.create(null),
1513
1514
  pagination: processed.pagination,
1514
1515
  filters: processed.filters,
1515
1516
  sorter: processed.sorter,
@@ -1518,7 +1519,7 @@ function FaasDataTable({
1518
1519
  return;
1519
1520
  }
1520
1521
  reload({
1521
- ...params,
1522
+ ...params || /* @__PURE__ */ Object.create(null),
1522
1523
  pagination,
1523
1524
  filters,
1524
1525
  sorter
@@ -1591,6 +1592,7 @@ exports.Routes = Routes;
1591
1592
  exports.Table = Table;
1592
1593
  exports.Tabs = Tabs;
1593
1594
  exports.Title = Title;
1595
+ exports.cloneUnionFaasItemElement = cloneUnionFaasItemElement;
1594
1596
  exports.transferOptions = transferOptions;
1595
1597
  exports.transferValue = transferValue;
1596
1598
  exports.upperFirst = upperFirst;
package/dist/index.d.ts CHANGED
@@ -7,13 +7,13 @@ import { MessageInstance } from 'antd/es/message/interface';
7
7
  import { NotificationInstance } from 'antd/es/notification/interface';
8
8
  import { BrowserRouterProps, RouteProps } from 'react-router-dom';
9
9
  import * as react from 'react';
10
- import { CSSProperties, JSX, Dispatch, SetStateAction, ReactNode, ReactElement, LazyExoticComponent, ComponentType } from 'react';
10
+ import { CSSProperties, JSX, Dispatch, SetStateAction, ReactNode, ReactElement, FC, LazyExoticComponent, ComponentType } from 'react';
11
11
  export { lazy } from 'react';
12
12
  import * as antd_es_modal_PurePanel from 'antd/es/modal/PurePanel';
13
13
  import * as antd_es_modal_useModal from 'antd/es/modal/useModal';
14
14
  import * as antd_es_modal_confirm from 'antd/es/modal/confirm';
15
15
  import { Dayjs } from 'dayjs';
16
- import { FaasAction } from '@faasjs/types';
16
+ import { FaasActionUnionType, FaasAction } from '@faasjs/types';
17
17
  import * as antd_es_form_FormItem from 'antd/es/form/FormItem';
18
18
  import { RuleObject } from 'rc-field-form/lib/interface';
19
19
  import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface';
@@ -294,7 +294,7 @@ declare namespace FaasDataWrapper {
294
294
  * const MyComponent = withFaasData(({ data }) => <div>{data.name}</div>, { action: 'test', params: { a: 1 } })
295
295
  * ```
296
296
  */
297
- declare function withFaasData<PathOrData extends FaasAction, TComponentProps extends Required<FaasDataInjection<PathOrData>> = Required<FaasDataInjection<PathOrData>>>(Component: React.FC<TComponentProps & Record<string, any>>, faasProps: FaasDataWrapperProps<PathOrData>): React.FC<Omit<TComponentProps, keyof FaasDataInjection<PathOrData>> & Record<string, any>>;
297
+ declare function withFaasData<PathOrData extends FaasActionUnionType, TComponentProps extends Required<FaasDataInjection<PathOrData>> = Required<FaasDataInjection<PathOrData>>>(Component: React.FC<TComponentProps & Record<string, any>>, faasProps: FaasDataWrapperProps<PathOrData>): React.FC<Omit<TComponentProps, keyof FaasDataInjection<PathOrData>>>;
298
298
 
299
299
  interface ExtendDescriptionTypeProps<T = any> {
300
300
  children?: UnionFaasItemElement<T>;
@@ -463,7 +463,7 @@ interface TableItemProps<T = any> extends FaasItemProps, Omit<TableColumnProps<T
463
463
  object?: TableItemProps<T>[];
464
464
  }
465
465
  type ExtendTableTypeProps<T = any> = {
466
- children?: JSX.Element;
466
+ children?: UnionFaasItemElement<T>;
467
467
  render?: UnionFaasItemRender<T>;
468
468
  };
469
469
  type ExtendTableItemProps<T = any> = BaseItemProps & Omit<TableColumnProps<T>, 'children'>;
@@ -538,13 +538,170 @@ type UnionFaasItemInjection<Value = any, Values = any> = {
538
538
  values?: Values;
539
539
  index?: number;
540
540
  };
541
+ /**
542
+ * A type representing a function that renders a React node for a given item in a list.
543
+ *
544
+ * @param value - The value of the current item.
545
+ * @param values - The entire list of values.
546
+ * @param index - The index of the current item in the list.
547
+ * @param scene {@link UnionScene} - The scene in which the rendering is taking place.
548
+ *
549
+ * @example
550
+ * ```tsx
551
+ * import { type UnionFaasItemRender, Form, Description, Table } from '@faasjs/ant-design'
552
+ *
553
+ * const nameReader: UnionFaasItemRender = (value, values, index, scene) => {
554
+ * switch (scene) {
555
+ * case 'form':
556
+ * return <input />
557
+ * case 'description':
558
+ * case 'table':
559
+ * return <span>{value}</span>
560
+ * default:
561
+ * return null
562
+ * }
563
+ * }
564
+ *
565
+ * const items = [
566
+ * {
567
+ * id: 'name',
568
+ * render: nameReader,
569
+ * }
570
+ * ]
571
+ *
572
+ * function App() {
573
+ * return <>
574
+ * <Form items={items} /> // Will render an input
575
+ * <Description items={items} dataSource={{ name: 'John' }} /> // Will render a span
576
+ * <Table items={items} dataSource={[{ name: 'John' }]} /> // Will render a span
577
+ * </>
578
+ * }
579
+ * ```
580
+ */
541
581
  type UnionFaasItemRender<Value = any, Values = any> = (value: Value, values: Values, index: number, scene: UnionScene) => React.ReactNode;
542
- type UnionFaasItemElement<Value = any, Values = any> = ReactElement<UnionFaasItemInjection<Value, Values>> | null;
582
+ /**
583
+ * Represents a React element that is used in the UnionFaasItem context.
584
+ *
585
+ * @template Value - The type of the value associated with the element. Defaults to `any`.
586
+ * @template Values - The type of the values associated with the element. Defaults to `any`.
587
+ *
588
+ * This type can either be a React element with the specified injection types or `null`.
589
+ *
590
+ * @example
591
+ * ```tsx
592
+ * import { type UnionFaasItemElement, Form, Description, Table } from '@faasjs/ant-design'
593
+ *
594
+ * const NameComponent: UnionFaasItemElement = ({ scene, value }) => {
595
+ * switch (scene) {
596
+ * switch (scene) {
597
+ * case 'form':
598
+ * return <input />
599
+ * case 'description':
600
+ * case 'table':
601
+ * return <span>{value}</span>
602
+ * default:
603
+ * return null
604
+ * }
605
+ * }
606
+ *
607
+ * const items = [
608
+ * {
609
+ * id: 'name',
610
+ * children: NameComponent // both `NameComponent` and `<NameComponent />` is valid
611
+ * }
612
+ * ]
613
+ *
614
+ * function App() {
615
+ * return <>
616
+ * <Form items={items} /> // Will render an input
617
+ * <Description items={items} dataSource={{ name: 'John' }} /> // Will render a span
618
+ * <Table items={items} dataSource={[{ name: 'John' }]} /> // Will render a span
619
+ * </>
620
+ * }
621
+ * ```
622
+ */
623
+ type UnionFaasItemElement<Value = any, Values = any> = ReactElement<UnionFaasItemInjection<Value, Values>> | FC<UnionFaasItemInjection<Value, Values>>;
624
+ /**
625
+ * Interface representing the properties of a UnionFaas item.
626
+ *
627
+ * The UnionFaas item can be used in a form, description, or table.
628
+ *
629
+ * ### Render Priority Order
630
+ *
631
+ * 1. **Null Rendering**
632
+ * 1. Returns `null` if specific children props are null:
633
+ * - `formChildren` / `descriptionChildren` / `tableChildren`
634
+ * 2. Returns `null` if `children` prop is null
635
+ * 2. **Children Rendering**
636
+ * 1. First priority: Component-specific children
637
+ * - `formChildren` for Form
638
+ * - `descriptionChildren` for Description
639
+ * - `tableChildren` for Table
640
+ * 2. Second priority: Generic `children` prop
641
+ * 3. **Custom Render Functions**
642
+ * 1. First priority: Component-specific render functions
643
+ * - `formRender` for Form
644
+ * - `descriptionRender` for Description
645
+ * - `tableRender` for Table
646
+ * 2. Second priority: Generic `render` prop
647
+ * 4. **Extended Types**
648
+ * - Renders based on registered extended type handlers
649
+ * 5. **Default Rendering**
650
+ * - Renders primitive types (string, number, etc.)
651
+ * - Uses default formatting based on data type
652
+ *
653
+ * @example
654
+ * ```tsx
655
+ * import { type UnionFaasItemProps, Form, Table, Description } from '@faasjs/ant-design'
656
+ *
657
+ * const item: UnionFaasItemProps[] = [
658
+ * {
659
+ * id: 'id',
660
+ * formChildren: null, // Don't show in form, only in description and table
661
+ * },
662
+ * {
663
+ * id: 'name',
664
+ * required: true, // Required in form
665
+ * },
666
+ * {
667
+ * id: 'age',
668
+ * type: 'number', // Number type in form, description and table
669
+ * options: ['< 18', '>= 18'], // Options in form and table
670
+ * }
671
+ * ]
672
+ *
673
+ * const data = {
674
+ * id: '1',
675
+ * name: 'John',
676
+ * age: '>= 18',
677
+ * }
678
+ *
679
+ * function App() {
680
+ * return <>
681
+ * <Form items={item} /> // Use in form
682
+ * <Description items={item} dataSource={data} /> // Use in description
683
+ * <Table items={item} dataSource={[ data ]} /> // Use in table
684
+ * </>
685
+ * }
686
+ * ```
687
+ */
543
688
  interface UnionFaasItemProps<Value = any, Values = any> extends FormItemProps, DescriptionItemProps, TableItemProps {
544
689
  children?: UnionFaasItemElement<UnionFaasItemProps<Value, Values>> | null;
545
- render?: UnionFaasItemRender;
690
+ render?: UnionFaasItemRender<Value, Values>;
546
691
  object?: UnionFaasItemProps<Value, Values>[];
547
692
  }
693
+ /**
694
+ * Clone a UnionFaasItemElement with the given props.
695
+ *
696
+ * This function takes a UnionFaasItemElement and props, and returns a cloned element.
697
+ * If the provided element is a valid React element, it clones it with the new props.
698
+ * Otherwise, it creates a new element from the provided element and props.
699
+ *
700
+ * @param element - The UnionFaasItemElement to be cloned.
701
+ * @param props - The props to be applied to the cloned element.
702
+ * @returns The cloned element with the applied props.
703
+ */
704
+ declare function cloneUnionFaasItemElement(element: UnionFaasItemElement, props: any): ReactElement<UnionFaasItemInjection<any, any>, string | react.JSXElementConstructor<any>>;
548
705
 
549
706
  type FormSubmitProps = {
550
707
  /** Default: Submit */
@@ -750,4 +907,4 @@ declare namespace Title {
750
907
  var whyDidYouRender: boolean;
751
908
  }
752
909
 
753
- export { App, type AppProps, type BaseItemProps, type BaseOption, Blank, type BlankProps, ConfigContext, ConfigProvider, type ConfigProviderProps, Description, type DescriptionItemContentProps, type DescriptionItemProps, type DescriptionProps, Drawer, type DrawerProps, ErrorBoundary, type ExtendDescriptionItemProps, type ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, type ExtendTableItemProps, type ExtendTableTypeProps, type ExtendTypes, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasItemProps, type FaasItemType, type FaasItemTypeValue, Form, FormItem, type FormItemProps, type FormProps, type FormSubmitProps, Link, type LinkProps, Loading, type LoadingProps, Modal, type ModalProps, PageNotFound, Routes, type RoutesProps, type TabProps, Table, type TableItemProps, type TableProps, Tabs, type TabsProps, Title, type TitleProps, type UnionFaasItemElement, type UnionFaasItemInjection, type UnionFaasItemProps, type UnionFaasItemRender, type UnionScene, type setDrawerProps, type setModalProps, transferOptions, transferValue, upperFirst, useApp, type useAppProps, useConfigContext, useDrawer, useModal, withFaasData };
910
+ export { App, type AppProps, type BaseItemProps, type BaseOption, Blank, type BlankProps, ConfigContext, ConfigProvider, type ConfigProviderProps, Description, type DescriptionItemContentProps, type DescriptionItemProps, type DescriptionProps, Drawer, type DrawerProps, ErrorBoundary, type ExtendDescriptionItemProps, type ExtendDescriptionTypeProps, type ExtendFormItemProps, type ExtendFormTypeProps, type ExtendTableItemProps, type ExtendTableTypeProps, type ExtendTypes, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasItemProps, type FaasItemType, type FaasItemTypeValue, Form, FormItem, type FormItemProps, type FormProps, type FormSubmitProps, Link, type LinkProps, Loading, type LoadingProps, Modal, type ModalProps, PageNotFound, Routes, type RoutesProps, type TabProps, Table, type TableItemProps, type TableProps, Tabs, type TabsProps, Title, type TitleProps, type UnionFaasItemElement, type UnionFaasItemInjection, type UnionFaasItemProps, type UnionFaasItemRender, type UnionScene, cloneUnionFaasItemElement, type setDrawerProps, type setModalProps, transferOptions, transferValue, upperFirst, useApp, type useAppProps, useConfigContext, useDrawer, useModal, withFaasData };
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { legacyLogicalPropertiesTransformer, StyleProvider } from '@ant-design/c
4
4
  import { Form as Form$1, Drawer as Drawer$1, Modal as Modal$1, message, notification, ConfigProvider as ConfigProvider$1, Typography, Spin, Descriptions, Input, Button, Row, Col, DatePicker, Switch, Select, InputNumber, Radio, Result, Skeleton, Table as Table$1, Tabs as Tabs$1, Alert, Space } from 'antd';
5
5
  import { BrowserRouter, useNavigate, Routes as Routes$1, Route, useLocation } from 'react-router-dom';
6
6
  import { defaultsDeep, cloneDeep, isNil, uniqBy } from 'lodash-es';
7
- import { createContext, useState, useContext, useEffect, cloneElement, Suspense } from 'react';
7
+ import { createContext, useState, useContext, cloneElement, isValidElement, createElement, useEffect, Suspense } from 'react';
8
8
  export { lazy } from 'react';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import dayjs2 from 'dayjs';
@@ -277,6 +277,12 @@ function transferValue(type, value) {
277
277
  }
278
278
  return value;
279
279
  }
280
+ function cloneUnionFaasItemElement(element, props) {
281
+ return cloneElement(
282
+ isValidElement(element) ? element : createElement(element),
283
+ props
284
+ );
285
+ }
280
286
  function Loading(props) {
281
287
  if (props.loading === false) return /* @__PURE__ */ jsx(Fragment, { children: props.children });
282
288
  return /* @__PURE__ */ jsx(
@@ -332,9 +338,22 @@ function DescriptionItemContent(props) {
332
338
  setComputedProps(propsCopy);
333
339
  }, [props]);
334
340
  if (!computedProps) return null;
341
+ if (computedProps.item.descriptionChildren === null || computedProps.item.children === null)
342
+ return null;
343
+ const children = computedProps.item.descriptionChildren || computedProps.item.children;
344
+ if (children)
345
+ return cloneUnionFaasItemElement(children, {
346
+ scene: "description",
347
+ value: computedProps.value,
348
+ values: computedProps.values,
349
+ index: 0
350
+ });
351
+ const render = computedProps.item.descriptionRender || computedProps.item.render;
352
+ if (render)
353
+ return /* @__PURE__ */ jsx(Fragment, { children: render(computedProps.value, computedProps.values, 0, "description") });
335
354
  if (computedProps.extendTypes?.[computedProps.item.type]) {
336
355
  if (computedProps.extendTypes[computedProps.item.type].children)
337
- return cloneElement(
356
+ return cloneUnionFaasItemElement(
338
357
  computedProps.extendTypes[computedProps.item.type].children,
339
358
  {
340
359
  scene: "description",
@@ -351,34 +370,6 @@ function DescriptionItemContent(props) {
351
370
  ) });
352
371
  throw Error(`${computedProps.item.type} requires children or render`);
353
372
  }
354
- if (computedProps.item.descriptionChildren === null) return null;
355
- if (computedProps.item.descriptionChildren)
356
- return cloneElement(computedProps.item.descriptionChildren, {
357
- scene: "description",
358
- value: computedProps.value,
359
- values: computedProps.values
360
- });
361
- if (computedProps.item.children === null) return null;
362
- if (computedProps.item.children)
363
- return cloneElement(computedProps.item.children, {
364
- scene: "description",
365
- value: computedProps.value,
366
- values: computedProps.values
367
- });
368
- if (computedProps.item.descriptionRender)
369
- return /* @__PURE__ */ jsx(Fragment, { children: computedProps.item.descriptionRender(
370
- computedProps.value,
371
- computedProps.values,
372
- 0,
373
- "description"
374
- ) });
375
- if (computedProps.item.render)
376
- return /* @__PURE__ */ jsx(Fragment, { children: computedProps.item.render(
377
- computedProps.value,
378
- computedProps.values,
379
- 0,
380
- "description"
381
- ) });
382
373
  if (computedProps.value === null || Array.isArray(computedProps.value) && !computedProps.value.length)
383
374
  return /* @__PURE__ */ jsx(Blank, {});
384
375
  switch (computedProps.item.type) {
@@ -559,18 +550,18 @@ function FormItem(props) {
559
550
  if (!computedProps) return null;
560
551
  if (hidden)
561
552
  return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, noStyle: true, rules: [], children: /* @__PURE__ */ jsx(Input, { type: "hidden", hidden: true }) });
553
+ if (computedProps.formChildren === null || computedProps.children === null)
554
+ return null;
555
+ const children = computedProps.formChildren || computedProps.children;
556
+ if (children)
557
+ return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneUnionFaasItemElement(children, { scene: "form" }) });
558
+ const render = computedProps.formRender || computedProps.render;
559
+ if (render)
560
+ return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: render(null, null, 0, "form") });
562
561
  if (extendTypes?.[computedProps.type])
563
- return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: extendTypes[computedProps.type].children });
564
- if (computedProps.formChildren === null) return null;
565
- if (computedProps.formChildren)
566
- return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneElement(computedProps.formChildren, { scene: "form" }) });
567
- if (computedProps.children === null) return null;
568
- if (computedProps.children)
569
- return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneElement(computedProps.children, { scene: "form" }) });
570
- if (computedProps.formRender)
571
- return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.formRender(null, null, 0, "form") });
572
- if (computedProps.render)
573
- return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: computedProps.render(null, null, 0, "form") });
562
+ return /* @__PURE__ */ jsx(Form$1.Item, { ...computedProps, children: cloneUnionFaasItemElement(extendTypes[computedProps.type].children, {
563
+ scene: "form"
564
+ }) });
574
565
  switch (computedProps.type) {
575
566
  case "string":
576
567
  if (isOptionsProps(computedProps))
@@ -1047,29 +1038,39 @@ function Table(props) {
1047
1038
  });
1048
1039
  generateFilterDropdown(item);
1049
1040
  }
1050
- if (item.tableChildren === null) item.render = () => null;
1051
- else if (item.tableChildren)
1052
- item.render = (value, values) => cloneElement(item.tableChildren, {
1053
- scene: "table",
1054
- value,
1055
- values
1056
- });
1057
- else if (item.children === null) item.render = () => null;
1058
- else if (item.children)
1059
- item.render = (value, values) => cloneElement(item.children, {
1041
+ const isNull = item.tableChildren === null || item.children === null;
1042
+ if (isNull) {
1043
+ item.render = () => null;
1044
+ continue;
1045
+ }
1046
+ const children = item.tableChildren || item.children;
1047
+ if (children) {
1048
+ item.render = (value, values) => cloneUnionFaasItemElement(children, {
1060
1049
  scene: "table",
1061
1050
  value,
1062
- values
1051
+ values,
1052
+ index: 0
1063
1053
  });
1054
+ delete item.children;
1055
+ delete item.tableChildren;
1056
+ continue;
1057
+ }
1058
+ const render = item.tableRender || item.render;
1059
+ if (render) {
1060
+ item.render = (value, values) => render(value, values, 0, "table");
1061
+ delete item.tableRender;
1062
+ continue;
1063
+ }
1064
1064
  if (props.extendTypes?.[item.type]) {
1065
- if (props.extendTypes[item.type].children)
1066
- item.render = (value, values) => cloneElement(props.extendTypes[item.type].children, {
1065
+ if (props.extendTypes[item.type].children) {
1066
+ item.render = (value, values) => cloneUnionFaasItemElement(props.extendTypes[item.type].children, {
1067
1067
  scene: "table",
1068
1068
  value,
1069
- values
1069
+ values,
1070
+ index: 0
1070
1071
  });
1071
- else if (props.extendTypes[item.type].render)
1072
- item.render = props.extendTypes[item.type].render;
1072
+ } else if (props.extendTypes[item.type].render)
1073
+ item.render = (value, values) => props.extendTypes[item.type].render(value, values, 0, "table");
1073
1074
  else throw Error(`${item.type} requires children or render`);
1074
1075
  continue;
1075
1076
  }
@@ -1497,15 +1498,15 @@ function FaasDataTable({
1497
1498
  rowKey: props.rowKey || "id",
1498
1499
  columns: currentColumns,
1499
1500
  dataSource: data.rows,
1500
- pagination: {
1501
- ...props.pagination,
1502
- ...data.pagination
1501
+ pagination: props.pagination === false ? false : {
1502
+ ...props.pagination || /* @__PURE__ */ Object.create(null),
1503
+ ...data.pagination || /* @__PURE__ */ Object.create(null)
1503
1504
  },
1504
1505
  onChange: (pagination, filters, sorter, extra) => {
1505
1506
  if (props.onChange) {
1506
1507
  const processed = props.onChange(pagination, filters, sorter, extra);
1507
1508
  reload({
1508
- ...params,
1509
+ ...params || /* @__PURE__ */ Object.create(null),
1509
1510
  pagination: processed.pagination,
1510
1511
  filters: processed.filters,
1511
1512
  sorter: processed.sorter,
@@ -1514,7 +1515,7 @@ function FaasDataTable({
1514
1515
  return;
1515
1516
  }
1516
1517
  reload({
1517
- ...params,
1518
+ ...params || /* @__PURE__ */ Object.create(null),
1518
1519
  pagination,
1519
1520
  filters,
1520
1521
  sorter
@@ -1557,4 +1558,4 @@ function Title(props) {
1557
1558
  }
1558
1559
  Title.whyDidYouRender = true;
1559
1560
 
1560
- export { App, Blank, ConfigContext, ConfigProvider, Description, Drawer, ErrorBoundary, FaasDataWrapper, Form, FormItem, Link, Loading, Modal, PageNotFound, Routes, Table, Tabs, Title, transferOptions, transferValue, upperFirst, useApp, useConfigContext, useDrawer, useModal, withFaasData };
1561
+ export { App, Blank, ConfigContext, ConfigProvider, Description, Drawer, ErrorBoundary, FaasDataWrapper, Form, FormItem, Link, Loading, Modal, PageNotFound, Routes, Table, Tabs, Title, cloneUnionFaasItemElement, transferOptions, transferValue, upperFirst, useApp, useConfigContext, useDrawer, useModal, withFaasData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "6.3.2",
3
+ "version": "6.4.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -30,7 +30,7 @@
30
30
  "dist"
31
31
  ],
32
32
  "peerDependencies": {
33
- "@faasjs/react": "6.3.2",
33
+ "@faasjs/react": "6.4.1",
34
34
  "antd": "*",
35
35
  "@ant-design/icons": "*",
36
36
  "lodash-es": "*",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/lodash-es": "*",
43
- "@faasjs/react": "6.3.2",
43
+ "@faasjs/react": "6.4.1",
44
44
  "antd": "*",
45
45
  "@ant-design/icons": "*",
46
46
  "lodash-es": "*",