Skip to content

Commit 15ba2be

Browse files
committed
fix issue with rendering 0 items per row
1 parent 14e41f6 commit 15ba2be

File tree

10 files changed

+97
-32
lines changed

10 files changed

+97
-32
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 4.26.0
4+
5+
- Fix problem with rendering 0 items per row. #676
6+
- The `headers` property of the `server.process` end point can now be a function.
7+
38
## 4.25.3
49

510
- Fix issue with `chunkRetryDelays`. #671

dist/filepond.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* FilePond 4.25.3
2+
* FilePond 4.26.0
33
* Licensed under MIT, https://opensource.org/licenses/MIT/
44
* Please visit https://pqina.nl/filepond/ for details.
55
*/

dist/filepond.esm.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* FilePond 4.25.3
2+
* FilePond 4.26.0
33
* Licensed under MIT, https://opensource.org/licenses/MIT/
44
* Please visit https://pqina.nl/filepond/ for details.
55
*/
@@ -3062,6 +3062,18 @@ const createFileProcessorFunction = (apiUrl, action, name, options) => (
30623062
const onload = action.onload || (res => res);
30633063
const onerror = action.onerror || (res => null);
30643064

3065+
const headers =
3066+
typeof action.headers === 'function'
3067+
? action.headers(file, metadata) || {}
3068+
: {
3069+
...action.headers,
3070+
};
3071+
3072+
const requestParams = {
3073+
...action,
3074+
headers,
3075+
};
3076+
30653077
// create formdata object
30663078
var formData = new FormData();
30673079

@@ -3080,7 +3092,7 @@ const createFileProcessorFunction = (apiUrl, action, name, options) => (
30803092
});
30813093

30823094
// send request object
3083-
const request = sendRequest(ondata(formData), buildURL(apiUrl, action.url), action);
3095+
const request = sendRequest(ondata(formData), buildURL(apiUrl, action.url), requestParams);
30843096
request.onload = xhr => {
30853097
load(createResponse('load', xhr.status, onload(xhr.response), xhr.getAllResponseHeaders()));
30863098
};
@@ -6049,7 +6061,7 @@ const item = createView({
60496061
var getItemsPerRow = (horizontalSpace, itemWidth) => {
60506062
// add one pixel leeway, when using percentages for item width total items can be 1.99 per row
60516063

6052-
return Math.floor((horizontalSpace + 1) / itemWidth);
6064+
return Math.max(1, Math.floor((horizontalSpace + 1) / itemWidth));
60536065
};
60546066

60556067
const getItemIndexByPosition = (view, children, positionInView) => {

dist/filepond.esm.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/filepond.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* FilePond 4.25.3
2+
* FilePond 4.26.0
33
* Licensed under MIT, https://opensource.org/licenses/MIT/
44
* Please visit https://pqina.nl/filepond/ for details.
55
*/
@@ -5177,6 +5177,19 @@
51775177
return null;
51785178
};
51795179

5180+
var headers =
5181+
typeof action.headers === 'function'
5182+
? action.headers(file, metadata) || {}
5183+
: Object.assign(
5184+
{},
5185+
5186+
action.headers
5187+
);
5188+
5189+
var requestParams = Object.assign({}, action, {
5190+
headers: headers,
5191+
});
5192+
51805193
// create formdata object
51815194
var formData = new FormData();
51825195

@@ -5195,7 +5208,11 @@
51955208
});
51965209

51975210
// send request object
5198-
var request = sendRequest(ondata(formData), buildURL(apiUrl, action.url), action);
5211+
var request = sendRequest(
5212+
ondata(formData),
5213+
buildURL(apiUrl, action.url),
5214+
requestParams
5215+
);
51995216
request.onload = function(xhr) {
52005217
load(
52015218
createResponse(
@@ -8599,7 +8616,7 @@
85998616
var getItemsPerRow = function(horizontalSpace, itemWidth) {
86008617
// add one pixel leeway, when using percentages for item width total items can be 1.99 per row
86018618

8602-
return Math.floor((horizontalSpace + 1) / itemWidth);
8619+
return Math.max(1, Math.floor((horizontalSpace + 1) / itemWidth));
86038620
};
86048621

86058622
var getItemIndexByPosition = function getItemIndexByPosition(view, children, positionInView) {

dist/filepond.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/filepond.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "filepond",
3-
"version": "4.25.3",
3+
"version": "4.26.0",
44
"description": "FilePond, Where files go to stretch their bits.",
55
"license": "MIT",
66
"author": {

src/js/app/utils/createFileProcessorFunction.js

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,78 @@ function signature:
1414
}
1515
}
1616
*/
17-
export const createFileProcessorFunction = (apiUrl, action, name, options) => (file, metadata, load, error, progress, abort, transfer) => {
18-
17+
export const createFileProcessorFunction = (apiUrl, action, name, options) => (
18+
file,
19+
metadata,
20+
load,
21+
error,
22+
progress,
23+
abort,
24+
transfer
25+
) => {
1926
// no file received
2027
if (!file) return;
2128

2229
// if was passed a file, and we can chunk it, exit here
2330
const canChunkUpload = options.chunkUploads;
2431
const shouldChunkUpload = canChunkUpload && file.size > options.chunkSize;
2532
const willChunkUpload = canChunkUpload && (shouldChunkUpload || options.chunkForce);
26-
if (file instanceof Blob && willChunkUpload) return processFileChunked(apiUrl, action, name, file, metadata, load, error, progress, abort, transfer, options);
27-
33+
if (file instanceof Blob && willChunkUpload)
34+
return processFileChunked(
35+
apiUrl,
36+
action,
37+
name,
38+
file,
39+
metadata,
40+
load,
41+
error,
42+
progress,
43+
abort,
44+
transfer,
45+
options
46+
);
47+
2848
// set handlers
2949
const ondata = action.ondata || (fd => fd);
3050
const onload = action.onload || (res => res);
3151
const onerror = action.onerror || (res => null);
3252

53+
const headers =
54+
typeof action.headers === 'function'
55+
? action.headers(file, metadata) || {}
56+
: {
57+
...action.headers,
58+
};
59+
60+
const requestParams = {
61+
...action,
62+
headers,
63+
};
64+
3365
// create formdata object
3466
var formData = new FormData();
3567

3668
// add metadata under same name
37-
if (isObject(metadata)) { formData.append(name, JSON.stringify(metadata)); }
69+
if (isObject(metadata)) {
70+
formData.append(name, JSON.stringify(metadata));
71+
}
3872

3973
// Turn into an array of objects so no matter what the input, we can handle it the same way
4074
(file instanceof Blob ? [{ name: null, file }] : file).forEach(item => {
41-
formData.append(name, item.file, item.name === null ? item.file.name : `${item.name}${item.file.name}`);
75+
formData.append(
76+
name,
77+
item.file,
78+
item.name === null ? item.file.name : `${item.name}${item.file.name}`
79+
);
4280
});
4381

4482
// send request object
45-
const request = sendRequest(ondata(formData), buildURL(apiUrl, action.url), action);
46-
request.onload = (xhr) => {
47-
load(
48-
createResponse(
49-
'load',
50-
xhr.status,
51-
onload(xhr.response),
52-
xhr.getAllResponseHeaders()
53-
)
54-
);
83+
const request = sendRequest(ondata(formData), buildURL(apiUrl, action.url), requestParams);
84+
request.onload = xhr => {
85+
load(createResponse('load', xhr.status, onload(xhr.response), xhr.getAllResponseHeaders()));
5586
};
5687

57-
request.onerror = (xhr) => {
88+
request.onerror = xhr => {
5889
error(
5990
createResponse(
6091
'error',
@@ -71,4 +102,4 @@ export const createFileProcessorFunction = (apiUrl, action, name, options) => (f
71102

72103
// should return request
73104
return request;
74-
};
105+
};

src/js/app/utils/getItemsPerRow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default (horizontalSpace, itemWidth) => {
22
// add one pixel leeway, when using percentages for item width total items can be 1.99 per row
33

4-
return Math.floor((horizontalSpace + 1) / itemWidth);
4+
return Math.max(1, Math.floor((horizontalSpace + 1) / itemWidth));
55
};

0 commit comments

Comments
 (0)