37ba7e661afa676d0dc97301a9441ff0057d8eddff738f50acbeab38b0982aaa2a193e47f7e81ef661155bce64cd71f42f422f868fe8b47fe382b4078f85c2 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var constants = require('../constants.js');
  5. var _private = require('../private.js');
  6. var utils = require('./utils.js');
  7. var shared = require('@vue/shared');
  8. function useColumns(props, columns, fixed) {
  9. const _columns = vue.computed(() => vue.unref(columns).map((column, index) => {
  10. var _a, _b;
  11. return {
  12. ...column,
  13. key: (_b = (_a = column.key) != null ? _a : column.dataKey) != null ? _b : index
  14. };
  15. }));
  16. const visibleColumns = vue.computed(() => {
  17. return vue.unref(_columns).filter((column) => !column.hidden);
  18. });
  19. const fixedColumnsOnLeft = vue.computed(() => vue.unref(visibleColumns).filter((column) => column.fixed === "left" || column.fixed === true));
  20. const fixedColumnsOnRight = vue.computed(() => vue.unref(visibleColumns).filter((column) => column.fixed === "right"));
  21. const normalColumns = vue.computed(() => vue.unref(visibleColumns).filter((column) => !column.fixed));
  22. const mainColumns = vue.computed(() => {
  23. const ret = [];
  24. vue.unref(fixedColumnsOnLeft).forEach((column) => {
  25. ret.push({
  26. ...column,
  27. placeholderSign: _private.placeholderSign
  28. });
  29. });
  30. vue.unref(normalColumns).forEach((column) => {
  31. ret.push(column);
  32. });
  33. vue.unref(fixedColumnsOnRight).forEach((column) => {
  34. ret.push({
  35. ...column,
  36. placeholderSign: _private.placeholderSign
  37. });
  38. });
  39. return ret;
  40. });
  41. const hasFixedColumns = vue.computed(() => {
  42. return vue.unref(fixedColumnsOnLeft).length || vue.unref(fixedColumnsOnRight).length;
  43. });
  44. const columnsStyles = vue.computed(() => {
  45. return vue.unref(_columns).reduce((style, column) => {
  46. style[column.key] = utils.calcColumnStyle(column, vue.unref(fixed), props.fixed);
  47. return style;
  48. }, {});
  49. });
  50. const columnsTotalWidth = vue.computed(() => {
  51. return vue.unref(visibleColumns).reduce((width, column) => width + column.width, 0);
  52. });
  53. const getColumn = (key) => {
  54. return vue.unref(_columns).find((column) => column.key === key);
  55. };
  56. const getColumnStyle = (key) => {
  57. return vue.unref(columnsStyles)[key];
  58. };
  59. const updateColumnWidth = (column, width) => {
  60. column.width = width;
  61. };
  62. function onColumnSorted(e) {
  63. var _a;
  64. const { key } = e.currentTarget.dataset;
  65. if (!key)
  66. return;
  67. const { sortState, sortBy } = props;
  68. let order = constants.SortOrder.ASC;
  69. if (shared.isObject(sortState)) {
  70. order = constants.oppositeOrderMap[sortState[key]];
  71. } else {
  72. order = constants.oppositeOrderMap[sortBy.order];
  73. }
  74. (_a = props.onColumnSort) == null ? void 0 : _a.call(props, { column: getColumn(key), key, order });
  75. }
  76. return {
  77. columns: _columns,
  78. columnsStyles,
  79. columnsTotalWidth,
  80. fixedColumnsOnLeft,
  81. fixedColumnsOnRight,
  82. hasFixedColumns,
  83. mainColumns,
  84. normalColumns,
  85. visibleColumns,
  86. getColumn,
  87. getColumnStyle,
  88. updateColumnWidth,
  89. onColumnSorted
  90. };
  91. }
  92. exports.useColumns = useColumns;
  93. //# sourceMappingURL=use-columns.js.map