-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWC-4693 #5612
SWC-4693 #5612
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,11 @@ | |
import com.google.gwt.user.client.ui.RootPanel; | ||
import com.google.gwt.user.datepicker.client.CalendarUtil; | ||
import com.google.inject.Inject; | ||
import elemental2.dom.DomGlobal; | ||
import elemental2.dom.DragEvent; | ||
import elemental2.dom.EventListener; | ||
import elemental2.dom.FileList; | ||
import elemental2.dom.HTMLDivElement; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
@@ -483,61 +487,61 @@ public void initializeToastContainer() { | |
public void initializeDropZone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored to JsInterop for easier debugging |
||
if (!isDragDropInitialized) { | ||
isDragDropInitialized = true; | ||
Element dropZoneElement = RootPanel.get("dropzone").getElement(); | ||
Element rootPanelElement = RootPanel.get("rootPanel").getElement(); | ||
_initializeDragDrop(this, dropZoneElement, rootPanelElement); | ||
HTMLDivElement dropZoneElement = | ||
(HTMLDivElement) DomGlobal.document.querySelector("[id=\"dropzone\"]"); | ||
HTMLDivElement rootPanelElement = | ||
(HTMLDivElement) DomGlobal.document.querySelector("[id=\"rootPanel\"]"); | ||
initializeDragDrop(this, dropZoneElement, rootPanelElement); | ||
} | ||
} | ||
|
||
private static final native void _initializeDragDrop( | ||
private static void initializeDragDrop( | ||
GlobalApplicationStateImpl globalAppState, | ||
Element dropZone, | ||
Element rootPanel | ||
) /*-{ | ||
try { | ||
function showDropZone() { | ||
dropZone.style.display = "block"; | ||
} | ||
|
||
function hideDropZone() { | ||
dropZone.style.display = "none"; | ||
} | ||
|
||
$wnd | ||
.addEventListener( | ||
'dragenter', | ||
function(e) { | ||
if (globalAppState.@org.sagebionetworks.web.client.GlobalApplicationStateImpl::isDragAndDropListenerSet()()) { | ||
showDropZone(); | ||
} | ||
}); | ||
|
||
function allowDrag(e) { | ||
e.dataTransfer.dropEffect = 'copy'; | ||
e.preventDefault(); | ||
} | ||
|
||
function handleDrop(e) { | ||
e.preventDefault(); | ||
hideDropZone(); | ||
globalAppState.@org.sagebionetworks.web.client.GlobalApplicationStateImpl::onDrop(Lelemental2/dom/FileList;)(e.dataTransfer.files); | ||
} | ||
|
||
dropZone.addEventListener('dragenter', allowDrag); | ||
dropZone.addEventListener('dragover', allowDrag); | ||
|
||
dropZone.addEventListener('drop', handleDrop); | ||
|
||
//if files are dropped into the root panel, then ignore the event (do not open file contents if user does not have the upload dialog open). | ||
rootPanel.addEventListener('drop', function(e) { | ||
e.preventDefault(); | ||
}); | ||
rootPanel.addEventListener('dragenter', allowDrag); | ||
rootPanel.addEventListener('dragover', allowDrag); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}-*/; | ||
HTMLDivElement dropZone, | ||
HTMLDivElement rootPanel | ||
) { | ||
try { | ||
Runnable showDropZone = () -> dropZone.style.set("display", "block"); | ||
Runnable hideDropZone = () -> dropZone.style.set("display", "none"); | ||
|
||
DomGlobal.window.addEventListener( | ||
"dragenter", | ||
e -> { | ||
if (globalAppState.isDragAndDropListenerSet()) { | ||
showDropZone.run(); | ||
} | ||
} | ||
); | ||
|
||
EventListener allowDrag = e -> { | ||
if (e instanceof DragEvent) { | ||
((DragEvent) e).dataTransfer.dropEffect = "copy"; | ||
e.preventDefault(); | ||
} | ||
}; | ||
EventListener handleDrop = e -> { | ||
if (e instanceof DragEvent) { | ||
e.preventDefault(); | ||
hideDropZone.run(); | ||
globalAppState.onDrop(((DragEvent) e).dataTransfer.files); | ||
} | ||
}; | ||
|
||
dropZone.addEventListener("dragenter", allowDrag); | ||
dropZone.addEventListener("dragover", allowDrag); | ||
|
||
dropZone.addEventListener("drop", handleDrop); | ||
dropZone.addEventListener("dragend", e -> hideDropZone.run()); | ||
dropZone.addEventListener("dragleave", e -> hideDropZone.run()); | ||
Comment on lines
+534
to
+535
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add dragend/dragleave handlers to fix bug where if you dragged into the window, then dragged out of the window, the dropzone wouldn't go away. |
||
|
||
//if files are dropped into the root panel, then ignore the event (do not open file contents if user does not have the upload dialog open). | ||
rootPanel.addEventListener("drop", elemental2.dom.Event::preventDefault); | ||
rootPanel.addEventListener("dragenter", allowDrag); | ||
rootPanel.addEventListener("dragover", allowDrag); | ||
} catch (Exception e) { | ||
DomGlobal.console.error("Error on drag-and-drop initialization", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void setDropZoneHandler(CallbackP<FileList> fileListCallback) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
import jsinterop.annotations.JsFunction; | ||
import jsinterop.annotations.JsNullable; | ||
import jsinterop.annotations.JsOverlay; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
@@ -20,20 +21,26 @@ public interface Callback { | |
|
||
public Callback onClose; | ||
|
||
@JsNullable | ||
public Callback onUploadReady; | ||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use new callback prop |
||
|
||
@JsNullable | ||
public ReactRef<EntityUploadHandle> ref; | ||
|
||
@JsOverlay | ||
public static EntityUploadModalProps create( | ||
String containerId, | ||
boolean open, | ||
Callback onClose, | ||
ReactRef<EntityUploadHandle> ref | ||
ReactRef<EntityUploadHandle> ref, | ||
Callback onUploadReady | ||
) { | ||
EntityUploadModalProps props = new EntityUploadModalProps(); | ||
props.entityId = containerId; | ||
props.open = open; | ||
props.onClose = onClose; | ||
props.ref = ref; | ||
props.onUploadReady = onUploadReady; | ||
return props; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import com.google.gwt.dom.client.Element; | ||
import jsinterop.annotations.JsConstructor; | ||
import jsinterop.annotations.JsFunction; | ||
import jsinterop.annotations.JsNullable; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
||
|
@@ -17,6 +18,10 @@ public interface CallbackRef { | |
void run(Element element); | ||
} | ||
|
||
@JsNullable | ||
public String key; | ||
|
||
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All React components can take a |
||
// Either a ComponentRef or CallbackRef may be passed. A CallbackRef will be invoked when the ref is set. | ||
@JsNullable | ||
public Object ref; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been enabled for weeks, let's remove it!