aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionMulticolumn
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-04-10 12:05:55 -0400
committerbobzel <zzzman@gmail.com>2025-04-10 12:05:55 -0400
commitb0bb28202fa77556768d1da93bf9ea879c6ba2e5 (patch)
tree85fbc30d8e82a87973d9aa2e8293d3012dc603f4 /src/client/views/collections/collectionMulticolumn
parent2d382a1dd28aa5aae22669988475e5721435b738 (diff)
performance fixes for text boxes to not call screenToLocal unnecessarily. simplifications to template data docs
Diffstat (limited to 'src/client/views/collections/collectionMulticolumn')
-rw-r--r--src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx106
-rw-r--r--src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx106
2 files changed, 106 insertions, 106 deletions
diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx
index f27398427..42b093cc7 100644
--- a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx
+++ b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx
@@ -6,7 +6,7 @@ import { observer } from 'mobx-react';
import * as React from 'react';
import { FaChevronRight } from 'react-icons/fa';
import { Doc, DocListCast } from '../../../../fields/Doc';
-import { BoolCast, DocCast, NumCast, ScriptCast, StrCast } from '../../../../fields/Types';
+import { BoolCast, NumCast, ScriptCast, StrCast } from '../../../../fields/Types';
import { DragManager } from '../../../util/DragManager';
import { SettingsManager } from '../../../util/SettingsManager';
import { Transform } from '../../../util/Transform';
@@ -18,7 +18,7 @@ import ResizeBar from './MulticolumnResizer';
import WidthLabel from './MulticolumnWidthLabel';
import { dropActionType } from '../../../util/DropActionTypes';
import { SnappingManager } from '../../../util/SnappingManager';
-import { DocData } from '../../../../fields/DocSymbols';
+import { computedFn } from 'mobx-utils';
interface WidthSpecifier {
magnitude: number;
@@ -198,15 +198,14 @@ export class CollectionMulticolumnView extends CollectionSubView() {
* documents before the target.
*/
private lookupIndividualTransform = (layout: Doc) => {
- if (this.columnUnitLength === undefined) {
- return Transform.Identity(); // we're still waiting on promises to resolve
- }
- let offset = 0;
- for (const { layout: candidate } of this.childLayoutPairs) {
- if (candidate === layout) {
- return this.ScreenToLocalBoxXf().translate(-offset / (this._props.NativeDimScaling?.() || 1), 0);
+ if (this.columnUnitLength !== undefined) {
+ let offset = 0;
+ for (const { layout: candidate } of this.childLayoutPairs) {
+ if (candidate === layout) {
+ return this.ScreenToLocalBoxXf().translate(-offset / (this._props.NativeDimScaling?.() || 1), 0);
+ }
+ offset += this.lookupPixels(candidate) + resizerWidth;
}
- offset += this.lookupPixels(candidate) + resizerWidth;
}
return Transform.Identity();
};
@@ -262,50 +261,51 @@ export class CollectionMulticolumnView extends CollectionSubView() {
? true
: undefined;
};
- getDisplayDoc = (childLayout: Doc) => {
- const width = () => this.lookupPixels(childLayout);
- const height = () => this._props.PanelHeight() - 2 * NumCast(this.layoutDoc._yMargin) - (BoolCast(this.layoutDoc.showWidthLabels) ? 20 : 0);
- const dxf = () =>
- this.lookupIndividualTransform(childLayout)
+ childHeight = () => this._props.PanelHeight() - 2 * NumCast(this.layoutDoc._yMargin) - (BoolCast(this.layoutDoc.showWidthLabels) ? 20 : 0);
+ childWidth = computedFn((childDoc: Doc) => () => this.lookupPixels(childDoc));
+ childXf = computedFn(
+ (childDoc: Doc) => () =>
+ this.lookupIndividualTransform(childDoc)
.translate(-NumCast(this.layoutDoc._xMargin), -NumCast(this.layoutDoc._yMargin))
- .scale(this._props.NativeDimScaling?.() || 1);
- return (
- <DocumentView
- Document={childLayout}
- TemplateDataDocument={DocCast(childLayout.rootDocument)?.[DocData]}
- styleProvider={this._props.styleProvider}
- containerViewPath={this.childContainerViewPath}
- LayoutTemplate={this._props.childLayoutTemplate}
- LayoutTemplateString={this._props.childLayoutString}
- renderDepth={this._props.renderDepth + 1}
- PanelWidth={width}
- PanelHeight={height}
- rootSelected={this.rootSelected}
- dragAction={StrCast(this.Document.childDragAction, this._props.childDragAction) as dropActionType}
- onClickScript={this.onChildClickHandler}
- onDoubleClickScript={this.onChildDoubleClickHandler}
- suppressSetHeight
- ScreenToLocalTransform={dxf}
- isContentActive={this.isChildContentActive}
- isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive}
- hideResizeHandles={!!(childLayout.layout_fitWidth || this._props.childHideResizeHandles)}
- hideDecorationTitle={this._props.childHideDecorationTitle}
- fitContentsToBox={this._props.fitContentsToBox}
- focus={this._props.focus}
- childFilters={this.childDocFilters}
- childFiltersByRanges={this.childDocRangeFilters}
- searchFilterDocs={this.searchFilterDocs}
- dontRegisterView={this._props.dontRegisterView}
- addDocument={this._props.addDocument}
- moveDocument={this._props.moveDocument}
- removeDocument={this._props.removeDocument}
- whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
- addDocTab={this._props.addDocTab}
- pinToPres={this._props.pinToPres}
- dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as 'x' | 'y' | 'xy'}
- />
- );
- };
+ .scale(this._props.NativeDimScaling?.() || 1)
+ );
+ getDisplayDoc = (childLayout: Doc) => (
+ <DocumentView
+ Document={childLayout}
+ TemplateDataDocument={childLayout.isTemplateDoc || childLayout.isTemplateForField ? this._props.TemplateDataDocument : undefined}
+ styleProvider={this._props.styleProvider}
+ containerViewPath={this.childContainerViewPath}
+ LayoutTemplate={this._props.childLayoutTemplate}
+ LayoutTemplateString={this._props.childLayoutString}
+ renderDepth={this._props.renderDepth + 1}
+ PanelWidth={this.childWidth(childLayout)}
+ PanelHeight={this.childHeight}
+ rootSelected={this.rootSelected}
+ dragAction={StrCast(this.Document.childDragAction, this._props.childDragAction) as dropActionType}
+ onClickScript={this.onChildClickHandler}
+ onDoubleClickScript={this.onChildDoubleClickHandler}
+ suppressSetHeight
+ ScreenToLocalTransform={this.childXf(childLayout)}
+ isContentActive={this.isChildContentActive}
+ isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive}
+ hideResizeHandles={!!(childLayout.layout_fitWidth || this._props.childHideResizeHandles)}
+ hideDecorationTitle={this._props.childHideDecorationTitle}
+ fitContentsToBox={this._props.fitContentsToBox}
+ focus={this._props.focus}
+ childFilters={this.childDocFilters}
+ childFiltersByRanges={this.childDocRangeFilters}
+ searchFilterDocs={this.searchFilterDocs}
+ dontRegisterView={this._props.dontRegisterView}
+ addDocument={this._props.addDocument}
+ moveDocument={this._props.moveDocument}
+ removeDocument={this._props.removeDocument}
+ whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
+ addDocTab={this._props.addDocTab}
+ pinToPres={this._props.pinToPres}
+ dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as 'x' | 'y' | 'xy'}
+ />
+ );
+
/**
* @returns the resolved list of rendered child documents, displayed
* at their resolved pixel widths, each separated by a resizer.
diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx b/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx
index f95928cf6..6bbe55f54 100644
--- a/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx
+++ b/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx
@@ -2,7 +2,7 @@ import { action, computed, makeObservable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Doc, DocListCast } from '../../../../fields/Doc';
-import { BoolCast, DocCast, NumCast, ScriptCast, StrCast } from '../../../../fields/Types';
+import { BoolCast, NumCast, ScriptCast, StrCast } from '../../../../fields/Types';
import { DragManager } from '../../../util/DragManager';
import { dropActionType } from '../../../util/DropActionTypes';
import { Transform } from '../../../util/Transform';
@@ -11,7 +11,7 @@ import { CollectionSubView, SubCollectionViewProps } from '../CollectionSubView'
import './CollectionMultirowView.scss';
import HeightLabel from './MultirowHeightLabel';
import ResizeBar from './MultirowResizer';
-import { DocData } from '../../../../fields/DocSymbols';
+import { computedFn } from 'mobx-utils';
interface HeightSpecifier {
magnitude: number;
@@ -179,16 +179,14 @@ export class CollectionMultirowView extends CollectionSubView() {
* documents before the target.
*/
private lookupIndividualTransform = (layout: Doc) => {
- if (this.rowUnitLength === undefined) {
- return Transform.Identity(); // we're still waiting on promises to resolve
- }
- let offset = 0;
- // eslint-disable-next-line no-restricted-syntax
- for (const { layout: candidate } of this.childLayoutPairs) {
- if (candidate === layout) {
- return this.ScreenToLocalBoxXf().translate(0, -offset / (this._props.NativeDimScaling?.() || 1));
+ if (this.rowUnitLength !== undefined) {
+ let offset = 0;
+ for (const { layout: candidate } of this.childLayoutPairs) {
+ if (candidate === layout) {
+ return this.ScreenToLocalBoxXf().translate(0, -offset / (this._props.NativeDimScaling?.() || 1));
+ }
+ offset += this.lookupPixels(candidate) + resizerHeight;
}
- offset += this.lookupPixels(candidate) + resizerHeight;
}
return Transform.Identity(); // type coersion, this case should never be hit
};
@@ -244,49 +242,51 @@ export class CollectionMultirowView extends CollectionSubView() {
? true
: undefined;
};
- getDisplayDoc = (layout: Doc) => {
- const height = () => this.lookupPixels(layout);
- const width = () => this._props.PanelWidth() - 2 * NumCast(this.layoutDoc._xMargin) - (BoolCast(this.layoutDoc.showWidthLabels) ? 20 : 0);
- const dxf = () =>
- this.lookupIndividualTransform(layout)
+ childHeight = computedFn((childDoc: Doc) => () => this.lookupPixels(childDoc));
+ childWidth = () => this._props.PanelWidth() - 2 * NumCast(this.layoutDoc._xMargin) - (BoolCast(this.layoutDoc.showWidthLabels) ? 20 : 0);
+ childXf = computedFn(
+ (childDoc: Doc) => () =>
+ this.lookupIndividualTransform(childDoc)
.translate(-NumCast(this.layoutDoc._xMargin), -NumCast(this.layoutDoc._yMargin))
- .scale(this._props.NativeDimScaling?.() || 1);
- return (
- <DocumentView
- Document={layout}
- TemplateDataDocument={DocCast(layout.rootDocument)?.[DocData]}
- styleProvider={this._props.styleProvider}
- containerViewPath={this.childContainerViewPath}
- LayoutTemplate={this._props.childLayoutTemplate}
- LayoutTemplateString={this._props.childLayoutString}
- renderDepth={this._props.renderDepth + 1}
- PanelWidth={width}
- PanelHeight={height}
- rootSelected={this.rootSelected}
- dragAction={StrCast(this.Document.childDragAction, this._props.childDragAction) as dropActionType}
- onClickScript={this.onChildClickHandler}
- onDoubleClickScript={this.onChildDoubleClickHandler}
- ScreenToLocalTransform={dxf}
- isContentActive={this.isChildContentActive}
- isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive}
- hideResizeHandles={!!(layout.layout_fitWidth || this._props.childHideResizeHandles)}
- hideDecorationTitle={this._props.childHideDecorationTitle}
- fitContentsToBox={this._props.fitContentsToBox}
- focus={this._props.focus}
- childFilters={this.childDocFilters}
- childFiltersByRanges={this.childDocRangeFilters}
- searchFilterDocs={this.searchFilterDocs}
- dontRegisterView={this._props.dontRegisterView}
- addDocument={this._props.addDocument}
- moveDocument={this._props.moveDocument}
- removeDocument={this._props.removeDocument}
- whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
- addDocTab={this._props.addDocTab}
- pinToPres={this._props.pinToPres}
- dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as 'y' | 'x' | 'xy'}
- />
- );
- };
+ .scale(this._props.NativeDimScaling?.() || 1)
+ );
+
+ getDisplayDoc = (childLayout: Doc) => (
+ <DocumentView
+ Document={childLayout}
+ TemplateDataDocument={childLayout.isTemplateDoc || childLayout.isTemplateForField ? this._props.TemplateDataDocument : undefined}
+ styleProvider={this._props.styleProvider}
+ containerViewPath={this.childContainerViewPath}
+ LayoutTemplate={this._props.childLayoutTemplate}
+ LayoutTemplateString={this._props.childLayoutString}
+ renderDepth={this._props.renderDepth + 1}
+ PanelWidth={this.childWidth}
+ PanelHeight={this.childHeight(childLayout)}
+ rootSelected={this.rootSelected}
+ dragAction={StrCast(this.Document.childDragAction, this._props.childDragAction) as dropActionType}
+ onClickScript={this.onChildClickHandler}
+ onDoubleClickScript={this.onChildDoubleClickHandler}
+ ScreenToLocalTransform={this.childXf(childLayout)}
+ isContentActive={this.isChildContentActive}
+ isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive}
+ hideResizeHandles={!!(childLayout.layout_fitWidth || this._props.childHideResizeHandles)}
+ hideDecorationTitle={this._props.childHideDecorationTitle}
+ fitContentsToBox={this._props.fitContentsToBox}
+ focus={this._props.focus}
+ childFilters={this.childDocFilters}
+ childFiltersByRanges={this.childDocRangeFilters}
+ searchFilterDocs={this.searchFilterDocs}
+ dontRegisterView={this._props.dontRegisterView}
+ addDocument={this._props.addDocument}
+ moveDocument={this._props.moveDocument}
+ removeDocument={this._props.removeDocument}
+ whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
+ addDocTab={this._props.addDocTab}
+ pinToPres={this._props.pinToPres}
+ dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as 'y' | 'x' | 'xy'}
+ />
+ );
+
/**
* @returns the resolved list of rendered child documents, displayed
* at their resolved pixel widths, each separated by a resizer.