stimeo-ui 0.18.1 → 0.18.2
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 +21 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +89 -45
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +77 -11
- data/dist/controllers/bulk_select_controller.js +6 -9
- data/dist/controllers/character_counter_controller.js +77 -11
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/combobox_controller.js +71 -6
- data/dist/controllers/command_palette_controller.js +160 -51
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +89 -45
- data/dist/controllers/context_menu_controller.js +1 -1
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +71 -6
- data/dist/controllers/data_grid_controller.js +77 -42
- data/dist/controllers/date_range_picker_controller.js +2 -1
- data/dist/controllers/dialog_controller.js +89 -45
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +11 -7
- data/dist/controllers/drawer_controller.js +89 -45
- data/dist/controllers/dropdown_controller.js +1 -1
- data/dist/controllers/editable_controller.js +71 -6
- data/dist/controllers/empty_state_controller.js +6 -5
- data/dist/controllers/file_dropzone_controller.js +13 -11
- data/dist/controllers/flash_controller.js +6 -5
- data/dist/controllers/focus_controller.js +89 -45
- data/dist/controllers/form_field_controller.js +6 -5
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +50 -16
- data/dist/controllers/hover_card_controller.js +1 -1
- data/dist/controllers/input_mask_controller.js +94 -36
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +80 -47
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +1 -1
- data/dist/controllers/menubar_controller.js +4 -6
- data/dist/controllers/meter_controller.js +6 -5
- data/dist/controllers/multi_select_controller.js +86 -21
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +17 -12
- data/dist/controllers/network_status_controller.js +6 -5
- data/dist/controllers/number_input_controller.js +154 -66
- data/dist/controllers/otp_controller.js +71 -6
- data/dist/controllers/overflow_menu_controller.js +7 -2
- data/dist/controllers/pagination_controller.js +7 -2
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +12 -8
- data/dist/controllers/progress_controller.js +6 -5
- data/dist/controllers/radio_group_controller.js +85 -49
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +7 -2
- data/dist/controllers/scroll_area_controller.js +11 -7
- data/dist/controllers/scrollspy_controller.js +61 -29
- data/dist/controllers/separator_controller.js +72 -54
- data/dist/controllers/sidebar_controller.js +89 -45
- data/dist/controllers/skeleton_controller.js +50 -16
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +50 -16
- data/dist/controllers/sticky_observer_controller.js +61 -29
- data/dist/controllers/submit_once_controller.js +6 -5
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tags_input_controller.js +83 -20
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toggle_group_controller.js +84 -44
- data/dist/controllers/toolbar_controller.js +78 -8
- data/dist/controllers/tooltip_controller.js +1 -1
- data/dist/controllers/tree_view_controller.js +87 -49
- data/dist/index.js +503 -286
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -153,11 +153,16 @@ var AttributeLease = class {
|
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
156
157
|
function inheritsFieldsetDisabled(control) {
|
|
157
158
|
let fieldset = control.closest("fieldset[disabled]");
|
|
158
159
|
while (fieldset) {
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
161
|
+
const legend = Array.from(fieldset.children).find(
|
|
162
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
163
|
+
);
|
|
164
|
+
if (!legend?.contains(control)) return true;
|
|
165
|
+
}
|
|
161
166
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
162
167
|
}
|
|
163
168
|
return false;
|
|
@@ -215,11 +220,10 @@ function hasNativeTabStop(element) {
|
|
|
215
220
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
216
221
|
return element.hasAttribute("controls");
|
|
217
222
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return false;
|
|
223
|
+
const details = element.parentElement;
|
|
224
|
+
return details instanceof HTMLDetailsElement && Array.from(details.children).find(
|
|
225
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
|
|
226
|
+
) === element;
|
|
223
227
|
}
|
|
224
228
|
function hasEditableTabStop(element) {
|
|
225
229
|
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
@@ -63,70 +63,102 @@ function queryRoot(selector) {
|
|
|
63
63
|
}
|
|
64
64
|
var IntersectionWatcher = class {
|
|
65
65
|
#onEntries;
|
|
66
|
-
#
|
|
67
|
-
#active = false;
|
|
68
|
-
#usingPlatformDefaults = false;
|
|
66
|
+
#session = null;
|
|
69
67
|
constructor(onEntries) {
|
|
70
68
|
this.#onEntries = onEntries;
|
|
71
69
|
}
|
|
72
70
|
get active() {
|
|
73
|
-
return this.#active;
|
|
71
|
+
return this.#session?.active ?? false;
|
|
74
72
|
}
|
|
75
73
|
get usingPlatformDefaults() {
|
|
76
|
-
return this.#usingPlatformDefaults;
|
|
74
|
+
return this.#session?.usingPlatformDefaults ?? false;
|
|
77
75
|
}
|
|
78
76
|
start(targets, options = {}) {
|
|
79
|
-
this
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
const previous = this.#session;
|
|
78
|
+
const session = {
|
|
79
|
+
observer: null,
|
|
80
|
+
active: false,
|
|
81
|
+
usingPlatformDefaults: false
|
|
82
|
+
};
|
|
83
|
+
this.#session = session;
|
|
84
84
|
let observer = null;
|
|
85
85
|
try {
|
|
86
|
+
if (previous) this.#release(previous);
|
|
87
|
+
if (this.#session !== session) return false;
|
|
88
|
+
if (typeof IntersectionObserver === "undefined") return false;
|
|
89
|
+
const list = Array.isArray(targets) ? targets : [targets];
|
|
90
|
+
const empty = list.length === 0;
|
|
91
|
+
if (this.#session !== session) return false;
|
|
92
|
+
if (empty) return false;
|
|
93
|
+
const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
|
|
94
|
+
if (this.#session !== session) return false;
|
|
86
95
|
const onEntries = (entries) => {
|
|
87
|
-
if (this.#
|
|
96
|
+
if (this.#session === session && session.active) this.#onEntries(entries);
|
|
88
97
|
};
|
|
98
|
+
let usingPlatformDefaults = false;
|
|
89
99
|
try {
|
|
90
|
-
|
|
100
|
+
const configured = {
|
|
91
101
|
root,
|
|
92
102
|
rootMargin: options.rootMargin,
|
|
93
103
|
threshold: options.threshold
|
|
94
|
-
}
|
|
104
|
+
};
|
|
105
|
+
if (this.#session !== session) return false;
|
|
106
|
+
observer = new IntersectionObserver(onEntries, configured);
|
|
95
107
|
} catch (error) {
|
|
108
|
+
if (this.#session !== session) return false;
|
|
96
109
|
console.warn(
|
|
97
110
|
"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
|
|
98
111
|
error
|
|
99
112
|
);
|
|
113
|
+
if (this.#session !== session) return false;
|
|
100
114
|
observer = new IntersectionObserver(onEntries, { root });
|
|
101
|
-
|
|
115
|
+
usingPlatformDefaults = true;
|
|
116
|
+
}
|
|
117
|
+
if (this.#session !== session) {
|
|
118
|
+
this.#release(session, observer);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
session.observer = observer;
|
|
122
|
+
for (const target of list) {
|
|
123
|
+
if (this.#session !== session) return false;
|
|
124
|
+
observer.observe(target);
|
|
125
|
+
if (this.#session !== session) {
|
|
126
|
+
this.#release(session, observer);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
102
129
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
130
|
+
if (this.#session !== session) return false;
|
|
131
|
+
session.usingPlatformDefaults = usingPlatformDefaults;
|
|
132
|
+
session.active = true;
|
|
106
133
|
return true;
|
|
107
134
|
} catch (error) {
|
|
108
|
-
observer
|
|
109
|
-
this.#observer = null;
|
|
110
|
-
this.#active = false;
|
|
111
|
-
this.#usingPlatformDefaults = false;
|
|
135
|
+
this.#release(session, observer);
|
|
112
136
|
throw error;
|
|
113
137
|
}
|
|
114
138
|
}
|
|
115
139
|
rearm(target) {
|
|
116
|
-
|
|
140
|
+
const session = this.#session;
|
|
141
|
+
const observer = session?.observer;
|
|
142
|
+
if (!session?.active || !observer) return;
|
|
117
143
|
try {
|
|
118
|
-
|
|
119
|
-
this.#
|
|
144
|
+
observer.unobserve(target);
|
|
145
|
+
if (this.#session !== session) return;
|
|
146
|
+
observer.observe(target);
|
|
147
|
+
if (this.#session !== session) this.#release(session, observer);
|
|
120
148
|
} catch (error) {
|
|
121
|
-
this
|
|
149
|
+
if (this.#session === session) this.#session = null;
|
|
150
|
+
this.#release(session, observer);
|
|
122
151
|
throw error;
|
|
123
152
|
}
|
|
124
153
|
}
|
|
125
154
|
stop() {
|
|
126
|
-
|
|
127
|
-
this.#
|
|
128
|
-
this.#
|
|
129
|
-
|
|
155
|
+
const session = this.#session;
|
|
156
|
+
this.#session = null;
|
|
157
|
+
if (session) this.#release(session);
|
|
158
|
+
}
|
|
159
|
+
#release(session, observer = session.observer) {
|
|
160
|
+
session.observer = null;
|
|
161
|
+
observer?.disconnect();
|
|
130
162
|
}
|
|
131
163
|
};
|
|
132
164
|
|
|
@@ -283,25 +283,22 @@ function snapSteppedValue(raw, range) {
|
|
|
283
283
|
if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
|
|
284
284
|
const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
|
|
285
285
|
const clamped = Math.min(range.max, Math.max(range.min, input));
|
|
286
|
-
const
|
|
287
|
-
const base = stepBase(range);
|
|
286
|
+
const grid = stepGrid(range);
|
|
288
287
|
const candidates = [];
|
|
289
288
|
if (Number.isFinite(range.min)) candidates.push(range.min);
|
|
290
289
|
if (Number.isFinite(range.max)) candidates.push(range.max);
|
|
291
|
-
const
|
|
292
|
-
if (Number.isFinite(
|
|
293
|
-
|
|
294
|
-
|
|
290
|
+
const position = gridPosition(clamped, grid);
|
|
291
|
+
if (Number.isFinite(position)) {
|
|
292
|
+
for (const index of [Math.floor(position), Math.ceil(position)]) {
|
|
293
|
+
const candidate = gridValue(index, grid);
|
|
294
|
+
if (inRange(candidate, range)) candidates.push(candidate);
|
|
295
|
+
}
|
|
295
296
|
}
|
|
296
297
|
if (candidates.length === 0) return clamped;
|
|
297
298
|
let nearest = candidates[0];
|
|
298
|
-
let nearestDistance = Math.abs(clamped - nearest);
|
|
299
299
|
for (const candidate of candidates.slice(1)) {
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
302
|
-
nearest = candidate;
|
|
303
|
-
nearestDistance = distance;
|
|
304
|
-
}
|
|
300
|
+
const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
|
|
301
|
+
if (nearer) nearest = candidate;
|
|
305
302
|
}
|
|
306
303
|
return nearest;
|
|
307
304
|
}
|
|
@@ -310,46 +307,36 @@ function stepSteppedValue(current, count, range) {
|
|
|
310
307
|
const distance = Math.abs(Math.trunc(count));
|
|
311
308
|
if (!Number.isFinite(distance) || distance === 0) return value;
|
|
312
309
|
const direction = Math.sign(count);
|
|
313
|
-
const adjacent =
|
|
310
|
+
const adjacent = nextGridValue(value, direction, range);
|
|
311
|
+
if (adjacent === value) return value;
|
|
314
312
|
const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
|
|
315
|
-
|
|
313
|
+
const endpoint = direction > 0 ? range.max : range.min;
|
|
314
|
+
return Number.isFinite(raw) || Number.isFinite(endpoint) ? snapSteppedValue(raw, range) : value;
|
|
316
315
|
}
|
|
317
|
-
function
|
|
316
|
+
function nextGridValue(current, direction, range) {
|
|
317
|
+
const grid = stepGrid(range);
|
|
318
|
+
const position = gridPosition(current, grid);
|
|
319
|
+
if (!Number.isFinite(position)) return current;
|
|
320
|
+
const index = direction > 0 ? Math.floor(position) + 1 : Math.ceil(position) - 1;
|
|
321
|
+
const first = gridValue(index, grid);
|
|
322
|
+
if (direction * (first - current) > 0 && !sameGridValue(first, current, grid.step)) {
|
|
323
|
+
return first;
|
|
324
|
+
}
|
|
325
|
+
const second = gridValue(index + direction, grid);
|
|
326
|
+
return direction * (second - current) > 0 ? second : current;
|
|
327
|
+
}
|
|
328
|
+
function stepGrid(range) {
|
|
318
329
|
const step = effectiveStep(range.step);
|
|
319
330
|
const base = stepBase(range);
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (candidate < current || nearlyEqual(candidate, current)) {
|
|
327
|
-
gridIndex += 1;
|
|
328
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
329
|
-
}
|
|
330
|
-
if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
331
|
-
candidates.push(clamp(candidate, range));
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return clamp(Math.min(...candidates), range);
|
|
335
|
-
}
|
|
336
|
-
const position = (current - base) / step;
|
|
337
|
-
if (Number.isFinite(position)) {
|
|
338
|
-
let gridIndex = Math.ceil(position) - 1;
|
|
339
|
-
let candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
340
|
-
if (candidate > current || nearlyEqual(candidate, current)) {
|
|
341
|
-
gridIndex -= 1;
|
|
342
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
343
|
-
}
|
|
344
|
-
if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
345
|
-
candidates.push(clamp(candidate, range));
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return clamp(Math.max(...candidates), range);
|
|
331
|
+
const near = base - Math.trunc(base / step) * step;
|
|
332
|
+
const origin = cleanGridValue(Number.isFinite(near) ? near % step : base % step, base, step);
|
|
333
|
+
return { step, base, origin };
|
|
334
|
+
}
|
|
335
|
+
function gridPosition(value, grid) {
|
|
336
|
+
return value / grid.step - grid.origin / grid.step;
|
|
349
337
|
}
|
|
350
|
-
function
|
|
351
|
-
|
|
352
|
-
if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));
|
|
338
|
+
function gridValue(index, grid) {
|
|
339
|
+
return cleanGridValue(grid.origin + index * grid.step, grid.base, grid.step);
|
|
353
340
|
}
|
|
354
341
|
function stepBase(range) {
|
|
355
342
|
if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
|
|
@@ -365,15 +352,46 @@ function decimalPlaces(value) {
|
|
|
365
352
|
const exponent = exponentText === void 0 ? 0 : Number(exponentText);
|
|
366
353
|
return Math.max(0, fractionLength - exponent);
|
|
367
354
|
}
|
|
368
|
-
function
|
|
369
|
-
return (value
|
|
355
|
+
function inRange(value, range) {
|
|
356
|
+
return Number.isFinite(value) && value >= range.min && value <= range.max;
|
|
357
|
+
}
|
|
358
|
+
function sameGridValue(left, right, step) {
|
|
359
|
+
const rounding = Number.EPSILON * Math.max(Math.abs(left), Math.abs(right));
|
|
360
|
+
return Math.abs(left - right) <= Math.min(rounding, step / 4);
|
|
361
|
+
}
|
|
362
|
+
function isMidpoint(value, left, right, range, grid) {
|
|
363
|
+
const imbalance = Math.abs(Math.abs(value - left) - Math.abs(value - right));
|
|
364
|
+
const rounding = 4 * Number.EPSILON * Math.max(Math.abs(value), Math.abs(left), Math.abs(right));
|
|
365
|
+
if (!(imbalance <= rounding)) return false;
|
|
366
|
+
if (imbalance <= Math.abs(left - right) / 4) return true;
|
|
367
|
+
const lower = Math.min(left, right);
|
|
368
|
+
const upper = Math.max(left, right);
|
|
369
|
+
return value > lower && value < upper && isDecimalMidpoint(value, lower, upper, range, grid);
|
|
370
370
|
}
|
|
371
|
-
function
|
|
372
|
-
|
|
371
|
+
function isDecimalMidpoint(value, lower, upper, range, grid) {
|
|
372
|
+
const raw = decimalParts(value);
|
|
373
|
+
const base = decimalParts(grid.base);
|
|
374
|
+
const step = decimalParts(grid.step);
|
|
375
|
+
const min = decimalParts(lower);
|
|
376
|
+
const max = decimalParts(upper);
|
|
377
|
+
const place = Math.min(raw.place, base.place, step.place, min.place, max.place);
|
|
378
|
+
const units = (part) => part.units * 10n ** BigInt(part.place - place);
|
|
379
|
+
const origin = units(base);
|
|
380
|
+
const stride = units(step);
|
|
381
|
+
const rawUnits = units(raw);
|
|
382
|
+
const remainder = (rawUnits - origin) % stride;
|
|
383
|
+
const below = rawUnits - (remainder < 0n ? remainder + stride : remainder);
|
|
384
|
+
const above = below + stride;
|
|
385
|
+
const minUnits = units(min);
|
|
386
|
+
const maxUnits = units(max);
|
|
387
|
+
const lowerUnits = lower === range.min && minUnits > below ? minUnits : below;
|
|
388
|
+
const upperUnits = upper === range.max && maxUnits < above ? maxUnits : above;
|
|
389
|
+
return Number(`${lowerUnits}e${place}`) === lower && Number(`${upperUnits}e${place}`) === upper && Number(`${(lowerUnits + upperUnits) * 5n}e${place - 1}`) === value;
|
|
373
390
|
}
|
|
374
|
-
function
|
|
375
|
-
const
|
|
376
|
-
|
|
391
|
+
function decimalParts(value) {
|
|
392
|
+
const [coefficient = "", exponent = "0"] = value.toString().split("e");
|
|
393
|
+
const [whole = "", fraction = ""] = coefficient.split(".");
|
|
394
|
+
return { units: BigInt(whole + fraction), place: Number(exponent) - fraction.length };
|
|
377
395
|
}
|
|
378
396
|
function finiteFallback(min, max) {
|
|
379
397
|
if (Number.isFinite(min)) return min;
|
|
@@ -197,6 +197,7 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
197
197
|
);
|
|
198
198
|
#active = null;
|
|
199
199
|
activate(ownerDocument = document, options) {
|
|
200
|
+
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
200
201
|
this.deactivate();
|
|
201
202
|
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
202
203
|
if (!registry2) {
|
|
@@ -204,7 +205,6 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
204
205
|
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
205
206
|
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
206
207
|
}
|
|
207
|
-
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
208
208
|
registry2.stack.push(entry);
|
|
209
209
|
this.#active = { document: ownerDocument, entry };
|
|
210
210
|
}
|
|
@@ -253,11 +253,16 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
253
253
|
}
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
256
257
|
function inheritsFieldsetDisabled(control) {
|
|
257
258
|
let fieldset = control.closest("fieldset[disabled]");
|
|
258
259
|
while (fieldset) {
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
261
|
+
const legend = Array.from(fieldset.children).find(
|
|
262
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
263
|
+
);
|
|
264
|
+
if (!legend?.contains(control)) return true;
|
|
265
|
+
}
|
|
261
266
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
262
267
|
}
|
|
263
268
|
return false;
|
|
@@ -330,11 +335,10 @@ function hasNativeTabStop(element) {
|
|
|
330
335
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
331
336
|
return element.hasAttribute("controls");
|
|
332
337
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return false;
|
|
338
|
+
const details = element.parentElement;
|
|
339
|
+
return details instanceof HTMLDetailsElement && Array.from(details.children).find(
|
|
340
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "summary"
|
|
341
|
+
) === element;
|
|
338
342
|
}
|
|
339
343
|
function hasEditableTabStop(element) {
|
|
340
344
|
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
@@ -397,8 +401,7 @@ function isSequentialStop(element) {
|
|
|
397
401
|
function ownedScope(element) {
|
|
398
402
|
if (element.shadowRoot) return Array.from(element.shadowRoot.children);
|
|
399
403
|
if (element instanceof HTMLSlotElement) {
|
|
400
|
-
|
|
401
|
-
return assigned.length > 0 ? assigned : Array.from(element.children);
|
|
404
|
+
return element.assignedNodes().length > 0 ? element.assignedElements() : Array.from(element.children);
|
|
402
405
|
}
|
|
403
406
|
return null;
|
|
404
407
|
}
|
|
@@ -407,12 +410,19 @@ function orderScope(elements, walk) {
|
|
|
407
410
|
const visit = (element) => {
|
|
408
411
|
if (element === walk.from) walk.fromAt = walk.tree.length;
|
|
409
412
|
const tabindex = authoredTabindex(element) ?? 0;
|
|
410
|
-
|
|
411
|
-
if (
|
|
413
|
+
let stop = null;
|
|
414
|
+
if ((element instanceof HTMLElement || element instanceof SVGElement) && isSequentialStop(element)) {
|
|
415
|
+
stop = element;
|
|
416
|
+
walk.tree.push(element);
|
|
417
|
+
}
|
|
412
418
|
const owned = ownedScope(element);
|
|
413
419
|
if (owned) {
|
|
414
420
|
if (tabindex >= 0) {
|
|
415
421
|
entries.push({ tabindex, stops: [...stop ? [stop] : [], ...orderScope(owned, walk)] });
|
|
422
|
+
} else if (walk.from && flatTreeContains(element, walk.from)) {
|
|
423
|
+
walk.fromAt = walk.tree.length;
|
|
424
|
+
walk.excludedScope = element;
|
|
425
|
+
orderScope(owned, { from: walk.from, tree: walk.tree, fromAt: -1, excludedScope: null });
|
|
416
426
|
}
|
|
417
427
|
return;
|
|
418
428
|
}
|
|
@@ -440,16 +450,38 @@ function startIndex(order, walk, backward, isStop) {
|
|
|
440
450
|
if (at >= 0) return backward ? at - 1 : at + 1;
|
|
441
451
|
const neighbour = backward ? walk.tree.slice(0, walk.fromAt).reverse().find(isStop) : walk.tree.slice(walk.fromAt).find(isStop);
|
|
442
452
|
if (neighbour) return order.indexOf(neighbour);
|
|
443
|
-
return backward ?
|
|
453
|
+
return backward ? -1 : order.length;
|
|
444
454
|
}
|
|
445
|
-
function
|
|
446
|
-
const walk = {
|
|
455
|
+
function movesWithin(root, from, backward, wrap, radioContext) {
|
|
456
|
+
const walk = {
|
|
457
|
+
from,
|
|
458
|
+
tree: [],
|
|
459
|
+
fromAt: from === root ? 0 : -1,
|
|
460
|
+
excludedScope: null
|
|
461
|
+
};
|
|
447
462
|
const order = orderScope(ownedScope(root) ?? Array.from(root.children), walk);
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
463
|
+
const radios = radioContext ?? {
|
|
464
|
+
tree: walk.tree,
|
|
465
|
+
focusedRadio: walk.fromAt >= 0 && isRadio(from) ? from : null
|
|
466
|
+
};
|
|
467
|
+
const isStop = (element) => passesRadioRule(element, radios.tree, radios.focusedRadio);
|
|
468
|
+
const start = startIndex(
|
|
469
|
+
order,
|
|
470
|
+
walk,
|
|
471
|
+
backward,
|
|
472
|
+
(element) => order.includes(element) && isStop(element)
|
|
473
|
+
);
|
|
474
|
+
const remaining = backward ? order.slice(0, start + 1).reverse() : order.slice(start);
|
|
475
|
+
const wrapped = wrap ? backward ? order.slice(start + 1).reverse() : order.slice(0, start) : [];
|
|
476
|
+
const excluded = walk.excludedScope;
|
|
477
|
+
const prefix = excluded && !(backward && from === excluded) ? movesWithin(excluded, from === excluded ? null : from, backward, false, radios) : [];
|
|
478
|
+
return [
|
|
479
|
+
...prefix,
|
|
480
|
+
...[...remaining, ...wrapped].filter((element) => element !== from && isStop(element))
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
function sequentialTabStops(root, from = null, backward = false) {
|
|
484
|
+
return movesWithin(root, from, backward, true);
|
|
453
485
|
}
|
|
454
486
|
function deepActiveElement(ownerDocument) {
|
|
455
487
|
let active = ownerDocument.activeElement;
|
|
@@ -636,7 +668,10 @@ var FocusTrap = class _FocusTrap {
|
|
|
636
668
|
constructor(getContainer, options = {}) {
|
|
637
669
|
this.#getContainer = getContainer;
|
|
638
670
|
this.#options = options;
|
|
639
|
-
this.#entry =
|
|
671
|
+
this.#entry = this.#createEntry();
|
|
672
|
+
}
|
|
673
|
+
#createEntry() {
|
|
674
|
+
return {
|
|
640
675
|
container: () => this.#readContainer(),
|
|
641
676
|
moveFocus: (backward) => this.#moveFocus(backward),
|
|
642
677
|
refocus: () => this.#refocus(),
|
|
@@ -652,6 +687,7 @@ var FocusTrap = class _FocusTrap {
|
|
|
652
687
|
activate() {
|
|
653
688
|
if (this.#activeState) return;
|
|
654
689
|
_FocusTrap.#sweep();
|
|
690
|
+
this.#entry = this.#createEntry();
|
|
655
691
|
this.#activeState = true;
|
|
656
692
|
this.#openers = _FocusTrap.#focusPath();
|
|
657
693
|
this.#entry.openedFrom = _FocusTrap.#trapHolding(this.#openers[0] ?? null);
|
|
@@ -668,14 +704,20 @@ var FocusTrap = class _FocusTrap {
|
|
|
668
704
|
this.#returnTabindexes();
|
|
669
705
|
return;
|
|
670
706
|
}
|
|
707
|
+
const entry = this.#entry;
|
|
708
|
+
const openers = this.#openers;
|
|
709
|
+
this.#openers = [];
|
|
671
710
|
this.#activeState = false;
|
|
672
711
|
this.#escapeLayer.deactivate();
|
|
673
|
-
const above = this.#leaveStack();
|
|
674
|
-
this.#unlockScroll();
|
|
712
|
+
const above = this.#leaveStack(entry);
|
|
713
|
+
this.#unlockScroll(entry);
|
|
675
714
|
_FocusTrap.#reconcileBackground(document);
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
715
|
+
try {
|
|
716
|
+
const wayBack = this.#handOver(entry, openers, above);
|
|
717
|
+
if (restoreFocus) this.#restore(wayBack, above);
|
|
718
|
+
} finally {
|
|
719
|
+
this.#returnTabindexes();
|
|
720
|
+
}
|
|
679
721
|
}
|
|
680
722
|
connect() {
|
|
681
723
|
this.#gate.cancel();
|
|
@@ -714,9 +756,9 @@ var FocusTrap = class _FocusTrap {
|
|
|
714
756
|
}
|
|
715
757
|
registry2.stack.push(this.#entry);
|
|
716
758
|
}
|
|
717
|
-
#leaveStack() {
|
|
759
|
+
#leaveStack(entry) {
|
|
718
760
|
const registry2 = _FocusTrap.#registry(document);
|
|
719
|
-
const index = registry2.stack.indexOf(
|
|
761
|
+
const index = registry2.stack.indexOf(entry);
|
|
720
762
|
const above = registry2.stack.slice(index + 1);
|
|
721
763
|
registry2.stack.splice(index, 1);
|
|
722
764
|
if (registry2.stack.length === 0) {
|
|
@@ -740,21 +782,23 @@ var FocusTrap = class _FocusTrap {
|
|
|
740
782
|
}
|
|
741
783
|
return null;
|
|
742
784
|
}
|
|
743
|
-
#handOver(above) {
|
|
744
|
-
const
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
this.#options.fallbackFocus?.() ?? null,
|
|
748
|
-
...entry.handedBack
|
|
749
|
-
].filter((element) => element !== null);
|
|
750
|
-
for (const trap of above) {
|
|
751
|
-
if (trap.openedFrom !== entry) continue;
|
|
752
|
-
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
753
|
-
trap.openedFrom = entry.openedFrom;
|
|
754
|
-
}
|
|
755
|
-
this.#openers = [];
|
|
785
|
+
#handOver(entry, openers, above) {
|
|
786
|
+
const wayBack = [...openers];
|
|
787
|
+
const parent = entry.openedFrom;
|
|
788
|
+
const handedBack = entry.handedBack;
|
|
756
789
|
entry.openedFrom = null;
|
|
757
790
|
entry.handedBack = [];
|
|
791
|
+
try {
|
|
792
|
+
const fallback = this.#options.fallbackFocus?.();
|
|
793
|
+
if (fallback) wayBack.push(fallback);
|
|
794
|
+
} finally {
|
|
795
|
+
wayBack.push(...handedBack);
|
|
796
|
+
for (const trap of above) {
|
|
797
|
+
if (trap.openedFrom !== entry) continue;
|
|
798
|
+
trap.handedBack = [...trap.handedBack, ...wayBack];
|
|
799
|
+
trap.openedFrom = parent;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
758
802
|
return wayBack;
|
|
759
803
|
}
|
|
760
804
|
#restore(wayBack, above) {
|
|
@@ -804,11 +848,11 @@ var FocusTrap = class _FocusTrap {
|
|
|
804
848
|
this.#entry.lockedBody = body;
|
|
805
849
|
body.style.overflow = "hidden";
|
|
806
850
|
}
|
|
807
|
-
#unlockScroll() {
|
|
851
|
+
#unlockScroll(entry) {
|
|
808
852
|
const registry2 = _FocusTrap.#registry(document);
|
|
809
|
-
const body =
|
|
810
|
-
|
|
811
|
-
if (!registry2.scrollLocks.delete(
|
|
853
|
+
const body = entry.lockedBody;
|
|
854
|
+
entry.lockedBody = null;
|
|
855
|
+
if (!registry2.scrollLocks.delete(entry) || !body) return;
|
|
812
856
|
if (!_FocusTrap.#isLocked(registry2, body)) _FocusTrap.#unlock(body);
|
|
813
857
|
}
|
|
814
858
|
static #isLocked(registry2, body) {
|