UNPKG

4.94 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23Object.defineProperty(exports, "__esModule", { value: true });
24exports.TreeCompressionService = exports.CompressionToggle = void 0;
25const inversify_1 = require("inversify");
26const types_1 = require("../../../common/types");
27const tree_1 = require("../tree");
28const tree_expansion_1 = require("../tree-expansion");
29exports.CompressionToggle = Symbol('CompressionToggle');
30let TreeCompressionService = class TreeCompressionService {
31 /**
32 * @returns `true` if the node has a single child that is a CompositeTreeNode
33 * In that case, the child can be shown in the same row as the parent.
34 */
35 isCompressionParent(node) {
36 return this.isVisibleExpandableNode(node) && node.children.length === 1 && this.isVisibleExpandableNode(node.children[0]);
37 }
38 isVisibleExpandableNode(node) {
39 return tree_expansion_1.ExpandableTreeNode.is(node) && tree_1.TreeNode.isVisible(node);
40 }
41 /**
42 * @returns `true` if the node is a CompositeTreeNode and is its parent's sole child
43 * In that case, the node can be shown in the same row as its parent.
44 */
45 isCompressionChild(node) {
46 return this.isCompressionParent(node === null || node === void 0 ? void 0 : node.parent);
47 }
48 /**
49 * @returns `true` if the node is a CompositeTreeNode with a sole child, and the same is not true of its parent.
50 * In that case, the node will appear as the first member of a compressed row.
51 */
52 isCompressionHead(node) {
53 return this.isCompressionParent(node) && !this.isCompressionParent(node.parent);
54 }
55 /**
56 * @returns `true` if the node's parent is a CompositeTreeNode with a sole child, and the same is not true of the node.
57 * In that case, the node will appear as the last member of a compressed row.
58 */
59 isCompressionTail(node) {
60 return this.isCompressionChild(node) && !this.isCompressionParent(node);
61 }
62 /**
63 * @returns `true` if the node is part of a compression row, either a {@link CompressionChild} or {@link CompressionParent}
64 */
65 isCompressionParticipant(node) {
66 return this.isCompressionParent(node) || this.isCompressionChild(node);
67 }
68 getCompressedChildren(node) {
69 if (this.isCompressionHead(node)) {
70 const items = [];
71 let next = node.children[0];
72 while (this.isCompressionChild(next)) {
73 items.push(next);
74 next = next.children[0];
75 }
76 return types_1.ArrayUtils.asTail(items);
77 }
78 }
79 /**
80 * @returns The {@link CompressionHead} of the node's compression chain, or undefined if the node is not a {@link CompressionParticipant}.
81 */
82 getCompressionHead(node) {
83 while (this.isCompressionParticipant(node)) {
84 if (this.isCompressionHead(node)) {
85 return node;
86 }
87 node = node.parent;
88 }
89 }
90 /**
91 * @returns The compression chain of which the `node` is a part, or `undefined` if the `node` is not a {@link CompressionParticipant}
92 */
93 getCompressionChain(node) {
94 const head = this.getCompressionHead(node);
95 if (head) {
96 return types_1.ArrayUtils.asHeadAndTail([head].concat(this.getCompressedChildren(head)));
97 }
98 }
99};
100TreeCompressionService = __decorate([
101 (0, inversify_1.injectable)()
102], TreeCompressionService);
103exports.TreeCompressionService = TreeCompressionService;
104//# sourceMappingURL=tree-compression-service.js.map
\No newline at end of file