stimeo-ui 0.9.0 → 0.11.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.
Files changed (162) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/dist/cable/index.d.ts +79 -14
  3. package/dist/cable/index.js +226 -43
  4. package/dist/cable/index.js.map +1 -1
  5. package/dist/controllers/accordion_controller.js.map +1 -1
  6. package/dist/controllers/alert_dialog_controller.js +17 -7
  7. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  8. package/dist/controllers/announcer_controller.js +1 -1
  9. package/dist/controllers/announcer_controller.js.map +1 -1
  10. package/dist/controllers/auto_submit_controller.js.map +1 -1
  11. package/dist/controllers/avatar_controller.js.map +1 -1
  12. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  13. package/dist/controllers/bulk_select_controller.js +2 -2
  14. package/dist/controllers/bulk_select_controller.js.map +1 -1
  15. package/dist/controllers/calendar_controller.js.map +1 -1
  16. package/dist/controllers/carousel_controller.js.map +1 -1
  17. package/dist/controllers/character_counter_controller.js.map +1 -1
  18. package/dist/controllers/clipboard_controller.js.map +1 -1
  19. package/dist/controllers/collapsible_controller.d.ts +1 -1
  20. package/dist/controllers/collapsible_controller.js +1 -1
  21. package/dist/controllers/collapsible_controller.js.map +1 -1
  22. package/dist/controllers/color_picker_controller.d.ts +1 -1
  23. package/dist/controllers/color_picker_controller.js.map +1 -1
  24. package/dist/controllers/combobox_controller.js.map +1 -1
  25. package/dist/controllers/command_palette_controller.js +15 -5
  26. package/dist/controllers/command_palette_controller.js.map +1 -1
  27. package/dist/controllers/conditional_fields_controller.js.map +1 -1
  28. package/dist/controllers/confirm_controller.js +15 -5
  29. package/dist/controllers/confirm_controller.js.map +1 -1
  30. package/dist/controllers/context_menu_controller.d.ts +5 -4
  31. package/dist/controllers/context_menu_controller.js.map +1 -1
  32. package/dist/controllers/count_up_controller.js.map +1 -1
  33. package/dist/controllers/countdown_controller.js +1 -1
  34. package/dist/controllers/countdown_controller.js.map +1 -1
  35. package/dist/controllers/data_grid_controller.js +1 -1
  36. package/dist/controllers/data_grid_controller.js.map +1 -1
  37. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  38. package/dist/controllers/dialog_controller.js +15 -5
  39. package/dist/controllers/dialog_controller.js.map +1 -1
  40. package/dist/controllers/direct_upload_controller.d.ts +2 -2
  41. package/dist/controllers/direct_upload_controller.js +1 -5
  42. package/dist/controllers/direct_upload_controller.js.map +1 -1
  43. package/dist/controllers/dismissible_controller.js.map +1 -1
  44. package/dist/controllers/drawer_controller.d.ts +2 -2
  45. package/dist/controllers/drawer_controller.js +17 -7
  46. package/dist/controllers/drawer_controller.js.map +1 -1
  47. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  48. package/dist/controllers/flash_controller.js.map +1 -1
  49. package/dist/controllers/focus_controller.d.ts +5 -0
  50. package/dist/controllers/focus_controller.js +45 -7
  51. package/dist/controllers/focus_controller.js.map +1 -1
  52. package/dist/controllers/form_field_controller.js +1 -1
  53. package/dist/controllers/form_field_controller.js.map +1 -1
  54. package/dist/controllers/form_validation_controller.js.map +1 -1
  55. package/dist/controllers/frame_loading_controller.js.map +1 -1
  56. package/dist/controllers/highlight_controller.js.map +1 -1
  57. package/dist/controllers/input_mask_controller.js.map +1 -1
  58. package/dist/controllers/intersection_controller.d.ts +4 -3
  59. package/dist/controllers/intersection_controller.js.map +1 -1
  60. package/dist/controllers/lazy_frame_controller.d.ts +2 -2
  61. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  62. package/dist/controllers/listbox_controller.js.map +1 -1
  63. package/dist/controllers/masonry_controller.d.ts +3 -1
  64. package/dist/controllers/masonry_controller.js.map +1 -1
  65. package/dist/controllers/menu_controller.d.ts +1 -1
  66. package/dist/controllers/menu_controller.js.map +1 -1
  67. package/dist/controllers/menubar_controller.js +2 -2
  68. package/dist/controllers/menubar_controller.js.map +1 -1
  69. package/dist/controllers/meter_controller.d.ts +1 -1
  70. package/dist/controllers/meter_controller.js.map +1 -1
  71. package/dist/controllers/multi_select_controller.js +1 -1
  72. package/dist/controllers/multi_select_controller.js.map +1 -1
  73. package/dist/controllers/navigation_menu_controller.js.map +1 -1
  74. package/dist/controllers/nested_form_controller.js.map +1 -1
  75. package/dist/controllers/number_input_controller.js.map +1 -1
  76. package/dist/controllers/otp_controller.js.map +1 -1
  77. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  78. package/dist/controllers/overflow_menu_controller.js +2 -2
  79. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  80. package/dist/controllers/pagination_controller.d.ts +1 -1
  81. package/dist/controllers/pagination_controller.js.map +1 -1
  82. package/dist/controllers/password_reveal_controller.d.ts +27 -2
  83. package/dist/controllers/password_reveal_controller.js +102 -3
  84. package/dist/controllers/password_reveal_controller.js.map +1 -1
  85. package/dist/controllers/password_strength_controller.d.ts +71 -17
  86. package/dist/controllers/password_strength_controller.js +287 -42
  87. package/dist/controllers/password_strength_controller.js.map +1 -1
  88. package/dist/controllers/pointer_drag_controller.d.ts +23 -5
  89. package/dist/controllers/pointer_drag_controller.js +64 -18
  90. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  91. package/dist/controllers/popover_controller.js.map +1 -1
  92. package/dist/controllers/portal_controller.d.ts +17 -4
  93. package/dist/controllers/portal_controller.js +32 -11
  94. package/dist/controllers/portal_controller.js.map +1 -1
  95. package/dist/controllers/preview_guard_controller.d.ts +22 -14
  96. package/dist/controllers/preview_guard_controller.js +180 -20
  97. package/dist/controllers/preview_guard_controller.js.map +1 -1
  98. package/dist/controllers/progress_controller.js.map +1 -1
  99. package/dist/controllers/radio_group_controller.js.map +1 -1
  100. package/dist/controllers/range_slider_controller.js.map +1 -1
  101. package/dist/controllers/rating_controller.js.map +1 -1
  102. package/dist/controllers/read_more_controller.js.map +1 -1
  103. package/dist/controllers/relative_time_controller.js.map +1 -1
  104. package/dist/controllers/reset_before_cache_controller.d.ts +1 -2
  105. package/dist/controllers/reset_before_cache_controller.js.map +1 -1
  106. package/dist/controllers/resizable_controller.d.ts +1 -1
  107. package/dist/controllers/resizable_controller.js +1 -1
  108. package/dist/controllers/resizable_controller.js.map +1 -1
  109. package/dist/controllers/roving_controller.d.ts +17 -4
  110. package/dist/controllers/roving_controller.js +127 -14
  111. package/dist/controllers/roving_controller.js.map +1 -1
  112. package/dist/controllers/scroll_area_controller.js.map +1 -1
  113. package/dist/controllers/scroll_restore_controller.d.ts +33 -11
  114. package/dist/controllers/scroll_restore_controller.js +127 -27
  115. package/dist/controllers/scroll_restore_controller.js.map +1 -1
  116. package/dist/controllers/scroll_visibility_controller.d.ts +42 -10
  117. package/dist/controllers/scroll_visibility_controller.js +167 -14
  118. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  119. package/dist/controllers/scrollspy_controller.js.map +1 -1
  120. package/dist/controllers/separator_controller.js.map +1 -1
  121. package/dist/controllers/sidebar_controller.js +15 -5
  122. package/dist/controllers/sidebar_controller.js.map +1 -1
  123. package/dist/controllers/skeleton_controller.js.map +1 -1
  124. package/dist/controllers/slider_controller.js.map +1 -1
  125. package/dist/controllers/spinner_controller.js.map +1 -1
  126. package/dist/controllers/step_indicator_controller.js +0 -5
  127. package/dist/controllers/step_indicator_controller.js.map +1 -1
  128. package/dist/controllers/stick_to_bottom_controller.d.ts +26 -9
  129. package/dist/controllers/stick_to_bottom_controller.js +149 -28
  130. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  131. package/dist/controllers/submit_once_controller.js.map +1 -1
  132. package/dist/controllers/switch_controller.js.map +1 -1
  133. package/dist/controllers/tabs_controller.js.map +1 -1
  134. package/dist/controllers/tags_input_controller.js.map +1 -1
  135. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  136. package/dist/controllers/theme_controller.d.ts +32 -6
  137. package/dist/controllers/theme_controller.js +151 -40
  138. package/dist/controllers/theme_controller.js.map +1 -1
  139. package/dist/controllers/time_picker_controller.js.map +1 -1
  140. package/dist/controllers/toast_controller.d.ts +2 -2
  141. package/dist/controllers/toast_controller.js +2 -2
  142. package/dist/controllers/toast_controller.js.map +1 -1
  143. package/dist/controllers/toggle_group_controller.js.map +1 -1
  144. package/dist/controllers/toolbar_controller.js.map +1 -1
  145. package/dist/controllers/transition_controller.d.ts +11 -7
  146. package/dist/controllers/transition_controller.js +79 -15
  147. package/dist/controllers/transition_controller.js.map +1 -1
  148. package/dist/controllers/tree_view_controller.js.map +1 -1
  149. package/dist/index.d.ts +6 -3
  150. package/dist/index.js +1188 -318
  151. package/dist/index.js.map +1 -1
  152. package/dist/inspector/cli.d.ts +3 -4
  153. package/dist/inspector/cli.js +1 -0
  154. package/dist/inspector/cli.js.map +1 -1
  155. package/dist/inspector/cli_bin.js +6 -5
  156. package/dist/inspector/cli_bin.js.map +1 -1
  157. package/dist/inspector/examples.json +6 -6
  158. package/dist/inspector/manifest.json +15 -32
  159. package/dist/positioning/index.d.ts +18 -4
  160. package/dist/positioning/index.js +84 -25
  161. package/dist/positioning/index.js.map +1 -1
  162. package/package.json +6 -6
@@ -2,12 +2,69 @@ import { Controller } from '@hotwired/stimulus';
2
2
 
3
3
  // src/controllers/stick_to_bottom_controller.ts
4
4
 
5
+ // src/utils/layout_observer.ts
6
+ var LayoutObserver = class {
7
+ #callback;
8
+ #resizeObserverFactory;
9
+ #resizeObserver = null;
10
+ #observingViewport = false;
11
+ /** Stable bound handler so add/removeEventListener target the same reference. */
12
+ #handleViewportResize = () => {
13
+ this.#callback();
14
+ };
15
+ constructor(callback, options = {}) {
16
+ this.#callback = callback;
17
+ this.#resizeObserverFactory = options.resizeObserverFactory ?? (typeof ResizeObserver === "undefined" ? null : (cb) => new ResizeObserver(cb));
18
+ }
19
+ /**
20
+ * Starts observing an element's size. Repeated calls observe additional
21
+ * elements through the same shared observer. No-ops when no
22
+ * `ResizeObserver` implementation is available.
23
+ */
24
+ observe(element) {
25
+ if (!this.#resizeObserverFactory) return;
26
+ if (!this.#resizeObserver) {
27
+ this.#resizeObserver = this.#resizeObserverFactory(() => {
28
+ this.#callback();
29
+ });
30
+ }
31
+ this.#resizeObserver.observe(element);
32
+ }
33
+ /** Stops observing a single element while leaving any others in place. */
34
+ unobserve(element) {
35
+ this.#resizeObserver?.unobserve(element);
36
+ }
37
+ /** Starts observing viewport resizes. Idempotent: the listener is added once. */
38
+ observeViewport() {
39
+ if (this.#observingViewport) return;
40
+ this.#observingViewport = true;
41
+ window.addEventListener("resize", this.#handleViewportResize);
42
+ }
43
+ /** Stops observing viewport resizes without affecting element observation. */
44
+ unobserveViewport() {
45
+ if (!this.#observingViewport) return;
46
+ this.#observingViewport = false;
47
+ window.removeEventListener("resize", this.#handleViewportResize);
48
+ }
49
+ /**
50
+ * Releases every observation: disconnects the {@link ResizeObserver} and
51
+ * removes the viewport listener. Safe to call multiple times. Call this from a
52
+ * controller's `disconnect()`.
53
+ */
54
+ disconnect() {
55
+ this.#resizeObserver?.disconnect();
56
+ this.#resizeObserver = null;
57
+ this.unobserveViewport();
58
+ }
59
+ };
60
+
5
61
  // src/utils/reduced_motion.ts
6
62
  function prefersReducedMotion() {
7
63
  return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
8
64
  }
9
65
 
10
66
  // src/controllers/stick_to_bottom_controller.ts
67
+ var DEFAULT_THRESHOLD = 80;
11
68
  var countElements = (nodes) => {
12
69
  let n = 0;
13
70
  for (const node of nodes) if (node.nodeType === Node.ELEMENT_NODE) n += 1;
@@ -16,34 +73,53 @@ var countElements = (nodes) => {
16
73
  var StickToBottomController = class extends Controller {
17
74
  static targets = ["content"];
18
75
  static values = {
19
- threshold: { type: Number, default: 80 },
76
+ threshold: { type: Number, default: DEFAULT_THRESHOLD },
20
77
  behavior: { type: String, default: "auto" },
21
78
  pinOnConnect: { type: Boolean, default: false }
22
79
  };
23
80
  static actions = ["scrollToBottom"];
24
81
  static events = ["pin", "new"];
25
82
  #observer = null;
26
- /** Watches for the box a deferred `pinOnConnect` jump is still waiting on. */
27
- #layout = null;
83
+ /** The element the append observer currently holds, so a swap can be detected. */
84
+ #watched = null;
85
+ /** Watches for the box a container connected without one is still waiting on. */
86
+ #layout = new LayoutObserver(() => this.#onLaidOut());
87
+ #awaitingLayout = false;
88
+ #connected = false;
28
89
  #pinned = false;
29
90
  #onScroll = () => this.#updatePinned();
30
91
  connect() {
92
+ this.#connected = true;
31
93
  if (this.pinOnConnectValue && this.#measurable()) this.#scrollToBottom("instant");
94
+ this.element.removeAttribute("data-has-new");
32
95
  this.#pinned = this.#isPinned();
33
96
  this.#reflectPinned();
34
97
  this.element.addEventListener("scroll", this.#onScroll, { passive: true });
35
- if (typeof MutationObserver !== "undefined") {
36
- this.#observer = new MutationObserver((mutations) => this.#onMutations(mutations));
37
- this.#observer.observe(this.#watched(), { childList: true });
38
- }
39
- if (this.pinOnConnectValue && !this.#measurable()) this.#pinWhenLaidOut();
98
+ this.#syncWatched();
99
+ if (!this.#measurable()) this.#waitForLayout();
40
100
  }
41
101
  disconnect() {
102
+ this.#connected = false;
42
103
  this.element.removeEventListener("scroll", this.#onScroll);
43
- this.#observer?.disconnect();
44
- this.#observer = null;
104
+ this.#stopWatching();
45
105
  this.#stopWaitingForLayout();
46
106
  }
107
+ /** Moves the append watch onto a `content` target that arrived at runtime. */
108
+ contentTargetConnected() {
109
+ this.#syncWatched();
110
+ }
111
+ /** Moves the append watch off a `content` target that left, back onto the container. */
112
+ contentTargetDisconnected() {
113
+ this.#syncWatched();
114
+ }
115
+ /**
116
+ * Re-derives pinned when the distance that counts as the bottom is changed at runtime
117
+ * (a morph that swaps the attribute on a retained element).
118
+ */
119
+ thresholdValueChanged() {
120
+ if (!this.#connected) return;
121
+ this.#updatePinned();
122
+ }
47
123
  /**
48
124
  * Jumps to the bottom and re-pins (wired to a "new messages" button).
49
125
  *
@@ -72,7 +148,11 @@ var StickToBottomController = class extends Controller {
72
148
  this.dispatch("new", { detail: { count: added } });
73
149
  }
74
150
  }
75
- /** Recomputes pinned from the scroll position and reflects it on a transition. */
151
+ /**
152
+ * Recomputes pinned from the scroll position and reflects it on a transition.
153
+ *
154
+ * @stimeoRenderRoot
155
+ */
76
156
  #updatePinned() {
77
157
  const pinned = this.#isPinned();
78
158
  if (pinned === this.#pinned) return;
@@ -89,9 +169,25 @@ var StickToBottomController = class extends Controller {
89
169
  this.element.removeAttribute("data-pinned");
90
170
  }
91
171
  }
172
+ /** Whether the container currently sits within `threshold` of its bottom. */
92
173
  #isPinned() {
174
+ if (!this.#measurable()) return false;
93
175
  const el = this.element;
94
- return el.scrollHeight - el.clientHeight - el.scrollTop <= this.thresholdValue;
176
+ return el.scrollHeight - el.clientHeight - el.scrollTop <= this.#threshold;
177
+ }
178
+ /**
179
+ * The distance from the bottom that counts as pinned: a finite, non-negative number of
180
+ * pixels. Anything else names no distance the container can be at, and settles the
181
+ * comparison the same way at every scroll position, so it falls back to the default.
182
+ * `Number` reads `"abc"` as `NaN` and every comparison against it is false; a negative
183
+ * distance sits below the closest the container ever gets; `Infinity` is never
184
+ * exceeded. The first two stop following and flag every append as new, and the last
185
+ * never stops following — it takes the reading position the flag exists to protect.
186
+ * Zero is a real declaration: it pins at the exact bottom only.
187
+ */
188
+ get #threshold() {
189
+ const declared = this.thresholdValue;
190
+ return Number.isFinite(declared) && declared >= 0 ? declared : DEFAULT_THRESHOLD;
95
191
  }
96
192
  /**
97
193
  * Whether the container has a box to scroll and to measure. One that is not rendered
@@ -102,23 +198,25 @@ var StickToBottomController = class extends Controller {
102
198
  return this.element.clientHeight > 0;
103
199
  }
104
200
  /**
105
- * Holds the `pinOnConnect` jump until the container is laid out, then runs it and
106
- * re-reads the state — otherwise the panel opens at the top still claiming the bottom.
201
+ * Holds the pinned decision until the container is laid out — otherwise the panel opens
202
+ * at the top while the state claims the bottom, and the appends that arrived meanwhile
203
+ * were followed into a box that could not move rather than flagged.
107
204
  */
108
- #pinWhenLaidOut() {
109
- if (typeof ResizeObserver === "undefined") return;
110
- this.#layout = new ResizeObserver(() => {
111
- if (!this.#measurable()) return;
112
- this.#stopWaitingForLayout();
113
- this.#scrollToBottom("instant");
114
- this.#updatePinned();
115
- });
205
+ #waitForLayout() {
206
+ this.#awaitingLayout = true;
116
207
  this.#layout.observe(this.element);
117
208
  }
118
- /** Releases the layout watch, whether or not the deferred jump ever ran. */
209
+ /** Runs the held decision once the container has the box it was waiting for. */
210
+ #onLaidOut() {
211
+ if (!this.#awaitingLayout || !this.#measurable()) return;
212
+ this.#stopWaitingForLayout();
213
+ if (this.pinOnConnectValue) this.#scrollToBottom("instant");
214
+ this.#updatePinned();
215
+ }
216
+ /** Releases the layout watch, whether or not the held decision ever ran. */
119
217
  #stopWaitingForLayout() {
120
- this.#layout?.disconnect();
121
- this.#layout = null;
218
+ this.#awaitingLayout = false;
219
+ this.#layout.disconnect();
122
220
  }
123
221
  /**
124
222
  * Scrolls to the bottom, clamped by the engine to the maximum scroll offset — which is
@@ -134,9 +232,32 @@ var StickToBottomController = class extends Controller {
134
232
  this.element.scrollTop = top;
135
233
  }
136
234
  }
137
- /** The append-watched element: the `content` target, or the container itself. */
138
- #watched() {
139
- return this.hasContentTarget ? this.contentTarget : this.element;
235
+ /**
236
+ * Points the append watch at the current `content` target, or at the container when
237
+ * there is none. Re-resolved whenever that target changes, so a swap does not leave the
238
+ * observer holding a detached node whose appends nobody sees.
239
+ *
240
+ * Stimulus runs the target callbacks outside the connected window too — before
241
+ * `connect()` for a target already in the DOM, and after `disconnect()` while the
242
+ * element is torn down — where this would arm an observer nothing releases. Re-syncing
243
+ * to the target already held is left alone, so an arrival still in flight is not
244
+ * dropped with the observer that was about to deliver it.
245
+ */
246
+ #syncWatched() {
247
+ if (!this.#connected) return;
248
+ const next = this.hasContentTarget ? this.contentTarget : this.element;
249
+ if (next === this.#watched) return;
250
+ this.#stopWatching();
251
+ this.#watched = next;
252
+ if (typeof MutationObserver === "undefined") return;
253
+ this.#observer = new MutationObserver((mutations) => this.#onMutations(mutations));
254
+ this.#observer.observe(next, { childList: true });
255
+ }
256
+ /** Releases the append watch and the element it held. */
257
+ #stopWatching() {
258
+ this.#observer?.disconnect();
259
+ this.#observer = null;
260
+ this.#watched = null;
140
261
  }
141
262
  /**
142
263
  * The behavior a follow-scroll runs with. `"auto"` is **not** a request to arrive at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/reduced_motion.ts","../../src/controllers/stick_to_bottom_controller.ts"],"names":[],"mappings":";;;;;AAmBO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OACE,OAAO,MAAA,CAAO,UAAA,KAAe,cAC7B,MAAA,CAAO,UAAA,CAAW,kCAAkC,CAAA,CAAE,OAAA;AAE1D;;;ACpBA,IAAM,aAAA,GAAgB,CAAC,KAAA,KAA4B;AACjD,EAAA,IAAI,CAAA,GAAI,CAAA;AACR,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO,IAAI,KAAK,QAAA,KAAa,IAAA,CAAK,cAAc,CAAA,IAAK,CAAA;AACxE,EAAA,OAAO,CAAA;AACT,CAAA;AA6CO,IAAM,uBAAA,GAAN,cAAsC,UAAA,CAAwB;AAAA,EACnE,OAAgB,OAAA,GAAU,CAAC,SAAS,CAAA;AAAA,EACpC,OAAgB,MAAA,GAAS;AAAA,IACvB,SAAA,EAAW,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,EAAA,EAAG;AAAA,IACvC,QAAA,EAAU,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,MAAA,EAAO;AAAA,IAC1C,YAAA,EAAc,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,KAAA;AAAM,GAChD;AAAA,EACA,OAAO,OAAA,GAAU,CAAC,gBAAgB,CAAA;AAAA,EAClC,OAAO,MAAA,GAAS,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,EAS7B,SAAA,GAAqC,IAAA;AAAA;AAAA,EAErC,OAAA,GAAiC,IAAA;AAAA,EACjC,OAAA,GAAU,KAAA;AAAA,EAED,SAAA,GAAY,MAAY,IAAA,CAAK,aAAA,EAAc;AAAA,EAE3C,O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A;AAAA;AAAA,EAQA,SAAA,GAA4B;AAC1B,IAAA,IAAI,oBAAA,IAAwB,OAAO,SAAA;AACnC,IAAA,OAAO,IAAA,CAAK,aAAA,KAAkB,QAAA,GAAW,QAAA,GAAW,MAAA;AAAA,EACtD;AACF","file":"stick_to_bottom_controller.js","sourcesContent":["/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n * (count-up, highlight, overflow-indicator, scroll-visibility, stick-to-bottom,\n * transition).\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\n/** Counts the element nodes in an added-node list (text nodes are ignored). */\nconst countElements = (nodes: NodeList): number => {\n let n = 0;\n for (const node of nodes) if (node.nodeType === Node.ELEMENT_NODE) n += 1;\n return n;\n};\n\n/**\n * Headless **stick-to-bottom**: auto-follows new content to the bottom of a scroll\n * container (a chat log, a live console) — but only while the user is already near the\n * bottom; if they have scrolled up to read, it holds position and flags that new content\n * arrived instead (no APG pattern; honors WCAG 2.3.3 via `prefers-reduced-motion` and\n * never steals focus).\n *\n * Markup contract (identifier: `stimeo--stick-to-bottom`):\n * <div data-controller=\"stimeo--stick-to-bottom\"\n * data-stimeo--stick-to-bottom-threshold-value=\"80\"\n * data-stimeo--stick-to-bottom-pin-on-connect-value=\"true\" style=\"overflow:auto\">\n * <ul data-stimeo--stick-to-bottom-target=\"content\"><!-- Turbo Stream appends --></ul>\n * </div>\n *\n * The container is \"pinned\" while its distance from the bottom is within `threshold`. A\n * `MutationObserver` on `content` (or the element) reacts to appended children: while\n * pinned it scrolls to the bottom; while unpinned it sets `data-has-new` and emits `new`.\n * Scrolling recomputes pinned and reflects `data-pinned`, emitting `pin` on change; the\n * `scrollToBottom` action jumps back down (a \"new messages\" button).\n *\n * A container renders at `scrollTop` 0 — unpinned — so out of the box it flags the first\n * append rather than following it. `pinOnConnect` opts into the other starting point:\n * `connect()` jumps to the bottom and reads the state back from where it landed. It runs\n * on every connect, so a container inserted or re-rendered later (a Turbo Stream, a panel\n * built on open) starts at the bottom too — which a once-per-document page event cannot\n * do. It is off by default, so a restored reading position (a Turbo cache restore, a user\n * who had scrolled up) is never yanked to the bottom unless the consumer asks for it.\n *\n * `pin` dispatches `{ pinned }`; `new` dispatches `{ count }`.\n *\n * @remarks\n * The `MutationObserver` watches `childList` only (not `subtree`), so it follows\n * direct appends to `content` (or the element). Appends made deeper inside a nested\n * wrapper are not detected — keep messages as direct children, or call the public\n * `scrollToBottom` action after such inserts.\n *\n * Behavior only — it does not add content (Turbo Stream / the consumer does) and is the\n * minimal follow primitive, not a full chat UI (no virtualization / message input). State\n * is derived from the scroll position each pass (no module-scope state), so `connect()`\n * re-syncs after a Turbo Stream insert; reduced motion forces an instant jump\n * independently of consumer CSS; auto-scroll never moves focus; the observer and the\n * passive scroll listener are released on `disconnect()` (Turbo navigation included).\n */\nexport class StickToBottomController extends Controller<HTMLElement> {\n static override targets = [\"content\"];\n static override values = {\n threshold: { type: Number, default: 80 },\n behavior: { type: String, default: \"auto\" },\n pinOnConnect: { type: Boolean, default: false },\n };\n static actions = [\"scrollToBottom\"] as const;\n static events = [\"pin\", \"new\"] as const;\n\n declare readonly contentTarget: HTMLElement;\n declare readonly hasContentTarget: boolean;\n\n declare thresholdValue: number;\n declare behaviorValue: string;\n declare pinOnConnectValue: boolean;\n\n #observer: MutationObserver | null = null;\n /** Watches for the box a deferred `pinOnConnect` jump is still waiting on. */\n #layout: ResizeObserver | null = null;\n #pinned = false;\n\n readonly #onScroll = (): void => this.#updatePinned();\n\n override connect(): void {\n // Instant whatever `behavior` says, overriding a consumer's `scroll-behavior: smooth`:\n // an animated jump emits scroll events on the way down, each recomputing pinned from a\n // position still far from the bottom, so the container would unpin (and re-pin)\n // mid-flight before it ever settles.\n if (this.pinOnConnectValue && this.#measurable()) this.#scrollToBottom(\"instant\");\n // Read the state back from where the container actually is, asked for a jump or not: a\n // request the engine does not honor must leave it unpinned, so the next append is\n // flagged rather than swallowed. This also drops a stale data-pinned / data-has-new a\n // Turbo cache restore brought back.\n this.#pinned = this.#isPinned();\n this.#reflectPinned();\n\n this.element.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n if (typeof MutationObserver !== \"undefined\") {\n this.#observer = new MutationObserver((mutations) => this.#onMutations(mutations));\n this.#observer.observe(this.#watched(), { childList: true });\n }\n if (this.pinOnConnectValue && !this.#measurable()) this.#pinWhenLaidOut();\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"scroll\", this.#onScroll);\n this.#observer?.disconnect();\n this.#observer = null;\n this.#stopWaitingForLayout();\n }\n\n /**\n * Jumps to the bottom and re-pins (wired to a \"new messages\" button).\n *\n * The has-new flag clears on request — the user has acknowledged the arrival — while\n * pinned is read back from where the scroll landed: a jump that arrives by the time\n * this returns pins immediately, an animated one settles from its own scroll events,\n * and a jump the engine cannot honor leaves the container unpinned, so the next append\n * flags it again instead of being swallowed by a pinned state that does not hold.\n *\n * Which of those happens is not this method's to decide — see {@link behaviorValue}.\n */\n scrollToBottom(): void {\n this.#scrollToBottom();\n this.element.removeAttribute(\"data-has-new\");\n this.#updatePinned();\n }\n\n /** Follows appended children while pinned; otherwise flags new content. */\n #onMutations(mutations: MutationRecord[]): void {\n let added = 0;\n for (const mutation of mutations) added += countElements(mutation.addedNodes);\n if (added === 0) return;\n\n if (this.#pinned) {\n this.#scrollToBottom();\n } else {\n this.element.setAttribute(\"data-has-new\", \"true\");\n this.dispatch(\"new\", { detail: { count: added } });\n }\n }\n\n /** Recomputes pinned from the scroll position and reflects it on a transition. */\n #updatePinned(): void {\n const pinned = this.#isPinned();\n if (pinned === this.#pinned) return;\n this.#pinned = pinned;\n this.#reflectPinned();\n this.dispatch(\"pin\", { detail: { pinned } });\n }\n\n /** Mirrors the current `#pinned` onto the state hooks (clearing has-new once pinned). */\n #reflectPinned(): void {\n if (this.#pinned) {\n this.element.setAttribute(\"data-pinned\", \"true\");\n this.element.removeAttribute(\"data-has-new\"); // caught up with the bottom\n } else {\n this.element.removeAttribute(\"data-pinned\");\n }\n }\n\n #isPinned(): boolean {\n const el = this.element;\n return el.scrollHeight - el.clientHeight - el.scrollTop <= this.thresholdValue;\n }\n\n /**\n * Whether the container has a box to scroll and to measure. One that is not rendered\n * (inside a closed panel) reports every metric as 0, which reads as \"already at the\n * bottom\" — a position describing no layout the user will ever see.\n */\n #measurable(): boolean {\n return this.element.clientHeight > 0;\n }\n\n /**\n * Holds the `pinOnConnect` jump until the container is laid out, then runs it and\n * re-reads the state — otherwise the panel opens at the top still claiming the bottom.\n */\n #pinWhenLaidOut(): void {\n if (typeof ResizeObserver === \"undefined\") return;\n this.#layout = new ResizeObserver(() => {\n if (!this.#measurable()) return;\n this.#stopWaitingForLayout();\n this.#scrollToBottom(\"instant\");\n this.#updatePinned();\n });\n this.#layout.observe(this.element);\n }\n\n /** Releases the layout watch, whether or not the deferred jump ever ran. */\n #stopWaitingForLayout(): void {\n this.#layout?.disconnect();\n this.#layout = null;\n }\n\n /**\n * Scrolls to the bottom, clamped by the engine to the maximum scroll offset — which is\n * 0 for a container tall enough to hold its whole content, so the jump moves nothing\n * there. `behavior` defaults to the configured follow behavior; pass `\"instant\"` for a\n * jump that must not animate.\n */\n #scrollToBottom(behavior: ScrollBehavior = this.#behavior()): void {\n const top = this.element.scrollHeight;\n if (typeof this.element.scrollTo === \"function\") {\n this.element.scrollTo({ top, behavior });\n } else {\n this.element.scrollTop = top;\n }\n }\n\n /** The append-watched element: the `content` target, or the container itself. */\n #watched(): HTMLElement {\n return this.hasContentTarget ? this.contentTarget : this.element;\n }\n\n /**\n * The behavior a follow-scroll runs with. `\"auto\"` is **not** a request to arrive at\n * once: it hands the decision to the element's computed `scroll-behavior`, so a\n * consumer stylesheet saying `smooth` animates these scrolls too. Only `\"instant\"`\n * overrides that CSS, which is why reduced motion and the `pinOnConnect` jump name it.\n */\n #behavior(): ScrollBehavior {\n if (prefersReducedMotion()) return \"instant\";\n return this.behaviorValue === \"smooth\" ? \"smooth\" : \"auto\";\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/layout_observer.ts","../../src/utils/reduced_motion.ts","../../src/controllers/stick_to_bottom_controller.ts"],"names":[],"mappings":";;;;;AAgDO,IAAM,iBAAN,MAAqB;AAAA,EACjB,SAAA;AAAA,EACA,sBAAA;AAAA,EACT,eAAA,GAAyC,IAAA;AAAA,EACzC,kBAAA,GAAqB,KAAA;AAAA;AAAA,EAGZ,wBAAwB,MAAY;AAC3C,IAAA,IAAA,CAAK,SAAA,EAAU;AAAA,EACjB,CAAA;AAAA,EAEA,WAAA,CAAY,QAAA,EAA0B,OAAA,GAAiC,EAAC,EAAG;AACzE,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA;AACjB,IAAA,IAAA,CAAK,sBAAA,GACH,OAAA,CAAQ,qBAAA,KACP,OAAO,cAAA,KAAmB,WAAA,GAAc,IAAA,GAAO,CAAC,EAAA,KAAO,IAAI,cAAA,CAAe,EAAE,CAAA,CAAA;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAQ,OAAA,EAAwB;AAC9B,IAAA,IAAI,CAAC,KAAK,sBAAA,EAAwB;AAClC,IAAA,IAAI,CAAC,KAAK,eAAA,EAAiB;AACzB,MAAA,IAAA,CAAK,eAAA,GAAkB,IAAA,CAAK,sBAAA,CAAuB,MAAM;AACvD,QAAA,IAAA,CAAK,SAAA,EAAU;AAAA,MAC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AK,UAAA,EAAY;AACtB,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,gBAAA,GAAmB,IAAA,CAAK,gBAAgB,IAAA,CAAK,OAAA;AAC/D,IAAA,IAAI,IAAA,KAAS,KAAK,QAAA,EAAU;AAE5B,IAAA,IAAA,CAAK,aAAA,EAAc;AACnB,IAAA,IAAA,CAAK,QAAA,GAAW,IAAA;AAChB,IAAA,IAAI,OAAO,qBAAqB,WAAA,EAAa;AAC7C,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,gBAAA,CAAiB,CAAC,cAAc,IAAA,CAAK,YAAA,CAAa,SAAS,CAAC,CAAA;AACjF,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,IAAA,EAAM,EAAE,SAAA,EAAW,MAAM,CAAA;AAAA,EAClD;AAAA;AAAA,EAGA,aAAA,GAAsB;AACpB,IAAA,IAAA,CAAK,WAAW,UAAA,EAAW;AAC3B,IAAA,IAAA,CAAK,SAAA,GAAY,IAAA;AACjB,IAAA,IAAA,CAAK,QAAA,GAAW,IAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAA,GAA4B;AAC1B,IAAA,IAAI,oBAAA,IAAwB,OAAO,SAAA;AACnC,IAAA,OAAO,IAAA,CAAK,aAAA,KAAkB,QAAA,GAAW,QAAA,GAAW,MAAA;AAAA,EACtD;AACF","file":"stick_to_bottom_controller.js","sourcesContent":["/**\n * Unified element-size and viewport observation for Stimeo controllers.\n *\n * Widgets whose output is measured — an overflow boundary, a masonry column count,\n * an autosized textarea — need to react both to their *own* box changing — via {@link ResizeObserver} —\n * and to the *viewport* changing — via the `window` `resize` event. Wiring those\n * two sources by hand in every controller risks leaked listeners on\n * `disconnect()`. {@link LayoutObserver} owns both behind one callback and one\n * {@link LayoutObserver.disconnect | disconnect()} that releases everything.\n *\n * Behavior only: the helper reports *that* layout changed; it never reads or\n * writes styles. Consumers decide what to recompute.\n */\n\n/** Invoked whenever an observed element or the viewport changes size. */\nexport type LayoutCallback = () => void;\n\n/** Constructs a {@link ResizeObserver}; injectable so tests stay deterministic. */\nexport type ResizeObserverFactory = (callback: ResizeObserverCallback) => ResizeObserver;\n\n/** Options for {@link LayoutObserver}. */\nexport interface LayoutObserverOptions {\n /**\n * Factory for the {@link ResizeObserver} used by {@link LayoutObserver.observe}.\n * Defaults to the global constructor; override it in tests, or to no-op in\n * environments where `ResizeObserver` is unavailable.\n */\n resizeObserverFactory?: ResizeObserverFactory;\n}\n\n/**\n * Observes element resizes and/or viewport resizes through a single callback,\n * with guaranteed teardown.\n *\n * @example\n * ```ts\n * #layout = new LayoutObserver(() => this.#reposition());\n *\n * connect() {\n * this.#layout.observe(this.panelTarget);\n * this.#layout.observeViewport();\n * }\n *\n * disconnect() {\n * this.#layout.disconnect();\n * }\n * ```\n */\nexport class LayoutObserver {\n readonly #callback: LayoutCallback;\n readonly #resizeObserverFactory: ResizeObserverFactory | null;\n #resizeObserver: ResizeObserver | null = null;\n #observingViewport = false;\n\n /** Stable bound handler so add/removeEventListener target the same reference. */\n readonly #handleViewportResize = (): void => {\n this.#callback();\n };\n\n constructor(callback: LayoutCallback, options: LayoutObserverOptions = {}) {\n this.#callback = callback;\n this.#resizeObserverFactory =\n options.resizeObserverFactory ??\n (typeof ResizeObserver === \"undefined\" ? null : (cb) => new ResizeObserver(cb));\n }\n\n /**\n * Starts observing an element's size. Repeated calls observe additional\n * elements through the same shared observer. No-ops when no\n * `ResizeObserver` implementation is available.\n */\n observe(element: Element): void {\n if (!this.#resizeObserverFactory) return;\n if (!this.#resizeObserver) {\n this.#resizeObserver = this.#resizeObserverFactory(() => {\n this.#callback();\n });\n }\n this.#resizeObserver.observe(element);\n }\n\n /** Stops observing a single element while leaving any others in place. */\n unobserve(element: Element): void {\n this.#resizeObserver?.unobserve(element);\n }\n\n /** Starts observing viewport resizes. Idempotent: the listener is added once. */\n observeViewport(): void {\n if (this.#observingViewport) return;\n this.#observingViewport = true;\n window.addEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /** Stops observing viewport resizes without affecting element observation. */\n unobserveViewport(): void {\n if (!this.#observingViewport) return;\n this.#observingViewport = false;\n window.removeEventListener(\"resize\", this.#handleViewportResize);\n }\n\n /**\n * Releases every observation: disconnects the {@link ResizeObserver} and\n * removes the viewport listener. Safe to call multiple times. Call this from a\n * controller's `disconnect()`.\n */\n disconnect(): void {\n this.#resizeObserver?.disconnect();\n this.#resizeObserver = null;\n this.unobserveViewport();\n }\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n *.\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { LayoutObserver } from \"../utils/layout_observer\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\n/** Distance from the bottom, in px, that still counts as pinned. */\nconst DEFAULT_THRESHOLD = 80;\n\n/** Counts the element nodes in an added-node list (text nodes are ignored). */\nconst countElements = (nodes: NodeList): number => {\n let n = 0;\n for (const node of nodes) if (node.nodeType === Node.ELEMENT_NODE) n += 1;\n return n;\n};\n\n/**\n * Headless **stick-to-bottom**: auto-follows new content to the bottom of a scroll\n * container (a chat log, a live console) — but only while the user is already near the\n * bottom; if they have scrolled up to read, it holds position and flags that new content\n * arrived instead (no APG pattern; honors WCAG 2.3.3 via `prefers-reduced-motion` and\n * never steals focus).\n *\n * Markup contract (identifier: `stimeo--stick-to-bottom`):\n * <div data-controller=\"stimeo--stick-to-bottom\"\n * data-stimeo--stick-to-bottom-threshold-value=\"80\"\n * data-stimeo--stick-to-bottom-pin-on-connect-value=\"true\" style=\"overflow:auto\">\n * <ul data-stimeo--stick-to-bottom-target=\"content\"><!-- Turbo Stream appends --></ul>\n * </div>\n *\n * The container is \"pinned\" while it has a box to measure and its distance from the\n * bottom is within `threshold`. A `MutationObserver` on `content` (or the element) reacts\n * to appended children: while pinned it scrolls to the bottom; while unpinned it sets\n * `data-has-new` and emits `new`. Scrolling recomputes pinned and reflects `data-pinned`,\n * emitting `pin` on change; the `scrollToBottom` action jumps back down (a \"new messages\"\n * button). A `threshold` changed at runtime re-derives the state at once.\n *\n * A container that already overflows renders at `scrollTop` 0 — further than\n * `threshold` from the bottom, so unpinned — and flags the first append rather\n * than following it. `pinOnConnect` opts into the other starting point:\n * `connect()` jumps to the bottom and reads the state back from where it landed. It runs\n * on every connect, so a container inserted or re-rendered later (a Turbo Stream, a panel\n * built on open) starts at the bottom too — which a once-per-document page event cannot\n * do. It is off by default, so a restored reading position (a Turbo cache restore, a user\n * who had scrolled up) is never yanked to the bottom unless the consumer asks for it.\n *\n * A container connected without a box — inside a closed panel — reports every metric as\n * 0, so it is held unpinned until layout arrives: appends meanwhile are flagged rather\n * than followed into a box that cannot move, and the decision is then made against the\n * layout the user actually sees.\n *\n * `pin` dispatches `{ pinned }`; `new` dispatches `{ count }`.\n *\n * @remarks\n * The `MutationObserver` watches `childList` only (not `subtree`), so it follows\n * direct appends to `content` (or the element). Appends made deeper inside a nested\n * wrapper are not detected — keep messages as direct children, or call the public\n * `scrollToBottom` action after such inserts. A `content` target that is swapped at\n * runtime moves the watch with it.\n *\n * Behavior only — it does not add content (Turbo Stream / the consumer does) and is the\n * minimal follow primitive, not a full chat UI (no virtualization / message input). State\n * is derived from the scroll position each pass (no module-scope state), so `connect()`\n * re-syncs after a Turbo Stream insert; reduced motion forces an instant jump\n * independently of consumer CSS; auto-scroll never moves focus; the observers and the\n * passive scroll listener are released on `disconnect()` (Turbo navigation included).\n */\nexport class StickToBottomController extends Controller<HTMLElement> {\n static override targets = [\"content\"];\n static override values = {\n threshold: { type: Number, default: DEFAULT_THRESHOLD },\n behavior: { type: String, default: \"auto\" },\n pinOnConnect: { type: Boolean, default: false },\n };\n static actions = [\"scrollToBottom\"] as const;\n static events = [\"pin\", \"new\"] as const;\n\n declare readonly contentTarget: HTMLElement;\n declare readonly hasContentTarget: boolean;\n\n declare thresholdValue: number;\n declare behaviorValue: string;\n declare pinOnConnectValue: boolean;\n\n #observer: MutationObserver | null = null;\n /** The element the append observer currently holds, so a swap can be detected. */\n #watched: HTMLElement | null = null;\n /** Watches for the box a container connected without one is still waiting on. */\n readonly #layout = new LayoutObserver(() => this.#onLaidOut());\n #awaitingLayout = false;\n #connected = false;\n #pinned = false;\n\n readonly #onScroll = (): void => this.#updatePinned();\n\n override connect(): void {\n this.#connected = true;\n // Instant whatever `behavior` says, overriding a consumer's `scroll-behavior: smooth`:\n // an animated jump emits scroll events on the way down, each recomputing pinned from a\n // position still far from the bottom, so the container would unpin (and re-pin)\n // mid-flight before it ever settles.\n if (this.pinOnConnectValue && this.#measurable()) this.#scrollToBottom(\"instant\");\n // Read the state back from where the container actually is, asked for a jump or not: a\n // request the engine does not honor must leave it unpinned, so the next append is\n // flagged rather than swallowed. Both hooks are re-derived here, so a stale data-pinned\n // or data-has-new a Turbo cache restore brought back is dropped: has-new records an\n // arrival this connection has not seen, and nothing in the DOM can attest to one.\n this.element.removeAttribute(\"data-has-new\");\n this.#pinned = this.#isPinned();\n this.#reflectPinned();\n\n this.element.addEventListener(\"scroll\", this.#onScroll, { passive: true });\n this.#syncWatched();\n // A container with no box yet reports every metric as 0; it stays unpinned until the\n // layout it will actually be read against arrives.\n if (!this.#measurable()) this.#waitForLayout();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.element.removeEventListener(\"scroll\", this.#onScroll);\n this.#stopWatching();\n this.#stopWaitingForLayout();\n }\n\n /** Moves the append watch onto a `content` target that arrived at runtime. */\n contentTargetConnected(): void {\n this.#syncWatched();\n }\n\n /** Moves the append watch off a `content` target that left, back onto the container. */\n contentTargetDisconnected(): void {\n this.#syncWatched();\n }\n\n /**\n * Re-derives pinned when the distance that counts as the bottom is changed at runtime\n * (a morph that swaps the attribute on a retained element).\n */\n thresholdValueChanged(): void {\n if (!this.#connected) return;\n this.#updatePinned();\n }\n\n /**\n * Jumps to the bottom and re-pins (wired to a \"new messages\" button).\n *\n * The has-new flag clears on request — the user has acknowledged the arrival — while\n * pinned is read back from where the scroll landed: a jump that arrives by the time\n * this returns pins immediately, an animated one settles from its own scroll events,\n * and a jump the engine cannot honor leaves the container unpinned, so the next append\n * flags it again instead of being swallowed by a pinned state that does not hold.\n *\n * Which of those happens is not this method's to decide — see {@link behaviorValue}.\n */\n scrollToBottom(): void {\n this.#scrollToBottom();\n this.element.removeAttribute(\"data-has-new\");\n this.#updatePinned();\n }\n\n /** Follows appended children while pinned; otherwise flags new content. */\n #onMutations(mutations: MutationRecord[]): void {\n let added = 0;\n for (const mutation of mutations) added += countElements(mutation.addedNodes);\n if (added === 0) return;\n\n if (this.#pinned) {\n this.#scrollToBottom();\n } else {\n this.element.setAttribute(\"data-has-new\", \"true\");\n this.dispatch(\"new\", { detail: { count: added } });\n }\n }\n\n /**\n * Recomputes pinned from the scroll position and reflects it on a transition.\n *\n * @stimeoRenderRoot\n */\n #updatePinned(): void {\n const pinned = this.#isPinned();\n if (pinned === this.#pinned) return;\n this.#pinned = pinned;\n this.#reflectPinned();\n this.dispatch(\"pin\", { detail: { pinned } });\n }\n\n /** Mirrors the current `#pinned` onto the state hooks (clearing has-new once pinned). */\n #reflectPinned(): void {\n if (this.#pinned) {\n this.element.setAttribute(\"data-pinned\", \"true\");\n this.element.removeAttribute(\"data-has-new\"); // caught up with the bottom\n } else {\n this.element.removeAttribute(\"data-pinned\");\n }\n }\n\n /** Whether the container currently sits within `threshold` of its bottom. */\n #isPinned(): boolean {\n if (!this.#measurable()) return false;\n const el = this.element;\n return el.scrollHeight - el.clientHeight - el.scrollTop <= this.#threshold;\n }\n\n /**\n * The distance from the bottom that counts as pinned: a finite, non-negative number of\n * pixels. Anything else names no distance the container can be at, and settles the\n * comparison the same way at every scroll position, so it falls back to the default.\n * `Number` reads `\"abc\"` as `NaN` and every comparison against it is false; a negative\n * distance sits below the closest the container ever gets; `Infinity` is never\n * exceeded. The first two stop following and flag every append as new, and the last\n * never stops following — it takes the reading position the flag exists to protect.\n * Zero is a real declaration: it pins at the exact bottom only.\n */\n get #threshold(): number {\n const declared = this.thresholdValue;\n return Number.isFinite(declared) && declared >= 0 ? declared : DEFAULT_THRESHOLD;\n }\n\n /**\n * Whether the container has a box to scroll and to measure. One that is not rendered\n * (inside a closed panel) reports every metric as 0, which reads as \"already at the\n * bottom\" — a position describing no layout the user will ever see.\n */\n #measurable(): boolean {\n return this.element.clientHeight > 0;\n }\n\n /**\n * Holds the pinned decision until the container is laid out — otherwise the panel opens\n * at the top while the state claims the bottom, and the appends that arrived meanwhile\n * were followed into a box that could not move rather than flagged.\n */\n #waitForLayout(): void {\n this.#awaitingLayout = true;\n this.#layout.observe(this.element);\n }\n\n /** Runs the held decision once the container has the box it was waiting for. */\n #onLaidOut(): void {\n if (!this.#awaitingLayout || !this.#measurable()) return;\n this.#stopWaitingForLayout();\n if (this.pinOnConnectValue) this.#scrollToBottom(\"instant\");\n this.#updatePinned();\n }\n\n /** Releases the layout watch, whether or not the held decision ever ran. */\n #stopWaitingForLayout(): void {\n this.#awaitingLayout = false;\n this.#layout.disconnect();\n }\n\n /**\n * Scrolls to the bottom, clamped by the engine to the maximum scroll offset — which is\n * 0 for a container tall enough to hold its whole content, so the jump moves nothing\n * there. `behavior` defaults to the configured follow behavior; pass `\"instant\"` for a\n * jump that must not animate.\n */\n #scrollToBottom(behavior: ScrollBehavior = this.#behavior()): void {\n const top = this.element.scrollHeight;\n if (typeof this.element.scrollTo === \"function\") {\n this.element.scrollTo({ top, behavior });\n } else {\n this.element.scrollTop = top;\n }\n }\n\n /**\n * Points the append watch at the current `content` target, or at the container when\n * there is none. Re-resolved whenever that target changes, so a swap does not leave the\n * observer holding a detached node whose appends nobody sees.\n *\n * Stimulus runs the target callbacks outside the connected window too — before\n * `connect()` for a target already in the DOM, and after `disconnect()` while the\n * element is torn down — where this would arm an observer nothing releases. Re-syncing\n * to the target already held is left alone, so an arrival still in flight is not\n * dropped with the observer that was about to deliver it.\n */\n #syncWatched(): void {\n if (!this.#connected) return;\n const next = this.hasContentTarget ? this.contentTarget : this.element;\n if (next === this.#watched) return;\n\n this.#stopWatching();\n this.#watched = next;\n if (typeof MutationObserver === \"undefined\") return;\n this.#observer = new MutationObserver((mutations) => this.#onMutations(mutations));\n this.#observer.observe(next, { childList: true });\n }\n\n /** Releases the append watch and the element it held. */\n #stopWatching(): void {\n this.#observer?.disconnect();\n this.#observer = null;\n this.#watched = null;\n }\n\n /**\n * The behavior a follow-scroll runs with. `\"auto\"` is **not** a request to arrive at\n * once: it hands the decision to the element's computed `scroll-behavior`, so a\n * consumer stylesheet saying `smooth` animates these scrolls too. Only `\"instant\"`\n * overrides that CSS, which is why reduced motion and the `pinOnConnect` jump name it.\n */\n #behavior(): ScrollBehavior {\n if (prefersReducedMotion()) return \"instant\";\n return this.behaviorValue === \"smooth\" ? \"smooth\" : \"auto\";\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/attribute_lease.ts","../../src/utils/before_cache_reset.ts","../../src/utils/detach_gate.ts","../../src/utils/safe_timeout.ts","../../src/controllers/submit_once_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAAY,4B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,IAAA,CAAK,OAAA,CAAQ,+CAA+C,CAAA,KAAM;AAAA,KACtE,IAAK,IAAA;AAAA,EAET;AAAA;AAAA,EAGA,cAAc,KAAA,EAAmC;AAC/C,IAAA,MAAM,OAAA,GAAW,MAA6C,MAAA,EAAQ,OAAA;AACtE,IAAA,OAAO,OAAO,OAAA,KAAY,SAAA,GAAY,OAAA,GAAU,MAAA;AAAA,EAClD;AACF","file":"submit_once_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/** One temporarily controlled attribute value and the authored value it displaced. */\ninterface AttributeLeaseRecord {\n readonly original: string | null;\n written: string | null;\n}\n\n/**\n * Temporarily controls one attribute across a changing set of elements.\n *\n * The first write remembers the authored value, including the distinction between\n * an absent attribute and an authored empty string. Returning a lease restores that\n * value only while the attribute still matches the controller's last write. If a\n * consumer changed it in the meantime, the consumer owns the new value and teardown\n * leaves it alone.\n *\n * A `null` write deliberately removes the attribute while retaining the lease. This\n * is useful for derived ARIA whose valid absence is itself controller state, such as\n * an unbounded `aria-valuemin` or a blank spinbutton's `aria-valuenow`.\n *\n * The lease has no lifecycle of its own, so it never subscribes to document events.\n * A consumer that must not let a derived value become the authored baseline of a\n * cached page returns its leases from its own `turbo:before-cache` rewind, where the\n * matching `disconnect()` also releases the subscription.\n */\nexport class AttributeLease<T extends Element = Element> {\n readonly #attribute: string;\n readonly #records = new Map<T, AttributeLeaseRecord>();\n\n /** @param attribute - The attribute whose temporary values this lease owns. */\n constructor(attribute: string) {\n this.#attribute = attribute;\n }\n\n /** Writes or removes the leased attribute while preserving its authored value. */\n write(element: T, value: string | null): void {\n const existing = this.#records.get(element);\n if (existing) {\n existing.written = value;\n } else {\n this.#records.set(element, {\n original: element.getAttribute(this.#attribute),\n written: value,\n });\n }\n\n this.#reflect(element, value);\n }\n\n /** Returns one lease without overwriting a value subsequently authored by a consumer. */\n return(element: T): void {\n const record = this.#records.get(element);\n if (!record) return;\n this.#records.delete(element);\n const stillOwned = element.getAttribute(this.#attribute) === record.written;\n if (stillOwned) this.#reflect(element, record.original);\n }\n\n /** Reflects only a real value transition, avoiding self-triggered mutation work. */\n #reflect(element: T, value: string | null): void {\n if (element.getAttribute(this.#attribute) === value) return;\n if (value === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, value);\n }\n\n /** Returns every outstanding lease using the same ownership check as {@link return}. */\n returnAll(): void {\n for (const element of Array.from(this.#records.keys())) this.return(element);\n }\n}\n","/**\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","/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer (the `SafeTimeout` / `FocusTrap` lineage —\n * this util owns the discrimination only):\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True while a probe is queued — the last disconnect was ambiguous and no\n * reconnect has cancelled it yet. Read it from `connect()` to tell the\n * reconnect half of an in-page move from a first connect: a controller whose\n * initialisation restarts a measurement (a min-duration floor, an elapsed\n * counter) must skip it for the move, where nothing actually restarted.\n */\n get pending(): boolean {\n return this.#pending;\n }\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\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 { announce } from \"../utils/announce\";\nimport { AttributeLease } from \"../utils/attribute_lease\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { DetachGate } from \"../utils/detach_gate\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/** Native controls that can submit a form. */\ntype SubmitControl = HTMLButtonElement | HTMLInputElement;\n\n/** Why an active submission returned to idle. */\ntype CompletionReason = \"canceled\" | \"manual\" | \"timeout\" | \"turbo\";\n\n/** A text/value write that cannot be represented by an {@link AttributeLease}. */\ntype LabelWrite =\n | {\n readonly channel: \"text\";\n readonly control: HTMLButtonElement;\n readonly original: string;\n readonly written: string;\n }\n | {\n readonly channel: \"value\";\n readonly control: HTMLInputElement;\n readonly original: string;\n readonly written: string;\n };\n\n/** One form's independent in-flight submission. */\ninterface SubmissionSession {\n readonly form: HTMLFormElement;\n readonly submitter: SubmitControl | null;\n readonly submitterHadFocus: boolean;\n readonly controls: Set<SubmitControl>;\n timeoutId: number | null;\n labelWrite: LabelWrite | null;\n idlePart: HTMLElement | null;\n busyPart: HTMLElement | null;\n}\n\n/** Per-button override for the controller's default busy label. */\nconst BUTTON_BUSY_LABEL = \"data-submit-once-busy-label\";\n\n/**\n * Headless form-scoped double-submit guard (identifier:\n * `stimeo--submit-once`). It disables every native submit control associated\n * with the submitting form, publishes busy state, and restores only the state\n * it still owns when the operation finishes.\n *\n * Turbo forms need no `data-action`: the controller observes\n * `turbo:submit-start` and `turbo:submit-end` itself.\n *\n * A non-Turbo async form owns its own lifecycle and declares each transition:\n * `submit->stimeo--submit-once#start` applies the busy state synchronously,\n * before the request is issued, and `#finish` / `#cancel` end it. Cancelling the\n * event's default is how such a form suppresses the native navigation, so it\n * never means the submission died — only `#cancel` does. A submit already\n * cancelled by an earlier listener never starts a session at all.\n *\n * ```html\n * <form data-controller=\"stimeo--submit-once\"\n * data-action=\"submit->stimeo--submit-once#start\n * save:complete->stimeo--submit-once#finish\n * save:error->stimeo--submit-once#cancel\">\n * <button type=\"submit\">Save</button>\n * </form>\n * ```\n *\n * A form whose submit a later listener vetoes needs `#cancel` wired to that\n * veto, or a non-zero `timeout`, to leave the busy state.\n *\n * Plain text buttons can use `busyLabel` (overridden by\n * `data-submit-once-busy-label`). A button with authored structure instead uses\n * an `idle` / `busy` target pair inside that button, so icons and descendants\n * are never replaced with `textContent`:\n *\n * ```html\n * <form data-controller=\"stimeo--submit-once\"\n * data-stimeo--submit-once-announce-text-value=\"Saving…\"\n * data-stimeo--submit-once-announce-ready-text-value=\"Saved.\">\n * <button type=\"submit\" data-stimeo--submit-once-target=\"submit\">\n * <span data-stimeo--submit-once-target=\"idle\">Save</span>\n * <span data-stimeo--submit-once-target=\"busy\" hidden>Saving…</span>\n * </button>\n * </form>\n * ```\n *\n * Events:\n * - `stimeo--submit-once:start` — `{ form, submitter }`.\n * - `stimeo--submit-once:reconcile` — `{ forms: HTMLFormElement[] }`, the forms\n * whose in-flight submission the Turbo cache rewind abandoned. `end` would\n * claim the submission resolved, so the rewind reports itself instead.\n * - `stimeo--submit-once:end` — `{ form, submitter, reason, success? }`, where\n * `reason` is `\"turbo\"`, `\"timeout\"`, `\"manual\"`, or `\"canceled\"`. Only\n * `\"canceled\"` skips the completion announcement, because no operation ran.\n *\n * @remarks\n * Behavior only: the consumer owns every visual, label, and announcement\n * string. `announceText` / `announceReadyText` are empty by default and speak\n * through the page's shared `stimeo--announcer` only on real state transitions.\n * Attribute writes use {@link AttributeLease}, so a consumer mutation made\n * while busy wins over restoration. {@link DetachGate} preserves an in-flight\n * session across an in-page move, while {@link BeforeCacheReset} rewinds the\n * snapshot before Turbo caches it. Cache/detach rewinds are silent and never\n * move focus.\n */\nexport class SubmitOnceController extends Controller<HTMLElement> {\n static override targets = [\"submit\", \"idle\", \"busy\"];\n static override values = {\n announceText: { type: String, default: \"\" },\n announceReadyText: { type: String, default: \"\" },\n busyLabel: { type: String, default: \"\" },\n timeout: { type: Number, default: 0 },\n restoreFocus: { type: Boolean, default: false },\n };\n static actions = [\"cancel\", \"finish\", \"start\"] as const;\n static events = [\"start\", \"end\", \"reconcile\"] as const;\n\n declare readonly submitTargets: SubmitControl[];\n declare readonly idleTargets: HTMLElement[];\n declare readonly busyTargets: HTMLElement[];\n\n declare announceTextValue: string;\n declare announceReadyTextValue: string;\n declare busyLabelValue: string;\n declare timeoutValue: number;\n declare restoreFocusValue: boolean;\n\n readonly #timers = new SafeTimeout();\n readonly #gate = new DetachGate();\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n readonly #sessions = new Map<HTMLFormElement, SubmissionSession>();\n\n readonly #disabled = new AttributeLease<SubmitControl>(\"disabled\");\n readonly #controlBusy = new AttributeLease<SubmitControl>(\"aria-busy\");\n readonly #formBusy = new AttributeLease<HTMLFormElement>(\"aria-busy\");\n readonly #submitting = new AttributeLease<HTMLFormElement>(\"data-submitting\");\n readonly #ariaLabel = new AttributeLease<HTMLButtonElement>(\"aria-label\");\n readonly #hidden = new AttributeLease<HTMLElement>(\"hidden\");\n\n readonly #onSubmitStart = (event: Event): void => {\n this.start(event);\n };\n\n readonly #onSubmitEnd = (event: Event): void => {\n this.#complete(this.#eventForm(event), \"turbo\", this.#eventSuccess(event));\n };\n\n /** Blocks a later native submit while one for the same form is still active. */\n readonly #onNativeSubmit = (event: Event): void => {\n // The submit event's target is its form. This listener runs in capture so it\n // always observes that first event before a public `start` action creates the\n // session, while a later event sees the session and is canceled here.\n const session = this.#sessionFor(event.target);\n if (!session) return;\n this.#syncControls(session);\n event.preventDefault();\n };\n\n override connect(): void {\n this.#gate.cancel();\n this.#beforeCache.activate();\n this.element.addEventListener(\"submit\", this.#onNativeSubmit, true);\n this.element.addEventListener(\"turbo:submit-start\", this.#onSubmitStart);\n this.element.addEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"submit\", this.#onNativeSubmit, true);\n this.element.removeEventListener(\"turbo:submit-start\", this.#onSubmitStart);\n this.element.removeEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#beforeCache.deactivate();\n this.#gate.disconnected(this, () => this.#teardown());\n }\n\n /**\n * Begins the submission represented by `event`.\n *\n * Native `submit` events are intended for non-Turbo async forms. Turbo calls\n * this path through its auto-subscribed `turbo:submit-start` event. An event\n * whose default an earlier listener already cancelled carries no submission,\n * so it starts nothing.\n */\n start(event: Event): void {\n if (event.defaultPrevented) return;\n const form = this.#eventForm(event);\n if (!form || this.#sessions.has(form)) return;\n\n const controls = this.#submitControls(form);\n const submitter = this.#resolveSubmitter(event, controls);\n const session: SubmissionSession = {\n form,\n submitter,\n submitterHadFocus: submitter !== null && document.activeElement === submitter,\n controls: new Set(),\n timeoutId: null,\n labelWrite: null,\n idlePart: null,\n busyPart: null,\n };\n this.#sessions.set(form, session);\n\n this.#formBusy.write(form, \"true\");\n this.#submitting.write(form, \"true\");\n this.#syncControls(session, controls);\n this.#enterLabel(session);\n this.dispatch(\"start\", { detail: { form, submitter } });\n\n if (this.timeoutValue > 0) {\n session.timeoutId = this.#timers.set(\n () => this.#complete(form, \"timeout\", false),\n this.timeoutValue,\n );\n }\n\n announce(this.announceTextValue);\n }\n\n /**\n * Completes a non-Turbo async submission for the form associated with\n * `event`. When called directly with no event, it completes the controller's\n * sole active form (or the controller element itself when it is a form).\n */\n finish(event?: Event): void {\n const form = event ? this.#eventForm(event) : this.#defaultForm();\n this.#complete(form, \"manual\", event ? this.#eventSuccess(event) : undefined);\n }\n\n /**\n * Abandons the submission for the form associated with `event` because it\n * never reached the network — a veto from validation, or a request the\n * consumer gave up before sending. With no event it targets the controller's\n * sole active form, exactly like {@link finish}.\n *\n * The distinction from `finish` is observable: a request that ran and failed\n * is `finish` with `success: false` and still announces completion, while a\n * submission that never happened announces nothing.\n */\n cancel(event?: Event): void {\n const form = event ? this.#eventForm(event) : this.#defaultForm();\n this.#complete(form, \"canceled\", false);\n }\n\n /** Disables a newly connected explicit submit target during its form's session. */\n submitTargetConnected(target: SubmitControl): void {\n const session = this.#sessionFor(target.form);\n if (!session || !this.#isNativeSubmitControl(target)) return;\n this.#enterControl(session, target);\n }\n\n /** Ends one session, restores owned state, and reports the observable completion. */\n #complete(form: HTMLFormElement | null, reason: CompletionReason, success?: boolean): void {\n const session = this.#sessionFor(form);\n if (!session) return;\n this.#sessions.delete(session.form);\n this.#returnSessionState(session);\n\n const detail =\n success === undefined\n ? { form: session.form, submitter: session.submitter, reason }\n : { form: session.form, submitter: session.submitter, reason, success };\n this.dispatch(\"end\", { detail });\n this.#restoreFocus(session);\n if (reason !== \"canceled\") announce(this.announceReadyTextValue);\n }\n\n /** Applies the busy state to every current native/explicit control exactly once. */\n #syncControls(session: SubmissionSession, controls = this.#submitControls(session.form)): void {\n for (const control of controls) this.#enterControl(session, control);\n }\n\n /** Temporarily disables one enabled submit control while retaining authored state. */\n #enterControl(session: SubmissionSession, control: SubmitControl): void {\n if (session.controls.has(control) || control.matches(\":disabled\")) return;\n session.controls.add(control);\n this.#disabled.write(control, \"\");\n this.#controlBusy.write(control, \"true\");\n }\n\n /** Swaps only the triggering control's safe label channel. */\n #enterLabel(session: SubmissionSession): void {\n const control = session.submitter;\n if (!control) return;\n\n const idlePart = this.#partInside(control, this.idleTargets);\n const busyPart = this.#partInside(control, this.busyTargets);\n if (idlePart && busyPart) {\n session.idlePart = idlePart;\n session.busyPart = busyPart;\n this.#hidden.write(idlePart, \"\");\n this.#hidden.write(busyPart, null);\n }\n\n const label = control.getAttribute(BUTTON_BUSY_LABEL) ?? this.busyLabelValue;\n if (label.length === 0) return;\n if (control instanceof HTMLInputElement) {\n // `input[type=image]#value` is submitted data, not a visible label.\n if (control.type !== \"submit\") return;\n session.labelWrite = {\n channel: \"value\",\n control,\n original: control.value,\n written: label,\n };\n control.value = label;\n return;\n }\n if (control.hasAttribute(\"aria-label\")) {\n this.#ariaLabel.write(control, label);\n return;\n }\n // A structured button needs the explicit idle/busy pair above. Replacing its\n // textContent would destroy icons, counters, and application-owned listeners.\n if (control.childElementCount > 0) return;\n session.labelWrite = {\n channel: \"text\",\n control,\n original: control.textContent ?? \"\",\n written: label,\n };\n control.textContent = label;\n }\n\n /** Returns labels, controls, and form hooks, respecting intervening consumer writes. */\n #returnSessionState(session: SubmissionSession): void {\n if (session.timeoutId !== null) {\n this.#timers.clear(session.timeoutId);\n session.timeoutId = null;\n }\n\n if (session.labelWrite?.channel === \"value\") {\n const { control, original, written } = session.labelWrite;\n if (control.value === written) control.value = original;\n } else if (session.labelWrite?.channel === \"text\") {\n const { control, original, written } = session.labelWrite;\n if (control.childElementCount === 0 && control.textContent === written) {\n control.textContent = original;\n }\n }\n session.labelWrite = null;\n\n if (session.submitter instanceof HTMLButtonElement) {\n this.#ariaLabel.return(session.submitter);\n }\n if (session.idlePart) this.#hidden.return(session.idlePart);\n if (session.busyPart) this.#hidden.return(session.busyPart);\n session.idlePart = null;\n session.busyPart = null;\n\n for (const control of session.controls) {\n this.#controlBusy.return(control);\n this.#disabled.return(control);\n }\n session.controls.clear();\n this.#submitting.return(session.form);\n this.#formBusy.return(session.form);\n }\n\n /** Restores focus only when disabling the focused submitter actually stranded it. */\n #restoreFocus(session: SubmissionSession): void {\n const submitter = session.submitter;\n if (!this.restoreFocusValue || !session.submitterHadFocus || !submitter?.isConnected) return;\n const active = document.activeElement;\n if (active === null || active === document.body || active === document.documentElement) {\n submitter.focus();\n }\n }\n\n /** Silently abandons every session before caching or on a real detach. */\n #abandonSessions(): void {\n this.#timers.clearAll();\n for (const session of this.#sessions.values()) {\n session.timeoutId = null;\n this.#returnSessionState(session);\n }\n this.#sessions.clear();\n }\n\n /** Keeps Turbo's cached snapshot idle, without events, announcements, or focus moves. */\n #rewindForCache(): void {\n const forms = [...this.#sessions.keys()];\n this.#abandonSessions();\n // A submission in flight dies with the navigation, so a consumer still\n // painting \"submitting\" from `start` would never be released.\n if (forms.length > 0) this.dispatch(\"reconcile\", { detail: { forms } });\n }\n\n /** Tears down a true detach; an in-page move is canceled by the next `connect()`. */\n #teardown(): void {\n this.#gate.cancel();\n this.#abandonSessions();\n }\n\n /** All native controls associated with `form`, plus valid explicit targets. */\n #submitControls(form: HTMLFormElement): SubmitControl[] {\n const controls = new Set<SubmitControl>();\n for (const element of Array.from(form.elements)) {\n if (this.#isNativeSubmitControl(element)) controls.add(element);\n }\n // Browsers historically omit input[type=image] from form.elements. Search\n // the form's tree root as well so descendant and external `form=` image\n // submitters receive the same guard without broadening into sibling forms.\n const root = form.getRootNode() as ParentNode;\n for (const image of root.querySelectorAll<HTMLInputElement>('input[type=\"image\"]')) {\n if (image.form === form) controls.add(image);\n }\n return Array.from(controls);\n }\n\n /** Resolves the real submitter, falling back to the first enabled submit control. */\n #resolveSubmitter(event: Event, controls: SubmitControl[]): SubmitControl | null {\n const submitter = this.#eventSubmitter(event);\n if (submitter && controls.includes(submitter)) return submitter;\n return controls.find((control) => !control.matches(\":disabled\")) ?? controls[0] ?? null;\n }\n\n /** Reads a native or Turbo submitter without assuming `SubmitEvent` exists. */\n #eventSubmitter(event: Event): SubmitControl | null {\n if (typeof SubmitEvent !== \"undefined\" && event instanceof SubmitEvent) {\n return this.#isNativeSubmitControl(event.submitter) ? event.submitter : null;\n }\n const detail = (event as CustomEvent<{ formSubmission?: { submitter?: HTMLElement | null } }>)\n .detail;\n const submitter = detail?.formSubmission?.submitter;\n return this.#isNativeSubmitControl(submitter) ? submitter : null;\n }\n\n /** Finds the form represented by an action/Turbo event and verifies this scope owns it. */\n #eventForm(event: Event): HTMLFormElement | null {\n const detail = (\n event as CustomEvent<{\n form?: HTMLFormElement;\n formSubmission?: { formElement?: HTMLFormElement; submitter?: HTMLElement | null };\n }>\n ).detail;\n const target = event.target;\n const candidate =\n (target instanceof HTMLFormElement ? target : null) ??\n (target instanceof Element ? target.closest(\"form\") : null) ??\n detail?.formSubmission?.formElement ??\n detail?.form ??\n this.#eventSubmitter(event)?.form ??\n (this.element instanceof HTMLFormElement ? this.element : null);\n return candidate && this.#ownsForm(candidate) ? candidate : null;\n }\n\n /** The only unambiguous form for a direct `finish()` call. */\n #defaultForm(): HTMLFormElement | null {\n if (this.element instanceof HTMLFormElement && this.#ownsForm(this.element))\n return this.element;\n if (this.#sessions.size === 1) return this.#sessions.keys().next().value ?? null;\n return null;\n }\n\n /** Prevents an ancestor controller from also taking over a nested instance's form. */\n #ownsForm(form: HTMLFormElement): boolean {\n let candidate: Element | null = form;\n while (candidate) {\n const identifiers = (candidate.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n if (identifiers.includes(this.identifier)) return candidate === this.element;\n candidate = candidate.parentElement;\n }\n return false;\n }\n\n /** Returns the active session for a form-shaped external event value. */\n #sessionFor(candidate: unknown): SubmissionSession | undefined {\n if (!(candidate instanceof HTMLFormElement)) return undefined;\n return this.#sessions.get(candidate);\n }\n\n /** Effective native submit controls, including implicit buttons and image inputs. */\n #isNativeSubmitControl(element: unknown): element is SubmitControl {\n if (element instanceof HTMLButtonElement) return element.type === \"submit\";\n return (\n element instanceof HTMLInputElement && (element.type === \"submit\" || element.type === \"image\")\n );\n }\n\n /** Finds a structured label part belonging to this button, not a nested control. */\n #partInside(control: SubmitControl, parts: HTMLElement[]): HTMLElement | null {\n return (\n parts.find(\n (part) =>\n control.contains(part) &&\n part.closest(\"button, input[type=submit], input[type=image]\") === control,\n ) ?? null\n );\n }\n\n /** Reads an optional boolean `success` from Turbo or a manual completion event. */\n #eventSuccess(event: Event): boolean | undefined {\n const success = (event as CustomEvent<{ success?: unknown }>).detail?.success;\n return typeof success === \"boolean\" ? success : undefined;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/attribute_lease.ts","../../src/utils/before_cache_reset.ts","../../src/utils/detach_gate.ts","../../src/utils/safe_timeout.ts","../../src/controllers/submit_once_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,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,OAAA,CAAQ,QAAA,CAAS,IAAI,CAAA,IACrB,IAAA,CAAK,OAAA,CAAQ,+CAA+C,CAAA,KAAM;AAAA,KACtE,IAAK,IAAA;AAAA,EAET;AAAA;AAAA,EAGA,cAAc,KAAA,EAAmC;AAC/C,IAAA,MAAM,OAAA,GAAW,MAA6C,MAAA,EAAQ,OAAA;AACtE,IAAA,OAAO,OAAO,OAAA,KAAY,SAAA,GAAY,OAAA,GAAU,MAAA;AAAA,EAClD;AACF","file":"submit_once_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/** One temporarily controlled attribute value and the authored value it displaced. */\ninterface AttributeLeaseRecord {\n readonly original: string | null;\n written: string | null;\n}\n\n/**\n * Temporarily controls one attribute across a changing set of elements.\n *\n * The first write remembers the authored value, including the distinction between\n * an absent attribute and an authored empty string. Returning a lease restores that\n * value only while the attribute still matches the controller's last write. If a\n * consumer changed it in the meantime, the consumer owns the new value and teardown\n * leaves it alone.\n *\n * A `null` write deliberately removes the attribute while retaining the lease. This\n * is useful for derived ARIA whose valid absence is itself controller state, such as\n * an unbounded `aria-valuemin` or a blank spinbutton's `aria-valuenow`.\n *\n * The lease has no lifecycle of its own, so it never subscribes to document events.\n * A consumer that must not let a derived value become the authored baseline of a\n * cached page returns its leases from its own `turbo:before-cache` rewind, where the\n * matching `disconnect()` also releases the subscription.\n */\nexport class AttributeLease<T extends Element = Element> {\n readonly #attribute: string;\n readonly #records = new Map<T, AttributeLeaseRecord>();\n\n /** @param attribute - The attribute whose temporary values this lease owns. */\n constructor(attribute: string) {\n this.#attribute = attribute;\n }\n\n /** Writes or removes the leased attribute while preserving its authored value. */\n write(element: T, value: string | null): void {\n const existing = this.#records.get(element);\n if (existing) {\n existing.written = value;\n } else {\n this.#records.set(element, {\n original: element.getAttribute(this.#attribute),\n written: value,\n });\n }\n\n this.#reflect(element, value);\n }\n\n /** Returns one lease without overwriting a value subsequently authored by a consumer. */\n return(element: T): void {\n const record = this.#records.get(element);\n if (!record) return;\n this.#records.delete(element);\n const stillOwned = element.getAttribute(this.#attribute) === record.written;\n if (stillOwned) this.#reflect(element, record.original);\n }\n\n /** Reflects only a real value transition, avoiding self-triggered mutation work. */\n #reflect(element: T, value: string | null): void {\n if (element.getAttribute(this.#attribute) === value) return;\n if (value === null) element.removeAttribute(this.#attribute);\n else element.setAttribute(this.#attribute, value);\n }\n\n /** Returns every outstanding lease using the same ownership check as {@link return}. */\n returnAll(): void {\n for (const element of Array.from(this.#records.keys())) this.return(element);\n }\n}\n","/**\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.\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","/**\n * Shared \"in-page move vs real detach\" discriminator for `disconnect()`.\n *\n * A mid-session `disconnect()` whose element is still in the document is\n * ambiguous. It can be:\n *\n * - an **in-page move** — a consumer (sortable, a teleport) re-inserted the\n * element; Stimulus reconnects the SAME instance in the same mutation batch\n * and the controller's runtime state must survive;\n * - a **detach that keeps the element** — `data-controller` no longer lists the\n * identifier (a Turbo 8 morph), or the element moved outside the observed\n * root (a scoped `Application.start(root)`, a shadow root); no reconnect will\n * ever come and the controller must tear down or it leaks its sessions,\n * document listeners, and moved nodes.\n *\n * Neither available signal decides this alone. A synchronous `data-controller`\n * token check catches the morph case but misses an observed-root exit (the\n * token stays, the reconnect never comes). Deferring teardown one microtask and\n * letting `connect()` cancel it catches the root exit, but leans on Stimulus\n * reconnecting moved elements within the same mutation batch — internal\n * behavior, not a public contract. {@link DetachGate} composes both: the token\n * check is the synchronous fast path (no probe, no reliance on batching), the\n * microtask probe is the fallback for the genuinely ambiguous remainder.\n *\n * Policy stays with the consumer; this util owns the discrimination only:\n *\n * - **Probe** ({@link disconnected}) when the teardown must eventually happen —\n * live drag sessions, document listeners, teleported *content*. Call\n * {@link cancel} from `connect()` (a reconnect means in-page move) and from\n * the head of any direct teardown path (see below).\n * - **Keep** (bare {@link DetachGate.isDetached}) when undoing the ambiguous\n * case would fight the controller's own effect: a controller that moves its\n * OWN element (portal's no-`content` form) exits a scoped observed root as\n * its normal job — a probe-driven teardown would restore the element into\n * the root, reconnect, re-teleport, and disconnect again, forever. Such\n * controllers keep their state on an ambiguous disconnect and tear down only\n * on {@link DetachGate.isDetached}.\n *\n * Event convention for probe consumers: teardown into a dead (detached) tree is\n * silent — consumers restore from their own `connect()`; a detach that keeps the\n * tree alive must end an in-flight session with a `cancel` event, or composing\n * consumers strand their session bookkeeping.\n */\n\n/** The slice of a Stimulus controller the gate inspects. */\nexport interface DetachGateHost {\n readonly element: Element;\n readonly identifier: string;\n}\n\n/**\n * Per-controller-instance gate deciding whether a `disconnect()` is a real\n * detach. Hold one per controller (`#gate = new DetachGate()`) — Stimulus\n * reuses the instance across reconnects, so the pending probe state carries\n * over exactly as the protocol needs.\n *\n * @example\n * ```ts\n * #gate = new DetachGate();\n *\n * connect(): void {\n * this.#gate.cancel(); // a reconnect: the element moved in-page\n * // …\n * }\n *\n * disconnect(): void {\n * this.#gate.disconnected(this, () => this.#teardown());\n * }\n *\n * #teardown(): void {\n * this.#gate.cancel(); // disarm a still-queued probe (double-run guard)\n * // …\n * }\n * ```\n */\nexport class DetachGate {\n /** Set while a probe is queued, waiting for a reconnect to cancel it. */\n #pending = false;\n\n /**\n * True while a probe is queued — the last disconnect was ambiguous and no\n * reconnect has cancelled it yet. Read it from `connect()` to tell the\n * reconnect half of an in-page move from a first connect: a controller whose\n * initialisation restarts a measurement (a min-duration floor, an elapsed\n * counter) must skip it for the move, where nothing actually restarted.\n */\n get pending(): boolean {\n return this.#pending;\n }\n\n /**\n * True when the disconnect is definitely a real detach — the element left\n * the document, or `data-controller` no longer lists the identifier. False\n * means ambiguous (in-page move or observed-root exit), NOT \"alive\".\n */\n static isDetached(host: DetachGateHost): boolean {\n if (!host.element.isConnected) return true;\n const tokens = (host.element.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n return !tokens.includes(host.identifier);\n }\n\n /**\n * Call from `disconnect()`: runs `teardown` synchronously on a definite\n * detach (fast path), otherwise defers it one microtask — a reconnect\n * ({@link cancel} from `connect()`) keeps the state, no reconnect runs it.\n * One microtask is the whole probe window: Stimulus reconnects a moved\n * element within the same mutation batch, before the checkpoint drains.\n */\n disconnected(host: DetachGateHost, teardown: () => void): void {\n if (DetachGate.isDetached(host)) {\n // Also disarms a probe a previous ambiguous disconnect left queued\n // (defer, element removed, disconnect again) — exactly one teardown.\n this.#pending = false;\n teardown();\n return;\n }\n this.#pending = true;\n queueMicrotask(() => {\n if (!this.#pending) return;\n this.#pending = false;\n teardown();\n });\n }\n\n /**\n * Disarms a pending probe. Call from `connect()` (the reconnect that proves\n * an in-page move) and from the head of any teardown path not routed through\n * {@link disconnected} (disabled-toggle, Escape), so an orphaned probe can\n * never run the teardown a second time.\n */\n cancel(): void {\n this.#pending = false;\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 { announce } from \"../utils/announce\";\nimport { AttributeLease } from \"../utils/attribute_lease\";\nimport { BeforeCacheReset } from \"../utils/before_cache_reset\";\nimport { DetachGate } from \"../utils/detach_gate\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\n\n/** Native controls that can submit a form. */\ntype SubmitControl = HTMLButtonElement | HTMLInputElement;\n\n/** Why an active submission returned to idle. */\ntype CompletionReason = \"canceled\" | \"manual\" | \"timeout\" | \"turbo\";\n\n/** A text/value write that cannot be represented by an {@link AttributeLease}. */\ntype LabelWrite =\n | {\n readonly channel: \"text\";\n readonly control: HTMLButtonElement;\n readonly original: string;\n readonly written: string;\n }\n | {\n readonly channel: \"value\";\n readonly control: HTMLInputElement;\n readonly original: string;\n readonly written: string;\n };\n\n/** One form's independent in-flight submission. */\ninterface SubmissionSession {\n readonly form: HTMLFormElement;\n readonly submitter: SubmitControl | null;\n readonly submitterHadFocus: boolean;\n readonly controls: Set<SubmitControl>;\n timeoutId: number | null;\n labelWrite: LabelWrite | null;\n idlePart: HTMLElement | null;\n busyPart: HTMLElement | null;\n}\n\n/** Per-button override for the controller's default busy label. */\nconst BUTTON_BUSY_LABEL = \"data-submit-once-busy-label\";\n\n/**\n * Headless form-scoped double-submit guard (identifier:\n * `stimeo--submit-once`). It disables every native submit control associated\n * with the submitting form, publishes busy state, and restores only the state\n * it still owns when the operation finishes.\n *\n * Turbo forms need no `data-action`: the controller observes\n * `turbo:submit-start` and `turbo:submit-end` itself.\n *\n * A non-Turbo async form owns its own lifecycle and declares each transition:\n * `submit->stimeo--submit-once#start` applies the busy state synchronously,\n * before the request is issued, and `#finish` / `#cancel` end it. Cancelling the\n * event's default is how such a form suppresses the native navigation, so it\n * never means the submission died — only `#cancel` does. A submit already\n * cancelled by an earlier listener never starts a session at all.\n *\n * ```html\n * <form data-controller=\"stimeo--submit-once\"\n * data-action=\"submit->stimeo--submit-once#start\n * save:complete->stimeo--submit-once#finish\n * save:error->stimeo--submit-once#cancel\">\n * <button type=\"submit\">Save</button>\n * </form>\n * ```\n *\n * A form whose submit a later listener vetoes needs `#cancel` wired to that\n * veto, or a non-zero `timeout`, to leave the busy state.\n *\n * Plain text buttons can use `busyLabel` (overridden by\n * `data-submit-once-busy-label`). A button with authored structure instead uses\n * an `idle` / `busy` target pair inside that button, so icons and descendants\n * are never replaced with `textContent`:\n *\n * ```html\n * <form data-controller=\"stimeo--submit-once\"\n * data-stimeo--submit-once-announce-text-value=\"Saving…\"\n * data-stimeo--submit-once-announce-ready-text-value=\"Saved.\">\n * <button type=\"submit\" data-stimeo--submit-once-target=\"submit\">\n * <span data-stimeo--submit-once-target=\"idle\">Save</span>\n * <span data-stimeo--submit-once-target=\"busy\" hidden>Saving…</span>\n * </button>\n * </form>\n * ```\n *\n * Events:\n * - `stimeo--submit-once:start` — `{ form, submitter }`.\n * - `stimeo--submit-once:reconcile` — `{ forms: HTMLFormElement[] }`, the forms\n * whose in-flight submission the Turbo cache rewind abandoned. `end` would\n * claim the submission resolved, so the rewind reports itself instead.\n * - `stimeo--submit-once:end` — `{ form, submitter, reason, success? }`, where\n * `reason` is `\"turbo\"`, `\"timeout\"`, `\"manual\"`, or `\"canceled\"`. Only\n * `\"canceled\"` skips the completion announcement, because no operation ran.\n *\n * @remarks\n * Behavior only: the consumer owns every visual, label, and announcement\n * string. `announceText` / `announceReadyText` are empty by default and speak\n * through the page's shared `stimeo--announcer` only on real state transitions.\n * Attribute writes use {@link AttributeLease}, so a consumer mutation made\n * while busy wins over restoration. {@link DetachGate} preserves an in-flight\n * session across an in-page move, while {@link BeforeCacheReset} rewinds the\n * snapshot before Turbo caches it. Cache/detach rewinds are silent and never\n * move focus.\n */\nexport class SubmitOnceController extends Controller<HTMLElement> {\n static override targets = [\"submit\", \"idle\", \"busy\"];\n static override values = {\n announceText: { type: String, default: \"\" },\n announceReadyText: { type: String, default: \"\" },\n busyLabel: { type: String, default: \"\" },\n timeout: { type: Number, default: 0 },\n restoreFocus: { type: Boolean, default: false },\n };\n static actions = [\"cancel\", \"finish\", \"start\"] as const;\n static events = [\"start\", \"end\", \"reconcile\"] as const;\n\n declare readonly submitTargets: SubmitControl[];\n declare readonly idleTargets: HTMLElement[];\n declare readonly busyTargets: HTMLElement[];\n\n declare announceTextValue: string;\n declare announceReadyTextValue: string;\n declare busyLabelValue: string;\n declare timeoutValue: number;\n declare restoreFocusValue: boolean;\n\n readonly #timers = new SafeTimeout();\n readonly #gate = new DetachGate();\n readonly #beforeCache = new BeforeCacheReset(() => this.#rewindForCache());\n readonly #sessions = new Map<HTMLFormElement, SubmissionSession>();\n\n readonly #disabled = new AttributeLease<SubmitControl>(\"disabled\");\n readonly #controlBusy = new AttributeLease<SubmitControl>(\"aria-busy\");\n readonly #formBusy = new AttributeLease<HTMLFormElement>(\"aria-busy\");\n readonly #submitting = new AttributeLease<HTMLFormElement>(\"data-submitting\");\n readonly #ariaLabel = new AttributeLease<HTMLButtonElement>(\"aria-label\");\n readonly #hidden = new AttributeLease<HTMLElement>(\"hidden\");\n\n readonly #onSubmitStart = (event: Event): void => {\n this.start(event);\n };\n\n readonly #onSubmitEnd = (event: Event): void => {\n this.#complete(this.#eventForm(event), \"turbo\", this.#eventSuccess(event));\n };\n\n /** Blocks a later native submit while one for the same form is still active. */\n readonly #onNativeSubmit = (event: Event): void => {\n // The submit event's target is its form. This listener runs in capture so it\n // always observes that first event before a public `start` action creates the\n // session, while a later event sees the session and is canceled here.\n const session = this.#sessionFor(event.target);\n if (!session) return;\n this.#syncControls(session);\n event.preventDefault();\n };\n\n override connect(): void {\n this.#gate.cancel();\n this.#beforeCache.activate();\n this.element.addEventListener(\"submit\", this.#onNativeSubmit, true);\n this.element.addEventListener(\"turbo:submit-start\", this.#onSubmitStart);\n this.element.addEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"submit\", this.#onNativeSubmit, true);\n this.element.removeEventListener(\"turbo:submit-start\", this.#onSubmitStart);\n this.element.removeEventListener(\"turbo:submit-end\", this.#onSubmitEnd);\n this.#beforeCache.deactivate();\n this.#gate.disconnected(this, () => this.#teardown());\n }\n\n /**\n * Begins the submission represented by `event`.\n *\n * Native `submit` events are intended for non-Turbo async forms. Turbo calls\n * this path through its auto-subscribed `turbo:submit-start` event. An event\n * whose default an earlier listener already cancelled carries no submission,\n * so it starts nothing.\n */\n start(event: Event): void {\n if (event.defaultPrevented) return;\n const form = this.#eventForm(event);\n if (!form || this.#sessions.has(form)) return;\n\n const controls = this.#submitControls(form);\n const submitter = this.#resolveSubmitter(event, controls);\n const session: SubmissionSession = {\n form,\n submitter,\n submitterHadFocus: submitter !== null && document.activeElement === submitter,\n controls: new Set(),\n timeoutId: null,\n labelWrite: null,\n idlePart: null,\n busyPart: null,\n };\n this.#sessions.set(form, session);\n\n this.#formBusy.write(form, \"true\");\n this.#submitting.write(form, \"true\");\n this.#syncControls(session, controls);\n this.#enterLabel(session);\n this.dispatch(\"start\", { detail: { form, submitter } });\n\n if (this.timeoutValue > 0) {\n session.timeoutId = this.#timers.set(\n () => this.#complete(form, \"timeout\", false),\n this.timeoutValue,\n );\n }\n\n announce(this.announceTextValue);\n }\n\n /**\n * Completes a non-Turbo async submission for the form associated with\n * `event`. When called directly with no event, it completes the controller's\n * sole active form (or the controller element itself when it is a form).\n */\n finish(event?: Event): void {\n const form = event ? this.#eventForm(event) : this.#defaultForm();\n this.#complete(form, \"manual\", event ? this.#eventSuccess(event) : undefined);\n }\n\n /**\n * Abandons the submission for the form associated with `event` because it\n * never reached the network — a veto from validation, or a request the\n * consumer gave up before sending. With no event it targets the controller's\n * sole active form, exactly like {@link finish}.\n *\n * The distinction from `finish` is observable: a request that ran and failed\n * is `finish` with `success: false` and still announces completion, while a\n * submission that never happened announces nothing.\n */\n cancel(event?: Event): void {\n const form = event ? this.#eventForm(event) : this.#defaultForm();\n this.#complete(form, \"canceled\", false);\n }\n\n /** Disables a newly connected explicit submit target during its form's session. */\n submitTargetConnected(target: SubmitControl): void {\n const session = this.#sessionFor(target.form);\n if (!session || !this.#isNativeSubmitControl(target)) return;\n this.#enterControl(session, target);\n }\n\n /** Ends one session, restores owned state, and reports the observable completion. */\n #complete(form: HTMLFormElement | null, reason: CompletionReason, success?: boolean): void {\n const session = this.#sessionFor(form);\n if (!session) return;\n this.#sessions.delete(session.form);\n this.#returnSessionState(session);\n\n const detail =\n success === undefined\n ? { form: session.form, submitter: session.submitter, reason }\n : { form: session.form, submitter: session.submitter, reason, success };\n this.dispatch(\"end\", { detail });\n this.#restoreFocus(session);\n if (reason !== \"canceled\") announce(this.announceReadyTextValue);\n }\n\n /** Applies the busy state to every current native/explicit control exactly once. */\n #syncControls(session: SubmissionSession, controls = this.#submitControls(session.form)): void {\n for (const control of controls) this.#enterControl(session, control);\n }\n\n /** Temporarily disables one enabled submit control while retaining authored state. */\n #enterControl(session: SubmissionSession, control: SubmitControl): void {\n if (session.controls.has(control) || control.matches(\":disabled\")) return;\n session.controls.add(control);\n this.#disabled.write(control, \"\");\n this.#controlBusy.write(control, \"true\");\n }\n\n /** Swaps only the triggering control's safe label channel. */\n #enterLabel(session: SubmissionSession): void {\n const control = session.submitter;\n if (!control) return;\n\n const idlePart = this.#partInside(control, this.idleTargets);\n const busyPart = this.#partInside(control, this.busyTargets);\n if (idlePart && busyPart) {\n session.idlePart = idlePart;\n session.busyPart = busyPart;\n this.#hidden.write(idlePart, \"\");\n this.#hidden.write(busyPart, null);\n }\n\n const label = control.getAttribute(BUTTON_BUSY_LABEL) ?? this.busyLabelValue;\n if (label.length === 0) return;\n if (control instanceof HTMLInputElement) {\n // `input[type=image]#value` is submitted data, not a visible label.\n if (control.type !== \"submit\") return;\n session.labelWrite = {\n channel: \"value\",\n control,\n original: control.value,\n written: label,\n };\n control.value = label;\n return;\n }\n if (control.hasAttribute(\"aria-label\")) {\n this.#ariaLabel.write(control, label);\n return;\n }\n // A structured button needs the explicit idle/busy pair above. Replacing its\n // textContent would destroy icons, counters, and application-owned listeners.\n if (control.childElementCount > 0) return;\n session.labelWrite = {\n channel: \"text\",\n control,\n original: control.textContent ?? \"\",\n written: label,\n };\n control.textContent = label;\n }\n\n /** Returns labels, controls, and form hooks, respecting intervening consumer writes. */\n #returnSessionState(session: SubmissionSession): void {\n if (session.timeoutId !== null) {\n this.#timers.clear(session.timeoutId);\n session.timeoutId = null;\n }\n\n if (session.labelWrite?.channel === \"value\") {\n const { control, original, written } = session.labelWrite;\n if (control.value === written) control.value = original;\n } else if (session.labelWrite?.channel === \"text\") {\n const { control, original, written } = session.labelWrite;\n if (control.childElementCount === 0 && control.textContent === written) {\n control.textContent = original;\n }\n }\n session.labelWrite = null;\n\n if (session.submitter instanceof HTMLButtonElement) {\n this.#ariaLabel.return(session.submitter);\n }\n if (session.idlePart) this.#hidden.return(session.idlePart);\n if (session.busyPart) this.#hidden.return(session.busyPart);\n session.idlePart = null;\n session.busyPart = null;\n\n for (const control of session.controls) {\n this.#controlBusy.return(control);\n this.#disabled.return(control);\n }\n session.controls.clear();\n this.#submitting.return(session.form);\n this.#formBusy.return(session.form);\n }\n\n /** Restores focus only when disabling the focused submitter actually stranded it. */\n #restoreFocus(session: SubmissionSession): void {\n const submitter = session.submitter;\n if (!this.restoreFocusValue || !session.submitterHadFocus || !submitter?.isConnected) return;\n const active = document.activeElement;\n if (active === null || active === document.body || active === document.documentElement) {\n submitter.focus();\n }\n }\n\n /** Silently abandons every session before caching or on a real detach. */\n #abandonSessions(): void {\n this.#timers.clearAll();\n for (const session of this.#sessions.values()) {\n session.timeoutId = null;\n this.#returnSessionState(session);\n }\n this.#sessions.clear();\n }\n\n /** Keeps Turbo's cached snapshot idle, without events, announcements, or focus moves. */\n #rewindForCache(): void {\n const forms = [...this.#sessions.keys()];\n this.#abandonSessions();\n // A submission in flight dies with the navigation, so a consumer still\n // painting \"submitting\" from `start` would never be released.\n if (forms.length > 0) this.dispatch(\"reconcile\", { detail: { forms } });\n }\n\n /** Tears down a true detach; an in-page move is canceled by the next `connect()`. */\n #teardown(): void {\n this.#gate.cancel();\n this.#abandonSessions();\n }\n\n /** All native controls associated with `form`, plus valid explicit targets. */\n #submitControls(form: HTMLFormElement): SubmitControl[] {\n const controls = new Set<SubmitControl>();\n for (const element of Array.from(form.elements)) {\n if (this.#isNativeSubmitControl(element)) controls.add(element);\n }\n // Browsers omit input[type=image] from form.elements. Search\n // the form's tree root as well so descendant and external `form=` image\n // submitters receive the same guard without broadening into sibling forms.\n const root = form.getRootNode() as ParentNode;\n for (const image of root.querySelectorAll<HTMLInputElement>('input[type=\"image\"]')) {\n if (image.form === form) controls.add(image);\n }\n return Array.from(controls);\n }\n\n /** Resolves the real submitter, falling back to the first enabled submit control. */\n #resolveSubmitter(event: Event, controls: SubmitControl[]): SubmitControl | null {\n const submitter = this.#eventSubmitter(event);\n if (submitter && controls.includes(submitter)) return submitter;\n return controls.find((control) => !control.matches(\":disabled\")) ?? controls[0] ?? null;\n }\n\n /** Reads a native or Turbo submitter without assuming `SubmitEvent` exists. */\n #eventSubmitter(event: Event): SubmitControl | null {\n if (typeof SubmitEvent !== \"undefined\" && event instanceof SubmitEvent) {\n return this.#isNativeSubmitControl(event.submitter) ? event.submitter : null;\n }\n const detail = (event as CustomEvent<{ formSubmission?: { submitter?: HTMLElement | null } }>)\n .detail;\n const submitter = detail?.formSubmission?.submitter;\n return this.#isNativeSubmitControl(submitter) ? submitter : null;\n }\n\n /** Finds the form represented by an action/Turbo event and verifies this scope owns it. */\n #eventForm(event: Event): HTMLFormElement | null {\n const detail = (\n event as CustomEvent<{\n form?: HTMLFormElement;\n formSubmission?: { formElement?: HTMLFormElement; submitter?: HTMLElement | null };\n }>\n ).detail;\n const target = event.target;\n const candidate =\n (target instanceof HTMLFormElement ? target : null) ??\n (target instanceof Element ? target.closest(\"form\") : null) ??\n detail?.formSubmission?.formElement ??\n detail?.form ??\n this.#eventSubmitter(event)?.form ??\n (this.element instanceof HTMLFormElement ? this.element : null);\n return candidate && this.#ownsForm(candidate) ? candidate : null;\n }\n\n /** The only unambiguous form for a direct `finish()` call. */\n #defaultForm(): HTMLFormElement | null {\n if (this.element instanceof HTMLFormElement && this.#ownsForm(this.element))\n return this.element;\n if (this.#sessions.size === 1) return this.#sessions.keys().next().value ?? null;\n return null;\n }\n\n /** Prevents an ancestor controller from also taking over a nested instance's form. */\n #ownsForm(form: HTMLFormElement): boolean {\n let candidate: Element | null = form;\n while (candidate) {\n const identifiers = (candidate.getAttribute(\"data-controller\") ?? \"\").split(/\\s+/);\n if (identifiers.includes(this.identifier)) return candidate === this.element;\n candidate = candidate.parentElement;\n }\n return false;\n }\n\n /** Returns the active session for a form-shaped external event value. */\n #sessionFor(candidate: unknown): SubmissionSession | undefined {\n if (!(candidate instanceof HTMLFormElement)) return undefined;\n return this.#sessions.get(candidate);\n }\n\n /** Effective native submit controls, including implicit buttons and image inputs. */\n #isNativeSubmitControl(element: unknown): element is SubmitControl {\n if (element instanceof HTMLButtonElement) return element.type === \"submit\";\n return (\n element instanceof HTMLInputElement && (element.type === \"submit\" || element.type === \"image\")\n );\n }\n\n /** Finds a structured label part belonging to this button, not a nested control. */\n #partInside(control: SubmitControl, parts: HTMLElement[]): HTMLElement | null {\n return (\n parts.find(\n (part) =>\n control.contains(part) &&\n part.closest(\"button, input[type=submit], input[type=image]\") === control,\n ) ?? null\n );\n }\n\n /** Reads an optional boolean `success` from Turbo or a manual completion event. */\n #eventSuccess(event: Event): boolean | undefined {\n const success = (event as CustomEvent<{ success?: unknown }>).detail?.success;\n return typeof success === \"boolean\" ? success : undefined;\n }\n}\n"]}