@molecule/app-file-dropzone-react 4.0.3 → 5.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 +11 -19
- package/dist/FileDropzone.d.ts +13 -4
- package/dist/FileDropzone.d.ts.map +1 -1
- package/dist/FileDropzone.js +16 -14
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/native.d.ts +6 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +6 -0
- package/package.json +12 -4
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-
|
|
6
|
+
Generated: 2026-11-27T12:43:50.682Z
|
|
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
|
|
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`.
|
|
@@ -57,8 +57,8 @@ Props for {@link FileDropzone}.
|
|
|
57
57
|
|
|
58
58
|
```typescript
|
|
59
59
|
interface FileDropzoneProps {
|
|
60
|
-
/** Called with the
|
|
61
|
-
onFiles: (files:
|
|
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:
|
|
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. */
|
|
@@ -87,16 +87,7 @@ Rejects files exceeding `maxSize` or not matching `accept` (best-effort
|
|
|
87
87
|
extension/MIME check) via `onRejected`.
|
|
88
88
|
|
|
89
89
|
```typescript
|
|
90
|
-
function FileDropzone(
|
|
91
|
-
onFiles,
|
|
92
|
-
accept,
|
|
93
|
-
multiple = false,
|
|
94
|
-
maxSize,
|
|
95
|
-
onRejected,
|
|
96
|
-
children: childrenProp,
|
|
97
|
-
disabled,
|
|
98
|
-
className,
|
|
99
|
-
}: FileDropzoneProps): JSX.Element
|
|
90
|
+
function FileDropzone(props: FileDropzoneProps): JSX.Element
|
|
100
91
|
```
|
|
101
92
|
|
|
102
93
|
- `props` — Component props (see {@link FileDropzoneProps}).
|
|
@@ -110,7 +101,7 @@ Peer dependencies:
|
|
|
110
101
|
- `@molecule/app-filesystem` ^1.1.0
|
|
111
102
|
- `@molecule/app-react` ^4.13.0
|
|
112
103
|
- `@molecule/app-ui` ^1.0.1
|
|
113
|
-
- `@molecule/app-ui-react` ^4.
|
|
104
|
+
- `@molecule/app-ui-react` ^4.13.0
|
|
114
105
|
- `react` ^18.0.0 || ^19.0.0
|
|
115
106
|
|
|
116
107
|
### Runtime Dependencies
|
|
@@ -128,10 +119,11 @@ The `accept` filter is a best-effort client-side check (file
|
|
|
128
119
|
extension or MIME prefix match) — treat it as UX sugar and always
|
|
129
120
|
re-validate on the server. Files failing `accept` or `maxSize` go to
|
|
130
121
|
`onRejected` (both rejection causes arrive in the same callback).
|
|
122
|
+
Read selected bytes with `arrayBuffer()` or append a file to a multipart
|
|
123
|
+
body with `file.appendTo(formData, fieldName)`.
|
|
131
124
|
|
|
132
|
-
Pass `children` to replace the default
|
|
133
|
-
|
|
134
|
-
`@molecule/app-locales-file-dropzone`.
|
|
125
|
+
Pass `children` to replace the default instructions. Browsers describe
|
|
126
|
+
dropping or browsing. The device entry shows the file picker action.
|
|
135
127
|
|
|
136
128
|
The zone is a keyboard-activatable `role="button"` (`tabIndex={0}`):
|
|
137
129
|
pressing Enter or Space opens the native file dialog, matching a click.
|
package/dist/FileDropzone.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
onFiles: (files:
|
|
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:
|
|
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. */
|
|
@@ -26,5 +27,13 @@ export interface FileDropzoneProps {
|
|
|
26
27
|
* extension/MIME check) via `onRejected`.
|
|
27
28
|
* @param props - Component props (see {@link FileDropzoneProps}).
|
|
28
29
|
*/
|
|
29
|
-
export declare function FileDropzone(
|
|
30
|
+
export declare function FileDropzone(props: FileDropzoneProps): JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* Shared file selection surface.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare function FileDropzoneSurface({ onFiles, accept, multiple, maxSize, onRejected, children: childrenProp, disabled, className, devicePicker, }: FileDropzoneProps & {
|
|
37
|
+
devicePicker?: boolean;
|
|
38
|
+
}): JSX.Element;
|
|
30
39
|
//# sourceMappingURL=FileDropzone.d.ts.map
|
|
@@ -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;
|
|
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,KAAK,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAElE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,MAAM,EACN,QAAgB,EAChB,OAAO,EACP,UAAU,EACV,QAAQ,EAAE,YAAY,EACtB,QAAQ,EACR,SAAS,EACT,YAAoB,GACrB,EAAE,iBAAiB,GAAG;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,GAAG,CAAC,OAAO,CA8D9D"}
|
package/dist/FileDropzone.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { createBrowserFileInput } from '@molecule/app-filesystem';
|
|
2
|
+
import { useState } from 'react';
|
|
4
3
|
import { useTranslation } from '@molecule/app-react';
|
|
5
4
|
import { slot } from '@molecule/app-react/render';
|
|
6
5
|
import { getClassMap } from '@molecule/app-ui';
|
|
6
|
+
import { FileField, Text } from '@molecule/app-ui-react/elements';
|
|
7
7
|
/**
|
|
8
8
|
* Drag-drop + click-to-browse file upload zone. Pure UI — apps handle
|
|
9
9
|
* the actual upload.
|
|
@@ -12,26 +12,26 @@ import { getClassMap } from '@molecule/app-ui';
|
|
|
12
12
|
* extension/MIME check) via `onRejected`.
|
|
13
13
|
* @param props - Component props (see {@link FileDropzoneProps}).
|
|
14
14
|
*/
|
|
15
|
-
export function FileDropzone(
|
|
15
|
+
export function FileDropzone(props) {
|
|
16
|
+
return _jsx(FileDropzoneSurface, { ...props });
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Shared file selection surface.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export function FileDropzoneSurface({ onFiles, accept, multiple = false, maxSize, onRejected, children: childrenProp, disabled, className, devicePicker = false, }) {
|
|
16
24
|
const children = slot(childrenProp);
|
|
17
25
|
const cm = getClassMap();
|
|
18
26
|
const { t } = useTranslation();
|
|
19
27
|
const [dragging, setDragging] = useState(false);
|
|
20
|
-
|
|
21
|
-
const handlers = createBrowserFileInput(() => inputRef.current, () => ({ accept, disabled, maxSize, multiple, onFiles, onRejected }), (file) => file);
|
|
22
|
-
return (_jsxs("div", { onDragOver: (e) => {
|
|
23
|
-
if (handlers.onDragOver(e))
|
|
24
|
-
setDragging(true);
|
|
25
|
-
}, onDragLeave: () => setDragging(false), onDrop: (e) => {
|
|
26
|
-
setDragging(false);
|
|
27
|
-
handlers.onDrop(e);
|
|
28
|
-
}, onClick: handlers.onClick, onKeyDown: handlers.onKeyDown, "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),
|
|
28
|
+
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),
|
|
29
29
|
/* mol-bespoke-button: a drop SURFACE, not a CTA — a 140px dashed target
|
|
30
30
|
that the user drops files onto and whose border thickens on drag-over.
|
|
31
31
|
No `cm.button()` tier is a dashed drop region. The colours are theme
|
|
32
32
|
tokens now; the old `rgba(0,0,0,…)` dashes were invisible on a dark
|
|
33
33
|
background. */
|
|
34
|
-
|
|
34
|
+
webStyle: {
|
|
35
35
|
border: dragging
|
|
36
36
|
? '2px dashed var(--mol-color-primary, #3366ff)'
|
|
37
37
|
: '2px dashed var(--mol-color-border, rgba(128,128,128,0.35))',
|
|
@@ -40,5 +40,7 @@ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRej
|
|
|
40
40
|
background: dragging
|
|
41
41
|
? 'color-mix(in srgb, var(--mol-color-primary, #3366ff) 6%, transparent)'
|
|
42
42
|
: undefined,
|
|
43
|
-
}, children:
|
|
43
|
+
}, children: children ?? (_jsxs(_Fragment, { children: [_jsx(Text, { as: "p", className: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')), children: devicePicker
|
|
44
|
+
? t('ui.fileField.browse', {}, { defaultValue: 'Browse files' })
|
|
45
|
+
: 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}}' }) }))] })) }));
|
|
44
46
|
}
|
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
|
|
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,15 +30,16 @@
|
|
|
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
|
-
* Pass `children` to replace the default
|
|
35
|
-
*
|
|
36
|
-
* `@molecule/app-locales-file-dropzone`.
|
|
36
|
+
* Pass `children` to replace the default instructions. Browsers describe
|
|
37
|
+
* dropping or browsing. The device entry shows the file picker action.
|
|
37
38
|
*
|
|
38
39
|
* The zone is a keyboard-activatable `role="button"` (`tabIndex={0}`):
|
|
39
40
|
* pressing Enter or Space opens the native file dialog, matching a click.
|
|
40
41
|
*
|
|
41
42
|
* @module
|
|
42
43
|
*/
|
|
43
|
-
export
|
|
44
|
+
export { FileDropzone, type FileDropzoneProps } from './FileDropzone.js';
|
|
44
45
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,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
|
|
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,14 +30,15 @@
|
|
|
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
|
-
* Pass `children` to replace the default
|
|
35
|
-
*
|
|
36
|
-
* `@molecule/app-locales-file-dropzone`.
|
|
36
|
+
* Pass `children` to replace the default instructions. Browsers describe
|
|
37
|
+
* dropping or browsing. The device entry shows the file picker action.
|
|
37
38
|
*
|
|
38
39
|
* The zone is a keyboard-activatable `role="button"` (`tabIndex={0}`):
|
|
39
40
|
* pressing Enter or Space opens the native file dialog, matching a click.
|
|
40
41
|
*
|
|
41
42
|
* @module
|
|
42
43
|
*/
|
|
43
|
-
export
|
|
44
|
+
export { FileDropzone } from './FileDropzone.js';
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import { type FileDropzoneProps } from './FileDropzone.js';
|
|
3
|
+
export type { FileDropzoneProps } from './FileDropzone.js';
|
|
4
|
+
/** File upload area using the device picker. */
|
|
5
|
+
export declare function FileDropzone(props: FileDropzoneProps): JSX.Element;
|
|
6
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,mBAAmB,CAAA;AAE/E,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAElE"}
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FileDropzoneSurface } from './FileDropzone.js';
|
|
3
|
+
/** File upload area using the device picker. */
|
|
4
|
+
export function FileDropzone(props) {
|
|
5
|
+
return _jsx(FileDropzoneSurface, { ...props, devicePicker: true });
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-file-dropzone-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.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",
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
+
"browser": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"react-native": {
|
|
21
|
+
"types": "./dist/native.d.ts",
|
|
22
|
+
"default": "./dist/native.js"
|
|
23
|
+
},
|
|
16
24
|
"types": "./dist/index.d.ts",
|
|
17
25
|
"import": "./dist/index.js"
|
|
18
26
|
}
|
|
@@ -36,14 +44,14 @@
|
|
|
36
44
|
"@molecule/app-filesystem": "^1.1.0",
|
|
37
45
|
"@molecule/app-react": "^4.13.0",
|
|
38
46
|
"@molecule/app-ui": "^1.0.1",
|
|
39
|
-
"@molecule/app-ui-react": "^4.
|
|
47
|
+
"@molecule/app-ui-react": "^4.13.0",
|
|
40
48
|
"react": "^18.0.0 || ^19.0.0"
|
|
41
49
|
},
|
|
42
50
|
"devDependencies": {
|
|
43
51
|
"@molecule/app-filesystem": "1.1.0",
|
|
44
52
|
"@molecule/app-react": "4.17.0",
|
|
45
|
-
"@molecule/app-ui": "1.
|
|
46
|
-
"@molecule/app-ui-react": "4.
|
|
53
|
+
"@molecule/app-ui": "1.15.0",
|
|
54
|
+
"@molecule/app-ui-react": "4.13.0",
|
|
47
55
|
"@testing-library/react": "16.3.3",
|
|
48
56
|
"@types/node": "26.6.5",
|
|
49
57
|
"@types/react": "19.3.0",
|