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
|
@@ -42,45 +42,234 @@ function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function sharedRegistry(key, create) {
|
|
46
|
+
const symbol = Symbol.for(key);
|
|
47
|
+
const scope = globalThis;
|
|
48
|
+
const existing = scope[symbol];
|
|
49
|
+
if (existing !== void 0) return existing;
|
|
50
|
+
const registry2 = create();
|
|
51
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
52
|
+
return registry2;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var registry = sharedRegistry(
|
|
56
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
57
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
58
|
+
);
|
|
59
|
+
function isAttributeValue(value) {
|
|
60
|
+
return value === null || typeof value === "string";
|
|
61
|
+
}
|
|
62
|
+
function readLeaseRecord(element, record) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
65
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
66
|
+
const [original, written, ...rest] = parsed;
|
|
67
|
+
const linked = rest[0] !== false;
|
|
68
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
69
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
70
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
71
|
+
} catch {
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function attributeStack(element, attribute) {
|
|
76
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
77
|
+
registry.stacks.set(element, byAttribute);
|
|
78
|
+
const known = byAttribute.get(attribute);
|
|
79
|
+
if (known) return known;
|
|
80
|
+
const found = [];
|
|
81
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
82
|
+
const read = readLeaseRecord(element, record);
|
|
83
|
+
if (read) found.push({ ...read, record });
|
|
84
|
+
}
|
|
85
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
86
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
87
|
+
lease: null,
|
|
88
|
+
record,
|
|
89
|
+
written,
|
|
90
|
+
original,
|
|
91
|
+
linked: linked && index > 0
|
|
92
|
+
}));
|
|
93
|
+
byAttribute.set(attribute, stack);
|
|
94
|
+
return stack;
|
|
95
|
+
}
|
|
96
|
+
function findHold(stack, lease, record) {
|
|
97
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
98
|
+
}
|
|
99
|
+
var AttributeLease = class {
|
|
100
|
+
#attribute;
|
|
101
|
+
#record;
|
|
102
|
+
#base;
|
|
103
|
+
#preserveAuthor;
|
|
104
|
+
#held = /* @__PURE__ */ new Set();
|
|
105
|
+
constructor(attribute, owner, options = {}) {
|
|
106
|
+
this.#attribute = attribute;
|
|
107
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
108
|
+
this.#base = options.base === true;
|
|
109
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
110
|
+
const names = registry.names;
|
|
111
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
112
|
+
}
|
|
113
|
+
write(element, value, beforeWrite) {
|
|
114
|
+
const stack = attributeStack(element, this.#attribute);
|
|
115
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
116
|
+
this.#held.add(element);
|
|
117
|
+
const shows = !this.#covered(element, stack, hold);
|
|
118
|
+
hold.written = value;
|
|
119
|
+
this.#mark(element, stack);
|
|
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;
|
|
141
|
+
}
|
|
142
|
+
return(element) {
|
|
143
|
+
const held = this.#held.delete(element);
|
|
144
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
145
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
146
|
+
const hold = this.#take(stack);
|
|
147
|
+
if (!hold) return false;
|
|
148
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
149
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
150
|
+
const index = stack.indexOf(hold);
|
|
151
|
+
stack.splice(index, 1);
|
|
152
|
+
const above = stack[index];
|
|
153
|
+
if (above) above.linked &&= hold.linked;
|
|
154
|
+
this.#mark(element, stack);
|
|
155
|
+
if (!owns) return true;
|
|
156
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
157
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
returnAll() {
|
|
161
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
162
|
+
}
|
|
163
|
+
#take(stack) {
|
|
164
|
+
const hold = findHold(stack, this, this.#record);
|
|
165
|
+
if (hold) hold.lease = this;
|
|
166
|
+
return hold;
|
|
167
|
+
}
|
|
168
|
+
#acquire(element, stack) {
|
|
169
|
+
const current = element.getAttribute(this.#attribute);
|
|
170
|
+
const top = stack.at(-1);
|
|
171
|
+
const bottom = stack[0];
|
|
172
|
+
const over = top?.written === current ? top : void 0;
|
|
173
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
174
|
+
const hold = {
|
|
175
|
+
lease: this,
|
|
176
|
+
record: this.#record,
|
|
177
|
+
written: current,
|
|
178
|
+
original: from ? from.original : current,
|
|
179
|
+
linked: !this.#base && over !== void 0
|
|
180
|
+
};
|
|
181
|
+
if (this.#base && bottom) {
|
|
182
|
+
bottom.linked = true;
|
|
183
|
+
stack.unshift(hold);
|
|
184
|
+
} else stack.push(hold);
|
|
185
|
+
return hold;
|
|
186
|
+
}
|
|
187
|
+
#covered(element, stack, hold) {
|
|
188
|
+
const current = element.getAttribute(this.#attribute);
|
|
189
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
190
|
+
}
|
|
191
|
+
#mark(element, stack) {
|
|
192
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
193
|
+
stack.forEach((hold, index) => {
|
|
194
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
195
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
196
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
197
|
+
records.set(
|
|
198
|
+
hold.record,
|
|
199
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
for (const [name, recorded] of records) {
|
|
203
|
+
setAttributeIfChanged(element, name, recorded);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
#reflect(element, value, beforeWrite) {
|
|
207
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
45
211
|
var AuthoredMutationWatcher = class {
|
|
46
212
|
#onAuthored;
|
|
47
|
-
#
|
|
48
|
-
#observer = null;
|
|
213
|
+
#lifetime = null;
|
|
49
214
|
constructor(onAuthored) {
|
|
50
215
|
this.#onAuthored = onAuthored;
|
|
51
216
|
}
|
|
52
217
|
observe(root, options) {
|
|
53
|
-
this
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
this.#
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
218
|
+
const previous = this.#lifetime;
|
|
219
|
+
const lifetime = {
|
|
220
|
+
observer: null,
|
|
221
|
+
active: false,
|
|
222
|
+
claims: { attributes: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() }
|
|
223
|
+
};
|
|
224
|
+
this.#lifetime = lifetime;
|
|
225
|
+
let observer = null;
|
|
226
|
+
try {
|
|
227
|
+
if (previous) this.#release(previous);
|
|
228
|
+
if (this.#lifetime !== lifetime) return;
|
|
229
|
+
const attributes = [...options.attributes];
|
|
230
|
+
const subtree = options.subtree ?? false;
|
|
231
|
+
const childList = options.childList ?? false;
|
|
232
|
+
const inherited = options.ancestorAttributes;
|
|
233
|
+
const ancestorAttributes = inherited ? [...inherited] : null;
|
|
234
|
+
if (this.#lifetime !== lifetime) return;
|
|
235
|
+
observer = new MutationObserver((records) => {
|
|
236
|
+
const authored = this.#filter(records, lifetime.claims);
|
|
237
|
+
if (this.#lifetime === lifetime && lifetime.active && authored.length > 0) {
|
|
238
|
+
this.#onAuthored(authored);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
if (this.#lifetime !== lifetime) return;
|
|
242
|
+
lifetime.observer = observer;
|
|
243
|
+
observer.observe(root, { attributes: true, attributeFilter: attributes, subtree, childList });
|
|
244
|
+
if (this.#lifetime !== lifetime) {
|
|
245
|
+
this.#release(lifetime, observer);
|
|
246
|
+
return;
|
|
75
247
|
}
|
|
248
|
+
if (ancestorAttributes) {
|
|
249
|
+
let ancestor = root.parentElement;
|
|
250
|
+
while (ancestor) {
|
|
251
|
+
observer.observe(ancestor, { attributes: true, attributeFilter: ancestorAttributes });
|
|
252
|
+
if (this.#lifetime !== lifetime) {
|
|
253
|
+
this.#release(lifetime, observer);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
ancestor = ancestor.parentElement;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
lifetime.active = true;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
this.#release(lifetime, observer);
|
|
262
|
+
throw error;
|
|
76
263
|
}
|
|
77
264
|
}
|
|
78
265
|
claim(target, name, value) {
|
|
79
|
-
const
|
|
80
|
-
|
|
266
|
+
const lifetime = this.#lifetime;
|
|
267
|
+
if (!lifetime?.active) return;
|
|
268
|
+
const claims = lifetime.claims.attributes;
|
|
269
|
+
let attributes = claims.get(target);
|
|
81
270
|
if (!attributes) {
|
|
82
271
|
attributes = /* @__PURE__ */ new Map();
|
|
83
|
-
claims
|
|
272
|
+
claims.set(target, attributes);
|
|
84
273
|
}
|
|
85
274
|
const pending = attributes.get(name);
|
|
86
275
|
attributes.set(name, { value, count: (pending?.count ?? 0) + 1 });
|
|
@@ -89,37 +278,49 @@ var AuthoredMutationWatcher = class {
|
|
|
89
278
|
this.claim(target, name, target.getAttribute(name));
|
|
90
279
|
}
|
|
91
280
|
claimChildList(target, added, removed) {
|
|
92
|
-
const
|
|
93
|
-
|
|
281
|
+
const lifetime = this.#lifetime;
|
|
282
|
+
if (!lifetime?.active) return;
|
|
283
|
+
const claims = lifetime.claims.children;
|
|
284
|
+
const pending = claims.get(target) ?? { added: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Map() };
|
|
94
285
|
for (const node of added) pending.added.set(node, (pending.added.get(node) ?? 0) + 1);
|
|
95
286
|
for (const node of removed) pending.removed.set(node, (pending.removed.get(node) ?? 0) + 1);
|
|
96
|
-
claims
|
|
287
|
+
claims.set(target, pending);
|
|
97
288
|
}
|
|
98
289
|
take() {
|
|
99
|
-
|
|
290
|
+
const lifetime = this.#lifetime;
|
|
291
|
+
const observer = lifetime?.observer;
|
|
292
|
+
if (!lifetime?.active || !observer) return [];
|
|
293
|
+
const records = observer.takeRecords();
|
|
294
|
+
const authored = this.#filter(records, lifetime.claims);
|
|
295
|
+
return this.#lifetime === lifetime && lifetime.active ? authored : [];
|
|
100
296
|
}
|
|
101
297
|
disconnect() {
|
|
102
|
-
this.#
|
|
103
|
-
this.#
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
298
|
+
const lifetime = this.#lifetime;
|
|
299
|
+
if (lifetime) this.#release(lifetime);
|
|
300
|
+
}
|
|
301
|
+
#release(lifetime, observer = lifetime.observer) {
|
|
302
|
+
if (this.#lifetime === lifetime) this.#lifetime = null;
|
|
303
|
+
lifetime.claims.attributes.clear();
|
|
304
|
+
lifetime.claims.children.clear();
|
|
305
|
+
observer?.disconnect();
|
|
306
|
+
}
|
|
307
|
+
#filter(records, claims) {
|
|
308
|
+
const authored = records.filter((record) => !this.#consume(record, claims));
|
|
309
|
+
claims.attributes.clear();
|
|
310
|
+
claims.children.clear();
|
|
110
311
|
return authored;
|
|
111
312
|
}
|
|
112
|
-
#consume(record) {
|
|
313
|
+
#consume(record, claims) {
|
|
113
314
|
if (record.type === "attributes") {
|
|
114
315
|
const target = record.target;
|
|
115
|
-
const pending2 =
|
|
316
|
+
const pending2 = claims.attributes.get(target)?.get(record.attributeName);
|
|
116
317
|
if (!pending2 || pending2.count === 0 || target.getAttribute(record.attributeName) !== pending2.value) {
|
|
117
318
|
return false;
|
|
118
319
|
}
|
|
119
320
|
pending2.count -= 1;
|
|
120
321
|
return true;
|
|
121
322
|
}
|
|
122
|
-
const pending =
|
|
323
|
+
const pending = claims.children.get(record.target);
|
|
123
324
|
if (!pending) return false;
|
|
124
325
|
const added = [...record.addedNodes];
|
|
125
326
|
const removed = [...record.removedNodes];
|
|
@@ -141,11 +342,16 @@ function commitField(target) {
|
|
|
141
342
|
target.dispatchEvent(new Event("change", { bubbles: true }));
|
|
142
343
|
}
|
|
143
344
|
|
|
345
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
144
346
|
function inheritsFieldsetDisabled(control) {
|
|
145
347
|
let fieldset = control.closest("fieldset[disabled]");
|
|
146
348
|
while (fieldset) {
|
|
147
|
-
|
|
148
|
-
|
|
349
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
350
|
+
const legend = Array.from(fieldset.children).find(
|
|
351
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
352
|
+
);
|
|
353
|
+
if (!legend?.contains(control)) return true;
|
|
354
|
+
}
|
|
149
355
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
150
356
|
}
|
|
151
357
|
return false;
|
|
@@ -268,8 +474,12 @@ var MoveCounter = class {
|
|
|
268
474
|
|
|
269
475
|
var RovingTabindex = class {
|
|
270
476
|
#getItems;
|
|
271
|
-
|
|
477
|
+
#write;
|
|
478
|
+
constructor(getItems, write = (item, tabindex) => {
|
|
479
|
+
item.tabIndex = tabindex;
|
|
480
|
+
}) {
|
|
272
481
|
this.#getItems = getItems;
|
|
482
|
+
this.#write = write;
|
|
273
483
|
}
|
|
274
484
|
get activeIndex() {
|
|
275
485
|
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
@@ -278,7 +488,7 @@ var RovingTabindex = class {
|
|
|
278
488
|
const { focus = false } = options;
|
|
279
489
|
const items = options.items ?? this.#getItems();
|
|
280
490
|
items.forEach((item, i) => {
|
|
281
|
-
item
|
|
491
|
+
this.#write(item, i === index ? 0 : -1);
|
|
282
492
|
});
|
|
283
493
|
if (focus) items[index]?.focus();
|
|
284
494
|
}
|
|
@@ -327,7 +537,6 @@ var Typeahead = class {
|
|
|
327
537
|
#timers = new SafeTimeout();
|
|
328
538
|
#resetMs;
|
|
329
539
|
#query = "";
|
|
330
|
-
#timerId = 0;
|
|
331
540
|
constructor({ resetMs = TYPEAHEAD_RESET_MS } = {}) {
|
|
332
541
|
this.#resetMs = resetMs;
|
|
333
542
|
}
|
|
@@ -338,14 +547,13 @@ var Typeahead = class {
|
|
|
338
547
|
const char = key.toLowerCase();
|
|
339
548
|
const repeated = this.#query.length > 0 && [...this.#query].every((c) => c === char);
|
|
340
549
|
this.#query = repeated ? char : this.#query + char;
|
|
341
|
-
this.#timers.
|
|
342
|
-
this.#
|
|
550
|
+
this.#timers.clearAll();
|
|
551
|
+
this.#timers.set(() => this.reset(), this.#resetMs);
|
|
343
552
|
return this.#query;
|
|
344
553
|
}
|
|
345
554
|
reset() {
|
|
346
555
|
this.#query = "";
|
|
347
|
-
this.#timers.
|
|
348
|
-
this.#timerId = 0;
|
|
556
|
+
this.#timers.clearAll();
|
|
349
557
|
}
|
|
350
558
|
};
|
|
351
559
|
function isTypeaheadKey(event) {
|
|
@@ -376,7 +584,14 @@ var TreeViewController = class extends Controller {
|
|
|
376
584
|
static targets = ["item", "group", "field"];
|
|
377
585
|
static actions = ["onKeydown", "select", "toggle"];
|
|
378
586
|
static events = ["select", "toggle", "reconcile"];
|
|
379
|
-
#
|
|
587
|
+
#selected = new AttributeLease("aria-selected", this.identifier);
|
|
588
|
+
#tabindex = new AttributeLease("tabindex", this.identifier);
|
|
589
|
+
#expanded = new AttributeLease("aria-expanded", this.identifier);
|
|
590
|
+
#hidden = new AttributeLease("hidden", this.identifier);
|
|
591
|
+
#roving = new RovingTabindex(
|
|
592
|
+
() => this.itemTargets,
|
|
593
|
+
(item, value) => this.#tabindex.write(item, String(value))
|
|
594
|
+
);
|
|
380
595
|
#typeahead = new Typeahead();
|
|
381
596
|
#reconcile = new MorphRenderWatcher(() => this.#reconcileSelection());
|
|
382
597
|
#observer = new AuthoredMutationWatcher((records) => {
|
|
@@ -484,6 +699,10 @@ var TreeViewController = class extends Controller {
|
|
|
484
699
|
if (this.#concernsItems(this.#observer.take())) this.#reconcile.schedule();
|
|
485
700
|
}
|
|
486
701
|
itemTargetDisconnected(item) {
|
|
702
|
+
if (this.scope.containsElement(item) && this.itemTargets.includes(item)) return;
|
|
703
|
+
this.#selected.return(item);
|
|
704
|
+
this.#tabindex.return(item);
|
|
705
|
+
this.#expanded.return(item);
|
|
487
706
|
if (!this.#connected || !this.element.isConnected) return;
|
|
488
707
|
const stranded = this.#focusDiedWith(item);
|
|
489
708
|
if (stranded) this.#focused = null;
|
|
@@ -494,6 +713,17 @@ var TreeViewController = class extends Controller {
|
|
|
494
713
|
this.#reconcile.schedule();
|
|
495
714
|
this.#order = this.#order.filter((tracked) => tracked !== item);
|
|
496
715
|
}
|
|
716
|
+
groupTargetConnected() {
|
|
717
|
+
this.#reconcile.schedule();
|
|
718
|
+
}
|
|
719
|
+
groupTargetDisconnected(group) {
|
|
720
|
+
if (this.scope.containsElement(group) && this.groupTargets.includes(group)) return;
|
|
721
|
+
this.#hidden.return(group);
|
|
722
|
+
this.#reconcile.schedule();
|
|
723
|
+
}
|
|
724
|
+
#writeGroupHidden(group, hidden) {
|
|
725
|
+
if (this.groupTargets.includes(group)) this.#hidden.write(group, hidden ? "" : null);
|
|
726
|
+
}
|
|
497
727
|
#trackOrder() {
|
|
498
728
|
const live = this.itemTargets;
|
|
499
729
|
const pending = this.#order.filter((tracked) => !live.includes(tracked));
|
|
@@ -674,8 +904,8 @@ var TreeViewController = class extends Controller {
|
|
|
674
904
|
this.dispatch("select", { detail: { item, reason } });
|
|
675
905
|
}
|
|
676
906
|
#setExpanded(item, group, expanded, reason = "user") {
|
|
677
|
-
|
|
678
|
-
group
|
|
907
|
+
this.#expanded.write(item, String(expanded));
|
|
908
|
+
this.#writeGroupHidden(group, !expanded);
|
|
679
909
|
if (!expanded) this.#escapeCollapsedSubtree(item, group);
|
|
680
910
|
this.dispatch("toggle", { detail: { item, expanded, reason } });
|
|
681
911
|
}
|
|
@@ -718,9 +948,9 @@ var TreeViewController = class extends Controller {
|
|
|
718
948
|
const group = this.#childGroup(item);
|
|
719
949
|
if (!group) continue;
|
|
720
950
|
if (item.hasAttribute("aria-expanded")) {
|
|
721
|
-
group
|
|
951
|
+
this.#writeGroupHidden(group, !this.#isExpanded(item));
|
|
722
952
|
} else {
|
|
723
|
-
|
|
953
|
+
this.#expanded.write(item, String(!group.hidden));
|
|
724
954
|
}
|
|
725
955
|
}
|
|
726
956
|
}
|
|
@@ -769,7 +999,7 @@ var TreeViewController = class extends Controller {
|
|
|
769
999
|
});
|
|
770
1000
|
}
|
|
771
1001
|
#writeSelection(target, value) {
|
|
772
|
-
|
|
1002
|
+
this.#selected.write(target, value, () => {
|
|
773
1003
|
this.#observer.claim(target, "aria-selected", value);
|
|
774
1004
|
});
|
|
775
1005
|
}
|