stimeo-ui 0.2.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.
- package/CHANGELOG.md +163 -0
- package/dist/cable/index.d.ts +16 -16
- package/dist/cable/index.js.map +1 -1
- package/dist/controllers/accordion_controller.d.ts +3 -2
- package/dist/controllers/accordion_controller.js +10 -0
- package/dist/controllers/accordion_controller.js.map +1 -1
- package/dist/controllers/alert_dialog_controller.d.ts +64 -0
- package/dist/controllers/alert_dialog_controller.js +318 -0
- package/dist/controllers/alert_dialog_controller.js.map +1 -0
- package/dist/controllers/breadcrumb_controller.d.ts +97 -10
- package/dist/controllers/breadcrumb_controller.js +225 -13
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/calendar_controller.d.ts +11 -1
- package/dist/controllers/calendar_controller.js +89 -22
- package/dist/controllers/calendar_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.d.ts +115 -0
- package/dist/controllers/carousel_controller.js +313 -0
- package/dist/controllers/carousel_controller.js.map +1 -0
- package/dist/controllers/clipboard_controller.d.ts +72 -0
- package/dist/controllers/clipboard_controller.js +144 -0
- package/dist/controllers/clipboard_controller.js.map +1 -0
- package/dist/controllers/collapsible_controller.d.ts +70 -0
- package/dist/controllers/collapsible_controller.js +327 -0
- package/dist/controllers/collapsible_controller.js.map +1 -0
- package/dist/controllers/color_picker_controller.d.ts +87 -0
- package/dist/controllers/color_picker_controller.js +252 -0
- package/dist/controllers/color_picker_controller.js.map +1 -0
- package/dist/controllers/combobox_controller.d.ts +14 -1
- package/dist/controllers/combobox_controller.js +162 -23
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.d.ts +2 -0
- package/dist/controllers/command_palette_controller.js +194 -17
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/confirm_controller.js.map +1 -1
- package/dist/controllers/context_menu_controller.d.ts +7 -6
- package/dist/controllers/context_menu_controller.js +32 -10
- package/dist/controllers/context_menu_controller.js.map +1 -1
- package/dist/controllers/count_up_controller.js +8 -1
- package/dist/controllers/count_up_controller.js.map +1 -1
- package/dist/controllers/currency_input_controller.d.ts +72 -0
- package/dist/controllers/currency_input_controller.js +147 -0
- package/dist/controllers/currency_input_controller.js.map +1 -0
- package/dist/controllers/data_grid_controller.d.ts +89 -0
- package/dist/controllers/data_grid_controller.js +246 -0
- package/dist/controllers/data_grid_controller.js.map +1 -0
- package/dist/controllers/date_range_picker_controller.d.ts +88 -0
- package/dist/controllers/date_range_picker_controller.js +441 -0
- package/dist/controllers/date_range_picker_controller.js.map +1 -0
- package/dist/controllers/dialog_controller.js.map +1 -1
- package/dist/controllers/dismissible_controller.d.ts +57 -0
- package/dist/controllers/dismissible_controller.js +117 -0
- package/dist/controllers/dismissible_controller.js.map +1 -0
- package/dist/controllers/drawer_controller.d.ts +96 -0
- package/dist/controllers/drawer_controller.js +630 -0
- package/dist/controllers/drawer_controller.js.map +1 -0
- package/dist/controllers/dropdown_controller.d.ts +1 -2
- package/dist/controllers/dropdown_controller.js.map +1 -1
- package/dist/controllers/editable_controller.d.ts +73 -0
- package/dist/controllers/editable_controller.js +169 -0
- package/dist/controllers/editable_controller.js.map +1 -0
- package/dist/controllers/file_dropzone_controller.d.ts +92 -0
- package/dist/controllers/file_dropzone_controller.js +165 -0
- package/dist/controllers/file_dropzone_controller.js.map +1 -0
- package/dist/controllers/filter_controller.d.ts +60 -0
- package/dist/controllers/filter_controller.js +86 -0
- package/dist/controllers/filter_controller.js.map +1 -0
- package/dist/controllers/flash_controller.js +36 -5
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/focus_controller.d.ts +1 -1
- package/dist/controllers/focus_controller.js.map +1 -1
- package/dist/controllers/form_field_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.js +1 -1
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.js +6 -4
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/hover_card_controller.d.ts +1 -1
- package/dist/controllers/hover_card_controller.js.map +1 -1
- package/dist/controllers/intersection_controller.js +67 -19
- package/dist/controllers/intersection_controller.js.map +1 -1
- package/dist/controllers/lazy_frame_controller.js +54 -11
- package/dist/controllers/lazy_frame_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.d.ts +9 -2
- package/dist/controllers/listbox_controller.js +257 -53
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/local_time_controller.js +2 -2
- package/dist/controllers/local_time_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +54 -0
- package/dist/controllers/masonry_controller.js +142 -0
- package/dist/controllers/masonry_controller.js.map +1 -0
- package/dist/controllers/menu_controller.d.ts +29 -11
- package/dist/controllers/menu_controller.js +104 -17
- package/dist/controllers/menu_controller.js.map +1 -1
- package/dist/controllers/menubar_controller.d.ts +142 -0
- package/dist/controllers/menubar_controller.js +785 -0
- package/dist/controllers/menubar_controller.js.map +1 -0
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.d.ts +141 -0
- package/dist/controllers/multi_select_controller.js +755 -0
- package/dist/controllers/multi_select_controller.js.map +1 -0
- package/dist/controllers/navigation_menu_controller.d.ts +146 -0
- package/dist/controllers/navigation_menu_controller.js +511 -0
- package/dist/controllers/navigation_menu_controller.js.map +1 -0
- package/dist/controllers/nested_form_controller.d.ts +4 -5
- package/dist/controllers/nested_form_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +1 -1
- package/dist/controllers/number_input_controller.js +7 -0
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/otp_controller.js +18 -1
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/overflow_indicator_controller.d.ts +15 -6
- package/dist/controllers/overflow_indicator_controller.js +246 -27
- package/dist/controllers/overflow_indicator_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.d.ts +78 -19
- package/dist/controllers/overflow_menu_controller.js +381 -57
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.d.ts +36 -5
- package/dist/controllers/pagination_controller.js +163 -32
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/password_reveal_controller.d.ts +49 -0
- package/dist/controllers/password_reveal_controller.js +117 -0
- package/dist/controllers/password_reveal_controller.js.map +1 -0
- package/dist/controllers/persist_controller.js +6 -6
- package/dist/controllers/persist_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.d.ts +2 -3
- package/dist/controllers/pointer_drag_controller.js +9 -1
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/popover_controller.d.ts +1 -2
- package/dist/controllers/popover_controller.js +2 -2
- package/dist/controllers/popover_controller.js.map +1 -1
- package/dist/controllers/portal_controller.d.ts +4 -4
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/radio_group_controller.js +22 -3
- package/dist/controllers/radio_group_controller.js.map +1 -1
- package/dist/controllers/range_slider_controller.d.ts +97 -0
- package/dist/controllers/range_slider_controller.js +192 -0
- package/dist/controllers/range_slider_controller.js.map +1 -0
- package/dist/controllers/rating_controller.js +16 -2
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/read_more_controller.d.ts +52 -0
- package/dist/controllers/read_more_controller.js +238 -0
- package/dist/controllers/read_more_controller.js.map +1 -0
- package/dist/controllers/reading_progress_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +3 -1
- package/dist/controllers/resizable_controller.js +65 -1
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/controllers/roving_controller.js +17 -2
- package/dist/controllers/roving_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.js +101 -14
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/scroll_restore_controller.d.ts +54 -0
- package/dist/controllers/scroll_restore_controller.js +93 -0
- package/dist/controllers/scroll_restore_controller.js.map +1 -0
- package/dist/controllers/scroll_visibility_controller.d.ts +6 -3
- package/dist/controllers/scroll_visibility_controller.js +40 -6
- package/dist/controllers/scroll_visibility_controller.js.map +1 -1
- package/dist/controllers/scrollspy_controller.d.ts +64 -15
- package/dist/controllers/scrollspy_controller.js +369 -74
- package/dist/controllers/scrollspy_controller.js.map +1 -1
- package/dist/controllers/separator_controller.d.ts +69 -0
- package/dist/controllers/separator_controller.js +96 -0
- package/dist/controllers/separator_controller.js.map +1 -0
- package/dist/controllers/sidebar_controller.d.ts +107 -0
- package/dist/controllers/sidebar_controller.js +761 -0
- package/dist/controllers/sidebar_controller.js.map +1 -0
- package/dist/controllers/skeleton_controller.js +1 -1
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +11 -1
- package/dist/controllers/slider_controller.js +32 -6
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/sortable_controller.d.ts +3 -1
- package/dist/controllers/sortable_controller.js +34 -3
- package/dist/controllers/sortable_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.js +1 -1
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/stepper_controller.d.ts +4 -0
- package/dist/controllers/stepper_controller.js +28 -12
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.d.ts +5 -6
- package/dist/controllers/stick_to_bottom_controller.js +9 -4
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/sticky_observer_controller.d.ts +17 -4
- package/dist/controllers/sticky_observer_controller.js +109 -20
- package/dist/controllers/sticky_observer_controller.js.map +1 -1
- package/dist/controllers/submit_once_controller.d.ts +2 -2
- package/dist/controllers/submit_once_controller.js.map +1 -1
- package/dist/controllers/switch_controller.js +1 -0
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/tabs_controller.d.ts +13 -4
- package/dist/controllers/tabs_controller.js +26 -3
- package/dist/controllers/tabs_controller.js.map +1 -1
- package/dist/controllers/tags_input_controller.d.ts +91 -0
- package/dist/controllers/tags_input_controller.js +295 -0
- package/dist/controllers/tags_input_controller.js.map +1 -0
- package/dist/controllers/theme_controller.d.ts +1 -1
- package/dist/controllers/theme_controller.js +42 -13
- package/dist/controllers/theme_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.d.ts +67 -0
- package/dist/controllers/time_picker_controller.js +231 -0
- package/dist/controllers/time_picker_controller.js.map +1 -0
- package/dist/controllers/toast_controller.d.ts +5 -14
- package/dist/controllers/toast_controller.js +40 -14
- package/dist/controllers/toast_controller.js.map +1 -1
- package/dist/controllers/toggle_group_controller.js +23 -2
- package/dist/controllers/toggle_group_controller.js.map +1 -1
- package/dist/controllers/toolbar_controller.d.ts +53 -13
- package/dist/controllers/toolbar_controller.js +230 -31
- package/dist/controllers/toolbar_controller.js.map +1 -1
- package/dist/controllers/tooltip_controller.d.ts +1 -1
- package/dist/controllers/tooltip_controller.js.map +1 -1
- package/dist/controllers/transition_controller.d.ts +14 -8
- package/dist/controllers/transition_controller.js +153 -38
- package/dist/controllers/transition_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +135 -0
- package/dist/controllers/tree_view_controller.js +691 -0
- package/dist/controllers/tree_view_controller.js.map +1 -0
- package/dist/index.d.ts +27 -1818
- package/dist/index.js +4256 -915
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +375 -39
- package/dist/inspector/cli.js +228 -14
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +419 -48
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +26 -26
- package/dist/inspector/manifest.json +1054 -127
- package/package.json +5 -6
|
@@ -2,6 +2,61 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/breadcrumb_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/blur_deferral.ts
|
|
6
|
+
var BlurDeferral = class {
|
|
7
|
+
/** Elements currently holding an update back, mapped to their `blur` listener. */
|
|
8
|
+
#pending = /* @__PURE__ */ new Map();
|
|
9
|
+
/** Called after a pending element blurs and has been detached. */
|
|
10
|
+
#onRelease;
|
|
11
|
+
/** @param onRelease - Invoked once `element` actually blurs; never on `release`. */
|
|
12
|
+
constructor(onRelease) {
|
|
13
|
+
this.#onRelease = onRelease;
|
|
14
|
+
}
|
|
15
|
+
/** Number of elements currently holding an update back. */
|
|
16
|
+
get size() {
|
|
17
|
+
return this.#pending.size;
|
|
18
|
+
}
|
|
19
|
+
/** Snapshot of the pending elements, safe to iterate while releasing them. */
|
|
20
|
+
get elements() {
|
|
21
|
+
return [...this.#pending.keys()];
|
|
22
|
+
}
|
|
23
|
+
/** Whether `element` is currently holding an update back. */
|
|
24
|
+
has(element) {
|
|
25
|
+
return this.#pending.has(element);
|
|
26
|
+
}
|
|
27
|
+
/** Holds an update back until `element` blurs. Idempotent (no stacked listeners). */
|
|
28
|
+
defer(element) {
|
|
29
|
+
if (this.#pending.has(element)) return;
|
|
30
|
+
const onBlur = () => {
|
|
31
|
+
this.#detach(element);
|
|
32
|
+
this.#onRelease(element);
|
|
33
|
+
};
|
|
34
|
+
this.#pending.set(element, onBlur);
|
|
35
|
+
element.addEventListener("blur", onBlur);
|
|
36
|
+
}
|
|
37
|
+
/** Defers `element` as the only pending entry, cancelling any others. */
|
|
38
|
+
deferOnly(element) {
|
|
39
|
+
for (const pending of this.elements) {
|
|
40
|
+
if (pending !== element) this.#detach(pending);
|
|
41
|
+
}
|
|
42
|
+
this.defer(element);
|
|
43
|
+
}
|
|
44
|
+
/** Cancels `element`'s deferral without completing it; no-ops when not pending. */
|
|
45
|
+
release(element) {
|
|
46
|
+
this.#detach(element);
|
|
47
|
+
}
|
|
48
|
+
/** Cancels every deferral without completing any of them. */
|
|
49
|
+
releaseAll() {
|
|
50
|
+
for (const element of this.elements) this.#detach(element);
|
|
51
|
+
}
|
|
52
|
+
/** Removes the `blur` listener for `element` and forgets it. */
|
|
53
|
+
#detach(element) {
|
|
54
|
+
const onBlur = this.#pending.get(element);
|
|
55
|
+
if (onBlur) element.removeEventListener("blur", onBlur);
|
|
56
|
+
this.#pending.delete(element);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
5
60
|
// src/utils/layout_observer.ts
|
|
6
61
|
var LayoutObserver = class {
|
|
7
62
|
#callback;
|
|
@@ -59,37 +114,152 @@ var LayoutObserver = class {
|
|
|
59
114
|
};
|
|
60
115
|
|
|
61
116
|
// src/controllers/breadcrumb_controller.ts
|
|
117
|
+
var OVERFLOW_EPSILON = 1;
|
|
62
118
|
var BreadcrumbController = class extends Controller {
|
|
63
119
|
static targets = ["list", "collapsible", "ellipsis", "trigger"];
|
|
64
|
-
static actions = ["toggle"];
|
|
120
|
+
static actions = ["toggle", "update"];
|
|
65
121
|
static events = ["toggle"];
|
|
122
|
+
/** Guards target callbacks that can fire outside the connected window. */
|
|
123
|
+
#connected = false;
|
|
66
124
|
/** Whether the trail currently overflows its container. */
|
|
67
125
|
#overflowing = false;
|
|
68
126
|
/** Whether the user has expanded the collapsed items via the disclosure. */
|
|
69
127
|
#expanded = false;
|
|
70
|
-
|
|
128
|
+
/** The list element currently observed (resize + mutations), if any. */
|
|
129
|
+
#observedList = null;
|
|
130
|
+
#listMutations = null;
|
|
131
|
+
#layout = new LayoutObserver(() => this.update());
|
|
132
|
+
#onListMutation = () => {
|
|
133
|
+
this.update();
|
|
134
|
+
};
|
|
135
|
+
/** Holds the ellipsis hide back while it contains focus; re-renders on blur. */
|
|
136
|
+
#deferredHide = new BlurDeferral(() => {
|
|
137
|
+
this.#render();
|
|
138
|
+
});
|
|
71
139
|
/** Starts observing for overflow and renders the initial state. */
|
|
72
140
|
connect() {
|
|
73
|
-
|
|
141
|
+
this.#connected = true;
|
|
142
|
+
this.#expanded = this.#initialExpanded();
|
|
74
143
|
this.#layout.observeViewport();
|
|
75
|
-
this.#
|
|
144
|
+
this.#syncListObservation();
|
|
145
|
+
this.update();
|
|
76
146
|
}
|
|
77
|
-
/** Releases the resize observation (Turbo navigation included). */
|
|
147
|
+
/** Releases the resize/mutation observation (Turbo navigation included). */
|
|
78
148
|
disconnect() {
|
|
149
|
+
this.#connected = false;
|
|
150
|
+
this.#deferredHide.releaseAll();
|
|
151
|
+
this.#stopObservingList();
|
|
79
152
|
this.#layout.disconnect();
|
|
80
153
|
}
|
|
81
|
-
|
|
154
|
+
listTargetConnected() {
|
|
155
|
+
this.#resync();
|
|
156
|
+
}
|
|
157
|
+
listTargetDisconnected() {
|
|
158
|
+
this.#resync();
|
|
159
|
+
}
|
|
160
|
+
collapsibleTargetConnected() {
|
|
161
|
+
this.#resync();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Re-measures when the disclosure set gains or loses a member. The set is a
|
|
165
|
+
* precondition for collapsing at all, so it needs the same watching the list
|
|
166
|
+
* and items get: without these callbacks a swap that breaks or completes the
|
|
167
|
+
* set would only take effect at the next resize or list mutation, which may
|
|
168
|
+
* never come.
|
|
169
|
+
*/
|
|
170
|
+
ellipsisTargetConnected() {
|
|
171
|
+
this.#resync();
|
|
172
|
+
}
|
|
173
|
+
ellipsisTargetDisconnected() {
|
|
174
|
+
this.#resync();
|
|
175
|
+
}
|
|
176
|
+
triggerTargetConnected() {
|
|
177
|
+
this.#resync();
|
|
178
|
+
}
|
|
179
|
+
triggerTargetDisconnected() {
|
|
180
|
+
this.#resync();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Hands `hidden` back when an element stops being a `collapsible` target.
|
|
184
|
+
*
|
|
185
|
+
* The marker is the source of truth for what may be collapsed, so an element
|
|
186
|
+
* that loses it while the controller is live is an always-visible item again —
|
|
187
|
+
* and `#render` only walks the *current* targets, so nothing else would ever
|
|
188
|
+
* clear the `hidden` this controller put there.
|
|
189
|
+
*
|
|
190
|
+
* The `#connected` guard is load-bearing, not defensive. Stimulus fires this
|
|
191
|
+
* callback for **every** target during teardown as well (`Context.disconnect()`
|
|
192
|
+
* stops the target observer after `disconnect()` has run), and there the
|
|
193
|
+
* collapsed DOM must survive untouched so Turbo's cache restores the trail in
|
|
194
|
+
* the state the user left it (see the ownership note in {@link BreadcrumbController}).
|
|
195
|
+
*
|
|
196
|
+
* @param element - the element that just left the `collapsible` target set
|
|
197
|
+
*/
|
|
198
|
+
collapsibleTargetDisconnected(element) {
|
|
199
|
+
if (this.#connected) element.hidden = false;
|
|
200
|
+
this.#resync();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Expands or re-collapses the trail and dispatches `toggle`.
|
|
204
|
+
*
|
|
205
|
+
* No-op while the trail fits: there is nothing collapsed to reveal, and the
|
|
206
|
+
* (hidden) trigger would otherwise keep a stale `aria-expanded="true"` that
|
|
207
|
+
* surfaces pre-expanded the next time the trail overflows. No event is
|
|
208
|
+
* dispatched in that case.
|
|
209
|
+
*/
|
|
82
210
|
toggle() {
|
|
211
|
+
if (!this.#connected || !this.#overflowing) return;
|
|
83
212
|
this.#expanded = !this.#expanded;
|
|
84
213
|
this.#render();
|
|
85
214
|
this.dispatch("toggle", { detail: { expanded: this.#expanded } });
|
|
86
215
|
}
|
|
87
|
-
/**
|
|
88
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Re-measures overflow and re-renders. Wired to resizes and list mutations;
|
|
218
|
+
* exposed as an action so consumers can re-measure after a change the
|
|
219
|
+
* observers cannot see (e.g. a web font swap that only alters text width).
|
|
220
|
+
*/
|
|
221
|
+
update() {
|
|
222
|
+
if (!this.#connected) return;
|
|
89
223
|
this.#overflowing = this.#measureOverflow();
|
|
90
224
|
if (!this.#overflowing) this.#expanded = false;
|
|
91
225
|
this.#render();
|
|
92
226
|
}
|
|
227
|
+
/** Re-attaches the list observation (targets may have been swapped) and re-measures. */
|
|
228
|
+
#resync() {
|
|
229
|
+
if (!this.#connected) return;
|
|
230
|
+
this.#syncListObservation();
|
|
231
|
+
this.update();
|
|
232
|
+
}
|
|
233
|
+
/** Reads the expanded state back from its DOM home (the trigger's `aria-expanded`). */
|
|
234
|
+
#initialExpanded() {
|
|
235
|
+
return this.hasTriggerTarget && this.triggerTarget.getAttribute("aria-expanded") === "true";
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Points the resize + mutation observation at the current `list` target.
|
|
239
|
+
*
|
|
240
|
+
* The list is re-resolved rather than captured at connect so a target swapped
|
|
241
|
+
* at runtime (Turbo Stream replacement of the `<ol>`) is observed too. Only
|
|
242
|
+
* `childList` / `subtree` / `characterData` are watched — deliberately **not**
|
|
243
|
+
* `attributes`, which the controller's own `hidden` writes would re-trigger.
|
|
244
|
+
*/
|
|
245
|
+
#syncListObservation() {
|
|
246
|
+
const next = this.hasListTarget ? this.listTarget : null;
|
|
247
|
+
if (next === this.#observedList) return;
|
|
248
|
+
this.#stopObservingList();
|
|
249
|
+
if (!next) return;
|
|
250
|
+
this.#observedList = next;
|
|
251
|
+
this.#layout.observe(next);
|
|
252
|
+
if (typeof MutationObserver !== "undefined") {
|
|
253
|
+
this.#listMutations = new MutationObserver(this.#onListMutation);
|
|
254
|
+
this.#listMutations.observe(next, { childList: true, subtree: true, characterData: true });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
#stopObservingList() {
|
|
258
|
+
if (this.#observedList) this.#layout.unobserve(this.#observedList);
|
|
259
|
+
this.#observedList = null;
|
|
260
|
+
this.#listMutations?.disconnect();
|
|
261
|
+
this.#listMutations = null;
|
|
262
|
+
}
|
|
93
263
|
/**
|
|
94
264
|
* Measures overflow against the **fully expanded** layout so hiding items does
|
|
95
265
|
* not make the condition oscillate. Reveals every item, then compares the list's
|
|
@@ -100,21 +270,63 @@ var BreadcrumbController = class extends Controller {
|
|
|
100
270
|
* check is independent of any padding/border on the host — comparing against the
|
|
101
271
|
* host's `clientWidth` would over-report the available space by its padding and
|
|
102
272
|
* miss real overflow in a padded container.
|
|
273
|
+
*
|
|
274
|
+
* With no `collapsible` items there is nothing to collapse, so the trail is
|
|
275
|
+
* never reported as overflowing (which also keeps the disclosure out of the
|
|
276
|
+
* tab order — a button controlling nothing).
|
|
277
|
+
*
|
|
278
|
+
* The full disclosure set is a precondition: collapsing without an `ellipsis`
|
|
279
|
+
* *and* a `trigger` would hide items behind a control that does not exist, so
|
|
280
|
+
* an incomplete set reports "not overflowing" and `#render` degrades the trail
|
|
281
|
+
* to a plain breadcrumb. Losing layout is recoverable; losing the path is not.
|
|
103
282
|
*/
|
|
104
283
|
#measureOverflow() {
|
|
105
|
-
if (!this.hasListTarget) return false;
|
|
284
|
+
if (!this.hasListTarget || this.collapsibleTargets.length === 0) return false;
|
|
285
|
+
if (!this.hasEllipsisTarget || !this.hasTriggerTarget) return false;
|
|
106
286
|
for (const item of this.collapsibleTargets) item.hidden = false;
|
|
107
|
-
|
|
108
|
-
return this.listTarget.scrollWidth > this.listTarget.clientWidth;
|
|
287
|
+
this.ellipsisTarget.hidden = true;
|
|
288
|
+
return this.listTarget.scrollWidth > this.listTarget.clientWidth + OVERFLOW_EPSILON;
|
|
109
289
|
}
|
|
110
290
|
/** Applies the collapsed/expanded state to the items, ellipsis, and trigger. */
|
|
111
291
|
#render() {
|
|
112
292
|
const collapsed = this.#overflowing && !this.#expanded;
|
|
293
|
+
const showEllipsis = this.#overflowing && this.collapsibleTargets.length > 0;
|
|
294
|
+
const rescueFocus = collapsed && this.hasTriggerTarget && this.collapsibleTargets.some((i) => this.#holdsFocus(i));
|
|
113
295
|
for (const item of this.collapsibleTargets) item.hidden = collapsed;
|
|
114
|
-
if (this.hasEllipsisTarget) this
|
|
296
|
+
if (this.hasEllipsisTarget) this.#applyEllipsisVisibility(showEllipsis);
|
|
115
297
|
if (this.hasTriggerTarget) {
|
|
116
|
-
|
|
298
|
+
const expanded = this.#overflowing && this.#expanded;
|
|
299
|
+
this.triggerTarget.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
300
|
+
}
|
|
301
|
+
if (rescueFocus) this.triggerTarget.focus();
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Shows or hides the ellipsis item, deferring a hide that would blur the user.
|
|
305
|
+
*
|
|
306
|
+
* Hiding the element that currently holds focus drops focus to `<body>`, so the
|
|
307
|
+
* hide waits for that element's `blur` and is re-applied then (the shared
|
|
308
|
+
* `BlurDeferral` registry).
|
|
309
|
+
*/
|
|
310
|
+
#applyEllipsisVisibility(show) {
|
|
311
|
+
const ellipsis = this.ellipsisTarget;
|
|
312
|
+
if (show) {
|
|
313
|
+
this.#deferredHide.releaseAll();
|
|
314
|
+
ellipsis.hidden = false;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const active = document.activeElement;
|
|
318
|
+
if (active instanceof HTMLElement && ellipsis.contains(active)) {
|
|
319
|
+
ellipsis.hidden = false;
|
|
320
|
+
this.#deferredHide.deferOnly(active);
|
|
321
|
+
return;
|
|
117
322
|
}
|
|
323
|
+
this.#deferredHide.releaseAll();
|
|
324
|
+
ellipsis.hidden = true;
|
|
325
|
+
}
|
|
326
|
+
/** Whether `element` contains (or is) the currently focused element. */
|
|
327
|
+
#holdsFocus(element) {
|
|
328
|
+
const active = document.activeElement;
|
|
329
|
+
return active instanceof HTMLElement && element.contains(active);
|
|
118
330
|
}
|
|
119
331
|
};
|
|
120
332
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/layout_observer.ts","../../src/controllers/breadcrumb_controller.ts"],"names":[],"mappings":";;;;;AAgDO,IAAM,iBAAN,MAAqB;AAAA,EACjB,SAAA;AAAA,EACA,sBAAA;AAAA,EACT,eAAA,GAAyC,IAAA;AAAA,EACzC,kBAAA,GAAqB,KAAA;AAAA;AAAA,EAGZ,wBAAwB,MAAY;AAC3C,IAAA,IAAA,CAAK,SAAA,EAAU;AAAA,EACjB,CAAA;AAAA,EAEA,WAAA,CAAY,QAAA,EAA0B,OAAA,GAAiC,EAAC,EAAG;AACzE,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA;AACjB,IAAA,IAAA,CAAK,sBAAA,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B;AAC1B,IAAA,IAAI,CAAC,IAAA,CAAK,aAAA,EAAe,OAAO,KAAA;AAChC,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,kBAAA,EAAoB,IAAA,CAAK,MAAA,GAAS,KAAA;AAC1D,IAAA,IAAI,IAAA,CAAK,iBAAA,EAAmB,IAAA,CAAK,cAAA,CAAe,MAAA,GAAS,IAAA;AACzD,IAAA,OAAO,IAAA,CAAK,UAAA,CAAW,WAAA,GAAc,IAAA,CAAK,UAAA,CAAW,WAAA;AAAA,EACvD;AAAA;AAAA,EAGA,OAAA,GAAgB;AACd,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,YAAA,IAAgB,CAAC,IAAA,CAAK,SAAA;AAC7C,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,kBAAA,EAAoB,IAAA,CAAK,MAAA,GAAS,SAAA;AAC1D,IAAA,IAAI,KAAK,iBAAA,EAAmB,IAAA,CAAK,cAAA,CAAe,MAAA,GAAS,CAAC,IAAA,CAAK,YAAA;AAC/D,IAAA,IAAI,KAAK,gBAAA,EAAkB;AACzB,MAAA,IAAA,CAAK,cAAc,YAAA,CAAa,eAAA,EAAiB,IAAA,CAAK,SAAA,GAAY,SAAS,OAAO,CAAA;AAAA,IACpF;AAAA,EACF;AACF","file":"breadcrumb_controller.js","sourcesContent":["/**\n * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Layout-sensitive widgets (sliders, resizable panes, scroll spies, popovers)\n * need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\n\n/**\n * Headless, accessible responsive breadcrumb behavior.\n *\n * Markup contract (identifier: `stimeo--breadcrumb`):\n * <nav data-controller=\"stimeo--breadcrumb\" aria-label=\"Breadcrumb\">\n * <ol data-stimeo--breadcrumb-target=\"list\">\n * <li><a href=\"/\">Home</a></li>\n * <li data-stimeo--breadcrumb-target=\"ellipsis\" hidden>\n * <button type=\"button\" aria-expanded=\"false\" aria-controls=\"bc-collapsed\"\n * aria-label=\"Show full path\"\n * data-stimeo--breadcrumb-target=\"trigger\"\n * data-action=\"stimeo--breadcrumb#toggle\">…</button>\n * </li>\n * <li id=\"bc-collapsed\" data-stimeo--breadcrumb-target=\"collapsible\"><a href=\"/a\">Section A</a></li>\n * <li data-stimeo--breadcrumb-target=\"collapsible\"><a href=\"/a/b\">Sub B</a></li>\n * <li><a href=\"/a/b/c\" aria-current=\"page\">Item C</a></li>\n * </ol>\n * </nav>\n *\n * Implements the WAI-ARIA APG **Breadcrumb** pattern. The base structure (`nav`\n * + `ol` + `aria-current=\"page\"`) lives in the markup; this controller adds the\n * responsive behavior: when the trail overflows its container it collapses the\n * author-marked middle items behind a disclosure (`…`) button, which expands\n * them back on demand.\n *\n * @remarks\n * Behavior only — the consumer owns separators (CSS) and the look. The items to\n * collapse are the author-marked `collapsible` targets (the source of truth),\n * placed between the leading and trailing items that must always stay visible.\n *\n * Behavior provided:\n * - Detects overflow via {@link LayoutObserver} (element + viewport resize).\n * - While overflowing and not expanded, hides the `collapsible` items and shows\n * the `ellipsis` item; when it fits, shows everything and hides the ellipsis.\n * - The disclosure `trigger` toggles `aria-expanded` and the collapsed items,\n * dispatching `stimeo--breadcrumb:toggle`.\n */\nexport class BreadcrumbController extends Controller<HTMLElement> {\n static override targets = [\"list\", \"collapsible\", \"ellipsis\", \"trigger\"];\n static actions = [\"toggle\"] as const;\n static events = [\"toggle\"] as const;\n\n declare readonly listTarget: HTMLElement;\n declare readonly collapsibleTargets: HTMLElement[];\n declare readonly ellipsisTarget: HTMLElement;\n declare readonly triggerTarget: HTMLElement;\n declare readonly hasListTarget: boolean;\n declare readonly hasEllipsisTarget: boolean;\n declare readonly hasTriggerTarget: boolean;\n\n /** Whether the trail currently overflows its container. */\n #overflowing = false;\n /** Whether the user has expanded the collapsed items via the disclosure. */\n #expanded = false;\n\n readonly #layout = new LayoutObserver(() => this.#update());\n\n /** Starts observing for overflow and renders the initial state. */\n override connect(): void {\n if (this.hasListTarget) this.#layout.observe(this.listTarget);\n this.#layout.observeViewport();\n this.#update();\n }\n\n /** Releases the resize observation (Turbo navigation included). */\n override disconnect(): void {\n this.#layout.disconnect();\n }\n\n /** Expands or re-collapses the trail and dispatches `toggle`. */\n toggle(): void {\n this.#expanded = !this.#expanded;\n this.#render();\n this.dispatch(\"toggle\", { detail: { expanded: this.#expanded } });\n }\n\n /** Re-measures overflow and re-renders (e.g. on resize). */\n #update(): void {\n this.#overflowing = this.#measureOverflow();\n if (!this.#overflowing) this.#expanded = false;\n this.#render();\n }\n\n /**\n * Measures overflow against the **fully expanded** layout so hiding items does\n * not make the condition oscillate. Reveals every item, then compares the list's\n * own scroll width to its own client width; `#render` immediately re-applies\n * the correct hidden state afterward.\n *\n * Both widths are read from the list element itself (not the host `nav`) so the\n * check is independent of any padding/border on the host — comparing against the\n * host's `clientWidth` would over-report the available space by its padding and\n * miss real overflow in a padded container.\n */\n #measureOverflow(): boolean {\n if (!this.hasListTarget) return false;\n for (const item of this.collapsibleTargets) item.hidden = false;\n if (this.hasEllipsisTarget) this.ellipsisTarget.hidden = true;\n return this.listTarget.scrollWidth > this.listTarget.clientWidth;\n }\n\n /** Applies the collapsed/expanded state to the items, ellipsis, and trigger. */\n #render(): void {\n const collapsed = this.#overflowing && !this.#expanded;\n for (const item of this.collapsibleTargets) item.hidden = collapsed;\n if (this.hasEllipsisTarget) this.ellipsisTarget.hidden = !this.#overflowing;\n if (this.hasTriggerTarget) {\n this.triggerTarget.setAttribute(\"aria-expanded\", this.#expanded ? \"true\" : \"false\");\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/blur_deferral.ts","../../src/utils/layout_observer.ts","../../src/controllers/breadcrumb_controller.ts"],"names":[],"mappings":";;;;;AAoDO,IAAM,eAAN,MAAwD;AAAA;AAAA,EAEpD,QAAA,uBAAe,GAAA,EAAmB;AAAA;AAAA,EAElC,UAAA;AAAA;AAAA,EAGT,YAAY,SAAA,EAAiC;AAC3C,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA;AAAA,EACpB;AAAA;AAAA,EAGA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,QAAA,CAAS,IAAA;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,QAAA,GAAgB;AAClB,IAAA,OAAO,CAAC,GAAG,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AAAA,EACjC;AAAA;AAAA,EAGA,IAAI,OAAA,EAAqB;AACvB,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,MAAM,OAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA,EAAG;AAChC,IAAA,MAAM,SAAS,MAAY;AACzB,MAAA,IAAA,CAAK,QAAQ,OAAO,CAAA;AACpB,MAAA,IAAA,CAAK,WAAW,OAAO,CAAA;AAAA,IACzB,CAAA;AACA,IAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAA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AAI,IAAA,CAAK,iBAAA,EAAmB,IAAA,CAAK,wBAAA,CAAyB,YAAY,CAAA;AACtE,IAAA,IAAI,KAAK,gBAAA,EAAkB;AAEzB,MAAA,MAAM,QAAA,GAAW,IAAA,CAAK,YAAA,IAAgB,IAAA,CAAK,SAAA;AAC3C,MAAA,IAAA,CAAK,aAAA,CAAc,YAAA,CAAa,eAAA,EAAiB,QAAA,GAAW,SAAS,OAAO,CAAA;AAAA,IAC9E;AACA,IAAA,IAAI,WAAA,EAAa,IAAA,CAAK,aAAA,CAAc,KAAA,EAAM;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,yBAAyB,IAAA,EAAqB;AAC5C,IAAA,MAAM,WAAW,IAAA,CAAK,cAAA;AACtB,IAAA,IAAI,IAAA,EAAM;AACR,MAAA,IAAA,CAAK,cAAc,UAAA,EAAW;AAC9B,MAAA,QAAA,CAAS,MAAA,GAAS,KAAA;AAClB,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,SAAS,QAAA,CAAS,aAAA;AACxB,IAAA,IAAI,MAAA,YAAkB,WAAA,IAAe,QAAA,CAAS,QAAA,CAAS,MAAM,CAAA,EAAG;AAC9D,MAAA,QAAA,CAAS,MAAA,GAAS,KAAA;AAClB,MAAA,IAAA,CAAK,aAAA,CAAc,UAAU,MAAM,CAAA;AACnC,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,cAAc,UAAA,EAAW;AAC9B,IAAA,QAAA,CAAS,MAAA,GAAS,IAAA;AAAA,EACpB;AAAA;AAAA,EAGA,YAAY,OAAA,EAA+B;AACzC,IAAA,MAAM,SAAS,QAAA,CAAS,aAAA;AACxB,IAAA,OAAO,MAAA,YAAkB,WAAA,IAAe,OAAA,CAAQ,QAAA,CAAS,MAAM,CAAA;AAAA,EACjE;AACF","file":"breadcrumb_controller.js","sourcesContent":["/**\n * Shared bookkeeping for updates that must wait until an element loses focus.\n *\n * A control that becomes redundant while the user is standing on it cannot be\n * removed from the page immediately: hiding a focused element (or turning it\n * into a native `disabled` one) drops focus to `<body>`, stranding a keyboard\n * user mid-widget. The fix every affected controller reached for is the same —\n * keep the element reachable, hold the destructive update, listen for `blur`,\n * and apply it then.\n *\n * {@link BlurDeferral} owns *only* the registry part of that: which elements are\n * currently holding an update back, attaching and detaching the `blur` listener,\n * and guaranteeing teardown. It is deliberately **policy-free** — what the\n * interim state looks like (`aria-disabled`, an ownership marker, nothing at\n * all), and what the deferred update actually is, stay in the controller, which\n * receives the element back through its release callback.\n *\n * Three contracts are worth stating up front, because each one is a hazard the\n * consumers would otherwise hit:\n *\n * - **The release callback fires only on a real `blur`.** `release()` /\n * `releaseAll()` *cancel* a deferral; they do not complete it. Conflating the\n * two makes `overflow-indicator` disable a button that just left the boundary.\n * - **`elements` is a snapshot.** Iterating the live key set while releasing\n * inside the loop is the failure this registry exists to prevent.\n * - **The entry is detached before the callback runs**, so a controller that\n * decides the update is still unsafe can simply defer again.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and contracts belong on the members.\n *\n * @example\n * ```ts\n * readonly #deferred = new BlurDeferral<HTMLElement>((trigger) => {\n * if (this.#connected) this.#evaluate();\n * });\n *\n * #hide(trigger: HTMLElement) {\n * if (document.activeElement === trigger) {\n * this.#deferred.deferOnly(trigger); // stays visible until blur\n * return;\n * }\n * this.#deferred.releaseAll();\n * trigger.hidden = true;\n * }\n *\n * disconnect() {\n * this.#deferred.releaseAll();\n * }\n * ```\n */\nexport class BlurDeferral<T extends HTMLElement = HTMLElement> {\n /** Elements currently holding an update back, mapped to their `blur` listener. */\n readonly #pending = new Map<T, () => void>();\n /** Called after a pending element blurs and has been detached. */\n readonly #onRelease: (element: T) => void;\n\n /** @param onRelease - Invoked once `element` actually blurs; never on `release`. */\n constructor(onRelease: (element: T) => void) {\n this.#onRelease = onRelease;\n }\n\n /** Number of elements currently holding an update back. */\n get size(): number {\n return this.#pending.size;\n }\n\n /** Snapshot of the pending elements, safe to iterate while releasing them. */\n get elements(): T[] {\n return [...this.#pending.keys()];\n }\n\n /** Whether `element` is currently holding an update back. */\n has(element: T): boolean {\n return this.#pending.has(element);\n }\n\n /** Holds an update back until `element` blurs. Idempotent (no stacked listeners). */\n defer(element: T): void {\n if (this.#pending.has(element)) return;\n const onBlur = (): void => {\n this.#detach(element);\n this.#onRelease(element);\n };\n this.#pending.set(element, onBlur);\n element.addEventListener(\"blur\", onBlur);\n }\n\n /** Defers `element` as the only pending entry, cancelling any others. */\n deferOnly(element: T): void {\n for (const pending of this.elements) {\n if (pending !== element) this.#detach(pending);\n }\n this.defer(element);\n }\n\n /** Cancels `element`'s deferral without completing it; no-ops when not pending. */\n release(element: T): void {\n this.#detach(element);\n }\n\n /** Cancels every deferral without completing any of them. */\n releaseAll(): void {\n for (const element of this.elements) this.#detach(element);\n }\n\n /** Removes the `blur` listener for `element` and forgets it. */\n #detach(element: T): void {\n const onBlur = this.#pending.get(element);\n if (onBlur) element.removeEventListener(\"blur\", onBlur);\n this.#pending.delete(element);\n }\n}\n","/**\n * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Layout-sensitive widgets (sliders, resizable panes, scroll spies, popovers)\n * need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { BlurDeferral } from \"../utils/blur_deferral\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\n\n/**\n * Sub-pixel tolerance (px) applied to the overflow comparison.\n *\n * Fractional layout metrics (zoom, `border-box` rounding, fractional font\n * metrics) routinely make `scrollWidth` exceed `clientWidth` by a fraction of a\n * pixel on a trail that visually fits, which would collapse it for no reason.\n * Same constant and rationale as `scroll_area_controller.ts`'s `EDGE_EPSILON`.\n */\nconst OVERFLOW_EPSILON = 1;\n\n/**\n * Headless, accessible responsive breadcrumb behavior.\n *\n * Markup contract (identifier: `stimeo--breadcrumb`):\n * <nav data-controller=\"stimeo--breadcrumb\" aria-label=\"Breadcrumb\">\n * <ol data-stimeo--breadcrumb-target=\"list\">\n * <li><a href=\"/\">Home</a></li>\n * <li data-stimeo--breadcrumb-target=\"ellipsis\" hidden>\n * <button type=\"button\" aria-expanded=\"false\" aria-controls=\"bc-a bc-b\"\n * aria-label=\"Show full path\"\n * data-stimeo--breadcrumb-target=\"trigger\"\n * data-action=\"click->stimeo--breadcrumb#toggle\">…</button>\n * </li>\n * <li id=\"bc-a\" data-stimeo--breadcrumb-target=\"collapsible\"><a href=\"/a\">Section A</a></li>\n * <li id=\"bc-b\" data-stimeo--breadcrumb-target=\"collapsible\"><a href=\"/a/b\">Sub B</a></li>\n * <li><a href=\"/a/b/c\" aria-current=\"page\">Item C</a></li>\n * </ol>\n * </nav>\n *\n * Implements the WAI-ARIA APG **Breadcrumb** pattern. The base structure (`nav`\n * + `ol` + `aria-current=\"page\"`) lives in the markup; this controller adds the\n * responsive behavior: when the trail overflows its container it collapses the\n * author-marked middle items behind a disclosure (`…`) button, which expands\n * them back on demand.\n *\n * @remarks\n * Behavior only — the consumer owns separators (CSS) and the look. The items to\n * collapse are the author-marked `collapsible` targets (the source of truth),\n * placed between the leading and trailing items that must always stay visible.\n *\n * Behavior provided:\n * - Detects overflow via {@link LayoutObserver} (element + viewport resize) and a\n * `MutationObserver` on the list (content edits, Turbo Stream / morph item\n * swaps); the public `update` action re-measures on demand.\n * - While overflowing and not expanded, hides the `collapsible` items and shows\n * the `ellipsis` item; when it fits, shows everything, hides the ellipsis and\n * resets the expanded state (so a later collapse starts collapsed).\n * - The disclosure `trigger` toggles `aria-expanded` and the collapsed items,\n * dispatching `stimeo--breadcrumb:toggle`. `toggle` is a no-op (no state\n * change, no event) while the trail fits, so a hidden trigger can never be\n * left reporting `aria-expanded=\"true\"`.\n *\n * Layout requirements the behavior depends on:\n * - **The list must not wrap** (`white-space: nowrap` / `flex-wrap: nowrap`). A\n * wrapping list grows in height instead of scroll width, so\n * `scrollWidth === clientWidth` always holds and overflow is never detected.\n * - **The list width must follow its container** (no shrink-to-fit / intrinsic\n * width). Overflow is re-measured synchronously inside the resize\n * notification, so a list that widens to its content would never report\n * overflow. There is deliberately no debounce: the pass is one write → one\n * forced read → one write on a single element.\n * - Consumers must not neutralize `[hidden]` (e.g. `display: inline-flex` on the\n * items wins over the UA's `[hidden] { display: none }`); collapsing is\n * expressed exclusively through the `hidden` attribute.\n *\n * Ownership of `hidden`: this controller owns the attribute on an element **for as\n * long as that element is a `collapsible` target and the controller is connected**.\n * Outside that window it does not write it:\n * - lose the marker while connected → the element becomes an always-visible item\n * and the controller clears the `hidden` it owned;\n * - controller `disconnect()` → the collapsed state is left in the DOM on purpose,\n * because that DOM is what Turbo caches and restores.\n *\n * A consumer that also wants to own `hidden` on the same element (for a reason of\n * its own) is not supported: `#measureOverflow` clears it on every measurement to\n * read the expanded width.\n *\n * Focus safety: hiding the element the user is standing on would drop focus to\n * `<body>`. When a collapse would hide the focused item, focus moves to the\n * disclosure `trigger` first; when the ellipsis would be hidden while it holds\n * focus, the hide waits for `blur`.\n *\n * **Fail-safe when the disclosure is incomplete.** Collapsing needs all of\n * `list`, one `collapsible`, `ellipsis`, and `trigger`; miss any and the trail\n * degrades to a plain APG breadcrumb (every item visible, ellipsis hidden,\n * `aria-expanded=\"false\"`, `toggle` a silent no-op). Hiding the middle items\n * with no control that can reveal them puts the path out of reach for good — a\n * too-wide trail is the cheaper failure. Watched at runtime, so a swap that\n * breaks the set releases the items and one that completes it starts collapsing.\n */\nexport class BreadcrumbController extends Controller<HTMLElement> {\n static override targets = [\"list\", \"collapsible\", \"ellipsis\", \"trigger\"];\n static actions = [\"toggle\", \"update\"] as const;\n static events = [\"toggle\"] as const;\n\n declare readonly listTarget: HTMLElement;\n declare readonly collapsibleTargets: HTMLElement[];\n declare readonly ellipsisTarget: HTMLElement;\n declare readonly triggerTarget: HTMLElement;\n declare readonly hasListTarget: boolean;\n declare readonly hasEllipsisTarget: boolean;\n declare readonly hasTriggerTarget: boolean;\n\n /** Guards target callbacks that can fire outside the connected window. */\n #connected = false;\n /** Whether the trail currently overflows its container. */\n #overflowing = false;\n /** Whether the user has expanded the collapsed items via the disclosure. */\n #expanded = false;\n /** The list element currently observed (resize + mutations), if any. */\n #observedList: HTMLElement | null = null;\n #listMutations: MutationObserver | null = null;\n readonly #layout = new LayoutObserver(() => this.update());\n\n readonly #onListMutation = (): void => {\n this.update();\n };\n\n /** Holds the ellipsis hide back while it contains focus; re-renders on blur. */\n readonly #deferredHide = new BlurDeferral(() => {\n this.#render();\n });\n\n /** Starts observing for overflow and renders the initial state. */\n override connect(): void {\n this.#connected = true;\n // The DOM is the source of truth on reconnect (Turbo cache restore / morph):\n // the trigger's `aria-expanded` is where the expanded state lives, so a trail\n // the user opened survives a back-navigation instead of silently re-collapsing.\n this.#expanded = this.#initialExpanded();\n this.#layout.observeViewport();\n this.#syncListObservation();\n this.update();\n }\n\n /** Releases the resize/mutation observation (Turbo navigation included). */\n override disconnect(): void {\n this.#connected = false;\n this.#deferredHide.releaseAll();\n this.#stopObservingList();\n this.#layout.disconnect();\n }\n\n listTargetConnected(): void {\n this.#resync();\n }\n\n listTargetDisconnected(): void {\n this.#resync();\n }\n\n collapsibleTargetConnected(): void {\n this.#resync();\n }\n\n /**\n * Re-measures when the disclosure set gains or loses a member. The set is a\n * precondition for collapsing at all, so it needs the same watching the list\n * and items get: without these callbacks a swap that breaks or completes the\n * set would only take effect at the next resize or list mutation, which may\n * never come.\n */\n ellipsisTargetConnected(): void {\n this.#resync();\n }\n\n ellipsisTargetDisconnected(): void {\n this.#resync();\n }\n\n triggerTargetConnected(): void {\n this.#resync();\n }\n\n triggerTargetDisconnected(): void {\n this.#resync();\n }\n\n /**\n * Hands `hidden` back when an element stops being a `collapsible` target.\n *\n * The marker is the source of truth for what may be collapsed, so an element\n * that loses it while the controller is live is an always-visible item again —\n * and `#render` only walks the *current* targets, so nothing else would ever\n * clear the `hidden` this controller put there.\n *\n * The `#connected` guard is load-bearing, not defensive. Stimulus fires this\n * callback for **every** target during teardown as well (`Context.disconnect()`\n * stops the target observer after `disconnect()` has run), and there the\n * collapsed DOM must survive untouched so Turbo's cache restores the trail in\n * the state the user left it (see the ownership note in {@link BreadcrumbController}).\n *\n * @param element - the element that just left the `collapsible` target set\n */\n collapsibleTargetDisconnected(element: HTMLElement): void {\n if (this.#connected) element.hidden = false;\n this.#resync();\n }\n\n /**\n * Expands or re-collapses the trail and dispatches `toggle`.\n *\n * No-op while the trail fits: there is nothing collapsed to reveal, and the\n * (hidden) trigger would otherwise keep a stale `aria-expanded=\"true\"` that\n * surfaces pre-expanded the next time the trail overflows. No event is\n * dispatched in that case.\n */\n toggle(): void {\n if (!this.#connected || !this.#overflowing) return;\n this.#expanded = !this.#expanded;\n this.#render();\n this.dispatch(\"toggle\", { detail: { expanded: this.#expanded } });\n }\n\n /**\n * Re-measures overflow and re-renders. Wired to resizes and list mutations;\n * exposed as an action so consumers can re-measure after a change the\n * observers cannot see (e.g. a web font swap that only alters text width).\n */\n update(): void {\n if (!this.#connected) return;\n this.#overflowing = this.#measureOverflow();\n if (!this.#overflowing) this.#expanded = false;\n this.#render();\n }\n\n /** Re-attaches the list observation (targets may have been swapped) and re-measures. */\n #resync(): void {\n if (!this.#connected) return;\n this.#syncListObservation();\n this.update();\n }\n\n /** Reads the expanded state back from its DOM home (the trigger's `aria-expanded`). */\n #initialExpanded(): boolean {\n return this.hasTriggerTarget && this.triggerTarget.getAttribute(\"aria-expanded\") === \"true\";\n }\n\n /**\n * Points the resize + mutation observation at the current `list` target.\n *\n * The list is re-resolved rather than captured at connect so a target swapped\n * at runtime (Turbo Stream replacement of the `<ol>`) is observed too. Only\n * `childList` / `subtree` / `characterData` are watched — deliberately **not**\n * `attributes`, which the controller's own `hidden` writes would re-trigger.\n */\n #syncListObservation(): void {\n const next = this.hasListTarget ? this.listTarget : null;\n if (next === this.#observedList) return;\n\n this.#stopObservingList();\n if (!next) return;\n\n this.#observedList = next;\n this.#layout.observe(next);\n if (typeof MutationObserver !== \"undefined\") {\n this.#listMutations = new MutationObserver(this.#onListMutation);\n this.#listMutations.observe(next, { childList: true, subtree: true, characterData: true });\n }\n }\n\n #stopObservingList(): void {\n if (this.#observedList) this.#layout.unobserve(this.#observedList);\n this.#observedList = null;\n this.#listMutations?.disconnect();\n this.#listMutations = null;\n }\n\n /**\n * Measures overflow against the **fully expanded** layout so hiding items does\n * not make the condition oscillate. Reveals every item, then compares the list's\n * own scroll width to its own client width; `#render` immediately re-applies\n * the correct hidden state afterward.\n *\n * Both widths are read from the list element itself (not the host `nav`) so the\n * check is independent of any padding/border on the host — comparing against the\n * host's `clientWidth` would over-report the available space by its padding and\n * miss real overflow in a padded container.\n *\n * With no `collapsible` items there is nothing to collapse, so the trail is\n * never reported as overflowing (which also keeps the disclosure out of the\n * tab order — a button controlling nothing).\n *\n * The full disclosure set is a precondition: collapsing without an `ellipsis`\n * *and* a `trigger` would hide items behind a control that does not exist, so\n * an incomplete set reports \"not overflowing\" and `#render` degrades the trail\n * to a plain breadcrumb. Losing layout is recoverable; losing the path is not.\n */\n #measureOverflow(): boolean {\n if (!this.hasListTarget || this.collapsibleTargets.length === 0) return false;\n if (!this.hasEllipsisTarget || !this.hasTriggerTarget) return false;\n for (const item of this.collapsibleTargets) item.hidden = false;\n // No `hasEllipsisTarget` check: the line above already returned without one.\n this.ellipsisTarget.hidden = true;\n return this.listTarget.scrollWidth > this.listTarget.clientWidth + OVERFLOW_EPSILON;\n }\n\n /** Applies the collapsed/expanded state to the items, ellipsis, and trigger. */\n #render(): void {\n const collapsed = this.#overflowing && !this.#expanded;\n const showEllipsis = this.#overflowing && this.collapsibleTargets.length > 0;\n\n // Decided *before* the writes below: once a focused item is hidden the browser\n // drops focus to <body> and the information is gone (same reasoning as\n // `overflow_menu_controller`'s pre-move focus decision).\n const rescueFocus =\n collapsed &&\n this.hasTriggerTarget &&\n this.collapsibleTargets.some((i) => this.#holdsFocus(i));\n\n for (const item of this.collapsibleTargets) item.hidden = collapsed;\n if (this.hasEllipsisTarget) this.#applyEllipsisVisibility(showEllipsis);\n if (this.hasTriggerTarget) {\n // Never report expanded while the trail fits: the trigger is hidden then.\n const expanded = this.#overflowing && this.#expanded;\n this.triggerTarget.setAttribute(\"aria-expanded\", expanded ? \"true\" : \"false\");\n }\n if (rescueFocus) this.triggerTarget.focus();\n }\n\n /**\n * Shows or hides the ellipsis item, deferring a hide that would blur the user.\n *\n * Hiding the element that currently holds focus drops focus to `<body>`, so the\n * hide waits for that element's `blur` and is re-applied then (the shared\n * `BlurDeferral` registry).\n */\n #applyEllipsisVisibility(show: boolean): void {\n const ellipsis = this.ellipsisTarget;\n if (show) {\n this.#deferredHide.releaseAll();\n ellipsis.hidden = false;\n return;\n }\n\n const active = document.activeElement;\n if (active instanceof HTMLElement && ellipsis.contains(active)) {\n ellipsis.hidden = false;\n this.#deferredHide.deferOnly(active);\n return;\n }\n\n this.#deferredHide.releaseAll();\n ellipsis.hidden = true;\n }\n\n /** Whether `element` contains (or is) the currently focused element. */\n #holdsFocus(element: HTMLElement): boolean {\n const active = document.activeElement;\n return active instanceof HTMLElement && element.contains(active);\n }\n}\n"]}
|
|
@@ -92,7 +92,17 @@ declare class CalendarController extends Controller<HTMLElement> {
|
|
|
92
92
|
selectByClick(event: MouseEvent): void;
|
|
93
93
|
/** Handles grid cell keyboard navigation and triggers selection. */
|
|
94
94
|
onKeydown(event: KeyboardEvent): void;
|
|
95
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Renders the grid days and updates the month/year label, then reports the
|
|
97
|
+
* painted month once it differs from the one already announced.
|
|
98
|
+
*
|
|
99
|
+
* The report belongs to the paint, not to the `month` Value: the Value is only
|
|
100
|
+
* one of the things that decide the month on screen. While a malformed `month`
|
|
101
|
+
* falls back, changing `selected` and selecting a neighbouring month's cell
|
|
102
|
+
* move the painted month too, and both repaint from here. Reading the report
|
|
103
|
+
* off the paint keeps the event naming the month the grid shows, in the
|
|
104
|
+
* `YYYY-MM` the detail contract promises, whichever route repainted.
|
|
105
|
+
*/
|
|
96
106
|
render(): void;
|
|
97
107
|
selectDayElement(dayElement: HTMLElement): void;
|
|
98
108
|
}
|
|
@@ -2,6 +2,22 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/calendar_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/logical_scroll.ts
|
|
6
|
+
function isRtl(element) {
|
|
7
|
+
return window.getComputedStyle(element).direction === "rtl";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/utils/arrow_step.ts
|
|
11
|
+
function logicalArrowKey(key, element) {
|
|
12
|
+
if (key !== "ArrowRight" && key !== "ArrowLeft") return key;
|
|
13
|
+
if (!isRtl(element)) return key;
|
|
14
|
+
return key === "ArrowRight" ? "ArrowLeft" : "ArrowRight";
|
|
15
|
+
}
|
|
16
|
+
function isReservedArrowChord(event, allow = []) {
|
|
17
|
+
if (!event.key.startsWith("Arrow")) return false;
|
|
18
|
+
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
19
|
+
}
|
|
20
|
+
|
|
5
21
|
// src/utils/dates.ts
|
|
6
22
|
function toISODateString(date) {
|
|
7
23
|
const year = date.getFullYear();
|
|
@@ -32,6 +48,9 @@ function parseISOMonthString(monthStr) {
|
|
|
32
48
|
if (month < 1 || month > 12) return null;
|
|
33
49
|
return { year: Number(y), month };
|
|
34
50
|
}
|
|
51
|
+
function toISOMonthString(date) {
|
|
52
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
|
53
|
+
}
|
|
35
54
|
|
|
36
55
|
// src/utils/safe_timeout.ts
|
|
37
56
|
var TimerRegistry = class {
|
|
@@ -87,6 +106,7 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
87
106
|
};
|
|
88
107
|
|
|
89
108
|
// src/controllers/calendar_controller.ts
|
|
109
|
+
var OWNED_DISABLED = "data-stimeo--calendar-owns-disabled";
|
|
90
110
|
var CalendarController = class extends Controller {
|
|
91
111
|
static targets = ["label", "grid", "day"];
|
|
92
112
|
static values = {
|
|
@@ -107,6 +127,13 @@ var CalendarController = class extends Controller {
|
|
|
107
127
|
* controller never steals focus after the element leaves the DOM (Turbo).
|
|
108
128
|
*/
|
|
109
129
|
#focusTimer = new SafeTimeout();
|
|
130
|
+
/**
|
|
131
|
+
* The painted month the last `monthchange` reported, or `null` before the first
|
|
132
|
+
* paint. Settling on the initial month — whether it comes from the attribute or
|
|
133
|
+
* is derived here — is the grid describing itself, not a navigation, so it must
|
|
134
|
+
* not reach a listener that refetches inventory or pushes history.
|
|
135
|
+
*/
|
|
136
|
+
#announcedMonth = null;
|
|
110
137
|
connect() {
|
|
111
138
|
if (!this.monthValue) {
|
|
112
139
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -129,7 +156,6 @@ var CalendarController = class extends Controller {
|
|
|
129
156
|
if (!this.monthValue) return;
|
|
130
157
|
this.#syncFocusedDateWithMonth();
|
|
131
158
|
this.render();
|
|
132
|
-
this.dispatch("monthchange", { detail: { month: this.monthValue } });
|
|
133
159
|
}
|
|
134
160
|
/**
|
|
135
161
|
* Stimulus lifecycle callback triggered automatically when the selectedValue changes.
|
|
@@ -156,25 +182,25 @@ var CalendarController = class extends Controller {
|
|
|
156
182
|
}
|
|
157
183
|
/** Handles day selection when a gridcell is clicked. */
|
|
158
184
|
selectByClick(event) {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
185
|
+
const dayElement = event.target?.closest(
|
|
186
|
+
"[data-stimeo--calendar-target='day']"
|
|
187
|
+
);
|
|
162
188
|
if (!dayElement) return;
|
|
163
189
|
this.selectDayElement(dayElement);
|
|
164
190
|
}
|
|
165
191
|
/** Handles grid cell keyboard navigation and triggers selection. */
|
|
166
192
|
onKeydown(event) {
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
const dayElement = target
|
|
193
|
+
if (event.defaultPrevented) return;
|
|
194
|
+
if (isReservedArrowChord(event)) return;
|
|
195
|
+
const dayElement = event.target?.closest(
|
|
196
|
+
"[data-stimeo--calendar-target='day']"
|
|
197
|
+
);
|
|
170
198
|
if (!dayElement) return;
|
|
171
|
-
const
|
|
172
|
-
if (!dateStr) return;
|
|
173
|
-
const date = parseISODateString(dateStr);
|
|
199
|
+
const date = parseISODateString(dayElement.getAttribute("data-date") ?? "");
|
|
174
200
|
if (!date) return;
|
|
175
201
|
let handled = true;
|
|
176
202
|
let nextDate = new Date(date);
|
|
177
|
-
switch (event.key) {
|
|
203
|
+
switch (logicalArrowKey(event.key, this.element)) {
|
|
178
204
|
case "ArrowLeft":
|
|
179
205
|
nextDate.setDate(nextDate.getDate() - 1);
|
|
180
206
|
break;
|
|
@@ -209,6 +235,10 @@ var CalendarController = class extends Controller {
|
|
|
209
235
|
break;
|
|
210
236
|
case "t":
|
|
211
237
|
case "T": {
|
|
238
|
+
if (event.ctrlKey || event.metaKey || event.altKey) {
|
|
239
|
+
handled = false;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
212
242
|
const now = /* @__PURE__ */ new Date();
|
|
213
243
|
nextDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
214
244
|
break;
|
|
@@ -227,25 +257,50 @@ var CalendarController = class extends Controller {
|
|
|
227
257
|
this.#focusAndNavigateToDate(nextDate);
|
|
228
258
|
}
|
|
229
259
|
}
|
|
230
|
-
/**
|
|
231
|
-
|
|
260
|
+
/**
|
|
261
|
+
* First day of the month the grid paints: the `month` Value when it parses,
|
|
262
|
+
* otherwise the focused date's month.
|
|
263
|
+
*
|
|
264
|
+
* A malformed `month` falls back instead of stopping the paint: every cell
|
|
265
|
+
* keeps its `aria-selected` and the grid keeps its tab stop, so a Value typo
|
|
266
|
+
* still leaves the grid reachable by Tab and the author can see what they
|
|
267
|
+
* typed. Every consumer of "which month is on screen" reads it from here, so
|
|
268
|
+
* the paint and the `monthchange` report cannot name different months.
|
|
269
|
+
*/
|
|
270
|
+
#paintedMonthStart() {
|
|
232
271
|
const monthInfo = parseISOMonthString(this.monthValue);
|
|
233
|
-
|
|
234
|
-
|
|
272
|
+
return monthInfo ? new Date(monthInfo.year, monthInfo.month - 1, 1) : new Date(this.focusedDate.getFullYear(), this.focusedDate.getMonth(), 1);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Renders the grid days and updates the month/year label, then reports the
|
|
276
|
+
* painted month once it differs from the one already announced.
|
|
277
|
+
*
|
|
278
|
+
* The report belongs to the paint, not to the `month` Value: the Value is only
|
|
279
|
+
* one of the things that decide the month on screen. While a malformed `month`
|
|
280
|
+
* falls back, changing `selected` and selecting a neighbouring month's cell
|
|
281
|
+
* move the painted month too, and both repaint from here. Reading the report
|
|
282
|
+
* off the paint keeps the event naming the month the grid shows, in the
|
|
283
|
+
* `YYYY-MM` the detail contract promises, whichever route repainted.
|
|
284
|
+
*/
|
|
285
|
+
render() {
|
|
286
|
+
const monthStart = this.#paintedMonthStart();
|
|
287
|
+
const year = monthStart.getFullYear();
|
|
288
|
+
const month = monthStart.getMonth() + 1;
|
|
235
289
|
if (this.hasLabelTarget) {
|
|
236
290
|
const lang = document.documentElement.lang || "en";
|
|
237
|
-
const labelDate = new Date(year, month - 1, 1);
|
|
238
291
|
const formatter = new Intl.DateTimeFormat(lang, { month: "long", year: "numeric" });
|
|
239
|
-
this.labelTarget.textContent = formatter.format(
|
|
292
|
+
this.labelTarget.textContent = formatter.format(monthStart);
|
|
240
293
|
}
|
|
241
294
|
const days = this.#calculateGridDays(year, month);
|
|
242
295
|
const dayElements = this.dayTargets;
|
|
243
|
-
for (
|
|
244
|
-
const el = dayElements[
|
|
296
|
+
for (const [index, date] of days.entries()) {
|
|
297
|
+
const el = dayElements[index];
|
|
245
298
|
if (!el) continue;
|
|
246
|
-
const date = days[i];
|
|
247
|
-
if (!date) continue;
|
|
248
299
|
const dateStr = toISODateString(date);
|
|
300
|
+
if (el.getAttribute("data-date") !== dateStr) {
|
|
301
|
+
el.removeAttribute("aria-disabled");
|
|
302
|
+
el.removeAttribute(OWNED_DISABLED);
|
|
303
|
+
}
|
|
249
304
|
el.setAttribute("data-date", dateStr);
|
|
250
305
|
el.textContent = String(date.getDate());
|
|
251
306
|
const isOutside = date.getFullYear() !== year || date.getMonth() !== month - 1;
|
|
@@ -258,11 +313,23 @@ var CalendarController = class extends Controller {
|
|
|
258
313
|
el.setAttribute("tabindex", isFocused ? "0" : "-1");
|
|
259
314
|
const isDisabled = this.#isDateOutOfBounds(dateStr);
|
|
260
315
|
if (isDisabled) {
|
|
316
|
+
if (!el.hasAttribute("aria-disabled")) el.setAttribute(OWNED_DISABLED, "");
|
|
261
317
|
el.setAttribute("aria-disabled", "true");
|
|
262
|
-
} else {
|
|
318
|
+
} else if (el.hasAttribute(OWNED_DISABLED)) {
|
|
263
319
|
el.removeAttribute("aria-disabled");
|
|
320
|
+
el.removeAttribute(OWNED_DISABLED);
|
|
264
321
|
}
|
|
265
322
|
}
|
|
323
|
+
if (!dayElements.some((el) => el.getAttribute("tabindex") === "0")) {
|
|
324
|
+
const fallback = dayElements.find((el) => el.getAttribute("data-outside") === "false") ?? dayElements[0];
|
|
325
|
+
fallback?.setAttribute("tabindex", "0");
|
|
326
|
+
}
|
|
327
|
+
const painted = toISOMonthString(monthStart);
|
|
328
|
+
const previous = this.#announcedMonth;
|
|
329
|
+
this.#announcedMonth = painted;
|
|
330
|
+
if (previous !== null && previous !== painted) {
|
|
331
|
+
this.dispatch("monthchange", { detail: { month: painted } });
|
|
332
|
+
}
|
|
266
333
|
}
|
|
267
334
|
selectDayElement(dayElement) {
|
|
268
335
|
if (dayElement.getAttribute("aria-disabled") === "true") return;
|