@molecule/app-file-dropzone-react 4.0.2 → 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-24T08:57:53.236Z
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
 
@@ -107,6 +107,7 @@ 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
113
  - `@molecule/app-ui-react` ^4.0.0
@@ -114,6 +115,7 @@ Peer dependencies:
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`
@@ -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,EA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B;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,5 +1,6 @@
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';
4
5
  import { slot } from '@molecule/app-react/render';
5
6
  import { getClassMap } from '@molecule/app-ui';
@@ -17,68 +18,14 @@ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRej
17
18
  const { t } = useTranslation();
18
19
  const [dragging, setDragging] = useState(false);
19
20
  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
- }
21
+ const handlers = createBrowserFileInput(() => inputRef.current, () => ({ accept, disabled, maxSize, multiple, onFiles, onRejected }), (file) => file);
61
22
  return (_jsxs("div", { onDragOver: (e) => {
62
- if (!disabled) {
63
- e.preventDefault();
23
+ if (handlers.onDragOver(e))
64
24
  setDragging(true);
65
- }
66
25
  }, onDragLeave: () => setDragging(false), onDrop: (e) => {
67
- e.preventDefault();
68
26
  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),
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),
82
29
  /* mol-bespoke-button: a drop SURFACE, not a CTA — a 140px dashed target
83
30
  that the user drops files onto and whose border thickens on drag-over.
84
31
  No `cm.button()` tier is a dashed drop region. The colours are theme
@@ -93,5 +40,5 @@ export function FileDropzone({ onFiles, accept, multiple = false, maxSize, onRej
93
40
  background: dragging
94
41
  ? 'color-mix(in srgb, var(--mol-color-primary, #3366ff) 6%, transparent)'
95
42
  : 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}}' }) }))] }))] }));
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}}' }) }))] }))] }));
97
44
  }
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": "4.0.3",
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
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.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.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",