@praxisui/files-upload 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ This package is licensed under the Apache License, Version 2.0.
2
+
3
+ For the full license text, see the repository root LICENSE file:
4
+ ../../LICENSE
5
+
6
+ Apache License 2.0: https://www.apache.org/licenses/LICENSE-2.0
7
+
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # Praxis Files Upload
2
+
3
+ Components and services for integrating file uploads with the Praxis backend. Configuration is provided as JSON and can be edited at runtime through the Settings Panel.
4
+
5
+ ## Component Overview
6
+
7
+ Main component selector: `praxis-files-upload`
8
+
9
+ Inputs
10
+ - `config: FilesUploadConfig | null` UI/limits/options for the upload flow.
11
+ - `baseUrl?: string` Required to enable uploads (backend base URL for files API).
12
+ - `componentId: string` Persistence key suffix for local config (default: `default`).
13
+ - `displayMode: 'full' | 'compact'` Controls UI density and overlays (default: `full`).
14
+
15
+ Outputs
16
+ - `uploadSuccess: { file: FileMetadata }` Emitted per successful single upload.
17
+ - `bulkComplete: BulkUploadResponse` Summary for batch uploads.
18
+ - `error: ErrorResponse` Error information for failed requests.
19
+ - `rateLimited: RateLimitInfo` Emits when 429 is detected (with reset hints).
20
+ - `retry | download | copyLink | detailsOpened | detailsClosed: BulkUploadFileResult` Advanced list actions.
21
+ - `pendingFilesChange: File[]` Current selected (pending) files.
22
+ - `proximityChange: boolean` Proximity overlay visibility toggles.
23
+
24
+ ## Components
25
+
26
+ ### `PraxisFilesUpload`
27
+
28
+ ```ts
29
+ import { Component } from "@angular/core";
30
+ import { PraxisFilesUpload, FilesUploadConfig, FileMetadata } from "@praxis/files-upload";
31
+
32
+ @Component({
33
+ standalone: true,
34
+ imports: [PraxisFilesUpload],
35
+ template: `<praxis-files-upload [config]="config" (uploadSuccess)="onSuccess($event)"></praxis-files-upload>`,
36
+ })
37
+ export class DemoComponent {
38
+ config: FilesUploadConfig = {
39
+ strategy: "auto",
40
+ ui: { showDropzone: true },
41
+ };
42
+
43
+ onSuccess(event: { file: FileMetadata }) {
44
+ console.log("uploaded", event.file);
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### `PdxFilesUploadFieldComponent`
50
+
51
+ Wrapper for dynamic forms that implements `ControlValueAccessor` and emits either file metadata or the uploaded id according to the configured `valueMode`.
52
+
53
+ ```ts
54
+ <form [formGroup]="form">
55
+ <pdx-material-files-upload formControlName="attachment" />
56
+ </form>
57
+ ```
58
+
59
+ ## Configuration options
60
+
61
+ The editor allows adjusting UI behavior, bulk parameters, limits, quotas, rate limit handling, headers and messages for individual error codes.
62
+
63
+ - `strategy`: `direct` | `presign` | `auto` — `auto` tenta upload pré-assinado e recorre ao modo direto se a etapa de presign falhar.
64
+
65
+ ```json
66
+ {
67
+ "ui": { "accept": ["image/png", "application/pdf"], "showMetadataForm": true },
68
+ "limits": { "maxFileSizeBytes": 1048576 },
69
+ "bulk": { "parallelUploads": 2, "retryCount": 3 },
70
+ "quotas": { "showQuotaWarnings": true },
71
+ "rateLimit": { "autoRetryOn429": true, "maxAutoRetry": 2 },
72
+ "headers": { "tenantHeader": "X-Tenant-Id" },
73
+ "messages": {
74
+ "successSingle": "Uploaded",
75
+ "errors": { "QUOTA_EXCEEDED": "Quota reached" }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Constraints
81
+
82
+ Client-side constraints can be enforced via `config` and validated by built-in validators:
83
+
84
+ - Types: `ui.accept: string[]` (e.g., `['image/png','application/pdf']`)
85
+ - Extensions/MIME: `options.allowedExtensions`, `options.acceptMimeTypes`
86
+ - Size per file: `limits.maxFileSizeBytes` (bytes) or `limits.maxUploadSizeMb`
87
+ - Count per batch: `limits.maxFilesPerBulk`
88
+ - Total size per batch: `limits.maxBulkSizeBytes`
89
+
90
+ Example (2 files max, 5 MB each, PNG/JPEG only):
91
+
92
+ ```ts
93
+ const cfg: FilesUploadConfig = {
94
+ ui: { accept: ['image/png', 'image/jpeg'], showDropzone: true },
95
+ limits: { maxFileSizeBytes: 5 * 1024 * 1024, maxFilesPerBulk: 2 },
96
+ };
97
+ ```
98
+
99
+ ## Services
100
+
101
+ - `FilesApiClient` – performs direct or bulk uploads and requests presigned URLs.
102
+ - `PresignedUploaderService` – posts files to presigned targets with headers and form fields.
103
+ - `ConfigService` – retrieves effective backend configuration with ETag caching scoped by base URL and tenant/user headers.
104
+ - `useEffectiveUploadConfig` – Angular composable exposing loading/data/error/context signals and a refetch method.
105
+
106
+ ## Validators
107
+
108
+ - `acceptValidator`
109
+ - `maxFileSizeValidator`
110
+ - `maxFilesPerBulkValidator`
111
+ - `maxBulkSizeValidator`
112
+
113
+ ## Error handling
114
+
115
+ `ErrorMapperService` translates backend `ErrorCode` values into user-facing messages and exposes rate limit information.
116
+
117
+ Default messages are provided in Portuguese but can be overridden globally by
118
+ providing the `FILES_UPLOAD_ERROR_MESSAGES` injection token:
119
+
120
+ ```ts
121
+ { provide: FILES_UPLOAD_ERROR_MESSAGES, useValue: { QUOTA_EXCEEDED: 'Limite atingido' } }
122
+ ```
123
+
124
+ ## Configuration persistence
125
+
126
+ The configuration editor stores settings in `CONFIG_STORAGE` with fallback to `localStorage`, using the key `files-upload-config:<componentId>`.
127
+
128
+ ## Internationalização
129
+
130
+ Todas as mensagens do componente são fornecidas em Português Brasileiro. Para cenários multilíngues, o componente integra-se opcionalmente ao `@ngx-translate/core` e expõe um conjunto de chaves `praxis.filesUpload.*`.
131
+
132
+ As traduções padrão podem ser registradas com o objeto `FILES_UPLOAD_PT_BR`:
133
+
134
+ ```ts
135
+ import { TranslateService } from '@ngx-translate/core';
136
+ import { FILES_UPLOAD_PT_BR } from '@praxis/files-upload';
137
+
138
+ constructor(private translate: TranslateService) {
139
+ translate.setTranslation('pt-BR', FILES_UPLOAD_PT_BR, true);
140
+ }
141
+ ```
142
+
143
+ Se nenhuma tradução estiver disponível, o componente utiliza o token `FILES_UPLOAD_TEXTS` como fallback. Para sobrescrever os textos manualmente:
144
+
145
+ ```ts
146
+ import { FILES_UPLOAD_TEXTS } from "@praxis/files-upload";
147
+
148
+ providers: [
149
+ {
150
+ provide: FILES_UPLOAD_TEXTS,
151
+ useValue: {
152
+ settingsAriaLabel: "Open settings",
153
+ dropzoneLabel: "Drag files here or",
154
+ dropzoneButton: "select",
155
+ conflictPolicyLabel: "Conflict policy",
156
+ metadataLabel: "Metadata (JSON)",
157
+ progressAriaLabel: "Upload progress",
158
+ rateLimitBanner: "Rate limit exceeded. Try again at",
159
+ },
160
+ },
161
+ ];
162
+ ```