@metacell/geppetto-meta-client
Version:
Geppetto web frontend. Geppetto is an open-source platform to build web-based tools to visualize and simulate neuroscience data and models.
62 lines (60 loc) • 2.03 kB
JavaScript
import { TabsetPosition } from "../model";
import * as FlexLayout from 'flexlayout-react';
/**
* Create a new tab set.
*
* @param model
* @param {string} tabsetID the id of the tab set
* @param position
* @param weight
* @private
*/
export function createTabSet(model, tabsetID) {
var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TabsetPosition.RIGHT;
var weight = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 50;
var rootNode = model.getRoot();
// @ts-expect-error: Constructor is declared as "internal" in the flex-layout source code
var tabset = new FlexLayout.TabSetNode(model, {
id: tabsetID
});
switch (position) {
case TabsetPosition.RIGHT:
rootNode.getChildren().forEach(function (node) {
return node.setWeight(100 - weight);
});
rootNode.addChild(tabset);
break;
case TabsetPosition.LEFT:
rootNode.getChildren().forEach(function (node) {
return node.setWeight(100 - weight);
});
rootNode.addChild(tabset, 0);
break;
case TabsetPosition.BOTTOM:
case TabsetPosition.TOP:
{
// @ts-expect-error: Constructor is declared as "internal" in the flex-layout source code
var hrow = new FlexLayout.RowNode(model, rootNode.windowId, {});
if (position === TabsetPosition.BOTTOM) {
hrow.addChild(tabset);
} else {
hrow.addChild(tabset, 0);
}
rootNode.getChildren().forEach(function (child) {
if (child.getWeight) {
var newWeight = child.getWeight() / 2;
child.setWeight(newWeight);
hrow.addChild(child, 0);
}
});
rootNode.removeAll();
rootNode.addChild(hrow);
tabset.setWeight(80);
hrow.setWeight(100);
}
}
return tabset;
}
export function moveWidget(model, widget) {
model.doAction(FlexLayout.Actions.moveNode(widget.id, widget.panelName, FlexLayout.DockLocation.CENTER, widget.pos));
}