@shival99/z-ui 2.1.28 → 2.1.29

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 (68) hide show
  1. package/package.json +1 -1
  2. package/types/shival99-z-ui-components-z-select.d.ts +1 -1
  3. package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs +0 -1079
  4. package/fesm2022/shival99-z-ui-components-z-autocomplete.mjs.map +0 -1
  5. package/fesm2022/shival99-z-ui-components-z-drawer.mjs +0 -742
  6. package/fesm2022/shival99-z-ui-components-z-drawer.mjs.map +0 -1
  7. package/fesm2022/shival99-z-ui-components-z-dropdown-menu.mjs +0 -58
  8. package/fesm2022/shival99-z-ui-components-z-dropdown-menu.mjs.map +0 -1
  9. package/fesm2022/shival99-z-ui-components-z-editor.mjs +0 -1750
  10. package/fesm2022/shival99-z-ui-components-z-editor.mjs.map +0 -1
  11. package/fesm2022/shival99-z-ui-components-z-gallery.mjs +0 -2419
  12. package/fesm2022/shival99-z-ui-components-z-gallery.mjs.map +0 -1
  13. package/fesm2022/shival99-z-ui-components-z-kanban.mjs +0 -981
  14. package/fesm2022/shival99-z-ui-components-z-kanban.mjs.map +0 -1
  15. package/fesm2022/shival99-z-ui-components-z-marquee.mjs +0 -70
  16. package/fesm2022/shival99-z-ui-components-z-marquee.mjs.map +0 -1
  17. package/fesm2022/shival99-z-ui-components-z-media-player.mjs +0 -668
  18. package/fesm2022/shival99-z-ui-components-z-media-player.mjs.map +0 -1
  19. package/fesm2022/shival99-z-ui-components-z-menu.mjs +0 -843
  20. package/fesm2022/shival99-z-ui-components-z-menu.mjs.map +0 -1
  21. package/fesm2022/shival99-z-ui-components-z-metric-card.mjs +0 -128
  22. package/fesm2022/shival99-z-ui-components-z-metric-card.mjs.map +0 -1
  23. package/fesm2022/shival99-z-ui-components-z-pagination.mjs +0 -158
  24. package/fesm2022/shival99-z-ui-components-z-pagination.mjs.map +0 -1
  25. package/fesm2022/shival99-z-ui-components-z-qrcode.mjs +0 -383
  26. package/fesm2022/shival99-z-ui-components-z-qrcode.mjs.map +0 -1
  27. package/fesm2022/shival99-z-ui-components-z-radio.mjs +0 -167
  28. package/fesm2022/shival99-z-ui-components-z-radio.mjs.map +0 -1
  29. package/fesm2022/shival99-z-ui-components-z-scrollarea.mjs +0 -131
  30. package/fesm2022/shival99-z-ui-components-z-scrollarea.mjs.map +0 -1
  31. package/fesm2022/shival99-z-ui-components-z-show-more.mjs +0 -121
  32. package/fesm2022/shival99-z-ui-components-z-show-more.mjs.map +0 -1
  33. package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs +0 -61
  34. package/fesm2022/shival99-z-ui-components-z-skeleton-auto.mjs.map +0 -1
  35. package/fesm2022/shival99-z-ui-components-z-steps.mjs +0 -396
  36. package/fesm2022/shival99-z-ui-components-z-steps.mjs.map +0 -1
  37. package/fesm2022/shival99-z-ui-components-z-table.mjs +0 -10508
  38. package/fesm2022/shival99-z-ui-components-z-table.mjs.map +0 -1
  39. package/fesm2022/shival99-z-ui-components-z-tabs.mjs +0 -507
  40. package/fesm2022/shival99-z-ui-components-z-tabs.mjs.map +0 -1
  41. package/fesm2022/shival99-z-ui-components-z-tags.mjs +0 -349
  42. package/fesm2022/shival99-z-ui-components-z-tags.mjs.map +0 -1
  43. package/fesm2022/shival99-z-ui-components-z-timeline.mjs +0 -237
  44. package/fesm2022/shival99-z-ui-components-z-timeline.mjs.map +0 -1
  45. package/fesm2022/shival99-z-ui-components-z-upload.mjs +0 -523
  46. package/fesm2022/shival99-z-ui-components-z-upload.mjs.map +0 -1
  47. package/types/shival99-z-ui-components-z-autocomplete.d.ts +0 -290
  48. package/types/shival99-z-ui-components-z-drawer.d.ts +0 -266
  49. package/types/shival99-z-ui-components-z-dropdown-menu.d.ts +0 -54
  50. package/types/shival99-z-ui-components-z-editor.d.ts +0 -337
  51. package/types/shival99-z-ui-components-z-gallery.d.ts +0 -402
  52. package/types/shival99-z-ui-components-z-kanban.d.ts +0 -237
  53. package/types/shival99-z-ui-components-z-marquee.d.ts +0 -35
  54. package/types/shival99-z-ui-components-z-media-player.d.ts +0 -124
  55. package/types/shival99-z-ui-components-z-menu.d.ts +0 -222
  56. package/types/shival99-z-ui-components-z-metric-card.d.ts +0 -67
  57. package/types/shival99-z-ui-components-z-pagination.d.ts +0 -55
  58. package/types/shival99-z-ui-components-z-qrcode.d.ts +0 -76
  59. package/types/shival99-z-ui-components-z-radio.d.ts +0 -69
  60. package/types/shival99-z-ui-components-z-scrollarea.d.ts +0 -46
  61. package/types/shival99-z-ui-components-z-show-more.d.ts +0 -36
  62. package/types/shival99-z-ui-components-z-skeleton-auto.d.ts +0 -35
  63. package/types/shival99-z-ui-components-z-steps.d.ts +0 -106
  64. package/types/shival99-z-ui-components-z-table.d.ts +0 -1924
  65. package/types/shival99-z-ui-components-z-tabs.d.ts +0 -92
  66. package/types/shival99-z-ui-components-z-tags.d.ts +0 -128
  67. package/types/shival99-z-ui-components-z-timeline.d.ts +0 -71
  68. package/types/shival99-z-ui-components-z-upload.d.ts +0 -153
@@ -1,523 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { inject, Injector, DestroyRef, viewChild, output, input, signal, computed, forwardRef, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
3
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
- import { NgControl, NgModel, PristineChangeEvent, TouchedChangeEvent, NG_VALUE_ACCESSOR } from '@angular/forms';
5
- import { TranslatePipe } from '@ngx-translate/core';
6
- import { ZIconComponent } from '@shival99/z-ui/components/z-icon';
7
- import { ZLoadingComponent } from '@shival99/z-ui/components/z-loading';
8
- import { ZTooltipDirective } from '@shival99/z-ui/components/z-tooltip';
9
- import { ZTranslateService } from '@shival99/z-ui/services';
10
- import { zTransform, zUuid, zMergeClasses, zCreateEvent } from '@shival99/z-ui/utils';
11
- import { merge, filter } from 'rxjs';
12
- import { cva } from 'class-variance-authority';
13
-
14
- const formatFileSize = (bytes) => {
15
- if (bytes === 0) {
16
- return '0 B';
17
- }
18
- const units = ['B', 'KB', 'MB', 'GB'];
19
- const k = 1024;
20
- const i = Math.floor(Math.log(bytes) / Math.log(k));
21
- const size = bytes / Math.pow(k, i);
22
- return `${size.toFixed(i > 0 ? 1 : 0)} ${units[i]}`;
23
- };
24
-
25
- const zUploadDropzoneVariants = cva([
26
- 'relative flex flex-col items-center justify-center rounded-sm border-2 border-dashed',
27
- 'transition-[border-color,background-color] duration-200 cursor-pointer',
28
- 'hover:border-primary/50 hover:bg-primary/5',
29
- ], {
30
- variants: {
31
- zSize: {
32
- sm: 'min-h-24 gap-1 p-3',
33
- default: 'min-h-32 gap-2 p-4',
34
- lg: 'min-h-40 gap-3 p-6',
35
- },
36
- zStatus: {
37
- default: 'border-input bg-background',
38
- active: 'border-primary bg-primary/10',
39
- disabled: 'opacity-50 cursor-not-allowed bg-muted border-muted',
40
- readonly: 'opacity-70 cursor-default bg-muted/50 border-muted',
41
- error: 'border-destructive! bg-destructive/5 hover:border-destructive!',
42
- },
43
- },
44
- defaultVariants: {
45
- zSize: 'default',
46
- zStatus: 'default',
47
- },
48
- });
49
- const zUploadFileItemVariants = cva(['relative flex items-center gap-3 rounded-sm border border-input bg-background p-3', 'transition-all duration-200'], {
50
- variants: {
51
- zStatus: {
52
- pending: '',
53
- uploading: '',
54
- success: '',
55
- error: '',
56
- },
57
- },
58
- defaultVariants: {
59
- zStatus: 'pending',
60
- },
61
- });
62
-
63
- class ZUploadComponent {
64
- _injector = inject(Injector);
65
- _destroyRef = inject(DestroyRef);
66
- _zTranslate = inject(ZTranslateService);
67
- fileInputRef = viewChild('fileInput', ...(ngDevMode ? [{ debugName: "fileInputRef" }] : []));
68
- zOnUpload = output();
69
- zOnRemove = output();
70
- zOnDownload = output();
71
- zOnError = output();
72
- zOnFileChange = output();
73
- zOnDragover = output();
74
- zOnDragleave = output();
75
- zOnDrop = output();
76
- zControl = output();
77
- zEvent = output();
78
- class = input('', ...(ngDevMode ? [{ debugName: "class" }] : []));
79
- zLabel = input('', ...(ngDevMode ? [{ debugName: "zLabel" }] : []));
80
- zLabelClass = input('', ...(ngDevMode ? [{ debugName: "zLabelClass" }] : []));
81
- zNote = input('', ...(ngDevMode ? [{ debugName: "zNote" }] : []));
82
- zSize = input('default', ...(ngDevMode ? [{ debugName: "zSize" }] : []));
83
- zAcceptFile = input('*', ...(ngDevMode ? [{ debugName: "zAcceptFile" }] : []));
84
- zMultipleFile = input(false, { ...(ngDevMode ? { debugName: "zMultipleFile" } : {}), transform: zTransform });
85
- zMaxSize = input(10, ...(ngDevMode ? [{ debugName: "zMaxSize" }] : []));
86
- zMaxFiles = input(5, ...(ngDevMode ? [{ debugName: "zMaxFiles" }] : []));
87
- zRequired = input(false, { ...(ngDevMode ? { debugName: "zRequired" } : {}), transform: zTransform });
88
- zDisabled = input(false, { ...(ngDevMode ? { debugName: "zDisabled" } : {}), transform: zTransform });
89
- zReadonly = input(false, { ...(ngDevMode ? { debugName: "zReadonly" } : {}), transform: zTransform });
90
- zLoading = input(false, { ...(ngDevMode ? { debugName: "zLoading" } : {}), transform: zTransform });
91
- zShowProgress = input(true, { ...(ngDevMode ? { debugName: "zShowProgress" } : {}), transform: zTransform });
92
- zValidators = input([], ...(ngDevMode ? [{ debugName: "zValidators" }] : []));
93
- files = signal([], ...(ngDevMode ? [{ debugName: "files" }] : []));
94
- inputId = zUuid('z-upload');
95
- labelId = zUuid('z-upload-label');
96
- isDragOver = signal(false, ...(ngDevMode ? [{ debugName: "isDragOver" }] : []));
97
- uiState = signal({
98
- touched: false,
99
- dirty: false,
100
- }, ...(ngDevMode ? [{ debugName: "uiState" }] : []));
101
- _fileError = signal('', ...(ngDevMode ? [{ debugName: "_fileError" }] : []));
102
- _disabled = signal(false, ...(ngDevMode ? [{ debugName: "_disabled" }] : []));
103
- _formControl = signal(null, ...(ngDevMode ? [{ debugName: "_formControl" }] : []));
104
- _formStateVersion = signal(0, ...(ngDevMode ? [{ debugName: "_formStateVersion" }] : []));
105
- _isNgModel = signal(false, ...(ngDevMode ? [{ debugName: "_isNgModel" }] : []));
106
- _onChange = () => void 0;
107
- _onTouched = () => void 0;
108
- _ngControl = null;
109
- isDisabled = computed(() => this._disabled() || this.zDisabled(), ...(ngDevMode ? [{ debugName: "isDisabled" }] : []));
110
- isBlocked = computed(() => this.isDisabled() || this.zLoading() || this.zReadonly(), ...(ngDevMode ? [{ debugName: "isBlocked" }] : []));
111
- _shouldShowValidation = computed(() => {
112
- const control = this._formControl();
113
- this._formStateVersion();
114
- if (this._isNgModel()) {
115
- return this.uiState().dirty || this.uiState().touched;
116
- }
117
- if (control) {
118
- return control.dirty;
119
- }
120
- return this.uiState().dirty || this.uiState().touched;
121
- }, ...(ngDevMode ? [{ debugName: "_shouldShowValidation" }] : []));
122
- hasError = computed(() => {
123
- if (this._fileError()) {
124
- return true;
125
- }
126
- const customErrors = this._getValidationErrors();
127
- if (customErrors.length > 0) {
128
- return true;
129
- }
130
- const control = this._formControl();
131
- this._formStateVersion();
132
- if (!control) {
133
- return false;
134
- }
135
- return control.invalid && this._shouldShowValidation();
136
- }, ...(ngDevMode ? [{ debugName: "hasError" }] : []));
137
- showError = computed(() => this.hasError() && (this._shouldShowValidation() || !!this._fileError()), ...(ngDevMode ? [{ debugName: "showError" }] : []));
138
- errorMessage = computed(() => {
139
- const fileError = this._fileError();
140
- if (fileError) {
141
- return fileError;
142
- }
143
- const customErrors = this._getValidationErrors();
144
- if (customErrors.length > 0) {
145
- return customErrors[0];
146
- }
147
- const control = this._formControl();
148
- const errors = control?.errors;
149
- if (!errors) {
150
- return '';
151
- }
152
- const validators = this.zValidators();
153
- for (const validator of validators) {
154
- if (errors[validator.error]) {
155
- return validator.message;
156
- }
157
- }
158
- return '';
159
- }, ...(ngDevMode ? [{ debugName: "errorMessage" }] : []));
160
- currentStatus = computed(() => {
161
- if (this.isDisabled()) {
162
- return 'disabled';
163
- }
164
- if (this.zReadonly()) {
165
- return 'readonly';
166
- }
167
- if (this._fileError()) {
168
- return 'error';
169
- }
170
- if (this.hasError() && this._shouldShowValidation()) {
171
- return 'error';
172
- }
173
- if (this.isDragOver()) {
174
- return 'active';
175
- }
176
- return 'default';
177
- }, ...(ngDevMode ? [{ debugName: "currentStatus" }] : []));
178
- dropzoneClasses = computed(() => zMergeClasses(zUploadDropzoneVariants({
179
- zSize: this.zSize(),
180
- zStatus: this.currentStatus(),
181
- }), this.class()), ...(ngDevMode ? [{ debugName: "dropzoneClasses" }] : []));
182
- acceptTypes = computed(() => {
183
- const accept = this.zAcceptFile();
184
- return accept === '*' ? '' : accept;
185
- }, ...(ngDevMode ? [{ debugName: "acceptTypes" }] : []));
186
- formatFileSize = formatFileSize;
187
- getFileItemClasses = (file) => zUploadFileItemVariants({ zStatus: file.status });
188
- ngOnInit() {
189
- queueMicrotask(() => {
190
- try {
191
- this._ngControl = this._injector.get(NgControl, null);
192
- this._isNgModel.set(this._ngControl instanceof NgModel);
193
- if (this._ngControl?.control) {
194
- const { control } = this._ngControl;
195
- this._formControl.set(control);
196
- merge(control.statusChanges, control.valueChanges, control.events.pipe(filter(event => event instanceof PristineChangeEvent || event instanceof TouchedChangeEvent)))
197
- .pipe(takeUntilDestroyed(this._destroyRef))
198
- .subscribe(() => {
199
- this._formStateVersion.update(v => v + 1);
200
- });
201
- }
202
- }
203
- catch {
204
- this._ngControl = null;
205
- }
206
- });
207
- setTimeout(() => this._emitControl());
208
- }
209
- writeValue(value) {
210
- this.files.set(value ?? []);
211
- }
212
- registerOnChange(fn) {
213
- this._onChange = fn;
214
- }
215
- registerOnTouched(fn) {
216
- this._onTouched = fn;
217
- }
218
- setDisabledState(isDisabled) {
219
- this._disabled.set(isDisabled);
220
- }
221
- updateProgress(fileId, progress) {
222
- this.files.update(files => files.map(f => {
223
- if (f.id !== fileId) {
224
- return f;
225
- }
226
- return {
227
- ...f,
228
- progress: Math.min(100, Math.max(0, progress)),
229
- status: progress >= 100 ? 'success' : 'uploading',
230
- };
231
- }));
232
- this._notifyChange();
233
- }
234
- setFileStatus(fileId, status) {
235
- this.files.update(files => files.map(f => {
236
- if (f.id !== fileId) {
237
- return f;
238
- }
239
- return { ...f, status };
240
- }));
241
- this._notifyChange();
242
- }
243
- clearFiles() {
244
- this.files.set([]);
245
- this._notifyChange();
246
- }
247
- /** @deprecated Use `valid()` for boolean form-submit checks. */
248
- validate() {
249
- this.uiState.update(s => ({ ...s, touched: true, dirty: true }));
250
- this._onTouched();
251
- if (this._ngControl?.control) {
252
- this._ngControl.control.markAsDirty();
253
- this._ngControl.control.markAsTouched();
254
- }
255
- return this.hasError();
256
- }
257
- valid() {
258
- return !this.validate();
259
- }
260
- reset() {
261
- this.files.set([]);
262
- this.uiState.update(s => ({ ...s, touched: false, dirty: false }));
263
- this._fileError.set('');
264
- this._onChange([]);
265
- if (this._ngControl?.control) {
266
- this._ngControl.control.markAsPristine();
267
- this._ngControl.control.markAsUntouched();
268
- }
269
- }
270
- markAsTouched() {
271
- this.uiState.update(s => ({ ...s, touched: true }));
272
- this._onTouched();
273
- }
274
- markAsUntouched() {
275
- this.uiState.update(s => ({ ...s, touched: false }));
276
- }
277
- markAsDirty() {
278
- this.uiState.update(s => ({ ...s, dirty: true }));
279
- }
280
- markAsPristine() {
281
- this.uiState.update(s => ({ ...s, dirty: false }));
282
- }
283
- _emitControl() {
284
- this.zControl.emit({
285
- valid: () => this.valid(),
286
- validate: () => this.validate(),
287
- reset: () => this.reset(),
288
- clearFiles: () => this.clearFiles(),
289
- openFileDialog: () => this.openFileDialog(),
290
- markAsTouched: () => this.markAsTouched(),
291
- markAsUntouched: () => this.markAsUntouched(),
292
- markAsDirty: () => this.markAsDirty(),
293
- markAsPristine: () => this.markAsPristine(),
294
- hasError: this.hasError,
295
- files: this.files.asReadonly(),
296
- errorMessage: this.errorMessage,
297
- });
298
- }
299
- getFiles() {
300
- return this.files()
301
- .filter(f => f.file)
302
- .map(f => f.file);
303
- }
304
- openFileDialog() {
305
- if (this.isBlocked()) {
306
- return;
307
- }
308
- this.fileInputRef()?.nativeElement.click();
309
- }
310
- onFileSelected(event) {
311
- const input = event.target;
312
- if (!input.files?.length) {
313
- return;
314
- }
315
- this._processFiles(Array.from(input.files));
316
- input.value = '';
317
- }
318
- onDragOver(event) {
319
- event.preventDefault();
320
- event.stopPropagation();
321
- if (this.isBlocked()) {
322
- return;
323
- }
324
- this.isDragOver.set(true);
325
- this.zOnDragover.emit(event);
326
- this.zEvent.emit(zCreateEvent('dragover', event));
327
- }
328
- onDragLeave(event) {
329
- event.preventDefault();
330
- event.stopPropagation();
331
- this.isDragOver.set(false);
332
- this.zOnDragleave.emit(event);
333
- this.zEvent.emit(zCreateEvent('dragleave', event));
334
- }
335
- onDrop(event) {
336
- event.preventDefault();
337
- event.stopPropagation();
338
- this.isDragOver.set(false);
339
- this.zOnDrop.emit(event);
340
- this.zEvent.emit(zCreateEvent('drop', event));
341
- if (this.isBlocked()) {
342
- return;
343
- }
344
- const droppedFiles = event.dataTransfer?.files;
345
- if (!droppedFiles?.length) {
346
- return;
347
- }
348
- this._processFiles(Array.from(droppedFiles));
349
- }
350
- removeFile(file) {
351
- if (this.zLoading()) {
352
- return;
353
- }
354
- this.files.update(files => files.filter(f => f.id !== file.id));
355
- this._notifyChange();
356
- this._emitFileChange();
357
- this.zOnRemove.emit(file);
358
- }
359
- downloadFile(file) {
360
- if (this.zLoading()) {
361
- return;
362
- }
363
- this.zOnDownload.emit(file);
364
- if (file.url) {
365
- const link = document.createElement('a');
366
- link.href = file.url;
367
- link.download = file.name;
368
- link.target = '_blank';
369
- link.rel = 'noopener noreferrer';
370
- document.body.appendChild(link);
371
- link.click();
372
- document.body.removeChild(link);
373
- return;
374
- }
375
- if (file.file) {
376
- const url = URL.createObjectURL(file.file);
377
- const link = document.createElement('a');
378
- link.href = url;
379
- link.download = file.name;
380
- document.body.appendChild(link);
381
- link.click();
382
- document.body.removeChild(link);
383
- URL.revokeObjectURL(url);
384
- }
385
- }
386
- _getValidationErrors() {
387
- const validators = this.zValidators();
388
- const currentFiles = this.files();
389
- const control = this._formControl();
390
- const errors = [];
391
- const isRequired = this.zRequired() || control?.errors?.['required'];
392
- if (isRequired && currentFiles.length === 0) {
393
- this._zTranslate.currentLang();
394
- errors.push(this._zTranslate.instant('i18n_z_ui_upload_required'));
395
- }
396
- for (const validator of validators) {
397
- if (validator.validate && !validator.validate(currentFiles)) {
398
- errors.push(validator.message);
399
- }
400
- }
401
- return errors;
402
- }
403
- _processFiles(newFiles) {
404
- const maxFiles = this.zMaxFiles();
405
- const maxSize = this.zMaxSize() * 1024 * 1024;
406
- const accept = this.zAcceptFile();
407
- const validFiles = [];
408
- if (!this.zMultipleFile()) {
409
- this.files.set([]);
410
- }
411
- for (const file of newFiles) {
412
- if (!this.zMultipleFile() && validFiles.length > 0) {
413
- break;
414
- }
415
- if (this.zMultipleFile()) {
416
- const currentCount = this.files().length + validFiles.length;
417
- if (currentCount >= maxFiles) {
418
- const errorMsg = this._zTranslate.instant('i18n_z_ui_upload_max_files', { count: maxFiles });
419
- this._fileError.set(errorMsg);
420
- this.zOnError.emit({ file, error: errorMsg });
421
- continue;
422
- }
423
- }
424
- if (file.size > maxSize) {
425
- const errorMsg = this._zTranslate.instant('i18n_z_ui_upload_max_size', { size: this.zMaxSize() + 'MB' });
426
- this._fileError.set(errorMsg);
427
- this.zOnError.emit({ file, error: errorMsg });
428
- continue;
429
- }
430
- if (accept !== '*' && !this._isValidFileType(file, accept)) {
431
- const errorMsg = this._zTranslate.instant('i18n_z_ui_upload_invalid_type');
432
- this._fileError.set(errorMsg);
433
- this.zOnError.emit({ file, error: errorMsg });
434
- continue;
435
- }
436
- validFiles.push({
437
- id: zUuid('file'),
438
- name: file.name,
439
- size: file.size,
440
- type: file.type,
441
- file,
442
- progress: 0,
443
- status: 'pending',
444
- });
445
- }
446
- if (validFiles.length === 0) {
447
- this._notifyChange();
448
- return;
449
- }
450
- this._fileError.set('');
451
- if (!this.zMultipleFile()) {
452
- this.files.set(validFiles.slice(0, 1));
453
- this.uiState.update(s => ({ ...s, touched: true, dirty: true }));
454
- this._onTouched();
455
- this._notifyChange();
456
- this._emitFileChange();
457
- this.zOnUpload.emit(validFiles);
458
- return;
459
- }
460
- this.files.update(files => [...files, ...validFiles]);
461
- this.uiState.update(s => ({ ...s, touched: true, dirty: true }));
462
- this._onTouched();
463
- this._notifyChange();
464
- this._emitFileChange();
465
- this.zOnUpload.emit(validFiles);
466
- }
467
- _emitFileChange() {
468
- const rawFiles = this.getFiles();
469
- this.zOnFileChange.emit(rawFiles);
470
- }
471
- _isValidFileType(file, accept) {
472
- const acceptTypes = accept.split(',').map(t => t.trim().toLowerCase());
473
- for (const type of acceptTypes) {
474
- if (type.startsWith('.')) {
475
- if (file.name.toLowerCase().endsWith(type)) {
476
- return true;
477
- }
478
- continue;
479
- }
480
- if (type.endsWith('/*')) {
481
- const category = type.slice(0, -2);
482
- if (file.type.startsWith(category + '/')) {
483
- return true;
484
- }
485
- continue;
486
- }
487
- if (file.type.toLowerCase() === type) {
488
- return true;
489
- }
490
- }
491
- return false;
492
- }
493
- _notifyChange() {
494
- this._onChange(this.files());
495
- }
496
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZUploadComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
497
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.9", type: ZUploadComponent, isStandalone: true, selector: "z-upload", inputs: { class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, zLabel: { classPropertyName: "zLabel", publicName: "zLabel", isSignal: true, isRequired: false, transformFunction: null }, zLabelClass: { classPropertyName: "zLabelClass", publicName: "zLabelClass", isSignal: true, isRequired: false, transformFunction: null }, zNote: { classPropertyName: "zNote", publicName: "zNote", isSignal: true, isRequired: false, transformFunction: null }, zSize: { classPropertyName: "zSize", publicName: "zSize", isSignal: true, isRequired: false, transformFunction: null }, zAcceptFile: { classPropertyName: "zAcceptFile", publicName: "zAcceptFile", isSignal: true, isRequired: false, transformFunction: null }, zMultipleFile: { classPropertyName: "zMultipleFile", publicName: "zMultipleFile", isSignal: true, isRequired: false, transformFunction: null }, zMaxSize: { classPropertyName: "zMaxSize", publicName: "zMaxSize", isSignal: true, isRequired: false, transformFunction: null }, zMaxFiles: { classPropertyName: "zMaxFiles", publicName: "zMaxFiles", isSignal: true, isRequired: false, transformFunction: null }, zRequired: { classPropertyName: "zRequired", publicName: "zRequired", isSignal: true, isRequired: false, transformFunction: null }, zDisabled: { classPropertyName: "zDisabled", publicName: "zDisabled", isSignal: true, isRequired: false, transformFunction: null }, zReadonly: { classPropertyName: "zReadonly", publicName: "zReadonly", isSignal: true, isRequired: false, transformFunction: null }, zLoading: { classPropertyName: "zLoading", publicName: "zLoading", isSignal: true, isRequired: false, transformFunction: null }, zShowProgress: { classPropertyName: "zShowProgress", publicName: "zShowProgress", isSignal: true, isRequired: false, transformFunction: null }, zValidators: { classPropertyName: "zValidators", publicName: "zValidators", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { zOnUpload: "zOnUpload", zOnRemove: "zOnRemove", zOnDownload: "zOnDownload", zOnError: "zOnError", zOnFileChange: "zOnFileChange", zOnDragover: "zOnDragover", zOnDragleave: "zOnDragleave", zOnDrop: "zOnDrop", zControl: "zControl", zEvent: "zEvent" }, providers: [
498
- {
499
- provide: NG_VALUE_ACCESSOR,
500
- useExisting: forwardRef(() => ZUploadComponent),
501
- multi: true,
502
- },
503
- TranslatePipe,
504
- ], viewQueries: [{ propertyName: "fileInputRef", first: true, predicate: ["fileInput"], descendants: true, isSignal: true }], exportAs: ["zUpload"], ngImport: i0, template: "<div class=\"z-upload-wrapper flex w-full flex-col gap-2\">\n @if (zLabel()) {\n <label [id]=\"labelId\" class=\"text-xs leading-none font-medium\" [class]=\"zLabelClass()\">\n {{ zLabel() }}\n @if (zRequired()) {\n <span class=\"text-destructive! ml-0.5\">*</span>\n }\n </label>\n }\n\n <div\n class=\"z-upload-dropzone\"\n [class]=\"dropzoneClasses()\"\n (click)=\"openFileDialog()\"\n (dragover)=\"onDragOver($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (drop)=\"onDrop($event)\">\n @if (zLoading()) {\n <div class=\"bg-background/80 absolute inset-0 z-10 flex items-center justify-center rounded-sm\">\n <svg\n class=\"text-primary size-6 animate-spin\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\">\n <path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />\n </svg>\n </div>\n }\n\n <svg\n class=\"text-muted-foreground\"\n [class.size-5]=\"zSize() === 'sm'\"\n [class.size-6]=\"zSize() === 'default'\"\n [class.size-8]=\"zSize() === 'lg'\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\">\n @if (isDragOver()) {\n <path d=\"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242\" />\n <path d=\"M12 12v9\" />\n <path d=\"m16 16-4-4-4 4\" />\n } @else {\n <path d=\"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4\" />\n <polyline points=\"17 8 12 3 7 8\" />\n <line x1=\"12\" x2=\"12\" y1=\"3\" y2=\"15\" />\n }\n </svg>\n\n <div class=\"text-center\">\n <p class=\"text-muted-foreground m-0 text-sm\">\n @if (isDragOver()) {\n {{ 'i18n_z_ui_upload_drop_here' | translate }}\n } @else {\n {{ 'i18n_z_ui_upload_drag_drop' | translate }}\n {{ 'i18n_z_ui_upload_or' | translate }}\n <span class=\"text-primary cursor-pointer font-medium\">{{ 'i18n_z_ui_upload_browse' | translate }}</span>\n }\n </p>\n\n @if (zNote() || zAcceptFile() !== '*') {\n <div class=\"text-muted-foreground/70 mt-2 flex flex-col gap-0.5 text-xs\">\n @if (zNote()) {\n <span>{{ zNote() }}</span>\n }\n @if (zAcceptFile() !== '*') {\n <span>{{ 'i18n_z_ui_upload_accepted' | translate }}: {{ zAcceptFile() }}</span>\n }\n </div>\n }\n </div>\n\n <input\n #fileInput\n type=\"file\"\n class=\"hidden\"\n [id]=\"inputId\"\n [accept]=\"acceptTypes()\"\n [multiple]=\"zMultipleFile()\"\n [disabled]=\"isBlocked()\"\n [attr.aria-labelledby]=\"zLabel() ? labelId : null\"\n (change)=\"onFileSelected($event)\" />\n </div>\n\n @if (showError()) {\n <p class=\"text-destructive animate-in fade-in slide-in-from-top-1 m-0 text-xs duration-200\">\n {{ errorMessage() }}\n </p>\n }\n\n @if (files().length > 0) {\n <div class=\"z-upload-file-list flex flex-col gap-1.5\">\n @for (file of files(); track file.id) {\n <div [class]=\"getFileItemClasses(file)\" class=\"relative overflow-hidden p-2!\">\n <!-- Progress border at bottom -->\n @if (zShowProgress() && file.status === 'uploading') {\n <div\n class=\"bg-primary absolute bottom-0 left-0 h-0.5 transition-all duration-300\"\n [style.width.%]=\"file.progress\"></div>\n }\n\n <div class=\"bg-muted relative flex size-8 shrink-0 items-center justify-center self-start rounded-sm\">\n <z-icon zType=\"lucideFile\" zSize=\"16\" class=\"text-muted-foreground\" />\n </div>\n\n <div class=\"flex min-w-0 flex-1 flex-col\">\n <div class=\"flex items-center gap-1.5\">\n <span class=\"line-clamp-2 text-xs font-medium\" z-tooltip [zContent]=\"file.name\" [zAlwaysShow]=\"false\">\n {{ file.name }}\n </span>\n\n @if (file.status === 'uploading') {\n <z-loading zSize=\"2xs\" class=\"shrink-0\" [zLoading]=\"true\" />\n @if (zShowProgress() && file.progress > 0) {\n <span class=\"text-primary shrink-0 text-[0.625rem] font-medium\">{{ file.progress }}%</span>\n }\n }\n @if (file.status === 'success') {\n <z-icon zType=\"lucideCheckCircle\" zSize=\"14\" class=\"shrink-0 text-green-500\" />\n }\n @if (file.status === 'error') {\n <z-icon zType=\"lucideXCircle\" zSize=\"14\" class=\"text-destructive shrink-0\" />\n }\n </div>\n\n <span class=\"text-muted-foreground mt-0.5 text-[0.625rem]\">\n {{ formatFileSize(file.size) }}\n </span>\n </div>\n\n <div class=\"flex shrink-0 items-center gap-0.5\">\n @if (file.url || file.file) {\n <button\n type=\"button\"\n class=\"group hover:bg-accent flex size-6 cursor-pointer items-center justify-center rounded-sm transition-colors\"\n [class.pointer-events-none]=\"zLoading()\"\n [class.opacity-50]=\"zLoading()\"\n (click)=\"downloadFile(file); $event.stopPropagation()\">\n <z-icon zType=\"lucideDownload\" zSize=\"14\" class=\"text-muted-foreground\" />\n </button>\n }\n\n @if (!zReadonly()) {\n <button\n type=\"button\"\n class=\"hover:bg-destructive/10 flex size-6 cursor-pointer items-center justify-center rounded-sm transition-colors\"\n [class.pointer-events-none]=\"zLoading()\"\n [class.opacity-50]=\"zLoading()\"\n (click)=\"removeFile(file); $event.stopPropagation()\">\n <z-icon zType=\"lucideX\" zSize=\"14\" class=\"text-destructive\" />\n </button>\n }\n </div>\n </div>\n }\n </div>\n }\n</div>\n", styles: [".z-upload-wrapper .z-upload-dropzone:focus-visible{outline:2px solid var(--color-ring);outline-offset:2px}.z-upload-wrapper .z-upload-progress-bar .z-upload-progress-fill{transition:width .3s ease-out}.z-upload-wrapper .z-upload-file-list{animation:z-upload-slide-in .2s ease-out}@keyframes z-upload-slide-in{0%{opacity:0;transform:translateY(-.25rem)}to{opacity:1;transform:translateY(0)}}\n"], dependencies: [{ kind: "component", type: ZIconComponent, selector: "z-icon, [z-icon]", inputs: ["class", "zType", "zAnimatedType", "zAnimate", "zAnimationTrigger", "zSize", "zStrokeWidth", "zSvg"] }, { kind: "component", type: ZLoadingComponent, selector: "z-loading", inputs: ["class", "zSpinner", "zSize", "zColor", "zText", "zOverlay", "zOverlayType", "zFullscreen", "zLoading"] }, { kind: "directive", type: ZTooltipDirective, selector: "[z-tooltip], [zTooltip]", inputs: ["zContent", "zPosition", "zTooltipPosition", "zTrigger", "zTooltipTrigger", "zTooltipType", "zTooltipSize", "zClass", "zTooltipClass", "zShowDelay", "zTooltipShowDelay", "zHideDelay", "zTooltipHideDelay", "zArrow", "zTooltipArrow", "zDisabled", "zTooltipDisabled", "zOffset", "zTooltipOffset", "zAutoDetect", "zTriggerElement", "zAlwaysShow", "zMaxWidth"], outputs: ["zShow", "zHide"], exportAs: ["zTooltip"] }, { kind: "pipe", type: TranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
505
- }
506
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZUploadComponent, decorators: [{
507
- type: Component,
508
- args: [{ selector: 'z-upload', imports: [ZIconComponent, ZLoadingComponent, ZTooltipDirective, TranslatePipe], standalone: true, providers: [
509
- {
510
- provide: NG_VALUE_ACCESSOR,
511
- useExisting: forwardRef(() => ZUploadComponent),
512
- multi: true,
513
- },
514
- TranslatePipe,
515
- ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, exportAs: 'zUpload', template: "<div class=\"z-upload-wrapper flex w-full flex-col gap-2\">\n @if (zLabel()) {\n <label [id]=\"labelId\" class=\"text-xs leading-none font-medium\" [class]=\"zLabelClass()\">\n {{ zLabel() }}\n @if (zRequired()) {\n <span class=\"text-destructive! ml-0.5\">*</span>\n }\n </label>\n }\n\n <div\n class=\"z-upload-dropzone\"\n [class]=\"dropzoneClasses()\"\n (click)=\"openFileDialog()\"\n (dragover)=\"onDragOver($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (drop)=\"onDrop($event)\">\n @if (zLoading()) {\n <div class=\"bg-background/80 absolute inset-0 z-10 flex items-center justify-center rounded-sm\">\n <svg\n class=\"text-primary size-6 animate-spin\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\">\n <path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />\n </svg>\n </div>\n }\n\n <svg\n class=\"text-muted-foreground\"\n [class.size-5]=\"zSize() === 'sm'\"\n [class.size-6]=\"zSize() === 'default'\"\n [class.size-8]=\"zSize() === 'lg'\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\">\n @if (isDragOver()) {\n <path d=\"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242\" />\n <path d=\"M12 12v9\" />\n <path d=\"m16 16-4-4-4 4\" />\n } @else {\n <path d=\"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4\" />\n <polyline points=\"17 8 12 3 7 8\" />\n <line x1=\"12\" x2=\"12\" y1=\"3\" y2=\"15\" />\n }\n </svg>\n\n <div class=\"text-center\">\n <p class=\"text-muted-foreground m-0 text-sm\">\n @if (isDragOver()) {\n {{ 'i18n_z_ui_upload_drop_here' | translate }}\n } @else {\n {{ 'i18n_z_ui_upload_drag_drop' | translate }}\n {{ 'i18n_z_ui_upload_or' | translate }}\n <span class=\"text-primary cursor-pointer font-medium\">{{ 'i18n_z_ui_upload_browse' | translate }}</span>\n }\n </p>\n\n @if (zNote() || zAcceptFile() !== '*') {\n <div class=\"text-muted-foreground/70 mt-2 flex flex-col gap-0.5 text-xs\">\n @if (zNote()) {\n <span>{{ zNote() }}</span>\n }\n @if (zAcceptFile() !== '*') {\n <span>{{ 'i18n_z_ui_upload_accepted' | translate }}: {{ zAcceptFile() }}</span>\n }\n </div>\n }\n </div>\n\n <input\n #fileInput\n type=\"file\"\n class=\"hidden\"\n [id]=\"inputId\"\n [accept]=\"acceptTypes()\"\n [multiple]=\"zMultipleFile()\"\n [disabled]=\"isBlocked()\"\n [attr.aria-labelledby]=\"zLabel() ? labelId : null\"\n (change)=\"onFileSelected($event)\" />\n </div>\n\n @if (showError()) {\n <p class=\"text-destructive animate-in fade-in slide-in-from-top-1 m-0 text-xs duration-200\">\n {{ errorMessage() }}\n </p>\n }\n\n @if (files().length > 0) {\n <div class=\"z-upload-file-list flex flex-col gap-1.5\">\n @for (file of files(); track file.id) {\n <div [class]=\"getFileItemClasses(file)\" class=\"relative overflow-hidden p-2!\">\n <!-- Progress border at bottom -->\n @if (zShowProgress() && file.status === 'uploading') {\n <div\n class=\"bg-primary absolute bottom-0 left-0 h-0.5 transition-all duration-300\"\n [style.width.%]=\"file.progress\"></div>\n }\n\n <div class=\"bg-muted relative flex size-8 shrink-0 items-center justify-center self-start rounded-sm\">\n <z-icon zType=\"lucideFile\" zSize=\"16\" class=\"text-muted-foreground\" />\n </div>\n\n <div class=\"flex min-w-0 flex-1 flex-col\">\n <div class=\"flex items-center gap-1.5\">\n <span class=\"line-clamp-2 text-xs font-medium\" z-tooltip [zContent]=\"file.name\" [zAlwaysShow]=\"false\">\n {{ file.name }}\n </span>\n\n @if (file.status === 'uploading') {\n <z-loading zSize=\"2xs\" class=\"shrink-0\" [zLoading]=\"true\" />\n @if (zShowProgress() && file.progress > 0) {\n <span class=\"text-primary shrink-0 text-[0.625rem] font-medium\">{{ file.progress }}%</span>\n }\n }\n @if (file.status === 'success') {\n <z-icon zType=\"lucideCheckCircle\" zSize=\"14\" class=\"shrink-0 text-green-500\" />\n }\n @if (file.status === 'error') {\n <z-icon zType=\"lucideXCircle\" zSize=\"14\" class=\"text-destructive shrink-0\" />\n }\n </div>\n\n <span class=\"text-muted-foreground mt-0.5 text-[0.625rem]\">\n {{ formatFileSize(file.size) }}\n </span>\n </div>\n\n <div class=\"flex shrink-0 items-center gap-0.5\">\n @if (file.url || file.file) {\n <button\n type=\"button\"\n class=\"group hover:bg-accent flex size-6 cursor-pointer items-center justify-center rounded-sm transition-colors\"\n [class.pointer-events-none]=\"zLoading()\"\n [class.opacity-50]=\"zLoading()\"\n (click)=\"downloadFile(file); $event.stopPropagation()\">\n <z-icon zType=\"lucideDownload\" zSize=\"14\" class=\"text-muted-foreground\" />\n </button>\n }\n\n @if (!zReadonly()) {\n <button\n type=\"button\"\n class=\"hover:bg-destructive/10 flex size-6 cursor-pointer items-center justify-center rounded-sm transition-colors\"\n [class.pointer-events-none]=\"zLoading()\"\n [class.opacity-50]=\"zLoading()\"\n (click)=\"removeFile(file); $event.stopPropagation()\">\n <z-icon zType=\"lucideX\" zSize=\"14\" class=\"text-destructive\" />\n </button>\n }\n </div>\n </div>\n }\n </div>\n }\n</div>\n", styles: [".z-upload-wrapper .z-upload-dropzone:focus-visible{outline:2px solid var(--color-ring);outline-offset:2px}.z-upload-wrapper .z-upload-progress-bar .z-upload-progress-fill{transition:width .3s ease-out}.z-upload-wrapper .z-upload-file-list{animation:z-upload-slide-in .2s ease-out}@keyframes z-upload-slide-in{0%{opacity:0;transform:translateY(-.25rem)}to{opacity:1;transform:translateY(0)}}\n"] }]
516
- }], propDecorators: { fileInputRef: [{ type: i0.ViewChild, args: ['fileInput', { isSignal: true }] }], zOnUpload: [{ type: i0.Output, args: ["zOnUpload"] }], zOnRemove: [{ type: i0.Output, args: ["zOnRemove"] }], zOnDownload: [{ type: i0.Output, args: ["zOnDownload"] }], zOnError: [{ type: i0.Output, args: ["zOnError"] }], zOnFileChange: [{ type: i0.Output, args: ["zOnFileChange"] }], zOnDragover: [{ type: i0.Output, args: ["zOnDragover"] }], zOnDragleave: [{ type: i0.Output, args: ["zOnDragleave"] }], zOnDrop: [{ type: i0.Output, args: ["zOnDrop"] }], zControl: [{ type: i0.Output, args: ["zControl"] }], zEvent: [{ type: i0.Output, args: ["zEvent"] }], class: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], zLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLabel", required: false }] }], zLabelClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLabelClass", required: false }] }], zNote: [{ type: i0.Input, args: [{ isSignal: true, alias: "zNote", required: false }] }], zSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "zSize", required: false }] }], zAcceptFile: [{ type: i0.Input, args: [{ isSignal: true, alias: "zAcceptFile", required: false }] }], zMultipleFile: [{ type: i0.Input, args: [{ isSignal: true, alias: "zMultipleFile", required: false }] }], zMaxSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "zMaxSize", required: false }] }], zMaxFiles: [{ type: i0.Input, args: [{ isSignal: true, alias: "zMaxFiles", required: false }] }], zRequired: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRequired", required: false }] }], zDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "zDisabled", required: false }] }], zReadonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "zReadonly", required: false }] }], zLoading: [{ type: i0.Input, args: [{ isSignal: true, alias: "zLoading", required: false }] }], zShowProgress: [{ type: i0.Input, args: [{ isSignal: true, alias: "zShowProgress", required: false }] }], zValidators: [{ type: i0.Input, args: [{ isSignal: true, alias: "zValidators", required: false }] }] } });
517
-
518
- /**
519
- * Generated bundle index. Do not edit.
520
- */
521
-
522
- export { ZUploadComponent, formatFileSize, zUploadDropzoneVariants, zUploadFileItemVariants };
523
- //# sourceMappingURL=shival99-z-ui-components-z-upload.mjs.map