@poadio/ui-elements 0.4.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 +82 -0
- package/README.md +16 -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 +12 -1
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +6 -0
- package/dist/card.js.map +1 -1
- 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 +8 -0
- package/dist/fieldset.d.ts.map +1 -1
- package/dist/fieldset.js +5 -0
- package/dist/fieldset.js.map +1 -1
- 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 +35 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -2
- 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 +15 -0
- package/dist/panel.d.ts.map +1 -1
- package/dist/panel.js +7 -0
- package/dist/panel.js.map +1 -1
- 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 +12 -1
- 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 +8 -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 +26 -2
- 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 +15 -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/stepper.ts
CHANGED
|
@@ -28,22 +28,50 @@ export interface StepData {
|
|
|
28
28
|
readonly state?: StepState | null;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Déclaration d'une étape dans un `<poad-stepper>` ; ses enfants sont son contenu.
|
|
33
|
+
* @slot default Contenu de l'étape, affiché quand elle est courante.
|
|
34
|
+
*/
|
|
32
35
|
export class PoadStepElement extends PoadDeclarationElement {
|
|
33
36
|
static override props = {
|
|
34
|
-
|
|
37
|
+
/** Libellé de l'étape. */
|
|
38
|
+
label: 'string',
|
|
39
|
+
/** Texte secondaire sous le libellé. */
|
|
40
|
+
description: 'string',
|
|
41
|
+
/** Icône dans la pastille, à la place du numéro. */
|
|
42
|
+
icon: 'string',
|
|
43
|
+
/** Étape facultative (mention affichée) ; elle ne bloque pas le mode `linear`. */
|
|
44
|
+
optional: 'boolean',
|
|
45
|
+
/** Étape désactivée : on ne peut pas y aller. */
|
|
46
|
+
disabled: 'boolean',
|
|
47
|
+
/** Étape validée (utilisé par `linear`). */
|
|
48
|
+
completed: 'boolean',
|
|
49
|
+
/** État forcé ; sinon dérivé de l'étape courante. */
|
|
50
|
+
state: 'string',
|
|
35
51
|
} as const;
|
|
36
52
|
}
|
|
37
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Une suite d'étapes.
|
|
56
|
+
* @slot default Les étapes : des `<poad-step>`.
|
|
57
|
+
* @fires change L'utilisateur va à une autre étape (clic) ; `detail` : son rang.
|
|
58
|
+
* @fires stepclick Clic sur une étape, même non atteignable ; `detail` : son rang.
|
|
59
|
+
*/
|
|
38
60
|
export class PoadStepperElement extends PoadElement {
|
|
39
61
|
static override props = {
|
|
40
62
|
activeIndex: 'number', linear: 'boolean', clickable: 'boolean', orientation: 'string', size: 'string', ariaLabel: 'string',
|
|
41
63
|
} as const;
|
|
64
|
+
/** Rang de l'étape courante. */
|
|
42
65
|
declare activeIndex?: number;
|
|
66
|
+
/** Une étape suit seulement des étapes complétées (`completed`) ou facultatives. */
|
|
43
67
|
declare linear?: boolean;
|
|
68
|
+
/** Un clic sur une étape y va (défaut oui). */
|
|
44
69
|
declare clickable?: boolean;
|
|
70
|
+
/** Disposition ; en vertical, le contenu s'ouvre sous l'étape courante. */
|
|
45
71
|
declare orientation?: 'horizontal' | 'vertical';
|
|
72
|
+
/** Taille : `sm` ou `md`. */
|
|
46
73
|
declare size?: 'sm' | 'md';
|
|
74
|
+
/** Nom accessible de la liste d'étapes. */
|
|
47
75
|
declare ariaLabel: string | null;
|
|
48
76
|
|
|
49
77
|
protected render() {
|
package/src/switch.ts
CHANGED
|
@@ -9,20 +9,35 @@ import { switchControlProps, switchLabelProps, switchRootClasses, switchTransiti
|
|
|
9
9
|
import { h } from './dom.js';
|
|
10
10
|
import { PoadFormElement } from './element.js';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @fires input Nouvelle valeur, au geste de l'utilisateur seulement (une valeur imposée par l'application n'émet rien).
|
|
14
|
+
* @fires change Nouvelle valeur, au geste de l'utilisateur seulement (une valeur imposée par l'application n'émet rien).
|
|
15
|
+
* @slot default Contenu ajouté après le libellé.
|
|
16
|
+
*/
|
|
12
17
|
export class PoadSwitchElement extends PoadFormElement {
|
|
13
18
|
static override props = {
|
|
14
19
|
checked: 'boolean', disabled: 'boolean', readonly: 'boolean', label: 'string', ariaLabel: 'string', size: 'string', labelPosition: 'string',
|
|
15
20
|
name: 'string', value: 'string', required: 'boolean',
|
|
16
21
|
} as const;
|
|
22
|
+
/** État coché ; l'attribut donne l'état de départ et celui de `form.reset()`. */
|
|
17
23
|
declare checked?: boolean;
|
|
24
|
+
/** Désactivé : hors tabulation, aucun geste. */
|
|
18
25
|
declare disabled?: boolean;
|
|
26
|
+
/** Lecture seule : atteignable au clavier, mais figé. */
|
|
19
27
|
declare readonly?: boolean;
|
|
28
|
+
/** Libellé visible ; absent : donner `aria-label`. */
|
|
20
29
|
declare label?: string;
|
|
30
|
+
/** Nom accessible quand il n'y a pas de libellé visible. */
|
|
21
31
|
declare ariaLabel: string | null;
|
|
32
|
+
/** Taille : `sm` ou `md`. */
|
|
22
33
|
declare size?: 'sm' | 'md';
|
|
34
|
+
/** Côté du libellé : `left` ou `right`. */
|
|
23
35
|
declare labelPosition?: 'left' | 'right';
|
|
36
|
+
/** Nom du champ soumis avec le `<form>`. */
|
|
24
37
|
declare name?: string;
|
|
38
|
+
/** Valeur soumise quand le contrôle est coché ; défaut `on`. */
|
|
25
39
|
declare value?: string;
|
|
40
|
+
/** Obligatoire : le formulaire est invalide tant que le contrôle n'est pas coché. */
|
|
26
41
|
declare required?: boolean;
|
|
27
42
|
protected readonly resetProps = ['checked'];
|
|
28
43
|
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table, tranche 2 — champs de filtre de `<poad-table>` (interne) : recherche de la barre d'outils et ligne de filtres
|
|
3
|
+
* à opérateurs sous l'en-tête. Même DOM, mêmes classes et même ARIA que `poad-table` d'ui-angular ; la logique
|
|
4
|
+
* (opérateurs, valeur gardée au changement d'opérateur, bornes, valeurs multiples, état) est le modèle `table.filter`
|
|
5
|
+
* du socle. Ici : les champs, leurs brouillons de frappe, les menus (`MenuController`, celui de `<poad-menu>`) et les
|
|
6
|
+
* listes oui / non et à choix unique (`<poad-select>` posés par `HeldElements`).
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
tableColumnId, tableFilterIsActive, tableFilterKind, tableFilterOperator, tableFilterOperatorLabel, tableFilterOperators, tableFilterPart, tableFilterValues,
|
|
10
|
+
type IconRegistry, type TableFilterMatchMode, type TableFilterOperator, type TableFilters,
|
|
11
|
+
} from '@poadio/ui-core';
|
|
12
|
+
import { h, type Child } from './dom.js';
|
|
13
|
+
import { HeldElements } from './held.js';
|
|
14
|
+
import type { UiI18nValue } from './i18n.js';
|
|
15
|
+
import { icon } from './icon.js';
|
|
16
|
+
import { MenuController, type PoadMenuItem } from './menu.js';
|
|
17
|
+
import type { PoadTableColumn } from './table.js';
|
|
18
|
+
|
|
19
|
+
/** Recherche globale de la barre d'outils (`.dt-bar__search`). */
|
|
20
|
+
export function tableSearch(i18n: UiI18nValue, registry: IconRegistry, o: { readonly text: string; readonly placeholder?: string; readonly onSearch: (text: string, immediate?: boolean) => void }): Child {
|
|
21
|
+
const label = i18n.text(o.placeholder, 'table.searchPlaceholder');
|
|
22
|
+
return h('div', { class: 'dt-bar__search' }, [
|
|
23
|
+
icon(registry, 'search', { size: 14 }),
|
|
24
|
+
h('input', { type: 'search', placeholder: label, value: o.text, 'aria-label': label, oninput: (e: Event) => o.onSearch((e.target as HTMLInputElement).value) }),
|
|
25
|
+
o.text && h('button', { type: 'button', class: 'dt-bar__clear', 'aria-label': i18n.t('table.clearSearch'), onclick: () => o.onSearch('', true) }, icon(registry, 'x', { size: 12 })),
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Ce que la ligne de filtres demande à la table (réducteur du socle et minuteries, côté table). */
|
|
30
|
+
export interface TableFilterActions {
|
|
31
|
+
/** Pose une valeur (`delayed` : après le délai des filtres). */
|
|
32
|
+
set(column: PoadTableColumn, value: unknown, matchMode?: TableFilterMatchMode, delayed?: boolean): void;
|
|
33
|
+
/** Une borne d'un filtre « entre » (après le délai). */
|
|
34
|
+
part(column: PoadTableColumn, index: 0 | 1, raw: string): void;
|
|
35
|
+
operator(column: PoadTableColumn, op: TableFilterOperator): void;
|
|
36
|
+
toggleValue(column: PoadTableColumn, value: unknown): void;
|
|
37
|
+
clear(column: PoadTableColumn): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Ce que reçoit `renderFilter` (ou `filterCell` d'une colonne) : `filter(valeur, mode)` pose le filtre de la colonne. */
|
|
41
|
+
export interface PoadTableFilterContext {
|
|
42
|
+
readonly column: PoadTableColumn;
|
|
43
|
+
readonly value: unknown;
|
|
44
|
+
readonly filter: (value: unknown, matchMode?: TableFilterMatchMode) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Cellules de la ligne de filtres (`tr.flt`) et menus (opérateurs, valeurs) d'une table. `drafts` : textes en cours
|
|
49
|
+
* de frappe (avant le délai), par colonne et par borne ; oubliés dès que l'état des filtres change.
|
|
50
|
+
*/
|
|
51
|
+
export class TableFilterRow {
|
|
52
|
+
private drafts: Record<string, string> = {};
|
|
53
|
+
private seen: TableFilters | null = null;
|
|
54
|
+
private menu: { readonly type: 'op' | 'in'; readonly column: PoadTableColumn } | null = null;
|
|
55
|
+
private anchor: HTMLElement | null = null;
|
|
56
|
+
private readonly controller: MenuController;
|
|
57
|
+
private readonly held = new HeldElements();
|
|
58
|
+
private menuShown = false;
|
|
59
|
+
/** `uid` : identifiant de la table (menu) ; `selectTag` : balise de la liste de la même définition. */
|
|
60
|
+
constructor(private readonly host: { update(): void }, private readonly uid: string, private readonly selectTag: string) {
|
|
61
|
+
this.controller = new MenuController(host);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private key(c: PoadTableColumn, i: 0 | 1) { return tableColumnId(c) + '|' + i; }
|
|
65
|
+
private forget(c: PoadTableColumn) { delete this.drafts[this.key(c, 0)]; delete this.drafts[this.key(c, 1)]; }
|
|
66
|
+
private shown(filters: TableFilters, c: PoadTableColumn, i: 0 | 1): string {
|
|
67
|
+
const d = this.drafts[this.key(c, i)];
|
|
68
|
+
if (d !== undefined) return d;
|
|
69
|
+
const v = tableFilterPart(filters[c.field ?? '']?.value ?? null, i);
|
|
70
|
+
return v instanceof Date ? v.toISOString().slice(0, 10) : String(v ?? '');
|
|
71
|
+
}
|
|
72
|
+
private open(type: 'op' | 'in', column: PoadTableColumn, el: HTMLElement) {
|
|
73
|
+
this.anchor = el;
|
|
74
|
+
this.menu = { type, column };
|
|
75
|
+
this.host.update();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Au début de chaque rendu : l'état a changé (filtre appliqué, ou posé par la page) → les champs relisent l'état. */
|
|
79
|
+
begin(filters: TableFilters): void {
|
|
80
|
+
if (filters !== this.seen) { this.seen = filters; this.drafts = {}; }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
cell(i18n: UiI18nValue, registry: IconRegistry, filters: TableFilters, c: PoadTableColumn, actions: TableFilterActions, custom?: (ctx: PoadTableFilterContext) => string | Node | null | undefined): Child {
|
|
84
|
+
if (!c.filterable) return null;
|
|
85
|
+
const { t } = i18n;
|
|
86
|
+
const label = (op: TableFilterOperator) => tableFilterOperatorLabel(op, (k) => t(k));
|
|
87
|
+
const field = c.field ?? '';
|
|
88
|
+
const value = filters[field]?.value ?? null;
|
|
89
|
+
if (custom) {
|
|
90
|
+
const out = custom({ column: c, value, filter: (v, m) => actions.set(c, v, m) });
|
|
91
|
+
if (out != null) return out;
|
|
92
|
+
}
|
|
93
|
+
const kind = tableFilterKind(c);
|
|
94
|
+
const op = tableFilterOperator(c, filters);
|
|
95
|
+
const active = tableFilterIsActive(filters[field]);
|
|
96
|
+
const name = c.header ?? '';
|
|
97
|
+
const type = kind === 'number' ? 'number' : kind === 'date' ? 'date' : 'search';
|
|
98
|
+
const any = c.filterPlaceholder || t('filter.any');
|
|
99
|
+
const id = tableColumnId(c);
|
|
100
|
+
let input: Child;
|
|
101
|
+
if (kind === 'boolean' || (kind === 'select' && op.mode === 'eq')) {
|
|
102
|
+
const options = kind === 'boolean' ? [{ label: t('common.yes'), value: true }, { label: t('common.no'), value: false }] : (c.filterOptions ?? []);
|
|
103
|
+
input = this.held.get('sel|' + id, this.selectTag, { size: 'sm', clearable: true, options, value, placeholder: any, ariaLabel: t('filter.column', { column: name }) },
|
|
104
|
+
(v) => (kind === 'boolean' ? actions.set(c, v) : actions.set(c, v, 'eq')));
|
|
105
|
+
} else if (kind === 'select') {
|
|
106
|
+
const n = tableFilterValues(filters, field).length;
|
|
107
|
+
input = h('button', {
|
|
108
|
+
type: 'button', class: ['flt-in', { 'is-ph': !n }], 'aria-label': t('filter.column', { column: name }),
|
|
109
|
+
onclick: (e: MouseEvent) => { e.stopPropagation(); this.open('in', c, e.currentTarget as HTMLElement); },
|
|
110
|
+
}, [h('span', {}, n ? t('filter.selectedCount', { n }) : any), icon(registry, 'chevron-down', { size: 11 })]);
|
|
111
|
+
} else if (!op.needsValue) {
|
|
112
|
+
input = h('span', { class: 'flt-txt' }, label(op));
|
|
113
|
+
} else if (op.range) {
|
|
114
|
+
input = ([0, 1] as const).map((i) => h('input', {
|
|
115
|
+
type, value: this.shown(filters, c, i), placeholder: t(i ? 'filter.max' : 'filter.min'), 'aria-label': t(i ? 'filter.columnMax' : 'filter.columnMin', { column: name }),
|
|
116
|
+
oninput: (e: Event) => { const v = (e.target as HTMLInputElement).value; this.drafts[this.key(c, i)] = v; actions.part(c, i, v); },
|
|
117
|
+
}));
|
|
118
|
+
} else {
|
|
119
|
+
input = h('input', {
|
|
120
|
+
type, value: this.shown(filters, c, 0), placeholder: c.filterPlaceholder || label(op), 'aria-label': t('filter.column', { column: name }),
|
|
121
|
+
oninput: (e: Event) => { const v = (e.target as HTMLInputElement).value; this.drafts[this.key(c, 0)] = v; actions.set(c, v, undefined, true); },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return h('div', { class: ['flt-cell', { 'is-active': active, 'is-range': !!op.range }] }, [
|
|
125
|
+
input,
|
|
126
|
+
kind !== 'boolean' && h('button', {
|
|
127
|
+
type: 'button', class: ['flt-op', { 'is-on': active }], 'aria-label': t('filter.operator', { label: label(op) }), title: label(op),
|
|
128
|
+
onclick: (e: MouseEvent) => { e.stopPropagation(); this.open('op', c, e.currentTarget as HTMLElement); },
|
|
129
|
+
}, icon(registry, 'filter', { size: 12 })),
|
|
130
|
+
active && h('button', { type: 'button', class: 'flt-x', 'aria-label': t('filter.clear'), onclick: () => { this.forget(c); actions.clear(c); } }, icon(registry, 'x', { size: 11 })),
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Le menu ouvert (opérateurs ou valeurs), monté seulement ouvert : sans ancre, ce serait un menu en ligne. */
|
|
135
|
+
menus(i18n: UiI18nValue, registry: IconRegistry, filters: TableFilters, actions: TableFilterActions): Child {
|
|
136
|
+
const m = this.menu;
|
|
137
|
+
const open = !!m && !!this.anchor?.isConnected;
|
|
138
|
+
const { t } = i18n;
|
|
139
|
+
const items: PoadMenuItem[] = !m ? [] : m.type === 'op'
|
|
140
|
+
? (() => {
|
|
141
|
+
const cur = tableFilterOperator(m.column, filters);
|
|
142
|
+
return tableFilterOperators(m.column).map((op) => ({
|
|
143
|
+
label: tableFilterOperatorLabel(op, (k) => t(k)), shortcut: op.short, icon: op.mode === cur.mode ? 'check' : undefined,
|
|
144
|
+
command: () => { this.forget(m.column); actions.operator(m.column, op); },
|
|
145
|
+
}));
|
|
146
|
+
})()
|
|
147
|
+
: (() => {
|
|
148
|
+
const sel = tableFilterValues(filters, m.column.field ?? '');
|
|
149
|
+
return (m.column.filterOptions ?? []).map((o) => ({ label: o.label, icon: sel.some((v) => v === o.value) ? 'check' : 'square', command: () => actions.toggleValue(m.column, o.value) }));
|
|
150
|
+
})();
|
|
151
|
+
if (!open) return null;
|
|
152
|
+
return this.controller.render({
|
|
153
|
+
id: `${this.uid}-fltmenu`, items, open: true, popup: true, anchor: () => this.anchor, contextual: false,
|
|
154
|
+
ariaLabel: t(m!.type === 'op' ? 'filter.operatorMenu' : 'filter.valuesMenu'), minWidth: m!.type === 'op' ? 200 : 180, closeOnSelect: m!.type === 'op',
|
|
155
|
+
closeLabel: t('common.close'), icons: registry,
|
|
156
|
+
// refermé par un choix (ou un clic dehors) : le focus, tombé sur la page, revient au bouton qui l'a ouvert
|
|
157
|
+
setOpen: (o) => {
|
|
158
|
+
if (o) return;
|
|
159
|
+
const from = this.anchor;
|
|
160
|
+
this.menu = null;
|
|
161
|
+
this.host.update();
|
|
162
|
+
const at = from?.ownerDocument.activeElement;
|
|
163
|
+
if (from?.isConnected && (!at || at === from.ownerDocument.body)) from.focus();
|
|
164
|
+
},
|
|
165
|
+
onItemClick: () => {},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Après le rendu de la table : menu placé et focalisé ; éléments posés qui n'ont plus servi oubliés. */
|
|
170
|
+
sync(): void {
|
|
171
|
+
if (this.menu) { this.menuShown = true; this.controller.sync(); }
|
|
172
|
+
else if (this.menuShown) { this.menuShown = false; this.controller.dispose(); }
|
|
173
|
+
this.held.sweep();
|
|
174
|
+
}
|
|
175
|
+
dispose(): void {
|
|
176
|
+
this.menu = null;
|
|
177
|
+
this.controller.dispose();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <div style="display: flex">
|
|
3
|
+
* <poad-table id="projects" style="flex: 1; min-width: 0"></poad-table>
|
|
4
|
+
* <poad-table-panel for="projects"></poad-table-panel>
|
|
5
|
+
* </div>
|
|
6
|
+
* panel.addEventListener('filterschange', (e) => e.detail);
|
|
7
|
+
*
|
|
8
|
+
* Panneau latéral d'une table (style AG Grid), tranche 2 : rail d'onglets verticaux (motif « tabs » de WAI-ARIA à focus
|
|
9
|
+
* itinérant : ↑ ↓ Début Fin entre onglets, Entrée / Espace ouvre l'onglet, ou le referme), onglet Colonnes (recherche
|
|
10
|
+
* sans accents, case « toutes », visibilité de chaque colonne) et onglet Filtres (recherche globale, un éditeur par
|
|
11
|
+
* colonne filtrable : valeurs à cocher, oui / non, opérateur et nombre(s), opérateur et date(s), opérateur et texte).
|
|
12
|
+
* Comme `[table]` d'ui-angular, il agit sur SA table : `for` (identifiant d'une `<poad-table>` du document) ou la
|
|
13
|
+
* propriété `table` (l'élément) ; il lit et pose ses `columns` (leur `hidden`), `filters` et `globalFilter`, se
|
|
14
|
+
* redessine à chaque rendu de la table, et émet `columnschange`, `filterschange`, `globalfilterchange` après un geste.
|
|
15
|
+
* Sous `overlay-below` (défaut `md`) il recouvre la table, fermé par défaut. Tranche 3 : onglet Groupes (champs du
|
|
16
|
+
* regroupement en puces qu'on retire, un bouton « + colonne » par colonne regroupable ; pose `groupBy` sur la table et
|
|
17
|
+
* émet `groupbychange`) et onglet Valeurs (agrégats en puces, ajout par colonne et fonction ; pose `aggregates` et émet
|
|
18
|
+
* `aggregateschange`) ; sans onglet à part, ces sections suivent les colonnes dès que la table a leur valeur. Modèle `table.panel` d'@poadio/ui-core, même DOM, mêmes classes et même ARIA que
|
|
19
|
+
* `poad-table-panel` d'ui-angular. Styles : `@poadio/ui-core/table-panel.css`, `checkbox.css`, `icon.css`,
|
|
20
|
+
* `select.css`, `option-list.css`, `floating.css`, `number.css`, `datepicker.css`, `segmented.css`.
|
|
21
|
+
*/
|
|
22
|
+
import {
|
|
23
|
+
TABLE_AGGREGATE_FNS, TABLE_PANEL_TABS, tableGroupByValue, tableGroupFields, tablePanelAggregateCandidates, tablePanelAggregateLabel, tablePanelAggregateList,
|
|
24
|
+
tablePanelAggregateSet, tablePanelGroupCandidates, type TableAggregate, type TableAggregates, type TableGroupBy, tableColumnId, tableFilterActiveCount, tableFilterDefaultMode, tableFilterKind, tableFilterSet, tablePanelAllState, tablePanelBodyProps,
|
|
25
|
+
tablePanelClasses, tablePanelColumnMatches, tablePanelDraftFilter, tablePanelDraftInit, tablePanelDraftSync, tablePanelDraftToggle, tablePanelFilterable, tablePanelIsActive,
|
|
26
|
+
tablePanelOperatorOptions, tablePanelOverlayQuery, tablePanelTabClick, tablePanelTabKey, tablePanelTabProps,
|
|
27
|
+
type TableFilterMatchMode, type TableFilters, type TablePanelDraft,
|
|
28
|
+
} from '@poadio/ui-core';
|
|
29
|
+
import { button } from './button.js';
|
|
30
|
+
import { checkboxNode } from './checkbox.js';
|
|
31
|
+
import { h, type Child } from './dom.js';
|
|
32
|
+
import { PoadElement } from './element.js';
|
|
33
|
+
import { HeldElements } from './held.js';
|
|
34
|
+
import { icon } from './icon.js';
|
|
35
|
+
import { tableWatchers, type PoadTableColumn, type PoadTableElement } from './table.js';
|
|
36
|
+
|
|
37
|
+
/** Onglets du rail. */
|
|
38
|
+
export type PoadTablePanelTab = 'columns' | 'filters' | 'groups' | 'values';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Panneau latéral d'une table : colonnes et filtres.
|
|
42
|
+
* @fires columnschange {PoadTableColumn[]} Visibilité changée : les colonnes de la table, avec leur nouveau `hidden` (déjà posées sur la table).
|
|
43
|
+
* @fires filterschange {TableFilters} Filtres changés par un éditeur du panneau (déjà posés sur la table).
|
|
44
|
+
* @fires globalfilterchange {string} Recherche globale changée dans le panneau (déjà posée sur la table).
|
|
45
|
+
* @fires groupbychange {string[]} Champs du regroupement changés dans le panneau (déjà posés sur la table).
|
|
46
|
+
* @fires aggregateschange {TableAggregates} Agrégats changés dans le panneau (déjà posés sur la table).
|
|
47
|
+
* @fires openchange {boolean} Panneau ouvert (`true`) ou refermé (`false`) par l'utilisateur.
|
|
48
|
+
* @fires activetabchange {PoadTablePanelTab} Onglet ouvert par l'utilisateur.
|
|
49
|
+
*/
|
|
50
|
+
export class PoadTablePanelElement extends PoadElement {
|
|
51
|
+
static override props = {
|
|
52
|
+
for: 'string', tabs: 'json', position: 'string', open: 'boolean', activeTab: 'string', width: 'string', collapsible: 'boolean', overlayBelow: 'string',
|
|
53
|
+
} as const;
|
|
54
|
+
static override functions = ['table'] as const;
|
|
55
|
+
/** Identifiant de la `<poad-table>` du document sur laquelle agit le panneau (sinon : propriété `table`). */
|
|
56
|
+
declare for?: string;
|
|
57
|
+
/** La `<poad-table>` sur laquelle agit le panneau (propriété seulement ; prime sur `for`). */
|
|
58
|
+
declare table?: PoadTableElement | null;
|
|
59
|
+
/**
|
|
60
|
+
* Onglets du rail, dans l'ordre.
|
|
61
|
+
* @default ['columns', 'filters']
|
|
62
|
+
*/
|
|
63
|
+
declare tabs?: readonly PoadTablePanelTab[];
|
|
64
|
+
/**
|
|
65
|
+
* Côté de la table où se place le panneau : `left` ou `right`.
|
|
66
|
+
* @default 'right'
|
|
67
|
+
*/
|
|
68
|
+
declare position?: 'left' | 'right';
|
|
69
|
+
/**
|
|
70
|
+
* Panneau ouvert, tenu par l'élément.
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
declare open?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Onglet ouvert, tenu par l'élément.
|
|
76
|
+
* @default 'columns'
|
|
77
|
+
*/
|
|
78
|
+
declare activeTab?: PoadTablePanelTab;
|
|
79
|
+
/**
|
|
80
|
+
* Largeur du contenu (valeur CSS).
|
|
81
|
+
* @default '260px'
|
|
82
|
+
*/
|
|
83
|
+
declare width?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Un clic sur l'onglet ouvert referme le panneau.
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
declare collapsible?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Sous ce seuil de fenêtre (`sm`, `md`, `lg`), le panneau recouvre la table, fermé par défaut ; `''` : jamais.
|
|
91
|
+
* @default 'md'
|
|
92
|
+
*/
|
|
93
|
+
declare overlayBelow?: 'sm' | 'md' | 'lg' | '';
|
|
94
|
+
|
|
95
|
+
private query = '';
|
|
96
|
+
private picker: { open: boolean; field: string | null; fn: string } = { open: false, field: null, fn: 'sum' };
|
|
97
|
+
private drafts: Record<string, TablePanelDraft> = {};
|
|
98
|
+
private seenFilters: TableFilters | null = null;
|
|
99
|
+
private watched: { readonly table: Element; readonly fn: () => void } | null = null;
|
|
100
|
+
private media: { readonly query: string; readonly list: MediaQueryList; readonly fn: () => void } | null = null;
|
|
101
|
+
private overlay = false;
|
|
102
|
+
private readonly held = new HeldElements();
|
|
103
|
+
|
|
104
|
+
override connectedCallback(): void {
|
|
105
|
+
super.connectedCallback();
|
|
106
|
+
// `for` vise une table écrite plus loin dans la page : la chercher une fois le document lu
|
|
107
|
+
if (!this.target() && this.ownerDocument.readyState === 'loading') this.ownerDocument.addEventListener('DOMContentLoaded', () => this.update(), { once: true });
|
|
108
|
+
}
|
|
109
|
+
override disconnectedCallback(): void {
|
|
110
|
+
super.disconnectedCallback();
|
|
111
|
+
this.unwatch();
|
|
112
|
+
this.media?.list.removeEventListener?.('change', this.media.fn);
|
|
113
|
+
this.media = null;
|
|
114
|
+
}
|
|
115
|
+
private unwatch() {
|
|
116
|
+
if (this.watched) tableWatchers.get(this.watched.table)?.delete(this.watched.fn);
|
|
117
|
+
this.watched = null;
|
|
118
|
+
}
|
|
119
|
+
private target(): PoadTableElement | null {
|
|
120
|
+
const t = this.table ?? (this.for ? this.ownerDocument.getElementById(this.for) : null);
|
|
121
|
+
return (t as PoadTableElement | null) ?? null;
|
|
122
|
+
}
|
|
123
|
+
/** La table suivie : chaque rendu de la table redessine le panneau. */
|
|
124
|
+
private follow(table: PoadTableElement | null) {
|
|
125
|
+
if (this.watched?.table === table) return;
|
|
126
|
+
this.unwatch();
|
|
127
|
+
if (!table) return;
|
|
128
|
+
const fn = () => this.update();
|
|
129
|
+
let set = tableWatchers.get(table);
|
|
130
|
+
if (!set) tableWatchers.set(table, (set = new Set()));
|
|
131
|
+
set.add(fn);
|
|
132
|
+
this.watched = { table, fn };
|
|
133
|
+
}
|
|
134
|
+
/** Recouvrement sous le seuil (requête média suivie) : fermé au passage sous le seuil. */
|
|
135
|
+
private watchMedia() {
|
|
136
|
+
const query = tablePanelOverlayQuery(this.overlayBelow ?? 'md');
|
|
137
|
+
if (this.media?.query === query) return;
|
|
138
|
+
this.media?.list.removeEventListener?.('change', this.media.fn);
|
|
139
|
+
this.media = null;
|
|
140
|
+
if (!query || typeof window === 'undefined' || typeof window.matchMedia !== 'function') { this.overlay = false; return; }
|
|
141
|
+
const list = window.matchMedia(query);
|
|
142
|
+
const fn = () => {
|
|
143
|
+
this.overlay = list.matches;
|
|
144
|
+
if (this.overlay && (this.open ?? true)) this.propValues['open'] = false;
|
|
145
|
+
this.update();
|
|
146
|
+
};
|
|
147
|
+
list.addEventListener?.('change', fn);
|
|
148
|
+
this.media = { query, list, fn };
|
|
149
|
+
this.overlay = list.matches;
|
|
150
|
+
if (this.overlay) this.propValues['open'] = false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected override updated(): void {
|
|
154
|
+
this.held.sweep();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected render(): Child {
|
|
158
|
+
const { t, locale } = this.i18n();
|
|
159
|
+
const registry = this.icons();
|
|
160
|
+
this.watchMedia();
|
|
161
|
+
const table = this.target();
|
|
162
|
+
this.follow(table);
|
|
163
|
+
const tabs = this.tabs ?? ['columns', 'filters'];
|
|
164
|
+
const open = this.open ?? true;
|
|
165
|
+
const active = this.activeTab ?? 'columns';
|
|
166
|
+
const collapsible = this.collapsible ?? true;
|
|
167
|
+
const baseId = `${this.uid}-tpanel`;
|
|
168
|
+
const columns: readonly PoadTableColumn[] = table?.columns ?? [];
|
|
169
|
+
const filters: TableFilters = table?.filters ?? {};
|
|
170
|
+
const globalFilter = table?.globalFilter ?? '';
|
|
171
|
+
const label = (c: PoadTableColumn) => c.header || c.field || tableColumnId(c);
|
|
172
|
+
const filterable = tablePanelFilterable(columns);
|
|
173
|
+
// les brouillons suivent le filtre posé ailleurs (ligne de filtres, page)
|
|
174
|
+
if (filters !== this.seenFilters) {
|
|
175
|
+
this.seenFilters = filters;
|
|
176
|
+
for (const c of filterable) this.drafts[tableColumnId(c)] = tablePanelDraftSync(this.drafts[tableColumnId(c)] ?? tablePanelDraftInit(c), filters[c.field ?? '']);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ---- onglets ----
|
|
180
|
+
const onTab = (tab: PoadTablePanelTab) => {
|
|
181
|
+
const next = tablePanelTabClick({ open, active }, tab, collapsible);
|
|
182
|
+
if (next.active !== active) { this.propValues['activeTab'] = next.active; this.emit('activetabchange', next.active); }
|
|
183
|
+
if (next.open !== open) { this.propValues['open'] = next.open; this.emit('openchange', next.open); }
|
|
184
|
+
this.update();
|
|
185
|
+
};
|
|
186
|
+
const onTabKey = (i: number, e: KeyboardEvent) => {
|
|
187
|
+
const to = tablePanelTabKey(tabs, i, e.key); if (to == null) return;
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
this.querySelectorAll<HTMLElement>(':scope > .poad-table-panel > .rail > [role=tab]')[to]?.focus();
|
|
190
|
+
};
|
|
191
|
+
const body = tablePanelBodyProps({ active, baseId });
|
|
192
|
+
|
|
193
|
+
// ---- colonnes ----
|
|
194
|
+
const setColumns = (next: PoadTableColumn[]) => {
|
|
195
|
+
if (!table) return;
|
|
196
|
+
table.columns = next;
|
|
197
|
+
this.emit('columnschange', next);
|
|
198
|
+
};
|
|
199
|
+
const all = tablePanelAllState(columns.map((c) => ({ hidden: c.hidden, toggleable: true })));
|
|
200
|
+
const setVisible = (c: PoadTableColumn, visible: boolean) => setColumns(columns.map((x) => (x === c ? { ...x, hidden: !visible } : x)));
|
|
201
|
+
const setAll = (visible: boolean) => setColumns(columns.map((x) => ({ ...x, hidden: !visible })));
|
|
202
|
+
const shownCols = columns.filter((c) => tablePanelColumnMatches(label(c), this.query, locale));
|
|
203
|
+
|
|
204
|
+
// ---- filtres (brouillons du socle, synchronisés avec l'état de la table) ----
|
|
205
|
+
const draft = (c: PoadTableColumn): TablePanelDraft => this.drafts[tableColumnId(c)] ?? tablePanelDraftSync(tablePanelDraftInit(c), filters[c.field ?? '']);
|
|
206
|
+
const patch = (c: PoadTableColumn, d: TablePanelDraft) => { this.drafts[tableColumnId(c)] = d; return d; };
|
|
207
|
+
const setFilters = (next: TableFilters) => {
|
|
208
|
+
if (!table) return;
|
|
209
|
+
this.seenFilters = next;
|
|
210
|
+
table.filters = next;
|
|
211
|
+
this.emit('filterschange', next);
|
|
212
|
+
};
|
|
213
|
+
const apply = (c: PoadTableColumn, d: TablePanelDraft) => {
|
|
214
|
+
const f = tablePanelDraftFilter(d, tableFilterKind(c));
|
|
215
|
+
setFilters(tableFilterSet(table?.filters ?? {}, c.field ?? '', f.value, { matchMode: f.matchMode, defaultMode: tableFilterDefaultMode(c), kind: tableFilterKind(c), locale }));
|
|
216
|
+
};
|
|
217
|
+
const setOp = (c: PoadTableColumn, op: TableFilterMatchMode) => { const d = patch(c, { ...draft(c), op }); if (d.a != null || d.b != null) apply(c, d); else this.update(); };
|
|
218
|
+
const setVal = (c: PoadTableColumn, v: unknown, which: 'a' | 'b') => apply(c, patch(c, { ...draft(c), [which]: v }));
|
|
219
|
+
const clear = (c: PoadTableColumn) => apply(c, patch(c, { ...draft(c), a: null, b: null, set: [] }));
|
|
220
|
+
const setGlobal = (g: string) => {
|
|
221
|
+
if (!table) return;
|
|
222
|
+
table.globalFilter = g;
|
|
223
|
+
this.emit('globalfilterchange', g);
|
|
224
|
+
};
|
|
225
|
+
const clearAll = () => { this.drafts = {}; setFilters({}); setGlobal(''); };
|
|
226
|
+
const ops = (kind: 'text' | 'number' | 'date') => tablePanelOperatorOptions(kind, (k) => t(k));
|
|
227
|
+
const select = (c: PoadTableColumn, kind: 'text' | 'number' | 'date', d: TablePanelDraft) =>
|
|
228
|
+
this.held.get(`op|${tableColumnId(c)}`, this.tag('select'), { options: ops(kind), value: d.op, size: 'sm' }, (v) => setOp(c, v as TableFilterMatchMode));
|
|
229
|
+
const number = (c: PoadTableColumn, v: unknown, ph: string, which: 'a' | 'b') =>
|
|
230
|
+
this.held.get(`num|${tableColumnId(c)}|${which}`, this.tag('number'), { value: v == null || v === '' ? null : Number(v), size: 'sm', placeholder: ph }, (x) => setVal(c, x, which));
|
|
231
|
+
const date = (c: PoadTableColumn, v: unknown, ph: string, which: 'a' | 'b') =>
|
|
232
|
+
this.held.get(`date|${tableColumnId(c)}|${which}`, this.tag('datepicker'), { value: v ?? null, size: 'sm', placeholder: ph, clearable: true }, (x) => setVal(c, x, which));
|
|
233
|
+
const editor = (c: PoadTableColumn): Child => {
|
|
234
|
+
const d = draft(c);
|
|
235
|
+
const kind = tableFilterKind(c);
|
|
236
|
+
switch (kind) {
|
|
237
|
+
case 'select': {
|
|
238
|
+
const options = c.filterOptions ?? [];
|
|
239
|
+
return h('div', { class: 'opts' }, options.length ? options.map((o, i) => h('label', {}, [
|
|
240
|
+
checkboxNode(registry, { id: `${baseId}-${tableColumnId(c)}-${i}`, checked: d.set.includes(o.value), ariaLabel: o.label, onToggle: (on) => apply(c, patch(c, tablePanelDraftToggle(draft(c), o.value, on))) }),
|
|
241
|
+
o.label,
|
|
242
|
+
])) : h('div', { class: 'empty' }, t('filter.noOptions', { input: 'filterOptions' })));
|
|
243
|
+
}
|
|
244
|
+
case 'boolean':
|
|
245
|
+
return this.held.get(`bool|${tableColumnId(c)}`, this.tag('segmented'), {
|
|
246
|
+
value: d.a ?? null, options: [{ label: t('common.yes'), value: true }, { label: t('common.no'), value: false }], allowEmpty: true, block: true, size: 'sm',
|
|
247
|
+
}, (v) => apply(c, patch(c, { ...draft(c), a: v, op: 'eq' })));
|
|
248
|
+
case 'number':
|
|
249
|
+
return [select(c, 'number', d), d.op === 'between'
|
|
250
|
+
? h('div', { class: 'two' }, [number(c, d.a, t('filter.min'), 'a'), number(c, d.b, t('filter.max'), 'b')])
|
|
251
|
+
: number(c, d.a, t('filter.value'), 'a')];
|
|
252
|
+
case 'date':
|
|
253
|
+
return [select(c, 'date', d), d.op === 'between'
|
|
254
|
+
? h('div', { class: 'two' }, [date(c, d.a, t('filter.from'), 'a'), date(c, d.b, t('filter.to'), 'b')])
|
|
255
|
+
: date(c, d.a, t('filter.date'), 'a')];
|
|
256
|
+
default:
|
|
257
|
+
return [
|
|
258
|
+
select(c, 'text', d),
|
|
259
|
+
h('label', { class: 'srch', style: { margin: 0 } }, h('input', {
|
|
260
|
+
type: 'text', value: String(d.a ?? ''), placeholder: t('filter.value'), 'aria-label': label(c), oninput: (e: Event) => setVal(c, (e.target as HTMLInputElement).value, 'a'),
|
|
261
|
+
})),
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// ---- groupes et valeurs ----
|
|
267
|
+
const labelOfField = (f: string) => { const c = columns.find((x) => x.field === f || tableColumnId(x) === f); return c ? label(c) : f; };
|
|
268
|
+
const groups = tableGroupFields((table?.groupBy ?? null) as TableGroupBy<unknown> | null);
|
|
269
|
+
const candidates = tablePanelGroupCandidates(columns, groups);
|
|
270
|
+
const setGroups = (next: string[]) => {
|
|
271
|
+
if (!table) return;
|
|
272
|
+
table.groupBy = tableGroupByValue(next);
|
|
273
|
+
this.emit('groupbychange', next);
|
|
274
|
+
};
|
|
275
|
+
const aggregates = (table?.aggregates ?? null) as TableAggregates<unknown> | null;
|
|
276
|
+
const setAgg = (field: string, fn: TableAggregate<unknown> | null) => {
|
|
277
|
+
if (!table) return;
|
|
278
|
+
const next = tablePanelAggregateSet(aggregates, field, fn);
|
|
279
|
+
table.aggregates = Object.keys(next).length ? next : null;
|
|
280
|
+
this.emit('aggregateschange', next);
|
|
281
|
+
};
|
|
282
|
+
const setPicker = (p: Partial<typeof this.picker>) => { this.picker = { ...this.picker, ...p }; this.update(); };
|
|
283
|
+
const closePicker = () => setPicker({ open: false, field: null, fn: 'sum' });
|
|
284
|
+
const inline = (tab: 'groups' | 'values') => !tabs.includes(tab) && (tab === 'groups' ? table?.groupBy : table?.aggregates) != null;
|
|
285
|
+
const groupsSec = () => h('div', { class: 'sec' }, [
|
|
286
|
+
h('div', { class: 'sec__ttl' }, [icon(registry, 'layers', { size: 12 }), ' ', t('table.rowGroups')]),
|
|
287
|
+
h('div', { class: 'drop' }, groups.length ? groups.map((f) => h('span', { class: 'chip' }, [
|
|
288
|
+
labelOfField(f),
|
|
289
|
+
h('button', { type: 'button', 'aria-label': t('table.removeGroup', { label: labelOfField(f) }), onclick: () => setGroups(groups.filter((x) => x !== f)) }, icon(registry, 'x', { size: 10 })),
|
|
290
|
+
])) : h('span', { class: 'hint' }, t('table.noGroup'))),
|
|
291
|
+
candidates.length > 0 && h('div', { class: 'picks' }, candidates.map((c) => h('button', {
|
|
292
|
+
type: 'button', class: 'add', 'aria-label': t('table.groupBy', { label: label(c) }), onclick: () => setGroups([...groups, c.field!]),
|
|
293
|
+
}, [icon(registry, 'plus', { size: 11 }), label(c)]))),
|
|
294
|
+
]);
|
|
295
|
+
const valuesSec = () => h('div', { class: 'sec' }, [
|
|
296
|
+
h('div', { class: 'sec__ttl' }, t('table.aggregates')),
|
|
297
|
+
h('div', { class: 'drop', style: { borderStyle: 'solid' } }, [
|
|
298
|
+
tablePanelAggregateList(aggregates).map((a) => h('span', { class: 'chip' }, [
|
|
299
|
+
h('span', { class: 'fn' }, tablePanelAggregateLabel(a.fn, (k) => t(k)) + '('), labelOfField(a.field), h('span', { class: 'fn' }, ')'),
|
|
300
|
+
h('button', { type: 'button', 'aria-label': t('select.removeItem', { label: labelOfField(a.field) }), onclick: () => setAgg(a.field, null) }, icon(registry, 'x', { size: 10 })),
|
|
301
|
+
])),
|
|
302
|
+
h('button', { class: 'add', type: 'button', 'aria-expanded': String(this.picker.open), onclick: () => setPicker({ open: !this.picker.open }) }, [icon(registry, 'plus', { size: 11 }), t('common.add')]),
|
|
303
|
+
]),
|
|
304
|
+
this.picker.open && h('div', { class: 'picker' }, [
|
|
305
|
+
h('div', { class: 'row' }, [
|
|
306
|
+
this.held.get('agg|field', this.tag('select'), {
|
|
307
|
+
value: this.picker.field, options: tablePanelAggregateCandidates(columns).map((c) => ({ label: label(c), value: c.field! })), placeholder: t('table.aggregateColumn'),
|
|
308
|
+
ariaLabel: t('table.aggregateColumn'), size: 'sm', style: 'flex: 1',
|
|
309
|
+
}, (v) => setPicker({ field: (v as string | null) ?? null })),
|
|
310
|
+
this.held.get('agg|fn', this.tag('select'), {
|
|
311
|
+
value: this.picker.fn, options: TABLE_AGGREGATE_FNS.map((f) => ({ label: t(f.labelKey), value: f.value })), ariaLabel: t('table.aggregates'), size: 'sm', style: 'width: 90px',
|
|
312
|
+
}, (v) => setPicker({ fn: (v as string | null) ?? 'sum' })),
|
|
313
|
+
]),
|
|
314
|
+
h('div', { class: 'row', style: { justifyContent: 'flex-end' } }, [
|
|
315
|
+
button({ size: 'sm', severity: 'secondary' }, { type: 'button', onclick: closePicker }, t('common.cancel')),
|
|
316
|
+
button({ size: 'sm', disabled: !this.picker.field }, { type: 'button', onclick: () => { if (this.picker.field) setAgg(this.picker.field, this.picker.fn as TableAggregate<unknown>); closePicker(); } }, t('common.add')),
|
|
317
|
+
]),
|
|
318
|
+
]),
|
|
319
|
+
]);
|
|
320
|
+
|
|
321
|
+
const section = active === 'groups' ? groupsSec() : active === 'values' ? valuesSec() : active === 'columns'
|
|
322
|
+
? [h('div', { class: 'sec' }, [
|
|
323
|
+
h('div', { class: 'sec__ttl' }, [t('table.columns'), ' ', h('span', { class: 'grow' }), h('button', { class: 'lnk', type: 'button', onclick: () => setAll(true) }, t('common.reset'))]),
|
|
324
|
+
h('label', { class: 'srch' }, [
|
|
325
|
+
icon(registry, 'search', { size: 13 }),
|
|
326
|
+
h('input', { type: 'search', value: this.query, placeholder: t('table.searchColumn'), 'aria-label': t('table.searchColumnLabel'), oninput: (e: Event) => { this.query = (e.target as HTMLInputElement).value; this.update(); } }),
|
|
327
|
+
]),
|
|
328
|
+
h('div', { class: 'all-row' }, [
|
|
329
|
+
checkboxNode(registry, { id: `${baseId}-all`, checked: all.all, indeterminate: all.some, ariaLabel: t('table.allColumns'), onToggle: setAll }),
|
|
330
|
+
h('span', {}, t('table.allColumns')), h('span', { class: 'cnt' }, `${all.visible}/${all.total}`),
|
|
331
|
+
]),
|
|
332
|
+
h('div', { class: 'cols' }, shownCols.length ? shownCols.map((c) => h('div', { class: ['col-row', { 'is-off': !!c.hidden }] }, [
|
|
333
|
+
checkboxNode(registry, { id: `${baseId}-col-${tableColumnId(c)}`, checked: !c.hidden, ariaLabel: label(c), onToggle: (v) => setVisible(c, v) }),
|
|
334
|
+
h('span', { class: 'lbl' }, label(c)),
|
|
335
|
+
])) : h('div', { class: 'empty' }, t('table.noColumn'))),
|
|
336
|
+
]), inline('groups') && groupsSec(), inline('values') && valuesSec()]
|
|
337
|
+
: h('div', { class: 'sec' }, [
|
|
338
|
+
h('div', { class: 'sec__ttl' }, [
|
|
339
|
+
t('table.filters'), ' ', h('span', { class: 'grow' }),
|
|
340
|
+
tableFilterActiveCount(filters) > 0 && h('button', { class: 'lnk', type: 'button', onclick: clearAll }, t('filter.clearAll')),
|
|
341
|
+
]),
|
|
342
|
+
h('label', { class: 'srch' }, [
|
|
343
|
+
icon(registry, 'search', { size: 13 }),
|
|
344
|
+
h('input', { type: 'search', value: globalFilter, placeholder: t('filter.globalSearch'), 'aria-label': t('filter.globalSearchLabel'), oninput: (e: Event) => setGlobal((e.target as HTMLInputElement).value) }),
|
|
345
|
+
]),
|
|
346
|
+
filterable.length ? filterable.map((c) => {
|
|
347
|
+
const d = draft(c);
|
|
348
|
+
const toggle = () => { patch(c, { ...draft(c), open: !draft(c).open }); this.update(); };
|
|
349
|
+
return h('div', { class: ['flt', { 'is-open': d.open }] }, [
|
|
350
|
+
h('div', {
|
|
351
|
+
class: 'flt__hd', role: 'button', 'aria-expanded': String(d.open), tabindex: 0, onclick: toggle,
|
|
352
|
+
onkeydown: (e: KeyboardEvent) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggle(); } },
|
|
353
|
+
}, [
|
|
354
|
+
icon(registry, 'chevron-right', { size: 12, class: 'chev' }),
|
|
355
|
+
h('span', { class: 'lbl' }, label(c)),
|
|
356
|
+
tablePanelIsActive(filters[c.field ?? '']) && [
|
|
357
|
+
h('span', { class: 'on' }, t('filter.active')),
|
|
358
|
+
h('button', { class: 'clr', type: 'button', 'aria-label': t('filter.clear'), onclick: (e: MouseEvent) => { e.stopPropagation(); clear(c); } }, icon(registry, 'x', { size: 11 })),
|
|
359
|
+
],
|
|
360
|
+
]),
|
|
361
|
+
d.open && h('div', { class: 'flt__bd', onclick: (e: MouseEvent) => e.stopPropagation() }, editor(c)),
|
|
362
|
+
]);
|
|
363
|
+
}) : h('div', { class: 'empty' }, t('filter.noFilterableColumn', { input: 'filterable' })),
|
|
364
|
+
]);
|
|
365
|
+
|
|
366
|
+
return h('div', { class: ['poad-table-panel', tablePanelClasses({ open, position: this.position ?? 'right', overlay: this.overlay })], style: { '--_w': this.width ?? '260px' } }, [
|
|
367
|
+
h('div', { class: 'body', id: body.id, role: body.role, 'aria-labelledby': body['aria-labelledby'] }, h('div', { class: 'body__scroll' }, section)),
|
|
368
|
+
h('div', { class: 'rail', role: 'tablist', 'aria-orientation': 'vertical' }, tabs.map((tab, i) => {
|
|
369
|
+
const tp = tablePanelTabProps({ tab, tabs, open, active, baseId });
|
|
370
|
+
const name = t(TABLE_PANEL_TABS[tab].labelKey);
|
|
371
|
+
return h('button', {
|
|
372
|
+
type: 'button', id: tp.id, role: tp.role, class: tp.selected ? 'is-active' : undefined, 'aria-selected': tp['aria-selected'], 'aria-controls': tp['aria-controls'],
|
|
373
|
+
tabindex: tp.tabindex, title: name, onclick: () => onTab(tab), onkeydown: (e: KeyboardEvent) => onTabKey(i, e),
|
|
374
|
+
}, [icon(registry, TABLE_PANEL_TABS[tab].icon, { size: 15 }), h('span', {}, name)]);
|
|
375
|
+
})),
|
|
376
|
+
]);
|
|
377
|
+
}
|
|
378
|
+
}
|