forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdndData.js
32 lines (26 loc) · 1.3 KB
/
dndData.js
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
32
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const Immutable = require('immutable')
module.exports.hasDragData = (dataTransfer, dragType) => {
return !!dataTransfer.getData(`application/x-brave-${dragType}`)
}
module.exports.getDragData = (dataTransfer, dragType) => {
const data = dataTransfer.getData(`application/x-brave-${dragType}`)
if (!data) {
return undefined
}
return Immutable.fromJS(JSON.parse(data))
}
module.exports.setupDataTransferURL = (dataTransfer, location, title) => {
dataTransfer.setData('text/plain', location)
dataTransfer.setData('text/uri-list', location)
dataTransfer.setData('text/html', `<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><A HREF="${location}">${title || location}</A></body></html>`)
}
module.exports.setupDataTransferBraveData = (dataTransfer, dragType, data) => {
dataTransfer.setData(`application/x-brave-${dragType}`, JSON.stringify(data.toJS()))
}
module.exports.shouldPrependVerticalItem = (target, clientY) => {
const boundingRect = target.getBoundingClientRect()
return clientY < boundingRect.top + (boundingRect.bottom - boundingRect.top) / 2
}