@molecule/app-file-upload-filepond 1.0.4 → 1.1.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
@@ -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-13T07:05:44.397Z
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.1
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
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAGV,kBAAkB,EAInB,MAAM,2BAA2B,CAAA;AAGlC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAkqBhD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,GAAE,cAAmB,GAAG,kBAAkB,CAMtF;AAED,sDAAsD;AACtD,eAAO,MAAM,QAAQ,EAAE,kBAA6C,CAAA"}
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;AAsrBhD;;;;;;;;;;;;;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 File object to upload.
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
- formData.append(fieldName, source);
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,19 +222,26 @@ function uploadWithFetch(url, method, body, headers, timeout) {
213
222
  /**
214
223
  * Generates a data URL preview for an image file.
215
224
  *
216
- * @param file - The File object.
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(file, maxSize) {
221
- if (!file.type.startsWith('image/'))
229
+ async function generatePreview(source, maxSize) {
230
+ if (typeof FileReader === 'undefined' || typeof FormData.prototype.get !== 'function')
222
231
  return undefined;
223
- if (typeof FileReader === 'undefined')
232
+ const formData = new FormData();
233
+ source.appendTo(formData, 'file');
234
+ const file = formData.get('file');
235
+ if (file === null || typeof file === 'string')
224
236
  return undefined;
225
237
  return new Promise((resolve) => {
226
238
  const reader = new FileReader();
227
239
  reader.onload = () => {
228
240
  const dataUrl = reader.result;
241
+ if (typeof dataUrl !== 'string') {
242
+ resolve(undefined);
243
+ return;
244
+ }
229
245
  // If no canvas available (Node), return the raw data URL
230
246
  if (typeof document === 'undefined' || typeof HTMLCanvasElement === 'undefined') {
231
247
  resolve(dataUrl);
@@ -293,7 +309,8 @@ function createUploaderInstance(options, config = {}) {
293
309
  * @param file - The UploadFile record to upload.
294
310
  */
295
311
  function startUpload(file) {
296
- if (!file.source) {
312
+ const source = file.pickedFile ?? (file.source && fromBrowserFile(file.source));
313
+ if (!source) {
297
314
  const noSourceMsg = t('fileUpload.error.noSource', undefined, {
298
315
  defaultValue: 'No source file available',
299
316
  });
@@ -303,7 +320,7 @@ function createUploaderInstance(options, config = {}) {
303
320
  return;
304
321
  }
305
322
  Object.assign(file, { status: 'uploading', progress: 0 });
306
- const handle = uploadTransport(file.source, options.destination, (loaded, total) => {
323
+ const handle = uploadTransport(source, options.destination, (loaded, total) => {
307
324
  const progress = Math.round((loaded / total) * 100);
308
325
  file.progress = progress;
309
326
  events.onProgress?.(file, progress);
@@ -369,7 +386,7 @@ function createUploaderInstance(options, config = {}) {
369
386
  type: source.type,
370
387
  status: 'idle',
371
388
  progress: 0,
372
- source,
389
+ ...('appendTo' in source ? { pickedFile: source } : { source }),
373
390
  };
374
391
  const errors = validateFile(uploadFile, options.validation, files.length);
375
392
  if (errors.length > 0) {
@@ -381,10 +398,14 @@ function createUploaderInstance(options, config = {}) {
381
398
  // Generate preview asynchronously if enabled
382
399
  if (options.imagePreview && source.type.startsWith('image/')) {
383
400
  const maxSize = options.imagePreviewMaxSize ?? 200;
384
- void generatePreview(source, maxSize).then((preview) => {
385
- if (preview) {
401
+ const selection = 'appendTo' in source ? source : fromBrowserFile(source);
402
+ void generatePreview(selection, maxSize)
403
+ .then((preview) => {
404
+ if (preview)
386
405
  uploadFile.preview = preview;
387
- }
406
+ })
407
+ .catch((_error) => {
408
+ // A preview is optional. The upload still reports any source error through onError.
388
409
  });
389
410
  }
390
411
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-file-upload-filepond",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
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.1",
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.3",
42
- "@molecule/app-i18n": "1.1.2",
42
+ "@molecule/app-file-upload": "1.1.0",
43
+ "@molecule/app-filesystem": "1.1.0",
44
+ "@molecule/app-i18n": "1.3.0",
43
45
  "@types/node": "26.6.5",
44
46
  "typescript": "6.0.3",
45
47
  "vitest": "4.1.12"