react-bwin 0.1.0
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/react-bwin.css +1 -0
- package/dist/react-bwin.d.ts +87 -0
- package/dist/react-bwin.js +1011 -0
- package/dist/react-bwin.umd.cjs +8 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Bhjs Dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--bw-font-family: system-ui;--bw-font-size: 14px;--bw-drop-area-bg-color: hsl(0, 0%, 0%, .05);--bw-glass-clearance: 2px;--bw-glass-border-radius: 2px;--bw-glass-border-color: hsl(0, 0%, 10%);--bw-glass-border-color-disabled: hsl(0, 0%, 80%);--bw-glass-bg-color-disabled: hsl(0, 0%, 100%);--bw-glass-header-height: 30px;--bw-glass-header-gap: 4px;--bw-glass-header-bg-color: hsl(0, 0%, 97%)}.body--bw-resize-x{-webkit-user-select:none;user-select:none;cursor:ew-resize}.body--bw-resize-y{-webkit-user-select:none;user-select:none;cursor:ns-resize}bw-window{position:absolute;display:block;box-sizing:border-box}bw-pane{position:absolute;overflow:auto;box-sizing:border-box;background-color:#f2f2f2}bw-pane[drop-area]:before{content:"";position:absolute;background-color:var(--bw-drop-area-bg-color)}bw-pane[drop-area=top]:before{top:0;left:0;right:0;height:50%}bw-pane[drop-area=right]:before{top:0;right:0;bottom:0;width:50%}bw-pane[drop-area=bottom]:before{bottom:0;left:0;right:0;height:50%}bw-pane[drop-area=left]:before{top:0;left:0;bottom:0;width:50%}bw-pane[drop-area=center]:before{top:0;left:0;right:0;bottom:0}bw-muntin{box-sizing:border-box;position:absolute;background-color:#fff}bw-muntin[horizontal]{cursor:ns-resize}bw-muntin[vertical]{cursor:ew-resize}bw-muntin[resizable=false]{cursor:auto}bw-window:has(bw-glass) bw-pane{background-color:transparent}bw-window:has(bw-glass) bw-pane[drop-area]:before{z-index:1}bw-window:has(bw-glass) bw-pane[drop-area=top]:before{top:var(--bw-glass-clearance);left:var(--bw-glass-clearance);right:var(--bw-glass-clearance);height:50%}bw-window:has(bw-glass) bw-pane[drop-area=right]:before{top:var(--bw-glass-clearance);right:var(--bw-glass-clearance);bottom:var(--bw-glass-clearance);width:50%}bw-window:has(bw-glass) bw-pane[drop-area=bottom]:before{bottom:var(--bw-glass-clearance);left:var(--bw-glass-clearance);right:var(--bw-glass-clearance);height:50%}bw-window:has(bw-glass) bw-pane[drop-area=left]:before{top:var(--bw-glass-clearance);left:var(--bw-glass-clearance);bottom:var(--bw-glass-clearance);width:50%}bw-window:has(bw-glass) bw-pane[drop-area=center]:before{inset:var(--bw-glass-clearance)}bw-window:has(bw-glass) bw-muntin{background-color:transparent}bw-glass{position:absolute;inset:var(--bw-glass-clearance);display:flex;flex-direction:column;border:1px solid var(--bw-glass-border-color);border-radius:var(--bw-glass-border-radius);background-color:#fff;font-family:var(--bw-font-family);font-size:var(--bw-font-size);box-sizing:border-box}bw-glass[draggable=true]:active{cursor:move;opacity:.3}bw-glass-header{white-space:nowrap;box-sizing:border-box;display:flex;align-items:center;gap:var(--bw-glass-header-gap);padding-inline:var(--bw-glass-header-gap);flex-basis:var(--bw-glass-header-height);border-bottom:1px solid var(--bw-glass-border-color);border-top-left-radius:var(--bw-glass-border-radius);border-top-right-radius:var(--bw-glass-border-radius);background-color:var(--bw-glass-header-bg-color)}bw-glass-tab-container{align-self:flex-end;display:flex;gap:var(--bw-glass-header-gap)}.bw-glass-tab{font-family:var(--bw-font-family);border:1px solid var(--bw-glass-border-color);border-bottom:none;border-top-left-radius:var(--bw-glass-border-radius);border-top-right-radius:var(--bw-glass-border-radius);cursor:pointer}.bw-glass-tab:hover{background-color:#fff}.bw-glass-tab:active{transform:translateY(1px)}bw-glass-action-container{margin-left:auto;display:flex;gap:2px}.bw-glass-action{font-family:var(--bw-font-family);border:1px solid var(--bw-glass-border-color);border-radius:var(--bw-glass-border-radius);cursor:pointer}.bw-glass-action:hover{background-color:#fff}.bw-glass-action:active{transform:scale(.95)}.bw-glass-action--close:before{content:"✕"}.bw-glass-action--close:disabled{border:1px solid var(--bw-glass-border-color-disabled);background-color:var(--bw-glass-bg-color-disabled);cursor:not-allowed}.bw-glass-action--close:disabled:hover{background-color:var(--bw-glass-bg-color-disabled)}.bw-glass-action--close:disabled:active{transform:scale(1)}bw-glass-content{display:block;box-sizing:border-box;overflow:auto;flex-grow:1}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
declare module 'react-bwin' {
|
|
2
|
+
export const BUILTIN_ACTIONS: Action[]
|
|
3
|
+
export const Window: React.FC<WindowProps>
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
type Position = 'left' | 'right' | 'top' | 'bottom'
|
|
8
|
+
|
|
9
|
+
type Action = {
|
|
10
|
+
label?: string
|
|
11
|
+
className?: string
|
|
12
|
+
onClick: (
|
|
13
|
+
event: React.MouseEvent<HTMLButtonElement>,
|
|
14
|
+
bwin: BinaryWindow
|
|
15
|
+
) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Actions = undefined | null | Action[]
|
|
19
|
+
|
|
20
|
+
interface Sash {
|
|
21
|
+
id: string
|
|
22
|
+
position: Position
|
|
23
|
+
left: number
|
|
24
|
+
top: number
|
|
25
|
+
width: number
|
|
26
|
+
height: number
|
|
27
|
+
children: Sash[]
|
|
28
|
+
domNode?: HTMLElement
|
|
29
|
+
leftChild?: Sash
|
|
30
|
+
rightChild?: Sash
|
|
31
|
+
topChild?: Sash
|
|
32
|
+
bottomChild?: Sash
|
|
33
|
+
store?: {
|
|
34
|
+
actions?: Actions
|
|
35
|
+
droppable?: boolean
|
|
36
|
+
draggable?: boolean
|
|
37
|
+
title?: any
|
|
38
|
+
content?: any
|
|
39
|
+
resizable?: boolean
|
|
40
|
+
}
|
|
41
|
+
walk(callback: (sash: Sash) => void): void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type ConfigNode = {
|
|
45
|
+
id?: string
|
|
46
|
+
size?: number
|
|
47
|
+
position?: Position
|
|
48
|
+
title?: React.ReactNode
|
|
49
|
+
content?: React.ReactNode
|
|
50
|
+
actions?: Actions
|
|
51
|
+
children?: ConfigNode[]
|
|
52
|
+
draggable?: boolean
|
|
53
|
+
droppable?: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type ConfigRoot = {
|
|
57
|
+
id?: string
|
|
58
|
+
width?: number
|
|
59
|
+
height?: number
|
|
60
|
+
fitContainer?: boolean
|
|
61
|
+
title?: React.ReactNode
|
|
62
|
+
content?: React.ReactNode
|
|
63
|
+
children?: ConfigNode[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface BinaryWindow {
|
|
67
|
+
new (settings: ConfigRoot): BinaryWindow
|
|
68
|
+
rootSash: Sash
|
|
69
|
+
windowElement: HTMLElement
|
|
70
|
+
containerElement: HTMLElement
|
|
71
|
+
mount(container: HTMLElement): void
|
|
72
|
+
enableFeatures(): void
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type WindowProps = ConfigRoot
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
Position,
|
|
80
|
+
Action,
|
|
81
|
+
Actions,
|
|
82
|
+
Sash,
|
|
83
|
+
ConfigNode,
|
|
84
|
+
ConfigRoot,
|
|
85
|
+
BinaryWindow,
|
|
86
|
+
WindowProps,
|
|
87
|
+
}
|
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
import g, { useRef as x, useEffect as $ } from "react";
|
|
2
|
+
var F = Object.defineProperty, U = (e, t, i) => t in e ? F(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);
|
|
3
|
+
function X(e = 0.7, t = 128) {
|
|
4
|
+
const i = 256 - t, n = Math.floor(Math.random() * i + t), o = Math.floor(Math.random() * i + t), s = Math.floor(Math.random() * i + t), r = Math.max(0.5, Math.random() * e);
|
|
5
|
+
return `rgba(${n}, ${o}, ${s}, ${r})`;
|
|
6
|
+
}
|
|
7
|
+
function P(e = 2, t = 3) {
|
|
8
|
+
if (e < 0 || t < 0)
|
|
9
|
+
throw new Error("Parameters must be non-negative numbers");
|
|
10
|
+
const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "0123456789";
|
|
11
|
+
let o = "";
|
|
12
|
+
for (let s = 0; s < e; s++) {
|
|
13
|
+
const r = Math.floor(Math.random() * i.length);
|
|
14
|
+
o += i[r];
|
|
15
|
+
}
|
|
16
|
+
o += "-";
|
|
17
|
+
for (let s = 0; s < t; s++) {
|
|
18
|
+
const r = Math.floor(Math.random() * n.length);
|
|
19
|
+
o += n[r];
|
|
20
|
+
}
|
|
21
|
+
return o;
|
|
22
|
+
}
|
|
23
|
+
function v(e, t) {
|
|
24
|
+
for (; t.firstChild; )
|
|
25
|
+
e.append(t.firstChild);
|
|
26
|
+
}
|
|
27
|
+
function Y(e, t) {
|
|
28
|
+
const i = document.createElement("div");
|
|
29
|
+
v(i, e), v(e, t), v(t, i);
|
|
30
|
+
}
|
|
31
|
+
function R(e) {
|
|
32
|
+
if (typeof e == "number" && !isNaN(e))
|
|
33
|
+
return e;
|
|
34
|
+
if (typeof e == "string") {
|
|
35
|
+
const t = e.trim();
|
|
36
|
+
if (t.endsWith("%")) {
|
|
37
|
+
const i = t.slice(0, -1);
|
|
38
|
+
if (!i) return NaN;
|
|
39
|
+
const n = Number(i);
|
|
40
|
+
return isNaN(n) ? NaN : n / 100;
|
|
41
|
+
}
|
|
42
|
+
if (t.endsWith("px")) {
|
|
43
|
+
const i = t.slice(0, -2);
|
|
44
|
+
if (!i) return NaN;
|
|
45
|
+
const n = Number(i);
|
|
46
|
+
return isNaN(n) ? NaN : n;
|
|
47
|
+
}
|
|
48
|
+
return Number(t);
|
|
49
|
+
}
|
|
50
|
+
return NaN;
|
|
51
|
+
}
|
|
52
|
+
function j(e) {
|
|
53
|
+
return e !== null && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
|
|
54
|
+
}
|
|
55
|
+
function K(e, t) {
|
|
56
|
+
for (const i in t) {
|
|
57
|
+
if (Object.hasOwn(e, i))
|
|
58
|
+
throw new Error(`Key "${i}" already exists in target object`);
|
|
59
|
+
e[i] = t[i];
|
|
60
|
+
}
|
|
61
|
+
return e;
|
|
62
|
+
}
|
|
63
|
+
function V(e) {
|
|
64
|
+
const t = document.createElement("template");
|
|
65
|
+
return t.innerHTML = e.trim(), t.content;
|
|
66
|
+
}
|
|
67
|
+
function C(e) {
|
|
68
|
+
if (e == null || e === "")
|
|
69
|
+
return null;
|
|
70
|
+
if (typeof e == "string")
|
|
71
|
+
try {
|
|
72
|
+
const t = V(e);
|
|
73
|
+
return t.childNodes.length === 1 ? t.firstChild : t;
|
|
74
|
+
} catch {
|
|
75
|
+
return document.createTextNode(e);
|
|
76
|
+
}
|
|
77
|
+
return e instanceof Node ? e : document.createTextNode(String(e));
|
|
78
|
+
}
|
|
79
|
+
const h = {
|
|
80
|
+
Top: "top",
|
|
81
|
+
Right: "right",
|
|
82
|
+
Bottom: "bottom",
|
|
83
|
+
Left: "left",
|
|
84
|
+
Center: "center",
|
|
85
|
+
Root: "root",
|
|
86
|
+
Unknown: "unknown",
|
|
87
|
+
Outside: "outside"
|
|
88
|
+
};
|
|
89
|
+
function Z(e) {
|
|
90
|
+
switch (e) {
|
|
91
|
+
case h.Top:
|
|
92
|
+
return h.Bottom;
|
|
93
|
+
case h.Right:
|
|
94
|
+
return h.Left;
|
|
95
|
+
case h.Bottom:
|
|
96
|
+
return h.Top;
|
|
97
|
+
case h.Left:
|
|
98
|
+
return h.Right;
|
|
99
|
+
default:
|
|
100
|
+
throw new Error(`[bwin] Invalid position: ${e}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function J({ width: e, height: t, x: i }) {
|
|
104
|
+
return t / e * i;
|
|
105
|
+
}
|
|
106
|
+
function Q({ width: e, height: t, y: i }) {
|
|
107
|
+
return e / t * i;
|
|
108
|
+
}
|
|
109
|
+
function tt({ width: e, height: t, x: i }) {
|
|
110
|
+
return t - t / e * i;
|
|
111
|
+
}
|
|
112
|
+
function et({ width: e, height: t, y: i }) {
|
|
113
|
+
return e - e / t * i;
|
|
114
|
+
}
|
|
115
|
+
function it(e, { clientX: t, clientY: i }) {
|
|
116
|
+
const n = e.getBoundingClientRect(), { width: o, height: s } = n, r = t - n.left, a = i - n.top;
|
|
117
|
+
if (r < 0 || r > o || a < 0 || a > s)
|
|
118
|
+
return h.Outside;
|
|
119
|
+
const l = 0.3, c = J({ width: o, height: s, x: r }), d = tt({ width: o, height: s, x: r }), p = Q({ width: o, height: s, y: a }), u = et({ width: o, height: s, y: a });
|
|
120
|
+
return r < o * (0.5 - l / 2) && a > c && a < d ? h.Left : r > o * (0.5 + l / 2) && a < c && a > d ? h.Right : a < s * (0.5 - l / 2) && r > p && r < u ? h.Top : a > s * (0.5 + l / 2) && r < p && r > u ? h.Bottom : r > o * (0.5 - l / 2) && r < o * (0.5 + l / 2) && a > s * (0.5 - l / 2) && a < s * (0.5 + l / 2) ? h.Center : h.Unknown;
|
|
121
|
+
}
|
|
122
|
+
const y = {
|
|
123
|
+
top: 0,
|
|
124
|
+
left: 0,
|
|
125
|
+
width: 100,
|
|
126
|
+
height: 100,
|
|
127
|
+
// Initial min values, real min width/height is calculated based on children
|
|
128
|
+
minWidth: 50,
|
|
129
|
+
minHeight: 50
|
|
130
|
+
};
|
|
131
|
+
class m {
|
|
132
|
+
constructor({
|
|
133
|
+
top: t = y.top,
|
|
134
|
+
left: i = y.left,
|
|
135
|
+
width: n = y.width,
|
|
136
|
+
height: o = y.height,
|
|
137
|
+
minWidth: s = y.minWidth,
|
|
138
|
+
minHeight: r = y.minHeight,
|
|
139
|
+
domNode: a = null,
|
|
140
|
+
store: l = {},
|
|
141
|
+
position: c,
|
|
142
|
+
id: d
|
|
143
|
+
} = y) {
|
|
144
|
+
if (this.id = d ?? P(), !c)
|
|
145
|
+
throw new Error("[bwin] Sash position is required");
|
|
146
|
+
this.position = c, this.domNode = a, this._top = t, this._left = i, this._width = n, this._height = o, this.children = [], this.minWidth = s, this.minHeight = r, this.store = l;
|
|
147
|
+
}
|
|
148
|
+
walk(t) {
|
|
149
|
+
this.children.forEach((i) => i.walk(t)), t(this);
|
|
150
|
+
}
|
|
151
|
+
isLeaf() {
|
|
152
|
+
return this.children.length === 0;
|
|
153
|
+
}
|
|
154
|
+
// A sash that doesn't split is a leaf, in UI it's a pane
|
|
155
|
+
isSplit() {
|
|
156
|
+
return this.children.length > 0;
|
|
157
|
+
}
|
|
158
|
+
isLeftRightSplit() {
|
|
159
|
+
return this.children.some(
|
|
160
|
+
(t) => t.position === h.Left || t.position === h.Right
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
isTopBottomSplit() {
|
|
164
|
+
return this.children.some(
|
|
165
|
+
(t) => t.position === h.Top || t.position === h.Bottom
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
get leftChild() {
|
|
169
|
+
return this.children.find((t) => t.position === h.Left);
|
|
170
|
+
}
|
|
171
|
+
get rightChild() {
|
|
172
|
+
return this.children.find((t) => t.position === h.Right);
|
|
173
|
+
}
|
|
174
|
+
get topChild() {
|
|
175
|
+
return this.children.find((t) => t.position === h.Top);
|
|
176
|
+
}
|
|
177
|
+
get bottomChild() {
|
|
178
|
+
return this.children.find((t) => t.position === h.Bottom);
|
|
179
|
+
}
|
|
180
|
+
getChildren() {
|
|
181
|
+
let t = null, i = null, n = null, o = null;
|
|
182
|
+
for (const s of this.children)
|
|
183
|
+
s.position === h.Left ? t = s : s.position === h.Right ? i = s : s.position === h.Top ? n = s : s.position === h.Bottom && (o = s);
|
|
184
|
+
return [n, i, o, t];
|
|
185
|
+
}
|
|
186
|
+
getAllLeafDescendants() {
|
|
187
|
+
const t = [];
|
|
188
|
+
return this.walk((i) => {
|
|
189
|
+
i.children.length === 0 && t.push(i);
|
|
190
|
+
}), t;
|
|
191
|
+
}
|
|
192
|
+
calcMinWidth() {
|
|
193
|
+
if (this.isLeaf())
|
|
194
|
+
return this.minWidth;
|
|
195
|
+
const [t, i, n, o] = this.getChildren();
|
|
196
|
+
if (o && i) {
|
|
197
|
+
const s = o.calcMinWidth() + i.calcMinWidth();
|
|
198
|
+
return Math.max(this.minWidth, s);
|
|
199
|
+
}
|
|
200
|
+
if (t && n) {
|
|
201
|
+
const s = Math.max(t.calcMinWidth(), n.calcMinWidth());
|
|
202
|
+
return Math.max(this.minWidth, s);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
calcMinHeight() {
|
|
206
|
+
if (this.isLeaf())
|
|
207
|
+
return this.minHeight;
|
|
208
|
+
const [t, i, n, o] = this.getChildren();
|
|
209
|
+
if (o && i) {
|
|
210
|
+
const s = Math.max(o.calcMinHeight(), i.calcMinHeight());
|
|
211
|
+
return Math.max(this.minHeight, s);
|
|
212
|
+
}
|
|
213
|
+
if (t && n) {
|
|
214
|
+
const s = t.calcMinHeight() + n.calcMinHeight();
|
|
215
|
+
return Math.max(this.minHeight, s);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Get self or descendant by id
|
|
219
|
+
getById(t) {
|
|
220
|
+
if (this.id === t)
|
|
221
|
+
return this;
|
|
222
|
+
for (const i of this.children) {
|
|
223
|
+
const n = i.getById(t);
|
|
224
|
+
if (n)
|
|
225
|
+
return n;
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
// Get all ids of self and descendants
|
|
230
|
+
getAllIds() {
|
|
231
|
+
const t = [this.id];
|
|
232
|
+
for (const i of this.children)
|
|
233
|
+
t.push(...i.getAllIds());
|
|
234
|
+
return t;
|
|
235
|
+
}
|
|
236
|
+
addChild(t) {
|
|
237
|
+
if (this.children.length >= 2)
|
|
238
|
+
throw new Error("[bwin] Maximum 2 children allowed");
|
|
239
|
+
this.children.push(t);
|
|
240
|
+
}
|
|
241
|
+
getDescendantParentById(t) {
|
|
242
|
+
for (const i of this.children) {
|
|
243
|
+
if (i.id === t)
|
|
244
|
+
return this;
|
|
245
|
+
const n = i.getDescendantParentById(t);
|
|
246
|
+
if (n)
|
|
247
|
+
return n;
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
getChildSiblingById(t) {
|
|
252
|
+
return this.children.find((i) => i.id !== t);
|
|
253
|
+
}
|
|
254
|
+
get top() {
|
|
255
|
+
return this._top;
|
|
256
|
+
}
|
|
257
|
+
set top(t) {
|
|
258
|
+
const i = t - this._top;
|
|
259
|
+
this._top = t;
|
|
260
|
+
const [n, o, s, r] = this.getChildren();
|
|
261
|
+
n && s && (n.top += i, s.top += i), r && o && (r.top += i, o.top += i);
|
|
262
|
+
}
|
|
263
|
+
get left() {
|
|
264
|
+
return this._left;
|
|
265
|
+
}
|
|
266
|
+
set left(t) {
|
|
267
|
+
const i = t - this._left;
|
|
268
|
+
this._left = t;
|
|
269
|
+
const [n, o, s, r] = this.getChildren();
|
|
270
|
+
r && o && (r.left += i, o.left += i), n && s && (n.left += i, s.left += i);
|
|
271
|
+
}
|
|
272
|
+
get width() {
|
|
273
|
+
return this._width;
|
|
274
|
+
}
|
|
275
|
+
set width(t) {
|
|
276
|
+
const i = t - this._width;
|
|
277
|
+
this._width = t;
|
|
278
|
+
const [n, o, s, r] = this.getChildren();
|
|
279
|
+
if (r && o) {
|
|
280
|
+
const a = r.width + o.width, l = i * (r.width / a), c = a + i;
|
|
281
|
+
let d = r.width + l, p = c - d, u = o.left + l;
|
|
282
|
+
const f = r.calcMinWidth(), w = o.calcMinWidth();
|
|
283
|
+
d < f && p > w ? (d = f, p = c - d, u = r.left + d) : p < w && d > f && (p = w, d = c - p, u = r.left + d), r.width = d, o.width = p, o.left = u;
|
|
284
|
+
}
|
|
285
|
+
n && s && (n.width += i, s.width += i);
|
|
286
|
+
}
|
|
287
|
+
get height() {
|
|
288
|
+
return this._height;
|
|
289
|
+
}
|
|
290
|
+
set height(t) {
|
|
291
|
+
const i = t - this._height;
|
|
292
|
+
this._height = t;
|
|
293
|
+
const [n, o, s, r] = this.getChildren();
|
|
294
|
+
if (n && s) {
|
|
295
|
+
const a = n.height + s.height, l = i * (n.height / a), c = a + i;
|
|
296
|
+
let d = n.height + l, p = c - d, u = s.top + l;
|
|
297
|
+
const f = n.calcMinHeight(), w = s.calcMinHeight();
|
|
298
|
+
d < f && p > w ? (d = f, p = c - d, u = n.top + d) : p < w && d > f && (p = w, d = c - p, u = n.top + d), n.height = d, s.height = p, s.top = u;
|
|
299
|
+
}
|
|
300
|
+
r && o && (r.height += i, o.height += i);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const L = {
|
|
304
|
+
size: "50%",
|
|
305
|
+
position: h.Left
|
|
306
|
+
};
|
|
307
|
+
class M {
|
|
308
|
+
constructor({
|
|
309
|
+
parentRect: t,
|
|
310
|
+
children: i,
|
|
311
|
+
siblingConfigNode: n,
|
|
312
|
+
id: o,
|
|
313
|
+
minWidth: s,
|
|
314
|
+
minHeight: r,
|
|
315
|
+
position: a,
|
|
316
|
+
size: l,
|
|
317
|
+
...c
|
|
318
|
+
}) {
|
|
319
|
+
E(this, "left"), E(this, "top"), E(this, "width"), E(this, "height"), this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = o, this.minWidth = s, this.minHeight = r, this.position = this.getPosition(a), this.size = this.getSize(l), this.nonCoreData = c, this.setBounds();
|
|
320
|
+
}
|
|
321
|
+
getPosition(t) {
|
|
322
|
+
if (!this.siblingConfigNode)
|
|
323
|
+
return t;
|
|
324
|
+
const i = Z(this.siblingConfigNode.position);
|
|
325
|
+
if (!t)
|
|
326
|
+
return i;
|
|
327
|
+
if (t !== i)
|
|
328
|
+
throw new Error("[bwin] Sibling position and current position are not opposite");
|
|
329
|
+
return t;
|
|
330
|
+
}
|
|
331
|
+
getSize(t) {
|
|
332
|
+
if (!this.siblingConfigNode)
|
|
333
|
+
return R(t);
|
|
334
|
+
if (!t) {
|
|
335
|
+
if (this.siblingConfigNode.size < 1)
|
|
336
|
+
return 1 - this.siblingConfigNode.size;
|
|
337
|
+
if (this.siblingConfigNode.position === h.Left || this.siblingConfigNode.position === h.Right)
|
|
338
|
+
return this.parentRect.width - this.siblingConfigNode.width;
|
|
339
|
+
if (this.siblingConfigNode.position === h.Top || this.siblingConfigNode.position === h.Bottom)
|
|
340
|
+
return this.parentRect.height - this.siblingConfigNode.height;
|
|
341
|
+
}
|
|
342
|
+
const i = R(t);
|
|
343
|
+
if (i < 1) {
|
|
344
|
+
if (i + this.siblingConfigNode.size !== 1)
|
|
345
|
+
throw new Error("[bwin] Sum of sibling sizes is not equal to 1");
|
|
346
|
+
} else {
|
|
347
|
+
if ((this.position === h.Left || this.position === h.Right) && i + this.siblingConfigNode.size !== this.parentRect.width)
|
|
348
|
+
throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");
|
|
349
|
+
if ((this.position === h.Top || this.position === h.Bottom) && i + this.siblingConfigNode.size !== this.parentRect.height)
|
|
350
|
+
throw new Error("[bwin] Sum of sibling sizes is not equal to parent height");
|
|
351
|
+
}
|
|
352
|
+
return i;
|
|
353
|
+
}
|
|
354
|
+
setBounds() {
|
|
355
|
+
if (this.position === h.Root)
|
|
356
|
+
this.left = 0, this.top = 0, this.width = this.parentRect.width, this.height = this.parentRect.height;
|
|
357
|
+
else if (this.position === h.Left) {
|
|
358
|
+
const t = this.size < 1 ? this.parentRect.width * this.size : this.size;
|
|
359
|
+
this.left = this.parentRect.left, this.top = this.parentRect.top, this.width = t, this.height = this.parentRect.height;
|
|
360
|
+
} else if (this.position === h.Right) {
|
|
361
|
+
const t = this.size < 1 ? this.parentRect.width * this.size : this.size;
|
|
362
|
+
this.left = this.parentRect.left + this.parentRect.width - t, this.top = this.parentRect.top, this.width = t, this.height = this.parentRect.height;
|
|
363
|
+
} else if (this.position === h.Top) {
|
|
364
|
+
const t = this.size < 1 ? this.parentRect.height * this.size : this.size;
|
|
365
|
+
this.left = this.parentRect.left, this.top = this.parentRect.top, this.width = this.parentRect.width, this.height = t;
|
|
366
|
+
} else if (this.position === h.Bottom) {
|
|
367
|
+
const t = this.size < 1 ? this.parentRect.height * this.size : this.size;
|
|
368
|
+
this.left = this.parentRect.left, this.top = this.parentRect.top + this.parentRect.height - t, this.width = this.parentRect.width, this.height = t;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
createSash() {
|
|
372
|
+
return new m({
|
|
373
|
+
left: this.left,
|
|
374
|
+
top: this.top,
|
|
375
|
+
width: this.width,
|
|
376
|
+
height: this.height,
|
|
377
|
+
position: this.position,
|
|
378
|
+
id: this.id,
|
|
379
|
+
minWidth: this.minWidth,
|
|
380
|
+
minHeight: this.minHeight,
|
|
381
|
+
store: this.nonCoreData
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
normConfig(t) {
|
|
385
|
+
if (j(t))
|
|
386
|
+
return t;
|
|
387
|
+
if (Array.isArray(t))
|
|
388
|
+
return {
|
|
389
|
+
children: t
|
|
390
|
+
};
|
|
391
|
+
if (typeof t == "string" || typeof t == "number") {
|
|
392
|
+
const i = R(t);
|
|
393
|
+
if (isNaN(i))
|
|
394
|
+
throw new Error(`[bwin] Invalid size value: ${i}`);
|
|
395
|
+
return {
|
|
396
|
+
size: t
|
|
397
|
+
};
|
|
398
|
+
} else {
|
|
399
|
+
if (t == null)
|
|
400
|
+
return {};
|
|
401
|
+
throw new Error(`[bwin] Invalid config value: ${t}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
createPrimaryConfigNode({ size: t, position: i, children: n, id: o, minWidth: s, minHeight: r, ...a }) {
|
|
405
|
+
return new M({
|
|
406
|
+
parentRect: this,
|
|
407
|
+
size: t ?? L.size,
|
|
408
|
+
position: i ?? L.position,
|
|
409
|
+
children: n,
|
|
410
|
+
id: o,
|
|
411
|
+
minWidth: s,
|
|
412
|
+
minHeight: r,
|
|
413
|
+
...a
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
createSecondaryConfigNode({ size: t, position: i, children: n, id: o, minWidth: s, minHeight: r, ...a }, l) {
|
|
417
|
+
return new M({
|
|
418
|
+
parentRect: this,
|
|
419
|
+
size: t,
|
|
420
|
+
position: i,
|
|
421
|
+
children: n,
|
|
422
|
+
siblingConfigNode: l,
|
|
423
|
+
id: o,
|
|
424
|
+
minWidth: s,
|
|
425
|
+
minHeight: r,
|
|
426
|
+
...a
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
buildSashTree() {
|
|
430
|
+
const t = this.createSash();
|
|
431
|
+
if (!Array.isArray(this.children) || this.children.length === 0)
|
|
432
|
+
return t;
|
|
433
|
+
const i = this.normConfig(this.children[0]), n = this.normConfig(this.children.at(1));
|
|
434
|
+
let o, s;
|
|
435
|
+
return !i.size && !i.position && n ? (n.position || (n.position = h.Right), o = this.createPrimaryConfigNode(n), s = this.createSecondaryConfigNode(
|
|
436
|
+
i,
|
|
437
|
+
o
|
|
438
|
+
)) : (o = this.createPrimaryConfigNode(i), s = this.createSecondaryConfigNode(
|
|
439
|
+
n,
|
|
440
|
+
o
|
|
441
|
+
)), o && s && (t.children.push(o.buildSashTree()), t.children.push(s.buildSashTree())), t;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const A = {
|
|
445
|
+
width: 333,
|
|
446
|
+
height: 333
|
|
447
|
+
}, D = {
|
|
448
|
+
fitContainer: !1
|
|
449
|
+
};
|
|
450
|
+
class nt extends M {
|
|
451
|
+
constructor({
|
|
452
|
+
id: t,
|
|
453
|
+
children: i,
|
|
454
|
+
width: n = A.width,
|
|
455
|
+
height: o = A.height,
|
|
456
|
+
fitContainer: s = D.fitContainer,
|
|
457
|
+
...r
|
|
458
|
+
} = {
|
|
459
|
+
...A,
|
|
460
|
+
...D
|
|
461
|
+
}) {
|
|
462
|
+
super({
|
|
463
|
+
id: t,
|
|
464
|
+
children: i,
|
|
465
|
+
size: NaN,
|
|
466
|
+
position: h.Root,
|
|
467
|
+
parentRect: { width: n, height: o },
|
|
468
|
+
...r
|
|
469
|
+
}), this.fitContainer = s;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
class st extends m {
|
|
473
|
+
constructor(t = y) {
|
|
474
|
+
super({ ...t, position: h.Root }), Object.assign(this, D);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const ot = {
|
|
478
|
+
createPane(e) {
|
|
479
|
+
const t = S(e);
|
|
480
|
+
return e.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
|
|
481
|
+
},
|
|
482
|
+
// Intended to be overridden
|
|
483
|
+
onPaneCreate(e, t) {
|
|
484
|
+
t.store.content && e.append(C(t.store.content)), this != null && this.debug && (e.style.backgroundColor = X(), e.innerHTML = "", e.append(T(e)));
|
|
485
|
+
},
|
|
486
|
+
updatePane(e) {
|
|
487
|
+
return ht(e);
|
|
488
|
+
},
|
|
489
|
+
// Intended to be overridden
|
|
490
|
+
onPaneUpdate(e, t) {
|
|
491
|
+
this != null && this.debug && (e.innerHTML = "", e.append(T(e)));
|
|
492
|
+
},
|
|
493
|
+
/**
|
|
494
|
+
* Add a pane into the target pane. The two panes become next to each other
|
|
495
|
+
*
|
|
496
|
+
* @param {string} targetPaneSashId - The Sash ID of the target pane that the new pane moves into
|
|
497
|
+
* @param {'top'|'right'|'bottom'|'left'} position - The position of the new pane relative to the target pane
|
|
498
|
+
* @returns {Sash} - The newly created sash
|
|
499
|
+
*/
|
|
500
|
+
addPane(e, t) {
|
|
501
|
+
if (!t) throw new Error("[bwin] Position is required when adding pane");
|
|
502
|
+
const i = this.rootSash.getById(e);
|
|
503
|
+
if (!i) throw new Error("[bwin] Parent sash not found when adding pane");
|
|
504
|
+
const n = ct(i, t);
|
|
505
|
+
return i.id = P(), this.update(), n;
|
|
506
|
+
},
|
|
507
|
+
/**
|
|
508
|
+
* Remove a pane
|
|
509
|
+
*
|
|
510
|
+
* @param {string} sashId - The Sash ID of the pane to be removed
|
|
511
|
+
*/
|
|
512
|
+
removePane(e) {
|
|
513
|
+
const t = this.rootSash.getDescendantParentById(e);
|
|
514
|
+
if (!t) throw new Error("[bwin] Parent sash not found when removing pane");
|
|
515
|
+
const i = t.getChildSiblingById(e);
|
|
516
|
+
t.id = P(), i.children.length === 0 ? (t.domNode = i.domNode, t.domNode.setAttribute("sash-id", t.id), t.children = []) : (t.children = i.children, i.position === h.Left ? i.width = t.width : i.position === h.Right ? (i.width = t.width, i.left = t.left) : i.position === h.Top ? i.height = t.height : i.position === h.Bottom && (i.height = t.height, i.top = t.top)), this.update();
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
function S(e) {
|
|
520
|
+
const t = document.createElement("bw-pane");
|
|
521
|
+
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;
|
|
522
|
+
}
|
|
523
|
+
function ht(e) {
|
|
524
|
+
const t = e.domNode;
|
|
525
|
+
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;
|
|
526
|
+
}
|
|
527
|
+
function rt(e) {
|
|
528
|
+
const t = new m({
|
|
529
|
+
top: e.top,
|
|
530
|
+
left: e.left,
|
|
531
|
+
width: e.width / 2,
|
|
532
|
+
height: e.height,
|
|
533
|
+
position: h.Left
|
|
534
|
+
}), i = new m({
|
|
535
|
+
top: e.top,
|
|
536
|
+
left: e.left + t.width,
|
|
537
|
+
width: e.width / 2,
|
|
538
|
+
height: e.height,
|
|
539
|
+
position: h.Right
|
|
540
|
+
}), n = S(i);
|
|
541
|
+
return i.domNode = n, v(n, e.domNode), e.addChild(t), e.addChild(i), t;
|
|
542
|
+
}
|
|
543
|
+
function at(e) {
|
|
544
|
+
const t = new m({
|
|
545
|
+
top: e.top,
|
|
546
|
+
left: e.left,
|
|
547
|
+
width: e.width / 2,
|
|
548
|
+
height: e.height,
|
|
549
|
+
position: h.Left
|
|
550
|
+
}), i = S(t);
|
|
551
|
+
t.domNode = i, v(i, e.domNode);
|
|
552
|
+
const n = new m({
|
|
553
|
+
top: e.top,
|
|
554
|
+
left: e.left + t.width,
|
|
555
|
+
width: e.width / 2,
|
|
556
|
+
height: e.height,
|
|
557
|
+
position: h.Right
|
|
558
|
+
});
|
|
559
|
+
return e.addChild(t), e.addChild(n), n;
|
|
560
|
+
}
|
|
561
|
+
function lt(e) {
|
|
562
|
+
const t = new m({
|
|
563
|
+
top: e.top,
|
|
564
|
+
left: e.left,
|
|
565
|
+
width: e.width,
|
|
566
|
+
height: e.height / 2,
|
|
567
|
+
position: h.Top
|
|
568
|
+
}), i = new m({
|
|
569
|
+
top: e.top + t.height,
|
|
570
|
+
left: e.left,
|
|
571
|
+
width: e.width,
|
|
572
|
+
height: e.height / 2,
|
|
573
|
+
position: h.Bottom
|
|
574
|
+
}), n = S(i);
|
|
575
|
+
return i.domNode = n, v(n, e.domNode), e.addChild(t), e.addChild(i), t;
|
|
576
|
+
}
|
|
577
|
+
function dt(e) {
|
|
578
|
+
const t = new m({
|
|
579
|
+
top: e.top,
|
|
580
|
+
left: e.left,
|
|
581
|
+
width: e.width,
|
|
582
|
+
height: e.height / 2,
|
|
583
|
+
position: h.Top
|
|
584
|
+
}), i = S(t);
|
|
585
|
+
t.domNode = i, v(i, e.domNode);
|
|
586
|
+
const n = new m({
|
|
587
|
+
top: e.top + t.height,
|
|
588
|
+
left: e.left,
|
|
589
|
+
width: e.width,
|
|
590
|
+
height: e.height / 2,
|
|
591
|
+
position: h.Bottom
|
|
592
|
+
});
|
|
593
|
+
return e.addChild(t), e.addChild(n), n;
|
|
594
|
+
}
|
|
595
|
+
function ct(e, t) {
|
|
596
|
+
if (t === h.Left)
|
|
597
|
+
return rt(e);
|
|
598
|
+
if (t === h.Right)
|
|
599
|
+
return at(e);
|
|
600
|
+
if (t === h.Top)
|
|
601
|
+
return lt(e);
|
|
602
|
+
if (t === h.Bottom)
|
|
603
|
+
return dt(e);
|
|
604
|
+
}
|
|
605
|
+
function T(e) {
|
|
606
|
+
const t = document.createElement("pre");
|
|
607
|
+
t.style.fontSize = "10px";
|
|
608
|
+
const i = `
|
|
609
|
+
id: ${e.getAttribute("sash-id")}
|
|
610
|
+
top: ${e.style.top}
|
|
611
|
+
left: ${e.style.left}
|
|
612
|
+
width: ${e.style.width}
|
|
613
|
+
height: ${e.style.height}
|
|
614
|
+
position: ${e.getAttribute("position")}
|
|
615
|
+
`;
|
|
616
|
+
return t.innerHTML = i.trim(), t;
|
|
617
|
+
}
|
|
618
|
+
const pt = {
|
|
619
|
+
createWindow() {
|
|
620
|
+
const e = document.createElement("bw-window");
|
|
621
|
+
return e.style.width = `${this.rootSash.width}px`, e.style.height = `${this.rootSash.height}px`, e.setAttribute("sash-id", this.rootSash.id), e;
|
|
622
|
+
},
|
|
623
|
+
glaze(e) {
|
|
624
|
+
this.rootSash.walk((t) => {
|
|
625
|
+
let i = null;
|
|
626
|
+
t.children.length > 0 ? (i = this.createMuntin(t), this.onMuntinCreate(i, t), e.append(i)) : (i = this.createPane(t), this.onPaneCreate(i, t), e.prepend(i)), t.domNode = i;
|
|
627
|
+
});
|
|
628
|
+
},
|
|
629
|
+
update() {
|
|
630
|
+
this.windowElement.style.width = `${this.rootSash.width}px`, this.windowElement.style.height = `${this.rootSash.height}px`;
|
|
631
|
+
const e = this.rootSash.getAllIds(), t = [];
|
|
632
|
+
this.windowElement.querySelectorAll("[sash-id]").forEach((i) => {
|
|
633
|
+
const n = i.getAttribute("sash-id");
|
|
634
|
+
t.push(n), e.includes(n) || i.remove();
|
|
635
|
+
}), this.rootSash.walk((i) => {
|
|
636
|
+
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));
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}, ut = {
|
|
640
|
+
muntinSize: 4,
|
|
641
|
+
createMuntin(e) {
|
|
642
|
+
const t = document.createElement("bw-muntin"), i = e.leftChild, n = e.topChild;
|
|
643
|
+
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;
|
|
644
|
+
},
|
|
645
|
+
onMuntinCreate(e, t) {
|
|
646
|
+
},
|
|
647
|
+
updateMuntin(e) {
|
|
648
|
+
const t = e.domNode, i = e.leftChild, n = e.topChild;
|
|
649
|
+
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`);
|
|
650
|
+
},
|
|
651
|
+
onMuntinUpdate(e, t) {
|
|
652
|
+
}
|
|
653
|
+
}, gt = {
|
|
654
|
+
fitContainer: !1,
|
|
655
|
+
enableFitContainer() {
|
|
656
|
+
new ResizeObserver((e) => {
|
|
657
|
+
for (const t of e)
|
|
658
|
+
t.target === this.containerElement && this.fitContainer && (this.rootSash.width = t.contentRect.width, this.rootSash.height = t.contentRect.height, this.update());
|
|
659
|
+
}).observe(this.containerElement);
|
|
660
|
+
}
|
|
661
|
+
}, ft = {
|
|
662
|
+
activeMuntinSash: null,
|
|
663
|
+
isResizeStarted: !1,
|
|
664
|
+
isDropStarted: !1,
|
|
665
|
+
lastX: 0,
|
|
666
|
+
lastY: 0,
|
|
667
|
+
applyResizeStyles() {
|
|
668
|
+
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");
|
|
669
|
+
},
|
|
670
|
+
revertResizeStyles() {
|
|
671
|
+
document.body.classList.remove("body--bw-resize-x"), document.body.classList.remove("body--bw-resize-y");
|
|
672
|
+
},
|
|
673
|
+
enableResize() {
|
|
674
|
+
document.addEventListener("mousedown", (e) => {
|
|
675
|
+
if (e.target.tagName !== "BW-MUNTIN" || e.target.getAttribute("resizable") === "false") return;
|
|
676
|
+
const t = e.target.getAttribute("sash-id");
|
|
677
|
+
this.activeMuntinSash = this.rootSash.getById(t), this.activeMuntinSash && (this.isResizeStarted = !0, this.lastX = e.pageX, this.lastY = e.pageY, this.applyResizeStyles());
|
|
678
|
+
}), document.addEventListener("mousemove", (e) => {
|
|
679
|
+
if (!this.isResizeStarted || !this.activeMuntinSash) return;
|
|
680
|
+
const [t, i, n, o] = this.activeMuntinSash.getChildren(), s = this.activeMuntinSash.isLeftRightSplit(), r = this.activeMuntinSash.isTopBottomSplit();
|
|
681
|
+
if (s && o && i) {
|
|
682
|
+
const a = e.pageX - this.lastX, l = o.width + a, c = i.width - a;
|
|
683
|
+
if (l <= o.calcMinWidth() || c <= i.calcMinWidth())
|
|
684
|
+
return;
|
|
685
|
+
o.width = l, i.width = c, i.left = i.left + a, this.update(), this.lastX = e.pageX;
|
|
686
|
+
} else if (r && t && n) {
|
|
687
|
+
const a = e.pageY - this.lastY, l = t.height + a, c = n.height - a;
|
|
688
|
+
if (l <= t.calcMinHeight() || c <= n.calcMinHeight())
|
|
689
|
+
return;
|
|
690
|
+
t.height = l, n.height = c, n.top = n.top + a, this.update(), this.lastY = e.pageY;
|
|
691
|
+
}
|
|
692
|
+
}), document.addEventListener("mouseup", () => {
|
|
693
|
+
this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}, wt = {
|
|
697
|
+
activeDropPaneEl: null,
|
|
698
|
+
// Intended to be overridden in `BinaryWindow` class
|
|
699
|
+
onPaneDrop(e, t) {
|
|
700
|
+
},
|
|
701
|
+
enableDrop() {
|
|
702
|
+
this.windowElement.addEventListener("dragover", (e) => {
|
|
703
|
+
e.preventDefault();
|
|
704
|
+
const t = e.target.matches("bw-pane") ? e.target : e.target.closest("bw-pane");
|
|
705
|
+
if (!t || (t !== this.activeDropPaneEl && (this.activeDropPaneEl && this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = t), t.getAttribute("can-drop") === "false")) return;
|
|
706
|
+
const i = it(t, e);
|
|
707
|
+
t.setAttribute("drop-area", i);
|
|
708
|
+
}), this.windowElement.addEventListener("dragleave", (e) => {
|
|
709
|
+
e.currentTarget.contains(e.relatedTarget) && e.currentTarget !== e.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
|
|
710
|
+
}), this.windowElement.addEventListener("drop", (e) => {
|
|
711
|
+
if (!this.activeDropPaneEl || this.activeDropPaneEl.getAttribute("can-drop") === "false") return;
|
|
712
|
+
const t = this.activeDropPaneEl.getAttribute("sash-id"), i = this.rootSash.getById(t);
|
|
713
|
+
this.onPaneDrop(e, i), typeof i.store.onDrop == "function" && i.store.onDrop(e, i), this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null;
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
class B {
|
|
718
|
+
constructor(t) {
|
|
719
|
+
E(this, "windowElement", null), E(this, "containerElement", null), E(this, "debug", !1);
|
|
720
|
+
let i = null;
|
|
721
|
+
t instanceof st ? (i = t, this.rootSash = t) : (i = new nt(t), this.rootSash = i.buildSashTree()), this.fitContainer = i.fitContainer;
|
|
722
|
+
}
|
|
723
|
+
// Features can work independently to each other
|
|
724
|
+
enableFeatures() {
|
|
725
|
+
this.enableResize(), this.enableDrop(), this.fitContainer && this.enableFitContainer();
|
|
726
|
+
}
|
|
727
|
+
mount(t) {
|
|
728
|
+
const i = this.createWindow();
|
|
729
|
+
this.glaze(i), this.containerElement = t, this.containerElement.append(i), this.windowElement = i, this.enableFeatures();
|
|
730
|
+
}
|
|
731
|
+
static assemble(...t) {
|
|
732
|
+
t.forEach((i) => {
|
|
733
|
+
K(this.prototype, i);
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
B.assemble(
|
|
738
|
+
pt,
|
|
739
|
+
ut,
|
|
740
|
+
ot,
|
|
741
|
+
gt,
|
|
742
|
+
wt,
|
|
743
|
+
ft
|
|
744
|
+
);
|
|
745
|
+
function H(e) {
|
|
746
|
+
if (e.tagName === "BW-PANE")
|
|
747
|
+
return e.getAttribute("sash-id");
|
|
748
|
+
const t = e.closest("bw-pane");
|
|
749
|
+
if (!t)
|
|
750
|
+
throw new Error("[bwin] Pane element not found");
|
|
751
|
+
return t.getAttribute("sash-id");
|
|
752
|
+
}
|
|
753
|
+
const I = "bw-glass-action--close", G = [
|
|
754
|
+
{
|
|
755
|
+
label: "",
|
|
756
|
+
className: I,
|
|
757
|
+
onClick: (e, t) => {
|
|
758
|
+
const i = H(e.target);
|
|
759
|
+
t.removePane(i);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
], N = {
|
|
763
|
+
title: null,
|
|
764
|
+
content: null,
|
|
765
|
+
tabs: [],
|
|
766
|
+
actions: void 0,
|
|
767
|
+
draggable: !0
|
|
768
|
+
};
|
|
769
|
+
class W {
|
|
770
|
+
constructor({
|
|
771
|
+
title: t = N.title,
|
|
772
|
+
content: i = N.content,
|
|
773
|
+
tabs: n = N.tabs,
|
|
774
|
+
actions: o = N.actions,
|
|
775
|
+
draggable: s = N.draggable,
|
|
776
|
+
sash: r,
|
|
777
|
+
binaryWindow: a
|
|
778
|
+
}) {
|
|
779
|
+
E(this, "domNode"), this.title = t, this.content = i, this.tabs = n, this.actions = o, this.sash = r, this.draggable = s, this.binaryWindow = a, this.build();
|
|
780
|
+
}
|
|
781
|
+
build() {
|
|
782
|
+
const t = document.createElement("bw-glass-header");
|
|
783
|
+
if (Array.isArray(this.tabs) && this.tabs.length > 0)
|
|
784
|
+
t.append(this.createTabs());
|
|
785
|
+
else if (this.title) {
|
|
786
|
+
const o = document.createElement("bw-glass-title");
|
|
787
|
+
o.append(C(this.title)), t.append(o);
|
|
788
|
+
}
|
|
789
|
+
t.setAttribute("can-drag", this.draggable), t.append(this.createActions());
|
|
790
|
+
const i = document.createElement("bw-glass-content"), n = C(this.content);
|
|
791
|
+
n && i.append(n), this.domNode = document.createElement("bw-glass"), this.domNode.append(t, i);
|
|
792
|
+
}
|
|
793
|
+
createTabs() {
|
|
794
|
+
const t = document.createElement("bw-glass-tab-container");
|
|
795
|
+
for (const i of this.tabs) {
|
|
796
|
+
const n = (i == null ? void 0 : i.label) ?? i, o = C(`<button class="bw-glass-tab">${n}</button>`);
|
|
797
|
+
t.append(o);
|
|
798
|
+
}
|
|
799
|
+
return t;
|
|
800
|
+
}
|
|
801
|
+
createActions() {
|
|
802
|
+
const t = document.createElement("bw-glass-action-container"), i = this.actions === void 0 ? G : Array.isArray(this.actions) ? this.actions : [];
|
|
803
|
+
for (const n of i) {
|
|
804
|
+
const o = (n == null ? void 0 : n.label) ?? n, s = n.className ? `bw-glass-action ${n.className}` : "bw-glass-action", r = C(`<button class="${s}">${o}</button>`);
|
|
805
|
+
typeof n.onClick == "function" && r.addEventListener("click", (a) => {
|
|
806
|
+
n.onClick(a, this.binaryWindow);
|
|
807
|
+
}), t.append(r);
|
|
808
|
+
}
|
|
809
|
+
return t;
|
|
810
|
+
}
|
|
811
|
+
get contentElement() {
|
|
812
|
+
return this.domNode.querySelector("bw-glass-content");
|
|
813
|
+
}
|
|
814
|
+
get headerElement() {
|
|
815
|
+
return this.domNode.querySelector("bw-glass-header");
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
const mt = {
|
|
819
|
+
enableObservers() {
|
|
820
|
+
this.observeCloseButtons();
|
|
821
|
+
},
|
|
822
|
+
observeCloseButtons() {
|
|
823
|
+
const e = `.${I}`;
|
|
824
|
+
new MutationObserver((t) => {
|
|
825
|
+
t.forEach((i) => {
|
|
826
|
+
if (i.type === "childList")
|
|
827
|
+
if (this.windowElement.querySelectorAll("bw-pane").length === 1) {
|
|
828
|
+
const n = this.windowElement.querySelector(e);
|
|
829
|
+
n && n.setAttribute("disabled", "");
|
|
830
|
+
} else
|
|
831
|
+
this.windowElement.querySelectorAll(e).forEach((n) => {
|
|
832
|
+
n.removeAttribute("disabled");
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
}).observe(this.windowElement, {
|
|
836
|
+
childList: !0
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
}, bt = {
|
|
840
|
+
activeDragGlassEl: null,
|
|
841
|
+
activeDragGlassPaneCanDrop: !1,
|
|
842
|
+
onPaneDrop(e, t) {
|
|
843
|
+
if (!this.activeDragGlassEl) return;
|
|
844
|
+
const i = this.activeDropPaneEl.getAttribute("drop-area");
|
|
845
|
+
if (i === "center") {
|
|
846
|
+
const n = this.activeDragGlassEl.closest("bw-pane"), o = this.activeDropPaneEl.getAttribute("can-drop") !== "false";
|
|
847
|
+
Y(n, this.activeDropPaneEl), n.setAttribute("can-drop", o);
|
|
848
|
+
return;
|
|
849
|
+
} else {
|
|
850
|
+
const n = H(this.activeDragGlassEl);
|
|
851
|
+
this.addPane(t.id, i).domNode.append(this.activeDragGlassEl), this.removePane(n);
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
enableDrag() {
|
|
855
|
+
document.addEventListener("mousedown", (e) => {
|
|
856
|
+
if (e.button !== 0 || !e.target.matches("bw-glass-header")) return;
|
|
857
|
+
if (e.target.getAttribute("can-drag") === "false") {
|
|
858
|
+
e.preventDefault();
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const t = e.target.closest("bw-glass");
|
|
862
|
+
t.setAttribute("draggable", !0), this.activeDragGlassEl = t;
|
|
863
|
+
}), document.addEventListener("mouseup", () => {
|
|
864
|
+
this.activeDragGlassEl && (this.activeDragGlassEl.removeAttribute("draggable"), this.activeDragGlassEl = null);
|
|
865
|
+
}), this.windowElement.addEventListener("dragstart", (e) => {
|
|
866
|
+
if (!(e.target instanceof HTMLElement) || !e.target.matches("bw-glass") || !this.activeDragGlassEl)
|
|
867
|
+
return;
|
|
868
|
+
e.dataTransfer.effectAllowed = "move";
|
|
869
|
+
const t = this.activeDragGlassEl.closest("bw-pane");
|
|
870
|
+
this.activeDragGlassPaneCanDrop = t.getAttribute("can-drop") !== "false", t.setAttribute("can-drop", !1);
|
|
871
|
+
}), this.windowElement.addEventListener("dragend", () => {
|
|
872
|
+
this.activeDragGlassEl && (this.activeDragGlassEl.removeAttribute("draggable"), this.activeDragGlassEl.closest("bw-pane").setAttribute("can-drop", this.activeDragGlassPaneCanDrop), this.activeDragGlassEl = null);
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
}, yt = {
|
|
876
|
+
trimMuntin(e) {
|
|
877
|
+
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`);
|
|
878
|
+
},
|
|
879
|
+
onMuntinCreate(e) {
|
|
880
|
+
this.trimMuntin(e);
|
|
881
|
+
},
|
|
882
|
+
onMuntinUpdate(e) {
|
|
883
|
+
this.trimMuntin(e);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
class k extends B {
|
|
887
|
+
enableFeatures() {
|
|
888
|
+
super.enableFeatures(), this.enableObservers(), this.enableDrag();
|
|
889
|
+
}
|
|
890
|
+
onPaneCreate(t, i) {
|
|
891
|
+
const n = new W({ ...i.store, sash: i, binaryWindow: this });
|
|
892
|
+
t.innerHTML = "", t.append(n.domNode), this.debug && n.contentElement.prepend(`${i.id}`);
|
|
893
|
+
}
|
|
894
|
+
onPaneUpdate() {
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Add glass into the target pane.
|
|
898
|
+
*
|
|
899
|
+
* @param {string} paneSashId - The Sash ID of the pane that the glass moves into
|
|
900
|
+
* @param {'top'|'right'|'bottom'|'left'} position - The position of the glass relative to the target pane
|
|
901
|
+
* @param {Object} glassProps - The glass properties
|
|
902
|
+
*
|
|
903
|
+
*/
|
|
904
|
+
addGlass(t, i, n) {
|
|
905
|
+
const o = this.addPane(t, i), s = new W({ ...n, sash: o, binaryWindow: this });
|
|
906
|
+
o.domNode.append(s.domNode);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Remove glass from or together with the pane
|
|
910
|
+
*
|
|
911
|
+
* @param {string} paneSashId - The Sash ID of the pane that contains the glass
|
|
912
|
+
* @param {boolean} removePane - Whether to remove the pane together
|
|
913
|
+
*/
|
|
914
|
+
removeGlass(t, i) {
|
|
915
|
+
if (i)
|
|
916
|
+
this.removePane(t);
|
|
917
|
+
else {
|
|
918
|
+
const n = this.rootSash.getById(t);
|
|
919
|
+
if (!n) throw new Error("[bwin] Pane not found when removing glass");
|
|
920
|
+
const o = n.domNode.querySelector("bw-glass");
|
|
921
|
+
o && o.remove();
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
k.assemble(mt, bt, yt);
|
|
926
|
+
const b = 4;
|
|
927
|
+
function Et({ sash: e }) {
|
|
928
|
+
var d;
|
|
929
|
+
const t = x(), i = e.leftChild, n = e.topChild;
|
|
930
|
+
let o, s, r, a, l, c;
|
|
931
|
+
return i ? (o = b, s = e.height - b, r = e.top + b / 2, a = e.left + i.width - b / 2, l = !0) : n && (o = e.width - b, s = b, r = e.top + n.height - b / 2, a = e.left + b / 2, c = !0), $(() => {
|
|
932
|
+
e.domNode = t.current;
|
|
933
|
+
}, []), /* @__PURE__ */ g.createElement(
|
|
934
|
+
"bw-muntin",
|
|
935
|
+
{
|
|
936
|
+
"sash-id": e.id,
|
|
937
|
+
style: {
|
|
938
|
+
width: o,
|
|
939
|
+
height: s,
|
|
940
|
+
top: r,
|
|
941
|
+
left: a
|
|
942
|
+
},
|
|
943
|
+
vertical: l,
|
|
944
|
+
horizontal: c,
|
|
945
|
+
resizable: ((d = e.store) == null ? void 0 : d.resizable) === !1 ? "false" : "true",
|
|
946
|
+
ref: t
|
|
947
|
+
}
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
function vt({
|
|
951
|
+
sash: e,
|
|
952
|
+
bwin: t
|
|
953
|
+
}) {
|
|
954
|
+
var d, p, u, f, w;
|
|
955
|
+
const i = x(), { left: n, top: o, width: s, height: r, id: a, position: l } = e;
|
|
956
|
+
$(() => {
|
|
957
|
+
e.domNode = i.current;
|
|
958
|
+
}, []);
|
|
959
|
+
const c = ((d = e.store) == null ? void 0 : d.actions) === void 0 ? G : Array.isArray(e.store.actions) ? e.store.actions : [];
|
|
960
|
+
return /* @__PURE__ */ g.createElement(
|
|
961
|
+
"bw-pane",
|
|
962
|
+
{
|
|
963
|
+
"sash-id": a,
|
|
964
|
+
position: l,
|
|
965
|
+
style: { left: n, top: o, width: s, height: r },
|
|
966
|
+
"can-drop": ((p = e.store) == null ? void 0 : p.droppable) === !1 ? "false" : "true",
|
|
967
|
+
ref: i
|
|
968
|
+
},
|
|
969
|
+
/* @__PURE__ */ g.createElement("bw-glass", null, /* @__PURE__ */ g.createElement(
|
|
970
|
+
"bw-glass-header",
|
|
971
|
+
{
|
|
972
|
+
"can-drag": ((u = e.store) == null ? void 0 : u.draggable) === !1 ? "false" : "true"
|
|
973
|
+
},
|
|
974
|
+
((f = e.store) == null ? void 0 : f.title) && /* @__PURE__ */ g.createElement("bw-glass-title", null, e.store.title),
|
|
975
|
+
c.length > 0 && /* @__PURE__ */ g.createElement("bw-glass-action-container", null, c.map((z, _) => {
|
|
976
|
+
const O = z.className ? `bw-glass-action ${z.className}` : "bw-glass-action";
|
|
977
|
+
return /* @__PURE__ */ g.createElement(
|
|
978
|
+
"button",
|
|
979
|
+
{
|
|
980
|
+
className: O,
|
|
981
|
+
key: _,
|
|
982
|
+
onClick: (q) => z.onClick(q, t)
|
|
983
|
+
},
|
|
984
|
+
z.label
|
|
985
|
+
);
|
|
986
|
+
}))
|
|
987
|
+
), /* @__PURE__ */ g.createElement("bw-glass-content", null, (w = e.store) == null ? void 0 : w.content))
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
function Ct(e) {
|
|
991
|
+
const t = x(), i = new k(e), n = [], o = [];
|
|
992
|
+
return i.rootSash.walk((s) => {
|
|
993
|
+
s.children.length > 0 ? n.push(s) : o.push(s);
|
|
994
|
+
}), $(() => {
|
|
995
|
+
const s = t.current;
|
|
996
|
+
s != null && s.parentElement && (i.windowElement = s, i.containerElement = s.parentElement, i.enableFeatures());
|
|
997
|
+
}, []), /* @__PURE__ */ g.createElement(
|
|
998
|
+
"bw-window",
|
|
999
|
+
{
|
|
1000
|
+
"sash-id": i.rootSash.id,
|
|
1001
|
+
style: { width: i.rootSash.width, height: i.rootSash.height },
|
|
1002
|
+
ref: t
|
|
1003
|
+
},
|
|
1004
|
+
o.map((s) => /* @__PURE__ */ g.createElement(vt, { key: s.id, sash: s, bwin: i })),
|
|
1005
|
+
n.map((s) => /* @__PURE__ */ g.createElement(Et, { key: s.id, sash: s }))
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
export {
|
|
1009
|
+
G as BUILTIN_ACTIONS,
|
|
1010
|
+
Ct as Window
|
|
1011
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
(function(b,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],u):(b=typeof globalThis<"u"?globalThis:b||self,u(b.ReactBinaryWindow={},b.React))})(this,function(b,u){"use strict";var k=Object.defineProperty,O=(e,t,i)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,y=(e,t,i)=>O(e,typeof t!="symbol"?t+"":t,i);function _(e=.7,t=128){const i=256-t,n=Math.floor(Math.random()*i+t),o=Math.floor(Math.random()*i+t),s=Math.floor(Math.random()*i+t),r=Math.max(.5,Math.random()*e);return`rgba(${n}, ${o}, ${s}, ${r})`}function P(e=2,t=3){if(e<0||t<0)throw new Error("Parameters must be non-negative numbers");const i="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789";let o="";for(let s=0;s<e;s++){const r=Math.floor(Math.random()*i.length);o+=i[r]}o+="-";for(let s=0;s<t;s++){const r=Math.floor(Math.random()*n.length);o+=n[r]}return o}function N(e,t){for(;t.firstChild;)e.append(t.firstChild)}function q(e,t){const i=document.createElement("div");N(i,e),N(e,t),N(t,i)}function R(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 F(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function U(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 j(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content}function C(e){if(e==null||e==="")return null;if(typeof e=="string")try{const t=j(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}const h={Top:"top",Right:"right",Bottom:"bottom",Left:"left",Center:"center",Root:"root",Unknown:"unknown",Outside:"outside"};function X(e){switch(e){case h.Top:return h.Bottom;case h.Right:return h.Left;case h.Bottom:return h.Top;case h.Left:return h.Right;default:throw new Error(`[bwin] Invalid position: ${e}`)}}function Y({width:e,height:t,x:i}){return t/e*i}function K({width:e,height:t,y:i}){return e/t*i}function V({width:e,height:t,x:i}){return t-t/e*i}function Z({width:e,height:t,y:i}){return e-e/t*i}function J(e,{clientX:t,clientY:i}){const n=e.getBoundingClientRect(),{width:o,height:s}=n,r=t-n.left,a=i-n.top;if(r<0||r>o||a<0||a>s)return h.Outside;const l=.3,c=Y({width:o,height:s,x:r}),d=V({width:o,height:s,x:r}),p=K({width:o,height:s,y:a}),g=Z({width:o,height:s,y:a});return r<o*(.5-l/2)&&a>c&&a<d?h.Left:r>o*(.5+l/2)&&a<c&&a>d?h.Right:a<s*(.5-l/2)&&r>p&&r<g?h.Top:a>s*(.5+l/2)&&r<p&&r>g?h.Bottom:r>o*(.5-l/2)&&r<o*(.5+l/2)&&a>s*(.5-l/2)&&a<s*(.5+l/2)?h.Center:h.Unknown}const E={top:0,left:0,width:100,height:100,minWidth:50,minHeight:50};class f{constructor({top:t=E.top,left:i=E.left,width:n=E.width,height:o=E.height,minWidth:s=E.minWidth,minHeight:r=E.minHeight,domNode:a=null,store:l={},position:c,id:d}=E){if(this.id=d??P(),!c)throw new Error("[bwin] Sash position is required");this.position=c,this.domNode=a,this._top=t,this._left=i,this._width=n,this._height=o,this.children=[],this.minWidth=s,this.minHeight=r,this.store=l}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===h.Left||t.position===h.Right)}isTopBottomSplit(){return this.children.some(t=>t.position===h.Top||t.position===h.Bottom)}get leftChild(){return this.children.find(t=>t.position===h.Left)}get rightChild(){return this.children.find(t=>t.position===h.Right)}get topChild(){return this.children.find(t=>t.position===h.Top)}get bottomChild(){return this.children.find(t=>t.position===h.Bottom)}getChildren(){let t=null,i=null,n=null,o=null;for(const s of this.children)s.position===h.Left?t=s:s.position===h.Right?i=s:s.position===h.Top?n=s:s.position===h.Bottom&&(o=s);return[n,i,o,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,o]=this.getChildren();if(o&&i){const s=o.calcMinWidth()+i.calcMinWidth();return Math.max(this.minWidth,s)}if(t&&n){const s=Math.max(t.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,s)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;const[t,i,n,o]=this.getChildren();if(o&&i){const s=Math.max(o.calcMinHeight(),i.calcMinHeight());return Math.max(this.minHeight,s)}if(t&&n){const s=t.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,s)}}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,o,s,r]=this.getChildren();n&&s&&(n.top+=i,s.top+=i),r&&o&&(r.top+=i,o.top+=i)}get left(){return this._left}set left(t){const i=t-this._left;this._left=t;const[n,o,s,r]=this.getChildren();r&&o&&(r.left+=i,o.left+=i),n&&s&&(n.left+=i,s.left+=i)}get width(){return this._width}set width(t){const i=t-this._width;this._width=t;const[n,o,s,r]=this.getChildren();if(r&&o){const a=r.width+o.width,l=i*(r.width/a),c=a+i;let d=r.width+l,p=c-d,g=o.left+l;const w=r.calcMinWidth(),m=o.calcMinWidth();d<w&&p>m?(d=w,p=c-d,g=r.left+d):p<m&&d>w&&(p=m,d=c-p,g=r.left+d),r.width=d,o.width=p,o.left=g}n&&s&&(n.width+=i,s.width+=i)}get height(){return this._height}set height(t){const i=t-this._height;this._height=t;const[n,o,s,r]=this.getChildren();if(n&&s){const a=n.height+s.height,l=i*(n.height/a),c=a+i;let d=n.height+l,p=c-d,g=s.top+l;const w=n.calcMinHeight(),m=s.calcMinHeight();d<w&&p>m?(d=w,p=c-d,g=n.top+d):p<m&&d>w&&(p=m,d=c-p,g=n.top+d),n.height=d,s.height=p,s.top=g}r&&o&&(r.height+=i,o.height+=i)}}const L={size:"50%",position:h.Left};class M{constructor({parentRect:t,children:i,siblingConfigNode:n,id:o,minWidth:s,minHeight:r,position:a,size:l,...c}){y(this,"left"),y(this,"top"),y(this,"width"),y(this,"height"),this.parentRect=t,this.children=i,this.siblingConfigNode=n,this.id=o,this.minWidth=s,this.minHeight=r,this.position=this.getPosition(a),this.size=this.getSize(l),this.nonCoreData=c,this.setBounds()}getPosition(t){if(!this.siblingConfigNode)return t;const i=X(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 R(t);if(!t){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===h.Left||this.siblingConfigNode.position===h.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===h.Top||this.siblingConfigNode.position===h.Bottom)return this.parentRect.height-this.siblingConfigNode.height}const i=R(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===h.Left||this.position===h.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===h.Top||this.position===h.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===h.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===h.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===h.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===h.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===h.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 f({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(F(t))return t;if(Array.isArray(t))return{children:t};if(typeof t=="string"||typeof t=="number"){const i=R(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:o,minWidth:s,minHeight:r,...a}){return new M({parentRect:this,size:t??L.size,position:i??L.position,children:n,id:o,minWidth:s,minHeight:r,...a})}createSecondaryConfigNode({size:t,position:i,children:n,id:o,minWidth:s,minHeight:r,...a},l){return new M({parentRect:this,size:t,position:i,children:n,siblingConfigNode:l,id:o,minWidth:s,minHeight:r,...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 o,s;return!i.size&&!i.position&&n?(n.position||(n.position=h.Right),o=this.createPrimaryConfigNode(n),s=this.createSecondaryConfigNode(i,o)):(o=this.createPrimaryConfigNode(i),s=this.createSecondaryConfigNode(n,o)),o&&s&&(t.children.push(o.buildSashTree()),t.children.push(s.buildSashTree())),t}}const D={width:333,height:333},x={fitContainer:!1};class Q extends M{constructor({id:t,children:i,width:n=D.width,height:o=D.height,fitContainer:s=x.fitContainer,...r}={...D,...x}){super({id:t,children:i,size:NaN,position:h.Root,parentRect:{width:n,height:o},...r}),this.fitContainer=s}}class tt extends f{constructor(t=E){super({...t,position:h.Root}),Object.assign(this,x)}}const et={createPane(e){const t=S(e);return e.store.droppable===!1&&t.setAttribute("can-drop","false"),t},onPaneCreate(e,t){t.store.content&&e.append(C(t.store.content)),this!=null&&this.debug&&(e.style.backgroundColor=_(),e.innerHTML="",e.append(T(e)))},updatePane(e){return it(e)},onPaneUpdate(e,t){this!=null&&this.debug&&(e.innerHTML="",e.append(T(e)))},addPane(e,t){if(!t)throw new Error("[bwin] Position is required when adding pane");const i=this.rootSash.getById(e);if(!i)throw new Error("[bwin] Parent sash not found when adding pane");const n=rt(i,t);return i.id=P(),this.update(),n},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=P(),i.children.length===0?(t.domNode=i.domNode,t.domNode.setAttribute("sash-id",t.id),t.children=[]):(t.children=i.children,i.position===h.Left?i.width=t.width:i.position===h.Right?(i.width=t.width,i.left=t.left):i.position===h.Top?i.height=t.height:i.position===h.Bottom&&(i.height=t.height,i.top=t.top)),this.update()}};function S(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 it(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 nt(e){const t=new f({top:e.top,left:e.left,width:e.width/2,height:e.height,position:h.Left}),i=new f({top:e.top,left:e.left+t.width,width:e.width/2,height:e.height,position:h.Right}),n=S(i);return i.domNode=n,N(n,e.domNode),e.addChild(t),e.addChild(i),t}function st(e){const t=new f({top:e.top,left:e.left,width:e.width/2,height:e.height,position:h.Left}),i=S(t);t.domNode=i,N(i,e.domNode);const n=new f({top:e.top,left:e.left+t.width,width:e.width/2,height:e.height,position:h.Right});return e.addChild(t),e.addChild(n),n}function ot(e){const t=new f({top:e.top,left:e.left,width:e.width,height:e.height/2,position:h.Top}),i=new f({top:e.top+t.height,left:e.left,width:e.width,height:e.height/2,position:h.Bottom}),n=S(i);return i.domNode=n,N(n,e.domNode),e.addChild(t),e.addChild(i),t}function ht(e){const t=new f({top:e.top,left:e.left,width:e.width,height:e.height/2,position:h.Top}),i=S(t);t.domNode=i,N(i,e.domNode);const n=new f({top:e.top+t.height,left:e.left,width:e.width,height:e.height/2,position:h.Bottom});return e.addChild(t),e.addChild(n),n}function rt(e,t){if(t===h.Left)return nt(e);if(t===h.Right)return st(e);if(t===h.Top)return ot(e);if(t===h.Bottom)return ht(e)}function T(e){const t=document.createElement("pre");t.style.fontSize="10px";const i=`
|
|
2
|
+
id: ${e.getAttribute("sash-id")}
|
|
3
|
+
top: ${e.style.top}
|
|
4
|
+
left: ${e.style.left}
|
|
5
|
+
width: ${e.style.width}
|
|
6
|
+
height: ${e.style.height}
|
|
7
|
+
position: ${e.getAttribute("position")}
|
|
8
|
+
`;return t.innerHTML=i.trim(),t}const at={createWindow(){const e=document.createElement("bw-window");return e.style.width=`${this.rootSash.width}px`,e.style.height=`${this.rootSash.height}px`,e.setAttribute("sash-id",this.rootSash.id),e},glaze(e){this.rootSash.walk(t=>{let i=null;t.children.length>0?(i=this.createMuntin(t),this.onMuntinCreate(i,t),e.append(i)):(i=this.createPane(t),this.onPaneCreate(i,t),e.prepend(i)),t.domNode=i})},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))})}},lt={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){}},dt={fitContainer:!1,enableFitContainer(){new ResizeObserver(e=>{for(const t of e)t.target===this.containerElement&&this.fitContainer&&(this.rootSash.width=t.contentRect.width,this.rootSash.height=t.contentRect.height,this.update())}).observe(this.containerElement)}},ct={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,o]=this.activeMuntinSash.getChildren(),s=this.activeMuntinSash.isLeftRightSplit(),r=this.activeMuntinSash.isTopBottomSplit();if(s&&o&&i){const a=e.pageX-this.lastX,l=o.width+a,c=i.width-a;if(l<=o.calcMinWidth()||c<=i.calcMinWidth())return;o.width=l,i.width=c,i.left=i.left+a,this.update(),this.lastX=e.pageX}else if(r&&t&&n){const a=e.pageY-this.lastY,l=t.height+a,c=n.height-a;if(l<=t.calcMinHeight()||c<=n.calcMinHeight())return;t.height=l,n.height=c,n.top=n.top+a,this.update(),this.lastY=e.pageY}}),document.addEventListener("mouseup",()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},ut={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=J(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})}};class W{constructor(t){y(this,"windowElement",null),y(this,"containerElement",null),y(this,"debug",!1);let i=null;t instanceof tt?(i=t,this.rootSash=t):(i=new Q(t),this.rootSash=i.buildSashTree()),this.fitContainer=i.fitContainer}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(t){const i=this.createWindow();this.glaze(i),this.containerElement=t,this.containerElement.append(i),this.windowElement=i,this.enableFeatures()}static assemble(...t){t.forEach(i=>{U(this.prototype,i)})}}W.assemble(at,lt,et,dt,ut,ct);function B(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 H="bw-glass-action--close",$=[{label:"",className:H,onClick:(e,t)=>{const i=B(e.target);t.removePane(i)}}],z={title:null,content:null,tabs:[],actions:void 0,draggable:!0};class I{constructor({title:t=z.title,content:i=z.content,tabs:n=z.tabs,actions:o=z.actions,draggable:s=z.draggable,sash:r,binaryWindow:a}){y(this,"domNode"),this.title=t,this.content=i,this.tabs=n,this.actions=o,this.sash=r,this.draggable=s,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 o=document.createElement("bw-glass-title");o.append(C(this.title)),t.append(o)}t.setAttribute("can-drag",this.draggable),t.append(this.createActions());const i=document.createElement("bw-glass-content"),n=C(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,o=C(`<button class="bw-glass-tab">${n}</button>`);t.append(o)}return t}createActions(){const t=document.createElement("bw-glass-action-container"),i=this.actions===void 0?$:Array.isArray(this.actions)?this.actions:[];for(const n of i){const o=(n==null?void 0:n.label)??n,s=n.className?`bw-glass-action ${n.className}`:"bw-glass-action",r=C(`<button class="${s}">${o}</button>`);typeof n.onClick=="function"&&r.addEventListener("click",a=>{n.onClick(a,this.binaryWindow)}),t.append(r)}return t}get contentElement(){return this.domNode.querySelector("bw-glass-content")}get headerElement(){return this.domNode.querySelector("bw-glass-header")}}const pt={enableObservers(){this.observeCloseButtons()},observeCloseButtons(){const e=`.${H}`;new MutationObserver(t=>{t.forEach(i=>{if(i.type==="childList")if(this.windowElement.querySelectorAll("bw-pane").length===1){const n=this.windowElement.querySelector(e);n&&n.setAttribute("disabled","")}else this.windowElement.querySelectorAll(e).forEach(n=>{n.removeAttribute("disabled")})})}).observe(this.windowElement,{childList:!0})}},gt={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"),o=this.activeDropPaneEl.getAttribute("can-drop")!=="false";q(n,this.activeDropPaneEl),n.setAttribute("can-drop",o);return}else{const n=B(this.activeDragGlassEl);this.addPane(t.id,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)})}},ft={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 G extends W{enableFeatures(){super.enableFeatures(),this.enableObservers(),this.enableDrag()}onPaneCreate(t,i){const n=new I({...i.store,sash:i,binaryWindow:this});t.innerHTML="",t.append(n.domNode),this.debug&&n.contentElement.prepend(`${i.id}`)}onPaneUpdate(){}addGlass(t,i,n){const o=this.addPane(t,i),s=new I({...n,sash:o,binaryWindow:this});o.domNode.append(s.domNode)}removeGlass(t,i){if(i)this.removePane(t);else{const n=this.rootSash.getById(t);if(!n)throw new Error("[bwin] Pane not found when removing glass");const o=n.domNode.querySelector("bw-glass");o&&o.remove()}}}G.assemble(pt,gt,ft);const v=4;function wt({sash:e}){var d;const t=u.useRef(),i=e.leftChild,n=e.topChild;let o,s,r,a,l,c;return i?(o=v,s=e.height-v,r=e.top+v/2,a=e.left+i.width-v/2,l=!0):n&&(o=e.width-v,s=v,r=e.top+n.height-v/2,a=e.left+v/2,c=!0),u.useEffect(()=>{e.domNode=t.current},[]),u.createElement("bw-muntin",{"sash-id":e.id,style:{width:o,height:s,top:r,left:a},vertical:l,horizontal:c,resizable:((d=e.store)==null?void 0:d.resizable)===!1?"false":"true",ref:t})}function mt({sash:e,bwin:t}){var d,p,g,w,m;const i=u.useRef(),{left:n,top:o,width:s,height:r,id:a,position:l}=e;u.useEffect(()=>{e.domNode=i.current},[]);const c=((d=e.store)==null?void 0:d.actions)===void 0?$:Array.isArray(e.store.actions)?e.store.actions:[];return u.createElement("bw-pane",{"sash-id":a,position:l,style:{left:n,top:o,width:s,height:r},"can-drop":((p=e.store)==null?void 0:p.droppable)===!1?"false":"true",ref:i},u.createElement("bw-glass",null,u.createElement("bw-glass-header",{"can-drag":((g=e.store)==null?void 0:g.draggable)===!1?"false":"true"},((w=e.store)==null?void 0:w.title)&&u.createElement("bw-glass-title",null,e.store.title),c.length>0&&u.createElement("bw-glass-action-container",null,c.map((A,yt)=>{const Et=A.className?`bw-glass-action ${A.className}`:"bw-glass-action";return u.createElement("button",{className:Et,key:yt,onClick:vt=>A.onClick(vt,t)},A.label)}))),u.createElement("bw-glass-content",null,(m=e.store)==null?void 0:m.content)))}function bt(e){const t=u.useRef(),i=new G(e),n=[],o=[];return i.rootSash.walk(s=>{s.children.length>0?n.push(s):o.push(s)}),u.useEffect(()=>{const s=t.current;s!=null&&s.parentElement&&(i.windowElement=s,i.containerElement=s.parentElement,i.enableFeatures())},[]),u.createElement("bw-window",{"sash-id":i.rootSash.id,style:{width:i.rootSash.width,height:i.rootSash.height},ref:t},o.map(s=>u.createElement(mt,{key:s.id,sash:s,bwin:i})),n.map(s=>u.createElement(wt,{key:s.id,sash:s})))}b.BUILTIN_ACTIONS=$,b.Window=bt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-bwin",
|
|
3
|
+
"description": "A tiling window manager in React based on Binary Window library",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/bhjsdev/react-bwin.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"react",
|
|
12
|
+
"drag",
|
|
13
|
+
"drop",
|
|
14
|
+
"resize",
|
|
15
|
+
"window-manager",
|
|
16
|
+
"tiling-window-manager"
|
|
17
|
+
],
|
|
18
|
+
"author": "Bhjs Dev <bhjsdev@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"bugs": "https://github.com/bhjsdev/react-bwin/issues",
|
|
21
|
+
"homepage": "https://github.com/bhjsdev/react-bwin#readme",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/react-bwin.js",
|
|
26
|
+
"module": "./dist/react-bwin.js",
|
|
27
|
+
"types": "./dist/react-bwin.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/react-bwin.d.ts",
|
|
31
|
+
"import": "./dist/react-bwin.js"
|
|
32
|
+
},
|
|
33
|
+
"./react-bwin.css": "./dist/react-bwin.css"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"dev": "vite",
|
|
37
|
+
"build": "tsc -b && vite build"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=16.8.0",
|
|
41
|
+
"react-dom": ">=16.8.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.10.1",
|
|
45
|
+
"@types/react": "^16.14.62",
|
|
46
|
+
"@types/react-dom": "^16.9.24",
|
|
47
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
48
|
+
"bwin": "0.1.1",
|
|
49
|
+
"prettier": "^3.4.1",
|
|
50
|
+
"react": "^16.14.0",
|
|
51
|
+
"react-dom": "^16.14.0",
|
|
52
|
+
"typescript": "^5.6.2",
|
|
53
|
+
"vite": "^6.0.1"
|
|
54
|
+
}
|
|
55
|
+
}
|