/* eslint-disable @typescript-eslint/ban-types */ import React, { memo, forwardRef, useImperativeHandle } from 'react' import { Space, Table } from 'antd' import { classnames, run } from '@fexd/tools' import { useProFormLocales } from '@fexd/pro-form' import { useContextSize, ConfigProvider } from '@fexd/pro-provider' import hoistStatics from 'hoist-non-react-statics' import { TableWrapper, ChainableTablePlugins } from '../utils' import useQueryFieldPlugin from '../plugins/queryField' import useTablePlugin from '../plugins/table' import { defaultProps } from '../useProps' import { ProTableProps, ProTableBuiltInPlugins } from '../types' import { builtInPluginList, builtInPlugins } from './builtInPlugins' import proTableAddon from './addon' const TableContent = memo( forwardRef(function TableContent(props: any, ref) { const queryField = useQueryFieldPlugin() const table = useTablePlugin() const ctxSize = useContextSize() const { mini = ctxSize ? ctxSize === 'small' : false, pure = false, tableExtraRender, hideQueryFields, plugins = [], bodyClassName, bodyStyle = pure ? { padding: 0 } : {}, render = ({ queryField, tableExtra, table }: any = {}) => ( {queryField} {tableExtra} {table} ), tableRef, } = props const allPluginRef = Object.assign( {}, ...plugins.map((plugin: any) => ({ [plugin.name]: plugin(), })), ) useImperativeHandle(ref, () => allPluginRef) useImperativeHandle(tableRef, () => allPluginRef) return ( {run(render, undefined, { queryField: !hideQueryFields && queryField?.hasQueryFields ? run(queryField, 'render') : null, tableExtra: tableExtraRender ?
{run(tableExtraRender)}
: null, table: run(table, 'render'), })} {run(queryField, 'renderAutoQueryTrigger')}
) }), ) // type TableType = typeof Table declare const ForwardTable: ( props: ProTableProps & { children?: React.ReactNode } & { ref?: React.Ref | undefined }, ) => React.ReactElement export type ProTableType = Omit & typeof ForwardTable & React.FC & typeof proTableAddon // ProTable.defaultProps = {} export function createProTable = ProTableProps>( plugins: ChainableTablePlugins = builtInPlugins, targetDefaultProps: ProTableProps = defaultProps, ): ProTableType { const ProTable = hoistStatics( memo( // const ProTable: React.FC = memo( forwardRef(function ProTable(props: T, ref) { const allPlugins = [...builtInPluginList, ...plugins.get()] return ( ) }), ), Table, ) as any Object.assign(ProTable, { defaultProps: targetDefaultProps, ...proTableAddon, }) return ProTable as ProTableType } export default createProTable