aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DocumentView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/DocumentView.tsx')
-rw-r--r--src/client/views/nodes/DocumentView.tsx48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 7ec0382e4..7f1e547e4 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -110,7 +110,7 @@ export interface DocFocusOptions {
easeFunc?: 'linear' | 'ease'; // transition method for scrolling
}
export type DocFocusFunc = (doc: Doc, options: DocFocusOptions) => Opt<number>;
-export type StyleProviderFunc = (doc: Opt<Doc>, props: Opt<DocumentViewProps | FieldViewProps>, property: string) => any;
+export type StyleProviderFunc = (doc: Opt<Doc>, props: Opt<DocumentViewInternalProps | FieldViewProps>, property: string) => any;
export interface DocComponentView {
fieldKey?: string;
annotationKey?: string;
@@ -394,11 +394,9 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
const views = SelectionManager.Views.filter(dv => dv.docView?._mainCont.current);
const selected = views.length > 1 && views.some(dv => dv.Document === this.Document) ? views : [this._props.DocumentView()];
const dragData = new DragManager.DocumentDragData(selected.map(dv => dv.Document));
- const [left, top] = this._props.ScreenToLocalTransform().scale(this.NativeDimScaling).inverse().transformPoint(0, 0);
- dragData.offset = this._props
- .ScreenToLocalTransform()
- .scale(this.NativeDimScaling)
- .transformDirection(x - left, y - top);
+ const screenXf = this.props.DocumentView().screenToViewTransform();
+ const [left, top] = screenXf.inverse().transformPoint(0, 0);
+ dragData.offset = screenXf.transformDirection(x - left, y - top);
dragData.dropAction = dropAction;
dragData.treeViewDoc = this._props.treeViewDoc;
dragData.removeDocument = this._props.removeDocument;
@@ -881,7 +879,7 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
}
rootSelected = () => this._rootSelected;
panelHeight = () => this._props.PanelHeight() - this.headerMargin;
- contentScreenToLocal = () => this._props.ScreenToLocalTransform().translate(0, -this.headerMargin);
+ screenToLocalContent = () => this.ScreenToLocalBoxXf().translate(0, -this.headerMargin);
onClickFunc: any = () => (this.disableClickScriptFunc ? undefined : this.onClickHandler);
setHeight = (height: number) => !this._props.suppressSetHeight && (this.layoutDoc._height = height);
setContentView = action((view: { getAnchor?: (addAsAnnotation: boolean) => Doc; forward?: () => boolean; back?: () => boolean }) => (this._componentView = view));
@@ -925,7 +923,7 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
PanelHeight={this.panelHeight}
setHeight={this.setHeight}
isContentActive={this.isContentActive}
- ScreenToLocalTransform={this.contentScreenToLocal}
+ ScreenToLocalTransform={this.screenToLocalContent}
rootSelected={this.rootSelected}
onClick={this.onClickFunc}
setTitleFocus={this.setTitleFocus}
@@ -938,7 +936,7 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
anchorPanelWidth = () => this._props.PanelWidth() || 1;
anchorPanelHeight = () => this._props.PanelHeight() || 1;
- anchorStyleProvider = (doc: Opt<Doc>, props: Opt<DocumentViewProps>, property: string): any => {
+ anchorStyleProvider = (doc: Opt<Doc>, props: Opt<DocumentViewInternalProps | FieldViewProps>, property: string): any => {
// prettier-ignore
switch (property.split(':')[0]) {
case StyleProp.ShowTitle: return '';
@@ -1073,7 +1071,7 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps
}
};
- captionStyleProvider = (doc: Opt<Doc>, props: Opt<DocumentViewProps>, property: string) => this._props?.styleProvider?.(doc, props, property + ':caption');
+ captionStyleProvider = (doc: Opt<Doc>, props: Opt<DocumentViewInternalProps | FieldViewProps>, property: string) => this._props?.styleProvider?.(doc, props, property + ':caption');
@observable _changingTitleField = false;
@observable _dropDownInnerWidth = 0;
fieldsDropdown = (inputOptions: string[], dropdownWidth: number, placeholder: string, onChange: (val: string | number) => void, onClose: () => void) => {
@@ -1431,11 +1429,20 @@ export class DocumentView extends ObservableReactComponent<DocumentViewProps> {
return this._props.LayoutTemplateString?.includes('link_anchor_2') ? DocCast(this.Document['link_anchor_2']) : this._props.LayoutTemplateString?.includes('link_anchor_1') ? DocCast(this.Document['link_anchor_1']) : undefined;
}
@computed get hideLinkButton() {
- return this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.HideLinkBtn + (this.IsSelected ? ':selected' : ''));
+ return (
+ this._props.hideLinkButton ||
+ this._props.renderDepth === -1 || //
+ (this.IsSelected && this._props.renderDepth) ||
+ !this._isHovering ||
+ (!this.IsSelected && this.layoutDoc.layout_hideLinkButton) ||
+ SnappingManager.IsDragging ||
+ SnappingManager.IsResizing
+ );
}
- hideLinkCount = () => false; // this._props.renderDepth === -1 || (this.IsSelected && this._props.renderDepth) || !this._isHovering || this.hideLinkButton;
+ hideLinkCount = () => (this.hideLinkButton ? true : false);
+
@computed get linkCountView() {
- return <DocumentLinksButton hideCount={this.hideLinkCount} View={this} scaling={this.scaleToScreenSpace} OnHover={true} Bottom={this.topMost} ShowCount={true} />;
+ return <DocumentLinksButton hideCount={this.hideLinkCount} View={this} scaling={this.screenToLocalScale} OnHover={true} Bottom={this.topMost} ShowCount={true} />;
}
@computed get docViewPath(): DocumentView[] {
return this._props.docViewPath ? [...this._props.docViewPath(), this] : [this];
@@ -1508,7 +1515,7 @@ export class DocumentView extends ObservableReactComponent<DocumentViewProps> {
if (this.docView._componentView?.screenBounds?.()) {
return this.docView._componentView.screenBounds();
}
- const xf = this.docView._props.ScreenToLocalTransform().scale(this.nativeScaling).inverse();
+ const xf = this.docView.ScreenToLocalBoxXf().scale(this.nativeScaling).inverse();
const [[left, top], [right, bottom]] = [xf.transformPoint(0, 0), xf.transformPoint(this.panelWidth, this.panelHeight)];
if (this.docView._props.LayoutTemplateString?.includes(LinkAnchorBox.name)) {
@@ -1566,7 +1573,7 @@ export class DocumentView extends ObservableReactComponent<DocumentViewProps> {
};
layout_fitWidthFunc = (doc: Doc) => BoolCast(this.layout_fitWidth);
- scaleToScreenSpace = () => this._props.ScreenToLocalTransform().Scale;
+ screenToLocalScale = () => this._props.ScreenToLocalTransform().Scale;
docViewPathFunc = () => this.docViewPath;
isSelected = () => this.IsSelected;
select = (extendSelection: boolean, focusSelection?: boolean) => {
@@ -1589,7 +1596,14 @@ export class DocumentView extends ObservableReactComponent<DocumentViewProps> {
PanelHeight = () => this.panelHeight;
NativeDimScaling = () => this.nativeScaling;
selfView = () => this;
- screenToNativeLocalTransform = () =>
+ /**
+ * @returns Transform to the document view (in the coordinate system of whatever contains the DocumentView)
+ */
+ screenToViewTransform = () => this._props.ScreenToLocalTransform();
+ /**
+ * @returns Transform to the coordinate system of the contents of the document view (includes native dimension scaling and centering)
+ */
+ screenToContentsTransform = () =>
this._props
.ScreenToLocalTransform()
.translate(-this.centeringX, -this.centeringY)
@@ -1676,7 +1690,7 @@ export class DocumentView extends ObservableReactComponent<DocumentViewProps> {
isSelected={this.isSelected}
select={this.select}
layout_fitWidth={this.layout_fitWidthFunc}
- ScreenToLocalTransform={this.screenToNativeLocalTransform}
+ ScreenToLocalTransform={this.screenToContentsTransform}
focus={this._props.focus || emptyFunction}
ref={action((r: DocumentViewInternal | null) => r && (this.docView = r))}
/>