@servicemind.tis/angular-image-and-file-picker 1.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 (27) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +305 -0
  3. package/fesm2022/servicemind.tis-angular-image-and-file-picker.mjs +3658 -0
  4. package/fesm2022/servicemind.tis-angular-image-and-file-picker.mjs.map +1 -0
  5. package/index.d.ts +5 -0
  6. package/lib/angular-camera-capture-dialog/angular-camera-capture-dialog.component.d.ts +34 -0
  7. package/lib/angular-confirmation-dialog/angular-confirmation-dialog.component.d.ts +10 -0
  8. package/lib/angular-error-dialog/angular-error-dialog.component.d.ts +10 -0
  9. package/lib/angular-file-viewer/angular-excel-file-viewer/angular-excel-file-viewer.component.d.ts +14 -0
  10. package/lib/angular-file-viewer/angular-file-viewer.component.d.ts +16 -0
  11. package/lib/angular-file-viewer/angular-pdf-viewer/angular-pdf-viewer.component.d.ts +16 -0
  12. package/lib/angular-file-viewer/angular-video/angular-video.component.d.ts +13 -0
  13. package/lib/angular-image-and-file-picker/angular-image-and-file-picker.component.d.ts +186 -0
  14. package/lib/angular-image-and-file-picker.module.d.ts +31 -0
  15. package/lib/angular-image-and-file-picker.service.d.ts +6 -0
  16. package/lib/angular-preview-image/angular-preview-image.component.d.ts +19 -0
  17. package/lib/angular-qr-code-dialog/angular-qr-code-dialog.component.d.ts +90 -0
  18. package/lib/angular-view-connection-dialog/angular-view-connection-dialog.component.d.ts +44 -0
  19. package/lib/interfaces/config.type.d.ts +19 -0
  20. package/lib/interfaces/file-viewer-file-type.type.d.ts +41 -0
  21. package/lib/interfaces/index.d.ts +3 -0
  22. package/lib/interfaces/socket-adapter.interface.d.ts +315 -0
  23. package/lib/pipes/time-ago.pipe.d.ts +7 -0
  24. package/lib/services/angular-helper.service.d.ts +45 -0
  25. package/lib/services/angular-remote-upload.service.d.ts +273 -0
  26. package/package.json +53 -0
  27. package/public-api.d.ts +7 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thai Informatics System Co., Ltd.
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 ADDED
@@ -0,0 +1,305 @@
1
+ # angular-image-and-file-picker
2
+
3
+ An all-in-one **image and file upload/view** Angular component by **Thai Informatic Systems Co. Ltd.**, designed for modern enterprise applications. This library provides a highly customizable drag-and-drop or button-triggered upload UI, with seamless preview and viewer integration for files including images, PDFs, videos, Excel, and more.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@servicemind.tis/angular-image-and-file-picker)](https://www.npmjs.com/package/@servicemind.tis/angular-image-and-file-picker)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@servicemind.tis/angular-image-and-file-picker)](https://www.npmjs.com/package/@servicemind.tis/angular-image-and-file-picker)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+
9
+ ---
10
+
11
+ ## πŸš€ Features
12
+
13
+ - βœ… Image and file upload with S3-style pre-signed URL handling
14
+ - βœ… Support for images, PDFs, Excel, CSV, videos, and raw files
15
+ - βœ… Built-in preview & viewer components
16
+ - βœ… Optional confirmation dialogs
17
+ - βœ… Fully customizable UI and dialog labels
18
+ - βœ… Support for standalone and module-based Angular apps
19
+ - βœ… Supports multiple uploads, size control, and compression toggle
20
+
21
+ ---
22
+
23
+ ## πŸ“¦ Installation
24
+
25
+ ```bash
26
+ npm install @servicemind.tis/angular-image-and-file-picker
27
+ ```
28
+
29
+ ### Peer Dependencies
30
+
31
+ ```bash
32
+ npm install @angular/material @angular/cdk
33
+ ```
34
+
35
+ ---
36
+
37
+ ## 🧩 Module Setup
38
+
39
+ ```ts
40
+ import { AngularImageAndFilePickerModule } from '@servicemind.tis/angular-image-and-file-picker';
41
+
42
+ @NgModule({
43
+ imports: [AngularImageAndFilePickerModule]
44
+ })
45
+ export class MyFeatureModule {}
46
+ ```
47
+
48
+ ---
49
+
50
+ ## βš™οΈ Configuration Interfaces
51
+
52
+ ### `UrlConfig`
53
+
54
+ ```ts
55
+ export interface UrlConfig {
56
+ getUploadUrl: string;
57
+ attachToEntity: string;
58
+ removeImage: string;
59
+ }
60
+ ```
61
+
62
+ ### `DialogConfig`
63
+
64
+ ```ts
65
+ export interface DialogConfig {
66
+ title: string;
67
+ message: string | null;
68
+ iconClass: string;
69
+ icon: string;
70
+ approveButtonText: string | null;
71
+ approveButtonClass: string;
72
+ cancelButtonText: string | null;
73
+ cancelButtonClass: string;
74
+ }
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 🧠 Component: `<angular-image-and-file-picker>`
80
+
81
+ This is the main component that allows users to upload and preview files.
82
+
83
+ ### βœ… Inputs
84
+
85
+ | Input | Type | Description |
86
+ |---------------|---------------------|-------------|
87
+ | `urlConfig` | `UrlConfig` | API endpoints for upload, attach, delete |
88
+ | `entityType` | `string` | Type of the associated entity |
89
+ | `disabled` | `boolean` | Disable upload actions |
90
+ | `viewType` | `'card'` | View format |
91
+ | `options` | `UploadOptions` | Visual and functional configurations |
92
+ | `accept` | `string` | Allowed file types (e.g., `.jpg,.png`) |
93
+ | `label` | `string` | Upload label |
94
+ | `data` | `any[]` | Existing file data to render |
95
+ | `dialogConfig`| `DialogConfig` | Custom confirmation dialog settings |
96
+
97
+ ---
98
+
99
+ ## πŸ“€ Example Usage
100
+
101
+ ### HTML
102
+
103
+ ```html
104
+ <angular-image-and-file-picker
105
+ [urlConfig]="urlConfig"
106
+ [entityType]="'announcement_details'"
107
+ [disabled]="false"
108
+ viewType="card"
109
+ [options]="{
110
+ selectorId: 'choosing-image-for-announcement-details',
111
+ height: '108px',
112
+ isStoredDb: false,
113
+ isMultiple: true,
114
+ cols: 5,
115
+ isCompressed: false
116
+ }"
117
+ accept=".png,.jpeg,.jpg"
118
+ label="Upload Image"
119
+ [data]="files"
120
+ [dialogConfig]="getImagePickerDialogConfig()">
121
+ </angular-image-and-file-picker>
122
+ ```
123
+
124
+ ### Component (TS)
125
+
126
+ ```ts
127
+ urlConfig: UrlConfig = {
128
+ getUploadUrl: 'https://your-api/get-upload-url',
129
+ attachToEntity: 'https://your-api/attach-to-entity',
130
+ removeImage: 'https://your-api/remove-url',
131
+ };
132
+
133
+ files = [
134
+ {
135
+ s3Url: 'https://bucket-url/file1.jpg',
136
+ uploadData: {
137
+ uploadURL: 'https://bucket-url/upload',
138
+ fileName: 'example.jpg',
139
+ uploadPath: '/entity/example.jpg',
140
+ resourceUrl: 'https://bucket-url/example.jpg'
141
+ }
142
+ }
143
+ ];
144
+
145
+ getImagePickerDialogConfig(): DialogConfig {
146
+ return {
147
+ title: 'Delete Image',
148
+ message: 'Are you sure you want to delete this image?',
149
+ iconClass: 'angular-text-danger',
150
+ icon: 'delete',
151
+ approveButtonText: 'Yes',
152
+ approveButtonClass: 'angular-btn-danger',
153
+ cancelButtonText: 'No',
154
+ cancelButtonClass: 'angular-btn-primary'
155
+ };
156
+ }
157
+ ```
158
+
159
+ ---
160
+
161
+ ## πŸ–ΌοΈ File Types Supported
162
+
163
+ Component auto-detects and handles:
164
+
165
+ - πŸ“„ PDF
166
+ - πŸ“· Images (`jpg`, `jpeg`, `png`)
167
+ - πŸ“Ή Videos
168
+ - πŸ“Š Excel & CSV
169
+ - πŸ“¦ Raw files (opens via download or fallback preview)
170
+
171
+ ---
172
+
173
+ ## πŸ”Œ Standalone App Integration
174
+
175
+ In `main.ts`:
176
+
177
+ ```ts
178
+ import { provideHttpClient } from '@angular/common/http';
179
+
180
+ bootstrapApplication(AppComponent, {
181
+ providers: [
182
+ provideHttpClient()
183
+ ]
184
+ });
185
+ ```
186
+
187
+ ---
188
+
189
+ ## 🎨 Styling
190
+
191
+ The component uses Angular Material β€” ensure a theme is included:
192
+
193
+ ```scss
194
+ @import "~@angular/material/prebuilt-themes/indigo-pink.css";
195
+ ```
196
+
197
+ ---
198
+
199
+
200
+
201
+ ## πŸ“‘ API Contract for Upload Integration
202
+
203
+ The component requires a pre-signed URL from your backend to upload files directly to cloud storage (like AWS S3). You must implement an API endpoint that responds with the following JSON structure:
204
+
205
+ ### βœ… Sample Response from `getUploadUrl`
206
+
207
+ ```json
208
+ {
209
+ "data": {
210
+ "uploadUrlData": {
211
+ "uploadURL": "https://your-s3-bucket/your-object-key.jpg?...",
212
+ "fileName": "your-object-key.jpg",
213
+ "uploadPath": "/folder/your-object-key.jpg",
214
+ "resourceUrl": "https://your-s3-bucket/your-object-key.jpg"
215
+ }
216
+ },
217
+ "message": "Upload Url generated successfully!"
218
+ }
219
+ ```
220
+
221
+ - **uploadURL**: This is the pre-signed `PUT` URL. The component will upload the file directly to this URL.
222
+ - **fileName**: Name of the file being uploaded.
223
+ - **uploadPath**: Optional path metadata for organizing resources.
224
+ - **resourceUrl**: The final public/accessible URL for accessing the uploaded file.
225
+
226
+ ---
227
+
228
+ ## πŸ“€ How Upload Works Internally
229
+
230
+ When a user selects a file:
231
+
232
+ 1. The component calls your `getUploadUrl` API with basic metadata (like file name/type).
233
+ 2. Your backend returns a `PUT` pre-signed URL via `uploadURL`.
234
+ 3. The component performs a **`PUT` request directly to that URL**, sending the image or file binary.
235
+ 4. After success, the `resourceUrl` is used for rendering or viewing.
236
+
237
+ ---
238
+
239
+ ## πŸ”Œ Backend API Example (Node.js)
240
+
241
+ Here’s a basic AWS S3 backend implementation in Node.js:
242
+
243
+ ```js
244
+ const AWS = require('aws-sdk');
245
+ const s3 = new AWS.S3();
246
+
247
+ app.post('/api/get-upload-url', (req, res) => {
248
+ const fileName = req.body.fileName;
249
+ const fileType = req.body.fileType;
250
+ const key = `cm_cases/${uuidv4()}.${fileType.split('/')[1]}`;
251
+
252
+ const params = {
253
+ Bucket: 'your-s3-bucket',
254
+ Key: key,
255
+ ContentType: fileType,
256
+ ACL: 'public-read',
257
+ Expires: 900,
258
+ };
259
+
260
+ const uploadURL = s3.getSignedUrl('putObject', params);
261
+ res.json({
262
+ data: {
263
+ uploadUrlData: {
264
+ uploadURL,
265
+ fileName,
266
+ uploadPath: `/${key}`,
267
+ resourceUrl: `https://your-s3-bucket.s3.amazonaws.com/${key}`
268
+ }
269
+ },
270
+ message: "Upload Url generated successfully!"
271
+ });
272
+ });
273
+ ```
274
+
275
+ ---
276
+
277
+
278
+ ## 🀝 Contributing
279
+
280
+ 1. Clone the repo
281
+ 2. Run `npm install`
282
+ 3. Use the demo app to test (`projects/` directory)
283
+ 4. Submit a PR or issue with details
284
+
285
+ ---
286
+
287
+ ## πŸš€ Publishing to npm
288
+
289
+ ```bash
290
+ git tag v1.0.0
291
+ git push origin v1.0.0
292
+ ```
293
+
294
+ GitHub Actions will build and publish to npm automatically if configured.
295
+
296
+ ---
297
+
298
+ ## πŸ“¬ Support / Questions
299
+
300
+ For bugs, suggestions, or feature requests, please open an issue on the [GitHub repository](https://github.com/Thai-Informatics-System/angular-image-and-file-picker).
301
+
302
+ ---
303
+
304
+ > Made with ❀️ by [Thai Informatic Systems Co. Ltd](https://tis.co.th/)
305
+