@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/dist/table.js
CHANGED
|
@@ -15,17 +15,61 @@
|
|
|
15
15
|
* chargement, grille WAI-ARIA dont la ligne a le focus. Tri (`sort`), page (`first`, `rows`) et sélection
|
|
16
16
|
* (`selection`) sont tenus par l'élément, comme la valeur d'un champ natif : un geste les change et émet
|
|
17
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"`.
|
|
19
|
-
*
|
|
20
|
-
* `
|
|
18
|
+
* page placé par `slot="toolbar"`, `"toolbar-end"`, `"selection-bar"`, `"empty"`, `"caption"`.
|
|
19
|
+
*
|
|
20
|
+
* Tranche 2 : recherche globale (`show-search`, `globalFilter`, `globalFilterFields`, sans accents ni casse dans la
|
|
21
|
+
* langue de l'élément), filtres de colonne (`filterable`, `filterType`, `filterOptions`, 19 modes) dans la ligne de
|
|
22
|
+
* filtres à opérateurs (`show-filter-row`), état `filters` tenu par l'élément (un geste le change et émet
|
|
23
|
+
* `filterchange` ; posé par la page, il est rendu sans évènement), délai (`filter-delay`), rendu de filtre
|
|
24
|
+
* (`renderFilter(ctx)`), pied « N lignes · filtrées · sélectionnées » (`show-row-count`, `renderRowCount`) ; en
|
|
25
|
+
* données serveur, l'état est émis (`filterchange`, `lazyload`) sans filtrer ici. Tranche 3 : groupes de lignes
|
|
26
|
+
* (`groupBy` — attribut `group-by="env"` ou JSON —, `aggregates`, `showGrandTotal`, `groupSort`, `groupLabel`,
|
|
27
|
+
* `hideGroupedColumns`, `expandedGroups` tenus par l'élément, évènement `expandedgroupschange`, rendus
|
|
28
|
+
* `renderGroupHeader` / `renderGroupFooter`), moteur `table.nodes` du socle, table `treegrid` ; table en arbre
|
|
29
|
+
* (`tree-field` ou `parent-key`, `tree-column`, `indent`, `show-tree-lines`, `treeIcon`, `expandedNodeKeys` tenus par
|
|
30
|
+
* l'élément — évènements `nodeexpand` / `nodecollapse` / `expandednodekeyschange` —, `keepAncestors`,
|
|
31
|
+
* `selection-propagation`, enfants paresseux `lazy-children` + `loadChildren` ou `setChildren(clé, lignes)`, clavier
|
|
32
|
+
* ← → `*`, `expandAll` / `collapseAll` / `expandTo`). Panneau latéral :
|
|
33
|
+
* `<poad-table-panel>`. Même DOM, mêmes classes, même ARIA que `poad-table` d'ui-angular. Styles :
|
|
34
|
+
* `@poadio/ui-core/table.css`, `paginator.css`, `checkbox.css`, `icon.css`, `menu.css`, `floating.css`, `select.css`,
|
|
35
|
+
* `option-list.css`.
|
|
21
36
|
*/
|
|
22
|
-
import { TABLE_ROW_CLICK_IGNORE, paginatorClampFirst, tableActiveIndex, tableAllState, tableAriaSort, tableBodyState, tableClearSelection, tableCollator, tableColumnAlign, tableColumnId, tableColumnSortField, tableColspan, tableFormatCell, tableGridKey, tableHeaderCellProps, tableHeaderRowProps, tablePageRows, tableResolve, tableRootClasses, tableRootProps, tableRowClasses, tableRowClickAction, tableRowKey, tableRowProps, tableSelectOnly, tableSelectRange, tableSelectSingle, tableSelectionArray, tableSelectionKeys, tableSelectionValue, tableShowsOverlay, tableSkeletonWidth, tableSortIcon, tableSortIndex, tableSortOrderOf, tableSortState, tableSortToggle, tableTdClasses, tableThClasses, tableToggleAll, tableToggleRow, tableView, } from '@poadio/ui-core';
|
|
37
|
+
import { TABLE_ROW_CLICK_IGNORE, paginatorClampFirst, tableActiveIndex, tableAllState, tableAriaSort, tableBodyState, tableClearSelection, tableCollator, tableColumnAlign, tableColumnId, tableColumnSortField, tableColspan, tableFormatCell, tableGridKey, tableHeaderCellProps, tableHeaderRowProps, tablePageRows, tableResolve, tableRootClasses, tableRootProps, tableRowClasses, tableRowClickAction, tableRowKey, tableRowProps, tableSelectOnly, tableSelectRange, tableSelectSingle, tableSelectionArray, tableSelectionKeys, tableSelectionValue, tableShowsOverlay, tableSkeletonWidth, tableSortIcon, tableSortIndex, tableSortOrderOf, tableSortState, tableSortToggle, tableTdClasses, tableThClasses, tableToggleAll, tableToggleRow, tableView, tableCounts, tableFilterClear, tableFilterDefaultMode, tableFilterDelay, tableFilterKind, tableFilterRangePart, tableFilterSet, tableFilterSetOperator, tableFilterToggleValue, tableGlobalFields, tableRowCountParts, tableRowPredicate, tableCanExpand, tableDetailPaddingLeft, tableExpandAllKeys, tableExpandButtonProps, tableExpandedSet, tableExpandToggle, tableHasExpandColumn, TableNodes, tableGroupFields, tableGroupHeaderProps, tableGroupToggle, tableGroupVisibleColumns, tableHasAggregate, tableHasGroupFooters, tableNodeRowProps, tableNodeTrackKey, tableShowsGrandTotal, tableToggleRows, tableIsTree, tableTreeColumnIndex, tableTreeExpandKeys, tableTreeGuides, tableTreeHasChildrenDefault, tableTreeIsExpanded, tableTreeKey, tableTreeNeedsLoad, tableTreeNodeState, tableTreeRootVars, tableTreeRowClasses, tableTreeToggle, tableTreeToggleProps, tableTreeToggleRow, } from '@poadio/ui-core';
|
|
23
38
|
import { checkboxNode } from './checkbox.js';
|
|
24
39
|
import { h } from './dom.js';
|
|
25
40
|
import { PoadElement } from './element.js';
|
|
26
41
|
import { icon } from './icon.js';
|
|
27
42
|
import { paginatorView } from './paginator.js';
|
|
43
|
+
import { TableFilterRow, tableSearch } from './table-filters.js';
|
|
44
|
+
/**
|
|
45
|
+
* Suivi d'une table par un panneau latéral (`<poad-table-panel>`) : rappelé après chaque rendu de la table. Interne
|
|
46
|
+
* au paquet.
|
|
47
|
+
*/
|
|
48
|
+
export const tableWatchers = new WeakMap();
|
|
28
49
|
const slotted = (content, name) => (content ?? []).filter((n) => n instanceof Element && n.getAttribute('slot') === name);
|
|
50
|
+
/**
|
|
51
|
+
* Table de données.
|
|
52
|
+
* @fires sortchange L'utilisateur change le tri.
|
|
53
|
+
* @fires pagechange L'utilisateur change de page ou de taille de page ; une position imposée n'émet rien.
|
|
54
|
+
* @fires selectionchange L'utilisateur change la sélection ; une sélection imposée n'émet rien.
|
|
55
|
+
* @fires rowselect L'utilisateur choisit une ligne.
|
|
56
|
+
* @fires rowunselect L'utilisateur retire une ligne de la sélection.
|
|
57
|
+
* @fires rowclick Clic sur une ligne.
|
|
58
|
+
* @fires rowdblclick Double-clic sur une ligne.
|
|
59
|
+
* @fires lazyload Données serveur : la table demande les lignes à afficher (au montage, au tri, à la page, au filtre…).
|
|
60
|
+
* @fires rowexpand {PoadTableRowDetail} Le détail d'une ligne est déplié par l'utilisateur.
|
|
61
|
+
* @fires rowcollapse {PoadTableRowDetail} Le détail d'une ligne est replié par l'utilisateur.
|
|
62
|
+
* @fires expandedgroupschange {unknown[] | null} L'utilisateur ouvre ou referme un groupe : les clés des groupes ouverts (`null` : tous).
|
|
63
|
+
* @fires nodeexpand {PoadTableNodeDetail} L'utilisateur déplie un nœud de l'arbre.
|
|
64
|
+
* @fires nodecollapse {PoadTableNodeDetail} L'utilisateur replie un nœud de l'arbre.
|
|
65
|
+
* @fires expandednodekeyschange {unknown[]} L'utilisateur déplie ou replie un nœud : les clés des nœuds dépliés.
|
|
66
|
+
* @fires filterchange {PoadTableFilterDetail} L'utilisateur change un filtre ou la recherche globale (après le délai) : `{ filters, globalFilter }` ; un état posé par la page n'émet rien.
|
|
67
|
+
* @slot toolbar Outils au début de la barre d'outils.
|
|
68
|
+
* @slot toolbar-end Outils à la fin de la barre d'outils.
|
|
69
|
+
* @slot selection-bar Actions de la barre de sélection, affichée quand des lignes sont choisies.
|
|
70
|
+
* @slot empty Contenu du corps vide.
|
|
71
|
+
* @slot caption Légende de la table (`<caption>`).
|
|
72
|
+
*/
|
|
29
73
|
export class PoadTableElement extends PoadElement {
|
|
30
74
|
static props = {
|
|
31
75
|
value: 'json', columns: 'json', dataKey: 'string', sortMode: 'string', sort: 'json', defaultSortOrder: 'number', customSort: 'boolean',
|
|
@@ -35,20 +79,114 @@ export class PoadTableElement extends PoadElement {
|
|
|
35
79
|
loading: 'boolean', loadingRows: 'number', emptyMessage: 'string', emptyHint: 'string', emptyIcon: 'string', dense: 'boolean', striped: 'boolean',
|
|
36
80
|
hoverable: 'boolean', bordered: 'boolean', borderless: 'boolean', stickyHeader: 'boolean', bodyMaxHeight: 'string', tableClass: 'string', showToolbar: 'boolean',
|
|
37
81
|
heading: 'string', count: 'number', showCount: 'boolean',
|
|
82
|
+
showSearch: 'boolean', searchPlaceholder: 'string', globalFilter: 'string', globalFilterFields: 'json', filters: 'json', filterDelay: 'number',
|
|
83
|
+
showFilterRow: 'boolean', showRowCount: 'boolean', rowCountLabel: 'string',
|
|
84
|
+
rowExpandable: 'boolean', expandedRowKeys: 'json', expandMode: 'string',
|
|
85
|
+
groupBy: 'json', aggregates: 'json', showGrandTotal: 'boolean', grandTotalLabel: 'string', groupSort: 'json', hideGroupedColumns: 'boolean', expandedGroups: 'json',
|
|
86
|
+
treeField: 'string', parentKey: 'string', treeColumn: 'string', indent: 'string', showTreeLines: 'boolean', expandedNodeKeys: 'json', keepAncestors: 'boolean',
|
|
87
|
+
selectionPropagation: 'string', lazyChildren: 'boolean',
|
|
38
88
|
};
|
|
39
|
-
static functions = ['renderCell', 'renderHeader', 'cellFormatter', 'rowSelectable', 'rowClass'];
|
|
89
|
+
static functions = ['renderCell', 'renderHeader', 'cellFormatter', 'rowSelectable', 'rowClass', 'renderFilter', 'renderRowCount', 'renderExpansion', 'groupLabel', 'renderGroupHeader', 'renderGroupFooter', 'treeIcon', 'hasChildren', 'loadChildren'];
|
|
90
|
+
/** Déplie tous les nœuds de l'arbre. */
|
|
91
|
+
expandAllNodes() {
|
|
92
|
+
this.expandedNodeKeys = this.treeNodes()?.expandableKeys(Infinity, ['row']) ?? [];
|
|
93
|
+
}
|
|
94
|
+
/** Déplie les nœuds jusqu'au niveau donné inclus (0 = racines). */
|
|
95
|
+
expandTo(level) {
|
|
96
|
+
this.expandedNodeKeys = this.treeNodes()?.expandableKeys(level, ['row']) ?? [];
|
|
97
|
+
}
|
|
98
|
+
/** Fournit les enfants chargés d'un nœud (`lazy-children` sans `loadChildren`) et le déplie. */
|
|
99
|
+
setChildren(key, rows) {
|
|
100
|
+
this.lazyKids = new Map(this.lazyKids).set(key, [...rows]);
|
|
101
|
+
const loading = new Set(this.loadingKeys);
|
|
102
|
+
loading.delete(key);
|
|
103
|
+
this.loadingKeys = loading;
|
|
104
|
+
const keys = this.expandedNodeKeys ?? [];
|
|
105
|
+
if (!keys.includes(key))
|
|
106
|
+
this.propValues['expandedNodeKeys'] = [...keys, key];
|
|
107
|
+
this.update();
|
|
108
|
+
}
|
|
109
|
+
/** Oublie les enfants chargés d'un nœud, ou de tous sans `key`, pour qu'ils soient redemandés. */
|
|
110
|
+
resetChildren(key) {
|
|
111
|
+
if (key === undefined)
|
|
112
|
+
this.lazyKids = new Map();
|
|
113
|
+
else {
|
|
114
|
+
const m = new Map(this.lazyKids);
|
|
115
|
+
m.delete(key);
|
|
116
|
+
this.lazyKids = m;
|
|
117
|
+
}
|
|
118
|
+
this.update();
|
|
119
|
+
}
|
|
120
|
+
lazyKids = new Map();
|
|
121
|
+
loadingKeys = new Set();
|
|
122
|
+
treeNodes() {
|
|
123
|
+
if (!tableIsTree(this))
|
|
124
|
+
return null;
|
|
125
|
+
const i18n = this.i18n();
|
|
126
|
+
return this.nodes(i18n.locale, this.columns ?? [], i18n.t('table.emptyGroup'));
|
|
127
|
+
}
|
|
128
|
+
/** Ouvre tous les groupes. */
|
|
129
|
+
expandAllGroups() {
|
|
130
|
+
this.expandedGroups = null;
|
|
131
|
+
}
|
|
132
|
+
/** Referme tous les groupes. */
|
|
133
|
+
collapseAllGroups() {
|
|
134
|
+
this.expandedGroups = [];
|
|
135
|
+
}
|
|
136
|
+
/** Déplie le détail de toutes les lignes dépliables (filtrées et triées ; en `single`, la première) ; en arbre, tous les nœuds. */
|
|
137
|
+
expandAll() {
|
|
138
|
+
if (tableIsTree(this)) {
|
|
139
|
+
this.expandAllNodes();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const keys = tableExpandAllKeys(this.sorted(this.i18n().locale, this.columns ?? []), { expandable: this.rowExpandable, keyOf: this.keyOf, mode: this.expandMode });
|
|
143
|
+
this.expandedRowKeys = keys;
|
|
144
|
+
}
|
|
145
|
+
/** Replie le détail de toutes les lignes ; en arbre, tous les nœuds. */
|
|
146
|
+
collapseAll() {
|
|
147
|
+
if (tableIsTree(this)) {
|
|
148
|
+
this.expandedNodeKeys = [];
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.expandedRowKeys = [];
|
|
152
|
+
}
|
|
40
153
|
activeKey = undefined;
|
|
41
154
|
anchor = null;
|
|
42
155
|
loadedOnce = false;
|
|
43
156
|
/** 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). */
|
|
44
157
|
memo = null;
|
|
158
|
+
/** Filtre mémorisé : rien ne se refiltre si ni les lignes, ni les filtres, ni la recherche, ni la langue ne changent. */
|
|
159
|
+
nodesMemo = null;
|
|
160
|
+
filterMemo = null;
|
|
161
|
+
searchText = null;
|
|
162
|
+
timers = new Map();
|
|
163
|
+
filterRowState = null;
|
|
164
|
+
get filterRow() {
|
|
165
|
+
return (this.filterRowState ??= new TableFilterRow(this, this.uid, this.tag('select')));
|
|
166
|
+
}
|
|
45
167
|
get metas() {
|
|
46
168
|
const sort = this.sort ?? [];
|
|
47
169
|
return (this.sortMode ?? 'single') === 'single' ? sort.slice(0, 1) : [...sort];
|
|
48
170
|
}
|
|
49
171
|
keyOf = (r) => tableRowKey(r, this.dataKey);
|
|
50
|
-
|
|
172
|
+
filtered(locale, columns) {
|
|
51
173
|
const value = this.value ?? [];
|
|
174
|
+
if (this.lazy)
|
|
175
|
+
return value;
|
|
176
|
+
const filters = this.filters ?? {};
|
|
177
|
+
const globalFilter = this.globalFilter ?? '';
|
|
178
|
+
const fields = tableGlobalFields(this.globalFilterFields, columns);
|
|
179
|
+
const key = JSON.stringify([filters, globalFilter, fields, locale]);
|
|
180
|
+
const m = this.filterMemo;
|
|
181
|
+
if (m && m.value === value && m.key === key)
|
|
182
|
+
return m.filtered;
|
|
183
|
+
const predicate = tableRowPredicate({ globalFilter, globalFields: fields, filters, locale, collator: tableCollator(locale) });
|
|
184
|
+
const filtered = tableView(value, { filter: predicate, metas: [] }).filtered;
|
|
185
|
+
this.filterMemo = { value, key, filtered };
|
|
186
|
+
return filtered;
|
|
187
|
+
}
|
|
188
|
+
sorted(locale, columns) {
|
|
189
|
+
const value = this.filtered(locale, columns);
|
|
52
190
|
const metas = this.metas;
|
|
53
191
|
const key = JSON.stringify(metas), flags = `${!!this.lazy}${!!this.customSort}`;
|
|
54
192
|
const m = this.memo;
|
|
@@ -58,14 +196,48 @@ export class PoadTableElement extends PoadElement {
|
|
|
58
196
|
this.memo = { value, sort: key, locale, flags, sorted };
|
|
59
197
|
return sorted;
|
|
60
198
|
}
|
|
199
|
+
/** Moteur de nœuds (mode groupé), mémorisé tant que les lignes et les options ne changent pas. */
|
|
200
|
+
nodes(locale, columns, emptyLabel) {
|
|
201
|
+
const groupBy = this.groupBy && !(Array.isArray(this.groupBy) && !this.groupBy.length) ? this.groupBy : null;
|
|
202
|
+
const tree = tableIsTree(this);
|
|
203
|
+
if (!groupBy && !tree)
|
|
204
|
+
return null;
|
|
205
|
+
const value = this.value ?? [];
|
|
206
|
+
const filters = this.filters ?? {};
|
|
207
|
+
const globalFilter = this.globalFilter ?? '';
|
|
208
|
+
const fields = tableGlobalFields(this.globalFilterFields, columns);
|
|
209
|
+
const metas = this.lazy || this.customSort ? [] : this.metas;
|
|
210
|
+
const key = JSON.stringify([filters, globalFilter, fields, locale, metas, emptyLabel, this.dataKey ?? null, !!this.lazy]);
|
|
211
|
+
const opts = [groupBy, this.aggregates, this.groupSort, this.groupLabel, this.treeField, this.parentKey, this.keepAncestors, this.lazyChildren, this.hasChildren, this.lazyKids, this.loadingKeys];
|
|
212
|
+
const m = this.nodesMemo;
|
|
213
|
+
if (m && m.value === value && m.key === key && m.opts.every((o, i) => o === opts[i]))
|
|
214
|
+
return m.nodes;
|
|
215
|
+
const filter = this.lazy ? null : tableRowPredicate({ globalFilter, globalFields: fields, filters, locale, collator: tableCollator(locale) });
|
|
216
|
+
const nodes = new TableNodes(value, {
|
|
217
|
+
dataKey: this.dataKey, groupBy, aggregates: this.aggregates, groupSort: this.groupSort ?? 1, groupLabel: this.groupLabel, emptyGroupLabel: emptyLabel,
|
|
218
|
+
collator: tableCollator(locale), sortMetas: metas, filter,
|
|
219
|
+
treeField: this.treeField || null, parentKey: this.parentKey || null, keepAncestors: this.keepAncestors !== false,
|
|
220
|
+
lazyChildren: this.lazyChildren ? this.lazyKids : null, hasChildren: this.lazyChildren ? (this.hasChildren ?? tableTreeHasChildrenDefault) : null, loadingKeys: this.loadingKeys,
|
|
221
|
+
});
|
|
222
|
+
this.nodesMemo = { value, key, opts, nodes };
|
|
223
|
+
return nodes;
|
|
224
|
+
}
|
|
61
225
|
lazyDetail(first, rows, metas) {
|
|
62
226
|
const s = tableSortState(metas);
|
|
63
|
-
return { first, rows, sortField: s.field, sortOrder: s.order, multiSortMeta: s.multiSortMeta };
|
|
227
|
+
return { first, rows, sortField: s.field, sortOrder: s.order, multiSortMeta: s.multiSortMeta, filters: this.filters ?? {}, globalFilter: this.globalFilter ?? '' };
|
|
64
228
|
}
|
|
65
229
|
tbody() {
|
|
66
230
|
return this.querySelector(':scope > .poad-table > .dt > .dt-scroll > table > tbody');
|
|
67
231
|
}
|
|
232
|
+
disconnectedCallback() {
|
|
233
|
+
super.disconnectedCallback();
|
|
234
|
+
this.timers.forEach(clearTimeout);
|
|
235
|
+
this.timers.clear();
|
|
236
|
+
this.filterRowState?.dispose();
|
|
237
|
+
}
|
|
68
238
|
updated() {
|
|
239
|
+
this.filterRowState?.sync();
|
|
240
|
+
tableWatchers.get(this)?.forEach((fn) => fn());
|
|
69
241
|
if (!this.loadedOnce) {
|
|
70
242
|
this.loadedOnce = true;
|
|
71
243
|
if (this.lazy && this.lazyLoadOnInit !== false)
|
|
@@ -81,22 +253,33 @@ export class PoadTableElement extends PoadElement {
|
|
|
81
253
|
const sortMode = this.sortMode ?? 'single';
|
|
82
254
|
const metas = this.metas;
|
|
83
255
|
const rows = this.rows ?? 25;
|
|
84
|
-
const
|
|
256
|
+
const allColumns = this.columns ?? [];
|
|
257
|
+
// groupes : le moteur de nœuds du socle filtre, trie par fratrie et pagine sur les groupes racines
|
|
258
|
+
const grouped = this.nodes(locale, allColumns, t('table.emptyGroup'));
|
|
259
|
+
const sorted = grouped ? grouped.allRows() : this.sorted(locale, allColumns);
|
|
85
260
|
const total = this.lazy ? (this.totalRecords ?? value.length) : sorted.length;
|
|
261
|
+
const pageTotal = grouped && !this.lazy ? grouped.rootCount : total;
|
|
86
262
|
// retour sur la dernière page quand `first` dépasse (filtre, suppression) : corrigé sans évènement, comme React
|
|
87
|
-
const back = !this.lazy && this.paginator ? paginatorClampFirst(this.first ?? 0,
|
|
263
|
+
const back = !this.lazy && this.paginator ? paginatorClampFirst(this.first ?? 0, pageTotal, rows) : null;
|
|
88
264
|
if (back !== null)
|
|
89
265
|
this.propValues['first'] = back;
|
|
90
266
|
const first = this.first ?? 0;
|
|
91
|
-
const
|
|
92
|
-
const
|
|
267
|
+
const expandedGroups = this.expandedGroups;
|
|
268
|
+
const isTree = tableIsTree(this);
|
|
269
|
+
const nodeKeys = this.expandedNodeKeys ?? [];
|
|
270
|
+
const shown = grouped ? grouped.visible(new Set(nodeKeys), {
|
|
271
|
+
expandedGroups: expandedGroups == null ? null : new Set(expandedGroups), withGroupFooters: tableHasGroupFooters({ hasTemplate: !!this.renderGroupFooter, aggregates: this.aggregates }),
|
|
272
|
+
first: this.paginator && !this.lazy ? first : 0, rows: this.paginator && !this.lazy ? rows : 0,
|
|
273
|
+
}) : null;
|
|
274
|
+
const page = shown ? shown.filter((n) => n.kind === 'row').map((n) => n.row) : this.paginator && !this.lazy ? tablePageRows(sorted, first, rows) : sorted;
|
|
275
|
+
const columns = tableGroupVisibleColumns(allColumns.filter((c) => !c.hidden), tableGroupFields(this.groupBy), this.hideGroupedColumns ?? true);
|
|
93
276
|
const keyOf = this.keyOf;
|
|
94
277
|
const selected = tableSelectionArray(this.selection);
|
|
95
278
|
const selectedKeys = tableSelectionKeys(this.selection, keyOf);
|
|
96
279
|
const canSelect = (r) => this.rowSelectable?.(r) ?? true;
|
|
97
280
|
const scope = (this.selectAllScope === 'all' ? sorted : page).filter(canSelect);
|
|
98
281
|
const allState = tableAllState(scope, selectedKeys, keyOf);
|
|
99
|
-
const body = tableBodyState({ loading: this.loading, hasData: value.length > 0, rowCount: page.length });
|
|
282
|
+
const body = tableBodyState({ loading: this.loading, hasData: value.length > 0, rowCount: shown ? shown.length : page.length });
|
|
100
283
|
const trackOf = (r, i) => (this.dataKey ? keyOf(r) : i);
|
|
101
284
|
const activeAt = tableActiveIndex(Math.max(0, page.findIndex((r, i) => trackOf(r, i) === this.activeKey)), page.length);
|
|
102
285
|
const hasSel = !!mode;
|
|
@@ -123,6 +306,59 @@ export class PoadTableElement extends PoadElement {
|
|
|
123
306
|
if (scroller)
|
|
124
307
|
scroller.scrollTop = 0;
|
|
125
308
|
};
|
|
309
|
+
// ---- filtres (réducteur du socle ; minuteries ici) ----
|
|
310
|
+
/** Lance `fn` tout de suite, ou après `filterDelay` depuis la dernière frappe (une minuterie par champ). */
|
|
311
|
+
const debounce = (key, fn, immediate = false) => {
|
|
312
|
+
const prev = this.timers.get(key);
|
|
313
|
+
if (prev)
|
|
314
|
+
clearTimeout(prev);
|
|
315
|
+
this.timers.delete(key);
|
|
316
|
+
const d = tableFilterDelay(immediate ? 0 : (this.filterDelay ?? 250));
|
|
317
|
+
if (d === 'now')
|
|
318
|
+
fn();
|
|
319
|
+
else
|
|
320
|
+
this.timers.set(key, setTimeout(() => { this.timers.delete(key); fn(); }, d));
|
|
321
|
+
};
|
|
322
|
+
// l'état est relu à l'application (une minuterie s'écoule après d'autres rendus)
|
|
323
|
+
const emitFilters = () => {
|
|
324
|
+
this.propValues['first'] = 0;
|
|
325
|
+
const detail = { filters: this.filters ?? {}, globalFilter: this.globalFilter ?? '' };
|
|
326
|
+
this.update();
|
|
327
|
+
this.emit('filterchange', detail);
|
|
328
|
+
if (this.lazy)
|
|
329
|
+
this.emit('lazyload', this.lazyDetail(0, this.rows ?? 25, this.metas));
|
|
330
|
+
};
|
|
331
|
+
const applyFilters = (next) => { this.propValues['filters'] = next; emitFilters(); };
|
|
332
|
+
const cur = () => this.filters ?? {};
|
|
333
|
+
const onSearch = (text, immediate = false) => {
|
|
334
|
+
const was = this.searchText ?? this.globalFilter ?? '';
|
|
335
|
+
this.searchText = text;
|
|
336
|
+
// le bouton d'effacement suit la frappe : redessiner quand le champ passe de vide à rempli, ou l'inverse
|
|
337
|
+
if (immediate || !was !== !text)
|
|
338
|
+
this.update();
|
|
339
|
+
debounce('\u0000global', () => { this.searchText = null; this.propValues['globalFilter'] = text; emitFilters(); }, immediate);
|
|
340
|
+
};
|
|
341
|
+
const filterOf = (c) => ({ defaultMode: tableFilterDefaultMode(c), kind: tableFilterKind(c), locale });
|
|
342
|
+
const actions = {
|
|
343
|
+
set: (c, v, m, delayed) => debounce(c.field ?? '', () => applyFilters(tableFilterSet(cur(), c.field ?? '', v, { ...filterOf(c), matchMode: m })), !delayed),
|
|
344
|
+
part: (c, i, raw) => {
|
|
345
|
+
const next = tableFilterRangePart(cur()[c.field ?? '']?.value ?? null, i, raw, { numeric: c.filterType === 'number' || c.dataType === 'number', locale });
|
|
346
|
+
debounce(c.field ?? '', () => applyFilters(tableFilterSet(cur(), c.field ?? '', next, { ...filterOf(c), matchMode: 'between' })));
|
|
347
|
+
},
|
|
348
|
+
operator: (c, op) => {
|
|
349
|
+
const r = tableFilterSetOperator(cur(), c.field ?? '', op, { kind: tableFilterKind(c), locale });
|
|
350
|
+
if (r.apply)
|
|
351
|
+
applyFilters(r.filters);
|
|
352
|
+
else
|
|
353
|
+
this.filters = r.filters;
|
|
354
|
+
},
|
|
355
|
+
toggleValue: (c, v) => applyFilters(tableFilterToggleValue(cur(), c.field ?? '', v, { matchMode: cur()[c.field ?? '']?.matchMode ?? tableFilterDefaultMode(c) })),
|
|
356
|
+
clear: (c) => applyFilters(tableFilterClear(cur(), c.field ?? '')),
|
|
357
|
+
};
|
|
358
|
+
const filters = cur();
|
|
359
|
+
const hasFilterRow = this.showFilterRow ?? columns.some((c) => c.filterable);
|
|
360
|
+
if (hasFilterRow)
|
|
361
|
+
this.filterRow.begin(filters);
|
|
126
362
|
// ---- sélection ----
|
|
127
363
|
const apply = (ch, index) => {
|
|
128
364
|
if (!ch)
|
|
@@ -132,8 +368,58 @@ export class PoadTableElement extends PoadElement {
|
|
|
132
368
|
ch.added.forEach((row) => this.emit('rowselect', { row, index: index ?? -1 }));
|
|
133
369
|
ch.removed.forEach((row) => this.emit('rowunselect', { row, index: index ?? -1 }));
|
|
134
370
|
};
|
|
135
|
-
const
|
|
136
|
-
|
|
371
|
+
const propagation = this.selectionPropagation ?? 'both';
|
|
372
|
+
const toggleRow = (row, i) => {
|
|
373
|
+
if (!canSelect(row))
|
|
374
|
+
return;
|
|
375
|
+
this.anchor = i;
|
|
376
|
+
apply(grouped && isTree ? tableTreeToggleRow(selected, row, { nodes: grouped, propagation, keyOf, canSelect }) : tableToggleRow(selected, row, keyOf), i);
|
|
377
|
+
};
|
|
378
|
+
// ---- arbre ----
|
|
379
|
+
const nodeDetail = (n) => ({ row: n.row, key: n.key, level: n.level, node: n });
|
|
380
|
+
const setNodeKeys = (next) => { this.propValues['expandedNodeKeys'] = next; this.emit('expandednodekeyschange', next); };
|
|
381
|
+
/** Demande les enfants d'un nœud qu'on déplie (`lazy-children` avec `loadChildren`), une seule fois. */
|
|
382
|
+
const load = (n) => {
|
|
383
|
+
const loader = this.loadChildren;
|
|
384
|
+
if (!tableTreeNeedsLoad(n, { lazy: !!this.lazyChildren, loaded: this.lazyKids }) || this.loadingKeys.has(n.key))
|
|
385
|
+
return;
|
|
386
|
+
this.loadingKeys = new Set(this.loadingKeys).add(n.key);
|
|
387
|
+
if (!loader)
|
|
388
|
+
return; // la page répond par setChildren
|
|
389
|
+
const done = () => { const x = new Set(this.loadingKeys); x.delete(n.key); this.loadingKeys = x; this.update(); };
|
|
390
|
+
Promise.resolve(loader(n.row, n)).then((kids) => { this.lazyKids = new Map(this.lazyKids).set(n.key, [...kids]); done(); }, done);
|
|
391
|
+
};
|
|
392
|
+
const toggleNode = (n) => {
|
|
393
|
+
if (!n.hasChildren || !grouped)
|
|
394
|
+
return;
|
|
395
|
+
const r = tableTreeToggle(grouped, this.expandedNodeKeys ?? [], n.key);
|
|
396
|
+
if (r.expanded)
|
|
397
|
+
load(n);
|
|
398
|
+
setNodeKeys(r.next);
|
|
399
|
+
this.update();
|
|
400
|
+
this.emit(r.expanded ? 'nodeexpand' : 'nodecollapse', nodeDetail(n));
|
|
401
|
+
};
|
|
402
|
+
/** Déplie plusieurs nœuds (`*`) : un évènement et un chargement par nœud qui s'ouvre. */
|
|
403
|
+
const expandMany = (keys) => {
|
|
404
|
+
const cur = this.expandedNodeKeys ?? [];
|
|
405
|
+
const fresh = keys.filter((k) => !tableTreeIsExpanded(grouped, cur, k));
|
|
406
|
+
if (!fresh.length)
|
|
407
|
+
return;
|
|
408
|
+
const opened = fresh.map((k) => grouped.get(k)).filter((n) => !!n);
|
|
409
|
+
opened.forEach(load);
|
|
410
|
+
setNodeKeys(tableTreeExpandKeys(cur, fresh));
|
|
411
|
+
this.update();
|
|
412
|
+
opened.forEach((n) => this.emit('nodeexpand', nodeDetail(n)));
|
|
413
|
+
};
|
|
414
|
+
/** Donne le focus à la ligne d'un nœud (clavier de l'arbre). */
|
|
415
|
+
const focusKey = (key) => {
|
|
416
|
+
const at = page.findIndex((r) => keyOf(r) === key);
|
|
417
|
+
if (at < 0)
|
|
418
|
+
return;
|
|
419
|
+
this.activeKey = trackOf(page[at], at);
|
|
420
|
+
this.update();
|
|
421
|
+
this.tbody()?.querySelectorAll(':scope > tr.dt-row')[at]?.focus();
|
|
422
|
+
};
|
|
137
423
|
const selectSingle = (row, i) => { if (!canSelect(row))
|
|
138
424
|
return; this.anchor = i; apply(tableSelectSingle(selected, row, keyOf), i); };
|
|
139
425
|
const selectRange = (from, to) => apply(tableSelectRange(selected, page, from, to, keyOf, canSelect), to);
|
|
@@ -156,10 +442,26 @@ export class PoadTableElement extends PoadElement {
|
|
|
156
442
|
toggleRow(row, i);
|
|
157
443
|
this.update(); // ligne active (focus itinérant), même sans changement de sélection
|
|
158
444
|
};
|
|
159
|
-
const onRowKeydown = (i, e) => {
|
|
445
|
+
const onRowKeydown = (i, e, node) => {
|
|
160
446
|
if (e.target !== e.currentTarget && e.target.closest('input, select, textarea, button, a'))
|
|
161
447
|
return;
|
|
162
|
-
const
|
|
448
|
+
const te = grouped && node && isTree ? tableTreeKey(e.key, node, grouped) : null;
|
|
449
|
+
if (te) {
|
|
450
|
+
e.preventDefault();
|
|
451
|
+
this.activeKey = trackOf(page[i], i);
|
|
452
|
+
const target = te.expand ?? te.collapse;
|
|
453
|
+
if (target !== undefined) {
|
|
454
|
+
const n = grouped.get(target);
|
|
455
|
+
if (n)
|
|
456
|
+
toggleNode(n);
|
|
457
|
+
}
|
|
458
|
+
else if (te.focus !== undefined)
|
|
459
|
+
focusKey(te.focus);
|
|
460
|
+
else if (te.expandKeys)
|
|
461
|
+
expandMany(te.expandKeys);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const eff = tableGridKey(e, { index: i, count: page.length, mode, selectAll: this.selectAll, navigation: !!grouped });
|
|
163
465
|
if (!eff)
|
|
164
466
|
return;
|
|
165
467
|
e.preventDefault();
|
|
@@ -184,9 +486,47 @@ export class PoadTableElement extends PoadElement {
|
|
|
184
486
|
// ---- rendu ----
|
|
185
487
|
const format = (v, c, row) => this.cellFormatter ? this.cellFormatter(v, c, row) : tableFormatCell(v, c.dataType, { locale, booleanText: (b) => t(b ? 'common.yes' : 'common.no') });
|
|
186
488
|
const selCount = selectedKeys.size;
|
|
187
|
-
const
|
|
188
|
-
const
|
|
489
|
+
const headerRows = hasFilterRow ? 2 : 1;
|
|
490
|
+
const ta = tableRootProps({ mode, hierarchical: !!grouped, busy: this.loading, rowCount: total, headerRows });
|
|
491
|
+
const counts = tableCounts({ total: this.lazy ? total : value.length, filtered: total, selected: selCount });
|
|
492
|
+
// ---- ligne de détail ----
|
|
493
|
+
const hasExp = tableHasExpandColumn({ hasTemplate: !!this.renderExpansion, rowExpandable: this.rowExpandable });
|
|
494
|
+
const expandedSet = tableExpandedSet(this.expandedRowKeys);
|
|
495
|
+
const toggleExpand = (row, i) => {
|
|
496
|
+
const r = tableExpandToggle(this.expandedRowKeys, keyOf(row), this.expandMode ?? 'multiple');
|
|
497
|
+
this.expandedRowKeys = r.next;
|
|
498
|
+
this.emit(r.expanded ? 'rowexpand' : 'rowcollapse', { row, index: i });
|
|
499
|
+
};
|
|
500
|
+
const colspan = tableColspan({ columns: columns.length, selection: hasSel, extra: hasExp ? 1 : 0 });
|
|
189
501
|
const check = (id, checked, label, onToggle, indeterminate) => checkboxNode(registry, { id: `${this.uid}-${id}`, checked, indeterminate, ariaLabel: label, onToggle });
|
|
502
|
+
// ---- groupes ----
|
|
503
|
+
const toggleGroup = (key) => {
|
|
504
|
+
const next = tableGroupToggle(this.expandedGroups ?? null, key, grouped?.expandableKeys(Infinity, ['group']) ?? []).next;
|
|
505
|
+
this.expandedGroups = next;
|
|
506
|
+
this.emit('expandedgroupschange', next);
|
|
507
|
+
};
|
|
508
|
+
const isSel = (r) => selectedKeys.has(keyOf(r));
|
|
509
|
+
const groupCtx = (n) => ({ ...n.group, level: n.level, expanded: n.expanded });
|
|
510
|
+
const grand = !!grouped && tableShowsGrandTotal({ showGrandTotal: this.showGrandTotal, aggregates: this.aggregates, hierarchical: true });
|
|
511
|
+
/** Cellules d'agrégats (pied de groupe, total général) : libellé dans la première colonne sans agrégat. */
|
|
512
|
+
const aggregateCells = (values, label) => [
|
|
513
|
+
hasSel && h('td', { class: 'col-sel' }),
|
|
514
|
+
hasExp && h('td', { class: 'col-exp' }),
|
|
515
|
+
columns.map((c, ci) => h('td', { class: tableTdClasses(c), 'data-l': c.header }, tableHasAggregate(c.field, this.aggregates) ? format(values[c.field], c, undefined) : ci === 0 ? label : null)),
|
|
516
|
+
];
|
|
517
|
+
const groupRow = (n, gi) => {
|
|
518
|
+
const gp = tableGroupHeaderProps(n);
|
|
519
|
+
const st = hasSel && mode === 'multiple' ? grouped.selectionState(n.key, isSel, canSelect) : 'off';
|
|
520
|
+
const custom = this.renderGroupHeader?.(groupCtx(n));
|
|
521
|
+
return h('tr', { class: ['dt-group', { 'is-expanded': n.expanded }], style: { '--_lvl': String(n.level) }, role: 'row', ...gp.row, 'aria-expanded': gp.row['aria-expanded'] ?? undefined }, h('td', { colspan, class: 'dt-group__cell' }, h('div', { class: 'dt-group__inner' }, [
|
|
522
|
+
hasSel && mode === 'multiple' && check(`g${gi}`, st === 'on', t(gp.checkboxLabelKey, { label: n.group.label }), () => apply(tableToggleRows(selected, grouped.rowsUnder(n.key).filter(canSelect), st !== 'on', keyOf), null), st === 'some'),
|
|
523
|
+
h('button', { type: 'button', class: 'exp', 'aria-expanded': gp.button['aria-expanded'], 'aria-label': t(gp.button.labelKey), onclick: () => toggleGroup(n.key) }, icon(registry, 'chevron-right', { size: 13 })),
|
|
524
|
+
custom != null ? custom : [h('span', { class: 'dt-group__label' }, n.group.label), h('span', { class: 'dt-group__count' }, String(n.group.count))],
|
|
525
|
+
])));
|
|
526
|
+
};
|
|
527
|
+
const groupFoot = (n) => h('tr', { class: 'dt-group-foot', style: { '--_lvl': String(n.level) } }, this.renderGroupFooter
|
|
528
|
+
? h('td', { colspan }, this.renderGroupFooter(groupCtx(n)) ?? null)
|
|
529
|
+
: aggregateCells(n.group.aggregates, h('span', { class: 'dt-group-foot__label' }, t('table.total', { label: n.group.label }))));
|
|
190
530
|
const header = (c) => {
|
|
191
531
|
const field = tableColumnSortField(c);
|
|
192
532
|
const order = tableSortOrderOf(metas, field);
|
|
@@ -201,16 +541,36 @@ export class PoadTableElement extends PoadElement {
|
|
|
201
541
|
])
|
|
202
542
|
: h('span', { class: 'hd' }, h('span', { class: 'hd-txt' }, c.header ?? '')));
|
|
203
543
|
};
|
|
204
|
-
const
|
|
544
|
+
const treeCol = grouped ? tableTreeColumnIndex(columns, this.treeColumn) : -1;
|
|
545
|
+
/** Bascule d'un nœud dans la cellule de l'arbre : repères d'indentation, bouton (ou indicateur de chargement), icône. */
|
|
546
|
+
const treeToggle = (node) => {
|
|
547
|
+
const tp = tableTreeToggleProps(node);
|
|
548
|
+
const ic = this.treeIcon?.(node.row, node);
|
|
549
|
+
return h('span', { class: 'poad-tree-toggle', style: { '--_lvl': String(node.level) } }, [
|
|
550
|
+
tableTreeGuides(node.level, !!this.showTreeLines).map((g) => h('i', { class: g, 'aria-hidden': 'true' })),
|
|
551
|
+
h('button', {
|
|
552
|
+
type: 'button', class: tp.className, tabindex: tp.tabindex, 'aria-expanded': tp['aria-expanded'] ?? undefined, 'aria-label': t(tp.labelKey),
|
|
553
|
+
onclick: (e) => { e.stopPropagation(); toggleNode(node); },
|
|
554
|
+
}, tp.loading ? icon(registry, 'loader', { size: 12, spin: true }) : icon(registry, 'chevron-right', { size: 13 })),
|
|
555
|
+
ic && h('span', { class: 'ic' }, icon(registry, ic, { size: 14 })),
|
|
556
|
+
]);
|
|
557
|
+
};
|
|
558
|
+
const cell = (row, i, c, ci, node) => {
|
|
205
559
|
const v = c.field ? tableResolve(row, c.field) : undefined;
|
|
206
|
-
const ctx = { row, value: v, rowIndex: i, column: c };
|
|
560
|
+
const ctx = { row, value: v, rowIndex: i, column: c, node };
|
|
207
561
|
const custom = c.cell?.(ctx) ?? this.renderCell?.(ctx);
|
|
208
|
-
|
|
562
|
+
const tree = !!node && ci === treeCol;
|
|
563
|
+
return h('td', { class: tableTdClasses(c) + (tree ? ' dt-tree-cell' : '') + (ci === 0 ? ' dt-first' : ''), 'data-l': c.header }, [
|
|
564
|
+
tree
|
|
565
|
+
? h('span', { class: 'dt-tree-wrap' }, [treeToggle(node), custom != null ? custom : h('span', { class: 'cell-txt' }, format(v, c, row))])
|
|
566
|
+
: custom != null ? custom : h('span', { class: 'cell-txt' }, format(v, c, row)),
|
|
567
|
+
]);
|
|
209
568
|
};
|
|
210
569
|
const bodyRows = () => {
|
|
211
570
|
if (body === 'skeleton') {
|
|
212
571
|
return Array.from({ length: this.loadingRows ?? 5 }, (_, r) => h('tr', { class: 'dt-row is-skeleton', 'aria-hidden': 'true' }, [
|
|
213
572
|
hasSel && h('td', { class: 'col-sel' }),
|
|
573
|
+
hasExp && h('td', { class: 'col-exp' }),
|
|
214
574
|
columns.map((c, ci) => h('td', { class: tableTdClasses(c) }, h('div', { class: 'skel', style: { width: tableSkeletonWidth(r, ci) + '%', marginLeft: tableColumnAlign(c) === 'right' ? 'auto' : undefined } }))),
|
|
215
575
|
]));
|
|
216
576
|
}
|
|
@@ -222,15 +582,27 @@ export class PoadTableElement extends PoadElement {
|
|
|
222
582
|
this.emptyHint && h('span', {}, this.emptyHint),
|
|
223
583
|
])));
|
|
224
584
|
}
|
|
225
|
-
|
|
585
|
+
// lignes du corps : nœuds (groupes, pieds, lignes) en mode groupé ; `i` = place parmi les lignes de données affichées
|
|
586
|
+
let di = -1, gi = -1;
|
|
587
|
+
const display = shown ? shown.map((n) => ({ node: n, row: n.row, i: n.kind === 'row' ? ++di : -1 })) : page.map((row, i) => ({ node: null, row, i }));
|
|
588
|
+
return display.map(({ node, row, i }) => {
|
|
589
|
+
if (node?.kind === 'group')
|
|
590
|
+
return groupRow(node, ++gi);
|
|
591
|
+
if (node?.kind === 'groupFooter')
|
|
592
|
+
return groupFoot(node);
|
|
226
593
|
const sel = selectedKeys.has(keyOf(row));
|
|
227
|
-
const rp = tableRowProps({ position: rowOffset + i, mode, selected: sel, active: i === activeAt });
|
|
594
|
+
const rp = tableRowProps({ position: rowOffset + i, headerRows, mode, selected: sel, active: i === activeAt });
|
|
228
595
|
const track = trackOf(row, i);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
596
|
+
const open = hasExp && expandedSet.has(keyOf(row));
|
|
597
|
+
const eb = tableExpandButtonProps(open);
|
|
598
|
+
const np = node ? tableNodeRowProps(node) : null;
|
|
599
|
+
const st = node && grouped && mode === 'multiple' ? tableTreeNodeState(node, grouped, { isSelected: isSel, canSelect, propagation: isTree ? propagation : 'none' }) : sel ? 'on' : 'off';
|
|
600
|
+
const tr = h('tr', {
|
|
601
|
+
class: tableRowClasses({ selectable: hasSel && canSelect(row), hasSelectionColumn: hasSel, selected: sel, extra: [open ? 'is-expanded' : '', node ? tableTreeRowClasses(node) : '', this.rowClass?.(row, i) ?? ''].filter(Boolean).join(' ') || null }),
|
|
602
|
+
'data-key': this.dataKey ? String(track) : undefined, tabindex: node ? (i === activeAt ? 0 : -1) : rp.tabindex, 'aria-selected': rp['aria-selected'], 'aria-rowindex': node ? undefined : rp['aria-rowindex'],
|
|
603
|
+
style: node ? { '--_lvl': String(node.level) } : undefined, role: np ? 'row' : undefined, 'aria-level': np?.['aria-level'], 'aria-expanded': np?.['aria-expanded'] ?? undefined, 'aria-posinset': np?.['aria-posinset'], 'aria-setsize': np?.['aria-setsize'],
|
|
232
604
|
onclick: (e) => onRowClick(row, i, e), ondblclick: () => this.emit('rowdblclick', { row, index: i }),
|
|
233
|
-
onkeydown: (e) => onRowKeydown(i, e),
|
|
605
|
+
onkeydown: (e) => onRowKeydown(i, e, node),
|
|
234
606
|
// focus itinérant posé sans redessiner : un nouveau rendu remplacerait les nœuds de `renderCell` sous le pointeur
|
|
235
607
|
// (le clic qui suit l'appui n'arriverait pas) ; le prochain rendu trouve les mêmes valeurs
|
|
236
608
|
onfocus: (e) => {
|
|
@@ -241,15 +613,21 @@ export class PoadTableElement extends PoadElement {
|
|
|
241
613
|
tr.setAttribute('tabindex', tr === e.currentTarget ? '0' : '-1'); });
|
|
242
614
|
},
|
|
243
615
|
}, [
|
|
244
|
-
hasSel && h('td', { class: 'col-sel' }, canSelect(row) && check(`r${i}`,
|
|
245
|
-
|
|
616
|
+
hasSel && h('td', { class: 'col-sel' }, canSelect(row) && check(`r${i}`, st === 'on', t('table.selectRow', { index: i + 1 }), () => (mode === 'multiple' ? toggleRow(row, i) : selectSingle(row, i)), st === 'some')),
|
|
617
|
+
hasExp && h('td', { class: 'col-exp' }, tableCanExpand(row, this.rowExpandable) && h('button', {
|
|
618
|
+
type: 'button', class: 'exp', 'aria-expanded': eb['aria-expanded'], 'aria-label': t(eb.labelKey), onclick: () => toggleExpand(row, i),
|
|
619
|
+
}, icon(registry, 'chevron-right', { size: 13 }))),
|
|
620
|
+
columns.map((c, ci) => cell(row, i, c, ci, node)),
|
|
246
621
|
]);
|
|
622
|
+
return open ? [tr, h('tr', { class: 'dt-detail' }, h('td', { colspan }, this.renderExpansion?.({ row, rowIndex: i }) ?? null))] : tr;
|
|
247
623
|
});
|
|
248
624
|
};
|
|
249
625
|
const caption = slotted(this.content, 'caption');
|
|
250
626
|
return h('div', {
|
|
251
|
-
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 })],
|
|
252
|
-
style: this.bodyMaxHeight
|
|
627
|
+
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 }), { 'is-grouped': !!this.groupBy && !(Array.isArray(this.groupBy) && !this.groupBy.length), 'is-tree': isTree, 'has-tree-lines': !!this.showTreeLines }],
|
|
628
|
+
style: this.bodyMaxHeight || hasExp || (isTree && this.indent) ? {
|
|
629
|
+
'--_scroll-h': this.bodyMaxHeight, '--_detail-pl': hasExp ? tableDetailPaddingLeft({ selection: hasSel, expand: true }) : undefined, ...(isTree ? tableTreeRootVars(this.indent) : {}),
|
|
630
|
+
} : undefined,
|
|
253
631
|
}, h('div', { class: 'dt' }, [
|
|
254
632
|
selCount > 0 && (this.showSelectionBar ?? true) ? h('div', { class: 'dt-sel', role: 'region', 'aria-live': 'polite' }, [
|
|
255
633
|
check('bar-all', allState === 'all', t('table.selectAll'), toggleAll, allState === 'some'),
|
|
@@ -262,6 +640,7 @@ export class PoadTableElement extends PoadElement {
|
|
|
262
640
|
(this.showCount ?? true) && h('span', { class: 'dt-bar__count' }, String(this.count ?? total)),
|
|
263
641
|
h('span', { class: 'dt-bar__tools' }, slotted(this.content, 'toolbar')),
|
|
264
642
|
h('span', { class: 'dt-bar__grow' }),
|
|
643
|
+
this.showSearch && tableSearch(i18n, registry, { text: this.searchText ?? this.globalFilter ?? '', placeholder: this.searchPlaceholder, onSearch }),
|
|
265
644
|
h('span', { class: 'dt-bar__tools-end' }, slotted(this.content, 'toolbar-end')),
|
|
266
645
|
]),
|
|
267
646
|
h('div', { class: 'dt-scroll' }, [
|
|
@@ -273,20 +652,34 @@ export class PoadTableElement extends PoadElement {
|
|
|
273
652
|
caption.length > 0 && h('caption', {}, caption),
|
|
274
653
|
h('colgroup', {}, [
|
|
275
654
|
hasSel && h('col', { style: { width: '36px' } }),
|
|
655
|
+
hasExp && h('col', { style: { width: '30px' } }),
|
|
276
656
|
columns.map((c) => h('col', { style: { width: c.width, minWidth: c.minWidth, maxWidth: c.maxWidth } })),
|
|
277
657
|
]),
|
|
278
|
-
h('thead', {},
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
658
|
+
h('thead', {}, [
|
|
659
|
+
h('tr', { 'aria-rowindex': tableHeaderRowProps(0)['aria-rowindex'] }, [
|
|
660
|
+
hasSel && h('th', { class: 'col-sel', scope: 'col' }, mode === 'multiple' && (this.selectAll ?? true) && check('all', allState === 'all', t('table.selectAll'), toggleAll, allState === 'some')),
|
|
661
|
+
hasExp && h('th', { class: 'col-exp', scope: 'col' }, h('span', { hidden: true }, t('table.detail'))),
|
|
662
|
+
columns.map(header),
|
|
663
|
+
]),
|
|
664
|
+
hasFilterRow && h('tr', { class: 'flt', 'aria-rowindex': tableHeaderRowProps(1)['aria-rowindex'] }, [
|
|
665
|
+
hasSel && h('th', {}),
|
|
666
|
+
hasExp && h('th', {}),
|
|
667
|
+
columns.map((c) => h('th', {}, this.filterRow.cell(i18n, registry, filters, c, actions, c.filterCell ?? this.renderFilter))),
|
|
668
|
+
]),
|
|
669
|
+
]),
|
|
282
670
|
h('tbody', {}, bodyRows()),
|
|
671
|
+
grand && h('tfoot', {}, h('tr', { class: 'dt-grand' }, aggregateCells(grouped.grandTotal, text(this.grandTotalLabel, 'table.grandTotal')))),
|
|
283
672
|
]),
|
|
284
673
|
]),
|
|
285
|
-
this.paginator && (total > 0 || this.lazy) && h('div', { class: 'dt-foot' }
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
674
|
+
((this.paginator && (total > 0 || this.lazy)) || this.showRowCount) && h('div', { class: ['dt-foot', { 'has-count': !!this.showRowCount }] }, [
|
|
675
|
+
this.showRowCount && h('span', { class: 'dt-foot__count' }, this.renderRowCount ? this.renderRowCount(counts) : tableRowCountParts(counts, (k, p) => t(k, p), this.rowCountLabel).join(' · ')),
|
|
676
|
+
this.paginator && (total > 0 || this.lazy) && paginatorView(i18n, registry, {
|
|
677
|
+
first, rows, totalRecords: pageTotal, rowsPerPageOptions: this.rowsPerPageOptions, pageLinks: this.pageLinks, showCurrentPageReport: this.showCurrentPageReport,
|
|
678
|
+
currentPageReportTemplate: this.currentPageReportTemplate, showFirstLastIcon: this.showFirstLastIcon, alwaysShow: this.alwaysShowPaginator, onPage: changePage,
|
|
679
|
+
owner: this, selectTag: this.tag('select'),
|
|
680
|
+
}),
|
|
681
|
+
]),
|
|
682
|
+
hasFilterRow && this.filterRow.menus(i18n, registry, filters, actions),
|
|
290
683
|
]));
|
|
291
684
|
}
|
|
292
685
|
}
|