@molecule/app-file-dropzone-svelte 1.1.2 → 1.1.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.913Z
6
+ Generated: 2026-11-26T01:31:05.016Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-file-dropzone-svelte
@@ -43,7 +43,7 @@ DOM for the same input.
43
43
  ## Installation
44
44
 
45
45
  ```bash
46
- npm install @molecule/app-file-dropzone-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
46
+ npm install @molecule/app-file-dropzone-svelte @molecule/app-filesystem @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
47
47
  ```
48
48
 
49
49
  ## API
@@ -89,6 +89,7 @@ const FileDropzone: LegacyComponentType
89
89
 
90
90
  Peer dependencies:
91
91
 
92
+ - `@molecule/app-filesystem` ^1.1.0
92
93
  - `@molecule/app-svelte` ^3.13.0
93
94
  - `@molecule/app-ui` ^1.0.1
94
95
  - `@molecule/app-ui-svelte` ^1.1.0
@@ -96,6 +97,7 @@ Peer dependencies:
96
97
 
97
98
  ### Runtime Dependencies
98
99
 
100
+ - `@molecule/app-filesystem`
99
101
  - `@molecule/app-svelte`
100
102
  - `@molecule/app-ui`
101
103
  - `@molecule/app-ui-svelte`
@@ -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 } 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
+ (file) => file,
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 (!disabled) {
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
- if (!disabled && event.dataTransfer?.files) dispatch(event.dataTransfer.files)
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={(event) => {
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":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAiLpD,QAAA,MAAM,YAAY,uDAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-file-dropzone-svelte",
3
- "version": "1.1.2",
3
+ "version": "1.1.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-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.2.2",
60
+ "@molecule/app-i18n": "1.3.0",
59
61
  "@molecule/app-icons": "1.0.4",
60
- "@molecule/app-svelte": "3.14.1",
61
- "@molecule/app-ui": "1.5.0",
62
- "@molecule/app-ui-svelte": "1.4.2",
62
+ "@molecule/app-svelte": "3.16.0",
63
+ "@molecule/app-ui": "1.13.0",
64
+ "@molecule/app-ui-svelte": "1.9.0",
63
65
  "@sveltejs/package": "3.0.2",
64
66
  "@sveltejs/vite-plugin-svelte": "7.1.2",
65
67
  "@types/node": "26.6.5",