File size: 1,073 Bytes
c19ca42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let dragDropInitialized = false;

async function initDragDrop() {
  if (dragDropInitialized) return;
  dragDropInitialized = true;
  log('initDragDrop');
  window.addEventListener('drop', (e) => {
    const target = e.composedPath()[0];
    if (!target.placeholder) return;
    if (target.placeholder.indexOf('Prompt') === -1) return;
    const tab = get_tab_index('tabs');
    let promptTarget = '';
    if (tab === 0) promptTarget = 'txt2img_prompt_image';
    else if (tab === 1) promptTarget = 'img2img_prompt_image';
    else if (tab === 2) promptTarget = 'control_prompt_image';
    else return;
    const imgParent = gradioApp().getElementById(promptTarget);
    const fileInput = imgParent.querySelector('input[type="file"]');
    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 files', fileInput.files);
    }
  });
}

onAfterUiUpdate(initDragDrop);