858f63514a41b92f48cf6ce36e4cab8e72ff93fd56e6cfa1f19c957e8f98381bee10a784dfed0945a07296331e403b0a2204b71fe13f6d3cba377285910256 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var header = require('../header.js');
  5. var utils = require('../utils.js');
  6. var tokens = require('../tokens.js');
  7. var index = require('../../../../hooks/use-namespace/index.js');
  8. var lodashUnified = require('lodash-unified');
  9. const COMPONENT_NAME = "ElTableV2Header";
  10. const TableV2Header = vue.defineComponent({
  11. name: COMPONENT_NAME,
  12. props: header.tableV2HeaderProps,
  13. setup(props, {
  14. slots,
  15. expose
  16. }) {
  17. const ns = index.useNamespace("table-v2");
  18. const scrollLeftInfo = vue.inject(tokens.TABLE_V2_GRID_INJECTION_KEY);
  19. const headerRef = vue.ref();
  20. const headerStyle = vue.computed(() => utils.enforceUnit({
  21. width: props.width,
  22. height: props.height
  23. }));
  24. const rowStyle = vue.computed(() => utils.enforceUnit({
  25. width: props.rowWidth,
  26. height: props.height
  27. }));
  28. const headerHeights = vue.computed(() => lodashUnified.castArray(vue.unref(props.headerHeight)));
  29. const scrollToLeft = (left) => {
  30. const headerEl = vue.unref(headerRef);
  31. vue.nextTick(() => {
  32. (headerEl == null ? void 0 : headerEl.scroll) && headerEl.scroll({
  33. left
  34. });
  35. });
  36. };
  37. const renderFixedRows = () => {
  38. const fixedRowClassName = ns.e("fixed-header-row");
  39. const {
  40. columns,
  41. fixedHeaderData,
  42. rowHeight
  43. } = props;
  44. return fixedHeaderData == null ? void 0 : fixedHeaderData.map((fixedRowData, fixedRowIndex) => {
  45. var _a;
  46. const style = utils.enforceUnit({
  47. height: rowHeight,
  48. width: "100%"
  49. });
  50. return (_a = slots.fixed) == null ? void 0 : _a.call(slots, {
  51. class: fixedRowClassName,
  52. columns,
  53. rowData: fixedRowData,
  54. rowIndex: -(fixedRowIndex + 1),
  55. style
  56. });
  57. });
  58. };
  59. const renderDynamicRows = () => {
  60. const dynamicRowClassName = ns.e("dynamic-header-row");
  61. const {
  62. columns
  63. } = props;
  64. return vue.unref(headerHeights).map((rowHeight, rowIndex) => {
  65. var _a;
  66. const style = utils.enforceUnit({
  67. width: "100%",
  68. height: rowHeight
  69. });
  70. return (_a = slots.dynamic) == null ? void 0 : _a.call(slots, {
  71. class: dynamicRowClassName,
  72. columns,
  73. headerIndex: rowIndex,
  74. style
  75. });
  76. });
  77. };
  78. vue.onUpdated(() => {
  79. if (scrollLeftInfo == null ? void 0 : scrollLeftInfo.value) {
  80. scrollToLeft(scrollLeftInfo.value);
  81. }
  82. });
  83. expose({
  84. scrollToLeft
  85. });
  86. return () => {
  87. if (props.height <= 0)
  88. return;
  89. return vue.createVNode("div", {
  90. "ref": headerRef,
  91. "class": props.class,
  92. "style": vue.unref(headerStyle),
  93. "role": "rowgroup"
  94. }, [vue.createVNode("div", {
  95. "style": vue.unref(rowStyle),
  96. "class": ns.e("header")
  97. }, [renderDynamicRows(), renderFixedRows()])]);
  98. };
  99. }
  100. });
  101. var Header = TableV2Header;
  102. exports["default"] = Header;
  103. //# sourceMappingURL=header.js.map