aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-08-19 22:30:57 -0400
committerbobzel <zzzman@gmail.com>2020-08-19 22:30:57 -0400
commit5b7d51d47a967e679d17560771efe71522ada13a (patch)
tree37773506a22949fce03c1e948d4406fd5c635df3
parent78a519ad9ef690fbfebb494b50708ed25bb7225b (diff)
more cleanup of SearchBox. made searchMatch be a tri-state for forward/backward/nomatch
-rw-r--r--src/client/views/collections/CollectionSchemaCells.tsx195
-rw-r--r--src/client/views/collections/CollectionTreeView.tsx2
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx11
-rw-r--r--src/client/views/pdf/PDFViewer.tsx2
4 files changed, 58 insertions, 152 deletions
diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx
index f95de5201..626ddf288 100644
--- a/src/client/views/collections/CollectionSchemaCells.tsx
+++ b/src/client/views/collections/CollectionSchemaCells.tsx
@@ -35,6 +35,7 @@ import { DateField } from "../../../fields/DateField";
import { RichTextField } from "../../../fields/RichTextField";
import { DocumentManager } from "../../util/DocumentManager";
import { SearchUtil } from "../../util/SearchUtil";
+import { DocumentType } from "../../documents/DocumentTypes";
const path = require('path');
library.add(faExpand);
@@ -146,10 +147,8 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
}
protected dropRef = (ele: HTMLElement | null) => {
- this._dropDisposer && this._dropDisposer();
- if (ele) {
- this._dropDisposer = DragManager.MakeDropTarget(ele, this.drop.bind(this));
- }
+ this._dropDisposer?.();
+ ele && (this._dropDisposer = DragManager.MakeDropTarget(ele, this.drop.bind(this)));
}
// expandDoc = (e: React.PointerEvent) => {
@@ -326,7 +325,7 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
ref={dragRef} onPointerDown={this.onPointerDown} onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}>
<div className={className} ref={this._focusRef} onPointerDown={onItemDown} tabIndex={-1}>
<div className="collectionSchemaView-cellContents"
- ref={type === undefined || type === "document" ? this.dropRef : null} key={props.Document[Id]}>
+ ref={type === undefined || type === "document" ? this.dropRef : null}>
{!search ?
<EditableView
positions={positions.length > 0 ? positions : undefined}
@@ -439,30 +438,22 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
);
}
- render() {
- return this.renderCellWithType(undefined);
- }
+ render() { return this.renderCellWithType(undefined); }
}
@observer
export class CollectionSchemaNumberCell extends CollectionSchemaCell {
- render() {
- return this.renderCellWithType("number");
- }
+ render() { return this.renderCellWithType("number"); }
}
@observer
export class CollectionSchemaBooleanCell extends CollectionSchemaCell {
- render() {
- return this.renderCellWithType("boolean");
- }
+ render() { return this.renderCellWithType("boolean"); }
}
@observer
export class CollectionSchemaStringCell extends CollectionSchemaCell {
- render() {
- return this.renderCellWithType("string");
- }
+ render() { return this.renderCellWithType("string"); }
}
@observer
@@ -792,25 +783,14 @@ export class CollectionSchemaListCell extends CollectionSchemaCell {
this._opened = open;
}
- // @action
- // onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
- // this._text = e.target.value;
-
- // // change if its a document
- // this._optionsList[this._selectedNum] = this._text;
- // }
-
@action
onSetValue = (value: string) => {
-
-
this._text = value;
// change if its a document
this._optionsList[this._selectedNum] = this._text;
(this.prop.Document[this.prop.fieldKey] as List<any>).splice(this._selectedNum, 1, value);
-
}
@action
@@ -824,55 +804,34 @@ export class CollectionSchemaListCell extends CollectionSchemaCell {
this._overlayDisposer = OverlayView.Instance.addElement(<DocumentIconContainer />, { x: 0, y: 0 });
}
-
render() {
-
- const dragRef: React.RefObject<HTMLDivElement> = React.createRef();
-
let type = "list";
-
let link = false;
- let doc = false;
const reference = React.createRef<HTMLDivElement>();
if (typeof this._field === "object" && this._optionsList[0]) {
-
- const options = this._optionsList.map((element, index) => {
-
- if (element instanceof Doc) {
- doc = true;
- type = "document";
- if (this.prop.fieldKey.toLowerCase() === "links") {
- link = true;
- type = "link";
+ const options = !this._opened ? (null) : <div>
+ {this._optionsList.map((element, index) => {
+ let title = "";
+ if (element instanceof Doc) {
+ type = "document";
+ if (this.prop.fieldKey.toLowerCase() === "links") {
+ link = true;
+ type = "link";
+ }
+ title = StrCast(element.title);
}
- const document = FieldValue(Cast(element, Doc));
- const title = element.title;
- return <div
- className="collectionSchemaView-dropdownOption"
- onPointerDown={(e) => { this.onSelected(StrCast(element.title), index); }}
- style={{ padding: "6px" }}>
+ return <div className="collectionSchemaView-dropdownOption" style={{ padding: "6px" }}
+ onPointerDown={(e) => this.onSelected(StrCast(element), index)} >
+ {element}
{title}
</div>;
-
- } else {
- return <div
- className="collectionSchemaView-dropdownOption"
- onPointerDown={(e) => { this.onSelected(StrCast(element), index); }}
- style={{ padding: "6px" }}>{element}</div>;
- }
- });
+ })}
+ </div>;
const plainText = <div style={{ padding: "5.9px" }}>{this._text}</div>;
- // const textarea = <textarea onChange={this.onChange} value={this._text}
- // onFocus={doc ? this.onFocus : undefined}
- // onBlur={doc ? e => this._overlayDisposer?.() : undefined}
- // style={{ resize: "none" }}
- // placeholder={"select an item"}></textarea>;
-
- const textarea = <div className="collectionSchemaView-cellContents"
- style={{ padding: "5.9px" }}
- ref={type === undefined || type === "document" ? this.dropRef : null} key={this.prop.Document[Id]}>
+ const textarea = <div className="collectionSchemaView-cellContents" key={this.prop.Document[Id]} style={{ padding: "5.9px" }}
+ ref={type === undefined || type === "document" ? this.dropRef : null} >
<EditableView
editing={this._isEditing}
isEditingCallback={this.isEditingCallback}
@@ -880,11 +839,8 @@ export class CollectionSchemaListCell extends CollectionSchemaCell {
contents={this._text}
height={"auto"}
maxHeight={Number(MAX_ROW_HEIGHT)}
- GetValue={() => {
- return this._text;
- }}
+ GetValue={() => this._text}
SetValue={action((value: string) => {
-
// add special for params
this.onSetValue(value);
return true;
@@ -893,37 +849,26 @@ export class CollectionSchemaListCell extends CollectionSchemaCell {
</div >;
//☰
-
- const dropdown = <div>
- {options}
- </div>;
-
return (
<div className="collectionSchemaView-cellWrapper" ref={this._focusRef} tabIndex={-1} onPointerDown={this.onPointerDown}>
<div className="collectionSchemaView-cellContents" key={this._document[Id]} ref={reference}>
<div className="collectionSchemaView-dropDownWrapper">
- <button type="button" className="collectionSchemaView-dropdownButton" onClick={(e) => { this.toggleOpened(!this._opened); }}
- style={{ right: "length", position: "relative" }}>
- {this._opened ? <FontAwesomeIcon icon="caret-up" size="lg" ></FontAwesomeIcon>
- : <FontAwesomeIcon icon="caret-down" size="lg" ></FontAwesomeIcon>}
+ <button type="button" className="collectionSchemaView-dropdownButton" style={{ right: "length", position: "relative" }}
+ onClick={e => this.toggleOpened(!this._opened)} >
+ <FontAwesomeIcon icon={this._opened ? "caret-up" : "caret-down"} size="lg" />
</button>
<div className="collectionSchemaView-dropdownText"> {link ? plainText : textarea} </div>
</div>
-
- {this._opened ? dropdown : null}
+ {options}
</div >
</div>
);
- } else {
- return this.renderCellWithType("list");
}
+ return this.renderCellWithType("list");
}
}
-
-
-
@observer
export class CollectionSchemaCheckboxCell extends CollectionSchemaCell {
@observable private _isChecked: boolean = typeof this.props.rowProps.original[this.props.rowProps.column.id as string] === "boolean" ? BoolCast(this.props.rowProps.original[this.props.rowProps.column.id as string]) : false;
@@ -932,15 +877,13 @@ export class CollectionSchemaCheckboxCell extends CollectionSchemaCell {
toggleChecked = (e: React.ChangeEvent<HTMLInputElement>) => {
this._isChecked = e.target.checked;
const script = CompileScript(e.target.checked.toString(), { requiredType: "boolean", addReturn: true, params: { this: Doc.name } });
- if (script.compiled) {
- this.applyToDoc(this._document, this.props.row, this.props.col, script.run);
- }
+ script.compiled && this.applyToDoc(this._document, this.props.row, this.props.col, script.run);
}
render() {
const reference = React.createRef<HTMLDivElement>();
const onItemDown = (e: React.PointerEvent) => {
- (!this.props.CollectionView || !this.props.CollectionView.props.isSelected() ? undefined :
+ (!this.props.CollectionView?.props.isSelected() ? undefined :
SetupDrag(reference, () => this._document, this.props.moveDocument, this.props.Document.schemaDoc ? "copy" : undefined)(e));
};
return (
@@ -956,62 +899,28 @@ export class CollectionSchemaCheckboxCell extends CollectionSchemaCell {
@observer
export class CollectionSchemaButtons extends CollectionSchemaCell {
-
render() {
+ const doc = this.props.rowProps.original;
+ const searchMatch = (backward: boolean = true) => { doc.searchMatch = undefined; setTimeout(() => doc.searchMatch = backward, 0); };
// const reference = React.createRef<HTMLDivElement>();
// const onItemDown = (e: React.PointerEvent) => {
// (!this.props.CollectionView || !this.props.CollectionView.props.isSelected() ? undefined :
// SetupDrag(reference, () => this._document, this.props.moveDocument, this.props.Document.schemaDoc ? "copy" : undefined)(e));
// };
- const doc = this.props.rowProps.original;
- let buttons: JSX.Element | undefined = undefined;
- buttons = <div style={{
- paddingTop: 8,
- paddingLeft: 3,
- }}><button onClick={() => {
- doc.searchMatch = false;
- setTimeout(() => doc.searchMatch = true, 0);
- }} style={{ padding: 2, left: 77 }}>
- <FontAwesomeIcon icon="arrow-up" size="sm" />
- </button>
- <button onClick={() => {
- {
- doc.searchMatchAlt = false;
- setTimeout(() => doc.searchMatchAlt = true, 0);
- }
- }} style={{ padding: 2 }}>
- <FontAwesomeIcon icon="arrow-down" size="sm" />
- </button></div>;
- const type = StrCast(doc.type);
- if (type === "pdf") {
- buttons = <div><button
- style={{
- position: "relative",
- height: 30,
- width: 28,
- left: 1,
- }}
-
- onClick={() => {
- doc.searchMatch = false;
- setTimeout(() => doc.searchMatch = true, 0);
- }}>
- <FontAwesomeIcon icon="arrow-down" size="sm" />
- </button></div >;
- }
- else if (type !== "rtf") {
- buttons = undefined;
- }
-
- if (BoolCast(this.props.Document._searchDoc) === true) {
-
- }
- else {
- buttons = undefined;
- }
- return (
- <div> {buttons}</div>
- );
- }
-}
-
+ return !BoolCast(this.props.Document._searchDoc) ? <></>
+ : StrCast(doc.type) === DocumentType.PDF ?
+ <button style={{ position: "relative", height: 30, width: 28, left: 1, }} onClick={() => searchMatch(false)}>
+ <FontAwesomeIcon icon="arrow-down" size="sm" />
+ </button>
+ : StrCast(doc.type) === DocumentType.RTF ?
+ <div style={{ paddingTop: 8, paddingLeft: 3, }} >
+ <button style={{ padding: 2, left: 77 }} onClick={() => searchMatch(true)}>
+ <FontAwesomeIcon icon="arrow-up" size="sm" />
+ </button>
+ <button style={{ padding: 2 }} onClick={() => searchMatch(false)} >
+ <FontAwesomeIcon icon="arrow-down" size="sm" />
+ </button>
+ </div> :
+ <></>;
+ }
+} \ No newline at end of file
diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx
index f23fa8eb6..0f6274663 100644
--- a/src/client/views/collections/CollectionTreeView.tsx
+++ b/src/client/views/collections/CollectionTreeView.tsx
@@ -469,7 +469,7 @@ class TreeView extends React.Component<TreeViewProps> {
return <>
<div className="docContainer" ref={this._tref} title="click to edit title" id={`docContainer-${this.props.parentKey}`}
style={{
- fontWeight: this.doc.searchMatch ? "bold" : undefined,
+ fontWeight: this.doc.searchMatch !== undefined ? "bold" : undefined,
textDecoration: Doc.GetT(this.doc, "title", "string", true) ? "underline" : undefined,
outline: BoolCast(this.doc.workspaceBrush) ? "dashed 1px #06123232" : undefined,
pointerEvents: this.props.active() || SnappingManager.GetIsDragging() ? undefined : "none"
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index 0f2f90c1d..d58d75226 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -374,7 +374,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
this._editorView.dispatch(tr.addMark(flattened[lastSel].from, flattened[lastSel].to, link));
}
}
- public highlightSearchTerms = (terms: string[], alt: boolean) => {
+ public highlightSearchTerms = (terms: string[], backward: boolean) => {
if (this._editorView && (this._editorView as any).docView && terms.some(t => t)) {
@@ -391,7 +391,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
}
else {
this._searchIndex = ++this._searchIndex > flattened.length - 1 ? 0 : this._searchIndex;
- if (alt === true) {
+ if (backward === true) {
if (this._searchIndex > 1) {
this._searchIndex += -2;
}
@@ -907,12 +907,9 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
this.setupEditor(this.config, this.props.fieldKey);
- this._disposers.searchAlt = reaction(() => this.rootDoc.searchMatchAlt,
- search => search ? this.highlightSearchTerms([Doc.SearchQuery()], false) : this.unhighlightSearchTerms(),
- { fireImmediately: true });
this._disposers.search = reaction(() => this.rootDoc.searchMatch,
- search => search ? this.highlightSearchTerms([Doc.SearchQuery()], true) : this.unhighlightSearchTerms(),
- { fireImmediately: this.rootDoc.searchMatch ? true : false });
+ search => search !== undefined ? this.highlightSearchTerms([Doc.SearchQuery()], BoolCast(search)) : this.unhighlightSearchTerms(),
+ { fireImmediately: this.rootDoc.searchMatch !== undefined ? true : false });
this._disposers.record = reaction(() => this._recording,
() => {
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 965d568e6..0916e8b0c 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -152,7 +152,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu
this._mainCont.current && (this._mainCont.current.scrollTop = this.layoutDoc._scrollTop || 0);
this._searchReactionDisposer = reaction(() => this.Document.searchMatch,
m => {
- if (m) (this._lastSearch = true) && this.search(Doc.SearchQuery(), true);
+ if (m !== undefined) (this._lastSearch = true) && this.search(Doc.SearchQuery(), true);
else !(this._lastSearch = false) && setTimeout(() => !this._lastSearch && this.search("", false, true), 200);
}, { fireImmediately: true });