react-bwin 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,5 @@
1
1
  # React Binary Window
2
2
 
3
- A React tiling window manager based on [Binary Window](https://github.com/bhjsdev/bwin) library.
3
+ A React-based tiling window manager featuring resizable panes, drag-and-drop, and more. Built on top of the [Binary Window](https://github.com/bhjsdev/bwin) library.
4
4
 
5
- [Demo](https://bhjsdev.github.io/react-bwin/)
6
-
7
- ## Troubleshooting
8
-
9
- Check the following items if you run into issues, such as restoring a minimized pane.
10
-
11
- - Disable `StrictMode` in React 18 or later, including frameworks built on it (e.g., Next.js).
5
+ [Documentation](https://bhjsdev.github.io/bwin-docs/)
@@ -1,4 +1,4 @@
1
- import f, { useRef as A, useEffect as W, forwardRef as Y, useState as j, useImperativeHandle as K, useMemo as V } from "react";
1
+ import f, { useRef as M, useEffect as W, forwardRef as Y, useState as j, useImperativeHandle as K, useMemo as V } from "react";
2
2
  import { createPortal as Z } from "react-dom";
3
3
  var J = Object.defineProperty, Q = (e, t, i) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i, E = (e, t, i) => Q(e, typeof t != "symbol" ? t + "" : t, i);
4
4
  function tt(e = 0.7, t = 128) {
@@ -284,8 +284,8 @@ class b {
284
284
  if (h && s) {
285
285
  const a = h.width + s.width, d = i * (h.width / a), l = a + i;
286
286
  let c = h.width + d, u = l - c, g = s.left + d;
287
- const w = h.calcMinWidth(), m = s.calcMinWidth();
288
- i < 0 && (c < w && u > m ? (c = h.width, u = l - c, g = h.left + c) : u < m && c > w && (u = s.width, c = l - u, g = h.left + c)), h.width = c, s.width = u, s.left = g;
287
+ const m = h.calcMinWidth(), w = s.calcMinWidth();
288
+ i < 0 && (c < m && u > w ? (c = h.width, u = l - c, g = h.left + c) : u < w && c > m && (u = s.width, c = l - u, g = h.left + c)), h.width = c, s.width = u, s.left = g;
289
289
  }
290
290
  n && o && (n.width += i, o.width += i);
291
291
  }
@@ -300,8 +300,8 @@ class b {
300
300
  const a = n.height + o.height, d = i * (n.height / a), l = a + i;
301
301
  let c = n.height + d, u = l - c, g = o.top + d;
302
302
  if (i < 0) {
303
- const w = n.calcMinHeight(), m = o.calcMinHeight();
304
- c < w && u > m ? (c = n.height, u = l - c, g = n.top + c) : u < m && c > w && (u = o.height, c = l - u, g = n.top + c);
303
+ const m = n.calcMinHeight(), w = o.calcMinHeight();
304
+ c < m && u > w ? (c = n.height, u = l - c, g = n.top + c) : u < w && c > m && (u = o.height, c = l - u, g = n.top + c);
305
305
  }
306
306
  n.height = c, o.height = u, o.top = g;
307
307
  }
@@ -482,7 +482,7 @@ class gt extends b {
482
482
  super({ ...t, position: r.Root }), Object.assign(this, T);
483
483
  }
484
484
  }
485
- function M(e) {
485
+ function A(e) {
486
486
  const t = document.createElement("bw-pane");
487
487
  return t.style.top = `${e.top}px`, t.style.left = `${e.left}px`, t.style.width = `${e.width}px`, t.style.height = `${e.height}px`, t.setAttribute("sash-id", e.id), t.setAttribute("position", e.position), t;
488
488
  }
@@ -490,7 +490,7 @@ function ft(e) {
490
490
  const t = e.domNode;
491
491
  return t.style.top = `${e.top}px`, t.style.left = `${e.left}px`, t.style.width = `${e.width}px`, t.style.height = `${e.height}px`, t.setAttribute("position", e.position), t;
492
492
  }
493
- function wt(e, { size: t }) {
493
+ function mt(e, { size: t }) {
494
494
  const i = C(t);
495
495
  let n = e.width / 2;
496
496
  i && (i < 1 ? n = e.width * i : n = i);
@@ -506,10 +506,10 @@ function wt(e, { size: t }) {
506
506
  width: e.width - n,
507
507
  height: e.height,
508
508
  position: r.Right
509
- }), h = M(o);
509
+ }), h = A(o);
510
510
  return o.domNode = h, z(h, e.domNode), e.addChild(s), e.addChild(o), s;
511
511
  }
512
- function mt(e, { size: t }) {
512
+ function wt(e, { size: t }) {
513
513
  const i = C(t);
514
514
  let n = e.width / 2;
515
515
  i && (i < 1 ? n = e.width * i : n = i);
@@ -525,7 +525,7 @@ function mt(e, { size: t }) {
525
525
  width: n,
526
526
  height: e.height,
527
527
  position: r.Right
528
- }), h = M(s);
528
+ }), h = A(s);
529
529
  return s.domNode = h, z(h, e.domNode), e.addChild(s), e.addChild(o), o;
530
530
  }
531
531
  function bt(e, { size: t }) {
@@ -544,7 +544,7 @@ function bt(e, { size: t }) {
544
544
  width: e.width,
545
545
  height: e.height - n,
546
546
  position: r.Bottom
547
- }), h = M(o);
547
+ }), h = A(o);
548
548
  return o.domNode = h, z(h, e.domNode), e.addChild(s), e.addChild(o), s;
549
549
  }
550
550
  function Et(e, { size: t }) {
@@ -563,14 +563,14 @@ function Et(e, { size: t }) {
563
563
  width: e.width,
564
564
  height: n,
565
565
  position: r.Bottom
566
- }), h = M(s);
566
+ }), h = A(s);
567
567
  return s.domNode = h, z(h, e.domNode), e.addChild(s), e.addChild(o), o;
568
568
  }
569
569
  function yt(e, { position: t, size: i, minWidth: n, minHeight: s }) {
570
570
  if (t === r.Left)
571
- return wt(e, { size: i });
572
- if (t === r.Right)
573
571
  return mt(e, { size: i });
572
+ if (t === r.Right)
573
+ return wt(e, { size: i });
574
574
  if (t === r.Top)
575
575
  return bt(e, { size: i });
576
576
  if (t === r.Bottom)
@@ -578,19 +578,19 @@ function yt(e, { position: t, size: i, minWidth: n, minHeight: s }) {
578
578
  }
579
579
  const vt = {
580
580
  createPane(e) {
581
- const t = M(e);
581
+ const t = A(e);
582
582
  return e.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
583
583
  },
584
584
  // Intended to be overridden
585
585
  onPaneCreate(e, t) {
586
- t.store.content && e.append(N(t.store.content)), this != null && this.debug && (e.style.backgroundColor = tt(), e.innerHTML = "", e.append(G(e)));
586
+ t.store.content && e.append(N(t.store.content)), this != null && this.debug && (e.style.backgroundColor = tt(), e.innerHTML = "", e.append(I(e)));
587
587
  },
588
588
  updatePane(e) {
589
589
  return ft(e);
590
590
  },
591
591
  // Intended to be overridden
592
592
  onPaneUpdate(e, t) {
593
- this != null && this.debug && (e.innerHTML = "", e.append(G(e)));
593
+ this != null && this.debug && (e.innerHTML = "", e.append(I(e)));
594
594
  },
595
595
  /**
596
596
  * Add a pane into the target pane. The two panes become next to each other
@@ -618,7 +618,7 @@ const vt = {
618
618
  t.id = B(), i.children.length === 0 ? (t.domNode = i.domNode, t.domNode.setAttribute("sash-id", t.id), t.children = []) : (t.children = i.children, i.position === r.Left ? i.width = t.width : i.position === r.Right ? (i.width = t.width, i.left = t.left) : i.position === r.Top ? i.height = t.height : i.position === r.Bottom && (i.height = t.height, i.top = t.top)), this.update();
619
619
  }
620
620
  };
621
- function G(e) {
621
+ function I(e) {
622
622
  const t = document.createElement("pre");
623
623
  t.style.fontSize = "10px";
624
624
  const i = `
@@ -710,7 +710,7 @@ const Nt = {
710
710
  this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
711
711
  });
712
712
  }
713
- }, Mt = {
713
+ }, At = {
714
714
  activeDropPaneEl: null,
715
715
  // Intended to be overridden in `BinaryWindow` class
716
716
  onPaneDrop(e, t) {
@@ -730,10 +730,10 @@ const Nt = {
730
730
  this.onPaneDrop(e, i), typeof i.store.onDrop == "function" && i.store.onDrop(e, i), this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null;
731
731
  });
732
732
  }
733
- }, At = !1;
733
+ }, Mt = !1;
734
734
  class O {
735
735
  constructor(t) {
736
- E(this, "windowElement", null), E(this, "containerElement", null), E(this, "debug", At);
736
+ E(this, "windowElement", null), E(this, "containerElement", null), E(this, "debug", Mt);
737
737
  let i = null;
738
738
  t instanceof gt ? (i = t, this.rootSash = t) : (i = new ut(t), this.rootSash = i.buildSashTree()), this.fitContainer = i.fitContainer;
739
739
  }
@@ -758,7 +758,7 @@ O.assemble(
758
758
  zt,
759
759
  vt,
760
760
  Ct,
761
- Mt,
761
+ At,
762
762
  St
763
763
  );
764
764
  function k(e) {
@@ -821,17 +821,17 @@ const F = [Pt, xt, Rt], $t = {
821
821
  a > i && (i = a, n = s);
822
822
  }
823
823
  }), n) {
824
- const s = e.bwOriginalPosition, o = R(n);
825
- let h = 0;
824
+ const s = e.bwOriginalPosition, o = R(n), h = n.getAttribute("sash-id"), a = this.rootSash.getById(h);
825
+ let d = 0;
826
826
  if (s === r.Left || s === r.Right)
827
- h = t.width >= o.width ? o.width / 2 : t.width;
827
+ d = o.width - t.width < a.minWidth ? o.width / 2 : t.width;
828
828
  else if (s === r.Top || s === r.Bottom)
829
- h = t.height >= o.height ? o.height / 2 : t.height;
829
+ d = o.height - t.height < a.minHeight ? o.height / 2 : t.height;
830
830
  else
831
831
  throw new Error("[bwin] Invalid position when restoring glass");
832
832
  this.addPane(n.getAttribute("sash-id"), {
833
833
  position: s,
834
- size: h
834
+ size: d
835
835
  }).domNode.append(e.bwGlassElement);
836
836
  }
837
837
  },
@@ -870,7 +870,7 @@ const F = [Pt, xt, Rt], $t = {
870
870
  actions: void 0,
871
871
  draggable: !0
872
872
  };
873
- class I {
873
+ class G {
874
874
  constructor({
875
875
  title: t = S.title,
876
876
  content: i = S.content,
@@ -979,7 +979,7 @@ class _ extends O {
979
979
  super.enableFeatures(), this.enableDrag(), this.enableActions();
980
980
  }
981
981
  onPaneCreate(t, i) {
982
- const n = new I({ ...i.store, sash: i, binaryWindow: this });
982
+ const n = new G({ ...i.store, sash: i, binaryWindow: this });
983
983
  t.innerHTML = "", t.append(n.domNode), this.debug && n.contentElement.prepend(`${i.id}`);
984
984
  }
985
985
  onPaneUpdate() {
@@ -992,7 +992,7 @@ class _ extends O {
992
992
  * @returns {Sash} - The newly created Sash
993
993
  */
994
994
  addPane(t, i) {
995
- const { position: n, size: s, ...o } = i, h = super.addPane(t, { position: n, size: s }), a = new I({ ...o, sash: h, binaryWindow: this });
995
+ const { position: n, size: s, ...o } = i, h = super.addPane(t, { position: n, size: s }), a = new G({ ...o, sash: h, binaryWindow: this });
996
996
  return h.domNode.append(a.domNode), h;
997
997
  }
998
998
  }
@@ -1000,7 +1000,7 @@ _.assemble(Lt, Bt, $t);
1000
1000
  const y = 4;
1001
1001
  function Tt({ sash: e }) {
1002
1002
  var c;
1003
- const t = A(), i = e.leftChild, n = e.topChild;
1003
+ const t = M(), i = e.leftChild, n = e.topChild;
1004
1004
  let s, o, h, a, d, l;
1005
1005
  return i ? (s = y, o = e.height - y, h = e.top + y / 2, a = e.left + i.width - y / 2, d = !0) : n && (s = e.width - y, o = y, h = e.top + n.height - y / 2, a = e.left + y / 2, l = !0), W(() => {
1006
1006
  e.domNode = t.current;
@@ -1025,8 +1025,8 @@ function Wt({
1025
1025
  sash: e,
1026
1026
  bwin: t
1027
1027
  }) {
1028
- var c, u, g, w, m;
1029
- const i = A(), { left: n, top: s, width: o, height: h, id: a, position: d } = e;
1028
+ var c, u, g, m, w;
1029
+ const i = M(), { left: n, top: s, width: o, height: h, id: a, position: d } = e;
1030
1030
  W(() => {
1031
1031
  e.domNode = i.current;
1032
1032
  }, []);
@@ -1045,7 +1045,7 @@ function Wt({
1045
1045
  {
1046
1046
  "can-drag": ((g = e.store) == null ? void 0 : g.draggable) === !1 ? "false" : "true"
1047
1047
  },
1048
- ((w = e.store) == null ? void 0 : w.title) && /* @__PURE__ */ f.createElement("bw-glass-title", null, e.store.title),
1048
+ ((m = e.store) == null ? void 0 : m.title) && /* @__PURE__ */ f.createElement("bw-glass-title", null, e.store.title),
1049
1049
  l.length > 0 && /* @__PURE__ */ f.createElement("bw-glass-action-container", null, l.map((p, x) => {
1050
1050
  const D = p.className ? `bw-glass-action ${p.className}` : "bw-glass-action";
1051
1051
  return /* @__PURE__ */ f.createElement(
@@ -1058,11 +1058,11 @@ function Wt({
1058
1058
  p.label
1059
1059
  );
1060
1060
  }))
1061
- ), /* @__PURE__ */ f.createElement("bw-glass-content", null, (m = e.store) == null ? void 0 : m.content))
1061
+ ), /* @__PURE__ */ f.createElement("bw-glass-content", null, (w = e.store) == null ? void 0 : w.content))
1062
1062
  );
1063
1063
  }
1064
- const It = Y((e, t) => {
1065
- const i = A(), n = A(), [s, o] = j(), { panes: h, ...a } = e, d = { ...a, children: h }, l = new _(d), c = [], u = [];
1064
+ const Gt = Y((e, t) => {
1065
+ const i = M(), n = M(), [s, o] = j(), { panes: h, ...a } = e, d = { ...a, children: h }, l = new _(d), c = [], u = [];
1066
1066
  l.rootSash.walk((p) => {
1067
1067
  p.children.length > 0 ? c.push(p) : u.push(p);
1068
1068
  }), W(() => {
@@ -1073,7 +1073,7 @@ const It = Y((e, t) => {
1073
1073
  () => ({
1074
1074
  fit: l.fit.bind(l),
1075
1075
  removePane: l.removePane.bind(l),
1076
- addPane: m
1076
+ addPane: w
1077
1077
  }),
1078
1078
  []
1079
1079
  );
@@ -1087,8 +1087,8 @@ const It = Y((e, t) => {
1087
1087
  u.map((p) => /* @__PURE__ */ f.createElement(Wt, { key: p.id, sash: p, bwin: l })),
1088
1088
  c.map((p) => /* @__PURE__ */ f.createElement(Tt, { key: p.id, sash: p })),
1089
1089
  /* @__PURE__ */ f.createElement("bw-sill", { ref: n })
1090
- ), w = V(() => g, []);
1091
- function m(p, x) {
1090
+ ), m = V(() => g, []);
1091
+ function w(p, x) {
1092
1092
  const { content: D, ...$ } = x, q = l.addPane(p, $), U = document.querySelector(
1093
1093
  `bw-pane[sash-id="${q.id}"] bw-glass-content`
1094
1094
  );
@@ -1097,10 +1097,10 @@ const It = Y((e, t) => {
1097
1097
  { node: D, container: U }
1098
1098
  ]);
1099
1099
  }
1100
- return /* @__PURE__ */ f.createElement(f.Fragment, null, w, s == null ? void 0 : s.map((p) => Z(p.node, p.container)));
1101
- }), Ot = "0.3.1";
1100
+ return /* @__PURE__ */ f.createElement(f.Fragment, null, m, s == null ? void 0 : s.map((p) => Z(p.node, p.container)));
1101
+ }), Ot = "0.3.2";
1102
1102
  export {
1103
1103
  F as BUILTIN_ACTIONS,
1104
- It as Window,
1104
+ Gt as Window,
1105
1105
  Ot as version
1106
1106
  };
@@ -5,4 +5,4 @@ top: ${e.style.top}
5
5
  left: ${e.style.left}
6
6
  width: ${e.style.width}
7
7
  height: ${e.style.height}
8
- `;return t.innerHTML=i.trim(),t}const gt={createWindow(){const e=document.createElement("bw-window");return e.style.width=`${this.rootSash.width}px`,e.style.height=`${this.rootSash.height}px`,e.setAttribute("root-sash-id",this.rootSash.id),e},glaze(){this.rootSash.walk(e=>{let t=null;e.children.length>0?(t=this.createMuntin(e),this.onMuntinCreate(t,e),this.windowElement.append(t)):(t=this.createPane(e),this.onPaneCreate(t,e),this.windowElement.prepend(t)),e.domNode=t})},update(){this.windowElement.style.width=`${this.rootSash.width}px`,this.windowElement.style.height=`${this.rootSash.height}px`;const e=this.rootSash.getAllIds(),t=[];this.windowElement.querySelectorAll("[sash-id]").forEach(i=>{const n=i.getAttribute("sash-id");t.push(n),e.includes(n)||i.remove()}),this.rootSash.walk(i=>{i.children.length>0?t.includes(i.id)?(this.updateMuntin(i),this.onMuntinUpdate(i.domNode,i)):(i.domNode=this.createMuntin(i),this.windowElement.append(i.domNode)):t.includes(i.id)?(this.updatePane(i),this.onPaneUpdate(i.domNode,i)):(i.domNode||(i.domNode=this.createPane(i)),this.windowElement.prepend(i.domNode))})}},ft={muntinSize:4,createMuntin(e){const t=document.createElement("bw-muntin"),i=e.leftChild,n=e.topChild;return i?(t.style.width=`${this.muntinSize}px`,t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`,t.setAttribute("vertical","")):n&&(t.style.width=`${e.width}px`,t.style.height=`${this.muntinSize}px`,t.style.top=`${e.top+n.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`,t.setAttribute("horizontal","")),t.setAttribute("sash-id",e.id),e.store.resizable===!1&&t.setAttribute("resizable","false"),t},onMuntinCreate(e,t){},updateMuntin(e){const t=e.domNode,i=e.leftChild,n=e.topChild;i?(t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`):n&&(t.style.width=`${e.width}px`,t.style.top=`${e.top+n.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`)},onMuntinUpdate(e,t){}},wt={fitContainer:!1,fit(){this.rootSash.width=this.containerElement.clientWidth,this.rootSash.height=this.containerElement.clientHeight,this.update()},enableFitContainer(){new ResizeObserver(e=>{for(const t of e)t.target===this.containerElement&&this.fitContainer&&this.fit()}).observe(this.containerElement)}},mt={activeMuntinSash:null,isResizeStarted:!1,isDropStarted:!1,lastX:0,lastY:0,applyResizeStyles(){this.activeMuntinSash.domNode.hasAttribute("vertical")?document.body.classList.add("body--bw-resize-x"):this.activeMuntinSash.domNode.hasAttribute("horizontal")&&document.body.classList.add("body--bw-resize-y")},revertResizeStyles(){document.body.classList.remove("body--bw-resize-x"),document.body.classList.remove("body--bw-resize-y")},enableResize(){document.addEventListener("mousedown",e=>{if(e.target.tagName!=="BW-MUNTIN"||e.target.getAttribute("resizable")==="false")return;const t=e.target.getAttribute("sash-id");this.activeMuntinSash=this.rootSash.getById(t),this.activeMuntinSash&&(this.isResizeStarted=!0,this.lastX=e.pageX,this.lastY=e.pageY,this.applyResizeStyles())}),document.addEventListener("mousemove",e=>{if(!this.isResizeStarted||!this.activeMuntinSash)return;const[t,i,n,s]=this.activeMuntinSash.getChildren(),o=this.activeMuntinSash.isLeftRightSplit(),h=this.activeMuntinSash.isTopBottomSplit();if(o&&s&&i){const a=e.pageX-this.lastX,d=s.width+a,l=i.width-a;if(a>0&&l<=i.calcMinWidth()||a<0&&d<=s.calcMinWidth())return;s.width=d,i.width=l,i.left=i.left+a,this.update(),this.lastX=e.pageX}else if(h&&t&&n){const a=e.pageY-this.lastY,d=t.height+a,l=n.height-a;if(a>0&&l<=n.calcMinHeight()||a<0&&d<=t.calcMinHeight())return;t.height=d,n.height=l,n.top=n.top+a,this.update(),this.lastY=e.pageY}}),document.addEventListener("mouseup",()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},bt={activeDropPaneEl:null,onPaneDrop(e,t){},enableDrop(){this.windowElement.addEventListener("dragover",e=>{e.preventDefault();const t=e.target.matches("bw-pane")?e.target:e.target.closest("bw-pane");if(!t||(t!==this.activeDropPaneEl&&(this.activeDropPaneEl&&this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=t),t.getAttribute("can-drop")==="false"))return;const i=it(t,e);t.setAttribute("drop-area",i)}),this.windowElement.addEventListener("dragleave",e=>{e.currentTarget.contains(e.relatedTarget)&&e.currentTarget!==e.relatedTarget||this.activeDropPaneEl&&(this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null)}),this.windowElement.addEventListener("drop",e=>{if(!this.activeDropPaneEl||this.activeDropPaneEl.getAttribute("can-drop")==="false")return;const t=this.activeDropPaneEl.getAttribute("sash-id"),i=this.rootSash.getById(t);this.onPaneDrop(e,i),typeof i.store.onDrop=="function"&&i.store.onDrop(e,i),this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null})}},yt=!1;class G{constructor(t){E(this,"windowElement",null),E(this,"containerElement",null),E(this,"debug",yt);let i=null;t instanceof ht?(i=t,this.rootSash=t):(i=new ot(t),this.rootSash=i.buildSashTree()),this.fitContainer=i.fitContainer}frame(t){this.containerElement=t,this.windowElement=this.createWindow(),this.glaze(),this.containerElement.append(this.windowElement)}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(t){this.frame(t),this.enableFeatures()}static assemble(...t){t.forEach(i=>{K(this.prototype,i)})}}G.assemble(gt,ft,pt,wt,bt,mt);function I(e){if(e.tagName==="BW-PANE")return e.getAttribute("sash-id");const t=e.closest("bw-pane");if(!t)throw new Error("[bwin] Pane element not found");return t.getAttribute("sash-id")}const Et={label:"",className:"bw-glass-action--close",onClick:(e,t)=>{const i=I(e.target);t.removePane(i)}},vt={label:"",className:"bw-glass-action--minimize",onClick:(e,t)=>{const i=t.sillElement;if(!i)throw new Error("[bwin] Sill element not found when minimizing");const n=S('<button class="bw-minimized-glass" />');i.append(n);const s=e.target.closest("bw-pane"),o=e.target.closest("bw-glass"),h=s.getAttribute("sash-id"),a=s.getAttribute("position");n.bwGlassElement=o,n.bwOriginalPosition=a,n.bwOriginalBoundingRect=P(s),t.removePane(h)}},Nt={label:"",className:"bw-glass-action--maximize",onClick:e=>{const t=e.target.closest("bw-pane");t.hasAttribute("maximized")?(t.removeAttribute("maximized"),t.style.left=`${t.bwOriginalBoundingRect.left}px`,t.style.top=`${t.bwOriginalBoundingRect.top}px`,t.style.width=`${t.bwOriginalBoundingRect.width}px`,t.style.height=`${t.bwOriginalBoundingRect.height}px`):(t.setAttribute("maximized",""),t.bwOriginalBoundingRect=P(t),t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%")}};function zt(e,t){const i=e.left+e.width,n=e.top+e.height,s=t.left+t.width,o=t.top+t.height;if(e.left>=s||t.left>=i||e.top>=o||t.top>=n)return null;const h=Math.max(e.left,t.left),a=Math.max(e.top,t.top),d=Math.min(i,s),l=Math.min(n,o);return{left:h,top:a,width:d-h,height:l-a}}const L=[vt,Nt,Et],Ct={enableActions(){this.handleMinimizedGlassClick(),this.observeActionButtons()},restoreGlass(e){const t=e.bwOriginalBoundingRect;let i=0,n=null;if(this.windowElement.querySelectorAll("bw-pane").forEach(s=>{const o=P(s),h=zt(t,o);if(h){const a=h.width*h.height;a>i&&(i=a,n=s)}}),n){const s=e.bwOriginalPosition,o=P(n);let h=0;if(s===r.Left||s===r.Right)h=t.width>=o.width?o.width/2:t.width;else if(s===r.Top||s===r.Bottom)h=t.height>=o.height?o.height/2:t.height;else throw new Error("[bwin] Invalid position when restoring glass");this.addPane(n.getAttribute("sash-id"),{position:s,size:h}).domNode.append(e.bwGlassElement)}},handleMinimizedGlassClick(){this.sillElement.addEventListener("click",e=>{if(!e.target.matches(".bw-minimized-glass"))return;const t=e.target;this.restoreGlass(t),t.remove()})},updateDisabledStateOfActionButtons(){this.updateDisabledState(".bw-glass-action--close"),this.updateDisabledState(".bw-glass-action--minimize"),this.updateDisabledState(".bw-glass-action--maximize")},updateDisabledState(e){if(this.windowElement.querySelectorAll("bw-pane").length===1){const t=this.windowElement.querySelector(e);t&&t.setAttribute("disabled","")}else this.windowElement.querySelectorAll(e).forEach(t=>{t.removeAttribute("disabled")})},observeActionButtons(){this.updateDisabledStateOfActionButtons(),new MutationObserver(e=>{e.forEach(t=>{t.type==="childList"&&this.updateDisabledStateOfActionButtons()})}).observe(this.windowElement,{childList:!0})}},A={title:null,content:null,tabs:[],actions:void 0,draggable:!0};class k{constructor({title:t=A.title,content:i=A.content,tabs:n=A.tabs,actions:s=A.actions,draggable:o=A.draggable,sash:h,binaryWindow:a}){E(this,"domNode"),this.title=t,this.content=i,this.tabs=n,this.actions=s,this.sash=h,this.draggable=o,this.binaryWindow=a,this.build()}build(){const t=document.createElement("bw-glass-header");if(Array.isArray(this.tabs)&&this.tabs.length>0)t.append(this.createTabs());else if(this.title){const s=document.createElement("bw-glass-title");s.append(S(this.title)),t.append(s)}t.setAttribute("can-drag",this.draggable),t.append(this.createActions());const i=document.createElement("bw-glass-content"),n=S(this.content);n&&i.append(n),this.domNode=document.createElement("bw-glass"),this.domNode.append(t,i)}createTabs(){const t=document.createElement("bw-glass-tab-container");for(const i of this.tabs){const n=(i==null?void 0:i.label)??i,s=S(`<button class="bw-glass-tab">${n}</button>`);t.append(s)}return t}createActions(){const t=document.createElement("bw-glass-action-container"),i=this.actions===void 0?L:Array.isArray(this.actions)?this.actions:[];for(const n of i){const s=(n==null?void 0:n.label)??n,o=n.className?`bw-glass-action ${n.className}`:"bw-glass-action",h=S(`<button class="${o}">${s}</button>`);typeof n.onClick=="function"&&h.addEventListener("click",a=>{n.onClick(a,this.binaryWindow)}),t.append(h)}return t}get contentElement(){return this.domNode.querySelector("bw-glass-content")}get headerElement(){return this.domNode.querySelector("bw-glass-header")}}const St={activeDragGlassEl:null,activeDragGlassPaneCanDrop:!1,onPaneDrop(e,t){if(!this.activeDragGlassEl)return;const i=this.activeDropPaneEl.getAttribute("drop-area");if(i==="center"){const n=this.activeDragGlassEl.closest("bw-pane"),s=this.activeDropPaneEl.getAttribute("can-drop")!=="false";X(n,this.activeDropPaneEl),n.setAttribute("can-drop",s);return}else{const n=I(this.activeDragGlassEl);this.addPane(t.id,{position:i}).domNode.append(this.activeDragGlassEl),this.removePane(n)}},enableDrag(){document.addEventListener("mousedown",e=>{if(e.button!==0||!e.target.matches("bw-glass-header"))return;if(e.target.getAttribute("can-drag")==="false"){e.preventDefault();return}const t=e.target.closest("bw-glass");t.setAttribute("draggable",!0),this.activeDragGlassEl=t}),document.addEventListener("mouseup",()=>{this.activeDragGlassEl&&(this.activeDragGlassEl.removeAttribute("draggable"),this.activeDragGlassEl=null)}),this.windowElement.addEventListener("dragstart",e=>{if(!(e.target instanceof HTMLElement)||!e.target.matches("bw-glass")||!this.activeDragGlassEl)return;e.dataTransfer.effectAllowed="move";const t=this.activeDragGlassEl.closest("bw-pane");this.activeDragGlassPaneCanDrop=t.getAttribute("can-drop")!=="false",t.setAttribute("can-drop",!1)}),this.windowElement.addEventListener("dragend",()=>{this.activeDragGlassEl&&(this.activeDragGlassEl.removeAttribute("draggable"),this.activeDragGlassEl.closest("bw-pane").setAttribute("can-drop",this.activeDragGlassPaneCanDrop),this.activeDragGlassEl=null)})}},Mt={trimMuntin(e){e.hasAttribute("vertical")?(e.style.top=`${parseFloat(e.style.top)+this.muntinSize/2}px`,e.style.height=`${parseFloat(e.style.height)-this.muntinSize}px`):e.hasAttribute("horizontal")&&(e.style.left=`${parseFloat(e.style.left)+this.muntinSize/2}px`,e.style.width=`${parseFloat(e.style.width)-this.muntinSize}px`)},onMuntinCreate(e){this.trimMuntin(e)},onMuntinUpdate(e){this.trimMuntin(e)}};class F extends G{constructor(){super(...arguments),E(this,"sillElement",null)}frame(){super.frame(...arguments);const t=S("<bw-sill />");this.windowElement.append(t),this.sillElement=t}enableFeatures(){super.enableFeatures(),this.enableDrag(),this.enableActions()}onPaneCreate(t,i){const n=new k({...i.store,sash:i,binaryWindow:this});t.innerHTML="",t.append(n.domNode),this.debug&&n.contentElement.prepend(`${i.id}`)}onPaneUpdate(){}addPane(t,i){const{position:n,size:s,...o}=i,h=super.addPane(t,{position:n,size:s}),a=new k({...o,sash:h,binaryWindow:this});return h.domNode.append(a.domNode),h}}F.assemble(St,Mt,Ct);const N=4;function At({sash:e}){var c;const t=u.useRef(),i=e.leftChild,n=e.topChild;let s,o,h,a,d,l;return i?(s=N,o=e.height-N,h=e.top+N/2,a=e.left+i.width-N/2,d=!0):n&&(s=e.width-N,o=N,h=e.top+n.height-N/2,a=e.left+N/2,l=!0),u.useEffect(()=>{e.domNode=t.current},[]),u.createElement("bw-muntin",{"sash-id":e.id,style:{width:s,height:o,top:h,left:a},vertical:d,horizontal:l,resizable:((c=e.store)==null?void 0:c.resizable)===!1?"false":"true",ref:t})}function Pt({sash:e,bwin:t}){var c,g,f,b,y;const i=u.useRef(),{left:n,top:s,width:o,height:h,id:a,position:d}=e;u.useEffect(()=>{e.domNode=i.current},[]);const l=((c=e.store)==null?void 0:c.actions)===void 0?L:Array.isArray(e.store.actions)?e.store.actions:[];return u.createElement("bw-pane",{"sash-id":a,position:d,style:{left:n,top:s,width:o,height:h},"can-drop":((g=e.store)==null?void 0:g.droppable)===!1?"false":"true",ref:i},u.createElement("bw-glass",null,u.createElement("bw-glass-header",{"can-drag":((f=e.store)==null?void 0:f.draggable)===!1?"false":"true"},((b=e.store)==null?void 0:b.title)&&u.createElement("bw-glass-title",null,e.store.title),l.length>0&&u.createElement("bw-glass-action-container",null,l.map((p,B)=>{const T=p.className?`bw-glass-action ${p.className}`:"bw-glass-action";return u.createElement("button",{className:T,key:B,onClick:W=>p.onClick(W,t)},p.label)}))),u.createElement("bw-glass-content",null,(y=e.store)==null?void 0:y.content)))}const Dt=u.forwardRef((e,t)=>{const i=u.useRef(),n=u.useRef(),[s,o]=u.useState(),{panes:h,...a}=e,d={...a,children:h},l=new F(d),c=[],g=[];l.rootSash.walk(p=>{p.children.length>0?c.push(p):g.push(p)}),u.useEffect(()=>{const p=i.current;p!=null&&p.parentElement&&(l.windowElement=p,l.containerElement=p.parentElement,l.sillElement=n.current,l.enableFeatures())},[]),u.useImperativeHandle(t,()=>({fit:l.fit.bind(l),removePane:l.removePane.bind(l),addPane:y}),[]);const f=u.createElement("bw-window",{"root-sash-id":l.rootSash.id,style:{width:l.rootSash.width,height:l.rootSash.height},ref:i},g.map(p=>u.createElement(Pt,{key:p.id,sash:p,bwin:l})),c.map(p=>u.createElement(At,{key:p.id,sash:p})),u.createElement("bw-sill",{ref:n})),b=u.useMemo(()=>f,[]);function y(p,B){const{content:T,...W}=B,Rt=l.addPane(p,W),$t=document.querySelector(`bw-pane[sash-id="${Rt.id}"] bw-glass-content`);o(Lt=>[...Lt||[],{node:T,container:$t}])}return u.createElement(u.Fragment,null,b,s==null?void 0:s.map(p=>_.createPortal(p.node,p.container)))}),xt="0.3.1";w.BUILTIN_ACTIONS=L,w.Window=Dt,w.version=xt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
8
+ `;return t.innerHTML=i.trim(),t}const gt={createWindow(){const e=document.createElement("bw-window");return e.style.width=`${this.rootSash.width}px`,e.style.height=`${this.rootSash.height}px`,e.setAttribute("root-sash-id",this.rootSash.id),e},glaze(){this.rootSash.walk(e=>{let t=null;e.children.length>0?(t=this.createMuntin(e),this.onMuntinCreate(t,e),this.windowElement.append(t)):(t=this.createPane(e),this.onPaneCreate(t,e),this.windowElement.prepend(t)),e.domNode=t})},update(){this.windowElement.style.width=`${this.rootSash.width}px`,this.windowElement.style.height=`${this.rootSash.height}px`;const e=this.rootSash.getAllIds(),t=[];this.windowElement.querySelectorAll("[sash-id]").forEach(i=>{const n=i.getAttribute("sash-id");t.push(n),e.includes(n)||i.remove()}),this.rootSash.walk(i=>{i.children.length>0?t.includes(i.id)?(this.updateMuntin(i),this.onMuntinUpdate(i.domNode,i)):(i.domNode=this.createMuntin(i),this.windowElement.append(i.domNode)):t.includes(i.id)?(this.updatePane(i),this.onPaneUpdate(i.domNode,i)):(i.domNode||(i.domNode=this.createPane(i)),this.windowElement.prepend(i.domNode))})}},ft={muntinSize:4,createMuntin(e){const t=document.createElement("bw-muntin"),i=e.leftChild,n=e.topChild;return i?(t.style.width=`${this.muntinSize}px`,t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`,t.setAttribute("vertical","")):n&&(t.style.width=`${e.width}px`,t.style.height=`${this.muntinSize}px`,t.style.top=`${e.top+n.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`,t.setAttribute("horizontal","")),t.setAttribute("sash-id",e.id),e.store.resizable===!1&&t.setAttribute("resizable","false"),t},onMuntinCreate(e,t){},updateMuntin(e){const t=e.domNode,i=e.leftChild,n=e.topChild;i?(t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`):n&&(t.style.width=`${e.width}px`,t.style.top=`${e.top+n.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`)},onMuntinUpdate(e,t){}},wt={fitContainer:!1,fit(){this.rootSash.width=this.containerElement.clientWidth,this.rootSash.height=this.containerElement.clientHeight,this.update()},enableFitContainer(){new ResizeObserver(e=>{for(const t of e)t.target===this.containerElement&&this.fitContainer&&this.fit()}).observe(this.containerElement)}},mt={activeMuntinSash:null,isResizeStarted:!1,isDropStarted:!1,lastX:0,lastY:0,applyResizeStyles(){this.activeMuntinSash.domNode.hasAttribute("vertical")?document.body.classList.add("body--bw-resize-x"):this.activeMuntinSash.domNode.hasAttribute("horizontal")&&document.body.classList.add("body--bw-resize-y")},revertResizeStyles(){document.body.classList.remove("body--bw-resize-x"),document.body.classList.remove("body--bw-resize-y")},enableResize(){document.addEventListener("mousedown",e=>{if(e.target.tagName!=="BW-MUNTIN"||e.target.getAttribute("resizable")==="false")return;const t=e.target.getAttribute("sash-id");this.activeMuntinSash=this.rootSash.getById(t),this.activeMuntinSash&&(this.isResizeStarted=!0,this.lastX=e.pageX,this.lastY=e.pageY,this.applyResizeStyles())}),document.addEventListener("mousemove",e=>{if(!this.isResizeStarted||!this.activeMuntinSash)return;const[t,i,n,s]=this.activeMuntinSash.getChildren(),o=this.activeMuntinSash.isLeftRightSplit(),h=this.activeMuntinSash.isTopBottomSplit();if(o&&s&&i){const a=e.pageX-this.lastX,d=s.width+a,l=i.width-a;if(a>0&&l<=i.calcMinWidth()||a<0&&d<=s.calcMinWidth())return;s.width=d,i.width=l,i.left=i.left+a,this.update(),this.lastX=e.pageX}else if(h&&t&&n){const a=e.pageY-this.lastY,d=t.height+a,l=n.height-a;if(a>0&&l<=n.calcMinHeight()||a<0&&d<=t.calcMinHeight())return;t.height=d,n.height=l,n.top=n.top+a,this.update(),this.lastY=e.pageY}}),document.addEventListener("mouseup",()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},bt={activeDropPaneEl:null,onPaneDrop(e,t){},enableDrop(){this.windowElement.addEventListener("dragover",e=>{e.preventDefault();const t=e.target.matches("bw-pane")?e.target:e.target.closest("bw-pane");if(!t||(t!==this.activeDropPaneEl&&(this.activeDropPaneEl&&this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=t),t.getAttribute("can-drop")==="false"))return;const i=it(t,e);t.setAttribute("drop-area",i)}),this.windowElement.addEventListener("dragleave",e=>{e.currentTarget.contains(e.relatedTarget)&&e.currentTarget!==e.relatedTarget||this.activeDropPaneEl&&(this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null)}),this.windowElement.addEventListener("drop",e=>{if(!this.activeDropPaneEl||this.activeDropPaneEl.getAttribute("can-drop")==="false")return;const t=this.activeDropPaneEl.getAttribute("sash-id"),i=this.rootSash.getById(t);this.onPaneDrop(e,i),typeof i.store.onDrop=="function"&&i.store.onDrop(e,i),this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null})}},yt=!1;class I{constructor(t){E(this,"windowElement",null),E(this,"containerElement",null),E(this,"debug",yt);let i=null;t instanceof ht?(i=t,this.rootSash=t):(i=new ot(t),this.rootSash=i.buildSashTree()),this.fitContainer=i.fitContainer}frame(t){this.containerElement=t,this.windowElement=this.createWindow(),this.glaze(),this.containerElement.append(this.windowElement)}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(t){this.frame(t),this.enableFeatures()}static assemble(...t){t.forEach(i=>{K(this.prototype,i)})}}I.assemble(gt,ft,pt,wt,bt,mt);function G(e){if(e.tagName==="BW-PANE")return e.getAttribute("sash-id");const t=e.closest("bw-pane");if(!t)throw new Error("[bwin] Pane element not found");return t.getAttribute("sash-id")}const Et={label:"",className:"bw-glass-action--close",onClick:(e,t)=>{const i=G(e.target);t.removePane(i)}},vt={label:"",className:"bw-glass-action--minimize",onClick:(e,t)=>{const i=t.sillElement;if(!i)throw new Error("[bwin] Sill element not found when minimizing");const n=S('<button class="bw-minimized-glass" />');i.append(n);const s=e.target.closest("bw-pane"),o=e.target.closest("bw-glass"),h=s.getAttribute("sash-id"),a=s.getAttribute("position");n.bwGlassElement=o,n.bwOriginalPosition=a,n.bwOriginalBoundingRect=P(s),t.removePane(h)}},Nt={label:"",className:"bw-glass-action--maximize",onClick:e=>{const t=e.target.closest("bw-pane");t.hasAttribute("maximized")?(t.removeAttribute("maximized"),t.style.left=`${t.bwOriginalBoundingRect.left}px`,t.style.top=`${t.bwOriginalBoundingRect.top}px`,t.style.width=`${t.bwOriginalBoundingRect.width}px`,t.style.height=`${t.bwOriginalBoundingRect.height}px`):(t.setAttribute("maximized",""),t.bwOriginalBoundingRect=P(t),t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%")}};function zt(e,t){const i=e.left+e.width,n=e.top+e.height,s=t.left+t.width,o=t.top+t.height;if(e.left>=s||t.left>=i||e.top>=o||t.top>=n)return null;const h=Math.max(e.left,t.left),a=Math.max(e.top,t.top),d=Math.min(i,s),l=Math.min(n,o);return{left:h,top:a,width:d-h,height:l-a}}const B=[vt,Nt,Et],Ct={enableActions(){this.handleMinimizedGlassClick(),this.observeActionButtons()},restoreGlass(e){const t=e.bwOriginalBoundingRect;let i=0,n=null;if(this.windowElement.querySelectorAll("bw-pane").forEach(s=>{const o=P(s),h=zt(t,o);if(h){const a=h.width*h.height;a>i&&(i=a,n=s)}}),n){const s=e.bwOriginalPosition,o=P(n),h=n.getAttribute("sash-id"),a=this.rootSash.getById(h);let d=0;if(s===r.Left||s===r.Right)d=o.width-t.width<a.minWidth?o.width/2:t.width;else if(s===r.Top||s===r.Bottom)d=o.height-t.height<a.minHeight?o.height/2:t.height;else throw new Error("[bwin] Invalid position when restoring glass");this.addPane(n.getAttribute("sash-id"),{position:s,size:d}).domNode.append(e.bwGlassElement)}},handleMinimizedGlassClick(){this.sillElement.addEventListener("click",e=>{if(!e.target.matches(".bw-minimized-glass"))return;const t=e.target;this.restoreGlass(t),t.remove()})},updateDisabledStateOfActionButtons(){this.updateDisabledState(".bw-glass-action--close"),this.updateDisabledState(".bw-glass-action--minimize"),this.updateDisabledState(".bw-glass-action--maximize")},updateDisabledState(e){if(this.windowElement.querySelectorAll("bw-pane").length===1){const t=this.windowElement.querySelector(e);t&&t.setAttribute("disabled","")}else this.windowElement.querySelectorAll(e).forEach(t=>{t.removeAttribute("disabled")})},observeActionButtons(){this.updateDisabledStateOfActionButtons(),new MutationObserver(e=>{e.forEach(t=>{t.type==="childList"&&this.updateDisabledStateOfActionButtons()})}).observe(this.windowElement,{childList:!0})}},A={title:null,content:null,tabs:[],actions:void 0,draggable:!0};class k{constructor({title:t=A.title,content:i=A.content,tabs:n=A.tabs,actions:s=A.actions,draggable:o=A.draggable,sash:h,binaryWindow:a}){E(this,"domNode"),this.title=t,this.content=i,this.tabs=n,this.actions=s,this.sash=h,this.draggable=o,this.binaryWindow=a,this.build()}build(){const t=document.createElement("bw-glass-header");if(Array.isArray(this.tabs)&&this.tabs.length>0)t.append(this.createTabs());else if(this.title){const s=document.createElement("bw-glass-title");s.append(S(this.title)),t.append(s)}t.setAttribute("can-drag",this.draggable),t.append(this.createActions());const i=document.createElement("bw-glass-content"),n=S(this.content);n&&i.append(n),this.domNode=document.createElement("bw-glass"),this.domNode.append(t,i)}createTabs(){const t=document.createElement("bw-glass-tab-container");for(const i of this.tabs){const n=(i==null?void 0:i.label)??i,s=S(`<button class="bw-glass-tab">${n}</button>`);t.append(s)}return t}createActions(){const t=document.createElement("bw-glass-action-container"),i=this.actions===void 0?B:Array.isArray(this.actions)?this.actions:[];for(const n of i){const s=(n==null?void 0:n.label)??n,o=n.className?`bw-glass-action ${n.className}`:"bw-glass-action",h=S(`<button class="${o}">${s}</button>`);typeof n.onClick=="function"&&h.addEventListener("click",a=>{n.onClick(a,this.binaryWindow)}),t.append(h)}return t}get contentElement(){return this.domNode.querySelector("bw-glass-content")}get headerElement(){return this.domNode.querySelector("bw-glass-header")}}const St={activeDragGlassEl:null,activeDragGlassPaneCanDrop:!1,onPaneDrop(e,t){if(!this.activeDragGlassEl)return;const i=this.activeDropPaneEl.getAttribute("drop-area");if(i==="center"){const n=this.activeDragGlassEl.closest("bw-pane"),s=this.activeDropPaneEl.getAttribute("can-drop")!=="false";X(n,this.activeDropPaneEl),n.setAttribute("can-drop",s);return}else{const n=G(this.activeDragGlassEl);this.addPane(t.id,{position:i}).domNode.append(this.activeDragGlassEl),this.removePane(n)}},enableDrag(){document.addEventListener("mousedown",e=>{if(e.button!==0||!e.target.matches("bw-glass-header"))return;if(e.target.getAttribute("can-drag")==="false"){e.preventDefault();return}const t=e.target.closest("bw-glass");t.setAttribute("draggable",!0),this.activeDragGlassEl=t}),document.addEventListener("mouseup",()=>{this.activeDragGlassEl&&(this.activeDragGlassEl.removeAttribute("draggable"),this.activeDragGlassEl=null)}),this.windowElement.addEventListener("dragstart",e=>{if(!(e.target instanceof HTMLElement)||!e.target.matches("bw-glass")||!this.activeDragGlassEl)return;e.dataTransfer.effectAllowed="move";const t=this.activeDragGlassEl.closest("bw-pane");this.activeDragGlassPaneCanDrop=t.getAttribute("can-drop")!=="false",t.setAttribute("can-drop",!1)}),this.windowElement.addEventListener("dragend",()=>{this.activeDragGlassEl&&(this.activeDragGlassEl.removeAttribute("draggable"),this.activeDragGlassEl.closest("bw-pane").setAttribute("can-drop",this.activeDragGlassPaneCanDrop),this.activeDragGlassEl=null)})}},Mt={trimMuntin(e){e.hasAttribute("vertical")?(e.style.top=`${parseFloat(e.style.top)+this.muntinSize/2}px`,e.style.height=`${parseFloat(e.style.height)-this.muntinSize}px`):e.hasAttribute("horizontal")&&(e.style.left=`${parseFloat(e.style.left)+this.muntinSize/2}px`,e.style.width=`${parseFloat(e.style.width)-this.muntinSize}px`)},onMuntinCreate(e){this.trimMuntin(e)},onMuntinUpdate(e){this.trimMuntin(e)}};class F extends I{constructor(){super(...arguments),E(this,"sillElement",null)}frame(){super.frame(...arguments);const t=S("<bw-sill />");this.windowElement.append(t),this.sillElement=t}enableFeatures(){super.enableFeatures(),this.enableDrag(),this.enableActions()}onPaneCreate(t,i){const n=new k({...i.store,sash:i,binaryWindow:this});t.innerHTML="",t.append(n.domNode),this.debug&&n.contentElement.prepend(`${i.id}`)}onPaneUpdate(){}addPane(t,i){const{position:n,size:s,...o}=i,h=super.addPane(t,{position:n,size:s}),a=new k({...o,sash:h,binaryWindow:this});return h.domNode.append(a.domNode),h}}F.assemble(St,Mt,Ct);const N=4;function At({sash:e}){var c;const t=u.useRef(),i=e.leftChild,n=e.topChild;let s,o,h,a,d,l;return i?(s=N,o=e.height-N,h=e.top+N/2,a=e.left+i.width-N/2,d=!0):n&&(s=e.width-N,o=N,h=e.top+n.height-N/2,a=e.left+N/2,l=!0),u.useEffect(()=>{e.domNode=t.current},[]),u.createElement("bw-muntin",{"sash-id":e.id,style:{width:s,height:o,top:h,left:a},vertical:d,horizontal:l,resizable:((c=e.store)==null?void 0:c.resizable)===!1?"false":"true",ref:t})}function Pt({sash:e,bwin:t}){var c,g,f,b,y;const i=u.useRef(),{left:n,top:s,width:o,height:h,id:a,position:d}=e;u.useEffect(()=>{e.domNode=i.current},[]);const l=((c=e.store)==null?void 0:c.actions)===void 0?B:Array.isArray(e.store.actions)?e.store.actions:[];return u.createElement("bw-pane",{"sash-id":a,position:d,style:{left:n,top:s,width:o,height:h},"can-drop":((g=e.store)==null?void 0:g.droppable)===!1?"false":"true",ref:i},u.createElement("bw-glass",null,u.createElement("bw-glass-header",{"can-drag":((f=e.store)==null?void 0:f.draggable)===!1?"false":"true"},((b=e.store)==null?void 0:b.title)&&u.createElement("bw-glass-title",null,e.store.title),l.length>0&&u.createElement("bw-glass-action-container",null,l.map((p,L)=>{const T=p.className?`bw-glass-action ${p.className}`:"bw-glass-action";return u.createElement("button",{className:T,key:L,onClick:W=>p.onClick(W,t)},p.label)}))),u.createElement("bw-glass-content",null,(y=e.store)==null?void 0:y.content)))}const Dt=u.forwardRef((e,t)=>{const i=u.useRef(),n=u.useRef(),[s,o]=u.useState(),{panes:h,...a}=e,d={...a,children:h},l=new F(d),c=[],g=[];l.rootSash.walk(p=>{p.children.length>0?c.push(p):g.push(p)}),u.useEffect(()=>{const p=i.current;p!=null&&p.parentElement&&(l.windowElement=p,l.containerElement=p.parentElement,l.sillElement=n.current,l.enableFeatures())},[]),u.useImperativeHandle(t,()=>({fit:l.fit.bind(l),removePane:l.removePane.bind(l),addPane:y}),[]);const f=u.createElement("bw-window",{"root-sash-id":l.rootSash.id,style:{width:l.rootSash.width,height:l.rootSash.height},ref:i},g.map(p=>u.createElement(Pt,{key:p.id,sash:p,bwin:l})),c.map(p=>u.createElement(At,{key:p.id,sash:p})),u.createElement("bw-sill",{ref:n})),b=u.useMemo(()=>f,[]);function y(p,L){const{content:T,...W}=L,Rt=l.addPane(p,W),$t=document.querySelector(`bw-pane[sash-id="${Rt.id}"] bw-glass-content`);o(Bt=>[...Bt||[],{node:T,container:$t}])}return u.createElement(u.Fragment,null,b,s==null?void 0:s.map(p=>_.createPortal(p.node,p.container)))}),xt="0.3.2";w.BUILTIN_ACTIONS=B,w.Window=Dt,w.version=xt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-bwin",
3
3
  "description": "A tiling window manager in React based on Binary Window library",
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -45,7 +45,7 @@
45
45
  "@types/react": "^16.14.62",
46
46
  "@types/react-dom": "^16.9.24",
47
47
  "@vitejs/plugin-react": "^4.3.4",
48
- "bwin": "0.2.1",
48
+ "bwin": "0.2.2",
49
49
  "prettier": "^3.4.1",
50
50
  "react": "^16.14.0",
51
51
  "react-dom": "^16.14.0",