ninegrid2 6.1087.0 → 6.1088.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/dist/bundle.cjs.js +34 -4
- package/dist/bundle.esm.js +34 -4
- package/dist/index.js +1 -0
- package/dist/nx/nxPanel.js +35 -0
- package/dist/nx/nxSplitter.js +0 -4
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/nx/nxPanel.js +35 -0
- package/src/nx/nxSplitter.js +0 -4
- package/src/nx/nxSplitter-BAK.js +0 -267
package/dist/bundle.cjs.js
CHANGED
|
@@ -121492,8 +121492,6 @@ class nxSplitter extends HTMLElement {
|
|
|
121492
121492
|
const gapCount = allChildren.length > 1 ? allChildren.length - 1 : 0;
|
|
121493
121493
|
const totalGapSize = gapCount * gapSize;
|
|
121494
121494
|
|
|
121495
|
-
console.log(totalGapSize);
|
|
121496
|
-
|
|
121497
121495
|
const finalDragBarPos = isHorizontal ? parseFloat(dragBar.style.left) : parseFloat(dragBar.style.top);
|
|
121498
121496
|
const dragOffset = finalDragBarPos - initialSplitterPosInParent;
|
|
121499
121497
|
|
|
@@ -121513,8 +121511,6 @@ class nxSplitter extends HTMLElement {
|
|
|
121513
121511
|
newNextSize = 0;
|
|
121514
121512
|
}
|
|
121515
121513
|
|
|
121516
|
-
console.log(prevSize, nextSize, newPrevSize, newNextSize);
|
|
121517
|
-
|
|
121518
121514
|
const initialSizes = allPanels.map(panel => isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height);
|
|
121519
121515
|
|
|
121520
121516
|
const totalSplitterSize = allChildren.reduce((sum, child) => {
|
|
@@ -121956,6 +121952,40 @@ class NxLayout extends HTMLElement {
|
|
|
121956
121952
|
|
|
121957
121953
|
customElements.define('nx-layout', NxLayout);
|
|
121958
121954
|
|
|
121955
|
+
class nxPanel extends HTMLElement {
|
|
121956
|
+
constructor() {
|
|
121957
|
+
super();
|
|
121958
|
+
this.attachShadow({ mode: "open" });
|
|
121959
|
+
}
|
|
121960
|
+
|
|
121961
|
+
connectedCallback() {
|
|
121962
|
+
this.#init();
|
|
121963
|
+
}
|
|
121964
|
+
|
|
121965
|
+
#init = () => {
|
|
121966
|
+
const caption = this.getAttribute("caption");
|
|
121967
|
+
const contents = this.innerHTML.trim();
|
|
121968
|
+
this.innerHTML = ""; // 기존 내부 HTML 제거
|
|
121969
|
+
|
|
121970
|
+
const htmlTmpl = document.createElement("template");
|
|
121971
|
+
htmlTmpl.innerHTML = `
|
|
121972
|
+
<style>
|
|
121973
|
+
@import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
|
|
121974
|
+
${ninegrid.getCustomPath(this,"nxPanel.css")}
|
|
121975
|
+
</style>
|
|
121976
|
+
|
|
121977
|
+
<div class="wrapper">
|
|
121978
|
+
<div class="head">${caption}</div>
|
|
121979
|
+
<div class="body">${contents}</div>
|
|
121980
|
+
</div>
|
|
121981
|
+
`;
|
|
121982
|
+
|
|
121983
|
+
this.shadowRoot.querySelector(".body").appendChild(htmlTmpl.content.cloneNode(true));
|
|
121984
|
+
}
|
|
121985
|
+
}
|
|
121986
|
+
|
|
121987
|
+
customElements.define("nx-panel", nxPanel);
|
|
121988
|
+
|
|
121959
121989
|
class aiSettings extends HTMLElement
|
|
121960
121990
|
{
|
|
121961
121991
|
constructor() {
|
package/dist/bundle.esm.js
CHANGED
|
@@ -121488,8 +121488,6 @@ class nxSplitter extends HTMLElement {
|
|
|
121488
121488
|
const gapCount = allChildren.length > 1 ? allChildren.length - 1 : 0;
|
|
121489
121489
|
const totalGapSize = gapCount * gapSize;
|
|
121490
121490
|
|
|
121491
|
-
console.log(totalGapSize);
|
|
121492
|
-
|
|
121493
121491
|
const finalDragBarPos = isHorizontal ? parseFloat(dragBar.style.left) : parseFloat(dragBar.style.top);
|
|
121494
121492
|
const dragOffset = finalDragBarPos - initialSplitterPosInParent;
|
|
121495
121493
|
|
|
@@ -121509,8 +121507,6 @@ class nxSplitter extends HTMLElement {
|
|
|
121509
121507
|
newNextSize = 0;
|
|
121510
121508
|
}
|
|
121511
121509
|
|
|
121512
|
-
console.log(prevSize, nextSize, newPrevSize, newNextSize);
|
|
121513
|
-
|
|
121514
121510
|
const initialSizes = allPanels.map(panel => isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height);
|
|
121515
121511
|
|
|
121516
121512
|
const totalSplitterSize = allChildren.reduce((sum, child) => {
|
|
@@ -121952,6 +121948,40 @@ class NxLayout extends HTMLElement {
|
|
|
121952
121948
|
|
|
121953
121949
|
customElements.define('nx-layout', NxLayout);
|
|
121954
121950
|
|
|
121951
|
+
class nxPanel extends HTMLElement {
|
|
121952
|
+
constructor() {
|
|
121953
|
+
super();
|
|
121954
|
+
this.attachShadow({ mode: "open" });
|
|
121955
|
+
}
|
|
121956
|
+
|
|
121957
|
+
connectedCallback() {
|
|
121958
|
+
this.#init();
|
|
121959
|
+
}
|
|
121960
|
+
|
|
121961
|
+
#init = () => {
|
|
121962
|
+
const caption = this.getAttribute("caption");
|
|
121963
|
+
const contents = this.innerHTML.trim();
|
|
121964
|
+
this.innerHTML = ""; // 기존 내부 HTML 제거
|
|
121965
|
+
|
|
121966
|
+
const htmlTmpl = document.createElement("template");
|
|
121967
|
+
htmlTmpl.innerHTML = `
|
|
121968
|
+
<style>
|
|
121969
|
+
@import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
|
|
121970
|
+
${ninegrid.getCustomPath(this,"nxPanel.css")}
|
|
121971
|
+
</style>
|
|
121972
|
+
|
|
121973
|
+
<div class="wrapper">
|
|
121974
|
+
<div class="head">${caption}</div>
|
|
121975
|
+
<div class="body">${contents}</div>
|
|
121976
|
+
</div>
|
|
121977
|
+
`;
|
|
121978
|
+
|
|
121979
|
+
this.shadowRoot.querySelector(".body").appendChild(htmlTmpl.content.cloneNode(true));
|
|
121980
|
+
}
|
|
121981
|
+
}
|
|
121982
|
+
|
|
121983
|
+
customElements.define("nx-panel", nxPanel);
|
|
121984
|
+
|
|
121955
121985
|
class aiSettings extends HTMLElement
|
|
121956
121986
|
{
|
|
121957
121987
|
constructor() {
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ninegrid from "../index.js";
|
|
2
|
+
|
|
3
|
+
class nxPanel extends HTMLElement {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.attachShadow({ mode: "open" });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
this.#init();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#init = () => {
|
|
14
|
+
const caption = this.getAttribute("caption");
|
|
15
|
+
const contents = this.innerHTML.trim();
|
|
16
|
+
this.innerHTML = ""; // 기존 내부 HTML 제거
|
|
17
|
+
|
|
18
|
+
const htmlTmpl = document.createElement("template");
|
|
19
|
+
htmlTmpl.innerHTML = `
|
|
20
|
+
<style>
|
|
21
|
+
@import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
|
|
22
|
+
${ninegrid.getCustomPath(this,"nxPanel.css")}
|
|
23
|
+
</style>
|
|
24
|
+
|
|
25
|
+
<div class="wrapper">
|
|
26
|
+
<div class="head">${caption}</div>
|
|
27
|
+
<div class="body">${contents}</div>
|
|
28
|
+
</div>
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
this.shadowRoot.querySelector(".body").appendChild(htmlTmpl.content.cloneNode(true));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
customElements.define("nx-panel", nxPanel);
|
package/dist/nx/nxSplitter.js
CHANGED
|
@@ -125,8 +125,6 @@ class nxSplitter extends HTMLElement {
|
|
|
125
125
|
const gapCount = allChildren.length > 1 ? allChildren.length - 1 : 0;
|
|
126
126
|
const totalGapSize = gapCount * gapSize;
|
|
127
127
|
|
|
128
|
-
console.log(totalGapSize);
|
|
129
|
-
|
|
130
128
|
const finalDragBarPos = isHorizontal ? parseFloat(dragBar.style.left) : parseFloat(dragBar.style.top);
|
|
131
129
|
const dragOffset = finalDragBarPos - initialSplitterPosInParent;
|
|
132
130
|
|
|
@@ -146,8 +144,6 @@ class nxSplitter extends HTMLElement {
|
|
|
146
144
|
newNextSize = 0;
|
|
147
145
|
}
|
|
148
146
|
|
|
149
|
-
console.log(prevSize, nextSize, newPrevSize, newNextSize);
|
|
150
|
-
|
|
151
147
|
const initialSizes = allPanels.map(panel => isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height);
|
|
152
148
|
|
|
153
149
|
const totalSplitterSize = allChildren.reduce((sum, child) => {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ninegrid from "../index.js";
|
|
2
|
+
|
|
3
|
+
class nxPanel extends HTMLElement {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.attachShadow({ mode: "open" });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
this.#init();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#init = () => {
|
|
14
|
+
const caption = this.getAttribute("caption");
|
|
15
|
+
const contents = this.innerHTML.trim();
|
|
16
|
+
this.innerHTML = ""; // 기존 내부 HTML 제거
|
|
17
|
+
|
|
18
|
+
const htmlTmpl = document.createElement("template");
|
|
19
|
+
htmlTmpl.innerHTML = `
|
|
20
|
+
<style>
|
|
21
|
+
@import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxPanel.css";
|
|
22
|
+
${ninegrid.getCustomPath(this,"nxPanel.css")}
|
|
23
|
+
</style>
|
|
24
|
+
|
|
25
|
+
<div class="wrapper">
|
|
26
|
+
<div class="head">${caption}</div>
|
|
27
|
+
<div class="body">${contents}</div>
|
|
28
|
+
</div>
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
this.shadowRoot.querySelector(".body").appendChild(htmlTmpl.content.cloneNode(true));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
customElements.define("nx-panel", nxPanel);
|
package/src/nx/nxSplitter.js
CHANGED
|
@@ -125,8 +125,6 @@ class nxSplitter extends HTMLElement {
|
|
|
125
125
|
const gapCount = allChildren.length > 1 ? allChildren.length - 1 : 0;
|
|
126
126
|
const totalGapSize = gapCount * gapSize;
|
|
127
127
|
|
|
128
|
-
console.log(totalGapSize);
|
|
129
|
-
|
|
130
128
|
const finalDragBarPos = isHorizontal ? parseFloat(dragBar.style.left) : parseFloat(dragBar.style.top);
|
|
131
129
|
const dragOffset = finalDragBarPos - initialSplitterPosInParent;
|
|
132
130
|
|
|
@@ -146,8 +144,6 @@ class nxSplitter extends HTMLElement {
|
|
|
146
144
|
newNextSize = 0;
|
|
147
145
|
}
|
|
148
146
|
|
|
149
|
-
console.log(prevSize, nextSize, newPrevSize, newNextSize);
|
|
150
|
-
|
|
151
147
|
const initialSizes = allPanels.map(panel => isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height);
|
|
152
148
|
|
|
153
149
|
const totalSplitterSize = allChildren.reduce((sum, child) => {
|
package/src/nx/nxSplitter-BAK.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import ninegrid from "../index.js";
|
|
2
|
-
|
|
3
|
-
class nxSplitter extends HTMLElement {
|
|
4
|
-
#mode;
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
this.attachShadow({ mode: "open" });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
connectedCallback() {
|
|
12
|
-
this.#init();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
#detectMode = (el) => {
|
|
16
|
-
const prev = el.previousElementSibling;
|
|
17
|
-
const next = el.nextElementSibling;
|
|
18
|
-
|
|
19
|
-
const prevRect = prev?.getBoundingClientRect();
|
|
20
|
-
const nextRect = next?.getBoundingClientRect();
|
|
21
|
-
|
|
22
|
-
if (this.classList.contains('h')) {
|
|
23
|
-
this.#mode = "h";
|
|
24
|
-
}
|
|
25
|
-
else if (this.classList.contains('v')) {
|
|
26
|
-
this.#mode = "v";
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
#startDrag = (e) => {
|
|
34
|
-
e.preventDefault();
|
|
35
|
-
e.stopPropagation();
|
|
36
|
-
|
|
37
|
-
const splitterRect = this.getBoundingClientRect();
|
|
38
|
-
const isHorizontal = this.#mode === "h";
|
|
39
|
-
|
|
40
|
-
const clickOffset = isHorizontal
|
|
41
|
-
? e.clientX - splitterRect.left
|
|
42
|
-
: e.clientY - splitterRect.top;
|
|
43
|
-
|
|
44
|
-
const dragBar = document.createElement("div");
|
|
45
|
-
dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
|
|
46
|
-
|
|
47
|
-
Object.assign(dragBar.style, {
|
|
48
|
-
position: "absolute",
|
|
49
|
-
zIndex: "999",
|
|
50
|
-
background: "#666",
|
|
51
|
-
opacity: "0.6",
|
|
52
|
-
pointerEvents: "none"
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const root = this.getRootNode({ composed: true });
|
|
56
|
-
const parent = root instanceof ShadowRoot ? root.host : this.parentElement;
|
|
57
|
-
|
|
58
|
-
const prev = this.previousElementSibling;
|
|
59
|
-
const next = this.nextElementSibling;
|
|
60
|
-
|
|
61
|
-
if (!parent || !prev || !next) {
|
|
62
|
-
console.warn("Spliter's parent or siblings not found.");
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
(parent.shadowRoot || parent).appendChild(dragBar);
|
|
67
|
-
|
|
68
|
-
const dragBarOffsetParent = dragBar.offsetParent;
|
|
69
|
-
|
|
70
|
-
if (!dragBarOffsetParent) {
|
|
71
|
-
console.error("dragBar's offsetParent could not be determined. Ensure parent or an ancestor has a position property (e.g., relative).");
|
|
72
|
-
dragBar.remove();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const dragBarOffsetParentRect = dragBarOffsetParent.getBoundingClientRect();
|
|
77
|
-
const prevRect = prev.getBoundingClientRect();
|
|
78
|
-
const nextRect = next.getBoundingClientRect();
|
|
79
|
-
|
|
80
|
-
let initialPosInOffsetParent;
|
|
81
|
-
if (isHorizontal) {
|
|
82
|
-
initialPosInOffsetParent = e.clientX - dragBarOffsetParentRect.left;
|
|
83
|
-
dragBar.style.top = "0";
|
|
84
|
-
dragBar.style.left = `${initialPosInOffsetParent}px`;
|
|
85
|
-
dragBar.style.width = "1px";
|
|
86
|
-
dragBar.style.height = "100%";
|
|
87
|
-
} else {
|
|
88
|
-
initialPosInOffsetParent = e.clientY - dragBarOffsetParentRect.top;
|
|
89
|
-
dragBar.style.left = "0";
|
|
90
|
-
dragBar.style.top = `${initialPosInOffsetParent}px`;
|
|
91
|
-
dragBar.style.height = "1px";
|
|
92
|
-
dragBar.style.width = "100%";
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const minLimit = isHorizontal
|
|
96
|
-
? prevRect.left - dragBarOffsetParentRect.left
|
|
97
|
-
: prevRect.top - dragBarOffsetParentRect.top;
|
|
98
|
-
const maxLimit = isHorizontal
|
|
99
|
-
? nextRect.right - dragBarOffsetParentRect.left
|
|
100
|
-
: nextRect.bottom - dragBarOffsetParentRect.top;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const onMove = moveEvent => {
|
|
104
|
-
const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
|
|
105
|
-
const currentPosInOffsetParent = isHorizontal
|
|
106
|
-
? clientPos - dragBarOffsetParentRect.left
|
|
107
|
-
: clientPos - dragBarOffsetParentRect.top;
|
|
108
|
-
|
|
109
|
-
const clampedPos = Math.max(minLimit, Math.min(currentPosInOffsetParent, maxLimit));
|
|
110
|
-
|
|
111
|
-
if (isHorizontal) {
|
|
112
|
-
dragBar.style.left = `${clampedPos}px`;
|
|
113
|
-
} else {
|
|
114
|
-
dragBar.style.top = `${clampedPos}px`;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
console.log(clampedPos);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const onUp = (upEvent) => {
|
|
121
|
-
window.removeEventListener("mousemove", onMove);
|
|
122
|
-
window.removeEventListener("mouseup", onUp);
|
|
123
|
-
dragBar.remove();
|
|
124
|
-
|
|
125
|
-
const finalDragBarPosInOffsetParent = isHorizontal
|
|
126
|
-
? parseFloat(dragBar.style.left)
|
|
127
|
-
: parseFloat(dragBar.style.top);
|
|
128
|
-
|
|
129
|
-
// ⭐⭐ offsetParentTotalSize 변수를 여기서 정의합니다 ⭐⭐
|
|
130
|
-
const offsetParentTotalSize = isHorizontal
|
|
131
|
-
? dragBarOffsetParentRect.width
|
|
132
|
-
: dragBarOffsetParentRect.height;
|
|
133
|
-
|
|
134
|
-
const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
|
|
135
|
-
|
|
136
|
-
// prev의 시작점 (offsetParent 기준)
|
|
137
|
-
const prevStartPosInOffsetParent = isHorizontal
|
|
138
|
-
? prevRect.left - dragBarOffsetParentRect.left
|
|
139
|
-
: prevRect.top - dragBarOffsetParentRect.top;
|
|
140
|
-
|
|
141
|
-
// prev의 새로운 크기 (dragBar의 왼쪽 위치 - prev의 왼쪽 위치)
|
|
142
|
-
let finalPrevSize = finalDragBarPosInOffsetParent - prevStartPosInOffsetParent;
|
|
143
|
-
|
|
144
|
-
// next의 새로운 크기 (offsetParent의 전체 크기 - prev 크기 - 스플리터 두께)
|
|
145
|
-
// 이 방법이 전체 공간을 정확히 채우면서 오차를 마지막 패널에 몰아넣는 데 더 견고합니다.
|
|
146
|
-
const MIN_PANEL_SIZE_PX = 1;
|
|
147
|
-
finalPrevSize = Math.max(MIN_PANEL_SIZE_PX, finalPrevSize) - clickOffset;
|
|
148
|
-
let finalNextSize = Math.max(MIN_PANEL_SIZE_PX, offsetParentTotalSize - finalPrevSize - splitterThickness);
|
|
149
|
-
|
|
150
|
-
// flex 속성 저장 및 복원
|
|
151
|
-
const originalPrevFlex = prev.style.flex;
|
|
152
|
-
const originalNextFlex = next.style.flex;
|
|
153
|
-
|
|
154
|
-
// 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
|
|
155
|
-
prev.style.flex = "none";
|
|
156
|
-
next.style.flex = "none";
|
|
157
|
-
|
|
158
|
-
console.log(finalPrevSize, finalNextSize, offsetParentTotalSize);
|
|
159
|
-
|
|
160
|
-
if (isHorizontal) {
|
|
161
|
-
prev.style.width = `${finalPrevSize}px`;
|
|
162
|
-
next.style.width = `${finalNextSize}px`;
|
|
163
|
-
} else {
|
|
164
|
-
prev.style.height = `${finalPrevSize}px`;
|
|
165
|
-
next.style.height = `${finalNextSize}px`;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// 작업 완료 후 원래 flex 값으로 복원
|
|
169
|
-
prev.style.flex = originalPrevFlex;
|
|
170
|
-
next.style.flex = originalNextFlex;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
window.addEventListener("mousemove", onMove);
|
|
174
|
-
window.addEventListener("mouseup", onUp);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
#init = () => {
|
|
179
|
-
this.#detectMode(this);
|
|
180
|
-
|
|
181
|
-
this.classList.add(this.#mode);
|
|
182
|
-
|
|
183
|
-
const contents = this.innerHTML.trim();
|
|
184
|
-
const gripClass = `grip-${this.#mode}`;
|
|
185
|
-
const gripTmpl = (contents === "") ? `<div class="${gripClass}"></div>`: `<div class="${gripClass}"></div><div class="inner-container">${contents}</div><div class="${gripClass}"></div>`;
|
|
186
|
-
|
|
187
|
-
this.innerHTML = "";
|
|
188
|
-
const htmlTmpl = document.createElement("template");
|
|
189
|
-
htmlTmpl.innerHTML = `
|
|
190
|
-
<style>
|
|
191
|
-
@import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/nxSplitter.css";
|
|
192
|
-
${ninegrid.getCustomPath(this,"nxSplitter.css")}
|
|
193
|
-
</style>
|
|
194
|
-
|
|
195
|
-
${gripTmpl}
|
|
196
|
-
`;
|
|
197
|
-
|
|
198
|
-
this.shadowRoot.appendChild(htmlTmpl.content.cloneNode(true));
|
|
199
|
-
|
|
200
|
-
this.shadowRoot.querySelectorAll(".grip-h,.grip-v").forEach(el => {
|
|
201
|
-
el.addEventListener("mousedown", e => this.#startDrag(e));
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
this.#prepareLayout();
|
|
205
|
-
|
|
206
|
-
window.addEventListener("resize", () => this.#prepareLayout());
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
#isLastSplitter = () => {
|
|
210
|
-
const parent = this.parentElement;
|
|
211
|
-
if (!parent) return false;
|
|
212
|
-
|
|
213
|
-
const allSplitters = [...parent.querySelectorAll("nx-splitter")];
|
|
214
|
-
return allSplitters.at(-1) === this;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
#getSiblingSizeSum = () => {
|
|
218
|
-
const parent = this.parentElement;
|
|
219
|
-
if (!parent) return 0;
|
|
220
|
-
|
|
221
|
-
const isHorizontal = this.#mode === "h";
|
|
222
|
-
|
|
223
|
-
return Array.from(parent.children).reduce((sum, el) => {
|
|
224
|
-
const size = isHorizontal ? el.offsetWidth : el.offsetHeight;
|
|
225
|
-
return sum + size;
|
|
226
|
-
}, 0);
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
#prepareLayout = () => {
|
|
231
|
-
|
|
232
|
-
const isHorizontal = this.#mode === "h";
|
|
233
|
-
const prev = this.previousElementSibling;
|
|
234
|
-
const next = this.nextElementSibling;
|
|
235
|
-
const parent = this.parentElement;
|
|
236
|
-
if (!prev || !next || !parent) return;
|
|
237
|
-
|
|
238
|
-
const currentTotal = this.#getSiblingSizeSum();
|
|
239
|
-
const nextTotal = isHorizontal
|
|
240
|
-
? parent.getBoundingClientRect().width
|
|
241
|
-
: parent.getBoundingClientRect().height;
|
|
242
|
-
|
|
243
|
-
const prevSize = isHorizontal ? prev.offsetWidth : prev.offsetHeight;
|
|
244
|
-
const nextSize = isHorizontal ? next.offsetWidth : next.offsetHeight;
|
|
245
|
-
|
|
246
|
-
const newPrevSize = nextTotal * prevSize / currentTotal;
|
|
247
|
-
const newNextSize = nextTotal * nextSize / currentTotal;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (isHorizontal) {
|
|
251
|
-
prev.style.width = `${newPrevSize}px`;
|
|
252
|
-
|
|
253
|
-
if (this.#isLastSplitter()) {
|
|
254
|
-
next.style.width = `${newNextSize}px`;
|
|
255
|
-
}
|
|
256
|
-
} else {
|
|
257
|
-
prev.style.height = `${newPrevSize}px`;
|
|
258
|
-
|
|
259
|
-
if (this.#isLastSplitter()) {
|
|
260
|
-
next.style.height = `${newNextSize}px`;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
customElements.define("nx-splitter", nxSplitter);
|