|
| 1 | +// Import Third-party Dependencies |
| 2 | +import { ResizeHandle } from "@jolly-pixel/resize-handle"; |
| 3 | + |
1 | 4 | // Import Internal Dependencies |
2 | 5 | import ThreeSceneManager from "./three/ThreeSceneManager.ts"; |
3 | 6 | import "./components/LeftPanel.ts"; |
4 | 7 | import "./components/RightPanel.ts"; |
5 | 8 | import "./components/PopupManager.ts"; |
6 | 9 | import "./components/popups/index.ts"; |
7 | | -import "./components/Resizer.ts"; |
8 | 10 |
|
9 | | -const kBody = document.querySelector("body") as HTMLBodyElement; |
10 | 11 | const leftPanel = document.querySelector("jolly-model-editor-left-panel") as HTMLElement; |
11 | 12 | const rightPanel = document.querySelector("jolly-model-editor-right-panel") as HTMLElement; |
12 | 13 | const popupManager = document.querySelector("jolly-popup-manager") as HTMLElement; |
@@ -34,53 +35,56 @@ requestAnimationFrame(function updateLoop() { |
34 | 35 | requestAnimationFrame(updateLoop); |
35 | 36 | }); |
36 | 37 |
|
37 | | -kBody.addEventListener("resizer", (e: Event) => { |
38 | | - const customEvent = e as CustomEvent; |
39 | | - const { delta, name } = customEvent.detail; |
40 | | - |
41 | | - function triggerManagerResize() { |
42 | | - threeSceneManager.onResize(); |
| 38 | +function triggerManagerResize() { |
| 39 | + threeSceneManager.onResize(); |
43 | 40 |
|
44 | | - // Essayer d'abord via le getSharedCanvasManager |
45 | | - const sharedManager = (leftPanel as any).getSharedCanvasManager?.(); |
46 | | - if (sharedManager) { |
47 | | - sharedManager.onResize(); |
48 | | - } |
49 | | - // Sinon, essayer via activeComponent |
50 | | - else { |
51 | | - const activeComponent = (leftPanel as any).getActiveComponent(); |
52 | | - if (activeComponent && activeComponent.canvasManagerInstance) { |
53 | | - activeComponent.canvasManagerInstance.onResize(); |
54 | | - } |
| 41 | + const sharedManager = (leftPanel as any).getSharedCanvasManager?.(); |
| 42 | + if (sharedManager) { |
| 43 | + sharedManager.onResize(); |
| 44 | + } |
| 45 | + else { |
| 46 | + const activeComponent = (leftPanel as any).getActiveComponent(); |
| 47 | + if (activeComponent && activeComponent.canvasManagerInstance) { |
| 48 | + activeComponent.canvasManagerInstance.onResize(); |
55 | 49 | } |
56 | 50 | } |
| 51 | +} |
57 | 52 |
|
58 | | - if (name === "leftPanel-threejs") { |
59 | | - const leftWidth = parseInt(getComputedStyle(leftPanel).width, 10); |
60 | | - const sectionWidth = parseInt(getComputedStyle(kSection).width, 10); |
61 | | - const newLeftWidth = leftWidth + delta; |
62 | | - const newSectionWidth = sectionWidth - delta; |
| 53 | +// direction "left" → handle div inserted AFTER leftPanel (between leftPanel and threeRenderer) |
| 54 | +// dragging right → leftPanel.style.width increases |
| 55 | +const leftResizeHandle = new ResizeHandle(leftPanel, { direction: "left" }); |
63 | 56 |
|
64 | | - if (newSectionWidth >= kMinWidth) { |
65 | | - leftPanel.style.width = `${newLeftWidth}px`; |
66 | | - triggerManagerResize(); |
67 | | - } |
| 57 | +leftResizeHandle.addEventListener("drag", () => { |
| 58 | + const sectionWidth = kSection.getBoundingClientRect().width; |
| 59 | + |
| 60 | + if (sectionWidth < kMinWidth) { |
| 61 | + const excess = kMinWidth - sectionWidth; |
| 62 | + leftPanel.style.width = `${parseInt(getComputedStyle(leftPanel).width, 10) - excess}px`; |
68 | 63 | } |
69 | | - else if (name === "threejs-rightPanel") { |
70 | | - const rightWidth = parseInt(getComputedStyle(rightPanel).width, 10); |
71 | | - const sectionWidth = parseInt(getComputedStyle(kSection).width, 10); |
72 | | - const newRightWidth = rightWidth - delta; |
73 | | - const newSectionWidth = sectionWidth + delta; |
74 | | - |
75 | | - if (newSectionWidth >= kMinWidth && newRightWidth >= kMinWidth) { |
76 | | - rightPanel.style.width = `${newRightWidth}px`; |
77 | | - triggerManagerResize(); |
78 | | - } |
| 64 | + |
| 65 | + triggerManagerResize(); |
| 66 | +}); |
| 67 | + |
| 68 | +// direction "right" → handle div inserted BEFORE rightPanel (between threeRenderer and rightPanel) |
| 69 | +// dragging left → rightPanel.style.width increases |
| 70 | +const rightResizeHandle = new ResizeHandle(rightPanel, { direction: "right" }); |
| 71 | + |
| 72 | +rightResizeHandle.addEventListener("drag", () => { |
| 73 | + const sectionWidth = kSection.getBoundingClientRect().width; |
| 74 | + const rightWidth = parseInt(getComputedStyle(rightPanel).width, 10); |
| 75 | + |
| 76 | + if (sectionWidth < kMinWidth) { |
| 77 | + const excess = kMinWidth - sectionWidth; |
| 78 | + rightPanel.style.width = `${rightWidth - excess}px`; |
| 79 | + } |
| 80 | + else if (rightWidth < kMinWidth) { |
| 81 | + rightPanel.style.width = `${kMinWidth}px`; |
79 | 82 | } |
| 83 | + |
| 84 | + triggerManagerResize(); |
80 | 85 | }); |
81 | 86 |
|
82 | 87 | rightPanel.addEventListener("addcube", (e: any) => { |
83 | 88 | const { name } = e.detail; |
84 | 89 | threeSceneManager.createCube(name); |
85 | 90 | }); |
86 | | - |
|
0 commit comments