From fa2d4e4e66f7f1de51a579b3a121ca1a2a7d56a8 Mon Sep 17 00:00:00 2001 From: srichman333 Date: Thu, 30 Nov 2023 01:38:05 -0500 Subject: drag onto canvas --- .../collectionFreeForm/CollectionFreeFormView.tsx | 4 +- .../views/nodes/DataVizBox/SchemaCSVPopUp.tsx | 60 ++++++++++++++++------ 2 files changed, 46 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index e1ff4fda3..19689f972 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -1997,10 +1997,10 @@ ScriptingGlobals.add(function datavizFromSchema(doc: Doc) { const loading = Docs.Create.LoadingDocument(file, options); loading.presentation_openInLightbox = true; DocUtils.uploadFileToDoc(file, {}, loading); - // if (view.ComponentView?.addDocument) view.ComponentView?.addDocument(loading); if (view.ComponentView?.addDocument) { - SchemaCSVPopUp.Instance.addToCollection = view.ComponentView?.addDocument; + SchemaCSVPopUp.Instance.setView(view); + SchemaCSVPopUp.Instance.setTarget(view.rootDoc); SchemaCSVPopUp.Instance.setDataVizDoc(loading); SchemaCSVPopUp.Instance.setVisible(true); } diff --git a/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx b/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx index 99b7dd3c4..0114721a2 100644 --- a/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx +++ b/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx @@ -6,6 +6,9 @@ import { Doc } from '../../../../fields/Doc'; import { Button, Type } from 'browndash-components'; import { StrCast } from '../../../../fields/Types'; import { MarqueeView } from '../../collections/collectionFreeForm/MarqueeView'; +import { Utils, emptyFunction, setupMoveUpEvents } from '../../../../Utils'; +import { DragManager } from '../../../util/DragManager'; +import { DocumentView } from '../DocumentView'; interface SchemaCSVPopUpProps {} @@ -21,20 +24,24 @@ export class SchemaCSVPopUp extends React.Component { }; @observable - public visible: boolean = false; + public view: DocumentView | undefined = undefined; @action - public setVisible = (vis: boolean) => { - this.visible = vis; + public setView = (docView: DocumentView) => { + this.view = docView; }; - public addToCollection: any | undefined; + @observable + public target: Doc | undefined = undefined; + @action + public setTarget = (doc: Doc) => { + this.target = doc; + }; - /** - * Transfers the doc to the user's canvas - */ - private transferToCanvas = () => { - if (this.dataVizDoc) this.addToCollection?.(this.dataVizDoc); - this.setVisible(false); + @observable + public visible: boolean = false; + @action + public setVisible = (vis: boolean) => { + this.visible = vis; }; constructor(props: SchemaCSVPopUpProps) { @@ -48,17 +55,12 @@ export class SchemaCSVPopUp extends React.Component { {this.heading('Schema Table as Data Visualization Doc')}
-
+
this.drag(e)}>
-
-
- {/* {this.props.children} */} -
); @@ -70,6 +72,32 @@ export class SchemaCSVPopUp extends React.Component { ); + drag = (e: React.PointerEvent) => { + const downX = e.clientX; + const downY = e.clientY; + setupMoveUpEvents( + {}, + e, + e => { + const sourceAnchorCreator = () => this.dataVizDoc!; + const targetCreator = (annotationOn: Doc | undefined) => { + const embedding = Doc.MakeEmbedding(this.dataVizDoc!); + return embedding; + }; + if (this.view && sourceAnchorCreator && !Utils.isClick(e.clientX, e.clientY, downX, downY, Date.now())) { + DragManager.StartAnchorAnnoDrag(e.target instanceof HTMLElement ? [e.target] : [], + new DragManager.AnchorAnnoDragData(this.view, sourceAnchorCreator, targetCreator), downX, downY, { + dragComplete: e => {this.setVisible(false);}, + }); + return true; + } + return false; + }, + emptyFunction, + action(e => {}) + ); + }; + render() { return (
-- cgit v1.2.3-70-g09d2