stimeo-ui 0.7.0 → 0.9.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.
- package/CHANGELOG.md +151 -0
- package/dist/controllers/auto_submit_controller.d.ts +14 -3
- package/dist/controllers/auto_submit_controller.js +94 -16
- package/dist/controllers/auto_submit_controller.js.map +1 -1
- package/dist/controllers/bulk_select_controller.d.ts +62 -15
- package/dist/controllers/bulk_select_controller.js +139 -28
- package/dist/controllers/bulk_select_controller.js.map +1 -1
- package/dist/controllers/carousel_controller.d.ts +81 -47
- package/dist/controllers/carousel_controller.js +451 -100
- package/dist/controllers/carousel_controller.js.map +1 -1
- package/dist/controllers/clipboard_controller.d.ts +48 -15
- package/dist/controllers/clipboard_controller.js +102 -20
- package/dist/controllers/clipboard_controller.js.map +1 -1
- package/dist/controllers/color_picker_controller.d.ts +37 -6
- package/dist/controllers/color_picker_controller.js +180 -43
- package/dist/controllers/color_picker_controller.js.map +1 -1
- package/dist/controllers/currency_input_controller.d.ts +39 -5
- package/dist/controllers/currency_input_controller.js +305 -74
- package/dist/controllers/currency_input_controller.js.map +1 -1
- package/dist/controllers/data_grid_controller.d.ts +25 -9
- package/dist/controllers/data_grid_controller.js +150 -24
- package/dist/controllers/data_grid_controller.js.map +1 -1
- package/dist/controllers/direct_upload_controller.d.ts +3 -1
- package/dist/controllers/direct_upload_controller.js +12 -2
- package/dist/controllers/direct_upload_controller.js.map +1 -1
- package/dist/controllers/editable_controller.d.ts +34 -9
- package/dist/controllers/editable_controller.js +83 -30
- package/dist/controllers/editable_controller.js.map +1 -1
- package/dist/controllers/file_dropzone_controller.d.ts +123 -29
- package/dist/controllers/file_dropzone_controller.js +386 -63
- package/dist/controllers/file_dropzone_controller.js.map +1 -1
- package/dist/controllers/filter_controller.d.ts +15 -3
- package/dist/controllers/filter_controller.js +32 -1
- package/dist/controllers/filter_controller.js.map +1 -1
- package/dist/controllers/flash_controller.d.ts +3 -1
- package/dist/controllers/flash_controller.js +3 -1
- package/dist/controllers/flash_controller.js.map +1 -1
- package/dist/controllers/frame_loading_controller.d.ts +4 -2
- package/dist/controllers/frame_loading_controller.js +2 -1
- package/dist/controllers/frame_loading_controller.js.map +1 -1
- package/dist/controllers/input_mask_controller.d.ts +42 -16
- package/dist/controllers/input_mask_controller.js +251 -76
- package/dist/controllers/input_mask_controller.js.map +1 -1
- package/dist/controllers/masonry_controller.d.ts +34 -5
- package/dist/controllers/masonry_controller.js +129 -17
- package/dist/controllers/masonry_controller.js.map +1 -1
- package/dist/controllers/nested_form_controller.d.ts +51 -14
- package/dist/controllers/nested_form_controller.js +450 -42
- package/dist/controllers/nested_form_controller.js.map +1 -1
- package/dist/controllers/otp_controller.d.ts +64 -25
- package/dist/controllers/otp_controller.js +485 -114
- package/dist/controllers/otp_controller.js.map +1 -1
- package/dist/controllers/reset_before_cache_controller.d.ts +25 -2
- package/dist/controllers/reset_before_cache_controller.js +51 -5
- package/dist/controllers/reset_before_cache_controller.js.map +1 -1
- package/dist/controllers/resizable_controller.d.ts +23 -7
- package/dist/controllers/resizable_controller.js +128 -55
- package/dist/controllers/resizable_controller.js.map +1 -1
- package/dist/controllers/spinner_controller.d.ts +3 -2
- package/dist/controllers/spinner_controller.js +7 -5
- package/dist/controllers/spinner_controller.js.map +1 -1
- package/dist/controllers/submit_once_controller.d.ts +4 -1
- package/dist/controllers/submit_once_controller.js +3 -1
- package/dist/controllers/submit_once_controller.js.map +1 -1
- package/dist/controllers/textarea_autosize_controller.d.ts +30 -10
- package/dist/controllers/textarea_autosize_controller.js +131 -3
- package/dist/controllers/textarea_autosize_controller.js.map +1 -1
- package/dist/index.js +2764 -923
- package/dist/index.js.map +1 -1
- package/dist/inspector/cli.d.ts +8 -1
- package/dist/inspector/cli.js +5 -1
- package/dist/inspector/cli.js.map +1 -1
- package/dist/inspector/cli_bin.js +5 -1
- package/dist/inspector/cli_bin.js.map +1 -1
- package/dist/inspector/examples.json +24 -24
- package/dist/inspector/manifest.json +193 -30
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,155 @@ 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.9.0] - 2026-08-28
|
|
11
|
+
|
|
12
|
+
Minor release with no new components. Ten existing ones are reworked —
|
|
13
|
+
bulk-select, clipboard, color-picker, data-grid, editable, filter, masonry, otp,
|
|
14
|
+
reset-before-cache, and resizable — and of those, bulk-select, clipboard,
|
|
15
|
+
data-grid, and editable also changed their markup contracts, so read Removed and
|
|
16
|
+
Changed before upgrading. The Inspector manifest stays on schema v12.
|
|
17
|
+
|
|
18
|
+
### Removed
|
|
19
|
+
|
|
20
|
+
- bulk-select: `announce`, and the `aria-live` on the `bar` target that went with
|
|
21
|
+
it — the count goes through the page's `stimeo--announcer` now.
|
|
22
|
+
- clipboard: the live-region requirement on the `feedback` target. Drop the
|
|
23
|
+
`role="status"` and `aria-live`; the slot is a plain visible label.
|
|
24
|
+
- editable: the `onBlur` action. Drop `blur->stimeo--editable#onBlur` — the
|
|
25
|
+
departure is watched on the controller element.
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- bulk-select: `announceText`, carrying `{count}`, and a `reconcile` event.
|
|
30
|
+
- clipboard: `announceCopiedText` and `announceErrorText`. Like `announceText`
|
|
31
|
+
they default to empty, so seat a `stimeo--announcer` on the page and write the
|
|
32
|
+
wording you want read.
|
|
33
|
+
- editable: `save` / `cancel` / `revert` actions, and `data-value` on the
|
|
34
|
+
`display` target for a display that renders the value rather than being it.
|
|
35
|
+
- color-picker: `data-value-text`, an `aria-valuetext` template whose `{value}`
|
|
36
|
+
carries the channel value, for pages that are not in English.
|
|
37
|
+
- Declarations read once are followed when they change — filter's `match`,
|
|
38
|
+
masonry's `minColumnWidth` / `gap`, resizable's `min` / `max` — as are targets
|
|
39
|
+
swapped in later by color-picker, editable, masonry, and resizable, and masonry
|
|
40
|
+
also relays out when a descendant resource finishes loading.
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- bulk-select: `selectAllPages` checks the rows on the page too, so a row that
|
|
45
|
+
arrives while the mode is on lands checked. Hiding the bar hands focus to the
|
|
46
|
+
select-all box, and a `bar` carrying `role="toolbar"` wants `stimeo--toolbar`
|
|
47
|
+
alongside it for the arrow keys and the single tab stop.
|
|
48
|
+
- clipboard: `copied` and `error` are transient `data-state` values — a
|
|
49
|
+
`connect()` that finds either returns to `idle`, and the state is rewound
|
|
50
|
+
before Turbo caches the page. Any other authored `data-state` is left alone.
|
|
51
|
+
- color-picker: `aria-valuenow` / `aria-valuetext` / `aria-valuemin` /
|
|
52
|
+
`aria-valuemax` are controller-owned, so the markup supplies `role="slider"`
|
|
53
|
+
and a name; an omitted range resolves to the channel default (hue `0`–`360`,
|
|
54
|
+
the rest `0`–`100`). Only a primary-button press drags, and an `alpha` slider
|
|
55
|
+
is inert unless `alpha` is on.
|
|
56
|
+
- data-grid: a keystroke or click that reached a control inside a cell, and one
|
|
57
|
+
an IME is composing, belongs to that control — no move, no sort, no selection.
|
|
58
|
+
The exception is a click on a sortable header's own `<button>`, which needs
|
|
59
|
+
`tabindex="-1"`; host `gridcell` / `columnheader` on `td` / `th`.
|
|
60
|
+
- editable: the mode is read back from the DOM and the controller writes no ARIA.
|
|
61
|
+
Focus landing inside the component has not left the edit, so a Save or Cancel
|
|
62
|
+
button beside the input keeps it open, and the value is trimmed once at the save.
|
|
63
|
+
- reset-before-cache: `data-reset-value` returns a field to what the markup
|
|
64
|
+
declares — `defaultValue`, `defaultChecked`, the `selected` option — instead of
|
|
65
|
+
emptying it; a file input empties and `hidden` / `submit` / `reset` / `button` /
|
|
66
|
+
`image` are left alone.
|
|
67
|
+
- resizable: a separator with no `aria-orientation` reads as `horizontal`, and
|
|
68
|
+
`toggle` reopens at the position the pane collapsed from. Pointer capture and
|
|
69
|
+
the drag listeners sit on the `separator` target, not on `event.target` and
|
|
70
|
+
`document`.
|
|
71
|
+
- masonry: `layout` fires when the result moves, not only on a column count
|
|
72
|
+
change, and every relayout after the first is deferred to a microtask. otp:
|
|
73
|
+
`reconcile` reports a move in the pair (joined value, `data-state`).
|
|
74
|
+
- A declaration that cannot be read falls back to its default instead of reaching
|
|
75
|
+
ARIA or CSS as `NaN` — masonry's `minColumnWidth` / `gap`, resizable's `min` /
|
|
76
|
+
`max` / `value` / `step`, bulk-select's `totalCount`, and reset-before-cache's
|
|
77
|
+
`scope`, which no longer aborts the whole sweep.
|
|
78
|
+
- Inspector: clipboard's `feedback` is no longer required, a color-picker
|
|
79
|
+
`slider` is checked for `role` and a name only, and bulk-select and clipboard
|
|
80
|
+
join the components that need a `stimeo--announcer`.
|
|
81
|
+
|
|
82
|
+
### Fixed
|
|
83
|
+
|
|
84
|
+
- data-grid: `Enter` and `Space` on a `<button>` nested in a cell reach it, so a
|
|
85
|
+
row-action button is keyboard-reachable, and rows coming and going at runtime
|
|
86
|
+
re-establish exactly one tab stop. editable: tabbing past a Save or Cancel
|
|
87
|
+
button no longer strands the editor open, and a display removed mid-edit no
|
|
88
|
+
longer throws. bulk-select: a nested bulk-select's rows stay out of the outer
|
|
89
|
+
container's count.
|
|
90
|
+
- clipboard: a copy that resolved after disconnect wrote to the detached element
|
|
91
|
+
and armed a timer past the teardown, and a repeat inside the feedback window is
|
|
92
|
+
read out again. In color-picker a drag belongs to the pointer that started it,
|
|
93
|
+
in masonry an item removed and re-appended in one batch keeps its layout hooks,
|
|
94
|
+
and in resizable `data-dragging` no longer rides a Turbo snapshot.
|
|
95
|
+
- reset-before-cache: `data-reset-value` wrote an empty string into a checkbox's
|
|
96
|
+
`value` attribute, and could leave a select with nothing selected at all.
|
|
97
|
+
|
|
98
|
+
## [0.8.0] - 2026-08-22
|
|
99
|
+
|
|
100
|
+
Minor release with no new components. Eight existing ones are reworked —
|
|
101
|
+
auto-submit, carousel, currency-input, file-dropzone, input-mask, nested-form,
|
|
102
|
+
otp, and textarea-autosize — and of those, carousel, otp, and file-dropzone also
|
|
103
|
+
changed their markup contracts, so read Removed and Changed before upgrading. The
|
|
104
|
+
Inspector manifest stays on schema v12.
|
|
105
|
+
|
|
106
|
+
### Removed
|
|
107
|
+
|
|
108
|
+
- otp: `length` — the number of `field` targets is the passcode length.
|
|
109
|
+
- file-dropzone: the `status` target, `dragLabel`, and the
|
|
110
|
+
`data-file-dropzone-slot` attributes.
|
|
111
|
+
|
|
112
|
+
### Added
|
|
113
|
+
|
|
114
|
+
- `reconcile` on auto-submit, direct-upload, file-dropzone, flash, frame-loading,
|
|
115
|
+
input-mask, nested-form, otp, spinner, and submit-once — it also reports the
|
|
116
|
+
state a Turbo rewind discarded, carrying what that component lost
|
|
117
|
+
(`{ files }`, `{ ids }`, `{ forms }`, `{ removed }`, or `{}`).
|
|
118
|
+
- carousel: `data-state`, `inert` on inactive slides, `prefers-reduced-motion`,
|
|
119
|
+
and optional pickers. otp: `clear` / `onPointerDown`, and text carrying several
|
|
120
|
+
characters spread across the following fields. file-dropzone:
|
|
121
|
+
`allowDuplicates`, a `thumb` target, and the `announce*Text` wording.
|
|
122
|
+
- Characters an IME commits full-width are read as their half-width form in
|
|
123
|
+
input-mask, otp, and currency-input.
|
|
124
|
+
- Inspector: rules for the reworked markup — carousel's controller-owned ARIA,
|
|
125
|
+
the `playToggle` an `autoplay` carousel needs, the `prev` / `next` pair, a
|
|
126
|
+
finite positive `interval`, otp's group and field names, and the parts
|
|
127
|
+
file-dropzone's item template must contain.
|
|
128
|
+
|
|
129
|
+
### Changed
|
|
130
|
+
|
|
131
|
+
- carousel: drop the `data-action` wiring and any authored `aria-pressed` —
|
|
132
|
+
clicks, picker keys, hover, and focus are delegated, and `aria-pressed` /
|
|
133
|
+
`aria-disabled` / `aria-live` / `aria-atomic` are controller-owned. Name the
|
|
134
|
+
toggle with `aria-label`, pair `prev` with `next`, and give an `autoplay`
|
|
135
|
+
carousel a `playToggle` (WCAG 2.2.2).
|
|
136
|
+
- otp: the root needs `role="group"` and a name, and each `field` its own.
|
|
137
|
+
`invalid` reports only input that filled no field.
|
|
138
|
+
- file-dropzone: put a `stimeo--announcer` on the page, set the `announce*Text`
|
|
139
|
+
wording, and use `name` / `thumb` / `remove` targets in the item template with
|
|
140
|
+
an authored `aria-label`. Validation runs `type` → `size` → `duplicate` →
|
|
141
|
+
`count`, and `change` precedes `reject`.
|
|
142
|
+
- input-mask: `change` fires only for a user edit; normalization and runtime
|
|
143
|
+
Value changes report `reconcile`. The manifest reports `tokens` as `String`
|
|
144
|
+
where it reported `Object`.
|
|
145
|
+
- textarea-autosize: `resize` no longer fires when a connect leaves the height
|
|
146
|
+
unchanged; width, font, and runtime `minRows` / `maxRows` changes are followed.
|
|
147
|
+
- currency-input keeps what was typed while typing and rounds on blur;
|
|
148
|
+
nested-form absorbs rows added or removed outside it; auto-submit follows a
|
|
149
|
+
swapped `form` target.
|
|
150
|
+
|
|
151
|
+
### Fixed
|
|
152
|
+
|
|
153
|
+
- carousel: the play toggle stops rotation — the `focusin` before the click no
|
|
154
|
+
longer makes the press resume instead. otp: a full-width commit into one field
|
|
155
|
+
fills the following ones. currency-input: a locale with non-Latin digits
|
|
156
|
+
reparses its own output. nested-form: a discarded-but-visible row's remove
|
|
157
|
+
button no longer swallows the click.
|
|
158
|
+
|
|
10
159
|
## [0.7.0] - 2026-08-16
|
|
11
160
|
|
|
12
161
|
Minor release reworking the form stack, separator, and scroll-area, with
|
|
@@ -634,6 +783,8 @@ Initial public alpha: 101 behavior-only, accessible Stimulus controllers driven
|
|
|
634
783
|
by `data-*` attributes, shipping no CSS. Published to npm (with provenance) and
|
|
635
784
|
RubyGems.
|
|
636
785
|
|
|
786
|
+
[0.9.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.9.0
|
|
787
|
+
[0.8.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.8.0
|
|
637
788
|
[0.7.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.7.0
|
|
638
789
|
[0.6.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.6.0
|
|
639
790
|
[0.5.0]: https://github.com/taiyaky/stimeo-ui/releases/tag/v0.5.0
|
|
@@ -19,6 +19,8 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
19
19
|
* </div>
|
|
20
20
|
*
|
|
21
21
|
* `submit` dispatches `{ trigger }`; `done` dispatches `{ message? }`.
|
|
22
|
+
* `reconcile` dispatches `{}` when the Turbo cache rewind drops a submission
|
|
23
|
+
* that was pending or in flight — `done` would claim a response arrived.
|
|
22
24
|
*
|
|
23
25
|
* @remarks
|
|
24
26
|
* Behavior only — it owns *triggering* the submit (debounce + `requestSubmit`),
|
|
@@ -28,8 +30,13 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
28
30
|
* setting `announce` bridges the completion to the shared `stimeo--announcer`
|
|
29
31
|
* as a safety net; apps can also listen for `stimeo--auto-submit:done`
|
|
30
32
|
* and announce richer text themselves. `aria-busy` marks the in-flight window and
|
|
31
|
-
* `data-auto-submit-pending` the debounce window, for consumer CSS
|
|
32
|
-
*
|
|
33
|
+
* `data-auto-submit-pending` the debounce window, for consumer CSS; both hooks are
|
|
34
|
+
* rewound just before Turbo caches the page so they never burn into a snapshot.
|
|
35
|
+
* The `turbo:submit-end`/composition subscriptions follow the `form` target as it
|
|
36
|
+
* is added, replaced, or removed at runtime; unbinding a form drops its pending
|
|
37
|
+
* debounced submit, since that submit described a form that is going away. With
|
|
38
|
+
* no resolvable form (no target and a non-`<form>` root) the controller is inert.
|
|
39
|
+
* During IME composition it holds the submit until `compositionend` (the confirmed
|
|
33
40
|
* conversion) so it does not fire on each intermediate keystroke. The debounce
|
|
34
41
|
* timer and the `turbo:submit-end`/composition listeners are torn down on
|
|
35
42
|
* `disconnect()`.
|
|
@@ -56,7 +63,7 @@ declare class AutoSubmitController extends Controller<HTMLElement> {
|
|
|
56
63
|
};
|
|
57
64
|
};
|
|
58
65
|
static actions: readonly ["submit"];
|
|
59
|
-
static events: readonly ["submit", "done"];
|
|
66
|
+
static events: readonly ["submit", "done", "reconcile"];
|
|
60
67
|
readonly formTarget: HTMLFormElement;
|
|
61
68
|
readonly hasFormTarget: boolean;
|
|
62
69
|
debounceValue: number;
|
|
@@ -65,6 +72,10 @@ declare class AutoSubmitController extends Controller<HTMLElement> {
|
|
|
65
72
|
messageValue: string;
|
|
66
73
|
connect(): void;
|
|
67
74
|
disconnect(): void;
|
|
75
|
+
/** Follows a `form` target added (or swapped in) at runtime. */
|
|
76
|
+
formTargetConnected(): void;
|
|
77
|
+
/** Follows a `form` target removed (or swapped out) at runtime. */
|
|
78
|
+
formTargetDisconnected(): void;
|
|
68
79
|
/**
|
|
69
80
|
* Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an
|
|
70
81
|
* allowlist so a configured subset (e.g. only `change`) is honored even when both
|
|
@@ -2,6 +2,35 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
2
2
|
|
|
3
3
|
// src/controllers/auto_submit_controller.ts
|
|
4
4
|
|
|
5
|
+
// src/utils/before_cache_reset.ts
|
|
6
|
+
var BeforeCacheReset = class _BeforeCacheReset {
|
|
7
|
+
/** Every subscribed instance, iterated by the one shared document listener. */
|
|
8
|
+
static #subscribers = /* @__PURE__ */ new Set();
|
|
9
|
+
/** The shared listener; installed while at least one instance is subscribed. */
|
|
10
|
+
static #onBeforeCache = () => {
|
|
11
|
+
for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
|
|
12
|
+
};
|
|
13
|
+
#rewind;
|
|
14
|
+
/** @param rewind - the pass that returns this controller's state to its initial form. */
|
|
15
|
+
constructor(rewind) {
|
|
16
|
+
this.#rewind = rewind;
|
|
17
|
+
}
|
|
18
|
+
/** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
|
|
19
|
+
activate() {
|
|
20
|
+
const first = _BeforeCacheReset.#subscribers.size === 0;
|
|
21
|
+
_BeforeCacheReset.#subscribers.add(this);
|
|
22
|
+
if (first) {
|
|
23
|
+
document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
|
|
27
|
+
deactivate() {
|
|
28
|
+
_BeforeCacheReset.#subscribers.delete(this);
|
|
29
|
+
if (_BeforeCacheReset.#subscribers.size > 0) return;
|
|
30
|
+
document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
5
34
|
// src/utils/composition_tracker.ts
|
|
6
35
|
var CompositionTracker = class {
|
|
7
36
|
#observedTargets = /* @__PURE__ */ new Set();
|
|
@@ -112,14 +141,18 @@ var AutoSubmitController = class extends Controller {
|
|
|
112
141
|
message: { type: String, default: "" }
|
|
113
142
|
};
|
|
114
143
|
static actions = ["submit"];
|
|
115
|
-
static events = ["submit", "done"];
|
|
144
|
+
static events = ["submit", "done", "reconcile"];
|
|
116
145
|
/** Debounce timer registry; one `clearAll()` in disconnect tears it down. */
|
|
117
146
|
#timers = new SafeTimeout();
|
|
118
147
|
/** Id of the pending debounce timer, so a new keystroke can reset it. */
|
|
119
148
|
#pendingId = 0;
|
|
149
|
+
/** The form the listeners are attached to; target callbacks rebind it. */
|
|
150
|
+
#boundForm = null;
|
|
151
|
+
/** Rewinds the transient state hooks just before Turbo snapshots the page. */
|
|
152
|
+
#beforeCache = new BeforeCacheReset(() => this.#rewindForCache());
|
|
120
153
|
/** Clears `aria-busy` and emits completion once Turbo finishes the submit. */
|
|
121
154
|
#onSubmitEnd = () => {
|
|
122
|
-
this.#
|
|
155
|
+
this.#boundForm?.removeAttribute("aria-busy");
|
|
123
156
|
const message = this.messageValue;
|
|
124
157
|
this.dispatch("done", { detail: { message: message || void 0 } });
|
|
125
158
|
if (this.announceValue && message) {
|
|
@@ -133,15 +166,23 @@ var AutoSubmitController = class extends Controller {
|
|
|
133
166
|
}
|
|
134
167
|
});
|
|
135
168
|
connect() {
|
|
136
|
-
this.#
|
|
137
|
-
this.#
|
|
169
|
+
this.#beforeCache.activate();
|
|
170
|
+
this.#bindForm(this.#resolveForm());
|
|
138
171
|
}
|
|
139
172
|
disconnect() {
|
|
173
|
+
this.#beforeCache.deactivate();
|
|
174
|
+
this.#bindForm(null);
|
|
175
|
+
this.#composition.disconnect();
|
|
140
176
|
this.#timers.clearAll();
|
|
141
177
|
this.#pendingId = 0;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
178
|
+
}
|
|
179
|
+
/** Follows a `form` target added (or swapped in) at runtime. */
|
|
180
|
+
formTargetConnected() {
|
|
181
|
+
this.#bindForm(this.#resolveForm());
|
|
182
|
+
}
|
|
183
|
+
/** Follows a `form` target removed (or swapped out) at runtime. */
|
|
184
|
+
formTargetDisconnected() {
|
|
185
|
+
this.#bindForm(this.#resolveForm());
|
|
145
186
|
}
|
|
146
187
|
/**
|
|
147
188
|
* Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an
|
|
@@ -155,21 +196,58 @@ var AutoSubmitController = class extends Controller {
|
|
|
155
196
|
}
|
|
156
197
|
/** Schedules (and coalesces) the debounced submit for the given trigger. */
|
|
157
198
|
#schedule(trigger) {
|
|
158
|
-
this.#
|
|
159
|
-
if (
|
|
199
|
+
const form = this.#boundForm;
|
|
200
|
+
if (!form) return;
|
|
201
|
+
form.setAttribute("data-auto-submit-pending", "true");
|
|
202
|
+
this.#cancelPending();
|
|
160
203
|
this.#pendingId = this.#timers.set(() => {
|
|
161
204
|
this.#pendingId = 0;
|
|
162
|
-
|
|
205
|
+
form.removeAttribute("data-auto-submit-pending");
|
|
163
206
|
this.dispatch("submit", { detail: { trigger } });
|
|
164
|
-
if (
|
|
165
|
-
|
|
207
|
+
if (form.checkValidity()) {
|
|
208
|
+
form.setAttribute("aria-busy", "true");
|
|
166
209
|
}
|
|
167
|
-
|
|
210
|
+
form.requestSubmit();
|
|
168
211
|
}, this.debounceValue);
|
|
169
212
|
}
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
|
|
213
|
+
/** Cancels the pending debounced submit, if any (`clear` no-ops on unknown ids). */
|
|
214
|
+
#cancelPending() {
|
|
215
|
+
this.#timers.clear(this.#pendingId);
|
|
216
|
+
this.#pendingId = 0;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Replaces the subscribed form symmetrically. The outgoing form loses the
|
|
220
|
+
* `turbo:submit-end`/composition listeners, its pending hook, and any pending
|
|
221
|
+
* debounced submit (which described the outgoing form). An in-flight `aria-busy`
|
|
222
|
+
* is left for `turbo:submit-end` or the pre-cache rewind — removing it here
|
|
223
|
+
* would wipe a legitimately in-progress submission.
|
|
224
|
+
*/
|
|
225
|
+
#bindForm(form) {
|
|
226
|
+
if (form === this.#boundForm) return;
|
|
227
|
+
const previous = this.#boundForm;
|
|
228
|
+
if (previous) {
|
|
229
|
+
this.#cancelPending();
|
|
230
|
+
previous.removeAttribute("data-auto-submit-pending");
|
|
231
|
+
previous.removeEventListener("turbo:submit-end", this.#onSubmitEnd);
|
|
232
|
+
this.#composition.unobserve(previous);
|
|
233
|
+
}
|
|
234
|
+
this.#boundForm = form;
|
|
235
|
+
if (!form) return;
|
|
236
|
+
form.addEventListener("turbo:submit-end", this.#onSubmitEnd);
|
|
237
|
+
this.#composition.observe(form);
|
|
238
|
+
}
|
|
239
|
+
/** Resolves the form: the explicit `form` target, else a `<form>` root, else null. */
|
|
240
|
+
#resolveForm() {
|
|
241
|
+
if (this.hasFormTarget) return this.formTarget;
|
|
242
|
+
return this.element instanceof HTMLFormElement ? this.element : null;
|
|
243
|
+
}
|
|
244
|
+
/** Returns the transient state hooks to their initial (absent) state. */
|
|
245
|
+
#rewindForCache() {
|
|
246
|
+
const inProgress = this.#pendingId !== 0 || this.#boundForm?.hasAttribute("aria-busy") === true;
|
|
247
|
+
this.#cancelPending();
|
|
248
|
+
this.#boundForm?.removeAttribute("data-auto-submit-pending");
|
|
249
|
+
this.#boundForm?.removeAttribute("aria-busy");
|
|
250
|
+
if (inProgress) this.dispatch("reconcile", { detail: {} });
|
|
173
251
|
}
|
|
174
252
|
/** Whether `type` is one of the whitespace-separated event types in `on`. */
|
|
175
253
|
#triggers(type) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/composition_tracker.ts","../../src/utils/safe_timeout.ts","../../src/controllers/auto_submit_controller.ts"],"names":[],"mappings":";;;;;AAuCO,IAAM,qBAAN,MAAyB;AAAA,EACrB,gBAAA,uBAAuB,GAAA,EAAiB;AAAA,EACxC,cAAA,uBAAqB,GAAA,EAAiB;AAAA,EACtC,QAAA;AAAA,EACA,MAAA;AAAA,EAET,WAAA,CAAY,OAAA,GAAqC,EAAC,EAAG;AACnD,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,OAAA;AACxB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,KAAA;AAAA,EACxB;AAAA;AAAA,EAGA,QAAQ,MAAA,EAA2B;AACjC,IAAA,IAAI,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAI,MAAM,CAAA,EAAG;AACvC,IAAA,MAAA,CAAO,gBAAA,CAAiB,kBAAA,EAAoB,IAAA,CAAK,YAAY,CAAA;AAC7D,IAAA,MAAA,CAAO,gBAAA,CAAiB,gBAAA,EAAkB,IAAA,CAAK,UAAU,CAAA;AACzD,IAAA,IAAA,CAAK,gBAAA,CAAiB,IAAI,MAAM,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,UAAU,MAAA,EAA2B;AACnC,IAAA,IAAI,CAAC,IAAA,CAAK,gBAAA,CAAiB,MAAA,CAAO,MAAM,CAAA,EAAG;AAC3C,IAAA,MAAA,CAAO,mBAAA,CAAoB,kBAAA,EAAoB,IAAA,CAAK,YAAY,CAAA;AAChE,IAAA,MAAA,CAAO,mBAAA,CAAoB,gBAAA,EAAkB,IAAA,CAAK,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IAAA,CAAK,MAAM,aAAA,EAAc;AAAA,IAC3B,CAAA,EAAG,KAAK,aAAa,CAAA;AAAA,EACvB;AAAA;AAAA,EAGA,IAAI,KAAA,GAAyB;AAC3B,IAAA,OAAO,IAAA,CAAK,aAAA,GAAgB,IAAA,CAAK,UAAA,GAAc,IAAA,CAAK,OAAA;AAAA,EACtD;AAAA;AAAA,EAGA,UAAU,IAAA,EAAuB;AAC/B,IAAA,OAAO,IAAA,CAAK,QAAQ,KAAA,CAAM,KAAK,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA;AAAA,EAChE;AACF","file":"auto_submit_controller.js","sourcesContent":["/** Minimal event shape carrying the platform's per-event composition signal. */\nexport interface CompositionSignal {\n readonly isComposing?: boolean;\n}\n\n/** Hooks that keep component-specific work outside {@link CompositionTracker}. */\nexport interface CompositionTrackerOptions {\n /** Runs after lifecycle state is set for a `compositionstart` event. */\n readonly onStart?: (event: Event) => void;\n /** Runs after lifecycle state is cleared for a `compositionend` event. */\n readonly onEnd?: (event: Event) => void;\n}\n\n/**\n * Owns IME composition listeners and transient state for one or more event targets.\n *\n * Some browsers omit `KeyboardEvent.isComposing` on the keydown that confirms a\n * conversion. Tracking `compositionstart` through `compositionend` supplies the\n * missing lifecycle signal without relying on deprecated numeric key codes.\n * Component policy stays with the consumer: filtering, validation, and submission\n * belong in the optional {@link CompositionTrackerOptions.onEnd} callback.\n *\n * @example\n * ```ts\n * #composition = new CompositionTracker({ onEnd: () => this.filter() });\n *\n * connect(): void {\n * this.#composition.observe(this.inputTarget);\n * }\n *\n * disconnect(): void {\n * this.#composition.disconnect();\n * }\n *\n * onKeydown(event: KeyboardEvent): void {\n * if (this.#composition.isComposing(event)) return;\n * }\n * ```\n */\nexport class CompositionTracker {\n readonly #observedTargets = new Set<EventTarget>();\n readonly #activeTargets = new Set<EventTarget>();\n readonly #onStart: ((event: Event) => void) | undefined;\n readonly #onEnd: ((event: Event) => void) | undefined;\n\n constructor(options: CompositionTrackerOptions = {}) {\n this.#onStart = options.onStart;\n this.#onEnd = options.onEnd;\n }\n\n /** Starts lifecycle tracking for `target`; repeated calls are idempotent. */\n observe(target: EventTarget): void {\n if (this.#observedTargets.has(target)) return;\n target.addEventListener(\"compositionstart\", this.#handleStart);\n target.addEventListener(\"compositionend\", this.#handleEnd);\n this.#observedTargets.add(target);\n }\n\n /** Stops tracking one target and clears any active composition it owned. */\n unobserve(target: EventTarget): void {\n if (!this.#observedTargets.delete(target)) return;\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n this.#activeTargets.delete(target);\n }\n\n /** Releases every listener and clears state so reconnect starts cleanly. */\n disconnect(): void {\n for (const target of this.#observedTargets) {\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n }\n this.#observedTargets.clear();\n this.#activeTargets.clear();\n }\n\n /** True when lifecycle tracking or the current event reports composition. */\n isComposing(event?: CompositionSignal): boolean {\n return this.#activeTargets.size > 0 || event?.isComposing === true;\n }\n\n readonly #handleStart = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.add(event.currentTarget);\n this.#onStart?.(event);\n };\n\n readonly #handleEnd = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);\n this.#onEnd?.(event);\n };\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { CompositionTracker } from \"../utils/composition_tracker\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless **debounced auto-submit** for forms (no dedicated APG pattern). Submits\n * the form a configurable delay after `input`/`change`, so Rails search/filter\n * forms refresh via Turbo without a submit button.\n *\n * Markup contract (identifier: `stimeo--auto-submit`):\n * <form data-controller=\"stimeo--auto-submit\"\n * data-stimeo--auto-submit-debounce-value=\"300\"\n * data-action=\"input->stimeo--auto-submit#submit\n * change->stimeo--auto-submit#submit\">\n * <input type=\"search\" name=\"q\">\n * </form>\n *\n * <!-- Or with the form as a target nested under the controller element: -->\n * <div data-controller=\"stimeo--auto-submit\">\n * <form data-stimeo--auto-submit-target=\"form\"> … </form>\n * </div>\n *\n * `submit` dispatches `{ trigger }`; `done` dispatches `{ message? }`.\n *\n * @remarks\n * Behavior only — it owns *triggering* the submit (debounce + `requestSubmit`),\n * never the submit itself (Turbo / native form submission) or validation. It\n * **never moves focus** (WCAG 2.2 3.2.2 / 4.1.3): auto-submitting must not yank the\n * caret out of the field. While a result swap is silent for screen-reader users,\n * setting `announce` bridges the completion to the shared `stimeo--announcer`\n * as a safety net; apps can also listen for `stimeo--auto-submit:done`\n * and announce richer text themselves. `aria-busy` marks the in-flight window and\n * `data-auto-submit-pending` the debounce window, for consumer CSS. During IME\n * composition it holds the submit until `compositionend` (the confirmed\n * conversion) so it does not fire on each intermediate keystroke. The debounce\n * timer and the `turbo:submit-end`/composition listeners are torn down on\n * `disconnect()`.\n */\nexport class AutoSubmitController extends Controller<HTMLElement> {\n static override targets = [\"form\"];\n static override values = {\n debounce: { type: Number, default: 300 },\n on: { type: String, default: \"input change\" },\n announce: { type: Boolean, default: false },\n message: { type: String, default: \"\" },\n };\n static actions = [\"submit\"] as const;\n static events = [\"submit\", \"done\"] as const;\n\n declare readonly formTarget: HTMLFormElement;\n declare readonly hasFormTarget: boolean;\n\n declare debounceValue: number;\n declare onValue: string;\n declare announceValue: boolean;\n declare messageValue: string;\n\n /** Debounce timer registry; one `clearAll()` in disconnect tears it down. */\n readonly #timers = new SafeTimeout();\n /** Id of the pending debounce timer, so a new keystroke can reset it. */\n #pendingId = 0;\n\n /** Clears `aria-busy` and emits completion once Turbo finishes the submit. */\n readonly #onSubmitEnd = (): void => {\n this.#form.removeAttribute(\"aria-busy\");\n const message = this.messageValue;\n this.dispatch(\"done\", { detail: { message: message || undefined } });\n // Bridge the silent result swap to the shared Announcer so SR users hear it.\n if (this.announceValue && message) {\n window.dispatchEvent(new CustomEvent(\"stimeo--announcer:announce\", { detail: { message } }));\n }\n };\n\n /** Owns delegated IME lifecycle state and submits confirmed input text. */\n readonly #composition = new CompositionTracker({\n onEnd: (event) => {\n if (this.#triggers(\"input\")) this.#schedule((event.target as HTMLElement | null) ?? null);\n },\n });\n\n override connect(): void {\n this.#form.addEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#composition.observe(this.#form);\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n this.#pendingId = 0;\n this.#composition.disconnect();\n this.#form.removeAttribute(\"data-auto-submit-pending\");\n this.#form.removeEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n }\n\n /**\n * Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an\n * allowlist so a configured subset (e.g. only `change`) is honored even when both\n * are bound in markup. Coalesces rapid events into a single `requestSubmit`.\n */\n submit(event: Event): void {\n if (!this.#triggers(event.type)) return;\n // Ignore `input` events fired mid-IME-composition (e.g. typing kana before the\n // Japanese conversion is confirmed); the confirmed text submits on\n // `compositionend` and the browser's final post-composition `input`.\n if (event.type === \"input\" && this.#composition.isComposing(event as InputEvent)) return;\n this.#schedule((event.target as HTMLElement | null) ?? null);\n }\n\n /** Schedules (and coalesces) the debounced submit for the given trigger. */\n #schedule(trigger: HTMLElement | null): void {\n this.#form.setAttribute(\"data-auto-submit-pending\", \"true\");\n if (this.#pendingId) this.#timers.clear(this.#pendingId);\n\n this.#pendingId = this.#timers.set(() => {\n this.#pendingId = 0;\n this.#form.removeAttribute(\"data-auto-submit-pending\");\n this.dispatch(\"submit\", { detail: { trigger } });\n // `requestSubmit()` runs native constraint validation. If the form is\n // invalid the actual submit never happens — the browser blocks it (or, when\n // a `stimeo--form-validation` set `novalidate`, that controller cancels the\n // submit) — so no `turbo:submit-end` arrives to clear `aria-busy`. Only mark\n // the form busy when the submit will really proceed; still call\n // `requestSubmit()` either way so the validation surfaces to the user.\n if (this.#form.checkValidity()) {\n this.#form.setAttribute(\"aria-busy\", \"true\");\n }\n this.#form.requestSubmit();\n }, this.debounceValue);\n }\n\n /** Resolves the form element (explicit `form` target, else the controller root). */\n get #form(): HTMLFormElement {\n return this.hasFormTarget ? this.formTarget : (this.element as HTMLFormElement);\n }\n\n /** Whether `type` is one of the whitespace-separated event types in `on`. */\n #triggers(type: string): boolean {\n return this.onValue.split(/\\s+/).filter(Boolean).includes(type);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/before_cache_reset.ts","../../src/utils/composition_tracker.ts","../../src/utils/safe_timeout.ts","../../src/controllers/auto_submit_controller.ts"],"names":[],"mappings":";;;;;AA2CO,IAAM,gBAAA,GAAN,MAAM,iBAAA,CAAiB;AAAA;AAAA,EAE5B,OAAgB,YAAA,mBAAe,IAAI,GAAA,E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A,EAAoB,IAAA,CAAK,YAAY,CAAA;AAClE,MAAA,IAAA,CAAK,YAAA,CAAa,UAAU,QAAQ,CAAA;AAAA,IACtC;AACA,IAAA,IAAA,CAAK,UAAA,GAAa,IAAA;AAClB,IAAA,IAAI,CAAC,IAAA,EAAM;AACX,IAAA,IAAA,CAAK,gBAAA,CAAiB,kBAAA,EAAoB,IAAA,CAAK,YAAY,CAAA;AAC3D,IAAA,IAAA,CAAK,YAAA,CAAa,QAAQ,IAAI,CAAA;AAAA,EAChC;AAAA;AAAA,EAGA,YAAA,GAAuC;AACrC,IAAA,IAAI,IAAA,CAAK,aAAA,EAAe,OAAO,IAAA,CAAK,UAAA;AACpC,IAAA,OAAO,IAAA,CAAK,OAAA,YAAmB,eAAA,GAAkB,IAAA,CAAK,OAAA,GAAU,IAAA;AAAA,EAClE;AAAA;AAAA,EAGA,eAAA,GAAwB;AACtB,IAAA,MAAM,UAAA,GAAa,KAAK,UAAA,KAAe,CAAA,IAAK,KAAK,UAAA,EAAY,YAAA,CAAa,WAAW,CAAA,KAAM,IAAA;AAC3F,IAAA,IAAA,CAAK,cAAA,EAAe;AACpB,IAAA,IAAA,CAAK,UAAA,EAAY,gBAAgB,0BAA0B,CAAA;AAC3D,IAAA,IAAA,CAAK,UAAA,EAAY,gBAAgB,WAAW,CAAA;AAC5C,IAAA,IAAI,UAAA,OAAiB,QAAA,CAAS,WAAA,EAAa,EAAE,MAAA,EAAQ,IAAI,CAAA;AAAA,EAC3D;AAAA;AAAA,EAGA,UAAU,IAAA,EAAuB;AAC/B,IAAA,OAAO,IAAA,CAAK,QAAQ,KAAA,CAAM,KAAK,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA;AAAA,EAChE;AACF","file":"auto_submit_controller.js","sourcesContent":["/**\n * Runs a controller's \"return to the initial state\" pass just before Turbo\n * caches the page.\n *\n * **`disconnect()` cannot do this job, for two independent reasons.** Turbo\n * queues the clone from this event rather than taking it here, and the body swap\n * that runs the controller's `disconnect()` is queued separately — so which of\n * the two lands first is not something a controller can rely on, and a rewind\n * written in `disconnect()` may reach only the DOM being thrown away. In the\n * other direction, `disconnect()` also fires on an in-page move (Stimulus tears\n * down and reconnects the same element), where rewinding would wipe a\n * legitimately in-progress interaction — a spinner mid-load would vanish. One\n * timing is unreliable, the other is too eager; `turbo:before-cache` is the only\n * point that is exactly \"the page is about to be frozen\".\n *\n * Scope is the subscription only: registering on `activate()`, unregistering on\n * `deactivate()`, and one shared document listener no matter how many instances\n * are live. *What* to return to its initial state — which `data-state`, which\n * `hidden`, which `aria-busy` — stays in the controller, because no two\n * consumers answer it the same way (the `MicrotaskCoalescer` split).\n *\n * **Rewind state, not appearance.** The pass writes attributes the controller\n * itself owns; the visual result of those attributes is the consumer's CSS, and\n * a library that reached for style or class names would be guessing at markup\n * it does not own.\n *\n * Both entry points are idempotent, so the lifecycle hooks can call them\n * unconditionally: a second `activate()` does not double-subscribe and does not\n * make the callback run twice, and `deactivate()` on an instance that never\n * subscribed is a no-op.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #beforeCache = new BeforeCacheReset(() => this.#rewind());\n *\n * connect() { this.#beforeCache.activate(); }\n * disconnect() { this.#beforeCache.deactivate(); }\n * ```\n */\nexport class BeforeCacheReset {\n /** Every subscribed instance, iterated by the one shared document listener. */\n static readonly #subscribers = new Set<BeforeCacheReset>();\n\n /** The shared listener; installed while at least one instance is subscribed. */\n static readonly #onBeforeCache = (): void => {\n for (const subscriber of BeforeCacheReset.#subscribers) subscriber.#rewind();\n };\n\n readonly #rewind: () => void;\n\n /** @param rewind - the pass that returns this controller's state to its initial form. */\n constructor(rewind: () => void) {\n this.#rewind = rewind;\n }\n\n /** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */\n activate(): void {\n const first = BeforeCacheReset.#subscribers.size === 0;\n BeforeCacheReset.#subscribers.add(this);\n if (first) {\n document.addEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n }\n\n /** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */\n deactivate(): void {\n BeforeCacheReset.#subscribers.delete(this);\n if (BeforeCacheReset.#subscribers.size > 0) return;\n document.removeEventListener(\"turbo:before-cache\", BeforeCacheReset.#onBeforeCache);\n }\n}\n","/** Minimal event shape carrying the platform's per-event composition signal. */\nexport interface CompositionSignal {\n readonly isComposing?: boolean;\n}\n\n/** Hooks that keep component-specific work outside {@link CompositionTracker}. */\nexport interface CompositionTrackerOptions {\n /** Runs after lifecycle state is set for a `compositionstart` event. */\n readonly onStart?: (event: Event) => void;\n /** Runs after lifecycle state is cleared for a `compositionend` event. */\n readonly onEnd?: (event: Event) => void;\n}\n\n/**\n * Owns IME composition listeners and transient state for one or more event targets.\n *\n * Some browsers omit `KeyboardEvent.isComposing` on the keydown that confirms a\n * conversion. Tracking `compositionstart` through `compositionend` supplies the\n * missing lifecycle signal without relying on deprecated numeric key codes.\n * Component policy stays with the consumer: filtering, validation, and submission\n * belong in the optional {@link CompositionTrackerOptions.onEnd} callback.\n *\n * @example\n * ```ts\n * #composition = new CompositionTracker({ onEnd: () => this.filter() });\n *\n * connect(): void {\n * this.#composition.observe(this.inputTarget);\n * }\n *\n * disconnect(): void {\n * this.#composition.disconnect();\n * }\n *\n * onKeydown(event: KeyboardEvent): void {\n * if (this.#composition.isComposing(event)) return;\n * }\n * ```\n */\nexport class CompositionTracker {\n readonly #observedTargets = new Set<EventTarget>();\n readonly #activeTargets = new Set<EventTarget>();\n readonly #onStart: ((event: Event) => void) | undefined;\n readonly #onEnd: ((event: Event) => void) | undefined;\n\n constructor(options: CompositionTrackerOptions = {}) {\n this.#onStart = options.onStart;\n this.#onEnd = options.onEnd;\n }\n\n /** Starts lifecycle tracking for `target`; repeated calls are idempotent. */\n observe(target: EventTarget): void {\n if (this.#observedTargets.has(target)) return;\n target.addEventListener(\"compositionstart\", this.#handleStart);\n target.addEventListener(\"compositionend\", this.#handleEnd);\n this.#observedTargets.add(target);\n }\n\n /** Stops tracking one target and clears any active composition it owned. */\n unobserve(target: EventTarget): void {\n if (!this.#observedTargets.delete(target)) return;\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n this.#activeTargets.delete(target);\n }\n\n /** Releases every listener and clears state so reconnect starts cleanly. */\n disconnect(): void {\n for (const target of this.#observedTargets) {\n target.removeEventListener(\"compositionstart\", this.#handleStart);\n target.removeEventListener(\"compositionend\", this.#handleEnd);\n }\n this.#observedTargets.clear();\n this.#activeTargets.clear();\n }\n\n /** True when lifecycle tracking or the current event reports composition. */\n isComposing(event?: CompositionSignal): boolean {\n return this.#activeTargets.size > 0 || event?.isComposing === true;\n }\n\n readonly #handleStart = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.add(event.currentTarget);\n this.#onStart?.(event);\n };\n\n readonly #handleEnd = (event: Event): void => {\n if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);\n this.#onEnd?.(event);\n };\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { CompositionTracker } from \"../utils/composition_tracker\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/**\n * Headless **debounced auto-submit** for forms (no dedicated APG pattern). Submits\n * the form a configurable delay after `input`/`change`, so Rails search/filter\n * forms refresh via Turbo without a submit button.\n *\n * Markup contract (identifier: `stimeo--auto-submit`):\n * <form data-controller=\"stimeo--auto-submit\"\n * data-stimeo--auto-submit-debounce-value=\"300\"\n * data-action=\"input->stimeo--auto-submit#submit\n * change->stimeo--auto-submit#submit\">\n * <input type=\"search\" name=\"q\">\n * </form>\n *\n * <!-- Or with the form as a target nested under the controller element: -->\n * <div data-controller=\"stimeo--auto-submit\">\n * <form data-stimeo--auto-submit-target=\"form\"> … </form>\n * </div>\n *\n * `submit` dispatches `{ trigger }`; `done` dispatches `{ message? }`.\n * `reconcile` dispatches `{}` when the Turbo cache rewind drops a submission\n * that was pending or in flight — `done` would claim a response arrived.\n *\n * @remarks\n * Behavior only — it owns *triggering* the submit (debounce + `requestSubmit`),\n * never the submit itself (Turbo / native form submission) or validation. It\n * **never moves focus** (WCAG 2.2 3.2.2 / 4.1.3): auto-submitting must not yank the\n * caret out of the field. While a result swap is silent for screen-reader users,\n * setting `announce` bridges the completion to the shared `stimeo--announcer`\n * as a safety net; apps can also listen for `stimeo--auto-submit:done`\n * and announce richer text themselves. `aria-busy` marks the in-flight window and\n * `data-auto-submit-pending` the debounce window, for consumer CSS; both hooks are\n * rewound just before Turbo caches the page so they never burn into a snapshot.\n * The `turbo:submit-end`/composition subscriptions follow the `form` target as it\n * is added, replaced, or removed at runtime; unbinding a form drops its pending\n * debounced submit, since that submit described a form that is going away. With\n * no resolvable form (no target and a non-`<form>` root) the controller is inert.\n * During IME composition it holds the submit until `compositionend` (the confirmed\n * conversion) so it does not fire on each intermediate keystroke. The debounce\n * timer and the `turbo:submit-end`/composition listeners are torn down on\n * `disconnect()`.\n */\nexport class AutoSubmitController extends Controller<HTMLElement> {\n static override targets = [\"form\"];\n static override values = {\n debounce: { type: Number, default: 300 },\n on: { type: String, default: \"input change\" },\n announce: { type: Boolean, default: false },\n message: { type: String, default: \"\" },\n };\n static actions = [\"submit\"] as const;\n static events = [\"submit\", \"done\", \"reconcile\"] as const;\n\n declare readonly formTarget: HTMLFormElement;\n declare readonly hasFormTarget: boolean;\n\n declare debounceValue: number;\n declare onValue: string;\n declare announceValue: boolean;\n declare messageValue: string;\n\n /** Debounce timer registry; one `clearAll()` in disconnect tears it down. */\n readonly #timers = new SafeTimeout();\n /** Id of the pending debounce timer, so a new keystroke can reset it. */\n #pendingId = 0;\n /** The form the listeners are attached to; target callbacks rebind it. */\n #boundForm: HTMLFormElement | null = null;\n /** Rewinds the transient state hooks just before Turbo snapshots the page. */\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n\n /** Clears `aria-busy` and emits completion once Turbo finishes the submit. */\n readonly #onSubmitEnd = (): void => {\n this.#boundForm?.removeAttribute(\"aria-busy\");\n const message = this.messageValue;\n this.dispatch(\"done\", { detail: { message: message || undefined } });\n // Bridge the silent result swap to the shared Announcer so SR users hear it.\n if (this.announceValue && message) {\n window.dispatchEvent(new CustomEvent(\"stimeo--announcer:announce\", { detail: { message } }));\n }\n };\n\n /** Owns delegated IME lifecycle state and submits confirmed input text. */\n readonly #composition = new CompositionTracker({\n onEnd: (event) => {\n if (this.#triggers(\"input\")) this.#schedule((event.target as HTMLElement | null) ?? null);\n },\n });\n\n override connect(): void {\n this.#beforeCache.activate();\n this.#bindForm(this.#resolveForm());\n }\n\n override disconnect(): void {\n this.#beforeCache.deactivate();\n this.#bindForm(null);\n this.#composition.disconnect();\n this.#timers.clearAll();\n this.#pendingId = 0;\n }\n\n /** Follows a `form` target added (or swapped in) at runtime. */\n formTargetConnected(): void {\n this.#bindForm(this.#resolveForm());\n }\n\n /** Follows a `form` target removed (or swapped out) at runtime. */\n formTargetDisconnected(): void {\n this.#bindForm(this.#resolveForm());\n }\n\n /**\n * Schedules a debounced submit. Wired to `input`/`change`; the `on` value is an\n * allowlist so a configured subset (e.g. only `change`) is honored even when both\n * are bound in markup. Coalesces rapid events into a single `requestSubmit`.\n */\n submit(event: Event): void {\n if (!this.#triggers(event.type)) return;\n // Ignore `input` events fired mid-IME-composition (e.g. typing kana before the\n // Japanese conversion is confirmed); the confirmed text submits on\n // `compositionend` and the browser's final post-composition `input`.\n if (event.type === \"input\" && this.#composition.isComposing(event as InputEvent)) return;\n this.#schedule((event.target as HTMLElement | null) ?? null);\n }\n\n /** Schedules (and coalesces) the debounced submit for the given trigger. */\n #schedule(trigger: HTMLElement | null): void {\n const form = this.#boundForm;\n if (!form) return;\n form.setAttribute(\"data-auto-submit-pending\", \"true\");\n this.#cancelPending();\n\n this.#pendingId = this.#timers.set(() => {\n this.#pendingId = 0;\n form.removeAttribute(\"data-auto-submit-pending\");\n this.dispatch(\"submit\", { detail: { trigger } });\n // `requestSubmit()` runs native constraint validation. If the form is\n // invalid the actual submit never happens — the browser blocks it (or, when\n // a `stimeo--form-validation` set `novalidate`, that controller cancels the\n // submit) — so no `turbo:submit-end` arrives to clear `aria-busy`. Only mark\n // the form busy when the submit will really proceed; still call\n // `requestSubmit()` either way so the validation surfaces to the user.\n if (form.checkValidity()) {\n form.setAttribute(\"aria-busy\", \"true\");\n }\n form.requestSubmit();\n }, this.debounceValue);\n }\n\n /** Cancels the pending debounced submit, if any (`clear` no-ops on unknown ids). */\n #cancelPending(): void {\n this.#timers.clear(this.#pendingId);\n this.#pendingId = 0;\n }\n\n /**\n * Replaces the subscribed form symmetrically. The outgoing form loses the\n * `turbo:submit-end`/composition listeners, its pending hook, and any pending\n * debounced submit (which described the outgoing form). An in-flight `aria-busy`\n * is left for `turbo:submit-end` or the pre-cache rewind — removing it here\n * would wipe a legitimately in-progress submission.\n */\n #bindForm(form: HTMLFormElement | null): void {\n if (form === this.#boundForm) return;\n const previous = this.#boundForm;\n if (previous) {\n this.#cancelPending();\n previous.removeAttribute(\"data-auto-submit-pending\");\n previous.removeEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#composition.unobserve(previous);\n }\n this.#boundForm = form;\n if (!form) return;\n form.addEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#composition.observe(form);\n }\n\n /** Resolves the form: the explicit `form` target, else a `<form>` root, else null. */\n #resolveForm(): HTMLFormElement | null {\n if (this.hasFormTarget) return this.formTarget;\n return this.element instanceof HTMLFormElement ? this.element : null;\n }\n\n /** Returns the transient state hooks to their initial (absent) state. */\n #rewindForCache(): void {\n const inProgress = this.#pendingId !== 0 || this.#boundForm?.hasAttribute(\"aria-busy\") === true;\n this.#cancelPending();\n this.#boundForm?.removeAttribute(\"data-auto-submit-pending\");\n this.#boundForm?.removeAttribute(\"aria-busy\");\n if (inProgress) this.dispatch(\"reconcile\", { detail: {} });\n }\n\n /** Whether `type` is one of the whitespace-separated event types in `on`. */\n #triggers(type: string): boolean {\n return this.onValue.split(/\\s+/).filter(Boolean).includes(type);\n }\n}\n"]}
|
|
@@ -9,31 +9,59 @@ import { Controller } from '@hotwired/stimulus';
|
|
|
9
9
|
*
|
|
10
10
|
* Markup contract (identifier: `stimeo--bulk-select`):
|
|
11
11
|
* <div data-controller="stimeo--bulk-select"
|
|
12
|
-
* data-stimeo--bulk-select-total-count-value="128"
|
|
12
|
+
* data-stimeo--bulk-select-total-count-value="128"
|
|
13
|
+
* data-stimeo--bulk-select-announce-text-value="{count} selected">
|
|
13
14
|
* <input type="checkbox" data-stimeo--bulk-select-target="all">
|
|
14
15
|
* <!-- rows (may be added dynamically; handled via event delegation) -->
|
|
15
16
|
* <input type="checkbox" data-stimeo--bulk-select-target="item">
|
|
16
17
|
* <input type="checkbox" data-stimeo--bulk-select-target="item">
|
|
17
|
-
* <div data-stimeo--bulk-select-target="bar" hidden role="toolbar"
|
|
18
|
+
* <div data-stimeo--bulk-select-target="bar" hidden role="toolbar"
|
|
19
|
+
* data-controller="stimeo--toolbar" aria-label="Bulk actions">
|
|
18
20
|
* <span data-stimeo--bulk-select-target="count"></span> selected
|
|
19
21
|
* <button data-stimeo--bulk-select-target="selectAllPages"
|
|
22
|
+
* data-stimeo--toolbar-target="control"
|
|
20
23
|
* data-action="click->stimeo--bulk-select#selectAllPages">Select all</button>
|
|
21
|
-
* <button data-
|
|
24
|
+
* <button data-stimeo--toolbar-target="control"
|
|
25
|
+
* data-action="click->stimeo--bulk-select#clear">Clear</button>
|
|
22
26
|
* </div>
|
|
23
27
|
* </div>
|
|
24
28
|
*
|
|
25
|
-
* `
|
|
29
|
+
* The bar carries `role="toolbar"`, so it is composed with `stimeo--toolbar` to get
|
|
30
|
+
* the arrow-key movement and single tab stop that role calls for.
|
|
31
|
+
*
|
|
32
|
+
* `change` and `reconcile` both dispatch `{ count, allPages }`.
|
|
33
|
+
*
|
|
34
|
+
* Selection is two-stage. The select-all box covers the rows on this page; the
|
|
35
|
+
* optional `selectAllPages` control extends the selection to `totalCount` rows
|
|
36
|
+
* across every page, checking each row here as it does so. Touching any single row
|
|
37
|
+
* leaves that mode, because the selection is no longer the whole set.
|
|
26
38
|
*
|
|
27
39
|
* @remarks
|
|
28
40
|
* Behavior only — it never runs the batch action (that is the consumer's
|
|
29
41
|
* form/Turbo) nor fetches/pages rows. Selection lives **only** in each checkbox's
|
|
30
42
|
* `checked` (no module-scope set), so `connect()` recomputes idempotently from the
|
|
31
43
|
* DOM after a Turbo swap. Row `change` is handled by **delegation** on the
|
|
32
|
-
* container, so dynamically-added rows work without per-row `data-action
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
44
|
+
* container, so dynamically-added rows work without per-row `data-action`, while
|
|
45
|
+
* rows arriving or leaving on their own are picked up by the target callbacks and
|
|
46
|
+
* coalesced into one repair per batch.
|
|
47
|
+
*
|
|
48
|
+
* `change` is dispatched when the user moves the selection; `reconcile` when the
|
|
49
|
+
* controller repairs the figures itself — a row added or removed by the page, or a
|
|
50
|
+
* render input changing at runtime. Both carry the same detail.
|
|
51
|
+
*
|
|
52
|
+
* The count reaches assistive tech through the page's shared `stimeo--announcer`,
|
|
53
|
+
* worded by the consumer via `announceText` (`{count}` expands to the figure being
|
|
54
|
+
* shown; an empty template stays silent, keeping announcements opt-in and
|
|
55
|
+
* i18n-neutral).
|
|
56
|
+
*
|
|
57
|
+
* Showing the bar never steals focus (WCAG 2.2 2.4.3). Hiding it hands focus to
|
|
58
|
+
* the select-all box first when the bar holds it, so the keyboard user keeps a Tab
|
|
59
|
+
* position instead of falling back to the document.
|
|
60
|
+
*
|
|
61
|
+
* A non-finite `totalCount` falls back to the Value's default and is written back
|
|
62
|
+
* to the attribute, so the count never renders as `NaN`.
|
|
63
|
+
*
|
|
64
|
+
* The delegated listener and the pending repair are both released on `disconnect()`.
|
|
37
65
|
*/
|
|
38
66
|
declare class BulkSelectController extends Controller<HTMLElement> {
|
|
39
67
|
#private;
|
|
@@ -43,26 +71,45 @@ declare class BulkSelectController extends Controller<HTMLElement> {
|
|
|
43
71
|
type: NumberConstructor;
|
|
44
72
|
default: number;
|
|
45
73
|
};
|
|
46
|
-
|
|
47
|
-
type:
|
|
48
|
-
default:
|
|
74
|
+
announceText: {
|
|
75
|
+
type: StringConstructor;
|
|
76
|
+
default: string;
|
|
49
77
|
};
|
|
50
78
|
};
|
|
51
79
|
static actions: readonly ["clear", "selectAllPages"];
|
|
52
|
-
static events: readonly ["change"];
|
|
80
|
+
static events: readonly ["change", "reconcile"];
|
|
53
81
|
readonly allTarget: HTMLInputElement;
|
|
54
82
|
readonly barTarget: HTMLElement;
|
|
55
83
|
readonly countTarget: HTMLElement;
|
|
84
|
+
readonly itemTargets: HTMLInputElement[];
|
|
56
85
|
readonly hasAllTarget: boolean;
|
|
57
86
|
readonly hasBarTarget: boolean;
|
|
58
87
|
readonly hasCountTarget: boolean;
|
|
59
88
|
totalCountValue: number;
|
|
60
|
-
|
|
89
|
+
announceTextValue: string;
|
|
61
90
|
connect(): void;
|
|
62
91
|
disconnect(): void;
|
|
92
|
+
/** Repairs the figures for a row that arrived at runtime. */
|
|
93
|
+
itemTargetConnected(): void;
|
|
94
|
+
/** Repairs the figures after a row leaves, so a removed selection stops counting. */
|
|
95
|
+
itemTargetDisconnected(): void;
|
|
96
|
+
/** Reflects the current selection onto a select-all box added at runtime. */
|
|
97
|
+
allTargetConnected(): void;
|
|
98
|
+
/** Repairs the figures after the select-all box leaves. */
|
|
99
|
+
allTargetDisconnected(): void;
|
|
100
|
+
/** Repaints the count for a total that changed at runtime, rejecting non-finite ones. */
|
|
101
|
+
totalCountValueChanged(): void;
|
|
102
|
+
/** Repaints so wording changed at runtime is used by the next announcement. */
|
|
103
|
+
announceTextValueChanged(): void;
|
|
63
104
|
/** Clears every selection (rows + select-all) and exits all-pages mode. */
|
|
64
105
|
clear(): void;
|
|
65
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Enters "select all across pages" mode: the count shows `totalCount`, and every
|
|
108
|
+
* row on this page is checked.
|
|
109
|
+
*
|
|
110
|
+
* The mode's claim is that the whole set is selected, so leaving a visible row
|
|
111
|
+
* unchecked would put the page and the count in open disagreement.
|
|
112
|
+
*/
|
|
66
113
|
selectAllPages(): void;
|
|
67
114
|
}
|
|
68
115
|
|