@@ -11,10 +11,17 @@ const GAP_WIDTH = 10;
1111const PERCENT_100 = 100 ;
1212
1313const TOTAL_PERCENT = 100 ;
14+ const MAX_PANEL_WIDTH_RATIO = 0.8 ;
15+
16+ const { containerWidth } = defineProps ({
17+ containerWidth: { type: Number , required: true },
18+ });
1419
1520const treeviewStore = useTreeviewStore ();
1621const emit = defineEmits ([" show-menu" ]);
1722
23+ const maxWidth = computed (() => containerWidth * MAX_PANEL_WIDTH_RATIO );
24+
1825const mainView = computed (() => treeviewStore .opened_views [0 ]);
1926const additionalViews = computed (() => treeviewStore .opened_views .slice (1 ));
2027
@@ -41,6 +48,28 @@ watch(
4148 { immediate: true },
4249);
4350
51+ watch (maxWidth, (newMax ) => {
52+ const hasAdditional = additionalViews .value .length > 0 ;
53+ const gap = hasAdditional ? GAP_WIDTH : 0 ;
54+ const total =
55+ treeviewStore .panelWidth + (hasAdditional ? treeviewStore .additionalPanelWidth : 0 ) + gap;
56+
57+ if (total > newMax) {
58+ if (hasAdditional) {
59+ const newAdditionalWidth = newMax - treeviewStore .panelWidth - gap;
60+ if (newAdditionalWidth < WIDTH_MIN ) {
61+ treeviewStore .setAdditionalPanelWidth (WIDTH_MIN );
62+ const newMainWidth = newMax - WIDTH_MIN - gap;
63+ treeviewStore .setPanelWidth (Math .max (WIDTH_MIN , newMainWidth));
64+ } else {
65+ treeviewStore .setAdditionalPanelWidth (newAdditionalWidth);
66+ }
67+ } else {
68+ treeviewStore .setPanelWidth (Math .max (WIDTH_MIN , newMax));
69+ }
70+ }
71+ });
72+
4473function onDragStart (index ) {
4574 draggedIndex .value = index;
4675}
@@ -61,8 +90,15 @@ function onResizeStart(event) {
6190 const startX = event .clientX ;
6291 function resize (move_event ) {
6392 const deltaX = move_event .clientX - startX;
64- const newWidth = Math .max (WIDTH_MIN , startWidth + deltaX);
65- treeviewStore .setPanelWidth (newWidth);
93+ let newWidth = Math .max (WIDTH_MIN , startWidth + deltaX);
94+ const hasAdditional = additionalViews .value .length > 0 ;
95+ const gap = hasAdditional ? GAP_WIDTH : 0 ;
96+ const currentTotalWidth =
97+ newWidth + (hasAdditional ? treeviewStore .additionalPanelWidth : 0 ) + gap;
98+ if (currentTotalWidth > maxWidth .value ) {
99+ newWidth = maxWidth .value - (hasAdditional ? treeviewStore .additionalPanelWidth : 0 ) - gap;
100+ }
101+ treeviewStore .setPanelWidth (Math .max (WIDTH_MIN , newWidth));
66102 document .body .style .userSelect = " none" ;
67103 }
68104 function stopResize () {
@@ -79,8 +115,12 @@ function onAdditionalResizeStart(event) {
79115 const startX = event .clientX ;
80116 function resize (move_event ) {
81117 const deltaX = move_event .clientX - startX;
82- const newWidth = Math .max (WIDTH_MIN , startWidth + deltaX);
83- treeviewStore .setAdditionalPanelWidth (newWidth);
118+ let newWidth = Math .max (WIDTH_MIN , startWidth + deltaX);
119+ const currentTotalWidth = treeviewStore .panelWidth + newWidth + GAP_WIDTH ;
120+ if (currentTotalWidth > maxWidth .value ) {
121+ newWidth = maxWidth .value - treeviewStore .panelWidth - GAP_WIDTH ;
122+ }
123+ treeviewStore .setAdditionalPanelWidth (Math .max (WIDTH_MIN , newWidth));
84124 document .body .style .userSelect = " none" ;
85125 }
86126 function stopResize () {
0 commit comments