@lonli-lokli/react-mosaic-component
Version:
A React Tiling Window Manager
99 lines (97 loc) • 3.71 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// libs/react-mosaic-component/src/lib/buttons/TabSplitButton.tsx
var TabSplitButton_exports = {};
__export(TabSplitButton_exports, {
TabSplitButton: () => TabSplitButton
});
module.exports = __toCommonJS(TabSplitButton_exports);
var import_classnames = __toESM(require("classnames"), 1);
var import_lodash_es = require("lodash-es");
var import_react = __toESM(require("react"), 1);
var import_contextTypes = require("../contextTypes.cjs");
var import_OptionalBlueprint = require("../util/OptionalBlueprint.cjs");
var import_MosaicButton = require("./MosaicButton.cjs");
var TabSplitButton = class extends import_react.default.PureComponent {
static contextType = import_contextTypes.MosaicContext;
render() {
return /* @__PURE__ */ import_react.default.createElement(
import_MosaicButton.DefaultToolbarButton,
{
title: "Split Tab Group",
className: (0, import_classnames.default)(
"split-button",
import_OptionalBlueprint.OptionalBlueprint.getIconClass(
this.context.blueprintNamespace,
"SPLIT_COLUMNS"
)
),
onClick: this.split
}
);
}
split = () => {
const { mosaicActions } = this.context;
const { path } = this.props;
if (mosaicActions.createNode == null) {
console.error(
"Operation invalid unless `createNode` is defined on Mosaic"
);
return;
}
Promise.resolve(mosaicActions.createNode()).then((newNode) => {
if (!newNode) return;
const currentNode = this.getCurrentTabsNode();
if (!currentNode) return;
const newSplitNode = {
type: "split",
direction: "row",
splitPercentages: [50, 50],
children: [currentNode, newNode]
};
mosaicActions.replaceWith(path, newSplitNode);
if (this.props.onClick) {
this.props.onClick();
}
}).catch(import_lodash_es.noop);
};
getCurrentTabsNode = () => {
const root = this.context.mosaicActions.getRoot();
if (!root) return null;
let currentNode = root;
for (const index of this.props.path) {
if (typeof currentNode === "object" && "children" in currentNode) {
currentNode = currentNode.children[index];
} else {
return null;
}
}
return currentNode;
};
};