You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
896 B

3 months ago
  1. import { isLeaf } from '../../../utils/dom/aria.mjs';
  2. const getMenuIndex = (el) => {
  3. if (!el)
  4. return 0;
  5. const pieces = el.id.split("-");
  6. return Number(pieces[pieces.length - 2]);
  7. };
  8. const checkNode = (el) => {
  9. if (!el)
  10. return;
  11. const input = el.querySelector("input");
  12. if (input) {
  13. input.click();
  14. } else if (isLeaf(el)) {
  15. el.click();
  16. }
  17. };
  18. const sortByOriginalOrder = (oldNodes, newNodes) => {
  19. const newNodesCopy = newNodes.slice(0);
  20. const newIds = newNodesCopy.map((node) => node.uid);
  21. const res = oldNodes.reduce((acc, item) => {
  22. const index = newIds.indexOf(item.uid);
  23. if (index > -1) {
  24. acc.push(item);
  25. newNodesCopy.splice(index, 1);
  26. newIds.splice(index, 1);
  27. }
  28. return acc;
  29. }, []);
  30. res.push(...newNodesCopy);
  31. return res;
  32. };
  33. export { checkNode, getMenuIndex, sortByOriginalOrder };
  34. //# sourceMappingURL=utils.mjs.map