@difizen/mana-app
Version:
72 lines (70 loc) • 2.06 kB
JavaScript
import { TreeNode } from "./tree";
/**
* The tree selection service.
*/
export var TreeSelectionService = Symbol('TreeSelectionService');
/**
* Representation of a tree selection.
*/
export var TreeSelection;
(function (_TreeSelection) {
var SelectionType = /*#__PURE__*/function (SelectionType) {
SelectionType[SelectionType["DEFAULT"] = 0] = "DEFAULT";
SelectionType[SelectionType["TOGGLE"] = 1] = "TOGGLE";
SelectionType[SelectionType["RANGE"] = 2] = "RANGE";
return SelectionType;
}({});
_TreeSelection.SelectionType = SelectionType;
function is(arg) {
return !!arg && 'node' in arg;
}
_TreeSelection.is = is;
function isRange(arg) {
return isSelectionTypeOf(arg, SelectionType.RANGE);
}
_TreeSelection.isRange = isRange;
function isToggle(arg) {
return isSelectionTypeOf(arg, SelectionType.TOGGLE);
}
_TreeSelection.isToggle = isToggle;
// eslint-disable-next-line no-inner-declarations
function isSelectionTypeOf(arg, expected) {
if (arg === undefined) {
return false;
}
var type = typeof arg === 'number' ? arg : arg.type;
return type === expected;
}
})(TreeSelection || (TreeSelection = {}));
/**
* A selectable tree node.
*/
export var SelectableTreeNode;
(function (_SelectableTreeNode) {
function is(node) {
return !!node && 'selected' in node;
}
_SelectableTreeNode.is = is;
function isSelected(node) {
return is(node) && node.selected;
}
_SelectableTreeNode.isSelected = isSelected;
function hasFocus(node) {
return is(node) && node.focus === true;
}
_SelectableTreeNode.hasFocus = hasFocus;
function isVisible(node) {
return is(node) && TreeNode.isVisible(node);
}
_SelectableTreeNode.isVisible = isVisible;
function getVisibleParent(node) {
if (node) {
if (isVisible(node.parent)) {
return node.parent;
}
return getVisibleParent(node.parent);
}
return undefined;
}
_SelectableTreeNode.getVisibleParent = getVisibleParent;
})(SelectableTreeNode || (SelectableTreeNode = {}));