From caaf9578dc8676833b45a98d7e448c1c754ae9ae Mon Sep 17 00:00:00 2001
From: Safae Merigh <safae_merigh@brown.edu>
Date: Tue, 26 May 2020 20:36:12 +0000
Subject: Modifications to DashDocCommentView (class from RichTextSchema)

---
 .../nodes/formattedText/DashDocCommentView.tsx     | 139 ++++++++++++---------
 1 file changed, 80 insertions(+), 59 deletions(-)

(limited to 'src/client/views/nodes/formattedText/DashDocCommentView.tsx')

diff --git a/src/client/views/nodes/formattedText/DashDocCommentView.tsx b/src/client/views/nodes/formattedText/DashDocCommentView.tsx
index d56b87ae5..2d4e360a8 100644
--- a/src/client/views/nodes/formattedText/DashDocCommentView.tsx
+++ b/src/client/views/nodes/formattedText/DashDocCommentView.tsx
@@ -1,56 +1,75 @@
-import { IReactionDisposer, observable, reaction, runInAction } from "mobx";
-import { baseKeymap, toggleMark } from "prosemirror-commands";
-import { redo, undo } from "prosemirror-history";
-import { keymap } from "prosemirror-keymap";
-import { DOMOutputSpecArray, Fragment, MarkSpec, Node, NodeSpec, Schema, Slice } from "prosemirror-model";
-import { bulletList, listItem, orderedList } from 'prosemirror-schema-list';
-import { EditorState, NodeSelection, Plugin, TextSelection } from "prosemirror-state";
-import { StepMap } from "prosemirror-transform";
-import { EditorView } from "prosemirror-view";
+import { TextSelection } from "prosemirror-state";
 import * as ReactDOM from 'react-dom';
-import { Doc, DocListCast, Field, HeightSym, WidthSym } from "../../../../fields/Doc";
-import { Id } from "../../../../fields/FieldSymbols";
-import { List } from "../../../../fields/List";
-import { ObjectField } from "../../../../fields/ObjectField";
-import { listSpec } from "../../../../fields/Schema";
-import { SchemaHeaderField } from "../../../../fields/SchemaHeaderField";
-import { ComputedField } from "../../../../fields/ScriptField";
-import { BoolCast, Cast, NumCast, StrCast } from "../../../../fields/Types";
-import { emptyFunction, returnEmptyString, returnFalse, returnOne, Utils, returnZero } from "../../../../Utils";
+import { Doc } from "../../../../fields/Doc";
 import { DocServer } from "../../../DocServer";
-
 import React = require("react");
 
-import { schema } from "./schema_rts";
+export class DashDocCommentView {
+    _fieldWrapper: HTMLDivElement; // container for label and value
+
+    constructor(node: any, view: any, getPos: any) {
+        this._fieldWrapper = document.createElement("div");
+        this._fieldWrapper.style.width = node.attrs.width;
+        this._fieldWrapper.style.height = node.attrs.height;
+        this._fieldWrapper.style.fontWeight = "bold";
+        this._fieldWrapper.style.position = "relative";
+        this._fieldWrapper.style.display = "inline-block";
+        this._fieldWrapper.onkeypress = function (e: any) { e.stopPropagation(); };
+        this._fieldWrapper.onkeydown = function (e: any) { e.stopPropagation(); };
+        this._fieldWrapper.onkeyup = function (e: any) { e.stopPropagation(); };
+        this._fieldWrapper.onmousedown = function (e: any) { e.stopPropagation(); };
+
+        ReactDOM.render(<DashDocCommentViewInternal
+            node={node}
+            view={view}
+            getPos={getPos}
+        />, this._fieldWrapper);
+        (this as any).dom = this._fieldWrapper;
+    }
+
+    destroy() {
+        ReactDOM.unmountComponentAtNode(this._fieldWrapper);
+    }
+
+    selectNode() { }
+}
 
-interface IDashDocCommentView {
+interface IDashDocCommentViewInternal {
     node: any;
     view: any;
     getPos: any;
 }
 
-export class DashDocCommentView extends React.Component<IDashDocCommentView>{
-    constructor(props: IDashDocCommentView) {
-        super(props);
+
+export class DashDocCommentViewInternal extends React.Component<IDashDocCommentViewInternal>{
+
+    constructor(props: IDashDocCommentViewInternal) {
+        super(props)
+        this.onPointerLeaveCollapsed = this.onPointerLeaveCollapsed.bind(this)
+        this.onPointerEnterCollapsed = this.onPointerEnterCollapsed.bind(this)
+        this.onPointerUpCollapsed = this.onPointerUpCollapsed.bind(this)
+        this.onPointerDownCollapsed = this.onPointerDownCollapsed.bind(this)
     }
 
-    targetNode = () => {  // search forward in the prosemirror doc for the attached dashDocNode that is the target of the comment anchor
-        for (let i = this.props.getPos() + 1; i < this.props.view.state.doc.content.size; i++) {
-            const m = this.props.view.state.doc.nodeAt(i);
-            if (m && m.type === this.props.view.state.schema.nodes.dashDoc && m.attrs.docid === this.props.node.attrs.docid) {
-                return { node: m, pos: i, hidden: m.attrs.hidden } as { node: any, pos: number, hidden: boolean };
-            }
-        }
-        const dashDoc = this.props.view.state.schema.nodes.dashDoc.create({ width: 75, height: 35, title: "dashDoc", docid: this.props.node.attrs.docid, float: "right" });
-        this.props.view.dispatch(this.props.view.state.tr.insert(this.props.getPos() + 1, dashDoc));
-        setTimeout(() => { try { this.props.view.dispatch(this.props.view.state.tr.setSelection(TextSelection.create(this.props.view.state.tr.doc, this.props.getPos() + 2))); } catch (e) { } }, 0);
-        return undefined;
+    getId() {
+        return this.props.node.attrs.docid
     }
 
-    onPointerDownCollapse = (e: any) => e.stopPropagation();
+    onPointerLeaveCollapsed(e: any) {
+        DocServer.GetRefField(this.props.node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowUnhighlight());
+        e.preventDefault();
+        e.stopPropagation();
+    };
 
-    onPointerUpCollapse = (e: any) => {
+    onPointerEnterCollapsed(e: any) {
+        DocServer.GetRefField(this.props.node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowHighlight(dashDoc, false));
+        e.preventDefault();
+        e.stopPropagation();
+    };
+
+    onPointerUpCollapsed(e: any) {
         const target = this.targetNode();
+
         if (target) {
             const expand = target.hidden;
             const tr = this.props.view.state.tr.setNodeMarkup(target.pos, undefined, { ...target.node.attrs, hidden: target.node.attrs.hidden ? false : true });
@@ -61,35 +80,37 @@ export class DashDocCommentView extends React.Component<IDashDocCommentView>{
             }, 0);
         }
         e.stopPropagation();
-    }
+    };
 
-    onPointerEnterCollapse = (e: any) => {
-        DocServer.GetRefField(this.props.node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowHighlight(dashDoc, false));
-        e.preventDefault();
+    onPointerDownCollapsed(e: any) {
         e.stopPropagation();
-    }
+    };
 
-    onPointerLeaveCollapse = (e: any) => {
-        DocServer.GetRefField(this.props.node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowUnhighlight());
-        e.preventDefault();
-        e.stopPropagation();
-    }
-
-    render() {
+    targetNode = () => {  // search forward in the prosemirror doc for the attached dashDocNode that is the target of the comment anchor
+        for (let i = this.props.getPos() + 1; i < this.props.view.state.doc.content.size; i++) {
+            const m = this.props.view.state.doc.nodeAt(i);
+            if (m && m.type === this.props.view.state.schema.nodes.dashDoc && m.attrs.docid === this.props.node.attrs.docid) {
+                return { node: m, pos: i, hidden: m.attrs.hidden } as { node: any, pos: number, hidden: boolean };
+            }
+        }
 
-        const collapsedId = "DashDocCommentView-" + this.props.node.attrs.docid;
+        const dashDoc = this.props.view.state.schema.nodes.dashDoc.create({ width: 75, height: 35, title: "dashDoc", docid: this.props.node.attrs.docid, float: "right" });
+        this.props.view.dispatch(this.props.view.state.tr.insert(this.props.getPos() + 1, dashDoc));
+        setTimeout(() => { try { this.props.view.dispatch(this.props.view.state.tr.setSelection(TextSelection.create(this.props.view.state.tr.doc, this.props.getPos() + 2))); } catch (e) { } }, 0);
+        return undefined;
+    };
 
+    render() {
         return (
             <span
                 className="formattedTextBox-inlineComment"
-                id={collapsedId}
-                onPointerDown={this.onPointerDownCollapse}
-                onPointerUp={this.onPointerUpCollapse}
-                onPointerEnter={this.onPointerEnterCollapse}
-                onPointerLeave={this.onPointerLeaveCollapse}
+                id={"DashDocCommentView-" + this.getId}
+                onPointerLeave={this.onPointerLeaveCollapsed}
+                onPointerEnter={this.onPointerEnterCollapsed}
+                onPointerUp={this.onPointerUpCollapsed}
+                onPointerDown={this.onPointerDownCollapsed}
             >
-
-            </span >
-        );
+            </span>
+        )
     }
-}
\ No newline at end of file
+}
-- 
cgit v1.2.3-70-g09d2

