treeUtil.js 1.7 KB

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