openStrategies.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. export const singleOpenStrategy = {
  2. open: _ref => {
  3. let {
  4. id,
  5. value,
  6. opened,
  7. parents
  8. } = _ref;
  9. if (value) {
  10. const newOpened = new Set();
  11. newOpened.add(id);
  12. let parent = parents.get(id);
  13. while (parent != null) {
  14. newOpened.add(parent);
  15. parent = parents.get(parent);
  16. }
  17. return newOpened;
  18. } else {
  19. opened.delete(id);
  20. return opened;
  21. }
  22. },
  23. select: () => null
  24. };
  25. export const multipleOpenStrategy = {
  26. open: _ref2 => {
  27. let {
  28. id,
  29. value,
  30. opened,
  31. parents
  32. } = _ref2;
  33. if (value) {
  34. let parent = parents.get(id);
  35. opened.add(id);
  36. while (parent != null && parent !== id) {
  37. opened.add(parent);
  38. parent = parents.get(parent);
  39. }
  40. return opened;
  41. } else {
  42. opened.delete(id);
  43. }
  44. return opened;
  45. },
  46. select: () => null
  47. };
  48. export const listOpenStrategy = {
  49. open: multipleOpenStrategy.open,
  50. select: _ref3 => {
  51. let {
  52. id,
  53. value,
  54. opened,
  55. parents
  56. } = _ref3;
  57. if (!value) return opened;
  58. const path = [];
  59. let parent = parents.get(id);
  60. while (parent != null) {
  61. path.push(parent);
  62. parent = parents.get(parent);
  63. }
  64. return new Set(path);
  65. }
  66. };
  67. //# sourceMappingURL=openStrategies.mjs.map