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
|
@@ -7,16 +7,191 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
22
|
+
if (element.getAttribute(name) === value) return false;
|
|
23
|
+
beforeWrite?.();
|
|
24
|
+
if (value === null) element.removeAttribute(name);
|
|
25
|
+
else element.setAttribute(name, value);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sharedRegistry(key, create) {
|
|
30
|
+
const symbol = Symbol.for(key);
|
|
31
|
+
const scope = globalThis;
|
|
32
|
+
const existing = scope[symbol];
|
|
33
|
+
if (existing !== void 0) return existing;
|
|
34
|
+
const registry2 = create();
|
|
35
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
36
|
+
return registry2;
|
|
18
37
|
}
|
|
19
38
|
|
|
39
|
+
var registry = sharedRegistry(
|
|
40
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
41
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
42
|
+
);
|
|
43
|
+
function isAttributeValue(value) {
|
|
44
|
+
return value === null || typeof value === "string";
|
|
45
|
+
}
|
|
46
|
+
function readLeaseRecord(element, record) {
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
49
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
50
|
+
const [original, written, ...rest] = parsed;
|
|
51
|
+
const linked = rest[0] !== false;
|
|
52
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
53
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
54
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
55
|
+
} catch {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function attributeStack(element, attribute) {
|
|
60
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
61
|
+
registry.stacks.set(element, byAttribute);
|
|
62
|
+
const known = byAttribute.get(attribute);
|
|
63
|
+
if (known) return known;
|
|
64
|
+
const found = [];
|
|
65
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
66
|
+
const read = readLeaseRecord(element, record);
|
|
67
|
+
if (read) found.push({ ...read, record });
|
|
68
|
+
}
|
|
69
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
70
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
71
|
+
lease: null,
|
|
72
|
+
record,
|
|
73
|
+
written,
|
|
74
|
+
original,
|
|
75
|
+
linked: linked && index > 0
|
|
76
|
+
}));
|
|
77
|
+
byAttribute.set(attribute, stack);
|
|
78
|
+
return stack;
|
|
79
|
+
}
|
|
80
|
+
function findHold(stack, lease, record) {
|
|
81
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
82
|
+
}
|
|
83
|
+
var AttributeLease = class {
|
|
84
|
+
#attribute;
|
|
85
|
+
#record;
|
|
86
|
+
#base;
|
|
87
|
+
#preserveAuthor;
|
|
88
|
+
#held = /* @__PURE__ */ new Set();
|
|
89
|
+
constructor(attribute, owner, options = {}) {
|
|
90
|
+
this.#attribute = attribute;
|
|
91
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
92
|
+
this.#base = options.base === true;
|
|
93
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
94
|
+
const names = registry.names;
|
|
95
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
96
|
+
}
|
|
97
|
+
write(element, value, beforeWrite) {
|
|
98
|
+
const stack = attributeStack(element, this.#attribute);
|
|
99
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
100
|
+
this.#held.add(element);
|
|
101
|
+
const shows = !this.#covered(element, stack, hold);
|
|
102
|
+
hold.written = value;
|
|
103
|
+
this.#mark(element, stack);
|
|
104
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
105
|
+
}
|
|
106
|
+
adopt(element, options = {}) {
|
|
107
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
108
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
109
|
+
const stack = attributeStack(element, this.#attribute);
|
|
110
|
+
const hold = this.#take(stack);
|
|
111
|
+
if (!hold) return false;
|
|
112
|
+
const current = element.getAttribute(this.#attribute);
|
|
113
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
this.#held.add(element);
|
|
117
|
+
hold.original = current;
|
|
118
|
+
hold.linked = false;
|
|
119
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
120
|
+
if (!above.linked) break;
|
|
121
|
+
above.original = current;
|
|
122
|
+
}
|
|
123
|
+
this.#mark(element, stack);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return(element) {
|
|
127
|
+
const held = this.#held.delete(element);
|
|
128
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
129
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
130
|
+
const hold = this.#take(stack);
|
|
131
|
+
if (!hold) return false;
|
|
132
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
133
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
134
|
+
const index = stack.indexOf(hold);
|
|
135
|
+
stack.splice(index, 1);
|
|
136
|
+
const above = stack[index];
|
|
137
|
+
if (above) above.linked &&= hold.linked;
|
|
138
|
+
this.#mark(element, stack);
|
|
139
|
+
if (!owns) return true;
|
|
140
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
141
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
returnAll() {
|
|
145
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
146
|
+
}
|
|
147
|
+
#take(stack) {
|
|
148
|
+
const hold = findHold(stack, this, this.#record);
|
|
149
|
+
if (hold) hold.lease = this;
|
|
150
|
+
return hold;
|
|
151
|
+
}
|
|
152
|
+
#acquire(element, stack) {
|
|
153
|
+
const current = element.getAttribute(this.#attribute);
|
|
154
|
+
const top = stack.at(-1);
|
|
155
|
+
const bottom = stack[0];
|
|
156
|
+
const over = top?.written === current ? top : void 0;
|
|
157
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
158
|
+
const hold = {
|
|
159
|
+
lease: this,
|
|
160
|
+
record: this.#record,
|
|
161
|
+
written: current,
|
|
162
|
+
original: from ? from.original : current,
|
|
163
|
+
linked: !this.#base && over !== void 0
|
|
164
|
+
};
|
|
165
|
+
if (this.#base && bottom) {
|
|
166
|
+
bottom.linked = true;
|
|
167
|
+
stack.unshift(hold);
|
|
168
|
+
} else stack.push(hold);
|
|
169
|
+
return hold;
|
|
170
|
+
}
|
|
171
|
+
#covered(element, stack, hold) {
|
|
172
|
+
const current = element.getAttribute(this.#attribute);
|
|
173
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
174
|
+
}
|
|
175
|
+
#mark(element, stack) {
|
|
176
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
177
|
+
stack.forEach((hold, index) => {
|
|
178
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
179
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
180
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
181
|
+
records.set(
|
|
182
|
+
hold.record,
|
|
183
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
for (const [name, recorded] of records) {
|
|
187
|
+
setAttributeIfChanged(element, name, recorded);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
#reflect(element, value, beforeWrite) {
|
|
191
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
20
195
|
var ListenerSet = class {
|
|
21
196
|
#abort = new AbortController();
|
|
22
197
|
add(target, type, handler, options) {
|
|
@@ -98,6 +273,7 @@ var EmptyStateController = class extends Controller {
|
|
|
98
273
|
#observer = null;
|
|
99
274
|
#connected = false;
|
|
100
275
|
#empty = null;
|
|
276
|
+
#hidden = new AttributeLease("hidden", this.identifier);
|
|
101
277
|
#morphRender = new MorphRenderWatcher(() => this.#resync());
|
|
102
278
|
connect() {
|
|
103
279
|
this.#morphRender.observe(this.element);
|
|
@@ -109,17 +285,25 @@ var EmptyStateController = class extends Controller {
|
|
|
109
285
|
this.#morphRender.disconnect();
|
|
110
286
|
this.#connected = false;
|
|
111
287
|
this.#stopObserving();
|
|
288
|
+
if (!this.scope.containsElement(this.element)) {
|
|
289
|
+
this.element.removeAttribute("data-count");
|
|
290
|
+
this.element.removeAttribute("data-empty");
|
|
291
|
+
}
|
|
112
292
|
}
|
|
113
293
|
listTargetConnected() {
|
|
114
294
|
this.#resync();
|
|
115
295
|
}
|
|
116
|
-
listTargetDisconnected() {
|
|
296
|
+
listTargetDisconnected(element) {
|
|
297
|
+
if (!this.scope.containsElement(element) || !this.listTargets.includes(element))
|
|
298
|
+
this.#hidden.return(element);
|
|
117
299
|
this.#resync();
|
|
118
300
|
}
|
|
119
301
|
emptyTargetConnected() {
|
|
120
302
|
this.#resync();
|
|
121
303
|
}
|
|
122
|
-
emptyTargetDisconnected() {
|
|
304
|
+
emptyTargetDisconnected(element) {
|
|
305
|
+
if (!this.scope.containsElement(element) || !this.emptyTargets.includes(element))
|
|
306
|
+
this.#hidden.return(element);
|
|
123
307
|
this.#resync();
|
|
124
308
|
}
|
|
125
309
|
itemSelectorValueChanged() {
|
|
@@ -174,8 +358,8 @@ var EmptyStateController = class extends Controller {
|
|
|
174
358
|
} else {
|
|
175
359
|
this.element.removeAttribute("data-empty");
|
|
176
360
|
}
|
|
177
|
-
this.listTarget
|
|
178
|
-
if (this.hasEmptyTarget) this.emptyTarget
|
|
361
|
+
this.#hidden.write(this.listTarget, empty ? "" : null);
|
|
362
|
+
if (this.hasEmptyTarget) this.#hidden.write(this.emptyTarget, empty ? null : "");
|
|
179
363
|
return count;
|
|
180
364
|
}
|
|
181
365
|
#count() {
|
|
@@ -7,18 +7,20 @@ function fillTemplate(template, values) {
|
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
10
11
|
function announce(message, options = {}) {
|
|
11
12
|
const text = message.trim();
|
|
12
13
|
if (text.length === 0) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
15
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
16
|
+
});
|
|
17
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
18
|
+
window.dispatchEvent(event);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
21
22
|
if (element.getAttribute(name) === value) return false;
|
|
23
|
+
beforeWrite?.();
|
|
22
24
|
if (value === null) element.removeAttribute(name);
|
|
23
25
|
else element.setAttribute(name, value);
|
|
24
26
|
return true;
|
|
@@ -92,14 +94,34 @@ var AttributeLease = class {
|
|
|
92
94
|
const names = registry.names;
|
|
93
95
|
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
94
96
|
}
|
|
95
|
-
write(element, value) {
|
|
97
|
+
write(element, value, beforeWrite) {
|
|
96
98
|
const stack = attributeStack(element, this.#attribute);
|
|
97
99
|
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
98
100
|
this.#held.add(element);
|
|
99
101
|
const shows = !this.#covered(element, stack, hold);
|
|
100
102
|
hold.written = value;
|
|
101
103
|
this.#mark(element, stack);
|
|
102
|
-
if (shows) this.#reflect(element, value);
|
|
104
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
105
|
+
}
|
|
106
|
+
adopt(element, options = {}) {
|
|
107
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
108
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
109
|
+
const stack = attributeStack(element, this.#attribute);
|
|
110
|
+
const hold = this.#take(stack);
|
|
111
|
+
if (!hold) return false;
|
|
112
|
+
const current = element.getAttribute(this.#attribute);
|
|
113
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
this.#held.add(element);
|
|
117
|
+
hold.original = current;
|
|
118
|
+
hold.linked = false;
|
|
119
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
120
|
+
if (!above.linked) break;
|
|
121
|
+
above.original = current;
|
|
122
|
+
}
|
|
123
|
+
this.#mark(element, stack);
|
|
124
|
+
return true;
|
|
103
125
|
}
|
|
104
126
|
return(element) {
|
|
105
127
|
const held = this.#held.delete(element);
|
|
@@ -165,8 +187,8 @@ var AttributeLease = class {
|
|
|
165
187
|
setAttributeIfChanged(element, name, recorded);
|
|
166
188
|
}
|
|
167
189
|
}
|
|
168
|
-
#reflect(element, value) {
|
|
169
|
-
setAttributeIfChanged(element, this.#attribute, value);
|
|
190
|
+
#reflect(element, value, beforeWrite) {
|
|
191
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
170
192
|
}
|
|
171
193
|
};
|
|
172
194
|
|
|
@@ -211,10 +233,6 @@ function matchingPart(root, selector) {
|
|
|
211
233
|
return root.matches(selector) ? root : root.querySelector(selector);
|
|
212
234
|
}
|
|
213
235
|
function writeLabel(slot, text) {
|
|
214
|
-
if (slot.childElementCount === 0) {
|
|
215
|
-
slot.textContent = text;
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
236
|
let first = null;
|
|
219
237
|
for (const node of Array.from(slot.childNodes)) {
|
|
220
238
|
if (node.nodeType !== Node.TEXT_NODE) continue;
|
|
@@ -233,15 +251,119 @@ function ownerOf(candidates, node) {
|
|
|
233
251
|
return candidates[ownerIndex(candidates, node)] ?? null;
|
|
234
252
|
}
|
|
235
253
|
|
|
254
|
+
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
236
255
|
function inheritsFieldsetDisabled(control) {
|
|
237
256
|
let fieldset = control.closest("fieldset[disabled]");
|
|
238
257
|
while (fieldset) {
|
|
239
|
-
|
|
240
|
-
|
|
258
|
+
if (fieldset.namespaceURI === HTML_NAMESPACE && fieldset.localName === "fieldset") {
|
|
259
|
+
const legend = Array.from(fieldset.children).find(
|
|
260
|
+
(child) => child.namespaceURI === HTML_NAMESPACE && child.localName === "legend"
|
|
261
|
+
);
|
|
262
|
+
if (!legend?.contains(control)) return true;
|
|
263
|
+
}
|
|
241
264
|
fieldset = fieldset.parentElement?.closest("fieldset[disabled]") ?? null;
|
|
242
265
|
}
|
|
243
266
|
return false;
|
|
244
267
|
}
|
|
268
|
+
function unslotted(element) {
|
|
269
|
+
return element.assignedSlot === null && element.parentElement?.shadowRoot != null;
|
|
270
|
+
}
|
|
271
|
+
function flatTreeParent(element) {
|
|
272
|
+
if (unslotted(element)) return null;
|
|
273
|
+
const parent = element.assignedSlot ?? element.parentNode;
|
|
274
|
+
if (parent instanceof ShadowRoot) return parent.host;
|
|
275
|
+
return parent instanceof Element ? parent : null;
|
|
276
|
+
}
|
|
277
|
+
function flatTreeContains(ancestor, element) {
|
|
278
|
+
for (let node = element; node; node = flatTreeParent(node)) {
|
|
279
|
+
if (node === ancestor) return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
function canTakeFocus(element) {
|
|
284
|
+
for (let node = element; node; node = flatTreeParent(node)) {
|
|
285
|
+
if (unslotted(node) || node.matches("[hidden], [inert]")) return false;
|
|
286
|
+
}
|
|
287
|
+
if (element instanceof HTMLInputElement && element.type === "hidden") return false;
|
|
288
|
+
if (!("disabled" in element)) return true;
|
|
289
|
+
if (element.disabled) return false;
|
|
290
|
+
return !inheritsFieldsetDisabled(element);
|
|
291
|
+
}
|
|
292
|
+
function deepActiveElement(ownerDocument) {
|
|
293
|
+
let active = ownerDocument.activeElement;
|
|
294
|
+
while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
|
|
295
|
+
return active;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
var ListenerSet = class {
|
|
299
|
+
#abort = new AbortController();
|
|
300
|
+
add(target, type, handler, options) {
|
|
301
|
+
target.addEventListener(type, handler, { ...options, signal: this.#abort.signal });
|
|
302
|
+
}
|
|
303
|
+
dispose() {
|
|
304
|
+
this.#abort.abort();
|
|
305
|
+
this.#abort = new AbortController();
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
var MicrotaskCoalescer = class {
|
|
310
|
+
#run;
|
|
311
|
+
#queued = false;
|
|
312
|
+
#active = false;
|
|
313
|
+
#generation = 0;
|
|
314
|
+
constructor(run) {
|
|
315
|
+
this.#run = run;
|
|
316
|
+
}
|
|
317
|
+
activate() {
|
|
318
|
+
this.#active = true;
|
|
319
|
+
}
|
|
320
|
+
cancel() {
|
|
321
|
+
this.#active = false;
|
|
322
|
+
this.#queued = false;
|
|
323
|
+
this.#generation += 1;
|
|
324
|
+
}
|
|
325
|
+
get pending() {
|
|
326
|
+
return this.#queued;
|
|
327
|
+
}
|
|
328
|
+
schedule() {
|
|
329
|
+
if (!this.#active || this.#queued) return;
|
|
330
|
+
this.#queued = true;
|
|
331
|
+
const generation = this.#generation;
|
|
332
|
+
queueMicrotask(() => {
|
|
333
|
+
if (generation !== this.#generation || !this.#queued || !this.#active) return;
|
|
334
|
+
this.#queued = false;
|
|
335
|
+
this.#run();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
var MorphRenderWatcher = class {
|
|
341
|
+
#listeners = new ListenerSet();
|
|
342
|
+
#pass;
|
|
343
|
+
#element = null;
|
|
344
|
+
#onMorph = () => this.#pass.schedule();
|
|
345
|
+
constructor(run) {
|
|
346
|
+
this.#pass = new MicrotaskCoalescer(run);
|
|
347
|
+
}
|
|
348
|
+
observe(element) {
|
|
349
|
+
if (this.#element === element) return;
|
|
350
|
+
this.disconnect();
|
|
351
|
+
this.#element = element;
|
|
352
|
+
this.#pass.activate();
|
|
353
|
+
this.#listeners.add(element, "turbo:morph-element", this.#onMorph);
|
|
354
|
+
}
|
|
355
|
+
schedule() {
|
|
356
|
+
this.#pass.schedule();
|
|
357
|
+
}
|
|
358
|
+
get pending() {
|
|
359
|
+
return this.#pass.pending;
|
|
360
|
+
}
|
|
361
|
+
disconnect() {
|
|
362
|
+
this.#listeners.dispose();
|
|
363
|
+
this.#pass.cancel();
|
|
364
|
+
this.#element = null;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
245
367
|
|
|
246
368
|
var NUMBER_BOUNDS = {
|
|
247
369
|
nonNegative: { finite: true, min: 0 }};
|
|
@@ -287,6 +409,126 @@ var NumberValueReader = class {
|
|
|
287
409
|
}
|
|
288
410
|
};
|
|
289
411
|
|
|
412
|
+
function queryOpenDescendants(root, selector) {
|
|
413
|
+
const matches = [];
|
|
414
|
+
const roots = [root];
|
|
415
|
+
for (const scope of roots) {
|
|
416
|
+
matches.push(...scope.querySelectorAll(selector));
|
|
417
|
+
if (scope.nodeType === Node.ELEMENT_NODE) {
|
|
418
|
+
const shadow = scope.shadowRoot;
|
|
419
|
+
if (shadow) roots.push(shadow);
|
|
420
|
+
}
|
|
421
|
+
for (const element of scope.querySelectorAll("*")) {
|
|
422
|
+
if (element.shadowRoot) roots.push(element.shadowRoot);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return matches;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function holdsFocus(element) {
|
|
429
|
+
return element.matches(":focus") || deepActiveElement(element.ownerDocument) === element;
|
|
430
|
+
}
|
|
431
|
+
var TabindexLoan = class _TabindexLoan {
|
|
432
|
+
static #registry = sharedRegistry(
|
|
433
|
+
"stimeo-ui.tabindex-loan.registry.v1",
|
|
434
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Set() })
|
|
435
|
+
);
|
|
436
|
+
#value;
|
|
437
|
+
#record;
|
|
438
|
+
#preserveFocus;
|
|
439
|
+
#lent = /* @__PURE__ */ new Set();
|
|
440
|
+
constructor(value, owner, options = {}) {
|
|
441
|
+
this.#value = value;
|
|
442
|
+
this.#record = `data-${owner}-tabindex-loan`;
|
|
443
|
+
this.#preserveFocus = options.preserveFocus === true;
|
|
444
|
+
_TabindexLoan.#registry.names.add(this.#record);
|
|
445
|
+
}
|
|
446
|
+
lend(element, options = {}) {
|
|
447
|
+
const stack = this.#stack(element);
|
|
448
|
+
const current = element.getAttribute("tabindex");
|
|
449
|
+
const held = stack.find((hold) => hold.loan === this) ?? stack.find(
|
|
450
|
+
(hold) => hold.loan === null && hold.record === this.#record && hold.value === this.#value
|
|
451
|
+
);
|
|
452
|
+
const linked = stack.at(-1)?.value === current;
|
|
453
|
+
if (!held && options.onlyIfUnfocusable && (current !== null || element.tabIndex >= 0)) return;
|
|
454
|
+
if (!held && current !== null && !linked) return;
|
|
455
|
+
this.#lent.add(element);
|
|
456
|
+
if (held) held.loan = this;
|
|
457
|
+
else stack.push({ loan: this, record: this.#record, value: this.#value, linked });
|
|
458
|
+
this.#mark(element, stack);
|
|
459
|
+
if (current === null || !held && current !== this.#value) {
|
|
460
|
+
element.setAttribute("tabindex", this.#value);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return(element) {
|
|
464
|
+
const stack = this.#stack(element);
|
|
465
|
+
const hold = stack.find((held) => held.loan === this) ?? stack.find(
|
|
466
|
+
(held) => held.loan === null && held.record === this.#record && held.value === this.#value
|
|
467
|
+
);
|
|
468
|
+
if (!hold) return false;
|
|
469
|
+
if (!this.#release(element, stack, hold, this.#preserveFocus)) {
|
|
470
|
+
hold.loan = this;
|
|
471
|
+
this.#lent.add(element);
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
this.#lent.delete(element);
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
returnAll() {
|
|
478
|
+
for (const element of Array.from(this.#lent)) this.return(element);
|
|
479
|
+
}
|
|
480
|
+
reclaim(element) {
|
|
481
|
+
if (element.getAttribute(this.#record) !== this.#value) return;
|
|
482
|
+
const stack = this.#stack(element);
|
|
483
|
+
const hold = stack.find((held) => held.loan === null && held.record === this.#record);
|
|
484
|
+
if (hold && !holdsFocus(element)) this.#release(element, stack, hold);
|
|
485
|
+
}
|
|
486
|
+
reclaimWithin(root) {
|
|
487
|
+
for (const element of queryOpenDescendants(root, `[${this.#record}]`)) {
|
|
488
|
+
this.reclaim(element);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
#stack(element) {
|
|
492
|
+
const stacks = _TabindexLoan.#registry.stacks;
|
|
493
|
+
const stack = stacks.get(element) ?? this.#seed(element);
|
|
494
|
+
stacks.set(element, stack);
|
|
495
|
+
return stack;
|
|
496
|
+
}
|
|
497
|
+
#seed(element) {
|
|
498
|
+
const current = element.getAttribute("tabindex");
|
|
499
|
+
const holds = [];
|
|
500
|
+
for (const record of _TabindexLoan.#registry.names) {
|
|
501
|
+
const value = element.getAttribute(record);
|
|
502
|
+
if (value !== null) holds.push({ loan: null, record, value, linked: true });
|
|
503
|
+
}
|
|
504
|
+
holds.sort((one, other) => Number(one.value === current) - Number(other.value === current));
|
|
505
|
+
for (const [index, hold] of holds.entries()) hold.linked = index > 0;
|
|
506
|
+
return holds;
|
|
507
|
+
}
|
|
508
|
+
#release(element, stack, hold, preserveFocus = false) {
|
|
509
|
+
const current = element.getAttribute("tabindex");
|
|
510
|
+
const index = stack.indexOf(hold);
|
|
511
|
+
const owns = current === hold.value && !stack.slice(index + 1).some((above2) => above2.value === current);
|
|
512
|
+
if (owns && preserveFocus && holdsFocus(element)) return false;
|
|
513
|
+
stack.splice(index, 1);
|
|
514
|
+
const above = stack[index];
|
|
515
|
+
if (above) above.linked &&= hold.linked;
|
|
516
|
+
this.#mark(element, stack);
|
|
517
|
+
if (!owns) return true;
|
|
518
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
519
|
+
if (!below) element.removeAttribute("tabindex");
|
|
520
|
+
else if (below.value !== current) element.setAttribute("tabindex", below.value);
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
#mark(element, stack) {
|
|
524
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
525
|
+
for (const hold of stack) records.set(hold.record, hold.value);
|
|
526
|
+
for (const [name, recorded] of records) {
|
|
527
|
+
setAttributeIfChanged(element, name, recorded);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
290
532
|
function targetSelector(identifier, name) {
|
|
291
533
|
return `[data-${identifier}-target~="${name}"]`;
|
|
292
534
|
}
|
|
@@ -404,6 +646,11 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
|
|
|
404
646
|
noun: "item template"
|
|
405
647
|
});
|
|
406
648
|
#gate = new DetachGate();
|
|
649
|
+
#listInert = new AttributeLease("inert", this.identifier);
|
|
650
|
+
#listListeners = new ListenerSet();
|
|
651
|
+
#listMorph = new MorphRenderWatcher(() => this.#settleLists());
|
|
652
|
+
#focusLoan = new TabindexLoan("-1", this.identifier);
|
|
653
|
+
#currentList = null;
|
|
407
654
|
#listWatch = new MutationObserver((records) => {
|
|
408
655
|
const lost = records.some(
|
|
409
656
|
(record) => Array.from(record.removedNodes).some(
|
|
@@ -424,11 +671,17 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
|
|
|
424
671
|
this.#connected = true;
|
|
425
672
|
this.#rows.connect();
|
|
426
673
|
if (!moved) this.#discardInherited();
|
|
674
|
+
this.#focusLoan.reclaim(this.element);
|
|
675
|
+
this.#listMorph.observe(this.element);
|
|
676
|
+
this.#settleLists();
|
|
427
677
|
}
|
|
428
678
|
disconnect() {
|
|
429
679
|
this.#connected = false;
|
|
430
|
-
|
|
680
|
+
this.#listListeners.dispose();
|
|
681
|
+
this.#currentList = null;
|
|
431
682
|
this.#listWatch.disconnect();
|
|
683
|
+
this.#listMorph.disconnect();
|
|
684
|
+
this.#focusLoan.returnAll();
|
|
432
685
|
this.#gate.disconnected(this, () => this.#teardown());
|
|
433
686
|
}
|
|
434
687
|
#discardInherited() {
|
|
@@ -450,14 +703,12 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
|
|
|
450
703
|
this.#syncInput();
|
|
451
704
|
this.dispatch("reconcile", { detail: { files: this.#files } });
|
|
452
705
|
}
|
|
453
|
-
listTargetConnected(
|
|
454
|
-
|
|
455
|
-
this.#listWatch.observe(list, { childList: true });
|
|
456
|
-
this.#rehome();
|
|
706
|
+
listTargetConnected() {
|
|
707
|
+
if (this.#connected) this.#settleLists();
|
|
457
708
|
}
|
|
458
709
|
listTargetDisconnected(list) {
|
|
459
|
-
|
|
460
|
-
if (this.#connected) this.#
|
|
710
|
+
if (!this.listTargets.includes(list)) this.#listInert.return(list);
|
|
711
|
+
if (this.#connected) this.#settleLists();
|
|
461
712
|
}
|
|
462
713
|
inputTargetConnected() {
|
|
463
714
|
if (this.#connected) this.#syncInput();
|
|
@@ -510,7 +761,7 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
|
|
|
510
761
|
if (index !== -1) this.#removeAt(index);
|
|
511
762
|
};
|
|
512
763
|
#addFiles(files) {
|
|
513
|
-
this.#
|
|
764
|
+
this.#settleLists();
|
|
514
765
|
this.#invalid = false;
|
|
515
766
|
const rejected = /* @__PURE__ */ new Map();
|
|
516
767
|
const turnedAway = [];
|
|
@@ -644,9 +895,47 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
|
|
|
644
895
|
}
|
|
645
896
|
#rehome() {
|
|
646
897
|
if (!this.hasListTarget) return;
|
|
898
|
+
const focused = deepActiveElement(this.element.ownerDocument);
|
|
899
|
+
const restore = this.#entries.some((entry) => flatTreeContains(entry.item, focused));
|
|
647
900
|
for (const entry of this.#entries) {
|
|
648
901
|
if (!this.listTarget.contains(entry.item)) this.listTarget.appendChild(entry.item);
|
|
649
902
|
}
|
|
903
|
+
if (restore && focused instanceof HTMLElement) {
|
|
904
|
+
if (canTakeFocus(focused)) focused.focus();
|
|
905
|
+
if (deepActiveElement(this.element.ownerDocument) !== focused) this.#rescueListFocus();
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
#settleLists() {
|
|
909
|
+
const [current, ...behind] = this.listTargets;
|
|
910
|
+
if (current) this.#listInert.return(current);
|
|
911
|
+
if (this.#currentList !== (current ?? null)) {
|
|
912
|
+
this.#listListeners.dispose();
|
|
913
|
+
this.#listWatch.disconnect();
|
|
914
|
+
this.#currentList = current ?? null;
|
|
915
|
+
if (current) {
|
|
916
|
+
this.#listListeners.add(current, "click", this.#onItemClick);
|
|
917
|
+
this.#listWatch.observe(current, { childList: true });
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
this.#rehome();
|
|
921
|
+
for (const list of behind) {
|
|
922
|
+
if (flatTreeContains(list, deepActiveElement(this.element.ownerDocument)))
|
|
923
|
+
this.#rescueListFocus();
|
|
924
|
+
this.#listInert.write(list, "");
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
#rescueListFocus() {
|
|
928
|
+
const candidates = [
|
|
929
|
+
...this.hasTriggerTarget ? [this.triggerTarget] : [],
|
|
930
|
+
...this.hasInputTarget ? [this.inputTarget] : []
|
|
931
|
+
];
|
|
932
|
+
for (const candidate of candidates) {
|
|
933
|
+
if (!canTakeFocus(candidate)) continue;
|
|
934
|
+
candidate.focus();
|
|
935
|
+
if (deepActiveElement(this.element.ownerDocument) === candidate) return;
|
|
936
|
+
}
|
|
937
|
+
this.#focusLoan.lend(this.element);
|
|
938
|
+
this.element.focus();
|
|
650
939
|
}
|
|
651
940
|
#endDrag() {
|
|
652
941
|
this.#dragging = false;
|
|
@@ -668,6 +957,7 @@ var FileDropzoneController = class _FileDropzoneController extends Controller {
|
|
|
668
957
|
this.#endDrag();
|
|
669
958
|
}
|
|
670
959
|
#teardown() {
|
|
960
|
+
this.#listInert.returnAll();
|
|
671
961
|
this.#reset();
|
|
672
962
|
}
|
|
673
963
|
get #isDisabled() {
|