@poadio/ui-elements 0.3.0 → 0.5.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/CHANGELOG.md +95 -0
- package/README.md +19 -2
- package/dist/accordion.d.ts +17 -1
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +19 -2
- package/dist/accordion.js.map +1 -1
- package/dist/avatar.d.ts +26 -2
- package/dist/avatar.d.ts.map +1 -1
- package/dist/avatar.js +1 -0
- package/dist/avatar.js.map +1 -1
- package/dist/badge.d.ts +15 -0
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js.map +1 -1
- package/dist/block.d.ts +22 -0
- package/dist/block.d.ts.map +1 -0
- package/dist/block.js +40 -0
- package/dist/block.js.map +1 -0
- package/dist/breadcrumb.d.ts +45 -0
- package/dist/breadcrumb.d.ts.map +1 -0
- package/dist/breadcrumb.js +60 -0
- package/dist/breadcrumb.js.map +1 -0
- package/dist/button-group.d.ts +12 -0
- package/dist/button-group.d.ts.map +1 -1
- package/dist/button-group.js +5 -0
- package/dist/button-group.js.map +1 -1
- package/dist/button.d.ts +16 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +4 -0
- package/dist/button.js.map +1 -1
- package/dist/card.d.ts +34 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +40 -0
- package/dist/card.js.map +1 -0
- package/dist/carousel.d.ts +95 -0
- package/dist/carousel.d.ts.map +1 -0
- package/dist/carousel.js +172 -0
- package/dist/carousel.js.map +1 -0
- package/dist/checkbox.d.ts +15 -0
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +5 -0
- package/dist/checkbox.js.map +1 -1
- package/dist/chip.d.ts +18 -0
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +5 -0
- package/dist/chip.js.map +1 -1
- package/dist/colorpicker.d.ts +21 -0
- package/dist/colorpicker.d.ts.map +1 -1
- package/dist/colorpicker.js +5 -0
- package/dist/colorpicker.js.map +1 -1
- package/dist/combo.d.ts +24 -1
- package/dist/combo.d.ts.map +1 -1
- package/dist/combo.js +6 -0
- package/dist/combo.js.map +1 -1
- package/dist/confirm.d.ts +2 -0
- package/dist/confirm.d.ts.map +1 -1
- package/dist/confirm.js.map +1 -1
- package/dist/datepicker.d.ts +35 -1
- package/dist/datepicker.d.ts.map +1 -1
- package/dist/datepicker.js +9 -0
- package/dist/datepicker.js.map +1 -1
- package/dist/dialog.d.ts +35 -2
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +14 -0
- package/dist/dialog.js.map +1 -1
- package/dist/divider.d.ts +8 -0
- package/dist/divider.d.ts.map +1 -1
- package/dist/divider.js +1 -0
- package/dist/divider.js.map +1 -1
- package/dist/field.d.ts +14 -2
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +3 -0
- package/dist/field.js.map +1 -1
- package/dist/fieldset.d.ts +23 -0
- package/dist/fieldset.d.ts.map +1 -0
- package/dist/fieldset.js +50 -0
- package/dist/fieldset.js.map +1 -0
- package/dist/filter-chip.d.ts +34 -0
- package/dist/filter-chip.d.ts.map +1 -0
- package/dist/filter-chip.js +41 -0
- package/dist/filter-chip.js.map +1 -0
- package/dist/held.d.ts +20 -0
- package/dist/held.d.ts.map +1 -0
- package/dist/held.js +61 -0
- package/dist/held.js.map +1 -0
- package/dist/icon.d.ts +14 -0
- package/dist/icon.d.ts.map +1 -1
- package/dist/icon.js.map +1 -1
- package/dist/image.d.ts +63 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +134 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +41 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/inplace.d.ts +20 -1
- package/dist/inplace.d.ts.map +1 -1
- package/dist/inplace.js +6 -0
- package/dist/inplace.js.map +1 -1
- package/dist/listbox.d.ts +126 -0
- package/dist/listbox.d.ts.map +1 -0
- package/dist/listbox.js +195 -0
- package/dist/listbox.js.map +1 -0
- package/dist/mask.d.ts +26 -0
- package/dist/mask.d.ts.map +1 -1
- package/dist/mask.js +9 -0
- package/dist/mask.js.map +1 -1
- package/dist/menu.d.ts +29 -0
- package/dist/menu.d.ts.map +1 -1
- package/dist/menu.js +11 -1
- package/dist/menu.js.map +1 -1
- package/dist/message.d.ts +23 -1
- package/dist/message.d.ts.map +1 -1
- package/dist/message.js +4 -0
- package/dist/message.js.map +1 -1
- package/dist/meter.d.ts +18 -2
- package/dist/meter.d.ts.map +1 -1
- package/dist/meter.js.map +1 -1
- package/dist/multiselect.d.ts +57 -2
- package/dist/multiselect.d.ts.map +1 -1
- package/dist/multiselect.js +8 -0
- package/dist/multiselect.js.map +1 -1
- package/dist/number.d.ts +20 -1
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +4 -0
- package/dist/number.js.map +1 -1
- package/dist/paginator.d.ts +14 -1
- package/dist/paginator.d.ts.map +1 -1
- package/dist/paginator.js +4 -0
- package/dist/paginator.js.map +1 -1
- package/dist/panel.d.ts +34 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/panel.js +57 -0
- package/dist/panel.js.map +1 -0
- package/dist/password.d.ts +18 -1
- package/dist/password.d.ts.map +1 -1
- package/dist/password.js +4 -0
- package/dist/password.js.map +1 -1
- package/dist/popover.d.ts +19 -0
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +6 -0
- package/dist/popover.js.map +1 -1
- package/dist/progress.d.ts +33 -0
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js.map +1 -1
- package/dist/radio.d.ts +15 -0
- package/dist/radio.d.ts.map +1 -1
- package/dist/radio.js +15 -1
- package/dist/radio.js.map +1 -1
- package/dist/rating.d.ts +26 -1
- package/dist/rating.d.ts.map +1 -1
- package/dist/rating.js +4 -0
- package/dist/rating.js.map +1 -1
- package/dist/scroll-top.d.ts +51 -0
- package/dist/scroll-top.d.ts.map +1 -0
- package/dist/scroll-top.js +65 -0
- package/dist/scroll-top.js.map +1 -0
- package/dist/segmented.d.ts +17 -0
- package/dist/segmented.d.ts.map +1 -1
- package/dist/segmented.js +4 -0
- package/dist/segmented.js.map +1 -1
- package/dist/select.d.ts +51 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +7 -0
- package/dist/select.js.map +1 -1
- package/dist/skeleton.d.ts +24 -0
- package/dist/skeleton.d.ts.map +1 -1
- package/dist/skeleton.js.map +1 -1
- package/dist/slider.d.ts +37 -0
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +4 -0
- package/dist/slider.js.map +1 -1
- package/dist/speed-dial.d.ts +86 -0
- package/dist/speed-dial.d.ts.map +1 -0
- package/dist/speed-dial.js +108 -0
- package/dist/speed-dial.js.map +1 -0
- package/dist/split-button.d.ts +17 -0
- package/dist/split-button.d.ts.map +1 -1
- package/dist/split-button.js +6 -0
- package/dist/split-button.js.map +1 -1
- package/dist/splitter.d.ts +77 -0
- package/dist/splitter.d.ts.map +1 -0
- package/dist/splitter.js +130 -0
- package/dist/splitter.js.map +1 -0
- package/dist/stepper.d.ts +23 -1
- package/dist/stepper.d.ts.map +1 -1
- package/dist/stepper.js +24 -2
- package/dist/stepper.js.map +1 -1
- package/dist/switch.d.ts +15 -0
- package/dist/switch.d.ts.map +1 -1
- package/dist/switch.js +5 -0
- package/dist/switch.js.map +1 -1
- package/dist/table-filters.d.ts +66 -0
- package/dist/table-filters.d.ts.map +1 -0
- package/dist/table-filters.js +174 -0
- package/dist/table-filters.js.map +1 -0
- package/dist/table-panel.d.ts +86 -0
- package/dist/table-panel.d.ts.map +1 -0
- package/dist/table-panel.js +349 -0
- package/dist/table-panel.js.map +1 -0
- package/dist/table.d.ts +276 -7
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +433 -40
- package/dist/table.js.map +1 -1
- package/dist/tabs.d.ts +24 -1
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +25 -2
- package/dist/tabs.js.map +1 -1
- package/dist/tag.d.ts +13 -1
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js +1 -0
- package/dist/tag.js.map +1 -1
- package/dist/timeline.d.ts +50 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +39 -0
- package/dist/timeline.js.map +1 -0
- package/dist/toast.d.ts +17 -0
- package/dist/toast.d.ts.map +1 -1
- package/dist/toast.js +4 -0
- package/dist/toast.js.map +1 -1
- package/dist/toggle-button.d.ts +17 -1
- package/dist/toggle-button.d.ts.map +1 -1
- package/dist/toggle-button.js +5 -0
- package/dist/toggle-button.js.map +1 -1
- package/dist/tooltip.d.ts +9 -0
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +4 -0
- package/dist/tooltip.js.map +1 -1
- package/dist/upload.d.ts +196 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +269 -0
- package/dist/upload.js.map +1 -0
- package/package.json +2 -2
- package/src/accordion.ts +23 -2
- package/src/avatar.ts +26 -2
- package/src/badge.ts +15 -0
- package/src/block.ts +48 -0
- package/src/breadcrumb.ts +85 -0
- package/src/button-group.ts +12 -0
- package/src/button.ts +16 -1
- package/src/card.ts +54 -0
- package/src/carousel.ts +212 -0
- package/src/checkbox.ts +15 -0
- package/src/chip.ts +18 -0
- package/src/colorpicker.ts +21 -0
- package/src/combo.ts +24 -1
- package/src/confirm.ts +2 -0
- package/src/datepicker.ts +35 -1
- package/src/dialog.ts +35 -2
- package/src/divider.ts +8 -0
- package/src/field.ts +14 -2
- package/src/fieldset.ts +57 -0
- package/src/filter-chip.ts +57 -0
- package/src/held.ts +57 -0
- package/src/icon.ts +14 -0
- package/src/image.ts +149 -0
- package/src/index.ts +31 -4
- package/src/inplace.ts +20 -1
- package/src/listbox.ts +236 -0
- package/src/mask.ts +26 -0
- package/src/menu.ts +33 -1
- package/src/message.ts +23 -1
- package/src/meter.ts +18 -2
- package/src/multiselect.ts +57 -2
- package/src/number.ts +20 -1
- package/src/paginator.ts +14 -1
- package/src/panel.ts +71 -0
- package/src/password.ts +18 -1
- package/src/popover.ts +19 -0
- package/src/progress.ts +33 -0
- package/src/radio.ts +21 -1
- package/src/rating.ts +26 -1
- package/src/scroll-top.ts +81 -0
- package/src/segmented.ts +17 -0
- package/src/select.ts +51 -1
- package/src/skeleton.ts +24 -0
- package/src/slider.ts +37 -0
- package/src/speed-dial.ts +140 -0
- package/src/split-button.ts +17 -0
- package/src/splitter.ts +151 -0
- package/src/stepper.ts +30 -2
- package/src/switch.ts +15 -0
- package/src/table-filters.ts +179 -0
- package/src/table-panel.ts +378 -0
- package/src/table.ts +557 -41
- package/src/tabs.ts +32 -2
- package/src/tag.ts +13 -1
- package/src/timeline.ts +66 -0
- package/src/toast.ts +17 -0
- package/src/toggle-button.ts +17 -1
- package/src/tooltip.ts +9 -0
- package/src/upload.ts +351 -0
package/src/tabs.ts
CHANGED
|
@@ -30,23 +30,53 @@ export interface TabData {
|
|
|
30
30
|
readonly closable?: boolean;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Déclaration d'un onglet dans un `<poad-tabs>` ; ses enfants sont le contenu de son panneau.
|
|
35
|
+
* @slot default Contenu du panneau de l'onglet.
|
|
36
|
+
*/
|
|
34
37
|
export class PoadTabElement extends PoadDeclarationElement {
|
|
35
|
-
static override props = {
|
|
38
|
+
static override props = {
|
|
39
|
+
/** Valeur qui identifie l'onglet ; sans elle, il est repéré par son rang. */
|
|
40
|
+
value: 'json',
|
|
41
|
+
/** Libellé de l'onglet. */
|
|
42
|
+
label: 'string',
|
|
43
|
+
/** Compteur affiché après le libellé ; `null` : aucun. */
|
|
44
|
+
count: 'json',
|
|
45
|
+
/** Icône avant le libellé. */
|
|
46
|
+
icon: 'string',
|
|
47
|
+
/** Onglet désactivé : ni clic ni clavier ne l'activent. */
|
|
48
|
+
disabled: 'boolean',
|
|
49
|
+
/** Petite croix dans l'onglet (évènement `tabclose` du groupe). */
|
|
50
|
+
closable: 'boolean',
|
|
51
|
+
} as const;
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
const isEnd = (n: Node) => n instanceof Element && n.getAttribute('slot') === 'end';
|
|
39
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Barre d'onglets et panneau de l'onglet actif.
|
|
58
|
+
* @slot default Les onglets : des `<poad-tab>`.
|
|
59
|
+
* @slot end Contenu en fin de barre.
|
|
60
|
+
* @fires change L'utilisateur change d'onglet ; `detail` : la valeur de l'onglet choisi, son rang s'il n'a pas de `value`.
|
|
61
|
+
* @fires tabclose Clic sur la croix d'un onglet `closable` ; `detail` : sa valeur (son rang sans `value`), l'application retire l'onglet.
|
|
62
|
+
*/
|
|
40
63
|
export class PoadTabsElement extends PoadElement {
|
|
41
64
|
static override props = {
|
|
42
65
|
value: 'json', activeIndex: 'number', variant: 'string', size: 'string', stretch: 'boolean', scrollable: 'boolean', keepAlive: 'boolean',
|
|
43
66
|
} as const;
|
|
67
|
+
/** Onglet actif par sa valeur (prime sur `activeIndex`). */
|
|
44
68
|
declare value?: unknown;
|
|
69
|
+
/** Onglet actif par son rang (sans `value`). */
|
|
45
70
|
declare activeIndex?: number;
|
|
71
|
+
/** Apparence de la barre : `line`, `pill` ou `enclosed`. */
|
|
46
72
|
declare variant?: TabsVariant;
|
|
73
|
+
/** Taille : `sm` ou `md`. */
|
|
47
74
|
declare size?: 'sm' | 'md';
|
|
75
|
+
/** Onglets de même largeur, sur toute la barre. */
|
|
48
76
|
declare stretch?: boolean;
|
|
77
|
+
/** Barre qui défile, flèches quand elle déborde. */
|
|
49
78
|
declare scrollable?: boolean;
|
|
79
|
+
/** Garder les panneaux déjà rendus (cachés) au lieu de les retirer. */
|
|
50
80
|
declare keepAlive?: boolean;
|
|
51
81
|
private rendered = new Set<number>();
|
|
52
82
|
private overflow = false;
|
package/src/tag.ts
CHANGED
|
@@ -9,14 +9,26 @@ import { h } from './dom.js';
|
|
|
9
9
|
import { PoadElement } from './element.js';
|
|
10
10
|
import { icon } from './icon.js';
|
|
11
11
|
|
|
12
|
+
/** @slot default Texte de l'étiquette, après `value`. */
|
|
12
13
|
export class PoadTagElement extends PoadElement {
|
|
13
14
|
static override props = { value: 'string', severity: 'string', size: 'string', rounded: 'boolean', dot: 'boolean', icon: 'string' } as const;
|
|
15
|
+
/** Texte de l'étiquette (avant le contenu écrit dans la balise). */
|
|
14
16
|
declare value?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Couleur : `primary`, `success`, `warning`, `danger`, `info` ou `neutral`.
|
|
19
|
+
* @default 'primary'
|
|
20
|
+
*/
|
|
15
21
|
declare severity?: TagSeverity;
|
|
22
|
+
/**
|
|
23
|
+
* Taille : `sm` ou `md`.
|
|
24
|
+
* @default 'md'
|
|
25
|
+
*/
|
|
16
26
|
declare size?: 'sm' | 'md';
|
|
27
|
+
/** Coins en pilule. */
|
|
17
28
|
declare rounded?: boolean;
|
|
29
|
+
/** Point de couleur avant le texte. */
|
|
18
30
|
declare dot?: boolean;
|
|
19
|
-
/** Nom d'une icône du jeu de la bibliothèque. */
|
|
31
|
+
/** Nom d'une icône du jeu de la bibliothèque, affichée avant le texte. */
|
|
20
32
|
declare icon?: string;
|
|
21
33
|
|
|
22
34
|
protected render() {
|
package/src/timeline.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-timeline events='[{"title":"Commissioned","severity":"success"},{"title":"Inspection","icon":"check"}]'
|
|
3
|
+
* align="alternate" active-index="1"></poad-timeline>
|
|
4
|
+
*
|
|
5
|
+
* Chronologie : liste (`role="list"`, un `listitem` par évènement) ; chaque évènement a un marqueur (point coloré par
|
|
6
|
+
* `color` / `severity`, ou icône `icon` dans un rond), un connecteur vers le suivant, un contenu (`label`, sinon
|
|
7
|
+
* `title`, sinon la valeur) et un texte en regard facultatif. Les évènements de rang ≤ `activeIndex` sont passés.
|
|
8
|
+
* Classes, couleur et texte de @poadio/ui-core — même DOM que `poad-timeline` d'ui-angular. Rendus sur mesure par
|
|
9
|
+
* propriétés-fonctions (`renderContent`, `renderOpposite`, `renderMarker` : `(event, index) => Node | string`). Style :
|
|
10
|
+
* `@poadio/ui-core/timeline.css` (et `icon.css`).
|
|
11
|
+
*/
|
|
12
|
+
import { timelineActiveIndex, timelineClasses, timelineEventClasses, timelineIcon, timelineMarkerColor, timelineText, type TimelineAlign } from '@poadio/ui-core';
|
|
13
|
+
import { h, type Child } from './dom.js';
|
|
14
|
+
import { PoadElement } from './element.js';
|
|
15
|
+
import { icon } from './icon.js';
|
|
16
|
+
|
|
17
|
+
/** Rendu sur mesure d'une partie d'un évènement. */
|
|
18
|
+
export type PoadTimelineRender = (event: unknown, index: number) => Node | string | null;
|
|
19
|
+
|
|
20
|
+
/** Chronologie. */
|
|
21
|
+
export class PoadTimelineElement extends PoadElement {
|
|
22
|
+
static override props = { events: 'json', align: 'string', layout: 'string', dense: 'boolean', activeIndex: 'number' } as const;
|
|
23
|
+
static override functions = ['renderContent', 'renderOpposite', 'renderMarker'] as const;
|
|
24
|
+
/** Les évènements, dans l'ordre ; objets (`label` ou `title`, `icon`, `color`, `severity`) ou valeurs simples. */
|
|
25
|
+
declare events?: readonly unknown[];
|
|
26
|
+
/**
|
|
27
|
+
* Position du contenu par rapport à la ligne : `left`, `right`, `alternate` ; en horizontal, `top` ou `bottom`.
|
|
28
|
+
* @default 'left'
|
|
29
|
+
*/
|
|
30
|
+
declare align?: TimelineAlign;
|
|
31
|
+
/**
|
|
32
|
+
* Ligne verticale (défaut) ou horizontale.
|
|
33
|
+
* @default 'vertical'
|
|
34
|
+
*/
|
|
35
|
+
declare layout?: 'vertical' | 'horizontal';
|
|
36
|
+
/** Évènements resserrés. */
|
|
37
|
+
declare dense?: boolean;
|
|
38
|
+
/** Rang de l'évènement courant : ceux de rang inférieur ou égal sont passés (marqueur et connecteur en accent). */
|
|
39
|
+
declare activeIndex?: number | null;
|
|
40
|
+
/** Contenu sur mesure de chaque évènement (propriété seulement). */
|
|
41
|
+
declare renderContent?: PoadTimelineRender | null;
|
|
42
|
+
/** Texte en regard de chaque évènement, une date… (propriété seulement). */
|
|
43
|
+
declare renderOpposite?: PoadTimelineRender | null;
|
|
44
|
+
/** Marqueur sur mesure (propriété seulement). */
|
|
45
|
+
declare renderMarker?: PoadTimelineRender | null;
|
|
46
|
+
|
|
47
|
+
protected render() {
|
|
48
|
+
const events = Array.isArray(this.events) ? this.events : [];
|
|
49
|
+
const align = this.align || 'left';
|
|
50
|
+
const active = timelineActiveIndex(this.activeIndex ?? null);
|
|
51
|
+
const icons = this.icons();
|
|
52
|
+
return h('div', { role: 'list', class: timelineClasses({ align, layout: this.layout, dense: this.dense }) }, events.map((e, i): Child => {
|
|
53
|
+
const ic = timelineIcon(e);
|
|
54
|
+
const color = timelineMarkerColor(e);
|
|
55
|
+
return h('div', { role: 'listitem', class: timelineEventClasses(i, Number.isNaN(active) ? null : active, align) }, [
|
|
56
|
+
h('div', { class: 'poad-timeline__opposite' }, this.renderOpposite?.(e, i) ?? null),
|
|
57
|
+
h('div', { class: 'poad-timeline__separator' }, [
|
|
58
|
+
h('div', { class: ic ? 'poad-timeline__marker has-icon' : 'poad-timeline__marker', style: color ? { '--_c': color } : null },
|
|
59
|
+
this.renderMarker ? this.renderMarker(e, i) : ic ? icon(icons, ic, { size: 14 }) : null),
|
|
60
|
+
i < events.length - 1 ? h('div', { class: 'poad-timeline__connector' }) : null,
|
|
61
|
+
]),
|
|
62
|
+
h('div', { class: 'poad-timeline__content' }, this.renderContent ? this.renderContent(e, i) : timelineText(e)),
|
|
63
|
+
]);
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/toast.ts
CHANGED
|
@@ -28,7 +28,9 @@ export interface PoadToastAction {
|
|
|
28
28
|
readonly severity?: 'primary' | 'secondary' | 'danger';
|
|
29
29
|
}
|
|
30
30
|
export interface PoadToastMessage extends ToastMessageLike {
|
|
31
|
+
/** Données libres de l'application, jointes au message. */
|
|
31
32
|
data?: unknown;
|
|
33
|
+
/** Boutons d'action du toast (`label`, `click`, `severity`). */
|
|
32
34
|
actions?: readonly PoadToastAction[];
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -37,9 +39,13 @@ type Shortcut = (summary: string, detail?: string, opts?: Partial<PoadToastMessa
|
|
|
37
39
|
/** Une file de toasts, appelable : `service(message)` = `service.add(message)`. */
|
|
38
40
|
export interface PoadToastService extends ToastStore<PoadToastMessage> {
|
|
39
41
|
(message: PoadToastMessage): PoadToastMessage;
|
|
42
|
+
/** Ajoute un message de succès (titre, détail, autres options) et le rend. */
|
|
40
43
|
success: Shortcut;
|
|
44
|
+
/** Ajoute un message d'information (titre, détail, autres options) et le rend. */
|
|
41
45
|
info: Shortcut;
|
|
46
|
+
/** Ajoute un avertissement (titre, détail, autres options) et le rend. */
|
|
42
47
|
warn: Shortcut;
|
|
48
|
+
/** Ajoute un message d'erreur (titre, détail, autres options) et le rend. */
|
|
43
49
|
error: Shortcut;
|
|
44
50
|
}
|
|
45
51
|
|
|
@@ -66,17 +72,28 @@ export const poadToast: PoadToastService = service(() => {
|
|
|
66
72
|
document.body.append(document.createElement(tag));
|
|
67
73
|
});
|
|
68
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @fires close {PoadToastMessage} Un toast sort (croix, durée de vie, trop-plein) ; reçoit son message.
|
|
77
|
+
* @fires toastclick {PoadToastMessage} Un toast est cliqué ; reçoit son message.
|
|
78
|
+
*/
|
|
69
79
|
export class PoadToastElement extends PoadElement {
|
|
70
80
|
static override props = {
|
|
71
81
|
position: 'string', toastKey: 'string', life: 'number', maxVisible: 'number', preventDuplicates: 'boolean', showProgress: 'boolean', zIndex: 'string',
|
|
72
82
|
} as const;
|
|
73
83
|
static override functions = ['service', 'renderItem'] as const;
|
|
84
|
+
/** Coin de la pile : `top-right`, `top-left`, `bottom-right`, `bottom-left`, `top-center` ou `bottom-center`. */
|
|
74
85
|
declare position?: ToastPosition;
|
|
86
|
+
/** Clé des messages montrés (sans clé : les messages sans clé). */
|
|
75
87
|
declare toastKey?: string;
|
|
88
|
+
/** Durée de vie par défaut d'un toast (ms), en pause au survol. */
|
|
76
89
|
declare life?: number;
|
|
90
|
+
/** Nombre maximal de toasts affichés ; au-delà, les plus anciens sortent. */
|
|
77
91
|
declare maxVisible?: number;
|
|
92
|
+
/** Refuse un message identique (titre, détail, sévérité) à un toast affiché. */
|
|
78
93
|
declare preventDuplicates?: boolean;
|
|
94
|
+
/** Barre qui montre la durée de vie restante. */
|
|
79
95
|
declare showProgress?: boolean;
|
|
96
|
+
/** `z-index` de la pile. */
|
|
80
97
|
declare zIndex?: string;
|
|
81
98
|
/** La file montrée (défaut : `poadToast`). */
|
|
82
99
|
declare service?: PoadToastService;
|
package/src/toggle-button.ts
CHANGED
|
@@ -12,23 +12,39 @@ import { h } from './dom.js';
|
|
|
12
12
|
import { PoadFormElement } from './element.js';
|
|
13
13
|
import { icon } from './icon.js';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @fires input Nouvelle valeur, au geste de l'utilisateur seulement (une valeur imposée par l'application n'émet rien).
|
|
17
|
+
* @fires change Nouvelle valeur, au geste de l'utilisateur seulement (une valeur imposée par l'application n'émet rien).
|
|
18
|
+
* @slot default Contenu ajouté après l'icône et le libellé, dans le bouton.
|
|
19
|
+
*/
|
|
15
20
|
export class PoadToggleButtonElement extends PoadFormElement {
|
|
16
21
|
static override props = {
|
|
17
22
|
pressed: 'boolean', onLabel: 'string', offLabel: 'string', onIcon: 'string', offIcon: 'string', severity: 'string', size: 'string',
|
|
18
23
|
disabled: 'boolean', readonly: 'boolean', ariaLabel: 'string', name: 'string', value: 'string',
|
|
19
24
|
} as const;
|
|
25
|
+
/** État enfoncé ; l'attribut donne l'état de départ et celui de `form.reset()`. */
|
|
20
26
|
declare pressed?: boolean;
|
|
27
|
+
/** Libellé à l'état enfoncé (le nom accessible suit). */
|
|
21
28
|
declare onLabel?: string;
|
|
29
|
+
/** Libellé à l'état relâché (le nom accessible suit). */
|
|
22
30
|
declare offLabel?: string;
|
|
31
|
+
/** Icône nommée à l'état enfoncé. */
|
|
23
32
|
declare onIcon?: string;
|
|
33
|
+
/** Icône nommée à l'état relâché. */
|
|
24
34
|
declare offIcon?: string;
|
|
25
|
-
/**
|
|
35
|
+
/** Couleur à l'état enfoncé. */
|
|
26
36
|
declare severity?: ButtonSeverity;
|
|
37
|
+
/** Taille : `sm`, `md` ou `lg`. */
|
|
27
38
|
declare size?: ButtonSize;
|
|
39
|
+
/** Désactivé : hors tabulation, aucun geste. */
|
|
28
40
|
declare disabled?: boolean;
|
|
41
|
+
/** Lecture seule : atteignable au clavier, mais figé. */
|
|
29
42
|
declare readonly?: boolean;
|
|
43
|
+
/** Nom accessible, pour un bouton icône seule. */
|
|
30
44
|
declare ariaLabel: string | null;
|
|
45
|
+
/** Nom du champ soumis avec le `<form>`. */
|
|
31
46
|
declare name?: string;
|
|
47
|
+
/** Valeur soumise quand le bouton est enfoncé ; défaut `on`. */
|
|
32
48
|
declare value?: string;
|
|
33
49
|
protected readonly resetProps = ['pressed'];
|
|
34
50
|
|
package/src/tooltip.ts
CHANGED
|
@@ -16,6 +16,10 @@ import { h } from './dom.js';
|
|
|
16
16
|
import { PoadElement } from './element.js';
|
|
17
17
|
import { FloatingTracker, Presence, arrowStyle, controlOf } from './floating.js';
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Info-bulle sur un élément.
|
|
21
|
+
* @slot default L'élément décrit (un seul).
|
|
22
|
+
*/
|
|
19
23
|
export class PoadTooltipElement extends PoadElement {
|
|
20
24
|
static override props = {
|
|
21
25
|
text: 'string', placement: 'string', delay: 'number', hideDelay: 'number', disabled: 'boolean', maxWidth: 'number', event: 'string',
|
|
@@ -24,10 +28,15 @@ export class PoadTooltipElement extends PoadElement {
|
|
|
24
28
|
declare text?: string;
|
|
25
29
|
/** Côté voulu (défaut `top`), retourné s'il ne tient pas. */
|
|
26
30
|
declare placement?: FloatingSide;
|
|
31
|
+
/** Délai d'apparition (ms, défaut 300). */
|
|
27
32
|
declare delay?: number;
|
|
33
|
+
/** Délai de disparition (ms, défaut 0). */
|
|
28
34
|
declare hideDelay?: number;
|
|
35
|
+
/** Désactive l'info-bulle. */
|
|
29
36
|
declare disabled?: boolean;
|
|
37
|
+
/** Largeur maximale (px, défaut 280). */
|
|
30
38
|
declare maxWidth?: number;
|
|
39
|
+
/** `hover` | `focus` | `both` (défaut). */
|
|
31
40
|
declare event?: TooltipTrigger;
|
|
32
41
|
private state = TOOLTIP_INITIAL;
|
|
33
42
|
private open = false;
|
package/src/upload.ts
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-upload name="attachments" multiple accept="image/*,.pdf" max-file-size="5000000" max-files="5"></poad-upload>
|
|
3
|
+
*
|
|
4
|
+
* Envoi de fichiers. Modes : `advanced` (zone de dépôt + liste + boutons), `dropzone` (zone et liste), `basic` (un
|
|
5
|
+
* bouton). Le choix passe par un `<input type="file">` caché (hors tabulation) que la zone (`role="button"` : clic,
|
|
6
|
+
* Entrée, Espace, dépôt) ou le bouton ouvrent ; chaque fichier est validé (type, poids, nombre) avec le message du
|
|
7
|
+
* catalogue ; une ligne se retire au clavier (le focus passe au bouton voisin, sinon à la zone). Envoi : `url`
|
|
8
|
+
* (XMLHttpRequest du socle, progression), `custom-upload` + `uploadrequest` (l'application envoie et rapporte par
|
|
9
|
+
* `progress(i, %)` / `done(i, ok, message?)`), ou `select-only`. Participe aux formulaires : avec `name`, les fichiers
|
|
10
|
+
* valides partent avec le `<form>` (une entrée par fichier) ; `required` ; `form.reset()` vide la liste. Validation,
|
|
11
|
+
* lignes, focus et envoi de @poadio/ui-core (`uploadAdd`, `uploadRemove`, `uploadSend`…) — même DOM que `poad-upload`
|
|
12
|
+
* d'ui-angular. Style : `@poadio/ui-core/upload.css` (et `button.css`, `progress.css`, `icon.css`).
|
|
13
|
+
*/
|
|
14
|
+
import {
|
|
15
|
+
UPLOAD_LIVE_PROPS, buttonClasses, progressBarWidth, uploadAnnouncement, progressClasses, progressTrackProps, uploadAdd, uploadClasses, uploadComplete, uploadFocusAfterRemove, uploadFormatSize, uploadIconFor, uploadInputProps,
|
|
16
|
+
uploadIsError, uploadItemClasses, uploadPatch, uploadPending, uploadRejectionText, uploadRemove, uploadSend, uploadStatusIcon, uploadZoneKey, uploadZoneProps,
|
|
17
|
+
type ButtonOptions, type UploadEntry, type UploadLimits, type UploadMode,
|
|
18
|
+
} from '@poadio/ui-core';
|
|
19
|
+
import { button } from './button.js';
|
|
20
|
+
import { h, type Child, type Props } from './dom.js';
|
|
21
|
+
import { PoadFormElement } from './element.js';
|
|
22
|
+
import { icon } from './icon.js';
|
|
23
|
+
|
|
24
|
+
/** Un bouton de la bibliothèque qui porte aussi une classe de partie (`poad-upload__remove`…). */
|
|
25
|
+
const part = (options: ButtonOptions, cls: string, props: Props, children: Child) => button(options, { ...props, class: [buttonClasses(options), cls] }, children);
|
|
26
|
+
|
|
27
|
+
/** Une ligne de la liste : le fichier, son état (`pending`, `uploading`, `done`, `error`, `invalid`), sa progression, son message, son aperçu. */
|
|
28
|
+
export type PoadUploadFile = UploadEntry<File>;
|
|
29
|
+
/** Envoi par l'application : les fichiers, et les rappels de progression et de fin (par indice dans `files`). */
|
|
30
|
+
export interface PoadUploadRequest {
|
|
31
|
+
readonly files: readonly PoadUploadFile[];
|
|
32
|
+
readonly progress: (index: number, percent: number) => void;
|
|
33
|
+
readonly done: (index: number, ok: boolean, message?: string) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Envoi de fichiers.
|
|
38
|
+
* @fires input La liste change par un geste (ajout, retrait) ; `detail` : la liste.
|
|
39
|
+
* @fires change La liste change par un geste (ajout, retrait) ; `detail` : la liste.
|
|
40
|
+
* @fires fileselect Fichiers choisis et valides ; `detail` : ces lignes.
|
|
41
|
+
* @fires fileremove Une ligne retirée par l'utilisateur ; `detail` : la ligne.
|
|
42
|
+
* @fires clear La liste vidée (« tout retirer »).
|
|
43
|
+
* @fires uploadrequest Envoi par l'application (`custom-upload`, ou sans `url`) ; `detail` : `{ files, progress, done }`.
|
|
44
|
+
* @fires uploadprogress Progression d'un fichier ; `detail` : `{ file, percent }`.
|
|
45
|
+
* @fires uploaded Un fichier envoyé ; `detail` : `{ file, response? }`.
|
|
46
|
+
* @fires uploaderror Un envoi en échec ; `detail` : `{ file, error }`.
|
|
47
|
+
* @fires uploadcomplete Plus rien en attente ni en cours ; `detail` : la liste finale.
|
|
48
|
+
*/
|
|
49
|
+
export class PoadUploadElement extends PoadFormElement {
|
|
50
|
+
static override props = {
|
|
51
|
+
mode: 'string', url: 'string', method: 'string', headers: 'json', withCredentials: 'boolean', fieldName: 'string', customUpload: 'boolean', selectOnly: 'boolean',
|
|
52
|
+
multiple: 'boolean', accept: 'string', maxFileSize: 'number', maxFiles: 'number', auto: 'boolean', disabled: 'boolean', previews: 'boolean', chooseLabel: 'string',
|
|
53
|
+
uploadLabel: 'string', cancelLabel: 'string', dropLabel: 'string', browseLabel: 'string', hint: 'string', invalidFileSizeMessage: 'string',
|
|
54
|
+
invalidFileTypeMessage: 'string', invalidFileLimitMessage: 'string', showUploadButton: 'boolean', showCancelButton: 'boolean', severity: 'string', size: 'string',
|
|
55
|
+
uploadTimeout: 'number', name: 'string', required: 'boolean',
|
|
56
|
+
} as const;
|
|
57
|
+
/**
|
|
58
|
+
* Présentation : `advanced` (zone, liste, boutons), `dropzone` (zone et liste) ou `basic` (un bouton).
|
|
59
|
+
* @default 'advanced'
|
|
60
|
+
*/
|
|
61
|
+
declare mode?: UploadMode;
|
|
62
|
+
/** Adresse d'envoi (`multipart/form-data`) ; vide : envoi par l'application (`uploadrequest`). */
|
|
63
|
+
declare url?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Méthode HTTP de l'envoi.
|
|
66
|
+
* @default 'POST'
|
|
67
|
+
*/
|
|
68
|
+
declare method?: 'POST' | 'PUT';
|
|
69
|
+
/** En-têtes HTTP de l'envoi (JSON). */
|
|
70
|
+
declare headers?: Readonly<Record<string, string>>;
|
|
71
|
+
/** Envoi avec les témoins (cookies) d'un autre domaine. */
|
|
72
|
+
declare withCredentials?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Nom du champ du fichier dans le `FormData` de l'envoi.
|
|
75
|
+
* @default 'file'
|
|
76
|
+
*/
|
|
77
|
+
declare fieldName?: string;
|
|
78
|
+
/** L'application envoie elle-même : `uploadrequest` porte les fichiers et les rappels `progress` / `done`. */
|
|
79
|
+
declare customUpload?: boolean;
|
|
80
|
+
/** Choix seulement, aucun envoi : les fichiers partent avec le formulaire (`name`), ou l'application lit `files`. */
|
|
81
|
+
declare selectOnly?: boolean;
|
|
82
|
+
/** Plusieurs fichiers (sinon un nouveau choix remplace le précédent). */
|
|
83
|
+
declare multiple?: boolean;
|
|
84
|
+
/** Types acceptés, comme l'attribut HTML (`image/*,.pdf`) ; vide : tout. */
|
|
85
|
+
declare accept?: string;
|
|
86
|
+
/** Poids maximal d'un fichier (octets). */
|
|
87
|
+
declare maxFileSize?: number;
|
|
88
|
+
/** Nombre maximal de fichiers valides dans la liste. */
|
|
89
|
+
declare maxFiles?: number;
|
|
90
|
+
/** Envoi dès le choix. */
|
|
91
|
+
declare auto?: boolean;
|
|
92
|
+
/** Désactivé (aussi par un `<fieldset disabled>`) : la zone sort de la tabulation, rien ne s'ajoute. */
|
|
93
|
+
declare disabled?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Vignettes des images (adresses `blob:` locales, libérées au retrait).
|
|
96
|
+
* @default true
|
|
97
|
+
*/
|
|
98
|
+
declare previews?: boolean;
|
|
99
|
+
/** Libellé du bouton du mode `basic` (défaut : le catalogue, `file.choose`). */
|
|
100
|
+
declare chooseLabel?: string;
|
|
101
|
+
/** Libellé du bouton d'envoi (défaut : le catalogue, `file.upload`). */
|
|
102
|
+
declare uploadLabel?: string;
|
|
103
|
+
/** Libellé du bouton qui vide la liste (défaut : le catalogue, `file.removeAll`). */
|
|
104
|
+
declare cancelLabel?: string;
|
|
105
|
+
/** Titre de la zone de dépôt (défaut : le catalogue, `file.drop`). */
|
|
106
|
+
declare dropLabel?: string;
|
|
107
|
+
/** Seconde ligne de la zone (défaut : le catalogue, `file.browse`). */
|
|
108
|
+
declare browseLabel?: string;
|
|
109
|
+
/** Aide sous les textes de la zone (types, poids maximal…). */
|
|
110
|
+
declare hint?: string;
|
|
111
|
+
/** Message d'un fichier trop lourd ; `{max}` reçoit le poids maximal (défaut : le catalogue, `file.tooLarge`). */
|
|
112
|
+
declare invalidFileSizeMessage?: string;
|
|
113
|
+
/** Message d'un type refusé (défaut : le catalogue, `file.invalidType`). */
|
|
114
|
+
declare invalidFileTypeMessage?: string;
|
|
115
|
+
/** Message au-delà de `max-files` ; `{max}` reçoit la limite (défaut : le catalogue, `file.limitReached`). */
|
|
116
|
+
declare invalidFileLimitMessage?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Bouton d'envoi (mode `advanced`, ni `auto` ni `select-only`).
|
|
119
|
+
* @default true
|
|
120
|
+
*/
|
|
121
|
+
declare showUploadButton?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Bouton « tout retirer » (mode `advanced`).
|
|
124
|
+
* @default true
|
|
125
|
+
*/
|
|
126
|
+
declare showCancelButton?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Couleur du bouton du mode `basic`.
|
|
129
|
+
* @default 'primary'
|
|
130
|
+
*/
|
|
131
|
+
declare severity?: 'primary' | 'secondary';
|
|
132
|
+
/**
|
|
133
|
+
* Taille des boutons.
|
|
134
|
+
* @default 'md'
|
|
135
|
+
*/
|
|
136
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
137
|
+
/** Délai maximal d'un envoi HTTP (ms) ; 0 : aucun. */
|
|
138
|
+
declare uploadTimeout?: number;
|
|
139
|
+
/** Nom du champ dans le formulaire (une entrée par fichier valide). */
|
|
140
|
+
declare name?: string;
|
|
141
|
+
/** Au moins un fichier valide est requis. */
|
|
142
|
+
declare required?: boolean;
|
|
143
|
+
protected readonly resetProps = [];
|
|
144
|
+
private list: readonly PoadUploadFile[] = [];
|
|
145
|
+
private drag = false;
|
|
146
|
+
private announce = '';
|
|
147
|
+
private seq = 0;
|
|
148
|
+
|
|
149
|
+
/** La liste : fichiers valides et refusés, avec leur état (lecture seule). */
|
|
150
|
+
get files(): readonly PoadUploadFile[] {
|
|
151
|
+
return this.list;
|
|
152
|
+
}
|
|
153
|
+
protected formValue() {
|
|
154
|
+
const valid = this.list.filter((f) => f.status !== 'invalid');
|
|
155
|
+
if (!this.name || !valid.length) return { value: null, missing: !valid.length };
|
|
156
|
+
const data = new FormData();
|
|
157
|
+
for (const f of valid) data.append(this.name, f.file, f.name);
|
|
158
|
+
return { value: data, missing: false };
|
|
159
|
+
}
|
|
160
|
+
override formResetCallback(): void {
|
|
161
|
+
this.list.forEach((f) => this.revoke(f));
|
|
162
|
+
this.list = [];
|
|
163
|
+
this.update();
|
|
164
|
+
}
|
|
165
|
+
override disconnectedCallback(): void {
|
|
166
|
+
super.disconnectedCallback();
|
|
167
|
+
this.list.forEach((f) => this.revoke(f));
|
|
168
|
+
}
|
|
169
|
+
private revoke(f: PoadUploadFile): void {
|
|
170
|
+
if (f.preview && typeof URL !== 'undefined' && URL.revokeObjectURL) URL.revokeObjectURL(f.preview);
|
|
171
|
+
}
|
|
172
|
+
private sizeText(bytes: number): string {
|
|
173
|
+
const { t, locale } = this.i18n();
|
|
174
|
+
return uploadFormatSize(bytes, (k, p) => t(k as never, p), locale);
|
|
175
|
+
}
|
|
176
|
+
private commit(next: readonly PoadUploadFile[]): void {
|
|
177
|
+
this.list = next;
|
|
178
|
+
this.update();
|
|
179
|
+
}
|
|
180
|
+
private patchFile(id: number, p: Partial<PoadUploadFile>): void {
|
|
181
|
+
this.commit(uploadPatch(this.list, id, p));
|
|
182
|
+
}
|
|
183
|
+
private checkComplete(): void {
|
|
184
|
+
if (uploadComplete(this.list)) this.emit('uploadcomplete', this.list);
|
|
185
|
+
}
|
|
186
|
+
private hasFocus(): boolean {
|
|
187
|
+
return this.contains(this.ownerDocument.activeElement);
|
|
188
|
+
}
|
|
189
|
+
private focusAfter(index: number): void {
|
|
190
|
+
(index >= 0 ? this.querySelectorAll<HTMLElement>('.poad-upload__remove')[index] : this.querySelector<HTMLElement>('.poad-upload__zone, .poad-upload__choose'))?.focus();
|
|
191
|
+
}
|
|
192
|
+
/** Ouvre le choix des fichiers du système (rien si désactivé). */
|
|
193
|
+
open(): void {
|
|
194
|
+
if (!this.inactive) this.querySelector<HTMLInputElement>('.poad-upload__input')?.click();
|
|
195
|
+
}
|
|
196
|
+
/** Ajoute des fichiers (validation taille / type / limite). */
|
|
197
|
+
addFiles(list: readonly File[]): void {
|
|
198
|
+
if (!list.length) return;
|
|
199
|
+
const limits: UploadLimits = { accept: this.accept, maxFileSize: this.maxFileSize ?? null, maxFiles: this.maxFiles ?? null, multiple: !!this.multiple };
|
|
200
|
+
const { text } = this.i18n();
|
|
201
|
+
const res = uploadAdd(this.list, list, limits, {
|
|
202
|
+
nextId: () => ++this.seq,
|
|
203
|
+
message: (r) => uploadRejectionText(r, limits, { text: (o, k, p) => text(o, k, p), size: (b) => this.sizeText(b) }, {
|
|
204
|
+
type: this.invalidFileTypeMessage, size: this.invalidFileSizeMessage, limit: this.invalidFileLimitMessage,
|
|
205
|
+
}),
|
|
206
|
+
preview: (f) => (this.previews !== false && typeof URL !== 'undefined' && URL.createObjectURL ? URL.createObjectURL(f) : undefined),
|
|
207
|
+
});
|
|
208
|
+
res.dropped.forEach((f) => this.revoke(f));
|
|
209
|
+
this.announce = uploadAnnouncement(res.added, (name, message) => this.i18n().t('file.rejected', { name, message }));
|
|
210
|
+
this.commit(res.files);
|
|
211
|
+
this.emit('fileselect', res.accepted);
|
|
212
|
+
this.changed(this.list);
|
|
213
|
+
if (this.auto && !this.selectOnly) this.upload();
|
|
214
|
+
}
|
|
215
|
+
/** Retire la ligne `index` (pas pendant son envoi) ; le focus passe au bouton « retirer » voisin, sinon à la zone. */
|
|
216
|
+
removeFile(index: number): void {
|
|
217
|
+
const f = this.list[index];
|
|
218
|
+
if (!f) return;
|
|
219
|
+
const res = uploadRemove(this.list, f.id);
|
|
220
|
+
if (!res.removed) return;
|
|
221
|
+
const refocus = this.hasFocus();
|
|
222
|
+
this.revoke(f);
|
|
223
|
+
this.commit(res.files);
|
|
224
|
+
this.emit('fileremove', f);
|
|
225
|
+
this.changed(this.list);
|
|
226
|
+
if (refocus) this.focusAfter(uploadFocusAfterRemove(res.files.length, index));
|
|
227
|
+
}
|
|
228
|
+
/** Vide la liste. */
|
|
229
|
+
clear(): void {
|
|
230
|
+
const refocus = this.hasFocus();
|
|
231
|
+
this.list.forEach((f) => this.revoke(f));
|
|
232
|
+
this.commit([]);
|
|
233
|
+
this.emit('clear');
|
|
234
|
+
this.changed(this.list);
|
|
235
|
+
if (refocus) this.focusAfter(-1);
|
|
236
|
+
}
|
|
237
|
+
/** Envoie les fichiers en attente (`url`, sinon `uploadrequest`). */
|
|
238
|
+
upload(): void {
|
|
239
|
+
const pending = uploadPending(this.list);
|
|
240
|
+
if (!pending.length || this.selectOnly) return;
|
|
241
|
+
if (this.customUpload || !this.url) {
|
|
242
|
+
this.commit(this.list.map((f) => (f.status === 'pending' ? { ...f, status: 'uploading' as const, progress: 0 } : f)));
|
|
243
|
+
const request: PoadUploadRequest = {
|
|
244
|
+
files: pending,
|
|
245
|
+
progress: (i, pct) => { const f = pending[i]; if (f) { this.patchFile(f.id, { progress: Math.round(pct) }); this.emit('uploadprogress', { file: f, percent: Math.round(pct) }); } },
|
|
246
|
+
done: (i, ok, message) => {
|
|
247
|
+
const f = pending[i];
|
|
248
|
+
if (!f) return;
|
|
249
|
+
const now = this.list.find((x) => x.id === f.id);
|
|
250
|
+
this.patchFile(f.id, { status: ok ? 'done' : 'error', progress: ok ? 100 : now?.progress ?? 0, message });
|
|
251
|
+
if (ok) this.emit('uploaded', { file: f }); else this.emit('uploaderror', { file: f, error: message });
|
|
252
|
+
this.checkComplete();
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
this.emit('uploadrequest', request);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
for (const f of pending) {
|
|
259
|
+
this.patchFile(f.id, { status: 'uploading', progress: 0 });
|
|
260
|
+
uploadSend({ url: this.url, method: this.method, headers: this.headers, withCredentials: this.withCredentials, fieldName: this.fieldName, timeout: this.uploadTimeout }, f.file, f.name,
|
|
261
|
+
(pct) => { this.patchFile(f.id, { progress: pct }); this.emit('uploadprogress', { file: f, percent: pct }); })
|
|
262
|
+
.then((response) => { this.patchFile(f.id, { status: 'done', progress: 100 }); this.emit('uploaded', { file: f, response }); this.checkComplete(); })
|
|
263
|
+
.catch((error: unknown) => {
|
|
264
|
+
const msg = (error as Error)?.message;
|
|
265
|
+
this.patchFile(f.id, { status: 'error', message: msg && msg !== 'network' ? msg : this.i18n().t('file.uploadFailed') });
|
|
266
|
+
this.emit('uploaderror', { file: f, error });
|
|
267
|
+
this.checkComplete();
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
private onDrag(e: DragEvent, over: boolean): void {
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
if (this.inactive || this.drag === over) return;
|
|
274
|
+
this.drag = over;
|
|
275
|
+
this.update();
|
|
276
|
+
}
|
|
277
|
+
private onDrop(e: DragEvent): void {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
this.drag = false;
|
|
280
|
+
if (this.inactive) { this.update(); return; }
|
|
281
|
+
this.addFiles([...(e.dataTransfer?.files ?? [])]);
|
|
282
|
+
}
|
|
283
|
+
private onZoneKey(e: KeyboardEvent): void {
|
|
284
|
+
if (!uploadZoneKey(e.key) || e.target !== e.currentTarget) return;
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
this.open();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private item(f: PoadUploadFile, i: number): Child {
|
|
290
|
+
const icons = this.icons();
|
|
291
|
+
const { t } = this.i18n();
|
|
292
|
+
const st = uploadStatusIcon(f.status);
|
|
293
|
+
const bar = { value: f.progress, size: 'sm' as const, ariaLabel: f.name };
|
|
294
|
+
return h('li', { class: uploadItemClasses(f.status) }, [
|
|
295
|
+
f.preview ? h('img', { class: 'poad-upload__thumb', src: f.preview, alt: '' }) : h('span', { class: 'poad-upload__ic' }, icon(icons, uploadIconFor(f.type, f.name), { size: 18 })),
|
|
296
|
+
h('div', { class: 'poad-upload__meta' }, [
|
|
297
|
+
h('div', { class: 'poad-upload__name', title: f.name }, f.name),
|
|
298
|
+
h('div', { class: 'poad-upload__sub' }, [this.sizeText(f.size), f.message ? [' · ', h('span', { class: ['poad-upload__msg', uploadIsError(f.status) && 'is-err'] }, f.message)] : null]),
|
|
299
|
+
f.status === 'uploading' ? h('div', { class: progressClasses(bar) }, h('div', { class: 'poad-progress__track', ...progressTrackProps(bar) }, h('div', { class: 'poad-progress__bar', style: { width: progressBarWidth(bar) } }))) : null,
|
|
300
|
+
]),
|
|
301
|
+
h('span', { class: 'poad-upload__st' }, f.status === 'uploading' ? h('span', { class: 'poad-upload__pct' }, `${f.progress} %`) : st ? icon(icons, st.name, { size: 16 }) : null),
|
|
302
|
+
part({ severity: 'ghost', size: 'sm', icon: true, disabled: f.status === 'uploading' }, 'poad-upload__remove', {
|
|
303
|
+
type: 'button', 'aria-label': t('file.remove', { name: f.name }), onclick: () => this.removeFile(i),
|
|
304
|
+
}, icon(icons, 'x', { size: 13 })),
|
|
305
|
+
]);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
protected render() {
|
|
309
|
+
const { t, text } = this.i18n();
|
|
310
|
+
const icons = this.icons();
|
|
311
|
+
const mode = this.mode ?? 'advanced';
|
|
312
|
+
const disabled = this.inactive;
|
|
313
|
+
const list = this.list;
|
|
314
|
+
const busy = list.some((f) => f.status === 'uploading');
|
|
315
|
+
const pendingCount = uploadPending(list).length;
|
|
316
|
+
const zone = uploadZoneProps(disabled);
|
|
317
|
+
const ia = uploadInputProps({ multiple: this.multiple, accept: this.accept, disabled });
|
|
318
|
+
const size = this.size ?? 'md';
|
|
319
|
+
return h('div', { class: uploadClasses({ mode, drag: this.drag, disabled }) }, [
|
|
320
|
+
h('input', {
|
|
321
|
+
...ia, onchange: (e: Event) => { const el = e.target as HTMLInputElement; this.addFiles([...(el.files ?? [])]); el.value = ''; },
|
|
322
|
+
}),
|
|
323
|
+
h('div', { ...UPLOAD_LIVE_PROPS }, this.announce),
|
|
324
|
+
mode === 'basic' ? [
|
|
325
|
+
part({ severity: this.severity ?? 'primary', size, disabled, loading: busy }, 'poad-upload__choose', { type: 'button', onclick: () => this.open() },
|
|
326
|
+
[icon(icons, 'upload', { size: 14 }), text(this.chooseLabel, 'file.choose')]),
|
|
327
|
+
list.length && !this.auto ? h('span', { class: 'poad-upload__basic-info' }, t('file.summary', { n: list.length, size: this.sizeText(list.reduce((s, f) => s + f.size, 0)) })) : null,
|
|
328
|
+
] : [
|
|
329
|
+
h('div', {
|
|
330
|
+
class: ['poad-upload__zone', this.drag && 'is-drag'], role: zone.role, tabindex: String(zone.tabindex), 'aria-disabled': zone['aria-disabled'],
|
|
331
|
+
onclick: () => this.open(), onkeydown: (e: KeyboardEvent) => this.onZoneKey(e), ondragenter: (e: DragEvent) => this.onDrag(e, true),
|
|
332
|
+
ondragover: (e: DragEvent) => this.onDrag(e, true), ondragleave: (e: DragEvent) => this.onDrag(e, false), ondrop: (e: DragEvent) => this.onDrop(e),
|
|
333
|
+
}, [
|
|
334
|
+
icon(icons, 'upload-cloud', { size: 28, strokeWidth: 1.5 }),
|
|
335
|
+
h('div', { class: 'poad-upload__txt' }, [h('b', text(this.dropLabel, 'file.drop')), ' ', h('span', text(this.browseLabel, 'file.browse'))]),
|
|
336
|
+
this.hint ? h('small', { class: 'poad-upload__hint' }, this.hint) : null,
|
|
337
|
+
]),
|
|
338
|
+
list.length ? h('ul', { class: 'poad-upload__list' }, list.map((f, i) => this.item(f, i))) : null,
|
|
339
|
+
mode === 'advanced' && (this.showUploadButton !== false || this.showCancelButton !== false) && list.length ? h('div', { class: 'poad-upload__actions' }, [
|
|
340
|
+
this.showUploadButton !== false && !this.auto && !this.selectOnly
|
|
341
|
+
? part({ size, loading: busy, disabled: !pendingCount || disabled }, 'poad-upload__send', { type: 'button', onclick: () => this.upload() },
|
|
342
|
+
[icon(icons, 'upload', { size: 14 }), text(this.uploadLabel, 'file.upload'), pendingCount ? ` (${pendingCount})` : null])
|
|
343
|
+
: null,
|
|
344
|
+
this.showCancelButton !== false
|
|
345
|
+
? part({ severity: 'secondary', size, disabled: busy || disabled }, 'poad-upload__clear', { type: 'button', onclick: () => this.clear() }, text(this.cancelLabel, 'file.removeAll'))
|
|
346
|
+
: null,
|
|
347
|
+
]) : null,
|
|
348
|
+
],
|
|
349
|
+
]);
|
|
350
|
+
}
|
|
351
|
+
}
|