{}}
- />
- );
- },
-
- renderRows(renderRows, rows, record, index, indent, fixed, parentKey, ancestorKeys) {
- const { expandedRowClassName, expandedRowRender, childrenColumnName } = this;
- const childrenData = record[childrenColumnName];
- const nextAncestorKeys = [...ancestorKeys, parentKey];
- const nextIndent = indent + 1;
-
- if (expandedRowRender) {
- rows.push(
- this.renderExpandedRow(
- record,
- index,
- expandedRowRender,
- expandedRowClassName(record, index, indent),
- nextAncestorKeys,
- nextIndent,
- fixed,
- ),
- );
- }
-
- if (childrenData) {
- rows.push(...renderRows(childrenData, nextIndent, nextAncestorKeys));
- }
- },
- },
-
- render() {
- const { data, childrenColumnName } = this;
- const props = getOptionProps(this);
- const needIndentSpaced = data.some(record => record[childrenColumnName]);
-
- return getSlot(this, 'default', {
- props: {
- ...props,
- ...this.$attrs,
- },
- needIndentSpaced,
- renderRows: this.renderRows,
- handleExpandChange: this.handleExpandChange,
- renderExpandIndentCell: this.renderExpandIndentCell,
- });
- },
-};
-
-export default ExpandableTable;
diff --git a/components/legacy-table/src/HeadTable.jsx b/components/legacy-table/src/HeadTable.jsx
deleted file mode 100644
index b5b6d765f..000000000
--- a/components/legacy-table/src/HeadTable.jsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import { inject } from 'vue';
-import PropTypes, { withUndefined } from '../../_util/vue-types';
-import { measureScrollbar } from './utils';
-import BaseTable from './BaseTable';
-import classNames from '../../_util/classNames';
-
-export default {
- name: 'HeadTable',
- inheritAttrs: false,
- props: {
- fixed: withUndefined(PropTypes.oneOfType([PropTypes.string, PropTypes.looseBool])),
- columns: PropTypes.array.isRequired,
- tableClassName: PropTypes.string.isRequired,
- handleBodyScrollLeft: PropTypes.func.isRequired,
- expander: PropTypes.object.isRequired,
- },
- setup() {
- return {
- table: inject('table', {}),
- };
- },
- render() {
- const { columns, fixed, tableClassName, handleBodyScrollLeft, expander, table } = this;
- const { prefixCls, scroll, showHeader, saveRef } = table;
- let { useFixedHeader } = table;
- const headStyle = {};
-
- const scrollbarWidth = measureScrollbar({ direction: 'vertical' });
-
- if (scroll.y) {
- useFixedHeader = true;
- // https://github.com/ant-design/ant-design/issues/17051
- const scrollbarWidthOfHeader = measureScrollbar({ direction: 'horizontal', prefixCls });
- // Add negative margin bottom for scroll bar overflow bug
- if (scrollbarWidthOfHeader > 0 && !fixed) {
- headStyle.marginBottom = `-${scrollbarWidthOfHeader}px`;
- headStyle.paddingBottom = '0px';
- // https://github.com/ant-design/ant-design/pull/19986
- headStyle.minWidth = `${scrollbarWidth}px`;
- // https://github.com/ant-design/ant-design/issues/17051
- headStyle.overflowX = 'scroll';
- headStyle.overflowY = scrollbarWidth === 0 ? 'hidden' : 'scroll';
- }
- }
-
- if (!useFixedHeader || !showHeader) {
- return null;
- }
- return (
- {} : saveRef('headTable')}
- class={classNames(`${prefixCls}-header`, {
- [`${prefixCls}-hide-scrollbar`]: scrollbarWidth > 0,
- })}
- style={headStyle}
- onScroll={handleBodyScrollLeft}
- >
-
-
- );
- },
-};
diff --git a/components/legacy-table/src/Table.jsx b/components/legacy-table/src/Table.jsx
deleted file mode 100644
index 19d0d6acc..000000000
--- a/components/legacy-table/src/Table.jsx
+++ /dev/null
@@ -1,611 +0,0 @@
-/* eslint-disable camelcase */
-import {
- provide,
- markRaw,
- defineComponent,
- nextTick,
- reactive,
- computed,
- ref,
- onUpdated,
- onMounted,
- toRef,
-} from 'vue';
-import shallowequal from '../../_util/shallowequal';
-import merge from 'lodash-es/merge';
-import classes from '../../_util/component-classes';
-import classNames from '../../_util/classNames';
-import PropTypes from '../../_util/vue-types';
-import { debounce, getColumnsKey, getDataAndAriaProps, validateValue } from './utils';
-import warning from '../../_util/warning';
-import addEventListener from '../../vc-util/Dom/addEventListener';
-import HeadTable from './HeadTable';
-import BodyTable from './BodyTable';
-import ExpandableTable from './ExpandableTable';
-import { initDefaultProps, getOptionProps } from '../../_util/props-util';
-import BaseMixin from '../../_util/BaseMixin';
-import { useLayoutState } from '../../_util/hooks/useLayoutState';
-import useColumnManager from './useColumnManager';
-import useStickyOffsets from './useStickyOffsets';
-import { getCellFixedInfo } from './fixUtil';
-import ResizeObserver from '../../vc-resize-observer';
-
-export default defineComponent({
- name: 'Table',
- mixins: [BaseMixin],
- inheritAttrs: false,
- props: initDefaultProps(
- {
- data: PropTypes.array,
- useFixedHeader: PropTypes.looseBool,
- columns: PropTypes.array,
- prefixCls: PropTypes.string,
- bodyStyle: PropTypes.object,
- rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
- rowClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
- customRow: PropTypes.func,
- customHeaderRow: PropTypes.func,
- // onRowClick: PropTypes.func,
- // onRowDoubleClick: PropTypes.func,
- // onRowContextMenu: PropTypes.func,
- // onRowMouseEnter: PropTypes.func,
- // onRowMouseLeave: PropTypes.func,
- showHeader: PropTypes.looseBool,
- title: PropTypes.func,
- id: PropTypes.string,
- footer: PropTypes.func,
- emptyText: PropTypes.any,
- scroll: PropTypes.object,
- rowRef: PropTypes.func,
- // getBodyWrapper: PropTypes.func,
- components: PropTypes.shape({
- table: PropTypes.any,
- header: PropTypes.shape({
- wrapper: PropTypes.any,
- row: PropTypes.any,
- cell: PropTypes.any,
- }).loose,
- body: PropTypes.shape({
- wrapper: PropTypes.any,
- row: PropTypes.any,
- cell: PropTypes.any,
- }).loose,
- }).loose,
- expandIconAsCell: PropTypes.looseBool,
- expandedRowKeys: PropTypes.array,
- expandedRowClassName: PropTypes.func,
- defaultExpandAllRows: PropTypes.looseBool,
- defaultExpandedRowKeys: PropTypes.array,
- expandIconColumnIndex: PropTypes.number,
- expandedRowRender: PropTypes.func,
- childrenColumnName: PropTypes.string,
- indentSize: PropTypes.number,
- expandRowByClick: PropTypes.looseBool,
- expandIcon: PropTypes.func,
- tableLayout: PropTypes.string,
- transformCellText: PropTypes.func,
- },
- {
- data: [],
- useFixedHeader: false,
- rowKey: 'key',
- rowClassName: () => '',
- prefixCls: 'rc-table',
- bodyStyle: {},
- showHeader: true,
- scroll: {},
- rowRef: () => null,
- emptyText: () => 'No Data',
- customHeaderRow: () => {},
- },
- ),
- setup(props) {
- const columnManager = useColumnManager(toRef(props, 'columns'));
- const colsKeys = computed(() => getColumnsKey(columnManager.leafColumns.value));
- const [colsWidths, updateColsWidths] = useLayoutState(new Map());
- const pureColWidths = computed(() =>
- colsKeys.value.map(columnKey => colsWidths.value.get(columnKey)),
- );
- const stickyOffsets = useStickyOffsets(pureColWidths, columnManager.leafColumns);
- const onColumnResize = (columnKey, width) => {
- updateColsWidths(widths => {
- if (widths.get(columnKey) !== width) {
- const newWidths = new Map(widths);
- newWidths.set(columnKey, width);
- return newWidths;
- }
- return widths;
- });
- };
- const fixedInfoList = computed(() =>
- columnManager.leafColumns.value.map((_, colIndex) =>
- getCellFixedInfo(colIndex, colIndex, columnManager.leafColumns.value, stickyOffsets.value),
- ),
- );
- const store = reactive({
- currentHoverKey: null,
- fixedColumnsHeadRowsHeight: [],
- fixedColumnsBodyRowsHeight: {},
- expandedRowsHeight: {},
- expandedRowKeys: [],
- columnManager,
- fixedInfoList,
- stickyOffsets,
- });
- provide('table-store', store);
- const bodyRef = ref();
- const pingedLeft = ref(false);
- const pingedRight = ref(false);
- const horizonScroll = computed(() => props.scroll && validateValue(props.scroll.x));
- const onScroll = currentTarget => {
- const { scrollWidth, clientWidth, scrollLeft } = currentTarget;
- pingedLeft.value = scrollLeft > 0;
- pingedRight.value = scrollLeft < scrollWidth - clientWidth;
- };
- onUpdated(() => {
- nextTick(() => {
- horizonScroll.value && onScroll(bodyRef.value.$el);
- });
- });
- onMounted(() => {
- nextTick(() => {
- horizonScroll.value && onScroll(bodyRef.value.$el);
- });
- });
- const onFullTableResize = () => {
- horizonScroll.value && onScroll(bodyRef.value.$el);
- };
- return {
- bodyRef,
- store,
- onColumnResize,
- columnManager,
- onScroll,
- pingedLeft,
- pingedRight,
- onFullTableResize,
- };
- },
- data() {
- this.preData = [...this.data];
- return {
- sComponents: markRaw(
- merge(
- {
- table: 'table',
- header: {
- wrapper: 'thead',
- row: 'tr',
- cell: 'th',
- },
- body: {
- wrapper: 'tbody',
- row: 'tr',
- cell: 'td',
- },
- },
- this.components,
- ),
- ),
- };
- },
- computed: {
- dataLen() {
- return this.$props.data.length;
- },
- },
- watch: {
- components() {
- this._components = merge(
- {
- table: 'table',
- header: {
- wrapper: 'thead',
- row: 'tr',
- cell: 'th',
- },
- body: {
- wrapper: 'tbody',
- row: 'tr',
- cell: 'td',
- },
- },
- this.components,
- );
- },
- dataLen(val, preVal) {
- if ((val === 0 || preVal === 0) && this.hasScrollX()) {
- nextTick(() => {
- this.resetScrollX();
- });
- }
- },
- },
- created() {
- provide('table', this);
-
- this.setScrollPosition('left');
-
- this.debouncedWindowResize = debounce(this.handleWindowResize, 150);
- },
-
- mounted() {
- this.$nextTick(() => {
- if (this.columnManager.isAnyColumnsFixed.value) {
- this.handleWindowResize();
- this.resizeEvent = addEventListener(window, 'resize', this.debouncedWindowResize);
- }
- // https://github.com/ant-design/ant-design/issues/11635
- if (this.ref_headTable) {
- this.ref_headTable.scrollLeft = 0;
- }
- if (this.ref_bodyTable) {
- this.ref_bodyTable.scrollLeft = 0;
- }
- });
- },
-
- updated() {
- this.$nextTick(() => {
- if (this.columnManager.isAnyColumnsFixed.value) {
- this.handleWindowResize();
- if (!this.resizeEvent) {
- this.resizeEvent = addEventListener(window, 'resize', this.debouncedWindowResize);
- }
- }
- });
- },
-
- beforeUnmount() {
- if (this.resizeEvent) {
- this.resizeEvent.remove();
- }
- if (this.debouncedWindowResize) {
- this.debouncedWindowResize.cancel();
- }
- },
- methods: {
- getRowKey(record, index) {
- const rowKey = this.rowKey;
- const key = typeof rowKey === 'function' ? rowKey(record, index) : record[rowKey];
- warning(
- key !== undefined,
- 'Each record in table should have a unique `key` prop,' +
- 'or set `rowKey` to an unique primary key.',
- );
- return key === undefined ? index : key;
- },
-
- setScrollPosition(position) {
- this.scrollPosition = position;
- if (this.tableNode) {
- const { prefixCls } = this;
- if (position === 'both') {
- classes(this.tableNode)
- .remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
- .add(`${prefixCls}-scroll-position-left`)
- .add(`${prefixCls}-scroll-position-right`);
- } else {
- classes(this.tableNode)
- .remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
- .add(`${prefixCls}-scroll-position-${position}`);
- }
- }
- },
-
- setScrollPositionClassName() {
- const node = this.ref_bodyTable;
- const scrollToLeft = node.scrollLeft === 0;
- const scrollToRight =
- node.scrollLeft + 1 >=
- node.children[0].getBoundingClientRect().width - node.getBoundingClientRect().width;
- if (scrollToLeft && scrollToRight) {
- this.setScrollPosition('both');
- } else if (scrollToLeft) {
- this.setScrollPosition('left');
- } else if (scrollToRight) {
- this.setScrollPosition('right');
- } else if (this.scrollPosition !== 'middle') {
- this.setScrollPosition('middle');
- }
- },
-
- isTableLayoutFixed() {
- const { tableLayout, columns = [], useFixedHeader, scroll = {} } = this.$props;
- if (typeof tableLayout !== 'undefined') {
- return tableLayout === 'fixed';
- }
- // if one column is ellipsis, use fixed table layout to fix align issue
- if (columns.some(({ ellipsis }) => !!ellipsis)) {
- return true;
- }
- // if header fixed, use fixed table layout to fix align issue
- if (useFixedHeader || scroll.y) {
- return true;
- }
- // if scroll.x is number/px/% width value, we should fixed table layout
- // to avoid long word layout broken issue
- if (scroll.x && scroll.x !== true && scroll.x !== 'max-content') {
- return true;
- }
- return false;
- },
-
- handleWindowResize() {
- this.syncFixedTableRowHeight();
- this.setScrollPositionClassName();
- },
-
- syncFixedTableRowHeight() {
- const tableRect = this.tableNode.getBoundingClientRect();
- // If tableNode's height less than 0, suppose it is hidden and don't recalculate rowHeight.
- // see: https://github.com/ant-design/ant-design/issues/4836
- if (tableRect.height !== undefined && tableRect.height <= 0) {
- return;
- }
- const { prefixCls } = this;
- const headRows = this.ref_headTable
- ? this.ref_headTable.querySelectorAll('thead')
- : this.ref_bodyTable.querySelectorAll('thead');
- const bodyRows = this.ref_bodyTable.querySelectorAll(`.${prefixCls}-row`) || [];
- const fixedColumnsHeadRowsHeight = [].map.call(headRows, row => {
- return row.getBoundingClientRect().height
- ? row.getBoundingClientRect().height - 0.5
- : 'auto';
- });
- const state = this.store;
- const fixedColumnsBodyRowsHeight = [].reduce.call(
- bodyRows,
- (acc, row) => {
- const rowKey = row.getAttribute('data-row-key');
- const height =
- row.getBoundingClientRect().height ||
- state.fixedColumnsBodyRowsHeight[rowKey] ||
- 'auto';
- acc[rowKey] = height;
- return acc;
- },
- {},
- );
- if (
- shallowequal(state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) &&
- shallowequal(state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight)
- ) {
- return;
- }
- this.store.fixedColumnsHeadRowsHeight = fixedColumnsHeadRowsHeight;
- this.store.fixedColumnsBodyRowsHeight = fixedColumnsBodyRowsHeight;
- },
-
- resetScrollX() {
- if (this.ref_headTable) {
- this.ref_headTable.scrollLeft = 0;
- }
- if (this.ref_bodyTable) {
- this.ref_bodyTable.scrollLeft = 0;
- }
- },
-
- hasScrollX() {
- const { scroll = {} } = this;
- return 'x' in scroll;
- },
-
- handleBodyScrollLeft(e) {
- const target = e.target;
- const { scroll = {} } = this;
- const { ref_headTable, ref_bodyTable } = this;
- if (target.scrollLeft !== this.lastScrollLeft && scroll.x) {
- if (target === ref_bodyTable && ref_headTable) {
- ref_headTable.scrollLeft = target.scrollLeft;
- } else if (target === ref_headTable && ref_bodyTable) {
- ref_bodyTable.scrollLeft = target.scrollLeft;
- }
- this.setScrollPositionClassName();
- }
- // Remember last scrollLeft for scroll direction detecting.
- this.lastScrollLeft = target.scrollLeft;
- },
-
- handleBodyScrollTop(e) {
- const target = e.target;
- // Fix https://github.com/ant-design/ant-design/issues/9033
- if (e.currentTarget !== target) {
- return;
- }
- const { scroll = {} } = this;
- const { ref_headTable, ref_bodyTable, ref_fixedColumnsBodyLeft, ref_fixedColumnsBodyRight } =
- this;
- if (target.scrollTop !== this.lastScrollTop && scroll.y && target !== ref_headTable) {
- const scrollTop = target.scrollTop;
- if (ref_fixedColumnsBodyLeft && target !== ref_fixedColumnsBodyLeft) {
- ref_fixedColumnsBodyLeft.scrollTop = scrollTop;
- }
- if (ref_fixedColumnsBodyRight && target !== ref_fixedColumnsBodyRight) {
- ref_fixedColumnsBodyRight.scrollTop = scrollTop;
- }
- if (ref_bodyTable && target !== ref_bodyTable) {
- ref_bodyTable.scrollTop = scrollTop;
- }
- }
- // Remember last scrollTop for scroll direction detecting.
- this.lastScrollTop = target.scrollTop;
- },
- handleBodyScroll(e) {
- this.onScroll(e.target);
- this.handleBodyScrollLeft(e);
- this.handleBodyScrollTop(e);
- },
- handleWheel(event) {
- const { scroll = {} } = this.$props;
- if (window.navigator.userAgent.match(/Trident\/7\./) && scroll.y) {
- event.preventDefault();
- const wd = event.deltaY;
- const target = event.target;
- const {
- ref_bodyTable: bodyTable,
- ref_fixedColumnsBodyLeft: fixedColumnsBodyLeft,
- ref_fixedColumnsBodyRight: fixedColumnsBodyRight,
- } = this;
- let scrollTop = 0;
-
- if (this.lastScrollTop) {
- scrollTop = this.lastScrollTop + wd;
- } else {
- scrollTop = wd;
- }
-
- if (fixedColumnsBodyLeft && target !== fixedColumnsBodyLeft) {
- fixedColumnsBodyLeft.scrollTop = scrollTop;
- }
- if (fixedColumnsBodyRight && target !== fixedColumnsBodyRight) {
- fixedColumnsBodyRight.scrollTop = scrollTop;
- }
- if (bodyTable && target !== bodyTable) {
- bodyTable.scrollTop = scrollTop;
- }
- }
- },
- // saveChildrenRef(name, node) {
- // this[`ref_${name}`] = node;
- // },
- saveRef(name) {
- return node => {
- this[`ref_${name}`] = node;
- };
- },
-
- saveTableNodeRef(node) {
- this.tableNode = node;
- },
- renderMainTable() {
- const { scroll, prefixCls } = this;
- const isAnyColumnsFixed = this.columnManager.isAnyColumnsFixed.value;
- const scrollable = isAnyColumnsFixed || scroll.x || scroll.y;
-
- const table = [
- this.renderTable({
- columns: this.columnManager.groupedColumns.value,
- isAnyColumnsFixed,
- }),
- this.renderEmptyText(),
- this.renderFooter(),
- ];
-
- return scrollable ? (
-
- {table}
-
- ) : (
- table
- );
- },
-
- renderTable(options) {
- const { columns, isAnyColumnsFixed } = options;
- const { prefixCls, scroll = {} } = this;
- const tableClassName = scroll.x ? `${prefixCls}-fixed` : '';
-
- const headTable = (
-
- );
-
- const bodyTable = (
-
- );
-
- return [headTable, bodyTable];
- },
-
- renderTitle() {
- const { title, prefixCls, data } = this;
- return title ? (
-
- {title(data)}
-
- ) : null;
- },
-
- renderFooter() {
- const { footer, prefixCls, data } = this;
- return footer ? (
-
- ) : null;
- },
-
- renderEmptyText() {
- const { emptyText, prefixCls, data } = this;
- if (data.length) {
- return null;
- }
- const emptyClassName = `${prefixCls}-placeholder`;
- return (
-
- {typeof emptyText === 'function' ? emptyText() : emptyText}
-
- );
- },
- },
-
- render() {
- const props = { ...getOptionProps(this), ...this.$attrs };
- const { columnManager, getRowKey } = this;
- const prefixCls = props.prefixCls;
-
- const tableClassName = classNames(props.prefixCls, props.class, {
- [`${prefixCls}-fixed-header`]: props.useFixedHeader || (props.scroll && props.scroll.y),
- [`${prefixCls}-scroll-position-left ${prefixCls}-scroll-position-right`]:
- this.scrollPosition === 'both',
- [`${prefixCls}-scroll-position-${this.scrollPosition}`]: this.scrollPosition !== 'both',
- [`${prefixCls}-layout-fixed`]: this.isTableLayoutFixed(),
- [`${prefixCls}-ping-left`]: this.pingedLeft,
- [`${prefixCls}-ping-right`]: this.pingedRight,
- });
- const dataAndAriaProps = getDataAndAriaProps(props);
- const expandableTableProps = {
- ...props,
- columnManager,
- getRowKey,
- };
- return (
- {
- this.expander = expander;
- return (
-
- {this.renderTitle()}
-
{this.renderMainTable()}
-
- );
- },
- }}
- />
- );
- },
-});
diff --git a/components/legacy-table/src/TableCell.jsx b/components/legacy-table/src/TableCell.jsx
deleted file mode 100644
index 71280e379..000000000
--- a/components/legacy-table/src/TableCell.jsx
+++ /dev/null
@@ -1,162 +0,0 @@
-import { inject, toRaw } from 'vue';
-import PropTypes from '../../_util/vue-types';
-import get from 'lodash-es/get';
-import classNames from '../../_util/classNames';
-import { isValidElement } from '../../_util/props-util';
-
-function isInvalidRenderCellText(text) {
- return (
- text && !isValidElement(text) && Object.prototype.toString.call(text) === '[object Object]'
- );
-}
-
-export default {
- name: 'TableCell',
- inheritAttrs: false,
- props: {
- record: PropTypes.object,
- prefixCls: PropTypes.string,
- index: PropTypes.number,
- indent: PropTypes.number,
- indentSize: PropTypes.number,
- column: PropTypes.object,
- expandIcon: PropTypes.any,
- component: PropTypes.any,
- colIndex: PropTypes.number,
- },
- setup() {
- return {
- table: inject('table', {}),
- store: inject('table-store', {}),
- };
- },
- methods: {
- handleClick(e) {
- const {
- record,
- column: { onCellClick },
- } = this;
- if (onCellClick) {
- onCellClick(record, e);
- }
- },
- },
-
- render() {
- const {
- record,
- indentSize,
- prefixCls,
- indent,
- index,
- expandIcon,
- column,
- component: BodyCell,
- } = this;
- const fixedInfoList = this.store.fixedInfoList || [];
- const fixedInfo = fixedInfoList[this.colIndex] || {};
- const { fixLeft, fixRight, firstFixLeft, lastFixLeft, firstFixRight, lastFixRight } = fixedInfo;
- // ====================== Fixed =======================
- const fixedStyle = {};
- const isFixLeft = typeof fixLeft === 'number';
- const isFixRight = typeof fixRight === 'number';
-
- if (isFixLeft) {
- fixedStyle.position = 'sticky';
- fixedStyle.left = `${fixLeft}px`;
- }
- if (isFixRight) {
- fixedStyle.position = 'sticky';
- fixedStyle.right = `${fixRight}px`;
- }
- const { dataIndex, customRender, className = '' } = column;
- const { transformCellText, prefixCls: rootPrefixCls } = this.table;
- // We should return undefined if no dataIndex is specified, but in order to
- // be compatible with object-path's behavior, we return the record object instead.
- let text;
- if (typeof dataIndex === 'number') {
- text = get(record, dataIndex);
- } else if (!dataIndex || dataIndex.length === 0) {
- text = record;
- } else {
- text = get(record, dataIndex);
- }
- let tdProps = {
- onClick: this.handleClick,
- };
- let colSpan;
- let rowSpan;
-
- if (customRender) {
- text = customRender({ text, record, index, column });
- if (isInvalidRenderCellText(text)) {
- tdProps = text.props || text.attrs || tdProps;
- ({ colSpan, rowSpan } = tdProps);
- text = text.children;
- }
- }
-
- if (column.customCell) {
- tdProps = { ...tdProps, ...column.customCell(record, index) };
- }
-
- // Fix https://github.com/ant-design/ant-design/issues/1202
- if (isInvalidRenderCellText(text)) {
- text = null;
- }
-
- if (transformCellText) {
- text = transformCellText({ text, column, record, index });
- }
-
- const indentText = expandIcon ? (
-
- ) : null;
-
- if (rowSpan === 0 || colSpan === 0) {
- return null;
- }
- if (column.align) {
- tdProps.style = { textAlign: column.align, ...tdProps.style };
- }
-
- const cellClassName = classNames(className, column.class, {
- [`${prefixCls}-cell-ellipsis`]: !!column.ellipsis,
- // 如果有宽度,增加断行处理
- // https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241
- [`${prefixCls}-cell-break-word`]: !!column.width,
- [`${rootPrefixCls}-cell-fix-left`]: isFixLeft,
- [`${rootPrefixCls}-cell-fix-left-first`]: firstFixLeft,
- [`${rootPrefixCls}-cell-fix-left-last`]: lastFixLeft,
- [`${rootPrefixCls}-cell-fix-right`]: isFixRight,
- [`${rootPrefixCls}-cell-fix-right-first`]: firstFixRight,
- [`${rootPrefixCls}-cell-fix-right-last`]: lastFixRight,
- });
-
- if (column.ellipsis) {
- if (typeof text === 'string') {
- tdProps.title = text;
- } else if (text) {
- // const { props: textProps } = text;
- // if (textProps && textProps.children && typeof textProps.children === 'string') {
- // tdProps.attrs.title = textProps.children;
- // }
- }
- }
-
- return (
-
- {indentText}
- {expandIcon}
- {toRaw(text)}
-
- );
- },
-};
diff --git a/components/legacy-table/src/TableHeader.jsx b/components/legacy-table/src/TableHeader.jsx
deleted file mode 100644
index 154356cc2..000000000
--- a/components/legacy-table/src/TableHeader.jsx
+++ /dev/null
@@ -1,114 +0,0 @@
-import { inject } from 'vue';
-import PropTypes from '../../_util/vue-types';
-import TableHeaderRow from './TableHeaderRow';
-
-function parseHeaderRows(rootColumns) {
- const rows = [];
-
- function fillRowCells(columns, colIndex, rowIndex = 0) {
- // Init rows
- rows[rowIndex] = rows[rowIndex] || [];
-
- let currentColIndex = colIndex;
- const colSpans = columns.filter(Boolean).map(column => {
- const cell = {
- key: column.key,
- className: column.className || column.class || '',
- children: column.title,
- column,
- colStart: currentColIndex,
- };
-
- let colSpan = 1;
-
- const subColumns = column.children;
- if (subColumns && subColumns.length > 0) {
- colSpan = fillRowCells(subColumns, currentColIndex, rowIndex + 1).reduce(
- (total, count) => total + count,
- 0,
- );
- cell.hasSubColumns = true;
- }
-
- if ('colSpan' in column) {
- ({ colSpan } = column);
- }
-
- if ('rowSpan' in column) {
- cell.rowSpan = column.rowSpan;
- }
-
- cell.colSpan = colSpan;
- cell.colEnd = cell.colStart + colSpan - 1;
- rows[rowIndex].push(cell);
-
- currentColIndex += colSpan;
-
- return colSpan;
- });
-
- return colSpans;
- }
-
- // Generate `rows` cell data
- fillRowCells(rootColumns, 0);
-
- // Handle `rowSpan`
- const rowCount = rows.length;
- for (let rowIndex = 0; rowIndex < rowCount; rowIndex += 1) {
- rows[rowIndex].forEach(cell => {
- if (!('rowSpan' in cell) && !cell.hasSubColumns) {
- // eslint-disable-next-line no-param-reassign
- cell.rowSpan = rowCount - rowIndex;
- }
- });
- }
-
- return rows;
-}
-
-export default {
- name: 'TableHeader',
- inheritAttrs: false,
- props: {
- fixed: PropTypes.string,
- columns: PropTypes.array.isRequired,
- expander: PropTypes.object.isRequired,
- },
- setup() {
- return {
- table: inject('table', {}),
- };
- },
-
- render() {
- const { sComponents: components, prefixCls, showHeader, customHeaderRow } = this.table;
- const { expander, columns, fixed } = this;
-
- if (!showHeader) {
- return null;
- }
- const rows = parseHeaderRows(this.columns);
- expander.renderExpandIndentCell(rows, fixed);
-
- const HeaderWrapper = components.header.wrapper;
-
- return (
-
- {rows.map((row, index) => (
-
- ))}
-
- );
- },
-};
diff --git a/components/legacy-table/src/TableHeaderRow.jsx b/components/legacy-table/src/TableHeaderRow.jsx
deleted file mode 100644
index d41de3e35..000000000
--- a/components/legacy-table/src/TableHeaderRow.jsx
+++ /dev/null
@@ -1,122 +0,0 @@
-import classNames from '../../_util/classNames';
-import PropTypes from '../../_util/vue-types';
-import { computed, inject } from 'vue';
-import { getCellFixedInfo } from './fixUtil';
-
-const TableHeaderRow = {
- name: 'TableHeaderRow',
- inheritAttrs: false,
- props: {
- index: PropTypes.number,
- fixed: PropTypes.string,
- columns: PropTypes.array,
- rows: PropTypes.array,
- row: PropTypes.array,
- components: PropTypes.object,
- customHeaderRow: PropTypes.func,
- prefixCls: PropTypes.prefixCls,
- },
- setup(props) {
- const store = inject('table-store', () => ({}));
- return {
- height: computed(() => {
- const { fixedColumnsHeadRowsHeight } = store;
- const { columns, rows, fixed } = props;
- const headerHeight = fixedColumnsHeadRowsHeight[0];
-
- if (!fixed) {
- return null;
- }
-
- if (headerHeight && columns) {
- if (headerHeight === 'auto') {
- return 'auto';
- }
- return `${headerHeight / rows.length}px`;
- }
- return null;
- }),
- store,
- };
- },
- render() {
- const { row, index, height, components, customHeaderRow, prefixCls } = this;
- const HeaderRow = components.header.row;
- const HeaderCell = components.header.cell;
- const rowProps = customHeaderRow(
- row.map(cell => cell.column),
- index,
- );
- const customStyle = rowProps ? rowProps.style : {};
- const style = { height, ...customStyle };
- if (style.height === null) {
- delete style.height;
- }
- const { stickyOffsets, columnManager } = this.store;
- return (
-
- {row.map((cell, i) => {
- const { column, isLast, children, className, ...cellProps } = cell;
- const fixedInfo = getCellFixedInfo(
- cell.colStart,
- cell.colEnd,
- columnManager.leafColumns,
- stickyOffsets,
- );
- const customProps = column.customHeaderCell ? column.customHeaderCell(column) : {};
- const headerCellProps = {
- ...cellProps,
- ...customProps,
- key: column.key || column.dataIndex || i,
- };
- if (headerCellProps.colSpan === 0) {
- return null;
- }
- if (column.align) {
- headerCellProps.style = { ...customProps.style, textAlign: column.align };
- }
- // ====================== Fixed =======================
- const { fixLeft, fixRight, firstFixLeft, lastFixLeft, firstFixRight, lastFixRight } =
- fixedInfo;
- const fixedStyle = {};
- const isFixLeft = typeof fixLeft === 'number';
- const isFixRight = typeof fixRight === 'number';
-
- if (isFixLeft) {
- fixedStyle.position = 'sticky';
- fixedStyle.left = `${fixLeft}px`;
- }
- if (isFixRight) {
- fixedStyle.position = 'sticky';
- fixedStyle.right = `${fixRight}px`;
- }
- headerCellProps.class = classNames(
- customProps.class,
- customProps.className,
- column.class,
- column.className,
- {
- [`${prefixCls}-align-${column.align}`]: !!column.align,
- [`${prefixCls}-row-cell-ellipsis`]: !!column.ellipsis,
- [`${prefixCls}-row-cell-break-word`]: !!column.width,
- [`${prefixCls}-row-cell-last`]: isLast,
- [`${prefixCls}-cell-fix-left`]: isFixLeft,
- [`${prefixCls}-cell-fix-left-first`]: firstFixLeft,
- [`${prefixCls}-cell-fix-left-last`]: lastFixLeft,
- [`${prefixCls}-cell-fix-right`]: isFixRight,
- [`${prefixCls}-cell-fix-right-first`]: firstFixRight,
- [`${prefixCls}-cell-fix-right-last`]: lastFixRight,
- },
- );
- headerCellProps.style = { ...(headerCellProps.style || {}), ...fixedStyle };
- if (typeof HeaderCell === 'function') {
- return HeaderCell(headerCellProps, children);
- }
- return {children};
- })}
-
- );
- },
-};
-
-export default TableHeaderRow;
diff --git a/components/legacy-table/src/TableRow.jsx b/components/legacy-table/src/TableRow.jsx
deleted file mode 100644
index 91318061b..000000000
--- a/components/legacy-table/src/TableRow.jsx
+++ /dev/null
@@ -1,302 +0,0 @@
-import classNames from '../../_util/classNames';
-import PropTypes, { withUndefined } from '../../_util/vue-types';
-import TableCell from './TableCell';
-import { initDefaultProps, findDOMNode } from '../../_util/props-util';
-import BaseMixin from '../../_util/BaseMixin';
-import { computed, inject } from 'vue';
-function noop() {}
-const TableRow = {
- name: 'TableRow',
- inheritAttrs: false,
- mixins: [BaseMixin],
- props: initDefaultProps(
- {
- customRow: PropTypes.func,
- // onRowClick: PropTypes.func,
- // onRowDoubleClick: PropTypes.func,
- // onRowContextMenu: PropTypes.func,
- // onRowMouseEnter: PropTypes.func,
- // onRowMouseLeave: PropTypes.func,
- record: PropTypes.object,
- prefixCls: PropTypes.string,
- // onHover: PropTypes.func,
- columns: PropTypes.array,
- index: PropTypes.number,
- rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
- className: PropTypes.string,
- indent: PropTypes.number,
- indentSize: PropTypes.number,
- hasExpandIcon: PropTypes.func,
- fixed: withUndefined(PropTypes.oneOfType([PropTypes.string, PropTypes.looseBool])),
- renderExpandIcon: PropTypes.func,
- renderExpandIconCell: PropTypes.func,
- components: PropTypes.any,
- expandedRow: PropTypes.looseBool,
- isAnyColumnsFixed: PropTypes.looseBool,
- ancestorKeys: PropTypes.array.isRequired,
- expandIconColumnIndex: PropTypes.number,
- expandRowByClick: PropTypes.looseBool,
- // visible: PropTypes.looseBool,
- // hovered: PropTypes.looseBool,
- // height: PropTypes.any,
- },
- {
- // expandIconColumnIndex: 0,
- // expandRowByClick: false,
- hasExpandIcon() {},
- renderExpandIcon() {},
- renderExpandIconCell() {},
- },
- ),
-
- setup(props) {
- const store = inject('table-store', () => ({}));
- const visible = computed(() => {
- const { expandedRowKeys } = store;
- const { ancestorKeys } = props;
- return !!(ancestorKeys.length === 0 || ancestorKeys.every(k => expandedRowKeys.includes(k)));
- });
- const height = computed(() => {
- const { expandedRowsHeight, fixedColumnsBodyRowsHeight } = store;
- const { fixed, rowKey } = props;
-
- if (!fixed) {
- return null;
- }
-
- if (expandedRowsHeight[rowKey]) {
- return expandedRowsHeight[rowKey];
- }
-
- if (fixedColumnsBodyRowsHeight[rowKey]) {
- return fixedColumnsBodyRowsHeight[rowKey];
- }
-
- return null;
- });
- const hovered = computed(() => {
- const { currentHoverKey } = store;
- const { rowKey } = props;
- return currentHoverKey === rowKey;
- });
- return {
- store,
- visible,
- hovered,
- height,
- };
- },
-
- data() {
- this.rowRef = null;
- return {
- shouldRender: this.visible,
- };
- },
-
- mounted() {
- if (this.shouldRender) {
- this.$nextTick(() => {
- this.saveRowRef();
- });
- }
- },
- watch: {
- visible(val) {
- if (val) {
- this.shouldRender = true;
- }
- },
- },
-
- updated() {
- if (this.shouldRender && !this.rowRef) {
- this.$nextTick(() => {
- this.saveRowRef();
- });
- }
- },
- methods: {
- onRowClick(event, rowPropFunc = noop) {
- const { record, index } = this;
- this.__emit('rowClick', record, index, event);
- rowPropFunc(event);
- },
-
- onRowDoubleClick(event, rowPropFunc = noop) {
- const { record, index } = this;
- this.__emit('rowDoubleClick', record, index, event);
- rowPropFunc(event);
- },
-
- onContextMenu(event, rowPropFunc = noop) {
- const { record, index } = this;
- this.__emit('rowContextmenu', record, index, event);
- rowPropFunc(event);
- },
-
- onMouseEnter(event, rowPropFunc = noop) {
- const { record, index, rowKey } = this;
- this.__emit('hover', true, rowKey);
- this.__emit('rowMouseenter', record, index, event);
- rowPropFunc(event);
- },
-
- onMouseLeave(event, rowPropFunc = noop) {
- const { record, index, rowKey } = this;
- this.__emit('hover', false, rowKey);
- this.__emit('rowMouseleave', record, index, event);
- rowPropFunc(event);
- },
-
- setExpandedRowHeight() {
- const { store, rowKey } = this;
- let { expandedRowsHeight } = store;
- const height = this.rowRef.getBoundingClientRect().height;
- expandedRowsHeight = {
- ...expandedRowsHeight,
- [rowKey]: height,
- };
- store.expandedRowsHeight = expandedRowsHeight;
- },
-
- setRowHeight() {
- const { store, rowKey } = this;
- const { fixedColumnsBodyRowsHeight } = store;
- const height = this.rowRef.getBoundingClientRect().height;
- store.fixedColumnsBodyRowsHeight = {
- ...fixedColumnsBodyRowsHeight,
- [rowKey]: height,
- };
- },
-
- getStyle() {
- const { height, visible } = this;
- let style = this.$attrs.style || {};
- if (height) {
- style = { ...style, height };
- }
-
- if (!visible && !style.display) {
- style = { ...style, display: 'none' };
- }
-
- return style;
- },
-
- saveRowRef() {
- this.rowRef = findDOMNode(this);
- const { isAnyColumnsFixed, fixed, expandedRow, ancestorKeys } = this;
- if (!isAnyColumnsFixed) {
- return;
- }
- if (!fixed && expandedRow) {
- this.setExpandedRowHeight();
- }
- if (!fixed && ancestorKeys.length >= 0) {
- this.setRowHeight();
- }
- },
- },
-
- render() {
- if (!this.shouldRender) {
- return null;
- }
-
- const {
- prefixCls,
- columns,
- record,
- rowKey,
- index,
- customRow = noop,
- indent,
- indentSize,
- hovered,
- height,
- visible,
- components,
- hasExpandIcon,
- renderExpandIcon,
- renderExpandIconCell,
- } = this;
- const BodyRow = components.body.row;
- const BodyCell = components.body.cell;
-
- let className = this.$attrs.class || '';
-
- if (hovered) {
- className += ` ${prefixCls}-hover`;
- }
-
- const cells = [];
-
- renderExpandIconCell(cells);
-
- for (let i = 0; i < columns.length; i += 1) {
- const column = columns[i];
-
- cells.push(
- ,
- );
- }
-
- const {
- class: customClass,
- className: customClassName,
- style: customStyle,
- ...rowProps
- } = customRow(record, index) || {};
-
- let style = { height: typeof height === 'number' ? `${height}px` : height };
-
- if (!visible) {
- style.display = 'none';
- }
-
- style = { ...style, ...customStyle };
- const rowClassName = classNames(
- prefixCls,
- className,
- `${prefixCls}-level-${indent}`,
- customClassName,
- customClass,
- );
- const bodyRowProps = {
- ...rowProps,
- style,
- onClick: e => {
- this.onRowClick(e, rowProps.onClick);
- },
- onDblclick: e => {
- this.onRowDoubleClick(e, rowProps.onDblclick);
- },
- onMouseenter: e => {
- this.onMouseEnter(e, rowProps.onMouseenter);
- },
- onMouseleave: e => {
- this.onMouseLeave(e, rowProps.onMouseleave);
- },
- onContextmenu: e => {
- this.onContextMenu(e, rowProps.onContextmenu);
- },
- class: rowClassName,
- 'data-row-key': rowKey,
- };
- return {cells};
- },
-};
-
-export default TableRow;
diff --git a/components/legacy-table/src/fixUtil.ts b/components/legacy-table/src/fixUtil.ts
deleted file mode 100644
index 4b4b40a8f..000000000
--- a/components/legacy-table/src/fixUtil.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-export interface StickyOffsets {
- left: readonly number[];
- right: readonly number[];
- isSticky?: boolean;
-}
-export type FixedType = 'left' | 'right' | boolean;
-export interface FixedInfo {
- fixLeft: number | false;
- fixRight: number | false;
- lastFixLeft: boolean;
- firstFixRight: boolean;
-
- // For Rtl Direction
- lastFixRight: boolean;
- firstFixLeft: boolean;
-
- isSticky: boolean;
-}
-
-export function getCellFixedInfo(
- colStart: number,
- colEnd: number,
- columns: readonly { fixed?: FixedType }[],
- stickyOffsets: StickyOffsets,
- direction: 'ltr' | 'rtl',
-): FixedInfo {
- const startColumn = columns[colStart] || {};
- const endColumn = columns[colEnd] || {};
-
- let fixLeft: number;
- let fixRight: number;
-
- if (startColumn.fixed === 'left') {
- fixLeft = stickyOffsets.left[colStart];
- } else if (endColumn.fixed === 'right') {
- fixRight = stickyOffsets.right[colEnd];
- }
-
- let lastFixLeft = false;
- let firstFixRight = false;
-
- let lastFixRight = false;
- let firstFixLeft = false;
-
- const nextColumn = columns[colEnd + 1];
- const prevColumn = columns[colStart - 1];
-
- if (direction === 'rtl') {
- if (fixLeft !== undefined) {
- const prevFixLeft = prevColumn && prevColumn.fixed === 'left';
- firstFixLeft = !prevFixLeft;
- } else if (fixRight !== undefined) {
- const nextFixRight = nextColumn && nextColumn.fixed === 'right';
- lastFixRight = !nextFixRight;
- }
- } else if (fixLeft !== undefined) {
- const nextFixLeft = nextColumn && nextColumn.fixed === 'left';
- lastFixLeft = !nextFixLeft;
- } else if (fixRight !== undefined) {
- const prevFixRight = prevColumn && prevColumn.fixed === 'right';
- firstFixRight = !prevFixRight;
- }
-
- return {
- fixLeft,
- fixRight,
- lastFixLeft,
- firstFixRight,
- lastFixRight,
- firstFixLeft,
- isSticky: stickyOffsets.isSticky,
- };
-}
diff --git a/components/legacy-table/src/useColumnManager.jsx b/components/legacy-table/src/useColumnManager.jsx
deleted file mode 100644
index 11c89c63b..000000000
--- a/components/legacy-table/src/useColumnManager.jsx
+++ /dev/null
@@ -1,101 +0,0 @@
-import { computed } from 'vue';
-export default function useColumnManager(columns) {
- const _leafColumns = (cls, fixed = false) => {
- const leafColumns = [];
- cls.forEach(column => {
- column.fixed = fixed || column.fixed;
- if (!column.children) {
- leafColumns.push(column);
- } else {
- leafColumns.push(..._leafColumns(column.children, column.fixed));
- }
- });
- return leafColumns;
- };
-
- // add appropriate rowspan and colspan to column
- const groupedColumns = computed(() => {
- const _groupColumns = (cls, currentRow = 0, parentColumn = {}, rows = [], fixed = false) => {
- // track how many rows we got
- rows[currentRow] = rows[currentRow] || [];
- const grouped = [];
- const setRowSpan = column => {
- const rowSpan = rows.length - currentRow;
- if (
- column &&
- !column.children && // parent columns.value are supposed to be one row
- rowSpan > 1 &&
- (!column.rowSpan || column.rowSpan < rowSpan)
- ) {
- column.rowSpan = rowSpan;
- }
- };
- cls.forEach((column, index) => {
- const newColumn = { ...column };
- newColumn.fixed = fixed || column.fixed;
- rows[currentRow].push(newColumn);
- parentColumn.colSpan = parentColumn.colSpan || 0;
- if (newColumn.children && newColumn.children.length > 0) {
- newColumn.children = _groupColumns(
- newColumn.children,
- currentRow + 1,
- newColumn,
- rows,
- newColumn.fixed,
- );
- parentColumn.colSpan += newColumn.colSpan;
- } else {
- parentColumn.colSpan += 1;
- }
- // update rowspan to all same row columns.value
- for (let i = 0; i < rows[currentRow].length - 1; i += 1) {
- setRowSpan(rows[currentRow][i]);
- }
- // last column, update rowspan immediately
- if (index + 1 === cls.length) {
- setRowSpan(newColumn);
- }
- grouped.push(newColumn);
- });
- return grouped;
- };
- return _groupColumns(columns.value);
- });
-
- const isAnyColumnsFixed = computed(() => columns.value.some(column => !!column.fixed));
-
- const isAnyColumnsLeftFixed = computed(() =>
- columns.value.some(column => column.fixed === 'left' || column.fixed === true),
- );
-
- const isAnyColumnsRightFixed = computed(() =>
- columns.value.some(column => column.fixed === 'right'),
- );
-
- const leftColumns = computed(() =>
- groupedColumns.value.filter(column => column.fixed === 'left' || column.fixed === true),
- );
-
- const rightColumns = computed(() => {
- return groupedColumns.value.filter(column => column.fixed === 'right');
- });
-
- const leafColumns = computed(() => {
- return _leafColumns(columns.value);
- });
-
- const leftLeafColumns = computed(() => _leafColumns(leftColumns.value));
-
- const rightLeafColumns = computed(() => _leafColumns(rightColumns.value));
- return {
- groupedColumns,
- isAnyColumnsFixed,
- isAnyColumnsLeftFixed,
- isAnyColumnsRightFixed,
- leftColumns,
- rightColumns,
- leafColumns,
- leftLeafColumns,
- rightLeafColumns,
- };
-}
diff --git a/components/legacy-table/src/useStickyOffsets.js b/components/legacy-table/src/useStickyOffsets.js
deleted file mode 100644
index 0005935bc..000000000
--- a/components/legacy-table/src/useStickyOffsets.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import { ref, watch } from 'vue';
-
-/**
- * Get sticky column offset width
- */
-function useStickyOffsets(colWidths, columns) {
- const stickyOffsets = ref({
- left: [],
- right: [],
- });
- const columnCount = ref();
- watch(
- columns,
- () => {
- columnCount.value = columns.value.length;
- },
- { immediate: true },
- );
- watch([colWidths, columnCount], () => {
- const leftOffsets = [];
- const rightOffsets = [];
- let left = 0;
- let right = 0;
-
- for (let start = 0; start < columnCount.value; start += 1) {
- // Left offset
- leftOffsets[start] = left;
- left += colWidths.value[start] || 0;
-
- // Right offset
- const end = columnCount.value - start - 1;
- rightOffsets[end] = right;
- right += colWidths.value[end] || 0;
- }
- stickyOffsets.value = {
- left: leftOffsets,
- right: rightOffsets,
- };
- });
- return stickyOffsets;
-}
-
-export default useStickyOffsets;
diff --git a/components/legacy-table/src/utils.js b/components/legacy-table/src/utils.js
deleted file mode 100644
index eacbf6fa4..000000000
--- a/components/legacy-table/src/utils.js
+++ /dev/null
@@ -1,116 +0,0 @@
-let scrollbarVerticalSize;
-let scrollbarHorizontalSize;
-
-// Measure scrollbar width for padding body during modal show/hide
-const scrollbarMeasure = {
- position: 'absolute',
- top: '-9999px',
- width: '50px',
- height: '50px',
-};
-
-export const INTERNAL_COL_DEFINE = 'RC_TABLE_INTERNAL_COL_DEFINE';
-
-export function measureScrollbar({ direction = 'vertical', prefixCls }) {
- if (typeof document === 'undefined' || typeof window === 'undefined') {
- return 0;
- }
- const isVertical = direction === 'vertical';
- if (isVertical && scrollbarVerticalSize) {
- return scrollbarVerticalSize;
- }
- if (!isVertical && scrollbarHorizontalSize) {
- return scrollbarHorizontalSize;
- }
- const scrollDiv = document.createElement('div');
- Object.keys(scrollbarMeasure).forEach(scrollProp => {
- scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
- });
- // apply hide scrollbar className ahead
- scrollDiv.className = `${prefixCls}-hide-scrollbar scroll-div-append-to-body`;
-
- // Append related overflow style
- if (isVertical) {
- scrollDiv.style.overflowY = 'scroll';
- } else {
- scrollDiv.style.overflowX = 'scroll';
- }
- document.body.appendChild(scrollDiv);
- let size = 0;
- if (isVertical) {
- size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
- scrollbarVerticalSize = size;
- } else {
- size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
- scrollbarHorizontalSize = size;
- }
-
- document.body.removeChild(scrollDiv);
- return size;
-}
-
-export function debounce(func, wait, immediate) {
- let timeout;
- function debounceFunc(...args) {
- const context = this;
- // https://fb.me/react-event-pooling
- if (args[0] && args[0].persist) {
- args[0].persist();
- }
- const later = () => {
- timeout = null;
- if (!immediate) {
- func.apply(context, args);
- }
- };
- const callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) {
- func.apply(context, args);
- }
- }
- debounceFunc.cancel = function cancel() {
- if (timeout) {
- clearTimeout(timeout);
- timeout = null;
- }
- };
- return debounceFunc;
-}
-
-export function remove(array, item) {
- const index = array.indexOf(item);
- const front = array.slice(0, index);
- const last = array.slice(index + 1, array.length);
- return front.concat(last);
-}
-
-/**
- * Returns only data- and aria- key/value pairs
- * @param {object} props
- */
-export function getDataAndAriaProps(props) {
- return Object.keys(props).reduce((memo, key) => {
- if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-') {
- memo[key] = props[key];
- }
- return memo;
- }, {});
-}
-
-export function getColumnsKey(columns) {
- const columnKeys = [];
-
- columns.forEach(column => {
- const { key, dataIndex } = column || {};
-
- columnKeys.push(key !== undefined ? key : dataIndex);
- });
-
- return columnKeys;
-}
-
-export function validateValue(val) {
- return val !== null && val !== undefined;
-}