@4sh/ui-kit 0.1.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/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +229 -0
- package/fesm2022/4sh-ui-kit-forms.mjs +501 -0
- package/fesm2022/4sh-ui-kit-forms.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-motion.mjs +155 -0
- package/fesm2022/4sh-ui-kit-motion.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-overlay.mjs +61 -0
- package/fesm2022/4sh-ui-kit-overlay.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-theming.mjs +120 -0
- package/fesm2022/4sh-ui-kit-theming.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-types.mjs +12 -0
- package/fesm2022/4sh-ui-kit-types.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-accordion.mjs +244 -0
- package/fesm2022/4sh-ui-kit-ui-accordion.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-alert.mjs +160 -0
- package/fesm2022/4sh-ui-kit-ui-alert.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-autocomplete.mjs +926 -0
- package/fesm2022/4sh-ui-kit-ui-autocomplete.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-avatar-group.mjs +34 -0
- package/fesm2022/4sh-ui-kit-ui-avatar-group.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-avatar.mjs +122 -0
- package/fesm2022/4sh-ui-kit-ui-avatar.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-badge.mjs +95 -0
- package/fesm2022/4sh-ui-kit-ui-badge.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-breadcrumb.mjs +190 -0
- package/fesm2022/4sh-ui-kit-ui-breadcrumb.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-button-split.mjs +151 -0
- package/fesm2022/4sh-ui-kit-ui-button-split.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-button.mjs +222 -0
- package/fesm2022/4sh-ui-kit-ui-button.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-card.mjs +164 -0
- package/fesm2022/4sh-ui-kit-ui-card.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-checkbox.mjs +118 -0
- package/fesm2022/4sh-ui-kit-ui-checkbox.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-chip.mjs +205 -0
- package/fesm2022/4sh-ui-kit-ui-chip.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-context-menu.mjs +219 -0
- package/fesm2022/4sh-ui-kit-ui-context-menu.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-datepicker.mjs +1508 -0
- package/fesm2022/4sh-ui-kit-ui-datepicker.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-drawer.mjs +300 -0
- package/fesm2022/4sh-ui-kit-ui-drawer.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-empty-state.mjs +148 -0
- package/fesm2022/4sh-ui-kit-ui-empty-state.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-field.mjs +102 -0
- package/fesm2022/4sh-ui-kit-ui-field.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-file-upload.mjs +568 -0
- package/fesm2022/4sh-ui-kit-ui-file-upload.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-helper.mjs +85 -0
- package/fesm2022/4sh-ui-kit-ui-helper.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-icon.mjs +98 -0
- package/fesm2022/4sh-ui-kit-ui-icon.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-image.mjs +201 -0
- package/fesm2022/4sh-ui-kit-ui-image.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-group.mjs +119 -0
- package/fesm2022/4sh-ui-kit-ui-input-group.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-mask.mjs +125 -0
- package/fesm2022/4sh-ui-kit-ui-input-mask.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-number.mjs +234 -0
- package/fesm2022/4sh-ui-kit-ui-input-number.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-otp.mjs +288 -0
- package/fesm2022/4sh-ui-kit-ui-input-otp.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-tags.mjs +679 -0
- package/fesm2022/4sh-ui-kit-ui-input-tags.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input.mjs +121 -0
- package/fesm2022/4sh-ui-kit-ui-input.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-label.mjs +61 -0
- package/fesm2022/4sh-ui-kit-ui-label.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-link.mjs +147 -0
- package/fesm2022/4sh-ui-kit-ui-link.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-menu.mjs +484 -0
- package/fesm2022/4sh-ui-kit-ui-menu.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-modal.mjs +555 -0
- package/fesm2022/4sh-ui-kit-ui-modal.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-nudger.mjs +168 -0
- package/fesm2022/4sh-ui-kit-ui-nudger.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-paginator.mjs +245 -0
- package/fesm2022/4sh-ui-kit-ui-paginator.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-popover.mjs +296 -0
- package/fesm2022/4sh-ui-kit-ui-popover.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-progress-bar.mjs +124 -0
- package/fesm2022/4sh-ui-kit-ui-progress-bar.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-radio.mjs +92 -0
- package/fesm2022/4sh-ui-kit-ui-radio.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-rating.mjs +185 -0
- package/fesm2022/4sh-ui-kit-ui-rating.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-read-only.mjs +146 -0
- package/fesm2022/4sh-ui-kit-ui-read-only.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-segment-control.mjs +386 -0
- package/fesm2022/4sh-ui-kit-ui-segment-control.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-select.mjs +868 -0
- package/fesm2022/4sh-ui-kit-ui-select.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-separator.mjs +77 -0
- package/fesm2022/4sh-ui-kit-ui-separator.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-sidebar.mjs +577 -0
- package/fesm2022/4sh-ui-kit-ui-sidebar.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-skeleton.mjs +81 -0
- package/fesm2022/4sh-ui-kit-ui-skeleton.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-slider.mjs +340 -0
- package/fesm2022/4sh-ui-kit-ui-slider.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-spinner.mjs +132 -0
- package/fesm2022/4sh-ui-kit-ui-spinner.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-stepper.mjs +389 -0
- package/fesm2022/4sh-ui-kit-ui-stepper.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-table.mjs +1406 -0
- package/fesm2022/4sh-ui-kit-ui-table.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-tabs.mjs +503 -0
- package/fesm2022/4sh-ui-kit-ui-tabs.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-tag.mjs +84 -0
- package/fesm2022/4sh-ui-kit-ui-tag.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-textarea.mjs +119 -0
- package/fesm2022/4sh-ui-kit-ui-textarea.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-toast.mjs +424 -0
- package/fesm2022/4sh-ui-kit-ui-toast.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-toggle.mjs +120 -0
- package/fesm2022/4sh-ui-kit-ui-toggle.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-tooltip.mjs +445 -0
- package/fesm2022/4sh-ui-kit-ui-tooltip.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit.mjs +16 -0
- package/fesm2022/4sh-ui-kit.mjs.map +1 -0
- package/package.json +287 -0
- package/styles/base/_base.scss +19 -0
- package/styles/base/_motion.scss +144 -0
- package/styles/base/_typography.scss +99 -0
- package/styles/generated/_tokens-breakpoint.scss +8 -0
- package/styles/generated/_tokens-metrics.scss +37 -0
- package/styles/generated/_tokens-primitives.scss +284 -0
- package/styles/generated/_tokens-responsive.scss +99 -0
- package/styles/generated/_tokens-semantics.scss +1274 -0
- package/styles/generated/_tokens-styles.scss +35 -0
- package/styles/generated/_tokens-transitions.scss +11 -0
- package/styles/generated/_tokens-typography.scss +14 -0
- package/styles/generated/_tokens.scss +10 -0
- package/styles/index.scss +25 -0
- package/styles/settings/_ui-config.scss +67 -0
- package/styles/utils/_functions.scss +67 -0
- package/styles/utils/_helpers.scss +129 -0
- package/styles/utils/_mixins.scss +186 -0
- package/styles/utils/_motion.scss +47 -0
- package/styles/utils/_overlay.scss +26 -0
- package/styles/utils.scss +15 -0
- package/styles.css +1 -0
- package/types/4sh-ui-kit-forms.d.ts +259 -0
- package/types/4sh-ui-kit-motion.d.ts +111 -0
- package/types/4sh-ui-kit-overlay.d.ts +31 -0
- package/types/4sh-ui-kit-theming.d.ts +54 -0
- package/types/4sh-ui-kit-types.d.ts +13 -0
- package/types/4sh-ui-kit-ui-accordion.d.ts +140 -0
- package/types/4sh-ui-kit-ui-alert.d.ts +89 -0
- package/types/4sh-ui-kit-ui-autocomplete.d.ts +411 -0
- package/types/4sh-ui-kit-ui-avatar-group.d.ts +17 -0
- package/types/4sh-ui-kit-ui-avatar.d.ts +55 -0
- package/types/4sh-ui-kit-ui-badge.d.ts +38 -0
- package/types/4sh-ui-kit-ui-breadcrumb.d.ts +131 -0
- package/types/4sh-ui-kit-ui-button-split.d.ts +102 -0
- package/types/4sh-ui-kit-ui-button.d.ts +91 -0
- package/types/4sh-ui-kit-ui-card.d.ts +102 -0
- package/types/4sh-ui-kit-ui-checkbox.d.ts +54 -0
- package/types/4sh-ui-kit-ui-chip.d.ts +114 -0
- package/types/4sh-ui-kit-ui-context-menu.d.ts +105 -0
- package/types/4sh-ui-kit-ui-datepicker.d.ts +539 -0
- package/types/4sh-ui-kit-ui-drawer.d.ts +147 -0
- package/types/4sh-ui-kit-ui-empty-state.d.ts +93 -0
- package/types/4sh-ui-kit-ui-field.d.ts +53 -0
- package/types/4sh-ui-kit-ui-file-upload.d.ts +268 -0
- package/types/4sh-ui-kit-ui-helper.d.ts +46 -0
- package/types/4sh-ui-kit-ui-icon.d.ts +69 -0
- package/types/4sh-ui-kit-ui-image.d.ts +88 -0
- package/types/4sh-ui-kit-ui-input-group.d.ts +54 -0
- package/types/4sh-ui-kit-ui-input-mask.d.ts +63 -0
- package/types/4sh-ui-kit-ui-input-number.d.ts +96 -0
- package/types/4sh-ui-kit-ui-input-otp.d.ts +130 -0
- package/types/4sh-ui-kit-ui-input-tags.d.ts +350 -0
- package/types/4sh-ui-kit-ui-input.d.ts +78 -0
- package/types/4sh-ui-kit-ui-label.d.ts +36 -0
- package/types/4sh-ui-kit-ui-link.d.ts +72 -0
- package/types/4sh-ui-kit-ui-menu.d.ts +235 -0
- package/types/4sh-ui-kit-ui-modal.d.ts +241 -0
- package/types/4sh-ui-kit-ui-nudger.d.ts +79 -0
- package/types/4sh-ui-kit-ui-paginator.d.ts +150 -0
- package/types/4sh-ui-kit-ui-popover.d.ts +125 -0
- package/types/4sh-ui-kit-ui-progress-bar.d.ts +82 -0
- package/types/4sh-ui-kit-ui-radio.d.ts +44 -0
- package/types/4sh-ui-kit-ui-rating.d.ts +90 -0
- package/types/4sh-ui-kit-ui-read-only.d.ts +70 -0
- package/types/4sh-ui-kit-ui-segment-control.d.ts +184 -0
- package/types/4sh-ui-kit-ui-select.d.ts +392 -0
- package/types/4sh-ui-kit-ui-separator.d.ts +43 -0
- package/types/4sh-ui-kit-ui-sidebar.d.ts +358 -0
- package/types/4sh-ui-kit-ui-skeleton.d.ts +52 -0
- package/types/4sh-ui-kit-ui-slider.d.ts +127 -0
- package/types/4sh-ui-kit-ui-spinner.d.ts +67 -0
- package/types/4sh-ui-kit-ui-stepper.d.ts +220 -0
- package/types/4sh-ui-kit-ui-table.d.ts +570 -0
- package/types/4sh-ui-kit-ui-tabs.d.ts +225 -0
- package/types/4sh-ui-kit-ui-tag.d.ts +46 -0
- package/types/4sh-ui-kit-ui-textarea.d.ts +61 -0
- package/types/4sh-ui-kit-ui-toast.d.ts +247 -0
- package/types/4sh-ui-kit-ui-toggle.d.ts +67 -0
- package/types/4sh-ui-kit-ui-tooltip.d.ts +167 -0
- package/types/4sh-ui-kit.d.ts +4 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, booleanAttribute, output, computed, Component, numberAttribute, inject, ElementRef, DestroyRef, viewChild, signal, isDevMode, effect } from '@angular/core';
|
|
3
|
+
import { UiIcon } from '@4sh/ui-kit/ui-icon';
|
|
4
|
+
import { UiSpinner } from '@4sh/ui-kit/ui-spinner';
|
|
5
|
+
import { formatLabel } from '@4sh/ui-kit/forms';
|
|
6
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
7
|
+
import { UiButton } from '@4sh/ui-kit/ui-button';
|
|
8
|
+
import { UiLink } from '@4sh/ui-kit/ui-link';
|
|
9
|
+
|
|
10
|
+
// =====================================================================
|
|
11
|
+
// Shared model for ui-file-upload and its file-row (ui-file-upload-list).
|
|
12
|
+
// =====================================================================
|
|
13
|
+
/** Human-readable file size (e.g. "2.5 MB"). Base-1024. */
|
|
14
|
+
function formatFileSize(bytes) {
|
|
15
|
+
if (!bytes || bytes < 0)
|
|
16
|
+
return '0 B';
|
|
17
|
+
const k = 1024;
|
|
18
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
19
|
+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), units.length - 1);
|
|
20
|
+
const value = bytes / Math.pow(k, i);
|
|
21
|
+
const rounded = Math.round(value * 10) / 10;
|
|
22
|
+
return `${rounded} ${units[i]}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether a File matches an `accept` string (e.g. "image/*,.pdf").
|
|
26
|
+
* Empty/absent accept means everything is allowed.
|
|
27
|
+
*/
|
|
28
|
+
function isFileTypeAccepted(file, accept) {
|
|
29
|
+
if (!accept)
|
|
30
|
+
return true;
|
|
31
|
+
const patterns = accept
|
|
32
|
+
.split(',')
|
|
33
|
+
.map((t) => t.trim().toLowerCase())
|
|
34
|
+
.filter(Boolean);
|
|
35
|
+
if (!patterns.length)
|
|
36
|
+
return true;
|
|
37
|
+
const name = file.name.toLowerCase();
|
|
38
|
+
const mime = (file.type || '').toLowerCase();
|
|
39
|
+
return patterns.some((pattern) => {
|
|
40
|
+
if (pattern.startsWith('.'))
|
|
41
|
+
return name.endsWith(pattern); // extension
|
|
42
|
+
if (pattern.endsWith('/*'))
|
|
43
|
+
return mime.startsWith(pattern.slice(0, -1)); // "image/"
|
|
44
|
+
return mime === pattern; // exact mime
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Whether a File is a previewable image. */
|
|
48
|
+
function isImageFile(file) {
|
|
49
|
+
return /^image\//.test(file.type);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* ui-file-upload-list — a single file row (the repeatable unit of an upload list).
|
|
54
|
+
*
|
|
55
|
+
* Presentational: shows a leading thumbnail (for images) or file icon, the file
|
|
56
|
+
* name + size/status, and a remove button. While the file is uploading it swaps
|
|
57
|
+
* the leading icon for a `ui-spinner` and reveals a slim progress bar.
|
|
58
|
+
*
|
|
59
|
+
* Named to mirror the Figma component; the uploader stacks one row per file.
|
|
60
|
+
*/
|
|
61
|
+
class UiFileUploadList {
|
|
62
|
+
constructor() {
|
|
63
|
+
/** The file to display (name/size/status/progress/preview). */
|
|
64
|
+
this.file = input.required(/* @ts-ignore */
|
|
65
|
+
...(ngDevMode ? [{ debugName: "file" }] : /* istanbul ignore next */ []));
|
|
66
|
+
this.size = input('default', /* @ts-ignore */
|
|
67
|
+
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
68
|
+
/** FontAwesome icon for non-image files. */
|
|
69
|
+
this.icon = input('file', /* @ts-ignore */
|
|
70
|
+
...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
71
|
+
/** Whether the remove button is shown. */
|
|
72
|
+
this.removable = input(true, { ...(ngDevMode ? { debugName: "removable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
73
|
+
/** Accessible name of the remove button (raw text — the file name is appended in the template). */
|
|
74
|
+
this.removeAriaLabel = input('Supprimer le fichier', /* @ts-ignore */
|
|
75
|
+
...(ngDevMode ? [{ debugName: "removeAriaLabel" }] : /* istanbul ignore next */ []));
|
|
76
|
+
/** Fallback error text when the file carries no message. */
|
|
77
|
+
this.failedLabel = input('Échec', /* @ts-ignore */
|
|
78
|
+
...(ngDevMode ? [{ debugName: "failedLabel" }] : /* istanbul ignore next */ []));
|
|
79
|
+
/** Accessible name of the upload spinner — `{0}` is the file name. */
|
|
80
|
+
this.uploadingLabel = input('Téléversement de {0}', /* @ts-ignore */
|
|
81
|
+
...(ngDevMode ? [{ debugName: "uploadingLabel" }] : /* istanbul ignore next */ []));
|
|
82
|
+
/** Accessible name of the progress bar — `{0}` is the file name. */
|
|
83
|
+
this.progressLabel = input('Progression du téléversement de {0}', /* @ts-ignore */
|
|
84
|
+
...(ngDevMode ? [{ debugName: "progressLabel" }] : /* istanbul ignore next */ []));
|
|
85
|
+
/** Emitted when the remove button is activated. */
|
|
86
|
+
this.remove = output();
|
|
87
|
+
/** @ignore Formatted size (e.g. "2.5 MB"). */
|
|
88
|
+
this.sizeLabel = computed(() => formatFileSize(this.file().size), /* @ts-ignore */
|
|
89
|
+
...(ngDevMode ? [{ debugName: "sizeLabel" }] : /* istanbul ignore next */ []));
|
|
90
|
+
/** @ignore Accessible name of the upload spinner (`{0}` filled with the file name). */
|
|
91
|
+
this.uploadingAriaLabel = computed(() => formatLabel(this.uploadingLabel(), this.file().name), /* @ts-ignore */
|
|
92
|
+
...(ngDevMode ? [{ debugName: "uploadingAriaLabel" }] : /* istanbul ignore next */ []));
|
|
93
|
+
/** @ignore Accessible name of the progress bar (`{0}` filled with the file name). */
|
|
94
|
+
this.progressAriaLabel = computed(() => formatLabel(this.progressLabel(), this.file().name), /* @ts-ignore */
|
|
95
|
+
...(ngDevMode ? [{ debugName: "progressAriaLabel" }] : /* istanbul ignore next */ []));
|
|
96
|
+
/** @ignore Uploading in progress → show the spinner + progress bar. */
|
|
97
|
+
this.isUploading = computed(() => this.file().status === 'uploading', /* @ts-ignore */
|
|
98
|
+
...(ngDevMode ? [{ debugName: "isUploading" }] : /* istanbul ignore next */ []));
|
|
99
|
+
/** @ignore Error state → surface the message + error styling. */
|
|
100
|
+
this.isError = computed(() => this.file().status === 'error', /* @ts-ignore */
|
|
101
|
+
...(ngDevMode ? [{ debugName: "isError" }] : /* istanbul ignore next */ []));
|
|
102
|
+
/** @ignore Image with a usable preview URL → render a thumbnail. */
|
|
103
|
+
this.thumbnail = computed(() => this.file().objectUrl ?? null, /* @ts-ignore */
|
|
104
|
+
...(ngDevMode ? [{ debugName: "thumbnail" }] : /* istanbul ignore next */ []));
|
|
105
|
+
/** @ignore Secondary line: error message, else size (+ status hint). */
|
|
106
|
+
this.infoLabel = computed(() => {
|
|
107
|
+
const f = this.file();
|
|
108
|
+
if (f.status === 'error')
|
|
109
|
+
return f.error ?? this.failedLabel();
|
|
110
|
+
if (f.status === 'uploading')
|
|
111
|
+
return `${this.sizeLabel()} · ${Math.round(f.progress)} %`;
|
|
112
|
+
return this.sizeLabel();
|
|
113
|
+
}, /* @ts-ignore */
|
|
114
|
+
...(ngDevMode ? [{ debugName: "infoLabel" }] : /* istanbul ignore next */ []));
|
|
115
|
+
/** @ignore */
|
|
116
|
+
this.iconSize = computed(() => (this.size() === 'small' ? 'sm' : 'md'), /* @ts-ignore */
|
|
117
|
+
...(ngDevMode ? [{ debugName: "iconSize" }] : /* istanbul ignore next */ []));
|
|
118
|
+
/** @ignore */
|
|
119
|
+
this.classes = computed(() => {
|
|
120
|
+
const c = ['ui-file-upload-list'];
|
|
121
|
+
if (this.size() !== 'default')
|
|
122
|
+
c.push(`_${this.size()}`);
|
|
123
|
+
if (this.isError())
|
|
124
|
+
c.push('_error');
|
|
125
|
+
if (this.thumbnail())
|
|
126
|
+
c.push('_has-thumb');
|
|
127
|
+
return c.join(' ');
|
|
128
|
+
}, /* @ts-ignore */
|
|
129
|
+
...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
|
|
130
|
+
}
|
|
131
|
+
/** @ignore */
|
|
132
|
+
onRemove() {
|
|
133
|
+
this.remove.emit(this.file());
|
|
134
|
+
}
|
|
135
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiFileUploadList, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
136
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: UiFileUploadList, isStandalone: true, selector: "ui-file-upload-list", inputs: { file: { classPropertyName: "file", publicName: "file", isSignal: true, isRequired: true, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null }, removable: { classPropertyName: "removable", publicName: "removable", isSignal: true, isRequired: false, transformFunction: null }, removeAriaLabel: { classPropertyName: "removeAriaLabel", publicName: "removeAriaLabel", isSignal: true, isRequired: false, transformFunction: null }, failedLabel: { classPropertyName: "failedLabel", publicName: "failedLabel", isSignal: true, isRequired: false, transformFunction: null }, uploadingLabel: { classPropertyName: "uploadingLabel", publicName: "uploadingLabel", isSignal: true, isRequired: false, transformFunction: null }, progressLabel: { classPropertyName: "progressLabel", publicName: "progressLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { remove: "remove" }, ngImport: i0, template: "<div [class]=\"classes()\">\n <div class=\"ui-file-upload-list-file\">\n <span class=\"ui-file-upload-list-media\">\n @if (isUploading()) {\n <ui-spinner size=\"small\" [ariaLabel]=\"uploadingAriaLabel()\" />\n } @else if (thumbnail(); as src) {\n <img class=\"ui-file-upload-list-thumb\" [src]=\"src\" alt=\"\" />\n } @else {\n <ui-icon [name]=\"isError() ? 'triangle-exclamation' : icon()\" [size]=\"iconSize()\" />\n }\n </span>\n\n <span class=\"ui-file-upload-list-infos\">\n <span class=\"ui-file-upload-list-name\" [title]=\"file().name\">{{ file().name }}</span>\n <span class=\"ui-file-upload-list-meta\">{{ infoLabel() }}</span>\n </span>\n </div>\n\n @if (removable()) {\n <button\n type=\"button\"\n class=\"ui-file-upload-list-remove\"\n [attr.aria-label]=\"removeAriaLabel() + ' : ' + file().name\"\n (click)=\"onRemove()\"\n >\n <ui-icon name=\"trash\" [size]=\"iconSize()\" />\n </button>\n }\n\n @if (isUploading()) {\n <div\n class=\"ui-file-upload-list-progress\"\n role=\"progressbar\"\n [attr.aria-valuenow]=\"file().progress\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n [attr.aria-label]=\"progressAriaLabel()\"\n >\n <span class=\"ui-file-upload-list-progress-bar\" [style.width.%]=\"file().progress\"></span>\n </div>\n }\n</div>\n", styles: [".ui-file-upload-list{position:relative;display:flex;align-items:center;box-sizing:border-box;width:100%;overflow:hidden;background-color:var(--form-high-surface-default);border:var(--stroke-default) solid var(--form-high-stroke-default);color:var(--form-high-content-default);border-radius:var(--radius-lg);padding:var(--units-md) var(--units-default);gap:var(--units-md)}.ui-file-upload-list .ui-file-upload-list-media{width:2.5rem;height:2.5rem}.ui-file-upload-list .ui-file-upload-list-name{font-size:var(--size-typography-title-sm)}.ui-file-upload-list .ui-file-upload-list-meta{font-size:var(--size-typography-text-sm)}.ui-file-upload-list._small{border-radius:var(--radius-md);padding:var(--units-sm) var(--units-md);gap:var(--units-sm)}.ui-file-upload-list._small .ui-file-upload-list-media{width:2rem;height:2rem}.ui-file-upload-list._small .ui-file-upload-list-name{font-size:var(--size-typography-text-md)}.ui-file-upload-list._small .ui-file-upload-list-meta{font-size:var(--size-typography-text-sm)}.ui-file-upload-list-file{display:flex;align-items:center;gap:var(--units-sm);min-width:0;flex:1 1 auto}.ui-file-upload-list-media{display:inline-flex;align-items:center;justify-content:center;flex:none;line-height:0;color:var(--form-high-content-default)}.ui-file-upload-list-thumb{width:100%;height:100%;object-fit:cover;border-radius:var(--radius-sm)}.ui-file-upload-list-infos{display:flex;flex-direction:column;gap:var(--units-2xs);min-width:0}.ui-file-upload-list-name{font-family:var(--fontfamily-base);font-weight:var(--weight-bold);line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-file-upload-list-meta{font-family:var(--fontfamily-base);font-weight:var(--weight-light);line-height:1.2;color:var(--form-high-content-default)}.ui-file-upload-list-remove{display:inline-flex;align-items:center;justify-content:center;flex:none;padding:var(--units-2xs);background:transparent;border:none;border-radius:var(--radius-sm);color:var(--form-high-content-default);cursor:pointer;line-height:0;transition:background-color var(--transition-default) var(--transition-easeinout),color var(--transition-default) var(--transition-easeinout)}.ui-file-upload-list-remove:hover{color:var(--global-text-default)}.ui-file-upload-list-remove:focus-visible{outline:none;box-shadow:0 0 0 var(--units-2xs) var(--form-high-stroke-focused)}.ui-file-upload-list-progress{position:absolute;left:0;right:0;bottom:0;height:var(--stroke-default);background-color:var(--form-high-surface-hover)}.ui-file-upload-list-progress-bar{display:block;height:100%;background-color:var(--global-text-default);transition:width var(--transition-default) var(--transition-easeinout)}.ui-file-upload-list._error{border-color:var(--informative-errorhigh-stroke-default)}.ui-file-upload-list._error .ui-file-upload-list-media,.ui-file-upload-list._error .ui-file-upload-list-meta{color:var(--informative-errorhigh-content-default)}\n"], dependencies: [{ kind: "component", type: UiIcon, selector: "ui-icon", inputs: ["name", "size", "type", "family", "decorative", "ariaLabel"] }, { kind: "component", type: UiSpinner, selector: "ui-spinner", inputs: ["size", "orientation", "label", "ariaLabel", "spinnerTemplate", "image", "imageAlt", "icon", "strokeWidth", "fill", "animationDuration", "delay"] }] }); }
|
|
137
|
+
}
|
|
138
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiFileUploadList, decorators: [{
|
|
139
|
+
type: Component,
|
|
140
|
+
args: [{ selector: 'ui-file-upload-list', imports: [UiIcon, UiSpinner], template: "<div [class]=\"classes()\">\n <div class=\"ui-file-upload-list-file\">\n <span class=\"ui-file-upload-list-media\">\n @if (isUploading()) {\n <ui-spinner size=\"small\" [ariaLabel]=\"uploadingAriaLabel()\" />\n } @else if (thumbnail(); as src) {\n <img class=\"ui-file-upload-list-thumb\" [src]=\"src\" alt=\"\" />\n } @else {\n <ui-icon [name]=\"isError() ? 'triangle-exclamation' : icon()\" [size]=\"iconSize()\" />\n }\n </span>\n\n <span class=\"ui-file-upload-list-infos\">\n <span class=\"ui-file-upload-list-name\" [title]=\"file().name\">{{ file().name }}</span>\n <span class=\"ui-file-upload-list-meta\">{{ infoLabel() }}</span>\n </span>\n </div>\n\n @if (removable()) {\n <button\n type=\"button\"\n class=\"ui-file-upload-list-remove\"\n [attr.aria-label]=\"removeAriaLabel() + ' : ' + file().name\"\n (click)=\"onRemove()\"\n >\n <ui-icon name=\"trash\" [size]=\"iconSize()\" />\n </button>\n }\n\n @if (isUploading()) {\n <div\n class=\"ui-file-upload-list-progress\"\n role=\"progressbar\"\n [attr.aria-valuenow]=\"file().progress\"\n aria-valuemin=\"0\"\n aria-valuemax=\"100\"\n [attr.aria-label]=\"progressAriaLabel()\"\n >\n <span class=\"ui-file-upload-list-progress-bar\" [style.width.%]=\"file().progress\"></span>\n </div>\n }\n</div>\n", styles: [".ui-file-upload-list{position:relative;display:flex;align-items:center;box-sizing:border-box;width:100%;overflow:hidden;background-color:var(--form-high-surface-default);border:var(--stroke-default) solid var(--form-high-stroke-default);color:var(--form-high-content-default);border-radius:var(--radius-lg);padding:var(--units-md) var(--units-default);gap:var(--units-md)}.ui-file-upload-list .ui-file-upload-list-media{width:2.5rem;height:2.5rem}.ui-file-upload-list .ui-file-upload-list-name{font-size:var(--size-typography-title-sm)}.ui-file-upload-list .ui-file-upload-list-meta{font-size:var(--size-typography-text-sm)}.ui-file-upload-list._small{border-radius:var(--radius-md);padding:var(--units-sm) var(--units-md);gap:var(--units-sm)}.ui-file-upload-list._small .ui-file-upload-list-media{width:2rem;height:2rem}.ui-file-upload-list._small .ui-file-upload-list-name{font-size:var(--size-typography-text-md)}.ui-file-upload-list._small .ui-file-upload-list-meta{font-size:var(--size-typography-text-sm)}.ui-file-upload-list-file{display:flex;align-items:center;gap:var(--units-sm);min-width:0;flex:1 1 auto}.ui-file-upload-list-media{display:inline-flex;align-items:center;justify-content:center;flex:none;line-height:0;color:var(--form-high-content-default)}.ui-file-upload-list-thumb{width:100%;height:100%;object-fit:cover;border-radius:var(--radius-sm)}.ui-file-upload-list-infos{display:flex;flex-direction:column;gap:var(--units-2xs);min-width:0}.ui-file-upload-list-name{font-family:var(--fontfamily-base);font-weight:var(--weight-bold);line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-file-upload-list-meta{font-family:var(--fontfamily-base);font-weight:var(--weight-light);line-height:1.2;color:var(--form-high-content-default)}.ui-file-upload-list-remove{display:inline-flex;align-items:center;justify-content:center;flex:none;padding:var(--units-2xs);background:transparent;border:none;border-radius:var(--radius-sm);color:var(--form-high-content-default);cursor:pointer;line-height:0;transition:background-color var(--transition-default) var(--transition-easeinout),color var(--transition-default) var(--transition-easeinout)}.ui-file-upload-list-remove:hover{color:var(--global-text-default)}.ui-file-upload-list-remove:focus-visible{outline:none;box-shadow:0 0 0 var(--units-2xs) var(--form-high-stroke-focused)}.ui-file-upload-list-progress{position:absolute;left:0;right:0;bottom:0;height:var(--stroke-default);background-color:var(--form-high-surface-hover)}.ui-file-upload-list-progress-bar{display:block;height:100%;background-color:var(--global-text-default);transition:width var(--transition-default) var(--transition-easeinout)}.ui-file-upload-list._error{border-color:var(--informative-errorhigh-stroke-default)}.ui-file-upload-list._error .ui-file-upload-list-media,.ui-file-upload-list._error .ui-file-upload-list-meta{color:var(--informative-errorhigh-content-default)}\n"] }]
|
|
141
|
+
}], propDecorators: { file: [{ type: i0.Input, args: [{ isSignal: true, alias: "file", required: true }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }], removable: [{ type: i0.Input, args: [{ isSignal: true, alias: "removable", required: false }] }], removeAriaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "removeAriaLabel", required: false }] }], failedLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "failedLabel", required: false }] }], uploadingLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "uploadingLabel", required: false }] }], progressLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "progressLabel", required: false }] }], remove: [{ type: i0.Output, args: ["remove"] }] } });
|
|
142
|
+
|
|
143
|
+
let nextUploadId = 0;
|
|
144
|
+
let nextInstanceId = 0;
|
|
145
|
+
/**
|
|
146
|
+
* ui-file-upload — headless file uploader (field + drag-and-drop).
|
|
147
|
+
*
|
|
148
|
+
* A native `<input type="file">` (visually hidden) drives selection, so the OS
|
|
149
|
+
* picker, keyboard and screen readers work natively; the whole component is also
|
|
150
|
+
* a drop target. Selection is validated client-side (type / size / count) and
|
|
151
|
+
* files can be uploaded automatically (`auto`), on demand, or via a custom
|
|
152
|
+
* handler (`customUpload`). Progress is tracked with `XMLHttpRequest` so no
|
|
153
|
+
* global HTTP provider is required.
|
|
154
|
+
*
|
|
155
|
+
* Security notes: client-side validation is a UX convenience — always re-validate
|
|
156
|
+
* server-side. Image previews use object URLs that are revoked on removal/clear.
|
|
157
|
+
*/
|
|
158
|
+
class UiFileUpload {
|
|
159
|
+
constructor() {
|
|
160
|
+
// --- Layout ----------------------------------------------------------
|
|
161
|
+
/** `field` = compact input + Browse button; `drag` = full drop zone. */
|
|
162
|
+
this.mode = input('field', /* @ts-ignore */
|
|
163
|
+
...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
164
|
+
this.size = input('default', /* @ts-ignore */
|
|
165
|
+
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
166
|
+
// --- Selection -------------------------------------------------------
|
|
167
|
+
/** Native input `name` (submitted with a surrounding form). */
|
|
168
|
+
this.name = input(/* @ts-ignore */
|
|
169
|
+
...(ngDevMode ? [undefined, { debugName: "name" }] : /* istanbul ignore next */ []));
|
|
170
|
+
/** Allow selecting more than one file. */
|
|
171
|
+
this.multiple = input(false, { ...(ngDevMode ? { debugName: "multiple" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
172
|
+
/** Native `accept` filter, e.g. "image/*,.pdf". Also enforced on drop. */
|
|
173
|
+
this.accept = input(/* @ts-ignore */
|
|
174
|
+
...(ngDevMode ? [undefined, { debugName: "accept" }] : /* istanbul ignore next */ []));
|
|
175
|
+
/** Max size per file, in bytes. */
|
|
176
|
+
this.maxFileSize = input(undefined, { ...(ngDevMode ? { debugName: "maxFileSize" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
177
|
+
/** Max number of files kept at once. */
|
|
178
|
+
this.fileLimit = input(undefined, { ...(ngDevMode ? { debugName: "fileLimit" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
179
|
+
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
180
|
+
// --- Upload behaviour ------------------------------------------------
|
|
181
|
+
/** Upload each file as soon as it is selected. */
|
|
182
|
+
this.auto = input(false, { ...(ngDevMode ? { debugName: "auto" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
183
|
+
/** Delegate uploading to the `uploadHandler` output instead of the built-in XHR. */
|
|
184
|
+
this.customUpload = input(false, { ...(ngDevMode ? { debugName: "customUpload" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
185
|
+
/** Endpoint for the built-in uploader. */
|
|
186
|
+
this.url = input(/* @ts-ignore */
|
|
187
|
+
...(ngDevMode ? [undefined, { debugName: "url" }] : /* istanbul ignore next */ []));
|
|
188
|
+
/** HTTP method for the built-in uploader. */
|
|
189
|
+
this.method = input('post', /* @ts-ignore */
|
|
190
|
+
...(ngDevMode ? [{ debugName: "method" }] : /* istanbul ignore next */ []));
|
|
191
|
+
/** Field name used for each file in the multipart body. */
|
|
192
|
+
this.fieldName = input('files', /* @ts-ignore */
|
|
193
|
+
...(ngDevMode ? [{ debugName: "fieldName" }] : /* istanbul ignore next */ []));
|
|
194
|
+
/** Send credentials (cookies) with the built-in upload request. */
|
|
195
|
+
this.withCredentials = input(false, { ...(ngDevMode ? { debugName: "withCredentials" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
196
|
+
// --- Presentation / labels ------------------------------------------
|
|
197
|
+
/** Show the file list under the control. */
|
|
198
|
+
this.showFileList = input(true, { ...(ngDevMode ? { debugName: "showFileList" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
199
|
+
/** Show the Upload/Cancel toolbar buttons (drag mode). */
|
|
200
|
+
this.showControls = input(true, { ...(ngDevMode ? { debugName: "showControls" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
201
|
+
this.browseLabel = input('Parcourir', /* @ts-ignore */
|
|
202
|
+
...(ngDevMode ? [{ debugName: "browseLabel" }] : /* istanbul ignore next */ []));
|
|
203
|
+
/** Placeholder shown in field mode before any selection. */
|
|
204
|
+
this.chooseLabel = input('Choisir un fichier…', /* @ts-ignore */
|
|
205
|
+
...(ngDevMode ? [{ debugName: "chooseLabel" }] : /* istanbul ignore next */ []));
|
|
206
|
+
this.uploadLabel = input('Téléverser', /* @ts-ignore */
|
|
207
|
+
...(ngDevMode ? [{ debugName: "uploadLabel" }] : /* istanbul ignore next */ []));
|
|
208
|
+
this.cancelLabel = input('Effacer', /* @ts-ignore */
|
|
209
|
+
...(ngDevMode ? [{ debugName: "cancelLabel" }] : /* istanbul ignore next */ []));
|
|
210
|
+
/** Drag-zone link + prompt. */
|
|
211
|
+
this.dragLinkLabel = input('Cliquer pour téléverser', /* @ts-ignore */
|
|
212
|
+
...(ngDevMode ? [{ debugName: "dragLinkLabel" }] : /* istanbul ignore next */ []));
|
|
213
|
+
this.dragPromptLabel = input('ou glisser-déposer les fichiers ici', /* @ts-ignore */
|
|
214
|
+
...(ngDevMode ? [{ debugName: "dragPromptLabel" }] : /* istanbul ignore next */ []));
|
|
215
|
+
/** Small hint under the drag prompt (e.g. "JPG, PNG (max 5 MB)"). */
|
|
216
|
+
this.hint = input(/* @ts-ignore */
|
|
217
|
+
...(ngDevMode ? [undefined, { debugName: "hint" }] : /* istanbul ignore next */ []));
|
|
218
|
+
/** Accessible name for the whole control. */
|
|
219
|
+
// Composite widget (dropzone + file list), not a single-value CVA control: unlike the other
|
|
220
|
+
// form components it doesn't extend BaseFieldControl, so it redeclares its own `ariaLabel`
|
|
221
|
+
// here — with a non-undefined default, since the dropzone always needs an accessible name.
|
|
222
|
+
this.ariaLabel = input('Téléversement de fichiers', /* @ts-ignore */
|
|
223
|
+
...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
224
|
+
/** Multi-file summary in field mode — `{0}` is replaced by the file count. */
|
|
225
|
+
this.filesSummaryLabel = input('{0} fichiers', /* @ts-ignore */
|
|
226
|
+
...(ngDevMode ? [{ debugName: "filesSummaryLabel" }] : /* istanbul ignore next */ []));
|
|
227
|
+
/** Rejection message: file type not accepted — `{0}` is the file name. */
|
|
228
|
+
this.invalidTypeMessage = input('Type de fichier non autorisé : {0}', /* @ts-ignore */
|
|
229
|
+
...(ngDevMode ? [{ debugName: "invalidTypeMessage" }] : /* istanbul ignore next */ []));
|
|
230
|
+
/** Rejection message: file too large — `{0}` is the file name. */
|
|
231
|
+
this.invalidSizeMessage = input('Fichier trop volumineux : {0}', /* @ts-ignore */
|
|
232
|
+
...(ngDevMode ? [{ debugName: "invalidSizeMessage" }] : /* istanbul ignore next */ []));
|
|
233
|
+
/** Rejection message: `fileLimit` reached — `{0}` is the limit. */
|
|
234
|
+
this.limitReachedMessage = input('Nombre maximum de fichiers atteint ({0}).', /* @ts-ignore */
|
|
235
|
+
...(ngDevMode ? [{ debugName: "limitReachedMessage" }] : /* istanbul ignore next */ []));
|
|
236
|
+
/** Error shown when an upload fails without a server message. */
|
|
237
|
+
this.uploadErrorMessage = input('Échec du téléversement', /* @ts-ignore */
|
|
238
|
+
...(ngDevMode ? [{ debugName: "uploadErrorMessage" }] : /* istanbul ignore next */ []));
|
|
239
|
+
/** Error shown when the upload request fails at the network level. */
|
|
240
|
+
this.networkErrorMessage = input('Erreur réseau', /* @ts-ignore */
|
|
241
|
+
...(ngDevMode ? [{ debugName: "networkErrorMessage" }] : /* istanbul ignore next */ []));
|
|
242
|
+
/** Error shown on a non-2xx response — `{0}` is the HTTP status. */
|
|
243
|
+
this.httpErrorMessage = input('Erreur {0}', /* @ts-ignore */
|
|
244
|
+
...(ngDevMode ? [{ debugName: "httpErrorMessage" }] : /* istanbul ignore next */ []));
|
|
245
|
+
// --- Templates (drag/advanced) --------------------------------------
|
|
246
|
+
/** Overrides a single file row (context: `{ $implicit: UiUploadFile, remove }`). */
|
|
247
|
+
this.fileTemplate = input(/* @ts-ignore */
|
|
248
|
+
...(ngDevMode ? [undefined, { debugName: "fileTemplate" }] : /* istanbul ignore next */ []));
|
|
249
|
+
/** Overrides the content section (context: `{ $implicit: UiUploadFile[], remove, clear }`). */
|
|
250
|
+
this.contentTemplate = input(/* @ts-ignore */
|
|
251
|
+
...(ngDevMode ? [undefined, { debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
|
|
252
|
+
/** Custom toolbar content (context: `{ $implicit: UiUploadFile[], choose, upload, clear }`). */
|
|
253
|
+
this.toolbarTemplate = input(/* @ts-ignore */
|
|
254
|
+
...(ngDevMode ? [undefined, { debugName: "toolbarTemplate" }] : /* istanbul ignore next */ []));
|
|
255
|
+
// --- Outputs ---------------------------------------------------------
|
|
256
|
+
/** Files added to the selection (validated). */
|
|
257
|
+
this.selected = output();
|
|
258
|
+
/** The full current selection changed. */
|
|
259
|
+
this.filesChange = output();
|
|
260
|
+
/** A custom upload was requested (customUpload = true). */
|
|
261
|
+
this.uploadHandler = output();
|
|
262
|
+
/** Built-in upload completed for a batch. */
|
|
263
|
+
this.uploaded = output();
|
|
264
|
+
/** A file failed validation or upload. */
|
|
265
|
+
this.uploadError = output();
|
|
266
|
+
/** A file was removed. */
|
|
267
|
+
this.removed = output();
|
|
268
|
+
/** The selection was cleared. */
|
|
269
|
+
this.cleared = output();
|
|
270
|
+
/** @ignore Stable id linking the visible label(s) to the native input. */
|
|
271
|
+
this.inputId = `ui-file-upload-${nextInstanceId++}`;
|
|
272
|
+
this.host = inject((ElementRef));
|
|
273
|
+
this.destroyRef = inject(DestroyRef);
|
|
274
|
+
this.fileInput = viewChild.required('fileInput', /* @ts-ignore */
|
|
275
|
+
...(ngDevMode ? [{ debugName: "fileInput" }] : /* istanbul ignore next */ []));
|
|
276
|
+
/** In-flight requests, keyed by file id, so we can abort. */
|
|
277
|
+
this.requests = new Map();
|
|
278
|
+
/** @ignore Current selection. */
|
|
279
|
+
this.selection = signal([], /* @ts-ignore */
|
|
280
|
+
...(ngDevMode ? [{ debugName: "selection" }] : /* istanbul ignore next */ []));
|
|
281
|
+
/** Read-only view of the current files. */
|
|
282
|
+
this.files = this.selection.asReadonly();
|
|
283
|
+
/** @ignore Drop-zone highlight while dragging over. */
|
|
284
|
+
this.dragging = signal(false, /* @ts-ignore */
|
|
285
|
+
...(ngDevMode ? [{ debugName: "dragging" }] : /* istanbul ignore next */ []));
|
|
286
|
+
/** @ignore Transient validation messages (rendered in a live region). */
|
|
287
|
+
this.messages = signal([], /* @ts-ignore */
|
|
288
|
+
...(ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []));
|
|
289
|
+
/** @ignore */
|
|
290
|
+
this.hasFiles = computed(() => this.selection().length > 0, /* @ts-ignore */
|
|
291
|
+
...(ngDevMode ? [{ debugName: "hasFiles" }] : /* istanbul ignore next */ []));
|
|
292
|
+
/** @ignore */
|
|
293
|
+
this.pending = computed(() => this.selection().filter((f) => f.status === 'pending'), /* @ts-ignore */
|
|
294
|
+
...(ngDevMode ? [{ debugName: "pending" }] : /* istanbul ignore next */ []));
|
|
295
|
+
/** @ignore Single-file summary shown in field mode. */
|
|
296
|
+
this.fieldSummary = computed(() => {
|
|
297
|
+
const files = this.selection();
|
|
298
|
+
if (!files.length)
|
|
299
|
+
return this.chooseLabel();
|
|
300
|
+
if (files.length === 1)
|
|
301
|
+
return files[0].name;
|
|
302
|
+
return formatLabel(this.filesSummaryLabel(), files.length);
|
|
303
|
+
}, /* @ts-ignore */
|
|
304
|
+
...(ngDevMode ? [{ debugName: "fieldSummary" }] : /* istanbul ignore next */ []));
|
|
305
|
+
/** @ignore */
|
|
306
|
+
this.canUpload = computed(() => !this.disabled() && this.pending().length > 0 && (this.customUpload() || !!this.url()), /* @ts-ignore */
|
|
307
|
+
...(ngDevMode ? [{ debugName: "canUpload" }] : /* istanbul ignore next */ []));
|
|
308
|
+
/** @ignore */
|
|
309
|
+
this.classes = computed(() => {
|
|
310
|
+
const c = ['ui-file-upload', `_${this.mode()}`];
|
|
311
|
+
if (this.size() !== 'default')
|
|
312
|
+
c.push(`_${this.size()}`);
|
|
313
|
+
if (this.dragging())
|
|
314
|
+
c.push('_dragging');
|
|
315
|
+
if (this.disabled())
|
|
316
|
+
c.push('_disabled');
|
|
317
|
+
return c.join(' ');
|
|
318
|
+
}, /* @ts-ignore */
|
|
319
|
+
...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
|
|
320
|
+
// --- Bound refs for custom templates (stable identities) -------------
|
|
321
|
+
/** @ignore */ this.removeFn = (f) => this.remove(f);
|
|
322
|
+
/** @ignore */ this.clearFn = () => this.clear();
|
|
323
|
+
/** @ignore */ this.chooseFn = () => this.choose();
|
|
324
|
+
/** @ignore */ this.uploadFn = () => this.upload();
|
|
325
|
+
// Revoke every object URL when the component is destroyed (no leaks).
|
|
326
|
+
this.destroyRef.onDestroy(() => {
|
|
327
|
+
for (const f of this.selection())
|
|
328
|
+
this.revoke(f);
|
|
329
|
+
for (const xhr of this.requests.values())
|
|
330
|
+
xhr.abort();
|
|
331
|
+
});
|
|
332
|
+
// A11y safeguard: the control needs an accessible name.
|
|
333
|
+
if (isDevMode()) {
|
|
334
|
+
effect(() => {
|
|
335
|
+
if (!this.ariaLabel()) {
|
|
336
|
+
console.warn('[ui-file-upload] Provide `ariaLabel` to name the control.');
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// --- Public API ------------------------------------------------------
|
|
342
|
+
/** Opens the native file picker. */
|
|
343
|
+
choose() {
|
|
344
|
+
if (this.disabled())
|
|
345
|
+
return;
|
|
346
|
+
this.fileInput().nativeElement.click();
|
|
347
|
+
}
|
|
348
|
+
/** Uploads all pending files (built-in XHR, or emits `uploadHandler`). */
|
|
349
|
+
upload() {
|
|
350
|
+
const pending = this.pending();
|
|
351
|
+
if (!pending.length)
|
|
352
|
+
return;
|
|
353
|
+
if (this.customUpload()) {
|
|
354
|
+
this.emitCustomUpload(pending);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const endpoint = this.url();
|
|
358
|
+
if (!endpoint)
|
|
359
|
+
return;
|
|
360
|
+
for (const f of pending)
|
|
361
|
+
this.xhrUpload(f, endpoint);
|
|
362
|
+
}
|
|
363
|
+
/** Removes a file (aborts its upload, revokes its preview). */
|
|
364
|
+
remove(target) {
|
|
365
|
+
this.requests.get(target.id)?.abort();
|
|
366
|
+
this.requests.delete(target.id);
|
|
367
|
+
this.revoke(target);
|
|
368
|
+
this.selection.update((files) => files.filter((f) => f.id !== target.id));
|
|
369
|
+
this.removed.emit(target);
|
|
370
|
+
this.filesChange.emit(this.selection());
|
|
371
|
+
}
|
|
372
|
+
/** Clears the whole selection. */
|
|
373
|
+
clear() {
|
|
374
|
+
for (const xhr of this.requests.values())
|
|
375
|
+
xhr.abort();
|
|
376
|
+
this.requests.clear();
|
|
377
|
+
for (const f of this.selection())
|
|
378
|
+
this.revoke(f);
|
|
379
|
+
this.selection.set([]);
|
|
380
|
+
this.messages.set([]);
|
|
381
|
+
this.resetInput();
|
|
382
|
+
this.cleared.emit();
|
|
383
|
+
this.filesChange.emit([]);
|
|
384
|
+
}
|
|
385
|
+
// --- Native input / drop --------------------------------------------
|
|
386
|
+
/** @ignore */
|
|
387
|
+
onInputChange(event) {
|
|
388
|
+
const input = event.target;
|
|
389
|
+
this.ingest(input.files);
|
|
390
|
+
// Reset so selecting the same file again re-triggers `change`.
|
|
391
|
+
this.resetInput();
|
|
392
|
+
}
|
|
393
|
+
/** @ignore */
|
|
394
|
+
onDragOver(event) {
|
|
395
|
+
if (this.disabled())
|
|
396
|
+
return;
|
|
397
|
+
event.preventDefault();
|
|
398
|
+
event.stopPropagation();
|
|
399
|
+
this.dragging.set(true);
|
|
400
|
+
}
|
|
401
|
+
/** @ignore */
|
|
402
|
+
onDragLeave(event) {
|
|
403
|
+
if (this.disabled())
|
|
404
|
+
return;
|
|
405
|
+
event.preventDefault();
|
|
406
|
+
// Ignore leave events bubbling from children still inside the zone.
|
|
407
|
+
if (this.host.nativeElement.contains(event.relatedTarget))
|
|
408
|
+
return;
|
|
409
|
+
this.dragging.set(false);
|
|
410
|
+
}
|
|
411
|
+
/** @ignore */
|
|
412
|
+
onDrop(event) {
|
|
413
|
+
if (this.disabled())
|
|
414
|
+
return;
|
|
415
|
+
event.preventDefault();
|
|
416
|
+
event.stopPropagation();
|
|
417
|
+
this.dragging.set(false);
|
|
418
|
+
this.ingest(event.dataTransfer?.files ?? null);
|
|
419
|
+
}
|
|
420
|
+
// --- Internals -------------------------------------------------------
|
|
421
|
+
/** Validate + add a FileList to the selection. */
|
|
422
|
+
ingest(list) {
|
|
423
|
+
if (!list || !list.length || this.disabled())
|
|
424
|
+
return;
|
|
425
|
+
const incoming = Array.from(list);
|
|
426
|
+
const added = [];
|
|
427
|
+
const newMessages = [];
|
|
428
|
+
const limit = this.fileLimit();
|
|
429
|
+
const maxSize = this.maxFileSize();
|
|
430
|
+
for (const file of incoming) {
|
|
431
|
+
// Single-file mode: the new file replaces the current one, so only cap the incoming batch.
|
|
432
|
+
if (!this.multiple() && added.length >= 1)
|
|
433
|
+
break;
|
|
434
|
+
const item = this.toUploadFile(file);
|
|
435
|
+
if (!isFileTypeAccepted(file, this.accept())) {
|
|
436
|
+
this.fail(item, 'type', formatLabel(this.invalidTypeMessage(), file.name), newMessages);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (maxSize != null && file.size > maxSize) {
|
|
440
|
+
this.fail(item, 'size', formatLabel(this.invalidSizeMessage(), file.name), newMessages);
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (limit != null && (this.multiple() ? this.selection().length : 0) + added.length >= limit) {
|
|
444
|
+
this.fail(item, 'limit', formatLabel(this.limitReachedMessage(), limit), newMessages);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
added.push(item);
|
|
448
|
+
}
|
|
449
|
+
this.messages.set(newMessages);
|
|
450
|
+
if (!added.length)
|
|
451
|
+
return;
|
|
452
|
+
if (!this.multiple()) {
|
|
453
|
+
// Replacement: release resources held by the previous selection.
|
|
454
|
+
for (const previous of this.selection()) {
|
|
455
|
+
this.requests.get(previous.id)?.abort();
|
|
456
|
+
this.requests.delete(previous.id);
|
|
457
|
+
this.revoke(previous);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
this.selection.update((files) => (this.multiple() ? [...files, ...added] : added));
|
|
461
|
+
this.selected.emit(added);
|
|
462
|
+
this.filesChange.emit(this.selection());
|
|
463
|
+
if (this.auto())
|
|
464
|
+
this.upload();
|
|
465
|
+
}
|
|
466
|
+
toUploadFile(file) {
|
|
467
|
+
return {
|
|
468
|
+
id: `uifu-${nextUploadId++}`,
|
|
469
|
+
file,
|
|
470
|
+
name: file.name,
|
|
471
|
+
size: file.size,
|
|
472
|
+
type: file.type,
|
|
473
|
+
status: 'pending',
|
|
474
|
+
progress: 0,
|
|
475
|
+
objectUrl: isImageFile(file) ? URL.createObjectURL(file) : undefined,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
fail(item, reason, message, sink) {
|
|
479
|
+
this.revoke(item);
|
|
480
|
+
sink.push(message);
|
|
481
|
+
this.uploadError.emit({ file: { ...item, status: 'error', error: message }, reason, message });
|
|
482
|
+
}
|
|
483
|
+
/** Mutates one file in place (immutably) and pushes a new array reference. */
|
|
484
|
+
patch(id, changes) {
|
|
485
|
+
this.selection.update((files) => files.map((f) => (f.id === id ? { ...f, ...changes } : f)));
|
|
486
|
+
}
|
|
487
|
+
emitCustomUpload(pending) {
|
|
488
|
+
for (const f of pending)
|
|
489
|
+
this.patch(f.id, { status: 'uploading', progress: 0 });
|
|
490
|
+
this.uploadHandler.emit({
|
|
491
|
+
files: pending,
|
|
492
|
+
setProgress: (file, progress) => this.patch(file.id, { status: 'uploading', progress: Math.max(0, Math.min(100, progress)) }),
|
|
493
|
+
markUploaded: (file) => {
|
|
494
|
+
this.patch(file.id, { status: 'completed', progress: 100 });
|
|
495
|
+
this.filesChange.emit(this.selection());
|
|
496
|
+
},
|
|
497
|
+
markError: (file, msg) => {
|
|
498
|
+
this.patch(file.id, { status: 'error', error: msg ?? this.uploadErrorMessage() });
|
|
499
|
+
this.uploadError.emit({
|
|
500
|
+
file,
|
|
501
|
+
reason: 'upload',
|
|
502
|
+
message: msg ?? this.uploadErrorMessage(),
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
xhrUpload(item, endpoint) {
|
|
508
|
+
const xhr = new XMLHttpRequest();
|
|
509
|
+
this.requests.set(item.id, xhr);
|
|
510
|
+
this.patch(item.id, { status: 'uploading', progress: 0 });
|
|
511
|
+
const body = new FormData();
|
|
512
|
+
body.append(this.fieldName(), item.file, item.name);
|
|
513
|
+
xhr.upload.addEventListener('progress', (e) => {
|
|
514
|
+
if (e.lengthComputable)
|
|
515
|
+
this.patch(item.id, { progress: Math.round((e.loaded / e.total) * 100) });
|
|
516
|
+
});
|
|
517
|
+
xhr.addEventListener('load', () => {
|
|
518
|
+
this.requests.delete(item.id);
|
|
519
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
520
|
+
this.patch(item.id, { status: 'completed', progress: 100 });
|
|
521
|
+
this.uploaded.emit({ files: [item], xhr });
|
|
522
|
+
this.filesChange.emit(this.selection());
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
this.uploadFailed(item, formatLabel(this.httpErrorMessage(), xhr.status));
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
xhr.addEventListener('error', () => this.uploadFailed(item, this.networkErrorMessage()));
|
|
529
|
+
xhr.addEventListener('abort', () => this.requests.delete(item.id));
|
|
530
|
+
xhr.open(this.method().toUpperCase(), endpoint, true);
|
|
531
|
+
xhr.withCredentials = this.withCredentials();
|
|
532
|
+
xhr.send(body);
|
|
533
|
+
}
|
|
534
|
+
uploadFailed(item, message) {
|
|
535
|
+
this.requests.delete(item.id);
|
|
536
|
+
this.patch(item.id, { status: 'error', error: message });
|
|
537
|
+
this.uploadError.emit({ file: item, reason: 'upload', message });
|
|
538
|
+
}
|
|
539
|
+
revoke(file) {
|
|
540
|
+
if (file.objectUrl)
|
|
541
|
+
URL.revokeObjectURL(file.objectUrl);
|
|
542
|
+
}
|
|
543
|
+
resetInput() {
|
|
544
|
+
const el = this.fileInput().nativeElement;
|
|
545
|
+
if (el)
|
|
546
|
+
el.value = '';
|
|
547
|
+
}
|
|
548
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiFileUpload, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
549
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: UiFileUpload, isStandalone: true, selector: "ui-file-upload", inputs: { mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, accept: { classPropertyName: "accept", publicName: "accept", isSignal: true, isRequired: false, transformFunction: null }, maxFileSize: { classPropertyName: "maxFileSize", publicName: "maxFileSize", isSignal: true, isRequired: false, transformFunction: null }, fileLimit: { classPropertyName: "fileLimit", publicName: "fileLimit", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, auto: { classPropertyName: "auto", publicName: "auto", isSignal: true, isRequired: false, transformFunction: null }, customUpload: { classPropertyName: "customUpload", publicName: "customUpload", isSignal: true, isRequired: false, transformFunction: null }, url: { classPropertyName: "url", publicName: "url", isSignal: true, isRequired: false, transformFunction: null }, method: { classPropertyName: "method", publicName: "method", isSignal: true, isRequired: false, transformFunction: null }, fieldName: { classPropertyName: "fieldName", publicName: "fieldName", isSignal: true, isRequired: false, transformFunction: null }, withCredentials: { classPropertyName: "withCredentials", publicName: "withCredentials", isSignal: true, isRequired: false, transformFunction: null }, showFileList: { classPropertyName: "showFileList", publicName: "showFileList", isSignal: true, isRequired: false, transformFunction: null }, showControls: { classPropertyName: "showControls", publicName: "showControls", isSignal: true, isRequired: false, transformFunction: null }, browseLabel: { classPropertyName: "browseLabel", publicName: "browseLabel", isSignal: true, isRequired: false, transformFunction: null }, chooseLabel: { classPropertyName: "chooseLabel", publicName: "chooseLabel", isSignal: true, isRequired: false, transformFunction: null }, uploadLabel: { classPropertyName: "uploadLabel", publicName: "uploadLabel", isSignal: true, isRequired: false, transformFunction: null }, cancelLabel: { classPropertyName: "cancelLabel", publicName: "cancelLabel", isSignal: true, isRequired: false, transformFunction: null }, dragLinkLabel: { classPropertyName: "dragLinkLabel", publicName: "dragLinkLabel", isSignal: true, isRequired: false, transformFunction: null }, dragPromptLabel: { classPropertyName: "dragPromptLabel", publicName: "dragPromptLabel", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, filesSummaryLabel: { classPropertyName: "filesSummaryLabel", publicName: "filesSummaryLabel", isSignal: true, isRequired: false, transformFunction: null }, invalidTypeMessage: { classPropertyName: "invalidTypeMessage", publicName: "invalidTypeMessage", isSignal: true, isRequired: false, transformFunction: null }, invalidSizeMessage: { classPropertyName: "invalidSizeMessage", publicName: "invalidSizeMessage", isSignal: true, isRequired: false, transformFunction: null }, limitReachedMessage: { classPropertyName: "limitReachedMessage", publicName: "limitReachedMessage", isSignal: true, isRequired: false, transformFunction: null }, uploadErrorMessage: { classPropertyName: "uploadErrorMessage", publicName: "uploadErrorMessage", isSignal: true, isRequired: false, transformFunction: null }, networkErrorMessage: { classPropertyName: "networkErrorMessage", publicName: "networkErrorMessage", isSignal: true, isRequired: false, transformFunction: null }, httpErrorMessage: { classPropertyName: "httpErrorMessage", publicName: "httpErrorMessage", isSignal: true, isRequired: false, transformFunction: null }, fileTemplate: { classPropertyName: "fileTemplate", publicName: "fileTemplate", isSignal: true, isRequired: false, transformFunction: null }, contentTemplate: { classPropertyName: "contentTemplate", publicName: "contentTemplate", isSignal: true, isRequired: false, transformFunction: null }, toolbarTemplate: { classPropertyName: "toolbarTemplate", publicName: "toolbarTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selected: "selected", filesChange: "filesChange", uploadHandler: "uploadHandler", uploaded: "uploaded", uploadError: "uploadError", removed: "removed", cleared: "cleared" }, viewQueries: [{ propertyName: "fileInput", first: true, predicate: ["fileInput"], descendants: true, isSignal: true }], ngImport: i0, template: "<div\n [class]=\"classes()\"\n (dragover)=\"onDragOver($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (drop)=\"onDrop($event)\"\n>\n <!-- Real native control (visually hidden, keeps keyboard + screen-reader support) -->\n <input\n #fileInput\n class=\"ui-file-upload-input\"\n type=\"file\"\n [id]=\"inputId\"\n [attr.name]=\"name()\"\n [attr.accept]=\"accept() || null\"\n [multiple]=\"multiple()\"\n [disabled]=\"disabled()\"\n [attr.aria-label]=\"ariaLabel() || null\"\n (change)=\"onInputChange($event)\"\n />\n\n @if (mode() === 'field') {\n <!-- Field mode: compact summary + Browse trigger (whole label opens picker) -->\n <label class=\"ui-file-upload-field\" [attr.for]=\"inputId\">\n <span class=\"ui-file-upload-field-text\" [class._placeholder]=\"!hasFiles()\">{{ fieldSummary() }}</span>\n <span class=\"ui-file-upload-browse\" aria-hidden=\"true\">{{ browseLabel() }}</span>\n </label>\n } @else {\n <!-- Drag mode: full drop zone -->\n <label class=\"ui-file-upload-zone\" [attr.for]=\"inputId\">\n <ui-icon class=\"ui-file-upload-zone-icon\" name=\"cloud-arrow-up\" size=\"lg\" />\n <span class=\"ui-file-upload-zone-content\">\n <span class=\"ui-file-upload-zone-title\">\n <span class=\"ui-file-upload-zone-link\">{{ dragLinkLabel() }}</span>\n <span class=\"ui-file-upload-zone-prompt\">{{ dragPromptLabel() }}</span>\n </span>\n @if (hint(); as h) {\n <span class=\"ui-file-upload-zone-hint\">{{ h }}</span>\n }\n </span>\n </label>\n\n <!-- Toolbar (custom, or default Upload/Clear actions) -->\n @if (toolbarTemplate(); as tpl) {\n <div class=\"ui-file-upload-toolbar\">\n <ng-container\n [ngTemplateOutlet]=\"tpl\"\n [ngTemplateOutletContext]=\"{ $implicit: files(), choose: chooseFn, upload: uploadFn, clear: clearFn }\"\n />\n </div>\n } @else if (showControls() && hasFiles()) {\n <div class=\"ui-file-upload-toolbar\">\n @if (!auto()) {\n <ui-button\n [label]=\"uploadLabel()\"\n [size]=\"size() === 'small' ? 'small' : 'default'\"\n icon=\"cloud-arrow-up\"\n [disabled]=\"!canUpload()\"\n (buttonClick)=\"upload()\"\n />\n }\n <ui-button\n [label]=\"cancelLabel()\"\n level=\"low\"\n [size]=\"size() === 'small' ? 'small' : 'default'\"\n icon=\"xmark\"\n (buttonClick)=\"clear()\"\n />\n </div>\n }\n }\n\n <!-- Content section: the file list -->\n @if (contentTemplate(); as tpl) {\n <div class=\"ui-file-upload-content\">\n <ng-container\n [ngTemplateOutlet]=\"tpl\"\n [ngTemplateOutletContext]=\"{ $implicit: files(), remove: removeFn, clear: clearFn }\"\n />\n </div>\n } @else if (showFileList() && hasFiles()) {\n <ul class=\"ui-file-upload-content\" role=\"list\">\n @for (f of files(); track f.id) {\n <li>\n @if (fileTemplate(); as tpl) {\n <ng-container\n [ngTemplateOutlet]=\"tpl\"\n [ngTemplateOutletContext]=\"{ $implicit: f, remove: removeFn }\"\n />\n } @else {\n <ui-file-upload-list [file]=\"f\" [size]=\"size()\" (remove)=\"remove($event)\" />\n }\n </li>\n }\n </ul>\n }\n\n <!-- Validation messages (assertive live region) -->\n @if (messages().length) {\n <div class=\"ui-file-upload-messages\" role=\"alert\" aria-live=\"assertive\">\n @for (msg of messages(); track msg) {\n <p class=\"ui-file-upload-message\">{{ msg }}</p>\n }\n </div>\n }\n</div>\n", styles: [".ui-file-upload{display:flex;flex-direction:column;gap:var(--units-default);width:100%;font-family:var(--fontfamily-base)}.ui-file-upload-input{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.ui-file-upload-field{display:flex;align-items:center;justify-content:space-between;gap:var(--units-sm);height:var(--size-components-default);padding-left:var(--units-md);overflow:hidden;background-color:var(--form-high-surface-default);border:var(--stroke-default) solid var(--form-high-stroke-default);border-radius:var(--radius-sm);color:var(--form-high-content-default);cursor:pointer;transition:background-color var(--transition-default) var(--transition-easeinout),border-color var(--transition-default) var(--transition-easeinout),color var(--transition-default) var(--transition-easeinout),box-shadow var(--transition-default) var(--transition-easeinout)}.ui-file-upload-field:hover{background-color:var(--form-high-surface-hover);border-color:var(--form-high-stroke-hover)}.ui-file-upload._small .ui-file-upload-field{height:var(--size-components-sm)}.ui-file-upload-field-text{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--size-typography-text-default);font-weight:var(--weight-regular)}.ui-file-upload-field-text._placeholder{color:var(--form-high-content-default);opacity:.75}.ui-file-upload._small .ui-file-upload-field-text{font-size:var(--size-typography-text-md)}.ui-file-upload-browse{display:inline-flex;align-items:center;align-self:stretch;flex:none;padding:0 var(--units-default);background-color:var(--actions-high-surface-default);color:var(--actions-high-content-default);font-size:var(--size-typography-text-default);font-weight:var(--weight-bold)}.ui-file-upload._small .ui-file-upload-browse{padding:0 var(--units-md);font-size:var(--size-typography-text-md)}.ui-file-upload-field:hover .ui-file-upload-browse{background-color:var(--actions-high-surface-hover)}.ui-file-upload-zone{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--units-lg);min-height:112px;padding:var(--units-default);background-color:var(--form-high-surface-default);border:var(--stroke-default) dashed var(--form-high-stroke-default);border-radius:var(--radius-sm);color:var(--form-high-content-default);text-align:center;cursor:pointer;transition:background-color var(--transition-default) var(--transition-easeinout),border-color var(--transition-default) var(--transition-easeinout),box-shadow var(--transition-default) var(--transition-easeinout)}.ui-file-upload-zone:hover{background-color:var(--form-high-surface-hover);border-color:var(--form-high-stroke-hover)}.ui-file-upload._small .ui-file-upload-zone{gap:var(--units-sm);min-height:94px}.ui-file-upload._dragging .ui-file-upload-zone{background-color:var(--form-high-surface-focused);border-style:solid;border-color:var(--form-high-stroke-focused)}.ui-file-upload-zone-icon{color:var(--form-high-content-default);line-height:0}.ui-file-upload-zone-content{display:flex;flex-direction:column;align-items:center;gap:var(--units-xs)}.ui-file-upload-zone-title{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:var(--units-2xs);font-size:var(--size-typography-text-default);font-weight:var(--weight-regular)}.ui-file-upload._small .ui-file-upload-zone-title{font-size:var(--size-typography-text-md)}.ui-file-upload-zone-link{color:var(--actions-low-content-default);font-weight:var(--weight-bold);text-decoration:underline}.ui-file-upload-zone-prompt{color:var(--form-high-content-default)}.ui-file-upload-zone-hint{color:var(--global-text-muted);font-size:var(--size-typography-text-md)}.ui-file-upload._small .ui-file-upload-zone-hint{font-size:var(--size-typography-text-sm)}.ui-file-upload-input:focus-visible~.ui-file-upload-field,.ui-file-upload-input:focus-visible~.ui-file-upload-zone{outline:none;border-color:var(--form-high-stroke-focused);box-shadow:0 0 0 var(--units-2xs) var(--form-high-stroke-focused)}.ui-file-upload-toolbar{display:flex;flex-wrap:wrap;gap:var(--units-sm)}.ui-file-upload-content{display:flex;flex-direction:column;gap:var(--units-sm);width:100%;margin:0;padding:0;list-style:none}.ui-file-upload-content li{display:block}.ui-file-upload-messages{display:flex;flex-direction:column;gap:var(--units-2xs)}.ui-file-upload-message{margin:0;color:var(--informative-errorhigh-content-default);font-size:var(--size-typography-text-md)}.ui-file-upload._disabled .ui-file-upload-field,.ui-file-upload._disabled .ui-file-upload-zone{background-color:var(--form-high-surface-disabled);border-color:var(--form-high-stroke-disabled);color:var(--form-high-content-disabled);cursor:not-allowed;pointer-events:none}.ui-file-upload._disabled .ui-file-upload-browse{background-color:var(--actions-high-surface-disabled);color:var(--actions-high-content-disabled)}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: UiIcon, selector: "ui-icon", inputs: ["name", "size", "type", "family", "decorative", "ariaLabel"] }, { kind: "component", type: UiButton, selector: "ui-button", inputs: ["label", "ariaLabel", "type", "level", "variant", "onColor", "size", "icon", "iconPos", "iconOnly", "loading", "loadingIcon", "expanded", "rounded", "disabled", "tabindex", "buttonProps", "iconTemplate", "loadingIconTemplate", "href", "routerLink", "target", "rel"], outputs: ["buttonClick", "buttonFocus", "buttonBlur"] }, { kind: "component", type: UiFileUploadList, selector: "ui-file-upload-list", inputs: ["file", "size", "icon", "removable", "removeAriaLabel", "failedLabel", "uploadingLabel", "progressLabel"], outputs: ["remove"] }] }); }
|
|
550
|
+
}
|
|
551
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiFileUpload, decorators: [{
|
|
552
|
+
type: Component,
|
|
553
|
+
args: [{ selector: 'ui-file-upload', imports: [NgTemplateOutlet, UiIcon, UiButton, UiLink, UiFileUploadList], template: "<div\n [class]=\"classes()\"\n (dragover)=\"onDragOver($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (drop)=\"onDrop($event)\"\n>\n <!-- Real native control (visually hidden, keeps keyboard + screen-reader support) -->\n <input\n #fileInput\n class=\"ui-file-upload-input\"\n type=\"file\"\n [id]=\"inputId\"\n [attr.name]=\"name()\"\n [attr.accept]=\"accept() || null\"\n [multiple]=\"multiple()\"\n [disabled]=\"disabled()\"\n [attr.aria-label]=\"ariaLabel() || null\"\n (change)=\"onInputChange($event)\"\n />\n\n @if (mode() === 'field') {\n <!-- Field mode: compact summary + Browse trigger (whole label opens picker) -->\n <label class=\"ui-file-upload-field\" [attr.for]=\"inputId\">\n <span class=\"ui-file-upload-field-text\" [class._placeholder]=\"!hasFiles()\">{{ fieldSummary() }}</span>\n <span class=\"ui-file-upload-browse\" aria-hidden=\"true\">{{ browseLabel() }}</span>\n </label>\n } @else {\n <!-- Drag mode: full drop zone -->\n <label class=\"ui-file-upload-zone\" [attr.for]=\"inputId\">\n <ui-icon class=\"ui-file-upload-zone-icon\" name=\"cloud-arrow-up\" size=\"lg\" />\n <span class=\"ui-file-upload-zone-content\">\n <span class=\"ui-file-upload-zone-title\">\n <span class=\"ui-file-upload-zone-link\">{{ dragLinkLabel() }}</span>\n <span class=\"ui-file-upload-zone-prompt\">{{ dragPromptLabel() }}</span>\n </span>\n @if (hint(); as h) {\n <span class=\"ui-file-upload-zone-hint\">{{ h }}</span>\n }\n </span>\n </label>\n\n <!-- Toolbar (custom, or default Upload/Clear actions) -->\n @if (toolbarTemplate(); as tpl) {\n <div class=\"ui-file-upload-toolbar\">\n <ng-container\n [ngTemplateOutlet]=\"tpl\"\n [ngTemplateOutletContext]=\"{ $implicit: files(), choose: chooseFn, upload: uploadFn, clear: clearFn }\"\n />\n </div>\n } @else if (showControls() && hasFiles()) {\n <div class=\"ui-file-upload-toolbar\">\n @if (!auto()) {\n <ui-button\n [label]=\"uploadLabel()\"\n [size]=\"size() === 'small' ? 'small' : 'default'\"\n icon=\"cloud-arrow-up\"\n [disabled]=\"!canUpload()\"\n (buttonClick)=\"upload()\"\n />\n }\n <ui-button\n [label]=\"cancelLabel()\"\n level=\"low\"\n [size]=\"size() === 'small' ? 'small' : 'default'\"\n icon=\"xmark\"\n (buttonClick)=\"clear()\"\n />\n </div>\n }\n }\n\n <!-- Content section: the file list -->\n @if (contentTemplate(); as tpl) {\n <div class=\"ui-file-upload-content\">\n <ng-container\n [ngTemplateOutlet]=\"tpl\"\n [ngTemplateOutletContext]=\"{ $implicit: files(), remove: removeFn, clear: clearFn }\"\n />\n </div>\n } @else if (showFileList() && hasFiles()) {\n <ul class=\"ui-file-upload-content\" role=\"list\">\n @for (f of files(); track f.id) {\n <li>\n @if (fileTemplate(); as tpl) {\n <ng-container\n [ngTemplateOutlet]=\"tpl\"\n [ngTemplateOutletContext]=\"{ $implicit: f, remove: removeFn }\"\n />\n } @else {\n <ui-file-upload-list [file]=\"f\" [size]=\"size()\" (remove)=\"remove($event)\" />\n }\n </li>\n }\n </ul>\n }\n\n <!-- Validation messages (assertive live region) -->\n @if (messages().length) {\n <div class=\"ui-file-upload-messages\" role=\"alert\" aria-live=\"assertive\">\n @for (msg of messages(); track msg) {\n <p class=\"ui-file-upload-message\">{{ msg }}</p>\n }\n </div>\n }\n</div>\n", styles: [".ui-file-upload{display:flex;flex-direction:column;gap:var(--units-default);width:100%;font-family:var(--fontfamily-base)}.ui-file-upload-input{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.ui-file-upload-field{display:flex;align-items:center;justify-content:space-between;gap:var(--units-sm);height:var(--size-components-default);padding-left:var(--units-md);overflow:hidden;background-color:var(--form-high-surface-default);border:var(--stroke-default) solid var(--form-high-stroke-default);border-radius:var(--radius-sm);color:var(--form-high-content-default);cursor:pointer;transition:background-color var(--transition-default) var(--transition-easeinout),border-color var(--transition-default) var(--transition-easeinout),color var(--transition-default) var(--transition-easeinout),box-shadow var(--transition-default) var(--transition-easeinout)}.ui-file-upload-field:hover{background-color:var(--form-high-surface-hover);border-color:var(--form-high-stroke-hover)}.ui-file-upload._small .ui-file-upload-field{height:var(--size-components-sm)}.ui-file-upload-field-text{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--size-typography-text-default);font-weight:var(--weight-regular)}.ui-file-upload-field-text._placeholder{color:var(--form-high-content-default);opacity:.75}.ui-file-upload._small .ui-file-upload-field-text{font-size:var(--size-typography-text-md)}.ui-file-upload-browse{display:inline-flex;align-items:center;align-self:stretch;flex:none;padding:0 var(--units-default);background-color:var(--actions-high-surface-default);color:var(--actions-high-content-default);font-size:var(--size-typography-text-default);font-weight:var(--weight-bold)}.ui-file-upload._small .ui-file-upload-browse{padding:0 var(--units-md);font-size:var(--size-typography-text-md)}.ui-file-upload-field:hover .ui-file-upload-browse{background-color:var(--actions-high-surface-hover)}.ui-file-upload-zone{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--units-lg);min-height:112px;padding:var(--units-default);background-color:var(--form-high-surface-default);border:var(--stroke-default) dashed var(--form-high-stroke-default);border-radius:var(--radius-sm);color:var(--form-high-content-default);text-align:center;cursor:pointer;transition:background-color var(--transition-default) var(--transition-easeinout),border-color var(--transition-default) var(--transition-easeinout),box-shadow var(--transition-default) var(--transition-easeinout)}.ui-file-upload-zone:hover{background-color:var(--form-high-surface-hover);border-color:var(--form-high-stroke-hover)}.ui-file-upload._small .ui-file-upload-zone{gap:var(--units-sm);min-height:94px}.ui-file-upload._dragging .ui-file-upload-zone{background-color:var(--form-high-surface-focused);border-style:solid;border-color:var(--form-high-stroke-focused)}.ui-file-upload-zone-icon{color:var(--form-high-content-default);line-height:0}.ui-file-upload-zone-content{display:flex;flex-direction:column;align-items:center;gap:var(--units-xs)}.ui-file-upload-zone-title{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:var(--units-2xs);font-size:var(--size-typography-text-default);font-weight:var(--weight-regular)}.ui-file-upload._small .ui-file-upload-zone-title{font-size:var(--size-typography-text-md)}.ui-file-upload-zone-link{color:var(--actions-low-content-default);font-weight:var(--weight-bold);text-decoration:underline}.ui-file-upload-zone-prompt{color:var(--form-high-content-default)}.ui-file-upload-zone-hint{color:var(--global-text-muted);font-size:var(--size-typography-text-md)}.ui-file-upload._small .ui-file-upload-zone-hint{font-size:var(--size-typography-text-sm)}.ui-file-upload-input:focus-visible~.ui-file-upload-field,.ui-file-upload-input:focus-visible~.ui-file-upload-zone{outline:none;border-color:var(--form-high-stroke-focused);box-shadow:0 0 0 var(--units-2xs) var(--form-high-stroke-focused)}.ui-file-upload-toolbar{display:flex;flex-wrap:wrap;gap:var(--units-sm)}.ui-file-upload-content{display:flex;flex-direction:column;gap:var(--units-sm);width:100%;margin:0;padding:0;list-style:none}.ui-file-upload-content li{display:block}.ui-file-upload-messages{display:flex;flex-direction:column;gap:var(--units-2xs)}.ui-file-upload-message{margin:0;color:var(--informative-errorhigh-content-default);font-size:var(--size-typography-text-md)}.ui-file-upload._disabled .ui-file-upload-field,.ui-file-upload._disabled .ui-file-upload-zone{background-color:var(--form-high-surface-disabled);border-color:var(--form-high-stroke-disabled);color:var(--form-high-content-disabled);cursor:not-allowed;pointer-events:none}.ui-file-upload._disabled .ui-file-upload-browse{background-color:var(--actions-high-surface-disabled);color:var(--actions-high-content-disabled)}\n"] }]
|
|
554
|
+
}], ctorParameters: () => [], propDecorators: { mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], accept: [{ type: i0.Input, args: [{ isSignal: true, alias: "accept", required: false }] }], maxFileSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxFileSize", required: false }] }], fileLimit: [{ type: i0.Input, args: [{ isSignal: true, alias: "fileLimit", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], auto: [{ type: i0.Input, args: [{ isSignal: true, alias: "auto", required: false }] }], customUpload: [{ type: i0.Input, args: [{ isSignal: true, alias: "customUpload", required: false }] }], url: [{ type: i0.Input, args: [{ isSignal: true, alias: "url", required: false }] }], method: [{ type: i0.Input, args: [{ isSignal: true, alias: "method", required: false }] }], fieldName: [{ type: i0.Input, args: [{ isSignal: true, alias: "fieldName", required: false }] }], withCredentials: [{ type: i0.Input, args: [{ isSignal: true, alias: "withCredentials", required: false }] }], showFileList: [{ type: i0.Input, args: [{ isSignal: true, alias: "showFileList", required: false }] }], showControls: [{ type: i0.Input, args: [{ isSignal: true, alias: "showControls", required: false }] }], browseLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "browseLabel", required: false }] }], chooseLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "chooseLabel", required: false }] }], uploadLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "uploadLabel", required: false }] }], cancelLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "cancelLabel", required: false }] }], dragLinkLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragLinkLabel", required: false }] }], dragPromptLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragPromptLabel", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], filesSummaryLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "filesSummaryLabel", required: false }] }], invalidTypeMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalidTypeMessage", required: false }] }], invalidSizeMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalidSizeMessage", required: false }] }], limitReachedMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "limitReachedMessage", required: false }] }], uploadErrorMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "uploadErrorMessage", required: false }] }], networkErrorMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "networkErrorMessage", required: false }] }], httpErrorMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "httpErrorMessage", required: false }] }], fileTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "fileTemplate", required: false }] }], contentTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "contentTemplate", required: false }] }], toolbarTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "toolbarTemplate", required: false }] }], selected: [{ type: i0.Output, args: ["selected"] }], filesChange: [{ type: i0.Output, args: ["filesChange"] }], uploadHandler: [{ type: i0.Output, args: ["uploadHandler"] }], uploaded: [{ type: i0.Output, args: ["uploaded"] }], uploadError: [{ type: i0.Output, args: ["uploadError"] }], removed: [{ type: i0.Output, args: ["removed"] }], cleared: [{ type: i0.Output, args: ["cleared"] }], fileInput: [{ type: i0.ViewChild, args: ['fileInput', { isSignal: true }] }] } });
|
|
555
|
+
|
|
556
|
+
/*
|
|
557
|
+
* Public API Surface of ui-kit/ui-file-upload
|
|
558
|
+
*
|
|
559
|
+
* Includes `ui-file-upload-list`: it renders the upload's own file model,
|
|
560
|
+
* so the two live in one entry point (a separate one would be a cycle).
|
|
561
|
+
*/
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Generated bundle index. Do not edit.
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
export { UiFileUpload, UiFileUploadList, formatFileSize, isFileTypeAccepted, isImageFile };
|
|
568
|
+
//# sourceMappingURL=4sh-ui-kit-ui-file-upload.mjs.map
|