treeUtil.js 2.1 KB

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