handy-uploader 2.0.2 → 3.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -297
  3. package/dist/components/InsertButton.vue.d.ts +5 -13
  4. package/dist/components/SelectFileIconType.vue.d.ts +3 -23
  5. package/dist/components/SimpleUploader.vue.d.ts +7 -35
  6. package/dist/components/TableUploader.vue.d.ts +6 -38
  7. package/dist/components/ThumbnailUploader.vue.d.ts +8 -44
  8. package/dist/components/handyUploader.vue.d.ts +21 -79
  9. package/dist/composables/deprecation.d.ts +2 -0
  10. package/dist/composables/useErrorHandler.d.ts +8 -4
  11. package/dist/composables/useFileUpload.d.ts +7 -2
  12. package/dist/core/attachments.d.ts +91 -0
  13. package/dist/core/fileUtils.d.ts +56 -0
  14. package/dist/core/index.d.ts +3 -0
  15. package/dist/core/videoThumbnail.d.ts +32 -0
  16. package/dist/handy-uploader.cjs +1 -0
  17. package/dist/handy-uploader.css +1 -0
  18. package/dist/handy-uploader.mjs +1110 -0
  19. package/dist/language-CYpPw-mk.mjs +551 -0
  20. package/dist/language-fvWXvWRx.js +1 -0
  21. package/dist/lib/index.d.ts +10 -712
  22. package/dist/lib/language.d.ts +3 -0
  23. package/dist/lib/shared.d.ts +5 -0
  24. package/dist/lib/vuetify.d.ts +15 -0
  25. package/dist/logo.png +0 -0
  26. package/dist/types/index.d.ts +4 -0
  27. package/dist/utils/fileUtils.d.ts +1 -41
  28. package/dist/vue/components/HandyDialog.vue.d.ts +31 -0
  29. package/dist/vue/components/HandyDropzone.vue.d.ts +38 -0
  30. package/dist/vue/components/HandyFileIcon.vue.d.ts +9 -0
  31. package/dist/vue/components/HandyFileList.vue.d.ts +65 -0
  32. package/dist/vue/components/HandyIcon.vue.d.ts +10 -0
  33. package/dist/vue/components/HandyUploader.vue.d.ts +137 -0
  34. package/dist/vue/index.d.ts +9 -0
  35. package/dist/vue/types.d.ts +5 -0
  36. package/dist/vue/useUploader.d.ts +46 -0
  37. package/dist/vuetify.cjs +1 -0
  38. package/dist/vuetify.mjs +1870 -0
  39. package/package.json +66 -26
  40. package/dist/handy-uploader.es.js +0 -2407
  41. package/dist/handy-uploader.umd.js +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Ali Jahanpak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,36 +5,27 @@
5
5
  [![Vue 3](https://img.shields.io/badge/Vue-3.x-4FC08D.svg)](https://vuejs.org/)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
7
7
 
8
- ## 🚀 [Live Demo](https://friendly-varahamihira-45c09f.netlify.app)
8
+ ## 🚀 [Live Demo](https://illustrious-griffin-257b43.netlify.app)
9
9
 
10
- A comprehensive Vue 3 file uploader component library with advanced features including **automatic video thumbnail generation**, multiple upload styles, and extensive file type support.
10
+ A Vue 3 file uploader with **automatic video thumbnails**, **image compression**, three layouts (thumbnail, simple, table), per-file names, descriptions and tags, and translations for 5 languages.
11
11
 
12
- ## ✨ Key Features
12
+ It comes in two flavours with **the same props and events**:
13
13
 
14
- ### 🎥 **Video Thumbnail Generation**
15
- - **Automatic thumbnail extraction** from video files using Canvas API
16
- - Support for **MP4, AVI, MOV, WMV, FLV, WebM** formats
17
- - Real-time thumbnail display with play button overlay
18
- - No external dependencies required
14
+ | Import | Needs | Styling |
15
+ | --- | --- | --- |
16
+ | `handy-uploader` | Vue 3 only | Plain CSS, works with any CSS framework (Tailwind, Bootstrap, your own) |
17
+ | `handy-uploader/vuetify` | Vue 3 + Vuetify 3 | Vuetify components |
19
18
 
20
- ### 📁 **Comprehensive File Support**
21
- - **Images**: JPG, JPEG, PNG, GIF, BMP, SVG, WebP, TIFF
22
- - **Videos**: MP4, AVI, MOV, WMV, FLV, WebM
23
- - **Documents**: PDF, DOC, DOCX, TXT, RTF, ODT
24
- - **Spreadsheets**: XLS, XLSX, CSV, ODS
25
- - **Presentations**: PPT, PPTX, ODP
26
- - **Archives**: ZIP, RAR, 7Z, TAR, GZ
27
- - **Audio**: MP3, WAV, FLAC, AAC, OGG
19
+ ## ✨ Features
28
20
 
29
- ### 🎨 **Multiple Upload Styles**
30
- - **ThumbnailUploader**: Grid-based layout with file previews
31
- - **TableUploader**: Table-based layout for detailed file information
32
- - **SimpleUploader**: Minimalist drag-and-drop interface
33
-
34
- ### 🌍 **Internationalization**
35
- - **8 languages**: English, Chinese, Spanish, French, German, Japanese, Korean, Arabic
36
- - RTL support for Arabic
37
- - Easy language switching
21
+ - **Video thumbnails:** a frame is captured automatically for MP4, WebM, MOV and other formats the browser can play.
22
+ - **Image compression:** optional; JPEG, PNG and WebP are re-encoded as JPEG, and the smaller result is kept.
23
+ - **Three views:** `thumbnail` (preview cards), `simple` (compact cards) and `table`.
24
+ - **File details:** rename files, and add descriptions and tags before or after upload.
25
+ - **Validation:** file size, file count and accepted types, including for drag-and-dropped files.
26
+ - **Permissions:** turn insert, edit and delete on or off.
27
+ - **Languages:** English, Persian, French, Chinese and Arabic, with right-to-left layout for Persian and Arabic. You can also add your own translations.
28
+ - **TypeScript:** full type declarations.
38
29
 
39
30
  ## 📦 Installation
40
31
 
@@ -42,362 +33,257 @@ A comprehensive Vue 3 file uploader component library with advanced features inc
42
33
  npm install handy-uploader
43
34
  ```
44
35
 
45
- ```bash
46
- yarn add handy-uploader
47
- ```
48
-
49
- ```bash
50
- pnpm add handy-uploader
51
- ```
36
+ For the Vuetify flavour, also install `vuetify@^3` (and `@mdi/font` for its icons).
52
37
 
53
38
  ## 🚀 Quick Start
54
39
 
55
- ### 1. Install Dependencies
56
-
57
- Make sure you have the required peer dependencies:
58
-
59
- ```bash
60
- npm install vue@^3.0.0 vuetify@^3.0.0
61
- ```
62
-
63
- ### 2. Import and Use
40
+ ### Without Vuetify (any CSS framework)
64
41
 
65
42
  ```vue
66
- <template>
67
- <div>
68
- <!-- Thumbnail Uploader with Video Support -->
69
- <ThumbnailUploader
70
- :max-file-size="10485760"
71
- :max-file-count="5"
72
- :accepted-file-types="['image/*', 'video/*']"
73
- :language="'en'"
74
- @files-selected="handleFilesSelected"
75
- />
76
- </div>
77
- </template>
78
-
79
43
  <script setup lang="ts">
80
- import { ThumbnailUploader } from 'handy-uploader'
81
- import type { FileData } from 'handy-uploader'
44
+ import { ref } from 'vue'
45
+ import { HandyUploader, type DocumentAttachment } from 'handy-uploader'
46
+ import 'handy-uploader/style.css'
82
47
 
83
- const handleFilesSelected = (files: FileData[]) => {
84
- console.log('Selected files:', files)
85
- // Each file includes base64 data and video thumbnails are auto-generated
86
- }
48
+ const files = ref<DocumentAttachment[]>([])
87
49
  </script>
50
+
51
+ <template>
52
+ <HandyUploader
53
+ v-model:document-attachment="files"
54
+ file-uploader-type="thumbnail"
55
+ file-accept="image/*,video/*,.pdf"
56
+ :max-file-size="10 * 1024 * 1024"
57
+ :max-file-count="10"
58
+ change-file-name
59
+ add-file-description
60
+ add-file-tag
61
+ :tags="['invoice', 'contract', 'photo']"
62
+ />
63
+ </template>
88
64
  ```
89
65
 
90
- ### 3. Setup Vuetify (Required)
66
+ ### With Vuetify
91
67
 
92
- ```typescript
68
+ ```ts
93
69
  // main.ts
94
70
  import { createApp } from 'vue'
95
71
  import { createVuetify } from 'vuetify'
96
72
  import 'vuetify/styles'
97
73
  import '@mdi/font/css/materialdesignicons.css'
74
+ import App from './App.vue'
98
75
 
99
- const vuetify = createVuetify()
100
- const app = createApp(App)
101
-
102
- app.use(vuetify)
103
- app.mount('#app')
76
+ createApp(App).use(createVuetify()).mount('#app')
104
77
  ```
105
78
 
106
- ## 📖 Component Usage
107
-
108
- ### ThumbnailUploader (Recommended)
79
+ ```vue
80
+ <script setup lang="ts">
81
+ import { ref } from 'vue'
82
+ import { HandyUploader } from 'handy-uploader/vuetify'
83
+ import type { DocumentAttachment } from 'handy-uploader/vuetify'
109
84
 
110
- Perfect for media files with automatic video thumbnail generation:
85
+ const files = ref<DocumentAttachment[]>([])
86
+ </script>
111
87
 
112
- ```vue
113
88
  <template>
114
- <ThumbnailUploader
115
- :max-file-size="52428800"
116
- :max-file-count="10"
117
- :accepted-file-types="['image/*', 'video/*', 'application/pdf']"
118
- :language="'en'"
119
- :theme="'light'"
120
- @files-selected="onFilesSelected"
121
- @file-removed="onFileRemoved"
122
- @error="onError"
123
- />
89
+ <HandyUploader v-model:document-attachment="files" file-uploader-type="table" />
124
90
  </template>
125
-
126
- <script setup>
127
- import { ThumbnailUploader } from 'handy-uploader'
128
-
129
- const onFilesSelected = (files) => {
130
- // Video files will have thumbnails automatically generated
131
- files.forEach(file => {
132
- if (file.type === 'video') {
133
- console.log('Video thumbnail:', file.thumbnail) // Base64 thumbnail
134
- }
135
- })
136
- }
137
- </script>
138
91
  ```
139
92
 
140
- ### TableUploader
93
+ Switching between the two is a one-line change, because the props are the same.
141
94
 
142
- Great for document management with detailed file information:
95
+ ## 🧭 Framework Support
143
96
 
144
- ```vue
145
- <template>
146
- <TableUploader
147
- :max-file-size="104857600"
148
- :max-file-count="20"
149
- :language="'en'"
150
- @files-selected="handleFiles"
151
- />
152
- </template>
153
- ```
97
+ | Framework | Status |
98
+ | --- | --- |
99
+ | **Vue 3** (any CSS) | ✅ `handy-uploader` |
100
+ | **Vue 3 + Vuetify 3** | ✅ `handy-uploader/vuetify` |
101
+ | **React, Svelte, Angular, plain HTML** | 🛠️ Planned as a Web Component (`<handy-uploader>`) in a 3.x release |
154
102
 
155
- ### SimpleUploader
103
+ The upload logic (reading files, validation, compression, video thumbnails) lives in a framework-free core that is already exported; see [Building your own UI](#-building-your-own-ui).
156
104
 
157
- Minimal drag-and-drop interface:
105
+ ## 📚 Documentation
158
106
 
159
- ```vue
160
- <template>
161
- <SimpleUploader
162
- :max-file-size="5242880"
163
- :accepted-file-types="['image/*']"
164
- @files-selected="handleImages"
165
- />
166
- </template>
167
- ```
107
+ The [live demo](https://illustrious-griffin-257b43.netlify.app) is a Storybook with guides and an interactive example of every feature:
108
+
109
+ - [Getting Started](https://illustrious-griffin-257b43.netlify.app/?path=/docs/guide-getting-started--docs)
110
+ - [Feature Tour](https://illustrious-griffin-257b43.netlify.app/?path=/docs/guide-feature-tour--docs): every feature, with a link to try it
111
+ - [Styling & Theming](https://illustrious-griffin-257b43.netlify.app/?path=/docs/guide-styling-theming--docs)
112
+ - [Build Your Own UI](https://illustrious-griffin-257b43.netlify.app/?path=/docs/guide-build-your-own-ui--docs)
113
+ - [Upgrading from 2.x](https://illustrious-griffin-257b43.netlify.app/?path=/docs/guide-upgrading-from-2-x--docs)
168
114
 
169
115
  ## ⚙️ API Reference
170
116
 
171
- ### Props
117
+ ### `HandyUploader` props
172
118
 
173
119
  | Prop | Type | Default | Description |
174
- |------|------|---------|-------------|
175
- | `maxFileSize` | `number` | `10485760` | Maximum file size in bytes (10MB) |
176
- | `maxFileCount` | `number` | `5` | Maximum number of files |
177
- | `acceptedFileTypes` | `string[]` | `['*']` | Accepted MIME types |
178
- | `language` | `string` | `'en'` | Language code |
179
- | `theme` | `string` | `'light'` | Theme variant |
120
+ | --- | --- | --- | --- |
121
+ | `documentAttachment` | `DocumentAttachment[]` | `[]` | The files. Use with `v-model:document-attachment`, or pass an array. The component updates the array you pass in, as the Vuetify version always has. |
122
+ | `fileUploaderType` | `'thumbnail' \| 'simple' \| 'table'` | `'thumbnail'` | Layout. |
123
+ | `maxFileSize` | `number` | `5242880` | Maximum size per file, **in bytes** (5 MB). |
124
+ | `maxFileCount` | `number` | `10` | Maximum number of files. |
125
+ | `fileAccept` | `string` | `''` | Accepted types, in the same format as the HTML `accept` attribute, e.g. `"image/*,.pdf"`. Empty means everything. |
126
+ | `imageCompressor` | `boolean` | `false` | Compress JPEG, PNG and WebP images (re-encoded as JPEG, kept only when smaller). |
127
+ | `imageCompressLevel` | `number` | `0.8` | JPEG quality, from 0 to 1. |
128
+ | `thumb` | `boolean` | `true` | Show image previews and video thumbnails. When off, file-type icons are shown instead. |
129
+ | `cols` | `number` | `3` | Thumbnail view: card width out of 12 columns (3 = four per row, 4 = three per row). |
130
+ | `cardType` | `'default' \| 'outlined' \| 'raised' \| 'shaped' \| 'tile'` | `'default'` | Card style. |
131
+ | `badgeCounter` | `boolean` | `true` | Show the file count on the Insert button. |
132
+ | `btnColor` | `string` | `'info'` | Button colour: a Vuetify colour name (`primary`, `info`, `success`, …) or, without Vuetify, any CSS colour. |
133
+ | `changeFileName` | `boolean` | `false` | Let users rename files. |
134
+ | `addFileDescription` | `boolean` | `false` | Let users add a description. |
135
+ | `addFileTag` | `boolean` | `false` | Let users pick tags from `tags`. |
136
+ | `tags` | `string[]` | `[]` | Tags users can choose from. |
137
+ | `insertPermission` | `boolean` | `true` | Show the Insert button. |
138
+ | `editPermission` | `boolean` | `true` | Show the edit button. |
139
+ | `deletePermission` | `boolean` | `true` | Show the delete button. Deleting always asks for confirmation. |
140
+ | `tableThumbColumn` | `boolean` | `true` | Table view: show the preview column. |
141
+ | `tableFixedHeader` | `boolean` | `true` | Table view: keep the header visible while scrolling. |
142
+ | `tableHeight` | `number` | `400` | Table view: height in pixels when the header is fixed. |
143
+ | `lang` | `string` | `'en'` | Interface language: `en`, `fa`, `fr`, `ch`, `ar`, or a key you add with `customLang`. |
144
+ | `customLang` | `LanguageCollection \| null` | `null` | Your own translations (see [Internationalization](#-internationalization)). |
145
+ | `rtlSupport` | `boolean` | `false` | Right-to-left layout. Without Vuetify it is also turned on automatically for `fa` and `ar`. With Vuetify, use Vuetify's own RTL setting (`createVuetify({ locale: { rtl: … } })`). |
180
146
 
181
147
  ### Events
182
148
 
183
149
  | Event | Payload | Description |
184
- |-------|---------|-------------|
185
- | `files-selected` | `FileData[]` | Emitted when files are selected |
186
- | `file-removed` | `FileData` | Emitted when a file is removed |
187
- | `error` | `Error` | Emitted on errors |
188
-
189
- ### FileData Interface
150
+ | --- | --- | --- |
151
+ | `updateDocumentAttachment` | `DocumentAttachment[]` | The file list changed (added, edited or removed). |
152
+ | `update:documentAttachment` | `DocumentAttachment[]` | Same as above, for `v-model:document-attachment`. *(Not in the Vuetify flavour.)* |
153
+ | `add` | `DocumentAttachment[]` | Files were added. *(Not in the Vuetify flavour.)* |
154
+ | `remove` | `(attachment, index)` | A file was removed. *(Not in the Vuetify flavour.)* |
155
+ | `error` | `AttachmentError[]` | Files were rejected (`fileType`, `maxFileSize`, `maxFileCount`, `invalidFormat`). *(Not in the Vuetify flavour.)* |
190
156
 
191
- ```typescript
192
- interface FileData {
193
- id: string
194
- name: string
195
- size: number
196
- type: string
197
- format: string
198
- base64?: string
199
- thumbnail?: string // Auto-generated for videos
200
- lastModified: number
201
- }
202
- ```
157
+ When a prop changes, the component also emits a matching `update…` event (e.g. `updateCardType`, `updateLang`), as the 2.x versions did.
203
158
 
204
- ## 🎯 Advanced Features
159
+ ### Slots (without Vuetify)
205
160
 
206
- ### Video Thumbnail Generation
161
+ | Slot | Props | Use |
162
+ | --- | --- | --- |
163
+ | `item` | `{ attachment, index, remove }` | Replace a whole card. |
164
+ | `actions` | `{ attachment, index }` | Add your own buttons to each card or row. |
165
+ | `empty` | – | Content to show when there are no files. |
207
166
 
208
- The library automatically generates thumbnails for video files:
167
+ ### Data types
209
168
 
210
- ```javascript
211
- // Thumbnails are generated automatically
212
- const videoFile = {
213
- name: 'video.mp4',
214
- type: 'video',
215
- thumbnail: 'data:image/jpeg;base64,/9j/4AAQ...' // Auto-generated
169
+ ```ts
170
+ interface DocumentAttachment {
171
+ file: FileData
216
172
  }
217
- ```
218
-
219
- ### File Type Detection
220
173
 
221
- Automatic file type detection and icon assignment:
222
-
223
- ```javascript
224
- // Automatic type detection
225
- const file = {
226
- name: 'document.pdf',
227
- type: 'document', // Auto-detected
228
- icon: 'mdi-file-pdf-box', // Auto-assigned
229
- color: 'red' // Auto-assigned
174
+ interface FileData {
175
+ name: string // with extension, e.g. "report.pdf"
176
+ format: string // extension, e.g. "pdf"; "jpg" after compression
177
+ base64: string // file contents, without the "data:…;base64," prefix
178
+ size: number // bytes
179
+ tags: string[]
180
+ description: string | null
181
+ showDetailState: boolean
230
182
  }
231
183
  ```
232
184
 
233
- ### Image Compression
185
+ ## 🎨 Styling (without Vuetify)
234
186
 
235
- Built-in image compression for large files:
187
+ Import the default theme once:
236
188
 
237
- ```vue
238
- <ThumbnailUploader
239
- :compress-images="true"
240
- :compression-quality="0.8"
241
- :max-width="1920"
242
- :max-height="1080"
243
- />
189
+ ```ts
190
+ import 'handy-uploader/style.css'
244
191
  ```
245
192
 
246
- ## 🌍 Internationalization
193
+ The easiest way to re-theme is with CSS variables, on the component or any parent:
247
194
 
248
- Supported languages:
249
-
250
- ```javascript
251
- const languages = [
252
- 'en', // English
253
- 'zh', // Chinese
254
- 'es', // Spanish
255
- 'fr', // French
256
- 'de', // German
257
- 'ja', // Japanese
258
- 'ko', // Korean
259
- 'ar' // Arabic (RTL)
260
- ]
195
+ ```css
196
+ .hu-uploader {
197
+ --hu-primary: #7c3aed; /* links, focus, drop area */
198
+ --hu-button-bg: #7c3aed; /* Insert / Add buttons (or use btnColor) */
199
+ --hu-chip: #7c3aed; /* size chips */
200
+ --hu-radius: 16px; /* card corners */
201
+ --hu-media-height: 160px; /* preview height in the thumbnail view */
202
+ --hu-font: inherit;
203
+ }
261
204
  ```
262
205
 
263
- ## 🛠️ Technical Requirements
206
+ - Add the `hu-dark` class (on the component or a parent) for the dark preset.
207
+ - Built-in styles are single `hu-*` class selectors. They survive global resets such as Tailwind's preflight, and are easy to override with your own classes.
208
+ - Or skip `style.css` entirely and style the `hu-*` classes yourself.
264
209
 
265
- ### Peer Dependencies
266
- - **Vue**: ^3.0.0
267
- - **Vuetify**: ^3.0.0
210
+ The default theme uses `color-mix()` and `:has()` (Chrome/Edge 111+, Firefox 121+, Safari 16.4+). In older browsers it still works, with simpler focus and badge styling.
268
211
 
269
- ### Browser Support
270
- - Chrome 88+
271
- - Firefox 85+
272
- - Safari 14+
273
- - Edge 88+
212
+ ## 🧱 Building your own UI
274
213
 
275
- ### Bundle Size
276
- - **Gzipped**: ~45KB
277
- - **Minified**: ~120KB
214
+ Everything `HandyUploader` uses is exported:
278
215
 
279
- ## 🎨 Customization
216
+ - **`useUploader(filesRef, options)`:** the upload logic with no markup. It provides `add`, `stage` + `commit` (read files, let users edit them, then add), `remove`, `update`, `clear`, `errors` and `isProcessing`.
217
+ - **Components:** `HandyDropzone`, `HandyFileList`, `HandyDialog` and `HandyFileIcon`.
218
+ - **Framework-agnostic helpers:** `readFiles`, `prepareAttachments`, `compressDataUrl`, `generateVideoThumbnail`, `matchesAccept`, `formatBytes` and more. These have no Vue dependency.
280
219
 
281
- ### Theming
282
-
283
- Works with Vuetify's theming system:
284
-
285
- ```javascript
286
- // vuetify.config.js
287
- export default createVuetify({
288
- theme: {
289
- themes: {
290
- light: {
291
- primary: '#1976D2',
292
- secondary: '#424242',
293
- // Custom theme colors
294
- }
295
- }
296
- }
220
+ ```ts
221
+ import { ref } from 'vue'
222
+ import { useUploader, type DocumentAttachment } from 'handy-uploader'
223
+
224
+ const files = ref<DocumentAttachment[]>([])
225
+ const { add, remove, errors, isProcessing } = useUploader(files, {
226
+ maxFileSize: 5 * 1024 * 1024,
227
+ maxFileCount: 10,
228
+ accept: 'image/*',
229
+ imageCompressor: true
297
230
  })
231
+ // <input type="file" multiple @change="add($event.target.files)">
298
232
  ```
299
233
 
300
- ### Custom Styling
234
+ ## 🌍 Internationalization
301
235
 
302
- ```vue
303
- <style scoped>
304
- .handy-uploader {
305
- --uploader-border-radius: 12px;
306
- --uploader-primary-color: #1976D2;
307
- --uploader-background: #f5f5f5;
308
- }
309
- </style>
310
- ```
236
+ Built-in languages: `en` (English), `fa` (Persian, RTL), `fr` (French), `ch` (Chinese), `ar` (Arabic, RTL).
237
+
238
+ To change texts or add a language, pass `customLang`. Start from the built-in strings:
311
239
 
312
- ## 📝 Examples
240
+ ```ts
241
+ import { languageData } from 'handy-uploader'
313
242
 
314
- ### Complete Example with All Features
243
+ const customLang = {
244
+ ...languageData,
245
+ de: { ...languageData.en, insertFile: 'Datei hinzufügen', add: 'Hinzufügen' /* … */ }
246
+ }
247
+ ```
315
248
 
316
249
  ```vue
317
- <template>
318
- <div class="uploader-container">
319
- <h2>File Upload with Video Thumbnails</h2>
320
-
321
- <ThumbnailUploader
322
- :max-file-size="52428800"
323
- :max-file-count="10"
324
- :accepted-file-types="['image/*', 'video/*', 'application/pdf']"
325
- :language="currentLanguage"
326
- :theme="isDark ? 'dark' : 'light'"
327
- :compress-images="true"
328
- :compression-quality="0.8"
329
- @files-selected="handleFilesSelected"
330
- @file-removed="handleFileRemoved"
331
- @error="handleError"
332
- />
333
-
334
- <!-- Display selected files -->
335
- <div v-if="selectedFiles.length" class="mt-4">
336
- <h3>Selected Files:</h3>
337
- <div v-for="file in selectedFiles" :key="file.id" class="file-item">
338
- <img v-if="file.thumbnail" :src="file.thumbnail" alt="Thumbnail" width="100" />
339
- <span>{{ file.name }} ({{ formatFileSize(file.size) }})</span>
340
- </div>
341
- </div>
342
- </div>
343
- </template>
250
+ <HandyUploader :custom-lang="customLang" lang="de" />
251
+ ```
344
252
 
345
- <script setup lang="ts">
346
- import { ref } from 'vue'
347
- import { ThumbnailUploader, type FileData } from 'handy-uploader'
253
+ ## 🛠️ Requirements
348
254
 
349
- const selectedFiles = ref<FileData[]>([])
350
- const currentLanguage = ref('en')
351
- const isDark = ref(false)
255
+ - **Vue** ^3.0.0
256
+ - **Vuetify** ^3.0.0: optional, only for `handy-uploader/vuetify`
257
+ - Modern browsers (Chrome, Edge, Firefox, Safari). Video thumbnails need a browser that can play the video format.
352
258
 
353
- const handleFilesSelected = (files: FileData[]) => {
354
- selectedFiles.value = files
355
- console.log('Files with thumbnails:', files)
356
- }
259
+ Bundle size (minified, gzipped): `handy-uploader` about 10 KB JS + 3 KB CSS, plus about 6 KB of translations; `handy-uploader/vuetify` about 14 KB (Vue and Vuetify not included).
357
260
 
358
- const handleFileRemoved = (file: FileData) => {
359
- console.log('File removed:', file.name)
360
- }
261
+ ## ⬆️ Upgrading from 2.x
361
262
 
362
- const handleError = (error: Error) => {
363
- console.error('Upload error:', error)
364
- }
263
+ - **Vuetify users:** change the import to `handy-uploader/vuetify`. Nothing else changes.
264
+ - **`maxFileSize` is now enforced in bytes**, as documented. 2.x compared it in kilobytes, so limits were about 1000× looser. If you tuned the value to the old behaviour, divide it by 1000.
265
+ - **`file.size` is always a number of bytes.** It used to be a string.
266
+ - **The package ships ES modules and CommonJS.** The UMD build was removed.
365
267
 
366
- const formatFileSize = (bytes: number) => {
367
- return bytes > 1024 * 1024
368
- ? `${(bytes / 1024 / 1024).toFixed(2)} MB`
369
- : `${(bytes / 1024).toFixed(2)} KB`
370
- }
371
- </script>
372
- ```
268
+ See [CHANGELOG.md](CHANGELOG.md) for details.
373
269
 
374
270
  ## 🤝 Contributing
375
271
 
376
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
377
-
378
- 1. Fork the repository
379
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
380
- 3. Commit your changes (`git commit -m 'Add amazing feature'`)
381
- 4. Push to the branch (`git push origin feature/amazing-feature`)
382
- 5. Open a Pull Request
272
+ 1. Fork the repository and create a branch.
273
+ 2. `npm install`, then `npm run storybook` to work on the components.
274
+ 3. Run `npm test`, `npm run type-check` and `npm run lint` before opening a pull request.
275
+ 4. Add a changeset (`npx changeset`) describing your change.
383
276
 
384
277
  ## 📄 License
385
278
 
386
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
279
+ MIT. See [LICENSE](LICENSE).
387
280
 
388
281
  ## 🔗 Links
389
282
 
390
- - [GitHub Repository](https://github.com/alijahanpak/vue-file-uploader)
391
- - [npm Package](https://www.npmjs.com/package/handy-uploader)
392
- - [Documentation](https://github.com/alijahanpak/vue-file-uploader#readme)
393
- - [Issues](https://github.com/alijahanpak/vue-file-uploader/issues)
394
-
395
- ## 📊 Stats
283
+ - [GitHub repository](https://github.com/alijahanpak/handy-uploader)
284
+ - [npm package](https://www.npmjs.com/package/handy-uploader)
285
+ - [Live demo (Storybook)](https://illustrious-griffin-257b43.netlify.app)
286
+ - [Issues](https://github.com/alijahanpak/handy-uploader/issues)
396
287
 
397
288
  ![npm downloads](https://img.shields.io/npm/dm/handy-uploader.svg)
398
289
  ![GitHub stars](https://img.shields.io/github/stars/alijahanpak/handy-uploader.svg)
399
- ![GitHub issues](https://img.shields.io/github/issues/alijahanpak/handy-uploader.svg)
400
-
401
- ---
402
-
403
- **Made with ❤️ for the Vue.js community**
@@ -7,18 +7,10 @@ interface Props {
7
7
  maxFileCount: number;
8
8
  selectedLang: LanguageCollection;
9
9
  }
10
- declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
+ declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
11
  openInputDocumentModal: (...args: any[]) => void;
12
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Props>>> & Readonly<{
13
- onOpenInputDocumentModal?: ((...args: any[]) => any) | undefined;
14
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
12
+ }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
13
+ onOpenInputDocumentModal?: (...args: any[]) => any;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
15
16
  export default _default;
16
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
17
- type __VLS_TypePropsToRuntimeProps<T> = {
18
- [K in keyof T]-?: {} extends Pick<T, K> ? {
19
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
20
- } : {
21
- type: import('vue').PropType<T[K]>;
22
- required: true;
23
- };
24
- };