@directo-ui/astro 1.0.0 → 1.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 (77) hide show
  1. package/README.md +16 -0
  2. package/components.css +661 -0
  3. package/index.d.ts +31 -31
  4. package/index.js +31 -31
  5. package/package.json +29 -7
  6. package/src/components/Accordion.astro +8 -8
  7. package/src/components/AccordionItem.astro +14 -14
  8. package/src/components/Alert.astro +42 -42
  9. package/src/components/Avatar.astro +21 -21
  10. package/src/components/Badge.astro +13 -13
  11. package/src/components/BottomSheet.astro +23 -23
  12. package/src/components/Breadcrumb.astro +18 -18
  13. package/src/components/Button.astro +31 -31
  14. package/src/components/Card.astro +25 -25
  15. package/src/components/Checkbox.astro +14 -14
  16. package/src/components/DatePicker.astro +25 -25
  17. package/src/components/Divider.astro +11 -11
  18. package/src/components/Dropdown.astro +71 -71
  19. package/src/components/EmptyState.astro +15 -15
  20. package/src/components/IconButton.astro +18 -18
  21. package/src/components/Modal.astro +34 -34
  22. package/src/components/MultiSelect.astro +108 -0
  23. package/src/components/Pagination.astro +30 -30
  24. package/src/components/Progress.astro +20 -20
  25. package/src/components/RadioGroup.astro +24 -24
  26. package/src/components/Select.astro +29 -29
  27. package/src/components/Skeleton.astro +13 -13
  28. package/src/components/Spinner.astro +17 -17
  29. package/src/components/StatusTag.astro +18 -0
  30. package/src/components/Switch.astro +13 -13
  31. package/src/components/Tabs.astro +60 -60
  32. package/src/components/TextField.astro +24 -24
  33. package/src/components/Textarea.astro +41 -41
  34. package/src/components/Toaster.astro +8 -8
  35. package/src/components/Tooltip.astro +31 -31
  36. package/src/components/WariClientDetails.astro +87 -0
  37. package/src/components/WariClientSearch.astro +88 -0
  38. package/src/components/WariDateField.astro +56 -0
  39. package/src/components/WariPassengerField.astro +84 -0
  40. package/src/components/WariRoute.astro +49 -0
  41. package/src/components/WariSchedule.astro +48 -0
  42. package/src/components/WariSelect.astro +76 -0
  43. package/src/components/WariServiceMeta.astro +19 -0
  44. package/src/components/WariStatusSelect.astro +20 -0
  45. package/src/components/WariStepper.astro +45 -0
  46. package/src/components/WariSwitchList.astro +111 -0
  47. package/src/components/WariTimeField.astro +50 -0
  48. package/src/components/WariTripAttributes.astro +60 -0
  49. package/src/modal.d.ts +3 -3
  50. package/src/modal.js +39 -39
  51. package/src/pagination.d.ts +2 -2
  52. package/src/pagination.js +16 -16
  53. package/src/toast.d.ts +9 -9
  54. package/src/toast.js +66 -66
  55. package/src/wari/datetime.d.ts +57 -0
  56. package/src/wari/datetime.js +151 -0
  57. package/src/wari/logic.d.ts +8 -0
  58. package/src/wari/logic.js +41 -0
  59. package/src/wari/motion.d.ts +14 -0
  60. package/src/wari/motion.js +60 -0
  61. package/src/wari/multiselect.d.ts +2 -0
  62. package/src/wari/multiselect.js +169 -0
  63. package/src/wari/pickers.d.ts +2 -0
  64. package/src/wari/pickers.js +369 -0
  65. package/src/wari/route-client.d.ts +10 -0
  66. package/src/wari/route-client.js +270 -0
  67. package/src/wari/route.d.ts +48 -0
  68. package/src/wari/route.js +71 -0
  69. package/src/wari/statuses.d.ts +14 -0
  70. package/src/wari/statuses.js +15 -0
  71. package/src/wari/trip-client.d.ts +4 -0
  72. package/src/wari/trip-client.js +370 -0
  73. package/src/wari/trip.d.ts +107 -0
  74. package/src/wari/trip.js +129 -0
  75. package/styles.css +3 -3
  76. package/wari.d.ts +26 -0
  77. package/wari.js +21 -0
@@ -0,0 +1,41 @@
1
+ // Pure selection logic (same behaviour as @directo-ui/web/wari and @directo-ui/angular/wari).
2
+
3
+ export function normalizeSearch(text) {
4
+ return String(text).normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase().trim();
5
+ }
6
+
7
+ export function filterOptions(options, query) {
8
+ const needle = normalizeSearch(query);
9
+ return needle ? options.filter(option => normalizeSearch(option.label).includes(needle)) : [...options];
10
+ }
11
+
12
+ function ordered(values, options) {
13
+ const set = new Set(values);
14
+ return options.filter(option => set.has(option.value)).map(option => option.value);
15
+ }
16
+
17
+ export function toggleValue(values, value, options) {
18
+ const option = options.find(item => item.value === value);
19
+ if (!option || option.disabled) return [...values];
20
+ const set = new Set(values);
21
+ if (set.has(value)) set.delete(value); else set.add(value);
22
+ return ordered(set, options);
23
+ }
24
+
25
+ export function selectionState(values, options) {
26
+ const enabled = options.filter(option => !option.disabled);
27
+ const selected = enabled.filter(option => values.includes(option.value)).length;
28
+ if (selected === 0) return 'none';
29
+ return selected === enabled.length ? 'all' : 'some';
30
+ }
31
+
32
+ export function toggleAll(values, options) {
33
+ const locked = options.filter(option => option.disabled && values.includes(option.value)).map(option => option.value);
34
+ if (selectionState(values, options) === 'all') return ordered(locked, options);
35
+ return ordered([...locked, ...options.filter(option => !option.disabled).map(option => option.value)], options);
36
+ }
37
+
38
+ export function selectionSummary(count) {
39
+ if (count <= 0) return '';
40
+ return count === 1 ? '1 elemento seleccionado' : `${count} elementos seleccionados`;
41
+ }
@@ -0,0 +1,14 @@
1
+ export type MotionSnapshot = Map<string, DOMRect>;
2
+ export declare function prefersReducedMotion(): boolean;
3
+ /** Positions of every [data-motion] element inside `root`, before a change. */
4
+ export declare function snapshot(root: Element | null | undefined): MotionSnapshot;
5
+ /**
6
+ * After the DOM changed: moved elements slide from their old position, new ones fade in (staggered).
7
+ * Nested [data-motion] elements only fade in; they already move with their parent.
8
+ */
9
+ export declare function animateFrom(root: Element | null | undefined, before: MotionSnapshot): void;
10
+ /**
11
+ * Fades an element out, then runs `remove` (your state change). The fade is cleared on the next frames, so an element that
12
+ * is reused for other content (for example a list keyed by index) shows up again.
13
+ */
14
+ export declare function leave(el: Element | null | undefined, remove: () => void): void;
@@ -0,0 +1,60 @@
1
+ // Generated from web/components/src/wari/motion.ts (same behaviour in React, Angular and Astro).
2
+ // Small FLIP helpers for the Wari route editor: elements marked with data-motion="key" slide to their new place when the
3
+ // list changes, new ones fade in and removed ones fade out first. Framework-free (same file in React, Angular and Astro).
4
+ // Respects prefers-reduced-motion.
5
+ const EASE = 'cubic-bezier(.2, .8, .2, 1)';
6
+ export function prefersReducedMotion() {
7
+ return typeof window === 'undefined' || typeof window.matchMedia !== 'function'
8
+ || window.matchMedia('(prefers-reduced-motion: reduce)').matches;
9
+ }
10
+ const canAnimate = (el) => typeof el.animate === 'function';
11
+ /** Positions of every [data-motion] element inside `root`, before a change. */
12
+ export function snapshot(root) {
13
+ const rects = new Map();
14
+ if (!root || prefersReducedMotion())
15
+ return rects;
16
+ root.querySelectorAll('[data-motion]').forEach(el => rects.set(el.dataset.motion, el.getBoundingClientRect()));
17
+ return rects;
18
+ }
19
+ /**
20
+ * After the DOM changed: moved elements slide from their old position, new ones fade in (staggered).
21
+ * Nested [data-motion] elements only fade in; they already move with their parent.
22
+ */
23
+ export function animateFrom(root, before) {
24
+ if (!root || before.size === 0 || prefersReducedMotion())
25
+ return;
26
+ let entering = 0;
27
+ root.querySelectorAll('[data-motion]').forEach(el => {
28
+ if (!canAnimate(el))
29
+ return;
30
+ const old = before.get(el.dataset.motion);
31
+ if (!old) {
32
+ el.animate([{ opacity: 0, transform: 'translateY(-6px) scale(.98)' }, { opacity: 1, transform: 'none' }], { duration: 240, easing: EASE, delay: Math.min(entering++, 6) * 35, fill: 'backwards' });
33
+ return;
34
+ }
35
+ if (el.parentElement?.closest('[data-motion]') && root.contains(el.parentElement.closest('[data-motion]')))
36
+ return;
37
+ const now = el.getBoundingClientRect();
38
+ const dx = old.left - now.left;
39
+ const dy = old.top - now.top;
40
+ if (Math.abs(dx) < 1 && Math.abs(dy) < 1)
41
+ return;
42
+ el.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }], { duration: 280, easing: EASE });
43
+ });
44
+ }
45
+ /**
46
+ * Fades an element out, then runs `remove` (your state change). The fade is cleared on the next frames, so an element that
47
+ * is reused for other content (for example a list keyed by index) shows up again.
48
+ */
49
+ export function leave(el, remove) {
50
+ if (!el || !canAnimate(el) || prefersReducedMotion()) {
51
+ remove();
52
+ return;
53
+ }
54
+ const animation = el.animate([{ opacity: 1, transform: 'none' }, { opacity: 0, transform: 'translateX(12px) scale(.97)' }], { duration: 170, easing: 'ease-in', fill: 'forwards' });
55
+ const done = () => {
56
+ remove();
57
+ requestAnimationFrame(() => requestAnimationFrame(() => animation.cancel()));
58
+ };
59
+ animation.finished.then(done, done);
60
+ }
@@ -0,0 +1,2 @@
1
+ /** Inicializa los MultiSelect/WariStatusSelect del documento (o de `scope`). Idempotente. */
2
+ export declare function initMultiSelects(scope?: ParentNode): void;
@@ -0,0 +1,169 @@
1
+ // Client behaviour for <MultiSelect> / <WariStatusSelect>. Safe to call many times: each root initialises once.
2
+ // Emits a bubbling "ds-change" CustomEvent with the selected values (string[]) as detail.
3
+ import { filterOptions, normalizeSearch, selectionState, selectionSummary, toggleAll, toggleValue } from './logic.js';
4
+
5
+ export function initMultiSelects(scope = document) {
6
+ scope.querySelectorAll('[data-ds-multiselect]:not([data-ds-ready])').forEach(setup);
7
+ }
8
+
9
+ function setup(root) {
10
+ root.dataset.dsReady = '';
11
+ const input = root.querySelector('.ds-multiselect-input');
12
+ const shell = root.querySelector('.ds-input-shell');
13
+ const list = root.querySelector('.ds-multiselect-list');
14
+ const valuesBox = root.querySelector('.ds-multiselect-values');
15
+ const hintEl = root.querySelector('.ds-multiselect-hint');
16
+ const empty = root.querySelector('.ds-multiselect-empty');
17
+ const inputsBox = root.querySelector('.ds-multiselect-inputs');
18
+ const allRow = list.querySelector('[data-all]');
19
+ const optionRows = [...list.querySelectorAll('[role="option"][data-value]')];
20
+ const options = optionRows.map(li => ({ value: li.dataset.value, label: li.dataset.label, disabled: li.getAttribute('aria-disabled') === 'true' }));
21
+ const { maxTags = '2', summary = 'true', supportingText = '', name = '', placeholder = '', searchPlaceholder = '' } = root.dataset;
22
+ const max = Number(maxTags) || 0;
23
+
24
+ let values = optionRows.filter(li => li.getAttribute('aria-selected') === 'true').map(li => li.dataset.value);
25
+ let open = false;
26
+ let active = 0;
27
+
28
+ const rows = () => [allRow, ...optionRows].filter(li => li && !li.hidden);
29
+ const cloneTag = li => li.querySelector('[data-tag]').cloneNode(true);
30
+
31
+ function render() {
32
+ const state = selectionState(values, options);
33
+ optionRows.forEach(li => li.setAttribute('aria-selected', String(values.includes(li.dataset.value))));
34
+ if (allRow) {
35
+ allRow.setAttribute('aria-selected', String(state === 'all'));
36
+ allRow.dataset.indeterminate = String(state === 'some');
37
+ }
38
+ valuesBox.replaceChildren();
39
+ if (state === 'all' && allRow) valuesBox.append(cloneTag(allRow));
40
+ else {
41
+ const chosen = optionRows.filter(li => values.includes(li.dataset.value));
42
+ chosen.slice(0, max).forEach(li => valuesBox.append(cloneTag(li)));
43
+ if (chosen.length > max) {
44
+ const more = document.createElement('span');
45
+ more.className = 'ds-multiselect-more';
46
+ more.textContent = `+${chosen.length - max}`;
47
+ valuesBox.append(more);
48
+ }
49
+ }
50
+ valuesBox.hidden = values.length === 0;
51
+ input.placeholder = open ? searchPlaceholder : values.length ? '' : placeholder;
52
+ const hint = supportingText || (summary !== 'false' ? selectionSummary(values.length) : '');
53
+ hintEl.textContent = hint;
54
+ hintEl.hidden = !hint;
55
+ if (hint) input.setAttribute('aria-describedby', hintEl.id); else input.removeAttribute('aria-describedby');
56
+ if (name) {
57
+ inputsBox.replaceChildren(...values.map(value => Object.assign(document.createElement('input'), { type: 'hidden', name, value })));
58
+ }
59
+ }
60
+
61
+ function setActive(index) {
62
+ const visible = rows();
63
+ active = Math.max(0, Math.min(index, visible.length - 1));
64
+ [allRow, ...optionRows].forEach(li => { if (li) li.dataset.active = 'false'; });
65
+ const current = visible[active];
66
+ if (current) {
67
+ current.dataset.active = 'true';
68
+ input.setAttribute('aria-activedescendant', current.id);
69
+ current.scrollIntoView?.({ block: 'nearest' });
70
+ } else input.removeAttribute('aria-activedescendant');
71
+ }
72
+
73
+ function filter(query) {
74
+ const matches = new Set(filterOptions(options, query).map(option => option.value));
75
+ optionRows.forEach(li => { li.hidden = !matches.has(li.dataset.value); });
76
+ if (allRow) allRow.hidden = Boolean(normalizeSearch(query));
77
+ empty.hidden = matches.size > 0;
78
+ }
79
+
80
+ function setOpen(next, index = 0) {
81
+ if (next && input.disabled) return;
82
+ open = next;
83
+ root.dataset.open = String(next);
84
+ list.hidden = !next;
85
+ input.setAttribute('aria-expanded', String(next));
86
+ if (next) setActive(index);
87
+ else {
88
+ input.value = '';
89
+ filter('');
90
+ input.removeAttribute('aria-activedescendant');
91
+ }
92
+ input.placeholder = open ? searchPlaceholder : values.length ? '' : placeholder;
93
+ }
94
+
95
+ function commit(next) {
96
+ values = next;
97
+ render();
98
+ root.dispatchEvent(new CustomEvent('ds-change', { detail: [...values], bubbles: true }));
99
+ }
100
+
101
+ function choose(li) {
102
+ if (!li || li.getAttribute('aria-disabled') === 'true') return;
103
+ commit(li === allRow ? toggleAll(values, options) : toggleValue(values, li.dataset.value, options));
104
+ }
105
+
106
+ input.addEventListener('input', () => {
107
+ if (!open) setOpen(true);
108
+ filter(input.value);
109
+ setActive(0);
110
+ });
111
+ input.addEventListener('click', () => { if (!open) setOpen(true); });
112
+ input.addEventListener('keydown', event => {
113
+ const last = rows().length - 1;
114
+ switch (event.key) {
115
+ case 'ArrowDown':
116
+ event.preventDefault();
117
+ if (open) setActive(active + 1); else setOpen(true, 0);
118
+ break;
119
+ case 'ArrowUp':
120
+ event.preventDefault();
121
+ if (open) setActive(active - 1); else setOpen(true, last);
122
+ break;
123
+ case 'Home':
124
+ case 'End':
125
+ if (open) { event.preventDefault(); setActive(event.key === 'Home' ? 0 : last); }
126
+ break;
127
+ case 'Enter':
128
+ event.preventDefault();
129
+ if (!open) setOpen(true, 0);
130
+ else choose(rows()[active]);
131
+ break;
132
+ case 'Escape':
133
+ if (open) {
134
+ event.preventDefault();
135
+ if (input.value) { input.value = ''; filter(''); setActive(0); } else setOpen(false);
136
+ }
137
+ break;
138
+ case 'Tab':
139
+ setOpen(false);
140
+ break;
141
+ }
142
+ });
143
+ shell.addEventListener('mousedown', event => {
144
+ if (input.disabled || event.target === input) return;
145
+ event.preventDefault();
146
+ input.focus();
147
+ setOpen(!open);
148
+ });
149
+ list.addEventListener('mousedown', event => event.preventDefault());
150
+ list.addEventListener('mousemove', event => {
151
+ const li = event.target.closest('[role="option"]');
152
+ const index = rows().indexOf(li);
153
+ if (index >= 0 && index !== active) setActive(index);
154
+ });
155
+ list.addEventListener('click', event => {
156
+ const li = event.target.closest('[role="option"]');
157
+ if (!li) return;
158
+ choose(li);
159
+ setActive(rows().indexOf(li));
160
+ });
161
+ root.addEventListener('focusout', event => {
162
+ if (open && event.relatedTarget && !root.contains(event.relatedTarget)) setOpen(false);
163
+ });
164
+ document.addEventListener('pointerdown', event => {
165
+ if (open && !root.contains(event.target)) setOpen(false);
166
+ });
167
+
168
+ render();
169
+ }
@@ -0,0 +1,2 @@
1
+ /** Inicializa los campos de fecha y hora de Wari del documento (o de `scope`). Idempotente. */
2
+ export declare function initWariFields(scope?: ParentNode): void;