@are-visual/virtual-table 0.11.3 → 0.11.5-beta.0
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/index.d.ts +4 -2
- package/index.esm.js +236 -118
- package/index.esm.js.map +1 -1
- package/middleware/expandable/index.js +4 -2
- package/middleware/expandable/index.js.map +1 -1
- package/middleware/loading/index.js +2 -10
- package/middleware/loading/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -28,8 +28,10 @@ const ExpandRow = props => {
|
|
|
28
28
|
display: isExpanded ? undefined : 'none'
|
|
29
29
|
},
|
|
30
30
|
ref: node => {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
setRowHeightByRowKey(rowKey, ExpandRowHeightKey, () => {
|
|
32
|
+
if (node == null) return;
|
|
33
|
+
return node.offsetHeight;
|
|
34
|
+
});
|
|
33
35
|
},
|
|
34
36
|
children: jsx("td", {
|
|
35
37
|
colSpan: colSpan,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../packages/virtual-table/src/middleware/expandable/expand-row.tsx","../../../../packages/virtual-table/src/middleware/expandable/index.tsx"],"sourcesContent":["import type { CSSProperties, FC, Key, ReactNode } from 'react'\nimport { useContainerSize, useTableRowManager } from '@are-visual/virtual-table'\nimport clsx from 'clsx'\n\nexport interface ExpandRowProps {\n className?: string\n style?: CSSProperties\n rowKey: Key\n isExpanded?: boolean\n colSpan?: number\n children?: ReactNode\n fixed?: boolean\n}\n\nexport const ExpandRowHeightKey = 'ExpandRow'\n\nconst ExpandRow: FC<ExpandRowProps> = (props) => {\n const {\n className,\n style,\n rowKey,\n isExpanded,\n colSpan,\n children,\n fixed,\n } = props\n\n const { setRowHeightByRowKey } = useTableRowManager()\n const { tableWidth } = useContainerSize()\n\n return (\n <tr\n className={clsx('virtual-table-expanded-row', className)}\n style={{ ...style, display: isExpanded ? undefined : 'none' }}\n ref={(node) => {\n if (node == null) return\n setRowHeightByRowKey(rowKey, ExpandRowHeightKey, node.offsetHeight)\n }}\n >\n <td colSpan={colSpan}>\n <div\n className={clsx(\n 'virtual-table-cell',\n fixed && 'virtual-table-expanded-row-fixed',\n )}\n style={{ width: tableWidth <= 0 ? undefined : tableWidth }}\n >\n {children}\n </div>\n </td>\n </tr>\n )\n}\n\nexport default ExpandRow\n","/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n AnyObject,\n ColumnExtra,\n ColumnType,\n FixedType,\n MiddlewareContext,\n MiddlewareRenderRow,\n MiddlewareResult,\n OnRowType,\n} from '@are-visual/virtual-table'\nimport type { Key, MouseEvent, ReactNode } from 'react'\nimport { createMiddleware, getRowKey, isValidFixed, useShallowMemo, useStableFn } from '@are-visual/virtual-table'\nimport { useControllableValue } from '@are-visual/virtual-table/middleware/utils/useControllableValue'\nimport clsx from 'clsx'\nimport { useCallback, useMemo, useRef } from 'react'\nimport ExpandRow, { ExpandRowHeightKey } from './expand-row'\n\ntype TriggerEventHandler<T> = (record: T, event: MouseEvent<HTMLElement>) => void\nexport interface RenderExpandIconProps<T> {\n prefixCls: string\n expanded: boolean\n record: T\n expandable: boolean\n onExpand: TriggerEventHandler<T>\n}\nexport type RowClassName<T> = (record: T, index: number, indent: number) => string\nexport type RenderExpandIcon<T> = (props: RenderExpandIconProps<T>) => ReactNode\nexport type ExpandedRowRender<T> = (record: T, index: number, indent: number, expanded: boolean) => ReactNode\n\nexport interface ExpandableConfig<T> {\n expandedRowKeys?: readonly Key[]\n defaultExpandedRowKeys?: readonly Key[]\n expandedRowRender?: ExpandedRowRender<T>\n columnTitle?: ReactNode\n expandRowByClick?: boolean\n expandIcon?: RenderExpandIcon<T>\n onExpand?: (expanded: boolean, record: T) => void\n onExpandedRowsChange?: (expandedKeys: readonly Key[]) => void\n defaultExpandAllRows?: boolean\n showExpandColumn?: boolean\n expandedRowClassName?: string | RowClassName<T>\n rowExpandable?: (record: T) => boolean\n columnWidth?: number\n fixed?: FixedType\n extraColumnProps?: ColumnExtra\n}\n\nexport { ExpandRowHeightKey }\nexport const EXPANSION_COLUMN_KEY = 'VirtualTable.EXPANSION_COLUMN'\n\nexport function isExpansionColumn<T = any>(column: ColumnType<T>) {\n return column.key === EXPANSION_COLUMN_KEY\n}\n\nfunction useTableExpandable<T = any>(\n ctx: MiddlewareContext<T>,\n options?: ExpandableConfig<T>,\n): MiddlewareResult<T> {\n const disablePlugin = options == null\n\n const { rowKey, columns: rawColumns, dataSource } = ctx\n const {\n // expandedRowKeys,\n // onExpandedRowsChange,\n defaultExpandedRowKeys,\n expandedRowRender,\n columnTitle,\n expandRowByClick = false,\n expandIcon,\n onExpand,\n\n defaultExpandAllRows = false,\n\n // TODO: 未实现\n // indentSize: _indentSize,\n\n showExpandColumn = true,\n expandedRowClassName,\n\n rowExpandable,\n columnWidth = 50,\n fixed,\n extraColumnProps,\n } = options ?? {}\n\n const _rowExpandableValue = useMemo(() => {\n return dataSource.map((row) => {\n if (!rowExpandable) return false\n return rowExpandable(row)\n })\n }, [dataSource, rowExpandable])\n\n // useShallowMemo 每一次渲染时候都会重新求值,这对于某些开销较大的计算不太友好,\n // 所以使用 useMemo 求值再通过 useShallowMemo 浅比较\n // useMemo 标记 deps 后,若 deps 不变也就不需要重新求值\n // 使用 useShallowMemo 主要是为了防止重新求值后结果不变但地址指针变化,导致不必要的渲染\n const rowExpandableRecord = useShallowMemo(() => _rowExpandableValue)\n\n // 即使 defaultExpandAllRows 变更之后,此插件也不要响应变化,只使用初始值,所以存储一下\n const defaultExpandAll = useRef(\n // options 中有 expandedRowKeys 则表示受控模式,那么 defaultExpandAllRows 不生效\n 'expandedRowKeys' in (options ?? {}) || 'defaultExpandedRowKeys' in (options ?? {})\n ? false\n : defaultExpandAllRows,\n )\n const defaultExpandKey = useShallowMemo((): readonly Key[] => {\n if (defaultExpandAll.current) {\n const expandKeys = dataSource.map((record, index): Key | null => {\n if (rowExpandableRecord[index]) {\n const key = (record as AnyObject)[rowKey as string] as string | number\n return key\n }\n return null\n })\n return expandKeys.filter((x) => x != null)\n }\n return []\n })\n\n const expansionKeys = useRef(new Set<Key>(defaultExpandedRowKeys ?? defaultExpandKey))\n const [expansion, setExpansion] = useControllableValue<readonly Key[]>(\n options ?? {},\n {\n trigger: 'onExpandedRowsChange',\n valuePropName: 'expandedRowKeys',\n defaultValue: defaultExpandedRowKeys ?? defaultExpandKey,\n },\n )\n\n const onUpdateExpansion = useStableFn((rowData: T, shouldExpand?: boolean) => {\n const key = getRowKey(rowData, rowKey)\n expansionKeys.current.add(key)\n if (shouldExpand == null) {\n if (expansion.includes(key)) {\n setExpansion(expansion.filter((x) => x !== key))\n onExpand?.(false, rowData)\n } else {\n setExpansion([...expansion, key])\n onExpand?.(true, rowData)\n }\n } else if (shouldExpand) {\n setExpansion([...expansion, key])\n onExpand?.(true, rowData)\n } else {\n setExpansion(expansion.filter((x) => x !== key))\n onExpand?.(false, rowData)\n }\n })\n\n const isFixed = isValidFixed(fixed)\n\n const renderRow: MiddlewareRenderRow = useCallback((children, args) => {\n const { rowData, rowIndex, rowKey: key, columnDescriptor } = args\n\n const isExpandable = rowExpandableRecord[rowIndex]\n if (isExpandable) {\n const isExpanded: boolean | undefined = expansion.includes(key)\n const isRendered = expansionKeys.current.has(key)\n\n let className = ''\n if (typeof expandedRowClassName === 'string') {\n className = expandedRowClassName\n } else if (typeof expandedRowClassName === 'function') {\n className = expandedRowClassName(rowData as T, rowIndex, 0)\n }\n\n return (\n <>\n {children}\n {isRendered && (\n <ExpandRow\n className={className}\n rowKey={key}\n isExpanded={isExpanded}\n colSpan={columnDescriptor.length}\n fixed={isFixed}\n >\n {expandedRowRender?.(rowData as T, rowIndex, 0, isExpanded)}\n </ExpandRow>\n )}\n </>\n )\n }\n return children\n }, [\n isFixed,\n rowExpandableRecord,\n expansion,\n expandedRowClassName,\n expandedRowRender,\n ])\n\n const columns = useMemo((): ColumnType<T>[] => {\n if (!showExpandColumn) {\n return rawColumns\n }\n\n return [\n {\n ...extraColumnProps,\n key: EXPANSION_COLUMN_KEY,\n title: columnTitle,\n width: columnWidth,\n fixed,\n render(_value, record, index) {\n const key = getRowKey(record, rowKey)\n\n const expandable = rowExpandableRecord[index] ?? false\n const expanded = expansion.includes(key)\n\n if (typeof expandIcon === 'function') {\n return expandIcon({\n expandable,\n expanded,\n record,\n prefixCls: 'virtual-table',\n onExpand: (rowData: T, _e) => {\n onUpdateExpansion(rowData)\n },\n })\n }\n\n if (!expandable) {\n return null\n }\n\n return (\n <button\n className={clsx(\n 'virtual-table-row-expand-icon',\n expanded\n ? 'virtual-table-row-expand-icon-expanded'\n : 'virtual-table-row-expand-icon-collapsed',\n )}\n type=\"button\"\n aria-label={expanded ? '关闭行' : '展开行'}\n aria-expanded={expanded}\n onClick={() => {\n onUpdateExpansion(record, !expanded)\n }}\n />\n )\n },\n onHeaderCell() {\n return { className: 'virtual-table-expand-column' }\n },\n },\n ...rawColumns,\n ]\n }, [\n showExpandColumn,\n columnTitle,\n columnWidth,\n fixed,\n rawColumns,\n rowKey,\n rowExpandableRecord,\n expansion,\n expandIcon,\n onUpdateExpansion,\n extraColumnProps,\n ])\n\n const onRow: OnRowType<T> = useCallback((record, index) => {\n if (rowExpandableRecord[index]) {\n return {\n onClick: (e) => {\n e.stopPropagation()\n onUpdateExpansion(record)\n },\n }\n }\n return {}\n }, [rowExpandableRecord, onUpdateExpansion])\n\n if (disablePlugin) {\n return ctx\n }\n\n return {\n ...ctx,\n columns,\n renderRow,\n onRow: !expandRowByClick ? undefined : onRow,\n }\n}\n\nexport const tableExpandable = createMiddleware(useTableExpandable)\n"],"names":["ExpandRowHeightKey","ExpandRow","props","className","style","rowKey","isExpanded","colSpan","children","fixed","setRowHeightByRowKey","useTableRowManager","tableWidth","useContainerSize","_jsx","clsx","display","undefined","ref","node","offsetHeight","width","EXPANSION_COLUMN_KEY","isExpansionColumn","column","key","useTableExpandable","ctx","options","disablePlugin","columns","rawColumns","dataSource","defaultExpandedRowKeys","expandedRowRender","columnTitle","expandRowByClick","expandIcon","onExpand","defaultExpandAllRows","showExpandColumn","expandedRowClassName","rowExpandable","columnWidth","extraColumnProps","_rowExpandableValue","useMemo","map","row","rowExpandableRecord","useShallowMemo","defaultExpandAll","useRef","defaultExpandKey","current","expandKeys","record","index","filter","x","expansionKeys","Set","expansion","setExpansion","useControllableValue","trigger","valuePropName","defaultValue","onUpdateExpansion","useStableFn","rowData","shouldExpand","getRowKey","add","includes","isFixed","isValidFixed","renderRow","useCallback","args","rowIndex","columnDescriptor","isExpandable","isRendered","has","_jsxs","length","title","render","_value","expandable","expanded","prefixCls","_e","type","onClick","onHeaderCell","onRow","e","stopPropagation","tableExpandable","createMiddleware"],"mappings":";;;;;;AAcO,MAAMA,kBAAkB,GAAG;AAElC,MAAMC,SAAS,GAAwBC,KAAK,IAAI;EAC9C,MAAM;IACJC,SAAS;IACTC,KAAK;IACLC,MAAM;IACNC,UAAU;IACVC,OAAO;IACPC,QAAQ;AACRC,IAAAA;AACD,GAAA,GAAGP,KAAK;EAET,MAAM;AAAEQ,IAAAA;GAAsB,GAAGC,kBAAkB,EAAE;EACrD,MAAM;AAAEC,IAAAA;GAAY,GAAGC,gBAAgB,EAAE;EAEzC,OACEC,GAAA,CAAA,IAAA,EAAA;AACEX,IAAAA,SAAS,EAAEY,IAAI,CAAC,4BAA4B,EAAEZ,SAAS,CAAC;AACxDC,IAAAA,KAAK,EAAE;AAAE,MAAA,GAAGA,KAAK;AAAEY,MAAAA,OAAO,EAAEV,UAAU,GAAGW,SAAS,GAAG;KAAQ;IAC7DC,GAAG,EAAGC,IAAI,IAAI;MACZ,IAAIA,IAAI,IAAI,IAAI,EAAE;MAClBT,oBAAoB,CAACL,MAAM,EAAEL,kBAAkB,EAAEmB,IAAI,CAACC,YAAY,CAAC;KACpE;cAEDN,GAAI,CAAA,IAAA,EAAA;AAAAP,MAAAA,OAAO,EAAEA,OAAO;AAAAC,MAAAA,QAAA,EAClBM;QACEX,S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,KAAK,CAAC,EAAE;MAC9B,OAAO;QACLsC,OAAO,EAAGG,CAAC,IAAI;UACbA,CAAC,CAACC,eAAe,EAAE;UACnB/B,iBAAiB,CAACZ,MAAM,CAAC;AAC3B;OACD;AACH;AACA,IAAA,OAAO,EAAE;AACX,GAAC,EAAE,CAACP,mBAAmB,EAAEmB,iBAAiB,CAAC,CAAC;AAE5C,EAAA,IAAIvC,aAAa,EAAE;AACjB,IAAA,OAAOF,GAAG;AACZ;EAEA,OAAO;AACL,IAAA,GAAGA,GAAG;IACNG,OAAO;IACP+C,SAAS;AACToB,IAAAA,KAAK,EAAE,CAAC7D,gBAAgB,GAAGnB,SAAS,GAAGgF;GACxC;AACH;MAEaG,eAAe,GAAGC,gBAAgB,CAAC3E,kBAAkB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../packages/virtual-table/src/middleware/expandable/expand-row.tsx","../../../../packages/virtual-table/src/middleware/expandable/index.tsx"],"sourcesContent":["import type { CSSProperties, FC, Key, ReactNode } from 'react'\nimport { useContainerSize, useTableRowManager } from '@are-visual/virtual-table'\nimport clsx from 'clsx'\n\nexport interface ExpandRowProps {\n className?: string\n style?: CSSProperties\n rowKey: Key\n isExpanded?: boolean\n colSpan?: number\n children?: ReactNode\n fixed?: boolean\n}\n\nexport const ExpandRowHeightKey = 'ExpandRow'\n\nconst ExpandRow: FC<ExpandRowProps> = (props) => {\n const {\n className,\n style,\n rowKey,\n isExpanded,\n colSpan,\n children,\n fixed,\n } = props\n\n const { setRowHeightByRowKey } = useTableRowManager()\n const { tableWidth } = useContainerSize()\n\n return (\n <tr\n className={clsx('virtual-table-expanded-row', className)}\n style={{ ...style, display: isExpanded ? undefined : 'none' }}\n ref={(node) => {\n setRowHeightByRowKey(rowKey, ExpandRowHeightKey, () => {\n if (node == null) return\n return node.offsetHeight\n })\n }}\n >\n <td colSpan={colSpan}>\n <div\n className={clsx(\n 'virtual-table-cell',\n fixed && 'virtual-table-expanded-row-fixed',\n )}\n style={{ width: tableWidth <= 0 ? undefined : tableWidth }}\n >\n {children}\n </div>\n </td>\n </tr>\n )\n}\n\nexport default ExpandRow\n","/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n AnyObject,\n ColumnExtra,\n ColumnType,\n FixedType,\n MiddlewareContext,\n MiddlewareRenderRow,\n MiddlewareResult,\n OnRowType,\n} from '@are-visual/virtual-table'\nimport type { Key, MouseEvent, ReactNode } from 'react'\nimport { createMiddleware, getRowKey, isValidFixed, useShallowMemo, useStableFn } from '@are-visual/virtual-table'\nimport { useControllableValue } from '@are-visual/virtual-table/middleware/utils/useControllableValue'\nimport clsx from 'clsx'\nimport { useCallback, useMemo, useRef } from 'react'\nimport ExpandRow, { ExpandRowHeightKey } from './expand-row'\n\ntype TriggerEventHandler<T> = (record: T, event: MouseEvent<HTMLElement>) => void\nexport interface RenderExpandIconProps<T> {\n prefixCls: string\n expanded: boolean\n record: T\n expandable: boolean\n onExpand: TriggerEventHandler<T>\n}\nexport type RowClassName<T> = (record: T, index: number, indent: number) => string\nexport type RenderExpandIcon<T> = (props: RenderExpandIconProps<T>) => ReactNode\nexport type ExpandedRowRender<T> = (record: T, index: number, indent: number, expanded: boolean) => ReactNode\n\nexport interface ExpandableConfig<T> {\n expandedRowKeys?: readonly Key[]\n defaultExpandedRowKeys?: readonly Key[]\n expandedRowRender?: ExpandedRowRender<T>\n columnTitle?: ReactNode\n expandRowByClick?: boolean\n expandIcon?: RenderExpandIcon<T>\n onExpand?: (expanded: boolean, record: T) => void\n onExpandedRowsChange?: (expandedKeys: readonly Key[]) => void\n defaultExpandAllRows?: boolean\n showExpandColumn?: boolean\n expandedRowClassName?: string | RowClassName<T>\n rowExpandable?: (record: T) => boolean\n columnWidth?: number\n fixed?: FixedType\n extraColumnProps?: ColumnExtra\n}\n\nexport { ExpandRowHeightKey }\nexport const EXPANSION_COLUMN_KEY = 'VirtualTable.EXPANSION_COLUMN'\n\nexport function isExpansionColumn<T = any>(column: ColumnType<T>) {\n return column.key === EXPANSION_COLUMN_KEY\n}\n\nfunction useTableExpandable<T = any>(\n ctx: MiddlewareContext<T>,\n options?: ExpandableConfig<T>,\n): MiddlewareResult<T> {\n const disablePlugin = options == null\n\n const { rowKey, columns: rawColumns, dataSource } = ctx\n const {\n // expandedRowKeys,\n // onExpandedRowsChange,\n defaultExpandedRowKeys,\n expandedRowRender,\n columnTitle,\n expandRowByClick = false,\n expandIcon,\n onExpand,\n\n defaultExpandAllRows = false,\n\n // TODO: 未实现\n // indentSize: _indentSize,\n\n showExpandColumn = true,\n expandedRowClassName,\n\n rowExpandable,\n columnWidth = 50,\n fixed,\n extraColumnProps,\n } = options ?? {}\n\n const _rowExpandableValue = useMemo(() => {\n return dataSource.map((row) => {\n if (!rowExpandable) return false\n return rowExpandable(row)\n })\n }, [dataSource, rowExpandable])\n\n // useShallowMemo 每一次渲染时候都会重新求值,这对于某些开销较大的计算不太友好,\n // 所以使用 useMemo 求值再通过 useShallowMemo 浅比较\n // useMemo 标记 deps 后,若 deps 不变也就不需要重新求值\n // 使用 useShallowMemo 主要是为了防止重新求值后结果不变但地址指针变化,导致不必要的渲染\n const rowExpandableRecord = useShallowMemo(() => _rowExpandableValue)\n\n // 即使 defaultExpandAllRows 变更之后,此插件也不要响应变化,只使用初始值,所以存储一下\n const defaultExpandAll = useRef(\n // options 中有 expandedRowKeys 则表示受控模式,那么 defaultExpandAllRows 不生效\n 'expandedRowKeys' in (options ?? {}) || 'defaultExpandedRowKeys' in (options ?? {})\n ? false\n : defaultExpandAllRows,\n )\n const defaultExpandKey = useShallowMemo((): readonly Key[] => {\n if (defaultExpandAll.current) {\n const expandKeys = dataSource.map((record, index): Key | null => {\n if (rowExpandableRecord[index]) {\n const key = (record as AnyObject)[rowKey as string] as string | number\n return key\n }\n return null\n })\n return expandKeys.filter((x) => x != null)\n }\n return []\n })\n\n const expansionKeys = useRef(new Set<Key>(defaultExpandedRowKeys ?? defaultExpandKey))\n const [expansion, setExpansion] = useControllableValue<readonly Key[]>(\n options ?? {},\n {\n trigger: 'onExpandedRowsChange',\n valuePropName: 'expandedRowKeys',\n defaultValue: defaultExpandedRowKeys ?? defaultExpandKey,\n },\n )\n\n const onUpdateExpansion = useStableFn((rowData: T, shouldExpand?: boolean) => {\n const key = getRowKey(rowData, rowKey)\n expansionKeys.current.add(key)\n if (shouldExpand == null) {\n if (expansion.includes(key)) {\n setExpansion(expansion.filter((x) => x !== key))\n onExpand?.(false, rowData)\n } else {\n setExpansion([...expansion, key])\n onExpand?.(true, rowData)\n }\n } else if (shouldExpand) {\n setExpansion([...expansion, key])\n onExpand?.(true, rowData)\n } else {\n setExpansion(expansion.filter((x) => x !== key))\n onExpand?.(false, rowData)\n }\n })\n\n const isFixed = isValidFixed(fixed)\n\n const renderRow: MiddlewareRenderRow = useCallback((children, args) => {\n const { rowData, rowIndex, rowKey: key, columnDescriptor } = args\n\n const isExpandable = rowExpandableRecord[rowIndex]\n if (isExpandable) {\n const isExpanded: boolean | undefined = expansion.includes(key)\n const isRendered = expansionKeys.current.has(key)\n\n let className = ''\n if (typeof expandedRowClassName === 'string') {\n className = expandedRowClassName\n } else if (typeof expandedRowClassName === 'function') {\n className = expandedRowClassName(rowData as T, rowIndex, 0)\n }\n\n return (\n <>\n {children}\n {isRendered && (\n <ExpandRow\n className={className}\n rowKey={key}\n isExpanded={isExpanded}\n colSpan={columnDescriptor.length}\n fixed={isFixed}\n >\n {expandedRowRender?.(rowData as T, rowIndex, 0, isExpanded)}\n </ExpandRow>\n )}\n </>\n )\n }\n return children\n }, [\n isFixed,\n rowExpandableRecord,\n expansion,\n expandedRowClassName,\n expandedRowRender,\n ])\n\n const columns = useMemo((): ColumnType<T>[] => {\n if (!showExpandColumn) {\n return rawColumns\n }\n\n return [\n {\n ...extraColumnProps,\n key: EXPANSION_COLUMN_KEY,\n title: columnTitle,\n width: columnWidth,\n fixed,\n render(_value, record, index) {\n const key = getRowKey(record, rowKey)\n\n const expandable = rowExpandableRecord[index] ?? false\n const expanded = expansion.includes(key)\n\n if (typeof expandIcon === 'function') {\n return expandIcon({\n expandable,\n expanded,\n record,\n prefixCls: 'virtual-table',\n onExpand: (rowData: T, _e) => {\n onUpdateExpansion(rowData)\n },\n })\n }\n\n if (!expandable) {\n return null\n }\n\n return (\n <button\n className={clsx(\n 'virtual-table-row-expand-icon',\n expanded\n ? 'virtual-table-row-expand-icon-expanded'\n : 'virtual-table-row-expand-icon-collapsed',\n )}\n type=\"button\"\n aria-label={expanded ? '关闭行' : '展开行'}\n aria-expanded={expanded}\n onClick={() => {\n onUpdateExpansion(record, !expanded)\n }}\n />\n )\n },\n onHeaderCell() {\n return { className: 'virtual-table-expand-column' }\n },\n },\n ...rawColumns,\n ]\n }, [\n showExpandColumn,\n columnTitle,\n columnWidth,\n fixed,\n rawColumns,\n rowKey,\n rowExpandableRecord,\n expansion,\n expandIcon,\n onUpdateExpansion,\n extraColumnProps,\n ])\n\n const onRow: OnRowType<T> = useCallback((record, index) => {\n if (rowExpandableRecord[index]) {\n return {\n onClick: (e) => {\n e.stopPropagation()\n onUpdateExpansion(record)\n },\n }\n }\n return {}\n }, [rowExpandableRecord, onUpdateExpansion])\n\n if (disablePlugin) {\n return ctx\n }\n\n return {\n ...ctx,\n columns,\n renderRow,\n onRow: !expandRowByClick ? undefined : onRow,\n }\n}\n\nexport const tableExpandable = createMiddleware(useTableExpandable)\n"],"names":["ExpandRowHeightKey","ExpandRow","props","className","style","rowKey","isExpanded","colSpan","children","fixed","setRowHeightByRowKey","useTableRowManager","tableWidth","useContainerSize","_jsx","clsx","display","undefined","ref","node","offsetHeight","width","EXPANSION_COLUMN_KEY","isExpansionColumn","column","key","useTableExpandable","ctx","options","disablePlugin","columns","rawColumns","dataSource","defaultExpandedRowKeys","expandedRowRender","columnTitle","expandRowByClick","expandIcon","onExpand","defaultExpandAllRows","showExpandColumn","expandedRowClassName","rowExpandable","columnWidth","extraColumnProps","_rowExpandableValue","useMemo","map","row","rowExpandableRecord","useShallowMemo","defaultExpandAll","useRef","defaultExpandKey","current","expandKeys","record","index","filter","x","expansionKeys","Set","expansion","setExpansion","useControllableValue","trigger","valuePropName","defaultValue","onUpdateExpansion","useStableFn","rowData","shouldExpand","getRowKey","add","includes","isFixed","isValidFixed","renderRow","useCallback","args","rowIndex","columnDescriptor","isExpandable","isRendered","has","_jsxs","length","title","render","_value","expandable","expanded","prefixCls","_e","type","onClick","onHeaderCell","onRow","e","stopPropagation","tableExpandable","createMiddleware"],"mappings":";;;;;;AAcO,MAAMA,kBAAkB,GAAG;AAElC,MAAMC,SAAS,GAAwBC,KAAK,IAAI;EAC9C,MAAM;IACJC,SAAS;IACTC,KAAK;IACLC,MAAM;IACNC,UAAU;IACVC,OAAO;IACPC,QAAQ;AACRC,IAAAA;AACD,GAAA,GAAGP,KAAK;EAET,MAAM;AAAEQ,IAAAA;GAAsB,GAAGC,kBAAkB,EAAE;EACrD,MAAM;AAAEC,IAAAA;GAAY,GAAGC,gBAAgB,EAAE;EAEzC,OACEC,GAAA,CAAA,IAAA,EAAA;AACEX,IAAAA,SAAS,EAAEY,IAAI,CAAC,4BAA4B,EAAEZ,SAAS,CAAC;AACxDC,IAAAA,KAAK,EAAE;AAAE,MAAA,GAAGA,KAAK;AAAEY,MAAAA,OAAO,EAAEV,UAAU,GAAGW,SAAS,GAAG;KAAQ;IAC7DC,GAAG,EAAGC,IAAI,IAAI;AACZT,MAAAA,oBAAoB,CAACL,MAAM,EAAEL,kBAAkB,EAAE,MAAK;QACpD,IAAImB,IAAI,IAAI,IAAI,EAAE;QAClB,OAAOA,IAAI,CAACC,YAAY;AAC1B,OAAC,CAAC;KACH;cAEDN,GAAI,CAAA,IAAA,EAAA;AAAAP,MAAAA,OAAO,EAAEA,OAAO;AAAAC,MAAAA,QAAA,EAClBM;QACEX,SAAS,EAAEY,IAAI,CACb,oBAAoB,EACpBN,KAAK,IAAI,kCAAkC,CAC5C;AACDL,QAAAA,KAAK,EAAE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AAE;UACnB/B,iBAAiB,CAACZ,MAAM,CAAC;AAC3B;OACD;AACH;AACA,IAAA,OAAO,EAAE;AACX,GAAC,EAAE,CAACP,mBAAmB,EAAEmB,iBAAiB,CAAC,CAAC;AAE5C,EAAA,IAAIvC,aAAa,EAAE;AACjB,IAAA,OAAOF,GAAG;AACZ;EAEA,OAAO;AACL,IAAA,GAAGA,GAAG;IACNG,OAAO;IACP+C,SAAS;AACToB,IAAAA,KAAK,EAAE,CAAC7D,gBAAgB,GAAGnB,SAAS,GAAGgF;GACxC;AACH;MAEaG,eAAe,GAAGC,gBAAgB,CAAC3E,kBAAkB;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { getKey, useTableSticky, isValidFixedRight, isValidFixedLeft, isValidFixed,
|
|
2
|
+
import { getKey, useTableSticky, isValidFixedRight, isValidFixedLeft, isValidFixed, findLastIndex, createMiddleware, onResize } from '@are-visual/virtual-table';
|
|
3
3
|
import { memo, useState, useEffect, useMemo, isValidElement, cloneElement } from 'react';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
|
|
@@ -32,12 +32,8 @@ var LoadingCell$1 = /*#__PURE__*/memo(LoadingCell);
|
|
|
32
32
|
function LoadingRow(props) {
|
|
33
33
|
const {
|
|
34
34
|
descriptor,
|
|
35
|
-
style
|
|
36
|
-
rowKey
|
|
35
|
+
style
|
|
37
36
|
} = props;
|
|
38
|
-
const {
|
|
39
|
-
setRowHeightByRowKey
|
|
40
|
-
} = useTableRowManager();
|
|
41
37
|
const lastFixedLeftColumnIndex = findLastIndex(descriptor, x => {
|
|
42
38
|
if (x.type === 'blank') {
|
|
43
39
|
return false;
|
|
@@ -53,10 +49,6 @@ function LoadingRow(props) {
|
|
|
53
49
|
return jsx("tr", {
|
|
54
50
|
className: "virtual-table-row virtual-table-loading-cell",
|
|
55
51
|
style: style,
|
|
56
|
-
ref: node => {
|
|
57
|
-
if (node == null) return;
|
|
58
|
-
setRowHeightByRowKey(rowKey, 'loading-tr', node.offsetHeight);
|
|
59
|
-
},
|
|
60
52
|
children: descriptor.map((item, index) => {
|
|
61
53
|
const {
|
|
62
54
|
key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../packages/virtual-table/src/middleware/loading/cell.tsx","../../../../packages/virtual-table/src/middleware/loading/row.tsx","../../../../packages/virtual-table/src/middleware/loading/index.tsx"],"sourcesContent":["import type { ColumnType } from '@are-visual/virtual-table'\nimport type { ReactElement } from 'react'\nimport { getKey, isValidFixed, isValidFixedLeft, isValidFixedRight, useTableSticky } from '@are-visual/virtual-table'\nimport clsx from 'clsx'\nimport { memo } from 'react'\n\nexport interface CellProps<T> {\n className?: string\n column: ColumnType<T>\n}\n\nfunction LoadingCell<T>(props: CellProps<T>) {\n const { column, className } = props\n\n const { align, fixed } = column\n const key = getKey(column)\n const { size: stickySizes } = useTableSticky()\n\n return (\n <td\n className={clsx(\n 'virtual-table-cell',\n className,\n align != null && `virtual-table-align-${align}`,\n isValidFixed(fixed) && 'virtual-table-sticky-cell',\n )}\n style={{\n left: isValidFixedLeft(fixed) ? stickySizes.get(key) : undefined,\n right: isValidFixedRight(fixed) ? stickySizes.get(key) : undefined,\n }}\n >\n <div className=\"virtual-table-loading-skeleton\" />\n </td>\n )\n}\n\nexport default memo(LoadingCell) as <T>(props: CellProps<T>) => ReactElement\n","import type { ColumnDescriptor } from '@are-visual/virtual-table'\nimport type { CSSProperties, Key, ReactElement } from 'react'\nimport { findLastIndex, isValidFixedLeft, isValidFixedRight, useTableRowManager } from '@are-visual/virtual-table'\nimport clsx from 'clsx'\nimport { memo } from 'react'\nimport LoadingCell from './cell'\n\nexport interface RowProps<T> {\n style?: CSSProperties\n descriptor: ColumnDescriptor<T>[]\n rowKey: Key\n}\n\nfunction LoadingRow<T>(props: RowProps<T>) {\n const { descriptor, style, rowKey } = props\n\n const { setRowHeightByRowKey } = useTableRowManager()\n\n const lastFixedLeftColumnIndex = findLastIndex(descriptor, (x) => {\n if (x.type === 'blank') {\n return false\n }\n return isValidFixedLeft(x.column.fixed)\n })\n const firstFixedRightColumnIndex = descriptor.findIndex((x) => {\n if (x.type === 'blank') {\n return false\n }\n return isValidFixedRight(x.column.fixed)\n })\n\n return (\n <tr\n className=\"virtual-table-row virtual-table-loading-cell\"\n style={style}\n ref={(node) => {\n if (node == null) return\n setRowHeightByRowKey(rowKey, 'loading-tr', node.offsetHeight)\n }}\n >\n {descriptor.map((item, index) => {\n const { key } = item\n if (item.type === 'blank') {\n return <td key={key} />\n }\n const { column } = item\n return (\n <LoadingCell\n key={key}\n className={clsx(\n lastFixedLeftColumnIndex === index && 'virtual-table-cell-fix-left-last',\n firstFixedRightColumnIndex === index\n && 'virtual-table-cell-fix-right-first',\n )}\n column={column}\n />\n )\n })}\n </tr>\n )\n}\n\nexport default memo(LoadingRow) as <T>(props: RowProps<T>) => ReactElement\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MiddlewareContext, MiddlewareResult } from '@are-visual/virtual-table'\nimport type { CSSProperties, ReactElement } from 'react'\nimport { createMiddleware, onResize } from '@are-visual/virtual-table'\nimport { cloneElement, isValidElement, useEffect, useMemo, useState } from 'react'\nimport LoadingRow from './row'\n\nfunction useTableLoading<T = any>(\n ctx: MiddlewareContext<T>,\n options?: { loading?: boolean },\n): MiddlewareResult<T> {\n const { loading = false } = options ?? {}\n const { estimatedRowHeight, headerWrapperRef, getScroller } = ctx\n\n const [count, setCount] = useState(10)\n\n useEffect(() => {\n const header = headerWrapperRef.current\n const container = getScroller()\n if (container == null) return\n return onResize(container, ({ height }) => {\n const headerHeight = header?.offsetHeight ?? 0\n setCount(Math.ceil((height - headerHeight) / estimatedRowHeight))\n })\n }, [getScroller, headerWrapperRef, estimatedRowHeight])\n\n const fakeDataSource = useMemo(() => {\n return Array.from({ length: count }, (_, index) => {\n return { key: index }\n })\n }, [count])\n\n if (!loading) {\n return ctx\n }\n\n return {\n ...ctx,\n renderBodyRoot: (children) => {\n if (isValidElement(children)) {\n if (Object.prototype.hasOwnProperty.call(children.props, 'style')) {\n const style = (children.props as { style: CSSProperties }).style\n return cloneElement(children as ReactElement<{ style: CSSProperties }>, {\n style: {\n ...style,\n paddingBottom: undefined,\n paddingTop: undefined,\n },\n })\n }\n }\n return children\n },\n renderBodyContent: (_ignore, { columnDescriptor, startRowIndex }) => {\n return fakeDataSource.map((item, index) => {\n return (\n <LoadingRow\n key={item.key}\n style={{ height: estimatedRowHeight }}\n descriptor={columnDescriptor}\n rowKey={`__loading$-${index + startRowIndex}`}\n />\n )\n })\n },\n }\n}\n\nexport const tableLoading = createMiddleware(useTableLoading)\n"],"names":["LoadingCell","props","column","className","align","fixed","key","getKey","size","stickySizes","useTableSticky","_jsx","clsx","isValidFixed","style","left","isValidFixedLeft","get","undefined","right","isValidFixedRight","children","memo","LoadingRow","descriptor","rowKey","setRowHeightByRowKey","useTableRowManager","lastFixedLeftColumnIndex","findLastIndex","x","type","firstFixedRightColumnIndex","findIndex","ref","node","offsetHeight","map","item","index","useTableLoading","ctx","options","loading","estimatedRowHeight","headerWrapperRef","getScroller","count","setCount","useState","useEffect","header","current","container","onResize","_ref","height","headerHeight","Math","ceil","fakeDataSource","useMemo","Array","from","length","_","renderBodyRoot","isValidElement","Object","prototype","hasOwnProperty","call","cloneElement","paddingBottom","paddingTop","renderBodyContent","_ignore","_ref2","columnDescriptor","startRowIndex","tableLoading","createMiddleware"],"mappings":";;;;;AAWA,SAASA,WAAWA,CAAIC,KAAmB,EAAA;EACzC,MAAM;IAAEC,MAAM;AAAEC,IAAAA;AAAW,GAAA,GAAGF,KAAK;EAEnC,MAAM;IAAEG,KAAK;AAAEC,IAAAA;AAAO,GAAA,GAAGH,MAAM;AAC/B,EAAA,MAAMI,GAAG,GAAGC,MAAM,CAACL,MAAM,CAAC;EAC1B,MAAM;AAAEM,IAAAA,IAAI,EAAEC;GAAa,GAAGC,cAAc,EAAE;EAE9C,OAC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EvD,SAAS;AACxBwD,cAAAA,UAAU,EAAExD;AACb;AACF,WAAA,CAAC;AACJ;AACF;AACA,MAAA,OAAOG,QAAQ;KAChB;AACDsD,IAAAA,iBAAiB,EAAEA,CAACC,OAAO,EAAAC,KAAA,KAAyC;MAAA,IAAvC;QAAEC,gBAAgB;AAAEC,QAAAA;AAAe,OAAA,GAAAF,KAAA;MAC9D,OAAOjB,cAAc,CAACvB,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAI;QACxC,OACE5B,GAAA,CAACY,YAAU,EAAA;AAETT,UAAAA,KAAK,EAAE;AAAE0C,YAAAA,MAAM,EAAEZ;WAAoB;AACrCpB,UAAAA,UAAU,EAAEsD,gBAAgB;AAC5BrD,UAAAA,MAAM,EAAE,CAAA,WAAA,EAAcc,KAAK,GAAGwC,aAAa,CAAA;AAAE,SAAA,EAHxCzC,IAAI,CAAChC,GAAG,CAIb;AAEN,OAAC,CAAC;AACJ;GACD;AACH;MAEa0E,YAAY,GAAGC,gBAAgB,CAACzC,eAAe;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../packages/virtual-table/src/middleware/loading/cell.tsx","../../../../packages/virtual-table/src/middleware/loading/row.tsx","../../../../packages/virtual-table/src/middleware/loading/index.tsx"],"sourcesContent":["import type { ColumnType } from '@are-visual/virtual-table'\nimport type { ReactElement } from 'react'\nimport { getKey, isValidFixed, isValidFixedLeft, isValidFixedRight, useTableSticky } from '@are-visual/virtual-table'\nimport clsx from 'clsx'\nimport { memo } from 'react'\n\nexport interface CellProps<T> {\n className?: string\n column: ColumnType<T>\n}\n\nfunction LoadingCell<T>(props: CellProps<T>) {\n const { column, className } = props\n\n const { align, fixed } = column\n const key = getKey(column)\n const { size: stickySizes } = useTableSticky()\n\n return (\n <td\n className={clsx(\n 'virtual-table-cell',\n className,\n align != null && `virtual-table-align-${align}`,\n isValidFixed(fixed) && 'virtual-table-sticky-cell',\n )}\n style={{\n left: isValidFixedLeft(fixed) ? stickySizes.get(key) : undefined,\n right: isValidFixedRight(fixed) ? stickySizes.get(key) : undefined,\n }}\n >\n <div className=\"virtual-table-loading-skeleton\" />\n </td>\n )\n}\n\nexport default memo(LoadingCell) as <T>(props: CellProps<T>) => ReactElement\n","import type { ColumnDescriptor } from '@are-visual/virtual-table'\nimport type { CSSProperties, Key, ReactElement } from 'react'\nimport { findLastIndex, isValidFixedLeft, isValidFixedRight } from '@are-visual/virtual-table'\nimport clsx from 'clsx'\nimport { memo } from 'react'\nimport LoadingCell from './cell'\n\nexport interface RowProps<T> {\n style?: CSSProperties\n descriptor: ColumnDescriptor<T>[]\n rowKey: Key\n}\n\nfunction LoadingRow<T>(props: RowProps<T>) {\n const { descriptor, style } = props\n\n const lastFixedLeftColumnIndex = findLastIndex(descriptor, (x) => {\n if (x.type === 'blank') {\n return false\n }\n return isValidFixedLeft(x.column.fixed)\n })\n const firstFixedRightColumnIndex = descriptor.findIndex((x) => {\n if (x.type === 'blank') {\n return false\n }\n return isValidFixedRight(x.column.fixed)\n })\n\n return (\n <tr\n className=\"virtual-table-row virtual-table-loading-cell\"\n style={style}\n >\n {descriptor.map((item, index) => {\n const { key } = item\n if (item.type === 'blank') {\n return <td key={key} />\n }\n const { column } = item\n return (\n <LoadingCell\n key={key}\n className={clsx(\n lastFixedLeftColumnIndex === index && 'virtual-table-cell-fix-left-last',\n firstFixedRightColumnIndex === index\n && 'virtual-table-cell-fix-right-first',\n )}\n column={column}\n />\n )\n })}\n </tr>\n )\n}\n\nexport default memo(LoadingRow) as <T>(props: RowProps<T>) => ReactElement\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MiddlewareContext, MiddlewareResult } from '@are-visual/virtual-table'\nimport type { CSSProperties, ReactElement } from 'react'\nimport { createMiddleware, onResize } from '@are-visual/virtual-table'\nimport { cloneElement, isValidElement, useEffect, useMemo, useState } from 'react'\nimport LoadingRow from './row'\n\nfunction useTableLoading<T = any>(\n ctx: MiddlewareContext<T>,\n options?: { loading?: boolean },\n): MiddlewareResult<T> {\n const { loading = false } = options ?? {}\n const { estimatedRowHeight, headerWrapperRef, getScroller } = ctx\n\n const [count, setCount] = useState(10)\n\n useEffect(() => {\n const header = headerWrapperRef.current\n const container = getScroller()\n if (container == null) return\n return onResize(container, ({ height }) => {\n const headerHeight = header?.offsetHeight ?? 0\n setCount(Math.ceil((height - headerHeight) / estimatedRowHeight))\n })\n }, [getScroller, headerWrapperRef, estimatedRowHeight])\n\n const fakeDataSource = useMemo(() => {\n return Array.from({ length: count }, (_, index) => {\n return { key: index }\n })\n }, [count])\n\n if (!loading) {\n return ctx\n }\n\n return {\n ...ctx,\n renderBodyRoot: (children) => {\n if (isValidElement(children)) {\n if (Object.prototype.hasOwnProperty.call(children.props, 'style')) {\n const style = (children.props as { style: CSSProperties }).style\n return cloneElement(children as ReactElement<{ style: CSSProperties }>, {\n style: {\n ...style,\n paddingBottom: undefined,\n paddingTop: undefined,\n },\n })\n }\n }\n return children\n },\n renderBodyContent: (_ignore, { columnDescriptor, startRowIndex }) => {\n return fakeDataSource.map((item, index) => {\n return (\n <LoadingRow\n key={item.key}\n style={{ height: estimatedRowHeight }}\n descriptor={columnDescriptor}\n rowKey={`__loading$-${index + startRowIndex}`}\n />\n )\n })\n },\n }\n}\n\nexport const tableLoading = createMiddleware(useTableLoading)\n"],"names":["LoadingCell","props","column","className","align","fixed","key","getKey","size","stickySizes","useTableSticky","_jsx","clsx","isValidFixed","style","left","isValidFixedLeft","get","undefined","right","isValidFixedRight","children","memo","LoadingRow","descriptor","lastFixedLeftColumnIndex","findLastIndex","x","type","firstFixedRightColumnIndex","findIndex","map","item","index","useTableLoading","ctx","options","loading","estimatedRowHeight","headerWrapperRef","getScroller","count","setCount","useState","useEffect","header","current","container","onResize","_ref","height","headerHeight","offsetHeight","Math","ceil","fakeDataSource","useMemo","Array","from","length","_","renderBodyRoot","isValidElement","Object","prototype","hasOwnProperty","call","cloneElement","paddingBottom","paddingTop","renderBodyContent","_ignore","_ref2","columnDescri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