stimeo-ui 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +160 -0
- data/dist/controllers/accordion_controller.js +10 -0
- data/dist/controllers/alert_dialog_controller.js +32 -5
- data/dist/controllers/announcer_controller.js +255 -20
- data/dist/controllers/breadcrumb_controller.js +225 -13
- data/dist/controllers/calendar_controller.js +89 -22
- data/dist/controllers/carousel_controller.js +47 -6
- data/dist/controllers/collapsible_controller.js +2 -2
- data/dist/controllers/color_picker_controller.js +92 -7
- data/dist/controllers/combobox_controller.js +162 -23
- data/dist/controllers/command_palette_controller.js +226 -22
- data/dist/controllers/confirm_controller.js +32 -5
- data/dist/controllers/context_menu_controller.js +32 -10
- data/dist/controllers/countdown_controller.js +112 -12
- data/dist/controllers/data_grid_controller.js +82 -4
- data/dist/controllers/date_range_picker_controller.js +77 -3
- data/dist/controllers/dialog_controller.js +32 -5
- data/dist/controllers/drawer_controller.js +32 -5
- data/dist/controllers/editable_controller.js +1 -0
- data/dist/controllers/empty_state_controller.js +24 -10
- data/dist/controllers/focus_controller.js +32 -5
- data/dist/controllers/form_validation_controller.js +1 -1
- data/dist/controllers/frame_loading_controller.js +177 -15
- data/dist/controllers/intersection_controller.js +36 -11
- data/dist/controllers/lazy_frame_controller.js +31 -10
- data/dist/controllers/listbox_controller.js +257 -53
- data/dist/controllers/local_time_controller.js +102 -8
- data/dist/controllers/menu_controller.js +104 -17
- data/dist/controllers/menubar_controller.js +415 -63
- data/dist/controllers/meter_controller.js +145 -26
- data/dist/controllers/multi_select_controller.js +312 -29
- data/dist/controllers/navigation_menu_controller.js +154 -27
- data/dist/controllers/network_status_controller.js +28 -8
- data/dist/controllers/number_input_controller.js +7 -0
- data/dist/controllers/otp_controller.js +18 -1
- data/dist/controllers/overflow_indicator_controller.js +81 -13
- data/dist/controllers/overflow_menu_controller.js +408 -57
- data/dist/controllers/pagination_controller.js +163 -32
- data/dist/controllers/persist_controller.js +6 -6
- data/dist/controllers/pointer_drag_controller.js +9 -1
- data/dist/controllers/popover_controller.js +2 -2
- data/dist/controllers/progress_controller.js +116 -9
- data/dist/controllers/radio_group_controller.js +22 -3
- data/dist/controllers/range_slider_controller.js +100 -9
- data/dist/controllers/rating_controller.js +69 -2
- data/dist/controllers/read_more_controller.js +63 -19
- data/dist/controllers/relative_time_controller.js +133 -12
- data/dist/controllers/resizable_controller.js +65 -1
- data/dist/controllers/roving_controller.js +17 -2
- data/dist/controllers/scroll_area_controller.js +86 -12
- data/dist/controllers/scroll_restore_controller.js +1 -1
- data/dist/controllers/scroll_visibility_controller.js +33 -3
- data/dist/controllers/scrollspy_controller.js +346 -73
- data/dist/controllers/separator_controller.js +9 -0
- data/dist/controllers/sidebar_controller.js +37 -8
- data/dist/controllers/skeleton_controller.js +73 -20
- data/dist/controllers/slider_controller.js +49 -8
- data/dist/controllers/sortable_controller.js +34 -3
- data/dist/controllers/spinner_controller.js +228 -27
- data/dist/controllers/step_indicator_controller.js +82 -5
- data/dist/controllers/stick_to_bottom_controller.js +61 -10
- data/dist/controllers/sticky_observer_controller.js +32 -11
- data/dist/controllers/switch_controller.js +1 -0
- data/dist/controllers/tabs_controller.js +26 -3
- data/dist/controllers/tags_input_controller.js +22 -2
- data/dist/controllers/theme_controller.js +22 -3
- data/dist/controllers/time_picker_controller.js +20 -1
- data/dist/controllers/toast_controller.js +4 -5
- data/dist/controllers/toggle_group_controller.js +23 -2
- data/dist/controllers/toolbar_controller.js +230 -31
- data/dist/controllers/tree_view_controller.js +467 -51
- data/dist/index.js +4507 -907
- data/lib/stimeo/ui/version.rb +2 -3
- metadata +2 -2
|
@@ -1,7 +1,53 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
3
|
// src/controllers/pagination_controller.ts
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
// src/utils/focus_candidate.ts
|
|
6
|
+
function inheritsFieldsetDisabled(control) {
|
|
7
|
+
let fieldset = control.closest("fieldset[disabled]");
|
|
8
|
+
while (fieldset) {
|
|
9
|
+
const legend = Array.from(fieldset.children).find((child) => child.tagName === "LEGEND");
|
|
10
|
+
if (!legend?.contains(control)) return true;
|
|
11
|
+
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
function canTakeFocus(element) {
|
|
16
|
+
if (element.closest("[hidden]")) return false;
|
|
17
|
+
if (!("disabled" in element)) return true;
|
|
18
|
+
if (element.disabled) return false;
|
|
19
|
+
return !inheritsFieldsetDisabled(element);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/utils/tabindex_loan.ts
|
|
23
|
+
var TabindexLoan = class {
|
|
24
|
+
#value;
|
|
25
|
+
#lent = /* @__PURE__ */ new Set();
|
|
26
|
+
/**
|
|
27
|
+
* @param value - the `tabindex` to lend. `"-1"` (the default) is
|
|
28
|
+
* programmatically focusable but not a Tab stop; `"0"` is a real Tab stop,
|
|
29
|
+
* which a scroll region with no focusable content of its own needs.
|
|
30
|
+
*/
|
|
31
|
+
constructor(value = "-1") {
|
|
32
|
+
this.#value = value;
|
|
33
|
+
}
|
|
34
|
+
/** Lends `element` the value; no-ops when it already carries a `tabindex`. */
|
|
35
|
+
lend(element) {
|
|
36
|
+
if (element.hasAttribute("tabindex")) return;
|
|
37
|
+
element.setAttribute("tabindex", this.#value);
|
|
38
|
+
this.#lent.add(element);
|
|
39
|
+
}
|
|
40
|
+
/** Takes back every loan whose value is still the one that was lent. */
|
|
41
|
+
returnAll() {
|
|
42
|
+
for (const element of this.#lent) {
|
|
43
|
+
if (element.getAttribute("tabindex") === this.#value) element.removeAttribute("tabindex");
|
|
44
|
+
}
|
|
45
|
+
this.#lent.clear();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/controllers/pagination_controller.ts
|
|
50
|
+
var PaginationController = class _PaginationController extends Controller {
|
|
5
51
|
static targets = ["page", "prev", "next"];
|
|
6
52
|
static values = {
|
|
7
53
|
page: { type: Number, default: 1 },
|
|
@@ -9,79 +55,164 @@ var PaginationController = class extends Controller {
|
|
|
9
55
|
};
|
|
10
56
|
static actions = ["next", "prev", "select"];
|
|
11
57
|
static events = ["change"];
|
|
58
|
+
/** Marks a `disabled` this controller applied at a boundary (ownership flag). */
|
|
59
|
+
static #BOUNDARY_ATTR = "data-stimeo--pagination-boundary-disabled";
|
|
60
|
+
#isConnected = false;
|
|
61
|
+
/** The `tabindex` this instance lends the root for the focus fallback. */
|
|
62
|
+
#tabindex = new TabindexLoan();
|
|
12
63
|
/** Normalizes out-of-range initial values and renders the initial state. */
|
|
13
64
|
connect() {
|
|
14
|
-
this
|
|
15
|
-
this
|
|
65
|
+
this.#isConnected = true;
|
|
66
|
+
this.#normalizeAndRender();
|
|
67
|
+
}
|
|
68
|
+
/** Reverts the one attribute the controller adds outside its state hooks. */
|
|
69
|
+
disconnect() {
|
|
70
|
+
this.#isConnected = false;
|
|
71
|
+
this.#tabindex.returnAll();
|
|
72
|
+
}
|
|
73
|
+
/** Re-renders when application code (or a Turbo morph) changes `page` at runtime. */
|
|
74
|
+
pageValueChanged() {
|
|
75
|
+
if (!this.#isConnected) return;
|
|
76
|
+
this.#normalizeAndRender();
|
|
77
|
+
}
|
|
78
|
+
/** Re-renders when application code (or a Turbo morph) changes `total` at runtime. */
|
|
79
|
+
totalValueChanged() {
|
|
80
|
+
if (!this.#isConnected) return;
|
|
81
|
+
this.#normalizeAndRender();
|
|
82
|
+
}
|
|
83
|
+
/** Syncs a page button appended/replaced at runtime (the consumer owns the list). */
|
|
84
|
+
pageTargetConnected() {
|
|
85
|
+
if (!this.#isConnected) return;
|
|
86
|
+
this.#render();
|
|
87
|
+
}
|
|
88
|
+
/** Syncs a `prev` button appended/replaced at runtime. */
|
|
89
|
+
prevTargetConnected() {
|
|
90
|
+
if (!this.#isConnected) return;
|
|
91
|
+
this.#render();
|
|
92
|
+
}
|
|
93
|
+
/** Syncs a `next` button appended/replaced at runtime. */
|
|
94
|
+
nextTargetConnected() {
|
|
95
|
+
if (!this.#isConnected) return;
|
|
16
96
|
this.#render();
|
|
17
97
|
}
|
|
18
98
|
/** Makes the clicked page button (its `data-page`) current. */
|
|
19
99
|
select(event) {
|
|
20
100
|
const button = event.currentTarget;
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
101
|
+
const raw = button.dataset.page;
|
|
102
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
103
|
+
const page = Number(raw);
|
|
104
|
+
if (!Number.isInteger(page)) return;
|
|
23
105
|
this.#goto(page);
|
|
24
106
|
}
|
|
25
107
|
/** Steps to the previous page. */
|
|
26
108
|
prev() {
|
|
27
|
-
this.#goto(this
|
|
109
|
+
this.#goto(this.#page - 1);
|
|
28
110
|
}
|
|
29
111
|
/** Steps to the next page. */
|
|
30
112
|
next() {
|
|
31
|
-
this.#goto(this
|
|
113
|
+
this.#goto(this.#page + 1);
|
|
32
114
|
}
|
|
33
115
|
/** Moves to `page` (clamped to `[1, total]`), re-renders, and dispatches `change`. */
|
|
34
116
|
#goto(page) {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
117
|
+
if (!Number.isFinite(page)) return;
|
|
118
|
+
const previous = this.#page;
|
|
119
|
+
const target = this.#clamp(page);
|
|
120
|
+
if (target === previous) return;
|
|
39
121
|
this.pageValue = target;
|
|
40
122
|
this.#render();
|
|
41
123
|
this.dispatch("change", {
|
|
42
|
-
detail: { page: target, total: this
|
|
124
|
+
detail: { page: target, total: this.#total, previous }
|
|
43
125
|
});
|
|
44
126
|
}
|
|
127
|
+
/** Writes the normalized Values back (only when they differ) and renders. */
|
|
128
|
+
#normalizeAndRender() {
|
|
129
|
+
const total = this.#total;
|
|
130
|
+
if (!Object.is(total, this.totalValue)) this.totalValue = total;
|
|
131
|
+
const page = this.#page;
|
|
132
|
+
if (!Object.is(page, this.pageValue)) this.pageValue = page;
|
|
133
|
+
this.#render();
|
|
134
|
+
}
|
|
45
135
|
/** Syncs `aria-current` on the page buttons and the prev/next `disabled` state. */
|
|
46
136
|
#render() {
|
|
137
|
+
const page = this.#page;
|
|
47
138
|
for (const button of this.pageTargets) {
|
|
48
|
-
if (Number(button.dataset.page) ===
|
|
139
|
+
if (Number(button.dataset.page) === page) {
|
|
49
140
|
button.setAttribute("aria-current", "page");
|
|
50
141
|
} else {
|
|
51
142
|
button.removeAttribute("aria-current");
|
|
52
143
|
}
|
|
53
144
|
}
|
|
54
|
-
this
|
|
55
|
-
this
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
145
|
+
const prev = this.hasPrevTarget ? this.prevTarget : null;
|
|
146
|
+
const next = this.hasNextTarget ? this.nextTarget : null;
|
|
147
|
+
const atStart = page <= 1;
|
|
148
|
+
const atEnd = page >= this.#total;
|
|
149
|
+
const prevStaysDisabled = this.#disabledAfter(prev, atStart);
|
|
150
|
+
const nextStaysDisabled = this.#disabledAfter(next, atEnd);
|
|
151
|
+
this.#release(prev, atStart);
|
|
152
|
+
this.#release(next, atEnd);
|
|
153
|
+
this.#disable(prev, atStart, nextStaysDisabled ? null : next);
|
|
154
|
+
this.#disable(next, atEnd, prevStaysDisabled ? null : prev);
|
|
155
|
+
}
|
|
156
|
+
/** Whether a boundary button will still be `disabled` once this render applies. */
|
|
157
|
+
#disabledAfter(button, atBoundary) {
|
|
158
|
+
if (!button) return true;
|
|
159
|
+
if (atBoundary) return true;
|
|
160
|
+
return button.disabled && !this.#owns(button);
|
|
161
|
+
}
|
|
162
|
+
/** Releases the boundary `disabled` this controller owns, once away from it. */
|
|
163
|
+
#release(button, atBoundary) {
|
|
164
|
+
if (!button || atBoundary || !this.#owns(button)) return;
|
|
165
|
+
button.disabled = false;
|
|
166
|
+
button.removeAttribute(_PaginationController.#BOUNDARY_ATTR);
|
|
59
167
|
}
|
|
60
168
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
169
|
+
* Disables a boundary button, first moving focus off it when it is the active
|
|
170
|
+
* element so disabling never strands focus.
|
|
63
171
|
*/
|
|
64
|
-
#
|
|
65
|
-
if (!button) return;
|
|
66
|
-
if (disabled && button
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
button.
|
|
172
|
+
#disable(button, atBoundary, opposite) {
|
|
173
|
+
if (!button || !atBoundary) return;
|
|
174
|
+
if (button.disabled && !this.#owns(button)) return;
|
|
175
|
+
if (button === document.activeElement) this.#moveFocusAwayFrom(opposite);
|
|
176
|
+
button.disabled = true;
|
|
177
|
+
button.setAttribute(_PaginationController.#BOUNDARY_ATTR, "");
|
|
70
178
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Moves focus to `opposite` (already resolved to `null` when it will stay
|
|
181
|
+
* disabled), else to the current page button, else to the landmark itself.
|
|
182
|
+
*/
|
|
183
|
+
#moveFocusAwayFrom(opposite) {
|
|
184
|
+
const page = this.#page;
|
|
74
185
|
const currentPage = this.pageTargets.find(
|
|
75
|
-
(candidate) => Number(candidate.dataset.page) ===
|
|
186
|
+
(candidate) => Number(candidate.dataset.page) === page
|
|
187
|
+
);
|
|
188
|
+
const destination = [opposite, currentPage].find(
|
|
189
|
+
(candidate) => candidate != null && canTakeFocus(candidate)
|
|
76
190
|
);
|
|
77
|
-
const destination = opposite && !opposite.disabled ? opposite : currentPage;
|
|
78
191
|
if (destination) {
|
|
79
192
|
destination.focus();
|
|
80
193
|
return;
|
|
81
194
|
}
|
|
82
|
-
|
|
195
|
+
this.#tabindex.lend(this.element);
|
|
83
196
|
this.element.focus();
|
|
84
197
|
}
|
|
198
|
+
/** Total pages, normalized to a finite integer >= 1. */
|
|
199
|
+
get #total() {
|
|
200
|
+
const total = this.totalValue;
|
|
201
|
+
return Number.isFinite(total) ? Math.max(1, Math.trunc(total)) : 1;
|
|
202
|
+
}
|
|
203
|
+
/** The current page, normalized into `[1, total]`. */
|
|
204
|
+
get #page() {
|
|
205
|
+
return this.#clamp(this.pageValue);
|
|
206
|
+
}
|
|
207
|
+
/** Constrains `page` to `[1, total]`; a non-finite page falls back to page 1. */
|
|
208
|
+
#clamp(page) {
|
|
209
|
+
if (!Number.isFinite(page)) return 1;
|
|
210
|
+
return Math.min(this.#total, Math.max(1, Math.trunc(page)));
|
|
211
|
+
}
|
|
212
|
+
/** Whether the button's current `disabled` was applied by boundary control. */
|
|
213
|
+
#owns(button) {
|
|
214
|
+
return button.hasAttribute(_PaginationController.#BOUNDARY_ATTR);
|
|
215
|
+
}
|
|
85
216
|
};
|
|
86
217
|
|
|
87
218
|
export { PaginationController };
|
|
@@ -182,12 +182,12 @@ var PersistController = class extends Controller {
|
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
184
184
|
* Persistable fields paired with a stable storage key. Uniquely-named fields key
|
|
185
|
-
* by their name
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
185
|
+
* by their name. Repeated same-name fields (e.g. a `tags[]` checkbox group or
|
|
186
|
+
* array text inputs) are disambiguated by DOM-order occurrence — the first keeps
|
|
187
|
+
* its plain `name`, later ones get a NUL-separated index suffix — so each is
|
|
188
|
+
* stored and restored individually instead of the last one clobbering the rest.
|
|
189
|
+
* Radios are the exception: a group intentionally shares one key (one value per
|
|
190
|
+
* name).
|
|
191
191
|
*/
|
|
192
192
|
#fieldEntries() {
|
|
193
193
|
const entries = [];
|
|
@@ -2,6 +2,12 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/pointer_drag_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/arrow_step.ts
|
|
6
|
+
function isReservedArrowChord(event, allow = []) {
|
|
7
|
+
if (!event.key.startsWith("Arrow")) return false;
|
|
8
|
+
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
// src/utils/detach_gate.ts
|
|
6
12
|
var DetachGate = class _DetachGate {
|
|
7
13
|
/** Set while a probe is queued, waiting for a reconnect to cancel it. */
|
|
@@ -186,8 +192,10 @@ var PointerDragController = class _PointerDragController extends Controller {
|
|
|
186
192
|
if (this.disabledValue) return;
|
|
187
193
|
const handle = this.#handleFor(event.target);
|
|
188
194
|
if (!handle) return;
|
|
195
|
+
if (event.defaultPrevented) return;
|
|
196
|
+
if (isReservedArrowChord(event)) return;
|
|
189
197
|
if (event.key === "Escape") {
|
|
190
|
-
if (event.
|
|
198
|
+
if (event.isComposing) return;
|
|
191
199
|
if (this.#pointer?.started) {
|
|
192
200
|
const { pointerType } = this.#pointer;
|
|
193
201
|
this.#teardownSessions();
|
|
@@ -133,7 +133,7 @@ var PopoverController = class _PopoverController extends Controller {
|
|
|
133
133
|
/** Starts closed and registers the standing dismissal listeners. */
|
|
134
134
|
connect() {
|
|
135
135
|
this.close();
|
|
136
|
-
document.addEventListener("click", this.#onOutsideClick);
|
|
136
|
+
document.addEventListener("click", this.#onOutsideClick, true);
|
|
137
137
|
this.element.addEventListener("focusout", this.#onFocusOut);
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
@@ -144,7 +144,7 @@ var PopoverController = class _PopoverController extends Controller {
|
|
|
144
144
|
*/
|
|
145
145
|
disconnect() {
|
|
146
146
|
this.#escapeLayer.deactivate();
|
|
147
|
-
document.removeEventListener("click", this.#onOutsideClick);
|
|
147
|
+
document.removeEventListener("click", this.#onOutsideClick, true);
|
|
148
148
|
this.element.removeEventListener("focusout", this.#onFocusOut);
|
|
149
149
|
this.#stopScrollDismiss?.();
|
|
150
150
|
this.#stopScrollDismiss = null;
|
|
@@ -2,6 +2,23 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/progress_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
|
+
|
|
5
22
|
// src/utils/coerce.ts
|
|
6
23
|
function toFiniteNumber(raw) {
|
|
7
24
|
if (raw === null || raw === void 0 || raw === "") return null;
|
|
@@ -9,7 +26,57 @@ function toFiniteNumber(raw) {
|
|
|
9
26
|
return Number.isFinite(value) ? value : null;
|
|
10
27
|
}
|
|
11
28
|
|
|
29
|
+
// src/utils/microtask_coalescer.ts
|
|
30
|
+
var MicrotaskCoalescer = class {
|
|
31
|
+
#run;
|
|
32
|
+
#queued = false;
|
|
33
|
+
#active = false;
|
|
34
|
+
#generation = 0;
|
|
35
|
+
/** @param run - the single reconciliation pass, invoked at most once per batch. */
|
|
36
|
+
constructor(run) {
|
|
37
|
+
this.#run = run;
|
|
38
|
+
}
|
|
39
|
+
/** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
|
|
40
|
+
activate() {
|
|
41
|
+
this.#active = true;
|
|
42
|
+
}
|
|
43
|
+
/** Closes the window and drops any pending pass; call from `disconnect()`. */
|
|
44
|
+
cancel() {
|
|
45
|
+
this.#active = false;
|
|
46
|
+
this.#queued = false;
|
|
47
|
+
this.#generation += 1;
|
|
48
|
+
}
|
|
49
|
+
/** Requests one pass after the batch settles. Idempotent; inert outside the window. */
|
|
50
|
+
schedule() {
|
|
51
|
+
if (!this.#active || this.#queued) return;
|
|
52
|
+
this.#queued = true;
|
|
53
|
+
const generation = this.#generation;
|
|
54
|
+
queueMicrotask(() => {
|
|
55
|
+
if (generation !== this.#generation || !this.#queued || !this.#active) return;
|
|
56
|
+
this.#queued = false;
|
|
57
|
+
this.#run();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/utils/range.ts
|
|
63
|
+
function rangeFraction(value, min, max) {
|
|
64
|
+
const span = max - min;
|
|
65
|
+
if (!(span > 0)) return 0;
|
|
66
|
+
const clamped = Math.min(max, Math.max(min, value));
|
|
67
|
+
let fraction;
|
|
68
|
+
if (Number.isFinite(span)) {
|
|
69
|
+
fraction = (clamped - min) / span;
|
|
70
|
+
} else {
|
|
71
|
+
const scale = Math.max(Math.abs(min), Math.abs(max));
|
|
72
|
+
fraction = (clamped / scale - min / scale) / (max / scale - min / scale);
|
|
73
|
+
}
|
|
74
|
+
if (!Number.isFinite(fraction)) return 0;
|
|
75
|
+
return Math.min(1, Math.max(0, fraction));
|
|
76
|
+
}
|
|
77
|
+
|
|
12
78
|
// src/controllers/progress_controller.ts
|
|
79
|
+
var OWNED_VALUE_TEXT = "data-stimeo--progress-owns-valuetext";
|
|
13
80
|
var ProgressController = class extends Controller {
|
|
14
81
|
static targets = ["bar"];
|
|
15
82
|
static values = {
|
|
@@ -17,13 +84,27 @@ var ProgressController = class extends Controller {
|
|
|
17
84
|
min: { type: Number, default: 0 },
|
|
18
85
|
max: { type: Number, default: 100 },
|
|
19
86
|
indeterminate: { type: Boolean, default: false },
|
|
20
|
-
valueText: { type: String, default: "" }
|
|
87
|
+
valueText: { type: String, default: "" },
|
|
88
|
+
announceText: { type: String, default: "" }
|
|
21
89
|
};
|
|
22
90
|
static actions = ["setValue"];
|
|
23
91
|
static events = ["change", "complete"];
|
|
92
|
+
/**
|
|
93
|
+
* Collapses a morph that swaps several render inputs at once into one repaint.
|
|
94
|
+
* A single update usually rewrites the whole set, and each Value would otherwise
|
|
95
|
+
* repaint on its own.
|
|
96
|
+
*/
|
|
97
|
+
#repaint = new MicrotaskCoalescer(() => {
|
|
98
|
+
this.#render();
|
|
99
|
+
});
|
|
24
100
|
connect() {
|
|
101
|
+
this.#repaint.activate();
|
|
25
102
|
this.#render();
|
|
26
103
|
}
|
|
104
|
+
/** Closes the window in which a queued repaint may still run. */
|
|
105
|
+
disconnect() {
|
|
106
|
+
this.#repaint.cancel();
|
|
107
|
+
}
|
|
27
108
|
/**
|
|
28
109
|
* Updates the progress value from an action param (`amount`) or a
|
|
29
110
|
* `detail.value` CustomEvent, normalizes it into range, syncs ARIA, and
|
|
@@ -39,11 +120,30 @@ var ProgressController = class extends Controller {
|
|
|
39
120
|
this.dispatch("change", { detail: { value, ratio: this.#ratio } });
|
|
40
121
|
if (value >= this.maxValue) {
|
|
41
122
|
this.dispatch("complete", { detail: { value } });
|
|
123
|
+
announce(
|
|
124
|
+
fillTemplate(this.announceTextValue, { value, percent: Math.round(this.#ratio * 100) })
|
|
125
|
+
);
|
|
42
126
|
}
|
|
43
127
|
}
|
|
44
|
-
/**
|
|
128
|
+
/** Repaints when application code (or a Turbo morph) changes `indeterminate` at runtime. */
|
|
45
129
|
indeterminateValueChanged() {
|
|
46
|
-
this.#
|
|
130
|
+
this.#repaint.schedule();
|
|
131
|
+
}
|
|
132
|
+
/** Repaints when application code (or a Turbo morph) changes `value` at runtime. */
|
|
133
|
+
valueValueChanged() {
|
|
134
|
+
this.#repaint.schedule();
|
|
135
|
+
}
|
|
136
|
+
/** Repaints when application code (or a Turbo morph) changes `min` at runtime. */
|
|
137
|
+
minValueChanged() {
|
|
138
|
+
this.#repaint.schedule();
|
|
139
|
+
}
|
|
140
|
+
/** Repaints when application code (or a Turbo morph) changes `max` at runtime. */
|
|
141
|
+
maxValueChanged() {
|
|
142
|
+
this.#repaint.schedule();
|
|
143
|
+
}
|
|
144
|
+
/** Repaints when application code (or a Turbo morph) changes `valueText` at runtime. */
|
|
145
|
+
valueTextValueChanged() {
|
|
146
|
+
this.#repaint.schedule();
|
|
47
147
|
}
|
|
48
148
|
/** Clamps `raw` into the configured `[min, max]` range. */
|
|
49
149
|
#clamp(raw) {
|
|
@@ -51,9 +151,7 @@ var ProgressController = class extends Controller {
|
|
|
51
151
|
}
|
|
52
152
|
/** Current fraction of the range in `[0, 1]`; `0` when the range is empty. */
|
|
53
153
|
get #ratio() {
|
|
54
|
-
|
|
55
|
-
if (span <= 0) return 0;
|
|
56
|
-
return (this.#clamp(this.valueValue) - this.minValue) / span;
|
|
154
|
+
return rangeFraction(this.valueValue, this.minValue, this.maxValue);
|
|
57
155
|
}
|
|
58
156
|
/** Reflects value/range/indeterminate onto ARIA, `data-state`, and the ratio. */
|
|
59
157
|
#render() {
|
|
@@ -61,7 +159,7 @@ var ProgressController = class extends Controller {
|
|
|
61
159
|
this.element.setAttribute("aria-valuemax", String(this.maxValue));
|
|
62
160
|
if (this.indeterminateValue) {
|
|
63
161
|
this.element.removeAttribute("aria-valuenow");
|
|
64
|
-
this
|
|
162
|
+
this.#clearOwnValueText();
|
|
65
163
|
this.element.style.removeProperty("--stimeo-progress-ratio");
|
|
66
164
|
this.element.setAttribute("data-state", "indeterminate");
|
|
67
165
|
return;
|
|
@@ -75,16 +173,25 @@ var ProgressController = class extends Controller {
|
|
|
75
173
|
/**
|
|
76
174
|
* Sets `aria-valuetext` from the consumer-provided template, substituting
|
|
77
175
|
* `{value}` and `{percent}`. Left to the consumer so the human-readable text
|
|
78
|
-
* stays i18n-neutral in the library
|
|
176
|
+
* stays i18n-neutral in the library. With no template the attribute belongs to
|
|
177
|
+
* the consumer, so only a text this controller wrote is taken back
|
|
178
|
+
* ({@link OWNED_VALUE_TEXT}).
|
|
79
179
|
*/
|
|
80
180
|
#applyValueText(value) {
|
|
81
181
|
if (this.valueTextValue.length === 0) {
|
|
82
|
-
this
|
|
182
|
+
this.#clearOwnValueText();
|
|
83
183
|
return;
|
|
84
184
|
}
|
|
85
185
|
const percent = Math.round(this.#ratio * 100);
|
|
86
186
|
const text = this.valueTextValue.replaceAll("{value}", String(value)).replaceAll("{percent}", String(percent));
|
|
87
187
|
this.element.setAttribute("aria-valuetext", text);
|
|
188
|
+
this.element.setAttribute(OWNED_VALUE_TEXT, "");
|
|
189
|
+
}
|
|
190
|
+
/** Removes `aria-valuetext` only when this controller is the one that wrote it. */
|
|
191
|
+
#clearOwnValueText() {
|
|
192
|
+
if (!this.element.hasAttribute(OWNED_VALUE_TEXT)) return;
|
|
193
|
+
this.element.removeAttribute("aria-valuetext");
|
|
194
|
+
this.element.removeAttribute(OWNED_VALUE_TEXT);
|
|
88
195
|
}
|
|
89
196
|
};
|
|
90
197
|
|
|
@@ -2,6 +2,24 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/radio_group_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/logical_scroll.ts
|
|
6
|
+
function isRtl(element) {
|
|
7
|
+
return window.getComputedStyle(element).direction === "rtl";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/utils/arrow_step.ts
|
|
11
|
+
function logicalArrowStep(key, element) {
|
|
12
|
+
if (key === "ArrowDown") return 1;
|
|
13
|
+
if (key === "ArrowUp") return -1;
|
|
14
|
+
if (key !== "ArrowRight" && key !== "ArrowLeft") return 0;
|
|
15
|
+
const forward = isRtl(element) ? "ArrowLeft" : "ArrowRight";
|
|
16
|
+
return key === forward ? 1 : -1;
|
|
17
|
+
}
|
|
18
|
+
function isReservedArrowChord(event, allow = []) {
|
|
19
|
+
if (!event.key.startsWith("Arrow")) return false;
|
|
20
|
+
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
// src/utils/roving_tabindex.ts
|
|
6
24
|
var RovingTabindex = class {
|
|
7
25
|
/** Returns the current ordered item elements; called on every operation. */
|
|
@@ -59,17 +77,18 @@ var RadioGroupController = class extends Controller {
|
|
|
59
77
|
}
|
|
60
78
|
/** Arrow/Home/End/Space navigation with selection-follows-focus. */
|
|
61
79
|
onKeydown(event) {
|
|
80
|
+
if (event.defaultPrevented) return;
|
|
81
|
+
if (isReservedArrowChord(event)) return;
|
|
62
82
|
const current = this.radioTargets.indexOf(event.currentTarget);
|
|
63
83
|
if (current === -1) return;
|
|
64
84
|
let next = null;
|
|
85
|
+
const step = logicalArrowStep(event.key, this.element);
|
|
65
86
|
switch (event.key) {
|
|
66
87
|
case "ArrowDown":
|
|
67
88
|
case "ArrowRight":
|
|
68
|
-
next = rovingMove(current, this.radioTargets.length, 1);
|
|
69
|
-
break;
|
|
70
89
|
case "ArrowUp":
|
|
71
90
|
case "ArrowLeft":
|
|
72
|
-
next = rovingMove(current, this.radioTargets.length,
|
|
91
|
+
next = rovingMove(current, this.radioTargets.length, step);
|
|
73
92
|
break;
|
|
74
93
|
case "Home":
|
|
75
94
|
next = 0;
|