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 } 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; addDocTab: (document: Doc, where: string) => boolean; } @observer export class LinkMenu extends React.Component { @observable private _editingLink?: Doc; @observable private _linkMenuRef = React.createRef(); private _editorRef = React.createRef(); //@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>): 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; } @computed get position() { const docView = this.props.docView; const transform = (docView.props.ScreenToLocalTransform().scale(docView.props.ContentScaling())).inverse(); const [sptX, sptY] = transform.transformPoint(0, 0); const [bptX, bptY] = transform.transformPoint(docView.props.PanelWidth(), docView.props.PanelHeight()); return { x: sptX, y: sptY, r: bptX, b: bptY }; } render() { const sourceDoc = this.props.docView.props.Document; const groups: Map = LinkManager.Instance.getRelatedGroupedLinks(sourceDoc); return
{!this._editingLink ?
{this.renderAllGroups(groups)}
:
this._editingLink = undefined)} />
}
; } }