-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathAnnotationMixin.js
More file actions
60 lines (49 loc) · 1.7 KB
/
AnnotationMixin.js
File metadata and controls
60 lines (49 loc) · 1.7 KB
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 { getRoot, isAlive, types } from "mobx-state-tree";
import Types from "../core/Types";
import { FF_DEV_3391, FF_SIMPLE_INIT, isFF } from "../utils/feature-flags";
export const AnnotationMixin = types.model("AnnotationMixin", {}).views((self) => ({
get annotation() {
// annotation should not be accessed before store is initialized
if (isFF(FF_SIMPLE_INIT) && !window.STORE_INIT_OK && !isFF(FF_DEV_3391)) {
console.error("LSF: annotation accessed before store is initialized", self);
}
if (!isAlive(self)) return null;
if (isFF(FF_DEV_3391)) {
const root = getRoot(self);
// if that's a Tool (they live in separate tree)
if (root === self) {
if (self.control) {
return self.control.annotation;
}
if (self.obj) {
return self.obj.annotation;
}
return null;
}
// if annotation history item selected
if (root.annotationStore?.selectedHistory) {
return root.annotationStore.selectedHistory;
}
// return connected annotation, not the globally selected one
return Types.getParentOfTypeString(self, "Annotation");
}
const as = self.annotationStore;
return as?.selectedHistory ?? as?.selected;
},
get annotationOrHistoryItem() {
return Types.getParentOfTypeString(self, "Annotation") ?? Types.getParentOfTypeString(self, "HistoryItem");
},
get annotationStore() {
const root = getRoot(self);
if (root === self) {
if (self.control) {
return getRoot(self.control).annotationStore;
}
if (self.obj) {
return getRoot(self.obj).annotationStore;
}
return null;
}
return root.annotationStore;
},
}));