stimeo-ui 0.18.0 → 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 +52 -2
- 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 +161 -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 +13 -7
- data/dist/controllers/drawer_controller.js +89 -45
- data/dist/controllers/dropdown_controller.js +1 -1
- data/dist/controllers/editable_controller.js +72 -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 +117 -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 +107 -22
- 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/pointer_drag_controller.js +6 -1
- data/dist/controllers/popover_controller.js +21 -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 +566 -288
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -227,25 +227,22 @@ function snapSteppedValue(raw, range) {
|
|
|
227
227
|
if (!(range.min <= range.max)) return finiteFallback(range.min, range.max);
|
|
228
228
|
const input = Number.isNaN(raw) ? finiteFallback(range.min, range.max) : raw;
|
|
229
229
|
const clamped = Math.min(range.max, Math.max(range.min, input));
|
|
230
|
-
const
|
|
231
|
-
const base = stepBase(range);
|
|
230
|
+
const grid = stepGrid(range);
|
|
232
231
|
const candidates = [];
|
|
233
232
|
if (Number.isFinite(range.min)) candidates.push(range.min);
|
|
234
233
|
if (Number.isFinite(range.max)) candidates.push(range.max);
|
|
235
|
-
const
|
|
236
|
-
if (Number.isFinite(
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
const position = gridPosition(clamped, grid);
|
|
235
|
+
if (Number.isFinite(position)) {
|
|
236
|
+
for (const index of [Math.floor(position), Math.ceil(position)]) {
|
|
237
|
+
const candidate = gridValue(index, grid);
|
|
238
|
+
if (inRange(candidate, range)) candidates.push(candidate);
|
|
239
|
+
}
|
|
239
240
|
}
|
|
240
241
|
if (candidates.length === 0) return clamped;
|
|
241
242
|
let nearest = candidates[0];
|
|
242
|
-
let nearestDistance = Math.abs(clamped - nearest);
|
|
243
243
|
for (const candidate of candidates.slice(1)) {
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
246
|
-
nearest = candidate;
|
|
247
|
-
nearestDistance = distance;
|
|
248
|
-
}
|
|
244
|
+
const nearer = isMidpoint(clamped, candidate, nearest, range, grid) ? candidate > nearest : Math.abs(clamped - candidate) < Math.abs(clamped - nearest);
|
|
245
|
+
if (nearer) nearest = candidate;
|
|
249
246
|
}
|
|
250
247
|
return nearest;
|
|
251
248
|
}
|
|
@@ -254,46 +251,36 @@ function stepSteppedValue(current, count, range) {
|
|
|
254
251
|
const distance = Math.abs(Math.trunc(count));
|
|
255
252
|
if (!Number.isFinite(distance) || distance === 0) return value;
|
|
256
253
|
const direction = Math.sign(count);
|
|
257
|
-
const adjacent =
|
|
254
|
+
const adjacent = nextGridValue(value, direction, range);
|
|
255
|
+
if (adjacent === value) return value;
|
|
258
256
|
const raw = adjacent + direction * (distance - 1) * effectiveStep(range.step);
|
|
259
|
-
|
|
257
|
+
const endpoint = direction > 0 ? range.max : range.min;
|
|
258
|
+
return Number.isFinite(raw) || Number.isFinite(endpoint) ? snapSteppedValue(raw, range) : value;
|
|
260
259
|
}
|
|
261
|
-
function
|
|
260
|
+
function nextGridValue(current, direction, range) {
|
|
261
|
+
const grid = stepGrid(range);
|
|
262
|
+
const position = gridPosition(current, grid);
|
|
263
|
+
if (!Number.isFinite(position)) return current;
|
|
264
|
+
const index = direction > 0 ? Math.floor(position) + 1 : Math.ceil(position) - 1;
|
|
265
|
+
const first = gridValue(index, grid);
|
|
266
|
+
if (direction * (first - current) > 0 && !sameGridValue(first, current, grid.step)) {
|
|
267
|
+
return first;
|
|
268
|
+
}
|
|
269
|
+
const second = gridValue(index + direction, grid);
|
|
270
|
+
return direction * (second - current) > 0 ? second : current;
|
|
271
|
+
}
|
|
272
|
+
function stepGrid(range) {
|
|
262
273
|
const step = effectiveStep(range.step);
|
|
263
274
|
const base = stepBase(range);
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (candidate < current || nearlyEqual(candidate, current)) {
|
|
271
|
-
gridIndex += 1;
|
|
272
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
273
|
-
}
|
|
274
|
-
if (candidate > current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
275
|
-
candidates.push(clamp(candidate, range));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return clamp(Math.min(...candidates), range);
|
|
279
|
-
}
|
|
280
|
-
const position = (current - base) / step;
|
|
281
|
-
if (Number.isFinite(position)) {
|
|
282
|
-
let gridIndex = Math.ceil(position) - 1;
|
|
283
|
-
let candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
284
|
-
if (candidate > current || nearlyEqual(candidate, current)) {
|
|
285
|
-
gridIndex -= 1;
|
|
286
|
-
candidate = cleanGridValue(base + gridIndex * step, base, step);
|
|
287
|
-
}
|
|
288
|
-
if (candidate < current && !nearlyEqual(candidate, current) && within(candidate, range.min, range.max)) {
|
|
289
|
-
candidates.push(clamp(candidate, range));
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return clamp(Math.max(...candidates), range);
|
|
275
|
+
const near = base - Math.trunc(base / step) * step;
|
|
276
|
+
const origin = cleanGridValue(Number.isFinite(near) ? near % step : base % step, base, step);
|
|
277
|
+
return { step, base, origin };
|
|
278
|
+
}
|
|
279
|
+
function gridPosition(value, grid) {
|
|
280
|
+
return value / grid.step - grid.origin / grid.step;
|
|
293
281
|
}
|
|
294
|
-
function
|
|
295
|
-
|
|
296
|
-
if (within(candidate, range.min, range.max)) candidates.push(clamp(candidate, range));
|
|
282
|
+
function gridValue(index, grid) {
|
|
283
|
+
return cleanGridValue(grid.origin + index * grid.step, grid.base, grid.step);
|
|
297
284
|
}
|
|
298
285
|
function stepBase(range) {
|
|
299
286
|
if (range.base !== void 0 && Number.isFinite(range.base)) return range.base;
|
|
@@ -309,15 +296,46 @@ function decimalPlaces(value) {
|
|
|
309
296
|
const exponent = exponentText === void 0 ? 0 : Number(exponentText);
|
|
310
297
|
return Math.max(0, fractionLength - exponent);
|
|
311
298
|
}
|
|
312
|
-
function
|
|
313
|
-
return (value
|
|
299
|
+
function inRange(value, range) {
|
|
300
|
+
return Number.isFinite(value) && value >= range.min && value <= range.max;
|
|
301
|
+
}
|
|
302
|
+
function sameGridValue(left, right, step) {
|
|
303
|
+
const rounding = Number.EPSILON * Math.max(Math.abs(left), Math.abs(right));
|
|
304
|
+
return Math.abs(left - right) <= Math.min(rounding, step / 4);
|
|
305
|
+
}
|
|
306
|
+
function isMidpoint(value, left, right, range, grid) {
|
|
307
|
+
const imbalance = Math.abs(Math.abs(value - left) - Math.abs(value - right));
|
|
308
|
+
const rounding = 4 * Number.EPSILON * Math.max(Math.abs(value), Math.abs(left), Math.abs(right));
|
|
309
|
+
if (!(imbalance <= rounding)) return false;
|
|
310
|
+
if (imbalance <= Math.abs(left - right) / 4) return true;
|
|
311
|
+
const lower = Math.min(left, right);
|
|
312
|
+
const upper = Math.max(left, right);
|
|
313
|
+
return value > lower && value < upper && isDecimalMidpoint(value, lower, upper, range, grid);
|
|
314
314
|
}
|
|
315
|
-
function
|
|
316
|
-
|
|
315
|
+
function isDecimalMidpoint(value, lower, upper, range, grid) {
|
|
316
|
+
const raw = decimalParts(value);
|
|
317
|
+
const base = decimalParts(grid.base);
|
|
318
|
+
const step = decimalParts(grid.step);
|
|
319
|
+
const min = decimalParts(lower);
|
|
320
|
+
const max = decimalParts(upper);
|
|
321
|
+
const place = Math.min(raw.place, base.place, step.place, min.place, max.place);
|
|
322
|
+
const units = (part) => part.units * 10n ** BigInt(part.place - place);
|
|
323
|
+
const origin = units(base);
|
|
324
|
+
const stride = units(step);
|
|
325
|
+
const rawUnits = units(raw);
|
|
326
|
+
const remainder = (rawUnits - origin) % stride;
|
|
327
|
+
const below = rawUnits - (remainder < 0n ? remainder + stride : remainder);
|
|
328
|
+
const above = below + stride;
|
|
329
|
+
const minUnits = units(min);
|
|
330
|
+
const maxUnits = units(max);
|
|
331
|
+
const lowerUnits = lower === range.min && minUnits > below ? minUnits : below;
|
|
332
|
+
const upperUnits = upper === range.max && maxUnits < above ? maxUnits : above;
|
|
333
|
+
return Number(`${lowerUnits}e${place}`) === lower && Number(`${upperUnits}e${place}`) === upper && Number(`${(lowerUnits + upperUnits) * 5n}e${place - 1}`) === value;
|
|
317
334
|
}
|
|
318
|
-
function
|
|
319
|
-
const
|
|
320
|
-
|
|
335
|
+
function decimalParts(value) {
|
|
336
|
+
const [coefficient = "", exponent = "0"] = value.toString().split("e");
|
|
337
|
+
const [whole = "", fraction = ""] = coefficient.split(".");
|
|
338
|
+
return { units: BigInt(whole + fraction), place: Number(exponent) - fraction.length };
|
|
321
339
|
}
|
|
322
340
|
function finiteFallback(min, max) {
|
|
323
341
|
if (Number.isFinite(min)) return min;
|
|
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
var ListenerSet = class {
|
|
@@ -7,14 +7,15 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
@@ -215,7 +216,7 @@ var DetachGate = class _DetachGate {
|
|
|
215
216
|
|
|
216
217
|
var MinDurationFloor = class {
|
|
217
218
|
#timers;
|
|
218
|
-
#
|
|
219
|
+
#task = null;
|
|
219
220
|
#since = 0;
|
|
220
221
|
constructor(timers) {
|
|
221
222
|
this.#timers = timers;
|
|
@@ -224,25 +225,19 @@ var MinDurationFloor = class {
|
|
|
224
225
|
this.#since = Date.now();
|
|
225
226
|
}
|
|
226
227
|
get pending() {
|
|
227
|
-
return this.#
|
|
228
|
+
return this.#task?.pending ?? false;
|
|
228
229
|
}
|
|
229
230
|
schedule(minDuration, finish) {
|
|
230
231
|
this.cancel();
|
|
231
232
|
const remaining = minDuration - (Date.now() - this.#since);
|
|
232
233
|
if (remaining > 0) {
|
|
233
|
-
this.#
|
|
234
|
-
this.#timerId = null;
|
|
235
|
-
finish();
|
|
236
|
-
}, remaining);
|
|
234
|
+
this.#task = this.#timers.setTask(finish, remaining);
|
|
237
235
|
} else {
|
|
238
236
|
finish();
|
|
239
237
|
}
|
|
240
238
|
}
|
|
241
239
|
cancel() {
|
|
242
|
-
|
|
243
|
-
this.#timers.clear(this.#timerId);
|
|
244
|
-
this.#timerId = null;
|
|
245
|
-
}
|
|
240
|
+
this.#task?.cancel();
|
|
246
241
|
}
|
|
247
242
|
};
|
|
248
243
|
|
|
@@ -309,6 +304,22 @@ var TimerRegistry = class {
|
|
|
309
304
|
return this.ids.size;
|
|
310
305
|
}
|
|
311
306
|
};
|
|
307
|
+
var TimeoutRegistration = class {
|
|
308
|
+
#registration;
|
|
309
|
+
constructor(owner, id) {
|
|
310
|
+
this.#registration = { owner, id };
|
|
311
|
+
}
|
|
312
|
+
get pending() {
|
|
313
|
+
return this.#registration !== null;
|
|
314
|
+
}
|
|
315
|
+
cancel() {
|
|
316
|
+
const registration = this.#registration;
|
|
317
|
+
if (registration) registration.owner.clear(registration.id);
|
|
318
|
+
}
|
|
319
|
+
expire() {
|
|
320
|
+
this.#registration = null;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
312
323
|
var SafeTimeout = class extends TimerRegistry {
|
|
313
324
|
set(callback, delay) {
|
|
314
325
|
const id = this.schedule(() => {
|
|
@@ -325,6 +336,29 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
325
336
|
window.clearTimeout(id);
|
|
326
337
|
}
|
|
327
338
|
};
|
|
339
|
+
var TaskTimeout = class extends SafeTimeout {
|
|
340
|
+
#tasks = /* @__PURE__ */ new Map();
|
|
341
|
+
setTask(callback, delay) {
|
|
342
|
+
const id = this.set(() => {
|
|
343
|
+
this.#tasks.delete(id);
|
|
344
|
+
registration.expire();
|
|
345
|
+
callback();
|
|
346
|
+
}, delay);
|
|
347
|
+
const registration = new TimeoutRegistration(this, id);
|
|
348
|
+
this.#tasks.set(id, registration);
|
|
349
|
+
return registration;
|
|
350
|
+
}
|
|
351
|
+
clear(id) {
|
|
352
|
+
this.#tasks.get(id)?.expire();
|
|
353
|
+
this.#tasks.delete(id);
|
|
354
|
+
super.clear(id);
|
|
355
|
+
}
|
|
356
|
+
clearAll() {
|
|
357
|
+
for (const registration of this.#tasks.values()) registration.expire();
|
|
358
|
+
this.#tasks.clear();
|
|
359
|
+
super.clearAll();
|
|
360
|
+
}
|
|
361
|
+
};
|
|
328
362
|
|
|
329
363
|
var SpinnerController = class _SpinnerController extends Controller {
|
|
330
364
|
#numbers = new NumberValueReader();
|
|
@@ -343,7 +377,7 @@ var SpinnerController = class _SpinnerController extends Controller {
|
|
|
343
377
|
};
|
|
344
378
|
static actions = ["start", "stop"];
|
|
345
379
|
static events = ["hide", "show", "timeout", "reconcile"];
|
|
346
|
-
#timers = new
|
|
380
|
+
#timers = new TaskTimeout();
|
|
347
381
|
#floor = new MinDurationFloor(this.#timers);
|
|
348
382
|
#gate = new DetachGate();
|
|
349
383
|
#busyLease = new AttributeLease("aria-busy", this.identifier);
|
|
@@ -173,70 +173,102 @@ function queryRoot(selector) {
|
|
|
173
173
|
}
|
|
174
174
|
var IntersectionWatcher = class {
|
|
175
175
|
#onEntries;
|
|
176
|
-
#
|
|
177
|
-
#active = false;
|
|
178
|
-
#usingPlatformDefaults = false;
|
|
176
|
+
#session = null;
|
|
179
177
|
constructor(onEntries) {
|
|
180
178
|
this.#onEntries = onEntries;
|
|
181
179
|
}
|
|
182
180
|
get active() {
|
|
183
|
-
return this.#active;
|
|
181
|
+
return this.#session?.active ?? false;
|
|
184
182
|
}
|
|
185
183
|
get usingPlatformDefaults() {
|
|
186
|
-
return this.#usingPlatformDefaults;
|
|
184
|
+
return this.#session?.usingPlatformDefaults ?? false;
|
|
187
185
|
}
|
|
188
186
|
start(targets, options = {}) {
|
|
189
|
-
this
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
const previous = this.#session;
|
|
188
|
+
const session = {
|
|
189
|
+
observer: null,
|
|
190
|
+
active: false,
|
|
191
|
+
usingPlatformDefaults: false
|
|
192
|
+
};
|
|
193
|
+
this.#session = session;
|
|
194
194
|
let observer = null;
|
|
195
195
|
try {
|
|
196
|
+
if (previous) this.#release(previous);
|
|
197
|
+
if (this.#session !== session) return false;
|
|
198
|
+
if (typeof IntersectionObserver === "undefined") return false;
|
|
199
|
+
const list = Array.isArray(targets) ? targets : [targets];
|
|
200
|
+
const empty = list.length === 0;
|
|
201
|
+
if (this.#session !== session) return false;
|
|
202
|
+
if (empty) return false;
|
|
203
|
+
const root = "root" in options ? options.root ?? null : queryRoot(options.rootSelector);
|
|
204
|
+
if (this.#session !== session) return false;
|
|
196
205
|
const onEntries = (entries) => {
|
|
197
|
-
if (this.#
|
|
206
|
+
if (this.#session === session && session.active) this.#onEntries(entries);
|
|
198
207
|
};
|
|
208
|
+
let usingPlatformDefaults = false;
|
|
199
209
|
try {
|
|
200
|
-
|
|
210
|
+
const configured = {
|
|
201
211
|
root,
|
|
202
212
|
rootMargin: options.rootMargin,
|
|
203
213
|
threshold: options.threshold
|
|
204
|
-
}
|
|
214
|
+
};
|
|
215
|
+
if (this.#session !== session) return false;
|
|
216
|
+
observer = new IntersectionObserver(onEntries, configured);
|
|
205
217
|
} catch (error) {
|
|
218
|
+
if (this.#session !== session) return false;
|
|
206
219
|
console.warn(
|
|
207
220
|
"Stimeo UI: IntersectionObserver could not be constructed with the configured options; retrying with platform defaults.",
|
|
208
221
|
error
|
|
209
222
|
);
|
|
223
|
+
if (this.#session !== session) return false;
|
|
210
224
|
observer = new IntersectionObserver(onEntries, { root });
|
|
211
|
-
|
|
225
|
+
usingPlatformDefaults = true;
|
|
226
|
+
}
|
|
227
|
+
if (this.#session !== session) {
|
|
228
|
+
this.#release(session, observer);
|
|
229
|
+
return false;
|
|
212
230
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
231
|
+
session.observer = observer;
|
|
232
|
+
for (const target of list) {
|
|
233
|
+
if (this.#session !== session) return false;
|
|
234
|
+
observer.observe(target);
|
|
235
|
+
if (this.#session !== session) {
|
|
236
|
+
this.#release(session, observer);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (this.#session !== session) return false;
|
|
241
|
+
session.usingPlatformDefaults = usingPlatformDefaults;
|
|
242
|
+
session.active = true;
|
|
216
243
|
return true;
|
|
217
244
|
} catch (error) {
|
|
218
|
-
observer
|
|
219
|
-
this.#observer = null;
|
|
220
|
-
this.#active = false;
|
|
221
|
-
this.#usingPlatformDefaults = false;
|
|
245
|
+
this.#release(session, observer);
|
|
222
246
|
throw error;
|
|
223
247
|
}
|
|
224
248
|
}
|
|
225
249
|
rearm(target) {
|
|
226
|
-
|
|
250
|
+
const session = this.#session;
|
|
251
|
+
const observer = session?.observer;
|
|
252
|
+
if (!session?.active || !observer) return;
|
|
227
253
|
try {
|
|
228
|
-
|
|
229
|
-
this.#
|
|
254
|
+
observer.unobserve(target);
|
|
255
|
+
if (this.#session !== session) return;
|
|
256
|
+
observer.observe(target);
|
|
257
|
+
if (this.#session !== session) this.#release(session, observer);
|
|
230
258
|
} catch (error) {
|
|
231
|
-
this
|
|
259
|
+
if (this.#session === session) this.#session = null;
|
|
260
|
+
this.#release(session, observer);
|
|
232
261
|
throw error;
|
|
233
262
|
}
|
|
234
263
|
}
|
|
235
264
|
stop() {
|
|
236
|
-
|
|
237
|
-
this.#
|
|
238
|
-
this.#
|
|
239
|
-
|
|
265
|
+
const session = this.#session;
|
|
266
|
+
this.#session = null;
|
|
267
|
+
if (session) this.#release(session);
|
|
268
|
+
}
|
|
269
|
+
#release(session, observer = session.observer) {
|
|
270
|
+
session.observer = null;
|
|
271
|
+
observer?.disconnect();
|
|
240
272
|
}
|
|
241
273
|
};
|
|
242
274
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
3
4
|
function announce(message, options = {}) {
|
|
4
5
|
const text = message.trim();
|
|
5
6
|
if (text.length === 0) return;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
);
|
|
7
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
8
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
9
|
+
});
|
|
10
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
11
|
+
window.dispatchEvent(event);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
@@ -10,43 +10,66 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
|
10
10
|
|
|
11
11
|
var AuthoredMutationWatcher = class {
|
|
12
12
|
#onAuthored;
|
|
13
|
-
#
|
|
14
|
-
#observer = null;
|
|
13
|
+
#lifetime = null;
|
|
15
14
|
constructor(onAuthored) {
|
|
16
15
|
this.#onAuthored = onAuthored;
|
|
17
16
|
}
|
|
18
17
|
observe(root, options) {
|
|
19
|
-
this
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
this.#
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
const previous = this.#lifetime;
|
|
19
|
+
const lifetime = {
|
|
20
|
+
observer: null,
|
|
21
|
+
active: false,
|
|
22
|
+
claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
|
|
23
|
+
};
|
|
24
|
+
this.#lifetime = lifetime;
|
|
25
|
+
let observer = null;
|
|
26
|
+
try {
|
|
27
|
+
if (previous) this.#release(previous);
|
|
28
|
+
if (this.#lifetime !== lifetime) return;
|
|
29
|
+
const attributes = [...options.attributes];
|
|
30
|
+
const subtree = options.subtree ?? false;
|
|
31
|
+
const childList = options.childList ?? false;
|
|
32
|
+
const inherited = options.ancestorAttributes;
|
|
33
|
+
const ancestorAttributes = inherited ? [...inherited] : null;
|
|
34
|
+
if (this.#lifetime !== lifetime) return;
|
|
35
|
+
observer = new MutationObserver((records) => {
|
|
36
|
+
const authored = this.#filter(records, lifetime.claims);
|
|
37
|
+
if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
|
|
38
|
+
this.#onAuthored(authored);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (this.#lifetime !== lifetime) return;
|
|
42
|
+
lifetime.observer = observer;
|
|
43
|
+
observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
|
|
44
|
+
if (this.#lifetime !== lifetime) {
|
|
45
|
+
this.#release(lifetime, observer);
|
|
46
|
+
return;
|
|
41
47
|
}
|
|
48
|
+
if (ancestorAttributes) {
|
|
49
|
+
let ancestor = root.parentElement;
|
|
50
|
+
while (ancestor) {
|
|
51
|
+
observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
|
|
52
|
+
if (this.#lifetime !== lifetime) {
|
|
53
|
+
this.#release(lifetime, observer);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
ancestor = ancestor.parentElement;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
lifetime.active = true;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
this.#release(lifetime, observer);
|
|
62
|
+
throw error;
|
|
42
63
|
}
|
|
43
64
|
}
|
|
44
65
|
claim(target, name, value) {
|
|
45
|
-
const
|
|
46
|
-
|
|
66
|
+
const lifetime = this.#lifetime;
|
|
67
|
+
if (!lifetime?.active) return;
|
|
68
|
+
const claims = lifetime.claims.attributes;
|
|
69
|
+
let attributes = claims.get(target);
|
|
47
70
|
if (!attributes) {
|
|
48
71
|
attributes = /* @__PURE__ */ new Map();
|
|
49
|
-
claims
|
|
72
|
+
claims.set(target, attributes);
|
|
50
73
|
}
|
|
51
74
|
const pending = attributes.get(name);
|
|
52
75
|
attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
|
|
@@ -55,37 +78,49 @@ var AuthoredMutationWatcher = class {
|
|
|
55
78
|
this.claim(target, name, target.getAttribute(name));
|
|
56
79
|
}
|
|
57
80
|
claimChildList(target, added, removed) {
|
|
58
|
-
const
|
|
59
|
-
|
|
81
|
+
const lifetime = this.#lifetime;
|
|
82
|
+
if (!lifetime?.active) return;
|
|
83
|
+
const claims = lifetime.claims.children;
|
|
84
|
+
const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
|
|
60
85
|
for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
|
|
61
86
|
for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
|
|
62
|
-
claims
|
|
87
|
+
claims.set(target, pending);
|
|
63
88
|
}
|
|
64
89
|
take() {
|
|
65
|
-
|
|
90
|
+
const lifetime = this.#lifetime;
|
|
91
|
+
const observer = lifetime?.observer;
|
|
92
|
+
if (!lifetime?.active || !observer) return [];
|
|
93
|
+
const records = observer.takeRecords();
|
|
94
|
+
const authored = this.#filter(records, lifetime.claims);
|
|
95
|
+
return this.#lifetime === lifetime && lifetime.active ? authored : [];
|
|
66
96
|
}
|
|
67
97
|
disconnect() {
|
|
68
|
-
this.#
|
|
69
|
-
this.#
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
const lifetime = this.#lifetime;
|
|
99
|
+
if (lifetime) this.#release(lifetime);
|
|
100
|
+
}
|
|
101
|
+
#release(lifetime, observer = lifetime.observer) {
|
|
102
|
+
if (this.#lifetime === lifetime) this.#lifetime = null;
|
|
103
|
+
lifetime.claims.attributes.clear();
|
|
104
|
+
lifetime.claims.children.clear();
|
|
105
|
+
observer?.disconnect();
|
|
106
|
+
}
|
|
107
|
+
#filter(records, claims) {
|
|
108
|
+
const authored = records.filter((record) => !this.#consume(record, claims));
|
|
109
|
+
claims.attributes.clear();
|
|
110
|
+
claims.children.clear();
|
|
76
111
|
return authored;
|
|
77
112
|
}
|
|
78
|
-
#consume(record) {
|
|
113
|
+
#consume(record, claims) {
|
|
79
114
|
if (record.type === "attributes") {
|
|
80
115
|
const target = record.target;
|
|
81
|
-
const pending2 =
|
|
116
|
+
const pending2 = claims.attributes.get(target)?.get(record.attributeName);
|
|
82
117
|
if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
|
|
83
118
|
return false;
|
|
84
119
|
}
|
|
85
120
|
pending2.count -= 1;
|
|
86
121
|
return true;
|
|
87
122
|
}
|
|
88
|
-
const pending =
|
|
123
|
+
const pending = claims.children.get(record.target);
|
|
89
124
|
if (!pending) return false;
|
|
90
125
|
const added = [...record.addedNodes];
|
|
91
126
|
const removed = [...record.removedNodes];
|
|
@@ -113,11 +148,16 @@ function commitField(target) {
|
|
|
113
148
|
target.dispatchEvent(new Event("change", { bubbles: true }));
|
|
114
149
|
}
|
|
115
150
|
|
|
151
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
116
152
|
function inheritsFieldsetDisabled(control) {
|
|
117
153
|
let fieldset = control.closest("fieldset[disabled]");
|
|
118
154
|
while (fieldset) {
|
|
119
|
-
|
|
120
|
-
|
|
155
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
156
|
+
const legend = Array.from(fieldset.children).find(
|
|
157
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
158
|
+
);
|
|
159
|
+
if (!legend?.contains(control)) return true;
|
|
160
|
+
}
|
|
121
161
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
122
162
|
}
|
|
123
163
|
return false;
|