import React = require("react"); import { observer } from "mobx-react"; import { CollectionSubView, CollectionViewProps, SubCollectionViewProps } from "./CollectionSubView"; 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 "./CollectionStackingView.scss"; import { action, reaction } from "mobx"; import { StrCast, NumCast } from "../../../new_fields/Types"; import { Id } from "../../../new_fields/FieldSymbols"; @observer export class CollectionStackingView extends CollectionSubView(doc => doc) { getPreviewTransform = (): Transform => this.props.ScreenToLocalTransform(); 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 moveDocument = (doc: Doc, targetCollection: Doc, addDocument: (document: Doc) => boolean): boolean => { this.props.removeDocument(doc); addDocument(doc); return true; } 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))); return (