aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
diff options
context:
space:
mode:
authormehekj <mehek.jethani@gmail.com>2023-02-27 17:00:49 -0500
committermehekj <mehek.jethani@gmail.com>2023-02-27 17:00:49 -0500
commit222f659b8c291fafce2648e367392dd9f467cb25 (patch)
tree2592b253f380624323285c325cf415d22ea42cbb /src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
parentfecf9bdf8fc6d551e4595af688179950af6ca684 (diff)
rows are documentviews but clipped
Diffstat (limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx96
1 files changed, 71 insertions, 25 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 64c39cf1a..46510b6fe 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -8,7 +8,7 @@ import { RichTextField } from '../../../../fields/RichTextField';
import { listSpec } from '../../../../fields/Schema';
import { BoolCast, Cast, NumCast, StrCast } from '../../../../fields/Types';
import { ImageField } from '../../../../fields/URLField';
-import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnEmptyString, returnFalse, returnTrue, setupMoveUpEvents, Utils } from '../../../../Utils';
+import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnEmptyString, returnFalse, returnTrue, setupMoveUpEvents, smoothScroll, Utils } from '../../../../Utils';
import { Docs, DocUtils } from '../../../documents/Documents';
import { DragManager } from '../../../util/DragManager';
import { SelectionManager } from '../../../util/SelectionManager';
@@ -17,7 +17,7 @@ import { undoBatch } from '../../../util/UndoManager';
import { ContextMenu } from '../../ContextMenu';
import { ContextMenuProps } from '../../ContextMenuItem';
import { EditableView } from '../../EditableView';
-import { DocumentView } from '../../nodes/DocumentView';
+import { DocFocusOptions, DocumentView, ViewAdjustment } from '../../nodes/DocumentView';
import { FormattedTextBox } from '../../nodes/formattedText/FormattedTextBox';
import { CollectionSubView } from '../CollectionSubView';
import './CollectionSchemaView.scss';
@@ -41,9 +41,9 @@ export class CollectionSchemaView extends CollectionSubView() {
private _lastSelectedRow: number | undefined;
private _selectedDocSortedArray: Doc[] = [];
private _closestDropIndex: number = 0;
- private _minColWidth: number = 150;
private _previewRef: HTMLDivElement | null = null;
+ public static _minColWidth: number = 150;
public static _rowMenuWidth: number = 100;
public static _previewDividerWidth: number = 4;
@observable _selectedDocs: ObservableSet = new ObservableSet<Doc>();
@@ -110,6 +110,7 @@ export class CollectionSchemaView extends CollectionSubView() {
}
componentDidMount() {
+ this.props.setContentView?.(this);
document.addEventListener('keydown', this.onKeyDown);
}
@@ -243,8 +244,8 @@ export class CollectionSchemaView extends CollectionSubView() {
if (shrinking === undefined || growing === undefined) return true;
change = Math.abs(change);
- if (this._displayColumnWidths[shrinking] - change < this._minColWidth) {
- change = this._displayColumnWidths[shrinking] - this._minColWidth;
+ if (this._displayColumnWidths[shrinking] - change < CollectionSchemaView._minColWidth) {
+ change = this._displayColumnWidths[shrinking] - CollectionSchemaView._minColWidth;
}
this._displayColumnWidths[shrinking] -= change;
@@ -481,7 +482,7 @@ export class CollectionSchemaView extends CollectionSubView() {
!Doc.noviceMode && ContextMenu.Instance.addItem({ description: 'Containers ...', subitems: layoutItems, icon: 'eye' });
ContextMenu.Instance.setDefaultItem('::', (name: string): void => {
Doc.GetProto(this.props.Document)[name] = '';
- const created = Docs.Create.TextDocument('', { title: name, _width: 250, _autoHeight: true });
+ const created = Docs.Create.TextDocument('', { title: name, _autoHeight: true });
if (created) {
if (this.props.Document.isTemplateDoc) {
Doc.MakeMetadataFieldTemplate(created, this.props.Document);
@@ -492,9 +493,25 @@ export class CollectionSchemaView extends CollectionSubView() {
ContextMenu.Instance.displayMenu(x, y, undefined, true);
};
+ focusDocument = (doc: Doc, options: DocFocusOptions) => {
+ Doc.BrushDoc(doc);
+ let focusSpeed = 0;
+ const found = this._mainCont && Array.from(this._mainCont.getElementsByClassName('documentView-node')).find((node: any) => node.id === doc[Id]);
+ if (found) {
+ const top = found.getBoundingClientRect().top;
+ const localTop = this.props.ScreenToLocalTransform().transformPoint(0, top);
+ if (Math.floor(localTop[1]) !== 0) {
+ smoothScroll((focusSpeed = options.zoomTime ?? 500), this._mainCont!, localTop[1] + this._mainCont!.scrollTop, options.easeFunc);
+ }
+ }
+ const endFocus = async (moved: boolean) => options?.afterFocus?.(moved) ?? ViewAdjustment.doNothing;
+ this.props.focus(this.rootDoc, {
+ ...options,
+ afterFocus: (didFocus: boolean) => new Promise<ViewAdjustment>(res => setTimeout(async () => res(await endFocus(didFocus)), focusSpeed)),
+ });
+ };
isChildContentActive = () =>
this.props.isDocumentActive?.() && (this.props.childDocumentsActive?.() || BoolCast(this.rootDoc.childDocumentsActive)) ? true : this.props.childDocumentsActive?.() === false || this.rootDoc.childDocumentsActive === false ? false : undefined;
-
getDocTransform(doc: Doc, dref?: DocumentView) {
const { scale, translateX, translateY } = Utils.GetScreenTransform(dref?.ContentDiv || undefined);
// the document view may center its contents and if so, will prepend that onto the screenToLocalTansform. so we have to subtract that off
@@ -543,26 +560,55 @@ export class CollectionSchemaView extends CollectionSubView() {
{this.childDocs.map((doc: Doc, index: number) => {
const dataDoc = !doc.isTemplateDoc && !doc.isTemplateForField && !doc.PARAMS ? undefined : this.props.DataDoc;
let dref: Opt<DocumentView>;
-
return (
- <SchemaRowBox
- {...this.props}
- key={index}
- Document={doc}
- ContainingCollectionDoc={this.props.CollectionView?.props.Document}
- ContainingCollectionView={this.props.CollectionView}
- rowIndex={index}
- columnKeys={this.columnKeys}
- columnWidths={this.displayColumnWidths}
- rowMenuWidth={CollectionSchemaView._rowMenuWidth}
- selectedDocs={this._selectedDocs}
- selectRow={this.selectRow}
- startDrag={this.startDrag}
- dragging={this._isDragging}
- dropIndex={this.setDropIndex}
- addRowRef={this.addRowRef}
- />
+ <div className="schema-row-wrapper">
+ <DocumentView
+ {...this.props}
+ ref={r => (dref = r || undefined)}
+ LayoutTemplate={this.props.childLayoutTemplate}
+ LayoutTemplateString={SchemaRowBox.LayoutString(this.props.fieldKey)}
+ renderDepth={this.props.renderDepth + 1}
+ Document={doc}
+ DataDoc={dataDoc}
+ ContainingCollectionView={this.props.CollectionView}
+ ContainingCollectionDoc={this.Document}
+ PanelWidth={() => this.tableWidth}
+ PanelHeight={() => 70}
+ styleProvider={DefaultStyleProvider}
+ focus={this.focusDocument}
+ docFilters={this.childDocFilters}
+ docViewPath={this.props.docViewPath}
+ docRangeFilters={this.childDocRangeFilters}
+ searchFilterDocs={this.searchFilterDocs}
+ rootSelected={this.rootSelected}
+ ScreenToLocalTransform={() => this.getDocTransform(doc, dref)}
+ bringToFront={emptyFunction}
+ isContentActive={this.isChildContentActive}
+ hideDecorations={true}
+ hideTitle={true}
+ hideDocumentButtonBar={true}
+ />
+ </div>
);
+ // return (
+ // <SchemaRowBox
+ // {...this.props}
+ // key={index}
+ // Document={doc}
+ // ContainingCollectionDoc={this.props.CollectionView?.props.Document}
+ // ContainingCollectionView={this.props.CollectionView}
+ // rowIndex={index}
+ // columnKeys={this.columnKeys}
+ // columnWidths={this.displayColumnWidths}
+ // rowMenuWidth={CollectionSchemaView._rowMenuWidth}
+ // selectedDocs={this._selectedDocs}
+ // selectRow={this.selectRow}
+ // startDrag={this.startDrag}
+ // dragging={this._isDragging}
+ // dropIndex={this.setDropIndex}
+ // addRowRef={this.addRowRef}
+ // />
+ // );
})}
</div>
<EditableView GetValue={returnEmptyString} SetValue={this.addNewTextDoc} placeholder={"Type ':' for commands"} contents={'+ New Node'} menuCallback={this.menuCallback} />