aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/ViewBoxInterface.ts
blob: 83e3958673628e76f81bbdc57a1dfdffec80c93d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as React from 'react';
import { Doc, FieldType, Opt } from '../../fields/Doc';
import { RefField } from '../../fields/RefField';
import { DragManager } from '../util/DragManager';
import { ObservableReactComponent } from './ObservableReactComponent';
import { PinProps } from './PinFuncs';
import { DocumentView } from './nodes/DocumentView';
import { FocusViewOptions } from './nodes/FocusViewOptions';
import { OpenWhere } from './nodes/OpenWhere';
// import { DocUtils } from '../documents/Documents';

/**
 * Shared interface among all viewBox'es (ie, react classes that render the contents of a Doc)
 * Many of these methods only make sense for specific viewBox'es, but they should be written to
 * be as general as possible
 */
export abstract class ViewBoxInterface<P> extends ObservableReactComponent<React.PropsWithChildren<P>> {
    abstract get Document(): Doc;
    abstract get dataDoc(): Doc;
    abstract get fieldKey(): string;
    get annotationKey(): string {
        return ''; //
    }
    promoteCollection?: () => void; // moves contents of collection to parent
    hasChildDocs?: () => Doc[];
    docEditorView?: () => void;
    autoTag?: () => void; // auto tag the document
    isOutpaintable?: () => boolean; // can document be resized and outpainted
    showSmartDraw?: (x: number, y: number, regenerate?: boolean) => void;
    updateIcon?: (usePanelDimensions?: boolean) => Promise<void>; // updates the icon representation of the document
    getAnchor?: (addAsAnnotation: boolean, pinData?: PinProps) => Doc; // returns an Anchor Doc that represents the current state of the doc's componentview (e.g., the current playhead location of a an audio/video box)
    restoreView?: (viewSpec: Doc) => boolean; // DEPRECATED: do not use, it will go away.  see PresBox.restoreTargetDocView
    scrollPreview?: (docView: DocumentView, doc: Doc, focusSpeed: number, options: FocusViewOptions) => Opt<number>; // returns the duration of the focus
    brushView?: (view: { width: number; height: number; panX: number; panY: number }, transTime: number, holdTime: number) => void; // highlight a region of a view (used by freeforms)
    getView?: (doc: Doc, options: FocusViewOptions) => Promise<Opt<DocumentView>>; // returns a nested DocumentView for the specified doc or undefined
    addDocTab?: (doc: Doc, where: OpenWhere) => boolean; // determines how to add a document - used in following links to open the target ina local lightbox
    addDocument?: (doc: Doc | Doc[], annotationKey?: string) => boolean; // add a document (used only by collections)
    removeDocument?: (doc: Doc | Doc[], annotationKey?: string, leavePushpin?: boolean, dontAddToRemoved?: boolean) => boolean; // add a document (used only by collections)
    select?: (ctrlKey: boolean, shiftKey: boolean) => void;
    focus?: (textAnchor: Doc, options: FocusViewOptions) => Opt<number>;
    viewTransition?: () => Opt<string>; // duration of a view transition animation
    isAnyChildContentActive?: () => boolean; // is any child content of the document active
    onClickScriptDisable?: () => 'never' | 'always'; // disable click scripts : never, always, or undefined = only when selected
    getKeyFrameEditing?: () => boolean; // whether the document is in keyframe editing mode (if it is, then all hidden documents that are not active at the keyframe time will still be shown)
    setKeyFrameEditing?: (set: boolean) => void; // whether the document is in keyframe editing mode (if it is, then all hidden documents that are not active at the keyframe time will still be shown)
    playTrail?: (docs: Doc[]) => void;
    playFrom?: (time: number, endTime?: number, fullPlay?: boolean) => void; // play a range of a media document
    Play?: () => void; // play a media documents
    Pause?: () => void; // pause a media document (eg, audio/video)
    IsPlaying?: () => boolean; // is a media document playing
    PlayerTime?: () => number | undefined; // current timecode of player
    TogglePause?: (keep?: boolean) => void; // toggle media document playing state
    setFocus?: () => void; // sets input focus to the componentView
    setData?: (data: FieldType | Promise<RefField | undefined>) => boolean;
    componentUI?: (boundsLeft: number, boundsTop: number) => JSX.Element | null;
    dragStarting?: (snapToDraggedDoc: boolean, showGroupDragTarget: boolean, visited: Set<Doc>) => void;
    dragConfig?: (dragData: DragManager.DocumentDragData) => void; // function to setup dragData in custom way (see TreeViews which add a tree view flag)
    incrementalRendering?: () => void;
    infoUI?: () => JSX.Element | null;
    contentBounds?: () => undefined | { bounds: { x: number; y: number; r: number; b: number }; cx: number; cy: number; width: number; height: number }; // bounds of contents in collection coordinate space (used by TabDocViewThumb)
    screenBounds?: () => Opt<{ left: number; top: number; right: number; bottom: number; transition?: string }>;
    ptToScreen?: (pt: { X: number; Y: number }) => { X: number; Y: number };
    ptFromScreen?: (pt: { X: number; Y: number }) => { X: number; Y: number };
    snapPt?: (pt: { X: number; Y: number }, excludeSegs?: number[]) => { nearestPt: { X: number; Y: number }; distance: number };
    search?: (str: string, bwd?: boolean, clear?: boolean) => boolean;
    dontRegisterView?: () => boolean; // KeyValueBox's don't want to register their views
    isUnstyledView?: () => boolean; // SchemaView and KeyValue are unstyled -- not titles, no opacity, no animations
    componentAIView?: () => JSX.Element;
}