aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraidahosa1 <aisosa_idahosa@brown.edu>2024-03-20 03:27:55 -0400
committeraidahosa1 <aisosa_idahosa@brown.edu>2024-03-20 03:27:55 -0400
commit7066e56d03cef12076a1c60c3cebad1d263ef2b3 (patch)
tree7207a177d25aa09c37333978df2799c8dfda85a2
parent66f904921ef519e1b54cb013ea7fafc640ae3dc7 (diff)
me vs pointer events who will win
-rw-r--r--src/client/views/DocComponent.tsx2
-rw-r--r--src/client/views/collections/CollectionCardDeckView.tsx168
2 files changed, 94 insertions, 76 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index 18e7ab12a..a7a9763ec 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -35,7 +35,7 @@ export interface ViewBoxInterface {
addDocument?: (doc: Doc | Doc[], annotationKey?: string) => boolean; // add a document (used only by collections)
removeDocument?: (doc: Doc | Doc[], annotationKey?: string, leavePushpin?: boolean, dontAddToRemoved?: boolean) => boolean; // add a document (used only by collections)
select?: (ctrlKey: boolean, shiftKey: boolean) => void;
- focus?: (textAnchor: Doc, options: FocusViewOptions) => Opt<number>;
+ focus?: (textAnchor: Doc, options: FocusViewOptions) => Opt<number>;
viewTransition?: () => Opt<string>; // duration of a view transition animation
isAnyChildContentActive?: () => boolean; // is any child content of the document active
onClickScriptDisable?: () => 'never' | 'always'; // disable click scripts : never, always, or undefined = only when selected
diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx
index e35f7b421..778280215 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -1,6 +1,6 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { computed, makeObservable } from 'mobx';
-import { observer } from 'mobx-react';
+import { computed, makeObservable, observable, action } from 'mobx';
+import { observer, } from 'mobx-react';
import * as React from 'react';
import { Utils, emptyFunction, returnFalse, returnZero } from '../../../Utils';
import { Doc, DocListCast } from '../../../fields/Doc';
@@ -14,12 +14,31 @@ import { DocumentView } from '../nodes/DocumentView';
import { FocusViewOptions } from '../nodes/FieldView';
import './CollectionCarousel3DView.scss';
import { CollectionSubView } from './CollectionSubView';
+import { ScriptField } from '../../../fields/ScriptField';
+
const { default: { CAROUSEL3D_CENTER_SCALE, CAROUSEL3D_SIDE_SCALE, CAROUSEL3D_TOP } } = require('../global/globalCssVariables.module.scss'); // prettier-ignore
@observer
export class CollectionCardView extends CollectionSubView() {
- @computed get scrollSpeed() {
- return this.layoutDoc._autoScrollSpeed ? NumCast(this.layoutDoc._autoScrollSpeed) : 1000; //default scroll speed
- }
+ // @computed get scrollSpeed() {
+ // return this.layoutDoc._autoScrollSpeed ? NumCast(this.layoutDoc._autoScrollSpeed) : 1000; //default scroll speed
+ // }
+
+ selectedNodeIndex = observable.box(-1); // -1 indicates no selection
+
+ @action
+ setSelectedNodeIndex = (index: number) => {
+ console.log('hi');
+ SelectionManager.DeselectAll();
+ this.selectedNodeIndex.set(index);
+ };
+
+ @computed
+ get rotationDegree() {
+ return this.isChildContentActive() ? 30 : 0; // Rotate by 30 degrees if selected, otherwise no rotation
+}
+
+
+
constructor(props: any) {
super(props);
makeObservable(this);
@@ -39,17 +58,23 @@ export class CollectionCardView extends CollectionSubView() {
};
centerScale = Number(CAROUSEL3D_CENTER_SCALE);
- panelWidth = () => this._props.PanelWidth() / 3;
- panelHeight = () => this._props.PanelHeight() * Number(CAROUSEL3D_SIDE_SCALE);
+ panelWidth = () => (this._props.PanelWidth()) / this.childLayoutPairs.length;
+ panelHeight = () => this.panelWidth() * 1.5;
onChildDoubleClick = () => ScriptCast(this.layoutDoc.onChildDoubleClick);
+ onChildClick = () => ScriptCast(this.rotate(3, 3));
isContentActive = () => this._props.isSelected() || this._props.isContentActive() || this._props.isAnyChildContentActive();
isChildContentActive = () => (this.isContentActive() ? true : false);
+
+ //thid needs to be fixed
childScreenToLocal = () =>
this._props // document's left is the panel shifted by the doc's index * panelWidth/#docs. But it scales by centerScale around its center, so it's left moves left by the distance of the left from the center (panelwidth/2) * the scale delta (centerScale-1)
.ScreenToLocalTransform() // the top behaves the same way ecept it's shifted by the 'top' amount specified for the panel in css and then by the scale factor.
- .translate(-this.panelWidth() + ((this.centerScale - 1) * this.panelWidth()) / 2, -((Number(CAROUSEL3D_TOP) / 100) * this._props.PanelHeight()) + ((this.centerScale - 1) * this.panelHeight()) / 2)
- .scale(1 / this.centerScale);
+ // .translate(-this.panelWidth() + ((this.centerScale - 1) * this.panelWidth()) / 2,-((Number(CAROUSEL3D_TOP) / 100) * this._props.PanelHeight()) + ((this.centerScale - 1) * this.panelHeight()) / 2)
+ .rotate(this.rotate(this.childLayoutPairs.length, Number(this.layoutDoc._carousel_index)))
+ // .scale(1 / this.centerScale);
+
+ //literally doesnot do anythin
focus = (anchor: Doc, options: FocusViewOptions) => {
const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
if (anchor.type !== DocumentType.CONFIG && !docs.includes(anchor)) return;
@@ -60,15 +85,41 @@ export class CollectionCardView extends CollectionSubView() {
return undefined;
};
+ rotate = (amCards: number, index: number) => {
+
+ const possRotate = -30 + (index * (30/((amCards - (amCards%2))/2)));
+
+ if (amCards%2 == 0 && possRotate==0){
+ console.log('whaddup')
+ return possRotate + Math.abs(-30 + ((index-1) * (30/((amCards - 1)/2))))
+ }
+
+ return possRotate;
+ }
+
+ // translateY = (amCards: number, index: number) => {
+ // // Assuming you want a default value when index > amCards/2
+ // // Adjust the logic as necessary for your use case
+ // if (index <= amCards / 2) {
+ // return -((50 / ((amCards - (amCards % 2)) / 2)) * index);
+ // } else {
+ // // Return a default or calculated value for indices greater than amCards/2
+ // // This is just an example; adjust the logic as needed
+ // return -((50 / ((amCards - (amCards % 2)) / 2)) * (amCards - index - 1));
+ // }
+ // };
+
@computed get content() {
- const currentIndex = NumCast(this.layoutDoc._carousel_index);
+ // const currentIndex = NumCast(this.layoutDoc._carousel_index);
+ const amCards = this.childLayoutPairs.length;
const displayDoc = (childPair: { layout: Doc; data: Doc }) => {
return (
<DocumentView
{...this._props}
Document={childPair.layout}
TemplateDataDocument={childPair.data}
+ // onClickScript={this.toggleIcon}
//suppressSetHeight={true}
NativeWidth={returnZero}
NativeHeight={returnZero}
@@ -88,76 +139,41 @@ export class CollectionCardView extends CollectionSubView() {
};
return this.childLayoutPairs.map((childPair, index) => {
+
+ const isSelected = this.selectedNodeIndex.get() === index;
+ const rotationDegree = isSelected ? 30 : 0; // Rotate selected node by 5 degrees, for example
+
+
return (
- <div key={childPair.layout[Id]} className={`collectionCarousel3DView-item${index === currentIndex ? '-active' : ''} ${index}`} style={{ width: this.panelWidth() }}>
+ <div key={childPair.layout[Id]}
+ // className={`collectionCarousel3DView-item${index === currentIndex ? '-active' : ''} ${index}`}
+ style={{ width: this.panelWidth(), height: this.panelHeight(),
+ transform: `rotate(${this.rotate(amCards, index) + rotationDegree}deg)`,
+
+
+ // translateY(${this.translateY(amCards, index)}px)`,
+ }}
+ onClick={() => this.setSelectedNodeIndex(index)}
+
+
+
+ >
+ {/* {this.lol(childPair.data, index)} */}
+
+
{displayDoc(childPair)}
- </div>
+ </div>
);
});
}
- changeSlide = (direction: number) => {
- SelectionManager.DeselectAll();
- this.layoutDoc._carousel_index = (NumCast(this.layoutDoc._carousel_index) + direction + this.childLayoutPairs.length) % this.childLayoutPairs.length;
- };
-
- onArrowClick = (direction: number) => {
- this.changeSlide(direction);
- !this.layoutDoc.autoScrollOn && (this.layoutDoc.showScrollButton = direction === 1 ? 'fwd' : 'back'); // while autoscroll is on, keep the other autoscroll button hidden
- !this.layoutDoc.autoScrollOn && this.fadeScrollButton(); // keep pause button visible while autoscroll is on
- };
-
- interval?: number;
- startAutoScroll = (direction: number) => {
- this.interval = window.setInterval(() => {
- this.changeSlide(direction);
- }, this.scrollSpeed);
- };
+ // lol = (d : Doc, index: number) => {
+ // if (SelectionManager.IsSelected(d)){
+ // this.setSelectedNodeIndex(index);
- stopAutoScroll = () => {
- window.clearInterval(this.interval);
- this.interval = undefined;
- this.fadeScrollButton();
- };
-
- toggleAutoScroll = (direction: number) => {
- this.layoutDoc.autoScrollOn = this.layoutDoc.autoScrollOn ? false : true;
- this.layoutDoc.autoScrollOn ? this.startAutoScroll(direction) : this.stopAutoScroll();
- };
+ // }
+ // }
- fadeScrollButton = () => {
- window.setTimeout(() => {
- !this.layoutDoc.autoScrollOn && (this.layoutDoc.showScrollButton = 'none'); //fade away after 1.5s if it's not clicked.
- }, 1500);
- };
-
- @computed get buttons() {
- return (
- <div className="arrow-buttons">
- <div title="click to go back" key="back" className="carousel3DView-back" onClick={e => this.onArrowClick(-1)} />
- <div title="click to advance" key="fwd" className="carousel3DView-fwd" onClick={e => this.onArrowClick(1)} />
- {/* {this.autoScrollButton} */}
- </div>
- );
- }
-
- @computed get autoScrollButton() {
- const whichButton = this.layoutDoc.showScrollButton;
- return (
- <>
- <div className={`carousel3DView-back-scroll${whichButton === 'back' ? '' : '-hidden'}`} style={{ background: `${StrCast(this.Document.backgroundColor)}` }} onClick={() => this.toggleAutoScroll(-1)}>
- {this.layoutDoc.autoScrollOn ? <FontAwesomeIcon icon={'pause'} size={'1x'} /> : <FontAwesomeIcon icon={'angle-double-left'} size={'1x'} />}
- </div>
- <div className={`carousel3DView-fwd-scroll${whichButton === 'fwd' ? '' : '-hidden'}`} style={{ background: `${StrCast(this.Document.backgroundColor)}` }} onClick={() => this.toggleAutoScroll(1)}>
- {this.layoutDoc.autoScrollOn ? <FontAwesomeIcon icon={'pause'} size={'1x'} /> : <FontAwesomeIcon icon={'angle-double-right'} size={'1x'} />}
- </div>
- </>
- );
- }
-
- @computed get dots() {
- return this.childLayoutPairs.map((_child, index) => <div key={Utils.GenerateGuid()} className={`dot${index === NumCast(this.layoutDoc._carousel_index) ? '-active' : ''}`} onClick={() => (this.layoutDoc._carousel_index = index)} />);
- }
@computed get translateX() {
const index = NumCast(this.layoutDoc._carousel_index);
return this.panelWidth() * (1 - index);
@@ -172,11 +188,13 @@ export class CollectionCardView extends CollectionSubView() {
background: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.BackgroundColor),
color: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.Color),
}}>
- <div className="carousel-wrapper" style={{ transform: `translateX(${this.translateX}px)` }}>
+ <div className="carousel-wrapper"
+ // style={{ transform: `translateX(${this.translateX}px)` }}
+ >
{this.content}
</div>
- {this.buttons}
- <div className="dot-bar">{this.dots}</div>
+ {/* {this.buttons}
+ <div className="dot-bar">{this.dots}</div> */}
</div>
);
}