treeUtil.js 2.0 KB

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