mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
fix prompt drag/drop
This commit is contained in:
+13
-7
@@ -45,27 +45,33 @@ function dropReplaceImage(imgWrap, files) {
|
||||
}
|
||||
|
||||
window.document.addEventListener('dragover', (e) => {
|
||||
log('dragoverEvent', e);
|
||||
const target = e.composedPath()[0];
|
||||
const imgWrap = target.closest('[data-testid="image"]');
|
||||
if (!imgWrap && target.placeholder && target.placeholder.indexOf('Prompt') === -1) return;
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'copy';
|
||||
if ((e.dataTransfer?.files?.length || 0) > 0) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'copy';
|
||||
}
|
||||
});
|
||||
|
||||
window.document.addEventListener('drop', (e) => {
|
||||
log('dropEvent', e);
|
||||
const target = e.composedPath()[0];
|
||||
if (!target.placeholder) return;
|
||||
if (target.placeholder.indexOf('Prompt') === -1) return;
|
||||
const imgWrap = target.closest('[data-testid="image"]');
|
||||
if (!imgWrap) return;
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
const { files } = e.dataTransfer;
|
||||
dropReplaceImage(imgWrap, files);
|
||||
if ((e.dataTransfer?.files?.length || 0) > 0) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
dropReplaceImage(imgWrap, e.dataTransfer.files);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('paste', (e) => {
|
||||
log('pasteEvent', e.clipboardData);
|
||||
const { files } = e.clipboardData;
|
||||
if (!isValidImageList(files)) return;
|
||||
const visibleImageFields = [...gradioApp().querySelectorAll('[data-testid="image"]')]
|
||||
|
||||
@@ -9,16 +9,15 @@ async function initDragDrop() {
|
||||
if (!target.placeholder) return;
|
||||
if (target.placeholder.indexOf('Prompt') === -1) return;
|
||||
const promptTarget = get_tab_index('tabs') === 1 ? 'img2img_prompt_image' : 'txt2img_prompt_image';
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
const imgParent = gradioApp().getElementById(promptTarget);
|
||||
if (!imgParent) return;
|
||||
const { files } = e.dataTransfer;
|
||||
const fileInput = imgParent.querySelector('input[type="file"]');
|
||||
if (fileInput) {
|
||||
fileInput.files = files;
|
||||
if (!imgParent || !fileInput) return;
|
||||
if ((e.dataTransfer?.files?.length || 0) > 0) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
fileInput.files = e.dataTransfer.files;
|
||||
fileInput.dispatchEvent(new Event('change'));
|
||||
log('dropEvent');
|
||||
log('dropEvent files', fileInput.files);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user