@nanahoshi/mona-ui 0.32.3 → 0.33.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/docs/api/file-upload.md +174 -0
- package/docs/api/i18n.md +46 -0
- package/docs/api/locales.md +14 -14
- package/docs/file-upload.md +516 -0
- package/docs/forms.md +2 -0
- package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-command.mjs +4 -3
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-file-upload.mjs +1137 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-colgroup.component-NhONCVIX.mjs → nanahoshi-mona-ui-grid-grid-colgroup.component-C62HvK-w.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-Djv8ZnT5.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-BpsJwMkQ.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-C1qjq2s7.mjs → nanahoshi-mona-ui-grid-grid-list.component-BVpGUjA7.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-CgOt2A6O.mjs → nanahoshi-mona-ui-grid-grid-row.component-D0T8kfdm.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-tguG2LpN.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-5D2BjGx4.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid.styles-BmLU-3zP.mjs → nanahoshi-mona-ui-grid-grid.styles-62LTuPhD.mjs} +3 -3
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +11 -10
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +74 -0
- package/fesm2022/nanahoshi-mona-ui-internal-live-announcer.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +50 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +38 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +38 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +38 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +38 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +44 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +38 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +44 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-spinner.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +2 -2
- package/file-upload/package.json +4 -0
- package/i18n/catalogs/en-US.messages.json +29 -0
- package/internal/live-announcer/package.json +4 -0
- package/llms.txt +3 -1
- package/locales/ar-sa/ar-sa.messages.json +29 -0
- package/locales/de-de/de-de.messages.json +29 -0
- package/locales/es-es/es-es.messages.json +29 -0
- package/locales/fr-fr/fr-fr.messages.json +29 -0
- package/locales/id-id/id-id.messages.json +29 -0
- package/locales/it-it/it-it.messages.json +29 -0
- package/locales/ja-jp/ja-jp.messages.json +29 -0
- package/locales/ko-kr/ko-kr.messages.json +29 -0
- package/locales/pl-pl/pl-pl.messages.json +29 -0
- package/locales/pt-br/pt-br.messages.json +29 -0
- package/locales/ru-ru/ru-ru.messages.json +29 -0
- package/locales/tr-tr/tr-tr.messages.json +29 -0
- package/locales/zh-cn/zh-cn.messages.json +29 -0
- package/locales/zh-tw/zh-tw.messages.json +29 -0
- package/package.json +9 -1
- package/types/nanahoshi-mona-ui-file-upload.d.ts +366 -0
- package/types/nanahoshi-mona-ui-i18n.d.ts +60 -0
- package/types/nanahoshi-mona-ui-internal-live-announcer.d.ts +12 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +29 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# `@nanahoshi/mona-ui/file-upload`
|
|
2
|
+
|
|
3
|
+
Everything `@nanahoshi/mona-ui/file-upload` exports.
|
|
4
|
+
|
|
5
|
+
**Guides:** [File Upload](../file-upload.md)
|
|
6
|
+
|
|
7
|
+
## `FileUploadComponent`
|
|
8
|
+
|
|
9
|
+
Component.
|
|
10
|
+
|
|
11
|
+
Picks files from a drop zone or the browser's file dialog, checks their type, size and count, and lists them. Given
|
|
12
|
+
an `upload` function, it uploads each file with a progress bar, and lets the person cancel or retry an upload.
|
|
13
|
+
|
|
14
|
+
The value is the files the checks let through. With an `upload` function, it's the files that finished uploading,
|
|
15
|
+
so a required field stays invalid until one has.
|
|
16
|
+
|
|
17
|
+
**Selector:** `mona-file-upload`
|
|
18
|
+
**Exported as:** `monaFileUpload`
|
|
19
|
+
**Implements:** `FormValueControl<File[]>`
|
|
20
|
+
|
|
21
|
+
### Inputs
|
|
22
|
+
|
|
23
|
+
| Name | Type | Default | Description |
|
|
24
|
+
| --- | --- | --- | --- |
|
|
25
|
+
| `accept` | `string` | `""` | File types the dialog offers and the checks accept, as in the native `accept` attribute: extensions such as `.pdf`, MIME types such as `image/png`, or `image/*`. Files dropped on the zone are checked against it too, since the dialog's filter doesn't apply to them. Empty accepts every file. |
|
|
26
|
+
| `aria-describedby` | `string \| null` | `null` | Id of an element that describes the browse button, such as an error message. A form field's hint and errors are added after it. |
|
|
27
|
+
| `aria-label` | `string \| null` | `null` | Accessible name of the group, when no label names it. |
|
|
28
|
+
| `aria-labelledby` | `string \| null` | `null` | Id of the element that names the group. |
|
|
29
|
+
| `autoUpload` | `boolean` | `true` | Uploads each file as soon as it's added. When off, files wait for the upload button, or for `uploadFiles()`. Has no effect without an `upload` function. |
|
|
30
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
31
|
+
| `disabled` | `boolean` | `false` | Turns off the drop zone, the browse button and the list's buttons. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
32
|
+
| `invalid` | `boolean` | `false` | Marks the upload as invalid. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
33
|
+
| `maxFiles` | `number \| null` | `null` | The most files the list holds, when `multiple` is on. Files past it are listed as rejected. |
|
|
34
|
+
| `maxFileSize` | `number \| null` | `null` | The largest file size in bytes. Larger files are listed as rejected, and not added. |
|
|
35
|
+
| `minFileSize` | `number \| null` | `null` | The smallest file size in bytes. Smaller files, such as empty ones, are listed as rejected. |
|
|
36
|
+
| `multiple` | `boolean` | `true` | Lets the person add several files. When off, a new file replaces the one in the list. |
|
|
37
|
+
| `readonly` | `boolean` | `false` | Keeps the list as it is: files can't be added or removed. |
|
|
38
|
+
| `required` | `boolean` | `false` | Marks the upload as required: it's invalid when touched with no file in its value. |
|
|
39
|
+
| `touched` | `boolean` | `false` | Sets the touched state. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
40
|
+
| `upload` | `FileUploadHandler \| null` | `null` | Uploads one file, and returns a promise or an observable, such as HttpClient's request with `reportProgress: true` and `observe: "events"`. Without it, the component only picks files, and the value holds them for the form to send. |
|
|
41
|
+
| `value` (two-way) | `File[]` | `[]` | The files the checks let through, or with an `upload` function, the files that finished uploading. Setting it from outside replaces the list, and stops the uploads that are running. |
|
|
42
|
+
|
|
43
|
+
### Outputs
|
|
44
|
+
|
|
45
|
+
| Name | Type | Description |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `remove` | `FileUploadItem` | Emitted when the person removes a file, by its remove or cancel button or by the clear button, with the file as it was. Delete an uploaded file from the server here. |
|
|
48
|
+
| `touch` | `void` | Emitted when focus leaves the component, and when files are dropped on it. The `FormField` directive listens to this to mark the field as touched. |
|
|
49
|
+
| `uploadError` | `FileUploadItem` | Emitted when a file fails to upload, with the error in its `error`. |
|
|
50
|
+
| `uploadSuccess` | `FileUploadItem` | Emitted when a file finishes uploading, with what the upload returned in its `response`. |
|
|
51
|
+
| `valueChange` | `File[]` | Emitted when `value` changes. |
|
|
52
|
+
|
|
53
|
+
### Properties
|
|
54
|
+
|
|
55
|
+
| Name | Type | Description |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| `items` (read-only) | `Signal<readonly FileUploadItem[]>` | Every file in the list, with where it stands, in the order they were added. |
|
|
58
|
+
| `uploading` (read-only) | `Signal<boolean>` | Whether any file is uploading. |
|
|
59
|
+
|
|
60
|
+
### Methods
|
|
61
|
+
|
|
62
|
+
| Signature | Description |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `browse(): void` | Opens the browser's file dialog, unless the component is disabled or read-only. |
|
|
65
|
+
| `clearFiles(): void` | Removes every file, stopping the uploads that are running, and emits `remove` for each but the rejected. |
|
|
66
|
+
| `focus(): void` | Moves focus to the browse button. |
|
|
67
|
+
| `uploadFiles(): void` | Uploads every file waiting for the upload button. Does nothing without an `upload` function. |
|
|
68
|
+
|
|
69
|
+
## `formatFileSize`
|
|
70
|
+
|
|
71
|
+
Function.
|
|
72
|
+
|
|
73
|
+
A file size in the locale, in the largest unit that keeps it at 1 or more: "512 bytes", "1.5 kB", "20 MB". Units are
|
|
74
|
+
multiples of 1024, as limits are usually written (`5 * 1024 * 1024`), so that limit reads as "5 MB".
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
function formatFileSize(bytes: number, localeId: string): string;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## `FILE_UPLOAD_DEFAULT_MESSAGES`
|
|
81
|
+
|
|
82
|
+
Constant.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const FILE_UPLOAD_DEFAULT_MESSAGES: MonaFileUploadMessages;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## `FileUploadContext`
|
|
89
|
+
|
|
90
|
+
Interface.
|
|
91
|
+
|
|
92
|
+
What the upload function gets with each file.
|
|
93
|
+
|
|
94
|
+
### Properties
|
|
95
|
+
|
|
96
|
+
| Name | Type | Description |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `signal` (read-only) | `AbortSignal` | Aborted when the upload stops early: the file is removed, the list is cleared, the value is replaced or the component is destroyed. Pass it to `fetch`. An observable doesn't need it, since it's unsubscribed instead. |
|
|
99
|
+
|
|
100
|
+
### Methods
|
|
101
|
+
|
|
102
|
+
| Signature | Description |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| `progress(loaded: number, total?: number): void` | Reports how much of the file has been sent. `total` defaults to the file's size. HttpClient's upload progress events are read without it. |
|
|
105
|
+
|
|
106
|
+
**Used by:** [`FileUploadHandler`](file-upload.md#fileuploadhandler)
|
|
107
|
+
|
|
108
|
+
## `FileUploadItem`
|
|
109
|
+
|
|
110
|
+
Interface.
|
|
111
|
+
|
|
112
|
+
A file in the upload's list, and where it stands.
|
|
113
|
+
|
|
114
|
+
### Properties
|
|
115
|
+
|
|
116
|
+
| Name | Type | Description |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| `error` (read-only) | `unknown` | What the upload failed with, while the status is `failed`. |
|
|
119
|
+
| `file` (read-only) | `File` | |
|
|
120
|
+
| `progress` (read-only) | `number \| null` | How much of the file has been sent, from 0 to 1, while it uploads. Null until the upload function reports progress, which it may never do. |
|
|
121
|
+
| `rejection` (read-only) | `FileUploadRejection \| null` | Why the file wasn't added, while the status is `rejected`. |
|
|
122
|
+
| `response` (read-only) | `unknown` | What the upload function returned for the file, once its status is `uploaded`. |
|
|
123
|
+
| `status` (read-only) | `FileUploadStatus` | |
|
|
124
|
+
|
|
125
|
+
**Used by:** [`FileUploadComponent`](file-upload.md#fileuploadcomponent)
|
|
126
|
+
|
|
127
|
+
## `FileUploadHandler`
|
|
128
|
+
|
|
129
|
+
Type alias.
|
|
130
|
+
|
|
131
|
+
Uploads one file, and returns a promise or an observable.
|
|
132
|
+
|
|
133
|
+
An observable can be HttpClient's request with `reportProgress: true` and `observe: "events"`: its upload progress
|
|
134
|
+
events move the progress bar, and its response's body becomes the file's `response`. For any other observable, its
|
|
135
|
+
last value does. For a promise, what it resolves to does. A rejected promise or an observable's error marks the file
|
|
136
|
+
`failed`.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
type FileUploadHandler = (file: File, context: FileUploadContext) => Observable<unknown> | Promise<unknown>;
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Used by:** [`FileUploadComponent`](file-upload.md#fileuploadcomponent)
|
|
143
|
+
|
|
144
|
+
## `FileUploadRejection`
|
|
145
|
+
|
|
146
|
+
Type alias.
|
|
147
|
+
|
|
148
|
+
Why a file wasn't added: its type isn't in `accept` (`type`), it's larger than `maxFileSize` (`maxFileSize`) or
|
|
149
|
+
smaller than `minFileSize` (`minFileSize`), or the list already holds as many files as it can (`maxFiles`).
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
type FileUploadRejection = "maxFileSize" | "maxFiles" | "minFileSize" | "type";
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Used by:** [`FileUploadItem`](file-upload.md#fileuploaditem)
|
|
156
|
+
|
|
157
|
+
## `FileUploadStatus`
|
|
158
|
+
|
|
159
|
+
Type alias.
|
|
160
|
+
|
|
161
|
+
Where a file in the list stands.
|
|
162
|
+
|
|
163
|
+
- `selected`: added and not uploaded. Without an `upload` function, every file the checks let through stays here.
|
|
164
|
+
With one, a file waits here while `autoUpload` is off.
|
|
165
|
+
- `uploading`: its upload is running.
|
|
166
|
+
- `uploaded`: its upload finished.
|
|
167
|
+
- `failed`: its upload failed, and can be retried.
|
|
168
|
+
- `rejected`: it didn't pass the type, size or count checks. It's listed with the reason, and isn't in the value.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
type FileUploadStatus = "failed" | "rejected" | "selected" | "uploaded" | "uploading";
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Used by:** [`FileUploadItem`](file-upload.md#fileuploaditem)
|
package/docs/api/i18n.md
CHANGED
|
@@ -443,6 +443,51 @@ Interface.
|
|
|
443
443
|
|
|
444
444
|
**Used by:** [`MonaLocaleMessages`](i18n.md#monalocalemessages)
|
|
445
445
|
|
|
446
|
+
## `MonaFileUploadMessages`
|
|
447
|
+
|
|
448
|
+
Interface.
|
|
449
|
+
|
|
450
|
+
The file upload's drop zone, its list of files, and what it announces as files are added, uploaded and removed.
|
|
451
|
+
|
|
452
|
+
### Properties
|
|
453
|
+
|
|
454
|
+
| Name | Type | Description |
|
|
455
|
+
| --- | --- | --- |
|
|
456
|
+
| `browse` (read-only) | `string` | The browse button's text, when several files can be added. |
|
|
457
|
+
| `browseFile` (read-only) | `string` | The browse button's text, when one file can be added. |
|
|
458
|
+
| `clear` (read-only) | `string` | Text of the button that removes every file, shown with the upload button while `autoUpload` is off. |
|
|
459
|
+
| `dropFile` (read-only) | `string` | The drop zone's text, when one file can be added. |
|
|
460
|
+
| `dropFiles` (read-only) | `string` | The drop zone's text, when several files can be added. |
|
|
461
|
+
| `dropToAdd` (read-only) | `string` | The drop zone's text while files are dragged over it. |
|
|
462
|
+
| `files` (read-only) | `string` | Name of the list of files. |
|
|
463
|
+
| `invalidType` (read-only) | `string` | Why a file of a type `accept` doesn't list wasn't added. |
|
|
464
|
+
| `readyToUpload` (read-only) | `string` | A file's status while it waits for the upload button. |
|
|
465
|
+
| `upload` (read-only) | `string` | Text of the button that uploads the waiting files, while `autoUpload` is off. |
|
|
466
|
+
| `uploaded` (read-only) | `string` | A file's status once it's uploaded. |
|
|
467
|
+
| `uploadFailed` (read-only) | `string` | A file's status when its upload failed. |
|
|
468
|
+
| `uploading` (read-only) | `string` | A file's status while it uploads. |
|
|
469
|
+
|
|
470
|
+
### Methods
|
|
471
|
+
|
|
472
|
+
| Signature | Description |
|
|
473
|
+
| --- | --- |
|
|
474
|
+
| `cancel(name: string): string` | Name of the button that stops a file's upload and removes it. |
|
|
475
|
+
| `fileFailed(name: string): string` | Announced when a file's upload fails. |
|
|
476
|
+
| `fileRejected(name: string, reason: string): string` | Announced for a file that wasn't added, with the reason, which is one of the rejection messages. |
|
|
477
|
+
| `fileRemoved(name: string): string` | Announced when a file is removed. |
|
|
478
|
+
| `filesAdded(count: number): string` | Announced when files are added. |
|
|
479
|
+
| `fileTypes(types: string): string` | The accepted types under the drop zone, as a list such as "PDF, PNG or JPG". |
|
|
480
|
+
| `fileUploaded(name: string): string` | Announced when a file's upload finishes. |
|
|
481
|
+
| `maxFiles(count: number): string` | The most files under the drop zone. |
|
|
482
|
+
| `maxFileSize(size: string): string` | The largest file size under the drop zone, formatted in the locale. |
|
|
483
|
+
| `remove(name: string): string` | Name of the button that removes a file. |
|
|
484
|
+
| `retry(name: string): string` | Name of the button that uploads a failed file again. |
|
|
485
|
+
| `tooLarge(size: string): string` | Why a file larger than `maxFileSize` wasn't added, with the size formatted in the locale. |
|
|
486
|
+
| `tooMany(count: number): string` | Why a file past `maxFiles` wasn't added. |
|
|
487
|
+
| `tooSmall(size: string): string` | Why a file smaller than `minFileSize` wasn't added, with the size formatted in the locale. |
|
|
488
|
+
|
|
489
|
+
**Used by:** [`FILE_UPLOAD_DEFAULT_MESSAGES`](file-upload.md#file-upload-default-messages), [`MonaLocaleMessages`](i18n.md#monalocalemessages)
|
|
490
|
+
|
|
446
491
|
## `MonaListBoxMessages`
|
|
447
492
|
|
|
448
493
|
Interface.
|
|
@@ -1236,6 +1281,7 @@ Interface.
|
|
|
1236
1281
|
| `dropdownList` | `MonaDropdownListMessages` |
|
|
1237
1282
|
| `dropdowns` | `MonaDropdownsMessages` |
|
|
1238
1283
|
| `editor` | `MonaEditorMessages` |
|
|
1284
|
+
| `fileUpload` | `MonaFileUploadMessages` |
|
|
1239
1285
|
| `filter` | `MonaFilterMessages` |
|
|
1240
1286
|
| `formField` | `MonaFormFieldMessages` |
|
|
1241
1287
|
| `grid` | `MonaGridMessages` |
|