diff options
Diffstat (limited to 'src/client/views/DocComponent.tsx')
-rw-r--r-- | src/client/views/DocComponent.tsx | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx index dfc298840..fb8ef7c36 100644 --- a/src/client/views/DocComponent.tsx +++ b/src/client/views/DocComponent.tsx @@ -1,6 +1,6 @@ import { action, computed, makeObservable, observable } from 'mobx'; import * as React from 'react'; -import { returnFalse } from '../../Utils'; +import { emptyPath, returnFalse } from '../../Utils'; import { DateField } from '../../fields/DateField'; import { Doc, DocListCast, Opt } from '../../fields/Doc'; import { AclAdmin, AclAugment, AclEdit, AclPrivate, AclReadonly, DocData } from '../../fields/DocSymbols'; @@ -9,17 +9,20 @@ import { GetEffectiveAcl, inheritParentAcls } from '../../fields/util'; import { DocumentType } from '../documents/DocumentTypes'; import { DocUtils } from '../documents/Documents'; import { DocumentManager } from '../util/DocumentManager'; +import { Transform } from '../util/Transform'; import { ObservableReactComponent } from './ObservableReactComponent'; import { CollectionFreeFormView } from './collections/collectionFreeForm'; import { DocumentView } from './nodes/DocumentView'; -import { Transform } from '../util/Transform'; -/// DocComponent returns a generic React base class used by views that don't have 'fieldKey' props (e.g.,CollectionFreeFormDocumentView, DocumentView) +/** + * DocComponent returns a generic React base class used by Doc views (not the 'Box' views that render the contents of Doc views) + * (e.g.,CollectionFreeFormDocumentView, DocumentViewInternal) + * + * */ export interface DocComponentProps { Document: Doc; LayoutTemplate?: () => Opt<Doc>; LayoutTemplateString?: string; - ScreenToLocalTransform: () => Transform; } export function DocComponent<P extends DocComponentProps>() { class Component extends ObservableReactComponent<React.PropsWithChildren<P>> { @@ -28,8 +31,6 @@ export function DocComponent<P extends DocComponentProps>() { makeObservable(this); } - ScreenToLocalBoxXf = () => this._props.ScreenToLocalTransform(); - //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then get Document() { return this._props.Document; @@ -46,21 +47,40 @@ export function DocComponent<P extends DocComponentProps>() { return Component; } -/// FieldViewBoxProps - a generic base class for field views that are not annotatable (e.g. InkingStroke, ColorBox) -interface ViewBoxBaseProps { +/** + * ViewBoxBaseComponent - base class for non-annotatable views that render the interior contents of a DocumentView + * (e.g. InkingStroke, ColorBox) + */ +export interface ViewBoxBaseProps { Document: Doc; TemplateDataDocument?: Doc; DocumentView?: () => DocumentView; + containerViewPath?: () => DocumentView[]; fieldKey: string; isSelected: () => boolean; isContentActive: () => boolean | undefined; ScreenToLocalTransform: () => Transform; renderDepth: number; } +function returnEmptyDocViewList() { + return [] as DocumentView[]; +} export function ViewBoxBaseComponent<P extends ViewBoxBaseProps>() { class Component extends ObservableReactComponent<React.PropsWithChildren<P>> { ScreenToLocalBoxXf = () => this._props.ScreenToLocalTransform(); + get DocumentView() { + return this._props.DocumentView; + } + get docViewPath() { + return this.DocumentView?.().docViewPath ?? emptyPath; + } + get docViewPathFunc() { + return this.DocumentView?.().docViewPathFunc ?? returnEmptyDocViewList; + } + get containerViewPath() { + return this._props.containerViewPath; + } //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then get Document() { return this._props.Document; @@ -81,10 +101,15 @@ export function ViewBoxBaseComponent<P extends ViewBoxBaseProps>() { return Component; } -/// DocAnnotatbleComponent -return a base class for React views of document fields that are annotatable *and* interactive when selected (e.g., pdf, image) +/** + * DocAnnotatableComponent - base class for annotatable views that render the interior contents of a DocumentView + * (e.g., PdfBox, ImageBox) + * These views should be interactive (respond to pointerEvents) when their conatainer DocumentView is selected + */ export interface ViewBoxAnnotatableProps { Document: Doc; TemplateDataDocument?: Doc; + DocumentView?: () => DocumentView; fieldKey: string; filterAddDocument?: (doc: Doc[]) => boolean; // allows a document that renders a Collection view to filter or modify any documents added to the collection (see PresBox for an example) isContentActive: () => boolean | undefined; @@ -106,6 +131,19 @@ export function ViewBoxAnnotatableComponent<P extends ViewBoxAnnotatableProps>() @observable _annotationKeySuffix = () => 'annotations'; @observable _isAnyChildContentActive = false; + + get DocumentView() { + return this._props.DocumentView; + } + get docViewPath() { + return this.DocumentView?.().docViewPath ?? emptyPath; + } + get docViewPathFunc() { + return this.DocumentView?.().docViewPathFunc ?? returnEmptyDocViewList; + } + get containerViewPath() { + return this.DocumentView?.().containerViewPath ?? returnEmptyDocViewList; + } //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then @computed get Document() { return this._props.Document; |