@poadio/ui-elements 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +47 -1
  3. package/dist/accordion.d.ts +31 -0
  4. package/dist/accordion.d.ts.map +1 -0
  5. package/dist/accordion.js +67 -0
  6. package/dist/accordion.js.map +1 -0
  7. package/dist/checkbox.d.ts +15 -1
  8. package/dist/checkbox.d.ts.map +1 -1
  9. package/dist/checkbox.js +18 -0
  10. package/dist/checkbox.js.map +1 -1
  11. package/dist/combo.d.ts +88 -0
  12. package/dist/combo.d.ts.map +1 -0
  13. package/dist/combo.js +238 -0
  14. package/dist/combo.js.map +1 -0
  15. package/dist/confirm.d.ts +35 -0
  16. package/dist/confirm.d.ts.map +1 -0
  17. package/dist/confirm.js +94 -0
  18. package/dist/confirm.js.map +1 -0
  19. package/dist/datepicker.d.ts +146 -0
  20. package/dist/datepicker.d.ts.map +1 -0
  21. package/dist/datepicker.js +468 -0
  22. package/dist/datepicker.js.map +1 -0
  23. package/dist/declaration.d.ts +25 -0
  24. package/dist/declaration.d.ts.map +1 -0
  25. package/dist/declaration.js +35 -0
  26. package/dist/declaration.js.map +1 -0
  27. package/dist/dialog.d.ts +137 -0
  28. package/dist/dialog.d.ts.map +1 -0
  29. package/dist/dialog.js +174 -0
  30. package/dist/dialog.js.map +1 -0
  31. package/dist/element.d.ts +4 -0
  32. package/dist/element.d.ts.map +1 -1
  33. package/dist/element.js +5 -2
  34. package/dist/element.js.map +1 -1
  35. package/dist/index.d.ts +40 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +23 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/menu.d.ts +121 -0
  40. package/dist/menu.d.ts.map +1 -0
  41. package/dist/menu.js +245 -0
  42. package/dist/menu.js.map +1 -0
  43. package/dist/meter.d.ts +1 -0
  44. package/dist/meter.d.ts.map +1 -1
  45. package/dist/meter.js +1 -2
  46. package/dist/meter.js.map +1 -1
  47. package/dist/multiselect.d.ts +133 -0
  48. package/dist/multiselect.d.ts.map +1 -0
  49. package/dist/multiselect.js +230 -0
  50. package/dist/multiselect.js.map +1 -0
  51. package/dist/option-list.d.ts +28 -0
  52. package/dist/option-list.d.ts.map +1 -0
  53. package/dist/option-list.js +31 -0
  54. package/dist/option-list.js.map +1 -0
  55. package/dist/paginator.d.ts +65 -0
  56. package/dist/paginator.d.ts.map +1 -0
  57. package/dist/paginator.js +110 -0
  58. package/dist/paginator.js.map +1 -0
  59. package/dist/segmented.d.ts +1 -0
  60. package/dist/segmented.d.ts.map +1 -1
  61. package/dist/segmented.js +1 -2
  62. package/dist/segmented.js.map +1 -1
  63. package/dist/select.d.ts +3 -6
  64. package/dist/select.d.ts.map +1 -1
  65. package/dist/select.js +8 -24
  66. package/dist/select.js.map +1 -1
  67. package/dist/services.d.ts +3 -0
  68. package/dist/services.d.ts.map +1 -0
  69. package/dist/services.js +10 -0
  70. package/dist/services.js.map +1 -0
  71. package/dist/slider.d.ts +1 -0
  72. package/dist/slider.d.ts.map +1 -1
  73. package/dist/slider.js +1 -2
  74. package/dist/slider.js.map +1 -1
  75. package/dist/split-button.d.ts +47 -0
  76. package/dist/split-button.d.ts.map +1 -0
  77. package/dist/split-button.js +64 -0
  78. package/dist/split-button.js.map +1 -0
  79. package/dist/stepper.d.ts +56 -0
  80. package/dist/stepper.d.ts.map +1 -0
  81. package/dist/stepper.js +69 -0
  82. package/dist/stepper.js.map +1 -0
  83. package/dist/table.d.ts +176 -0
  84. package/dist/table.d.ts.map +1 -0
  85. package/dist/table.js +293 -0
  86. package/dist/table.js.map +1 -0
  87. package/dist/tabs.d.ts +62 -0
  88. package/dist/tabs.d.ts.map +1 -0
  89. package/dist/tabs.js +118 -0
  90. package/dist/tabs.js.map +1 -0
  91. package/dist/toast.d.ts +79 -0
  92. package/dist/toast.d.ts.map +1 -0
  93. package/dist/toast.js +176 -0
  94. package/dist/toast.js.map +1 -0
  95. package/package.json +3 -3
  96. package/src/accordion.ts +80 -0
  97. package/src/checkbox.ts +21 -1
  98. package/src/combo.ts +220 -0
  99. package/src/confirm.ts +106 -0
  100. package/src/datepicker.ts +413 -0
  101. package/src/declaration.ts +37 -0
  102. package/src/dialog.ts +217 -0
  103. package/src/element.ts +7 -2
  104. package/src/index.ts +33 -2
  105. package/src/menu.ts +281 -0
  106. package/src/meter.ts +2 -1
  107. package/src/multiselect.ts +273 -0
  108. package/src/option-list.ts +51 -0
  109. package/src/paginator.ts +151 -0
  110. package/src/segmented.ts +2 -1
  111. package/src/select.ts +14 -30
  112. package/src/services.ts +10 -0
  113. package/src/slider.ts +2 -1
  114. package/src/split-button.ts +76 -0
  115. package/src/stepper.ts +86 -0
  116. package/src/table.ts +364 -0
  117. package/src/tabs.ts +129 -0
  118. package/src/toast.ts +203 -0
@@ -0,0 +1,273 @@
1
+ /**
2
+ * <poad-multiselect name="envs" aria-label="Environments" filter show-toggle-all
3
+ * options='[{"label":"Dev","value":"dev"},{"label":"Prod","value":"prod"}]' value='["dev"]'></poad-multiselect>
4
+ *
5
+ * Liste à choix multiples : machine `select` de @poadio/ui-core en mode `multiple` (ouverture, option active, filtre,
6
+ * clavier, recherche au clavier, attributs, placement) et ses compléments `multiselect*` (bascule bornée par
7
+ * `selection-limit`, puces retirables, case « tout » tri-état sur les options visibles, ce que montre le déclencheur).
8
+ * Propriété `value` (tableau ; attribut en JSON) ; Espace / Entrée basculent l'option sans fermer. Évènements `input` /
9
+ * `change` (detail : le tableau) à chaque changement de l'utilisateur, `remove` (detail : la valeur d'une puce retirée),
10
+ * `clear`, `filter`, `openchange`. Formulaire : `name` (une entrée par valeur, en chaîne — JSON pour un objet),
11
+ * `required` (au moins une). Même DOM, mêmes classes, même ARIA que `poad-multiselect` d'ui-angular ; petit écran :
12
+ * feuille basse avec un pied « OK (n) ». Styles : `multiselect.css`, `option-list.css`, `icon.css`, `floating.css`,
13
+ * `sheet.css`.
14
+ */
15
+ import {
16
+ FOCUS_AUTOFOCUS_ATTR, SELECT_INITIAL, SELECT_PLACEMENTS, SHEET_MOBILE_QUERY, multiselectAllProps, multiselectAllState, multiselectCountLabel, multiselectIncludes,
17
+ multiselectLimitReached, multiselectRemove, multiselectRootClasses, multiselectShows, multiselectToggle, multiselectToggleAll, selectEmptyMessage, selectFilterProps,
18
+ selectItems, selectOptionsOf, selectScrollTop, selectSheetTitle, selectTransition, selectTriggerProps, selectUseSheet, selectVisibleItems,
19
+ type MultiselectDisplay, type SelectContext, type SelectEffect, type SelectEvent, type SelectMobileMode, type SelectOptionItem, type SelectState,
20
+ } from '@poadio/ui-core';
21
+ import { h } from './dom.js';
22
+ import { PoadFormElement } from './element.js';
23
+ import { FloatingTracker, Listening, Sheet, listenOutside, mediaMatches } from './floating.js';
24
+ import { icon } from './icon.js';
25
+ import { optionList, type PoadSelectOptionContext } from './option-list.js';
26
+
27
+ const autofocus = (on: boolean) => (on ? { [FOCUS_AUTOFOCUS_ATTR]: '' } : {});
28
+
29
+ export class PoadMultiselectElement extends PoadFormElement {
30
+ static override props = {
31
+ value: 'json', options: 'json', optionLabel: 'string', optionValue: 'string', optionDisabled: 'string', optionHint: 'string', optionIcon: 'string',
32
+ optionGroupLabel: 'string', optionGroupChildren: 'string', dataKey: 'string', placeholder: 'string', display: 'string', maxSelectedLabels: 'number',
33
+ selectedItemsLabel: 'string', showToggleAll: 'boolean', selectionLimit: 'number', filter: 'boolean', filterPlaceholder: 'string', filterBy: 'string',
34
+ autofocusFilter: 'boolean', clearable: 'boolean', loading: 'boolean', emptyMessage: 'string', emptyFilterMessage: 'string', size: 'string',
35
+ invalid: 'boolean', disabled: 'boolean', readonly: 'boolean', panelMaxHeight: 'number', ariaLabel: 'string', mobile: 'string', sheetTitle: 'string',
36
+ name: 'string', required: 'boolean',
37
+ } as const;
38
+ static override functions = ['compareWith', 'renderOption', 'renderValue', 'renderEmpty'] as const;
39
+ declare value?: readonly unknown[] | null;
40
+ declare options?: readonly unknown[];
41
+ declare optionLabel?: string;
42
+ declare optionValue?: string;
43
+ declare optionDisabled?: string;
44
+ declare optionHint?: string;
45
+ declare optionIcon?: string;
46
+ declare optionGroupLabel?: string;
47
+ declare optionGroupChildren?: string;
48
+ declare dataKey?: string;
49
+ declare placeholder?: string;
50
+ /** `chip` (défaut) : puces retirables ; `comma` : libellés joints. */
51
+ declare display?: MultiselectDisplay;
52
+ /** Au-delà de N valeurs, le déclencheur montre un compte (`selected-items-label`, `{0}` = nombre ; défaut : catalogue). */
53
+ declare maxSelectedLabels?: number | null;
54
+ declare selectedItemsLabel?: string;
55
+ declare showToggleAll?: boolean;
56
+ declare selectionLimit?: number | null;
57
+ declare filter?: boolean;
58
+ declare filterPlaceholder?: string;
59
+ declare filterBy?: string;
60
+ declare autofocusFilter?: boolean;
61
+ declare clearable?: boolean;
62
+ declare loading?: boolean;
63
+ declare emptyMessage?: string;
64
+ declare emptyFilterMessage?: string;
65
+ declare size?: 'sm' | 'md' | 'lg';
66
+ declare invalid?: boolean;
67
+ declare disabled?: boolean;
68
+ declare readonly?: boolean;
69
+ declare panelMaxHeight?: number;
70
+ declare ariaLabel: string | null;
71
+ declare mobile?: SelectMobileMode;
72
+ declare sheetTitle?: string;
73
+ declare name?: string;
74
+ declare required?: boolean;
75
+ declare compareWith?: (a: unknown, b: unknown) => boolean;
76
+ /** Contenu d'une option, d'une puce, de la liste vide. */
77
+ declare renderOption?: (option: unknown, context: PoadSelectOptionContext) => string | Node;
78
+ declare renderValue?: (option: unknown, context: { readonly label: string }) => string | Node;
79
+ declare renderEmpty?: (context: { readonly filtered: boolean; readonly query: string }) => string | Node;
80
+ protected readonly resetProps = ['value'];
81
+
82
+ private state: SelectState = SELECT_INITIAL;
83
+ private focused = false;
84
+ private inSheet = false;
85
+ private triggerWidth = 0;
86
+ private readonly tracker = new FloatingTracker(() => this.update());
87
+ private readonly outside = new Listening(() => listenOutside(() => [this], () => this.send({ type: 'close', refocus: false })));
88
+ private readonly sheet = new Sheet(() => this.update());
89
+
90
+ private find<E extends HTMLElement>(selector: string): E | null {
91
+ return this.querySelector<E>(`:scope > .poad-multiselect ${selector}`);
92
+ }
93
+ private get listId() { return `${this.uid}-list`; }
94
+ private get values(): readonly unknown[] { return this.value ?? []; }
95
+ private get items() {
96
+ const { optionLabel, optionValue, optionDisabled, optionHint, optionIcon, optionGroupLabel, optionGroupChildren } = this;
97
+ return selectItems(this.options, { optionLabel, optionValue, optionDisabled, optionHint, optionIcon, optionGroupLabel, optionGroupChildren }, this.listId);
98
+ }
99
+ private get compare() { return { compareWith: this.compareWith, dataKey: this.dataKey }; }
100
+ private get interactive() { return !this.inactive && !this.readonly; }
101
+ private readonly isSelected = (it: SelectOptionItem<unknown>) => multiselectIncludes(this.values, it.value, this.compare);
102
+ private context(items = this.items): SelectContext<unknown> {
103
+ return {
104
+ items, filter: { enabled: !!this.filter, by: this.filterBy, grouped: !!this.optionGroupLabel }, interactive: this.interactive, clearable: this.clearable,
105
+ modal: this.inSheet, multiple: true, isSelected: this.isSelected,
106
+ };
107
+ }
108
+
109
+ protected formValue() {
110
+ const values = this.values;
111
+ if (!this.name || !values.length) return { value: null, missing: !values.length };
112
+ const data = new FormData();
113
+ for (const v of values) data.append(this.name, typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v));
114
+ return { value: data, missing: false };
115
+ }
116
+ override disconnectedCallback(): void {
117
+ super.disconnectedCallback();
118
+ this.state = SELECT_INITIAL;
119
+ this.tracker.sync(null, null);
120
+ this.outside.toggle(false);
121
+ this.sheet.dispose();
122
+ }
123
+ private commit(next: readonly unknown[]) {
124
+ this.value = next;
125
+ this.changed([...next]);
126
+ }
127
+ private run(effect: SelectEffect<unknown>) {
128
+ switch (effect.type) {
129
+ case 'opened':
130
+ this.triggerWidth = this.find('.poad-multiselect__trigger')?.getBoundingClientRect().width ?? 0;
131
+ this.inSheet = selectUseSheet(this.mobile ?? 'auto', mediaMatches(SHEET_MOBILE_QUERY));
132
+ return void this.emit('openchange', true);
133
+ case 'closed':
134
+ this.inSheet = false;
135
+ this.emit('openchange', false);
136
+ if (effect.refocus) this.find('.poad-multiselect__trigger')?.focus();
137
+ return;
138
+ case 'pick': {
139
+ const cur = this.values;
140
+ const next = multiselectToggle(cur, effect.item.value, this.compare, this.selectionLimit ?? null);
141
+ if (next === cur) return; // limite atteinte
142
+ this.state = { ...this.state, activeIndex: effect.item.index };
143
+ return this.commit(next);
144
+ }
145
+ case 'clear':
146
+ this.commit([]);
147
+ return void this.emit('clear');
148
+ case 'filtered':
149
+ return void this.emit('filter', effect.query);
150
+ }
151
+ }
152
+ private send(event: SelectEvent) {
153
+ const was = this.state.open;
154
+ const step = selectTransition(this.state, event, this.context());
155
+ this.state = step.state;
156
+ step.effects.forEach((e) => this.run(e));
157
+ this.update();
158
+ if (this.state.open && !was && this.filter && this.autofocusFilter !== false && !this.inSheet) this.find<HTMLInputElement>('.poad-multiselect__head input')?.focus();
159
+ return step;
160
+ }
161
+ protected override updated(): void {
162
+ super.updated();
163
+ const floating = this.state.open && !this.inSheet;
164
+ this.tracker.sync(floating ? this.find('.poad-multiselect__trigger') : null, floating ? this.find('.poad-floating') : null, {
165
+ candidates: SELECT_PLACEMENTS, offset: 4, shift: true,
166
+ });
167
+ this.outside.toggle(this.state.open);
168
+ this.sheet.sync(this);
169
+ const list = this.find('.poad-optlist');
170
+ const option = list?.querySelector<HTMLElement>(`[id="${this.listId}-opt-${this.state.activeIndex}"]`);
171
+ if (!list || !option) return;
172
+ const next = selectScrollTop({ top: option.offsetTop, height: option.offsetHeight }, { scrollTop: list.scrollTop, clientHeight: list.clientHeight });
173
+ if (next !== null) list.scrollTop = next;
174
+ }
175
+ private readonly onKeydown = (e: KeyboardEvent) => {
176
+ const step = this.send({
177
+ type: 'keydown', key: e.key, ctrlKey: e.ctrlKey, metaKey: e.metaKey, altKey: e.altKey, inTextField: e.target instanceof HTMLInputElement, time: Date.now(),
178
+ });
179
+ if (step.preventDefault) e.preventDefault();
180
+ if (step.stopPropagation) e.stopPropagation();
181
+ };
182
+
183
+ protected render() {
184
+ const { t, text } = this.i18n();
185
+ const registry = this.icons();
186
+ const s = this.state, items = this.items, c = this.context(items), listId = this.listId, values = this.values, compare = this.compare;
187
+ const hasValue = values.length > 0;
188
+ const trigger = selectTriggerProps(s, c, { id: this.uid, listId, ariaLabel: this.ariaLabel, invalid: this.invalid, disabled: this.inactive, readonly: this.readonly });
189
+ const selectedItems = selectOptionsOf(items).filter(this.isSelected);
190
+ const visible = selectVisibleItems(s, c);
191
+ const visibleOptions = selectOptionsOf(visible);
192
+ const filtered = !!s.query;
193
+ const limit = multiselectLimitReached(values, this.selectionLimit ?? null);
194
+ const display = this.display ?? 'chip';
195
+ const root = multiselectRootClasses({
196
+ open: s.open, disabled: this.inactive, readonly: this.readonly, invalid: this.invalid, focused: this.focused, hasValue, limit, size: this.size ?? 'md', display,
197
+ });
198
+ const shows = multiselectShows(values.length, display, this.maxSelectedLabels ?? null);
199
+ const all = multiselectAllProps(multiselectAllState(visibleOptions, values, compare), !visibleOptions.some((o) => !o.disabled));
200
+ const interactive = this.interactive;
201
+ const remove = (it: SelectOptionItem<unknown>, e: MouseEvent) => {
202
+ e.stopPropagation();
203
+ if (!interactive) return;
204
+ this.commit(multiselectRemove(values, it.value, compare));
205
+ this.emit('remove', it.value);
206
+ };
207
+ const toggleAll = () => { if (interactive) this.commit(multiselectToggleAll(visibleOptions, values, compare, this.selectionLimit ?? null)); };
208
+ const clear = (e: MouseEvent) => { e.stopPropagation(); this.send({ type: 'clear' }); };
209
+ const f = selectFilterProps(s, c, { listId });
210
+ const head = (this.filter || this.showToggleAll) && h('div', { class: 'poad-multiselect__head' }, [
211
+ this.showToggleAll && h('button', {
212
+ type: 'button', class: 'poad-multiselect__all', role: all.role, 'aria-checked': all['aria-checked'], 'aria-label': t('select.selectAll'), tabindex: -1,
213
+ disabled: all.disabled, onpointerdown: (e: PointerEvent) => e.preventDefault(), onclick: toggleAll,
214
+ }, h('span', { class: ['poad-multiselect__check', all.classes] },
215
+ all.classes['is-on'] ? icon(registry, 'check', { size: 10, strokeWidth: 3.2 }) : all.classes['is-mixed'] && h('i'))),
216
+ this.filter ? [
217
+ icon(registry, 'search', { size: 13 }),
218
+ h('input', {
219
+ type: 'text', ...autofocus(this.inSheet), placeholder: text(this.filterPlaceholder, 'select.filterPlaceholder'), value: s.query, autocomplete: 'off',
220
+ spellcheck: 'false', role: f.role, 'aria-autocomplete': f['aria-autocomplete'], 'aria-controls': f['aria-controls'], 'aria-activedescendant': f['aria-activedescendant'],
221
+ oninput: (e: Event) => this.send({ type: 'filter', query: (e.target as HTMLInputElement).value }),
222
+ }),
223
+ ] : this.showToggleAll && h('span', { class: 'poad-multiselect__all-label', onclick: toggleAll }, t('common.all')),
224
+ ]);
225
+ const panel = h('div', {
226
+ class: ['poad-multiselect__panel', { 'is-sheet': this.inSheet }], style: this.inSheet ? undefined : { minWidth: `${this.triggerWidth}px` },
227
+ tabindex: this.inSheet ? -1 : undefined, ...autofocus(this.inSheet && !this.filter), onkeydown: this.onKeydown,
228
+ }, [
229
+ head,
230
+ optionList({
231
+ listId, items: visible, activeIndex: s.activeIndex, isSelected: this.isSelected, multiple: true, maxHeight: this.panelMaxHeight ?? 260, icons: registry,
232
+ renderOption: this.renderOption, onPick: (item) => this.send({ type: 'pick', item }), onHover: (index) => this.send({ type: 'hover', index }),
233
+ empty: this.renderEmpty ? this.renderEmpty({ filtered, query: s.query }) : text(filtered ? this.emptyFilterMessage : this.emptyMessage, selectEmptyMessage(filtered)),
234
+ }),
235
+ this.inSheet && h('div', { class: 'poad-multiselect__sheet-foot' }, [
236
+ hasValue && this.clearable && h('button', { type: 'button', class: 'poad-multiselect__sheet-btn is-ghost', onclick: clear }, t('select.clearAll')),
237
+ h('button', { type: 'button', class: 'poad-multiselect__sheet-btn', onclick: () => this.send({ type: 'close' }) },
238
+ [t('common.ok'), values.length ? ` (${values.length})` : '']),
239
+ ]),
240
+ ]);
241
+ return h('div', { class: ['poad-multiselect', root] }, [
242
+ h('div', {
243
+ class: 'poad-multiselect__trigger', role: trigger.role, tabindex: trigger.tabIndex, id: trigger.id, 'aria-haspopup': trigger['aria-haspopup'],
244
+ 'aria-expanded': trigger['aria-expanded'], 'aria-controls': trigger['aria-controls'], 'aria-activedescendant': trigger['aria-activedescendant'],
245
+ 'aria-label': trigger['aria-label'], 'aria-invalid': trigger['aria-invalid'], 'aria-disabled': trigger['aria-disabled'], 'aria-readonly': trigger['aria-readonly'],
246
+ onclick: () => this.send({ type: 'toggle' }), onkeydown: this.onKeydown,
247
+ onfocus: () => { this.focused = true; this.update(); }, onblur: () => { this.focused = false; this.update(); },
248
+ }, [
249
+ h('span', { class: ['poad-multiselect__value', { 'is-placeholder': !hasValue }] },
250
+ shows === 'placeholder' ? (this.placeholder ?? '')
251
+ : shows === 'count' ? (multiselectCountLabel(this.selectedItemsLabel, values.length) ?? t('select.selectedCount', { n: values.length }))
252
+ : shows === 'comma' ? selectedItems.map((o) => o.label).join(', ')
253
+ : selectedItems.map((o) => h('span', { class: 'poad-multiselect__chip' }, [
254
+ this.renderValue ? this.renderValue(o.option, { label: o.label }) : o.label,
255
+ interactive && h('button', {
256
+ type: 'button', class: 'poad-multiselect__chip-x', tabindex: -1, 'aria-label': t('select.removeItem', { label: o.label }),
257
+ onclick: (e: MouseEvent) => remove(o, e),
258
+ }, icon(registry, 'x', { size: 10, strokeWidth: 2.6 })),
259
+ ]))),
260
+ this.loading && icon(registry, 'loader', { size: 14, spin: true, class: 'poad-multiselect__spin' }),
261
+ this.clearable && hasValue && interactive && h('button', {
262
+ type: 'button', class: 'poad-multiselect__clear', tabindex: -1, 'aria-label': t('select.clearAll'), onclick: clear,
263
+ }, icon(registry, 'x', { size: 12 })),
264
+ icon(registry, 'chevron-down', { size: 13, class: 'poad-multiselect__chev' }),
265
+ ]),
266
+ s.open && !this.inSheet && h('div', { class: 'poad-floating', style: this.tracker.style }, panel),
267
+ this.sheet.render({
268
+ open: s.open && this.inSheet, titleId: `${this.uid}-sheet-title`, restoreFocus: false, label: t('common.close'), icons: registry,
269
+ onClose: () => this.send({ type: 'close' }), title: selectSheetTitle({ sheetTitle: this.sheetTitle, ariaLabel: this.ariaLabel, placeholder: this.placeholder }),
270
+ }, this.inSheet ? panel : null),
271
+ ]);
272
+ }
273
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Liste d'options d'un panneau — INTERNE, partagée par `<poad-select>` et `<poad-multiselect>` : même DOM que
3
+ * `poad-option-list` d'ui-angular (`role="listbox"`, options `role="option"`, coche ou case en choix multiple, icône,
4
+ * libellé, indice, groupes, message vide). Attributs : machine `select` d'ui-core. Style : `option-list.css`.
5
+ */
6
+ import { selectListboxProps, selectOptionProps, type IconRegistry, type SelectListItem, type SelectOptionItem } from '@poadio/ui-core';
7
+ import { h, type Child, type VNode } from './dom.js';
8
+ import { icon } from './icon.js';
9
+
10
+ export interface PoadSelectOptionContext {
11
+ readonly selected: boolean;
12
+ readonly active: boolean;
13
+ readonly index: number;
14
+ readonly label: string;
15
+ }
16
+
17
+ export interface OptionListOptions<T> {
18
+ readonly listId: string;
19
+ readonly items: readonly SelectListItem<T>[];
20
+ readonly activeIndex: number;
21
+ readonly isSelected: (item: SelectOptionItem<T>) => boolean;
22
+ readonly multiple?: boolean;
23
+ readonly maxHeight: number;
24
+ readonly empty: Child;
25
+ readonly icons: IconRegistry;
26
+ readonly renderOption?: (option: T, context: PoadSelectOptionContext) => string | Node;
27
+ readonly onPick: (item: SelectOptionItem<T>) => void;
28
+ readonly onHover: (index: number) => void;
29
+ }
30
+
31
+ export function optionList<T>(o: OptionListOptions<T>): VNode {
32
+ const listbox = selectListboxProps(o.listId, o.multiple);
33
+ return h('div', {
34
+ class: 'poad-optlist', role: listbox.role, id: listbox.id, 'aria-multiselectable': listbox['aria-multiselectable'] ?? undefined, style: { maxHeight: `${o.maxHeight}px` },
35
+ }, o.items.length ? o.items.map((it): Child => {
36
+ if (it.kind === 'group') return h('div', { class: 'poad-optlist__group', role: 'presentation', id: it.id }, it.label);
37
+ const isSel = o.isSelected(it);
38
+ const p = selectOptionProps(it, { active: it.index === o.activeIndex, selected: isSel });
39
+ return h('div', {
40
+ id: p.id, role: p.role, class: ['poad-optlist__opt', p.classes], 'aria-selected': p['aria-selected'], 'aria-disabled': p['aria-disabled'],
41
+ onpointerdown: (e: PointerEvent) => e.preventDefault(), onclick: () => !it.disabled && o.onPick(it), onpointerenter: () => !it.disabled && o.onHover(it.index),
42
+ }, o.renderOption ? o.renderOption(it.option, { selected: isSel, active: p.classes['is-active'], index: it.index, label: it.label }) : [
43
+ o.multiple
44
+ ? h('span', { class: ['poad-optlist__check', { 'is-on': isSel }] }, icon(o.icons, 'check', { size: 10, strokeWidth: 3.2 }))
45
+ : isSel && icon(o.icons, 'check', { size: 12, strokeWidth: 2.6, class: 'poad-optlist__tick' }),
46
+ it.icon && icon(o.icons, it.icon, { size: 14, class: 'poad-optlist__icon' }),
47
+ h('span', { class: 'poad-optlist__label' }, it.label),
48
+ it.hint && h('span', { class: 'poad-optlist__hint' }, it.hint),
49
+ ]);
50
+ }) : h('div', { class: 'poad-optlist__empty', role: 'presentation' }, o.empty));
51
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * <poad-paginator total-records="137" rows="10" first="40" show-first-last-icon></poad-paginator>
3
+ * pager.addEventListener('pagechange', (e) => load(e.detail.first, e.detail.rows));
4
+ *
5
+ * Paginateur : machine `paginator` de @poadio/ui-core (nombre de pages, liens avec ellipses, rapport du catalogue
6
+ * `paginator.report`, changement de taille de page qui garde la page). La position (`first`, `rows`) est tenue par
7
+ * l'élément, comme la valeur d'un champ natif : un geste la change et émet `pagechange` (detail : `{ first, rows, page,
8
+ * pageCount }`) ; une valeur posée par la page est rendue sans évènement. Même DOM, mêmes classes, même ARIA que
9
+ * `poad-paginator` d'ui-angular. Taille de page : `<poad-select>` de la même définition (jamais de `<select>` natif).
10
+ * Style : `@poadio/ui-core/paginator.css` (et `icon.css`, `select.css`, `option-list.css`, `floating.css`).
11
+ */
12
+ import {
13
+ paginatorChangeRows, paginatorEvent, paginatorGoTo, paginatorLinks, paginatorNavProps, paginatorPage, paginatorPageCount, paginatorReport, paginatorVisible,
14
+ type IconRegistry, type PaginatorEvent, type UiMessageKey,
15
+ } from '@poadio/ui-core';
16
+ import { h, type VNode } from './dom.js';
17
+ import { PoadElement } from './element.js';
18
+ import type { UiI18nValue } from './i18n.js';
19
+ import { icon } from './icon.js';
20
+
21
+ export interface PaginatorView {
22
+ readonly first: number;
23
+ readonly rows: number;
24
+ readonly totalRecords: number;
25
+ readonly rowsPerPageOptions?: readonly number[];
26
+ readonly rowsPerPageLabel?: string;
27
+ readonly pageLinks?: number;
28
+ readonly showCurrentPageReport?: boolean;
29
+ readonly currentPageReportTemplate?: string;
30
+ readonly showFirstLastIcon?: boolean;
31
+ readonly showPageLinks?: boolean;
32
+ readonly alwaysShow?: boolean;
33
+ /** Un geste a changé la position. */
34
+ readonly onPage: (e: PaginatorEvent) => void;
35
+ /** Élément qui rend le paginateur (il garde sa liste de taille de page) et balise de la liste (`poad-select`). */
36
+ readonly owner: Element;
37
+ readonly selectTag: string;
38
+ }
39
+
40
+ interface SizeSelect extends HTMLElement {
41
+ options?: readonly unknown[];
42
+ value?: unknown;
43
+ size?: string;
44
+ ariaLabel: string | null;
45
+ }
46
+ const sizeSelects = new WeakMap<Element, { readonly el: SizeSelect; key: string; pick: (rows: number) => void }>();
47
+
48
+ /**
49
+ * Liste de taille de page : un `<poad-select>` créé une fois par hôte et posé tel quel dans le rendu (`patch` ne
50
+ * touche pas à un nœud donné, donc ni à son contenu ni à son focus). Ses évènements (`input`, `change`, `openchange`)
51
+ * s'arrêtent à lui : seul `pagechange` sort du paginateur ou de la table.
52
+ */
53
+ function pageSizeSelect(o: PaginatorView, options: readonly number[], rows: number, label: string, pick: (rows: number) => void): Node {
54
+ let held = sizeSelects.get(o.owner);
55
+ if (!held || held.el.localName !== o.selectTag) {
56
+ const el = document.createElement(o.selectTag) as SizeSelect;
57
+ el.className = 'poad-paginator__sel';
58
+ el.size = 'sm';
59
+ held = { el, key: '', pick };
60
+ const box = held;
61
+ for (const type of ['input', 'openchange']) el.addEventListener(type, (e) => e.stopPropagation());
62
+ el.addEventListener('change', (e) => {
63
+ e.stopPropagation();
64
+ const v = (e as CustomEvent).detail;
65
+ if (v != null) box.pick(+v);
66
+ });
67
+ sizeSelects.set(o.owner, held);
68
+ }
69
+ held.pick = pick;
70
+ const key = options.join(',');
71
+ if (held.key !== key) {
72
+ held.key = key;
73
+ held.el.options = options.map((n) => ({ label: String(n), value: n }));
74
+ }
75
+ if (held.el.value !== rows) held.el.value = rows;
76
+ if (held.el.ariaLabel !== label) held.el.ariaLabel = label;
77
+ return held.el;
78
+ }
79
+
80
+ /** Le paginateur en nœud de rendu (seul, ou au pied de `<poad-table>`). Interne au paquet. */
81
+ export function paginatorView(i18n: UiI18nValue, registry: IconRegistry, o: PaginatorView): VNode {
82
+ const { t, text } = i18n;
83
+ const { first, rows, totalRecords: total } = o;
84
+ const options = o.rowsPerPageOptions ?? [10, 25, 50, 100];
85
+ const pageCount = paginatorPageCount(total, rows);
86
+ const page = paginatorPage(first, rows, pageCount);
87
+ const visible = paginatorVisible(o.alwaysShow ?? true, pageCount);
88
+ const nav = paginatorNavProps(page, pageCount);
89
+ const rppText = text(o.rowsPerPageLabel, 'paginator.rowsPerPage');
90
+ const goTo = (p: number) => {
91
+ const next = paginatorGoTo(p, { first, rows, pageCount });
92
+ if (next !== null) o.onPage(paginatorEvent(next, rows, total));
93
+ };
94
+ const changeRows = (r: number) => {
95
+ const next = paginatorChangeRows(r, { first, rows, total });
96
+ if (next) o.onPage(paginatorEvent(next.first, next.rows, total));
97
+ };
98
+ const navButton = (b: { readonly labelKey: UiMessageKey; readonly disabled: boolean; readonly to: number }, name: string) =>
99
+ h('button', { type: 'button', 'aria-label': t(b.labelKey), disabled: b.disabled, onclick: () => goTo(b.to) }, icon(registry, name, { size: 13 }));
100
+ return h('nav', { class: ['poad-paginator', { 'is-hidden': !visible }], role: 'navigation', 'aria-label': t('paginator.label') }, visible && [
101
+ options.length > 0 && h('span', { class: 'poad-paginator__rpp' }, [
102
+ h('span', {}, rppText),
103
+ pageSizeSelect(o, options, rows, rppText, changeRows),
104
+ ]),
105
+ h('span', { class: 'poad-paginator__grow' }),
106
+ (o.showCurrentPageReport ?? true) && h('span', { class: 'poad-paginator__report' }, paginatorReport(o.currentPageReportTemplate ?? t('paginator.report'), { first, rows, total })),
107
+ h('span', { class: 'poad-paginator__pages' }, [
108
+ o.showFirstLastIcon && navButton(nav.first, 'chevrons-left'),
109
+ navButton(nav.previous, 'chevron-left'),
110
+ (o.showPageLinks ?? true) && paginatorLinks(pageCount, page, o.pageLinks ?? 5).map((p) => (p < 0
111
+ ? h('span', { class: 'poad-paginator__dots', 'aria-hidden': 'true' }, '…')
112
+ : h('button', { type: 'button', class: p === page ? 'is-on' : undefined, 'aria-current': p === page ? 'page' : undefined, 'aria-label': t('paginator.page', { page: p + 1 }), onclick: () => goTo(p) }, String(p + 1)))),
113
+ navButton(nav.next, 'chevron-right'),
114
+ o.showFirstLastIcon && navButton(nav.last, 'chevrons-right'),
115
+ ]),
116
+ ]);
117
+ }
118
+
119
+ export class PoadPaginatorElement extends PoadElement {
120
+ static override props = {
121
+ first: 'number', rows: 'number', totalRecords: 'number', rowsPerPageOptions: 'json', rowsPerPageLabel: 'string', pageLinks: 'number',
122
+ showCurrentPageReport: 'boolean', currentPageReportTemplate: 'string', showFirstLastIcon: 'boolean', showPageLinks: 'boolean', alwaysShow: 'boolean',
123
+ } as const;
124
+ /** Index du premier élément de la page (à partir de 0). */
125
+ declare first?: number;
126
+ /** Taille de page (défaut 25). */
127
+ declare rows?: number;
128
+ declare totalRecords?: number;
129
+ declare rowsPerPageOptions?: readonly number[];
130
+ declare rowsPerPageLabel?: string;
131
+ declare pageLinks?: number;
132
+ declare showCurrentPageReport?: boolean;
133
+ declare currentPageReportTemplate?: string;
134
+ declare showFirstLastIcon?: boolean;
135
+ declare showPageLinks?: boolean;
136
+ declare alwaysShow?: boolean;
137
+
138
+ protected render() {
139
+ return paginatorView(this.i18n(), this.icons(), {
140
+ first: this.first ?? 0, rows: this.rows ?? 25, totalRecords: this.totalRecords ?? 0, rowsPerPageOptions: this.rowsPerPageOptions,
141
+ rowsPerPageLabel: this.rowsPerPageLabel, pageLinks: this.pageLinks, showCurrentPageReport: this.showCurrentPageReport,
142
+ currentPageReportTemplate: this.currentPageReportTemplate, showFirstLastIcon: this.showFirstLastIcon, showPageLinks: this.showPageLinks, alwaysShow: this.alwaysShow,
143
+ owner: this, selectTag: this.tag('select'),
144
+ onPage: (e) => {
145
+ this.propValues['first'] = e.first;
146
+ this.rows = e.rows;
147
+ this.emit('pagechange', e);
148
+ },
149
+ });
150
+ }
151
+ }
package/src/segmented.ts CHANGED
@@ -22,6 +22,7 @@ export class PoadSegmentedElement extends PoadFormElement {
22
22
  value: 'json', options: 'json', optionLabel: 'string', optionValue: 'string', multiple: 'boolean', allowEmpty: 'boolean', block: 'boolean',
23
23
  size: 'string', shape: 'string', disabled: 'boolean', ariaLabel: 'string', name: 'string', required: 'boolean',
24
24
  } as const;
25
+ static override functions = ['renderOption'] as const;
25
26
  declare value?: unknown;
26
27
  declare options?: readonly PoadSegmentOption[];
27
28
  declare optionLabel?: string;
@@ -36,7 +37,7 @@ export class PoadSegmentedElement extends PoadFormElement {
36
37
  declare name?: string;
37
38
  declare required?: boolean;
38
39
  /** Contenu d'une option (gabarit d'option en Angular) ; absent : icône et libellé. */
39
- renderOption?: (option: PoadSegmentOption) => string | Node;
40
+ declare renderOption?: (option: PoadSegmentOption) => string | Node;
40
41
  protected readonly resetProps = ['value'];
41
42
 
42
43
  protected formValue() {
package/src/select.ts CHANGED
@@ -15,24 +15,20 @@
15
15
  */
16
16
  import {
17
17
  FOCUS_AUTOFOCUS_ATTR, SELECT_INITIAL, SELECT_PLACEMENTS, SHEET_MOBILE_QUERY, selectEmptyMessage, selectEquals, selectFallbackLabel, selectFilterProps,
18
- selectFindOption, selectItems, selectListboxProps, selectOptionProps, selectRootClasses, selectScrollTop, selectSheetTitle, selectTransition,
18
+ selectFindOption, selectItems, selectRootClasses, selectScrollTop, selectSheetTitle, selectTransition,
19
19
  selectTriggerProps, selectUseSheet, selectVisibleItems,
20
20
  type SelectContext, type SelectEffect, type SelectEvent, type SelectMobileMode, type SelectState,
21
21
  } from '@poadio/ui-core';
22
- import { h, type Child } from './dom.js';
22
+ import { h } from './dom.js';
23
23
  import { PoadFormElement } from './element.js';
24
24
  import { FloatingTracker, Listening, Sheet, listenOutside, mediaMatches } from './floating.js';
25
25
  import { icon } from './icon.js';
26
+ import { optionList, type PoadSelectOptionContext } from './option-list.js';
26
27
 
27
28
  /** Attribut « focus initial » du piège à focus de la feuille (ui-core). */
28
29
  const autofocus = (on: boolean) => (on ? { [FOCUS_AUTOFOCUS_ATTR]: '' } : {});
29
30
 
30
- export interface PoadSelectOptionContext {
31
- readonly selected: boolean;
32
- readonly active: boolean;
33
- readonly index: number;
34
- readonly label: string;
35
- }
31
+ export type { PoadSelectOptionContext };
36
32
 
37
33
  export class PoadSelectElement extends PoadFormElement {
38
34
  static override props = {
@@ -42,6 +38,7 @@ export class PoadSelectElement extends PoadFormElement {
42
38
  size: 'string', invalid: 'boolean', disabled: 'boolean', readonly: 'boolean', panelMaxHeight: 'number', ariaLabel: 'string', mobile: 'string',
43
39
  sheetTitle: 'string', name: 'string', required: 'boolean',
44
40
  } as const;
41
+ static override functions = ['compareWith', 'renderOption', 'renderValue', 'renderEmpty'] as const;
45
42
  declare value?: unknown;
46
43
  declare options?: readonly unknown[];
47
44
  declare optionLabel?: string;
@@ -72,11 +69,11 @@ export class PoadSelectElement extends PoadFormElement {
72
69
  declare name?: string;
73
70
  declare required?: boolean;
74
71
  /** Comparaison de valeurs (objets). Défaut : `data-key`, puis `===`. */
75
- compareWith?: (a: unknown, b: unknown) => boolean;
72
+ declare compareWith?: (a: unknown, b: unknown) => boolean;
76
73
  /** Contenu d'une option, de la valeur affichée, de la liste vide (gabarits `poadSelectItem` / `Selected` / `Empty`). */
77
- renderOption?: (option: unknown, context: PoadSelectOptionContext) => string | Node;
78
- renderValue?: (option: unknown, context: { readonly label: string }) => string | Node;
79
- renderEmpty?: (context: { readonly filtered: boolean; readonly query: string }) => string | Node;
74
+ declare renderOption?: (option: unknown, context: PoadSelectOptionContext) => string | Node;
75
+ declare renderValue?: (option: unknown, context: { readonly label: string }) => string | Node;
76
+ declare renderEmpty?: (context: { readonly filtered: boolean; readonly query: string }) => string | Node;
80
77
  protected readonly resetProps = ['value'];
81
78
 
82
79
  private state: SelectState = SELECT_INITIAL;
@@ -180,24 +177,11 @@ export class PoadSelectElement extends PoadFormElement {
180
177
  const visible = selectVisibleItems(s, c);
181
178
  const filtered = !!s.query;
182
179
  const root = selectRootClasses({ open: s.open, disabled: this.inactive, readonly: this.readonly, invalid: this.invalid, focused: this.focused, hasValue: this.hasValue, size: this.size ?? 'md' });
183
- const listbox = selectListboxProps(listId);
184
- const list = h('div', { class: 'poad-optlist', role: listbox.role, id: listbox.id, style: { maxHeight: `${this.panelMaxHeight ?? 260}px` } },
185
- visible.length ? visible.map((it): Child => {
186
- if (it.kind === 'group') return h('div', { class: 'poad-optlist__group', role: 'presentation', id: it.id }, it.label);
187
- const isSel = c.isSelected(it);
188
- const o = selectOptionProps(it, { active: it.index === s.activeIndex, selected: isSel });
189
- return h('div', {
190
- id: o.id, role: o.role, class: ['poad-optlist__opt', o.classes], 'aria-selected': o['aria-selected'], 'aria-disabled': o['aria-disabled'],
191
- onpointerdown: (e: PointerEvent) => e.preventDefault(), onclick: () => !it.disabled && this.send({ type: 'pick', item: it }),
192
- onpointerenter: () => !it.disabled && this.send({ type: 'hover', index: it.index }),
193
- }, this.renderOption ? this.renderOption(it.option, { selected: isSel, active: o.classes['is-active'], index: it.index, label: it.label }) : [
194
- isSel && icon(registry, 'check', { size: 12, strokeWidth: 2.6, class: 'poad-optlist__tick' }),
195
- it.icon && icon(registry, it.icon, { size: 14, class: 'poad-optlist__icon' }),
196
- h('span', { class: 'poad-optlist__label' }, it.label),
197
- it.hint && h('span', { class: 'poad-optlist__hint' }, it.hint),
198
- ]);
199
- }) : h('div', { class: 'poad-optlist__empty', role: 'presentation' },
200
- this.renderEmpty ? this.renderEmpty({ filtered, query: s.query }) : text(filtered ? this.emptyFilterMessage : this.emptyMessage, selectEmptyMessage(filtered))));
180
+ const list = optionList({
181
+ listId, items: visible, activeIndex: s.activeIndex, isSelected: c.isSelected, maxHeight: this.panelMaxHeight ?? 260, icons: registry, renderOption: this.renderOption,
182
+ onPick: (item) => this.send({ type: 'pick', item }), onHover: (index) => this.send({ type: 'hover', index }),
183
+ empty: this.renderEmpty ? this.renderEmpty({ filtered, query: s.query }) : text(filtered ? this.emptyFilterMessage : this.emptyMessage, selectEmptyMessage(filtered)),
184
+ });
201
185
  const f = selectFilterProps(s, c, { listId });
202
186
  const panel = h('div', {
203
187
  class: ['poad-select__panel', { 'is-sheet': this.inSheet }], style: this.inSheet ? undefined : { minWidth: `${this.triggerWidth}px` },
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Préfixe des éléments que créent les services (`poadConfirm`, `poadToast`) : celui du premier `defineElements()`,
3
+ * sinon `poad`. Interne.
4
+ */
5
+ let prefix: string | null = null;
6
+
7
+ export function noteDefinedPrefix(p: string): void {
8
+ prefix ??= p;
9
+ }
10
+ export const servicePrefix = (): string => prefix ?? 'poad';
package/src/slider.ts CHANGED
@@ -23,6 +23,7 @@ export class PoadSliderElement extends PoadFormElement {
23
23
  marks: 'json', showTicks: 'boolean', disabled: 'boolean', readonly: 'boolean', invalid: 'boolean', size: 'string', severity: 'string', label: 'string',
24
24
  ariaLabel: 'string', name: 'string',
25
25
  } as const;
26
+ static override functions = ['formatValue'] as const;
26
27
  declare value?: SliderValue | null;
27
28
  declare min?: number;
28
29
  declare max?: number;
@@ -42,7 +43,7 @@ export class PoadSliderElement extends PoadFormElement {
42
43
  declare ariaLabel: string | null;
43
44
  declare name?: string;
44
45
  /** Texte d'une valeur (bulle, graduations, `aria-valuetext`). */
45
- formatValue?: (v: number) => string;
46
+ declare formatValue?: (v: number) => string;
46
47
  protected readonly resetProps = ['value'];
47
48
  private draft: SliderValue | null = null;
48
49
  private dragging: number | null = null;