@poadio/ui-elements 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +47 -1
  3. package/dist/accordion.d.ts +31 -0
  4. package/dist/accordion.d.ts.map +1 -0
  5. package/dist/accordion.js +67 -0
  6. package/dist/accordion.js.map +1 -0
  7. package/dist/checkbox.d.ts +15 -1
  8. package/dist/checkbox.d.ts.map +1 -1
  9. package/dist/checkbox.js +18 -0
  10. package/dist/checkbox.js.map +1 -1
  11. package/dist/combo.d.ts +88 -0
  12. package/dist/combo.d.ts.map +1 -0
  13. package/dist/combo.js +238 -0
  14. package/dist/combo.js.map +1 -0
  15. package/dist/confirm.d.ts +35 -0
  16. package/dist/confirm.d.ts.map +1 -0
  17. package/dist/confirm.js +94 -0
  18. package/dist/confirm.js.map +1 -0
  19. package/dist/datepicker.d.ts +146 -0
  20. package/dist/datepicker.d.ts.map +1 -0
  21. package/dist/datepicker.js +468 -0
  22. package/dist/datepicker.js.map +1 -0
  23. package/dist/declaration.d.ts +25 -0
  24. package/dist/declaration.d.ts.map +1 -0
  25. package/dist/declaration.js +35 -0
  26. package/dist/declaration.js.map +1 -0
  27. package/dist/dialog.d.ts +137 -0
  28. package/dist/dialog.d.ts.map +1 -0
  29. package/dist/dialog.js +174 -0
  30. package/dist/dialog.js.map +1 -0
  31. package/dist/element.d.ts +4 -0
  32. package/dist/element.d.ts.map +1 -1
  33. package/dist/element.js +5 -2
  34. package/dist/element.js.map +1 -1
  35. package/dist/index.d.ts +40 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +23 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/menu.d.ts +121 -0
  40. package/dist/menu.d.ts.map +1 -0
  41. package/dist/menu.js +245 -0
  42. package/dist/menu.js.map +1 -0
  43. package/dist/meter.d.ts +1 -0
  44. package/dist/meter.d.ts.map +1 -1
  45. package/dist/meter.js +1 -2
  46. package/dist/meter.js.map +1 -1
  47. package/dist/multiselect.d.ts +133 -0
  48. package/dist/multiselect.d.ts.map +1 -0
  49. package/dist/multiselect.js +230 -0
  50. package/dist/multiselect.js.map +1 -0
  51. package/dist/option-list.d.ts +28 -0
  52. package/dist/option-list.d.ts.map +1 -0
  53. package/dist/option-list.js +31 -0
  54. package/dist/option-list.js.map +1 -0
  55. package/dist/paginator.d.ts +65 -0
  56. package/dist/paginator.d.ts.map +1 -0
  57. package/dist/paginator.js +110 -0
  58. package/dist/paginator.js.map +1 -0
  59. package/dist/segmented.d.ts +1 -0
  60. package/dist/segmented.d.ts.map +1 -1
  61. package/dist/segmented.js +1 -2
  62. package/dist/segmented.js.map +1 -1
  63. package/dist/select.d.ts +3 -6
  64. package/dist/select.d.ts.map +1 -1
  65. package/dist/select.js +8 -24
  66. package/dist/select.js.map +1 -1
  67. package/dist/services.d.ts +3 -0
  68. package/dist/services.d.ts.map +1 -0
  69. package/dist/services.js +10 -0
  70. package/dist/services.js.map +1 -0
  71. package/dist/slider.d.ts +1 -0
  72. package/dist/slider.d.ts.map +1 -1
  73. package/dist/slider.js +1 -2
  74. package/dist/slider.js.map +1 -1
  75. package/dist/split-button.d.ts +47 -0
  76. package/dist/split-button.d.ts.map +1 -0
  77. package/dist/split-button.js +64 -0
  78. package/dist/split-button.js.map +1 -0
  79. package/dist/stepper.d.ts +56 -0
  80. package/dist/stepper.d.ts.map +1 -0
  81. package/dist/stepper.js +69 -0
  82. package/dist/stepper.js.map +1 -0
  83. package/dist/table.d.ts +176 -0
  84. package/dist/table.d.ts.map +1 -0
  85. package/dist/table.js +293 -0
  86. package/dist/table.js.map +1 -0
  87. package/dist/tabs.d.ts +62 -0
  88. package/dist/tabs.d.ts.map +1 -0
  89. package/dist/tabs.js +118 -0
  90. package/dist/tabs.js.map +1 -0
  91. package/dist/toast.d.ts +79 -0
  92. package/dist/toast.d.ts.map +1 -0
  93. package/dist/toast.js +176 -0
  94. package/dist/toast.js.map +1 -0
  95. package/package.json +3 -3
  96. package/src/accordion.ts +80 -0
  97. package/src/checkbox.ts +21 -1
  98. package/src/combo.ts +220 -0
  99. package/src/confirm.ts +106 -0
  100. package/src/datepicker.ts +413 -0
  101. package/src/declaration.ts +37 -0
  102. package/src/dialog.ts +217 -0
  103. package/src/element.ts +7 -2
  104. package/src/index.ts +33 -2
  105. package/src/menu.ts +281 -0
  106. package/src/meter.ts +2 -1
  107. package/src/multiselect.ts +273 -0
  108. package/src/option-list.ts +51 -0
  109. package/src/paginator.ts +151 -0
  110. package/src/segmented.ts +2 -1
  111. package/src/select.ts +14 -30
  112. package/src/services.ts +10 -0
  113. package/src/slider.ts +2 -1
  114. package/src/split-button.ts +76 -0
  115. package/src/stepper.ts +86 -0
  116. package/src/table.ts +364 -0
  117. package/src/tabs.ts +129 -0
  118. package/src/toast.ts +203 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * <poad-split-button label="Save" icon="save" items='[{"label":"Save and close"}]'></poad-split-button>
3
+ *
4
+ * Bouton principal + bouton chevron accolé qui ouvre un menu flottant ancré sur lui (le même que `<poad-menu>`).
5
+ * Mêmes options d'apparence que `<poad-button>` (`severity`, `variant`, `size`, `loading`, `disabled`). Attributs du
6
+ * chevron (`aria-haspopup="menu"`, `aria-expanded`) et tailles d'icône : `menu` de @poadio/ui-core. Évènements :
7
+ * `press` (bouton principal), `itemclick` (detail `{ item, originalEvent }`), `openchange` (detail : ouvert ou non).
8
+ * Le contenu de l'élément suit le libellé dans le bouton principal. Même DOM que `poad-split-button` d'ui-angular.
9
+ * Styles : `menu.css`, `button.css` (et ceux du menu).
10
+ */
11
+ import { buttonClasses, splitButtonIconSize, splitButtonToggleProps, type ButtonSeverity, type ButtonSize, type ButtonVariant } from '@poadio/ui-core';
12
+ import { button } from './button.js';
13
+ import { h } from './dom.js';
14
+ import { PoadElement } from './element.js';
15
+ import { icon } from './icon.js';
16
+ import { MenuController, type PoadMenuItem } from './menu.js';
17
+
18
+ export class PoadSplitButtonElement extends PoadElement {
19
+ static override props = {
20
+ label: 'string', icon: 'string', items: 'json', severity: 'string', variant: 'string', size: 'string', loading: 'boolean', disabled: 'boolean',
21
+ dropdownAriaLabel: 'string', menuMinWidth: 'number', mobile: 'string',
22
+ } as const;
23
+ declare label?: string;
24
+ declare icon?: string;
25
+ declare items?: readonly PoadMenuItem[];
26
+ declare severity?: ButtonSeverity;
27
+ declare variant?: ButtonVariant;
28
+ declare size?: ButtonSize;
29
+ declare loading?: boolean;
30
+ declare disabled?: boolean;
31
+ declare dropdownAriaLabel?: string;
32
+ declare menuMinWidth?: number;
33
+ declare mobile?: 'auto' | 'sheet' | 'popover';
34
+ private open = false;
35
+ private toggleEl: HTMLElement | null = null;
36
+ private readonly menu = new MenuController(this);
37
+
38
+ private setOpen(next: boolean) {
39
+ if (next === this.open) return;
40
+ this.open = next;
41
+ this.update();
42
+ this.emit('openchange', next);
43
+ }
44
+ override disconnectedCallback(): void {
45
+ super.disconnectedCallback();
46
+ this.open = false;
47
+ this.menu.dispose();
48
+ }
49
+ protected render() {
50
+ const { t, text } = this.i18n();
51
+ const registry = this.icons();
52
+ const size = this.size ?? 'md';
53
+ const iconSize = splitButtonIconSize(size);
54
+ const tg = splitButtonToggleProps(this.open, this.disabled, this.loading);
55
+ const look = { severity: this.severity ?? 'primary', variant: this.variant ?? 'solid', size } as const;
56
+ const main = { ...look, loading: this.loading, disabled: this.disabled };
57
+ const toggle = { ...look, disabled: tg.disabled, icon: true };
58
+ return h('div', { class: ['poad-split-button', { 'is-disabled': !!this.disabled }] }, [
59
+ button(main, { type: 'button', class: `${buttonClasses(main)} poad-split-button__main`, onclick: () => this.emit('press') },
60
+ [this.icon && icon(registry, this.icon, { size: iconSize }), this.label && h('span', {}, this.label), this.content]),
61
+ button(toggle, {
62
+ type: 'button', class: `${buttonClasses(toggle)} poad-split-button__toggle`, ref: (el: HTMLElement) => { this.toggleEl = el; },
63
+ 'aria-label': text(this.dropdownAriaLabel, 'nav.moreActions'), 'aria-haspopup': tg['aria-haspopup'], 'aria-expanded': tg['aria-expanded'],
64
+ onclick: () => this.setOpen(!this.open),
65
+ }, icon(registry, 'chevron-down', { size: iconSize - 2 })),
66
+ this.menu.render({
67
+ id: `${this.uid}-menu`, items: this.items ?? [], open: this.open, popup: true, anchor: () => this.toggleEl, contextual: false, minWidth: this.menuMinWidth,
68
+ mobile: this.mobile, closeLabel: t('common.close'), icons: registry, setOpen: (open) => this.setOpen(open),
69
+ onItemClick: (item, originalEvent) => this.emit('itemclick', { item, originalEvent }),
70
+ }),
71
+ ]);
72
+ }
73
+ protected override updated(): void {
74
+ this.menu.sync();
75
+ }
76
+ }
package/src/stepper.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * <poad-stepper active-index="0" linear aria-label="Deployment">
3
+ * <poad-step label="Domain" description="DNS" completed>…contenu…</poad-step>
4
+ * <poad-step label="Certificate" optional>…</poad-step>
5
+ * <poad-step label="Go live"></poad-step>
6
+ * </poad-stepper>
7
+ *
8
+ * Étapes : machine `stepper` de @poadio/ui-core (état affiché de chaque étape, étapes atteignables en `linear`,
9
+ * `aria-current="step"`). Les `<poad-step>` sont des DÉCLARATIONS (leur contenu va dans le panneau de l'étape
10
+ * courante). Propriété `activeIndex` ; la page avance en la changeant (ses boutons « suivant » sont les siens).
11
+ * Évènements : `change` (detail : le rang de l'étape où l'utilisateur va par un clic), `stepclick` (detail : le rang
12
+ * cliqué, même non atteignable). Même DOM, mêmes classes, même ARIA que `poad-stepper` d'ui-angular. Style :
13
+ * `@poadio/ui-core/stepper.css` (et `icon.css`).
14
+ */
15
+ import { stepperGoTo, stepperItemProps, stepperRootClasses, type StepItem, type StepState } from '@poadio/ui-core';
16
+ import { PoadDeclarationElement, declarations } from './declaration.js';
17
+ import { h } from './dom.js';
18
+ import { PoadElement } from './element.js';
19
+ import { icon } from './icon.js';
20
+
21
+ export interface StepData {
22
+ readonly label?: string;
23
+ readonly description?: string;
24
+ readonly icon?: string;
25
+ readonly optional?: boolean;
26
+ readonly disabled?: boolean;
27
+ readonly completed?: boolean;
28
+ readonly state?: StepState | null;
29
+ }
30
+
31
+ /** Déclaration d'une étape dans un `<poad-stepper>` ; ses enfants sont son contenu. */
32
+ export class PoadStepElement extends PoadDeclarationElement {
33
+ static override props = {
34
+ label: 'string', description: 'string', icon: 'string', optional: 'boolean', disabled: 'boolean', completed: 'boolean', state: 'string',
35
+ } as const;
36
+ }
37
+
38
+ export class PoadStepperElement extends PoadElement {
39
+ static override props = {
40
+ activeIndex: 'number', linear: 'boolean', clickable: 'boolean', orientation: 'string', size: 'string', ariaLabel: 'string',
41
+ } as const;
42
+ declare activeIndex?: number;
43
+ declare linear?: boolean;
44
+ declare clickable?: boolean;
45
+ declare orientation?: 'horizontal' | 'vertical';
46
+ declare size?: 'sm' | 'md';
47
+ declare ariaLabel: string | null;
48
+
49
+ protected render() {
50
+ const { t } = this.i18n();
51
+ const registry = this.icons();
52
+ const steps = declarations<StepData>(this, this.content, this.tag('step'), PoadStepElement.props);
53
+ const items: StepItem[] = steps.map(({ data: s }) => ({ disabled: s.disabled, completed: s.completed, optional: s.optional, state: s.state }));
54
+ const active = this.activeIndex ?? 0;
55
+ const clickable = this.clickable !== false;
56
+ const vertical = this.orientation === 'vertical';
57
+ const click = (i: number) => {
58
+ this.emit('stepclick', i);
59
+ if (!clickable) return;
60
+ const to = stepperGoTo(items, active, i, this.linear);
61
+ if (to === null) return;
62
+ this.activeIndex = to;
63
+ this.emit('change', to);
64
+ };
65
+ return h('div', { class: ['poad-stepper', stepperRootClasses({ orientation: this.orientation, size: this.size })] }, [
66
+ h('ol', { class: 'poad-stepper__list', 'aria-label': this.ariaLabel || undefined }, steps.map(({ data: s, content }, i) => {
67
+ const a = stepperItemProps(items, i, active, { linear: this.linear, clickable });
68
+ return h('li', { class: ['poad-stepper__item', a.classes], 'data-state': a.state }, [
69
+ h('button', { type: 'button', class: 'poad-stepper__btn', disabled: a.disabled, 'aria-current': a['aria-current'], onclick: () => click(i) }, [
70
+ h('span', { class: 'poad-stepper__dot', 'aria-hidden': 'true' },
71
+ a.state === 'done' ? icon(registry, 'check', { size: 11, strokeWidth: 3 })
72
+ : a.state === 'error' ? icon(registry, 'x', { size: 11, strokeWidth: 3 })
73
+ : s.icon ? icon(registry, s.icon, { size: 12 }) : String(i + 1)),
74
+ h('span', { class: 'poad-stepper__txt' }, [
75
+ h('span', { class: 'poad-stepper__label' }, [s.label ?? '', s.optional && h('small', {}, ` ${t('nav.optional')}`)]),
76
+ s.description && h('span', { class: 'poad-stepper__desc' }, s.description),
77
+ ]),
78
+ ]),
79
+ i < steps.length - 1 && h('span', { class: 'poad-stepper__line', 'aria-hidden': 'true' }),
80
+ vertical && i === active && h('div', { class: 'poad-stepper__panel' }, content),
81
+ ]);
82
+ })),
83
+ !vertical && steps[active] && h('div', { class: 'poad-stepper__panel' }, steps[active]!.content),
84
+ ]);
85
+ }
86
+ }
package/src/table.ts ADDED
@@ -0,0 +1,364 @@
1
+ /**
2
+ * <poad-table data-key="id" selection-mode="multiple" paginator rows="10"
3
+ * columns='[{"field":"name","header":"Project","sortable":true},{"field":"pods","header":"Pods","dataType":"number"}]'>
4
+ * <button slot="toolbar">Export</button>
5
+ * </poad-table>
6
+ * table.value = rows;
7
+ * table.renderCell = ({ row, column }) => column.field === 'name' ? Object.assign(document.createElement('b'), { textContent: row.name }) : undefined;
8
+ * table.addEventListener('selectionchange', (e) => e.detail);
9
+ *
10
+ * Table de données, tranche 1 : modèle `table` et machine `paginator` de @poadio/ui-core — colonnes en données
11
+ * (`columns`, propriété ou attribut JSON ; une colonne posée en propriété peut porter `cell` / `headerCell`), rendu de
12
+ * cellule par une fonction (`renderCell(ctx)` → texte, nœud, ou `undefined` pour le texte par défaut) et d'en-tête
13
+ * (`renderHeader(column)`), tri simple / multiple (`Intl.Collator` de la langue de l'élément), pagination, données
14
+ * serveur (`lazy`, évènement `lazyload`), sélection simple / multiple / cases avec plage à la Maj, états vide et
15
+ * chargement, grille WAI-ARIA dont la ligne a le focus. Tri (`sort`), page (`first`, `rows`) et sélection
16
+ * (`selection`) sont tenus par l'élément, comme la valeur d'un champ natif : un geste les change et émet
17
+ * `sortchange`, `pagechange`, `selectionchange` ; une valeur posée par la page est rendue sans évènement. Contenu de la
18
+ * page placé par `slot="toolbar"`, `"toolbar-end"`, `"selection-bar"`, `"empty"`, `"caption"`. Même DOM, mêmes classes,
19
+ * même ARIA que `poad-table` d'ui-angular. Styles : `@poadio/ui-core/table.css`, `paginator.css`, `checkbox.css`,
20
+ * `icon.css`.
21
+ */
22
+ import {
23
+ TABLE_ROW_CLICK_IGNORE, paginatorClampFirst, tableActiveIndex, tableAllState, tableAriaSort, tableBodyState, tableClearSelection, tableCollator, tableColumnAlign,
24
+ tableColumnId, tableColumnSortField, tableColspan, tableFormatCell, tableGridKey, tableHeaderCellProps, tableHeaderRowProps, tablePageRows, tableResolve,
25
+ tableRootClasses, tableRootProps, tableRowClasses, tableRowClickAction, tableRowKey, tableRowProps, tableSelectOnly, tableSelectRange, tableSelectSingle,
26
+ tableSelectionArray, tableSelectionKeys, tableSelectionValue, tableShowsOverlay, tableSkeletonWidth, tableSortIcon, tableSortIndex, tableSortOrderOf, tableSortState,
27
+ tableSortToggle, tableTdClasses, tableThClasses, tableToggleAll, tableToggleRow, tableView,
28
+ type PaginatorEvent, type TableColumnDef, type TableSelectionChange, type TableSelectionMode, type TableSortMeta, type TableSortMode, type TableSortOrder,
29
+ } from '@poadio/ui-core';
30
+ import { checkboxNode } from './checkbox.js';
31
+ import { h, type Child } from './dom.js';
32
+ import { PoadElement } from './element.js';
33
+ import { icon } from './icon.js';
34
+ import { paginatorView } from './paginator.js';
35
+
36
+ type Row = unknown;
37
+ /** Ce que reçoit `renderCell`. */
38
+ export interface PoadTableCellContext {
39
+ readonly row: Row;
40
+ readonly value: unknown;
41
+ /** Position de la ligne dans la page. */
42
+ readonly rowIndex: number;
43
+ readonly column: PoadTableColumn;
44
+ }
45
+ /** Une colonne en données. `cell` / `headerCell` : seulement quand `columns` est posé en propriété. */
46
+ export interface PoadTableColumn extends TableColumnDef {
47
+ readonly width?: string;
48
+ readonly minWidth?: string;
49
+ readonly maxWidth?: string;
50
+ readonly hidden?: boolean;
51
+ readonly cell?: (ctx: PoadTableCellContext) => string | Node | null | undefined;
52
+ readonly headerCell?: (column: PoadTableColumn) => string | Node;
53
+ }
54
+ export interface PoadTableSortDetail { readonly field: string | null; readonly order: TableSortOrder; readonly multiSortMeta: TableSortMeta[] }
55
+ export interface PoadTableLazyLoadDetail { readonly first: number; readonly rows: number; readonly sortField: string | null; readonly sortOrder: TableSortOrder; readonly multiSortMeta: TableSortMeta[] }
56
+ export interface PoadTableRowDetail { readonly row: Row; readonly index: number }
57
+
58
+ const slotted = (content: readonly Node[] | null, name: string) => (content ?? []).filter((n) => n instanceof Element && n.getAttribute('slot') === name);
59
+
60
+ export class PoadTableElement extends PoadElement {
61
+ static override props = {
62
+ value: 'json', columns: 'json', dataKey: 'string', sortMode: 'string', sort: 'json', defaultSortOrder: 'number', customSort: 'boolean',
63
+ paginator: 'boolean', first: 'number', rows: 'number', rowsPerPageOptions: 'json', totalRecords: 'number', showCurrentPageReport: 'boolean',
64
+ currentPageReportTemplate: 'string', pageLinks: 'number', showFirstLastIcon: 'boolean', alwaysShowPaginator: 'boolean', lazy: 'boolean', lazyLoadOnInit: 'boolean',
65
+ selectionMode: 'string', selection: 'json', selectAll: 'boolean', selectAllScope: 'string', metaKeySelection: 'boolean', showSelectionBar: 'boolean',
66
+ loading: 'boolean', loadingRows: 'number', emptyMessage: 'string', emptyHint: 'string', emptyIcon: 'string', dense: 'boolean', striped: 'boolean',
67
+ hoverable: 'boolean', bordered: 'boolean', borderless: 'boolean', stickyHeader: 'boolean', bodyMaxHeight: 'string', tableClass: 'string', showToolbar: 'boolean',
68
+ heading: 'string', count: 'number', showCount: 'boolean',
69
+ } as const;
70
+ static override functions = ['renderCell', 'renderHeader', 'cellFormatter', 'rowSelectable', 'rowClass'] as const;
71
+ declare value?: readonly Row[];
72
+ declare columns?: readonly PoadTableColumn[];
73
+ /** Chemin de la clé d'une ligne (sinon : la ligne elle-même). */
74
+ declare dataKey?: string;
75
+ declare sortMode?: TableSortMode;
76
+ /** Tri courant (critères dans l'ordre). */
77
+ declare sort?: readonly TableSortMeta[];
78
+ declare defaultSortOrder?: 1 | -1;
79
+ /** La page trie elle-même (reçoit `sortchange`, pose `value` trié). */
80
+ declare customSort?: boolean;
81
+ declare paginator?: boolean;
82
+ declare first?: number;
83
+ /** Taille de page (défaut 25). */
84
+ declare rows?: number;
85
+ declare rowsPerPageOptions?: readonly number[];
86
+ /** Nombre total de lignes (données serveur). */
87
+ declare totalRecords?: number;
88
+ declare showCurrentPageReport?: boolean;
89
+ declare currentPageReportTemplate?: string;
90
+ declare pageLinks?: number;
91
+ declare showFirstLastIcon?: boolean;
92
+ declare alwaysShowPaginator?: boolean;
93
+ declare lazy?: boolean;
94
+ declare lazyLoadOnInit?: boolean;
95
+ declare selectionMode?: TableSelectionMode;
96
+ /** Ligne (simple) ou lignes (multiple) choisies. */
97
+ declare selection?: Row | readonly Row[] | null;
98
+ declare selectAll?: boolean;
99
+ declare selectAllScope?: 'page' | 'all';
100
+ declare metaKeySelection?: boolean;
101
+ declare showSelectionBar?: boolean;
102
+ declare loading?: boolean;
103
+ declare loadingRows?: number;
104
+ declare emptyMessage?: string;
105
+ declare emptyHint?: string;
106
+ declare emptyIcon?: string;
107
+ declare dense?: boolean;
108
+ declare striped?: boolean;
109
+ declare hoverable?: boolean;
110
+ declare bordered?: boolean;
111
+ declare borderless?: boolean;
112
+ declare stickyHeader?: boolean;
113
+ /** Hauteur maximale de la zone qui défile (`scrollHeight` d'Angular et React ; ici `bodyMaxHeight`, `scrollHeight` étant la hauteur mesurée de tout élément). */
114
+ declare bodyMaxHeight?: string;
115
+ declare tableClass?: string;
116
+ declare showToolbar?: boolean;
117
+ /** Titre de la barre (`title` d'Angular et React ; ici `heading`, pour ne pas donner une info-bulle à toute la table). */
118
+ declare heading?: string;
119
+ declare count?: number;
120
+ declare showCount?: boolean;
121
+ /** Rendu d'une cellule : texte, nœud, ou `undefined` pour le texte mis en forme de la valeur. */
122
+ declare renderCell?: (ctx: PoadTableCellContext) => string | Node | null | undefined;
123
+ /** Rendu d'un en-tête (remplace le libellé et le bouton de tri) ; `undefined` : celui par défaut. */
124
+ declare renderHeader?: (column: PoadTableColumn) => string | Node | null | undefined;
125
+ declare cellFormatter?: (value: unknown, column: PoadTableColumn, row: Row) => string;
126
+ declare rowSelectable?: (row: Row) => boolean;
127
+ declare rowClass?: (row: Row, index: number) => string;
128
+
129
+ private activeKey: unknown = undefined;
130
+ private anchor: number | null = null;
131
+ private loadedOnce = false;
132
+ /** Tri mémorisé : rien ne se retrie si ni les lignes, ni le tri, ni la langue ne changent (10 000 lignes : quelques dizaines de ms). */
133
+ private memo: { readonly value: unknown; readonly sort: string; readonly locale: string; readonly flags: string; readonly sorted: readonly Row[] } | null = null;
134
+
135
+ private get metas(): TableSortMeta[] {
136
+ const sort = this.sort ?? [];
137
+ return (this.sortMode ?? 'single') === 'single' ? sort.slice(0, 1) : [...sort];
138
+ }
139
+ private keyOf = (r: Row) => tableRowKey(r, this.dataKey);
140
+ private sorted(locale: string): readonly Row[] {
141
+ const value = this.value ?? [];
142
+ const metas = this.metas;
143
+ const key = JSON.stringify(metas), flags = `${!!this.lazy}${!!this.customSort}`;
144
+ const m = this.memo;
145
+ if (m && m.value === value && m.sort === key && m.locale === locale && m.flags === flags) return m.sorted;
146
+ const sorted = tableView(value, { metas, collator: tableCollator(locale), lazy: this.lazy, customSort: this.customSort }).sorted;
147
+ this.memo = { value, sort: key, locale, flags, sorted };
148
+ return sorted;
149
+ }
150
+ private lazyDetail(first: number, rows: number, metas: readonly TableSortMeta[]): PoadTableLazyLoadDetail {
151
+ const s = tableSortState(metas);
152
+ return { first, rows, sortField: s.field, sortOrder: s.order, multiSortMeta: s.multiSortMeta };
153
+ }
154
+ private tbody(): HTMLElement | null {
155
+ return this.querySelector<HTMLElement>(':scope > .poad-table > .dt > .dt-scroll > table > tbody');
156
+ }
157
+
158
+ protected override updated(): void {
159
+ if (!this.loadedOnce) {
160
+ this.loadedOnce = true;
161
+ if (this.lazy && this.lazyLoadOnInit !== false) this.emit('lazyload', this.lazyDetail(this.first ?? 0, this.rows ?? 25, this.metas));
162
+ }
163
+ }
164
+
165
+ protected render(): Child {
166
+ const i18n = this.i18n();
167
+ const { t, text, locale } = i18n;
168
+ const registry = this.icons();
169
+ const value = this.value ?? [];
170
+ const mode = this.selectionMode ?? null;
171
+ const sortMode = this.sortMode ?? 'single';
172
+ const metas = this.metas;
173
+ const rows = this.rows ?? 25;
174
+ const sorted = this.sorted(locale);
175
+ const total = this.lazy ? (this.totalRecords ?? value.length) : sorted.length;
176
+ // retour sur la dernière page quand `first` dépasse (filtre, suppression) : corrigé sans évènement, comme React
177
+ const back = !this.lazy && this.paginator ? paginatorClampFirst(this.first ?? 0, total, rows) : null;
178
+ if (back !== null) this.propValues['first'] = back;
179
+ const first = this.first ?? 0;
180
+ const page = this.paginator && !this.lazy ? tablePageRows(sorted, first, rows) : sorted;
181
+ const columns = (this.columns ?? []).filter((c) => !c.hidden);
182
+ const keyOf = this.keyOf;
183
+ const selected = tableSelectionArray<Row>(this.selection as Row | Row[] | null);
184
+ const selectedKeys = tableSelectionKeys<Row>(this.selection as Row | Row[] | null, keyOf);
185
+ const canSelect = (r: Row) => this.rowSelectable?.(r) ?? true;
186
+ const scope = (this.selectAllScope === 'all' ? sorted : page).filter(canSelect);
187
+ const allState = tableAllState(scope, selectedKeys, keyOf);
188
+ const body = tableBodyState({ loading: this.loading, hasData: value.length > 0, rowCount: page.length });
189
+ const trackOf = (r: Row, i: number) => (this.dataKey ? keyOf(r) : i);
190
+ const activeAt = tableActiveIndex(Math.max(0, page.findIndex((r, i) => trackOf(r, i) === this.activeKey)), page.length);
191
+ const hasSel = !!mode;
192
+ const rowOffset = this.paginator || this.lazy ? first : 0;
193
+
194
+ // ---- tri ----
195
+ const sortBy = (c: PoadTableColumn, e: MouseEvent) => {
196
+ const field = tableColumnSortField(c);
197
+ if (!field) return;
198
+ const next = tableSortToggle(metas, field, { mode: sortMode, additive: e.ctrlKey || e.metaKey || e.shiftKey, defaultOrder: this.defaultSortOrder ?? 1 });
199
+ this.sort = next;
200
+ this.emit('sortchange', tableSortState(next) satisfies PoadTableSortDetail);
201
+ if (this.lazy) this.emit('lazyload', this.lazyDetail(first, rows, next));
202
+ };
203
+ // ---- pagination ----
204
+ const changePage = (e: PaginatorEvent) => {
205
+ this.propValues['first'] = e.first;
206
+ this.rows = e.rows;
207
+ this.emit('pagechange', e);
208
+ if (this.lazy) this.emit('lazyload', this.lazyDetail(e.first, e.rows, metas));
209
+ const scroller = this.querySelector<HTMLElement>(':scope > .poad-table > .dt > .dt-scroll');
210
+ if (scroller) scroller.scrollTop = 0;
211
+ };
212
+ // ---- sélection ----
213
+ const apply = (ch: TableSelectionChange<Row> | null, index: number | null) => {
214
+ if (!ch) return;
215
+ this.selection = tableSelectionValue(ch.next, mode);
216
+ this.emit('selectionchange', this.selection);
217
+ ch.added.forEach((row) => this.emit('rowselect', { row, index: index ?? -1 } satisfies PoadTableRowDetail));
218
+ ch.removed.forEach((row) => this.emit('rowunselect', { row, index: index ?? -1 } satisfies PoadTableRowDetail));
219
+ };
220
+ const toggleRow = (row: Row, i: number) => { if (!canSelect(row)) return; this.anchor = i; apply(tableToggleRow(selected, row, keyOf), i); };
221
+ const selectSingle = (row: Row, i: number) => { if (!canSelect(row)) return; this.anchor = i; apply(tableSelectSingle(selected, row, keyOf), i); };
222
+ const selectRange = (from: number, to: number) => apply(tableSelectRange(selected, page, from, to, keyOf, canSelect), to);
223
+ const toggleAll = () => apply(tableToggleAll(selected, scope, keyOf), null);
224
+
225
+ const onRowClick = (row: Row, i: number, e: MouseEvent) => {
226
+ if ((e.target as Element).closest(TABLE_ROW_CLICK_IGNORE)) return;
227
+ this.activeKey = trackOf(row, i);
228
+ this.emit('rowclick', { row, index: i } satisfies PoadTableRowDetail);
229
+ const action = tableRowClickAction({ mode, selectable: canSelect(row), shiftKey: e.shiftKey, ctrlKey: e.ctrlKey, metaKey: e.metaKey, metaKeySelection: this.metaKeySelection, hasAnchor: this.anchor != null });
230
+ if (action === 'single') selectSingle(row, i);
231
+ else if (action === 'range') selectRange(this.anchor!, i);
232
+ else if (action === 'only') { this.anchor = i; apply(tableSelectOnly(selected, row, keyOf), i); }
233
+ else if (action === 'toggle') toggleRow(row, i);
234
+ this.update(); // ligne active (focus itinérant), même sans changement de sélection
235
+ };
236
+ const onRowKeydown = (i: number, e: KeyboardEvent) => {
237
+ if (e.target !== e.currentTarget && (e.target as Element).closest('input, select, textarea, button, a')) return;
238
+ const eff = tableGridKey(e, { index: i, count: page.length, mode, selectAll: this.selectAll });
239
+ if (!eff) return;
240
+ e.preventDefault();
241
+ const to = eff.move ?? i;
242
+ if (eff.move !== undefined && eff.move !== i) {
243
+ this.activeKey = trackOf(page[eff.move], eff.move);
244
+ this.tbody()?.querySelectorAll<HTMLElement>(':scope > tr.dt-row')[eff.move]?.focus();
245
+ }
246
+ const row = page[to];
247
+ if (eff.select === 'all') { if (allState !== 'all') toggleAll(); }
248
+ else if (to < page.length && eff.select === 'single') selectSingle(row, to);
249
+ else if (to < page.length && eff.select === 'toggle') toggleRow(row, to);
250
+ else if (to < page.length && eff.select === 'range' && canSelect(row)) selectRange(this.anchor ?? i, to);
251
+ this.update(); // ligne active (focus itinérant)
252
+ };
253
+
254
+ // ---- rendu ----
255
+ const format = (v: unknown, c: PoadTableColumn, row: Row) =>
256
+ this.cellFormatter ? this.cellFormatter(v, c, row) : tableFormatCell(v, c.dataType, { locale, booleanText: (b) => t(b ? 'common.yes' : 'common.no') });
257
+ const selCount = selectedKeys.size;
258
+ const ta = tableRootProps({ mode, busy: this.loading, rowCount: total, headerRows: 1 });
259
+ const colspan = tableColspan({ columns: columns.length, selection: hasSel });
260
+ const check = (id: string, checked: boolean, label: string, onToggle: () => void, indeterminate?: boolean) =>
261
+ checkboxNode(registry, { id: `${this.uid}-${id}`, checked, indeterminate, ariaLabel: label, onToggle });
262
+
263
+ const header = (c: PoadTableColumn) => {
264
+ const field = tableColumnSortField(c);
265
+ const order = tableSortOrderOf(metas, field);
266
+ const idx = sortMode === 'multiple' ? tableSortIndex(metas, field) : 0;
267
+ const hp = tableHeaderCellProps({ ariaSort: tableAriaSort(metas, field, !!c.sortable) });
268
+ const custom = c.headerCell?.(c) ?? this.renderHeader?.(c);
269
+ return h('th', { scope: hp.scope, class: tableThClasses(c, order !== 0), 'aria-sort': hp['aria-sort'], style: c.width ? { width: c.width } : undefined }, custom != null ? custom : c.sortable
270
+ ? h('button', { type: 'button', class: 'hd', 'aria-label': t('table.sortBy', { column: c.header ?? '' }), onclick: (e: MouseEvent) => sortBy(c, e) }, [
271
+ h('span', { class: 'hd-txt' }, c.header ?? ''),
272
+ icon(registry, tableSortIcon(order), { size: 12 }),
273
+ idx > 0 && h('span', { class: 'hd-idx' }, String(idx)),
274
+ ])
275
+ : h('span', { class: 'hd' }, h('span', { class: 'hd-txt' }, c.header ?? '')));
276
+ };
277
+ const cell = (row: Row, i: number, c: PoadTableColumn, ci: number) => {
278
+ const v = c.field ? tableResolve(row, c.field) : undefined;
279
+ const ctx: PoadTableCellContext = { row, value: v, rowIndex: i, column: c };
280
+ const custom = c.cell?.(ctx) ?? this.renderCell?.(ctx);
281
+ return h('td', { class: tableTdClasses(c) + (ci === 0 ? ' dt-first' : ''), 'data-l': c.header }, custom != null ? custom : h('span', { class: 'cell-txt' }, format(v, c, row)));
282
+ };
283
+ const bodyRows = (): Child => {
284
+ if (body === 'skeleton') {
285
+ return Array.from({ length: this.loadingRows ?? 5 }, (_, r) => h('tr', { class: 'dt-row is-skeleton', 'aria-hidden': 'true' }, [
286
+ hasSel && h('td', { class: 'col-sel' }),
287
+ columns.map((c, ci) => h('td', { class: tableTdClasses(c) }, h('div', { class: 'skel', style: { width: tableSkeletonWidth(r, ci) + '%', marginLeft: tableColumnAlign(c) === 'right' ? 'auto' : undefined } }))),
288
+ ]));
289
+ }
290
+ if (body === 'empty') {
291
+ const empty = slotted(this.content, 'empty');
292
+ return h('tr', { class: 'dt-empty' }, h('td', { colspan }, empty.length ? empty : h('div', { class: 'empty' }, [
293
+ (this.emptyIcon ?? 'inbox') && icon(registry, this.emptyIcon ?? 'inbox', { size: 26, strokeWidth: 1.5 }),
294
+ h('b', {}, text(this.emptyMessage, 'table.empty')),
295
+ this.emptyHint && h('span', {}, this.emptyHint),
296
+ ])));
297
+ }
298
+ return page.map((row, i) => {
299
+ const sel = selectedKeys.has(keyOf(row));
300
+ const rp = tableRowProps({ position: rowOffset + i, mode, selected: sel, active: i === activeAt });
301
+ const track = trackOf(row, i);
302
+ return h('tr', {
303
+ class: tableRowClasses({ selectable: hasSel && canSelect(row), hasSelectionColumn: hasSel, selected: sel, extra: this.rowClass?.(row, i) }),
304
+ 'data-key': this.dataKey ? String(track) : undefined, tabindex: rp.tabindex, 'aria-selected': rp['aria-selected'], 'aria-rowindex': rp['aria-rowindex'],
305
+ onclick: (e: MouseEvent) => onRowClick(row, i, e), ondblclick: () => this.emit('rowdblclick', { row, index: i } satisfies PoadTableRowDetail),
306
+ onkeydown: (e: KeyboardEvent) => onRowKeydown(i, e),
307
+ // focus itinérant posé sans redessiner : un nouveau rendu remplacerait les nœuds de `renderCell` sous le pointeur
308
+ // (le clic qui suit l'appui n'arriverait pas) ; le prochain rendu trouve les mêmes valeurs
309
+ onfocus: (e: FocusEvent) => {
310
+ if (e.target !== e.currentTarget || this.activeKey === track) return;
311
+ this.activeKey = track;
312
+ this.tbody()?.querySelectorAll(':scope > tr.dt-row').forEach((tr) => { if (tr.hasAttribute('tabindex')) tr.setAttribute('tabindex', tr === e.currentTarget ? '0' : '-1'); });
313
+ },
314
+ }, [
315
+ hasSel && h('td', { class: 'col-sel' }, canSelect(row) && check(`r${i}`, sel, t('table.selectRow', { index: i + 1 }), () => (mode === 'multiple' ? toggleRow(row, i) : selectSingle(row, i)))),
316
+ columns.map((c, ci) => cell(row, i, c, ci)),
317
+ ]);
318
+ });
319
+ };
320
+
321
+ const caption = slotted(this.content, 'caption');
322
+ return h('div', {
323
+ class: ['poad-table', tableRootClasses({ dense: this.dense, striped: this.striped, hoverable: this.hoverable, bordered: this.bordered, borderless: this.borderless, stickyHeader: this.stickyHeader, scrollHeight: this.bodyMaxHeight, loading: this.loading })],
324
+ style: this.bodyMaxHeight ? { '--_scroll-h': this.bodyMaxHeight } : undefined,
325
+ }, h('div', { class: 'dt' }, [
326
+ selCount > 0 && (this.showSelectionBar ?? true) ? h('div', { class: 'dt-sel', role: 'region', 'aria-live': 'polite' }, [
327
+ check('bar-all', allState === 'all', t('table.selectAll'), toggleAll, allState === 'some'),
328
+ h('span', {}, t('table.selectedCount', { n: selCount })),
329
+ h('span', { class: 'dt-sel__grow' }),
330
+ slotted(this.content, 'selection-bar'),
331
+ h('button', { type: 'button', class: 'dt-sel__clear', 'aria-label': t('table.clearSelection'), onclick: () => apply(tableClearSelection(selected), null) }, icon(registry, 'x', { size: 14 })),
332
+ ]) : (this.showToolbar ?? true) && h('div', { class: 'dt-bar' }, [
333
+ this.heading && h('span', { class: 'dt-bar__title' }, this.heading),
334
+ (this.showCount ?? true) && h('span', { class: 'dt-bar__count' }, String(this.count ?? total)),
335
+ h('span', { class: 'dt-bar__tools' }, slotted(this.content, 'toolbar')),
336
+ h('span', { class: 'dt-bar__grow' }),
337
+ h('span', { class: 'dt-bar__tools-end' }, slotted(this.content, 'toolbar-end')),
338
+ ]),
339
+ h('div', { class: 'dt-scroll' }, [
340
+ tableShowsOverlay({ loading: this.loading, hasData: value.length > 0 }) && h('div', { class: 'dt-loading' }, icon(registry, 'loader', { size: 22, spin: true })),
341
+ h('table', {
342
+ class: this.tableClass ? 'tbl ' + this.tableClass : 'tbl', role: ta.role, 'aria-rowcount': ta['aria-rowcount'], 'aria-busy': ta['aria-busy'],
343
+ 'aria-multiselectable': ta['aria-multiselectable'],
344
+ }, [
345
+ caption.length > 0 && h('caption', {}, caption),
346
+ h('colgroup', {}, [
347
+ hasSel && h('col', { style: { width: '36px' } }),
348
+ columns.map((c) => h('col', { style: { width: c.width, minWidth: c.minWidth, maxWidth: c.maxWidth } })),
349
+ ]),
350
+ h('thead', {}, h('tr', { 'aria-rowindex': tableHeaderRowProps(0)['aria-rowindex'] }, [
351
+ hasSel && h('th', { class: 'col-sel', scope: 'col' }, mode === 'multiple' && (this.selectAll ?? true) && check('all', allState === 'all', t('table.selectAll'), toggleAll, allState === 'some')),
352
+ columns.map(header),
353
+ ])),
354
+ h('tbody', {}, bodyRows()),
355
+ ]),
356
+ ]),
357
+ this.paginator && (total > 0 || this.lazy) && h('div', { class: 'dt-foot' }, paginatorView(i18n, registry, {
358
+ first, rows, totalRecords: total, rowsPerPageOptions: this.rowsPerPageOptions, pageLinks: this.pageLinks, showCurrentPageReport: this.showCurrentPageReport,
359
+ currentPageReportTemplate: this.currentPageReportTemplate, showFirstLastIcon: this.showFirstLastIcon, alwaysShow: this.alwaysShowPaginator, onPage: changePage,
360
+ owner: this, selectTag: this.tag('select'),
361
+ })),
362
+ ]));
363
+ }
364
+ }