useEntities.js 1.1 KB

123456789101112131415161718192021222324252627
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { convertDataToEntities } from '../../vc-tree/utils/treeUtil';
  3. import { VALUE_SPLIT } from '../utils/commonUtil';
  4. import { computed } from 'vue';
  5. /** Lazy parse options data into conduct-able info to avoid perf issue in single mode */
  6. export default (function (options, fieldNames) {
  7. var entities = computed(function () {
  8. return convertDataToEntities(options.value, {
  9. fieldNames: fieldNames.value,
  10. initWrapper: function initWrapper(wrapper) {
  11. return _objectSpread(_objectSpread({}, wrapper), {}, {
  12. pathKeyEntities: {}
  13. });
  14. },
  15. processEntity: function processEntity(entity, wrapper) {
  16. var pathKey = entity.nodes.map(function (node) {
  17. return node[fieldNames.value.value];
  18. }).join(VALUE_SPLIT);
  19. wrapper.pathKeyEntities[pathKey] = entity;
  20. // Overwrite origin key.
  21. // this is very hack but we need let conduct logic work with connect path
  22. entity.key = pathKey;
  23. }
  24. }).pathKeyEntities;
  25. });
  26. return entities;
  27. });