Skip to content

Commit

Permalink
fix problem with paste throwing an error and counting ignored files w…
Browse files Browse the repository at this point in the history
…hen dropping folders
  • Loading branch information
rikschennink committed May 20, 2019
1 parent 607ecd0 commit 07c3959
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.4.7

- Fix issue where pasting a file would throw an error.
- Fix issue where ignored files would be counted as files when dropping a folder.


## 4.4.6

- Fix issue where `processFiles` would re-process `local` server images.
Expand Down
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.4.6
* FilePond 4.4.7
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
29 changes: 22 additions & 7 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.4.6
* FilePond 4.4.7
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -3090,7 +3090,7 @@ const createFileStub = source => {
};

const isFile = value =>
value instanceof File || (value instanceof Blob && value.name);
!!(value instanceof File || (value instanceof Blob && value.name));

const deepCloneObject = src => {
if (!isObject(src)) return src;
Expand Down Expand Up @@ -6774,7 +6774,11 @@ const createHopper = (scope, validateItems, options) => {
scope.classList.add('filepond--hopper');

// shortcuts
const { catchesDropsOnPage, requiresDropOnElement } = options;
const {
catchesDropsOnPage,
requiresDropOnElement,
filterItems = items => items
} = options;

// create a dnd client
const client = createDragNDropClient(
Expand All @@ -6791,18 +6795,20 @@ const createHopper = (scope, validateItems, options) => {
client.allowdrop = items => {
// TODO: if we can, throw error to indicate the items cannot by dropped

return validateItems(items);
return validateItems(filterItems(items));
};

client.ondrop = (position, items) => {
if (!validateItems(items)) {
const filteredItems = filterItems(items);

if (!validateItems(filteredItems)) {
api.ondragend(position);
return;
}

currentState = 'drag-drop';

api.onload(items, position);
api.onload(filteredItems, position);
};

client.ondrag = position => {
Expand Down Expand Up @@ -7499,6 +7505,15 @@ const toggleDrop = root => {
: true;
},
{
filterItems: items => {
const ignoredFiles = root.query('GET_IGNORED_FILES');
return items.filter(item => {
if (isFile(item)) {
return !ignoredFiles.includes(item.name.toLowerCase());
}
return true;
});
},
catchesDropsOnPage: root.query('GET_DROP_ON_PAGE'),
requiresDropOnElement: root.query('GET_DROP_ON_ELEMENT')
}
Expand Down Expand Up @@ -7581,7 +7596,7 @@ const togglePaste = root => {
root.ref.paster.onload = items => {
root.dispatch('ADD_ITEMS', {
items,
index: getDragIndex(root.ref.list, position),
index: -1,
interactionMethod: InteractionMethod.PASTE
});
};
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

32 changes: 25 additions & 7 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.4.6
* FilePond 4.4.7
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -3629,7 +3629,7 @@
};

var isFile = function isFile(value) {
return value instanceof File || (value instanceof Blob && value.name);
return !!(value instanceof File || (value instanceof Blob && value.name));
};

var deepCloneObject = function deepCloneObject(src) {
Expand Down Expand Up @@ -7812,7 +7812,14 @@

// shortcuts
var catchesDropsOnPage = options.catchesDropsOnPage,
requiresDropOnElement = options.requiresDropOnElement;
requiresDropOnElement = options.requiresDropOnElement,
_options$filterItems = options.filterItems,
filterItems =
_options$filterItems === void 0
? function(items) {
return items;
}
: _options$filterItems;

// create a dnd client
var client = createDragNDropClient(
Expand All @@ -7829,18 +7836,20 @@
client.allowdrop = function(items) {
// TODO: if we can, throw error to indicate the items cannot by dropped

return validateItems(items);
return validateItems(filterItems(items));
};

client.ondrop = function(position, items) {
if (!validateItems(items)) {
var filteredItems = filterItems(items);

if (!validateItems(filteredItems)) {
api.ondragend(position);
return;
}

currentState = 'drag-drop';

api.onload(items, position);
api.onload(filteredItems, position);
};

client.ondrag = function(position) {
Expand Down Expand Up @@ -8606,6 +8615,15 @@
: true;
},
{
filterItems: function filterItems(items) {
var ignoredFiles = root.query('GET_IGNORED_FILES');
return items.filter(function(item) {
if (isFile(item)) {
return !ignoredFiles.includes(item.name.toLowerCase());
}
return true;
});
},
catchesDropsOnPage: root.query('GET_DROP_ON_PAGE'),
requiresDropOnElement: root.query('GET_DROP_ON_ELEMENT')
}
Expand Down Expand Up @@ -8691,7 +8709,7 @@
root.ref.paster.onload = function(items) {
root.dispatch('ADD_ITEMS', {
items: items,
index: getDragIndex(root.ref.list, position),
index: -1,
interactionMethod: InteractionMethod.PASTE
});
};
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.4.6",
"version": "4.4.7",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
10 changes: 6 additions & 4 deletions src/js/app/utils/createHopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const createHopper = (scope, validateItems, options) => {
scope.classList.add('filepond--hopper');

// shortcuts
const { catchesDropsOnPage, requiresDropOnElement } = options;
const { catchesDropsOnPage, requiresDropOnElement, filterItems = items => items } = options;

// create a dnd client
const client = createDragNDropClient(
Expand All @@ -22,19 +22,21 @@ export const createHopper = (scope, validateItems, options) => {
client.allowdrop = items => {
// TODO: if we can, throw error to indicate the items cannot by dropped

return validateItems(items);
return validateItems(filterItems(items));
};

client.ondrop = (position, items) => {

const filteredItems = filterItems(items);

if (!validateItems(items)) {
if (!validateItems(filteredItems)) {
api.ondragend(position);
return;
}

currentState = 'drag-drop';

api.onload(items, position);
api.onload(filteredItems, position);
};

client.ondrag = position => {
Expand Down
12 changes: 11 additions & 1 deletion src/js/app/view/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { toCamels } from '../../utils/toCamels';
import { createElement } from '../../utils/createElement';
import { createResponse } from '../../utils/createResponse';
import { debounce } from '../../utils/debounce';
import { isFile } from '../../utils/isFile';

const MAX_FILES_LIMIT = 1000000;

Expand Down Expand Up @@ -451,6 +452,15 @@ const toggleDrop = (root) => {
) : true;
},
{
filterItems: items => {
const ignoredFiles = root.query('GET_IGNORED_FILES');
return items.filter(item => {
if (isFile(item)) {
return !ignoredFiles.includes(item.name.toLowerCase())
}
return true;
})
},
catchesDropsOnPage: root.query('GET_DROP_ON_PAGE'),
requiresDropOnElement: root.query('GET_DROP_ON_ELEMENT')
}
Expand Down Expand Up @@ -538,7 +548,7 @@ const togglePaste = (root) => {
root.ref.paster.onload = items => {
root.dispatch('ADD_ITEMS', {
items,
index: getDragIndex(root.ref.list, position),
index: -1,
interactionMethod: InteractionMethod.PASTE
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/isFile.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const isFile = value => value instanceof File || (value instanceof Blob && value.name);
export const isFile = value => !!(value instanceof File || (value instanceof Blob && value.name));

0 comments on commit 07c3959

Please sign in to comment.