UNPKG

@hitachivantara/uikit-react-core

Version:

Core React components for the NEXT Design System.

47 lines (46 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const getPreviousNode = (instance, nodeId) => { const node = instance.getNode(nodeId); const siblings = instance.getNavigableChildrenIds(node.parentId); const nodeIndex = siblings.indexOf(nodeId); if (nodeIndex === 0) { return node.parentId; } let currentNode = siblings[nodeIndex - 1]; while (instance.isNodeExpanded(currentNode) && instance.getNavigableChildrenIds(currentNode).length > 0) { currentNode = instance.getNavigableChildrenIds(currentNode).pop(); } return currentNode; }; const getNextNode = (instance, nodeId) => { if (instance.isNodeExpanded(nodeId) && instance.getNavigableChildrenIds(nodeId).length > 0) { return instance.getNavigableChildrenIds(nodeId)[0]; } let node = instance.getNode(nodeId); while (node != null) { const siblings = instance.getNavigableChildrenIds(node.parentId); const nextSibling = siblings[siblings.indexOf(node.id) + 1]; if (nextSibling) { return nextSibling; } node = instance.getNode(node.parentId); } return null; }; const getLastNode = (instance) => { let lastNode = instance.getNavigableChildrenIds(null).pop(); while (instance.isNodeExpanded(lastNode)) { lastNode = instance.getNavigableChildrenIds(lastNode).pop(); } return lastNode; }; const getFirstNode = (instance) => instance.getNavigableChildrenIds(null)[0]; const populateInstance = (instance, methods) => { Object.assign(instance, methods); }; exports.getFirstNode = getFirstNode; exports.getLastNode = getLastNode; exports.getNextNode = getNextNode; exports.getPreviousNode = getPreviousNode; exports.populateInstance = populateInstance;