stimeo-ui 0.4.0 → 0.6.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 +184 -0
- data/dist/controllers/aspect_ratio_controller.js +19 -11
- data/dist/controllers/avatar_controller.js +195 -40
- data/dist/controllers/breadcrumb_controller.js +5 -1
- data/dist/controllers/carousel_controller.js +90 -10
- data/dist/controllers/checkbox_controller.js +136 -25
- data/dist/controllers/clipboard_controller.js +8 -3
- data/dist/controllers/collapsible_controller.js +4 -1
- data/dist/controllers/color_picker_controller.js +41 -11
- data/dist/controllers/context_menu_controller.js +2 -2
- data/dist/controllers/countdown_controller.js +5 -1
- data/dist/controllers/date_range_picker_controller.js +162 -31
- data/dist/controllers/direct_upload_controller.js +3 -3
- data/dist/controllers/empty_state_controller.js +107 -16
- data/dist/controllers/file_dropzone_controller.js +26 -3
- data/dist/controllers/flash_controller.js +161 -21
- data/dist/controllers/form_validation_controller.js +8 -2
- data/dist/controllers/frame_loading_controller.js +94 -22
- data/dist/controllers/highlight_controller.js +38 -1
- data/dist/controllers/idle_controller.js +39 -6
- data/dist/controllers/local_time_controller.js +2 -0
- data/dist/controllers/masonry_controller.js +1 -1
- data/dist/controllers/menubar_controller.js +5 -3
- data/dist/controllers/meter_controller.js +3 -1
- data/dist/controllers/multi_select_controller.js +460 -151
- data/dist/controllers/network_status_controller.js +1 -3
- data/dist/controllers/number_input_controller.js +455 -64
- data/dist/controllers/overflow_menu_controller.js +5 -1
- data/dist/controllers/pagination_controller.js +38 -1
- data/dist/controllers/password_strength_controller.js +21 -3
- data/dist/controllers/persist_controller.js +24 -5
- data/dist/controllers/pointer_drag_controller.js +10 -0
- data/dist/controllers/portal_controller.js +10 -0
- data/dist/controllers/progress_controller.js +7 -3
- data/dist/controllers/radio_group_controller.js +540 -56
- data/dist/controllers/range_slider_controller.js +385 -94
- data/dist/controllers/rating_controller.js +274 -89
- data/dist/controllers/relative_time_controller.js +2 -0
- data/dist/controllers/resizable_controller.js +33 -0
- data/dist/controllers/roving_controller.js +60 -5
- data/dist/controllers/scroll_area_controller.js +155 -23
- data/dist/controllers/scroll_visibility_controller.js +33 -0
- data/dist/controllers/separator_controller.js +13 -17
- data/dist/controllers/skeleton_controller.js +71 -3
- data/dist/controllers/slider_controller.js +325 -48
- data/dist/controllers/spinner_controller.js +18 -3
- data/dist/controllers/step_indicator_controller.js +3 -1
- data/dist/controllers/stepper_controller.js +2 -0
- data/dist/controllers/switch_controller.js +162 -18
- data/dist/controllers/tags_input_controller.js +356 -120
- data/dist/controllers/textarea_autosize_controller.js +1 -1
- data/dist/controllers/time_picker_controller.js +296 -104
- data/dist/controllers/toggle_group_controller.js +378 -55
- data/dist/controllers/toolbar_controller.js +5 -3
- data/dist/controllers/tree_view_controller.js +24 -4
- data/dist/index.js +3811 -1048
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2883d44061c4c7ec8e5cd1a3b021c1d7fa8bf34bf8f2f74df1a3f496fe99f578
|
|
4
|
+
data.tar.gz: 9024ef97e2802777390ebc1a18cbbc202df8643ccac875d59b49a06bf6ae7f3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6dd511725546fc75ffa9e150ff02640d22c09404238f9ac418b8042eac78fab90bf6c19e8266933a5b2c47178ccc13dea00793c76c7e4184f708e9619afb84c
|
|
7
|
+
data.tar.gz: 926ccd828054b1e374bc5e9039d94d0eb4b0c398a45b235090af702ce037993e2bff6b774f6932d39e8eabdb27e69ae80fd953e25b2a8ead7525c1ee6a59d585
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,188 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
While the version is `0.x`, the public API (the `stimeo--*` data attributes) may
|
|
8
8
|
change between releases.
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-08-15
|
|
11
|
+
|
|
12
|
+
Minor release that separates reconciled state from user edits: `change` now
|
|
13
|
+
means the user committed a value, and a controller that re-derives its own state
|
|
14
|
+
reports `reconcile` instead. Several markup contracts tightened, and authored
|
|
15
|
+
prose — remove-button names, announcements — moved out of the library. The
|
|
16
|
+
Inspector manifest stays on schema v11, but **`stimeo check` can report errors on
|
|
17
|
+
views that passed under 0.5.0**, so run it before deploying.
|
|
18
|
+
|
|
19
|
+
### Upgrade notes
|
|
20
|
+
|
|
21
|
+
- Listening to `change` to observe controller-driven repair? Subscribe to
|
|
22
|
+
`reconcile` too: carousel, checkbox, color-picker, multi-select, number-input,
|
|
23
|
+
radio-group, rating, tags-input, time-picker. Neither fires on connect.
|
|
24
|
+
- rating: delete `max` and every `data-rating-value`. The DOM order of the
|
|
25
|
+
`symbol` targets is the scale.
|
|
26
|
+
- aspect-ratio: delete the `content` target.
|
|
27
|
+
- toggle-group, radio-group: items must be `<button type="button">` or a
|
|
28
|
+
non-interactive host with `role="button"` / `role="radio"`. Others are left
|
|
29
|
+
untouched at runtime.
|
|
30
|
+
- tags-input, multi-select: delete the `status` target, put a
|
|
31
|
+
`stimeo--announcer` on the page, and set `announceText` /
|
|
32
|
+
`announceRemovedText`. In the chip template add `label` and `remove` targets
|
|
33
|
+
and author the remove button's `aria-label` (`{label}` / `{value}` expand).
|
|
34
|
+
Drop `data-*-slot="label"` and tags-input's `removeTag` action.
|
|
35
|
+
- date-range-picker: declare unavailable days with `disabled-dates`; an
|
|
36
|
+
`aria-disabled` you write on a cell is overwritten on the next paint.
|
|
37
|
+
- time-picker: AM/PM is a `role="spinbutton"` segment, not an `aria-pressed`
|
|
38
|
+
toggle. `seconds` only decides whether the composed value carries seconds.
|
|
39
|
+
- List values are read as JSON strings — idle's `events`, password-strength's
|
|
40
|
+
`levels`, persist's `exclude`, date-range-picker's `disabled-dates`. The
|
|
41
|
+
markup is unchanged; the manifest reports `String` where it reported `Array`.
|
|
42
|
+
|
|
43
|
+
### Removed
|
|
44
|
+
|
|
45
|
+
- **Breaking** — rating: `max` and `data-rating-value`. aspect-ratio: the
|
|
46
|
+
`content` target. tags-input, multi-select: the `status` target, tags-input's
|
|
47
|
+
`removeTag` action, and the English `Remove {value}` label the library wrote
|
|
48
|
+
onto generated remove buttons.
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
|
|
52
|
+
- A `reconcile` event, carrying the same `detail` as that component's `change`,
|
|
53
|
+
on carousel, checkbox, color-picker, multi-select, number-input, radio-group,
|
|
54
|
+
rating, tags-input, and time-picker.
|
|
55
|
+
- checkbox: a group works without a `parent`; the root still reports
|
|
56
|
+
`all` / `partial` / `none`.
|
|
57
|
+
- rating: `Delete` and `Backspace` clear the rating when `clearable`.
|
|
58
|
+
- date-range-picker: `disabled-dates`, a `monthchange` event,
|
|
59
|
+
`Shift+PageUp` / `Shift+PageDown` for stepping a year, and month labels
|
|
60
|
+
formatted from `documentElement.lang`.
|
|
61
|
+
- multi-select: a `fields` target holding one hidden input per selected value,
|
|
62
|
+
with `name` and `form`, plus `announceText` / `announceRemovedText`.
|
|
63
|
+
tags-input: `label` and `remove` targets and the same two announce values.
|
|
64
|
+
- avatar: an `empty` state beside `loading`, `loaded`, and `error`.
|
|
65
|
+
- Inspector: `invalid-host` for radio-group and toggle-group items;
|
|
66
|
+
chip-template parts required *inside* the template; `aria-label` on remove
|
|
67
|
+
buttons and the group role on toggle groups; at most one checkbox `parent`
|
|
68
|
+
and one checked radio; a positive integer time-picker `step`. An empty
|
|
69
|
+
attribute value no longer satisfies a requirement that asks only for the
|
|
70
|
+
attribute's presence.
|
|
71
|
+
|
|
72
|
+
### Changed
|
|
73
|
+
|
|
74
|
+
- **Breaking** — `change` is reserved for user-committed values. DOM
|
|
75
|
+
normalization, target churn, morphs, and runtime value changes report
|
|
76
|
+
`reconcile`, and a repair that leaves the committed state unchanged reports
|
|
77
|
+
nothing.
|
|
78
|
+
- **Breaking** — radio-group, time-picker: the hidden `field` fires a native
|
|
79
|
+
`change` only for user edits, so a server-rendered repaint cannot drive an
|
|
80
|
+
`auto-submit` companion into a resubmit loop.
|
|
81
|
+
- **Breaking** — multi-select: `max` is enforced at all times, not only on the
|
|
82
|
+
click path; surplus options normalize to `aria-selected="false"`.
|
|
83
|
+
- **Breaking** — avatar: a present `src` value wins over an authored `src`, and
|
|
84
|
+
an empty one means "no image". Remove the attribute to hand the element's own
|
|
85
|
+
`src` back.
|
|
86
|
+
- **Breaking** — checkbox: a parent toggle sets each child's `checked` without
|
|
87
|
+
synthesizing a native `change` per child; the root reports one event.
|
|
88
|
+
- toggle-group, radio-group, tags-input, multi-select: interaction is delegated
|
|
89
|
+
from the container, so items added at runtime work without per-item
|
|
90
|
+
`data-action`. Existing per-item actions stay compatible.
|
|
91
|
+
- toggle-group, radio-group: `aria-disabled` items stay reachable by arrow keys
|
|
92
|
+
with activation suppressed; natively disabled and `hidden` items are skipped.
|
|
93
|
+
- number-input, rating, scroll-area, time-picker: ARIA and `tabindex` the
|
|
94
|
+
controller writes are treated as loans and handed back to their authored
|
|
95
|
+
values, without overwriting a change you made in the meantime.
|
|
96
|
+
- date-range-picker: a preset that only partly overlaps `min` / `max` is
|
|
97
|
+
narrowed to the selectable span instead of committing an unavailable endpoint.
|
|
98
|
+
- multi-select, tags-input: `Backspace` in an empty input removes the last chip
|
|
99
|
+
and keeps focus in the input.
|
|
100
|
+
- time-picker: a unit that wraps past noon or midnight carries AM/PM with it,
|
|
101
|
+
and one operation reports one `change` with the final value.
|
|
102
|
+
|
|
103
|
+
### Fixed
|
|
104
|
+
|
|
105
|
+
- avatar, carousel, checkbox, radio-group, rating, roving, toggle-group: targets
|
|
106
|
+
added, removed, or morphed at runtime settle on one state — a single tab stop,
|
|
107
|
+
a single checked or pressed item, and focus on a surviving item.
|
|
108
|
+
- date-range-picker: an unavailable day cannot become a committed endpoint
|
|
109
|
+
through a preset, a preview, or Enter/Space; a reversed stored range is
|
|
110
|
+
normalized on connect; a pending selection is rewound before Turbo caches the
|
|
111
|
+
page.
|
|
112
|
+
- number-input: commits compare numbers rather than the displayed text, and IME
|
|
113
|
+
composition never commits a value.
|
|
114
|
+
- time-picker: with `wrap` disabled, 11 and 12 no longer step into each other,
|
|
115
|
+
and an unfinished direct-entry buffer is discarded when focus leaves.
|
|
116
|
+
- multi-select, tags-input: a chip is built only when the template can produce a
|
|
117
|
+
complete one, only the `remove` target inside a chip acts on it, and a
|
|
118
|
+
replaced `tags` container is re-wired.
|
|
119
|
+
- file-dropzone, scroll-area: a replaced `list` / `viewport` keeps its state and
|
|
120
|
+
takes over the listeners; the old element stops responding.
|
|
121
|
+
- idle, password-strength, persist, date-range-picker: a malformed list value
|
|
122
|
+
falls back to its default instead of stopping the controller from connecting
|
|
123
|
+
and leaving the whole element inert.
|
|
124
|
+
|
|
125
|
+
## [0.5.0] - 2026-08-13
|
|
126
|
+
|
|
127
|
+
### Changed
|
|
128
|
+
|
|
129
|
+
- **Breaking** — every CSS custom property the library writes now carries the
|
|
130
|
+
`--stimeo--` namespace (two hyphens). Rename them in your stylesheets: a name
|
|
131
|
+
you miss raises no error, it just falls back to `var()`'s default and the bar
|
|
132
|
+
or thumb stops moving.
|
|
133
|
+
- `--stimeo-range-start` / `--stimeo-range-end` →
|
|
134
|
+
`--stimeo--range-slider-start` / `--stimeo--range-slider-end`
|
|
135
|
+
- `--stimeo-<name>` → `--stimeo--<name>` for `aspect-ratio`,
|
|
136
|
+
`collapsible-content-height`, `color`, `context-menu-x`, `context-menu-y`,
|
|
137
|
+
`masonry-columns`, `meter-ratio`, `password-strength`, `progress-ratio`,
|
|
138
|
+
`scroll-progress`, `step-indicator-ratio`, `textarea-rows`,
|
|
139
|
+
`upload-progress`
|
|
140
|
+
- **Breaking** — spinner's `indicator`, the network-status banners, and
|
|
141
|
+
countdown's `status` slot are no longer live regions. Drop `role="status"` /
|
|
142
|
+
`role="alert"` / `aria-live` from them and set `announceText` (and its
|
|
143
|
+
siblings) with a `stimeo--announcer` on the page; keeping the role reads the
|
|
144
|
+
change twice.
|
|
145
|
+
- time-picker: committing a field change dispatches a native `change` from the
|
|
146
|
+
`field` target, and `stimeo--time-picker:change` reports the composed value
|
|
147
|
+
even when no `field` target is present.
|
|
148
|
+
- tree-view: more native elements count as nested-interactive (`label`,
|
|
149
|
+
`summary`, `details`, `area[href]`, media with `controls`, `iframe`, `object`,
|
|
150
|
+
`embed`), so a click or key inside one is left alone instead of moving the
|
|
151
|
+
tree selection.
|
|
152
|
+
|
|
153
|
+
### Added
|
|
154
|
+
|
|
155
|
+
- Inspector: the manifest advances from schema v8 to **v11** — tools that read it
|
|
156
|
+
raw must accept the new `valueConstraints`, `hosts`, and `valueRelations`
|
|
157
|
+
fields. Two diagnostics are new, so **re-run `stimeo check` before deploying;
|
|
158
|
+
it can report errors on views that passed under 0.4.0**:
|
|
159
|
+
- `invalid-value` — slider, range-slider, and number-input need a finite,
|
|
160
|
+
positive `step`; range-slider needs finite `min`, `max`, `start`, and `end`
|
|
161
|
+
with `min` at or below `max`.
|
|
162
|
+
- `invalid-host` — switch, time-picker, and tree-view report an unsupported
|
|
163
|
+
host element before it reaches the browser.
|
|
164
|
+
|
|
165
|
+
### Fixed
|
|
166
|
+
|
|
167
|
+
- range-slider: two thumbs resting on the same value can be pulled apart with
|
|
168
|
+
the pointer again, and invalid or reversed bounds fall back to a finite
|
|
169
|
+
ordered range.
|
|
170
|
+
- slider, range-slider, number-input: an endpoint that does not sit on the step
|
|
171
|
+
grid is reachable, and an invalid `step` falls back to `1`.
|
|
172
|
+
- slider, range-slider: a Turbo morph that swaps a value repaints instead of
|
|
173
|
+
freezing, a replaced thumb or track picks up the current state, and a drag
|
|
174
|
+
stays with the pointer that started it.
|
|
175
|
+
- switch: holding Space no longer scrolls a non-`<button>` host, and an ancestor
|
|
176
|
+
`fieldset[disabled]` or `aria-disabled` blocks activation.
|
|
177
|
+
- flash: hover and focus pause the auto-dismiss independently, a flash paused
|
|
178
|
+
after its deadline dismisses instead of staying forever, a second dismiss on a
|
|
179
|
+
leaving flash is ignored, and a replaced `region` target is picked up.
|
|
180
|
+
- frame-loading: `aria-busy`, the skeleton, and `inert` are rolled back when the
|
|
181
|
+
controller is detached, instead of burning in with nothing left to finish the
|
|
182
|
+
load.
|
|
183
|
+
- empty-state: a replaced `list` or `empty` element and a runtime `itemSelector`
|
|
184
|
+
change are followed, so the placeholder no longer sticks beside a filled list.
|
|
185
|
+
- highlight: a highlight that outlives a Turbo navigation is cleaned up on the
|
|
186
|
+
way back instead of staying marked.
|
|
187
|
+
- idle: `data-idle` is cleared when a new measurement cycle connects, and
|
|
188
|
+
`disconnect()` removes the listeners it actually registered even when `events`
|
|
189
|
+
changed while connected.
|
|
190
|
+
- skeleton: a skeleton moved within the page keeps its ready intent.
|
|
191
|
+
|
|
10
192
|
## [0.4.0] - 2026-08-11
|
|
11
193
|
|
|
12
194
|
The feedback and status components announce through the shared
|
|
@@ -391,6 +573,8 @@ Initial public alpha: 101 behavior-only, accessible Stimulus controllers driven
|
|
|
391
573
|
by `data-*` attributes, shipping no CSS. Published to npm (with provenance) and
|
|
392
574
|
RubyGems.
|
|
393
575
|
|
|
576
|
+
[0.6.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.6.0
|
|
577
|
+
[0.5.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.5.0
|
|
394
578
|
[0.4.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.4.0
|
|
395
579
|
[0.3.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.3.0
|
|
396
580
|
[0.2.1]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.2.1
|
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
3
|
// src/controllers/aspect_ratio_controller.ts
|
|
4
|
+
var DEFAULT_RATIO = "1 / 1";
|
|
5
|
+
var RATIO_PROPERTY = "--stimeo--aspect-ratio";
|
|
6
|
+
var CSS_NUMBER_PATTERN = /^[+-]?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
4
7
|
var AspectRatioController = class extends Controller {
|
|
5
|
-
static targets = ["content"];
|
|
6
8
|
static values = {
|
|
7
9
|
ratio: { type: String, default: "1/1" }
|
|
8
10
|
};
|
|
9
11
|
/** Applies the ratio on connect and whenever the value changes. */
|
|
10
12
|
ratioValueChanged() {
|
|
11
|
-
this.element.style.setProperty(
|
|
13
|
+
this.element.style.setProperty(RATIO_PROPERTY, this.#normalizeRatio(this.ratioValue));
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Normalizes a ratio string to a valid CSS `<ratio>`:
|
|
15
|
-
* - `"16/9"` / `"16 / 9"` → `"16 / 9"` (both parts must be positive numbers)
|
|
16
|
-
* - `"1.5"` → `"1.5"` (a bare positive number)
|
|
17
|
+
* - `"16/9"` / `"16 / 9"` → `"16 / 9"` (both parts must be positive CSS numbers)
|
|
18
|
+
* - `"1.5"` → `"1.5"` (a bare positive CSS number)
|
|
17
19
|
* - anything else → `"1 / 1"` (the default), so the custom property is always valid.
|
|
18
20
|
*/
|
|
19
21
|
#normalizeRatio(raw) {
|
|
20
22
|
const value = raw.trim();
|
|
21
23
|
if (value.includes("/")) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
|
|
24
|
+
const parts = value.split("/");
|
|
25
|
+
if (parts.length !== 2) return DEFAULT_RATIO;
|
|
26
|
+
const width = this.#parsePositiveNumber(parts[0] ?? "");
|
|
27
|
+
const height = this.#parsePositiveNumber(parts[1] ?? "");
|
|
28
|
+
return width !== void 0 && height !== void 0 ? `${width} / ${height}` : DEFAULT_RATIO;
|
|
25
29
|
}
|
|
26
|
-
const single =
|
|
27
|
-
return
|
|
30
|
+
const single = this.#parsePositiveNumber(value);
|
|
31
|
+
return single === void 0 ? DEFAULT_RATIO : String(single);
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
/** Parses one complete CSS `<number>` token and rejects units or trailing syntax. */
|
|
34
|
+
#parsePositiveNumber(raw) {
|
|
35
|
+
const token = raw.trim();
|
|
36
|
+
if (!CSS_NUMBER_PATTERN.test(token)) return void 0;
|
|
37
|
+
const value = Number(token);
|
|
38
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
31
39
|
}
|
|
32
40
|
};
|
|
33
41
|
|
|
@@ -1,63 +1,218 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
// src/controllers/avatar_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/attribute_lease.ts
|
|
6
|
+
var AttributeLease = class {
|
|
7
|
+
#attribute;
|
|
8
|
+
#records = /* @__PURE__ */ new Map();
|
|
9
|
+
/** @param attribute - The attribute whose temporary values this lease owns. */
|
|
10
|
+
constructor(attribute) {
|
|
11
|
+
this.#attribute = attribute;
|
|
12
|
+
}
|
|
13
|
+
/** Writes or removes the leased attribute while preserving its authored value. */
|
|
14
|
+
write(element, value) {
|
|
15
|
+
const existing = this.#records.get(element);
|
|
16
|
+
if (existing) {
|
|
17
|
+
existing.written = value;
|
|
18
|
+
} else {
|
|
19
|
+
this.#records.set(element, {
|
|
20
|
+
original: element.getAttribute(this.#attribute),
|
|
21
|
+
written: value
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (value === null) element.removeAttribute(this.#attribute);
|
|
25
|
+
else element.setAttribute(this.#attribute, value);
|
|
26
|
+
}
|
|
27
|
+
/** Returns one lease without overwriting a value subsequently authored by a consumer. */
|
|
28
|
+
return(element) {
|
|
29
|
+
const record = this.#records.get(element);
|
|
30
|
+
if (!record) return;
|
|
31
|
+
this.#records.delete(element);
|
|
32
|
+
if (element.getAttribute(this.#attribute) !== record.written) return;
|
|
33
|
+
if (record.original === null) element.removeAttribute(this.#attribute);
|
|
34
|
+
else element.setAttribute(this.#attribute, record.original);
|
|
35
|
+
}
|
|
36
|
+
/** Returns every outstanding lease using the same ownership check as {@link return}. */
|
|
37
|
+
returnAll() {
|
|
38
|
+
for (const element of Array.from(this.#records.keys())) this.return(element);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/utils/microtask_coalescer.ts
|
|
43
|
+
var MicrotaskCoalescer = class {
|
|
44
|
+
#run;
|
|
45
|
+
#queued = false;
|
|
46
|
+
#active = false;
|
|
47
|
+
#generation = 0;
|
|
48
|
+
/** @param run - the single reconciliation pass, invoked at most once per batch. */
|
|
49
|
+
constructor(run) {
|
|
50
|
+
this.#run = run;
|
|
51
|
+
}
|
|
52
|
+
/** Opens the window in which {@link schedule} is honoured; call from `connect()`. */
|
|
53
|
+
activate() {
|
|
54
|
+
this.#active = true;
|
|
55
|
+
}
|
|
56
|
+
/** Closes the window and drops any pending pass; call from `disconnect()`. */
|
|
57
|
+
cancel() {
|
|
58
|
+
this.#active = false;
|
|
59
|
+
this.#queued = false;
|
|
60
|
+
this.#generation += 1;
|
|
61
|
+
}
|
|
62
|
+
/** Requests one pass after the batch settles. Idempotent; inert outside the window. */
|
|
63
|
+
schedule() {
|
|
64
|
+
if (!this.#active || this.#queued) return;
|
|
65
|
+
this.#queued = true;
|
|
66
|
+
const generation = this.#generation;
|
|
67
|
+
queueMicrotask(() => {
|
|
68
|
+
if (generation !== this.#generation || !this.#queued || !this.#active) return;
|
|
69
|
+
this.#queued = false;
|
|
70
|
+
this.#run();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
3
75
|
// src/controllers/avatar_controller.ts
|
|
4
76
|
var AvatarController = class extends Controller {
|
|
5
77
|
static targets = ["image", "fallback"];
|
|
6
|
-
static values = {
|
|
7
|
-
src: { type: String, default: "" }
|
|
8
|
-
};
|
|
78
|
+
static values = { src: String };
|
|
9
79
|
static actions = ["onError", "onLoad"];
|
|
10
80
|
static events = ["error"];
|
|
81
|
+
/** Collapses one morph's Value, target, and direct-attribute signals into one pass. */
|
|
82
|
+
#reconcile = new MicrotaskCoalescer(() => this.#render());
|
|
83
|
+
/** Preserves directly-authored source and visibility while targets are controlled. */
|
|
84
|
+
#src = new AttributeLease("src");
|
|
85
|
+
#imageHidden = new AttributeLease("hidden");
|
|
86
|
+
#fallbackHidden = new AttributeLease("hidden");
|
|
87
|
+
/** True only while target departure means ownership was actually relinquished. */
|
|
88
|
+
#connected = false;
|
|
89
|
+
/** Watches the non-Value render input used by the direct `<img src>` form. */
|
|
90
|
+
#srcObserver = new MutationObserver((records) => {
|
|
91
|
+
if (records.some((record) => this.hasImageTarget && record.target === this.imageTarget)) {
|
|
92
|
+
this.#reconcile.schedule();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
/** Starts retained-DOM observation and silently derives the current phase. */
|
|
11
96
|
connect() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
97
|
+
this.#connected = true;
|
|
98
|
+
this.#reconcile.activate();
|
|
99
|
+
this.#srcObserver.observe(this.element, {
|
|
100
|
+
attributes: true,
|
|
101
|
+
attributeFilter: ["src"],
|
|
102
|
+
subtree: true
|
|
103
|
+
});
|
|
104
|
+
this.#render();
|
|
105
|
+
}
|
|
106
|
+
/** Cancels asynchronous work while retaining the last materialized visual state. */
|
|
107
|
+
disconnect() {
|
|
108
|
+
this.#connected = false;
|
|
109
|
+
this.#reconcile.cancel();
|
|
110
|
+
this.#srcObserver.disconnect();
|
|
111
|
+
}
|
|
112
|
+
/** Repaints when application code or a Turbo morph changes the source Value. */
|
|
113
|
+
srcValueChanged() {
|
|
114
|
+
this.#reconcile.schedule();
|
|
115
|
+
}
|
|
116
|
+
/** Applies the current source and phase to an image inserted or replaced at runtime. */
|
|
117
|
+
imageTargetConnected() {
|
|
118
|
+
this.#reconcile.schedule();
|
|
119
|
+
}
|
|
120
|
+
/** Returns attributes borrowed from an image that leaves this live avatar. */
|
|
121
|
+
imageTargetDisconnected(image) {
|
|
122
|
+
if (this.#connected) {
|
|
123
|
+
this.#src.return(image);
|
|
124
|
+
this.#imageHidden.return(image);
|
|
15
125
|
}
|
|
16
|
-
|
|
17
|
-
|
|
126
|
+
this.#reconcile.schedule();
|
|
127
|
+
}
|
|
128
|
+
/** Applies the current phase to a fallback inserted or replaced at runtime. */
|
|
129
|
+
fallbackTargetConnected() {
|
|
130
|
+
this.#reconcile.schedule();
|
|
131
|
+
}
|
|
132
|
+
/** Returns authored visibility when a fallback leaves this live avatar. */
|
|
133
|
+
fallbackTargetDisconnected(fallback) {
|
|
134
|
+
if (this.#connected) this.#fallbackHidden.return(fallback);
|
|
135
|
+
this.#reconcile.schedule();
|
|
136
|
+
}
|
|
137
|
+
/** Reveals the current image after its native `load` event. */
|
|
138
|
+
onLoad(event) {
|
|
139
|
+
const image = this.#eventImage(event);
|
|
140
|
+
if (!image) return;
|
|
141
|
+
if (!image.getAttribute("src")) {
|
|
142
|
+
this.#render();
|
|
143
|
+
return;
|
|
18
144
|
}
|
|
19
|
-
|
|
145
|
+
this.#reflect("loaded");
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reveals the fallback after the current image's native `error` event.
|
|
149
|
+
*
|
|
150
|
+
* Dispatches `stimeo--avatar:error` with `{ src: string }`, where `src` is
|
|
151
|
+
* the attempted attribute value. Empty/stale/detached image events are ignored.
|
|
152
|
+
*/
|
|
153
|
+
onError(event) {
|
|
154
|
+
const image = this.#eventImage(event);
|
|
155
|
+
if (!image) return;
|
|
156
|
+
const src = image.getAttribute("src");
|
|
20
157
|
if (!src) {
|
|
21
|
-
this.#
|
|
158
|
+
this.#render();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.#reflect("error");
|
|
162
|
+
this.dispatch("error", { detail: { src } });
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Materializes the phase from the final source/target DOM after one mutation batch.
|
|
166
|
+
*
|
|
167
|
+
* Cached success and failure are state reconstruction, not new load events, so
|
|
168
|
+
* this pass never dispatches the public `error` event.
|
|
169
|
+
*
|
|
170
|
+
* @stimeoRenderRoot
|
|
171
|
+
*/
|
|
172
|
+
#render() {
|
|
173
|
+
if (!this.hasImageTarget) {
|
|
174
|
+
this.#reflect("empty");
|
|
22
175
|
return;
|
|
23
176
|
}
|
|
24
|
-
|
|
25
|
-
|
|
177
|
+
const image = this.imageTarget;
|
|
178
|
+
const src = this.#applySource(image);
|
|
179
|
+
if (!src) {
|
|
180
|
+
this.#reflect("empty");
|
|
26
181
|
return;
|
|
27
182
|
}
|
|
28
|
-
if (
|
|
29
|
-
this
|
|
183
|
+
if (!image.complete) {
|
|
184
|
+
this.#reflect("loading");
|
|
30
185
|
return;
|
|
31
186
|
}
|
|
32
|
-
this.#
|
|
187
|
+
this.#reflect(image.naturalWidth > 0 ? "loaded" : "error");
|
|
33
188
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
this
|
|
189
|
+
/** Applies Value precedence and returns the effective raw `src` attribute. */
|
|
190
|
+
#applySource(image) {
|
|
191
|
+
if (!this.element.hasAttribute("data-stimeo--avatar-src-value")) {
|
|
192
|
+
this.#src.return(image);
|
|
193
|
+
return image.getAttribute("src");
|
|
194
|
+
}
|
|
195
|
+
const desired = this.srcValue.length > 0 ? this.srcValue : null;
|
|
196
|
+
if (image.getAttribute("src") !== desired) this.#src.write(image, desired);
|
|
197
|
+
return desired;
|
|
37
198
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
this.
|
|
199
|
+
/** Accepts an action only from the singular image target currently controlled. */
|
|
200
|
+
#eventImage(event) {
|
|
201
|
+
const candidate = event.currentTarget;
|
|
202
|
+
if (!(candidate instanceof HTMLImageElement)) return null;
|
|
203
|
+
if (!this.hasImageTarget || candidate !== this.imageTarget) return null;
|
|
204
|
+
return candidate;
|
|
43
205
|
}
|
|
44
|
-
/**
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
if (this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.element.setAttribute("data-state", "loaded");
|
|
55
|
-
}
|
|
56
|
-
/** Error / no-src phase: fallback visible, image hidden. */
|
|
57
|
-
#showFallback() {
|
|
58
|
-
if (this.hasImageTarget) this.imageTarget.hidden = true;
|
|
59
|
-
if (this.hasFallbackTarget) this.fallbackTarget.hidden = false;
|
|
60
|
-
this.element.setAttribute("data-state", "error");
|
|
206
|
+
/** Writes the visibility pair and public root state as one controller-owned output. */
|
|
207
|
+
#reflect(state) {
|
|
208
|
+
const showImage = state === "loading" || state === "loaded";
|
|
209
|
+
if (this.hasImageTarget) {
|
|
210
|
+
this.#imageHidden.write(this.imageTarget, showImage ? null : "");
|
|
211
|
+
}
|
|
212
|
+
if (this.hasFallbackTarget) {
|
|
213
|
+
this.#fallbackHidden.write(this.fallbackTarget, showImage ? "" : null);
|
|
214
|
+
}
|
|
215
|
+
this.element.setAttribute("data-state", state);
|
|
61
216
|
}
|
|
62
217
|
};
|
|
63
218
|
|
|
@@ -287,7 +287,11 @@ var BreadcrumbController = class extends Controller {
|
|
|
287
287
|
this.ellipsisTarget.hidden = true;
|
|
288
288
|
return this.listTarget.scrollWidth > this.listTarget.clientWidth + OVERFLOW_EPSILON;
|
|
289
289
|
}
|
|
290
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* Applies the collapsed/expanded state to the items, ellipsis, and trigger.
|
|
292
|
+
*
|
|
293
|
+
* @stimeoRenderRoot
|
|
294
|
+
*/
|
|
291
295
|
#render() {
|
|
292
296
|
const collapsed = this.#overflowing && !this.#expanded;
|
|
293
297
|
const showEllipsis = this.#overflowing && this.collapsibleTargets.length > 0;
|