aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/WebBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/WebBox.tsx')
-rw-r--r--src/client/views/nodes/WebBox.tsx114
1 files changed, 112 insertions, 2 deletions
diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx
index 0b23c3bec..c405dd9d4 100644
--- a/src/client/views/nodes/WebBox.tsx
+++ b/src/client/views/nodes/WebBox.tsx
@@ -21,6 +21,9 @@ import "./WebBox.scss";
import React = require("react");
import { DocAnnotatableComponent } from "../DocComponent";
import { documentSchema } from "../../../new_fields/documentSchemas";
+import { Id } from "../../../new_fields/FieldSymbols";
+import { DragManager } from "../../util/DragManager";
+import { ImageUtils } from "../../util/Import & Export/ImageUtils";
library.add(faStickyNote);
@@ -34,6 +37,12 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument>
@observable private collapsed: boolean = true;
@observable private url: string = "";
+ private _longPressSecondsHack?: NodeJS.Timeout;
+ private _iframeRef = React.createRef<HTMLIFrameElement>();
+ private _iframeDragRef = React.createRef<HTMLDivElement>();
+ @observable private _pressX: number = 0;
+ @observable private _pressY: number = 0;
+
componentWillMount() {
const field = Cast(this.props.Document[this.props.fieldKey], WebField);
@@ -51,6 +60,49 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument>
this.setURL();
}
+ componentDidMount() {
+ document.addEventListener("pointerup", this.onLongPressUp);
+ document.addEventListener("pointermove", this.onLongPressMove);
+ // this._iframeRef.current?.contentWindow?.document.addEventListener("mousedown", (event: MouseEvent) => {
+ // console.log("clicked inside the iframe?");
+ // });
+ // const iframe = document.getElementById(this.props.Document.proto![Id]);
+ // if (iframe) {
+ // iframe.addEventListener('pointerdown', function (event) {
+ // const B = iframe.getBoundingClientRect();
+ // const e = new CustomEvent('pointerdown', { bubbles: true, cancelable: false });
+ // // e.clientX = e.clientX + B?.left;
+ // // e.clientY = e.clientY + B?.top;
+ // console.log("custom event pointer down");
+ // iframe.dispatchEvent(e);
+ // })
+ // }
+ // if (this._iframeRef.current) {
+ // console.log("resetting iframes events");
+ // const self = this;
+ // this._iframeRef.current.addEventListener('pointermove', function (event) {
+ // const B = self._iframeRef.current?.getBoundingClientRect();
+ // const e = new CustomEvent('pointermove', { bubbles: true, cancelable: false });
+ // // e.clientX = e.clientX + B?.left;
+ // // e.clientY = e.clientY + B?.top;
+ // self._iframeRef.current?.dispatchEvent(e);
+ // });
+ // this._iframeRef.current.addEventListener('pointerdown', function (event) {
+ // const B = self._iframeRef.current?.getBoundingClientRect();
+ // const e = new CustomEvent('pointerdown', { bubbles: true, cancelable: false });
+ // // e.clientX = e.clientX + B?.left;
+ // // e.clientY = e.clientY + B?.top;
+ // console.log("custom event pointer down");
+ // self._iframeRef.current?.dispatchEvent(e);
+ // })
+ // }
+ }
+
+ componentWillUnmount() {
+ document.removeEventListener("pointerup", this.onLongPressUp);
+ document.removeEventListener("pointermove", this.onLongPressMove);
+ }
+
@action
onURLChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.url = e.target.value;
@@ -165,6 +217,62 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument>
}
}
+ // TODO: make this actually a long press
+ onLongPressDown = (e: React.PointerEvent) => {
+
+ console.log("press down", e.clientX, e.clientX);
+ this._pressX = e.clientX;
+ this._pressY = e.clientY;
+ this._longPressSecondsHack = setTimeout(() => {
+ console.log("start the drag!!");
+ const B = this._iframeRef.current?.getBoundingClientRect();
+ const iframeDoc = this._iframeRef.current?.contentDocument;
+ if (B && iframeDoc) {
+ console.log("frame doc", iframeDoc);
+ console.log("get point", this._pressX, B.left, this._pressY, B.top);
+ const element = iframeDoc.elementFromPoint(this._pressX - B.left, this._pressY - B.top);
+ console.log("found element", element);
+ if (element) {
+ e.stopPropagation();
+ e.preventDefault();
+ const clone = element.cloneNode(true) as HTMLElement;
+
+ if (clone.nodeName === "IMG") {
+ const src = clone.getAttribute("src"); // TODO: may not always work
+
+ if (src) {
+ const doc = Docs.Create.ImageDocument(src, { width: 300 });
+ ImageUtils.ExtractExif(doc);
+
+ console.log("start image drag", this._pressX, this._pressY, doc);
+ // document.dispatchEvent()
+ const dragData = new DragManager.DocumentDragData([doc]);
+ DragManager.StartDocumentDrag([clone], dragData, this._pressX, this._pressY);
+ }
+ }
+ }
+ }
+ }, 1500);
+ // e.stopPropagation();
+ // e.preventDefault();
+ }
+
+ onLongPressMove = (e: PointerEvent) => {
+ this._pressX = e.clientX;
+ this._pressY = e.clientY;
+ }
+
+ onLongPressUp = (e: PointerEvent) => {
+ console.log("press up");
+ if (this._longPressSecondsHack) {
+ clearTimeout(this._longPressSecondsHack);
+ console.log("long press cancelled");
+ }
+ // e.stopPropagation();
+ // e.preventDefault();
+ }
+
+
@computed
get content() {
const field = this.dataDoc[this.props.fieldKey];
@@ -172,9 +280,9 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument>
if (field instanceof HtmlField) {
view = <span id="webBox-htmlSpan" dangerouslySetInnerHTML={{ __html: field.html }} />;
} else if (field instanceof WebField) {
- view = <iframe src={Utils.CorsProxy(field.url.href)} style={{ position: "absolute", width: "100%", height: "100%", top: 0 }} />;
+ view = <iframe ref={this._iframeRef} src={Utils.CorsProxy(field.url.href)} style={{ position: "absolute", width: "100%", height: "100%", top: 0 }} />;
} else {
- view = <iframe src={"https://crossorigin.me/https://cs.brown.edu"} style={{ position: "absolute", width: "100%", height: "100%", top: 0 }} />;
+ view = <iframe ref={this._iframeRef} src={"https://crossorigin.me/https://cs.brown.edu"} style={{ position: "absolute", width: "100%", height: "100%", top: 0 }} />;
}
const content =
<div style={{ width: "100%", height: "100%", position: "absolute" }} onWheel={this.onPostWheel} onPointerDown={this.onPostPointer} onPointerMove={this.onPostPointer} onPointerUp={this.onPostPointer}>
@@ -192,7 +300,9 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument>
<div className={classname} >
{content}
</div>
+ <div className="mobileIframeDragger" ref={this._iframeDragRef} draggable></div>
{!frozen ? (null) : <div className="webBox-overlay" onWheel={this.onPreWheel} onPointerDown={this.onPrePointer} onPointerMove={this.onPrePointer} onPointerUp={this.onPrePointer} />}
+ {/* onPointerDown={(e) => { this.onPrePointer(e); this.onLongPressDown(e) }} onPointerMove={this.onPrePointer} onPointerUp={(e) => { this.onPrePointer(e); }} />} */}
</>);
}
render() {