@@ -107,19 +107,56 @@ const SCROLL_CONTAINER_ID = 'scroll-container';
107107
108108const { editorSize, ifexViewerSize, startResizing } = useEditorResizing (codemirrorInstance );
109109
110+ const calculateSizes = () => {
111+ const parentElement = document .getElementById (SCROLL_CONTAINER_ID )?.parentElement ;
112+ if (parentElement ) {
113+ const parentWidth = parentElement .offsetWidth ;
114+ const totalGap = 70 ; // Total gap/padding (35px each side)
115+ const availableWidth = parentWidth - totalGap ;
116+
117+ // If sizes haven't been set yet, use 50/50 split
118+ if (editorSize .value === 0 && ifexViewerSize .value === 0 ) {
119+ editorSize .value = availableWidth / 2 ;
120+ ifexViewerSize .value = availableWidth / 2 ;
121+ } else {
122+ // Maintain the current ratio when resizing
123+ const currentTotal = editorSize .value + ifexViewerSize .value ;
124+ if (currentTotal > 0 ) {
125+ const editorRatio = editorSize .value / currentTotal ;
126+ editorSize .value = availableWidth * editorRatio ;
127+ ifexViewerSize .value = availableWidth * (1 - editorRatio );
128+ } else {
129+ // Fallback to 50/50 if something went wrong
130+ editorSize .value = availableWidth / 2 ;
131+ ifexViewerSize .value = availableWidth / 2 ;
132+ }
133+ }
134+ }
135+ };
136+
137+ let resizeTimeout: ReturnType <typeof setTimeout > | null = null ;
138+
139+ const handleWindowResize = () => {
140+ // Debounce the resize calculation to avoid excessive recalculations
141+ if (resizeTimeout ) {
142+ clearTimeout (resizeTimeout );
143+ }
144+ resizeTimeout = setTimeout (() => {
145+ calculateSizes ();
146+ resizeTimeout = null ;
147+ }, 100 );
148+ };
149+
110150onMounted (() => {
111151 // Workaround for lazy loading web components in SSR
112152 import (' ../../dist/ifex-viewer.es.js' ).then (() => {
113153 mounted .value = true ;
114154 });
115155
116- const parentElement = document .getElementById (SCROLL_CONTAINER_ID )?.parentElement ;
117- if (parentElement ) {
118- const parentWidth = parentElement .offsetWidth ;
119- editorSize .value = parentWidth / 2 - 35 ; // 50% - 2rem (32px) - 3px
120-
121- ifexViewerSize .value = parentWidth / 2 - 35 ; // 50% - 2rem (32px) - 3px
122- }
156+ calculateSizes ();
157+
158+ // Add window resize listener
159+ window .addEventListener (' resize' , handleWindowResize );
123160
124161 const initialEditorState = EditorState .create ({
125162 doc: simpleSpecificationMock ,
@@ -151,6 +188,15 @@ onBeforeUnmount(() => {
151188 if (view .value ) {
152189 view .value .destroy ();
153190 }
191+
192+ // Remove window resize listener
193+ window .removeEventListener (' resize' , handleWindowResize );
194+
195+ // Clear any pending resize timeout
196+ if (resizeTimeout ) {
197+ clearTimeout (resizeTimeout );
198+ resizeTimeout = null ;
199+ }
154200});
155201
156202watch (errorMap , newErrorMap => {
0 commit comments