stimeo-ui 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +59 -0
- data/dist/controllers/alert_dialog_controller.js +318 -0
- data/dist/controllers/carousel_controller.js +272 -0
- data/dist/controllers/clipboard_controller.js +144 -0
- data/dist/controllers/collapsible_controller.js +327 -0
- data/dist/controllers/color_picker_controller.js +213 -0
- data/dist/controllers/count_up_controller.js +8 -1
- data/dist/controllers/currency_input_controller.js +147 -0
- data/dist/controllers/data_grid_controller.js +168 -0
- data/dist/controllers/date_range_picker_controller.js +417 -0
- data/dist/controllers/dismissible_controller.js +117 -0
- data/dist/controllers/drawer_controller.js +630 -0
- data/dist/controllers/editable_controller.js +168 -0
- data/dist/controllers/file_dropzone_controller.js +165 -0
- data/dist/controllers/filter_controller.js +86 -0
- data/dist/controllers/flash_controller.js +36 -5
- data/dist/controllers/highlight_controller.js +6 -4
- data/dist/controllers/intersection_controller.js +41 -18
- data/dist/controllers/lazy_frame_controller.js +33 -11
- data/dist/controllers/masonry_controller.js +142 -0
- data/dist/controllers/menubar_controller.js +433 -0
- data/dist/controllers/multi_select_controller.js +472 -0
- data/dist/controllers/navigation_menu_controller.js +384 -0
- data/dist/controllers/overflow_indicator_controller.js +178 -27
- data/dist/controllers/password_reveal_controller.js +117 -0
- data/dist/controllers/range_slider_controller.js +166 -0
- data/dist/controllers/read_more_controller.js +194 -0
- data/dist/controllers/scroll_area_controller.js +15 -2
- data/dist/controllers/scroll_restore_controller.js +93 -0
- data/dist/controllers/scroll_visibility_controller.js +8 -4
- data/dist/controllers/scrollspy_controller.js +33 -11
- data/dist/controllers/separator_controller.js +87 -0
- data/dist/controllers/sidebar_controller.js +761 -0
- data/dist/controllers/stepper_controller.js +28 -12
- data/dist/controllers/stick_to_bottom_controller.js +8 -4
- data/dist/controllers/sticky_observer_controller.js +88 -20
- data/dist/controllers/tags_input_controller.js +275 -0
- data/dist/controllers/theme_controller.js +20 -10
- data/dist/controllers/time_picker_controller.js +212 -0
- data/dist/controllers/toast_controller.js +36 -9
- data/dist/controllers/transition_controller.js +153 -38
- data/dist/controllers/tree_view_controller.js +275 -0
- data/dist/index.js +811 -295
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +28 -2
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// src/controllers/navigation_menu_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/escape_layer.ts
|
|
6
|
+
function claimsWhileFocusWithin(element) {
|
|
7
|
+
return () => {
|
|
8
|
+
const active = element.ownerDocument.activeElement;
|
|
9
|
+
return active === null || active === element.ownerDocument.body || element.contains(active);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
var EscapeLayer = class _EscapeLayer {
|
|
13
|
+
static #registries = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
#ownerDocument = null;
|
|
15
|
+
/** Dismissal callback while active; `null` when inactive. */
|
|
16
|
+
#onDismiss = null;
|
|
17
|
+
/** Live predicate deciding whether the layer claims a press; `null` = always. */
|
|
18
|
+
#claims = null;
|
|
19
|
+
/**
|
|
20
|
+
* Activates this layer at the top of its document's Escape stack, installing
|
|
21
|
+
* the document's shared resolver listener if this is its first layer.
|
|
22
|
+
* Re-activating an already-active layer moves it to the top.
|
|
23
|
+
*/
|
|
24
|
+
activate(ownerDocument = document, options) {
|
|
25
|
+
this.deactivate();
|
|
26
|
+
let registry = _EscapeLayer.#registries.get(ownerDocument);
|
|
27
|
+
if (!registry) {
|
|
28
|
+
registry = _EscapeLayer.#createRegistry();
|
|
29
|
+
_EscapeLayer.#registries.set(ownerDocument, registry);
|
|
30
|
+
ownerDocument.addEventListener("keydown", registry.onKeydown);
|
|
31
|
+
}
|
|
32
|
+
registry.stack.push(this);
|
|
33
|
+
this.#ownerDocument = ownerDocument;
|
|
34
|
+
this.#onDismiss = options.onDismiss;
|
|
35
|
+
this.#claims = options.claims ?? null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Removes this layer from its document's Escape stack, uninstalling the
|
|
39
|
+
* shared listener when the stack empties. Safe to call when inactive.
|
|
40
|
+
*/
|
|
41
|
+
deactivate() {
|
|
42
|
+
const ownerDocument = this.#ownerDocument;
|
|
43
|
+
if (!ownerDocument) return;
|
|
44
|
+
const registry = _EscapeLayer.#registries.get(ownerDocument);
|
|
45
|
+
if (registry) {
|
|
46
|
+
const index = registry.stack.lastIndexOf(this);
|
|
47
|
+
if (index >= 0) registry.stack.splice(index, 1);
|
|
48
|
+
if (registry.stack.length === 0) {
|
|
49
|
+
ownerDocument.removeEventListener("keydown", registry.onKeydown);
|
|
50
|
+
_EscapeLayer.#registries.delete(ownerDocument);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
this.#ownerDocument = null;
|
|
54
|
+
this.#onDismiss = null;
|
|
55
|
+
this.#claims = null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether this active layer would own a press right now: it is the topmost
|
|
59
|
+
* layer whose {@link EscapeLayerOptions.claims} passes. Exposed for tests
|
|
60
|
+
* and diagnostics — production dismissal goes through the shared listener.
|
|
61
|
+
*/
|
|
62
|
+
get ownsEscape() {
|
|
63
|
+
const ownerDocument = this.#ownerDocument;
|
|
64
|
+
if (!ownerDocument) return false;
|
|
65
|
+
const registry = _EscapeLayer.#registries.get(ownerDocument);
|
|
66
|
+
if (!registry) return false;
|
|
67
|
+
return _EscapeLayer.#resolveOwner(registry.stack) === this;
|
|
68
|
+
}
|
|
69
|
+
/** Builds a document's registry with its shared resolver listener. */
|
|
70
|
+
static #createRegistry() {
|
|
71
|
+
const registry = {
|
|
72
|
+
stack: [],
|
|
73
|
+
onKeydown: (event) => {
|
|
74
|
+
if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) return;
|
|
75
|
+
const owner = _EscapeLayer.#resolveOwner(registry.stack);
|
|
76
|
+
if (!owner) return;
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
owner.#onDismiss?.();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return registry;
|
|
82
|
+
}
|
|
83
|
+
/** The topmost stack layer whose claims predicate passes, or `null`. */
|
|
84
|
+
static #resolveOwner(stack) {
|
|
85
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
86
|
+
const layer = stack[index];
|
|
87
|
+
if (!layer) continue;
|
|
88
|
+
if (layer.#claims && !layer.#claims()) continue;
|
|
89
|
+
return layer;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/utils/safe_timeout.ts
|
|
96
|
+
var TimerRegistry = class {
|
|
97
|
+
/** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
|
|
98
|
+
ids = /* @__PURE__ */ new Set();
|
|
99
|
+
/**
|
|
100
|
+
* Cancels a single tracked timer.
|
|
101
|
+
*
|
|
102
|
+
* No-ops if the id is unknown (already cleared, fired, or never owned by this
|
|
103
|
+
* registry), so callers can clear defensively without guarding.
|
|
104
|
+
*/
|
|
105
|
+
clear(id) {
|
|
106
|
+
if (this.ids.delete(id)) {
|
|
107
|
+
this.cancel(id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Cancels every tracked timer. Call this from a controller's `disconnect()`
|
|
112
|
+
* to guarantee no timer outlives the element.
|
|
113
|
+
*/
|
|
114
|
+
clearAll() {
|
|
115
|
+
for (const id of this.ids) {
|
|
116
|
+
this.cancel(id);
|
|
117
|
+
}
|
|
118
|
+
this.ids.clear();
|
|
119
|
+
}
|
|
120
|
+
/** Number of timers currently tracked (pending). */
|
|
121
|
+
get size() {
|
|
122
|
+
return this.ids.size;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var SafeTimeout = class extends TimerRegistry {
|
|
126
|
+
/**
|
|
127
|
+
* Schedules `callback` after `delay` ms and returns the timer id.
|
|
128
|
+
*
|
|
129
|
+
* The id is removed from the registry automatically when the timeout fires,
|
|
130
|
+
* so {@link TimerRegistry.size | size} reflects only still-pending timers.
|
|
131
|
+
*/
|
|
132
|
+
set(callback, delay) {
|
|
133
|
+
const id = this.schedule(() => {
|
|
134
|
+
this.ids.delete(id);
|
|
135
|
+
callback();
|
|
136
|
+
}, delay);
|
|
137
|
+
this.ids.add(id);
|
|
138
|
+
return id;
|
|
139
|
+
}
|
|
140
|
+
schedule(callback, delay) {
|
|
141
|
+
return window.setTimeout(callback, delay);
|
|
142
|
+
}
|
|
143
|
+
cancel(id) {
|
|
144
|
+
window.clearTimeout(id);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/controllers/navigation_menu_controller.ts
|
|
149
|
+
var NavigationMenuController = class extends Controller {
|
|
150
|
+
static targets = ["trigger", "panel", "hoverArea"];
|
|
151
|
+
static values = {
|
|
152
|
+
openOnHover: { type: Boolean, default: false },
|
|
153
|
+
hoverDelay: { type: Number, default: 150 }
|
|
154
|
+
};
|
|
155
|
+
static actions = ["onTriggerKeydown", "toggle"];
|
|
156
|
+
/** Open/close delay timers for hover mode; cleared together on disconnect. */
|
|
157
|
+
#hoverTimers = new SafeTimeout();
|
|
158
|
+
/**
|
|
159
|
+
* Elements currently carrying hover listeners. Removal always mirrors this
|
|
160
|
+
* set (not a recomputed target snapshot), so add/remove stays symmetric even
|
|
161
|
+
* when targets churn between connect and disconnect.
|
|
162
|
+
*/
|
|
163
|
+
#hoverWired = /* @__PURE__ */ new Set();
|
|
164
|
+
/** Escape-stack membership while any panel is open; the shared resolver dismisses via it. */
|
|
165
|
+
#escapeLayer = new EscapeLayer();
|
|
166
|
+
/** Establishes the closed baseline and the dismissal listeners. */
|
|
167
|
+
connect() {
|
|
168
|
+
this.#closeAll();
|
|
169
|
+
document.addEventListener("click", this.#onOutsideClick);
|
|
170
|
+
this.element.addEventListener("focusout", this.#onFocusOut);
|
|
171
|
+
if (this.openOnHoverValue) this.#addHoverListeners();
|
|
172
|
+
}
|
|
173
|
+
/** Removes every listener, pending hover timer, and stack membership registered while connected. */
|
|
174
|
+
disconnect() {
|
|
175
|
+
this.#escapeLayer.deactivate();
|
|
176
|
+
document.removeEventListener("click", this.#onOutsideClick);
|
|
177
|
+
this.element.removeEventListener("focusout", this.#onFocusOut);
|
|
178
|
+
this.#removeHoverListeners();
|
|
179
|
+
this.#hoverTimers.clearAll();
|
|
180
|
+
}
|
|
181
|
+
/** Re-wires hover listeners when a target is added after connect (Turbo Streams etc.). */
|
|
182
|
+
triggerTargetConnected() {
|
|
183
|
+
this.#rewireHoverListeners();
|
|
184
|
+
}
|
|
185
|
+
/** Re-wires hover listeners when a target is removed while connected. */
|
|
186
|
+
triggerTargetDisconnected() {
|
|
187
|
+
this.#rewireHoverListeners();
|
|
188
|
+
}
|
|
189
|
+
/** See {@link NavigationMenuController.triggerTargetConnected}. */
|
|
190
|
+
panelTargetConnected() {
|
|
191
|
+
this.#rewireHoverListeners();
|
|
192
|
+
}
|
|
193
|
+
/** See {@link NavigationMenuController.triggerTargetDisconnected}. */
|
|
194
|
+
panelTargetDisconnected() {
|
|
195
|
+
this.#rewireHoverListeners();
|
|
196
|
+
}
|
|
197
|
+
/** See {@link NavigationMenuController.triggerTargetConnected}. */
|
|
198
|
+
hoverAreaTargetConnected() {
|
|
199
|
+
this.#rewireHoverListeners();
|
|
200
|
+
}
|
|
201
|
+
/** See {@link NavigationMenuController.triggerTargetDisconnected}. */
|
|
202
|
+
hoverAreaTargetDisconnected() {
|
|
203
|
+
this.#rewireHoverListeners();
|
|
204
|
+
}
|
|
205
|
+
/** Toggles a trigger's panel (single-open). Bound via `data-action` (click). */
|
|
206
|
+
toggle(event) {
|
|
207
|
+
const trigger = event.currentTarget;
|
|
208
|
+
if (this.#isExpanded(trigger)) {
|
|
209
|
+
this.#closePanel(trigger);
|
|
210
|
+
} else {
|
|
211
|
+
this.#openPanel(trigger);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** `ArrowLeft`/`ArrowRight` move focus between triggers (keeping Tab order). */
|
|
215
|
+
onTriggerKeydown(event) {
|
|
216
|
+
const triggers = this.triggerTargets;
|
|
217
|
+
const index = triggers.indexOf(event.currentTarget);
|
|
218
|
+
if (index === -1) return;
|
|
219
|
+
const length = triggers.length;
|
|
220
|
+
if (event.key === "ArrowRight") {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
triggers[(index + 1) % length]?.focus();
|
|
223
|
+
} else if (event.key === "ArrowLeft") {
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
triggers[(index - 1 + length) % length]?.focus();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** Opens `trigger`'s panel, closing any other open panel first. */
|
|
229
|
+
#openPanel(trigger) {
|
|
230
|
+
this.#closeAll();
|
|
231
|
+
const panel = this.#panelFor(trigger);
|
|
232
|
+
if (!panel) return;
|
|
233
|
+
panel.hidden = false;
|
|
234
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
235
|
+
this.#syncEscapeLayer();
|
|
236
|
+
}
|
|
237
|
+
/** Closes `trigger`'s panel and reflects the collapsed state. */
|
|
238
|
+
#closePanel(trigger) {
|
|
239
|
+
const panel = this.#panelFor(trigger);
|
|
240
|
+
if (panel) panel.hidden = true;
|
|
241
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
242
|
+
this.#syncEscapeLayer();
|
|
243
|
+
}
|
|
244
|
+
/** Closes every open panel. */
|
|
245
|
+
#closeAll() {
|
|
246
|
+
for (const trigger of this.triggerTargets) this.#closePanel(trigger);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Aligns Escape-stack membership with the open state: joins (or re-asserts to
|
|
250
|
+
* the top) while a panel is open, leaves once none is. Re-asserting when the
|
|
251
|
+
* user switches panels is deliberate — the nav is again the newest layer.
|
|
252
|
+
*/
|
|
253
|
+
#syncEscapeLayer() {
|
|
254
|
+
if (this.#isAnyOpen) {
|
|
255
|
+
this.#escapeLayer.activate(document, {
|
|
256
|
+
onDismiss: () => this.#closeAndRestore(),
|
|
257
|
+
claims: claimsWhileFocusWithin(this.element)
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
this.#escapeLayer.deactivate();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/** Closes any open panel and returns focus to its trigger (Escape path). */
|
|
264
|
+
#closeAndRestore() {
|
|
265
|
+
const open = this.#openTrigger;
|
|
266
|
+
if (!open) return;
|
|
267
|
+
this.#closePanel(open);
|
|
268
|
+
open.focus();
|
|
269
|
+
}
|
|
270
|
+
/** Closes panels when a click lands outside the nav element. */
|
|
271
|
+
#onOutsideClick = (event) => {
|
|
272
|
+
if (this.#isAnyOpen && !this.element.contains(event.target)) this.#closeAll();
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Closes (without restoring focus) when focus leaves the nav for a known
|
|
276
|
+
* external destination. A null/non-Node destination is indeterminate:
|
|
277
|
+
* browsers use it for clicks on non-focusable content and for window
|
|
278
|
+
* deactivation, so those never close the nav here (matching the popover
|
|
279
|
+
* convention) — the outside-click handler decides pointer dismissal, and the
|
|
280
|
+
* Escape stack's body-focus claim keeps keyboard dismissal working.
|
|
281
|
+
*/
|
|
282
|
+
#onFocusOut = (event) => {
|
|
283
|
+
const next = event.relatedTarget;
|
|
284
|
+
if (!(next instanceof Node) || this.element.contains(next)) return;
|
|
285
|
+
this.#closeAll();
|
|
286
|
+
};
|
|
287
|
+
/** Opens a trigger's panel after the hover delay (hover mode). */
|
|
288
|
+
#onPointerEnter = (event) => {
|
|
289
|
+
const trigger = this.#triggerForHover(event.currentTarget);
|
|
290
|
+
if (!trigger) return;
|
|
291
|
+
this.#hoverTimers.clearAll();
|
|
292
|
+
this.#hoverTimers.set(() => this.#openPanel(trigger), this.hoverDelayValue);
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Closes the open panel after the hover delay (hover mode) — unless the
|
|
296
|
+
* pointer moved directly into another part of the hover region (an adjacent
|
|
297
|
+
* trigger, panel, or hoverArea): crossing a shared edge must not schedule a
|
|
298
|
+
* spurious close, e.g. a hoverArea whose panel sits outside it as a sibling.
|
|
299
|
+
*/
|
|
300
|
+
#onPointerLeave = (event) => {
|
|
301
|
+
const next = event instanceof MouseEvent ? event.relatedTarget : null;
|
|
302
|
+
if (next instanceof Node && this.#hoverElements.some((el) => el.contains(next))) return;
|
|
303
|
+
this.#hoverTimers.clearAll();
|
|
304
|
+
this.#hoverTimers.set(() => this.#closeAll(), this.hoverDelayValue);
|
|
305
|
+
};
|
|
306
|
+
/** Wires hover open/close on each hover element (opt-in), tracking what was wired. */
|
|
307
|
+
#addHoverListeners() {
|
|
308
|
+
for (const element of this.#hoverElements) {
|
|
309
|
+
element.addEventListener("mouseenter", this.#onPointerEnter);
|
|
310
|
+
element.addEventListener("mouseleave", this.#onPointerLeave);
|
|
311
|
+
this.#hoverWired.add(element);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/** Removes the hover listeners from exactly the elements that were wired. */
|
|
315
|
+
#removeHoverListeners() {
|
|
316
|
+
for (const element of this.#hoverWired) {
|
|
317
|
+
element.removeEventListener("mouseenter", this.#onPointerEnter);
|
|
318
|
+
element.removeEventListener("mouseleave", this.#onPointerLeave);
|
|
319
|
+
}
|
|
320
|
+
this.#hoverWired.clear();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Rebuilds the hover wiring from the current targets. Target callbacks call
|
|
324
|
+
* this so items added or removed after connect (e.g. a Turbo Stream append)
|
|
325
|
+
* participate in hover; the wired-set removal keeps the rebuild symmetric.
|
|
326
|
+
*/
|
|
327
|
+
#rewireHoverListeners() {
|
|
328
|
+
if (!this.openOnHoverValue) return;
|
|
329
|
+
this.#removeHoverListeners();
|
|
330
|
+
this.#addHoverListeners();
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Elements that participate in hover: each `hoverArea`, plus every trigger and
|
|
334
|
+
* panel **not** wrapped by one. A wrapped trigger/panel must defer to its
|
|
335
|
+
* wrapper — its own mouseleave would otherwise schedule a close while the
|
|
336
|
+
* pointer is still inside the area (mouseenter does not re-fire on the wrapper
|
|
337
|
+
* when moving among its descendants), flickering the panel shut.
|
|
338
|
+
*/
|
|
339
|
+
get #hoverElements() {
|
|
340
|
+
const areas = this.hoverAreaTargets;
|
|
341
|
+
const covered = (element) => areas.some((area) => area.contains(element));
|
|
342
|
+
return [
|
|
343
|
+
...areas,
|
|
344
|
+
...this.triggerTargets.filter((trigger) => !covered(trigger)),
|
|
345
|
+
...this.panelTargets.filter((panel) => !covered(panel))
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Resolves the trigger for a hovered element: the trigger itself, the trigger
|
|
350
|
+
* controlling a hovered panel, or the first trigger contained in a hovered
|
|
351
|
+
* `hoverArea` wrapper.
|
|
352
|
+
*/
|
|
353
|
+
#triggerForHover(element) {
|
|
354
|
+
if (this.triggerTargets.includes(element)) return element;
|
|
355
|
+
if (this.panelTargets.includes(element)) {
|
|
356
|
+
return this.triggerTargets.find((trigger) => this.#panelFor(trigger) === element) ?? null;
|
|
357
|
+
}
|
|
358
|
+
if (this.hoverAreaTargets.includes(element)) {
|
|
359
|
+
return this.triggerTargets.find((trigger) => element.contains(trigger)) ?? null;
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
/** The panel controlled by `trigger` (matched by `aria-controls`/`id`). */
|
|
364
|
+
#panelFor(trigger) {
|
|
365
|
+
const id = trigger.getAttribute("aria-controls");
|
|
366
|
+
return id ? this.panelTargets.find((panel) => panel.id === id) ?? null : null;
|
|
367
|
+
}
|
|
368
|
+
/** Whether `trigger`'s panel is currently expanded. */
|
|
369
|
+
#isExpanded(trigger) {
|
|
370
|
+
return trigger.getAttribute("aria-expanded") === "true";
|
|
371
|
+
}
|
|
372
|
+
/** The trigger whose panel is currently open, if any. */
|
|
373
|
+
get #openTrigger() {
|
|
374
|
+
return this.triggerTargets.find((trigger) => this.#isExpanded(trigger)) ?? null;
|
|
375
|
+
}
|
|
376
|
+
/** Whether any panel is currently open. */
|
|
377
|
+
get #isAnyOpen() {
|
|
378
|
+
return this.#openTrigger !== null;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export { NavigationMenuController };
|
|
383
|
+
//# sourceMappingURL=navigation_menu_controller.js.map
|
|
384
|
+
//# sourceMappingURL=navigation_menu_controller.js.map
|
|
@@ -58,7 +58,30 @@ var LayoutObserver = class {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
// src/utils/logical_scroll.ts
|
|
62
|
+
function isRtl(element) {
|
|
63
|
+
return window.getComputedStyle(element).direction === "rtl";
|
|
64
|
+
}
|
|
65
|
+
function logicalScrollMetrics(element, horizontal) {
|
|
66
|
+
const max = Math.max(
|
|
67
|
+
0,
|
|
68
|
+
horizontal ? element.scrollWidth - element.clientWidth : element.scrollHeight - element.clientHeight
|
|
69
|
+
);
|
|
70
|
+
const raw = horizontal ? element.scrollLeft : element.scrollTop;
|
|
71
|
+
const position = horizontal && isRtl(element) ? -raw : raw;
|
|
72
|
+
return { position: Math.min(max, Math.max(0, position)), max };
|
|
73
|
+
}
|
|
74
|
+
function physicalScrollDelta(element, horizontal, logicalDelta) {
|
|
75
|
+
return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/utils/reduced_motion.ts
|
|
79
|
+
function prefersReducedMotion() {
|
|
80
|
+
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
81
|
+
}
|
|
82
|
+
|
|
61
83
|
// src/controllers/overflow_indicator_controller.ts
|
|
84
|
+
var DIRECTION_BUTTON_SELECTOR = "[data-stimeo--overflow-indicator-direction-param]";
|
|
62
85
|
var OverflowIndicatorController = class extends Controller {
|
|
63
86
|
static targets = ["viewport"];
|
|
64
87
|
static values = {
|
|
@@ -67,38 +90,50 @@ var OverflowIndicatorController = class extends Controller {
|
|
|
67
90
|
};
|
|
68
91
|
static actions = ["scrollByPage", "update"];
|
|
69
92
|
static events = ["change"];
|
|
70
|
-
#layout = new LayoutObserver(() =>
|
|
93
|
+
#layout = new LayoutObserver(() => {
|
|
94
|
+
if (this.#connected) this.update();
|
|
95
|
+
});
|
|
96
|
+
#connected = false;
|
|
97
|
+
#observedViewport = null;
|
|
98
|
+
#observedContent = /* @__PURE__ */ new Set();
|
|
71
99
|
#mutationObserver = null;
|
|
100
|
+
#pendingButtonDisables = /* @__PURE__ */ new Map();
|
|
72
101
|
/** Last reported room, so `change` fires only on transitions. */
|
|
73
102
|
#state = null;
|
|
74
103
|
connect() {
|
|
75
|
-
|
|
76
|
-
this.#
|
|
77
|
-
this.#layout.observeViewport();
|
|
78
|
-
if (typeof MutationObserver !== "undefined") {
|
|
79
|
-
this.#mutationObserver = new MutationObserver(() => this.update());
|
|
80
|
-
this.#mutationObserver.observe(this.viewportTarget, {
|
|
81
|
-
childList: true,
|
|
82
|
-
subtree: true,
|
|
83
|
-
characterData: true
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
this.update();
|
|
104
|
+
this.#connected = true;
|
|
105
|
+
this.#syncViewport();
|
|
87
106
|
}
|
|
88
107
|
disconnect() {
|
|
108
|
+
this.#connected = false;
|
|
109
|
+
this.#stopObservingViewport();
|
|
89
110
|
this.#layout.disconnect();
|
|
90
|
-
this.#
|
|
91
|
-
this.#mutationObserver = null;
|
|
111
|
+
this.#clearPendingButtonDisables();
|
|
92
112
|
this.#state = null;
|
|
93
113
|
}
|
|
94
|
-
|
|
114
|
+
viewportTargetConnected() {
|
|
115
|
+
this.#syncViewport();
|
|
116
|
+
}
|
|
117
|
+
viewportTargetDisconnected(viewport) {
|
|
118
|
+
if (this.#observedViewport === viewport) this.#stopObservingViewport();
|
|
119
|
+
this.#syncViewport();
|
|
120
|
+
}
|
|
121
|
+
orientationValueChanged() {
|
|
122
|
+
if (this.#connected) this.update();
|
|
123
|
+
}
|
|
124
|
+
thresholdValueChanged() {
|
|
125
|
+
if (this.#connected) this.update();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Re-measures remaining scroll room and reflects the state hooks.
|
|
129
|
+
* Public so it can be wired to the viewport's `scroll`.
|
|
130
|
+
*/
|
|
95
131
|
update() {
|
|
96
132
|
if (!this.hasViewportTarget) return;
|
|
97
133
|
const vp = this.viewportTarget;
|
|
98
134
|
const horizontal = this.orientationValue !== "vertical";
|
|
99
|
-
const t = this
|
|
100
|
-
const scrollPos
|
|
101
|
-
const maxScroll = horizontal ? vp.scrollWidth - vp.clientWidth : vp.scrollHeight - vp.clientHeight;
|
|
135
|
+
const t = this.#threshold;
|
|
136
|
+
const { position: scrollPos, max: maxScroll } = logicalScrollMetrics(vp, horizontal);
|
|
102
137
|
const start = scrollPos > t;
|
|
103
138
|
const end = scrollPos < maxScroll - t;
|
|
104
139
|
vp.setAttribute("data-overflow-start", start ? "true" : "false");
|
|
@@ -114,11 +149,13 @@ var OverflowIndicatorController = class extends Controller {
|
|
|
114
149
|
if (!this.hasViewportTarget) return;
|
|
115
150
|
const direction = this.#directionFromEvent(event);
|
|
116
151
|
if (!direction) return;
|
|
152
|
+
if (this.#state && !this.#state[direction]) return;
|
|
117
153
|
const vp = this.viewportTarget;
|
|
118
154
|
const horizontal = this.orientationValue !== "vertical";
|
|
119
155
|
const page = horizontal ? vp.clientWidth : vp.clientHeight;
|
|
120
|
-
const
|
|
121
|
-
const
|
|
156
|
+
const logicalDelta = direction === "start" ? -page : page;
|
|
157
|
+
const delta = physicalScrollDelta(vp, horizontal, logicalDelta);
|
|
158
|
+
const behavior = prefersReducedMotion() ? "auto" : "smooth";
|
|
122
159
|
if (horizontal) {
|
|
123
160
|
vp.scrollBy({ left: delta, behavior });
|
|
124
161
|
} else {
|
|
@@ -127,10 +164,16 @@ var OverflowIndicatorController = class extends Controller {
|
|
|
127
164
|
}
|
|
128
165
|
/** Mirrors remaining room onto any direction buttons by toggling `disabled`. */
|
|
129
166
|
#syncButtons(start, end) {
|
|
130
|
-
const
|
|
131
|
-
"[data-stimeo--overflow-indicator
|
|
132
|
-
|
|
167
|
+
for (const button of [...this.#pendingButtonDisables.keys()]) {
|
|
168
|
+
if (!button.isConnected || button.closest("[data-controller~='stimeo--overflow-indicator']") !== this.element) {
|
|
169
|
+
this.#cancelPendingButtonDisable(button);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const buttons = this.element.querySelectorAll(DIRECTION_BUTTON_SELECTOR);
|
|
133
173
|
for (const button of buttons) {
|
|
174
|
+
if (button.closest("[data-controller~='stimeo--overflow-indicator']") !== this.element) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
134
177
|
const direction = button.getAttribute("data-stimeo--overflow-indicator-direction-param");
|
|
135
178
|
if (direction === "start") this.#toggleButton(button, start);
|
|
136
179
|
else if (direction === "end") this.#toggleButton(button, end);
|
|
@@ -143,7 +186,11 @@ var OverflowIndicatorController = class extends Controller {
|
|
|
143
186
|
* whole control disabled) is therefore never blindly re-enabled.
|
|
144
187
|
*/
|
|
145
188
|
#toggleButton(button, hasRoom) {
|
|
189
|
+
if (!this.#pendingButtonDisables.has(button) && button.hasAttribute("data-overflow-indicator-pending-disabled")) {
|
|
190
|
+
this.#cancelPendingButtonDisable(button);
|
|
191
|
+
}
|
|
146
192
|
if (hasRoom) {
|
|
193
|
+
this.#cancelPendingButtonDisable(button);
|
|
147
194
|
if (button.hasAttribute("data-overflow-indicator-disabled")) {
|
|
148
195
|
button.disabled = false;
|
|
149
196
|
button.removeAttribute("data-overflow-indicator-disabled");
|
|
@@ -151,17 +198,121 @@ var OverflowIndicatorController = class extends Controller {
|
|
|
151
198
|
return;
|
|
152
199
|
}
|
|
153
200
|
if (button.disabled) return;
|
|
201
|
+
if (document.activeElement === button) {
|
|
202
|
+
this.#deferButtonDisable(button);
|
|
203
|
+
} else {
|
|
204
|
+
this.#disableButton(button);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Keeps a boundary button focusable until native blur, exposing its temporary
|
|
209
|
+
* inoperability with `aria-disabled` and making its action a no-op meanwhile.
|
|
210
|
+
*/
|
|
211
|
+
#deferButtonDisable(button) {
|
|
212
|
+
if (this.#pendingButtonDisables.has(button)) return;
|
|
213
|
+
button.setAttribute("data-overflow-indicator-pending-disabled", "");
|
|
214
|
+
button.setAttribute(
|
|
215
|
+
"data-overflow-indicator-aria-disabled",
|
|
216
|
+
button.getAttribute("aria-disabled") ?? ""
|
|
217
|
+
);
|
|
218
|
+
button.setAttribute("aria-disabled", "true");
|
|
219
|
+
const onBlur = () => {
|
|
220
|
+
this.#cancelPendingButtonDisable(button);
|
|
221
|
+
if (!button.disabled) this.#disableButton(button);
|
|
222
|
+
};
|
|
223
|
+
this.#pendingButtonDisables.set(button, { onBlur });
|
|
224
|
+
button.addEventListener("blur", onBlur);
|
|
225
|
+
}
|
|
226
|
+
#disableButton(button) {
|
|
154
227
|
button.disabled = true;
|
|
155
228
|
button.setAttribute("data-overflow-indicator-disabled", "");
|
|
156
229
|
}
|
|
230
|
+
#cancelPendingButtonDisable(button) {
|
|
231
|
+
const pending = this.#pendingButtonDisables.get(button);
|
|
232
|
+
if (pending) button.removeEventListener("blur", pending.onBlur);
|
|
233
|
+
this.#pendingButtonDisables.delete(button);
|
|
234
|
+
button.removeAttribute("data-overflow-indicator-pending-disabled");
|
|
235
|
+
const displaced = button.getAttribute("data-overflow-indicator-aria-disabled");
|
|
236
|
+
if (displaced !== null) {
|
|
237
|
+
button.removeAttribute("data-overflow-indicator-aria-disabled");
|
|
238
|
+
if (button.getAttribute("aria-disabled") === "true") {
|
|
239
|
+
if (displaced === "") button.removeAttribute("aria-disabled");
|
|
240
|
+
else button.setAttribute("aria-disabled", displaced);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
#clearPendingButtonDisables() {
|
|
245
|
+
for (const button of [...this.#pendingButtonDisables.keys()]) {
|
|
246
|
+
this.#cancelPendingButtonDisable(button);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Moves resize/mutation/load observation to the current viewport target. */
|
|
250
|
+
#syncViewport() {
|
|
251
|
+
if (!this.#connected) return;
|
|
252
|
+
const next = this.hasViewportTarget ? this.viewportTarget : null;
|
|
253
|
+
if (next === this.#observedViewport) return;
|
|
254
|
+
this.#stopObservingViewport();
|
|
255
|
+
if (!next) return;
|
|
256
|
+
this.#observedViewport = next;
|
|
257
|
+
this.#layout.observe(next);
|
|
258
|
+
this.#layout.observeViewport();
|
|
259
|
+
next.addEventListener("load", this.#onContentLoad, true);
|
|
260
|
+
this.#syncContentObservation();
|
|
261
|
+
if (typeof MutationObserver !== "undefined") {
|
|
262
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
263
|
+
if (!this.#connected || this.#observedViewport !== next) return;
|
|
264
|
+
this.#syncContentObservation();
|
|
265
|
+
this.update();
|
|
266
|
+
});
|
|
267
|
+
this.#mutationObserver.observe(this.element, {
|
|
268
|
+
childList: true,
|
|
269
|
+
subtree: true,
|
|
270
|
+
characterData: true,
|
|
271
|
+
attributes: true,
|
|
272
|
+
attributeFilter: ["class", "style", "hidden"]
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
this.#state = null;
|
|
276
|
+
this.update();
|
|
277
|
+
}
|
|
278
|
+
/** Observes direct content boxes whose resize can change the viewport's scroll extent. */
|
|
279
|
+
#syncContentObservation() {
|
|
280
|
+
const next = new Set(this.#observedViewport?.children ?? []);
|
|
281
|
+
for (const content of this.#observedContent) {
|
|
282
|
+
if (!next.has(content)) {
|
|
283
|
+
this.#layout.unobserve(content);
|
|
284
|
+
this.#observedContent.delete(content);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
for (const content of next) {
|
|
288
|
+
if (!this.#observedContent.has(content)) {
|
|
289
|
+
this.#observedContent.add(content);
|
|
290
|
+
this.#layout.observe(content);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
#stopObservingViewport() {
|
|
295
|
+
this.#mutationObserver?.disconnect();
|
|
296
|
+
this.#mutationObserver = null;
|
|
297
|
+
this.#observedViewport?.removeEventListener("load", this.#onContentLoad, true);
|
|
298
|
+
if (this.#observedViewport) this.#layout.unobserve(this.#observedViewport);
|
|
299
|
+
for (const content of this.#observedContent) this.#layout.unobserve(content);
|
|
300
|
+
this.#observedContent.clear();
|
|
301
|
+
this.#observedViewport = null;
|
|
302
|
+
this.#layout.unobserveViewport();
|
|
303
|
+
}
|
|
304
|
+
#onContentLoad = () => {
|
|
305
|
+
if (this.#connected) this.update();
|
|
306
|
+
};
|
|
307
|
+
get #threshold() {
|
|
308
|
+
const value = this.thresholdValue;
|
|
309
|
+
return Number.isFinite(value) ? Math.max(0, value) : 1;
|
|
310
|
+
}
|
|
157
311
|
#directionFromEvent(event) {
|
|
158
312
|
const params = event.params;
|
|
159
313
|
const direction = params?.direction;
|
|
160
314
|
return direction === "start" || direction === "end" ? direction : null;
|
|
161
315
|
}
|
|
162
|
-
#prefersReducedMotion() {
|
|
163
|
-
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
164
|
-
}
|
|
165
316
|
};
|
|
166
317
|
|
|
167
318
|
export { OverflowIndicatorController };
|