useEntities.js 966 B

1234567891011121314151617181920212223
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  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 ((options, fieldNames) => {
  7. const entities = computed(() => {
  8. return convertDataToEntities(options.value, {
  9. fieldNames: fieldNames.value,
  10. initWrapper: wrapper => _extends(_extends({}, wrapper), {
  11. pathKeyEntities: {}
  12. }),
  13. processEntity: (entity, wrapper) => {
  14. const pathKey = entity.nodes.map(node => node[fieldNames.value.value]).join(VALUE_SPLIT);
  15. wrapper.pathKeyEntities[pathKey] = entity;
  16. // Overwrite origin key.
  17. // this is very hack but we need let conduct logic work with connect path
  18. entity.key = pathKey;
  19. }
  20. }).pathKeyEntities;
  21. });
  22. return entities;
  23. });