bwin 0.2.6 → 0.2.8
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/dist/bwin.js +80 -65
- package/package.json +1 -1
package/dist/bwin.js
CHANGED
|
@@ -21,13 +21,13 @@ function C(i = 2, t = 3) {
|
|
|
21
21
|
}
|
|
22
22
|
return s;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function S(i, t) {
|
|
25
25
|
for (; t.firstChild; )
|
|
26
26
|
i.append(t.firstChild);
|
|
27
27
|
}
|
|
28
28
|
function W(i, t) {
|
|
29
29
|
const e = document.createElement("div");
|
|
30
|
-
|
|
30
|
+
S(e, i), S(i, t), S(t, e);
|
|
31
31
|
}
|
|
32
32
|
function b(i) {
|
|
33
33
|
if (typeof i == "number" && !isNaN(i))
|
|
@@ -117,21 +117,23 @@ function k({ width: i, height: t, x: e }) {
|
|
|
117
117
|
function U({ width: i, height: t, y: e }) {
|
|
118
118
|
return i - i / t * e;
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function q(i, { clientX: t, clientY: e }) {
|
|
121
121
|
const n = i.getBoundingClientRect(), { width: s, height: o } = n, h = t - n.left, l = e - n.top;
|
|
122
122
|
if (h < 0 || h > s || l < 0 || l > o)
|
|
123
123
|
return r.Outside;
|
|
124
|
-
const d = 0.3,
|
|
125
|
-
return h < s * (0.5 - d / 2) && l >
|
|
124
|
+
const d = 0.3, c = F({ width: s, height: o, x: h }), a = k({ width: s, height: o, x: h }), p = _({ width: s, height: o, y: l }), u = U({ width: s, height: o, y: l });
|
|
125
|
+
return h < s * (0.5 - d / 2) && l > c && l < a ? r.Left : h > s * (0.5 + d / 2) && l < c && l > a ? r.Right : l < o * (0.5 - d / 2) && h > p && h < u ? r.Top : l > o * (0.5 + d / 2) && h < p && h > u ? r.Bottom : h > s * (0.5 - d / 2) && h < s * (0.5 + d / 2) && l > o * (0.5 - d / 2) && l < o * (0.5 + d / 2) ? r.Center : r.Unknown;
|
|
126
126
|
}
|
|
127
|
-
const
|
|
127
|
+
const Y = 100, X = 100, w = {
|
|
128
128
|
left: 0,
|
|
129
129
|
top: 0,
|
|
130
130
|
width: 150,
|
|
131
131
|
height: 150,
|
|
132
132
|
// Initial min values, real min width/height is calculated based on children
|
|
133
|
-
minWidth:
|
|
134
|
-
minHeight: X
|
|
133
|
+
minWidth: Y,
|
|
134
|
+
minHeight: X,
|
|
135
|
+
// `classic` | `natural`, `natural` means only one child is updating its size
|
|
136
|
+
resizeStrategy: "classic"
|
|
135
137
|
};
|
|
136
138
|
class g {
|
|
137
139
|
constructor({
|
|
@@ -141,14 +143,16 @@ class g {
|
|
|
141
143
|
height: s = w.height,
|
|
142
144
|
minWidth: o = w.minWidth,
|
|
143
145
|
minHeight: h = w.minHeight,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
resizeStrategy: l = w.resizeStrategy,
|
|
147
|
+
parent: d = null,
|
|
148
|
+
domNode: c = null,
|
|
149
|
+
store: a = {},
|
|
150
|
+
position: p,
|
|
151
|
+
id: u
|
|
148
152
|
} = w) {
|
|
149
|
-
if (this.id =
|
|
153
|
+
if (this.id = u ?? C(), !p)
|
|
150
154
|
throw new Error("[bwin] Sash position is required");
|
|
151
|
-
this.position =
|
|
155
|
+
this.position = p, this.domNode = c, this.parent = d, this._top = e, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.resizeStrategy = l, this.store = a;
|
|
152
156
|
}
|
|
153
157
|
walk(t) {
|
|
154
158
|
this.children.forEach((e) => e.walk(t)), t(this);
|
|
@@ -289,10 +293,13 @@ class g {
|
|
|
289
293
|
this._width = t;
|
|
290
294
|
const [n, s, o, h] = this.getChildren();
|
|
291
295
|
if (h && s) {
|
|
292
|
-
const l = h.width + s.width, d = e * (h.width / l),
|
|
293
|
-
let
|
|
294
|
-
|
|
295
|
-
|
|
296
|
+
const l = h.width + s.width, d = e * (h.width / l), c = l + e;
|
|
297
|
+
let a, p, u;
|
|
298
|
+
if (this.resizeStrategy === "natural" && this.position === r.Left ? (a = h.width, p = s.width + e, u = s.left) : this.resizeStrategy === "natural" && this.position === r.Right ? (a = h.width + e, p = s.width, u = h.left + a) : (a = h.width + d, p = c - a, u = s.left + d), e < 0) {
|
|
299
|
+
const y = h.calcMinWidth(), E = s.calcMinWidth();
|
|
300
|
+
a < y && p > E ? (a = h.width, p = c - a, u = h.left + a) : p < E && a > y && (p = s.width, a = c - p, u = h.left + a);
|
|
301
|
+
}
|
|
302
|
+
h.width = a, s.width = p, s.left = u;
|
|
296
303
|
}
|
|
297
304
|
n && o && (n.width += e, o.width += e);
|
|
298
305
|
}
|
|
@@ -304,13 +311,13 @@ class g {
|
|
|
304
311
|
this._height = t;
|
|
305
312
|
const [n, s, o, h] = this.getChildren();
|
|
306
313
|
if (n && o) {
|
|
307
|
-
const l = n.height + o.height, d = e * (n.height / l),
|
|
308
|
-
let
|
|
309
|
-
if (e < 0) {
|
|
310
|
-
const
|
|
311
|
-
|
|
314
|
+
const l = n.height + o.height, d = e * (n.height / l), c = l + e;
|
|
315
|
+
let a, p, u;
|
|
316
|
+
if (this.resizeStrategy === "natural" && this.position === r.Top ? (a = n.height, p = o.height + e, u = o.top) : this.resizeStrategy === "natural" && this.position === r.Bottom ? (a = n.height + e, p = o.height, u = n.top + a) : (a = n.height + d, p = c - a, u = o.top + d), e < 0) {
|
|
317
|
+
const y = n.calcMinHeight(), E = o.calcMinHeight();
|
|
318
|
+
a < y && p > E ? (a = n.height, p = c - a, u = n.top + a) : p < E && a > y && (p = o.height, a = c - p, u = n.top + a);
|
|
312
319
|
}
|
|
313
|
-
n.height =
|
|
320
|
+
n.height = a, o.height = p, o.top = u;
|
|
314
321
|
}
|
|
315
322
|
h && s && (h.height += e, s.height += e);
|
|
316
323
|
}
|
|
@@ -319,7 +326,7 @@ const v = {
|
|
|
319
326
|
size: "50%",
|
|
320
327
|
position: r.Left
|
|
321
328
|
};
|
|
322
|
-
class
|
|
329
|
+
class z {
|
|
323
330
|
constructor({
|
|
324
331
|
parentRect: t,
|
|
325
332
|
children: e,
|
|
@@ -329,13 +336,14 @@ class A {
|
|
|
329
336
|
minHeight: h,
|
|
330
337
|
position: l,
|
|
331
338
|
size: d,
|
|
339
|
+
resizeStrategy: c,
|
|
332
340
|
...a
|
|
333
341
|
}) {
|
|
334
342
|
f(this, "left");
|
|
335
343
|
f(this, "top");
|
|
336
344
|
f(this, "width");
|
|
337
345
|
f(this, "height");
|
|
338
|
-
this.parentRect = t, this.children = e, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(d), this.nonCoreData = a, this.setBounds();
|
|
346
|
+
this.parentRect = t, this.children = e, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(d), this.resizeStrategy = c, this.nonCoreData = a, this.setBounds();
|
|
339
347
|
}
|
|
340
348
|
getPosition(t) {
|
|
341
349
|
if (!this.siblingConfigNode)
|
|
@@ -387,7 +395,7 @@ class A {
|
|
|
387
395
|
this.left = this.parentRect.left, this.top = this.parentRect.top + this.parentRect.height - t, this.width = this.parentRect.width, this.height = t;
|
|
388
396
|
}
|
|
389
397
|
}
|
|
390
|
-
createSash() {
|
|
398
|
+
createSash({ resizeStrategy: t } = {}) {
|
|
391
399
|
return new g({
|
|
392
400
|
left: this.left,
|
|
393
401
|
top: this.top,
|
|
@@ -397,6 +405,7 @@ class A {
|
|
|
397
405
|
id: this.id,
|
|
398
406
|
minWidth: this.minWidth,
|
|
399
407
|
minHeight: this.minHeight,
|
|
408
|
+
resizeStrategy: t || this.resizeStrategy,
|
|
400
409
|
store: this.nonCoreData
|
|
401
410
|
});
|
|
402
411
|
}
|
|
@@ -421,7 +430,7 @@ class A {
|
|
|
421
430
|
}
|
|
422
431
|
}
|
|
423
432
|
createPrimaryConfigNode({ size: t, position: e, children: n, id: s, minWidth: o, minHeight: h, ...l }) {
|
|
424
|
-
return new
|
|
433
|
+
return new z({
|
|
425
434
|
parentRect: this,
|
|
426
435
|
size: t ?? v.size,
|
|
427
436
|
position: e ?? v.position,
|
|
@@ -433,7 +442,7 @@ class A {
|
|
|
433
442
|
});
|
|
434
443
|
}
|
|
435
444
|
createSecondaryConfigNode({ size: t, position: e, children: n, id: s, minWidth: o, minHeight: h, ...l }, d) {
|
|
436
|
-
return new
|
|
445
|
+
return new z({
|
|
437
446
|
parentRect: this,
|
|
438
447
|
size: t,
|
|
439
448
|
position: e,
|
|
@@ -445,37 +454,41 @@ class A {
|
|
|
445
454
|
...l
|
|
446
455
|
});
|
|
447
456
|
}
|
|
448
|
-
buildSashTree() {
|
|
449
|
-
const
|
|
457
|
+
buildSashTree({ resizeStrategy: t } = {}) {
|
|
458
|
+
const e = this.createSash({ resizeStrategy: t });
|
|
450
459
|
if (!Array.isArray(this.children) || this.children.length === 0)
|
|
451
|
-
return
|
|
452
|
-
const
|
|
453
|
-
let
|
|
454
|
-
|
|
455
|
-
e,
|
|
456
|
-
s
|
|
457
|
-
)) : (s = this.createPrimaryConfigNode(e), o = this.createSecondaryConfigNode(
|
|
460
|
+
return e;
|
|
461
|
+
const n = this.normConfig(this.children[0]), s = this.normConfig(this.children.at(1));
|
|
462
|
+
let o, h;
|
|
463
|
+
if (!n.size && !n.position && s ? (s.position || (s.position = r.Right), o = this.createPrimaryConfigNode(s), h = this.createSecondaryConfigNode(
|
|
458
464
|
n,
|
|
459
|
-
|
|
460
|
-
))
|
|
465
|
+
o
|
|
466
|
+
)) : (o = this.createPrimaryConfigNode(n), h = this.createSecondaryConfigNode(
|
|
467
|
+
s,
|
|
468
|
+
o
|
|
469
|
+
)), o && h) {
|
|
470
|
+
const l = o.buildSashTree({ resizeStrategy: t }), d = h.buildSashTree({ resizeStrategy: t });
|
|
471
|
+
l.parent = e, d.parent = e, e.children.push(l), e.children.push(d);
|
|
472
|
+
}
|
|
473
|
+
return e;
|
|
461
474
|
}
|
|
462
475
|
}
|
|
463
|
-
const
|
|
476
|
+
const R = {
|
|
464
477
|
width: 333,
|
|
465
478
|
height: 333
|
|
466
479
|
}, D = {
|
|
467
480
|
fitContainer: !1
|
|
468
481
|
};
|
|
469
|
-
class j extends
|
|
482
|
+
class j extends z {
|
|
470
483
|
constructor({
|
|
471
484
|
id: t,
|
|
472
485
|
children: e,
|
|
473
|
-
width: n =
|
|
474
|
-
height: s =
|
|
486
|
+
width: n = R.width,
|
|
487
|
+
height: s = R.height,
|
|
475
488
|
fitContainer: o = D.fitContainer,
|
|
476
489
|
...h
|
|
477
490
|
} = {
|
|
478
|
-
...
|
|
491
|
+
...R,
|
|
479
492
|
...D
|
|
480
493
|
}) {
|
|
481
494
|
super({
|
|
@@ -599,7 +612,7 @@ function et(i, { position: t, size: e, id: n, minWidth: s, minHeight: o }) {
|
|
|
599
612
|
if (t === r.Bottom)
|
|
600
613
|
return it(i, { size: e, id: n });
|
|
601
614
|
}
|
|
602
|
-
function
|
|
615
|
+
function A(i) {
|
|
603
616
|
if (i.tagName === "BW-PANE")
|
|
604
617
|
return i.getAttribute("sash-id");
|
|
605
618
|
const t = i.closest("bw-pane");
|
|
@@ -649,7 +662,7 @@ const nt = {
|
|
|
649
662
|
e.children.length === 0 ? (t.id = e.id, t.domNode = e.domNode, t.domNode.setAttribute("sash-id", e.id), t.children = []) : (t.id = C(), t.children = e.children, e.position === r.Left ? e.width = t.width : e.position === r.Right ? (e.width = t.width, e.left = t.left) : e.position === r.Top ? e.height = t.height : e.position === r.Bottom && (e.height = t.height, e.top = t.top)), this.update();
|
|
650
663
|
},
|
|
651
664
|
swapPanes(i, t) {
|
|
652
|
-
const e =
|
|
665
|
+
const e = A(i), n = A(t), s = i.getAttribute("can-drop") !== "false", o = t.getAttribute("can-drop") !== "false";
|
|
653
666
|
this.rootSash.swapIds(e, n), W(i, this.activeDropPaneEl), i.setAttribute("sash-id", n), t.setAttribute("sash-id", e), i.setAttribute("can-drop", o), t.setAttribute("can-drop", s);
|
|
654
667
|
}
|
|
655
668
|
};
|
|
@@ -708,8 +721,10 @@ const st = {
|
|
|
708
721
|
},
|
|
709
722
|
enableFitContainer() {
|
|
710
723
|
new ResizeObserver((t) => {
|
|
711
|
-
|
|
712
|
-
|
|
724
|
+
requestAnimationFrame(() => {
|
|
725
|
+
for (const e of t)
|
|
726
|
+
e.target === this.containerElement && this.fitContainer && this.fit();
|
|
727
|
+
});
|
|
713
728
|
}).observe(this.containerElement);
|
|
714
729
|
}
|
|
715
730
|
}, rt = {
|
|
@@ -733,13 +748,13 @@ const st = {
|
|
|
733
748
|
if (!this.isResizeStarted || !this.activeMuntinSash) return;
|
|
734
749
|
const [t, e, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
|
|
735
750
|
if (o && s && e) {
|
|
736
|
-
const l = i.pageX - this.lastX, d = s.width + l,
|
|
737
|
-
if (l > 0 &&
|
|
738
|
-
s.width = d, e.width =
|
|
751
|
+
const l = i.pageX - this.lastX, d = s.width + l, c = e.width - l;
|
|
752
|
+
if (l > 0 && c <= e.calcMinWidth() || l < 0 && d <= s.calcMinWidth()) return;
|
|
753
|
+
s.width = d, e.width = c, e.left = e.left + l, this.update(), this.lastX = i.pageX;
|
|
739
754
|
} else if (h && t && n) {
|
|
740
|
-
const l = i.pageY - this.lastY, d = t.height + l,
|
|
741
|
-
if (l > 0 &&
|
|
742
|
-
t.height = d, n.height =
|
|
755
|
+
const l = i.pageY - this.lastY, d = t.height + l, c = n.height - l;
|
|
756
|
+
if (l > 0 && c <= n.calcMinHeight() || l < 0 && d <= t.calcMinHeight()) return;
|
|
757
|
+
t.height = d, n.height = c, n.top = n.top + l, this.update(), this.lastY = i.pageY;
|
|
743
758
|
}
|
|
744
759
|
}), document.addEventListener("mouseup", () => {
|
|
745
760
|
this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
|
|
@@ -755,7 +770,7 @@ const st = {
|
|
|
755
770
|
i.preventDefault();
|
|
756
771
|
const t = i.target.matches("bw-pane") ? i.target : i.target.closest("bw-pane");
|
|
757
772
|
if (!t || (t !== this.activeDropPaneEl && (this.activeDropPaneEl && this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = t), t.getAttribute("can-drop") === "false")) return;
|
|
758
|
-
const e =
|
|
773
|
+
const e = q(t, i);
|
|
759
774
|
t.setAttribute("drop-area", e);
|
|
760
775
|
}), this.windowElement.addEventListener("dragleave", (i) => {
|
|
761
776
|
i.currentTarget.contains(i.relatedTarget) && i.currentTarget !== i.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
|
|
@@ -772,7 +787,7 @@ class B {
|
|
|
772
787
|
f(this, "containerElement", null);
|
|
773
788
|
f(this, "debug", dt);
|
|
774
789
|
let e = null;
|
|
775
|
-
t instanceof K ? (e = t, this.rootSash = t) : (e = new j(t), this.rootSash = e.buildSashTree()), this.fitContainer = e.fitContainer;
|
|
790
|
+
t instanceof K ? (e = t, this.rootSash = t) : (e = new j(t), this.rootSash = e.buildSashTree({ resizeStrategy: e.resizeStrategy })), this.fitContainer = e.fitContainer;
|
|
776
791
|
}
|
|
777
792
|
frame(t) {
|
|
778
793
|
this.containerElement = t, this.windowElement = this.createWindow(), this.glaze(), this.containerElement.append(this.windowElement);
|
|
@@ -802,7 +817,7 @@ const at = {
|
|
|
802
817
|
label: "",
|
|
803
818
|
className: "bw-glass-action--close",
|
|
804
819
|
onClick: (i, t) => {
|
|
805
|
-
const e =
|
|
820
|
+
const e = A(i.target);
|
|
806
821
|
t.removePane(e);
|
|
807
822
|
}
|
|
808
823
|
}, ct = {
|
|
@@ -828,12 +843,12 @@ function ut(i, t) {
|
|
|
828
843
|
const e = i.left + i.width, n = i.top + i.height, s = t.left + t.width, o = t.top + t.height;
|
|
829
844
|
if (i.left >= s || t.left >= e || i.top >= o || t.top >= n)
|
|
830
845
|
return null;
|
|
831
|
-
const h = Math.max(i.left, t.left), l = Math.max(i.top, t.top), d = Math.min(e, s),
|
|
846
|
+
const h = Math.max(i.left, t.left), l = Math.max(i.top, t.top), d = Math.min(e, s), c = Math.min(n, o);
|
|
832
847
|
return {
|
|
833
848
|
left: h,
|
|
834
849
|
top: l,
|
|
835
850
|
width: d - h,
|
|
836
|
-
height:
|
|
851
|
+
height: c - l
|
|
837
852
|
};
|
|
838
853
|
}
|
|
839
854
|
const ft = [ct, pt, at], gt = {
|
|
@@ -858,9 +873,9 @@ const ft = [ct, pt, at], gt = {
|
|
|
858
873
|
d = o.height - t.height < l.minHeight ? o.height / 2 : t.height;
|
|
859
874
|
else
|
|
860
875
|
throw new Error("[bwin] Invalid position when restoring glass");
|
|
861
|
-
const
|
|
876
|
+
const c = i.bwOriginalSashId;
|
|
862
877
|
this.addPane(n.getAttribute("sash-id"), {
|
|
863
|
-
id:
|
|
878
|
+
id: c,
|
|
864
879
|
position: s,
|
|
865
880
|
size: d
|
|
866
881
|
}).domNode.append(i.bwGlassElement);
|
|
@@ -966,7 +981,7 @@ const wt = {
|
|
|
966
981
|
this.swapPanes(n, this.activeDropPaneEl);
|
|
967
982
|
return;
|
|
968
983
|
} else {
|
|
969
|
-
const n =
|
|
984
|
+
const n = A(this.activeDragGlassEl);
|
|
970
985
|
this.removePane(n), this.addPane(t.id, { position: e, id: n }).domNode.append(this.activeDragGlassEl);
|
|
971
986
|
}
|
|
972
987
|
},
|
|
@@ -1029,8 +1044,8 @@ class bt extends B {
|
|
|
1029
1044
|
* @returns {Sash} - The newly created Sash
|
|
1030
1045
|
*/
|
|
1031
1046
|
addPane(e, n) {
|
|
1032
|
-
const { position: s, size: o, id: h, ...l } = n, d = super.addPane(e, { position: s, size: o, id: h }),
|
|
1033
|
-
return d.domNode.append(
|
|
1047
|
+
const { position: s, size: o, id: h, ...l } = n, d = super.addPane(e, { position: s, size: o, id: h }), c = new T({ ...l, sash: d, binaryWindow: this });
|
|
1048
|
+
return d.domNode.append(c.domNode), d;
|
|
1034
1049
|
}
|
|
1035
1050
|
removePane(e) {
|
|
1036
1051
|
if (this.windowElement.querySelector(`[sash-id="${e}"]`)) {
|