treeUtil.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { SHOW_CHILD } from './commonUtil';
  2. export function formatStrategyValues(pathKeys, keyPathEntities, showCheckedStrategy) {
  3. var valueSet = new Set(pathKeys);
  4. return pathKeys.filter(function (key) {
  5. var entity = keyPathEntities[key];
  6. var parent = entity ? entity.parent : null;
  7. var children = entity ? entity.children : null;
  8. return showCheckedStrategy === SHOW_CHILD ? !(children && children.some(function (child) {
  9. return child.key && valueSet.has(child.key);
  10. })) : !(parent && !parent.node.disabled && valueSet.has(parent.key));
  11. });
  12. }
  13. export function toPathOptions(valueCells, options, fieldNames) {
  14. var stringMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  15. var currentList = options;
  16. var valueOptions = [];
  17. var _loop = function _loop(i) {
  18. var _currentList, _currentList2, _foundOption$fieldNam;
  19. var valueCell = valueCells[i];
  20. var foundIndex = (_currentList = currentList) === null || _currentList === void 0 ? void 0 : _currentList.findIndex(function (option) {
  21. var val = option[fieldNames.value];
  22. return stringMode ? String(val) === String(valueCell) : val === valueCell;
  23. });
  24. var foundOption = foundIndex !== -1 ? (_currentList2 = currentList) === null || _currentList2 === void 0 ? void 0 : _currentList2[foundIndex] : null;
  25. valueOptions.push({
  26. value: (_foundOption$fieldNam = foundOption === null || foundOption === void 0 ? void 0 : foundOption[fieldNames.value]) !== null && _foundOption$fieldNam !== void 0 ? _foundOption$fieldNam : valueCell,
  27. index: foundIndex,
  28. option: foundOption
  29. });
  30. currentList = foundOption === null || foundOption === void 0 ? void 0 : foundOption[fieldNames.children];
  31. };
  32. for (var i = 0; i < valueCells.length; i += 1) {
  33. _loop(i);
  34. }
  35. return valueOptions;
  36. }