From fb918c91e9c7533868601c6d3e23687b5dccf1df Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 21 Oct 2020 23:09:41 -0400 Subject: fixed warnings. fixed pinning of multiple documents at the same time to bring up the presentation view just once. --- src/client/views/collections/TabDocView.tsx | 12 ++- src/client/views/nodes/PresBox.tsx | 106 ++++++++++----------- .../views/presentationview/PresElementBox.tsx | 2 +- 3 files changed, 60 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx index 338b1d590..9c5f7c66e 100644 --- a/src/client/views/collections/TabDocView.tsx +++ b/src/client/views/collections/TabDocView.tsx @@ -124,7 +124,7 @@ export class TabDocView extends React.Component { **/ @undoBatch @action - public static async PinDoc(doc: Doc, unpin = false, audioRange?: boolean) { + public static PinDoc(doc: Doc, unpin = false, audioRange?: boolean) { if (unpin) console.log('TODO: Remove UNPIN from this location'); //add this new doc to props.Document const curPres = CurrentUserUtils.ActivePresentation; @@ -140,11 +140,15 @@ export class TabDocView extends React.Component { pinDoc.presEndTime = doc.duration; } if (curPres.expandBoolean) pinDoc.presExpandInlineButton = true; - const curPresDocView = DocumentManager.Instance.getDocumentView(curPres); - if (!curPresDocView) { + const dview = CollectionDockingView.Instance.props.Document; + const fieldKey = CollectionDockingView.Instance.props.fieldKey; + const sublists = DocListCast(dview[fieldKey]); + const tabs = Cast(sublists[0], Doc, null); + const tabdocs = DocListCast(tabs.data); + if (!tabdocs.includes(curPres)) { CollectionDockingView.AddSplit(curPres, "right"); } - await DocumentManager.Instance.jumpToDocument(doc, false, undefined); + DocumentManager.Instance.jumpToDocument(doc, false, undefined); } } diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index b19cba585..d38e48974 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -305,7 +305,7 @@ export class PresBox extends ViewBoxBaseComponent const presDocView = DocumentManager.Instance.getDocumentView(this.rootDoc); if (presDocView) SelectionManager.SelectDoc(presDocView, false); this.rootDoc.presStatus = presStatus; - }, 2000) + }, 2000); } else //docToJump stayed same meaning, it was not in the group or was the last element in the group if (activeItem.zoomProgressivize && this.rootDoc.presStatus !== PresStatus.Edit) { @@ -583,24 +583,26 @@ export class PresBox extends ViewBoxBaseComponent doc.presMovement = PresMovement.None; break; } - }) - } else if (this._selectedArray) this._selectedArray.forEach((doc) => { - switch (movement) { - case PresMovement.Zoom: //Pan and zoom - doc.presMovement = PresMovement.Zoom; - break; - case PresMovement.Pan: //Pan - doc.presMovement = PresMovement.Pan; - break; - case PresMovement.Jump: //Jump Cut - doc.presJump = true; - doc.presMovement = PresMovement.Jump; - break; - case PresMovement.None: default: - doc.presMovement = PresMovement.None; - break; - } - }) + }); + } else { + this._selectedArray?.forEach((doc) => { + switch (movement) { + case PresMovement.Zoom: //Pan and zoom + doc.presMovement = PresMovement.Zoom; + break; + case PresMovement.Pan: //Pan + doc.presMovement = PresMovement.Pan; + break; + case PresMovement.Jump: //Jump Cut + doc.presJump = true; + doc.presMovement = PresMovement.Jump; + break; + case PresMovement.None: default: + doc.presMovement = PresMovement.None; + break; + } + }); + } }); setMovementName = action((movement: any, activeItem: Doc): string => { @@ -892,9 +894,7 @@ export class PresBox extends ViewBoxBaseComponent if (change) timeInMS += change; if (timeInMS < 100) timeInMS = 100; if (timeInMS > 10000) timeInMS = 10000; - if (this._selectedArray) this._selectedArray.forEach((doc) => { - doc.presTransition = timeInMS; - }) + this._selectedArray?.forEach((doc) => doc.presTransition = timeInMS); } // Converts seconds to ms and updates presDuration @@ -904,25 +904,19 @@ export class PresBox extends ViewBoxBaseComponent if (change) timeInMS += change; if (timeInMS < 100) timeInMS = 100; if (timeInMS > 20000) timeInMS = 20000; - if (this._selectedArray) this._selectedArray.forEach((doc) => { - doc.presDuration = timeInMS; - }) + this._selectedArray?.forEach((doc) => doc.presDuration = timeInMS); } @undoBatch updateHideBefore = (activeItem: Doc) => { activeItem.presHideTillShownButton = !activeItem.presHideTillShownButton; - this._selectedArray.forEach((doc) => { - doc.presHideTillShownButton = activeItem.presHideTillShownButton; - }); + this._selectedArray?.forEach((doc) => doc.presHideTillShownButton = activeItem.presHideTillShownButton); } @undoBatch updateHideAfter = (activeItem: Doc) => { activeItem.presHideAfterButton = !activeItem.presHideAfterButton; - this._selectedArray.forEach((doc) => { - doc.presHideAfterButton = activeItem.presHideAfterButton; - }); + this._selectedArray?.forEach((doc) => doc.presHideAfterButton = activeItem.presHideAfterButton); } @undoBatch @@ -958,30 +952,32 @@ export class PresBox extends ViewBoxBaseComponent tagDoc.presEffect = PresEffect.None; break; } - }) - } else if (this._selectedArray) this._selectedArray.forEach((doc) => { - const tagDoc = Cast(doc.presentationTargetDoc, Doc, null); - switch (effect) { - case PresEffect.Bounce: - tagDoc.presEffect = PresEffect.Bounce; - break; - case PresEffect.Fade: - tagDoc.presEffect = PresEffect.Fade; - break; - case PresEffect.Flip: - tagDoc.presEffect = PresEffect.Flip; - break; - case PresEffect.Roll: - tagDoc.presEffect = PresEffect.Roll; - break; - case PresEffect.Rotate: - tagDoc.presEffect = PresEffect.Rotate; - break; - case PresEffect.None: default: - tagDoc.presEffect = PresEffect.None; - break; - } - }) + }); + } else { + this._selectedArray?.forEach((doc) => { + const tagDoc = Cast(doc.presentationTargetDoc, Doc, null); + switch (effect) { + case PresEffect.Bounce: + tagDoc.presEffect = PresEffect.Bounce; + break; + case PresEffect.Fade: + tagDoc.presEffect = PresEffect.Fade; + break; + case PresEffect.Flip: + tagDoc.presEffect = PresEffect.Flip; + break; + case PresEffect.Roll: + tagDoc.presEffect = PresEffect.Roll; + break; + case PresEffect.Rotate: + tagDoc.presEffect = PresEffect.Rotate; + break; + case PresEffect.None: default: + tagDoc.presEffect = PresEffect.None; + break; + } + }); + } } @computed get transitionDropdown() { diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index 33b67ae69..6ebb7d623 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -266,7 +266,7 @@ export class PresElementBox extends ViewBoxBaseComponent Date: Wed, 21 Oct 2020 23:59:30 -0400 Subject: fixed dragging documents to bottom of presentation list. fixed adding to preentation list without creatinga a duplicate. --- src/client/views/collections/CollectionStackingView.tsx | 2 +- src/client/views/collections/TabDocView.tsx | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionStackingView.tsx b/src/client/views/collections/CollectionStackingView.tsx index d490b65a8..4880d342c 100644 --- a/src/client/views/collections/CollectionStackingView.tsx +++ b/src/client/views/collections/CollectionStackingView.tsx @@ -295,7 +295,7 @@ export class CollectionStackingView extends CollectionSubView this.filteredChildren.find((fdoc, i) => ndoc === fdoc && i <= insertInd) ? off + 1 : off, 0); + const offset = newDocs.reduce((off, ndoc) => this.filteredChildren.find((fdoc, i) => ndoc === fdoc && i < insertInd) ? off + 1 : off, 0); newDocs.filter(ndoc => docs.indexOf(ndoc) !== -1).forEach(ndoc => docs.splice(docs.indexOf(ndoc), 1)); docs.splice(insertInd - offset, 0, ...newDocs); } diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx index 9c5f7c66e..41c372faa 100644 --- a/src/client/views/collections/TabDocView.tsx +++ b/src/client/views/collections/TabDocView.tsx @@ -6,7 +6,7 @@ import { clamp } from 'lodash'; import { action, computed, IReactionDisposer, observable, reaction } from "mobx"; import { observer } from "mobx-react"; import * as ReactDOM from 'react-dom'; -import { DataSym, Doc, DocListCast, Opt } from "../../../fields/Doc"; +import { DataSym, Doc, DocListCast, Opt, DocListCastAsync } from "../../../fields/Doc"; import { Id } from '../../../fields/FieldSymbols'; import { FieldId } from "../../../fields/RefField"; import { listSpec } from '../../../fields/Schema'; @@ -144,10 +144,11 @@ export class TabDocView extends React.Component { const fieldKey = CollectionDockingView.Instance.props.fieldKey; const sublists = DocListCast(dview[fieldKey]); const tabs = Cast(sublists[0], Doc, null); - const tabdocs = DocListCast(tabs.data); - if (!tabdocs.includes(curPres)) { - CollectionDockingView.AddSplit(curPres, "right"); - } + DocListCastAsync(tabs.data).then(tabdocs => { + if (!tabdocs?.includes(curPres)) { + CollectionDockingView.AddSplit(curPres, "right"); + } + }); DocumentManager.Instance.jumpToDocument(doc, false, undefined); } } -- cgit v1.2.3-70-g09d2 From 05257784ed7c0e6ed9ce5375cd5e3cccc04c7bec Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 22 Oct 2020 00:20:26 -0400 Subject: fixed problem when dragging preselements when sometimes the whole screen turns gray because the dragged item has no width/height --- src/client/views/presentationview/PresElementBox.tsx | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index 6ebb7d623..b260bc00d 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -142,6 +142,7 @@ export class PresElementBox extends ViewBoxBaseComponent { -- cgit v1.2.3-70-g09d2 From b75fc9edafb72a6cf5b1e15a3d2b5300c053f92f Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 22 Oct 2020 01:38:03 -0400 Subject: fixed webBoxes to switch URLS when hyperlink is clicked (and page is not cross-origin). fixed some undo navigation web stuff. fixed drag/drop to create anchor that bounds the original selection. fixed html clippings to not have a nativewith/height so that they reflow --- src/client/documents/Documents.ts | 2 +- src/client/views/collections/CollectionSubView.tsx | 14 +++++++++----- src/client/views/nodes/WebBox.tsx | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index d7c9af1a3..d7af88b72 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -1101,7 +1101,7 @@ export namespace DocUtils { }); } ctor = Docs.Create.WebDocument; - options = { ...options, _fitWidth: true, _nativeWidth: 850, _width: 400, _height: 512, title: path, }; + options = { ...options, _fitWidth: true, _width: 400, _height: 512, title: path, }; } return ctor ? ctor(path, options) : undefined; } diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index f0cf54db4..5c3c70be2 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -344,12 +344,16 @@ export function CollectionSubView(schemaCtor: (doc: Doc) => T, moreProps?: Doc.GetProto(htmlDoc)["data-text"] = Doc.GetProto(htmlDoc).text = text; this.props.addDocument(htmlDoc); if (srcWeb) { - const focusNode = (SelectionManager.SelectedDocuments()[0].ContentDiv?.getElementsByTagName("iframe")?.[0]?.contentDocument?.getSelection()?.focusNode as any); + const iframe = SelectionManager.SelectedDocuments()[0].ContentDiv?.getElementsByTagName("iframe")?.[0]; + const focusNode = (iframe?.contentDocument?.getSelection()?.focusNode as any); if (focusNode) { - const rect = "getBoundingClientRect" in focusNode ? focusNode.getBoundingClientRect() : focusNode?.parentElement.getBoundingClientRect(); - const x = (rect?.x || 0); - const y = NumCast(srcWeb._scrollTop) + (rect?.y || 0); - const anchor = Docs.Create.FreeformDocument([], { _backgroundColor: "transparent", _width: 75, _height: 40, x, y, annotationOn: srcWeb }); + const rects = iframe?.contentWindow?.getSelection()?.getRangeAt(0).getClientRects(); + "getBoundingClientRect" in focusNode ? focusNode.getBoundingClientRect() : focusNode?.parentElement.getBoundingClientRect(); + const x = (rects && Array.from(rects).reduce((x: any, r: DOMRect) => x === undefined || r.x < x ? r.x : x, undefined as any)) || 0; + const y = NumCast(srcWeb._scrollTop) + ((rects && Array.from(rects).reduce((y: any, r: DOMRect) => y === undefined || r.y < y ? r.y : y, undefined as any)) || 0); + const r = (rects && Array.from(rects).reduce((x: any, r: DOMRect) => x === undefined || r.x + r.width > x ? r.x + r.width : x, undefined as any)) || 0; + const b = NumCast(srcWeb._scrollTop) + ((rects && Array.from(rects).reduce((y: any, r: DOMRect) => y === undefined || r.y + r.height > y ? r.y + r.height : y, undefined as any)) || 0); + const anchor = Docs.Create.FreeformDocument([], { _backgroundColor: "transparent", _width: r - x, _height: b - y, x, y, annotationOn: srcWeb }); anchor.context = srcWeb; const key = Doc.LayoutFieldKey(srcWeb); Doc.AddDocToList(srcWeb, key + "-annotations", anchor); diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index eb9e08e20..168fee807 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -72,14 +72,23 @@ export class WebBox extends ViewBoxAnnotatableComponent { const iframe = this._iframeRef.current; if (iframe && iframe.contentDocument) { iframe.setAttribute("enable-annotation", "true"); + iframe.contentDocument.addEventListener("click", undoBatch(action(e => { + const href = (e.target as any)?.href; + if (href) { + this._url = href.replace(Utils.prepend(""), Cast(this.dataDoc[this.fieldKey], WebField, null)?.url.origin); + this.submitURL(); + } + }))); iframe.contentDocument.addEventListener('pointerdown', this.iframedown, false); iframe.contentDocument.addEventListener('scroll', this.iframeScrolled, false); this.layoutDoc.scrollHeight = iframe.contentDocument.children?.[0].scrollHeight || 1000; @@ -178,14 +187,11 @@ export class WebBox extends ViewBoxAnnotatableComponent) => { - this._url = e.target.value; - } - onUrlDragover = (e: React.DragEvent) => { e.preventDefault(); } + + @undoBatch @action onUrlDrop = (e: React.DragEvent) => { const { dataTransfer } = e; -- cgit v1.2.3-70-g09d2 From 4a79649904a70f5903e36b0d8d259583e597c315 Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 22 Oct 2020 01:48:14 -0400 Subject: fixed list undo/redo to work with non-doc items. --- src/fields/util.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/fields/util.ts b/src/fields/util.ts index a374c7f54..af743d9f2 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -379,12 +379,12 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any diff?.op === "$addToSet" ? { redo: () => { - receiver[prop].push(...diff.items.map((item: any) => item.value())); + receiver[prop].push(...diff.items.map((item: any) => item.hasOwnProperty("value") ? item.value() : item)); lastValue = ObjectField.MakeCopy(receiver[prop]); }, undo: action(() => { - diff.items.forEach((doc: any) => { - const ind = receiver[prop].indexOf(doc.value()); + diff.items.forEach((item: any) => { + const ind = receiver[prop].indexOf(item.hasOwnProperty("value") ? item.value() : item); ind !== -1 && receiver[prop].splice(ind, 1); }); lastValue = ObjectField.MakeCopy(receiver[prop]); @@ -393,16 +393,16 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any diff?.op === "$remFromSet" ? { redo: action(() => { - diff.items.forEach((doc: any) => { - const ind = receiver[prop].indexOf(doc.value()); + diff.items.forEach((item: any) => { + const ind = receiver[prop].indexOf(item.hasOwnProperty("value") ? item.value() : item); ind !== -1 && receiver[prop].splice(ind, 1); }); lastValue = ObjectField.MakeCopy(receiver[prop]); }), undo: () => { - diff.items.map((item: any) => { - const ind = (prevValue as List).indexOf(diff.items[0].value()); - ind !== -1 && receiver[prop].indexOf(diff.items[0].value()) === -1 && receiver[prop].splice(ind, 0, item); + diff.items.forEach((item: any) => { + const ind = (prevValue as List).indexOf(item.hasOwnProperty("value") ? item.value() : item); + ind !== -1 && receiver[prop].indexOf(item.hasOwnProperty("value") ? item.value() : item) === -1 && receiver[prop].splice(ind, 0, item); }); lastValue = ObjectField.MakeCopy(receiver[prop]); } -- cgit v1.2.3-70-g09d2 From 93ff528ebce3ac970fa7a5d299fd3bfbc2ee021e Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 22 Oct 2020 02:16:59 -0400 Subject: fixed pinning multiple documents to work and be undoable. --- src/client/views/collections/TabDocView.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx index 41c372faa..d816dea0d 100644 --- a/src/client/views/collections/TabDocView.tsx +++ b/src/client/views/collections/TabDocView.tsx @@ -122,13 +122,13 @@ export class TabDocView extends React.Component { /** * Adds a document to the presentation view **/ - @undoBatch @action - public static PinDoc(doc: Doc, unpin = false, audioRange?: boolean) { + public static async PinDoc(doc: Doc, unpin = false, audioRange?: boolean) { if (unpin) console.log('TODO: Remove UNPIN from this location'); //add this new doc to props.Document const curPres = CurrentUserUtils.ActivePresentation; if (curPres) { + const batch = UndoManager.StartBatch("pinning doc"); const pinDoc = Doc.MakeAlias(doc); pinDoc.presentationTargetDoc = doc; pinDoc.title = doc.title; @@ -144,12 +144,13 @@ export class TabDocView extends React.Component { const fieldKey = CollectionDockingView.Instance.props.fieldKey; const sublists = DocListCast(dview[fieldKey]); const tabs = Cast(sublists[0], Doc, null); - DocListCastAsync(tabs.data).then(tabdocs => { - if (!tabdocs?.includes(curPres)) { - CollectionDockingView.AddSplit(curPres, "right"); - } - }); + const tabdocs = await DocListCastAsync(tabs.data); + if (!tabdocs?.includes(curPres)) { + tabdocs?.push(curPres); // bcz: Argh! this is annoying. if multiple documents are pinned, this will get called multiple times before the presentation view is drawn. Thus it won't be in the tabdocs list and it will get created multple times. so need to explicilty add the presbox to the list of open tabs + CollectionDockingView.AddSplit(curPres, "right"); + } DocumentManager.Instance.jumpToDocument(doc, false, undefined); + batch.end(); } } -- cgit v1.2.3-70-g09d2