b7392bebdf7abee37fab002176f8a6c592c34e81d927b2c271f253837b210992eef7bfe0cef59a31de3c3d569ac3676a645acb6faae0f0c961509c0db0d364 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { defineComponent, getCurrentInstance, inject, watch, onUnmounted, h } from 'vue';
  2. import useLayoutObserver from '../layout-observer.mjs';
  3. import { removePopper } from '../util.mjs';
  4. import { TABLE_INJECTION_KEY } from '../tokens.mjs';
  5. import useRender from './render-helper.mjs';
  6. import defaultProps from './defaults.mjs';
  7. import { useNamespace } from '../../../../hooks/use-namespace/index.mjs';
  8. import { addClass, removeClass } from '../../../../utils/dom/style.mjs';
  9. import { isClient } from '@vueuse/core';
  10. import { rAF } from '../../../../utils/raf.mjs';
  11. var TableBody = defineComponent({
  12. name: "ElTableBody",
  13. props: defaultProps,
  14. setup(props) {
  15. var _a;
  16. const instance = getCurrentInstance();
  17. const parent = inject(TABLE_INJECTION_KEY);
  18. const ns = useNamespace("table");
  19. const { wrappedRowRender, tooltipContent, tooltipTrigger } = useRender(props);
  20. const { onColumnsChange, onScrollableChange } = useLayoutObserver(parent);
  21. const hoveredCellList = [];
  22. watch((_a = props.store) == null ? void 0 : _a.states.hoverRow, (newVal, oldVal) => {
  23. var _a2, _b;
  24. const el = instance == null ? void 0 : instance.vnode.el;
  25. const rows = Array.from((el == null ? void 0 : el.children) || []).filter((e) => e == null ? void 0 : e.classList.contains(`${ns.e("row")}`));
  26. let rowNum = newVal;
  27. const childNodes = (_a2 = rows[rowNum]) == null ? void 0 : _a2.childNodes;
  28. if (childNodes == null ? void 0 : childNodes.length) {
  29. let control = 0;
  30. const indexes = Array.from(childNodes).reduce((acc, item, index) => {
  31. var _a3, _b2;
  32. if (((_a3 = childNodes[index]) == null ? void 0 : _a3.colSpan) > 1) {
  33. control = (_b2 = childNodes[index]) == null ? void 0 : _b2.colSpan;
  34. }
  35. if (item.nodeName !== "TD" && control === 0) {
  36. acc.push(index);
  37. }
  38. control > 0 && control--;
  39. return acc;
  40. }, []);
  41. indexes.forEach((rowIndex) => {
  42. var _a3;
  43. rowNum = newVal;
  44. while (rowNum > 0) {
  45. const preChildNodes = (_a3 = rows[rowNum - 1]) == null ? void 0 : _a3.childNodes;
  46. if (preChildNodes[rowIndex] && preChildNodes[rowIndex].nodeName === "TD" && preChildNodes[rowIndex].rowSpan > 1) {
  47. addClass(preChildNodes[rowIndex], "hover-cell");
  48. hoveredCellList.push(preChildNodes[rowIndex]);
  49. break;
  50. }
  51. rowNum--;
  52. }
  53. });
  54. } else {
  55. hoveredCellList.forEach((item) => removeClass(item, "hover-cell"));
  56. hoveredCellList.length = 0;
  57. }
  58. if (!((_b = props.store) == null ? void 0 : _b.states.isComplex.value) || !isClient)
  59. return;
  60. rAF(() => {
  61. const oldRow = rows[oldVal];
  62. const newRow = rows[newVal];
  63. if (oldRow && !oldRow.classList.contains("hover-fixed-row")) {
  64. removeClass(oldRow, "hover-row");
  65. }
  66. if (newRow) {
  67. addClass(newRow, "hover-row");
  68. }
  69. });
  70. });
  71. onUnmounted(() => {
  72. var _a2;
  73. (_a2 = removePopper) == null ? void 0 : _a2();
  74. });
  75. return {
  76. ns,
  77. onColumnsChange,
  78. onScrollableChange,
  79. wrappedRowRender,
  80. tooltipContent,
  81. tooltipTrigger
  82. };
  83. },
  84. render() {
  85. const { wrappedRowRender, store } = this;
  86. const data = (store == null ? void 0 : store.states.data.value) || [];
  87. return h("tbody", { tabIndex: -1 }, [
  88. data.reduce((acc, row) => {
  89. return acc.concat(wrappedRowRender(row, acc.length));
  90. }, [])
  91. ]);
  92. }
  93. });
  94. export { TableBody as default };
  95. //# sourceMappingURL=index.mjs.map