53631b764b21b4a3305ce3869c7eef481d38b41737efbcccc4ff00dd1af1494a8717d4641d28b87c07b840e5a83465ad68f29d6fb464bd64a35b070f0ae07b 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var constants = require('../constants.js');
  6. var types = require('../../../../utils/types.js');
  7. const useRow = (props, {
  8. mainTableRef,
  9. leftTableRef,
  10. rightTableRef,
  11. tableInstance,
  12. ns,
  13. isScrolling
  14. }) => {
  15. const vm = vue.getCurrentInstance();
  16. const { emit } = vm;
  17. const isResetting = vue.shallowRef(false);
  18. const expandedRowKeys = vue.ref(props.defaultExpandedRowKeys || []);
  19. const lastRenderedRowIndex = vue.ref(-1);
  20. const resetIndex = vue.shallowRef(null);
  21. const rowHeights = vue.ref({});
  22. const pendingRowHeights = vue.ref({});
  23. const leftTableHeights = vue.shallowRef({});
  24. const mainTableHeights = vue.shallowRef({});
  25. const rightTableHeights = vue.shallowRef({});
  26. const isDynamic = vue.computed(() => types.isNumber(props.estimatedRowHeight));
  27. function onRowsRendered(params) {
  28. var _a;
  29. (_a = props.onRowsRendered) == null ? void 0 : _a.call(props, params);
  30. if (params.rowCacheEnd > vue.unref(lastRenderedRowIndex)) {
  31. lastRenderedRowIndex.value = params.rowCacheEnd;
  32. }
  33. }
  34. function onRowHovered({ hovered, rowKey }) {
  35. if (isScrolling.value) {
  36. return;
  37. }
  38. const tableRoot = tableInstance.vnode.el;
  39. const rows = tableRoot.querySelectorAll(`[rowkey="${String(rowKey)}"]`);
  40. rows.forEach((row) => {
  41. if (hovered) {
  42. row.classList.add(ns.is("hovered"));
  43. } else {
  44. row.classList.remove(ns.is("hovered"));
  45. }
  46. });
  47. }
  48. function onRowExpanded({
  49. expanded,
  50. rowData,
  51. rowIndex,
  52. rowKey
  53. }) {
  54. var _a, _b;
  55. const _expandedRowKeys = [...vue.unref(expandedRowKeys)];
  56. const currentKeyIndex = _expandedRowKeys.indexOf(rowKey);
  57. if (expanded) {
  58. if (currentKeyIndex === -1)
  59. _expandedRowKeys.push(rowKey);
  60. } else {
  61. if (currentKeyIndex > -1)
  62. _expandedRowKeys.splice(currentKeyIndex, 1);
  63. }
  64. expandedRowKeys.value = _expandedRowKeys;
  65. emit("update:expandedRowKeys", _expandedRowKeys);
  66. (_a = props.onRowExpand) == null ? void 0 : _a.call(props, {
  67. expanded,
  68. rowData,
  69. rowIndex,
  70. rowKey
  71. });
  72. (_b = props.onExpandedRowsChange) == null ? void 0 : _b.call(props, _expandedRowKeys);
  73. const tableRoot = tableInstance.vnode.el;
  74. const hoverRow = tableRoot.querySelector(`.${ns.is("hovered")}[rowkey="${String(rowKey)}"]`);
  75. if (hoverRow) {
  76. vue.nextTick(() => onRowHovered({ hovered: true, rowKey }));
  77. }
  78. }
  79. const flushingRowHeights = lodashUnified.debounce(() => {
  80. var _a, _b, _c, _d;
  81. isResetting.value = true;
  82. rowHeights.value = { ...vue.unref(rowHeights), ...vue.unref(pendingRowHeights) };
  83. resetAfterIndex(vue.unref(resetIndex), false);
  84. pendingRowHeights.value = {};
  85. resetIndex.value = null;
  86. (_a = mainTableRef.value) == null ? void 0 : _a.forceUpdate();
  87. (_b = leftTableRef.value) == null ? void 0 : _b.forceUpdate();
  88. (_c = rightTableRef.value) == null ? void 0 : _c.forceUpdate();
  89. (_d = vm.proxy) == null ? void 0 : _d.$forceUpdate();
  90. isResetting.value = false;
  91. }, 0);
  92. function resetAfterIndex(index, forceUpdate = false) {
  93. if (!vue.unref(isDynamic))
  94. return;
  95. [mainTableRef, leftTableRef, rightTableRef].forEach((tableRef) => {
  96. const table = vue.unref(tableRef);
  97. if (table)
  98. table.resetAfterRowIndex(index, forceUpdate);
  99. });
  100. }
  101. function resetHeights(rowKey, height, rowIdx) {
  102. const resetIdx = vue.unref(resetIndex);
  103. if (resetIdx === null) {
  104. resetIndex.value = rowIdx;
  105. } else {
  106. if (resetIdx > rowIdx) {
  107. resetIndex.value = rowIdx;
  108. }
  109. }
  110. pendingRowHeights.value[rowKey] = height;
  111. }
  112. function onRowHeightChange({ rowKey, height, rowIndex }, fixedDir) {
  113. if (!fixedDir) {
  114. mainTableHeights.value[rowKey] = height;
  115. } else {
  116. if (fixedDir === constants.FixedDir.RIGHT) {
  117. rightTableHeights.value[rowKey] = height;
  118. } else {
  119. leftTableHeights.value[rowKey] = height;
  120. }
  121. }
  122. const maximumHeight = Math.max(...[leftTableHeights, rightTableHeights, mainTableHeights].map((records) => records.value[rowKey] || 0));
  123. if (vue.unref(rowHeights)[rowKey] !== maximumHeight) {
  124. resetHeights(rowKey, maximumHeight, rowIndex);
  125. flushingRowHeights();
  126. }
  127. }
  128. return {
  129. expandedRowKeys,
  130. lastRenderedRowIndex,
  131. isDynamic,
  132. isResetting,
  133. rowHeights,
  134. resetAfterIndex,
  135. onRowExpanded,
  136. onRowHovered,
  137. onRowsRendered,
  138. onRowHeightChange
  139. };
  140. };
  141. exports.useRow = useRow;
  142. //# sourceMappingURL=use-row.js.map