import { ReactNode, createRef, UIEventHandler, ReactElement, CSSProperties, MouseEventHandler, isValidElement, cloneElement, WheelEventHandler, HTMLAttributes, RefObject, forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, } from 'react' import { cx as c, addClass, addThousandSeparator, classes, codeWarningOnce, EventListenerHandler, forceRedrawAlt, getBrowserScrollBarWidth, omit, pickDerivedStateFromProps, removeClass, safeInvoke, toggleSelectedList, createElementFromHTML, __DEV__, getTextFromReactNode, debounce, isArray, isEqual, isFunction, isUndefined, throttle, toArray, } from '@befe/brick-utils' import {ResizeObserver} from '@juggle/resize-observer' import {useLocale, useTheme, fontSize, lineHeight, getThemeConfigSingleton} from '@befe/brick-core' import {Button, ButtonProps} from '@befe/brick-comp-button' import {Checkbox, CheckboxProps} from '@befe/brick-comp-checkbox' import {Switch, SwitchProps} from '@befe/brick-comp-switch' import {Icon} from '@befe/brick-comp-icon' import {Menu, MenuItem, MenuPopper, MenuPopperHandle, MenuItemProps} from '@befe/brick-comp-menu' import {PopoverConfirm, PopoverConfirmProps, Popover, PopoverProps} from '@befe/brick-comp-popover' import { SvgDataFileBox, SvgDataFileBoxLg, SvgDataFileTick, SvgDataFileTickLg, SvgDataFileX, SvgDataFileXLg, SvgDataFolderSearch, SvgDataFolderSearchLg, SvgFastDown, SvgFastUp, SvgMoreEllipsis, SvgPlainDown, SvgPlainUp, } from '@befe/brick-icon' import {Loading} from '@befe/brick-comp-loading' import {SvgSorterTriangleUp} from './assets/sorter-triangle-up' import {SvgSorterTriangleDown} from './assets/sorter-triangle-down' import { IS_CHROME, IS_EDGE, IS_SAFARI, SCROLL_BAR_WIDTH, TR_HOVER_CLASS, TR_HOVER_KEY_CLASS_PREFIX, IS_IE, } from './constants' import {localeDictTable} from './locale' import {StickyController} from './utils/sticky' /** * @public */ export interface TdProps { className?: string colSpan?: number rowSpan?: number } type OperationPropsBase = ButtonProps & MenuItemProps /** * @public */ export interface OperationProps extends OperationPropsBase { key?: string label?: string dropList?: Array popoverConfirmProps?: PopoverConfirmProps popoverProps?: PopoverProps } export const TABLE_SIZES = ['sm', 'md'] as const type TableSize = (typeof TABLE_SIZES)[number] export const TABLE_LINE_SPACINGS = ['compact', 'regular'] as const type TableLineSpacing = (typeof TABLE_LINE_SPACINGS)[number] export const TABLE_NO_DATA_TYPES = ['empty', 'search', 'error', 'success'] as const export type TableNoDataType = (typeof TABLE_NO_DATA_TYPES)[number] /** * TableRow extends `Record` * @public */ export interface TableRow extends Record { /** * 树状数据.行层级 * @private */ _level?: number /** * 树状数据.子行 */ children?: TableRow[] } type CallbackGivesRow = { bivarianceHack(row: TRow, rowIdx: number): Val }['bivarianceHack'] const SORT_ORDER_ASCENT = 'ascent' const SORT_ORDER_DESCENT = 'descent' const SORT_ORDER_ORIGINAL = 'original' // original 最后 const SORT_ORDER_SEQUENCE = [SORT_ORDER_ASCENT, SORT_ORDER_DESCENT, SORT_ORDER_ORIGINAL] as const type SortOrder = typeof SORT_ORDER_ORIGINAL | typeof SORT_ORDER_ASCENT | typeof SORT_ORDER_DESCENT const NEXT_SORT_ORDER: Record = {} SORT_ORDER_SEQUENCE.forEach((order, index) => { NEXT_SORT_ORDER[order] = SORT_ORDER_SEQUENCE[index + 1] || SORT_ORDER_SEQUENCE[0] }) const SORT_ORDER_DIRECTION = { [SORT_ORDER_ASCENT]: 1, [SORT_ORDER_DESCENT]: -1, [SORT_ORDER_ORIGINAL]: 0, } /** * @public */ export interface TableCol { /** * 列的主键 * 可以对应到数据行的字段名 */ key: string | string[] /** * 列头的内容 */ thContent?: ReactNode // | { // bivarianceHack(row: TRow): ReactNode // }['bivarianceHack'] /** * 列头的内容的 title tip * 默认 title tip 与列头的内容一致 */ thTitle?: string /** * 列的行内容 * * 如不指定,则默认为 `row => row[key]` */ tdContent?: CallbackGivesRow /** * 列的行内容的 title tip * * 默认 title tip 与行内容一致 */ tdTitle?: CallbackGivesRow /** * 此列的 td 的 props */ tdProps?: CallbackGivesRow /** * 固定列于左/右 */ fixed?: 'left' | 'right' /** * 作为 “序号列” 的,单元改个 */ serial?: CallbackGivesRow /** * 作为"选择列"的 checkbox props * * **注意** 如果返回的 ReactElement 不是 ``,比如 ``, * 需要自行控制其中 `` 的 size 等以符合其在 Table 中的样式要求 */ checkbox?: CallbackGivesRow /** * 作为"开关列"的 switch props * * **注意** 如果返回的 ReactElement 不是 ``,比如 ``, * 需要自行控制其中 `` 的 size 等以符合其在 Table 中的样式要求 */ switch?: CallbackGivesRow /** * 作为"操作列"的 button 列表 * * **注意** 如果返回的 ReactElement 不是 `