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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
import { action, computed, observable } from "mobx";
import { observer } from "mobx-react";
import { Doc } from "../../../fields/Doc";
import { LinkManager } from "../../util/LinkManager";
import { DocumentLinksButton } from "../nodes/DocumentLinksButton";
import { DocumentView, DocumentViewSharedProps } from "../nodes/DocumentView";
import { LinkDocPreview } from "../nodes/LinkDocPreview";
import { LinkEditor } from "./LinkEditor";
import './LinkMenu.scss';
import { LinkMenuGroup } from "./LinkMenuGroup";
import React = require("react");
interface Props {
docView: DocumentView;
changeFlyout: () => void;
docprops: DocumentViewSharedProps;
}
@observer
export class LinkMenu extends React.Component<Props> {
@observable private _editingLink?: Doc;
@observable private _linkMenuRef = React.createRef<HTMLDivElement>();
private _editorRef = React.createRef<HTMLDivElement>();
//@observable private _numLinks: number = 0;
// @computed get overflow() {
// if (this._numLinks) {
// return "scroll";
// }
// return "auto";
// }
@action
onClick = (e: PointerEvent) => {
LinkDocPreview.LinkInfo = undefined;
if (this._linkMenuRef && !this._linkMenuRef.current?.contains(e.target as any)) {
if (this._editorRef && !this._editorRef.current?.contains(e.target as any)) {
DocumentLinksButton.EditLink = undefined;
}
}
}
@action
componentDidMount() {
this._editingLink = undefined;
document.addEventListener("pointerdown", this.onClick);
}
componentWillUnmount() {
document.removeEventListener("pointerdown", this.onClick);
}
clearAllLinks = () => {
LinkManager.Instance.deleteAllLinksOnAnchor(this.props.docView.props.Document);
}
renderAllGroups = (groups: Map<string, Array<Doc>>): Array<JSX.Element> => {
const linkItems = Array.from(groups.entries()).map(group =>
<LinkMenuGroup
key={group[0]}
docView={this.props.docView}
sourceDoc={this.props.docView.props.Document}
group={group[1]}
groupType={group[0]}
showEditor={action(linkDoc => this._editingLink = linkDoc)}
docprops={this.props.docprops} />);
return linkItems.length ? linkItems : [<p key="">No links have been created yet. Drag the linking button onto another document to create a link.</p>];
}
@computed
get position() {
const docView = this.props.docView.getBounds();
return { x: docView?.left || 0, y: docView?.top || 0, r: docView?.right || 0, b: docView?.bottom || 0 };
}
render() {
const sourceDoc = this.props.docView.props.Document;
const groups: Map<string, Doc[]> = LinkManager.Instance.getRelatedGroupedLinks(sourceDoc);
return <div className="linkMenu" style={{ left: this.position.x, top: this.props.docView.topMost ? undefined : this.position.b + 15, bottom: this.props.docView.topMost ? 20 : undefined }} ref={this._linkMenuRef} >
{!this._editingLink ?
<div className="linkMenu-list" >
{this.renderAllGroups(groups)}
</div> :
<div className="linkMenu-listEditor">
<LinkEditor sourceDoc={this.props.docView.props.Document} linkDoc={this._editingLink}
showLinks={action(() => this._editingLink = undefined)} />
</div>
}
</div>;
}
}
|