112 lines
16 KiB
JavaScript
112 lines
16 KiB
JavaScript
export const DROP_EFFECTS = ['move', 'copy', 'link'];
|
|
export const CUSTOM_MIME_TYPE = 'application/x-dnd';
|
|
export const JSON_MIME_TYPE = 'application/json';
|
|
export const MSIE_MIME_TYPE = 'Text';
|
|
function mimeTypeIsCustom(mimeType) {
|
|
return mimeType.substr(0, CUSTOM_MIME_TYPE.length) === CUSTOM_MIME_TYPE;
|
|
}
|
|
export function getWellKnownMimeType(event) {
|
|
if (event.dataTransfer) {
|
|
const types = event.dataTransfer.types;
|
|
// IE 9 workaround.
|
|
if (!types) {
|
|
return MSIE_MIME_TYPE;
|
|
}
|
|
for (let i = 0; i < types.length; i++) {
|
|
if (types[i] === MSIE_MIME_TYPE ||
|
|
types[i] === JSON_MIME_TYPE ||
|
|
mimeTypeIsCustom(types[i])) {
|
|
return types[i];
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
export function setDragData(event, data, effectAllowed) {
|
|
// Internet Explorer and Microsoft Edge don't support custom mime types, see design doc:
|
|
// https://github.com/marceljuenemann/angular-drag-and-drop-lists/wiki/Data-Transfer-Design
|
|
const mimeType = CUSTOM_MIME_TYPE + (data.type ? '-' + data.type : '');
|
|
const dataString = JSON.stringify(data);
|
|
try {
|
|
event.dataTransfer?.setData(mimeType, dataString);
|
|
}
|
|
catch (e) {
|
|
// Setting a custom MIME type did not work, we are probably in IE or Edge.
|
|
try {
|
|
event.dataTransfer?.setData(JSON_MIME_TYPE, dataString);
|
|
}
|
|
catch (e) {
|
|
// We are in Internet Explorer and can only use the Text MIME type. Also note that IE
|
|
// does not allow changing the cursor in the dragover event, therefore we have to choose
|
|
// the one we want to display now by setting effectAllowed.
|
|
const effectsAllowed = filterEffects(DROP_EFFECTS, effectAllowed);
|
|
if (event.dataTransfer) {
|
|
event.dataTransfer.effectAllowed = effectsAllowed[0];
|
|
}
|
|
event.dataTransfer?.setData(MSIE_MIME_TYPE, dataString);
|
|
}
|
|
}
|
|
}
|
|
export function getDropData(event, dragIsExternal) {
|
|
// check if the mime type is well known
|
|
const mimeType = getWellKnownMimeType(event);
|
|
// drag did not originate from [dndDraggable]
|
|
if (dragIsExternal === true) {
|
|
if (mimeType !== null && mimeTypeIsCustom(mimeType)) {
|
|
// the type of content is well known and safe to handle
|
|
return JSON.parse(event.dataTransfer?.getData(mimeType) ?? '{}');
|
|
}
|
|
// the contained data is unknown, let user handle it
|
|
return {};
|
|
}
|
|
if (mimeType !== null) {
|
|
// the type of content is well known and safe to handle
|
|
return JSON.parse(event.dataTransfer?.getData(mimeType) ?? '{}');
|
|
}
|
|
// the contained data is unknown, let user handle it
|
|
return {};
|
|
}
|
|
export function filterEffects(effects, allowed) {
|
|
if (allowed === 'all' || allowed === 'uninitialized') {
|
|
return effects;
|
|
}
|
|
return effects.filter(function (effect) {
|
|
return allowed.toLowerCase().indexOf(effect) !== -1;
|
|
});
|
|
}
|
|
export function getDirectChildElement(parentElement, childElement) {
|
|
let directChild = childElement;
|
|
while (directChild.parentNode !== parentElement) {
|
|
// reached root node without finding given parent
|
|
if (!directChild.parentNode) {
|
|
return null;
|
|
}
|
|
directChild = directChild.parentNode;
|
|
}
|
|
return directChild;
|
|
}
|
|
export function shouldPositionPlaceholderBeforeElement(event, element, horizontal) {
|
|
const bounds = element.getBoundingClientRect();
|
|
// If the pointer is in the upper half of the list item element,
|
|
// we position the placeholder before the list item, otherwise after it.
|
|
if (horizontal) {
|
|
return event.clientX < bounds.left + bounds.width / 2;
|
|
}
|
|
return event.clientY < bounds.top + bounds.height / 2;
|
|
}
|
|
export function calculateDragImageOffset(event, dragImage) {
|
|
const dragImageComputedStyle = window.getComputedStyle(dragImage);
|
|
const paddingTop = parseFloat(dragImageComputedStyle.paddingTop) || 0;
|
|
const paddingLeft = parseFloat(dragImageComputedStyle.paddingLeft) || 0;
|
|
const borderTop = parseFloat(dragImageComputedStyle.borderTopWidth) || 0;
|
|
const borderLeft = parseFloat(dragImageComputedStyle.borderLeftWidth) || 0;
|
|
return {
|
|
x: event.offsetX + paddingLeft + borderLeft,
|
|
y: event.offsetY + paddingTop + borderTop,
|
|
};
|
|
}
|
|
export function setDragImage(event, dragImage, offsetFunction) {
|
|
const offset = offsetFunction(event, dragImage) || { x: 0, y: 0 };
|
|
event.dataTransfer.setDragImage(dragImage, offset.x, offset.y);
|
|
}
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG5kLXV0aWxzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvZG5kL3NyYy9saWIvZG5kLXV0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWlCQSxNQUFNLENBQUMsTUFBTSxZQUFZLEdBQUcsQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLE1BQU0sQ0FBaUIsQ0FBQztBQUVyRSxNQUFNLENBQUMsTUFBTSxnQkFBZ0IsR0FBRyxtQkFBbUIsQ0FBQztBQUNwRCxNQUFNLENBQUMsTUFBTSxjQUFjLEdBQUcsa0JBQWtCLENBQUM7QUFDakQsTUFBTSxDQUFDLE1BQU0sY0FBYyxHQUFHLE1BQU0sQ0FBQztBQUVyQyxTQUFTLGdCQUFnQixDQUFDLFFBQWdCO0lBQ3hDLE9BQU8sUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFDLEVBQUUsZ0JBQWdCLENBQUMsTUFBTSxDQUFDLEtBQUssZ0JBQWdCLENBQUM7QUFDMUUsQ0FBQztBQUVELE1BQU0sVUFBVSxvQkFBb0IsQ0FBQyxLQUFnQjtJQUNuRCxJQUFJLEtBQUssQ0FBQyxZQUFZLEVBQUU7UUFDdEIsTUFBTSxLQUFLLEdBQUcsS0FBSyxDQUFDLFlBQVksQ0FBQyxLQUFLLENBQUM7UUFFdkMsbUJBQW1CO1FBQ25CLElBQUksQ0FBQyxLQUFLLEVBQUU7WUFDVixPQUFPLGNBQWMsQ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