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
|
@@ -1,5 +1,179 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
4
|
+
if (element.getAttribute(name) === value) return false;
|
|
5
|
+
beforeWrite?.();
|
|
6
|
+
if (value === null) element.removeAttribute(name);
|
|
7
|
+
else element.setAttribute(name, value);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function sharedRegistry(key, create) {
|
|
12
|
+
const symbol = Symbol.for(key);
|
|
13
|
+
const scope = globalThis;
|
|
14
|
+
const existing = scope[symbol];
|
|
15
|
+
if (existing !== void 0) return existing;
|
|
16
|
+
const registry2 = create();
|
|
17
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
18
|
+
return registry2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var registry = sharedRegistry(
|
|
22
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
23
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
24
|
+
);
|
|
25
|
+
function isAttributeValue(value) {
|
|
26
|
+
return value === null || typeof value === "string";
|
|
27
|
+
}
|
|
28
|
+
function readLeaseRecord(element, record) {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
31
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
32
|
+
const [original, written, ...rest] = parsed;
|
|
33
|
+
const linked = rest[0] !== false;
|
|
34
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
35
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
36
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
37
|
+
} catch {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function attributeStack(element, attribute) {
|
|
42
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
43
|
+
registry.stacks.set(element, byAttribute);
|
|
44
|
+
const known = byAttribute.get(attribute);
|
|
45
|
+
if (known) return known;
|
|
46
|
+
const found = [];
|
|
47
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
48
|
+
const read = readLeaseRecord(element, record);
|
|
49
|
+
if (read) found.push({ ...read, record });
|
|
50
|
+
}
|
|
51
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
52
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
53
|
+
lease: null,
|
|
54
|
+
record,
|
|
55
|
+
written,
|
|
56
|
+
original,
|
|
57
|
+
linked: linked && index > 0
|
|
58
|
+
}));
|
|
59
|
+
byAttribute.set(attribute, stack);
|
|
60
|
+
return stack;
|
|
61
|
+
}
|
|
62
|
+
function findHold(stack, lease, record) {
|
|
63
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
64
|
+
}
|
|
65
|
+
var AttributeLease = class {
|
|
66
|
+
#attribute;
|
|
67
|
+
#record;
|
|
68
|
+
#base;
|
|
69
|
+
#preserveAuthor;
|
|
70
|
+
#held = /* @__PURE__ */ new Set();
|
|
71
|
+
constructor(attribute, owner, options = {}) {
|
|
72
|
+
this.#attribute = attribute;
|
|
73
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
74
|
+
this.#base = options.base === true;
|
|
75
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
76
|
+
const names = registry.names;
|
|
77
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
78
|
+
}
|
|
79
|
+
write(element, value, beforeWrite) {
|
|
80
|
+
const stack = attributeStack(element, this.#attribute);
|
|
81
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
82
|
+
this.#held.add(element);
|
|
83
|
+
const shows = !this.#covered(element, stack, hold);
|
|
84
|
+
hold.written = value;
|
|
85
|
+
this.#mark(element, stack);
|
|
86
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
87
|
+
}
|
|
88
|
+
adopt(element, options = {}) {
|
|
89
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
90
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
91
|
+
const stack = attributeStack(element, this.#attribute);
|
|
92
|
+
const hold = this.#take(stack);
|
|
93
|
+
if (!hold) return false;
|
|
94
|
+
const current = element.getAttribute(this.#attribute);
|
|
95
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
this.#held.add(element);
|
|
99
|
+
hold.original = current;
|
|
100
|
+
hold.linked = false;
|
|
101
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
102
|
+
if (!above.linked) break;
|
|
103
|
+
above.original = current;
|
|
104
|
+
}
|
|
105
|
+
this.#mark(element, stack);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return(element) {
|
|
109
|
+
const held = this.#held.delete(element);
|
|
110
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
111
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
112
|
+
const hold = this.#take(stack);
|
|
113
|
+
if (!hold) return false;
|
|
114
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
115
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
116
|
+
const index = stack.indexOf(hold);
|
|
117
|
+
stack.splice(index, 1);
|
|
118
|
+
const above = stack[index];
|
|
119
|
+
if (above) above.linked &&= hold.linked;
|
|
120
|
+
this.#mark(element, stack);
|
|
121
|
+
if (!owns) return true;
|
|
122
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
123
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
returnAll() {
|
|
127
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
128
|
+
}
|
|
129
|
+
#take(stack) {
|
|
130
|
+
const hold = findHold(stack, this, this.#record);
|
|
131
|
+
if (hold) hold.lease = this;
|
|
132
|
+
return hold;
|
|
133
|
+
}
|
|
134
|
+
#acquire(element, stack) {
|
|
135
|
+
const current = element.getAttribute(this.#attribute);
|
|
136
|
+
const top = stack.at(-1);
|
|
137
|
+
const bottom = stack[0];
|
|
138
|
+
const over = top?.written === current ? top : void 0;
|
|
139
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
140
|
+
const hold = {
|
|
141
|
+
lease: this,
|
|
142
|
+
record: this.#record,
|
|
143
|
+
written: current,
|
|
144
|
+
original: from ? from.original : current,
|
|
145
|
+
linked: !this.#base && over !== void 0
|
|
146
|
+
};
|
|
147
|
+
if (this.#base && bottom) {
|
|
148
|
+
bottom.linked = true;
|
|
149
|
+
stack.unshift(hold);
|
|
150
|
+
} else stack.push(hold);
|
|
151
|
+
return hold;
|
|
152
|
+
}
|
|
153
|
+
#covered(element, stack, hold) {
|
|
154
|
+
const current = element.getAttribute(this.#attribute);
|
|
155
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
156
|
+
}
|
|
157
|
+
#mark(element, stack) {
|
|
158
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
159
|
+
stack.forEach((hold, index) => {
|
|
160
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
161
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
162
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
163
|
+
records.set(
|
|
164
|
+
hold.record,
|
|
165
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
for (const [name, recorded] of records) {
|
|
169
|
+
setAttributeIfChanged(element, name, recorded);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
#reflect(element, value, beforeWrite) {
|
|
173
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
3
177
|
var ListenerSet = class {
|
|
4
178
|
#abort = new AbortController();
|
|
5
179
|
add(target, type, handler, options) {
|
|
@@ -81,6 +255,7 @@ var FilterController = class extends Controller {
|
|
|
81
255
|
#reported = null;
|
|
82
256
|
#connected = false;
|
|
83
257
|
#morphRender = new MorphRenderWatcher(() => this.#evaluate());
|
|
258
|
+
#hidden = new AttributeLease("hidden", this.identifier);
|
|
84
259
|
#listeners = new ListenerSet();
|
|
85
260
|
connect() {
|
|
86
261
|
this.#morphRender.observe(this.element);
|
|
@@ -94,6 +269,20 @@ var FilterController = class extends Controller {
|
|
|
94
269
|
this.#connected = false;
|
|
95
270
|
this.#listeners.dispose();
|
|
96
271
|
}
|
|
272
|
+
itemTargetDisconnected(item) {
|
|
273
|
+
this.#releaseHidden(item);
|
|
274
|
+
}
|
|
275
|
+
groupTargetDisconnected(group) {
|
|
276
|
+
this.#releaseHidden(group);
|
|
277
|
+
}
|
|
278
|
+
emptyTargetDisconnected(empty) {
|
|
279
|
+
this.#releaseHidden(empty);
|
|
280
|
+
}
|
|
281
|
+
#releaseHidden(element) {
|
|
282
|
+
if (this.itemTargets.includes(element) || this.groupTargets.includes(element) || this.emptyTargets.includes(element))
|
|
283
|
+
return;
|
|
284
|
+
this.#hidden.return(element);
|
|
285
|
+
}
|
|
97
286
|
matchValueChanged() {
|
|
98
287
|
if (!this.#connected) return;
|
|
99
288
|
this.#evaluate();
|
|
@@ -105,15 +294,15 @@ var FilterController = class extends Controller {
|
|
|
105
294
|
const active = this.#activeTokens();
|
|
106
295
|
let visibleCount = 0;
|
|
107
296
|
for (const item of this.itemTargets) {
|
|
108
|
-
|
|
109
|
-
item.hidden
|
|
110
|
-
if (
|
|
297
|
+
if (this.#matches(item, active)) this.#hidden.return(item);
|
|
298
|
+
else if (!item.hidden) this.#hidden.write(item, "");
|
|
299
|
+
if (!item.hidden) visibleCount += 1;
|
|
111
300
|
}
|
|
112
301
|
for (const group of this.groupTargets) {
|
|
113
|
-
group
|
|
302
|
+
this.#hidden.write(group, this.#hasVisibleItem(group) ? null : "");
|
|
114
303
|
}
|
|
115
304
|
for (const empty of this.emptyTargets) {
|
|
116
|
-
empty
|
|
305
|
+
this.#hidden.write(empty, visibleCount > 0 ? "" : null);
|
|
117
306
|
}
|
|
118
307
|
const total = this.itemTargets.length;
|
|
119
308
|
const reported = this.#reported;
|
|
@@ -22,15 +22,190 @@ function actionSource(source) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
var afterFocus = /* @__PURE__ */ Symbol.for("stimeo--announcer:after-focus");
|
|
25
26
|
function announce(message, options = {}) {
|
|
26
27
|
const text = message.trim();
|
|
27
28
|
if (text.length === 0) return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
29
|
+
const event = new CustomEvent("stimeo--announcer:announce", {
|
|
30
|
+
detail: { message: text, assertive: options.assertive === true }
|
|
31
|
+
});
|
|
32
|
+
if (options.afterFocus) event[afterFocus] = true;
|
|
33
|
+
window.dispatchEvent(event);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function setAttributeIfChanged(element, name, value, beforeWrite) {
|
|
37
|
+
if (element.getAttribute(name) === value) return false;
|
|
38
|
+
beforeWrite?.();
|
|
39
|
+
if (value === null) element.removeAttribute(name);
|
|
40
|
+
else element.setAttribute(name, value);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function sharedRegistry(key, create) {
|
|
45
|
+
const symbol = Symbol.for(key);
|
|
46
|
+
const scope = globalThis;
|
|
47
|
+
const existing = scope[symbol];
|
|
48
|
+
if (existing !== void 0) return existing;
|
|
49
|
+
const registry2 = create();
|
|
50
|
+
Object.defineProperty(globalThis, symbol, { value: registry2 });
|
|
51
|
+
return registry2;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var registry = sharedRegistry(
|
|
55
|
+
"stimeo-ui.attribute-lease.registry.v1",
|
|
56
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
57
|
+
);
|
|
58
|
+
function isAttributeValue(value) {
|
|
59
|
+
return value === null || typeof value === "string";
|
|
33
60
|
}
|
|
61
|
+
function readLeaseRecord(element, record) {
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(element.getAttribute(record) ?? "null");
|
|
64
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
65
|
+
const [original, written, ...rest] = parsed;
|
|
66
|
+
const linked = rest[0] !== false;
|
|
67
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
68
|
+
if (!beneath.every((under) => typeof under === "string")) return void 0;
|
|
69
|
+
return isAttributeValue(original) && isAttributeValue(written) ? { original, written, linked, beneath } : void 0;
|
|
70
|
+
} catch {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function attributeStack(element, attribute) {
|
|
75
|
+
const byAttribute = registry.stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
76
|
+
registry.stacks.set(element, byAttribute);
|
|
77
|
+
const known = byAttribute.get(attribute);
|
|
78
|
+
if (known) return known;
|
|
79
|
+
const found = [];
|
|
80
|
+
for (const record of registry.names.get(attribute) ?? []) {
|
|
81
|
+
const read = readLeaseRecord(element, record);
|
|
82
|
+
if (read) found.push({ ...read, record });
|
|
83
|
+
}
|
|
84
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
85
|
+
const stack = found.sort((one, other) => depth(one) - depth(other)).map(({ record, written, original, linked }, index) => ({
|
|
86
|
+
lease: null,
|
|
87
|
+
record,
|
|
88
|
+
written,
|
|
89
|
+
original,
|
|
90
|
+
linked: linked && index > 0
|
|
91
|
+
}));
|
|
92
|
+
byAttribute.set(attribute, stack);
|
|
93
|
+
return stack;
|
|
94
|
+
}
|
|
95
|
+
function findHold(stack, lease, record) {
|
|
96
|
+
return stack.find((held) => held.lease === lease) ?? stack.find((held) => held.lease === null && held.record === record);
|
|
97
|
+
}
|
|
98
|
+
var AttributeLease = class {
|
|
99
|
+
#attribute;
|
|
100
|
+
#record;
|
|
101
|
+
#base;
|
|
102
|
+
#preserveAuthor;
|
|
103
|
+
#held = /* @__PURE__ */ new Set();
|
|
104
|
+
constructor(attribute, owner, options = {}) {
|
|
105
|
+
this.#attribute = attribute;
|
|
106
|
+
this.#record = `data-${owner}-${attribute}-lease`;
|
|
107
|
+
this.#base = options.base === true;
|
|
108
|
+
this.#preserveAuthor = options.preserveAuthor === true;
|
|
109
|
+
const names = registry.names;
|
|
110
|
+
names.set(attribute, (names.get(attribute) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
111
|
+
}
|
|
112
|
+
write(element, value, beforeWrite) {
|
|
113
|
+
const stack = attributeStack(element, this.#attribute);
|
|
114
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
115
|
+
this.#held.add(element);
|
|
116
|
+
const shows = !this.#covered(element, stack, hold);
|
|
117
|
+
hold.written = value;
|
|
118
|
+
this.#mark(element, stack);
|
|
119
|
+
if (shows) this.#reflect(element, value, beforeWrite);
|
|
120
|
+
}
|
|
121
|
+
adopt(element, options = {}) {
|
|
122
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
123
|
+
if (!this.#held.has(element) && !known && !element.hasAttribute(this.#record)) return false;
|
|
124
|
+
const stack = attributeStack(element, this.#attribute);
|
|
125
|
+
const hold = this.#take(stack);
|
|
126
|
+
if (!hold) return false;
|
|
127
|
+
const current = element.getAttribute(this.#attribute);
|
|
128
|
+
if (options.ifChanged && (current === hold.written || this.#covered(element, stack, hold))) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
this.#held.add(element);
|
|
132
|
+
hold.original = current;
|
|
133
|
+
hold.linked = false;
|
|
134
|
+
for (const above of stack.slice(stack.indexOf(hold) + 1)) {
|
|
135
|
+
if (!above.linked) break;
|
|
136
|
+
above.original = current;
|
|
137
|
+
}
|
|
138
|
+
this.#mark(element, stack);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return(element) {
|
|
142
|
+
const held = this.#held.delete(element);
|
|
143
|
+
const known = registry.stacks.get(element)?.has(this.#attribute);
|
|
144
|
+
const stack = held || known || element.hasAttribute(this.#record) ? attributeStack(element, this.#attribute) : [];
|
|
145
|
+
const hold = this.#take(stack);
|
|
146
|
+
if (!hold) return false;
|
|
147
|
+
const carries = element.getAttribute(this.#attribute) === hold.written;
|
|
148
|
+
const owns = carries && !this.#covered(element, stack, hold);
|
|
149
|
+
const index = stack.indexOf(hold);
|
|
150
|
+
stack.splice(index, 1);
|
|
151
|
+
const above = stack[index];
|
|
152
|
+
if (above) above.linked &&= hold.linked;
|
|
153
|
+
this.#mark(element, stack);
|
|
154
|
+
if (!owns) return true;
|
|
155
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
156
|
+
this.#reflect(element, below ? below.written : hold.original);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
returnAll() {
|
|
160
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
161
|
+
}
|
|
162
|
+
#take(stack) {
|
|
163
|
+
const hold = findHold(stack, this, this.#record);
|
|
164
|
+
if (hold) hold.lease = this;
|
|
165
|
+
return hold;
|
|
166
|
+
}
|
|
167
|
+
#acquire(element, stack) {
|
|
168
|
+
const current = element.getAttribute(this.#attribute);
|
|
169
|
+
const top = stack.at(-1);
|
|
170
|
+
const bottom = stack[0];
|
|
171
|
+
const over = top?.written === current ? top : void 0;
|
|
172
|
+
const from = this.#base ? this.#preserveAuthor && !stack.some((held) => held.written === current) ? void 0 : bottom : over;
|
|
173
|
+
const hold = {
|
|
174
|
+
lease: this,
|
|
175
|
+
record: this.#record,
|
|
176
|
+
written: current,
|
|
177
|
+
original: from ? from.original : current,
|
|
178
|
+
linked: !this.#base && over !== void 0
|
|
179
|
+
};
|
|
180
|
+
if (this.#base && bottom) {
|
|
181
|
+
bottom.linked = true;
|
|
182
|
+
stack.unshift(hold);
|
|
183
|
+
} else stack.push(hold);
|
|
184
|
+
return hold;
|
|
185
|
+
}
|
|
186
|
+
#covered(element, stack, hold) {
|
|
187
|
+
const current = element.getAttribute(this.#attribute);
|
|
188
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => above.written === current);
|
|
189
|
+
}
|
|
190
|
+
#mark(element, stack) {
|
|
191
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
192
|
+
stack.forEach((hold, index) => {
|
|
193
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
194
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
195
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
196
|
+
records.set(
|
|
197
|
+
hold.record,
|
|
198
|
+
hold.written === hold.original && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([hold.original, hold.written, ...marker, ...beneath])
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
for (const [name, recorded] of records) {
|
|
202
|
+
setAttributeIfChanged(element, name, recorded);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
#reflect(element, value, beforeWrite) {
|
|
206
|
+
setAttributeIfChanged(element, this.#attribute, value, beforeWrite);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
34
209
|
|
|
35
210
|
function ownerIndex(candidates, node) {
|
|
36
211
|
if (!(node instanceof Node)) return -1;
|
|
@@ -379,6 +554,8 @@ var FlashController = class _FlashController extends Controller {
|
|
|
379
554
|
#dismiss = new PausableTimers();
|
|
380
555
|
#fixedDismiss = new KeyedTimers();
|
|
381
556
|
#reapply = new MorphRenderWatcher(() => this.#reapplyCap());
|
|
557
|
+
#role = new AttributeLease("role", this.identifier);
|
|
558
|
+
#writtenStates = /* @__PURE__ */ new WeakMap();
|
|
382
559
|
#spared = [];
|
|
383
560
|
#pointer = new HoverRecheck(
|
|
384
561
|
this.element.ownerDocument,
|
|
@@ -404,7 +581,7 @@ var FlashController = class _FlashController extends Controller {
|
|
|
404
581
|
this.#connected = true;
|
|
405
582
|
const current = this.messageTargets;
|
|
406
583
|
for (const item of this.#arrivals) {
|
|
407
|
-
if (!current.includes(item)) this.#
|
|
584
|
+
if (!current.includes(item)) this.#returnMessage(item);
|
|
408
585
|
}
|
|
409
586
|
this.#discardInherited();
|
|
410
587
|
this.#reapply.observe(this.element);
|
|
@@ -455,16 +632,23 @@ var FlashController = class _FlashController extends Controller {
|
|
|
455
632
|
return this.hasRegionTarget && this.regionTarget.contains(message);
|
|
456
633
|
}
|
|
457
634
|
messageTargetDisconnected(message) {
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
if (moved) {
|
|
461
|
-
this.#afterMove(message);
|
|
635
|
+
if (this.#owns(message) && this.messageTargets.includes(message)) {
|
|
636
|
+
if (this.#connected) this.#afterMove(message);
|
|
462
637
|
return;
|
|
463
638
|
}
|
|
464
|
-
this.#
|
|
465
|
-
this.#
|
|
639
|
+
if (!this.#connected && !message.isConnected) return;
|
|
640
|
+
this.#returnMessage(message);
|
|
641
|
+
if (this.#connected) this.#forget(message);
|
|
466
642
|
this.#leaving.delete(message);
|
|
467
643
|
}
|
|
644
|
+
#returnMessage(message) {
|
|
645
|
+
this.#role.return(message);
|
|
646
|
+
if (!this.#arrivals.delete(message) || !message.isConnected) return;
|
|
647
|
+
if (message.getAttribute("data-flash-state") === this.#writtenStates.get(message)) {
|
|
648
|
+
message.removeAttribute("data-flash-state");
|
|
649
|
+
}
|
|
650
|
+
message.removeAttribute(this.#shownAttribute);
|
|
651
|
+
}
|
|
468
652
|
#resync() {
|
|
469
653
|
if (!this.#connected) return;
|
|
470
654
|
this.#syncObservation();
|
|
@@ -520,9 +704,9 @@ var FlashController = class _FlashController extends Controller {
|
|
|
520
704
|
const type = message.getAttribute("data-flash-type") ?? "";
|
|
521
705
|
const assertive = ASSERTIVE_TYPES.has(type);
|
|
522
706
|
if (!message.hasAttribute("role")) {
|
|
523
|
-
|
|
707
|
+
this.#role.write(message, assertive ? "alert" : "status");
|
|
524
708
|
}
|
|
525
|
-
message
|
|
709
|
+
this.#writeState(message, "visible");
|
|
526
710
|
message.setAttribute(this.#shownAttribute, "");
|
|
527
711
|
const known = this.#arrivals.has(message);
|
|
528
712
|
this.#order.push(message);
|
|
@@ -567,14 +751,18 @@ var FlashController = class _FlashController extends Controller {
|
|
|
567
751
|
if (spare) this.#spared.push(spare);
|
|
568
752
|
this.#reapply.schedule();
|
|
569
753
|
}
|
|
754
|
+
#writeState(message, state) {
|
|
755
|
+
this.#writtenStates.set(message, state);
|
|
756
|
+
message.setAttribute("data-flash-state", state);
|
|
757
|
+
}
|
|
570
758
|
#reapplyCap() {
|
|
571
759
|
for (const message of [...this.#order, ...this.#leaving]) {
|
|
572
760
|
if (!this.#owns(message)) continue;
|
|
573
|
-
message
|
|
761
|
+
this.#writeState(message, this.#leaving.has(message) ? "leaving" : "visible");
|
|
574
762
|
message.setAttribute(this.#shownAttribute, "");
|
|
575
763
|
if (!message.hasAttribute("role")) {
|
|
576
764
|
const assertive = ASSERTIVE_TYPES.has(message.getAttribute("data-flash-type") ?? "");
|
|
577
|
-
|
|
765
|
+
this.#role.write(message, assertive ? "alert" : "status");
|
|
578
766
|
}
|
|
579
767
|
}
|
|
580
768
|
const spared = this.#spared;
|
|
@@ -604,7 +792,7 @@ var FlashController = class _FlashController extends Controller {
|
|
|
604
792
|
if (!this.#order.includes(message)) return;
|
|
605
793
|
this.#forget(message);
|
|
606
794
|
this.#leaving.add(message);
|
|
607
|
-
message
|
|
795
|
+
this.#writeState(message, "leaving");
|
|
608
796
|
const finalize = () => {
|
|
609
797
|
if (!this.#leaving.delete(message)) return;
|
|
610
798
|
message.remove();
|