aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-05-29 12:06:44 -0400
committerbob <bcz@cs.brown.edu>2019-05-29 12:06:44 -0400
commit732cc8c3aec072525535d246b1177181bbd3f7da (patch)
tree0319adf3a98306b64155719cd467a84be2a18be7 /src/client/views/collections
parent7cd5d922930ba1eaed894c2b0a91e3edf4f08164 (diff)
improved stacking view and captions templates.
Diffstat (limited to 'src/client/views/collections')
-rw-r--r--src/client/views/collections/CollectionStackingView.tsx125
-rw-r--r--src/client/views/collections/CollectionSubView.tsx2
2 files changed, 71 insertions, 56 deletions
diff --git a/src/client/views/collections/CollectionStackingView.tsx b/src/client/views/collections/CollectionStackingView.tsx
index a29648d5b..425eecebb 100644
--- a/src/client/views/collections/CollectionStackingView.tsx
+++ b/src/client/views/collections/CollectionStackingView.tsx
@@ -4,9 +4,9 @@ import { CollectionSubView, CollectionViewProps, SubCollectionViewProps } from "
import { Doc, WidthSym, HeightSym, DocListCast } from "../../../new_fields/Doc";
import { DocumentView } from "../nodes/DocumentView";
import { Transform } from "../../util/Transform";
-import { emptyFunction, returnOne } from "../../../Utils";
+import { emptyFunction, returnOne, Utils } from "../../../Utils";
import "./CollectionStackingView.scss";
-import { action, reaction } from "mobx";
+import { action, reaction, trace, computed } from "mobx";
import { StrCast, NumCast } from "../../../new_fields/Types";
import { Id } from "../../../new_fields/FieldSymbols";
@@ -14,20 +14,13 @@ import { Id } from "../../../new_fields/FieldSymbols";
@observer
export class CollectionStackingView extends CollectionSubView(doc => doc) {
- getPreviewTransform = (): Transform => this.props.ScreenToLocalTransform();
+
+ get gridGap() { return 10; }
+ get gridSize() { return 20; }
+ get itemWidth() { return NumCast(this.props.Document.itemWidth, 250); }
constructor(props: SubCollectionViewProps) {
super(props);
- // reaction(() => [this.props.PanelHeight() + this.props.PanelWidth(),
- // (this.props.ContainingCollectionView && this.props.ContainingCollectionView.props.Document[this.props.ContainingCollectionView.props.fieldKey])], () => {
- // if (this.props.ContainingCollectionView) {
- // let allItems = DocListCast(this.props.ContainingCollectionView.props.Document[this.props.ContainingCollectionView.props.fieldKey]);
- // for (let x = 0; x < allItems.length; x++) {
- // resizeGridItem(allItems[x]);
- // }
- // }
- // }
- // );
}
@action
@@ -36,57 +29,79 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) {
addDocument(doc);
return true;
}
+ getDocTransform(doc: Doc, dref: HTMLDivElement) {
+ let { scale, translateX, translateY } = Utils.GetScreenTransform(dref);
+ let outerXf = Utils.GetScreenTransform(this.masonryGridRef!);
+ let offset = this.props.ScreenToLocalTransform().transformDirection(outerXf.translateX - translateX, outerXf.translateY - translateY);
+ return this.props.ScreenToLocalTransform().translate(offset[0], offset[1]).scale(NumCast(doc.width, 1) / this.itemWidth);
+ }
+ masonryGridRef: HTMLDivElement | null = null;
+ createRef = (ele: HTMLDivElement | null) => {
+ this.masonryGridRef = ele;
+ this.createDropTarget(ele!);
+ }
+ @computed
+ get children() {
+ return this.childDocs.map(d => {
+ let colSpan = Math.ceil((this.itemWidth + this.gridGap) / (this.gridSize + this.gridGap));
+ let rowSpan = Math.ceil((this.itemWidth / d[WidthSym]() * d[HeightSym]() + this.gridGap) / (this.gridSize + this.gridGap));
+ let dref = React.createRef<HTMLDivElement>();
+ let dxf = () => this.getDocTransform(d, dref.current!);
+ return (<div className="colletionStackingView-masonryDoc"
+ key={d[Id]}
+ ref={dref}
+ style={{
+ transformOrigin: "top left",
+ gridRowEnd: `span ${rowSpan}`,
+ gridColumnEnd: `span ${colSpan}`,
+ transform: `scale(${this.itemWidth / NumCast(d.nativeWidth, 1)}, ${this.itemWidth / NumCast(d.nativeWidth, 1)})`
+ }} >
+ <DocumentView key={d[Id]} Document={d}
+ addDocument={this.props.addDocument}
+ removeDocument={this.props.removeDocument}
+ moveDocument={this.moveDocument}
+ ContainingCollectionView={this.props.CollectionView}
+ isTopMost={false}
+ ScreenToLocalTransform={dxf}
+ focus={emptyFunction}
+ ContentScaling={returnOne}
+ PanelWidth={d[WidthSym]}
+ PanelHeight={d[HeightSym]}
+ selectOnLoad={false}
+ parentActive={this.props.active}
+ addDocTab={this.props.addDocTab}
+ bringToFront={emptyFunction}
+ toggleMinimized={emptyFunction}
+ whenActiveChanged={this.props.whenActiveChanged} />
+ </div>);
+ })
+ }
+ onClick = (e: React.MouseEvent) => {
+ if (this.props.active()) {
+ let rect = (this.masonryGridRef!.firstChild! as HTMLElement).getBoundingClientRect();
+ if (e.clientX < rect.left || e.clientX > rect.right || e.clientY > rect.bottom) this.props.select(false);
+ e.stopPropagation();
+ }
+ }
render() {
- const docs = this.childDocs;
- let gridGap = 10;
- let gridSize = 20;
- let itemWidth = NumCast(this.props.Document.itemWidth, 250);
let leftMargin = 20;
let topMargin = 20;
- let itemCols = Math.ceil(itemWidth / (gridSize + gridGap));
- let cells = Math.floor((this.props.PanelWidth() - leftMargin) / (itemCols * (gridSize + gridGap)));
+ let itemCols = Math.ceil(this.itemWidth / (this.gridSize + this.gridGap));
+ let cells = Math.floor((this.props.PanelWidth() - leftMargin) / (itemCols * (this.gridSize + this.gridGap)));
return (
- <div className="collectionStackingView" ref={this.createDropTarget} onWheel={(e: React.WheelEvent) => e.stopPropagation()}>
+ <div className="collectionStackingView" ref={this.createRef} onClick={this.onClick} onWheel={(e: React.WheelEvent) => e.stopPropagation()}>
<div className="collectionStackingview-masonryGrid"
style={{
padding: `${topMargin}px 0px 0px ${leftMargin}px`,
- width: `${cells * itemCols * (gridSize + gridGap) + leftMargin}`,
- margin: "auto", position: "relative",
- gridGap: gridGap,
- gridTemplateColumns: `repeat(auto-fill, minmax(${gridSize}px,1fr))`,
- gridAutoRows: `${gridSize}px`
+ width: `${cells * itemCols * (this.gridSize + this.gridGap) + leftMargin}`,
+ height: "auto",
+ marginLeft: "auto", marginRight: "auto", position: "relative",
+ gridGap: this.gridGap,
+ gridTemplateColumns: `repeat(auto-fill, minmax(${this.gridSize}px,1fr))`,
+ gridAutoRows: `${this.gridSize}px`
}}
>
- {docs.map(d => {
- let colSpan = Math.ceil((itemWidth + gridGap) / (gridSize + gridGap));
- let rowSpan = Math.ceil((itemWidth / d[WidthSym]() * d[HeightSym]() + gridGap) / (gridSize + gridGap));
- return (<div className="mycontent" id={StrCast(d.title, "")}
- key={d[Id]}
- style={{
- transformOrigin: "top left",
- gridRowEnd: `span ${rowSpan}`,
- gridColumnEnd: `span ${colSpan}`,
- transform: `scale(${itemWidth / NumCast(d.nativeWidth, 1)}, ${itemWidth / NumCast(d.nativeWidth, 1)})`
- }} >
- <DocumentView Document={d}
- addDocument={this.props.addDocument}
- removeDocument={this.props.removeDocument}
- moveDocument={this.moveDocument}
- ContainingCollectionView={this.props.CollectionView}
- isTopMost={false}
- ScreenToLocalTransform={this.getPreviewTransform}
- focus={emptyFunction}
- ContentScaling={returnOne}
- PanelWidth={d[WidthSym]}
- PanelHeight={d[HeightSym]}
- selectOnLoad={false}
- parentActive={this.props.active}
- addDocTab={this.props.addDocTab}
- bringToFront={emptyFunction}
- toggleMinimized={emptyFunction}
- whenActiveChanged={this.props.active} />
- </div>);
- })}
+ {this.children}
</div>
</div>
);
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index c4e72b23a..fe9e12640 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -212,7 +212,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) {
}).then(async (res: Response) => {
(await res.json()).map(action((file: any) => {
let path = window.location.origin + file;
- let docPromise = this.getDocumentFromType(type, path, { ...options, nativeWidth: 600, width: 300, title: dropFileName });
+ let docPromise = this.getDocumentFromType(type, path, { ...options, nativeWidth: 300, width: 300, title: dropFileName });
docPromise.then(doc => doc && this.props.addDocument(doc));
}));