@poadio/ui-core 0.1.0 → 0.2.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 (155) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +16 -0
  3. package/accordion.css +29 -0
  4. package/combo.css +43 -0
  5. package/datepicker.css +80 -0
  6. package/dialog.css +119 -0
  7. package/dist/accordion/accordion.machine.d.ts +35 -0
  8. package/dist/accordion/accordion.machine.d.ts.map +1 -0
  9. package/dist/accordion/accordion.machine.js +38 -0
  10. package/dist/accordion/accordion.machine.js.map +1 -0
  11. package/dist/accordion/index.d.ts +2 -0
  12. package/dist/accordion/index.d.ts.map +1 -0
  13. package/dist/accordion/index.js +2 -0
  14. package/dist/accordion/index.js.map +1 -0
  15. package/dist/combo/combo.machine.d.ts +106 -0
  16. package/dist/combo/combo.machine.d.ts.map +1 -0
  17. package/dist/combo/combo.machine.js +88 -0
  18. package/dist/combo/combo.machine.js.map +1 -0
  19. package/dist/combo/index.d.ts +2 -0
  20. package/dist/combo/index.d.ts.map +1 -0
  21. package/dist/combo/index.js +2 -0
  22. package/dist/combo/index.js.map +1 -0
  23. package/dist/datepicker/datepicker.machine.d.ts +223 -0
  24. package/dist/datepicker/datepicker.machine.d.ts.map +1 -0
  25. package/dist/datepicker/datepicker.machine.js +213 -0
  26. package/dist/datepicker/datepicker.machine.js.map +1 -0
  27. package/dist/datepicker/index.d.ts +2 -0
  28. package/dist/datepicker/index.d.ts.map +1 -0
  29. package/dist/datepicker/index.js +2 -0
  30. package/dist/datepicker/index.js.map +1 -0
  31. package/dist/dialog/dialog.machine.d.ts +145 -0
  32. package/dist/dialog/dialog.machine.d.ts.map +1 -0
  33. package/dist/dialog/dialog.machine.js +119 -0
  34. package/dist/dialog/dialog.machine.js.map +1 -0
  35. package/dist/dialog/index.d.ts +2 -0
  36. package/dist/dialog/index.d.ts.map +1 -0
  37. package/dist/dialog/index.js +2 -0
  38. package/dist/dialog/index.js.map +1 -0
  39. package/dist/index.d.ts +11 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +11 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/menu/index.d.ts +2 -0
  44. package/dist/menu/index.d.ts.map +1 -0
  45. package/dist/menu/index.js +2 -0
  46. package/dist/menu/index.js.map +1 -0
  47. package/dist/menu/menu.machine.d.ts +109 -0
  48. package/dist/menu/menu.machine.d.ts.map +1 -0
  49. package/dist/menu/menu.machine.js +118 -0
  50. package/dist/menu/menu.machine.js.map +1 -0
  51. package/dist/paginator/index.d.ts +2 -0
  52. package/dist/paginator/index.d.ts.map +1 -0
  53. package/dist/paginator/index.js +2 -0
  54. package/dist/paginator/index.js.map +1 -0
  55. package/dist/paginator/paginator.machine.d.ts +88 -0
  56. package/dist/paginator/paginator.machine.d.ts.map +1 -0
  57. package/dist/paginator/paginator.machine.js +82 -0
  58. package/dist/paginator/paginator.machine.js.map +1 -0
  59. package/dist/roving/index.d.ts +2 -0
  60. package/dist/roving/index.d.ts.map +1 -0
  61. package/dist/roving/index.js +2 -0
  62. package/dist/roving/index.js.map +1 -0
  63. package/dist/roving/roving.d.ts +26 -0
  64. package/dist/roving/roving.d.ts.map +1 -0
  65. package/dist/roving/roving.js +46 -0
  66. package/dist/roving/roving.js.map +1 -0
  67. package/dist/select/index.d.ts +1 -0
  68. package/dist/select/index.d.ts.map +1 -1
  69. package/dist/select/index.js +1 -0
  70. package/dist/select/index.js.map +1 -1
  71. package/dist/select/multiselect.d.ts +65 -0
  72. package/dist/select/multiselect.d.ts.map +1 -0
  73. package/dist/select/multiselect.js +70 -0
  74. package/dist/select/multiselect.js.map +1 -0
  75. package/dist/stepper/index.d.ts +2 -0
  76. package/dist/stepper/index.d.ts.map +1 -0
  77. package/dist/stepper/index.js +2 -0
  78. package/dist/stepper/index.js.map +1 -0
  79. package/dist/stepper/stepper.machine.d.ts +44 -0
  80. package/dist/stepper/stepper.machine.d.ts.map +1 -0
  81. package/dist/stepper/stepper.machine.js +48 -0
  82. package/dist/stepper/stepper.machine.js.map +1 -0
  83. package/dist/table/index.d.ts +5 -0
  84. package/dist/table/index.d.ts.map +1 -0
  85. package/dist/table/index.js +5 -0
  86. package/dist/table/index.js.map +1 -0
  87. package/dist/table/table.keyboard.d.ts +41 -0
  88. package/dist/table/table.keyboard.d.ts.map +1 -0
  89. package/dist/table/table.keyboard.js +36 -0
  90. package/dist/table/table.keyboard.js.map +1 -0
  91. package/dist/table/table.machine.d.ts +158 -0
  92. package/dist/table/table.machine.d.ts.map +1 -0
  93. package/dist/table/table.machine.js +115 -0
  94. package/dist/table/table.machine.js.map +1 -0
  95. package/dist/table/table.selection.d.ts +54 -0
  96. package/dist/table/table.selection.d.ts.map +1 -0
  97. package/dist/table/table.selection.js +95 -0
  98. package/dist/table/table.selection.js.map +1 -0
  99. package/dist/table/table.sort.d.ts +65 -0
  100. package/dist/table/table.sort.d.ts.map +1 -0
  101. package/dist/table/table.sort.js +131 -0
  102. package/dist/table/table.sort.js.map +1 -0
  103. package/dist/tabs/index.d.ts +2 -0
  104. package/dist/tabs/index.d.ts.map +1 -0
  105. package/dist/tabs/index.js +2 -0
  106. package/dist/tabs/index.js.map +1 -0
  107. package/dist/tabs/tabs.machine.d.ts +59 -0
  108. package/dist/tabs/tabs.machine.d.ts.map +1 -0
  109. package/dist/tabs/tabs.machine.js +58 -0
  110. package/dist/tabs/tabs.machine.js.map +1 -0
  111. package/dist/toast/index.d.ts +2 -0
  112. package/dist/toast/index.d.ts.map +1 -0
  113. package/dist/toast/index.js +2 -0
  114. package/dist/toast/index.js.map +1 -0
  115. package/dist/toast/toast.machine.d.ts +96 -0
  116. package/dist/toast/toast.machine.d.ts.map +1 -0
  117. package/dist/toast/toast.machine.js +79 -0
  118. package/dist/toast/toast.machine.js.map +1 -0
  119. package/menu.css +38 -0
  120. package/multiselect.css +62 -0
  121. package/package.json +23 -1
  122. package/paginator.css +23 -0
  123. package/src/accordion/accordion.machine.ts +46 -0
  124. package/src/accordion/index.ts +1 -0
  125. package/src/combo/combo.machine.ts +115 -0
  126. package/src/combo/index.ts +1 -0
  127. package/src/datepicker/datepicker.machine.ts +256 -0
  128. package/src/datepicker/index.ts +1 -0
  129. package/src/dialog/dialog.machine.ts +185 -0
  130. package/src/dialog/index.ts +1 -0
  131. package/src/index.ts +11 -0
  132. package/src/menu/index.ts +1 -0
  133. package/src/menu/menu.machine.ts +162 -0
  134. package/src/paginator/index.ts +1 -0
  135. package/src/paginator/paginator.machine.ts +89 -0
  136. package/src/roving/index.ts +1 -0
  137. package/src/roving/roving.ts +52 -0
  138. package/src/select/index.ts +1 -0
  139. package/src/select/multiselect.ts +82 -0
  140. package/src/stepper/index.ts +1 -0
  141. package/src/stepper/stepper.machine.ts +59 -0
  142. package/src/table/README.md +145 -0
  143. package/src/table/index.ts +4 -0
  144. package/src/table/table.keyboard.ts +73 -0
  145. package/src/table/table.machine.ts +150 -0
  146. package/src/table/table.selection.ts +101 -0
  147. package/src/table/table.sort.ts +120 -0
  148. package/src/tabs/index.ts +1 -0
  149. package/src/tabs/tabs.machine.ts +74 -0
  150. package/src/toast/index.ts +1 -0
  151. package/src/toast/toast.machine.ts +131 -0
  152. package/stepper.css +47 -0
  153. package/table.css +133 -0
  154. package/tabs.css +45 -0
  155. package/toast.css +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poadio/ui-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Framework-free core of the poad UI library: design tokens, base CSS and the shared component styles (switch, button, field, select, option list, icon, badge, tag, chip, avatar, divider, skeleton, progress, meter, message, checkbox, radio, segmented, toggle button, button group, number, password, rating, slider, inplace, tooltip, popover, colorpicker, bottom sheet, floating layer), named icon set and registry, message catalogue (en, fr) and i18n helpers, date helpers, the floating bricks (placement with flip / shift / arrow, focus trap, dismiss rules, scroll lock, bottom-sheet model, listbox navigation), and the state machines of the components, shared by @poadio/ui-angular and the future React, Vue and web-component packages. No DOM access at import time.",
5
5
  "license": "MIT",
6
6
  "author": "poad — Stéphane Zuccatti",
@@ -47,6 +47,17 @@
47
47
  "./tooltip.css": "./tooltip.css",
48
48
  "./popover.css": "./popover.css",
49
49
  "./colorpicker.css": "./colorpicker.css",
50
+ "./tabs.css": "./tabs.css",
51
+ "./accordion.css": "./accordion.css",
52
+ "./stepper.css": "./stepper.css",
53
+ "./menu.css": "./menu.css",
54
+ "./multiselect.css": "./multiselect.css",
55
+ "./dialog.css": "./dialog.css",
56
+ "./toast.css": "./toast.css",
57
+ "./datepicker.css": "./datepicker.css",
58
+ "./combo.css": "./combo.css",
59
+ "./paginator.css": "./paginator.css",
60
+ "./table.css": "./table.css",
50
61
  "./package.json": "./package.json"
51
62
  },
52
63
  "files": [
@@ -85,6 +96,17 @@
85
96
  "tooltip.css",
86
97
  "popover.css",
87
98
  "colorpicker.css",
99
+ "tabs.css",
100
+ "accordion.css",
101
+ "stepper.css",
102
+ "menu.css",
103
+ "multiselect.css",
104
+ "dialog.css",
105
+ "toast.css",
106
+ "datepicker.css",
107
+ "combo.css",
108
+ "paginator.css",
109
+ "table.css",
88
110
  "README.md",
89
111
  "CHANGELOG.md",
90
112
  "LICENSE"
package/paginator.css ADDED
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Paginateur (.poad-paginator) — partagé par tous les rendus : poad-paginator d'ui-angular (encapsulation désactivée),
3
+ * PoadPaginator d'ui-react. Calculs : machine `paginator` d'@poadio/ui-core.
4
+ *
5
+ * .poad-paginator (role="navigation") > label.poad-paginator__rpp > (span, span.poad-paginator__sel > select + .poad-icon),
6
+ * span.poad-paginator__grow, span.poad-paginator__report, span.poad-paginator__pages > button[.is-on] | span.poad-paginator__dots
7
+ */
8
+ .poad-paginator { display: flex; align-items: center; gap: 14px; font: var(--poad-font-size-sm) var(--poad-font); color: var(--poad-fg-secondary); }
9
+ .poad-paginator.is-hidden { display: none; }
10
+ .poad-paginator .poad-paginator__grow { flex: 1; }
11
+ .poad-paginator .poad-paginator__rpp { display: inline-flex; align-items: center; gap: 8px; }
12
+ .poad-paginator .poad-paginator__sel { position: relative; display: inline-flex; align-items: center; border: 1px solid var(--poad-border); border-radius: 6px; color: var(--poad-fg); background: var(--poad-surface); }
13
+ .poad-paginator .poad-paginator__sel > select { appearance: none; border: 0; background: transparent; color: inherit; font: inherit; padding-block: 3px; padding-inline: 8px 22px; cursor: pointer; outline: none; }
14
+ .poad-paginator .poad-paginator__sel:focus-within { border-color: var(--poad-accent); box-shadow: 0 0 0 3px var(--poad-ring); }
15
+ .poad-paginator .poad-paginator__sel > .poad-icon { position: absolute; inset-inline-end: 6px; pointer-events: none; color: var(--poad-fg-muted); }
16
+ .poad-paginator .poad-paginator__report { font-variant-numeric: tabular-nums; }
17
+ .poad-paginator .poad-paginator__pages { display: inline-flex; gap: 2px; align-items: center; }
18
+ .poad-paginator .poad-paginator__pages > button { min-width: 26px; height: 26px; padding: 0 6px; border: 0; border-radius: 6px; background: transparent; color: var(--poad-fg-secondary); font: 500 var(--poad-font-size-sm) var(--poad-font); cursor: pointer; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
19
+ .poad-paginator .poad-paginator__pages > button.is-on { background: var(--poad-accent-soft); color: var(--poad-accent); }
20
+ .poad-paginator .poad-paginator__pages > button:hover:not(.is-on):not([disabled]) { background: var(--poad-hover); color: var(--poad-fg); }
21
+ .poad-paginator .poad-paginator__pages > button[disabled] { opacity: .4; cursor: default; }
22
+ .poad-paginator .poad-paginator__pages > button:focus-visible { outline: 2px solid var(--poad-ring); outline-offset: -1px; }
23
+ .poad-paginator .poad-paginator__dots { min-width: 20px; text-align: center; color: var(--poad-fg-muted); }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Accordéon (accordion) — la logique, sans framework ni DOM.
3
+ *
4
+ * Des panneaux à en-tête `<button aria-expanded>` (dans un titre `h3`) et région `role="region"` (WAI-ARIA, motif
5
+ * « accordion ») ; un seul ouvert à la fois, ou plusieurs (`multiple`). La valeur ouverte est celle d'un panneau
6
+ * (`string`), ou un tableau en `multiple`, ou `null`. Clavier entre en-têtes : ↓ / ↑ (en boucle), Début, Fin ;
7
+ * Entrée / Espace : le clic natif du bouton. Un panneau fermé est `inert` (contenu hors tabulation).
8
+ */
9
+ import { rovingKeyTarget } from '../roving/roving.js';
10
+
11
+ export type AccordionValue = string | readonly string[] | null | undefined;
12
+
13
+ /** Panneaux ouverts. */
14
+ export const accordionOpenSet = (value: AccordionValue): ReadonlySet<string> =>
15
+ new Set(value == null ? [] : Array.isArray(value) ? (value as readonly string[]) : [value as string]);
16
+
17
+ export const accordionIsOpen = (value: AccordionValue, panel: string): boolean => accordionOpenSet(value).has(panel);
18
+
19
+ /**
20
+ * Valeur après l'ouverture (`open`) ou la fermeture du panneau `panel`. Rend la MÊME valeur quand rien ne change ;
21
+ * en choix unique, ouvrir un panneau ferme l'autre.
22
+ */
23
+ export function accordionSet(value: AccordionValue, panel: string, open: boolean, multiple = false): string | string[] | null | AccordionValue {
24
+ if (open === accordionIsOpen(value, panel)) return value;
25
+ if (multiple) {
26
+ const s = new Set(accordionOpenSet(value));
27
+ if (open) s.add(panel);
28
+ else s.delete(panel);
29
+ return [...s];
30
+ }
31
+ return open ? panel : null;
32
+ }
33
+
34
+ /** Touche sur un en-tête : rang de l'en-tête à focaliser parmi `panels`, ou `null`. */
35
+ export const accordionKeydown = (panels: readonly { readonly disabled?: boolean }[], from: number, key: string): number | null =>
36
+ rovingKeyTarget(panels, from, key, { orientation: 'vertical' });
37
+
38
+ /** Attributs de l'en-tête (`<button>`) et de la région d'un panneau d'identifiant `id`. */
39
+ export const accordionHeaderProps = (id: string, open: boolean, disabled = false) =>
40
+ ({ id: `${id}-h`, 'aria-expanded': open ? 'true' : 'false', 'aria-controls': `${id}-c`, disabled }) as const;
41
+ export const accordionRegionProps = (id: string, open: boolean) =>
42
+ ({ id: `${id}-c`, role: 'region', 'aria-labelledby': `${id}-h`, inert: open ? null : '' }) as const;
43
+
44
+ /** Classes d'un panneau `.poad-accordion-panel` et de la racine `.poad-accordion`. */
45
+ export const accordionPanelClasses = (open: boolean, disabled = false) => ({ 'is-open': open, 'is-disabled': disabled });
46
+ export const accordionRootClasses = (flush = false) => ({ 'is-flush': flush });
@@ -0,0 +1 @@
1
+ export * from './accordion.machine.js';
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Saisie avec suggestions (combo, « autocomplete ») — la logique, sans framework ni DOM.
3
+ *
4
+ * Un champ `role="combobox"` (`aria-autocomplete="list"`) et une liste de suggestions `role="listbox"` (WAI-ARIA,
5
+ * motif « combobox à liste »). La frappe déclenche une recherche (au-delà de `minLength`, après `delay`) : suggestions
6
+ * données (filtrées sans accents ni casse sur le libellé) ou rendues par une fonction de l'application (le rendu
7
+ * l'appelle et garde la dernière réponse). Clavier : ↓ ouvre (recherche du texte courant) ou descend, ↑ monte (en
8
+ * boucle), Entrée choisit l'active, Échap ferme, Tab ferme ; en choix multiple, Retour arrière dans un champ vide
9
+ * retire la dernière puce. Texte libre, ou `forceSelection` : à la sortie, un texte qui n'est pas celui d'une
10
+ * suggestion choisie est effacé.
11
+ */
12
+ import { listboxNormalize } from '../listbox/listbox.nav.js';
13
+ import { selectResolve } from '../select/select.machine.js';
14
+
15
+ /** Libellé d'une suggestion : primitive telle quelle, objet par son chemin (défaut `label`). */
16
+ export const comboLabel = (o: unknown, path = 'label'): string => (o != null && typeof o === 'object' ? String(selectResolve(o, path) ?? '') : String(o ?? ''));
17
+
18
+ /** Suggestions données par l'application, filtrées sur le libellé (sans accents ni casse). */
19
+ export const comboFilter = <T>(source: readonly T[] | null | undefined, query: string, path = 'label'): T[] => {
20
+ const q = listboxNormalize(query);
21
+ return (source ?? []).filter((o) => listboxNormalize(comboLabel(o, path)).includes(q));
22
+ };
23
+
24
+ /** Valeurs en choix multiple. */
25
+ export const comboValues = (value: unknown, multiple: boolean): unknown[] => (multiple && Array.isArray(value) ? value : []);
26
+ export const comboIsSelected = (value: unknown, o: unknown, multiple: boolean): boolean => (multiple ? comboValues(value, true).includes(o) : value === o);
27
+
28
+ /** Texte du champ pour une valeur imposée (choix unique) : le libellé d'un objet, la valeur elle-même sinon. */
29
+ export const comboTextOf = (value: unknown, path = 'label'): string => (value == null ? '' : typeof value === 'object' ? comboLabel(value, path) : String(value));
30
+
31
+ /** Frappe : lancer une recherche, ou fermer (texte trop court). */
32
+ export const comboInput = (text: string, minLength = 1): 'search' | 'close' => (text.length < minLength ? 'close' : 'search');
33
+
34
+ export interface ComboKeyState {
35
+ readonly open: boolean;
36
+ readonly active: number;
37
+ readonly count: number;
38
+ readonly multiple?: boolean;
39
+ readonly text: string;
40
+ readonly valuesCount?: number;
41
+ }
42
+
43
+ export type ComboKeyAction =
44
+ | { readonly type: 'search' }
45
+ | { readonly type: 'move'; readonly active: number }
46
+ | { readonly type: 'pick'; readonly index: number }
47
+ | { readonly type: 'close' }
48
+ | { readonly type: 'remove-last' }
49
+ | { readonly type: 'none' };
50
+
51
+ /** Touche dans le champ : l'action, et si le rendu doit empêcher le comportement par défaut. */
52
+ export function comboKeydown(s: ComboKeyState, key: string): { readonly action: ComboKeyAction; readonly preventDefault: boolean } {
53
+ const none = { action: { type: 'none' } as const, preventDefault: false };
54
+ switch (key) {
55
+ case 'ArrowDown':
56
+ if (!s.open) return { action: { type: 'search' }, preventDefault: true };
57
+ return { action: s.count ? { type: 'move', active: (s.active + 1) % s.count } : { type: 'none' }, preventDefault: true };
58
+ case 'ArrowUp':
59
+ return { action: s.open && s.count ? { type: 'move', active: (s.active - 1 + s.count) % s.count } : { type: 'none' }, preventDefault: true };
60
+ case 'Enter':
61
+ return s.open && s.active >= 0 ? { action: { type: 'pick', index: s.active }, preventDefault: true } : none;
62
+ case 'Escape':
63
+ return s.open ? { action: { type: 'close' }, preventDefault: true } : none;
64
+ case 'Tab':
65
+ return { action: { type: 'close' }, preventDefault: false };
66
+ case 'Backspace':
67
+ return s.multiple && !s.text && (s.valuesCount ?? 0) > 0 ? { action: { type: 'remove-last' }, preventDefault: false } : none;
68
+ }
69
+ return none;
70
+ }
71
+
72
+ /** Réponse d'une recherche : suggestions montrées, la première active ; le panneau s'ouvre s'il était fermé. */
73
+ export const comboResults = (count: number): { readonly active: number; readonly open: true } => ({ active: count ? 0 : -1, open: true });
74
+
75
+ /**
76
+ * Choix d'une suggestion : la valeur suivante (ajoutée en choix multiple, sans doublon), le texte du champ, et si la
77
+ * valeur change.
78
+ */
79
+ export function comboPick(value: unknown, o: unknown, o2: { readonly multiple?: boolean; readonly labelPath?: string }): { readonly value: unknown; readonly text: string; readonly changed: boolean } {
80
+ if (o2.multiple) {
81
+ const cur = comboValues(value, true);
82
+ return cur.includes(o) ? { value: cur, text: '', changed: false } : { value: [...cur, o], text: '', changed: true };
83
+ }
84
+ return { value: o, text: comboLabel(o, o2.labelPath), changed: true };
85
+ }
86
+
87
+ /**
88
+ * Sortie du champ (choix unique). `forceSelection` : un texte qui n'est pas le libellé de la valeur est effacé (et la
89
+ * valeur avec) ; texte libre : le texte devient la valeur. Rend ce qu'il faut écrire, ou `null`.
90
+ */
91
+ export function comboBlur(value: unknown, text: string, o: { readonly forceSelection?: boolean; readonly multiple?: boolean; readonly labelPath?: string }): { readonly text?: string; readonly value?: unknown } | null {
92
+ if (o.multiple) return null;
93
+ if (o.forceSelection) {
94
+ const ok = value != null && comboLabel(value, o.labelPath) === text;
95
+ if (ok) return null;
96
+ return value != null ? { text: '', value: null } : { text: '' };
97
+ }
98
+ return text !== (value ?? '') ? { value: text || null } : null;
99
+ }
100
+
101
+ /** Attributs du champ. */
102
+ export const comboInputProps = (o: { readonly open: boolean; readonly listId: string; readonly active: number; readonly invalid?: boolean }) =>
103
+ ({
104
+ role: 'combobox', 'aria-autocomplete': 'list', 'aria-expanded': o.open ? 'true' : 'false', 'aria-controls': o.listId,
105
+ 'aria-activedescendant': o.open && o.active >= 0 ? `${o.listId}-${o.active}` : null, 'aria-invalid': o.invalid ? 'true' : null,
106
+ }) as const;
107
+
108
+ /** Attributs et classes d'une suggestion. */
109
+ export const comboOptionProps = (listId: string, index: number, active: boolean, selected: boolean) =>
110
+ ({ id: `${listId}-${index}`, role: 'option', 'aria-selected': selected ? 'true' : 'false', classes: { 'is-active': active, 'is-on': selected } }) as const;
111
+
112
+ /** Classes de la racine `.poad-combo`. */
113
+ export const comboRootClasses = (o: { readonly open: boolean; readonly disabled?: boolean; readonly invalid?: boolean; readonly size?: 'sm' | 'md' | 'lg' }) => ({
114
+ 'is-open': o.open, 'is-disabled': !!o.disabled, 'is-invalid': !!o.invalid, 'size-sm': o.size === 'sm', 'size-lg': o.size === 'lg',
115
+ });
@@ -0,0 +1 @@
1
+ export * from './combo.machine.js';
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Sélecteur de date (datepicker) — la logique, sans framework ni DOM. Calcul de dates : `date-utils` du socle et
3
+ * `Intl` (noms de mois et de jours, libellés des jours, format par défaut) dans la langue courante.
4
+ *
5
+ * Calendrier en grille `role="grid"` (WAI-ARIA, motif « date picker dialog ») : 6 semaines à partir du premier jour de
6
+ * la semaine de la langue ; un seul jour atteignable à la tabulation (celui qui a le focus) ; ← → (jour), ↑ ↓
7
+ * (semaine), Page↑ / Page↓ (mois ; avec Maj : année), Début / Fin (début / fin de semaine) déplacent le focus, en
8
+ * changeant de mois si besoin ; Entrée / Espace choisissent. Vues mois et années (12 cases). Choix unique, intervalle
9
+ * (`range` : deux clics, dans n'importe quel ordre) ou plusieurs dates (`multiple`, triées). Bornes `min` / `max`,
10
+ * jours et jours de semaine désactivés. Heure (heures, minutes au pas, secondes, 12 / 24 h selon la langue). Saisie
11
+ * au clavier lue selon le format. Valeur : `Date`, ou ISO local (`yyyy-MM-dd`, `…THH:mm`, `HH:mm`, `yyyy-MM`, `yyyy`).
12
+ */
13
+ import {
14
+ addDays, addMonths, addYears, compareDay, daysInMonth, formatDate, isBetweenDay, isSameDay, isoOf, isoWeek, localeDateFormat, monthNames, parseWithFormat,
15
+ startOfDay, startOfMonth, toDate, weekdayNames,
16
+ } from '../date/date-utils.js';
17
+
18
+ export type DateMode = 'date' | 'datetime' | 'time' | 'month' | 'year';
19
+ export type DateSelection = 'single' | 'range' | 'multiple';
20
+ export type DateView = 'days' | 'months' | 'years';
21
+ export type DateValue = Date | string | null | (Date | string | null)[];
22
+
23
+ export interface DayCell {
24
+ readonly date: Date;
25
+ readonly key: string;
26
+ readonly day: number;
27
+ readonly out: boolean;
28
+ readonly today: boolean;
29
+ readonly sel: boolean;
30
+ readonly inRange: boolean;
31
+ readonly rangeStart: boolean;
32
+ readonly rangeEnd: boolean;
33
+ readonly disabled: boolean;
34
+ readonly label: string;
35
+ readonly week: number;
36
+ }
37
+
38
+ /** Ce qui rend un jour indisponible. */
39
+ export interface DateLimits {
40
+ readonly min?: Date | null;
41
+ readonly max?: Date | null;
42
+ /** Jours de semaine désactivés (0 = dimanche … 6 = samedi). */
43
+ readonly disabledDays?: readonly number[];
44
+ /** Dates désactivées (clés `yyyy-MM-dd`, `isoOf`). */
45
+ readonly disabledKeys?: ReadonlySet<string>;
46
+ }
47
+
48
+ /** Clés `yyyy-MM-dd` des dates désactivées données par l'application. */
49
+ export const datepickerDisabledKeys = (dates: readonly (Date | string)[] | null | undefined): Set<string> =>
50
+ new Set((dates ?? []).map((d) => toDate(d)).filter((d): d is Date => !!d).map((d) => isoOf(d)));
51
+
52
+ export function datepickerDayDisabled(d: Date, l: DateLimits): boolean {
53
+ if (l.min && compareDay(d, l.min) < 0) return true;
54
+ if (l.max && compareDay(d, l.max) > 0) return true;
55
+ if (l.disabledDays?.includes(d.getDay())) return true;
56
+ return !!l.disabledKeys?.has(isoOf(d));
57
+ }
58
+ export function datepickerMonthDisabled(year: number, month: number, l: DateLimits): boolean {
59
+ const s = new Date(year, month, 1), e = new Date(year, month, daysInMonth(year, month));
60
+ return (!!l.min && compareDay(e, l.min) < 0) || (!!l.max && compareDay(s, l.max) > 0);
61
+ }
62
+ export const datepickerYearDisabled = (year: number, l: DateLimits): boolean => (!!l.min && year < l.min.getFullYear()) || (!!l.max && year > l.max.getFullYear());
63
+
64
+ /** Dates de la valeur (une, un intervalle, plusieurs), lues (`Date` ou ISO). */
65
+ export const datepickerSelected = (value: DateValue | undefined): Date[] =>
66
+ (Array.isArray(value) ? value : [value]).map((x) => toDate(x)).filter((d): d is Date => !!d);
67
+
68
+ /** Le mode effectif : `date` avec heure → `datetime`. */
69
+ export const datepickerEffectiveMode = (mode: DateMode, showTime = false): DateMode => (mode === 'date' && showTime ? 'datetime' : mode);
70
+ export const datepickerHasTime = (mode: DateMode, showTime = false): boolean => mode === 'datetime' || mode === 'time' || (mode === 'date' && showTime);
71
+ /** Vue d'ouverture selon le mode. */
72
+ export const datepickerInitialView = (mode: DateMode): DateView => (mode === 'year' ? 'years' : mode === 'month' ? 'months' : 'days');
73
+
74
+ /** Format d'affichage : celui de l'application, sinon selon le mode, la langue et le cycle horaire. */
75
+ export function datepickerFormat(o: { readonly format?: string | null; readonly mode: DateMode; readonly showTime?: boolean; readonly hours: 12 | 24; readonly showSeconds?: boolean; readonly locale: string }): string {
76
+ if (o.format) return o.format;
77
+ const t = o.hours === 12 ? 'hh:mm' + (o.showSeconds ? ':ss' : '') + ' a' : 'HH:mm' + (o.showSeconds ? ':ss' : '');
78
+ switch (datepickerEffectiveMode(o.mode, o.showTime)) {
79
+ case 'datetime': return localeDateFormat(o.locale) + ' ' + t;
80
+ case 'time': return t;
81
+ case 'month': return localeDateFormat(o.locale, 'month');
82
+ case 'year': return 'yyyy';
83
+ default: return localeDateFormat(o.locale);
84
+ }
85
+ }
86
+
87
+ /** Texte du champ : une date, un intervalle (`début – fin`, `début – …` en cours), ou des dates jointes. */
88
+ export function datepickerDisplay(selected: readonly Date[], fmt: string, selection: DateSelection): string {
89
+ if (selection === 'range') return selected.length ? formatDate(selected[0], fmt) + (selected[1] ? ' – ' + formatDate(selected[1], fmt) : ' – …') : '';
90
+ if (selection === 'multiple') return selected.map((d) => formatDate(d, fmt)).join(', ');
91
+ return formatDate(selected[0], fmt);
92
+ }
93
+
94
+ /**
95
+ * Lecture de la saisie au clavier : les dates lues, `[]` pour un champ vidé, ou `null` (rien de lisible : ne rien
96
+ * changer). Un jour indisponible n'est pas pris (choix unique).
97
+ */
98
+ export function datepickerParse(raw: string, fmt: string, selection: DateSelection, current: readonly Date[], limits: DateLimits = {}): Date[] | null {
99
+ if (!raw.trim()) return [];
100
+ if (selection === 'single') {
101
+ const d = parseWithFormat(raw, fmt, current[0]);
102
+ return d && !datepickerDayDisabled(d, limits) ? [d] : null;
103
+ }
104
+ const parts = selection === 'range' ? raw.split(/\s*[–-]\s*(?=\d)/).filter(Boolean) : raw.split(',');
105
+ const ds = parts.map((p) => parseWithFormat(p, fmt)).filter((d): d is Date => !!d);
106
+ return ds.length ? (selection === 'range' ? ds.slice(0, 2) : ds) : null;
107
+ }
108
+
109
+ /** Noms courts des jours (deux lettres), à partir du premier jour de la semaine. */
110
+ export const datepickerWeekdays = (locale: string, firstDay: number): string[] =>
111
+ weekdayNames(locale, firstDay, 'short').map((w) => w.replace('.', '').slice(0, 2));
112
+ export const datepickerMonths = (locale: string): string[] => monthNames(locale, 'short');
113
+ export const datepickerMonthLabel = (locale: string, viewDate: Date): string => monthNames(locale, 'long')[viewDate.getMonth()]!;
114
+ /** Première année de la vue des années (12 cases). */
115
+ export const datepickerDecadeStart = (viewDate: Date): number => Math.floor(viewDate.getFullYear() / 12) * 12;
116
+ export const datepickerYears = (viewDate: Date): number[] => Array.from({ length: 12 }, (_, i) => datepickerDecadeStart(viewDate) + i);
117
+
118
+ /** Les 6 semaines du mois de `viewDate`, à partir du premier jour de la semaine. */
119
+ export function datepickerRows(o: {
120
+ readonly viewDate: Date; readonly firstDay: number; readonly selected: readonly Date[]; readonly selection: DateSelection; readonly today: Date;
121
+ readonly limits?: DateLimits; readonly locale: string;
122
+ }): DayCell[][] {
123
+ const first = startOfMonth(o.viewDate);
124
+ const lead = (first.getDay() - o.firstDay + 7) % 7;
125
+ const start = addDays(first, -lead);
126
+ const sel = o.selected, range = o.selection === 'range';
127
+ const lf = new Intl.DateTimeFormat(o.locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' });
128
+ const rows: DayCell[][] = [];
129
+ for (let r = 0; r < 6; r++) {
130
+ const row: DayCell[] = [];
131
+ for (let c = 0; c < 7; c++) {
132
+ const date = addDays(start, r * 7 + c);
133
+ row.push({
134
+ date, key: isoOf(date), day: date.getDate(), out: date.getMonth() !== o.viewDate.getMonth(), today: isSameDay(date, o.today), sel: sel.some((s) => isSameDay(s, date)),
135
+ inRange: range && sel.length === 2 && isBetweenDay(date, sel[0]!, sel[1]!), rangeStart: range && sel.length >= 1 && isSameDay(date, sel[0]),
136
+ rangeEnd: range && sel.length === 2 && isSameDay(date, sel[1]), disabled: datepickerDayDisabled(date, o.limits ?? {}), label: lf.format(date), week: isoWeek(date),
137
+ });
138
+ }
139
+ rows.push(row);
140
+ }
141
+ return rows;
142
+ }
143
+
144
+ /** Survol pendant le choix d'un intervalle : jours entre la première date et le jour survolé. */
145
+ export const datepickerHoverInRange = (d: Date, selected: readonly Date[], hover: Date | null, selection: DateSelection): boolean =>
146
+ selection === 'range' && selected.length === 1 && !!hover && isBetweenDay(d, selected[0]!, hover) && !isSameDay(d, selected[0]);
147
+
148
+ /**
149
+ * Touche dans la grille des jours (WAI-ARIA) : le jour qui prend le focus (`move`), le choix du jour qui a le focus
150
+ * (`pick`), ou `null` (touche sans effet).
151
+ */
152
+ export function datepickerGridKey(focus: Date, key: string, o: { readonly shiftKey?: boolean; readonly firstDay: number; readonly rtl?: boolean }): { readonly move: Date } | { readonly pick: true } | null {
153
+ const dir = o.rtl ? -1 : 1;
154
+ switch (key) {
155
+ case 'ArrowLeft': return { move: addDays(focus, -dir) };
156
+ case 'ArrowRight': return { move: addDays(focus, dir) };
157
+ case 'ArrowUp': return { move: addDays(focus, -7) };
158
+ case 'ArrowDown': return { move: addDays(focus, 7) };
159
+ case 'PageUp': return { move: o.shiftKey ? addYears(focus, -1) : addMonths(focus, -1) };
160
+ case 'PageDown': return { move: o.shiftKey ? addYears(focus, 1) : addMonths(focus, 1) };
161
+ case 'Home': return { move: addDays(focus, -((focus.getDay() - o.firstDay + 7) % 7)) };
162
+ case 'End': return { move: addDays(focus, 6 - ((focus.getDay() - o.firstDay + 7) % 7)) };
163
+ case 'Enter': case ' ': return { pick: true };
164
+ default: return null;
165
+ }
166
+ }
167
+
168
+ /** Le mois affiché doit-il changer pour montrer `d` ? Le premier du mois de `d`, sinon `null`. */
169
+ export const datepickerFollow = (viewDate: Date, d: Date): Date | null =>
170
+ d.getMonth() !== viewDate.getMonth() || d.getFullYear() !== viewDate.getFullYear() ? startOfMonth(d) : null;
171
+
172
+ /** Flèches de l'en-tête : la vue suivante ou précédente (mois, année, ou douze ans) et ce qu'il faut signaler. */
173
+ export function datepickerNavigate(view: DateView, viewDate: Date, dir: 1 | -1): { readonly viewDate: Date; readonly month?: { readonly month: number; readonly year: number }; readonly year?: number } {
174
+ if (view === 'days') { const nd = addMonths(viewDate, dir); return { viewDate: startOfMonth(nd), month: { month: nd.getMonth(), year: nd.getFullYear() } }; }
175
+ if (view === 'months') { const nd = addYears(viewDate, dir); return { viewDate: startOfMonth(nd), year: nd.getFullYear() }; }
176
+ return { viewDate: startOfMonth(addYears(viewDate, dir * 12)) };
177
+ }
178
+ /** Clés du catalogue des flèches de l'en-tête. */
179
+ export const datepickerNavLabels = (view: DateView) =>
180
+ view === 'years' ? { prev: 'date.previousDecade', next: 'date.nextDecade' } as const
181
+ : view === 'months' ? { prev: 'date.previousYear', next: 'date.nextYear' } as const
182
+ : { prev: 'date.previousMonth', next: 'date.nextMonth' } as const;
183
+
184
+ /**
185
+ * Choix du jour `d` : les dates suivantes (heure appliquée par `withTime`) et s'il faut fermer. Intervalle : un premier
186
+ * clic (re)commence, le second complète dans l'ordre ; plusieurs : bascule, triées.
187
+ */
188
+ export function datepickerPickDay(selected: readonly Date[], d: Date, selection: DateSelection, withTime: (d: Date) => Date): { readonly dates: Date[]; readonly complete: boolean } {
189
+ const t = withTime(d);
190
+ if (selection === 'single') return { dates: [t], complete: true };
191
+ if (selection === 'range') {
192
+ if (selected.length !== 1) return { dates: [t], complete: false };
193
+ const a = selected[0]!;
194
+ return { dates: compareDay(t, a) < 0 ? [t, withTime(a)] : [withTime(a), t], complete: true };
195
+ }
196
+ const i = selected.findIndex((s) => isSameDay(s, d));
197
+ return { dates: i >= 0 ? selected.filter((_, k) => k !== i) : [...selected, t].sort((x, y) => x.getTime() - y.getTime()), complete: false };
198
+ }
199
+
200
+ /** Fermer après un choix ? `closeOnSelect` s'il est donné ; sinon oui, sauf plusieurs dates ou avec l'heure. */
201
+ export const datepickerShouldClose = (closeOnSelect: boolean | null | undefined, selection: DateSelection, hasTime: boolean): boolean =>
202
+ closeOnSelect ?? (selection !== 'multiple' && !hasTime);
203
+
204
+ /** La valeur à écrire : `Date` (`dataType: 'date'`) ou ISO local selon le mode ; une date, ou un tableau. */
205
+ export function datepickerValue(dates: readonly Date[], o: { readonly selection: DateSelection; readonly dataType: 'date' | 'string'; readonly mode: DateMode; readonly showSeconds?: boolean }): DateValue {
206
+ const conv = (d: Date): Date | string => (o.dataType === 'date' ? d : isoOf(d, o.mode, o.showSeconds));
207
+ return o.selection === 'single' ? (dates[0] ? conv(dates[0]) : null) : dates.map(conv);
208
+ }
209
+
210
+ /** La date `d` à l'heure donnée (sans heure : début du jour). */
211
+ export const datepickerWithTime = (d: Date, time: { readonly h: number; readonly m: number; readonly s: number } | null, showSeconds = false): Date =>
212
+ time ? new Date(d.getFullYear(), d.getMonth(), d.getDate(), time.h, time.m, showSeconds ? time.s : 0) : startOfDay(d);
213
+
214
+ /** Flèche d'un champ d'heure : heures en boucle sur 24, minutes au pas (arrondies au pas), secondes en boucle. */
215
+ export function datepickerBumpTime(time: { readonly h: number; readonly m: number; readonly s: number }, part: 'h' | 'm' | 's', dir: 1 | -1, stepMinute = 1) {
216
+ if (part === 'h') return { ...time, h: (time.h + dir + 24) % 24 };
217
+ if (part === 'm') { const step = Math.max(1, stepMinute); return { ...time, m: ((Math.round(time.m / step) * step) + dir * step + 60) % 60 }; }
218
+ return { ...time, s: (time.s + dir + 60) % 60 };
219
+ }
220
+ /** Saisie d'un champ d'heure (12 h : l'après-midi est gardé), bornée ; `null` si illisible. */
221
+ export function datepickerTimeFromInput(time: { readonly h: number; readonly m: number; readonly s: number }, part: 'h' | 'm' | 's', raw: string, hours: 12 | 24) {
222
+ const n = parseInt(raw, 10);
223
+ if (Number.isNaN(n)) return null;
224
+ if (part === 'h') { const h = hours === 12 ? (n % 12) + (time.h >= 12 ? 12 : 0) : n; return { ...time, h: Math.min(23, Math.max(0, h)) }; }
225
+ if (part === 'm') return { ...time, m: Math.min(59, Math.max(0, n)) };
226
+ return { ...time, s: Math.min(59, Math.max(0, n)) };
227
+ }
228
+ /** Heure affichée (1 à 12 en 12 h). */
229
+ export const datepickerHourDisplay = (h: number, hours: 12 | 24): number => (hours === 12 ? h % 12 || 12 : h);
230
+
231
+ /** Attributs d'un jour de la grille. `focused` : le seul jour à `tabindex="0"`. */
232
+ export const datepickerDayProps = (c: DayCell, focused: boolean, hoverRange = false) =>
233
+ ({
234
+ role: 'gridcell', 'data-key': c.key, 'aria-selected': c.sel ? 'true' : 'false', 'aria-label': c.label, 'aria-disabled': c.disabled ? 'true' : null,
235
+ disabled: c.disabled, tabindex: focused ? 0 : -1,
236
+ classes: {
237
+ 'is-out': c.out, 'is-today': c.today, 'is-sel': c.sel, 'in-range': c.inRange, 'range-start': c.rangeStart, 'range-end': c.rangeEnd, 'is-hover-range': hoverRange,
238
+ },
239
+ }) as const;
240
+
241
+ /** Attributs du champ (`combobox` qui ouvre un dialogue) et du panneau. */
242
+ export const datepickerInputProps = (o: { readonly id: string; readonly open: boolean; readonly invalid?: boolean }) =>
243
+ ({ id: o.id, role: 'combobox', 'aria-haspopup': 'dialog', 'aria-expanded': o.open ? 'true' : 'false', 'aria-controls': o.open ? `${o.id}-panel` : null, 'aria-invalid': o.invalid ? 'true' : null }) as const;
244
+ export const datepickerPanelProps = (id: string, mode: DateMode) =>
245
+ ({ id: `${id}-panel`, role: 'dialog', 'aria-modal': 'false', labelKey: mode === 'time' ? 'date.chooseTime' : 'date.chooseDate' }) as const;
246
+
247
+ /** Classes de la racine `.poad-datepicker`. */
248
+ export const datepickerRootClasses = (o: { readonly open: boolean; readonly disabled?: boolean; readonly invalid?: boolean; readonly inline?: boolean; readonly size?: 'sm' | 'md' | 'lg' }) => ({
249
+ 'is-open': o.open, 'is-disabled': !!o.disabled, 'is-invalid': !!o.invalid, 'is-inline': !!o.inline, 'size-sm': o.size === 'sm', 'size-lg': o.size === 'lg',
250
+ });
251
+
252
+ /** Positions du panneau : sous le champ (début), au-dessus, puis alignées sur la fin ; à 6 px. */
253
+ export const DATEPICKER_PLACEMENTS = [
254
+ { side: 'bottom', align: 'start' }, { side: 'top', align: 'start' }, { side: 'bottom', align: 'end' }, { side: 'top', align: 'end' },
255
+ ] as const;
256
+ export const DATEPICKER_OFFSET = 6;
@@ -0,0 +1 @@
1
+ export * from './datepicker.machine.js';