From c7878fc9b8df619d77c1323725022997d93c9789 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 22 Feb 2023 19:31:43 -0500 Subject: capture viewType as part of pinning a document/making an anchor to simplify VIewSpec restoration --- src/client/views/collections/CollectionMenu.tsx | 2 +- src/client/views/collections/CollectionTimeView.tsx | 2 -- .../collectionFreeForm/CollectionFreeFormView.tsx | 13 ++++++++----- src/client/views/nodes/DocumentView.tsx | 13 ++++++------- src/client/views/nodes/trails/PresBox.tsx | 15 +++++++++++++-- 5 files changed, 28 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionMenu.tsx b/src/client/views/collections/CollectionMenu.tsx index 17f02711d..c83f4e689 100644 --- a/src/client/views/collections/CollectionMenu.tsx +++ b/src/client/views/collections/CollectionMenu.tsx @@ -746,7 +746,7 @@ export class CollectionFreeFormViewChrome extends React.Component([]); proto.docRangeFilters = ObjectField.MakeCopy(this.layoutDoc._docRangeFilters as ObjectField) || new List([]); - proto[ViewSpecPrefix + '_viewType'] = this.layoutDoc._viewType; if (addAsAnnotation) { // when added as an annotation, links to anchors can be found as links to the document even if the anchors are not rendered diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 132538ea4..d69e6b810 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -38,7 +38,7 @@ import { GestureOverlay } from '../../GestureOverlay'; import { ActiveArrowEnd, ActiveArrowStart, ActiveDash, ActiveFillColor, ActiveInkBezierApprox, ActiveInkColor, ActiveInkWidth, ActiveIsInkMask, InkingStroke, SetActiveInkColor, SetActiveInkWidth } from '../../InkingStroke'; import { LightboxView } from '../../LightboxView'; import { CollectionFreeFormDocumentView } from '../../nodes/CollectionFreeFormDocumentView'; -import { DocFocusOptions, DocumentView, DocumentViewProps, OpenWhere, ViewAdjustment, ViewSpecPrefix } from '../../nodes/DocumentView'; +import { DocFocusOptions, DocumentView, DocumentViewProps, OpenWhere, ViewAdjustment } from '../../nodes/DocumentView'; import { FieldViewProps } from '../../nodes/FieldView'; import { FormattedTextBox } from '../../nodes/formattedText/FormattedTextBox'; import { PresBox } from '../../nodes/trails/PresBox'; @@ -1617,6 +1617,7 @@ export class CollectionFreeFormView extends CollectionSubView([]); + PresBox.pinDocView(anchor, { pinData: { pannable: true, viewType: true } }, this.rootDoc); + // bcz TODO: saving document filters should be part of pinDocView... + Doc.GetProto(anchor).docFilters = ObjectField.MakeCopy(this.layoutDoc.docFilters as ObjectField) || new List([]); + if (addAsAnnotation) { if (Cast(this.dataDoc[this.props.fieldKey + '-annotations'], listSpec(Doc), null) !== undefined) { Cast(this.dataDoc[this.props.fieldKey + '-annotations'], listSpec(Doc), []).push(anchor); diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index c3b0412de..5bdb994c5 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -98,8 +98,6 @@ export enum OpenWhereMod { bottom = 'bottom', } -export const ViewSpecPrefix = 'viewSpec'; // field prefix for anchor fields that are immediately copied over to the target document when link is followed. Other anchor properties will be copied over in the specific setViewSpec() method on their view (which allows for seting preview values instead of writing to the document) - export interface DocFocusOptions { originalTarget?: Doc; // set in JumpToDocument, used by TabDocView to determine whether to fit contents to tab willPan?: boolean; // determines whether to pan to target document @@ -585,13 +583,14 @@ export class DocumentViewInternal extends DocComponent { LightboxView.SetCookie(StrCast(anchor['cookies-set'])); - // copying over VIEW fields immediately allows the view type to switch to create the right _componentView - Array.from(Object.keys(Doc.GetProto(anchor))) - .filter(key => key.startsWith(ViewSpecPrefix)) - .forEach(spec => (this.layoutDoc[spec.replace(ViewSpecPrefix, '')] = (field => (field instanceof ObjectField ? ObjectField.MakeCopy(field) : field))(anchor[spec]))); - // after a render the general viewSpec should have created the right _componentView, so after a timeout, call the componentview to update its specific view specs + + // Restore viewing specification of target by reading them out of the anchor and applying to the target doc. + // after a render the correct _componentView should be created, so after a timeout, call the componentview to update its specific view specs + // bcz: TODO: all viewing specs should be restored via the anchor doc in PresBox.restoreTargetDocView called from scrollFocus() below. setTimeout(() => this._componentView?.setViewSpec?.(anchor, LinkDocPreview.LinkInfo ? true : false)); const focusSpeed = this._componentView?.scrollFocus?.(anchor, { ...options, instant: options?.instant || LinkDocPreview.LinkInfo ? true : false }); + + // FOCUS: navigate through the display hierarchy making sure the target is in view const endFocus = focusSpeed === undefined ? options?.afterFocus : async (moved: boolean) => options?.afterFocus?.(true) ?? ViewAdjustment.doNothing; const startTime = Date.now(); this.props.focus(options?.docTransform ? anchor : this.rootDoc, { diff --git a/src/client/views/nodes/trails/PresBox.tsx b/src/client/views/nodes/trails/PresBox.tsx index 929bf1230..32fcc0fae 100644 --- a/src/client/views/nodes/trails/PresBox.tsx +++ b/src/client/views/nodes/trails/PresBox.tsx @@ -48,6 +48,7 @@ export interface PinProps { pinData?: { scrollable?: boolean | undefined; pannable?: boolean | undefined; + viewType?: boolean | undefined; temporal?: boolean | undefined; clippable?: boolean | undefined; dataview?: boolean | undefined; @@ -316,7 +317,7 @@ export class PresBox extends ViewBoxBaseComponent() { this.onHideDocument(); //Handles hide after/before } }); - static pinDataTypes(target?: Doc): { scrollable?: boolean; pannable?: boolean; temporal?: boolean; clippable?: boolean; dataview?: boolean; textview?: boolean; poslayoutview?: boolean; dataannos?: boolean } { + static pinDataTypes(target?: Doc): { scrollable?: boolean; pannable?: boolean; viewType?: boolean; temporal?: boolean; clippable?: boolean; dataview?: boolean; textview?: boolean; poslayoutview?: boolean; dataannos?: boolean } { const targetType = target?.type as any; const scrollable = [DocumentType.PDF, DocumentType.RTF, DocumentType.WEB].includes(targetType) || target?._viewType === CollectionViewType.Stacking; const pannable = [DocumentType.IMG, DocumentType.PDF].includes(targetType) || (targetType === DocumentType.COL && target?._viewType === CollectionViewType.Freeform); @@ -325,8 +326,9 @@ export class PresBox extends ViewBoxBaseComponent() { const dataview = [DocumentType.INK, DocumentType.COL, DocumentType.IMG].includes(targetType) && target?.activeFrame === undefined; const poslayoutview = [DocumentType.COL].includes(targetType) && target?.activeFrame === undefined; const textview = [DocumentType.RTF].includes(targetType) && target?.activeFrame === undefined; + const viewType = targetType === DocumentType.COL; const dataannos = false; - return { scrollable, pannable, temporal, clippable, dataview, textview, poslayoutview, dataannos }; + return { scrollable, pannable, viewType, temporal, clippable, dataview, textview, poslayoutview, dataannos }; } @action @@ -366,6 +368,13 @@ export class PresBox extends ViewBoxBaseComponent() { changed = true; } } + if (pinDataTypes.viewType && activeItem.presPinViewType !== undefined) { + if (bestTarget._viewType !== activeItem.presPinViewType) { + bestTarget._viewType = activeItem.presPinViewType; + changed = true; + } + } + if (pinDataTypes.scrollable) { if (bestTarget._scrollTop !== activeItem.presPinViewScroll) { bestTarget._scrollTop = activeItem.presPinViewScroll; @@ -454,6 +463,7 @@ export class PresBox extends ViewBoxBaseComponent() { pinProps.pinData.scrollable || pinProps.pinData.temporal || pinProps.pinData.pannable || + pinProps.pinData.viewType || pinProps.pinData.clippable || pinProps.pinData.dataview || pinProps.pinData.textview || @@ -472,6 +482,7 @@ export class PresBox extends ViewBoxBaseComponent() { if (pinProps.pinData.scrollable) pinDoc.presPinViewScroll = targetDoc._scrollTop; if (pinProps.pinData.clippable) pinDoc.presPinClipWidth = targetDoc._clipWidth; if (pinProps.pinData.poslayoutview) pinDoc.presPinLayoutData = new List(DocListCast(targetDoc.presData).map(d => JSON.stringify({ id: d[Id], x: NumCast(d.x), y: NumCast(d.y), w: NumCast(d._width), h: NumCast(d._height) }))); + if (pinProps.pinData.viewType) pinDoc.presPinViewType = targetDoc._viewType; if (pinProps.pinData.pannable) { pinDoc.presPinViewX = NumCast(targetDoc._panX); pinDoc.presPinViewY = NumCast(targetDoc._panY); -- cgit v1.2.3-70-g09d2