@are-visual/virtual-table 0.7.0 → 0.8.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.
@@ -2,6 +2,8 @@ import * as _are_visual_virtual_table from '@are-visual/virtual-table';
2
2
  import { FixedType, ColumnExtra, ColumnType } from '@are-visual/virtual-table';
3
3
  import { MouseEvent, ReactNode, Key } from 'react';
4
4
 
5
+ declare const ExpandRowHeightKey = "ExpandRow";
6
+
5
7
  type TriggerEventHandler<T> = (record: T, event: MouseEvent<HTMLElement>) => void;
6
8
  interface RenderExpandIconProps<T> {
7
9
  prefixCls: string;
@@ -30,9 +32,10 @@ interface ExpandableConfig<T> {
30
32
  fixed?: FixedType;
31
33
  extraColumnProps?: ColumnExtra;
32
34
  }
35
+
33
36
  declare const EXPANSION_COLUMN_KEY = "VirtualTable.EXPANSION_COLUMN";
34
37
  declare function isExpansionColumn<T = any>(column: ColumnType<T>): boolean;
35
38
  declare const tableExpandable: <T = any>(options?: ExpandableConfig<T> | undefined) => _are_visual_virtual_table.Middleware<T>;
36
39
 
37
- export { EXPANSION_COLUMN_KEY, isExpansionColumn, tableExpandable };
40
+ export { EXPANSION_COLUMN_KEY, ExpandRowHeightKey, isExpansionColumn, tableExpandable };
38
41
  export type { ExpandableConfig, ExpandedRowRender, RenderExpandIcon, RenderExpandIconProps, RowClassName };
@@ -4,18 +4,19 @@ import { useControllableValue } from '@are-visual/virtual-table/middleware/utils
4
4
  import clsx from 'clsx';
5
5
  import { useMemo, useRef, useCallback } from 'react';
6
6
 
7
+ const ExpandRowHeightKey = 'ExpandRow';
7
8
  const ExpandRow = props => {
8
9
  const {
9
10
  className,
10
11
  style,
11
- rowIndex,
12
+ rowKey,
12
13
  isExpanded,
13
14
  colSpan,
14
15
  children,
15
16
  fixed
16
17
  } = props;
17
18
  const {
18
- updateRowHeight
19
+ setRowHeightByRowKey
19
20
  } = useTableRowManager();
20
21
  const {
21
22
  tableWidth
@@ -28,7 +29,7 @@ const ExpandRow = props => {
28
29
  },
29
30
  ref: node => {
30
31
  if (node == null) return;
31
- updateRowHeight(rowIndex, `row(${rowIndex})-expandable`, node.offsetHeight);
32
+ setRowHeightByRowKey(rowKey, ExpandRowHeightKey, node.offsetHeight);
32
33
  },
33
34
  children: jsx("td", {
34
35
  colSpan: colSpan,
@@ -131,11 +132,11 @@ function useTableExpandable(ctx, options) {
131
132
  const {
132
133
  rowData,
133
134
  rowIndex,
135
+ rowKey: key,
134
136
  columnDescriptor
135
137
  } = args;
136
138
  const isExpandable = rowExpandableRecord[rowIndex];
137
139
  if (isExpandable) {
138
- const key = getRowKey(rowData, rowKey);
139
140
  const isExpanded = expansion.includes(key);
140
141
  const isRendered = expansionKeys.current.has(key);
141
142
  let className = '';
@@ -147,7 +148,7 @@ function useTableExpandable(ctx, options) {
147
148
  return jsxs(Fragment, {
148
149
  children: [children, isRendered && jsx(ExpandRow, {
149
150
  className: className,
150
- rowIndex: rowIndex,
151
+ rowKey: key,
151
152
  isExpanded: isExpanded,
152
153
  colSpan: columnDescriptor.length,
153
154
  fixed: isFixed,
@@ -156,7 +157,7 @@ function useTableExpandable(ctx, options) {
156
157
  });
157
158
  }
158
159
  return children;
159
- }, [isFixed, rowExpandableRecord, rowKey, expansion, expandedRowClassName, expandedRowRender]);
160
+ }, [isFixed, rowExpandableRecord, expansion, expandedRowClassName, expandedRowRender]);
160
161
  const columns = useMemo(() => {
161
162
  if (!showExpandColumn) {
162
163
  return rawColumns;
@@ -223,8 +224,7 @@ function useTableExpandable(ctx, options) {
223
224
  onRow: !expandRowByClick ? undefined : onRow
224
225
  };
225
226
  }
226
- /* eslint max-len: ["error", { "code": 120 }] */
227
227
  const tableExpandable = createMiddleware(useTableExpandable);
228
228
 
229
- export { EXPANSION_COLUMN_KEY, isExpansionColumn, tableExpandable };
229
+ export { EXPANSION_COLUMN_KEY, ExpandRowHeightKey, isExpansionColumn, tableExpandable };
230
230
  //# sourceMappingURL=index.js.map
@@ -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, 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 rowIndex: number\n isExpanded?: boolean\n colSpan?: number\n children?: ReactNode\n fixed?: boolean\n}\n\nconst ExpandRow: FC<ExpandRowProps> = (props) => {\n const {\n className,\n style,\n rowIndex,\n isExpanded,\n colSpan,\n children,\n fixed,\n } = props\n\n const { updateRowHeight } = 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 updateRowHeight(rowIndex, `row(${rowIndex})-expandable`, 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-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 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 | string\n fixed?: FixedType\n extraColumnProps?: ColumnExtra\n}\n\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, columnDescriptor } = args\n\n const isExpandable = rowExpandableRecord[rowIndex]\n if (isExpandable) {\n const key = getRowKey(rowData as T, rowKey)\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 rowIndex={rowIndex}\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 rowKey,\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\n/* eslint max-len: [\"error\", { \"code\": 120 }] */\nexport const tableExpandable = createMiddleware(useTableExpandable)\n"],"names":["ExpandRow","props","className","style","rowIndex","isExpanded","colSpan","children","fixed","updateRowHeight","useTableRowManager","tableWidth","useContainerSize","_jsx","clsx","display","undefined","ref","node","offsetHeight","width","EXPANSION_COLUMN_KEY","isExpansionColumn","column","key","useTableExpandable","ctx","options","disablePlugin","rowKey","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","columnDescriptor","isExpandable","isRendered","has","_jsxs","length","title","render","_value","expandable","expanded","prefixCls","_e","type","onClick","onHeaderCell","onRow","e","stopPropagation","tableExpandable","createMiddleware"],"mappings":";;;;;;AAcA,MAAMA,SAAS,GAAwBC,KAAK,IAAI;EAC9C,MAAM;IACJC,SAAS;IACTC,KAAK;IACLC,QAAQ;IACRC,UAAU;IACVC,OAAO;IACPC,QAAQ;AACRC,IAAAA;AACD,GAAA,GAAGP,KAAK;EAET,MAAM;AAAEQ,IAAAA;GAAiB,GAAGC,kBAAkB,EAAE;EAChD,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AA,YAAA,EAAAH,QAAQ,GAAG,KAAK,GAAG,KAAK;AAAA,UAAA,eAAA,EACrBA,QAAQ;UACvBI,OAAO,EAAEA,MAAK;AACZ1B,YAAAA,iBAAiB,CAACZ,MAAM,EAAE,CAACkC,QAAQ,CAAC;AACtC;AAAC,SAAA,CACD;OAEL;AACDK,MAAAA,YAAYA,GAAA;QACV,OAAO;AAAE7F,UAAAA,SAAS,EAAE;SAA+B;AACrD;KACD,EACD,GAAG6B,UAAU,CACd;GACF,EAAE,CACDS,gBAAgB,EAChBL,WAAW,EACXQ,WAAW,EACXnC,KAAK,EACLuB,UAAU,EACVF,MAAM,EACNoB,mBAAmB,EACnBa,SAAS,EACTzB,UAAU,EACV+B,iBAAiB,EACjBxB,gBAAgB,CACjB,CAAC;EAEF,MAAMoD,KAAK,GAAiBlB,WAAW,CAAC,CAACtB,MAAM,EAAEC,KAAK,KAAI;AACxD,IAAA,IAAIR,mBAAmB,CAACQ,KAAK,CAAC,EAAE;MAC9B,OAAO;QACLqC,OAAO,EAAGG,CAAC,IAAI;UACbA,CAAC,CAACC,eAAe,EAAE;UACnB9B,iBAAiB,CAACZ,MAAM,CAAC;AAC3B;OACD;AACH;AACA,IAAA,OAAO,EAAE;AACX,GAAC,EAAE,CAACP,mBAAmB,EAAEmB,iBAAiB,CAAC,CAAC;AAE5C,EAAA,IAAIxC,aAAa,EAAE;AACjB,IAAA,OAAOF,GAAG;AACZ;EAEA,OAAO;AACL,IAAA,GAAGA,GAAG;IACNI,OAAO;IACP+C,SAAS;AACTmB,IAAAA,KAAK,EAAE,CAAC5D,gBAAgB,GAAGpB,SAAS,GAAGgF;GACxC;AACH;AAEA;MACaG,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 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-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 | string\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,IAA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AACtC;AAAC,SAAA,CACD;OAEL;AACDK,MAAAA,YAAYA,GAAA;QACV,OAAO;AAAE7F,UAAAA,SAAS,EAAE;SAA+B;AACrD;KACD,EACD,GAAG4B,UAAU,CACd;GACF,EAAE,CACDS,gBAAgB,EAChBL,WAAW,EACXQ,WAAW,EACXlC,KAAK,EACLsB,UAAU,EACV1B,MAAM,EACN4C,mBAAmB,EACnBa,SAAS,EACTzB,UAAU,EACV+B,iBAAiB,EACjBxB,gBAAgB,CACjB,CAAC;EAEF,MAAMqD,KAAK,GAAiBnB,WAAW,CAAC,CAACtB,MAAM,EAAEC,KAAK,KAAI;AACxD,IAAA,IAAIR,mBAAmB,CAACQ,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,6 +1,6 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { getKey, useTableSticky, isValidFixedRight, isValidFixedLeft, isValidFixed, useTableRowManager, findLastIndex, createMiddleware, onResize } from '@are-visual/virtual-table';
3
- import { memo, useState, useEffect, useMemo } from 'react';
3
+ import { memo, useState, useEffect, useMemo, isValidElement, cloneElement } from 'react';
4
4
  import clsx from 'clsx';
5
5
 
6
6
  function LoadingCell(props) {
@@ -33,10 +33,10 @@ function LoadingRow(props) {
33
33
  const {
34
34
  descriptor,
35
35
  style,
36
- rowIndex
36
+ rowKey
37
37
  } = props;
38
38
  const {
39
- updateRowHeight
39
+ setRowHeightByRowKey
40
40
  } = useTableRowManager();
41
41
  const lastFixedLeftColumnIndex = findLastIndex(descriptor, x => {
42
42
  if (x.type === 'blank') {
@@ -55,7 +55,7 @@ function LoadingRow(props) {
55
55
  style: style,
56
56
  ref: node => {
57
57
  if (node == null) return;
58
- updateRowHeight(rowIndex, rowIndex, node.offsetHeight);
58
+ setRowHeightByRowKey(rowKey, 'loading-tr', node.offsetHeight);
59
59
  },
60
60
  children: descriptor.map((item, index) => {
61
61
  const {
@@ -76,7 +76,6 @@ function LoadingRow(props) {
76
76
  }
77
77
  var LoadingRow$1 = /*#__PURE__*/memo(LoadingRow);
78
78
 
79
- const EMPTY_ARR = [];
80
79
  function useTableLoading(ctx, options) {
81
80
  const {
82
81
  loading = false
@@ -113,7 +112,21 @@ function useTableLoading(ctx, options) {
113
112
  }
114
113
  return {
115
114
  ...ctx,
116
- dataSource: EMPTY_ARR,
115
+ renderBodyRoot: children => {
116
+ if (/*#__PURE__*/isValidElement(children)) {
117
+ if (Object.prototype.hasOwnProperty.call(children.props, 'style')) {
118
+ const style = children.props.style;
119
+ return /*#__PURE__*/cloneElement(children, {
120
+ style: {
121
+ ...style,
122
+ paddingBottom: undefined,
123
+ paddingTop: undefined
124
+ }
125
+ });
126
+ }
127
+ }
128
+ return children;
129
+ },
117
130
  renderBodyContent: (_ignore, _ref2) => {
118
131
  let {
119
132
  columnDescriptor,
@@ -125,7 +138,7 @@ function useTableLoading(ctx, options) {
125
138
  height: estimatedRowHeight
126
139
  },
127
140
  descriptor: columnDescriptor,
128
- rowIndex: index + startRowIndex
141
+ rowKey: `__loading$-${index + startRowIndex}`
129
142
  }, item.key);
130
143
  });
131
144
  }
@@ -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, 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 rowIndex: number\n}\n\nfunction LoadingRow<T>(props: RowProps<T>) {\n const { descriptor, style, rowIndex } = props\n\n const { updateRowHeight } = 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 updateRowHeight(rowIndex, rowIndex, 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 { createMiddleware, onResize } from '@are-visual/virtual-table'\nimport { useEffect, useMemo, useState } from 'react'\nimport LoadingRow from './row'\n\nconst EMPTY_ARR: unknown[] = []\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 dataSource: EMPTY_ARR as T[],\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 rowIndex={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","rowIndex","updateRowHeight","useTableRowManager","lastFixedLeftColumnIndex","findLastIndex","x","type","firstFixedRightColumnIndex","findIndex","ref","node","offsetHeight","map","item","index","EMPTY_ARR","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","_","dataSource","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,OACEC,GACE,CAAA,IAAA,EAAA;IAAAR,SAAS,EAAES,IAAI,CACb,oBAAoB,EACpBT,SAAS,EACTC,KAAK,IAAI,IAAI,IAAI,CAAuBA,oBAAAA,EAAAA,KAAK,EAAE,EAC/CS,YAAY,CAACR,KAAK,CAAC,IAAI,2BAA2B,CACnD;AACDS,IAAAA,KAAK,EAAE;AACLC,MAAAA,IAAI,EAAEC,gBAAgB,CAACX,KAAK,CAAC,GAAGI,WAAW,CAACQ,GAAG,CAACX,GAAG,CAAC,GAAGY,SAAS;AAChEC,MAAAA,KAAK,EAAEC,iBAAiB,CAACf,KAAK,CAAC,GAAGI,WAAW,CAACQ,GAAG,CAACX,GAAG,CAAC,GAAGY;KAC1D;AAAAG,IAAAA,QAAA,EAEDV;AAAKR,MAAAA,SAAS,EAAC;KAAmC;AAAA,GAAA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gB,cAAc,GAAGC,OAAO,CAAC,MAAK;IAClC,OAAOC,KAAK,CAACC,IAAI,CAAC;AAAEC,MAAAA,MAAM,EAAEjB;AAAK,KAAE,EAAE,CAACkB,CAAC,EAAE3B,KAAK,KAAI;MAChD,OAAO;AAAEjC,QAAAA,GAAG,EAAEiC;OAAO;AACvB,KAAC,CAAC;AACJ,GAAC,EAAE,CAACS,KAAK,CAAC,CAAC;EAEX,IAAI,CAACJ,OAAO,EAAE;AACZ,IAAA,OAAOF,GAAG;AACZ;EAEA,OAAO;AACL,IAAA,GAAGA,GAAG;AACNyB,IAAAA,UAAU,EAAE3B,SAAgB;AAC5B4B,IAAAA,iBAAiB,EAAEA,CAACC,OAAO,EAAAC,KAAA,KAAyC;MAAA,IAAvC;QAAEC,gBAAgB;AAAEC,QAAAA;AAAe,OAAA,GAAAF,KAAA;MAC9D,OAAOT,cAAc,CAACxB,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAI;QACxC,OACE5B,GAAC,CAAAY,YAAU,EAET;AAAAT,UAAAA,KAAK,EAAE;AAAE2C,YAAAA,MAAM,EAAEZ;WAAoB;AACrCrB,UAAAA,UAAU,EAAE+C,gBAAgB;UAC5B9C,QAAQ,EAAEc,KAAK,GAAGiC;AAHb,SAAA,EAAAlC,IAAI,CAAChC,GAAG,CAIb;AAEN,OAAC,CAAC;AACJ;GACD;AACH;MAEamE,YAAY,GAAGC,gBAAgB,CAACjC,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, 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,OACEC,GACE,CAAA,IAAA,EAAA;IAAAR,SAAS,EAAES,IAAI,CACb,oBAAoB,EACpBT,SAAS,EACTC,KAAK,IAAI,IAAI,IAAI,CAAuBA,oBAAAA,EAAAA,KAAK,EAAE,EAC/CS,YAAY,CAACR,KAAK,CAAC,IAAI,2BAA2B,CACnD;AACDS,IAAAA,KAAK,EAAE;AACLC,MAAAA,IAAI,EAAEC,gBAAgB,CAACX,KAAK,CAAC,GAAGI,WAAW,CAACQ,GAAG,CAACX,GAAG,CAAC,GAAGY,SAAS;AAChEC,MAAAA,KAAK,EAAEC,iBAAiB,CAACf,KAAK,CAAC,GAAGI,WAAW,CAACQ,GAAG,CAACX,GAAG,CAAC,GAAGY;KAC1D;AAAAG,IAAAA,QAAA,EAEDV;AAAKR,M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AA,EAAcc,KAAK,GAAGwC,aAAa,CAAA;AAAE,SAAA,EAHxCzC,IAAI,CAAChC,GAAG,CAIb;AAEN,OAAC,CAAC;AACJ;GACD;AACH;MAEa0E,YAAY,GAAGC,gBAAgB,CAACzC,eAAe;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@are-visual/virtual-table",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "main": "./index.esm.js",
5
5
  "types": "./index.d.ts",
6
6
  "sideEffects": false,