treeUtil.js 1.6 KB

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