module Capybara::Selenium::Node::Html5Drag

def drag_to(element, html5: nil, delay: 0.05, drop_modifiers: [])

def drag_to(element, html5: nil, delay: 0.05, drop_modifiers: [])
  drop_modifiers = Array(drop_modifiers)
  driver.execute_script MOUSEDOWN_TRACKER
  scroll_if_needed { browser_action.click_and_hold(native).perform }
  html5 = !driver.evaluate_script(LEGACY_DRAG_CHECK, self) if html5.nil?
  if html5
    perform_html5_drag(element, delay, drop_modifiers)
  else
    perform_legacy_drag(element, drop_modifiers)
  end
end

def html5_drop(*args)

def html5_drop(*args)
  if args[0].is_a? String
    input = driver.evaluate_script ATTACH_FILE
    input.set_file(args)
    driver.execute_script DROP_FILE, self, input
  else
    items = args.flat_map do |arg|
      arg.map { |(type, data)| { type: type, data: data } }
    end
    driver.execute_script DROP_STRING, items, self
  end
end

def perform_html5_drag(element, delay, drop_modifiers)

def perform_html5_drag(element, delay, drop_modifiers)
  driver.evaluate_async_script HTML5_DRAG_DROP_SCRIPT, self, element, delay * 1000, normalize_keys(drop_modifiers)
  browser_action.release.perform
end

def perform_legacy_drag(element, drop_modifiers)

def perform_legacy_drag(element, drop_modifiers)
  element.scroll_if_needed do
    # browser_action.move_to(element.native).release.perform
    keys_down = modifiers_down(browser_action, drop_modifiers)
    keys_up = modifiers_up(keys_down.move_to(element.native).release, drop_modifiers)
    keys_up.perform
  end
end