e9949a2671b73e2119eab1047035e9d059aa00162249ac0b58c48d0c96afda382d28af988398a5623a813b507f8889eeb78e90e6fb642498c8ca00253d2455 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { createVNode, renderSlot, mergeProps } from 'vue';
  2. import { get } from 'lodash-unified';
  3. import { Alignment } from '../constants.mjs';
  4. import { placeholderSign } from '../private.mjs';
  5. import { enforceUnit, tryCall, componentToSlot } from '../utils.mjs';
  6. import TableCell from '../components/cell.mjs';
  7. import ExpandIcon from '../components/expand-icon.mjs';
  8. import { isFunction, isObject } from '@vue/shared';
  9. const CellRenderer = ({
  10. columns,
  11. column,
  12. columnIndex,
  13. depth,
  14. expandIconProps,
  15. isScrolling,
  16. rowData,
  17. rowIndex,
  18. style,
  19. expandedRowKeys,
  20. ns,
  21. cellProps: _cellProps,
  22. expandColumnKey,
  23. indentSize,
  24. iconSize,
  25. rowKey
  26. }, {
  27. slots
  28. }) => {
  29. const cellStyle = enforceUnit(style);
  30. if (column.placeholderSign === placeholderSign) {
  31. return createVNode("div", {
  32. "class": ns.em("row-cell", "placeholder"),
  33. "style": cellStyle
  34. }, null);
  35. }
  36. const {
  37. cellRenderer,
  38. dataKey,
  39. dataGetter
  40. } = column;
  41. const cellData = isFunction(dataGetter) ? dataGetter({
  42. columns,
  43. column,
  44. columnIndex,
  45. rowData,
  46. rowIndex
  47. }) : get(rowData, dataKey != null ? dataKey : "");
  48. const extraCellProps = tryCall(_cellProps, {
  49. cellData,
  50. columns,
  51. column,
  52. columnIndex,
  53. rowIndex,
  54. rowData
  55. });
  56. const cellProps = {
  57. class: ns.e("cell-text"),
  58. columns,
  59. column,
  60. columnIndex,
  61. cellData,
  62. isScrolling,
  63. rowData,
  64. rowIndex
  65. };
  66. const columnCellRenderer = componentToSlot(cellRenderer);
  67. const Cell = columnCellRenderer ? columnCellRenderer(cellProps) : renderSlot(slots, "default", cellProps, () => [createVNode(TableCell, cellProps, null)]);
  68. const kls = [ns.e("row-cell"), column.class, column.align === Alignment.CENTER && ns.is("align-center"), column.align === Alignment.RIGHT && ns.is("align-right")];
  69. const expandable = rowIndex >= 0 && expandColumnKey && column.key === expandColumnKey;
  70. const expanded = rowIndex >= 0 && expandedRowKeys.includes(rowData[rowKey]);
  71. let IconOrPlaceholder;
  72. const iconStyle = `margin-inline-start: ${depth * indentSize}px;`;
  73. if (expandable) {
  74. if (isObject(expandIconProps)) {
  75. IconOrPlaceholder = createVNode(ExpandIcon, mergeProps(expandIconProps, {
  76. "class": [ns.e("expand-icon"), ns.is("expanded", expanded)],
  77. "size": iconSize,
  78. "expanded": expanded,
  79. "style": iconStyle,
  80. "expandable": true
  81. }), null);
  82. } else {
  83. IconOrPlaceholder = createVNode("div", {
  84. "style": [iconStyle, `width: ${iconSize}px; height: ${iconSize}px;`].join(" ")
  85. }, null);
  86. }
  87. }
  88. return createVNode("div", mergeProps({
  89. "class": kls,
  90. "style": cellStyle
  91. }, extraCellProps, {
  92. "role": "cell"
  93. }), [IconOrPlaceholder, Cell]);
  94. };
  95. CellRenderer.inheritAttrs = false;
  96. var Cell = CellRenderer;
  97. export { Cell as default };
  98. //# sourceMappingURL=cell.mjs.map