aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-09-17 10:46:27 -0400
committerbobzel <zzzman@gmail.com>2020-09-17 10:46:27 -0400
commit80bbbb3842cb89949d2b949ce8f5a2ed3921b112 (patch)
tree0041374a63f80325060a47dc0a259c750e526792 /src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx
parent5dc5009da8018d79620a42b75833d5b4335e0f56 (diff)
fixed deleting text links to work when there are multiple links in the same linkAnchor mark. addressed problem with text getting a negative height when its resized to fit content in a preview window when its also displayed in freeform.
Diffstat (limited to 'src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx')
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx b/src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx
index 1bf885636..249aca812 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBoxComment.tsx
@@ -1,6 +1,6 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Tooltip } from "@material-ui/core";
-import { action } from "mobx";
+import { action, observable } from "mobx";
import { Mark, ResolvedPos } from "prosemirror-model";
import { EditorState, Plugin } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
@@ -23,6 +23,7 @@ import { FormattedTextBox } from "./FormattedTextBox";
import './FormattedTextBoxComment.scss';
import { schema } from "./schema_rts";
import React = require("react");
+import { observer } from "mobx-react";
export let formattedTextBoxCommentPlugin = new Plugin({
view(editorView) { return new FormattedTextBoxComment(editorView); }
@@ -60,6 +61,7 @@ export function findEndOfMark(rpos: ResolvedPos, view: EditorView, finder: (mark
// this view appears when clicking on text that has a hyperlink which is configured to show a preview of its target.
// this will also display metadata information about text when the view is configured to display things like other people who authored text.
//
+
export class FormattedTextBoxComment {
static tooltip: HTMLElement;
static tooltipText: HTMLElement;
@@ -72,6 +74,13 @@ export class FormattedTextBoxComment {
static _deleteRef: Opt<HTMLDivElement | null>;
static _followRef: Opt<HTMLDivElement | null>;
+ static _nextRef: Opt<HTMLDivElement | null>;
+
+ static _lastState?: EditorState;
+ static _lastView?: EditorView;
+
+ @observable static _hrefInd = 0;
+ static _hrefs: string[] | undefined = [];
constructor(view: any) {
if (!FormattedTextBoxComment.tooltip) {
@@ -101,6 +110,8 @@ export class FormattedTextBoxComment {
if (linkDoc.author) {
if (FormattedTextBoxComment._deleteRef?.contains(e.target as any)) {
this.deleteLink();
+ } else if (FormattedTextBoxComment._nextRef?.contains(e.target as any)) {
+ FormattedTextBoxComment.showPreview(FormattedTextBoxComment._lastView!, FormattedTextBoxComment._lastState, FormattedTextBoxComment._hrefs?.[(++FormattedTextBoxComment._hrefInd) % FormattedTextBoxComment._hrefs?.length])
} else {
FormattedTextBoxComment.linkDoc = undefined;
if (linkDoc.type !== DocumentType.LINK) {
@@ -128,7 +139,6 @@ export class FormattedTextBoxComment {
FormattedTextBoxComment.linkDoc ? LinkManager.Instance.deleteLink(FormattedTextBoxComment.linkDoc) : null;
LinkDocPreview.LinkInfo = undefined;
DocumentLinksButton.EditLink = undefined;
- //FormattedTextBoxComment.tooltipText = undefined;
FormattedTextBoxComment.Hide();
});
@@ -164,14 +174,20 @@ export class FormattedTextBoxComment {
}
static update(view: EditorView, lastState?: EditorState, forceUrl: string = "") {
- const state = view.state;
// Don't do anything if the document/selection didn't change
- if (lastState && lastState.doc.eq(state.doc) &&
- lastState.selection.eq(state.selection)) {
+ if (!forceUrl && lastState?.doc.eq(view.state.doc) && lastState?.selection.eq(view.state.selection)) {
return;
}
+ FormattedTextBoxComment._lastState = lastState;
+ FormattedTextBoxComment._lastView = view;
+ FormattedTextBoxComment._hrefs = forceUrl ? forceUrl.trim().split(" ") : undefined;
+ FormattedTextBoxComment._hrefInd = 0;
FormattedTextBoxComment.linkDoc = undefined;
+ FormattedTextBoxComment.showPreview(view, lastState, FormattedTextBoxComment._hrefs?.[FormattedTextBoxComment._hrefInd]);
+ }
+ static showPreview(view: EditorView, lastState?: EditorState, forceUrl: string = "") {
+ const state = view.state;
const textBox = FormattedTextBoxComment.textBox;
if (!textBox || !textBox.props) {
return;
@@ -209,7 +225,7 @@ export class FormattedTextBoxComment {
state.doc.nodesBetween(state.selection.from, state.selection.to, (node: any, pos: number, parent: any) => !child && node.marks.length && (child = node));
child = child || (nbef && state.selection.$from.nodeBefore);
const mark = child ? findLinkMark(child.marks) : undefined;
- const href = (!mark?.attrs.docref || naft === nbef) && mark?.attrs.allLinks.find((item: { href: string }) => item.href)?.href || forceUrl;
+ const href = forceUrl || (!mark?.attrs.docref || naft === nbef) && mark?.attrs.allLinks.find((item: { href: string }) => item.href)?.href;
if (forceUrl || (href && child && nbef && naft && mark?.attrs.showPreview)) {
try {
ReactDOM.unmountComponentAtNode(FormattedTextBoxComment.tooltipText);
@@ -245,34 +261,35 @@ export class FormattedTextBoxComment {
if (target?.author) {
FormattedTextBoxComment.showCommentbox("", view, nbef);
- const title = StrCast(target.title).length > 16 ?
- StrCast(target.title).substr(0, 16) + "..." : target.title;
-
+ const title = StrCast(target.title).length > 16 ? StrCast(target.title).substr(0, 16) + "..." : target.title;
const docPreview = <div className="FormattedTextBoxComment">
<div className="FormattedTextBoxComment-info">
<div className="FormattedTextBoxComment-title">
{title}
- {FormattedTextBoxComment.linkDoc.description !== "" ? <p className="FormattedTextBoxComment-description">
- {StrCast(FormattedTextBoxComment.linkDoc.description)}</p> : null}
+ {FormattedTextBoxComment.linkDoc.description === "" ? (null) :
+ <p className="FormattedTextBoxComment-description"> {StrCast(FormattedTextBoxComment.linkDoc.description)}</p>}
</div>
<div className="wrapper" style={{ float: "right" }}>
+ {(FormattedTextBoxComment._hrefs?.length || 0) <= 1 ? (null) : <Tooltip title={<><div className="dash-tooltip">Next Link</div></>} placement="top">
+ <div className="FormattedTextBoxComment-button" ref={(r) => this._nextRef = r}>
+ <FontAwesomeIcon className="FormattedTextBoxComment-fa-icon" icon="chevron-right" color="white" size="sm" />
+ </div>
+ </Tooltip>}
<Tooltip title={<><div className="dash-tooltip">Delete Link</div></>} placement="top">
- <div className="FormattedTextBoxComment-button"
- ref={(r) => this._deleteRef = r}>
- <FontAwesomeIcon className="FormattedTextBoxComment-fa-icon" icon="trash" color="white"
- size="sm" /></div>
+ <div className="FormattedTextBoxComment-button" ref={(r) => this._deleteRef = r}>
+ <FontAwesomeIcon className="FormattedTextBoxComment-fa-icon" icon="trash" color="white" size="sm" />
+ </div>
</Tooltip>
<Tooltip title={<><div className="dash-tooltip">Follow Link</div></>} placement="top">
- <div className="FormattedTextBoxComment-button"
- ref={(r) => this._followRef = r}>
- <FontAwesomeIcon className="FormattedTextBoxComment-fa-icon" icon="arrow-right" color="white"
- size="sm" />
+ <div className="FormattedTextBoxComment-button" ref={(r) => this._followRef = r}>
+ <FontAwesomeIcon className="FormattedTextBoxComment-fa-icon" icon="arrow-right" color="white" size="sm" />
</div>
</Tooltip>
- </div> </div>
+ </div>
+ </div>
<div className="FormattedTextBoxComment-preview-wrapper">
<ContentFittingDocumentView
Document={target}
@@ -304,8 +321,6 @@ export class FormattedTextBoxComment {
</div>
</div>;
-
-
FormattedTextBoxComment.showCommentbox("", view, nbef);
ReactDOM.render(docPreview, FormattedTextBoxComment.tooltipText);