forked from tutao/tutanota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRootView.ts
60 lines (53 loc) · 1.77 KB
/
RootView.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import m, {Children} from "mithril"
import {modal} from "./gui/base/Modal"
import {overlay} from "./gui/base/Overlay"
import {styles} from "./gui/styles"
import {assertMainOrNodeBoot} from "./api/common/Env"
assertMainOrNodeBoot()
export const enum LayerType {
// Minimized editors, SearchBarOverlay
View = 0,
// notifications that require no user interaction
LowPriorityOverlay = 100,
// Foreground menu in mobile layout
LowPriorityNotification = 150,
// Editors, Dialogs
ForegroundMenu = 200,
// Error message dialogs, Notifications
Modal = 300,
Overlay = 400,
}
export class RootView {
view: (...args: Array<any>) => any
viewCache: Record<string, (...args: Array<any>) => any>
constructor() {
this.viewCache = {}
// On first mouse event disable outline. This is a compromise between keyboard navigation users and mouse users.
let onmousedown: EventListener | null = (e: EventRedraw<MouseEvent>) => {
if (onmousedown) {
console.log("disabling outline")
styles.registerStyle("outline", () => ({
"*": {
outline: "none",
},
}))
// remove event listener after the first click to not re-register style
onmousedown = null
// It is important to not redraw at this point because click event may be lost otherwise and saved login button would not be
// actually pressed. It's unclear why but preventing redraw (this way or setting listener manually) helps.
// It's also useless to redraw for this click handler because we just want to add a global style definition.
e.redraw = false
}
}
this.view = (vnode): Children => {
return m(
"#root" + (styles.isUsingBottomNavigation() ? ".mobile" : ""),
{
onmousedown,
},
[m(overlay), m(modal), vnode.children],
)
}
}
}
export const root: RootView = new RootView()