diff options
author | vellichora <fangrui_tong@brown.edu> | 2020-01-07 15:58:10 -0500 |
---|---|---|
committer | vellichora <fangrui_tong@brown.edu> | 2020-01-07 15:58:10 -0500 |
commit | 89d3ec54886a588f3b7c8e46e771830eeefc3c8b (patch) | |
tree | f4c7c7fe6ef363ca686b4b781fd9d7382c0f4a2a /src | |
parent | e9dcc0f18498d9415d204dfd3e61465a70486374 (diff) |
added logic so that text nodes started on the very left still show the full richtextmenu
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/RichTextMenu.scss | 9 | ||||
-rw-r--r-- | src/client/util/RichTextMenu.tsx | 49 | ||||
-rw-r--r-- | src/client/views/AntimodeMenu.tsx | 6 | ||||
-rw-r--r-- | src/client/views/nodes/FormattedTextBox.tsx | 8 |
4 files changed, 55 insertions, 17 deletions
diff --git a/src/client/util/RichTextMenu.scss b/src/client/util/RichTextMenu.scss index 5a57f4b98..ff9270829 100644 --- a/src/client/util/RichTextMenu.scss +++ b/src/client/util/RichTextMenu.scss @@ -94,4 +94,13 @@ select { &::-ms-expand { color: white; } +} + +.row-2 { + display: flex; + justify-content: space-between; + + >div { + display: flex; + } }
\ No newline at end of file diff --git a/src/client/util/RichTextMenu.tsx b/src/client/util/RichTextMenu.tsx index 4538a77d6..ae55dbd30 100644 --- a/src/client/util/RichTextMenu.tsx +++ b/src/client/util/RichTextMenu.tsx @@ -29,7 +29,7 @@ library.add(faBold, faItalic, faUnderline, faStrikethrough, faSuperscript, faSub @observer export default class RichTextMenu extends AntimodeMenu { static Instance: RichTextMenu; - public overDropdown: boolean = false; // kind of hacky way to prevent selects not being selectable + public overMenu: boolean = false; // kind of hacky way to prevent selects not being selectable private view?: EditorView; private editorProps: FieldViewProps & FormattedTextBoxProps | undefined; @@ -188,9 +188,7 @@ export default class RichTextMenu extends AntimodeMenu { } }); } - function onPointerEnter() { self.overDropdown = true; } - function onPointerLeave() { self.overDropdown = false; } - return <select onChange={onChange} onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}>{items}</select>; + return <select onChange={onChange}>{items}</select>; } createNodesDropdown(activeOption: string, options: { node: NodeType | any | null, title: string, label: string, command: (node: NodeType | any) => void, hidden?: boolean }[]): JSX.Element { @@ -213,9 +211,7 @@ export default class RichTextMenu extends AntimodeMenu { } }); } - function onPointerEnter() { self.overDropdown = true; } - function onPointerLeave() { self.overDropdown = false; } - return <select onChange={e => onChange(e.target.value)} onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}>{items}</select>; + return <select onChange={e => onChange(e.target.value)}>{items}</select>; } changeFontSize = (mark: Mark, view: EditorView) => { @@ -311,7 +307,9 @@ export default class RichTextMenu extends AntimodeMenu { return ( <div className="button-dropdown-wrapper"> - <button className="antimodeMenu-button" title="" onPointerDown={onBrushClick}><FontAwesomeIcon icon="eye-dropper" size="lg" /></button> + <button className="antimodeMenu-button" title="" onPointerDown={onBrushClick} style={this.brushMarks && this.brushMarks.size > 0 ? { backgroundColor: "121212" } : {}}> + <FontAwesomeIcon icon="eye-dropper" size="lg" style={{ transition: "transform 0.1s", transform: this.brushMarks && this.brushMarks.size > 0 ? "rotate(45deg)" : "" }} /> + </button> <button className="dropdown-button antimodeMenu-button" onPointerDown={onDropdownClick}><FontAwesomeIcon icon="caret-down" size="sm" /></button> {this.showBrushDropdown ? (<div className="dropdown"> @@ -652,6 +650,17 @@ export default class RichTextMenu extends AntimodeMenu { return ref_node; } + @action onPointerEnter(e: React.PointerEvent) { RichTextMenu.Instance.overMenu = true; } + @action onPointerLeave(e: React.PointerEvent) { RichTextMenu.Instance.overMenu = false; } + + @action + toggleMenuPin = (e: React.MouseEvent) => { + this.Pinned = !this.Pinned; + if (!this.Pinned) { + this.fadeOut(true); + } + } + render() { const fontSizeOptions = [ @@ -705,16 +714,28 @@ export default class RichTextMenu extends AntimodeMenu { this.createButton("indent", "Summarize", undefined, this.insertSummarizer), ]}</div> - const row2 = <div className="antimodeMenu-row">{[ - this.createMarksDropdown(this.activeFontSize, fontSizeOptions), - this.createMarksDropdown(this.activeFontFamily, fontFamilyOptions), - this.createNodesDropdown(this.activeListType, listTypeOptions), - ]}</div> + const row2 = <div className="antimodeMenu-row row-2"> + <div>{[ + this.createMarksDropdown(this.activeFontSize, fontSizeOptions), + this.createMarksDropdown(this.activeFontFamily, fontFamilyOptions), + this.createNodesDropdown(this.activeListType, listTypeOptions), + ]}</div> + <div> + <button className="antimodeMenu-button" title="Pin menu" onClick={this.toggleMenuPin} style={this.Pinned ? { backgroundColor: "#121212" } : {}}> + <FontAwesomeIcon icon="thumbtack" size="lg" style={{ transition: "transform 0.1s", transform: this.Pinned ? "rotate(45deg)" : "" }} /> + </button> + {this.getDragger()} + </div> + </div> const buttons = [ row1, row2 ]; - return this.getElementWithRows(buttons, 2); + return ( + <div className="richTextMenu" onPointerEnter={this.onPointerEnter} onPointerLeave={this.onPointerLeave}> + {this.getElementWithRows(buttons, 2)} + </div> + ); } }
\ No newline at end of file diff --git a/src/client/views/AntimodeMenu.tsx b/src/client/views/AntimodeMenu.tsx index 713a8a189..62ecdffaf 100644 --- a/src/client/views/AntimodeMenu.tsx +++ b/src/client/views/AntimodeMenu.tsx @@ -116,6 +116,10 @@ export default abstract class AntimodeMenu extends React.Component { e.preventDefault(); } + protected getDragger = () => { + return <div className="antimodeMenu-dragger" onPointerDown={this.dragStart} style={{ width: this.Pinned ? "20px" : "0px" }} /> + } + protected getElement(buttons: JSX.Element[]) { return ( <div className="antimodeMenu-cont" onPointerLeave={this.pointerLeave} onPointerEnter={this.pointerEntered} ref={this._mainCont} onContextMenu={this.handleContextMenu} @@ -131,7 +135,7 @@ export default abstract class AntimodeMenu extends React.Component { <div className="antimodeMenu-cont with-rows" onPointerLeave={this.pointerLeave} onPointerEnter={this.pointerEntered} ref={this._mainCont} onContextMenu={this.handleContextMenu} style={{ left: this._left, top: this._top, opacity: this._opacity, transition: this._transition, transitionDelay: this._transitionDelay, height: 35 * numRows + "px" }}> {rows} - <div className="antimodeMenu-dragger" onPointerDown={this.dragStart} style={{ width: this.Pinned ? "20px" : "0px" }} /> + {/* <div className="antimodeMenu-dragger" onPointerDown={this.dragStart} style={{ width: this.Pinned ? "20px" : "0px" }} /> */} </div> ); } diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx index 7291d2e8e..4712b1974 100644 --- a/src/client/views/nodes/FormattedTextBox.tsx +++ b/src/client/views/nodes/FormattedTextBox.tsx @@ -913,7 +913,11 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & keeplocation && setTimeout(() => this._editorView?.dispatch(this._editorView?.state.tr.setSelection(TextSelection.create(this._editorView.state.doc, pos)))); // jump rich text menu to this textbox - this._ref.current && RichTextMenu.Instance.jumpTo(this._ref.current.getBoundingClientRect().x, this._ref.current?.getBoundingClientRect().y - 105); + if (this._ref.current) { + let x = Math.min(Math.max(this._ref.current!.getBoundingClientRect().x, 0), window.innerWidth - 445); + let y = this._ref.current!.getBoundingClientRect().y - 105; + RichTextMenu.Instance.jumpTo(x, y); + } } onPointerWheel = (e: React.WheelEvent): void => { // if a text note is not selected and scrollable, this prevents us from being able to scroll and zoom out at the same time @@ -1062,7 +1066,7 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & this.doLinkOnDeselect(); // move the richtextmenu offscreen - if (!RichTextMenu.Instance.Pinned && !RichTextMenu.Instance.overDropdown) RichTextMenu.Instance.jumpTo(-300, -300); + if (!RichTextMenu.Instance.Pinned && !RichTextMenu.Instance.overMenu) RichTextMenu.Instance.jumpTo(-300, -300); } _lastTimedMark: Mark | undefined = undefined; |