aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ImageBox.tsx
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-04-29 20:32:39 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-04-29 20:32:39 -0400
commit08849062e84087ac24031944af8697c87d7d183c (patch)
tree4e21bbc4fa144ab5e5a17bdfbeea87b729ff091a /src/client/views/nodes/ImageBox.tsx
parent986595be59e714de4fe6c677dcace3c3f402ac82 (diff)
parent3da71792a339536118b7af7cfe0529201a45c64e (diff)
Merge branch 'master' into presentation_view
Diffstat (limited to 'src/client/views/nodes/ImageBox.tsx')
-rw-r--r--src/client/views/nodes/ImageBox.tsx59
1 files changed, 39 insertions, 20 deletions
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index edd7f55fc..2cbb0fa90 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -1,21 +1,22 @@
-import { action, observable, trace } from 'mobx';
+import { action, observable } from 'mobx';
import { observer } from "mobx-react";
import Lightbox from 'react-image-lightbox';
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
+import { Document } from '../../../fields/Document';
import { FieldWaiting } from '../../../fields/Field';
import { ImageField } from '../../../fields/ImageField';
import { KeyStore } from '../../../fields/KeyStore';
+import { ListField } from '../../../fields/ListField';
+import { Utils } from '../../../Utils';
+import { DragManager } from '../../util/DragManager';
+import { undoBatch } from '../../util/UndoManager';
import { ContextMenu } from "../../views/ContextMenu";
import { FieldView, FieldViewProps } from './FieldView';
import "./ImageBox.scss";
import React = require("react");
-import { Utils } from '../../../Utils';
-import { ListField } from '../../../fields/ListField';
-import { DragManager } from '../../util/DragManager';
-import { undoBatch } from '../../util/UndoManager';
-import { TextField } from '../../../fields/TextField';
-import { Document } from '../../../fields/Document';
+import { InkingControl } from '../InkingControl';
+import { NumberField } from '../../../fields/NumberField';
@observer
export class ImageBox extends React.Component<FieldViewProps> {
@@ -33,21 +34,19 @@ export class ImageBox extends React.Component<FieldViewProps> {
super(props);
this._imgRef = React.createRef();
- this.state = {
- photoIndex: 0,
- isOpen: false,
- };
}
@action
onLoad = (target: any) => {
var h = this._imgRef.current!.naturalHeight;
var w = this._imgRef.current!.naturalWidth;
- this.props.Document.SetNumber(KeyStore.NativeHeight, this.props.Document.GetNumber(KeyStore.NativeWidth, 0) * h / w);
+ if (this._photoIndex === 0) {
+ this.props.Document.SetNumber(KeyStore.NativeHeight, this.props.Document.GetNumber(KeyStore.NativeWidth, 0) * h / w);
+ this.props.Document.GetTAsync(KeyStore.Width, NumberField, field =>
+ field && this.props.Document.SetNumber(KeyStore.Height, field.Data * h / w));
+ }
}
- componentDidMount() {
- }
protected createDropTarget = (ele: HTMLDivElement) => {
if (this.dropDisposer) {
@@ -57,8 +56,10 @@ export class ImageBox extends React.Component<FieldViewProps> {
this.dropDisposer = DragManager.MakeDropTarget(ele, { handlers: { drop: this.drop.bind(this) } });
}
}
-
- componentWillUnmount() {
+ onDrop = (e: React.DragEvent) => {
+ e.stopPropagation();
+ e.preventDefault();
+ console.log("IMPLEMENT ME PLEASE");
}
@@ -70,7 +71,7 @@ export class ImageBox extends React.Component<FieldViewProps> {
if (layout.indexOf(ImageBox.name) !== -1) {
let imgData = this.props.Document.Get(KeyStore.Data);
if (imgData instanceof ImageField && imgData) {
- this.props.Document.Set(KeyStore.Data, new ListField([imgData]));
+ this.props.Document.SetOnPrototype(KeyStore.Data, new ListField([imgData]));
}
let imgList = this.props.Document.GetList(KeyStore.Data, [] as any[]);
if (imgList) {
@@ -89,7 +90,6 @@ export class ImageBox extends React.Component<FieldViewProps> {
onPointerDown = (e: React.PointerEvent): void => {
if (Date.now() - this._lastTap < 300) {
if (e.buttons === 1) {
- e.stopPropagation();
this._downX = e.clientX;
this._downY = e.clientY;
document.removeEventListener("pointerup", this.onPointerUp);
@@ -139,6 +139,23 @@ export class ImageBox extends React.Component<FieldViewProps> {
}
}
+ @action
+ onDotDown(index: number) {
+ this._photoIndex = index;
+ this.props.Document.SetNumber(KeyStore.CurPage, index);
+ }
+
+ dots(paths: string[]) {
+ let nativeWidth = this.props.Document.GetNumber(KeyStore.NativeWidth, 1);
+ let dist = Math.min(nativeWidth / paths.length, 40);
+ let left = (nativeWidth - paths.length * dist) / 2;
+ return paths.map((p, i) =>
+ <div className="imageBox-placer" key={i} >
+ <div className="imageBox-dot" style={{ background: (i == this._photoIndex ? "black" : "gray"), transform: `translate(${i * dist + left}px, 0px)` }} onPointerDown={(e: React.PointerEvent) => { e.stopPropagation(); this.onDotDown(i); }} />
+ </div>
+ );
+ }
+
render() {
let field = this.props.Document.Get(this.props.fieldKey);
let paths: string[] = ["http://www.cs.brown.edu/~bcz/face.gif"];
@@ -146,9 +163,11 @@ export class ImageBox extends React.Component<FieldViewProps> {
else if (field instanceof ImageField) paths = [field.Data.href];
else if (field instanceof ListField) paths = field.Data.filter(val => val as ImageField).map(p => (p as ImageField).Data.href);
let nativeWidth = this.props.Document.GetNumber(KeyStore.NativeWidth, 1);
+ let interactive = InkingControl.Instance.selectedTool ? "" : "-interactive";
return (
- <div className="imageBox-cont" onPointerDown={this.onPointerDown} ref={this.createDropTarget} onContextMenu={this.specificContextMenu}>
- <img src={paths[0]} width={nativeWidth} alt="Image not found" ref={this._imgRef} onLoad={this.onLoad} />
+ <div className={`imageBox-cont${interactive}`} onPointerDown={this.onPointerDown} onDrop={this.onDrop} ref={this.createDropTarget} onContextMenu={this.specificContextMenu}>
+ <img src={paths[Math.min(paths.length, this._photoIndex)]} style={{ objectFit: (this._photoIndex === 0 ? undefined : "contain") }} width={nativeWidth} alt="Image not found" ref={this._imgRef} onLoad={this.onLoad} />
+ {paths.length > 1 ? this.dots(paths) : (null)}
{this.lightbox(paths)}
</div>);
}