import { action, observable } from "mobx"; import { observer } from "mobx-react"; import { DocumentView } from "../nodes/DocumentView"; import { LinkEditor } from "./LinkEditor"; import './LinkMenu.scss'; import React = require("react"); import { Doc, Opt } from "../../../fields/Doc"; import { LinkManager } from "../../util/LinkManager"; import { LinkMenuGroup } from "./LinkMenuGroup"; import { faTrash } from '@fortawesome/free-solid-svg-icons'; import { library } from "@fortawesome/fontawesome-svg-core"; import { DocumentLinksButton } from "../nodes/DocumentLinksButton"; library.add(faTrash); interface Props { docView: DocumentView; changeFlyout: () => void; addDocTab: (document: Doc, where: string) => boolean; location: number[]; } @observer export class LinkMenu extends React.Component { @observable private _editingLink?: Doc; @observable private _linkMenuRef: Opt; @action onClick = (e: PointerEvent) => { if (!Array.from(this._linkMenuRef?.getElementsByTagName((e.target as HTMLElement).tagName) || []).includes(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>): Array => { const linkItems: Array = []; groups.forEach((group, groupType) => { linkItems.push( this._editingLink = linkDoc)} addDocTab={this.props.addDocTab} /> ); }); // if source doc has no links push message if (linkItems.length === 0) linkItems.push(

No links have been created yet. Drag the linking button onto another document to create a link.

); return linkItems; } render() { const sourceDoc = this.props.docView.props.Document; const groups: Map = LinkManager.Instance.getRelatedGroupedLinks(sourceDoc); return
this._linkMenuRef = r} style={{ left: this.props.location[0], top: this.props.location[1] }}> {!this._editingLink ? this.renderAllGroups(groups) : this._editingLink = undefined)} /> }
; } }