@molecule/app-file-dropzone-svelte 1.1.2 → 2.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 +13 -7
- package/dist/FileDropzone.svelte +11 -84
- package/dist/FileDropzone.svelte.d.ts.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -5
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-26T08:58:21.597Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-file-dropzone-svelte
|
|
10
10
|
|
|
11
11
|
Svelte 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 `readonly PickedFile[]`
|
|
13
13
|
and the host app performs the actual upload.
|
|
14
14
|
|
|
15
15
|
Exports `FileDropzone` and its `FileDropzoneProps`. It is the Svelte
|
|
@@ -31,7 +31,11 @@ DOM for the same input.
|
|
|
31
31
|
accept="image/*"
|
|
32
32
|
multiple={false}
|
|
33
33
|
maxSize={5 * 1024 * 1024}
|
|
34
|
-
onFiles={(files) =>
|
|
34
|
+
onFiles={(files) => {
|
|
35
|
+
const form = new FormData()
|
|
36
|
+
files[0]?.appendTo(form, 'avatar')
|
|
37
|
+
uploadAvatar(form)
|
|
38
|
+
}}
|
|
35
39
|
onRejected={(files) => showError(files[0].name)}
|
|
36
40
|
/>
|
|
37
41
|
```
|
|
@@ -43,7 +47,7 @@ DOM for the same input.
|
|
|
43
47
|
## Installation
|
|
44
48
|
|
|
45
49
|
```bash
|
|
46
|
-
npm install @molecule/app-file-dropzone-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
|
|
50
|
+
npm install @molecule/app-file-dropzone-svelte @molecule/app-filesystem @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
|
|
47
51
|
```
|
|
48
52
|
|
|
49
53
|
## API
|
|
@@ -56,8 +60,8 @@ Props for {@link FileDropzone}.
|
|
|
56
60
|
|
|
57
61
|
```typescript
|
|
58
62
|
interface FileDropzoneProps {
|
|
59
|
-
/** Called with the
|
|
60
|
-
onFiles: (files:
|
|
63
|
+
/** Called with the files the user selected or dropped, in selection order. */
|
|
64
|
+
onFiles: (files: readonly PickedFile[]) => void
|
|
61
65
|
/** Accept attribute (e.g. `'image/*'` or `'.pdf,.docx'`). */
|
|
62
66
|
accept?: string
|
|
63
67
|
/** Allow multi-file selection. Defaults to false. */
|
|
@@ -65,7 +69,7 @@ interface FileDropzoneProps {
|
|
|
65
69
|
/** Max file size in bytes. Files exceeding are rejected. */
|
|
66
70
|
maxSize?: number
|
|
67
71
|
/** Called with rejected files (wrong type or size). */
|
|
68
|
-
onRejected?: (files:
|
|
72
|
+
onRejected?: (files: readonly PickedFile[]) => void
|
|
69
73
|
/** Optional content rendered inside the dropzone (defaults to standard upload copy). */
|
|
70
74
|
children?: Snippet
|
|
71
75
|
/** Disabled state. */
|
|
@@ -89,6 +93,7 @@ const FileDropzone: LegacyComponentType
|
|
|
89
93
|
|
|
90
94
|
Peer dependencies:
|
|
91
95
|
|
|
96
|
+
- `@molecule/app-filesystem` ^1.1.0
|
|
92
97
|
- `@molecule/app-svelte` ^3.13.0
|
|
93
98
|
- `@molecule/app-ui` ^1.0.1
|
|
94
99
|
- `@molecule/app-ui-svelte` ^1.1.0
|
|
@@ -96,6 +101,7 @@ Peer dependencies:
|
|
|
96
101
|
|
|
97
102
|
### Runtime Dependencies
|
|
98
103
|
|
|
104
|
+
- `@molecule/app-filesystem`
|
|
99
105
|
- `@molecule/app-svelte`
|
|
100
106
|
- `@molecule/app-ui`
|
|
101
107
|
- `@molecule/app-ui-svelte`
|
package/dist/FileDropzone.svelte
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
string goes through `t()` so a locale switch re-renders it.
|
|
7
7
|
-->
|
|
8
8
|
<script lang="ts">
|
|
9
|
+
import { createBrowserFileInput, fromBrowserFile } from '@molecule/app-filesystem'
|
|
9
10
|
import { contentNodes, useTranslation } from '@molecule/app-svelte'
|
|
10
11
|
import { getClassMap } from '@molecule/app-ui'
|
|
11
12
|
|
|
@@ -27,6 +28,11 @@
|
|
|
27
28
|
|
|
28
29
|
let dragging = $state(false)
|
|
29
30
|
let inputEl = $state<HTMLInputElement | undefined>()
|
|
31
|
+
const handlers = createBrowserFileInput(
|
|
32
|
+
() => inputEl,
|
|
33
|
+
() => ({ accept, disabled, maxSize, multiple, onFiles, onRejected }),
|
|
34
|
+
fromBrowserFile,
|
|
35
|
+
)
|
|
30
36
|
|
|
31
37
|
// Every `t(…)` runs inside a `$derived`: it reads the i18n version under the
|
|
32
38
|
// hood, so this re-runs on a locale switch the way React's render-time `t`
|
|
@@ -38,67 +44,6 @@
|
|
|
38
44
|
accept ? t('fileDropzone.accepts', { accept }, { defaultValue: 'Accepts: {{accept}}' }) : '',
|
|
39
45
|
)
|
|
40
46
|
|
|
41
|
-
/**
|
|
42
|
-
* Filters a file list into kept and rejected files, exactly as React does: a
|
|
43
|
-
* file over `maxSize` is rejected, then a file matching neither the accept
|
|
44
|
-
* extension nor the accept MIME token is rejected (`'*'` accepts everything).
|
|
45
|
-
*
|
|
46
|
-
* @param raw - The files the user dropped or picked.
|
|
47
|
-
* @returns The kept and rejected files.
|
|
48
|
-
*/
|
|
49
|
-
function filter(raw: FileList | File[]): { kept: File[]; rejected: File[] } {
|
|
50
|
-
const arr = Array.from(raw)
|
|
51
|
-
const kept: File[] = []
|
|
52
|
-
const rejected: File[] = []
|
|
53
|
-
for (const f of arr) {
|
|
54
|
-
if (maxSize && f.size > maxSize) {
|
|
55
|
-
rejected.push(f)
|
|
56
|
-
continue
|
|
57
|
-
}
|
|
58
|
-
// cheap accept check
|
|
59
|
-
if (accept) {
|
|
60
|
-
const okByExt = accept
|
|
61
|
-
.split(',')
|
|
62
|
-
.some(
|
|
63
|
-
(a) =>
|
|
64
|
-
a.trim() && f.name.toLowerCase().endsWith(a.trim().toLowerCase().replace(/^\./, '.')),
|
|
65
|
-
)
|
|
66
|
-
const okByMime = accept
|
|
67
|
-
.split(',')
|
|
68
|
-
.some(
|
|
69
|
-
(a) =>
|
|
70
|
-
a.trim() &&
|
|
71
|
-
f.type &&
|
|
72
|
-
(f.type === a.trim() ||
|
|
73
|
-
(a.trim().endsWith('/*') && f.type.startsWith(a.trim().replace('/*', '/')))),
|
|
74
|
-
)
|
|
75
|
-
if (!okByExt && !okByMime && accept !== '*') {
|
|
76
|
-
rejected.push(f)
|
|
77
|
-
continue
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
kept.push(f)
|
|
81
|
-
}
|
|
82
|
-
return { kept, rejected }
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Filters the given file list and dispatches kept/rejected files to the
|
|
87
|
-
* callbacks — only the first kept file unless `multiple` is set.
|
|
88
|
-
*
|
|
89
|
-
* @param list - The files from the drop or the hidden input.
|
|
90
|
-
*/
|
|
91
|
-
function dispatch(list: FileList | File[]): void {
|
|
92
|
-
const { kept, rejected } = filter(list)
|
|
93
|
-
if (kept.length > 0) onFiles(multiple ? kept : [kept[0]!])
|
|
94
|
-
if (rejected.length > 0) onRejected?.(rejected)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Opens the native file dialog through the hidden input. */
|
|
98
|
-
function openDialog(): void {
|
|
99
|
-
inputEl?.click()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
47
|
/** The base (not dragging) drop-surface style — React's dashed drop region. */
|
|
103
48
|
const baseStyle =
|
|
104
49
|
'border: 2px dashed var(--mol-color-border, rgba(128,128,128,0.35)); border-radius: 12px; min-height: 140px'
|
|
@@ -133,32 +78,17 @@
|
|
|
133
78
|
|
|
134
79
|
<div
|
|
135
80
|
ondragover={(event) => {
|
|
136
|
-
if (
|
|
137
|
-
event.preventDefault()
|
|
138
|
-
dragging = true
|
|
139
|
-
}
|
|
81
|
+
if (handlers.onDragOver(event)) dragging = true
|
|
140
82
|
}}
|
|
141
83
|
ondragleave={() => {
|
|
142
84
|
dragging = false
|
|
143
85
|
}}
|
|
144
86
|
ondrop={(event) => {
|
|
145
|
-
event.preventDefault()
|
|
146
87
|
dragging = false
|
|
147
|
-
|
|
148
|
-
}}
|
|
149
|
-
onclick={() => {
|
|
150
|
-
if (!disabled) openDialog()
|
|
151
|
-
}}
|
|
152
|
-
onkeydown={(event) => {
|
|
153
|
-
// role="button" gets no native keyboard activation — wire Enter/Space to
|
|
154
|
-
// open the file dialog so keyboard users can browse (preventDefault stops
|
|
155
|
-
// Space from scrolling the page).
|
|
156
|
-
if (disabled) return
|
|
157
|
-
if (event.key === 'Enter' || event.key === ' ' || event.key === 'Spacebar') {
|
|
158
|
-
event.preventDefault()
|
|
159
|
-
openDialog()
|
|
160
|
-
}
|
|
88
|
+
handlers.onDrop(event)
|
|
161
89
|
}}
|
|
90
|
+
onclick={handlers.onClick}
|
|
91
|
+
onkeydown={handlers.onKeyDown}
|
|
162
92
|
data-mol-id="file-dropzone"
|
|
163
93
|
role="button"
|
|
164
94
|
tabindex="0"
|
|
@@ -179,10 +109,7 @@
|
|
|
179
109
|
{accept}
|
|
180
110
|
{multiple}
|
|
181
111
|
{disabled}
|
|
182
|
-
onchange={
|
|
183
|
-
const files = event.currentTarget.files
|
|
184
|
-
if (files) dispatch(files)
|
|
185
|
-
}}
|
|
112
|
+
onchange={handlers.onChange}
|
|
186
113
|
style="display: none"
|
|
187
114
|
/>
|
|
188
115
|
{#if children}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDropzone.svelte.d.ts","sourceRoot":"","sources":["../src/FileDropzone.svelte"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileDropzone.svelte.d.ts","sourceRoot":"","sources":["../src/FileDropzone.svelte"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAwGpD,QAAA,MAAM,YAAY,uDAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Svelte 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 `readonly PickedFile[]`
|
|
4
4
|
* and the host app performs the actual upload.
|
|
5
5
|
*
|
|
6
6
|
* Exports `FileDropzone` and its `FileDropzoneProps`. It is the Svelte
|
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
* accept="image/*"
|
|
18
18
|
* multiple={false}
|
|
19
19
|
* maxSize={5 * 1024 * 1024}
|
|
20
|
-
* onFiles={(files) =>
|
|
20
|
+
* onFiles={(files) => {
|
|
21
|
+
* const form = new FormData()
|
|
22
|
+
* files[0]?.appendTo(form, 'avatar')
|
|
23
|
+
* uploadAvatar(form)
|
|
24
|
+
* }}
|
|
21
25
|
* onRejected={(files) => showError(files[0].name)}
|
|
22
26
|
* />
|
|
23
27
|
* ```
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Svelte 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 `readonly PickedFile[]`
|
|
4
4
|
* and the host app performs the actual upload.
|
|
5
5
|
*
|
|
6
6
|
* Exports `FileDropzone` and its `FileDropzoneProps`. It is the Svelte
|
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
* accept="image/*"
|
|
18
18
|
* multiple={false}
|
|
19
19
|
* maxSize={5 * 1024 * 1024}
|
|
20
|
-
* onFiles={(files) =>
|
|
20
|
+
* onFiles={(files) => {
|
|
21
|
+
* const form = new FormData()
|
|
22
|
+
* files[0]?.appendTo(form, 'avatar')
|
|
23
|
+
* uploadAvatar(form)
|
|
24
|
+
* }}
|
|
21
25
|
* onRejected={(files) => showError(files[0].name)}
|
|
22
26
|
* />
|
|
23
27
|
* ```
|
package/dist/types.d.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
import type { Snippet } from 'svelte';
|
|
8
|
+
import type { PickedFile } from '@molecule/app-filesystem';
|
|
8
9
|
/** Props for {@link FileDropzone}. */
|
|
9
10
|
export interface FileDropzoneProps {
|
|
10
|
-
/** Called with the
|
|
11
|
-
onFiles: (files:
|
|
11
|
+
/** Called with the files the user selected or dropped, in selection order. */
|
|
12
|
+
onFiles: (files: readonly PickedFile[]) => void;
|
|
12
13
|
/** Accept attribute (e.g. `'image/*'` or `'.pdf,.docx'`). */
|
|
13
14
|
accept?: string;
|
|
14
15
|
/** Allow multi-file selection. Defaults to false. */
|
|
@@ -16,7 +17,7 @@ export interface FileDropzoneProps {
|
|
|
16
17
|
/** Max file size in bytes. Files exceeding are rejected. */
|
|
17
18
|
maxSize?: number;
|
|
18
19
|
/** Called with rejected files (wrong type or size). */
|
|
19
|
-
onRejected?: (files:
|
|
20
|
+
onRejected?: (files: readonly PickedFile[]) => void;
|
|
20
21
|
/** Optional content rendered inside the dropzone (defaults to standard upload copy). */
|
|
21
22
|
children?: Snippet;
|
|
22
23
|
/** Disabled state. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,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,OAAO,CAAA;IAClB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-file-dropzone-svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.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-svelte",
|
|
6
6
|
"type": "module",
|
|
@@ -48,18 +48,20 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
+
"@molecule/app-filesystem": "^1.1.0",
|
|
51
52
|
"@molecule/app-svelte": "^3.13.0",
|
|
52
53
|
"@molecule/app-ui": "^1.0.1",
|
|
53
54
|
"@molecule/app-ui-svelte": "^1.1.0",
|
|
54
55
|
"svelte": "^5.0.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
58
|
+
"@molecule/app-filesystem": "1.1.0",
|
|
57
59
|
"@molecule/app-framework-conformance": "0.0.0",
|
|
58
|
-
"@molecule/app-i18n": "1.
|
|
60
|
+
"@molecule/app-i18n": "1.3.0",
|
|
59
61
|
"@molecule/app-icons": "1.0.4",
|
|
60
|
-
"@molecule/app-svelte": "3.
|
|
61
|
-
"@molecule/app-ui": "1.
|
|
62
|
-
"@molecule/app-ui-svelte": "1.
|
|
62
|
+
"@molecule/app-svelte": "3.16.0",
|
|
63
|
+
"@molecule/app-ui": "1.14.0",
|
|
64
|
+
"@molecule/app-ui-svelte": "1.10.0",
|
|
63
65
|
"@sveltejs/package": "3.0.2",
|
|
64
66
|
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
65
67
|
"@types/node": "26.6.5",
|