UNPKG

@nodeject/ui-components

Version:

UI library for non-trivial components

116 lines (115 loc) 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isOrgStyle = exports.hasParent = exports.hasChildren = exports.hasSiblings = exports.siblingsAndCallingNode = exports.getNextNode = exports.getNextSibling = exports.getPreviousSibling = exports.toCytoscape = void 0; var cytoscape_1 = require("cytoscape"); var toCytoscape = function (graph) { return cytoscape_1.default({ headless: true, elements: graph }); }; exports.toCytoscape = toCytoscape; /** * Returns a node's previous sibling * @param node * @returns {Cy.NodeCollection} */ var getPreviousSibling = function (node) { var nodeId = node.id(); if (exports.hasSiblings(node)) { var mySiblingsAndCallingNode = exports.siblingsAndCallingNode(node); for (var i = 0; mySiblingsAndCallingNode.length - 1; i++) { if (nodeId == mySiblingsAndCallingNode[i].id()) { if (i > 0) { return mySiblingsAndCallingNode[i - 1]; } else { return null; } } } } else { return null; } }; exports.getPreviousSibling = getPreviousSibling; /** * Returns a node's next sibling * @param node * @returns {Cy.NodeCollection} */ var getNextSibling = function (node) { var nodeId = node.id(); if (exports.hasSiblings(node)) { var mySiblingsAndCallingNode = exports.siblingsAndCallingNode(node); for (var i = 0; exports.siblingsAndCallingNode.length - 1; i++) { if (nodeId == mySiblingsAndCallingNode[i].id()) { if (i < mySiblingsAndCallingNode.length - 1) { return mySiblingsAndCallingNode[i + 1]; } else { return null; } } } } else { return null; } }; exports.getNextSibling = getNextSibling; /** * Returns the next node in the tree * @param node */ var getNextNode = function (node) { return exports.hasChildren(node) ? node.children().first() : exports.getNextSibling(node); }; exports.getNextNode = getNextNode; /** * Returns a node's parent's children * @param node * @returns {Cy.NodeCollection} */ var siblingsAndCallingNode = function (node) { if (exports.hasParent(node)) { return node.parent().children(); } else { return node; } }; exports.siblingsAndCallingNode = siblingsAndCallingNode; /** * Returns true if node has siblings * @param node */ var hasSiblings = function (node) { return node.siblings().length > 0; }; exports.hasSiblings = hasSiblings; /** * Returns true if node has children * @param node */ var hasChildren = function (node) { return node.children().length > 0; }; exports.hasChildren = hasChildren; /** * Returns true if node has a parent * @param node */ var hasParent = function (node) { return node.parent().length > 0; }; exports.hasParent = hasParent; /** * Returns true if node is Org Style, false if it's List Style * @param node */ var isOrgStyle = function (node) { return typeof node === 'number' ? node === 0 : node.data().layoutStyle === 0; }; exports.isOrgStyle = isOrgStyle;