summaryrefslogtreecommitdiffstats
path: root/src/modules/Fridge.ts
blob: c12bc53178be3b732414fa2fd7d44a9931641b7f (plain) (blame)
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
import Chit, { ChitFromDb } from "Modules/Chit"
import WYSiWYG from "./WYSiWYG";

export default class Fridge {
  #chits: Chit[] = [];
  //@ts-expect-error
  #wysiwyg: WYSiWYG;

  constructor(wysiwyg: WYSiWYG) {
    const f = sessionStorage.fridge;
    if (f === null) {
      location.href = "/"
      return;
    }

    const cs = JSON.parse(f) as ChitFromDb[];
    for (const c of cs) {
      this.#chits.push(new Chit(this, wysiwyg, c));
    }


    this.#wysiwyg = wysiwyg;
  }

  setChitZIAuto() {
    for (const c of this.#chits)
      c.div.style.zIndex = "auto"
  }
  removeChit(ch: Chit) {
    this.#chits = this.#chits.filter(c => c !== ch);
  }
  // moveChit(coord: { top: number, left: number }) {
  //   for (const c of this.#chits) {
  //     if (c.isMoving) {
  //       c.move(coord)
  //     }
  //   }
  // }
  // stopChitMove() {
  //   for (const c of this.#chits) {
  //     c.isMoving = false;
  //     //@ts-expect-error
  //     c.mouseUpH({ preventDefault: () => null })
  //   }
  // }

  createChit() {
    this.#chits.push(new Chit(this, this.#wysiwyg))
  }

  get chits(): Chit[] {
    return this.#chits;
  }
}