@poadio/ui-elements 0.5.0 → 0.7.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 +58 -0
- package/dist/app-shell.d.ts +34 -0
- package/dist/app-shell.d.ts.map +1 -0
- package/dist/app-shell.js +112 -0
- package/dist/app-shell.js.map +1 -0
- package/dist/bottom-nav.d.ts +79 -0
- package/dist/bottom-nav.d.ts.map +1 -0
- package/dist/bottom-nav.js +86 -0
- package/dist/bottom-nav.js.map +1 -0
- package/dist/breakpoint.d.ts +47 -0
- package/dist/breakpoint.d.ts.map +1 -0
- package/dist/breakpoint.js +74 -0
- package/dist/breakpoint.js.map +1 -0
- package/dist/dataview.d.ts +114 -0
- package/dist/dataview.d.ts.map +1 -0
- package/dist/dataview.js +75 -0
- package/dist/dataview.js.map +1 -0
- package/dist/floating.d.ts +1 -0
- package/dist/floating.d.ts.map +1 -1
- package/dist/floating.js +3 -18
- package/dist/floating.js.map +1 -1
- package/dist/index.d.ts +32 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +262 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +137 -0
- package/dist/layout.js.map +1 -0
- package/dist/menubar.d.ts +96 -0
- package/dist/menubar.d.ts.map +1 -0
- package/dist/menubar.js +326 -0
- package/dist/menubar.js.map +1 -0
- package/dist/nav-drawer.d.ts +141 -0
- package/dist/nav-drawer.d.ts.map +1 -0
- package/dist/nav-drawer.js +204 -0
- package/dist/nav-drawer.js.map +1 -0
- package/dist/table.d.ts +83 -5
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +134 -31
- package/dist/table.js.map +1 -1
- package/package.json +2 -2
- package/src/app-shell.ts +101 -0
- package/src/bottom-nav.ts +126 -0
- package/src/breakpoint.ts +84 -0
- package/src/dataview.ts +143 -0
- package/src/floating.ts +4 -19
- package/src/index.ts +23 -3
- package/src/layout.ts +272 -0
- package/src/menubar.ts +316 -0
- package/src/nav-drawer.ts +256 -0
- package/src/table.ts +170 -32
package/src/app-shell.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-app-shell>
|
|
3
|
+
* <poad-menubar slot="bar" …></poad-menubar> <poad-nav-drawer slot="nav" …></poad-nav-drawer>
|
|
4
|
+
* contenu de la page
|
|
5
|
+
* <poad-bottom-nav slot="bottom" …></poad-bottom-nav>
|
|
6
|
+
* </poad-app-shell>
|
|
7
|
+
*
|
|
8
|
+
* Coquille d'application : barre haute sur toute la largeur, menu dessous à gauche, contenu, barre basse. La coquille ne
|
|
9
|
+
* défile pas (hauteur de la fenêtre, `100dvh`, ou `--poad-shell-height`) : seul le contenu défile, les barres restent en
|
|
10
|
+
* place parce qu'elles ne peuvent pas bouger. Elle mesure ses zones et publie `--poad-shell-top`, `--poad-shell-bottom` et
|
|
11
|
+
* `--poad-shell-nav` (un toast, une feuille, un bouton flottant s'y placent sans rien importer). Elle ne possède pas le
|
|
12
|
+
* menu : sous le seuil mobile (`compact`), elle cesse de lui réserver une colonne, et `openNav()` (appelé par n'importe
|
|
13
|
+
* quel enfant : `el.closest('poad-app-shell').openNav()`) émet `navrequested` — c'est l'application qui ouvre son tiroir.
|
|
14
|
+
*
|
|
15
|
+
* Décisions : module `app-shell` de @poadio/ui-core — même DOM, mêmes classes que `poad-app-shell` d'ui-angular. Le
|
|
16
|
+
* contenu peut changer après coup : un enfant ajouté à la coquille (avec ou sans `slot`) rejoint sa zone, un enfant
|
|
17
|
+
* retiré la quitte. Styles : `app-shell.css`.
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
APP_SHELL_NO_METRICS, BREAKPOINT_SERVER_WIDTH, appShellClasses, appShellCompact, appShellMeasure, appShellMetrics, appShellStyle, breakpointState,
|
|
21
|
+
type AppShellMetrics,
|
|
22
|
+
} from '@poadio/ui-core';
|
|
23
|
+
import { slotted, unslotted } from './card.js';
|
|
24
|
+
import { h, type Child } from './dom.js';
|
|
25
|
+
import { PoadElement } from './element.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Coquille d'application.
|
|
29
|
+
* @slot bar Barre haute, sur toute la largeur (barre de menus…).
|
|
30
|
+
* @slot nav Menu, colonne de gauche (tiroir de navigation).
|
|
31
|
+
* @slot default Le contenu : le seul élément qui défile.
|
|
32
|
+
* @slot bottom Barre basse, sur toute la largeur (barre de navigation basse).
|
|
33
|
+
* @fires navrequested Un enfant a demandé le menu (`openNav()`) : l'application ouvre son tiroir.
|
|
34
|
+
*/
|
|
35
|
+
export class PoadAppShellElement extends PoadElement {
|
|
36
|
+
static override props = { compactAt: 'number' } as const;
|
|
37
|
+
/** Surcharge locale du seuil, en px. Par défaut : le seuil mobile de la bibliothèque (`md`). */
|
|
38
|
+
declare compactAt?: number | null;
|
|
39
|
+
private metrics: AppShellMetrics = APP_SHELL_NO_METRICS;
|
|
40
|
+
private lastCompact: boolean | null = null;
|
|
41
|
+
private stop: (() => void) | null = null;
|
|
42
|
+
|
|
43
|
+
/** Sous le seuil mobile (ou sous `compactAt`). */
|
|
44
|
+
get compact(): boolean {
|
|
45
|
+
return appShellCompact(breakpointState(this.ownerDocument.defaultView?.innerWidth ?? BREAKPOINT_SERVER_WIDTH), this.compactAt ?? null);
|
|
46
|
+
}
|
|
47
|
+
/** Hauteur mesurée de la barre haute, en px. */
|
|
48
|
+
get topHeight(): number { return this.metrics.top; }
|
|
49
|
+
/** Hauteur mesurée de la barre basse, en px. */
|
|
50
|
+
get bottomHeight(): number { return this.metrics.bottom; }
|
|
51
|
+
/** Largeur mesurée du menu, en px. */
|
|
52
|
+
get navWidth(): number { return this.metrics.nav; }
|
|
53
|
+
/** Demande l'ouverture du menu, sans connaître le composant qui le porte : émet `navrequested`. */
|
|
54
|
+
openNav(): void { this.emit('navrequested'); }
|
|
55
|
+
|
|
56
|
+
override connectedCallback(): void {
|
|
57
|
+
super.connectedCallback();
|
|
58
|
+
const win = this.ownerDocument.defaultView;
|
|
59
|
+
if (this.stop || !this.content || !win) return;
|
|
60
|
+
const onResize = () => { if (this.compact !== this.lastCompact) this.update(); };
|
|
61
|
+
win.addEventListener('resize', onResize, { passive: true });
|
|
62
|
+
// Contenu changé par l'application : un enfant ajouté à la coquille rejoint sa zone, un enfant retiré la quitte.
|
|
63
|
+
const mo = new MutationObserver((records) => {
|
|
64
|
+
let changed = false;
|
|
65
|
+
for (const r of records) {
|
|
66
|
+
for (const n of r.removedNodes) if (this.content?.includes(n) && !this.contains(n)) { this.content = this.content.filter((c) => c !== n); changed = true; }
|
|
67
|
+
if (r.target === this) for (const n of r.addedNodes) if (!this.content?.includes(n) && !(n instanceof Element && n.classList.contains('poad-app-shell'))) { this.content = [...(this.content ?? []), n]; changed = true; }
|
|
68
|
+
}
|
|
69
|
+
if (changed) this.update();
|
|
70
|
+
});
|
|
71
|
+
mo.observe(this, { childList: true, subtree: true });
|
|
72
|
+
let ro: ResizeObserver | null = null;
|
|
73
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
74
|
+
ro = new ResizeObserver(() => {
|
|
75
|
+
const zone = (z: 'bar' | 'nav' | 'bottom') => this.querySelector<HTMLElement>(`:scope > .poad-app-shell > .poad-shell__${z}`);
|
|
76
|
+
const m = (z: 'bar' | 'nav' | 'bottom') => { const el = zone(z); return el ? appShellMeasure(z, el.getBoundingClientRect()) : 0; };
|
|
77
|
+
const next = appShellMetrics(this.metrics, { top: m('bar'), bottom: m('bottom'), nav: m('nav') });
|
|
78
|
+
if (next !== this.metrics) { this.metrics = next; this.update(); }
|
|
79
|
+
});
|
|
80
|
+
for (const z of ['bar', 'nav', 'bottom']) { const el = this.querySelector(`:scope > .poad-app-shell > .poad-shell__${z}`); if (el) ro.observe(el); }
|
|
81
|
+
}
|
|
82
|
+
this.stop = () => { win.removeEventListener('resize', onResize); mo.disconnect(); ro?.disconnect(); };
|
|
83
|
+
}
|
|
84
|
+
override disconnectedCallback(): void {
|
|
85
|
+
super.disconnectedCallback();
|
|
86
|
+
this.stop?.();
|
|
87
|
+
this.stop = null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected render(): Child {
|
|
91
|
+
const compact = this.compact;
|
|
92
|
+
this.lastCompact = compact;
|
|
93
|
+
const content = this.content;
|
|
94
|
+
return h('div', { class: ['poad-app-shell', appShellClasses(compact)], style: appShellStyle(this.metrics) }, [
|
|
95
|
+
h('div', { class: 'poad-shell__bar' }, slotted(content, 'bar')),
|
|
96
|
+
h('div', { class: 'poad-shell__nav' }, slotted(content, 'nav')),
|
|
97
|
+
h('div', { class: 'poad-shell__main' }, unslotted(content)),
|
|
98
|
+
h('div', { class: 'poad-shell__bottom' }, slotted(content, 'bottom')),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-bottom-nav value="home" labels="selected" items='[{"value":"home","label":"Home","icon":"home"},…]'></poad-bottom-nav>
|
|
3
|
+
*
|
|
4
|
+
* Barre de navigation basse : trois à cinq destinations à portée de pouce, sur mobile seulement (au-dessus de
|
|
5
|
+
* `breakpoint`, rien n'est rendu, sauf `always-show`). Région `<nav>` nommée par le catalogue (`nav.mainNavigation`) ;
|
|
6
|
+
* la destination courante porte `aria-current="page"` et une pastille pleine en plus de la couleur ; comptes plafonnés
|
|
7
|
+
* à « 99+ » ou simple point ; zone sûre des téléphones à encoche réservée. Décisions : module `bottom-nav` de
|
|
8
|
+
* @poadio/ui-core — même DOM, mêmes classes, même ARIA que `poad-bottom-nav` d'ui-angular. Les destinations à adresse
|
|
9
|
+
* sont des `<a href>` ; `itemclick` est annulable (routeur de l'application). Styles : `bottom-nav.css`, `icon.css`.
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
BOTTOM_NAV_MAX, BREAKPOINT_SERVER_WIDTH, bottomNavBadge, bottomNavIcon, bottomNavItemProps, bottomNavPick, bottomNavShowLabel, bottomNavShown, bottomNavVisible, breakpointOf,
|
|
13
|
+
type BottomNavLabels, type Breakpoint,
|
|
14
|
+
} from '@poadio/ui-core';
|
|
15
|
+
import { h, type Child } from './dom.js';
|
|
16
|
+
import { PoadElement } from './element.js';
|
|
17
|
+
import { icon } from './icon.js';
|
|
18
|
+
|
|
19
|
+
/** Une destination de la barre basse. Pas de sous-niveau : c'est le principe du composant. */
|
|
20
|
+
export interface PoadBottomNavItem {
|
|
21
|
+
/** Identifiant stable, rendu par `change` et comparé à `value`. */
|
|
22
|
+
readonly value: string;
|
|
23
|
+
/** Libellé sous l'icône. */
|
|
24
|
+
readonly label: string;
|
|
25
|
+
/** Icône (nom du jeu d'icônes). */
|
|
26
|
+
readonly icon: string;
|
|
27
|
+
/** Icône affichée quand la destination est active (variante pleine, par exemple). */
|
|
28
|
+
readonly activeIcon?: string;
|
|
29
|
+
/** Adresse : la destination devient un lien `<a href>`. */
|
|
30
|
+
readonly url?: string;
|
|
31
|
+
/** Pastille de comptage. `true` affiche un simple point. */
|
|
32
|
+
readonly badge?: string | number | boolean;
|
|
33
|
+
/** Destination désactivée. */
|
|
34
|
+
readonly disabled?: boolean;
|
|
35
|
+
/** Libellé lu par un lecteur d'écran s'il doit différer du libellé visible. */
|
|
36
|
+
readonly ariaLabel?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Barre de navigation basse.
|
|
41
|
+
* @fires itemclick Une destination est choisie, même déjà courante (pas une destination désactivée) ; `detail` : `{ item, originalEvent }`. Annulable : `preventDefault()` empêche la navigation du lien et le changement de valeur.
|
|
42
|
+
* @fires change La destination courante change ; `detail` : sa valeur.
|
|
43
|
+
*/
|
|
44
|
+
export class PoadBottomNavElement extends PoadElement {
|
|
45
|
+
static override props = { items: 'json', value: 'string', labels: 'string', maxItems: 'number', breakpoint: 'string', alwaysShow: 'boolean', ariaLabel: 'string' } as const;
|
|
46
|
+
/** Les destinations (3 à 5). */
|
|
47
|
+
declare items?: readonly PoadBottomNavItem[];
|
|
48
|
+
/** Destination courante. */
|
|
49
|
+
declare value?: string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Quand afficher le libellé sous l'icône : toujours, sur la destination courante, jamais.
|
|
52
|
+
* @default 'always'
|
|
53
|
+
*/
|
|
54
|
+
declare labels?: BottomNavLabels;
|
|
55
|
+
/**
|
|
56
|
+
* Au-delà, les destinations en trop ne sont pas affichées (prévoir une destination « Plus »).
|
|
57
|
+
* @default 5
|
|
58
|
+
*/
|
|
59
|
+
declare maxItems?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Seuil de la fenêtre au-delà duquel la barre disparaît : elle n'a de sens que sur petit écran.
|
|
62
|
+
* @default 'md'
|
|
63
|
+
*/
|
|
64
|
+
declare breakpoint?: Breakpoint;
|
|
65
|
+
/** Affichée quel que soit le seuil (démonstration). */
|
|
66
|
+
declare alwaysShow?: boolean;
|
|
67
|
+
/** Nom accessible (attribut `aria-label`) ; par défaut le message `nav.mainNavigation` du catalogue. */
|
|
68
|
+
declare ariaLabel: string | null;
|
|
69
|
+
private stopResize: (() => void) | null = null;
|
|
70
|
+
private lastVisible: boolean | null = null;
|
|
71
|
+
|
|
72
|
+
override connectedCallback(): void {
|
|
73
|
+
super.connectedCallback();
|
|
74
|
+
const win = this.ownerDocument.defaultView;
|
|
75
|
+
if (this.stopResize || !this.content || !win) return;
|
|
76
|
+
const onResize = () => { if (this.visible() !== this.lastVisible) this.update(); };
|
|
77
|
+
win.addEventListener('resize', onResize, { passive: true });
|
|
78
|
+
this.stopResize = () => win.removeEventListener('resize', onResize);
|
|
79
|
+
}
|
|
80
|
+
override disconnectedCallback(): void {
|
|
81
|
+
super.disconnectedCallback();
|
|
82
|
+
this.stopResize?.();
|
|
83
|
+
this.stopResize = null;
|
|
84
|
+
}
|
|
85
|
+
private visible(): boolean {
|
|
86
|
+
const bp = breakpointOf(this.ownerDocument.defaultView?.innerWidth ?? BREAKPOINT_SERVER_WIDTH);
|
|
87
|
+
return bottomNavVisible(bp, this.breakpoint || 'md', !!this.alwaysShow);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private pick(it: PoadBottomNavItem, e: MouseEvent): void {
|
|
91
|
+
const action = bottomNavPick(this.value ?? null, it);
|
|
92
|
+
if (action === 'none') { e.preventDefault(); return; }
|
|
93
|
+
const go = this.dispatchEvent(new CustomEvent('itemclick', { detail: { item: it, originalEvent: e }, bubbles: true, composed: true, cancelable: true }));
|
|
94
|
+
if (!go) { e.preventDefault(); return; }
|
|
95
|
+
if (action === 'click') return;
|
|
96
|
+
this.value = it.value;
|
|
97
|
+
this.emit('change', it.value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected render(): Child {
|
|
101
|
+
const visible = this.visible();
|
|
102
|
+
this.lastVisible = visible;
|
|
103
|
+
if (!visible) return null;
|
|
104
|
+
const icons = this.icons();
|
|
105
|
+
const items = Array.isArray(this.items) ? this.items : [];
|
|
106
|
+
return h('nav', { class: 'poad-bottom-nav', 'aria-label': this.ariaLabel || this.i18n().t('nav.mainNavigation') }, h('ul', { class: 'poad-bottom-nav__list', role: 'list' },
|
|
107
|
+
bottomNavShown(items, this.maxItems ?? BOTTOM_NAV_MAX).map((it) => {
|
|
108
|
+
const active = (this.value ?? null) === it.value;
|
|
109
|
+
const a = bottomNavItemProps(it, active);
|
|
110
|
+
const b = bottomNavBadge(it.badge);
|
|
111
|
+
const body: Child[] = [
|
|
112
|
+
h('span', { class: 'poad-bottom-nav__icon' }, [
|
|
113
|
+
h('span', { class: 'poad-bottom-nav__pill', 'aria-hidden': 'true' }),
|
|
114
|
+
icon(icons, bottomNavIcon(it, active), { size: 22 }),
|
|
115
|
+
b.show ? h('span', { class: ['poad-bottom-nav__badge', { 'is-dot': b.dot }] }, b.text) : null,
|
|
116
|
+
]),
|
|
117
|
+
bottomNavShowLabel(this.labels, active) ? h('span', { class: 'poad-bottom-nav__label' }, it.label) : null,
|
|
118
|
+
];
|
|
119
|
+
const common = { 'aria-current': a['aria-current'] ?? undefined, 'aria-label': a['aria-label'] ?? undefined, onclick: (e: MouseEvent) => this.pick(it, e) };
|
|
120
|
+
const el = it.url && !it.disabled
|
|
121
|
+
? h('a', { href: it.url, class: ['poad-bottom-nav__item', { 'is-active': active }], ...common }, body)
|
|
122
|
+
: h('button', { type: 'button', class: ['poad-bottom-nav__item', a.classes], disabled: !!it.disabled, ...common }, body);
|
|
123
|
+
return h('li', {}, el);
|
|
124
|
+
})));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-if when="md+">…contenu…</poad-if> rendu seulement au-dessus de md
|
|
3
|
+
* <poad-if when="mobile"><nav>…</nav><p slot="fallback">…</p></poad-if>
|
|
4
|
+
* const stop = watchBreakpoint((bp) => …); le point de rupture, suivi (script)
|
|
5
|
+
*
|
|
6
|
+
* Points de rupture de la FENÊTRE (xs < 640, sm ≥ 640, md ≥ 768, lg ≥ 1024, xl ≥ 1280, 2xl ≥ 1536), suivis au
|
|
7
|
+
* redimensionnement — l'équivalent du service `PoadBreakpointService` et de la directive `*poadIf` d'ui-angular.
|
|
8
|
+
* Décisions de @poadio/ui-core (`breakpointState`, `breakpointShows`). L'élément ne dessine rien lui-même
|
|
9
|
+
* (`display: contents`, comme tous les hôtes) : son contenu est retiré du document quand l'expression ne correspond pas (pas seulement
|
|
10
|
+
* masqué), puis reposé tel quel (mêmes nœuds, leur état gardé).
|
|
11
|
+
*/
|
|
12
|
+
import { BREAKPOINT_MOBILE, BREAKPOINT_SERVER_WIDTH, BREAKPOINT_TOUCH_QUERY, breakpointShows, breakpointState, type Breakpoint, type BreakpointState } from '@poadio/ui-core';
|
|
13
|
+
import { slotted, unslotted } from './card.js';
|
|
14
|
+
import { PoadElement } from './element.js';
|
|
15
|
+
|
|
16
|
+
/** État de la fenêtre `win` (pointeur grossier compris). */
|
|
17
|
+
function stateOf(win: Window | null, mobile: Breakpoint): BreakpointState {
|
|
18
|
+
const touch = !!win && typeof win.matchMedia === 'function' && win.matchMedia(BREAKPOINT_TOUCH_QUERY).matches;
|
|
19
|
+
return breakpointState(win?.innerWidth ?? BREAKPOINT_SERVER_WIDTH, touch, mobile);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Suit le point de rupture de la fenêtre : `listener` est appelé tout de suite, puis à chaque changement de point de
|
|
24
|
+
* rupture ou de pointeur. Rend la fonction qui arrête le suivi.
|
|
25
|
+
*/
|
|
26
|
+
export function watchBreakpoint(listener: (state: BreakpointState) => void, options: { readonly mobile?: Breakpoint; readonly window?: Window } = {}): () => void {
|
|
27
|
+
const win = options.window ?? (typeof window === 'undefined' ? null : window);
|
|
28
|
+
const mobile = options.mobile ?? BREAKPOINT_MOBILE;
|
|
29
|
+
let last = stateOf(win, mobile);
|
|
30
|
+
listener(last);
|
|
31
|
+
if (!win) return () => {};
|
|
32
|
+
const check = () => {
|
|
33
|
+
const next = stateOf(win, mobile);
|
|
34
|
+
if (next.current === last.current && next.touch === last.touch) return;
|
|
35
|
+
last = next;
|
|
36
|
+
listener(next);
|
|
37
|
+
};
|
|
38
|
+
const mq = typeof win.matchMedia === 'function' ? win.matchMedia(BREAKPOINT_TOUCH_QUERY) : null;
|
|
39
|
+
win.addEventListener('resize', check, { passive: true });
|
|
40
|
+
mq?.addEventListener('change', check);
|
|
41
|
+
return () => { win.removeEventListener('resize', check); mq?.removeEventListener('change', check); };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Contenu rendu selon le point de rupture de la fenêtre.
|
|
46
|
+
* @slot default Contenu rendu quand l'expression correspond.
|
|
47
|
+
* @slot fallback Contenu rendu à la place quand elle ne correspond pas.
|
|
48
|
+
*/
|
|
49
|
+
export class PoadIfElement extends PoadElement {
|
|
50
|
+
static override props = { when: 'string', mobile: 'string' } as const;
|
|
51
|
+
/**
|
|
52
|
+
* Expression de point de rupture : `'md+'` (≥ md), `'sm-'` (≤ sm), `'sm..lg'`, `'xs'`, `'md,xl'`, `'mobile'`,
|
|
53
|
+
* `'desktop'`, `'touch'`. Vide : toujours rendu.
|
|
54
|
+
*/
|
|
55
|
+
declare when?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Seuil mobile des expressions `mobile` / `desktop`.
|
|
58
|
+
* @default 'md'
|
|
59
|
+
*/
|
|
60
|
+
declare mobile?: Breakpoint;
|
|
61
|
+
private stop: (() => void) | null = null;
|
|
62
|
+
|
|
63
|
+
override connectedCallback(): void {
|
|
64
|
+
super.connectedCallback();
|
|
65
|
+
if (this.stop || !this.content) return;
|
|
66
|
+
const win = this.ownerDocument.defaultView;
|
|
67
|
+
if (!win) return;
|
|
68
|
+
const onResize = () => this.update();
|
|
69
|
+
const mq = typeof win.matchMedia === 'function' ? win.matchMedia(BREAKPOINT_TOUCH_QUERY) : null;
|
|
70
|
+
win.addEventListener('resize', onResize, { passive: true });
|
|
71
|
+
mq?.addEventListener('change', onResize);
|
|
72
|
+
this.stop = () => { win.removeEventListener('resize', onResize); mq?.removeEventListener('change', onResize); };
|
|
73
|
+
}
|
|
74
|
+
override disconnectedCallback(): void {
|
|
75
|
+
super.disconnectedCallback();
|
|
76
|
+
this.stop?.();
|
|
77
|
+
this.stop = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected render() {
|
|
81
|
+
const state = stateOf(this.ownerDocument.defaultView, this.mobile || BREAKPOINT_MOBILE);
|
|
82
|
+
return breakpointShows(this.when, state) ? unslotted(this.content) : slotted(this.content, 'fallback');
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/dataview.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-dataview data-key="id" layout="grid" show-layout-switch paginator rows="12" sort-field="name" filter-by='["name","owner"]' grid-cols="1 sm:2 lg:3">
|
|
3
|
+
* <div slot="header">…</div>
|
|
4
|
+
* </poad-dataview>
|
|
5
|
+
* dataview.value = projets; dataview.renderList = ({ item }) => nœud; dataview.renderGrid = ({ item }) => nœud;
|
|
6
|
+
*
|
|
7
|
+
* Vue de données (le `poad-dataview` d'ui-angular) : liste ou grille de gabarits de l'application, recherche sans accents
|
|
8
|
+
* ni casse sur des champs, tri sur un champ, page, bascule liste / grille, squelettes au chargement. Modèle `dataview`
|
|
9
|
+
* de @poadio/ui-core ; même DOM et mêmes classes qu'Angular. Disposition (`layout`) et page (`first`, `rows`) tenues par
|
|
10
|
+
* l'élément. Styles : `@poadio/ui-core/dataview.css`, `paginator.css`, `skeleton.css`, `icon.css`.
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
dataviewBodyState, dataviewGridVars, dataviewItems, dataviewPage, dataviewRootClasses, dataviewSetLayout, dataviewSwitchItems, dataviewTrack, skeletonBars, skeletonRootClasses,
|
|
14
|
+
type DataviewLayout, type SkeletonOptions,
|
|
15
|
+
} from '@poadio/ui-core';
|
|
16
|
+
import { h, type Child } from './dom.js';
|
|
17
|
+
import { PoadElement } from './element.js';
|
|
18
|
+
import { icon } from './icon.js';
|
|
19
|
+
import { paginatorView } from './paginator.js';
|
|
20
|
+
|
|
21
|
+
type Item = Record<string, unknown>;
|
|
22
|
+
/** Contexte d'un gabarit d'élément. */
|
|
23
|
+
export interface PoadDataviewItemContext { readonly item: Item; readonly index: number }
|
|
24
|
+
const slotted = (content: readonly Node[] | null, name: string) => (content ?? []).filter((n) => n instanceof Element && n.getAttribute('slot') === name);
|
|
25
|
+
const skeleton = (o: SkeletonOptions) => h('div', { class: ['poad-skeleton', skeletonRootClasses(o)], 'aria-hidden': 'true' },
|
|
26
|
+
skeletonBars(o).map((bar) => h('span', { class: bar.className, style: { width: bar.width, height: bar.height } })));
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Vue de données : liste ou grille de gabarits (`renderList`, `renderGrid`).
|
|
30
|
+
* @fires layoutchange {DataviewLayout} L'utilisateur change de disposition.
|
|
31
|
+
* @fires pagechange {PaginatorEvent} L'utilisateur change de page ou de taille de page.
|
|
32
|
+
* @slot header Contenu de l'en-tête, à gauche de la bascule.
|
|
33
|
+
* @slot footer Contenu du pied, avant le paginateur.
|
|
34
|
+
*/
|
|
35
|
+
export class PoadDataviewElement extends PoadElement {
|
|
36
|
+
static override props = {
|
|
37
|
+
value: 'json', dataKey: 'string', layout: 'string', showLayoutSwitch: 'boolean', paginator: 'boolean', first: 'number', rows: 'number', rowsPerPageOptions: 'json',
|
|
38
|
+
alwaysShowPaginator: 'boolean', sortField: 'string', sortOrder: 'number', filterValue: 'string', filterBy: 'json', gridCols: 'string', gridMin: 'string',
|
|
39
|
+
loading: 'boolean', loadingRows: 'number', emptyMessage: 'string',
|
|
40
|
+
} as const;
|
|
41
|
+
static override functions = ['renderList', 'renderGrid'] as const;
|
|
42
|
+
/** Éléments affichés. */
|
|
43
|
+
declare value?: readonly Item[];
|
|
44
|
+
/** Champ de la clé d'un élément (suivi des éléments ; sinon leur place). */
|
|
45
|
+
declare dataKey?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Disposition `list` ou `grid`, tenue par l'élément.
|
|
48
|
+
* @default 'list'
|
|
49
|
+
*/
|
|
50
|
+
declare layout?: DataviewLayout;
|
|
51
|
+
/** Bascule liste / grille dans l'en-tête. */
|
|
52
|
+
declare showLayoutSwitch?: boolean;
|
|
53
|
+
/** Paginateur au pied et éléments découpés en pages. */
|
|
54
|
+
declare paginator?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Index du premier élément de la page, tenu par l'élément.
|
|
57
|
+
* @default 0
|
|
58
|
+
*/
|
|
59
|
+
declare first?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Taille de page, tenue par l'élément.
|
|
62
|
+
* @default 12
|
|
63
|
+
*/
|
|
64
|
+
declare rows?: number;
|
|
65
|
+
/** Tailles de page proposées. */
|
|
66
|
+
declare rowsPerPageOptions?: readonly number[];
|
|
67
|
+
/**
|
|
68
|
+
* Paginateur affiché même avec une seule page.
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
declare alwaysShowPaginator?: boolean;
|
|
72
|
+
/** Champ du tri (sinon : l'ordre de `value`). */
|
|
73
|
+
declare sortField?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Ordre du tri : `1` croissant, `-1` décroissant.
|
|
76
|
+
* @default 1
|
|
77
|
+
*/
|
|
78
|
+
declare sortOrder?: 1 | -1;
|
|
79
|
+
/** Texte recherché (sans accents ni casse) dans `filterBy`. */
|
|
80
|
+
declare filterValue?: string;
|
|
81
|
+
/** Champs de la recherche. */
|
|
82
|
+
declare filterBy?: readonly string[];
|
|
83
|
+
/**
|
|
84
|
+
* Colonnes de la grille : un nombre, ou par point de rupture (`"1 sm:2 lg:3"`).
|
|
85
|
+
* @default '1 sm:2 lg:3'
|
|
86
|
+
*/
|
|
87
|
+
declare gridCols?: string;
|
|
88
|
+
/** Largeur minimale d'une carte : la grille remplit la ligne (à la place de `gridCols`). */
|
|
89
|
+
declare gridMin?: string;
|
|
90
|
+
/** Chargement : squelettes à la place des éléments. */
|
|
91
|
+
declare loading?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Nombre de squelettes.
|
|
94
|
+
* @default 6
|
|
95
|
+
*/
|
|
96
|
+
declare loadingRows?: number;
|
|
97
|
+
/** Message du corps vide (défaut : message du catalogue). */
|
|
98
|
+
declare emptyMessage?: string;
|
|
99
|
+
/** Gabarit d'un élément en liste : ({ item, index }) → texte ou nœud ; sinon celui de la grille. */
|
|
100
|
+
declare renderList?: (ctx: PoadDataviewItemContext) => string | Node | null | undefined;
|
|
101
|
+
/** Gabarit d'un élément en grille : ({ item, index }) → texte ou nœud ; sinon celui de la liste. */
|
|
102
|
+
declare renderGrid?: (ctx: PoadDataviewItemContext) => string | Node | null | undefined;
|
|
103
|
+
|
|
104
|
+
protected render(): Child {
|
|
105
|
+
const i18n = this.i18n();
|
|
106
|
+
const { t, text, locale } = i18n;
|
|
107
|
+
const registry = this.icons();
|
|
108
|
+
const layout = this.layout ?? 'list';
|
|
109
|
+
const first = this.first ?? 0, rows = this.rows ?? 12;
|
|
110
|
+
const items = dataviewItems(this.value ?? [], { filterValue: this.filterValue, filterBy: this.filterBy, sortField: this.sortField, sortOrder: this.sortOrder, locale });
|
|
111
|
+
const page = dataviewPage(items, { paginator: this.paginator, first, rows });
|
|
112
|
+
const body = dataviewBodyState({ loading: this.loading, count: page.length });
|
|
113
|
+
const grid = layout === 'grid';
|
|
114
|
+
const tpl = grid ? this.renderGrid ?? this.renderList : this.renderList ?? this.renderGrid;
|
|
115
|
+
const at = (i: number) => (this.paginator ? first : 0) + i;
|
|
116
|
+
const skel = Array.from({ length: this.loadingRows ?? 6 }, (_, i) => i);
|
|
117
|
+
const change = (l: DataviewLayout) => {
|
|
118
|
+
const next = dataviewSetLayout(layout, l); if (!next) return;
|
|
119
|
+
this.layout = next; this.emit('layoutchange', next);
|
|
120
|
+
};
|
|
121
|
+
const footer = slotted(this.content, 'footer');
|
|
122
|
+
return h('div', { class: ['poad-dataview', dataviewRootClasses({ layout, min: this.gridMin })], style: grid ? dataviewGridVars(this.gridCols ?? '1 sm:2 lg:3', this.gridMin) : undefined }, [
|
|
123
|
+
h('div', { class: 'dv__hd' }, [
|
|
124
|
+
h('div', { class: 'dv__hd-slot' }, slotted(this.content, 'header')),
|
|
125
|
+
this.showLayoutSwitch && h('div', { class: 'dv__switch', role: 'group', 'aria-label': t('dataview.layout') }, dataviewSwitchItems(layout).map((b) =>
|
|
126
|
+
h('button', { type: 'button', class: b.className || undefined, 'aria-pressed': b['aria-pressed'], 'aria-label': t(b.labelKey), onclick: () => change(b.layout) }, icon(registry, b.icon, { size: 15 })))),
|
|
127
|
+
]),
|
|
128
|
+
body === 'skeleton' ? h('div', { class: 'dv__body' }, grid
|
|
129
|
+
? h('div', { class: 'dv__grid' }, skel.map(() => skeleton({ shape: 'rect', height: '120px' })))
|
|
130
|
+
: skel.map(() => h('div', { class: 'dv__row' }, skeleton({ lines: 2 }))))
|
|
131
|
+
: body === 'empty' ? h('div', { class: 'dv__empty' }, [icon(registry, 'inbox', { size: 24, strokeWidth: 1.5 }), h('span', {}, text(this.emptyMessage, 'dataview.empty'))])
|
|
132
|
+
: grid ? h('div', { class: 'dv__body dv__grid' }, page.map((it, i) => (tpl?.({ item: it, index: at(i) }) ?? null) as Child))
|
|
133
|
+
: h('div', { class: 'dv__body dv__list' }, page.map((it, i) => h('div', { class: 'dv__row', 'data-track': String(dataviewTrack(it, i, this.dataKey)) }, (tpl?.({ item: it, index: at(i) }) ?? null) as Child))),
|
|
134
|
+
(footer.length > 0 || this.paginator) && h('div', { class: 'dv__ft' }, [
|
|
135
|
+
footer,
|
|
136
|
+
this.paginator && paginatorView(i18n, registry, {
|
|
137
|
+
first, rows, totalRecords: items.length, rowsPerPageOptions: this.rowsPerPageOptions ?? [6, 12, 24, 48], alwaysShow: this.alwaysShowPaginator ?? true,
|
|
138
|
+
onPage: (e) => { this.first = e.first; this.rows = e.rows; this.emit('pagechange', e); }, owner: this, selectTag: this.tag('select'),
|
|
139
|
+
}),
|
|
140
|
+
]),
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/floating.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* compensé, mais s'il coupe, il coupe aussi le flottant.
|
|
12
12
|
*/
|
|
13
13
|
import {
|
|
14
|
-
FOCUSABLE_SELECTOR, FOCUS_AUTOFOCUS_ATTR, SHEET_ANIM_MS,
|
|
15
|
-
focusTrapTab,
|
|
14
|
+
FOCUSABLE_SELECTOR, FOCUS_AUTOFOCUS_ATTR, SHEET_ANIM_MS, lockDocumentScroll, dismissDecision, elementIsRtl, floatingPlacement, focusTrapInitial,
|
|
15
|
+
focusTrapTab, sheetDialogProps, sheetDragOffset, sheetDragStarts, sheetDragTransform, sheetHeightClass, sheetHeightCss, sheetRelease,
|
|
16
16
|
type DismissPolicy, type DismissReason, type FloatingAlign, type FloatingPlacement, type FloatingPosition, type FloatingSide, type FocusCandidate,
|
|
17
17
|
type IconRegistry, type SheetHeight,
|
|
18
18
|
} from '@poadio/ui-core';
|
|
@@ -171,24 +171,9 @@ export class FocusTrap {
|
|
|
171
171
|
|
|
172
172
|
// ───────────────────────────── blocage du défilement ─────────────────────────────
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
let saved: { overflow: string; paddingInlineEnd: string } | null = null;
|
|
176
|
-
|
|
174
|
+
/** Bloque le défilement de la page : `lockDocumentScroll` d'ui-core (compteur par document, partagé par tous les rendus). */
|
|
177
175
|
export function lockScroll(): () => void {
|
|
178
|
-
|
|
179
|
-
if (locks.acquire()) {
|
|
180
|
-
saved = { overflow: root.style.overflow, paddingInlineEnd: root.style.paddingInlineEnd };
|
|
181
|
-
const s = scrollLockStyle(window.innerWidth - root.clientWidth, parseFloat(getComputedStyle(root).paddingInlineEnd) || 0);
|
|
182
|
-
root.style.overflow = s.overflow;
|
|
183
|
-
if (s.paddingInlineEnd) root.style.paddingInlineEnd = s.paddingInlineEnd;
|
|
184
|
-
}
|
|
185
|
-
return () => {
|
|
186
|
-
if (locks.release() && saved) {
|
|
187
|
-
root.style.overflow = saved.overflow;
|
|
188
|
-
root.style.paddingInlineEnd = saved.paddingInlineEnd;
|
|
189
|
-
saved = null;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
176
|
+
return lockDocumentScroll(document);
|
|
192
177
|
}
|
|
193
178
|
|
|
194
179
|
// ───────────────────────────── présence (animations d'entrée et de sortie) ─────────────────────────────
|
package/src/index.ts
CHANGED
|
@@ -58,6 +58,12 @@ import { PoadSpeedDialElement } from './speed-dial.js';
|
|
|
58
58
|
import { PoadListboxElement } from './listbox.js';
|
|
59
59
|
import { PoadUploadElement } from './upload.js';
|
|
60
60
|
import { PoadCarouselElement } from './carousel.js';
|
|
61
|
+
import { PoadIfElement } from './breakpoint.js';
|
|
62
|
+
import { PoadMenubarElement } from './menubar.js';
|
|
63
|
+
import { PoadBottomNavElement } from './bottom-nav.js';
|
|
64
|
+
import { PoadNavDrawerElement } from './nav-drawer.js';
|
|
65
|
+
import { PoadAppShellElement } from './app-shell.js';
|
|
66
|
+
import { PoadCenterElement, PoadClusterElement, PoadContainerElement, PoadGridElement, PoadSidebarElement, PoadSpacerElement, PoadSplitElement, PoadStackElement } from './layout.js';
|
|
61
67
|
import { PoadMultiselectElement } from './multiselect.js';
|
|
62
68
|
import { PoadComboElement } from './combo.js';
|
|
63
69
|
import { PoadDatepickerElement } from './datepicker.js';
|
|
@@ -68,6 +74,7 @@ import { PoadTableElement } from './table.js';
|
|
|
68
74
|
import { PoadPaginatorElement } from './paginator.js';
|
|
69
75
|
import { PoadTablePanelElement } from './table-panel.js';
|
|
70
76
|
import { PoadFilterChipElement } from './filter-chip.js';
|
|
77
|
+
import { PoadDataviewElement } from './dataview.js';
|
|
71
78
|
import { noteDefinedPrefix } from './services.js';
|
|
72
79
|
|
|
73
80
|
/** Nom (sans préfixe) → classe de chaque élément. */
|
|
@@ -83,9 +90,11 @@ export const POAD_ELEMENTS = {
|
|
|
83
90
|
step: PoadStepElement, menu: PoadMenuElement, 'split-button': PoadSplitButtonElement,
|
|
84
91
|
multiselect: PoadMultiselectElement, combo: PoadComboElement, datepicker: PoadDatepickerElement,
|
|
85
92
|
dialog: PoadDialogElement, drawer: PoadDrawerElement, 'confirm-dialog': PoadConfirmDialogElement, toast: PoadToastElement,
|
|
86
|
-
table: PoadTableElement, paginator: PoadPaginatorElement, 'table-panel': PoadTablePanelElement, 'filter-chip': PoadFilterChipElement,
|
|
93
|
+
table: PoadTableElement, paginator: PoadPaginatorElement, 'table-panel': PoadTablePanelElement, 'filter-chip': PoadFilterChipElement, dataview: PoadDataviewElement,
|
|
87
94
|
breadcrumb: PoadBreadcrumbElement, timeline: PoadTimelineElement, 'scroll-top': PoadScrollTopElement, block: PoadBlockElement, image: PoadImageElement,
|
|
88
95
|
splitter: PoadSplitterElement, 'splitter-panel': PoadSplitterPanelElement, 'speed-dial': PoadSpeedDialElement, listbox: PoadListboxElement, upload: PoadUploadElement, carousel: PoadCarouselElement,
|
|
96
|
+
if: PoadIfElement, menubar: PoadMenubarElement, 'bottom-nav': PoadBottomNavElement, 'nav-drawer': PoadNavDrawerElement, 'app-shell': PoadAppShellElement, stack: PoadStackElement, cluster: PoadClusterElement, grid: PoadGridElement, split: PoadSplitElement, sidebar: PoadSidebarElement,
|
|
97
|
+
center: PoadCenterElement, container: PoadContainerElement, spacer: PoadSpacerElement,
|
|
89
98
|
} as const;
|
|
90
99
|
|
|
91
100
|
export interface DefineElementsOptions {
|
|
@@ -131,19 +140,30 @@ export {
|
|
|
131
140
|
PoadAccordionPanelElement, PoadStepperElement, PoadStepElement, PoadMenuElement, PoadSplitButtonElement,
|
|
132
141
|
PoadMultiselectElement, PoadComboElement, PoadDatepickerElement, PoadDialogElement, PoadDrawerElement,
|
|
133
142
|
PoadConfirmDialogElement, PoadToastElement, PoadTableElement, PoadPaginatorElement, PoadCardElement, PoadPanelElement, PoadFieldsetElement,
|
|
134
|
-
PoadTablePanelElement, PoadFilterChipElement,
|
|
143
|
+
PoadTablePanelElement, PoadFilterChipElement, PoadDataviewElement,
|
|
135
144
|
PoadBreadcrumbElement, PoadTimelineElement, PoadScrollTopElement, PoadBlockElement, PoadImageElement, PoadSplitterElement, PoadSplitterPanelElement, PoadSpeedDialElement, PoadListboxElement, PoadUploadElement, PoadCarouselElement,
|
|
145
|
+
PoadIfElement, PoadStackElement, PoadClusterElement, PoadGridElement, PoadSplitElement, PoadSidebarElement, PoadCenterElement, PoadContainerElement, PoadSpacerElement,
|
|
146
|
+
PoadMenubarElement, PoadBottomNavElement, PoadNavDrawerElement, PoadAppShellElement,
|
|
136
147
|
};
|
|
148
|
+
/** Types de la mise en page. */
|
|
149
|
+
export type { LayoutGap, LayoutAlign, LayoutJustify, LayoutContainerSize } from '@poadio/ui-core';
|
|
150
|
+
export { watchBreakpoint } from './breakpoint.js';
|
|
151
|
+
/** Types des points de rupture. */
|
|
152
|
+
export type { Breakpoint, BreakpointState } from '@poadio/ui-core';
|
|
137
153
|
export { poadConfirm, type PoadConfirmOptions } from './confirm.js';
|
|
138
154
|
export { poadToast, createPoadToastService, type PoadToastService, type PoadToastMessage, type PoadToastAction } from './toast.js';
|
|
139
155
|
export type { PoadComboSource } from './combo.js';
|
|
140
156
|
export type { PoadMenuItem, MenuPoint } from './menu.js';
|
|
157
|
+
export type { PoadMenubarItem, PoadMenubarColumn } from './menubar.js';
|
|
158
|
+
export type { PoadBottomNavItem } from './bottom-nav.js';
|
|
159
|
+
export type { PoadNavDrawerItem } from './nav-drawer.js';
|
|
141
160
|
export type { PoadBreadcrumbItem } from './breadcrumb.js';
|
|
142
161
|
export type { PoadTimelineRender } from './timeline.js';
|
|
143
162
|
export type { PoadCarouselRender } from './carousel.js';
|
|
144
163
|
export type { TabData } from './tabs.js';
|
|
145
|
-
export type { PoadTableColumn, PoadTableCellContext, PoadTableSortDetail, PoadTableLazyLoadDetail, PoadTableRowDetail, PoadTableNodeDetail, PoadTableFilterDetail, PoadTableFilterContext, PoadTableGroupContext } from './table.js';
|
|
164
|
+
export type { PoadTableColumn, PoadTableCellContext, PoadTableSortDetail, PoadTableLazyLoadDetail, PoadTableRowDetail, PoadTableNodeDetail, PoadTableFilterDetail, PoadTableFilterContext, PoadTableGroupContext, PoadTableExpansionContext, PoadTableRowActionsContext, PoadTableCardContext } from './table.js';
|
|
146
165
|
export type { PoadTablePanelTab } from './table-panel.js';
|
|
166
|
+
export type { PoadDataviewItemContext } from './dataview.js';
|
|
147
167
|
/** Types de la table. */
|
|
148
168
|
export type { TableFilters, TableFilterMeta, TableFilterMatchMode, TableFilterKind, TableFilterOption } from '@poadio/ui-core';
|
|
149
169
|
/** Texte d'une valeur de filtre pour une puce, et prédicat des filtres (pour filtrer ailleurs comme la table). */
|