stimeo-ui 0.6.0 → 0.7.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 +62 -0
- package/dist/controllers/alert_dialog_controller.d.ts +2 -0
- package/dist/controllers/alert_dialog_controller.js +75 -4
- package/dist/controllers/alert_dialog_controller.js.map +1 -1
- package/dist/controllers/auto_submit_controller.d.ts +2 -0
- package/dist/controllers/auto_submit_controller.js.map +1 -1
- package/dist/controllers/avatar_controller.js +47 -5
- package/dist/controllers/avatar_controller.js.map +1 -1
- package/dist/controllers/breadcrumb_controller.d.ts +2 -0
- package/dist/controllers/breadcrumb_controller.js.map +1 -1
- package/dist/controllers/bulk_select_controller.d.ts +2 -0
- package/dist/controllers/bulk_select_controller.js.map +1 -1
- package/dist/controllers/calendar_controller.d.ts +2 -0
- package/dist/controllers/calendar_controller.js.map +1 -1
- package/dist/controllers/character_counter_controller.d.ts +52 -20
- package/dist/controllers/character_counter_controller.js +338 -63
- package/dist/controllers/character_counter_controller.js.map +1 -1
- package/dist/controllers/checkbox_controller.d.ts +3 -0
- package/dist/controllers/checkbox_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +3 -0
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/combobox_controller.d.ts +2 -0
- package/dist/controllers/combobox_controller.js.map +1 -1
- package/dist/controllers/command_palette_controller.d.ts +2 -0
- package/dist/controllers/command_palette_controller.js +75 -4
- package/dist/controllers/command_palette_controller.js.map +1 -1
- package/dist/controllers/conditional_fields_controller.d.ts +42 -14
- package/dist/controllers/conditional_fields_controller.js +345 -51
- package/dist/controllers/conditional_fields_controller.js.map +1 -1
- package/dist/controllers/confirm_controller.d.ts +2 -0
- package/dist/controllers/confirm_controller.js +75 -4
- package/dist/controllers/confirm_controller.js.map +1 -1
- package/dist/controllers/count_up_controller.d.ts +2 -0
- package/dist/controllers/count_up_controller.js.map +1 -1
- package/dist/controllers/countdown_controller.d.ts +4 -0
- package/dist/controllers/countdown_controller.js.map +1 -1
- package/dist/controllers/currency_input_controller.d.ts +2 -0
- package/dist/controllers/currency_input_controller.js.map +1 -1
- package/dist/controllers/data_grid_controller.d.ts +3 -0
- package/dist/controllers/data_grid_controller.js.map +1 -1
- package/dist/controllers/dialog_controller.js +75 -4
- package/dist/controllers/dialog_controller.js.map +1 -1
- package/dist/controllers/direct_upload_controller.d.ts +56 -24
- package/dist/controllers/direct_upload_controller.js +201 -45
- package/dist/controllers/direct_upload_controller.js.map +1 -1
- package/dist/controllers/dirty_form_controller.d.ts +14 -6
- package/dist/controllers/dirty_form_controller.js +192 -29
- package/dist/controllers/dirty_form_controller.js.map +1 -1
- package/dist/controllers/dismissible_controller.d.ts +2 -0
- package/dist/controllers/dismissible_controller.js +83 -18
- package/dist/controllers/dismissible_controller.js.map +1 -1
- package/dist/controllers/drawer_controller.js +75 -4
- package/dist/controllers/drawer_controller.js.map +1 -1
- package/dist/controllers/empty_state_controller.d.ts +2 -0
- package/dist/controllers/empty_state_controller.js.map +1 -1
- package/dist/controllers/file_dropzone_controller.d.ts +2 -0
- package/dist/controllers/file_dropzone_controller.js.map +1 -1
- package/dist/controllers/filter_controller.d.ts +2 -0
- package/dist/controllers/filter_controller.js.map +1 -1
- package/dist/controllers/flash_controller.d.ts +4 -0
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/focus_controller.d.ts +2 -0
- package/dist/controllers/focus_controller.js +75 -4
- package/dist/controllers/focus_controller.js.map +1 -1
- package/dist/controllers/form_field_controller.d.ts +50 -10
- package/dist/controllers/form_field_controller.js +280 -62
- package/dist/controllers/form_field_controller.js.map +1 -1
- package/dist/controllers/form_validation_controller.d.ts +10 -8
- package/dist/controllers/form_validation_controller.js +208 -83
- package/dist/controllers/form_validation_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.d.ts +2 -0
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/highlight_controller.d.ts +2 -0
- package/dist/controllers/highlight_controller.js.map +1 -1
- package/dist/controllers/idle_controller.d.ts +2 -0
- package/dist/controllers/idle_controller.js.map +1 -1
- package/dist/controllers/input_mask_controller.d.ts +2 -0
- package/dist/controllers/input_mask_controller.js.map +1 -1
- package/dist/controllers/lazy_frame_controller.d.ts +2 -0
- package/dist/controllers/lazy_frame_controller.js.map +1 -1
- package/dist/controllers/listbox_controller.d.ts +2 -0
- package/dist/controllers/listbox_controller.js.map +1 -1
- package/dist/controllers/local_time_controller.d.ts +2 -0
- package/dist/controllers/local_time_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +2 -0
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/meter_controller.d.ts +2 -0
- package/dist/controllers/meter_controller.js.map +1 -1
- package/dist/controllers/multi_select_controller.d.ts +2 -0
- package/dist/controllers/multi_select_controller.js.map +1 -1
- package/dist/controllers/nested_form_controller.d.ts +2 -0
- package/dist/controllers/nested_form_controller.js.map +1 -1
- package/dist/controllers/network_status_controller.d.ts +2 -0
- package/dist/controllers/network_status_controller.js.map +1 -1
- package/dist/controllers/number_input_controller.d.ts +2 -0
- package/dist/controllers/number_input_controller.js +47 -5
- package/dist/controllers/number_input_controller.js.map +1 -1
- package/dist/controllers/otp_controller.d.ts +3 -0
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/overflow_indicator_controller.d.ts +2 -0
- package/dist/controllers/overflow_indicator_controller.js.map +1 -1
- package/dist/controllers/overflow_menu_controller.d.ts +2 -0
- package/dist/controllers/overflow_menu_controller.js +2 -1
- package/dist/controllers/overflow_menu_controller.js.map +1 -1
- package/dist/controllers/pagination_controller.d.ts +2 -0
- package/dist/controllers/pagination_controller.js +2 -1
- package/dist/controllers/pagination_controller.js.map +1 -1
- package/dist/controllers/password_reveal_controller.d.ts +2 -0
- package/dist/controllers/password_reveal_controller.js.map +1 -1
- package/dist/controllers/password_strength_controller.d.ts +2 -0
- package/dist/controllers/password_strength_controller.js.map +1 -1
- package/dist/controllers/persist_controller.d.ts +30 -16
- package/dist/controllers/persist_controller.js +432 -122
- package/dist/controllers/persist_controller.js.map +1 -1
- package/dist/controllers/pointer_drag_controller.d.ts +3 -0
- package/dist/controllers/pointer_drag_controller.js.map +1 -1
- package/dist/controllers/popover_controller.js +77 -4
- package/dist/controllers/popover_controller.js.map +1 -1
- package/dist/controllers/portal_controller.d.ts +2 -0
- package/dist/controllers/portal_controller.js.map +1 -1
- package/dist/controllers/preview_guard_controller.d.ts +2 -0
- package/dist/controllers/preview_guard_controller.js.map +1 -1
- package/dist/controllers/progress_controller.d.ts +3 -0
- package/dist/controllers/progress_controller.js.map +1 -1
- package/dist/controllers/radio_group_controller.d.ts +3 -0
- package/dist/controllers/radio_group_controller.js.map +1 -1
- package/dist/controllers/rating_controller.d.ts +2 -0
- package/dist/controllers/rating_controller.js +9 -5
- package/dist/controllers/rating_controller.js.map +1 -1
- package/dist/controllers/reading_progress_controller.d.ts +2 -0
- package/dist/controllers/reading_progress_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +2 -0
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/controllers/roving_controller.d.ts +2 -0
- package/dist/controllers/roving_controller.js.map +1 -1
- package/dist/controllers/scroll_area_controller.d.ts +23 -15
- package/dist/controllers/scroll_area_controller.js +462 -162
- package/dist/controllers/scroll_area_controller.js.map +1 -1
- package/dist/controllers/scroll_visibility_controller.d.ts +2 -0
- package/dist/controllers/scroll_visibility_controller.js.map +1 -1
- package/dist/controllers/scrollspy_controller.d.ts +2 -0
- package/dist/controllers/scrollspy_controller.js.map +1 -1
- package/dist/controllers/separator_controller.d.ts +54 -11
- package/dist/controllers/separator_controller.js +354 -38
- package/dist/controllers/separator_controller.js.map +1 -1
- package/dist/controllers/sidebar_controller.js +83 -10
- package/dist/controllers/sidebar_controller.js.map +1 -1
- package/dist/controllers/skeleton_controller.d.ts +2 -0
- package/dist/controllers/skeleton_controller.js.map +1 -1
- package/dist/controllers/slider_controller.d.ts +2 -0
- package/dist/controllers/slider_controller.js.map +1 -1
- package/dist/controllers/smart_sticky_header_controller.d.ts +2 -0
- package/dist/controllers/smart_sticky_header_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.d.ts +2 -0
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/step_indicator_controller.d.ts +2 -0
- package/dist/controllers/step_indicator_controller.js.map +1 -1
- package/dist/controllers/stepper_controller.d.ts +2 -0
- package/dist/controllers/stepper_controller.js.map +1 -1
- package/dist/controllers/stick_to_bottom_controller.d.ts +2 -0
- package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
- package/dist/controllers/sticky_observer_controller.d.ts +2 -0
- package/dist/controllers/sticky_observer_controller.js.map +1 -1
- package/dist/controllers/submit_once_controller.d.ts +94 -38
- package/dist/controllers/submit_once_controller.js +399 -121
- package/dist/controllers/submit_once_controller.js.map +1 -1
- package/dist/controllers/switch_controller.d.ts +2 -0
- package/dist/controllers/switch_controller.js.map +1 -1
- package/dist/controllers/tags_input_controller.d.ts +2 -0
- package/dist/controllers/tags_input_controller.js.map +1 -1
- package/dist/controllers/textarea_autosize_controller.d.ts +2 -0
- package/dist/controllers/textarea_autosize_controller.js.map +1 -1
- package/dist/controllers/theme_controller.d.ts +2 -0
- package/dist/controllers/theme_controller.js +8 -6
- package/dist/controllers/theme_controller.js.map +1 -1
- package/dist/controllers/time_picker_controller.d.ts +2 -0
- package/dist/controllers/time_picker_controller.js.map +1 -1
- package/dist/controllers/toast_controller.d.ts +4 -0
- package/dist/controllers/toast_controller.js.map +1 -1
- package/dist/controllers/toggle_group_controller.d.ts +2 -0
- package/dist/controllers/toggle_group_controller.js.map +1 -1
- package/dist/controllers/toolbar_controller.js.map +1 -1
- package/dist/controllers/transition_controller.d.ts +2 -0
- package/dist/controllers/transition_controller.js.map +1 -1
- package/dist/controllers/tree_view_controller.d.ts +2 -0
- package/dist/controllers/tree_view_controller.js +2 -1
- package/dist/controllers/tree_view_controller.js.map +1 -1
- package/dist/index.js +2387 -861
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +107 -3
- package/dist/inspector/cli.js +192 -14
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +254 -46
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +7 -7
- package/dist/inspector/manifest.json +434 -44
- package/dist/positioning/index.d.ts +2 -0
- package/dist/positioning/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,93 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/character_counter_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/attribute_lease.ts
|
|
23
|
+
var AttributeLease = class {
|
|
24
|
+
#attribute;
|
|
25
|
+
#records = /* @__PURE__ */ new Map();
|
|
26
|
+
/** @param attribute - The attribute whose temporary values this lease owns. */
|
|
27
|
+
constructor(attribute) {
|
|
28
|
+
this.#attribute = attribute;
|
|
29
|
+
}
|
|
30
|
+
/** Writes or removes the leased attribute while preserving its authored value. */
|
|
31
|
+
write(element, value) {
|
|
32
|
+
const existing = this.#records.get(element);
|
|
33
|
+
if (existing) {
|
|
34
|
+
existing.written = value;
|
|
35
|
+
} else {
|
|
36
|
+
this.#records.set(element, {
|
|
37
|
+
original: element.getAttribute(this.#attribute),
|
|
38
|
+
written: value
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.#reflect(element, value);
|
|
42
|
+
}
|
|
43
|
+
/** Returns one lease without overwriting a value subsequently authored by a consumer. */
|
|
44
|
+
return(element) {
|
|
45
|
+
const record = this.#records.get(element);
|
|
46
|
+
if (!record) return;
|
|
47
|
+
this.#records.delete(element);
|
|
48
|
+
const stillOwned = element.getAttribute(this.#attribute) === record.written;
|
|
49
|
+
if (stillOwned) this.#reflect(element, record.original);
|
|
50
|
+
}
|
|
51
|
+
/** Reflects only a real value transition, avoiding self-triggered mutation work. */
|
|
52
|
+
#reflect(element, value) {
|
|
53
|
+
if (element.getAttribute(this.#attribute) === value) return;
|
|
54
|
+
if (value === null) element.removeAttribute(this.#attribute);
|
|
55
|
+
else element.setAttribute(this.#attribute, value);
|
|
56
|
+
}
|
|
57
|
+
/** Returns every outstanding lease using the same ownership check as {@link return}. */
|
|
58
|
+
returnAll() {
|
|
59
|
+
for (const element of Array.from(this.#records.keys())) this.return(element);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/utils/before_cache_reset.ts
|
|
64
|
+
var BeforeCacheReset = class _BeforeCacheReset {
|
|
65
|
+
/** Every subscribed instance, iterated by the one shared document listener. */
|
|
66
|
+
static #subscribers = /* @__PURE__ */ new Set();
|
|
67
|
+
/** The shared listener; installed while at least one instance is subscribed. */
|
|
68
|
+
static #onBeforeCache = () => {
|
|
69
|
+
for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
|
|
70
|
+
};
|
|
71
|
+
#rewind;
|
|
72
|
+
/** @param rewind - the pass that returns this controller's state to its initial form. */
|
|
73
|
+
constructor(rewind) {
|
|
74
|
+
this.#rewind = rewind;
|
|
75
|
+
}
|
|
76
|
+
/** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
|
|
77
|
+
activate() {
|
|
78
|
+
const first = _BeforeCacheReset.#subscribers.size === 0;
|
|
79
|
+
_BeforeCacheReset.#subscribers.add(this);
|
|
80
|
+
if (first) {
|
|
81
|
+
document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
|
|
85
|
+
deactivate() {
|
|
86
|
+
_BeforeCacheReset.#subscribers.delete(this);
|
|
87
|
+
if (_BeforeCacheReset.#subscribers.size > 0) return;
|
|
88
|
+
document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
5
92
|
// src/utils/composition_tracker.ts
|
|
6
93
|
var CompositionTracker = class {
|
|
7
94
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -49,6 +136,39 @@ var CompositionTracker = class {
|
|
|
49
136
|
};
|
|
50
137
|
};
|
|
51
138
|
|
|
139
|
+
// src/utils/microtask_coalescer.ts
|
|
140
|
+
var MicrotaskCoalescer = class {
|
|
141
|
+
#run;
|
|
142
|
+
#queued = false;
|
|
143
|
+
#active = false;
|
|
144
|
+
#generation = 0;
|
|
145
|
+
/** @param run - the single reconciliation pass, invoked at most once per batch. */
|
|
146
|
+
constructor(run) {
|
|
147
|
+
this.#run = run;
|
|
148
|
+
}
|
|
149
|
+
/** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
|
|
150
|
+
activate() {
|
|
151
|
+
this.#active = true;
|
|
152
|
+
}
|
|
153
|
+
/** Closes the window and drops any pending pass; call from `disconnect()`. */
|
|
154
|
+
cancel() {
|
|
155
|
+
this.#active = false;
|
|
156
|
+
this.#queued = false;
|
|
157
|
+
this.#generation += 1;
|
|
158
|
+
}
|
|
159
|
+
/** Requests one pass after the batch settles. Idempotent; inert outside the window. */
|
|
160
|
+
schedule() {
|
|
161
|
+
if (!this.#active || this.#queued) return;
|
|
162
|
+
this.#queued = true;
|
|
163
|
+
const generation = this.#generation;
|
|
164
|
+
queueMicrotask(() => {
|
|
165
|
+
if (generation !== this.#generation || !this.#queued || !this.#active) return;
|
|
166
|
+
this.#queued = false;
|
|
167
|
+
this.#run();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
52
172
|
// src/utils/safe_timeout.ts
|
|
53
173
|
var TimerRegistry = class {
|
|
54
174
|
/** Live timer ids that have not yet been cleared (or, for timeouts, fired). */
|
|
@@ -103,110 +223,265 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
103
223
|
};
|
|
104
224
|
|
|
105
225
|
// src/controllers/character_counter_controller.ts
|
|
106
|
-
var ORIGINAL_INVALID = "data-character-counter-original-invalid";
|
|
107
226
|
var CharacterCounterController = class _CharacterCounterController extends Controller {
|
|
108
227
|
static targets = ["input", "output"];
|
|
109
228
|
static values = {
|
|
110
229
|
max: { type: Number, default: 0 },
|
|
111
230
|
warnAt: { type: Number, default: 0 },
|
|
112
|
-
mode: { type: String, default: "remaining" }
|
|
231
|
+
mode: { type: String, default: "remaining" },
|
|
232
|
+
announceText: { type: String, default: "" }
|
|
113
233
|
};
|
|
114
|
-
static events = ["change"];
|
|
115
|
-
/** Delay (ms) before
|
|
234
|
+
static events = ["change", "reconcile"];
|
|
235
|
+
/** Delay (ms) before one settled count is sent to the shared announcer. */
|
|
116
236
|
static #announceDelay = 200;
|
|
117
237
|
#timeouts = new SafeTimeout();
|
|
238
|
+
#ariaInvalid = new AttributeLease("aria-invalid");
|
|
239
|
+
#beforeCache = new BeforeCacheReset(() => this.#rewindForCache());
|
|
240
|
+
#repaint = new MicrotaskCoalescer(() => this.#reconcile(true));
|
|
241
|
+
#composition = new CompositionTracker({
|
|
242
|
+
onEnd: (event) => this.#commitFrom(event.currentTarget)
|
|
243
|
+
});
|
|
118
244
|
#announceId = null;
|
|
119
|
-
|
|
120
|
-
#
|
|
245
|
+
#boundField = null;
|
|
246
|
+
#lastLength = null;
|
|
247
|
+
#lastDetail = null;
|
|
248
|
+
#reflectedOver = null;
|
|
121
249
|
#onInput = (event) => {
|
|
250
|
+
const field = this.#boundField;
|
|
251
|
+
if (!field || event.currentTarget !== field || this.#field !== field) return;
|
|
122
252
|
if (this.#composition.isComposing(event)) return;
|
|
123
|
-
this.#
|
|
253
|
+
this.#commit(field);
|
|
124
254
|
};
|
|
255
|
+
/** Reflects the current DOM state and opens the mutation-reconciliation window. */
|
|
125
256
|
connect() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.#composition.observe(field);
|
|
130
|
-
this.#update({ announce: false });
|
|
257
|
+
this.#repaint.activate();
|
|
258
|
+
this.#beforeCache.activate();
|
|
259
|
+
this.#reconcile(false);
|
|
131
260
|
}
|
|
261
|
+
/** Releases listeners, timers, borrowed ARIA, and controller-owned state hooks. */
|
|
132
262
|
disconnect() {
|
|
133
|
-
|
|
134
|
-
|
|
263
|
+
this.#repaint.cancel();
|
|
264
|
+
this.#beforeCache.deactivate();
|
|
265
|
+
this.#cancelAnnouncement();
|
|
266
|
+
this.#bindField(null);
|
|
135
267
|
this.#composition.disconnect();
|
|
136
|
-
this.#
|
|
137
|
-
this.#
|
|
268
|
+
this.#clearStateHooks();
|
|
269
|
+
this.#lastLength = null;
|
|
270
|
+
this.#lastDetail = null;
|
|
271
|
+
}
|
|
272
|
+
/** Rebinds and repaints after an input target is added or replaced at runtime. */
|
|
273
|
+
inputTargetConnected() {
|
|
274
|
+
this.#repaint.schedule();
|
|
275
|
+
}
|
|
276
|
+
/** Releases and repaints after an input target is removed or replaced at runtime. */
|
|
277
|
+
inputTargetDisconnected() {
|
|
278
|
+
this.#repaint.schedule();
|
|
279
|
+
}
|
|
280
|
+
/** Initializes a display target inserted after the controller connected. */
|
|
281
|
+
outputTargetConnected() {
|
|
282
|
+
this.#repaint.schedule();
|
|
283
|
+
}
|
|
284
|
+
/** Reconciles the optional display target set after a removal or replacement. */
|
|
285
|
+
outputTargetDisconnected() {
|
|
286
|
+
this.#repaint.schedule();
|
|
287
|
+
}
|
|
288
|
+
/** Repaints when application code or a Turbo morph changes `max`. */
|
|
289
|
+
maxValueChanged() {
|
|
290
|
+
this.#repaint.schedule();
|
|
291
|
+
}
|
|
292
|
+
/** Repaints when application code or a Turbo morph changes `warnAt`. */
|
|
293
|
+
warnAtValueChanged() {
|
|
294
|
+
this.#repaint.schedule();
|
|
295
|
+
}
|
|
296
|
+
/** Repaints when application code or a Turbo morph changes `mode`. */
|
|
297
|
+
modeValueChanged() {
|
|
298
|
+
this.#repaint.schedule();
|
|
299
|
+
}
|
|
300
|
+
/** Cancels a pending old message when its consumer-authored template changes. */
|
|
301
|
+
announceTextValueChanged() {
|
|
302
|
+
this.#repaint.schedule();
|
|
303
|
+
}
|
|
304
|
+
/** Rebinds one mutation batch and reports a changed controller-derived state. */
|
|
305
|
+
#reconcile(report) {
|
|
306
|
+
const previous = this.#lastDetail;
|
|
307
|
+
const owedField = this.#announceId === null ? null : this.#boundField;
|
|
308
|
+
this.#cancelAnnouncement();
|
|
309
|
+
this.#bindField(this.#field);
|
|
310
|
+
if (this.#composition.isComposing()) return;
|
|
311
|
+
const field = this.#boundField;
|
|
312
|
+
if (!field) {
|
|
313
|
+
this.#renderEmpty();
|
|
314
|
+
this.#lastLength = null;
|
|
315
|
+
this.#lastDetail = null;
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const reading = this.#render(field);
|
|
319
|
+
const detail = this.#detail(reading);
|
|
320
|
+
this.#lastLength = reading.length;
|
|
321
|
+
this.#lastDetail = detail;
|
|
322
|
+
if (owedField === field) this.#scheduleAnnouncement(reading);
|
|
323
|
+
if (report && previous && this.#detailsDiffer(previous, detail)) {
|
|
324
|
+
this.dispatch("reconcile", { detail });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/** Commits a composition only when it came from the field still owned here. */
|
|
328
|
+
#commitFrom(target) {
|
|
329
|
+
const field = this.#boundField;
|
|
330
|
+
if (!field || target !== field || this.#field !== field) return;
|
|
331
|
+
this.#commit(field);
|
|
332
|
+
}
|
|
333
|
+
/** Reflects one confirmed user input and reports only a real length transition. */
|
|
334
|
+
#commit(field) {
|
|
335
|
+
const reading = this.#render(field);
|
|
336
|
+
const previousLength = this.#lastLength;
|
|
337
|
+
const previousDetail = this.#lastDetail;
|
|
338
|
+
const detail = this.#detail(reading);
|
|
339
|
+
this.#lastLength = reading.length;
|
|
340
|
+
this.#lastDetail = detail;
|
|
341
|
+
if (previousLength === reading.length) {
|
|
342
|
+
if (previousDetail && this.#detailsDiffer(previousDetail, detail)) {
|
|
343
|
+
this.dispatch("reconcile", { detail });
|
|
344
|
+
}
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
this.dispatch("change", { detail });
|
|
348
|
+
this.#scheduleAnnouncement(reading);
|
|
349
|
+
}
|
|
350
|
+
/** Selects the public event state from the richer internal reading. */
|
|
351
|
+
#detail(reading) {
|
|
352
|
+
return {
|
|
353
|
+
length: reading.length,
|
|
354
|
+
remaining: reading.remaining,
|
|
355
|
+
over: reading.over
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/** Compares exactly the state carried by `change` and `reconcile`. */
|
|
359
|
+
#detailsDiffer(left, right) {
|
|
360
|
+
return left.length !== right.length || left.remaining !== right.remaining || left.over !== right.over;
|
|
138
361
|
}
|
|
139
362
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
363
|
+
* Synchronizes visible count, state hooks, and temporary validation ARIA.
|
|
364
|
+
*
|
|
365
|
+
* @stimeoRenderRoot
|
|
143
366
|
*/
|
|
144
|
-
#
|
|
145
|
-
const field = this.#field;
|
|
146
|
-
if (!field) return;
|
|
367
|
+
#render(field) {
|
|
147
368
|
const length = field.value.length;
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
369
|
+
const max = this.#normalizeCount(this.maxValue);
|
|
370
|
+
const warnAt = this.#normalizeCount(this.warnAtValue);
|
|
371
|
+
const remaining = max > 0 ? max - length : null;
|
|
372
|
+
const over = remaining !== null && remaining < 0;
|
|
373
|
+
const near = remaining !== null && warnAt > 0 && !over && remaining <= warnAt;
|
|
152
374
|
this.#toggle("data-over-limit", over);
|
|
153
375
|
this.#toggle("data-near-limit", near);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
376
|
+
this.#reflectInvalid(field, over);
|
|
377
|
+
const text = this.#format(length, remaining, max);
|
|
378
|
+
this.#writeOutput(text);
|
|
379
|
+
return { length, remaining, over, max, text };
|
|
380
|
+
}
|
|
381
|
+
/** Clears derived output when the declarative input set has no usable field. */
|
|
382
|
+
#renderEmpty() {
|
|
383
|
+
this.#ariaInvalid.returnAll();
|
|
384
|
+
this.#reflectedOver = null;
|
|
385
|
+
this.#clearStateHooks();
|
|
386
|
+
this.#writeOutput("");
|
|
387
|
+
}
|
|
388
|
+
/** Replaces the observed field symmetrically, returning state from the old one. */
|
|
389
|
+
#bindField(field) {
|
|
390
|
+
if (field === this.#boundField) return;
|
|
391
|
+
const previous = this.#boundField;
|
|
392
|
+
if (previous) {
|
|
393
|
+
previous.removeEventListener("input", this.#onInput);
|
|
394
|
+
this.#composition.unobserve(previous);
|
|
395
|
+
this.#ariaInvalid.return(previous);
|
|
172
396
|
}
|
|
173
|
-
this
|
|
174
|
-
|
|
175
|
-
this.#
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
397
|
+
this.#boundField = field;
|
|
398
|
+
this.#lastLength = null;
|
|
399
|
+
this.#reflectedOver = null;
|
|
400
|
+
if (!field) return;
|
|
401
|
+
field.addEventListener("input", this.#onInput);
|
|
402
|
+
this.#composition.observe(field);
|
|
403
|
+
}
|
|
404
|
+
/** Leases `aria-invalid` only on the edge into over-limit, then returns it. */
|
|
405
|
+
#reflectInvalid(field, over) {
|
|
406
|
+
if (this.#reflectedOver === over) return;
|
|
407
|
+
this.#reflectedOver = over;
|
|
408
|
+
if (over) this.#ariaInvalid.write(field, "true");
|
|
409
|
+
else this.#ariaInvalid.return(field);
|
|
179
410
|
}
|
|
180
|
-
/** Builds the count
|
|
181
|
-
#format(length, remaining) {
|
|
411
|
+
/** Builds the visible count for the normalized display mode. */
|
|
412
|
+
#format(length, remaining, max) {
|
|
182
413
|
if (remaining === null) return String(length);
|
|
183
|
-
switch (this
|
|
414
|
+
switch (this.#mode) {
|
|
184
415
|
case "used":
|
|
185
416
|
return String(length);
|
|
186
417
|
case "both":
|
|
187
|
-
return `${length}/${
|
|
418
|
+
return `${length}/${max}`;
|
|
188
419
|
default:
|
|
189
420
|
return String(remaining);
|
|
190
421
|
}
|
|
191
422
|
}
|
|
423
|
+
/** Debounces one i18n-neutral message into the shared polite announcer. */
|
|
424
|
+
#scheduleAnnouncement(reading) {
|
|
425
|
+
this.#cancelAnnouncement();
|
|
426
|
+
const message = fillTemplate(this.announceTextValue, {
|
|
427
|
+
count: reading.text,
|
|
428
|
+
length: reading.length,
|
|
429
|
+
remaining: reading.remaining ?? "",
|
|
430
|
+
max: reading.max,
|
|
431
|
+
over: String(reading.over)
|
|
432
|
+
});
|
|
433
|
+
if (message.trim().length === 0) return;
|
|
434
|
+
this.#announceId = this.#timeouts.set(() => {
|
|
435
|
+
announce(message);
|
|
436
|
+
this.#announceId = null;
|
|
437
|
+
}, _CharacterCounterController.#announceDelay);
|
|
438
|
+
}
|
|
439
|
+
/** Cancels the one outstanding announcement without touching visible output. */
|
|
440
|
+
#cancelAnnouncement() {
|
|
441
|
+
if (this.#announceId !== null) this.#timeouts.clear(this.#announceId);
|
|
442
|
+
this.#announceId = null;
|
|
443
|
+
}
|
|
444
|
+
/** Writes the optional display only when its text actually changed. */
|
|
192
445
|
#writeOutput(text) {
|
|
193
|
-
if (this.hasOutputTarget
|
|
446
|
+
if (!this.hasOutputTarget || this.outputTarget.textContent === text) return;
|
|
447
|
+
this.outputTarget.textContent = text;
|
|
194
448
|
}
|
|
195
|
-
/**
|
|
449
|
+
/** Reflects a presence-style state hook without redundant attribute writes. */
|
|
196
450
|
#toggle(name, on) {
|
|
197
451
|
if (on) {
|
|
198
|
-
this.element.setAttribute(name, "true");
|
|
199
|
-
} else {
|
|
452
|
+
if (this.element.getAttribute(name) !== "true") this.element.setAttribute(name, "true");
|
|
453
|
+
} else if (this.element.hasAttribute(name)) {
|
|
200
454
|
this.element.removeAttribute(name);
|
|
201
455
|
}
|
|
202
456
|
}
|
|
203
|
-
/**
|
|
457
|
+
/** Removes both state hooks owned by this controller. */
|
|
458
|
+
#clearStateHooks() {
|
|
459
|
+
this.#toggle("data-over-limit", false);
|
|
460
|
+
this.#toggle("data-near-limit", false);
|
|
461
|
+
}
|
|
462
|
+
/** Returns borrowed ARIA and transient hooks before Turbo snapshots the page. */
|
|
463
|
+
#rewindForCache() {
|
|
464
|
+
this.#cancelAnnouncement();
|
|
465
|
+
this.#ariaInvalid.returnAll();
|
|
466
|
+
this.#reflectedOver = null;
|
|
467
|
+
this.#clearStateHooks();
|
|
468
|
+
}
|
|
469
|
+
/** Converts a public count Value into a finite non-negative integer. */
|
|
470
|
+
#normalizeCount(raw) {
|
|
471
|
+
if (!Number.isFinite(raw)) return 0;
|
|
472
|
+
return Math.max(0, Math.trunc(raw));
|
|
473
|
+
}
|
|
474
|
+
/** Falls back to `remaining` when an authored display mode is unknown. */
|
|
475
|
+
get #mode() {
|
|
476
|
+
if (this.modeValue === "used" || this.modeValue === "both") return this.modeValue;
|
|
477
|
+
return "remaining";
|
|
478
|
+
}
|
|
479
|
+
/** The watched field: the first target, or a directly controlled form field. */
|
|
204
480
|
get #field() {
|
|
205
481
|
if (this.hasInputTarget) return this.inputTarget;
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
return
|
|
209
|
-
}
|
|
482
|
+
const element = this.element;
|
|
483
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement)
|
|
484
|
+
return element;
|
|
210
485
|
return null;
|
|
211
486
|
}
|
|
212
487
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/composition_tracker.ts","../../src/utils/safe_timeout.ts","../../src/controllers/character_counter_controller.ts"],"names":[],"mappings":";;;;;AAuCO,IAAM,qBAAN,MAAyB;AAAA,EACrB,gBAAA,uBAAuB,GAAA,EAAiB;AAAA,EACxC,cAAA,uBAAqB,GAAA,EAAiB;AAAA,EACtC,QAAA;AAAA,EACA,MAAA;AAAA,EAET,WAAA,CAAY,OAAA,GAAqC,EAAC,EAAG;AACnD,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,OAAA;AACxB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,KAAA;AAAA,EACxB;AAAA;AAAA,EAGA,QAAQ,MAAA,EAA2B;AACjC,IAAA,IAAI,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAI,MAAM,CAAA,EAAG;AACvC,IAAA,MAAA,CAAO,gBAAA,CAAiB,kBAAA,EAAoB,IAAA,CAAK,YAAY,CAAA;AAC7D,IAAA,MAAA,CAAO,gBAAA,CAAiB,gBAAA,EAAkB,IAAA,CAAK,UAAU,CAAA;AACzD,IAAA,IAAA,CAAK,gBAAA,CAAiB,IAAI,MAAM,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,UAAU,MAAA,EAA2B;AACnC,IAAA,IAAI,CAAC,IAAA,CAAK,gBAAA,CAAiB,MAAA,CAAO,MAAM,CAAA,EAAG;AAC3C,IAAA,MAAA,CAAO,mBAAA,CAAoB,kBAAA,EAAoB,IAAA,CAAK,YAAY,CAAA;AAChE,IAAA,MAAA,CAAO,mBAAA,CAAoB,gBAAA,EAAkB,IAAA,CAAK,UAAU,CAAA;AAC5D,IAAA,IAAA,CAAK,cAA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MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,IAAA,EAAM,MAAM,CAAA;AAAA,IACxC,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,OAAA,CAAQ,gBAAgB,IAAI,CAAA;AAAA,IACnC;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,MAAA,GAAwD;AAC1D,IAAA,IAAI,IAAA,CAAK,cAAA,EAAgB,OAAO,IAAA,CAAK,WAAA;AACrC,IAAA,MAAM,KAAkB,IAAA,CAAK,OAAA;AAC7B,IAAA,IAAI,EAAA,YAAc,gBAAA,IAAoB,EAAA,YAAc,mBAAA,EAAqB;AACvE,MAAA,OAAO,EAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"character_counter_controller.js","sourcesContent":["/** Minimal event shape carrying the platform's per-event composition signal. */\nexport interface CompositionSignal {\n readonly isComposing?: boolean;\n}\n\n/** Hooks that keep component-specific work outside {@link CompositionTracker}. */\nexport interface CompositionTrackerOptions {\n /** Runs after lifecycle state is set for a `compositionstart` event. */\n readonly onStart?: (event: Event) => void;\n /** Runs after lifecycle state is cleared for a `compositionend` event. */\n readonly onEnd?: (event: Event) => void;\n}\n\n/**\n * Owns IME composition listeners and transient state for one or more event targets.\n *\n * Some browsers omit `KeyboardEvent.isComposing` on the keydown that confirms a\n * conversion. Tracking `compositionstart` through `compositionend` supplies the\n * missing lifecycle signal without relying on deprecated numeric key codes.\n * Component policy stays with the consumer: filtering, validation, and submission\n * belong in the optional {@link CompositionTrackerOptions.onEnd} callback.\n *\n * @example\n * ```ts\n * #composition = new CompositionTracker({ onEnd: () => this.filter() });\n *\n * connect(): void {\n * this.#composition.observe(this.inputTarget);\n * }\n *\n * disconnect(): void {\n * this.#composition.disconnect();\n * }\n *\n * onKeydown(event: KeyboardEvent): void {\n * if (this.#composition.isComposing(event)) return;\n * }\n * ```\n */\nexport class CompositionTracker {\n readonly #observedTargets = new Set<EventTarget>();\n readonly #activeTargets = new Set<EventTarget>();\n readonly #onStart: ((event: Event) => void) | undefined;\n readonly #onEnd: ((event: Event) => void) | undefined;\n\n constructor(options: CompositionTrackerOptions = {}) {\n this.#onStart = options.onStart;\n this.#onEnd = options.onEnd;\n }\n\n /** Starts lifecycle tracking for `target`; repeated calls are idempotent. */\n observe(target: EventTarget): void {\n if (this.#observedTargets.has(target)) return;\n target.addEventListener(\"compositionstart\", this.#handleStart);\n target.addEventListener(\"compositionend\", this.#handleEnd);\n this.#observedTargets.add(target);\n }\n\n /** Stops tracking one target and clears any active composition it owned. */\n unobserve(target: EventTarget): void {\n if (!this.#observedTargets.delete(target)) return;\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n this.#activeTargets.delete(target);\n }\n\n /** Releases every listener and clears state so reconnect starts cleanly. */\n disconnect(): void {\n for (const target of this.#observedTargets) {\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n }\n this.#observedTargets.clear();\n this.#activeTargets.clear();\n }\n\n /** True when lifecycle tracking or the current event reports composition. */\n isComposing(event?: CompositionSignal): boolean {\n return this.#activeTargets.size > 0 || event?.isComposing === true;\n }\n\n readonly #handleStart = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.add(event.currentTarget);\n this.#onStart?.(event);\n };\n\n readonly #handleEnd = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);\n this.#onEnd?.(event);\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 { CompositionTracker } from \"../utils/composition_tracker\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/** Parks the field's original `aria-invalid` while we override it for over-limit. */\nconst ORIGINAL_INVALID = \"data-character-counter-original-invalid\";\n\n/**\n * Headless character-counter behavior for a text field (no dedicated APG\n * pattern; follows the WCAG 2.2 \"status messages\" practice, 4.1.3).\n *\n * Markup contract (identifier: `stimeo--character-counter`):\n * <div data-controller=\"stimeo--character-counter\"\n * data-stimeo--character-counter-max-value=\"140\">\n * <textarea data-stimeo--character-counter-target=\"input\"\n * aria-describedby=\"cc\"></textarea>\n * <span id=\"cc\" data-stimeo--character-counter-target=\"output\"\n * aria-live=\"polite\"></span>\n * </div>\n *\n * Watches the field's length, writes the remaining/used count into `output`, and\n * toggles the `data-near-limit` / `data-over-limit` state hooks (plus\n * `aria-invalid` on the field once the limit is exceeded). The field is the\n * `input` target, or — when the controller is attached straight onto an\n * `<input>`/`<textarea>` — the controller element itself.\n *\n * @remarks\n * Behavior only — the count text is updated, not styled. Outside IME composition\n * the non-text state (`data-*` hooks, `aria-invalid`, and the `change` event)\n * updates **immediately** on every input so styling and consumers stay responsive,\n * while the visible count — in the `aria-live=\"polite\"` region — is written on a\n * short debounce so a screen reader is not flooded during fast typing (it hears the\n * settled count when the user pauses). During IME composition both are deferred to\n * `compositionend`, so they reflect the confirmed characters rather than the\n * intermediate (pre-conversion) kana. The debounce timer is owned by\n * {@link SafeTimeout} and torn down on `disconnect()` (Turbo navigation included);\n * `connect()` re-reads the field so the count is correct after a cache restore.\n */\nexport class CharacterCounterController extends Controller<HTMLElement> {\n static override targets = [\"input\", \"output\"];\n static override values = {\n max: { type: Number, default: 0 },\n warnAt: { type: Number, default: 0 },\n mode: { type: String, default: \"remaining\" },\n };\n static events = [\"change\"] as const;\n\n declare readonly inputTarget: HTMLInputElement | HTMLTextAreaElement;\n declare readonly outputTarget: HTMLElement;\n declare readonly hasInputTarget: boolean;\n declare readonly hasOutputTarget: boolean;\n\n declare maxValue: number;\n declare warnAtValue: number;\n declare modeValue: string;\n\n /** Delay (ms) before the live-region count is written, to throttle SR flooding. */\n static readonly #announceDelay = 200;\n\n readonly #timeouts = new SafeTimeout();\n #announceId: number | null = null;\n\n /** Owns IME lifecycle state and applies the confirmed count once. */\n readonly #composition = new CompositionTracker({ onEnd: () => this.#update() });\n\n readonly #onInput = (event: Event): void => {\n // During IME composition the field holds unconverted text; defer the count to\n // `compositionend` so it reflects the confirmed characters, not each keystroke.\n if (this.#composition.isComposing(event as InputEvent)) return;\n this.#update();\n };\n\n override connect(): void {\n const field = this.#field;\n if (!field) return;\n field.addEventListener(\"input\", this.#onInput);\n this.#composition.observe(field);\n // Initial render is synchronous (no announce debounce): reflect the current\n // value on connect/cache-restore without queueing a screen-reader message.\n this.#update({ announce: false });\n }\n\n override disconnect(): void {\n const field = this.#field;\n field?.removeEventListener(\"input\", this.#onInput);\n this.#composition.disconnect();\n this.#timeouts.clearAll();\n this.#announceId = null;\n }\n\n /**\n * Recomputes length-derived state. Non-text state (data hooks, `aria-invalid`)\n * and the `change` event apply immediately; the live-region count text is\n * debounced unless `announce` is `false` (initial render).\n */\n #update(options: { announce?: boolean } = {}): void {\n const field = this.#field;\n if (!field) return;\n\n const length = field.value.length;\n const hasLimit = this.maxValue > 0;\n const remaining = hasLimit ? this.maxValue - length : null;\n const over = hasLimit && length > this.maxValue;\n const near =\n hasLimit &&\n this.warnAtValue > 0 &&\n !over &&\n remaining !== null &&\n remaining <= this.warnAtValue;\n\n this.#toggle(\"data-over-limit\", over);\n this.#toggle(\"data-near-limit\", near);\n // `aria-invalid` is a shared attribute (Form Field / server validation also use\n // it), so we never clobber an authored value: park the original when flagging\n // over-limit and restore it once back within the limit.\n if (hasLimit && over) {\n if (!field.hasAttribute(ORIGINAL_INVALID)) {\n field.setAttribute(ORIGINAL_INVALID, field.getAttribute(\"aria-invalid\") ?? \"\");\n }\n field.setAttribute(\"aria-invalid\", \"true\");\n } else if (field.hasAttribute(ORIGINAL_INVALID)) {\n const original = field.getAttribute(ORIGINAL_INVALID);\n if (original) {\n field.setAttribute(\"aria-invalid\", original);\n } else {\n field.removeAttribute(\"aria-invalid\");\n }\n field.removeAttribute(ORIGINAL_INVALID);\n }\n\n const text = this.#format(length, remaining);\n if (options.announce === false) {\n // Initial render (connect / cache-restore): reflect the current state without\n // emitting a change event or queueing a screen-reader announcement.\n this.#writeOutput(text);\n return;\n }\n\n this.dispatch(\"change\", { detail: { length, remaining, over } });\n if (this.#announceId !== null) this.#timeouts.clear(this.#announceId);\n this.#announceId = this.#timeouts.set(() => {\n this.#writeOutput(text);\n this.#announceId = null;\n }, CharacterCounterController.#announceDelay);\n }\n\n /** Builds the count text for the active `mode`. */\n #format(length: number, remaining: number | null): string {\n if (remaining === null) return String(length); // no limit → used count only\n switch (this.modeValue) {\n case \"used\":\n return String(length);\n case \"both\":\n return `${length}/${this.maxValue}`;\n default:\n return String(remaining); // \"remaining\"\n }\n }\n\n #writeOutput(text: string): void {\n if (this.hasOutputTarget) this.outputTarget.textContent = text;\n }\n\n /** Sets a presence-style boolean data hook (attribute present when `on`). */\n #toggle(name: string, on: boolean): void {\n if (on) {\n this.element.setAttribute(name, \"true\");\n } else {\n this.element.removeAttribute(name);\n }\n }\n\n /** The watched field: the `input` target, or the element itself when it is one. */\n get #field(): HTMLInputElement | HTMLTextAreaElement | null {\n if (this.hasInputTarget) return this.inputTarget;\n const el: HTMLElement = this.element;\n if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {\n return el;\n }\n return null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/attribute_lease.ts","../../src/utils/before_cache_reset.ts","../../src/utils/composition_tracker.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/safe_timeout.ts","../../src/controllers/character_counter_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,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAAY,4BAAA,EAA8B;AAAA,MAC5C,QAAQ,EAAE,OAAA,EAAS,MAAM,SAAA,EAAW,OAAA,CAAQ,cAAc,IAAA;AAAK,KAChE;AAAA,GACH;AACF;AAUO,SAAS,YAAA,CAAa,UAAkB,MAAA,EAAiD;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,6BAAA,EAA+B,CAAC,OAAO,IAAA,KAAiB;AAC9E,IAAA,MAAM,WAAA,GAAc,OAAO,IAAI,CAAA;AAC/B,IAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,KAAA,GAAQ,MAAA,CAAO,WAAW,CAAA;AAAA,EAC/D,CAAC,CAAA;AACH;;;ACnBO,IAAM,iBAAN,MAAkD;AAAA,EAC9C,UAAA;AAAA,EACA,QAAA,uBAAe,GAAA,EAA6B;AAAA;AAAA,EAGrD,YAAY,SAAA,EAAmB;AAC7B,IAAA,IAAA,CAAK,UAAA,GAAa,SAA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SAAA;AACxE,IAAA,OAAO,WAAA;AAAA,EACT;AAAA;AAAA,EAGA,IAAI,MAAA,GAAuC;AACzC,IAAA,IAAI,IAAA,CAAK,cAAA,EAAgB,OAAO,IAAA,CAAK,WAAA;AACrC,IAAA,MAAM,UAAuB,IAAA,CAAK,OAAA;AAClC,IAAA,IAAI,OAAA,YAAmB,oBAAoB,OAAA,YAAmB,mBAAA;AAC5D,MAAA,OAAO,OAAA;AACT,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"character_counter_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","/** One temporarily controlled attribute value and the authored value it displaced. */\ninterface AttributeLeaseRecord {\n readonly original: string | null;\n written: string | null;\n}\n\n/**\n * Temporarily controls one attribute across a changing set of elements.\n *\n * The first write remembers the authored value, including the distinction between\n * an absent attribute and an authored empty string. Returning a lease restores that\n * value only while the attribute still matches the controller's last write. If a\n * consumer changed it in the meantime, the consumer owns the new value and teardown\n * leaves it alone.\n *\n * A `null` write deliberately removes the attribute while retaining the lease. This\n * is useful for derived ARIA whose valid absence is itself controller state, such as\n * an unbounded `aria-valuemin` or a blank spinbutton's `aria-valuenow`.\n *\n * The lease has no lifecycle of its own, so it never subscribes to document events.\n * A consumer that must not let a derived value become the authored baseline of a\n * cached page returns its leases from its own `turbo:before-cache` rewind, where the\n * matching `disconnect()` also releases the subscription.\n */\nexport class AttributeLease<T extends Element = Element> {\n readonly #attribute: string;\n readonly #records = new Map<T, AttributeLeaseRecord>();\n\n /** @param attribute - The attribute whose temporary values this lease owns. */\n constructor(attribute: string) {\n this.#attribute = attribute;\n }\n\n /** Writes or removes the leased attribute while preserving its authored value. */\n write(element: T, value: string | null): void {\n const existing = this.#records.get(element);\n if (existing) {\n existing.written = value;\n } else {\n this.#records.set(element, {\n original: element.getAttribute(this.#attribute),\n written: value,\n });\n }\n\n this.#reflect(element, value);\n }\n\n /** Returns one lease without overwriting a value subsequently authored by a consumer. */\n return(element: T): void {\n const record = this.#records.get(element);\n if (!record) return;\n this.#records.delete(element);\n const stillOwned = element.getAttribute(this.#attribute) === record.written;\n if (stillOwned) this.#reflect(element, record.original);\n }\n\n /** Reflects only a real value transition, avoiding self-triggered mutation work. */\n #reflect(element: T, value: string | null): void {\n if (element.getAttribute(this.#attribute) === value) return;\n if (value === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, value);\n }\n\n /** Returns every outstanding lease using the same ownership check as {@link return}. */\n returnAll(): void {\n for (const element of Array.from(this.#records.keys())) this.return(element);\n }\n}\n","/**\n * Runs a controller's \"return to the initial state\" pass just before Turbo\n * caches the page.\n *\n * **`disconnect()` cannot do this job, for two independent reasons.** Turbo\n * queues the clone from this event rather than taking it here, and the body swap\n * that runs the controller's `disconnect()` is queued separately — so which of\n * the two lands first is not something a controller can rely on, and a rewind\n * written in `disconnect()` may reach only the DOM being thrown away. In the\n * other direction, `disconnect()` also fires on an in-page move (Stimulus tears\n * down and reconnects the same element), where rewinding would wipe a\n * legitimately in-progress interaction — a spinner mid-load would vanish. One\n * timing is unreliable, the other is too eager; `turbo:before-cache` is the only\n * point that is exactly \"the page is about to be frozen\".\n *\n * Scope is the subscription only: registering on `activate()`, unregistering on\n * `deactivate()`, and one shared document listener no matter how many instances\n * are live. *What* to return to its initial state — which `data-state`, which\n * `hidden`, which `aria-busy` — stays in the controller, because no two\n * consumers answer it the same way (the `MicrotaskCoalescer` split).\n *\n * **Rewind state, not appearance.** The pass writes attributes the controller\n * itself owns; the visual result of those attributes is the consumer's CSS, and\n * a library that reached for style or class names would be guessing at markup\n * it does not own.\n *\n * Both entry points are idempotent, so the lifecycle hooks can call them\n * unconditionally: a second `activate()` does not double-subscribe and does not\n * make the callback run twice, and `deactivate()` on an instance that never\n * subscribed is a no-op.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #beforeCache = new BeforeCacheReset(() => this.#rewind());\n *\n * connect() { this.#beforeCache.activate(); }\n * disconnect() { this.#beforeCache.deactivate(); }\n * ```\n */\nexport class BeforeCacheReset {\n /** Every subscribed instance, iterated by the one shared document listener. */\n static readonly #subscribers = new Set<BeforeCacheReset>();\n\n /** The shared listener; installed while at least one instance is subscribed. */\n static readonly #onBeforeCache = (): void => {\n for (const subscriber of BeforeCacheReset.#subscribers) subscriber.#rewind();\n };\n\n readonly #rewind: () => void;\n\n /** @param rewind - the pass that returns this controller's state to its initial form. */\n constructor(rewind: () => void) {\n this.#rewind = rewind;\n }\n\n /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */\n activate(): void {\n const first = BeforeCacheReset.#subscribers.size === 0;\n BeforeCacheReset.#subscribers.add(this);\n if (first) {\n document.addEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n }\n\n /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */\n deactivate(): void {\n BeforeCacheReset.#subscribers.delete(this);\n if (BeforeCacheReset.#subscribers.size > 0) return;\n document.removeEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n}\n","/** Minimal event shape carrying the platform's per-event composition signal. */\nexport interface CompositionSignal {\n readonly isComposing?: boolean;\n}\n\n/** Hooks that keep component-specific work outside {@link CompositionTracker}. */\nexport interface CompositionTrackerOptions {\n /** Runs after lifecycle state is set for a `compositionstart` event. */\n readonly onStart?: (event: Event) => void;\n /** Runs after lifecycle state is cleared for a `compositionend` event. */\n readonly onEnd?: (event: Event) => void;\n}\n\n/**\n * Owns IME composition listeners and transient state for one or more event targets.\n *\n * Some browsers omit `KeyboardEvent.isComposing` on the keydown that confirms a\n * conversion. Tracking `compositionstart` through `compositionend` supplies the\n * missing lifecycle signal without relying on deprecated numeric key codes.\n * Component policy stays with the consumer: filtering, validation, and submission\n * belong in the optional {@link CompositionTrackerOptions.onEnd} callback.\n *\n * @example\n * ```ts\n * #composition = new CompositionTracker({ onEnd: () => this.filter() });\n *\n * connect(): void {\n * this.#composition.observe(this.inputTarget);\n * }\n *\n * disconnect(): void {\n * this.#composition.disconnect();\n * }\n *\n * onKeydown(event: KeyboardEvent): void {\n * if (this.#composition.isComposing(event)) return;\n * }\n * ```\n */\nexport class CompositionTracker {\n readonly #observedTargets = new Set<EventTarget>();\n readonly #activeTargets = new Set<EventTarget>();\n readonly #onStart: ((event: Event) => void) | undefined;\n readonly #onEnd: ((event: Event) => void) | undefined;\n\n constructor(options: CompositionTrackerOptions = {}) {\n this.#onStart = options.onStart;\n this.#onEnd = options.onEnd;\n }\n\n /** Starts lifecycle tracking for `target`; repeated calls are idempotent. */\n observe(target: EventTarget): void {\n if (this.#observedTargets.has(target)) return;\n target.addEventListener(\"compositionstart\", this.#handleStart);\n target.addEventListener(\"compositionend\", this.#handleEnd);\n this.#observedTargets.add(target);\n }\n\n /** Stops tracking one target and clears any active composition it owned. */\n unobserve(target: EventTarget): void {\n if (!this.#observedTargets.delete(target)) return;\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n this.#activeTargets.delete(target);\n }\n\n /** Releases every listener and clears state so reconnect starts cleanly. */\n disconnect(): void {\n for (const target of this.#observedTargets) {\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n }\n this.#observedTargets.clear();\n this.#activeTargets.clear();\n }\n\n /** True when lifecycle tracking or the current event reports composition. */\n isComposing(event?: CompositionSignal): boolean {\n return this.#activeTargets.size > 0 || event?.isComposing === true;\n }\n\n readonly #handleStart = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.add(event.currentTarget);\n this.#onStart?.(event);\n };\n\n readonly #handleEnd = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);\n this.#onEnd?.(event);\n };\n}\n","/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\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 { AttributeLease } from \"../utils/attribute_lease\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { CompositionTracker } from \"../utils/composition_tracker\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\ntype CharacterCounterField = HTMLInputElement | HTMLTextAreaElement;\ntype DisplayMode = \"remaining\" | \"used\" | \"both\";\n\ninterface CharacterCountReading {\n readonly length: number;\n readonly remaining: number | null;\n readonly over: boolean;\n readonly max: number;\n readonly text: string;\n}\n\ntype CharacterCounterDetail = Pick<CharacterCountReading, \"length\" | \"remaining\" | \"over\">;\n\n/**\n * Headless character-counter behavior for a text field (no dedicated APG\n * pattern; follows the WCAG 2.2 \"status messages\" practice, 4.1.3).\n *\n * Markup contract (identifier: `stimeo--character-counter`):\n * <div data-controller=\"stimeo--character-counter\"\n * data-stimeo--character-counter-max-value=\"140\"\n * data-stimeo--character-counter-announce-text-value=\"{remaining} characters remaining\">\n * <textarea data-stimeo--character-counter-target=\"input\"\n * aria-describedby=\"cc\"></textarea>\n * <span id=\"cc\" data-stimeo--character-counter-target=\"output\"></span>\n * </div>\n *\n * Watches the field's UTF-16 code-unit length, writes the remaining/used count\n * into `output`, and toggles the `data-near-limit` / `data-over-limit` state\n * hooks. While over the limit it temporarily leases `aria-invalid=\"true\"` on\n * the field and returns the consumer's authored value on recovery or teardown.\n * The field is the first `input` target, or — when the controller is attached\n * straight onto an `<input>`/`<textarea>` — the controller element itself.\n *\n * `change` and `reconcile` dispatch\n * `{ length: number, remaining: number | null, over: boolean }`.\n *\n * @remarks\n * Behavior only — count text and state update synchronously, with no styling.\n * Confirmed user input dispatches `stimeo--character-counter:change` only when\n * the measured length actually changes. Its detail is `{ length, remaining,\n * over }`; `remaining` is `null` when `max` is disabled. IME intermediate input\n * is ignored, and `compositionend` commits the confirmed value exactly once.\n *\n * Assistive notification is opt-in and i18n-neutral. `announceText` accepts\n * `{count}`, `{length}`, `{remaining}`, `{max}`, and `{over}` placeholders and\n * sends the settled message to the page's shared `stimeo--announcer` after a\n * short debounce. The visible `output` is not itself required to be a live\n * region. Initial reflection and Turbo restoration never dispatch or announce.\n * Runtime target/Value reconciliation dispatches\n * `stimeo--character-counter:reconcile` only when the public derived state\n * changes, and never announces.\n */\nexport class CharacterCounterController extends Controller<HTMLElement> {\n static override targets = [\"input\", \"output\"];\n static override values = {\n max: { type: Number, default: 0 },\n warnAt: { type: Number, default: 0 },\n mode: { type: String, default: \"remaining\" },\n announceText: { type: String, default: \"\" },\n };\n static events = [\"change\", \"reconcile\"] as const;\n\n declare readonly inputTarget: CharacterCounterField;\n declare readonly outputTarget: HTMLElement;\n declare readonly hasInputTarget: boolean;\n declare readonly hasOutputTarget: boolean;\n\n declare maxValue: number;\n declare warnAtValue: number;\n declare modeValue: string;\n declare announceTextValue: string;\n\n /** Delay (ms) before one settled count is sent to the shared announcer. */\n static readonly #announceDelay = 200;\n\n readonly #timeouts = new SafeTimeout();\n readonly #ariaInvalid = new AttributeLease<CharacterCounterField>(\"aria-invalid\");\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n readonly #repaint = new MicrotaskCoalescer(() => this.#reconcile(true));\n readonly #composition = new CompositionTracker({\n onEnd: (event) => this.#commitFrom(event.currentTarget),\n });\n #announceId: number | null = null;\n #boundField: CharacterCounterField | null = null;\n #lastLength: number | null = null;\n #lastDetail: CharacterCounterDetail | null = null;\n #reflectedOver: boolean | null = null;\n\n readonly #onInput = (event: Event): void => {\n const field = this.#boundField;\n if (!field || event.currentTarget !== field || this.#field !== field) return;\n if (this.#composition.isComposing(event as InputEvent)) return;\n this.#commit(field);\n };\n\n /** Reflects the current DOM state and opens the mutation-reconciliation window. */\n override connect(): void {\n this.#repaint.activate();\n this.#beforeCache.activate();\n this.#reconcile(false);\n }\n\n /** Releases listeners, timers, borrowed ARIA, and controller-owned state hooks. */\n override disconnect(): void {\n this.#repaint.cancel();\n this.#beforeCache.deactivate();\n this.#cancelAnnouncement();\n this.#bindField(null);\n this.#composition.disconnect();\n this.#clearStateHooks();\n this.#lastLength = null;\n this.#lastDetail = null;\n }\n\n /** Rebinds and repaints after an input target is added or replaced at runtime. */\n inputTargetConnected(): void {\n this.#repaint.schedule();\n }\n\n /** Releases and repaints after an input target is removed or replaced at runtime. */\n inputTargetDisconnected(): void {\n this.#repaint.schedule();\n }\n\n /** Initializes a display target inserted after the controller connected. */\n outputTargetConnected(): void {\n this.#repaint.schedule();\n }\n\n /** Reconciles the optional display target set after a removal or replacement. */\n outputTargetDisconnected(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code or a Turbo morph changes `max`. */\n maxValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code or a Turbo morph changes `warnAt`. */\n warnAtValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Repaints when application code or a Turbo morph changes `mode`. */\n modeValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Cancels a pending old message when its consumer-authored template changes. */\n announceTextValueChanged(): void {\n this.#repaint.schedule();\n }\n\n /** Rebinds one mutation batch and reports a changed controller-derived state. */\n #reconcile(report: boolean): void {\n const previous = this.#lastDetail;\n // An edit inside the debounce window has already earned an announcement.\n // Reconciliation never originates one, but it must not swallow that one\n // either: the pending message is retargeted at the settled reading, so the\n // user hears the count that ends up displayed rather than nothing. A\n // replaced field is the exception — its pending message describes a field\n // the reader can no longer reach.\n const owedField = this.#announceId === null ? null : this.#boundField;\n this.#cancelAnnouncement();\n this.#bindField(this.#field);\n if (this.#composition.isComposing()) return;\n const field = this.#boundField;\n if (!field) {\n this.#renderEmpty();\n this.#lastLength = null;\n this.#lastDetail = null;\n return;\n }\n const reading = this.#render(field);\n const detail = this.#detail(reading);\n this.#lastLength = reading.length;\n this.#lastDetail = detail;\n if (owedField === field) this.#scheduleAnnouncement(reading);\n if (report && previous && this.#detailsDiffer(previous, detail)) {\n this.dispatch(\"reconcile\", { detail });\n }\n }\n\n /** Commits a composition only when it came from the field still owned here. */\n #commitFrom(target: EventTarget | null): void {\n const field = this.#boundField;\n if (!field || target !== field || this.#field !== field) return;\n this.#commit(field);\n }\n\n /** Reflects one confirmed user input and reports only a real length transition. */\n #commit(field: CharacterCounterField): void {\n const reading = this.#render(field);\n const previousLength = this.#lastLength;\n const previousDetail = this.#lastDetail;\n const detail = this.#detail(reading);\n this.#lastLength = reading.length;\n this.#lastDetail = detail;\n if (previousLength === reading.length) {\n if (previousDetail && this.#detailsDiffer(previousDetail, detail)) {\n this.dispatch(\"reconcile\", { detail });\n }\n return;\n }\n\n this.dispatch(\"change\", { detail });\n this.#scheduleAnnouncement(reading);\n }\n\n /** Selects the public event state from the richer internal reading. */\n #detail(reading: CharacterCountReading): CharacterCounterDetail {\n return {\n length: reading.length,\n remaining: reading.remaining,\n over: reading.over,\n };\n }\n\n /** Compares exactly the state carried by `change` and `reconcile`. */\n #detailsDiffer(left: CharacterCounterDetail, right: CharacterCounterDetail): boolean {\n return (\n left.length !== right.length || left.remaining !== right.remaining || left.over !== right.over\n );\n }\n\n /**\n * Synchronizes visible count, state hooks, and temporary validation ARIA.\n *\n * @stimeoRenderRoot\n */\n #render(field: CharacterCounterField): CharacterCountReading {\n const length = field.value.length;\n const max = this.#normalizeCount(this.maxValue);\n const warnAt = this.#normalizeCount(this.warnAtValue);\n const remaining = max > 0 ? max - length : null;\n const over = remaining !== null && remaining < 0;\n const near = remaining !== null && warnAt > 0 && !over && remaining <= warnAt;\n\n this.#toggle(\"data-over-limit\", over);\n this.#toggle(\"data-near-limit\", near);\n this.#reflectInvalid(field, over);\n\n const text = this.#format(length, remaining, max);\n this.#writeOutput(text);\n return { length, remaining, over, max, text };\n }\n\n /** Clears derived output when the declarative input set has no usable field. */\n #renderEmpty(): void {\n this.#ariaInvalid.returnAll();\n this.#reflectedOver = null;\n this.#clearStateHooks();\n this.#writeOutput(\"\");\n }\n\n /** Replaces the observed field symmetrically, returning state from the old one. */\n #bindField(field: CharacterCounterField | null): void {\n if (field === this.#boundField) return;\n\n const previous = this.#boundField;\n if (previous) {\n previous.removeEventListener(\"input\", this.#onInput);\n this.#composition.unobserve(previous);\n this.#ariaInvalid.return(previous);\n }\n\n this.#boundField = field;\n this.#lastLength = null;\n this.#reflectedOver = null;\n if (!field) return;\n\n field.addEventListener(\"input\", this.#onInput);\n this.#composition.observe(field);\n }\n\n /** Leases `aria-invalid` only on the edge into over-limit, then returns it. */\n #reflectInvalid(field: CharacterCounterField, over: boolean): void {\n if (this.#reflectedOver === over) return;\n this.#reflectedOver = over;\n if (over) this.#ariaInvalid.write(field, \"true\");\n else this.#ariaInvalid.return(field);\n }\n\n /** Builds the visible count for the normalized display mode. */\n #format(length: number, remaining: number | null, max: number): string {\n if (remaining === null) return String(length);\n switch (this.#mode) {\n case \"used\":\n return String(length);\n case \"both\":\n return `${length}/${max}`;\n default:\n return String(remaining);\n }\n }\n\n /** Debounces one i18n-neutral message into the shared polite announcer. */\n #scheduleAnnouncement(reading: CharacterCountReading): void {\n this.#cancelAnnouncement();\n const message = fillTemplate(this.announceTextValue, {\n count: reading.text,\n length: reading.length,\n remaining: reading.remaining ?? \"\",\n max: reading.max,\n over: String(reading.over),\n });\n if (message.trim().length === 0) return;\n\n this.#announceId = this.#timeouts.set(() => {\n announce(message);\n this.#announceId = null;\n }, CharacterCounterController.#announceDelay);\n }\n\n /** Cancels the one outstanding announcement without touching visible output. */\n #cancelAnnouncement(): void {\n if (this.#announceId !== null) this.#timeouts.clear(this.#announceId);\n this.#announceId = null;\n }\n\n /** Writes the optional display only when its text actually changed. */\n #writeOutput(text: string): void {\n if (!this.hasOutputTarget || this.outputTarget.textContent === text) return;\n this.outputTarget.textContent = text;\n }\n\n /** Reflects a presence-style state hook without redundant attribute writes. */\n #toggle(name: string, on: boolean): void {\n if (on) {\n if (this.element.getAttribute(name) !== \"true\") this.element.setAttribute(name, \"true\");\n } else if (this.element.hasAttribute(name)) {\n this.element.removeAttribute(name);\n }\n }\n\n /** Removes both state hooks owned by this controller. */\n #clearStateHooks(): void {\n this.#toggle(\"data-over-limit\", false);\n this.#toggle(\"data-near-limit\", false);\n }\n\n /** Returns borrowed ARIA and transient hooks before Turbo snapshots the page. */\n #rewindForCache(): void {\n this.#cancelAnnouncement();\n this.#ariaInvalid.returnAll();\n this.#reflectedOver = null;\n this.#clearStateHooks();\n }\n\n /** Converts a public count Value into a finite non-negative integer. */\n #normalizeCount(raw: number): number {\n if (!Number.isFinite(raw)) return 0;\n return Math.max(0, Math.trunc(raw));\n }\n\n /** Falls back to `remaining` when an authored display mode is unknown. */\n get #mode(): DisplayMode {\n if (this.modeValue === \"used\" || this.modeValue === \"both\") return this.modeValue;\n return \"remaining\";\n }\n\n /** The watched field: the first target, or a directly controlled form field. */\n get #field(): CharacterCounterField | null {\n if (this.hasInputTarget) return this.inputTarget;\n const element: HTMLElement = this.element;\n if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement)\n return element;\n return null;\n }\n}\n"]}
|
|
@@ -21,6 +21,9 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
21
21
|
* `indeterminate` property (announced as `mixed`) derived from its children, and
|
|
22
22
|
* the cascade from a parent toggle to its children.
|
|
23
23
|
*
|
|
24
|
+
* `change` and `reconcile` dispatch
|
|
25
|
+
* `{ checked: boolean, indeterminate: boolean, state: "all" | "partial" | "none" }`.
|
|
26
|
+
*
|
|
24
27
|
* @remarks
|
|
25
28
|
* Behavior only — the check mark and any "mixed" affordance are the consumer's
|
|
26
29
|
* CSS (keyed off `:checked` / `:indeterminate` / `data-state`). The `parent`
|