The UK and the EU have reached a draft agreement on the first phase of Brexit talks after a long night of talks.