dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
37 lines (36 loc) • 1.78 kB
JavaScript
export function resolveDndCapabilities(options) {
if (options.disableDnd) {
return { html5: false, pointer: false, pointerHandlesMouse: false };
}
switch (options.dndStrategy) {
case 'pointer':
return { html5: false, pointer: true, pointerHandlesMouse: true };
case 'html5':
return { html5: true, pointer: false, pointerHandlesMouse: false };
case 'auto':
case undefined:
default:
// On touch-primary devices (phones / basic tablets) HTML5 DnD's
// native long-press intercepts the gesture before our pointer
// backend can react — Android Chrome launches a system drag with
// its half-transparent thumbnail, and the long-press context menu
// never opens. Disable HTML5 there so the pointer backend owns
// every gesture. Hybrid devices (touchscreen laptops, Surface,
// iPad with mouse) keep both backends — mouse uses HTML5, touch
// falls back to whichever backend the underlying element wired.
return isCoarsePrimaryInput()
? { html5: false, pointer: true, pointerHandlesMouse: true }
: { html5: true, pointer: true, pointerHandlesMouse: false };
}
}
function isCoarsePrimaryInput() {
if (typeof window === 'undefined' || !window.matchMedia) {
return false;
}
// Coarse pointer without any fine pointer = phone-class device. A laptop
// touchscreen reports both, and we want HTML5 to remain available there
// because a real mouse is also plugged in.
const coarse = window.matchMedia('(pointer: coarse)').matches;
const fine = window.matchMedia('(pointer: fine)').matches;
return coarse && !fine;
}