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
|
@@ -1,39 +1,181 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
3
|
// src/controllers/switch_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/default_attribute.ts
|
|
6
|
+
function setDefaultAttribute(element, name, value) {
|
|
7
|
+
if (element.hasAttribute(name)) return false;
|
|
8
|
+
element.setAttribute(name, value);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/utils/focus_candidate.ts
|
|
13
|
+
function inheritsFieldsetDisabled(control) {
|
|
14
|
+
let fieldset = control.closest("fieldset[disabled]");
|
|
15
|
+
while (fieldset) {
|
|
16
|
+
const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
|
|
17
|
+
if (!legend?.contains(control)) return true;
|
|
18
|
+
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/utils/interactive_host.ts
|
|
24
|
+
var INTERACTIVE_HOST_SELECTOR = "button, input, select, textarea, label, a[href], area[href], summary, details, audio[controls], video[controls], iframe, object, embed";
|
|
25
|
+
function isInteractiveHost(element) {
|
|
26
|
+
if (element.matches(INTERACTIVE_HOST_SELECTOR)) return true;
|
|
27
|
+
let current = element;
|
|
28
|
+
while (current) {
|
|
29
|
+
const raw = current.getAttribute("contenteditable");
|
|
30
|
+
if (raw !== null) {
|
|
31
|
+
const value = raw.trim().toLowerCase();
|
|
32
|
+
if (value === "false") return false;
|
|
33
|
+
if (value === "" || value === "true" || value === "plaintext-only") return true;
|
|
34
|
+
}
|
|
35
|
+
current = current.parentElement;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/controllers/switch_controller.ts
|
|
41
|
+
var OBSERVED_ATTRIBUTES = [
|
|
42
|
+
"role",
|
|
43
|
+
"aria-checked",
|
|
44
|
+
"tabindex",
|
|
45
|
+
"type",
|
|
46
|
+
"href",
|
|
47
|
+
"contenteditable",
|
|
48
|
+
"controls"
|
|
49
|
+
];
|
|
50
|
+
var OBSERVED_ANCESTOR_ATTRIBUTES = ["contenteditable"];
|
|
4
51
|
var SwitchController = class extends Controller {
|
|
5
52
|
static actions = ["onKeydown", "toggle"];
|
|
6
53
|
static events = ["changed"];
|
|
54
|
+
/** Defaults this instance introduced and may therefore remove safely. */
|
|
55
|
+
#ownedDefaults = /* @__PURE__ */ new Set();
|
|
56
|
+
/** Controller writes that must not be mistaken for authored morph changes. */
|
|
57
|
+
#internalAttributeValues = /* @__PURE__ */ new Map();
|
|
58
|
+
#attributeObserver = new MutationObserver((records) => {
|
|
59
|
+
this.#releaseAuthoredDefaults(records);
|
|
60
|
+
this.#attributeObserver.disconnect();
|
|
61
|
+
this.#reconcileDefaults();
|
|
62
|
+
this.#observeAttributes();
|
|
63
|
+
});
|
|
64
|
+
/** Blocks disabled pointer/native-key activation before consumer click handlers. */
|
|
65
|
+
#onClickCapture = (event) => {
|
|
66
|
+
if (!this.#isSupportedHost || !this.#isActivationDisabled) return;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
event.stopImmediatePropagation();
|
|
69
|
+
};
|
|
7
70
|
/** Ensures the switch exposes a role and is keyboard-reachable. */
|
|
8
71
|
connect() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
72
|
+
this.#reconcileDefaults();
|
|
73
|
+
this.element.addEventListener("click", this.#onClickCapture, true);
|
|
74
|
+
this.#observeAttributes();
|
|
75
|
+
}
|
|
76
|
+
/** Releases the explicit click guard and retained-element attribute observer. */
|
|
77
|
+
disconnect() {
|
|
78
|
+
this.element.removeEventListener("click", this.#onClickCapture, true);
|
|
79
|
+
this.#attributeObserver.disconnect();
|
|
80
|
+
this.#internalAttributeValues.clear();
|
|
18
81
|
}
|
|
19
82
|
/** Toggles the checked state. Bound via `data-action` (click). */
|
|
20
83
|
toggle() {
|
|
84
|
+
if (!this.#isSupportedHost || this.#isActivationDisabled) return;
|
|
21
85
|
this.#checked = !this.#checked;
|
|
22
86
|
}
|
|
23
87
|
/**
|
|
24
|
-
* Activates the switch on Space/Enter for non-native hosts and
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
88
|
+
* Activates the switch on Space/Enter for non-native hosts and suppresses key
|
|
89
|
+
* repeat. Bound via `data-action` (keydown). A native `<button type="button">`
|
|
90
|
+
* owns the initial key-to-click synthesis; repeated keydowns are canceled before
|
|
91
|
+
* the browser can synthesize additional clicks.
|
|
28
92
|
*/
|
|
29
93
|
onKeydown(event) {
|
|
30
94
|
if (event.defaultPrevented) return;
|
|
31
|
-
if (this
|
|
32
|
-
if (event.
|
|
33
|
-
if (
|
|
95
|
+
if (!this.#isSupportedHost) return;
|
|
96
|
+
if (event.key !== " " && event.key !== "Enter") return;
|
|
97
|
+
if (this.#isActivationDisabled) {
|
|
34
98
|
event.preventDefault();
|
|
35
|
-
|
|
99
|
+
event.stopImmediatePropagation();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (this.element instanceof HTMLButtonElement) {
|
|
103
|
+
if (event.repeat) event.preventDefault();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
if (event.repeat) return;
|
|
108
|
+
this.toggle();
|
|
109
|
+
}
|
|
110
|
+
/** Re-adds only missing defaults, preserving every authored attribute value. */
|
|
111
|
+
#reconcileDefaults() {
|
|
112
|
+
if (!this.#isSupportedHost) {
|
|
113
|
+
this.#removeOwnedDefaults();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.#setOwnedDefault("role", "switch");
|
|
117
|
+
this.#setOwnedDefault("aria-checked", "false");
|
|
118
|
+
if (!(this.element instanceof HTMLButtonElement)) {
|
|
119
|
+
this.#setOwnedDefault("tabindex", "0");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Records a newly introduced default without claiming authored markup. */
|
|
123
|
+
#setOwnedDefault(name, value) {
|
|
124
|
+
if (setDefaultAttribute(this.element, name, value)) this.#ownedDefaults.add(name);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gives ownership back when a retained-element morph authors a value. Missing
|
|
128
|
+
* owned attributes stay owned so reconciliation can restore them.
|
|
129
|
+
*/
|
|
130
|
+
#releaseAuthoredDefaults(records) {
|
|
131
|
+
for (const record of records) {
|
|
132
|
+
if (record.target === this.element) {
|
|
133
|
+
const name = record.attributeName;
|
|
134
|
+
if (name && this.#ownedDefaults.has(name)) {
|
|
135
|
+
const value = this.element.getAttribute(name);
|
|
136
|
+
if (value !== null && this.#internalAttributeValues.get(name) !== value) {
|
|
137
|
+
this.#ownedDefaults.delete(name);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this.#internalAttributeValues.clear();
|
|
143
|
+
}
|
|
144
|
+
/** Removes only defaults introduced by this instance when a host becomes invalid. */
|
|
145
|
+
#removeOwnedDefaults() {
|
|
146
|
+
for (const name of this.#ownedDefaults) this.element.removeAttribute(name);
|
|
147
|
+
this.#ownedDefaults.clear();
|
|
148
|
+
this.#internalAttributeValues.clear();
|
|
149
|
+
}
|
|
150
|
+
/** Watches retained host attributes that Turbo can morph without reconnecting. */
|
|
151
|
+
#observeAttributes() {
|
|
152
|
+
this.#attributeObserver.observe(this.element, {
|
|
153
|
+
attributes: true,
|
|
154
|
+
attributeFilter: OBSERVED_ATTRIBUTES
|
|
155
|
+
});
|
|
156
|
+
let ancestor = this.element.parentElement;
|
|
157
|
+
while (ancestor) {
|
|
158
|
+
this.#attributeObserver.observe(ancestor, {
|
|
159
|
+
attributes: true,
|
|
160
|
+
attributeFilter: OBSERVED_ANCESTOR_ATTRIBUTES
|
|
161
|
+
});
|
|
162
|
+
ancestor = ancestor.parentElement;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Whether the host has one activation model that this controller can own. */
|
|
166
|
+
get #isSupportedHost() {
|
|
167
|
+
if (this.element instanceof HTMLButtonElement) return this.element.type === "button";
|
|
168
|
+
return !isInteractiveHost(this.element);
|
|
169
|
+
}
|
|
170
|
+
/** Whether ARIA or native HTML semantics make the supported switch inoperable. */
|
|
171
|
+
get #isActivationDisabled() {
|
|
172
|
+
let current = this.element;
|
|
173
|
+
while (current) {
|
|
174
|
+
if (current.getAttribute("aria-disabled") === "true") return true;
|
|
175
|
+
current = current.parentElement;
|
|
36
176
|
}
|
|
177
|
+
if (!(this.element instanceof HTMLButtonElement)) return false;
|
|
178
|
+
return this.element.disabled || inheritsFieldsetDisabled(this.element);
|
|
37
179
|
}
|
|
38
180
|
/** Whether the switch is currently on. */
|
|
39
181
|
get #checked() {
|
|
@@ -41,7 +183,9 @@ var SwitchController = class extends Controller {
|
|
|
41
183
|
}
|
|
42
184
|
/** Reflects the new state on `aria-checked` and notifies listeners. */
|
|
43
185
|
set #checked(value) {
|
|
44
|
-
|
|
186
|
+
const reflected = value ? "true" : "false";
|
|
187
|
+
this.#internalAttributeValues.set("aria-checked", reflected);
|
|
188
|
+
this.element.setAttribute("aria-checked", reflected);
|
|
45
189
|
this.dispatch("changed", { detail: { checked: value } });
|
|
46
190
|
}
|
|
47
191
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/switch_controller.ts"],"names":[],"mappings":";;;AAyBO,IAAM,gBAAA,GAAN,cAA+B,UAAA,CAAwB;AAAA,EAC5D,OAAO,OAAA,GAAU,CAAC,WAAA,EAAa,QAAQ,CAAA;AAAA,EACvC,OAAO,MAAA,GAAS,CAAC,SAAS,CAAA;AAAA;AAAA,EAGjB,OAAA,GAAgB;AACvB,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,MAAM,CAAA,EAAG;AACtC,MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,MAAA,EAAQ,QAAQ,CAAA;AAAA,IAC5C;AACA,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,cAAc,CAAA,EAAG;AAC9C,MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,cAAA,EAAgB,OAAO,CAAA;AAAA,IACnD;AAIA,IAAA,IAAI,EAAE,KAAK,OAAA,YAAmB,iBAAA,CAAA,IAAsB,CAAC,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,UAAU,CAAA,EAAG;AAC1F,MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,UAAA,EAAY,GAAG,CAAA;AAAA,IAC3C;AAAA,EACF;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,CAAC,IAAA,CAAK,QAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,KAAA,EAA4B;AAGpC,IAAA,IAAI,MAAM,gBAAA,EAAkB;AAC5B,IAAA,IAAI,IAAA,CAAK,mBAAmB,iBAAA,EAAmB;AAC/C,IAAA,IAAI,MAAM,MAAA,EAAQ;AAClB,IAAA,IAAI,KAAA,CAAM,GAAA,KAAQ,GAAA,IAAO,KAAA,CAAM,QAAQ,OAAA,EAAS;AAC9C,MAAA,KAAA,CAAM,cAAA,EAAe;AACrB,MAAA,IAAA,CAAK,MAAA,EAAO;AAAA,IACd;AAAA,EACF;AAAA;AAAA,EAGA,IAAI,QAAA,GAAoB;AACtB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,cAAc,CAAA,KAAM,MAAA;AAAA,EACvD;AAAA;AAAA,EAGA,IAAI,SAAS,KAAA,EAAgB;AAC3B,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,cAAA,EAAgB,KAAA,GAAQ,SAAS,OAAO,CAAA;AAClE,IAAA,IAAA,CAAK,QAAA,CAAS,WAAW,EAAE,MAAA,EAAQ,EAAE,OAAA,EAAS,KAAA,IAAS,CAAA;AAAA,EACzD;AACF","file":"switch_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/**\n * Headless, accessible switch (toggle) behavior.\n *\n * Markup contract (identifier: `stimeo--switch`):\n * <button data-controller=\"stimeo--switch\"\n * data-action=\"stimeo--switch#toggle keydown->stimeo--switch#onKeydown\"\n * role=\"switch\" aria-checked=\"false\">…</button>\n *\n * Implements the WAI-ARIA APG **Switch** pattern. The controller element is the\n * switch itself; its on/off state is reflected solely through `aria-checked`.\n *\n * @remarks\n * Behavior only — the consumer owns all styling (typically keyed off the\n * `[aria-checked=\"true\"]` attribute). On a native `<button>` host, the browser\n * already synthesizes a click for Space/Enter, so {@link onKeydown} deliberately\n * does nothing there (to avoid a double toggle) and only drives non-button hosts\n * such as `<div role=\"switch\" tabindex=\"0\">`.\n *\n * Behavior provided:\n * - Click (or Space/Enter) toggles `aria-checked` between `\"true\"` and `\"false\"`.\n * - A `stimeo--switch:changed` event is dispatched on every toggle so the\n * consumer can react (its `detail.checked` carries the new boolean state).\n */\nexport class SwitchController extends Controller<HTMLElement> {\n static actions = [\"onKeydown\", \"toggle\"] as const;\n static events = [\"changed\"] as const;\n\n /** Ensures the switch exposes a role and is keyboard-reachable. */\n override connect(): void {\n if (!this.element.hasAttribute(\"role\")) {\n this.element.setAttribute(\"role\", \"switch\");\n }\n if (!this.element.hasAttribute(\"aria-checked\")) {\n this.element.setAttribute(\"aria-checked\", \"false\");\n }\n // Native <button> hosts are focusable already; a non-button host (e.g.\n // <div role=\"switch\">) needs an explicit tabindex to be keyboard-reachable,\n // otherwise the keyboard support below would be unreachable.\n if (!(this.element instanceof HTMLButtonElement) && !this.element.hasAttribute(\"tabindex\")) {\n this.element.setAttribute(\"tabindex\", \"0\");\n }\n }\n\n /** Toggles the checked state. Bound via `data-action` (click). */\n toggle(): void {\n this.#checked = !this.#checked;\n }\n\n /**\n * Activates the switch on Space/Enter for non-native hosts and prevents the\n * default Space scroll. Bound via `data-action` (keydown). Native `<button>`\n * hosts are skipped because the browser already turns Space/Enter into a click,\n * which would otherwise toggle the switch twice.\n */\n onKeydown(event: KeyboardEvent): void {\n // A descendant widget that already claimed the key must not ALSO toggle the switch —\n // composition depends on this yield.\n if (event.defaultPrevented) return;\n if (this.element instanceof HTMLButtonElement) return;\n if (event.repeat) return;\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n this.toggle();\n }\n }\n\n /** Whether the switch is currently on. */\n get #checked(): boolean {\n return this.element.getAttribute(\"aria-checked\") === \"true\";\n }\n\n /** Reflects the new state on `aria-checked` and notifies listeners. */\n set #checked(value: boolean) {\n this.element.setAttribute(\"aria-checked\", value ? \"true\" : \"false\");\n this.dispatch(\"changed\", { detail: { checked: value } });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/default_attribute.ts","../../src/utils/focus_candidate.ts","../../src/utils/interactive_host.ts","../../src/controllers/switch_controller.ts"],"names":[],"mappings":";;;;;AAYO,SAAS,mBAAA,CAAoB,OAAA,EAAkB,IAAA,EAAc,KAAA,EAAwB;AAC1F,EAAA,IAAI,OAAA,CAAQ,YAAA,CAAa,IAAI,CAAA,EAAG,OAAO,KAAA;AACvC,EAAA,OAAA,CAAQ,YAAA,CAAa,MAAM,KAAK,CAAA;AAChC,EAAA,OAAO,IAAA;AACT;;;ACLO,SAAS,yBAAyB,OAAA,EAA+B;AACtE,EAAA,IAAI,QAAA,GAA2B,OAAA,CAAQ,OAAA,CAAQ,oBAAoB,CAAA;AACnE,EAAA,OAAO,QAAA,EAAU;AACf,IAAA,MAAM,MAAA,GAAS,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,KAAU,KAAA,CAAM,OAAA,KAAY,QAAQ,CAAA;AACvF,IAAA,IAAI,CAAC,MAAA,EAAQ,QAAA,CAAS,OAAO,GAAG,OAAO,IAAA;AACvC,IAAA,QAAA,GAAW,QAAA,CAAS,aAAA,EAAe,OAAA,CAAQ,oBAAoB,CAAA,IAAK,IAAA;AAAA,EACtE;AACA,EAAA,OAAO,KAAA;AACT;;;ACZO,IAAM,yBAAA,GACX,wIAAA;AASK,SAAS,kBAAkB,OAAA,EAA+B;AAC/D,EAAA,IAAI,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IAAA,IAAI,UAA8B,IAAA,CAAK,OAAA;AACvC,IAAA,OAAO,OAAA,EAAS;AACd,MAAA,IAAI,OAAA,CAAQ,YAAA,CAAa,eAAe,CAAA,KAAM,QAAQ,OAAO,IAAA;AAC7D,MAAA,OAAA,GAAU,OAAA,CAAQ,aAAA;AAAA,IACpB;AACA,IAAA,IAAI,EAAE,IAAA,CAAK,OAAA,YAAmB,iBAAA,CAAA,EAAoB,OAAO,KAAA;AACzD,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,QAAA,IAAY,wBAAA,CAAyB,KAAK,OAAO,CAAA;AAAA,EACvE;AAAA;AAAA,EAGA,IAAI,QAAA,GAAoB;AACtB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,cAAc,CAAA,KAAM,MAAA;AAAA,EACvD;AAAA;AAAA,EAGA,IAAI,SAAS,KAAA,EAAgB;AAC3B,IAAA,MAAM,SAAA,GAAY,QAAQ,MAAA,GAAS,OAAA;AACnC,IAAA,IAAA,CAAK,wBAAA,CAAyB,GAAA,CAAI,cAAA,EAAgB,SAAS,CAAA;AAC3D,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,cAAA,EAAgB,SAAS,CAAA;AACnD,IAAA,IAAA,CAAK,QAAA,CAAS,WAAW,EAAE,MAAA,EAAQ,EAAE,OAAA,EAAS,KAAA,IAAS,CAAA;AAAA,EACzD;AACF","file":"switch_controller.js","sourcesContent":["/**\n * Adds an attribute default without displacing an authored value.\n *\n * Attribute presence — including an authored empty string — is the ownership\n * boundary. The return value lets a caller remember that it supplied the\n * default when that caller must later restore the authored state.\n *\n * @param element - Element that owns the attribute\n * @param name - Attribute name\n * @param value - Value to write only when the attribute is absent\n * @returns Whether this call added the attribute\n */\nexport function setDefaultAttribute(element: Element, name: string, value: string): boolean {\n if (element.hasAttribute(name)) return false;\n element.setAttribute(name, value);\n return true;\n}\n","/**\n * Whether a disabled `<fieldset>` ancestor actually reaches `control`.\n *\n * HTML exempts the contents of a fieldset's **first direct-child `<legend>`**, and\n * the exemption is per fieldset — a control legal in one legend can still be\n * disabled by a second, outer fieldset, so the walk continues upward.\n *\n * Exported for the consumer that needs this rule *without* the rest of\n * {@link canTakeFocus}: `toolbar` bounds its own `hidden` walk at the toolbar\n * root, which is a different rule, so it composes the two itself.\n */\nexport function inheritsFieldsetDisabled(control: HTMLElement): boolean {\n let fieldset: Element | null = control.closest(\"fieldset[disabled]\");\n while (fieldset) {\n const legend = Array.from(fieldset.children).find((child) => child.tagName === \"LEGEND\");\n if (!legend?.contains(control)) return true;\n fieldset = fieldset.parentElement?.closest(\"fieldset[disabled]\") ?? null;\n }\n return false;\n}\n\n/**\n * Whether an element can actually take focus, checked **before** `focus()` runs.\n *\n * A controller that must move focus off a control it is about to disable or hide\n * picks a destination and calls `focus()` on it. If that destination cannot take\n * focus, the call **fails silently**: `hidden` and natively `disabled` elements\n * swallow it, so the caret stays in the subtree that is disappearing and lands on\n * `<body>` a frame later — the exact outcome the rescue exists to prevent, minus\n * any signal that it happened.\n *\n * Testing after the fact is the obvious alternative and is deliberately not the\n * rule. Reading `document.activeElement` back only works in a real browser, and\n * looping over candidates that way performs a real focus move per failure —\n * observable to assistive technology. Checking first costs nothing and catches\n * the cases that actually occur.\n *\n * **`aria-disabled` is not disqualifying.** It is the attribute an author uses\n * for a control that must stay *discoverable*, and the roving contract keeps\n * such items reachable. Only the three conditions that make the platform refuse\n * focus are checked: `hidden` (an ancestor's counts), the native `disabled`\n * property, and `disabled` inherited from an ancestor `fieldset`. CSS-only\n * invisibility is not detectable here and stays the consumer's problem.\n *\n * Reading `:disabled` instead of walking the fieldset chain would be shorter, but\n * that pseudo-class is not evaluated consistently outside real browsers and this\n * has to be right headlessly too. happy-dom in particular focuses a `<button>`\n * inside a disabled fieldset where a real engine refuses, so the inheritance is\n * spelled out rather than delegated.\n *\n * What a consumer does when nothing survives is its own call: some fall back to\n * their landmark, while a widget whose caret already sits somewhere legitimate\n * refuses the move outright rather than relocating it.\n *\n * @example\n * ```ts\n * const target = candidates.find(canTakeFocus);\n * if (target) target.focus();\n * else {\n * this.#tabindex.lend(this.element); // nothing left: fall back to the landmark\n * this.element.focus();\n * }\n * ```\n *\n * @param element - the candidate destination\n */\nexport function canTakeFocus(element: HTMLElement): boolean {\n if (element.closest(\"[hidden]\")) return false;\n if (!(\"disabled\" in element)) return true;\n if ((element as HTMLElement & { disabled: boolean }).disabled) return false;\n return !inheritsFieldsetDisabled(element);\n}\n","/**\n * Native interactive elements whose built-in activation must not be replaced\n * wholesale by a controller. Deliberately excludes `[tabindex]`: a generic\n * element made focusable is the supported host for several headless patterns.\n * Contenteditable is handled by {@link isInteractiveHost} because its state is\n * inherited and its keywords are ASCII-case-insensitive.\n */\nexport const INTERACTIVE_HOST_SELECTOR =\n \"button, input, select, textarea, label, a[href], area[href], summary, details, audio[controls], video[controls], iframe, object, embed\";\n\n/**\n * Whether an element owns native activation or an inherited editing surface.\n *\n * The `contenteditable` missing and invalid states inherit. Walking explicitly\n * also keeps `contenteditable=\"false\"` as a real boundary inside an editable\n * ancestor instead of treating any ancestor attribute as decisive.\n */\nexport function isInteractiveHost(element: HTMLElement): boolean {\n if (element.matches(INTERACTIVE_HOST_SELECTOR)) return true;\n\n let current: HTMLElement | null = element;\n while (current) {\n const raw = current.getAttribute(\"contenteditable\");\n if (raw !== null) {\n const value = raw.trim().toLowerCase();\n if (value === \"false\") return false;\n if (value === \"\" || value === \"true\" || value === \"plaintext-only\") return true;\n }\n current = current.parentElement;\n }\n return false;\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { setDefaultAttribute } from \"../utils/default_attribute\";\nimport { inheritsFieldsetDisabled } from \"../utils/focus_candidate\";\nimport { isInteractiveHost } from \"../utils/interactive_host\";\n\n/** Attributes whose in-place changes can alter the host or its required defaults. */\nconst OBSERVED_ATTRIBUTES = [\n \"role\",\n \"aria-checked\",\n \"tabindex\",\n \"type\",\n \"href\",\n \"contenteditable\",\n \"controls\",\n];\n\n/** Ancestor attributes whose inherited state can change the supported host. */\nconst OBSERVED_ANCESTOR_ATTRIBUTES = [\"contenteditable\"];\n\n/**\n * Headless, accessible switch (toggle) behavior.\n *\n * Markup contract (identifier: `stimeo--switch`):\n * <button type=\"button\" data-controller=\"stimeo--switch\"\n * data-action=\"stimeo--switch#toggle keydown->stimeo--switch#onKeydown\"\n * role=\"switch\" aria-checked=\"false\">…</button>\n *\n * Implements the WAI-ARIA APG **Switch** pattern. The controller element is the\n * switch itself; its on/off state is reflected solely through `aria-checked`.\n *\n * @remarks\n * Behavior only — the consumer owns all styling (typically keyed off the\n * `[aria-checked=\"true\"]` attribute). On a native `<button>` host, the browser\n * already synthesizes a click for Space/Enter, so {@link onKeydown} leaves the\n * initial key to the browser and suppresses repeated keydowns. Non-button hosts\n * such as `<div role=\"switch\" tabindex=\"0\">` are driven directly. Other native\n * interactive hosts stand down because their checked/navigation semantics would\n * conflict with `aria-checked` as this controller's sole source of truth.\n *\n * Behavior provided:\n * - Click (or Space/Enter) toggles `aria-checked` between `\"true\"` and `\"false\"`.\n * - A `stimeo--switch:changed` event is dispatched on every toggle so the\n * consumer can react (its `detail.checked` carries the new boolean state).\n */\nexport class SwitchController extends Controller<HTMLElement> {\n static actions = [\"onKeydown\", \"toggle\"] as const;\n static events = [\"changed\"] as const;\n\n /** Defaults this instance introduced and may therefore remove safely. */\n readonly #ownedDefaults = new Set<string>();\n /** Controller writes that must not be mistaken for authored morph changes. */\n readonly #internalAttributeValues = new Map<string, string>();\n\n readonly #attributeObserver = new MutationObserver((records) => {\n this.#releaseAuthoredDefaults(records);\n // Stop observation while restoring defaults so the writes do not schedule a\n // second, empty callback batch. Re-observe synchronously before returning.\n this.#attributeObserver.disconnect();\n this.#reconcileDefaults();\n this.#observeAttributes();\n });\n\n /** Blocks disabled pointer/native-key activation before consumer click handlers. */\n readonly #onClickCapture = (event: MouseEvent): void => {\n if (!this.#isSupportedHost || !this.#isActivationDisabled) return;\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n\n /** Ensures the switch exposes a role and is keyboard-reachable. */\n override connect(): void {\n this.#reconcileDefaults();\n this.element.addEventListener(\"click\", this.#onClickCapture, true);\n this.#observeAttributes();\n }\n\n /** Releases the explicit click guard and retained-element attribute observer. */\n override disconnect(): void {\n this.element.removeEventListener(\"click\", this.#onClickCapture, true);\n this.#attributeObserver.disconnect();\n this.#internalAttributeValues.clear();\n }\n\n /** Toggles the checked state. Bound via `data-action` (click). */\n toggle(): void {\n if (!this.#isSupportedHost || this.#isActivationDisabled) return;\n this.#checked = !this.#checked;\n }\n\n /**\n * Activates the switch on Space/Enter for non-native hosts and suppresses key\n * repeat. Bound via `data-action` (keydown). A native `<button type=\"button\">`\n * owns the initial key-to-click synthesis; repeated keydowns are canceled before\n * the browser can synthesize additional clicks.\n */\n onKeydown(event: KeyboardEvent): void {\n // A descendant widget that already claimed the key must not ALSO toggle the switch —\n // composition depends on this yield.\n if (event.defaultPrevented) return;\n if (!this.#isSupportedHost) return;\n if (event.key !== \" \" && event.key !== \"Enter\") return;\n if (this.#isActivationDisabled) {\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n if (this.element instanceof HTMLButtonElement) {\n if (event.repeat) event.preventDefault();\n return;\n }\n event.preventDefault();\n if (event.repeat) return;\n this.toggle();\n }\n\n /** Re-adds only missing defaults, preserving every authored attribute value. */\n #reconcileDefaults(): void {\n if (!this.#isSupportedHost) {\n this.#removeOwnedDefaults();\n return;\n }\n this.#setOwnedDefault(\"role\", \"switch\");\n this.#setOwnedDefault(\"aria-checked\", \"false\");\n // Native buttons are focusable already; generic hosts need a Tab stop for\n // the keyboard action above to be reachable.\n if (!(this.element instanceof HTMLButtonElement)) {\n this.#setOwnedDefault(\"tabindex\", \"0\");\n }\n }\n\n /** Records a newly introduced default without claiming authored markup. */\n #setOwnedDefault(name: string, value: string): void {\n if (setDefaultAttribute(this.element, name, value)) this.#ownedDefaults.add(name);\n }\n\n /**\n * Gives ownership back when a retained-element morph authors a value. Missing\n * owned attributes stay owned so reconciliation can restore them.\n */\n #releaseAuthoredDefaults(records: MutationRecord[]): void {\n for (const record of records) {\n if (record.target === this.element) {\n const name = record.attributeName;\n if (name && this.#ownedDefaults.has(name)) {\n const value = this.element.getAttribute(name);\n if (value !== null && this.#internalAttributeValues.get(name) !== value) {\n this.#ownedDefaults.delete(name);\n }\n }\n }\n }\n this.#internalAttributeValues.clear();\n }\n\n /** Removes only defaults introduced by this instance when a host becomes invalid. */\n #removeOwnedDefaults(): void {\n for (const name of this.#ownedDefaults) this.element.removeAttribute(name);\n this.#ownedDefaults.clear();\n this.#internalAttributeValues.clear();\n }\n\n /** Watches retained host attributes that Turbo can morph without reconnecting. */\n #observeAttributes(): void {\n this.#attributeObserver.observe(this.element, {\n attributes: true,\n attributeFilter: OBSERVED_ATTRIBUTES,\n });\n let ancestor = this.element.parentElement;\n while (ancestor) {\n this.#attributeObserver.observe(ancestor, {\n attributes: true,\n attributeFilter: OBSERVED_ANCESTOR_ATTRIBUTES,\n });\n ancestor = ancestor.parentElement;\n }\n }\n\n /** Whether the host has one activation model that this controller can own. */\n get #isSupportedHost(): boolean {\n if (this.element instanceof HTMLButtonElement) return this.element.type === \"button\";\n return !isInteractiveHost(this.element);\n }\n\n /** Whether ARIA or native HTML semantics make the supported switch inoperable. */\n get #isActivationDisabled(): boolean {\n let current: HTMLElement | null = this.element;\n while (current) {\n if (current.getAttribute(\"aria-disabled\") === \"true\") return true;\n current = current.parentElement;\n }\n if (!(this.element instanceof HTMLButtonElement)) return false;\n return this.element.disabled || inheritsFieldsetDisabled(this.element);\n }\n\n /** Whether the switch is currently on. */\n get #checked(): boolean {\n return this.element.getAttribute(\"aria-checked\") === \"true\";\n }\n\n /** Reflects the new state on `aria-checked` and notifies listeners. */\n set #checked(value: boolean) {\n const reflected = value ? \"true\" : \"false\";\n this.#internalAttributeValues.set(\"aria-checked\", reflected);\n this.element.setAttribute(\"aria-checked\", reflected);\n this.dispatch(\"changed\", { detail: { checked: value } });\n }\n}\n"]}
|
|
@@ -52,7 +52,7 @@ var TextareaAutosizeController = class extends Controller {
|
|
|
52
52
|
} else {
|
|
53
53
|
el.removeAttribute("data-at-max-rows");
|
|
54
54
|
}
|
|
55
|
-
el.style.setProperty("--stimeo
|
|
55
|
+
el.style.setProperty("--stimeo--textarea-rows", String(rows));
|
|
56
56
|
if (height !== this.#lastHeight) {
|
|
57
57
|
this.#lastHeight = height;
|
|
58
58
|
this.dispatch("resize", { detail: { height, rows } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/textarea_autosize_controller.ts"],"names":[],"mappings":";;;AAGA,SAAS,GAAG,KAAA,EAAuB;AACjC,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,UAAA,CAAW,KAAK,CAAA;AACjC,EAAA,OAAO,MAAA,CAAO,KAAA,CAAM,CAAC,CAAA,GAAI,CAAA,GAAI,CAAA;AAC/B;AAwBO,IAAM,0BAAA,GAAN,cAAyC,UAAA,CAAgC;AAAA,EAC9E,OAAgB,MAAA,GAAS;AAAA,IACvB,OAAA,EAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,CAAA,EAAE;AAAA,IACpC,OAAA,EAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,CAAA;AAAE,GACtC;AAAA,EACA,OAAO,OAAA,GAAU,CAAC,QAAQ,CAAA;AAAA,EAC1B,OAAO,MAAA,GAAS,CAAC,QAAQ,CAAA;AAAA,EAKzB,WAAA,GAAc,EAAA;AAAA,EAEL,WAAW,MAAY;AAC9B,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd,CAAA;AAAA,EAES,OAAA,GAAgB;AACvB,IAAA,IAAA,CAAK,OAAA,CAAQ,gBAAA,CAAiB,OAAA,EAAS,IAAA,CAAK,QAAQ,CAAA;AACpD,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd;AAAA,EAES,UAAA,GAAmB;AAC1B,IAAA,IAAA,CAAK,O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AQ,IAAA;AAAA,MACV;AAAA,IACF;AAEA,IAAA,MAAM,QAAA,GAAW,SAAA,GAAY,QAAA,GAAW,OAAA,GAAU,CAAA;AAClD,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,aAAA,GAAgB,QAAQ,CAAA;AAClD,IAAA,EAAA,CAAG,KAAA,CAAM,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,EAAA,CAAA;AAC3B,IAAA,EAAA,CAAG,KAAA,CAAM,SAAA,GAAY,KAAA,GAAQ,MAAA,GAAS,QAAA;AAEtC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,EAAA,CAAG,YAAA,CAAa,oBAAoB,MAAM,CAAA;AAAA,IAC5C,CAAA,MAAO;AACL,MAAA,EAAA,CAAG,gBAAgB,kBAAkB,CAAA;AAAA,IACvC;AACA,IAAA,EAAA,CAAG,KAAA,CAAM,WAAA,CAAY,yBAAA,EAA2B,MAAA,CAAO,IAAI,CAAC,CAAA;AAE5D,IAAA,IAAI,MAAA,KAAW,KAAK,WAAA,EAAa;AAC/B,MAAA,IAAA,CAAK,WAAA,GAAc,MAAA;AACnB,MAAA,IAAA,CAAK,QAAA,CAAS,UAAU,EAAE,MAAA,EAAQ,EAAE,MAAA,EAAQ,IAAA,IAAQ,CAAA;AAAA,IACtD;AAAA,EACF;AAAA;AAAA,EAGA,YAAY,KAAA,EAAoC;AAC9C,IAAA,MAAM,EAAA,GAAK,EAAA,CAAG,KAAA,CAAM,UAAU,CAAA;AAC9B,IAAA,IAAI,EAAA,GAAK,GAAG,OAAO,EAAA;AACnB,IAAA,MAAM,QAAA,GAAW,EAAA,CAAG,KAAA,CAAM,QAAQ,CAAA;AAClC,IAAA,OAAO,QAAA,GAAW,CAAA,GAAI,QAAA,GAAW,GAAA,GAAM,EAAA;AAAA,EACzC;AACF","file":"textarea_autosize_controller.js","sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n/** Parses a CSS pixel length, defaulting to 0 for `auto` / empty / `normal`. */\nfunction px(value: string): number {\n const n = Number.parseFloat(value);\n return Number.isNaN(n) ? 0 : n;\n}\n\n/**\n * Headless autosize behavior for a `<textarea>`: grows the element to fit its\n * content (and clamps to `minRows` / `maxRows`, scrolling past the max). No APG\n * pattern; supports WCAG 1.4.4 by following the text as it grows.\n *\n * Markup contract (identifier: `stimeo--textarea-autosize`):\n * <textarea\n * data-controller=\"stimeo--textarea-autosize\"\n * data-stimeo--textarea-autosize-max-rows-value=\"10\"></textarea>\n *\n * On connect and on every input it collapses the element (`height:auto`), reads\n * `scrollHeight`, and sets an explicit pixel height clamped between `minRows` and\n * `maxRows` (in line-height units), toggling internal scrolling and the\n * `data-at-max-rows` hook at the cap. Height-only changes preserve focus and caret.\n *\n * @remarks\n * Behavior only — the height is written to the element's own inline style, never a\n * CSS class. State lives on the element (no module-scope state), so `connect()`\n * re-measures after a Turbo navigation / morph. The input listener is removed on\n * `disconnect()` (Turbo navigation included). Measurement is synchronous, so there\n * is no pending animation frame to tear down.\n */\nexport class TextareaAutosizeController extends Controller<HTMLTextAreaElement> {\n static override values = {\n minRows: { type: Number, default: 1 },\n maxRows: { type: Number, default: 0 },\n };\n static actions = [\"resize\"] as const;\n static events = [\"resize\"] as const;\n\n declare minRowsValue: number;\n declare maxRowsValue: number;\n\n #lastHeight = -1;\n\n readonly #onInput = (): void => {\n this.resize();\n };\n\n override connect(): void {\n this.element.addEventListener(\"input\", this.#onInput);\n this.resize();\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"input\", this.#onInput);\n }\n\n /** Re-measures the content and applies the clamped height. */\n resize(): void {\n const el = this.element;\n const style = window.getComputedStyle(el);\n const lineHeight = this.#lineHeight(style);\n const paddingV = px(style.paddingTop) + px(style.paddingBottom);\n const borderV = px(style.borderTopWidth) + px(style.borderBottomWidth);\n const borderBox = style.boxSizing === \"border-box\";\n\n // Collapse first so scrollHeight reflects the content, not the prior height.\n el.style.height = \"auto\";\n const contentHeight = Math.max(0, el.scrollHeight - paddingV);\n const rows = Math.max(1, Math.round(contentHeight / lineHeight));\n\n let targetContent = Math.max(contentHeight, this.minRowsValue * lineHeight);\n let atMax = false;\n if (this.maxRowsValue > 0) {\n const maxContent = this.maxRowsValue * lineHeight;\n if (targetContent > maxContent) {\n targetContent = maxContent;\n atMax = true;\n }\n }\n\n const boxExtra = borderBox ? paddingV + borderV : 0;\n const height = Math.round(targetContent + boxExtra);\n el.style.height = `${height}px`;\n el.style.overflowY = atMax ? \"auto\" : \"hidden\";\n\n if (atMax) {\n el.setAttribute(\"data-at-max-rows\", \"true\");\n } else {\n el.removeAttribute(\"data-at-max-rows\");\n }\n el.style.setProperty(\"--stimeo--textarea-rows\", String(rows));\n\n if (height !== this.#lastHeight) {\n this.#lastHeight = height;\n this.dispatch(\"resize\", { detail: { height, rows } });\n }\n }\n\n /** Resolved line height, falling back to ~1.2× font-size when `normal`. */\n #lineHeight(style: CSSStyleDeclaration): number {\n const lh = px(style.lineHeight);\n if (lh > 0) return lh;\n const fontSize = px(style.fontSize);\n return fontSize > 0 ? fontSize * 1.2 : 16;\n }\n}\n"]}
|
|
@@ -27,6 +27,9 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
27
27
|
* (and, when `wrap` is set, carrying minutes→hours and seconds→minutes). Typing
|
|
28
28
|
* digits enters a value directly and advances after two digits. AM/PM is modeled
|
|
29
29
|
* as a `meridiem` spinbutton that toggles; the hidden field is always 24-hour.
|
|
30
|
+
* A committed field-value change dispatches a bubbling native `change` from
|
|
31
|
+
* that field, while `stimeo--time-picker:change` reports the composed widget
|
|
32
|
+
* state even when no field target is present.
|
|
30
33
|
*/
|
|
31
34
|
declare class TimePickerController extends Controller<HTMLElement> {
|
|
32
35
|
#private;
|
|
@@ -121,7 +121,6 @@ var TimePickerController = class extends Controller {
|
|
|
121
121
|
}
|
|
122
122
|
/** Propagates a wrap carry from `kind` into the next larger segment. */
|
|
123
123
|
#carry(kind, amount) {
|
|
124
|
-
if (amount === 0) return;
|
|
125
124
|
if (kind === "second") this.#step("minute", amount);
|
|
126
125
|
else if (kind === "minute") this.#step("hour", amount);
|
|
127
126
|
}
|
|
@@ -183,15 +182,19 @@ var TimePickerController = class extends Controller {
|
|
|
183
182
|
segment.setAttribute("aria-valuemax", String(max));
|
|
184
183
|
segment.textContent = text;
|
|
185
184
|
}
|
|
186
|
-
/** Composes `HH:MM[:SS]`
|
|
185
|
+
/** Composes `HH:MM[:SS]` and notifies both native-form and widget consumers. */
|
|
187
186
|
#syncField(notify) {
|
|
188
187
|
const h24 = this.#hours24();
|
|
189
188
|
const parts = [pad(h24), pad(this.#state.minute)];
|
|
190
189
|
if (this.secondsValue) parts.push(pad(this.#state.second));
|
|
191
190
|
const value = parts.join(":");
|
|
192
|
-
|
|
191
|
+
const fieldChanged = this.hasFieldTarget && this.fieldTarget.value !== value;
|
|
192
|
+
if (fieldChanged) {
|
|
193
193
|
this.fieldTarget.value = value;
|
|
194
194
|
}
|
|
195
|
+
if (notify && fieldChanged) {
|
|
196
|
+
this.fieldTarget.dispatchEvent(new Event("change", { bubbles: true }));
|
|
197
|
+
}
|
|
195
198
|
if (notify && value !== this.#lastValue) this.dispatch("change", { detail: { value } });
|
|
196
199
|
this.#lastValue = value;
|
|
197
200
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/controllers/time_picker_controller.ts"],"names":["text"],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC6CO,SAAS,eAAA,CAAgB,KAAa,OAAA,EAA0B;AACrE,EAAA,IAAI,GAAA,KAAQ,YAAA,IAAgB,GAAA,KAAQ,WAAA,EAAa,OAAO,GAAA;AACxD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAO,CAAA,EAAG,OAAO,GAAA;AAC5B,EAAA,OAA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A,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAGA,SAAS,IAAI,KAAA,EAAuB;AAClC,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAA;AACtC","file":"time_picker_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord, logicalArrowKey } from \"../utils/arrow_step\";\n\n/** A time segment kind, as declared by `data-segment` on each spinbutton. */\ntype SegmentKind = \"hour\" | \"minute\" | \"second\" | \"meridiem\";\n\n/** Meridiem encoding: 0 = AM, 1 = PM. */\nconst AM = 0;\nconst PM = 1;\n\n/**\n * Headless, accessible **time picker** behavior. Each segment (hour, minute,\n * optional second, optional AM/PM) is an APG **Spinbutton**; the controller\n * composes them into an `HH:MM[:SS]` value mirrored to a hidden field.\n *\n * Markup contract (identifier: `stimeo--time-picker`):\n * <div data-controller=\"stimeo--time-picker\"\n * data-stimeo--time-picker-hour-cycle-value=\"24\"\n * role=\"group\" aria-label=\"Time\">\n * <span role=\"spinbutton\" aria-label=\"Hours\" tabindex=\"0\"\n * aria-valuenow=\"9\" aria-valuemin=\"0\" aria-valuemax=\"23\" aria-valuetext=\"09\"\n * data-segment=\"hour\" data-stimeo--time-picker-target=\"segment\"\n * data-action=\"keydown->stimeo--time-picker#onKeydown\">09</span>\n * <span aria-hidden=\"true\">:</span>\n * <span role=\"spinbutton\" aria-label=\"Minutes\" tabindex=\"0\"\n * data-segment=\"minute\" data-stimeo--time-picker-target=\"segment\"\n * data-action=\"keydown->stimeo--time-picker#onKeydown\">30</span>\n * <input type=\"hidden\" data-stimeo--time-picker-target=\"field\" />\n * </div>\n *\n * @remarks\n * Behavior only — no styling, no locale formatting. Every segment is its own Tab\n * stop (multi-tabstop, *not* roving); `ArrowLeft`/`ArrowRight` are an auxiliary\n * move between segments. `ArrowUp`/`ArrowDown` step the focused segment, wrapping\n * (and, when `wrap` is set, carrying minutes→hours and seconds→minutes). Typing\n * digits enters a value directly and advances after two digits. AM/PM is modeled\n * as a `meridiem` spinbutton that toggles; the hidden field is always 24-hour.\n */\nexport class TimePickerController extends Controller<HTMLElement> {\n static override targets = [\"segment\", \"field\"];\n static override values = {\n hourCycle: { type: Number, default: 24 },\n step: { type: Number, default: 1 },\n seconds: { type: Boolean, default: false },\n wrap: { type: Boolean, default: true },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly segmentTargets: HTMLElement[];\n declare readonly fieldTarget: HTMLInputElement;\n declare readonly hasFieldTarget: boolean;\n declare hourCycleValue: number;\n declare stepValue: number;\n declare secondsValue: boolean;\n declare wrapValue: boolean;\n\n /** Current numeric value per segment kind (hours are the *displayed* hours). */\n #state: Record<SegmentKind, number> = { hour: 0, minute: 0, second: 0, meridiem: AM };\n /** Direct-entry digit buffer and the segment it belongs to. */\n #typeBuffer = \"\";\n #typeSegment: SegmentKind | null = null;\n /** Last composed field value, to suppress duplicate `change` dispatches. */\n #lastValue = \"\";\n\n /** Seeds each segment from its initial `aria-valuenow` and syncs the field. */\n override connect(): void {\n for (const segment of this.segmentTargets) {\n const kind = this.#kindOf(segment);\n if (!kind) continue;\n const now = Number(segment.getAttribute(\"aria-valuenow\"));\n const { min, max } = this.#bounds(kind);\n // Clamp the seeded value so malformed markup (out-of-range aria-valuenow)\n // never propagates into the rendered state or the composed field.\n this.#state[kind] = Number.isFinite(now) ? Math.min(max, Math.max(min, now)) : min;\n }\n for (const segment of this.segmentTargets) this.#renderSegment(segment);\n this.#syncField(false);\n }\n\n /** Handles stepping, inter-segment focus moves, jumps, and direct entry. */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n const segment = (event.target as HTMLElement | null)?.closest<HTMLElement>(\n \"[data-stimeo--time-picker-target='segment']\",\n );\n const kind = segment ? this.#kindOf(segment) : null;\n if (!segment || !kind) return;\n // Logical, not physical, for the horizontal pair: the segments form an\n // ordered row laid out inline, so a right-to-left writing direction mirrors\n // them. `ArrowUp` / `ArrowDown` change the *value* and pass through\n // untouched — `logicalArrowKey` only ever rewrites the horizontal pair.\n\n switch (logicalArrowKey(event.key, this.element)) {\n case \"ArrowUp\":\n event.preventDefault();\n this.#step(kind, this.#delta(kind));\n break;\n case \"ArrowDown\":\n event.preventDefault();\n this.#step(kind, -this.#delta(kind));\n break;\n case \"ArrowLeft\":\n event.preventDefault();\n this.#focusSibling(segment, -1);\n break;\n case \"ArrowRight\":\n event.preventDefault();\n this.#focusSibling(segment, 1);\n break;\n case \"Home\":\n event.preventDefault();\n this.#set(kind, this.#bounds(kind).min);\n break;\n case \"End\":\n event.preventDefault();\n this.#set(kind, this.#bounds(kind).max);\n break;\n default:\n if (/^[0-9]$/.test(event.key)) {\n event.preventDefault();\n this.#typeDigit(segment, kind, event.key);\n }\n return;\n }\n // Any non-digit action ends the current direct-entry sequence.\n this.#typeBuffer = \"\";\n this.#typeSegment = null;\n }\n\n /** The per-step delta: minutes step by `step`, others by 1, meridiem toggles. */\n #delta(kind: SegmentKind): number {\n return kind === \"minute\" ? this.stepValue : 1;\n }\n\n /** Steps a segment, wrapping at its bounds and carrying over when enabled. */\n #step(kind: SegmentKind, delta: number): void {\n if (kind === \"meridiem\") {\n this.#set(\"meridiem\", this.#state.meridiem === AM ? PM : AM);\n return;\n }\n const { min, max } = this.#bounds(kind);\n const span = max - min + 1;\n const raw = this.#state[kind] + delta;\n\n if (raw > max || raw < min) {\n if (!this.wrapValue) {\n this.#set(kind, Math.min(max, Math.max(min, raw)));\n return;\n }\n // Wrap within the segment, carrying the overflow into the larger unit.\n const wrapped = ((((raw - min) % span) + span) % span) + min;\n const carry = Math.floor((raw - min) / span);\n this.#set(kind, wrapped);\n this.#carry(kind, carry);\n return;\n }\n this.#set(kind, raw);\n }\n\n /** Propagates a wrap carry from `kind` into the next larger segment. */\n #carry(kind: SegmentKind, amount: number): void {\n if (amount === 0) return;\n if (kind === \"second\") this.#step(\"minute\", amount);\n else if (kind === \"minute\") this.#step(\"hour\", amount);\n // Hours wrap on their own (no day rollover); meridiem has no carry.\n }\n\n /**\n * Sets a segment's value (clamped to its `[min, max]` bounds), re-renders it,\n * and resyncs the composed field. Clamping here guards the direct-entry path:\n * typing `0` into a 12-hour hour (min 1) must not commit an out-of-range\n * `aria-valuenow=\"0\"`. The stepping path already passes in-bounds values, so\n * the clamp is a no-op there.\n */\n #set(kind: SegmentKind, value: number): void {\n const { min, max } = this.#bounds(kind);\n this.#state[kind] = Math.min(max, Math.max(min, value));\n const segment = this.segmentTargets.find((s) => this.#kindOf(s) === kind);\n if (segment) this.#renderSegment(segment);\n this.#syncField(true);\n }\n\n /** Accumulates a typed digit, committing and advancing after two digits. */\n #typeDigit(segment: HTMLElement, kind: SegmentKind, digit: string): void {\n if (kind === \"meridiem\") return;\n if (this.#typeSegment !== kind) this.#typeBuffer = \"\";\n this.#typeSegment = kind;\n\n const { max } = this.#bounds(kind);\n const candidate = Number(`${this.#typeBuffer}${digit}`);\n if (candidate <= max) this.#typeBuffer = `${this.#typeBuffer}${digit}`;\n else this.#typeBuffer = digit; // restart from this digit when it overflows\n\n this.#set(kind, Number(this.#typeBuffer));\n\n // Two digits (or a value that can't grow further) completes the segment.\n if (this.#typeBuffer.length >= 2 || Number(this.#typeBuffer) * 10 > max) {\n this.#typeBuffer = \"\";\n this.#typeSegment = null;\n this.#focusSibling(segment, 1);\n }\n }\n\n /** Moves focus to the previous/next segment, if one exists. */\n #focusSibling(segment: HTMLElement, direction: 1 | -1): void {\n const index = this.segmentTargets.indexOf(segment);\n const next = this.segmentTargets[index + direction];\n next?.focus();\n }\n\n /** Reflects a segment's current value onto its ARIA/text representation. */\n #renderSegment(segment: HTMLElement): void {\n const kind = this.#kindOf(segment);\n if (!kind) return;\n const value = this.#state[kind];\n\n if (kind === \"meridiem\") {\n const text = value === PM ? \"PM\" : \"AM\";\n segment.setAttribute(\"aria-valuenow\", String(value));\n segment.setAttribute(\"aria-valuetext\", text);\n segment.setAttribute(\"aria-valuemin\", String(AM));\n segment.setAttribute(\"aria-valuemax\", String(PM));\n segment.textContent = text;\n return;\n }\n\n const { min, max } = this.#bounds(kind);\n const text = String(value).padStart(2, \"0\");\n segment.setAttribute(\"aria-valuenow\", String(value));\n segment.setAttribute(\"aria-valuetext\", text);\n segment.setAttribute(\"aria-valuemin\", String(min));\n segment.setAttribute(\"aria-valuemax\", String(max));\n segment.textContent = text;\n }\n\n /** Composes `HH:MM[:SS]` (24-hour) into the hidden field; dispatches `change`. */\n #syncField(notify: boolean): void {\n const h24 = this.#hours24();\n const parts = [pad(h24), pad(this.#state.minute)];\n if (this.secondsValue) parts.push(pad(this.#state.second));\n const value = parts.join(\":\");\n\n if (this.hasFieldTarget && this.fieldTarget.value !== value) {\n this.fieldTarget.value = value;\n }\n // Dispatch only when the composed value actually changed, so a no-op step\n // (e.g. Home at the minimum) does not emit a redundant event.\n if (notify && value !== this.#lastValue) this.dispatch(\"change\", { detail: { value } });\n this.#lastValue = value;\n }\n\n /** Converts the displayed hour (+ meridiem in 12-hour mode) to 24-hour. */\n #hours24(): number {\n if (this.hourCycleValue !== 12) return this.#state.hour;\n const base = this.#state.hour % 12; // 12 → 0\n return base + (this.#state.meridiem === PM ? 12 : 0);\n }\n\n /** The inclusive `[min, max]` bounds for a segment kind. */\n #bounds(kind: SegmentKind): { min: number; max: number } {\n switch (kind) {\n case \"hour\":\n return this.hourCycleValue === 12 ? { min: 1, max: 12 } : { min: 0, max: 23 };\n case \"minute\":\n case \"second\":\n return { min: 0, max: 59 };\n case \"meridiem\":\n return { min: AM, max: PM };\n }\n }\n\n /** Reads a segment's declared kind, or null when absent/invalid. */\n #kindOf(segment: HTMLElement): SegmentKind | null {\n const kind = segment.getAttribute(\"data-segment\");\n if (kind === \"hour\" || kind === \"minute\" || kind === \"second\" || kind === \"meridiem\") {\n return kind;\n }\n return null;\n }\n}\n\n/** Zero-pads a number to two digits. */\nfunction pad(value: number): string {\n return String(value).padStart(2, \"0\");\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/logical_scroll.ts","../../src/utils/arrow_step.ts","../../src/controllers/time_picker_controller.ts"],"names":["text"],"mappings":";;;;;AAiBO,SAAS,MAAM,OAAA,EAA2B;AAC/C,EAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,OAAO,CAAA,CAAE,SAAA,KAAc,KAAA;AACxD;;;AC6CO,SAAS,eAAA,CAAgB,KAAa,OAAA,EAA0B;AACrE,EAAA,IAAI,GAAA,KAAQ,YAAA,IAAgB,GAAA,KAAQ,WAAA,EAAa,OAAO,GAAA;AACxD,EAAA,IA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A,QAAQ,OAAA,EAA0C;AAChD,IAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,YAAA,CAAa,cAAc,CAAA;AAChD,IAAA,IAAI,SAAS,MAAA,IAAU,IAAA,KAAS,YAAY,IAAA,KAAS,QAAA,IAAY,SAAS,UAAA,EAAY;AACpF,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAGA,SAAS,IAAI,KAAA,EAAuB;AAClC,EAAA,OAAO,MAAA,CAAO,KAAK,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAA;AACtC","file":"time_picker_controller.js","sourcesContent":["/** Normalized scroll position and maximum distance on one logical axis. */\nexport interface LogicalScrollMetrics {\n position: number;\n max: number;\n}\n\n/**\n * Whether horizontal scrolling on `element` follows right-to-left inline flow.\n *\n * Resolved from the **computed** `direction`, so the authoring contract is the\n * usual `dir=\"rtl\"` (or a stylesheet) on the element or any ancestor.\n *\n * Scope: horizontal writing modes. A vertical writing mode (`writing-mode:\n * vertical-rl`) also inverts the horizontal axis, which this check does not\n * model — vertical writing modes are out of scope for the scroll utilities\n * (their consumers describe axes as horizontal/vertical, not inline/block).\n */\nexport function isRtl(element: Element): boolean {\n return window.getComputedStyle(element).direction === \"rtl\";\n}\n\n/**\n * Returns scroll distance from the logical start edge.\n *\n * CSSOM View exposes standards-mode RTL horizontal offsets as `0` at the inline\n * start (right) and increasingly negative values toward the inline end (left).\n * The normalized position is always clamped to `[0, max]`, which also absorbs\n * Safari's elastic overscroll values.\n */\nexport function logicalScrollMetrics(\n element: HTMLElement,\n horizontal: boolean,\n): LogicalScrollMetrics {\n const max = Math.max(\n 0,\n horizontal\n ? element.scrollWidth - element.clientWidth\n : element.scrollHeight - element.clientHeight,\n );\n const raw = horizontal ? element.scrollLeft : element.scrollTop;\n const position = horizontal && isRtl(element) ? -raw : raw;\n return { position: Math.min(max, Math.max(0, position)), max };\n}\n\n/**\n * Converts a logical start/end delta to the physical value accepted by\n * `Element.scrollBy`.\n */\nexport function physicalScrollDelta(\n element: HTMLElement,\n horizontal: boolean,\n logicalDelta: number,\n): number {\n return horizontal && isRtl(element) ? -logicalDelta : logicalDelta;\n}\n","import { isRtl } from \"./logical_scroll\";\n\n/**\n * Turns an arrow key into a **logical** step: `+1` for \"next\", `-1` for\n * \"previous\", `0` when the key names neither.\n *\n * APG defines the horizontal pair as *next / previous* and says a vertical\n * arrangement swaps in Down/Up for the same meaning — so the pair is one axis's\n * spelling of an order, and the order reverses with the writing direction. Only\n * the horizontal pair reverses. Down/Up name an axis the writing direction does\n * not mirror, and returning them unchanged is the point: many controllers fold\n * both pairs into one branch, where swapping the branches under RTL would flip\n * the vertical axis too — a bug that reads as \"the arrows work\" until someone\n * presses Down.\n *\n * **Direction is read from the element the caller passes, which should be the\n * container that lays the items out** — not the focused child. A child may carry\n * its own `dir` (an LTR input inside an RTL form is ordinary authoring), and\n * probing per handler makes two handlers disagree at the boundary between them.\n *\n * This decides direction only. Whether the axis is even active (an\n * `orientation=\"horizontal\"` widget ignoring Down/Up), how far the step lands,\n * and what wrapping does all stay with the caller.\n *\n * **It encodes the list-order convention: `ArrowDown` is *next*.** Widgets that\n * pair the arrows by *value* instead — `ArrowUp` meaning \"more\", as a rating or a\n * slider does — must not use this, or their vertical axis inverts. Reverse the\n * horizontal pair on its own there.\n *\n * @example\n * ```ts\n * const step = logicalArrowStep(event.key, this.element);\n * if (step === 0) return;\n * this.#roving.setActive(rovingMove(current, length, step, \"wrap\"), { focus: true });\n * ```\n */\nexport function logicalArrowStep(key: string, element: Element): 1 | -1 | 0 {\n if (key === \"ArrowDown\") return 1;\n if (key === \"ArrowUp\") return -1;\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return 0;\n const forward = isRtl(element) ? \"ArrowLeft\" : \"ArrowRight\";\n return key === forward ? 1 : -1;\n}\n\n/**\n * Rewrites `key` so an existing LTR-shaped branch keeps working under RTL:\n * `ArrowRight` and `ArrowLeft` trade places, everything else passes through.\n *\n * The alternative — negating a delta — silently breaks handlers whose two\n * horizontal branches are **not mirror images**. A grid that clamps one edge but\n * not the other, or a segmented field guarding `index > 0` on one side and\n * `index < length - 1` on the other, ends up applying the wrong guard to the\n * wrong direction. Swapping the key leaves each branch, guards and all, exactly\n * where its author put it.\n *\n * Same rule as {@link logicalArrowStep} about which element to read: pass the\n * container that lays the items out, not the focused child.\n *\n * @example\n * ```ts\n * switch (logicalArrowKey(event.key, this.element)) {\n * case \"ArrowLeft\": // \"previous\" — whatever direction that is on screen\n * ```\n */\nexport function logicalArrowKey(key: string, element: Element): string {\n if (key !== \"ArrowRight\" && key !== \"ArrowLeft\") return key;\n if (!isRtl(element)) return key;\n return key === \"ArrowRight\" ? \"ArrowLeft\" : \"ArrowRight\";\n}\n\n/** Modifiers a widget may claim on an arrow key, named for the `allow` list. */\nexport type ArrowModifier = \"alt\" | \"ctrl\" | \"meta\" | \"shift\";\n\n/**\n * True when an arrow key arrived carrying a modifier the widget must leave to\n * the browser: return without calling `preventDefault()` and without moving any\n * state.\n *\n * A bare arrow belongs to the widget; a chorded one usually does not.\n * `Alt`/`Meta` plus a horizontal arrow is history back/forward on every desktop\n * browser, and a widget that swallows it makes the shortcut work or not\n * depending on where focus happens to sit — a coin-flip the user cannot see.\n *\n * `allow` is for the combinations APG assigns to a pattern **and the widget\n * actually implements** — today only Combobox's optional `Alt+Down`/`Alt+Up`.\n * Listing one the widget does not implement defeats the point: the chord then\n * runs the plain-arrow branch, which is exactly what this guard exists to stop.\n * Non-arrow keys return `false`, so chorded letters and\n * `Control+Home`/`Control+End` are untouched.\n *\n * @example\n * ```ts\n * if (isReservedArrowChord(event)) return;\n * ```\n */\nexport function isReservedArrowChord(\n event: KeyboardEvent,\n allow: readonly ArrowModifier[] = [],\n): boolean {\n if (!event.key.startsWith(\"Arrow\")) return false;\n return (\n (event.altKey && !allow.includes(\"alt\")) ||\n (event.ctrlKey && !allow.includes(\"ctrl\")) ||\n (event.metaKey && !allow.includes(\"meta\")) ||\n (event.shiftKey && !allow.includes(\"shift\"))\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { isReservedArrowChord, logicalArrowKey } from \"../utils/arrow_step\";\n\n/** A time segment kind, as declared by `data-segment` on each spinbutton. */\ntype SegmentKind = \"hour\" | \"minute\" | \"second\" | \"meridiem\";\n\n/** Meridiem encoding: 0 = AM, 1 = PM. */\nconst AM = 0;\nconst PM = 1;\n\n/**\n * Headless, accessible **time picker** behavior. Each segment (hour, minute,\n * optional second, optional AM/PM) is an APG **Spinbutton**; the controller\n * composes them into an `HH:MM[:SS]` value mirrored to a hidden field.\n *\n * Markup contract (identifier: `stimeo--time-picker`):\n * <div data-controller=\"stimeo--time-picker\"\n * data-stimeo--time-picker-hour-cycle-value=\"24\"\n * role=\"group\" aria-label=\"Time\">\n * <span role=\"spinbutton\" aria-label=\"Hours\" tabindex=\"0\"\n * aria-valuenow=\"9\" aria-valuemin=\"0\" aria-valuemax=\"23\" aria-valuetext=\"09\"\n * data-segment=\"hour\" data-stimeo--time-picker-target=\"segment\"\n * data-action=\"keydown->stimeo--time-picker#onKeydown\">09</span>\n * <span aria-hidden=\"true\">:</span>\n * <span role=\"spinbutton\" aria-label=\"Minutes\" tabindex=\"0\"\n * data-segment=\"minute\" data-stimeo--time-picker-target=\"segment\"\n * data-action=\"keydown->stimeo--time-picker#onKeydown\">30</span>\n * <input type=\"hidden\" data-stimeo--time-picker-target=\"field\" />\n * </div>\n *\n * @remarks\n * Behavior only — no styling, no locale formatting. Every segment is its own Tab\n * stop (multi-tabstop, *not* roving); `ArrowLeft`/`ArrowRight` are an auxiliary\n * move between segments. `ArrowUp`/`ArrowDown` step the focused segment, wrapping\n * (and, when `wrap` is set, carrying minutes→hours and seconds→minutes). Typing\n * digits enters a value directly and advances after two digits. AM/PM is modeled\n * as a `meridiem` spinbutton that toggles; the hidden field is always 24-hour.\n * A committed field-value change dispatches a bubbling native `change` from\n * that field, while `stimeo--time-picker:change` reports the composed widget\n * state even when no field target is present.\n */\nexport class TimePickerController extends Controller<HTMLElement> {\n static override targets = [\"segment\", \"field\"];\n static override values = {\n hourCycle: { type: Number, default: 24 },\n step: { type: Number, default: 1 },\n seconds: { type: Boolean, default: false },\n wrap: { type: Boolean, default: true },\n };\n static actions = [\"onKeydown\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly segmentTargets: HTMLElement[];\n declare readonly fieldTarget: HTMLInputElement;\n declare readonly hasFieldTarget: boolean;\n declare hourCycleValue: number;\n declare stepValue: number;\n declare secondsValue: boolean;\n declare wrapValue: boolean;\n\n /** Current numeric value per segment kind (hours are the *displayed* hours). */\n #state: Record<SegmentKind, number> = { hour: 0, minute: 0, second: 0, meridiem: AM };\n /** Direct-entry digit buffer and the segment it belongs to. */\n #typeBuffer = \"\";\n #typeSegment: SegmentKind | null = null;\n /** Last composed field value, to suppress duplicate `change` dispatches. */\n #lastValue = \"\";\n\n /** Seeds each segment from its initial `aria-valuenow` and syncs the field. */\n override connect(): void {\n for (const segment of this.segmentTargets) {\n const kind = this.#kindOf(segment);\n if (!kind) continue;\n const now = Number(segment.getAttribute(\"aria-valuenow\"));\n const { min, max } = this.#bounds(kind);\n // Clamp the seeded value so malformed markup (out-of-range aria-valuenow)\n // never propagates into the rendered state or the composed field.\n this.#state[kind] = Number.isFinite(now) ? Math.min(max, Math.max(min, now)) : min;\n }\n for (const segment of this.segmentTargets) this.#renderSegment(segment);\n this.#syncField(false);\n }\n\n /** Handles stepping, inter-segment focus moves, jumps, and direct entry. */\n onKeydown(event: KeyboardEvent): void {\n if (isReservedArrowChord(event)) return;\n const segment = (event.target as HTMLElement | null)?.closest<HTMLElement>(\n \"[data-stimeo--time-picker-target='segment']\",\n );\n const kind = segment ? this.#kindOf(segment) : null;\n if (!segment || !kind) return;\n // Logical, not physical, for the horizontal pair: the segments form an\n // ordered row laid out inline, so a right-to-left writing direction mirrors\n // them. `ArrowUp` / `ArrowDown` change the *value* and pass through\n // untouched — `logicalArrowKey` only ever rewrites the horizontal pair.\n\n switch (logicalArrowKey(event.key, this.element)) {\n case \"ArrowUp\":\n event.preventDefault();\n this.#step(kind, this.#delta(kind));\n break;\n case \"ArrowDown\":\n event.preventDefault();\n this.#step(kind, -this.#delta(kind));\n break;\n case \"ArrowLeft\":\n event.preventDefault();\n this.#focusSibling(segment, -1);\n break;\n case \"ArrowRight\":\n event.preventDefault();\n this.#focusSibling(segment, 1);\n break;\n case \"Home\":\n event.preventDefault();\n this.#set(kind, this.#bounds(kind).min);\n break;\n case \"End\":\n event.preventDefault();\n this.#set(kind, this.#bounds(kind).max);\n break;\n default:\n if (/^[0-9]$/.test(event.key)) {\n event.preventDefault();\n this.#typeDigit(segment, kind, event.key);\n }\n return;\n }\n // Any non-digit action ends the current direct-entry sequence.\n this.#typeBuffer = \"\";\n this.#typeSegment = null;\n }\n\n /** The per-step delta: minutes step by `step`, others by 1, meridiem toggles. */\n #delta(kind: SegmentKind): number {\n return kind === \"minute\" ? this.stepValue : 1;\n }\n\n /** Steps a segment, wrapping at its bounds and carrying over when enabled. */\n #step(kind: SegmentKind, delta: number): void {\n if (kind === \"meridiem\") {\n this.#set(\"meridiem\", this.#state.meridiem === AM ? PM : AM);\n return;\n }\n const { min, max } = this.#bounds(kind);\n const span = max - min + 1;\n const raw = this.#state[kind] + delta;\n\n if (raw > max || raw < min) {\n if (!this.wrapValue) {\n this.#set(kind, Math.min(max, Math.max(min, raw)));\n return;\n }\n // Wrap within the segment, carrying the overflow into the larger unit.\n const wrapped = ((((raw - min) % span) + span) % span) + min;\n const carry = Math.floor((raw - min) / span);\n this.#set(kind, wrapped);\n this.#carry(kind, carry);\n return;\n }\n this.#set(kind, raw);\n }\n\n /** Propagates a wrap carry from `kind` into the next larger segment. */\n #carry(kind: SegmentKind, amount: number): void {\n if (kind === \"second\") this.#step(\"minute\", amount);\n else if (kind === \"minute\") this.#step(\"hour\", amount);\n // Hours wrap on their own (no day rollover); meridiem has no carry.\n }\n\n /**\n * Sets a segment's value (clamped to its `[min, max]` bounds), re-renders it,\n * and resyncs the composed field. Clamping here guards the direct-entry path:\n * typing `0` into a 12-hour hour (min 1) must not commit an out-of-range\n * `aria-valuenow=\"0\"`. The stepping path already passes in-bounds values, so\n * the clamp is a no-op there.\n */\n #set(kind: SegmentKind, value: number): void {\n const { min, max } = this.#bounds(kind);\n this.#state[kind] = Math.min(max, Math.max(min, value));\n const segment = this.segmentTargets.find((s) => this.#kindOf(s) === kind);\n if (segment) this.#renderSegment(segment);\n this.#syncField(true);\n }\n\n /** Accumulates a typed digit, committing and advancing after two digits. */\n #typeDigit(segment: HTMLElement, kind: SegmentKind, digit: string): void {\n if (kind === \"meridiem\") return;\n if (this.#typeSegment !== kind) this.#typeBuffer = \"\";\n this.#typeSegment = kind;\n\n const { max } = this.#bounds(kind);\n const candidate = Number(`${this.#typeBuffer}${digit}`);\n if (candidate <= max) this.#typeBuffer = `${this.#typeBuffer}${digit}`;\n else this.#typeBuffer = digit; // restart from this digit when it overflows\n\n this.#set(kind, Number(this.#typeBuffer));\n\n // Two digits (or a value that can't grow further) completes the segment.\n if (this.#typeBuffer.length >= 2 || Number(this.#typeBuffer) * 10 > max) {\n this.#typeBuffer = \"\";\n this.#typeSegment = null;\n this.#focusSibling(segment, 1);\n }\n }\n\n /** Moves focus to the previous/next segment, if one exists. */\n #focusSibling(segment: HTMLElement, direction: 1 | -1): void {\n const index = this.segmentTargets.indexOf(segment);\n const next = this.segmentTargets[index + direction];\n next?.focus();\n }\n\n /** Reflects a segment's current value onto its ARIA/text representation. */\n #renderSegment(segment: HTMLElement): void {\n const kind = this.#kindOf(segment);\n if (!kind) return;\n const value = this.#state[kind];\n\n if (kind === \"meridiem\") {\n const text = value === PM ? \"PM\" : \"AM\";\n segment.setAttribute(\"aria-valuenow\", String(value));\n segment.setAttribute(\"aria-valuetext\", text);\n segment.setAttribute(\"aria-valuemin\", String(AM));\n segment.setAttribute(\"aria-valuemax\", String(PM));\n segment.textContent = text;\n return;\n }\n\n const { min, max } = this.#bounds(kind);\n const text = String(value).padStart(2, \"0\");\n segment.setAttribute(\"aria-valuenow\", String(value));\n segment.setAttribute(\"aria-valuetext\", text);\n segment.setAttribute(\"aria-valuemin\", String(min));\n segment.setAttribute(\"aria-valuemax\", String(max));\n segment.textContent = text;\n }\n\n /** Composes `HH:MM[:SS]` and notifies both native-form and widget consumers. */\n #syncField(notify: boolean): void {\n const h24 = this.#hours24();\n const parts = [pad(h24), pad(this.#state.minute)];\n if (this.secondsValue) parts.push(pad(this.#state.second));\n const value = parts.join(\":\");\n\n const fieldChanged = this.hasFieldTarget && this.fieldTarget.value !== value;\n if (fieldChanged) {\n this.fieldTarget.value = value;\n }\n if (notify && fieldChanged) {\n // Match a native form control: only a real committed value change bubbles\n // to form validation, dirty tracking, and auto-submit consumers.\n this.fieldTarget.dispatchEvent(new Event(\"change\", { bubbles: true }));\n }\n // The widget event describes its composed state and remains available even\n // when no form field target exists.\n if (notify && value !== this.#lastValue) this.dispatch(\"change\", { detail: { value } });\n this.#lastValue = value;\n }\n\n /** Converts the displayed hour (+ meridiem in 12-hour mode) to 24-hour. */\n #hours24(): number {\n if (this.hourCycleValue !== 12) return this.#state.hour;\n const base = this.#state.hour % 12; // 12 → 0\n return base + (this.#state.meridiem === PM ? 12 : 0);\n }\n\n /** The inclusive `[min, max]` bounds for a segment kind. */\n #bounds(kind: SegmentKind): { min: number; max: number } {\n switch (kind) {\n case \"hour\":\n return this.hourCycleValue === 12 ? { min: 1, max: 12 } : { min: 0, max: 23 };\n case \"minute\":\n case \"second\":\n return { min: 0, max: 59 };\n case \"meridiem\":\n return { min: AM, max: PM };\n }\n }\n\n /** Reads a segment's declared kind, or null when absent/invalid. */\n #kindOf(segment: HTMLElement): SegmentKind | null {\n const kind = segment.getAttribute(\"data-segment\");\n if (kind === \"hour\" || kind === \"minute\" || kind === \"second\" || kind === \"meridiem\") {\n return kind;\n }\n return null;\n }\n}\n\n/** Zero-pads a number to two digits. */\nfunction pad(value: number): string {\n return String(value).padStart(2, \"0\");\n}\n"]}
|
|
@@ -56,8 +56,7 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
56
56
|
* `Enter` / click / `select` redefined first.
|
|
57
57
|
* - An out-of-contract host makes `onKeydown` and `onClick` stand down
|
|
58
58
|
* **entirely** — no movement, no selection, no `select` — rather than respond
|
|
59
|
-
* partially. `stimeo check`
|
|
60
|
-
* attributes are required and cannot forbid an element shape.
|
|
59
|
+
* partially. `stimeo check` reports the unsupported host before runtime.
|
|
61
60
|
*
|
|
62
61
|
* Consumer contract — controls nested inside a row:
|
|
63
62
|
* - Keep them out of the Tab sequence (`tabindex="-1"`); the tree is one Tab
|
|
@@ -30,6 +30,23 @@ function canTakeFocus(element) {
|
|
|
30
30
|
return !inheritsFieldsetDisabled(element);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// src/utils/interactive_host.ts
|
|
34
|
+
var INTERACTIVE_HOST_SELECTOR = "button, input, select, textarea, label, a[href], area[href], summary, details, audio[controls], video[controls], iframe, object, embed";
|
|
35
|
+
function isInteractiveHost(element) {
|
|
36
|
+
if (element.matches(INTERACTIVE_HOST_SELECTOR)) return true;
|
|
37
|
+
let current = element;
|
|
38
|
+
while (current) {
|
|
39
|
+
const raw = current.getAttribute("contenteditable");
|
|
40
|
+
if (raw !== null) {
|
|
41
|
+
const value = raw.trim().toLowerCase();
|
|
42
|
+
if (value === "false") return false;
|
|
43
|
+
if (value === "" || value === "true" || value === "plaintext-only") return true;
|
|
44
|
+
}
|
|
45
|
+
current = current.parentElement;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
33
50
|
// src/utils/roving_tabindex.ts
|
|
34
51
|
var RovingTabindex = class {
|
|
35
52
|
/** Returns the current ordered item elements; called on every operation. */
|
|
@@ -175,7 +192,7 @@ function findTypeaheadMatch(items, from, query, label = (item) => typeaheadLabel
|
|
|
175
192
|
}
|
|
176
193
|
|
|
177
194
|
// src/controllers/tree_view_controller.ts
|
|
178
|
-
var NESTED_INTERACTIVE =
|
|
195
|
+
var NESTED_INTERACTIVE = INTERACTIVE_HOST_SELECTOR;
|
|
179
196
|
var TreeViewController = class extends Controller {
|
|
180
197
|
static targets = ["item", "group"];
|
|
181
198
|
static actions = ["onClick", "onKeydown", "toggle"];
|
|
@@ -436,6 +453,7 @@ var TreeViewController = class extends Controller {
|
|
|
436
453
|
if (target.closest('[role="treeitem"]') !== item) return null;
|
|
437
454
|
const control = target.closest(NESTED_INTERACTIVE);
|
|
438
455
|
if (control && item.contains(control)) return null;
|
|
456
|
+
if (isInteractiveHost(target)) return null;
|
|
439
457
|
return item;
|
|
440
458
|
}
|
|
441
459
|
/**
|