7aa2d708cf29a73983a8f8e7e6f58a3848031c254998770a6317765562d275fc14dbe7cff418457e27ed293b87322cdfa9c1cbff418f96a8ffc224dc191aaa 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var shared = require('@vue/shared');
  5. const useData = (props, { expandedRowKeys, lastRenderedRowIndex, resetAfterIndex }) => {
  6. const depthMap = vue.ref({});
  7. const flattenedData = vue.computed(() => {
  8. const depths = {};
  9. const { data: data2, rowKey } = props;
  10. const _expandedRowKeys = vue.unref(expandedRowKeys);
  11. if (!_expandedRowKeys || !_expandedRowKeys.length)
  12. return data2;
  13. const array = [];
  14. const keysSet = /* @__PURE__ */ new Set();
  15. _expandedRowKeys.forEach((x) => keysSet.add(x));
  16. let copy = data2.slice();
  17. copy.forEach((x) => depths[x[rowKey]] = 0);
  18. while (copy.length > 0) {
  19. const item = copy.shift();
  20. array.push(item);
  21. if (keysSet.has(item[rowKey]) && shared.isArray(item.children) && item.children.length > 0) {
  22. copy = [...item.children, ...copy];
  23. item.children.forEach((child) => depths[child[rowKey]] = depths[item[rowKey]] + 1);
  24. }
  25. }
  26. depthMap.value = depths;
  27. return array;
  28. });
  29. const data = vue.computed(() => {
  30. const { data: data2, expandColumnKey } = props;
  31. return expandColumnKey ? vue.unref(flattenedData) : data2;
  32. });
  33. vue.watch(data, (val, prev) => {
  34. if (val !== prev) {
  35. lastRenderedRowIndex.value = -1;
  36. resetAfterIndex(0, true);
  37. }
  38. });
  39. return {
  40. data,
  41. depthMap
  42. };
  43. };
  44. exports.useData = useData;
  45. //# sourceMappingURL=use-data.js.map