treeUtil.js 1.9 KB

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