From 605ab32150c5b2b9d84eb817d3086796b72964df Mon Sep 17 00:00:00 2001
From: Naafiyan Ahmed <naafiyan@gmail.com>
Date: Thu, 14 Apr 2022 17:46:15 -0400
Subject: fix: fixed panning with finger interaction

---
 src/client/util/InteractionUtils.tsx | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'src/client/util/InteractionUtils.tsx')

diff --git a/src/client/util/InteractionUtils.tsx b/src/client/util/InteractionUtils.tsx
index 3e051dec8..675dff00b 100644
--- a/src/client/util/InteractionUtils.tsx
+++ b/src/client/util/InteractionUtils.tsx
@@ -286,6 +286,8 @@ export namespace InteractionUtils {
             // pen and eraser are both pointer type 'pen', but pen is button 0 and eraser is button 5. -syip2
             case PENTYPE: return e.pointerType === PENTYPE && (e.button === -1 || e.button === 0);
             case ERASERTYPE: return e.pointerType === PENTYPE && e.button === (e instanceof PointerEvent ? ERASER_BUTTON : ERASER_BUTTON);
+            case TOUCHTYPE: 
+                return e.pointerType === TOUCHTYPE;
             default: return e.pointerType === type;
         }
     }
-- 
cgit v1.2.3-70-g09d2


From 4f6b6306803437851959e9ad214fd61a14207a20 Mon Sep 17 00:00:00 2001
From: Naafiyan Ahmed <naafiyan@gmail.com>
Date: Thu, 28 Apr 2022 16:34:31 -0400
Subject: added basic code for subgrouping transcribed text

---
 src/client/util/InteractionUtils.tsx               |  1 +
 src/client/views/GestureOverlay.tsx                |  2 +-
 src/client/views/InkTranscription.tsx              | 71 +++++++++++++++++++++-
 src/client/views/LightboxView.tsx                  |  3 +-
 src/client/views/Touchable.tsx                     |  2 +
 .../collectionFreeForm/CollectionFreeFormView.tsx  |  4 +-
 src/client/views/nodes/DocumentLinksButton.tsx     |  2 +
 src/client/views/nodes/button/FontIconBox.tsx      | 56 ++---------------
 8 files changed, 86 insertions(+), 55 deletions(-)

(limited to 'src/client/util/InteractionUtils.tsx')

diff --git a/src/client/util/InteractionUtils.tsx b/src/client/util/InteractionUtils.tsx
index 675dff00b..e2c5fab64 100644
--- a/src/client/util/InteractionUtils.tsx
+++ b/src/client/util/InteractionUtils.tsx
@@ -357,6 +357,7 @@ export namespace InteractionUtils {
     }
 
     export function IsDragging(oldTouches: Map<number, React.Touch>, newTouches: React.Touch[], leniency: number): boolean {
+        console.log("getting here");
         for (const touch of newTouches) {
             if (touch) {
                 const oldTouch = oldTouches.get(touch.identifier);
diff --git a/src/client/views/GestureOverlay.tsx b/src/client/views/GestureOverlay.tsx
index 5f0311d38..e689cd43c 100644
--- a/src/client/views/GestureOverlay.tsx
+++ b/src/client/views/GestureOverlay.tsx
@@ -212,7 +212,7 @@ export class GestureOverlay extends Touchable {
         const nts: any = this.getNewTouches(e);
         this._holdTimer && clearTimeout(this._holdTimer);
         this._holdTimer = undefined;
-
+        
         document.dispatchEvent(
             new CustomEvent<InteractionUtils.MultiTouchEvent<TouchEvent>>("dashOnTouchMove",
                 {
diff --git a/src/client/views/InkTranscription.tsx b/src/client/views/InkTranscription.tsx
index ea5d5a1ec..3b464db10 100644
--- a/src/client/views/InkTranscription.tsx
+++ b/src/client/views/InkTranscription.tsx
@@ -5,6 +5,7 @@ import * as React from 'react';
 import { Doc } from '../../fields/Doc';
 import { InkData, InkField } from "../../fields/InkField";
 import { Cast, NumCast, StrCast } from '../../fields/Types';
+import { aggregateBounds } from '../../Utils';
 import { DocumentType } from "../documents/DocumentTypes";
 import './InkTranscription.scss';
 
@@ -15,12 +16,18 @@ export class InkTranscription extends React.Component {
     @observable _mathRef: any;
     @observable _textRegister: any;
     @observable _textRef: any;
+    private lastJiix: any;
     private currGroup?: Doc;
+    private wordsBoundMapping: any;
+    private inkDocs: Doc[];
+    private ffView: any;
 
     constructor(props: Readonly<{}>) {
         super(props);
 
         InkTranscription.Instance = this;
+        this.wordsBoundMapping = new Map<any, any>();
+        this.inkDocs = new Array<Doc>();
     }
 
     componentWillUnmount() {
@@ -98,8 +105,10 @@ export class InkTranscription extends React.Component {
         return this._textRef = r;
     }
 
-    transcribeInk = (groupDoc: Doc | undefined, inkDocs: Doc[], math: boolean) => {
+    transcribeInk = (groupDoc: Doc | undefined, inkDocs: Doc[], math: boolean, ffView?: any) => {
         if (!groupDoc) return;
+        this.inkDocs = inkDocs;
+        this.ffView = ffView;
 
         const validInks = inkDocs.filter(s => s.type === DocumentType.INK);
 
@@ -137,8 +146,20 @@ export class InkTranscription extends React.Component {
         };
     }
 
+    mmToPixel = (mm: number) => {
+        return ((96 * mm) / 25.4);
+    }
+
+    calcBounds = (coords: any) => {
+        // find max and min x values and subtract
+        const max = Math.max(...coords);
+        const min = Math.min(...coords);
+        return max - min;
+    }
+
     exportInk = (e: any, ref: any) => {
         const exports = e.detail.exports;
+        console.log(e);
         if (exports) {
             if (exports['application/x-latex']) {
                 const latex = exports['application/x-latex'];
@@ -152,12 +173,60 @@ export class InkTranscription extends React.Component {
                 ref.editor.clear();
             }
             else if (exports['text/plain']) {
+                if (exports['application/vnd.myscript.jiix']) {
+                    this.lastJiix = JSON.parse(exports['application/vnd.myscript.jiix']);
+                    // console.log("lastJiix:", this.lastJiix);
+                    // TODO: nda - go through all the words and look at x,y values and figure out the selection
+                    this.lastJiix.words.forEach((word: any) => {
+                        // map each word to a new map                            
+                        this.wordsBoundMapping[word] = new Map<any, any>();
+                        if (word.items) {
+                            word.items.map((item: any) => {
+                                this.wordsBoundMapping.set(word, {xList: item.X, yList: item.Y, width: this.calcBounds(item.X), height: this.calcBounds(item.Y)});
+                            })
+                        }
+                    })
+                    // make groups for each of the words
+                    // loop through this.wordsBoundMapping
+
+                    this.wordsBoundMapping.forEach((value: any, key: any) => {
+                        const xList = value.xList;
+                        const yList = value.yList;
+                        const width = value.width;
+                        const height = value.height;
+                        const bounds: { x: number, y: number, width?: number, height?: number }[] = []
+                        // loop through xList
+                        for (let i = 0; i < xList.length; i++) {
+                            const x = xList[i];
+                            const y = yList[i];
+                            const newBounds = { x: x, y: y };
+                            bounds.push(newBounds);
+                        }
+                        const aggregBounds = aggregateBounds(bounds, 0, 0);
+
+                        const marqViewRef = this.ffView?._marqueeViewRef.current;
+
+                        // set the vals for bounds in marqueeView
+                        if (marqViewRef) {
+                            marqViewRef._downX = aggregBounds.x;
+                            marqViewRef._downY = aggregBounds.y;
+                            marqViewRef._lastX = aggregBounds.r;
+                            marqViewRef._lastY = aggregBounds.b;
+                        }
+                    
+                    });
+
+                    // console.log(this.wordsBoundMapping);
+                }
                 const text = exports['text/plain'];
                 console.log(text);
 
                 if (this.currGroup) {
+                    console.log("curr grouping");
                     this.currGroup.text = text;
                     this.currGroup.title = text;
+                    console.log(this.lastJiix);
+                    console.log(this.currGroup);
                 }
 
                 ref.editor.clear();
diff --git a/src/client/views/LightboxView.tsx b/src/client/views/LightboxView.tsx
index ec3bf6c18..c8f6b5f0b 100644
--- a/src/client/views/LightboxView.tsx
+++ b/src/client/views/LightboxView.tsx
@@ -5,7 +5,7 @@ import "normalize.css";
 import * as React from 'react';
 import { Doc, DocListCast, Opt } from '../../fields/Doc';
 import { Cast, NumCast, StrCast } from '../../fields/Types';
-import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue } from '../../Utils';
+import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue, Utils } from '../../Utils';
 import { DocUtils } from '../documents/Documents';
 import { DocumentManager } from '../util/DocumentManager';
 import { LinkManager } from '../util/LinkManager';
@@ -17,6 +17,7 @@ import "./LightboxView.scss";
 import { DocumentView } from './nodes/DocumentView';
 import { DefaultStyleProvider, wavyBorderPath } from './StyleProvider';
 import { CollectionMenu } from './collections/CollectionMenu';
+import { utils } from 'mocha';
 
 interface LightboxViewProps {
     PanelWidth: number;
diff --git a/src/client/views/Touchable.tsx b/src/client/views/Touchable.tsx
index 789756a78..c712e7ed3 100644
--- a/src/client/views/Touchable.tsx
+++ b/src/client/views/Touchable.tsx
@@ -127,11 +127,13 @@ export abstract class Touchable<T = {}> extends React.Component<T> {
     }
 
     handle1PointerMove = (e: TouchEvent, me: InteractionUtils.MultiTouchEvent<TouchEvent>): any => {
+        console.log("getting to handle1PointersMove");
         e.stopPropagation();
         e.preventDefault();
     }
 
     handle2PointersMove = (e: TouchEvent, me: InteractionUtils.MultiTouchEvent<TouchEvent>): any => {
+        console.log("getting to handle2PointersMove");
         e.stopPropagation();
         e.preventDefault();
     }
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 023953658..7c11c252a 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -702,9 +702,9 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
 
     @action
     onPointerMove = (e: PointerEvent): void => {
+        console.log("this is onPointerMove");
         if (InteractionUtils.IsType(e, InteractionUtils.PENTYPE)) return;
         if (InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE)) {
-            console.log("is touch");
             Doc.UserDoc().activeInkTool = InkTool.None;
             if (this.props.isContentActive(true)) e.stopPropagation();
         } else if (!e.cancelBubble) {
@@ -825,6 +825,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
     }
 
     handle1PointerMove = (e: TouchEvent, me: InteractionUtils.MultiTouchEvent<TouchEvent>) => {
+        console.log("getting here yeet");
         if (!e.cancelBubble) {
             const myTouches = InteractionUtils.GetMyTargetTouches(me, this.prevPoints, true);
             if (myTouches[0]) {
@@ -836,6 +837,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
                         document.removeEventListener("pointerup", this.onPointerUp);
                         return;
                     }
+                    // TODO: nda - this allows us to pan collections with finger -> only want to do this when collection is selected'
                     this.pan(myTouches[0]);
                 }
             }
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index 7e6ca4248..f9d2b9917 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -21,6 +21,8 @@ import { LinkDescriptionPopup } from "./LinkDescriptionPopup";
 import { TaskCompletionBox } from "./TaskCompletedBox";
 import React = require("react");
 import { Transform } from "../../util/Transform";
+import { InkTool } from "../../../fields/InkField";
+import { CurrentUserUtils } from "../../util/CurrentUserUtils";
 
 const higflyout = require("@hig/flyout");
 export const { anchorPoints } = higflyout;
diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx
index fc358f106..85130e69e 100644
--- a/src/client/views/nodes/button/FontIconBox.tsx
+++ b/src/client/views/nodes/button/FontIconBox.tsx
@@ -757,13 +757,17 @@ export function createInkGroup(inksToGroup?: Doc[]) {
             ffView.props.removeDocument?.(selected);
             // TODO: nda - this is the code to actually get a new grouped collection
             const newCollection = marqViewRef?.getCollection(selected, undefined, [], true);
+            if (newCollection) {
+                newCollection.height = newCollection[HeightSym]();
+                newCollection.width = newCollection[WidthSym]();
+            }
 
             // nda - bug: when deleting a stroke before leaving writing mode, delete the stroke from unprocessed ink docs
             newCollection && ffView.props.addDocument?.(newCollection);
             // TODO: nda - will probably need to go through and only remove the unprocessed selected docs
             ffView.unprocessedDocs = [];
 
-            InkTranscription.Instance.transcribeInk(newCollection, selected, false);
+            InkTranscription.Instance.transcribeInk(newCollection, selected, false, ffView);
         });
     }
     CollectionFreeFormView.collectionsWithUnprocessedInk.clear();
@@ -778,56 +782,6 @@ export function createInkGroup(inksToGroup?: Doc[]) {
 
 ScriptingGlobals.add(function setActiveInkTool(tool: string, checkResult?: boolean) {
     createInkGroup();
-    // if (CurrentUserUtils.SelectedTool === InkTool.Write) {
-    //     CollectionFreeFormView.collectionsWithUnprocessedInk.forEach(ffView => {
-    //         const selected = ffView.unprocessedDocs;
-    //         // loop through selected an get the bound
-    //         const bounds: { x: number, y: number, width?: number, height?: number }[] = []
-
-    //         selected.map(action(d => {
-    //             const x = NumCast(d.x);
-    //             const y = NumCast(d.y);
-    //             const width = d[WidthSym]();
-    //             const height = d[HeightSym]();
-    //             bounds.push({x, y, width, height});
-    //         }))
-
-    //         const aggregBounds = aggregateBounds(bounds, 0, 0);
-    //         const marqViewRef = ffView._marqueeViewRef.current;
-
-    //         // set the vals for bounds in marqueeView
-    //         if (marqViewRef) {
-    //             marqViewRef._downX = aggregBounds.x;
-    //             marqViewRef._downY = aggregBounds.y;
-    //             marqViewRef._lastX = aggregBounds.r;
-    //             marqViewRef._lastY = aggregBounds.b;
-    //         }        
-
-    //         selected.map(action(d => {
-    //             const dx = NumCast(d.x);
-    //             const dy = NumCast(d.y);
-    //             delete d.x;
-    //             delete d.y;
-    //             delete d.activeFrame;
-    //             delete d._timecodeToShow;  // bcz: this should be automatic somehow.. along with any other properties that were logically associated with the original collection
-    //             delete d._timecodeToHide;  // bcz: this should be automatic somehow.. along with any other properties that were logically associated with the original collection
-    //             // calculate pos based on bounds
-    //             if (marqViewRef?.Bounds) {
-    //                 d.x = dx - marqViewRef.Bounds.left - marqViewRef.Bounds.width / 2;
-    //                 d.y = dy - marqViewRef.Bounds.top - marqViewRef.Bounds.height / 2;
-    //             }
-    //             return d;
-    //         }));
-    //         ffView.props.removeDocument?.(selected);
-    //         // TODO: nda - this is the code to actually get a new grouped collection
-    //         const newCollection = marqViewRef?.getCollection(selected, undefined, [], true);
-
-    //         // nda - bug: when deleting a stroke before leaving writing mode, delete the stroke from unprocessed ink docs
-    //         newCollection && ffView.props.addDocument?.(newCollection);
-    //         ffView.unprocessedDocs = [];
-    //     });
-    // }
-    // CollectionFreeFormView.collectionsWithUnprocessedInk.clear();
 
     if (checkResult) {
         return ((Doc.UserDoc().activeInkTool === tool && !GestureOverlay.Instance?.InkShape) || GestureOverlay.Instance?.InkShape === tool) ?
-- 
cgit v1.2.3-70-g09d2

