@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
128 lines • 4.53 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2018 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { __decorate } from "tslib";
/* eslint-disable @typescript-eslint/no-explicit-any */
import { injectable } from 'inversify';
import { TreeImpl, CompositeTreeNode, SelectableTreeNode, ExpandableTreeNode } from '../tree/index.js';
import { CompositeTreeElement } from './tree-source.js';
let SourceTree = class SourceTree extends TreeImpl {
async resolveChildren(parent) {
const elements = await this.resolveElements(parent);
const nodes = [];
let index = 0;
for (const element of elements) {
if (element.visible !== false) {
nodes.push(this.toNode(element, index++, parent));
}
}
return nodes;
}
resolveElements(parent) {
if (TreeSourceNode.is(parent)) {
return parent.source.getElements();
}
return parent.element.getElements();
}
toNode(element, index, parent) {
const id = element.id ? String(element.id) : (parent.id + ':' + index);
const name = id;
const existing = this.getNode(id);
const updated = existing && Object.assign(existing, { element, parent });
if (CompositeTreeElement.hasElements(element)) {
const expand = element.expandByDefault ? element.expandByDefault() : false;
if (updated) {
if (!ExpandableTreeNode.is(updated)) {
Object.assign(updated, { expanded: expand });
}
if (!CompositeTreeNode.is(updated)) {
Object.assign(updated, { children: [] });
}
return updated;
}
return {
element,
parent,
id,
name,
selected: false,
expanded: expand,
children: []
};
}
if (CompositeTreeElementNode.is(updated)) {
delete updated.expanded;
delete updated.children;
}
if (updated) {
if (ExpandableTreeNode.is(updated)) {
delete updated.expanded;
}
if (CompositeTreeNode.is(updated)) {
delete updated.children;
}
return updated;
}
return {
element,
parent,
id,
name,
selected: false
};
}
};
SourceTree = __decorate([
injectable()
], SourceTree);
export { SourceTree };
export var TreeElementNode;
(function (TreeElementNode) {
function is(node) {
return SelectableTreeNode.is(node) && 'element' in node;
}
TreeElementNode.is = is;
})(TreeElementNode || (TreeElementNode = {}));
export var CompositeTreeElementNode;
(function (CompositeTreeElementNode) {
function is(node) {
return TreeElementNode.is(node) && CompositeTreeNode.is(node) && ExpandableTreeNode.is(node) && !!node.visible;
}
CompositeTreeElementNode.is = is;
})(CompositeTreeElementNode || (CompositeTreeElementNode = {}));
export var TreeSourceNode;
(function (TreeSourceNode) {
function is(node) {
return CompositeTreeNode.is(node) && !node.visible && 'source' in node;
}
TreeSourceNode.is = is;
function to(source) {
if (!source) {
return source;
}
const id = source.id || '__source__';
return {
id,
name: id,
visible: false,
children: [],
source,
parent: undefined,
selected: false
};
}
TreeSourceNode.to = to;
})(TreeSourceNode || (TreeSourceNode = {}));
//# sourceMappingURL=source-tree.js.map