stimeo-ui 0.18.1 → 0.19.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 +54 -0
- data/dist/cable/index.js +6 -5
- data/dist/controllers/alert_dialog_controller.js +324 -76
- data/dist/controllers/announcer_controller.js +22 -9
- data/dist/controllers/auto_submit_controller.js +103 -16
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +31 -13
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +103 -16
- data/dist/controllers/clipboard_controller.js +6 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +155 -26
- data/dist/controllers/command_palette_controller.js +445 -117
- data/dist/controllers/conditional_fields_controller.js +84 -44
- data/dist/controllers/confirm_controller.js +303 -68
- data/dist/controllers/context_menu_controller.js +59 -30
- data/dist/controllers/countdown_controller.js +6 -5
- data/dist/controllers/currency_input_controller.js +72 -7
- data/dist/controllers/data_grid_controller.js +273 -51
- data/dist/controllers/date_range_picker_controller.js +27 -5
- data/dist/controllers/dialog_controller.js +330 -79
- data/dist/controllers/direct_upload_controller.js +6 -5
- data/dist/controllers/dismissible_controller.js +68 -18
- data/dist/controllers/drawer_controller.js +362 -92
- data/dist/controllers/dropdown_controller.js +64 -52
- data/dist/controllers/editable_controller.js +140 -12
- data/dist/controllers/empty_state_controller.js +193 -9
- data/dist/controllers/file_dropzone_controller.js +313 -23
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +205 -17
- data/dist/controllers/focus_controller.js +273 -57
- data/dist/controllers/form_field_controller.js +71 -14
- data/dist/controllers/form_validation_controller.js +11 -7
- data/dist/controllers/frame_loading_controller.js +75 -20
- data/dist/controllers/hover_card_controller.js +108 -39
- data/dist/controllers/input_mask_controller.js +95 -37
- data/dist/controllers/intersection_controller.js +61 -29
- data/dist/controllers/lazy_frame_controller.js +61 -29
- data/dist/controllers/listbox_controller.js +174 -83
- data/dist/controllers/local_time_controller.js +1 -7
- data/dist/controllers/menu_controller.js +45 -24
- data/dist/controllers/menubar_controller.js +232 -52
- data/dist/controllers/meter_controller.js +31 -9
- data/dist/controllers/multi_select_controller.js +195 -62
- data/dist/controllers/navigation_menu_controller.js +1 -1
- data/dist/controllers/nested_form_controller.js +275 -21
- data/dist/controllers/network_status_controller.js +31 -9
- data/dist/controllers/number_input_controller.js +180 -71
- data/dist/controllers/otp_controller.js +97 -11
- data/dist/controllers/overflow_menu_controller.js +190 -24
- data/dist/controllers/pagination_controller.js +186 -24
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/password_strength_controller.js +6 -5
- data/dist/controllers/popover_controller.js +466 -42
- data/dist/controllers/progress_controller.js +31 -9
- data/dist/controllers/radio_group_controller.js +279 -88
- data/dist/controllers/range_slider_controller.js +72 -54
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/relative_time_controller.js +1 -7
- data/dist/controllers/roving_controller.js +204 -8
- data/dist/controllers/scroll_area_controller.js +61 -19
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +240 -32
- data/dist/controllers/separator_controller.js +97 -58
- data/dist/controllers/sidebar_controller.js +368 -127
- data/dist/controllers/skeleton_controller.js +75 -20
- data/dist/controllers/slider_controller.js +72 -54
- data/dist/controllers/sortable_controller.js +6 -5
- data/dist/controllers/spinner_controller.js +75 -20
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +86 -33
- data/dist/controllers/submit_once_controller.js +31 -9
- data/dist/controllers/switch_controller.js +84 -44
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +293 -29
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/time_picker_controller.js +77 -42
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +282 -79
- data/dist/controllers/toolbar_controller.js +276 -15
- data/dist/controllers/tooltip_controller.js +244 -46
- data/dist/controllers/tree_view_controller.js +287 -57
- data/dist/index.js +2258 -1016
- 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;
|
|
@@ -36,6 +36,7 @@ function hasModifierChord(event) {
|
|
|
36
36
|
|
|
37
37
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
38
38
|
if (element.getAttribute(name) === value) return false;
|
|
39
|
+
beforeWrite?.();
|
|
39
40
|
if (value === null) element.removeAttribute(name);
|
|
40
41
|
else element.setAttribute(name, value);
|
|
41
42
|
return true;
|
|
@@ -109,14 +110,34 @@ var AttributeLease = class {
|
|
|
109
110
|
const names = registry.names;
|
|
110
111
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
111
112
|
}
|
|
112
|
-
write(element, value) {
|
|
113
|
+
write(element, value, beforeWrite) {
|
|
113
114
|
const stack = attributeStack(element, this.#attribute);
|
|
114
115
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
115
116
|
this.#held.add(element);
|
|
116
117
|
const shows = !this.#covered(element, stack, hold);
|
|
117
118
|
hold.written = value;
|
|
118
119
|
this.#mark(element, stack);
|
|
119
|
-
if (shows) this.#reflect(element, value);
|
|
120
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
121
|
+
}
|
|
122
|
+
adopt(element, options = {}) {
|
|
123
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
124
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
125
|
+
const stack = attributeStack(element, this.#attribute);
|
|
126
|
+
const hold = this.#take(stack);
|
|
127
|
+
if (!hold) return false;
|
|
128
|
+
const current = element.getAttribute(this.#attribute);
|
|
129
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
this.#held.add(element);
|
|
133
|
+
hold.original = current;
|
|
134
|
+
hold.linked = false;
|
|
135
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
136
|
+
if (!above.linked) break;
|
|
137
|
+
above.original = current;
|
|
138
|
+
}
|
|
139
|
+
this.#mark(element, stack);
|
|
140
|
+
return true;
|
|
120
141
|
}
|
|
121
142
|
return(element) {
|
|
122
143
|
const held = this.#held.delete(element);
|
|
@@ -182,8 +203,8 @@ var AttributeLease = class {
|
|
|
182
203
|
setAttributeIfChanged(element, name, recorded);
|
|
183
204
|
}
|
|
184
205
|
}
|
|
185
|
-
#reflect(element, value) {
|
|
186
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
206
|
+
#reflect(element, value, beforeWrite) {
|
|
207
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
187
208
|
}
|
|
188
209
|
};
|
|
189
210
|
|
|
@@ -323,8 +344,12 @@ var NumberValueReader = class {
|
|
|
323
344
|
|
|
324
345
|
var RovingTabindex = class {
|
|
325
346
|
#getItems;
|
|
326
|
-
|
|
347
|
+
#write;
|
|
348
|
+
constructor(getItems, write = (item, tabindex) => {
|
|
349
|
+
item.tabIndex = tabindex;
|
|
350
|
+
}) {
|
|
327
351
|
this.#getItems = getItems;
|
|
352
|
+
this.#write = write;
|
|
328
353
|
}
|
|
329
354
|
get activeIndex() {
|
|
330
355
|
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
@@ -333,7 +358,7 @@ var RovingTabindex = class {
|
|
|
333
358
|
const { focus = false } = options;
|
|
334
359
|
const items = options.items ?? this.#getItems();
|
|
335
360
|
items.forEach((item, i) => {
|
|
336
|
-
item
|
|
361
|
+
this.#write(item, i === index ? 0 : -1);
|
|
337
362
|
});
|
|
338
363
|
if (focus) items[index]?.focus();
|
|
339
364
|
}
|
|
@@ -483,7 +508,13 @@ var RatingController = class _RatingController extends Controller {
|
|
|
483
508
|
};
|
|
484
509
|
static actions = ["endPreview", "onKeydown", "preview", "select"];
|
|
485
510
|
static events = ["change", "reconcile"];
|
|
486
|
-
#
|
|
511
|
+
#checked = new AttributeLease("aria-checked", this.identifier);
|
|
512
|
+
#tabindex = new AttributeLease("tabindex", this.identifier);
|
|
513
|
+
#managedSymbols = /* @__PURE__ */ new Set();
|
|
514
|
+
#roving = new RovingTabindex(
|
|
515
|
+
() => this.symbolTargets,
|
|
516
|
+
(symbol, tabindex) => this.#tabindex.write(symbol, String(tabindex))
|
|
517
|
+
);
|
|
487
518
|
#rootRole = new AttributeLease("role", this.identifier);
|
|
488
519
|
#symbolRole = new AttributeLease("role", this.identifier);
|
|
489
520
|
#symbolAriaHidden = new AttributeLease("aria-hidden", this.identifier);
|
|
@@ -493,6 +524,10 @@ var RatingController = class _RatingController extends Controller {
|
|
|
493
524
|
#rescuedFocus = false;
|
|
494
525
|
#shown = 0;
|
|
495
526
|
connect() {
|
|
527
|
+
const current = new Set(this.symbolTargets);
|
|
528
|
+
for (const symbol of this.#managedSymbols) {
|
|
529
|
+
if (!current.has(symbol)) this.#releaseSymbol(symbol);
|
|
530
|
+
}
|
|
496
531
|
this.#rootTabindex.reclaim(this.element);
|
|
497
532
|
this.#repaint.observe(this.element);
|
|
498
533
|
this.#shown = this.#normalize(this.#safeValue);
|
|
@@ -506,13 +541,25 @@ var RatingController = class _RatingController extends Controller {
|
|
|
506
541
|
}
|
|
507
542
|
symbolTargetConnected(symbol) {
|
|
508
543
|
if (this.#connected === false) return;
|
|
509
|
-
symbol
|
|
544
|
+
if (!this.#managedSymbols.has(symbol)) {
|
|
545
|
+
this.#managedSymbols.add(symbol);
|
|
546
|
+
this.#tabindex.write(symbol, "-1");
|
|
547
|
+
}
|
|
510
548
|
this.#repaint.schedule();
|
|
511
549
|
}
|
|
512
550
|
symbolTargetDisconnected(symbol) {
|
|
551
|
+
if (!this.scope.containsElement(symbol) || !this.symbolTargets.includes(symbol)) {
|
|
552
|
+
this.#releaseSymbol(symbol);
|
|
553
|
+
}
|
|
554
|
+
this.#repaint.schedule();
|
|
555
|
+
}
|
|
556
|
+
#releaseSymbol(symbol) {
|
|
557
|
+
this.#managedSymbols.delete(symbol);
|
|
558
|
+
this.#checked.return(symbol);
|
|
559
|
+
this.#tabindex.return(symbol);
|
|
513
560
|
this.#symbolRole.return(symbol);
|
|
514
561
|
this.#symbolAriaHidden.return(symbol);
|
|
515
|
-
|
|
562
|
+
symbol.removeAttribute("data-rating-hover");
|
|
516
563
|
}
|
|
517
564
|
fieldTargetConnected() {
|
|
518
565
|
this.#repaint.schedule();
|
|
@@ -624,7 +671,8 @@ var RatingController = class _RatingController extends Controller {
|
|
|
624
671
|
#apply(value, { focus }) {
|
|
625
672
|
const move = this.#move;
|
|
626
673
|
this.symbolTargets.forEach((symbol, index) => {
|
|
627
|
-
|
|
674
|
+
this.#managedSymbols.add(symbol);
|
|
675
|
+
this.#checked.write(symbol, value > 0 && index + 1 === value ? "true" : "false");
|
|
628
676
|
});
|
|
629
677
|
const field = this.hasFieldTarget ? this.fieldTarget : null;
|
|
630
678
|
const moved = field && writeField(field, String(value));
|
|
@@ -1,5 +1,179 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
4
|
+
if (element.getAttribute(name) === value) return false;
|
|
5
|
+
beforeWrite?.();
|
|
6
|
+
if (value === null) element.removeAttribute(name);
|
|
7
|
+
else element.setAttribute(name, value);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function sharedRegistry(key, create) {
|
|
12
|
+
const symbol = Symbol.for(key);
|
|
13
|
+
const scope = globalThis;
|
|
14
|
+
const existing = scope[symbol];
|
|
15
|
+
if (existing !== void 0) return existing;
|
|
16
|
+
const registry2 = create();
|
|
17
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
18
|
+
return registry2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var registry = sharedRegistry(
|
|
22
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
23
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
24
|
+
);
|
|
25
|
+
function isAttributeValue(value) {
|
|
26
|
+
return value === null || typeof value === "string";
|
|
27
|
+
}
|
|
28
|
+
function readLeaseRecord(element, record) {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
31
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
32
|
+
const [original, written, ...rest] = parsed;
|
|
33
|
+
const linked = rest[0] !== false;
|
|
34
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
35
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
36
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
37
|
+
} catch {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function attributeStack(element, attribute) {
|
|
42
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
43
|
+
registry.stacks.set(element, byAttribute);
|
|
44
|
+
const known = byAttribute.get(attribute);
|
|
45
|
+
if (known) return known;
|
|
46
|
+
const found = [];
|
|
47
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
48
|
+
const read = readLeaseRecord(element, record);
|
|
49
|
+
if (read) found.push({ ...read, record });
|
|
50
|
+
}
|
|
51
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
52
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
53
|
+
lease: null,
|
|
54
|
+
record,
|
|
55
|
+
written,
|
|
56
|
+
original,
|
|
57
|
+
linked: linked && index > 0
|
|
58
|
+
}));
|
|
59
|
+
byAttribute.set(attribute, stack);
|
|
60
|
+
return stack;
|
|
61
|
+
}
|
|
62
|
+
function findHold(stack, lease, record) {
|
|
63
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
64
|
+
}
|
|
65
|
+
var AttributeLease = class {
|
|
66
|
+
#attribute;
|
|
67
|
+
#record;
|
|
68
|
+
#base;
|
|
69
|
+
#preserveAuthor;
|
|
70
|
+
#held = /* @__PURE__ */ new Set();
|
|
71
|
+
constructor(attribute, owner, options = {}) {
|
|
72
|
+
this.#attribute = attribute;
|
|
73
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
74
|
+
this.#base = options.base === true;
|
|
75
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
76
|
+
const names = registry.names;
|
|
77
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
78
|
+
}
|
|
79
|
+
write(element, value, beforeWrite) {
|
|
80
|
+
const stack = attributeStack(element, this.#attribute);
|
|
81
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
82
|
+
this.#held.add(element);
|
|
83
|
+
const shows = !this.#covered(element, stack, hold);
|
|
84
|
+
hold.written = value;
|
|
85
|
+
this.#mark(element, stack);
|
|
86
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
87
|
+
}
|
|
88
|
+
adopt(element, options = {}) {
|
|
89
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
90
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
91
|
+
const stack = attributeStack(element, this.#attribute);
|
|
92
|
+
const hold = this.#take(stack);
|
|
93
|
+
if (!hold) return false;
|
|
94
|
+
const current = element.getAttribute(this.#attribute);
|
|
95
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
this.#held.add(element);
|
|
99
|
+
hold.original = current;
|
|
100
|
+
hold.linked = false;
|
|
101
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
102
|
+
if (!above.linked) break;
|
|
103
|
+
above.original = current;
|
|
104
|
+
}
|
|
105
|
+
this.#mark(element, stack);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return(element) {
|
|
109
|
+
const held = this.#held.delete(element);
|
|
110
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
111
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
112
|
+
const hold = this.#take(stack);
|
|
113
|
+
if (!hold) return false;
|
|
114
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
115
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
116
|
+
const index = stack.indexOf(hold);
|
|
117
|
+
stack.splice(index, 1);
|
|
118
|
+
const above = stack[index];
|
|
119
|
+
if (above) above.linked &&= hold.linked;
|
|
120
|
+
this.#mark(element, stack);
|
|
121
|
+
if (!owns) return true;
|
|
122
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
123
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
returnAll() {
|
|
127
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
128
|
+
}
|
|
129
|
+
#take(stack) {
|
|
130
|
+
const hold = findHold(stack, this, this.#record);
|
|
131
|
+
if (hold) hold.lease = this;
|
|
132
|
+
return hold;
|
|
133
|
+
}
|
|
134
|
+
#acquire(element, stack) {
|
|
135
|
+
const current = element.getAttribute(this.#attribute);
|
|
136
|
+
const top = stack.at(-1);
|
|
137
|
+
const bottom = stack[0];
|
|
138
|
+
const over = top?.written === current ? top : void 0;
|
|
139
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
140
|
+
const hold = {
|
|
141
|
+
lease: this,
|
|
142
|
+
record: this.#record,
|
|
143
|
+
written: current,
|
|
144
|
+
original: from ? from.original : current,
|
|
145
|
+
linked: !this.#base && over !== void 0
|
|
146
|
+
};
|
|
147
|
+
if (this.#base && bottom) {
|
|
148
|
+
bottom.linked = true;
|
|
149
|
+
stack.unshift(hold);
|
|
150
|
+
} else stack.push(hold);
|
|
151
|
+
return hold;
|
|
152
|
+
}
|
|
153
|
+
#covered(element, stack, hold) {
|
|
154
|
+
const current = element.getAttribute(this.#attribute);
|
|
155
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
156
|
+
}
|
|
157
|
+
#mark(element, stack) {
|
|
158
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
159
|
+
stack.forEach((hold, index) => {
|
|
160
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
161
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
162
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
163
|
+
records.set(
|
|
164
|
+
hold.record,
|
|
165
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
for (const [name, recorded] of records) {
|
|
169
|
+
setAttributeIfChanged(element, name, recorded);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
#reflect(element, value, beforeWrite) {
|
|
173
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
3
177
|
var BlurDeferral = class {
|
|
4
178
|
#pending = /* @__PURE__ */ new Map();
|
|
5
179
|
#onRelease;
|
|
@@ -107,23 +281,6 @@ function stateReasonFor(event) {
|
|
|
107
281
|
return "user";
|
|
108
282
|
}
|
|
109
283
|
|
|
110
|
-
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
111
|
-
if (element.getAttribute(name) === value) return false;
|
|
112
|
-
if (value === null) element.removeAttribute(name);
|
|
113
|
-
else element.setAttribute(name, value);
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function sharedRegistry(key, create) {
|
|
118
|
-
const symbol = Symbol.for(key);
|
|
119
|
-
const scope = globalThis;
|
|
120
|
-
const existing = scope[symbol];
|
|
121
|
-
if (existing !== void 0) return existing;
|
|
122
|
-
const registry = create();
|
|
123
|
-
Object.defineProperty(globalThis, symbol, { value: registry });
|
|
124
|
-
return registry;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
284
|
var StateRegions = class _StateRegions {
|
|
128
285
|
static #registry = sharedRegistry(
|
|
129
286
|
"stimeo-ui.state-regions.registry.v1",
|
|
@@ -281,6 +438,9 @@ var ReadMoreController = class extends Controller {
|
|
|
281
438
|
if (this.#connected) this.#evaluateOverflow();
|
|
282
439
|
};
|
|
283
440
|
#layout = new LayoutObserver(this.#update);
|
|
441
|
+
#contentState = new AttributeLease("data-state", this.identifier);
|
|
442
|
+
#triggerState = new AttributeLease("aria-expanded", this.identifier);
|
|
443
|
+
#triggerVisibility = new AttributeLease("hidden", this.identifier);
|
|
284
444
|
#labels = new StateRegions(
|
|
285
445
|
{
|
|
286
446
|
whenTrue: () => this.expandedLabelTargets,
|
|
@@ -304,15 +464,21 @@ var ReadMoreController = class extends Controller {
|
|
|
304
464
|
contentTargetConnected() {
|
|
305
465
|
this.#syncTargets();
|
|
306
466
|
}
|
|
307
|
-
contentTargetDisconnected() {
|
|
467
|
+
contentTargetDisconnected(content) {
|
|
468
|
+
if (!this.scope.containsElement(content) || !this.contentTargets.includes(content))
|
|
469
|
+
this.#contentState.return(content);
|
|
308
470
|
this.#syncTargets();
|
|
309
471
|
}
|
|
310
472
|
triggerTargetConnected() {
|
|
311
473
|
this.#syncTargets();
|
|
312
474
|
}
|
|
313
475
|
triggerTargetDisconnected(trigger) {
|
|
314
|
-
this
|
|
315
|
-
|
|
476
|
+
if (!this.scope.containsElement(trigger) || !this.triggerTargets.includes(trigger)) {
|
|
477
|
+
this.#deferredHide.release(trigger);
|
|
478
|
+
this.#labels.release(trigger);
|
|
479
|
+
this.#triggerState.return(trigger);
|
|
480
|
+
this.#triggerVisibility.return(trigger);
|
|
481
|
+
}
|
|
316
482
|
this.#syncTargets();
|
|
317
483
|
}
|
|
318
484
|
expandedLabelTargetConnected() {
|
|
@@ -340,10 +506,10 @@ var ReadMoreController = class extends Controller {
|
|
|
340
506
|
}
|
|
341
507
|
#reflect() {
|
|
342
508
|
if (this.hasContentTarget) {
|
|
343
|
-
this.contentTarget
|
|
509
|
+
this.#contentState.write(this.contentTarget, this.#collapsed ? "collapsed" : "expanded");
|
|
344
510
|
}
|
|
345
511
|
if (this.hasTriggerTarget) {
|
|
346
|
-
this.triggerTarget
|
|
512
|
+
this.#triggerState.write(this.triggerTarget, this.#collapsed ? "false" : "true");
|
|
347
513
|
this.#labels.reflect(this.triggerTarget, !this.#collapsed);
|
|
348
514
|
}
|
|
349
515
|
}
|
|
@@ -389,16 +555,16 @@ var ReadMoreController = class extends Controller {
|
|
|
389
555
|
const useful = !this.#collapsed || content.scrollHeight > content.clientHeight;
|
|
390
556
|
if (useful) {
|
|
391
557
|
this.#deferredHide.releaseAll();
|
|
392
|
-
trigger
|
|
558
|
+
this.#triggerVisibility.write(trigger, null);
|
|
393
559
|
return;
|
|
394
560
|
}
|
|
395
561
|
if (document.activeElement === trigger) {
|
|
396
|
-
trigger
|
|
562
|
+
this.#triggerVisibility.write(trigger, null);
|
|
397
563
|
this.#deferredHide.deferOnly(trigger);
|
|
398
564
|
return;
|
|
399
565
|
}
|
|
400
566
|
this.#deferredHide.releaseAll();
|
|
401
|
-
trigger
|
|
567
|
+
this.#triggerVisibility.write(trigger, "");
|
|
402
568
|
}
|
|
403
569
|
};
|
|
404
570
|
|
|
@@ -34,13 +34,7 @@ function readDatetime(element) {
|
|
|
34
34
|
const minute = Number(minuteText);
|
|
35
35
|
const second = Number(secondText);
|
|
36
36
|
if (hour === 24 && (minute !== 0 || second !== 0 || /[1-9]/.test(fraction))) return null;
|
|
37
|
-
|
|
38
|
-
if (zone !== "Z") {
|
|
39
|
-
const digits = zone.slice(1).replace(":", "");
|
|
40
|
-
const offsetHour = digits.slice(0, 2);
|
|
41
|
-
const offsetMinute = digits.slice(2);
|
|
42
|
-
offset = `${zone[0]}${offsetHour}:${offsetMinute}`;
|
|
43
|
-
}
|
|
37
|
+
const offset = zone.replace(/^([+-]\d{2})(\d{2})$/, "$1:$2");
|
|
44
38
|
const milliseconds = fraction.slice(0, 3).padEnd(3, "0");
|
|
45
39
|
const canonical = `${yearText}-${monthText}-${dayText}T${hourText}:${minuteText}:${secondText}.${milliseconds}${offset}`;
|
|
46
40
|
const instant = Date.parse(canonical);
|