ninegrid2 6.1021.0 → 6.1023.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.
@@ -121369,8 +121369,6 @@ customElements.define('nx-tab-page', nxTabPage);
121369
121369
 
121370
121370
  class nxSplitter extends HTMLElement {
121371
121371
  #mode;
121372
- #originalPrevFlex;
121373
- #originalNextFlex;
121374
121372
 
121375
121373
  constructor() {
121376
121374
  super();
@@ -121397,7 +121395,6 @@ class nxSplitter extends HTMLElement {
121397
121395
  } else if (this.classList.contains('v')) {
121398
121396
  this.#mode = "v";
121399
121397
  } else {
121400
- // 형제 요소의 위치를 비교하여 모드를 감지
121401
121398
  this.#mode = (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
121402
121399
  }
121403
121400
  };
@@ -121406,13 +121403,9 @@ class nxSplitter extends HTMLElement {
121406
121403
  e.preventDefault();
121407
121404
  e.stopPropagation();
121408
121405
 
121409
- const splitterRect = this.getBoundingClientRect();
121406
+ this.getBoundingClientRect();
121410
121407
  const isHorizontal = this.#mode === "h";
121411
121408
 
121412
- isHorizontal
121413
- ? e.clientX - splitterRect.left
121414
- : e.clientY - splitterRect.top;
121415
-
121416
121409
  const dragBar = document.createElement("div");
121417
121410
  dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
121418
121411
 
@@ -121470,25 +121463,26 @@ class nxSplitter extends HTMLElement {
121470
121463
  }
121471
121464
  };
121472
121465
 
121473
- // #startDrag 메서드 내부 (수정된 onUp 함수)
121474
121466
  const onUp = () => {
121475
121467
  window.removeEventListener("mousemove", onMove);
121476
121468
  window.removeEventListener("mouseup", onUp);
121477
121469
  dragBar.remove();
121478
121470
 
121471
+ const parent = this.parentElement;
121472
+ const isHorizontal = this.#mode === "h";
121473
+
121474
+ // 모든 패널과 스플리터의 현재 크기를 가져옵니다.
121475
+ const allChildren = Array.from(parent.children);
121476
+ const allPanels = allChildren.filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
121477
+
121479
121478
  const finalDragBarPosInParent = isHorizontal
121480
121479
  ? parseFloat(dragBar.style.left)
121481
121480
  : parseFloat(dragBar.style.top);
121482
121481
 
121483
- const parent = this.parentElement;
121484
121482
  const parentRect = parent.getBoundingClientRect();
121485
- const splitterRect = this.getBoundingClientRect();
121486
- const prev = this.previousElementSibling;
121487
- const next = this.nextElementSibling;
121488
- const isHorizontal = this.#mode === "h";
121489
-
121490
121483
  const prevRect = prev.getBoundingClientRect();
121491
121484
  const nextRect = next.getBoundingClientRect();
121485
+ const splitterRect = this.getBoundingClientRect();
121492
121486
 
121493
121487
  const prevStartPosInParent = isHorizontal ? prevRect.left - parentRect.left : prevRect.top - parentRect.top;
121494
121488
  const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
@@ -121497,24 +121491,14 @@ class nxSplitter extends HTMLElement {
121497
121491
  const newPrevSize = finalDragBarPosInParent - prevStartPosInParent;
121498
121492
  const newNextSize = (isHorizontal ? nextRect.right : nextRect.bottom) - finalDragBarPosInParent - splitterThickness;
121499
121493
 
121500
- const totalInitialSize = Array.from(parent.children)
121501
- .filter(el => el.tagName.toLowerCase() !== 'nx-splitter')
121502
- .reduce((sum, el) => {
121503
- const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
121504
- return sum + size;
121505
- }, 0);
121506
-
121507
- const newTotalSize = totalInitialSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
121494
+ const totalContentSize = allPanels.reduce((sum, el) => {
121495
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
121496
+ return sum + size;
121497
+ }, 0);
121508
121498
 
121509
- // 전체 패널의 새로운 Flex 비율을 계산하고 적용
121510
- const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
121511
-
121512
- allPanels.length;
121499
+ const newTotalContentSize = totalContentSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
121513
121500
 
121514
121501
  allPanels.forEach(panel => {
121515
-
121516
- console.log(panel);
121517
-
121518
121502
  const panelRect = panel.getBoundingClientRect();
121519
121503
  const currentSize = isHorizontal ? panelRect.width : panelRect.height;
121520
121504
 
@@ -121522,10 +121506,8 @@ class nxSplitter extends HTMLElement {
121522
121506
  if (panel === prev) newSize = newPrevSize;
121523
121507
  if (panel === next) newSize = newNextSize;
121524
121508
 
121525
- const newFlexBasis = newSize / newTotalSize;
121509
+ const newFlexBasis = newSize / newTotalContentSize;
121526
121510
  panel.style.flex = `${newFlexBasis} ${newFlexBasis} 0`;
121527
-
121528
- console.log(panel.style.flex);
121529
121511
  });
121530
121512
  };
121531
121513
 
@@ -121533,7 +121515,6 @@ class nxSplitter extends HTMLElement {
121533
121515
  window.addEventListener("mouseup", onUp);
121534
121516
  };
121535
121517
 
121536
-
121537
121518
  #init = () => {
121538
121519
  this.#detectMode(this);
121539
121520
 
@@ -121567,28 +121548,25 @@ class nxSplitter extends HTMLElement {
121567
121548
  #prepareLayout = () => {
121568
121549
  const isHorizontal = this.#mode === "h";
121569
121550
  const parent = this.parentElement;
121570
- const prev = this.previousElementSibling;
121571
- const next = this.nextElementSibling;
121572
- if (!prev || !next || !parent) return;
121551
+ const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
121552
+
121553
+ if (allPanels.length < 2) return;
121573
121554
 
121574
121555
  const parentRect = parent.getBoundingClientRect();
121575
- const currentPrevSize = isHorizontal ? prev.getBoundingClientRect().width : prev.getBoundingClientRect().height;
121576
- const currentNextSize = isHorizontal ? next.getBoundingClientRect().width : next.getBoundingClientRect().height;
121577
121556
 
121578
- const totalContentSize = Array.from(parent.children).reduce((sum, el) => {
121579
- const rect = el.getBoundingClientRect();
121580
- const size = isHorizontal ? rect.width : rect.height;
121557
+ const totalContentSize = allPanels.reduce((sum, el) => {
121558
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
121581
121559
  return sum + size;
121582
121560
  }, 0);
121583
121561
 
121584
121562
  const totalParentSize = isHorizontal ? parentRect.width : parentRect.height;
121585
121563
 
121586
- // 리사이즈 시 비율 유지
121587
- const newPrevSize = totalParentSize * (currentPrevSize / totalContentSize);
121588
- const newNextSize = totalParentSize * (currentNextSize / totalContentSize);
121589
-
121590
- prev.style.flex = `0 0 ${newPrevSize}px`;
121591
- next.style.flex = `0 0 ${newNextSize}px`;
121564
+ allPanels.forEach(panel => {
121565
+ const size = isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height;
121566
+ const newSize = totalParentSize * (size / totalContentSize);
121567
+ const flexGrow = newSize / totalParentSize;
121568
+ panel.style.flex = `${flexGrow} ${flexGrow} 0`;
121569
+ });
121592
121570
  };
121593
121571
  }
121594
121572
 
@@ -121365,8 +121365,6 @@ customElements.define('nx-tab-page', nxTabPage);
121365
121365
 
121366
121366
  class nxSplitter extends HTMLElement {
121367
121367
  #mode;
121368
- #originalPrevFlex;
121369
- #originalNextFlex;
121370
121368
 
121371
121369
  constructor() {
121372
121370
  super();
@@ -121393,7 +121391,6 @@ class nxSplitter extends HTMLElement {
121393
121391
  } else if (this.classList.contains('v')) {
121394
121392
  this.#mode = "v";
121395
121393
  } else {
121396
- // 형제 요소의 위치를 비교하여 모드를 감지
121397
121394
  this.#mode = (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
121398
121395
  }
121399
121396
  };
@@ -121402,13 +121399,9 @@ class nxSplitter extends HTMLElement {
121402
121399
  e.preventDefault();
121403
121400
  e.stopPropagation();
121404
121401
 
121405
- const splitterRect = this.getBoundingClientRect();
121402
+ this.getBoundingClientRect();
121406
121403
  const isHorizontal = this.#mode === "h";
121407
121404
 
121408
- isHorizontal
121409
- ? e.clientX - splitterRect.left
121410
- : e.clientY - splitterRect.top;
121411
-
121412
121405
  const dragBar = document.createElement("div");
121413
121406
  dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
121414
121407
 
@@ -121466,25 +121459,26 @@ class nxSplitter extends HTMLElement {
121466
121459
  }
121467
121460
  };
121468
121461
 
121469
- // #startDrag 메서드 내부 (수정된 onUp 함수)
121470
121462
  const onUp = () => {
121471
121463
  window.removeEventListener("mousemove", onMove);
121472
121464
  window.removeEventListener("mouseup", onUp);
121473
121465
  dragBar.remove();
121474
121466
 
121467
+ const parent = this.parentElement;
121468
+ const isHorizontal = this.#mode === "h";
121469
+
121470
+ // 모든 패널과 스플리터의 현재 크기를 가져옵니다.
121471
+ const allChildren = Array.from(parent.children);
121472
+ const allPanels = allChildren.filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
121473
+
121475
121474
  const finalDragBarPosInParent = isHorizontal
121476
121475
  ? parseFloat(dragBar.style.left)
121477
121476
  : parseFloat(dragBar.style.top);
121478
121477
 
121479
- const parent = this.parentElement;
121480
121478
  const parentRect = parent.getBoundingClientRect();
121481
- const splitterRect = this.getBoundingClientRect();
121482
- const prev = this.previousElementSibling;
121483
- const next = this.nextElementSibling;
121484
- const isHorizontal = this.#mode === "h";
121485
-
121486
121479
  const prevRect = prev.getBoundingClientRect();
121487
121480
  const nextRect = next.getBoundingClientRect();
121481
+ const splitterRect = this.getBoundingClientRect();
121488
121482
 
121489
121483
  const prevStartPosInParent = isHorizontal ? prevRect.left - parentRect.left : prevRect.top - parentRect.top;
121490
121484
  const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
@@ -121493,24 +121487,14 @@ class nxSplitter extends HTMLElement {
121493
121487
  const newPrevSize = finalDragBarPosInParent - prevStartPosInParent;
121494
121488
  const newNextSize = (isHorizontal ? nextRect.right : nextRect.bottom) - finalDragBarPosInParent - splitterThickness;
121495
121489
 
121496
- const totalInitialSize = Array.from(parent.children)
121497
- .filter(el => el.tagName.toLowerCase() !== 'nx-splitter')
121498
- .reduce((sum, el) => {
121499
- const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
121500
- return sum + size;
121501
- }, 0);
121502
-
121503
- const newTotalSize = totalInitialSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
121490
+ const totalContentSize = allPanels.reduce((sum, el) => {
121491
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
121492
+ return sum + size;
121493
+ }, 0);
121504
121494
 
121505
- // 전체 패널의 새로운 Flex 비율을 계산하고 적용
121506
- const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
121507
-
121508
- allPanels.length;
121495
+ const newTotalContentSize = totalContentSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
121509
121496
 
121510
121497
  allPanels.forEach(panel => {
121511
-
121512
- console.log(panel);
121513
-
121514
121498
  const panelRect = panel.getBoundingClientRect();
121515
121499
  const currentSize = isHorizontal ? panelRect.width : panelRect.height;
121516
121500
 
@@ -121518,10 +121502,8 @@ class nxSplitter extends HTMLElement {
121518
121502
  if (panel === prev) newSize = newPrevSize;
121519
121503
  if (panel === next) newSize = newNextSize;
121520
121504
 
121521
- const newFlexBasis = newSize / newTotalSize;
121505
+ const newFlexBasis = newSize / newTotalContentSize;
121522
121506
  panel.style.flex = `${newFlexBasis} ${newFlexBasis} 0`;
121523
-
121524
- console.log(panel.style.flex);
121525
121507
  });
121526
121508
  };
121527
121509
 
@@ -121529,7 +121511,6 @@ class nxSplitter extends HTMLElement {
121529
121511
  window.addEventListener("mouseup", onUp);
121530
121512
  };
121531
121513
 
121532
-
121533
121514
  #init = () => {
121534
121515
  this.#detectMode(this);
121535
121516
 
@@ -121563,28 +121544,25 @@ class nxSplitter extends HTMLElement {
121563
121544
  #prepareLayout = () => {
121564
121545
  const isHorizontal = this.#mode === "h";
121565
121546
  const parent = this.parentElement;
121566
- const prev = this.previousElementSibling;
121567
- const next = this.nextElementSibling;
121568
- if (!prev || !next || !parent) return;
121547
+ const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
121548
+
121549
+ if (allPanels.length < 2) return;
121569
121550
 
121570
121551
  const parentRect = parent.getBoundingClientRect();
121571
- const currentPrevSize = isHorizontal ? prev.getBoundingClientRect().width : prev.getBoundingClientRect().height;
121572
- const currentNextSize = isHorizontal ? next.getBoundingClientRect().width : next.getBoundingClientRect().height;
121573
121552
 
121574
- const totalContentSize = Array.from(parent.children).reduce((sum, el) => {
121575
- const rect = el.getBoundingClientRect();
121576
- const size = isHorizontal ? rect.width : rect.height;
121553
+ const totalContentSize = allPanels.reduce((sum, el) => {
121554
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
121577
121555
  return sum + size;
121578
121556
  }, 0);
121579
121557
 
121580
121558
  const totalParentSize = isHorizontal ? parentRect.width : parentRect.height;
121581
121559
 
121582
- // 리사이즈 시 비율 유지
121583
- const newPrevSize = totalParentSize * (currentPrevSize / totalContentSize);
121584
- const newNextSize = totalParentSize * (currentNextSize / totalContentSize);
121585
-
121586
- prev.style.flex = `0 0 ${newPrevSize}px`;
121587
- next.style.flex = `0 0 ${newNextSize}px`;
121560
+ allPanels.forEach(panel => {
121561
+ const size = isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height;
121562
+ const newSize = totalParentSize * (size / totalContentSize);
121563
+ const flexGrow = newSize / totalParentSize;
121564
+ panel.style.flex = `${flexGrow} ${flexGrow} 0`;
121565
+ });
121588
121566
  };
121589
121567
  }
121590
121568
 
@@ -2,8 +2,6 @@ import ninegrid from "../index.js";
2
2
 
3
3
  class nxSplitter extends HTMLElement {
4
4
  #mode;
5
- #originalPrevFlex;
6
- #originalNextFlex;
7
5
 
8
6
  constructor() {
9
7
  super();
@@ -30,7 +28,6 @@ class nxSplitter extends HTMLElement {
30
28
  } else if (this.classList.contains('v')) {
31
29
  this.#mode = "v";
32
30
  } else {
33
- // 형제 요소의 위치를 비교하여 모드를 감지
34
31
  this.#mode = (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
35
32
  }
36
33
  };
@@ -42,10 +39,6 @@ class nxSplitter extends HTMLElement {
42
39
  const splitterRect = this.getBoundingClientRect();
43
40
  const isHorizontal = this.#mode === "h";
44
41
 
45
- const clickOffset = isHorizontal
46
- ? e.clientX - splitterRect.left
47
- : e.clientY - splitterRect.top;
48
-
49
42
  const dragBar = document.createElement("div");
50
43
  dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
51
44
 
@@ -103,25 +96,26 @@ class nxSplitter extends HTMLElement {
103
96
  }
104
97
  };
105
98
 
106
- // #startDrag 메서드 내부 (수정된 onUp 함수)
107
99
  const onUp = () => {
108
100
  window.removeEventListener("mousemove", onMove);
109
101
  window.removeEventListener("mouseup", onUp);
110
102
  dragBar.remove();
111
103
 
104
+ const parent = this.parentElement;
105
+ const isHorizontal = this.#mode === "h";
106
+
107
+ // 모든 패널과 스플리터의 현재 크기를 가져옵니다.
108
+ const allChildren = Array.from(parent.children);
109
+ const allPanels = allChildren.filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
110
+
112
111
  const finalDragBarPosInParent = isHorizontal
113
112
  ? parseFloat(dragBar.style.left)
114
113
  : parseFloat(dragBar.style.top);
115
114
 
116
- const parent = this.parentElement;
117
115
  const parentRect = parent.getBoundingClientRect();
118
- const splitterRect = this.getBoundingClientRect();
119
- const prev = this.previousElementSibling;
120
- const next = this.nextElementSibling;
121
- const isHorizontal = this.#mode === "h";
122
-
123
116
  const prevRect = prev.getBoundingClientRect();
124
117
  const nextRect = next.getBoundingClientRect();
118
+ const splitterRect = this.getBoundingClientRect();
125
119
 
126
120
  const prevStartPosInParent = isHorizontal ? prevRect.left - parentRect.left : prevRect.top - parentRect.top;
127
121
  const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
@@ -130,24 +124,14 @@ class nxSplitter extends HTMLElement {
130
124
  const newPrevSize = finalDragBarPosInParent - prevStartPosInParent;
131
125
  const newNextSize = (isHorizontal ? nextRect.right : nextRect.bottom) - finalDragBarPosInParent - splitterThickness;
132
126
 
133
- const totalInitialSize = Array.from(parent.children)
134
- .filter(el => el.tagName.toLowerCase() !== 'nx-splitter')
135
- .reduce((sum, el) => {
136
- const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
137
- return sum + size;
138
- }, 0);
139
-
140
- const newTotalSize = totalInitialSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
127
+ const totalContentSize = allPanels.reduce((sum, el) => {
128
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
129
+ return sum + size;
130
+ }, 0);
141
131
 
142
- // 전체 패널의 새로운 Flex 비율을 계산하고 적용
143
- const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
144
-
145
- const newTotalFlex = allPanels.length;
132
+ const newTotalContentSize = totalContentSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
146
133
 
147
134
  allPanels.forEach(panel => {
148
-
149
- console.log(panel);
150
-
151
135
  const panelRect = panel.getBoundingClientRect();
152
136
  const currentSize = isHorizontal ? panelRect.width : panelRect.height;
153
137
 
@@ -155,10 +139,8 @@ class nxSplitter extends HTMLElement {
155
139
  if (panel === prev) newSize = newPrevSize;
156
140
  if (panel === next) newSize = newNextSize;
157
141
 
158
- const newFlexBasis = newSize / newTotalSize;
142
+ const newFlexBasis = newSize / newTotalContentSize;
159
143
  panel.style.flex = `${newFlexBasis} ${newFlexBasis} 0`;
160
-
161
- console.log(panel.style.flex);
162
144
  });
163
145
  };
164
146
 
@@ -166,7 +148,6 @@ class nxSplitter extends HTMLElement {
166
148
  window.addEventListener("mouseup", onUp);
167
149
  };
168
150
 
169
-
170
151
  #init = () => {
171
152
  this.#detectMode(this);
172
153
 
@@ -200,28 +181,25 @@ class nxSplitter extends HTMLElement {
200
181
  #prepareLayout = () => {
201
182
  const isHorizontal = this.#mode === "h";
202
183
  const parent = this.parentElement;
203
- const prev = this.previousElementSibling;
204
- const next = this.nextElementSibling;
205
- if (!prev || !next || !parent) return;
184
+ const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
185
+
186
+ if (allPanels.length < 2) return;
206
187
 
207
188
  const parentRect = parent.getBoundingClientRect();
208
- const currentPrevSize = isHorizontal ? prev.getBoundingClientRect().width : prev.getBoundingClientRect().height;
209
- const currentNextSize = isHorizontal ? next.getBoundingClientRect().width : next.getBoundingClientRect().height;
210
189
 
211
- const totalContentSize = Array.from(parent.children).reduce((sum, el) => {
212
- const rect = el.getBoundingClientRect();
213
- const size = isHorizontal ? rect.width : rect.height;
190
+ const totalContentSize = allPanels.reduce((sum, el) => {
191
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
214
192
  return sum + size;
215
193
  }, 0);
216
194
 
217
195
  const totalParentSize = isHorizontal ? parentRect.width : parentRect.height;
218
196
 
219
- // 리사이즈 시 비율 유지
220
- const newPrevSize = totalParentSize * (currentPrevSize / totalContentSize);
221
- const newNextSize = totalParentSize * (currentNextSize / totalContentSize);
222
-
223
- prev.style.flex = `0 0 ${newPrevSize}px`;
224
- next.style.flex = `0 0 ${newNextSize}px`;
197
+ allPanels.forEach(panel => {
198
+ const size = isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height;
199
+ const newSize = totalParentSize * (size / totalContentSize);
200
+ const flexGrow = newSize / totalParentSize;
201
+ panel.style.flex = `${flexGrow} ${flexGrow} 0`;
202
+ });
225
203
  };
226
204
  }
227
205
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ninegrid2",
3
3
  "type": "module",
4
- "version": "6.1021.0",
4
+ "version": "6.1023.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -2,8 +2,6 @@ import ninegrid from "../index.js";
2
2
 
3
3
  class nxSplitter extends HTMLElement {
4
4
  #mode;
5
- #originalPrevFlex;
6
- #originalNextFlex;
7
5
 
8
6
  constructor() {
9
7
  super();
@@ -30,7 +28,6 @@ class nxSplitter extends HTMLElement {
30
28
  } else if (this.classList.contains('v')) {
31
29
  this.#mode = "v";
32
30
  } else {
33
- // 형제 요소의 위치를 비교하여 모드를 감지
34
31
  this.#mode = (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
35
32
  }
36
33
  };
@@ -42,10 +39,6 @@ class nxSplitter extends HTMLElement {
42
39
  const splitterRect = this.getBoundingClientRect();
43
40
  const isHorizontal = this.#mode === "h";
44
41
 
45
- const clickOffset = isHorizontal
46
- ? e.clientX - splitterRect.left
47
- : e.clientY - splitterRect.top;
48
-
49
42
  const dragBar = document.createElement("div");
50
43
  dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
51
44
 
@@ -103,25 +96,26 @@ class nxSplitter extends HTMLElement {
103
96
  }
104
97
  };
105
98
 
106
- // #startDrag 메서드 내부 (수정된 onUp 함수)
107
99
  const onUp = () => {
108
100
  window.removeEventListener("mousemove", onMove);
109
101
  window.removeEventListener("mouseup", onUp);
110
102
  dragBar.remove();
111
103
 
104
+ const parent = this.parentElement;
105
+ const isHorizontal = this.#mode === "h";
106
+
107
+ // 모든 패널과 스플리터의 현재 크기를 가져옵니다.
108
+ const allChildren = Array.from(parent.children);
109
+ const allPanels = allChildren.filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
110
+
112
111
  const finalDragBarPosInParent = isHorizontal
113
112
  ? parseFloat(dragBar.style.left)
114
113
  : parseFloat(dragBar.style.top);
115
114
 
116
- const parent = this.parentElement;
117
115
  const parentRect = parent.getBoundingClientRect();
118
- const splitterRect = this.getBoundingClientRect();
119
- const prev = this.previousElementSibling;
120
- const next = this.nextElementSibling;
121
- const isHorizontal = this.#mode === "h";
122
-
123
116
  const prevRect = prev.getBoundingClientRect();
124
117
  const nextRect = next.getBoundingClientRect();
118
+ const splitterRect = this.getBoundingClientRect();
125
119
 
126
120
  const prevStartPosInParent = isHorizontal ? prevRect.left - parentRect.left : prevRect.top - parentRect.top;
127
121
  const splitterThickness = isHorizontal ? splitterRect.width : splitterRect.height;
@@ -130,24 +124,14 @@ class nxSplitter extends HTMLElement {
130
124
  const newPrevSize = finalDragBarPosInParent - prevStartPosInParent;
131
125
  const newNextSize = (isHorizontal ? nextRect.right : nextRect.bottom) - finalDragBarPosInParent - splitterThickness;
132
126
 
133
- const totalInitialSize = Array.from(parent.children)
134
- .filter(el => el.tagName.toLowerCase() !== 'nx-splitter')
135
- .reduce((sum, el) => {
136
- const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
137
- return sum + size;
138
- }, 0);
139
-
140
- const newTotalSize = totalInitialSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
127
+ const totalContentSize = allPanels.reduce((sum, el) => {
128
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
129
+ return sum + size;
130
+ }, 0);
141
131
 
142
- // 전체 패널의 새로운 Flex 비율을 계산하고 적용
143
- const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
144
-
145
- const newTotalFlex = allPanels.length;
132
+ const newTotalContentSize = totalContentSize - (isHorizontal ? prevRect.width + nextRect.width : prevRect.height + nextRect.height) + newPrevSize + newNextSize;
146
133
 
147
134
  allPanels.forEach(panel => {
148
-
149
- console.log(panel);
150
-
151
135
  const panelRect = panel.getBoundingClientRect();
152
136
  const currentSize = isHorizontal ? panelRect.width : panelRect.height;
153
137
 
@@ -155,10 +139,8 @@ class nxSplitter extends HTMLElement {
155
139
  if (panel === prev) newSize = newPrevSize;
156
140
  if (panel === next) newSize = newNextSize;
157
141
 
158
- const newFlexBasis = newSize / newTotalSize;
142
+ const newFlexBasis = newSize / newTotalContentSize;
159
143
  panel.style.flex = `${newFlexBasis} ${newFlexBasis} 0`;
160
-
161
- console.log(panel.style.flex);
162
144
  });
163
145
  };
164
146
 
@@ -166,7 +148,6 @@ class nxSplitter extends HTMLElement {
166
148
  window.addEventListener("mouseup", onUp);
167
149
  };
168
150
 
169
-
170
151
  #init = () => {
171
152
  this.#detectMode(this);
172
153
 
@@ -200,28 +181,25 @@ class nxSplitter extends HTMLElement {
200
181
  #prepareLayout = () => {
201
182
  const isHorizontal = this.#mode === "h";
202
183
  const parent = this.parentElement;
203
- const prev = this.previousElementSibling;
204
- const next = this.nextElementSibling;
205
- if (!prev || !next || !parent) return;
184
+ const allPanels = Array.from(parent.children).filter(el => el.tagName.toLowerCase() !== 'nx-splitter');
185
+
186
+ if (allPanels.length < 2) return;
206
187
 
207
188
  const parentRect = parent.getBoundingClientRect();
208
- const currentPrevSize = isHorizontal ? prev.getBoundingClientRect().width : prev.getBoundingClientRect().height;
209
- const currentNextSize = isHorizontal ? next.getBoundingClientRect().width : next.getBoundingClientRect().height;
210
189
 
211
- const totalContentSize = Array.from(parent.children).reduce((sum, el) => {
212
- const rect = el.getBoundingClientRect();
213
- const size = isHorizontal ? rect.width : rect.height;
190
+ const totalContentSize = allPanels.reduce((sum, el) => {
191
+ const size = isHorizontal ? el.getBoundingClientRect().width : el.getBoundingClientRect().height;
214
192
  return sum + size;
215
193
  }, 0);
216
194
 
217
195
  const totalParentSize = isHorizontal ? parentRect.width : parentRect.height;
218
196
 
219
- // 리사이즈 시 비율 유지
220
- const newPrevSize = totalParentSize * (currentPrevSize / totalContentSize);
221
- const newNextSize = totalParentSize * (currentNextSize / totalContentSize);
222
-
223
- prev.style.flex = `0 0 ${newPrevSize}px`;
224
- next.style.flex = `0 0 ${newNextSize}px`;
197
+ allPanels.forEach(panel => {
198
+ const size = isHorizontal ? panel.getBoundingClientRect().width : panel.getBoundingClientRect().height;
199
+ const newSize = totalParentSize * (size / totalContentSize);
200
+ const flexGrow = newSize / totalParentSize;
201
+ panel.style.flex = `${flexGrow} ${flexGrow} 0`;
202
+ });
225
203
  };
226
204
  }
227
205