f6d395cd8468fad4922e9e228e1088454eea8bff3224a73d40fd912b66411e9495c664940fdcb4a1a5cb6db82a7f402c3f86fcf52e9b535b856d7ac8cebd7d 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { getCurrentInstance, watch } from 'vue';
  2. import { parseWidth, parseMinWidth } from '../util.mjs';
  3. import { hasOwn } from '@vue/shared';
  4. function getAllAliases(props, aliases) {
  5. return props.reduce((prev, cur) => {
  6. prev[cur] = cur;
  7. return prev;
  8. }, aliases);
  9. }
  10. function useWatcher(owner, props_) {
  11. const instance = getCurrentInstance();
  12. const registerComplexWatchers = () => {
  13. const props = ["fixed"];
  14. const aliases = {
  15. realWidth: "width",
  16. realMinWidth: "minWidth"
  17. };
  18. const allAliases = getAllAliases(props, aliases);
  19. Object.keys(allAliases).forEach((key) => {
  20. const columnKey = aliases[key];
  21. if (hasOwn(props_, columnKey)) {
  22. watch(() => props_[columnKey], (newVal) => {
  23. let value = newVal;
  24. if (columnKey === "width" && key === "realWidth") {
  25. value = parseWidth(newVal);
  26. }
  27. if (columnKey === "minWidth" && key === "realMinWidth") {
  28. value = parseMinWidth(newVal);
  29. }
  30. instance.columnConfig.value[columnKey] = value;
  31. instance.columnConfig.value[key] = value;
  32. const updateColumns = columnKey === "fixed";
  33. owner.value.store.scheduleLayout(updateColumns);
  34. });
  35. }
  36. });
  37. };
  38. const registerNormalWatchers = () => {
  39. const props = [
  40. "label",
  41. "filters",
  42. "filterMultiple",
  43. "filteredValue",
  44. "sortable",
  45. "index",
  46. "formatter",
  47. "className",
  48. "labelClassName",
  49. "filterClassName",
  50. "showOverflowTooltip",
  51. "tooltipFormatter"
  52. ];
  53. const parentProps = ["showOverflowTooltip"];
  54. const aliases = {
  55. property: "prop",
  56. align: "realAlign",
  57. headerAlign: "realHeaderAlign"
  58. };
  59. const allAliases = getAllAliases(props, aliases);
  60. Object.keys(allAliases).forEach((key) => {
  61. const columnKey = aliases[key];
  62. if (hasOwn(props_, columnKey)) {
  63. watch(() => props_[columnKey], (newVal) => {
  64. instance.columnConfig.value[key] = newVal;
  65. });
  66. }
  67. });
  68. parentProps.forEach((key) => {
  69. if (hasOwn(owner.value.props, key)) {
  70. watch(() => owner.value.props[key], (newVal) => {
  71. instance.columnConfig.value[key] = newVal;
  72. });
  73. }
  74. });
  75. };
  76. return {
  77. registerComplexWatchers,
  78. registerNormalWatchers
  79. };
  80. }
  81. export { useWatcher as default };
  82. //# sourceMappingURL=watcher-helper.mjs.map