stimeo-ui 0.18.2 → 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 +33 -0
- data/dist/controllers/alert_dialog_controller.js +246 -42
- data/dist/controllers/auto_submit_controller.js +26 -5
- data/dist/controllers/avatar_controller.js +29 -9
- data/dist/controllers/breadcrumb_controller.js +205 -17
- data/dist/controllers/bulk_select_controller.js +25 -4
- data/dist/controllers/calendar_controller.js +242 -7
- data/dist/controllers/carousel_controller.js +70 -15
- data/dist/controllers/character_counter_controller.js +26 -5
- data/dist/controllers/collapsible_controller.js +35 -8
- data/dist/controllers/combobox_controller.js +84 -20
- data/dist/controllers/command_palette_controller.js +296 -77
- data/dist/controllers/confirm_controller.js +225 -34
- data/dist/controllers/context_menu_controller.js +58 -29
- data/dist/controllers/currency_input_controller.js +1 -1
- data/dist/controllers/data_grid_controller.js +196 -9
- data/dist/controllers/date_range_picker_controller.js +25 -4
- data/dist/controllers/dialog_controller.js +252 -45
- data/dist/controllers/dismissible_controller.js +57 -11
- data/dist/controllers/drawer_controller.js +284 -58
- data/dist/controllers/dropdown_controller.js +63 -51
- data/dist/controllers/editable_controller.js +69 -6
- data/dist/controllers/empty_state_controller.js +187 -4
- data/dist/controllers/file_dropzone_controller.js +300 -12
- data/dist/controllers/filter_controller.js +194 -5
- data/dist/controllers/flash_controller.js +199 -12
- data/dist/controllers/focus_controller.js +195 -23
- data/dist/controllers/form_field_controller.js +65 -9
- data/dist/controllers/frame_loading_controller.js +25 -4
- data/dist/controllers/hover_card_controller.js +107 -38
- data/dist/controllers/input_mask_controller.js +1 -1
- data/dist/controllers/listbox_controller.js +94 -36
- data/dist/controllers/menu_controller.js +44 -23
- data/dist/controllers/menubar_controller.js +228 -46
- data/dist/controllers/meter_controller.js +25 -4
- data/dist/controllers/multi_select_controller.js +110 -42
- data/dist/controllers/nested_form_controller.js +258 -9
- data/dist/controllers/network_status_controller.js +25 -4
- data/dist/controllers/number_input_controller.js +26 -5
- data/dist/controllers/otp_controller.js +26 -5
- data/dist/controllers/overflow_menu_controller.js +183 -22
- data/dist/controllers/pagination_controller.js +179 -22
- data/dist/controllers/password_reveal_controller.js +25 -4
- data/dist/controllers/popover_controller.js +454 -34
- data/dist/controllers/progress_controller.js +25 -4
- data/dist/controllers/radio_group_controller.js +195 -40
- data/dist/controllers/rating_controller.js +58 -10
- data/dist/controllers/read_more_controller.js +191 -25
- data/dist/controllers/roving_controller.js +197 -6
- data/dist/controllers/scroll_area_controller.js +50 -12
- data/dist/controllers/scroll_visibility_controller.js +25 -4
- data/dist/controllers/scrollspy_controller.js +179 -3
- data/dist/controllers/separator_controller.js +25 -4
- data/dist/controllers/sidebar_controller.js +290 -93
- data/dist/controllers/skeleton_controller.js +25 -4
- data/dist/controllers/spinner_controller.js +25 -4
- data/dist/controllers/step_indicator_controller.js +181 -6
- data/dist/controllers/stepper_controller.js +188 -6
- data/dist/controllers/sticky_observer_controller.js +25 -4
- data/dist/controllers/submit_once_controller.js +25 -4
- data/dist/controllers/tabs_controller.js +189 -3
- data/dist/controllers/tags_input_controller.js +210 -9
- data/dist/controllers/theme_controller.js +192 -5
- data/dist/controllers/toast_controller.js +478 -16
- data/dist/controllers/toggle_group_controller.js +198 -35
- data/dist/controllers/toolbar_controller.js +198 -7
- data/dist/controllers/tooltip_controller.js +243 -45
- data/dist/controllers/tree_view_controller.js +200 -8
- data/dist/index.js +1764 -739
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
|
@@ -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
|
|
|
@@ -12,6 +12,180 @@ function hasModifierChord(event) {
|
|
|
12
12
|
return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
16
|
+
if (element.getAttribute(name) === value) return false;
|
|
17
|
+
beforeWrite?.();
|
|
18
|
+
if (value === null) element.removeAttribute(name);
|
|
19
|
+
else element.setAttribute(name, value);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function sharedRegistry(key, create) {
|
|
24
|
+
const symbol = Symbol.for(key);
|
|
25
|
+
const scope = globalThis;
|
|
26
|
+
const existing = scope[symbol];
|
|
27
|
+
if (existing !== void 0) return existing;
|
|
28
|
+
const registry2 = create();
|
|
29
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
30
|
+
return registry2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var registry = sharedRegistry(
|
|
34
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
35
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
36
|
+
);
|
|
37
|
+
function isAttributeValue(value) {
|
|
38
|
+
return value === null || typeof value === "string";
|
|
39
|
+
}
|
|
40
|
+
function readLeaseRecord(element, record) {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
43
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
44
|
+
const [original, written, ...rest] = parsed;
|
|
45
|
+
const linked = rest[0] !== false;
|
|
46
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
47
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
48
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
49
|
+
} catch {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function attributeStack(element, attribute) {
|
|
54
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
55
|
+
registry.stacks.set(element, byAttribute);
|
|
56
|
+
const known = byAttribute.get(attribute);
|
|
57
|
+
if (known) return known;
|
|
58
|
+
const found = [];
|
|
59
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
60
|
+
const read = readLeaseRecord(element, record);
|
|
61
|
+
if (read) found.push({ ...read, record });
|
|
62
|
+
}
|
|
63
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
64
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
65
|
+
lease: null,
|
|
66
|
+
record,
|
|
67
|
+
written,
|
|
68
|
+
original,
|
|
69
|
+
linked: linked && index > 0
|
|
70
|
+
}));
|
|
71
|
+
byAttribute.set(attribute, stack);
|
|
72
|
+
return stack;
|
|
73
|
+
}
|
|
74
|
+
function findHold(stack, lease, record) {
|
|
75
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
76
|
+
}
|
|
77
|
+
var AttributeLease = class {
|
|
78
|
+
#attribute;
|
|
79
|
+
#record;
|
|
80
|
+
#base;
|
|
81
|
+
#preserveAuthor;
|
|
82
|
+
#held = /* @__PURE__ */ new Set();
|
|
83
|
+
constructor(attribute, owner, options = {}) {
|
|
84
|
+
this.#attribute = attribute;
|
|
85
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
86
|
+
this.#base = options.base === true;
|
|
87
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
88
|
+
const names = registry.names;
|
|
89
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
90
|
+
}
|
|
91
|
+
write(element, value, beforeWrite) {
|
|
92
|
+
const stack = attributeStack(element, this.#attribute);
|
|
93
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
94
|
+
this.#held.add(element);
|
|
95
|
+
const shows = !this.#covered(element, stack, hold);
|
|
96
|
+
hold.written = value;
|
|
97
|
+
this.#mark(element, stack);
|
|
98
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
99
|
+
}
|
|
100
|
+
adopt(element, options = {}) {
|
|
101
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
102
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
103
|
+
const stack = attributeStack(element, this.#attribute);
|
|
104
|
+
const hold = this.#take(stack);
|
|
105
|
+
if (!hold) return false;
|
|
106
|
+
const current = element.getAttribute(this.#attribute);
|
|
107
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
this.#held.add(element);
|
|
111
|
+
hold.original = current;
|
|
112
|
+
hold.linked = false;
|
|
113
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
114
|
+
if (!above.linked) break;
|
|
115
|
+
above.original = current;
|
|
116
|
+
}
|
|
117
|
+
this.#mark(element, stack);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return(element) {
|
|
121
|
+
const held = this.#held.delete(element);
|
|
122
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
123
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
124
|
+
const hold = this.#take(stack);
|
|
125
|
+
if (!hold) return false;
|
|
126
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
127
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
128
|
+
const index = stack.indexOf(hold);
|
|
129
|
+
stack.splice(index, 1);
|
|
130
|
+
const above = stack[index];
|
|
131
|
+
if (above) above.linked &&= hold.linked;
|
|
132
|
+
this.#mark(element, stack);
|
|
133
|
+
if (!owns) return true;
|
|
134
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
135
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
returnAll() {
|
|
139
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
140
|
+
}
|
|
141
|
+
#take(stack) {
|
|
142
|
+
const hold = findHold(stack, this, this.#record);
|
|
143
|
+
if (hold) hold.lease = this;
|
|
144
|
+
return hold;
|
|
145
|
+
}
|
|
146
|
+
#acquire(element, stack) {
|
|
147
|
+
const current = element.getAttribute(this.#attribute);
|
|
148
|
+
const top = stack.at(-1);
|
|
149
|
+
const bottom = stack[0];
|
|
150
|
+
const over = top?.written === current ? top : void 0;
|
|
151
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
152
|
+
const hold = {
|
|
153
|
+
lease: this,
|
|
154
|
+
record: this.#record,
|
|
155
|
+
written: current,
|
|
156
|
+
original: from ? from.original : current,
|
|
157
|
+
linked: !this.#base && over !== void 0
|
|
158
|
+
};
|
|
159
|
+
if (this.#base && bottom) {
|
|
160
|
+
bottom.linked = true;
|
|
161
|
+
stack.unshift(hold);
|
|
162
|
+
} else stack.push(hold);
|
|
163
|
+
return hold;
|
|
164
|
+
}
|
|
165
|
+
#covered(element, stack, hold) {
|
|
166
|
+
const current = element.getAttribute(this.#attribute);
|
|
167
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
168
|
+
}
|
|
169
|
+
#mark(element, stack) {
|
|
170
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
171
|
+
stack.forEach((hold, index) => {
|
|
172
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
173
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
174
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
175
|
+
records.set(
|
|
176
|
+
hold.record,
|
|
177
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
for (const [name, recorded] of records) {
|
|
181
|
+
setAttributeIfChanged(element, name, recorded);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
#reflect(element, value, beforeWrite) {
|
|
185
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
15
189
|
function ownerIndex(candidates, node) {
|
|
16
190
|
if (!(node instanceof Node)) return -1;
|
|
17
191
|
return candidates.findIndex((candidate) => candidate.contains(node));
|
|
@@ -104,8 +278,12 @@ var MorphRenderWatcher = class {
|
|
|
104
278
|
|
|
105
279
|
var RovingTabindex = class {
|
|
106
280
|
#getItems;
|
|
107
|
-
|
|
281
|
+
#write;
|
|
282
|
+
constructor(getItems, write = (item, tabindex) => {
|
|
283
|
+
item.tabIndex = tabindex;
|
|
284
|
+
}) {
|
|
108
285
|
this.#getItems = getItems;
|
|
286
|
+
this.#write = write;
|
|
109
287
|
}
|
|
110
288
|
get activeIndex() {
|
|
111
289
|
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
@@ -114,7 +292,7 @@ var RovingTabindex = class {
|
|
|
114
292
|
const { focus = false } = options;
|
|
115
293
|
const items = options.items ?? this.#getItems();
|
|
116
294
|
items.forEach((item, i) => {
|
|
117
|
-
item
|
|
295
|
+
this.#write(item, i === index ? 0 : -1);
|
|
118
296
|
});
|
|
119
297
|
if (focus) items[index]?.focus();
|
|
120
298
|
}
|
|
@@ -135,7 +313,12 @@ var RovingController = class extends Controller {
|
|
|
135
313
|
homeEnd: { type: Boolean, default: true }
|
|
136
314
|
};
|
|
137
315
|
static events = ["change"];
|
|
138
|
-
#
|
|
316
|
+
#tabindex = new AttributeLease("tabindex", this.identifier);
|
|
317
|
+
#managedItems = /* @__PURE__ */ new WeakSet();
|
|
318
|
+
#roving = new RovingTabindex(
|
|
319
|
+
() => this.itemTargets,
|
|
320
|
+
(item, value) => this.#writeTabindex(item, value)
|
|
321
|
+
);
|
|
139
322
|
#reconcile = new MorphRenderWatcher(() => this.#ensureTabStop(true));
|
|
140
323
|
#connected = false;
|
|
141
324
|
#observer = null;
|
|
@@ -156,13 +339,21 @@ var RovingController = class extends Controller {
|
|
|
156
339
|
this.#observer = null;
|
|
157
340
|
}
|
|
158
341
|
itemTargetConnected(item) {
|
|
159
|
-
if (!this.#connected) return;
|
|
160
|
-
item
|
|
342
|
+
if (!this.#connected || this.#managedItems.has(item)) return;
|
|
343
|
+
this.#writeTabindex(item, -1);
|
|
161
344
|
this.#reconcile.schedule();
|
|
162
345
|
}
|
|
163
|
-
itemTargetDisconnected() {
|
|
346
|
+
itemTargetDisconnected(item) {
|
|
347
|
+
if (!this.scope.containsElement(item) || !this.itemTargets.includes(item)) {
|
|
348
|
+
this.#managedItems.delete(item);
|
|
349
|
+
this.#tabindex.return(item);
|
|
350
|
+
}
|
|
164
351
|
this.#reconcile.schedule();
|
|
165
352
|
}
|
|
353
|
+
#writeTabindex(item, value) {
|
|
354
|
+
this.#managedItems.add(item);
|
|
355
|
+
this.#tabindex.write(item, String(value));
|
|
356
|
+
}
|
|
166
357
|
#onKeydown = (event) => {
|
|
167
358
|
if (event.defaultPrevented) return;
|
|
168
359
|
if (isReservedArrowChord(event)) return;
|
|
@@ -2,6 +2,7 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
4
4
|
if (element.getAttribute(name) === value) return false;
|
|
5
|
+
beforeWrite?.();
|
|
5
6
|
if (value === null) element.removeAttribute(name);
|
|
6
7
|
else element.setAttribute(name, value);
|
|
7
8
|
return true;
|
|
@@ -75,14 +76,34 @@ var AttributeLease = class {
|
|
|
75
76
|
const names = registry.names;
|
|
76
77
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
77
78
|
}
|
|
78
|
-
write(element, value) {
|
|
79
|
+
write(element, value, beforeWrite) {
|
|
79
80
|
const stack = attributeStack(element, this.#attribute);
|
|
80
81
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
81
82
|
this.#held.add(element);
|
|
82
83
|
const shows = !this.#covered(element, stack, hold);
|
|
83
84
|
hold.written = value;
|
|
84
85
|
this.#mark(element, stack);
|
|
85
|
-
if (shows) this.#reflect(element, value);
|
|
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;
|
|
86
107
|
}
|
|
87
108
|
return(element) {
|
|
88
109
|
const held = this.#held.delete(element);
|
|
@@ -148,8 +169,8 @@ var AttributeLease = class {
|
|
|
148
169
|
setAttributeIfChanged(element, name, recorded);
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
|
-
#reflect(element, value) {
|
|
152
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
172
|
+
#reflect(element, value, beforeWrite) {
|
|
173
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
153
174
|
}
|
|
154
175
|
};
|
|
155
176
|
|
|
@@ -235,14 +256,23 @@ function isTabStop(element) {
|
|
|
235
256
|
if (tabindex !== null) return tabindex >= 0;
|
|
236
257
|
return hasNativeTabStop(element) || hasEditableTabStop(element);
|
|
237
258
|
}
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
259
|
+
function tabStopsWithin(root) {
|
|
260
|
+
return Array.from(root.querySelectorAll(TAB_STOP_CANDIDATE_SELECTOR)).filter(
|
|
261
|
+
isTabStop
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
function isRadio(element) {
|
|
265
|
+
return element instanceof HTMLInputElement && element.type === "radio";
|
|
266
|
+
}
|
|
267
|
+
function sameRadioGroup(a, b) {
|
|
268
|
+
return a.name !== "" && a.name === b.name && a.form === b.form && a.getRootNode() === b.getRootNode();
|
|
243
269
|
}
|
|
244
|
-
function
|
|
245
|
-
|
|
270
|
+
function isUncheckedRadioInCheckedGroup(element) {
|
|
271
|
+
if (!isRadio(element) || element.checked) return false;
|
|
272
|
+
const root = element.getRootNode();
|
|
273
|
+
return Array.from(root.querySelectorAll("input")).some(
|
|
274
|
+
(other) => isRadio(other) && other.checked && sameRadioGroup(other, element) && isTabStop(other)
|
|
275
|
+
);
|
|
246
276
|
}
|
|
247
277
|
function deepActiveElement(ownerDocument) {
|
|
248
278
|
let active = ownerDocument.activeElement;
|
|
@@ -724,6 +754,11 @@ var ScrollAreaController = class extends Controller {
|
|
|
724
754
|
const viewport = event.currentTarget;
|
|
725
755
|
this.#frames.schedule(() => this.#syncPosition(viewport, this.#overflowing));
|
|
726
756
|
};
|
|
757
|
+
#onRadioChange = (event) => {
|
|
758
|
+
if (event.target instanceof HTMLInputElement && event.target.type === "radio") {
|
|
759
|
+
this.#refresh();
|
|
760
|
+
}
|
|
761
|
+
};
|
|
727
762
|
#onFontsSettled = () => {
|
|
728
763
|
this.#refresh();
|
|
729
764
|
};
|
|
@@ -763,6 +798,9 @@ var ScrollAreaController = class extends Controller {
|
|
|
763
798
|
return;
|
|
764
799
|
}
|
|
765
800
|
this.#viewportListeners.add(next, "scroll", this.#onScroll, { passive: true });
|
|
801
|
+
this.#viewportListeners.add(next.ownerDocument, "change", this.#onRadioChange, {
|
|
802
|
+
capture: true
|
|
803
|
+
});
|
|
766
804
|
this.#layout.observeDescendantLoads(next);
|
|
767
805
|
this.#layout.observe(next);
|
|
768
806
|
this.#bindContentObserver(next);
|
|
@@ -878,7 +916,7 @@ var ScrollAreaController = class extends Controller {
|
|
|
878
916
|
return { position: "middle", progress };
|
|
879
917
|
}
|
|
880
918
|
#syncKeyboardReach(viewport, overflowing) {
|
|
881
|
-
const wantsTabindex = overflowing && !
|
|
919
|
+
const wantsTabindex = overflowing && !tabStopsWithin(viewport).some((candidate) => !isUncheckedRadioInCheckedGroup(candidate));
|
|
882
920
|
if (!wantsTabindex) {
|
|
883
921
|
this.#clearViewportAttributes(viewport);
|
|
884
922
|
return;
|
|
@@ -2,6 +2,7 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
4
4
|
if (element.getAttribute(name) === value) return false;
|
|
5
|
+
beforeWrite?.();
|
|
5
6
|
if (value === null) element.removeAttribute(name);
|
|
6
7
|
else element.setAttribute(name, value);
|
|
7
8
|
return true;
|
|
@@ -75,14 +76,34 @@ var AttributeLease = class {
|
|
|
75
76
|
const names = registry.names;
|
|
76
77
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
77
78
|
}
|
|
78
|
-
write(element, value) {
|
|
79
|
+
write(element, value, beforeWrite) {
|
|
79
80
|
const stack = attributeStack(element, this.#attribute);
|
|
80
81
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
81
82
|
this.#held.add(element);
|
|
82
83
|
const shows = !this.#covered(element, stack, hold);
|
|
83
84
|
hold.written = value;
|
|
84
85
|
this.#mark(element, stack);
|
|
85
|
-
if (shows) this.#reflect(element, value);
|
|
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;
|
|
86
107
|
}
|
|
87
108
|
return(element) {
|
|
88
109
|
const held = this.#held.delete(element);
|
|
@@ -148,8 +169,8 @@ var AttributeLease = class {
|
|
|
148
169
|
setAttributeIfChanged(element, name, recorded);
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
|
-
#reflect(element, value) {
|
|
152
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
172
|
+
#reflect(element, value, beforeWrite) {
|
|
173
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
153
174
|
}
|
|
154
175
|
};
|
|
155
176
|
|