|
109 | 109 | import WidgetsBar from './sidebar/Sidebar.svelte'
|
110 | 110 | import { sidebarStore, SidebarVariant, syncSidebarState } from '../sidebar'
|
111 | 111 | import { get } from 'svelte/store'
|
112 |
| - import type { Application, NavigatorModel, SpecialNavModel, ViewConfiguration, WorkbenchTab} from '@hcengineering/workbench'; |
| 112 | + import type { |
| 113 | + Application, |
| 114 | + NavigatorModel, |
| 115 | + SpecialNavModel, |
| 116 | + ViewConfiguration, |
| 117 | + WorkbenchTab |
| 118 | + } from '@hcengineering/workbench' |
113 | 119 |
|
114 | 120 | import {
|
115 | 121 | getTabDataByLocation,
|
|
120 | 126 | tabIdStore,
|
121 | 127 | tabsStore,
|
122 | 128 | updateTabUiState
|
123 |
| - } from '../workbench'; |
| 129 | + } from '../workbench' |
124 | 130 |
|
125 | 131 | const HIDE_NAVIGATOR = 720
|
126 | 132 | const FLOAT_ASIDE = 1024 // lg
|
|
250 | 256 | }
|
251 | 257 | }
|
252 | 258 |
|
253 |
| -let currentTabId: Ref<WorkbenchTab> | undefined = $tabIdStore; |
| 259 | + let currentTabId: Ref<WorkbenchTab> | undefined = $tabIdStore |
254 | 260 |
|
255 |
| -function saveScrollState() { |
256 |
| - if (!currentTabId || !contentPanel) { |
257 |
| - return; |
258 |
| - } |
| 261 | + function saveScrollState () { |
| 262 | + if (!currentTabId || !contentPanel) { |
| 263 | + return |
| 264 | + } |
259 | 265 |
|
260 |
| - const allScrollers = contentPanel.querySelectorAll<HTMLElement>('.scroll'); |
261 |
| - if (allScrollers.length === 0) { |
262 |
| - return; |
263 |
| - } |
264 |
| - |
265 |
| - console.log(`[SAVE] Tab ${currentTabId}. Found a total of ${allScrollers.length} elements with class .scroll.`); |
266 |
| -
|
267 |
| - const scrollableElements = Array.from(allScrollers).filter( |
268 |
| - (el) => el.scrollHeight > el.clientHeight |
269 |
| - ); |
270 |
| - |
271 |
| - console.log(`[SAVE] Of these, ${scrollableElements.length} are actually scrollable.`); |
272 |
| -
|
273 |
| - if (scrollableElements.length > 0) { |
274 |
| - const scrollPositions: Record<string, number> = {}; |
275 |
| - scrollableElements.forEach((scroller, index) => { |
276 |
| - const id = `index-${index}`; |
277 |
| - const scrollTop = scroller.scrollTop; |
278 |
| - scrollPositions[id] = scrollTop; |
279 |
| - console.log(`[SAVE] -> Saving for element #${id} ORIGINAL scrollTop value: ${scrollTop}`); |
280 |
| - }); |
281 |
| -
|
282 |
| - console.log('[SAVE] Final object to save:', scrollPositions); |
283 |
| - updateTabUiState(currentTabId, { scrollPositions }); |
284 |
| - } |
285 |
| -} |
| 266 | + const allScrollers = contentPanel.querySelectorAll<HTMLElement>('.scroll') |
| 267 | + if (allScrollers.length === 0) { |
| 268 | + return |
| 269 | + } |
286 | 270 |
|
287 |
| -async function restoreScrollState() { |
288 |
| - const tabId = $tabIdStore; |
289 |
| - if (!tabId || !contentPanel) { |
290 |
| - return; |
291 |
| - } |
| 271 | + console.log(`[SAVE] Tab ${currentTabId}. Found a total of ${allScrollers.length} elements with class .scroll.`) |
292 | 272 |
|
293 |
| - console.log('[RESTORE] Waiting for two ticks for components to render...'); |
294 |
| - await tick(); |
295 |
| - await tick(); |
| 273 | + const scrollableElements = Array.from(allScrollers).filter((el) => el.scrollHeight > el.clientHeight) |
296 | 274 |
|
297 |
| - const tab = get(tabsStore).find((t) => t._id === tabId); |
298 |
| - const savedScrollPositions = tab?.uiState?.scrollPositions; |
| 275 | + console.log(`[SAVE] Of these, ${scrollableElements.length} are actually scrollable.`) |
299 | 276 |
|
300 |
| - console.log(`[RESTORE] Tab ${tabId}. Found saved positions:`, savedScrollPositions); |
| 277 | + if (scrollableElements.length > 0) { |
| 278 | + const scrollPositions: Record<string, number> = {} |
| 279 | + scrollableElements.forEach((scroller, index) => { |
| 280 | + const id = `index-${index}` |
| 281 | + const scrollTop = scroller.scrollTop |
| 282 | + scrollPositions[id] = scrollTop |
| 283 | + console.log(`[SAVE] -> Saving for element #${id} ORIGINAL scrollTop value: ${scrollTop}`) |
| 284 | + }) |
301 | 285 |
|
302 |
| - if (!savedScrollPositions) { |
303 |
| - console.log('[RESTORE] Positions object is undefined, exiting.'); |
304 |
| - return; |
| 286 | + console.log('[SAVE] Final object to save:', scrollPositions) |
| 287 | + updateTabUiState(currentTabId, { scrollPositions }) |
| 288 | + } |
305 | 289 | }
|
306 | 290 |
|
307 |
| - if (Object.keys(savedScrollPositions).length === 0) { |
308 |
| - console.log('[RESTORE] No saved positions (object is empty), exiting.'); |
309 |
| - return; |
310 |
| - } |
311 |
| - |
312 |
| - const finalPositions = savedScrollPositions; |
313 |
| - const expectedCount = Object.keys(finalPositions).length; |
314 |
| - let attempts = 0; |
315 |
| - const maxAttempts = 100; |
316 |
| -
|
317 |
| - function findAndApplyScroll() { |
318 |
| - const allScrollers = contentPanel.querySelectorAll<HTMLElement>('.scroll'); |
319 |
| - const scrollableElements = Array.from(allScrollers).filter( |
320 |
| - (el) => el.scrollHeight > el.clientHeight |
321 |
| - ); |
322 |
| -
|
323 |
| - if (scrollableElements.length === expectedCount) { |
324 |
| - console.log(`[RESTORE] Success! Found ${scrollableElements.length} scrollable elements.`); |
325 |
| - |
326 |
| - scrollableElements.forEach((scroller, index) => { |
327 |
| - const id = `index-${index}`; |
328 |
| - const savedScrollTop = finalPositions[id]; |
| 291 | + async function restoreScrollState () { |
| 292 | + const tabId = $tabIdStore |
| 293 | + if (!tabId || !contentPanel) { |
| 294 | + return |
| 295 | + } |
329 | 296 |
|
330 |
| - if (savedScrollTop !== undefined) { |
331 |
| - console.log(`[RESTORE] -> Direct assignment of scroller.scrollTop = ${savedScrollTop} for element #${id}`); |
332 |
| - scroller.scrollTop = savedScrollTop; |
333 |
| - } |
334 |
| - }); |
335 |
| - return; |
| 297 | + console.log('[RESTORE] Waiting for two ticks for components to render...') |
| 298 | + await tick() |
| 299 | + await tick() |
| 300 | +
|
| 301 | + const tab = get(tabsStore).find((t) => t._id === tabId) |
| 302 | + const savedScrollPositions = tab?.uiState?.scrollPositions |
| 303 | +
|
| 304 | + console.log(`[RESTORE] Tab ${tabId}. Found saved positions:`, savedScrollPositions) |
| 305 | +
|
| 306 | + if (!savedScrollPositions) { |
| 307 | + console.log('[RESTORE] Positions object is undefined, exiting.') |
| 308 | + return |
336 | 309 | }
|
337 |
| - |
338 |
| - if (attempts < maxAttempts) { |
339 |
| - attempts++; |
340 |
| - requestAnimationFrame(findAndApplyScroll); |
341 |
| - } else { |
342 |
| - console.error(`[RESTORE] FAILED to wait for content to load in .scroll after ${maxAttempts} attempts.`); |
| 310 | +
|
| 311 | + if (Object.keys(savedScrollPositions).length === 0) { |
| 312 | + console.log('[RESTORE] No saved positions (object is empty), exiting.') |
| 313 | + return |
343 | 314 | }
|
344 |
| - } |
345 | 315 |
|
346 |
| - findAndApplyScroll(); |
347 |
| -} |
| 316 | + const finalPositions = savedScrollPositions |
| 317 | + const expectedCount = Object.keys(finalPositions).length |
| 318 | + let attempts = 0 |
| 319 | + const maxAttempts = 100 |
| 320 | +
|
| 321 | + function findAndApplyScroll () { |
| 322 | + const allScrollers = contentPanel.querySelectorAll<HTMLElement>('.scroll') |
| 323 | + const scrollableElements = Array.from(allScrollers).filter((el) => el.scrollHeight > el.clientHeight) |
348 | 324 |
|
349 |
| -$: { |
350 |
| - if (currentTabId !== $tabIdStore) { |
351 |
| - console.log(`%c[SWITCH] Tab changed. Old: ${currentTabId}, New: ${$tabIdStore}`, 'color: blue; font-weight: bold;'); |
| 325 | + if (scrollableElements.length === expectedCount) { |
| 326 | + console.log(`[RESTORE] Success! Found ${scrollableElements.length} scrollable elements.`) |
352 | 327 |
|
353 |
| - saveScrollState(); |
354 |
| - void restoreScrollState(); |
355 |
| - currentTabId = $tabIdStore; |
| 328 | + scrollableElements.forEach((scroller, index) => { |
| 329 | + const id = `index-${index}` |
| 330 | + const savedScrollTop = finalPositions[id] |
| 331 | +
|
| 332 | + if (savedScrollTop !== undefined) { |
| 333 | + console.log(`[RESTORE] -> Direct assignment of scroller.scrollTop = ${savedScrollTop} for element #${id}`) |
| 334 | + scroller.scrollTop = savedScrollTop |
| 335 | + } |
| 336 | + }) |
| 337 | + return |
| 338 | + } |
| 339 | +
|
| 340 | + if (attempts < maxAttempts) { |
| 341 | + attempts++ |
| 342 | + requestAnimationFrame(findAndApplyScroll) |
| 343 | + } else { |
| 344 | + console.error(`[RESTORE] FAILED to wait for content to load in .scroll after ${maxAttempts} attempts.`) |
| 345 | + } |
| 346 | + } |
| 347 | +
|
| 348 | + findAndApplyScroll() |
| 349 | + } |
| 350 | +
|
| 351 | + $: { |
| 352 | + if (currentTabId !== $tabIdStore) { |
| 353 | + console.log( |
| 354 | + `%c[SWITCH] Tab changed. Old: ${currentTabId}, New: ${$tabIdStore}`, |
| 355 | + 'color: blue; font-weight: bold;' |
| 356 | + ) |
| 357 | +
|
| 358 | + saveScrollState() |
| 359 | + void restoreScrollState() |
| 360 | + currentTabId = $tabIdStore |
| 361 | + } |
356 | 362 | }
|
357 |
| -} |
358 | 363 |
|
359 | 364 | onMount(() => {
|
360 | 365 | pushRootBarComponent('right', view.component.SearchSelector)
|
@@ -1098,46 +1103,46 @@ $: {
|
1098 | 1103 | !(mobileAdaptive && $deviceInfo.isPortrait)}
|
1099 | 1104 | data-id={'contentPanel'}
|
1100 | 1105 | >
|
1101 |
| - {#if currentApplication && currentApplication.component} |
1102 |
| - <Component |
1103 |
| - is={currentApplication.component} |
1104 |
| - props={{ |
1105 |
| - currentSpace, |
1106 |
| - workbenchWidth |
1107 |
| - }} |
1108 |
| - /> |
1109 |
| - {:else if specialComponent} |
1110 |
| - <Component |
1111 |
| - is={specialComponent.component} |
1112 |
| - props={{ |
1113 |
| - model: navigatorModel, |
1114 |
| - ...specialComponent.componentProps, |
1115 |
| - currentSpace, |
1116 |
| - space: currentSpace, |
1117 |
| - navigationModel: specialComponent?.navigationModel, |
1118 |
| - workbenchWidth, |
1119 |
| - queryBuilder: specialComponent?.queryBuilder |
1120 |
| - }} |
1121 |
| - on:action={(e) => { |
1122 |
| - if (e?.detail) { |
1123 |
| - const loc = getCurrentLocation() |
1124 |
| - loc.query = { ...loc.query, ...e.detail } |
1125 |
| - navigate(loc) |
1126 |
| - } |
1127 |
| - }} |
1128 |
| - /> |
1129 |
| - {:else if currentView?.component !== undefined} |
1130 |
| - <Component |
1131 |
| - is={currentView.component} |
| 1106 | + {#if currentApplication && currentApplication.component} |
| 1107 | + <Component |
| 1108 | + is={currentApplication.component} |
| 1109 | + props={{ |
| 1110 | + currentSpace, |
| 1111 | + workbenchWidth |
| 1112 | + }} |
| 1113 | + /> |
| 1114 | + {:else if specialComponent} |
| 1115 | + <Component |
| 1116 | + is={specialComponent.component} |
| 1117 | + props={{ |
| 1118 | + model: navigatorModel, |
| 1119 | + ...specialComponent.componentProps, |
| 1120 | + currentSpace, |
| 1121 | + space: currentSpace, |
| 1122 | + navigationModel: specialComponent?.navigationModel, |
| 1123 | + workbenchWidth, |
| 1124 | + queryBuilder: specialComponent?.queryBuilder |
| 1125 | + }} |
| 1126 | + on:action={(e) => { |
| 1127 | + if (e?.detail) { |
| 1128 | + const loc = getCurrentLocation() |
| 1129 | + loc.query = { ...loc.query, ...e.detail } |
| 1130 | + navigate(loc) |
| 1131 | + } |
| 1132 | + }} |
| 1133 | + /> |
| 1134 | + {:else if currentView?.component !== undefined} |
| 1135 | + <Component |
| 1136 | + is={currentView.component} |
1132 | 1137 | props={{ ...currentView.componentProps, currentSpace, currentView, workbenchWidth }}
|
1133 |
| - /> |
1134 |
| - {:else if $accessDeniedStore} |
1135 |
| - <div class="flex-center h-full"> |
1136 |
| - <h2><Label label={workbench.string.AccessDenied} /></h2> |
1137 |
| - </div> |
1138 |
| - {:else} |
1139 |
| - <SpaceView {currentSpace} {currentView} {createItemDialog} {createItemLabel} /> |
1140 |
| - {/if} |
| 1138 | + /> |
| 1139 | + {:else if $accessDeniedStore} |
| 1140 | + <div class="flex-center h-full"> |
| 1141 | + <h2><Label label={workbench.string.AccessDenied} /></h2> |
| 1142 | + </div> |
| 1143 | + {:else} |
| 1144 | + <SpaceView {currentSpace} {currentView} {createItemDialog} {createItemLabel} /> |
| 1145 | + {/if} |
1141 | 1146 | </div>
|
1142 | 1147 | </div>
|
1143 | 1148 | {#if $sidebarStore.variant === SidebarVariant.EXPANDED && !$sidebarStore.float}
|
|
0 commit comments