aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/EditableView.tsx
diff options
context:
space:
mode:
authorMohammad Amoush <47069173+mamoush34@users.noreply.github.com>2020-02-08 17:03:12 -0500
committerMohammad Amoush <47069173+mamoush34@users.noreply.github.com>2020-02-08 17:03:12 -0500
commitf9855e8d1ec83405ae3cc7d0113b46de63fc0848 (patch)
treebf4be61a021e59b771c1cd5958fd9fd43cac8693 /src/client/views/EditableView.tsx
parent87f5f043388b591c52e96a795fa461a79770550d (diff)
parent1b046f76cf39f1f6cb1875aa84b45db74b6d994e (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into webcam_mohammad
Diffstat (limited to 'src/client/views/EditableView.tsx')
-rw-r--r--src/client/views/EditableView.tsx38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx
index faf02b946..84c6b0dfd 100644
--- a/src/client/views/EditableView.tsx
+++ b/src/client/views/EditableView.tsx
@@ -1,10 +1,12 @@
import React = require('react');
+import { action, observable } from 'mobx';
import { observer } from 'mobx-react';
-import { observable, action, trace } from 'mobx';
-import "./EditableView.scss";
import * as Autosuggest from 'react-autosuggest';
-import { undoBatch } from '../util/UndoManager';
+import { ObjectField } from '../../new_fields/ObjectField';
import { SchemaHeaderField } from '../../new_fields/SchemaHeaderField';
+import { ContextMenu } from './ContextMenu';
+import { ContextMenuProps } from './ContextMenuItem';
+import "./EditableView.scss";
export interface EditableProps {
/**
@@ -43,6 +45,8 @@ export interface EditableProps {
editing?: boolean;
onClick?: (e: React.MouseEvent) => boolean;
isEditingCallback?: (isEditing: boolean) => void;
+ menuCallback?: (x: number, y: number) => void;
+ showMenuOnLoad?: boolean;
HeadingObject?: SchemaHeaderField | undefined;
HeadingsHack?: number;
toggle?: () => void;
@@ -65,7 +69,7 @@ export class EditableView extends React.Component<EditableProps> {
}
@action
- componentWillReceiveProps(nextProps: EditableProps) {
+ componentDidUpdate(nextProps: EditableProps) {
// this is done because when autosuggest is turned on, the suggestions are passed in as a prop,
// so when the suggestions are passed in, and no editing prop is passed in, it used to set it
// to false. this will no longer do so -syip
@@ -74,6 +78,8 @@ export class EditableView extends React.Component<EditableProps> {
}
}
+ _didShow = false;
+
@action
onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Tab") {
@@ -87,21 +93,27 @@ export class EditableView extends React.Component<EditableProps> {
} else if (this.props.OnFillDown) {
this.props.OnFillDown(e.currentTarget.value);
this._editing = false;
- this.props.isEditingCallback && this.props.isEditingCallback(false);
+ this.props.isEditingCallback?.(false);
}
} else if (e.key === "Escape") {
e.stopPropagation();
this._editing = false;
- this.props.isEditingCallback && this.props.isEditingCallback(false);
+ this.props.isEditingCallback?.(false);
+ } else if (e.key === ":") {
+ this.props.menuCallback?.(e.currentTarget.getBoundingClientRect().x, e.currentTarget.getBoundingClientRect().y);
}
}
@action
onClick = (e: React.MouseEvent) => {
e.nativeEvent.stopPropagation();
- if (!this.props.onClick || !this.props.onClick(e)) {
- this._editing = true;
- this.props.isEditingCallback && this.props.isEditingCallback(true);
+ if (this._ref.current && this.props.showMenuOnLoad) {
+ this.props.menuCallback?.(this._ref.current.getBoundingClientRect().x, this._ref.current.getBoundingClientRect().y);
+ } else {
+ if (!this.props.onClick || !this.props.onClick(e)) {
+ this._editing = true;
+ this.props.isEditingCallback?.(true);
+ }
}
e.stopPropagation();
}
@@ -110,7 +122,7 @@ export class EditableView extends React.Component<EditableProps> {
private finalizeEdit(value: string, shiftDown: boolean) {
this._editing = false;
if (this.props.SetValue(value, shiftDown)) {
- this.props.isEditingCallback && this.props.isEditingCallback(false);
+ this.props.isEditingCallback?.(false);
}
}
@@ -125,6 +137,7 @@ export class EditableView extends React.Component<EditableProps> {
return wasFocused !== this._editing;
}
+ _ref = React.createRef<HTMLDivElement>();
render() {
if (this._editing && this.props.GetValue() !== undefined) {
return this.props.autosuggestProps
@@ -151,9 +164,10 @@ export class EditableView extends React.Component<EditableProps> {
style={{ display: this.props.display, fontSize: this.props.fontSize }}
/>;
} else {
- if (this.props.autosuggestProps) this.props.autosuggestProps.resetValue();
- return (
+ this.props.autosuggestProps?.resetValue();
+ return (this.props.contents instanceof ObjectField ? (null) :
<div className={`editableView-container-editing${this.props.oneLine ? "-oneLine" : ""}`}
+ ref={this._ref}
style={{ display: this.props.display, minHeight: "20px", height: `${this.props.height ? this.props.height : "auto"}`, maxHeight: `${this.props.maxHeight}` }}
onClick={this.onClick}>
<span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize }}>{this.props.contents}</span>