element-plus
Version:
A Component Library for Vue 3
222 lines (219 loc) • 6.49 kB
JavaScript
import { defineComponent, getCurrentInstance, provide, computed, onBeforeUnmount } from 'vue';
import { debounce } from 'lodash-unified';
import { ElScrollbar } from '../../scrollbar/index.mjs';
import { createStore } from './store/helper.mjs';
import TableLayout from './table-layout.mjs';
import TableHeader from './table-header/index.mjs';
import TableBody from './table-body/index.mjs';
import TableFooter from './table-footer/index.mjs';
import useUtils from './table/utils-helper.mjs';
import { convertToRows } from './table-header/utils-helper.mjs';
import useStyle from './table/style-helper.mjs';
import useKeyRender from './table/key-render-helper.mjs';
import defaultProps from './table/defaults.mjs';
import { TABLE_INJECTION_KEY } from './tokens.mjs';
import { hColgroup } from './h-helper.mjs';
import { useScrollbar } from './composables/use-scrollbar.mjs';
import Mousewheel from '../../../directives/mousewheel/index.mjs';
import { useLocale } from '../../../hooks/use-locale/index.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
let tableIdSeed = 1;
var _sfc_main = defineComponent({
name: "ElTable",
directives: {
Mousewheel
},
components: {
TableHeader,
TableBody,
TableFooter,
ElScrollbar,
hColgroup
},
props: defaultProps,
emits: [
"select",
"select-all",
"selection-change",
"cell-mouse-enter",
"cell-mouse-leave",
"cell-contextmenu",
"cell-click",
"cell-dblclick",
"row-click",
"row-contextmenu",
"row-dblclick",
"header-click",
"header-contextmenu",
"sort-change",
"filter-change",
"current-change",
"header-dragend",
"expand-change",
"scroll"
],
setup(props) {
const { t } = useLocale();
const ns = useNamespace("table");
const table = getCurrentInstance();
provide(TABLE_INJECTION_KEY, table);
const store = createStore(table, props);
table.store = store;
const layout = new TableLayout({
store: table.store,
table,
fit: props.fit,
showHeader: props.showHeader
});
table.layout = layout;
const isEmpty = computed(() => (store.states.data.value || []).length === 0);
const {
setCurrentRow,
getSelectionRows,
toggleRowSelection,
clearSelection,
clearFilter,
toggleAllSelection,
toggleRowExpansion,
clearSort,
sort,
updateKeyChildren
} = useUtils(store);
const {
isHidden,
renderExpanded,
setDragVisible,
isGroup,
handleMouseLeave,
handleHeaderFooterMousewheel,
tableSize,
emptyBlockStyle,
resizeProxyVisible,
bodyWidth,
resizeState,
doLayout,
tableBodyStyles,
tableLayout,
scrollbarViewStyle,
scrollbarStyle
} = useStyle(props, layout, store, table);
const { scrollBarRef, scrollTo, setScrollLeft, setScrollTop } = useScrollbar();
const debouncedUpdateLayout = debounce(doLayout, 50);
const tableId = `${ns.namespace.value}-table_${tableIdSeed++}`;
table.tableId = tableId;
table.state = {
isGroup,
resizeState,
doLayout,
debouncedUpdateLayout
};
const computedSumText = computed(
() => {
var _a;
return (_a = props.sumText) != null ? _a : t("el.table.sumText");
}
);
const computedEmptyText = computed(() => {
var _a;
return (_a = props.emptyText) != null ? _a : t("el.table.emptyText");
});
const columns = computed(() => {
return convertToRows(store.states.originColumns.value)[0];
});
useKeyRender(table);
onBeforeUnmount(() => {
debouncedUpdateLayout.cancel();
});
return {
ns,
layout,
store,
columns,
handleHeaderFooterMousewheel,
handleMouseLeave,
tableId,
tableSize,
isHidden,
isEmpty,
renderExpanded,
resizeProxyVisible,
resizeState,
isGroup,
bodyWidth,
tableBodyStyles,
emptyBlockStyle,
debouncedUpdateLayout,
/**
* @description used in single selection Table, set a certain row selected. If called without any parameter, it will clear selection
*/
setCurrentRow,
/**
* @description returns the currently selected rows
*/
getSelectionRows,
/**
* @description used in multiple selection Table, toggle if a certain row is selected. With the second parameter, you can directly set if this row is selected
*/
toggleRowSelection,
/**
* @description used in multiple selection Table, clear user selection
*/
clearSelection,
/**
* @description clear filters of the columns whose `columnKey` are passed in. If no params, clear all filters
*/
clearFilter,
/**
* @description used in multiple selection Table, toggle select all and deselect all
*/
toggleAllSelection,
/**
* @description used in expandable Table or tree Table, toggle if a certain row is expanded. With the second parameter, you can directly set if this row is expanded or collapsed
*/
toggleRowExpansion,
/**
* @description clear sorting, restore data to the original order
*/
clearSort,
/**
* @description refresh the layout of Table. When the visibility of Table changes, you may need to call this method to get a correct layout
*/
doLayout,
/**
* @description sort Table manually. Property `prop` is used to set sort column, property `order` is used to set sort order
*/
sort,
/**
* @description used in lazy Table, must set `rowKey`, update key children
*/
updateKeyChildren,
t,
setDragVisible,
context: table,
computedSumText,
computedEmptyText,
tableLayout,
scrollbarViewStyle,
scrollbarStyle,
scrollBarRef,
/**
* @description scrolls to a particular set of coordinates
*/
scrollTo,
/**
* @description set horizontal scroll position
*/
setScrollLeft,
/**
* @description set vertical scroll position
*/
setScrollTop,
/**
* @description whether to allow drag the last column
*/
allowDragLastColumn: props.allowDragLastColumn
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=table.vue2.mjs.map