bug: stop scrolling page when moving through search results
[apps/outliner/.git] / src / cursor.ts
1 import {isVisible} from "dom";
2
3 export class Cursor {
4   constructor() {
5
6   }
7
8   get() {
9     return document.querySelector('.cursor');
10   }
11
12   getIdOfNode(): string {
13     return this.get().getAttribute('data-id');
14   }
15
16   unset() {
17     const el = this.get();
18     if(el) {
19       el.classList.remove('cursor');
20     }
21   }
22
23   set(elementId: string) {
24     this.unset();
25     const el = document.querySelector(elementId) as HTMLElement;
26
27     if(el) {
28       el.classList.add('cursor');
29       if(!isVisible(el)) {
30         el.scrollIntoView(true);
31       }
32     }
33   }
34
35   collapse() {
36     this.get().classList.remove('expanded');
37     this.get().classList.add('collapsed');
38   }
39
40   expand() {
41     this.get().classList.remove('collapsed');
42     this.get().classList.add('expanded');
43   }
44
45   isNodeCollapsed(): boolean {
46     return this.get().classList.contains('collapsed');
47   }
48   
49   isNodeExpanded(): boolean {
50     return this.get().classList.contains('expanded');
51   }
52 }