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,15 +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
|
+
|
|
3
11
|
function sharedRegistry(key, create) {
|
|
4
12
|
const symbol = Symbol.for(key);
|
|
5
13
|
const scope = globalThis;
|
|
6
14
|
const existing = scope[symbol];
|
|
7
15
|
if (existing !== void 0) return existing;
|
|
8
|
-
const
|
|
9
|
-
Object.defineProperty(globalThis, symbol, { value:
|
|
10
|
-
return
|
|
16
|
+
const registry2 = create();
|
|
17
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
18
|
+
return registry2;
|
|
11
19
|
}
|
|
12
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
|
+
|
|
13
177
|
var EscapeLayer = class _EscapeLayer {
|
|
14
178
|
static #registries = sharedRegistry(
|
|
15
179
|
"stimeo-ui.escape-layer.registry.v1",
|
|
@@ -19,24 +183,24 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
19
183
|
activate(ownerDocument = document, options) {
|
|
20
184
|
const entry = { onDismiss: options.onDismiss, claims: options.claims ?? null };
|
|
21
185
|
this.deactivate();
|
|
22
|
-
let
|
|
23
|
-
if (!
|
|
24
|
-
|
|
25
|
-
_EscapeLayer.#registries.set(ownerDocument,
|
|
26
|
-
ownerDocument.addEventListener("keydown",
|
|
186
|
+
let registry2 = _EscapeLayer.#registries.get(ownerDocument);
|
|
187
|
+
if (!registry2) {
|
|
188
|
+
registry2 = _EscapeLayer.#createRegistry();
|
|
189
|
+
_EscapeLayer.#registries.set(ownerDocument, registry2);
|
|
190
|
+
ownerDocument.addEventListener("keydown", registry2.onKeydown);
|
|
27
191
|
}
|
|
28
|
-
|
|
192
|
+
registry2.stack.push(entry);
|
|
29
193
|
this.#active = { document: ownerDocument, entry };
|
|
30
194
|
}
|
|
31
195
|
deactivate() {
|
|
32
196
|
const active = this.#active;
|
|
33
197
|
if (!active) return;
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
const index =
|
|
37
|
-
if (index >= 0)
|
|
38
|
-
if (
|
|
39
|
-
active.document.removeEventListener("keydown",
|
|
198
|
+
const registry2 = _EscapeLayer.#registries.get(active.document);
|
|
199
|
+
if (registry2) {
|
|
200
|
+
const index = registry2.stack.lastIndexOf(active.entry);
|
|
201
|
+
if (index >= 0) registry2.stack.splice(index, 1);
|
|
202
|
+
if (registry2.stack.length === 0) {
|
|
203
|
+
active.document.removeEventListener("keydown", registry2.onKeydown);
|
|
40
204
|
_EscapeLayer.#registries.delete(active.document);
|
|
41
205
|
}
|
|
42
206
|
}
|
|
@@ -45,22 +209,22 @@ var EscapeLayer = class _EscapeLayer {
|
|
|
45
209
|
get ownsEscape() {
|
|
46
210
|
const active = this.#active;
|
|
47
211
|
if (!active) return false;
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
50
|
-
return _EscapeLayer.#resolveOwner(
|
|
212
|
+
const registry2 = _EscapeLayer.#registries.get(active.document);
|
|
213
|
+
if (!registry2) return false;
|
|
214
|
+
return _EscapeLayer.#resolveOwner(registry2.stack) === active.entry;
|
|
51
215
|
}
|
|
52
216
|
static #createRegistry() {
|
|
53
|
-
const
|
|
217
|
+
const registry2 = {
|
|
54
218
|
stack: [],
|
|
55
219
|
onKeydown: (event) => {
|
|
56
220
|
if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) return;
|
|
57
|
-
const owner = _EscapeLayer.#resolveOwner(
|
|
221
|
+
const owner = _EscapeLayer.#resolveOwner(registry2.stack);
|
|
58
222
|
if (!owner) return;
|
|
59
223
|
event.preventDefault();
|
|
60
224
|
owner.onDismiss();
|
|
61
225
|
}
|
|
62
226
|
};
|
|
63
|
-
return
|
|
227
|
+
return registry2;
|
|
64
228
|
}
|
|
65
229
|
static #resolveOwner(stack) {
|
|
66
230
|
for (let index = stack.length - 1; index >= 0; index--) {
|
|
@@ -207,11 +371,18 @@ var TooltipController = class _TooltipController extends Controller {
|
|
|
207
371
|
#focusActive = false;
|
|
208
372
|
#pointerActive = false;
|
|
209
373
|
#stopScrollDismiss = null;
|
|
210
|
-
#
|
|
374
|
+
#open = false;
|
|
375
|
+
#revealToken = null;
|
|
376
|
+
#currentContent = null;
|
|
377
|
+
#hidden = new AttributeLease("hidden", this.identifier);
|
|
378
|
+
#state = new AttributeLease("data-state", this.identifier);
|
|
211
379
|
#reporting = false;
|
|
212
380
|
connect() {
|
|
381
|
+
this.#reporting = false;
|
|
213
382
|
this.#cancelTimers();
|
|
214
383
|
this.#resetInteractionState();
|
|
384
|
+
this.#open = false;
|
|
385
|
+
this.#currentContent = null;
|
|
215
386
|
this.#conceal("api");
|
|
216
387
|
this.#reporting = true;
|
|
217
388
|
}
|
|
@@ -219,20 +390,23 @@ var TooltipController = class _TooltipController extends Controller {
|
|
|
219
390
|
this.#reporting = false;
|
|
220
391
|
this.#cancelTimers();
|
|
221
392
|
this.#release();
|
|
393
|
+
this.#open = false;
|
|
394
|
+
this.#currentContent = null;
|
|
222
395
|
}
|
|
223
396
|
closeOnScrollValueChanged() {
|
|
224
|
-
if (this.#
|
|
397
|
+
if (this.#open) this.#syncScrollDismiss();
|
|
398
|
+
}
|
|
399
|
+
contentTargetConnected() {
|
|
400
|
+
if (this.#reporting) this.#syncContent();
|
|
225
401
|
}
|
|
226
402
|
contentTargetDisconnected(content) {
|
|
227
|
-
if (
|
|
228
|
-
if (this.contentTargets.includes(content))
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
content.hidden = true;
|
|
232
|
-
content.setAttribute("data-state", "closed");
|
|
233
|
-
this.#reflectHidden();
|
|
403
|
+
if (this.#reporting) this.#syncContent();
|
|
404
|
+
if (!this.scope.containsElement(content) || !this.contentTargets.includes(content)) {
|
|
405
|
+
this.#returnContent(content);
|
|
406
|
+
}
|
|
234
407
|
}
|
|
235
408
|
show(event) {
|
|
409
|
+
this.#syncContent();
|
|
236
410
|
const reason = stateReasonFor(event);
|
|
237
411
|
this.#activateInteraction(event);
|
|
238
412
|
this.#cancelHide();
|
|
@@ -247,6 +421,7 @@ var TooltipController = class _TooltipController extends Controller {
|
|
|
247
421
|
}, this.#safeShowDelay);
|
|
248
422
|
}
|
|
249
423
|
hide(event) {
|
|
424
|
+
this.#syncContent();
|
|
250
425
|
const reason = stateReasonFor(event);
|
|
251
426
|
const interactionEnded = this.#deactivateInteraction(event);
|
|
252
427
|
if (interactionEnded && this.#hasActiveInteraction) return;
|
|
@@ -262,36 +437,59 @@ var TooltipController = class _TooltipController extends Controller {
|
|
|
262
437
|
}, this.#safeHideDelay);
|
|
263
438
|
}
|
|
264
439
|
#reveal(reason) {
|
|
265
|
-
|
|
266
|
-
const content = this.contentTarget;
|
|
440
|
+
this.#syncContent();
|
|
267
441
|
const was = this.#isVisible;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
this.#
|
|
442
|
+
this.#open = true;
|
|
443
|
+
const token = {};
|
|
444
|
+
this.#revealToken = token;
|
|
445
|
+
this.#reflectContent(this.#currentContent, true);
|
|
271
446
|
if (!was && this.#reporting) this.dispatch("open", { detail: { reason }, cancelable: false });
|
|
272
|
-
if (this.#
|
|
447
|
+
if (!this.#open || !this.#reporting) return;
|
|
448
|
+
this.#syncContent();
|
|
449
|
+
if (this.#revealToken !== token) return;
|
|
273
450
|
this.#escapeLayer.activate(document, { onDismiss: () => this.#dismiss("escape") });
|
|
274
451
|
this.#syncScrollDismiss();
|
|
275
452
|
}
|
|
276
453
|
#conceal(reason) {
|
|
454
|
+
this.#syncContent();
|
|
277
455
|
const was = this.#isVisible;
|
|
456
|
+
this.#open = false;
|
|
278
457
|
this.#release();
|
|
279
|
-
this.#
|
|
458
|
+
this.#reflectContent(this.#currentContent, false);
|
|
280
459
|
if (was && this.#reporting) this.dispatch("close", { detail: { reason }, cancelable: false });
|
|
281
460
|
}
|
|
282
|
-
#
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
461
|
+
#syncContent() {
|
|
462
|
+
const next = this.hasContentTarget ? this.contentTarget : null;
|
|
463
|
+
const current = this.#currentContent;
|
|
464
|
+
if (current === next) return;
|
|
465
|
+
if (current) {
|
|
466
|
+
this.#open = !current.hidden;
|
|
467
|
+
if (!this.scope.containsElement(current) || !this.contentTargets.includes(current)) {
|
|
468
|
+
this.#returnContent(current);
|
|
469
|
+
} else this.#reflectContent(current, false);
|
|
470
|
+
}
|
|
471
|
+
this.#currentContent = next;
|
|
472
|
+
this.#reflectContent(next, this.#open);
|
|
473
|
+
if (!this.#open) this.#release();
|
|
474
|
+
else this.#syncScrollDismiss();
|
|
475
|
+
}
|
|
476
|
+
#reflectContent(content, open) {
|
|
477
|
+
if (!content) return;
|
|
478
|
+
this.#hidden.write(content, open ? null : "");
|
|
479
|
+
this.#state.write(content, open ? "open" : "closed");
|
|
480
|
+
}
|
|
481
|
+
#returnContent(content) {
|
|
482
|
+
this.#hidden.return(content);
|
|
483
|
+
this.#state.return(content);
|
|
286
484
|
}
|
|
287
485
|
#release() {
|
|
288
|
-
this.#
|
|
486
|
+
this.#revealToken = null;
|
|
289
487
|
this.#escapeLayer.deactivate();
|
|
290
488
|
this.#stopScrollDismiss?.();
|
|
291
489
|
this.#stopScrollDismiss = null;
|
|
292
490
|
}
|
|
293
491
|
#syncScrollDismiss() {
|
|
294
|
-
if (this.closeOnScrollValue) {
|
|
492
|
+
if (this.closeOnScrollValue && this.#currentContent && this.#open) {
|
|
295
493
|
this.#stopScrollDismiss ??= observeScrollDismiss(this.element, () => this.#dismiss("scroll"));
|
|
296
494
|
return;
|
|
297
495
|
}
|
|
@@ -341,10 +539,10 @@ var TooltipController = class _TooltipController extends Controller {
|
|
|
341
539
|
}
|
|
342
540
|
}
|
|
343
541
|
get #isVisible() {
|
|
344
|
-
return this
|
|
542
|
+
return this.#currentContent ? !this.#currentContent.hidden : this.#open;
|
|
345
543
|
}
|
|
346
544
|
get #hidable() {
|
|
347
|
-
return this.#isVisible || this.#
|
|
545
|
+
return this.#isVisible || this.#open;
|
|
348
546
|
}
|
|
349
547
|
get #safeShowDelay() {
|
|
350
548
|
return this.#numbers.read(
|
|
@@ -42,6 +42,172 @@ 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
213
|
#lifetime = null;
|
|
@@ -308,8 +474,12 @@ var MoveCounter = class {
|
|
|
308
474
|
|
|
309
475
|
var RovingTabindex = class {
|
|
310
476
|
#getItems;
|
|
311
|
-
|
|
477
|
+
#write;
|
|
478
|
+
constructor(getItems, write = (item, tabindex) => {
|
|
479
|
+
item.tabIndex = tabindex;
|
|
480
|
+
}) {
|
|
312
481
|
this.#getItems = getItems;
|
|
482
|
+
this.#write = write;
|
|
313
483
|
}
|
|
314
484
|
get activeIndex() {
|
|
315
485
|
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
@@ -318,7 +488,7 @@ var RovingTabindex = class {
|
|
|
318
488
|
const { focus = false } = options;
|
|
319
489
|
const items = options.items ?? this.#getItems();
|
|
320
490
|
items.forEach((item, i) => {
|
|
321
|
-
item
|
|
491
|
+
this.#write(item, i === index ? 0 : -1);
|
|
322
492
|
});
|
|
323
493
|
if (focus) items[index]?.focus();
|
|
324
494
|
}
|
|
@@ -414,7 +584,14 @@ var TreeViewController = class extends Controller {
|
|
|
414
584
|
static targets = ["item", "group", "field"];
|
|
415
585
|
static actions = ["onKeydown", "select", "toggle"];
|
|
416
586
|
static events = ["select", "toggle", "reconcile"];
|
|
417
|
-
#
|
|
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
|
+
);
|
|
418
595
|
#typeahead = new Typeahead();
|
|
419
596
|
#reconcile = new MorphRenderWatcher(() => this.#reconcileSelection());
|
|
420
597
|
#observer = new AuthoredMutationWatcher((records) => {
|
|
@@ -522,6 +699,10 @@ var TreeViewController = class extends Controller {
|
|
|
522
699
|
if (this.#concernsItems(this.#observer.take())) this.#reconcile.schedule();
|
|
523
700
|
}
|
|
524
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);
|
|
525
706
|
if (!this.#connected || !this.element.isConnected) return;
|
|
526
707
|
const stranded = this.#focusDiedWith(item);
|
|
527
708
|
if (stranded) this.#focused = null;
|
|
@@ -532,6 +713,17 @@ var TreeViewController = class extends Controller {
|
|
|
532
713
|
this.#reconcile.schedule();
|
|
533
714
|
this.#order = this.#order.filter((tracked) => tracked !== item);
|
|
534
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
|
+
}
|
|
535
727
|
#trackOrder() {
|
|
536
728
|
const live = this.itemTargets;
|
|
537
729
|
const pending = this.#order.filter((tracked) => !live.includes(tracked));
|
|
@@ -712,8 +904,8 @@ var TreeViewController = class extends Controller {
|
|
|
712
904
|
this.dispatch("select", { detail: { item, reason } });
|
|
713
905
|
}
|
|
714
906
|
#setExpanded(item, group, expanded, reason = "user") {
|
|
715
|
-
|
|
716
|
-
group
|
|
907
|
+
this.#expanded.write(item, String(expanded));
|
|
908
|
+
this.#writeGroupHidden(group, !expanded);
|
|
717
909
|
if (!expanded) this.#escapeCollapsedSubtree(item, group);
|
|
718
910
|
this.dispatch("toggle", { detail: { item, expanded, reason } });
|
|
719
911
|
}
|
|
@@ -756,9 +948,9 @@ var TreeViewController = class extends Controller {
|
|
|
756
948
|
const group = this.#childGroup(item);
|
|
757
949
|
if (!group) continue;
|
|
758
950
|
if (item.hasAttribute("aria-expanded")) {
|
|
759
|
-
group
|
|
951
|
+
this.#writeGroupHidden(group, !this.#isExpanded(item));
|
|
760
952
|
} else {
|
|
761
|
-
|
|
953
|
+
this.#expanded.write(item, String(!group.hidden));
|
|
762
954
|
}
|
|
763
955
|
}
|
|
764
956
|
}
|
|
@@ -807,7 +999,7 @@ var TreeViewController = class extends Controller {
|
|
|
807
999
|
});
|
|
808
1000
|
}
|
|
809
1001
|
#writeSelection(target, value) {
|
|
810
|
-
|
|
1002
|
+
this.#selected.write(target, value, () => {
|
|
811
1003
|
this.#observer.claim(target, "aria-selected", value);
|
|
812
1004
|
});
|
|
813
1005
|
}
|