7d3994ba78fa70ef7076d0dd696e9fbd15489837397612c15b253ad9a4aab08be3c02cc604c3b35f9ed580480ba6288bd091d2375481ce639a89d15529b3eb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var buildGrid = require('../builders/build-grid.js');
  4. var defaults = require('../defaults.js');
  5. const FixedSizeGrid = buildGrid["default"]({
  6. name: "ElFixedSizeGrid",
  7. getColumnPosition: ({ columnWidth }, index) => [
  8. columnWidth,
  9. index * columnWidth
  10. ],
  11. getRowPosition: ({ rowHeight }, index) => [
  12. rowHeight,
  13. index * rowHeight
  14. ],
  15. getEstimatedTotalHeight: ({ totalRow, rowHeight }) => rowHeight * totalRow,
  16. getEstimatedTotalWidth: ({ totalColumn, columnWidth }) => columnWidth * totalColumn,
  17. getColumnOffset: ({ totalColumn, columnWidth, width }, columnIndex, alignment, scrollLeft, _, scrollBarWidth) => {
  18. width = Number(width);
  19. const lastColumnOffset = Math.max(0, totalColumn * columnWidth - width);
  20. const maxOffset = Math.min(lastColumnOffset, columnIndex * columnWidth);
  21. const minOffset = Math.max(0, columnIndex * columnWidth - width + scrollBarWidth + columnWidth);
  22. if (alignment === "smart") {
  23. if (scrollLeft >= minOffset - width && scrollLeft <= maxOffset + width) {
  24. alignment = defaults.AUTO_ALIGNMENT;
  25. } else {
  26. alignment = defaults.CENTERED_ALIGNMENT;
  27. }
  28. }
  29. switch (alignment) {
  30. case defaults.START_ALIGNMENT:
  31. return maxOffset;
  32. case defaults.END_ALIGNMENT:
  33. return minOffset;
  34. case defaults.CENTERED_ALIGNMENT: {
  35. const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
  36. if (middleOffset < Math.ceil(width / 2)) {
  37. return 0;
  38. } else if (middleOffset > lastColumnOffset + Math.floor(width / 2)) {
  39. return lastColumnOffset;
  40. } else {
  41. return middleOffset;
  42. }
  43. }
  44. case defaults.AUTO_ALIGNMENT:
  45. default:
  46. if (scrollLeft >= minOffset && scrollLeft <= maxOffset) {
  47. return scrollLeft;
  48. } else if (minOffset > maxOffset) {
  49. return minOffset;
  50. } else if (scrollLeft < minOffset) {
  51. return minOffset;
  52. } else {
  53. return maxOffset;
  54. }
  55. }
  56. },
  57. getRowOffset: ({ rowHeight, height, totalRow }, rowIndex, align, scrollTop, _, scrollBarWidth) => {
  58. height = Number(height);
  59. const lastRowOffset = Math.max(0, totalRow * rowHeight - height);
  60. const maxOffset = Math.min(lastRowOffset, rowIndex * rowHeight);
  61. const minOffset = Math.max(0, rowIndex * rowHeight - height + scrollBarWidth + rowHeight);
  62. if (align === defaults.SMART_ALIGNMENT) {
  63. if (scrollTop >= minOffset - height && scrollTop <= maxOffset + height) {
  64. align = defaults.AUTO_ALIGNMENT;
  65. } else {
  66. align = defaults.CENTERED_ALIGNMENT;
  67. }
  68. }
  69. switch (align) {
  70. case defaults.START_ALIGNMENT:
  71. return maxOffset;
  72. case defaults.END_ALIGNMENT:
  73. return minOffset;
  74. case defaults.CENTERED_ALIGNMENT: {
  75. const middleOffset = Math.round(minOffset + (maxOffset - minOffset) / 2);
  76. if (middleOffset < Math.ceil(height / 2)) {
  77. return 0;
  78. } else if (middleOffset > lastRowOffset + Math.floor(height / 2)) {
  79. return lastRowOffset;
  80. } else {
  81. return middleOffset;
  82. }
  83. }
  84. case defaults.AUTO_ALIGNMENT:
  85. default:
  86. if (scrollTop >= minOffset && scrollTop <= maxOffset) {
  87. return scrollTop;
  88. } else if (minOffset > maxOffset) {
  89. return minOffset;
  90. } else if (scrollTop < minOffset) {
  91. return minOffset;
  92. } else {
  93. return maxOffset;
  94. }
  95. }
  96. },
  97. getColumnStartIndexForOffset: ({ columnWidth, totalColumn }, scrollLeft) => Math.max(0, Math.min(totalColumn - 1, Math.floor(scrollLeft / columnWidth))),
  98. getColumnStopIndexForStartIndex: ({ columnWidth, totalColumn, width }, startIndex, scrollLeft) => {
  99. const left = startIndex * columnWidth;
  100. const visibleColumnsCount = Math.ceil((width + scrollLeft - left) / columnWidth);
  101. return Math.max(0, Math.min(totalColumn - 1, startIndex + visibleColumnsCount - 1));
  102. },
  103. getRowStartIndexForOffset: ({ rowHeight, totalRow }, scrollTop) => Math.max(0, Math.min(totalRow - 1, Math.floor(scrollTop / rowHeight))),
  104. getRowStopIndexForStartIndex: ({ rowHeight, totalRow, height }, startIndex, scrollTop) => {
  105. const top = startIndex * rowHeight;
  106. const numVisibleRows = Math.ceil((height + scrollTop - top) / rowHeight);
  107. return Math.max(0, Math.min(totalRow - 1, startIndex + numVisibleRows - 1));
  108. },
  109. initCache: () => void 0,
  110. clearCache: true,
  111. validateProps: ({ columnWidth, rowHeight }) => {
  112. }
  113. });
  114. exports["default"] = FixedSizeGrid;
  115. //# sourceMappingURL=fixed-size-grid.js.map