@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
177 lines • 8.05 kB
JavaScript
import { __decorate, __param } from "tslib";
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
// *****************************************************************************
// Copyright (C) 2022 Ericsson 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 '../../../../src/browser/tree/tree-compression/tree-compression.css';
import { injectable, inject } from 'inversify';
import { ContextMenuRenderer } from '../../context-menu-renderer.js';
import { CompressionToggle, TreeCompressionService } from './tree-compression-service.js';
import { TreeNode } from '../tree.js';
import { TreeProps } from '../tree-widget.js';
import { SelectableTreeNode, TreeSelection } from '../tree-selection.js';
import { ExpandableTreeNode } from '../tree-expansion.js';
import { TreeViewWelcomeWidget } from '../tree-view-welcome-widget.js';
import { CompressedTreeModel } from './compressed-tree-model.js';
let CompressedTreeWidget = class CompressedTreeWidget extends TreeViewWelcomeWidget {
constructor(props, model, contextMenuRenderer) {
super(props, model, contextMenuRenderer);
this.model = model;
this.rows = new Map();
}
toggleCompression(newCompression = !this.compressionToggle.compress) {
if (newCompression !== this.compressionToggle.compress) {
this.compressionToggle.compress = newCompression;
this.updateRows();
}
}
shouldRenderIndent(node) {
return !this.compressionToggle.compress
|| !this.compressionService.isCompressionParticipant(node)
|| this.compressionService.getCompressionHead(node) === node;
}
shouldDisplayNode(node) {
if (this.compressionToggle.compress && this.compressionService.isCompressionParticipant(node) && !this.compressionService.isCompressionHead(node)) {
return false;
}
return super.shouldDisplayNode(node);
}
getDepthForNode(node, depths) {
if (!this.compressionToggle.compress) {
return super.getDepthForNode(node, depths);
}
const parent = this.compressionService.getCompressionHead(node.parent) ?? node.parent;
const parentDepth = depths.get(parent);
return parentDepth === undefined ? 0 : TreeNode.isVisible(node.parent) ? parentDepth + 1 : parentDepth;
}
toNodeRow(node, index, depth) {
if (!this.compressionToggle.compress) {
return super.toNodeRow(node, index, depth);
}
const row = { node, index, depth };
if (this.compressionService.isCompressionHead(node)) {
row.compressionChain = this.compressionService.getCompressionChain(node);
}
return row;
}
doRenderNodeRow({ node, depth, compressionChain }) {
const nodeProps = { depth, compressionChain };
return _jsxs(_Fragment, { children: [this.renderIndent(node, nodeProps), this.renderNode(node, nodeProps)] });
}
rowIsSelected(node, props) {
if (this.compressionToggle.compress && props.compressionChain) {
return props.compressionChain.some(participant => SelectableTreeNode.isSelected(participant));
}
return SelectableTreeNode.isSelected(node);
}
getCaptionAttributes(node, props) {
const operativeNode = props.compressionChain?.tail() ?? node;
return super.getCaptionAttributes(operativeNode, props);
}
getCaptionChildren(node, props) {
if (!this.compressionToggle.compress || !props.compressionChain) {
return super.getCaptionChildren(node, props);
}
return props.compressionChain.map((subNode, index, self) => {
const classes = ['theia-tree-compressed-label-part'];
if (SelectableTreeNode.isSelected(subNode)) {
classes.push('theia-tree-compressed-selected');
}
const handlers = this.getCaptionChildEventHandlers(subNode, props);
const caption = _jsx("span", { className: classes.join(' '), ...handlers, children: super.getCaptionChildren(subNode, props) }, subNode.id);
if (index === self.length - 1) {
return caption;
}
return [
caption,
_jsx("span", { className: 'theia-tree-compressed-label-separator', children: this.getSeparatorContent(node, props) }, subNode + '-separator')
];
});
}
getCaptionChildEventHandlers(node, props) {
return {
onClick: event => (event.stopPropagation(), this.handleClickEvent(node, event)),
onDoubleClick: event => (event.stopPropagation(), this.handleDblClickEvent(node, event)),
onContextMenu: event => (event.stopPropagation(), this.handleContextMenuEvent(node, event)),
};
}
handleUp(event) {
if (!this.compressionToggle.compress) {
return super.handleUp(event);
}
const type = this.props.multiSelect && this.hasShiftMask(event) ? TreeSelection.SelectionType.RANGE : undefined;
this.model.selectPrevRow(type);
this.node.focus();
}
handleDown(event) {
if (!this.compressionToggle.compress) {
return super.handleDown(event);
}
const type = this.props.multiSelect && this.hasShiftMask(event) ? TreeSelection.SelectionType.RANGE : undefined;
this.model.selectNextRow(type);
this.node.focus();
}
async handleLeft(event) {
if (!this.compressionToggle.compress) {
return super.handleLeft(event);
}
if (Boolean(this.props.multiSelect) && (this.hasCtrlCmdMask(event) || this.hasShiftMask(event))) {
return;
}
const active = this.focusService.focusedNode;
if (ExpandableTreeNode.isExpanded(active)
&& (this.compressionService.isCompressionHead(active)
|| !this.compressionService.isCompressionParticipant(active))) {
await this.model.collapseNode(active);
}
else {
this.model.selectParent();
}
}
async handleRight(event) {
if (!this.compressionToggle.compress) {
return super.handleRight(event);
}
if (Boolean(this.props.multiSelect) && (this.hasCtrlCmdMask(event) || this.hasShiftMask(event))) {
return;
}
const active = this.focusService.focusedNode;
if (ExpandableTreeNode.isCollapsed(active)
&& (!this.compressionService.isCompressionParticipant(active)
|| this.compressionService.isCompressionTail(active))) {
await this.model.expandNode(active);
}
else if (ExpandableTreeNode.is(active)) {
this.model.selectNextNode();
}
}
getSeparatorContent(node, props) {
return '/';
}
};
__decorate([
inject(CompressionToggle)
], CompressedTreeWidget.prototype, "compressionToggle", void 0);
__decorate([
inject(TreeCompressionService)
], CompressedTreeWidget.prototype, "compressionService", void 0);
CompressedTreeWidget = __decorate([
injectable(),
__param(0, inject(TreeProps)),
__param(1, inject(CompressedTreeModel)),
__param(2, inject(ContextMenuRenderer))
], CompressedTreeWidget);
export { CompressedTreeWidget };
//# sourceMappingURL=compressed-tree-widget.js.map