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.
- package/CHANGELOG.md +124 -0
- package/dist/controllers/alert_dialog_controller.js +32 -5
- package/dist/controllers/alert_dialog_controller.js.map +1 -1
- package/dist/controllers/announcer_controller.d.ts +32 -6
- package/dist/controllers/announcer_controller.js +255 -20
- package/dist/controllers/announcer_controller.js.map +1 -1
- package/dist/controllers/aspect_ratio_controller.d.ts +2 -2
- package/dist/controllers/aspect_ratio_controller.js +1 -1
- package/dist/controllers/aspect_ratio_controller.js.map +1 -1
- package/dist/controllers/breadcrumb_controller.js +5 -1
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.js +5 -1
- package/dist/controllers/carousel_controller.js.map +1 -1
- package/dist/controllers/clipboard_controller.js +8 -3
- package/dist/controllers/clipboard_controller.js.map +1 -1
- package/dist/controllers/collapsible_controller.d.ts +1 -1
- package/dist/controllers/collapsible_controller.js +4 -1
- package/dist/controllers/collapsible_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +4 -3
- package/dist/controllers/color_picker_controller.js +52 -2
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.js +32 -5
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/confirm_controller.js +32 -5
- package/dist/controllers/confirm_controller.js.map +1 -1
- package/dist/controllers/context_menu_controller.d.ts +1 -1
- package/dist/controllers/context_menu_controller.js +2 -2
- package/dist/controllers/context_menu_controller.js.map +1 -1
- package/dist/controllers/countdown_controller.d.ts +24 -8
- package/dist/controllers/countdown_controller.js +117 -13
- package/dist/controllers/countdown_controller.js.map +1 -1
- package/dist/controllers/date_range_picker_controller.d.ts +4 -1
- package/dist/controllers/date_range_picker_controller.js +55 -1
- package/dist/controllers/date_range_picker_controller.js.map +1 -1
- package/dist/controllers/dialog_controller.js +32 -5
- package/dist/controllers/dialog_controller.js.map +1 -1
- package/dist/controllers/direct_upload_controller.d.ts +1 -1
- package/dist/controllers/direct_upload_controller.js +3 -3
- package/dist/controllers/direct_upload_controller.js.map +1 -1
- package/dist/controllers/dismissible_controller.js.map +1 -1
- package/dist/controllers/drawer_controller.js +32 -5
- package/dist/controllers/drawer_controller.js.map +1 -1
- package/dist/controllers/empty_state_controller.d.ts +36 -11
- package/dist/controllers/empty_state_controller.js +128 -23
- package/dist/controllers/empty_state_controller.js.map +1 -1
- package/dist/controllers/flash_controller.d.ts +25 -5
- package/dist/controllers/flash_controller.js +161 -21
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/focus_controller.js +32 -5
- package/dist/controllers/focus_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.js +8 -2
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.d.ts +31 -3
- package/dist/controllers/frame_loading_controller.js +261 -27
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.d.ts +8 -4
- package/dist/controllers/highlight_controller.js +38 -1
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/idle_controller.d.ts +2 -1
- package/dist/controllers/idle_controller.js +13 -2
- package/dist/controllers/idle_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/local_time_controller.d.ts +19 -3
- package/dist/controllers/local_time_controller.js +102 -6
- package/dist/controllers/local_time_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +1 -1
- package/dist/controllers/masonry_controller.js +1 -1
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/meter_controller.d.ts +22 -2
- package/dist/controllers/meter_controller.js +147 -26
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.js.map +1 -1
- package/dist/controllers/network_status_controller.d.ts +25 -11
- package/dist/controllers/network_status_controller.js +29 -11
- package/dist/controllers/network_status_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +8 -0
- package/dist/controllers/number_input_controller.js +191 -24
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.js +34 -7
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.js +5 -1
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/password_strength_controller.d.ts +1 -1
- package/dist/controllers/password_strength_controller.js +1 -1
- package/dist/controllers/password_strength_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.js +10 -0
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/portal_controller.js +10 -0
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/progress_controller.d.ts +17 -2
- package/dist/controllers/progress_controller.js +123 -12
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/range_slider_controller.d.ts +27 -1
- package/dist/controllers/range_slider_controller.js +449 -93
- package/dist/controllers/range_slider_controller.js.map +1 -1
- package/dist/controllers/rating_controller.d.ts +4 -1
- package/dist/controllers/rating_controller.js +55 -0
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/relative_time_controller.d.ts +13 -0
- package/dist/controllers/relative_time_controller.js +135 -12
- package/dist/controllers/relative_time_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.d.ts +1 -1
- package/dist/controllers/scroll_area_controller.js +1 -1
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/separator_controller.js +13 -17
- package/dist/controllers/separator_controller.js.map +1 -1
- package/dist/controllers/sidebar_controller.d.ts +1 -11
- package/dist/controllers/sidebar_controller.js +37 -8
- package/dist/controllers/sidebar_controller.js.map +1 -1
- package/dist/controllers/skeleton_controller.d.ts +7 -2
- package/dist/controllers/skeleton_controller.js +143 -22
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +17 -1
- package/dist/controllers/slider_controller.js +342 -50
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.d.ts +50 -12
- package/dist/controllers/spinner_controller.js +244 -28
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/step_indicator_controller.d.ts +13 -2
- package/dist/controllers/step_indicator_controller.js +85 -6
- package/dist/controllers/step_indicator_controller.js.map +1 -1
- package/dist/controllers/stepper_controller.js +2 -0
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.d.ts +26 -2
- package/dist/controllers/stick_to_bottom_controller.js +60 -10
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/switch_controller.d.ts +12 -8
- package/dist/controllers/switch_controller.js +162 -18
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/textarea_autosize_controller.js +1 -1
- package/dist/controllers/textarea_autosize_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.d.ts +3 -0
- package/dist/controllers/time_picker_controller.js +6 -3
- package/dist/controllers/time_picker_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +1 -2
- package/dist/controllers/tree_view_controller.js +19 -1
- package/dist/controllers/tree_view_controller.js.map +1 -1
- package/dist/index.js +2278 -596
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +76 -1
- package/dist/inspector/cli.js +937 -76
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +997 -78
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +20 -20
- package/dist/inspector/manifest.json +428 -33
- package/package.json +3 -3
|
@@ -2,6 +2,126 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/skeleton_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/announce.ts
|
|
6
|
+
function announce(message, options = {}) {
|
|
7
|
+
const text = message.trim();
|
|
8
|
+
if (text.length === 0) return;
|
|
9
|
+
window.dispatchEvent(
|
|
10
|
+
new CustomEvent("stimeo--announcer:announce", {
|
|
11
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
12
|
+
})
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
function fillTemplate(template, values) {
|
|
16
|
+
return template.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (match, name) => {
|
|
17
|
+
const replacement = values[name];
|
|
18
|
+
return replacement === void 0 ? match : String(replacement);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/utils/detach_gate.ts
|
|
23
|
+
var DetachGate = class _DetachGate {
|
|
24
|
+
/** Set while a probe is queued, waiting for a reconnect to cancel it. */
|
|
25
|
+
#pending = false;
|
|
26
|
+
/**
|
|
27
|
+
* True while a probe is queued — the last disconnect was ambiguous and no
|
|
28
|
+
* reconnect has cancelled it yet. Read it from `connect()` to tell the
|
|
29
|
+
* reconnect half of an in-page move from a first connect: a controller whose
|
|
30
|
+
* initialisation restarts a measurement (a min-duration floor, an elapsed
|
|
31
|
+
* counter) must skip it for the move, where nothing actually restarted.
|
|
32
|
+
*/
|
|
33
|
+
get pending() {
|
|
34
|
+
return this.#pending;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* True when the disconnect is definitely a real detach — the element left
|
|
38
|
+
* the document, or `data-controller` no longer lists the identifier. False
|
|
39
|
+
* means ambiguous (in-page move or observed-root exit), NOT "alive".
|
|
40
|
+
*/
|
|
41
|
+
static isDetached(host) {
|
|
42
|
+
if (!host.element.isConnected) return true;
|
|
43
|
+
const tokens = (host.element.getAttribute("data-controller") ?? "").split(/\s+/);
|
|
44
|
+
return !tokens.includes(host.identifier);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Call from `disconnect()`: runs `teardown` synchronously on a definite
|
|
48
|
+
* detach (fast path), otherwise defers it one microtask — a reconnect
|
|
49
|
+
* ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.
|
|
50
|
+
* One microtask is the whole probe window: Stimulus reconnects a moved
|
|
51
|
+
* element within the same mutation batch, before the checkpoint drains.
|
|
52
|
+
*/
|
|
53
|
+
disconnected(host, teardown) {
|
|
54
|
+
if (_DetachGate.isDetached(host)) {
|
|
55
|
+
this.#pending = false;
|
|
56
|
+
teardown();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.#pending = true;
|
|
60
|
+
queueMicrotask(() => {
|
|
61
|
+
if (!this.#pending) return;
|
|
62
|
+
this.#pending = false;
|
|
63
|
+
teardown();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Disarms a pending probe. Call from `connect()` (the reconnect that proves
|
|
68
|
+
* an in-page move) and from the head of any teardown path not routed through
|
|
69
|
+
* {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can
|
|
70
|
+
* never run the teardown a second time.
|
|
71
|
+
*/
|
|
72
|
+
cancel() {
|
|
73
|
+
this.#pending = false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/utils/min_duration_floor.ts
|
|
78
|
+
var MinDurationFloor = class {
|
|
79
|
+
#timers;
|
|
80
|
+
/** Pending finish timer id, or `null` when nothing is held back. */
|
|
81
|
+
#timerId = null;
|
|
82
|
+
/** Epoch ms the floor is measured from. */
|
|
83
|
+
#since = 0;
|
|
84
|
+
/** @param timers - the controller's registry; the floor schedules into it. */
|
|
85
|
+
constructor(timers) {
|
|
86
|
+
this.#timers = timers;
|
|
87
|
+
}
|
|
88
|
+
/** Starts the floor: call when the state being held becomes visible. */
|
|
89
|
+
begin() {
|
|
90
|
+
this.#since = Date.now();
|
|
91
|
+
}
|
|
92
|
+
/** True while a finish is held back waiting for the floor to elapse. */
|
|
93
|
+
get pending() {
|
|
94
|
+
return this.#timerId !== null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Runs `finish` once the floor has elapsed, immediately when it already has.
|
|
98
|
+
*
|
|
99
|
+
* A held-back finish is **replaced**, never stacked: only the most recently
|
|
100
|
+
* queued id is cancellable, so a second timer would outlive every cancel and
|
|
101
|
+
* end a state that has since restarted. Controllers that want the first signal
|
|
102
|
+
* to win guard on {@link pending} before calling.
|
|
103
|
+
*/
|
|
104
|
+
schedule(minDuration, finish) {
|
|
105
|
+
this.cancel();
|
|
106
|
+
const remaining = minDuration - (Date.now() - this.#since);
|
|
107
|
+
if (remaining > 0) {
|
|
108
|
+
this.#timerId = this.#timers.set(() => {
|
|
109
|
+
this.#timerId = null;
|
|
110
|
+
finish();
|
|
111
|
+
}, remaining);
|
|
112
|
+
} else {
|
|
113
|
+
finish();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Drops a held-back finish. Safe when none is queued, or after a bulk clear. */
|
|
117
|
+
cancel() {
|
|
118
|
+
if (this.#timerId !== null) {
|
|
119
|
+
this.#timers.clear(this.#timerId);
|
|
120
|
+
this.#timerId = null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
5
125
|
// src/utils/safe_timeout.ts
|
|
6
126
|
var TimerRegistry = class {
|
|
7
127
|
/** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
|
|
@@ -59,48 +179,37 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
59
179
|
var SkeletonController = class extends Controller {
|
|
60
180
|
static targets = ["placeholder", "content"];
|
|
61
181
|
static values = {
|
|
182
|
+
announceReadyText: { type: String, default: "" },
|
|
62
183
|
minDuration: { type: Number, default: 0 }
|
|
63
184
|
};
|
|
64
185
|
static actions = ["ready", "reset"];
|
|
65
186
|
static events = ["ready"];
|
|
66
187
|
#timers = new SafeTimeout();
|
|
67
|
-
|
|
68
|
-
#
|
|
69
|
-
/** Epoch ms when the loading state began; `minDuration` is measured from it. */
|
|
70
|
-
#loadingSince = 0;
|
|
188
|
+
#floor = new MinDurationFloor(this.#timers);
|
|
189
|
+
#gate = new DetachGate();
|
|
71
190
|
connect() {
|
|
72
|
-
|
|
191
|
+
const moved = this.#gate.pending;
|
|
192
|
+
this.#gate.cancel();
|
|
193
|
+
if (!moved && this.#state !== "ready") {
|
|
73
194
|
this.#enterLoading();
|
|
74
195
|
}
|
|
75
196
|
}
|
|
76
197
|
disconnect() {
|
|
77
|
-
this.#
|
|
78
|
-
this.#revealTimerId = null;
|
|
198
|
+
this.#gate.disconnected(this, () => this.#teardown());
|
|
79
199
|
}
|
|
80
200
|
/** Swaps to the real content. Honors `minDuration` to prevent a flash. */
|
|
81
201
|
ready() {
|
|
82
|
-
if (this.#state === "ready" || this.#
|
|
83
|
-
|
|
84
|
-
if (remaining > 0) {
|
|
85
|
-
this.#revealTimerId = this.#timers.set(() => {
|
|
86
|
-
this.#revealTimerId = null;
|
|
87
|
-
this.#reveal();
|
|
88
|
-
}, remaining);
|
|
89
|
-
} else {
|
|
90
|
-
this.#reveal();
|
|
91
|
-
}
|
|
202
|
+
if (this.#state === "ready" || this.#floor.pending) return;
|
|
203
|
+
this.#floor.schedule(this.minDurationValue, () => this.#reveal());
|
|
92
204
|
}
|
|
93
205
|
/** Returns to the loading state (e.g. a Turbo Stream re-fetch). */
|
|
94
206
|
reset() {
|
|
95
|
-
|
|
96
|
-
this.#timers.clear(this.#revealTimerId);
|
|
97
|
-
this.#revealTimerId = null;
|
|
98
|
-
}
|
|
207
|
+
this.#floor.cancel();
|
|
99
208
|
this.#enterLoading();
|
|
100
209
|
}
|
|
101
210
|
/** Shows the placeholder, hides content, and marks the region busy. */
|
|
102
211
|
#enterLoading() {
|
|
103
|
-
this.#
|
|
212
|
+
this.#floor.begin();
|
|
104
213
|
if (this.hasPlaceholderTarget) this.placeholderTarget.hidden = false;
|
|
105
214
|
if (this.hasContentTarget) this.contentTarget.hidden = true;
|
|
106
215
|
this.element.setAttribute("aria-busy", "true");
|
|
@@ -113,6 +222,18 @@ var SkeletonController = class extends Controller {
|
|
|
113
222
|
this.element.setAttribute("aria-busy", "false");
|
|
114
223
|
this.element.setAttribute("data-state", "ready");
|
|
115
224
|
this.dispatch("ready", { detail: {} });
|
|
225
|
+
announce(fillTemplate(this.announceReadyTextValue, {}));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Drops the held reveal on a real detach. The markup keeps whatever it last
|
|
229
|
+
* held: an element on its way out of the document has no reader left, and one
|
|
230
|
+
* whose `data-controller` dropped the identifier no longer resolves its own
|
|
231
|
+
* targets, so the rollback could only ever be partial.
|
|
232
|
+
*/
|
|
233
|
+
#teardown() {
|
|
234
|
+
this.#gate.cancel();
|
|
235
|
+
this.#timers.clearAll();
|
|
236
|
+
this.#floor.cancel();
|
|
116
237
|
}
|
|
117
238
|
/** Current lifecycle phase as reflected on `data-state`. */
|
|
118
239
|
get #state() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/controllers/skeleton_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACvB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAA,GAAiB;AACf,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,GAAA,EAAK;AACzB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AACA,IAAA,IAAA,CAAK,IAAI,KAAA,EAAM;AAAA,EACjB;AAAA;AAAA,EAGA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,GAAA,CAAI,IAAA;AAAA,EAClB;AACF,CAAA;AAmBO,IAAM,WAAA,GAAN,cAA0B,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AACd,IAAA,IAAI,IAAA,CAAK,oBAAA,EAAsB,IAAA,CAAK,iBAAA,CAAkB,MAAA,GAAS,IAAA;AAC/D,IAAA,IAAI,IAAA,CAAK,gBAAA,EAAkB,IAAA,CAAK,aAAA,CAAc,MAAA,GAAS,KAAA;AACvD,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,WAAA,EAAa,OAAO,CAAA;AAC9C,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA;AAC/C,IAAA,IAAA,CAAK,SAAS,OAAA,EAAS,EAAE,MAAA,EAAQ,IAAI,CAAA;AAAA,EACvC;AAAA;AAAA,EAGA,IAAI,MAAA,GAAiB;AACnB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAY,CAAA,IAAK,SAAA;AAAA,EACpD;AACF","file":"skeleton_controller.js","sourcesContent":["/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless skeleton/placeholder manager. No dedicated APG pattern; it follows\n * the `aria-busy` + show/hide practice.\n *\n * Markup contract (identifier: `stimeo--skeleton`):\n * <div data-controller=\"stimeo--skeleton\" aria-busy=\"true\"\n * data-stimeo--skeleton-min-duration-value=\"300\"\n * data-action=\"content:ready->stimeo--skeleton#ready\">\n * <div aria-hidden=\"true\" data-stimeo--skeleton-target=\"placeholder\"></div>\n * <div hidden data-stimeo--skeleton-target=\"content\"></div>\n * </div>\n *\n * Starts in the loading state (placeholder shown, real content hidden, region\n * `aria-busy=\"true\"`); `ready` swaps to the content and clears busy. The\n * placeholder is `aria-hidden` (decorative) so assistive tech never reads the\n * skeleton. `minDuration` keeps the placeholder up long enough to avoid a flash\n * when content arrives almost immediately.\n *\n * @remarks\n * Behavior only — skeleton shapes/animation are the consumer's. The\n * min-duration timer is owned by {@link SafeTimeout} and torn down on\n * `disconnect()` (Turbo navigation included).\n */\nexport class SkeletonController extends Controller<HTMLElement> {\n static override targets = [\"placeholder\", \"content\"];\n static override values = {\n minDuration: { type: Number, default: 0 },\n };\n static actions = [\"ready\", \"reset\"] as const;\n static events = [\"ready\"] as const;\n\n declare readonly placeholderTarget: HTMLElement;\n declare readonly contentTarget: HTMLElement;\n declare readonly hasPlaceholderTarget: boolean;\n declare readonly hasContentTarget: boolean;\n\n declare minDurationValue: number;\n\n readonly #timers = new SafeTimeout();\n\n /** Pending min-duration reveal timer id, or `null` when none is scheduled. */\n #revealTimerId: number | null = null;\n /** Epoch ms when the loading state began; `minDuration` is measured from it. */\n #loadingSince = 0;\n\n override connect(): void {\n if (this.#state !== \"ready\") {\n this.#enterLoading();\n }\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n this.#revealTimerId = null;\n }\n\n /** Swaps to the real content. Honors `minDuration` to prevent a flash. */\n ready(): void {\n if (this.#state === \"ready\" || this.#revealTimerId !== null) return;\n const remaining = this.minDurationValue - (Date.now() - this.#loadingSince);\n if (remaining > 0) {\n this.#revealTimerId = this.#timers.set(() => {\n this.#revealTimerId = null;\n this.#reveal();\n }, remaining);\n } else {\n this.#reveal();\n }\n }\n\n /** Returns to the loading state (e.g. a Turbo Stream re-fetch). */\n reset(): void {\n if (this.#revealTimerId !== null) {\n this.#timers.clear(this.#revealTimerId);\n this.#revealTimerId = null;\n }\n this.#enterLoading();\n }\n\n /** Shows the placeholder, hides content, and marks the region busy. */\n #enterLoading(): void {\n this.#loadingSince = Date.now();\n if (this.hasPlaceholderTarget) this.placeholderTarget.hidden = false;\n if (this.hasContentTarget) this.contentTarget.hidden = true;\n this.element.setAttribute(\"aria-busy\", \"true\");\n this.element.setAttribute(\"data-state\", \"loading\");\n }\n\n /** Hides the placeholder, shows content, and clears the busy state. */\n #reveal(): void {\n if (this.hasPlaceholderTarget) this.placeholderTarget.hidden = true;\n if (this.hasContentTarget) this.contentTarget.hidden = false;\n this.element.setAttribute(\"aria-busy\", \"false\");\n this.element.setAttribute(\"data-state\", \"ready\");\n this.dispatch(\"ready\", { detail: {} });\n }\n\n /** Current lifecycle phase as reflected on `data-state`. */\n get #state(): string {\n return this.element.getAttribute(\"data-state\") ?? \"loading\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/detach_gate.ts","../../src/utils/min_duration_floor.ts","../../src/utils/safe_timeout.ts","../../src/controllers/skeleton_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAA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A,SAAA,GAAkB;AAChB,IAAA,IAAA,CAAK,MAAM,MAAA,EAAO;AAClB,IAAA,IAAA,CAAK,QAAQ,QAAA,EAAS;AACtB,IAAA,IAAA,CAAK,OAAO,MAAA,EAAO;AAAA,EACrB;AAAA;AAAA,EAGA,IAAI,MAAA,GAAiB;AACnB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAY,CAAA,IAAK,SAAA;AAAA,EACpD;AACF","file":"skeleton_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True while a probe is queued — the last disconnect was ambiguous and no\n * reconnect has cancelled it yet. Read it from `connect()` to tell the\n * reconnect half of an in-page move from a first connect: a controller whose\n * initialisation restarts a measurement (a min-duration floor, an elapsed\n * counter) must skip it for the move, where nothing actually restarted.\n */\n get pending(): boolean {\n return this.#pending;\n }\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\n }\n}\n","import type { SafeTimeout } from \"./safe_timeout\";\n\n/**\n * Holds a transient state visible for a minimum time before letting it end.\n *\n * A loading indicator that appears and disappears within a few frames reads as a\n * flicker rather than as feedback, so several controllers keep one up for a floor\n * of `minDuration` milliseconds measured from the moment it became visible. The\n * shape is always the same: note the moment, and when the end signal arrives\n * either run it now, because the floor has already passed, or hold it on a timer\n * for whatever is left.\n *\n * The floor **borrows** a {@link SafeTimeout} instead of owning one, so a\n * controller that also schedules other work (a show delay) keeps every timer in a\n * single registry and one `clearAll()` in its teardown still drops them all.\n * Cancelling after such a bulk clear is safe: the registry no-ops on an id it no\n * longer holds.\n *\n * Scope is the floor itself. **When an end signal is allowed to arrive at all\n * stays with the controller**, because the answers differ — one keeps the first\n * queued finish and ignores repeats, another lets the newest replace it — and\n * flattening that into a shared default would silently change what the consumers\n * already promise.\n *\n * @example\n * ```ts\n * readonly #timers = new SafeTimeout();\n * readonly #floor = new MinDurationFloor(this.#timers);\n *\n * #show() { this.#floor.begin(); … }\n * stop() { this.#floor.schedule(this.minDurationValue, () => this.#hide()); }\n * ```\n */\nexport class MinDurationFloor {\n readonly #timers: SafeTimeout;\n\n /** Pending finish timer id, or `null` when nothing is held back. */\n #timerId: number | null = null;\n\n /** Epoch ms the floor is measured from. */\n #since = 0;\n\n /** @param timers - the controller's registry; the floor schedules into it. */\n constructor(timers: SafeTimeout) {\n this.#timers = timers;\n }\n\n /** Starts the floor: call when the state being held becomes visible. */\n begin(): void {\n this.#since = Date.now();\n }\n\n /** True while a finish is held back waiting for the floor to elapse. */\n get pending(): boolean {\n return this.#timerId !== null;\n }\n\n /**\n * Runs `finish` once the floor has elapsed, immediately when it already has.\n *\n * A held-back finish is **replaced**, never stacked: only the most recently\n * queued id is cancellable, so a second timer would outlive every cancel and\n * end a state that has since restarted. Controllers that want the first signal\n * to win guard on {@link pending} before calling.\n */\n schedule(minDuration: number, finish: () => void): void {\n this.cancel();\n const remaining = minDuration - (Date.now() - this.#since);\n if (remaining > 0) {\n this.#timerId = this.#timers.set(() => {\n this.#timerId = null;\n finish();\n }, remaining);\n } else {\n finish();\n }\n }\n\n /** Drops a held-back finish. Safe when none is queued, or after a bulk clear. */\n cancel(): void {\n if (this.#timerId !== null) {\n this.#timers.clear(this.#timerId);\n this.#timerId = null;\n }\n }\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { announce, fillTemplate } from \"../utils/announce\";\nimport { DetachGate } from \"../utils/detach_gate\";\nimport { MinDurationFloor } from \"../utils/min_duration_floor\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless skeleton/placeholder manager. No dedicated APG pattern; it follows\n * the `aria-busy` + show/hide practice.\n *\n * Markup contract (identifier: `stimeo--skeleton`):\n * <div data-controller=\"stimeo--skeleton\" aria-busy=\"true\"\n * data-stimeo--skeleton-min-duration-value=\"300\"\n * data-action=\"content:ready->stimeo--skeleton#ready\">\n * <div aria-hidden=\"true\" data-stimeo--skeleton-target=\"placeholder\"></div>\n * <div hidden data-stimeo--skeleton-target=\"content\"></div>\n * </div>\n *\n * Starts in the loading state (placeholder shown, real content hidden, region\n * `aria-busy=\"true\"`); `ready` swaps to the content and clears busy. The\n * placeholder is `aria-hidden` (decorative) so assistive tech never reads the\n * skeleton. `minDuration` keeps the placeholder up long enough to avoid a flash\n * when content arrives almost immediately.\n *\n * @remarks\n * Behavior only — skeleton shapes/animation are the consumer's. The\n * min-duration wait is held by {@link MinDurationFloor} on a {@link SafeTimeout},\n * kept across an in-page move and dropped on a real detach via {@link DetachGate}.\n */\nexport class SkeletonController extends Controller<HTMLElement> {\n static override targets = [\"placeholder\", \"content\"];\n static override values = {\n announceReadyText: { type: String, default: \"\" },\n minDuration: { type: Number, default: 0 },\n };\n static actions = [\"ready\", \"reset\"] as const;\n static events = [\"ready\"] as const;\n\n declare readonly placeholderTarget: HTMLElement;\n declare readonly contentTarget: HTMLElement;\n declare readonly hasPlaceholderTarget: boolean;\n declare readonly hasContentTarget: boolean;\n\n declare minDurationValue: number;\n declare announceReadyTextValue: string;\n\n readonly #timers = new SafeTimeout();\n readonly #floor = new MinDurationFloor(this.#timers);\n readonly #gate = new DetachGate();\n\n override connect(): void {\n // A probe still queued means this is the reconnect half of an in-page move.\n // The placeholder never left the screen, so the loading hooks already hold\n // the values `#enterLoading()` would write and the floor is still measuring\n // from the moment the skeleton actually appeared — restarting it here would\n // hold the reveal back for longer than `minDuration` asks.\n const moved = this.#gate.pending;\n this.#gate.cancel();\n if (!moved && this.#state !== \"ready\") {\n this.#enterLoading();\n }\n }\n\n override disconnect(): void {\n this.#gate.disconnected(this, () => this.#teardown());\n }\n\n /** Swaps to the real content. Honors `minDuration` to prevent a flash. */\n ready(): void {\n // The first signal wins: a repeat while the floor still holds the reveal back\n // must not restart the wait, or a stream of ready events keeps postponing it.\n if (this.#state === \"ready\" || this.#floor.pending) return;\n this.#floor.schedule(this.minDurationValue, () => this.#reveal());\n }\n\n /** Returns to the loading state (e.g. a Turbo Stream re-fetch). */\n reset(): void {\n this.#floor.cancel();\n this.#enterLoading();\n }\n\n /** Shows the placeholder, hides content, and marks the region busy. */\n #enterLoading(): void {\n this.#floor.begin();\n if (this.hasPlaceholderTarget) this.placeholderTarget.hidden = false;\n if (this.hasContentTarget) this.contentTarget.hidden = true;\n this.element.setAttribute(\"aria-busy\", \"true\");\n this.element.setAttribute(\"data-state\", \"loading\");\n }\n\n /** Hides the placeholder, shows content, and clears the busy state. */\n #reveal(): void {\n if (this.hasPlaceholderTarget) this.placeholderTarget.hidden = true;\n if (this.hasContentTarget) this.contentTarget.hidden = false;\n this.element.setAttribute(\"aria-busy\", \"false\");\n this.element.setAttribute(\"data-state\", \"ready\");\n this.dispatch(\"ready\", { detail: {} });\n // loading → ready is the transition; the skeleton itself carries no words.\n announce(fillTemplate(this.announceReadyTextValue, {}));\n }\n\n /**\n * Drops the held reveal on a real detach. The markup keeps whatever it last\n * held: an element on its way out of the document has no reader left, and one\n * whose `data-controller` dropped the identifier no longer resolves its own\n * targets, so the rollback could only ever be partial.\n */\n #teardown(): void {\n this.#gate.cancel();\n this.#timers.clearAll();\n this.#floor.cancel();\n }\n\n /** Current lifecycle phase as reflected on `data-state`. */\n get #state(): string {\n return this.element.getAttribute(\"data-state\") ?? \"loading\";\n }\n}\n"]}
|
|
@@ -11,7 +11,7 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
11
11
|
* data-stimeo--slider-value-value="40">
|
|
12
12
|
* <div data-stimeo--slider-target="track"
|
|
13
13
|
* data-action="pointerdown->stimeo--slider#onPointerDown">
|
|
14
|
-
* <div data-stimeo--slider-target="thumb" role="slider" tabindex="0"
|
|
14
|
+
* <div data-stimeo--slider-target="thumb" role="slider" tabindex="0" aria-label="Volume"
|
|
15
15
|
* aria-valuemin="0" aria-valuemax="100" aria-valuenow="40"
|
|
16
16
|
* data-action="keydown->stimeo--slider#onKeydown"></div>
|
|
17
17
|
* </div>
|
|
@@ -31,6 +31,8 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
31
31
|
* - `ArrowRight`/`ArrowUp` increase and `ArrowLeft`/`ArrowDown` decrease by one
|
|
32
32
|
* step; `Home`/`End` jump to the min/max; `PageUp`/`PageDown` move by ten steps.
|
|
33
33
|
* - Pointer press/drag on the track sets the value from the pointer position.
|
|
34
|
+
* - `step` must be finite and positive; invalid runtime input falls back to `1`.
|
|
35
|
+
* Finite endpoints remain allowed even when they do not align to the step grid.
|
|
34
36
|
*
|
|
35
37
|
* The fraction is a value ratio, not a position, so only the consumer knows
|
|
36
38
|
* whether their track mirrors under RTL. Set `logicalTrack` to declare that it
|
|
@@ -77,6 +79,20 @@ declare class SliderController extends Controller<HTMLElement> {
|
|
|
77
79
|
connect(): void;
|
|
78
80
|
/** Cancels any active pointer drag so document listeners never leak. */
|
|
79
81
|
disconnect(): void;
|
|
82
|
+
/** Silently repaints a minimum changed by application code or a Turbo morph. */
|
|
83
|
+
minValueChanged(): void;
|
|
84
|
+
/** Silently repaints a maximum changed by application code or a Turbo morph. */
|
|
85
|
+
maxValueChanged(): void;
|
|
86
|
+
/** Silently repaints a step changed by application code or a Turbo morph. */
|
|
87
|
+
stepValueChanged(): void;
|
|
88
|
+
/** Silently repaints a value changed by application code or a Turbo morph. */
|
|
89
|
+
valueValueChanged(): void;
|
|
90
|
+
/** Hydrates a thumb inserted or replaced at runtime with the current ARIA state. */
|
|
91
|
+
thumbTargetConnected(thumb: HTMLElement): void;
|
|
92
|
+
/** Drops the stale focus owner while allowing a live track gesture to continue. */
|
|
93
|
+
thumbTargetDisconnected(thumb: HTMLElement): void;
|
|
94
|
+
/** Ends a gesture whose geometry target disappeared or ceased being a target. */
|
|
95
|
+
trackTargetDisconnected(track: HTMLElement): void;
|
|
80
96
|
/** Handles keyboard stepping per the APG slider model. */
|
|
81
97
|
onKeydown(event: KeyboardEvent): void;
|
|
82
98
|
/** Begins a pointer drag: sets the value and tracks subsequent movement. */
|