Drop popupVisibilityNames/viewModelName in favor of the new visiblePopups Set

This commit is contained in:
djmaze 2021-09-22 13:37:12 +02:00
parent 1d29a281b4
commit 11f69ef9e4
3 changed files with 17 additions and 21 deletions

View file

@ -8,18 +8,15 @@ import { ViewType } from 'Knoin/Knoin';
class AbstractView {
constructor(name, templateID, type)
{
this.viewModelName = 'View/' + name;
this.viewModelTemplateID = templateID;
this.viewModelPosition = type;
this.bDisabeCloseOnEsc = false;
this.sDefaultScope = Scope.None;
this.sCurrentScope = Scope.None;
this.viewModelVisible = false;
this.modalVisibility = ko.observable(false).extend({ rateLimit: 0 });
this.viewModelName = '';
this.viewModelDom = null;
}
@ -64,6 +61,7 @@ export class AbstractViewPopup extends AbstractView
if (name in Scope) {
this.sDefaultScope = Scope[name];
}
this.bDisabeCloseOnEsc = false;
}
/*
cancelCommand() {}

View file

@ -4,7 +4,6 @@ import { doc, $htmlCL } from 'Common/Globals';
import { arrayLength, isFunction } from 'Common/Utils';
let currentScreen = null,
visiblePopups = new Set,
defaultScreenName = '';
const SCREENS = {},
@ -13,6 +12,8 @@ const SCREENS = {},
af && af.focus();
},
visiblePopups = new Set,
/**
* @param {string} screenName
* @returns {?Object}
@ -62,10 +63,10 @@ const SCREENS = {},
vm.modalVisibility.subscribe(value => {
if (value) {
visiblePopups.add(vm);
vmDom.style.zIndex = 3000 + popupVisibilityNames().length + 10;
vmDom.style.zIndex = 3000 + visiblePopups.size + 10;
vmDom.hidden = false;
vm.storeAndSetScope();
popupVisibilityNames.push(vm.viewModelName);
arePopupsVisible(true);
requestAnimationFrame(() => { // wait just before the next paint
vmDom.offsetHeight; // force a reflow
vmDom.classList.add('show'); // trigger the transitions
@ -75,7 +76,7 @@ const SCREENS = {},
vm.onHide && vm.onHide();
vmDom.classList.remove('show');
vm.restoreScope();
popupVisibilityNames(popupVisibilityNames.filter(v=>v!==vm.viewModelName));
arePopupsVisible(0 < visiblePopups.size);
}
vmDom.setAttribute('aria-hidden', !value);
});
@ -211,8 +212,6 @@ const SCREENS = {},
};
export const
popupVisibilityNames = ko.observableArray(),
ViewType = {
Popup: 'Popups',
Left: 'Left',
@ -276,7 +275,7 @@ export const
}
},
arePopupsVisible = () => 0 < visiblePopups.size,
arePopupsVisible = ko.observable(false),
/**
* @param {Function} ViewModelClassToShow