stimeo-ui 0.3.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +124 -0
- data/dist/controllers/alert_dialog_controller.js +32 -5
- data/dist/controllers/announcer_controller.js +255 -20
- data/dist/controllers/aspect_ratio_controller.js +1 -1
- data/dist/controllers/breadcrumb_controller.js +5 -1
- data/dist/controllers/carousel_controller.js +5 -1
- data/dist/controllers/clipboard_controller.js +8 -3
- data/dist/controllers/collapsible_controller.js +4 -1
- data/dist/controllers/color_picker_controller.js +52 -2
- data/dist/controllers/command_palette_controller.js +32 -5
- data/dist/controllers/confirm_controller.js +32 -5
- data/dist/controllers/context_menu_controller.js +2 -2
- data/dist/controllers/countdown_controller.js +117 -13
- data/dist/controllers/date_range_picker_controller.js +55 -1
- data/dist/controllers/dialog_controller.js +32 -5
- data/dist/controllers/direct_upload_controller.js +3 -3
- data/dist/controllers/drawer_controller.js +32 -5
- data/dist/controllers/empty_state_controller.js +128 -23
- data/dist/controllers/flash_controller.js +161 -21
- data/dist/controllers/focus_controller.js +32 -5
- data/dist/controllers/form_validation_controller.js +8 -2
- data/dist/controllers/frame_loading_controller.js +261 -27
- data/dist/controllers/highlight_controller.js +38 -1
- data/dist/controllers/idle_controller.js +13 -2
- data/dist/controllers/local_time_controller.js +102 -6
- data/dist/controllers/masonry_controller.js +1 -1
- data/dist/controllers/meter_controller.js +147 -26
- data/dist/controllers/network_status_controller.js +29 -11
- data/dist/controllers/number_input_controller.js +191 -24
- data/dist/controllers/overflow_menu_controller.js +34 -7
- data/dist/controllers/pagination_controller.js +5 -1
- data/dist/controllers/password_strength_controller.js +1 -1
- data/dist/controllers/pointer_drag_controller.js +10 -0
- data/dist/controllers/portal_controller.js +10 -0
- data/dist/controllers/progress_controller.js +123 -12
- data/dist/controllers/range_slider_controller.js +449 -93
- data/dist/controllers/rating_controller.js +55 -0
- data/dist/controllers/relative_time_controller.js +135 -12
- data/dist/controllers/scroll_area_controller.js +1 -1
- data/dist/controllers/separator_controller.js +13 -17
- data/dist/controllers/sidebar_controller.js +37 -8
- data/dist/controllers/skeleton_controller.js +143 -22
- data/dist/controllers/slider_controller.js +342 -50
- data/dist/controllers/spinner_controller.js +244 -28
- data/dist/controllers/step_indicator_controller.js +85 -6
- data/dist/controllers/stepper_controller.js +2 -0
- data/dist/controllers/stick_to_bottom_controller.js +60 -10
- data/dist/controllers/switch_controller.js +162 -18
- data/dist/controllers/textarea_autosize_controller.js +1 -1
- data/dist/controllers/time_picker_controller.js +6 -3
- data/dist/controllers/tree_view_controller.js +19 -1
- data/dist/index.js +2278 -596
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a78d7192424e66f85cd4fbc901f75f260178f890fbcf040724fd5e518314dda7
|
|
4
|
+
data.tar.gz: d14ba0559fd6659b4b1edc860c653815bb949439768f26e3540cb758dabee2f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e02be89ae227eec783f0eb7f21c492a00ff75174c5285de3d8cf8418b3a826b6d9fb42d779b63a47845b77679d4b61adcade253746cf39ea83d7c924651f8a8e
|
|
7
|
+
data.tar.gz: 7661666a77da707d43ad07bf9e7bb4a8b0cb63caea75f2d0d8abf9f43fd6b43421bfe8d24203f814e70042a506177995df72e14487c4c11aa49016129bd44f02
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,128 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
While the version is `0.x`, the public API (the `stimeo--*` data attributes) may
|
|
8
8
|
change between releases.
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-08-13
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **Breaking** — every CSS custom property the library writes now carries the
|
|
15
|
+
`--stimeo--` namespace (two hyphens). Rename them in your stylesheets: a name
|
|
16
|
+
you miss raises no error, it just falls back to `var()`'s default and the bar
|
|
17
|
+
or thumb stops moving.
|
|
18
|
+
- `--stimeo-range-start` / `--stimeo-range-end` →
|
|
19
|
+
`--stimeo--range-slider-start` / `--stimeo--range-slider-end`
|
|
20
|
+
- `--stimeo-<name>` → `--stimeo--<name>` for `aspect-ratio`,
|
|
21
|
+
`collapsible-content-height`, `color`, `context-menu-x`, `context-menu-y`,
|
|
22
|
+
`masonry-columns`, `meter-ratio`, `password-strength`, `progress-ratio`,
|
|
23
|
+
`scroll-progress`, `step-indicator-ratio`, `textarea-rows`,
|
|
24
|
+
`upload-progress`
|
|
25
|
+
- **Breaking** — spinner's `indicator`, the network-status banners, and
|
|
26
|
+
countdown's `status` slot are no longer live regions. Drop `role="status"` /
|
|
27
|
+
`role="alert"` / `aria-live` from them and set `announceText` (and its
|
|
28
|
+
siblings) with a `stimeo--announcer` on the page; keeping the role reads the
|
|
29
|
+
change twice.
|
|
30
|
+
- time-picker: committing a field change dispatches a native `change` from the
|
|
31
|
+
`field` target, and `stimeo--time-picker:change` reports the composed value
|
|
32
|
+
even when no `field` target is present.
|
|
33
|
+
- tree-view: more native elements count as nested-interactive (`label`,
|
|
34
|
+
`summary`, `details`, `area[href]`, media with `controls`, `iframe`, `object`,
|
|
35
|
+
`embed`), so a click or key inside one is left alone instead of moving the
|
|
36
|
+
tree selection.
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- Inspector: the manifest advances from schema v8 to **v11** — tools that read it
|
|
41
|
+
raw must accept the new `valueConstraints`, `hosts`, and `valueRelations`
|
|
42
|
+
fields. Two diagnostics are new, so **re-run `stimeo check` before deploying;
|
|
43
|
+
it can report errors on views that passed under 0.4.0**:
|
|
44
|
+
- `invalid-value` — slider, range-slider, and number-input need a finite,
|
|
45
|
+
positive `step`; range-slider needs finite `min`, `max`, `start`, and `end`
|
|
46
|
+
with `min` at or below `max`.
|
|
47
|
+
- `invalid-host` — switch, time-picker, and tree-view report an unsupported
|
|
48
|
+
host element before it reaches the browser.
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- range-slider: two thumbs resting on the same value can be pulled apart with
|
|
53
|
+
the pointer again, and invalid or reversed bounds fall back to a finite
|
|
54
|
+
ordered range.
|
|
55
|
+
- slider, range-slider, number-input: an endpoint that does not sit on the step
|
|
56
|
+
grid is reachable, and an invalid `step` falls back to `1`.
|
|
57
|
+
- slider, range-slider: a Turbo morph that swaps a value repaints instead of
|
|
58
|
+
freezing, a replaced thumb or track picks up the current state, and a drag
|
|
59
|
+
stays with the pointer that started it.
|
|
60
|
+
- switch: holding Space no longer scrolls a non-`<button>` host, and an ancestor
|
|
61
|
+
`fieldset[disabled]` or `aria-disabled` blocks activation.
|
|
62
|
+
- flash: hover and focus pause the auto-dismiss independently, a flash paused
|
|
63
|
+
after its deadline dismisses instead of staying forever, a second dismiss on a
|
|
64
|
+
leaving flash is ignored, and a replaced `region` target is picked up.
|
|
65
|
+
- frame-loading: `aria-busy`, the skeleton, and `inert` are rolled back when the
|
|
66
|
+
controller is detached, instead of burning in with nothing left to finish the
|
|
67
|
+
load.
|
|
68
|
+
- empty-state: a replaced `list` or `empty` element and a runtime `itemSelector`
|
|
69
|
+
change are followed, so the placeholder no longer sticks beside a filled list.
|
|
70
|
+
- highlight: a highlight that outlives a Turbo navigation is cleaned up on the
|
|
71
|
+
way back instead of staying marked.
|
|
72
|
+
- idle: `data-idle` is cleared when a new measurement cycle connects, and
|
|
73
|
+
`disconnect()` removes the listeners it actually registered even when `events`
|
|
74
|
+
changed while connected.
|
|
75
|
+
- skeleton: a skeleton moved within the page keeps its ready intent.
|
|
76
|
+
|
|
77
|
+
## [0.4.0] - 2026-08-11
|
|
78
|
+
|
|
79
|
+
The feedback and status components announce through the shared
|
|
80
|
+
`stimeo--announcer` and survive Turbo caching and morphs. The Inspector reads the
|
|
81
|
+
`data:` hashes Rails helpers render. Two public API entries were removed.
|
|
82
|
+
|
|
83
|
+
### Removed
|
|
84
|
+
|
|
85
|
+
- **Breaking** — sidebar: the `beforeCache` action. Delete
|
|
86
|
+
`data-action="turbo:before-cache@document->stimeo--sidebar#beforeCache"`; the
|
|
87
|
+
behavior is built in, and leaving it makes `stimeo check` report an unknown
|
|
88
|
+
action.
|
|
89
|
+
- **Breaking** — empty-state: the `announce` boolean, and the `role="status"` /
|
|
90
|
+
`aria-live="polite"` it applied to the `empty` target. Use `announceText` /
|
|
91
|
+
`announceFilledText` instead.
|
|
92
|
+
|
|
93
|
+
### Added
|
|
94
|
+
|
|
95
|
+
- countdown, empty-state, frame-loading, meter, network-status, progress,
|
|
96
|
+
skeleton, spinner: `announceText`, plus `announceFilledText` /
|
|
97
|
+
`announceOnlineText` / `announceReadyText` where a component has two
|
|
98
|
+
transitions to report. Wording is yours and defaults to empty, and the page
|
|
99
|
+
needs a `stimeo--announcer` for any of it to be read.
|
|
100
|
+
- spinner: `timeout`, with a `stimeo--spinner:timeout` event. Off by default.
|
|
101
|
+
- stick-to-bottom: `pinOnConnect`. Off by default.
|
|
102
|
+
- Inspector: Stimulus wiring in a Rails helper's literal `data:` hash is checked
|
|
103
|
+
like static attributes. Re-run `stimeo check` — it can report new diagnostics.
|
|
104
|
+
|
|
105
|
+
### Changed
|
|
106
|
+
|
|
107
|
+
- meter, progress: an `aria-valuetext` you authored is preserved across renders.
|
|
108
|
+
- local-time, relative-time: the locale falls back to the nearest ancestor
|
|
109
|
+
carrying `lang`, not just the element's own and then the document's.
|
|
110
|
+
- countdown: `data-state` is the source of truth for the run state; `autostart`
|
|
111
|
+
governs only markup that states none.
|
|
112
|
+
|
|
113
|
+
### Fixed
|
|
114
|
+
|
|
115
|
+
- Turbo caching and morphs across announcer, color-picker, countdown,
|
|
116
|
+
date-range-picker, frame-loading, local-time, meter, overflow-menu, progress,
|
|
117
|
+
range-slider, rating, relative-time, sidebar, spinner, step-indicator: the
|
|
118
|
+
page is rewound before the snapshot and repaints when values are swapped,
|
|
119
|
+
instead of restoring stuck state or leaving a stale reading.
|
|
120
|
+
- network-status: transitions are actually announced.
|
|
121
|
+
- countdown: resume steps by one unit, and a settled timer no longer re-emits
|
|
122
|
+
`complete` on reconnect.
|
|
123
|
+
- step-indicator: runtime step changes re-derive the set, and a non-numeric
|
|
124
|
+
`current` falls back to the first step.
|
|
125
|
+
- local-time: a `datetime` with a space separator (`2026-06-08 12:30`) parses.
|
|
126
|
+
- relative-time: a malformed `locale` no longer throws.
|
|
127
|
+
- skeleton, frame-loading: a repeated signal no longer restarts or stacks the
|
|
128
|
+
minimum-duration wait.
|
|
129
|
+
- Empty, inverted, and non-numeric ranges floor to `0` across meter, progress,
|
|
130
|
+
slider, and range-slider.
|
|
131
|
+
|
|
10
132
|
## [0.3.0] - 2026-08-09
|
|
11
133
|
|
|
12
134
|
Minor release focused on consistent keyboard and selection behavior, resilient
|
|
@@ -336,6 +458,8 @@ Initial public alpha: 101 behavior-only, accessible Stimulus controllers driven
|
|
|
336
458
|
by `data-*` attributes, shipping no CSS. Published to npm (with provenance) and
|
|
337
459
|
RubyGems.
|
|
338
460
|
|
|
461
|
+
[0.5.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.5.0
|
|
462
|
+
[0.4.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.4.0
|
|
339
463
|
[0.3.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.3.0
|
|
340
464
|
[0.2.1]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.2.1
|
|
341
465
|
[0.2.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.2.0
|
|
@@ -2,6 +2,35 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/alert_dialog_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/before_cache_reset.ts
|
|
6
|
+
var BeforeCacheReset = class _BeforeCacheReset {
|
|
7
|
+
/** Every subscribed instance, iterated by the one shared document listener. */
|
|
8
|
+
static #subscribers = /* @__PURE__ */ new Set();
|
|
9
|
+
/** The shared listener; installed while at least one instance is subscribed. */
|
|
10
|
+
static #onBeforeCache = () => {
|
|
11
|
+
for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
|
|
12
|
+
};
|
|
13
|
+
#rewind;
|
|
14
|
+
/** @param rewind - the pass that returns this controller's state to its initial form. */
|
|
15
|
+
constructor(rewind) {
|
|
16
|
+
this.#rewind = rewind;
|
|
17
|
+
}
|
|
18
|
+
/** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
|
|
19
|
+
activate() {
|
|
20
|
+
const first = _BeforeCacheReset.#subscribers.size === 0;
|
|
21
|
+
_BeforeCacheReset.#subscribers.add(this);
|
|
22
|
+
if (first) {
|
|
23
|
+
document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
|
|
27
|
+
deactivate() {
|
|
28
|
+
_BeforeCacheReset.#subscribers.delete(this);
|
|
29
|
+
if (_BeforeCacheReset.#subscribers.size > 0) return;
|
|
30
|
+
document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
5
34
|
// src/utils/escape_layer.ts
|
|
6
35
|
var EscapeLayer = class _EscapeLayer {
|
|
7
36
|
static #registries = /* @__PURE__ */ new WeakMap();
|
|
@@ -135,7 +164,7 @@ var FocusTrap = class {
|
|
|
135
164
|
}
|
|
136
165
|
if (this.#flag(this.#options.isolate, true)) this.#isolateBackground();
|
|
137
166
|
document.addEventListener("keydown", this.#onKeydown);
|
|
138
|
-
|
|
167
|
+
this.#beforeCache.activate();
|
|
139
168
|
const onEscape = this.#options.onEscape;
|
|
140
169
|
if (onEscape) this.#escapeLayer.activate(document, { onDismiss: () => onEscape() });
|
|
141
170
|
if (this.#flag(this.#options.autoFocus, true)) this.#focusInitial();
|
|
@@ -152,7 +181,7 @@ var FocusTrap = class {
|
|
|
152
181
|
this.#activeState = false;
|
|
153
182
|
this.#escapeLayer.deactivate();
|
|
154
183
|
document.removeEventListener("keydown", this.#onKeydown);
|
|
155
|
-
|
|
184
|
+
this.#beforeCache.deactivate();
|
|
156
185
|
if (this.#scrollLocked) {
|
|
157
186
|
document.body.style.overflow = this.#previousBodyOverflow;
|
|
158
187
|
this.#scrollLocked = false;
|
|
@@ -176,9 +205,7 @@ var FocusTrap = class {
|
|
|
176
205
|
* untouched (restore-open designs reopen against a clean baseline), and focus
|
|
177
206
|
* is left alone mid-navigation. The listener lives only while active.
|
|
178
207
|
*/
|
|
179
|
-
#
|
|
180
|
-
this.deactivate({ restoreFocus: false });
|
|
181
|
-
};
|
|
208
|
+
#beforeCache = new BeforeCacheReset(() => this.deactivate({ restoreFocus: false }));
|
|
182
209
|
/**
|
|
183
210
|
* Handles `Tab` (focus trap) while active. `Escape` dismissal is owned by the
|
|
184
211
|
* shared {@link EscapeLayer} resolver, so Tab trapping stays independent of
|
|
@@ -2,6 +2,68 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/announcer_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/before_cache_reset.ts
|
|
6
|
+
var BeforeCacheReset = class _BeforeCacheReset {
|
|
7
|
+
/** Every subscribed instance, iterated by the one shared document listener. */
|
|
8
|
+
static #subscribers = /* @__PURE__ */ new Set();
|
|
9
|
+
/** The shared listener; installed while at least one instance is subscribed. */
|
|
10
|
+
static #onBeforeCache = () => {
|
|
11
|
+
for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
|
|
12
|
+
};
|
|
13
|
+
#rewind;
|
|
14
|
+
/** @param rewind - the pass that returns this controller's state to its initial form. */
|
|
15
|
+
constructor(rewind) {
|
|
16
|
+
this.#rewind = rewind;
|
|
17
|
+
}
|
|
18
|
+
/** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
|
|
19
|
+
activate() {
|
|
20
|
+
const first = _BeforeCacheReset.#subscribers.size === 0;
|
|
21
|
+
_BeforeCacheReset.#subscribers.add(this);
|
|
22
|
+
if (first) {
|
|
23
|
+
document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
|
|
27
|
+
deactivate() {
|
|
28
|
+
_BeforeCacheReset.#subscribers.delete(this);
|
|
29
|
+
if (_BeforeCacheReset.#subscribers.size > 0) return;
|
|
30
|
+
document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/utils/microtask_coalescer.ts
|
|
35
|
+
var MicrotaskCoalescer = class {
|
|
36
|
+
#run;
|
|
37
|
+
#queued = false;
|
|
38
|
+
#active = false;
|
|
39
|
+
#generation = 0;
|
|
40
|
+
/** @param run - the single reconciliation pass, invoked at most once per batch. */
|
|
41
|
+
constructor(run) {
|
|
42
|
+
this.#run = run;
|
|
43
|
+
}
|
|
44
|
+
/** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
|
|
45
|
+
activate() {
|
|
46
|
+
this.#active = true;
|
|
47
|
+
}
|
|
48
|
+
/** Closes the window and drops any pending pass; call from `disconnect()`. */
|
|
49
|
+
cancel() {
|
|
50
|
+
this.#active = false;
|
|
51
|
+
this.#queued = false;
|
|
52
|
+
this.#generation += 1;
|
|
53
|
+
}
|
|
54
|
+
/** Requests one pass after the batch settles. Idempotent; inert outside the window. */
|
|
55
|
+
schedule() {
|
|
56
|
+
if (!this.#active || this.#queued) return;
|
|
57
|
+
this.#queued = true;
|
|
58
|
+
const generation = this.#generation;
|
|
59
|
+
queueMicrotask(() => {
|
|
60
|
+
if (generation !== this.#generation || !this.#queued || !this.#active) return;
|
|
61
|
+
this.#queued = false;
|
|
62
|
+
this.#run();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
5
67
|
// src/utils/safe_timeout.ts
|
|
6
68
|
var TimerRegistry = class {
|
|
7
69
|
/** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
|
|
@@ -56,6 +118,7 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
56
118
|
};
|
|
57
119
|
|
|
58
120
|
// src/controllers/announcer_controller.ts
|
|
121
|
+
var LEVELS = ["polite", "assertive"];
|
|
59
122
|
var AnnouncerController = class extends Controller {
|
|
60
123
|
static targets = ["polite", "assertive"];
|
|
61
124
|
static values = {
|
|
@@ -67,6 +130,30 @@ var AnnouncerController = class extends Controller {
|
|
|
67
130
|
#timers = new SafeTimeout();
|
|
68
131
|
/** Live regions generated to stand in for absent targets, for teardown. */
|
|
69
132
|
#generated = /* @__PURE__ */ new Map();
|
|
133
|
+
/** Messages waiting to be written, oldest first, one queue per politeness. */
|
|
134
|
+
#queues = /* @__PURE__ */ new Map();
|
|
135
|
+
/** Politeness levels whose next drain is already armed. */
|
|
136
|
+
#draining = /* @__PURE__ */ new Set();
|
|
137
|
+
/** Collapses a batch of target callbacks (and morph removals) into one pass. */
|
|
138
|
+
#reconcile = new MicrotaskCoalescer(() => this.#reconcileRegions());
|
|
139
|
+
/**
|
|
140
|
+
* Watches the host's own children for a generated region disappearing. A morph
|
|
141
|
+
* drops it — the server's HTML never had it — and no target callback reports
|
|
142
|
+
* that, because a generated region carries no target attribute. `subtree` stays
|
|
143
|
+
* off so writing a message inside a region does not re-enter this pass.
|
|
144
|
+
*/
|
|
145
|
+
#hostWatch = new MutationObserver(() => {
|
|
146
|
+
this.#reconcile.schedule();
|
|
147
|
+
});
|
|
148
|
+
/** Rewinds to an announceable initial state for the snapshot; see the remarks. */
|
|
149
|
+
#beforeCache = new BeforeCacheReset(() => this.#rewindForCache());
|
|
150
|
+
/**
|
|
151
|
+
* The one timer a region may have outstanding — its dedupe re-set, then its
|
|
152
|
+
* auto-clear. Held weakly so a swapped-out target is not retained; a leftover
|
|
153
|
+
* id is harmless because {@link SafeTimeout.clear} no-ops on an id it does not
|
|
154
|
+
* own.
|
|
155
|
+
*/
|
|
156
|
+
#pending = /* @__PURE__ */ new WeakMap();
|
|
70
157
|
/**
|
|
71
158
|
* Guards against handling the same CustomEvent twice. An event dispatched on
|
|
72
159
|
* the controller element with `bubbles: true` reaches both the element and the
|
|
@@ -83,13 +170,86 @@ var AnnouncerController = class extends Controller {
|
|
|
83
170
|
this.#announce(message, this.#assertiveFromDetail(detail));
|
|
84
171
|
};
|
|
85
172
|
connect() {
|
|
173
|
+
this.#reconcile.activate();
|
|
174
|
+
this.#beforeCache.activate();
|
|
175
|
+
this.#reconcileRegions();
|
|
176
|
+
this.#hostWatch.observe(this.element, { childList: true });
|
|
86
177
|
this.element.addEventListener("stimeo--announcer:announce", this.#onAnnounceEvent);
|
|
87
178
|
window.addEventListener("stimeo--announcer:announce", this.#onAnnounceEvent);
|
|
88
179
|
}
|
|
89
180
|
disconnect() {
|
|
181
|
+
this.#reconcile.cancel();
|
|
182
|
+
this.#hostWatch.disconnect();
|
|
183
|
+
this.#beforeCache.deactivate();
|
|
90
184
|
this.element.removeEventListener("stimeo--announcer:announce", this.#onAnnounceEvent);
|
|
91
185
|
window.removeEventListener("stimeo--announcer:announce", this.#onAnnounceEvent);
|
|
92
186
|
this.#timers.clearAll();
|
|
187
|
+
this.#queues.clear();
|
|
188
|
+
this.#draining.clear();
|
|
189
|
+
this.#removeGenerated();
|
|
190
|
+
}
|
|
191
|
+
/** Retires the stand-in once the consumer supplies a polite region. */
|
|
192
|
+
politeTargetConnected() {
|
|
193
|
+
this.#reconcile.schedule();
|
|
194
|
+
}
|
|
195
|
+
/** Materialises a stand-in once the consumer's polite region goes away. */
|
|
196
|
+
politeTargetDisconnected() {
|
|
197
|
+
this.#reconcile.schedule();
|
|
198
|
+
}
|
|
199
|
+
/** Retires the stand-in once the consumer supplies an assertive region. */
|
|
200
|
+
assertiveTargetConnected() {
|
|
201
|
+
this.#reconcile.schedule();
|
|
202
|
+
}
|
|
203
|
+
/** Materialises a stand-in once the consumer's assertive region goes away. */
|
|
204
|
+
assertiveTargetDisconnected() {
|
|
205
|
+
this.#reconcile.schedule();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Brings the region set back to exactly one region per politeness and reports
|
|
209
|
+
* whether anything had to be created.
|
|
210
|
+
*
|
|
211
|
+
* A region created here is not written to in the same task: assistive tech
|
|
212
|
+
* reports changes to regions it already knows about, so {@link drain} waits a
|
|
213
|
+
* task whenever this says a region is new.
|
|
214
|
+
*/
|
|
215
|
+
#reconcileRegions() {
|
|
216
|
+
let created = false;
|
|
217
|
+
for (const level of LEVELS) {
|
|
218
|
+
if (this.#hasTargetFor(level)) {
|
|
219
|
+
const generated = this.#generated.get(level);
|
|
220
|
+
if (generated) {
|
|
221
|
+
generated.remove();
|
|
222
|
+
this.#generated.delete(level);
|
|
223
|
+
}
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const existing = this.#generated.get(level);
|
|
227
|
+
if (existing?.isConnected) continue;
|
|
228
|
+
this.#generated.set(level, this.#createRegion(level));
|
|
229
|
+
created = true;
|
|
230
|
+
}
|
|
231
|
+
return created;
|
|
232
|
+
}
|
|
233
|
+
/** Whether the consumer supplied a target for `level`. */
|
|
234
|
+
#hasTargetFor(level) {
|
|
235
|
+
return level === "assertive" ? this.hasAssertiveTarget : this.hasPoliteTarget;
|
|
236
|
+
}
|
|
237
|
+
/** Builds a visually hidden live region for `level` and attaches it. */
|
|
238
|
+
#createRegion(level) {
|
|
239
|
+
const region = document.createElement("div");
|
|
240
|
+
region.setAttribute("aria-live", level);
|
|
241
|
+
region.setAttribute("aria-atomic", "true");
|
|
242
|
+
visuallyHide(region);
|
|
243
|
+
this.element.appendChild(region);
|
|
244
|
+
return region;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Removes and forgets every region this controller generated. Authored targets
|
|
248
|
+
* belong to the consumer and are left untouched. Forgetting them is what keeps
|
|
249
|
+
* the live page working after a snapshot rewind: the next announcement finds an
|
|
250
|
+
* empty map and materialises a fresh region.
|
|
251
|
+
*/
|
|
252
|
+
#removeGenerated() {
|
|
93
253
|
for (const region of this.#generated.values()) {
|
|
94
254
|
region.remove();
|
|
95
255
|
}
|
|
@@ -111,47 +271,122 @@ var AnnouncerController = class extends Controller {
|
|
|
111
271
|
this.#announce(message, assertive);
|
|
112
272
|
}
|
|
113
273
|
/**
|
|
114
|
-
*
|
|
274
|
+
* Queues `message` for its politeness and arms the drain.
|
|
115
275
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* observed and announced again.
|
|
276
|
+
* Queuing is what makes a burst audible: assistive tech announces the changes it
|
|
277
|
+
* observes, so several messages written into one region within a single task are
|
|
278
|
+
* one change and only the last is read.
|
|
120
279
|
*/
|
|
121
280
|
#announce(message, assertive) {
|
|
122
|
-
const
|
|
281
|
+
const level = assertive ? "assertive" : "polite";
|
|
282
|
+
const queue = this.#queues.get(level);
|
|
283
|
+
if (queue) {
|
|
284
|
+
queue.push(message);
|
|
285
|
+
} else {
|
|
286
|
+
this.#queues.set(level, [message]);
|
|
287
|
+
}
|
|
288
|
+
this.#scheduleDrain(level);
|
|
289
|
+
}
|
|
290
|
+
/** Arms one drain pass for `level`; further messages ride the pass already armed. */
|
|
291
|
+
#scheduleDrain(level) {
|
|
292
|
+
if (this.#draining.has(level)) return;
|
|
293
|
+
this.#draining.add(level);
|
|
294
|
+
this.#timers.set(() => {
|
|
295
|
+
this.#draining.delete(level);
|
|
296
|
+
this.#drain(level);
|
|
297
|
+
}, 0);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Writes one queued message, then arms the next pass while the queue holds more.
|
|
301
|
+
*
|
|
302
|
+
* Two steps take a whole pass without consuming the message: materialising a
|
|
303
|
+
* region (it has to be in the accessibility tree before the text arrives) and
|
|
304
|
+
* emptying a region that already holds this exact text (an unchanged node is not
|
|
305
|
+
* re-read, so `dedupeReannounce` clears first and writes on the following pass).
|
|
306
|
+
*/
|
|
307
|
+
#drain(level) {
|
|
308
|
+
const queue = this.#queues.get(level);
|
|
309
|
+
const message = queue?.[0];
|
|
310
|
+
if (queue === void 0 || message === void 0) return;
|
|
311
|
+
if (this.#reconcileRegions()) {
|
|
312
|
+
this.#scheduleDrain(level);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const region = this.#regionFor(level);
|
|
123
316
|
if (this.dedupeReannounceValue && region.textContent === message) {
|
|
317
|
+
this.#cancelPending(region);
|
|
124
318
|
region.textContent = "";
|
|
125
|
-
this.#
|
|
126
|
-
region.textContent = message;
|
|
127
|
-
this.#scheduleClear(region, message);
|
|
128
|
-
}, 0);
|
|
319
|
+
this.#scheduleDrain(level);
|
|
129
320
|
return;
|
|
130
321
|
}
|
|
322
|
+
queue.shift();
|
|
323
|
+
this.#cancelPending(region);
|
|
131
324
|
region.textContent = message;
|
|
132
325
|
this.#scheduleClear(region, message);
|
|
326
|
+
if (queue.length > 0) this.#scheduleDrain(level);
|
|
133
327
|
}
|
|
134
328
|
/** Clears the region after `clearAfter` ms, unless a newer message replaced it. */
|
|
135
329
|
#scheduleClear(region, message) {
|
|
136
330
|
if (this.clearAfterValue <= 0) return;
|
|
137
|
-
this.#
|
|
138
|
-
|
|
139
|
-
|
|
331
|
+
this.#schedule(
|
|
332
|
+
region,
|
|
333
|
+
() => {
|
|
334
|
+
if (region.textContent === message) region.textContent = "";
|
|
335
|
+
},
|
|
336
|
+
this.clearAfterValue
|
|
337
|
+
);
|
|
140
338
|
}
|
|
141
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* Arms `region`'s single pending timer. Callers reach here with the slot
|
|
341
|
+
* already free — `#announce` releases it, and a fired timer clears its own
|
|
342
|
+
* entry below — so this does not cancel again.
|
|
343
|
+
*/
|
|
344
|
+
#schedule(region, callback, delay) {
|
|
345
|
+
const id = this.#timers.set(() => {
|
|
346
|
+
this.#pending.delete(region);
|
|
347
|
+
callback();
|
|
348
|
+
}, delay);
|
|
349
|
+
this.#pending.set(region, id);
|
|
350
|
+
}
|
|
351
|
+
/** Releases `region`'s pending timer, if it has one. */
|
|
352
|
+
#cancelPending(region) {
|
|
353
|
+
this.#timers.clear(this.#pending.get(region) ?? -1);
|
|
354
|
+
this.#pending.delete(region);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Resolves the live region for a politeness level.
|
|
358
|
+
*
|
|
359
|
+
* The remembered stand-in is used only while it is still in the document: a morph
|
|
360
|
+
* can drop it, and writing into the detached node would announce nothing at all.
|
|
361
|
+
*/
|
|
142
362
|
#regionFor(level) {
|
|
143
363
|
if (level === "assertive" && this.hasAssertiveTarget) return this.assertiveTarget;
|
|
144
364
|
if (level === "polite" && this.hasPoliteTarget) return this.politeTarget;
|
|
145
365
|
const existing = this.#generated.get(level);
|
|
146
|
-
if (existing) return existing;
|
|
147
|
-
const region =
|
|
148
|
-
region.setAttribute("aria-live", level);
|
|
149
|
-
region.setAttribute("aria-atomic", "true");
|
|
150
|
-
visuallyHide(region);
|
|
151
|
-
this.element.appendChild(region);
|
|
366
|
+
if (existing?.isConnected) return existing;
|
|
367
|
+
const region = this.#createRegion(level);
|
|
152
368
|
this.#generated.set(level, region);
|
|
153
369
|
return region;
|
|
154
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Restores the announceable initial state for the snapshot Turbo is about to
|
|
373
|
+
* take: queued and displayed messages go, generated regions go, and the live
|
|
374
|
+
* page — which keeps running when a visit is aborted — gets its regions back on
|
|
375
|
+
* the next task, after the clone.
|
|
376
|
+
*/
|
|
377
|
+
#rewindForCache() {
|
|
378
|
+
this.#queues.clear();
|
|
379
|
+
this.#draining.clear();
|
|
380
|
+
this.#timers.clearAll();
|
|
381
|
+
for (const level of LEVELS) {
|
|
382
|
+
if (this.#hasTargetFor(level)) {
|
|
383
|
+
const target = level === "assertive" ? this.assertiveTarget : this.politeTarget;
|
|
384
|
+
target.textContent = "";
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
this.#removeGenerated();
|
|
388
|
+
this.#timers.set(() => this.#reconcileRegions(), 0);
|
|
389
|
+
}
|
|
155
390
|
/** Extracts a non-empty string `message` from a CustomEvent detail, else null. */
|
|
156
391
|
#messageFromDetail(detail) {
|
|
157
392
|
if (detail && typeof detail === "object" && "message" in detail) {
|
|
@@ -8,7 +8,7 @@ var AspectRatioController = class extends Controller {
|
|
|
8
8
|
};
|
|
9
9
|
/** Applies the ratio on connect and whenever the value changes. */
|
|
10
10
|
ratioValueChanged() {
|
|
11
|
-
this.element.style.setProperty("--stimeo
|
|
11
|
+
this.element.style.setProperty("--stimeo--aspect-ratio", this.#normalizeRatio(this.ratioValue));
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Normalizes a ratio string to a valid CSS `<ratio>`:
|
|
@@ -287,7 +287,11 @@ var BreadcrumbController = class extends Controller {
|
|
|
287
287
|
this.ellipsisTarget.hidden = true;
|
|
288
288
|
return this.listTarget.scrollWidth > this.listTarget.clientWidth + OVERFLOW_EPSILON;
|
|
289
289
|
}
|
|
290
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* Applies the collapsed/expanded state to the items, ellipsis, and trigger.
|
|
292
|
+
*
|
|
293
|
+
* @stimeoRenderRoot
|
|
294
|
+
*/
|
|
291
295
|
#render() {
|
|
292
296
|
const collapsed = this.#overflowing && !this.#expanded;
|
|
293
297
|
const showEllipsis = this.#overflowing && this.collapsibleTargets.length > 0;
|
|
@@ -271,7 +271,11 @@ var CarouselController = class extends Controller {
|
|
|
271
271
|
this.#syncTimer();
|
|
272
272
|
if (changed) this.dispatch("change", { detail: { index, total: this.slideTargets.length } });
|
|
273
273
|
}
|
|
274
|
-
/**
|
|
274
|
+
/**
|
|
275
|
+
* Reflects `this.#index` onto slides and pickers (state hooks + roving).
|
|
276
|
+
*
|
|
277
|
+
* @stimeoRenderRoot
|
|
278
|
+
*/
|
|
275
279
|
#render({ focus }) {
|
|
276
280
|
this.slideTargets.forEach((slide, i) => {
|
|
277
281
|
const active = i === this.#index;
|
|
@@ -2,6 +2,13 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/clipboard_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/default_attribute.ts
|
|
6
|
+
function setDefaultAttribute(element, name, value) {
|
|
7
|
+
if (element.hasAttribute(name)) return false;
|
|
8
|
+
element.setAttribute(name, value);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
// src/utils/safe_timeout.ts
|
|
6
13
|
var TimerRegistry = class {
|
|
7
14
|
/** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
|
|
@@ -75,9 +82,7 @@ var ClipboardController = class extends Controller {
|
|
|
75
82
|
*/
|
|
76
83
|
#resetTimerId = null;
|
|
77
84
|
connect() {
|
|
78
|
-
|
|
79
|
-
this.element.setAttribute("data-state", "idle");
|
|
80
|
-
}
|
|
85
|
+
setDefaultAttribute(this.element, "data-state", "idle");
|
|
81
86
|
}
|
|
82
87
|
disconnect() {
|
|
83
88
|
this.#timers.clearAll();
|
|
@@ -297,7 +297,10 @@ var CollapsibleController = class extends Controller {
|
|
|
297
297
|
#applyContent(content, open, waitForCloseTransition) {
|
|
298
298
|
if (open) {
|
|
299
299
|
content.hidden = false;
|
|
300
|
-
content.style.setProperty(
|
|
300
|
+
content.style.setProperty(
|
|
301
|
+
"--stimeo--collapsible-content-height",
|
|
302
|
+
`${content.scrollHeight}px`
|
|
303
|
+
);
|
|
301
304
|
content.setAttribute("data-state", "open");
|
|
302
305
|
return;
|
|
303
306
|
}
|