aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/EditableView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/EditableView.tsx')
-rw-r--r--src/client/views/EditableView.tsx128
1 files changed, 90 insertions, 38 deletions
diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx
index e0e205df9..ec3e754fb 100644
--- a/src/client/views/EditableView.tsx
+++ b/src/client/views/EditableView.tsx
@@ -5,6 +5,9 @@ import * as Autosuggest from 'react-autosuggest';
import { ObjectField } from '../../fields/ObjectField';
import { SchemaHeaderField } from '../../fields/SchemaHeaderField';
import "./EditableView.scss";
+import { DragManager } from '../util/DragManager';
+import { ComputedField } from '../../fields/ScriptField';
+import { FieldValue } from '../../fields/Types';
export interface EditableProps {
/**
@@ -30,6 +33,7 @@ export interface EditableProps {
fontStyle?: string;
fontSize?: number;
height?: number | "auto";
+ sizeToContent?: boolean;
maxHeight?: number;
display?: string;
autosuggestProps?: {
@@ -48,6 +52,12 @@ export interface EditableProps {
HeadingObject?: SchemaHeaderField | undefined;
toggle?: () => void;
color?: string | undefined;
+ onDrop?: any;
+ placeholder?: string;
+ highlight?: boolean;
+ positions?: number[];
+ search?: string;
+ bing?: () => string | undefined;
}
/**
@@ -57,23 +67,28 @@ export interface EditableProps {
*/
@observer
export class EditableView extends React.Component<EditableProps> {
- public static loadId = "";
@observable _editing: boolean = false;
constructor(props: EditableProps) {
super(props);
this._editing = this.props.editing ? true : false;
- EditableView.loadId = "";
}
+ // @action
+ // 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
+ // if (nextProps.editing && nextProps.editing !== this._editing) {
+ // this._editing = nextProps.editing;
+ // EditableView.loadId = "";
+ // }
+ // }
+
@action
- 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
- if (nextProps.editing && nextProps.editing !== this._editing) {
- this._editing = nextProps.editing;
- EditableView.loadId = "";
+ componentDidMount() {
+ if (this._ref.current && this.props.onDrop) {
+ DragManager.MakeDropTarget(this._ref.current, this.props.onDrop.bind(this));
}
}
@@ -109,7 +124,7 @@ export class EditableView extends React.Component<EditableProps> {
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)) {
+ if (!this.props.onClick?.(e)) {
this._editing = true;
this.props.isEditingCallback?.(true);
}
@@ -139,44 +154,81 @@ export class EditableView extends React.Component<EditableProps> {
@action
setIsFocused = (value: boolean) => {
const wasFocused = this._editing;
- this._editing = value;
+ //this._editing = value;
return wasFocused !== this._editing;
}
_ref = React.createRef<HTMLDivElement>();
+ renderEditor() {
+ return this.props.autosuggestProps
+ ? <Autosuggest
+ {...this.props.autosuggestProps.autosuggestProps}
+ inputProps={{
+ className: "editableView-input",
+ onKeyDown: this.onKeyDown,
+ autoFocus: true,
+ onBlur: e => this.finalizeEdit(e.currentTarget.value, false, true),
+ onPointerDown: this.stopPropagation,
+ onClick: this.stopPropagation,
+ onPointerUp: this.stopPropagation,
+ value: this.props.autosuggestProps.value,
+ onChange: this.props.autosuggestProps.onChange
+ }}
+ />
+ : <input className="editableView-input"
+ defaultValue={this.props.GetValue()}
+ onKeyDown={this.onKeyDown}
+ autoFocus={true}
+ onBlur={e => this.finalizeEdit(e.currentTarget.value, false, true)}
+ onPointerDown={this.stopPropagation} onClick={this.stopPropagation} onPointerUp={this.stopPropagation}
+ style={{ display: this.props.display, fontSize: this.props.fontSize, minWidth: 20 }}
+ placeholder={this.props.placeholder}
+ />;
+ }
+
+ returnHighlights() {
+ const results = [];
+ const contents = this.props.bing!();
+
+ if (contents !== undefined) {
+ if (this.props.positions !== undefined) {
+ const positions = this.props.positions;
+ const length = this.props.search!.length;
+
+ // contents = String(this.props.contents.valueOf());
+
+ results.push(<span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{contents ? contents.slice(0, this.props.positions[0]) : this.props.placeholder?.valueOf()}</span>);
+ positions.forEach((num, cur) => {
+ results.push(<span style={{ backgroundColor: "#FFFF00", fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{contents ? contents.slice(num, num + length) : this.props.placeholder?.valueOf()}</span>);
+ let end = 0;
+ cur === positions.length - 1 ? end = contents.length : end = positions[cur + 1];
+ results.push(<span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{contents ? contents.slice(num + length, end) : this.props.placeholder?.valueOf()}</span>);
+ }
+ );
+ }
+ return results;
+ }
+ else {
+ return <span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{this.props.contents ? this.props.contents?.valueOf() : this.props.placeholder?.valueOf()}</span>;
+ }
+ }
+
render() {
if (this._editing && this.props.GetValue() !== undefined) {
- return this.props.autosuggestProps
- ? <Autosuggest
- {...this.props.autosuggestProps.autosuggestProps}
- inputProps={{
- className: "editableView-input",
- onKeyDown: this.onKeyDown,
- autoFocus: true,
- onBlur: e => this.finalizeEdit(e.currentTarget.value, false, true),
- onPointerDown: this.stopPropagation,
- onClick: this.stopPropagation,
- onPointerUp: this.stopPropagation,
- value: this.props.autosuggestProps.value,
- onChange: this.props.autosuggestProps.onChange
- }}
- />
- : <input className="editableView-input"
- defaultValue={this.props.GetValue()}
- onKeyDown={this.onKeyDown}
- autoFocus={true}
- onBlur={e => this.finalizeEdit(e.currentTarget.value, false, true)}
- onPointerDown={this.stopPropagation} onClick={this.stopPropagation} onPointerUp={this.stopPropagation}
- style={{ display: this.props.display, fontSize: this.props.fontSize }}
- />;
+ return this.props.sizeToContent ?
+ <div style={{ display: "grid", minWidth: 100 }}>
+ <div style={{ display: "inline-block", position: "relative", height: 0, width: "100%", overflow: "hidden" }}>{this.props.GetValue()}</div>
+ {this.renderEditor()}
+ </div> : this.renderEditor();
} else {
- this.props.autosuggestProps?.resetValue();
+ setTimeout(() => this.props.autosuggestProps?.resetValue(), 0);
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>
+ style={{ display: this.props.display, minHeight: "17px", whiteSpace: "nowrap", height: `${this.props.height ? this.props.height : "auto"}`, maxHeight: `${this.props.maxHeight}` }}
+ onClick={this.onClick} placeholder={this.props.placeholder}>
+ {this.props.highlight === undefined || this.props.positions === undefined || this.props.bing === undefined ? <span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{this.props.contents ? this.props.contents?.valueOf() : this.props.placeholder?.valueOf()}</span>
+ : this.returnHighlights()}
</div>
);
}