11<template >
2- <BlockUI ref =" blockUiRef " class =" opencor overflow-hidden h-full" :class =" isFullWebApp ? 'with-main-menu' : ''"
3- :blocked =" blockUiBlocked "
2+ <SafeBlockUI ref =" safeBlockUiRef " class =" opencor overflow-hidden h-full" :class =" isFullWebApp ? 'with-main-menu' : ''"
3+ :blocked =" compBlockUiEnabled "
44 @click =" activateInstance"
55 @focus =" activateInstance"
66 @focusin =" activateInstance"
9898 @close =" webUpdateAvailableVisible = false"
9999 />
100100 </div >
101- </BlockUI >
101+ </SafeBlockUI >
102102</template >
103103
104104<script setup lang="ts">
@@ -110,7 +110,6 @@ import firebase from 'firebase/compat/app';
110110import 'firebase/compat/auth';
111111import { Octokit } from 'octokit';
112112*/
113- import BlockUI from ' primevue/blockui' ;
114113import primeVueConfig from ' primevue/config' ;
115114import primeVueConfirmationService from ' primevue/confirmationservice' ;
116115import primeVueToastService from ' primevue/toastservice' ;
@@ -122,7 +121,7 @@ import type { IOpenCOREmits, IOpenCORProps } from '../../index.ts';
122121import ' ../assets/app.css' ;
123122import ' ../assets/primeicons-assets.ts' ;
124123import * as common from ' ../common/common.ts' ;
125- import { FULL_URI_SCHEME , LONG_DELAY , NO_DELAY , SHORT_DELAY , TOAST_LIFE } from ' ../common/constants.ts' ;
124+ import { FULL_URI_SCHEME , LONG_DELAY , SHORT_DELAY , TOAST_LIFE } from ' ../common/constants.ts' ;
126125import * as dependencies from ' ../common/dependencies.ts' ;
127126import { electronApi } from ' ../common/electronApi.ts' ;
128127/* TODO: enable once our GitHub integration is fully ready.
@@ -136,6 +135,7 @@ import ContentsComponent from '../components/ContentsComponent.vue';
136135import * as locApi from ' ../libopencor/locApi.ts' ;
137136
138137import { provideDialogState } from ' ./dialogs/BaseDialog.vue' ;
138+ import SafeBlockUI from ' ./widgets/SafeBlockUI.vue' ;
139139import MainMenu from ' ./MainMenu.vue' ;
140140
141141const props = defineProps <IOpenCORProps >();
@@ -191,7 +191,7 @@ const emitSimulationData = (): void => {
191191
192192const { isDialogActive } = provideDialogState ();
193193
194- const blockUiRef = vue .ref <InstanceType <typeof BlockUI > | null >(null );
194+ const safeBlockUiRef = vue .ref <InstanceType <typeof SafeBlockUI > | null >(null );
195195const mainMenuRef = vue .ref <InstanceType <typeof MainMenu > | null >(null );
196196const filesRef = vue .ref <HTMLElement | null >(null );
197197const contentsRef = vue .ref <InstanceType <typeof ContentsComponent > | null >(null );
@@ -247,35 +247,25 @@ const compUiEnabled = vue.computed<boolean>(() => {
247247 return ! compBlockUiEnabled .value && ! isDialogActive .value ;
248248});
249249
250- // Block/unblock the UI with "no" (i.e. a bit of a) delay to ensure that it doesn't happen too quickly (e.g., when
251- // loading a model from a COMBINE archive, we don't want the UI to be blocked for a split second while the file is
252- // being processed and the Simulation Experiment view is being shown in isolation).
253-
254- const blockUiBlocked = vue .ref <boolean >(true );
255- let blockUiBlockedTimeoutId: number | undefined ;
250+ // Remove any leftover SafeBlockUI masks when unblocking.
251+ // Note: this is to ensure that we don't end up with leftover masks if the block event is emitted multiple times before
252+ // the unblock event is emitted, which can lead to multiple masks being created and not properly removed.
256253
257254vue .watch (
258255 compBlockUiEnabled ,
259256 (newCompBlockUiEnabled : boolean ) => {
260- if (blockUiBlockedTimeoutId !== undefined ) {
261- window .clearTimeout (blockUiBlockedTimeoutId );
257+ if (! newCompBlockUiEnabled ) {
258+ const safeBlockUi = safeBlockUiRef .value as unknown as InstanceType <typeof SafeBlockUI > | null ;
259+ const safeBlockUiRoot = safeBlockUi ?.$el as HTMLElement | undefined ;
262260
263- blockUiBlockedTimeoutId = undefined ;
261+ for (const mask of safeBlockUiRoot ?.querySelectorAll (' .p-blockui-mask' ) ?? []) {
262+ mask .remove ();
263+ }
264264 }
265-
266- blockUiBlockedTimeoutId = window .setTimeout (() => {
267- blockUiBlocked .value = newCompBlockUiEnabled ;
268- }, NO_DELAY );
269265 },
270266 { immediate: true }
271267);
272268
273- vue .onUnmounted (() => {
274- if (blockUiBlockedTimeoutId !== undefined ) {
275- window .clearTimeout (blockUiBlockedTimeoutId );
276- }
277- });
278-
279269// Determine whether we are running the full Web app (i.e. not in isolation).
280270
281271const isFullWebApp = vue .computed <boolean >(() => {
@@ -898,7 +888,7 @@ electronApi?.onSelect((filePath: string) => {
898888// A few things that can only be done when the component is mounted.
899889
900890vue .onMounted (() => {
901- const blockUiElement = (blockUiRef .value as unknown as { $el: HTMLElement })?.$el ;
891+ const safeBlockUiElement = (safeBlockUiRef .value as unknown as { $el: HTMLElement })?.$el ;
902892
903893 // Make ourselves the active instance.
904894
@@ -911,8 +901,8 @@ vue.onMounted(() => {
911901 setTimeout (() => {
912902 const toastElement = document .getElementById (toastId .value );
913903
914- if (toastElement && blockUiElement && toastElement .parentElement !== blockUiElement ) {
915- blockUiElement .appendChild (toastElement );
904+ if (toastElement && safeBlockUiElement && toastElement .parentElement !== safeBlockUiElement ) {
905+ safeBlockUiElement .appendChild (toastElement );
916906 }
917907 }, SHORT_DELAY );
918908});
@@ -928,10 +918,14 @@ vue.onMounted(() => {
928918
929919 void vue .nextTick (() => {
930920 const mainMenuElement = (mainMenuRef .value as unknown as { $el: HTMLElement })?.$el ;
931- const blockUiElement = (blockUiRef .value as unknown as { $el: HTMLElement })?.$el ;
932-
933- if (mainMenuElement && blockUiElement ) {
934- stopTrackingMainMenuHeight = vueCommon .trackElementHeight (mainMenuElement , blockUiElement , ' --main-menu-height' );
921+ const safeBlockUiElement = (safeBlockUiRef .value as unknown as { $el: HTMLElement })?.$el ;
922+
923+ if (mainMenuElement && safeBlockUiElement ) {
924+ stopTrackingMainMenuHeight = vueCommon .trackElementHeight (
925+ mainMenuElement ,
926+ safeBlockUiElement ,
927+ ' --main-menu-height'
928+ );
935929 }
936930 });
937931});
0 commit comments