ninegrid2 6.850.0 → 6.852.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 +145 -8
- package/dist/bundle.esm.js +145 -8
- package/dist/nx/nxSplitter.js +145 -8
- package/package.json +1 -1
- package/src/nx/nxSplitter.js +145 -8
package/dist/bundle.cjs.js
CHANGED
|
@@ -121167,7 +121167,7 @@ class nxSplitter extends HTMLElement {
|
|
|
121167
121167
|
this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
|
|
121168
121168
|
};
|
|
121169
121169
|
|
|
121170
|
-
#
|
|
121170
|
+
#startDrag_BAK = (e) => {
|
|
121171
121171
|
|
|
121172
121172
|
e.preventDefault(); // 기본 drag/select 동작 제거
|
|
121173
121173
|
e.stopPropagation();
|
|
@@ -121207,21 +121207,18 @@ class nxSplitter extends HTMLElement {
|
|
|
121207
121207
|
parseFloat(computedStyle.paddingLeft) || 0;
|
|
121208
121208
|
const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
|
|
121209
121209
|
|
|
121210
|
+
|
|
121210
121211
|
let el = parent;
|
|
121211
121212
|
let totalPadding = 0;
|
|
121212
121213
|
|
|
121213
121214
|
while (el) {
|
|
121214
|
-
console.log(el, el
|
|
121215
|
+
console.log(el, el.parentElement, el.host);
|
|
121215
121216
|
if (el instanceof Element) {
|
|
121216
121217
|
const style = getComputedStyle(el);
|
|
121217
121218
|
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
121218
|
-
el = el.
|
|
121219
|
+
el = el.parentElement;
|
|
121219
121220
|
} else if (el instanceof ShadowRoot) {
|
|
121220
|
-
|
|
121221
|
-
const host = el.host;
|
|
121222
|
-
const style = getComputedStyle(host);
|
|
121223
|
-
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
121224
|
-
el = host.offsetParent;
|
|
121221
|
+
el = el.host;
|
|
121225
121222
|
} else {
|
|
121226
121223
|
break;
|
|
121227
121224
|
}
|
|
@@ -121229,6 +121226,7 @@ class nxSplitter extends HTMLElement {
|
|
|
121229
121226
|
|
|
121230
121227
|
|
|
121231
121228
|
|
|
121229
|
+
|
|
121232
121230
|
console.log(totalPadding, e.clientX, parentRect.left);
|
|
121233
121231
|
|
|
121234
121232
|
const left = e.clientX - parentRect.left + totalPadding;
|
|
@@ -121316,6 +121314,145 @@ class nxSplitter extends HTMLElement {
|
|
|
121316
121314
|
window.addEventListener("mouseup", onUp);
|
|
121317
121315
|
};
|
|
121318
121316
|
|
|
121317
|
+
#startDrag = (e) => {
|
|
121318
|
+
e.preventDefault();
|
|
121319
|
+
e.stopPropagation();
|
|
121320
|
+
|
|
121321
|
+
const splitterRect = this.getBoundingClientRect();
|
|
121322
|
+
const isHorizontal = this.#mode === "h";
|
|
121323
|
+
|
|
121324
|
+
// 클릭 지점에서 스플리터 경계까지의 오프셋
|
|
121325
|
+
isHorizontal
|
|
121326
|
+
? e.clientX - splitterRect.left
|
|
121327
|
+
: e.clientY - splitterRect.top;
|
|
121328
|
+
|
|
121329
|
+
const dragBar = document.createElement("div");
|
|
121330
|
+
dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
|
|
121331
|
+
Object.assign(dragBar.style, {
|
|
121332
|
+
position: "absolute",
|
|
121333
|
+
zIndex: "999",
|
|
121334
|
+
background: "#666",
|
|
121335
|
+
opacity: "0.6",
|
|
121336
|
+
pointerEvents: "none"
|
|
121337
|
+
});
|
|
121338
|
+
|
|
121339
|
+
const root = this.getRootNode({ composed: true });
|
|
121340
|
+
// parent는 스플리터의 직접적인 컨테이너 (flex 컨테이너 역할)
|
|
121341
|
+
const parent = root instanceof ShadowRoot ? root.host : this.parentElement;
|
|
121342
|
+
|
|
121343
|
+
const prev = this.previousElementSibling;
|
|
121344
|
+
const next = this.nextElementSibling;
|
|
121345
|
+
|
|
121346
|
+
if (!parent || !prev || !next) {
|
|
121347
|
+
console.warn("Spliter's parent or siblings not found.");
|
|
121348
|
+
return;
|
|
121349
|
+
}
|
|
121350
|
+
|
|
121351
|
+
const parentRect = parent.getBoundingClientRect();
|
|
121352
|
+
const prevRect = prev.getBoundingClientRect();
|
|
121353
|
+
const nextRect = next.getBoundingClientRect();
|
|
121354
|
+
|
|
121355
|
+
// dragBar의 초기 위치 설정 (parent 기준)
|
|
121356
|
+
// padding을 고려하지 않고 parentRect를 기준으로 하는 것이 일반적이며,
|
|
121357
|
+
// 스플리터 컨테이너의 flex-basis가 padding을 포함하는지 여부에 따라 조절.
|
|
121358
|
+
// 여기서는 parent의 content-box 기준으로 relative 위치를 계산.
|
|
121359
|
+
let initialPos;
|
|
121360
|
+
if (isHorizontal) {
|
|
121361
|
+
initialPos = e.clientX - parentRect.left;
|
|
121362
|
+
dragBar.style.top = "0";
|
|
121363
|
+
dragBar.style.left = `${initialPos}px`;
|
|
121364
|
+
dragBar.style.width = "1px";
|
|
121365
|
+
dragBar.style.height = "100%";
|
|
121366
|
+
} else {
|
|
121367
|
+
initialPos = e.clientY - parentRect.top;
|
|
121368
|
+
dragBar.style.left = "0";
|
|
121369
|
+
dragBar.style.top = `${initialPos}px`;
|
|
121370
|
+
dragBar.style.height = "1px";
|
|
121371
|
+
dragBar.style.width = "100%";
|
|
121372
|
+
}
|
|
121373
|
+
|
|
121374
|
+
// Shadow DOM이 있다면 ShadowRoot에, 아니면 일반 DOM에 삽입
|
|
121375
|
+
(parent.shadowRoot || parent).appendChild(dragBar);
|
|
121376
|
+
|
|
121377
|
+
// 드래그 가능한 범위 (부모 요소 내에서 이전/다음 엘리먼트의 실제 경계 기준)
|
|
121378
|
+
const minLimit = isHorizontal ? prevRect.left : prevRect.top;
|
|
121379
|
+
const maxLimit = isHorizontal ? nextRect.right : nextRect.bottom;
|
|
121380
|
+
|
|
121381
|
+
const onMove = moveEvent => {
|
|
121382
|
+
const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
|
|
121383
|
+
// 드래그 바가 부모 영역을 벗어나지 않도록 클램프
|
|
121384
|
+
const clampedPos = Math.max(minLimit, Math.min(clientPos, maxLimit));
|
|
121385
|
+
|
|
121386
|
+
// 부모 기준으로 드래그 바의 상대 위치
|
|
121387
|
+
const relativePos = clampedPos - parentRect[isHorizontal ? "left" : "top"];
|
|
121388
|
+
|
|
121389
|
+
if (isHorizontal) {
|
|
121390
|
+
dragBar.style.left = `${relativePos}px`;
|
|
121391
|
+
} else {
|
|
121392
|
+
dragBar.style.top = `${relativePos}px`;
|
|
121393
|
+
}
|
|
121394
|
+
};
|
|
121395
|
+
|
|
121396
|
+
const onUp = upEvent => {
|
|
121397
|
+
window.removeEventListener("mousemove", onMove);
|
|
121398
|
+
window.removeEventListener("mouseup", onUp);
|
|
121399
|
+
dragBar.remove();
|
|
121400
|
+
|
|
121401
|
+
// 최종 드래그 바의 위치를 기준으로 새 크기 계산
|
|
121402
|
+
const finalDragBarPos = isHorizontal
|
|
121403
|
+
? parseFloat(dragBar.style.left)
|
|
121404
|
+
: parseFloat(dragBar.style.top);
|
|
121405
|
+
|
|
121406
|
+
// 이전 요소의 새로운 크기 (부모의 좌측/상단 경계부터 드래그 바까지)
|
|
121407
|
+
const newPrevSize = finalDragBarPos;
|
|
121408
|
+
|
|
121409
|
+
// 다음 요소의 새로운 크기 (부모의 전체 크기에서 이전 요소 크기를 뺀 값)
|
|
121410
|
+
const parentTotalSize = isHorizontal ? parentRect.width : parentRect.height;
|
|
121411
|
+
const newNextSize = parentTotalSize - newPrevSize;
|
|
121412
|
+
|
|
121413
|
+
// 최소/최대 크기 제약 (예: 1px 미만으로 작아지지 않도록)
|
|
121414
|
+
const MIN_PANEL_SIZE = 1; // 패널 최소 크기
|
|
121415
|
+
let finalPrevSize = Math.max(MIN_PANEL_SIZE, newPrevSize);
|
|
121416
|
+
let finalNextSize = Math.max(MIN_PANEL_SIZE, newNextSize);
|
|
121417
|
+
|
|
121418
|
+
// flex 레이아웃에 직접 width/height를 부여하는 대신 flex-basis를 사용하거나
|
|
121419
|
+
// flex-grow 비율을 재조정하는 것이 일반적이나, 현재 flex: none; 으로 제어하는 방식을 유지한다면,
|
|
121420
|
+
// 이와 같이 직접 style.width/height를 설정.
|
|
121421
|
+
// 하지만 flex 컨테이너 내부에서는 flex-basis를 설정하는 것이 더 바람직합니다.
|
|
121422
|
+
// 여기서는 기존 코드의 스타일 설정을 유지하면서 값을 정확히 계산.
|
|
121423
|
+
|
|
121424
|
+
// flex-grow 비율로 제어하는 경우
|
|
121425
|
+
// const currentTotalFlex = parseFloat(getComputedStyle(prev).flexGrow || 0) + parseFloat(getComputedStyle(next).flexGrow || 0);
|
|
121426
|
+
// prev.style.flexGrow = (newPrevSize / parentTotalSize) * currentTotalFlex;
|
|
121427
|
+
// next.style.flexGrow = (newNextSize / parentTotalSize) * currentTotalFlex;
|
|
121428
|
+
|
|
121429
|
+
// 기존 flex 값을 저장하고 복원
|
|
121430
|
+
const originalPrevFlex = prev.style.flex;
|
|
121431
|
+
const originalNextFlex = next.style.flex;
|
|
121432
|
+
|
|
121433
|
+
// 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
|
|
121434
|
+
prev.style.flex = "none";
|
|
121435
|
+
next.style.flex = "none";
|
|
121436
|
+
|
|
121437
|
+
if (isHorizontal) {
|
|
121438
|
+
prev.style.width = `${finalPrevSize}px`;
|
|
121439
|
+
next.style.width = `${finalNextSize}px`;
|
|
121440
|
+
} else {
|
|
121441
|
+
prev.style.height = `${finalPrevSize}px`;
|
|
121442
|
+
next.style.height = `${finalNextSize}px`;
|
|
121443
|
+
}
|
|
121444
|
+
|
|
121445
|
+
// 작업 완료 후 원래 flex 값으로 복원
|
|
121446
|
+
// 단, width/height가 설정된 경우 flex 속성이 다시 적용되면 겹칠 수 있으므로 주의 필요.
|
|
121447
|
+
// 일반적으로 flex-basis를 사용하거나, width/height 설정 후 flex-grow/shrink를 기본값으로 돌리는 것을 고려.
|
|
121448
|
+
prev.style.flex = originalPrevFlex;
|
|
121449
|
+
next.style.flex = originalNextFlex;
|
|
121450
|
+
};
|
|
121451
|
+
|
|
121452
|
+
window.addEventListener("mousemove", onMove);
|
|
121453
|
+
window.addEventListener("mouseup", onUp);
|
|
121454
|
+
};
|
|
121455
|
+
|
|
121319
121456
|
|
|
121320
121457
|
#init = () => {
|
|
121321
121458
|
this.#detectMode(this);
|
package/dist/bundle.esm.js
CHANGED
|
@@ -121163,7 +121163,7 @@ class nxSplitter extends HTMLElement {
|
|
|
121163
121163
|
this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
|
|
121164
121164
|
};
|
|
121165
121165
|
|
|
121166
|
-
#
|
|
121166
|
+
#startDrag_BAK = (e) => {
|
|
121167
121167
|
|
|
121168
121168
|
e.preventDefault(); // 기본 drag/select 동작 제거
|
|
121169
121169
|
e.stopPropagation();
|
|
@@ -121203,21 +121203,18 @@ class nxSplitter extends HTMLElement {
|
|
|
121203
121203
|
parseFloat(computedStyle.paddingLeft) || 0;
|
|
121204
121204
|
const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
|
|
121205
121205
|
|
|
121206
|
+
|
|
121206
121207
|
let el = parent;
|
|
121207
121208
|
let totalPadding = 0;
|
|
121208
121209
|
|
|
121209
121210
|
while (el) {
|
|
121210
|
-
console.log(el, el
|
|
121211
|
+
console.log(el, el.parentElement, el.host);
|
|
121211
121212
|
if (el instanceof Element) {
|
|
121212
121213
|
const style = getComputedStyle(el);
|
|
121213
121214
|
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
121214
|
-
el = el.
|
|
121215
|
+
el = el.parentElement;
|
|
121215
121216
|
} else if (el instanceof ShadowRoot) {
|
|
121216
|
-
|
|
121217
|
-
const host = el.host;
|
|
121218
|
-
const style = getComputedStyle(host);
|
|
121219
|
-
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
121220
|
-
el = host.offsetParent;
|
|
121217
|
+
el = el.host;
|
|
121221
121218
|
} else {
|
|
121222
121219
|
break;
|
|
121223
121220
|
}
|
|
@@ -121225,6 +121222,7 @@ class nxSplitter extends HTMLElement {
|
|
|
121225
121222
|
|
|
121226
121223
|
|
|
121227
121224
|
|
|
121225
|
+
|
|
121228
121226
|
console.log(totalPadding, e.clientX, parentRect.left);
|
|
121229
121227
|
|
|
121230
121228
|
const left = e.clientX - parentRect.left + totalPadding;
|
|
@@ -121312,6 +121310,145 @@ class nxSplitter extends HTMLElement {
|
|
|
121312
121310
|
window.addEventListener("mouseup", onUp);
|
|
121313
121311
|
};
|
|
121314
121312
|
|
|
121313
|
+
#startDrag = (e) => {
|
|
121314
|
+
e.preventDefault();
|
|
121315
|
+
e.stopPropagation();
|
|
121316
|
+
|
|
121317
|
+
const splitterRect = this.getBoundingClientRect();
|
|
121318
|
+
const isHorizontal = this.#mode === "h";
|
|
121319
|
+
|
|
121320
|
+
// 클릭 지점에서 스플리터 경계까지의 오프셋
|
|
121321
|
+
isHorizontal
|
|
121322
|
+
? e.clientX - splitterRect.left
|
|
121323
|
+
: e.clientY - splitterRect.top;
|
|
121324
|
+
|
|
121325
|
+
const dragBar = document.createElement("div");
|
|
121326
|
+
dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
|
|
121327
|
+
Object.assign(dragBar.style, {
|
|
121328
|
+
position: "absolute",
|
|
121329
|
+
zIndex: "999",
|
|
121330
|
+
background: "#666",
|
|
121331
|
+
opacity: "0.6",
|
|
121332
|
+
pointerEvents: "none"
|
|
121333
|
+
});
|
|
121334
|
+
|
|
121335
|
+
const root = this.getRootNode({ composed: true });
|
|
121336
|
+
// parent는 스플리터의 직접적인 컨테이너 (flex 컨테이너 역할)
|
|
121337
|
+
const parent = root instanceof ShadowRoot ? root.host : this.parentElement;
|
|
121338
|
+
|
|
121339
|
+
const prev = this.previousElementSibling;
|
|
121340
|
+
const next = this.nextElementSibling;
|
|
121341
|
+
|
|
121342
|
+
if (!parent || !prev || !next) {
|
|
121343
|
+
console.warn("Spliter's parent or siblings not found.");
|
|
121344
|
+
return;
|
|
121345
|
+
}
|
|
121346
|
+
|
|
121347
|
+
const parentRect = parent.getBoundingClientRect();
|
|
121348
|
+
const prevRect = prev.getBoundingClientRect();
|
|
121349
|
+
const nextRect = next.getBoundingClientRect();
|
|
121350
|
+
|
|
121351
|
+
// dragBar의 초기 위치 설정 (parent 기준)
|
|
121352
|
+
// padding을 고려하지 않고 parentRect를 기준으로 하는 것이 일반적이며,
|
|
121353
|
+
// 스플리터 컨테이너의 flex-basis가 padding을 포함하는지 여부에 따라 조절.
|
|
121354
|
+
// 여기서는 parent의 content-box 기준으로 relative 위치를 계산.
|
|
121355
|
+
let initialPos;
|
|
121356
|
+
if (isHorizontal) {
|
|
121357
|
+
initialPos = e.clientX - parentRect.left;
|
|
121358
|
+
dragBar.style.top = "0";
|
|
121359
|
+
dragBar.style.left = `${initialPos}px`;
|
|
121360
|
+
dragBar.style.width = "1px";
|
|
121361
|
+
dragBar.style.height = "100%";
|
|
121362
|
+
} else {
|
|
121363
|
+
initialPos = e.clientY - parentRect.top;
|
|
121364
|
+
dragBar.style.left = "0";
|
|
121365
|
+
dragBar.style.top = `${initialPos}px`;
|
|
121366
|
+
dragBar.style.height = "1px";
|
|
121367
|
+
dragBar.style.width = "100%";
|
|
121368
|
+
}
|
|
121369
|
+
|
|
121370
|
+
// Shadow DOM이 있다면 ShadowRoot에, 아니면 일반 DOM에 삽입
|
|
121371
|
+
(parent.shadowRoot || parent).appendChild(dragBar);
|
|
121372
|
+
|
|
121373
|
+
// 드래그 가능한 범위 (부모 요소 내에서 이전/다음 엘리먼트의 실제 경계 기준)
|
|
121374
|
+
const minLimit = isHorizontal ? prevRect.left : prevRect.top;
|
|
121375
|
+
const maxLimit = isHorizontal ? nextRect.right : nextRect.bottom;
|
|
121376
|
+
|
|
121377
|
+
const onMove = moveEvent => {
|
|
121378
|
+
const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
|
|
121379
|
+
// 드래그 바가 부모 영역을 벗어나지 않도록 클램프
|
|
121380
|
+
const clampedPos = Math.max(minLimit, Math.min(clientPos, maxLimit));
|
|
121381
|
+
|
|
121382
|
+
// 부모 기준으로 드래그 바의 상대 위치
|
|
121383
|
+
const relativePos = clampedPos - parentRect[isHorizontal ? "left" : "top"];
|
|
121384
|
+
|
|
121385
|
+
if (isHorizontal) {
|
|
121386
|
+
dragBar.style.left = `${relativePos}px`;
|
|
121387
|
+
} else {
|
|
121388
|
+
dragBar.style.top = `${relativePos}px`;
|
|
121389
|
+
}
|
|
121390
|
+
};
|
|
121391
|
+
|
|
121392
|
+
const onUp = upEvent => {
|
|
121393
|
+
window.removeEventListener("mousemove", onMove);
|
|
121394
|
+
window.removeEventListener("mouseup", onUp);
|
|
121395
|
+
dragBar.remove();
|
|
121396
|
+
|
|
121397
|
+
// 최종 드래그 바의 위치를 기준으로 새 크기 계산
|
|
121398
|
+
const finalDragBarPos = isHorizontal
|
|
121399
|
+
? parseFloat(dragBar.style.left)
|
|
121400
|
+
: parseFloat(dragBar.style.top);
|
|
121401
|
+
|
|
121402
|
+
// 이전 요소의 새로운 크기 (부모의 좌측/상단 경계부터 드래그 바까지)
|
|
121403
|
+
const newPrevSize = finalDragBarPos;
|
|
121404
|
+
|
|
121405
|
+
// 다음 요소의 새로운 크기 (부모의 전체 크기에서 이전 요소 크기를 뺀 값)
|
|
121406
|
+
const parentTotalSize = isHorizontal ? parentRect.width : parentRect.height;
|
|
121407
|
+
const newNextSize = parentTotalSize - newPrevSize;
|
|
121408
|
+
|
|
121409
|
+
// 최소/최대 크기 제약 (예: 1px 미만으로 작아지지 않도록)
|
|
121410
|
+
const MIN_PANEL_SIZE = 1; // 패널 최소 크기
|
|
121411
|
+
let finalPrevSize = Math.max(MIN_PANEL_SIZE, newPrevSize);
|
|
121412
|
+
let finalNextSize = Math.max(MIN_PANEL_SIZE, newNextSize);
|
|
121413
|
+
|
|
121414
|
+
// flex 레이아웃에 직접 width/height를 부여하는 대신 flex-basis를 사용하거나
|
|
121415
|
+
// flex-grow 비율을 재조정하는 것이 일반적이나, 현재 flex: none; 으로 제어하는 방식을 유지한다면,
|
|
121416
|
+
// 이와 같이 직접 style.width/height를 설정.
|
|
121417
|
+
// 하지만 flex 컨테이너 내부에서는 flex-basis를 설정하는 것이 더 바람직합니다.
|
|
121418
|
+
// 여기서는 기존 코드의 스타일 설정을 유지하면서 값을 정확히 계산.
|
|
121419
|
+
|
|
121420
|
+
// flex-grow 비율로 제어하는 경우
|
|
121421
|
+
// const currentTotalFlex = parseFloat(getComputedStyle(prev).flexGrow || 0) + parseFloat(getComputedStyle(next).flexGrow || 0);
|
|
121422
|
+
// prev.style.flexGrow = (newPrevSize / parentTotalSize) * currentTotalFlex;
|
|
121423
|
+
// next.style.flexGrow = (newNextSize / parentTotalSize) * currentTotalFlex;
|
|
121424
|
+
|
|
121425
|
+
// 기존 flex 값을 저장하고 복원
|
|
121426
|
+
const originalPrevFlex = prev.style.flex;
|
|
121427
|
+
const originalNextFlex = next.style.flex;
|
|
121428
|
+
|
|
121429
|
+
// 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
|
|
121430
|
+
prev.style.flex = "none";
|
|
121431
|
+
next.style.flex = "none";
|
|
121432
|
+
|
|
121433
|
+
if (isHorizontal) {
|
|
121434
|
+
prev.style.width = `${finalPrevSize}px`;
|
|
121435
|
+
next.style.width = `${finalNextSize}px`;
|
|
121436
|
+
} else {
|
|
121437
|
+
prev.style.height = `${finalPrevSize}px`;
|
|
121438
|
+
next.style.height = `${finalNextSize}px`;
|
|
121439
|
+
}
|
|
121440
|
+
|
|
121441
|
+
// 작업 완료 후 원래 flex 값으로 복원
|
|
121442
|
+
// 단, width/height가 설정된 경우 flex 속성이 다시 적용되면 겹칠 수 있으므로 주의 필요.
|
|
121443
|
+
// 일반적으로 flex-basis를 사용하거나, width/height 설정 후 flex-grow/shrink를 기본값으로 돌리는 것을 고려.
|
|
121444
|
+
prev.style.flex = originalPrevFlex;
|
|
121445
|
+
next.style.flex = originalNextFlex;
|
|
121446
|
+
};
|
|
121447
|
+
|
|
121448
|
+
window.addEventListener("mousemove", onMove);
|
|
121449
|
+
window.addEventListener("mouseup", onUp);
|
|
121450
|
+
};
|
|
121451
|
+
|
|
121315
121452
|
|
|
121316
121453
|
#init = () => {
|
|
121317
121454
|
this.#detectMode(this);
|
package/dist/nx/nxSplitter.js
CHANGED
|
@@ -22,7 +22,7 @@ class nxSplitter extends HTMLElement {
|
|
|
22
22
|
this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
#
|
|
25
|
+
#startDrag_BAK = (e) => {
|
|
26
26
|
|
|
27
27
|
e.preventDefault(); // 기본 drag/select 동작 제거
|
|
28
28
|
e.stopPropagation();
|
|
@@ -62,21 +62,18 @@ class nxSplitter extends HTMLElement {
|
|
|
62
62
|
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
|
|
63
63
|
const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
|
|
64
64
|
|
|
65
|
+
|
|
65
66
|
let el = parent;
|
|
66
67
|
let totalPadding = 0;
|
|
67
68
|
|
|
68
69
|
while (el) {
|
|
69
|
-
console.log(el, el
|
|
70
|
+
console.log(el, el.parentElement, el.host)
|
|
70
71
|
if (el instanceof Element) {
|
|
71
72
|
const style = getComputedStyle(el);
|
|
72
73
|
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
73
|
-
el = el.
|
|
74
|
+
el = el.parentElement;
|
|
74
75
|
} else if (el instanceof ShadowRoot) {
|
|
75
|
-
|
|
76
|
-
const host = el.host;
|
|
77
|
-
const style = getComputedStyle(host);
|
|
78
|
-
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
79
|
-
el = host.offsetParent;
|
|
76
|
+
el = el.host;
|
|
80
77
|
} else {
|
|
81
78
|
break;
|
|
82
79
|
}
|
|
@@ -84,6 +81,7 @@ class nxSplitter extends HTMLElement {
|
|
|
84
81
|
|
|
85
82
|
|
|
86
83
|
|
|
84
|
+
|
|
87
85
|
console.log(totalPadding, e.clientX, parentRect.left);
|
|
88
86
|
|
|
89
87
|
const left = e.clientX - parentRect.left + totalPadding;
|
|
@@ -171,6 +169,145 @@ class nxSplitter extends HTMLElement {
|
|
|
171
169
|
window.addEventListener("mouseup", onUp);
|
|
172
170
|
};
|
|
173
171
|
|
|
172
|
+
#startDrag = (e) => {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
e.stopPropagation();
|
|
175
|
+
|
|
176
|
+
const splitterRect = this.getBoundingClientRect();
|
|
177
|
+
const isHorizontal = this.#mode === "h";
|
|
178
|
+
|
|
179
|
+
// 클릭 지점에서 스플리터 경계까지의 오프셋
|
|
180
|
+
const clickOffset = isHorizontal
|
|
181
|
+
? e.clientX - splitterRect.left
|
|
182
|
+
: e.clientY - splitterRect.top;
|
|
183
|
+
|
|
184
|
+
const dragBar = document.createElement("div");
|
|
185
|
+
dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
|
|
186
|
+
Object.assign(dragBar.style, {
|
|
187
|
+
position: "absolute",
|
|
188
|
+
zIndex: "999",
|
|
189
|
+
background: "#666",
|
|
190
|
+
opacity: "0.6",
|
|
191
|
+
pointerEvents: "none"
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const root = this.getRootNode({ composed: true });
|
|
195
|
+
// parent는 스플리터의 직접적인 컨테이너 (flex 컨테이너 역할)
|
|
196
|
+
const parent = root instanceof ShadowRoot ? root.host : this.parentElement;
|
|
197
|
+
|
|
198
|
+
const prev = this.previousElementSibling;
|
|
199
|
+
const next = this.nextElementSibling;
|
|
200
|
+
|
|
201
|
+
if (!parent || !prev || !next) {
|
|
202
|
+
console.warn("Spliter's parent or siblings not found.");
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const parentRect = parent.getBoundingClientRect();
|
|
207
|
+
const prevRect = prev.getBoundingClientRect();
|
|
208
|
+
const nextRect = next.getBoundingClientRect();
|
|
209
|
+
|
|
210
|
+
// dragBar의 초기 위치 설정 (parent 기준)
|
|
211
|
+
// padding을 고려하지 않고 parentRect를 기준으로 하는 것이 일반적이며,
|
|
212
|
+
// 스플리터 컨테이너의 flex-basis가 padding을 포함하는지 여부에 따라 조절.
|
|
213
|
+
// 여기서는 parent의 content-box 기준으로 relative 위치를 계산.
|
|
214
|
+
let initialPos;
|
|
215
|
+
if (isHorizontal) {
|
|
216
|
+
initialPos = e.clientX - parentRect.left;
|
|
217
|
+
dragBar.style.top = "0";
|
|
218
|
+
dragBar.style.left = `${initialPos}px`;
|
|
219
|
+
dragBar.style.width = "1px";
|
|
220
|
+
dragBar.style.height = "100%";
|
|
221
|
+
} else {
|
|
222
|
+
initialPos = e.clientY - parentRect.top;
|
|
223
|
+
dragBar.style.left = "0";
|
|
224
|
+
dragBar.style.top = `${initialPos}px`;
|
|
225
|
+
dragBar.style.height = "1px";
|
|
226
|
+
dragBar.style.width = "100%";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Shadow DOM이 있다면 ShadowRoot에, 아니면 일반 DOM에 삽입
|
|
230
|
+
(parent.shadowRoot || parent).appendChild(dragBar);
|
|
231
|
+
|
|
232
|
+
// 드래그 가능한 범위 (부모 요소 내에서 이전/다음 엘리먼트의 실제 경계 기준)
|
|
233
|
+
const minLimit = isHorizontal ? prevRect.left : prevRect.top;
|
|
234
|
+
const maxLimit = isHorizontal ? nextRect.right : nextRect.bottom;
|
|
235
|
+
|
|
236
|
+
const onMove = moveEvent => {
|
|
237
|
+
const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
|
|
238
|
+
// 드래그 바가 부모 영역을 벗어나지 않도록 클램프
|
|
239
|
+
const clampedPos = Math.max(minLimit, Math.min(clientPos, maxLimit));
|
|
240
|
+
|
|
241
|
+
// 부모 기준으로 드래그 바의 상대 위치
|
|
242
|
+
const relativePos = clampedPos - parentRect[isHorizontal ? "left" : "top"];
|
|
243
|
+
|
|
244
|
+
if (isHorizontal) {
|
|
245
|
+
dragBar.style.left = `${relativePos}px`;
|
|
246
|
+
} else {
|
|
247
|
+
dragBar.style.top = `${relativePos}px`;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const onUp = upEvent => {
|
|
252
|
+
window.removeEventListener("mousemove", onMove);
|
|
253
|
+
window.removeEventListener("mouseup", onUp);
|
|
254
|
+
dragBar.remove();
|
|
255
|
+
|
|
256
|
+
// 최종 드래그 바의 위치를 기준으로 새 크기 계산
|
|
257
|
+
const finalDragBarPos = isHorizontal
|
|
258
|
+
? parseFloat(dragBar.style.left)
|
|
259
|
+
: parseFloat(dragBar.style.top);
|
|
260
|
+
|
|
261
|
+
// 이전 요소의 새로운 크기 (부모의 좌측/상단 경계부터 드래그 바까지)
|
|
262
|
+
const newPrevSize = finalDragBarPos;
|
|
263
|
+
|
|
264
|
+
// 다음 요소의 새로운 크기 (부모의 전체 크기에서 이전 요소 크기를 뺀 값)
|
|
265
|
+
const parentTotalSize = isHorizontal ? parentRect.width : parentRect.height;
|
|
266
|
+
const newNextSize = parentTotalSize - newPrevSize;
|
|
267
|
+
|
|
268
|
+
// 최소/최대 크기 제약 (예: 1px 미만으로 작아지지 않도록)
|
|
269
|
+
const MIN_PANEL_SIZE = 1; // 패널 최소 크기
|
|
270
|
+
let finalPrevSize = Math.max(MIN_PANEL_SIZE, newPrevSize);
|
|
271
|
+
let finalNextSize = Math.max(MIN_PANEL_SIZE, newNextSize);
|
|
272
|
+
|
|
273
|
+
// flex 레이아웃에 직접 width/height를 부여하는 대신 flex-basis를 사용하거나
|
|
274
|
+
// flex-grow 비율을 재조정하는 것이 일반적이나, 현재 flex: none; 으로 제어하는 방식을 유지한다면,
|
|
275
|
+
// 이와 같이 직접 style.width/height를 설정.
|
|
276
|
+
// 하지만 flex 컨테이너 내부에서는 flex-basis를 설정하는 것이 더 바람직합니다.
|
|
277
|
+
// 여기서는 기존 코드의 스타일 설정을 유지하면서 값을 정확히 계산.
|
|
278
|
+
|
|
279
|
+
// flex-grow 비율로 제어하는 경우
|
|
280
|
+
// const currentTotalFlex = parseFloat(getComputedStyle(prev).flexGrow || 0) + parseFloat(getComputedStyle(next).flexGrow || 0);
|
|
281
|
+
// prev.style.flexGrow = (newPrevSize / parentTotalSize) * currentTotalFlex;
|
|
282
|
+
// next.style.flexGrow = (newNextSize / parentTotalSize) * currentTotalFlex;
|
|
283
|
+
|
|
284
|
+
// 기존 flex 값을 저장하고 복원
|
|
285
|
+
const originalPrevFlex = prev.style.flex;
|
|
286
|
+
const originalNextFlex = next.style.flex;
|
|
287
|
+
|
|
288
|
+
// 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
|
|
289
|
+
prev.style.flex = "none";
|
|
290
|
+
next.style.flex = "none";
|
|
291
|
+
|
|
292
|
+
if (isHorizontal) {
|
|
293
|
+
prev.style.width = `${finalPrevSize}px`;
|
|
294
|
+
next.style.width = `${finalNextSize}px`;
|
|
295
|
+
} else {
|
|
296
|
+
prev.style.height = `${finalPrevSize}px`;
|
|
297
|
+
next.style.height = `${finalNextSize}px`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 작업 완료 후 원래 flex 값으로 복원
|
|
301
|
+
// 단, width/height가 설정된 경우 flex 속성이 다시 적용되면 겹칠 수 있으므로 주의 필요.
|
|
302
|
+
// 일반적으로 flex-basis를 사용하거나, width/height 설정 후 flex-grow/shrink를 기본값으로 돌리는 것을 고려.
|
|
303
|
+
prev.style.flex = originalPrevFlex;
|
|
304
|
+
next.style.flex = originalNextFlex;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
window.addEventListener("mousemove", onMove);
|
|
308
|
+
window.addEventListener("mouseup", onUp);
|
|
309
|
+
};
|
|
310
|
+
|
|
174
311
|
|
|
175
312
|
#init = () => {
|
|
176
313
|
this.#detectMode(this);
|
package/package.json
CHANGED
package/src/nx/nxSplitter.js
CHANGED
|
@@ -22,7 +22,7 @@ class nxSplitter extends HTMLElement {
|
|
|
22
22
|
this.#mode = (!prevRect || !nextRect) || (Math.abs(prevRect.top - nextRect.top) < 5) ? "h" : "v";
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
#
|
|
25
|
+
#startDrag_BAK = (e) => {
|
|
26
26
|
|
|
27
27
|
e.preventDefault(); // 기본 drag/select 동작 제거
|
|
28
28
|
e.stopPropagation();
|
|
@@ -62,21 +62,18 @@ class nxSplitter extends HTMLElement {
|
|
|
62
62
|
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
|
|
63
63
|
const paddingTop = parseFloat(computedStyle.paddingTop) || 0;
|
|
64
64
|
|
|
65
|
+
|
|
65
66
|
let el = parent;
|
|
66
67
|
let totalPadding = 0;
|
|
67
68
|
|
|
68
69
|
while (el) {
|
|
69
|
-
console.log(el, el
|
|
70
|
+
console.log(el, el.parentElement, el.host)
|
|
70
71
|
if (el instanceof Element) {
|
|
71
72
|
const style = getComputedStyle(el);
|
|
72
73
|
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
73
|
-
el = el.
|
|
74
|
+
el = el.parentElement;
|
|
74
75
|
} else if (el instanceof ShadowRoot) {
|
|
75
|
-
|
|
76
|
-
const host = el.host;
|
|
77
|
-
const style = getComputedStyle(host);
|
|
78
|
-
totalPadding += parseFloat(style.paddingLeft) || 0;
|
|
79
|
-
el = host.offsetParent;
|
|
76
|
+
el = el.host;
|
|
80
77
|
} else {
|
|
81
78
|
break;
|
|
82
79
|
}
|
|
@@ -84,6 +81,7 @@ class nxSplitter extends HTMLElement {
|
|
|
84
81
|
|
|
85
82
|
|
|
86
83
|
|
|
84
|
+
|
|
87
85
|
console.log(totalPadding, e.clientX, parentRect.left);
|
|
88
86
|
|
|
89
87
|
const left = e.clientX - parentRect.left + totalPadding;
|
|
@@ -171,6 +169,145 @@ class nxSplitter extends HTMLElement {
|
|
|
171
169
|
window.addEventListener("mouseup", onUp);
|
|
172
170
|
};
|
|
173
171
|
|
|
172
|
+
#startDrag = (e) => {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
e.stopPropagation();
|
|
175
|
+
|
|
176
|
+
const splitterRect = this.getBoundingClientRect();
|
|
177
|
+
const isHorizontal = this.#mode === "h";
|
|
178
|
+
|
|
179
|
+
// 클릭 지점에서 스플리터 경계까지의 오프셋
|
|
180
|
+
const clickOffset = isHorizontal
|
|
181
|
+
? e.clientX - splitterRect.left
|
|
182
|
+
: e.clientY - splitterRect.top;
|
|
183
|
+
|
|
184
|
+
const dragBar = document.createElement("div");
|
|
185
|
+
dragBar.className = `nx-splitter-drag-bar-${this.#mode}`;
|
|
186
|
+
Object.assign(dragBar.style, {
|
|
187
|
+
position: "absolute",
|
|
188
|
+
zIndex: "999",
|
|
189
|
+
background: "#666",
|
|
190
|
+
opacity: "0.6",
|
|
191
|
+
pointerEvents: "none"
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const root = this.getRootNode({ composed: true });
|
|
195
|
+
// parent는 스플리터의 직접적인 컨테이너 (flex 컨테이너 역할)
|
|
196
|
+
const parent = root instanceof ShadowRoot ? root.host : this.parentElement;
|
|
197
|
+
|
|
198
|
+
const prev = this.previousElementSibling;
|
|
199
|
+
const next = this.nextElementSibling;
|
|
200
|
+
|
|
201
|
+
if (!parent || !prev || !next) {
|
|
202
|
+
console.warn("Spliter's parent or siblings not found.");
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const parentRect = parent.getBoundingClientRect();
|
|
207
|
+
const prevRect = prev.getBoundingClientRect();
|
|
208
|
+
const nextRect = next.getBoundingClientRect();
|
|
209
|
+
|
|
210
|
+
// dragBar의 초기 위치 설정 (parent 기준)
|
|
211
|
+
// padding을 고려하지 않고 parentRect를 기준으로 하는 것이 일반적이며,
|
|
212
|
+
// 스플리터 컨테이너의 flex-basis가 padding을 포함하는지 여부에 따라 조절.
|
|
213
|
+
// 여기서는 parent의 content-box 기준으로 relative 위치를 계산.
|
|
214
|
+
let initialPos;
|
|
215
|
+
if (isHorizontal) {
|
|
216
|
+
initialPos = e.clientX - parentRect.left;
|
|
217
|
+
dragBar.style.top = "0";
|
|
218
|
+
dragBar.style.left = `${initialPos}px`;
|
|
219
|
+
dragBar.style.width = "1px";
|
|
220
|
+
dragBar.style.height = "100%";
|
|
221
|
+
} else {
|
|
222
|
+
initialPos = e.clientY - parentRect.top;
|
|
223
|
+
dragBar.style.left = "0";
|
|
224
|
+
dragBar.style.top = `${initialPos}px`;
|
|
225
|
+
dragBar.style.height = "1px";
|
|
226
|
+
dragBar.style.width = "100%";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Shadow DOM이 있다면 ShadowRoot에, 아니면 일반 DOM에 삽입
|
|
230
|
+
(parent.shadowRoot || parent).appendChild(dragBar);
|
|
231
|
+
|
|
232
|
+
// 드래그 가능한 범위 (부모 요소 내에서 이전/다음 엘리먼트의 실제 경계 기준)
|
|
233
|
+
const minLimit = isHorizontal ? prevRect.left : prevRect.top;
|
|
234
|
+
const maxLimit = isHorizontal ? nextRect.right : nextRect.bottom;
|
|
235
|
+
|
|
236
|
+
const onMove = moveEvent => {
|
|
237
|
+
const clientPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;
|
|
238
|
+
// 드래그 바가 부모 영역을 벗어나지 않도록 클램프
|
|
239
|
+
const clampedPos = Math.max(minLimit, Math.min(clientPos, maxLimit));
|
|
240
|
+
|
|
241
|
+
// 부모 기준으로 드래그 바의 상대 위치
|
|
242
|
+
const relativePos = clampedPos - parentRect[isHorizontal ? "left" : "top"];
|
|
243
|
+
|
|
244
|
+
if (isHorizontal) {
|
|
245
|
+
dragBar.style.left = `${relativePos}px`;
|
|
246
|
+
} else {
|
|
247
|
+
dragBar.style.top = `${relativePos}px`;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const onUp = upEvent => {
|
|
252
|
+
window.removeEventListener("mousemove", onMove);
|
|
253
|
+
window.removeEventListener("mouseup", onUp);
|
|
254
|
+
dragBar.remove();
|
|
255
|
+
|
|
256
|
+
// 최종 드래그 바의 위치를 기준으로 새 크기 계산
|
|
257
|
+
const finalDragBarPos = isHorizontal
|
|
258
|
+
? parseFloat(dragBar.style.left)
|
|
259
|
+
: parseFloat(dragBar.style.top);
|
|
260
|
+
|
|
261
|
+
// 이전 요소의 새로운 크기 (부모의 좌측/상단 경계부터 드래그 바까지)
|
|
262
|
+
const newPrevSize = finalDragBarPos;
|
|
263
|
+
|
|
264
|
+
// 다음 요소의 새로운 크기 (부모의 전체 크기에서 이전 요소 크기를 뺀 값)
|
|
265
|
+
const parentTotalSize = isHorizontal ? parentRect.width : parentRect.height;
|
|
266
|
+
const newNextSize = parentTotalSize - newPrevSize;
|
|
267
|
+
|
|
268
|
+
// 최소/최대 크기 제약 (예: 1px 미만으로 작아지지 않도록)
|
|
269
|
+
const MIN_PANEL_SIZE = 1; // 패널 최소 크기
|
|
270
|
+
let finalPrevSize = Math.max(MIN_PANEL_SIZE, newPrevSize);
|
|
271
|
+
let finalNextSize = Math.max(MIN_PANEL_SIZE, newNextSize);
|
|
272
|
+
|
|
273
|
+
// flex 레이아웃에 직접 width/height를 부여하는 대신 flex-basis를 사용하거나
|
|
274
|
+
// flex-grow 비율을 재조정하는 것이 일반적이나, 현재 flex: none; 으로 제어하는 방식을 유지한다면,
|
|
275
|
+
// 이와 같이 직접 style.width/height를 설정.
|
|
276
|
+
// 하지만 flex 컨테이너 내부에서는 flex-basis를 설정하는 것이 더 바람직합니다.
|
|
277
|
+
// 여기서는 기존 코드의 스타일 설정을 유지하면서 값을 정확히 계산.
|
|
278
|
+
|
|
279
|
+
// flex-grow 비율로 제어하는 경우
|
|
280
|
+
// const currentTotalFlex = parseFloat(getComputedStyle(prev).flexGrow || 0) + parseFloat(getComputedStyle(next).flexGrow || 0);
|
|
281
|
+
// prev.style.flexGrow = (newPrevSize / parentTotalSize) * currentTotalFlex;
|
|
282
|
+
// next.style.flexGrow = (newNextSize / parentTotalSize) * currentTotalFlex;
|
|
283
|
+
|
|
284
|
+
// 기존 flex 값을 저장하고 복원
|
|
285
|
+
const originalPrevFlex = prev.style.flex;
|
|
286
|
+
const originalNextFlex = next.style.flex;
|
|
287
|
+
|
|
288
|
+
// 드래그 중에는 flex를 "none"으로 설정하여 직접 크기 조절
|
|
289
|
+
prev.style.flex = "none";
|
|
290
|
+
next.style.flex = "none";
|
|
291
|
+
|
|
292
|
+
if (isHorizontal) {
|
|
293
|
+
prev.style.width = `${finalPrevSize}px`;
|
|
294
|
+
next.style.width = `${finalNextSize}px`;
|
|
295
|
+
} else {
|
|
296
|
+
prev.style.height = `${finalPrevSize}px`;
|
|
297
|
+
next.style.height = `${finalNextSize}px`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 작업 완료 후 원래 flex 값으로 복원
|
|
301
|
+
// 단, width/height가 설정된 경우 flex 속성이 다시 적용되면 겹칠 수 있으므로 주의 필요.
|
|
302
|
+
// 일반적으로 flex-basis를 사용하거나, width/height 설정 후 flex-grow/shrink를 기본값으로 돌리는 것을 고려.
|
|
303
|
+
prev.style.flex = originalPrevFlex;
|
|
304
|
+
next.style.flex = originalNextFlex;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
window.addEventListener("mousemove", onMove);
|
|
308
|
+
window.addEventListener("mouseup", onUp);
|
|
309
|
+
};
|
|
310
|
+
|
|
174
311
|
|
|
175
312
|
#init = () => {
|
|
176
313
|
this.#detectMode(this);
|