Skip to content

Commit

Permalink
Reorderings with Long Press
Browse files Browse the repository at this point in the history
Swapping to a Long Press to drag and reorders files signals intent. Without this intent, the reordering feature can hijack scrolling on touch-devices, and users can become unintentionally trapped reordering a file. The long press restores user-intent and dramatically improves the UX on touch-devices.

Resolves pqina#865
  • Loading branch information
jakejackson1 committed Oct 16, 2023
1 parent 97bcbca commit f49c0a5
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/filepond.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.30.4
* FilePond 4.30.5
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
23 changes: 21 additions & 2 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.30.4
* FilePond 4.30.5
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -1831,6 +1831,7 @@ const defaultOptions = {
allowRemove: [true, Type.BOOLEAN], // Allow user to remove a file
allowProcess: [true, Type.BOOLEAN], // Allows user to process a file, when set to false, this removes the file upload button
allowReorder: [false, Type.BOOLEAN], // Allow reordering of files
reorderLongPressInterval: [100, Type.INT], // The longpress interval to wait before reordering the file
allowDirectoriesOnly: [false, Type.BOOLEAN], // Allow only selecting directories with browse (no support for filtering dnd at this point)

// Try store file if `server` not set
Expand Down Expand Up @@ -5966,6 +5967,24 @@ const createDragHelper = items => {
};
};

const onLongPress = (element, callback, interval) => {
let timer;

element.addEventListener('pointerdown', e => {
timer = setTimeout(() => {
timer = null;
callback(e);
}, interval);
});

function cancel() {
clearTimeout(timer);
}

element.addEventListener('pointerup', cancel);
element.addEventListener('pointermove', cancel);
};

const ITEM_TRANSLATE_SPRING = {
type: 'spring',
stiffness: 0.75,
Expand Down Expand Up @@ -6091,7 +6110,7 @@ const create$7 = ({ root, props }) => {
document.addEventListener('pointerup', drop);
};

root.element.addEventListener('pointerdown', grab);
onLongPress(root.element, grab, root.query('GET_REORDER_LONG_PRESS_INTERVAL'));
};

const route$1 = createRoute({
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.30.4
* FilePond 4.30.5
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -3757,6 +3757,7 @@
allowRemove: [true, Type.BOOLEAN], // Allow user to remove a file
allowProcess: [true, Type.BOOLEAN], // Allows user to process a file, when set to false, this removes the file upload button
allowReorder: [false, Type.BOOLEAN], // Allow reordering of files
reorderLongPressInterval: [100, Type.INT], // The longpress interval to wait before reordering the file
allowDirectoriesOnly: [false, Type.BOOLEAN], // Allow only selecting directories with browse (no support for filtering dnd at this point)

// Try store file if `server` not set
Expand Down Expand Up @@ -8506,6 +8507,24 @@
};
};

var onLongPress = function onLongPress(element, callback, interval) {
var timer;

element.addEventListener('pointerdown', function(e) {
timer = setTimeout(function() {
timer = null;
callback(e);
}, interval);
});

function cancel() {
clearTimeout(timer);
}

element.addEventListener('pointerup', cancel);
element.addEventListener('pointermove', cancel);
};

var ITEM_TRANSLATE_SPRING = {
type: 'spring',
stiffness: 0.75,
Expand Down Expand Up @@ -8641,7 +8660,7 @@
document.addEventListener('pointerup', drop);
};

root.element.addEventListener('pointerdown', grab);
onLongPress(root.element, grab, root.query('GET_REORDER_LONG_PRESS_INTERVAL'));
};

var route$1 = createRoute({
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/filepond.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filepond",
"version": "4.30.4",
"version": "4.30.5",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
1 change: 1 addition & 0 deletions src/js/app/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const defaultOptions = {
allowRemove: [true, Type.BOOLEAN], // Allow user to remove a file
allowProcess: [true, Type.BOOLEAN], // Allows user to process a file, when set to false, this removes the file upload button
allowReorder: [false, Type.BOOLEAN], // Allow reordering of files
reorderLongPressInterval: [100, Type.INT], // The longpress interval to wait before reordering the file
allowDirectoriesOnly: [false, Type.BOOLEAN], // Allow only selecting directories with browse (no support for filtering dnd at this point)

// Try store file if `server` not set
Expand Down
3 changes: 2 additions & 1 deletion src/js/app/view/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createView, createRoute } from '../frame/index';
import { fileWrapper } from './fileWrapper';
import { panel } from './panel';
import { createDragHelper } from '../utils/createDragHelper';
import { onLongPress } from '../../utils/onLongPress'

const ITEM_TRANSLATE_SPRING = {
type: 'spring',
Expand Down Expand Up @@ -136,7 +137,7 @@ const create = ({ root, props }) => {
document.addEventListener('pointerup', drop);
}

root.element.addEventListener('pointerdown', grab);
onLongPress(root.element, grab, root.query('GET_REORDER_LONG_PRESS_INTERVAL'))
};

const route = createRoute({
Expand Down
17 changes: 17 additions & 0 deletions src/js/utils/onLongPress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const onLongPress = (element, callback, interval) => {
let timer;

element.addEventListener('pointerdown', (e) => {
timer = setTimeout(() => {
timer = null;
callback(e);
}, interval);
});

function cancel() {
clearTimeout(timer);
}

element.addEventListener('pointerup', cancel);
element.addEventListener('pointermove', cancel);
};

0 comments on commit f49c0a5

Please sign in to comment.