mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-23 09:01:56 +03:00
basic link drag and drop
This commit is contained in:
parent
de46ac3896
commit
819219bd90
@ -100,7 +100,7 @@ export const hydrate = async () => {
|
|||||||
return JSON.parse(JSON.stringify(response.data));
|
return JSON.parse(JSON.stringify(response.data));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDroppedFiles = ({ dataTransfer }) => {
|
export const formatDroppedFiles = async ({ dataTransfer }) => {
|
||||||
// NOTE(jim): If this is true, then drag and drop came from a slate object.
|
// NOTE(jim): If this is true, then drag and drop came from a slate object.
|
||||||
const data = dataTransfer.getData("slate-object-drag-data");
|
const data = dataTransfer.getData("slate-object-drag-data");
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -111,15 +111,24 @@ export const formatDroppedFiles = ({ dataTransfer }) => {
|
|||||||
let fileLoading = {};
|
let fileLoading = {};
|
||||||
if (dataTransfer.items && dataTransfer.items.length) {
|
if (dataTransfer.items && dataTransfer.items.length) {
|
||||||
for (var i = 0; i < dataTransfer.items.length; i++) {
|
for (var i = 0; i < dataTransfer.items.length; i++) {
|
||||||
if (dataTransfer.items[i].kind === "file") {
|
const it = dataTransfer.items[i];
|
||||||
var file = dataTransfer.items[i].getAsFile();
|
var file = null;
|
||||||
files.push(file);
|
if (it.kind === "file") {
|
||||||
fileLoading[`${file.lastModified}-${file.name}`] = {
|
file = it.getAsFile();
|
||||||
name: file.name,
|
} else if (it.kind == "string" && it.type == "text/uri-list") {
|
||||||
loaded: 0,
|
let asString = new Promise((resolve, reject) => it.getAsString((d) => resolve(d))); // kill me
|
||||||
total: file.size,
|
const resp = await fetch(await asString);
|
||||||
};
|
const blob = resp.blob(); // is there an easier way to chain all this await?
|
||||||
|
|
||||||
|
file = new File(blob, "dragged link"); // theres probably some way to get a real file name for this, but i dont think we care?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files.push(file);
|
||||||
|
fileLoading[`${file.lastModified}-${file.name}`] = {
|
||||||
|
name: file.name,
|
||||||
|
loaded: 0,
|
||||||
|
total: file.size,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user