blob: 74af78234aba3df0f3657f844a699c6713a67d61 (
plain)
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
|
import { observer } from "mobx-react";
import { Doc } from "../../../fields/Doc";
import { Id } from "../../../fields/FieldSymbols";
import { Cast } from "../../../fields/Types";
import { LinkManager } from "../../util/LinkManager";
import { DocumentView } from "../nodes/DocumentView";
import './LinkMenu.scss';
import { LinkMenuItem } from "./LinkMenuItem";
import React = require("react");
interface LinkMenuGroupProps {
sourceDoc: Doc;
group: Doc[];
groupType: string;
showEditor: (linkDoc: Doc) => void;
docView: DocumentView;
}
@observer
export class LinkMenuGroup extends React.Component<LinkMenuGroupProps> {
private _menuRef = React.createRef<HTMLDivElement>();
render() {
const set = new Set<Doc>(this.props.group);
const groupItems = Array.from(set.keys()).map(linkDoc => {
const destination = LinkManager.getOppositeAnchor(linkDoc, this.props.sourceDoc) ||
LinkManager.getOppositeAnchor(linkDoc, Cast(linkDoc.anchor2, Doc, null).annotationOn === this.props.sourceDoc ? Cast(linkDoc.anchor2, Doc, null) : Cast(linkDoc.anchor1, Doc, null));
if (destination && this.props.sourceDoc) {
return <LinkMenuItem key={linkDoc[Id]}
groupType={this.props.groupType}
docView={this.props.docView}
linkDoc={linkDoc}
sourceDoc={this.props.sourceDoc}
destinationDoc={destination}
showEditor={this.props.showEditor}
menuRef={this._menuRef} />;
}
});
return (
<div className="linkMenu-group" ref={this._menuRef}>
<div className="linkMenu-group-name">
<p className={this.props.groupType === "*" || this.props.groupType === "" ? "" : "expand-one"} > {this.props.groupType}:</p>
</div>
<div className="linkMenu-group-wrapper">
{groupItems}
</div>
</div >
);
}
}
|