react-bwin 0.3.0 → 0.3.1

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
@@ -3,3 +3,9 @@
3
3
  A React tiling window manager based on [Binary Window](https://github.com/bhjsdev/bwin) library.
4
4
 
5
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).
@@ -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 m = h.calcMinWidth(), w = s.calcMinWidth();
288
- c < m && u > w ? (c = m, u = l - c, g = h.left + c) : u < w && c > m && (u = w, c = l - u, g = h.left + c), h.width = c, s.width = u, s.left = g;
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;
289
289
  }
290
290
  n && o && (n.width += i, o.width += i);
291
291
  }
@@ -299,8 +299,11 @@ class b {
299
299
  if (n && o) {
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
- const m = n.calcMinHeight(), w = o.calcMinHeight();
303
- c < m && u > w ? (c = m, u = l - c, g = n.top + c) : u < w && c > m && (u = w, c = l - u, g = n.top + c), n.height = c, o.height = u, o.top = g;
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);
305
+ }
306
+ n.height = c, o.height = u, o.top = g;
304
307
  }
305
308
  h && s && (h.height += i, s.height += i);
306
309
  }
@@ -487,7 +490,7 @@ function ft(e) {
487
490
  const t = e.domNode;
488
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;
489
492
  }
490
- function mt(e, { size: t }) {
493
+ function wt(e, { size: t }) {
491
494
  const i = C(t);
492
495
  let n = e.width / 2;
493
496
  i && (i < 1 ? n = e.width * i : n = i);
@@ -506,7 +509,7 @@ function mt(e, { size: t }) {
506
509
  }), h = M(o);
507
510
  return o.domNode = h, z(h, e.domNode), e.addChild(s), e.addChild(o), s;
508
511
  }
509
- function wt(e, { size: t }) {
512
+ function mt(e, { size: t }) {
510
513
  const i = C(t);
511
514
  let n = e.width / 2;
512
515
  i && (i < 1 ? n = e.width * i : n = i);
@@ -565,9 +568,9 @@ function Et(e, { size: t }) {
565
568
  }
566
569
  function yt(e, { position: t, size: i, minWidth: n, minHeight: s }) {
567
570
  if (t === r.Left)
568
- return mt(e, { size: i });
569
- if (t === r.Right)
570
571
  return wt(e, { size: i });
572
+ if (t === r.Right)
573
+ return mt(e, { size: i });
571
574
  if (t === r.Top)
572
575
  return bt(e, { size: i });
573
576
  if (t === r.Bottom)
@@ -696,13 +699,11 @@ const Nt = {
696
699
  const [t, i, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
697
700
  if (o && s && i) {
698
701
  const a = e.pageX - this.lastX, d = s.width + a, l = i.width - a;
699
- if (d <= s.calcMinWidth() || l <= i.calcMinWidth())
700
- return;
702
+ if (a > 0 && l <= i.calcMinWidth() || a < 0 && d <= s.calcMinWidth()) return;
701
703
  s.width = d, i.width = l, i.left = i.left + a, this.update(), this.lastX = e.pageX;
702
704
  } else if (h && t && n) {
703
705
  const a = e.pageY - this.lastY, d = t.height + a, l = n.height - a;
704
- if (d <= t.calcMinHeight() || l <= n.calcMinHeight())
705
- return;
706
+ if (a > 0 && l <= n.calcMinHeight() || a < 0 && d <= t.calcMinHeight()) return;
706
707
  t.height = d, n.height = l, n.top = n.top + a, this.update(), this.lastY = e.pageY;
707
708
  }
708
709
  }), document.addEventListener("mouseup", () => {
@@ -1024,7 +1025,7 @@ function Wt({
1024
1025
  sash: e,
1025
1026
  bwin: t
1026
1027
  }) {
1027
- var c, u, g, m, w;
1028
+ var c, u, g, w, m;
1028
1029
  const i = A(), { left: n, top: s, width: o, height: h, id: a, position: d } = e;
1029
1030
  W(() => {
1030
1031
  e.domNode = i.current;
@@ -1044,7 +1045,7 @@ function Wt({
1044
1045
  {
1045
1046
  "can-drag": ((g = e.store) == null ? void 0 : g.draggable) === !1 ? "false" : "true"
1046
1047
  },
1047
- ((m = e.store) == null ? void 0 : m.title) && /* @__PURE__ */ f.createElement("bw-glass-title", null, e.store.title),
1048
+ ((w = e.store) == null ? void 0 : w.title) && /* @__PURE__ */ f.createElement("bw-glass-title", null, e.store.title),
1048
1049
  l.length > 0 && /* @__PURE__ */ f.createElement("bw-glass-action-container", null, l.map((p, x) => {
1049
1050
  const D = p.className ? `bw-glass-action ${p.className}` : "bw-glass-action";
1050
1051
  return /* @__PURE__ */ f.createElement(
@@ -1057,7 +1058,7 @@ function Wt({
1057
1058
  p.label
1058
1059
  );
1059
1060
  }))
1060
- ), /* @__PURE__ */ f.createElement("bw-glass-content", null, (w = e.store) == null ? void 0 : w.content))
1061
+ ), /* @__PURE__ */ f.createElement("bw-glass-content", null, (m = e.store) == null ? void 0 : m.content))
1061
1062
  );
1062
1063
  }
1063
1064
  const It = Y((e, t) => {
@@ -1072,7 +1073,7 @@ const It = Y((e, t) => {
1072
1073
  () => ({
1073
1074
  fit: l.fit.bind(l),
1074
1075
  removePane: l.removePane.bind(l),
1075
- addPane: w
1076
+ addPane: m
1076
1077
  }),
1077
1078
  []
1078
1079
  );
@@ -1086,8 +1087,8 @@ const It = Y((e, t) => {
1086
1087
  u.map((p) => /* @__PURE__ */ f.createElement(Wt, { key: p.id, sash: p, bwin: l })),
1087
1088
  c.map((p) => /* @__PURE__ */ f.createElement(Tt, { key: p.id, sash: p })),
1088
1089
  /* @__PURE__ */ f.createElement("bw-sill", { ref: n })
1089
- ), m = V(() => g, []);
1090
- function w(p, x) {
1090
+ ), w = V(() => g, []);
1091
+ function m(p, x) {
1091
1092
  const { content: D, ...$ } = x, q = l.addPane(p, $), U = document.querySelector(
1092
1093
  `bw-pane[sash-id="${q.id}"] bw-glass-content`
1093
1094
  );
@@ -1096,8 +1097,8 @@ const It = Y((e, t) => {
1096
1097
  { node: D, container: U }
1097
1098
  ]);
1098
1099
  }
1099
- return /* @__PURE__ */ f.createElement(f.Fragment, null, m, s == null ? void 0 : s.map((p) => Z(p.node, p.container)));
1100
- }), Ot = "0.3.0";
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";
1101
1102
  export {
1102
1103
  F as BUILTIN_ACTIONS,
1103
1104
  It as Window,
@@ -1,8 +1,8 @@
1
- (function(b,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],u):(b=typeof globalThis<"u"?globalThis:b||self,u(b.ReactBinaryWindow={},b.React,b.ReactDOM))})(this,function(b,u,_){"use strict";var q=Object.defineProperty,U=(e,t,i)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,E=(e,t,i)=>U(e,typeof t!="symbol"?t+"":t,i);function j(e=.7,t=128){const i=256-t,n=Math.floor(Math.random()*i+t),s=Math.floor(Math.random()*i+t),o=Math.floor(Math.random()*i+t),h=Math.max(.5,Math.random()*e);return`rgba(${n}, ${s}, ${o}, ${h})`}function x(e=2,t=3){if(e<0||t<0)throw new Error("Parameters must be non-negative numbers");const i="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789";let s="";for(let o=0;o<e;o++){const h=Math.floor(Math.random()*i.length);s+=i[h]}s+="-";for(let o=0;o<t;o++){const h=Math.floor(Math.random()*n.length);s+=n[h]}return s}function z(e,t){for(;t.firstChild;)e.append(t.firstChild)}function X(e,t){const i=document.createElement("div");z(i,e),z(e,t),z(t,i)}function C(e){if(typeof e=="number"&&!isNaN(e))return e;if(typeof e=="string"){const t=e.trim();if(t.endsWith("%")){const i=t.slice(0,-1);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n/100}if(t.endsWith("px")){const i=t.slice(0,-2);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n}return Number(t)}return NaN}function Y(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function K(e,t){for(const i in t){if(Object.hasOwn(e,i))throw new Error(`Key "${i}" already exists in target object`);e[i]=t[i]}return e}function V(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content}function S(e){if(e==null||e==="")return null;if(typeof e=="string")try{const t=V(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}function P(e){const t=parseFloat(e.style.left)||0,i=parseFloat(e.style.top)||0,n=parseFloat(e.style.width)||0,s=parseFloat(e.style.height)||0;return{left:t,top:i,width:n,height:s}}const r={Top:"top",Right:"right",Bottom:"bottom",Left:"left",Center:"center",Root:"root",Unknown:"unknown",Outside:"outside"};function Z(e){switch(e){case r.Top:return r.Bottom;case r.Right:return r.Left;case r.Bottom:return r.Top;case r.Left:return r.Right;default:throw new Error(`[bwin] Invalid position: ${e}`)}}function J({width:e,height:t,x:i}){return t/e*i}function Q({width:e,height:t,y:i}){return e/t*i}function tt({width:e,height:t,x:i}){return t-t/e*i}function et({width:e,height:t,y:i}){return e-e/t*i}function it(e,{clientX:t,clientY:i}){const n=e.getBoundingClientRect(),{width:s,height:o}=n,h=t-n.left,a=i-n.top;if(h<0||h>s||a<0||a>o)return r.Outside;const d=.3,l=J({width:s,height:o,x:h}),c=tt({width:s,height:o,x:h}),g=Q({width:s,height:o,y:a}),f=et({width:s,height:o,y:a});return h<s*(.5-d/2)&&a>l&&a<c?r.Left:h>s*(.5+d/2)&&a<l&&a>c?r.Right:a<o*(.5-d/2)&&h>g&&h<f?r.Top:a>o*(.5+d/2)&&h<g&&h>f?r.Bottom:h>s*(.5-d/2)&&h<s*(.5+d/2)&&a>o*(.5-d/2)&&a<o*(.5+d/2)?r.Center:r.Unknown}const nt=100,st=100,v={left:0,top:0,width:150,height:150,minWidth:nt,minHeight:st};class y{constructor({left:t=v.left,top:i=v.top,width:n=v.width,height:s=v.height,minWidth:o=v.minWidth,minHeight:h=v.minHeight,domNode:a=null,store:d={},position:l,id:c}=v){if(this.id=c??x(),!l)throw new Error("[bwin] Sash position is required");this.position=l,this.domNode=a,this._top=i,this._left=t,this._width=n,this._height=s,this.children=[],this.minWidth=o,this.minHeight=h,this.store=d}walk(t){this.children.forEach(i=>i.walk(t)),t(this)}isLeaf(){return this.children.length===0}isSplit(){return this.children.length>0}isLeftRightSplit(){return this.children.some(t=>t.position===r.Left||t.position===r.Right)}isTopBottomSplit(){return this.children.some(t=>t.position===r.Top||t.position===r.Bottom)}get leftChild(){return this.children.find(t=>t.position===r.Left)}get rightChild(){return this.children.find(t=>t.position===r.Right)}get topChild(){return this.children.find(t=>t.position===r.Top)}get bottomChild(){return this.children.find(t=>t.position===r.Bottom)}getChildren(){let t=null,i=null,n=null,s=null;for(const o of this.children)o.position===r.Left?t=o:o.position===r.Right?i=o:o.position===r.Top?n=o:o.position===r.Bottom&&(s=o);return[n,i,s,t]}getAllLeafDescendants(){const t=[];return this.walk(i=>{i.children.length===0&&t.push(i)}),t}calcMinWidth(){if(this.isLeaf())return this.minWidth;const[t,i,n,s]=this.getChildren();if(s&&i){const o=s.calcMinWidth()+i.calcMinWidth();return Math.max(this.minWidth,o)}if(t&&n){const o=Math.max(t.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,o)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;const[t,i,n,s]=this.getChildren();if(s&&i){const o=Math.max(s.calcMinHeight(),i.calcMinHeight());return Math.max(this.minHeight,o)}if(t&&n){const o=t.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,o)}}getById(t){if(this.id===t)return this;for(const i of this.children){const n=i.getById(t);if(n)return n}return null}getAllIds(){const t=[this.id];for(const i of this.children)t.push(...i.getAllIds());return t}addChild(t){if(this.children.length>=2)throw new Error("[bwin] Maximum 2 children allowed");this.children.push(t)}getDescendantParentById(t){for(const i of this.children){if(i.id===t)return this;const n=i.getDescendantParentById(t);if(n)return n}return null}getChildSiblingById(t){return this.children.find(i=>i.id!==t)}get top(){return this._top}set top(t){const i=t-this._top;this._top=t;const[n,s,o,h]=this.getChildren();n&&o&&(n.top+=i,o.top+=i),h&&s&&(h.top+=i,s.top+=i)}get left(){return this._left}set left(t){const i=t-this._left;this._left=t;const[n,s,o,h]=this.getChildren();h&&s&&(h.left+=i,s.left+=i),n&&o&&(n.left+=i,o.left+=i)}get width(){return this._width}set width(t){const i=t-this._width;this._width=t;const[n,s,o,h]=this.getChildren();if(h&&s){const a=h.width+s.width,d=i*(h.width/a),l=a+i;let c=h.width+d,g=l-c,f=s.left+d;const m=h.calcMinWidth(),w=s.calcMinWidth();c<m&&g>w?(c=m,g=l-c,f=h.left+c):g<w&&c>m&&(g=w,c=l-g,f=h.left+c),h.width=c,s.width=g,s.left=f}n&&o&&(n.width+=i,o.width+=i)}get height(){return this._height}set height(t){const i=t-this._height;this._height=t;const[n,s,o,h]=this.getChildren();if(n&&o){const a=n.height+o.height,d=i*(n.height/a),l=a+i;let c=n.height+d,g=l-c,f=o.top+d;const m=n.calcMinHeight(),w=o.calcMinHeight();c<m&&g>w?(c=m,g=l-c,f=n.top+c):g<w&&c>m&&(g=w,c=l-g,f=n.top+c),n.height=c,o.height=g,o.top=f}h&&s&&(h.height+=i,s.height+=i)}}const H={size:"50%",position:r.Left};class D{constructor({parentRect:t,children:i,siblingConfigNode:n,id:s,minWidth:o,minHeight:h,position:a,size:d,...l}){E(this,"left"),E(this,"top"),E(this,"width"),E(this,"height"),this.parentRect=t,this.children=i,this.siblingConfigNode=n,this.id=s,this.minWidth=o,this.minHeight=h,this.position=this.getPosition(a),this.size=this.getSize(d),this.nonCoreData=l,this.setBounds()}getPosition(t){if(!this.siblingConfigNode)return t;const i=Z(this.siblingConfigNode.position);if(!t)return i;if(t!==i)throw new Error("[bwin] Sibling position and current position are not opposite");return t}getSize(t){if(!this.siblingConfigNode)return C(t);if(!t){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===r.Left||this.siblingConfigNode.position===r.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===r.Top||this.siblingConfigNode.position===r.Bottom)return this.parentRect.height-this.siblingConfigNode.height}const i=C(t);if(i<1){if(i+this.siblingConfigNode.size!==1)throw new Error("[bwin] Sum of sibling sizes is not equal to 1")}else{if((this.position===r.Left||this.position===r.Right)&&i+this.siblingConfigNode.size!==this.parentRect.width)throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");if((this.position===r.Top||this.position===r.Bottom)&&i+this.siblingConfigNode.size!==this.parentRect.height)throw new Error("[bwin] Sum of sibling sizes is not equal to parent height")}return i}setBounds(){if(this.position===r.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===r.Left){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Right){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left+this.parentRect.width-t,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Top){const t=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=this.parentRect.width,this.height=t}else if(this.position===r.Bottom){const t=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top+this.parentRect.height-t,this.width=this.parentRect.width,this.height=t}}createSash(){return new y({left:this.left,top:this.top,width:this.width,height:this.height,position:this.position,id:this.id,minWidth:this.minWidth,minHeight:this.minHeight,store:this.nonCoreData})}normConfig(t){if(Y(t))return t;if(Array.isArray(t))return{children:t};if(typeof t=="string"||typeof t=="number"){const i=C(t);if(isNaN(i))throw new Error(`[bwin] Invalid size value: ${i}`);return{size:t}}else{if(t==null)return{};throw new Error(`[bwin] Invalid config value: ${t}`)}}createPrimaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a}){return new D({parentRect:this,size:t??H.size,position:i??H.position,children:n,id:s,minWidth:o,minHeight:h,...a})}createSecondaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a},d){return new D({parentRect:this,size:t,position:i,children:n,siblingConfigNode:d,id:s,minWidth:o,minHeight:h,...a})}buildSashTree(){const t=this.createSash();if(!Array.isArray(this.children)||this.children.length===0)return t;const i=this.normConfig(this.children[0]),n=this.normConfig(this.children.at(1));let s,o;return!i.size&&!i.position&&n?(n.position||(n.position=r.Right),s=this.createPrimaryConfigNode(n),o=this.createSecondaryConfigNode(i,s)):(s=this.createPrimaryConfigNode(i),o=this.createSecondaryConfigNode(n,s)),s&&o&&(t.children.push(s.buildSashTree()),t.children.push(o.buildSashTree())),t}}const R={width:333,height:333},$={fitContainer:!1};class ot extends D{constructor({id:t,children:i,width:n=R.width,height:s=R.height,fitContainer:o=$.fitContainer,...h}={...R,...$}){super({id:t,children:i,size:NaN,position:r.Root,parentRect:{width:n,height:s},...h}),this.fitContainer=o}}class ht extends y{constructor(t=v){super({...t,position:r.Root}),Object.assign(this,$)}}function M(e){const t=document.createElement("bw-pane");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}function rt(e){const t=e.domNode;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}function at(e,{size:t}){const i=C(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new y({top:e.top,left:e.left,width:n,height:e.height,position:r.Left}),o=new y({top:e.top,left:e.left+s.width,width:e.width-n,height:e.height,position:r.Right}),h=M(o);return o.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),s}function lt(e,{size:t}){const i=C(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new y({left:e.left,top:e.top,width:e.width-n,height:e.height,position:r.Left}),o=new y({left:e.left+s.width,top:e.top,width:n,height:e.height,position:r.Right}),h=M(s);return s.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),o}function dt(e,{size:t}){const i=C(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new y({left:e.left,top:e.top,width:e.width,height:n,position:r.Top}),o=new y({left:e.left,top:e.top+s.height,width:e.width,height:e.height-n,position:r.Bottom}),h=M(o);return o.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),s}function ct(e,{size:t}){const i=C(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new y({top:e.top,left:e.left,width:e.width,height:e.height-n,position:r.Top}),o=new y({top:e.top+s.height,left:e.left,width:e.width,height:n,position:r.Bottom}),h=M(s);return s.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),o}function ut(e,{position:t,size:i,minWidth:n,minHeight:s}){if(t===r.Left)return at(e,{size:i});if(t===r.Right)return lt(e,{size:i});if(t===r.Top)return dt(e,{size:i});if(t===r.Bottom)return ct(e,{size:i})}const pt={createPane(e){const t=M(e);return e.store.droppable===!1&&t.setAttribute("can-drop","false"),t},onPaneCreate(e,t){t.store.content&&e.append(S(t.store.content)),this!=null&&this.debug&&(e.style.backgroundColor=j(),e.innerHTML="",e.append(O(e)))},updatePane(e){return rt(e)},onPaneUpdate(e,t){this!=null&&this.debug&&(e.innerHTML="",e.append(O(e)))},addPane(e,{position:t,size:i}){if(!t)throw new Error("[bwin] Position is required when adding pane");const n=this.rootSash.getById(e);if(!n)throw new Error("[bwin] Parent sash not found when adding pane");const s=ut(n,{position:t,size:i});return n.id=x(),this.update(),s},removePane(e){const t=this.rootSash.getDescendantParentById(e);if(!t)throw new Error("[bwin] Parent sash not found when removing pane");const i=t.getChildSiblingById(e);t.id=x(),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()}};function O(e){const t=document.createElement("pre");t.style.fontSize="10px";const i=`
1
+ (function(w,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],u):(w=typeof globalThis<"u"?globalThis:w||self,u(w.ReactBinaryWindow={},w.React,w.ReactDOM))})(this,function(w,u,_){"use strict";var q=Object.defineProperty,U=(e,t,i)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,E=(e,t,i)=>U(e,typeof t!="symbol"?t+"":t,i);function j(e=.7,t=128){const i=256-t,n=Math.floor(Math.random()*i+t),s=Math.floor(Math.random()*i+t),o=Math.floor(Math.random()*i+t),h=Math.max(.5,Math.random()*e);return`rgba(${n}, ${s}, ${o}, ${h})`}function x(e=2,t=3){if(e<0||t<0)throw new Error("Parameters must be non-negative numbers");const i="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789";let s="";for(let o=0;o<e;o++){const h=Math.floor(Math.random()*i.length);s+=i[h]}s+="-";for(let o=0;o<t;o++){const h=Math.floor(Math.random()*n.length);s+=n[h]}return s}function z(e,t){for(;t.firstChild;)e.append(t.firstChild)}function X(e,t){const i=document.createElement("div");z(i,e),z(e,t),z(t,i)}function C(e){if(typeof e=="number"&&!isNaN(e))return e;if(typeof e=="string"){const t=e.trim();if(t.endsWith("%")){const i=t.slice(0,-1);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n/100}if(t.endsWith("px")){const i=t.slice(0,-2);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n}return Number(t)}return NaN}function Y(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function K(e,t){for(const i in t){if(Object.hasOwn(e,i))throw new Error(`Key "${i}" already exists in target object`);e[i]=t[i]}return e}function V(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content}function S(e){if(e==null||e==="")return null;if(typeof e=="string")try{const t=V(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}function P(e){const t=parseFloat(e.style.left)||0,i=parseFloat(e.style.top)||0,n=parseFloat(e.style.width)||0,s=parseFloat(e.style.height)||0;return{left:t,top:i,width:n,height:s}}const r={Top:"top",Right:"right",Bottom:"bottom",Left:"left",Center:"center",Root:"root",Unknown:"unknown",Outside:"outside"};function Z(e){switch(e){case r.Top:return r.Bottom;case r.Right:return r.Left;case r.Bottom:return r.Top;case r.Left:return r.Right;default:throw new Error(`[bwin] Invalid position: ${e}`)}}function J({width:e,height:t,x:i}){return t/e*i}function Q({width:e,height:t,y:i}){return e/t*i}function tt({width:e,height:t,x:i}){return t-t/e*i}function et({width:e,height:t,y:i}){return e-e/t*i}function it(e,{clientX:t,clientY:i}){const n=e.getBoundingClientRect(),{width:s,height:o}=n,h=t-n.left,a=i-n.top;if(h<0||h>s||a<0||a>o)return r.Outside;const d=.3,l=J({width:s,height:o,x:h}),c=tt({width:s,height:o,x:h}),g=Q({width:s,height:o,y:a}),f=et({width:s,height:o,y:a});return h<s*(.5-d/2)&&a>l&&a<c?r.Left:h>s*(.5+d/2)&&a<l&&a>c?r.Right:a<o*(.5-d/2)&&h>g&&h<f?r.Top:a>o*(.5+d/2)&&h<g&&h>f?r.Bottom:h>s*(.5-d/2)&&h<s*(.5+d/2)&&a>o*(.5-d/2)&&a<o*(.5+d/2)?r.Center:r.Unknown}const nt=100,st=100,v={left:0,top:0,width:150,height:150,minWidth:nt,minHeight:st};class m{constructor({left:t=v.left,top:i=v.top,width:n=v.width,height:s=v.height,minWidth:o=v.minWidth,minHeight:h=v.minHeight,domNode:a=null,store:d={},position:l,id:c}=v){if(this.id=c??x(),!l)throw new Error("[bwin] Sash position is required");this.position=l,this.domNode=a,this._top=i,this._left=t,this._width=n,this._height=s,this.children=[],this.minWidth=o,this.minHeight=h,this.store=d}walk(t){this.children.forEach(i=>i.walk(t)),t(this)}isLeaf(){return this.children.length===0}isSplit(){return this.children.length>0}isLeftRightSplit(){return this.children.some(t=>t.position===r.Left||t.position===r.Right)}isTopBottomSplit(){return this.children.some(t=>t.position===r.Top||t.position===r.Bottom)}get leftChild(){return this.children.find(t=>t.position===r.Left)}get rightChild(){return this.children.find(t=>t.position===r.Right)}get topChild(){return this.children.find(t=>t.position===r.Top)}get bottomChild(){return this.children.find(t=>t.position===r.Bottom)}getChildren(){let t=null,i=null,n=null,s=null;for(const o of this.children)o.position===r.Left?t=o:o.position===r.Right?i=o:o.position===r.Top?n=o:o.position===r.Bottom&&(s=o);return[n,i,s,t]}getAllLeafDescendants(){const t=[];return this.walk(i=>{i.children.length===0&&t.push(i)}),t}calcMinWidth(){if(this.isLeaf())return this.minWidth;const[t,i,n,s]=this.getChildren();if(s&&i){const o=s.calcMinWidth()+i.calcMinWidth();return Math.max(this.minWidth,o)}if(t&&n){const o=Math.max(t.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,o)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;const[t,i,n,s]=this.getChildren();if(s&&i){const o=Math.max(s.calcMinHeight(),i.calcMinHeight());return Math.max(this.minHeight,o)}if(t&&n){const o=t.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,o)}}getById(t){if(this.id===t)return this;for(const i of this.children){const n=i.getById(t);if(n)return n}return null}getAllIds(){const t=[this.id];for(const i of this.children)t.push(...i.getAllIds());return t}addChild(t){if(this.children.length>=2)throw new Error("[bwin] Maximum 2 children allowed");this.children.push(t)}getDescendantParentById(t){for(const i of this.children){if(i.id===t)return this;const n=i.getDescendantParentById(t);if(n)return n}return null}getChildSiblingById(t){return this.children.find(i=>i.id!==t)}get top(){return this._top}set top(t){const i=t-this._top;this._top=t;const[n,s,o,h]=this.getChildren();n&&o&&(n.top+=i,o.top+=i),h&&s&&(h.top+=i,s.top+=i)}get left(){return this._left}set left(t){const i=t-this._left;this._left=t;const[n,s,o,h]=this.getChildren();h&&s&&(h.left+=i,s.left+=i),n&&o&&(n.left+=i,o.left+=i)}get width(){return this._width}set width(t){const i=t-this._width;this._width=t;const[n,s,o,h]=this.getChildren();if(h&&s){const a=h.width+s.width,d=i*(h.width/a),l=a+i;let c=h.width+d,g=l-c,f=s.left+d;const b=h.calcMinWidth(),y=s.calcMinWidth();i<0&&(c<b&&g>y?(c=h.width,g=l-c,f=h.left+c):g<y&&c>b&&(g=s.width,c=l-g,f=h.left+c)),h.width=c,s.width=g,s.left=f}n&&o&&(n.width+=i,o.width+=i)}get height(){return this._height}set height(t){const i=t-this._height;this._height=t;const[n,s,o,h]=this.getChildren();if(n&&o){const a=n.height+o.height,d=i*(n.height/a),l=a+i;let c=n.height+d,g=l-c,f=o.top+d;if(i<0){const b=n.calcMinHeight(),y=o.calcMinHeight();c<b&&g>y?(c=n.height,g=l-c,f=n.top+c):g<y&&c>b&&(g=o.height,c=l-g,f=n.top+c)}n.height=c,o.height=g,o.top=f}h&&s&&(h.height+=i,s.height+=i)}}const H={size:"50%",position:r.Left};class D{constructor({parentRect:t,children:i,siblingConfigNode:n,id:s,minWidth:o,minHeight:h,position:a,size:d,...l}){E(this,"left"),E(this,"top"),E(this,"width"),E(this,"height"),this.parentRect=t,this.children=i,this.siblingConfigNode=n,this.id=s,this.minWidth=o,this.minHeight=h,this.position=this.getPosition(a),this.size=this.getSize(d),this.nonCoreData=l,this.setBounds()}getPosition(t){if(!this.siblingConfigNode)return t;const i=Z(this.siblingConfigNode.position);if(!t)return i;if(t!==i)throw new Error("[bwin] Sibling position and current position are not opposite");return t}getSize(t){if(!this.siblingConfigNode)return C(t);if(!t){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===r.Left||this.siblingConfigNode.position===r.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===r.Top||this.siblingConfigNode.position===r.Bottom)return this.parentRect.height-this.siblingConfigNode.height}const i=C(t);if(i<1){if(i+this.siblingConfigNode.size!==1)throw new Error("[bwin] Sum of sibling sizes is not equal to 1")}else{if((this.position===r.Left||this.position===r.Right)&&i+this.siblingConfigNode.size!==this.parentRect.width)throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");if((this.position===r.Top||this.position===r.Bottom)&&i+this.siblingConfigNode.size!==this.parentRect.height)throw new Error("[bwin] Sum of sibling sizes is not equal to parent height")}return i}setBounds(){if(this.position===r.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===r.Left){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Right){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left+this.parentRect.width-t,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Top){const t=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=this.parentRect.width,this.height=t}else if(this.position===r.Bottom){const t=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top+this.parentRect.height-t,this.width=this.parentRect.width,this.height=t}}createSash(){return new m({left:this.left,top:this.top,width:this.width,height:this.height,position:this.position,id:this.id,minWidth:this.minWidth,minHeight:this.minHeight,store:this.nonCoreData})}normConfig(t){if(Y(t))return t;if(Array.isArray(t))return{children:t};if(typeof t=="string"||typeof t=="number"){const i=C(t);if(isNaN(i))throw new Error(`[bwin] Invalid size value: ${i}`);return{size:t}}else{if(t==null)return{};throw new Error(`[bwin] Invalid config value: ${t}`)}}createPrimaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a}){return new D({parentRect:this,size:t??H.size,position:i??H.position,children:n,id:s,minWidth:o,minHeight:h,...a})}createSecondaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a},d){return new D({parentRect:this,size:t,position:i,children:n,siblingConfigNode:d,id:s,minWidth:o,minHeight:h,...a})}buildSashTree(){const t=this.createSash();if(!Array.isArray(this.children)||this.children.length===0)return t;const i=this.normConfig(this.children[0]),n=this.normConfig(this.children.at(1));let s,o;return!i.size&&!i.position&&n?(n.position||(n.position=r.Right),s=this.createPrimaryConfigNode(n),o=this.createSecondaryConfigNode(i,s)):(s=this.createPrimaryConfigNode(i),o=this.createSecondaryConfigNode(n,s)),s&&o&&(t.children.push(s.buildSashTree()),t.children.push(o.buildSashTree())),t}}const R={width:333,height:333},$={fitContainer:!1};class ot extends D{constructor({id:t,children:i,width:n=R.width,height:s=R.height,fitContainer:o=$.fitContainer,...h}={...R,...$}){super({id:t,children:i,size:NaN,position:r.Root,parentRect:{width:n,height:s},...h}),this.fitContainer=o}}class ht extends m{constructor(t=v){super({...t,position:r.Root}),Object.assign(this,$)}}function M(e){const t=document.createElement("bw-pane");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}function rt(e){const t=e.domNode;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}function at(e,{size:t}){const i=C(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new m({top:e.top,left:e.left,width:n,height:e.height,position:r.Left}),o=new m({top:e.top,left:e.left+s.width,width:e.width-n,height:e.height,position:r.Right}),h=M(o);return o.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),s}function lt(e,{size:t}){const i=C(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new m({left:e.left,top:e.top,width:e.width-n,height:e.height,position:r.Left}),o=new m({left:e.left+s.width,top:e.top,width:n,height:e.height,position:r.Right}),h=M(s);return s.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),o}function dt(e,{size:t}){const i=C(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new m({left:e.left,top:e.top,width:e.width,height:n,position:r.Top}),o=new m({left:e.left,top:e.top+s.height,width:e.width,height:e.height-n,position:r.Bottom}),h=M(o);return o.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),s}function ct(e,{size:t}){const i=C(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new m({top:e.top,left:e.left,width:e.width,height:e.height-n,position:r.Top}),o=new m({top:e.top+s.height,left:e.left,width:e.width,height:n,position:r.Bottom}),h=M(s);return s.domNode=h,z(h,e.domNode),e.addChild(s),e.addChild(o),o}function ut(e,{position:t,size:i,minWidth:n,minHeight:s}){if(t===r.Left)return at(e,{size:i});if(t===r.Right)return lt(e,{size:i});if(t===r.Top)return dt(e,{size:i});if(t===r.Bottom)return ct(e,{size:i})}const pt={createPane(e){const t=M(e);return e.store.droppable===!1&&t.setAttribute("can-drop","false"),t},onPaneCreate(e,t){t.store.content&&e.append(S(t.store.content)),this!=null&&this.debug&&(e.style.backgroundColor=j(),e.innerHTML="",e.append(O(e)))},updatePane(e){return rt(e)},onPaneUpdate(e,t){this!=null&&this.debug&&(e.innerHTML="",e.append(O(e)))},addPane(e,{position:t,size:i}){if(!t)throw new Error("[bwin] Position is required when adding pane");const n=this.rootSash.getById(e);if(!n)throw new Error("[bwin] Parent sash not found when adding pane");const s=ut(n,{position:t,size:i});return n.id=x(),this.update(),s},removePane(e){const t=this.rootSash.getDescendantParentById(e);if(!t)throw new Error("[bwin] Parent sash not found when removing pane");const i=t.getChildSiblingById(e);t.id=x(),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()}};function O(e){const t=document.createElement("pre");t.style.fontSize="10px";const i=`
2
2
  ${e.getAttribute("sash-id")}
3
3
  ${e.getAttribute("position")}
4
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){}},mt={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)}},wt={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(d<=s.calcMinWidth()||l<=i.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(d<=t.calcMinHeight()||l<=n.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,mt,bt,wt);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,m,w;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"},((m=e.store)==null?void 0:m.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,(w=e.store)==null?void 0:w.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:w}),[]);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})),m=u.useMemo(()=>f,[]);function w(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,m,s==null?void 0:s.map(p=>_.createPortal(p.node,p.container)))}),xt="0.3.0";b.BUILTIN_ACTIONS=L,b.Window=Dt,b.version=xt,Object.defineProperty(b,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 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"})});
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.0",
4
+ "version": "0.3.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -45,11 +45,10 @@
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.0",
48
+ "bwin": "0.2.1",
49
49
  "prettier": "^3.4.1",
50
50
  "react": "^16.14.0",
51
51
  "react-dom": "^16.14.0",
52
- "react-router-dom": "6.27.0",
53
52
  "typescript": "^5.6.2",
54
53
  "vite": "^6.0.1",
55
54
  "zustand": "^4.5.5"