aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-07-28 17:59:22 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-07-28 17:59:22 -0400
commitaaf1776644f6701462022cccc7088c24b5c72000 (patch)
tree6b96636c5346a431adccd58142f0a384426b396f /src/client/views/collections
parentbe1e6e967a60f49eec1cb1d404912b0736812323 (diff)
parentcb2347347c8d9d2a0f1531479c73ecbcb3008128 (diff)
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web
Diffstat (limited to 'src/client/views/collections')
-rw-r--r--src/client/views/collections/CollectionSchemaCells.tsx65
-rw-r--r--src/client/views/collections/CollectionSchemaView.tsx114
-rw-r--r--src/client/views/collections/CollectionStackingViewFieldColumn.tsx74
-rw-r--r--src/client/views/collections/KeyRestrictionRow.tsx4
4 files changed, 173 insertions, 84 deletions
diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx
index c91f1017b..f1e013edd 100644
--- a/src/client/views/collections/CollectionSchemaCells.tsx
+++ b/src/client/views/collections/CollectionSchemaCells.tsx
@@ -24,7 +24,7 @@ import { SelectionManager } from "../../util/SelectionManager";
import { library } from '@fortawesome/fontawesome-svg-core';
import { faExpand } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { SchemaHeaderField, RandomPastel } from "../../../new_fields/SchemaHeaderField";
+import { SchemaHeaderField } from "../../../new_fields/SchemaHeaderField";
library.add(faExpand);
@@ -44,6 +44,8 @@ export interface CellProps {
setIsEditing: (isEditing: boolean) => void;
isEditable: boolean;
setPreviewDoc: (doc: Doc) => void;
+ setComputed: (script: string, doc: Doc, field: string, row: number, col: number) => boolean;
+ getField: (row: number, col?: number) => void;
}
@observer
@@ -82,11 +84,18 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
@action
onPointerDown = (e: React.PointerEvent): void => {
this.props.changeFocusedCellByIndex(this.props.row, this.props.col);
+ this.props.setPreviewDoc(this.props.rowProps.original);
+
+ let field = this.props.rowProps.original[this.props.rowProps.column.id!];
+ let doc = FieldValue(Cast(field, Doc));
+ if (typeof field === "object" && doc) this.props.setPreviewDoc(doc);
}
- applyToDoc = (doc: Doc, run: (args?: { [name: string]: any }) => any) => {
- const res = run({ this: doc });
+ applyToDoc = (doc: Doc, row: number, col: number, run: (args?: { [name: string]: any }) => any) => {
+ const res = run({ this: doc, $r: row, $c: col, $: (r: number = 0, c: number = 0) => this.props.getField(r + row, c + col) });
if (!res.success) return false;
+ // doc[this.props.fieldKey] = res.result;
+ // return true;
doc[this.props.rowProps.column.id as string] = res.result;
return true;
}
@@ -146,10 +155,16 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
addDocTab: this.props.addDocTab,
};
- // let onItemDown = (e: React.PointerEvent) => {
- // SetupDrag(this._focusRef, () => this._document[props.fieldKey] instanceof Doc ? this._document[props.fieldKey] : this._document,
- // this._document[props.fieldKey] instanceof Doc ? (doc: Doc, target: Doc, addDoc: (newDoc: Doc) => any) => addDoc(doc) : this.props.moveDocument, this._document[props.fieldKey] instanceof Doc ? "alias" : this.props.Document.schemaDoc ? "copy" : undefined)(e);
- // };
+ let field = props.Document[props.fieldKey];
+ let doc = FieldValue(Cast(field, Doc));
+ let fieldIsDoc = (type === "document" && typeof field === "object") || (typeof field === "object" && doc);
+
+ let onItemDown = (e: React.PointerEvent) => {
+ if (fieldIsDoc) {
+ SetupDrag(this._focusRef, () => this._document[props.fieldKey] instanceof Doc ? this._document[props.fieldKey] : this._document,
+ this._document[props.fieldKey] instanceof Doc ? (doc: Doc, target: Doc, addDoc: (newDoc: Doc) => any) => addDoc(doc) : this.props.moveDocument, this._document[props.fieldKey] instanceof Doc ? "alias" : this.props.Document.schemaDoc ? "copy" : undefined)(e);
+ }
+ };
let onPointerEnter = (e: React.PointerEvent): void => {
if (e.buttons === 1 && SelectionManager.GetIsDragging() && (type === "document" || type === undefined)) {
dragRef!.current!.className = "collectionSchemaView-cellContainer doc-drag-over";
@@ -159,7 +174,6 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
dragRef!.current!.className = "collectionSchemaView-cellContainer";
};
- let field = props.Document[props.fieldKey];
let contents: any = "incorrect type";
if (type === undefined) contents = <FieldView {...props} />;
if (type === "number") contents = typeof field === "number" ? NumCast(field) : "--" + typeof field + "--";
@@ -175,18 +189,16 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
if (this.props.isFocused && this.props.isEditable) className += " focused";
if (this.props.isFocused && !this.props.isEditable) className += " inactive";
- let doc = FieldValue(Cast(field, Doc));
- if (type === "document") console.log("doc", typeof field);
- let fieldIsDoc = (type === "document" && typeof field === "object") || (typeof field === "object" && doc);
- let docExpander = (
- <div className="collectionSchemaView-cellContents-docExpander" onPointerDown={this.expandDoc} >
- <FontAwesomeIcon icon="expand" size="sm" />
- </div>
- );
+
+ // let docExpander = (
+ // <div className="collectionSchemaView-cellContents-docExpander" onPointerDown={this.expandDoc} >
+ // <FontAwesomeIcon icon="expand" size="sm" />
+ // </div>
+ // );
return (
- <div className="collectionSchemaView-cellContainer" ref={dragRef} onPointerDown={this.onPointerDown} onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}>
- <div className={className} ref={this._focusRef} tabIndex={-1}>
+ <div className="collectionSchemaView-cellContainer" style={{ cursor: fieldIsDoc ? "grab" : "auto" }} 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]}>
<EditableView
editing={this._isEditing}
@@ -203,24 +215,27 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
}
}
SetValue={(value: string) => {
- let script = CompileScript(value, { requiredType: type, addReturn: true, params: { this: Doc.name } });
+ if (value.startsWith(":=")) {
+ return this.props.setComputed(value.substring(2), props.Document, this.props.rowProps.column.id!, this.props.row, this.props.col);
+ }
+ let script = CompileScript(value, { requiredType: type, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
if (!script.compiled) {
return false;
}
- return this.applyToDoc(props.Document, script.run);
+ return this.applyToDoc(props.Document, this.props.row, this.props.col, script.run);
}}
OnFillDown={async (value: string) => {
- let script = CompileScript(value, { requiredType: type, addReturn: true, params: { this: Doc.name } });
+ let script = CompileScript(value, { requiredType: type, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
if (!script.compiled) {
return;
}
const run = script.run;
- //TODO This should be able to be refactored to compile the script once
const val = await DocListCastAsync(this.props.Document[this.props.fieldKey]);
- val && val.forEach(doc => this.applyToDoc(doc, run));
- }} />
+ val && val.forEach((doc, i) => this.applyToDoc(doc, i, this.props.col, run));
+ }}
+ />
</div >
- {fieldIsDoc ? docExpander : null}
+ {/* {fieldIsDoc ? docExpander : null} */}
</div>
</div>
);
diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index d504f9799..77ed2d8dc 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -202,7 +202,7 @@ export class CollectionSchemaView extends CollectionSubView(doc => doc) {
Document={this.props.Document} // child doc
PanelHeight={this.props.PanelHeight}
PanelWidth={this.props.PanelWidth}
- // childDocs={this.childDocs}
+ childDocs={this.childDocs}
CollectionView={this.props.CollectionView}
ContainingCollectionView={this.props.ContainingCollectionView}
fieldKey={this.props.fieldKey} // might just be this.
@@ -252,7 +252,7 @@ export interface SchemaTableProps {
dataDoc?: Doc;
PanelHeight: () => number;
PanelWidth: () => number;
- // childDocs: Doc[];
+ childDocs: Doc[];
CollectionView: CollectionView | CollectionPDFView | CollectionVideoView;
ContainingCollectionView: Opt<CollectionView | CollectionPDFView | CollectionVideoView>;
fieldKey: string;
@@ -299,8 +299,9 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
let focusedCol = this._focusedCell.col;
let isEditable = !this._headerIsEditing;// && this.props.isSelected();
- let cdoc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = DocListCast(cdoc[this.props.fieldKey]);
+ // let cdoc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
+ // let children = DocListCast(cdoc[this.props.fieldKey]);
+ let children = this.props.childDocs;
if (children.reduce((found, doc) => found || doc.type === "collection", false)) {
columns.push(
@@ -321,13 +322,12 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
}
let cols = this.columns.map(col => {
-
let header = <CollectionSchemaHeader
keyValue={col}
possibleKeys={possibleKeys}
existingKeys={this.columns.map(c => c.heading)}
keyType={this.getColumnType(col)}
- typeConst={col.type !== undefined || columnTypes.get(col.heading) !== undefined}
+ typeConst={columnTypes.get(col.heading) !== undefined}
onSelect={this.changeColumns}
setIsEditing={this.setHeaderIsEditing}
deleteColumn={this.deleteColumn}
@@ -360,7 +360,9 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
moveDocument: this.props.moveDocument,
setIsEditing: this.setCellIsEditing,
isEditable: isEditable,
- setPreviewDoc: this.props.setPreviewDoc
+ setPreviewDoc: this.props.setPreviewDoc,
+ setComputed: this.setComputed,
+ getField: this.getField,
};
let colType = this.getColumnType(col);
@@ -423,7 +425,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
tableRemoveDoc = (document: Doc): boolean => {
let doc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ // let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ let children = this.props.childDocs;
if (children.indexOf(document) !== -1) {
children.splice(children.indexOf(document), 1);
return true;
@@ -518,7 +521,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
this.changeFocusedCellByDirection(direction);
let doc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ // let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ let children = this.props.childDocs;
const pdoc = FieldValue(children[this._focusedCell.row]);
pdoc && this.props.setPreviewDoc(pdoc);
}
@@ -527,7 +531,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
@action
changeFocusedCellByDirection = (direction: string): void => {
let doc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ // let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ let children = this.props.childDocs;
switch (direction) {
case "tab":
if (this._focusedCell.col + 1 === this.columns.length && this._focusedCell.row + 1 === children.length) {
@@ -558,7 +563,7 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
@action
changeFocusedCellByIndex = (row: number, col: number): void => {
let doc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ // let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
this._focusedCell = { row: row, col: col };
this.props.setFocused(this.props.Document);
@@ -569,7 +574,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
createRow = () => {
let doc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ // let children = Cast(doc[this.props.fieldKey], listSpec(Doc), []);
+ let children = this.props.childDocs;
let newDoc = Docs.Create.TextDocument({ width: 100, height: 30 });
let proto = Doc.GetProto(newDoc);
@@ -681,7 +687,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
}
get documentKeys() {
- const docs = DocListCast(this.props.Document[this.props.fieldKey]);
+ // const docs = DocListCast(this.props.Document[this.props.fieldKey]);
+ let docs = this.props.childDocs;
let keys: { [key: string]: boolean } = {};
// bcz: ugh. this is untracked since otherwise a large collection of documents will blast the server for all their fields.
// then as each document's fields come back, we update the documents _proxies. Each time we do this, the whole schema will be
@@ -710,7 +717,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
get reactTable() {
let cdoc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
- let children = DocListCast(cdoc[this.props.fieldKey]);
+ // let children = DocListCast(cdoc[this.props.fieldKey]);
+ let children = this.props.childDocs;
let previewWidth = this.previewWidth(); // + 2 * this.borderWidth + this.DIVIDER_WIDTH + 1;
let hasCollectionChild = children.reduce((found, doc) => found || doc.type === "collection", false);
@@ -756,7 +764,7 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
let csv: string = this.columns.reduce((val, col) => val + col + ",", "");
csv = csv.substr(0, csv.length - 1) + "\n";
let self = this;
- DocListCast(this.props.Document.data).map(doc => {
+ this.props.childDocs.map(doc => {
csv += self.columns.reduce((val, col) => val + (doc[col.heading] ? doc[col.heading]!.toString() : "0") + ",", "");
csv = csv.substr(0, csv.length - 1) + "\n";
});
@@ -772,6 +780,82 @@ export class SchemaTable extends React.Component<SchemaTableProps> {
}
}
+ getField = (row: number, col?: number) => {
+ // const docs = DocListCast(this.props.Document[this.props.fieldKey]);
+
+ let cdoc = this.props.dataDoc ? this.props.dataDoc : this.props.Document;
+ // const docs = DocListCast(cdoc[this.props.fieldKey]);
+ let docs = this.props.childDocs;
+
+ row = row % docs.length;
+ while (row < 0) row += docs.length;
+ const columns = this.columns;
+ const doc = docs[row];
+ if (col === undefined) {
+ return doc;
+ }
+ if (col >= 0 && col < columns.length) {
+ const column = this.columns[col].heading;
+ return doc[column];
+ }
+ return undefined;
+ }
+
+ createTransformer = (row: number, col: number): Transformer => {
+ const self = this;
+ const captures: { [name: string]: Field } = {};
+
+ const transformer: ts.TransformerFactory<ts.SourceFile> = context => {
+ return root => {
+ function visit(node: ts.Node) {
+ node = ts.visitEachChild(node, visit, context);
+ if (ts.isIdentifier(node)) {
+ const isntPropAccess = !ts.isPropertyAccessExpression(node.parent) || node.parent.expression === node;
+ const isntPropAssign = !ts.isPropertyAssignment(node.parent) || node.parent.name !== node;
+ if (isntPropAccess && isntPropAssign) {
+ if (node.text === "$r") {
+ return ts.createNumericLiteral(row.toString());
+ } else if (node.text === "$c") {
+ return ts.createNumericLiteral(col.toString());
+ } else if (node.text === "$") {
+ if (ts.isCallExpression(node.parent)) {
+ // captures.doc = self.props.Document;
+ // captures.key = self.props.fieldKey;
+ }
+ }
+ }
+ }
+
+ return node;
+ }
+ return ts.visitNode(root, visit);
+ };
+ };
+
+ // const getVars = () => {
+ // return { capturedVariables: captures };
+ // };
+
+ return { transformer, /*getVars*/ };
+ }
+
+ setComputed = (script: string, doc: Doc, field: string, row: number, col: number): boolean => {
+ script =
+ `const $ = (row:number, col?:number) => {
+ if(col === undefined) {
+ return (doc as any)[key][row + ${row}];
+ }
+ return (doc as any)[key][row + ${row}][(doc as any).schemaColumns[col + ${col}].heading];
+ }
+ return ${script}`;
+ const compiled = CompileScript(script, { params: { this: Doc.name }, capturedVariables: { doc: this.props.Document, key: this.props.fieldKey }, typecheck: true, transformer: this.createTransformer(row, col) });
+ if (compiled.compiled) {
+ doc[field] = new ComputedField(compiled);
+ return true;
+ }
+ return false;
+ }
+
render() {
// if (SelectionManager.SelectedDocuments().length > 0) console.log(StrCast(SelectionManager.SelectedDocuments()[0].Document.title));
// if (DocumentManager.Instance.getDocumentView(this.props.Document)) console.log(StrCast(this.props.Document.title), SelectionManager.IsSelected(DocumentManager.Instance.getDocumentView(this.props.Document)!))
diff --git a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
index cf6079196..cf5bc451a 100644
--- a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
+++ b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
@@ -69,62 +69,50 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
children(docs: Doc[]) {
let parent = this.props.parent;
- this.props.parent._docXfs.length = 0;
+ parent._docXfs.length = 0;
return docs.map((d, i) => {
- let layoutDoc = Doc.expandTemplateLayout(d, parent.props.DataDoc);
let headings = this.props.headings();
let uniqueHeadings = headings.map((i, idx) => headings.indexOf(i) === idx);
let pair = Doc.GetLayoutDataDocPair(parent.props.Document, parent.props.DataDoc, parent.props.fieldKey, d);
let width = () => (d.nativeWidth && !BoolCast(d.ignoreAspect) ? Math.min(pair.layout[WidthSym](), parent.columnWidth) : parent.columnWidth) / (uniqueHeadings.length + 1);
let height = () => parent.getDocHeight(pair.layout);
- if (parent.singleColumn) {
- let dxf;
- let dref = React.createRef<HTMLDivElement>();
- if (uniqueHeadings.length > 0) {
- dxf = () => this.getDocTransform(layoutDoc, dref.current!);
- this.props.parent._docXfs.push({ dxf: dxf, width: width, height: height });
- }
- else {
- //have to add the height of all previous single column sections or the doc decorations will be in the wrong place.
- dxf = () => this.getSingleDocTransform(layoutDoc, i, width());
- this.props.parent._docXfs.push({ dxf: dxf, width: width, height: height });
- }
- let rowHgtPcnt = height();
- return <div className="collectionStackingView-columnDoc" key={d[Id]} ref={dref} style={{ width: width(), marginTop: i === 0 ? 0 : parent.gridGap, height: `${rowHgtPcnt}` }} >
- {this.props.parent.getDisplayDoc(layoutDoc, d, dxf, width)}
- </div>;
- } else {
- let dref = React.createRef<HTMLDivElement>();
- let dxf = () => this.getDocTransform(layoutDoc, dref.current!);
- this.props.parent._docXfs.push({ dxf: dxf, width: width, height: height });
- let rowHgtPcnt = height();
- let rowSpan = Math.ceil((height() + parent.gridGap) / parent.gridGap);
- let divStyle = parent.singleColumn ? { width: width(), marginTop: i === 0 ? 0 : parent.gridGap, height: `${rowHgtPcnt}` } : { gridRowEnd: `span ${rowSpan}` };
- return <div className="collectionStackingView-masonryDoc" key={d[Id]} ref={dref} style={divStyle} >
- {this.props.parent.getDisplayDoc(layoutDoc, d, dxf, width)}
- </div>;
- }
+ let dref = React.createRef<HTMLDivElement>();
+ // if (uniqueHeadings.length > 0) {
+ let dxf = () => this.getDocTransform(pair.layout, dref.current!);
+ this.props.parent._docXfs.push({ dxf: dxf, width: width, height: height });
+ // }
+ // else {
+ // //have to add the height of all previous single column sections or the doc decorations will be in the wrong place.
+ // let dxf = () => this.getDocTransform(layoutDoc, i, width());
+ // this.props.parent._docXfs.push({ dxf: dxf, width: width, height: height });
+ // }
+ let rowHgtPcnt = height();
+ let rowSpan = Math.ceil((height() + parent.gridGap) / parent.gridGap);
+ let style = parent.singleColumn ? { width: width(), marginTop: i === 0 ? 0 : parent.gridGap, height: `${rowHgtPcnt}` } : { gridRowEnd: `span ${rowSpan}` };
+ return <div className={`collectionStackingView-${parent.singleColumn ? "columnDoc" : "masonryDoc"}`} key={d[Id]} ref={dref} style={style} >
+ {this.props.parent.getDisplayDoc(pair.layout, pair.data, dxf, width)}
+ </div>;
+ // } else {
+ // let dref = React.createRef<HTMLDivElement>();
+ // let dxf = () => this.getDocTransform(layoutDoc, dref.current!);
+ // this.props.parent._docXfs.push({ dxf: dxf, width: width, height: height });
+ // let rowHgtPcnt = height();
+ // let rowSpan = Math.ceil((height() + parent.gridGap) / parent.gridGap);
+ // let divStyle = parent.singleColumn ? { width: width(), marginTop: i === 0 ? 0 : parent.gridGap, height: `${rowHgtPcnt}` } : { gridRowEnd: `span ${rowSpan}` };
+ // return <div className="collectionStackingView-masonryDoc" key={d[Id]} ref={dref} style={divStyle} >
+ // {this.props.parent.getDisplayDoc(layoutDoc, d, dxf, width)}
+ // </div>;
+ // }
});
}
- getSingleDocTransform(doc: Doc, ind: number, width: number) {
- let localY = this.props.parent.filteredChildren.reduce((height, d, i) =>
- height + (i < ind ? this.props.parent.getDocHeight(Doc.expandTemplateLayout(d, this.props.parent.props.DataDoc)) + this.props.parent.gridGap : 0), this.props.parent.yMargin);
- let translate = this.props.parent.props.ScreenToLocalTransform().inverse().transformPoint((this.props.parent.props.PanelWidth() - width) / 2, localY);
- return this.offsetTransform(doc, translate[0], translate[1]);
- }
-
- offsetTransform(doc: Doc, translateX: number, translateY: number) {
- let outerXf = Utils.GetScreenTransform(this.props.parent._masonryGridRef!);
- let offset = this.props.parent.props.ScreenToLocalTransform().transformDirection(outerXf.translateX - translateX, outerXf.translateY - translateY);
- return this.props.parent.props.ScreenToLocalTransform().translate(offset[0], offset[1]).scale(NumCast(doc.width, 1) / this.props.parent.columnWidth);
- }
-
getDocTransform(doc: Doc, dref: HTMLDivElement) {
let { scale, translateX, translateY } = Utils.GetScreenTransform(dref);
let outerXf = Utils.GetScreenTransform(this.props.parent._masonryGridRef!);
let offset = this.props.parent.props.ScreenToLocalTransform().transformDirection(outerXf.translateX - translateX, outerXf.translateY - translateY);
- return this.props.parent.props.ScreenToLocalTransform().translate(offset[0], offset[1]).scale(NumCast(doc.width, 1) / this.props.parent.columnWidth);
+ return this.props.parent.props.ScreenToLocalTransform().
+ translate(offset[0], offset[1] - (this.props.parent.chromeCollapsed ? 0 : 100)).
+ scale(NumCast(doc.width, 1) / this.props.parent.columnWidth);
}
getValue = (value: string): any => {
diff --git a/src/client/views/collections/KeyRestrictionRow.tsx b/src/client/views/collections/KeyRestrictionRow.tsx
index f292557b5..4f3d82114 100644
--- a/src/client/views/collections/KeyRestrictionRow.tsx
+++ b/src/client/views/collections/KeyRestrictionRow.tsx
@@ -18,10 +18,12 @@ export default class KeyRestrictionRow extends React.Component<IKeyRestrictionPr
if (this._key && this._value) {
let parsedValue: string | number = `"${this._value}"`;
let parsed = parseInt(this._value);
+ let type = "string";
if (!isNaN(parsed)) {
parsedValue = parsed;
+ type = "number";
}
- let scriptText = `(doc.${this._key} ${this._contains ? "===" : "!=="} ${parsedValue})`;
+ let scriptText = `${this._contains ? "" : "!"}((doc.${this._key} as ${type})${type === "string" ? ".includes" : "<="}(${parsedValue}))`;
this.props.script(scriptText);
}
return (