@molecule/app-file-dropzone-react 4.0.2 → 5.0.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,13 +3,13 @@ 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-24T08:57:53.236Z
6
+ Generated: 2026-11-26T08:58:20.561Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-file-dropzone-react
10
10
 
11
11
  File dropzone — drag-drop + click-to-browse file picker with
12
- accept / max-size filtering. Pure UI: it emits the chosen `File[]`
12
+ accept / max-size filtering. Pure UI: it emits portable `PickedFile` values
13
13
  and the host app performs the actual upload.
14
14
 
15
15
  Exports `<FileDropzone>` and its `FileDropzoneProps`.
@@ -43,7 +43,7 @@ function AvatarUpload() {
43
43
  ## Installation
44
44
 
45
45
  ```bash
46
- npm install @molecule/app-file-dropzone-react @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
46
+ npm install @molecule/app-file-dropzone-react @molecule/app-filesystem @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
47
47
  npm install -D @types/react
48
48
  ```
49
49
 
@@ -57,8 +57,8 @@ Props for {@link FileDropzone}.
57
57
 
58
58
  ```typescript
59
59
  interface FileDropzoneProps {
60
- /** Called with the File[] the user selected or dropped. */
61
- onFiles: (files: File[]) => void
60
+ /** Called with the files the user selected or dropped, in selection order. */
61
+ onFiles: (files: readonly PickedFile[]) => void
62
62
  /** Accept attribute (e.g. `'image/*'` or `'.pdf,.docx'`). */
63
63
  accept?: string
64
64
  /** Allow multi-file selection. Defaults to false. */
@@ -66,7 +66,7 @@ interface FileDropzoneProps {
66
66
  /** Max file size in bytes. Files exceeding are rejected. */
67
67
  maxSize?: number
68
68
  /** Called with rejected files (wrong type or size). */
69
- onRejected?: (files: File[]) => void
69
+ onRejected?: (files: readonly PickedFile[]) => void
70
70
  /** Optional content rendered inside the dropzone (defaults to standard upload copy). */
71
71
  children?: ReactNode
72
72
  /** Disabled state. */
@@ -107,13 +107,15 @@ function FileDropzone({
107
107
 
108
108
  Peer dependencies:
109
109
 
110
+ - `@molecule/app-filesystem` ^1.1.0
110
111
  - `@molecule/app-react` ^4.13.0
111
112
  - `@molecule/app-ui` ^1.0.1
112
- - `@molecule/app-ui-react` ^4.0.0
113
+ - `@molecule/app-ui-react` ^4.12.0
113
114
  - `react` ^18.0.0 || ^19.0.0
114
115
 
115
116
  ### Runtime Dependencies
116
117
 
118
+ - `@molecule/app-filesystem`
117
119
  - `@molecule/app-react`
118
120
  - `@molecule/app-ui`
119
121
  - `@molecule/app-ui-react`
@@ -126,6 +128,8 @@ The `accept` filter is a best-effort client-side check (file
126
128
  extension or MIME prefix match) — treat it as UX sugar and always
127
129
  re-validate on the server. Files failing `accept` or `maxSize` go to
128
130
  `onRejected` (both rejection causes arrive in the same callback).
131
+ Read selected bytes with `arrayBuffer()` or append a file to a multipart
132
+ body with `file.appendTo(formData, fieldName)`.
129
133
 
130
134
  Pass `children` to replace the default "Drop files here or click to
131
135
  browse" copy; the default copy translates via
@@ -1,8 +1,9 @@
1
1
  import type { JSX, ReactNode } from 'react';
2
+ import type { PickedFile } from '@molecule/app-filesystem';
2
3
  /** Props for {@link FileDropzone}. */
3
4
  export interface FileDropzoneProps {
4
- /** Called with the File[] the user selected or dropped. */
5
- onFiles: (files: File[]) => void;
5
+ /** Called with the files the user selected or dropped, in selection order. */
6
+ onFiles: (files: readonly PickedFile[]) => void;
6
7
  /** Accept attribute (e.g. `'image/*'` or `'.pdf,.docx'`). */
7
8
  accept?: string;
8
9
  /** Allow multi-file selection. Defaults to false. */
@@ -10,7 +11,7 @@ export interface FileDropzoneProps {
10
11
  /** Max file size in bytes. Files exceeding are rejected. */
11
12
  maxSize?: number;
12
13
  /** Called with rejected files (wrong type or size). */
13
- onRejected?: (files: File[]) => void;
14
+ onRejected?: (files: readonly PickedFile[]) => void;
14
15
  /** Optional content rendered inside the dropzone (defaults to standard upload copy). */
15
16
  children?: ReactNode;
16
17
  /** Disabled state. */
@@ -1 +1 @@
1
- {"version":3,"file":"FileDropzone.d.ts","sourceRoot":"","sources":["../src/FileDropzone.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAO3C,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAA;IAChC,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAA;IACpC,wFAAwF;IACxF,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAM,EACN,QAAgB,EAChB,OAAO,EACP,UAAU,EACV,QAAQ,EAAE,YAAY,EACtB,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAoIjC"}
1
+ {"version":3,"file":"FileDropzone.d.ts","sourceRoot":"","sources":["../src/FileDropzone.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAM1D,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,KAAK,IAAI,CAAA;IAC/C,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,KAAK,IAAI,CAAA;IACnD,wFAAwF;IACxF,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAM,EACN,QAAgB,EAChB,OAAO,EACP,UAAU,EACV,QAAQ,EAAE,YAAY,EACtB,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAwDjC"}
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useRef, useState } from 'react';
2
+ import { useState } from 'react';
3
3
  import { useTranslation } from '@molecule/app-react';
4
4
  import { slot } from '@molecule/app-react/render';
5
5
  import { getClassMap } from '@molecule/app-ui';
6
+ import { FileField, Text } from '@molecule/app-ui-react/elements';
6
7
  /**
7
8
  * Drag-drop + click-to-browse file upload zone. Pure UI — apps handle
8
9
  * the actual upload.
@@ -16,75 +17,13 @@ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRej
16
17
  const cm = getClassMap();
17
18
  const { t } = useTranslation();
18
19
  const [dragging, setDragging] = useState(false);
19
- const inputRef = useRef(null);
20
- const filter = useCallback((raw) => {
21
- const arr = Array.from(raw);
22
- const kept = [];
23
- const rejected = [];
24
- for (const f of arr) {
25
- if (maxSize && f.size > maxSize) {
26
- rejected.push(f);
27
- continue;
28
- }
29
- // cheap accept check
30
- if (accept) {
31
- const okByExt = accept
32
- .split(',')
33
- .some((a) => a.trim() &&
34
- f.name.toLowerCase().endsWith(a.trim().toLowerCase().replace(/^\./, '.')));
35
- const okByMime = accept
36
- .split(',')
37
- .some((a) => a.trim() &&
38
- f.type &&
39
- (f.type === a.trim() ||
40
- (a.trim().endsWith('/*') && f.type.startsWith(a.trim().replace('/*', '/')))));
41
- if (!okByExt && !okByMime && accept !== '*') {
42
- rejected.push(f);
43
- continue;
44
- }
45
- }
46
- kept.push(f);
47
- }
48
- return { kept, rejected };
49
- }, [accept, maxSize]);
50
- /**
51
- * Filters the given file list and dispatches kept/rejected files to callbacks.
52
- * @param list
53
- */
54
- function dispatch(list) {
55
- const { kept, rejected } = filter(list);
56
- if (kept.length > 0)
57
- onFiles(multiple ? kept : [kept[0]]);
58
- if (rejected.length > 0)
59
- onRejected?.(rejected);
60
- }
61
- return (_jsxs("div", { onDragOver: (e) => {
62
- if (!disabled) {
63
- e.preventDefault();
64
- setDragging(true);
65
- }
66
- }, onDragLeave: () => setDragging(false), onDrop: (e) => {
67
- e.preventDefault();
68
- setDragging(false);
69
- if (!disabled && e.dataTransfer?.files)
70
- dispatch(e.dataTransfer.files);
71
- }, onClick: () => !disabled && inputRef.current?.click(), onKeyDown: (e) => {
72
- // role="button" gets no native keyboard activation — wire Enter/Space
73
- // to open the file dialog so keyboard users can browse (preventDefault
74
- // stops Space from scrolling the page).
75
- if (disabled)
76
- return;
77
- if (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar') {
78
- e.preventDefault();
79
- inputRef.current?.click();
80
- }
81
- }, "data-mol-id": "file-dropzone", role: "button", tabIndex: 0, "aria-disabled": disabled, className: cm.cn(cm.flex({ direction: 'col', align: 'center', justify: 'center' }), cm.sp('p', 6), cm.textCenter, !disabled ? cm.cursorPointer : undefined, className),
20
+ return (_jsx(FileField, { accept: accept, multiple: multiple, maxSize: maxSize, disabled: disabled, onValueChange: onFiles, onRejected: onRejected, webDrop: { onActiveChange: setDragging }, webInputDisplayNone: true, "data-mol-id": "file-dropzone", role: "button", tabIndex: 0, className: cm.cn(cm.flex({ direction: 'col', align: 'center', justify: 'center' }), cm.sp('p', 6), cm.textCenter, !disabled ? cm.cursorPointer : undefined, className),
82
21
  /* mol-bespoke-button: a drop SURFACE, not a CTA — a 140px dashed target
83
22
  that the user drops files onto and whose border thickens on drag-over.
84
23
  No `cm.button()` tier is a dashed drop region. The colours are theme
85
24
  tokens now; the old `rgba(0,0,0,…)` dashes were invisible on a dark
86
25
  background. */
87
- style: {
26
+ webStyle: {
88
27
  border: dragging
89
28
  ? '2px dashed var(--mol-color-primary, #3366ff)'
90
29
  : '2px dashed var(--mol-color-border, rgba(128,128,128,0.35))',
@@ -93,5 +32,5 @@ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRej
93
32
  background: dragging
94
33
  ? 'color-mix(in srgb, var(--mol-color-primary, #3366ff) 6%, transparent)'
95
34
  : undefined,
96
- }, children: [_jsx("input", { ref: inputRef, type: "file", accept: accept, multiple: multiple, disabled: disabled, onChange: (e) => e.target.files && dispatch(e.target.files), style: { display: 'none' } }), children ?? (_jsxs(_Fragment, { children: [_jsx("p", { className: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')), children: t('fileDropzone.dropHere', {}, { defaultValue: 'Drop files here or click to browse' }) }), accept && (_jsx("p", { className: cm.cn(cm.textSize('xs'), cm.sp('mt', 1)), children: t('fileDropzone.accepts', { accept }, { defaultValue: 'Accepts: {{accept}}' }) }))] }))] }));
35
+ }, children: children ?? (_jsxs(_Fragment, { children: [_jsx(Text, { as: "p", className: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')), children: t('fileDropzone.dropHere', {}, { defaultValue: 'Drop files here or click to browse' }) }), accept && (_jsx(Text, { as: "p", className: cm.cn(cm.textSize('xs'), cm.sp('mt', 1)), children: t('fileDropzone.accepts', { accept }, { defaultValue: 'Accepts: {{accept}}' }) }))] })) }));
97
36
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * File dropzone — drag-drop + click-to-browse file picker with
3
- * accept / max-size filtering. Pure UI: it emits the chosen `File[]`
3
+ * accept / max-size filtering. Pure UI: it emits portable `PickedFile` values
4
4
  * and the host app performs the actual upload.
5
5
  *
6
6
  * Exports `<FileDropzone>` and its `FileDropzoneProps`.
@@ -30,6 +30,8 @@
30
30
  * extension or MIME prefix match) — treat it as UX sugar and always
31
31
  * re-validate on the server. Files failing `accept` or `maxSize` go to
32
32
  * `onRejected` (both rejection causes arrive in the same callback).
33
+ * Read selected bytes with `arrayBuffer()` or append a file to a multipart
34
+ * body with `file.appendTo(formData, fieldName)`.
33
35
  *
34
36
  * Pass `children` to replace the default "Drop files here or click to
35
37
  * browse" copy; the default copy translates via
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,cAAc,mBAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * File dropzone — drag-drop + click-to-browse file picker with
3
- * accept / max-size filtering. Pure UI: it emits the chosen `File[]`
3
+ * accept / max-size filtering. Pure UI: it emits portable `PickedFile` values
4
4
  * and the host app performs the actual upload.
5
5
  *
6
6
  * Exports `<FileDropzone>` and its `FileDropzoneProps`.
@@ -30,6 +30,8 @@
30
30
  * extension or MIME prefix match) — treat it as UX sugar and always
31
31
  * re-validate on the server. Files failing `accept` or `maxSize` go to
32
32
  * `onRejected` (both rejection causes arrive in the same callback).
33
+ * Read selected bytes with `arrayBuffer()` or append a file to a multipart
34
+ * body with `file.appendTo(formData, fieldName)`.
33
35
  *
34
36
  * Pass `children` to replace the default "Drop files here or click to
35
37
  * browse" copy; the default copy translates via
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-file-dropzone-react",
3
- "version": "4.0.2",
3
+ "version": "5.0.0",
4
4
  "description": "Drag-drop file upload area with click-to-browse, accept/size filtering, and a content slot",
5
5
  "homepage": "https://www.molecule.dev/packages/app-file-dropzone-react",
6
6
  "type": "module",
@@ -33,15 +33,17 @@
33
33
  "directory": "packages/app/features/file-dropzone-react"
34
34
  },
35
35
  "peerDependencies": {
36
+ "@molecule/app-filesystem": "^1.1.0",
36
37
  "@molecule/app-react": "^4.13.0",
37
38
  "@molecule/app-ui": "^1.0.1",
38
- "@molecule/app-ui-react": "^4.0.0",
39
+ "@molecule/app-ui-react": "^4.12.0",
39
40
  "react": "^18.0.0 || ^19.0.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@molecule/app-react": "4.13.0",
43
- "@molecule/app-ui": "1.5.0",
44
- "@molecule/app-ui-react": "4.3.2",
43
+ "@molecule/app-filesystem": "1.1.0",
44
+ "@molecule/app-react": "4.17.0",
45
+ "@molecule/app-ui": "1.14.0",
46
+ "@molecule/app-ui-react": "4.12.1",
45
47
  "@testing-library/react": "16.3.3",
46
48
  "@types/node": "26.6.5",
47
49
  "@types/react": "19.3.0",