import React = require('react'); import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { computed, ObservableSet } from 'mobx'; import { observer } from 'mobx-react'; import { Doc } from '../../../../fields/Doc'; import { undoBatch } from '../../../util/UndoManager'; import { ViewBoxBaseComponent } from '../../DocComponent'; import { OpenWhere } from '../../nodes/DocumentView'; import { FieldView, FieldViewProps } from '../../nodes/FieldView'; import { CollectionSchemaView } from './CollectionSchemaView'; import './CollectionSchemaView.scss'; import { SchemaTableCell } from './SchemaTableCell'; import { Colors } from '../../global/globalEnums'; import { DocCast, StrCast } from '../../../../fields/Types'; export interface SchemaRowBoxProps extends FieldViewProps { rowIndex: number; columnKeys: string[]; columnWidths: number[]; rowMenuWidth: number; selectedDocs: ObservableSet; selectRow: (e: any, doc: Doc, ref: HTMLDivElement, index: number) => void; startDrag: (e: any, doc: Doc, ref: HTMLDivElement, index: number) => boolean; dragging: boolean; dropIndex: (index: number) => void; addRowRef: (doc: Doc, ref: HTMLDivElement) => void; } @observer export class SchemaRowBox extends ViewBoxBaseComponent() { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(SchemaRowBox, fieldKey); } private _ref: HTMLDivElement | null = null; bounds = () => this._ref?.getBoundingClientRect(); @computed get schemaView() { const vpath = this.props.docViewPath(); console.log(vpath[vpath.length - 2]); return vpath.length > 1 ? (vpath[vpath.length - 2].ComponentView as CollectionSchemaView) : undefined; } @computed get schemaDoc() { return this.props.ContainingCollectionDoc!; } // isSelected = () => this.props.selectedDocs.has(this.props.Document); // @action // onRowPointerDown = (e: React.PointerEvent) => { // e.stopPropagation(); // setupMoveUpEvents( // this, // e, // e => this.props.startDrag(e, this.props.Document, this._ref!, this.props.rowIndex), // emptyFunction, // e => this.props.selectRow(e, this.props.Document, this._ref!, this.props.rowIndex) // ); // }; // onPointerEnter = (e: any) => { // if (!this.props.dragging) return; // document.removeEventListener('pointermove', this.onPointerMove); // document.addEventListener('pointermove', this.onPointerMove); // }; // onPointerMove = (e: any) => { // if (!this.props.dragging) return; // let dragIsRow: boolean = true; // DragManager.docsBeingDragged.forEach(doc => { // dragIsRow = this.props.selectedDocs.has(doc); // }); // if (this._ref && dragIsRow) { // const rect = this._ref.getBoundingClientRect(); // const y = e.clientY - rect.top; //y position within the element. // const height = this._ref.clientHeight; // const halfLine = height / 2; // if (y <= halfLine) { // this._ref.style.borderTop = `solid 2px ${Colors.MEDIUM_BLUE}`; // this._ref.style.borderBottom = '0px'; // this.props.dropIndex(this.props.rowIndex); // } else if (y > halfLine) { // this._ref.style.borderTop = '0px'; // this._ref.style.borderBottom = `solid 2px ${Colors.MEDIUM_BLUE}`; // this.props.dropIndex(this.props.rowIndex + 1); // } // } // }; onPointerLeave = (e: any) => { if (this._ref) { this._ref.style.borderTop = '0px'; this._ref.style.borderBottom = '0px'; } // document.removeEventListener('pointermove', this.onPointerMove); }; render() { return (
{ // row && this.props.addRowRef(this.props.Document, row); this._ref = row; }}>
{ e.stopPropagation(); this.props.removeDocument?.(this.props.Document); })}>
{ e.stopPropagation(); this.props.addDocTab(this.props.Document, OpenWhere.addRight); }}>
{this.schemaView?.columnKeys?.map((key, index) => ( ))}
); } }