@molecule/app-file-upload-filepond 1.0.4 → 1.1.1
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 +5 -3
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +41 -15
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-26T01:31:05.584Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-file-upload-filepond
|
|
@@ -34,7 +34,7 @@ setProvider(provider)
|
|
|
34
34
|
## Installation
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
npm install @molecule/app-file-upload-filepond @molecule/app-file-upload @molecule/app-i18n
|
|
37
|
+
npm install @molecule/app-file-upload-filepond @molecule/app-file-upload @molecule/app-filesystem @molecule/app-i18n
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## API
|
|
@@ -102,12 +102,14 @@ export function setupFileUploadFilepond(): void {
|
|
|
102
102
|
|
|
103
103
|
Peer dependencies:
|
|
104
104
|
|
|
105
|
-
- `@molecule/app-file-upload` >=1.0
|
|
105
|
+
- `@molecule/app-file-upload` >=1.1.0
|
|
106
|
+
- `@molecule/app-filesystem` ^1.1.0
|
|
106
107
|
- `@molecule/app-i18n` >=1.0.1
|
|
107
108
|
|
|
108
109
|
### Runtime Dependencies
|
|
109
110
|
|
|
110
111
|
- `@molecule/app-file-upload`
|
|
112
|
+
- `@molecule/app-filesystem`
|
|
111
113
|
- `@molecule/app-i18n`
|
|
112
114
|
|
|
113
115
|
Transport is ONE multipart/form-data request per file to
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAGV,kBAAkB,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAGV,kBAAkB,EAKnB,MAAM,2BAA2B,CAAA;AAIlC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AA0rBhD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,GAAE,cAAmB,GAAG,kBAAkB,CAMtF;AAED,sDAAsD;AACtD,eAAO,MAAM,QAAQ,EAAE,kBAA6C,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
+
import { fromBrowserFile } from '@molecule/app-filesystem';
|
|
10
11
|
import { t } from '@molecule/app-i18n';
|
|
11
12
|
// ---------------------------------------------------------------------------
|
|
12
13
|
// ID generation
|
|
@@ -75,7 +76,7 @@ function validateFile(file, validation, currentFileCount) {
|
|
|
75
76
|
* Uploads a single file using XMLHttpRequest (browser) with progress events,
|
|
76
77
|
* falling back to fetch when XMLHttpRequest is unavailable (Node/SSR).
|
|
77
78
|
*
|
|
78
|
-
* @param source - The
|
|
79
|
+
* @param source - The file selection to upload.
|
|
79
80
|
* @param destination - Upload destination configuration.
|
|
80
81
|
* @param onProgress - Progress callback receiving loaded and total bytes.
|
|
81
82
|
* @param timeout - Request timeout in milliseconds.
|
|
@@ -85,7 +86,15 @@ function uploadTransport(source, destination, onProgress, timeout) {
|
|
|
85
86
|
const method = destination.method ?? 'POST';
|
|
86
87
|
const fieldName = destination.fieldName ?? 'file';
|
|
87
88
|
const formData = new FormData();
|
|
88
|
-
|
|
89
|
+
try {
|
|
90
|
+
source.appendTo(formData, fieldName);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
promise: Promise.reject(error instanceof Error ? error : new Error(String(error))),
|
|
95
|
+
abort: () => undefined,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
89
98
|
if (destination.additionalData) {
|
|
90
99
|
for (const [key, value] of Object.entries(destination.additionalData)) {
|
|
91
100
|
formData.append(key, value);
|
|
@@ -213,25 +222,37 @@ function uploadWithFetch(url, method, body, headers, timeout) {
|
|
|
213
222
|
/**
|
|
214
223
|
* Generates a data URL preview for an image file.
|
|
215
224
|
*
|
|
216
|
-
* @param
|
|
225
|
+
* @param source - The original file selection.
|
|
217
226
|
* @param maxSize - Maximum width/height in pixels.
|
|
218
227
|
* @returns A promise resolving to the data URL string, or undefined.
|
|
219
228
|
*/
|
|
220
|
-
async function generatePreview(
|
|
221
|
-
if (!file.type.startsWith('image/'))
|
|
222
|
-
return undefined;
|
|
229
|
+
async function generatePreview(source, maxSize) {
|
|
223
230
|
if (typeof FileReader === 'undefined')
|
|
224
231
|
return undefined;
|
|
232
|
+
const formData = new FormData();
|
|
233
|
+
if (typeof formData.get !== 'function')
|
|
234
|
+
return undefined;
|
|
235
|
+
source.appendTo(formData, 'file');
|
|
236
|
+
const file = formData.get('file');
|
|
237
|
+
if (file === null || typeof file === 'string')
|
|
238
|
+
return undefined;
|
|
225
239
|
return new Promise((resolve) => {
|
|
226
240
|
const reader = new FileReader();
|
|
227
241
|
reader.onload = () => {
|
|
228
242
|
const dataUrl = reader.result;
|
|
229
|
-
|
|
230
|
-
|
|
243
|
+
if (typeof dataUrl !== 'string') {
|
|
244
|
+
resolve(undefined);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// Return the original preview where canvas resizing is unavailable.
|
|
248
|
+
if (typeof document === 'undefined' ||
|
|
249
|
+
typeof HTMLCanvasElement === 'undefined' ||
|
|
250
|
+
typeof Image !== 'function') {
|
|
231
251
|
resolve(dataUrl);
|
|
232
252
|
return;
|
|
233
253
|
}
|
|
234
254
|
// Resize using canvas in browser environments
|
|
255
|
+
const browserDocument = document;
|
|
235
256
|
const img = new Image();
|
|
236
257
|
img.onload = () => {
|
|
237
258
|
let { width, height } = img;
|
|
@@ -240,7 +261,7 @@ async function generatePreview(file, maxSize) {
|
|
|
240
261
|
width = Math.round(width * ratio);
|
|
241
262
|
height = Math.round(height * ratio);
|
|
242
263
|
}
|
|
243
|
-
const canvas =
|
|
264
|
+
const canvas = browserDocument.createElement('canvas');
|
|
244
265
|
canvas.width = width;
|
|
245
266
|
canvas.height = height;
|
|
246
267
|
const ctx = canvas.getContext('2d');
|
|
@@ -293,7 +314,8 @@ function createUploaderInstance(options, config = {}) {
|
|
|
293
314
|
* @param file - The UploadFile record to upload.
|
|
294
315
|
*/
|
|
295
316
|
function startUpload(file) {
|
|
296
|
-
|
|
317
|
+
const source = file.pickedFile ?? (file.source && fromBrowserFile(file.source));
|
|
318
|
+
if (!source) {
|
|
297
319
|
const noSourceMsg = t('fileUpload.error.noSource', undefined, {
|
|
298
320
|
defaultValue: 'No source file available',
|
|
299
321
|
});
|
|
@@ -303,7 +325,7 @@ function createUploaderInstance(options, config = {}) {
|
|
|
303
325
|
return;
|
|
304
326
|
}
|
|
305
327
|
Object.assign(file, { status: 'uploading', progress: 0 });
|
|
306
|
-
const handle = uploadTransport(
|
|
328
|
+
const handle = uploadTransport(source, options.destination, (loaded, total) => {
|
|
307
329
|
const progress = Math.round((loaded / total) * 100);
|
|
308
330
|
file.progress = progress;
|
|
309
331
|
events.onProgress?.(file, progress);
|
|
@@ -369,7 +391,7 @@ function createUploaderInstance(options, config = {}) {
|
|
|
369
391
|
type: source.type,
|
|
370
392
|
status: 'idle',
|
|
371
393
|
progress: 0,
|
|
372
|
-
source,
|
|
394
|
+
...('appendTo' in source ? { pickedFile: source } : { source }),
|
|
373
395
|
};
|
|
374
396
|
const errors = validateFile(uploadFile, options.validation, files.length);
|
|
375
397
|
if (errors.length > 0) {
|
|
@@ -381,10 +403,14 @@ function createUploaderInstance(options, config = {}) {
|
|
|
381
403
|
// Generate preview asynchronously if enabled
|
|
382
404
|
if (options.imagePreview && source.type.startsWith('image/')) {
|
|
383
405
|
const maxSize = options.imagePreviewMaxSize ?? 200;
|
|
384
|
-
|
|
385
|
-
|
|
406
|
+
const selection = 'appendTo' in source ? source : fromBrowserFile(source);
|
|
407
|
+
void generatePreview(selection, maxSize)
|
|
408
|
+
.then((preview) => {
|
|
409
|
+
if (preview)
|
|
386
410
|
uploadFile.preview = preview;
|
|
387
|
-
|
|
411
|
+
})
|
|
412
|
+
.catch((_error) => {
|
|
413
|
+
// A preview is optional. The upload still reports any source error through onError.
|
|
388
414
|
});
|
|
389
415
|
}
|
|
390
416
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-file-upload-filepond",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "FilePond-style file upload provider for @molecule/app-file-upload",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/app-file-upload-filepond",
|
|
6
6
|
"type": "module",
|
|
@@ -34,12 +34,14 @@
|
|
|
34
34
|
"directory": "packages/app/bonds/file-upload/filepond"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@molecule/app-file-upload": ">=1.0
|
|
37
|
+
"@molecule/app-file-upload": ">=1.1.0",
|
|
38
|
+
"@molecule/app-filesystem": "^1.1.0",
|
|
38
39
|
"@molecule/app-i18n": ">=1.0.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@molecule/app-file-upload": "1.0
|
|
42
|
-
"@molecule/app-
|
|
42
|
+
"@molecule/app-file-upload": "1.1.0",
|
|
43
|
+
"@molecule/app-filesystem": "1.1.1",
|
|
44
|
+
"@molecule/app-i18n": "1.4.0",
|
|
43
45
|
"@types/node": "26.6.5",
|
|
44
46
|
"typescript": "6.0.3",
|
|
45
47
|
"vitest": "4.1.12"
|