@hitachivantara/uikit-react-core
Version:
UI Kit Core React components.
33 lines (32 loc) • 1.49 kB
JavaScript
//#region src/TreeView/internals/hooks/utils.ts
var 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;
};
var 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;
};
var getLastNode = (instance) => {
let lastNode = instance.getNavigableChildrenIds(null).pop();
while (instance.isNodeExpanded(lastNode)) lastNode = instance.getNavigableChildrenIds(lastNode).pop();
return lastNode;
};
var getFirstNode = (instance) => instance.getNavigableChildrenIds(null)[0];
var populateInstance = (instance, methods) => {
Object.assign(instance, methods);
};
//#endregion
export { getFirstNode, getLastNode, getNextNode, getPreviousNode, populateInstance };