@molecule/app-file-dropzone-react 4.0.1 → 4.0.3

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-12T04:40:35.227Z
6
+ Generated: 2026-11-26T01:31:04.458Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-file-dropzone-react
@@ -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
 
@@ -93,7 +93,7 @@ function FileDropzone({
93
93
  multiple = false,
94
94
  maxSize,
95
95
  onRejected,
96
- children,
96
+ children: childrenProp,
97
97
  disabled,
98
98
  className,
99
99
  }: FileDropzoneProps): JSX.Element
@@ -107,13 +107,15 @@ function FileDropzone({
107
107
 
108
108
  Peer dependencies:
109
109
 
110
- - `@molecule/app-react` ^4.0.0
110
+ - `@molecule/app-filesystem` ^1.1.0
111
+ - `@molecule/app-react` ^4.13.0
111
112
  - `@molecule/app-ui` ^1.0.1
112
113
  - `@molecule/app-ui-react` ^4.0.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`
@@ -26,5 +26,5 @@ export interface FileDropzoneProps {
26
26
  * extension/MIME check) via `onRejected`.
27
27
  * @param props - Component props (see {@link FileDropzoneProps}).
28
28
  */
29
- export declare function FileDropzone({ onFiles, accept, multiple, maxSize, onRejected, children, disabled, className, }: FileDropzoneProps): JSX.Element;
29
+ export declare function FileDropzone({ onFiles, accept, multiple, maxSize, onRejected, children: childrenProp, disabled, className, }: FileDropzoneProps): JSX.Element;
30
30
  //# 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;AAM3C,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,EACR,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAmIjC"}
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;AAQ3C,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,CA2EjC"}
@@ -1,6 +1,8 @@
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 { useRef, useState } from 'react';
3
+ import { createBrowserFileInput } from '@molecule/app-filesystem';
3
4
  import { useTranslation } from '@molecule/app-react';
5
+ import { slot } from '@molecule/app-react/render';
4
6
  import { getClassMap } from '@molecule/app-ui';
5
7
  /**
6
8
  * Drag-drop + click-to-browse file upload zone. Pure UI — apps handle
@@ -10,73 +12,20 @@ import { getClassMap } from '@molecule/app-ui';
10
12
  * extension/MIME check) via `onRejected`.
11
13
  * @param props - Component props (see {@link FileDropzoneProps}).
12
14
  */
13
- export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRejected, children, disabled, className, }) {
15
+ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRejected, children: childrenProp, disabled, className, }) {
16
+ const children = slot(childrenProp);
14
17
  const cm = getClassMap();
15
18
  const { t } = useTranslation();
16
19
  const [dragging, setDragging] = useState(false);
17
20
  const inputRef = useRef(null);
18
- const filter = useCallback((raw) => {
19
- const arr = Array.from(raw);
20
- const kept = [];
21
- const rejected = [];
22
- for (const f of arr) {
23
- if (maxSize && f.size > maxSize) {
24
- rejected.push(f);
25
- continue;
26
- }
27
- // cheap accept check
28
- if (accept) {
29
- const okByExt = accept
30
- .split(',')
31
- .some((a) => a.trim() &&
32
- f.name.toLowerCase().endsWith(a.trim().toLowerCase().replace(/^\./, '.')));
33
- const okByMime = accept
34
- .split(',')
35
- .some((a) => a.trim() &&
36
- f.type &&
37
- (f.type === a.trim() ||
38
- (a.trim().endsWith('/*') && f.type.startsWith(a.trim().replace('/*', '/')))));
39
- if (!okByExt && !okByMime && accept !== '*') {
40
- rejected.push(f);
41
- continue;
42
- }
43
- }
44
- kept.push(f);
45
- }
46
- return { kept, rejected };
47
- }, [accept, maxSize]);
48
- /**
49
- * Filters the given file list and dispatches kept/rejected files to callbacks.
50
- * @param list
51
- */
52
- function dispatch(list) {
53
- const { kept, rejected } = filter(list);
54
- if (kept.length > 0)
55
- onFiles(multiple ? kept : [kept[0]]);
56
- if (rejected.length > 0)
57
- onRejected?.(rejected);
58
- }
21
+ const handlers = createBrowserFileInput(() => inputRef.current, () => ({ accept, disabled, maxSize, multiple, onFiles, onRejected }), (file) => file);
59
22
  return (_jsxs("div", { onDragOver: (e) => {
60
- if (!disabled) {
61
- e.preventDefault();
23
+ if (handlers.onDragOver(e))
62
24
  setDragging(true);
63
- }
64
25
  }, onDragLeave: () => setDragging(false), onDrop: (e) => {
65
- e.preventDefault();
66
26
  setDragging(false);
67
- if (!disabled && e.dataTransfer?.files)
68
- dispatch(e.dataTransfer.files);
69
- }, onClick: () => !disabled && inputRef.current?.click(), onKeyDown: (e) => {
70
- // role="button" gets no native keyboard activation — wire Enter/Space
71
- // to open the file dialog so keyboard users can browse (preventDefault
72
- // stops Space from scrolling the page).
73
- if (disabled)
74
- return;
75
- if (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar') {
76
- e.preventDefault();
77
- inputRef.current?.click();
78
- }
79
- }, "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),
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),
80
29
  /* mol-bespoke-button: a drop SURFACE, not a CTA — a 140px dashed target
81
30
  that the user drops files onto and whose border thickens on drag-over.
82
31
  No `cm.button()` tier is a dashed drop region. The colours are theme
@@ -91,5 +40,5 @@ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRej
91
40
  background: dragging
92
41
  ? 'color-mix(in srgb, var(--mol-color-primary, #3366ff) 6%, transparent)'
93
42
  : undefined,
94
- }, 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}}' }) }))] }))] }));
43
+ }, children: [_jsx("input", { ref: inputRef, type: "file", accept: accept, multiple: multiple, disabled: disabled, onChange: handlers.onChange, 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}}' }) }))] }))] }));
95
44
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@molecule/app-file-dropzone-react",
3
- "version": "4.0.1",
4
- "description": "Drag-drop file upload area with click fallback and preview slot",
3
+ "version": "4.0.3",
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",
7
7
  "main": "dist/index.js",
@@ -33,20 +33,22 @@
33
33
  "directory": "packages/app/features/file-dropzone-react"
34
34
  },
35
35
  "peerDependencies": {
36
- "@molecule/app-react": "^4.0.0",
36
+ "@molecule/app-filesystem": "^1.1.0",
37
+ "@molecule/app-react": "^4.13.0",
37
38
  "@molecule/app-ui": "^1.0.1",
38
39
  "@molecule/app-ui-react": "^4.0.0",
39
40
  "react": "^18.0.0 || ^19.0.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@molecule/app-react": "4.5.0",
43
- "@molecule/app-ui": "1.3.11",
44
- "@molecule/app-ui-react": "4.1.2",
43
+ "@molecule/app-filesystem": "1.1.0",
44
+ "@molecule/app-react": "4.17.0",
45
+ "@molecule/app-ui": "1.13.0",
46
+ "@molecule/app-ui-react": "4.11.0",
45
47
  "@testing-library/react": "16.3.3",
46
48
  "@types/node": "26.6.5",
47
49
  "@types/react": "19.3.0",
48
50
  "@types/react-dom": "19.3.0",
49
- "jsdom": "30.1.3",
51
+ "jsdom": "31.0.1",
50
52
  "react": "19.3.1",
51
53
  "react-dom": "19.3.1",
52
54
  "typescript": "6.0.3",