From c694f7d7d9fbb88f2b2fa6ebb6093e9265a0b0b7 Mon Sep 17 00:00:00 2001 From: bob Date: Fri, 12 Apr 2019 16:04:08 -0400 Subject: moved previewcursor to main --- src/client/views/Main.tsx | 37 +++++++++++++++++ .../collectionFreeForm/CollectionFreeFormView.tsx | 3 +- .../collectionFreeForm/PreviewCursor.tsx | 47 +++------------------- 3 files changed, 44 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 419de6fc1..ac00be63c 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -40,7 +40,43 @@ import { DocumentView } from './nodes/DocumentView'; import { FormattedTextBox } from './nodes/FormattedTextBox'; import { REPLCommand } from 'repl'; import { Key } from '../../fields/Key'; +import { truncate } from 'fs'; + +export interface PromptProps { +} + +@observer +export class PreviewCursorPrompt extends React.Component { + private _prompt = React.createRef(); + //when focus is lost, this will remove the preview cursor + @action onBlur = (): void => { + PreviewCursorPrompt.Visible = false; + PreviewCursorPrompt.hide(); + } + + @observable static clickPoint = [0, 0]; + @observable public static Visible = false; + @observable public static hide = () => { }; + @action + public static Show(hide: any, x: number, y: number) { + this.clickPoint = [x, y]; + this.hide = hide; + setTimeout(action(() => this.Visible = true), (1)); + } + render() { + if (!PreviewCursorPrompt.clickPoint) + return (null); + if (PreviewCursorPrompt.Visible && this._prompt.current) { + this._prompt.current.focus(); + } + let p = PreviewCursorPrompt.clickPoint; + return
+ I +
; + } +} @observer export class Main extends React.Component { // dummy initializations keep the compiler happy @@ -392,6 +428,7 @@ export class Main extends React.Component { {({ measureRef }) =>
{this.mainContent} +
} diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index e38e71a68..dae62f126 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -325,8 +325,7 @@ export class CollectionFreeFormView extends CollectionSubView { - +
{blay} diff --git a/src/client/views/collections/collectionFreeForm/PreviewCursor.tsx b/src/client/views/collections/collectionFreeForm/PreviewCursor.tsx index 8eabb020a..64da8ecc6 100644 --- a/src/client/views/collections/collectionFreeForm/PreviewCursor.tsx +++ b/src/client/views/collections/collectionFreeForm/PreviewCursor.tsx @@ -6,12 +6,11 @@ import { Transform } from "../../../util/Transform"; import { CollectionFreeFormView } from "./CollectionFreeFormView"; import "./PreviewCursor.scss"; import React = require("react"); -import { interfaceDeclaration } from "babel-types"; +import { Main, PreviewCursorPrompt } from "../../Main"; export interface PreviewCursorProps { getTransform: () => Transform; - getContainerTransform: () => Transform; container: CollectionFreeFormView; addLiveTextDocument: (doc: Document) => void; } @@ -20,7 +19,6 @@ export interface PreviewCursorProps { export class PreviewCursor extends React.Component { @observable _lastX: number = 0; @observable _lastY: number = 0; - @observable public _visible: boolean = false; @observable public DownX: number = 0; @observable public DownY: number = 0; _showOnUp: boolean = false; @@ -46,17 +44,14 @@ export class PreviewCursor extends React.Component { onPointerMove = (e: PointerEvent): void => { if (Math.abs(this.DownX - e.clientX) > 4 || Math.abs(this.DownY - e.clientY) > 4) { this._showOnUp = false; - this._visible = false; + PreviewCursorPrompt.Visible = false; } } - @action onPointerUp = (e: PointerEvent): void => { if (this._showOnUp) { + PreviewCursorPrompt.Show(this.hideCursor, this.DownX, this.DownY); document.addEventListener("keypress", this.onKeyPress, false); - this._lastX = this.DownX; - this._lastY = this.DownY; - this._visible = true; } this.cleanupInteractions(); } @@ -69,52 +64,22 @@ export class PreviewCursor extends React.Component { //if not these keys, make a textbox if preview cursor is active! if (!e.ctrlKey && !e.altKey && !e.defaultPrevented && !(e as any).DASHFormattedTextBoxHandled) { //make textbox and add it to this collection - let [x, y] = this.props.getTransform().transformPoint(this._lastX, this._lastY); + let [x, y] = this.props.getTransform().transformPoint(this.DownX, this.DownY); let newBox = Documents.TextDocument({ width: 200, height: 100, x: x, y: y, title: "typed text" }); this.props.addLiveTextDocument(newBox); - document.removeEventListener("keypress", this.onKeyPress, false); - this._visible = false; + PreviewCursorPrompt.Visible = false; e.stopPropagation(); } } - getPoint = () => this.props.getContainerTransform().transformPoint(this._lastX, this._lastY); - getVisible = () => this._visible; - setVisible = (v: boolean) => { - this._visible = v; + hideCursor = () => { document.removeEventListener("keypress", this.onKeyPress, false); } render() { return (
{this.props.children} -
); } -} - -export interface PromptProps { - getPoint: () => number[]; - getVisible: () => boolean; - setVisible: (v: boolean) => void; -} - -@observer -export class PreviewCursorPrompt extends React.Component { - private _promptRef = React.createRef(); - - //when focus is lost, this will remove the preview cursor - @action onBlur = (): void => this.props.setVisible(false); - - render() { - let p = this.props.getPoint(); - if (this.props.getVisible() && this._promptRef.current) { - this._promptRef.current.focus(); - } - return
- I -
; - } } \ No newline at end of file -- cgit v1.2.3-70-g09d2