react-layman
Version:
A dynamic tiling layout manager made for React
1,568 lines (1,566 loc) • 54.9 kB
JavaScript
import './index.css';var Wt = Object.defineProperty;
var kt = (t, r, n) => r in t ? Wt(t, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[r] = n;
var ae = (t, r, n) => kt(t, typeof r != "symbol" ? r + "" : r, n);
import { v4 as It } from "uuid";
import tt, { createContext as rt, useReducer as At, useState as U, useContext as Q, useEffect as z, useRef as pe, useMemo as nt } from "react";
import { DndProvider as Lt, useDrag as je, useDrop as Ft, useDragLayer as at } from "react-dnd";
import { HTML5Backend as Nt } from "react-dnd-html5-backend";
import b from "lodash";
import { VscClose as Se, VscAdd as Vt, VscEllipsis as $t, VscLayoutSidebarRight as Mt, VscLayoutSidebarLeft as zt, VscLayoutPanel as Qe } from "react-icons/vsc";
import { createPortal as Yt } from "react-dom";
import { LuMinimize as Bt, LuMaximize as Ut } from "react-icons/lu";
class re {
/** Creates an instance of the TabData class. */
constructor(r, n = {}) {
// private UUID representing the tab
ae(this, "id");
// Is the tab currently selected in a window?
ae(this, "isSelected");
// Display name of tab
ae(this, "name");
// Optional data attached to each tab
ae(this, "options");
this.id = It(), this.isSelected = !1, this.name = r, this.options = n;
}
}
var Re = { exports: {} }, ie = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ze;
function Ht() {
if (Ze) return ie;
Ze = 1;
var t = tt, r = Symbol.for("react.element"), n = Symbol.for("react.fragment"), a = Object.prototype.hasOwnProperty, o = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, g = { key: !0, ref: !0, __self: !0, __source: !0 };
function p(f, c, P) {
var s, m = {}, d = null, y = null;
P !== void 0 && (d = "" + P), c.key !== void 0 && (d = "" + c.key), c.ref !== void 0 && (y = c.ref);
for (s in c) a.call(c, s) && !g.hasOwnProperty(s) && (m[s] = c[s]);
if (f && f.defaultProps) for (s in c = f.defaultProps, c) m[s] === void 0 && (m[s] = c[s]);
return { $$typeof: r, type: f, key: d, ref: y, props: m, _owner: o.current };
}
return ie.Fragment = n, ie.jsx = p, ie.jsxs = p, ie;
}
var oe = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var et;
function Gt() {
return et || (et = 1, process.env.NODE_ENV !== "production" && function() {
var t = tt, r = Symbol.for("react.element"), n = Symbol.for("react.portal"), a = Symbol.for("react.fragment"), o = Symbol.for("react.strict_mode"), g = Symbol.for("react.profiler"), p = Symbol.for("react.provider"), f = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), P = Symbol.for("react.suspense"), s = Symbol.for("react.suspense_list"), m = Symbol.for("react.memo"), d = Symbol.for("react.lazy"), y = Symbol.for("react.offscreen"), x = Symbol.iterator, k = "@@iterator";
function O(e) {
if (e === null || typeof e != "object")
return null;
var i = x && e[x] || e[k];
return typeof i == "function" ? i : null;
}
var h = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function v(e) {
{
for (var i = arguments.length, l = new Array(i > 1 ? i - 1 : 0), w = 1; w < i; w++)
l[w - 1] = arguments[w];
T("error", e, l);
}
}
function T(e, i, l) {
{
var w = h.ReactDebugCurrentFrame, S = w.getStackAddendum();
S !== "" && (i += "%s", l = l.concat([S]));
var _ = l.map(function(R) {
return String(R);
});
_.unshift("Warning: " + i), Function.prototype.apply.call(console[e], console, _);
}
}
var E = !1, K = !1, N = !1, W = !1, V = !1, D;
D = Symbol.for("react.module.reference");
function A(e) {
return !!(typeof e == "string" || typeof e == "function" || e === a || e === g || V || e === o || e === P || e === s || W || e === y || E || K || N || typeof e == "object" && e !== null && (e.$$typeof === d || e.$$typeof === m || e.$$typeof === p || e.$$typeof === f || e.$$typeof === c || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === D || e.getModuleId !== void 0));
}
function B(e, i, l) {
var w = e.displayName;
if (w)
return w;
var S = i.displayName || i.name || "";
return S !== "" ? l + "(" + S + ")" : l;
}
function H(e) {
return e.displayName || "Context";
}
function $(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case a:
return "Fragment";
case n:
return "Portal";
case g:
return "Profiler";
case o:
return "StrictMode";
case P:
return "Suspense";
case s:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case f:
var i = e;
return H(i) + ".Consumer";
case p:
var l = e;
return H(l._context) + ".Provider";
case c:
return B(e, e.render, "ForwardRef");
case m:
var w = e.displayName || null;
return w !== null ? w : $(e.type) || "Memo";
case d: {
var S = e, _ = S._payload, R = S._init;
try {
return $(R(_));
} catch {
return null;
}
}
}
return null;
}
var q = Object.assign, C = 0, L, Oe, We, ke, Ie, Ae, Le;
function Fe() {
}
Fe.__reactDisabledLog = !0;
function st() {
{
if (C === 0) {
L = console.log, Oe = console.info, We = console.warn, ke = console.error, Ie = console.group, Ae = console.groupCollapsed, Le = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: Fe,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
C++;
}
}
function lt() {
{
if (C--, C === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: q({}, e, {
value: L
}),
info: q({}, e, {
value: Oe
}),
warn: q({}, e, {
value: We
}),
error: q({}, e, {
value: ke
}),
group: q({}, e, {
value: Ie
}),
groupCollapsed: q({}, e, {
value: Ae
}),
groupEnd: q({}, e, {
value: Le
})
});
}
C < 0 && v("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var me = h.ReactCurrentDispatcher, we;
function le(e, i, l) {
{
if (we === void 0)
try {
throw Error();
} catch (S) {
var w = S.stack.trim().match(/\n( *(at )?)/);
we = w && w[1] || "";
}
return `
` + we + e;
}
}
var be = !1, ce;
{
var ct = typeof WeakMap == "function" ? WeakMap : Map;
ce = new ct();
}
function Ne(e, i) {
if (!e || be)
return "";
{
var l = ce.get(e);
if (l !== void 0)
return l;
}
var w;
be = !0;
var S = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var _;
_ = me.current, me.current = null, st();
try {
if (i) {
var R = function() {
throw Error();
};
if (Object.defineProperty(R.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(R, []);
} catch (X) {
w = X;
}
Reflect.construct(e, [], R);
} else {
try {
R.call();
} catch (X) {
w = X;
}
e.call(R.prototype);
}
} else {
try {
throw Error();
} catch (X) {
w = X;
}
e();
}
} catch (X) {
if (X && w && typeof X.stack == "string") {
for (var j = X.stack.split(`
`), M = w.stack.split(`
`), I = j.length - 1, F = M.length - 1; I >= 1 && F >= 0 && j[I] !== M[F]; )
F--;
for (; I >= 1 && F >= 0; I--, F--)
if (j[I] !== M[F]) {
if (I !== 1 || F !== 1)
do
if (I--, F--, F < 0 || j[I] !== M[F]) {
var G = `
` + j[I].replace(" at new ", " at ");
return e.displayName && G.includes("<anonymous>") && (G = G.replace("<anonymous>", e.displayName)), typeof e == "function" && ce.set(e, G), G;
}
while (I >= 1 && F >= 0);
break;
}
}
} finally {
be = !1, me.current = _, lt(), Error.prepareStackTrace = S;
}
var te = e ? e.displayName || e.name : "", Ke = te ? le(te) : "";
return typeof e == "function" && ce.set(e, Ke), Ke;
}
function dt(e, i, l) {
return Ne(e, !1);
}
function ut(e) {
var i = e.prototype;
return !!(i && i.isReactComponent);
}
function de(e, i, l) {
if (e == null)
return "";
if (typeof e == "function")
return Ne(e, ut(e));
if (typeof e == "string")
return le(e);
switch (e) {
case P:
return le("Suspense");
case s:
return le("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case c:
return dt(e.render);
case m:
return de(e.type, i, l);
case d: {
var w = e, S = w._payload, _ = w._init;
try {
return de(_(S), i, l);
} catch {
}
}
}
return "";
}
var ue = Object.prototype.hasOwnProperty, Ve = {}, $e = h.ReactDebugCurrentFrame;
function fe(e) {
if (e) {
var i = e._owner, l = de(e.type, e._source, i ? i.type : null);
$e.setExtraStackFrame(l);
} else
$e.setExtraStackFrame(null);
}
function ft(e, i, l, w, S) {
{
var _ = Function.call.bind(ue);
for (var R in e)
if (_(e, R)) {
var j = void 0;
try {
if (typeof e[R] != "function") {
var M = Error((w || "React class") + ": " + l + " type `" + R + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[R] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw M.name = "Invariant Violation", M;
}
j = e[R](i, R, w, l, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (I) {
j = I;
}
j && !(j instanceof Error) && (fe(S), v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", w || "React class", l, R, typeof j), fe(null)), j instanceof Error && !(j.message in Ve) && (Ve[j.message] = !0, fe(S), v("Failed %s type: %s", l, j.message), fe(null));
}
}
}
var ht = Array.isArray;
function Pe(e) {
return ht(e);
}
function gt(e) {
{
var i = typeof Symbol == "function" && Symbol.toStringTag, l = i && e[Symbol.toStringTag] || e.constructor.name || "Object";
return l;
}
}
function pt(e) {
try {
return Me(e), !1;
} catch {
return !0;
}
}
function Me(e) {
return "" + e;
}
function ze(e) {
if (pt(e))
return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", gt(e)), Me(e);
}
var ne = h.ReactCurrentOwner, vt = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Ye, Be, xe;
xe = {};
function mt(e) {
if (ue.call(e, "ref")) {
var i = Object.getOwnPropertyDescriptor(e, "ref").get;
if (i && i.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function wt(e) {
if (ue.call(e, "key")) {
var i = Object.getOwnPropertyDescriptor(e, "key").get;
if (i && i.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function bt(e, i) {
if (typeof e.ref == "string" && ne.current && i && ne.current.stateNode !== i) {
var l = $(ne.current.type);
xe[l] || (v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', $(ne.current.type), e.ref), xe[l] = !0);
}
}
function Pt(e, i) {
{
var l = function() {
Ye || (Ye = !0, v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", i));
};
l.isReactWarning = !0, Object.defineProperty(e, "key", {
get: l,
configurable: !0
});
}
}
function xt(e, i) {
{
var l = function() {
Be || (Be = !0, v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", i));
};
l.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: l,
configurable: !0
});
}
}
var yt = function(e, i, l, w, S, _, R) {
var j = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: r,
// Built-in properties that belong on the element
type: e,
key: i,
ref: l,
props: R,
// Record the component responsible for creating this element.
_owner: _
};
return j._store = {}, Object.defineProperty(j._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(j, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: w
}), Object.defineProperty(j, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: S
}), Object.freeze && (Object.freeze(j.props), Object.freeze(j)), j;
};
function Et(e, i, l, w, S) {
{
var _, R = {}, j = null, M = null;
l !== void 0 && (ze(l), j = "" + l), wt(i) && (ze(i.key), j = "" + i.key), mt(i) && (M = i.ref, bt(i, S));
for (_ in i)
ue.call(i, _) && !vt.hasOwnProperty(_) && (R[_] = i[_]);
if (e && e.defaultProps) {
var I = e.defaultProps;
for (_ in I)
R[_] === void 0 && (R[_] = I[_]);
}
if (j || M) {
var F = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
j && Pt(R, F), M && xt(R, F);
}
return yt(e, j, M, S, w, ne.current, R);
}
}
var ye = h.ReactCurrentOwner, Ue = h.ReactDebugCurrentFrame;
function ee(e) {
if (e) {
var i = e._owner, l = de(e.type, e._source, i ? i.type : null);
Ue.setExtraStackFrame(l);
} else
Ue.setExtraStackFrame(null);
}
var Ee;
Ee = !1;
function Te(e) {
return typeof e == "object" && e !== null && e.$$typeof === r;
}
function He() {
{
if (ye.current) {
var e = $(ye.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function Tt(e) {
return "";
}
var Ge = {};
function jt(e) {
{
var i = He();
if (!i) {
var l = typeof e == "string" ? e : e.displayName || e.name;
l && (i = `
Check the top-level render call using <` + l + ">.");
}
return i;
}
}
function qe(e, i) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var l = jt(i);
if (Ge[l])
return;
Ge[l] = !0;
var w = "";
e && e._owner && e._owner !== ye.current && (w = " It was passed a child from " + $(e._owner.type) + "."), ee(e), v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', l, w), ee(null);
}
}
function Xe(e, i) {
{
if (typeof e != "object")
return;
if (Pe(e))
for (var l = 0; l < e.length; l++) {
var w = e[l];
Te(w) && qe(w, i);
}
else if (Te(e))
e._store && (e._store.validated = !0);
else if (e) {
var S = O(e);
if (typeof S == "function" && S !== e.entries)
for (var _ = S.call(e), R; !(R = _.next()).done; )
Te(R.value) && qe(R.value, i);
}
}
}
function Rt(e) {
{
var i = e.type;
if (i == null || typeof i == "string")
return;
var l;
if (typeof i == "function")
l = i.propTypes;
else if (typeof i == "object" && (i.$$typeof === c || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
i.$$typeof === m))
l = i.propTypes;
else
return;
if (l) {
var w = $(i);
ft(l, e.props, "prop", w, e);
} else if (i.PropTypes !== void 0 && !Ee) {
Ee = !0;
var S = $(i);
v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", S || "Unknown");
}
typeof i.getDefaultProps == "function" && !i.getDefaultProps.isReactClassApproved && v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function Ct(e) {
{
for (var i = Object.keys(e.props), l = 0; l < i.length; l++) {
var w = i[l];
if (w !== "children" && w !== "key") {
ee(e), v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", w), ee(null);
break;
}
}
e.ref !== null && (ee(e), v("Invalid attribute `ref` supplied to `React.Fragment`."), ee(null));
}
}
function Je(e, i, l, w, S, _) {
{
var R = A(e);
if (!R) {
var j = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (j += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var M = Tt();
M ? j += M : j += He();
var I;
e === null ? I = "null" : Pe(e) ? I = "array" : e !== void 0 && e.$$typeof === r ? (I = "<" + ($(e.type) || "Unknown") + " />", j = " Did you accidentally export a JSX literal instead of a component?") : I = typeof e, v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", I, j);
}
var F = Et(e, i, l, S, _);
if (F == null)
return F;
if (R) {
var G = i.children;
if (G !== void 0)
if (w)
if (Pe(G)) {
for (var te = 0; te < G.length; te++)
Xe(G[te], e);
Object.freeze && Object.freeze(G);
} else
v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Xe(G, e);
}
return e === a ? Ct(F) : Rt(F), F;
}
}
function St(e, i, l) {
return Je(e, i, l, !0);
}
function Dt(e, i, l) {
return Je(e, i, l, !1);
}
var _t = Dt, Ot = St;
oe.Fragment = a, oe.jsx = _t, oe.jsxs = Ot;
}()), oe;
}
process.env.NODE_ENV === "production" ? Re.exports = Ht() : Re.exports = Gt();
var u = Re.exports;
function qt({ position: t, isDragging: r }) {
return /* @__PURE__ */ u.jsx(
"div",
{
className: "layman-drop-highlight",
style: {
...t,
visibility: r ? "visible" : "hidden",
opacity: r ? 0.2 : 0
}
}
);
}
const Y = (t, r) => {
if (r.length === 0) return t;
const n = "children." + r.join(".children.");
return b.get(t, n);
}, De = (t, r) => {
if (!t)
return {
tabs: [r.tab]
};
const n = "children." + r.path.join(".children."), a = Y(t, r.path);
if (!a || !("tabs" in a)) return t;
const o = {
...a,
tabs: [...a.tabs, r.tab]
};
return r.path.length == 0 ? o : b.set(b.cloneDeep(t), n, o);
}, Xt = (t, r) => {
if (!t) return t;
const n = "children." + r.path.join(".children."), a = Y(t, r.path);
if (!a || !("tabs" in a)) return t;
const o = a.tabs.filter((c) => c.id !== r.tab.id);
let g = a.selectedIndex;
const p = b.indexOf(a.tabs, r.tab);
if (a.selectedIndex && p <= a.selectedIndex && (g = Math.max(0, a.selectedIndex - 1)), o.length === 0)
return ve(t, {
type: "removeWindow",
path: r.path
});
const f = {
...a,
tabs: o,
selectedIndex: g
};
return r.path.length == 0 ? f : b.set(b.cloneDeep(t), n, f);
}, Jt = (t, r) => {
if (!t) return t;
const n = "children." + r.path.join(".children."), a = Y(t, r.path);
if (!a || !("tabs" in a)) return t;
const o = {
...a,
selectedIndex: a.tabs.findIndex((g) => g.id === r.tab.id)
};
return r.path.length == 0 ? o : b.set(b.cloneDeep(t), n, o);
}, Kt = (t, r) => {
if (!t) return t;
const n = Y(t, r.newPath);
if (!n || !("tabs" in n)) return t;
let a = t;
return r.path.length === 1 && r.path[0] === -1 || (a = ve(t, {
type: "removeTab",
path: r.path,
tab: r.tab
})), r.placement === "center" ? De(a, {
type: "addTab",
path: r.newPath,
tab: r.tab
}) : _e(a, {
type: "addWindow",
path: r.newPath,
window: {
tabs: [r.tab],
selectedIndex: 0
},
placement: r.placement
});
}, Qt = (t, r) => {
if (!t) return t;
const n = b.dropRight(r.path), a = "children." + n.join(".children."), o = Y(t, n);
if (!o || !("children" in o))
return;
const g = o.children.find((d, y) => y === b.last(r.path)), p = g ? g.viewPercent : void 0, f = o.children.filter((d, y) => y !== b.last(r.path)).map((d) => {
if (d)
return {
...d,
viewPercent: p ? (d.viewPercent ? d.viewPercent : 100 / o.children.length) * 100 / (100 - p) : (d.viewPercent ? d.viewPercent : 100 / o.children.length) * o.children.length / (o.children.length - 1)
};
});
if (f.length != 1) {
const d = {
...o,
children: f
};
return n.length == 0 ? d : b.set(b.cloneDeep(t), a, d);
}
const c = f[0];
if ("tabs" in c)
return n.length == 0 ? { ...c, viewPercent: o.viewPercent } : b.set(b.cloneDeep(t), a, { ...c, viewPercent: o.viewPercent });
const P = b.dropRight(n), s = "children." + P.join(".children."), m = Y(t, P);
if (!m || !("children" in m)) return t;
if (m.direction === c.direction) {
const d = b.last(n), y = {
...m,
children: [
...m.children.slice(0, d).map((x) => {
if (x)
return {
...x,
viewPercent: x.viewPercent ? x.viewPercent * m.children.length / (m.children.length + c.children.length - 1) : x.viewPercent
};
}),
...c.children.map((x) => {
if (x)
return {
...x,
viewPercent: x.viewPercent ? x.viewPercent * c.children.length / (m.children.length + c.children.length - 1) : x.viewPercent
};
}),
...m.children.slice(d + 1).map((x) => {
if (x)
return {
...x,
viewPercent: x.viewPercent ? x.viewPercent * m.children.length / (m.children.length + c.children.length - 1) : x.viewPercent
};
})
]
};
return P.length == 0 ? y : b.set(b.cloneDeep(t), s, y);
} else
return P.length == 0 ? f[0] : b.set(b.cloneDeep(t), a, f[0]);
}, _e = (t, r) => {
if (!t) return t;
const n = "children." + b.dropRight(r.path).join(".children."), a = Y(t, b.dropRight(r.path));
if (!a) return t;
if (!("children" in a)) {
const p = r.placement === "top" || r.placement === "bottom", f = r.placement === "top" || r.placement === "left" ? [r.window, a] : [a, r.window];
return {
direction: p ? "column" : "row",
children: f
};
}
const o = r.placement === "top" || r.placement === "bottom", g = r.placement === "bottom" || r.placement === "right" ? b.last(r.path) + 1 : b.last(r.path);
if (o && a.direction === "column" || !o && a.direction === "row") {
const p = {
...a,
children: [
...a.children.slice(0, g).map((f) => {
if (f)
return {
...f,
viewPercent: f.viewPercent ? f.viewPercent * a.children.length / (a.children.length + 1) : f.viewPercent
};
}),
{ ...r.window, viewPercent: 100 / (a.children.length + 1) },
...a.children.slice(g).map((f) => {
if (f)
return {
...f,
viewPercent: f.viewPercent ? f.viewPercent * a.children.length / (a.children.length + 1) : f.viewPercent
};
})
]
};
return r.path.length == 1 ? p : b.set(b.cloneDeep(t), n, p);
} else {
const p = Y(t, r.path);
if (!p || !("tabs" in p)) return t;
const f = r.placement === "top" || r.placement === "left" ? [r.window, { ...p, viewPercent: 50 }] : [{ ...p, viewPercent: 50 }, r.window], c = {
...a,
children: a.children.map(
(P, s) => s === b.last(r.path) ? {
direction: o ? "column" : "row",
children: f,
viewPercent: p.viewPercent
} : P
)
};
return r.path.length == 1 ? c : b.set(b.cloneDeep(t), n, c);
}
}, Zt = (t, r) => {
const n = r.path, a = r.newPath, o = b.takeWhile(n, (c, P) => c === a[P]).length;
if (o != n.length - 1) {
if (o != n.length - 2)
return a;
const c = b.clone(a), P = b.dropRight(r.path), s = Y(t, P);
if (!s || !("children" in s)) return c;
const m = b.dropRight(P), d = Y(t, m);
if (!d || !("children" in d)) return c;
const y = s.children[b.last(n) == 1 ? 0 : 1];
if (!y || !("children" in y))
return c;
if (d.direction === y.direction)
return c[o] > n[o] && (c[o] += y.children.length - 1), c;
}
const g = b.clone(a);
a[o] > n[o] && (g[o] = a[o] - 1);
const p = b.dropRight(n), f = Y(t, p);
if (!f || !("children" in f))
return g;
if (f.children.length == 2) {
g.splice(o, 1);
const c = b.dropRight(p), P = Y(t, c);
if (!P || !("children" in P))
return g;
const s = f.children[b.last(n) == 1 ? 0 : 1];
if (!s || !("children" in s))
return g;
P.direction === s.direction && (g[o - 1] += g[o], g.splice(o, 1));
}
return g;
}, er = (t, r) => {
const n = Y(t, r.path);
if (!n || !("tabs" in n)) return t;
const a = ve(t, {
type: "removeWindow",
path: r.path
}), o = Zt(t, r);
if (r.placement === "center") {
let g = b.cloneDeep(a);
return r.window.tabs.forEach((p) => {
g = De(g, {
type: "addTab",
path: o,
tab: p
});
}), g;
} else
return _e(a, {
type: "addWindow",
path: o,
window: r.window,
placement: r.placement
});
}, tr = (t, r) => {
if (!t) return t;
const n = Y(t, r.path);
if (!n || !("children" in n)) return t;
const a = "children." + r.path.join(".children."), o = n.children.length, g = n.children[r.index].viewPercent ?? 100 / o, p = n.children[r.index + 1].viewPercent ?? 100 / o, f = r.newSplitPercentage, c = g + p - f, P = b.cloneDeep(n);
return P.children[r.index].viewPercent = f, P.children[r.index + 1].viewPercent = c, r.path.length == 0 ? P : b.set(b.cloneDeep(t), a, P);
}, he = (t, r) => {
if (!t)
return {
tabs: [r.tab]
};
if ("tabs" in t)
return {
...t,
tabs: [...t.tabs, r.tab],
selectedIndex: t.tabs.length
};
if (r.heuristic === "topleft") {
const n = [...t.children];
return n[0] = he(n[0], r), { ...t, children: n };
} else if (r.heuristic === "topright") {
const n = [...t.children];
return t.direction === "column" ? n[0] = he(n[0], r) : n[n.length - 1] = he(n[n.length - 1], r), { ...t, children: n };
}
return t;
}, it = (t) => {
if (!t || "tabs" in t)
return t;
const n = 100 / t.children.length;
return {
...t,
children: t.children.map((a) => ({
...it(a),
viewPercent: n
}))
};
}, ve = (t, r) => {
switch (r.type) {
case "addTab":
return De(t, r);
case "removeTab":
return Xt(t, r);
case "selectTab":
return Jt(t, r);
case "moveTab":
return Kt(t, r);
case "addWindow":
return _e(t, r);
case "removeWindow":
return Qt(t, r);
case "moveWindow":
return er(t, r);
case "moveSeparator":
return tr(t, r);
case "addTabWithHeuristic":
return he(t, r);
case "autoArrange":
return it(t);
default:
throw new Error("Unknown action: " + r);
}
}, rr = {
globalContainerSize: { top: 0, left: 0, width: 0, height: 0 },
setGlobalContainerSize: () => {
},
layout: { tabs: [] },
layoutDispatch: () => {
},
setDropHighlightPosition: () => {
},
globalDragging: !1,
setGlobalDragging: () => {
},
draggedWindowTabs: [],
setDraggedWindowTabs: () => {
},
windowDragStartPosition: { x: 0, y: 0 },
setWindowDragStartPosition: () => {
},
renderPane: () => /* @__PURE__ */ u.jsx(u.Fragment, {}),
renderTab: () => /* @__PURE__ */ u.jsx(u.Fragment, {}),
mutable: !1,
toolbarButtons: [],
renderNull: /* @__PURE__ */ u.jsx(u.Fragment, {})
}, Z = rt(rr), wr = ({
initialLayout: t,
renderPane: r,
renderTab: n,
renderNull: a,
mutable: o = !1,
toolbarButtons: g = [],
children: p
}) => {
const [f, c] = At(ve, t), [P, s] = U({
top: 0,
left: 0,
width: 0,
height: 0
}), [m, d] = U({
top: 0,
left: 0,
width: 0,
height: 0
}), [y, x] = U([]), [k, O] = U({
x: 0,
y: 0
}), [h, v] = U(!1);
return /* @__PURE__ */ u.jsx(
Z.Provider,
{
value: {
globalContainerSize: P,
setGlobalContainerSize: s,
layout: f,
layoutDispatch: c,
setDropHighlightPosition: d,
globalDragging: h,
setGlobalDragging: v,
draggedWindowTabs: y,
setDraggedWindowTabs: x,
windowDragStartPosition: k,
setWindowDragStartPosition: O,
renderPane: r,
renderTab: n,
mutable: o,
toolbarButtons: g,
renderNull: a
},
children: /* @__PURE__ */ u.jsxs(Lt, { backend: Nt, children: [
/* @__PURE__ */ u.jsx(qt, { position: m, isDragging: h }),
/* @__PURE__ */ u.jsx("div", { id: "drag-window-border" }),
p
] })
}
);
}, ot = rt({
position: {
top: 0,
left: 0,
width: 0,
height: 0
},
path: [],
tab: new re(""),
isSelected: !1
}), br = () => Q(ot), nr = ({ tab: t, path: r, isSelected: n, onDelete: a, onMouseDown: o }) => {
const { renderTab: g, setGlobalDragging: p, mutable: f } = Q(Z), [{ isDragging: c }, P] = je({
type: Ce,
item: {
path: r,
tab: t
},
collect: (s) => ({
isDragging: s.isDragging()
})
});
return z(() => {
p(c);
}, [c, p]), /* @__PURE__ */ u.jsxs(
"div",
{
ref: P,
className: `tab ${n ? "selected" : ""}`,
style: {
visibility: c ? "hidden" : "visible",
width: c ? 0 : "auto"
},
children: [
n && /* @__PURE__ */ u.jsx("div", { className: "indicator" }),
/* @__PURE__ */ u.jsx("button", { className: "tab-selector", onMouseDown: o, children: g(t) }),
f && /* @__PURE__ */ u.jsx("button", { className: "close-tab", onClick: a, children: /* @__PURE__ */ u.jsx(Se, {}) })
]
}
);
}, ar = ({ dragRef: t, tab: r, onDelete: n, onMouseDown: a }) => {
const { renderTab: o, mutable: g } = Q(Z);
return /* @__PURE__ */ u.jsxs("div", { ref: t, className: "tab selected", children: [
/* @__PURE__ */ u.jsx("div", { className: "indicator" }),
/* @__PURE__ */ u.jsx("button", { className: "tab-selector", onMouseDown: a, children: o(r) }),
g && /* @__PURE__ */ u.jsx("button", { className: "close-tab", onClick: n, children: /* @__PURE__ */ u.jsx(Se, {}) })
] });
};
function J({
children: t,
...r
// Spread operator for capturing all additional props
}) {
return /* @__PURE__ */ u.jsx("button", { className: "toolbar-button", ...r, children: t });
}
function se({ path: t, position: r, placement: n }) {
const { globalContainerSize: a, layoutDispatch: o, setDropHighlightPosition: g } = Q(Z), p = pe({
top: 0,
left: 0,
width: 0,
height: 0
}), f = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--toolbar-height").trim(), 10) ?? 64, c = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--separator-thickness").trim(), 10) ?? 8;
z(() => {
const s = {
top: r.top + f,
left: r.left,
width: r.width - c,
height: r.height - f - c / 2
};
n === "top" && (s.height = s.height / 2), n === "bottom" && (s.top += s.height / 2, s.height = s.height / 2), n === "left" && (s.width = s.width / 2), n === "right" && (s.left += s.width / 2, s.width = s.width / 2), s.top += a.top, s.left += a.left, p.current = s;
}, [
a.left,
a.top,
n,
r.height,
r.left,
r.top,
r.width,
c,
f
]);
const [, P] = Ft(() => ({
accept: [Ce, ge],
drop: (s, m) => {
const d = m.getItemType();
d === Ce && "tab" in s ? o({
type: "moveTab",
tab: s.tab,
path: s.path ?? [-1],
newPath: t,
placement: n
}) : d === ge && "tabs" in s && o({
type: "moveWindow",
path: s.path,
newPath: t,
window: {
tabs: s.tabs,
selectedIndex: s.selectedIndex
},
placement: n
});
},
hover: () => g(p.current)
}));
return /* @__PURE__ */ u.jsx("div", { ref: P, className: `layman-window-drop-target ${n}` });
}
function ir(t) {
const r = pe(0);
return z(() => {
r.current = t;
}), r.current;
}
function or({ path: t, position: r, tabs: n, selectedIndex: a }) {
const {
layoutDispatch: o,
globalDragging: g,
setGlobalDragging: p,
setWindowDragStartPosition: f,
setDraggedWindowTabs: c,
mutable: P,
toolbarButtons: s
} = Q(Z), m = pe(null), d = ir(n.length), y = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--toolbar-height").trim(), 10) ?? 64, x = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--separator-thickness").trim(), 10) ?? 8, k = nt(() => {
const C = new Image();
return C.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", C;
}, []);
z(() => {
if (d !== void 0 && n.length > d && m.current) {
const C = m.current;
C.scrollWidth > C.clientWidth && (C.scrollLeft = C.scrollWidth);
}
}, [n.length, d]), z(() => {
o({
type: "selectTab",
path: t,
tab: n[a]
});
}, []);
const [O, h] = U({
top: r.top,
left: r.left
}), [v, T] = U({ x: 0, y: 0 }), [{ isDragging: E }, K, N] = je({
type: ge,
item: { path: t, tabs: n, selectedIndex: a },
collect: (C) => ({
isDragging: C.isDragging()
}),
end: () => {
c([]), f({ x: 0, y: 0 });
}
}), [{ singleTabIsDragging: W }, V, D] = je({
type: ge,
item: { path: t, tabs: n, selectedIndex: a },
collect: (C) => ({
singleTabIsDragging: C.isDragging()
}),
end: () => {
c([]), f({ x: 0, y: 0 });
}
});
z(() => {
N(k);
}, [N, k]), z(() => {
D(k);
}, [D, k]);
const { clientOffset: A } = at((C) => ({
clientOffset: C.getClientOffset()
}));
z(() => {
h(A && (E || W) ? {
top: A.y - v.y,
left: A.x - v.x
} : {
top: 0,
left: 0
});
}, [A, v.x, v.y, E, W]), z(() => {
p(E || W);
}, [E, p, W]), z(() => {
(E || W) && (c(n), f(v));
}, [v, E, c, f, W, n]);
const B = E || W ? 0.7 : 1, H = {
top: r.top + O.top,
left: r.left * B + O.left,
width: r.width - x,
height: y
}, $ = {
top: r.top + y,
left: r.left,
width: r.width - x,
height: r.height - y - x / 2
}, q = (C, L) => {
switch (C) {
case "splitTop":
return /* @__PURE__ */ u.jsx(
J,
{
onClick: () => o({
type: "addWindow",
path: t,
window: {
tabs: [new re("blank")],
selectedIndex: 0
},
placement: "top"
}),
children: /* @__PURE__ */ u.jsx(Qe, { style: { transform: "rotate(180deg)" } })
},
L
);
case "splitBottom":
return /* @__PURE__ */ u.jsx(
J,
{
onClick: () => o({
type: "addWindow",
path: t,
window: {
tabs: [new re("blank")],
selectedIndex: 0
},
placement: "bottom"
}),
children: /* @__PURE__ */ u.jsx(Qe, {})
},
L
);
case "splitLeft":
return /* @__PURE__ */ u.jsx(
J,
{
onClick: () => o({
type: "addWindow",
path: t,
window: {
tabs: [new re("blank")],
selectedIndex: 0
},
placement: "left"
}),
children: /* @__PURE__ */ u.jsx(zt, {})
},
L
);
case "splitRight":
return /* @__PURE__ */ u.jsx(
J,
{
onClick: () => o({
type: "addWindow",
path: t,
window: {
tabs: [new re("blank")],
selectedIndex: 0
},
placement: "right"
}),
children: /* @__PURE__ */ u.jsx(Mt, {})
},
L
);
case "maximize":
return /* @__PURE__ */ u.jsx(J, { onClick: () => {
}, children: /* @__PURE__ */ u.jsx(Ut, {}) }, L);
case "minimize":
return /* @__PURE__ */ u.jsx(J, { onClick: () => {
}, children: /* @__PURE__ */ u.jsx(Bt, {}) }, L);
case "close":
return /* @__PURE__ */ u.jsx(
J,
{
onClick: () => {
o({
type: "removeWindow",
path: t
});
},
children: /* @__PURE__ */ u.jsx(Se, {})
},
L
);
case "misc":
return /* @__PURE__ */ u.jsx(J, { onClick: () => {
}, children: /* @__PURE__ */ u.jsx($t, {}) }, L);
}
};
return /* @__PURE__ */ u.jsxs(u.Fragment, { children: [
/* @__PURE__ */ u.jsxs(
"div",
{
id: t.join(":"),
style: {
...H,
transform: `scale(${B})`,
transformOrigin: `${v.x}px bottom`,
zIndex: E || W ? 13 : 7,
pointerEvents: E || W ? "none" : "auto",
userSelect: E || W ? "none" : "auto"
},
className: "layman-toolbar",
children: [
/* @__PURE__ */ u.jsx("div", { ref: m, className: "tab-container", children: n.length > 1 ? n.map((C, L) => /* @__PURE__ */ u.jsx(
nr,
{
path: t,
tab: C,
isSelected: L == a,
onDelete: () => o({
type: "removeTab",
path: t,
tab: n[L]
}),
onMouseDown: () => o({
type: "selectTab",
path: t,
tab: n[L]
})
},
L
)) : /* @__PURE__ */ u.jsx(
ar,
{
dragRef: V,
tab: n[0],
onDelete: () => o({
type: "removeTab",
path: t,
tab: n[0]
}),
onMouseDown: (C) => {
T({
x: C.clientX,
y: C.clientY
}), o({
type: "selectTab",
path: t,
tab: n[0]
});
}
}
) }),
/* @__PURE__ */ u.jsx("div", { style: { display: "flex" }, children: /* @__PURE__ */ u.jsx(
J,
{
onClick: () => o({
type: "addTab",
path: t,
tab: new re("blank")
}),
children: /* @__PURE__ */ u.jsx(Vt, {})
}
) }),
/* @__PURE__ */ u.jsx(
"div",
{
ref: K,
className: "drag-area",
onMouseDown: (C) => {
T({
x: C.clientX,
y: C.clientY
});
}
}
),
/* @__PURE__ */ u.jsx("div", { className: "toolbar-button-container", children: P ? s == null ? void 0 : s.map((C, L) => q(C, L)) : ["maximize", "minimize", "misc"].map(
(C, L) => q(C, L)
) })
]
}
),
!(E || W) && /* @__PURE__ */ u.jsxs(
"div",
{
style: {
position: "absolute",
...$,
zIndex: 10,
margin: "calc(var(--separator-thickness, 8px) / 2)",
marginTop: 0,
pointerEvents: g ? "auto" : "none"
},
children: [
/* @__PURE__ */ u.jsx(se, { path: t, position: r, placement: "top" }),
/* @__PURE__ */ u.jsx(se, { path: t, position: r, placement: "bottom" }),
/* @__PURE__ */ u.jsx(se, { path: t, position: r, placement: "left" }),
/* @__PURE__ */ u.jsx(se, { path: t, position: r, placement: "right" }),
/* @__PURE__ */ u.jsx(se, { path: t, position: r, placement: "center" })
]
}
)
] });
}
function sr({ position: t, path: r, tab: n, isSelected: a }) {
const { globalContainerSize: o, renderPane: g, draggedWindowTabs: p, windowDragStartPosition: f } = Q(Z), c = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--separator-thickness").trim(), 10) ?? 8, P = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--toolbar-height").trim(), 10) ?? 64, s = p.includes(n), m = s ? 0.7 : 1, { clientOffset: d } = at((T) => ({
clientOffset: T.getClientOffset()
})), [y, x] = U({
top: t.top,
left: t.left
});
z(() => {
if (s && d) {
const T = f.x, E = f.y;
x({
top: d.y - E,
left: d.x - T
});
} else
x({
top: 0,
left: 0
});
}, [d, s, f.x, f.y]);
const [k, O] = U(null);
if (z(() => {
const T = document.getElementById("drag-window-border");
T ? O(T) : console.error("Element with id 'drag-window-border' not found.");
}, []), !k)
return null;
const h = {
top: t.top + P + c / 2 + y.top,
left: t.left * m + y.left,
width: t.width - c,
height: t.height - P - c
}, v = {
top: t.top + P / 2 * m + y.top + o.top,
left: t.left * m + y.left + o.left,
width: t.width - c + 2,
// +2 for thickness of the border itself
height: t.height - c / 2
};
return /* @__PURE__ */ u.jsxs(
"div",
{
id: n.id,
style: {
...h,
transform: `scale(${m})`,
transformOrigin: `${f.x}px top`,
zIndex: s ? 12 : 5,
pointerEvents: s ? "none" : "auto"
},
className: `layman-window ${a ? "selected" : "unselected"}`,
children: [
s && Yt(
/* @__PURE__ */ u.jsx(
"div",
{
style: {
position: "absolute",
zIndex: 12,
...v,
transform: `scale(${m})`,
transformOrigin: `${f.x}px top`,
border: "1px solid var(--indicator-color, #f97316)",
borderRadius: "var(--border-radius, 8px)",
pointerEvents: "none",
userSelect: "none"
}
}
),
document.getElementById("drag-window-border")
),
/* @__PURE__ */ u.jsx(
ot.Provider,
{
value: {
position: t,
path: r,
tab: n,
isSelected: a
},
children: g(n)
}
)
]
}
);
}
function lr({ nodePosition: t, position: r, index: n, direction: a, path: o, separators: g }) {
var O, h;
const { globalContainerSize: p, layoutDispatch: f } = Q(Z), [c, P] = U(!1), s = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--separator-thickness").trim(), 10) ?? 8, m = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--toolbar-height").trim(), 10) ?? 32, d = (O = g.find((v) => {
const T = [...o];
return T[T.length - 1] -= 1, b.isEqual(v.path, T);
})) == null ? void 0 : O.position, y = (h = g.find((v) => {
const T = [...o];
return T[T.length - 1] += 1, b.isEqual(v.path, T);
})) == null ? void 0 : h.position, x = (v) => {
v.preventDefault(), P(!1);
}, k = (v) => {
v.preventDefault(), P(!0);
};
return z(() => {
const v = (E) => {
const K = E.clientX - p.left, N = E.clientY - p.top, W = a === "column" ? 100 * ((N - (d ? d.top : t.top)) / t.height) : 100 * ((K - (d ? d.left : t.left)) / t.width), V = 100 * (m + s) / (a === "column" ? t.height : t.width), D = (a === "column" ? 100 * (((y ? y.top : t.top + t.height) - (d ? d.top : t.top)) / t.height) : 100 * (((y ? y.left : t.left + t.width) - (d ? d.left : t.left)) / t.width)) - V;
return b.clamp(W, V, D);
}, T = (E) => {
if (E.preventDefault(), !c) return;
const K = v(E), N = o.slice(0, o.length - 1);
f({
type: "moveSeparator",
path: N,
index: n,
newSplitPercentage: K
});
};
return document.addEventListener("mousemove", T), document.addEventListener("mouseup", x), () => {
document.removeEventListener(
"mousemove",
T
), document.removeEventListener(
"mouseup",
x
);
};
}, [
a,
p.left,
p.top,
n,
c,
f,
y,
t.height,
t.left,
t.top,
t.width,
o,
d,
s,
m
]), /* @__PURE__ */ u.jsx(
"div",
{
style: {
top: r.top,
left: r.left,
width: a === "column" ? r.width : s,
height: a === "row" ? r.height : s
},
className: `layman-separator ${a === "column" ? "layman-col-separator" : "layman-row-separator"}`,
onMouseDown: k,
onMouseUp: x,
children: /* @__PURE__ */ u.jsx("div", {})
}
);
}
function Pr() {
const { globalContainerSize: t, setGlobalContainerSize: r, layout: n, renderNull: a, draggedWindowTabs: o } = Q(Z), [g, p] = U([]), [f, c] = U([]), [P, s] = U([]), m = pe(null);
return z(() => {
const d = () => {
if (m.current) {
const { top: y, left: x, width: k, height: O } = m.current.getBoundingClientRect();
r({ top: y, left: x, width: k, height: O });
}
};
return d(), window.addEventListener("resize", d), () => {
window.removeEventListener("resize", d);
};
}, [r]), z(()