filepond 4.28.1 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,20 @@
1
- # <img src="https://github.com/pqina/filepond-github-assets/blob/master/logo.svg" height="44" alt="FilePond"/>
1
+ # [<img src="https://github.com/pqina/filepond-github-assets/blob/master/logo.svg" height="44" alt="FilePond"/>](https://pqina.nl/filepond/)
2
2
 
3
3
  A JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user experience.
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/pqina/filepond/blob/master/LICENSE)
6
6
  [![npm version](https://badge.fury.io/js/filepond.svg)](https://www.npmjs.com/package/filepond)
7
+ ![npm](https://img.shields.io/npm/dt/filepond)
7
8
 
8
9
  21 KB gzipped. FilePond adapters are available for **[React](https://github.com/pqina/react-filepond)**, **[Vue](https://github.com/pqina/vue-filepond)**, **[Angular](https://github.com/pqina/ngx-filepond)**, **[Svelte](https://github.com/pqina/svelte-filepond)**, and **[jQuery](https://github.com/pqina/jquery-filepond)**
9
10
 
10
- FilePond is maintained by **[Rik Schennink](https://twitter.com/rikschennink/)**
11
+ ---
12
+
13
+ [<img src="https://github.com/pqina/filepond-github-assets/blob/master/header.svg" alt="FilePond"/>](https://www.buymeacoffee.com/rikschennink/)
14
+
15
+ [Buy me a Coffee](https://www.buymeacoffee.com/rikschennink/) / [Use FilePond with Pintura](https://pqina.nl/pintura/?ref=github-filepond) / [Dev updates on Twitter](https://twitter.com/rikschennink/)
11
16
 
12
- <img src="https://github.com/pqina/filepond-github-assets/blob/master/filepond-animation-01.gif?raw=true" width="370" alt=""/>
17
+ ---
13
18
 
14
19
  ### Core Features
15
20
 
@@ -22,15 +27,17 @@ FilePond is maintained by **[Rik Schennink](https://twitter.com/rikschennink/)**
22
27
 
23
28
  [Learn more about FilePond](https://pqina.nl/filepond/)
24
29
 
30
+ [<img src="https://github.com/pqina/filepond-github-assets/blob/master/filepond-animation-01.gif?raw=true" width="370" alt=""/>](https://pqina.nl/filepond/)
31
+
25
32
  ---
26
33
 
27
34
  ### Also need Image Editing?
28
35
 
29
- **Doka.js** is what you're looking for. It's a Modern JavaScript Image Editor, Doka supports setting **crop aspect ratios**, **resizing**, **rotating**, **cropping**, and **flipping** images. Above all, it integrates beautifully with FilePond.
36
+ **Pintura the modern JavaScript Image Editor** is what you're looking for. Pintura supports setting **crop aspect ratios**, **resizing**, **rotating**, **cropping**, and **flipping** images. Above all, it integrates beautifully with FilePond.
30
37
 
31
- [Learn more about Doka](https://pqina.nl/doka/?ref=github-filepond)
38
+ [Learn more about Pintura](https://pqina.nl/pintura/?ref=github-filepond)
32
39
 
33
- <img src="https://github.com/pqina/filepond-github-assets/blob/master/filepond_doka.gif?raw=true" width="600" alt=""/>
40
+ [<img src="https://github.com/pqina/filepond-github-assets/blob/master/filepond_pintura.gif?raw=true" width="600" alt=""/>](https://pqina.nl/pintura/?ref=github-filepond)
34
41
 
35
42
  ---
36
43
 
@@ -76,7 +83,7 @@ FilePond is maintained by **[Rik Schennink](https://twitter.com/rikschennink/)**
76
83
  * [Django](https://github.com/ImperialCollegeLondon/django-drf-filepond) ([ImperialCollegeLondon/django-drf-filepond](https://github.com/ImperialCollegeLondon/django-drf-filepond))
77
84
  * [Laravel](https://github.com/Sopamo/laravel-filepond) ([Sopamo/laravel-filepond](https://github.com/Sopamo/laravel-filepond))
78
85
  * [Laravel](https://github.com/Albert221/laravel-filepond) ([Albert221/laravel-filepond](https://github.com/Albert221/laravel-filepond))
79
-
86
+ * [SilverStripe](https://github.com/lekoala/silverstripe-filepond) ([lekoala/silverstripe-filepond](https://github.com/lekoala/silverstripe-filepond))
80
87
 
81
88
  ## Quick Start
82
89
 
@@ -155,6 +162,7 @@ To build the library run `npm run build`
155
162
 
156
163
  ## Publications
157
164
 
165
+ * [Using FilePond with NodeJS](https://www.infoworld.com/article/3627248/how-to-use-filepond-with-nodejs.html)
158
166
  * [Applying Watermarks to Images with FilePond](https://pqina.nl/blog/applying-watermarks-to-images-with-filepond/)
159
167
  * [Generating Image Thumbnails in the Browser using JavaScript and FilePond](https://dev.to/pqina/generating-image-thumbnails-in-the-browser-using-javascript-and-filepond-10b8)
160
168
  * [How to upload files with Vue and FilePond](https://dev.to/pqina/how-to-upload-files-with-vue-and-filepond-1m02)
package/dist/filepond.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * FilePond 4.28.1
2
+ * FilePond 4.30.0
3
3
  * Licensed under MIT, https://opensource.org/licenses/MIT/
4
4
  * Please visit https://pqina.nl/filepond/ for details.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * FilePond 4.28.1
2
+ * FilePond 4.30.0
3
3
  * Licensed under MIT, https://opensource.org/licenses/MIT/
4
4
  * Please visit https://pqina.nl/filepond/ for details.
5
5
  */
@@ -1872,6 +1872,11 @@ const defaultOptions = {
1872
1872
  fileSizeBase: [1000, Type.INT],
1873
1873
 
1874
1874
  // Labels and status messages
1875
+ labelFileSizeBytes: ['bytes', Type.STRING],
1876
+ labelFileSizeKilobytes: ['KB', Type.STRING],
1877
+ labelFileSizeMegabytes: ['MB', Type.STRING],
1878
+ labelFileSizeGigabytes: ['GB', Type.STRING],
1879
+
1875
1880
  labelDecimalSeparator: [getDecimalSeparator(), Type.STRING], // Default is locale separator
1876
1881
  labelThousandsSeparator: [getThousandsSeparator(), Type.STRING], // Default is locale separator
1877
1882
 
@@ -2113,6 +2118,13 @@ const queries = state => ({
2113
2118
  state.options.storeAsFile && canUpdateFileInput() && !isAsync(state),
2114
2119
 
2115
2120
  IS_ASYNC: () => isAsync(state),
2121
+
2122
+ GET_FILE_SIZE_LABELS: query => ({
2123
+ labelBytes: query('GET_LABEL_FILE_SIZE_BYTES') || undefined,
2124
+ labelKilobytes: query('GET_LABEL_FILE_SIZE_KILOBYTES') || undefined,
2125
+ labelMegabytes: query('GET_LABEL_FILE_SIZE_MEGABYTES') || undefined,
2126
+ labelGigabytes: query('GET_LABEL_FILE_SIZE_GIGABYTES') || undefined,
2127
+ }),
2116
2128
  });
2117
2129
 
2118
2130
  const hasRoomForItem = state => {
@@ -3734,7 +3746,6 @@ const createItem = (origin = null, serverFileReference = null, file = null) => {
3734
3746
  state.activeProcessor = null;
3735
3747
 
3736
3748
  // if file was uploaded but processing was cancelled during perceived processor time store file reference
3737
- state.transferId = null;
3738
3749
  state.serverFileReference = serverFileReference;
3739
3750
 
3740
3751
  setStatus(ItemStatus.IDLE);
@@ -3798,18 +3809,24 @@ const createItem = (origin = null, serverFileReference = null, file = null) => {
3798
3809
  //
3799
3810
  const revert = (revertFileUpload, forceRevert) =>
3800
3811
  new Promise((resolve, reject) => {
3812
+ // a completed upload will have a serverFileReference, a failed chunked upload where
3813
+ // getting a serverId succeeded but >=0 chunks have been uploaded will have transferId set
3814
+ const serverTransferId =
3815
+ state.serverFileReference !== null ? state.serverFileReference : state.transferId;
3816
+
3801
3817
  // cannot revert without a server id for this process
3802
- if (state.serverFileReference === null) {
3818
+ if (serverTransferId === null) {
3803
3819
  resolve();
3804
3820
  return;
3805
3821
  }
3806
3822
 
3807
3823
  // revert the upload (fire and forget)
3808
3824
  revertFileUpload(
3809
- state.serverFileReference,
3825
+ serverTransferId,
3810
3826
  () => {
3811
- // reset file server id as now it's no available on the server
3827
+ // reset file server id and transfer id as now it's not available on the server
3812
3828
  state.serverFileReference = null;
3829
+ state.transferId = null;
3813
3830
  resolve();
3814
3831
  },
3815
3832
  error => {
@@ -3857,7 +3874,7 @@ const createItem = (origin = null, serverFileReference = null, file = null) => {
3857
3874
 
3858
3875
  const api = {
3859
3876
  id: { get: () => id },
3860
- origin: { get: () => origin },
3877
+ origin: { get: () => origin, set: value => (origin = value) },
3861
3878
  serverId: { get: () => state.serverFileReference },
3862
3879
  transferId: { get: () => state.transferId },
3863
3880
  status: { get: () => state.status },
@@ -4127,6 +4144,15 @@ const actions = (dispatch, query, state) => ({
4127
4144
  return;
4128
4145
  }
4129
4146
 
4147
+ // if is local item we need to enable upload button so change can be propagated to server
4148
+ if (item.origin === FileOrigin.LOCAL) {
4149
+ dispatch('DID_LOAD_ITEM', {
4150
+ id: item.id,
4151
+ error: null,
4152
+ serverFileReference: item.source,
4153
+ });
4154
+ }
4155
+
4130
4156
  // for async scenarios
4131
4157
  const upload = () => {
4132
4158
  // we push this forward a bit so the interface is updated correctly
@@ -4485,8 +4511,13 @@ const actions = (dispatch, query, state) => ({
4485
4511
  handleAdd
4486
4512
  );
4487
4513
  })
4488
- .catch(() => {
4489
- handleAdd(false);
4514
+ .catch(e => {
4515
+ if (!e || !e.error || !e.status) return handleAdd(false);
4516
+ dispatch('DID_THROW_ITEM_INVALID', {
4517
+ id,
4518
+ error: e.error,
4519
+ status: e.status,
4520
+ });
4490
4521
  });
4491
4522
  });
4492
4523
 
@@ -4756,6 +4787,16 @@ const actions = (dispatch, query, state) => ({
4756
4787
  success(createItemAPI(item));
4757
4788
  processNext();
4758
4789
 
4790
+ // if origin is local, and we're instant uploading, trigger remove of original
4791
+ // as revert will remove file from list
4792
+ const server = state.options.server;
4793
+ const instantUpload = state.options.instantUpload;
4794
+ if (instantUpload && item.origin === FileOrigin.LOCAL && isFunction(server.remove)) {
4795
+ const noop = () => {};
4796
+ item.origin = FileOrigin.LIMBO;
4797
+ state.options.server.remove(item.source, noop, noop);
4798
+ }
4799
+
4759
4800
  // All items processed? No errors?
4760
4801
  const allItemsProcessed =
4761
4802
  query('GET_ITEMS_BY_STATUS', ItemStatus.PROCESSING_COMPLETE).length ===
@@ -4836,7 +4877,8 @@ const actions = (dispatch, query, state) => ({
4836
4877
  success(createItemAPI(item));
4837
4878
  };
4838
4879
 
4839
- // if this is a local file and the server.remove function has been configured, send source there so dev can remove file from server
4880
+ // if this is a local file and the `server.remove` function has been configured,
4881
+ // send source there so dev can remove file from server
4840
4882
  const server = state.options.server;
4841
4883
  if (
4842
4884
  item.origin === FileOrigin.LOCAL &&
@@ -4862,7 +4904,14 @@ const actions = (dispatch, query, state) => ({
4862
4904
  );
4863
4905
  } else {
4864
4906
  // if is requesting revert and can revert need to call revert handler (not calling request_ because that would also trigger beforeRemoveHook)
4865
- if (options.revert && item.origin !== FileOrigin.LOCAL && item.serverId !== null) {
4907
+ if (
4908
+ (options.revert && item.origin !== FileOrigin.LOCAL && item.serverId !== null) ||
4909
+ // if chunked uploads are enabled and we're uploading in chunks for this specific file
4910
+ // or if the file isn't big enough for chunked uploads but chunkForce is set then call
4911
+ // revert before removing from the view...
4912
+ (state.options.chunkUploads && item.file.size > state.options.chunkSize) ||
4913
+ (state.options.chunkUploads && state.options.chunkForce)
4914
+ ) {
4866
4915
  item.revert(
4867
4916
  createRevertFunction(state.options.server.url, state.options.server.revert),
4868
4917
  query('GET_FORCE_REVERT')
@@ -5119,7 +5168,14 @@ const fileActionButton = createView({
5119
5168
  write: write$1,
5120
5169
  });
5121
5170
 
5122
- const toNaturalFileSize = (bytes, decimalSeparator = '.', base = 1000) => {
5171
+ const toNaturalFileSize = (bytes, decimalSeparator = '.', base = 1000, options = {}) => {
5172
+ const {
5173
+ labelBytes = 'bytes',
5174
+ labelKilobytes = 'KB',
5175
+ labelMegabytes = 'MB',
5176
+ labelGigabytes = 'GB',
5177
+ } = options;
5178
+
5123
5179
  // no negative byte sizes
5124
5180
  bytes = Math.round(Math.abs(bytes));
5125
5181
 
@@ -5129,21 +5185,21 @@ const toNaturalFileSize = (bytes, decimalSeparator = '.', base = 1000) => {
5129
5185
 
5130
5186
  // just bytes
5131
5187
  if (bytes < KB) {
5132
- return `${bytes} bytes`;
5188
+ return `${bytes} ${labelBytes}`;
5133
5189
  }
5134
5190
 
5135
5191
  // kilobytes
5136
5192
  if (bytes < MB) {
5137
- return `${Math.floor(bytes / KB)} KB`;
5193
+ return `${Math.floor(bytes / KB)} ${labelKilobytes}`;
5138
5194
  }
5139
5195
 
5140
5196
  // megabytes
5141
5197
  if (bytes < GB) {
5142
- return `${removeDecimalsWhenZero(bytes / MB, 1, decimalSeparator)} MB`;
5198
+ return `${removeDecimalsWhenZero(bytes / MB, 1, decimalSeparator)} ${labelMegabytes}`;
5143
5199
  }
5144
5200
 
5145
5201
  // gigabytes
5146
- return `${removeDecimalsWhenZero(bytes / GB, 2, decimalSeparator)} GB`;
5202
+ return `${removeDecimalsWhenZero(bytes / GB, 2, decimalSeparator)} ${labelGigabytes}`;
5147
5203
  };
5148
5204
 
5149
5205
  const removeDecimalsWhenZero = (value, decimalCount, separator) => {
@@ -5182,7 +5238,8 @@ const updateFile = ({ root, props }) => {
5182
5238
  toNaturalFileSize(
5183
5239
  root.query('GET_ITEM_SIZE', props.id),
5184
5240
  '.',
5185
- root.query('GET_FILE_SIZE_BASE')
5241
+ root.query('GET_FILE_SIZE_BASE'),
5242
+ root.query('GET_FILE_SIZE_LABELS', root.query)
5186
5243
  )
5187
5244
  );
5188
5245
  text(root.ref.fileName, formatFilename(root.query('GET_ITEM_NAME', props.id)));
@@ -5191,6 +5248,7 @@ const updateFile = ({ root, props }) => {
5191
5248
  const updateFileSizeOnError = ({ root, props }) => {
5192
5249
  // if size is available don't fallback to unknown size message
5193
5250
  if (isInt(root.query('GET_ITEM_SIZE', props.id))) {
5251
+ updateFile({ root, props });
5194
5252
  return;
5195
5253
  }
5196
5254